{"text": "\\subsection{Line Integrals of Scalar Functions}\r\n\\noindent\r\nLet's say we have a a simple (non-self-intersecting) curve in the xy-plane $C$ parameterized by $\\vec{r}(t) = \\langle x(t), y(t)\\rangle$ and a surface $z = f(x,y)$ above $C$. We can extrude $C$ up to $f$, forming a \"curtain\" with an area $A$ that can be found through integration.\r\n\\begin{align*}\r\n\t\\mathrm{d}A &= f(x,y) \\cdot \\mathrm{d}s\t\\\\\r\n\ts &= \\int{\\norm{\\vec{r^\\prime}(t)}\\mathrm{d}t} \\\\\r\n\t\\mathrm{d}s &= \\norm{\\vec{r'}(t)}\\mathrm{d}t \\\\\r\n\t\\implies A &= \\int\\limits_{C}{f(x,y)\\mathrm{d}s} = \\int{(f\\circ\\vec{r})(t) \\cdot \\norm{\\vec{r^\\prime}(t)}\\mathrm{d}t}\r\n\\end{align*}\r\nThis is the line integral of $\\vec{r}$ on $f$. $(f\\circ\\vec{r})$ is called the \"pullback.\"\r\n\r\n\\noindent\r\nFor example, let's find the line integral of $y = x^2$ for $x \\leq x \\leq \\sqrt{2}$ in $f(x,y) = 2x$.\r\n\\begin{equation*}\r\n\t\\vec{r}(t) = \\langle t, t^2 \\rangle, 0 \\leq t \\leq \\sqrt{2}\t\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\int\\limits_{C}{f(x,y)\\mathrm{d}s} = \\int_{0}^{\\sqrt{2}}{(2x \\circ \\langle t, t^2\\rangle) \\cdot \\norm{\\vec{r^\\prime}(t)}\\mathrm{d}t} = \\int_{0}^{\\sqrt{2}}{2t\\sqrt{1 + 4t^2}\\mathrm{d}t}\r\n\\end{equation*}\r\nLet $u = 1+4t^2$, $\\mathrm{d}u = 8t\\mathrm{d}t$.\r\n\\begin{equation*}\r\n\t= \\frac{1}{4}\\int_{1}^{9}{\\sqrt{u}\\mathrm{d}u} = \\frac{13}{3}\r\n\\end{equation*}", "meta": {"hexsha": "19cda2757806ca02aed6b593852a64a23a46e316", "size": 1317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsScalarFunctions.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsScalarFunctions.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsScalarFunctions.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.2608695652, "max_line_length": 281, "alphanum_fraction": 0.6051632498, "num_tokens": 560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8856314783461303, "lm_q1q2_score": 0.7999857790534411}}
{"text": "\n\\subsection{Existence of an infinite number of prime numbers}\n\n\\subsubsection{Existence of an infinite number of prime numbers}\n\nIf there are a finite number of primes, we can call the set of primes \\(P\\).\n\nWe identify a new natural number \\(a\\) by taking the product of existing primes and adding \\(1\\).\n\n\\(a=1+\\prod_{p\\in P} p\\)\n\nFrom the fundamental theorem of arithmetic we know all numbers are primes or the products of primes.\n\nIf \\(a\\) is not a prime then it can be divided by one of the existing primes to form number \\(n\\):\n\n\\(\\dfrac{\\prod^n p_i +1}{p_j}=n\\)\n\n\\(\\dfrac{p_j \\prod^n_{i\\ne j} p_i +1}{p_j}=n\\)\n\n\\(\\prod^n_{i\\ne j} p_i +\\dfrac{1}{p_j}=n\\)\n\nAs this is not a whole number, \\(n\\) must prime.\n\nWe can do this process for any finite number of primes, so there are an infinite number.\n\n", "meta": {"hexsha": "d60371d0d113359c26c7cefcfefb1344b235dc77", "size": 802, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmeticFundamental/01-05-infinite.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/arithmeticFundamental/01-05-infinite.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/arithmeticFundamental/01-05-infinite.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.8461538462, "max_line_length": 100, "alphanum_fraction": 0.7057356608, "num_tokens": 232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741214369555, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7999088484064544}}
{"text": "\n\\subsection{Fields}\n\nA field is a ring where the multiplication function has an inverse.\n\nThe integers, addition and multiplication form a ring, but not a group.\n\nThe rational numbers (except \\(0\\)), addition and multiplication form a field (and a ring).\n\nThe real numbers and complex numbers also form fields.\n\n", "meta": {"hexsha": "be34ab7d77f98cc881a58794f1a11dfc9734605b", "size": 313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/fields/01-01-fields.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/fields/01-01-fields.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/fields/01-01-fields.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.0833333333, "max_line_length": 91, "alphanum_fraction": 0.7699680511, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7998812319682076}}
{"text": "\\section{Matrices}\n\n\\subsection{Exercise 1}\n$(P + T)_{ij} = ((P + T)e_j)_i = (Pe_j + Te_j)_i = P_{ij} + T_{ij} $.\n\n\\subsection{Exercise 2}\nRepresent $A$ as a column of row vectors $A_i$ and $B$ as a row of column\nvectors $B_i$. Denote blocks by parenthesized subscripts.\nThen the first block of $AB$ looks like:\n\\begin{align*}\n        (AB)_{(11)} &=\n    \\begin{pmatrix}\n            A_1B_1 & & \\\\\n            & \\ddots & \\\\\n            & & A_kB_k\n    \\end{pmatrix}\n    \\\\\n    &=\n    \\begin{pmatrix}\n            A_{1, :(k+1)} B_{1, :(k+1)} & & \\\\\n            & \\ddots & \\\\\n            & & A_{k, :(k+1)} B_{k, :(k+1)}\n    \\end{pmatrix}\n    \\\\\n    &+\n    \\begin{pmatrix}\n            A_{1, (k+1):} B_{1, (k+1):} & & \\\\\n            & \\ddots & \\\\\n            & & A_{k, (k+1):} B_{k, (k+1):}\n    \\end{pmatrix}\n    \\\\\n    &=\n    A_{(11)}B_{(11)} + A_{(12)}B_{(21)}\n\\end{align*}\n\nWhere:\n\\begin{align*}\n        A_{i, :(k+1)} B_{i, :(k+1)} &= \\sum_{j=1}^{k} A_{i, j} B_{i, j} \\\\\n        A_{i, (k+1):} B_{i, (k+1):} &= \\sum_{j=k+1}^{n} A_{i, j} B_{i, j}\n\\end{align*}\nThe rest follow similarly.\n", "meta": {"hexsha": "5e6491e701bd282c91741a76c4203f8e471db662", "size": 1080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/chapter_4.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Linear_Algebra_Lax/chapter_4.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear_Algebra_Lax/chapter_4.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": 25.7142857143, "max_line_length": 74, "alphanum_fraction": 0.4444444444, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7998596574696516}}
{"text": "\\section{Non Compact Projection}%\n\\label{sec:ncp}\nRecall the expression for the \\(x\\) update in the augmented L2HMC sampler,\n%\n\\begin{align}\n  x^{\\prime} &= m^{t}\\odot x + \\bar{m}^{t}\\odot\\big[x\\odot\\exp(\\varepsilon\n           S_{x}(\\zeta^{t}_{2})) + \\varepsilon * \\big(v \\odot \\exp(\\varepsilon\n           Q_x(\\zeta^{t}_{2})) + T_{x}(\\zeta^{t}_{2})\\big)\\big]\\\\\n        &= m^{t}\\odot x + \\bar{m}^{t}\\odot\\left[\\alpha x + \\beta\\right]\n        % &= m^{t}\\odot x + \\bar{m}^{t}\\odot g(x)\n\\end{align}\n%\nwhere \\(\\alpha = \\exp(\\varepsilon S_{x}), \\beta =\n\\varepsilon\\cdot\\left(v\\odot\\exp(\\varepsilon Q_{x}) + T_{x}\\right)\\), depend on\n\\(\\zeta_{2} = (m^{t}\\odot x, v, t)\\), but are independent of \\(\\bar{m}^{t}\\odot\nx\\).\n\nLet \\(z = h(x): [-\\pi, \\pi] \\rightarrow \\mathbb{R}\\) be given by\n%\n\\begin{equation}\n  z = \\tan\\left(\\frac{x}{2}\\right).\n\\end{equation}\n%\nWe can perform the affine transformation in \\(\\mathbb{R}\\) and then project\nback to \\([-\\pi, \\pi]\\) via \\(x = h^{-1}(z)\\) to complete the\nupdate:\n%\n% &= m^{t}\\odot x + \\bar{m}^{t}\\odot h^{-1}\\left(g\\left(h(x)\\right)\\right) \\\\\n\\begin{align}\n  x^{\\prime} &= m^{t}\\odot x + \\bar{m}^{t}\\odot \\left[2\\tan^{-1}\\left(\\alpha\n           \\tan\\left(\\frac{x}{2}\\right)\\right) + \\beta\\right]\n           %   &= m^{t}\\odot x +\n           %   \\bar{m}^{t}\\odot\\big[2\\tan^{-1}\\left(\\tan{\\left(\\frac{x}{2}\\right)}\\odot\\exp(\\varepsilon\n           %       S_{x}(\\zeta^{t}_{2}))\\right) + \\varepsilon * \\big(v \\odot \\exp(\\varepsilon\n           % Q_x(\\zeta^{t}_{2})) + T_{x}(\\zeta^{t}_{2})\\big)\\big]\n\\end{align}\n%\nWith Jacobian factor\n%\n\\begin{align}\n  \\frac{\\partial x^{\\prime}}{\\partial x} \n  &= \\frac{\\alpha}{\\cos^{2}(\\frac{x}{2})+\\alpha^{2}\\sin^{2}(\\frac{x}{2})} \\\\\n  &= \\frac{\\exp{(\\eps S_{x})}}{\\cos^{2}{(\\frac{x}{2})} \n  + \\exp{(2\\cdot\\eps S_{x})} \\sin{(\\frac{x}{2})}}\n\\end{align}\n", "meta": {"hexsha": "6a342da761d8a592875df571af07770d4d031b8c", "size": 1814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/updates/updates_2020_08_07.tex", "max_stars_repo_name": "saforem2/l2hmc-qcd", "max_stars_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-18T18:50:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:30:48.000Z", "max_issues_repo_path": "doc/updates/updates_2020_08_07.tex", "max_issues_repo_name": "saforem2/l2hmc-qcd", "max_issues_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2019-09-09T21:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:43:51.000Z", "max_forks_repo_path": "doc/ncp.tex", "max_forks_repo_name": "saforem2/l2hmc-qcd", "max_forks_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-31T02:25:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T00:49:14.000Z", "avg_line_length": 39.4347826087, "max_line_length": 103, "alphanum_fraction": 0.5429988975, "num_tokens": 745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915913, "lm_q2_score": 0.85776809953619, "lm_q1q2_score": 0.7998287074776737}}
{"text": "% -*- root: Main.tex -*-\n\\section{Essentials}\n\\subsection*{Matrix/Vector}\n\\begin{compactdesc}\n\t\\item[Orthogonal:] (i.e. columns are orthonormal!) $\\mathbf{A}^{-1} = \\mathbf{A}^\\top$, $\\mathbf{A} \\mathbf{A}^\\top = \\mathbf{A}^\\top \\mathbf{A} = \\mathbf{I}$, $\\operatorname{det}(\\mathbf{A}) \\in \\{+1, -1\\}$, $\\operatorname{det}(\\mathbf{A}^\\top \\mathbf{A}) = 1$\n\t\\item[Inner Product:] $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\mathbf{x}^\\top \\mathbf{y} = \\sum_{i=1}^{N} \\mathbf{x}_i \\mathbf{y}_i$.\n\t\\begin{inparaitem}\n\t\t\\item $\\langle \\mathbf{x} \\pm \\mathbf{y}, \\mathbf{x} \\pm \\mathbf{y} \\rangle = \\langle \\mathbf{x}, \\mathbf{x} \\rangle \\pm 2 \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{y}, \\mathbf{y} \\rangle$\n\t\t\\item $\\langle \\mathbf{x}, \\mathbf{y} + \\mathbf{z} \\rangle = \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{x}, \\mathbf{z} \\rangle$\n\t\t\\item $\\langle \\mathbf{x} + \\mathbf{y}, \\mathbf{z} \\rangle = \\langle \\mathbf{x}, \\mathbf{z} \\rangle + \\langle \\mathbf{y}, \\mathbf{z} \\rangle$\n\t\t\\item $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\|\\mathbf{x}\\|_2 \\cdot \\|\\mathbf{y}\\|_2 \\cdot \\cos(\\theta)$\n\t\t\\item If $\\mathbf{y}$ is a unit vector then $\\langle \\mathbf{x}, \\mathbf{y} \\rangle$ projects $\\mathbf{x}$ onto $\\mathbf{y}$\n\t\\end{inparaitem}\n\t\\item[Outer Product:] $\\mathbf{u} \\mathbf{v}^\\top$, $(\\mathbf{u} \\mathbf{v}^\\top)_{i, j} = \\mathbf{u}_i \\mathbf{v}_j$\n\t\\item[Transpose:] $(\\mathbf{A}^\\top)^{-1} = (\\mathbf{A}^{-1})^\\top$,  $(\\mathbf{A}\\mathbf{B})^\\top= \\mathbf{B}^\\top\\mathbf{A}^\\top$, $(\\mathbf{A}+\\mathbf{B})^\\top= \\mathbf{A}^\\top + \\mathbf{B}^\\top$\n\t\\item[Cross product:] $\\vec{a}\\times\\vec{b}=(a_2b_3-a_3b_2, a_3b_1-a_1b_3, a_1b_2-a_2b_1)^\\top$\n\\end{compactdesc}\n\n\\subsection*{Norms}\n\\begin{inparaitem}\n\t\\item $\\|\\mathbf{x}\\|_0 = |\\{i | x_i \\neq 0\\}|$\n\t\\item $\\|\\mathbf{x}\\|_2 = \\sqrt{\\sum_{i=1}^{N} \\mathbf{x}_i^2} = \\sqrt{\\langle \\mathbf{x}, \\mathbf{x} \\rangle}$\n\t\\item $\\|\\mathbf{u}-\\mathbf{v}\\|_2 = \\sqrt{(\\mathbf{u}-\\mathbf{v})^\\top(\\mathbf{u}-\\mathbf{v})}$\n\t\\item $\\|\\mathbf{x}\\|_p = \\left( \\sum_{i=1}^{N} |x_i|^p \\right)^{\\frac{1}{p}}$\n\t\\item $\\mathbf{A} \\in \\mathbb{R}^{N \\times N}, \\|\\mathbf{A}\\|_F =\\allowbreak \\sqrt{trace(\\mathbf{A}\\mathbf{A}^\\top)}$\n\t\\item\n\t$\\|\\mathbf{M}\\|_F =\\allowbreak \\sqrt{\\sum_{i=1}^{m} \\sum_{j=1}^{n}\\mathbf{m}_{i,j}^2} =\\allowbreak \\sqrt{\\sum_{i=1}^{\\min\\{m, n\\}} \\sigma_i^2}$\n\t\\item\n\t$\\|\\mathbf{M}\\|_1 = \\sum_{i,j} | m_{i,j}|$\n\t\\item $\\|\\mathbf{M}\\|_2 = \\sigma_{\\text{max}}(\\mathbf{M})$\\\\\n\t$\\|\\mathbf{M}\\|_p = \\max_{\\mathbf{v} \\neq 0} \\frac{\\|\\mathbf{M}\\mathbf{v}\\|_p}{\\|\\mathbf{v}\\|_p}$\n\t\\item $\\|\\mathbf{M}\\|_\\star = \\sum_{i=1}^{\\min(m, n)} \\sigma_i$\n\\end{inparaitem}\n\n\\subsection*{Derivatives}\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{x}) = \\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{b}) = \\mathbf{b}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{A}\\mathbf{x}) = (\\mathbf{A}^\\top + \\mathbf{A})\\mathbf{x}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{A}\\mathbf{x}) = \\mathbf{A}^\\top \\mathbf{b}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X} \\mathbf{b}) = \\mathbf{c}\\mathbf{b}^\\top$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X}^\\top \\mathbf{b}) = \\mathbf{b}\\mathbf{c}^\\top$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\| \\mathbf{x}-\\mathbf{b} \\|_2) = \\frac{\\mathbf{x}-\\mathbf{b}}{\\|\\mathbf{x}-\\mathbf{b}\\|_2}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\|\\mathbf{x}\\|^2_2) = \\frac{\\partial}{\\partial \\mathbf{x}} (\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\|\\mathbf{X}\\|_F^2) = 2\\mathbf{X}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}\\log(x) = \\frac{1}{x}$\n\n\\subsection*{Eigenvalue / -vectors}\nEigenvalue Problem: $\\mathbf{Ax} = \\lambda \\mathbf{x}$\\\\\n1. solve $\\operatorname{det}(\\mathbf{A} - \\lambda \\mathbf{I}) \\overset{!}{=} 0$ resulting in $\\{\\lambda_i\\}_i$\\\\\n2. $\\forall \\lambda_i$:\nsolve $(\\mathbf{A} - \\lambda_i \\mathbf{I}) \\mathbf{x}_i = \\mathbf{0}$, for $\\mathbf{x}_i$.\n\n\\subsection*{Eigendecomposition}\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times N}$ then $\\mathbf{A} = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q}^{-1}$ with $\\mathbf{Q} \\in \\mathbb{R}^{N \\times N}$.\\\\\nif fullrank: $\\mathbf{A}^{-1} = \\mathbf{Q} \\boldsymbol{\\Lambda}^{-1} \\mathbf{Q}^{-1}$ and $(\\boldsymbol{\\Lambda}^{-1})_{i,i} = \\frac{1}{\\lambda_i}$.\\\\\nif $\\mathbf{A}$ symmetric: $A = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q^\\top}$ ($\\mathbf{Q}$ orthogonal).\n\n\\subsection*{Probability / Statistics}\n\\begin{inparaitem}\n\t\\item $P(x) := Pr[X = x] := \\sum_{y \\in Y} P(x, y)$\n\t\\item $P(x|y) := Pr[X = x | Y = y] := \\frac{P(x,y)}{P(y)},\\quad \\text{if } P(y) > 0$\n\t\\item $\\forall y \\in Y: \\sum_{x \\in X} P(x|y) = 1$ (property for any fixed $y$)\n\t\\item $P(x, y) = P(x|y) P(y)$\n\t\\item $P(x|y) = \\frac{P(y|x)P(x)}{P(y)}$ (Bayes' rule)\n\t\\item $P(x|y) = P(x) \\Leftrightarrow P(y|x) = P(y)$ (iff $X$, $Y$ independent)\n\t\\item $P(x_1, \\ldots, x_n) = \\prod_{i=1}^n P(x_i)$ (iff IID)\n\t\\item Variance $Var[X]:= E[(X-\\mu_x)^2]:=\\sum_{x \\in X}(x-\\mu_x)^2P(x)$\n\t\\item expectation $\\mu_x := E[X]:=\\sum_{x \\in X}xP(x)$\n\t\\item standard deviation $\\sigma_x := \\sqrt{Var[X]}$\n\\end{inparaitem}\n", "meta": {"hexsha": "f6bfb4db64d59610ab3f306ea5b146e2bce78c12", "size": 5263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Essentials.tex", "max_stars_repo_name": "ABBDVD/eth-cil-exam-summary", "max_stars_repo_head_hexsha": "c9e7c4b1e6b5aecc2f8b37ee18956517a8d44bc4", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Essentials.tex", "max_issues_repo_name": "ABBDVD/eth-cil-exam-summary", "max_issues_repo_head_hexsha": "c9e7c4b1e6b5aecc2f8b37ee18956517a8d44bc4", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Essentials.tex", "max_forks_repo_name": "ABBDVD/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "c9e7c4b1e6b5aecc2f8b37ee18956517a8d44bc4", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-08-03T18:47:02.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-03T18:47:02.000Z", "avg_line_length": 74.1267605634, "max_line_length": 262, "alphanum_fraction": 0.5945278358, "num_tokens": 2365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778073288128, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7997898504183728}}
{"text": "\\section*{Singular Value Decomposition}\n$\\mathbf{A} = \\mathbf{U} \\mathbf{D} \\mathbf{V}^\\top = \\sum_{k=1}^{\\operatorname{rank}(\\mathbf{A})} d_{k,k} u_k (v_k)^\\top$\\\\\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times P}, \\mathbf{U} \\in \\mathbb{R}^{N \\times N}, \\mathbf{D} \\in \\mathbb{R}^{N \\times P}, \\mathbf{V} \\in \\mathbb{R}^{P \\times P}$\\\\\n$\\mathbf{U}^\\top \\mathbf{U} = I = \\mathbf{V}^\\top \\mathbf{V}$ ($\\mathbf{U}, \\mathbf{V}$ orthonormal)\\\\\n$\\mathbf{U}$: cols are eigenvectors of $\\mathbf{A} \\mathbf{A}^\\top$, $\\mathbf{V}$: cols are eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$, $\\mathbf{D}$ diag. el. are singular values.\n\n1. calculate $\\mathbf{A}^\\top \\mathbf{A}$.\\\\\n2. calculate eigenvalues of $\\mathbf{A}^\\top \\mathbf{A}$, the square root of them, in desc. order, are the diagonal elements of $\\mathbf{D}$.\\\\\n3. calculate eigenvectors of $\\mathbf{A}^\\top \\mathbf{A}$ using the eigenvalues resulting in the columns of $\\mathbf{V}$.\\\\\n4. calculate the missing matrix: $\\mathbf{U} = \\mathbf{A} \\mathbf{V} \\mathbf{D}^{-1}$.\\\\\n5. normalize each column of $\\mathbf{U}$ and $\\mathbf{V}$.\\\\\nComplexity: $O(\\min(mn^2, nm^3))$\n\n\\subsection*{Eckart-Young Theorem}\n$\\min_{rank(B)=K} ||A-B||_F^2 = ||A-A_k||_F^2 = \\sum_{r=k+1}^{rank(A)} \\sigma_r^2$\n$\\min_{rank(B)=K} ||A-B||_2 = ||A-A_k||_2 = \\sigma_{k+1}$\n", "meta": {"hexsha": "40e4884fb3e999d571186cbbae9796881b92ce55", "size": 1288, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SVD.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": "SVD.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": "SVD.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": 75.7647058824, "max_line_length": 181, "alphanum_fraction": 0.6273291925, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474168650673, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7996317265714175}}
{"text": "\\subsection{K-Means Clustering}\n\n\\noindent{\\bf Description}\n\\smallskip\n\nGiven a collection of $n$ records with a pairwise similarity measure,\nthe goal of clustering is to assign a category label to each record so that\nsimilar records tend to get the same label.  In contrast to multinomial\nlogistic regression, clustering is an \\emph{unsupervised}\\/ learning problem\nwith neither category assignments nor label interpretations given in advance.\nIn $k$-means clustering, the records $x_1, x_2, \\ldots, x_n$ are numerical\nfeature vectors of $\\dim x_i = m$ with the squared Euclidean distance \n$\\|x_i - x_{i'}\\|_2^2$ as the similarity measure.  We want to partition\n$\\{x_1, \\ldots, x_n\\}$ into $k$ clusters $\\{S_1, \\ldots, S_k\\}$ so that\nthe aggregated squared distance from records to their cluster means is\nminimized:\n\\begin{equation}\n\\textrm{WCSS}\\,\\,=\\,\\, \\sum_{i=1}^n \\,\\big\\|x_i - \\mean(S_j: x_i\\in S_j)\\big\\|_2^2 \\,\\,\\to\\,\\,\\min\n\\label{eqn:WCSS}\n\\end{equation}\nThe aggregated distance measure in~(\\ref{eqn:WCSS}) is called the\n\\emph{within-cluster sum of squares}~(WCSS).  It can be viewed as a measure\nof residual variance that remains in the data after the clustering assignment,\nconceptually similar to the residual sum of squares~(RSS) in linear regression.\nHowever, unlike for the RSS, the minimization of~(\\ref{eqn:WCSS}) is an NP-hard \nproblem~\\cite{AloiseDHP2009:kmeans}.\n\nRather than searching for the global optimum in~(\\ref{eqn:WCSS}), a heuristic algorithm\ncalled Lloyd's algorithm is typically used.  This iterative algorithm maintains\nand updates a set of $k$~\\emph{centroids} $\\{c_1, \\ldots, c_k\\}$, one centroid per cluster.\nIt defines each cluster $S_j$ as the set of all records closer to~$c_j$ than\nto any other centroid.  Each iteration of the algorithm reduces the WCSS in two steps:\n\\begin{Enumerate}\n\\item Assign each record to the closest centroid, making $\\mean(S_j)\\neq c_j$;\n\\label{step:kmeans:recluster}\n\\item Reset each centroid to its cluster's mean: $c_j := \\mean(S_j)$.\n\\label{step:kmeans:recenter}\n\\end{Enumerate}\nAfter Step~\\ref{step:kmeans:recluster} the centroids are generally different from the cluster\nmeans, so we can compute another ``within-cluster sum of squares'' based on the centroids:\n\\begin{equation}\n\\textrm{WCSS\\_C}\\,\\,=\\,\\, \\sum_{i=1}^n \\,\\big\\|x_i - \\mathop{\\textrm{centroid}}(S_j: x_i\\in S_j)\\big\\|_2^2\n\\label{eqn:WCSS:C}\n\\end{equation}\nThis WCSS\\_C after Step~\\ref{step:kmeans:recluster} is less than the means-based WCSS\nbefore Step~\\ref{step:kmeans:recluster} (or equal if convergence achieved), and in\nStep~\\ref{step:kmeans:recenter} the WCSS cannot exceed the WCSS\\_C for \\emph{the same}\nclustering; hence the WCSS reduction.\n\nExact convergence is reached when each record becomes closer to its\ncluster's mean than to any other cluster's mean, so there are no more re-assignments\nand the centroids coincide with the means.  In practice, iterations may be stopped\nwhen the reduction in WCSS (or in WCSS\\_C) falls below a minimum threshold, or upon\nreaching the maximum number of iterations.  The initialization of the centroids is also\nan important part of the algorithm.  The smallest WCSS obtained by the algorithm is not\nthe global minimum and varies depending on the initial centroids.  We implement multiple\nparallel runs with different initial centroids and report the best result.\n\n\\Paragraph{Scoring} \nOur scoring script evaluates the clustering output by comparing it with a known category\nassignment.  Since cluster labels have no prior correspondence to the categories, we\ncannot count ``correct'' and ``wrong'' cluster assignments.  Instead, we quantify them in\ntwo ways:\n\\begin{Enumerate}\n\\item Count how many same-category and different-category pairs of records end up in the\nsame cluster or in different clusters;\n\\item For each category, count the prevalence of its most common cluster; for each\ncluster, count the prevalence of its most common category.\n\\end{Enumerate}\nThe number of categories and the number of clusters ($k$) do not have to be equal.  \nA same-category pair of records clustered into the same cluster is viewed as a\n``true positive,'' a different-category pair clustered together is a ``false positive,''\na same-category pair clustered apart is a ``false negative''~etc.\n\n\n\\smallskip\n\\noindent{\\bf Usage: K-means Script}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\it%\n{\\tt{}-f }path/\\/{\\tt{}Kmeans.dml}\n{\\tt{} -nvargs}\n{\\tt{} X=}path/file\n{\\tt{} C=}path/file\n{\\tt{} k=}int\n{\\tt{} runs=}int\n{\\tt{} maxi=}int\n{\\tt{} tol=}double\n{\\tt{} samp=}int\n{\\tt{} isY=}int\n{\\tt{} Y=}path/file\n{\\tt{} fmt=}format\n{\\tt{} verb=}int\n\n}\n\n\\smallskip\n\\noindent{\\bf Usage: K-means Scoring/Prediction}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\it%\n{\\tt{}-f }path/\\/{\\tt{}Kmeans-predict.dml}\n{\\tt{} -nvargs}\n{\\tt{} X=}path/file\n{\\tt{} C=}path/file\n{\\tt{} spY=}path/file\n{\\tt{} prY=}path/file\n{\\tt{} fmt=}format\n{\\tt{} O=}path/file\n\n}\n\n\\smallskip\n\\noindent{\\bf Arguments}\n\\begin{Description}\n\\item[{\\tt X}:]\nLocation to read matrix $X$ with the input data records as rows\n\\item[{\\tt C}:] (default:\\mbox{ }{\\tt \"C.mtx\"})\nLocation to store the output matrix with the best available cluster centroids as rows\n\\item[{\\tt k}:]\nNumber of clusters (and centroids)\n\\item[{\\tt runs}:] (default:\\mbox{ }{\\tt 10})\nNumber of parallel runs, each run with different initial centroids\n\\item[{\\tt maxi}:] (default:\\mbox{ }{\\tt 1000})\nMaximum number of iterations per run\n\\item[{\\tt tol}:] (default:\\mbox{ }{\\tt 0.000001})\nTolerance (epsilon) for single-iteration WCSS\\_C change ratio\n\\item[{\\tt samp}:] (default:\\mbox{ }{\\tt 50})\nAverage number of records per centroid in data samples used in the centroid\ninitialization procedure\n\\item[{\\tt Y}:] (default:\\mbox{ }{\\tt \"Y.mtx\"})\nLocation to store the one-column matrix $Y$ with the best available mapping of\nrecords to clusters (defined by the output centroids)\n\\item[{\\tt isY}:] (default:\\mbox{ }{\\tt 0})\n{\\tt 0} = do not write matrix~$Y$,  {\\tt 1} = write~$Y$\n\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\nMatrix file output format, such as {\\tt text}, {\\tt mm}, or {\\tt csv};\nsee read/write functions in SystemML Language Reference for details.\n\\item[{\\tt verb}:] (default:\\mbox{ }{\\tt 0})\n{\\tt 0} = do not print per-iteration statistics for each run, {\\tt 1} = print them\n(the ``verbose'' option)\n\\end{Description}\n\\smallskip\n\\noindent{\\bf Arguments --- Scoring/Prediction}\n\\begin{Description}\n\\item[{\\tt X}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to read matrix $X$ with the input data records as rows,\noptional when {\\tt prY} input is provided\n\\item[{\\tt C}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to read matrix $C$ with cluster centroids as rows, optional\nwhen {\\tt prY} input is provided; NOTE: if both {\\tt X} and {\\tt C} are\nprovided, {\\tt prY} is an output, not input\n\\item[{\\tt spY}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to read a one-column matrix with the externally specified ``true''\nassignment of records (rows) to categories, optional for prediction without\nscoring\n\\item[{\\tt prY}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to read (or write, if {\\tt X} and {\\tt C} are present) a\ncolumn-vector with the predicted assignment of rows to clusters;\nNOTE: No prior correspondence is assumed between the predicted\ncluster labels and the externally specified categories\n\\item[{\\tt fmt}:] (default:\\mbox{ }{\\tt \"text\"})\nMatrix file output format for {\\tt prY}, such as {\\tt text}, {\\tt mm},\nor {\\tt csv}; see read/write functions in SystemML Language Reference\nfor details\n\\item[{\\tt O}:] (default:\\mbox{ }{\\tt \" \"})\nLocation to write the output statistics defined in \nTable~\\ref{table:kmeans:predict:stats}, by default print them to the\nstandard output\n\\end{Description}\n\n\n\\begin{table}[t]\\small\\centerline{%\n\\begin{tabular}{|lcl|}\n\\hline\nName & CID & Meaning \\\\\n\\hline\n{\\tt TSS}             &     & Total Sum of Squares (from the total mean) \\\\\n{\\tt WCSS\\_M}         &     & Within-Cluster  Sum of Squares (means as centers) \\\\\n{\\tt WCSS\\_M\\_PC}     &     & Within-Cluster  Sum of Squares (means), in \\% of TSS \\\\\n{\\tt BCSS\\_M}         &     & Between-Cluster Sum of Squares (means as centers) \\\\\n{\\tt BCSS\\_M\\_PC}     &     & Between-Cluster Sum of Squares (means), in \\% of TSS \\\\\n\\hline\n{\\tt WCSS\\_C}         &     & Within-Cluster  Sum of Squares (centroids as centers) \\\\\n{\\tt WCSS\\_C\\_PC}     &     & Within-Cluster  Sum of Squares (centroids), \\% of TSS \\\\\n{\\tt BCSS\\_C}         &     & Between-Cluster Sum of Squares (centroids as centers) \\\\\n{\\tt BCSS\\_C\\_PC}     &     & Between-Cluster Sum of Squares (centroids), \\% of TSS \\\\\n\\hline\n{\\tt TRUE\\_SAME\\_CT}  &     & Same-category pairs predicted as Same-cluster, count \\\\\n{\\tt TRUE\\_SAME\\_PC}  &     & Same-category pairs predicted as Same-cluster, \\% \\\\\n{\\tt TRUE\\_DIFF\\_CT}  &     & Diff-category pairs predicted as Diff-cluster, count \\\\\n{\\tt TRUE\\_DIFF\\_PC}  &     & Diff-category pairs predicted as Diff-cluster, \\% \\\\\n{\\tt FALSE\\_SAME\\_CT} &     & Diff-category pairs predicted as Same-cluster, count \\\\\n{\\tt FALSE\\_SAME\\_PC} &     & Diff-category pairs predicted as Same-cluster, \\% \\\\\n{\\tt FALSE\\_DIFF\\_CT} &     & Same-category pairs predicted as Diff-cluster, count \\\\\n{\\tt FALSE\\_DIFF\\_PC} &     & Same-category pairs predicted as Diff-cluster, \\% \\\\\n\\hline\n{\\tt SPEC\\_TO\\_PRED}  & $+$ & For specified category, the best predicted cluster id \\\\\n{\\tt SPEC\\_FULL\\_CT}  & $+$ & For specified category, its full count \\\\\n{\\tt SPEC\\_MATCH\\_CT} & $+$ & For specified category, best-cluster matching count \\\\\n{\\tt SPEC\\_MATCH\\_PC} & $+$ & For specified category, \\% of matching to full count \\\\\n{\\tt PRED\\_TO\\_SPEC}  & $+$ & For predicted cluster, the best specified category id \\\\\n{\\tt PRED\\_FULL\\_CT}  & $+$ & For predicted cluster, its full count \\\\\n{\\tt PRED\\_MATCH\\_CT} & $+$ & For predicted cluster, best-category matching count \\\\\n{\\tt PRED\\_MATCH\\_PC} & $+$ & For predicted cluster, \\% of matching to full count \\\\\n\\hline\n\\end{tabular}}\n\\caption{The {\\tt O}-file for {\\tt Kmeans-predict} provides the output statistics\nin CSV format, one per line, in the following format: (NAME, [CID], VALUE).  Note:\nthe 1st group statistics are given if {\\tt X} input is available;\nthe 2nd group statistics are given if {\\tt X} and {\\tt C} inputs are available;\nthe 3rd and 4th group statistics are given if {\\tt spY} input is available;\nonly the 4th group statistics contain a nonempty CID value;\nwhen present, CID contains either the specified category label or the\npredicted cluster label.}\n\\label{table:kmeans:predict:stats}\n\\end{table}\n\n\n\\noindent{\\bf Details}\n\\smallskip\n\nOur clustering script proceeds in 3~stages: centroid initialization,\nparallel $k$-means iterations, and the best-available output generation.\nCentroids are initialized at random from the input records (the rows of~$X$),\nbiased towards being chosen far apart from each other.  The initialization\nmethod is based on the {\\tt k-means++} heuristic from~\\cite{ArthurVassilvitskii2007:kmeans},\nwith one important difference: to reduce the number of passes through~$X$,\nwe take a small sample of $X$ and run the {\\tt k-means++} heuristic over\nthis sample.  Here is, conceptually, our centroid initialization algorithm\nfor one clustering run:\n\\begin{Enumerate}\n\\item Sample the rows of~$X$ uniformly at random, picking each row with probability\n$p = ks / n$ where\n\\begin{Itemize}\n\\item $k$~is the number of centroids, \n\\item $n$~is the number of records, and\n\\item $s$~is the {\\tt samp} input parameter.\n\\end{Itemize}\nIf $ks \\geq n$, the entire $X$ is used in place of its sample.\n\\item Choose the first centroid uniformly at random from the sampled rows.\n\\item Choose each subsequent centroid from the sampled rows, at random, with\nprobability proportional to the squared Euclidean distance between the row and\nthe nearest already-chosen centroid.\n\\end{Enumerate}\nThe sampling of $X$ and the selection of centroids are performed independently\nand in parallel for each run of the $k$-means algorithm.  When we sample the\nrows of~$X$, rather than tossing a random coin for each row, we compute the\nnumber of rows to skip until the next sampled row as $\\lceil \\log(u) / \\log(1 - p) \\rceil$\nwhere $u\\in (0, 1)$ is uniformly random.  This time-saving trick works because\n\\begin{equation*}\n\\Prob [k-1 < \\log_{1-p}(u) < k] \\,\\,=\\,\\, p(1-p)^{k-1} \\,\\,=\\,\\,\n\\Prob [\\textrm{skip $k-1$ rows}]\n\\end{equation*}\nHowever, it requires us to estimate the maximum sample size, which we set\nnear~$ks + 10\\sqrt{ks}$ to make it generous enough.\n\nOnce we selected the initial centroid sets, we start the $k$-means iterations\nindependently in parallel for all clustering runs.  The number of clustering runs\nis given as the {\\tt runs} input parameter.  Each iteration of each clustering run\nperforms the following steps:\n\\begin{Itemize}\n\\item Compute the centroid-dependent part of squared Euclidean distances from\nall records (rows of~$X$) to each of the $k$~centroids using matrix product;\n\\item Take the minimum of the above for each record;\n\\item Update the current within-cluster sum of squares (WCSS) value, with centroids\nsubstituted instead of the means for efficiency;\n\\item Check the convergence criterion:\\hfil\n$\\textrm{WCSS}_{\\mathrm{old}} - \\textrm{WCSS}_{\\mathrm{new}} < \\eps\\cdot\\textrm{WCSS}_{\\mathrm{new}}$\\linebreak\nas well as the number of iterations limit;\n\\item Find the closest centroid for each record, sharing equally any records with multiple\nclosest centroids;\n\\item Compute the number of records closest to each centroid, checking for ``runaway''\ncentroids with no records left (in which case the run fails);\n\\item Compute the new centroids by averaging the records in their clusters.\n\\end{Itemize}\nWhen a termination condition is satisfied, we store the centroids and the WCSS value\nand exit this run.  A run has to satisfy the WCSS convergence criterion to be considered\nsuccessful.  Upon the termination of all runs, we select the smallest WCSS value among\nthe successful runs, and write out this run's centroids.  If requested, we also compute\nthe cluster assignment of all records in~$X$, using integers from 1 to~$k$ as the cluster\nlabels.  The scoring script can then be used to compare the cluster assignment with\nan externally specified category assignment.\n\n\\smallskip\n\\noindent{\\bf Returns}\n\\smallskip\n\nWe output the $k$ centroids for the best available clustering, i.~e.\\ whose WCSS\nis the smallest of all successful runs.\nThe centroids are written as the rows of the $k\\,{\\times}\\,m$-matrix into the output\nfile whose path/name was provided as the ``{\\tt C}'' input argument.  If the input\nparameter ``{\\tt isY}'' was set to~{\\tt 1}, we also output the one-column matrix with\nthe cluster assignment for all the records.  This assignment is written into the\nfile whose path/name was provided as the ``{\\tt Y}'' input argument.\nThe best WCSS value, as well as some information about the performance of the other\nruns, is printed during the script execution.  The scoring script {\\tt Kmeans-predict}\nprints all its results in a self-explanatory manner, as defined in\nTable~\\ref{table:kmeans:predict:stats}.\n\n\n\\smallskip\n\\noindent{\\bf Examples}\n\\smallskip\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f Kmeans.dml -nvargs X=/user/biadmin/X.mtx k=5 C=/user/biadmin/centroids.mtx fmt=csv\n\n}\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f Kmeans.dml -nvargs X=/user/biadmin/X.mtx k=5 runs=100 maxi=5000 \ntol=0.00000001 samp=20 C=/user/biadmin/centroids.mtx isY=1 Y=/user/biadmin/Yout.mtx verb=1\n\n}\n\\noindent To predict {\\tt Y} given {\\tt X} and {\\tt C}:\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f Kmeans-predict.dml -nvargs X=/user/biadmin/X.mtx\n         C=/user/biadmin/C.mtx prY=/user/biadmin/PredY.mtx O=/user/biadmin/stats.csv\n\n}\n\\noindent To compare ``actual'' labels {\\tt spY} with ``predicted'' labels given {\\tt X} and {\\tt C}:\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f Kmeans-predict.dml -nvargs X=/user/biadmin/X.mtx\n         C=/user/biadmin/C.mtx spY=/user/biadmin/Y.mtx O=/user/biadmin/stats.csv\n\n}\n\\noindent To compare ``actual'' labels {\\tt spY} with given ``predicted'' labels {\\tt prY}:\n\n{\\hangindent=\\parindent\\noindent\\tt\n\\hml -f Kmeans-predict.dml -nvargs spY=/user/biadmin/Y.mtx prY=/user/biadmin/PredY.mtx O=/user/biadmin/stats.csv\n\n}\n\n\\smallskip\n\\noindent{\\bf References}\n\\begin{itemize}\n\\item\nD.~Aloise, A.~Deshpande, P.~Hansen, and P.~Popat.\n\\newblock {NP}-hardness of {E}uclidean sum-of-squares clustering.\n\\newblock {\\em Machine Learning}, 75(2):245--248, May 2009.\n\\item\nD.~Arthur and S.~Vassilvitskii.\n\\newblock {\\tt k-means++}: The advantages of careful seeding.\n\\newblock In {\\em Proceedings of the 18th Annual {ACM-SIAM} Symposium on\n  Discrete Algorithms ({SODA}~2007)}, pages 1027--1035, New Orleans~{LA},\n  {USA}, January 7--9 2007.\n\\end{itemize}\n", "meta": {"hexsha": "0b8cbcdf255969cf7423f4520cc32359ce365d50", "size": 16744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "system-ml/docs/Algorithms Reference/Kmeans.tex", "max_stars_repo_name": "alcedo/systemml", "max_stars_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2018-03-17T18:03:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-25T08:17:09.000Z", "max_issues_repo_path": "system-ml/docs/Algorithms Reference/Kmeans.tex", "max_issues_repo_name": "alcedo/systemml", "max_issues_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "system-ml/docs/Algorithms Reference/Kmeans.tex", "max_forks_repo_name": "alcedo/systemml", "max_forks_repo_head_hexsha": "4d371a6d6b52e5517b1411302af3fdd8cd3c156a", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2017-11-26T00:43:09.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-02T06:29:30.000Z", "avg_line_length": 47.7037037037, "max_line_length": 112, "alphanum_fraction": 0.7266483516, "num_tokens": 4797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8705972784807406, "lm_q1q2_score": 0.7996263988440614}}
{"text": "\n\\subsection{Domains and ranges}\n\n\\subsubsection{Domain}\n\nAll values on which the function can be called\n\n\\(\\forall x(f(x)=y)\\rightarrow P(y))\\)\n\n\\subsubsection{Image}\n\n\\(\\forall x((\\exists y f(x)=y)\\rightarrow P(y))\\)\n\nOutputs of a function.\n\nAKA: Range\n\nThe image of \\(x\\) is \\(f(x)\\).\n\n\\subsubsection{Preimage}\n\nThe preimage of \\(y\\) is all \\(x\\) where \\(f(x)=y\\).\n\n\\subsubsection{Codomain}\n\nSometimes the image is a subset of another set. For example a function may map onto natural numbers above \\(0\\). Natural numbers above \\(0\\) would be the image, and the natural numbers would be the codomain.\n\n\\subsubsection{Example}\n\n\\(f(n)=s(n)\\)\n\nDomain is: \\(\\mathbb{N}\\)\n\nCodomain is also: \\(\\mathbb{N}\\)\n\nImage is \\(\\mathbb{N}\\land n\\ne 0\\)\n\n\\subsubsection{Describing  functions}\n\nIf function \\(f\\) maps from set \\(X\\) to set \\(Y\\) we can write this as:\n\n\\(f:X\\rightarrow Y\\)\n\n", "meta": {"hexsha": "fe904a82c7a517495d0cc86a1f54b08acb8c6548", "size": 877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/04-02-setsRanges.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/04-02-setsRanges.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/04-02-setsRanges.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.9318181818, "max_line_length": 207, "alphanum_fraction": 0.6784492588, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418262465169, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.7995897621793856}}
{"text": "\\pagebreak\n\\null\n\\newpage\n\\section{Appendix}\n\nIn this section we provide the necessary definitions and mathematical concepts necessary to properly introduce the weak formulation of a differential problem, the Galerkin method and finally the Finite Element Method.\\\\\n\n\\paragraph{Linear operators, functionals and bilinear forms} A \\textit{linear operator} $L: X\\to X$ from the Hilbert space $(X, \\norm \\cdot)$ to itself is a map such that $L(\\alpha x + \\beta y) = \\alpha L x + \\beta L y$. A linear operator on a Hilbert space is \\textit{continuous} (or {bounded}) if $\\exists M:\\ |Lx|\\leq Mx$. $(x, \\lambda)$ are called respectively \\textit{eigenvector} and \\textit{eigenvalue} of the linear operator $L$ if the image of $x$ through $L$ is a rescaling of $x$ of factor $\\lambda$ i.e. $Lx = \\lambda x$. The operator $L$ is called \\textit{self-adjoint} if $\\langle Lx, y\\rangle = \\langle x,Ly\\rangle\\ \\  \\forall x,y \\in X$. Self-adjoint operators have two important properties: their eigenvalues are real, and two eigenvectors $x, y$ associated to different eigenvalues $\\lambda, \\mu$ are orthogonal. Indeed \n\\begin{align*}\n\t\\langle Lx, y\\rangle &= \\langle x,Ly\\rangle,\\\\\n\t\\langle \\lambda x, y\\rangle &= \\langle x,\\mu y\\rangle,\\\\\n\t\\lambda \\langle  x, y\\rangle &= \\mu \\langle x, y\\rangle,\n\\end{align*}\nthat implies $ \\langle  x, y\\rangle = 0$. If the eigenvectors of a self-adjoint operator $L$ span the whole space $X$, then $L$ is called \\textit{diagonalisable}.  A linear operator from a Hilbert space $X$ to $\\mathbb R$ is called a linear \\textit{functional} on $X$. A functional is bounded if $\\exists M\\geq 0: \\ |Lx|\\leq M\\norm x$. The normed vector space made by the set of all linear bounded functionals on $X$ endowed with the norm $\\norm L = sup_{v\\in X}|Lv|/\\norm v$ is called the \\textit{dual} space of $X$ and is indicated with $X^\\star$. An important property of linear functionals is that for every functional $L\\in X^\\star$, there exists a unique vector $u\\in X$ such that\n$$Lv = \\langle u, v\\rangle\\quad \\forall v\\in X$$ \n\nA \\textit{bilinear form} on the vector space $X$ is a map $a(\\cdot, \\cdot): X\\times X\\to F$ that is linear with respect to both arguments. It is said to be \\textit{strongly coercive} if \\\\\n$\\exists\\alpha>0:\\ |a(x, x)|\\geq \\alpha \\norm {x}^2$, and \\textit{bounded} if $\\exists M>0:\\ |a(x, y)|\\leq M \\norm x \\norm y$.\n\n\\paragraph{The Lax-Milgram theorem}\nBefore introducing the Galerkin method the last thing to do is to state the Lax-Milgram theorem, theorem that is the foundation of the FEM formulation.\n\\vspace{0.5cm}\n\\begin{theorem}[Lax-Milgram]\n\tIf \\(a(\\cdot, \\cdot)\\) is a bounded and strongly coercive bilinear form on the Hilbert space \\(X\\),  $L\\in X^\\star$ is a linear bounded functional on $X$, there exist a unique solution $f$ to the following problem:\n\t\\begin{equation}\\label{eq:variational abstract problem}\n\t\\text{Find }f\\in X\\text{ such that } a(f, v)=Lv \\text{ for all } v \\in X\n\t\\end{equation}\n\tFor such \\(f\\) one has \\(\\|f\\| \\leq \\frac{1}{\\alpha}\\norm L\\) where \\(\\alpha>0\\) is the coercive constant \\\\\\(a(v, v) \\geq \\alpha\\norm v^{2} \\forall v \\in X.\\)\n\\end{theorem} \n\\vspace{0.5cm}\nThe Finite Element Method takes a PDE problem in strong form (\\ref{eq:strong form}), reformulates it in the equivalent \\textit{weak form} (\\ref{eq:variational abstract problem}) through suitable definitions of $X, a(\\cdot, \\cdot), L$ and finally solves it through polynomial interpolation.\n\\subsubsection{Weak formulation of a PDE and Galerkin Method}\n\nGalerkin's method is a method to approximate the solution $f$ of an infinite dimensional problem of the form (\\ref{eq:variational abstract problem}) with the solution $f_h$ of a finite dimensional problem. Our goal is now to explain how to write a differential problem like \n\\begin{align}\\label{eq:strong form}\n\\begin{split}\n&\\text{Given a regular domain }\\Omega\\subset\\mathbb R^2\\text{ and } u\\in C(\\Omega)\\text{, find }f\\in C^2(\\Omega) \\text{ such that}\\\\\n&\\begin{cases}\n-\\partial_{x_1x_1}f(\\mathbf x) - \\partial_{x_2x_2}f(\\mathbf x) = u(\\mathbf x) & \\mathbf x \\in \\Omega\\\\\nf(\\mathbf x) =  0& \\mathbf x \\in \\partial \\Omega\n\\end{cases}\n\\end{split}\n\\end{align}\nin the form \\ref{eq:variational abstract problem}. Let's multiply the differential equation times a sufficiently regular function $v$ that vanishes on $\\partial \\Omega$ and integrate on $\\Omega$. We obtain\n\\begin{align}\n\\begin{cases}\n-\\int_{\\mathbb S^2}\\Delta f(\\mathbf x)v(\\mathbf x)d\\mathbf x =\\int_{\\mathbb S^2} u(\\mathbf x)v(\\mathbf x)d\\mathbf x &\\quad \\mathbf x \\in \\Omega\\\\\nf(\\mathbf x) =  0&\\quad \\mathbf x \\in \\partial \\Omega\n\\end{cases}\t\n\\end{align}\n Since the contribution of both $f$ and $v$ on the border $\\partial \\Omega$ is zero, \\\\$\\int_{\\partial \\Omega}\\nabla f \\cdot \\mathbf nv d\\sigma=0$ and integrating by parts we get\n\n\\begin{equation}\\label{eq:int by parts}\n\t\\int_\\Omega \\nabla f(\\mathbf x)\\cdot\\nabla v(\\mathbf x) d\\mathbf x = \\int_\\Omega  u(\\mathbf x)\\cdot v(\\mathbf x)d\\mathbf x\n\\end{equation}\n\nBy defining $a(f, v):=\t\\int_\\Omega \\nabla f(\\mathbf x)\\cdot\\nabla v(\\mathbf x) d\\mathbf x $ and $Lv := \\int_\\Omega  u(\\mathbf x)\\cdot v(\\mathbf x)d\\mathbf x$ problem \\ref{eq:int by parts} can be written in the form of equation \\ref{eq:variational abstract problem}. It remains to choose a Hilbert space $(X, \\langle\\cdot,\\cdot\\rangle_X)$ such that (i) $X$ is \"big enough\" to include those functions such that all the integrals and derivatives in the problem \\ref{eq:int by parts} is well defined. This means that $X$ must include those functions $f$ such that $f, \\nabla f$ are in $L^2(\\Omega)$ and has to be \\textit{complete} with respect to the norm induced by the scalar product $\\langle\\cdot,\\cdot\\rangle_X$. At the same time $X$ must be (ii) \"small enough\" to include only those functions that vanish on the boundary of $\\Omega$. and (iii) the hypothesis of the Lax-Milgram theorem are satisfied, i.e. $a(\\cdot, \\cdot)$ is actually bounded and coercive and $L$ is bounded and linear. It turns out that such an Hilbert space exists: it is called $H^1_0(\\Omega)$, it contains all the functions $v$ such that $v\\in L^2(\\Omega), \\nabla v\\in L^2(\\Omega)$ and it is endowed with the scalar product \n$$\n\\langle u, v\\rangle_{H^1_0(\\Omega)} = \\int_\\Omega u(\\mathbf x)v(\\mathbf x)d\\mathbf x + \\int_\\Omega\\nabla u(\\mathbf x)\\cdot \\nabla v(\\mathbf x) d\\mathbf x\n$$\n$H^1_0$ contains only those functions that vanish on $\\delta \\Omega$ i.e. \\\\$f\\in H^1_0(\\Omega)\\cap C(\\Omega) \\implies \\left.f(\\mathbf x)\\right|_{\\partial\\Omega}=0$. This means that thanks to Lax-Milgram theorem the problem\n\n\\begin{equation}\\label{eq:final variational form}\n\\begin{split}\n\t&\\text{Given }u\\in L^2(\\Omega)\\text{ find }f\\in H^1_0(\\Omega)\\text{ such that }\\\\\n\t&\\int_\\Omega \\nabla f(\\mathbf x)\\cdot\\nabla v(\\mathbf x) d\\mathbf x = \\int_\\Omega  u(\\mathbf x)\\cdot v(\\mathbf x)d\\mathbf x\\quad \\forall v\\in H^1_0(\\Omega)\n\\end{split}\n\\end{equation}\n\n\\textit{has one and only one solution in} $H^1_0(\\Omega)$. However, to have this result (existence and uniqueness of the solution) we had to pay the price of looking for the solution $f$ in $H^1_0(\\Omega)$, a much bigger space than  $C^2(\\Omega)$ that we had in the original, strong form of the problem. This means that our solution $f\\in H^1_0(\\Omega)$ to the problem (\\ref{eq:final variational form}) could not be a solution to problem (\\ref{eq:strong form}), because it could be not regular enough and the second derivative $\\Delta f$ could not exist! Fortunately there are regularity results - that we omit here - that assure that if the forcing term $u$ is regular enough, then also the solution $f$ will be regular and thus the two formulations - strong and weak - of the problem are actually equivalent, and thus solving \\ref{eq:final variational form} eventually leads to solving \\ref{eq:strong form}.\n\nNow that we know that a solution exists, we need to compute it! Computing it analytically is often impossible; Galerkin's method in a mathematical tool provide us a way to compute an approximation of the solution $f$. Take the weak problem \\ref{eq:variational abstract problem}, but restrict the ambient space to be a finite dimensional subspace of $X$, say $V_h = \\text{span}\\{\\phi_0, ..., \\phi_{n-1}\\}$. We write thus the Galerkin problem\n\\vspace{0.5cm}\n\n\\begin{equation}\\label{eq:Galerkin problem}\n\t\t\\text{Find }f_h\\in V_h\\text{ such that } a(f_h, v_h)=\\langle u_h, v_h\\rangle \\text{ for all } u_h \\in V_h\n\\end{equation}\n\\vspace{0.5cm}\n\nThe key property of the Galerkin method is that the error $f-f_h$ is orthogonal to $V_h$; thus by choosing a sequence of finite dimensional spaces that fill the original space $X$, we can get as close as we want to the continuous solution $f$.\nTo solve equation \\ref{eq:Galerkin problem} we write $f_h, u_h, v$ as linear combinations of the basis $\\{\\phi_0, ..., \\phi_{n-1}\\}$\n\\begin{equation}\\label{eq:basis functions}\n\t\\begin{cases}\n\tf_h = f_0\\phi_0 +  f_1\\phi_1 + ...  f_{n-1}\\phi_{n-1}\\\\\n\tu_h = u_0\\phi_0 +  u_1\\phi_1 + ...  u_{n-1}\\phi_{n-1}\\\\\n\tv_h = v_0\\phi_0 +  v_1\\phi_1 + ...  v_{n-1}\\phi_{n-1}\n\t\\end{cases}\n\\end{equation}\n thus obtaining by linearity of the bilinear form and of the scalar product a linear system of equations in the $n$ coordinates of $f_h$\n\\begin{equation}\\label{eq:Galerkin problem in the basis functions}\n\\text{Find }\\mathbf f\\in\\mathbb R^n\\text{ such that } \\sum_{j=0}^{n-1}a(\\phi_i, \\phi_j)f_j=\\sum_{j=0}^{n-1}\\langle \\phi_i, \\phi_j\\rangle u_j \\text{ for all } i=0, ... n-1\n\\end{equation}\n\nDefining the \\textit{stiffness matrix} $(A)_{ij} = a(\\phi_i, \\phi_j)$ and the \\textit{mass matrix} \\\\$(B)_{ij} = \\langle \\phi_i, \\phi_j\\rangle$ we can rewrite problem \\ref{eq:Galerkin problem in the basis functions} in the following algebraic form\n\\begin{equation}\\label{eq:Galerkin algebraic}\n\\text{Find }\\mathbf f\\in\\mathbb R^n\\text{ such that } A\\mathbf f = B \\mathbf u\n\\end{equation}\nwhere $\\mathbf f, \\mathbf u$ are the vectors of coordinates of $f_h, u_h$ with respect to the basis $(\\phi_i)$. \n\\vspace{0.5cm}\n\\begin{remark}\n\t If the basis functions $\\phi_i$ are orthonormal, then the mass matrix $B$ is the identity matrix. Furthermore, the scalar product in the space $V_h$ of two functions $u_h, v_h$ is equal to the dot product defined by the mass matrix $B$ in $\\mathbb R^n$ of the coordinate vectors\n\t\\begin{equation}\\label{eq:dot product}\n\t\\langle u_h, v_h\\rangle = \\mathbf u^\\intercal B \\mathbf v\n\t\\end{equation}\n\tThe Galerkin method \\ref{eq:Galerkin problem} is well posed by a straight-forward application of the Lax-Milgram theorem, and thus also the system \\ref{eq:Galerkin algebraic} admits one and only one solution.\n\\end{remark}\n\n \\subsubsection{The Finite Element Method}\n \n  The Finite Element Method is a technique that let us construct a particular subspace $V_h$ in (\\ref{eq:Galerkin problem}) through polynomial interpolation. Let's refer again to the problem \\ref{eq:strong form} defined on the domain $\\Omega\\subset\\mathbb R^2$ in figure \\ref{fig:omega and mesh}. \n \\paragraph{Approximation of the domain $\\Omega$}\n\\begin{figure}[h]\n\t\\centering\n\t\\includegraphics[width=0.4\\textwidth]{figs/Chapter3/omega.png}\n\t\\includegraphics[width=0.4\\textwidth]{figs/Chapter3/mesh.png}\n\t\\caption{\\label{fig:omega and mesh}The domain $\\Omega$ and its approximation $\\mathcal T_h$}\n\\end{figure}\nFirst we need to construct a discretization of the continuous domain $\\Omega$. In this example we take the triangulation in figure \\ref{fig:omega and mesh} $\\mathcal T_h = \\left\\{\\tau_{k} : 1 \\leq k \\leq q\\right\\}$, where $h\\in\\mathbb R$ is a parameter such that every edge of the triangles $\\tau_k\\in\\mathcal T_h$ is smaller than $h$. $\\mathcal T_h$ is such that \n\\begin{itemize}\n\t\\item The elements \\(\\tau \\in \\mathcal{T}_h\\) are closed subsets of \\(\\Omega\\) with pairwise disjoint interior and \\({\\Omega}_h=\\bigcup_{\\tau \\in \\mathcal{T}_h} \\tau\\)\n\t\\item The triangulation \\(\\mathcal{T}_h\\) has no hanging vertices.\n\\end{itemize}\n\nIt's clear that by discretizing the continuous domain $\\Omega$ we introduce a first source of errors in the method; however for simplicity we won't take this into account in the next discussion, and we will identify the domain $\\Omega$ with the domain $\\Omega_h$ covered by $\\mathcal T_h$. The quality of the \\textit{mesh} $\\mathcal T_h$ is important for a good solution; a good quality mesh should avoid triangles with extreme angles and every triangle of $\\mathcal T_h$ should look like as much as possible to an equilateral triangle. In figure \\ref{fig:bad mesh} we see an example of a bad quality mesh: its triangles look very stretched; there are vertices that are shared by many triangles and vertices that are shared by very few. In figure \\ref{fig:omega and mesh} we see a better mesh: there are no stretched triangles, and every vertex is shared by an almost constant number of triangles.\n\\begin{wrapfigure}{r}{0.3\\textwidth}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.4\\textwidth]{figs/Chapter3/badmesh.png}\n\t\t\\caption{\\label{fig:bad mesh}A bad quality mesh}\n\t\\end{center}\n\t\n\\end{wrapfigure}\n\\paragraph{Choosing $V_h$ and the basis functions $\\phi_i$}\n\nBeyond $X_h^1$, explained in section \\ref{sec:Chapter3:FEM on the sphere}, other choices for $V_h$ are possible. A common choice is the space $X_h^{2}$ that is the space of all the piecewise second-order polynomials. In this case, since every second order polynomial in $\\mathbb R^2$ has 6 degrees of freedom per each triangle $\\tau_k$, meaning that we need to know its values in at least 6 different points on the triangle $\\tau_k$ to uniquely identify it, the dimension of the space will grow (figure \\ref{fig:elements}). A bigger space means that the approximation $f_h$ will be better, but we'll need more basis functions to define and thus it will result in a bigger linear system $Af = Bu$ and higher computational costs.\n\\begin{figure}[h!]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.4\\textwidth]{figs/Chapter3/elemntsP1P2.png}\n\t\\end{center}\n\t\\caption{\\label{fig:elements}The degrees of freedom (DOF) for $X_h^{1}$ and $X_h^{2}$ on a reference triangle}\n\\end{figure}\n\\paragraph{Assembling the stiffness and mass matrices}\nOnce defined the basis functions $\\phi_i$, the FEM method constructs the stiffness matrix and the mass matrix $(A)_{ij} = a(\\phi_i, \\phi_j),\\  (B)_{ij}=\\langle\\phi_i,\\phi_j\\rangle$ and solves the linear system \\ref{eq:Galerkin algebraic} for the coefficients $f_i$ of the FEM solution $f_h$. An important fact to notice is both matrices $A$ and $B$ are \\textit{sparse} and share the same sparsity pattern. Due to the form of the basis function $\\phi_i$, the element $(i, j)$ of these matrices is different from zero only if the supports of the corresponding basis functions $(\\phi_i, \\phi_j)$ overlap, meaning that the vertices $(x_i, x_j)$ are connected by an edge of the mesh $\\mathcal T_h$. In other words, the number of non-null entries of the $i-th$ row of $A$ and $B$ is equal to number of triangles of the mesh $\\mathcal T_h$ that share the $i$th vertex i.e., the degree of the $i-th$ vertex.\n\n\\paragraph{About the boundary conditions}\n\tNote that the Dirichlet boundary conditions in the strong formulation of the differential problem \\ref{eq:strong form} got transformed in the weak formulation \\ref{eq:final variational form} as a condition on the ambient space $H_0^1(\\Omega)$. Other kind of boundary conditions (Neumann, Robin for example) would not translate into the condition on the ambient space that functions must vanish on the border, but instead they would impose a different formulation of the bilinear form $a(\\cdot, \\cdot)$ or of the functional $L$. For this reason, Dirichlet boundary conditions are called \\textit{essential} since translated into a condition on the ambient space and thus automatically satisfied from the FEM formulation; Neumann boundary conditions are called \\textit{natural} since they transform into a different weak formulation through a modification of the bilinear form $a(\\cdot, \\cdot)$ and/or the functional $L$.\n\n", "meta": {"hexsha": "b6bf4ee926d85dec0a00d0d0ff3b30eb06930f19", "size": 15957, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/5.Appendix.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/5.Appendix.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/5.Appendix.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": 108.5510204082, "max_line_length": 1197, "alphanum_fraction": 0.7344738986, "num_tokens": 4804, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.8652240704135291, "lm_q1q2_score": 0.799589748929059}}
{"text": "\n\\subsection{Tensor product}\n\nWe have spaces \\(V\\) and \\(W\\) over field \\(F\\). If we have a linear operation which takes a vector from each space and returns a scalar from the underlying field, it is an element of the tensor product of the two spaces.\n\nFor example if we have two vectors:\n\n\\(v=e_iv^i\\)\n\n\\(w=e_jw^j\\)\n\nA tensor product would take these and return a scalar.\n\nThere are three types of tensor products:\n\n\\begin{itemize}\n\\item Both are from the vector space\n\\item \\(T_{ij}v^iw^j\\)\n\\item \\(T_{ij} \\in V\\otimes W\\)\n\\item Both are from the dual space\n\\item \\(T^{ij}v_iw_j\\)\n\\item \\(T_{ij} \\in V^*\\otimes W^*\\)\n\\item One is from each space\n\\item \\(T_i^jv^iw_j\\)\n\\item \\(T_{ij} \\in V\\otimes W^*\\)\n\\end{itemize}\n\n\nAs a vector space, we can add together tensor products, and do scalar multiplication.\n\n\\subsubsection{Basis of a tensor product}\n\nNot all elements spanned by a basis of a tensor product are themselves tensor products.\n\n\\subsubsection{Eigenvalues and Eigenvectors of a tensor product}\n\n\\subsubsection{Homomorphisms}\n\nWe can define homomorphisms in terms of tensor products.\n\n\\(Hom (V) =V \\otimes V^*\\)\n\n\\(T_j^i\\)\n\nWe use the dual space for the second argument. This is because it ensures that changes to the bases do not affect the maps.\n\n\\(w^j=T_i^j v^i\\)\n\n", "meta": {"hexsha": "35edfe90eedae7c5bfa149912fd64f75cd7c3bf6", "size": 1277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/02-01-tensorProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/02-01-tensorProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/02-01-tensorProduct.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.0612244898, "max_line_length": 221, "alphanum_fraction": 0.7227877839, "num_tokens": 373, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.799589746717702}}
{"text": "% This is the LaTeX file for the chapter:\r\n%   Public-Key Encryption\r\n% for the manual:\r\n%   Highly Secure Systems\r\n% Written by Andrew Ensor\r\n% Last updated 12 December 2018.\r\n\r\n\\chapter{Public-Key Encryption}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%% Modular Arithmetic                                                            %%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\section{Modular Arithmetic}\r\nBesides its importance for AES, the modular arithmetic operations in the ring\r\n$\\mathbb{Z}_n$ have an important role in public-key encryption.\r\nCalculating an arithmetic expression modulo $n$ can be simplified by taking the modulo of\r\neach term before performing the arithmetic operations:\r\n\\begin{eqnarray*}\r\n  (a+b)\\mbox{ mod }n &=& ((a\\mbox{ mod }n)+(b\\mbox{ mod }n))\\mbox{ mod }n \\\\\r\n  (a-b)\\mbox{ mod }n &=& ((a\\mbox{ mod }n)-(b\\mbox{ mod }n))\\mbox{ mod }n \\\\\r\n  (a\\cdot b)\\mbox{ mod }n &=& ((a\\mbox{ mod }n)\\cdot(b\\mbox{ mod }n))\\mbox{ mod }n.\r\n\\end{eqnarray*}\r\nPrime numbers turn out to be very useful when performing modular arithmetic.\r\nThe following fundamental result demonstrates the importance of prime numbers in number theory.\r\n\r\n\\begin{theorem}{Unique Prime Factorization}\r\nEvery integer $a>1$ can be factorized in a unique way as a product of prime numbers:\r\n\\begin{displaymath}\r\n  a = p_1^{a_1} p_2^{a_2} \\dots p_t^{a_t}\r\n\\end{displaymath}\r\nwhere $p_1<p_2<\\cdots<p_t$ are prime numbers and the exponents\r\n$a_1,a_2,\\dots,a_t$ are positive integers.\r\n\\end{theorem}\r\n\r\nFor example:\r\n\\begin{eqnarray*}\r\n  21600 &=& 2^5\\cdot3^3\\cdot5^2 \\\\\r\n  49000 &=& 2^3\\cdot5^3\\cdot7^2 \\\\\r\n  65535 &=& 3^1\\cdot5^1\\cdot17^1\\cdot257^1 \\\\\r\n  65536 &=& 2^{16} \\\\\r\n  65537 &=& 65537^1 \\qquad\\mbox{ as $65537$ is itself prime}.\r\n\\end{eqnarray*}\r\n\r\nAs a consequence, if a prime $p$ divides a product $ab$ then it must be one of the primes\r\nin the factorization of the product $ab$ and thus also be a prime in the factorization\r\nof either $a$ or of $b$, so must divide either $a$ or $b$ (or both).\r\n\r\n\\begin{theorem}{Fermat's Theorem}\r\nIf $p$ is a prime number and $a$ is a positive integer not divisible by $p$ then\r\n$a^{p-1} \\mbox{ mod } p = 1$.\r\n\\end{theorem}\r\n\r\nAs an example, $7$ is a prime number that does not divide $21600$ (as $7$ does not\r\nappear in its prime factorization). Hence $21600^6\\mbox{ mod }7=1$.\r\n\r\nTo see why Fermat's Theorem is true consider the numbers $1, 2, \\dots, p-1$, multiply\r\neach number by $a$ and take the remainder modulo $p$ to get the set:\r\n\\begin{displaymath}\r\n  \\{a\\mbox{ mod }p, 2a\\mbox{ mod }p, \\dots, (p-1)a\\mbox{ mod }p\\}.\r\n\\end{displaymath}\r\nNote that none of the elements in this set are $0$, which can be\r\nseen by using a proof by contradiction (if $ia\\mbox{ mod }p=0$\r\nfor some $i$ with $1\\leq i\\leq p-1$ then $p$ divides $ia$, but $p$ does not\r\ndivide $a$ so $p$ must divide $i$, which is not possible).\r\nFurthermore, all the elements of this set are distinct from each other,\r\nwhich can also be seen by using a proof by contradiction\r\n(if $ia\\mbox{ mod }p = ja\\mbox{ mod }p$  where\r\n$1\\leq i<j\\leq p-1$ then $p$ must divide $(j-i)a$,\r\nbut as $a$ is not divisible by $p$, $p$ must be divide $j-i$,\r\nwhich is not possible as both $i<p$ and $j<p$).\r\nHence this set is just a permutation of $\\{1, 2, \\dots, p-1\\}$.\r\nMultiplying all the elements together therefore gives:\r\n\\begin{eqnarray*}\r\n  (a\\mbox{ mod }p)\\cdot(2a\\mbox{ mod }p)\\cdot\\dots\\cdot((p-1)a\\mbox{ mod }p)\r\n    &=& 1\\cdot2\\cdot\\dots\\cdot(p-1) \\\\\r\n  (a\\cdot2a\\cdot\\dots\\cdot(p-1)a)\\mbox{ mod }p\r\n    &=& (p-1)!\\mbox{ mod }p \\\\\r\n  a^{p-1} (p-1)!\\mbox{ mod }p &=& (p-1)!\\mbox{ mod }p\r\n\\end{eqnarray*}\r\nSo $p$ divides $(a^{p-1}-1)(p-1)!$. As $p$ does not divide $(p-1)!$ it must divide\r\n$a^{p-1}-1$ which verifies Fermat's Theorem.\r\n\r\nNow, if $p$ is an odd prime number then $p-1$ is even and so\r\n$p-1=2^k q$ for some $k\\geq1$ and odd value of $q$.\r\nHence for any $a<p$ Fermat's Theorem gives that $a^{2^k q}\\mbox{ mod }p=1$.\r\nAs a consequence since $p$ is prime, it can be shown that the values:\r\n\\begin{displaymath}\r\n  a^q\\mbox{ mod }p, a^{2q}\\mbox{ mod }p, a^{2^2 q}\\mbox{ mod }p,\r\n  a^{2^3 q}\\mbox{ mod }p, \\dots, a^{2^k q}\\mbox{ mod }p=1\r\n\\end{displaymath}\r\nwhere each term is the square of the previous modulo $p$,\r\nare either all $1$ or else one is equal to $-1\\mbox{ mod }p=p-1$ and the next is $1$.\r\nInterestingly, for an odd value of $n$ that is not a prime\r\nif a random value of $a<n-1$ is chosen it has probability less than\r\n$\\frac{1}{4}$ of satisfying this condition.\r\nThis gives a simple $O(\\log_2 n)$ technique for determining whether a number is\r\n\\defn{probably prime} which can be much more efficient than the brute-force $O(\\sqrt{n})$\r\napproach of checking whether any of the numbers\r\n$2, 3, \\dots, \\sqrt{n}$ divide $n$.\r\nIf $\\proc{Probably-Prime}(n)$ returns $\\const{false}$ then $n$ is definitely\r\nnot a prime, whereas if it returns $\\const{true}$ then the probability\r\nthat it is a prime is at least $\\frac{3}{4}$.\r\n\r\n\\begin{figure*}[htb]\r\n\\begin{codebox}\r\n\\Procname{$\\proc{Probably-Prime}(n)$}\r\n\\li \\Comment determine whether the odd value of $n>2$ is probably a prime\r\n\\li Find integers $k$ and $q$ for which $n-1=2^k q$\r\n\\li \\Comment pick a random integer between $2$ and $n-1$ exclusive to use in test\r\n\\li $a \\gets \\proc{Random(2, $n-1$)}$\r\n\\li $\\id{current} \\gets a^q\\mbox{ mod }n$\r\n\\li \\If $\\id{current}=1$ \\Then\r\n\\li    \\Return \\const{true} \\`\\Comment $n$ is probably a prime\r\n    \\End\r\n\\li \\For $i \\gets 1$ \\To $k$ \\Do\r\n\\li    $\\id{next} \\gets \\id{current}^2\\mbox{ mod }n$\r\n\\li    \\If $\\id{next}=1$ \\Then\r\n\\li       \\If $\\id{current}\\neq n-1$ \\Then\r\n\\li          \\Return \\const{false} \\`\\Comment $n$ is definitely not a prime\r\n\\li       \\Else\r\n\\li          \\Return \\const{true} \\`\\Comment $n$ is probably a prime\r\n          \\End\r\n       \\End\r\n\\li    $\\id{current}\\gets\\id{next}$\r\n    \\End\r\n\\li \\Comment After end of loop it must be that $\\id{current}\\neq1$\r\n\\li \\Return \\const{false} \\`\\Comment $n$ is definitely not a prime\r\n\\end{codebox}\r\n\\begin{codebox}\r\n\\Procname{$\\proc{Miller-Rabin}(n,s)$}\r\n\\li \\If $n=2$ \\Then\r\n\\li    \\Return \\const{true}\r\n\\li  \\ElseIf  $n\\mbox{ mod }2=0$ \\Then\r\n\\li    \\Return \\const{false} \\`\\Comment $n$ is even\r\n    \\End\r\n\\li \\Comment test whether $n$ is a prime $s$ times\r\n\\li \\For $j\\gets1$ \\To $s$ \\Do\r\n\\li    \\If not $\\proc{Probably-Prime}(n)$ \\Then\r\n\\li       \\Return \\const{false} \\`\\Comment $n$ is definitely not a prime\r\n       \\End\r\n    \\End\r\n\\li \\Return \\const{true} \\`\\Comment $n$ is probably a prime with prob at least $1-\\frac{1}{4^s}$\r\n\\end{codebox}\r\n\\end{figure*}\r\nThe \\defn{Miller-Rabin} algorithm simply repeatedly tests $\\proc{Probably-Prime}(n)$\r\n$s$ times, and will mistakenly claim that an odd value of $n$ is a prime\r\nwith probability less than $\\frac{1}{4^s}$. Thus the algorithm can be\r\nused to determine with any desired probability whether a value of $n$ is a\r\nprime, simply by choosing a large enough value of $s$.\r\nIn fact, if $n$ is a randomly chosen large number it can be shown that\r\ntaking $s=3$ is very unlikely to lead to a false result\r\n(the non-prime \\defn{Carmichael numbers} such as $561$, $1105$, $1729$\r\ndo always get mistaken by the Miller-Rabin algorithm,\r\nbut they are extremely rare with only 255 such numbers less than $100000000$).\r\n\r\nIf $n$ is a positive integer then the \\defn{Euler totient function} $\\phi(n)$\r\nis the number of positive integers $m$ less than $n$ that are\r\n\\defn{relatively prime} to $n$, meaning that $\\mbox{gcd}(m,n)=1$.\r\nBy convention one takes $\\phi(1)=1$.\r\n\r\n\\begin{figure*}[htb]\\begin{center}\r\n\\begin{tabular}{|r|r||r|r||r|r||r|r||r|r|} \\hline\r\n  \\multicolumn{10}{|l|}{\\textit{Euler Totient Function for Small Values of $n$}} \\\\ \\hline\\hline\r\n  \\textit{$n$} & \\textit{$\\phi(n)$} & \\textit{$n$} & \\textit{$\\phi(n)$}\r\n  & \\textit{$n$} & \\textit{$\\phi(n)$} & \\textit{$n$} & \\textit{$\\phi(n)$}\r\n  & \\textit{$n$} & \\textit{$\\phi(n)$} \\\\ \\hline\r\n  1 & 1 & 2 & 1 & 3 & 2 & 4 & 2 & 5 & 4 \\\\\r\n  6 & 2 & 7 & 6 & 8 & 4 & 9 & 6 & 10 & 4 \\\\\r\n  11 & 10 & 12 & 4 & 13 & 12 & 14 & 6 & 15 & 8 \\\\\r\n  16 & 8 & 17 & 16 & 18 & 6 & 19 & 18 & 20 & 8 \\\\\r\n  21 & 12 & 22 & 10 & 23 & 22 & 24 & 8 & 25 & 20 \\\\\r\n  26 & 12 & 27 & 18 & 28 & 12 & 29 & 28 & 30 & 8 \\\\\\hline\r\n\\end{tabular}\r\n\\end{center}\\end{figure*}\r\n\r\nFor example, to find $\\phi(18)$ one lists the numbers $1$ to $17$ and removes\r\nthose that are not relatively prime to $18$:\r\n\\begin{displaymath}\r\n  \\mathbf{1}, \\mathit{2}, \\mathit{3}, \\mathit{4}, \\mathbf{5}, \\mathit{6},\r\n  \\mathbf{7}, \\mathit{8}, \\mathit{9}, \\mathit{10}, \\mathbf{11}, \\mathit{12},\r\n  \\mathbf{13}, \\mathit{14}, \\mathit{15}, \\mathit{16}, \\mathbf{17}.\r\n\\end{displaymath}\r\nOnly $6$ numbers remain and so $\\phi(18)=6$.\r\n\r\nIf $p$ is a prime then clearly all positive integers less than $p$ are relatively\r\nprime to $p$ and so $\\phi(p)=p-1$. Also, it is not difficult to show that\r\nif $p$ and $q$ are distinct primes then $\\phi(pq)=(p-1)(q-1)$.\r\nDetermining $\\phi(n)$ for most other values of $n$ can be shown to be about as difficult\r\nas is determining the unique prime factorization of $n$, which is usually quite difficult\r\nfor large values of $n$.\r\n\r\nThe following result generalizes Fermat's Theorem for the case when arithmetic\r\nis taken modulo a value $n$ that might not be a prime. It can be proved in almost\r\nexactly the same way as Fermat's Theorem, but by starting with the $\\phi(n)$ numbers\r\nthat are relatively prime to $n$.\r\n\r\n\\begin{theorem}{Euler's Theorem}\r\n  If $n$ and $a$ are positive integers that are relatively prime then\r\n  $a^{\\phi(n)}\\mbox{ mod }n = 1$.\r\n\\end{theorem}\r\n\r\nFor example, $18$ and $35$ are relatively prime as $\\mbox{gcd}(18,35)=1$\r\n(this can also be seen as their prime factorizations have no primes in common).\r\nAs $\\phi(18)=6$ Euler's Theorem gives that $35^6\\mbox{ mod }18=1$.\r\n\r\nThe following result is also useful for performing modular arithmetic.\r\nIt states that arithmetic in $\\mathbb{Z}_n$ can be performed by using (simpler)\r\narithmetic in $\\mathbb{Z}_{n_i}$ for some relatively prime divisors $n_i$ of $n$.\r\n\r\n\\begin{theorem}{Chinese Remainder Theorem}\r\n  Suppose $n=n_1n_2\\dots n_k$ where $n_1, n_2, \\dots, n_k$ are all relatively prime,\r\n  and define the function\r\n  $f\\colon\\mathbb{Z}_n\\to\\mathbb{Z}_{n_1}\\times\\mathbb{Z}_{n_2}\\times\\dots\\times\\mathbb{Z}_{n_k}$\r\n  by:\r\n  \\begin{displaymath}\r\n    f(a) = \\left( a\\mbox{ mod }n_1, a\\mbox{ mod }n_2, \\dots, a\\mbox{ mod }n_k \\right).\r\n  \\end{displaymath}\r\n  Then $f$ is a bijection for which:\r\n  \\begin{eqnarray*}\r\n    f(a+b) &=& f(a)+f(b) \\\\\r\n    f(a-b) &=& f(a)-f(b) \\\\\r\n    f(a\\cdot b) &=& f(a)\\cdot f(b).\r\n  \\end{eqnarray*}\r\n  where arithmetic in $\\mathbb{Z}_n$ is taken modulo $n$ and in\r\n  $\\mathbb{Z}_{n_1}\\times\\mathbb{Z}_{n_2}\\times\\dots\\times\\mathbb{Z}_{n_k}$ is taken\r\n  modulo $n_i$ in each coordinate.\r\n  The inverse $f^{-1}\\colon\r\n  \\mathbb{Z}_{n_1}\\times\\mathbb{Z}_{n_2}\\times\\dots\\times\\mathbb{Z}_{n_k}\\to\\mathbb{Z}_n$\r\n  is given by:\r\n  \\begin{displaymath}\r\n    f^{-1}\\left( a_1, a_2, \\dots, a_k \\right)\r\n    = \\left( a_1c_1+a_2c_2+\\cdots+a_kc_k \\right)\\mbox{ mod }n,\r\n  \\end{displaymath}\r\n  where each $c_i=(n/n_i)\\cdot d_i$\r\n  and $d_i$ is the value in $\\mathbb{Z}_{n_i}$ for which\r\n  $(n/n_i)\\cdot d_i\\mbox{ mod }n_i=1$ ($d_i$ can be obtained by the Euclidean algorithm).\r\n\\end{theorem}\r\n\r\nTo illustrate the Chinese Remainder Theorem, suppose $a$ is a value for which\r\n$a\\mbox{ mod }5=3$ and $a\\mbox{ mod }12=7$. To determine the value of $a$\r\n(which is unique modulo $5\\cdot12=60$) one approach would be to make a table of all values\r\nbetween $0$ and $59$ where the rows have the same remainder modulo $5$ and\r\nthe columns have the same remainder $12$. Then the correct value of $a$\r\ncan be read off the row with remainder $3$ and column with remainder $7$,\r\ngiving $a=43$.\r\n\\begin{figure*}[htb]\\begin{center}\r\n\\begin{tabular}{|c||rrrrrrrrrrrr|} \\hline\r\n  \\multicolumn{13}{|l|}{\\textit{Values of $a$ between $0$ and $59$\r\n    with remainders modulo $5$ and modulo $12$}} \\\\ \\hline\\hline\r\n  \\textit{Remainders} & \\textit{$0$} & \\textit{$1$} & \\textit{$2$} & \\textit{$3$}\r\n  & \\textit{$4$} & \\textit{$5$} & \\textit{$6$} & \\textit{$7$}\r\n  & \\textit{$8$} & \\textit{$9$} & \\textit{$10$} & \\textit{$11$} \\\\ \\hline\\hline\r\n  \\textit{$0$} & 0 & 25 & 50 & 15 & 40 & 5 & 30 & 55 & 20 & 45 & 10 & 35 \\\\\r\n  \\textit{$1$} & 36 & 1 & 26 & 51 & 16 & 41 & 6 & 31 & 56 & 21 & 46 & 11 \\\\\r\n  \\textit{$2$} & 12 & 37 & 2 & 27 & 52 & 17 & 42 & 7 & 32 & 57 & 22 & 47 \\\\\r\n  \\textit{$3$} & 48 & 13 & 38 & 3 & 28 & 53 & 18 & 43 & 8 & 33 & 58 & 23 \\\\\r\n  \\textit{$4$} & 24 & 49 & 14 & 39 & 4 & 29 & 54 & 19 & 44 & 9 & 34 & 59 \\\\\\hline\r\n\\end{tabular}\\end{center}\r\n\\end{figure*}\r\nAlternatively, as $n_1=5$ and $n_2=12$ are relatively prime the Chinese Remainder Theorem\r\ncan be used to find $a=f^{-1}(3,7)$. Let $n=n_1\\cdot n_2=60$,\r\nso that $n/n_1=12$ and $n/n_2=5$. Then $d_1$ is the value for which\r\n$12\\cdot d_1\\mbox{ mod }5=1$, which by the Euclidean algorithm can be found to be\r\n$d_1=3$. Similarly, $d_2$ is the value for which $5\\cdot d_2\\mbox{ mod }12=1$,\r\nwhich is $d_2=5$. Then $c_1=(n/n_1)\\cdot d_1=12\\cdot3=36$ and\r\n$c_2=(n/n_2)\\cdot d_2=5\\cdot5=25$.\r\nNow any value of $f^{-1}(a_1,a_2)$ can be found, such as\r\n$a=f^{-1}(3,7)=(3\\cdot36+7\\cdot25)\\mbox{ mod }60=43$.\r\n\r\n\r\n\\begin{exercise}[Random Prime Generator]\r\n  Prepare a program that can generate a cryptographically strong large random prime number\r\n  (for a very large number you might like to make use of the\r\n  \\begin{code}BigInteger\\end{code} class that is in the \\begin{code}java.math\\end{code}\r\n  package).\r\n\\end{exercise}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%% RSA Algorithm                                                                 %%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\section{RSA Algorithm}\\label{Se:RSAAlgorithm}\r\nThe concept of public-key cryptography was introduced as a way to\r\ndistribute secret keys without resorting to physical distribution,\r\nand as a way to authenticate the sender of a message.\r\nPublic-key cryptography uses two keys, a \\defn{public key} which is\r\nusually publicly available and a \\defn{private key} which must\r\nbe kept confidential. Encrypting plaintext using one of the keys\r\nresults in ciphertext which should only be able to be decrypted\r\nwith the other key. Hence the holder of the private key should be the\r\nonly one that can decrypt messages encoded by anyone using the public key,\r\nenabling others to encrypt messages that they send to the holder.\r\nThe holder should also be the only one that can encrypt messages that\r\nget decrypted by anyone using the public key, enabling others\r\nto authenticate that a message was produced by the holder\r\n(provided they are certain of the origin of the public key).\r\n\r\nOne of the first public-key ciphers and currently the most-popular\r\npublic key block cipher\r\nwas developed by Rivest, Shamir, Adleman and known as the \\defn{RSA algorithm}.\r\nThe public and private keys are calculated with the following steps:\r\n\\begin{enumerate}\r\n  \\item two large prime numbers $p$ and $q$ are selected at random,\r\n  typically each at least 512 bits,\r\n  \\item the product $n=pq$ is calculated, allowing encryption\r\n  of any plaintext block whose value is in $\\mathbb{Z}_n$\r\n  (typically at least 1024 bits),\r\n  \\item a small odd integer $e$ that is relatively prime to\r\n  $\\phi(n)=(p-1)(q-1)$ is selected, a common choice is $e=65537$ so long\r\n  as $\\mbox{gcd}(\\phi(n),e)=1$,\r\n  \\item the multiplicative inverse $d$ of $e$ in $\\mathbb{Z}_{\\phi(n)}$ is calculated\r\n  using the Euclidean algorithm (which is the value $s$ calculated by\r\n  $\\proc{Extended-Euclid}(e, \\phi(n))$),\r\n  \\item the public key is the pair $(e, n)$ which is published,\r\n  \\item the private key is the pair $(d, n)$ which is kept secret.\r\n\\end{enumerate}\r\n\\begin{figure*}[htb]\r\n\\begin{codebox}\r\n\\Procname{$\\proc{Extended-Euclid}(m,n)$}\r\n\\li \\Comment determine $d=\\mbox{gcd}(m,n)$ and $s$, $t$ for which\r\n   $\\mbox{gcd}(m,n)=s\\cdot m+t\\cdot n$\r\n\\li \\If $n=0$ \\Then\r\n\\li    \\Return $(m, 1, 0)$\r\n    \\End\r\n\\li $(d^\\prime, s^\\prime, t^\\prime) \\gets \\proc{Extended-Euclid}(n,m\\mbox{ mod }n)$\r\n\\li $q \\gets \\lfloor m/n\\rfloor$ \\`\\Comment integer division $m/n$\r\n\\li $(d, s, t) \\gets (d^\\prime, t^\\prime, s^\\prime - q t^\\prime)$\r\n\\li \\Return $(d, s, t)$\r\n\\end{codebox}\r\n\\end{figure*}\r\n\r\nA plaintext block $P$ is considered a value in $\\mathbb{Z}_n$.\r\nEncryption of $P$ using the public key into a ciphertext value $C$ is given by:\r\n\\begin{displaymath}\r\n  C = P^e\\mbox{ mod }n,\r\n\\end{displaymath}\r\nwhereas for authentication the private key $d$ would instead be used for encryption.\r\nDecryption is then achieved by the same technique but with the other key:\r\n\\begin{displaymath}\r\n  P = C^d\\mbox{ mod }n.\r\n\\end{displaymath}\r\nTo verify that encryption and decryption are indeed inverse operations, it must be\r\nshown that $\\left(P^e\\mbox{ mod }n\\right)^d\\mbox{ mod }n=P$\r\nfor any possible value $P$ in $\\mathbb{Z}_n$.\r\nNote that $ed\\mbox{ mod }\\phi(n)=1$ and $\\phi(n)=(p-1)(q-1)$ as $p$ and $q$ are\r\nboth primes, so that $ed=1+k(p-1)(q-1)$ for some multiple $k$. Thus:\r\n\\begin{displaymath}\r\n  \\left(P^e\\mbox{ mod }n\\right)^d\\mbox{ mod }n\r\n  = P^{ed}\\mbox{ mod }n\r\n  = P^{1+k(p-1)(q-1)}\\mbox{ mod }n.\r\n\\end{displaymath}\r\nNow, if $P$ is not divisible by $p$ then $P^{p-1}\\mbox{ mod }p=1$ by Fermat's Theorem, so:\r\n\\begin{eqnarray*}\r\n  P^{1+k(p-1)(q-1)}\\mbox{ mod }p\r\n  &=& P\\cdot\\left(P^{p-1}\\right)^{k(q-1)}\\mbox{ mod }p \\\\\r\n  &=& P\\cdot\\left(1\\right)^{k(q-1)}\\mbox{ mod }p \\\\\r\n  &=& P\\mbox{ mod }p.\r\n\\end{eqnarray*}\r\nIf instead $P$ is divisible by $p$ then too $P^{1+k(p-1)(q-1)}\\mbox{ mod }p=0=P\\mbox{ mod }p$.\r\nSimilarly, $P^{1+k(p-1)(q-1)}\\mbox{ mod }q=P\\mbox{ mod }q$, so the Chinese Remainder Theorem\r\ncan be applied to show that $P^{1+k(p-1)(q-1)}\\mbox{ mod }n=P\\mbox{ mod }n$.\r\nThis verifies that RSA decryption is the reverse of RSA encryption.\r\n\r\nThe exponentiation operations $P^e$ and $C^d$ used in encryption and decryption\r\ncan be performed in $\\Theta(\\log_2 e)$ and $\\Theta(\\log_2 d)$ respectively.\r\nFor instance $P^e\\mbox{ mod }n$ can be found by calculating:\r\n\\begin{displaymath}\r\n  P, P^2\\mbox{ mod }n, P^4\\mbox{ mod }n, P^8\\mbox{ mod }n, P^{16}\\mbox{ mod }n, \\dots\r\n\\end{displaymath}\r\nwhere each term is the square modulo $n$ of the previous term.\r\nThe algorithm $\\proc{Modular}$-$\\proc{Exponentiation}$ demonstrates how this can be achieved\r\nusing the binary representation of an exponent $b$.\r\nFor example, if $b=22$ which has binary representation $10110$, then\r\nafter the first iteration of the loop $b_4=1$ and so $t=a\\cdot1=a$.\r\nDuring the next iteration $b_3=0$ and so $t$ is just squared giving\r\n$t=a^2$. During the third iteration $b_2=1$ and so\r\n$t$ is squared and then multiplied by $a$ giving $t=a^5$.\r\nDuring the fourth iteration $b_1=1$ and so $t$ is again squared and\r\nmultiplied by $a$, resulting in $t=a^{11}$. In the final iteration\r\n$b_0=0$ and so the result is just squared, giving $t=a^{22}$.\r\n\\begin{figure*}[htb]\r\n\\begin{codebox}\r\n\\Procname{$\\proc{Modular-Exponentiation}(a,b,n)$}\r\n\\li \\Comment determine $a^b\\mbox{ mod }n$ in order $\\Theta(\\log_2 b)$\r\n       where $b=b_{k-1} b_{k-2}\\dots b_0$ in binary\r\n\\li $t \\gets 1$\r\n\\li \\For $i\\gets k\\!-\\!1$ \\Downto $0$ \\Do\r\n\\li    $t \\gets t\\times t\\mbox{ mod }n$\r\n\\li    \\If $b_i=1$ \\Then\r\n\\li       $t \\gets (t\\times a)\\mbox{ mod }n$\r\n       \\End\r\n    \\End\r\n\\li \\Return $t$\r\n\\end{codebox}\r\n\\end{figure*}\r\nActually, since the exponent $d$ is probably very large a more efficient\r\nway of calculating $C^d$ during decryption can be advantageous.\r\nUsing Fermat's Theorem, $C^d\\mbox{ mod }p=C^{d\\mbox{ \\scriptsize mod }(p-1)}\\mbox{ mod }p$\r\nand $C^d\\mbox{ mod }q=C^{d\\mbox{ \\scriptsize mod }(q-1)}\\mbox{ mod }q$.\r\nSo $C^d\\mbox{ mod }p$ and $C^d\\mbox{ mod }q$ can be found relatively quickly.\r\nThen as $n=pq$ and $p$ and $q$ are relatively prime,\r\nthe Chinese Remainder Theorem can be applied to obtain $C^d\\mbox{ mod }n$.\r\nThis way is about four times faster than simply using $\\proc{Modular-Exponentiation}$\r\nto calculate $C^d\\mbox{ mod }n$.\r\n\r\nIt may appear surprising that $n$ can be included as part of the public key,\r\nas if a cryptanalyst were to find the primes $p$ and $q$ with $n=pq$, or even just\r\ncalculate $\\phi(n)$ then the private key would be obtained.\r\nHowever, obtaining the prime factorization for large values of $n$ is well-known\r\nto be difficult, with no efficient algorithm yet discovered.\r\nAlso, it has been shown that calculating $\\phi(n)$ is equivalent to\r\nfactorizing $n=pq$.\r\nHence the security of the RSA algorithm is based on the difficulty\r\nof factorizing a sufficiently large value of $n$.\r\n\r\nCryptanalysis attacks on RSA based on factorizing $n$ have improved since the\r\nrelease of RSA. When RSA was first published in 1977 a challenge was made\r\nto break a particular ciphertext encrypted using a 428 bit value for $n$,\r\nwhich at the time was presumed would take 40 quadrillion years by brute force.\r\nBut in 1994, after only eight months work the ciphertext was successfully\r\nbroken, and since then factorization techniques have improved substantially,\r\nso that by 2005 a 663 bit value of $n$ was no longer considered secure.\r\nHence larger values (currently between 1024 bit and 2048 bit) are now used for\r\nRSA encryption. However, the drawback is that encryption and decryption\r\ncalculations are longer, slowing the algorithm.\r\n\r\nThere are several other interesting cryptanalysis attacks on RSA.\r\nIf a particularly small value of $e$ is chosen and if the same plaintext is encrypted\r\nfor that number of users each with different values of $n$ then the plaintext\r\ncan be easily obtained. For instance, if $e=3$ (which was once commonly used)\r\nand the same plaintext $P$ is encrypted with $n_1$, $n_2$, $n_3$ and intercepted by a\r\ncryptanalyst, then the values\r\n$P^3\\mbox{ mod }n_1$, $P^3\\mbox{ mod }n_1$, $P^3\\mbox{ mod }n_1$\r\nare obtained. As $n_1$, $n_2$, $n_3$ are probably relatively prime\r\nwith each other, the Chinese Remainder Theorem can then be used to obtain\r\n$P^3\\mbox{ mod }n_1n_2n_3$. But $P<n_1$, $P<n_2$, $P<n_3$, so $P^3$\r\nhas been found. Taking its cube root then gives the original plaintext $P$.\r\n\r\nAnother approach that demonstrates the ingenuity of cryptanalysis attacks\r\nis known as a \\defn{timing attack}, which relies on the time taken by an\r\nalgorithm such as RSA to decrypt ciphertext.\r\nAs the time taken by each iteration of the $\\proc{Modular-Exponentiation}$\r\nalgorithm depends on whether the bit $d_i$ of the private key $d$ is $0$\r\nor $1$, by carefully choosing ciphertext, a cryptanalyst can\r\ndetermine bit by bit the value of $d$. To foil a timing attack,\r\nRSA algorithms usually include \\defn{blinding}, where a secret random number\r\n$r$ is chosen, encrypted and multiplied by the ciphertext $C$ before it\r\ngets decrypted. This ensures that the ciphertext actually being decrypted is not\r\nknown to the cryptanalyst. The decrypted result is then multiplied by\r\nthe multiplicative inverse of $r$ in $\\mathbb{Z}_n$ to give the original\r\nplaintext.\r\n\r\nRSA has further properties that can be exploited by a cryptanalyst.\r\nIt is easily seen that the ciphertext for $P_1\\cdot P_2$ is the same\r\nas the product of the ciphertext for $P_1$ with the ciphertext for $P_2$.\r\nAs a consequence, if a cryptanalyst intercepts a ciphertext $C$ and\r\nis then allowed to obtain the plaintext for certain chosen ciphertext, then\r\nthe plaintext for the intercepted ciphertext $C$ can be quickly obtained.\r\nTo counter this attack, RSA algorithms use \\defn{optimal asymmetric encryption padding}\r\n(OAEP) where all plaintext are randomly padded before they get encrypted.\r\n\r\nDue to the length of the key needed to ensure security of RSA, and the resulting\r\nlong calculations, RSA is not nearly as efficient as symmetric cipher algorithms\r\nsuch as AES for encrypting and decrypting large quantities of data.\r\nFor this reason RSA is typically used only for the initial exchange of a\r\nsecret key after which a symmetric cipher is used for further encryption and\r\ndecryption.\r\n\r\nThe class \\begin{code}RSADecrypter\\end{code} demonstrates how a pair\r\nof keys can be generated in Java using the \\begin{code}KeyPairGenerator\\end{code}\r\nclass:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nKeyPairGenerator kpg = KeyPairGenerator.getInstance(\"RSA\");\r\nkpg.initialize(1024); // size of key in bits\r\nKeyPair keyPair = kpg.generateKeyPair();\r\nPublicKey publicKey = keyPair.getPublic();\r\nPrivateKey privateKey = keyPair.getPrivate();\r\n\\end{verbatim}\\end{code}\\end{quote}\r\nFrom the two keys their modulus $n$ and exponent $e$ or $d$ can be obtained\r\nby typecasting them to \\begin{code}RSAPublicKey\\end{code} and\r\n\\begin{code}RSAPrivateKey\\end{code} respectively.\r\nOnce the key pair has been generated the example sends the public key\r\nvia a TCP socket connection to another class called \\begin{code}RSAEncrypter\\end{code}\r\n(either a Java or a C\\# class) that is listening for socket connections.\r\nThe \\begin{code}RSAEncrypter\\end{code} obtains the modulus $n$ and the public\r\nexponent $e$ and uses them to encrypt a short plaintext using RSA.\r\nThe encrypted ciphertext is then passed back to \\begin{code}RSADecrypter\\end{code}\r\nwhere it is decrypted using the private key.\r\nIn a more-realistic application this plaintext might typically be a secret key\r\nfor symmetric encryption, and the public key would be passed using a standard format\r\nsuch as the X.509 standard (discussed in Section \\ref{Se:CertificatesKeyStorage}).\r\nFurthermore, this example does not use OAEP which is supported in both Java and C\\#.\r\n\r\nRSA encryption is performed in C\\# using the \\begin{code}RSACryptoServiceProvider\\end{code}\r\nclass (instead of the usual C\\# \\begin{code}CipherStream\\end{code}).\r\nNote if a key of length exactly a power of two is used then the\r\n\\begin{code}RSACryptoServiceProvider\\end{code} cipher appears to add an\r\nextra byte to the encrypted ciphertext, which is inconsistent\r\nwith the length of the key,\r\nresulting in a \\begin{code}BadPaddingException\\end{code} in \\begin{code}RSADecrypter\\end{code}.\r\nThis small incompatibility can be avoided by not using keys of lengths\r\nexactly 512 or 1024 in the C\\# version.\r\n\\begin{lstlisting}[caption=RSA encryption]\r\n/**\r\n   A class that demonstrates how RSA encryption can be used to obtain\r\n   RSA encrypted information from an RSAEncrypter server.\r\n   To run first start RSAEncrypter.\r\n   @author Andrew Ensor\r\n*/\r\n...\r\npublic class RSADecrypter\r\n{\r\n   public static final String HOST_NAME = \"localhost\";\r\n   public static final int HOST_PORT = 8888; // host port number\r\n   private KeyPair keyPair;\r\n\r\n   public RSADecrypter()\r\n   {  // generate an RSA public and private key pair\r\n      try\r\n      {  KeyPairGenerator kpg = KeyPairGenerator.getInstance(\"RSA\");\r\n         kpg.initialize(1024); // size of key in bits\r\n         keyPair = kpg.generateKeyPair();\r\n      }\r\n      catch (NoSuchAlgorithmException e)\r\n      {  System.err.println(\"Encryption algorithm not available: \"+e);\r\n      }\r\n   }\r\n\r\n   private void obtainBytes()\r\n   {  // open TCP connection to RSAEncrypter server on specified port\r\n      Socket socket = null;\r\n      OutputStream os = null;\r\n      InputStream is = null;\r\n      try\r\n      {  socket = new Socket(HOST_NAME, HOST_PORT);\r\n         os = socket.getOutputStream();\r\n         // send the public key modulus and public exponent to host\r\n         RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();\r\n         System.out.println(\"Sending public key\");\r\n         byte[] modulus = publicKey.getModulus().toByteArray();\r\n         byte[] exponent = publicKey.getPublicExponent().toByteArray();\r\n         os.write(modulus.length); // write number of bytes in modulus\r\n         os.write(modulus);\r\n         os.write(exponent.length);//write number of bytes in exponent\r\n         os.write(exponent);\r\n         os.flush();\r\n         // obtain the encrypted bytes\r\n         is = socket.getInputStream();\r\n         ByteArrayOutputStream baos = new ByteArrayOutputStream();\r\n         int data = is.read();\r\n         while (data != -1) // end of stream encountered\r\n         {  baos.write(data);\r\n            data = is.read();\r\n         }\r\n\\end{verbatim}\\hfill \\emph{cont-}\\end{program}\\end{figure*}%\r\n\\begin{figure*}\\begin{program}\\emph{-cont}\\begin{verbatim}\r\n         byte[] ciphertext = baos.toByteArray();\r\n         // decrypt the bytes using the private key\r\n         PrivateKey privateKey = keyPair.getPrivate();\r\n         Cipher cipher = Cipher.getInstance(\"RSA\");\r\n         cipher.init(Cipher.DECRYPT_MODE, privateKey);\r\n         byte[] plaintext = cipher.doFinal(ciphertext);\r\n         // display the plaintext\r\n         System.out.print(\"Deciphered plaintext:\");\r\n         for (int i=0; i<plaintext.length; i++)\r\n           System.out.print(\" \" + plaintext[i]);\r\n         System.out.println();\r\n      }\r\n      catch (IOException e)\r\n      {  System.err.println(\"IOException in decrypter: \" + e);\r\n      }\r\n      catch (NoSuchAlgorithmException e)\r\n      {  System.err.println(\"Encryption algorithm not available: \"+e);\r\n      }\r\n      catch (NoSuchPaddingException e)\r\n      {  System.err.println(\"Padding scheme not available: \" + e);\r\n      }\r\n      catch (InvalidKeyException e)\r\n      {  System.err.println(\"Invalid key: \" + e);\r\n      }\r\n      catch (IllegalBlockSizeException e)\r\n      {  System.err.println(\"Cannot pad plaintext: \" + e);\r\n      }\r\n      catch (BadPaddingException e)\r\n      {  System.err.println(\"Exception with padding: \" + e);\r\n      }\r\n      finally\r\n      {  try\r\n         {  if (os != null) os.close();\r\n            if (is != null) is.close();\r\n            if (socket != null) socket.close();\r\n         }\r\n         catch (IOException e)\r\n         {  System.err.println(\"Failed to close streams: \" + e);\r\n         }\r\n      }\r\n   }\r\n\r\n   public static void main(String[] args)\r\n   {  RSADecrypter decrypter = new RSADecrypter();\r\n      decrypter.obtainBytes();\r\n   }\r\n}\r\n\\end{lstlisting}\r\n\\begin{lstlisting}[caption=RSA encryption]\r\n/**\r\n   A class that demonstrates how RSA encryption can be used to encrypt\r\n   RSA encrypted information to an RSADecrypter client\r\n   @see RSADecrypter.java\r\n*/\r\n...\r\npublic class RSAEncrypter\r\n{\r\n   public static final int PORT = 8888; // some unused port number\r\n   private final byte[] plaintext = {1, 2, 3, 4, 5, 6, 7}; // secret\r\n   ...\r\n   // inner class that represents a single connection handler\r\n   private class ConnectionHandler implements Runnable\r\n   {\r\n      private Socket socket; // socket for client/server communication\r\n\r\n      public ConnectionHandler(Socket socket)\r\n      {  this.socket = socket;\r\n      }\r\n\r\n      public void run()\r\n      {  // handle the TCP connection with an RSADecrypter client\r\n         InputStream is = null;\r\n         OutputStream os = null;\r\n         try\r\n         {  // obtain public key modulus and public exponent from client\r\n            is = socket.getInputStream();\r\n            int modulusLength = is.read(); // get num bytes in modulus\r\n            byte[] modulus = new byte[modulusLength];\r\n            for (int i=0; i<modulusLength; i++)\r\n               modulus[i] = (byte)is.read();\r\n            int exponentLength = is.read();//get num bytes in exponent\r\n            byte[] exponent = new byte[exponentLength];\r\n            for (int i=0; i<exponentLength; i++)\r\n               exponent[i] = (byte)is.read();\r\n            RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec\r\n               (new BigInteger(modulus), new BigInteger(exponent));\r\n            // create public key from the modulus and public exponent\r\n            KeyFactory keyFactory = KeyFactory.getInstance(\"RSA\");\r\n            PublicKey publicKey\r\n               = keyFactory.generatePublic(publicKeySpec);\r\n            // use the public key to encrypt the information\r\n            Cipher cipher = Cipher.getInstance(\"RSA\");\r\n            cipher.init(Cipher.ENCRYPT_MODE, publicKey);\r\n            byte[] ciphertext = cipher.doFinal(plaintext);\r\n            // send the encrypted bytes\r\n            os = socket.getOutputStream();\r\n            os.write(ciphertext);\r\n         }\r\n         ...\r\n      }\r\n   }\r\n}\r\n\\end{lstlisting}\r\n\\begin{lstlisting}[caption=RSA encryption in C\\#]\r\n/*\r\n   A C# class that demonstrates how RSA encryption can be used to\r\n   obtain RSA encrypted information from an RSAEncrypter server.\r\n   Note this example presumes that the modulus length can be\r\n   represented as a byte (an int would be preferable but then the\r\n   endian order needs to be considered), and that the modulus is a\r\n   positive integer in twos-complement notation (so most significant\r\n   bit is zero).\r\n*/\r\n...\r\npublic class RSADecrypter\r\n{\r\n   public const String HOST_NAME = \"localhost\";\r\n   public const int HOST_PORT = 8888; // host port number\r\n   private RSAParameters keyPair;\r\n\r\n   public RSADecrypter()\r\n   {  // generate an RSA public and private key pair using 1024 bit key\r\n      RSACryptoServiceProvider cipher\r\n         = new RSACryptoServiceProvider(1024);\r\n      keyPair = cipher.ExportParameters(true);\r\n   }\r\n\r\n   private void ObtainBytes()\r\n   {  // open TCP connection to RSAEncrypter server on specified port\r\n      TcpClient client = null;\r\n      try\r\n      {  client = new TcpClient();\r\n         client.Connect(HOST_NAME, HOST_PORT);\r\n      }\r\n      catch (SocketException e)\r\n      {  Console.WriteLine(\"Client could not make connection: \" + e);\r\n         System.Environment.Exit(System.Environment.ExitCode);\r\n      }\r\n      NetworkStream stream = null;\r\n      BinaryWriter bw = null;\r\n      BinaryReader br = null;\r\n      try\r\n      {  stream = client.GetStream();\r\n         bw = new BinaryWriter(stream);\r\n         // send the public key modulus and public exponent to host\r\n         Console.WriteLine(\"Sending public key\");\r\n         byte[] modulus = keyPair.Modulus;\r\n         byte[] exponent = keyPair.Exponent;\r\n         if ((modulus[0] & 0x80) != 0)\r\n         {  // modulus needs a 00 prepended to put into twos complement\r\n            byte[] twosComplement = new byte[modulus.Length+1];\r\n            twosComplement[0] = 0;\r\n            Array.Copy(modulus, 0, twosComplement, 1, modulus.Length);\r\n            modulus = twosComplement;\r\n         }\r\n\\end{verbatim}\\hfill \\emph{cont-}\\end{program}\\end{figure*}%\r\n\\begin{figure*}\\begin{program}\\emph{-cont}\\begin{verbatim}\r\n         bw.Write((byte)modulus.Length); // write num of modulus bytes\r\n         bw.Write(modulus);\r\n         bw.Write((byte)exponent.Length);//write num of exponent bytes\r\n         bw.Write(exponent);\r\n         bw.Flush();\r\n         // obtain the encrypted bytes\r\n         br = new BinaryReader(stream);\r\n         MemoryStream memoryStream = new MemoryStream();\r\n         BinaryWriter msbw = new BinaryWriter(memoryStream);\r\n         byte[] data = br.ReadBytes(0);\r\n         while (data.Length>0) // end of stream encountered\r\n         {  msbw.Write(data);\r\n            data = br.ReadBytes(0);\r\n         }\r\n         stream.CopyTo(memoryStream);\r\n         byte[] ciphertext = memoryStream.ToArray();\r\n         // decrypt the bytes using private key without OAEP padding\r\n         RSACryptoServiceProvider cipher\r\n            = new RSACryptoServiceProvider();\r\n         cipher.ImportParameters(keyPair);\r\n         byte[] plaintext = cipher.Decrypt(ciphertext, true);\r\n         // display the plaintext\r\n         Console.Write(\"Deciphered plaintext:\");\r\n         for (int i=0; i<plaintext.Length; i++)\r\n            Console.Write(\" \" + plaintext[i]);\r\n         Console.WriteLine();\r\n         cipher.Dispose();\r\n\r\n      }\r\n      catch (SocketException e)\r\n      {  Console.WriteLine(\"Client error: \" + e);\r\n      }\r\n      finally\r\n      {  try\r\n         {  if (br != null) br.Close();\r\n            if (bw != null) bw.Close();\r\n            if (stream != null) stream.Close();\r\n            if (client != null) client.Close();\r\n         }\r\n         catch (SocketException e)\r\n         {  Console.WriteLine(\"Failed to close streams: \" + e);\r\n         }\r\n      }\r\n   }\r\n\r\n   public static void Main(string[] args)\r\n   {  RSADecrypter decrypter = new RSADecrypter();\r\n      decrypter.ObtainBytes();\r\n   }\r\n}\r\n\\end{lstlisting}\r\n\\begin{lstlisting}[caption=RSA encryption in .NET]\r\n/*\r\n   A C# class that demonstrates how RSA encryption can be used in .NET\r\n   to encrypt RSA encrypted information to an RSADecrypter client.\r\n*/\r\n...\r\npublic class RSAEncrypter\r\n{\r\n   ...\r\n   // inner class that represents a single connection handler\r\n   private class ConnectionHandler\r\n   {\r\n      ...\r\n      public void Run() // can call this method anything in C#\r\n      {  // handle the TCP connection with an RSADecrypter client\r\n         NetworkStream stream = new NetworkStream(socket);\r\n         BinaryReader br = null;\r\n         BinaryWriter bw = null;\r\n         try\r\n         {  // obtain public key modulus and public expon from client\r\n            br = new BinaryReader(stream);\r\n            int modulusLength=br.ReadByte();//get num bytes in modulus\r\n            byte[] modulus = new byte[modulusLength];\r\n            for (int i=0; i<modulusLength; i++)\r\n               modulus[i] = br.ReadByte();\r\n            if (modulus[0] == 0)\r\n            {  // an additional 00 byte has probably been appended\r\n               // to make modulus twos complement\r\n               byte[] unsigned = new byte[modulus.Length-1];\r\n               Array.Copy(modulus, 1, unsigned, 0, modulus.Length-1);\r\n               modulus = unsigned;\r\n            }\r\n            int exponentLength=br.ReadByte();//get num bytes in expon\r\n            byte[] exponent = new byte[exponentLength];\r\n            for (int i=0; i<exponentLength; i++)\r\n               exponent[i] = br.ReadByte();\r\n            RSAParameters publicKeySpec = new RSAParameters();\r\n            publicKeySpec.Modulus = modulus;\r\n            publicKeySpec.Exponent = exponent;\r\n            // create public key from the modulus and public exponent\r\n            RSACryptoServiceProvider cipher\r\n               = new RSACryptoServiceProvider();\r\n            cipher.ImportParameters(publicKeySpec);\r\n            // use the public key to encrypt info without OAEP padding\r\n            byte[] ciphertext = cipher.Encrypt(plaintext, true);\r\n            // send the encrypted bytes\r\n            bw = new BinaryWriter(stream);\r\n            bw.Write(ciphertext);\r\n            cipher.Dispose();\r\n         }\r\n         ...\r\n      }\r\n   }\r\n}\r\n\\end{lstlisting}\r\n\r\n\r\n\\begin{exercise}[Implementation of RSA]\r\nPrepare a program that provides an implementation of the RSA public-key block cipher.\r\n\\end{exercise}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%% Key Exchange                                                                  %%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\section{Key Exchange}\r\nThe performance of public-key encryption algorithms\r\ncan be up to 1000 times slower than symmetric encryption,\r\nwhich limits their suitability to the exchange of\r\nbrief messages such as secret keys for symmetric encryption.\r\nThe classes \\begin{code}RSADecrypter\\end{code} and\r\n\\begin{code}RSAEncrypter\\end{code} from Section \\ref{Se:RSAAlgorithm}\r\ndemonstrate how an asymmetric cipher such as RSA can be used to pass a\r\nsecret key safely encrypted between two processes, which can then be\r\nused for the encryption of further messages.\r\n\r\nThe \\defn{Diffie-Hellman key exchange} algorithm was the first published\r\npublic-key algorithm and was devised so that two processes could\r\nuse insecure communication to determine a common secret key.\r\nThis algorithm starts with two public values that are pre-computed,\r\na large prime $p$ and an integer value $a$ with $1<a<p$ for which:\r\n\\begin{displaymath}\r\n  a, a^2\\mbox{ mod }p, a^3\\mbox{ mod }p, \\dots, a^{p-1}\\mbox{ mod }p=1.\r\n\\end{displaymath}\r\nare all distinct (so they must just be a permutation of $\\{1,2,3,\\dots, p-1\\}$)\r\nin which case $a$ is called a \\defn{primitive root} of $p$.\r\nOnce a primitive root $a$ of a prime $p$ has been found,\r\nfor any integer $b$ there is a unique power $i<p$\r\nfor which $b\\mbox{ mod }p=a^i\\mbox{ mod }p$, and $i$ is\r\ncalled the \\defn{discrete logarithm} or \\defn{index} of $b$ modulo $p$ for\r\nthe base $a$.\r\n\r\nFor example, taking $p=7$ the value $a=2$ is not a primitive root of $7$ since in\r\n$\\mathbb{Z}_7$ one has:\r\n\\begin{displaymath}\r\n  2^1=2, 2^2=4, 2^3=1, 2^4=2, 2^5=4, 2^6=1,\r\n\\end{displaymath}\r\nwhich are not all distinct, whereas the value $a=3$ is a primitive root as:\r\n\\begin{displaymath}\r\n  3^1=3, 3^2=2, 3^3=6, 3^4=4, 3^5=5, 3^6=1,\r\n\\end{displaymath}\r\nwhich are all distinct.\r\nThus the discrete logarithm of an integer such as $b=1763$ modulo $p=7$ for the\r\nbase $a=3$ is found by $b\\mbox{ mod }7=6=3^3$, and so $i=3$.\r\n\r\nThe security of the Diffie-Hellman key exchange relies on the\r\ndifficulty of computing discrete logarithms for large primes $p$,\r\nmuch as RSA relies on the difficulty of computing prime\r\nfactorizations for large integers $n$. When two processes with the\r\nsame base $a$ and prime $p$ want to exchange a secret key each\r\nselects its own secure random number $x<p$ as its private key and\r\ncalculates a public key $y=a^x\\mbox{ mod }p$, which is\r\ncommunicated to the other process. When each process receives the\r\npublic key $y^\\prime=a^{x^\\prime}\\mbox{ mod }p$ of the other\r\nprocess (but not knowing the other private key $x^\\prime$), it\r\ncalculates the secret key $K$:\r\n\\begin{displaymath}\r\n  K = \\left(y^\\prime\\right)^x\\mbox{ mod }p.\r\n\\end{displaymath}\r\nNote that this is the same key as that calculated by the other process as:\r\n\\begin{eqnarray*}\r\n  \\left(y^\\prime\\right)^x\\mbox{ mod }p\r\n  &=& \\left(a^{x^\\prime}\\mbox{ mod }p\\right)^x\\mbox{ mod }p \\\\\r\n  &=& a^{x\\cdot x^\\prime}\\mbox{ mod }p \\\\\r\n  &=& \\left(a^x\\mbox{ mod }p\\right)^{x^\\prime}\\mbox{ mod }p \\\\\r\n  &=& y^{x^\\prime}\\mbox{ mod }p,\r\n\\end{eqnarray*}\r\nbut a cryptanalyst cannot calculate $K$ without knowing one of the values $x$ or $x^\\prime$.\r\nObtaining these values would require calculating the discrete logarithm of\r\nan intercepted $y$ or $y^\\prime$ value modulo $p$ to the base $a$, which is\r\ncomputationally difficult.\r\n\r\nJCA supports Diffie-Hellman key exchange using the algorithm name \\begin{code}DH\\end{code}\r\nand the following steps:\r\n\\begin{description}\r\n  \\item[Generate the Public Prime and Primitive Root]\r\n  New values of $p$ and $a$ can be generated for a Diffie-Hellman key exchange\r\n  using an \\begin{code}Algorithm\\-ParameterGenerator\\end{code}:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nAlgorithmParameterGenerator apg\r\n   = AlgorithmParameterGenerator.getInstance(\"DH\");\r\napg.init(512); // 512-bit prime\r\nDHParameterSpec dhSpec = (DHParameterSpec)\r\n   apg.generateParameters().getParameterSpec\r\n   (DHParameterSpec.class);\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  or else existing values of $p$ and $a$ can be passed directly:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nDHParameterSpec dhSpec = new DHParameterSpec(p, a);\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n\r\n  \\item[Create Public and Private Keys]\r\n  Values of $x$ and $y$ can be generated by each process\r\n  by passing a \\begin{code}KeyPairGenerator\\end{code}\r\n  the $p$ and $a$ parameters:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nKeyPairGenerator kpg=KeyPairGenerator.getInstance(\"DH\");\r\nkpg.initialize(dhSpec);\r\nKeyPair keyPair = kpg.generateKeyPair();\r\nPublicKey publicKey = keyPair.getPublic();\r\nPrivateKey privateKey = keyPair.getPrivate();\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  From the two keys their public value $y$ or private value $x$ can be obtained\r\n  by typecasting the keys to \\begin{code}DHPublicKey\\end{code} or\r\n  \\begin{code}DHPrivateKey\\end{code} respectively.\r\n\r\n  \\item[Swap Public Keys]\r\n  The processes involved in the key exchange swap their public values of $y$.\r\n  This can be accomplished by passing the raw values of $y$\r\n  (along with $p$ and $a$ if not already publicly available):\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nBigInteger yValue = ((DHPublicKey)publicKey).getY();\r\n... // send yValue\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  and using a \\begin{code}DHPublicKeySpec\\end{code} with a \\begin{code}KeyFactory\\end{code}\r\n  to reassemble the public key at the other end:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nBigInteger otherYValue = ...; // receive\r\nDHPublicKeySpec otherPublicKeySpec\r\n   = new DHPublicKeySpec(otherYValue, pValue, aValue);\r\nKeyFactory keyFactory = KeyFactory.getInstance(\"DH\");\r\nPublicKey otherPublicKey\r\n   = keyFactory.generatePublic(otherPublicKeySpec);\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  A preferred way to accomplish this is to send the public key in the\r\n  standardized X.509 key exchange format:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nbyte[] publicKeyBytes = publicKey.getEncoded();\r\n... // send publicKeyBytes\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  and use an \\begin{code}X509EncodedKeySpec\\end{code} with a \\begin{code}KeyFactory\\end{code}\r\n  to reassemble the public key at the other end:\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nbyte[] otherPublicKeyBytes = ...; // receive\r\nX509EncodedKeySpec otherPublicKeySpec\r\n   = new X509EncodedKeySpec(otherPublicKeyBytes);\r\nKeyFactory keyFactory = KeyFactory.getInstance(\"DH\");\r\nPublicKey otherPublicKey\r\n   = keyFactory.generatePublic(otherPublicKeySpec);\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n\r\n  \\item[Generate Secret Key]\r\n  The private key is used to initialize a \\begin{code}KeyAgreement\\end{code}\r\n  and then its \\begin{code}doPhase\\end{code} method is passed the swapped public key(s)\r\n  (with a boolean to indicate which is the last public key obtained):\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nKeyAgreement ka = KeyAgreement.getInstance(\"DH\");\r\nka.init(privateKey); // initialize with own private key\r\nka.doPhase(otherPublicKey, true);\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n  Then the \\begin{code}KeyAgreement\\end{code} method \\begin{code}generateSecret\\end{code}\r\n  can be used to generate bytes for a secret key (or for a specific\r\n  algorithm such as \\begin{code}DES\\end{code} or \\begin{code}DESede\\end{code}):\r\n\\begin{quote}\\begin{code}\\begin{verbatim}\r\nbyte[] key = ka.generateSecret();\r\n\\end{verbatim}\\end{code}\\end{quote}\r\n\r\n\\end{description}\r\n\r\nHowever, if the communication channel between two processes\r\ncan be compromised so that messages can be modified then\r\nthe Diffie-Hellman key exchange is susceptible to a \\defn{man-in-the-middle attack}.\r\nWith this attack an adversary generates its own key pair and\r\nintercepts all messages between the two processes.\r\nThe attacker starts by replacing the public key\r\nof each with its own public key during the key exchange.\r\nThen each process will generate a secret key in common\r\nwith the attacker rather than with each other.\r\nThe attacker then decrypts messages from either process using one secret\r\nkey and can re-encrypt them (possibly modified) for the other process using\r\nthe other secret key.\r\nIf both ends are unaware that their messages have been modified then their\r\nencrypted communication will be compromised.\r\n\r\nTo counter a man-in-the-middle attack it is important that the recipient\r\nof a public key be certain that it is an authentic key for the intended\r\nprocess. Merely broadcasting a public key is not secure as anyone could\r\nforge a broadcast, sending a public key generated by themselves and\r\nclaiming to be another process. The forger would then receive messages\r\nencrypted for it that were intended for the genuine process until the\r\nforgery were detected and all other processes notified.\r\nInstead, the public keys could be made globally available from a\r\nsecure public directory, which would require a man-in-the-middle attack to\r\nintercept messages to and from the directory (which might be able to be made\r\nphysically secure) as well as eavesdrop on communication between\r\nprocesses.\r\n\r\nA more secure approach is to use a \\defn{public-key authority} which\r\ncontrols access to the public keys in a system.\r\nA central authority holds a public key for each process, which is\r\ndelivered to the authority via some secure means (such as physically),\r\nand in exchange the process is given a public key for its communication\r\nwith the authority.\r\nWhen an initiating process wants to exchange its public key with that\r\nof another process it can use the following steps:\r\n\\begin{enumerate}\r\n\t\\begin{multicols}{2}\r\n  \\item\r\n     The initiator sends a request encrypted using the public key of the\r\n    authority, requesting the public key for the receiving process, and\r\n    including a timestamp with the request.\r\n    The public-key authority responds with a message encrypted using its private key,\r\n    including the public key for the receiver and the original request with the timestamp.\r\n    Once the response has been decrypted by the initiator using the public key of the authority\r\n    it is assured that the message was encrypted by the authority and that\r\n    its original request was received by the authority untampered.\\end{multicols}\r\n \r\n \t\\begin{figure*}\t\\begin{center}\r\n \t \\begin{pspicture}[h](0,0)(5,1.5)\r\n    \\rput(0.8,0.25){\\ovalnode{I}{\\makebox[10mm]{\\scriptsize Initiator}}}\r\n    \\rput(2.5,1.25){\\ovalnode{K}{\\makebox[10mm]{\\scriptsize Authority}}}\r\n    \\rput(4.2,0.25){\\ovalnode{R}{\\makebox[10mm]{\\scriptsize Receiver}}}\r\n    \\nccurve[arrows=->,linecolor=red,linewidth=1mm,angleA=75,angleB=195]{I}{K}\r\n    \\nccurve[arrows=->,linecolor=red,linewidth=1mm,angleA=255,angleB=15]{K}{I}\r\n    \\rput(0.75,1.2){\\tiny\\begin{tabular}{c}public key\\\\encrypted\\\\request\\end{tabular}}\r\n    \\rput(2.75,0.3){\\tiny\\begin{tabular}{c}private key\\\\encrypted\\\\reply\\end{tabular}}\r\n  \\end{pspicture}\\end{center}\r\n\\end{figure*}\r\n\r\n\r\n\\begin{multicols}{2}\r\n  \\item\r\n    The initiator then uses the public key for the receiver to encrypt an identifier\r\n    for itself and a nonce, which it sends to the receiver, requesting an exchange.\r\n    It is assured that only the receiver can decrypt the request to obtain\r\n    its nonce.\r\n  \\begin{pspicture}[shift=-1.5](0,0)(5,1.5)\r\n    \\rput(0.8,0.25){\\ovalnode{I}{\\makebox[10mm]{\\scriptsize Initiator}}}\r\n    \\rput(2.5,1.25){\\ovalnode{K}{\\makebox[10mm]{\\scriptsize Authority}}}\r\n    \\rput(4.2,0.25){\\ovalnode{R}{\\makebox[10mm]{\\scriptsize Receiver}}}\r\n    \\ncline[arrows=->,linecolor=red,linewidth=1mm]{I}{R}\r\n    \\rput(2.5,0.55){\\tiny\\begin{tabular}{c}receiver's public key\\\\encrypted request\\end{tabular}}\r\n  \\end{pspicture}\r\n\\end{multicols}\r\n\\begin{multicols}{2} \r\n\t \\item\r\n    Upon receiving the request for an exchange, the receiver repeats the same process\r\n    with the public-key authority to obtain a public key for the initiator. At this stage the initiator and the receiver have securely obtained\r\n    each other's public key. To assure both ends that they are communicating with\r\n    each other two further steps are included.\r\n \\begin{pspicture}[shift=-1.5](0,0)(5,1.5)\r\n    \\rput(0.8,0.25){\\ovalnode{I}{\\makebox[10mm]{\\scriptsize Initiator}}}\r\n    \\rput(2.5,1.25){\\ovalnode{K}{\\makebox[10mm]{\\scriptsize Authority}}}\r\n    \\rput(4.2,0.25){\\ovalnode{R}{\\makebox[10mm]{\\scriptsize Receiver}}}\r\n    \\nccurve[arrows=->,linecolor=red,linewidth=1mm,angleA=105,angleB=345]{R}{K}\r\n    \\nccurve[arrows=->,linecolor=red,linewidth=1mm,angleA=285,angleB=165]{K}{R}\r\n    \\rput(4.25,1.2){\\tiny\\begin{tabular}{c}public key\\\\encrypted\\\\request\\end{tabular}}\r\n    \\rput(2.25,0.3){\\tiny\\begin{tabular}{c}private key\\\\encrypted\\\\reply\\end{tabular}}\r\n  \\end{pspicture}\r\n\\end{multicols}\r\n\\begin{multicols}{2} \r\n  \\item\r\n    The receiver sends a response to the initiator encrypted using the initiator's\r\n    public key, including the initiator's nonce as well as its own nonce.\r\n    When the initiator decrypts the response and finds its own nonce it is \r\n    assured that it is actually communicating with the intended receiver.\r\n\r\n  \\begin{pspicture}[shift=-1.5](0,0)(5,1.5)\r\n    \\rput(0.8,0.25){\\ovalnode{I}{\\makebox[10mm]{\\scriptsize Initiator}}}\r\n    \\rput(2.5,1.25){\\ovalnode{K}{\\makebox[10mm]{\\scriptsize Authority}}}\r\n    \\rput(4.2,0.25){\\ovalnode{R}{\\makebox[10mm]{\\scriptsize Receiver}}}\r\n    \\ncline[arrows=->,linecolor=red,linewidth=1mm]{R}{I}\r\n    \\rput(2.5,0.55){\\tiny\\begin{tabular}{c}initiator's public key\\\\encrypted response\\end{tabular}}\r\n  \\end{pspicture}\r\n\r\n\\end{multicols}\r\n\\begin{multicols}{2} \r\n  \\item\r\n    The initiator acknowledges the response from the receiver by sending an\r\n    acknowledgement message encrypted using the public key of the receiver,\r\n    including the receiver's nonce.\r\nWhen the receiver decrypts the acknowledgement and finds its own nonce it is assured that it is actually\r\ncommunicating with the intended initiator.\r\n \r\n  \\begin{pspicture}[shift=-1.5](0,0)(5,1.5)\r\n    \\rput(0.8,0.25){\\ovalnode{I}{\\makebox[10mm]{\\scriptsize Initiator}}}\r\n    \\rput(2.5,1.25){\\ovalnode{K}{\\makebox[10mm]{\\scriptsize Authority}}}\r\n    \\rput(4.2,0.25){\\ovalnode{R}{\\makebox[10mm]{\\scriptsize Receiver}}}\r\n    \\ncline[arrows=->,linecolor=red,linewidth=1mm]{I}{R}\r\n    \\rput(2.5,0.55){\\tiny\\begin{tabular}{c}receivers's public key\\\\encrypted acknow\\end{tabular}}\r\n  \\end{pspicture}\r\n\\end{multicols}\r\n \r\n\\end{enumerate}\r\n\r\nOne drawback of using a central public-key authority is that it can become\r\na bottleneck in a large system, hindering scalability. Also, if the\r\nauthority were to temporarily fail then no keys would be available.\r\nAn alternative approach is to use encrypted certificates.\r\nA \\defn{certificate} holds an identifier for a process and a public key offered\r\nby it, prepared by a trusted \\defn{certificate authority}\r\nand encrypted by the authority using a private key.\r\nThe certificate authority makes its corresponding public key available\r\nso that any process can decrypt the certificate and obtain the public key\r\nof the process, but since its private key is confidential no one else\r\ncan forge a certificate by that authority.\r\nSo long as each process trusts the certificate authority and is certain\r\nthat it has the correct public key for the authority, then two processes\r\ncan exchange public keys simply by sending each other a certificate\r\nfor itself issued by the authority.\r\nThus certificates can be forwarded around the system even when the authority\r\nmight be temporarily unavailable.\r\nA timestamp is usually included as part of the encrypted certificate so that\r\nobsolete or expired certificates can be ignored.\r\nCertificates are discussed further in Section \\ref{Se:CertificatesKeyStorage}.\r\n\r\nOnce two processes have successfully exchanged public keys\r\n(such as via a public-key authority or by exchanging certificates)\r\nthe following steps can be followed to protect against attacks\r\nbefore a secret key is exchanged:\r\n\\begin{enumerate}\r\n  \\item First, the initiator and receiver assure that they are communicating\r\n  with each other by exchanging nonce values. The initiator starts by sending\r\n  a request encrypted using the public key of the receiver,\r\n  including an identifier for itself and a nonce.\r\n\r\n  \\item The receiver replies with a response encrypted using the public key\r\n  of the initiator, including the nonce of the initiator as well as\r\n  its own nonce. This assures the initiator that it is communicating with\r\n  the receiver.\r\n\r\n  \\item The initiator then sends an acknowledgement encrypted using the\r\n  public key of the receiver, including the nonce of the receiver.\r\n  This assures the receiver that it is communicating with the initiator.\r\n\r\n  \\item One end then generates a secret key. Rather than just encrypting it once\r\n  using the public key of the other process (so that only that process can decrypt\r\n  it), the encrypted key is also further encrypted using the private key of the\r\n  process that generated it. This assures the other end that this process\r\n  was the process that created the key, and so is not susceptible to a\r\n  man-in-the-middle attack.\r\n\\end{enumerate}\r\n\r\n\r\n\\begin{exercise}[Diffie-Hellman Key Exchange]\r\nPrepare a program that uses the Diffie-Hellman key exchange algorithm over a\r\nTCP connection to exchange a secret key.\r\n\\end{exercise}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n%%%%% Elliptic Curve Cryptography                                                   %%%%%\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\section{Elliptic Curve Cryptography}\\label{Se:EllipticCurveCryptography}\r\nDue to recent progress in calculating prime factorizations RSA public keys\r\nneed to be at least 1024 bits to provide adequate security.\r\n\\defn{Elliptic Curve Cryptography} (ECC) is a promising alternative\r\nto RSA for public-key encryption, allowing a much shorter key to be used\r\nwith far less computational overhead, yet providing the same level of security\r\nas RSA against a cryptanalysis attack.\r\n\r\n\\noindent\r\n\\begin{minipage}{95mm}\r\n  For instance, in order to provide roughly the same level of security as a\r\n  128-bit AES key, RSA requires a 3072-bit key, which places quite a computational\r\n  burden on any devices using RSA. Worse still, to be equivalent to\r\n  a 256-bit AES key, RSA requires a 15360-bit key, which is infeasible on limited\r\n  devices such as mobile phones. ECC however requires just double the number of bits\r\n  than an AES key, making it particularly attractive for public-key encryption on limited devices. It has begun to challenge\r\n  RSA and Diffie-Hellman key exchange as the\r\n\\end{minipage}\r\n\\hfill\r\n\\begin{tabular}{|r|r|r|} \\hline\r\n  \\multicolumn{3}{|l|}{\\textit{Comparable Key Sizes}} \\\\ \\hline\\hline\r\n  \\textit{AES} & \\textit{RSA} & \\textit{ECC} \\\\ \\hline\r\n  --- & 512 & 112 \\\\\r\n  --- & 1024 & 160 \\\\\r\n  --- & 2048 & 224 \\\\\r\n  128 & 3072 & 256 \\\\\r\n  192 & 7680 & 384 \\\\\r\n  256 & 15360 & 512 \\\\\\hline\r\n\\end{tabular}\r\npreferred public-key cryptographic algorithm, since the difficulty of cryptanalysis against ECC gets harder for longer keys much faster than for either RSA or Diffie-Hellman.\r\n\r\nAn \\defn{elliptic curve} over a field consists of the set of points $(x,y)$\r\nwhere $x$ and $y$ are elements of the field that satisfy an equation of the form:\r\n\\begin{displaymath}\r\n  y^2 + a_1xy+a_3y = x^3+a_2x^2+a_4x+a_6,\r\n\\end{displaymath}\r\nwhere the coefficients $a_1, a_3, a_2, a_4, a_6$ are also elements of the field.\r\n\r\nIf the number of elements in the field is not divisible by $2$ nor $3$\r\n(such as the field $\\mathbb{R}$ of all real numbers\r\nor the finite field $\\mathbb{Z}_p$ for a prime $p>3$)\r\nthen using a suitable affine transformation results in the simpler equation:\r\n\\begin{displaymath}\r\n  y^2 = x^3+ax+b.\r\n\\end{displaymath}\r\nIf instead the number of elements is divisible by $2$ but not by $3$\r\n(such as the field $GF(2^m)$) then the equation is more\r\nconveniently expressed in the form $y^2+xy=x^3+ax^2+b$.\r\n\r\nThe \\defn{discriminant} $\\Delta=-16\\left(4a^3+27b^2\\right)$ for an elliptic curve\r\n$y^2 = x^3+ax+b$\r\nis a quantity analogous to $\\Delta=b^2-4ac$ for a quadratic curve $y=ax^2+bx+c$,\r\nthat determines the number of values of $x$ for which $y=0$.\r\nIf $\\Delta\\neq0$ then there are three distinct (possibly complex) solutions.\r\nFor example, the elliptic curves $y^2=x^3-x$, $y^2=x^3-x+1$, $y^2=x^3+x$\r\nall have non-zero discriminant, and so $x^3+ax+b=0$ has three distinct solutions\r\nfor $x$ (the first curve has roots $x=-1, 0, 1$, the second has roots\r\n$x\\approx-1.3247, 0.6624+0.5623i, 0.6624-0.5623i$, and the third has\r\n$x=0, i, -i$).\r\n\r\n\\noindent\r\n\\begin{pspicture}*(-1.5,-3.2)(2.5,2.5)\r\n  % draw the x and y axes\r\n  \\psaxes[arrows=->,linecolor=red](0,0)(-1.5,-2.5)(2.5,2.5)\r\n  \\rput(2.3,0.2){$x$}\\rput(0.15,2.2){$y$}\r\n  \\psset{linecolor=blue,linewidth=0.5mm}\r\n  \\psplot{-1}{0}{x 3 exp x sub sqrt}\r\n  \\psplot{-1}{0}{x 3 exp x sub sqrt -1 mul}\r\n  \\psplot{1}{2}{x 3 exp x sub sqrt}\r\n  \\psplot{1}{2}{x 3 exp x sub sqrt -1 mul}\r\n  \\rput(0.5,-2.7){\\small$y^2=x^3-x$}\r\n\\end{pspicture}\r\n\\hfill\r\n\\begin{pspicture}*(-1.5,-3.2)(2.5,2.5)\r\n  % draw the x and y axes\r\n  \\psaxes[arrows=->,linecolor=red](0,0)(-1.5,-2.5)(2.5,2.5)\r\n  \\rput(2.3,0.2){$x$}\\rput(0.15,2.2){$y$}\r\n  \\psset{linecolor=blue,linewidth=0.5mm}\r\n  \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt}\r\n  \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt -1 mul}\r\n  \\rput(0.5,-2.7){\\small$y^2=x^3-x+1$}\r\n\\end{pspicture}\r\n\\hfill\r\n\\begin{pspicture}*(-0.5,-3.2)(2.5,2.5)\r\n  % draw the x and y axes\r\n  \\psaxes[arrows=->,linecolor=red](0,0)(-0.5,-2.5)(2.5,2.5)\r\n  \\rput(2.3,0.2){$x$}\\rput(0.15,2.2){$y$}\r\n  \\psset{linecolor=blue,linewidth=0.5mm}\r\n  \\psplot{0}{2}{x 3 exp x add sqrt}\r\n  \\psplot{0}{1.7}{x 3 exp x add sqrt -1 mul}\r\n  \\rput(0.5,-2.7){\\small$y^2=x^3+x$}\r\n\\end{pspicture}\r\n\r\nSo long as the discriminant is not zero it can be shown that any elliptic curve\r\ngiven by $y^2=x^3+ax+b$ can be used to define an abelian group $E(a,b)$\r\nconsisting of all points $(x,y)$ on the curve together with another element denoted by $O$.\r\nIn this group the binary operation $+$ is defined for two points $P$ and $Q$\r\ndepending on four possible cases:\r\n\\begin{enumerate}\r\n  \\item If $P=O$ or $Q=O$ then $P+Q$ is just taken to be $P$ (if $Q=O$)\r\n  or else $Q$ (if $P=O$), so that $O$ acts as the identity for the group.\r\n\r\n \r\n   \\item If $P=(x, y)$ and $Q=(x, -y)$, so that $Q$ is the mirror image of $P$ in the $x$-axis\r\n    then $P+Q$ is taken to be $O$, so that $Q=-P$ is the inverse of $P$ in the group.\r\n    Algebraically:\r\n    \\begin{displaymath}\r\n      -\\left(x,y\\right) = \\left(x, -y\\right).\r\n    \\end{displaymath}\r\n\r\n  \\begin{pspicture}*[shift=2.5](-1,-1.25)(1.25,1.25)\r\n    \\psset{unit=0.5}\r\n    % draw the x and y axes\r\n    \\psaxes[arrows=->,linecolor=red,labels=none,ticks=none](0,0)(-2,-2.5)(2.5,2.5)\r\n    \\psset{linecolor=blue,linewidth=0.5mm}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt -1 mul}\r\n    \\psset{linecolor=black}\r\n    \\dotnode(1.5,1.696){P}\\rput(1.9,1.5){\\footnotesize$P$}\r\n    \\dotnode(1.5,-1.696){MP}\\rput(2,-1.5){\\footnotesize$-\\!P$}\r\n    \\psline[linecolor=red,linestyle=dashed,linewidth=0.2mm](1.5,1.696)(1.5,-1.696)\r\n  \\end{pspicture}\r\n  \\item\r\n\r\n    If $P=(x, y)$ and $Q=(x^\\prime, y^\\prime)$ with $x\\neq x^\\prime$ then $P+Q$ is taken\r\n    to be $-R$ where $R$ is the point where the line through $P$ and $Q$ meets the\r\n    elliptic curve a third time.\r\n    Algebraically, the slope of the line through $P$ and $Q$ is given by\r\n    $m=\\frac{y^\\prime-y}{x^\\prime-x}$\r\n    and the following equation can be derived:\r\n    \\begin{displaymath}\r\n      \\left(x,y\\right)+\\left(x^\\prime,y^\\prime\\right)\r\n      = \\left(m^2\\!-\\!x\\!-\\!x^\\prime, 2mx\\!+\\!mx^\\prime\\!-\\!m^3\\!-\\!y\\right).\r\n    \\end{displaymath}\r\n\r\n\r\n  \\begin{pspicture}*[shift=-2.5](-1,-1.25)(1.25,1.25)\r\n    \\psset{unit=0.5}\r\n    % draw the x and y axes\r\n    \\psaxes[arrows=->,linecolor=red,labels=none,ticks=none](0,0)(-2,-2.5)(2.5,2.5)\r\n    \\psset{linecolor=blue,linewidth=0.5mm}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt -1 mul}\r\n    \\psset{linecolor=black}\r\n    \\dotnode(1.5,1.696){P}\\rput(1.9,1.5){\\footnotesize$P$}\r\n    \\dotnode(0.588,0.785){Q}\\rput(0.9,0.4){\\footnotesize$Q$}\r\n    \\psline[linecolor=red,linewidth=0.2mm](-2,-1.804)(2.304,2.5)\r\n    \\psline[linecolor=red,linestyle=dashed,linewidth=0.2mm](-1.089,-0.893)(-1.089,0.893)\r\n    \\dotnode(-1.089,-0.893){R}\\rput(-1.1,-1.4){\\footnotesize$R$}\r\n    \\dotnode(-1.089,0.893){PQ}\\rput(-1.45,1.4){\\footnotesize$P\\!\\!+\\!\\!Q$}\r\n  \\end{pspicture}\r\n\r\n  \\item\r\n\r\n    If $P=Q$ then $P+Q=2 P$ is taken to be $-R$ where $R$ is the point\r\n    where the tangent line through $P$ meets the\r\n    elliptic curve again.\r\n    Algebraically, the slope of the tangent is given by $m=\\frac{3x^2+a}{2y}$\r\n    and the following equation can be derived:\r\n    \\begin{displaymath}\r\n      2\\left(x,y\\right) = \\left(m^2-2x, 3mx-m^3-y\\right).\r\n    \\end{displaymath}\r\n \r\n \r\n  \\begin{pspicture}*[shift=-2.5](-1,-1.25)(1.25,1.25)\r\n    \\psset{unit=0.5}\r\n    % draw the x and y axes\r\n    \\psaxes[arrows=->,linecolor=red,labels=none,ticks=none](0,0)(-2,-2.5)(2.5,2.5)\r\n    \\psset{linecolor=blue,linewidth=0.5mm}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt}\r\n    \\psplot{-1.3247}{2}{x 3 exp x sub 1 add sqrt -1 mul}\r\n    \\psset{linecolor=black}\r\n    \\dotnode(1.5,1.696){P}\\rput(1.9,1.5){\\footnotesize$P$}\r\n    \\psline[linecolor=red,linewidth=0.2mm](-1.12,-2.5)(2,2.5)\r\n    \\psline[linecolor=red,linestyle=dashed,linewidth=0.2mm](-0.256,-1.113)(-0.256,1.113)\r\n    \\dotnode(-0.256,-1.113){R}\\rput(-0.25,-1.6){\\footnotesize$R$}\r\n    \\dotnode(-0.256,1.113){PP}\\rput(-0.45,1.6){\\footnotesize$2P$}\r\n  \\end{pspicture}\r\n\\end{enumerate}\r\n\r\nIn Elliptic Curve Cryptography a finite field is used instead of $\\mathbb{R}$.\r\nTypically if ECC is implemented in software then the field\r\n$\\mathbb{Z}_p$ where $p$ is a prime is chosen and an elliptic curve\r\n$y^2=x^3+ax+b$ with $4a^3+27b^2\\neq0$ is used (called a \\defn{prime curve}),\r\nand addition calculations are performed using the previous algebraic equations:\r\n\\begin{eqnarray*}\r\n  \\left(x,y\\right)+\\left(x^\\prime,y^\\prime\\right)\r\n    &=& \\left(m^2\\!-\\!x\\!-\\!x^\\prime, 2mx\\!+\\!mx^\\prime\\!-\\!m^3\\!-\\!y\\right) \\\\\r\n  2\\left(x,y\\right) &=& \\left(m^2-2x, 3mx-m^3-y\\right).\r\n\\end{eqnarray*}\r\nThe number of elements in the resulting abelian group can be shown to be\r\nsomewhere between $p+1-2\\sqrt{p}$ and $p+1+2\\sqrt{p}$.\r\nIf instead ECC is implemented in hardware (where rapid bitwise operations are\r\nadvantageous) then the field $GF(2^m)$ where $m\\geq1$ is chosen and\r\nan elliptic curve $y^2+xy=x^3+ax^2+b$ with $b\\neq0$ is used\r\n(called a \\defn{binary curve}).\r\n\r\n\\begin{multicols}{2}\r\nAs an example, the elliptic curve $y^2=x^3-x+1$ over the field $\\mathbb{Z}_7$\r\nhas $11$ solutions, the points $(0,1)$, $(0,6)$, $(1,1)$, $(1,6)$,\r\n$(2,0)$, $(3,2)$, $(3,5)$, $(5,3)$, $(5,4)$, $(6,1)$, $(6,6)$.\r\nIncluding the identity $O$ results in a group $E(-1,1)$ with $12$ elements.\r\nNote that for any point $(x, y)$ in the abelian group\r\nits inverse is given by\r\n$-(x,y)=(x, -y)=(x, 7-y)$ resulting in symmetry in the\r\nillustrated grid. So for example $-(5,3)=(5,4)$ and $-(2,0)=(2,0)$.\\columnbreak\r\n\r\n\\begin{pspicture}[shift=1.75](-0.4,-0.7)(3.1,2.8)\r\n  \\psset{unit=0.5}\r\n  \\multirput*(0,0)(1,0){7}{\\psline[linestyle=dotted,linewidth=0.3mm](0,0)(0,6)}\r\n  \\rput(0,-0.4){\\footnotesize$0$}\\rput(1,-0.4){\\footnotesize$1$}\r\n  \\rput(2,-0.4){\\footnotesize$2$}\\rput(3,-0.4){\\footnotesize$3$}\r\n  \\rput(4,-0.4){\\footnotesize$4$}\\rput(5,-0.4){\\footnotesize$5$}\r\n  \\rput(6,-0.4){\\footnotesize$6$}\r\n  \\multirput*(0,0)(0,1){7}{\\psline[linestyle=dotted,linewidth=0.3mm](0,0)(6,0)}\r\n  \\rput(-0.4,0){\\footnotesize$0$}\\rput(-0.4,1){\\footnotesize$1$}\r\n  \\rput(-0.4,2){\\footnotesize$2$}\\rput(-0.4,3){\\footnotesize$3$}\r\n  \\rput(-0.4,4){\\footnotesize$4$}\\rput(-0.4,5){\\footnotesize$5$}\r\n  \\rput(-0.4,6){\\footnotesize$6$}\r\n  \\psset{dotsize=1.5mm}\r\n  \\dotnode(0,1){e1}\\dotnode(0,6){e2}\\dotnode(1,1){e3}\\dotnode(1,6){e4}\r\n  \\dotnode(2,0){e5}\\dotnode(3,2){e6}\\dotnode(3,5){e7}\\dotnode(5,3){e8}\r\n  \\dotnode(5,4){e9}\\dotnode(6,1){e10}\\dotnode(6,6){e11}\r\n\\end{pspicture}\r\n\\end{multicols}\r\n\\noindent\r\nTaking $P=(5,3)$ the equation for $2P$ gives that\r\n$m=\\frac{3\\cdot5^2-1}{2\\cdot3}=4\\cdot6^{-1}=3$\r\n(using the fact that $6^{-1}=6$ in the field $\\mathbb{Z}_7$) and so:\r\n\\begin{displaymath}\r\n  2P = \\left(3^2-2\\cdot5,3\\cdot3\\cdot5-3^3-3\\right) = (6,1).\r\n\\end{displaymath}\r\nLarger multiples $nP$ of a point $P$ can be found by repeated doubling of the previous value,\r\nobtaining $P, 2P, 4P, 8P, 16P, \\dots$ in $\\Theta(\\log_2 n)$. For some particular\r\ncurves and values of $p$ there are more efficient algorithms\r\n(such as the NIST P192 curve defined using the prime $p=2^{192}-2^{64}+1$\r\nwhere $nP$ can be found using up to 38 addition and 192 doubling operations,\r\nquite feasible for a limited device).\r\nHowever, for a cryptanalyst to determine $n$ given $P$ and $nP$ by brute force\r\nwould require checking $P, 2P, 3P, 4P, 5P, \\dots$ in $\\Theta(n)$, which is infeasible for\r\nlarge values of $n$\r\n(a brute force attack on the NIST P192 curve would require on average approximately\r\n$\\frac{1}{2}p\\approx3\\times10^{57}$ additions, completely infeasible on any computer).\r\nHence the security of ECC relies on the difficulty of computing the integer\r\n$n$ given the points $P$ and $nP$,\r\nwhich is named the \\defn{elliptic curve discrete logarithm problem}.\r\n\r\nECC can be utilized for key exchange by making public the\r\nchosen field ($p$ or $2^m$), the curve ($a$ and $b$ values in the field),\r\nand a point $G$ in the resulting abelian group for which there are many multiples\r\n$G, 2G, 3G, \\dots, nG$ that are all distinct\r\n(eventually the multiples start to repeat when for some integer value of $n$ called the\r\n\\defn{order} of $G$ one finds that $nG=O$).\r\nWhen two processes want to exchange a secret key each selects its own secure\r\nrandom number $s<n$ as its private key and calculates a public key\r\n$Q=sG$, which is communicated to the other process.\r\nWhen each process receives the public key $Q^\\prime=s^\\prime G$ of the other process\r\n(but not knowing the other private key $s^\\prime$), it calculates the secret key $K$:\r\n\\begin{displaymath}\r\n  K = s Q^\\prime.\r\n\\end{displaymath}\r\nNote that as in Diffie-Hellman key exchange this gives the same key for\r\nboth processes as:\r\n\\begin{displaymath}\r\n  s^\\prime Q\r\n  = \\underbrace{Q+Q+\\cdots+Q}_{s^\\prime\\mbox{ times}}\r\n  = \\underbrace{G+G+\\cdots+G}_{s\\cdot s^\\prime\\mbox{ times}}\r\n  = \\underbrace{Q^\\prime+Q^\\prime+\\cdots+Q^\\prime}_{s\\mbox{ times}}\r\n  = s Q^\\prime.\r\n\\end{displaymath}\r\n\r\nJCA provides support for Elliptic Curve Cryptography, including\r\nthe interface \\begin{code}ECField\\end{code}\r\nwith implementing classes \\begin{code}ECFieldFp\\end{code} and \\begin{code}ECFieldF2m\\end{code}\r\nfor representing finite fields of order $p$ and $2^m$ respectively,\r\nthe interface \\begin{code}ECKey\\end{code} with subinterfaces\r\n\\begin{code}ECPublicKey\\end{code}, \\begin{code}ECPrivateKey\\end{code}\r\nand implementing classes \\begin{code}ECPublic\\-KeySpec\\end{code},\r\n\\begin{code}ECPrivateKeySpec\\end{code}, and classes\r\n\\begin{code}EllipticCurve\\end{code}, \\begin{code}ECParameterSpec\\end{code},\r\n\\begin{code}ECGenParameterSpec\\end{code} for creating elliptic curves and suitable\r\nparameters for the cipher. The cipher for ECC is named \\begin{code}ECIES\\end{code}\r\nand the key agreement is named \\begin{code}ECDH\\end{code}.\r\nFor example, the Eclipse project \\begin{code}AndroidECKeyExchangeDemo\\end{code}\r\nhas the activity \\begin{code}AndroidECKeyExchangeActivity\\end{code}\r\nthat demonstrates ECC key exchange using the fixed elliptic curve secp256r1.\r\n\r\n\r\nThe Bouncy Castle lightweight API also supports Elliptic Curve Cryptography,\r\nincluding the class \\begin{code}ECCurve\\end{code} with subclasses\r\n\\begin{code}ECCurve.Fp\\end{code} and \\begin{code}ECCurve.F2m\\end{code}\r\nfor representing prime and binary curves,\r\n\\begin{code}ECPoint\\end{code} for representing a point on an elliptic curve,\r\nand \\begin{code}ECDomainParameters\\end{code} for suitable parameters for the cipher.\r\nThe MIDlet \\begin{code}ECKeyExchangeMIDlet\\end{code} demonstrates how ECC can be used for\r\nkey exchange. It creates an \\begin{code}ECCurve\\end{code} for the fixed elliptic curve secp256r1.\r\nUsing the parameters for the curve and a point\r\n(\\begin{code}GX\\end{code},\\begin{code}GY\\end{code}) on the curve\r\nan \\begin{code}AsymmetricCipher\\-KeyPair\\end{code}\r\nis generated and its public key made available to the other process.\r\nOnce the public key is received from the other process\r\na \\begin{code}BasicAgreement\\end{code} is used to calculate the\r\nsecret key.\r\nNote that the generation of the key pair is very computationally intensive,\r\nin practice this step would need to be performed in a background thread.\r\n\r\nBesides the shorter key size required for ECC as compared to other public-key encryption\r\nsystems, ECC encryption is not vulnerable to \\defn{index calculus} attacks\r\nthat are used against RSA and Diffie-Hellman, which make use of certain\r\nspecial properties of the groups created by RSA and Diffie-Hellman,\r\nproperties which are not found in the ECC groups $E(a,b)$.\r\nThe best known current attack against ECC is believed to be the \\defn{Pollard $\\rho$ attack},\r\none of a class of cryptanalysis techniques known as a \\defn{collision search}.\r\nHowever, even its computational requirements grow exponentially with the size of the field,\r\nquickly becoming infeasible for moderate values of $p$.\r\n\r\n\r\n\\begin{exercise}[ECC Key Exchange]\\label{Ex:AESEncryptionMobile}\r\n\tUse either the Android example\\\\\r\n\t \\begin{code}Andr\\-oidECKeyExchangeActivity\\end{code}\r\n\tor the Java ME Bouncy Castle lightweight example\\\\ \\begin{code}ECKeyExchangeMIDlet\\end{code}\r\n\tto prepare a mobile application that uses SMS communication to perform an ECC key exchange.\r\n\\end{exercise}\r\n\r\n\\begin{lstlisting}[caption=ECC key exchange]\r\n/**\r\n* Android Activity that demonstrates ECC key exchange using the fixed elliptic curve secp256r1\r\n* @author Andrew Ensor\r\n*/\r\npackage aut.hss;\r\n...\r\nimport java.math.BigInteger;\r\nimport java.security.InvalidAlgorithmParameterException;\r\nimport java.security.InvalidKeyException;\r\nimport java.security.KeyPair;\r\nimport java.security.KeyPairGenerator;\r\nimport java.security.NoSuchAlgorithmException;\r\nimport java.security.interfaces.ECPrivateKey;\r\nimport java.security.interfaces.ECPublicKey;\r\nimport java.security.spec.ECField;\r\nimport java.security.spec.ECFieldFp;\r\nimport java.security.spec.ECParameterSpec;\r\nimport java.security.spec.ECPoint;\r\nimport java.security.spec.EllipticCurve;\r\nimport java.util.Arrays;\r\nimport javax.crypto.KeyAgreement;\r\n...\r\npublic class AndroidECKeyExchangeActivity extends Activity implements\r\nOnClickListener\r\n{\r\nprivate Button exchangeButton;\r\nprivate TextView statusTextView;\r\n// well-known elliptic curve secp256r1 (256 bit prime, 32 byte)\r\nprivate static final BigInteger P = new BigInteger\r\n(\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFF...\", 16);\r\nprivate static final BigInteger A = new BigInteger\r\n(\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFF...\", 16);\r\nprivate static final BigInteger B = new BigInteger\r\n(\"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3...\", 16);\r\nprivate static final BigInteger GX = new BigInteger\r\n(\"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13...\", 16);\r\nprivate static final BigInteger GY = new BigInteger\r\n(\"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB64...\", 16);\r\nprivate static final BigInteger N = new BigInteger\r\n(\"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9C...\", 16);\r\nprivate static final int H = 1; // cofactor\r\n\r\n// inner class that represents one end of a key exchange\r\nprivate static class KeyExchangeProcess\r\n{\r\nprivate ECPublicKey publicKey;\r\nprivate ECPrivateKey privateKey;\r\n\\end{verbatim}\\hfill \\emph{cont-}\\end{program}\\end{figure*}%\r\n\\begin{figure*}\\begin{program}\\emph{-cont}\\begin{verbatim}\r\npublic KeyExchangeProcess()\r\n{  // create the elliptic curve\r\nECField field = new ECFieldFp(P);\r\nEllipticCurve curve = new EllipticCurve(field, A, B);\r\n// use existing precalculated values of G and N\r\nECPoint G = new ECPoint(GX, GY);\r\nECParameterSpec ecSpec = new ECParameterSpec(curve, G, N, H);\r\n// create public and private keys\r\ntry\r\n{  KeyPairGenerator kpg = KeyPairGenerator.getInstance(\"EC\");\r\nkpg.initialize(ecSpec); // size of key in bits\r\nSystem.out.println(\"About to generate a key pair\");\r\nKeyPair keyPair = kpg.generateKeyPair();\r\nSystem.out.println(\"Finished generating a key pair\");\r\nprivateKey = (ECPrivateKey)keyPair.getPrivate();\r\npublicKey = (ECPublicKey)keyPair.getPublic();\r\n\r\n}\r\ncatch (NoSuchAlgorithmException e)\r\n{  System.err.println\r\n(\"Encryption algorithm not available: \" + e);\r\n}\r\ncatch (InvalidAlgorithmParameterException e)\r\n{  System.err.println\r\n(\"Invalid Parameter in Encryption algorithm: \" + e);\r\n}\r\n}\r\n\r\npublic ECPublicKey getPublicKey()\r\n{  return publicKey;\r\n}\r\n\r\npublic byte[] calculateSecretKey(ECPublicKey otherPublicKey)\r\n{  // generate secret key using Elliptic Curve Diffie-Hellman\r\nbyte[] key = null;\r\ntry\r\n{  KeyAgreement ka = KeyAgreement.getInstance(\"ECDH\");\r\nka.init(privateKey); // initialize with own private key\r\nka.doPhase(otherPublicKey, true);\r\nkey = ka.generateSecret();\r\n}\r\ncatch (NoSuchAlgorithmException e)\r\n{  System.err.println\r\n(\"Key agreement algorithm not available: \" + e);\r\n}\r\ncatch (InvalidKeyException e)\r\n{  System.err.println\r\n(\"Invalid key in key agreement algorithm: \" + e);\r\n}\r\nreturn key;\r\n}\r\n}\r\n}\r\n\\end{lstlisting}\r\n\\begin{lstlisting}[caption=ECC key exchange via the Bouncy Castle]\r\n/**\r\n   A MIDlet that demonstrates ECC key exchange via the Bouncy Castle\r\n   lightweight API\r\n   @author Andrew Ensor\r\n*/\r\n...\r\npublic class ECKeyExchangeMIDlet extends MIDlet\r\n   implements CommandListener\r\n{\r\n   private Display display;\r\n   private Form form;\r\n   private Command exitCommand, exchangeCommand;\r\n   // well-known elliptic curve secp256r1 (256 bit prime, 32 byte)\r\n   private static final BigInteger P = new BigInteger\r\n      (\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFF...\", 16);\r\n   private static final BigInteger A = new BigInteger\r\n      (\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFF...\", 16);\r\n   private static final BigInteger B = new BigInteger\r\n      (\"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3...\", 16);\r\n   private static final BigInteger GX = new BigInteger\r\n      (\"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13...\", 16);\r\n   private static final BigInteger GY = new BigInteger\r\n      (\"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB64...\", 16);\r\n   private static final BigInteger N = new BigInteger\r\n      (\"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9C...\", 16);\r\n   private static final int H = 1; // cofactor\r\n\r\n   ...\r\n   // implementation of the CommandListener interface\r\n   public void commandAction(Command c, Displayable s)\r\n   {  if (c == exitCommand)\r\n         exitMIDlet();\r\n      else if (c == exchangeCommand)\r\n      {  KeyExchangeProcess processA = new KeyExchangeProcess();\r\n         KeyExchangeProcess processB = new KeyExchangeProcess();\r\n         CipherParameters publicKeyA = processA.getPublicKey();\r\n         CipherParameters publicKeyB = processB.getPublicKey();\r\n         BigInteger secretKeyA=processA.calculateSecretKey(publicKeyB);\r\n         BigInteger secretKeyB=processB.calculateSecretKey(publicKeyA);\r\n         if (secretKeyA.equals(secretKeyB))\r\n         {  form.append(\"Secret keys do agree and have length \"\r\n               + (secretKeyA.bitLength()+7)/8 + \" bytes\\n\");\r\n            form.append(\"Secret key: \".concat(secretKeyA.toString()));\r\n         }\r\n         else\r\n         {  form.append(\"Error: secret keys do not agree!\");\r\n            form.append(\"Secret key: \".concat(secretKeyA.toString()));\r\n            form.append(\"Secret key: \".concat(secretKeyB.toString()));\r\n         }\r\n      }\r\n   }\r\n\r\n   // inner class that represents one end of a key exchange\r\n   private class KeyExchangeProcess\r\n   {\r\n      private CipherParameters publicKey, privateKey;\r\n\r\n      public KeyExchangeProcess()\r\n      {  // create the elliptic curve\r\n         ECCurve.Fp curve = new ECCurve.Fp(P, A, B);\r\n         // use existing precalculated values of G and N\r\n         ECPoint G = new ECPoint.Fp(curve,\r\n            new ECFieldElement.Fp(P,GX), new ECFieldElement.Fp(P,GY));\r\n         ECDomainParameters params = new ECDomainParameters(curve, G,\r\n            N);\r\n         // create public and private keys\r\n         SecureRandom generator = new SecureRandom();\r\n         ECKeyGenerationParameters ecSpec\r\n            = new ECKeyGenerationParameters(params, generator);\r\n         ECKeyPairGenerator kpg = new ECKeyPairGenerator();\r\n         kpg.init(ecSpec);\r\n         System.out.println(\"About to generate a key pair\");\r\n         AsymmetricCipherKeyPair keyPair=kpg.generateKeyPair(); //slow\r\n         System.out.println(\"Finished generating a key pair\");\r\n         publicKey = keyPair.getPublic();\r\n         privateKey = keyPair.getPrivate();\r\n      }\r\n\r\n      public CipherParameters getPublicKey()\r\n      {  return publicKey;\r\n      }\r\n\r\n      public BigInteger calculateSecretKey\r\n         (CipherParameters otherPublicKey)\r\n      {  // generate secret key using\r\n         BasicAgreement ba = new ECDHBasicAgreement();\r\n         ba.init(privateKey); // initialize with own private key\r\n         BigInteger key = ba.calculateAgreement(otherPublicKey);\r\n         return key;\r\n      }\r\n   }\r\n}\r\n\\end{lstlisting}\r\n\r\n\r\n", "meta": {"hexsha": "6e1fea683ec4224a9dbf542dd88f3994b8c6113a", "size": 80454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PublicKeyEncryption.tex", "max_stars_repo_name": "millecodex/COMP716", "max_stars_repo_head_hexsha": "43db5c0b615f60bf2b8eb5130e5b788464a4b737", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "PublicKeyEncryption.tex", "max_issues_repo_name": "millecodex/COMP716", "max_issues_repo_head_hexsha": "43db5c0b615f60bf2b8eb5130e5b788464a4b737", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "PublicKeyEncryption.tex", "max_forks_repo_name": "millecodex/COMP716", "max_forks_repo_head_hexsha": "43db5c0b615f60bf2b8eb5130e5b788464a4b737", "max_forks_repo_licenses": ["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.4375, "max_line_length": 175, "alphanum_fraction": 0.6765232307, "num_tokens": 23741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8774767826757123, "lm_q1q2_score": 0.7995390340312997}}
{"text": "\n\\subsection{Quadratic polynomials}\n\nQuadratic polynomials are of the form \\(ax^2+bx+c=0\\).\n\n\\subsection{Solving quadratic polynomials}\n\n\\(x=\\dfrac{-b\\pm \\sqrt {b^2-4ac}}{2a}\\)\n\n\\subsection{Proof}\n\nWe can get the two solutions to a quadratic equation from the following manipulation.\n\n\\(ax^2+bx+c=0\\)\n\n\\(a[x^2+\\dfrac{b}{a}x]=-c\\)\n\n\\(a[(x+\\dfrac{b}{2a})^2-\\dfrac{b^2}{4a^2}]=-c\\)\n\n\\(a[(x+\\dfrac{b}{2a})^2]=\\dfrac{b^2}{4a}-c\\)\n\n\\((x+\\dfrac{b}{2a})^2=\\dfrac{b^2-4ac}{4a^2}\\)\n\n\\(x+\\dfrac{b}{2a}=\\pm \\sqrt {\\dfrac{b^2-4ac}{4a^2}}\\)\n\n\\(x=\\dfrac{-b\\pm \\sqrt {b^2-4ac}}{2a}\\)\n\n", "meta": {"hexsha": "0fde8a4c43e3c6d9478a23f8e1fba9f705a14632", "size": 569, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/polynomials/02-01-quadratic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/polynomials/02-01-quadratic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/polynomials/02-01-quadratic.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.3214285714, "max_line_length": 85, "alphanum_fraction": 0.6063268893, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810466522862, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7994902218034018}}
{"text": "\\input{../qxfkindle}\r\n\\begin{document}\r\n\r\n\\chapter{Matrix Definitions:}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&A_{m\\times n}=\\M{a}{m}{n}=[a_{ij}]_{m\\times n }\\\\\r\n   &\\text{Abbreviate as}~A.~\\text{For}~m=n,\\,\\text{write as}~A_n~\\tag{Matrix}\\\\\r\n   &\\text{For}~B=[b_{ij}]_{m\\times n},\\,a_{ij}=b_{ij},\\\\\r\n   &\\text{write as}~A=B\\tag{Matrix Equivalence}\\\\\r\n   &\\text{For}~\\forall a_{ij}=0,~\\text{write as}~O\\tag{Zero Matrix}\\\\\r\n   &\\text{For}~m=n,\\,\\forall(i\\neq j)\\,a_{ij}=0,\\,\\forall(i=j)\\,a_{ij}=1,\\\\\r\n   &\\text{write as}~E\\tag{Identity Matrix}\\\\\r\n   &\\text{Recollect here.}\\tag{Block Matrix}\\\\\r\n\\C~&A+B=[a_{ij} + b_{ij}]_{m\\times n}\\tag{Matrix Addition}\\\\\r\n   &C=AB=[a_{ij}]_{m\\times s}[b_{ij}]_{s\\times n}=[c_{ij}]_{m\\times n},\\\\\r\n   &c_{ij}=\\sum_{k=1}^{s}a_{ik}b_{kj}\\tag{Matrix Multiplication}\\\\\r\n   &kA=k[a_{ij}]_{m\\times n}=[ka_{ij}]_{m\\times n}\\tag{Matrix Scalar Multiplication}\\\\\r\n   &A=[a_{ij}]_{m\\times n},\\,A^T=[a_{ji}]_{n\\times m}\\tag{Transposition}\\\\\r\n\\C~&\\text{For}~A_n,~\\text{there is}~B~{that let}~AB=BA=E,\\\\\r\n   &\\text{write}~B~\\text{as}~A^{-1}\\tag{Inverse of Matrix}\\\\\r\n   &\\text{For}~A~\\text{that has}~A^{-1},\\\\\r\n   &\\text{call it invertible matrix}\\tag{Invertible Matrix}\\\\\r\n\\C~&\\text{Elementary Row Operations,}\\\\\r\n   &\\text{matrix row write as}~R_i,\\\\\r\n   &R_i\\leftrightarrow R_j\\tag{Row Switching}\\\\\r\n   &kR_i\\rightarrow R_i\\tag{Row Multiplication}\\\\\r\n   &kR_j + R_i\\rightarrow R_i\\tag{Row Addition}\\\\\r\n\\C~&\\text{Elementary Matrix}\\\\\r\n   &\\text{Apply row switching to}~E\\tag{\\(E_{ij}\\)}\\\\\r\n   &\\text{Apply row multiplication to}~E\\tag{\\(E_i(k)\\)}\\\\\r\n   &\\text{Apply row addition to}~E\\tag{\\(E_{ij}(k)\\)}\\\\\r\n\\C~&\\text{For}~AA^T=A^TA=E\\Leftrightarrow A^T=A^{-1}\\tag{Orthogonal Matrix}\\\\\r\n\\C~&|A_n|=\\MD{a}{n}\\\\\r\n   &\\qquad=\\sum_{j_1 j_2 \\cdots j_n} (-1)^{\\tau{(j_1 j_2 \\cdots j_n)}}\r\n      a_{1j_1}a_{2j_2}\\cdots a_{nj_n}\\tag{Determinant}\\\\\r\n\\C~&\\text{Pick}~p~\\text{rows and}~q~\\text{columns from}~A,\\\\\r\n   &\\text{use the cross elements of these rows and columns}\\\\\r\n   &\\text{to construct a matrix.}\\tag{Submatrix}\\\\\r\n   &\\text{For}~p=q=k,\\\\\r\n   &\\text{write as}~\\ps{A}_k\\tag{Principal Submatrix}\\\\\r\n\\C~&\\text{For}~\\exists{r},\\,\\forall|\\ps{A}_r|\\neq 0,\\,\\forall|\\ps{A}_{r+1}|=0,\\\\\r\n   &\\text{write as}~r(A)\\tag{Rank of Matrix}\\\\\r\n\\C~&M_{ij}=\\begin{vmatrix}\r\n      a_{11}&~\\cdots&~a_{1,j-1}&~a_{1,j+1}&~\\cdots&~a_{1n}\\\\\r\n      \\vdots&~      &~\\vdots   &~\\vdots   &~      &~\\vdots\\\\\r\n      a_{i-1,1}&~\\cdots&~a_{i-1,j-1}&~a_{i-1,j+1}&~\\cdots&~a_{i-1,n}\\\\\r\n      a_{i+1,1}&~\\cdots&~a_{i+1,j-1}&~a_{i+1,j+1}&~\\cdots&~a_{i+1,n}\\\\\r\n      \\vdots&~      &~\\vdots   &~\\vdots   &~      &~\\vdots\\\\\r\n      a_{n1}&~\\cdots&~a_{n,j-1}&~a_{n,j+1}&~\\cdots&~a_{nn}\r\n      \\end{vmatrix}\\tag{Minor}\\\\\r\n\\C~&A_{ij}=(-1)^{i+j}M_{ij}\\tag{Cofactor}\\\\\r\n\\C~&A^* = \\M{A}{n}{n}\\tag{Cofactor Matrix}\\\\\r\n\\C~&\\text{For}~AA^*=A^*A=E\\Leftrightarrow A^*=A^{-1}\\tag{Unitary Matrix}\r\n\\end{align*}\r\n\r\n\\chapter{Vector:}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&\\text{For 1 column matrix}~A_{n\\times 1},\\\\\r\n   &\\text{call it column vector, or simply vector},\\\\\r\n   &\\text{write it as}~\\V{\\alpha}\\tag{n-dimensional Vector}\\\\\r\n   &\\text{For all zero element vector,}\\\\\r\n   &\\text{write as}~\\V{0}\\tag{Zero Vector}\\\\\r\n\\C~&\\text{Vector Operation}\\\\\r\n   &\\text{For the rest of this \\textbf{Vector} section,}\\\\\r\n   &\\V{\\alpha}=\\MC{a}{n};\\;\\V{\\beta}=\\MC{b}{n};\\;k_1,k_2,\\cdots,k_n\\in\\V{R}\\\\\r\n   &k_1k_2\\cdots k_n\\neq 0;\\;s,t\\in\\V{Z}\\\\\r\n   &\\mathbb{A}_s = \\VG{\\alpha}{s};\\;\r\n    \\mathbb{B}_t = \\VG{\\beta}{t}\\\\\r\n   &\\V{\\alpha} + \\V{\\beta} = \\begin{bmatrix}\r\n      a_1 + b_1\\\\a_2 + b_2\\\\\\vdots\\\\a_n + b_n\r\n   \\end{bmatrix}\\tag{Addition}\\\\\r\n   &k\\V{\\alpha} = \\MC{ka}{n}\\tag{Scalar Multiplication}\\\\\r\n   &(\\V{\\alpha},\\V{\\beta}) = \\V{\\alpha}^T\\V{\\beta} = [a_1~a_2~\\cdots~a_n]\\MC{b}{n}\\\\\r\n   &= a_1b_1 + a_2b_2 + \\cdots + a_nb_n\\tag{Dot/Inner Product}\\\\\r\n\\C~&\\text{For~}\\exists k_1,k_2,\\cdots,k_n\\text{~make}\\\\\r\n   &\\V{\\beta} = k_1\\V{\\alpha}_1 + k_2\\V{\\alpha}_2 + \\cdots + k_n\\V{\\alpha}_n\\text{,~write as}\\\\\r\n   &\\mathbb{A}_s\\xrightarrow{LEXP}\\V{\\beta}\\tag{Linear Expression}\\\\\r\n\\C~&\\text{For~}\\forall\\V{\\alpha}\\in\\mathbb{A}_s,\\text{~has~}\\mathbb{B}_t\\xrightarrow{LEXP}\\V{\\alpha},\\text{~write~as}\\\\\r\n   &\\mathbb{B}_t\\xrightarrow{\\mathbb{LEXP}}\\mathbb{A}_s,\\text{~If~}\\mathbb{B}_t\\xrightarrow{\\mathbb{LEXP}}\\mathbb{A}_s\\text{~and~}\\mathbb{A}_s\\xrightarrow{\\mathbb{LEXP}}\\mathbb{B}_t\\\\\r\n   &\\text{write~as~}\\mathbb{A}_s\\equiv\\mathbb{B}_t\\tag{Vector Group Equivalence}\\\\\r\n\\C~&\\text{If~}\\mathbb{A}_s\\xrightarrow{LEXP}\\V{0},\\text{~say~}\\mathbb{A}_s\\text{~linearly correlated,~or~say~it}\\\\\r\n   &\\text{linearly~independent}\\tag{Linearly Independent}\\\\\r\n\\C~&\\mathbb{S}_r\\subset\\mathbb{A}_s,\\text{~(1)~}\\mathbb{S}_r\\text{~is~linearly~independent};\\\\\r\n   &\\text{(2) Add }\\forall\\V{\\alpha}_i\\in\\mathbb{A}_s\\text{~into~}\\mathbb{S}_r\\text{~to~make~a~}\\mathbb{S'}_{r+1},\\\\\r\n   &\\mathbb{S'}_{r+1}\\text{ is linearly correlated. Say }\\mathbb{S}_r\\text{ is maximal}\\\\\r\n   &\\text{linearly independent subset of }\\mathbb{A}_s\\tag{Maximal Linearly Independent Subset}\\\\\r\n\\C~&\\text{The number }r\\text{ of }\\mathbb{S}_r\\text{ is called rank of }\\mathbb{A}_s,\\text{ write as}\\\\\r\n   &r(\\VG{\\alpha}{s})\\text{ or }r\\tag{Rank of Vector Set}\\\\\r\n\\C~&\\text{n-dimentional vector space has 3 constituents:}\\\\\r\n   &\\text{(1) Universal set of n-dimentional vectors}\\\\\r\n   &\\text{(2) Scalar multiplication}\\\\\r\n   &\\text{(3) Addition}\\tag{Vector Space}\\\\\r\n\\C~&W\\text{ is a n-dimensional vector set that satisfies:}\\\\\r\n   &\\text{(1) }\\forall\\V{\\alpha},\\V{\\beta}\\in W\\text{ satisfies }\\V{\\alpha}+\\V{\\beta}\\in W\\\\\r\n   &\\text{(2) }\\forall\\V{\\alpha}\\in W,k\\in R\\text{ satisfies }k\\V{\\alpha}\\in W\\\\\r\n   &\\text{Say }W\\text{ is a subspace of n-dimensional vector space}\\tag{Linear Subspace}\\\\\r\n\\C~&\\text{Vector space }V\\text{ has vectors }\\VG{\\alpha}{m}\\text{ satisfy:}\\\\\r\n   &\\text{(1) }\\VG{\\alpha}{m}\\text{ is linearly indenpendent}\\\\\r\n   &\\text{(2) }\\forall\\V{\\beta}\\in V\\text{ satisfy }x_1\\V{\\alpha}_1+x_2\\V{\\alpha}_2+\\cdots+x_m\\V{\\alpha}_m=\\V{\\beta}\\\\\r\n   &\\text{Say }\\VG{\\alpha}{m}\\text{ is a basis of }V\\tag{Basis}\\\\\r\n   &\\text{Say number }m\\text{ is dimension of }V\\tag{Dimension}\\\\\r\n   &\\text{Say }\\SG{x}{m}\\text{ is coordinate of }\\V\\beta\\text{ under basis}\\\\\r\n   &\\VG{\\alpha}{m}\\tag{Cartesian Coordinate}\\\\\r\n   &\\text{Basis of }V:\\VG{e}{m}\\text{ that satisfies}\\\\\r\n   &(\\V{e}_i,\\V{e}_j)=\\begin{cases}1,&i=j\\\\0,&i\\neq j\\end{cases}\\tag{Standard Basis}\\\\\r\n\\C~&\\VG{\\alpha}{n}\\text{ and }\\VG{\\beta}{n}\\text{ both are vector}\\\\\r\n   &\\text{space basis, and satisfy }\\\\\r\n   &[\\VG{\\beta}{n}] = [\\VG{\\alpha}{n}]C\\text{ and}\\\\\r\n   &C=\\M{c}{n}{n},\\text{ call }C\\text{ transition matrix}\\\\\r\n   &\\text{for }\\VG{\\alpha}{n}\\text{ change to }\\VG{\\beta}{n}\\tag{Transition Matrix}\r\n\\end{align*}\r\n\r\n\\chapter{System of Linear Equations}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&\\text{General form:}\\\\\r\n   &\\begin{cases}\r\n   \\LE{a}{x}{1}{n}{0}\\\\\r\n   \\LE{a}{x}{2}{n}{0}\\\\\r\n   \\LD\\\\\r\n   \\LE{a}{x}{m}{n}{0}\r\n   \\end{cases}\\\\\r\n   &\\text{Vector form: }\\LE{\\V\\alpha}{x}{}{n}{\\V{0}}\\\\\r\n   &\\text{Matrix form: }A_{m\\times n}\\V{x}=\\V{0},\\text{ that}\\\\\r\n   &A=\\M{a}{m}{n},\\,\\V{x}=\\MC{x}{n},\\,\\V{0}=\\begin{bmatrix}0\\\\0\\\\\\vdots\\\\0\\end{bmatrix}\\\\\r\n   &\\text{Solution: }\\V\\xi=\\MC{c}{n}\\text{ satisfies }A\\V\\xi=\\V{0}\\\\\r\n   &\\text{Basic solution set: solutions }\\VG{\\xi}{n-r}\\text{ satisfy:}\\\\\r\n   &\\text{(1) }\\VG{\\xi}{n-r}\\text{ linearly independent}\\\\\r\n   &\\text{(2) For }\\forall\\V\\xi:\\:\\VG{\\xi}{n-r}\\xrightarrow{LEXP}\\V\\xi\\\\\r\n   &\\text{General solution: }\\LEX{k}{\\V\\xi}{n-r}\\\\\r\n   &\\tag{System of homogeneous linear equations}\\\\\r\n\\C~&\\text{General form:}\\\\\r\n   &\\begin{cases}\r\n   \\LE{a}{x}{1}{n}{b_1}\\\\\r\n   \\LE{a}{x}{2}{n}{b_2}\\\\\r\n   \\LD\\\\\r\n   \\LE{a}{x}{m}{n}{b_m}\\\\\r\n   \\end{cases}\\\\\r\n   &\\text{Vector form: }\\LE{\\V\\alpha}{x}{}{n}{\\V{b}}\\\\\r\n   &\\text{Matrix form: }A_{m\\times n}\\V{x}=\\V{b},\\text{ that}\\\\\r\n   &A=\\M{a}{m}{n},\\,\\V{x}=\\MC{x}{n},\\,\\V{b}=\\MC{b}{n}\\\\\r\n   &\\text{Solution: }\\V\\eta=\\MC{c}{n}\\text{ satisties }A\\V\\eta=\\V{b}\\\\\r\n   &\\text{General solution: }\\LEX{k}{\\V\\xi}{n-r}+\\V\\eta\\\\\r\n   &\\tag{System of inhomogeneous linear equations}\\\\\r\n\\C~&\\text{For }A_{n\\times n}\\V{x}=\\V{b}\\text{ that }|A|\\neq0,\\text{ there is only one}\\\\\r\n   &\\text{solution that can be described with:}\\\\\r\n   &x_i=\\frac{|A_i|}{|A|},i=1,2,\\cdots,n;\\text{ that}\\\\\r\n   &A_i=[\\V\\alpha_1~\\V\\alpha_2~\\cdots~\\V\\alpha_{i-1}~\\V{b}~\\V\\alpha_{i+1}~\\cdots~\\V\\alpha_n]\\tag{Cramer's rule}\r\n\\end{align*}\r\n\r\n\\end{document}", "meta": {"hexsha": "4b07144603ac278c221da8b40251408f2d93b7f5", "size": 8354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/linear-algebra-definitions.tex", "max_stars_repo_name": "qixiaofeng-gst/math-learning", "max_stars_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_stars_repo_licenses": ["MIT"], "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/linear-algebra-definitions.tex", "max_issues_repo_name": "qixiaofeng-gst/math-learning", "max_issues_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_issues_repo_licenses": ["MIT"], "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/linear-algebra-definitions.tex", "max_forks_repo_name": "qixiaofeng-gst/math-learning", "max_forks_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_forks_repo_licenses": ["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.6013071895, "max_line_length": 184, "alphanum_fraction": 0.584390711, "num_tokens": 3633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591977, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7994111202278311}}
{"text": "\\section{Linear Independence}\n$(a_1,...,a_k)$ is linearly dependent if\\\\\n$\\beta_1 a_1+...+\\beta_k a_k = 0$, for some $\\beta_1,,...\\beta_k$ ,that are not all zero\n\\subsection{Linear Independence}\n$(a_1,...,a_k)$ is linearly independent if\\\\\n$\\beta_1 a_1+...+\\beta_k a_k = 0$ \\& $\\beta_1 =...= \\beta_k =0$\\\\\n\\textbullet Adding vector to linearly dependent makes new vector linearly dependent\\\\\n\\textbullet Removing vector from linearly independent makes new vector linearly independent\\\\\n\\subsection{Basis}\n\\textit{basis}: A collection of n linearly independent(maximum possible size) n-vectors\n\\textbf{Independence-dimension inequality}\\\\\n\\textbullet \\textit{a linearly independent set of n-vectors can have at most n elements}\\\\\n\\textbullet \\textit{any set of n + 1 or more n-vectors is linearly dependent}\n\n\\subsection{Orthonomal Vectors}\n$a_1,...,a_k$ are (mutually) \\textit{orthogonal} if $a_i \\perp a_j$ for i != j\\\\\nThey are \\textit{normalized} if $\\Vert a_i\\Vert = 1$ for i=1,..,k\\\\\n\\textbullet \\textit{orthonormal} if \\textit{orthogonal} \\& \\textit{normalized}\\\\\n\\textbullet can be expressed using inner products\\\\\n$\na_i^Ta_j = \\left\\{\n  \\begin{array}{@{}ll@{}}\n    1, & \\text{if}\\ i=j \\\\\n    0, & i \\neq j\n  \\end{array}\\right.\n$\\\\\n\\textbullet orthonormal sets of vectors are linearly independent\\\\\n\\textbullet $a_1,. . . ,a_n$ is an orthonormal basis, we have for any n-vector $x = ( a^T_1 x ) a_1 +...+ ( a^T_n x ) a_n$\n\\subsection{Gram–Schmidt(orthogonalization)}\nAn algorithm to check if $a_1,...,a_k$ are linearly independent\\\\\n\\rule{\\linewidth}{0.4pt}\n\\textbf{given} n-vectors $a_1,...a_n$\\\\\n\\textbf{for} i = 1,..,k\\\\\n1.Orthogonalization: \\\\$\\tilde{q}_i = a_i - (q^T_1 a_i)q_1 - ... - (q^T_{i-1}a_i)q_{i-1}$\\\\\n2. Test for linear dependence: \\\\if $\\tilde{q} = 0$, quit\\\\\n3.Normalization: $q_i = \\tilde{q}_i/\\Vert \\tilde{q}_i\\Vert$\\\\\n\\rule{\\linewidth}{0.4pt}\n\n\\textbullet if G–S does not stop early (in step 2), $a_1 , . . . , a_k$ are linearly independent\\\\\n\\textbullet if G–S stops early in iteration $i = j$, then $a_j$ is a linear combination of $a_1,..,a_{j-1}$ (so $a_1,..,a_k$ are linearly dependent)\\\\\n\\textbf{Complexity}: $2nk^2$\n", "meta": {"hexsha": "6ac81440281f39e6e906b969ecb911b149c5e496", "size": 2150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter5.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2019-10-03T00:00:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-26T00:44:47.000Z", "max_issues_repo_path": "cheatsheet/inhalt/chapter5.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter5.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-10-01T14:09:07.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-11T20:02:53.000Z", "avg_line_length": 51.1904761905, "max_line_length": 150, "alphanum_fraction": 0.6860465116, "num_tokens": 773, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8947894569842487, "lm_q1q2_score": 0.7993238485285001}}
{"text": "\n\\subsection{2 Stage OLS (2SOLS) estimator}\n\n\\subsubsection{Motivation}\n\nIf \\(x\\) is correlated with the error term the OLS estimate will be biased.\n\n\\subsubsection{2 Stage OLS - first stage}\n\nWe have \n\n\\(y_i=x_i \\theta + \\epsilon_i \\)\n\n\\(x_i=z_i \\rho +\\mu_i\\)\n\nWe do OLS on the second to get \\(\\hat \\rho \\).\n\n\\(\\hat \\rho =(Z^TZ)^{-1}Z^TX\\)\n\nWe use this to get predicted values of \\(X\\).\n\n\\(\\hat X=Z\\rho =Z(Z^TZ)^{-1}Z^TX = P_ZX\\)\n\n\\subsubsection{2 Stage OLS - second stage}\n\nWe then regress \\(y\\) on the estimated \\(X\\):\n\n\\(y_i=\\hat x_i\\theta +\\epsilon_i\\)\n\nOur prediction is then:\n\n\\(\\hat {\\theta_{2SOLS}} = (\\hat {X^T}\\hat X)^{-1}\\hat {X^T}y)\\)\n\n\\(\\hat {\\theta_{2SOLS}} = ((P_ZX)^TP_ZX)^{-1}(P_ZX)^Ty)\\)\n\n\\(\\hat {\\theta_{2SOLS}} = (X^TP_ZX)^{-1}X^TP_Zy)\\)\n\nIf the dimension of \\(Z\\) is the same as \\(X\\) this collapses to:\n\n\\(\\hat {\\theta_{2SOLS}} = (Z^TX)^{-1}Z^Ty\\)\n\n", "meta": {"hexsha": "b632e03b1f0a3fd0e464e192faa81fd2b72ac6ac", "size": 872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsMore/03-01-2SOLS.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsMore/03-01-2SOLS.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsMore/03-01-2SOLS.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.7619047619, "max_line_length": 75, "alphanum_fraction": 0.6123853211, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7993118969470921}}
{"text": "\n\n\\section{Math}\n\n\\subsection{Taylor Series}\nIncredibly important for simplifications, approximations and to have a notion of the shape of the function.\n\nThe definition is as follows:\nA real or complex-valued function $f(x)$ that is infinitely differentiable at a real or complex number $a$ can be written as a power series the following way\n\n\\begin{align*}\n    f(x) &= \\sum_{n = 0}^{\\infty} \\frac{f^{(n)}(a)}{n!} (x-a)^n = \\\\\n    &= f(a)+{\\frac {f'(a)}{1!}}(x-a)+{\\frac {f''(a)}{2!}}(x-a)^{2}+{\\frac {f'''(a)}{3!}}(x-a)^{3}+\\cdots\n\\end{align*}\n\nSome utilities of this formula:\n\\begin{itemize}\n    \\item The approximation $(1+x)^n \\approx 1-x^n$, when x is much smaller than 1. (Binomial Series)\n    \\item When approximating $y(x) = cos(2x) + \\epsilon$ with a polynomial using least squares, the coefficients fo that polynomial will tend for the coefficients of Taylor's polynomial. Many MacLaurin Series (Taylor Series at the origin) can be found \\href{https://en.wikipedia.org/wiki/Taylor_series#List_of_Maclaurin_series_of_some_common_functions}{\\ul{Here in the Wiki}}.\n\\end{itemize}\n\n\\subsection{Erlang Models B and C}\n\\par These are statistical models to predict the necessary resources to satisfy a certain amount of traffic with the constraint of not serving at most a certain percentage of the incoming traffic at a given time. \n\\par Instead of thinking like:\n\\begin{center}\n    ``''\\textit{Hey, it's simple arithmetic! We get 3 200 calls a day. That's 400 calls an hour. Each call lasts three minutes, so each person can handle 20 calls and hour. So we'll need 20 incoming  lines and 20 people to answer the phones.}''\n\\end{center}\nGood models were created because of this! This is completely wrong if the calls don't arrive evenly distributed across the day, which is very likely. There are busy hours where the traffic is much bigger than in any other time of the day. \n\\par A.K. Erlang derived nice formulas for us to use. Note that the terms \"call\" and \"resource\" will be used interchangeable because these models can be used for a immense variety of applications besides call-centres. For instance, to figure how many printers to buy so that people in the office can print decently.\n\\par One last note: these formulas were derived for \"infinite sources\" of incoming traffic. However, they work very very well for cases when there are about 10x more sources than trunks. For real world applications that tends to be the case. \n\n\\par The concepts:\n\\begin{itemize}\n    \\item \\bb{Erlang}: Dimensionless unit. Regards the continuous use of a resource. Normally is referred to hours, therefore 90 minutes of traffic are regarded as 1.5 erlangs.\n    \\item \\bb{Grade of Service}: Probability of all servers/trunks being busy when a resource is requested for a given amount of traffic and for a certain amount of trunks.\n\\end{itemize}\n\n\n\\subsubsection*{Erlang B}\nUse if a call is really blocked, i.e if the person trying to use the resource doesn't wait to use it when all the trunks are busy at that time. Given 2 from \\ul{Traffic}, \\ul{Grade of Service} or \\ul{Number of Trunks} one may calculate the other.\n\\par Tables can be found \\href{https://onlinelibrary.wiley.com/doi/pdf/10.1002/0470862696.app5}{here}.\n\n\\subsubsection*{Erlang C}\nUse if a blocked call is delayed instead of the \"come back later\" that happens in the previous model. This one needs as well the \\ul{average duration of each call}.\n\n\n\n\n\\subsection{Probabilities}\n\n\n\\subsubsection{Conditional Probability}\n\nProbability of A happening given that B happened before. \nThe formula:\n\\quickimage{Other/math5.png}{.5}\n\nSome intuitive images:\n\\quickimage{Other/math3.png}{.3}\n\n\\quickimage{Other/math4.png}{.5}\n\n\n\n\n\\subsubsection{Bayes Theorem}\n\nThis an important topic. Is appears just about everywhere!\n\nWhat is the probability of something, given that something happened.\n\nWhat we'll see very very often is that this is associated with decision \nboundaries and thresholds. Depending on what we saw, the likeliness of what we \nthing was transmitted or the class we thing our data may belong, may change.\n\nThis is Bayes' Theorem in its discrete form:\n\n\\quickimage{Other/math2.png}{.5}\n\n\\quickimage{Other/math1.png}{.5}\n\n\nIn just about every case, we want to choose:\n\\begin{itemize}\n    \\item the symbol that was most likely transmitted given that we received a certain signal (the maximum likelihood criteria, which Bayes Theorem definitely is, may degenerate in a shortest distance criteria in phase and quadrature plots - remember QAM and PSK)\n    \\item the class that a certain sample most likely fits into is the class that most likely would generate that kind of sample. \n\\end{itemize} \n\nTherefore\n\n\n\\subsection{Optimization}\n\n\\subsubsection{Unconstraint Optimization}\n\n\\quickimage{AIML/AA-009.png}{.6}\nRefer to Section \\ref{sec:Hessian} for details of the Hessian Matrix.\n\n\n\\subsubsection{Constraint Optimization - Lagrange Multipliers} \\label{sec:Lagrange}\n\nThe Lagrange Multipliers is a mathematical optimization method, allows the finding of local maxima or minima of a function, subject to constraints.\n\nPerfect Explanation why it works:\n\n\\href{https://www.quora.com/Why-does-the-method-of-Lagrange-multipliers-work-for-optimization-in-multivariable-calculus-Why-exactly-given-a-function-f-x-y-and-a-constraint-g-x-y-c-can-we-set-the-gradients-of-the-functions-to-be-multiples-of-each-other}{\\ul{Quora - Intuition on Langrange Multipliers}}\n\nAnd a video showing exactly how it's done:\n\n\\href{https://www.youtube.com/watch?v=yuqB-d5MjZA}{\\ul{Khan Academy - Lagrange Multipliers Example}}\n\n\\vspace{.5cm}\n\n\\bb{How to use:}\n\nLet $f$ be the optimizing function and $g$ the constraint function. They are both scalar functions, i.e $\\mathds{R}^n \\rightarrow \\mathds{R}$. For example purpose, let is consider $n = 2$.\n\n\\begin{gather}\n    f(x,y) = x^2 y \\\\\n    g(x,y) = x^2+y^2 = c\n\\end{gather}\n\nThe Lagrange Multipliers Method for Constraint Optimization tells us that:\n\n\\begin{equation} \\label{eq:lagMult}\n    \\bigtriangleup f = \\lambda \\bigtriangleup g\n\\end{equation}\n\nThus, is common to formalize the Lagrangean function:\n\n\\begin{equation}\n    L(x,y,\\lambda) = f(x,y) - \\lambda g(x,y)\n\\end{equation}\n\nTo get the optimized point, we just have to solve the following system of $n+1$ equations for the $n$ dimensions and the lagrange multiplier:\n\n\\begin{gather}\n    \\begin{cases}\n        \\bigtriangleup L(x,y,\\lambda) = 0 \\\\\n        g(x,y) = c\n    \\end{cases}\n\\end{gather}\n\n\nCuriosity notes:\n\\begin{itemize}\n    \\item it doesn't matter if $g(x,y) = c$ is the constraint of if $g(x,y) = x^2 + y^2 - c = 0$ is the constraint. The constraint should be the last equation and the Lagrangean doesn't need that constant in there as it will disappear for our purposes\n    \\item The core of this methods is equation \\eqref{eq:lagMult}. This is true because in the point we want to obtain, there's tangency between the constraint and the optimizing function's contour lines\n    \\quickimagesidebyside{AIML/AA-007.png}{0.9}{AIML/AA-008.png}{0.7}\n    \\quickimage{AIML/AA-006.png}{0.4}\n    \\item If there are many constraints, they are summed in the Lagrangean, there will be an extra multiplier for each one and each one will appear in the final system of equations. Note that for each Lagrange Multiplier there should be one constraint equation to get that multiplier value.\n    \\item Yet another generalization can be made when there are constraints that are not $= c$ but are $\\geq c$. Refer to page 7 on Langrage Duality of \\href{http://cs229.stanford.edu/notes/cs229-notes3.pdf}{\\ul{Andrew Ng stanford Lectures notes on SVMs}}.\n    \\item Still regarding Lagrange Duality, consists of transformating the general Lagrangean into something else. In particular, Quadratic Programming is done is the SVM chapter.\n\\end{itemize}\n\\subsubsection{Constraint Optimization - Quadratic Programming}\n", "meta": {"hexsha": "af6507ffbc4fec3cb2301de500ed4406c22ecbcb", "size": 7849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Math.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/Math.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/Math.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": 50.3141025641, "max_line_length": 376, "alphanum_fraction": 0.7539813989, "num_tokens": 2055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8962513759047848, "lm_q1q2_score": 0.7992868816750816}}
{"text": "\\subsection{Gradient descent method}\n\nUsing the convolution notation \\eqref{con010}, we consider\n$$\nJ(v_h)=I(\\nu)=\\frac12\\nu^TA\\ast\\nu-b^T\\nu\n$$\nand \n$$\n\\nabla I(\\nu) =A\\ast \\nu -b,\n$$\nwhere $A=\\frac{1}{h}[-1,2, -1]$.\n\nAt the same time, let $\\displaystyle u_h=\\sum_{i=1}^n\\mu_i\\varphi_i,$\n\\begin{equation}\\label{min}\n\\displaystyle u_h=\\argmin_{v_h\\in V_h} J(v_h)\\Leftrightarrow \\mu=\\argmin_{\\nu \\in R^n} I(\\nu)\n\\end{equation}\n\nNoting that $\\nabla I(\\nu) =A\\ast \\nu -b$ and applying the gradient descent method to solve problem \\eqref{min}, we obtain \n$$\n\\mu^{(m)}=\\mu^{(m-1)}-\\eta(A\\ast \\mu^{(m-1)}-b),\\quad m=1,\\cdots,\\nu. \n$$\nAfter $\\nu$ iterations of gradient descent method, we denote the solution as $u_h^{\\nu}$.\n\nConsider the finite element discretization of Poisson equation in 1D: One very simple iterative method for \\eqref{min} is the following\ngradient descent method\n$$\n       \\mu^{(m)}=\\mu^{(m-1)}+\\eta (b-A\\ast \\mu^{(m-1)}),\n$$\nor, for $j=1:N$, \n$$ \n\\mu^{(m)}_j=\\mu^{(m-1)}_j+\\eta\n\\bigg(\\beta_j-\\frac{-\\mu^{(m-1)}_{j-1}+2\\mu^{(m-1)}_j-\\mu^{(m-1)}_{j+1}}{h}\\bigg),\n$$\nwhere $\\eta>0$ is a positive parameter named learning rate.  \n\nIt is not so difficult to\nproperly choose $\\eta$ so that the above iterative scheme converges,\nnamely for any initial guess $\\mu^0$, the sequence $(\\mu^{(m)})$ generated\nby the above iteration converges to the exact solution $\\mu$ of\n\\eqref{min}.\n\nNote that\n$$\n        \\mu=\\mu+\\eta (b-A\\ast\\mu),\n$$\nwe get\n$$\n        \\mu-\\mu^{(m)}=(I-\\eta A\\ast)(\\mu-\\mu^{(m-1)}),\n$$\nor\n$$\n        \\mu-\\mu^{(m)}=(I-\\eta A\\ast)^m(\\mu-\\mu^0), m=1,2,3,\\cdots\n$$\nAs we known,\n$$\n(I-\\eta A\\ast)^m\\longrightarrow 0\n$$\nif and only if $\\rho (I-\\eta A\\ast)<1$. Here $\\rho(B)$ is the spectral \nradius of $B$. However, $\\rho (I-\\eta A\\ast)<1$ if and only if\n$$\n0< \\mbox{all the eigenvalue of}~ A\\ast< 2\\eta^{-1}.\n$$\nThus, a necessary and sufficient condition for the \nconvergence is the following\n$$\n       0< \\eta<{2\\over \\rho(A\\ast)}.\n$$\nIt is easy to see that\n(for example, $4/h$ is an upper bound of its row sums)\n$$\n{4\\over {h}}> \\rho(A\\ast).\n$$\nTherefore it is reasonable to make the following choice\n$$\n        \\eta={h \\over 4}\n$$\nand the resulting algorithm is \n\\begin{equation}\\Label{1dRichardson}\n        \\mu^{(m)}=\\mu^{(m-1)}+{h\\over4} (b-A\\ast\\mu^{(m-1)}).\n\\end{equation}\nIn the rest of this section, unless otherwise noted, we shall choose\n$\\eta$ as above for simplicity.\n\nOn Figure~\\ref{fig:richardson} the convergence history plot of the\nabove gradient descent iterative method for typical application is shown.\nAs we see, this iterative scheme converges very slowly.\n\n\\begin{figure}[!htb]\n\\begin{center}\n\\includegraphics[height=5cm,width=3in]{pictures/richardson.pdf}\n\\end{center}\n\\caption{A picture on the GD method convergence history\n\\label{fig:richardson}}\n\\end{figure}\n\nOur main goal is to find a way to speed up such kind of rather slowly\nconvergent iterative scheme.  To do that, we need to study its\nconvergent property in more microscopic level.  First of all, let us\nnow take a careful look at the convergence history picture and make\nthe following observation:\n\\begin{quote}\n\\underbar{\\it Observation 1.}  The scheme converges rather fast in the\nvery beginning but then slows down after a few steps. Overall, the method \nconverges very slowly. \n\\end{quote}\nTo further understand this phenomenon, let us plot the detailed\npictures of the error functions in the first few iterations.\nAfter a careful look at these pictures, we have the following \nobservation:\n\\begin{quote}\n\\underbar{\\it Observation 2.} The scheme not only converges fast in the\nfirst few steps, but also smooth out the error function very quickly.\n\\end{quote}\n\n\\begin{figure}[!htb]\n\\begin{center}\n\\includegraphics[height=5cm,width=3in]{pictures/smoothing.pdf}\n\\end{center}\n\\caption{The smoothing effect of the gradient descent method\n\\label{fig:smoothing}}\n\\end{figure}\n\n\nIn other words, the error function becomes a much smoother function\nafter a few such simple iterations.  This property of the iterative\nscheme is naturally called {\\it a smoothing property} and an iterative\nscheme having this smoothing property is called a {\\it smoother}.\n\nThe above two observations, especially the second one, concern the\nmost important property of the simple gradient descent method that we can\ntake advantage to get a much faster algorithm.\n\n\nThe gradient descent method can be written in terms of $S_{0}:\\mathbb R^{N}\\rightarrow \\mathbb R^{N}$ satisfying\n\\begin{equation}\n\\label{jacobi1d}\n\\mu^{(1)}=(S_{0}b)={h\\over 4} b,\n\\end{equation}\nfor equation \\eqref{min} with initial guess zero.\nIf we apply this method twice, then\n$$\n\\mu^{(2)}=S_1(b) = S_{0} b + S_0(b - A\\ast(S_{0}b)),\n$$\nwith element-wise form\n\\begin{equation} \n\\begin{aligned}\n\\mu^{(2)}_{i} &={h\\over 16}(b_{i-1}+6b_i+b_{i+1}).\n\\end{aligned}\n\\end{equation}\nThen by the definition of convolution \\eqref{con010}, we have\n \\begin{equation}\\label{eq:convS}\n\\mu^{(1)}= S_{0}\\ast b \\quad \\mu^{(2)} = S_1 \\ast b.\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:kernel-S1d}\nS_{0} = {h\\over 4},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:kernel-S2}\nS_1={h\\over 16}[1,6,1].\n\\end{equation} \n\nHence we denote $S_0$ or $S_1$ as $S$.\n\nNow for any given $\\mu^{(0)}=\\tilde{\\mu}^{(0)}$, \n\\begin{equation}\n\\begin{aligned}\n&m=1,2,\\cdots,2\\nu\\\\\n&\\mu^{(m)}=\\mu^{(m-1)}+S_0\\ast(b-A\\ast\\mu^{(m-1)})\n\\end{aligned}\n\\end{equation}\n$$\\Leftrightarrow$$\n\\begin{equation}\n\\begin{aligned}\n&m=1,2,\\cdots,\\nu\\\\\n&\\tilde{\\mu}^{(m)}=\\tilde{\\mu}^{(m-1)}+S_1\\ast(b-A\\ast\\tilde{\\mu}^{(m-1)})\n\\end{aligned}\n\\end{equation}\nwe obtain $\\mu^{(2\\nu)}=\\tilde{\\mu}^{(\\nu)}$ which means one step $S_1$ is equivalent to two steps of $S_0$.\n\n\\paragraph{Convergence and smoothing properties of GD}\nBecause of the extraordinary importance of this smoothing property, we\nshall now try to give some simple theoretical analysis.  To do this,\nwe make use of the eigenvalues and eigenvectors of the matrix $A$.\n\\paragraph{Fourier analysis for the gradient descent method}\nOur earlier numerical experiments indicate that the gradient descent\nmethod has a smoothing property.  Based on our understanding of the\nrelation between the smoothness and the size of Fourier coefficients,\nwe can imagine that this smoothing property can be analyzed using the\ndiscrete Fourier expansion.\n\nLet $\\mu$ be the exact solution of \\eqref{min} and $\\mu^{(m)}$ the result of\n$m-th$ iteration from the gradient descent method \\rf{1dRichardson}.  Then\n$$\n\\mu-\\mu^{(m)}=(1-\\eta A\\ast)(\\mu-\\mu^{(m-1)})=\\ldots=(1-\\eta A\\ast)^m(\\mu-\\mu^{(0)}).\n$$\nConsider the Fourier expansion of the initial error:\n$$\n        \\mu-\\mu^{(0)}=\\sum_{k=1}^N\\alpha_k\\xi^k.\n$$\nThen \n$$\n        \\mu-\\mu^{(m)}=\\sum_{k=1}^N\\alpha_k(I-\\eta A\\ast)^m\\xi^k.\n$$\nNote that $\\eta=h/4$ and for any polynomial $p$\n$$\np(A\\ast)\\xi^k=p(\\lambda_k)\\xi^k,\n$$\nwe get\n$$\n        \\mu-\\mu^{(m)}=\\sum_{k=1}^N\\alpha_k(1-\\eta\\lambda_k)^m\\xi^k\n        =\\sum_{k=1}^N\\alpha_k^{(m)}\\xi^k\n$$\nwhere \n$$\n\\alpha_k^{(m)}=\\bigg(1-\\sin^2{{k\\pi}\\over {2(N+1)}}\\bigg)^m\\alpha_k.\n$$\nFor $k$ close to $N$, for example $k=N$,\nnote that \n$$\n1-\\sin^2{{N\\pi}\\over {2(N+1)}}=\\cos^2{{N\\pi}\\over {2(N+1)}}\n=\\sin^2({\\pi\\over2}-{{N\\pi}\\over {2(N+1)}})\n$$\nimplies\n$$\n|\\alpha_N^{(m)}|=|\\alpha_N|\\sin^{2m}{{N+1-N}\\over{N+1}}{\\pi\\over 2}\n\\le |\\alpha_k|\\bigg({{1}\\over{N+1}}{\\pi\\over 2}\\bigg)^{2m}\n$$\nwhich approaches to $0$ very rapidly when\n$m\\rightarrow\\infty$. This means that high frequency components get\ndamped very quickly. \n\nHowever, for $k$ far away from $N$, for example $k=1$, note that\n$$\n\\sin^2{{\\pi}\\over {2(N+1)}}\\le \\left({{\\pi}\\over {2(N+1)}}\\right)^2\n$$\nimplies\n$$\n|\\alpha_1^{(m)}|= |\\alpha_1| \\bigg(1-\\sin^2{{\\pi}\\over {2(N+1)}}\\bigg)^m\\ge  |\\alpha_1|  \\left(1-\\left({{\\pi}\\over {2(N+1)}}\\right)^2\\right)^m\n$$\nwhich approaches to $0$ very slowly when\n$m\\rightarrow\\infty$. \n\nThis simple analysis clearly justifies the smoothing property that has\nbeen observed by numerical experiments.\n\n%\\newpage\n\n\\begin{figure}[!ht]\n\\setlength{\\abovecaptionskip}{0pt}\n\\setlength{\\belowcaptionskip}{0pt}\n\\includegraphics[width=5cm]{figures/jianhongu0.png}\\qquad\n\\includegraphics[width=5cm]{figures/jianhongu1.png}\\qquad\n\\includegraphics[width=5cm]{figures/jianhongu2.png}\\qquad\n\\includegraphics[width=5cm]{figures/jianhongu3.png}\\qquad\n\\includegraphics[width=5cm]{figures/jianhongu4.png}\\qquad\n\\includegraphics[width=5cm]{figures/jianhongGDerror.png}\n\\caption{\\footnotesize{ $u-u^0$, $u-u^1$, $u-u^2$, $u-u^3$, $u-u^4$}}\n\\label{fig:Hmesh}\n\\end{figure}\n\n%\\begin{figure}[!ht] \n%\\centering\n%\\includegraphics[width=5cm,height=4cm]{figures/jianhongu0.png}\n%\\caption{ $u^0$}\n%\\label{fig:u0j}\n%\\end{figure}\n%\\begin{figure}[!ht] \n%\\centering\n%\\includegraphics[width=5cm,height=4cm]{figures/jianhongu1.png}\n%\\caption{ $u^1$}\n%\\label{fig:u1j}\n%\\end{figure}\n%\\begin{figure}[!ht] \n%\\centering\n%\\includegraphics[width=10cm,height=8cm]{figures/jianhongu2.png}\n%\\caption{ $u^2$}\n%\\label{fig:u2j}\n%\\end{figure}\n%\\begin{figure}[!ht] \n%\\centering\n%\\includegraphics[width=10cm,height=8cm]{figures/jianhongu3.png}\n%\\caption{ $u^3$}\n%\\label{fig:u3j}\n%\\end{figure}\n%\\begin{figure}[!ht] \n%\\centering\n%\\includegraphics[width=10cm,height=8cm]{figures/jianhongu4.png}\n%\\caption{ $u^4$}\n%\\label{fig:u4j}\n%\\end{figure} \n\n\\paragraph{An intuitive discussion} \nThe gradient descent method is oftentimes called {\\it local relaxation}\nmethods. This name refers to the fact that what that\nalgorithm does is just trying to correct the residual vector locally\nat one nodal point at a time (recall that $\\mu_j\\approx u(x_j)$).\nThis local relaxation procedure is then effective to the error\ncomponents that are local in nature.  Incidentally, the nonsmooth or\nhigh frequency component which oscillates across one or few grid\npoints have a strong local feature.  Therefore, it is not surprising the\n gradient descent  iteration can damp out these\nnonsmooth components more easily.  This method is very inefficient\nfor relatively smoother components in the error since a smoother\nfunction is more globally related in nature.\n\n", "meta": {"hexsha": "a9b816860825d3f627032689f14b79d651d93806", "size": 9998, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.2-smootherproperty.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.2-smootherproperty.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.2-smootherproperty.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.5667752443, "max_line_length": 142, "alphanum_fraction": 0.6963392679, "num_tokens": 3413, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.9294404086988677, "lm_q1q2_score": 0.7990062376427}}
{"text": "\\chapter{Functions}\n\\section{Basics}\nA function \\emph{f}, from A to B is an assignment of exactly one element of B\nto each element in A.\n\n\\begin{example}\n    Let \\emph{f} be a function such that $\\forall x \\in \\mathbb{R}$, $f(x) =\n    x^{2}$. You can observe that for any desired value of x, there is only one\n    unique mapping to $f(x)$. The reverse is not always true!\n\\end{example}\n\n\\begin{definition}\n    A function is considered \\textbf{\\underline{one-to-one or injective}} if\n    $f(x) = f(y) \\Leftrightarrow x = y$\n\\end{definition}\n\n\\begin{definition}\n    A function from A to B is \\textbf{\\underline{onto or surjective}} if $\\forall y\n    \\in B$ $\\exists x \\in A$ such that $f(x) = y$.\n\\end{definition}\n\n\\begin{definition}\n    A function that is both one-to-one and onto is called a\n    \\textbf{\\underline{bijection}}. A function that is bijective implies that\n    an inverse for the function exists!\n\\end{definition}\n\n\\begin{example}\n    Consider the function $f:\\mathbb{R} \\rightarrow \\mathbb{R}$ such that $f(x)\n    = 12x + 5$. Show that \\emph{f} has an inverse and find its inverse.\n\\end{example}\n\n\\begin{solution}\n    First we have to show that f is injective.\n\n    Let us assume that $f(x_{1}) = f(x_{2})$.\n\n    Then, $12x_{1} + 5 = 12x_{2} + 5 \\Leftrightarrow 12x_{1} = 12{x2}\n    \\Leftrightarrow x_{1} = x_{2}$. Thus, f is injective!\n\n    Next, we have to show that f is surjective.\n\n    Let $f(x) = y$. Then, $y = 12x + 5$.\n\n    Then, $x = \\frac{y - 5}{12}$. One can observe that for any real number y,\n    there exists a real number x such that $x = \\frac{y - 5}{12}$. Thus, f is\n    surjective!\n\n    Since f is a bijection, the inverse of f $f^{-1}(x) = \\frac{x - 5}{12}$\n\\end{solution}\n\n\\section{Floor and Ceiling Functions}\n\\begin{definition}\n    The \\textbf{floor} of any real number returns the greatest integer that is\n    less than or equal to the real number.\n\\end{definition}\n\n\\begin{definition}\n    The \\textbf{ceiling} of any real number returns the smallest integer that\n    is greater than or equal to the real number.\n\\end{definition}\n\n\\begin{example}\n    \\[\n        \\begin{split}\n            &\\lfloor 2.5 \\rfloor = 2, \\lfloor -3.4 \\rfloor = -4, \\lfloor 7\n            \\rfloor = 7 \\\\\n            &\\lceil 2.5 \\rceil = 3, \\lceil -3.4 \\rceil = -3, \\lceil \\pi \\rceil\n            = 4\n        \\end{split}\n    \\]\n\\end{example}\n\n\\subsection{Proofs regarding Floor and ceiling functions}\nI think it would be quite redundant to show proofs regarding floor and ceiling\nfunctions. Questions that are similar to the ones shown in the\n\\href{http://nook.cs.ucdavis.edu/~koehl/Teaching/ECS20/Lectures/Lecture5_notes.pdf}{\\underline{\\emph{lecture\nnotes}}} generally show up on the midterms/final. Thus, I have omitted this one\ntopic as you can just read it up from the notes.\n\n\\section{Growth of Functions}\nOften times, your task would be to determine the running time of an algorithm\nthat you just developed. These running times are represented as $O()$ (Big Oh),\n$\\Omega()$ (Big Omega), and $\\Theta()$ (Big Theta) respectively.\n\n\\subsection{Big-O Notation}\nThe Big-O Notation is often used to represent the worst case analysis. Think of\nBig-O as an upper bound for functions. The function f(x) is O(g(x)) if $[f(x)\n\\leq c \\times g(x)]$ for all x > k, where c is a positive constant.\n\n\\begin{example}\n    Show that $x^{2} + 5x + 3$ is $O(x^{2})$\n\\end{example}\n\n\\begin{solution}\n    In order for $x^{2} + 5x + 3$ to be $O(x^{2})$, $x^{2} + 5x + 3 \\leq\n    cx^{2}$.\n\n    We know that if $x > 1$ then, $5x \\leq 5x^{2}$ and $3 \\leq 3x^{2}$.\n\n    Adding these up we get: $x^{2} + 5x + 3 \\leq x^{2} + 5x^{2} + 3x^{2} \\leq\n    9x^{2}$.\n\n    Thus by selectively choosing $k = 1$ and $c = 9$, we can show that $x^{2} +\n    5x + 3$ is $O(x^{2})$.\n\n    For further verification and understanding, let us graph the functions\n    $x^{2} + 5x + 3$ and $9x^{2}$.\n\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            axis lines = left,\n            xlabel = $x$,\n            ylabel = {$f(x)$},\n        ]\n            %Below the red parabola is defined\n            \\addplot [\n                domain=0:50,\n                samples=100,\n                color=red,\n            ]\n            {x^2 + 5*x + 3};\n            \\addlegendentry{$x^2 + 5x + 3$}\n            %Here the blue parabola is defined\n            \\addplot [\n                domain=0:50,\n                samples=100,\n                color=blue,\n                ]\n                {9*x^2};\n            \\addlegendentry{$9x^{2}$}\n        \\end{axis}\n    \\end{tikzpicture}\n\n    As you can see, $x^2 + 5x + 3$ is never greater than $9x^{2}$.\n\\end{solution}\n\n\\subsection{Big-Omega Notation}\nThe Big-Omega Notation is often used to represent the best case analysis. Think\nof Big-Omega as an lower bound for functions. The function f(x) is\n$\\Omega(g(x))$ if $[f(x) \\geq c \\times g(x)]$ for all x > k, where c is a\npositive constant.\n\n\\begin{example}\n    Show that $x^{3} + 6x^{2} + 3$ is $\\Omega(x^{3})$\n\\end{example}\n\n\\begin{solution}\n    In order for $x^{3} + 6x^{2} + 3$ to be\n    $\\Omega(x^{3})$, $x^{3} + 6x^{2} + 3 \\geq cx^{3}$.\n\n    We know that if $x > 1$ then, $x^{3} + 6x^{2} + 3 \\geq x^{3}$.\n\n    Thus by selectively choosing $k = 1$ and $c = 1$, we can show that $x^{3} +\n    6x^{2} + 3$ is $\\Omega(x^{3})$.\n\n    For further verification and understanding, let us graph the functions\n    $x^{3} + 6x^{2} + 3$ and $x^{3}$.\n\n    \\begin{tikzpicture}\n        \\begin{axis}[\n            axis lines = left,\n            xlabel = $x$,\n            ylabel = {$f(x)$},\n        ]\n            %Below the red parabola is defined\n            \\addplot [\n                domain=0:50,\n                samples=100,\n                color=red,\n            ]\n            {x^3 + 6*x^2 + 3};\n            \\addlegendentry{$x^{3} + 6x^{2} + 3$}\n            %Here the blue parabola is defined\n            \\addplot [\n                domain=0:50,\n                samples=100,\n                color=blue,\n                ]\n                {x^3};\n            \\addlegendentry{$x^{3}$}\n        \\end{axis}\n    \\end{tikzpicture}\n\n    As you can see, $x^{3} + 6x^{2} + 3$ is always greater than $x^{3}$.\n\\end{solution}\n\n\\subsection{Big-Theta Notation}\nThe Big-Theta Notation is often used to represent the average case analysis.\nThink of Big-Theta as a tight bound for functions. The function f(x) is\n$\\Theta(g(x))$ if f(x) is $O(g(x))$ and if f(x) is $\\Omega(g(x))$\n\n\\begin{example}\nShow that $x^{2} + 4x + 7$ is $\\Theta(x^{2})$\n\\end{example}\n\n\\begin{solution}\n    First, we have to show that $x^{2} + 4x + 7$ is $O(x^{2})$.\n\n    Then, $x^{2} + 4x + 7 \\leq cx^{2}$.\n\n    We know that for all $x > 1$, $4x \\leq 4x^{2}$ and $7 \\leq 7x^{2}$. Adding\n    these up, we can say that $x^{2} + 4x + 7 \\leq 12x^{2}$. Thus by\n    selectively choosing $k = 1$ and $c = 12$ we can conclude that $x^{2} + 4x\n    + 7$ is $O(x^{2})$.\n\n    Next, we have to show the Big-Omega relation between these two functions.\n\n    We know that for all $x > 1$ $x^{2} + 4x + 7 \\geq x^{2}$\n\n    Thus by selectively choosing $k = 1$ and $c = 1$ we can\n    conclude that $x > 1$ $x^{2} + 4x + 7$ is $\\Omega(x^{2})$.\n\n    Thus $\\forall x > 1$ we can infer that:\n\n    \\[\n        x^{2} \\leq x^{2} + 4x + 7 \\leq 12x^{2}\n    \\]\n\n    Thus, $x^{2} + 4x + 7$ is $\\Theta(x^{2})$\n\\end{solution}\n\n\\subsection{Why do we need all this?}\nOften times in algorithm analysis, you deal with large chunks of data. If, for\nexample, $n = 10$ where n is the number of elements, then it doesn't really\nmatter how good or bad our Big-Oh is. What if $n = 1,000,000$? Then $n^{2}$ and\n$n^{3}$ would be significantly different. This is why we study the growth of\nthese functions. These notations are also sometimes referred to as time\ncomplexities. You will learn about time complexities extensively in ECS 60 and\nECS 122A.\n", "meta": {"hexsha": "e242f62ef8cb57bde17812e3497665c799a70c5d", "size": 7791, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ECS 20 Study Guide/Functions.tex", "max_stars_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_stars_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ECS 20 Study Guide/Functions.tex", "max_issues_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_issues_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-12-19T03:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-30T05:45:28.000Z", "max_forks_repo_path": "ECS 20 Study Guide/Functions.tex", "max_forks_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_forks_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-19T01:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-19T01:54:16.000Z", "avg_line_length": 33.7272727273, "max_line_length": 108, "alphanum_fraction": 0.5870876653, "num_tokens": 2584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681158979307, "lm_q2_score": 0.9314625060167181, "lm_q1q2_score": 0.7989788388155252}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Ratio and Root Tests}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to the Ratio and Root Tests.\n\\end{abstract}\n\\maketitle\n\n\nNote: As always, you can type the word ``infinity'' or ``infty'' (without quotes) in any entry box to indicate that the answer is infinite.\n\n\\begin{exercise}\nConsider the infinite series\n\\[ \\sum_{n=1}^\\infty n 2^{-n}. \\]\nApply the Ratio Test:\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{(n+1) 2^{-n-1}}}{\\answer{n 2^{-n}}} = \\answer{\\frac{1}{2}}. \\]\nApply the Root Test:\n\\[ \\lim_{n \\rightarrow \\infty} \\left| \\answer{n 2^{-n}} \\right|^{\\frac{1}{n}} = \\answer{\\frac{1}{2}}. \\]\nBoth tests indicate that the series \\wordChoice{\\choice[correct]{converges}\\choice{diverges}}.\n\\end{exercise}\n\n\\begin{exercise}\nOftentimes the Ratio Test is easier to apply than the Root Test when dealing with factorials. Use the Ratio Test to determine convergence or divergence of the series\n\\[ \\sum_{n=1}^\\infty \\frac{(n!)^2}{(2n)!}. \\]\nIn the spaces below, record the eponymous ``ratio'' in the first blanks, simplify it in the second blanks, and then record the limit.\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{\\frac{((n+1)!)^2}{(2n+2)!}}}{\\answer{\\frac{(n!)^2}{(2n)!}}} = \\lim_{n \\rightarrow \\infty} \\answer{\\frac{(n+1)^2}{(2n+1)(2n+2)}} = \\answer{\\frac{1}{4}}. \\]\nThe test \\wordChoice{\\choice[correct]{indicates convergence}\\choice{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}%APEX0804RATTST06\nApply the Ratio Test to the series given below.\n\\[ \\sum_{n=0}^\\infty \\frac{5^n-3n}{4^n} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{\\frac{5^{n+1}-3(n+1)}{4^{n+1}}}}{\\answer{\\frac{5^n-3n}{4^n}}} = \\lim_{n \\rightarrow \\infty} \\answer{\\frac{1}{4} \\frac{5^{n+1} - 3(n+1)}{5^n - 3n}} = \\answer{\\frac{5}{4}}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice[correct]{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Ratio Test to the series given below.\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^2+1} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{((n+1)^2+1)^{-1}}}{\\answer{(n^2+1)^{-1}}} = \\lim_{n \\rightarrow \\infty} \\answer{\\frac{n^2+1}{(n+1)^2+1}} = \\answer{1}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice{indicates divergence}\\choice[correct]{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Ratio Test to the series given below.\n\\[ \\sum_{n=1}^\\infty \\frac{3^n}{n^2 2^n} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{3^{n+1}/((n+1)^2 2^{n+1})}}{\\answer{3^n/(n^2 2^n)}} = \\lim_{n \\rightarrow \\infty} \\answer{ \\frac{3}{2} \\frac{n^2}{(n+1)^2}} = \\answer{\\frac{3}{2}}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice[correct]{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Ratio Test to the series given below.\n\\[ \\sum_{n=0}^\\infty \\frac{4^n}{4^n+1} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\frac{\\answer{\\frac{4^{n+1}}{4^{n+1}+1}}}{\\answer{\\frac{4^n}{4^n+1}}} = \\lim_{n \\rightarrow \\infty} \\answer{4 \\frac{4^n+1}{4^{n+1}+1}} = \\answer{1}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice{indicates divergence}\\choice[correct]{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nOftentimes the Root Test is easier to apply when terms have large exponents (growing faster than a constant times $n$). Use the Root Test to determine the convergence or divergence of the series\n\\[ \\sum_{n=1}^\\infty 4^n \\left( 1 - \\frac{1}{n} \\right)^{n^2}. \\]\nFirst say what should quantity should have its $n$-th root taken, then simplify, and lastly record the value of the limit.\n\\[ \\lim_{n \\rightarrow \\infty} = \\left| \\answer{4^n \\left( 1 - \\frac{1}{n} \\right)^{n^2}} \\right|^{\\frac{1}{n}} = \\lim_{n \\rightarrow \\infty} \\answer{4 \\left( 1 - \\frac{1}{n} \\right)^n} = \\answer{ \\frac{4}{e}}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice[correct]{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Root Test to the series given below.\n\\[ \\sum_{n=1}^\\infty  2^{- \\ln n} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\left| \\answer{2^{-\\ln n}} \\right|^{\\frac{1}{n}} = 2^{- \\lim_{n \\rightarrow \\infty} \\answer{\\frac{\\ln n}{n}}} = \\answer{1}. \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice{indicates divergence}\\choice[correct]{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Root Test to the series given below.\n\\[ \\sum_{n=1}^\\infty 2^{-n^2} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\left| \\answer{2^{-n^2}} \\right|^{\\frac{1}{n}} = \\lim_{n \\rightarrow \\infty} \\answer{2^{-n}} = \\answer{0}. \\]\nThe test \\wordChoice{\\choice[correct]{indicates convergence}\\choice{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Root Test to the series given below.\n\\[ \\sum_{n=1}^\\infty  e^{\\ln n} \\left( 1 - \\frac{1}{n} \\right)^{n^2} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\left| \\answer{e^{\\ln n} \\left( 1 - \\frac{1}{n} \\right)^{n^2}} \\right|^{\\frac{1}{n}} = \\lim_{n \\rightarrow \\infty} \\answer{e^{(\\ln n)/n} \\left( 1 - \\frac{1}{n} \\right)^{n}} = \\answer{1/e}. \\]\nThe test \\wordChoice{\\choice[correct]{indicates convergence}\\choice{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\begin{exercise}\nApply the Root Test to the series given below.\n\\[ \\sum_{n=1}^\\infty \\frac{e^{n^2}}{n^n} \\]\n\\[ \\lim_{n \\rightarrow \\infty} \\left| \\frac{e^{n^2}}{n^n} \\right|^{\\frac{1}{n}}  = \\lim_{n \\rightarrow \\infty} \\answer{e^n/n} = \\answer{\\infty} \\]\nThe test \\wordChoice{\\choice{indicates convergence}\\choice[correct]{indicates divergence}\\choice{is inconclusive}}.\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[2019RatioInconclusive1]\n\nDetermine which of the following three infinite series will lead to inconclusive results for the Ratio Test and then determine whether that series is convergent or divergent. \n\\[ \n\t\\text{I: }   \\sum_{k=1}^\\infty \\frac{1}{k - e^{-k}} \\ \\ \\\n\t\\text{II: }  \\sum_{m=1}^\\infty \\frac{1}{m^2 - e^{m}} \\ \\ \\\n\t\\text{III: } \\sum_{l=1}^\\infty \\frac{e^{-l}}{l^2+1}\n\\]\n\\begin{multiplechoice}\n\\choice{I inconclusive, converges}\n\\choice[correct]{I inconclusive, diverges}\n\\choice{II inconclusive, converges}\n\\choice{II inconclusive, diverges}\n\\choice{III inconclusive, converges}\n\\choice{III inconclusive, diverges}\n\\end{multiplechoice}\n\\begin{feedback}\nThe first series will give an inconclusive result for the Ratio Test because\n\\[ \n\\lim_{k \\rightarrow \\infty} \\frac{k - e^{-k}}{k+1 - e^{-k-1}} = \\lim_{k \\rightarrow \\infty} \\frac{1 - k^{-1} e^{-k}}{\\frac{k+1}{k} - k^{-1} e^{-k-1}} = \\frac{1 - 0}{1 - 0} = 1.\n\\]\nHowever, we know that the harmonic series diverges and that\n\\[ \\frac{1}{k - e^{-k}} > \\frac{1}{k}, \\]\nso by direct comparison to the harmonic series, series I must diverge.\n\\end{feedback}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "9f813ee199ea60cb31bbb9e7e4a8cf479e8f3858", "size": 6836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series/21ratiorootpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "series/21ratiorootpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "series/21ratiorootpractice.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": 52.992248062, "max_line_length": 222, "alphanum_fraction": 0.6701287303, "num_tokens": 2396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.900529781446146, "lm_q1q2_score": 0.7989541561923466}}
{"text": "\\subsection{$n^{th}$ Derivative}\r\n\\noindent\r\nWe'll use induction to show that\r\n\\begin{equation*}\r\n\\Laplace{f^{(n)}(t)} = s^n\\Laplace{f(t)} - f^{(n-1)}(0) - sf^{(n-2)}(0) - \\ldots - s^{n-1}f(0)\r\n\\end{equation*}\r\nWe'll start with the first derivative as a base case. We could use the $0^{th}$ derivative, but this case will give us a little more insight into where the formula comes from.\\\\\r\nLet $f$ be a differentiable function.\r\n\\begin{equation*}\r\n\\Laplace{f'(t)} = \\lim\\limits_{n\\to\\infty}{\\int_{0}^{n}{f'(t)e^{-st}\\mathrm{d}t}}\r\n\\end{equation*}\r\nIntegrating by parts and using the fundamental theorem of calculus,\r\n\\begin{equation*}\r\n\t = \\left(\\lim\\limits_{n\\to\\infty}{\\left(f(n)e^{-sn}\\right)} - f(0)e^{-s\\cdot 0}\\right) + \\lim\\limits_{n\\to\\infty}{s\\int_{0}^{n}{f(t)e^{-st} \\mathrm{d}t}}\r\n\\end{equation*}\r\nAssuming that $f(n)$ grows slower than $e^{-sn}$,\r\n\\begin{equation*}\r\n\t = \\left(0 - f(0)\\right) + \\lim\\limits_{n\\to\\infty}{s\\int_{0}^{n}{f(t)e^{-st} \\mathrm{d}t}}\r\n\\end{equation*}\r\nSince the right part of the expression is just $s$ times the definition of $\\Laplace{f}$,\r\n\\begin{equation*}\r\n\t = s\\Laplace{f} - f(0)\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{f'(t)} = s\\Laplace{f} - f(0)\r\n\\end{equation*}\r\nAssuming the following is true,\r\n\\begin{equation*}\r\n\t\\Laplace{f^{(n)}(t)} = s^n\\Laplace{f(t)} - f^{(n-1)}(0) - sf^{(n-2)}(0) - \\ldots - s^{n-1}f(0)\r\n\\end{equation*}\r\nwe'll show that the $n+1$ case follows.\r\n\\begin{equation*}\r\n\t\\Laplace{f^{(n+1)}(t)} = \\Laplace{\\left(f^{(n)}\\right)'}\r\n\\end{equation*}\r\nUsing our first derivative formula,\r\n\\begin{equation*}\r\n\t = s\\Laplace{f^{(n)}(t)} - f^{(n)}(0)\r\n\\end{equation*}\r\nUsing our general formula,\r\n\\begin{equation*}\r\n\t= s \\left(s^n\\Laplace{f(t)} - f^{(n-1)}(0) - sf^{(n-2)}(0) - \\ldots - s^{n-1}f(0)\\right) - f^{(n)}(0)\r\n\\end{equation*}\r\n\\begin{equation*}\r\n = s^{n+1}\\Laplace{f(t)} - f^{(n)}(0) - sf^{(n-1)}(0) s^2f^{(n-2)}(0) - \\ldots - s^{n}f(0)\r\n\\end{equation*}\r\nwhich is the $n+1$ case, meaning we have proven the general formula as correct.", "meta": {"hexsha": "1027a0fb5d0c565729304b2d76bf586fcd6a68e7", "size": 2013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/nthDerivative.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/laplaceTransforms/derivations/nthDerivative.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/laplaceTransforms/derivations/nthDerivative.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": 42.829787234, "max_line_length": 178, "alphanum_fraction": 0.609041232, "num_tokens": 834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133498259924, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7988992621119365}}
{"text": "\n\\subsection{Too many variables}\n\nIf there are more independent variables than samples then OLS will not work. There will be an infinite number of perfect fits.\n\nFor example if we regression genetic information on height with \\(1000\\) people, there will be too little data to fit using OLS.\n\nThis is due to colinearity.\n\nWe could also have too many variables through the use of derived variables. For example if we choose to use \\(x\\), \\(x^2\\), \\(x^3\\) etc.\n\n\\subsubsection{Optimal sparce regression}\n\nOptimal is \\(\\lambda = \\sigma 2\\sqrt {{2\\log (pn)}{n}}\\)\n\nRelies on knowing \\(\\sigma \\), which we may not.\n\nInstead we can use root LASSO.\n\nMinimise the squareroot of the sum of squares loss (over n) , and use \\(\\lambda = \\sqrt{2\\log (pn)/n}\\)\n\nDoesn't have \\(\\sigma \\)\n\nLasso biased, estimators \\(0\\) for many.\n\n\\subsubsection{Post-LASSO}\n\nWe can use LASSO for model selection, then use OLS on only those estimators.\n\n", "meta": {"hexsha": "8fe3c3ede47c4008bfc73c7cade9f71ffce547f7", "size": 921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/01-01-manyVariables.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/01-01-manyVariables.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/01-01-manyVariables.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.7, "max_line_length": 136, "alphanum_fraction": 0.7263843648, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133531922389, "lm_q2_score": 0.8499711737573763, "lm_q1q2_score": 0.7988992560430387}}
{"text": "%%% File: 3.5.tex\n%%% Author: Alexandre Medeiros <alexandre.medeiros@students.ic.unicamp.br>\n\n\\paragraph{3.5}\n\n\\subparagraph{a.}\n\nWe have that $f(n) = 100n + \\log n$ and $g(n) = n + (\\log n)^2$.\nThen let\n\\[\n  \\lim_{n \\to \\infty} \\frac{f(n)}{g(n)} =\n  \\lim_{n \\to \\infty} \\frac{100n + \\log n}{n + (\\log n)^2}\n\\]\nBy L'Hôpital's rule\n\\[\n  \\lim_{n \\to \\infty} \\frac{100n + \\log n}{n + (\\log n)^2} =\n  \\lim_{n \\to \\infty} \\frac{100 + \\frac{1}{n}}{1 + 2\\frac{\\log n}{n}} = 100\n\\]\n\\begin{equation}\\label{eq:ch03:5:a:O}\n  \\therefore f(n) = O(g(n))\n\\end{equation}\nNow, let\n\\[\n  \\lim_{n \\to \\infty} \\frac{g(n)}{f(n)} =\n  \\lim_{n \\to \\infty} \\frac{n + (\\log n)^2}{100n + \\log n}\n\\]\nBy L'Hôpital's rule\n\\[\n  \\lim_{n \\to \\infty} \\frac{n + (\\log n)^2}{100n + \\log n} =\n  \\lim_{n \\to \\infty} \\frac{1 + 2\\frac{\\log n}{n}}{100 + \\frac{1}{n}} =\n  \\frac{1}{100}\n\\]\n\\begin{equation}\\label{eq:ch03:5:a:Om}\n  \\therefore g(n) = O(f(n)) \\Leftrightarrow f(n) = \\Omega(g(n))\n\\end{equation}\nFrom \\eqref{eq:ch03:5:a:O} and \\eqref{eq:ch03:5:a:Om} we have that\n\\[\n  f(n) = \\Theta(g(n))\n\\]\n\n\\subparagraph{b.}\n\nWe have that $f(n) = \\log n$ and $g(n) = \\log n^2$.\nNote that\n\\[\n  g(n) = \\log n^2 = 2\\log n = 2 f(n)\n\\]\n\\[\n  \\therefore f(n) = \\Theta(g(n))\n\\]\n\n\\subparagraph{c.}\n\nWe have that $f(n) = \\frac{n^2}{\\log n}$ and $g(n) = n(\\log n)^2$.\nThen let\n\\[\n  \\lim_{n \\to \\infty} \\frac{f(n)}{g(n)} =\n  \\lim_{n \\to \\infty} \\frac{\\frac{n^2}{\\log n}}{n(\\log n)^2} =\n  \\lim_{n \\to \\infty} \\frac{n}{(\\log n)^3}\n\\]\nBy L'Hôpital's rule\n\\[\n  \\lim_{n \\to \\infty} \\frac{n}{(\\log n)^3} =\n  \\lim_{n \\to \\infty} \\frac{n}{3(\\log n)^2} =\n  \\lim_{n \\to \\infty} \\frac{n}{6\\log n} =\n  \\lim_{n \\to \\infty} \\frac{n}{6} = \\infty\n\\]\n\\[\n  \\therefore f(n) \\neq O(g(n))\n\\]\nNow, let\n\\[\n  \\lim_{n \\to \\infty} \\frac{g(n)}{f(n)} =\n  \\lim_{n \\to \\infty} \\frac{n(\\log n)^2}{\\frac{n^2}{\\log n}} =\n  \\lim_{n \\to \\infty} \\frac{(\\log n)^3}{n}\n\\]\nBy L'Hôpital's rule\n\\[\n  \\lim_{n \\to \\infty} \\frac{(\\log n)^3}{n} =\n  \\lim_{n \\to \\infty} \\frac{3(\\log n)^2}{n} =\n  \\lim_{n \\to \\infty} \\frac{6\\log n}{n} =\n  \\lim_{n \\to \\infty} \\frac{6}{n} = 0\n\\]\n\\[\n  \\therefore g(n) = O(f(n)) \\Leftrightarrow f(n) = \\Omega(g(n))\n\\]\n", "meta": {"hexsha": "dc876e5c66b8783cfa25d46e009760f83866b17b", "size": 2142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/5.tex", "max_stars_repo_name": "ILLusioness/manber-solutions", "max_stars_repo_head_hexsha": "f0bb4255874fe4a7d6a10e8d923af9bc61f070c4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 24, "max_stars_repo_stars_event_min_datetime": "2016-09-06T17:39:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-24T22:47:39.000Z", "max_issues_repo_path": "ch03/5.tex", "max_issues_repo_name": "ILLusioness/manber-solutions", "max_issues_repo_head_hexsha": "f0bb4255874fe4a7d6a10e8d923af9bc61f070c4", "max_issues_repo_licenses": ["MIT"], "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/5.tex", "max_forks_repo_name": "ILLusioness/manber-solutions", "max_forks_repo_head_hexsha": "f0bb4255874fe4a7d6a10e8d923af9bc61f070c4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 21, "max_forks_repo_forks_event_min_datetime": "2016-09-06T17:39:55.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T22:45:17.000Z", "avg_line_length": 24.6206896552, "max_line_length": 75, "alphanum_fraction": 0.5317460317, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7987192669141497}}
{"text": "\\section{The likelihood function}\n\nThe likelihood function is defined as the product of a set of the probability density functions (pdfs) of variables $x$, that used to evaluate the probability of the observed dataset:\n\\begin{equation}\\label{eq:likelihoodf}\n    \\mathcal{L} (x_{1}, ..., x_{N}; \\theta_{1}, ..., \\theta_{M}) = \\prod_{i}^{N} f(x_{i}; \\theta_{1}, ..., \\theta_{M})\n\\end{equation}\nwhere $\\theta_{1}$, ..., $\\theta_{M}$ are the nuisance parameters that can be written as $\\pmb{\\theta}$,\nand $x_{1}$, ..., $x_{N}$ denote the observables of dataset. \nUsually one measures the variable $x$ by constructing a histogram $\\pmb{n} = (n_{1}, ..., n_{N})$.\nThe expectation value of the ith bin $n_{i}$ is written as~\\cite{Cowan:2010js}:\n\\begin{equation}\\label{eq:discri}\n    E[n_{i}] = \\mu s_{i} + b_{i}\n\\end{equation}\nwhere $\\mu$ is the signal strength, $s_{i}$ and $b_{i}$ are the number of signal and background events in that bin.\nIn addition to the histogram $\\pmb{n}$, in some cases, one would like to use subsidiary measurements to further constrain the nuisance parameters.\nFor instance, due to the lack of background simulation or the mismodelling issue of one MC sample, one can choose a control region and construct another histogram $\\pmb{m} = (m_{1}, ..., m_{M})$ to constrain the contribution of one certain background in data.\nFor this measurement, the expectation value of the ith bin $m_{i}$ is written as:\n\\begin{equation}\\label{eq:cr}\n    E[m_i] = u_i(\\pmb{\\theta})\n\\end{equation}\n\nIn most particle experiments, the number of these events observed in one bin follows the Poisson distribution,\nby combining the equation~\\ref{eq:discri} and ~\\ref{eq:cr}, one can get the likelihood function for all bins as:\n\\begin{equation}\n    \\mathcal{L} (\\mu, \\pmb{\\theta}) = \\prod_{i=1}^{N} \\frac{(\\mu s_{i} + b_{i})^{n_i}}{n_i !} e^{-(\\mu s_{i} + b_{i})}\n    \\prod_{k=1}^{M} \\frac{u_k^{m_k}}{m_k !} e^{-u_k}\n\\end{equation}\n\nThen the profile likelihood ratio is defined to test the hypothesized value of $\\mu$:\n\\begin{equation} \\label{eq:lambda}\n    \\lambda (\\mu) = \\frac{\\mathcal{L}(\\mu, \\pmb{\\hat{\\hat{\\theta}}})}{\\mathcal{L}(\\hat{\\mu}, \\pmb{\\hat{\\theta}})}\n\\end{equation}\nwhere numerator denotes the local maximum-likelihood for a specific $\\mu$, $\\pmb{\\hat{\\hat{\\theta}}}$ is the value of $\\pmb{\\theta}$ that maximizes the numerator.\nAnd the denominator is the global maximum-likelihood with the $\\hat{\\mu}$ and $\\pmb{\\hat{\\theta}}$ as their best fit value.\n", "meta": {"hexsha": "165d66800e82aa256820962c0ea195aa6cc8c1f0", "size": 2468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Statistic/likelihood.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/Statistic/likelihood.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/Statistic/likelihood.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": 70.5142857143, "max_line_length": 259, "alphanum_fraction": 0.693273906, "num_tokens": 751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813551535005, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7987066820505649}}
{"text": "\n\\subsection{Disks}\n\nA disk is the area contained by a circle.\n\nAn open disk at \\((a,b)\\) of radius \\(r\\) is:\n\n\\(\\{(x,y)\\in \\mathbb R^2:(x-a)^2+(y-b)^2 < r^2\\}\\)\n\nFor a closed disk it is:\n\n\\(\\{(x,y)\\in \\mathbb R^2:(x-a)^2+(y-b)^2 \\le r^2\\}\\)\n\n", "meta": {"hexsha": "878ca3166506dddf423444180088f84ff4486337", "size": 243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/complex/03-03-disk.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/complex/03-03-disk.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/complex/03-03-disk.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.3571428571, "max_line_length": 52, "alphanum_fraction": 0.5432098765, "num_tokens": 102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422255326288, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7987064310522567}}
{"text": "\\section{Likelihood Ratio Methods}\nIn this section, we describe several methods based on the \\emph{likelihood ratio} technique of stochastic optimization. Let $Z$ be a random variable with a parametric probability density $p_\\theta$ and assume that $p_\\theta$ is known, explicitly computable and differentiable with respect to the parameters. The likelihood ratio technique is used to compute the following gradient\n\\begin{equation*}\n\t\\nabla_\\theta \\E[Z \\sim p_\\theta]{f(Z)} = \\nabla_\\theta \\int p_\\theta(z) f(z) dz\n\\end{equation*}\nThis type of problem appears in many domains, such as when computing the greeks of a  derivative product in computational finance \\cite{pages2016introduction}. Under some regularity assumptions on the function $f$ and on the probability distribution $p_\\theta$, this gradient can be rewritten in a more amenable way\n\\begin{equation*}\n\t\\begin{split}\n\t\t\\nabla_\\theta \\E[Z \\sim p_\\theta]{f(Z)} &= \\int \\nabla_\\theta p_\\theta(z) f(z) dz\\\\\n\t\t&= \\int p_\\theta(z) \\frac{\\nabla_\\theta p_\\theta(z)}{p_\\theta(z)} f(z) dz\\\\\n\t\t&= \\int p_\\theta(z) \\nabla_\\theta \\log p_\\theta(z) f(z) dz\\\\\n\t\t&= \\E[Z\\sim p_\\theta]{\\nabla_\\theta \\log p_\\theta(Z) f(Z)}\n\t\\end{split}\n\\end{equation*}\nThus, the likelihood ratio technique simply consists in the following equality\n\\begin{proposition}[Likelihood Ratio Technique]\n\\begin{equation}\n\t\\nabla_\\theta \\E[Z \\sim p_\\theta]{f(Z)} = \\E[Z\\sim p_\\theta]{\\nabla_\\theta \\log p_\\theta(Z) f(Z)}\n\\end{equation}\n\\end{proposition}\nThe quantity $\\nabla_\\theta \\log p_\\theta(Z)$ is usually called likelihood score. This result provides a simple way to approximate the gradient using a Monte Carlo estimate: let $\\{Z^{(m)}\\}_{m=1}^M$ be i.i.d. samples from $p_\\theta$, then \n\\begin{equation}\n\t\\nabla_\\theta \\E[Z \\sim p_\\theta]{f(Z)} \\approx \\frac{1}{M} \\sum_{m=1}^M \\nabla_\\theta \\log p_\\theta(Z^{(m)}) f(Z^{(m)})\t\n\\end{equation}\nAs we will see in the following sections, this technique provides the basis for some of the most common policy gradient algorithms in the reinforcement learning literature. \n\n\\subsection{Monte Carlo Policy Gradient}\n\\label{sec:MCPG}\nLet $h = {\\{(s_t, a_t)\\}}_{t\\geq 0} \\in \\H$ be a given trajectory of the MDP and let us \ndenote by $p_\\theta(h) = \\P[\\pi_\\theta]{H = h}$ the probability of obtaining \nthis trajectory under policy $\\pi_\\theta$. Let $G(h)$ denote the expected return obtained on trajectory $h$\n\\begin{equation*}\n\tG(h) = \\E{G_0 | H = h} = \\sum_{t=0}^\\infty \\gamma^t \\calR(s_t,\n\ta_t) \n\\end{equation*}\nLet us consider the start value objective function, which can be rewritten as an expectation over all possible trajectories\n\\begin{equation*}\n\tJ_{\\text{start}}(\\theta) = \\E[H \\sim p_\\theta]{G(H)}\n\\end{equation*}\nApplying the likelihood ratio technique, we obtain\n\\begin{equation}\n\\label{eq:gradient_MC}\n\t\t\\nabla_\\theta J(\\theta) = \\E[H\\sim p_\\theta]{\\nabla_\\theta \\log p_\\theta(H)G(H)}\n\\end{equation}\nThe crucial point is that $\\nabla_\\theta \\log p_\\theta(H)$ can be computed without\nknowledge of the transition probability kernel $\\calP$. Indeed, by a recursive application of the Markov property, we have\n\\begin{equation*}\n\tp_\\theta(h) = \\P{S_0 = s_0} \\prod_{t=0}^\\infty \\pi_\\theta(s_t, a_t)\n\t\\calP(s_t, a_t, s_{t+1})\n\\end{equation*}\ntaking the logarithm yields\n\\begin{equation*}\n\t\\log p_\\theta(h) = \\log \\P{S_0 = s_0} + \\sum_{t=0}^\\infty \\log \n\t\\pi_\\theta(s_t, a_t) + \\sum_{t=0}^\\infty \\log \\calP(s_t, a_t, s_{t+1})\n\\end{equation*}\nSince the only term depending on the parameters $\\theta$ is the policy term,\n\\begin{equation}\n\t\\nabla_\\theta \\log p_\\theta(H) = \\sum_{t=0}^\\infty \\nabla_\\theta \\log \n\t\\pi_\\theta(s_t, a_t)\n\\end{equation}\nTherefore, we do not need the transition model to compute the $\\nabla_\\theta \\log \np_\\theta(H)$. Moreover, it is easy to prove that\n\\begin{equation}\n\\label{eq:likelihood_bias}\n\t\\E[H\\sim p_\\theta]{\\nabla_\\theta \\log p_\\theta(H)} = 0\t\n\\end{equation}\nHence, a constant baseline $b \\in \\R$ can always be subtracted in Eq. \\ref{eq:gradient_MC} without changing the gradient value\n\\begin{equation}\n\\label{eq:gradient_MC_baseline}\n\t\\nabla_\\theta J(\\theta) = \\E[H \\sim p_\\theta]{\\nabla_\\theta \\log p_\\theta(H)(G(H)-b)}\n\\end{equation}\nIntuitively, the baseline $b$ should measure the expected return under the policy, so that better (resp. worse) than average returns would produce a positive (resp. negative) gradient. A simple approach is to use a moving average of the returns observed while improving the policy. A more elaborate approach is to compute the baseline that minimizes the variance of the estimate of the gradient.\\\\\nIn an episodic environment, we can derive an estimate of the gradient by sampling $M$ trajectories $h^{(m)} = \\{(s_t^{(m)}, a_t^{(m)})\\}_{t = 0}^{T^{(m)}}$ under policy $\\pi_\\theta$ and by approximating the expected value via Monte Carlo\n\\begin{equation}\n\\label{eq:reinforce_gradient}\n\t\\widehat{g}_{\\text{RF}} = \\frac{1}{M} \\sum^{M}_{m=1} \\left[ \\sum_{i=0}^{T^{(m)}} \n\t\\nabla_\\theta \\log \\pi_\\theta(s_i^{(m)}, a_i^{(m)}) \\right] \\left[\n\t\\sum^{T^{(m)}}_{j=0} \\gamma^j r_{j+1}^{(m)} - b \\right]  \n\\end{equation}\nThis method, synthetized in Algorithm \\ref{algo:reinforce}, is known in the literature as the REINFORCE algorithm and is guaranteed to converge to the true gradient at a pace of $O(M^{-1/2})$. In practice, we can obtain an approximation of the gradient using only one sample which leads to a stochastic gradient ascent method\n\\begin{equation}\n\t\\widehat{g}_{\\text{SRF}} = \\left[ \\sum_{i=0}^{T} \\nabla_\\theta \\log \\pi_\\theta(s_i, \n\ta_i) \\right] \\left[ \\sum^{T}_{j=0} \\gamma^j r_{j+1} - b \\right]  \n\\end{equation}\nThis method is very easy and works well on many problems. However, the gradient\nestimate is characterized by a large variance which can hamper the convergence\nrate of the algorithm. A first approach to address this issue is to optimally\nset the baseline to reduce the gradient variance.\n\n\\subsubsection{Optimal Baseline}\nA standard variance reduction technique consists in setting the baseline so as to minimize the gradient estimate variance. More in detail, the optimal baseline for the $k$-th gradient component $\\widehat{g}_{k}$ solves\n\\begin{equation*}\n\tb_k^* = \\argmin_b \\Var{\\widehat{g}_{k}}\n\\end{equation*} \nIt is easy to show that \n\\begin{equation*}\n\tb_k^* = \\frac{\\E{G(H) \\left(\\partial_{\\theta_k} \\log p_\\theta(H)\\right)^2  }}{\\E{\\left(\\partial_{\\theta_k} \\log p_\\theta(H)\\right)^2}}\n\\end{equation*}\nwhich can be approximated by \n\\begin{equation}\n\t\\label{eq:optimal_baseline}\n\t\\widehat{b}_k^* = \\frac{\\sum^{M}_{m=1} \\left[ \\sum_{i=0}^{T^{(m)}} \n\t\t\\partial_{\\theta_k} \\log \\pi_\\theta\\left(s_i^{(m)}, a_i^{(m)}\\right) \\right]^2 \n\t\t\\sum^{T^{(m)}}_{j=0} \\gamma^j r_{j+1}^{(m)}}{\\sum^{M}_{m=1} \\left[ \\sum_{i=0}^{T^{(m)}} \\partial_{\\theta_k} \\log \\pi_\\theta\\left(s_i^{(m)}, a_i^{(m)}\\right) \\right]^2}\n\\end{equation}\n\n\\begin{algorithm}[t]\n\t\\caption{Episodic REINFORCE policy gradient estimate}\n\t\\label{algo:reinforce}\n\t\\begin{algorithmic}[1]\n\t\t\\Require Policy parameterization $\\theta$, number of trajectories $M$\n\t\t\\Ensure REINFORCE policy gradient estimate $\\widehat{g}_{RF} \\approx \\nabla_\\theta J(\\theta)$\n\t\t\\State Sample $M$ trajectories of the MDP following policy $\\pi_\\theta$\n\t\t\\State For all $k$, Compute the optimal baseline $b_k^*$ according to Eq. (\\ref{eq:optimal_baseline})\n\t\t\\State Compute $\\widehat{g}_{\\text{RF}}$ according to Eq. (\\ref{eq:reinforce_gradient})\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\subsection{GPOMDP}\nThe Monte Carlo policy gradient estimate is typically characterized by a large variance, which may slow down the method's convergence. To improve the estimate, it is sufficient to notice that future actions and past rewards are independent, unless the policy has been changed. Therefore, combining this observation with Eq. (\\ref{eq:likelihood_bias}) yields\n\\begin{equation*}\n\t\\E[\\pi_\\theta]{\\nabla_\\theta\\log \\pi_\\theta(S_t, A_t) \\calR(S_s, A_s)} = 0\n\t\\;\\;\\;\\;\\; \\forall t>s\n\\end{equation*}\nPlugging this equation in Eq. (\\ref{eq:gradient_MC_baseline}) leads to the well-known \\gls{GPOMDP} algorithm \\cite{baxter2001infinite} for generating an estimate of the gradient of\nthe objective function\n\\begin{equation}\n\\label{eq:GPOMDP}\n\t\\widehat{g}_{\\text{GPOMDP}} = \\frac{1}{M} \\sum^{M}_{m=1} \\sum_{i=0}^{T^{(m)}} \n\t\\nabla_\\theta \\log \\pi_\\theta(s_i^{(m)}, a_i^{(m)}) \\left( \n\t\\sum^{T^{(m)}}_{j=i} \\gamma^j r_{j+1}^{(m)} - b \\right)\n\\end{equation}\nBy removing almost half of the cross-products, this estimate typically has a smaller variance than the trivial REINFORCE policy gradient and can be further reduced by computing an optimal baseline. In the following sections we will see how this algorithm can be easily derived from a more general result: the policy gradient theorem. \n\n\\subsection{Stochastic Policies}\nThe likelihood ratio technique is a powerful tool and it allows to derive some powerful policy gradient algorithms. However, this approach only works if the policy is  stochastic. In most cases this is not a big problem, since stochastic policies are needed anyway to ensure sufficient exploration of the state-action space. Moreover, stochastic policies might be beneficial in partially observable \\gls{MDP} to avoid state aliasing and in adversarial learning where the Pareto optimal strategies of different players are randomized, such as in the classical game ``rock-paper-scissors''. We introduce now two standard examples of stochastic policies for discrete and continuous action spaces respectively.  \n\n\\subsubsection{Boltzmann Exploration Policy}\n\\label{sec:softmax}\nIn discrete action spaces, the Boltzmann exploration policy, also known as softmax policy, is a common choice. In state $s \\in \\S$, this policy selects an action $a \\in \\A$ with probability \n\\begin{equation}\n\t\\pi_\\theta(s,a) = \\frac{e^{\\theta^T \\Phi(s,a)}}{\\sum_{b \\in \\A} e^{\\theta^T \\Phi(s,b)}}\n\\end{equation}    \nwhere $\\Phi(s,a) \\in \\R^{D_\\theta}$ is a given feature vector corresponding to state $s$ and action $a$. the likelihood score for this policy is thus given by \n\\begin{equation}\n\\nabla_\\theta \\log \\pi_\\theta(s,a) = \\Phi(s,a) - \\sum_{b\\in\\A} \\pi_\\theta(s,a) \\Phi(s,b)\n\\end{equation}\n\n\\subsubsection{Gaussian Exploration Policy} \n\\label{sec:gaussian_policy}\nIn continuous action spaces, a Gaussian exploration policy is commonly used. According to this policy, in a state $s$, actions are sampled from a Gaussian distribution with a parametric state-dependent mean $\\mu_\\psi(s) \\in \\R^{D_a}$, with $\\psi \\in \\R^{D_\\psi}$, and a covariance matrix $\\Sigma \\in \\R^{D_a \\times D_a}$. The policy parameters consist of $\\theta = \\{\\psi, \\Sigma\\}$ and the likelihood scores are thus given by \n\\begin{equation}\n\t\\nabla_\\psi \\log \\pi_\\theta(s,a) = \\left(\\frac{\\partial \\mu_\\psi(s)}{\\partial \\psi}\\right)^T \\Sigma^{-1} (a - \\mu_\\psi(s))\n\\end{equation}\n\\begin{equation}\n\t\\nabla_\\Sigma \\log \\pi_\\theta(s,a) = \\frac{1}{2}\\left[\\Sigma^{-1} \\left(a - \\mu_\\psi(s)\\right) \\left(a - \\mu_\\psi(s)\\right)^T \\Sigma^{-1} - \\Sigma^{-1}\\right]\n\\end{equation}\nwhere $\\frac{\\partial \\mu_\\psi(s)}{\\partial \\psi}$ denotes the Jacobian matrix of $\\mu_\\psi$ with respect to $\\psi$.\n\n\\subsection{Policy Gradient with Parameter Exploration}\nIn Monte Carlo Policy Gradient, trajectories are generated by sampling at each\ntime step an action according to a stochastic policy $\\pi_\\theta$ and the\nobjective function gradient is estimated by differentiating the policy with\nrespect to the parameters. However, sampling an action from the policy at each\ntime step leads to a large variance in the sampled histories and therefore in \nthe gradient estimate, which can in turn slow down the convergence of the\nlearning process. To address this issue, in \\cite{sehnke2008policy} the authors\npropose the \\glsfirst{PGPE}\nmethod, in which the search in the policy space is replaced with a direct\nsearch in the model parameter space. We start by presenting the episodic case\nand we will later extend this approach to the infinite horizon setting.  \n\n\\subsubsection{Episodic PGPE}\nGiven an episodic \\gls{MDP}, \\gls{PGPE} considers a deterministic controller $F: \\S \\times \\Theta \\to \\A$ that, given a set of parameters $\\theta \\in \\Theta \\subseteq\n\\R^{D_\\theta}$, maps a state $s \\in \\S$ to an action $a = F(s; \\theta) =\nF_\\theta(s) \\in \\A$. The policy parameters are drawn from a probability distribution $p_\\xi$, with hyper-parameters $\\xi \\in \\Xi \\subseteq \\R^{D_\\xi}$. Combining these two\nhypotheses, the agent follows a stochastic policy $\\pi_\\xi$ defined by\n\\begin{equation*}\n\t\\forall B \\in \\calA ,\\ \\pi_\\xi(s,B) = \\pi(s, B; \\xi) = \\int_\\Theta p_\\xi(\\theta) \n\t\\ind{F_{\\theta}(s)\\in B} d\\theta\n\\end{equation*}\nThe advantage of this approach is that the controller is deterministic and\ntherefore the actions do not need to be sampled at each time step, with a\nconsequent reduction of the gradient estimate variance. Indeed, It is\nsufficient to sample the parameters $\\theta$ once at the beginning of the\nepisode and then generate an entire trajectory following the deterministic \npolicy $F_\\theta$. As an additional benefit, the parameter gradient is\nestimated by direct parameter perturbations, without having to backpropagate\nany derivatives, which allows to use non-differentiable controllers.\\\\\nThe hyper-parameters $\\xi$ will be updated by following the gradient ascent direction of the gradient of the expected reward, which can be rewritten as \n\\begin{equation}\n\t\\begin{split}\n\t\tJ(\\xi) = \\E[\\substack{\\theta \\sim p_\\xi\\\\H \\sim p_\\theta}]{G(H)} =\n\t\t\\int_\\Theta \\int_\\H p_\\xi(\\theta, h) G(h) dh d\\theta\\\\\n\t\\end{split}\n\\end{equation}\nBy remarking that $h$ is conditionally independent from $\\xi$ given $\\theta$, so that $p_\\xi(\\theta, h) = p_\\xi(\\theta) p_\\theta(h)$, and applying the likelihood ratio technique, we obtain\n\\begin{equation}\n\t\\begin{split}\n\t\t\\nabla_\\xi J(\\xi) = \\E[\\substack{\\theta \\sim p_\\xi\\\\H \\sim p_\\theta}]{\\nabla_\\xi \\log p_\\xi(\\theta) G(H)}\n\t\\end{split}\n\\end{equation}\nAgain, we can subtract a constant baseline $b \\in \\R$ from the total return \n\\begin{equation}\n\t\\nabla_\\xi J(\\xi) = \\E{\\nabla_\\xi \\log p_\\xi(\\theta)\\left(G(H) - b\\right)}\n\\end{equation}\nIn an episodic environment, the gradient can be approximated via Monte Carlo by first drawing $M$ samples $\\theta^{(m)} \\sim p_\\xi$ and then, for each combination of parameters, generating a trajectory $h^{(m)} = \\{(s_t^{(m)}, a_t^{(m)})\\}_{t \\geq 0}$ where actions are selected according to the deterministic controller $F_{\\theta^{(m)}}$. This leads to the following estimate\n\\begin{equation}\n\\label{eq:pgpe_gradient}\n\t\\widehat{g}_{\\text{PGPE}} = \\frac{1}{M} \\sum^{M}_{m=1} \\nabla_\\xi \\log p_\\xi\\left(\\theta^{(m)}\\right) \\left[G\\left(h^{(m)}\\right)-b\\right] \n\\end{equation}\nIn order to further reduce the estimate variance, an optimal baseline can be computed similarly to the REINFORCE case \\cite{zhao2011analysis}. The episodic \\gls{PGPE} algorithm obtained in this way is reported in Algorithm \\ref{algo:episodic_pgpe}. In the following paragraphs, we discuss some possible choices for the policy parameters distribution $p_\\xi$, which is the last component of the algorithm. \n\n\\begin{algorithm}[t]\n\t\\caption{Episodic PGPE algorithm}\n\t\\label{algo:episodic_pgpe}\n\t\\begin{algorithmic}[1]\n\t\t\\Require Initial hyper-parameters $\\xi_0$, learning rate $\\{\\alpha_k\\}$\n\t\t\\Ensure Approximation of the optimal policy $F_{\\xi^*} \\approx \\pi_*$\n\t\t\\Repeat\n\t\t\t\\For {$m = 1, \\ldots, M$}\n\t\t\t\t\\State Sample controller parameters $\\theta^{(m)} \\sim p_{\\xi_k}$ \n\t\t\t\t\\State Sample trajectory $h^{(m)} = \\{(s_t^{(m)}, a_t^{(m)})\\}_{t \\geq 0}$ under policy $F_{\\theta^{(m)}}$\n\t\t\t\\EndFor\n\t\t\t\\State Approximate policy gradient $\\nabla_\\xi J(\\xi_k) \\approx \\widehat{g}_\\text{PGPE}$ using Eq. (\\ref{eq:pgpe_gradient})\n\t\t\t\\State Update hyperparameters using gradient ascent $\\xi_{k+1} = \\xi_k + \\alpha_k \\widehat{g}_\\text{PGPE}$\n\t\t\t\\State $k \\leftarrow k + 1$\n\t\t\\Until{converged}\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\paragraph{Independent Gaussian Parameter Distribution}\nA simple approach is to assume that all the components of the parameter vector\n$\\theta$ are independent and normally distributed with mean $\\mu_i$ and\nvariance $\\sigma_i^2$, in other words $\\theta_i \\sim \\mathcal{N}(\\mu_i, \\sigma_i^2)$, the gradient with respect to the hyper-parameters $\\xi = (\\mu_1, \\ldots, \\mu_{D_\\theta}, \\sigma_1,$ $\\ldots, \\sigma_{D_\\theta})^T$ is given by \n\\begin{equation}\n\t\\begin{split}\n\t\t\\pardev{\\log p_\\xi(\\theta)}{\\mu_i} &= \\frac{\\theta_i -\n\t\t\\mu_i}{\\sigma_i^2}\\\\\t\n\t\t\\pardev{\\log p_\\xi(\\theta)}{\\sigma_i} &= \\frac{(\\theta_i - \\mu_i)^2 -\n\t\t\\sigma_i^2}{\\sigma_i^3}\n\t\\end{split}\n\\end{equation}\nUsing a constant learning rate $\\alpha_i = \\alpha \\sigma_i^2$, the gradient\nupdates takes the following form\n\\begin{equation}\n\t\\begin{split}\n\t\t\\mu_i^{k+1} &= \\mu_i^k + \\alpha \\left[G(h) - b\\right] (\\theta_i - \\mu_i)\\\\\n\t\t\\sigma_i^{k+1} &= \\sigma_i^k + \\alpha \\left[G(h) - b\\right] \n\t\t\\frac{(\\theta_i -\\mu_i)^2}{\\sigma_i}\n\t\\end{split}\n\\end{equation}\nwhere $b$ can be computed as a moving average of the past returns. Intuitively,\nif $G(h) > b$ we adjust $\\xi$ so as to increase the probability of $\\theta$\nwhile if $G(h) < b$ we do the opposite. \n\n\\paragraph{Gaussian Parameter Distribution}\nA more elaborate approach is to assume a generic dependence among the controller parameters, namely $\\theta \\sim \\calN(\\mu, \\Sigma)$. However, if we directly used the covariance matrix $\\Sigma$ as an hyper-parameter, it would be computationally difficult to enforce that it remains well-defined, namely symmetric and semidefinite positive, during the gradient ascent iterations. A simpler approach is to parameterize the distribution using the Cholesky factor $\\Sigma$, the matrix $C$ such that $\\Sigma = C^T C$. This choice has two advantages: first, $C$ makes explicit the $n(n+1)/2$ independent parameters determining the covariance matrix $\\Sigma$; in addition, $C^T C$ is by construction a well-defined covariance matrix. Hence, the hyper-parameters are $\\xi =\\{\\mu, C\\}$. The likelihood score for this distribution does not have a simple expression, but it becomes extremely easy in the Natural version of \\gls{PGPE} which will be discussed in the next sections.\n\n\\paragraph{Symmetric Sampling and Gain Normalization} \nIn some settings, comparing the gain with a baseline can be misleading. In\ntheir original work, the authors propose a symmetric sampling technique similar\nto antithetic variates that further improves the convergence of the method.\nMore in detail, a more robust gradient estimate can be obtained by measuring\nthe difference in reward between two symmetric samples on either side of the\ncurrent mean. That is, we sample a random perturbation $\\epsilon \\sim\n\\mathcal{N}(0, \\Sigma)$, where $\\Sigma = \\text{diag}(\\sigma_1^2, \\ldots,\n\\sigma_{D_\\theta}^2)$, and we define $\\theta^+ = \\mu + \\epsilon$ and $\\theta^- =\n\\mu - \\epsilon$. Denoting by $G^+$ (resp. $G^-$) the gains obtained on the\ntrajectory associated to $\\theta^+$ (resp. $\\theta^-$), the objective function\ngradient can be approximated with\n\\begin{equation}\n\t\\begin{split}\n\t\t\\nabla_{\\mu_i} J(\\xi) &\\approx \\frac{\\epsilon_i (G^+ - G^-)}{2\n\t\t\\sigma_i^2}\\\\\n\t\t\\nabla_{\\sigma_i} J(\\xi) &\\approx \\frac{\\epsilon_i^2 -\n\t\\sigma_i^2}{\\sigma_i^3}\\left(\\frac{G^+ + G^-}{2} - b\\right)\n\t\\end{split}\n\\end{equation}\nHence, by choosing $\\alpha_i^k = 2 \\alpha \\sigma_i^2$, we have the following \nupdate rules\n\\begin{equation}\n\t\\begin{split}\n\t\t\\mu_i^{k+1} &= \\mu_i^k + \\alpha \\epsilon_i (G^+ - G^-)\\\\\n\t\t\\sigma_i^{k+1} &= \\sigma_i^k + \\alpha \\frac{\\epsilon_i^2 - \\sigma_i^2}\n\t\t{\\sigma_i}\\left(G^+ + G^- - 2b\\right)\n\t\\end{split}\n\\end{equation}\nIn addition, the authors propose to normalize the gains in order to make the\nupdates independent of the scale of the rewards. For instance, we could modify\nthe hyperparameters updates as follows\n\\begin{equation}\n\t\\begin{split}\n\t\t\\mu_i^{k+1} &= \\mu_i^k + \\alpha \\epsilon_i \\frac{(G^+ - G^-)}{2m - G^+\n\t- G^-}\\\\\n\t\t\\sigma_i^{k+1} &= \\sigma_i^k + \\alpha \\frac{\\epsilon_i^2 - \\sigma_i^2}\n\t{\\sigma_i}\\frac{\\left(G^+ + G^- - 2b\\right)}{m - b}\n\t\\end{split}\n\\end{equation}\nwhere $m$ might be the maximum gain the agent can receive, if known, or\nalternatively the maximum gain achieved so far. Symmetric sampling and gain\nnormalization can drastically improve the gradient estimate quality and \nconsequently the convergence time.  \n\n\\subsubsection{Infinite Horizon PGPE}\nWhile in the episodic PGPE the parameters $\\theta$ are sampled only at the beginning of each episode, in \\gls{IHPGPE} \\cite{sehnke2012parameter} the parameters and learning are carried out simultaneously, while interacting with the environment. Let $0 < \\varepsilon < 1$ the probability of updating the policy parameters, the parameters $\\theta_t$ can be sampled consecutively as follows\n\\begin{equation}\n\tp_\\xi(\\theta_{i,t+1}) = \\varepsilon \\mathcal{N}(\\mu_{i,t}, \\sigma_{i,t}^2) \n\t\t\t\t\t\t\t+ (1-\\varepsilon) \\delta_{\\theta_{i,t}}\n\\end{equation}\nIn practice, $\\varepsilon$ should be chosen so that the expected frequency of\nchanging a single parameter is coherent with the typical episode length in the\nepisodic framework. Alternatively, one could sample all the parameters at a\ncertain time step simultaneously\n\\begin{equation}\n\tp_\\xi(\\theta_{t+1}) = \\varepsilon \\mathcal{N}(\\mu_{t}, \\Sigma_t) \n\t\t\t\t\t\t\t+ (1-\\varepsilon) \\delta_{\\theta_{t}}\n\\end{equation}\nThis is equivalent to splitting the state-action space into artificial\nepisodes. However, updating parameters asynchronously changes the policy only\nslightly thus introducing less noise in the process. Again, parameters can be\nupdated at every time step by gradient ascent\n\\begin{equation}\n\t\\begin{split}\n\t\t\\mu_{i,t+1} &= \\mu_{i,t} + \\alpha \\left[G_t(h) - b\\right] (\\theta_{i,t}\n\t\t- \\mu_{i,t})\\\\\n\t\t\\sigma_{i,t+1} &= \\sigma_{i,t} + \\alpha \\left[G_t(h) - b\\right] \n\t\t\\frac{(\\theta_{i,t} -\\mu_{i,t})^2}{\\sigma_{i,t}}\n\t\\end{split}\n\\end{equation}\nSimilarly to the episodic case, we can improve the gradient estimate by\nsymmetric sampling and gain normalization. ", "meta": {"hexsha": "dfe6c71c1f0e8f87143d70e61162838600adfec8", "size": 21879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Chapters/4_2_Likelihood_Ratio_Methods.tex", "max_stars_repo_name": "AmineAboussalah/Thesis", "max_stars_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 80, "max_stars_repo_stars_event_min_datetime": "2016-06-13T15:20:29.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T23:47:13.000Z", "max_issues_repo_path": "Report/Chapters/4_2_Likelihood_Ratio_Methods.tex", "max_issues_repo_name": "pnecchi/Thesis", "max_issues_repo_head_hexsha": "1a3ae97023acff1ee5e2d197a446734117a6fb99", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/Chapters/4_2_Likelihood_Ratio_Methods.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": 65.9006024096, "max_line_length": 968, "alphanum_fraction": 0.7244389597, "num_tokens": 6692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391579526935, "lm_q2_score": 0.8652240895276224, "lm_q1q2_score": 0.7986357150379625}}
{"text": "\n\\subsection{Axiom of pairing}\n\nFor any pair of sets, \\(x\\) and \\(y\\) there is another set \\(z\\) which containing only \\(x\\) and \\(y\\).\n\n\\(\\forall x \\forall y \\exists z \\forall a[a\\in z \\leftrightarrow a=x \\lor a=y]\\)\n\n\\subsubsection{For each set, there exists a set containing only that set}\n\nTake the axiom, but replace all instance of \\(y\\) with \\(x\\).\n\n\\(\\forall x \\exists z \\forall a[a\\in z \\leftrightarrow a=x \\lor a=x]\\)\n\n\\(\\forall x \\exists z \\forall a[a\\in z \\leftrightarrow a=x]\\)\n\n\\subsubsection{For any finite number of sets, there is a set containing only those sets}\n\n\\subsubsection{For any finite number of sets, there is a set containing the intersection of those sets}\n\n", "meta": {"hexsha": "b9f94b5ae6d23308c35c7af0dd91c3c407999a36", "size": 687, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/03-02-pairing.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/03-02-pairing.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/03-02-pairing.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.35, "max_line_length": 103, "alphanum_fraction": 0.7016011645, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391664210672, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7986357079297753}}
{"text": "\\chapter*{Appendix D: Generalization of Derivative Needed for Minimization}\n\\label{annexC}\n\\addcontentsline{toc}{chapter}{Appendix D:  Generalization of Derivative Needed for Minimization}\n\nThe contribution of the wavelet coefficient $x$ to the noise and signal\ninformation in the general case is\n\\begin{eqnarray}\nh_n(x) & = & \\int_{0}^{\\mid x \\mid } p_n(u|x) (\\frac{\\partial h(x)}{\\partial \nx})_{x=u} du \\\\ \\nonumber \nh_s(x) & = & \\int_{0}^{\\mid x \\mid } p_s(u|x) (\\frac{\\partial h(x)}{\\partial \nx})_{x=u} du\n\\end{eqnarray}\n\nAssuming $h(x) = \\frac{1}{2}x^2$, we have\n\\begin{eqnarray}\nh_n(x) & = & \\int_{0}^{\\mid x \\mid } p_n(x-u) u du \\\\ \\nonumber \nh_s(x) & = & \\int_{0}^{\\mid x \\mid } p_s(x-u) u du\n\\end{eqnarray}\n\n\n\\begin{eqnarray}\n\\frac{ d h_{s}(x)}{dx} = \\int_0^x  \\frac{\\partial P_s(x-u)}{\\partial x})_{x=u} u du +\n         \\frac{1}{dx}  \\int_x^{x+dx} P_s(x-u) u  du\n\\end{eqnarray}\n\nAs $P_s(0) = 0$, the second term tends to zero.\n\nDenoting  $\\frac{\\partial P_s(x-u)}{\\partial x} = - \\frac{\\partial P_s(x-u)}{\\partial u}$, we have  \n\\begin{eqnarray}\n\\frac{ d h_{s}(x)}{dx} & = & - \\int_0^x \\frac{\\partial P_s(x-u)}{\\partial u} u du \\\\\n& = &  - ( [u P_s(x-u) ]_0^x - \\int_0^w P_s(x-u) du) \\\\\n& = & \\int_0^x P_s(x-u) du \\\\\n& = & \\int_0^x P_s(u) du\n\\end{eqnarray}\n\nand from $h_n = h - h_s$ we get\n\\begin{eqnarray}\n\\frac{ d h_{n}(x)}{dx} & = &  x -  \\int_0^x P_s(u) du\n\\end{eqnarray}\nand \n\\begin{eqnarray}\n\\frac{ d h_{s}(y-x)}{dx} = - \\int_0^{y-x} P_s(u) du\n\\end{eqnarray}\n\nIt is easy to verify that replacing $P_s(x) = \\mbox{erf}(x)$, \nand $P_n(x) = \\mbox{erfc}(x)$,\n(case of Gaussian noise) we find the same equation as in Appendix B.\n\n", "meta": {"hexsha": "958480974b75b720ab36364c7acaa7572d8226db", "size": 1640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/annex_deriv2.tex", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/doc/doc_mra/doc_mr2/annex_deriv2.tex", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/doc/doc_mra/doc_mr2/annex_deriv2.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": 33.4693877551, "max_line_length": 100, "alphanum_fraction": 0.6115853659, "num_tokens": 680, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8740772417253255, "lm_q1q2_score": 0.7986238636329442}}
{"text": "\\documentclass{tufte-handout}\n\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\n% set hyperlink attributes\n\\hypersetup{colorlinks}\n\n\\usepackage{amsmath}\n\n% set image attributes:\n\\usepackage{graphicx}\n\\graphicspath{ {images/} }\n\n% create environment for bottom paragraph:\n\\newenvironment{bottompar}{\\par\\vspace*{\\fill}}{\\clearpage}\n\n% ============================================================\n\n% define the title\n\\title{SOC 4930/5050: Week 07 Equations Quick \\\\Reference}\n\\author{Christopher Prener, Ph.D.}\n\\date{October 9\\textsuperscript{th}, 2017}\n% ============================================================\n\\begin{document}\n% ============================================================\n\\maketitle % generates the title\n% ============================================================\n\n\\vspace{5mm}\n\\section{One-sample T-test}\\marginnote{Degrees of freedom ($v$) is defined as $v=n-1$.}\n\\begin{equation}\n\\scalebox{2} {$ t=\\frac { \\bar { x } - \\mu }{ \\frac{s}{\\sqrt{n}} }  $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Independent T-test, Homogeneous Variance}\n\\begin{subequations}\n\\paragraph{Independent T-test}\\marginnote{Degrees of freedom ($v$) is defined as $v={n}_{a}+{n}_{b}-2$.}\n\\begin{equation}\n\\scalebox{2} {$ t=\\frac { { \\bar{X}  }_{ a }-{ \\bar{X}  }_{ b } }{ \\sqrt{\\frac{{ s }_{ p }^{ 2 }}{{ n }_{ a }}+\\frac{{ s }_{ p }^{ 2 }}{{ n }_{ b }}} } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Pooled Variance}\n\\begin{equation}\n\\scalebox{2} {$ { s }_{ p }^{ 2 }=\\frac{\\left({n}_{a}-1\\right){s}_{a}^{2}+\\left({n}_{b}-1\\right){s}_{b}^{2}}{{n}_{a}+{n}_{b}-2} $}\n\\end{equation}\n\\end{subequations}\n\n\\vspace{5mm}\n\\section{Independent T-test, Heterogeneous Variance}\n\\begin{subequations}\n\\paragraph{Independent T-test}\n\\begin{equation}\n\\scalebox{2} {$ t=\\frac { { \\bar{X}  }_{ a }-{ \\bar{X}  }_{ b } }{ \\sqrt{\\frac{{ s }_{ a }^{ 2 }}{{ n }_{ a }}+\\frac{{ s }_{ b }^{ 2 }}{{ n }_{ b }}} } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Welch's Corrected Degrees of Freedom ($v$)}\n\\begin{equation}\n\\scalebox{2} {$ v\\approx \\frac { \\left( \\frac { { s }_{ a }^{ 2 } }{ { n }_{ a } } +\\frac { { s }_{ b }^{ 2 } }{ { n }_{ b } }  \\right) ^{ 2 } }{ \\frac { { s }_{ a }^{ 4 } }{ \\left( { n }_{ a }^{2} \\right)\\left( { n }_{ a }-1 \\right) } +\\frac { { s }_{ b }^{ 4 } }{ \\left( { n }_{ b }^{2} \\right)\\left( { n }_{ b }-1 \\right) }  } $}\n\\end{equation}\n\\end{subequations}\n\n\\vspace{5mm}\n\\section{Dependent T-test}\n\\begin{equation}\n\\scalebox{2} {$ t=\\frac{\\bar{d}}{\\sqrt{\\frac{{s}_{d}^{2}}{n}}} $}\n\\end{equation}\n\n\\vspace{5mm}\n\\section{Cohen's $D$}\\marginnote{Note that groups $t$ and $c$ are defined for controlled experiments where $t=treatment$ and $c=control$. This can be applied to the above equations by defining $t=a$ and $c=b$.}\n\\begin{subequations}\n\\paragraph{General Equation}\n\\begin{equation}\n\\scalebox{2} {$ d=\\frac{{M}_{t}-{M}_{c}}{\\sqrt{\\frac{\\left({n}_{t}-1\\right){s}_{t}^{2}+\\left({n}_{c}-1\\right){s}_{c}^{2}}{{n}_{t}+{n}_{c}-2}}} $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Cohen's $D$ after T-test, ${n}_{a}={n}_{b}$}\n\\begin{equation}\n\\scalebox{2} {$ d=\\frac{2t}{\\sqrt{v}} $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Cohen's $D$ after T-test, ${n}_{a}\\neq{n}_{b}$}\n\\begin{equation}\n\\scalebox{2} {$ d=\\frac{t\\left({n}_{t}+{n}_{c}\\right)}{\\sqrt{v}\\left(\\sqrt{{n}_{t}+{n}_{c}} \\right)} $}\n\\end{equation}\n\\end{subequations}\n\n% ============================================================\n\\end{document}", "meta": {"hexsha": "0bcdebe8ed0a35330685fb614096135ba5a2e7e8", "size": 3392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-07-equations.tex", "max_stars_repo_name": "slu-soc5050/Equations", "max_stars_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week-07-equations.tex", "max_issues_repo_name": "slu-soc5050/Equations", "max_issues_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week-07-equations.tex", "max_forks_repo_name": "slu-soc5050/Equations", "max_forks_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.085106383, "max_line_length": 332, "alphanum_fraction": 0.5527712264, "num_tokens": 1223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7986238561402738}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Compute the following complex dot products in $\\C^n$:\n  \\begin{equation*}\n    (a)\n    \\begin{mymatrix}{c} 1 \\\\ i \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c} 1+i \\\\ 2 \\end{mymatrix},\n    \\quad\n    (b)\n    \\begin{mymatrix}{c} 2 \\\\ 1 \\\\ i \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c} i \\\\ 1 \\\\ -3 \\end{mymatrix},\n    \\quad\n    (c)\n    \\begin{mymatrix}{c} i \\\\ 1 \\\\ -3 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c} 2 \\\\ 1 \\\\ i \\end{mymatrix},\n    \\quad\n    (d)\n    \\begin{mymatrix}{c} i \\\\ i+1 \\\\ 1 \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{c} 1+2i \\\\ -2 \\\\ -i \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    (a) $1-i$, (b) $1+5i$, (c) $1-5i$, (d) $0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Compute the norm of each of the following vectors in $\\C^n$:\n  \\begin{equation*}\n    (a) \\begin{mymatrix}{c} 1 \\\\ i \\end{mymatrix},\\quad\n    (b) \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1+2i \\end{mymatrix},\\quad\n    (c) \\begin{mymatrix}{c} 1+i \\\\ 1-i \\\\ 3i \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    (a) $\\sqrt{2}$, (b) $\\sqrt{6}$, (c) $\\sqrt{13}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $\\vect{u},\\vect{v}\\in\\C^n$ and\n  $\\vect{u}\\dotprod\\vect{u} = 1$, $\\vect{v}\\dotprod\\vect{v} = 2$, and\n  $\\vect{u}\\dotprod\\vect{v} = 2i$. Then compute:\n  \\begin{enumerate}\n  \\item $(2\\vect{u}+\\vect{v})\\dotprod(\\vect{u}-\\vect{v})$.\n  \\item $(i\\vect{u}-\\vect{v})\\dotprod(\\vect{u}-2i\\vect{v})$.\n  \\end{enumerate}\n  \\begin{sol}\n    (a) $-6i$, (b) $5i$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Compute the adjoint of the following matrices.\n  \\begin{equation*}\n    (a)\n    \\begin{mymatrix}{cc}\n      i   \\\\\n      i-1 \\\\\n      2   \\\\\n    \\end{mymatrix},\n    \\quad\n    (b)\n    \\begin{mymatrix}{cc}\n      1 & i \\\\\n      -i & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    (c)\n    \\begin{mymatrix}{ccc}\n      2 & 1+i & -i \\\\\n      1-i & 3 & 2+2i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $\\vect{u}$ and $\\vect{v}$ are vectors in a complex inner\n  product space such that $\\iprod{\\vect{u},\\vect{u}} = 3$,\n  $\\iprod{\\vect{v},\\vect{v}} = 2$, and $\\iprod{\\vect{u},\\vect{v}} =\n  i+1$. Then compute:\n  \\begin{enumerate}\n  \\item $\\iprod{\\vect{u}+2\\vect{v},\\vect{u}-i\\vect{v}}$.\n  \\item $\\iprod{\\vect{u}-i\\vect{v},2\\vect{u}+\\vect{v}}$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  In $C[0,2\\pi]$, consider the functions $f(x) = \\sin x + i\\cos x$,\n  $g(x) = 1$, and $h(x) = x$. Compute the following:\n  \\begin{equation*}\n    (a)~~ \\iprod{f,g},\\quad\n    (b)~~ \\iprod{f,h},\\quad\n    (c)~~ \\iprod{f,f},\\quad\n    (d)~~ \\norm{f}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following vectors, if any, are orthogonal?\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\  i \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} 1 \\\\ -i \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{c} 0 \\\\  1 \\\\ -i \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{c} 0 \\\\  0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $\\vect{u}_1\\orth\\vect{u}_2$, $\\vect{u}_1\\orth\\vect{u}_4$, and\n    $\\vect{u}_2\\orth\\vect{u}_3$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose that $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ is an\n  orthogonal basis for a complex inner product space $V$, such that\n  $\\norm{\\vect{u}_1}=\\sqrt{2}$, $\\norm{\\vect{u}_2}=2$, and\n  $\\norm{\\vect{u}_3}=\\sqrt{3}$. Moreover, suppose that $\\vect{v}\\in V$ is a\n  vector such that $\\iprod{\\vect{u}_1,\\vect{v}} = 1$,\n  $\\iprod{\\vect{u}_2,\\vect{v}} = 3i$, and\n  $\\iprod{\\vect{u}_3,\\vect{v}} = 1-i$. Find the coordinates of\n  $\\vect{v}$ with respect to $B$.\n\\end{ex}\n\n\\begin{ex}\n  Consider $\\C^3$ with the complex dot product. Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 0 \\\\ i \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} 1 \\\\ 1+i \\\\ 3i+2  \\end{mymatrix}\n  \\end{equation*}\n  Use the Gram-Schmidt procedure to find an orthogonal basis for\n  $\\sspan\\set{\\vect{v}_1,\\vect{v}_2}$. Then find an orthonormal basis.\n  \\begin{sol}\n    Orthogonal: $\\mat{0,i,2}^T$, $\\mat{1,2,i}^T$. Orthonormal:\n    $\\frac{1}{\\sqrt{5}}\\mat{0,i,2}^T$, $\\frac{1}{\\sqrt{6}}\\mat{1,2,i}^T$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the subspace of $\\C^3$ spanned by the orthogonal vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{c} 2 \\\\ i \\\\ 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} i \\\\ 3 \\\\ i \\end{mymatrix}.\n  \\end{equation*}\n  Find the best approximation of\n  $\\vect{v}=\\begin{mymatrix}{c} -2i \\\\ 3 \\\\ 4i \\end{mymatrix}$ in this\n  subspace.\n\\end{ex}\n", "meta": {"hexsha": "8fd84a00b35fbb1ba0d94699a93d4b3499b11846", "size": 4555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Complex.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Complex.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Complex.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.7712418301, "max_line_length": 75, "alphanum_fraction": 0.5626783754, "num_tokens": 2002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.7986011750233061}}
{"text": "\n\\subsection{Outer product}\n\n\\subsubsection{The outer product is a bilinear map}\n\nThis is a bilinear map from two vectors from the same vector space to another vector space.\n\n\\(V\\times V \\rightarrow V\\)\n\n\\subsubsection{Calculating the outer product}\n\n\\(u\\otimes v = w\\)\n\n\\(w_{ij}=u_iv_j\\)\n\n\\subsubsection{The dimensions of the tensor outer product}\n\n\\(\\dim (V \\otimes W)= \\dim V \\times \\dim W \\)\n\n\\subsubsection{Outer product on the complex numbers}\n\n\\subsubsection{Relation between the dot product and outer product}\n\nThe dot product in the trace of the outer product.\n\n\n", "meta": {"hexsha": "aac8b4a04c44358ba0623bcbfc980fe9069bf039", "size": 572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/05-01-outerProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/05-01-outerProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/05-01-outerProduct.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.1851851852, "max_line_length": 91, "alphanum_fraction": 0.7465034965, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.7983575626911785}}
{"text": "%!TEX root = Calculus_I.tex\n\\chapter{Short-Cuts to Differentiation}\nThis chapter will cover simple rules that are used to take the \\textbf{\\textit{derivative}} for a variety of functions.\n\n\\section{Powers and Polynomials}\nThe \\textbf{\\textit{derivative}} of a constant multiple is given by:\n\\begin{equation}\n\\label{eq:ConstantMultDeriv}\n\\frac{d}{dx}\\left[c f(x)\\right] = c f^\\prime(x)\n\\end{equation}\n%\nIf $f(x)$ is \\textbf{\\textit{differentiable}} and $c$ is constant. This is a special case of the \\textbf{\\textit{Product Rule}}, which will be covered shortly. Proving this rule can be done using the definition of the \\textbf{\\textit{derivative}}:\n\\begin{equation}\n\\frac{d}{dx}\\left[c f(x)\\right] = \\lim_{h \\rightarrow 0} \\frac{c f(x+h) - cf(x)}{h} = \\lim_{h \\rightarrow 0} c\\frac{f(x+h) - f(x)}{h}\n\\end{equation}\n%\n\\begin{equation}\n\\lim_{h \\rightarrow 0} c\\frac{f(x+h) - f(x)}{h} = c f^\\prime(x)\n\\end{equation}\n\n\\vspace{0.1in}\nThe derivative of two functions, $f(x)$ and $g(x)$, added or subtracted together, provided both $f(x)$ and $g(x)$ are \\textbf{\\textit{differentiable}}, is given by:\n%\n\\begin{equation}\n\\label{eq:SumDeriv}\n\\frac{d}{dx}\\left[f(x) + g(x)\\right] = f^\\prime(x) + g^\\prime(x)\n\\end{equation}\n%\n\\begin{equation}\n\\label{eq:DiffDeriv}\n\\frac{d}{dx}\\left[f(x) - g(x)\\right] = f^\\prime(x) - g^\\prime(x)\n\\end{equation}\n%\nAgain, using the definition of the \\textbf{\\textit{derivative}}:\n\\begin{equation}\n\\frac{d}{dx}\\left[f(x) + g(x)\\right] = \\lim_{h \\rightarrow 0} \\frac{\\left[f(x+h) + g(x+h)\\right] - \\left[f(x) + g(x)\\right]}{h}\n\\end{equation}\n%\n\\begin{equation}\n\\label{eq:SumDiffLim}\n\\lim_{h \\rightarrow 0} \\left[\\frac{f(x+h) - f(x)}{h} + \\frac{g(x+h) - g(x)}{h}\\right]\n\\end{equation}\n%\nwhere the limits of each term in Equation (\\ref{eq:SumDiffLim}) approach $f^\\prime(x)$ and $g^\\prime(x)$.\n\n\\vspace{0.1in}\nFor equations containing powers of $x$, the \\textbf{\\textit{Power Rule}} can be used:\n\\begin{equation}\n\\label{eq:PowerRule}\n\\frac{d}{dx}\\left(x^n\\right) = nx^{n-1}\n\\end{equation}\nThis is valid provided that $n$ is constant and $n \\in \\mathbb{R}$. Combining the rules shown in Equations (\\ref{eq:ConstantMultDeriv}), (\\ref{eq:SumDeriv}), (\\ref{eq:DiffDeriv}), and (\\ref{eq:PowerRule}), the \\textbf{\\textit{derivative}} of \\textit{any \\textbf{polynomial}} can be taken.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Exponential Function}\nRecall that \\textbf{\\textit{exponential functions}} are given by:\n\\begin{equation}\nf(x) = a^x\n\\end{equation}\nThese are \\textbf{\\textit{monotonically increasing}} functions; thus, the \\textbf{\\textit{derivative}} must be strictly positive. Suppose we have a function, $f(x)$, given by:\n\\begin{equation}\nf(x) = 2^x\n\\end{equation}\nUsing the definition of the \\textbf{\\textit{derivative}}:\n\\begin{equation}\nf^\\prime(x) = \\lim_{h \\rightarrow 0} \\left(\\frac{2^{x+h} - 2^x}{h}\\right) = \\lim_{h \\rightarrow 0} \\left(\\frac{{2^x 2^h} - 2^x}{h}\\right)\n\\end{equation}\n%\n\\begin{equation}\n\\lim_{h \\rightarrow 0} \\left(\\frac{2^h - 1}{h}\\right)\\cdot 2^x\n\\end{equation}\n%\nUsing this representation, we can approach the \\textbf{\\textit{limit}} of the coefficient of $2^x$ by taking small values of $h$:\n%\n\\begin{table}[tb]\n\\begin{center}\n\\caption{Evaluations of coefficient $\\frac{2^h - 1}{h}$ for various values of $h$}\n\\begin{tabular}{l|c}\n\\hline\n$h$ & $\\frac{2^h - 1}{h}$\\\\\n\\hline\n-0.1 & 0.6697\\\\\n-0.01 & 0.6908\\\\\n-0.001 & 0.6929\\\\\n0.001 & 0.6934\\\\\n0.01 & 0.6956\\\\\n0.1 & 0.7177\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n%\nThis suggests that the \\textbf{\\textit{limit}} of $\\frac{2^h - 1}{h}$ as $h \\rightarrow 0$ is approximately 0.693. Thus:\n%\n\\begin{equation}\ng^\\prime(x) = \\frac{d}{dx} \\left(0.693\\cdot 2^x\\right)\n\\end{equation}\n%\nApplying Equation (\\ref{eq:ConstantMultDeriv}) to this expression means that only the \\textbf{\\textit{derivative}} of $2^x$ must be taken. This indicates that the \\textbf{\\textit{derivative}} of an \\textbf{\\textit{exponential function}} depends upon the function itself. In the general form:\n\\begin{equation}\nf(x) = a^x\n\\end{equation}\n\\begin{equation}\nf^\\prime(x) = \\lim_{h \\rightarrow 0} \\left(\\frac{a^{x+h} - a^x}{h}\\right) = \\lim_{h \\rightarrow 0}\\left(\\frac{a^h - 1}{h}\\right)\\cdot a^x\n\\end{equation}\n%\n\\begin{table}[b]\n\\begin{center}\n\\caption{Limit evaluations of coefficient $\\frac{a^h - 1}{h}$ for various values of $a$}\n\\label{tab:GenFormExponentialLims}\n\\begin{tabular}{l|c}\n\\hline\n$a$ & $\\lim_{h \\rightarrow 0}\\frac{a^h - 1}{h}$\\\\\n\\hline\n2 & 0.693\\\\\n3 & 1.099\\\\\n4 & 1.386\\\\\n5 & 1.609\\\\\n6 & 1.792\\\\\n7 & 1.946\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n%\nLooking at Table~\\ref{tab:GenFormExponentialLims} indicates that there is a number, $a$, between 2 and 3 such that $\\lim_{h \\rightarrow 0}\\frac{a^h - 1}{h}$ is 1. Thus:\n%\n\\begin{equation}\na^h - 1 \\approx h, \\hphantom{-} h \\ll 1\n\\end{equation}\n%\n\\begin{equation}\na^h \\approx 1+h\n\\end{equation}\n%\n\\begin{equation}\n\\label{eq:NaturalNumberDefinition}\na \\approx \\left(1+h\\right)^{\\frac{1}{h}}\n\\end{equation}\n%\nTaking the \\textbf{\\textit{limit}} of Equation~(\\ref{eq:NaturalNumberDefinition}) results in the values shown in Table~\\ref{tab:NaturalNumberDefinition}\n%\n\\begin{table}[b]\n\\begin{center}\n\\caption{Evaluations of coefficient $\\left(1+h\\right)^{\\frac{1}{h}}$ for various values of $h$}\n\\label{tab:NaturalNumberDefinition}\n\\begin{tabular}{l|c}\n\\hline\n$h$ & $\\left(1+h\\right)^{\\frac{1}{h}}$\\\\\n\\hline\n-0.001 & 2.7196422\\\\\n-0.0001 & 2.7184178\\\\\n-0.00001 & 2.7182954\\\\\n0.00001 & 2.7182682\\\\\n0.0001 & 2.7181459\\\\\n0.001 & 2.7169239\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n%\nWe observe that $a \\approx 2.718$. This is referred to as the \\textbf{\\textit{Natural Number}}, $e$. Using the \\textbf{\\textit{derivative}} relationships shown previously:\n\\begin{equation}\n\\frac{d}{dx}\\left(e^x\\right) = e^x\n\\end{equation}\n%\nTo adjust this expression for various values of $a$, we use a combination of the \\textbf{\\textit{limit}} and \\textbf{\\textit{derivative}} defintions previously presented and properties of logarithms:\n%\n\\begin{equation}\nf^\\prime(x) = \\lim_{h \\rightarrow 0} \\frac{a^{x+h} - a^x}{h} = \\left(\\lim_{h \\rightarrow 0} \\frac{a^h - 1}{h} \\right)a^x\n\\end{equation}\n%\n\\begin{equation}\na = e^{\\ln a}\n\\end{equation}\n%\n\\begin{equation}\n\\lim_{h \\rightarrow 0} \\frac{\\left(e^{\\ln a}\\right)^h - 1}{h} =  \\lim_{h \\rightarrow 0} \\frac{e^{\\left({\\ln a}\\right)h} - 1}{h}\n\\end{equation}\n%\nFrom the definition of the \\textbf{\\textit{Natural Number}}, $e$:\n%\n\\begin{equation}\n\\lim_{h \\rightarrow 0} \\frac{e^h - 1}{h} = 1\n\\end{equation}\n%\nSubstituting $t = (\\ln a) \\cdot h$:\n%\n\\begin{equation}\n\\lim_{h \\rightarrow 0}\\frac{e^{\\left(\\ln a\\right)h} - 1}{h} = \\lim_{t \\rightarrow 0} \\frac{e^t - 1}{t / \\ln a} = \\lim_{t \\rightarrow 0}\\left(\\ln a \\cdot \\frac{e^t - 1}{t}\\right)\n\\end{equation}\n%\n\\begin{equation}\n= \\ln a \\left(\\lim_{t \\rightarrow 0} \\frac{e^t - 1}{t}\\right) = (\\ln a) \\cdot 1 = \\ln a\n\\end{equation}\n%\nThus:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(a^x\\right) = (\\ln a)a^x\n\\end{equation}\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Product and Quotient Rules}\nRecall the Greek symbol $\\Delta$ refers to the change in a quantity. For a function $f(x)$, the change in the function can be written as:\n%\n\\begin{equation}\n\\Delta f = f(x+h) - f(x)\n\\end{equation}\n%\nfor small values of $h$. Using this notation, we can arrive at the definition of the \\textbf{\\textit{derivative}} as:\n%\n\\begin{equation}\nf^\\prime(x) = \\lim_{h \\rightarrow 0} \\frac{\\Delta f}{h}\n\\end{equation}\n%\nSuppose we know the \\textbf{\\textit{derivatives}} of two functions, $f(x)$ and $g(x)$, but we want to calculate the \\textbf{\\textit{derivative}} of their product, $f(x)g(x)$. A proof of this is included in the text these notes are based on (see Mechanical-Engineering-Curriculum/Calculus_I/README.md), but the \\textbf{\\textit{Product Rule}} can be used to determine this \\textbf{\\textit{derivative}}. The proof uses the definition of the \\textbf{\\textit{limit}}, but the \\textbf{\\textit{Product Rule}} is given as:\n%\n\\begin{equation}\n(fg)^\\prime = f^\\prime g + fg^\\prime\n\\end{equation}\n%\nprovided that $u = f(x)$ and $v = g(x)$ are \\textbf{\\textit{differentiable}}. Using \\textbf{\\textit{Leibniz's Notation}}:\n%\n\\begin{equation}\n\\frac{d(uv)}{dx} = \\frac{d}{dx}(uv)= \\frac{du}{dx} \\cdot v + u \\cdot \\frac{dv}{dx}\n\\end{equation}\n%\nSimilarly, the \\textbf{\\textit{Quotient Rule}} is the inverse of the \\textbf{\\textit{Product Rule}}. If a function $Q(x) = \\frac{f(x)}{g(x)}$ exists, and $u = f(x)$ and $v =g(x)$ are \\textbf{\\textit{differentiable}} then the \\textbf{\\textit{Quotient Rule}} is given as:\n%\n\\begin{equation}\n\\left(\\frac{f}{g}\\right)^\\prime = \\frac{f^\\prime g - f g^\\prime}{g^2}\n\\end{equation}\n%\nRepresenting this in \\textbf{\\textit{Leibniz's Notation}}:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\frac{u}{v}\\right) = \\frac{\\frac{du}{dx} \\cdot v - u \\frac{dv}{dx}}{v^2}\n\\end{equation}\n%\nNote that some expressions are likely to be easier handled by one rule over another, but equations can also be re-written such that multiplicative operations appear as division, such as:\n%\n\\begin{equation}\n\\frac{1}{x} = x^{-1}\n\\end{equation}\n%\nHere, the \\textbf{\\textit{derivative}} of the right-hand side can be easily computed using the \\textbf{\\textit{Quotient Rule}}, but the left-hand side is in the form of the \\textbf{\\textit{Power Rule}}, but both expressions are equivalent.\n%\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Chain Rule}\nThe \\textbf{\\textit{Chain Rule}} is used to take the \\textbf{\\textit{derivative}} of \\textbf{\\textit{composite functions}}. Suppose $f(g(x))$ is a \\textbf{\\textit{composite function}}. Then, substituting $z = g(x)$ yields:\n%\n\\begin{equation}\ny = f(z)\n\\end{equation}\n%\nBecause $z$ is a function of $x$, a small change in $x$, $\\Delta x$ will result in a small change in $z$, $\\Delta z$. In turn, $\\Delta z$ results in a small change in the dependent variable, $y$, because $y = f(z)$. If $\\Delta x$ and $\\Delta z$ are not identically zero, then:\n%\n\\begin{equation}\n\\frac{\\Delta y}{\\Delta x} = \\frac{\\Delta y}{\\Delta z} \\cdot \\frac{\\Delta z}{\\Delta x}\n\\end{equation}\n%\nBecause $\\frac{dy}{dx} = \\lim_{\\Delta x \\rightarrow 0} \\frac{\\Delta y}{\\Delta x}$, as these three differentials get closer to zero the \\textbf{\\textit{Chain Rule}} can be defined as:\n%\n\\begin{equation}\n\\frac{dy}{dx} = \\frac{dy}{dz} \\cdot \\frac{dz}{dx}\n\\end{equation}\n%\nFurthermore, because $\\frac{dy}{dz} = f^\\prime(z)$ and $\\frac{dz}{dx} = g^\\prime(x)$:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(f\\left(g\\left(x\\right)\\right)\\right) = f^\\prime\\left(z\\right) \\cdot g^\\prime(x)\n\\end{equation}\n%\nBack-substituting $z = g(x)$ yields:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(f\\left(g\\left(x\\right)\\right)\\right) = f^\\prime \\left(\\left(g\\left(x\\right)\\right)\\right) \\cdot g^\\prime(x)\n\\end{equation}\n%\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Trigonometric Functions}\nThis section is concerned with the \\textbf{\\textit{derivatives}} of the $sine$ and $cosine$ functions. Because these functions are periodic, their \\textbf{\\textit{derivatives}} must also be periodic. This can be done by looking at the graph of the functions and taking the \\textbf{\\textit{limit}} at multiple points for small changes from the point, $h$. Note that the relationships between the\\textit{sine} and \\textit{cosine} functions and the Unit Circle require $x$ to be in \\textbf{\\textit{radians}}.\n\n\\vspace{0.1in}\nTaking the limit at multple points along the $sine$ function's domain of $[0, 2\\pi]$ results in the following relationship:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\sin(x)\\right) = \\cos(x)\n\\end{equation}\n%\nFollowing a similar process for the $cosine$ function:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\cos(x)\\right) = -\\sin(x)\n\\end{equation}\n%\nThe \\textbf{\\textit{derivative}} of \\textit{cosine} is $-\\sin$ because of the phase shift between the two functions. Recall that:\n%\n\\begin{equation}\n\\cos(x) = \\sin\\left(x + \\frac{\\pi}{2}\\right)\n\\end{equation}\n%\nAlso note that the \\textbf{\\textit{Chain Rule}} must be used to differentiate the trigonometric functions because they are \\textbf{\\textit{composite functions}}. For the \\textit{tangent} function, which is defined as:\n%\n\\begin{equation}\n\\tan(x) = \\frac{\\sin(x)}{\\cos(x)}\n\\end{equation}\n%\nthe \\textbf{\\textit{Quotient Rule}} can be easily used. It results in the following:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\tan(x)\\right) = \\frac{d}{dx}\\left(\\frac{\\sin(x)}{\\cos(x)}\\right)\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\tan(x)\\right) = \\frac{\\left(\\sin(x)\\right)^\\prime \\cdot \\left(\\cos(x)\\right) - \\left(\\sin(x)\\right) \\cdot \\left(\\cos(x)\\right)^\\prime}{\\cos^2(x)}\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\tan(x)\\right) = \\frac{\\sin^2(x) + \\cos^2(x)}{\\cos^2(x)} = \\frac{1}{\\cos^2(x)}\n\\end{equation}\n%\nAgain, these relationships require $x$ to be in \\textbf{\\textit{radians}}.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{The Chain Rule and Inverse Functions}\nWe will now apply the \\textbf{\\textit{Chain Rule}} to calculate \\textbf{\\textit{derivatives}} of \\textbf{\\textit{logarithmic functions}}, \\textbf{\\textit{exponential functions}}, and the \\textbf{\\textit{inverse trigonometric functions}}. A general rule for the \\textbf{\\textit{derivative}} of any \\textbf{\\textit{inverse function}} will also be shown.\n\n\\vspace{0.1in}\nRecall that, using the properties of \\textbf{\\textit{logarithms}}, we can write:\n%\n\\begin{equation}\ne^{\\ln x} = x\n\\end{equation}\n%\nTo arrive at the \\textbf{\\textit{derivative}} of $\\ln x$, we will use the equation $e^{\\ln x} = x$:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(e^{\\ln x}\\right) = \\frac{d}{dx}\\left(x\\right)\n\\end{equation}\n%\n\\begin{equation}\ne^{\\ln x} \\cdot \\frac{d}{dx}\\left(\\ln x\\right) = 1\n\\end{equation}\n%\nThus:\n%\n\\begin{equation}\n\\frac{d}{dx} \\left(\\ln x \\right) = \\frac{1}{e^{\\ln x}} = \\frac{1}{x}\n\\end{equation}\n%\n\nFor \\textbf{\\textit{derivatives}} of the \\textbf{\\textit{inverse trigonometric functions}}, $\\arcsin(x)$, $\\arccos(x)$, and $\\arctan(x)$, we can utilize several trigonometric identities. For the \\textbf{\\textit{derivative}} of $\\arctan(x)$, note that $\\tan(\\arctan(x)) = x$. Differentiation via the \\textbf{\\textit{Chain Rule}} yields:\n%\n\\begin{equation}\n\\frac{1}{\\cos^2(\\arctan(x))} \\cdot \\frac{d}{dx}\\left(\\arctan(x)\\right) = 1\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\arctan(x)\\right) = \\cos^2(\\arctan(x))\n\\end{equation}\n%\nThe trigonometric identity $1 + \\tan^2(\\theta) = \\frac{1}{\\cos^2(\\theta)}$ can be used here, replacing $\\theta$ with $\\arctan(x)$; thus:\n%\n\\begin{equation}\n\\cos^2(\\arctan(x)) = \\frac{1}{1 + \\tan^2(\\arctan(x))} = \\frac{1}{1 + x^2}\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\arctan(x)\\right) = \\cos^2(\\arctan(x)) = \\frac{1}{1 + x^2}\n\\end{equation}\n%\nFollowing a similar process for $\\arcsin(x)$ and $\\arccos(x)$:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\arcsin(x)\\right) = \\frac{1}{\\sqrt{1-x^2}}\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\arccos(x)\\right) = -\\frac{1}{\\sqrt{1-x^2}}\n\\end{equation}\n%\nFor general \\textbf{\\textit{inverse functions}}, if a function, $f(x)$, has a \\textbf{\\textit{differentiable inverse}}, $f^{-1}$, its \\textbf{\\textit{derivative}}, $f\\left(f^{-1}(x)\\right) = x$ by the \\textbf{\\textit{Chain Rule}}:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(f\\left(f^{-1}\\left(x\\right)\\right)\\right) = 1\n\\end{equation}\n%\n\\begin{equation}\nf^\\prime\\left(f^{-1}\\left(x\\right)\\right) \\cdot \\frac{d}{dx}\\left(f^{-1}\\left(x\\right)\\right) = 1\n\\end{equation}\n%\nTherefore:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(f^{-1}\\left(x\\right)\\right) = \\frac{1}{f^\\prime\\left(f^{-1}\\left(x\\right)\\right)}\n\\end{equation}\n%\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Implicit Functions}\nSo far, the functions presented have been considered \\textbf{\\textit{explicit functions}} of $x$, functions of the form $y = f(x)$. This section addresses \\textbf{\\textit{implicit functions}}, where one $x$ value corresponds to multiple $y$ values. An example of an \\textbf{\\textit{implicit function}} is the equation of a circle:\n%\n\\begin{equation}\n\\label{eq:circle}\nx^2 + y^2 = r^2\n\\end{equation}\n%\nHere, $y$ is a function of $x$ on both the top and bottom halves of the circle, buy when the circle is considered as a whole, as in Equation~(\\ref{eq:circle}), where the function does not have a tangent lineat each point, but the equation is still \\textbf{\\textit{differentiable}} with respect to $x$:\n%\n\\begin{equation}\n\\label{eq:circle_derivative}\n\\frac{d}{dx}\\left(x^2\\right) + \\frac{d}{dx}\\left(y^2\\right) = \\frac{d}{dx}\\left(r^2\\right)\n\\end{equation}\n%\nBecause $r$ is a constant of the circle, \\textbf{\\textit{differentiation}} results in the right-hand side of Equation~(\\ref{eq:circle_derivative}) goes to zero. If $y$ is treated as a function of $x$, and the \\textbf{\\textit{Chain Rule}} is used:\n%\n\\begin{equation}\n2x + 2y\\frac{dy}{dx} = 0\n\\end{equation}\n%\nSolving this for the $\\frac{dy}{dx}$ yields:\n%\n\\begin{equation}\n\\frac{dy}{dx} = -\\frac{x}{y}\n\\end{equation}\n%\nThis relationship is valid, provided $y \\neq 0$. This is expected because the line tangent to the circle at this point is vertical, so the \\textbf{\\textit{slope}} is infinite.\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Hyperbolic Functions}\nThe \\textbf{\\textit{Hyperbolic Functions}} are combinations of $e^x$ and $e^{-x}$. \\textit{Hyperbolic Sine}, abbreviated $\\sinh(x)$, and \\textit{Hyperbolic Cosine}, abbreviated $\\cosh(x)$, are given by:\n%\n\\begin{equation}\n\\label{eq:sinh}\n\\sinh(x) = \\frac{e^x - e^{-x}}{2}\n\\end{equation}\n%\n\\begin{equation}\n\\label{eq:cosh}\n\\cosh(x) = \\frac{e^x + e^{-x}}{2}\n\\end{equation}\n%\nObserving properties of these functions graphically, and recalling that $\\frac{d}{dx}\\left(e^x\\right) = e^x$, the following results hold:\n\\begin{table}[H]\n\\begin{center}\n\\caption{Properties of $\\sinh(x)$ and $\\cosh(x)$}\n\\begin{tabular}{c|c}\n$\\cosh(0) = 1$ & $\\sinh(0) = 0$\\\\\n$\\cosh(-x) = \\cosh(x)$ & $\\sinh(-x) = -\\sinh(x)$\\\\\n$\\frac{d}{dx}\\left(\\cosh(x)\\right) = \\sinh(x)$ & $\\frac{d}{dx}\\left(\\sinh(x)\\right) = \\cosh(x)$\n\\end{tabular}\n\\end{center}\n\\end{table}\n%\nFurthermore, the it can be shown that the following result is true:\n%\n\\begin{equation}\n\\cosh^2(x) - \\sinh^2(x) = 1\n\\end{equation}\n%\nThe \\textit{Hyperbolic Tangent} function can also be defined, and is given by:\n%\n\\begin{equation}\n\\tanh(x) = \\frac{\\sinh(x)}{\\cosh(x)} = \\frac{e^x - e^{-x}}{e^x + e^{-x}}\n\\end{equation}\n%\nIt's derivative is given by:\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\tanh(x)\\right) = \\frac{d}{dx}\\left(\\frac{\\sinh(x)}{\\cosh(x)}\\right) = \\frac{\\left(\\cosh(x)\\right)^2 - \\left(\\sinh(x)\\right)^2}{\\left(\\cosh(x)\\right)^2}\n\\end{equation}\n%\n\\begin{equation}\n\\frac{d}{dx}\\left(\\tanh(x)\\right) = \\frac{1}{\\cosh^2(x)}\n\\end{equation}\n%\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Linear Approximation and the Derivative}\nWhen zooming into the graph of a \\textbf{\\textit{differentiable}} function, if the change between numbers is small enough $(\\Delta x \\rightarrow 0)$, the graph will look more and more like a line. This idea of \\textbf{\\textit{local linearity}} is commonly used to approximate the \\textbf{\\textit{slope}} or \\textbf{\\textit{derivative}} of a function $f(x)$ at a specific point, $x = a$ and function values near that point, $y = f(a+h)$. The \\textbf{\\textit{Tangent Line Approximation}} is given by:\n%\n\\begin{equation}\nf(x) \\approx f(a) + f^\\prime(a)(x - a)\n\\end{equation}\n%\nprovided that $f(x)$ is \\textbf{\\textit{differentiable}} at $x = a$. The resulting error in the approximation is given by:\n%\n\\begin{equation}\nE(x) = f(x) - f(a) - f^\\prime(a)(x-a)\n\\end{equation}\n%\nMore information about this error approximation will be discussed in the Calculus II course.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Theorems about Differentiable Functions}\nThe \\textbf{\\textit{Mean Value Theorem}} states that if $f(x)$ is \\textbf{\\textit{continuous}} on $[a, b]$, and is \\textbf{\\textit{differentiable}} on $(a, b)$, then a number $c$ exists such that:\n%\n\\begin{equation}\nf^\\prime(c) = \\frac{f(b) - f(a)}{b -a}\n\\end{equation}\n%\nwhich is the slope of the secant line between points $x=a$, and $x=b$. This theorem does not indicate how to find $c$, though.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{Increasing Function Theorem}} states that if a function $f(x)$ is \\textbf{\\textit{continuous}} on $[a, b]$, and is \\textbf{\\textit{differentiable}} on $(a, b)$, then:\n%\n\\begin{enumerate}\n\\item If $f^\\prime(x) > 0 \\hphantom{-} \\forall x \\in (a, b)$, then $f$ is \\textbf{\\textit{increasing}} on $[a, b]$.\\\\\n\\vspace{-0.25in}\n\\item If $f^\\prime(x) \\geq 0\\hphantom{-}  \\forall x \\in (a, b)$, then $f$ is \\textbf{\\textit{non-decreasing}} on $[a,b]$.\n\\end{enumerate}\n%\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{Constant Function Theorem}} states that if a function $f(x)$ is \\textbf{\\textit{continuous}} on $[a, b]$, and is \\textbf{\\textit{differentiable}} on $(a, b)$, then if $f^\\prime(x) = 0 \\hphantom{-} \\forall x \\in [a, b]$, then $f$ is constant on $x \\in [a, b]$.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{Racetrack Principle}} states that for two functions, $g(x)$, and $h(x)$, that are \\textbf{\\textit{continuous}} on $[a, b]$, and is \\textbf{\\textit{differentiable}} on $(a, b)$, and that $g^\\prime(x) \\leq h^\\prime(x) \\hphantom{-} \\forall x \\in (a, b)$:\n%\n\\begin{enumerate}\n\\item If $g(a) = h(a)$, then $g(x) \\leq h(x) \\hphantom{-} \\forall x \\in [a, b]$.\\\\\n\\vspace{-0.25in}\n\\item If $g(b) = h(b)$, then $g(x) \\geq h(x) \\hphantom{-} \\forall x \\in [a,b]$.\n\\end{enumerate}\n%\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}", "meta": {"hexsha": "72ca8c86414e9c8985ad45c0cc9a7ca3075383bc", "size": 21821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus I/Notes/chapter3.tex", "max_stars_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_stars_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-06T01:05:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T01:05:34.000Z", "max_issues_repo_path": "Calculus I/Notes/chapter3.tex", "max_issues_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_issues_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus I/Notes/chapter3.tex", "max_forks_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_forks_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5530035336, "max_line_length": 514, "alphanum_fraction": 0.6780624169, "num_tokens": 7822, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.9046505376715775, "lm_q1q2_score": 0.7982888438444385}}
{"text": "\\chapter{Approximations}\n\n\\section{VERTEX-COVER}\n\nCreate a copy of the edge list.  Choose an arbitrary edge from this\ncopy, and add both vertices on this edge to the set which will become\nthe vertex cover.  Then remove all edges in our edge list copy which\nare incident to either vertex on the chosen edge.  Repeat this process\nuntil our edge list copy is empty.\n\nExercise for the reader: prove that this is a 2-approximation.\n\n\\section{Bin Packing}\n\nWe describe the ``First-Fit'' approximation.  Given an object to pack\nand a list of open bins, add the object to the first bin into which it\nwill fit.  If it fits into no bins, open a new bin and insert the object.\n\nIt should be easy to see that no two bins will be less than half full,\notherwise the object(s) in the second bin would have been added to the\nfirst.\n\nThe worst case for this approximation is that every bin will be about\nhalf full.  In which case it is no worse than twice the optimal, so\nthis is a 2-approximation.\n", "meta": {"hexsha": "d4b71563beb94a5cc47ce4687729050bab97081c", "size": 982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "approximation.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": "approximation.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": "approximation.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.7692307692, "max_line_length": 73, "alphanum_fraction": 0.7708757637, "num_tokens": 237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505453836383, "lm_q2_score": 0.8824278540866548, "lm_q1q2_score": 0.7982888394612059}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nProve that the context-free grammar $ G = (\\{S\\},\\{a,b,c\\},S,\\{S\\rightarrow SS, S\\rightarrow \\lambda, S\\rightarrow aSb, S\\rightarrow bSa, S\\rightarrow aSc, S\\rightarrow cSa\\}) $\ngenerates the language $ L = \\{x \\in \\{a,b,c\\}^* | n_a(x) = n_b(x) + n_c(x) \\}$.\n\n\\subsection*{Solution}\n\nProof is given in two steps. First we prove $L(G) \\subseteq L$. Second, by proving $L \\subseteq L(G)$ we convert inclusion to equality.\n\n\\begin{enumerate}\n\n\t\\item\n\tIt is claimed that for any word $w \\in L(G)$, $n_a = n_b + n_c$.\n\tIt is clear that using the first two productions will not hinder the condition for they do not generate terminal symbols.\n\tHowever, using any of the four latter productions would increment $n_a$ while incrementing either $n_b$ or $n_c$.\n\tThus, informally, the statement $w \\in L$ holds true.\n\tA more formal solution can be given by induction on length of $w$.\n\n\t\\begin{itemize}[label={}]\n\n\t\t\\item\n\t\tClearly, if $|w| = 0$, $w = \\lambda$, $n_a = n_b + n_c = 0$.\n\t\tIf $|w| = 2$, either $S\\rightarrow aSx$ or $S\\rightarrow xSa$ where $x \\in \\{b,c\\}$ and then $S\\rightarrow \\lambda$.\n\t\tIn which case, $w \\in L$.\n\t\tNote that we cannot have a word generated by grammar $G$ which is of odd length.\n\t\tNor can we have a word $w$ with odd length whose $n_a(w) = n_b(w) + n_c(w)$.\n\n\t\t\\item\n\t\tWe take the induction hypothesis as, for $w \\in L(G)$ such that $|w| = p$, $w \\in L$.\n\t\tIt is shown for any $w^\\prime \\in L(G)$ such that $|w^\\prime| = p + 2$, $w^\\prime \\in L$.\n\t\tStarting from $S$, $w^\\prime$ is generated first by generating $w$ such that $|w| = p$, then applying one of the four productions in $G$ that generate terminal symbols and finally by using $S\\rightarrow \\lambda$.\n\t\tAs discussed previously, applying either one of the four productions would increment $n_a$ by one.\n\t\tAs there is no production that increment $n_b$ and $n_c$ by one at the same time, the argument $n_a = n_b + n_c$ still holds true and therefore $w \\in L$.\n\n\t\\end{itemize}\n\n\tThus $L(G) \\subseteq L$.\n\n\t\\item\n\tNow we prove $L \\subseteq L(G)$, that is, for any $w \\in L$, $w$ can be generated by S.\n\tIt is claimed that grammar $G$ is indifferent to position and order of the symbols of $w$ as long as they follow $n_a(w) = n_b(w) + n_c(w)$.\n\tProof is given again by induction on length of $w$.\n\n\t\\begin{itemize}[label={}]\n\n\t\t\\item\n\t\tClearly if $|w| = 0$, $w = \\lambda \\in L$ and $S\\xRightarrow[G]{} \\lambda = w$, thus $w \\in L(G)$.\n\t\tIf $|w| = 2$, $w \\in L$ either begins with an $a$ or ends with an $a$.\n\t\tIn the first case, $S\\xRightarrow[G]{} aSx \\xRightarrow[G]{} ax$ and in the second case, $S\\xRightarrow[G]{} xSa \\xRightarrow[G]{} xa$, where $x$ is either $b$ or $c$.\n\t\tBoth cases prove $w \\in L(G)$.\n\n\t\t\\item\n\t\tWe take the induction hypothesis that $S\\xRightarrow[G]{*}w$ for $|w| = k$.\n\t\tLet $w = uv$ such that $u,v \\in A^*$.\n\t\tBased on hypothesis, $S \\xRightarrow[G]{*} uSv \\xRightarrow[G]{} uv = w$.\n\t\tFor any $|w^\\prime| = k + 2$, $S \\xRightarrow[G]{*} uSv$.\n\t\tThen either $uSv \\xRightarrow[G]{} uaSxv \\xRightarrow[G]{} uaxv = w^\\prime$ or $uSv \\xRightarrow[G]{} uxSav \\xRightarrow uxav = w^\\prime$ where $x$ is $b$ or $c$.\n\t\tTherefore $w^\\prime \\in L(G)$.\n\n\t\\end{itemize}\n\n\tThus $L \\subseteq L(G)$.\n\n\\end{enumerate}\n\nBased on the equality, grammar $G$ can be said to generate language $L$ as defined.\n", "meta": {"hexsha": "3561a29b505a53462c11d8e59a91bd144d18bd6a", "size": 3682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/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-cs622-2015f/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-cs622-2015f/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": 49.7567567568, "max_line_length": 214, "alphanum_fraction": 0.6382400869, "num_tokens": 1217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.9046505280315008, "lm_q1q2_score": 0.7982888297434814}}
{"text": "    \\subsection{Catalan Number}\n    \tBinary trees with $n+1$ vertices.\n      \\begin{equation*}\n        C_{n+1} = \\sum_{i=0}^nC_iC_{n-i}\n      \\end{equation*}\n      %Una fórmula cerrada para los números de Catalán es:\n      \\begin{equation*}\n        C_n = \\frac{1}{n+1}\\binom{2n}{n} = \\binom{2n}{n} - \\binom{2n}{n+1}\n      \\end{equation*}\n    \\subsection{Stirling Numbers($1^{st}$ kind)} Arrangements of an $n$ element set into $k$ cycles.\n      \\begin{equation*}\n        \\stirlingfirst{n}{k} = (n-1)\\stirlingfirst{n-1}{k} + \\stirlingfirst{n-1}{k-1}\n      \\end{equation*}\n\n    \\subsection{Stirling Numbers($2^{nd}$kind)} \\# of ways of dividing $n$ distinct element into $k$ non-empty sets.\n      \\begin{equation*}\n        \\stirlingsecond{n}{k} = k\\stirlingsecond{n-1}{k} + \\stirlingsecond{n-1}{k-1}\n      \\end{equation*}\n\n      Además:\n      \\begin{equation*}\n        \\stirlingsecond{n}{k} = \\frac{1}{k!}\\sum_{j=0}^k (-1)^{k-j} \\binom{k}{j} j^n\n      \\end{equation*}\n\n      \\subsection{Bell Numbers} Count the number of ways to divide $n$ elements into subsets.\n      \\begin{equation*}\n        \\mathcal{B}_{n+1} = \\sum_{k=0}^n \\binom{n}{k} \\mathcal{B}_k\n      \\end{equation*}\n\n      \\\n\n      \\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}\n        \\hline\n        x&0&1&2&3&4&5&6&7&8&9&10 \\\\ \\hline %&9&10&11&12\n        $\\mathcal{B}_x$&1&1&2&5&15&52&203&877&4.140&21.147&115.975 \\\\ \\hline %&678.570&4.213.597\n      \\end{tabular}\n\n      \\subsection{Derangement} Permutation that leaves no element in the original location.\n\n      \\begin{equation*}\n        !n = (n - 1)( !(n - 1) + !(n - 2) ); !1 = 0, !2 = 1\n      \\end{equation*}\n\n      \\begin{equation*}\n        !n = n! \\sum_{k = 0}^n \\frac{(-1)^k}{k!}\n      \\end{equation*}\n\n    \\subsection{Números armónicos}\n\n    \\begin{equation*}\n     H_n = \\sum_{k = 1}^n \\frac{1}{k}\n    \\end{equation*}\n\n    \\begin{equation*}\n     \\frac{1}{2n+1} < H_n - \\ln n - \\gamma < \\frac{1}{2n}\n    \\end{equation*}\n\n    \\begin{equation*}\n     \\gamma = 0.57721 56649 01532 86060 65120 90082 40243 10421 59335 \\ldots\n    \\end{equation*}\n\n    \\subsection{Fibonacci Number} $f_0 = 0$, $f_1 = 1$:\n\n    \\begin{equation*}\n     f_n = \\frac{1}{\\sqrt{5}}(\\frac{1 + \\sqrt{5}}{2})^n - \\frac{1}{\\sqrt{5}}(\\frac{1 - \\sqrt{5}}{2})^n\n    \\end{equation*}\n\n    \\begin{equation*}\n     f_{n+1}^2 + f_n^2 = f_{2n + 1}, \n     f_{n+2}^2 - f_n^2 = f_{2n + 2}\n    \\end{equation*}\n\n    \\begin{equation*}\n     f_n = \\sum_{j = 0}^{\\lfloor \\frac{n}{2} \\rfloor} \\binom{n-j}{j}\n    \\end{equation*}\n\n    \\subsection{Sums of Combinations}\n\n    \\begin{equation*}\n     \\sum_{i = n}^m \\binom{i}{n} = \\binom{m + 1}{n + 1}\n    \\end{equation*}\n\n    \\begin{equation*}\n     \\sum_{i = 0}^k \\binom{n}{i} \\binom{m}{k - i} = \\binom{n + m}{k}\n    \\end{equation*}\n\n\n    \\subsection{Generating functions}\n      \\ \n\n      \\begin{tabular}{|c|c|}\n        \\hline\n        $(1,1,1,1,1,1,\\ldots)$ & $\\frac{1}{1-z}$ \\\\ \\hline\n        $(1,-1,1,-1,1,-1,\\ldots)$ & $\\frac{1}{1+z}$ \\\\ \\hline\n        $(1,0,1,0,1,0,\\ldots)$ & $\\frac{1}{1-z^2}$ \\\\ \\hline\n        $(1,0,\\ldots,0,1,0,1,0,\\ldots,0,1,0,\\ldots)$ & $\\frac{1}{1-z^2}$ \\\\ \\hline\n        $(1,2,3,4,5,6,\\ldots)$ & $\\frac{1}{(1-z)^2}$ \\\\ \\hline\n        $(1,\\binom{m+1}{m},\\binom{m+2}{m},\\binom{m+3}{m},\\ldots)$ & $\\frac{1}{(1-z)^{m+1}}$ \\\\ \\hline\n        $(1,c,\\binom{c+1}{2},\\binom{c+2}{3},\\ldots)$ & $\\frac{1}{(1-z)^c}$ \\\\ \\hline\n        $(1,c,c^2, c^3, \\ldots)$ & $\\frac{1}{1-cz}$ \\\\ \\hline\n        $(0,1,\\frac{1}{2},\\frac{1}{3},\\frac{1}{4},\\ldots)$ & $\\ln \\frac{1}{1-z}$ \\\\ \\hline\n      \\end{tabular}\n      \n    \\subsection{Combination Basis}\n    \t\tOccupancy $n$ Balls into $m$ Boxes\n      \\ \n\n      \\begin{tabular}{|c|c|c|c|c|}\n        \\hline\n         & Balls labeled & Boxes labeled & Any Box Empty & \\# of ways \\\\ \\hline\n        $(1)$ & N & N & N & $P_m(n)-P_{m-1}(n)$ \\\\ \\hline\n        $(2)$ & N & N & Y & $P_m(n)$ \\\\ \\hline\n        $(3)$ & N & Y & N & $\\binom{n-1}{m-1}$ \\\\ \\hline\n        $(4)$ & N & Y & Y & $\\binom{n+m-1}{n}$ \\\\ \\hline\n        $(5)$ & Y & N & N & $\\stirlingsecond{n}{m}$ \\\\ \\hline\n        $(6)$ & Y & N & Y & $\\stirlingsecond{n}{1}+...+\\stirlingsecond{n}{m}$ \\\\ \\hline\n        $(7)$ & Y & Y & N & $m!\\stirlingsecond{n}{m}$ \\\\ \\hline\n        $(8)$ & Y & Y & Y & $m^n$ \\\\ \\hline\n      \\end{tabular}\n    \\begin{enumerate}\n    \\item[*] $P_m(n)$:\\# of partitions of $n$ into $1,2,...,m$ with repetition allowed.\n    \\item[*] $P_m(n)=P_{m-1}(n)+P_{m}(n-m)$\n    \\item[*] $(8)=\\sum^m_{i=1}\\binom{m}{i}(7)$\n    \\item[*] $(4)=\\sum^m_{i=1}\\binom{m}{i}(3)$\n    \\end{enumerate}\n    Taylor's series:\n$$\nf(x) = f(a) + (x-a)f'(a) + {(x-a)^2 \\over 2} f''(a) + \\cdots = \\sum_{i=0}^\\infty {(x-a)^i \\over i!} f^{(i)}(a).\n$$\n\n\n%{F_n x \\over 1 - (F_{n-1} + F_{n+1})x - (-1)^n x^2}\n%&F_n x + F_{2n} x^2 + F_{3n} x^3 + \\cdots\n%&\\sum_{i=0}^\\infty F_{ni} x^i.\\cr\n\n%{x \\cot x}\n%&\\sum_{i=0}^\\infty {(-4)^i B_{2i} x^{2i} \\over (2i)!},\\cr\n%{\\tan x}\n%&\\sum_{i=1}^\\infty (-1)^{i-1}{2^{2i} (2^{2i} - 1) B_{2i} x^{2i-1} \\over %(2i)!},\\cr\n", "meta": {"hexsha": "f09537e23ae95ac3b411e1eab3640d4d4b9a3b3f", "size": 4947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math_facts.tex", "max_stars_repo_name": "ISeaTeL/Codebook", "max_stars_repo_head_hexsha": "2c137377d39085cb642294e5481bff039a074985", "max_stars_repo_licenses": ["MIT"], "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_facts.tex", "max_issues_repo_name": "ISeaTeL/Codebook", "max_issues_repo_head_hexsha": "2c137377d39085cb642294e5481bff039a074985", "max_issues_repo_licenses": ["MIT"], "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_facts.tex", "max_forks_repo_name": "ISeaTeL/Codebook", "max_forks_repo_head_hexsha": "2c137377d39085cb642294e5481bff039a074985", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-26T05:02:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-26T05:02:48.000Z", "avg_line_length": 35.3357142857, "max_line_length": 116, "alphanum_fraction": 0.4972710734, "num_tokens": 2217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037384317887, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7980460641977977}}
{"text": "\\subsection{Implicit Differentiation}\r\nAlthough we normally have equations of the form $y = f(x)$, some equations might be given in are are more convenient to write in different forms.\r\nUsing our understanding of the chain rule, we can still work with these forms and find $y^\\prime$. There are generally three steps to finding $y^\\prime$ when equations are given in these different forms.\r\n\\begin{enumerate}\r\n\t\\item Get all terms involving $y$ to one side of the equation. This step is technically optional but usually makes the step 3 more convenient.\r\n\t\\item Take the derivatives of both sides of the equation, using the chain rule.\r\n\t\\item Rearrange to solve for $y^\\prime$, making substitutions for $y$ to get the answer in terms of input parameters (e.g $x$).\r\n\\end{enumerate}\r\nIt's possible that you can get multiple solutions for $y^\\prime$.\r\nYou'll need to check if \r\n\r\n\\begin{example}\r\n\tGiven that $y^2 = x$, find $y^\\prime$ using implicit differentiation.\r\n\\end{example}\r\n\\begin{answer}\r\n\tStep 1 is already complete by what's given.\r\n\tTaking the derivative of both sides, remembering to use the chain rule,\r\n\t\\begin{equation*}\r\n\t\t2yy^\\prime = 1.\r\n\t\\end{equation*}\r\n\t\r\n\tSolving for $y^\\prime$,\r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\frac{1}{2y}.\r\n\t\\end{equation*}\r\n\t\r\n\tLooking back at our original equation, we see $y = \\pm\\sqrt{x}$.\r\n\tSubstituting back into our work,\r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\pm\\frac{1}{2\\sqrt{x}}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\nSometimes, it's not possible or is not necessary for what you're working on to complete step 3, meaning you leave your answer for $y^\\prime$ in terms of $y$ and input parameters.\r\n\\begin{example}\r\n\tFind the derivative for $y$ with respect to $x$ at $(0,1)$ if $y^4 = x^3 + x + y$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tRearranging to complete step 1,\r\n\t\\begin{equation*}\r\n\t\ty^4 - y = x^3 + x.\r\n\t\\end{equation*}\r\n\t\r\n\tTaking the derivative of both sides,\r\n\t\\begin{equation*}\r\n\t\t(4y^3 - 1)y^\\prime = 3x^2 + 1.\r\n\t\\end{equation*}\r\n\t\r\n\tSolving for $y^\\prime$ and completing step 2,\r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\frac{3x^2 + 1}{4y^3 - 1}.\r\n\t\\end{equation*}\r\n\t\r\n\tSince we have both the $x$ and $y$ coordinates of where we're looking for the slope, we don't need to complete step 3.\r\n\tWe can simply substitute to find our numerical answer for $y^\\prime$.\r\n\t\\begin{equation*}\r\n\t\ty^\\prime_{(0,1)} = \\frac{0 + 1}{4 - 1} = \\frac{1}{3}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\nSometimes, we might already be given a formula for $y$, but rearranging and then doing implicit differentiation is easier.\r\n\\begin{example}\r\n\tFind the derivative with respect to $x$ of $y = \\ln{x}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe don't have any way to find the derivative of $\\ln$ directly, but we do know how $\\ln$ relates to exponential functions, a form we do know how to differentiate.\r\n\tExponentiating both sides with base $e$,\r\n\t\\begin{equation*}\r\n\t\te^y = e^{\\ln{x}} = x.\r\n\t\\end{equation*}\r\n\t \r\n\tImplicitly differentiating,\r\n\t\\begin{equation*}\r\n\t\te^{y}y^\\prime = 1.\r\n\t\\end{equation*}\r\n\t\r\n\tSolving for $y^\\prime$,\r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\frac{1}{e^y}.\r\n\t\\end{equation*}\r\n\t\r\n\tSubstituting what we were given for $y$,\r\n\t\\begin{equation*}\r\n\t\ty^\\prime = \\frac{1}{e^{\\ln{x}}} = \\frac{1}{x}.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Logarithmic Differentiation}\r\nLogarithmic differentiation is a certain type of differentiation where you take to natural log of both sides and then implicitly differentiate.\r\nIt's especially useful when input parameters appear in both the base and exponent.\r\n\\begin{example}\r\n\tFind the derivative with respect to $x$ of $y = x^{\\ln{x}}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the natural log of both sides,\r\n\t\\begin{equation*}\r\n\t\t\\ln{y} = \\ln^2{x}.\r\n\t\\end{equation*}\r\n\t\r\n\tImplicitly differentiating,\r\n\t\\begin{align*}\r\n\t\t\\frac{1}{y}y^\\prime &= \\frac{2\\ln{x}}{x} \\\\\r\n\t\ty^\\prime &= y\\frac{2\\ln{x}}{x} \\\\\r\n\t\t&= x^{\\ln{x}}\\frac{2\\ln{x}}{x}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nWe now have the tools to prove the power rule for all real exponents.\r\n\\begin{proof}\r\n\tLet $n$ be an real number.\r\n\t\\begin{align*}\r\n\t\ty &= x^n \\\\\r\n\t\t\\ln{y} &= n\\ln{x} \\\\\r\n\t\t\\frac{1}{y}y^\\prime &= n\\frac{1}{x} \\\\\r\n\t\ty^\\prime &= \\frac{ny}{x} \\\\\r\n\t\t&= \\frac{nx^n}{x} \\\\\r\n\t\t&= nx^{n-1}.\r\n\t\\end{align*}\r\n\\end{proof}\r\n\r\n\\subsubsection{Combining Power and Exponential Rule}\r\nWe can also find the derivative of $f(x)^{g(x)}$, which combines the power and exponential rules and is something you'll likely won't see in a standard calculus course.\r\n\\begin{align*}\r\n\ty &= f^g \\\\\r\n\t\\ln{y} &= g\\ln{f} \\\\\r\n\t\\frac{1}{y}y^\\prime &= g\\frac{1}{f}f^\\prime + \\ln{f}g^\\prime \\\\\r\n\ty^\\prime &= f^g\\left(g\\frac{1}{f}f^\\prime + \\ln{f}g^\\prime\\right) \\\\\r\n\t&= f^{g-1}\\left(gf^\\prime + fg^\\prime\\ln{f}\\right).\r\n\\end{align*}", "meta": {"hexsha": "808cb6cde16985fab032f171dd2ce948c83b0767", "size": 4749, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/implicit_differenciation.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/implicit_differenciation.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/implicit_differenciation.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 36.5307692308, "max_line_length": 204, "alphanum_fraction": 0.6632975363, "num_tokens": 1544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382023207901, "lm_q2_score": 0.9263037333456405, "lm_q1q2_score": 0.7980460532296397}}
{"text": "\\subsection{Definitions}\n\\begin{align*}\nb&=\\sqrt{a} : b \\geq 0 \\wedge b^2=a \\\\\n\\sqrt{a^2}&= \\vert a \\vert \\\\\n\\text{If } a&\\geq \\text{ then } \\sqrt{a^2}=a\n\\end{align*}\n\\subsection{Distributing}\n$(a\\geq 0 \\wedge b\\geq 0)$\n\\begin{align*}\n\\sqrt{ab}&=\\sqrt{a}\\sqrt{b} \\\\\n\\sqrt{\\frac{a}{b}}&= \\frac{\\sqrt{a}}{\\sqrt{b}}\\qquad(b\\neq 0) \\\\\n\\sqrt{a}\\sqrt{a}&=a\\\\\n\\sqrt{a^n}&=\\left( \\sqrt{a} \\right) ^n \\vee a^{\\frac{n}{2}}\n\\end{align*}\n\\subsection{Rationalizing the Denominator}\n$(a>0 \\wedge b>0 \\wedge c>0)$\n\\begin{align*}\n\\frac{a}{\\sqrt{b}}=\\frac{a}{\\sqrt{b}}\\cdot\\frac{\\sqrt{b}}{\\sqrt{b}}&=\\frac{a\\sqrt{b}}{b} \n&\n\\frac{4}{\\sqrt{2}}=\\frac{4}{\\sqrt{2}}\\cdot\\frac{\\sqrt{2}}{\\sqrt{2}}&=\\frac{4\\sqrt{2}}{2}=2\\sqrt{2} \\\\ \\\\\n\\frac{a}{b+\\sqrt{c}}=\\frac{a}{b+\\sqrt{c}}\\cdot \\frac{b-\\sqrt{c}}{b-\\sqrt{c}}&=\\frac{ab-a\\sqrt{c}}{b^2-c}\n&\n\\frac{6}{3+\\sqrt{7}}=\\frac{6}{3+\\sqrt{7}}\\cdot\\frac{3-\\sqrt{7}}{3-\\sqrt{7}}&=\\frac{18-6\\sqrt{7}}{9-7} \\\\\n& & = \\frac{18-6\\sqrt{7}}{9-7}=\\frac{18-6\\sqrt{7}}{2}&=9-3\\sqrt{7} \\\\ \\\\\n\\frac{a}{b-\\sqrt{c}}=\\frac{a}{b-\\sqrt{c}} \\cdot \\frac{b+\\sqrt{c}}{b+\\sqrt{c}} &= \\frac{ab+a\\sqrt{c}}{b^2-c}\n&\n\\frac{5}{2-\\sqrt{3}}=\\frac{5}{2-\\sqrt{3}}\\cdot\\frac{2+\\sqrt{3}}{2+\\sqrt{3}}&=\\frac{10+5\\sqrt{3}}{4-3} \\\\\n& & =\\frac{10+5\\sqrt{3}}{1}&=10+5\\sqrt{3} \\\\ \\\\\n\\frac{a}{\\sqrt{b}+\\sqrt{c}}=\\frac{a}{\\sqrt{b}+\\sqrt{c}}\\cdot \\frac{\\sqrt{b}-\\sqrt{c}}{\\sqrt{b}-\\sqrt{c}}&=\\frac{a\\sqrt{b}-a\\sqrt{c}}{b-c}\n&\n\\frac{14}{\\sqrt{13}+\\sqrt{11}}=\\frac{14}{\\sqrt{13}+\\sqrt{11}}\\cdot \\frac{\\sqrt{13}-\\sqrt{11}}{\\sqrt{13}-\\sqrt{11}}&=\\frac{14\\sqrt{13}-14\\sqrt{11}}{13-11}\\\\\n& & = \\frac{14\\sqrt{13}-14\\sqrt{11}}{2}&=7\\sqrt{13}-7\\sqrt{11} \\\\ \\\\\n\\frac{a}{\\sqrt{b}-\\sqrt{c}}=\\frac{a}{\\sqrt{b}-\\sqrt{c}}\\cdot \\frac{\\sqrt{b}+\\sqrt{c}}{\\sqrt{b}+\\sqrt{c}}&=\\frac{a\\sqrt{b}+a\\sqrt{c}}{b-c}\n&\n\\frac{12}{\\sqrt{15}-\\sqrt{7}}=\\frac{12}{\\sqrt{15}-\\sqrt{7}} \\cdot \\frac{\\sqrt{15}+\\sqrt{7}}{\\sqrt{15}+\\sqrt{7}}&=\\frac{12\\sqrt{15}+12\\sqrt{7}}{15-7}\\\\\n& & = \\frac{12\\sqrt{15}+12\\sqrt{7}}{8}&=\\frac{3\\sqrt{15}+2\\sqrt{7}}{2}\n\\end{align*}\n\\subsection{OBS!}\n\\begin{align*}\n\\sqrt{a+b}&\\neq \\sqrt{a}+\\sqrt{b}\\\\\n\\sqrt{a-b}&\\neq \\sqrt{a}-\\sqrt{b}\\\\\n\\sqrt{a^2+b^2}&\\neq a+b\n\\end{align*}\n", "meta": {"hexsha": "039b268c6bf8e18a07627b3ef8688ea997a683a5", "size": 2141, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms and Data Structures - Reference/root.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/root.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/root.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": 48.6590909091, "max_line_length": 155, "alphanum_fraction": 0.5539467539, "num_tokens": 1110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291502, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7980412342046204}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\n\\graphicspath{ {./assets/} }\n\n\\setlength\\paperwidth{20.999cm}\\setlength\\paperheight{29.699cm}\\setlength\\voffset{-1in}\\setlength\\hoffset{-1in}\\setlength\\topmargin{1.499cm}\\setlength\\headheight{12pt}\\setlength\\headsep{0cm}\\setlength\\footskip{1.131cm}\\setlength\\textheight{25cm}\\setlength\\oddsidemargin{2.499cm}\\setlength\\textwidth{15.999cm}\n\n\\begin{document}\n\\begin{center}\n\\hrule\n\n\\vspace{.4cm}\n{\\bf {\\Huge Assignment 7}} \\\\\n\\vspace{.2cm}\n{\\bf Computer Graphics}\n\\vspace{.2cm}\n\\end{center}{\\bf Edoardo Riggio } (edoardo.riggio@usi.ch) \\hspace{\\fill}  \\today \\\\\n\\hrule\n\\vspace{.2cm}\n\n\\section{Exercise 1}\nIn order to compute the pixels that need to be coloured, we first need to transform the global coordinates into screen coordinates. To do so, we use the following formula:\n\n\\[ p_{ixs} = p_{ix} \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} \\]\n\\[ p_{iys} = p_{iy} \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} \\] \\\\\nWhere $p_{ixs}$ and $p_{iys}$ are the points in screen coordinates, $p_{ix}$ and $p_{iy}$ are the points in global coordinates, ${\\frac{3}{8}\\cdot \\pi}$ is the camera opening divided by 2, and 8 is the width of the screen divided by 2 -- rounded up to the nearest integer. By using this function, we can finally compute the values of the points.\\\\ \\\\\nIn the following computations, the results are floored. Moreover, in the case that the $z$ value of the global point is not 1, then $p_{ix}$ and $p_{iy}$ are divided by $z$. Finally, I assume the point $(0,0)$ to be at the center of the screen, rather than at the top-left corner.\n\n\\[ p_{1xs} = \\frac{1}{4} \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} = 0 \\]\n\\[ p_{1ys} = \\frac{1}{4} \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} = 0 \\]\n\\[ p_{1s} = (0,0) \\] \\\\\n\\[ p_{2xs} = 2 \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} = 6 \\]\n\\[ p_{2ys} = 1 \\cdot \\frac{8}{\\tan{\\frac{3}{8}} \\cdot \\pi} = 3 \\]\n\\[ p_{2s} = (6,3) \\] \\\\\nAfter converting the points, we can use the following pseudocode in order to compute the pixels of the line.\n\n\\begin{verbatim}\n  x = p1.x\n  y = p1.y\n  dx = p2.x - p1.x\n  dy = p2.y - p1.y\n  f = -2 * dy + dx\n\n  for i in range(0, dx+1):\n    setPoints(x,y)\n    x += 1\n    if f < 0:\n      y += 1\n      f += 2 * dx\n    f -= 2 * dy\n\\end{verbatim}\nWhich will output the following pixels:\n\n\\[ (0, 0), (1, 0), (2, 1), (3, 1), (4, 2), (5, 2), (6, 3) \\]\\\\\nIn the case of the segment between $p_1$ and $p'2$, we have that $p'2$ has a negative $z$ value. Because the screen has $z=1$, this means that the segment intersects the screen and goes behind it. For this reason we need to find the intersection between the segment and the plane $z = 1$. By using the calculator, I've found out the intersection to be the point $(2,1,1)$. This means that the points to be coloured are the same as the ones in the previous part of the exercise.\n\n\\section{Exercise 2}\nThe pseudocode used to compute the midpoint algorithm for the circle is the following:\n\n\\begin{verbatim}\n  function midpoint_circle(r):\n    x = 0\n    y = -r\n\n    f = 1 - r\n\n    while y < x:\n      setPoint(x,y)\n      setPoint(-x,y)\n      setPoint(x,-y)\n      setPoint(-x,-y)\n      setPoint(y,x)\n      setPoint(-y,x)\n      setPoint(y,-x)\n      setPoint(-y,-x)\n      x += 1\n        \n      if f > 0:        \n        y += 1\n        f += 2 * x - 2 * y + 1\n        \n      f += 2 * x + 1\n\n      if (|y| < x):\n        exit loop\n\\end{verbatim}\nHere we use a similar approach as the one used in the midpoint algorithm for the line. Inside of the while loop -- which computes only the points of $\\frac{1}{8}$ of the circle, and then uses symmetric properties of the circle in order to compute the points in the other $\\frac{1}{8}$s of the circle -- we check if $f$ is greater, equal or smaller than 0. This is because we can recognize three different cases:\n\n\\begin{enumerate}\n\t\\item f $>$ 0: In this case the midpoint is outside of the circle;\n\t\\item f = 0: In this case the midpoint is on the circle;\n\t\\item f $<$ 0: In this case the midpoint is inside of the circle.\n\\end{enumerate}\nIn this algorithm the decision value ($f$) is computed by using the formula of the circle:\n\t\\[ x^2 + y^2 - r^2 \\]\n\n\\end{document}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "863bf37ffc415e18e18210151e465cbaf6368ecb", "size": 4213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "artifacts/assignment 7/assigment-7.tex", "max_stars_repo_name": "edoriggio/rasterizer", "max_stars_repo_head_hexsha": "7ac0db182211aa2a6f858ed3fd4bfff277572b9d", "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": "artifacts/assignment 7/assigment-7.tex", "max_issues_repo_name": "edoriggio/rasterizer", "max_issues_repo_head_hexsha": "7ac0db182211aa2a6f858ed3fd4bfff277572b9d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "artifacts/assignment 7/assigment-7.tex", "max_forks_repo_name": "edoriggio/rasterizer", "max_forks_repo_head_hexsha": "7ac0db182211aa2a6f858ed3fd4bfff277572b9d", "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.7033898305, "max_line_length": 477, "alphanum_fraction": 0.6456206978, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159129, "lm_q2_score": 0.8933094046341533, "lm_q1q2_score": 0.7980017038258914}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\\begin{document}\n\\subsection{Accessible Set-Systems}\n\\begin{defn}\nAn \\textit{accessible set-system} is a pair $M=(E,\\mathcal{S})$ where $E$ is a finite ground set and $\\mathcal{S}$ is a non-empty subset of the power set of $E.$ Elements of $\\mathcal{S}$ are called the \\textit{feasible sets} of $M.$ Maximal feasible sets are also called \\textit{bases}.\\\\\n$\\mathcal{S}$ satisfies the following \\textit{accessibility axiom}:\\\\\n(A) For any non-empty feasible set $X \\in \\mathcal{S}$ there exists an element $e \\in X$ such that $X \\setminus \\{e\\} \\in \\mathcal{S}.$\n\\end{defn}\n\n\\begin{rem}\nMatroid $\\supseteq$ Independence System $\\supseteq$ Accessible Set-System.\\\\\nAll matroids are independence systems and all independence systems are accessible set-systems but the converse is not true in general.\n\\end{rem}\n\n\\noindent The axiom $(A)$ is needed due to the process of the greedy algorithm. We require the ability to sequentially select a single element and then union it to our constructed solution at each step so an arbitrary set system cannot guarantee this. Axiom (A) however ensures that at each step such an element does in fact exist, although the subset of possible choices for this element may not be the same at each iteration of the process, which leads to further possible issues.\n\n\\noindent Our general problem can now be restated as:\n\\begin{prop}\nFor any accessible set-system $M$ and any weight function $\\omega:E \\longrightarrow \\mathbb{R^+},$ the optimisation problem is:\\\\\n Maximise $\\omega(B)$ such that $B$ is a basis of $M.$\n\\end{prop}\n\\noindent We can now apply a modified greedy algorithm in order to find a solution to this generalised version of our matroid/independence system problem.\n\n\\begin{algorithm}[H]\n\\caption{Greedy algorithm for accessible set-systems}\\label{modified_greedy}\nLet $M=(E,\\mathcal{S})$ be an accessible set-system and $\\omega:E \\longrightarrow \\mathbb{R^+}$ a weight function.\n\\begin{algorithmic}[1]\n\\Procedure{GREEDY}{$E, \\mathcal{S}, \\omega,T$}\n\\State $T \\gets \\emptyset$, $X \\gets E$\n\\While{there $\\exists x \\in X$ with $T \\cup \\{x\\} \\in \\mathcal{S}$}\n\\State choose some $x \\in X$ with $T \\cup \\{x\\} \\in \\mathcal{S}$ and\n\\State $\\omega(x) \\geq \\omega(y)$ $\\forall y \\in X$ with $T \\cup \\{y\\} \\in \\mathcal{S}$\n\\State $T \\gets T \\cup \\{x\\}$, $X \\gets X \\setminus \\{x\\}$\n\\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\\noindent Using our above definitions and algorithm we can now begin finding solutions to our problem for any accessible set-system. However, we are interested in learning about the characterisations of these set-systems that lead to optimal solutions through the use of our greedy algorithm as described in \\textit{section 5.2}.\\\\\nOne such characterisation is the concept of a \\textit{greedoid}. A greedoid is an accessible set-system satisfying (I3). Formally this means,\n\\begin{defn}\nA \\textit{greedoid} is a pair $(E,\\mathcal{S})$ where $E$ is a finite ground set and $\\mathcal{S}$ is a collection of the feasible subsets of $E$ satisfying the following conditions:\\\\\n(I1): $\\mathcal{S}$ is non-empty, $\\emptyset \\in \\mathcal{S}.$\\\\\n(A):  For any non-empty feasible set $X \\in \\mathcal{S}$ there exists an element $e \\in X$ such that $X \\setminus \\{e\\} \\in \\mathcal{S}.$\\\\\n(I3): If $ A $ and $ B $ are two independent sets of $\\mathcal{S}$ and $|A|>|B|$, then there exists $x \\in A \\setminus B$ such that $B \\cup \\{ x \\}$ is in $\\mathcal{S}.$\n\\end{defn}\nUnfortunately the greedy algorithm while providing solutions does not gaurantee optimal solutions for all greedoids. To characterise the greedoids that do result in optimal solutions when the greedy algorithm is applied we must add to our existing machinery an additional axiom. This is called the \\textit{strong exchange axiom}. This axiom is a strong version of (I3): the exchange axiom of a matroid. \n\\begin{prop}\nLet $M=(E,\\mathcal{S})$ be a greedoid. Then the above modified greedy algorithm  finds an optimal solution to our problem for any weight function $\\omega:E \\longrightarrow \\mathbb{R^+}$ if and only if $M$ satisfies the following axiom:\\\\\n(SE): For $A,B \\in \\mathcal{S}$ with $|A|=|B|+1$, there always exists some $e \\in A \\setminus B$ such that $B \\cup \\{e\\}$ and $A \\setminus \\{e\\}$ are contained in $\\mathcal{S}.$ Which is very reminiscent of \\textit{lemma 1.3}.\n\\end{prop}\n\\begin{rem}\nIt can be seen that this axiom holds trivially for matroids due to the hereditary condition.\n\\end{rem}\n\\begin{rem}\nThe amount of the possible greedoids which can yield optimal solutions can be further characterised using further abstracted properties of matroids, similar to axiom (SE), for this I refer you to Jungnickel's text\\cite{jungnickel} and the papers cited above.\n\\end{rem}\n\\end{document}\n", "meta": {"hexsha": "76ef474eb48293cc4b64b4642d044c10b28e5091", "size": 4778, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeXPdfs/sections/gre1.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/gre1.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/gre1.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": 80.9830508475, "max_line_length": 482, "alphanum_fraction": 0.7362913353, "num_tokens": 1356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094060543487, "lm_q2_score": 0.8933094117351309, "lm_q1q2_score": 0.7980017000198695}}
{"text": "% This is a template for doing homework assignments in LaTeX, cribbed from M. Frenkel (NYU) and A. Hanhart (UW-Madison)\n\n\\documentclass{article} % This command is used to set the type of document you are working on such as an article, book, or presenation\n\n\\usepackage[margin=1in]{geometry} % This package allows the editing of the page layout. I've set the margins to be 1inch. \n\\usepackage{datetime}\n\n\\usepackage{amsmath, amsfonts}  % The first package allows the use of a large range of mathematical formula, commands, and symbols.  The second gives some useful mathematical fonts.\n\n\\usepackage{graphicx}  % This package allows the importing of images\n\n%Custom commands \n\\newcommand{\\der}[2]{\\frac{\\mathrm{d} #1}{\\mathrm{d} #2}}\n\n%Custom symbols\n\\newcommand{\\linediv}{\\noindent\\rule{6.5in}{2pt}}\n\\newcommand{\\linedivm}{\\noindent\\rule{6.5in}{1pt}}\n\n\n\\begin{document}\n\n\\begin{center}\n    \\Large{\n        \\textbf{Assignment \\#1}\n\n        UW-Madison MATH 421\n    }\n    \n    \\vspace{5pt}\n        \n    \\normalsize{\n        GEOFF YOERGER\n\n        \\usdate\n        \\formatdate{2}{2}{2021}\n    }\n    \n    \\vspace{15pt}\n\\end{center}\n    \n\\subsection*{Exercise One:} \n    \na)\n\n\\linediv\n\n\\begin{verbatim}\nIf $f(x) = x^n$,  then \n$$\nf^\\prime(x) = n x^{n-1}.\n$$\n\\end{verbatim}\n\n\\linedivm\n\nIf $f(x) = x^n$,  then \n$$\nf^\\prime(x) = n x^{n-1}.\n$$\n\n\\linediv\n \n\\noindent b)\n\n\\linediv\n\n\\begin{verbatim}\nIf $n \\neq -1$,  then \n$$\n\\int x^{n} dx = \\frac{1}{n+1} x^{n+1} + C.\n$$\n\\end{verbatim}\n\n\\linedivm\n\nIf $n \\neq -1$,  then \n$$\n\\int x^{n} dx = \\frac{1}{n+1} x^{n+1} + C.\n$$\n\n\\linediv\n\n\\noindent c)\n\n\\linediv\n\n\\begin{verbatim}\nThe derivative of a function $f$ at $x=a$ is\n$$\nf'(a) = \\lim_{h \\to 0} \\frac{f(a+h) - f(a)}{h}.\n$$\n\\end{verbatim}\n\n\\linedivm\n\nThe derivative of a function $f$ at $x=a$ is\n$$\nf'(a) = \\lim_{h \\to 0} \\frac{f(a+h) - f(a)}{h}.\n$$\n\n\\linediv\n\n    \n\\subsection*{Exercises Two:}     \n    \n\\noindent a)\n\n\\linediv\n\n\\begin{verbatim}\nThe number $e$ is defined by\n$$\ne = \\lim_{n \\to \\inf} \\left( 1 + \\frac{1}{n} \\right) ^ {n}.\n$$\n\\end{verbatim}\n\n\\linedivm\n\nThe number $e$ is defined by\n$$\ne = \\lim_{n \\to \\infty} \\left( 1 + \\frac{1}{n} \\right) ^ {n}.\n$$\n\n\\linediv\n\n\\noindent b)\n\n\\linediv\n\n\\begin{verbatim}\nIf $f$ is a continuous function, then\n$$\n\\frac{d}{dx} \\left[ \\int_{a}^{x} f(t) dt \\right] = f(x).\n$$\n\\end{verbatim}\n\n\\linedivm\n\nIf $f$ is a continuous function, then\n$$\n\\frac{d}{dx} \\left[ \\int_{a}^{x} f(t) dt \\right] = f(x).\n$$\n\n\\linediv\n \n\\subsection*{Exercise Three:}\n\n\\linediv\n\n\\begin{verbatim}\n\\begin{center}\n    \\begin{tabular}{|rl|cc|}\n    \\hline\n    First Name & Last Name & Ice Cream Flavor & Number of Scoops \\\\\n    \\hline\n    Alexa & Leal & Vanilla & $4$ \\\\\n    Julia & Maschi & Chocolate & $2$ \\\\\n    Johnny & Tran & Strawberry & $18$ \\\\\n    Geoff & Yoerger & Chocolate Malt & $\\infty$ \\\\\n    \\hline\n    \\end{tabular}\n\\end{center}\n\\end{verbatim}\n\n\\linedivm\n\n\\begin{center}\n    \\begin{tabular}{|rl|cc|}\n    \\hline\n    First Name & Last Name & Ice Cream Flavor & Number of Scoops \\\\\n    \\hline\n    Alexa & Leal & Vanilla & $4$ \\\\\n    Julia & Maschi & Chocolate & $2$ \\\\\n    Johnny & Tran & Strawberry & $18$ \\\\\n    Geoff & Yoerger & Chocolate Malt & $\\infty$ \\\\\n    \\hline\n    \\end{tabular}\n\\end{center}\n\n\\linediv\n\n\\subsection*{Exercise Four:}\n\n\\linediv\n\n\\begin{verbatim}\n$$\n\\det\n\\begin{pmatrix}\n    a & b \\\\\n    c & d \\\\\n\\end{pmatrix}\n= ad - bc.\n$$\n\\end{verbatim}\n\n\\linedivm\n\n$$\n\\det\n\\begin{pmatrix}\n    a & b \\\\\n    c & d \\\\\n\\end{pmatrix}\n= ad - bc.\n$$\n\n\\linediv\n\n\\subsection*{Exercise Five:}\n\n\\noindent 1)\n\n\\linediv\n\n\\begin{verbatim}\n\\newcommand{\\Rb}{\\mathbb{R}}\n\\newcommand{\\Nb}{\\mathbb{N}}\n\\newcommand{\\Zb}{\\mathbb{Z}}\n\\newcommand{\\Qb}{\\mathbb{Q}}\n\\newcommand{\\Cb}{\\mathbb{C}}\n\n$$\n\\Nb \\subset \\Zb \\subset \\Qb \\subset \\Rb \\subset \\Cb\n$$\n\\end{verbatim}\n\n\\linedivm\n\n\\newcommand{\\Rb}{\\mathbb{R}}\n\\newcommand{\\Nb}{\\mathbb{N}}\n\\newcommand{\\Zb}{\\mathbb{Z}}\n\\newcommand{\\Qb}{\\mathbb{Q}}\n\\newcommand{\\Cb}{\\mathbb{C}}\n\n$$\n\\Nb \\subset \\Zb \\subset \\Qb \\subset \\Rb \\subset \\Cb\n$$\n\n\\linediv\n\n\\noindent 2)\n\n\\linediv\n\n\\begin{verbatim}\n\\newcommand{\\pder}[2]{\\frac{\\partial #1}{\\partial #2}}\n\nIf $z = x^2 + xy + y^2$, then\n$$\n\\pder{z}{x} = 2x + y\n$$\n\\end{verbatim}\n\n\\linedivm\n\n\\newcommand{\\pder}[2]{\\frac{\\partial #1}{\\partial #2}}\n\nIf $z = x^2 + xy + y^2$, then\n$$\n\\pder{z}{x} = 2x + y\n$$\n\n\\linediv\n \n\\subsection*{Exercise Six:}\n    \n\\linediv\n\n\\begin{verbatim}\nIf $f(x) = x^2$, then\n\\begin{align*}\n    f'(a) & = \\lim_{h \\to 0} \\frac{f(a+h) - f(a)}{h} \\\\\n    & = \\lim_{h \\to 0} \\frac{(a+h)^2 - a^2}{h} \\\\\n    & = \\lim_{h \\to 0} \\frac{a^2 + 2ah + h^2 - a^2}{h} \\\\\n    & = \\lim_{h \\to 0} 2a + h = 2a. \\\\\n\\end{align*}\n\\end{verbatim}\n\n\\linedivm\n\nIf $f(x) = x^2$, then\n\\begin{align*}\n    f'(a) & = \\lim_{h \\to 0} \\frac{f(a+h) - f(a)}{h} \\\\\n    & = \\lim_{h \\to 0} \\frac{(a+h)^2 - a^2}{h} \\\\\n    & = \\lim_{h \\to 0} \\frac{a^2 + 2ah + h^2 - a^2}{h} \\\\\n    & = \\lim_{h \\to 0} 2a + h = 2a. \\\\\n\\end{align*}\n\n\\linediv\n\n\\end{document}\n", "meta": {"hexsha": "226692fa1916c149f9485bdd3627f82b809c2e51", "size": 4918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "UWM/421/HW1/HW1_doc.tex", "max_stars_repo_name": "DirkyJerky/Uni", "max_stars_repo_head_hexsha": "73ec1a84cdd59af9fc82a7bbb8af931305ec2ad3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "UWM/421/HW1/HW1_doc.tex", "max_issues_repo_name": "DirkyJerky/Uni", "max_issues_repo_head_hexsha": "73ec1a84cdd59af9fc82a7bbb8af931305ec2ad3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "UWM/421/HW1/HW1_doc.tex", "max_forks_repo_name": "DirkyJerky/Uni", "max_forks_repo_head_hexsha": "73ec1a84cdd59af9fc82a7bbb8af931305ec2ad3", "max_forks_repo_licenses": ["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.7849829352, "max_line_length": 181, "alphanum_fraction": 0.585603904, "num_tokens": 1933, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.918480237888855, "lm_q1q2_score": 0.7980002334822414}}
{"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{numerical precision}, \\emph{accuracy} and \\emph{complexity}.\n\nFirstly, I will provide a detailed mathematical derivation of the model for all these formulations, then I will propose two algorithms to solve the optimization problem in case of \\emph{constrained} or \\emph{unconstrained} formulation of the problem, explaining their theoretical properties, i.e., \\emph{convergence} and \\emph{complexity}.\n\nFinally, I will show some experiments for \\emph{linearly} and \\emph{nonlinearly} separable generated datasets to compare the performance of different \\emph{kernels}, also by comparing the \\emph{custom} results with \\emph{sklearn} SVM implementations, i.e., \\emph{liblinear}~\\cite{fan2008liblinear} and \\emph{libsvm}~\\cite{chang2011libsvm} implementations, and \\emph{cvxopt}~\\cite{vandenberghe2010cvxopt} QP solver.\n", "meta": {"hexsha": "fd04eb773f33b0deab3db69e4e2852917eab5a21", "size": 1289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/abstract.tex", "max_stars_repo_name": "AF207/optiml", "max_stars_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-06T13:59:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T13:59:03.000Z", "max_issues_repo_path": "notebooks/optimization/tex/abstract.tex", "max_issues_repo_name": "AF207/optiml", "max_issues_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebooks/optimization/tex/abstract.tex", "max_forks_repo_name": "AF207/optiml", "max_forks_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_forks_repo_licenses": ["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.9, "max_line_length": 414, "alphanum_fraction": 0.7951900698, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8757869851639066, "lm_q1q2_score": 0.7979993290614309}}
{"text": "\\subsection*{Ex.29.1-5}\n\nWe have the following linear program\n$$\n\\begin{aligned}\n & \\max & 2x_1 && && && - && 6x_3 & \n\\\\\n & \\ \\text{s.t.} & x_1 && + && x_2 && - && x_3 & \\leq 7\n\\\\\n & & 3x_1 && - && x_2 && && & \\geq 8\n\\\\\n & & -x_1 && + && 2x_2 && + && 2x_3 & \\geq 0\n\\\\\n & & && && && && x_1,x_2,x_3 & \\geq 0\n\\end{aligned}\n$$\nWe first put this on standard form, by reversing two of the inequalities:\n$$\n\\begin{aligned}\n & \\max & 2x_1 && && && - && 6x_3 & \n\\\\\n & \\ \\text{s.t.} & x_1 && + && x_2 && - && x_3 & \\leq 7\n\\\\\n & & -3x_1 && + && x_2 && && & \\leq -8\n\\\\\n & & x_1 && - && 2x_2 && - && 2x_3 & \\leq 0\n\\\\\n & & && && && && x_1,x_2,x_3 & \\geq 0\n\\end{aligned}\n$$\nWe can now convert the linear program into slack form, by introducing the slack variables $x_4$, $x_5$ and $x_6$, which measures the slack between the left-hand and right-hand sides of each of the inequalities, besides the nonnegativity constraints.\n\\\\\nThe slack form will then have equality constraints, besides the nonnegativity constraints, as follows:\n$$\n\\begin{aligned}\n & \\max & && && && 2x_1 && && && - && 6x_3\n\\\\\n & \\ \\text{s.t.} & x_4 = && 7 && - && x_1 && - && x_2 && + && x_3 &\n\\\\\n & & x_5 = && -8 && + && 3x_1 && - && x_2 && &&\n\\\\\n & & x_6 = &&  && - && x_1 && + && 2x_2 && + && 2x_3\n\\\\\n & & && && x_1,x_2,x_3,x_4,x_5,x_6 \\geq 0 \\span\\span\\span\\span\\span\\span\\span\\span\\span\\span\\span\\span\n\\end{aligned}\n$$\nAnd the basic and nonbasic variables are:\n\\\\\nBasic: $x_4,x_5,x_6$\n\\\\\nNonbasic: $x_1,x_2,x_3$", "meta": {"hexsha": "6f4de361e770f2a6612f746113f5d98efbe571f3", "size": 1470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.29.1-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": "Uge2/Ex.29.1-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": "Uge2/Ex.29.1-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": 28.8235294118, "max_line_length": 249, "alphanum_fraction": 0.5340136054, "num_tokens": 633, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834277, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.7979931921412093}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\title{Square root of 321}\n\\author{Dave Neary}\n\\date{January 2021}\n\n\\begin{document}\n\n\\section{Approximation of square roots}\n\nWe can estimate square roots of numbers that are close to perfect squares. For example, $18^2 = 324$\nand\n\\begin{eqnarray*}\n(18-x)^2& =& 321\\\\\n324 - 36x + x^2 & =& 321\\\\\n3 &=& 36x - x^2 \\\\\n\\end{eqnarray*}\n\nNow, since $x$ will be small, $x^2$ will be negligible for a reasonable estimate. We can thus\ndiscard the $x^2$ term, giving:\n\n\\[ x \\approx \\frac{3}{36} = \\frac{1}{12}\\]\nfor small values of $x$. So $\\sqrt{321} \\approx 18 - \\frac{1}{12}$.\n\nIn general, if a number is close to a perfect square, we can write it as $n^2 + m$ for\n$m\\in \\mathbb{Z}$, and you can approximate the square root with:\n\\[\\sqrt{n^2+m} \\approx n+\\frac{m}{2n}\\]\n\nThis also works for higher powers! If a number is close to $n^k$, we write it as $n^k+m$, and:\n\\[ \\sqrt[k]{n^k+m} \\approx n+\\frac{m}{kn^{k-1}} \\]\n\nThis is the method that Richard Feynmann used to approximate the cube root of $1729$ when\ncompeting against an abacus salesman. $12^3 = 1728$ (which he knew from cubic inches in a cubic foot), so\n\\[ \\sqrt[3]{1729} \\approx 12 + \\frac{1}{3\\times12^2} = 12+\\frac{1}{432} \\]\n\nWe can also use the Binomial theorem extended to real exponents to get even closer approximations.\n\\begin{eqnarray*}\n \\sqrt{321}& =& \\sqrt{324 - 3} \\\\\n& = & 18 \\left(1-\\frac{1}{108}\\right)^{\\frac{1}{2}} \\\\\n& = &18 \\left( 1 + \\binom{\\frac{1}{2}}{1}\\left(\\frac{-1}{108}\\right) + \\binom{\\frac{1}{2}}{2}\\left(\\frac{1}{108^2}\\right) + \\cdots ) \\right) \\\\\n& \\approx & 18 \\left(1 - \\frac{1}{216} - \\frac{1}{93312} - \\cdots\\right) \\\\\n& \\approx & 18 - \\frac{1}{12} - \\frac{1}{5184} - \\cdots\n\\end{eqnarray*}\nwhere $\\binom{x}{r} = \\frac{(x)(x-1)(\\cdots)(x-r+1)}{r!}$ for $x \\in \\mathbb{R}$.\n\n \\end{document}\n", "meta": {"hexsha": "a6a7d3a2a36ae422878cfc72e54141ada20d570b", "size": 1876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sqrt_estimate.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": "sqrt_estimate.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": "sqrt_estimate.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": 37.52, "max_line_length": 143, "alphanum_fraction": 0.64445629, "num_tokens": 702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8947894541786198, "lm_q1q2_score": 0.7979831262966371}}
{"text": "\\subsection{Example}\n\nLet $A=\\begin{bmatrix}1&4&7\\\\ 2&5&8\\\\3&6&9\\end{bmatrix}$. Finding the basis:\n\n\\[\n    \\mathrm{rref}(A)=\n     \\begin{bmatrix}1&0&-1\\\\ 0&1&2\\\\0&0&0\\end{bmatrix}\n\\] \n\nSince there is redundance, a possible expression of the basis of $A$:\n\n\\[\\mathfrak{B}=\\left\\{\\begin{bmatrix}1\\\\2\\\\3\\end{bmatrix},\\begin{bmatrix}4\\\\5\\\\6\\end{bmatrix}\\right\\}\\]\n\nWhen finding kernel, must solve $A\\tb{x}=\\tb{0}$. So with $[\\mathrm{rref}(A)|\\tb{0}]$:\n\n\\[\\tb{x}=\\begin{bmatrix}t\\\\ -2t\\\\t\\end{bmatrix}=t \\begin{bmatrix}1\\\\-2\\\\1\\end{bmatrix}\\]\n\nThus,\n\n\\[\\mathrm{ker}(A)=\\left\\{t\\begin{bmatrix}1\\\\-2\\\\1\\end{bmatrix}\\bigg|\\;t\\in \\R\\right\\}\\]\n\n\\noindent\nSubsequently, the basis of the kernel of $A$ can be represented as $\\mathfrak{B}=\\left\\{\\begin{bmatrix}1\\\\-2\\\\1\\end{bmatrix}\\right\\}$.\n\n\\noindent\nEquivalent statements for $\\left\\{\\tb{v}_{1}, \\tb{v}_{2}, \\tb{v}_{3}, \\ldots, \\tb{v}_{m}\\right\\}$ being linearly independent:\n\\begin{itemize}\n    \\item None of the vectors are redundant\n    \\item Only relation is trivial\n    \\item Kernel of $\\left(\\begin{array}{cccc}\n        \\mid & \\mid & & \\mid \\\\\n        \\tb{v}_{1} & \\tb{v}_{2} & \\ldots & \\tb{v}_{m} \\\\\n        \\mid & \\mid & & \\mid\n        \\end{array}\\right)$ is trivial\n    \\item Rank of $\\left(\\begin{array}{cccc}\n        \\mid & \\mid & & \\mid \\\\\n        \\tb{v}_{1} & \\tb{v}_{2} & \\ldots & \\tb{v}_{m} \\\\\n        \\mid & \\mid & & \\mid\n        \\end{array}\\right)$ is $m$\n    \\item If $m=n$ then $\\left(\\begin{array}{cccc}\n        \\mid & \\mid & & \\mid \\\\\n        \\tb{v}_{1} & \\tb{v}_{2} & \\ldots & \\tb{v}_{m} \\\\\n        \\mid & \\mid & & \\mid\n        \\end{array}\\right)$ reduces to $I_n$\n\\end{itemize}", "meta": {"hexsha": "608fc4b10448c0955438b7d88e23bcd0f36fd4c6", "size": 1641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/13_basis-kernel.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/13_basis-kernel.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/13_basis-kernel.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": 36.4666666667, "max_line_length": 134, "alphanum_fraction": 0.5679463742, "num_tokens": 651, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8902942290328345, "lm_q1q2_score": 0.7979274203293122}}
{"text": "\\section{Introduction and Background}\nThe FW is a classic dynamic programming algorithm that solves the \\emph{all-pairs shortest path (APSP)} problem on a directed weighted\ngraph $G(V, E, w)$, where $V = \\{1, \\dots, n\\}$ is a set of nodes, $E \\subseteq V \\times V$ are the edges and $w$ is a weight function $E \\rightarrow  \\mathbb{R}$\nthat expresses the cost of crossing two nodes. The number of nodes is denoted by $n$ and the number of edges by $m$ . \\par\nThe output of the algorithm is typically in matrix form: the entry in the $i^{th}$ row and $j^{th}$ column is the weight of the shortest path between\nnodes $i$ and $j$. FW runs in $\\Theta(|V|^3)$ time and for this reason is a good choiche when working with dense graph: even though there\nmay be up to $\\Omega(|E|^2)$ edges, the computational time is independent from the number of edges. \\par\nThe FW algorithm is shown in \\textbf{Algorithm \\ref*{alg:fw1}}.\n\n\\begin{algorithm}[h!]\n\n\\SetAlgoLined\n\n\\For{$(u, v) \\in E$}{\n    $M_{u, v} \\leftarrow w(u, v)$\n}\n\\For{$v = 1 \\rightarrow n$}{\n    $M_{v, v} \\leftarrow 0$\n}\n \\For{$k = 1 \\rightarrow n$}{\n  \\For{$i = 1 \\rightarrow n$}{\n  \\For{$j = 1 \\rightarrow n$}{\n  \\If{$M_{i, j} > M_{i, k} + M_{k, j}$}{\n \n    $M_{i, j} \\leftarrow M_{i, k} + M_{k, j}$ \n }\n }\n }\n }\n \n\\caption{The Floyd-Warshall (FW) algorithm}\\label{alg:fw1}\n\\end{algorithm}\n\n\n\nA C implementation of this algorithm can be found \\href{https://github.com/firaja/Parallel-FloydWarshall/blob/master/sequential.c}{here};\nthis version is referred in this document as \\emph{serial} FW and it is used as base for comparison. \\par \n\n", "meta": {"hexsha": "4c143bb4c1102c37f4b4243555e96c4fb12d0860", "size": 1592, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/intro.tex", "max_stars_repo_name": "firaja/Parallel-FloydWarshall", "max_stars_repo_head_hexsha": "97b99291cf2eb8bf12b1775358f6c5179f5a03b8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-06-19T21:42:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-12T11:25:06.000Z", "max_issues_repo_path": "report/intro.tex", "max_issues_repo_name": "firaja/Parallel-FloydWarshall", "max_issues_repo_head_hexsha": "97b99291cf2eb8bf12b1775358f6c5179f5a03b8", "max_issues_repo_licenses": ["MIT"], "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/intro.tex", "max_forks_repo_name": "firaja/Parallel-FloydWarshall", "max_forks_repo_head_hexsha": "97b99291cf2eb8bf12b1775358f6c5179f5a03b8", "max_forks_repo_licenses": ["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.8205128205, "max_line_length": 162, "alphanum_fraction": 0.6790201005, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220294, "lm_q2_score": 0.8962513655129178, "lm_q1q2_score": 0.7979274158701353}}
{"text": "\\chapter{The hydrogen atom}\\label{c6}\n\\section{The Hamiltonian}\\label{c6s1}\nThe quantum mechanical treatment of the hydrogen atom resolved the mystery of \nBohr's second postulate. It also demonstrated the convenience of the \nSchr\\\"{o}dinger's approach. His equation can be solved exactly for the hydrogen\natom. The hydrogen atom consists of a single electron in the electric field od a\nsingle proton. Since the electron is almost $1836$ times lighter than the proton\nwe can, as a first approximation, assume that the proton is at rest. Therefore, \nthe energy of the system is\n\\begin{equation}\\label{c6s1e1}\nH = \\frac{p^2}{2m} - \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r},\n\\end{equation}\nwhere $e$ is the electronic charge and $r$ is the distance between the two. The\noperator representation of this Hamiltonian is\n\\begin{equation}\\label{c6s1e2}\n\\hat{H} = -\\frac{\\hslash^2}{2m}\\nabla^2 - \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\n\\end{equation}\nand the Schr\\\"{o}dinger's time independent equation is\n\\begin{equation}\\label{c6s1e3}\n-\\frac{\\hslash^2}{2m}\\nabla^2\\psi(\\vec{r}) - \n\\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\\psi(\\vec{r}) = E\\psi(\\vec{r}).\n\\end{equation}\nThe spherical symmetry of the problem suggests that we should work in the \nspherical polar coordinate system. The Laplacian in these coordinates is\n\\begin{equation}\\label{c6s1e4}\n\\nabla^2 = \\frac{1}{r^2}\\frac{\\partial}{\\partial r}\n\\left(r^2\\frac{\\partial}{\\partial r}\\right) + \n\\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\n\\left(\\sin\\theta\\frac{\\partial}{\\partial\\theta}\\right) + \n\\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2}{\\partial\\phi^2}\n\\end{equation}\nThe equation \\eqref{c6s1e3} is solved using the method of `separation of \nvariables'. We write\n\\begin{equation}\\label{c6s1e5}\n\\psi(\\vec{r}) = \\psi(r, \\theta, \\phi) = R(r)\\Theta(\\theta)\\Phi(\\phi)\n\\end{equation}\nso that equation \\eqref{c6s1e3} becomes\n\\begin{eqnarray}\n-\\frac{\\hslash^2}{2m}\\left[\n\\frac{\\Theta\\Phi}{r^2}\\frac{d}{dr}\\left(r^2\\frac{dR}{dr}\\right) +\n\\frac{R\\Phi}{r^2\\sin\\theta}\\frac{d}{d\\theta}\n\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) + \n\\frac{R\\Theta}{r^2\\sin^2\\theta}\\frac{d^2\\Phi}{d\\phi^2}\\right] &=& \\nonumber \\\\ \n\\left(E + \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\\right)R\\Theta\\Phi & & \n\\label{c6s1e6}\n\\end{eqnarray}\nMultiplying both sides by\n\\[\n\\frac{r^2\\sin^2\\theta}{R\\Theta\\Phi}\n\\]\nand rearranging a bit, we get\n\\begin{equation}\\label{c6s1e7}\n\\frac{\\sin^2\\theta}{R}\\frac{d}{dr}\\left(r^2\\frac{dR}{dr}\\right) +\n\\frac{\\sin\\theta}{\\Theta}\\frac{d}{d\\theta}\n\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) +\n\\frac{2m}{\\hslash^2}\\left(E + \\frac{e^2}{4\\pi\\epsilon_0 r}\\right)\nr^2\\sin^2\\theta =\n-\\frac{1}{\\Phi}\\frac{d^2\\Phi}{d\\phi^2}. \n\\end{equation}\nThe left hand side of this equation is a function of $r$ and $\\theta$ while\nthe right hand side depends on $\\phi$ alone. Therefore, each side must be equal\nto a constant, say $\\alpha$. In particular, we get\n\\begin{equation}\\label{c6s1e8}\n\\frac{1}{\\Phi}\\frac{d^2\\Phi}{d\\phi^2} = -\\alpha\n\\end{equation}\nor\n\\begin{equation}\\label{c6s1e9}\n\\frac{d^2\\Phi}{d\\phi^2} + \\alpha\\Phi = 0.\n\\end{equation}\nThis equation will have a periodic solution if $\\alpha > 0$ and an exponential\none if $\\alpha < 0$. The hydrogen atom is clearly periodic in $\\phi$. Therefore,\nwe can write\n\\begin{equation}\\label{c6s1e10}\n\\alpha = m_l^2\n\\end{equation} \nso that we get\n\\begin{equation}\\label{c6s1e11}\n\\frac{d^2\\Phi}{d\\phi^2} + m_l^2\\Phi = 0\n\\end{equation}\nand\n\\begin{equation}\\label{c6s1e12}\n\\frac{\\sin^2\\theta}{R}\\frac{d}{dr}\\left(r^2\\frac{dR}{dr}\\right) +\n\\frac{\\sin\\theta}{\\Theta}\\frac{d}{d\\theta}\n\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) +\n\\frac{2m}{\\hslash^2}\\left(E + \\frac{e^2}{4\\pi\\epsilon_0r}\\right)\nr^2\\sin^2\\theta = m_l^2.\n\\end{equation}\nThe solution of the equation \\eqref{c6s1e11} is\n\\begin{equation}\\label{c6s1e13}\n\\Phi(\\phi) = \\alpha_1 e^{im_l\\phi} + \\alpha_2 e^{-im_l\\phi},\n\\end{equation}\nwhere $\\alpha_1$ and $\\alpha_2$ are constants of integration. Since $\\Phi(\\phi)\n= \\Phi(\\phi + 2\\pi)$ $m_l$ must be an integer. We can therefore write the \nsolution \\eqref{c6s1e13} as just\n\\begin{equation}\\label{c6s1e14}\n\\Phi_{m_l}(\\phi) = \\alpha_1 e^{im_l\\phi}\n\\end{equation}\nas the other factor is automatically included in the first one. $m_l$ is called\nthe \\emph{magnetic quantum number} and it is an integer. In order to separate \nequation \\eqref{c6s1e12}, divide both sides by $\\sin^2\\theta$ and rearrange a \nbit to get\n\\begin{equation}\\label{c6s1e15}\n\\frac{1}{R}\\frac{d}{dr}\\left(r^2\\frac{dR}{dr}\\right) +\n\\frac{2m}{\\hslash^2}\\left(E + \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\\right)r^2 =\n-\\frac{1}{\\Theta\\sin\\theta}\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) +\n\\frac{m_l^2}{\\sin^2\\theta}.\n\\end{equation}\nOnce again we have a situation in which the left hand side of the equation \ndepends on one variable, $r$, and the right hand side on another, $\\theta$\nso that each side is a constant, say $\\beta$. Thus, we have\n\\begin{equation}\\label{c6s1e16}\n-\\frac{1}{\\Theta\\sin\\theta}\\frac{d}{d\\theta}\n\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) +\\frac{m_l^2}{\\sin^2\\theta} = \n\\beta\n\\end{equation}\nand\n\\begin{equation}\\label{c6s1e17}\n\\frac{1}{R}\\frac{d}{dr}\\left(r^2\\frac{dR}{dr}\\right) +\n\\frac{2m}{\\hslash^2}\\left(E + \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\\right)r^2 =\n\\beta.\n\\end{equation}\nWe will solve these equations in the following sections. And yet, before \nproceeding we notice that the energy $E$ is part of the $r$-equation. This \nindicates that the energy of an electron in the Hydrogen atom depends on $r$\nalone, in agreement with the Bohr model.\n\n\\section{The $\\theta$ and $r$ equations}\\label{c6s2}\nEquations \\eqref{c6s1e6} and \\eqref{c6s1e7} can be solved using the Frobenius\nseries solution method however the analysis is a bit labourious. We will,\ntherefore, only summarise it here. The solutions of \\eqref{c6s1e16} remain \nfinite as $\\theta \\rightarrow 0$ and $\\theta \\rightarrow \\pi$ only if $\\beta$\nis of the form $l(l+1)$ for a positive integer $l$. When $m_l = 0$, the \nsolutions of \\eqref{c6s1e16} are called Legendre polynomials. When $m_l \\le 0$,\nthey are required to be such that $-l \\le m_l \\le l$ and the corresponding\nsolutions are called associated Legendre polynomials. The product of the \nsolution of the $\\theta$ equation and \\eqref{c6s1e14} is called a spherical\nharmonic of order $l$ and $m_l$. Spherical harmonics were studied as solutions\nof Laplace equation since a century prior to the advent of quantum mechanics.\nThe Legendre polynomials for are denoted by $P_l(\\cos\\theta)$ and the associated\nLegendre polynomials by $P_l^{m_l}(\\cos\\theta)$. The spherical harmonics are\ndenoted by\n\\begin{equation}\\label{c6s1e18}\nY_{l, m_l}(\\theta, \\phi) = N_{lm_l}P_l^{m_l}(\\cos\\theta)\\Phi_{m_l}(\\phi).\n\\end{equation}\n$l$ is called the \\emph{orbital quantum number} and it restricts the values \n$m_l$ can take. Likewise, the solution of the $r$ equation can be written in \nterms of the associated Laguerre polynomials. The solutions exist for all \n$E \\ge 0$ but for $E < 0$, they exists only for the discrete set\n\\begin{equation}\\label{c6s1e19}\nE_n = -\\frac{me^4}{32\\pi^2 n^2\\hslash^2\\epsilon_0^2} = \n-\\frac{me^4}{8n^2h^2\\epsilon_0^2},\n\\end{equation}\nwhere $n \\ge 0$ is an integer and it is always greater than $l$. It is called\nthe \\emph{principal quantum number}.\n\nThus the three equations, one each for $r$, $\\theta$ and $\\phi$ give rise to the\nquantum numbers $n, l, m_l$ such that\n\\begin{eqnarray}\nn &\\ge& 0 \\label{c6s2e3} \\\\\nl &<& n \\label{c6s2e4} \\\\\n|m_l| &\\le& l \\label{c6s2e5}\n\\end{eqnarray}\nEquation \\eqref{c6s2e5} can be written in an equivalent form\n\\begin{equation}\\label{c6s2e6}\n-l \\le m_l \\le l.\n\\end{equation}\n\n\\subsection{Problem set 1}\n\\begin{enumerate}\n\\item Consider a thought experiment in which the electrostatic potential was of\nthe form $e^{-r}$. Which of the three quantum numbers introduced above would \nhave remained unchanged.\n\\item Show that there are $n^2$ electrons with principal quantum number $n$.\nYou may remember having learnt that this number is $2n^2$. The factor of $2$\nis missing in our analysis because we still have not take into account the spin\nof an electron.\n\\item Although the proton is $1836$ times heavier than an electron, it does get\naffected by the reaction of the electron. What would change in our analysis if\nwe want to take the proton's motion into account? (Hint: problem 4 in chapter\n\\ref{c3}.)\n\\end{enumerate}\n\n\\section{Quantization of angular momentum}\\label{c6s3}\nBohr's second postulate was about the quantization of the electron's angular \nmomentum. We will now show that it is possible to understand it in the framework\nof quantum mechanics. The angular momentum is an important dynamical variable\nin quantum mechanics with a rich theory which explains its quantization in a\nvery natural way. We will not discuss it in this course and instead restrict\nour analysis to hydrogen atom alone.\n\nSince $\\beta = l(l+1)$, we can rearrange equations \\eqref{c6s1e6} and \n\\eqref{c6s1e7} as \n\\begin{eqnarray}\n\\frac{1}{\\sin\\theta}\\frac{d}{d\\theta}\n\\left(\\sin\\theta\\frac{d\\Theta}{d\\theta}\\right) + \n\\left(\\frac{m_l^2}{\\sin^2\\theta} - l(l+1)\\right)\\Theta &=& 0 \\label{c6s3e1} \\\\\n\\frac{1}{r^2}\\frac{d}{dr}\\left(r\\frac{dR}{dr}\\right) + \\frac{2m}{\\hslash^2}\n\\left[\\left(E + \\frac{1}{4\\pi\\epsilon_0}\\frac{e^2}{r}\\right)\n- \\frac{l(l+1)\\hslash^2}{2mr^2}\\right]R &=& 0 \\label{c6s3e2}\n\\end{eqnarray}\nThe $r$-equation should ideally not have anything to do with the orbital motion.\nTherefore, the presence of the term $l(l+1)\\hslash^2/(2mr^2)$ is a bit \ndisconcerting. The total energy $E$ is the sum of the electron's potential\nenergy and kinetic energy. The former is $-e^2/(4\\pi\\epsilon_0 r)$, while the \nlatter can be written as the sum of $T_r$, the radial, and $T_o$, the orbital\nkinetic energies. We conjecture that the orbital kinetic energy is\n\\begin{equation}\\label{c6s3e3}\nT_o = \\frac{l(l+1)\\hslash^2}{2mr^2}\n\\end{equation}\nso that there is no dependence of the orbital motion on the $r$-equation. If\n$v_o$ is the orbital velocity then \n\\begin{equation}\\label{c6s3e4}\nT_o = \\frac{mv_o^2}{2}\n\\end{equation}\nso that from \\eqref{c6s3e3} and \\eqref{c6s3e4} we get\n\\begin{equation}\\label{c6s3e5}\nmv_or = \\sqrt{l(l+1)}\\hslash.\n\\end{equation}\nAlthough the angular momentum is not an integral multiple of $\\hslash$ as Bohr\nhad proposed, it is quantized nevertheless.\n\n\\section{Electron density}\\label{c6s4}\nThe squared modulus solution of \\eqref{c6s1e6} is the probability density \nfunction of finding an electron in the atom. Although the mathematical forms \nof the wave-function and its modulus are quite formidable their plots are quite\nfamiliar to us. The figure \\ref{c6f1} labels the probability densities by the\ntriple $(n, l, m_l)$ of the quantum numbers. Wave functions with different \nvalues of $l$ are called orbitals. The orbitals with $l = 0$ have a spherical \nsymmetry.  They are called s-orbitals. Observe the one with $n=2$. The orbital \nhas minumum, between two maxima of unequal sizes. The surfaces in which the \norbitals are zero are called nodal surfaces. Thus, the $2s$ orbital has a nodal \nsurface between the two maxima. The orbitals with $l = 1$ are called the p-\norbitals. They have two lobes separated by a nodal plane. The orbitals with \n$l = 2$ are called d-orbitals and those with $l = 3$ are called f-orbitals. \nThey have far more complicated shapes. Their shapes play an important role in \ninorganic chemistry, especially of the transition elements.\n\nThe diagram in figure \\ref{c6f1} also gives an expression for the wavefunction.\nThe variable $\\rho$ in it is the ratio $r/a_0$, where $a_0$ is the radius of the\nfirst Bohr orbit. The factor $e^{-\\rho}$ ensures that the wavefunction goes to\nzero away from the nucleus. The angular distribution of the orbitals is \ndetermined solely by the spherical harmonics and the radial distribution by the\nassociated Laguerre polynomials (and $e^{-\\rho}$).\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.20]{Hydrogen_Density_Plots}\n\\caption{Hydrogen orbitals credit: Wikipedia}\n\\label{c6f1}\n\\end{center}\n\\end{figure}\n\n\\subsection{Problem set 2}\n\\begin{enumerate}\n\\item Based on your understanding of the solutions of the $r, \\theta$ and \n$\\phi$ equations show that the $|\\psi|^2$ is independent of the azimuthal angle\n$\\phi$. How do you decide where the $z$-axis is?\n\\item The wavefunction for the $n=1, l=0, m_l=0$ is\n\\begin{equation}\\label{c6s3e6}\n\\psi_{1,0,0}(r,\\theta,\\phi) = \\frac{e^{-r/a_0}}{\\sqrt{\\pi}a_0^{3/2}}.\n\\end{equation}\nLet $P(r)$ be the probability density of finding an electron in the thin \nspherical shell with radii $r$ and $r + dr$. Then,\n\\begin{equation}\\label{c6s3e7}\nP(r) = \\int_0^{\\pi}\\int_0^{2\\pi}|\\psi_{1,0,0}^2|^2r^2\\sin\\theta d\\theta d\\phi.\n\\end{equation}\nShow that\n\\begin{equation}\\label{c6s3e8}\nP(r) = \\frac{4r^2 e^{-r/a_0}}{a_0^3}.\n\\end{equation}\nHence show that $P$ has a maximum at $r = a_0$, where $a_0$ is the radius of the\nfirst Bohr orbit.\n\\end{enumerate}\n", "meta": {"hexsha": "5046360d7c59b6b7ed34f9b3c61c31b1c9996f14", "size": 12904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "qm/modern-physics/notes/c6.tex", "max_stars_repo_name": "drameyjoshi/physics", "max_stars_repo_head_hexsha": "9d3360258bdd12bc3d981ae08c8358dff4b777b3", "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": "qm/modern-physics/notes/c6.tex", "max_issues_repo_name": "drameyjoshi/physics", "max_issues_repo_head_hexsha": "9d3360258bdd12bc3d981ae08c8358dff4b777b3", "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": "qm/modern-physics/notes/c6.tex", "max_forks_repo_name": "drameyjoshi/physics", "max_forks_repo_head_hexsha": "9d3360258bdd12bc3d981ae08c8358dff4b777b3", "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": 47.2673992674, "max_line_length": 80, "alphanum_fraction": 0.7260539368, "num_tokens": 4495, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7978962952401474}}
{"text": "\n\\subsection{Matrix square roots}\n\nFor a matrix \\(M\\), the square root \\(M^{\\dfrac{1}{2}}\\) is \\(A\\) where \\(AA=M\\).\n\nThis does not necessarily exist.\n\nSquare roots may not be unique.\n\nReal matrices may have no real square root.\n\n", "meta": {"hexsha": "cb6ba1f74f1a8cf6b298a65019d721113b739bd0", "size": 230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/02-04-matrixRoot.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/02-04-matrixRoot.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/02-04-matrixRoot.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.1666666667, "max_line_length": 81, "alphanum_fraction": 0.6826086957, "num_tokens": 62, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9407897558991952, "lm_q2_score": 0.847967764140929, "lm_q1q2_score": 0.7977593858365309}}
{"text": "\\lab{Lorenz Equations}{Lorenz Equations}\n% \\epigraph{\\textit{Chaos: When the present determines the future, but the approximate present does not approximately determine the future.}}{Edward Lorenz}\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\\subsection*{Plotting and Interacting}\nWe will be making interactive 3D plots using \\li{matplotlib}.\nPlease refer back to the \\textit{Introduction to Matplotlib} lab for tips and tricks to graphing 3D.\nBelow is some sample code to help you out.\n\n\\begin{lstlisting}\nfrom matplotlib import rcParams, pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nrcParams['figure.figsize'] = (16,10)     #Affects output size of graphs.\n'''\nCode up your X, Y, Z values\n'''\nfig = plt.figure()\nax = fig.gca(projection='3d')\nax.plot( X, Y, Z )    #Make sure X, Y, Z are same length.\n                      #Connect points (X[i], Y[i], Z[i]) for i in len(X)\nax.set_xlabel('X')\nax.set_ylabel('Y')\nax.set_zlabel('Z')\n\nax.set_xlim3d([min(X), max(X)])    #Bounds the axes nicely\nax.set_ylim3d([min(Y), max(Y)])\nax.set_zlim3d([min(Z), max(Z)])\n\nplt.show()\n\\end{lstlisting}\n\nBecause we are plotting in 3D, we are also interested in being able to interact with the plot and rotate it to analyze what our solutions are actually doing.\nTo facilitate this, \\li{matplotlib} has different backends which allow for various levels of control over what our graphs do.\nThese backends are accessed using \\li{matplotlib}'s \\li{switch_backend()} function with a call to whichever backend we want.\nYour computer may default to a backend which you can already interact with (try clicking your plot and rotating it to see).\nIf not, consider using 'qt5agg', 'qt4agg', nbagg', or 'tkagg' in the function call.\n\n\\begin{lstlisting}\nplt.switch_backend('qt5agg') # This backend opens the graph in a new window\n\\end{lstlisting}\n\n\\begin{warn}\nDo not run \\li{\\%matplotlib inline} with this code. You will crash your kernel.\n\\end{warn}\n\n\\begin{problem}\nSolve and graph the Lorenz equation by completing the code.\nInitialize the initial conditions with random values between $-15$ and $15$.\nFor this exercise, let $\\sigma=10$, $\\rho=28$, $\\beta=\\frac{8}{3}$.\nCompare to Figure \\ref{fig:Single_Lorenz}\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.integrate import odeint\n\ndef lorenz_ode(inputs, T):\n\t'''\n\tCode up the sytem of equations given\n\t'''\n\treturn Xprime, Yprime, Zprime\n\ndef solve_lorenx(init_cond, time=10):\n\tT = np.linspace(0, time, time*100)\t#initialize time interval for ode\n\t'''\n\tUse odeint in conjuction with lorenz_ode and the time interval T\n\tTo get the X, Y, and Z values for this system.\n\tYou will need to transpose the output of odeint to graph it correctly.\n\t'''\n \treturn X, Y, Z\n\nsigma = 'value'\nrho = 'value'\nbeta = 'value'\ninit_cond = [x0, y0, z0]\n\nX, Y, Z = solve_lorenz(init_cond, 50)\n'''\nCode to graph\n'''\n\\end{lstlisting}\n\n\\end{problem}\n\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/Single_Lorenz.pdf}\n\\caption{Approximate solution to the Lorenz equation with random initial conditions}\n\\label{fig:Single_Lorenz}\n\\end{figure}\n\n\\section*{Basin of Attraction}\nNotice in the first problem that the solution tended to a 'nice' region.\nThis region is a basin of attraction, and the set of numerical values towards which a system will converge to is an \\textbf{attractor}.\nConsider what happens when we change up the initial conditions.\n\\begin{problem}\nChange your code to plot $n$ different solution using different random initial conditions.\nProduce a plot with $n=3$ different solutions.\nCompare to Figure \\ref{fig:Multiple_Lorenz}\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/Multiple_Lorenz.pdf}\n\\caption{Multiple solutions to the Lorenz equation with random initial conditions}\n\\label{fig:Multiple_Lorenz}\n\\end{figure}\n\n\\section*{Chaos}\n\nChaos in dynamical systems connotes a high sensitivity to initial conditions.\nSmall differences in initial conditions can yield widely diverging outcomes for these systems.\nDespite having equations that completely determine the future behavior of systems, there is no way to determine where a system will be time $t$ down the road without running through the full interval.\nIn other words, these systems are unpredictable.\n\n\\begin{problem}\nChange the code above so that it initializes one set of initial conditions and creates a second set of initial conditions by adding the array \\li{np.random.randn(3)*(1E-10)}.\nThis will represent a small perturbation in the initial conditions. Make sure the \\li{time} variable is large enough to notice a difference in the two solutions.\nPlot both solutions together.\nRefer to Figure \\ref{fig:perturbed_lorenz}\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/perturbed_lorenz.pdf}\n\\caption{Two solutions to the Lorenz equation with perturbed initial conditions}\n\\label{fig:perturbed_lorenz}\n\\end{figure}\n\nYou may be wondering if your code was even correct.\nYou could distinctly see the two curves because there was some separation of color, but who is to say that the two solutions moved away from each other only slightly as time went on.\nOur next task will be to \\textit{animate} this beast.\n\n\\section*{Intro to Animation}\nLet's get you a degree in Computer Animation.\nYou will be provided with some code that helps with animation.\nPlease feel free to play around and try to animate different things.\nAgain, refer to the \\textit{Introduction to Matplotlib} lab for additional help.\n\nWe will call on \\li{matplotlib.animate} to assist in animation. Import the following:\n\\begin{lstlisting}\nfrom matplotlib.animation import FuncAnimation\n\\end{lstlisting}\nFollow these steps for setting up an animation.\n\\begin{itemize}\n\\item Calculate all data needed for the animation (not necessary in some cases, but it simplifies things).\n\\item Define a figure explicitly with \\li{plt.figure()} and set its window boundaries.\n\\item Draw empty objects that can be altered dynamically.\n\\item Define a function to update the drawing objects.\n\\item make a call to \\li{FuncAnimation()} which will start the animation.\n\\end{itemize}\n\\li{FuncAnimation()} accepts the figure to be animated, the function that updates the figure, the number of frames to show before repeating, and how fast to run the animation (lower number $=$ faster).\n\nCheck out the sample code for animating two 2D objects simultaneously.\n\\begin{lstlisting}\nfrom matplotlib.animation import FuncAnimation\n\ndef sine_cos_animation():\n\t#Calculate the data to be animated\n\tx = np.linspace(0, 2*np.pi, 200)[:-1]\n\ty1, y2 = np.sin(x), np.cos(x)\n\t\n\t#Create a figure and set the window boundaries\n\tfig = plt.figure()\n\tplt.xlim(0, 2*np.pi)\n\tplt.ylim(-1.2, 1.2)\n\t\n\t#Initiate empty lines of the correct dimension\n\tsin_drawing, = plt.plot([], [])\n\tcos_drawing, = plt.plot([], [])\t#note the comma after the variable name\n\t\n\t#Define a function that updates each line\n\tdef update(index):\n\t\tsin_drawing.set_data(x[:index], y1[:index])\n\t\tcos_drawing.set_data(x[:index], y2[:index])\n\t\treturn sin_drawing, cos_drawing,\n\t\n\ta = FuncAnimation(fig, update, frames=len(x), interval=10)\n\tplt.show()\n\\end{lstlisting}\n\n\\begin{warn}\nThe above animation code works great for 2D animations, but \\li{set_data()} is only good for 2D. When you want to animate in 3D, you will need an extra empty list in \\li{plt.plot()} and a call to \\li{set_3d_properties()} in the \\li{update(index)} function.\n\\end{warn}\n\n\\section*{Animate}\nYou now know how to plot the Lorenz equation, how to plot multiple equations, and even how to animate (yay you, you're a star) simple plots.\nIt's time to put all your know-how to good use.\n\n\\begin{problem}\nAnimate the solutions of the Lorenz equation for an initial set of conditions and the perturbed conditions on the same plot.\nTo make the animation go faster, decrease the \\li{interval} value in the \\li{FuncAnimation()} call.\nIt will take several seconds before the curves split, so be patient.\n\\end{problem}\n\nIf our system is very chaotic, then even small round off errors in your computer can lead to drastically different solutions.\n\n\\begin{problem}\nNow set one initial condition.\nUse \\li{odeint} to solve the system, but use the arguments \\li{atol=1E-14}, \\li{rtol=1E-12}, and then again with \\li{atol=1E-15}, \\li{rtol=1E-13}.\nAnimate both solutions on the same plot.\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, experimentally it can be verified that $\\lambda \\approx .9$.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/semilog.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\nSuppose we want tol find the Lyapunov exponent for the Lorenz System.\nStart by importing \\li{linalg} and \\li{linregress} modules from \\li{scipy}.\n\\begin{lstlisting}\nfrom scipy import linalg as la\nfrom scipy.stats import linregress\n\\end{lstlisting}\nTo get a good estimate of the Lyapunov exponent, we want to make sure our initial solution already lies on the attractor.\nTo do this, choose some random initial conditions, run your \\li{solve_lorenz} function, then pick out the final coordinates.\nLet these coordinates be the starting point for our next system.\n\nNext perturb the conditions slightly.\nFind the solution curve using these two sets of initial coordinates and then calculate the \\li{norm} between the solution at each point.\nPlot the norm using \\li{plt.semilogy(time, norm)}.\n\nFinally we want to calculate the exponential line fitted to the data.\nBecause we are using the semilog plot, we can find this line as follows:\n\\begin{itemize}\n\\item take the \\li{log} of the norms.\n\\item use \\li{linregress()} to compute the linear regression of the log of the norms.\n\\item take the \\li{exp} of the linear regression to turn back into an exponential regression.\n\\item plot the exponential regression using \\li{plt.semilogy()} (your solution will be a line)\n\\end{itemize}\n\n\n\\begin{problem}\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": "66623fc460ead84024e2cc2ba8fc5f56954eb031", "size": 13016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/LorenzEquations/LorenzEquations.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/LorenzEquations/LorenzEquations.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/LorenzEquations/LorenzEquations.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": 48.0295202952, "max_line_length": 256, "alphanum_fraction": 0.7697449293, "num_tokens": 3210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.797704630404987}}
{"text": "\\lab{Image Compression (SVD)}{SVD}\n\n\\objective{Explore the SVD as a method of image compression}\n\\label{lab:SVD}\n\nIn this lab, we are going to explore how the SVD can be used to compress image data.\nRecall that the SVD is a decomposition of an $m \\times n$ matrix $A$ of rank $r$ into the product $A = U \\Sigma V^H$, where $U$ and $V$ are unitary matrices having dimensions $m \\times m$ and $n \\times n$, respectively, and $\\Sigma$ is an $m \\times n$ diagonal matrix.\n\\begin{equation*}\n\\Sigma = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_r,0,\\ldots,0)\n\\end{equation*}\nwhere $\\sigma_1 \\geq \\sigma_2 \\geq \\ldots \\geq \\sigma_r > 0$ are the singular values of $A$.\nUpon closer inspection, we see that we can write\n\\begin{equation*}\nU = \\begin{pmatrix}U_1 & U_2\\end{pmatrix}, \\quad \\Sigma =\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}, \\quad V =\n\\begin{pmatrix}V_1 & V_2\\end{pmatrix},\n\\end{equation*}\nwhere $U_1$ and $V_1$ have dimensions $m\\times r$ and $n\\times r$ respectively and $\\Sigma_r$ is the $r\\times r$ diagonal matrix of (nonzero) singular values.\nMultiplying this out yields the reduced form of the SVD\n\\begin{equation*}\nA =\n\\begin{pmatrix}U_1 & U_2\\end{pmatrix}\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}\n\\begin{pmatrix}V^H_1 \\\\ V^H_2\\end{pmatrix} =\nU_1 \\Sigma_r V_1^H\n\\end{equation*}\n\n\\subsection*{Low rank data storage}\nIf the rank of a given matrix is significantly smaller than its dimensions, the reduced form of the SVD offers a way to store $A$ with less memory.\nWithout the SVD, an $m\\times n$ matrix requires storing $mn$ values.\nBy decomposing the original matrix into the SVD reduced form, $U_1$, $\\Sigma_r$ and $V_1$ together require $mr+r+nr$ values.\nThus if $r$ is much smaller than both $m$ and $n$, we can obtain considerable efficiency.\nFor example, suppose $m=100$, $n=200$ and $r=20$.\nThen the original matrix would require storing $20,000$ values whereas the reduces form of the SVD only requires storing $6020$ values.\n\n\\subsection*{Low rank approximation}\nThe reduced form of the SVD also provides a way to approximate a\nmatrix 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_{\\widehat A} = \\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 the singular values.\nIn Figure \\ref{fig:hubble} we present an image and its singular values.\nMatrix rank is on the x-axis and the singular values are the y-axis.\nNote that SVD orders the singular values from greatest to least.\nThe greatest singular values contribute most to the image while the smallest singular values hardly contribute anything to the final approximation.\nBy looking at the graph in Figure \\ref{fig:svals_plot} we can have a rough idea of how many singular values we need to preserve to have a good approximation of $A$.\nThe matrix rank of the image below is $670$.\nHowever, as the plot shows, we could easily approximate the image using only the first half of the singular values.  In Figure \\ref{fig:rankvalues}, we can see different rank approximations of the image in Figure \\ref{fig:hubble}.\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{hubble_red}\n\\caption{NGC 3603 (Hubble Space Telescope).}\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.}\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]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank1.jpg}\n\\caption{Rank 1 approximation}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank14.jpg}\n\\caption{Rank 14 approximation}\n\\end{subfigure}\n\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank27.jpg}\n\\caption{Rank 27 approximation}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n\\centering\n\\includegraphics[width=\\textwidth]{rank40.jpg}\n\\caption{Rank 40 approximation}\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 \\li{scipy.linalg} module has a convenient method to calculate the SVD of a given matrix. We can use\nthis method to create a lower-rank approximation of a given matrix. Execute the following code.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.linalg import svd, norm\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,Vt = svd(A, full_matrices=False)\n\\end{lstlisting}\nIn that last line of code, we included the keyword argument \\li{full_matrices=False} to calculate the\nreduced SVD rather than the full SVD. The arrays \\li{U} and \\li{Vt} correspond to the matrices\n$U_1$ and $V_1^H$ discussed earlier in the lab. The array \\li{s} simply 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} (in this\nexample, we have a rank 4 matrix). \n\nNext, we calculate a rank 3 approximation. Instead of setting the smallest singular value to 0, we simply\nomit it from the calculation. Note that we also omit the last column of \\li{U} and last row of \\li{Vt}, as\nthey correspond to the smallest eigenvalue. \n\\begin{lstlisting}\n>>> S = np.diag(s[:-1])\n>>> Ahat = U[:,:-1].dot(S).dot(Vt[:-1,:])\n>>> 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. More\nprecisely, $\\widehat A$ is the best rank 3 approximation of $A$ with respect to both the induced 2-norm and\nthe Frobenius norm. \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.\n\\end{problem}\n\n\\subsection*{Application to Imaging}\nEnter the following into IPython (note that any image you might have will work):\n\\begin{lstlisting}\n>>> import matplotlib.pyplot as plt\n>>> X = plt.imread('fingerprint.png')[:,:,0].astype(float)\n>>> X.nbytes      #number of bytes needed to store X\n>>> plt.imshow(X)\n>>> plt.show()\n\\end{lstlisting}\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, $n$ represents the desired rank of the output.\n\\begin{lstlisting}\n>>> n = 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}\nRecall that the error between the best rank $s$ approximation $\\widehat{A_s}$ to $A$ with respect to the induced \n2-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\n\\begin{problem}\nSometimes there is not enough available bandwidth to transmit a full resolution photograph.\nYou aim to reduce the amount of data that needs to be transmitted from a remote location such that loss of image detail is minimal, but the amount of data that needs to be sent has reduced as much as possible.\nWrite 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).\n\\end{problem}\n", "meta": {"hexsha": "03ac987fbb3d282d91cb0bfd51252e1373cd4c8d", "size": 8268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/SVD/SVD.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 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/SVD/SVD.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/SVD/SVD.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 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": 49.5089820359, "max_line_length": 268, "alphanum_fraction": 0.7408079342, "num_tokens": 2416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.9219218380728936, "lm_q1q2_score": 0.7976689829622514}}
{"text": "% Appendix\n\n% Thomas, 2/2 -- feel free to delete this\n\\section{More category theory: properties of morphisms}\n\nAs we have seen, limits and colimits allow us ways to construct new objects, morphisms, and universal properties, over indexing diagrams. In particular we might be interested in relating certain properties of morphisms in a category to induced morphisms produced out of a colimit. As a motivating example, consider the following question.\n\n\\begin{question} Let $I$ be a small indexing diagram, and let $\\alpha,\\beta: I \\to \\Set$ denote two functors, and let $A_i := \\alpha(i)$ and $B_i = \\beta(i)$ denote the sets at each object $i\\in I$. Suppose we have a natural transformation between these functors, consisting of functions $f_i \\colon A_i \\to B_i$ for each $i$. \\textit{If each $f_i$ is injective, is it true that the induced map $f\\colon \\colim \\alpha \\to \\colim \\beta$ is injective as well?}\n\\end{question}\n\nIt turns out the answer to this diagram depends on the shape of $I$. It is true if the colimits are \\textit{filtered}, which is a condition on the indexing diagram which tells us that it interacts well with finite limits. This motivates the more broad question of what properties of morphisms are preserved under limits and colimits. In general this is a hard question, but it will be important when we investigate fibrations and cofibrations in the category of topological spaces.\n\n\n\\subsection{Stability and closure definitions}\n\n\n\nLet $\\mathscr{C}$ be a category, not necessarily assumed to be locally small. We start with an easy definition.\n\n\\begin{definition}\\label{def:closed-under-pullback} Let \\textbf{P} be a property of morphisms in $\\mathscr{C}$. We say that \\textbf{P} is \\textit{closed under composition} if, anytime we have two composable morphisms $f: x \\to y$ and $g: y \\to z$, if both $f$ and $g$ have property \\textbf{P}, then the composite $g\\circ f$ does as well.\n\\end{definition}\n\n\n\\begin{definition}\\label{def:2-out-of-3} Let \\textbf{P} be a property of morphisms in $\\mathscr{C}$. We say that \\textbf{P} \\textit{satisfies 2-out-of-3} if for every commutative diagram of the form\n\\[ \\begin{tikzcd}\n    A\\rar[\"f\" above]\\ar[dr,\"g\\circ f\" below left] & B\\dar[\"g\" right]\\\\\n     & C,\\\\\n\\end{tikzcd} \\]\nif any two of $f$, $g$, or $g\\circ f$ have property \\textbf{P}, then the third does as well.\n\\end{definition}\n\n\n\\begin{exercise} $\\ $\n\\begin{enumerate}\n    \\item Prove that isomorphisms satisfy 2-out-of-3.\n    \\item In the category $\\Set$, prove that injections and surjections do not satisfy 2-out-of-3.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{definition}\\label{def:cancellative-properties} Let \\textbf{P} be a property of morphisms.\n\\begin{enumerate}\n    \\item We say that \\textbf{P} is a \\textit{left cancellative property} if any time $g\\circ f$ has property \\textbf{P}, this implies that $f$ has property \\textbf{P} as well.\n    \\item We say that \\textbf{P} is a \\textit{right cancellative property} if any time $g\\circ f$ has property \\textbf{P}, this implies that $g$ has property \\textbf{P} as well.\n\\end{enumerate}\n\\end{definition}\nAs a warning to the reader, \\textbf{the terminology in} \\autoref{def:cancellative-properties} \\textbf{is not standard}, although we would advocate for its usage. The notion of left cancellative properties is referred to as (CANC) in \\cite[Appendix~C]{GortzWedhorn}, and has many examples in algebraic geometry (e.g. immersions, locally of finite type, purely inseparable, quasi-separated, separated). Many other examples occur under hypotheses on $g$, e.g. if it is separated or unramified. In a broader categorical context, we will see that mono-(resp. epi-)morphisms are left (resp. right) cancellative. \n\n\n\\begin{definition}\\label{def:closed-under-retracts} Let \\textbf{P} be a property of morphisms. We say that \\textbf{P} is \\textit{closed under retracts} if, for any $f: A \\to B$ with property \\textbf{P}, and any $g: X \\to Y$ fitting into a commutative diagram\n\\[ \\begin{tikzcd}\n    X\\ar[rr,bend left=30,\"\\id_X\" above]\\dar[\"g\" left]\\rar & A\\dar[\"f\"]\\rar & X\\dar[\"g\" right]\\\\\n    Y\\rar\\ar[rr,bend right=30,\"\\id_Y\" below] & B\\rar & Y,\n\\end{tikzcd} \\]\nwe have that $g$ has property \\textbf{P} as well.\n\\end{definition}\n\n\n\n\n\n\n\n\\begin{definition} Let \\textbf{P} be a property of morphisms. Then we say that \\textbf{P} is \\textit{stable under pullback} (often also called \\textit{stable under base change}) if for any pullback diagram of the form\n\\[ \\begin{tikzcd}\n    C\\rar[\"j\" above]\\dar[\"k\" left]\\pb & D\\dar[\"f\" right]\\\\\n    A\\rar[\"g\" below] & B,\\\\\n\\end{tikzcd} \\]\nif $f$ has property \\textbf{P}, then $k$ has property \\textbf{P} as well. Dually, we say that \\textbf{P} is \\textit{stable under pushout} if for any pushout diagram of the form\n\\[ \\begin{tikzcd}\n    C\\rar[\"j\" above]\\dar[\"k\" left] & D\\dar[\"f\" right]\\\\\n    A\\rar[\"g\" below] & B\\po,\\\\\n\\end{tikzcd} \\]\nif $k$ has property \\textbf{P}, then $f$ has property \\textbf{P} as well.\n\\end{definition}\n\n\\begin{exercise}\\label{exer:injective-stable-under-pullback} $\\ $\n\\begin{enumerate}\n    \\item Prove that isomorphisms are always stable under pushout and pullback.\n    \\item Prove in the category $\\Set$ that injective functions are stable under pullback, and surjective functions are stable under pushout.\n\\end{enumerate}\n\\end{exercise}\n\n\nThus far we have discussed closure properties internal to a category. We might wonder how properties translate across functors.\n\n\\begin{definition}\\label{def:functor-preserve-reflect-properties} Let $F: \\mathscr{C} \\to \\mathscr{D}$ be a functor, and let \\textbf{P} be a property of morphisms.\n\\begin{enumerate}\n    \\item We say that $F$ \\textit{preserves property} \\textbf{P} if any time $f: x \\to y$ is a morphisms in $\\mathscr{C}$ with property \\textbf{P}, we have that $Ff: Fx \\to Fy$ has property \\textbf{P} as well.\n\n    \\item We say that $F$ \\textit{reflects property} \\textbf{P} if any tie $f:x \\to y$ is a morphism in $\\mathscr{C}$, if $Ff: Fx \\to Fy$ has property \\textbf{P}, then $f$ must necessarily have property \\textbf{P} as well.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark} We have that $F$ always preserves isomorphisms (this is part of the property of being a functor). It is \\textit{not true} that $F$ needs to reflect isomorphisms. For example if $X$ is a topological space with a non-trivial topology, then the map $\\id : X \\to X_{\\text{disc}}$ from $X$ to itself with the discrete topology is not a homeomorphism, however its underlying set map is a bijection. (That is, the forgetful functor $\\Top \\to \\Set$ does not reflect isomorphisms).\n\\end{remark}\n\n\\begin{exercise} If $F$ is full and faithful, it reflects isomorphisms.\n\\end{exercise}\n\n\n\n\n\\subsection{Monomorphisms and epimorphisms}\n\n\\autoref{exer:injective-stable-under-pullback} generalizes, as the notions of being injective and surjective in $\\Set$ are equivalent to more abstract categorical conditions. We begin by generalizing injections.\n\n\\begin{definition}\\label{def:monomorphism} Let $\\mathscr{C}$ be a category. Then a morphism $f: x \\to y$ is a \\textit{monomorphism} if any of the following equivalent conditions hold:\n\\begin{enumerate}\n    \\item For any pair of morphisms $g,h : z \\to x$ so that $f\\circ g = f\\circ h$, that is:\n    \\begin{align*}\n        z \\rightrightarrows x \\to y,\n    \\end{align*}\n    we have that $g = h$. (Another way of phrasing this is that $f$ is \\textit{left cancellable}).\n\n    \\item The following diagram is a pullback:\n\\[ \\begin{tikzcd}\n    x\\rar[\"\\id_x\" above]\\dar[\"\\id_x\" left]\\pb & x\\dar[\"f\" right]\\\\\n    x\\rar[\"f\" below] & y.\n\\end{tikzcd} \\]\n\nIf $\\mathscr{C}$ is locally small, there is another equivalent condition:\n\\end{enumerate}\n\n\n\\begin{enumerate}\n\\setcounter{enumi}{2}\n    \\item The induced functor $\\Hom_\\mathscr{C}(-,x) \\xto{f\\circ -} \\Hom_\\mathscr{C}(-,y)$ is a natural injection, meaning that $\\Hom_\\mathscr{C}(z,x) \\xto{f\\circ -} \\Hom_\\mathscr{C}(z,y)$ is an injective function for any $z\\in \\mathscr{C}$.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{exercise} Prove that the definitions in \\autoref{def:monomorphism} are equivalent.\n\\end{exercise}\n\n\\begin{example} We have that isomorphisms and equalizers are always monomorphisms. Any morphism from a terminal object is a monomorphism.\n\\end{example}\n\n\\begin{exercise} \\textit{(Closure properties of monomorphisms)}\n\\begin{enumerate}\n    \\item Monomorphisms are closed under composition\n    \\item Monomorphisms are stable under pullback\n    \\item Monomorphisms are left cancellative.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\\label{exer:left-adjoints-preserve-monomorphisms} \\textit{(Left adjoints preserve monomorphisms)} Let $F: \\mathscr{C} \\rightleftarrows \\mathscr{D} : G$ be an adjunction betweem locally small categories. Then if $f: x\\to y$ is a monomorphism in $\\mathscr{C}$, we have that $Ff : Fx \\to Fy$ is a monomorphism in $\\mathscr{D}$. (Hint: use the natural bijection associated to the adjunction, together with \\autoref{def:monomorphism}, Definition (iii)).\n\\end{exercise}\n\nThere is a dual notion, called an \\textit{epimorphism}.\n\n\\begin{definition}\\label{def:epimorphism} Let $\\mathscr{C}$ be a category. Then a morphism $f: x \\to y$ is a \\textit{epimorphism} if any of the following equivalent conditions hold:\n\\begin{enumerate}\n    \\item For any pair of morphisms $g,h : y \\to z$ so that $g\\circ f = h\\circ f$, that is:\n    \\begin{align*}\n         x \\to y \\rightrightarrows z,\n    \\end{align*}\n    we have that $g = h$. (Another way of phrasing this is that $f$ is \\textit{right cancellable}).\n\n    \\item The following diagram is a pushout:\n\\[ \\begin{tikzcd}\n    x\\rar[\"f\" above]\\dar[\"f\" left] & y\\dar[\"\\id_y\" right]\\\\\n    y\\rar[\"\\id_y\" below] & y\\po.\n\\end{tikzcd} \\]\n\nIf $\\mathscr{C}$ is locally small, there is another equivalent condition:\n\\end{enumerate}\n\n\n\\begin{enumerate}\n\\setcounter{enumi}{2}\n    \\item The induced functor $\\Hom_\\mathscr{C}(y,-) \\xto{-\\circ f} \\Hom_\\mathscr{C}(x,-)$ is a natural injection, meaning that $\\Hom_\\mathscr{C}(y,z) \\xto{-\\circ f} \\Hom_\\mathscr{C}(x,z)$ is an injective function for any $z\\in \\mathscr{C}$.\n\\end{enumerate}\n\\end{definition}\n\nEpimorphisms satisfy all the dual properties to monomorphisms.\n\n\\begin{exercise}\\label{exer:properties-of-epimorphisms} \\textit{(Properties of epimorphisms)}\n\\begin{enumerate}\n    \\item Every isomorphism is an epimorphism, as is every coequalizer.\n    \\item Any morphism to an initial object is an epimorphism.\n    \\item Epimorphisms are closed under composition.\n    \\item Epimorphisms are stable under pushout.\n    \\item Epimorphisms are right cancellative. \n    \\item Right adjoints preserve epimorphisms.\n\\end{enumerate}\n\\end{exercise}\n\nAs we have hinted at, monomorphisms and epimorphisms generalize the notions of injectivity and surjectivity in $\\Set$. We can ask then whether categories which we think of as ``sets with extra data'' have the property that their monomorphisms are just those underlain by injections. Phrased differently, does the forgetful functor $U: \\mathscr{C} \\to \\Set$ reflect mono and epimorphisms? This turns out to be true in some generality, but we must first make rigorous what it means to be a ``set with extra structure.''\n\n\\begin{definition}\\label{def:concrete-category} A \\textit{concrete category} is a locally small category $\\mathscr{C}$, together with faithful functor to sets $U : \\mathscr{C} \\to \\Set$. We think of this functor as ``forgetting'' the data.\n\\end{definition}\n\n\\begin{examples}\\label{exs:concrete-categories} The following categories are concrete: $\\Grp$, $\\Poset$, $\\Vect$, $\\Top$, \\todo{add more}.\n\\end{examples}\n\n\n\\begin{proposition} Any faithful functor reflects monomorphisms and epimorphisms.\n\\end{proposition}\n\nThus we see that all the categories in \\autoref{exs:concrete-categories} have the property that their monomorphisms are underlying injections, and epimorphisms are underlying surjections. We summarize this in the following table.\n\n\\begin{table}[h]\n    \\centering\n    \\caption{Examples of monomorphisms and epimorphisms}\n    \\begin{tabular}{ p{2cm} l  p{5cm}  p{8cm} }\n        \\toprule\n\\textbf{Category}      \n& \\textbf{Monomorphisms}   \n& \\textbf{Epimorphisms} \\\\\\midrule\n$\\Set$ & injections & surjections \\\\\\hline\n\n$\\Grp$ & underlying injections & underlying surjections  \\\\\\hline\t \\bottomrule\n    \\end{tabular}\n\\end{table}\n\n\n\\begin{counterexample} We have that the inclusion $\\Z \\hookto \\mathbb{Q}$ is an epimorphism in the category $\\Ring$ of unital rings. This tells us that the forgetful functor $U: \\Ring \\to \\Set$ is \\textit{not} faithful.\n\\end{counterexample}\n\n\\subsection{Properties of morphisms can induce properties of objects}\n\nSuppose we have a commutative diagram of the form\n\\[ \\begin{tikzcd}\n    A\\rar[\"i\" above]\\ar[dr,\"\\id_A\" below left] & B\\dar[\"r\" right]\\\\\n     & A.\n\\end{tikzcd} \\]\nIn this case we say the object $A$ is a \\textit{retract} of $B$. We can ask about what properties of objects descend to their retracts, motivating the following definition.\n\n\\begin{definition}\\label{def:property-objects-closed-under-retracts} Let \\textbf{O} be a property of objects in $\\mathscr{C}$ (we can just think of this as some subclass of the class of objects). Then we say that \\textbf{O} is \\textit{closed under retracts} if, any time $B \\in \\mathbf{O}$, and $A$ is a retract of $B$, we have that $A\\in \\mathbf{O}$ as well.\n\\end{definition}\n\nWe can ask about how a property of objects could potentially be related to a property of morphisms. In particular, we could ask about how properties of morphisms might induce properties of objects. Our perspective on this is stolen from algebraic geometry, in which a scheme is defined to have a property if and only if its structure morphism has the associated property. In the world of schemes and varieties, there basically don't exist properties for objects, only properties for morphisms. This is a feature of life with a terminal object. In many situations, such as topological spaces, we have the same luxury.\n\n\\begin{terminology}\\label{term:inducing-properties-of-objects-from-properties-of-morphisms} Let $\\mathscr{C}$ be a category with a terminal object $\\ast$, and let \\textbf{P} be a property of morphisms in $\\mathscr{C}$. Then we have an \\textit{induced property of objects} \\textbf{O}, defined by saying that $X\\in \\mathbf{O}$ if the unique morphism $X \\xto{!} \\ast$ lies in \\textbf{P}.\n\\end{terminology}\n\n\\begin{exercise} Let $\\mathscr{C}$ be a category with a terminal object. Prove that if \\textbf{P} is a property of morphisms closed under retracts in the sense of \\autoref{def:closed-under-retracts}, then the induced property of objects is closed under retracts in the sense of \\autoref{def:property-objects-closed-under-retracts}.\n\\end{exercise}\n\n\\begin{remark} The passage from fibrations to fibrant objects follows \\autoref{term:inducing-properties-of-objects-from-properties-of-morphisms}.\n\\end{remark}\n\n\n\n\n\n\n\\subsection{Preservation properties under limits and colimits}\n\n\\begin{definition}\\label{def:naturally-P} Let $I$ be an indexing category, let $\\mathscr{C}$ be a category, and let \\textbf{P} be a property of morphisms in $\\mathscr{C}$. Let $f_1, f_2 : I \\to \\mathscr{C}$ be two diagrams in $\\mathscr{C}$, and let $\\eta: f_1 \\Rightarrow f_2$ be a natural transformation between them. We say that $\\eta$ \\textit{has property} \\textbf{P} \\textit{levelwise} (or \\textit{has property} \\textbf{P} \\textit{naturally}) if each of the components $\\eta_c : f_1(c) \\to f_2(c)$ has property \\textbf{P}. As some examples:\n\\begin{enumerate}\n    \\item a \\textit{natural isomorphism} is a natural transformation whose components are isomorphisms.\n    \\item a \\textit{natural monomorphism} is a natural transformation whose components are monomorphisms.\n\\end{enumerate}\n\\end{definition}\n\n\n\n\\begin{definition}\\label{def:colimit-preserve-property} Let $I$ be an indexing category, and let \\textbf{P} be a property of morphisms in $\\mathscr{C}$. We say that \\textbf{P} \\textit{is preserved under} $I$\\textit{-shaped colimits} if, any time we have a natural transformation $\\eta: f_1 \\Rightarrow f_2$ which has property \\textbf{P} levelwise, we have that the induced map\n\\begin{align*}\n    \\colim_I(f_1) \\to \\colim_I(f_2)\n\\end{align*}\nis in \\textbf{P} as well (assuming both colimits exist). Dually we have a notion of preservation under $I$-shaped limits.\n\\end{definition}\n\n\\begin{example} We have that isomorphisms are preserved under arbitrary limits and colimits.\n\\end{example}\n\n\\begin{example} If $I = \\bullet\\ \\bullet$ is a discrete category on two points, we say that a property \\textbf{P} is \\textit{preserved under products} (resp. \\textit{coproducts}) if it is preserved under $I$-shaped limits (resp. colimits).\n\\end{example}\n\n\\begin{proposition}\\label{prop:monos-preserved-under-products} We have that\n\\begin{enumerate}\n    \\item Monomorphisms are preserved under products\n    \\item Epimorphisms are preserved under coproducts.\n\\end{enumerate}\n\\end{proposition}\n\\begin{proof} We will prove (1) and remark that (2) follows formally. Let $f: A \\to B$ and $g: C \\to D$ be monomorphisms. Then assuming their products exist, there is an induced map $(f \\times g) : A \\times C \\to B \\times D$. We claim that this is a monomorphism as well. Via \\autoref{def:monomorphism}, we can restate the statement that $f$ and $g$ are monomorphisms into the statement that these diagrams are pullbacks\n\\[ \\begin{tikzcd}\n    A\\rar\\dar\\pb & A\\dar\\\\\n    A\\rar & B\n\\end{tikzcd} \\quad\\quad  \\begin{tikzcd}\n    C\\rar\\dar\\pb & C\\dar\\\\\n    C\\rar & D.\n\\end{tikzcd} \\]\nSince limits commute, we have that taking a product of the two pullbacks is the same as the pullback of the product of the two diagrams, that is, the following diagram is a pullback\n\\[ \\begin{tikzcd}\n    A \\times C\\rar[\"\\id \\times \\id\"]\\dar[\"\\id \\times \\id\" left]\\pb & A \\times C\\dar[\"f \\times g\" right]\\\\\n    A \\times C \\rar[\"f \\times g\" below] & B \\times D.\n\\end{tikzcd} \\]\nThus $f \\times g$ is a monomorphism.\n\\end{proof}\n\n\nThis is an instance of a more general phenomenon, namely functors preserving limits and colimits.\n\n\\begin{definition}\\label{def:preserve-reflect-create-limits} Let $F:\\mathscr{C} \\to \\mathscr{D}$ be a functor, and let $I$ be an indexing diagram.\n\\begin{enumerate}\n    \\item We say that $F$ \\textit{preserves} $I$-shaped limits if, for any functor $j: I \\to \\mathscr{C}$, we have that the natural map is an isomorphism\n    \\begin{align*}\n        F(\\lim(j)) \\cong \\lim(F\\circ j).\n    \\end{align*}\n    That is, a limit cone over $j$ is sent to a limit cone over $F\\circ j$.\n\n    \\item We say that $F$ \\textit{reflects} $I$-shaped limits if, for any functor $j: I \\to \\mathscr{C}$, if we have that $F(c)$ is the limit of $F\\circ j$, then $c$ is a limit of $j$. Phrased differently, a limit cone over $F\\circ j$ in the image of $F$ must have come from a limit cone over $j$.\n\n    \\item We say $F$ \\textit{creates} limits if it preserves and reflects them.\n\\end{enumerate}\nWe have analogous definitions for colimits.\n\\end{definition}\n\nThis relates to some things we have already seen: e.g. \\autoref{prop:LAPC} said that left adjoints preserve colimits, and right adjoints preserve limits.\n\n\\begin{proposition}\\label{prop:hom-functors-preserve-limits} Hom functors preserve limits in both arguments. That is, if $\\mathscr{C}$ is a locally small category, then the bifunctor\n\\begin{align*}\n    \\Hom : \\mathscr{C}^\\op \\times \\mathscr{C} &\\to \\Set\n\\end{align*}\npreserves limits in both arguments (limits in $\\mathscr{C}^\\op$ are colimits in $\\mathscr{C}$).\n\\end{proposition}\n\n\n\\begin{corollary}\\label{cor:Yoneda-embedding-preserves-limits} Let $\\mathscr{C}$ be locally small. Then the Yoneda embedding $y: \\mathscr{C} \\hookto \\Fun(\\mathscr{C}^\\op, \\Set)$ preserves and reflects all limits.\n\\end{corollary}\n\n\\begin{proposition}\\label{prop:fully-faithful-functor-reflects-limits-colimits} A fully faithful functor reflects all limits and colimits.\n\\end{proposition}\n\n\n\\begin{remark}\\label{rmk:labelname} If $F$ is a functor preserving all limits over the diagram $I = \\bullet \\to \\bullet \\from \\bullet$, we say that it \\textit{preserves pullbacks}. Dually if $F$ preserves limits over the span diagram $J = \\bullet \\from \\bullet \\to \\bullet$, we say it is \\textit{preserves pushouts}.\n\\end{remark}\n\n\\begin{exercise}\\label{exer:pullback-preserving-functor-preserves-monos} Let $F: \\mathscr{C}\\to \\mathscr{D}$ be a functor.\n\\begin{enumerate}\n    \\item If $F$ preserves pullbacks, then it preserves monomorphisms.\n    \\item If $F$ preserves pushouts, then it preserves epimorphisms.\n\\end{enumerate}\n\\end{exercise}\n\nThus far we have defined two notions of preservation of properties. Namely, properties preserved under functors (as in \\autoref{def:functor-preserve-reflect-properties}), and properties preserved under limits and colimits (as in \\autoref{def:colimit-preserve-property}). We can see that these are both instances of the same idea.\n\n\\subsection{Colimits and limits as functors}\n\nIn order to relate these two notions of preservation, we should relate one to the other. In particular we claim that the most general notion of preservation of properties of morphisms is under a functor. In order to see that this encapsulates the other definition, we should view the construction of limits and colimits as a functor in some sense.\n\nLet $\\mathscr{C}$ be a category, and $I$ be an indexing category which we want to take limits and colimits over. Then there is a \\textit{diagonal functor}\n\\begin{align*}\n    \\Delta : \\mathscr{C} &\\to \\Fun(I, \\mathscr{C}).\n\\end{align*}\nThis sends an object $c$ to the functor $\\Delta_c: I \\to \\mathscr{C}$, where $\\Delta_c(i) = c$ for all $i\\in I$, and $\\Delta_c(i \\to i') = \\id_c$. That is, $\\Delta_c$ is really a constant functor at the object $c\\in \\mathscr{C}$. For a morphism $f:c\\to c'$, we have an induced natural transformation  $\\Delta_c \\Rightarrow \\Delta_{c'}$, all of whose components are $f$. \n\n\\begin{exercise}\\label{exer:diagonal-functor-into-functor-cat-fully-faithful} Show that $\\Delta$ is fully faithful.\n\\end{exercise}\n\n\n\\begin{remark} We can consider the construction of colimits as a functor\n\\begin{align*}\n    \\colim : \\Fun(I, \\mathscr{C}) \\to \\mathscr{C},\n\\end{align*}\nsending a diagram $I \\to \\mathscr{C}$ to the nadir of its colimit cone. Similarly $\\lim: \\Fun(I, \\mathscr{C}) \\to \\mathscr{C}$ is a functor, sending a diagram to the apex of its limit cone.\n\\end{remark}\n\n\\begin{proposition} We have that $\\colim \\dashv \\Delta \\dashv \\lim$ are adjoint functors.\n\\[ \\begin{tikzcd}\n    \\mathscr{C}\\rar[\"\\Delta\"] & \\Fun(I,\\mathscr{C})\\lar[bend right=40,\"\\colim\" above]\\lar[bend left=40,\"\\lim\" below].\n\\end{tikzcd} \\]\n\\end{proposition}\n\\begin{proof} Let $c\\in \\mathscr{C}$, and let $j: I \\to \\mathscr{C}$ be a diagram. Then we have that $\\Hom_{\\Fun(I,\\mathscr{C})}(\\Delta_c, j)$ are the natural transformations of diagrams from $\\Delta_c \\to j$. That is, it is the \\textit{set of cones over $j$ with vertex $c$}. By the universal property of the limit, for any such diagram, there is a unique map $c \\to \\lim(j)$, that is, we have a natural transformation\n\\begin{align*}\n    \\Hom_{\\Fun(I,\\mathscr{C})}(\\Delta_c, j) \\cong \\Hom_\\mathscr{C}(c, \\lim(j)).\n\\end{align*}\nA dual argument works to show that $\\colim \\dashv \\Delta$.\n\\end{proof}\n\n\\begin{remark}\\label{rmk:colimits-in-functor-categories} Since $\\colim$ is a left adjoint, it now preserves colimits by \\autoref{thm:LAPC}. We can ask what a colimit in $\\Fun(I,\\mathscr{C})$ looks like. Suppose we have a diagram of the form\n\\begin{align*}\n    I \\to \\Fun(J, \\mathscr{C}).\n\\end{align*}\nThis corresponds under adjunction to a map $I \\times J \\to \\Fun(\\mathscr{C})$. We can ask whether\n\\begin{align*}\n    \\colim \\left( I \\to \\Fun(J, \\mathscr{C}) \\right) \\overset{?}{=} \\colim \\left( I \\times J \\to \\mathscr{C} \\right).\n\\end{align*}\nIf $I$ and $J$ are small indexing diagrams, and $\\mathscr{C}$ has all colimits, this is certainly true {\\color{blue} because Kan extensions are computed pointwise in this context --- find a better way to explain this though}.\n\\end{remark}\n\n\n\\begin{theorem}\\label{thm:colimits-commute} \\textit{(Colimits commute)} Let $I$ and $J$ be small indexing diagrams, and let $\\mathscr{C}$ be cocomplete (or at least have all the colimits we are discussing here exist). Then for any bifunctor\n\\begin{align*}\n    F: I \\times J \\to \\mathscr{C}\n\\end{align*}\nwe have a canonical isomorphism\n\\begin{align*}\n    \\lim_i \\lim_j F(i,j) \\cong \\lim_j \\lim_i F(i,j).\n\\end{align*}\nSee for example \\cite[3.8.1]{Riehl-context}. A dual statement is true for colimits as well.\n\\end{theorem}\n\n\n\n\n\n\\begin{center}\n    [[todo]]    \n\\end{center}\n\n\\subsection{Filtered limits and colimits}\n\nIn \\autoref{thm:colimits-commute}, we could replace one of the limits with a colimit and ask if everything is still true. Phrased differently, if we have a functor $F: I \\times J \\to \\mathscr{C}$, we can compare\n\\begin{align*}\n    \\colim_j \\lim_i F(i,j) \\text{ and } \\lim_i \\colim_j F(i,j).\n\\end{align*}\nWe first show that there definitely exists a map between them.\n\n\\begin{proposition}\\label{prop:labelname} There is a canonical map\n\\begin{align*}\n    \\colim_j \\lim_i F(i,j) \\to \\lim_i \\colim_j F(i,j).\n\\end{align*}\n\\end{proposition}\n\n\\begin{proof} By \\autoref{exer:diagonal-functor-into-functor-cat-fully-faithful}, we have that $\\Delta$ is fully faithful, therefore the unit and counit maps are natural isomorphisms:\n\\begin{align*}\n    1_{\\Fun(I,\\mathscr{C})} \\xto{\\sim} \\lim \\circ \\Delta \\\\\n    \\colim \\circ \\Delta \\xto{\\sim}  1_\\mathscr{C}.\n\\end{align*}\nNow consider the diagram\n\\[ \\begin{tikzcd}\n    \\Fun(I \\times J, \\mathscr{C})\\rar[bend left=30,\"\\colim_I\" above]\\rar[bend right=30,\"\\lim_I\" below] & \\Fun(J, \\mathscr{C})\\lar[\"\\Delta\"]\\rar[bend left=30,\"\\colim_J\" above]\\rar[bend right=30,\"\\lim_J\" below] & \\mathscr{C}\\lar[\"\\Delta\"].\\\\\n\\end{tikzcd} \\]\n\nThe composite $\\colim_J \\lim_I$ weaves through the middle of this diagram in a wave shape. By looping through the units of adjunctions, we have a map\n\nTherefore we see that\n\\begin{align*}\n    \\colim_J \\lim_I = 1 \\colim_J \\lim_I 1 \\to \\left( \\lim_J \\Delta \\right)\\colim_J \\lim_I \\left( \\Delta \\colim_I \\right) \\\\\n    &= \n\\end{align*}\nFor an explicit computation of this map, see \\cite[3.8.3]{Riehl-context}.\n\\end{proof}\n\n\n\n\\begin{center}\n    [[todo]]    \n\\end{center}\n\n\n\n\n\\section{Unsorted subsections on category theory}\n\n\\subsection{Conventions}\n\nWe record some standard notation for use in these notes.\n\n\\begin{notation}\\label{nota:initial-terminal-objects} We denote an \\textit{initial object} in a category $\\mathscr{C}$ by $\\emptyset$. We denote a \\textit{terminal object} in a category $\\mathscr{C}$ by $\\ast$. If $X \\in \\mathscr{C}$ is arbitrary, it receives a unique map from the initial object and to the terminal object. We decorate each of these with a shriek:\n\\begin{align*}\n    \\emptyset &\\xto{!} X \\\\\n    X &\\xto{!} \\ast.\n\\end{align*}\n\\end{notation}\n\n\\begin{notation}\\label{nota:diagonal-map} Let $\\mathscr{C}$ be a category, and let $X\\in \\mathscr{C}$ be an arbitrary object. If the product $X \\times X$ exists, there is a \\textit{diagonal map}, which we denote by\n\\begin{align*}\n    X \\xto{\\Delta} X \\times X,\n\\end{align*}\ndefined to be the unique map provided to us by the universal property of the product\n\\[ \\begin{tikzcd}\n     & X\\dar\\ar[ddl,bend right=10,\"\\id_X\" left]\\ar[ddr,bend left=10,\"\\id_X\" right]\\dar[dashed,\"\\Delta\" right] & \\\\\n     & X \\times X\\ar[dl,\"\\pr_1\" below right]\\ar[dr,\"\\pr_2\" below left] & \\\\\n    X &  & X.\n\\end{tikzcd} \\]\n\\end{notation}\n\\begin{notation}\\label{nota:fold-map} Let $\\mathscr{C}$ be a category, and let $X\\in \\mathscr{C}$ be an arbitrary object. If the coproduct $X \\amalg X$, there is a \\textit{fold map}, which we denote by\n\\begin{align*}\n    X \\amalg X \\xto{\\nabla} X,\n\\end{align*}\ndefined to be the unique map provided to us by the universal property of the coproduct\n\\[ \\begin{tikzcd}\n    X\\ar[dr,\"i_1\" above right]\\ar[ddr,bend right=10,\"\\id_X\" left] &  & X\\ar[dl,\"i_2\" above left]\\ar[ddl,bend left=10,\"\\id_X\" right]\\\\\n     & X \\amalg X\\dar[dashed,\"\\nabla\" right]& \\\\\n     & X. & \\\\\n\\end{tikzcd} \\]\n\\end{notation}\n\nThe terminology for the \\textit{diagonal} map comes from the world of sets (or concrete categories more generally), where the function $\\Delta: X \\to X \\times X$ is defined elementwise by $x \\mapsto (x,x)$. That is, its image is the diagonal in the product. The \\textit{fold} map comes from the mental image of taking two disjoint copies of $X$ and folding them over one another into one copy of $X$.\n\n\\begin{notation}\\label{nota:product-coproduct-of-morphisms} Let $\\mathscr{C}$ be a category with products, and let $f: A \\to B$ and $g: C \\to D$ be two morphisms. Then we denote by\n\\begin{align*}\n    f \\times g : A \\times C \\to B \\times D\n\\end{align*}\nthe morphism given via the universal property\n\\[ \\begin{tikzcd}\n     & A \\times B\\ar[dl]\\ar[dr]\\dar[dashed,\"f \\times g\"] & \\\\\n    A\\dar[\"f\" left] & C \\times D\\ar[dl]\\ar[dr] & B\\dar[\"g\" right]\\\\\n    C &  & D.\n\\end{tikzcd} \\]\nSimilarly if $\\mathscr{C}$ is a category with coproducts, we denote by\n\\begin{align*}\n    f \\amalg g : A \\amalg C \\to B \\amalg D\n\\end{align*}\nthe morphism provided by the universal property\n\\[ \\begin{tikzcd}\n    A\\ar[dr]\\dar[\"f\" left] &  & B\\ar[dl]\\dar[\"g\" right]\\\\\n    C\\ar[dr] & A\\amalg B\\dar[dashed,\"f \\amalg g\"] & D\\ar[dl]\\\\\n     & C \\amalg D. &\n\\end{tikzcd} \\]\n\n\\end{notation}\n\n\n\n\n\\subsection{Laws for pullbacks and pushouts}\n\nFrequently we will be asked to glue together commutative squares and talk about whether the composite square is a pullback and/or whether the individual squares are pullbacks. This is discussed in the so-called \\textit{pasting law}.\n\n\\begin{proposition}\\label{prop:pasting-law-pullbacks-pushouts} \\textit{(Pasting law for pullbacks and pushouts)} Let $\\mathscr{C}$ be an arbitrary category, and consider a commutative diagram of the following form\n\\[ \\begin{tikzcd}\n    \\bullet\\rar\\dar & \\bullet\\rar\\dar & \\bullet\\dar\\\\\n    \\bullet\\rar & \\bullet\\rar & \\bullet.\n\\end{tikzcd} \\]\n\\begin{enumerate}\n    \\item If the right square is a pullback, then the total square is a pullback if and only if the left square is a pullback.\n    \\item If the left square is a pushout, then the total square is a pushout if and only if the right square is a pushout.\n\\end{enumerate}\n\\end{proposition}\n\nWe also have the ``magic square,'' which is generally stated for varieties or schemes, but holds in a more broad context.\n\n\\begin{proposition}\\label{prop:magic-pullback-square} \\textit{(Magic pullback square)} Let $\\mathscr{C}$ be a locally small category with products and pullbacks. Let $f: X \\to Z$, and $g: Y \\to Z$ be morphisms in $\\mathscr{C}$. Then the following square is a pullback\n\\[ \\begin{tikzcd}\n    X \\times_Y Z\\rar\\dar\\pb & X \\times Y\\dar[\"f \\times g\" right]\\\\\n    Z\\rar[\"\\Delta\" below] & Z \\times Z.\n\\end{tikzcd} \\]\n\\end{proposition}\n\\begin{proof} We first check that this holds if $\\mathscr{C} = \\Set$. This is certainly true, since elements of $(X \\times Y)\\times_{Z \\times Z} Z$ are precisely elements $(x,y) \\in X \\times Y$ so that $f(x) = g(y)$. Then for any locally small category $\\mathscr{C}$, we have that this diagram is a levelwise pullback in $\\Fun \\left( \\mathscr{C}^\\op, \\Set \\right)$. Finally we remark that under the Yoneda embedding $y : \\mathscr{C} \\hookto \\Fun(\\mathscr{C}^\\op, \\Set)$, limits are reflected.\n\\end{proof}\n\nThe magic pullback square is generally stated in the following form.\n\n\\begin{corollary}\\label{cor:magic-square-over-S} Let $\\mathscr{C}$ be a locally small category, and $S\\in \\mathscr{C}$ be any element. Then if $f: X \\to Z$ and $g : Y \\to Z$ are morphisms over $S$, we have a pullback square\n\\[ \\begin{tikzcd}\n    X \\times_Y Z\\rar\\dar\\pb & X \\times_S Y\\dar[\"f \\times g\"]\\\\\n    Z\\rar[\"\\Delta\" below] & Z \\times_S Z.\n\\end{tikzcd} \\]\n\\end{corollary}\n\n\n\\section{Homotopy colimits}\n\nHere we explore instances in which homotopy (co)limits appear in the basic curriculum of algebraic topology, namely in \\cite{Hatcher} and \\cite{May}. A rigorous treatment of homotopy colimits is not provided here, we defer to the far better expositors Dugger and Riehl for their expositions of simplicial and categorical understandings of homotopy colimits \\cite{Dugger,Riehl-hocolims}. We would posit that homotopy colimits are an intuitive concept to grasp and work with, and that recognizing them as they occur in basic algebraic topology provides the reader with another tool to grasp the material.\n\n\\subsection{Intro to homotopy colimits}\n\nAs described above, we neglect to provide a rigorous definition of homotopy colimits, as the rigorous definitions ($\\hocolim$ is the derived functor of $\\colim$; homotopy colimits are the geometric realization of the simplicial replacement) are technical to state. Instead, we provide the following characterization of homotopy colimits, based on an intuitive understanding of colimits:\n\\begin{center}\n    Colimits are obtained by gluing spaces.\\\\\n    \\textit{Homotopy colimits} are obtained by gluing spaces \\textit{with wiggle room, in a continuous fashion}.\n\\end{center}\n\nWhat do we mean by this? Say we want to glue two spaces $X$ and $Y$ together along distinguished basepoints to form a wedge product $X \\vee Y$. How do we do this in general? We take the disjoint union $X \\amalg Y$ and mod out by the equivalence relation $x_0 \\sim y_0$. Phrased differently, we glue $x_0$ and $y_0$ together to force them to become the same point in the quotient space.\n\nInstead of gluing them directly together, we could instead draw a path connecting $x_0$ and $y_0$. Now instead of formally identifying the two points, we provide them a path by which one can travel to the other.\n\n\\begin{figure}[H]\n  \\scalebox{0.2}{\\includegraphics{pics/whisker-gluing.png}}\n  \\centering\n\\end{figure}\n\n\n\n\n\\begin{example} As another example, suppose $\\ast \\hookto X$ is the inclusion of a point $x\\in X$. Taking the cofiber of this map\\footnote{Recall the cofiber of a map $f: X \\to Y$ is the colimit $\\colim \\left( \\ast \\from X \\xto{f} Y \\right)$.} is the same as simply gluing the point $\\ast$ to $x\\in X$, and you simply end up with the space $X$. If, instead, you wanted to take the \\textit{homotopy cofiber} of this map, you would end up with the space $X$, with a small whisker protruding from the point $x$, ending at the point $\\ast$. This procedure has a name, and it is actually called \\textit{whiskering}. For example if $(X,x)$ is a based space which is not well based\\footnote{Recall a space is \\textit{well-based/non-degenerately based} if the inclusion of the basepoint is a cofibraion.}, we can take the based space $(\\hocolim(\\ast \\hookto X),\\ast)$, which becomes well-based.\n\\end{example}\n\n\\begin{figure}[H]\n  \\scalebox{0.2}{\\includegraphics{pics/whisker.png}}\n  \\centering\n\\end{figure}\n\n\n\n\\begin{example} Consider the map $S^1 \\to \\ast$ collapsing the sphere to a point. The cofiber of this map is $\\ast$, that is, a one-point space. However to form the homotopy cofiber, we must draw a path from each point on $S^1$ to the point $\\ast$. Here is where we sweep some more rigor under the rug, and illustrate what we mean by ``in a continuous fashion'' in our characterization of homotopy colimits. When creating our paths from points on $S^1$ to $\\ast$, a small change in the choice of point on the circle $S^1$ should correspond to a small change in the path drawn. We shouldn't think of these paths as a loose collection of uncountably many strings, flying everywhere and connecting each point on $S^1$ to $\\ast$. Instead, nearby strings should coagulate to form surfaces.\n\n\\begin{figure}[H]\n  \\scalebox{0.2}{\\includegraphics{pics/cone.png}}\n  \\centering\n\\end{figure}\n\nIf you've followed this rough description, then it would make sense to you that the homotopy cofiber of the map $S^1 \\to \\ast$ becomes a hollow cone over $S^1$, whose vertex is the point $\\ast$. If, on the other hand, this lack of rigor has disgusted you, then the authors understand wholeheartedly and invite you to read \\cite{Dugger}.\n\\end{example}\n\n\nIn the previous examples, the resulting space obtained by taking a homotopy colimit was weakly homotopy equivalent to the original one obtained by taking a colimit. We can ask whether this will always be the case, which the following example (a rephrased version of Example 2.1 in \\cite{Dugger}) illustrates.\n\n\n\\begin{example} Consider the diagram $\\ast \\from S^1 \\to \\ast$. Its colimit is the pushout $\\ast \\amalg_{S^1} \\ast \\cong \\ast$, which is just a one-point space. On the other hand, its homotopy colimit can be constructed via the previous example. By gluing $S^1$ to each point $\\ast$, we obtain two hollow cones which are identified together along their bases. That is, we obtain a 2-sphere $S^2$. Note that $S^2 \\not \\simeq \\ast$!\n\\end{example}\n\nThis is an example of a general phenomena; for a diagram $D: I \\to \\Top$, it is often the case that $\\colim(D) \\not\\simeq \\hocolim(D)$.\n\n\n\\begin{remark} In the previous section we have said that a homotopy colimit ``is'' a certain space. The reader should be advised that homotopy colimits are only defined up to weak equivalence. This turns out to be both a blessing and a curse, in that we fail to obtain a well-defined construction in the topological category, however the ambiguity allows homotopy colimits to satisfy a property that colimits fail to satisfy: \\textit{homotopy invariance.} We will make this precise.\n\\end{remark}\n\n\\subsection{Homotopy Invariance}\n\n\\begin{definition} A \\textit{weak homotopy equivalence of diagrams} is a natural transformation $D \\Rightarrow D'$ (occasionally denoted $D \\simeq D'$) between two diagrams $D,D' : I \\to \\Top$ whose components are weak homotopy equivalences.\n\\end{definition}\n\n\\begin{example}\\label{ex:we-of-diagrams} Let our index category be $I = \\bullet \\from \\bullet \\to \\bullet$, and let $D(I) = \\left(D^{n+1} \\hookfrom S^n \\hookto D^{n+1}\\right)$, and $D'(I) = \\left(\\ast \\from S^n \\to \\ast \\right)$. Then there is a weak homotopy equivalence of diagrams $D \\Rightarrow D'$ whose components are the identity map on $S^n$ and the contraction $D^{n+1} \\xto{\\sim} \\ast$ on the disks.\n\\end{example}\n\n\\begin{remark} Colimits fail to satisfy \\textit{homotopy invariance}. That is, for a weak homotopy equivalence of diagrams $D\\simeq D'$, we may have that $\\colim(D) \\not\\simeq \\colim(D')$.\n\\end{remark}\n\n\\begin{exercise} See in Example \\ref{ex:we-of-diagrams} that $\\colim(D) = S^{n+1}$ but $\\colim(D') = \\ast$.\n\\end{exercise}\n\n\\begin{theorem} Homotopy colimits satisfy homotopy invariance. That is, for $D\\simeq D'$, one always has that\n\\begin{align*}\n    \\hocolim(D) \\simeq \\hocolim(D').\n\\end{align*}\n\\end{theorem}\n\n\\begin{corollary} Given any diagram, we may replace maps and objects in the diagram by weakly equivalent ones and obtain the same homotopy colimit.\n\\end{corollary}\n\n\n\\subsection{Homotopy colimits coinciding with colimits}\n\nThere are many deep questions to ask about homotopy colimits, but perhaps the first one that we might be curious about is when homotopy colimits and colimits coincide. This question is non-trivial to answer, and as always we defer to \\cite{Dugger} for a full treatment. However we will give one example, which is a stronger condition on a diagram than one needs in general, but will suit our examples:\n\n\\begin{proposition} If a diagram $D: I \\to \\Top$ has the property that all of its maps are cofibrations, then $\\colim(D) \\simeq \\hocolim(D)$.\n\\end{proposition}\n\nIn particular, if the maps are inclusions of subspaces which form a relative CW complex, they are cofibrations.\n\nThis fact, combined with homotopy invariance of homotopy colimits, will allow us to provide a characterization of a lot of phenomena occurring in algebraic topology in terms of homotopy colimits.\n\n\\begin{example} We have that $\\Sigma X = \\hocolim(\\ast \\from X \\to \\ast)$.\n\\end{example}\n\\begin{proof} Let $CX$ denote the cone over $X$, and note that $CX \\simeq \\ast$ is contractible. Then since the inclusion $X \\hookto CX$ is a relative CW complex, one has\n\\begin{align*}\n    \\Sigma X &= \\colim \\left( \\begin{tikzcd}[ampersand replacement=\\&] X\\rar[hook]\\dar[hook] \\& CX \\\\ CX \\& \\end{tikzcd} \\right) = \\hocolim \\left( \\begin{tikzcd}[ampersand replacement=\\&] X\\rar[hook]\\dar[hook] \\& CX \\\\ CX \\& \\end{tikzcd} \\right) \\\\\n    &=\\hocolim \\left( \\begin{tikzcd}[ampersand replacement=\\&] X\\rar[hook]\\dar[hook] \\& \\ast \\\\ \\ast \\& \\end{tikzcd} \\right).\n\\end{align*}\n\\end{proof}\n\n\\begin{example} Let $\\phi: S^n \\to X_n$ be the attaching map for an $(n+1)$-cell, and let $X_{n+1}$ be the space obtained by attaching this cell. Then\n\\begin{align*}\n    X_{n+1} = \\hocofib\\left(S^n \\xto{\\phi} X_n\\right).\n\\end{align*}\n\\end{example}\n\\begin{proof} Again we apply the previous proposition and homotopy invariance of homotopy colimits. We have that\n\\begin{align*}\n    X_{n+1} &= \\colim \\left( \\begin{tikzcd}[ampersand replacement=\\&] S^n\\rar[hook,\"\\phi\" above]\\dar[hook] \\& X_n \\\\ D^{n+1} \\& \\end{tikzcd} \\right) = \\hocolim \\left( \\begin{tikzcd}[ampersand replacement=\\&] S^n\\rar[hook,\"\\phi\" above]\\dar[hook] \\& X_n \\\\ D^{n+1} \\& \\end{tikzcd} \\right) \\\\\n    &=\\hocolim \\left( \\begin{tikzcd}[ampersand replacement=\\&] S^n\\rar[hook,\"\\phi\" above]\\dar[hook] \\& X_n \\\\ \\ast \\& \\end{tikzcd} \\right) = \\hocofib(\\phi).\n\\end{align*}\n\\end{proof}\n\n\\begin{example} For a map $f: X\\to Y$, the \\textit{mapping cylinder}, defined on \\cite[p.2]{hatcher} may be thought of as $M_f = \\hocolim(X \\xto{f} Y)$.\n\\end{example}\n\n\n\\begin{example} For a map $f: X\\to Y$ \\textit{mapping cone} $C_f$, defined on \\cite[p.13]{hatcher}, is the homotopy cofiber of the map $f$:\n\\begin{align*}\n    C_f = \\hocofib(f).\n\\end{align*}\n\\end{example}\n\n\\begin{example} The \\textit{join} of two spaces $X$ and $Y$, defined on \\cite[p.9]{hatcher}, is the homotopy pushout $\\hocolim(X \\from X\\times Y \\to Y)$.\n\\end{example}\n\n\\begin{example} As a generalization of the previous example, the \\textit{double mapping cylinder}, defined on \\cite[p.80]{may}, is the homotopy pushout $\\hocolim( A \\from X \\to B)$.\n\\end{example}\n\n\\begin{example} The \\textit{mapping telescope}, defined on \\cite[p.138]{hatcher}, is the homotopy colimit\n\\begin{align*}\n    \\hocolim\\left(X_0 \\xto{f_0} X_1 \\xto{f_1} \\cdots \\right).\n\\end{align*}\n\n\\end{example}\n\n\n\n\n\\begin{theorem} \\cite[Theorem~24.9]{chacholski} Homotopy colimits commute.\n\\end{theorem}\n\n\\begin{corollary} On \\cite[p.57]{may}, a critical aspect of the cofiber sequence generated by a map $f$ is that there is a weak equivalence (really a homeomorphism) $\\Sigma C_f \\simeq C(\\Sigma f)$. This can be easily remembered by the fact that homotopy colimits commute.\n\\end{corollary}\n\n\n", "meta": {"hexsha": "6d3fe318f730d4dd592d4a4334ef815ded4bb550", "size": 42491, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix.tex", "max_stars_repo_name": "tbrazel/math619", "max_stars_repo_head_hexsha": "88b90311a08c099777f08608f52e5293671b29d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-02T16:27:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-02T16:27:41.000Z", "max_issues_repo_path": "appendix.tex", "max_issues_repo_name": "tbrazel/math619", "max_issues_repo_head_hexsha": "88b90311a08c099777f08608f52e5293671b29d2", "max_issues_repo_licenses": ["MIT"], "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": "tbrazel/math619", "max_forks_repo_head_hexsha": "88b90311a08c099777f08608f52e5293671b29d2", "max_forks_repo_licenses": ["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.3145743146, "max_line_length": 886, "alphanum_fraction": 0.723965075, "num_tokens": 12994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8740772482857833, "lm_q1q2_score": 0.7975396842236018}}
{"text": "\\chapter{Matrices}\n\\section{Properties}\n\\subsection{Dimension}\nThe dimension\n\\footnote{Not to be confused with the dimenson of a vector space, see \\ref{dimension}} is the number of rows \\(a\\) and columns \\(b\\) of a Matrix \\(A\\)\n\\begin{equation}\n    \\dim{A} = a \\times b\n\\end{equation}\nDenoted as:\n\\begin{align*}\n    A^{a \\times b}\n\\end{align*}\n\\begin{example}\n    \\begin{equation*}\n        \\dim{\\begin{bmatrix}\n                1 & 2 & 3 \\\\\n                4 & 5 & 6\n            \\end{bmatrix}} = 2 \\times 3\n    \\end{equation*}\n\\end{example}\n\\begin{example}[Linearly dependent rows/columns]\n    \\begin{equation*}\n        \\dim{\\begin{bmatrix}\n                1 & 2 \\\\\n                2 & 4\n            \\end{bmatrix}}= 2 \\times 2\n    \\end{equation*}\n\\end{example}\n\\begin{matlab}\n    \\apilink{size}{https://www.mathworks.com/help/matlab/ref/size.html}\n    \\begin{lstlisting}\n    A = [[1,2,3],[1,2,3]]\n    size(A)\n    ans 2 3\n    \\end{lstlisting}\n\\end{matlab}\n\\subsection{Rank (Rang)} \\label{rank}\n\\subsubsection{Rowsapce, columnspace}\nThe rowspace \\( C \\) of a matrix ist the span of its column vectors. \\\\\nThe definied as is the span of its row vectors. It is dentoed as \\( C(A^T) \\)\\\\\nThe dimension of the column and rowspace are always equal.\n\\begin{example}\n    \\begin{align*}\n        A         & = \\begin{bmatrix}\n            1 & 2 & 4 \\\\ 1 & 2 & 4\n        \\end{bmatrix}      \\\\\n        C(A)      & = \\setb{\n        \\begin{bmatrix}\n                c \\\\ c\n            \\end{bmatrix}}{c \\in \\mathbb{R}} \\\\\n        C(A^T)    & = \\setb{\n        \\begin{bmatrix}\n                c \\\\ 2c \\\\ 4c\n            \\end{bmatrix}}{c \\in \\mathbb{R}} \\\\\n        \\dim C(A) & = \\dim C(A^T) = 1                \\\\\n    \\end{align*}\n\\end{example}\n\\subsubsection{Rank}\nThe rank of a matrix \\(A\\) is the maximal number of linearly independent columns\n(or the number of linearly independent rows, is the same thing). Or equally, the rank\nof a matrix A is the dimenson of its columnspace (or rowspace):\n\\begin{equation}\n    \\rank A = \\dim C(A) = \\dim C(A^T)\n\\end{equation}\n\\begin{example}\n    \\begin{equation*}\n        \\rank \\begin{bmatrix}\n            1 & 2 & 3 \\\\\n            4 & 5 & 6\n        \\end{bmatrix} = 2\n    \\end{equation*}\n\\end{example}\n\\begin{example}[Both rows are linearly dependent]\n    \\begin{equation*}\n        \\rank \\begin{bmatrix}\n            1 & 2 & 3 \\\\\n            2 & 4 & 6\n        \\end{bmatrix}  = 1 \\\\\n    \\end{equation*}\n\\end{example}\n\\begin{example}[Only a matrix containing zeroes has a rank of 0]\n    \\begin{equation*}\n        \\rank \\begin{bmatrix}\n            0 & 0 & 0 \\\\\n            0 & 0 & 0\n        \\end{bmatrix} = 0\n    \\end{equation*}\n\\end{example}\n\\begin{example}\n    Both columns are linearly independent, some rows are linearly dependent.\n    \\begin{equation*}\n        \\rank \\begin{bmatrix}\n            1 & 2 \\\\ 2 & 4 \\\\ 5 & 7\n        \\end{bmatrix} = 2\n    \\end{equation*}\n\\end{example}\n\\begin{matlab}\n    \\apilink{rank}{https://www.mathworks.com/help/matlab/ref/rank.html}\n    \\begin{lstlisting}\n    A = [[1,2,3],[1,2,3]]\n    rank(A)\n    ans = 1\n    \\end{lstlisting}\n\\end{matlab}\n\\subsection{Trace (Spur)}\nThe trace of a square matrix \\( A \\) is the sum of all its main diagonal elements.\n\\begin{equation}\n    tr(A) = \\sum_{i=0}^{n} a_{ii}\n\\end{equation}\n\n\\begin{example}\n    \\begin{align*}\n        A     & = \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9\n        \\end{bmatrix} \\\\\n        tr(A) & = 1 + 5 + 9 = 15\n    \\end{align*}\n\\end{example}\n\n\\begin{matlab}\n    \\apilink{trace}{https://www.mathworks.com/help/matlab/ref/double.trace.html}\n    \\begin{lstlisting}\n>> A = [1,2,3;4,5,6;7,8,9]\n>> trace(A)\nans =\n15\n\\end{lstlisting}\n\\end{matlab}\n\\subsection{Minor, Cofactors}\\label{minor}\n\\subsubsection{Submatrix}\nA submatrix \\(S_ij\\) of a Matrix \\(A\\) is the Matrix obtained by deleting the \\(i\\)th Row and deleting the \\(j\\)th column.\n\\begin{example}\n    \\begin{align*}\n        A      & = \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9\n        \\end{bmatrix} \\\\\n        S_{12} & = \\begin{bmatrix}\n            4 & 6 \\\\ 7 & 9\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsubsection{Minor}\nA minor \\(M_{ij}\\) of a matrix \\(A\\) is the determinant of the submatrix \\(S_{ij}\\).\n\\subsubsection{Cofactors}\nA cofactor \\( C_{ij} \\) is obtained by multiplying the minor \\( M_{ij} \\) by \\( (-1)^{i + j} \\). The cofactor Matrix \\(C \\) is given by:\n\\begin{equation}\n    C = \\begin{bmatrix}\n        C_{11} & C_{12} & \\dots  & C_{1i} \\\\\n        C_{21} & C_{22} & \\dots  & C_{1i} \\\\\n        \\vdots & \\vdots & \\ddots          \\\\\n        C_{j1} & C_{j2} &        & C_{ij} \\\\\n    \\end{bmatrix} =  \\begin{bmatrix}\n        M_{11}            & -M_{12}             & \\dots  & (-1)^{i + 1}M_{1i}  \\\\\n        -M_{21}           & M_{22}              & \\dots  & (-1)^{i + 2} M_{2i} \\\\\n        \\vdots            & \\vdots              & \\ddots                       \\\\\n        (-1)^{1+ j}M_{j1} & (-1)^{2 + j} M_{j2} &        & (-1)^{i + j} M_{ij} \\\\\n    \\end{bmatrix}\n\\end{equation}\n\\begin{example}\\label{minor_example}\n    \\begin{align*}\n        A = \\begin{bmatrix}\n            1 & 2 & 3 \\\\\n            4 & 5 & 6 \\\\\n            7 & 8 & 9 \\\\\n        \\end{bmatrix} \\\\\n    \\end{align*}\n    \\begin{align*}\n        M_{11} & = det(\\begin{bmatrix}\n            5 & 6 \\\\\n            8 & 9 \\\\\n        \\end{bmatrix}) = -3  &\n        M_{12} & = det(\\begin{bmatrix}\n            4 & 6 \\\\\n            7 & 9 \\\\\n        \\end{bmatrix}) = -6  &\n        M_{13} & = det(\\begin{bmatrix}\n            4 & 5 \\\\\n            7 & 8 \\\\\n        \\end{bmatrix}) = -3    \\\\\n        M_{21} & = det(\\begin{bmatrix}\n            2 & 3 \\\\\n            8 & 9 \\\\\n        \\end{bmatrix}) = -6  &\n        M_{22} & = det(\\begin{bmatrix}\n            1 & 3 \\\\\n            7 & 9 \\\\\n        \\end{bmatrix}) = -12 &\n        M_{23} & = det(\\begin{bmatrix}\n            1 & 2 \\\\\n            7 & 8 \\\\\n        \\end{bmatrix}) = -6    \\\\\n        M_{31} & = det(\\begin{bmatrix}\n            2 & 3 \\\\\n            5 & 6 \\\\\n        \\end{bmatrix}) = -3  &\n        M_{32} & = det(\\begin{bmatrix}\n            1 & 4 \\\\\n            3 & 6 \\\\\n        \\end{bmatrix}) = -6  &\n        M_{33} & = det(\\begin{bmatrix}\n            1 & 2 \\\\\n            4 & 5 \\\\\n        \\end{bmatrix}) = -3\n    \\end{align*}\n    \\begin{equation*}\n        C = \\begin{bmatrix}\n            M_{11}  & -M_{12} & M_{13}  \\\\\n            -M_{21} & M_{22}  & -M_{23} \\\\\n            M_{31}  & -M_{32} & M_{33}  \\\\\n        \\end{bmatrix} = \\begin{bmatrix}\n            -3 & 6   & -3 \\\\\n            6  & -12 & 6  \\\\\n            -3 & 6   & -3 \\\\\n        \\end{bmatrix}\n    \\end{equation*}\n\\end{example}\n\\begin{example}\n    \\begin{equation*}\n        A = \\begin{bmatrix}\n            1 & 2 \\\\ 3 & 4\n        \\end{bmatrix}\n    \\end{equation*}\n    \\begin{align*}\n        M_{11} & = 4 & M_{12} & = 3 \\\\\n        M_{21} & = 2 & M_{22} & = 1\n    \\end{align*}\n    \\begin{equation*}\n        C = \\begin{bmatrix}\n            M_{11}  & -M_{12} \\\\\n            -M_{21} & M_22\n        \\end{bmatrix} = \\begin{bmatrix}\n            4 & -3 \\\\ -2 & 1\n        \\end{bmatrix}\n    \\end{equation*}\n\\end{example}\n\\subsection{Determinant}\n\\subsubsection{2x2 Matrix}\nFor 2x2 Matrix the formula is as given:\n\\begin{align*}\n    \\determinant{\\begin{bmatrix}\n            x_1, x_2 \\\\\n            x_3, x_4 \\\\\n        \\end{bmatrix}} = x_1 \\cdot x_4 - x_2 \\cdot x_4\n\\end{align*}\n\\begin{example}\n    \\begin{align*}\n        \\determinant{\n            \\begin{bmatrix}\n                3 & 7 \\\\ -5 & 11\n            \\end{bmatrix}\n        } = 3 \\cdot 11 - 7 \\cdot (-5) = 68\n    \\end{align*}\n\\end{example}\n\\subsubsection{3x3 Matrix}\nThe determinant of a 3x3 Matrix can be calculated using its minors.\n\\begin{align*}\n    \\determinant{\\begin{bmatrix}\n            x_1 & x_2 & x_3  \\\\\n            x_4 & x_5 & x_6  \\\\\n            x_7 & x_8 & x_9) \\\\\n        \\end{bmatrix}} & = x_1 \\cdot\n    \\determinant{\\begin{bmatrix}\n            x_5 & x_6 \\\\\n            x_8 & x_9 \\\\\n        \\end{bmatrix}}- x_2 \\cdot\n    \\determinant{\\begin{bmatrix}\n            x_4 & x_6 \\\\\n            x_7 & x_9 \\\\\n        \\end{bmatrix}}+ x_3 \\cdot \\determinant{\\begin{bmatrix}\n            x_4 & x_5 \\\\\n            x_7 & x_8 \\\\\n        \\end{bmatrix}}                                   \\\\\n                                             & = x_1 (x_5x_9 - x_6 x_8) - x_2 (x_4 x_9 - x_6 x_7) + x_3 (x_4 x_8 - x_5 x_7)        \\\\\n                                             & = x_1 x_5 x_9 + x_2 x_6 x_7 + x_3 x_4 x_8 - x_3 x_5 x_7 - x_2 x_4 x_9 - x_1 x_6 x_8\n\\end{align*}\nFor higher order matrices you can apply this method recursively.\n\\begin{example}\n    Minors were calculated in previous example.\n    \\begin{align*}\n        \\determinant{\\begin{bmatrix}\n                1 & 2 & 3 \\\\\n                4 & 5 & 6 \\\\\n                7 & 8 & 9 \\\\\n            \\end{bmatrix}} & = 1 \\cdot(-3) - 2 \\cdot(-6) + 3 \\cdot(-3) = 0 \\\\\n    \\end{align*}\n\\end{example}\n\\subsubsection{Triangular matrx}\n\\begin{align*}\n    D = \\begin{bmatrix}\n        x_{11} & x_{12} & \\cdots & x_{1n} \\\\\n        0      & x_{22} &        &        \\\\\n        \\vdots &        & \\ddots          \\\\\n        0      & 0      & \\cdots & x_{nn} \\\\\n    \\end{bmatrix} \\det(D) & = x_{11} \\cdot x_{22} \\dots x_{nn} = \\prod_{i=1}^n x_{}\n\\end{align*}\n\\subsubsection{Singular matrix}\nSingular matrices are matrices with \\( \\det = 0 \\).\nSingular matrices have rows and/or columns that are not linearly independent.\n\\begin{example}\n    \\begin{align*}\n        A               & = \\begin{bmatrix}\n            1 & 2 \\\\ -2 & -4\n        \\end{bmatrix}      \\\\\n        \\determinant{A} & = 1 \\cdot (-4) - (-2) \\cdot 2 = 0\n    \\end{align*}\n\\end{example}\n\\begin{matlab}\n    \\apilink{det}{https://www.mathworks.com/help/matlab/ref/det.html}\n    \\begin{lstlisting}\n>> a =[[3,7];[4,12]]\n>> det(a)\nans = 8\n\\end{lstlisting}\n\\end{matlab}\n\\subsection{Eigenvalues, Eigenvectors}\\label{eigen}\nAn eigenvector \\( v \\) of a square matrix \\(A\\) is a nonzero vector that changes at most by a scalar factor when that linear transformation is applied to it. The corresponding eigenvalue $\\lambda$ is the factor by which the eigenvector is scaled.\n\\begin{equation} \\label{eigenexpression}\n    A\\cdot v = \\lambda \\cdot v\n\\end{equation}\n\\begin{example}\n    \\begin{align*}\n        A         & = \\begin{bmatrix}\n            5 & 1 \\\\ 0 & 3\n        \\end{bmatrix}                                                               \\\\\n        v         & = \\begin{bmatrix}\n            1 \\\\ 0\n        \\end{bmatrix}, \\lambda = 5                                                  \\\\\n        A \\cdot v & = \\begin{bmatrix}\n            5 & 1 \\\\ 0 & 3\n        \\end{bmatrix} \\cdot \\begin{bmatrix}\n            1 \\\\ 0\n        \\end{bmatrix} = \\begin{bmatrix}\n            5 \\\\ 0\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsubsection{Characteristic polynomial}\nThe expression \\ref{eigenexpression} can be written as:\n\\begin{align}\n    A\\cdot v = \\lambda \\cdot I \\cdot v \\tag*{Multiplying with identity Matrix} \\\\\n    A \\cdot v - \\lambda \\cdot I \\cdot v = 0                                    \\\\\n    v \\cdot (A - \\lambda \\cdot I) = 0\n\\end{align}\nSince \\(v\\) per definition can't be the zero vector, the expression \\( (A - \\lambda \\cdot I) \\) must be zero.\n\\begin{align*}\n    A - \\lambda \\cdot I = 0                 \\\\\n    \\determinant{ A - \\lambda \\cdot I } = 0 \\\\\n    \\determinant{\n        \\begin{bmatrix}\n            a_{11} - \\lambda & a_{12}           & \\cdots & a_{1n}           \\\\\n            a_{12}           & a_{22} - \\lambda &        &                  \\\\\n            \\vdots           &                  & \\ddots &                  \\\\\n            a_{n1}           &                  &        & a_{nn} - \\lambda\n        \\end{bmatrix}\n    } & = 0\n\\end{align*}\nThe characteristic polynomial \\( P_{A}\\) of a matrix \\(A\\) is defined as:\n\\begin{equation}\n    P_A(t) = \\determinant{A - t I}\n\\end{equation}\nIf a square matrix A with \\( \\dim(A) = n \\times n \\) then \\(p_A(t)\\) will have a degree of \\(n\\). The characteristic polynomial is always monic (the leading coefficient is 1)\n\\begin{example}\\label{eigenexample}\n    \\begin{align*}\n        A      & = \\begin{bmatrix}\n            5 & 7 \\\\ 11 & 3\n        \\end{bmatrix}                                                                    \\\\\n        p_A(t) & = \\determinant{\\begin{bmatrix}\n                5 - t & 7 \\\\ 11 & 3 -t\n            \\end{bmatrix}} = (5 - t) \\cdot (3 - t) - 7 \\cdot 11 = t^2 - 8t - 62\n    \\end{align*}\n    Note for a \\(2 \\times 2 \\) matrix \\( p_A(t) \\) is always:\n    \\begin{equation}\n        p_A(t) = t^2 - \\trace(A) t - \\determinant{A}\n    \\end{equation}\n\\end{example}\n\\begin{matlab}\n    \\apilink{charpoly}{https://www.mathworks.com/help/symbolic/sym.charpoly.html}\n    \\begin{lstlisting}\n    >> charpoly([5, 7 ; 11, 3])\n    ans =\n         1    -8   -62\n   \\end{lstlisting}\n\\end{matlab}\nIf  A gets pluged into \\(p_A(t)\\) then the result will be the zero-matrix.\n\\begin{equation}\n    P_a(A) = A^n + b_2 A^{n-1} \\cdots b_{n-1} A + b_n I = 0 \\\\\n\\end{equation}\n\\begin{example}\n    From previous example.\n    \\begin{gather*}\n        p_A(t) = t^2 - 8t - 62 \\\\\n        p_A(A) =  \\begin{bmatrix}\n            5 & 7 \\\\ 11 & 3\n        \\end{bmatrix}^2  - \\begin{bmatrix}\n            5 & 7 \\\\ 11 & 3\n        \\end{bmatrix} - 62 I \\\\\n        = \\begin{bmatrix}\n            102 & 56 \\\\ 88 & 86\n        \\end{bmatrix} - \\begin{bmatrix}\n            40 & 56 \\\\ 88 & 24\n        \\end{bmatrix} - \\begin{bmatrix}\n            62 & 0 \\\\ 0 & 62\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 & 0 \\\\ 0 & 0\n        \\end{bmatrix}\n    \\end{gather*}\n\\end{example}\n\\subsubsection{Characteristic equation}\nThe roots of the characteristic polynomial are the eigenvalues \\(\\lambda_i \\) of \\(A\\). The expression\n\\begin{equation}\n    p_A(t) = 0\\\\\n\\end{equation}\nis called the characteristic equation. The characteristic polynomial can be written as:\n\\begin{equation}\n    p_A(t) = (t - \\lambda_1)(t - \\lambda_2) \\cdots (t - \\lambda_i)\n\\end{equation}\n\\begin{example}\\label{eigenexampld}\n    \\begin{align*}\n        A      & = \\begin{bmatrix}\n            3 & 7 \\\\ 2 & 5\n        \\end{bmatrix}                                                 \\\\                                                                                                                                                  \\\\\n        p_A(t) & = \\det(A - t I)  = \\determinant{\\begin{bmatrix}\n                3 - t & 7 \\\\2  & 5 - t\n            \\end{bmatrix}} =  t^2 - 8 t + 1 \\\\\n    \\end{align*}\n    We get the eigenvalues by setting \\(p_A(\\lambda) = 0\\) and solving for \\( \\lambda \\)\n    \\begin{align*}\n        \\lambda^2 - 8 \\lambda + 1 = 0                                           \\\\\n        \\lambda_{12} = -\\frac{-8}{2} \\pm \\sqrt{\\left( \\frac{-8}{2}\\right)^2 -1} \\\\\n        \\lambda_1 = 4 - \\sqrt{15},  \\lambda_2 = 4 + \\sqrt{15}                   \\\\\n    \\end{align*}\n\\end{example}\n\\subsubsection{Arithmetic Multiplity}\nA matrix can have multiple eigenvalues $\\lambda_i$ with the same value.\nThe characteristic polynomial can be written as:\n\\begin{align*}\n    p_A(t) = (t-\\lambda_1)(t-\\lambda_2) \\dots (t-\\lambda_n)\n\\end{align*}\nThe arithmetic Multiplicity $\\mu_A(\\lambda_1)$ is the number of times $(t - \\lambda_i)$ can divide $p_A(t)$,\nso the highest power $(t - \\lambda_i)$ can have (simply said the number of times a value appears).\n\\begin{example}\n    \\begin{align*}\n        A = \\begin{bmatrix}\n            1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n            0 & 2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n            0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n            0 & 0 & 0 & 3 & 0 & 0 & 0 & 0 & 0 \\\\\n            0 & 0 & 0 & 0 & 3 & 0 & 0 & 0 & 0 \\\\\n            0 & 0 & 0 & 0 & 0 & 4 & 0 & 0 & 0 \\\\\n            0 & 0 & 0 & 0 & 0 & 0 & 4 & 0 & 0 \\\\\n            0 & 0 & 0 & 0 & 0 & 0 & 0 & 4 & 0 \\\\\n            0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 4 \\\\\n        \\end{bmatrix}\n    \\end{align*}\n    A has 4 eigenvalues: 1, 2, 3, 4($=\\lambda_{1..10})$\\\\\n    The characteristic polynomial can be expressed by using only distinct eigenvalues:\n    \\begin{align*}\n        p_A(t) = (t -1)(t-2)^2(t-3)^3(t-4)^4\n    \\end{align*}\n\\end{example}\nFor example $\\mu_A(\\lambda_4) = 4$, because $(t - 4)$ divides $p_A(t)$ 4 times.\n\\subsubsection{Eigenvectors, eigenspace}\nTo find the eigenvector of an associatited eigenvalue we need to find the kernel of the following linear map:\n\\begin{align*}\n    L:  (A - \\lambda_i \\cdot I) x = y \\\\\n    \\epsilon_i = \\ker L\n\\end{align*}\nSince the kernel of a tranformation forms a vectorspace  \\( \\epsilon \\) called \\textbf{eigenspace}. So following properites are satisfied:\n\\begin{align*}\n    v_1, v_2 \\in \\epsilon_i, c \\in \\mathbb{F} \\\\\n    v_1 + v_2 \\in \\epsilon_i                  \\\\\n    c \\cdot v_1 \\in \\epsilon_i                \\\\\n\\end{align*}\n\\begin{example}\n    Continuing  example \\ref{eigenexample}.\n    \\begin{align*}\n        A & = \\begin{bmatrix}\n            3 & 7 \\\\ 2 & 5\n        \\end{bmatrix}                      \\\\                                                                                                                                                  \\\\\n        \\lambda_1 = 4 - \\sqrt{15},  \\lambda_2 = 4 + \\sqrt{15} \\\\\n    \\end{align*}\n    \\(\\lambda_1\\):\n    \\begin{align*}\n        \\begin{bmatrix}\n            3 - (4 - \\sqrt{15}) & 7 \\\\ 2 & 5 - ( 4 - \\sqrt{15})\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            x_1 \\\\ x_2\n        \\end{bmatrix}= \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix}                           \\\\\n        \\begin{bmatrix}\n            -1 + \\sqrt{15} & 7 \\\\ 2 & 1 + \\sqrt{15}\n        \\end{bmatrix}\\begin{bmatrix}\n            x_1 \\\\ x_2\n        \\end{bmatrix}= \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix} \\\\\n    \\end{align*}\n    We can eliminate the II row by subtracting I $ \\left( \\frac{2}{-1 + \\sqrt{15}} \\right) $ \\\\\n    \\begin{align*}\n        \\begin{bmatrix}\n            -1 + \\sqrt{15} & 7 \\\\ 2 & 1 + \\sqrt{15}\n        \\end{bmatrix} \\rightarrow\n        \\begin{bmatrix}\n            -1 + \\sqrt{15} & 7 \\\\ 2 - 2 & (1 + \\sqrt{15})-  \\left(\\frac{14}{-1 + \\sqrt{15}} \\right)\n        \\end{bmatrix} = \\begin{bmatrix}\n            -1 + \\sqrt{15} & 7 \\\\ 0 & 0\n        \\end{bmatrix}\n    \\end{align*}\n    Since the last row was eliminated, we see that  of $rank(A- \\lambda I)$ is 1. It means $x_1$ or $x_2$ can be freely chosen.\n\n    Keep in mind we are interest only in the 'form' of the eigenvector, because an eigenvector of $A$ multiplied with a scalar is still an eigenvector of $A$.\n    \\begin{align*}\n        0 & = (-1 + \\sqrt{15})x + 7y     \\\\\n        y & = \\frac{(1 - \\sqrt{15})x}{7}\n    \\end{align*}\n    We can eliminate the fraction by setting  $x=7$.\n    \\begin{align*}\n        x   & = 7                                          \\\\\n        y   & = \\frac{(1 - \\sqrt{15})7}{7} = 1 - \\sqrt{15} \\\\\n        v_1 & = \\begin{bmatrix}\n            7 \\\\ 1 - \\sqrt{15}\n        \\end{bmatrix}\n    \\end{align*}\n    Same for $\\lambda_2$:\n    \\begin{align*}\n        \\begin{bmatrix}\n            3 - (4 + \\sqrt{15}) & 7                   \\\\\n            2                   & 5 - (4 - \\sqrt{15})\n        \\end{bmatrix} \\begin{bmatrix}\n            x_1 \\\\ x_2\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix}\n    \\end{align*}\n    \\begin{align*}\n        \\begin{bmatrix}\n            -1 - \\sqrt{15} & 7             \\\\\n            2              & 1 - \\sqrt{15}\n        \\end{bmatrix} \\begin{bmatrix}\n            x_1 \\\\ x_2\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix}\n    \\end{align*}\n    We can eliminate the II row by subtracting I $ \\left( \\frac{2}{-1 - \\sqrt{15}} \\right) $ \\\\\n    \\begin{align*}\n        \\begin{bmatrix}\n            -1  - \\sqrt{15} & 7 \\\\\n            0               & 0\n        \\end{bmatrix} \\begin{bmatrix}\n            x_1 \\\\ x_2\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 \\\\ 0\n        \\end{bmatrix} \\\\\n    \\end{align*}\n    Solving for $x_1$, $x_2$:\n    \\begin{align*}\n        (-1-\\sqrt{15}) x_1 + 7 x_2 & = 0                          \\\\\n        x_2                        & = \\frac{1 + \\sqrt{15}x_1}{7} \\\\\n        x_1                        & = 7  \\text{ (chosen)}        \\\\\n        x_2                        & = 1 + \\sqrt{15}              \\\\\n        v_2                        & = \\begin{bmatrix}\n            7 \\\\ 1 + \\sqrt{15}\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\begin{matlab}\n    \\apilink{eig}{https://www.mathworks.com/help/matlab/ref/eig.html}\n    \\begin{lstlisting}\n        >> [a, d] = eig([3, 7; 11, 3])\n    a =\n        0.6236   -0.6236\n        0.7817    0.7817\n    d =\n        11.7750         0\n        0   -5.7750\n    \\end{lstlisting}\n\\end{matlab}\n\\subsubsection{Geometric multiplicity}\nThe geometry multiplicity \\(\\gamma_A \\) of an eigenvalue is the dimension of the associatited eigenspace.\n\\begin{equation}\n    \\gamma_a(\\lambda_i) = \\dim \\ker\\left(A - I \\lambda_i \\right)\n\\end{equation}\n\nThe geometry multiplicity of an eigenvalue can't be larger than the arithmetic multiplicity.\n\\begin{equation}\n    \\gamma_A(\\lambda_i) \\leq \\mu_a(\\lambda_1)\n\\end{equation}\nFor a square Matrix \\(A^{n \\times n}\\) with \\(m\\) eigenvalues it holds:\n\\begin{equation}\n    \\sum_{i=1}^{m} \\gamma(\\lambda_i) + \\mu(\\lambda_i) = n\n\\end{equation}\n\\begin{example}\n    \\begin{align*}\n        A = \\begin{bmatrix}\n            2 & 0 & 0 & 0 \\\\ 0 & 0 & 0 &0 \\\\ 0 & 0 &0 &0 \\\\ 0 & 0 & 1 & 0\n        \\end{bmatrix}                                                  \\\\\n        p_A(t) = t^3(t- 2)                                                               \\\\\n        \\lambda_1 = 2, \\lambda_2 = 0                                                     \\\\\n        \\mu_A(2) = 1, \\mu_A(0) = 3,                                                      \\\\\n        \\epsilon_1 = \\span \\{ \\begin{bmatrix}\n            2 \\\\ 0 \\\\ 0 \\\\ 0\n        \\end{bmatrix} \\}                             \\\\\n        \\epsilon_2 = \\span \\{ \\begin{bmatrix}\n            0 \\\\ 1 \\\\ 0 \\\\ 0\n        \\end{bmatrix}, \\begin{bmatrix}\n            0 \\\\ 0 \\\\ 0 \\\\ 1\n        \\end{bmatrix}\\} \\\\\n        \\gamma_a(2) = \\dim \\epsilon_1 = 1                                                \\\\\n        \\gamma_a(0) = \\dim \\epsilon_2 = 2\n    \\end{align*}\n\\end{example}\n\\subsection{Similarity}\\label{similiarity}\nTwo square matrices $A$ and $B$ are similar when an if there exists an invertible $n \\times n$ matrix P such that:\n\\begin{gather}\n    A = P^{-1}BP \\\\\n    B = PAP^{-1}\n\\end{gather}\nIt is denoted as\n\\begin{equation*}\n    A \\tilde{=} B\n\\end{equation*}\nU is also called the change of base matrix.\nSimilar matrices have the same:\n\\begin{itemize}\n    \\item Characteristic polynomial\n    \\item Eigenvalues (but not eigenvectors)\n    \\item Determinant\n    \\item Trace\n\\end{itemize}\nSimilarity is an equivalence relation\n\\begin{itemize}\n    \\item A is similar to A\n    \\item If A is similar to B, then B is similar to A.\n    \\item If A is similar to B and B is similar to C, then A is similar to C.\n\\end{itemize}\n\\begin{example}\n    \\begin{align*}\n        B = \\begin{bmatrix}\n            2 & 3 \\\\ 0 & 4\n        \\end{bmatrix}, A = \\begin{bmatrix}\n            3 & 4 \\\\ \\frac{1}{4} & 3\n        \\end{bmatrix}, P = \\begin{bmatrix}\n            3 & 0 \\\\ 1 & 4\n        \\end{bmatrix}, P^{-1} = \\begin{bmatrix}\n            \\frac{1}{3} & 0 \\\\ -\\frac{1}{12} & \\frac{1}{4}\n        \\end{bmatrix}\n    \\end{align*}\n    \\begin{align*}\n        P^{-1}BP = \\begin{bmatrix}\n            \\frac{1}{3} & 0 \\\\ -\\frac{1}{12} & \\frac{1}{4}\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            2 & 3 \\\\ 0 & 4\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            3 & 0 \\\\ 1 & 4\n        \\end{bmatrix} = \\begin{bmatrix}\n            \\frac{2}{3} & 1 \\\\ -\\frac{1}{6} & \\frac{3}{4}\n        \\end{bmatrix}\\begin{bmatrix}\n            3 & 0 \\\\ 1 & 4\n        \\end{bmatrix} = \\begin{bmatrix}\n            3 & 4 \\\\ \\frac{1}{4} & 3\n        \\end{bmatrix}\n    \\end{align*}\n    \\begin{align*}\n        \\det(B) & = 2 \\cdot 4 - 3 \\cdot 0 = 8                           \\\\\n        \\det(A) & = 3 \\cdot 3 - 1 \\cdot \\frac{1}{4} = 8                 \\\\\n        tr(A)   & = 3 + 3 = 6                                           \\\\\n        tr(B)   & = 2 +4 = 6                                            \\\\\n        p_B(t)  & = (2 - t)(4 - t) - 4 \\cdot 0 = t^2 - 6t + 8           \\\\\n        p_A(t)  & = (3 - t)(3 - t) - 4 \\cdot \\frac{1}{4} = t^2 - 6t + 8 \\\\\n    \\end{align*}\n\\end{example}\n\\subsection{Defective matrices}\nIf there is one eigenvalue \\(\\lambda_i\\) with \\(\\mu_A(\\lambda_i) \\neq \\gamma_A(\\lambda_i) \\) then the corresponding Matrix \\(A\\) defective:\n\\begin{itemize}\n    \\item The matrix has less than \\(n\\) lienary independent eigenvectors\n    \\item The sum of the dimesons of the eigensapces has a dimension less than \\( n\\)\n\\end{itemize}\nThe eigenvalue is called defective eigenvalue.\n\\begin{example}\n    \\begin{gather*}\n        A = \\begin{bmatrix}\n            1 & 1 & 0 \\\\ 0 & 1 & 1 \\\\ 0 & 0 & 4\n        \\end{bmatrix}\\\\\n        \\lambda_1 = 1, \\lambda_2 = 4\\\\\n        v_1 = \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 0\n        \\end{bmatrix}, v_2 = \\begin{bmatrix}\n            \\frac{1}{9} \\\\ \\frac{1}{3} \\\\ 1\n        \\end{bmatrix}\\\\\n        \\mu_A(\\lambda_1) = 2 \\neq \\gamma_A(\\lambda_1) = 1 \\\\\n    \\end{gather*}\n\\end{example}\nDefective matrices can't be diagonalized.\n\\subsection{Geeralized eigenvectors}\nLet \\(L : V \\rightarrow V\\) with a defective transformation matrix \\(A\\). A generalized eigenvector \\(w\\) of a defective eigenvalue is the solution of:\n\\begin{equation}\n    \\begin{split}\n        \\left(A - \\lambda I \\right)^m w = 0\\\\\n        \\left(A - \\lambda I \\right)^{m-1} w \\neq 0 \\\\\n        m > 1, m \\in \\mathbb{N}\\\\\n    \\end{split}\n\\end{equation}\n\\(m\\) is called the rank of the generalized eigenvector.\n\\subsubsection{Jordan chain}\nLet \\(v\\) be an ordinary eigenvector of \\(A\\):\n\\begin{align*}\n    (A - \\lambda I)v = 0         \\\\\n    (A - \\lambda I)w_1 = v       \\\\\n    (A - \\lambda I)w_2 = w_1     \\\\\n    (A - \\lambda I)w_3 = w_2     \\\\\n    \\vdots                       \\\\\n    (A - \\lambda I)w_{n-1} = w_n \\\\\n\\end{align*}\n\\begin{example}\n    \\begin{align*}\n        A = \\begin{bmatrix}\n            3 & 2 & 0 \\\\ 0 & 3 & 4 \\\\  0 & 0 & 3\n        \\end{bmatrix}\n    \\end{align*}\n    The matrix has single eigenvalue \\(\\lambda = 3\\) with \\(\\mu_a(3) = 3\\) but only one eigenvector \\(v_1\\).\n    \\begin{align*}\n        A - I \\lambda = \\begin{bmatrix}\n            0 & 2 & 0 \\\\ 0 & 0 & 4 \\\\  0 & 0 & 0\n        \\end{bmatrix}                                                   \\\\\n        \\begin{bmatrix}\n            0 & 2 & 0 \\\\ 0 & 0 & 4 \\\\  0 & 0 & 0\n        \\end{bmatrix} v =  \\begin{bmatrix}\n            0 \\\\ 0 \\\\ 0\n        \\end{bmatrix}, v = \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 0\n        \\end{bmatrix} \\\\\n        \\begin{bmatrix}\n            0 & 2 & 0 \\\\ 0 & 0 & 4 \\\\  0 & 0 & 0\n        \\end{bmatrix} w_1 =  \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 0\n        \\end{bmatrix}, w_1 = \\begin{bmatrix}\n            0 \\\\ \\frac{1}{2} \\\\ 0\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsection{Shift matrix}\nA shift matrix that has 1 on its superdiagonal and 0 elsewhere.\n\\begin{equation*}\n    S  = \\begin{bmatrix}\n        0      & 1 & 0      & \\cdots &        \\\\\n        \\vdots & 0 & 1      & 0      & \\cdots \\\\\n        \\vdots &   & \\ddots &        &        \\\\\n               &   &        & 0      & 1      \\\\\n               &   & \\ddots & 0      & 0      \\\\\n    \\end{bmatrix}\n\\end{equation*}\nWhen multplied wiht another matrix \\(A\\) it shifts the columns of \\(A\\) by one to the right.\n\\begin{align*}\n    A         & = \\begin{bmatrix}\n        c_1 & c_2 & \\cdots & c_{n -1} & c_n\n    \\end{bmatrix} \\\\\n    A \\cdot S & = \\begin{bmatrix}\n        0 & c_2 & \\cdots & c_{n -2} & c_{n - 1}\n    \\end{bmatrix}\n\\end{align*}\n\\begin{example}\n    \\begin{gather*}\n        \\begin{bmatrix}\n            1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9\n        \\end{bmatrix} \\cdot \\begin{bmatrix}\n            0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 & 0\n        \\end{bmatrix} = \\begin{bmatrix}\n            0 & 1 & 2 \\\\ 0 & 4 & 5 \\\\ 0 & 7 & 8\n        \\end{bmatrix}\n    \\end{gather*}\n\\end{example}\n\\subsection{Nilpotent matrix}\nA matrix is nilpotent of degree k if\n\\begin{gather*}\n    A^i \\neq 0 \\\\\n    A^k = 0 \\\\\n    0 \\leq i < k\n\\end{gather*}\n\\begin{example}\n    Let A be a Matrix containing only zeroers except on its superdiagonal. A is nilpotent of degree  \\( k +1 \\) where \\(k\\) is the number of nonzero element. An example\n    would be the shift matrix:\n    \\begin{align*}\n        S^{1} = \\begin{bmatrix}\n            0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 & 0\n        \\end{bmatrix}\n        S^{2} = \\begin{bmatrix}\n            0 & 0 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 & 0\n        \\end{bmatrix}\n        S^{3} = \\begin{bmatrix}\n            0 & 0 & 0 \\\\ 0 & 0 & 0 \\\\ 0 & 0 & 0\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    Only the zero matrix is nilpotent with degree 1.\n\\end{example}\n\\begin{example}\n    A diagonal matrix is not nilpotent.\n    \\begin{align*}\n        D = \\begin{bmatrix}\n            2 & 0 \\\\ 0 & 4\n        \\end{bmatrix} \\\\\n        D^n = \\begin{bmatrix}\n            2^{n} & 0 \\\\ 0 & 4^{n}\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\subsection{Jordan normal form}\n\\subsubsection{Jordan Block}\nA jordan block is a square matrix with the same value for each element on its main diagonal and 1 on it superdiagonal. The other elements are 0.\n\\begin{equation*}\n    B_{\\lambda}  = \\begin{bmatrix}\n        \\lambda & 1       & 0      & \\cdots  &         \\\\\n        0       & \\lambda & 1      & 0       & \\cdots  \\\\\n        \\vdots  &         & \\ddots &         &         \\\\\n                &         &        & \\lambda & 1       \\\\\n                &         & \\ddots & 0       & \\lambda \\\\\n    \\end{bmatrix}\n\\end{equation*}\n\n\\subsubsection{Jordan box}\nLet \\(lambda\\) be an eigenvalue of \\(A\\) with \\(\\mu(\\lambda) = n\\) and \\( \\gamma_a(\\lambda) = m \\).\nA Jordan box is the direct sum of\n\\begin{equation}\n    J_{\\lambda} = D_{\\lambda} \\oplus B_{\\lambda}\n\\end{equation}\nwhere:\n\\begin{gather*}\n    \\dim J_{\\lambda} = n \\\\\n    \\dim D_{\\lambda} = m \\\\\n    \\dim B_{\\lambda} = n - m \\\\\n\\end{gather*}\n\\begin{example}\n    \\begin{gather*}\n        \\mu(\\lambda) = 4, \\gamma(\\lambda) = 2 \\\\\n        D_{\\lambda} = \\begin{bmatrix}\n            \\lambda\n        \\end{bmatrix}\n        B_{\\lambda} = \\begin{bmatrix}\n            \\lambda & 1 & 0 \\\\ 0 & \\lambda & 1 \\\\ 0 & 0 & \\lambda\n        \\end{bmatrix} \\\\\n        J_{\\lambda} = \\begin{bmatrix}\n            \\lambda & 0       & 0       & 0       \\\\\n            0       & \\lambda & 1       & 0       \\\\\n            0       & 0       & \\lambda & 1       \\\\\n            0       & 0       & 0       & \\lambda \\\\\n        \\end{bmatrix}\n    \\end{gather*}\n\\end{example}\n\\begin{example}\n    \\begin{gather*}\n        \\mu(\\lambda) = 4, \\gamma(\\lambda) = 3 \\\\\n        D_{\\lambda} = \\begin{bmatrix}\n            \\lambda & 0 \\\\  0 & \\lambda\n        \\end{bmatrix}\n        B_{\\lambda} = \\begin{bmatrix}\n            \\lambda & 1 \\\\ 0 & \\lambda\n        \\end{bmatrix} \\\\\n        J_{\\lambda} = \\begin{bmatrix}\n            \\lambda & 0       & 0       & 0       \\\\\n            0       & \\lambda & 0       & 0       \\\\\n            0       & 0       & \\lambda & 1       \\\\\n            0       & 0       & 0       & \\lambda \\\\\n        \\end{bmatrix}\n    \\end{gather*}\n\\end{example}\n\\section{Operations}\n\\subsection{Transposing}\nTranspose of a matrix \\( A \\) is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix A by producing another matrix, often denoted by $A^T$.\n\\begin{example}\n    \\begin{align*}\n        \\begin{bmatrix}\n            1 & 2 & 3\n        \\end{bmatrix}^T = \\begin{bmatrix}\n            1 \\\\\n            2 \\\\\n            3 \\\\\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\n\\begin{example}\n    \\begin{align*}\n        \\begin{bmatrix}\n            1 & 2 & 3 \\\\\n            4 & 5 & 6 \\\\\n            7 & 8 & 9 \\\\\n        \\end{bmatrix}^T = \\begin{bmatrix}\n            1 & 4 & 7 \\\\\n            2 & 5 & 8 \\\\\n            3 & 6 & 9 \\\\\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}\nNotice the diagonal elements do not get swaped by transposing. So for any diagonal matrix D holds $D=D^T$.\n\\begin{matlab}\n    \\apilink{transpose}{https://www.mathworks.com/help/matlab/ref/transpose.html}\n    \\begin{lstlisting}\n    A = [1,2,3;4,5,6]\n    transpose(A)\n    ans =\n    1     4\n    2     5\n    3     6\n    \\end{lstlisting}\n\\end{matlab}\n\\subsection{Direct sum}\nThe direct sum of two matrixes \\(A^{a \\times b}\\) and \\(B^{c \\times d}\\) is defined as\n\\begin{equation}\n    \\begin{split}\n        C = A \\oplus B = \\begin{bmatrix}\n            A & N_1 \\\\ N_2 & B\n        \\end{bmatrix} \\\\\n        \\dim C = (a + c) \\times (b + d)\n    \\end{split}\n\\end{equation}\n\\(N_1\\) and \\(N_2\\) are zero matrices with dimensons \\(\\dim N_1 = b\\)\n\\subsection{Diagonalisation}\nA matrix $A$ is diagonalizabe if $A$ is similar (see \\ref{similiarity}) to a diagonal matrix $D$.\n\\begin{equation*}\n    D = U^{-1}AU \\\\\n\\end{equation*}\n\\subsubsection{Eigendecomposition}\nA  matrix can be diagonalized using its eigenvalues and eigenvectors.\nD is a diagonal matrix containing the eigenvalues $\\lambda_i$ on it main diagonal.\nThe the eigenspaces $\\epsilon_i$ form a base called \\textbf{eigenbase} (when the arithmetic multiplicity of an eigenvalue is 1 then $\\epsilon$ is just the eigenvector).\nSo change of base matrix $U$ has the base vectors of the eigenspaces as it's columns.\n\\begin{equation}\n    A = U D U^{-1} \\\\\n\\end{equation}\n\\begin{equation}\n    U = \\begin{bmatrix}\n        v_1 & v_2 \\cdots v_n\n    \\end{bmatrix}\n\\end{equation}\n\\begin{example}\n    \\begin{equation*}\n        A = \\begin{bmatrix}\n            3 & 0 & 1 \\\\ 0 & 2 & 0  \\\\ 5 & 0 & -1\n        \\end{bmatrix}\n    \\end{equation*}\n    The eigenvalues $\\lambda_i$ and eigenvectors $v_i$ are:\n    \\begin{gather*}\n        \\lambda_1 = 4, v_1 = \\begin{bmatrix}\n            1 \\\\ 0 \\\\ 1\n        \\end{bmatrix}  \\\\\n        \\lambda_2 = -2, v_2 = \\begin{bmatrix}\n            -\\frac{1}{5} \\\\ 0 \\\\ 1\n        \\end{bmatrix} \\\\\n        \\lambda_3 = 2, v_3 = \\begin{bmatrix}\n            0 \\\\ 1 \\\\ 0\n        \\end{bmatrix}  \\\\\n    \\end{gather*}\n    We can construct U and D. Keep in mind that the order of the eigenvalues in the diagonal of $D$ must match the order of the order of eigenvector columns in $U$ (and $U^{-1}$).\n    \\begin{align*}\n        D      & = \\begin{bmatrix}\n            2 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & -2\n        \\end{bmatrix}  \\\\\n        U      & =  \\begin{bmatrix}\n            -\\frac{1}{5} & 0 & 1   \\\\\n            0            & 0 & 1 & \\\\\n            1            & 1 & 0   \\\\\n        \\end{bmatrix} \\\\\n        U^{-1} & = \\begin{bmatrix}\n            \\frac{5}{6}   & 0 & \\frac{1}{6} \\\\\n            - \\frac{5}{6} & 0 & \\frac{5}{6} \\\\\n            0             & 1 & 0\n        \\end{bmatrix}\n    \\end{align*}\n    The diagonalized A is:\n    \\begin{equation*}\n        A = \\begin{bmatrix}\n            -\\frac{1}{5} & 0 & 1   \\\\\n            0            & 0 & 1 & \\\\\n            1            & 1 & 0   \\\\\n        \\end{bmatrix} \\begin{bmatrix}\n            2 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & -2\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            \\frac{5}{6}   & 0 & \\frac{1}{6} \\\\\n            - \\frac{5}{6} & 0 & \\frac{5}{6} \\\\\n            0             & 1 & 0\n        \\end{bmatrix}     \\end{equation*}\n    \\begin{matlab}\n        \\begin{lstlisting}\n    >> a = [3,0,1;0,2,0;5,0,-1]\n    >> [v, d] = eig(a)\n        v =\n            0.7071   -0.1961         0\n                0         0    1.0000\n            0.7071    0.9806         0\n        d =\n            4     0     0\n            0    -2     0\n            0     0     2\n    >> v*d*inv(v)\n            ans =\n                3.0000         0    1.0000\n                     0    2.0000         0\n                5.0000         0   -1.0000\n            \n\n   \\end{lstlisting}\n    \\end{matlab}\n    \\subsection{Raising a matrix to the nth power using diagonalisation}\n    Using the definition of matrix multiplication a single squaring a matrix takes \\(O(n^3)\\) computation steps. Raising a matrix to the \\(m\\)th power would take \\(O(m \\cdot n^3)\\) steps.\n    For any diagonal matrix it holds:\n    \\begin{equation}\n        D^{m} = \\begin{bmatrix}\n            x_{11}^{m} &            &        &            \\\\\n                       & x_{22}^{m} &        &            \\\\\n                       &            & \\ddots &            \\\\\n                       &            &        & x_{nn}^{m}\n        \\end{bmatrix}\n    \\end{equation}\n    Using diagonalisation a more effcient calculation can be achieved:\n    \\begin{gather*}\n        A = UDU^{-1} \\\\\n        A^2 = A \\cdot A =  UD \\cancel{U^{-1}  U} DU^{-1} = UD^2U^{-1} \\\\\n        A^3 = A^2 \\cdot A = UD^2 \\cancel{U^{-1} U} D U^{-1} = U D^3 U^{-1}  \\\\\n        \\vdots \\\\\n        A^{n} = U D^n U^{-1}\n    \\end{gather*}\n\\end{example}\n\\subsection{Matrix exponential}\\label{sec:matrixexponent}\nThe taylor series of the exponential functions is given as:\n\\begin{equation}\n    e^{x} = \\sum_{n=0}^{\\infty} \\frac{x^n}{n!} = 1 + x + \\frac{x^2}{2} + \\frac{x^3}{6} \\cdots\n\\end{equation}\nUsing this definition you can define the matrix exponential:\n\\begin{equation}\n    e^{A} = \\sum_{n=0}^{\\infty} \\frac{A^n}{n!} = I + A + \\frac{A^2}{2} + \\frac{A^3}{6} \\cdots\n\\end{equation}\n\\subsubsection{Diagonal Case}\n\\begin{align*}\n    e^{D} & = I +\n    \\begin{bmatrix}\n        x_{11} &        &        &        \\\\\n               & x_{22} &        &        \\\\\n               &        & \\ddots &        \\\\\n               &        &        & x_{nn}\n    \\end{bmatrix} + \\frac{1}{2}\n    \\begin{bmatrix}\n        x_{11}^{2} &            &        &            \\\\\n                   & x_{22}^{2} &        &            \\\\\n                   &            & \\ddots &            \\\\\n                   &            &        & x_{nn}^{2}\n    \\end{bmatrix}  + \\frac{1}{6}\n    \\begin{bmatrix}\n        x_{11}^{3} &            &        &            \\\\\n                   & x_{22}^{3} &        &            \\\\\n                   &            & \\ddots &            \\\\\n                   &            &        & x_{nn}^{3}\n    \\end{bmatrix} + \\frac{1}{24}\n    \\begin{bmatrix}\n        x_{11}^{4} &            &        &            \\\\\n                   & x_{22}^{4} &        &            \\\\\n                   &            & \\ddots &            \\\\\n                   &            &        & x_{nn}^{4}\n    \\end{bmatrix} + \\cdots                                    \\\\\n          & = I + \\begin{bmatrix}\n        x_{11} &        &        &        \\\\\n               & x_{22} &        &        \\\\\n               &        & \\ddots &        \\\\\n               &        &        & x_{nn}\n    \\end{bmatrix} +\n    \\begin{bmatrix}\n        \\frac{x_{11}^{2}}{2} &                      &        &                      \\\\\n                             & \\frac{x_{22}^{2}}{2} &        &                      \\\\\n                             &                      & \\ddots &                      \\\\\n                             &                      &        & \\frac{x_{nn}^{2}}{2}\n    \\end{bmatrix}  +\n    \\begin{bmatrix}\n        \\frac{x_{11}^{3}}{6} &                      &        &                      \\\\\n                             & \\frac{x_{22}^{3}}{6} &        &                      \\\\\n                             &                      & \\ddots &                      \\\\\n                             &                      &        & \\frac{x_{nn}^{3}}{6}\n    \\end{bmatrix} +\n    \\begin{bmatrix}\n        \\frac{ x_{11}^{4}}{24} &                       &        &                       \\\\\n                               & \\frac{x_{22}^{4}}{24} &        &                       \\\\\n                               &                       & \\ddots &                       \\\\\n                               &                       &        & \\frac{x_{nn}^{4}}{24}\n    \\end{bmatrix} + \\cdots                                    \\\\\n          & = \\begin{bmatrix}\n        \\sum_{m=0}^{\\infty} \\frac{x_{11}^m}{m!} &                                         &        &                                         \\\\\n                                                & \\sum_{m=0}^{\\infty} \\frac{x_{22}^m}{m!} &        &                                         \\\\\n                                                &                                         & \\ddots &                                         \\\\\n                                                &                                         &        & \\sum_{m=0}^{\\infty} \\frac{x_{22}^m}{m!}\n    \\end{bmatrix}   =   \\begin{bmatrix}\n        e^{x_{11}} &             &        &            \\\\\n                   & e^{x_{22} } &        &            \\\\\n                   &             & \\ddots &            \\\\\n                   &             &        & e^{x_{nn}}\n    \\end{bmatrix} \\\\\n\\end{align*}\n\\subsection{Diagonalizable case}\nIf \\(A\\) is diagonalizabe with \\(UDU^{-1}\\) then:\n\\begin{align*}\n    e^{A} & = \\sum_{n=0}^{\\infty} \\frac{U D^n U^{-1}}{n!} = U I U^{-1} + \\frac{U D U^{-1}}{n!}  + \\frac{{U D^2 U^{-1}}}{2} + \\frac{U D^3 U^{-1}}{6} \\cdots \\\\\n          & = U^{-1} \\left(\\sum_{n=0}^{\\infty} \\frac{D^n}{n!}\\right)U = U^{-1}e^DU                                                                         \\\\\n          & = U^{-1} \\begin{bmatrix}\n        e^{\\lambda_1} &                &        &               \\\\\n                      & e^{\\lambda_2 } &        &               \\\\\n                      &                & \\ddots &               \\\\\n                      &                &        & e^{\\lambda_n}\n    \\end{bmatrix} U                                                                                                         \\\\\n\\end{align*}\n\\begin{example}\n    \\begin{gather*}\n        A = \\begin{bmatrix}\n            3 & -4 \\\\ -5 & -5 \\\\\n        \\end{bmatrix} \\\\\n        \\lambda_1 = -7, v_1 = \\begin{bmatrix}\n            \\frac{2}{5} \\\\ 1\n        \\end{bmatrix} \\\\\n        \\lambda_2 = 5, v_2 = \\begin{bmatrix}\n            -2 \\\\ 1\n        \\end{bmatrix} \\\\\n        e^D =         \\begin{bmatrix}\n            \\frac{2}{5} & -2 \\\\ 1 & 1\n        \\end{bmatrix}\n        \\begin{bmatrix}\n            e^{-7} & 0 \\\\0 & e^5\n        \\end{bmatrix}\n        \\begin{bmatrix} \\frac{5}{12} & \\frac{5}{6} \\\\ \\frac{-5}{12} & \\frac{1}{6} \\end{bmatrix}\n    \\end{gather*}\n\\end{example}\n\\begin{matlab}\n    \\apilink{expm}{https://www.mathworks.com/help/matlab/ref/expm.html}\n    \\begin{lstlisting}\n     >> a = [3, -4; -5, -5]\n     >> expm(a)\n        ans =\n            123.6778  -49.4707\n            -61.8384   24.7363\n    \\end{lstlisting}\n\\end{matlab}\n\\subsubsection{Comuting matrices}\nIf two matrices \\(A\\) and \\(B\\) commute (\\(AB = BA\\)) then\n\\begin{equation}\n    e^{A + B} = e^{A}e^{B}\n\\end{equation}\n\\subsubsection{Jordan bock}\nA Jordan block \\(B_{\\lambda}\\) of size m can be separated into:\n\\begin{equation}\n    B_{\\lambda} = D_{\\lambda} + S\n\\end{equation}\nwhere \\(S\\) is the shift matrix (the shift matrix is nilpotent of degree \\(m\\)).\n\\begin{align}\n    e^{B_\\lambda} = e^{D_{\\lambda} + S} =  e^{D_{\\lambda}} \\cdot e^{S} \\tag{Note \\(D_{\\lambda} \\) and S commute}\n\\end{align}\n\\begin{align*}\n     & =  e^{D_{\\lambda}} \\cdot e^{S} = e^{D_{\\lambda}} \\left( \\sum_{n=0}^{m - 1} \\frac{S^n}{n!} = I + S + \\frac{S^2}{2} + \\frac{S^3}{6} \\cdots \\right) \\\\\n     & =  e^{D_{\\lambda}} \\left(I + \\begin{bmatrix} 0 & 1 & 0  &  0 & \\cdots \\\\ 0 & 0 & 1 & 0 & \\cdots \\\\ 0 & 0 & 0 & 1 & \\cdots \\\\ \\vdots & & & \\end{bmatrix} +\n    \\frac{1}{2} \\begin{bmatrix} 0 & 0 & 1  &  0 & \\cdots \\\\ 0 & 0 & 0 & 1 & \\cdots \\\\ 0 & 0 & 0 & 0 & \\cdots \\\\ \\vdots & & & \\end{bmatrix} + \\cdots +\n    \\frac{1}{(m-1)!} \\begin{bmatrix} 0 &  \\cdots & 0 & 1  \\\\ 0 & \\cdots & & 0 \\\\  \\vdots & & & \\end{bmatrix}  \\right)                                                                                               \\\\\n     & = e^{D_{\\lambda}} \\begin{bmatrix}\n        1      & 1 & \\frac{1}{2} & \\frac{1}{6} & \\cdots & \\frac{1}{(m -1)!} \\\\\n        0      & 1 & 1           & \\frac{1}{2} & \\cdots & \\frac{1}{(m -2)!} \\\\\n        0      & 0 & 1           & 1           & \\cdots & \\frac{1}{(m -3)!} \\\\\n        \\vdots &   &             &\n    \\end{bmatrix} = \\begin{bmatrix}\n        e^{\\lambda} & e^{\\lambda} & \\frac{1}{2} e^{\\lambda} & \\frac{1}{6}  e^{\\lambda} & \\cdots & \\frac{1}{(m-1)!}    e^{\\lambda} \\\\\n        0           & e^{\\lambda} & e^{\\lambda}             & \\frac{1}{2}  e^{\\lambda} & \\cdots & \\frac{1}{(m-2)!}   e^{\\lambda}  \\\\\n        0           & 0           & e^{\\lambda}             & e^{\\lambda}              & \\cdots & \\frac{1}{(m-3)!}   e^{\\lambda}  \\\\\n        \\vdots      &             &                         &\n    \\end{bmatrix}\n\\end{align*}\n\\begin{example}\n    \\begin{align*}\n        B_2 = \\begin{bmatrix}\n            2 & 1 & 0 & 0 \\\\\n            0 & 2 & 1 & 0 \\\\\n            0 & 0 & 2 & 1 \\\\\n            0 & 0 & 0 & 2 \\\\\n        \\end{bmatrix} \\\\\n        e^{B_2} = \\begin{bmatrix}\n            e^{2} & e^{2} & \\frac{1}{2} e^{2} & \\frac{1}{6} e^{2} \\\\\n            0     & e^{2} & e^{2}             & \\frac{1}{2} e^{2} \\\\\n            0     & 0     & e^{2}             & e^{2}             \\\\\n            0     & 0     & 0                 & e^{2}             \\\\\n        \\end{bmatrix}\n    \\end{align*}\n\\end{example}", "meta": {"hexsha": "644b27b16f08b050c458b9e1ea4dab42d6a856a4", "size": 45023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/matrices.tex", "max_stars_repo_name": "KriCse/Math-knowledge", "max_stars_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/matrices.tex", "max_issues_repo_name": "KriCse/Math-knowledge", "max_issues_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/matrices.tex", "max_forks_repo_name": "KriCse/Math-knowledge", "max_forks_repo_head_hexsha": "92c036c4563999ddaa97888a4023297e22bb7649", "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": 37.86627418, "max_line_length": 246, "alphanum_fraction": 0.4411078782, "num_tokens": 15302, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361652391385, "lm_q2_score": 0.8740772335247531, "lm_q1q2_score": 0.7975396790801607}}
{"text": "\\section{Maximum Likelihood \\& Maximum a Posteriori}\n\\smallskip \\hrule height 2pt \\smallskip\n(Also see paragraph at the end of this PDF near vocab for a MLE/MAP comparison.) \\hfill \\\\\n\n\\underline{Vocab}\n\\begin{itemize}\n\t\\item\\textbf{likelihood}: the probability of the data given a parameter.  E.g. $P(D | \\theta)$ (for discrete like Binomial).  \n\tNeed not a pdf; need not be normalized.   %  http://www.robots.ox.ac.uk/~az/lectures/est/lect34.pdf  + Erick\n \t\\item \\textbf{log-likelihood}: lower-case: $l(\\theta|x) = \\log L(\\theta | x)$\n\t\\item \\textbf{maximum likelihood} (ML): \n\t\\item \\textbf{MLE}: Maximum Likelihood Estimation. \n\t\\item \\textbf{PAC}: Probability Approximately Correct. \n\t\\item \\textbf{Posterior}: the likelihood times the prior, normalized  % Murphy 2012 pg 70\n\\end{itemize}\n \n\\underline{MLE}: Maximum Likelihood Estimation \\hfill \\\\\nChoose $\\theta$ to maximize probability of D. \\hfill \\\\\nSet derivative of \\_\\_ to zero and solve.  If function is multivariate, set each partial derivative to zero and solve. \\hfill \\\\\n$\\hat{\\theta} = \\argmax_\\theta P(D | \\theta) = \\argmax_\\theta \\ln P(D | \\theta) $ \\hfill \\\\\nNote we are using $\\ln$, not $\\log_2$ as we did for entropy above.  Want it to cancel exponents now. \n \\hfill \\\\\n \n\\hfill \\\\\n\\underline{Binomial Distribution} \\hfill \\\\\nAssumes i.i.d: $D=\\{x_i | i=1 \\dots n\\}, P(D | \\theta) = \\prod_i P(x_i \\mid \\theta)$. \\hfill \\\\\nLikelihood function: $P(D | \\theta) = \\theta^{\\alpha_H} (1-\\theta)^{\\alpha_T}$  \\hfill \\\\\nP(heads) = $\\theta$, P(tails) = $1 - \\theta$ \\hfill \\\\\n\\begin{align*} \n\t\\hat{\\theta} &= \\argmax_\\theta \\ln P(D| \\theta) \\\\\n\t \t &= \\argmax_\\theta \\ln \\theta*{\\alpha H}(1-\\theta)^{\\alpha T}\n\\end{align*}\nFind optimal theta by setting the derivative to zero: \n\\begin{align*} \n\t\\frac{d}{d\\theta} \\ln P(D| \\theta) &= \\frac{d}{d\\theta}  \\ln \\theta*{\\alpha H}(1-\\theta)^{\\alpha T} \\\\\n\t \t &= \\argmax_\\theta \\ln \\theta*{\\alpha H}(1-\\theta)^{\\alpha T} \\\\\n\t\t & = \\dots = \\frac{\\alpha_H}{\\alpha_H  + \\alpha_T}\n\\end{align*}\n\nFor Binomial, there is exponential decay in uncertainty with \\# of observations.  % slide 7 at http://courses.cs.washington.edu/courses/cse446/16wi/Slides/3_PointEstimation.pdf\nYou can also find the probability that you are approximately correct (see \\href{http://courses.cs.washington.edu/courses/cse446/16wi/Slides/3_PointEstimation.pdf}{notes}).  \\hfill \\\\\n$P(|\\widehat{\\theta} = \\theta*| \\geq \\epsilon) \\leq 2e^{-2N\\epsilon^2}$.  Can calculate N (\\# of flips) to have error less than $\\epsilon$ with probability of being incorrect $\\delta$.  Your sensitivity depends on your problem; error on stock market data might cost billions. \n\nWhat if you had prior beliefs?  Use MAP instead of MLE.\n\n", "meta": {"hexsha": "680f09a652fc38ec83ceed48fc122f7492ec4c9a", "size": 2691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/likelihood.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/likelihood.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/likelihood.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": 59.8, "max_line_length": 276, "alphanum_fraction": 0.6889632107, "num_tokens": 859, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8740772286044095, "lm_q1q2_score": 0.7975396766719254}}
{"text": "%% Solution of part 1\n\\subsubsection*{1.A}\nSince the input signal $r_k$ is white, the $R$ matrix only has non-zero entries in its main diagonal:\n\n\\begin{equation}\nR = \\mathrm{diag}([1, \\sigma^2_r, \\ldots, \\sigma^2_r]) \\implies \\mathrm{tr}(R) = (L+1)\\sigma^2_r + 1,\n\\end{equation} \nwhere the first entry is 1 because the bias weight input is always $+1$. Therefore,\n\\begin{equation}\n\\mu = 0.01\\frac{1}{\\mathrm{tr}(R)} = \\frac{0.01}{(L+1)\\sigma^2_r + 1} = 2.439\\times 10^{-4}.\n\\end{equation}\n\n\\subsubsection*{1.B}\nThe Matlab code to calculate the learning curve is included below. Figure~\\ref{fig:part1-learning-curve} shows the learning curve averaged over 100 independent input realizations, and  Figure~\\ref{fig:part1-weights} shows the converged weight vector. Note that the bias weight value is very significant.\n\n\\FloatBarrier\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.8]{part1_learning_curve.eps}\n\t\\caption{Experimental learning curve for nonlinear plant indemnification using a linear filter. The learning curve was averaged 100 times.}\n\t\\label{fig:part1-learning-curve}\n\\end{figure}\n\\FloatBarrier\n\n\\FloatBarrier\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.8]{part1_weights.eps}\n\t\\caption{Weight vector after convergence.}\n\t\\label{fig:part1-weights}\n\\end{figure}\n\\FloatBarrier\n\n\\subsubsection*{1.C}\nAs shown in Figure~\\ref{fig:part1-learning-curve}, the MMSE estimated using the last 200 samples was equal to $\\approx 0.051$.\n\n\\subsubsection*{1.D}\nAs discussed in class, the convergence time of the learning curve depends on the eigenvalues of the matrix $R$. Since $R$ is a diagonal matrix, its eigenvalues are equal to the entries in the main diagonal:\n\\begin{equation}\n\\lambda_1 = 1, \\qquad \\lambda_2 = \\ldots = \\lambda_{L+2} = \\sigma_r^2.\n\\end{equation}\n\nThe time constants $\\tau_n = 1/2\\mu\\lambda_n$ are therefore\n\\begin{equation}\n\\tau_1 = \\frac{1}{2\\mu}, \\qquad \\tau_2 = \\ldots = \\tau_{L+2} = \\frac{1}{2\\mu\\sigma_r^2}.\n\\end{equation}\n\nThe learning curve has two modes. One due to the bias weight, and another due to the signal inputs. The slowest mode will determine the convergence time of the learning curve. \n\nIn the first case, when $\\sigma_r^2 = 4$, the slowest mode is due to the bias weight since $\\tau_n < \\tau_1, n > 1$. Therefore, the slowest time constant is $\\tau_1 = 2050$. The approximate number of iterations for convergence is given by $(T_{mse})_1 = 0.5\\tau_1 = 1025$, which we can verify this from Figure~\\ref{fig:part1-learning-curve}.\n\nWhen, $\\sigma_r^2$ is made small. The mode due to the signal inputs will become the slowest one. And since we're assuming that $(L+1)\\sigma_r^2 << 1$, the time constant due to the input signals is inversely proportional to the signal variance $\\sigma_r^2$, as $\\mu\\approx 0.01$. Thus, the time constant is $\\tau_n = 50/\\sigma_r^2 >> 2050$. Therefore, the convergence time of the learning curve increases as we decrease the input signal power.\n\nAs for the MMSE, the MMSE is smaller for smaller $\\sigma_r^2$. When the input signal is small enough to make the plant nonlinearity negligible, the plant is essentially the linear filter $\\frac{1}{2}H_1(z)H_2(z)$, which is an FIR filter with 11 taps. The factor of $\\frac{1}{2}$ appears because $g(x) \\approx x/2, x \\to 0$, which follows from the Taylor series expansion of $g(x)$. The adaptive filter has 10 taps plus the bias weight, and thus it could model the plant not perfectly, but very well. \n\n\\subsubsection*{1.E}\nThe Matlab code is the same as for part (B) and it is shown below. The output of the plant is compared to the output of the adaptive filter in Figure~\\ref{fig:part1-test}.\n\n\\FloatBarrier\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.8]{part1_test.eps}\n\t\\caption{Test of the adaptive filter after convergence with a sinusoidal signal. During the first $L+1$ samples, the filter was being initialized.}\n\t\\label{fig:part1-test}\n\\end{figure}\n\\FloatBarrier\n", "meta": {"hexsha": "937b82ef2d661c8a5399de55c936aeb71b7c39c7", "size": 3926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exams/final/practice final/tex/solutions_part1.tex", "max_stars_repo_name": "jkperin/DSP", "max_stars_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 21, "max_stars_repo_stars_event_min_datetime": "2019-05-11T21:48:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-07T08:56:28.000Z", "max_issues_repo_path": "exams/final/practice final/tex/solutions_part1.tex", "max_issues_repo_name": "jkperin/DSP", "max_issues_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exams/final/practice final/tex/solutions_part1.tex", "max_forks_repo_name": "jkperin/DSP", "max_forks_repo_head_hexsha": "0ec74b4597fb54800ebdab440cba4892d210343d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2019-04-16T01:11:14.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T07:25:20.000Z", "avg_line_length": 58.5970149254, "max_line_length": 500, "alphanum_fraction": 0.7435048395, "num_tokens": 1172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.874077230244524, "lm_q1q2_score": 0.7975396698433688}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ -3 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Which of the following vectors are in\n  $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_4}$? For each vector that is\n  in the span, exhibit a linear combination of\n  $\\vect{u}_1,\\ldots,\\vect{u}_4$ that equals this vector.\n  \\begin{equation*}\n    (a)\\quad\n    \\vect{x} = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -1 \\end{mymatrix},\n    \\qquad\n    (b)\\quad\n    \\vect{y} = \\begin{mymatrix}{r} 2 \\\\ -3 \\\\ -4 \\end{mymatrix},\n    \\qquad\n    (c)\\quad\n    \\vect{z} = \\begin{mymatrix}{r} 1 \\\\ 5 \\\\ -2 \\end{mymatrix}.\n  \\end{equation*}\n  \\vspace{-2ex}\n  \\begin{sol}\n    (a) $\\vect{x}$ is not in the span.\n    (b) $\\vect{y} = 7\\vect{u}_1-5\\vect{u}_2$.\n    (c) $\\vect{z} = -3\\vect{u}_1+4\\vect{u}_2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Describe the span of the vectors\n  $\\vect{u}=\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 2 \\end{mymatrix}$ and\n  $\\vect{v}=\\begin{mymatrix}{r} 2 \\\\ -1 \\\\ 1 \\end{mymatrix}$ in\n  $\\R^3$.\n  \\begin{sol}\n    It is the plane $2x + 3y - z = 0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Describe the span of the following vectors in $\\R^4$:\n  \\begin{equation*}\n    \\vect{u}_1=\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\\\ -1 \\end{mymatrix},\\quad\n    \\vect{u}_2=\\begin{mymatrix}{r} 5 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_3=\\begin{mymatrix}{r} 0 \\\\ -2 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_4=\\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    It is the hyperplane given by the equation $x - 2y - 3z + 2w = 0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u}=\\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 0 \\end{mymatrix}$,\n  $\\vect{v}=\\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 5 \\end{mymatrix}$, and\n  $\\vect{w}=\\begin{mymatrix}{r} 1 \\\\ 0 \\\\ -1 \\end{mymatrix}$.\n  Show that\n  $\\sspan\\set{\\vect{u},\\vect{v},\\vect{w}} =\n  \\sspan\\set{\\vect{u},\\vect{v}}$.\n\\end{ex}\n\n\\begin{ex}\n  Suppose $\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$ is a set of\n  vectors from $\\R^n$. Show that\n  $\\vect{0}\\in\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_k}$.\n  \\begin{sol}\n    $0\\vect{u}_1+\\ldots+0\\vect{u}_k = \\vect{0}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_5$ of integers\n  modulo $5$ instead of real numbers (see Section~\\ref{sec:fields},\n  ``Fields''). Consider the vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 4 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  Which of the following vectors are in\n  $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_4}$? For each vector that is\n  in the span, exhibit a linear combination of\n  $\\vect{u}_1,\\ldots,\\vect{u}_4$ that equals this vector.\n  \\begin{equation*}\n    (a)\\quad\n    \\vect{x} = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 4 \\end{mymatrix},\n    \\qquad\n    (b)\\quad\n    \\vect{y} = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\end{mymatrix},\n    \\qquad\n    (c)\\quad\n    \\vect{z} = \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 4 \\end{mymatrix}.\n  \\end{equation*}\n  \\vspace{-2ex}\n  \\begin{sol}\n    (a) $\\vect{x} = 3\\vect{u}_2$.\n    (b) $\\vect{y}$ is not in the span.\n    (c) $\\vect{z} = 2\\vect{u}_1 + 1\\vect{u}_2$.\n  \\end{sol}\n\n\\end{ex}\n", "meta": {"hexsha": "fe32299ed27e961a2d8874e219f9e3a216185ca7", "size": 3547, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/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/exercises/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/exercises/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": 33.4622641509, "max_line_length": 74, "alphanum_fraction": 0.5759797012, "num_tokens": 1584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.885631484383387, "lm_q1q2_score": 0.7975375264825337}}
{"text": "\\section*{Data Clustering \\& Mixture Models}\n\\subsection*{K-Means}\n$\\mathbf{Z} \\in \\{0,1\\}^{N\\times K}$ (if point $i$ assigned to cluster $j$) \\\\\n\\textbf{Target:} $\\min_{\\mathbf{U}, \\mathbf{Z}} J(\\mathbf{U}, \\mathbf{Z}) = \\|\\mathbf{X} - \\mathbf{U} \\mathbf{Z}\\|_F^2$\\\\\n$= \\sum_{n=1}^N \\sum_{k=1}^K \\mathbf{z}_{k,n} \\|\\mathbf{x}_n - \\mathbf{u}_k\\|_2^2$\\\\\n1. \\textbf{Initiate:} choose $K$ centroids $\\mathbf{U} = [\\mathbf{u}_1, \\ldots, \\mathbf{u}_K]$\\\\\n2. \\textbf{Cluster Assign:} assign data points to closest cluster  $z_{ij}^* = 1 \\text{ if } j=\\argmin_k||\\mathbf{x}_i - \\mathbf{u}_k||^2 \\text{ else } 0$\\\\\n3. \\textbf{Update centroids}: $\\mathbf{u}_k = \\frac{\\sum_{n=1}^N z_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N z_{k,n}}$. Repeat 2\\\\\nStop if $||\\mathbf{Z} - \\mathbf{Z_{new}}||_F^2 = 0$. \nGuaranteed to converge to local optimum.\nComputational cost: $O(k\\cdot n \\cdot d)$\n\\subsection*{Gaussian Mixture Models (GMM)}\n$p(x;\\mu;\\Sigma)=\\frac{1}{|\\Sigma|^{\\frac{1}{2}}(2\\pi)^{\\frac{D}{2}}}\\mathit{exp}[-\\frac{1}{2}(x-\\mu)^T \\Sigma^{-1} (x-\\mu)]$ \\\\\n$\\int \\mathcal{N}(z;\\mu, \\Sigma) \\log(\\mathcal{N}(z;0,I)) dz = E_z[\\mathcal{N}(z;0, I)]$\\\\\n$=-D/2 \\log(2\\pi)-1/2 \\sum_{i=1}^D(\\mu_i^2 + \\sigma_i^2)$ \\\\\nFor GMM let $\\boldsymbol{\\theta}_k = (\\boldsymbol{\\mu}_k, \\boldsymbol{\\Sigma}_k)$; $p_{\\theta_k}(\\mathbf{x}) = \\mathcal{N}(\\mathbf{x} | \\boldsymbol{\\mu}_k, \\Sigma_k)$\\\\\n\\textbf{Mixture Models:} $p_\\theta(\\mathbf{x}) = \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x})$\\\\\n\\textbf{Generate:}\nsample cluster $j \\sim Categorical(\\pi)$, \\\\\nsample data from $j$-th cluster: $x \\sim \\mathcal{N}(\\mu_j, \\Sigma_j)$\\\\\n\\textbf{Assignment variable (generative model):} \\\\\n$z_{ij} \\in \\{0, 1\\}$, $\\sum_{j=1}^k z_{ij} = 1$\\\\\n$\\operatorname{Pr}(z_k = 1) = \\pi_k \\Leftrightarrow p(\\mathbf{z}) = \\prod_{k=1}^K \\pi_k^{z_k}$\\\\\n\\textbf{Complete data distribution:}\\\\\n$p_\\theta(\\mathbf{x}, \\mathbf{z}) = \\prod_{k=1}^K \\left( \\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})\\right)^{z_k}$\\\\\n\\textbf{Posterior Probabilities:} $\\\\\\operatorname{Pr}(z_k = 1 | \\mathbf{x}) = \\frac{\\operatorname{Pr}(z_k = 1) p(\\mathbf{x} | z_k = 1)}{\\sum_{l=1}^K \\operatorname{Pr}(z_l = 1) p(\\mathbf{x} | z_l = 1)} = \\frac{\\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})}{\\sum_{l=1}^K \\boldsymbol{\\pi}_l p_{\\theta_l}(\\mathbf{x})}$\\\\\n$\\text{posterior } p(A|B)=\\frac{\\text{prior } p(A)\\ \\times \\ \\text{likelihood } p(B|A)}{\\text{evidence } p(B)}$\\\\\n\\textbf{Likelihood of observed data $\\mathbf{X}$:}\\\\\n$p_\\theta(\\mathbf{X}) = \\prod_{n=1}^N p_\\theta(\\mathbf{x}_n) = \\prod_{n=1}^N \\left(\\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)$\n\\textbf{Max. Likelihood Estimation (MLE):}\\\\\n$\\argmax_\\theta\\sum_{n=1}^N \\log \\left( \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)$ (mult. 1)\\\\\n$\\ge \\sum_{n=1}^N \\sum_{k=1}^K{q_{nk}[\\log p_{\\theta_k}(\\mathbf{x}_n) + \\log \\pi_k - \\log q_{nk}]}$\\\\\nwith $\\sum_{k=1}^K{q_{nk}} = 1$ by Jensen Inequality.\n\\subsection*{Expectation-Maximization (EM) for GMM}\n\\textbf{E-Step:}\n$Pr[z_{j}=1|\\mathbf{x}_i] = q_{ij}=\\frac{\\pi_j p(\\mathbf{x}_i;\\theta_j)}{\\sum_{l=1}^K \\pi_l p(\\mathbf{x}_i;\\theta_l)}$ \\\\\n\\textit{Derivation:} Can maximize independent of $i$. Take derivative of lower bound w.r.t. $q_{ij}$ with Lagrangian: $\\lambda(\\sum_j q_{ij} -1)$ to get: $\\log \\pi_j +\\log p(x_i|\\mu_j, \\Sigma_j)-\\log q_{ij} - 1 + \\lambda = 0 \\to q_{ij}=\\pi_j p(x_i|\\mu_j, \\Sigma_j) e^{\\lambda-1}$. Now use $\\sum_j q_{ij}=\\sum_j \\pi_j p(x_i|\\mu_j, \\Sigma_j)e^{\\lambda-1}=1 \\to e^{\\lambda -1}= 1/(\\sum_j pi_j p(x_i|\\mu_j, \\Sigma_j))$ and plug in. \n\\\\\n\\textbf{M-Step:} \n$\\boldsymbol{\\mu}_j^{*} := \\frac{\\sum_{i=1}^N q_{ij} \\mathbf{x}_i}{\\sum_{i=1}^N q_{ij}}$\n$, \\pi_j^* := \\frac{1}{N} \\sum_{i=1}^N q_{ij}$\\\\\n$\\Sigma_k^{*} = \\frac{\\sum_{i=1}^N q_{ij} (\\mathbf{x}_i - \\boldsymbol{\\mu}_j)(\\mathbf{x}_i - \\boldsymbol{\\mu}_j)^\\top}{\\sum_{i=1}^N q_{ij}}$\\\\\n\\textit{Derivations:}  Take derivative of lower bound w.r.t. $\\pi_k$ with Lagrangian: $\\lambda (\\sum_k \\pi_k - 1)$ to get $\\sum_i q_{ik} (1 / \\pi_k) + \\lambda = 0 \\to \\pi_k = (\\sum_i q_{ik}) / \\lambda$. Then use $\\sum_k \\pi_k=1 \\to (\\sum_k \\sum_i q_{ik})/\\lambda = N / \\lambda = 1 \\to \\lambda = 1 / N$ and plug in. For $\\mathbf{\\mu}_k$: $-\\sum_i q_{ik} \\Sigma_k^{-1}(\\mathbf{x}_i - \\mathbf{\\mu}_i)=\\Sigma_k^{-1}\\sum_i q_{ik}(\\mathbf{x}_i - \\mathbf{\\mu}_k)$ (note: $\\Sigma$ is symmetric \\& invertible so $Ax=0$ iff $x=0$), so $\\sum_i q_{ik}(\\mathbf{x}_i - \\mathbf{\\mu}_k) = 0 \\to \\mathbf{\\mu}_k = (\\sum_i q_{ik}\\mathbf{x_i}) / (\\sum_i q_{ik})$\n\\\\\nGuaranteed to converge to local optimum. \\\\\n\\textbf{Comparison to K-Means}\\\\\nSoft assignments (not hard), learn cov. matrix (not spherical clusters), slow (not fast), more (not less) iterations, use K-means as initialization (use sample coveriance as matrix, use fraction of datapoints as mixing weights). K-means as a special case of GMM with covariances $\\Sigma_j = \\sigma^2 I$. in the limit of $\\sigma \\rightarrow 0$, recover K-means (hard assignments). \\\\\n\\textbf{Model Order Selection (AIC / BIC for GMM)}\\\\\nTrade-off between data fit (i.e. likelihood $p(\\mathbf{X} | \\theta)$) and complexity (i.e. \\# of free parameters $\\kappa(\\cdot)$). Compare for different parameters and take smallest:\\\\\n$\\operatorname{AIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\kappa(\\theta)$\\\\\n$\\operatorname{BIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\frac{1}{2} \\kappa(\\theta) \\log N$ \\\\\n(penalizes complexity more)\\\\\n\\textbf{Example:} \\#free params, fixed cov. matrix: $\\kappa(\\theta) = K \\cdot D + (K - 1)$ ($K$: \\# clusters, $D$: $\\mathsf{dim}\\text{(data)}=\\mathsf{dim}(\\mu_i)$), full cov. matrix: $\\kappa(\\theta) = K(D + \\frac{D(D+1)}{2}) + (K - 1)$.", "meta": {"hexsha": "eac69888e396fdd8db8e5e946e1dbbadd740de12", "size": 5608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mixture.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": "Mixture.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": "Mixture.tex", "max_forks_repo_name": "anklinv/Computational-Intelligence-Lab-ETH-FS19", "max_forks_repo_head_hexsha": "2ef62f626fa83d1410fbb1b2f8a0501937c0dabe", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-02-06T16:55:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-21T01:02:09.000Z", "avg_line_length": 105.8113207547, "max_line_length": 642, "alphanum_fraction": 0.6223252496, "num_tokens": 2380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9621075690244281, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7975282976783077}}
{"text": "\\subsection{Velocities}\nSuppose $f(t)$ is a position function of an object, representing the displacement of the object from the origin at time $t$.\nIn terms of derivatives, the \\dfont{velocity of an object is:}\n$$v(a)=f'(a)$$\nThe change of velocity with respect to time is called the \\dfont{acceleration} and can be found as follows:\n$$a(t)=v'(t)=f''(t).$$\nAcceleration is the derivative of the velocity function and the second derivative of the position function.\n\n\\begin{example}{Position, Velocity and Acceleration}{PositionFunction}\nSuppose the position function of an object is $f(t)=t^2~metres$ at $t$ seconds.\nFind the velocity and acceleration of the object at time $t=1s$.\n\\end{example}\n\n\\begin{solution} \nBy the definition of velocity and acceleration we need to compute $f'(t)$ and $f''(t)$.\nUsing the definition of derivative, we have,\n$$f'(t)=\\lim_{h\\to 0}\\frac{(t+h)^2-t^2}{h}=\\lim_{h\\to 0}\\frac{2th+h^2}{h}=\\lim_{h\\to 0}(2t+h)=2t.$$\nTherefore, $v(t)=f'(t)=2t$.\nThus, the velocity at time $t=1$ is $v(1)=2~m/s$.\nWe now have that the acceleration at time $t$ is:\n$$a(t)=f''(t)=\\lim_{h\\to 0}\\frac{2(t+h)-2t}{h}=\\lim_{h\\to 0}\\frac{2h}{h}=2.$$\nTherefore, $a(t)=2$.\nSubstituting $t=1$ into the function $a(t)$ gives $a(1)=2~m/s^2$.\n\\end{solution}\n", "meta": {"hexsha": "90293cee6a9af3ba069a627fc4c20e76d45d609d", "size": 1257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-3-3-velocities.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "4-derivatives/4-3-3-velocities.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "4-derivatives/4-3-3-velocities.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": 50.28, "max_line_length": 124, "alphanum_fraction": 0.6961018298, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947179030094, "lm_q2_score": 0.8438951084436076, "lm_q1q2_score": 0.7974764199433965}}
{"text": "\\chapter{Exponential Decay}\n\nIn a previous chapter, we saw that an investment of $P$ getting\ncompound interest with an annual interest rate of $r$, grows\nexponentially. At the end of year $t$, your balance would be\n\n$$P\\left(1 + r\\right)^t$$\n\nBecause $r$ is positive, this number grows as time passes.  You get a\nnice exponential growth curve that looks something like this:\n\n\\includegraphics[width=0.7\\textwidth]{exponential_growth.png}\n\nThis is \\$30 invested with 10\\% annual interest rate. So the formula\nfor the balance after $t$ years would be\n\n$$(30)(1.1)^t$$\n\nWhat if $r$ were negative? This would be \\textit{exponential decay}.\n\n\\section{Radioactive Decay}\n\nUntil around 1970, there were companies making watches whose faces and\nhands were coated with radioactive paint. The paint usually contained\nradium. When a radium atom decays, it gives off some energy, loses two\nprotons and two neutrons, and becomes becomes a different element\n(radon). Some of the energy given off is visible light. Thus, these\nwatches glow in the dark.\\index{radioactive decay}\n\nHow many of the radium atoms in the paint decay each century? About 4.24\\%.\n\nNotice the quantity of atoms lost is proportional to the number of\natoms you have. This is exponential decay. If we assume that we start\nwith a million radium atoms, the number of atoms decreases over time like this:\n\n\\includegraphics[width=0.7\\textwidth]{radium_decay.png}\n \n\\begin{itemize}\n\\item We start off with 1,000,000 atoms.\n\\item At 16 centuries, we have only 500,000 (half as many) left.\n\\item 16 centuries after that, we have only 250,000 (half again) left.\n\\item 16 centures after that, we have only 125,000 (half again) left.\n\\end{itemize}\n\nA nuclear chemist would say that radium has a \\textit{half-life} of\n1,600 years. Note that this means that if you bought a watch with\nglowing hands in 1960, it will be glowing half as brightly in the year\n3560.\\index{half-life}\n\nHow do we calculate the amount of radium left at the end of century\n$t$? If you start with $P$ atoms, at the end of the $t$-th century you\nwill have\n\n$$P\\left(1 - 0.0424\\right)^t$$\n\nThis is exponential decay.\\index{exponential decay}\n\n\\section{Model Exponential Decay}\n\nLet's say you get hired to be run a company with 480,000\nemployees. Each year $1/8$ of your employees leave the company for\nsome reason (retirement, quitting, etc.). For some reason, you never\nhire any new employees.\n\nMake a spreadsheet that indicates how many of the original 480,000\nemployees will still be around at the end of each year for the next 12.  Then make a\nbar graph from that data.\n", "meta": {"hexsha": "a40f2affb3b5de92a60dee779305a809cb81568c", "size": 2590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Spreadsheets/exponential_decay-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/exponential_decay-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/exponential_decay-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.0882352941, "max_line_length": 84, "alphanum_fraction": 0.7640926641, "num_tokens": 692, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.7973629576064643}}
{"text": "\n\\subsection{Special orthogonal groups \\(SO(n, F)\\)}\n\nThe special orthogonal group, \\(SO(n,F)\\), is the subgroup of the orthogonal group where \\(|M|=1\\).\n\nAs a result it includes only the rotation operators, not the flip operators.\n\n\\(SO(3)\\) is rotations in 3d space.\n\n\\(SO(2)\\) is rotations in 2d space.\n\n\\subsubsection{Determinant of the orthogonal group}\n\nThe orthogonal group has determinants of \\(-1\\) or \\(1\\).\n\n\\(O^T=O^{-1}\\)\n\n\\(\\det (O^T)=\\det (O^{-1})\\)\n\n\\(\\det O=\\dfrac{1}{\\det O}\\)\n\n\\(\\det O=\\pm 1\\)\n\n", "meta": {"hexsha": "8cd5b0fb76cf9aea388e0fde9e4946d39a16362d", "size": 513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/05-01-SO.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-01-SO.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-01-SO.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 21.375, "max_line_length": 99, "alphanum_fraction": 0.6471734893, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632876167044, "lm_q2_score": 0.8596637469145053, "lm_q1q2_score": 0.7972205985835301}}
{"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 $\\mathcal{X}$ be a set of examples.\nSuppose that the hypotheses space consists of \\textit{all} functions $h : \\mathcal{X} \\longrightarrow \\{-\\infty, \\infty \\}$.\nProve that any unobserved example satisfies exactly half of hypotheses in the current version space, regardless of which training examples had been observed.\n\n\\subsection*{Solution}\n\nProve is given by induction on the number $n$ of attributes.\n\n\\begin{itemize}\n\\item \\textit{Base case} ($n = 1$)\\\\\nWhen we have only one attribute, the set of hypotheses $\\mathcal{H}$ would only have two elements $h_1$ and $h_2$ where $h_1$ is $x_1$ and $h_2$ is $\\bar{x_1}$.\nAs set of possible unobserved examples has only two elements $x_1$ and $\\bar{x_1}$, we argue that $x_1$ is either positive or negative but not both at the same time.\nIf $x_1$ is positive, it only satisfies hypothesis $h_1$.\nIf it is negative, it only satisfies $h_2$.\nSame argument can be made for $\\bar{x_1}$.\nThus exactly half of hypotheses in version space would be satisfied.\n\n\\item \\textit{Induction Step}\\\\\nWhen there are $k$ attributes, set of hypotheses space would have $2^k$ elements $h_i$ where $1 \\leq i \\leq 2^k$.\nWe define set of unobserved examples in this case as $\\mathcal{S}$.\n$\\mathcal{S}$ would have $2^k$ elements as well.\nWe form the inductive hypothesis as any unobserved example $c$ would satisfy exactly half of the possible hypotheses in current version space.\nOur objective now is to show that the statement would still hold true if we add one more attribute.\n\nBy adding one more attribute $x_{k+1}$, number of hypotheses in set of hypotheses space as well as number of elements in set of possible unobserved examples $\\mathcal{S}^{\\prime}$ would change to $2^{k+1}$.\nWe can write $\\mathcal{S}^{\\prime}$ as given by Equation \\ref{eq21}.\n\n\\begin{equation}\\label{eq21}\n\\mathcal{S}^{\\prime} = \\{c^{\\prime} | c^{\\prime} \\in \\{cx_{k+1}, c\\overline{x_{k+1}}, \\overline{c}x_{k+1}, \\overline{c}\\overline{x_{k+1}}\\}, c \\in \\mathcal{S} \\}\n\\end{equation}\n\nNow we can argue, if $x_{k+1}$ is positive only hypotheses that are satisfied by examples of the form $cx_{k+1}$ or $\\overline{c}x_{k+1}$ are satisfied and if $x_{k+1}$ is negative, only hypotheses that are satisfied by examples of the form $c\\overline{x_{k+1}}$ or $\\overline{c}\\overline{x_{k+1}}$ are satisfied.\nThus any concept $c$ would satisfy exactly half of hypotheses in $\\mathcal{S}^{\\prime}$.\n\n\\end{itemize}\n", "meta": {"hexsha": "d33466b93db053ce0885a24e49f8587c0657623c", "size": 2786, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q02.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q02.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 61.9111111111, "max_line_length": 313, "alphanum_fraction": 0.696338837, "num_tokens": 811, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7972205951906265}}
{"text": "\n\\subsection{Measure space}\n\nIn a metric space, the structure was defining a value for each two elements of the set.\n\nIn a measure space, the structure defines a value of subsets of the set.\n\nA measure space includes the set \\(X\\), subsets of the set, \\(\\Sigma \\), and a function \\(\\mu \\) which maps from \\(\\Sigma \\) to \\(\\mathbb{R}\\).\n\n\\subsubsection{Sigma algebra}\n\nRequirement for \\(\\Sigma \\).\n\n", "meta": {"hexsha": "84e6c7449fe75d108ed73969b102e0de06186750", "size": 398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/measures/01-01-measures.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/measures/01-01-measures.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/measures/01-01-measures.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.4285714286, "max_line_length": 143, "alphanum_fraction": 0.7060301508, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625050654264, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7971932464678041}}
{"text": "\\chapter{Vector spaces}\n\nIn Chapter~\\ref{cha:vectors-rn}, we considered $\\R^n$, the set of\n$n$-dimensional column vectors. We now introduce a more general\nconcept of ``vector'', as an element of an abstract vector\nspace. Basically, vectors are entities that can be added and\nscaled. While some vectors look like lists of numbers (for example,\ncolumn vectors, row vectors), other kinds of vectors don't look like\nlists of numbers at all (for example, functions, polynomials). Part of\nthe power of linear algebra comes from our ability to find vector\nspaces in many unexpected places.\n\nMuch of the content of this chapter will be a repetition of things we\nhave already seen in Chapter~\\ref{cha:vectors-rn} in the context of\n$\\R^n$. For example, we will be talking about linear combinations,\nlinear independence, spanning sets, bases, subspaces, linear\ntransformations, and so on. We initially introduced these concepts in\nthe context of the vector space $\\R^n$, so that they would be easier\nto understand. We will now see that they in fact apply to \\textit{all}\nvector spaces.\n\n", "meta": {"hexsha": "ec723bd65d537ff95693334e646ec4925b39fd44", "size": 1076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/VectorSpaces.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/VectorSpaces.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.9090909091, "max_line_length": 70, "alphanum_fraction": 0.7788104089, "num_tokens": 250, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8723473779969194, "lm_q1q2_score": 0.7970433154362968}}
{"text": "\n\\subsubsection{Discrete Distributions}\n\nThe discrete distributions packages contains the following. \n\n\\subsubsection*{Binomial}\n\nThe binomial distribution (class name Binomial) has the parameters $p$ for the prior proportion of successes and $n$ for the total number of trials and calculates the probability of $y$ successes \n$$\nP(y; n; p) = \\sum_{i=1}^n {n \\choose y_i} p^y_i (1-p)^{n-y_i} \n$$\nThe properties of the binomial are:\\\\\\\\\nMean: $\\mu = np$\\\\\nVariance: $\\sigma^2 = np \\left( 1-p \\right) = npq$\n\n\n\\subsubsection*{Geometric Distribution}\nThe geometric distribution (class name Geometric) with 1 parameter for probability p and $y \\ge 1$.\nThe variable represents the nth trial where the success occurs (for instance if y=2 then the trial was successful on the 2nd attempt). The parameter p represents the probability of success. The probability  function calculates the probability of success at the nth trial.\n$$\nP(y;p) = p(1-p)^{y-1}\n$$\nThe simple properties of the distribution are:\\\\\\\\\nMean: $\\mu = \\frac{1}{p}$\\\\\nVariance: $\\sigma^2 = \\frac{1-p}{p^2}$\n\n\\subsubsection*{Hyper Geometric Distribution}\nThe Hypergeometric (class name HyperGeometric) distribution represents the probability of choosing y number of events of the same kind from a subset of r like items within a population of all N possible items (of different kinds) for the sample of size n containing the mixed items. The constraints are such that $r \\le n \\le N$ and $y \\le r \\le n$. The parameters are $y,r,n,N$.\nThe probability distribution is defined as follows.\n$$\nP(y; r,n,N) = \\frac{ {r \\choose y } {{N - r} \\choose {n - y} } } {  {N \\choose n} }\n$$\nThe simple properties of the distribution are:\\\\\\\\\nMean: $\\mu = \\frac{nr}{N}$\\\\\nVariance: $\\sigma^2 = n \\left( \\frac{r}{N} \\right) \\left( \\frac{N - r}{N} \\right) \\left( \\frac{N - n}{N-1}\\right)$\n\n\\subsubsection*{Negative Binomial Distribution}\nThe Negative Binomial Distribution (class name NegativeBinomial) provides the probability of the nth success or potentially nth failure of a bernoulli trial. The parameters are r representing the (r -1) initial trials that where the successful and y the total number of trials before the next success r occurs. The distribution is calculated as follows:\n$$\nP(y;r) = {y - 1 \\choose r - 1}p^rq^{y-r} \n$$\nwhere $y = r, r + 1, ...$\\\\\\\\\nThe simple properties of the distribution are:\\\\\\\\\nMean: $\\mu = \\frac{r}{p}$\\\\\nVariance: $\\sigma^2 = \\frac{r(1-p)}{p^2}$\n\n\\subsubsection*{The Poisson Distribution}\nThe Poisson Distribution (class name Poisson) provides the probability of an event occurring a certain number of times within an interval. It is commonly used to model a number of events occuring in a certain period of time. We can use the two parameters lambda and y to represent the number of events, and period of time respectively.\nThe distribution is defined as:\n$$\nP(y;\\lambda) = \\frac{ \\lambda^y e^{-\\lambda} }{ y! }\n$$\nwhere $y \\ge 0$ and $\\lambda > 0$\\\\\nThe simple properties of the distribution are:\\\\\\\\\nMean: $\\mu = \\lambda$\\\\\nVariance: $\\sigma^2 = \\lambda$\n\n", "meta": {"hexsha": "afca7c8c038e3dbbd6aa78d1b35e8b5a643abd55", "size": 3045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/au.id.cxd.math.probability.discrete.tex", "max_stars_repo_name": "cxd/scala-au.id.cxd.math", "max_stars_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-02T02:57:07.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-02T02:57:07.000Z", "max_issues_repo_path": "docs/au.id.cxd.math.probability.discrete.tex", "max_issues_repo_name": "cxd/scala-au.id.cxd.math", "max_issues_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-05-16T21:30:06.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-09T02:26:59.000Z", "max_forks_repo_path": "docs/au.id.cxd.math.probability.discrete.tex", "max_forks_repo_name": "cxd/scala-au.id.cxd.math", "max_forks_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-15T04:48:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-15T04:48:30.000Z", "avg_line_length": 52.5, "max_line_length": 379, "alphanum_fraction": 0.7178981938, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539661002182847, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7970229716871442}}
{"text": "\\chapter{Metric Spaces}\nUp until this point, everything we've discussed has risen out of just the original vector space $V$; we created the dual space, vectors, covectors, tensor product spaces, and basis transformations based only on the original definition of $V$, its scalar field $\\mathbb{F}$, and its basis $\\vec{e}_\\mu$.\nNow, we're going to add a new object into the mix.\nThis will be the \\emph{inner product} or \\emph{metric}, denoted $\\rho: V \\times V \\to \\mathbb{F}$.\nVector spaces which are equipped with this function are known as \\emph{metric spaces} or \\emph{inner product spaces}. \nWe want this function to satisfy some key properties.\n\\begin{enumerate}\n    \\item $\\rho$ must map an ordered pair of vectors to the scalar field of $V$.\n    \\item $\\rho$ must be linear in both arguments; then $\\rho(\\lambda\\vec{v},\\vec{u}) = \\lambda \\rho(\\vec{v},\\vec{u})$ and $\\rho(\\vec{v} + \\vec{u},\\vec{w}) = \\rho(\\vec{v},\\vec{w}) + \\rho(\\vec{u},\\vec{w})$.\n    \\item[3*.] $\\rho$ must be symmetric; $\\rho(\\vec{v},\\vec\n    u) = \\rho(\\vec{u},\\vec{v})$.\n    \\item[4*.] $\\rho(\\vec{v},\\vec{v}) \\geq 0$, and $\\rho(\\vec{v},\\vec{v}) = 0$ if and only if $\\vec{v} = \\vec{0}$. This is known as a \\emph{positive-definite} form. If this rule does not hold, it is a \\emph{indefinite} form.\n    If $\\rho$ is positive-definite, then $V$ is a \\emph{Reimannian} metric space; if it is indefinite, $V$ is a \\emph{pseudo-Reimannian} metric space.\n\\end{enumerate}\nThese last two conditions are marked with asterisks because the definition of $\\rho$ when used in general relativity differs from the definition of $\\rho$ when discussing pure mathematics.\nIn general relativity, we insist that $\\rho$ be symmetric, but we don't require that $\\rho(\\vec{v},\\vec{v})$ be greater than or equal to 0, so General Relativity is based on a pseudo-Remannian metric space.\nThis function is a specific function, not a set of all possible functions like the dual space is.\nBy adding this specific function, we promote $V$ to become a metric space.\n\nThere are a few notational conventions for an inner product.\n\\begin{itemize}\n    \\item A named function, like $\\rho(\\cdot,\\cdot)$.\n    \\item Using ordered pairs, like $(\\cdot, \\cdot)$.\n    \\item The Bra-Ket notation of quantum mechanics, $\\langle \\cdot \\mid \\cdot \\rangle$.\n    \\item The braket notation which we have so far used to mean mappings, $\\langle \\cdot, \\cdot \\rangle$.\n    \\item The elementary vector notation of the dot product, where $\\vec{v}\\cdot\\vec{u}$ is the inner product of $\\vec{v}$ and $\\vec{u}$.\n\\end{itemize}\nThroughout this lesson, we will use the ordered pair notation of an inner product.\n\n\\subsection{Creating the Inner Product}\nWe define the inner product by what defining what happens to the basis vectors of $V$.\nSince the metric is linear, we can simply factor out the scalars and use these definitions to calculate the inner product of any two vectors.\nIn special relativity, we use the \\emph{Minkowski metric}\\footnote{Some books take the reverse convention, where $\\eta_{00} = 1$ and $\\eta_{11}, \\eta_{22}, \\eta_{33} = -1$. This choice between $(-,+,+,+)$ and $(+,-,-,-)$ is known as the \\emph{metric signature}.} $\\eta$, where \n\\[ (\\vec{e}_\\mu,\\vec{e}_\\nu) = \\eta_{\\mu\\nu},\\quad \\eta_{\\mu\\nu} = \n    \\begin{cases}\n        -1 & \\mu = \\nu = 0 \\\\\n        1 & \\mu = \\nu \\in \\{1,2,3\\} \\\\\n        0 & \\mu \\not= \\nu\n    \\end{cases}.\n\\]\nThis can be represented by a $4\\times4$ matrix with each element having the value of $\\eta_{r,c}$, like\n\\[\n\t\\eta = \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\\]\nIn general relativity, however, we don't have the luxury of picking such nice values.\nInstead, we look to what values nature seems to prefer.\n", "meta": {"hexsha": "c3c24aed10c92ba2772112c615d3fd1684f463e8", "size": 3775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/metric_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/metric_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/metric_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": 71.2264150943, "max_line_length": 302, "alphanum_fraction": 0.6768211921, "num_tokens": 1148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660949832346, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7970229692672369}}
{"text": "\\section{Vectors and Polytopes}\n\\label{polytopes-sect}\n\nWe will often need to refer to sets of natural numbers. We follow the\nnotation $[n]=\\{ i\\in\\naturals\\ |\\ 1\\leq i\\leq n \\}$.\n\nWe denote the transpose of a matrix $A$ as $A\\T$.\nVectors will be considered as column vectors, so $u\\T v$ is\nthe scalar product of $u,v\\in\\reals^d$. A vector for which all components\nare $0$'s will be denoted as $\\0$. A vector for which all\ncomponents are $1$'s will be denoted as $\\1$. The $i$-th component of\nthe {\\em $i$-th unit vector} $e_i$ is equal to 1, whereas\nall its other components are 0.\nAn inequality of the form $u\\geq v$ is intended to hold for every component.\n\nAn {\\em affine combination} of points in an Euclidean space\n$z_i\\in\\reals^d$, where $i\\in[m]$,\nis $\\sum_{i\\in [m]} \\lambda_i z_i$ where $\\lambda_i\\in\\reals$ such that\n$\\sum_{i\\in [m]} \\lambda_i = 1$.\nThe points $z_i$ are {\\em affinely independent} if none of them\nis an affine combination of the others.\nA {\\em convex combination} of the points $z_i$ is such an\naffine combination with $\\lambda_i\\geq 0$ for all $i\\in [m]$.\nThe {\\em convex hull} of a set $Z$ of points is the set of all\nits convex combinations. We denote it as $\\conv(Z)$, so\n\\[\n\\conv \\{z_i\\ \\mid\\ i\\in [m] \\}=\\{ \\sum_i \\lambda_i z_i\\ \\mid\\ %\n\\lambda_i\\geq 0\n\\text{ for } i\\in [m],~\n\\sum_i \\lambda_i=1 \\}~.\n\\]\nA set of points $Z$ is {\\em convex} if $Z=\\conv(Z)$. It has\n{\\em dimension} $d$ if it contains exactly $d + 1$ affinely independent\npoints. The convex hull of $d+1$ points of dimension\n$d$ is called a {\\em $d$-simplex}. The {\\em standard $d$-simplex} is\nthe convex hull of the first $d+1$ unit vectors, that is,\n $\\Delta_d=\\conv\\{ e_i\\ \\mid\\ i\\in[d+1] \\}$.\n\nA {\\em polytope} is the convex hull of a finite set of points, not\nnecessarily affinely independent.\nIts {\\em dimension} is its dimension as a convex set.\nA {\\em polyhedron} is the intersection of finitely many closed halfspaces\n$\\{ x\\in \\reals^d\\ \\mid\\ a\\T x\\leq a_0\\}$. It can be shown that a bounded\npolyhedron is a polytope.\nA {\\em vertex} of a\n$d$-dimensional polytope $P=\\conv(Z)$ is a\npoint $z\\in Z$ that is not the convex combination of other\npoints in $P$.\n% you have not defined convex hulls of infinite sets\n% such that $\\conv(Z\\setminus \\{ z \\})\\neq P$;\nAn {\\em edge} of P is a 1-dimensional line segment that has two vertices\nas endpoints.\nA {\\em facet} of $P$ is a set of dimension $d-1$ that is the convex hull of\na set of vertices that lie on a hyperplane of the form\n$\\{ x\\in \\reals^d\\ \\mid\\ a\\T x=a_0\\}$ so that $a\\T u<a_0$ for all other\nvertices\n$u$ of $P$.\nA $d$-dimensional polytope $P$ is {\\em simplicial} if it is the convex hull\nof a set of at least $d+1$ points $v\\in \\reals^d$ such that no\n$d+1$ of them are on a common hyperplane. This is equivalent to requiring\nthat every facet of $P$ is a $d$-simplex. A $d$-dimensional polytope\n$P$ is {\\em simple}\nif every point of $P$ lies on at most $d$ facets. Notice that the points\nlying on exactly $d$ facets are exactly the vertices.\nConsider a polytope $P$ which has $\\0$ in its\ninterior and is given by $n$ inequalities with normal\nvectors $c_i$ for $i\\in[n]$ according to\n\\[\nP=\\{ x\\in\\reals^d\\ \\mid\\ c_i\\T x\\leq 1,\\ i\\in [n]~\\}.\n\\]\nThen the {\\em polar} of the polytope $P$ is denoted by $P^\\Delta$, where\n\\[\nP^\\Delta = \\conv\\{ c_i\\ \\mid\\ i\\in [n]~\\}.\n\\]\nIf $P$ is a polytope and contains the origin $\\0$, the\npolar of its polar is $P$ itself, $P^{\\Delta\\Delta}=P$.\nFurthermore, if $P$ is simplicial then $P^\\Delta$\nis simple, and vice versa.\nFor details see Ziegler~\\cite{ziegler}.\n", "meta": {"hexsha": "f498b4b647da01fd5da4459febb8818e3fde80de", "size": 3553, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapter-1/polytopes.tex", "max_stars_repo_name": "mmcasetti/mphil-thesis", "max_stars_repo_head_hexsha": "6d9902c4f813cf3239d1b312e9453b3ea690c3db", "max_stars_repo_licenses": ["OLDAP-2.4"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/chapter-1/polytopes.tex", "max_issues_repo_name": "mmcasetti/mphil-thesis", "max_issues_repo_head_hexsha": "6d9902c4f813cf3239d1b312e9453b3ea690c3db", "max_issues_repo_licenses": ["OLDAP-2.4"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/chapter-1/polytopes.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": 44.4125, "max_line_length": 76, "alphanum_fraction": 0.6889952153, "num_tokens": 1233, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7969771160845801}}
{"text": "\n\\subsection{Bezout's identity}\n\nFor any two non-zero natural numbers \\(a\\) and \\(b\\) we can select natural numbers \\(x\\) and \\(y\\) such that\n\n\\(ax+by=c\\)\n\nThe value of \\(c\\) is always a multiple of the greatest common denominator of \\(a\\) and \\(b\\).\n\nIn addition, there exist \\(x\\) and \\(y\\) such that \\(c\\) is the greatest common denominator itself. This is the smallest positve value of c..\n\n\nLet's take two numbers of the form \\(ax+by\\):\n\n\\(d=as+bt\\)\n\n\\(n=ax+by\\)\n\nWhere \\(n>d\\). And \\(d\\) is the smallest non-zero natural number form.\n\nWe know from Euclidian division above that for any numbers \\(i\\) and \\(j\\) there is the form \\(i=jq+r\\).\n\nSo there are values for \\(q\\) and \\(r\\) for \\(n=dq+r\\).\n\nIf \\(r\\) is always zero that means that all values of \\(ax+by\\) are multiples of the smallest value.\n\n\\(n=dq+r\\) so \\(r=n-dq\\).\n\n\\(r=ax+by-(as+bt)q\\)\n\n\\(r=a(x-sq)+b(y-tq)\\)\n\nThis is also of the form \\(ax+by\\). Recall that \\(r\\) is the remainder for the division of \\(d\\) and \\(n\\), and that \\(d=ax+by\\) is the smallest positive value.\n\n\\(r\\) cannot be above or equal to \\(d\\) due to the rules of euclidian division and so it must be \\(0\\).\n\nAs a result we know that all solutions to \\(ax+by\\) are multiples of the smallest value.\n\nAs every possible \\(ax+by\\) is a multiple of \\(d\\), \\(d\\) must be a common divisor to both numbers. This is because \\(a.0+b.1\\) and \\(a.1+b.0\\) are also solutions, and \\(d\\) is their divisor.\n\nSo we know that the smallest positive solution is a common mutliple of both numbers.\n\nWe now need to show that that \\(d\\) is the largest common denominator. Consider a common denominator \\(c\\).\n\n\\(a=pc\\)\n\n\\(b=qc\\)\n\nAnd as before:\n\n\\(d=ax+by\\)\n\nSo:\n\n\\(d=pcx+qcy\\)\n\n\\(d=c(px+qy)\\)\n\nSo \\(d\\ge c\\)\n\n", "meta": {"hexsha": "85ba6e59ce866b8cd0838f7ff4eec3aa5fe70049", "size": 1723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmeticFundamental/01-02-Bezout.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/arithmeticFundamental/01-02-Bezout.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/arithmeticFundamental/01-02-Bezout.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.2459016393, "max_line_length": 191, "alphanum_fraction": 0.6529309344, "num_tokens": 519, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.868826784729373, "lm_q1q2_score": 0.7969771105305228}}
{"text": "\\section{Linear Support Vector Regression}\n\nIn the case of regression the goal is to predict a real-valued output for $y'$ so that our training data is of the form:\n\n\\begin{equation}\n\t\\{(x_i,y_i), x\\in\\Re^m, y_i\\in\\Re, i=1, \\dots, n\\} \\label{eq:svr_data}\n\\end{equation}\n\nThe regression SVM use a loss function that not allocating a penalty if the predicted value $y'_i$ is less than a distance $\\epsilon$ away from the actual value $y_i$, i.e., if $|y_i-y'_i| \\leq \\epsilon$, where $y'_i = w^T x_i + b$. The region bound by $y'_i\\pm\\epsilon \\ \\forall_i$ is called an $\\epsilon$-insensitive tube. The output variables which are outside the tube are given one of two slack variable penalties depending on whether they lie above, $\\xi^+$, or below, $\\xi^-$, the tube, provided $\\xi^+ \\geq 0$ and $\\xi^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_consts}\n\t\\begin{aligned}\n\t\t& y_i\\leq y'_i+\\epsilon+\\xi^+ \\ \\forall_i \\\\\n    \t& y_i\\geq y'_i-\\epsilon-\\xi^- \\ \\forall_i \\\\\n    \t& \\xi_i^+, \\xi_i^- \\geq 0 \\ \\forall_i\n\t\\end{aligned}\n\\end{equation}\n\nThe objective function for SVR can then be written as:\n\n\\begin{equation} \\label{eq:quad_svr_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi^+,\\xi^-} \\quad & \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n (\\xi_i^+ + \\xi_i^-) \\\\\n            \\text{subject to} \\quad & y_i - w^T x_i - b \\leq \\epsilon + \\xi_i^+ \\ \\forall_i \\\\ & w^T x_i + b - y_i \\leq \\epsilon + \\xi_i^- \\ \\forall_i \\\\ & \\xi_i^+, \\xi_i^- \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.6]{img/linear_dual_svr_hyperplane}\n  \t\\caption{Linear SVR hyperplane}\n  \t\\label{fig:linear_dual_svr_hyperplane}\n\\end{figure}\n\n\\subsection{Epsilon-insensitive loss}\n\nThe \\emph{epsilon-insensitive} loss is defined as:\n\n\\begin{equation} \\label{eq:eps_loss1}\n\t\\mathcal{L}_\\epsilon = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ |y - (w^T x + b)| \\leq \\epsilon \\\\\n\t\t|y - (w^T x + b)| - \\epsilon & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:eps_loss2}\n\t\\mathcal{L}_\\epsilon = \\max(0, |y - (w^T x + b)| - \\epsilon)\n\\end{equation}\n\nAs the \\emph{hinge} loss, also the \\emph{epsilon-insensitive} loss is a nondifferentiable convex function due to its nonsmoothness in $\\pm\\epsilon$, but has a subgradient wrt $w$ that is given by:\n\n\\begin{equation} \\label{eq:eps_loss_der}\n\t\\frac{\\partial \\mathcal{L_\\epsilon}}{\\partial w}=\n\t\t\\begin{cases}\n            (y - (w^T x + b)) x & \\text{if} \\ |y - (w^T x + b)| > \\epsilon \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nThe general primal unconstrained formulation takes the same form of~\\eqref{eq:primal_svc}.\n\nThe quadratic optimization problem~\\eqref{eq:quad_svr_obj} can be equivalently formulated as:\n\n\\begin{equation} \\label{eq:svr_eps}\n\t\\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)\n\\end{equation}\n\nwhere we make use of the \\emph{epsilon-insensitive} loss~\\eqref{eq:eps_loss1} or~\\eqref{eq:eps_loss2}.\n\nThe above formulation penalizes slacks $\\xi$ linearly and is called $\\mathcal{L}_1$-SVR.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/svr_eps_loss}\n  \t\\caption{SVR Epsilon-insensitive loss with different optimization steps}\n  \t\\label{fig:svr_eps_loss}\n\\end{figure}\n\n\\subsubsection{Wolfe Dual formulation}\n\nTo reformulate the~\\eqref{eq:quad_svr_obj} as a \\emph{Wolfe dual}, we introduce the Lagrange multipliers $\\alpha_i^+ \\geq 0, \\alpha_i^- \\geq 0, \\mu_i^+ \\geq 0, \\mu_i^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_wolfe_dual}\n\t\\begin{aligned}\n    \t\\max_{\\alpha^+,\\alpha^-,\\mu^+,\\mu^-} \\min_{w,b,\\xi^+,\\xi^-} \\mathcal{W}(w,b,\\xi^+,\\xi^-,\\alpha^+,\\alpha^-,\\mu^+,\\mu^-) = \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n (\\xi_i^+ + \\xi_i^-)-\\sum_{i=1}^n (\\mu_i^+ \\xi_i^+ + \\mu_i^- \\xi_i^-) \\\\ -\\sum_{i=1}^n \\alpha_i^+(\\epsilon+\\xi_i^+ + y'_i-y_i)-\\sum_{i=1}^n \\alpha_i^-(\\epsilon+\\xi_i^- - y'_i+y_i)\n\t\\end{aligned}\n\\end{equation}\n\nSubstituting for $y_i$, differentiating wrt $w, b, \\xi^+$, $\\xi^-$ and setting the derivatives to $0$ gives:\n\n\\begin{equation} \\label{eq:svr_wolfe_der_w}\n\t\\frac{\\partial \\mathcal{W}}{\\partial w}=w-\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-) x_i \\Rightarrow w=\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-) x_i\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_wolfe_der_b}\n\t\\frac{\\partial \\mathcal{W}}{\\partial b}=-\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)\\Rightarrow \\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)=0\n\\end{equation}\n\n\\begin{equation}\\label{eq:svr_wolfe_der_xip}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i^+}=0\\Rightarrow C=\\alpha_i^+ + \\mu_i^+\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_wolfe_der_xim}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i^-}=0\\Rightarrow C=\\alpha_i^- + \\mu_i^-\n\\end{equation}\n\nSubstituting~\\eqref{eq:svr_wolfe_der_w} and~\\eqref{eq:svr_wolfe_der_b} in, we now need to maximize $\\mathcal{W}$ wrt $\\alpha_i^+$ and $\\alpha_i^-$, where $\\alpha_i^+ \\geq 0,\\ \\alpha_i^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_max_wolfe_dual}\n    \\max_{\\alpha^+,\\alpha^-} \\mathcal{W}(\\alpha^+,\\alpha^-) = \\sum_{i=1}^n y_i(\\alpha_i^+ - \\alpha_i^-)-\\epsilon\\sum_{i=1}^n (\\alpha_i^+ + \\alpha_i^-)-\\frac{1}{2}\\sum_{i,j}(\\alpha_i^+ - \\alpha_i^-)\\langle x_i, x_j \\rangle(\\alpha_j ^+ - \\alpha_j ^-)\n\\end{equation}\n\nUsing $\\mu_i^+ \\geq 0$ and $\\mu_i^- \\geq 0$ together with~\\eqref{eq:svr_wolfe_der_w} and~\\eqref{eq:svr_wolfe_der_b} means that $\\alpha_i^+ \\leq C$ and $\\alpha_i^- \\leq C$. We therefore need to find:\n\n\\begin{equation} \\label{eq:svr_min_wolfe_dual}\n    \\begin{aligned}\n        \\min_{\\alpha^+,\\alpha^-} \\quad & \\frac{1}{2}(\\alpha^+ - \\alpha^-)^TK(\\alpha^+ - \\alpha^-)+\\epsilon q^T(\\alpha^+ + \\alpha^-)-y^T(\\alpha^+ - \\alpha^-) \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i^+,\\alpha_i^- \\leq C \\ \\forall_i \\\\ & q^T(\\alpha^+ - \\alpha^-)=0\n    \\end{aligned}\n\\end{equation}\n\nwhere $q^T = [1, \\dots, 1]$.\n\nWe can write the~\\eqref{eq:svr_min_wolfe_dual} in a standard quadratic form as:\n\n\\begin{equation}\n    \\begin{aligned} \\label{eq:svr_min_qp_wolfe_dual}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T Q\\alpha-q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i \\\\ & e^T\\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nwhere the Hessian matrix $Q$ is \n$\n\\begin{bmatrix}\nK & -K\\\\\n-K & K \n\\end{bmatrix}$\n, $q$ is \n$\n\\begin{bmatrix}\n-y\\\\\ny\n\\end{bmatrix}$ + $\\epsilon$\n, and $e$ is \n$\n\\begin{bmatrix}\n1\\\\\n-1\n\\end{bmatrix}$.\n\nEach new predictions $y'$ can be found using:\n\n\\begin{equation} \\label{eq:svr_pred}\n    y'= \\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)\\langle x_i, x' \\rangle+b\n\\end{equation}\n\nA set $S$ of support vectors $x_s$ can be created by finding the indices $i$ where $0\\leq\\alpha\\leq C$ and $\\xi_i^+=0$ or $\\xi_i^-=0$.\n\nThis gives us:\n\n\\begin{equation} \\label{eq:svr_b}\n    b=y_s-\\epsilon-\\sum_{m\\in S}(\\alpha_m^+ -\\alpha_m^-) \\langle x_m, x_s \\rangle\n\\end{equation}\n\nAs before it is better to average over all the indices $i$ in $S$:\n\n\\begin{equation} \\label{eq:svr_b_avg}\n    b=\\frac{1}{N_s}\\sum_{s\\in S}y_s-\\epsilon-\\sum_{m \\in S}(\\alpha_m^+ - \\alpha_m^-)\\langle x_m, x_s \\rangle\n\\end{equation}\n\nFrom~\\eqref{eq:svr_min_qp_wolfe_dual} we can notice that the equality constraint $e^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. We report below the box-constrained dual formulation~\\cite{hsu2002simple} that arises from the primal~\\eqref{eq:primal_svc_hinge1} or~\\eqref{eq:primal_svc_hinge2} where the bias term $b$ is embedded into the weight vector $w$:\n\n\\begin{equation} \\label{eq:svr_min_bcqp_wolf_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Lagrangian Dual formulation}\n\nIn order to relax the constraints in the \\emph{Wolfe dual} formulation~\\eqref{eq:svr_min_wolfe_dual} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrangian multipliers $\\mu \\geq 0, \\lambda_+ \\geq 0$, $\\lambda_- \\geq 0$:\n\n\\begin{equation} \\label{eq:svr_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha - \\mu^T (e^T \\alpha) - \\lambda_+^T (u - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T Q\\alpha + (q - \\mu e + \\lambda_+ - \\lambda_-)^T \\alpha - \\lambda_+^T u\n\t\\end{aligned}\n\\end{equation}\n\nwhere the upper bound $u^T = [C, \\dots, C]$.\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow Q \\alpha + (q - \\mu e + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:svr_lagrangian_sol}\n    Q \\alpha = - (q - \\mu e + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradient wrt $\\mu$, $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-e \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - u\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\nIf the Hessian matrix Q is not positive definite, i.e., the Lagrangian function is not strictly convex since it will be linear along the eigenvectors correspondent to the null eigenvalues and so it will be unbounded below, the Lagrangian dual relaxation will be nondifferentiable, so it will have infinite solutions and for each of them it will have a different subgradient. In order to compute an approximation of the gradient, we will choose $\\alpha$ in such a way as the one that minimizes the norm of the residual:\n\n\\begin{equation} \\label{eq:svr_lagrangian_krylov_sol}\n\t\\begin{aligned}\n\t\t\\min_{\\alpha_n \\in K_n(Q, b)} \\quad & \\| Q \\alpha_n - b \\| \\\\ \n\t\t\\text{where} \\quad & b = - (q - \\mu e + \\lambda_+ - \\lambda_-)\n\t\\end{aligned}\n\\end{equation}\n\nSince we are dealing with a symmetric but indefinite linear system we will choose a well-known Krylov method that performs the Lanczos iterate, i.e., symmetric Arnoldi iterate, called \\emph{minres}, i.e., symmetric \\emph{gmres}, to compute the vector $\\alpha_n$ that minimizes the norm of the residual $r_n = Q \\alpha_n - b$ among all vectors in $K_n(Q, b) = span(b, Qb, Q^2b, \\dots, Q^{n-1}b)$.\n\n\\bigskip\n\nFrom~\\eqref{eq:svr_min_qp_wolfe_dual} we can notice that the equality constraint $e^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:svr_lagrangian_dual} is reduced of 1/3 by removing the multipliers $\\mu$ which was allocated to control the equality constraint $e^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:svr_min_bcqp_wolf_dual}.\n\n\\begin{equation} \\label{eq:svr_bcqp_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha+q^T\\alpha - \\lambda_+^T (u - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha + (q + \\lambda_+ - \\lambda_-)^T \\alpha - \\lambda_+^T u\n\t\\end{aligned}\n\\end{equation}\n\nwhere, again, the upper bound $u^T = [C, \\dots, C]$.\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svr_bcqp_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + ee^T) \\alpha + (q + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:svr_bcqp_lagrangian_sol}\n    (Q + ee^T) \\alpha = - (q + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradient wrt $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svr_bcqp_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - u\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_bcqp_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\n\\subsection{Squared Epsilon-insensitive loss}\n\nThe \\emph{squared epsilon-insensitive} loss is defined as:\n\n\\begin{equation} \\label{eq:squared_eps_loss1}\n\t\\mathcal{L}_\\epsilon^2 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ |y - (w^T x + b)| \\leq \\epsilon \\\\\n\t\t(|y - (w^T x + b)| - \\epsilon)^2 & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:squared_eps_loss2}\n\t\\mathcal{L}_\\epsilon^2 = \\max(0, |y - (w^T x + b)| - \\epsilon)^2\n\\end{equation}\n\nAs the \\emph{squared hinge} loss, also the \\emph{squared epsilon-insensitive} loss is a strictly convex function and it has a gradient wrt $w$ that is given by:\n\n\\begin{equation} \\label{eq:squared_eps_loss_der}\n\t\\frac{\\partial \\mathcal{L}_\\epsilon^2}{\\partial w}=\n\t\t\\begin{cases}\n            2 ((y - (w^T x + b)) x) & \\text{if} \\ |y - (w^T x + b)| > \\epsilon \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nTo provide a continuously differentiable function the optimization problem~\\eqref{eq:svr_eps} can be formulated as:\n\n\\begin{equation} \\label{eq:svr_squared_eps}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)^2\n\\end{equation}\n\nwhere we make use of the \\emph{squared epsilon-insensitive} loss that quadratically penalized slacks $\\xi$ and is called $\\mathcal{L}_2$-SVR.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/svr_squared_eps_loss}\n  \t\\caption{SVC Squared Epsilon-insensitive loss with different optimization steps}\n  \t\\label{fig:svr_squared_eps_loss}\n\\end{figure}\n", "meta": {"hexsha": "a337c704e802f60392c5fe0e09d3664403eb2de5", "size": 14080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/linear_svr.tex", "max_stars_repo_name": "AF207/optiml", "max_stars_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-06T13:59:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T13:59:03.000Z", "max_issues_repo_path": "notebooks/optimization/tex/linear_svr.tex", "max_issues_repo_name": "AF207/optiml", "max_issues_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebooks/optimization/tex/linear_svr.tex", "max_forks_repo_name": "AF207/optiml", "max_forks_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_forks_repo_licenses": ["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.6984126984, "max_line_length": 549, "alphanum_fraction": 0.6747869318, "num_tokens": 5154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7969771036221953}}
{"text": "\\documentclass[../research.tex]{subfile}\n\n\\subsection{Quotients}\n\\label{sec:2.1}\n\n  \\begin{definition}[Binary relation]\n    Let $X$ be a non-empty set. A \\textit{binary relation}, $\\sim$, on $X$ is a map \n  $$\\cdot\\sim\\cdot:X\\times X\\to\\{\\verb%True, False%\\}.$$\n  \\end{definition}\n\n  \\begin{definition}[Equivalence relation]\n    Let $\\sim$ be a binary operation on a non-empty set $X$. We say $\\sim$ is an \n    \\textit{equivalence relation} if it is\n    \\begin{enumerate}\n      \\item Reflexive: $x\\sim x \\quad\\forall x\\in X$\n      \\item Symmetric: $x\\sim y$ $\\Leftrightarrow$ $y\\sim x\\quad\\forall x,y\\in X$\n      \\item Transitive: $x\\sim y$, $y\\sim z$ $\\Rightarrow$ $x\\sim z\\quad\\forall x,y,z\\in X$\n    \\end{enumerate}\n  \\end{definition}\n\n  \\begin{prop}\n    Let $\\sim$ be an equivalence operation on a non-empty set $X$. Given an $x\\in X$, we define \n    the \\textit{equivalence class} of $x$, $[x]$, to be the set of elements in $X$ equivalent to $x$ \n    under $\\sim$. In other words:\n    $$[x]=\\{y\\in X:y\\sim x\\}.$$\n    Then the equivalence classes partition $X$.\n  \\end{prop}\n\n  \\begin{proof}\n    Since every element $x_i\\in X$, $i\\in I$, is equivalent to itself, $x_i\\in[x_i]$, so \n    $$X = \\bigcup_{i\\in I}{[x_i]}.$$\n    So equivalence classes cover $X$.\\\\\n\n    Then if $x\\nsim y$, $y\\nsim x$, so $y\\notin[x]$. And if $z\\in[y]$, $z\\sim y$ so $z\\nsim x$, \n    and so $z\\notin [x]$. Hence\n    $$x\\nsim y \\Leftrightarrow [x]\\cap[y]=\\varnothing.$$\n    So equivalence classes partition $X$.\n  \\end{proof}\n\n  \\begin{definition}[Quotient set]\n    Let $X$ be a non-empty set, and $\\sim$ an equivalence relation on $X$. We define the \\textit{quotient set}, \n    or \\textit{quotient space}, $\\X$ to be the set of equivalence classes of $X$. I.e.\n    $$\\X=\\{[x]:x\\in X\\}.$$\n    When $X$ has an equivalence relation, $\\sim\\,$, we call $(X,\\sim)$ a \\textit{setoid}. Another way \n    of thinking about quotient sets is by turning $\\sim$ into equality, and thus turning \n    the setoid $(X,\\sim)$ into a quotient set $\\X$.\n  \\end{definition}\n\n  \\begin{example}[Quotient group]\n    Let $(G,+)$ be a group, and $N$ a normal subgroup of $G$, where we write $xy$ for $x+y$ $\\forall x,y\\in G$. We define an equivalence relation \n    $\\sim$ on $G$ to be such that \n    $$x\\sim y\\text{ if and only if }Nx=Ny.$$    \n    Then equivalence classes $[x]$ are the cosets of $N$ in $G$, $Nx=\\{nx:n\\in N\\}$, so the quotient set\n    $$\\G=\\{Nx:x\\in G\\}.$$\n    Equivalently, two elements of $G$ are equivalent if they lie in the same coset. \n    Then we define the \\textit{quotient group} \n    $$\\frac{G}{N}=(\\G,+)$$\n    where the binary operation $\\cdot+\\cdot:\\frac{G}{N}\\times\\frac{G}{N}\\to\\frac{G}{N}$ is defined by \n    $$(Nx)(Ny)=N(xy).$$\n  \\end{example}\n\n  \\begin{prop}\n    $\\frac{G}{N}$ is indeed a group under $+$.\n  \\end{prop}\n\n  \\begin{proof}\n    We first check that $+$ is well-defined on $\\frac{G}{N}$. \\\\\n    \n    Suppose that $Nx=Nx'$, and $Ny=Ny'$. \n    So $xx'^{-1}\\in N$ and $yy'^{-1}\\in N$. Then $xx'^{-1}yy'^{-1}\\in N$ this implies that $xy(x'y')^{-1}\\in N$, \n    since $N$ is a normal subgroup.\\\\\n\n    Then $Nxy=Nx'y'$, which implies that $(Nx)(Ny)=(Nx')(Ny')$.\\\\\n\n    So $+$ is well-defined. We now check the group axioms:\n    \\begin{enumerate}\n      \\item \\textit{Closure}: Since $G$ is closed under $+$, $\\frac{G}{N}$ is clearly closed under $+$.\n      \\item \\textit{Associativity}: \\begin{align*}\n                                      \\forall x,y,z\\in G, (Nx)((Ny)(Nz)) &= (Nx)(N(yz)) \\\\\n                                                                              &= Nx(yz) \\\\\n                                                                              &= N(xy)z \\\\\n                                                                              &= (Nxy)(Nz) \\\\\n                                                                              &= ((Nx)(Ny))(Nz)\n                                    \\end{align*}\n      \\item \\textit{Identity}: $N$ is the identity. To see this, observe that $N(Nx)=Nx=(Nx)N$.\n      \\item \\textit{Inverses}: Given $Nx$, $(Nx)^{-1}=Nx^{-1}$. To see this, observe that $(Nx)(Nx^{-1})=N=(Nx^{-1})(Nx)$.\n    \\end{enumerate}\n  \\end{proof}\n\n  \\begin{example}[Quotient ring]\n    Let $(R,+,\\times)$ be a ring, and $I$ an ideal of $R$. We can define an equivalence relation, \n    $\\sim$, on $R$ by \n    $$r\\sim s\\Longleftrightarrow I+r=I+s.$$\n    Then $(R/\\sim,+,\\times)$ forms a ring under $+$ and $\\times$, called the \\textit{quotient ring}, \n    $R/I$. \\\\\n\n    We can construct the field of complex numbers, $\\mathbb{C}$, by taking the following quotient: \\\\\n\n    Consider $I:=(x^2+1)\\R[x]$ as an ideal of $\\R[x]$. We define an equivalence relation $\\sim$ on $\\R[x]$ \n    by \n    $$f(x)\\sim g(x)\\Longleftrightarrow I+f(x)=I+g(x)\\quad,\\forall f(x),g(x)\\in\\R[x].$$\n    I claim that the quotient ring $\\R[x]\\,/\\sim$,\n    $$\\frac{\\R[x]}{I}=\\{a(I+x)+(I+b):a,b\\in\\R\\}$$.\n    \\begin{proof}\n      Fix a coset $I+p(x)$, $p(x)\\in\\R[x]$. Since $\\R$ is a field, $\\R[x]$ is a Euclidean domain, so \n      $\\exists q(x),r(x)\\in\\R[x]$, with $deg(r(x))<deg(x^2+1)=2$, or else $r(x)=0$, such that \n      $$p(x)=q(x)(x^2+1)+r(x).$$\n      Then we write the quotient ring as \n      \\begin{align*}\n        \\frac{\\R[x]}{I} &=\\{I+p(x):p(x)\\in\\R[x]\\} \\\\\n                        &=\\{I+q(x)(x^2+1)+r(x):deg(r)<2\\} \\\\\n                        &=\\{I+r(x):deg(r)<2\\} \\\\\n                        &=\\{I+(ax+b):a,b\\in\\R\\} \\\\\n                        &=\\{a(I+x)+(I+b):a,b\\in\\R\\}\n      \\end{align*}\n    \\end{proof}\n    Note that $(I+x)^2=I+x^2=(I+x^2)+(I+1)-(I+1)=-(I+1)$. This is clearly isomorphic to $\\mathbb{C}$, \n    since $i^2=-1$ when we identify $i$ with $I+x$.\n  \\end{example}\n\n  \\begin{example}[Quotient topology]\n    Let $(X,\\tau_x)$ be a topological space, $Y$ a set, and $f:X\\to Y$ a surjective function. Then a subset \n    $U\\subset Y$ is open in $Y$ if and only if $f^{-1}(U)$ is open in $X$. In other words, this \n    topology, called the \\textit{quotient topology}, is the finest topology we can define on $Y$ such \n    that $f$ is continuous, called the \\textit{final topology} on $Y$ with respect to $f$. \\\\\n\n    The key example here is given by defining an equivalence relation, $\\sim$ on $X$, and then \n    taking $Y=\\X$. We then define the \\textit{natural map}, $p:X\\to\\X$, by $p(x)=[x]$ $\\forall x\\in X$. \\\\\n\n    Then $(\\X,\\tau)$ is a topological space, where the quotient topology, $\\tau$, is defined by\n    $$\\tau=\\{U\\in \\X:p^{-1}(U)\\in\\tau_X\\}.$$\n    Note that $\\tau$ is the final topology on $\\X$ with respect to $p$.\n  \\end{example}\n\n  \\begin{definition}[Separateness conditions]\n    \\verb%%\n    \\begin{enumerate}\n      \\item Hausdorff: A topological space $X$ is called \\textit{Hausdorff} iff $\\forall x,y\\in X,\\, \n            \\exists U_x,U_y\\text{ such that }U_x\\cap U_y=\\varnothing$, where $U_x,U_y$ are open \n            neighbourhoods of $x,y$ respectively. \\\\\n\n            This asserts that every two points in $X$ can be `separated' by open sets - open \n            neighbourhoods that are disjoint. Conversely, $X$ is non-Hausdorff if there exists a pair of points \n            $x,y\\in X$ such for every open neighbourhood $U_x$ of $x$ and $U_y$ of $y$, $U_x\\cap U_y\n            \\neq\\varnothing$. \\\\\n\n            For example, if $X=\\{x,y,z\\}$ and $\\tau=\\{\\varnothing,\\{x\\},\\{x,y\\},\\{x,z\\},X\\}$, then $X$ is \n            non-Hausdorff since the open neighbourhoods of $x$ are $\\{x\\},\\{x,y\\},\\{x,z\\}$, and the only open \n            neighbourhoods of $y,z$  $\\{x,y\\},\\{x,z\\}$ respectively, which are all clearly non-disjoint.\n      \\item Regular: A topological space $X$ is called \\textit{regular} iff for any $x\\in X$ and any \n            closed set $V\\subset X$, there exists an open neighbourhood $U_x$ of $x$ and an open \n            superset $U_V$ of $V$, such that $U_x\\cap U_V=\\varnothing$.\n      \\item Normal: A topological space $X$ is called \\textit{normal} iff for any pair of closed sets \n            $V_1,V_2\\subset X$ there exist open supersets $U_1,U_2$ of $V_1,V_2$ such that $U_1\\cap U_2=\\varnothing$.\n    \\end{enumerate}\n  \\end{definition} \n\n  \\begin{example}\n    Let $X$ be a non-Hausdroff topological space. Then we can turn $X$ into a Hausdorff space by \n    considering the equivalence relation $\\sim$ on $X$ defined by \n    $$x\\sim y\\Longleftrightarrow U_x\\cap U_y\\neq\\varnothing$$\n    for all open neighbourhoods $U_x,U_y$ of $x,y$ respectively. \\\\\n\n    Then the quotient space $\\X$ is Hausdorff when given the quotient topology.\n  \\end{example}\n\n  \\begin{proof}\n    So $U\\subset\\X$ is open if and only if $p^{-1}(U)$ is open, where $p:X\\to\\X$ maps $x\\in X$ to \n    the set of points which cannot be separated from $x$ by open sets, denoted $[x]$. \\\\\n\n    So we fix distinct $[x],[y]\\in\\X$. Now, $p^{-1}(\\{[x]\\})$ is \n    open in $X$, so $\\{[x]\\}$ is open in $\\X$. Similarly, $\\{[y]\\}$ is open in $\\X$. Finally, note \n    that $\\{[x]\\}\\cap\\{[y]\\}=\\varnothing$, and so $\\X$ is Hausdorff.\n  \\end{proof}\n\n  \\begin{definition}[Quotient map]\n    We say $q:X\\to Y$ between topological spaces $X$ and $Y$ is a \\textit{quotient map} \n    if it is surjective, and $U\\subset Y$ is open in $Y$ if and only if $q^{-1}(U)\\subset X$ \n    is open in $X$.\n  \\end{definition}\n\n  \\begin{example}\n    The natural map $p:X\\to \\X$ is a quotient map.\n  \\end{example}\n\n  \\begin{proof}\n    $p$ is surjective, since $\\forall[x]\\in \\X$, $p(x)=[x]$. The second property follows from the \n    definition of $p$.\n  \\end{proof}\n\n  \\begin{prop}\n    Let $q:X\\to Y$ be a quotient map. Then $f:Y\\to Z$ is continuous if and only if \n    $f\\circ q:X\\to Z$ is continuous.\n  \\end{prop}\n\n  \\begin{proof}\n    If $f$ is continuous, then $f\\circ q$ is continuous by composition. Now assume \n    $f\\circ q$ to be continuous, and let $U\\subset Z$ be open in $Z$. Then \n    $(f\\circ q)^{-1}(U)=q^{-1}(f^{-1}(U))$ is open in $X$, so $f^{-1}(U)$ is open in $Y$.\n  \\end{proof}\n\n  \\begin{prop}[Universal property of quotients]\n    If $f:X\\to Y$ is continuous and constant on equivalence classes of $X$. I.e. \n    $f|_{[x]}$ is constant $\\forall[x]\\in\\X.$\\\\\n\n    Then there exists a unique continuous map $g:\\X\\to Y$ such that \n    $$f=g\\circ p.$$\n    We say that $f$ descends to the quotient.\n  \\end{prop}\n\n  \\begin{proof}\n    So given $x_i\\in X$, $f(x)=c_i$ $\\forall x\\in[x_i]$. Then we define $g:\\X\\to Y$ by \n    $g([x_i])=c_i$. Clearly this choice of $g$ is unique. We first check this is well-defined:\\\\\n\n    Suppose $[x_i]=[y_i]$. Then if $y\\in[y_i]$, $y\\in[x_i]$, so $g([y_i])=c_i$. Now, \n    $g\\circ p(x_i)=g(p(x_i))=g([x_i])=c_i=f(x_i)$. Hence $g\\circ p=f$.\\\\\n\n    We now check $g$ is continuous. Since $p$ is a quotient map and $g\\circ p$ is continuous, \n    $g$ is continuous by the previous proposition.\n  \\end{proof}\n\n\\subsection{Group Actions}\n\\label{sec:2.2}\n\n  \\begin{definition}[Automorphism group]\n    Given a mathematical structure $X$, an \\textit{automorphism} is an isomorphism, $\\phi$, from $X$ to itself. Explicitly,\n    $$\\phi:X\\to X.$$\n    Coloquially, automorphisms are invertible mappings that preserve structure. In fact, they form a group under composition, \n    called the \\textit{automorphism group} of $X$, which we denote $\\Aut{X}$.\n  \\end{definition}\n\n  \\begin{example}\n    \\verb%%\n    \\begin{enumerate}\n      \\item If $X$ is a set with $n$ elements, then\n            $$\\Aut{X}=S_n,$$\n            the group of permutations of the elements of $X$.\n      \\item If $V$ is an $n$-dimensional vector space over a field $F$, then \n            $$\\Aut{V}=\\text{GL}_n(F),$$\n            the group of invertible $n\\times n$ matrices over $F$, or equivalently the group of invertible linear \n            transformations from $V$ to itself.\n      \\item If $(X,\\tau)$ is a topological space, then \n            $$\\Aut{X}=\\Homeo{X},$$\n            the group of homeomorphisms of $X$. Note that homeomorphism groups of homeomorphic spaces \n            are isomorphic as groups. \\\\\n    \\end{enumerate}\n  \\end{example}\n\n  Given a set $X$, we can think of $\\Aut{X}$ as \\textit{acting} on $X$ in an invertible way.\n  Explicitly, we describe the \\textit{group action} of $\\Aut{X}$ on $X$ by the function:\n  $$\\Aut{X}\\times X\\to X:(\\sigma,x)\\mapsto \\sigma\\cdot x,\\quad\\forall\\sigma\\in\\Aut{x},$$\n  such that the following hold $\\forall x\\in X$, where $\\sigma\\cdot x$ refers to outcome of acting \n  on $x\\in X$ by an automorphism $\\sigma\\in\\Aut{X}$, and the identity in $\\Aut{X}$ is denoted $e$:\n  \\begin{enumerate}\n    \\item \\textit{Identity}: $e\\cdot x=x$\n    \\item \\textit{Compatibility}: $(\\sigma\\rho)\\cdot x=\\sigma\\cdot(\\rho\\cdot x),\\quad\\forall\n                                    \\sigma,\\rho\\in\\Aut{X}$\n  \\end{enumerate}\n\n  In fact, this is a special case of an arbitrary group $G$ acting on $X$. We specify the action \n  by describing a homomorphism\n  $$\\varphi:G\\to\\Aut{X}.$$\n  Which amounts to assigning an automorphism of $X$ to each element of $G$ in such a way that\n  \\begin{enumerate}\n    \\item The identity automorphism in $\\Aut{X}$ is assigned to the identity in $G$,\n    \\item The composition of the two automorphisms assigned to two elements $g,h\\in G$ is assigned to \n          the product $gh$.\n  \\end{enumerate}\n  Since $\\varphi(G)$ is a subgroup of $\\Aut{X}$, we define the action of $G$ on $X$ by \n  the group action of the homomorphic image of $G$, in $\\Aut{X}$, on $X$. So $g\\cdot x=\\varphi(g)x$, \n  where $\\varphi(g)x$ is the result of applying the automorphism $\\varphi(g)\\in\\Aut{X}$ to $x\\in X$. \n  Specifically:\n\n  \\begin{definition}[Group action]\n    Let $G$ be a group and $X$ a set. The \\textit{(left) group action}, is a function\n    $$G\\times X\\to X:(g,x)\\mapsto g\\cdot x,$$\n    such that the following hold $\\forall x\\in X$, where we $e$ is the identity in $G$:\n    \\begin{enumerate}\n      \\item \\textit{Identity}: $e\\cdot x=x$\n      \\item \\textit{Compatibility}: $(gh)\\cdot x=g\\cdot(h\\cdot x)\\quad\\forall g,h\\in G$\n    \\end{enumerate}\n    Here $G$ is called a \\textit{transformation group}, $X$ is called a \\textit{$G$-set}.\n  \\end{definition}\n\n  \\begin{definition}[Orbit]\n    Consider a group $G$ acting on a set $X$. We define the \\textit{orbit}, $G\\cdot x$,\n    of $x\\in X$ to be the set of elements in $X$ to which $x$ can be mapped to by the elements of $G$. Explicitly:\n    $$G\\cdot x=\\{g\\cdot x:g\\in G\\}.$$\n  \\end{definition}\n\n  We can define an equivalence relation $\\sim$ on $X$ by\n  $$x\\sim y\\text{ if and only if }G\\cdot x=G\\cdot y,\\quad x,y\\in X.$$\n  Equivalently, $x\\sim y$ if and only if $\\exists g\\in G$ such that $g\\cdot x=y$ (and so $g^{-1}\\cdot y=x$). \n  Then the orbits of $X$, under the action of $G$, partition $X$. The quotient set induced by $\\sim$ is\n  $$\\X=\\{G\\cdot x:x\\in X\\}.$$\n  This is the set of all orbits of $X$ under the action of $G$, called the \\textit{quotient} of the action and denoted $\\frac{X}{G}$.\n\n  \\begin{definition}[Stabiliser subgroup]\n    Given $g\\in G$ and $x\\in X$ such that $g\\cdot x=x$, we say that $g$ fixes $x$, in other words \n    $g$ acts as the identity on $x$. So for all $x\\in X$, we define the \\textit{stabiliser subgroup}, \n    $G_x\\subset G$, of $G$ with respect to $x$ as the set of elements in $G$ that fix $x$. Explicitly, given $x$,\n    $$G_x=\\{g\\in G:g\\cdot x=x\\}.$$\n  \\end{definition}\n\n  \\begin{prop}\n    $G_x$ is indeed a subgroup of $G$.\n  \\end{prop}\n\n%  \\begin{prop}\n%    Let $\\psi:G\\to\\text{Aut}(X)$ be a homomorphism. Then\n%    $$\\text{Ker}(\\psi)=\\bigcap_{x\\in X}{G_x}.$$\n%  \\end{prop}\n\n  $G_x$ is generally not a normal subgroup of $G$. However, given an $x\\in X$, we can define an \n  equivalent relation, $\\sim$, on $G$ by \n  $$g\\sim h\\Longleftrightarrow G_xg=G_xh,\\quad g,h\\in G.$$\n  We can then form the quotient set $\\G$ to be the set of cosets of $G_x$ in $G$, denoted $G/G_x$. \n  Explicitly, given $x\\in X$,\n  $$\\frac{G}{G_x}=\\{G_xg:g\\in G\\}.$$\n\n  \\begin{lemma}\n    Given $x,y\\in X$, and $g\\in G$ such that $y=g\\cdot x$, \n    the two stabiliser groups $G_x,G_y$ are related by \n    $$G_y=g^{-1}G_x g.$$\n  \\end{lemma}\n\n  \\begin{proof}\n    Fix $x,y\\in X$, and let $g\\in G$ be such that $y=g\\cdot x$, and fix $h\\in G_y$. Then \n    \\begin{align*}\n      h\\cdot y= y &\\Longleftrightarrow h\\cdot(g\\cdot x)=g\\cdot x \\\\\n                  &\\Longleftrightarrow (hg)\\cdot x=g\\cdot x \\\\\n                  &\\Longleftrightarrow g^{-1}\\cdot((hg)\\cdot x)=g^{-1}\\cdot(g\\cdot x) \\\\\n                  &\\Longleftrightarrow (g^{-1}hg)\\cdot x=(g^{-1}g)\\cdot x = x \\\\\n                  &\\Longleftrightarrow g^{-1}hg\\in G_x \\\\\n                  &\\Longleftrightarrow h\\in g^{-1}G_xg\n    \\end{align*}\n  \\end{proof}\n\n  \\begin{theorem}[Orbit-stabiliser theorem]\n    For a fixed $x\\in X$, there exists a bijection $\\psi:G/G_x\\to G\\cdot x.$\n  \\end{theorem}\n\n  \\begin{proof}\n    We define a map $\\psi:G/G_x\\to G\\cdot x$ by $\\psi(G_xg)=g\\cdot x$, $\\forall g\\in G$.\n    First, we show this an injective, well-defined function: Fix $x\\in X$, and let $G_xg=G_xh$. Then \n    \\begin{align*}\n      G_xg^{-1}h=G_x &\\Longleftrightarrow g^{-1}h\\in G_x \\\\\n                     &\\Longleftrightarrow (g^{-1}h)\\cdot x=g^{-1}\\cdot(h\\cdot x)=x \\\\\n                     &\\Longleftrightarrow h\\cdot x=g\\cdot x \\\\\n                     &\\Longleftrightarrow \\psi(G_xg)=\\psi(G_xh)\n    \\end{align*}\n    Now we show that $\\psi$ is surjective: Fix $x\\in X$, and $g\\cdot x\\in G\\cdot x$.\n    $$G_xg=\\{hg:h\\cdot x=x, \\,\\forall h\\in G\\}$$\n  \\end{proof}\n\n  \\begin{cor}[Burnside's lemma]\n    The number of orbits of $G$ in $X$, $|X/G|$, is given by\n    $$|X/G|=\\frac{1}{|G|}\\sum_{g\\in G}{|X^g|},$$\n    where $X^g\\subset X$ is the set of elements in $X$ fixed by $g$.\n  \\end{cor}  \n  \n  In fact, if $G$ is finite, then by Lagrange's theorem,\n  $$|G|=|G\\cdot x||G_x|.$$\n\n  \\begin{definition}[Topological group]\n    A \\textit{topological group} is a non-empty set $G$ which is both a group and topological space, \n    in which the group operations of product:\n    $$G\\times G\\to G:(x,y)\\mapsto xy,\\quad x,y\\in G$$\n    and taking inverses:\n    $$G\\to G:x\\mapsto x^{-1},\\quad x\\in G$$\n    are continuous, where $G\\times G$ is given the product topology.\n\n    For example, we can turn every finite group into a topological group by giving it the discrete \n    topology. Returning to our idea of group actions, since the automorphism groups of a topological \n    space $X$ is $\\Homeo{X}$, we can think of $\\Homeo{X}$ as acting of $X$\n\n    Let $X$ be a topological space, and $G$ a topological group. Then we say the action of $G$ on \n    $X$, \n    $$\\phi:G\\times X\\to X:(g,x)\\mapsto g\\cdot x,$$\n    is \\textit{continuous} if $\\phi^{-1}(U)$ is open in $G\\times X$, with respect to the product \n    topology, whenever $U$ is open in $X$. \n\n    We then call $X$ a \\textit{$G$-space}. \\\\ \n\n    Another way of thinking about a continuous group action is if we define a homomorphism\n    $$\\varphi:G\\to\\Homeo{X},$$\n    then the action of an element $g\\in G$ on $x\\in X$ is $g\\cdot x:=\\varphi(g)x$.\n\n      %\\begin{definition}[Homomorphism of topological groups]\n  %  Let $G,H$ be topological groups. Then a \\textit{homomorphism of topological groups} is a \n  %  structure-preserving map (i.e. a group homomorphism), $\\phi:G\\to H$, which is continuous. Explicitly,\n  %  \\begin{enumerate}\n  %    \\item $\\phi(xy)=\\phi(x)\\phi(y),\\quad x,y\\in G$\n  %    \\item $\\phi^{-1}(U)$ is open in $G$ whenever $U$ is an open subset of $H$.\n  %  \\end{enumerate}\n%\n  %  An \\textit{isomorphism} is a bijective group homomorphism which is also a homeomorphism of the \n  %  underlying topological spaces.\n  %\\end{definition}\n  \\end{definition}\n\n\\subsection{Initial and Final Topologies}\n\\label{sec:2.3}\n\n  Given a set $X$, the indiscrete topology is the coursest topology we can give to $X$. \n  However, for a family of topological spaces $Y_i$ indexed by $i\\in I$, the functions \n  $$f_i:X\\to Y_i$$\n  will almost never be continuous. The initial topology is the coursest topology such that \n  they are.\n\n  \\begin{definition}[Initial topology]\n    Given a family of topological spaces $Y_i$ indexed by $i\\in I$, the \\textit{initial topology} \n    with respect to the functions\n    $$f_i:X\\to Y_i$$\n    is that in which open sets $U\\subset X$ are those for which $f_i(U)$ is open in $Y_i$ $\\forall i\\in I$. \n    If $X$ already has a topology, then these functions are continuous if and only if the existing \n    topology is finer than the initial topology. Thus, the initial topology is the coursest topology that \n    can be defined on $X$ such that these functions are continuous. \\\\\n\n    Explicitly, it is the topology generated by taking all finite intersections and arbitrary unions of \n    sets of the form $f_i^{-1}(U_i)$, where $U_i$ is open in $Y_i$. Consider the following examples:\n\n    \\begin{enumerate}\n      \\item Let $A\\subset X$. The subspace topology $\\tau_A=\\{A\\cap U:U\\text{ is open in }X\\}$\n            is the initial topology on $A$ with respect to the canonical inclusion map \n            $$i:A\\hookrightarrow X.$$\n      \\item Given a family of topological spaces $X_i$ indexed by $I$, let $X=\\prod_{i\\in I}{X_i}.$\n            the product topology on $X$ is the initial topology on $X$ with respect to \n            the canonical projections \n            $$p_i:X\\to X_i\\quad\\forall i\\in I.$$\n    \\end{enumerate}\n\n    If $f$ is injective, the initial topology can be identified with the \\textit{subspace} topology of \n    $X$, when $X$ is viewed as a subset of $Y_i$.\n  \\end{definition}\n\n  \\begin{theorem}[Characteristic property of initial topologies]\n    Let $X,Y,Z_i$ be topological spaces, with $Z_i$ indexed by $i\\in I$ and $Y$ given the initial \n    topology with respect to the functions\n    $$g_i:Y\\to Z_i.$$\n\n    Let $f:X\\to Y$. Then $f$ is continuous if and only if $g_i\\circ f$ is continuous $\\forall i\\in I$. \\\\\n\n    In other words, the following diagram is commutative for all $i\\in I$: \\\\\n    \\begin{center}\n      \\begin{tikzcd}\n        X \\arrow{r}{f} \\arrow[swap]{dr}{g_i\\circ f} & Y \\arrow{d}{g_i} \\\\\n         & Z_i\n      \\end{tikzcd}\n    \\end{center}\n  \\end{theorem}\n  \n  \\begin{proof}\n    Assume first that $f$ is continuous. Then since $g_i$ is continuous $\\forall i\\in I$, $g_i\\circ f$ is continuous. \\\\\n\n    Now assume $g_i\\circ f$ is continuous $\\forall i\\in I$. Let $U\\subset Y$ be open in $Y$. Then $U$ is a finite intersection \n    and arbitrary union of open sets of the form $g_i^{-1}(V_i)$, where each $V_i$ is open in $Z_i$. \\\\\n\n    Then $f^{-1}(U)$ is a finite intersection and arbitrary union of open sets of the form $f^{-1}(g_i^{-1}(V_i))=\n    (g_i\\circ f)^{-1}(V_i)$. This is equal to $(g_i\\circ f)^{-1}(W_i)$, where $W_i$ is a finite intersection and arbitrary union \n    of the open sets $V_i$. \\\\\n\n    Then since each $W_i$ is open, and each $g_i\\circ f$ is continuous, $(g_i\\circ f)^{-1}(W_i)=f^{-1}(g_i^{-1}(W_i))$ is open in $X$.\n    $g_i^{-1}(W_i)$ is a finite intersection and arbitrary union of $g_i^{-1}(V_i)$, which is open in $Y$. Hence $f^{-1}(U)$ is open in $X$.\n  \\end{proof}\n\n  \\begin{definition}[Final topology]\n    Given a family of topological spaces $X_i$ indexed by $i\\in I$, the \\textit{final topology} \n    with respect to the functions\n    $$f_i:X_i\\to Y$$\n    is that in which open sets $A\\subset Y$ are those for which $f_i^{-1}(U)$ is open in $X_i$ $\\forall\n    i\\in I$. If $Y$ already has a topology, the $f_i$ are continuous precisely when the existing \n    topology is \\textit{courser} than the final topology on $Y$. Thus, the final topology is the finest \n    topology that can be given to $Y$ such that these functions are continuous. \\\\\n\n    If each $f_i$ is surjective, we call this topology the \\textit{quotient topology} under the equivalence \n    relation $\\sim$ defined by\n    $$x\\sim y\\Longleftrightarrow f_i^{-1}(\\{x\\})=f_i^{-1}(\\{y\\})\\quad\\forall x,y\\in X_i,\\,i\\in I.$$\n  \\end{definition}\n\n  \\begin{theorem}[Universal property of final topologies]\n    Let $X_i,Y,Z$ be topological spaces, with $X_i$ indexed by $i\\in I$ and $Y$ given the final \n    topology with respect to the functions\n    $$f_i:X_i\\to Y$$\n\n    Then $g:Y\\to Z$ is continuous if and only if $g\\circ f_i$ is continuous $\\forall i\\in I$. \\\\\n\n    In other words, the following diagram is commutative $\\forall i\\in I$: \\\\\n    \\begin{center}\n      \\begin{tikzcd}\n        X_i \\arrow{r}{f_i} \\arrow[swap]{dr}{g\\circ f_i} & Y \\arrow{d}{g} \\\\\n         & Z\n      \\end{tikzcd}\n    \\end{center}\n  \\end{theorem}\n\n\\subsection{Review of point-set topology}\n\\label{sec:2.4}\n\n  \\begin{prop}\n    Any compact subset of a Hausdroff space is closed.\n  \\end{prop}\n\n  \\begin{prop}\n    Any closed subset of a compact space is compact.\n  \\end{prop}\n\n  \\begin{prop}\n    Let $f:X\\to Y$ be injective and continuous. Then if $Y$ is Hausdorff, $X$ is Hausdorff.\n  \\end{prop}\n\n  \\begin{prop}\n    Let $X$ be a compact topological space, and $Y$ a Hausdorff space. \n    Let $f:X\\to Y$ be surjective and continuous. Then $f$ is a quotient map.\n  \\end{prop}\n\n  \\begin{proof}\n    Let $U\\subset Y$ be non-empty. Since $f$ is surjective, $f^{-1}(U)$ is non-empty. \n    Suppose $f^{-1}(U)$ is open in $X$. Then since $X\\backslash f^{-1}(U)$ is closed and $X$ is compact, \n    $X\\backslash f^{-1}(U)$ is compact. Then since $f$ is continuous, $f(X\\backslash f^{-1}(U))$ \n    is compact. \\\\\n    \n    Then since $Y$ is Hausdorff, $f(X\\backslash f^{-1}(U))=Y\\backslash f(f^{-1}(U))=Y\\backslash U$ is closed, \n    and hence $U$ is open, so $f$ is a quotient map.\n  \\end{proof}\n\n\\subsection{Construction of topological spaces}\n\\label{sec:2.5}\n\n  \\begin{definition}[Disjoint union]\n    Consider a family of non-empty sets $X_i$ indexed by $I$. Let $X_i^*=\\{(x,i):x\\in X_i\\}.$\n    Then we define the \\textit{disjoint union} of the $X_i$ as \n    $$\\coprod_{i\\in I}{X_i}=\\bigcup_{i\\in I}{X_i^*}.$$\n  \\end{definition}\n\n  \\begin{definition}[Disjoint union topology]\n    Let $X=\\coprod_{i\\in I}{X_i}$. For each $i\\in I$, we define \n    $$\\phi_i:X_i\\to X:x\\mapsto(x,i)$$\n    to be the \\textit{canonical injection}. Then we say $U$ is open in $X$ if and only if \n    $\\phi_i^{-1}(U)$ is open in $X_i$, $\\forall i\\in I$. \\\\\n\n    Equivalently, $U$ is open in $X$ if and only if $U\\cap X_i$ is open in $X_i$, $\\forall i\\in I$. \\\\\n\n    Note that this topology is the finest topology on $X$ such that all of the canonical injections \n    $\\phi_i$ are continuous. In other words, it is the final topology on $X$ with respect to the $\\phi_i$.\n  \\end{definition}\n\n  We use this to construct some topological spaces.\n\n  \\begin{enumerate}\n    \\item Let $A$ be a subset of a topological space $X$, and $q:A\\to Y$ be a quotient map.\n          We define an equivalence relation $\\sim$ on $A$ by\n          $$x\\sim y \\Leftrightarrow q(x)=q(y),\\quad\\forall x,y\\in A.$$\n          Then we define $X\\cup_q Y=\\X.$ \\\\\n\n          If $Y$ is a singlet set, then we call this \\textit{collapsing}, and \n          denote it $X/A$.\n    \\item Instead let $f:A\\to Y$ be continuous, and define $\\sim$ on $Y$ by \n          $x\\sim f(x)\\quad\\forall x\\in A$. Then we define \n          $$X\\cup_q Y=X\\sqcup Y\\,/\\sim.$$\n  \\end{enumerate}\n\n  \\begin{definition}[Attaching map]\n  \\end{definition}\n\n  \\begin{definition}[Adjunction space]\n  \\end{definition}\n\n  \\begin{lemma}[Gluing lemma]\n  \\end{lemma}", "meta": {"hexsha": "df9482ac8c559e327912f2ea2c50dbcac38666cc", "size": 27080, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "02-topology.tex", "max_stars_repo_name": "Jerrycaster/maths", "max_stars_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "02-topology.tex", "max_issues_repo_name": "Jerrycaster/maths", "max_issues_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "02-topology.tex", "max_forks_repo_name": "Jerrycaster/maths", "max_forks_repo_head_hexsha": "29706561f90442846e67348a75094e840a8124b2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.5087719298, "max_line_length": 146, "alphanum_fraction": 0.6093057607, "num_tokens": 8964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.7969770957653628}}
{"text": "\\chapter{Appendix}\\label{ch:mathematical-background}\n\\section{Stability theory}\\label{dynamical-systems}\nA dynamical system is a system that evolves in time. Stability theory is concerned with finding and classifying equilibriums. These are states of the system that do not change with time. Many dynamical systems can be represented through differential equations. If the system of differential equations has $n$ variables, choosing any set of values for the variables defines a point $x\\in\\mathbb{R}^n$. As the differential equations describe some change in time, moving time forwards sees this point moves through the space $\\mathbb{R}^n$. The path made by including all points passed through in a period of time is called a \\textit{trajectory}.\\\\\n\\\\\nA \\textit{fixed point}, $\\bf{x}$, is a point at which, if there is no perturbation, the system will stay forever. It is a time-independent solution to the system. However, there are many different types of fixed point. The two basic classes are stable and unstable fixed points. Informally, a fixed point $x$ is stable if a small perturbation from the point will bring it back to $x$. Similarly, a fixed point is unstable if a small perturbation from the point $x$ makes the system move away from $x$.\\\\\n\\\\\n%Let's get a bit more specific with this. Three key concepts are attraction, liapanov stability and asymptotic stability.\nLet $\\bf{x}\\in\\mathbb{R}^n$ and $\\bf{f}:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$ such that $\\bf{\\dot x}=\\bf{f}(\\bf{x})$. This is a compact form of\n\\begin{equation}\\label{eq:compact-form}\n\\frac{d}{dt}\n\\begin{bmatrix}\n x_1 \\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\n=\n\\begin{bmatrix}\nf_1(x_1,...,x_n) \\\\\n\\vdots\\\\\nf_n(x_1,...,x_n)\n\\end{bmatrix}\n\\end{equation}\nWe say that $\\bf{x}^*$ is a \\textit{fixed point} of a dynamical system if $\\bf{f}(\\bf{x}^*)=\\bf(0)$. Geometrically this means that this point would not move. $\\bf{x}^*$ is also called an equilibrium.\\\\\n\\\\\n%Let $\\bf{x}^*$ be a fixed point. We say that a point is \\textit{attracting} if all trajectories starting near $x^*$ approach $x^*$ as time goes to infinity. Formally this means that \n%\\begin{equation*}\n%\\lim_{t\\rightarrow\\infty}\\norm{\\bf{x}(t)-\\bf{x}^*(t)} = 0\n%\\end{equation*}\n%A point is \\textit{stable} (or Liapanov stable) if all trajectories that start close to $x^*$ stay close to it for all time. Formally this means\n%\\begin{equation*} \\forall\\epsilon>0,\\exists\\delta>0\\text{ s.t. }\\norm{x(0)-x^*}<\\delta\\implies\\norm{x(t)-x^*}<\\epsilon,\\forall t>0\n%\\end{equation*}\n%A fixed point that is not (Liapanov) stable is \\textit{unstable}\\cite{Braun:1993kx}.\\\\\n%\\\\\n%More strongly, a fixed point is \\textit{asymptotically stable} if it is both attracting and Liapanov stable. The difference between Liapanov and asymptotic stability is that a small perturbation from a (Liapanov) stable point will stay close. However, a small perturbation from an asymptotically stable point will return to the fixed point. Thus a pendulum without friction is Liapanov stable but a pendulum with friction is also asymptotically stable.\n%https://www.cds.caltech.edu/~murray/courses/cds101/fa02/faq/02-10-23_lyapexact.html\nWe say $\\bf{x}(t)$ is \\textit{stable} if it is a solution of Eq. (\\ref{eq:compact-form}) with initial condition $\\bf{x}(t=0)=\\bf{x_0}$ and $\\forall \\epsilon>0,\\exists \\delta>0$ such that if $\\bf{x'}(t)$ is another solution of Eq. (\\ref{eq:compact-form}) with $\\bf{x'}(t=0)=\\bf{x_0}'$ and $\\norm{\\bf{x_0'}-\\bf{x_0}}<\\delta$ then $\\norm{\\bf{x'}(t)-\\bf{x}(t)}<\\epsilon$ for all $t\\geq0$\\cite{Braun:1993kx}. Finally, a solution of Eq. (\\ref{eq:compact-form}) that is not stable is \\textit{unstable}\\cite{Braun:1993kx}.\n\\subsubsection{Jacobian}\nThe stability of a point $\\mathbf{x}$ can be investigated by considering the Jacobian matrix at that point. The Jacobian is the generalisation of a derivative, providing the best linear approximation of a function at a differentiable point.\\\\\n\\\\\n%Suppose we have a triple integral in the set of variables $x, y, z$:\n%\\begin{equation*}\n%\\int\\int\\int f(x,y,z)\\,dx\\,dy\\,dz\n%\\end{equation*}\n%Let $r, s, t$ be another set of variables, related to $x, y, z$ by the equations\n%\\begin{equation*}\n%r=r(x,y,z), \\hspace{1cm} s=s(x,y,z), \\hspace{1cm} t=t(x,y,z)\n%\\end{equation*}\nThe general Jacobian of a function $\\bf{f}:\\mathbb{R}^n\\rightarrow\\mathbb{R}^m$ that takes elements $\\bf{x}\\in\\mathbb{R}^n$ and outputs the vector $\\bf{f}(\\bf{x})\\in\\mathbb{R}^m$ is given by:\n\\begin{equation*}\n{\\displaystyle \\mathbf {J} ={\\begin{bmatrix}{\\dfrac {\\partial \\mathbf {f} }{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial \\mathbf {f} }{\\partial x_{n}}}\\end{bmatrix}}={\\begin{bmatrix}{\\dfrac {\\partial f_{1}}{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial f_{1}}{\\partial x_{n}}}\\\\\\vdots &\\ddots &\\vdots \\\\{\\dfrac {\\partial f_{m}}{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial f_{m}}{\\partial x_{n}}}\\end{bmatrix}}}\n\\end{equation*}\nMore specifically, if $\\bf{f}:\\mathbb{R}^3\\rightarrow\\mathbb{R}^3$ is a function taking $(r,s,t)$ to $(x,y,z)$ then the Jacobian is:\n%={\\partial(x,y,z) \\over \\partial(r,s,t)} =\n%{\\displaystyle \\mathbf {J} ={\\begin{bmatrix}{\\dfrac {\\partial \\mathbf {f} }{\\partial r}}&\\cdots &{\\dfrac {\\partial \\mathbf {f} }{\\partial t}}\\end{bmatrix}}\n\\begin{equation*}\nJ\n={\\begin{bmatrix}{\\partial x \\over \\partial r} & {\\partial x\\over \\partial s} & {\\partial x \\over \\partial t} \\cr \n\t\t{\\partial y \\over \\partial r} & {\\partial y\\over \\partial s} & {\\partial y \\over \\partial t} \\cr \n\t\t{\\partial z \\over \\partial r} & {\\partial z\\over \\partial s} & {\\partial z \\over \\partial t}\\end{bmatrix}}\n\\end{equation*}\n\nIf the Jacobian at a fixed point has eigenvalues all with negative real part then the point is\n%asymptotically\nstable. If it has at one or more eigenvalues with a positive real part it is unstable\\cite{Izhikevich:2007}.\n\\section{Code}\nAll of the code I have written for this project (around 3000 lines) is open-source and can be accessed, downloaded, modified and reused at \\url{https://github.com/joekroese/networks-and-revolution}. Included are some key excerpts.\n\\subsection{Compartmental model of revolution}\nThis code runs the simulation described in Section \\ref{sec:rev-compartment} and creates graphs such as Fig. \\ref{fig:rev-traj-default} and Fig. \\ref{fig:rev-traj-diff-gamma}.\n\\lstinputlisting[language=python]{../Code/illustrative/rev/run.py}\n\\subsection{Revolution on network model}\nThe following code runs the agent-based model of revolution as described in Section \\ref{sec:abm-rev}.\n\\lstinputlisting[language=python]{../Code/illustrative/abm-rev-zealot/run-slim.py}\n\\lstinputlisting[language=python]{../Code/illustrative/abm-rev-zealot/model.py}\n\\subsection{Evolutionary Prisoner's Dilemma on a torus}\nCreates the live visualisation of the evolutionary prisoner's dilemma on a torus as seen in Section \\ref{p-d-torus}.\n\\lstinputlisting[language=java]{../Code/illustrative/evo_prisoners_dilemma/evo_prisoners_dilemma.pde}\n\\lstinputlisting[language=java]{../Code/illustrative/evo_prisoners_dilemma/Game.pde}\n\\lstinputlisting[language=java]{../Code/illustrative/evo_prisoners_dilemma/Cell.pde}", "meta": {"hexsha": "e367f7be2b35003203b3afaae00066b2d007d78f", "size": 7073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Writing/TeX_files/appendix.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/appendix.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/appendix.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": 90.6794871795, "max_line_length": 645, "alphanum_fraction": 0.7301003817, "num_tokens": 2219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.7968847175034971}}
{"text": "% Author: Jonathan Siegel\n% This chapter aims to introduce the logistic regression, a model which\n% is the basis of machine learning classification problems.\n\n\\section{The Logistic Regression}\n\\subsection{Soft-max}\nNow we introduce the softmax: Given $z=\\left( \\begin{array}{ccc}\n\tz_1\\\\\n\t\\vdots \\\\\n\tz_k\n\\end{array} \\right)\\in \\mathbb R^k$, let\n\n\\begin{equation}\n\t\\label{softmax}\n\tq_j=\\frac{e^{z_j}}{\\sum_{i=1}^ke^{z_i}}, \\quad j=1:k.\n\\end{equation}\nWe note that \n$$\nq_j\\ge 0, \\quad \\sum_{j=1}^kq_j=1\n$$\nwhich can be viewed as probability distribution. \nWe can write \\eqref{softmax} as a more compact form:\n$$\nq = (\\mathbbm{1}^Te^z)^{-1}e^z\n$$\n\nThe softmax is a good measure when the classification is not\ndistinctive.  For example, in the MNIST, we may not be able to\ndistinct some handwritings for ``$0$'' versus ``$6$\", ``$2$'' versus\n``$7$'', ``$3$'' versus ``$5$''.  In these cases, the softmax is\nexpected to give relative large components corresponding to these\nnumbers.\n\\subsection{2-class case} Let $A_1$ and $A_2$ are two linearly\nseparable sets and $(w,b)$ is as in Lemma~\\ref{lem:2class}. We apply\nthe soft-max to the linear classifying vector function\n\\begin{equation}\n  \\label{eq:1}\n{1\\over 2}\n\\begin{pmatrix}\n  wx+b\\\\\n-(wx+b)\n\\end{pmatrix}\n\\end{equation}\nwe easily obtain the following classifier:\n\\begin{equation}\n  \\label{f-sigmoidal}\nf(x)=  \n\\begin{pmatrix}\ns(wx+b)\\\\\ns(-(wx+b)\n\\end{pmatrix}\n\\end{equation}\n where $s$ is the so-called sigmoidal function defined by\n\\begin{equation}\n\\label{sigmoidal}\ns(x)=\\frac{e^x}{e^x+e^{-x}}  \n\\end{equation}\nWe define $s(x)$ in this way so that $f(x)$ is a probability distribution on\n$A_1$ and $A_2$.\n\\begin{remark} We note that, in the above discussions, we have\n  encountered with $4$ special functions, namely\n\\begin{enumerate}\n\\item the Heaviside function given by \\eqref{heaviside};\n\\item the linear-step function given by\n  \\eqref{linear-step};\n\\item the rectified linear unit function given by \\eqref{ReLU}\n\\item the sigmoidal function given by \\eqref{sigmoidal}.\n\\end{enumerate}\nThese functions are examples of the so-called activation functions\nused in machine learning.  The Heaviside function was probably the\nmost natural and introduced most early in the machine learning\nliterature, but its lack of continuity makes the relevant model hards\nto train using gradient based training algorithm.  Both the\nlinear-step and the sigmoid functions are smoothed variants of the\nHeaviside function, while the former is only Liptschitz and the latter\nis infinitely differential.  We note that\n\\begin{equation}\n  \\label{approx-Heaviside}\n\\lim_{\\epsilon\\to 0}\\sigma(x/\\epsilon) =\n\\lim_{\\epsilon\\to 0}s(x/\\epsilon) =h_0(x), \\quad\\forall x\\in\n\\mathbb R^1. \n\\end{equation}\nThe ReLU function \\eqref{ReLU} emerges to be the most popular\nactivation used in the modern machine learning literature.  The\npopularity of ReLU may attribute to the following two properties:\n\\begin{enumerate}\n\\item it generates the linear step function $\\sigma$\n  \\eqref{linear-step} as in \\eqref{sigma-ReLU};\n\\item it generates the identity mapping:\n  \\begin{equation}\n    \\label{ReLU-identity}\nx=ReLU(x)-ReLU(-x)    \n  \\end{equation}\n\\end{enumerate}\n\n\\end{remark}\nThe following lemma is a trivial consequence of the definition of linear separability\n\\begin{lemma}\n\tIf $A_1$, $A_2\\subset\\mathbb{R}^n$ are linearly separable,\n        then there exist $\\theta^* = (w^*,b^*)\\in\\mathbb{R}^{1\\times\n          (n+1)}$ such that\n\\begin{equation}\\label{ftheta}\nf(\\theta^*;x)\\cdot e_i>f(\\theta^*;x)\\cdot e_j, \\mbox{ if }\\ x\\in A_i,\\ i=1,2, j\\neq i.          \n\\end{equation}\n\\end{lemma}\n\nDefine \n$$\ny(x)=e_i,\\quad x\\in A_i.\n$$\nand consider the loss function\n\\begin{equation}\\label{logit_loss}\n L(\\theta) = \\displaystyle\\sum_{i = 1}^N -\\log\\left(f(\\theta;x_i)\\cdot y(x_i)\\right)\n\\end{equation}\n\n\\begin{lemma}\\label{lemma116}\n If $A_1$ and $A_2$ are linearly separable, then \n \\begin{equation}\n  \\inf_{\\theta} L(\\theta) = 0\n \\end{equation}\n Moreover, this infimum is not achieved.\n\\end{lemma}\n\\begin{proof}\n Since $A_1$ and $A_2$ are linearly separable, there exists a $\\theta = (w,b)$ such that\n \\begin{equation}\n  wx+b\n  \\begin{cases}\n   > 0 & x\\in A_1 \\\\\n   < 0 & x\\in A_2\n  \\end{cases}\n \\end{equation}\n\n This means that for each $i$, \n $$-\\log\\left(f(\\theta;x_i)\\cdot y(x_i)\\right) = \\log(e^{c_i} + e^{-c_i}) - c_i$$\n for some $c_i > 0$. Now we note that\n $$-\\log\\left(f(K\\theta;x_i)\\cdot y(x_i)\\right) = \\log(e^{Kc_i} + e^{-Kc_i}) - Kc_i$$\n Thus we see that\n \\begin{equation}\n  \\lim_{K\\rightarrow \\infty} L(K\\theta) = 0\n \\end{equation}\n so $\\inf_{\\theta} L(\\theta) \\leq 0$. It is a simple exercise to see that $L(\\theta) > 0$\n for any $\\theta$, which completes the proof.\n\n\\end{proof}\n \n\\begin{lemma}\\label{lemma146}\nSuppose $A_1,A_2$ are two linearly separable sets and let $(\\theta_i)_{i = 1}^\\infty$ be\na minimizing sequence for the loss functions $L$ in (\\ref{logit_loss}), i.e.\n\\begin{equation}\n \\lim_{i\\rightarrow \\infty} L(\\theta_i) = \\inf_{\\theta} L(\\theta)\n\\end{equation}\n Then there exists an $N$ such that for all $n > N$, (\\ref{ftheta}) holds for $\\theta_n$.\n\\end{lemma}\n\\begin{proof}\n We have from Lemma \\ref{lemma116} that $\\inf_{\\theta} L(\\theta) = 0$. So let $N$ be chosen so that\n $L(\\theta_n) < \\log(2)$ for all $n > N$. \n \n We claim that (\\ref{ftheta}) holds for $\\theta_n$ as long\n as $n > N$. \n \n To prove this we simply note that if (\\ref{ftheta}) fails to hold for $\\theta_n$, then\n there exists a $j$ such that $f(\\theta;x_j)\\cdot y(x_j) < \\frac{1}{2}$. Thus\n \\begin{equation}\n  L(\\theta_n) = -\\log\\left(f(\\theta;x_j)\\cdot y(x_j)\\right) + \\displaystyle\\sum_{i\\neq j}-\\log\\left(f(\\theta;x_i)\\cdot y(x_i)\\right) > \\log(2)\n \\end{equation}\n as $f(\\theta;x_j)\\cdot y(x_j) < \\frac{1}{2}$ and $f(\\theta;x_i)\\cdot y(x_i) < 1$ for all $i$.\n\n Since this contradicts our choice of $N$ above, we have that (\\ref{ftheta}) holds for $\\theta_n$ as desired.\n\\end{proof}\n\nNext, we examine what happens when we add a regularization term to the loss function in (\\ref{logit_loss}), i.e. we consider\nthe loss function\n\\begin{equation}\\label{regularized_logit_loss}\n L(\\theta,\\lambda) = \\displaystyle\\sum_{i = 1}^N -\\log\\left(f(\\theta;x_i)\\cdot y(x_i)\\right) + \\lambda \\|\\theta\\|_2^2\n\\end{equation}\nNote that this loss is strongly convex and thus has a unique minimizer. We have the following lemma.\n\\begin{lemma}\n Suppose $A_1,A_2$ are two linearly separable sets and let $\\theta^*$ be the unique minimizer of the \n regularized loss function in (\\ref{regularized_logit_loss}), i.e.\n \\begin{equation}\n  \\theta^* = \\argmin_\\theta L(\\theta, \\lambda)\n \\end{equation}\n Then for sufficiently small $\\lambda > 0$, (\\ref{ftheta}) holds for $\\theta^*$.\n\\end{lemma}\n\\begin{proof}\n Lemma \\ref{lemma116} implies that there exists a $\\theta^\\prime$ such that $L(\\theta^\\prime) < \\frac{1}{2}\\log(2)$ (note\n that $L$ here is the unregularized loss in (\\ref{logit_loss})). Set \n $$\\lambda < \\frac{\\log(2)}{2\\|\\theta^\\prime\\|_2^2}$$\n Then we have\n \\begin{equation}\n  L(\\theta^\\prime, \\lambda) = L(\\theta) + \\lambda \\|\\theta\\|_2^2 < \\frac{1}{2}\\log(2) + \\frac{1}{2}\\log(2) = \\log(2)\n \\end{equation}\n This means that $L(\\theta^*,\\lambda) < \\log(2)$. But the same argument as in the proof of Lemma \\ref{lemma146} shows that\n if (\\ref{ftheta}) fails for $\\theta^*$, then\n $$L(\\theta^*, \\lambda) \\geq L(\\theta^*) > \\log(2)$$\n This contradiction shows that (\\ref{ftheta}) holds for $\\theta^*$ as desired.\n\n\\end{proof}\n\nWe can easily generalize those consequences to multicalass situations.\n\\begin{lemma}{\\label{fade}}\n\tAssume that the sets $A_1,\\cdots,A_k$ are linearly separable. Then we must have\n\t\\begin{equation}\n\t\\inf_{\\theta} L(\\theta,\\alpha) \\rightarrow 0, \\alpha \\rightarrow 0.\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tEasy to observe that if $\\theta = (W,b)\\in \\Theta$, then $K\\theta \\in \\Theta$ for all $K>0$. And\n\t\\begin{equation}\n\t\\lim\\limits_{K\\rightarrow +\\infty} \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n\t\\left(\\log(\\mathbbm{1}^T\\exp(KW x + Kb)) - (KW x + Kb)_i\\right) = 0.\n\t\\end{equation}\n\tGiven $\\epsilon>0$ arbitrarily. Then there must exist a $\\theta^{\\epsilon} = (W^{\\epsilon},b^{\\epsilon}) \\in \\Theta$ such that \n\t\\begin{equation}\n\t\\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n\t\\left(\\log(\\mathbbm{1}^T\\exp(W^{\\epsilon} x + b^{\\epsilon})) - (W^{\\epsilon} x + b^{\\epsilon})_i\\right) \\leq \\epsilon/2.\n\t\\end{equation}\n\tSo for all $0 < \\alpha \\leq \\frac{\\epsilon}{2\\max_i \\|w^{\\epsilon}_i\\|}$, we have\n\t\\begin{equation}\n\t|\\inf_{\\theta} L(\\theta,\\alpha)| = \\inf_{\\theta} L(\\theta,\\alpha) \\leq L(\\theta^{\\epsilon},\\alpha) \\leq \\frac{\\epsilon}{2} + \\frac{\\epsilon}{2} = \\epsilon\n\t\\end{equation}\n\tSo we obtain\n\t\\[\n\t\\inf_{\\theta} L(\\theta,\\alpha) \\rightarrow 0, \\alpha \\rightarrow 0.\n\t\\]\n\\end{proof}\n\n\\begin{lemma}\n\tSuppose that the sets $A_i,\\cdots,A_k$ are linearly separable. We claim that when $\\alpha$ is sufficiently small, we must have\n\t\\begin{equation}\n\t\\theta_\\alpha = \\argmin_{\\theta} L(\\theta,\\alpha) \\in \\Theta.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n\tNotice that for all $\\theta \\notin \\Theta$ and $\\alpha>0$, we have\n\t\\begin{equation}\n\tL(\\theta,\\alpha) \\geq \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n\t\\left(\\log(\\mathbbm{1}^T\\exp(W x + b)) - (W x + b)_i\\right) > \\log 2.\n\t\\end{equation}\n\tBut according to lemma (\\ref{fade}), we know there exists a $\\delta>0$ such that \n\t\\begin{equation}\n\t\\inf_{\\theta} L(\\theta,\\alpha) < \\log 2,~~\\forall 0< \\alpha < \\delta.\n\t\\end{equation} \n\tSo when $0< \\alpha < \\delta$, we must have\n\t\\[\n\t\\theta_\\alpha = \\argmin_{\\theta} L(\\theta,\\alpha) \\in \\Theta.\n\t\\]\n\\end{proof}\n\n\\begin{remark}\n$\\theta^*$ is a desirable weight, i.e. $f(\\theta^*;x)$ is a classifier, if $\\{A_i\\}_i$ are all finite. \n\\end{remark}\n\n\n\\subsection{Description of the model}\nThe logistic regression model takes as input a vector of real valued features\nand outputs a probability distribution over a set of labels. So the feature, or input space is\n$\\mathcal{X} = \\mathbb{R}^n$, the label set is $\\mathcal{Y} = \\{l_1,...,l_k\\}$, and the output of the model\nlies in the set $\\mathcal{Y}^* = \\mathcal{P}(\\mathcal{Y})$. In what follows, we will denote the \ninput features by a vector $x\\in \\mathcal{X} = \\mathbb{R}^n$.\n\n\\subsubsection{Special Case: Two Labels}\nWe consider first the simple case where there are only two possible labels, i.e. $\\mathcal{Y} = \\{l_1,l_2\\}$.\nIn this case, a probability distribution on the labels is uniquely determined by the probability of the first label\n$l_1$. Thus, in this case we can view the output of the logistic regression as a single number $p_1\\in [0,1]$, which\nrepresents the probability of the first label.\n\nThe model consists of the composition of an affine linear function which the logistic function, i.e.\n\\begin{equation}\n p_i(x~|~W,b) \\sim \\exp(W_{i}x + b_i)\n\\end{equation}\nHere\n$W_{i}$ denotes the $i$-th row of $W$. Explicitly normalizing this probability distribution gives\n$$p_i(x~|~W,b) = \\left(\\displaystyle\\sum_{j = 1}^2\\exp(W_{j}x + b_j)\\right)^{-1}\\exp(W_{i}x + b_i)$$\n%where $$l(z) = \\frac{\\exp(z)}{1 + \\exp(z)}$$ is the logistic function. \nThe parameters of the model are $b\\in \\mathbb{R}^2$\nand $W\\in \\mathbb{R}^{2\\times n}$, which specify an affine linear function from the parameter space to $\\mathbb{R}$.\n\n\\subsection*{Loss functions for two labels case}\nIn the case of a logistic regression with two labels, we have\n\\begin{equation}\np_1(x~|~W,b)  = \\frac{\\exp(W_{1}x + b_1)}{\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)}.\n\\end{equation}\nThen the likelihood is defined as follows\n\\begin{equation}\n\\begin{split}\np(\\mathcal{D}~|~W, b) &= \n\\prod_{j = 1}^n \n\\left(\n\\left(p_1(x~|~W,b)\\right)^{(y_j)_1}\\cdot(1-p_1\\left(x~|~W,b)\\right)^{(y_j)_2}\n\\right)\n\\\\\n&=\n\\prod_{j = 1}^n \n\\left(\n\\left(\n\\frac{\\exp(W_{1}x + b_1)}{\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)}\n\\right)^{(y_j)_1}\n\\cdot\n\\left(\n\\frac{\\exp(W_{2}x + b_2)}{\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)} \n\\right)^{(y_j)_2}\n\\right),\n\\end{split}\n\\end{equation}\nwhere $y_j$ is the label of the $j$-th data point. Finally, we take the negative log likelihood as the loss function\n\n\\begin{equation}\\label{LossTwoLabels}\n\\begin{aligned}\n&-\\log(p(\\mathcal{D}~|~W, b)) \\\\\n&= \n-\\displaystyle\\sum_{j=1}^n\n\\left(\n{(y_j)_1}\n\\log\\left(\n\\frac{\\exp(W_{1}x + b_1)}{\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)}\n\\right)\n+\n(y_j)_2\\log\\left(\n\\frac{\\exp(W_{2}x + b_2)}{\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)}\n\\right)\n\\right)\n\\\\\n&=\n-\\displaystyle\\sum_{j=1}^n \\left(\n(y_j)_1(W_{1}x + b_1)+(y_j)_2(W_{2}x + b_2)-\\log\\left(\\exp(W_{1}x + b_1)+\\exp(W_{2}x + b_2)\\right)\n\\right).\n\\end{aligned}\n\\end{equation}\n\n\n\n\n\\subsubsection{General Case: Multiple Labels}\nWe now consider the more general case where the number of labels can be greater than $2$, i.e. $\\mathcal{Y} = \\{l_1,...,l_k\\}$\nwith $k > 2$. The output of the logistic regression model will be a probability distribution over $\\mathcal{Y}$, i.e. for each\ninput $x\\in \\mathbb{R}^n$ and index $i = 1,...,k$ the model gives a probability $p_i(x~|~W,b)$, such that the \nsum of the probabilities over $i$ is $1$. \n\n\\begin{itemize}\n\\item \nIf given $(W,b)$,\n\\begin{equation}\np_i(x~|~W,b) = {\\rm Pr}(Y=i | X = x),\n\\end{equation}\nmeans the probability of the random variable $Y =i $ with condition $ X = x$ where \n$X$ is the random variable corresponding to the data space \nand $Y$ is the random variable corresponding to the label space.  \n\n\\item Here\n\\begin{equation}\np_i(x~|~W,b) = {\\rm Pr}( X = x, Y = i | W ,b),\n\\end{equation}\nmeans the probability of the random variable $(X,Y) = (x,i)$ with condition $W ,b$ are given. \nHere $X$ is the random variable corresponding to the data space \nand $Y$ is the random variable corresponding to the label space.  \nFollowing the notation in the next paragraphs, this setup seems more reasonable.\n\n\\end{itemize}\n\n\n\n\nThe model consists of an affine linear map composed with the softmax function, i.e.\n\\begin{equation}\n p_i(x~|~W,b) \\sim \\exp(W_{i}x + b_i)\n\\end{equation}\nwhere the parameters of the model are $b\\in \\mathbb{R}^k$ and $W\\in \\mathbb{R}^{k\\times n}$. Here\n$W_{i}$ denotes the $i$-th row of $W$. Explicitly normalizing this probability distribution gives\n$$p_i(x~|~W,b) = \\left(\\displaystyle\\sum_{j = 1}^k\\exp(W_{j}x + b_j)\\right)^{-1}\\exp(W_{i}x + b_i)$$\n\nA simpler way of saying this is that the output of the model is given by\n\\begin{equation}\n \\mathcal{Y}^* = \\mathcal{P}(\\mathcal{Y})\\ni h(x~|~W,b) = l(W x + b)\n\\end{equation}\nhere $W x$ simply denotes matrix-vector multiplication and the map $l$ is the softmax function\n$l:\\mathbb{R}^k\\rightarrow \\mathcal{P}(\\mathcal{Y})$, defined by\n$$l(y)_i = \\frac{\\exp(y_i)}{\\exp(y_1) + \\cdots + \\exp(y_k)}$$\nwhere $l(y)_i$ denotes the probability of label $l_i$ under the distribution $l(y)$.\n\n\\subsubsection{Remarks}\n\\begin{itemize}\n \\item Notice that adding any vector to the rows of $W$ or adding any constant to each entry of $b$ doesn't\n change the model. We are only fitting the parameters up to these symmetries. Essentially, what is important are the\n differences between each pair of the rows of $W$ and each pair of entries of $b$. We can remove this redundancy in \n the parameter space by assuming that the first row of $W$ and the first entry of $b$ are $0$. Whether this is\n useful depends on which algorithm we are using to fit the parameters.\n \\item The success of the logistic regression depends on how good the features (the entries of $x$) are at linearly distinguishing\n the different classes. In machine learning practice, these features must be engineered based on some domain knowledge.\n Many neural network models attempt to learn the features in addition to the coefficients.\n \\item Another way of thinking about the logistic regression is as follows. Given two labels, $l_i$ and $l_j$, define the\n odds of $l_i$ over $l_j$ to be the ratio $o_{i,j} = p(l_i) / p(l_j)$ (i.e. the ratio of the respective probabilities). \n The logistic regression models the logarithm of the\n odds, $\\log(o_{i,j})$, as a linear function of the features for all pairs $(i,j)$.\n \\item Somewhat counterintuitively, if the training data is perfectly linearly separable, then the negative log-likelihood\n objective has no minimizers because scaling up the parameters $W$ and $b$ always produces a smaller loss. This means that\n some form of regularization is necessary if the data are well-separated by linear functions.\n\\end{itemize}\n\n\n\\subsection{Loss functions}\nGiven a collection of labelled data points $\\mathcal{D} = (x_1,y_1),...,(x_n,y_n)$ with $x_i\\in \\mathcal{X} = \\mathbb{R}^n$ and\n$y_i \\in \\mathcal{Y} = \\{l_1,...,l_n\\}$, we want to fit parameters $W^*,b^*$ from the data $\\mathcal{D}$. There are\nmany different ways of doing this (a large part of statistics is concerned with what it means to fit parameters from data),\nbut we will only describe two standard approaches, the maximum likelihood and maximum posterior estimators.\n\\subsubsection{Maximum Likelihood Estimator}\nThe maximum likelihood estimator finds the parameter values which maximize the likelihood $p(\\mathcal{D}~|~W, b)$ \nof the observed data, i.e. we set\n\\begin{equation}\n \\theta^*=(W^*,b^*) = \\argmax_{W, b} p(\\mathcal{D}~|~W, b)\n\\end{equation}\nVery often, the above optimization problem is replaced by the equivalent minimization of the negative log likelihood,\n\\begin{equation}\n \\theta^*= (W^*,b^*) = \\argmin_{W, b} -\\log(p(\\mathcal{D}~|~W, b))\n\\end{equation}\nthe reason for considering the log likelihood is that the objective now becomes a sum over the data points\n$(x_1,y_1),...,(x_n,y_n)$ instead of a product. Specifically, in the case of a logistic regression, we have\n\\begin{equation}\n p(\\mathcal{D}~|~W, b) = \\prod_{j = 1}^n p_{i_j}(x_j ~|~W, b ) = \n\\prod_{j = 1}^n \n\\frac{\\exp(W_{i_j}x_j + b_{i_j})}\n{\\displaystyle\\sum_{i=1}^k\\exp(W_{i}x_j + b_i)} = \n\\displaystyle\\prod_{j = 1}^n \n \\frac{\\exp(W x_j + b)_{i_j}}\n {\\mathbbm{1}^T\\exp(W x_j + b)}\n\\end{equation}\nwhere $i_j$ denote the index such that $y_j = l_{i_j}$ (i.e. $i_j$ is the label of the $j$-th data point), $\\exp$ is applied\nto a vector entrywise, and $\\mathbbm{1}$ denotes the vector of ones. Then the negative log likelihood becomes\n\\begin{equation}\n -\\log(p(\\mathcal{D}~|~W, b)) = \\displaystyle\\sum_{j=1}^n \\left(\\log(\\mathbbm{1}^T\\exp(W x_j + b)) - \n (W x_j + b)_{i_j}\\right) = \\sum_{j=1}^n Cross-Entropy(p(x_j ~|~ W,b), y_j).\n\\end{equation}\n\n\n\\subsubsection{Maximum Posterior Estimator}\nThe maximum posterior estimator is very similar to the maximum likelihood estimator, but approaches the problem from a \nBayesian point of view. Equivalently, we can think of the maximum posterior estimator as a regularized maximum likelihood estimator.\n\nIn the Bayesian setting we fix a prior distribution over the parameters, $p(W,b)$, which represents domain\nknowledge that we have concerning the values of the parameters. The posterior distribution (or distribution\ngiven the data), $p(W,b~|~\\mathcal{D})$, is determined by Bayes' rule\n\\begin{equation}\n p(W,b~|~\\mathcal{D}) \\sim p(W,b)p(\\mathcal{D}~|~W,b)\n\\end{equation}\n\nBecause the posterior distribution is difficult to deal with in general, various approximate approaches exist, for example\nsampling from the posterior distribution using MCMC or approximating the posterior distribution by a parametrized class\nof distributions (known as variational Bayes'). The approach we consider here is the simpler elementary approach of\nchoosing the parameter values which maximize the posterior distribution, or equivalently minimize the negative log of the\nposterior\n\\begin{equation}\n (W^*,b^*) = \\argmin_{W, b} -\\log(p(W, b~|~D))\n\\end{equation}\nPlugging Bayes' formula into this yields\n\\begin{equation}\n (W^*,b^*) = \\argmin_{W, b} -\\log(p(W,b)) - \\log(p(W, b~|~D))\n\\end{equation}\nand we see that this becomes a `regularized' maximum likelihood estimate with regularizer $-\\log(p(W,b))$,\nwhich depends on the assumed prior. Often, the prior is a Gaussian centered at $0$, which results in a quadratic regularizer\nof the form $\\alpha (\\|W\\|_2^2 + \\|b\\|_2^2)$. \n\nTaking into account the form of the likelihood function for the\nlogistic regression, we get the following problem\n\\begin{equation}\n (W^*,b^*) = \\argmin_{W, b} \\alpha (\\|W\\|_2^2 + \\|b\\|_2^2) + \\displaystyle\\sum_{j=1}^n \\left(\\log(\\mathbbm{1}^T\\exp(W x_j + b)) - \n (W x_j + b)_{i_j}\\right)\n\\end{equation}\n\nWe now consider the logistic regression with a different type of regularizer.\n\\begin{equation}\n (W^*,b^*) = \\argmin_{W, b} \\alpha (\\max_i \\|w_i\\|_2) + \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(W x_j + b)) - (W x_j + b)_i\\right)\n\\end{equation}\n\n\n\n\n\n\\begin{theorem}\n Suppose that the sets $A_i$ are linearly separable. Let\n $$\\theta_\\alpha = \\argmin_{W, b} \\alpha (\\max_i \\|w_i\\|_2) + \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(W x + b)) - (W x + b)_i\\right)\n $$\n and\n $$\\theta^* = \\argmin_{\\substack{w_ix + b_i \\geq w_jx + b_j + 1\\\\x\\in A_i,~j\\neq i}} \\max_i \\|w_i\\|_2$$\n Then, up to a rescaling, $\\theta_\\alpha \\rightarrow \\theta^*$ as $\\alpha\\rightarrow 0$, i.e.\n \\begin{equation}\n  \\lim_{\\alpha\\rightarrow 0} \\frac{\\theta_\\alpha}{\\max_i \\|w^\\alpha_i\\|_2} = \\frac{\\theta^*}{\\max_i \\|w^*_i\\|_2}\n \\end{equation}\n\n\\end{theorem}\n\\begin{proof}\n The key is to consider the auxiliary problem\n \\begin{equation}\n  \\theta_M = \\argmin_{\\substack{W, b\\\\\\max_i \\|w_i\\|_2 = M}}\\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(W x_j + b)) - (W x_j + b)_i\\right)\n \\end{equation}\n The linear separability of the sets $A_i$ implies that $\\theta_\\alpha \\rightarrow \\infty$ as $\\alpha\\rightarrow 0$.\n This means that\n \\begin{equation}\n  \\lim_{\\alpha\\rightarrow 0} \\frac{\\theta_\\alpha}{\\max_i \\|w^\\alpha_i\\|_2} = \\lim_{M\\rightarrow \\infty} \\frac{\\theta_M}{M}\n \\end{equation}\n So we only need to consider the problem\n \\begin{equation}\n  \\frac{\\theta_M}{M} = \\argmin_{\\substack{W, b\\\\\\max_i \\|w_i\\|_2 = 1}}\\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(M(W x_j + b))) - (M(W x_j + b))_i\\right)\n \\end{equation}\n Additionally, by rewriting the optimization for $\\theta^*$, we obtain\n \\begin{equation}\n  \\frac{\\theta^*}{\\max_i \\|w^*_i\\|_2} = \\argmax_{\\substack{W, b\\\\\\max_i \\|w_i\\|_2 = 1}} \\min_{i\\neq j,~x\\in A_i} [(w_ix + b_i) - (w_jx + b_j)]\n \\end{equation}\n It now suffices to show that given $\\epsilon > 0$, there exists an $M(\\epsilon)$ such that given $\\theta, \\theta^\\prime$ with $\\max_i \\|w_i\\|_2 = \\max_i \\|w^\\prime_i\\|_2 = 1$ and\n $$\\min_{i\\neq j,~x\\in A_i} [(w^\\prime_ix + b^\\prime_i) - (w^\\prime_jx + b^\\prime_j)] \n > \\min_{i\\neq j,~x\\in A_i} [(w_ix + b_i) - (w_jx + b_j)] + \\epsilon\n $$\n we have\n \\begin{equation}\n \\begin{split}\n  &\\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(M(\\epsilon)(W^\\prime x_j + b^\\prime))) - (M(\\epsilon)(W^\\prime x_j + b^\\prime))_i\\right) > \\\\\n &\\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n \\left(\\log(\\mathbbm{1}^T\\exp(M(\\epsilon)(W x_j + b))) - (M(\\epsilon)(W x_j + b))_i\\right)\n \\end{split}\n \\end{equation}\n To see why this is the case, it helps to rewrite the above objective as\n \\begin{equation}\n  \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \\log\\left(\\displaystyle\\sum_{j = 1}^k \\exp(-M[(w_ix+b_i) - (w_jx+b_j)])\\right)\n \\end{equation}\n It is now clear that for sufficiently large $M$, this term is dominated by the terms which minimize $[(w_ix + b_i) - (w_jx + b_j)]$\n and thus for large $M$, this objective behaves as\n \\begin{equation}\n  C(\\theta) \\exp(-M\\min_{i\\neq j,~x\\in A_i} [(w_ix + b_i) - (w_jx + b_j)])\n \\end{equation}\n where $C(\\theta)$ depends on how many indices and data points \n achieve the minimum $\\min_{i\\neq j,~x\\in A_i} [(w_ix + b_i) - (w_jx + b_j)]$. This clearly implies that claim and completes the\n proof.\n\n\n\\end{proof}\n\n", "meta": {"hexsha": "db76a8174bf4009d770239f0b9a30ea38d9e9661", "size": 23730, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LogisticRegression.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/LogisticRegression.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/LogisticRegression.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.7822878229, "max_line_length": 179, "alphanum_fraction": 0.6888327012, "num_tokens": 8150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949657, "lm_q2_score": 0.8757869786798663, "lm_q1q2_score": 0.7968847055580852}}
{"text": "\\section{Surface Integrals}\\label{sec:SurfaceIntegrals}\n\nIn the integral for surface area, from Equation \\ref{eq:surfaceareaintegral},\n$$\\int_a^b\\int_c^d |\\vect{r}_u\\times\\vect{r}_v|\\,du\\,dv,$$\nthe integrand $|\\vect{r}_u\\times\\vect{r}_v|\\,du\\,dv$\nis the area of a tiny parallelogram, that is, a very small surface\narea, so it is reasonable to abbreviate it $dS$; then a shortened\nversion of the integral is\n$$\\iint_{D} 1\\cdot dS.$$\nWe have already seen that if $D$ is a region in the plane, the area of\n$D$ may be computed with \n$$\\iint_{D} 1\\cdot dA,$$\nso this is really quite familiar, but the $dS$ hides a little more\ndetail than does $dA$.\n\nJust as we can integrate functions $f(x,y)$ over regions in the plane,\nusing\n$$\\iint_{D} f(x,y)\\, dA,$$\nso we can compute integrals over surfaces in space, using\n$$\\iint_{D} f(x,y,z)\\, dS.$$\nIn practice this means that we have a vector function\n$\\vect{r}(u,v)=\\langle x(u,v),y(u,v),z(u,v)\\rangle$ for the surface,\nand the integral we compute is\n$$\\int_a^b\\int_c^d f(x(u,v),y(u,v),z(u,v))|\\vect{r}_u\\times\\vect{r}_v|\\,du\\,dv.$$ \nThat is, we express everything in terms of $u$ and $v$, and then we\ncan do an ordinary double integral.\n\n\\begin{example}{Mass and Center of Mass}{}\nSuppose a thin object occupies the upper hemisphere of \n$x^2+y^2+z^2=1$ and has density $\\sigma(x,y,z)=z$. Find the mass \nand center of mass of the\nobject. (Note that the object is just a thin shell; it does not occupy\nthe interior of the hemisphere.)\n\\end{example}\n\\begin{solution}\nWe write the hemisphere as $\\vect{r}(\\phi,\\theta)=\n\\langle \\cos\\theta\\sin\\phi, \\sin\\theta\\sin\\phi, \\cos\\phi\\rangle$,\n$0\\le\\phi\\le \\pi/2$ and $0\\le\\theta\\le 2\\pi$. So\n$\\vect{r}_\\theta = \\langle -\\sin\\theta\\sin\\phi, \\cos\\theta\\sin\\phi, 0\\rangle$\nand \n$\\vect{r}_\\phi =\\langle \\cos\\theta\\cos\\phi, \\sin\\theta\\cos\\phi, -\\sin\\phi\\rangle$.\nThen\n$$\\vect{r}_\\theta\\times\\vect{r}_\\phi =\n\\langle -\\cos\\theta\\sin^2\\phi,-\\sin\\theta\\sin^2\\phi,-\\cos\\phi\\sin\\phi\\rangle$$\nand\n$$ |\\vect{r}_\\theta\\times\\vect{r}_\\phi| = |\\sin\\phi| = \\sin\\phi,$$\nsince we are interested only in $0\\le\\phi\\le \\pi/2$.\nFinally, the density is $z=\\cos\\phi$ and the integral for mass is\n$$\\int_0^{2\\pi}\\int_0^{\\pi/2} \\cos\\phi\\sin\\phi\\,d\\phi\\,d\\theta=\\pi.$$\n\nBy symmetry, the center of mass is clearly on the $z$-axis, so we only\nneed to find the $z$-coordinate of the center of mass. The moment\naround the $x$-$y$ plane is\n$$\\int_0^{2\\pi}\\int_0^{\\pi/2} z\\cos\\phi\\sin\\phi\\,d\\phi\\,d\\theta\n=\\int_0^{2\\pi}\\int_0^{\\pi/2} \\cos^2\\phi\\sin\\phi\\,d\\phi\\,d\\theta\n={2\\pi\\over 3},$$\nso the center of mass is at $(0,0,2/3)$.\n\\end{solution}\n\nNow suppose that $\\vect{f}$ is a vector field; imagine that it\nrepresents the velocity of some fluid at each point in space. We would\nlike to measure how much fluid is passing through a surface $D$, the\n\\dfont{flux}\\index{flux} across $D$. As usual, we imagine computing\nthe flux across a very small section of the surface, with area $dS$,\nand then adding up all such small fluxes over $D$ with an\nintegral. Suppose that vector $\\vect{N}$ is a unit normal to the surface\nat a point; $\\vect{f}\\cdot\\vect{N}$ is the scalar projection of $\\vect{f}$\nonto the direction of $\\vect{N}$, so it measures how fast the fluid is\nmoving across the surface. In one unit of time the fluid moving across\nthe surface will fill a volume of $\\vect{f}\\cdot\\vect{N}\\,dS$, which is\ntherefore the rate at which the fluid is moving across a small patch\nof the surface. Thus, the total flux across $D$ is\n$$\\iint_{D} \\vect{f}\\cdot\\vect{N}\\,dS=\\iint_{D} \\vect{f}\\cdot\\,d\\vect{S},$$\ndefining $d\\vect{S}=\\vect{N}\\,dS$.\n\nAs usual, certain conditions must be met for this to work out; chief\namong them is the nature of the surface. As we integrate over the\nsurface, we must choose the normal vectors $\\vect{N}$ in such a way that\nthey point ``the same way'' through the surface. For example, if the\nsurface is roughly horizontal in orientation, we might want to measure\nthe flux in the ``upwards'' direction, or if the surface is closed,\nlike a sphere, we might want to measure the flux ``outwards'' across\nthe surface. In the first case we would choose $\\vect{N}$ to have\npositive $z$ component, in the second we would make sure that $\\vect{N}$\npoints away from the origin. Unfortunately, there are surfaces that\nare not \\dfont{orientable}\\index{orientable surface}: they have\nonly one side, so that it is not possible to choose the normal vectors\nto point in the ``same way'' through the surface. The most famous such\nsurface is the M\\\"obius strip shown in Figure~\\ref{fig:moebius}. It\nis quite easy to make such a strip with a piece of paper and some\ntape. If you have never done this, it is quite instructive; in\nparticular, you should draw a line down the center of the strip until\nyou return to your starting point. No matter how unit normal vectors\nare assigned to the points of the M\\\"obius strip, there will be normal\nvectors very close to each other pointing in opposite directions.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\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/moebius.eps}}} at 0 0\n\\endpicture}}\n\\caption{A M\\\"obius strip. \\label{fig:moebius}}\n\\end{figure}\n\nAssuming that the quantities involved are well behaved, however, the\nflux of the vector field across the surface $\\vect{r}(u,v)$ is\n$$\\iint_{D} \\vect{f}\\cdot\\vect{N}\\,dS\n=\\iint_{D}\\vect{f}\\cdot \n {\\vect{r}_u\\times\\vect{r}_v\\over|\\vect{r}_u\\times\\vect{r}_v|}\n |\\vect{r}_u\\times\\vect{r}_v|\\,dA\n=\\iint_{D}\\vect{f}\\cdot (\\vect{r}_u\\times\\vect{r}_v)\\,dA.$$\nIn practice, we may have to use $\\vect{r}_v\\times\\vect{r}_u$\nor even something a bit more complicated to make sure that the normal\nvector points in the desired direction.\n\n\\begin{example}{Flux}{}\nCompute the flux of $\\vect{f}=\\langle x,y,z^2\\rangle$ across the\ncone $z=\\sqrt{x^2+y^2}$, $0\\le z\\le 2$, in the downward direction.\n\\end{example}\n\\begin{solution}\nWe write the cone as a vector function: $\\vect{r}=\\langle v\\cos u, v\\sin u,\nv\\rangle$, $0\\le u\\le 2\\pi$ and $0\\le v\\le 2$.\nThen $\\vect{r}_u=\\langle -v\\sin u, v\\cos u,0\\rangle$ and \n$\\vect{r}_v=\\langle \\cos u, \\sin u, 1\\rangle$ and\n$\\vect{r}_u\\times\\vect{r}_v=\\langle v\\cos u,v\\sin u,-v\\rangle$.\nThe third coordinate $-v$ is negative, which is exactly what we\ndesire, that is, the normal vector points down through the\nsurface. Then \n\\begin{align*}\n\\int_0^{2\\pi}\\int_0^2 \\langle x,y,z^2\\rangle\\cdot\\langle v\\cos u,v\\sin u,-v\\rangle \\,dv\\,du\n&=\\int_0^{2\\pi}\\int_0^2 xv\\cos u+yv\\sin u-z^2v\\,dv\\,du\t\\\\\n&=\\int_0^{2\\pi}\\int_0^2 v^2\\cos^2 u+ v^2\\sin^2 u-v^3\\,dv\\,du\t\\\\\n&=\\int_0^{2\\pi}\\int_0^2 v^2-v^3\\,dv\\,du=-\\frac{8\\pi}{3}.\n\\end{align*}\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:SurfaceIntegrals}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the center of mass of an object that occupies the upper\nhemisphere of $x^2+y^2+z^2=1$ and has density $x^2+y^2$.\n\\begin{sol}\n\t$(0,0,3/8)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of an object that occupies the\nsurface $z=xy$, $0\\le x\\le1$, $0\\le y\\le 1$ and has density $\\sqrt{1+x^2+y^2}$.\n\\begin{sol}\n\t$(11/20,11/20,3/10)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the center of mass of an object that occupies the\nsurface $\\ds z=\\sqrt{x^2+y^2}$, $1\\le z\\le4$ and has density $x^2z$.\n\\begin{sol}\n\t$(0,0,1364/425)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the centroid of the surface of a right circular cone of\nheight $h$ and base radius $r$, not including the base.\n\\begin{sol}\n\ton center axis, $h/3$ above the base\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds \\iint_{D} \\langle 2,-3,4\\rangle\\cdot \\vect{N}\\,dS$, where $D$ is given by $z=x^2+y^2$, $-1\\le x\\le 1$, $-1\\le\ny\\le 1$, oriented up.\n\\begin{sol}\n\t$16$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds \\iint_{D} \\langle x,y,3\\rangle\\cdot\\vect{N}\\,dS$, where $D$ is given by $z=3x-5y$, $1\\le x\\le 2$, $0\\le\ny\\le 2$, oriented up.\n\\begin{sol}\n\t$7$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds \\iint_{D} \\langle x,y,-2\\rangle\\cdot \\vect{N}\\,dS$, where $D$ is given by $z=1-x^2-y^2$, $x^2+y^2\\le1$,\noriented up.\n\\begin{sol}\n\t$-\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds \\iint_{D} \\langle e^x, e^y,z\\rangle\\cdot\\vect{N}\\,dS$, where $D$ is given by $z=xy$, $0\\le x\\le 1$, $-x\\le\ny\\le x$, oriented up.\n\\begin{sol}\n\t$-2/e$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds \\iint_{D} \\langle xz,yz,z\\rangle\\cdot\\vect{N}\\,dS$, where $D$ is given by $z=a^2-x^2-y^2$, $x^2+y^2\\le b^2$, \noriented up.\n\\begin{sol}\n\t$\\pi b^2(-4b^4-3b^2+6a^2b^2+6a^2)/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA fluid has density 870 kg/m$^3$ and flows with velocity $\\vect{v} =\n \\langle z,y^2,x^2\\rangle$, where distances are in meters and the\n components of $\\vect{v}$ are in meters per second.  Find the rate of flow\n outward through the portion of the cylinder $x^2+y^2 = 4$, $0\\leq\n z\\leq 1$ for which $y>0$.\n\\begin{sol}\n\t$9280$ kg/s\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nGauss's Law says that the net charge, $Q$,\nenclosed by a closed surface, $S$, is \n$$Q=\\epsilon_0 \\iint \\vect{e}\\cdot \\vect{N}\\,dS$$ \nwhere $\\vect{e}$ is an electric field and $\\epsilon_0$ (the\npermittivity of free space) is a known constant; $\\vect{N}$ is oriented\noutward. \nUse Gauss's Law to find the charge contained in the cube with vertices\n$(\\pm 1, \\pm 1, \\pm 1)$ if the electric field is \n$\\vect{e} = \\langle x,y,z\\rangle$.\n\\begin{sol}\n\t$24\\epsilon_0$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "26491007ba334f98bba71a936c08e31eb69de7fb", "size": 9480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-7-surface-integrals.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "16-vector-calculus/16-7-surface-integrals.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "16-vector-calculus/16-7-surface-integrals.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5365853659, "max_line_length": 123, "alphanum_fraction": 0.6892405063, "num_tokens": 3462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.9099069999303416, "lm_q1q2_score": 0.7968847023486553}}
{"text": "\n\\subsection{Cardinality of the natural numbers}\n\nConsider the infinite set, that is the set of all natural numbers which is defined in ZFC. Clearly there isn’t a natural number cardinality of this – we instead write \\(\\aleph_0\\).\n\nWe call sets with this cardinality, countably infinite.\n\nSo:\n\n\\(|\\mathbb{N} |=\\aleph_0\\)\n\n\\subsubsection{Cardinality of natural  numbers}\n\nWe define:\n\n\\(|\\emptyset |=0\\)\n\nThat, the empty set has a cardinality of \\(0\\).\n\nAs we define \\(0\\) as the empty set, \\(|0|=0\\).\n\nWhat is \\(1\\)? using the definition above we know \\(|1|>|0|\\), so let's say \\(|1|=1\\), and more generally:\n\n\\(\\forall n \\in \\mathbb{N} |n|=n\\)\n\n", "meta": {"hexsha": "3d4e861f887f0551444d5ded680d95ff124df6a5", "size": 645, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/01-02-cardinalityNatural.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/01-02-cardinalityNatural.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/01-02-cardinalityNatural.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.8076923077, "max_line_length": 180, "alphanum_fraction": 0.6837209302, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8519527982093668, "lm_q1q2_score": 0.7968710824965761}}
{"text": "\\chapter{DT Frequency Response}\n\nIn this lecture we are going to focus on the frequency response of discrete-time systems and highlight it's importance in linear systems theory.\n\n\\section{Determining the frequency response (FR) of a DT system}\n\nThe frequency response of a DT LTI system can be thought of as arising in several equivalent ways. What follows is a common, but not exhaustive, list of ways the frequency response can be derived from other representations.\n\n\\subsection*{Using the Eigenvalues / Transfer Function}\n\nRecall if we apply the Eigenfunction $z^{n}$ for $z \\in \\mathbb{C}$ as the input to a LTI system, the output is the Eigenfunction scaled by the Eigenvalue (transfer function) $H(z)$ for values of $z$ in the region of convergence, where\n\\[\nH(z) = \\sum\\limits_{-\\infty}^{\\infty} h[n] z^{-n}\\; dt \\; .\n\\]\nis the bilateral Z transform of the impulse response.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/19-dt-tf.pdf}\n\\end{center}\n\nIf a system is stable, then the region of convergence includes the unit circle $z = e^{j\\omega}$. In that case, evaluating the Eigenvalues on the unit circle gives the DT frequency response $H\\left(e^{j\\omega}\\right)$. This converts from a function of a complex variable, $z$, to one of a real variable $\\omega$.\n\n\\begin{example} Consider a system with Eigenvalues (transfer function)\n  \\[\n  H(z) = \\frac{z}{z+\\tfrac{1}{2}}\\mbox{ for } |z| > \\frac{1}{2}\n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: We first need to check of the system is stable using the region-of-convergence. Since the region of convergence includes the unit circle, the system is stable. To find the frequency response we substitute $s = e^{j\\omega}$ to give\n  \\[\n  H\\left(e^{j\\omega}\\right) = \\frac{e^{j\\omega}}{e^{j\\omega} + \\tfrac{1}{2}}\n  \\]\n  \\\\$\\blacksquare$\n\\end{example}\n\n\\begin{example} Consider an apparently similar system with Eigenvalues\n  \\[\n  H(z) = \\frac{z}{z+2}\\mbox{ for } |z| > 2\n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: Again, we first need to check of the system is stable using the region-of-convergence. Since the region of convergence does not include the unit circle, the system is unstable. Thus, the frequency response does not exist.\n\\\\$\\blacksquare$\n\\end{example}\n\n\\subsection*{Using the DTFT}\n\nAnother way we can view the frequency response is as the DT Fourier Transform of the impulse response. If the system is stable, then the impulse response is absolutely integrable, and the Fourier transform exists giving $H\\left(e^{j\\omega}\\right) = \\mathcal{F}\\left\\{h[n]\\right\\}$. This is connected to the transfer function by noting the bilateral Z transform and the DT Fourier Transform are identical under the substitution $z = e^{j\\omega}$, which is allowed if the system is stable.\n\n\\begin{example} Suppose the impulse response of a DT LTI system is given by\n  \\[\n  h[n] = \\left(\\frac{1}{4}\\right)^n u[n] + 5\\left(\\frac{2}{3}\\right)^n u[n] \n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: If the system is stable, the Fourier transform of the impulse response exists. Since $\\left(\\frac{1}{4}\\right) < 1$ and $\\left(\\frac{2}{3}\\right) < 1$\n  \\[\nH\\left(e^{j\\omega}\\right) = \\mathcal{F}\\left\\{ \\left(\\frac{1}{4}\\right)^n u[n] + 5\\left(\\frac{2}{3}\\right)^n u[n] \\right\\} = \\mathcal{F}\\left\\{ \\left(\\frac{1}{4}\\right)^n u[n]\\right\\} + 5 \\mathcal{F}\\left\\{ \\left(\\frac{2}{3}\\right)^n u[n] \\right\\} = \\frac{e^{j\\omega}}{e^{j\\omega} - \\left(\\frac{1}{4}\\right)} + \\frac{5e^{j\\omega}}{e^{j\\omega} - \\left(\\frac{2}{3}\\right)} \n\\]\\\\\n$\\blacksquare$\n\\end{example}\n\n\\subsection*{Directly from a LCCDE}\n\nBy the convolution theorem of the DTFT, the frequency response is the ratio of the output to input in the frequency domain, i.e.\n\\[\nH\\left(e^{j\\omega}\\right) = \\frac{Y\\left(e^{j\\omega}\\right)}{X\\left(e^{j\\omega}\\right)}\n\\]\nWe can easily determine this ratio from the LCCDE representation of the system using the shifting property of the DT Fourier Transform. Recall this property states if $\\mathcal{F}\\{x[n]\\} = X\\left(e^{j\\omega}\\right)$ then\n\\[\n\\mathcal{F}\\left\\{x[n-m] \\right\\} =  e^{-j\\omega m} X\\left(e^{j\\omega}\\right)\\; .\n\\]\nfor index shift $m\\in\\mathbb{Z}$.\n\nIf the system is stable (and thus the frequency response exists) then \\textbf{all} roots of the characteristic equation $Q(E)$ have magnitude that are less than one. If the system is stable we can take the Fourier transform of each term of the LCCDE using the shift property, then algebraically solve for the ratio of output to input. Note this provides a significant savings in analysis effort since we do not have to first find the impulse response, then take it's Fourier transform to arrive at the frequency response (although that approach is still valid).\n\n\\begin{example} Consider a system described by the LCCDE\n  \\[\n  3y[n+1]-y[n] = x[n+1]\n  \\]\n  Determine the frequency response of the system, if possible.\n\n  Solution: We first need to check for stability. The characteristic equation is $Q(E) = 3E - 1$ which has a single root of $\\frac{1}{3}$. Since it is less than one, the system is stable. Next we take the Fourier transform of both sides and apply the derivative property\n  \\[\n  3e^{j\\omega} Y\\left(e^{j\\omega}\\right) - Y\\left(e^{j\\omega}\\right) = e^{j\\omega} X\\left(e^{j\\omega}\\right)\n  \\]\n  and rearrange to get the frequency response\n  \\[\n  H\\left(e^{j\\omega}\\right) = \\frac{e^{j\\omega}}{3e^{j\\omega}-1}\n  \\]\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\section{Magnitude-phase representation of the DTFR}\n\nNote that any complex valued function can be expressed in polar form using the magnitude and phase. Specifically the input and output can be put into this form\n\\[\nX\\left(e^{j\\omega}\\right) = |X\\left(e^{j\\omega}\\right)|e^{\\angle X\\left(e^{j\\omega}\\right)}\n\\]\n\\[\nY\\left(e^{j\\omega}\\right) = |Y\\left(e^{j\\omega}\\right)|e^{\\angle Y\\left(e^{j\\omega}\\right)}\n\\]\n\nBy the convolution theorem then\n  \\[\n  H\\left(e^{j\\omega}\\right) = \\frac{Y\\left(e^{j\\omega}\\right)}{X\\left(e^{j\\omega}\\right)} = \\frac{|Y\\left(e^{j\\omega}\\right)|e^{\\angle Y\\left(e^{j\\omega}\\right)}}{ |X\\left(e^{j\\omega}\\right)|e^{\\angle X\\left(e^{j\\omega}\\right)}} = \\frac{|Y\\left(e^{j\\omega}\\right)|}{|X\\left(e^{j\\omega}\\right)|}e^{\\angle Y\\left(e^{j\\omega}\\right) - \\angle X\\left(e^{j\\omega}\\right)} = |H\\left(e^{j\\omega}\\right)|e^{\\angle H\\left(e^{j\\omega}\\right)}\n  \\]\n  Thus we see that\n  \\[\n  |H\\left(e^{j\\omega}\\right)| = \\frac{|Y\\left(e^{j\\omega}\\right)|}{|X\\left(e^{j\\omega}\\right)|}\n  \\]\n  and\n  \\[\n  \\angle H\\left(e^{j\\omega}\\right) = \\angle Y\\left(e^{j\\omega}\\right) - \\angle X\\left(e^{j\\omega}\\right)\n  \\]\n  This is the magnitude and phase representation of the frequency response.\n  \n\\section{DTFR acting on sinusoids}\n\nThe advantage of the magnitude and phase representation of the frequency response, is the ease with which we can find the output due to a sinusoidal input. If we apply a sinusoidal input $x[n] = A e^{j\\omega n}$, the output is a the same sinusoid scaled by the frequency response $y[n] = H\\left(e^{j\\omega}\\right) A e^{j\\omega n}$.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/19-dt-fr.pdf}\n\\end{center}\n\nNow using the magnitude and phase representation\n\\[\ny[n] = H\\left(e^{j\\omega}\\right) A e^{j\\omega n} = |H\\left(e^{j\\omega}\\right)|e^{\\angle H\\left(e^{j\\omega}\\right)} A e^{j\\omega n} = A |H\\left(e^{j\\omega}\\right)| e^{j\\omega n + \\angle H\\left(e^{j\\omega}\\right)} \n\\]\nThus we can interpret the frequency response as telling us how the input sinusoids are scaled in magnitude and phase shifted as they pass through the system.\n\nBy the linearity property this extends to real sinusoidal inputs since\n\\begin{align*}\n  x[n] &\\longrightarrow y[n]\\\\\n  \\sin(\\omega n) &\\longrightarrow \\frac{1}{2j}|H\\left(e^{j\\omega}\\right)| e^{j\\omega n + \\angle H\\left(e^{j\\omega}\\right)} - \\frac{1}{2j}|H\\left(e^{j\\omega}\\right)| e^{-j\\omega n + \\angle H\\left(e^{j\\omega}\\right)}\\\\\n  \\sin(\\omega n) &\\longrightarrow |H\\left(e^{j\\omega}\\right)|\\sin(\\omega n + \\angle H\\left(e^{j\\omega}\\right))  \n\\end{align*}\nand\n\\begin{align*}\n  x[n] &\\longrightarrow y[n]\\\\\n  \\cos(\\omega n) &\\longrightarrow \\frac{1}{2}|H\\left(e^{j\\omega}\\right)| e^{j\\omega n + \\angle H\\left(e^{j\\omega}\\right)} + \\frac{1}{2}|H\\left(e^{j\\omega}\\right)| e^{-j\\omega n + \\angle H\\left(e^{j\\omega}\\right)}\\\\\n  \\cos(\\omega n) &\\longrightarrow |H\\left(e^{j\\omega}\\right)|\\cos(\\omega n + \\angle H\\left(e^{j\\omega}\\right))  \n\\end{align*}\n\nAlso by the linearity property this analysis extends to the DT Fourier representation of a signal (an infinite sum of sinusoids):\n\\[\nx[n] = \\frac{1}{2\\pi}\\int\\limits_{2\\pi} X\\left(e^{j \\omega}\\right) \\, e^{j \\omega n}\\; d\\omega \\;\\longrightarrow\\; y[n] = \\frac{1}{2\\pi}\\int\\limits_{2\\pi} H\\left(e^{j \\omega}\\right) X\\left(e^{j \\omega}\\right) \\, e^{j \\omega n}\\; d\\omega = \\frac{1}{2\\pi}\\int\\limits_{2\\pi} \\left| H\\left(e^{j\\omega}\\right)\\right| X\\left(e^{j\\omega}\\right) \\, e^{j \\omega n + \\angle H\\left(e^{j\\omega}\\right)}\\; d\\omega\n\\]\n\nThus we arrive at the reason for the name DT \\textit{Frequency Response} -- it specifies the the response of a stable system to any linear combination of DT sinusoidal inputs, i.e. any signal with a Fourier Transform.\n\n\\section{Plotting the DT frequency response}\n\nAs in CT, we can visualize the frequency response as a plot of the real and imaginary part, or, of the magnitude and phase. Since the magnitude and phase allow us to directly see the system behavior at a given frequency, those plots are much more useful.\n\nIn contrast to CT, where the unique Bode plot format is used, for the DTFR it is most common to plot the magnitude spectrum in dB and the phase spectrum in rad over just $\\omega = [0, \\pi]$. Since the DTFR is periodic there is no need to compress the information using a logarithmic frequency scale. Further, if $x[n]$ is real the DTFR magnitude spectrum is even, so that the magnitude from $\\omega = [\\pi, 2\\pi]$ is the same as from $\\omega = [-\\pi, 0]$. Also if $x[n]$ is real the DTFR phase spectrum is odd, so that the phase from $\\omega = [\\pi, 2\\pi]$ is the same as the negative from $\\omega = [-\\pi, 0]$. Note we would not call this kind of plot a Bode plot as that is typically reserved for the CTFR.\n\nAs with the CTFR it is important to understand these plots well enough to create them on your own using software and read them.\n\n\\begin{example} Consider a frequency response given by\n  \\[\n  H\\left(e^{j\\omega}\\right) = \\frac{4e^{j\\omega}}{4e^{j\\omega} - 1} \n  \\]\n  The following Matlab code shows you how to plot the spectrum (with some extra code to make it look nicer).\n  \n\\begin{verbatim}\n% compute the FTFR\nw = 0:0.001:pi;\nH = 4.*exp(j*2*w)./(4*exp(j*2*w) - 1);\n\n% Create a nice DTFR plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = plot(w,20*log10(abs(H)));\naxis tight;\ngrid on;\nhTitle  = title ('Frequency Response');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, ...\n    'Box', 'off', 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = plot(w,angle(H));\naxis tight;\ngrid on;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/sample)');\nset(gca, 'FontSize', 14, 'Box', 'off', 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\nThis gives the following plot\n\\begin{center}\n\\includegraphics[scale=0.5]{graphics/lecture21_1.png}\n\\end{center}\n\n$\\blacksquare$\n\\end{example}\n\nTo read a Bode plot to see the behavior of the system at a given frequency, one need only read the values off the plot and convert from dB to a unit-less gain.\n\n\\begin{example}\n  Suppose you are given the DTFR plot (only) from the previous example and are asked: what the output of the system is when the input is $x[n] = \\cos\\left(\\frac{\\pi}{4} n\\right)$?\\\\\n  \\textbf{Solution:} We go to the frequency $\\frac{\\pi}{4} \\approx 0.78$ on the plot and read off a value of about $-0.1$ dB for the magnitude and about $-0.25$ rad for the phase. To convert back from dB\n  \\[\n  \\left|H\\left(e^{j\\frac{\\pi}{4}}\\right)\\right| = 10^{\\frac{-0.1}{20}} \\approx 0.988 \n  \\]\n  so the output would be\n  \\[\n  y[n] \\approx 0.988\\cos\\left(\\frac{\\pi}{4} n  - 0.25\\right)\n  \\]\n  $\\blacksquare$\n\\end{example}\n", "meta": {"hexsha": "3b1bcd36eda71fba127ea2fb1ea5ee73ede27da1", "size": 12317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "19-dt-fr.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": "19-dt-fr.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": "19-dt-fr.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": 55.481981982, "max_line_length": 708, "alphanum_fraction": 0.6894536007, "num_tokens": 3832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650403, "lm_q2_score": 0.9046505395995929, "lm_q1q2_score": 0.7968135603625334}}
{"text": "\\section*{Problem 3 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\n\\begin{align*}\n\\frac{dy}{dx}\t&= -3y \\\\\n\\frac{dy}{y} \t& = -3\\,dx \\\\\n\\int\\frac{dy}{y}&= -3 \\int \\,dx \\\\\n\\ln y\t\t\t&= -3 x + C \\\\\ny\t\t\t\t&= e^{-3x + C} \\\\\n\\end{align*}\n$$\\boxed{y = Ce^{-3x}}$$\n\n\\item \n\nSolve the second order differential equation\n$$ \\frac{d^2 y}{dx^2} - A^2y = B $$\nFor the homogeneous equation, $\\frac{d^2 y}{dx^2} - A^2y = 0$, try $y_c = X_1 e^{Ax} + X_2 e^{-Ax}$ as the complementary solution ($X_1$ and $X_2$ are constants). Then\n$$ \\frac{d^2 y}{dx^2} = X_1 A^2 e^{Ax} + X_2 A^2 e^{-Ax} $$\nand\n$$ (X_1 A^2 e^{Ax} + X_2 A^2 e^{-Ax}) - A^2(X_1 e^{Ax} + X_2 e^{-Ax}) = 0 $$\n$$ A^2 (X_1 e^{Ax} + X_2 e^{-Ax}) - A^2 (X_1 e^{Ax} + X_2 e^{-Ax}) = 0 $$\n\nThis is \\underline{true}.\n\nFor the inhomogeneous equation, $\\frac{d^2 y}{dx^2} - A^2y = B$, $y_P = -B/A^2$ is the only particular solution satisfying the equation. The general solution is the sum of the complementary and particular solutions, $y = y_c + y_p$. \n$$ y = X_1 e^{Ax} + X_2 e^{-Ax} - \\frac{B}{A^2} $$\nNow we can solve for $X_1$ and $X_2$. \n$$ y(\\frac{1}{A}) = X_1 e^{A(\\frac{1}{A})} + X_2 e^{-A(\\frac{1}{A})} - \\frac{B}{A^2} = 0 $$\nand\n$$ y(-\\frac{1}{A}) = X_1 e^{A(-\\frac{1}{A})} + X_2 e^{A(\\frac{1}{A})} - \\frac{B}{A^2} = 0 $$\nWe can note that in these two equations, $X_1$ and $X_2$ can be interchanged freely, and so must be equal. We will say, $X_1 = X_2 = X$. Then, we have\n$$ 0 = X e^{A(-\\frac{1}{A})} + X e^{A(\\frac{1}{A})} - \\frac{B}{A^2} $$\n$$ 0 = X (e^{-1} + e^{1}) - \\frac{B}{A^2} $$\n$$ X = \\frac{B}{A^2(\\frac{1}{e} + e)} $$\nThe we plug this $X$ into the final solution, which gives\n$$ y = \\frac{B}{A^2(\\frac{1}{e} + e)} (e^{Ax} + e^{-Ax}) - \\frac{B}{A^2} $$\n\\end{enumerate}\nNote that $e^{Ax} + e^{-Ax}$ is similar in form to $\\cosh(Ax)$ which we could have also used to solve this problem.\n\n", "meta": {"hexsha": "b36b92112b50ea0287690e026fa88f9c10aa7730", "size": 1837, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc01/disc01_solution03.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_solution03.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_solution03.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": 42.7209302326, "max_line_length": 233, "alphanum_fraction": 0.5459989113, "num_tokens": 826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9585377272885903, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7966819701504061}}
{"text": "The grammar used in this section is the following:\n\n\\begin{align*}\n    &S \\to BA\\\\\n    &A \\to a\\\\\n    &B \\to BB|a|b\n\\end{align*}\n\n\\subsubsection{Number of iterations/recursive calls for each parser}\n\nAn interesting thing to notice is that with that grammar and a string of size $n$, no matter the used pattern, the amount of needed iterations or recursive calls will be the same for the naive, top-down and `boolean' bottom-up parsers.\n\nThe `string' bottom-up parser follows exactly the same behaviour as with the previous grammar.\n\nBy decomposing the behaviour of the naive parser one can find out that for any pattern it evolves following that sequence:\n\\begin{equation}\\label{seq:naive}\nn + (n - 1)^2\n\\end{equation}\n\nIt can be demonstrated like so:\n\n\\begin{itemize}\n    \\item[$-$] The initial call is $parse(S, 0, n)$\n    \\item[$-$] Then it calls $parse(B, 0, 1)$, which returns true no matter the character.\n    \\item[$-$] Then it calls $parse(A, 1, n)$, which returns false since A doesn't possess any \\textit{non-terminals}.\n    \\item[$-$] Then it calls $parse(B, 0, 2)$, which returns true by doing 2 more recursive calls, $parse(B, 0, n)$ will always return true and do two more recursive calls each time it is called.\n    \\item[$-$] The process ends up when $parse(A, n - 1, n)$ is called, then it returns true or false depending on if the last character is an `a' or a `b'. No matter the result, and so the pattern, the algorithm will always make the same amount of recursive calls.\n    \\item[$-$] When it ends up the number of recursive calls is $1$ for the initial call, plus $n - 1$ for each time it has called parse(A, x, n), plus $(n - 1)^2$ for each time it has called parse(B, 0, x) and all the recursive calls it made. So the total number of recursive calls is $n + (n - 1)^2$ for the naive parser.\n\\end{itemize}\n\nThe top-down parser follows the exact same behaviour as the naive parser, to parse a string of size $n$ it will also need $n + (n - 1)^2$ recursive calls.\n\nHowever some sub-problems will not need to be recomputed by the top-down parser, it is possible to show that, for a string of size $n$ and whatever pattern is used, it needs to solve that many sub-problems:\n\\begin{equation}\\label{seq:top-down}\nn + (n - 1)^2 - \\dfrac{(n - 2) \\cdot (n - 1)}{2}\n\\end{equation}\n\nHere is the demonstration:\n\n\\begin{itemize}\n    \\item[$-$] The running process is exactly the same as for the naive one, the difference is that some results have already been computed and can be directly returned.\n    \\item[$-$] The amount of results already stored in the table and then asked again increases by one for each level of recursive depth when $parse(B, 0, x)$ is called.\n    \\item[$-$] This amount corresponds to a triangular number sequence: $\\dfrac{n \\cdot (n + 1)}{2}$. The formula needs to be twisted a little to match the string size $n$ and the number of asked already known results is $\\dfrac{(n - 1) \\cdot (n - 2)}{2}$.\n    \\item[$-$] Then the total amount of solved sub-problems is just the number of recursive calls minus the expression above: $n + (n - 1)^2 - \\dfrac{(n - 2) \\cdot (n - 1)}{2}$.\n\\end{itemize}\n\nIt is now possible to compare the anticipated behaviours of the naive, top-down and bottom-up parsers, using functions \\ref{seq:naive} and \\ref{eq:bottom-up_iterations}.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=`Boolean' bottom-up, xlabel=string size, ylabel=iterations]\n    \\addplot[red, domain=0:1000]{2 * x + ((3 / 6) * ((3 * (x^2) * (x + 1)) - (x * (x + 1) * ((2 * x) + 1))))};\n    \\nextgroupplot[title=Naive and top-down, xlabel=string size, ylabel=recursive calls]\n    \\addplot[blue, domain=0:50000]{x + (x - 1)^2};\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{Anticipation of the behaviours of the parsers, grammar 3}\n\\end{figure}\n\\FloatBarrier\n\nThe `boolean' bottom-up parser follows a power function with an exponent of three as usual, but the top-down and naive parsers will follow a power function with an exponent of two with that grammar.\n\n\\subsubsection{Comparing the efficiency}\n\nExcept for the `string' bottom-up parser, with this grammar there is no particular cases, any pattern will be as long to parse as another by any of the three other parsers, the first used pattern is $a^n$.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 2},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Both bottom-up counters, ylabel=iterations, legend pos = north west]\n    \\addplot coordinates {\n        (100, 1500150)\n        (200, 12000300)\n        (400, 96000600)\n        (600, 324000900)\n        (800, 768001200)\n        (1000, 1500001500)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (100, 333600)\n        (200, 2667200)\n        (400, 21334400)\n        (600, 72001600)\n        (800, 170668800)\n        (1000, 333336000)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Both bottom-up running times, ylabel=seconds, legend pos = north west]\n    \\addplot coordinates {\n        (100, 0.087481)\n        (200, 0.652142)\n        (400, 5.16778)\n        (600, 16.9815)\n        (800, 40.5165)\n        (1000, 79.5284)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (100, 0.012412)\n        (200, 0.102093)\n        (400, 0.82625)\n        (600, 3.08987)\n        (800, 8.56199)\n        (1000, 18.7261)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Top-down/Naive counters, ylabel=recursive calls, xlabel=string size, legend pos = north west]\n    \\addplot coordinates {\n        (100, 9901)\n        (1000, 999001)\n        (3000, 8997001)\n        (5000, 24995001)\n        (7000, 48993001)\n        (9000, 80991001)};\n    \\nextgroupplot[title=Top-down/Naive running times, ylabel=seconds, legend pos=north west, xlabel=string size]\n    \\addplot coordinates {\n        (100, 0.000158)\n        (1000, 0.016837)\n        (3000, 0.176553)\n        (5000, 0.50593)\n        (7000, 1.05917)\n        (9000, 1.69652)};\n    \\addlegendentry{TD parsing}\n    \\addplot coordinates {\n        (100, 0.00027)\n        (1000, 0.020982)\n        (3000, 0.207965)\n        (5000, 0.595206)\n        (7000, 1.23223)\n        (9000, 1.99075)};\n    \\addlegendentry{TD total}\n    \\addplot coordinates {\n        (100, 0.000091)\n        (1000, 0.004109)\n        (3000, 0.031383)\n        (5000, 0.089245)\n        (7000, 0.17303)\n        (9000, 0.29419)};\n    \\addlegendentry{TD init}\n    \\addplot coordinates {\n        (100, 0.000173)\n        (1000, 0.01458)\n        (3000, 0.134243)\n        (5000, 0.374054)\n        (7000, 0.776454)\n        (9000, 1.17694)};\n    \\addlegendentry{Naive}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{The 4 parsers behaviours, grammar 3}\n\\end{figure}\n\\FloatBarrier\n\nWith strings of sizes greater than $9,000$ the top-down parser could not allocate the table so the used strings did not exceed that size.\n\nThe same string sizes are used for the top-down and naive parsers, it is possible to see on the graphs above that despite the fact that the naive parser and the top-down parsers need the same amount of recursive calls the naive parser has a lower running time.\n\nThe only parser that needs a various number of iterations is the `string' bottom-up parser, the pattern `$a\\string^ n$' was as previously its worst case, its best case with that grammar is the pattern `$b\\string^ n$' as previously.\nIt is not a suprise to find out that the `string' bottom-up parser is slower than the `boolean' version with that grammar, since it follows the same behaviour as before.\n\nNext are the results obtained with the `string' bottom-up parser, using the last results for the `boolean' bottom-up parser as reference.\n\n\\FloatBarrier\n\\begin{figure}[h]\n\\begin{tikzpicture}\n    \\begin{groupplot}[group style={group size=2 by 1},height=0.5\\textwidth,width=0.5\\textwidth] \n    \\nextgroupplot[title=Both bottom-up counters, ylabel=iterations, xlabel=string size, legend pos = north west]\n    \\addplot coordinates {\n        (100, 500250)\n        (200, 4000500)\n        (400, 32001000)\n        (600, 108001500)\n        (800, 256002000)\n        (1000, 500002500)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (100, 333600)\n        (200, 2667200)\n        (400, 21334400)\n        (600, 72001600)\n        (800, 170668800)\n        (1000, 333336000)};\n    \\addlegendentry{Boolean}\n    \\nextgroupplot[title=Both bottom-up running times, legend pos = north west, xlabel=string size, ylabel=seconds]\n    \\addplot coordinates {\n        (100, 0.042859)\n        (200, 0.322342)\n        (400, 2.60902)\n        (600, 8.56177)\n        (800, 20.5762)\n        (1000, 40.6679)};\n    \\addlegendentry{String}\n    \\addplot coordinates {\n        (100, 0.012412)\n        (200, 0.102093)\n        (400, 0.82625)\n        (600, 3.08987)\n        (800, 8.56199)\n        (1000, 18.7261)};\n    \\addlegendentry{Boolean}\n    \\end{groupplot}\n\\end{tikzpicture}\n\\caption{The `string' bottom-up parser worst case, grammar 3}\n\\end{figure}\n\\FloatBarrier\n\nAs with the previous grammar the best case of the `string' bottom-up parser is once again slower than the `boolean' version.\nThe running time follows exactly the same curve as the number of iterations for the `string' bottom-up parser.\n\nIt would be possible to plot the area containing all the possible cases of the `string' bottom-up parser once again but it would be the exact same figure as before since the running time of the parser for each pattern remains the same with both grammars.\n", "meta": {"hexsha": "112955969f2f834aa9cc70e38f50a34b504c78b3", "size": 9591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/grammar_3.tex", "max_stars_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_stars_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections/grammar_3.tex", "max_issues_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_issues_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections/grammar_3.tex", "max_forks_repo_name": "ThomasRanvier/cyk_algorithm_analysis", "max_forks_repo_head_hexsha": "f6d7fbf95533461b58b0a9937530f1e4d8bc2e29", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-13T17:38:35.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-13T17:38:35.000Z", "avg_line_length": 45.4549763033, "max_line_length": 323, "alphanum_fraction": 0.6701073923, "num_tokens": 2857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.893309411735131, "lm_q2_score": 0.8918110461567922, "lm_q1q2_score": 0.7966632010212158}}
{"text": "\\section{Tensor Polynomial (First-Order)}\nAssociated external model: \\texttt{tensor\\_poly.py}\n\nTensor polynomial evaluation for quantity of interest $u$ with input parameters $Y=[y_1,\\ldots,y_N]$:\n\\begin{equation}\nu(Y) = \\prod_{n=1}^N y_n+1.\n\\end{equation}\nThis test is specifically useful for its analytic statistical moments.  It is used as a benchmark in\n\\cite{ayreseaton2015}.\n\n\\subsection{Uniform, (-1,1)}\nLet all $y_n$ be uniformly distributed between -1 and 1.  The first two statistical moments are:\n\n\\subsubsection{mean}\n\\begin{align}\n\\expv{u(Y)} &=\\int_{-1}^1 dY \\rho(Y)u(Y), \\notag \\\\\n  &=\\int_{-1}^1 dy_1\\cdots\\int_{-1}^1 dy_N \\prod_{n=1}^N \\frac{y_n+1}{2},\\notag \\\\\n  &=\\left[ \\int_{-1}^1 dy \\frac{y+1}{2}\\right]^N,\\\\\n  &=\\left[\\frac{1}{2}\\left(\\frac{y^2}{2}+y\\right)\\bigg|_{-1}^1\\right]^N, \\notag \\\\\n  &=\\left[\\frac{2}{2}\\right]^N, \\notag \\\\\n  &=1. \\notag\n\\end{align}\n\n\\subsubsection{variance}\n\\begin{align}\n\\expv{u(Y)^2} &= \\int_{-1}^1 dY \\rho(Y)u(Y),\\notag \\\\\n  &=\\int_{-1}^1 dy_1\\cdots\\int_{-1}^1 dy_N \\frac{1}{2^N} \\left(\\prod_{n=1}^N y_n+1\\right)^2,\\notag \\\\\n  &=\\left[\\frac{1}{2}\\left(\\int_{-1}^1 dy\\ y^2+2y+1 \\right)\\right]^N,\\\\\n  &=\\left[\\frac{1}{2}\\left(\\frac{y^3}{3}+y^2+y \\right)\\bigg|_{-1}^1 \\right]^N, \\notag \\\\\n  &=\\left[\\frac{1}{3}+1\\right]^N, \\notag \\\\\n  &=\\left(\\frac{4}{3}\\right)^N.\\notag \\\\\n\\text{var}[u(Y)] &= \\expv{u(Y)^2}-\\expv{u(Y)}^2,\\notag \\\\\n  &= \\left(\\frac{4}{3}\\right)^N-1.\n\\end{align}\n\n\\subsubsection{numeric values}\nSome numeric values for the mean and variance are listed below for several input cardinalities $N$.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{c|c|c}\n    $N$ & mean & variance \\\\ \\hline\n    2 & 1.0 & 0.77777777777 \\\\\n    4 & 1.0 & 2.16049382716 \\\\\n    6 & 1.0 & 4.61865569273\n  \\end{tabular}\n\\end{table}\n\n\\subsection{Uniform, (0,1)}\nLet all $y_n$ be uniformly distributed between 0 and 1.  The first two statistical moments are:\n\n\\subsubsection{mean}\n\\begin{align}\n\\expv{u(Y)} &=\\int_{0}^1 dY \\rho(Y)u(Y),\\\\\n  &=\\int_{0}^1 dy_1\\cdots\\int_{0}^1 dy_N \\prod_{n=1}^N y_n+1,\\\\\n  &=\\left[ \\int_{0}^1 dy y+1\\right]^N,\\\\\n  &=\\left[\\left(\\frac{y^2}{2}+y\\right)\\bigg|_{0}^1\\right]^N,\\\\\n  &=\\left[\\frac{3}{2}\\right]^N.\n\\end{align}\n\n\\subsubsection{variance}\n\\begin{align}\n\\expv{u(Y)^2} &= \\int_{0}^1 dY \\rho(Y)u(Y),\\\\\n  &=\\int_{0}^1 dy_1\\cdots\\int_{0}^1 dy_N \\left(\\prod_{n=1}^N y_n+1\\right)^2,\\\\\n  &=\\left[\\left(\\int_{0}^1 dy\\ y^2+2y+1 \\right)\\right]^N,\\\\\n  &=\\left[\\left(\\frac{y^3}{3}+y^2+y \\right)\\bigg|_{0}^1 \\right]^N,\\\\\n  &=\\left(\\frac{7}{3}\\right)^N.\\\\\n\\text{var}[u(Y)] &= \\expv{u(Y)^2}-\\expv{u(Y)}^2,\\\\\n  &= \\left(\\frac{7}{3}\\right)^N-\\left(\\frac{3}{2}\\right)^{2N}.\n\\end{align}\n\n\\subsubsection{numeric values}\nSome numeric values for the mean and variance are listed below for several input cardinalities $N$.\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{c|c|c}\n    $N$ & mean & variance \\\\ \\hline\n    2 & 2.25      & 0.38194444444 \\\\\n    4 & 5.0625    & 4.01306905864 \\\\\n    6 & 11.390625 & 31.6377499009\n  \\end{tabular}\n\\end{table}\n\n\\subsection{Multivariate Normal}\nLet $Y$ be $N$-dimensional, and have a multivariate normal distribution:\n\\begin{equation}\nY \\thicksim N(\\mu,\\Sigma)\n\\end{equation}\nwith $N$-dimensional mean vector $\\mu=[\\mu_{y_1},\\mu_{y_2},\\ldots,\\mu_{y_N}]$, and $N X N$ covariance matrix:\n\\begin{equation}\n\\Sigma = [Cov[y_i,y_j]],i = 1,2,\\ldots,N; j = 1,2,\\ldots,N\n\\end{equation}\n\nTo be simplicity, we assume there are no correlations between the input parameters. Then, the covariance matrix can be written\nas:\n\\begin{equation}\n\\Sigma =\n\\begin{pmatrix}\n\\sigma_{y_1}^2 & 0 &\\ldots & 0 \\\\\n0 & \\sigma_{y_2}^2 &\\ldots & 0 \\\\\n\\vdots &\\vdots &\\ddots & \\vdots \\\\\n0 & 0 & \\ldots & \\sigma_{y_N}^2\\\\\n\\end{pmatrix}\n\\end{equation}\nwhere $\\sigma_{y_i}^2 = Cov[y_i,y_i]$, for $i = 1,2,\\ldots,N$. Based on this assumption, the first two statistical moments are:\n\n\\subsubsection{mean}\n\\begin{align}\n\\expv{u(Y)} &=\\int_{-\\infty}^\\infty dY \\rho(Y)u(Y),\\notag \\\\\n  &=\\int_{-\\infty}^\\infty dy_1 (1/\\sqrt{2 \\pi \\sigma_{y_1}}e^{-\\frac{(y_1-\\mu_{y_1})^2}{2\\sigma_{y_1}^2}})\\cdots\\int_{-\\infty}^\\infty dy_N (1/\\sqrt{2 \\pi \\sigma_{y_N}}e^{-\\frac{(y_N-\\mu_{y_N})^2}{2\\sigma_{y_N}^2}})\\prod_{n=1}^N (y_n+1),\\\\\n  &=\\prod_{n=1}^5{(\\mu_{y_n}+1)}.\\notag\n\\end{align}\n\n\\subsubsection{variance}\n\\begin{align}\n\\text{var}[u(Y)]=\\expv{(u(Y)-\\expv{u(Y)})^2} &= \\int_{-\\infty}^\\infty dY \\rho(Y)(u(Y)-\\expv{u(Y)})^2,\\notag \\\\\n  &=\\int_{-\\infty}^\\infty dy_1 (1/\\sqrt{2 \\pi \\sigma_{y_1}}e^{-\\frac{(y_1-\\mu_{y_1})^2}{2\\sigma_{y_1}^2}}), \\notag \\\\\n  &\\cdots\\int_{-\\infty}^\\infty dy_N  (1/\\sqrt{2 \\pi \\sigma_{y_N}}e^{-\\frac{(y_N-\\mu_{y_N})^2}{2\\sigma_{y_N}^2}})(\\prod_{n=1}^N (y_n+1-\\expv{u(Y)})^2,\\\\\n  &=\\prod_{n=1}^5{[(1+\\mu_{y_n})^2+\\sigma_{y_n}^2]} - [\\prod_{n=1}^5{(\\mu_{y_n}+1)}]^2. \\notag\n\\end{align}\n\\subsubsection{numeric values}\nFor example, for given mean $\\mu = [0.5, -0.4, 0.3, -0.2, 0.1]$, and covariance\n\\begin{equation}\n\\Sigma =\n\\begin{pmatrix}\n0.64 & 0 & 0 & 0 & 0 \\\\\n0 & 0.49 & 0 & 0 & 0 \\\\\n0 & 0 & 0.09 & 0 & 0 \\\\\n0 & 0 & 0 & 0.16 & 0 \\\\\n0 & 0 & 0 & 0 & 0.25 \\\\\n\\end{pmatrix}\n\\end{equation}\nThe mean and variance can computed using previous equation, and the results are:\n\\begin{equation}\n\\expv{u(Y)} = 1.0296\n\\end{equation}\n\\begin{equation}\n\\text{var}[u(Y)] = 4.047085600000002\n\\end{equation}\n\n", "meta": {"hexsha": "10463f63d2f7a00753ee089adae6173a0450b978", "size": 5257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/tensor_poly.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/tensor_poly.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/tensor_poly.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": 37.55, "max_line_length": 238, "alphanum_fraction": 0.617462431, "num_tokens": 2323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8918110360927155, "lm_q1q2_score": 0.7966631818985127}}
{"text": "\\subsection{Cardinality of the rationals}\n\n\\subsubsection{Cardinality of rational numbers}\n\nWe can see rational numbers as cartesian products of integers. That is:\n\n\\(\\mathbb{Q}=Z.Z\\)\n\nWe can order the rational numbers like so:\n\n\\(\\{\\dfrac{1}{1},\\dfrac{2}{1},\\dfrac{1}{2},\\dfrac{1}{3},\\dfrac{2}{2}\\dfrac{3}{1}...\\}\\)\n\nThese can be mapped from natural numbers, so there is a bijunctive function.\n\nSo:\n\n\\(|\\mathbb{Q} |=|\\mathbb{Z}.\\mathbb{Z} |=|\\mathbb{N} |=\\aleph_0\\)\n\nAs: \\(|\\mathbb{Z}.\\mathbb{Z} |=|\\mathbb{Z}|^2\\)\n\n\\(|\\mathbb{N}|^n=\\mathbb{N}\\)\n\n", "meta": {"hexsha": "0183abcee2edff813cab1920445882bfab39f59e", "size": 548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/rational/01-04-rationalsCardinality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/rational/01-04-rationalsCardinality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/rational/01-04-rationalsCardinality.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.8260869565, "max_line_length": 87, "alphanum_fraction": 0.651459854, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813551535005, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.796642773930543}}
{"text": "\\section{The complex numbers}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Add, subtract, multiply, and divide complex numbers.\n  \\item Find the conjugate and the magnitude of a complex number.\n  \\item Apply algebraic properties of the complex numbers to simplify\n    equations.\n  \\end{enumerate}\n\\end{outcome}\n\n\\begin{definition}{The complex numbers}{complex-numbers}\n  Let $i$ be an imaginary number such that $i\\,^2=-1$. A \\textbf{complex\n    number}%\n  \\index{complex number} is a number of the form\n  \\begin{equation*}\n    z = a + bi,\n  \\end{equation*}\n  where $a$ and $b$ are real numbers. The set of all complex numbers\n  is denoted $\\C$.\n\\end{definition}\n\nThe form $z = a+bi$ is called the \\textbf{standard form}%\n\\index{complex number!standard form}%\n\\index{standard form!of a complex number} or \\textbf{Cartesian form}%\n\\index{complex number!Cartesian form}%\n\\index{Cartesian form!of a complex number} of the complex number $z$.\nWe refer to $a$ as the \\textbf{real part}%\n\\index{complex number!real part}%\n\\index{real part!of a complex number} and to $b$ as the\n\\textbf{imaginary part}%\n\\index{complex number!imaginary part}%\n\\index{imaginary part!of a complex number} of $z$.\n\n\\textbf{Addition}%\n\\index{complex number!addition}%\n\\index{addition!of complex numbers}, \\textbf{subtraction}%\n\\index{complex number!subtraction}%\n\\index{subtraction!of complex numbers}, and \\textbf{multiplication}%\n\\index{complex number!multiplication}%\n\\index{multiplication!of complex numbers} of complex numbers are\ndefined in the obvious way, keeping in mind that $i\\,^2=-1$. Namely, we\nhave\n\\begin{eqnarray*}\n  (a+bi) + (c+di) &=& (a+c) + (b+d)i, \\\\\n  (a+bi) - (c+di) &=& (a-c) + (b-d)i, \\\\\n  (a+bi) (c+di)   &=& ac+adi+bci+bdi\\,^2 ~=~ (ac-bd) + (ad + bc)i.\n\\end{eqnarray*}\n\n\\begin{example}{Addition, subtraction, and multiplication of complex numbers}{complex-add-subtract-multiply}\n  \\begin{itemize}\n  \\item $(3+5i) + (2-3i) = (3+2) + (5-3)i         = 5 + 2i$.\n  \\item $(3+5i) - (2-3i) = (3-2) + (5+3)i         = 1 + 8i$.\n  \\item $(3+5i) (2-3i)   = 6 - 9i + 10i - 15i\\,^2 = 21 + i$.\n  \\end{itemize}\n\\end{example}\n\nDivision of complex numbers is more complicated. We first note that it\nis easy to divide a complex number by a {\\em real} number. Namely,\n\\begin{equation*}\n  \\frac{a+bi}{r} = \\frac{a}{r} + \\frac{b}{r}i.\n\\end{equation*}\nBut how can we divide by a complex number? We use the following\ntrick. Let $z=a+bi$ be a complex number, and consider the product\n$(a+bi)(a-bi)$. It is equal to\n\\begin{equation*}\n  (a+bi)(a-bi) = a^2 - b^2i\\,^2 = a^2+b^2.\n\\end{equation*}\nTherefore, $(a+bi)(a-bi)$ is always a {\\em real} number, and therefore\neasy to divide by. Therefore, we can compute the\n\\textbf{multiplicative inverse}%\n\\index{multiplicative inverse!of a complex number}%\n\\index{inverse!of a complex number}%\n\\index{complex number!inverse} of a complex number $z=a+bi$ as\nfollows:\n\\begin{equation*}\n  z^{-1}\n  = \\frac{1}{z}\n  = \\frac{1}{a+bi}\n  = \\frac{1}{a+bi}\\,\\frac{a-bi}{a-bi}=\\frac{a-bi}{a^2+b^2}.\n\\end{equation*}\n\n\\begin{example}{Inverse of a complex number}{complex-inverse}\n  \\begin{equation*}\n    \\frac{1}{2+5i}\n    = \\frac{2-5i}{2^2+5^2}\n    = \\frac{2}{29} - \\frac{5}{29}i.\n  \\end{equation*}\n\\end{example}\n\nYou should verify that this is indeed the inverse, by multiplying\n$2+5i$ by $\\frac{2}{29} - \\frac{5}{29}i$ and checking that the answer\nis indeed $1$.\n\n\\textbf{Division}%\n\\index{complex number!division}%\n\\index{division!of complex numbers} of complex numbers can then be\ndefined in terms of the multiplicative inverse, i.e.,\n$\\frac{z}{w} = zw^{-1}$.\n\n\\begin{example}{Division of complex numbers}{complex-division}\n  \\begin{equation*}\n    \\frac{5+7i}{3-4i}\n    = \\frac{(5+7i)(3+4i)}{(3-4i)(3+4i)}\n    = \\frac{-13+41i}{3^2+4^2}\n    = -\\frac{13}{25} + \\frac{41}{25}i.\n  \\end{equation*}\n\\end{example}\n\nAs a special case of division, note that\n\\begin{equation*}\n  i\\,^{-1} = \\frac{1}{i} = \\frac{1(-i)}{i(-i)} = -i.\n\\end{equation*}\n\nThe complex numbers form a {\\em field}, i.e., they satisfy the nine\nfield axioms. See Section~\\ref{sec:fields} for the definition of a\nfield.\n\n\\begin{proposition}{The complex numbers form a field}{complex-field}\n  The complex numbers, with the operations of addition, subtraction,\n  multiplication, and division, form a {\\em field}%\n  \\index{complex number!field axioms}%\n  \\index{field!of complex numbers}%\n  \\index{properties of addition!complex numbers}%\n  \\index{properties of multiplication!complex numbers}. Specifically,\n  this means that they satisfy the following properties:\n  \\begin{itemize}\n  \\item[(A1)] {Commutative law of addition:} $z+w=w+z$;\n  \\item[(A2)] {Associative law of addition:} $(z+w)+u = z+(w+u)$;\n  \\item[(A3)] {Unit law of addition:} $0+z = z$;\n  \\item[(A4)] {Additive inverse:} $z+(-z)=0$;\n  \\item[(M1)] {Commutative law of multiplication:} $zw=wz$;\n  \\item[(M2)] {Associative law of multiplication:} $(zw)u=z(wu)$;\n  \\item[(M3)] {Unit law of multiplication:} $1z=z$;\n  \\item[(M4)] {Multiplicative inverse:} when $z$ is non-zero: $zz^{-1}=1$;\n  \\item[(D)] {Distributive law:} $z(w+u)=zw+zu$.\n  \\end{itemize}\n\\end{proposition}\n\nAnother useful operation on complex numbers is the complex\nconjugate. Let $z = a+bi$ be a complex number. Then the\n\\textbf{conjugate}%\n\\index{complex number!conjugate}%\n\\index{conjugate!of a complex number}%\n\\index{complex conjugate} of $z$, written $\\conjugate{z}$, is given by\n\\begin{equation*}\n  \\conjugate{z} = a-bi.\n\\end{equation*}\nNote that if $z=a+bi$ is a complex number, then\n$z\\conjugate{z} = (a+bi)(a-bi) = a^2+b^2$. Therefore, $z\\conjugate{z}$\nis always a real number and $z\\conjugate{z}\\geq 0$. We define the\n\\textbf{magnitude}%\n\\index{complex number!magnitude}%\n\\index{magnitude!of a complex number} of $z$ to be\n\\begin{equation*}\n  \\abs{z} = \\sqrt{z\\conjugate{z}} = \\sqrt{a^2+b^2}.\n\\end{equation*}\nThe magnitude is also sometimes called the \\textbf{absolute value}%\n\\index{complex number!absolute value|see{magnitude}}%\n\\index{absolute value!of a complex number|see{magnitude}} or the\n\\textbf{modulus}%\n\\index{complex number!modulus|see{magnitude}}%\n\\index{modulus!of a complex number|see{magnitude}} of the complex\nnumber.\n\n\\begin{example}{Conjugate and magnitude of a complex number}{complex-conjugate}\n  \\begin{itemize}\n  \\item $\\conjugate{3+5i} = 3-5i$.\n  \\item $\\conjugate{i} = -i$.\n  \\item $\\conjugate{7} = 7$.\n  \\item $\\abs{3+5i} = \\sqrt{3^2+5^2} = \\sqrt{34}$.\n  \\item $\\abs{i} = 1$.\n  \\item $\\abs{-6} = 6$.\n  \\end{itemize}\n\\end{example}\n\nNote that for a real number $a$, we have $\\conjugate{a}=a$. Also, when\n$a$ is real, the magnitude $|a| = \\sqrt{a^2}$ is just the usual\nabsolute value of real numbers. The following two propositions\nlist some basic properties of the conjugate and of the magnitude.\n\n\\begin{proposition}{Properties of the conjugate}{properties-complex-conjugate}\n  Let $z$ and $w$ be complex numbers. Then, the following properties\n  of the conjugate hold.%\n  \\index{complex number!conjugate!properties}%\n  \\index{conjugate!of a complex number!properties}%\n  \\index{complex conjugate!properties}%\n  \\index{properties of complex conjugate}\n  \\begin{itemize}\n  \\item $\\conjugate{z\\pm w} = \\conjugate{z} \\pm \\conjugate{w}$.\n  \\item $\\conjugate{(zw)} = \\conjugate{z}~ \\conjugate{w}$.\n  \\item $\\conjugate{z^{-1}} = \\conjugate{z}^{-1}$.\n  \\item $\\conjugate{z/w} = \\conjugate{z} / \\conjugate{w}$.\n  \\item $\\conjugate{\\conjugate{z}}=z$.\n  \\item $z$ is real if and only if $\\conjugate{z}=z$.\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proposition}{Properties of the magnitude}{properties-complex-magnitude}\n  Let $z,w$ be complex numbers.  The following properties hold.%\n  \\index{complex number!magnitude!properties}%\n  \\index{magnitude!of a complex number!properties}\n  \\begin{itemize}\n  \\item $\\abs{z} \\geq 0$, and $\\abs{z}=0$ if and only if $z=0$.\n  \\item $\\abs{zw} = \\abs{z}\\abs{w}$.\n  \\item $\\abs{\\conjugate{z}} = \\abs{z}$.\n  \\item $\\abs{z/w} = \\abs{z}/\\abs{w}$.\n  \\item \\textbf{Triangle inequality}%\n    \\index{triangle inequality!in complex numbers}:\n    $\\abs{z+w} \\leq \\abs{z} + \\abs{w}$.\n  \\end{itemize}\n\\end{proposition}\n", "meta": {"hexsha": "362cc30e8f51a6ce5fcd62421e99a627c950fe16", "size": 8066, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/ComplexNumbers-ComplexNumbers.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/ComplexNumbers-ComplexNumbers.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/ComplexNumbers-ComplexNumbers.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.8685446009, "max_line_length": 108, "alphanum_fraction": 0.6762955616, "num_tokens": 2856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789468908171, "lm_q2_score": 0.89029422102812, "lm_q1q2_score": 0.7966258932057653}}
{"text": "\\paragraph{Numerical Experiment of Restriction}\nWe test to different restriction, on is 7-point (based on linear) and the other is 9 point (based on bilinear).\n\n The kernel of 7-point is \n\\begin{equation}\n\\begin{pmatrix}\n0 &0.5 &0.5\\\\\n0.5 &1 &0.5\\\\\n0.5 &0.5 &0\n\\end{pmatrix} \n\\end{equation} \n The kernel of 9-point is \n\\begin{equation}\n\\begin{pmatrix}\n0.25 &0.5 &0.25\\\\\n0.5 &1 &0.5\\\\\n0.25 &0.5 &0.25\n\\end{pmatrix} \n\\end{equation} \n\nSuppose the prolongation is $P$, \nwe can write a step iteration of two layer multigrid method as:\n\\begin{equation}\nx^{t+1}-x^*=[I-(D-U)^{-1}A][I-(D-L)^{-1}A][I-P(P^T A P)^{-1}P^T)A](x^t-x^*)\n\\end{equation}\nwrite $I-BA=[I-(D-U)^{-1}A][I-(D-L)^{-1}A][I-P(P^T A P)^{-1}P^T)A]$\n\n\nSome numerical experiment are briefly list below:\n\nOur problem is a Possion equation on $n\\times n$ conforming triangular grid. Boundary condition is Dirichlet or Neumann.\n\n\\begin{table}[!htp]\n\t\\caption{Dirichlet Boundary}\n\t\\begin{tabular}{l |c}\n\t\tn&  32\\\\ \\hline\n\t\t7-point  & 0.2308\t\\\\\n\t\t9-point  & 0.1984\t\\\\\n\t\\end{tabular}\n\\end{table}\n\\begin{table}[!htp]\n\t\\caption{Neumann Boundary}\n\t\\begin{tabular}{l |c}\n\t\tn&  32\\\\ \\hline\n\t\t7-point  & 0.2325\t\\\\\n\t\t9-point  & 0.2232\t\\\\\n\t\\end{tabular}\n\\end{table}\n\nFor multilayer, we choose $A_i = P_i^T A P_i$, then\n\\begin{equation}\nx^{t+1}-x^*=[\\Pi_{i=1}^{J}(I-T_i)](x^t-x^*)\n\\end{equation}\nwhere $T_i=\\Pi_iR_i\\Pi_i^TA$, $R_i$ is the GS smoother of $A_i$.\n\n\\begin{table}[!htp]\n\t\\caption{Dirichlet Boundary}\n\t\\begin{tabular}{l |c c}\n\t\tLayer& 2&3 \\\\ \\hline\n\t\t7-point  & 0.3234 &\t0.7433\\\\\n\t\t9-point  & 0.2870 &\t0.6256\\\\\n\t\\end{tabular}\n\\end{table}\n\n\\begin{table}[!htp]\n\t\\caption{Neumann Boundary}\n\t\\begin{tabular}{l |c c}\n\t\tLayer& 2&3 \\\\ \\hline\n\t\t7-point  & 0.3289 &\t0.7167\\\\\n\t\t9-point  & 0.3155 &\t0.6283\\\\\n\t\\end{tabular}\n\\end{table}\n\n\n", "meta": {"hexsha": "79b5654ac4728a2600e7525880b3dcb1bf5d7615", "size": 1777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/amg-p.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/amg-p.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/amg-p.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": 23.6933333333, "max_line_length": 120, "alphanum_fraction": 0.6359032077, "num_tokens": 783, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107966642557, "lm_q2_score": 0.8499711756575749, "lm_q1q2_score": 0.7966021626796898}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\\begin{document}\n\\title{Advent of Code 2021: Day 7}\n\\author{Lyle Kopnicky}\n\\maketitle\n\\section{Introduction}\nThe crabs are located at positions $p_i$ for $0 \\le i < n$.\nThe cost of fuel for a crab to move from position $x$ to position $y$ is\n\\begin{equation}\\label{eq:fuel-cost}\n  c(x, y) = \\sum_{j=0}^{|x-y|} j.\n\\end{equation}\nTo minimize the amount of fuel expended by the crabs, we must choose a position $y$\nsuch that the total cost for all crab movements,\n\\begin{equation}\n  t(y) = \\sum_{i=0}^{n-1} c(p_i, y),\n\\end{equation}\nis minimized.\n\nBy finding the antidifference of \\eqref{eq:fuel-cost}, we can see that the\nfuel cost is very close to the square of the distance moved:\n\\begin{equation}\n  c(x, y) = \\frac{|x - y|(|x - y| + 1)}{2}\n\\end{equation}\n\nThis is very close to the square of the distance.\nSo, it seems possible that, since the arithmetic mean minimizes\nthe sum of squared errors, it might minimize the sum\nof this fuel cost.\n\nIn fact, it does, and we will prove it. However, there's a hitch:\nthe mean may not be integral. In that case, it turns out that the\nposition of minimal cost will be one or both of the integers closest\nto the mean, on either side.\n\nOur proof consists of two steps:\n\\begin{enumerate}\n  \\item Prove that if a position is to the left of the mean, then\n  moving further left will increase the total cost.\n  \\item Prove that if a position is to the right of the mean, then\n  moving further right will increase the total cost.\n\\end{enumerate}\nIf we can prove these, then we can be sure that there are at most\ntwo points with minimum cost, and if there are two, they are adjacent.\nWe can also calculate the mean and know that either:\n\\begin{enumerate}\n  \\item It falls on an integer: Then the mean is the unique position\n        of minimum cost.\n  \\item It falls between integers: Then one or both of the positions\n        to the left or right of the mean has the minimum cost.\n\\end{enumerate}\nSo, finding the position with minimum cost would involve calculating\nthe mean, then testing the adjacent points to see which has a lower\ncost.\n\n\\section{Left of the mean}\n\nLet's first show that for any position to the left of the mean,\nmoving further left increases the cost. First, recall the formula\nfor the mean:\n%\n\\begin{equation}\\label{eq:mean}\n  m = \\frac{1}{n} \\sum_{i=0}^{n-1} p_i\n\\end{equation}\n\nNow choose an arbitrary position $y$ less than or equal to the mean $m$.\nWe want to show that the total cost is higher at $y-1$ than at $y$.\nTo do this, we will show that $t(y-1)-t(y) > 0$.\n\n\\begin{equation*}\n  \\begin{split}\n    t(y-1)-t(y) &= \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i - y, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i - y + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= -ny + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= -n(y-m+m) + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= -n(y-m) -nm + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= n(m-y) -nm + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= n(m-y) -\\sum_{i=0}^{n-1} p_i + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      p_i, & \\quad\\text{if}\\ p_i < y \\\\\n      p_i + 1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n    &= n(m-y) + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      0, & \\quad\\text{if}\\ p_i < y \\\\\n      1, & \\quad\\text{if}\\ p_i >= y \\\\\n    \\end{cases} \\\\\n  \\end{split}\n\\end{equation*}\n\nSince $y<=m$, and $n$ must be positive, the term $n(m-y)$ must be\nnon-negative. The summation term must be positive as long as there\nis at least one $i$ such that $p_i >= y$.\n\nTo show that there is at least one $p_i >= y$, recall that $y <= m$,\nso we only need to show that there is at least one $p_i >= m$.\nThen consider the definition of the mean \\eqref{eq:mean}. If all\nthe $p_i$ were less than $m$, then $\\sum_{i=0}^{n-1} p_i$ would be\nless than $nm$, so $m$ would be less than $m$, a contradiction.\nThus there must be at least one $p_i$ greater than or equal to $m$,\nand therefore greater than or equal to $y$.\n\nSince we have at least one $p_i >= y$, the last summation term\nin the calculation of $t(y-1) - t(y)$ must be positive, and since\nthe $n(m-y)$ term is non-negative, we have that $t(y-1) - t(y)$ is\npositive. Therefore, the total fuel cost at $t(y-1)$ is greater than\nthe total fuel cost at $t(y)$, when $y <= m$.\n\n\\section{Right of the mean}\n\nSecondly, we must prove that when $y >= m$, the total fuel cost\n$t(y+1)$ is greater than the total fuel cost $t(y)$. The steps\nare the same as the $y <= m$ case, but with some of the signs flipped:\n\n\\begin{equation*}\n  \\begin{split}\n    t(y+1)-t(y) &= \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      y - p_i, & \\quad\\text{if}\\ p_i > y \\\\\n      y - p_i + 1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n    &= ny + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      -p_i, & \\quad\\text{if}\\ p_i > y \\\\\n      -p_i + 1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n    &= n(y-m+m) + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      -p_i, & \\quad\\text{if}\\ p_i > y \\\\\n      -p_i + 1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n    &= n(y-m) +nm + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      -p_i, & \\quad\\text{if}\\ p_i > y \\\\\n      -p_i + 1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n    &= n(y-m) +\\sum_{i=0}^{n-1} p_i + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      -p_i, & \\quad\\text{if}\\ p_i > y \\\\\n      -p_i + 1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n    &= n(y-m) + \\sum_{i=0}^{n-1}\n    \\begin{cases}\n      0, & \\quad\\text{if}\\ p_i > y \\\\\n      1, & \\quad\\text{if}\\ p_i <= y \\\\\n    \\end{cases} \\\\\n  \\end{split}\n\\end{equation*}\n\nSince $y>=m$, and $n$ must be positive, the term $n(y-m)$ must be\nnon-negative. The summation term must be positive as long as there\nis at least one $i$ such that $p_i <= y$.\n\nTo show that there is at least one $p_i <= y$, recall that $y >= m$,\nso we only need to show that there is at least one $p_i <= m$.\nThen consider the definition of the mean \\eqref{eq:mean}. If all\nthe $p_i$ were greater than $m$, then $\\sum_{i=0}^{n-1} p_i$ would be\ngreater than $nm$, so $m$ would be greater than $m$, a contradiction.\nThus there must be at least one $p_i$ less than or equal to $m$,\nand therefore less than or equal to $y$.\n\nSince we have at least one $p_i <= y$, the last summation term\nin the calculation of $t(y+1) - t(y)$ must be positive, and since\nthe $n(y-m)$ term is non-negative, we have that $t(y+1) - t(y)$ is\npositive. Therefore, the total fuel cost at $t(y+1)$ is greater than\nthe total fuel cost at $t(y)$, when $y >= m$.\n\n\\section{Conclusions}\n\nThese two proofs lead us to the following conclusions:\n\\begin{enumerate}\n  \\item The position $\\lfloor m \\rfloor$, the greatest integer less\n        than or equal to the mean, must have the minimal cost of all\n        positions less than or equal to the mean.\n  \\item The position $\\lceil m \\rceil$, the least integer greater than\n        or equal to the mean, must have the minimal cost of all positions\n        greater than or equal to the mean.\n  \\item Either position $\\lfloor m \\rfloor$, $\\lceil m \\rceil$, or\n        both, must have minimal total fuel cost.\n  \\item If $m$ is integral, then that position has minimal total fuel\n        cost.\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "101d49adfed919d5dec9dd45df748f95c9f92d84", "size": 7577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "day07.tex", "max_stars_repo_name": "lylek/advent2021", "max_stars_repo_head_hexsha": "c8d569af4a617603453f045ba2ea647cc0fd2dd7", "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": "day07.tex", "max_issues_repo_name": "lylek/advent2021", "max_issues_repo_head_hexsha": "c8d569af4a617603453f045ba2ea647cc0fd2dd7", "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": "day07.tex", "max_forks_repo_name": "lylek/advent2021", "max_forks_repo_head_hexsha": "c8d569af4a617603453f045ba2ea647cc0fd2dd7", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1421568627, "max_line_length": 83, "alphanum_fraction": 0.6245215785, "num_tokens": 2562, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8962513821399044, "lm_q1q2_score": 0.7965512891343169}}
{"text": "\\section{Linear Support Vector Classifier}\n\nGiven $n$ training points, where each input $x_i$ has $m$ attributes, i.e., is of dimensionality $m$, and is in one of two classes $y_i=\\pm1$, i.e., our training data is of the form:\n\n\\begin{equation}\n\t\\{(x_i,y_i), x_i\\in\\Re^m, y_i=\\pm1, i=1, \\dots, n\\} \\label{eq:svc_data}\n\\end{equation}\n\nFor simplicity we first assume that data are (not fully) linearly separable in the input space $x$, meaning that we can draw a line separating the two classes when $m=2$, a plane for $m=3$ and, more in general, a hyperplane for an arbitrary $m$.\n\nSupport vectors are the examples closest to the separating hyperplane and the aim of support vector machines is to orientate this hyperplane in such a way as to be as far as possible from the closest members of both classes, i.e., we need to maximize this margin.\n\nThis hyperplane is represented by the equation $w^T x + b=0$. So, we need to find $w$ and $b$ so that our training data can be described by:\n\n\\begin{equation} \\label{eq:svc_consts}\n\t\\begin{aligned}\n\t\t& w^T x_i + b \\geq +1 - \\xi_i, \\forall y_i=+1 \\\\\n    \t& w^T x_i + b \\leq -1 + \\xi_i, \\forall y_i=-1 \\\\\n    \t& \\xi_i \\geq 0 \\ \\forall_i\n\t\\end{aligned}\n\\end{equation}\n\nwhere the positive slack variables $\\xi_i$ are introduced to allow misclassified points. In this way data points on the incorrect side of the margin boundary will have a penalty that increases with the distance from it.\n\nThese two equations can be combined into:\n\n\\begin{equation} \\label{eq:svc_const}\n\t\\begin{aligned}\n    \t& y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\\n    \t& \\xi_i\\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nThe margin is equal to $\\displaystyle \\frac{1}{\\| w \\|}$ and maximizing it subject to the constraint in~\\eqref{eq:svc_const} while as we are trying to reduce the number of misclassifications is equivalent to finding:\n\n\\begin{equation} \\label{eq:svc_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi} \\quad & \\| w \\| + C \\sum_{i=1}^n \\xi_i \\\\\n            \\text{subject to} \\quad & y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\ & \\xi_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nMinimizing $\\| w \\|$ is equivalent to minimizing $\\displaystyle \\frac{1}{2} \\| w \\|^2$, so we need to find:\n\n\\begin{equation} \\label{eq:quad_svc_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi} \\quad & \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\xi_i \\\\\n            \\text{subject to} \\quad & y_i (w^T x_i + b) \\geq 1 - \\xi_i \\ \\forall_i \\\\ & \\xi_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nwhere the parameter $C$ controls the trade-off between the slack variable penalty and the size of the margin.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.6]{img/linear_dual_svc_hyperplane}\n\t\\caption{Linear SVC hyperplane}\n\t\\label{fig:linear_dual_svc_hyperplane}\n\\end{figure}\n\n\\subsection{Hinge loss}\n\nThe \\emph{hinge} loss is defined as:\n\n\\begin{equation} \\label{eq:hinge_loss1}\n\t\\mathcal{L}_1 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ y (w^T x + b) \\geq 1 \\\\\n\t\t1 - y (w^T x + b) & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:hinge_loss2}\n\t\\mathcal{L}_1 = \\max(0, 1 - y (w^T x + b))\n\\end{equation}\n\nand it is a nondifferentiable convex function due to its nonsmoothness in 1, but has a subgradient wrt $w$ that is given by:\n\n\\begin{equation} \\label{eq:hinge_loss_der}\n    \\frac{\\partial \\mathcal{L}_1}{\\partial w}=\n        \\begin{cases}\n            -y x & \\text{if} \\ y (w^T x + b) < 1 \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nThe general primal unconstrained formulation takes the form:\n\n\\begin{equation} \\label{eq:primal_svc}\n    \\min_{w,b} \\mathcal{R}(w,b) + C \\sum_{i=1}^n \\mathcal{L}(w,b;x_i,y_i)\n\\end{equation}\n\nwhere $\\mathcal{R}(w, b)$ is the \\emph{regularization term} and $\\mathcal{L}(w,b;x_i,y_i)$ is the \\emph{loss function} associated with the observation $(x_i,y_i)$~\\cite{piccialli2018nonlinear}.\n\nThe quadratic optimization problem~\\eqref{eq:quad_svc_obj} can be equivalently formulated as:\n\n\\begin{equation} \\label{eq:svc_hinge}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))\n\\end{equation}\n\nwhere we make use of the \\emph{hinge} loss~\\eqref{eq:hinge_loss1} or~\\eqref{eq:hinge_loss2}.\n\nThe above formulation penalizes slacks $\\xi$ linearly and is called $\\mathcal{L}_1$-SVC.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/svc_hinge_loss}\n  \t\\caption{SVC Hinge loss with different optimization steps}\n  \t\\label{fig:svc_hinge_loss}\n\\end{figure}\n\nTo simplify the notation and so also the design of the algorithms, the simplest approach to learn the bias term $b$ is that of including that into the \\emph{regularization term}; so we can rewrite~\\eqref{eq:svc_hinge} and~\\eqref{eq:svc_squared_hinge} as follows:\n\n\\begin{equation} \\label{eq:primal_svc_hinge1}\n    \\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\mathcal{L}(w;x_i,y_i)\n\\end{equation}\n\nor, equivalently, by augmenting the weight vector $w$ with the bias term $b$ and each instance $x_i$ with an additional dimension, i.e., with constant value equal to 1:\n\n\\begin{equation} \\label{eq:primal_svc_hinge2}\n    \\begin{aligned}\n        \\min_{w} \\quad & \\frac{1}{2} \\| \\bar{w} \\|^2 + C \\sum_{i=1}^n \\mathcal{L}(w;\\bar{x}_i,y_i) \\\\\n            \\text{where} \\quad & \\bar{w}^T = [w^T, b] \\\\ & \\bar{x}_i^T = [x_i^T, 1]\n    \\end{aligned}\n\\end{equation}\n\nwith the advantages of having convex properties of the objective function useful for convergence analysis and the possibility to directly apply algorithms designed for models without the bias term.\n\nNotice that in terms of numerical optimization the formulations~\\eqref{eq:svc_hinge} and~\\eqref{eq:svc_squared_hinge} are not equivalent to~\\eqref{eq:primal_svc_hinge1} or~\\eqref{eq:primal_svc_hinge2} since in the first one the bias term $b$ does not contribute to the \\emph{regularization term}, so the SVM formulation is based on an unregularized bias term $b$, as highlighted by the \\emph{statistical learning theory}. But, in machine learning sense, numerical experiments in~\\cite{hsu2002simple} show that the accuracy does not vary much when the bias term $b$ is embedded into the weight vector $w$.\n\n\\subsubsection{Wolfe Dual formulation}\n\nTo reformulate the~\\eqref{eq:quad_svc_obj} as a \\emph{Wolfe dual}, we need to allocate the Lagrange multipliers $\\alpha_i\\geq 0, \\mu_i \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svc_wolfe_dual}\n    \\max_{\\alpha,\\mu} \\min_{w,b,\\xi} \\mathcal{W}(w,b,\\xi,\\alpha,\\mu) = \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\xi_i-\\sum_{i=1}^n \\alpha_i(y_i(w^T x_i + b)-1+\\xi_i)-\\sum_{i=1}^n\\mu_i\\xi_i\n\\end{equation}\n\nWe wish to find the $w$, $b$ and $\\xi_i$ which minimizes, and the $\\alpha$ and $\\mu$ which maximizes $\\mathcal{W}$, provided $\\alpha_i\\geq 0, \\mu_i \\geq 0 \\ \\forall_i$. We can do this by differentiating $\\mathcal{W}$ wrt $w$ and $b$ and setting the derivatives to 0:\n\n\\begin{equation} \\label{eq:svc_wolfe_der_w}\n\t\\frac{\\partial \\mathcal{W}}{\\partial w}=w-\\sum_{i=1}^n \\alpha_i y_i x_i \\Rightarrow w=\\sum_{i=1}^n \\alpha_i y_i x_i\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_wolfe_der_b}\n\t\\frac{\\partial \\mathcal{W}}{\\partial b}=-\\sum_{i=1}^n \\alpha_i y_i\\Rightarrow\\sum_{i=1}^n \\alpha_i y_i=0\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_wolfe_der_xi}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i}=0\\Rightarrow C=\\alpha_i+\\mu_i\n\\end{equation}\n\nSubstituting~\\eqref{eq:svc_wolfe_der_w} and~\\eqref{eq:svc_wolfe_der_b} into~\\eqref{eq:svc_wolfe_dual} together with $\\mu_i\\geq 0 \\ \\forall_i$, which implies that $\\alpha\\leq C$, gives a new formulation being dependent on $\\alpha$. We therefore need to find:\n\n\\begin{equation} \\label{eq:svc_max_wolfe_dual}\n\t\\begin{aligned}\n    \t\\max_{\\alpha} \\mathcal{W}(\\alpha) &= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\sum_{i,j}\\alpha_i\\alpha_j y_i y_j \\langle x_i, x_j \\rangle \\\\\n    \t&= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\sum_{i,j}\\alpha_i Q_{ij}\\alpha_j \\ \\text{where} \\ Q_{ij} = y_i y_j \\langle x_i, x_j \\rangle \\\\\n    \t&= \\sum_{i=1}^n \\alpha_i - \\frac{1}{2}\\alpha^T Q\\alpha \\ \\text{subject to} \\ 0\\leq\\alpha_i\\leq C \\ \\forall_i, \\sum_{i=1}^n \\alpha_i y_i=0 \n\t\\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:svc_min_wolfe_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T Q\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i \\\\ & y^T\\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nwhere $q^T = [1, \\dots, 1]$.\n\nBy solving~\\eqref{eq:svc_min_wolfe_dual} we will know $\\alpha$ and, from~\\eqref{eq:svc_wolfe_der_w}, we will get $w$, so we need to calculate $b.$\n\nWe know that any data point satisfying~\\eqref{eq:svc_wolfe_der_b} which is a support vector $x_s$ will have the form:\n\n\\begin{equation} \\label{eq:svc_sv_const1}\n\ty_s(w^T x_s + b)=1\n\\end{equation}\n\nand, by substituting in~\\eqref{eq:svc_wolfe_der_w}, we get:\n\n\\begin{equation} \\label{eq:svc_sv_const2}\n\ty_s\\big(\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle +b\\big)=1\n\\end{equation}\n\nwhere $s$ denotes the set of indices of the support vectors and is determined by finding the indices $i$ where $\\alpha_i>0$, i.e., nonzero Lagrange multipliers.\n\nMultiplying through by $y_s$ and then using $y_s^2=1$ from~\\eqref{eq:svc_consts}:\n\n\\begin{equation} \\label{eq:svc_sv_squared_const2}\n\ty_s^2\\big(\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle +b\\big)=y_s\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_b}\n\tb=y_s-\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle\n\\end{equation}\n\nInstead of using an arbitrary support vector $x_s$, it is better to take an average over all of the support vectors in $S$:\n\n\\begin{equation} \\label{eq:svc_b_avg}\n\tb=\\frac{1}{N_s}\\sum_{s\\in S} y_s-\\sum_{m\\in S}\\alpha_m y_m \\langle x_m, x_s \\rangle\n\\end{equation}\n\nWe now have the variables $w$ and $b$ that define our separating hyperplane's optimal orientation and hence our support vector machine. Each new point $x'$ is classified by evaluating:\n\n\\begin{equation} \\label{eq:svc_pred}\n    y'=\\operatorname{sgn}\\big(\\sum_{i=1}^n\\alpha_i y_i\\langle x_i, x' \\rangle+b\\big)\n\\end{equation}\n\nFrom~\\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. We report below the box-constrained dual formulation~\\cite{hsu2002simple} that arises from the primal~\\eqref{eq:primal_svc_hinge1} or~\\eqref{eq:primal_svc_hinge2} where the bias term $b$ is embedded into the weight vector $w$:\n\n\\begin{equation} \\label{eq:svc_min_bcqp_wolf_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Lagrangian Dual formulation}\n\nIn order to relax the constraints in the \\emph{Wolfe dual} formulation~\\eqref{eq:svc_min_wolfe_dual} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrangian multipliers $\\mu \\geq 0, \\lambda_+ \\geq 0$, $\\lambda_- \\geq 0$:\n\n\\begin{equation} \\label{eq:svc_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha - \\mu^T (y^T \\alpha) - \\lambda_+^T (u - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T Q\\alpha + (q - \\mu y + \\lambda_+ - \\lambda_-)^T \\alpha - \\lambda_+^T u\n\t\\end{aligned}\n\\end{equation}\n\nwhere the upper bound $u^T = [C, \\dots, C]$.\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow Q \\alpha + (q - \\mu y + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:svc_lagrangian_sol}\n    Q \\alpha = - (q - \\mu y + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradient wrt $\\mu$, $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-y \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - u\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\nIf the Hessian matrix Q is not positive definite, i.e., the Lagrangian function is not strictly convex since it will be linear along the eigenvectors correspondent to the null eigenvalues and so it will be unbounded below, the Lagrangian dual relaxation will be nondifferentiable, so it will have infinite solutions and for each of them it will have a different subgradient. In order to compute an approximation of the gradient, we will choose $\\alpha$ in such a way as the one that minimizes the norm of the residual:\n\n\\begin{equation} \\label{eq:svc_lagrangian_krylov_sol}\n\t\\begin{aligned}\n\t\t\t\\min_{\\alpha_n \\in K_n(Q, b)} \\quad & \\| Q \\alpha_n - b \\| \\\\ \n\t\t\t\\text{where} \\quad & b = - (q - \\mu y + \\lambda_+ - \\lambda_-)\n\t\\end{aligned}\n\\end{equation}\n\nSince we are dealing with a symmetric but indefinite linear system we will choose a well-known Krylov method that performs the Lanczos iterate, i.e., symmetric Arnoldi iterate, called \\emph{minres}, i.e., symmetric \\emph{gmres}, to compute the vector $\\alpha_n$ that minimizes the norm of the residual $r_n = Q \\alpha_n - b$ among all vectors in $K_n(Q, b) = span(b, Qb, Q^2b, \\dots, Q^{n-1}b)$.\n\n\\bigskip\n\nFrom~\\eqref{eq:svc_min_wolfe_dual} we can notice that the equality constraint $y^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:svc_lagrangian_dual} is reduced of 1/3 by removing the multipliers $\\mu$ which was allocated to control the equality constraint $y^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:svc_min_bcqp_wolf_dual}.\n\n\\begin{equation} \\label{eq:svc_bcqp_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha+q^T\\alpha - \\lambda_+^T (u - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + yy^T)\\alpha + (q + \\lambda_+ - \\lambda_-)^T \\alpha - \\lambda_+^T u\n\t\\end{aligned}\n\\end{equation}\n\nwhere, again, the upper bound $u^T = [C, \\dots, C]$.\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svc_bcqp_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + yy^T) \\alpha + (q + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:svc_bcqp_lagrangian_sol}\n    (Q + yy^T) \\alpha = - (q + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradient wrt $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svc_bcqp_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - u\n\\end{equation}\n\n\\begin{equation} \\label{eq:svc_bcqp_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\n\\subsection{Squared Hinge loss}\n\nThe \\emph{squared hinge} loss is defined as:\n\n\\begin{equation} \\label{eq:squared_hinge_loss1}\n\t\\mathcal{L}_2 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ y (w^T x + b) \\geq 1 \\\\\n\t\t(1 - y (w^T x + b))^2 & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:squared_hinge_loss2}\n\t\\mathcal{L}_2 = \\max(0, 1 - y (w^T x + b))^2\n\\end{equation}\n\nIt is a strictly convex function and its gradient wrt $w$ is given by:\n\n\\begin{equation} \\label{eq:squared_hinge_loss_der}\n    \\frac{\\partial \\mathcal{L}_2}{\\partial w}=\n        \\begin{cases}\n            - 2 y x & \\text{if} \\ y (w^T x + b) < 1 \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nSince smoothed versions of objective functions may be preferred for optimization, we can reformulate~\\eqref{eq:svc_hinge} as:\n\n\\begin{equation} \\label{eq:svc_squared_hinge}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, 1 - y_i (w^T x_i + b))^2\n\\end{equation}\n\nwhere we make use of the \\emph{squared hinge} loss that quadratically penalized slacks $\\xi$ and is called $\\mathcal{L}_2$-SVC.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/svc_squared_hinge_loss}\n  \t\\caption{SVC Squared Hinge loss with different optimization steps}\n  \t\\label{fig:svc_squared_hinge_loss}\n\\end{figure}\n", "meta": {"hexsha": "08d947d56f35743f93918347735d89369f466c9f", "size": 16855, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_stars_repo_name": "AF207/optiml", "max_stars_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-06T13:59:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T13:59:03.000Z", "max_issues_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_issues_repo_name": "AF207/optiml", "max_issues_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebooks/optimization/tex/linear_svc.tex", "max_forks_repo_name": "AF207/optiml", "max_forks_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_forks_repo_licenses": ["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.6129943503, "max_line_length": 604, "alphanum_fraction": 0.6968851973, "num_tokens": 5845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8962513828326955, "lm_q1q2_score": 0.796551287109277}}
{"text": "\\lab{Newton and Quasi-Newton Methods}{Newton and Quasi-Newton Methods}\n\n\\objective{Newton's method is the basis of several iterative methods for optimization.\nThough it converges quickly, it is often very computationally expensive.\nVariants on Newton's method, including BFGS, remedy the problem somewhat by numerically approximating Hessian matrices.\nIn this lab we implement Newton's method, BFGS, and the Gauss-Newton method for nonlinear least squares problems.}\n\n% Newton's method is generally useful because of its fast convergence properties.\n% However, Newton's method requires the explicit calculation of the second derivative (i.e., the Hessian matrix) at each step, which is computationally costly.\n% Quasi-Newton methods modify Newton's method so that the Hessian does not have to be computed at each step, thus making computations faster.\n% This generally comes at the cost of slower convergence speed, but the increased computation speed can make these methods more effective in many cases.\n\n\\section*{Newton's Method} % ==================================================\n\nFor $g:\\mathbb{R}\\rightarrow\\mathbb{R}$, Newton's method finds a root $\\bar{x}$ of the equation $g(x) = 0$ with the following rule.\n\\begin{equation}\nx_{k+1} = x_{k} - \\frac{g(x_k)}{g'(x_k)}\n\\label{eq:quasinewton-newton1d-root}\n\\end{equation}\nLet $f:\\mathbb{R}\\rightarrow\\mathbb{R}$.\nSubstituting $g = f'$ into \\eqref{eq:quasinewton-newton1d-root} yields an iterative method for locating a critical point $x^*$ of $f$ satisfying $f'(x^*) = 0$.\n\\begin{equation}\nx_{k+1} = x_{k} - \\frac{f'(x_k)}{f''(x_k)}\n\\label{eq:quasinewton-newton1d}\n\\end{equation}\n\nThis technique generalizes to higher dimensions.\nFor $g:\\mathbb{R}^n \\rightarrow \\mathbb{R}^n$, the following iterative technique finds $\\bar{\\x}$ such that $g(\\bar{\\x}) = \\0$.\n\\begin{equation}\n\\x_{k+1} = \\x_k - Dg(\\x_k)^{-1}g(\\x_k)\n\\label{eq:quasinewton-newtonroot-nd}\n\\end{equation}\nNow let $f:\\mathbb{R}^n\\rightarrow\\mathbb{R}$.\nTo calculate an optimal value $\\x^*$ of $f$ satisfying $Df(\\x^*) = \\0$, plug $g = Df$ into \\eqref{eq:quasinewton-newtonroot-nd} to get the following equation.\n\\begin{equation}\n\\x_{k+1} = \\x_k - D^2f(\\x_k)^{-1}Df(\\x_k)\\trp\n\\label{eq:quasinewton-newton-nd}\n\\end{equation}\nHere the first derivative $Df:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$ evaluates to the row vector $Df(\\x) = [D_{1}f(\\x)\\ \\ldots\\ D_{n}f(\\x)]$,\nand the second derivative $D^2f:\\mathbb{R}^n\\rightarrow\\mathbb{R}^{n\\times n}$ evaluates to the $n\\times n$ \\emph{Hessian} matrix\n\\[\nD^2f(\\x) =\n\\left[\\begin{array}{ccc}\nD_1 D_1 f(\\x) & \\ldots & D_n D_1 f(\\x) \\\\\nD_1 D_2 f(\\x) & \\ldots & D_n D_2 f(\\x) \\\\\n\\vdots        &        & \\vdots        \\\\\nD_1 D_n f(\\x) & \\ldots & D_n D_n f(\\x)\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc}\n\\frac{\\partial^2 f}{\\partial x_1 \\partial x_1} & \\cdots & \\frac{\\partial^2 f}{\\partial x_n \\partial x_1} \\\\\n\\vdots & \\ddots & \\vdots \\\\\n\\frac{\\partial^2 f}{\\partial x_1 \\partial x_n} & \\cdots & \\frac{\\partial^2 f}{\\partial x_n \\partial x_n}\n\\end{array}\\right].\n\\]\n\n\\begin{problem}\nWrite a function that accepts functions $Df:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$ and $D^2f:\\mathbb{R}^n\\rightarrow\\mathbb{R}^{n\\times n}$, a starting point $\\x_0 \\in \\mathbb{R}^n$,  a stopping tolerance \\li{tol} defaulting to $1e^{-5}$, and an integer \\li{maxiter} defaulting to $20$ .\nUse Newton's method in \\eqref{eq:quasinewton-newton-nd} to optimize $f$.\nReturn the final estimate $\\x_k$, whether or not the method converged (\\li{True} or \\li{False}), and the number of iterations computed.\n\nYour implementation should include the following items.\n\\begin{itemize}\n    \\item Iterate until either $\\|Df(\\x_{k})\\|_\\infty <$ \\li{tol} or $k >$ \\li{maxiter}.\n    The criteria $\\|\\x_{k} - \\x_{k-1}\\| <$ \\li{tol} is also common, but making sure $Df$ is near zero works better in many circumstances.\n    \\item Instead of inverting $D^2 f(\\x_k)$ at each step, solve the equation $D^2 f(\\x_k)\\z_k = D f(\\x_k)\\trp$ and compute $\\x_{k+1} = \\x_k - \\z_k$.\n    In other words, use \\li{la.solve()} instead of \\li{la.inv()}.\n    \\item Avoid recomputing values by only computing $Df(\\x_k)$ and $D^2f(\\x_k)$ once for each $k$.\n\\end{itemize}\n%\nThe \\emph{Rosenbrock function} is a common test function for optimization methods.\n\\[\nf(x,y) = 100(y - x^2)^2 + (1 - x)^2\n\\]\nThe minimizer is $\\x^* = (1,1)$ with minimum value $f(1,1) = 0$.\nTest your function by minimizing the Rosenbrock function using an initial guess $\\x_0 = (-2,2)$.\nThe function and its derivatives are implemented as \\li{rosen()}, \\li{rosen_der()}, and \\li{rosen_hess()} in \\li{scipy.optimize}.\nCompare your results to \\li{scipy.optimize.fmin_bfgs()}.\n\\begin{lstlisting}\n>>> from scipy import optimize as opt\n\n>>> f = opt.rosen                   # The Rosenbrock function.\n>>> df = opt.rosen_der              # The first derivative.\n>>> d2f = opt.rosen_hess            # The second derivative (Hessian).\n>>> opt.fmin_bfgs(f=f, x0=[-2,2], fprime=df, maxiter=50)\n<<Optimization terminated successfully.\n         Current function value: 0.000000\n         Iterations: 35\n         Function evaluations: 42\n         Gradient evaluations: 42\narray([ 1.00000021,  1.00000045])>>\n\\end{lstlisting}\n\\label{prob:quasinewton-newton}\n\\end{problem}\n\n\\begin{comment} % NONE OF THIS MAKES SENSE WITH THIS LAB.\n    % We aren't talking about f:R->R and what is alpha?\n\\begin{info}\nRemember, Newton's method has quadratic convergence if:\n\\begin{enumerate}\n\\item $f: \\mathbb{R} \\rightarrow \\mathbb{R}$ is $C^2$ in an open neighborhood $ I = (x_* - r, x_* + r)$ with $r \\geq |x_* - x_0|$\n\\item $Df(x_k) \\neq 0$ for $x_k$ in the iteration\n\\item $x_0$ is sufficiently close to $\\alpha$ that the Taylor series approximation is accurate enough to ignore higher order terms. Additional conditions of closeness can be found in Volume 2 text.\n\\end{enumerate}\n\\end{info}\n\\end{comment}\n\n\\section*{BFGS} % =============================================================\n\nNewton's method enjoys quadratic convergence when the initial guess is good enough.\nHowever, computing and inverting the Hessian matrix at each step of \\eqref{eq:quasinewton-newton-nd} is often prohibitively expensive.\nThe idea behind \\emph{quasi-Newton methods} is to numerically approximate the inverse of the Hessian at each step.\nThese methods sacrifice some convergence properties in exchange for becoming less computationally expensive.\nThey also make it possible to optimize functions where $D^2f$ is unknown.\n\n\\emph{Broyden's method} is a high-dimensional generalization of the secant method.\nJust as the secant method approximates the second derivative of $f$ in \\eqref{eq:quasinewton-newton1d} by using the first derivative at nearby points, Broyden's method uses the first derivative to update an approximated Hessian matrix.\n\\begin{equation}\n\\x_{k+1} = \\x_k - A_{k}^{-1}Df(\\x_k)\\trp,\n\\qquad\nA_{k+1} = A_k + \\frac{\\y_k-A_k\\mathbf{s}_k}{\\|\\mathbf{s}_k\\|^2}\\mathbf{s}_k\\trp,\n\\label{eq:quasinewton-broyden}\n\\end{equation}\nwhere $\\mathbf{s}_k = \\x_{k+1} - \\x_{k}$ and $\\y_k = Df(\\x_{k+1})\\trp - Df(\\x_{k})\\trp$.\n\n\\begin{comment} % We don't need this much detail on Broyden.\nTo get an overview of how this method works, consider the quadratic Taylor series approximation used to construct Newton's method for a function:\n\n\\begin{equation}\ng_k(\\x) = f(\\x_k) + Df(\\x_k)(\\x - \\x_k) + \\frac{1}{2}(\\x - \\x_k)\\trp A_k(\\x - \\x_k)\n\\end{equation}\n\n\\noindent By assuming that the Jacobian is the same at $\\x$ and $\\x_k$, this equation can be rearranged to\n\n\\begin{equation} \\label{Eq:BroydenRestraint}\nDf(\\x_{k+1})-Df(\\x_k)=(\\x_{k+1}-\\x_k)\\trp A_{k+1}.\n\\end{equation}\n\nThough there are many possible matrices $A_{k+1}$ that can satisfy this equation, if an estimate of the Hessian $A_k$ at the point $\\x_k$ is given, the best rank one approximation of $A_{k+1}$ (meaning that $A_{k+1} -  A_{k}$ is rank one) can be found to minimize $\\|A_{k+1}-A_k\\|$.\nIf $\\y_k = Df(\\x_{k+1})\\trp -Df(\\x_k)\\trp $ and $\\mathbf{s}_k=\\x_{k+1}-\\x_k$,  then $\\y_k = A_{k+1}\\trp \\mathbf{s}_k$.\nWith this notation, $\\|A_{k+1}-A_k\\|$ can be shown to be uniquely minimized by the following:\n\n\\begin{equation} \\label{Eq:BroydenHessian}\nA_{k+1} = A_k + \\frac{\\y_k-A_k\\mathbf{s}_k}{\\|\\mathbf{s}_k\\|^2}\\mathbf{s}_k\\trp .\n\\end{equation}\n\nThis Hessian approximation can then be used in Newton's method as a replacement for the real Hessian as follows:\n\\begin{equation} \\label{eq:quasinewton-broyden}\n\\x_{k+1} = \\x_k - A_{k}^{-1}Df(\\x_k)\\trp\n\\end{equation}\n\\end{comment}\n\nThough this method no longer explicitly calculates the Hessian $D^{2}f(\\x_k)$, it still involves a matrix inversion.\nThe \\emph{Sherman-Morrison-Woodbury} formula translates the update rule for $A_k$ in \\eqref{eq:quasinewton-broyden} into the following update rule for $A_k^{-1}$.\n\\[\nA_{k+1}^{-1} = A_{k}^{-1} + \\frac{\\mathbf{s}_k - A_{k}^{-1}\\y_k}{\\mathbf{s}_k\\trp  A_{k}^{-1}\\y_k} (\\mathbf{s}_k\\trp  A_{k}^{-1})\n\\]\n\nUnfortunately, even if $D^2f(\\x_k)$ is positive definite (which is desirable for minimization), the first-order approximation $A_k$ is not guaranteed to be positive definite, so Broyden's method is unreliable.\nThe \\emph{Broyden-Fletcher-Goldfarb-Shanno} (BFGS) method remedies this problem by using the following positive definite second-order approximation for the Hessian.\n\\[\nA_{k+1} = A_k + \\frac{\\y_k\\y_k\\trp }{\\y_k\\trp \\mathbf{s}_k}-\\frac{A_k\\mathbf{s}_k\\mathbf{s}_k\\trp A_k}{\\mathbf{s}_k\\trp A_k\\mathbf{s}_k}\n\\]\nThe Sherman-Morrison-Woodbury formula can also be applied in this situation to yield a computationally efficient form of BFGS.\n\\begin{align}\n\\x_{k+1} &= \\x_k - A_{k}^{-1}Df(\\x_k)\\trp\n\\label{eq:quasinewton-bfgs-iteration}\n\\\\\nA_{k+1}^{-1} &= A_k^{-1} + \\frac{(\\mathbf{s}_k\\trp \\y_k + \\y_k\\trp A_k^{-1}\\y_k)\\mathbf{s}_k\\mathbf{s}_k\\trp }{(\\mathbf{s}_k\\trp \\y_k)^2} - \\frac{A_k^{-1}\\y_k\\mathbf{s}_k\\trp  + \\mathbf{s}_k\\y_k\\trp A_k^{-1}}{\\mathbf{s}_k\\trp \\y_k}\n\\label{eq:quasinewton-bfgs-hessian}\n\\end{align}\nHere $\\mathbf{s}_k = \\x_{k+1} - \\x_{k}$ and $\\y_k = Df(\\x_{k+1})\\trp - Df(\\x_{k})\\trp$ as before.\n\n\\begin{problem} % Implement BFGS.\nWrite a function that accepts a function $Df:\\mathbb{R}^n\\rightarrow\\mathbb{R}^n$, a starting point $\\x_0 \\in \\mathbb{R}^n$, a stopping tolerance \\li{tol} defaulting to $1e^{-5}$, and an integer \\li{maxiter} defaulting to $80$.\nUse BFGS as given in \\eqref{eq:quasinewton-bfgs-iteration} and \\eqref{eq:quasinewton-bfgs-hessian} to optimize $f$, with $A_0^{-1} = I$ (the $n\\times n$ identity matrix) as the initial approximation to the inverse of the Hessian.\nReturn the final estimate $\\x_k$, whether or not the method converged, and the number of iterations computed.\n\nThis method is a little tricky and can have issues if $\\x_0$ is chosen poorly.\nConsider the following as you implement your function.\n\\begin{itemize}\n    \\item Use the same stopping criteria as in Problem \\ref{prob:quasinewton-newton}, iterating until either $\\|Df(\\x_{k})\\|_\\infty <$ \\li{tol} or $k >$ \\li{maxiter}.\n    The usual criteria $\\|\\x_{k} - \\x_{k-1}\\| <$ \\li{tol} is \\textbf{not} a good choice for BFGS.\n    \\item Avoid recomputing values by only calculating each $Df(\\x_k)$, $\\mathbf{s}_k$, $\\y_k$, and $\\mathbf{s}_k\\trp\\y_k$ once.\n    \\item Note that $\\mathbf{s}_k\\mathbf{s}_k\\trp$, $\\y_k\\mathbf{s}_k\\trp$, and $\\mathbf{s}_k\\y_k\\trp$ are all \\emph{outer products} that result in $n\\times n$ matrices.\n    Use \\li{np.outer()} instead of \\li{np.dot()} or the \\li{@} operator for these computations.\n    Carefully identify which parts of \\eqref{eq:quasinewton-bfgs-hessian} are scalars and which parts are matrices.\n    \\item If $(\\mathbf{s}_k\\trp\\y_k)^2 = 0$, terminate the iteration early to avoid dividing by zero.\n\\end{itemize}\nTest your function on the Rosenbrock function as in Problem \\ref{prob:quasinewton-newton}.\n\n% % OLD TEST FUNCTIONS.\n% Test this method on the following function:\n% \\[\n% f(x,y) = e^{x-1}+e^{1-y}+(x-y)^2\n% \\]\n% using starting point $(2,3)$, maximum iterations $1000$, and tolerance $10^{-2}$.\n% Your results can be tested with the following:\n% \\begin{lstlisting}\n% >>> import scipy.optimize as opt\n% >>> f = lambda x : np.exp(x[0]-1) + np.exp(1 - x[1]) + (x[0] - x[1])**2\n% >>> df = lambda x : np.array([np.exp(x[0]-1) + 2*(x[0]-x[1]), -1*np.exp(1-x[1]) - 2*(x[0]-x[1])])\n% >>> minx = opt.fmin_bfgs(f=f,fprime=df,x0=[2,3],gtol=10**-2,maxiter=1000)\n% \\end{lstlisting}\n\\label{prob:quasinewton-bfgs}\n\\end{problem}\n\n\\begin{info}\nThe formula in \\eqref{eq:quasinewton-bfgs-hessian} is not the only way to approximate the inverse Hessian.\nFor example, the \\emph{Davidon-Fletcher-Powell} (DFP) method uses the following updating scheme.\n\\[\nA_{k+1}^{-1} = A_k^{-1} +\n\\frac{\\mathbf{s}_k\\mathbf{s}_k\\trp}{\\mathbf{s}_k\\trp \\y_k}\n- \\frac{A_k^{-1}\\y_k\\y_k\\trp A_k^{-1}}{\\y_k\\trp A_k^{-1}\\y_k}\n\\]\nThis approximation works well for many problems, but BFGS is considered to be the superior method in general.\n\\end{info}\n\n\\begin{problem} % Compare Newton, BFGS, and SciPy.\nWrite a function that accepts an integer $N$ and performs the following $N$ times.\n\\begin{enumerate}\n\\item Sample a random initial guess $\\x_0$ from the 2-D uniform distribution over $[-3,3]\\times[-3,3]$.\n\\\\(Hint: Use \\li{np.random.uniform()} or \\li{np.random.random()}.)\n\\item Time (separately) your implementation of Newton's method from Problem \\ref{prob:quasinewton-newton}, your BFGS routine from Problem \\ref{prob:quasinewton-bfgs}, and \\li{scipy.optimize.bfgs_fmin()} for minimizing the Rosenbrock function with an initial guess of $\\x_0$.\n\\item Record the number of iterations from each method.\nFor \\li{scipy.optimize.fmin_bfgs()}, set \\li{disp=False} to suppress printing the convergence message and \\li{retall=True} to get the list of $\\x_k$ at each iteration (to count the number of iterations).\n\\end{enumerate}\n\nPlot the computation times versus the number of iterations with a log-log scale, using different colors for each method.\nFor $N = 100$, your plot should resemble the following figure.\nNote that Newton's method consistently converges much faster than BFGS.\nIn addition, SciPy's BFGS algorithm will likely converge faster than your BFGS implementation because it employs a line search to choose an intelligent step size at each iteration.\n% % OLD test functions.\n% \\begin{align*}\n% f(x,y) &= 0.26(x^2+y^2) - 0.48xy\\\\\n% g(x,y) &= \\sin(x+y) + (x-y)^2 - 1.5x + 2.5y + 1\n% \\end{align*}\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\textwidth]{figures/newton_comparison.pdf}\n\\end{figure}\n\\end{problem}\n\n\\section*{The Gauss-Newton Method} % ==========================================\n\n\\subsection*{Non-linear Least Squares Problems}\n\nLeast Squares problems aim to fit a line (or model parameters) to a given set of data points.\nThese problems arise in many scientific fields, including economics, physics, and statistics and represent unconstrained optimization problems that minimize an objective function of the form\n$$\nf(\\x) = \\frac{1}{2}\\displaystyle\\sum_{j=1}^m r_j^2(\\x),\n$$\nwhere each $r_i : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ is smooth and $m \\geq n$.\nThis case of least squares problems can be solved with a Newton-like method.\n\nSpecifically, with data points $(t_1, y_1), (t_2, y_2), \\ldots, (t_m, y_m)$, where $t_i,y_i \\in \\mathbb{R}$ for $i = 1, \\ldots, m$.\nLet $\\phi(\\x, \\mathbf{t)}$ be a possible model for this data set, where $\\x$ is a vector of parameters of the model, and $\\mathbf{t} \\in \\mathbb{R}^n$.\nThe error at the $i$-th data point, called the \\emph{residual}, is the value $$r_i(\\x) := \\phi(x_i, t_i) - y_i.$$\nSumming the squares of these errors gives the following non-linear least squares objective function.\n$$\nf(\\x) = \\frac{1}{2} \\displaystyle \\sum_{j=1}^m  r_j^2(\\x).\n$$\nThe first and second derivatives of this function can then be expressed as\n\\begin{align*}\nDf(\\x) &= J(\\x)\\trp  r(\\x), \\\\\nD^2 f(\\x) &= J(\\x)\\trp J(\\x) + \\displaystyle \\sum_{j=1}^m r_j(\\x) D^2r_j(\\x).\n\\end{align*}\nwith $\\mathbf{r}(\\x) = [r_1(\\x), r_2(\\x), \\ldots, r_m(\\x)]\\trp $ and\n\\[\nJ(\\x) =\n\\left[\\begin{array}{c}\n\\arrayrulecolor{lightgray}\nD r_1(\\x) \\\\\\hline D r_2(\\x) \\\\\\hline \\vdots \\\\\\hline D r_m(\\x)\n\\end{array}\\right] \\in \\mathbb{R}^{m\\times n}.\n\\]\n\nThe second term in the formula for $D^2 f$ involves second derivatives and can be problematic to compute.\nIn practice, the second term in the formula for $D^2 f$ is small, either because the residuals themselves are small, or because they are nearly affine in a neighborhood of the solution.\nThe simplest method for solving the nonlinear least squares problem, known as the \\emph{Gauss-Newton Method}, exploits this observation, simply ignoring the second term and making the approximation\n$$\nD^2 f(\\x) \\approx J(\\x)\\trp J(\\x).\n$$\nThe method then proceeds in a manner similar to Newton's method.\nThus, at each iteration, we find $\\x_{k+1}$ as follows:\n\\begin{equation} \\label{Eq:GaussNewtonUpdate}\n\\x_{k+1} = \\x_k-(J(\\x_k)\\trp J(\\x_k))^{-1}J( \\x_k)\\trp  \\mathbf{r}( \\x_k).\n\\end{equation}\n\nAs an example, suppose we have data points generated from the function $y = 3\\sin(x/2)$ and slightly perturbed by Gaussian noise.\nTo fit the data to a model $\\phi(\\x, t_i) = \\phi(x_0, x_1, t_i) = x_0 \\sin(x_1 t_i)$, we must select values for $\\x = [x_0, x_1]\\trp$ (since we know how the data was generated, we expect to find that $x_0 \\approx 3$ and $x_1 \\approx 1/2$).\nBegin by writing functions for the proposed model, the residual vector, and the Jacobian of the residuals.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from matplotlib import pyplot as plt\n\n# Generate random data for t = 0, 1, ..., 10.\n>>> T = np.arange(10)\n>>> y = 3*np.sin(0.5*T)+ 0.5*np.random.randn(10)    # Perturbed data.\n\n# Define the model function and the residual (based on the data).\n>>> model = lambda x, t: x[0]*np.sin(x[1]*t)        # phi(x,t)\n>>> residual = lambda x: model(x, T) - y            # r(x) = phi(x,t) - y\n\n# Define the Jacobian of the residual function, computed by hand.\n>>> jac = lambda x: np.column_stack((np.sin(x[1]*t), x[0]*t*np.cos(x[1]*t)))\n\\end{lstlisting}\n\nBy inspecting the data, an initial guess for the parameters could be $x_0 = (2.5, 0.6)$.\nA function implementing Gauss Newton can then be used to find the least squares solution.\n\n\\begin{lstlisting}\n>>> x0 = np.array([2.5,.6])\n>>> x, conv, niters = gauss_newton(jac, residual, x0, tol=1e-3, maxiter=10)\n\n# Plot the fitted model with the observed data and the data-generating curve.\n>>> dom = np.linspace(0, 10, 200)\n>>> plt.plot(T, y, '*')                         # Observed data.\n>>> plt.plot(dom, 3*np.sin(.5*dom), '--')       # Data-generating curve.\n>>> plt.plot(dom, model(x, dom))                # Fitted model.\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{problem} % Gauss Newton for nonlinear least squares.\nWrite a function that accepts a function for the proposed model $\\phi(\\x)$, the model derivative $D\\phi(\\x)$, a function that returns the residual vector $r(\\x)$, a callable function that returns the Jacobian of the residual $Dr(\\x) = J(\\x)$, a starting point $\\x_0$, a stopping tolerance \\li{tol} defaulting to $1e^{-5}$, and a max number of iterations \\li{maxiter} defaulting to $10$.\nThis method should implement the Gauss-Newton Method and return a list containing: the minimizing x value, the number of iterations performed, and if the method converged as a boolean.\n\nTest your function by using the Jacobian function, residual function, and starting point given in the example above.\nCompare your results to \\li{scipy.optimize.leastsq()}.\n\\begin{lstlisting}\n>>> minx = opt.leastsq(func=residual, x0=np.array([2.5,.6]), Dfun=jac)\n\\end{lstlisting}\n\\end{problem}\n\n% Non-linear least squares problems can be used to analyze trends in data or to predict future events and are ubiquitous in many academic fields as well as in industrial applications and machine learning.\n\n\\begin{problem}\nThe file \\texttt{population.npy} contains census data from the United States every ten years since 1790 for 16 decades.\nThe first column ($\\mathbf{t}$) gives the number of decades since 1790 in the decade ($0,1,\\ldots$) and the second column ($\\y$) gives the population count in millions of people.\n\nBy plotting the data, and with a little knowledge about population growth, it is reasonable to hypothesize an \\emph{exponential model} for the population:\n\\[\n\\phi(x_1,x_2,x_3,t) = x_1\\exp(x_2(t+x_3)).\n\\]\nUse the initial guess $(1.5, .4, 2.5)$ for the parameters $(x_1, x_2, x_3)$ and your Gauss Newton function or \\li{scipy.optimize.leastsq()} to fit this model.\nPlot the resulting curve along with the actual data points.\n\nUnfortunately, the exponential model isn't a very good fit for the data because the population grows exponentially for only the first 8 or so decades.\\footnote{Fitting an exponential model to only the first 8 data points results in a good model for those points (but not for later data).}\nInstead, consider the following \\emph{logistic model}.\n$$\n\\phi(x_1,x_2,x_3,t) = \\frac{x_1}{1+\\exp(-x_2(t+x_3))}.\n$$\nA reasonable initial guess for the parameters $(x_1, x_2, x_3)$ is $(150, .4, -15)$.\nWrite functions for the model and the corresponding residual vector, then fit the model.\nPlot the data against the fitted curve (in the same plot as before).\nIt should be a much better fit than the exponential curve.\n\\end{problem}\n\n\\begin{comment}\n\n%%% OLD GAUSS NEWTON\nThe individual functions $r_i$ that measure the error between the model and the data point are known as \\emph{residuals},\nand we can aggregate these functions into a \\emph{residual vector}\n$$\n\\mathbf{r}(\\x) := (r_1(\\x), r_2(\\x), \\ldots, r_m(\\x))\\trp .\n$$\nThe Jacobian of $\\mathbf{r}(\\x)$ can be expressed in terms of the gradients of each $r_i$ as follows:\n%% TODO: put this back in!\n$$\nJ(\\x) = \\begin{bmatrix} D r_1(\\x)\\trp  \\\\ D r_2(\\x)\\trp  \\\\ \\vdots \\\\ D r_m(\\x)\\trp  \\end{bmatrix}\n$$\nYou can further verify that\n\\begin{align*}\nD f(\\x) &= J(\\x)\\trp  r(\\x), \\\\\nD^2 f(\\x) &= J(\\x)\\trp J(\\x) + \\displaystyle \\sum_{j=1}^m r_j(\\x) D^2r_j(\\x).\n\\end{align*}\n\nIn particular, at the $k$-th iteration, we choose a search direction $p_k$ that solves the linear system\n$$\nJ_k\\trp J_kp_k = -J_k\\trp r_k.\n$$\n\nFor convenience, we summarize these steps in Algorithm \\ref{alg:guassnewton}.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Gauss-Newton}{}\n    \\State \\textrm{Choose initial parameter vector } $x_0$\n    \\State $k \\gets 0$\n    \\While{$J_k\\trp r_k \\neq 0$}\n        \\State \\textrm{solve } $J_k\\trp J_kp_k = -J_k\\trp r_k$\n        \\State \\textrm{choose step size } $\\alpha_k$ \\textrm{ satisfying Wolfe Conditions.}\n        \\State $x_{k+1} \\gets x_k + \\alpha_kp_k$\n        \\State $k \\gets k+1$\n    \\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Gauss-Newton Method}\n\\label{alg:guassnewton}\n\\end{algorithm}\n\nNow we write Python functions for our model, the residual vector, the Jacobian, the objective function,\nand the gradient. The calculations for all of these are straight forward.\n\\begin{lstlisting}\n>>> def model(x, t):\n>>>     return x[0]*np.sin(x[1]*t)\n>>> def residual(x):\n>>>     return model(x, t) - y\n>>> def jac(x):\n>>>     ans = np.empty((10,2))\n>>>     ans[:,0] = np.sin(x[1]*t)\n>>>     ans[:,1] = x[0]*t*np.cos(x[1]*t)\n>>>     return ans\n>>> def objective(x):\n>>>     return .5*(residual(x)**2).sum()\n>>> def grad(x):\n>>>     return jac(x).T.dot(residual(x))\n\\end{lstlisting}\nBy inspecting our data, we might make an initial guess for the parameters $x_0 = (2.5, 0.6)$.\nWe are now ready to use our \\li{gaussNewton} function to find the least squares solution.\n\\begin{lstlisting}\n>>> x0 = np.array([2.5,.6])\n>>> x = gaussNewton(jac, residual, x0, niter=10)\n\\end{lstlisting}\nWe can plot everything together to compare our fitted model with the data and the original sine\ncurve from which the data were generated.\n\\begin{lstlisting}\ndom = np.linspace(0,10,100)\nplt.plot(t, y, '*')\nplt.plot(dom, 3*np.sin(.5*dom), '--')\nplt.plot(dom, x[0]*np.sin(x[1]*dom))\nplt.show()\n\\end{lstlisting}\n\n\nThe module \\li{scipy.optimize} also has a method to solve non-linear least squares problem, and it is quite convenient.\nThe function is called \\li{leastsq()}, and in its most basic use, you only need\nto pass in the residual function and starting point as arguments.\nIn the example above, we simply need to execute the following code:\n\\begin{lstlisting}\n>>> from scipy.optimize import leastsq\n>>> x2 = leastsq(residual, x0)[0]\n\\end{lstlisting}\nThis should give us the same answer, but much faster.\n\n%% TODO: put this back in!\nThus, your new model is\n$$\n\\phi(x_1,x_2,x_3,t) = \\frac{x_1}{1+\\exp(-x_2(t+x_3))}.\n$$\nBy inspection, find a reasonable\ninitial guess for the parameters $(x_1, x_2, x_3)$ (i.e. $(150, .4, -15)$).\nAgain, write Python functions for the model and the corresponding residual vector,\nand fit the model. Plot the data against the fitted curve. It should be a good fit.\n\\end{comment}\n", "meta": {"hexsha": "749e69e65f0e9313c8e3279eff52a4764b1acb7a", "size": 24718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/QuasiNewtonMethods/QuasiNewtonMethods.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/QuasiNewtonMethods/QuasiNewtonMethods.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/QuasiNewtonMethods/QuasiNewtonMethods.tex", "max_forks_repo_name": "DM561/dm561.github.io", "max_forks_repo_head_hexsha": "216e8f41007f4f4fbd174c529f543b20bb477702", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.3252747253, "max_line_length": 386, "alphanum_fraction": 0.6949591391, "num_tokens": 7998, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.9149009526726544, "lm_q1q2_score": 0.7965102610457895}}
{"text": "%\n% Chapter 5.4\n%\n\n\\section*{5.4 Work}\n\nThe \\textbf{force} \\(F\\) on an object (in the same direction) is given by Newton's Second Law of Motion as the product of its mass \\(m\\) and its acceleration \\(a\\):\n\\[ \\text{force = mass} \\times \\text{acceleration} \\quad \\Leftrightarrow \\quad F = ma = m \\frac{d^2s}{dt^2} \\]\nFor the case of constant acceleration, the force \\(F\\) is also constant and the work done is defined to be the product of the force \\(F\\) and the distance \\(d\\) that the object moves:\n\\[ \\text{work = force} \\times \\text{distance} \\quad \\Leftrightarrow \\quad W = Fd \\]\n\n\\subsubsection*{Work Done Moving an Object from \\(A\\) to \\(B\\)}\n\n\\[ W = \\lim_{n \\to \\infty} \\sum_{i=1}^n f(x_1^*) \\Delta x = \\int_a^b f(x)dx \\]\n\n\\subsubsection*{Hooke's Law}\n\nThe force required to maintain a spring stretched \\(x\\) units beyond its natural length is proportional to \\(x\\):\n\\[f(x)=kx\\]\nwhere \\(k\\) is a positive constant called the \\textbf{spring constant}. Hooke's law holds as long as \\(x\\) is not too large.\n", "meta": {"hexsha": "bc198d076045bbbb49029ef368aa7dd6858e4405", "size": 1010, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/5-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/5-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/5-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": 48.0952380952, "max_line_length": 183, "alphanum_fraction": 0.6792079208, "num_tokens": 314, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8354835289107307, "lm_q1q2_score": 0.7964455944805349}}
{"text": "\n\\subsection{Hamilton Equations}\n\n\\noindent\\textbf{Legendre transformation}\n\n\\noindent Single variables\n\n% \\begin{definition}\n    The Legendre transformation of the convex function $f(x)$ is another function $g(p)$ defined as \n    $g(p)=\\max_{x}F(p,x)$, where $F(p,x)=px-f(x)$.\n% \\end{definition}\n\nThe function $F(p,x)$ gets the maximum with respect to $x$ only when $\\partial F/\\partial x =0$ \nwhich means $p = f'(x)$. So, the transformation of the function $x$ is \n\\begin{equation}\n        g(p) = px-f(x),\\ p=f'(x)\n\\end{equation}\n\nThe variable $x$ and $p$ are dual variables. The functions $f$ and $g$ are the Legendre transformation mutually and \nthe function $g(p)$ is also a convex function.\n\n\\noindent Multi-variables\n\nFor the multi-variable function $f(\\mathbf{x}):\\mathbf{x}\\in \\mathbb{R}^{n}\\rightarrow \\mathbb{R}$, \nits Legendre transformation is defined as \n\\begin{equation}\n        g(\\mathbf{p}) = \\mathbf{p}^{T}\\mathbf{x}-f(\\mathbf{x}),\\ \\mathbf{p}=f'(\\mathbf{x})\n\\end{equation}\n\n\\noindent \\textbf{Hamiltonian}\nThe Legendre transformation of the Lagrangian $L(\\mathbf{q},\\dot{\\mathbf{q}},t)$ is  \n\\begin{equation}\n    H(\\mathbf{p},\\mathbf{q},t)=\\mathbf{p}^{T}\\dot{\\mathbf{q}}-L(\\mathbf{q},\\dot{\\mathbf{q}},t),\\ \\mathbf{p}=\\frac{\\partial L}{\\partial \\dot{\\mathbf{q}}}\n\\end{equation}\n\n$H(\\mathbf{p},\\mathbf{q},t)$ is the so-called Hamiltonian. \nThe Lagrange equation is equivalent to the following Hamilton equations \n\\begin{equation}\n    \\begin{aligned}\n        &\\dot{\\mathbf{p}} = -\\frac{\\partial H}{\\partial \\mathbf{q}} \\\\\n        &\\dot{\\mathbf{q}} = \\frac{\\partial H}{\\partial \\mathbf{q}}\n    \\end{aligned}\n\\end{equation}\n\nProof:\n% \\begin{proof}\n    The total differential of $H$ is \n    $$dH = \\frac{\\partial H}{\\partial \\mathbf{p}}d\\mathbf{p} + \\frac{\\partial H}{\\partial \\mathbf{q}}d\\mathbf{q} + \\frac{\\partial H}{\\partial t}dt.$$\n    The total differential of $\\mathbf{p}^{T}\\dot{\\mathbf{q}}-L(\\mathbf{q},\\dot{\\mathbf{q}},t)$ is \n    $$dH = \\dot{\\mathbf{p}}^{T}d\\mathbf{p} - \\frac{\\partial L}{\\partial \\mathbf{q}}d\\mathbf{q} - \\frac{\\partial L}{\\partial t}dt$$\n    The two equations are equivalent, so \n\\begin{equation}\n    \\dot{\\mathbf{q}}=\\frac{\\partial H}{\\partial \\mathbf{p}},\\ \\frac{\\partial H}{\\partial \\mathbf{q}}=-\\frac{\\partial L}{\\partial \\mathbf{q}},\\ \\frac{\\partial H}{\\partial t}=-\\frac{\\partial H}{\\partial t}.\n\\end{equation}\n    Combining with the Lagrange equation and $\\mathbf{p}=\\frac{\\partial L}{\\partial \\dot{\\mathbf{q}}}$, one can obtain the Hamilton equations.\n% \\end{proof}\n\nThe Euler's homogeneous function theorem for quadric form $f(\\mathbf{x})$ is \n\\begin{equation}\n    \\mathbf{x}^{T}\\frac{\\partial f}{\\partial \\mathbf{x}}=2f\n\\end{equation}\n\nAssuming the kinematic energy $T$ is a quadric form with respect to $\\dot{\\mathbf{q}}$, one can obtain \n\\begin{equation}\n    H(\\mathbf{p},\\mathbf{q},t)=\\mathbf{p}^{T}\\dot{\\mathbf{q}}-L(\\mathbf{q},\\dot{\\mathbf{q}},t)=\\mathbf{p}^{T}\\dot{\\mathbf{q}}-T+U=\\dot{\\mathbf{q}}^{T}\\frac{\\partial T}{\\partial \\dot{\\mathbf{q}}}-T+U=T+U.\n\\end{equation}\nTherefore, the Hamiltonian is the total energy.\n", "meta": {"hexsha": "d71a053f557b1ce2c96d468608a3ca8ba5d9dc0e", "size": 3076, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ClassicalMechanic/hamiltonian.tex", "max_stars_repo_name": "wangkuner/mechanics", "max_stars_repo_head_hexsha": "58a0cb36bbf3dc4333860be666fcfe18f8aada14", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ClassicalMechanic/hamiltonian.tex", "max_issues_repo_name": "wangkuner/mechanics", "max_issues_repo_head_hexsha": "58a0cb36bbf3dc4333860be666fcfe18f8aada14", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ClassicalMechanic/hamiltonian.tex", "max_forks_repo_name": "wangkuner/mechanics", "max_forks_repo_head_hexsha": "58a0cb36bbf3dc4333860be666fcfe18f8aada14", "max_forks_repo_licenses": ["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.2352941176, "max_line_length": 204, "alphanum_fraction": 0.6612483745, "num_tokens": 1082, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521252, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.796441420663279}}
{"text": "\\section{Task 01a}\nIn this exercise I will solve the one dimensional Poisson equation with Dirichlet boundary conditions by rewriting it as a set of linear equations. \n\n\\begin{equation}\n\t-u''(x) = f(x),  x\\in (0,1), u(0)=u(1)=0\n\\end{equation}\n\nWe can approximate the second order derivative of u with:\n\n\\begin{equation*}\n   -\\frac{v_{i+1}+v_{i-1}-2v_i}{h^2} = f_i  \\hspace{0.5cm} \\mathrm{for} \\hspace{0.1cm} i=1,\\dots, n,\n\\end{equation*}\n\nThis can be written as a set of linear equations almost directly:\n\n\\begin{equation*}\n   -v_{i-1}+2v_i-v_{i+1} = f_i h^2  \\hspace{0.5cm} \\mathrm{for} \\hspace{0.1cm} i=1,\\dots, n,\n\\end{equation*}\n\n\\begin{equation*}\n   -v_{0}+2v_1-v_{2} = f_1 h^2\\\\\n\\end{equation*}\n\\begin{equation*}\n   -v_{1}+2v_2-v_{3} = f_2 h^2\\\\\n\\end{equation*}\n\\begin{equation*}\n   -v_{2}+2v_3-v_{4} = f_3 h^2\\\\\n\\end{equation*}\n\\begin{equation*}\n   -v_{n-2}+2v_{n-1}-v_{n} = f_{n-1} h^2\\\\\n\\end{equation*}\n\\begin{equation*}\n   -v_{n-1}+2v_n-v_{n+1} = f_n h^2\\\\\n\\end{equation*}\n\n$v_0$ and $v_{n+1}$ are 0, so the linear equations reduce to the following matrix form:\n\\[\n\\begin{bmatrix}\n       2& -1& 0 &\\dots   & \\dots &0 \\\\\n       -1 & 2 & -1 &0 &\\dots &\\dots \\\\\n       0&-1 &2 & -1 & 0 & \\dots \\\\\n       & \\dots   & \\dots &\\dots   &\\dots & \\dots \\\\\n       0&\\dots   &  &-1 &2& -1 \\\\\n       0&\\dots    &  & 0  &-1 & 2 \\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n\tv_1 \\\\\n\tv_2 \\\\\n\tv_3 \\\\\n\t\\vdots \\\\\n\tv_{n-1} \\\\\n\tv_n \\\\                      \n\\end{bmatrix} = \nh^2\n\\begin{bmatrix}\n\tf_1 \\\\\n\tf_2 \\\\\n\tf_3 \\\\\n\t\\vdots \\\\\n\tf_{n-1} \\\\\n\tf_n \\\\                      \n\\end{bmatrix}\n\\]\n\nThis is the same form of \n\\begin{equation*}\n   \\mathbf{A}\\mathbf{v} = \\tilde{\\mathbf{b}},\n\\end{equation*}\n\n\\section{Task 01b}\nIn this exercise I want to find a general algorithm for solving this set of equations with different values for the matrix elements by using decomposition and forward substitution and backward substitution. Let the tridiagonal matrix have elements $a_i$, $b_i$ and $c_i$\\\\\n\nFor clarity replace $'\\tilde{b}'$ with $'d'$\n\\begin{equation*}\n   a_{i-1} v_{i-1} + b_i v_i + c_i v_{i+1} = d_i  \\hspace{0.5cm} \\mathrm{for} \\hspace{0.1cm} i=1,\\dots, n,\n\\end{equation*}\n\nwhere\n$v_0 = v_{n+1} = a_0 = a_{n} = c_n = 0$\\\\\n\n\\begin{gather*}\n   b_1 v_1 + c_1 v_{2} = d_1\\\\\n   a_{1} v_{1} + b_2 v_2 + c_2 v_{3} = d_2\\\\\n   a_{2} v_{2} + b_3 v_3 + c_3 v_{4} = d_3\\\\\n   \\vdots\\\\\n   a_{n-2} v_{n-2} + b_{n-1} v_{n-1} + c_{n-1} v_{n} = d_{n-1}\\\\\n   a_{n-1} v_{n-1}+b_{n} v_{n} = d_{n}\\\\\n\\end{gather*}\n\nMethodology: Reduce the tridiagonal matrix to an upper diagonal matrix by decomposition, forwards substitution and backward substitution.\nModifying equation 2 with equation 1 to eliminate $v_1$\\\\\nEquation 2 * b1 - equation 1 *a1: \\\\\n\n\\[\n\\begin{bmatrix}\n     b_1 & c_1     & 0     & \\dots    & \\dots   & \\dots    & \\| & d_1 \\\\\n     a_1 & b_2     & c_2   & \\dots    & \\dots   & \\dots    & \\| & d_2 \\\\\n         & a_2     & b_3   & c_3      & \\dots   & \\dots    & \\| & d_3 \\\\\n         & \\dots   & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &         &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &         &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\nEquation 1 times $a_1$ and equation 2 times $b_1$\\\\\n\\[\n\\begin{bmatrix}\n     a_1 b_1 & a_1 c_1     & 0     & \\dots    & \\dots   & \\dots    & \\| & a_1 d_1 \\\\\n     b_1 a_1 & b_1 b_2     & b_1 c_2   & \\dots    & \\dots   & \\dots    & \\| & b_1 d_2 \\\\\n         & a_2     & b_3   & c_3      & \\dots   & \\dots    & \\| & d_3 \\\\\n         & \\dots   & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &         &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &         &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\nEquation 2 - equation 1\\\\\n\\[\n\\begin{bmatrix}\n     b_1 & c_1                   & 0     & \\dots    & \\dots   & \\dots    & \\| & d_1 \\\\\n     0   & b_1 b_2 - a_1 c_1     & b_1 c_2   & \\dots    & \\dots   & \\dots    & \\| & b_1 d_2 - a_1 d_1 \\\\\n         & a_2                   & b_3   & c_3      & \\dots   & \\dots    & \\| & d_3 \\\\\n         & \\dots                 & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &                       &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &                       &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\n$\\tilde{b_2} = b_1 b_2 - a_1 c_1$ \\\\\n$\\tilde{c_2} = b_1 c_2$ \\\\\n$\\tilde{d_2} = b_1 d_2 - a_1 d_1$ \\\\\n\n\\[\n\\begin{bmatrix}\n     b_1 & c_1                   & 0     & \\dots    & \\dots   & \\dots    & \\| & d_1 \\\\\n     0   & \\tilde{b_2} & \\tilde{c_2}   & \\dots    & \\dots   & \\dots    & \\| & \\tilde{d_2} \\\\\n         & a_2                   & b_3   & c_3      & \\dots   & \\dots    & \\| & d_3 \\\\\n         & \\dots                 & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &                       &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &                       &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\nEquation 2 times $a_2$ and equation 3 times $\\tilde{b_2}$\\\\\n\n\\[\n\\begin{bmatrix}\n     b_1 & c_1                   & 0     & \\dots    & \\dots   & \\dots    & \\| & d_1 \\\\\n     0   & a_2 \\tilde{b_2}       & a_2 \\tilde{c_2}   & \\dots    & \\dots   & \\dots    & \\| & a_2 \\tilde{d_2} \\\\\n         & \\tilde{b_2} a_2       & \\tilde{b_2} b_3   & \\tilde{b_2} c_3      & \\dots   & \\dots    & \\| & \\tilde{b_2} d_3 \\\\\n         & \\dots                 & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &                       &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &                       &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\nEquation 3 -equation 2: \\\\\n\n\\[\n\\begin{bmatrix}\n     b_1 & c_1                   & 0     & \\dots    & \\dots   & \\dots    & \\| & d_1 \\\\\n     0   & a_2 \\tilde{b_2} & a_2 \\tilde{c_2}   & \\dots    & \\dots   & \\dots    & \\| & a_2 \\tilde{d_2} \\\\\n         & 0                   & \\tilde{b_2} b_3 - a_2 \\tilde{c_2}  & \\tilde{b_2} c_3      & \\dots   & \\dots    & \\| & \\tilde{b_2} d_3 - a_2 \\tilde{d_2}\\\\\n         & \\dots                 & \\dots & \\dots    & \\dots   & \\dots    & \\| & \\dots \\\\\n         &                       &       & a_{n-2}  & b_{n-1} & c_{n-1}  & \\| & d_{n-1} \\\\\n         &                       &       &          & a_{n-1} & b_n      & \\| & d_n \\\\\n\\end{bmatrix}  \n\\]\n\n$\\tilde{b_3} = \\tilde{b_2} b_3 - a_2 \\tilde{c_2}$ \\\\\n$\\tilde{c_3} = \\tilde{b_2} c_3$ \\\\\n$\\tilde{d_3} = \\tilde{b_2} d_3 - a_2 \\tilde{d_2}$ \\\\\n\nBy examining the procedure, the modified coefficients notated with tildes may be defined recursively:\\\\\n\n\\begin{gather*}\n\t\\tilde{a_i} = 0 \\\\\n\t\\tilde{b_1} = b_1 \\\\\n\t\\tilde{b_i} = b_i \\tilde{b_{i-1}} - a_{i-1} \\tilde{c_{i-1}} \\\\\n\t\\tilde{c_1} = c_1 \\\\\n\t\\tilde{c_i} = \\tilde{b_{i-1}} c_i \\\\\n\t\\tilde{d_1} = d_1  \\\\\n\t\\tilde{d_i} = \\tilde{b_{i-1}} d_i - a_{i-1} \\tilde{d_{i-1}} \\\\\n\\end{gather*}\n\nTo further hasten the solution process, $\\tilde{d_i}$ may be divided out if there is no division by zero risk. The newer modified coefficients each notated with a hat will be:\\\\\n\n\\begin{gather*}\n\t\\hat{a_i} = 0 \\\\\n\t\\hat{b_i} = 1 \\\\\n\t\\hat{c_1} = \\frac{c_1}{b_1} \\\\\n\t\\hat{c_i} = \\frac{c_i}{b_i - a_{i-1} \\hat{c_{i-1}}} \\\\\n\t\\hat{d_1} = \\frac{d_1}{b_1}  \\\\\n\t\\hat{d_i} = \\frac{ d_i - a_{i-1} \\hat{d_{i-1}}}{b_i - a_{i-1} \\hat{c_{i-1}}} \\\\\n\\end{gather*}\n\nThis gives the following system with the same unknowns and coefficients defined in terms of the original ones above: \\\\\n\n$v_i + \\hat{c_i} v_{i+1} = \\hat{d_i}$\n\n$v_n = \\hat{d_n}$\n\nThe last equation involves only one unknown. Solving it in turn reduces the next last equation to one unknown. This backward substitution can be used to find all of the unknowns: \\\\\n$v_n = \\hat{d_n}$  \\\\\n$v_i + \\hat{c_i} v_{i+1} = \\hat{d_i}$ for $i = n-1, n-2, \\ldots, 1$ \\\\\n\nFloating point operations: \\\\\n\nFor calculating $\\hat{c_i}$ we need $3(n-2)+1$ flops. \\\\\nFor calculating $\\hat{d_i}$ we need $5(n-1)+1$ flops. \\\\\nFor back substitution we need $2(n-1)+1$ flops. \\\\\n\nHowever the denominator is the same for both $\\hat{c_i}$ and $\\hat{d_i}$. Thus the calculation of the denominator only has to be carried out once. Therefore we can subtract 2(n-2) flops from the total number of flops.\n\n\nIn total to solve the problem we need $7(n-1)+3(n-2)-2(n-2)+3 = 8(n-1)+2$ flops. \\\\\n\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.32\\textwidth]{task1b_n10.png}\n\\includegraphics[width=0.32\\textwidth]{task1b_n100.png}\n\\includegraphics[width=0.32\\textwidth]{task1b_n1000.png}\n\\caption{Solving the Poisson equation numerically and exact with grid size n =10,100,1000}\n\\label{fig:Poisson}\n\\end{figure}\n\\FloatBarrier\n\nFrom figure~\\ref{fig:Poisson} I can see that the numerical solution approaches the exact solution for more grid points. \\\\\n\n\n\\section{Task 01c}\n\nAssuming identical matrix elements along the diagonal and identical  but different values for the non-diagonal elements. This means that the $a_i =c_i =-1$ and $b_i =2$. Substituting this result into the solution we found in project 1b we get:\n\\begin{gather*}\n\t\\hat{a_i} = 0 \\\\\n\t\\hat{b_i} = 1 \\\\\n\t\\hat{c_1} = -0.5 \\\\\n\t\\hat{c_i} = \\frac{-1}{2 + \\hat{c_{i-1}}} \\\\\n\t\\hat{d_1} = \\frac{d_1}{2}  \\\\\n\t\\hat{d_i} = \\frac{d_i + \\hat{d_{i-1}}}{2 + \\hat{c_{i-1}}} \\\\\n\\end{gather*}\n\n\nFloating point operations specific: \\\\\n\nFor calculating $\\hat{c_i}$ we need $2(n-2)$ flops. \\\\\nFor calculating $\\hat{d_i}$ we need $3(n-1)+1$ flops. \\\\\nBack substitution does not change so it's the same is in 1b, we need $2(n-1)+1$ flops. \\\\\n\nThe denominator is the same for both $\\hat{c_i}$ and $\\hat{d_i}$. Thus the calculation of the denominator only has to be carried out once. Therefore we can subtract (n-2) flops from the total number of flops.\n\n\nIn total to solve the specific problem we need $5(n-1)+2(n-2)-(n-2)+2 = 6(n-1)+1$ flops. \\\\\n\nRunning the program to check for CPU time for both the general and the specific case I got very similar results the first time. General case gave  a time of: 7.62825565887. The specific case gave a time of\n7.512299363. This is probably because pure Python code has more overhead than compiled languages like C++ or Fortran, minimizing the importance of flops. Therefore I tried to import numba, which compiles the code just in time. This resulted in a time for the general case of; 0.515605151976 seconds, and for the specific case:\n0.309811743968 seconds. Comparing the flops to the running times, I get for Flops: $(9(n-1)+2)/(6(n-1)+1) \\approx 1.5$ and for running times: $0.515605151976/0.309811743968 \\approx 1.65$\\\\\n\n\n\\section{Task 01d}\nIn this exercise I want to check for truncation errors in the calculations.\\\\\n\nHere I made a function that extracts the maximum relative error for each step length. The results of the calculations are shown in figure~\\ref{fig:Error_poisson}.\\\\\n\n\\FloatBarrier\n\\begin{figure}[!ht]\n\\centering\n\\FloatBarrier\n\\includegraphics[width=0.45\\textwidth]{error.png}\n\n\\caption{Computing the relative error of the numerical solution to the Poisson equation for grid sizes n =10, 100, 1000, 10000, 100000, 1000000, 10000000}\n\\label{fig:Error_poisson}\n\\end{figure}\n\\FloatBarrier\n\nIn the figure~\\ref{fig:Error_poisson} I can see that the error declines until h reaches about $10^{-5}$. Decreasing the step size beyond this value results in increased truncation errors.\\\\\n\n\n\\section{Task 01e}\nFlops of LU decomposition goes like $O(n^2)$ when trying to solve the set of linear equations.\n\nTrying to run the LU decomposition for a matrix of size $10^{10}$ does not work because I have too little memory space.\n\n\\FloatBarrier\n\\begin{table}[!ht]\n\\centering\n\\begin{tabular}{|c|c|c|c|}\n\\hline \nn & tridiagonal specific & tridiagonal & LU \\\\ \n\\hline \n10 & 0.000204 & 0.000177 & 0.002522 \\\\ \n\\hline \n100 & 0.000212 & 0.000199 & 0.002558 \\\\ \n\\hline \n1000 & 0.000478 & 0.000557 & 0.299024 \\\\ \n\\hline \n2000 & 0.000293 & 0.000516 & 1.664050 \\\\\n\\hline \n\n\\label{Runtimes for various methods of decomposition}\n\\end{tabular} \n\\caption{Runtimes in seconds for various methods of decomposition}\n\\end{table}\n\\FloatBarrier\n\nFor tridiagonal specific flops goes like $O(6n)$. For tridiagonal flops goes like $O(9n)$. LU decomposition flops goes like $O(n^2)$. From the runtimes I can see in \\ref{Runtimes for various methods of decomposition} that the two first grows linearly within errors, while the LU decomposition grows quadratically.\\\\\n\n\n\\section{Comments}\nIn general the exercise was useful, but I realize that I could have written the report better. I have just gotten started with github, so I attached the program code, like I have done in projects I have done in the past. I hand in the exercise a bit late, because I was abroad until recently after agreement with Morten. It would be great to get some feedback on some of the report outlines, and maybe a tip on where or how I could implement further tests in my program. ", "meta": {"hexsha": "5b56bf03a346785263b5740332b0406e33722e4d", "size": 12911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project_1/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_1/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_1/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": 41.249201278, "max_line_length": 471, "alphanum_fraction": 0.5750910077, "num_tokens": 4840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8872045929715078, "lm_q1q2_score": 0.7964393838182592}}
{"text": "\\subsection{The Power Method}\n\nAccording to Golub \\cite{golub00}, quoting Householder, the power\nmethod has its origin at the work of Müntz in 1913\n\\cite{muntz1913}. The method is the simplest algorithm for solving the\neigenproblem; it basically consists in picking carefully a vector,\nand then apply the matrix $A$ iteratively until it converges to an\neigenvector. And not to any eigenvector, but precisely to the one with\nlargest eigenvalue (in absolute value). The following pseudocode is\ntaken from Golub \\cite{golub13}: \n\n\\begin{algorithm}\n  \\label{alg:power-method}\n  \\caption{The Power Method}\n%\n  \\setstretch{1.5}\n  \\SetKwInOut{Input}{Input}\n  \\SetKwInOut{Output}{Output}\n  \\DontPrintSemicolon\n%\n    \\Input{A unit vector $\\vec{q_0} \\in \\R{n}$ and a symmetric matrix $A^{n\n        \\times n}$}\n%\n    \\Output{The tuple $(\\lambda_k,\\vec{q_k})$ which is expected to\n      approximate an eigenpair $(\\lambda,\\vec{q})$ of $A$}\n%\n    \\For {$i = 1,2,\\dots,k$}\n    {\n      $\\vec{z_k} \\gets A \\vec{q_{k-1}}$ \\;\n      $\\vec{q_k} \\gets \\dfrac{\\vec{z_k}}{\\norm{\\vec{z_k}}_2}$ \\;\n      $\\lambda_k \\gets \\trans{\\vec{q_k}} A \\vec{q_k}$ \\;\n    }\n%\n    return $(\\lambda_k, \\vec{q_k})$ \\;\n\\end{algorithm}\n\\hfill\n\nOne immediate trick that is detected, is that we are not giving a\nprecise value for $k$, the number of iterations; this is because we do\nnot really know how many in advance, though we know how ``fast'' we\ncan reach convergence, more about this in a minute. Though the\nalgorithm looks trivial, a powerful theorem justifies why it\nworks. Golub mentions the  conditions which are required for its\nconvergence: the \nmaximum eigenvalue of $A$ must be unique (no repetition), and the \ninitial vector $q_0$ is not ``deficient''  (its component on the\ndirection of the eigenvector with maximum value must not be zero). A\nproof of convergence/correctness can be consulted in \\cite{golub13}. \\\\\\\n\nGolub also mentions the computable error bounds of this method.\nThe real eigenvalue and eigenvectors of $A$ will satisfy the equation\nbelow: \n\n\\[\nA \\vec{q} = \\lambda \\vec{q}\n\\]\n\\hfill\n\nBut accepting the fact that a computer will not product exactly the\neigenvalue nor the eigenvector, we can at least see how close we are\nin meeting above condition. That is, we can calculate the error $\\delta$: \n\n\\[\n\\norm{A \\vec{q_k} - \\lambda_k \\vec{q_k}}_2 = \\delta\n\\]\n\\hfill\n\nGolub shows that there is an eigenvalue $\\lambda$ that satisfies\n$\\abs{\\lambda_k - \\lambda} \\le \\sqrt{2}\\delta$; which is a way to tell\nthat we can really approximate an actual eigenvalue, as long as we are\ncapable of reproducing its defining property with good accuracy (which\nin turn, will depend on how many iterations we make). \\\\\n\nAlright, so we know how to calculate one eigenpair; why not\ncalculating them all? We may be tempted now to recall the geometric\nproof of SVD (see \\cref{cha:svd-theory}), and consider the following\nprocedure for finding all the eigenpairs (assuming preconditions met):\n\n\\begin{enumerate}\n\\item Pick carefully initial vector. \n\\item Apply \\cref{alg:power-method} to find the first\n  eigenpair. \n\\item Obtain the hyperplane that is orthogonal to the first\n  eigenvector found, and repeat recursively the procedure until\n  we have all the desired eigenpairs\\footnote{The third step is\n    usually called ``deflation'' (see \\cite{golub13}), when mentioned\n    in the context of the matrix, as it is reduced to dimensions $(n-1)\n    \\times (n-1)$.}.\n\\end{enumerate}\n\\hfill\n\nThe problem with this procedure, also exposed by Golub in his proof of\ncorrectness, is that the rate of convergence depends on\n$\\abs{\\frac{\\lambda_2}{\\lambda_1}}^k$; where $\\lambda_2$ is the second\nlargest eigenvalue in absolute value. Thus, unless there is a\nconsiderable gap between first and second largest eigenvalues of $A$,\nthe Power Method will converge quite slowly. That makes it unsuitable\nfor practical purposes, at least in the standalone version we just\npresented. Further sections will show how it can evolve to overcome\nthis limitation. \n", "meta": {"hexsha": "3fe3ef89a159ff1c45bbcb08c65e613d281e2cda", "size": 4009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-lanczos-serial-power.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-power.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-power.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": 39.6930693069, "max_line_length": 75, "alphanum_fraction": 0.7383387378, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094304, "lm_q2_score": 0.9184802496038499, "lm_q1q2_score": 0.7963552305455759}}
{"text": "\\chapter*{Part One: Matrix Factorization}\n\\addcontentsline{toc}{chapter}{Part One}\n\nNote: I collaborated with Vivienne Zhang and Justin Yao.\n\nThe first part to code was the latent semantic analysis word representations. Latent semantic analysis uses singular value decomposition to represent words in a lower dimensional space than the number of documents in the corpus. In my case, I found that using the principle components matrix $\\bm{U}$ alone provided significantly better results than weighting it with the diagonal matrix $\\bm{\\Sigma}$.\n\n\\begin{python}\n    def learn_reps_lsa(matrix, rep_size):\n    U, sigma, V = np.linalg.svd(matrix, full_matrices=True)\n    return result = U[:, :rep_size]\n\\end{python}\n\nThe next piece of code is the term frequency-inverse document frequency (TF-IDF), which re-weights word counts in the term-document matrix to prevent frequent words from dominating the word representation. It penalizes ubiquitous words while allowing sparser data to appear in the representation.\n\n\\begin{python}\n    def transform_tfidf(matrix):\n\n    nwords, ndocs = matrix.shape\n    vidf = np.vectorize(idf_helper)\n    idfs = np.zeros(nwords)\n    for i, _ in enumerate(idfs):\n    idfs[i] = idf_helper(matrix[i,:], ndocs)\n    tfidf = np.multiply(matrix, idfs[:, np.newaxis])\n    return tfidf\n\n    def idf_helper(row, ndocs):\n    df = np.count_nonzero(row)\n    idf = np.log(ndocs/df)\n    return idf\n\\end{python}\n\nThe final code is the LSA featurizer, which projects word contexts into the LSA lower dimensional representation.\n\n\\begin{python}\n    def lsa_featurizer(xs):\n    lsa = reps_tfidf\n    feats = xs @ lsa\n    # normalize\n    return feats / np.sqrt((feats ** 2).sum(axis=1, keepdims=True))\n\\end{python}\n\n\\subsection*{Theoretical Problem A}\nThe singular value decomposition of a matrix $\\bm{M}$ is given by\n\n\\begin{equation*}\n    \\bm{M} = \\bm{U \\Sigma V}\n\\end{equation*}\n\nGiven the word co-occurence matrix $\\bm{W_{tt}} = \\bm{W_{td}W_{td}^T}$ we can solve as follows by applying the SVD to the matrix and its transpose:\n\n\\begin{align*}\n    \\bm{MM^T} & = \\bm{U \\Sigma V^T} \\cdot \\bm{V \\Sigma U^T} \\\\\n              & = \\bm{U \\Sigma^2 U^T}\n\\end{align*}\n\nThe final result is itself a singular decomposition, where the left singular matrix of $\\bm{W_{tt}}$ is equal to the left singular matrix of the original term-document matrix $\\bm{W_{td}}$.\nIf $\\bm{U}$ is negative, then $\\bm{U \\Sigma^2 U^T}$ is positive, resulting in flipped signs compared to the original, therefore the left singular matrices are equivalent to each other's absolute values. This behavior is observed in my implementation of learn\\_reps\\_lsa, which simply truncates $\\bm{U}$ along its second axis to achieve a lower dimensional word representation. This implies that word co-occurence relations can be incorporated while using $\\bm{U}$ for my representation.\n\n\\subsection*{Experimental Problem B}\n\nThe nearest neighbors in representation space appear better for some words than others. For instance, their is a clear connection between dog and all of its top related words. Words associated with \"the\" are seemingly random; given that \"the\" is a filler word, associations are likely largely meaningless.\n\nFor this data set, using a smaller representation size and therefore a denser approximation of the term-document matrix appears to give slightly more meaningful associations. My LSA performance results match this assertion.\n\n\\begin{center}\n\n    \\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|p{3cm}|  }\n\n        \\hline\n        \\multicolumn{4}{|c|}{Word Similarities r = 100}                 \\\\\n        \\hline\n        the             & dog            & 3           & good           \\\\\n        \\hline\n        lid 1.753       & foods 0.571    & per 0.884   & pretty 1.255   \\\\\n        leaked 1.779    & pets 0.624     & 1 0.943     & bread 1.349    \\\\\n        filter 1.779    & switched 0.742 & 2 0.992     & prepare 1.376  \\\\\n        rest 1.786      & pet 0.794      & 4 1.061     & flaxseed 1.407 \\\\\n        flavoring 1.789 & cheap 0.831    & ounce 1.100 & beat 1.457     \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\n\n\\begin{center}\n    \\begin{tabular}{ |p{3cm}|p{3cm}|p{4cm}|p{3cm}|  }\n        \\hline\n        \\multicolumn{4}{|c|}{Word Similarities r = 500}                     \\\\\n        \\hline\n        the           & dog            & 3                 & good           \\\\\n        \\hline\n        suspect 1.953 & happier 1.670  & omega 1.733       & gerber 1.873   \\\\\n        flowers 1.961 & earlier 1.681  & vendor 1.739      & luck 1.885     \\\\\n        leaked 1.966  & eats 1.702     & supermarket 1.747 & crazy 1.890    \\\\\n        m 1.966       & stays 1.722    & nutty 1.755       & flaxseed 1.907 \\\\\n        burn 1.967    & standard 1.727 & carries 1.797     & suspect 1.907  \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\n\n\\subsection*{Experimental Problem C}\n\nLearned representations clearly help with the downstream classification task. Figure \\ref{fig:fig} shows a parameter sweep of my three featurizers across representation size and training size. For the word featurizer, once the training size is sufficient it mostly platueaus, with a slight dip in the middle.\nLSA featurizer performance drastically improves with a larger training size and a smaller representation space. The maximum values I obtained for each featurizer are as follows: LSA max: 0.812 Word max: 0.784 Combo max: 0.818.\n\n\\begin{figure}[ht]\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        % include first image\n        \\includegraphics[width=.8\\linewidth]{resources/png/word_perf.png}\n        \\caption{Word Featurizer}\n        \\label{fig:sub-first}\n    \\end{subfigure}\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        % include second image\n        \\includegraphics[width=.8\\linewidth]{resources/png/lsa_perf.png}\n        \\caption{LSA Featurizer}\n        \\label{fig:sub-second}\n    \\end{subfigure}\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        % include second image\n        \\includegraphics[width=.8\\linewidth]{resources/png/combo_perf.png}\n        \\caption{Combo Featurizer}\n        \\label{fig:sub-third}\n    \\end{subfigure}\n    \\caption{Featurizer Training and Representation size feature sweep}\n    \\label{fig:fig}\n\\end{figure}\n\n\\chapter*{Part Two: Language Modeling}\n\\addcontentsline{toc}{chapter}{Part Two}\n\nThis section of the assignment involved implementing a Word2Vec model. My model uses CrossEntropy as its loss function for training, as we are training the model to predict binary labels for positive or negative reviews. CrossEntropy increases loss as a prediction is a further distance from the actual label, making it suited for teaching a model to label a review as good or bad.\n\nFor my model itself, I used the standard PyTorch embedding module to represent words. In my forward function, I sum the embedding of all context words for the CBOW model, put the embeddings through a linear layer, and then a log softmax.\n\nI've observed some variance in my training. Somewhere a random number isn't seeded, so the finaly accuracy varies between different trainings in the range of ~.8 to .825.\n\n\\subsection*{Experimental Problem A}\n\nThe nearest neighbor space for Word2Vec is entirely unintuitive to me. The associated words for good seem reasonable, but every other example word seems somewhat random (particularly dog and barbecue). However Word2Vec appears to be my strongest featurizer, so perhaps the model is learning relationships that are not evident to me? In a production system I would worry it is cheating somehow and discovering idiosyncrasies hidden in my training set.\n\n\\begin{center}\n    \\begin{tabular}{ |p{3cm}|p{3cm}|p{4cm}|p{3cm}|  }\n        \\hline\n        \\multicolumn{4}{|c|}{Word2Vec Word Similarities context  = 2}    \\\\\n        \\hline\n        the         & dog             & 3                 & good         \\\\\n        \\hline\n        lots 1.668  & companies 1.686 & sip 1.701         & nice 1.660   \\\\\n        fish 1.752  & double 1.707    & gingerbread 1.734 & sauces 1.697 \\\\\n        betty 1.771 & barbeque 1.713  & pets 1.7434       & pure 1.698   \\\\\n        alive 1.774 & times 1.717     & send 1.750        & great 1.704  \\\\\n        my 1.775    & leak 1.726      & bears 1.752       & photo 1.732  \\\\\n        \\hline\n    \\end{tabular}\n\\end{center}\n\\subsection*{Experimental Problem B}\nWord2Vec is consistently about 2\\% more accurate than any of my other featurizers. The gains in performance over LSA are likely due to the fact that Word2Vec models context and has information about word ordering, which could be the difference between a positive and negative review.\n\n\\subsection*{Experimental Problem 3}\nIn terms of accuracy for my downstream task, two appears to be the magic number for my Word2Vec implementation. Using a context size of one tanks the model performance, and increasing it beyond two more gradually decreases performance.\n\nUsing a larger context size increases the distance from the center word that our model examines when learning. The relationships between words become less intuitive as the model is more likely to pick up on words farther away in the sentence. For instance, with a context size of six, dog has the following related words: junk, intake, photo, replace, and generally. One could imagine a review along the lines of \"Generally I feed my little dog smaller kibbles\" that is causing the adverb generally to associate with dog.\n\n\n\n\n\n\n\n\\chapter*{Part Three: Improving the Model}\n\\addcontentsline{toc}{chapter}{Part Three}\n\nFor my model improvements, I took multiple approaches. I spent a while tuning hyperparameters and I also implemented alternative TF-IDF weighting schemes.\n\nUnfortunately there is some element of randomness to the training (somewhere a random call is not seeded), and I could not get perfectly deterministic results based on my hyperparameter tuning. For all models a higher training size correlated with better results.\n\nFor Word2Vec, I discovered the best performing parameters were generally a context window size of two, a representation size of 500, and five epochs of training. Reducing the training was the most impactful hyperparameter, improving the model by ~1.5\\%, implying that the default of ten epochs is probably overfitting the training data. It also makes sense that Word2Vec benefits from a higher dimensional representation than LSA, because Word2Vec has more information in the form of an ordered context window. In terms of overall featurizer performance, my best featurizer is a concatenation of the provided combo featurizer and Word2Vec, with a performance of ~0.82.\n\nFor my LSA featurizer, I found the best performing parameter was to set the representation size to 100. A denser representation of the words (especially when context information is stripped and we're left purely with counts) results in a better fit on our regression. This implies there may be noise in our higher dimensional representations that a dense matrix eliminates.\n\nFinally I implemented three alternative weightings schemes for both TF and IDF taken from our lecture notes (Figure \\ref{fig2}).\n\n\\begin{figure}[ht]\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        % include first image\n        \\includegraphics[width=.8\\linewidth]{resources/png/tf.png}\n        \\caption{Word Featurizer}\n\n    \\end{subfigure}\n    \\begin{subfigure}{.5\\textwidth}\n        \\centering\n        % include second image\n        \\includegraphics[width=.8\\linewidth]{resources/png/idf.png}\n        \\caption{LSA Featurizer}\n\n    \\end{subfigure}\n    \\caption{Alternative TF-IDF weighting schemes}\n    \\label{fig2}\n\\end{figure}\n\nMy baseline LSA featurizer had a performance of 0.798. The table below shows a sweep of the different weighting schemes. Most of the weighting schemes failed to improve my results, with the exception being the term frequency combine with the probabilistic IDF, and the log norm combined with the smooth IDF. My best explanation for this is the first pair normalize document length, and perhaps longer reviews were given too much weight in the baseline. The second improved pair add a smoothing factor to account for sparseness in reviews, ensuring the TF-IDF matrix isn't mostly zeroes, and relatively boosting the importance of rare words. Perhaps some rarer but important words were below the noise threshold of the baseline.\n\n\\begin{table}[]\n    \\centering\n    \\begin{tabular}{|l|c|c|c|l}\n        \\cline{1-4}\n                       & IDF smooth & IDF max & \\begin{tabular}[c]{@{}c@{}}probabilistic\\\\ IDF\\end{tabular} & \\\\ \\cline{1-4}\n        term frequency & 0.79       & 0.774   & 0.802                                                       & \\\\ \\cline{1-4}\n        log norm       & 0.802      & 0.764   & 0.766                                                       & \\\\ \\cline{1-4}\n        double norm    & 0.78       & 0.766   & 0.774                                                       & \\\\ \\cline{1-4}\n    \\end{tabular}\n\\end{table}\n\n\n\\chapter*{Part Four: Skip-Gram Variant}\n\\addcontentsline{toc}{chapter}{Part Four}\n\n\n\n\n\\subsection*{Theoretical Problem A}\n\\begin{equation*}\n    \\sigma(\\vec{w} \\cdot \\vec{c})=\\frac{1}{1+e^{-\\vec{w} \\cdot \\vec{c}}}\n\\end{equation*}\n\nSubstituting $x$ for $\\vec{w} \\cdot \\vec{c}$\n\n\\begin{equation*}\n    \\frac{\\partial \\log \\sigma(x)}{\\partial x} = 1 - \\frac{1}{e^{-x}+1}\n\\end{equation*}\n\n\\subsection*{Theoretical Problem B}\n\nGiven the local objective function\n\n\\begin{equation*}\n    \\ell(w, c)=\\#(w, c) \\cdot \\log \\sigma(\\vec{w} \\cdot \\vec{c})+k \\cdot \\#(w) \\cdot \\frac{\\#(c)}{|D|} \\cdot \\log \\sigma(-\\vec{w} \\cdot \\vec{c})\n\\end{equation*}\n\nAgain substituting $x$ for $\\vec{w} \\cdot \\vec{c}$, and substituting $\\lambda$ for the constant expression $k \\cdot \\#(w) \\cdot \\frac{\\#(c)}{|D|}$ and $\\alpha$ for constant term $\\#(w,c)$\n\n\\begin{align*}\n    \\frac{\\partial \\ell(x)}{\\partial x} & = \\frac{\\alpha}{e^x + 1} -\\lambda \\frac{e^x}{e^x + 1}\n\\end{align*}\n\nSetting the derivative to $0$ we can rewrite $\\partial \\ell$ in the form\n\n\\begin{align*}\n     & \\frac{\\alpha}{1 + e^x} = \\frac{\\lambda e^x}{1 + e^x}             \\\\\n     & \\frac{\\alpha}{\\lambda} = e^x                                     \\\\\n     & x = \\log(\\frac{\\alpha}{\\lambda})                                 \\\\\n     & =\\log \\left(\\frac{\\#(w, c)}{\\#(w) \\cdot \\#(c) k} \\cdot|D|\\right)\n\\end{align*}\n\n\\subsection*{Theoretical Problem C}\nPointwise mutual information is the ratio of how often two events (in our case a word and its context) occur together versus how often they could be expected to occur if one assumes the events are independent. It is a useful index for showing quantitatively how strongly words are associated with each other.\n\nThe critical points of the skip-gram local objective function are the same as the PMI formulation except scaled by a factor of $\\log(1/k)$ (or shifted by $log(k)$ if you pull the term outside the PMI). $k$ is the number of negative samples introduced to each context. When $k=1$, the skip-gram model trains our embedding vectors towards exactly the PMI.\n\n\n", "meta": {"hexsha": "b6e1c5b6d8efc2e6ea210d685bca66ccab34d369", "size": 15028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework_2/report/content.tex", "max_stars_repo_name": "RichardMuri/MIT_6864", "max_stars_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Homework_2/report/content.tex", "max_issues_repo_name": "RichardMuri/MIT_6864", "max_issues_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Homework_2/report/content.tex", "max_forks_repo_name": "RichardMuri/MIT_6864", "max_forks_repo_head_hexsha": "40a7472f8ad03545a0ecec9b63361d4a3136d815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.7094339623, "max_line_length": 727, "alphanum_fraction": 0.6869177535, "num_tokens": 3923, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7963552157345817}}
{"text": "\n\\subsection{Directional derivative}\n\nWe have a function, \\(f(\\mathbf x)\\).\n\nGiven a vector \\(v\\), we can identify by how much this scalar function changes as you move in that direction.\n\n\\(\\nabla_v f(x):=\\lim_{\\delta \\rightarrow 0}\\dfrac{f(\\mathbf x+\\delta \\mathbf v)-f(\\mathbf x) }{\\delta }\\)\n\nThe directional derivative is the same dimension as underlying field.\n\n\\subsubsection{Other}\n\nDifferentiation of scalar field, \\(d f\\), can be defined as a vector field where grad is 0. can differ with orientation, scale\n\n", "meta": {"hexsha": "dbfc2541d1331463166e733aaa085b11ca78ef44", "size": 518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/multiScalar/02-01-directional.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/02-01-directional.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/02-01-directional.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.375, "max_line_length": 126, "alphanum_fraction": 0.7316602317, "num_tokens": 138, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7963337600984097}}
{"text": "\\documentclass{article}\n\\usepackage{color}\n\\usepackage{bigints}\n\\usepackage[italicdiff]{physics}\n\\color{white}\n\\definecolor{Red}{RGB}{124,10,2}\n\\begin{document}\n\\pagecolor{Red}\n\\title{Solution to Calculus with Calvin\\textsc{\\char13}s Problem}\n\\author{Jose Bedoya}\n\\maketitle\n\\section{Question}\n{\\LARGE\n$$I=\\bigintss_{0}^{1} \\frac{\\ln \\left(x+1\\right)\\ln x}{x}\\,dx$$\n}\n\\section{Solution}\n{\\Large\nKnowing,\n$$\\ln \\left(x+1\\right)=\\sum_{n=1}^{\\infty} \\left(-1\\right)^{n-1}\\frac{x^n}{n}$$\n\n\\vspace{3mm}\nWe have\n$$I=\\sum_{n=1}^{\\infty}\\frac{\\left(-1\\right)^{n-1}}{n}\\bigintsss_{0}^{1}x^{n-1}\\ln x\\,dx$$\n\n\\vspace{3mm}\nApplying IBP, we get\n$$I=\\sum_{n=1}^{\\infty}\\frac{\\left(-1\\right)^{n-1}}{n}\\left(\\frac{x^n\\ln x}{n}\\Big|_0^1-\\frac{1}{n}\\bigintsss_{0}^{1}x^{n-1}\\,dx\\right)$$\n$$=\\sum_{n=1}^{\\infty}\\frac{\\left(-1\\right)^n}{n^3}$$\n\n\\vspace{4mm}\nLet\\textsc{\\char13}s try to find a closed expression for this sum. We know:\n$$\\zeta\\left(3\\right)=\\sum_{n=1}^{\\infty}\\frac{1}{n^3}$$\n\n\\vspace{3mm}\nAs you can see, our sum is equal to the even inverse cubes minus the odd ones. So, let\\textsc{\\char13}s find an expression for the odd ones\n$$\\sum_{n=1}^{\\infty}\\frac{1}{\\left(2n+1\\right)^3}=\\sum_{n=1}^{\\infty}\\left(\\frac{1}{n^3}-\\frac{1}{\\left(2n\\right)^3}\\right)$$\n$$=\\frac{7\\zeta\\left(3\\right)}{8}$$\n\n\\vspace{3mm}\nTherefore,\n$$\\sum_{n=1}^{\\infty}\\frac{\\left(-1\\right)^n}{n^3}=\\sum_{n=1}^{\\infty}\\left(\\frac{1}{\\left(2n\\right)^3}-\\frac{1}{\\left(2n+1\\right)^3}\\right)$$\n\n\\vspace{5mm}\nThus,\n}\n{\\LARGE\n$$I=\\frac{-3\\zeta\\left(3\\right)}{4}$$\n}\n\\end{document}", "meta": {"hexsha": "2363093e2d805b967daa9ba1dc991252ac34ddc0", "size": 1540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Jose Bedoya's questions/Integral with Riemann Zeta Function 2.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Jose Bedoya's questions/Integral with Riemann Zeta Function 2.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Jose Bedoya's questions/Integral with Riemann Zeta Function 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": 31.4285714286, "max_line_length": 142, "alphanum_fraction": 0.6448051948, "num_tokens": 678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7963337583277893}}
{"text": "\\section*{Ex.3.3}\n\\subsection*{Argue that if $h$ is strongly universal, then it is also universal.}\n\nTo be $c$-universal it must hold that $P(h(x) = h(y))\\leq c/m$. To be strongly $c$-universal it must hold that $P(h(x) = h(y))\\leq c^2/m^2$. Hence if we can show \n$$\\left(\\frac{c}{m}\\right)^2\\leq\\frac{c}{m}$$ \nthe statement holds. As $\\frac{c}{m}$ is the probability of a collision, the value must be in the interval [0,1]. Hence $\\left(\\frac{c}{m}\\right)^2 < \\frac{c}{m}$.", "meta": {"hexsha": "6f5f6de5d7873302640ce2eaec8766f0c88ea386", "size": 474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.3.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.3.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.3.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": 79.0, "max_line_length": 163, "alphanum_fraction": 0.6518987342, "num_tokens": 173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305318133554, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7963140472277834}}
{"text": "%-------------------------------Aspect Delta---------------------------------\n\\section{Aspect Delta}\n\nAspect $\\delta$ is a dimensionless number defined as the smallest ratio of the\nheight of a vertex above its opposing triangle (see Figure~\\ref{f:tet-height}) to\nthe square root of the area the triangle across all vertices of the tetrahedron. \n\\begin{figure}[bhp]\n  \\centering\n  \\includegraphics[width=1.5in]{tet-height}\n  \\caption{\n    An illustration of the height $h_3$ of vertex 3.%\n                                                          \\label{f:tet-height}}\n\\end{figure}\nIn general, take $(i,j,k,\\ell)$ to be a permutation of $\\{0,1,2,3\\}$\n(i.e., $(i,j,k,\\ell)\\in\\Sf$) and $\\normvec{ L_{ab}}$ to be the length of the edge\nconnecting vertices $a$ and $b$.\nThen aspect ratio $\\delta$ may be written\n\\[\n  q = \\min_i\\left\\{C\\frac{h_i}{\\sqrt{A_{jk\\ell}}}\\right\\}\n\\]\nwhere $A_{jk\\ell}$ is the area of the triangle opposite vertex $i$ and\n$C = \\frac{\\sqrt[4]{108}}{4}\\approx 0.805927$ chosen so that an equilateral tetrahedron has $q = 1$.\nPATRAN~\\cite{patran:03} also speaks of a ``normalized'' aspect ratio defined as\n\\[\n  q_{alt} = 1 - q = 1 - \\min_i\\left\\{C\\frac{h_i}{\\sqrt{A_{jk\\ell}}}\\right\\}\n\\]\nwhich is 0 for an equilateral tetrahedron.\n\n\\tetmetrictable{aspect $\\delta$}%\n{$1$}%                                                Dimension\n{$[0.1,DBL\\_MAX]$}%                                   Acceptable range\n{$(0,DBL\\_MAX]$}%                                     Normal range\n{$[0,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Equilateral tet\n{\\cite{patran:03}}%                                   Citation\n{\\nsup}%                                              Verdict function name\n\n\n", "meta": {"hexsha": "c158405bc78e6756fdbdaf23a87050b8d6cbeddf", "size": 1761, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectDelta.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/TetAspectDelta.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/TetAspectDelta.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 45.1538461538, "max_line_length": 100, "alphanum_fraction": 0.5298126065, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.926303724190573, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7963097336489716}}
{"text": "\\section{Solving Poisson equation}\n\nPoisson equation is relatively easy to solve in periodic\nboundary condition using Fourier method (FFT). This situtation is different\nfrom other discretization method, such as finite difference or Lagrange\nfunction.\n\nPoisson equation in $\\mathbf{G}$-space:\n\\begin{equation}\n-G^2 \\tilde{V}_{\\mathrm{Ha}}(\\mathbf{G}) = -4\\pi \\tilde{\\rho}(\\mathbf{G})\n\\end{equation}\n\nHartree potential can be solve directly, for $\\mathbf{G} \\neq \\mathbf{0}$:\n\\begin{equation}\n\\tilde{V}_{\\mathrm{Ha}}(\\mathbf{G}) = \\frac{4\\pi\\tilde{\\rho}(\\mathbf{G})}{G^2}\n\\end{equation}\n\nAn example a program to solve Poisson equation is given in directory\n{\\tt poisson\\_01}. In this program, a charge density is constructed\nfrom difference between two Gaussian charge density. Total charge\n(integrated charge density) is restricted to zero.\nFrom this charge density, we calculate the electrostatic (Hartree) potential\nby solving Poisson equation.\n\nFunction to generate vector {\\tt dr}:\n\n\\begin{juliacode}\nfunction gen_dr( r, center )\n  Npoints = size(r)[2]\n  dr = Array(Float64,Npoints)\n  for ip=1:Npoints\n    dx2 = ( r[1,ip] - center[1] )^2\n    dy2 = ( r[2,ip] - center[2] )^2\n    dz2 = ( r[3,ip] - center[3] )^2\n    dr[ip] = sqrt( dx2 + dy2 + dz2 )\n  end\n  return dr\nend\n\\end{juliacode}\n\n\nFunction to generate charge density:\n\n\\begin{juliacode}\nfunction gen_rho( dr, σ1, σ2 )\n  Npoints = size(dr)[1]\n  rho = Array( Float64, Npoints )\n  c1 = 2*σ1^2\n  c2 = 2*σ2^2\n  cc1 = sqrt(2*pi*σ1^2)^3\n  cc2 = sqrt(2*pi*σ2^2)^3\n  for ip=1:Npoints\n    g1 = exp(-dr[ip]^2/c1)/cc1\n    g2 = exp(-dr[ip]^2/c2)/cc2\n    rho[ip] = g2 - g1\n  end\n  return rho\nend\n\\end{juliacode}\n\nFunction to solve Poisson equation:\n\n\\begin{juliacode}\nfunction solve_poisson( pw_grid::PWGrid, rho )\n  Ω  = pw_grid.Ω\n  G2 = pw_grid.G2\n  Ns = pw_grid.Ns\n  Npoints = pw_grid.Npoints\n  ctmp = 4.0*pi*R_to_G( Ns, rho )\n  for ip = 2:Npoints\n    ctmp[ip] = ctmp[ip] / G2[ip]\n  end\n  ctmp[1] = 0.0\n  phi = real( G_to_R( Ns, ctmp ) )\n  return phi\nend\n\\end{juliacode}\n", "meta": {"hexsha": "740aa7b7e0c7205d494ad25e62d6ebd0738e1860", "size": 2019, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/Doc/poisson_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/poisson_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/poisson_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": 25.8846153846, "max_line_length": 78, "alphanum_fraction": 0.681030213, "num_tokens": 730, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322215, "lm_q2_score": 0.8418256492357359, "lm_q1q2_score": 0.7961997708867005}}
{"text": "\n\n\n% mutually exclusive\n\\section{Mutually Exclusive Events, Disjoint Sets}\nTwo events $A$ and $B$ are mutually exclusive if $A\\cap B= \\emptyset$. That is, $A$ and $B$ are disjoint sets.\n\n% independent \n\\section{Independent Events}\nInterestingly, independence can, with the exception of specific symmetric cases, generally not be read off from a Venn diagram \\cite{wasserman2013all}. A set of events $A_i$ is \\textit{independent} if:\n\n\\begin{equation}\n\\mathbb{P}\\left(\\bigcap_i A_i \\right) = \\prod_i \\mathbb{P}(A_i)\n\\end{equation}\n\n\\citeasnoun{wasserman2013all} writes independence using the coproduct symbol $A\\coprod B$. Independence can be either assumed or it can be proven by verifying $\\mathbb{P}(A\\cap B) = \\mathbb{P}(A)\\mathbb{P}(B)$.\n\n\n% conditional probability\n\\section{Conditional Probability}\nConditional probability $\\mathbb{P}(A|B)$ \"probability of $A$ given $B$\" is the ratio of the probability measure applied to the subsets $A\\cap B$ and $B$:\n\nFor $\\mathbb{P}(B) > 0$:\n\\begin{equation}\n\\mathbb{P}(A|B) = \\frac{\\mathbb{P}(A\\cap B)}{\\mathbb{P}(B)}\n\\end{equation}\n\nFor dependent events, this can be interpreted as the fraction of $B$ that overlaps with $A$. For independent events, $\\mathbb{P}(A|B) = \\mathbb{P}(A)$. \n\n\n\n% law of total expectation / tower rule\n\\section{Law of Total Probability}\n\nLet $A_1,...,A_n$ be a partition of $\\Sigma$ so that $\\mathbb{P}(\\bigcup_i A_i) = \\mathbb{P}(\\Omega) = 1$. Then:\n\n\\begin{equation}\n\\mathbb{P}(B) = \\sum_i \\mathbb{P}(B|A_i)\\mathbb{P}(A_i) \n\\end{equation} \n\n% Bayes Theorem\n\\section{Bayes' Theorem}\nLet $A_1,...,A_n$ be a partition of $\\Sigma$ so that $\\mathbb{P}(\\bigcup_i A_i) = \\mathbb{P}(\\Omega) = 1$ and $\\mathbb{P}(A_i)>0$ for each $A_i$. Then:\n\n\\begin{equation}\n\\mathbb{P}(A_i|B) = \\frac{\\mathbb{P}(B|A_i)\\mathbb{P}(A_i) }{\\sum_j \\mathbb{P}(B|A_j)\\mathbb{P}(A_j) } = \\frac{\\mathbb{P}(B|A_i)\\mathbb{P}(A_i) }{\\mathbb{P}(B)}\n\\end{equation}\n\nThe theorem is so important that the different terms have names:\n\n\\begin{itemize}\n\\item $\\mathbb{P}(A_i|B)$ is the posterior\n\\item $\\mathbb{P}(B|A_i)$ is the likelihood \n\\item $\\mathbb{P}(A_j)$ is the prior\n\\item $\\mathbb{P}(B)$ is the evidence\n\\end{itemize}\n\n", "meta": {"hexsha": "5281591136b7a7df1d12945b7b722a136d0b58b8", "size": 2163, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/proba_basics.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_basics.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_basics.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": 37.2931034483, "max_line_length": 210, "alphanum_fraction": 0.696717522, "num_tokens": 758, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8774767858797979, "lm_q1q2_score": 0.7961454183865836}}
{"text": "\\section{Change of Basis and Equivalent Matrices}\r\nConsider vector spaces $V,W$ and $B=\\{v_1,\\ldots,v_n\\}, B'=\\{v_1',\\ldots,v_n'\\}$ bases of $V$, $C=\\{w_1,\\ldots,w_n\\},C'=\\{w_1',\\ldots,w_n'\\}$.\r\nLet $\\alpha:V\\to W$ be a linear map.\r\nWe want to study the relationship between $[\\alpha]_{B,C}$ and $[\\alpha]_{B',C'}$.\r\n\\begin{definition}\r\n    For a vector space $V$ with bases $B=\\{v_1,\\ldots,v_n\\}, B'=\\{v_1',\\ldots,v_n'\\}$, the change of basis matrix from $B'$ to $B$ is $P=(p_{ij})_{1\\le i,j\\le n}$ given by $p_{ij}=([v_j']_B)_i$.\r\n\\end{definition}\r\nIndeed $P=[\\operatorname{id}_V]_{B',B}$.\r\n\\begin{lemma}\r\n    $[v]_B=P[v]_{B'}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $P[v]_{B'}=[\\operatorname{id}_V]_{B',B}[v]_{B'}=[\\operatorname{id}_V(v)]_B=[v]_B$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Let $P$ be the change of basis matrix from $B'$ to $B$, then $P$ is invertible and $P^{-1}$ is the change of basis matrix from $B'$ to $B$.\r\n\\end{remark}\r\nSo for the problem we stated at the start of this section, we write $P=[\\operatorname{id}_V]_{B',B}$ and $Q=[\\operatorname{id}_W]_{C',C}$, then\r\n\\begin{proposition}\r\n    Let $A=[\\alpha]_{B,C}$, $A'=[\\alpha]_{B',C'}$ and $P,Q$ be as above, then $A'=Q^{-1}AP$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    For any $v\\in V$, we evaluate\r\n    $$AP[v]_{B'}=[\\alpha]_{B,C}[v]_B=[\\alpha(v)]_C=Q[\\alpha(v)]_{C'}=Q[\\alpha]_{B',C'}[v]_B=QA'[v]_{B'}$$\r\n    So $AP=QA'$, which means $A'=Q^{-1}AP$.\r\n\\end{proof}\r\n\\begin{definition}[Equivalent Matrices]\r\n    Two matrices $A,A'\\in M_{m,n}(F)$ are equivalent if $A'=Q^{-1}AP$ for some $Q\\in M_{m,m},P\\in M_{n,n}$ invertible.\r\n\\end{definition}\r\n\\begin{remark}\r\n    As one can check, this defines an equivalent relation.\r\n\\end{remark}\r\n\\begin{proposition}\\label{eqv_form}\r\n    Let $V,W$ be vector spaces over $F$ and $\\dim V=n,\\dim W=m$.\r\n    Let $\\alpha:V\\to W$ be linear.\r\n    Then there exists bases $B$ of $V$ and $C$ of $W$ such that\r\n    $$[\\alpha]_{B,C}=\\left( \\begin{array}{c|c}\r\n        I_r&0\\\\\r\n        \\hline\r\n        0&0\r\n    \\end{array} \\right)$$\r\n    where $I_r$ is the identity matrix of dimension $r=n-n(\\alpha)$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Fix a basis $v_{r+1},\\ldots,v_n$ of $\\ker\\alpha$ and extend it to a basis $B=\\{v_1,\\ldots,v_r\\}$.\r\n    It is easy to see that $\\alpha(v_1),\\ldots,\\alpha(v_r)$ gives a basis of $\\operatorname{Im}\\alpha$ as it is a spanning set that has the right size and that\r\n    $$\\sum_{i=1}^r\\lambda_i\\alpha(v_i)=0\\implies \\alpha\\left( \\sum_{i=1}^r\\lambda_iv_i \\right)=0\\implies\\sum_{i=1}^r\\lambda_iv_i\\in\\ker\\alpha\\implies \\forall i,\\lambda_i=0$$\r\n    Extend this to a basis $C$ of $W$, then $[\\alpha]_{B,C}$ can be easily seen to have the right form.\r\n\\end{proof}\r\n\\begin{remark}\r\n    This provides another proof of the Rank-Nullity Theorem.\r\n\\end{remark}\r\n\\begin{corollary}\r\n    Any $m\\times n$ matrix is equivalent to a matrix in the form illustrated in the preceding proposition.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $A\\in M_{m\\times n}(F)$.\r\n    The column rank $r(A)$ of $A$ is the dimension of the subspace spanned by the columns of $A$ in $F^n$.\r\n    Similarly, the row rank of $A$ is the column rank of $A^T$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    If $\\alpha$ is a linear map represented by $A$ with respect to some basis, then $r(\\alpha)=r(A)$.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Two matrices $A,A'$ of the same dimension are equivalent iff $r(A)=r(A')$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Direct consequence of Proposition \\ref{eqv_form} and the preceding remark.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    $r(A)=r(A^T)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $r=r(A)$, so there are some invertible $Q,P$ of the right sizes such that\r\n    $$Q^{-1}AP=\\left( \\begin{array}{c|c}\r\n        I_r&0\\\\\r\n        \\hline\r\n        0&0\r\n    \\end{array} \\right)$$\r\n    which is an $m\\times n$ matrix.\r\n    But then\r\n    $$P^\\top A^\\top (Q^{\\top})^{-1}=P^\\top A^\\top(Q^{-1})^\\top=(Q^{-1}AP)^\\top=\\left( \\begin{array}{c|c}\r\n        I_r&0\\\\\r\n        \\hline\r\n        0&0\r\n    \\end{array} \\right)$$\r\n    as an $n\\times m$ matrix.\r\n    So $r(A^\\top)=r=r(A)$.\r\n\\end{proof}\r\nIn the case where $\\alpha:V\\to V$ is an endomomrphism, the change of basis formula becomes $A'=P^{-1}AP$ where $P$ is the change of basis matrix and $A',A$ are the matrices of $\\alpha$ in the two different bases.\r\nThis induces the following definition.\r\n\\begin{definition}\r\n    Let $A,A'$ be square matrices.\r\n    We say $A,A'$ are similar (or conjugate) if there is an $n\\times n$ invertible square matrix $P$ such that $A'=P^{-1}AP$\r\n\\end{definition}\r\nThis notion is central to the study of diagonalisation and spectral theory.", "meta": {"hexsha": "4977196f44d40296b6f489f2e0bcc752bc888259", "size": 4667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/bases.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": "6/bases.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": "6/bases.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": 47.1414141414, "max_line_length": 213, "alphanum_fraction": 0.6228840797, "num_tokens": 1658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.8774767954920547, "lm_q1q2_score": 0.7961454161118953}}
{"text": "\\subsubsection{Integrals}\r\nThe definite integral of a function $f(x)$ from $x=a$ to $x=b$ where $a \\leq b$ is the area between $f(x)$ and the x-axis bounded by the lines $x=a$ and $x=b$ where area above the x-axis is positive, and area below the x-axis is negative. \r\n\\begin{definition}\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f(x) \\mathrm{d}x} = \\lim\\limits_{h \\to 0}{\\sum_{n=1}^{\\frac{b-a}{h}}}{f(a + (n-1)h) \\cdot h}\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\r\nWe also define an indefinite integral, or antiderivative of $f(x)$, notated $F(x)$ where\r\n\\begin{equation*}\r\nF'(x) = f(x) \\implies \\int{f(x)\\mathrm{d}x} = F(x)\r\n\\end{equation*}\r\nNote that there are infinitely many such functions $F$, since adding a constant to $F$ does not affect its derivative. To notate this, we add a constant $C$ to the indefinite integral. Given an initial condition for $f$, we can solve for $C$.\\\\\r\n\r\n\\noindent\r\nBelow are some properties of the integral. Let $f$ and $g$ be functions of $x$ and $p$, $a$, $b$, and $c$ where $a < b < c$, and $f$ and $g$ are continuous on the closed interval $[a,c]$.\r\n\\begin{enumerate}[label=]\r\n\t\\item Linearity\r\n\t\\begin{equation*}\r\n\t\t\\int{(pf \\pm g) \\mathrm{d}x} = p\\int{f \\mathrm{d}x} \\pm \\int{g \\mathrm{d}x}\r\n\t\\end{equation*}\r\n\t\\item Flipped Bounds\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f \\mathrm{d}x} = -\\int_{b}^{a}{f \\mathrm{d}x}\r\n\t\\end{equation*}\r\n\t\\item Union of Intervals\r\n\t\\begin{equation*}\r\n\t\t\\int_{a}^{b}{f \\mathrm{d}x} + \\int_{b}^{c}{f \\mathrm{d}x} = \\int_{a}^{c}{f \\mathrm{d}x}\r\n\t\\end{equation*}\r\n\t\\item Power Rule\r\n\t\\begin{equation*}\r\n\t\t\\int{x^n \\mathrm{d}x} = \\frac{x^{n+1}}{n+1} + C \\text{, }n \\neq -1\r\n\t\\end{equation*}\r\n\t\\item U-Substitution\r\n\t\\begin{equation*}\r\n\t\t\\int{\\left(f'\\circ g\\right) g' \\mathrm{d}x} = f\\circ g+ C\r\n\t\\end{equation*}\r\n\t\\item Integration by Parts\r\n\t\\begin{equation*}\r\n\t\t\\int{f' g \\mathrm{d}x} = fg - \\int{fg' \\mathrm{d}x}\r\n\t\\end{equation*}\r\n\t\\item Fundamental Theorem of Calculus\r\n\t\\begin{equation*}\r\n\t\t\\dd{}{x}\\int_{a}^{x}{f(s) \\mathrm{d}s} = f(x)\r\n\t\\end{equation*}\r\n\\end{enumerate}\r\nUsing the definition of the integral and the above rules, we can find the indefinite integral of some common functions.\r\n\\begin{enumerate}[label=]\r\n\t\\item \r\n\t\\begin{equation*}\r\n\t\\int{\\frac{1}{x} \\mathrm{d}x} = \\ln{\\abs{x}} + C\r\n\t\\end{equation*}\r\n\t\\item \r\n\t\\begin{equation*}\r\n\t\\int{\\sin{x} \\mathrm{d}x} = -\\cos{x} + C\r\n\t\\end{equation*}\r\n\t\\item \r\n\t\\begin{equation*}\r\n\t\\int{\\cos{x} \\mathrm{d}x} = \\sin{x} + C\r\n\t\\end{equation*}\r\n\t\\item \r\n\t\\begin{equation*}\r\n\t\\int{\\tan{x} \\mathrm{d}x} = -\\ln{\\abs{\\cos{x}}} + C\r\n\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "c1a5f9575d3c6a9c314cf8184a43697ce92e20b2", "size": 2578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/singleVariableCalc/integrals.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/singleVariableCalc/integrals.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/singleVariableCalc/integrals.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": 39.6615384615, "max_line_length": 245, "alphanum_fraction": 0.626454616, "num_tokens": 1013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7960605788282809}}
{"text": "\\section{Residue Theorem}\nToday I want to talk about how to evaluate integrals using the residue theorem.\n\nLet $z_0$ be an isolated singular point of $f(z)$.\nConsider the value of the closed line integral $\\oint_C f(z) dz$\naround a simple closed curve $C$ surrounding $z_0$\nbut enclosing no other singularities.\nThe little circle means it's a closed line as opposed to an open line.\nIt means it comes back to where you started.\nLet $f(z)$ be expanded in a Laurent series about $z=z_0$ that converges near\n$z=z_0$.\n\nThen,\n\\begin{align}\n    f(z) = a_0 + a_1(z - z_0) + \\cdots\n    + \\frac{b_1}{z - z_0} + \\frac{b_2}{(z - z_0)^2} + \\cdots.\n\\end{align}\n\n\\begin{question}\n    What is converging near $z_0$?\n\\end{question}\nIt means converging in the neighbourhood around that point.\nThis is important because you could have several Laurent series about a point\nthat converge in different regions.\nWe want the series that converges near the point we're expanding about.\n\nThe point of the residue theorem is that there are an infinite number of $b$'s,\nbut $b_1$ is special.\nOut of all the infinite terms, this $b_1$ is special.\nThis $b_1$ is called the \\emph{residue}.\nThat one is special.\n\nThe terms in the $a$ series do not contribute to the integral,\nbecause they are analytic.\nThe thing is, of the terms in the $b$ series,\nonly $b_1$ contributes.\nThis is because of this identity we see again and again.\n\\begin{align}\n    \\oint \\frac{dz}{\\left( z - z_0 \\right)^n} =\n    \\begin{cases}\n        2\\pi i & \\text{if } n =1\\\\\n        0 & \\text{otherwise}\n    \\end{cases}\n\\end{align}\nIt's easy to prove with a circle.\nJust substitute $z=\\rho e^{i\\theta}$.\nIf the curve is not a circle,\nfirst prove arbitrary curves give the same result\nusing Cauchy's theorem using a cut as we showed before.\nThen if you know the results of the circle,\nyou know the result for arbitrary curves.\nAnyway,\nit's a homework problem and the solution will be provided at some point.\n\nThe point is,\nthat if you use this integral,\nthe $b_1$ is the only term that satisfies $n=1$.\nAll the other $b$s have an $n$ that is bigger than one and doesn't contribute.\nThe $a$'s don't contribute because they are analytic and Cauchy's theorem tells\nyou they don't contribute,\nand of all the $b$'s only the $b_1$ contributes because of that formula.\n\nSo then, therefore\n\\begin{align}\n    \\oint_C f(z)\\, dz = 2\\pi b_1\n\\end{align}\nand this $b_1$ is called the \\emph{residue} of $f(z)$ at $z=z_0$.\nIt's the only term that survives this integration.\nAny questions about all this?\n\nSo this particular result corresponds to when you have just one singular point\ninside the contour $C$.\nWhat if there are half a dozen,\nwhat if there is more than one singularity inside that point?\nThen what?\n\nSo we have to generalize this result.\nWe generalize to when there are multiple isolated singularities.\nAnd we will see there is a very simple generalization of this thing.\n\nNow let's say this is the region [picture]\nand there are two isolated singular points enclosed by the contour $C$.\nLet's call this point $z_1$ and this point $z_2$.\nNow what you do is draw a circle around $z_1$\nand another circle around $z_2$.\nThis contour $C$ goes counter clockwise.\nThen we do what we did before.\nWe create a cut like this from $C$ to $C_1$ and a cut from $C$ to $C_2$.\nNow the contour is deformed.\nFollow the arrows and see you have a simply connected closed loop.\n\nA couple of things I want you to realise.\nThis region in between $C$ and the circles,\nthat is simply connected.\nIf I put a rubber band anywhere,\nI can shrink it to a point,\nand I can apply Cauchy's theorem.\n\nSo around the deformed contour,\nwe have\n\\begin{align}\n    \\oint f(z)\\, dz = 0\n\\end{align}\nby Cauchy's theorem,\nbecause we have cut out the singularities and it's analytic.\nThe contribution to the integral from the cut vanishes.\nSo then you can convince yourself using the logic very similar to our proof of\nthe Cauchy integral formula that\n\\begin{align}\n    \\oint_C f(z) \\, &=\n    \\oint_{C_1} f(z)\\,dz\n    + \\oint_{C_2} f(z)\\, dz\n\\end{align}\nIn other words,\nthe contribution from the cuts vanishes,\nbut you can see that $C_1$ and $C_2$ are going clockwise,\nbut if you make everything counterclockwise,\nthe signs work out.\nWe are going around $C$, $C_1$ and $C_2$ counterclockwise\nin the equation above.\n\nAnd this generalizes no matter how many singularities you have.\nIt is the sum of the contour integral around each point.\nBut we just proved the integral around one singularity is just the residue times\n$2\\pi i$.\nEach circle contains only one singular point\nand we can immediately apply the result we just derived.\nSo it should be $2\\pi i$ times the residue of each singular point.\nAnd this is the residue theorem we're going to apply again and again.\n\nSo this is my claim.\nThis leads to the residue theorem\n\\begin{align}\n    \\oint_C f(z)\\, dz &= 2\\pi i\\times\n    \\text{sum of residues of $f(z)$ from singular points inside $C$}\n\\end{align}\nThis is the thing that you guys have to remember.\n\n\\begin{question}\n    That's the closed contour $C$?\n\\end{question}\nYes it's the closed contour $C$ that contains the isolated points.\nAny questions?\n\nThe rest of this class and most of the rest of the next class will be giving\nexamples where we use the residue theorem to evaluate integrals.\nThis is a place where you use complex analysis a lot.\nThere are many integrals where the simplest way to do them is to use a contour\nintegral,\nsometimes you know for example,\nthe most convenient way to express something is as a contour integral.\nThis result gets used a lot,\nespecially if you do theoretical physics,\nyou will see this over and over again.\nLet's do some examples.\n\nYou should look at all the literature on ELMS\nand try to work through the examples there.\nDo several of them.\nUnfortunately I can't cover the full range of possibilities.\nAs you'll see,\nyou have to be clever in most cases,\nchoose your contour cunningly,\nhence it's helpful to do some examples so you can learn how to choose.\nBut time constraints.\n\nLet's start with some very simple ones.\n\\begin{example}\n    Integrate $f(z) = \\sin(z)/z^4$ around the unit circle counterclockwise.\n\\end{example}\n\\begin{proof}[solution]\n    This potentially has a pole at $z=0$.\n    There's nowhere else where it might have a pole.\n    The first thing to do is expand this in Taylor series.\n    \\begin{align}\n        \\frac{\\sin(z)}{z^4} &=\n        \\frac{1}{z^4}\\left\\{\n            z\n            - \\frac{z^3}{3!}\n            + \\frac{z^5}{5!}\n            - \\cdots\n        \\right\\}\n    \\end{align}\n    What is the order of the pole?\n    It's order 3.\n    What is the residue?\n    It's $-1/6$.\n    You can see this\n    \\begin{align}\n        f(z) &=\n        \\frac{1}{z^3}\n        - \\frac{1}{6} \\frac{1}{z}\n        + \\frac{z}{5!} - \\cdots\n    \\end{align}\n    Don't forget that negative sign,\n    the residue is $-\\frac{1}{6}$,\n    not $\\frac{1}{6}$.\n    So by the residue theorem,\n    \\begin{align}\n        \\oint \\frac{\\sin z}{z^4}\\,dz &=\n        2\\pi i \\left( -\\frac{1}{6} \\right)\\\\\n        &= -\\frac{\\pi i}{3}\n    \\end{align}\n\\end{proof}\nAny questions?\nOK let's do another example.\n\n\\begin{example}\n    Integrate $\\frac{4 - 3z}{z^2 - z}$\n    around the circle $|z|=2$ counterclockwise.\n\\end{example}\n\\begin{proof}[solution]\n    This is the circle of radius 2 centred at the origin.\n    Look at this and tell me where it has poles.\n    $z=0$ and $z=1$ where the denominator vanishes.\n    The poles are where the denominator vanishes.\n    And $0$ and $1$ are both inside the circle.\n    And so we really have to use the residue theorem\n    but first we need to find the residue at both $0$ and $1$.\n    That's the procedure.\n\n    The function has poles at $z=0$ and $z=1$.\n    Near $z=0$,\n    \\begin{align}\n        f(z) &=\n        \\frac{4 - 3z}{z(z - 1)}\\\\\n        &= \\frac{1}{z}\\left\\{\n            \\frac{4 - 3z}{z - 1}\n        \\right\\}\\\\\n        &= -\\frac{4}{z} + \\text{analytic terms near $z=0$}\n    \\end{align}\n    The fraction in the bracket is analytic at $z=0$,\n    and it's equal to $-4$.\n    What's where it comes from.\n\n    Near $z=1$,\n    \\begin{align}\n        f(z) &=\n        \\frac{4 - 3z}{z(z - 1)}\n        = \\frac{1}{z - 1}\\left\\{\n            \\frac{4 - 3z}{z}\n        \\right\\}\n    \\end{align}\n    Near $z=1$, the things in the braces are analytic,\n    so then the whole thing behaves like\n    \\begin{align}\n        f(z) = \\frac{1}{z - 1}\n    \\end{align}\n    and hence $1$ is the residue.\n    \n    By the residue theorem,\n    \\begin{align}\n        \\oint f(z)\\, dz &= 2\\pi i\\sum \\text{residues}\\\\\n        &= 2\\pi i \\left\\{ -4 + 1 \\right\\}\\\\\n        &= -6\\pi i.\n    \\end{align}\n    These are just some really simple examples to illustrate.\n\\end{proof}\nLet's suppose this is $|z|=1/2$.\nHow would this change the answer?\n\nIf you draw it,\nthe circle would then have radius $1/2$,\nand $z=1$ is outside the circle,\nso then this $z=1$ residue wouldn't have contributed\nand the result would be $-8\\pi i$.\nThe boundary is not well defined for $|z|=1$.\nYou may have to take some limiting procedure,\nand the answer may depend on how you take that limiting procedure.\n\nLet's go on to the next problem.\n\\begin{example}\n    Evaluate the definite integral\n    \\begin{align}\n        I = \\int_{0}^{2\\pi} \\frac{d\\theta}{5 + 4\\cos\\theta}.\n    \\end{align}\n\\end{example}\n\\begin{proof}[Solution]\n    Strictly speaking,\n    you don't need complex analysis to do this integral,\n    but it's a tough one.\n    You'd have to use\n    \\begin{align}\n        t = \\tan\\frac{\\theta}{2}\n    \\end{align}\n    but you would have had to know it.\n    I'll show you it's easy with complex analysis.\n    Here's what you do.\n    There's all classes of problems where you integrate trig functions.\n    The steps are going to be the same.\n\n    Change variables to $z=e^{i\\theta}$.\n    Then $\\theta$ goes from $0$ to $2\\pi$\n    around the unit circle in the complex plane.\n    As $\\theta$ goes from $0$ to $2\\pi$,\n    we go around the unit circle in the complex plane,\n    which of course is $|z|=1$.\n\n    So then, you have to change variables from $\\theta$ to $z$.\n    \\begin{align}\n        dz = i e^{i\\theta} d\\theta\\qquad\n        \\implies\\qquad\n        \\frac{1}{i} \\frac{dz}{z} = d\\theta.\n    \\end{align}\n    And then\n    \\begin{align}\n        \\cos\\theta = \\frac{1}{2}\\left(\n            z + \\frac{1}{z}\n        \\right).\n    \\end{align}\n    To see this\n    just use the Euler formula\n    \\begin{align}\n        e^{i\\theta} = \\cos\\theta + i\\sin\\theta.\n    \\end{align}\n    So then the problem has reduced to evaluating\n    \\begin{align}\n        I &=\n        \\oint \\frac{1}{iz}\n        \\frac{1}{5 + 2\\left( z + \\frac{1}{z} \\right)}\\,dz\\\\\n        &= \\frac{1}{i}\\oint \\frac{dz}{2z^2 + 5z + 2}.\n    \\end{align}\n    That's what you get when the dust settles.\n    Now we have to figure out what the poles of this thing are.\n    You have to find the roots first.\n    I'm going to skip the step and claim it can be written like this.\n    \\begin{align}\n        I &=\n        \\frac{1}{i}\n        \\oint\n        \\frac{dz}{(2z + 1)(z + 2)}.\n    \\end{align}\n    If I draw this in the complex plane,\n    it has a pole here at $z=-1/2$ and then it has a pole here at $z=-2$.\n    And we want the contour integral of the unit circle\n    centred at $z=0$.\n    You can see that only one of the two poles is inside the circle.\n    We're going counterclockwise because $\\theta$ is increasing this way.\n    $\\theta$ is increasing from $0$ to $2\\pi$ so we're going counterclockwise,\n    which is good,\n    so we don't have to put an extra sign in\n    and just blindly apply the theorems.\n\n    Only the pole at $z=-1/2$ contributes.\n    Now let's calculate the residue.\n    Let's look at this\n    \\begin{align}\n        \\frac{1}{(2z + 1)(z + 2)} &=\n        \\frac{1}{z + \\frac{1}{2}}\\left[ \n            \\frac{1}{2(z + 2)}\n        \\right]\\\\\n        &= \\frac{1}{z + \\frac{1}{2}}\\left[\n            \\frac{1}{3}\n        \\right]\n    \\end{align}\n    near $z=-1/2$,\n    where we have evaluated the analytic part at $z=-1/2$.\n    So $1/3$ is the residue,\n    so\n    \\begin{align}\n        I &= \\frac{1}{i}2\\pi i \\frac{1}{3}\\\\\n        &= \\frac{2\\pi}{3}\n    \\end{align}\n\\end{proof}\n\nAny questions?\n\\begin{question}\n    When evaluating the analytic part,\n    can we ever just say this region is analytic and just plug in the value of\n    $z$.\n    Do we have to do the Taylor series?\n\\end{question}\nYou don't have to do the Taylor series,\nonly the first term matters.\nThis thing is non-zero,\nbut if it is zero,\nthe residue is zero.\n\nWe have to be a little bit careful.\nSuppose if our function had a square in it\n\\begin{align}\n    \\frac{1}{(2z + 1)^2(z + 2)}\n    = \\frac{1}{\\left( z + \\frac{1}{2} \\right)^2}\\left[\n    \\frac{(z + \\frac{1}{2})}{2(z + 2)}\n    \\right]\n\\end{align}\nthere is a higher order pole and you have to expand.\nIn physics problems you typically only have simple poles\nand you don't have to expand.\n\nYou always want to make it a closed curve.\n\n\\begin{question}\n    What happens if the integral is not from $0$ to $2\\pi$?\n\\end{question}\nCan we try $z=e^{i2\\theta}$ for example if it's from $0$ to $\\pi$.\n\n\\begin{question}\n    Can you explain how you'd do it if it were a complex pole?\n\\end{question}\nLet's say instead we had\n\\begin{align}\n    \\frac{1}{(2z + 1)^2 (z + 2)}\n    = \\frac{1}{\\left(1 + \\frac{1}{2} \\right)^2}\n    \\frac{1}{4\\left(z + 2 \\right)}\n\\end{align}\nThen you have to expand in a Taylor series,\nso the coefficient of the next term in the Taylor series is what gives you the\nresidue.\nIn this situation with a higher order pole,\nyou need more terms in the Taylor series to work it out.\n\n\\begin{example}\n    Evaluate\n    \\begin{align}\n        I = \\int_{-\\infty}^{\\infty}\n        \\frac{dx}{1 + x^2}\n    \\end{align}\n\\end{example}\n\\begin{proof}[Solution]\n    If you were to use elementary methods,\n    you would get\n    \\begin{align}\n        \\tan^{-1}(x)|_{-\\infty}^{\\inftyy}\n        = \\frac{\\pi}{2}\n        - \\left( -\\frac{\\pi}{2} \\right)\n        = \\pi.\n    \\end{align}\n    Let's do it using complex analysis,\n    just to show you the kind of contours you can integrate with.\n    Consider the complex line integral\n    \\begin{align}\n        \\lim_{\\rho\\to\\infty}\n        \\int_{-\\rho}^{\\rho}\n        \\frac{dz}{1 + z^2}\n    \\end{align}\n    where the path is along the real line.\n    This line integral is equal to $I$.\n    Now let's draw this thing in the complex plane.\n    Let's look at this integrand.\n    It has poles where this $1+z^2$ vanishes.\n    The denominator vanishes at $z=+i$ and $z=-i$.\n    Right now the fact it has two poles is irrelevant for now.\n    Consider this thing integrated not just along the real line,\n    but back along a big semicircle in the upper half plane.\n\n    Consider\n    \\begin{align}\n        \\oint \\frac{dz}{1 + z^2}\n    \\end{align}\n    integrated over the closed contour shown in the figure,\n    which consists of a semicircle over the upper half plane,\n    in addition to the integral over real line.\n\n    This closed line integral we can evaluate using the residue theorem.\n    Even though it has two poles,\n    only $z=+i$ is inside the contour.\n    Let's evaluate it.\n    Close to $z=i$,\n    \\begin{align}\n        \\frac{1}{1 + z^2} = \\frac{1}{(z + i)(z - i)}\n        = \\frac{1}{z - 1} \\underbrace{\\frac{1}{2i}}_{\\text{residue}}\n        + \\text{analytic function}\n    \\end{align}\n    Hence by the residue theorem, the contour integral is\n    \\begin{align}\n        \\oint \\frac{dz}{1 + z^2} &=\n        2\\pi i \\frac{1}{2i} = \\pi.\n    \\end{align}\n    We have evaluated this integral not over the real line,\n    but over this closed contour which includes the real line,\n    but also includes the contribution from this big semicircle.\n    I'm going to show you the contribution from the big semicircle vanishes as\n    you take $\\rho\\to\\infty$.\n    And so this closed integral is actually equal to the integral we want.\n    That's going to be the logic here.\n\n    We need to prove the line integral over the semicircle vanishes and then\n    we're done.\n    Let's prove that.\n    \\begin{align}\n        \\underbrace{\\oint \\frac{dz}{1 + z^2}}_{\\pi} &=\n        \\underbrace{\\int_{\\text{real line}} \\frac{dz}{1 + z^2}}_{I}\n        + \\underbrace{\\int_{\\text{semicircle}} \\frac{dz}{1 + z^2}}_{?}\n    \\end{align}\n    Set $z=\\rho e^{i\\theta}$.\n    Then consider\n    \\begin{align}\n        \\int_{\\text{semicircle}} \\frac{dz}{1 + z^2} &=\n        \\int_{0}^{\\pi} \\frac{i\\rho e^{i\\theta}}{1 + \\rho^2 e^{2i\\theta}}\\,\n        d\\theta\n    \\end{align}\n    This has $\\rho$ in the numerator and $\\rho^2$ in the denominator,\n    this should go to zero as $\\rho\\to\\infty$.\n    But you still have to be careful because it's complex,\n    but you'll see this intuition is correct.\n    It's just going to vanish.\n    \\begin{align}\n        \\left|\n            \\int_{\\text{semicircle}} \\frac{dz}{1 + z^2}\n        \\right|\n        &=\n        \\left|\n            \\int_{0}^{\\pi} \\frac{i\\rho e^{i\\theta}}{1 + \\rho^2 e^{2i\\theta}}\\,\n            d\\theta\\\\\n        \\right|\n        &\\le\n        \\int_{0}^{\\pi}\n        \\left|\n            \\frac{i\\rho e^{i\\theta}}{1 + \\rho^2 e^{2i\\theta}}\n        \\right|\n        \\left|\n            d\\theta\n        \\right|\\\\\n        &\\le\n        \\int_{0}^{\\pi}\n        \\frac{\\rho}{\\rho^2} |d\\theta|\\\\\n        &=\n        \\frac{\\pi}{\\rho}\\\\\n        &\\to 0\n    \\end{align}\n    as $\\rho\\to\\infty$.\n    So in the end the contribution of this semicircle vanishes.\n\\end{proof}\n\nThis shows you can do an integral over the real line by doing an integral like\nthis with a contour like this.\nThis is one of the very standard contours where you have an integral over the\nreal line and make it a contour by closing the upper half plane,\nor lower half plane.\n\n\\begin{question}\n    What if you took the semicircle in the lower half plane?\n\\end{question}\nEverything would work, but you're not going counterclockwise and you have to\ndeal with signs.\nIt still works though.\nThere's more than one way to do these problem.\nChoose the most convenient one.\nAs you do more problems, you'll see.\nI want you guys to convince yourselves that it can be closed in the negative\nhalf plane and get the same result.\n\nThis contour works for this function works for a lot of functions,\nbut it also doesn't work for a lot of functions.\nYou could have used either up or down in this problem,\nbut we're going to look at at problem where you have to use one of them.\nIt's actually more common.\n\n\\begin{example}\n    Evaluate\n    \\begin{align}\n        I = \\int_{0}^{\\infty} \\frac{\\cos(z)}{1 + x^2}\\,dx\n    \\end{align}\n\\end{example}\n\\begin{proof}[Solution]\n    Notice that it's similar to before.\n    Notice that the integrand is even, so this is equal to\n    \\begin{align}\n        I &=\n        \\frac{1}{2}\\int_{-\\infty}^{\\infty}\n        \\frac{\\cos(x)}{1 + x^2}\\,dx.\n    \\end{align}\n    It's an even function so we can be a bit clever.\n    We want to make this an integral over some line in the complex plane.\n    There's more than one way to do this,\n    but here's the trick.\n    Write $\\cos z = \\Re e^{iz}$.\n    Then write\n    \\begin{align}\n        I &= \\Re\\left\\{\n        \\frac{1}{2}\n        \\int_{-\\infty}^{\\infty}\n        \\frac{e^{iz}}{1 + z^2}\\,\n        dz\n        \\right\\}\n    \\end{align}\n    where the integral is over the real line in the complex plane.\n    Now it's beginning to look a lot like the problem we just saw.\n    You have a function integrating over the whole real line.\n    It has singularities at exactly the same points $z=\\pm i$.\n    But can we use the same contour?\n\n    The integrand is a bit different.\n    Can we convince ourselves that the contribution from this semicircle\n    vanishes?\n    If it does, then we can use the same contour.\n    It turns out it does vanish.\n\n    Along that big semicircle, $z$ has a real and imaginary part\n    \\begin{align}\n        z = \\rho_R + i\\rho_I\n    \\end{align}\n    Unless you're at $+\\rho$ or $-\\rho$,\n    the imaginary part is infinite.\n    If the imaginary part is positive and infinite,\n    $e^{iz}$ because $e$ raised to minus infinity,\n    so it goes to zero exponentially quickly\n    if you're in the upper half plane.\n    That means this integrand vanishes incredibly quickly in the upper half\n    plane.\n    So we can use exactly the same contour as we used before\n    and use the residue theorem.\n    At the same time,\n    we can't use a contour with a semicircle in the lower half plane,\n    because it blows up incredibly quickly.\n    Last time we had a choice of contours up or down,\n    but here we don't have a choice,\n    at least we don't have that choice,\n    you have to choose to go in the upper half.\n\\end{proof}\n", "meta": {"hexsha": "4468994ee00e4dc302bda2b8d18783a14c6a4656", "size": 20583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture5.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/lecture5.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/lecture5.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": 33.6323529412, "max_line_length": 80, "alphanum_fraction": 0.6488364184, "num_tokens": 6076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7959795855989152}}
{"text": "\\chapter{Bit Manipulation}\n\\section{Concepts}\n\\subsection{Basics}\n\\begin{enumerate}\n\\item Bit value: bit0, bit1. \n\\item BitSet/Bits\n\\item Bit position (bit interchangeably)\n\\item 32-bit signed range: $[-2^{31}, 2^{31}-1]$. $0$ is like positive number without complement. \n\\end{enumerate}\n\\subsection{Operations}\n\\runinhead{Mask.} \n\\begin{enumerate}\n\\item Masking to 1: to mask a single bit position, $bit\\OR 1$\n\\item Masking to 0: to mask a single bit position, $bit\\AND 0$\n\\item Querying a bit position value: to query a single bit position, $bit\\AND 0010$\n\\item Toggling bit values: to toggle a single bit position, $bit\\XOR 1$\n\\end{enumerate}}\nThis can be extended to do masking operations on multiple bits. \n\n\\runinhead{Check 2's power}\n$$x\\AND(x-1)$$\n\n\\runinhead{Rightmost bit set.} To get the rightmost bit, with the help of 2's complement:\n\\begin{enumerate}\n\\item Left extended with 1's:\n$$x \\XOR (-x)$$\n\\item Left extended with 0's:\n$$x \\AND (-x)$$\n\\end{enumerate}\n\n\\runinhead{Negation and index} We can use tilde notation for the index accessing a string or an array\n\\begin{lstlisting}\ni  ~i  \n0  -1\n1  -2\n2  -3\n3  -4 \n4  -5 \n5  -6\n\\end{lstlisting}\n$$\n\\NOT i = -i+1\n$$\nTo determine whether a string is palindrome:\n\\begin{python}\ndef is_palindrome(s):\n  return all(s[i] == s[~i] for i in xrange(len(s)/2)) \n\\end{python}\n\\section{Single Number}\n\\subsection{Three-time appearance} \nGiven an array of integers, every element appears three times except for one. Find that single one.\n\n\\rih{Using list.} Consider 4-bit numbers:\n\\begin{eqnarray*}\n&& 0000 \\\\\n&& 0001 \\\\\n&& 0010 \\\\\n&& ... \\\\\n&& 1111\n\\end{eqnarray*}\n\nAdd (not $\\&$) the bit values \\textbf{vertically}, then result would be $abcd$ where $a, b, c, d$ can be any number, not just binary. $a, b, c, d$ can be divided by 3 if the all element appears three times. Until here, you can use a list to hold $a, b, c, d$. By mod 3, the single one that does not appear 3 times is found. \n\nTo generalize to 32-bit \\pythoninline{int}, use a list of length 32.\n\n\\rih{Using bits.}\nTo further optimize the space, use bits (bit set) instead of list. \n\\begin{itemize}\n\\item Since all except one appears 3 times, we are only interested in $0, 1, 2$ (mod 3) count of bit1 appearances in a bit position.\n\\item We create 3 bit sets to represent $0, 1, 2$ appearances of all positions of bits.\n\\item For a bit, there is one and only one bit set containing bit1 in that bit position.\n\\item Transition among the 3 bit sets for every number:\n$$\nbitSet^{(i)} = (bitSet^{(i-1)}\\AND num)\\OR(bitSet^{(i)}\\AND \\NOT num)\n$$\n\\end{itemize}\n\nFor $i$ appearances, the first part is the bit set \\textbf{transited from} $(i-1)$ appearances, and the second part is the bit set \\textbf{transited out} from itself.\n\nConsider each single bit separately. For the $j$-th bit in $num$, if $num_j=1$, the first part indicates $bitSet^{(i-1)}$ will transit in (since transition); the 2nd part is always 0 (since transition out or initially 0). If $num_j=0$, the 1st part is always 0 (since no transition); the 2nd part indicates $bitSet^{(i)}$ will remain the same (since no transition). \n\n\n\n\\subsection{Two Numbers} \nGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.\n\n\\begin{itemize}\n\\item Easily get: $x = a \\XOR b$.\n\\item $a \\neq b$; thus there are at least one 1-bit in $x$ is different.  \n\\item Take an arbitrary 1 bit set in $x$, and such bit set can classify the elements in the array into two separate groups.\n\\end{itemize}\n\n\\section{Bitwise operators}\n\\runinhead{Comparison.} Write a method which finds the maximum of two numbers $a, b$. You should not use if- else or any other comparison operator\n\\\\\nClues:\n\\begin{enumerate}\n\\item check the sign bit $s$ of $a-b$.\n\\item return $a-s*(a-b)$\n\\end{enumerate}\nCodes:\n\\begin{java}\nint getMax(int a, int b) { \n    int c = a - b;\n    int k = (c >> 31) & 0x1; \n    int max = a - k * c; \n    return max;\n}\n\n\\end{java}\nIf consider overflow, it raises another level of difficulty. \n", "meta": {"hexsha": "2e441c0b08f919727480dbeceb4d35abb3c20539", "size": 4072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterBitManipulation.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": "chapterBitManipulation.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": "chapterBitManipulation.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.3571428571, "max_line_length": 366, "alphanum_fraction": 0.7062868369, "num_tokens": 1268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218327098193, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7959795818945685}}
{"text": "\\subsection{Ordinary Differential Equations}\n\\begin{definition}\n\tAn ordinary differential equation is an equation involving a function of a single variable and its derivatives.\n\\end{definition}\n\\begin{example}\n\t\\vspace{-\\baselineskip}\n\t\\begin{flalign*}\n\t\t& y' = y & \\\\\n\t\t& y' = y^2 - t \\\\\n\t\t& y'' + y' = ye^t\n\t\\end{flalign*}\n\\end{example}\n\\subsection{Normal Forms}\n\\begin{definition}\n\tA first order equation $y' = f\\p{t, y}$ is said to be in normal form. More generally, $y^{(n)} = f\\p{t, y^{(1)}, y^{(2)}, \\ldots, y^{(n-1)}}$ is in normal form.\n\\end{definition}\n\\begin{example}\nThe normal form of $y' + 2ty = 0$ is given by $y' = -2ty$.\n\\end{example}\n\\par\\bigskip\nDifferential equations can have many solutions. In the above equation, all solutions are in the form $y\\p{t} = Ce^{-t^2}$, so it is called the \\textit{general solution} to the above ODE.\n\\begin{definition}\n\tThe general solution is the family of solutions depending on some parameters that give all but a finite number of solutions.\n\\end{definition}\n\n\\subsection{Initial Value Problems}\n\\begin{definition}\n\tA first order ODE $y' = f\\p{t, y}$ together with the initial value $y\\p{t_0} = y_0$ is called an initial value problem (\\textrm{abbreviated as IVP}).\n\\end{definition}\nA solution to an initial value problem satisfies both the associated ODE and the initial condition.\n\nFrom the above example, if we had the initial condition $y\\p{0} = 2$, then the solution to the initial value problem would be $y\\p{t} = 2e^{-t^2}$.\n\n\\pagebreak\n\\subsection{Interval of Existence}\n\\begin{definition}\n\tSuppose $y = y\\p{t}$ satisfies an initial value problem with initial condition $y\\p{t_0} = y_0$. Then the interval of existence is the largest interval containing $t = t_0$ on which $y\\p{t}$ is defined.\n\\end{definition}\n\\begin{example}\n\t\\vspace{-0.5\\baselineskip}\n\t\\begin{flalign*}\n\t\t&\n\t\t\\begin{cases}\n\t\t\ty' = y^2 \\\\\n\t\t\ty\\p{0} = 2\n\t\t\\end{cases}\n\t\t&\n\t\\end{flalign*}\n\tSolution: $\\displaystyle y\\p{t} = \\frac{1}{\\frac{1}{2} - t}$\n\t\n\tThe interval of existence for this IVP is $\\p{-\\infty, \\, \\frac{1}{2}}$ (as opposed to the set $\\mathbb{R} - \\left\\{ \\frac{1}{2} \\right\\}$, which is not connected).\n\\end{example}\n\n\\subsection{Geometric Meaning}\nConsider $y' = f\\p{t, y}$ with $y\\p{t_0} = y_0$. If $y\\p{t}$ is a solution to the problem, then for any $t$, we must have $\\underbrace{y'\\p{t}}_{\\mathclap{\\substack{\\text{Slope of } \\\\ \\text{tangent line at }t.}}} = f\\p{t, y\\p{t}}$.\n\n\\subsection{Direction Fields}\n\\begin{definition}\n\tA direction field is a plot of line segments, where each one is centered at a point $\\p{t, y}$ whose slope is given by $f\\p{t, y}$.\n\\end{definition}\n\\textit{Example:} $y' = y$\n\\par\n\\begin{tikzpicture}\n\t\\draw[<->, black] (-4, 0) -- (4, 0) node[pos = 1, right]{$t$};\n\t\\draw[<->, black] (0, -2) -- (0, 3) node[pos = 1, above]{$y$};\n\t\\foreach \\x in {-3.5, -3, ..., 3.5}\n\t\t\\foreach \\y in {-1.5, -1, ..., 2.5}\n\t\t{\n\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(\\y)}:-0.125);\n\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(\\y)}:0.125);\n\t\t}\n\t\\draw[<->, red, thick, domain = -3.5:1] plot (\\x, {exp(\\x)});\n\t\\node[circle, inner sep = 1pt, fill = black, label = right:{$\\p{0, 1}$}] at (0, 1) {};\n\\end{tikzpicture}\n\\par\nThese are useful for finding numerical solutions to equations we can't solve explicitly.\n\n\\subsection{Qualitative Methods}\n\\textit{Example:} $y' = 1 - y^2$\n\\par\n\\begin{figure}[H]\n\t\\begin{minipage}[t]{0.5\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale = 0.75]\n\t\t\t\\draw[<->, black] (-4, 0) -- (4, 0) node[pos = 1, right] {$t$};\n\t\t\t\\draw[<->, black] (0, -3) -- (0, 3) node[pos = 1, above] {$y$};\n\t\t\t\\foreach \\x in {-3.5, -3, ..., 3.5}\n\t\t\t\t\\foreach \\y in {-2.5, -2, ..., 2.5}\n\t\t\t\t{\n\t\t\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(1 - \\y * \\y)}:-0.125);\n\t\t\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(1 - \\y * \\y)}:0.125);\n\t\t\t\t}\n\t\t\t\\draw[<->, dashed, thick, red] (-4.25, 1) -- (4.25, 1) node[pos = 1, right] {$y\\p{t} = 1$};\n\t\t\t\\draw[<->, dashed, thick, red] (-4.25, -1) -- (4.25, -1) node[pos = 1, right] {$y\\p{t} = -1$};\n\t\t\t\\draw[thin] (5.2, 1.5) .. controls (5.2, 1.8) and (5.5, 2.1) .. (5.5, 2.5) node[pos = 1, above, align = center] {\\small Equilibrium \\\\ \\small solutions};\n\t\t\\end{tikzpicture}\n\t\t\\caption{Direction Field}\n\t\\end{minipage}%\n\t\\begin{minipage}[t]{0.5\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale = 1.5]\n\t\t\t\\draw[<->, black] (-2, 0) -- (2, 0) node[pos = 1, right] {$y$};\n\t\t\t\\draw[<->, black] (0, -1.5) -- (0, 1.5) node[pos = 1, above] {$y'$};\n\t\t\t\\draw[thin, gray] (-1, -0.25) -- (-1, 0.25) node[pos = 0, below, black] {-1};\n\t\t\t\\draw[thin, gray] (1, -0.25) -- (1, 0.25) node[pos = 0, below, black] {1};\n\t\t\t\\draw[<->, red, thick] plot[domain = -1.5:1.5] (\\x, 1 - \\x * \\x);\n\t\t\\end{tikzpicture}\n\t\t\\caption{Phase Portrait}\n\t\\end{minipage}\n\\end{figure}\n\\begin{minipage}[t]{0.5\\textwidth}\n\tSolution classifications:\n\t\\begin{enumerate}[label = \\arabic*.]\n\t\t\\item Equilibrium solution: $y\\p{t} = 1$, $y\\p{t} = -1$\n\t\t\\item $\\phantom{|} y\\p{0} \\phantom{|} > 1$: \\quad\n\t\t\t\\begin{tikzpicture}[scale = 0.35, baseline = -0.8ex]\n\t\t\t\t\\draw[red] (1.25, -0.75) .. controls (-1.3, -0.65) .. (-1.5, 0.5);\n\t\t\t\\end{tikzpicture}\n\t\t\\item $|y\\p{0}| < 1$: \\quad\n\t\t\t\\begin{tikzpicture}[scale = 0.35, baseline = -0.8ex]\n\t\t\t\t\\draw[red] (1.25, 0.5) .. controls (-0.25, 0.5) and (-0.25, -0.75) .. (-1.5, -0.75);\n\t\t\t\\end{tikzpicture}\n\t\t\\item $\\phantom{|} y\\p{0} \\phantom{|} < 1$: \\quad\n\t\t\t\\begin{tikzpicture}[scale = 0.35, baseline = -0.8ex]\n\t\t\t\t\\draw[red] (1.25, -0.75) .. controls (0.9, 0.5) .. (-1.5, 0.5);\n\t\t\t\\end{tikzpicture}\n\t\\end{enumerate}\n\\end{minipage}%\n\\begin{minipage}[t]{0.5\\textwidth}\n\t\\begin{tikzpicture}[baseline = (current bounding box.north)]\n\t\t\\draw[<->, black] (-4, 0) -- (4, 0) node[pos = 1, right] {$t$};\n\t\t\\draw[<->, black] (0, -3) -- (0, 3) node[pos = 1, above] {$y$};\n\t\t\\foreach \\x in {-3.5, -3, ..., 3.5}\n\t\t\t\\foreach \\y in {-2.5, -2, ..., 2.5}\n\t\t\t{\n\t\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(1 - \\y * \\y)}:-0.125);\n\t\t\t\t\\draw[\\slopecolor] (\\x, \\y) -- +({atan(1 - \\y * \\y)}:0.125);\n\t\t\t}\n\t\t\\draw[<->, dashed, thick, red] (-4.25, 1) -- (4.25, 1) node[pos = 1, right] {};\n\t\t\\draw[<->, dashed, thick, red] (-4.25, -1) -- (4.25, -1) node[pos = 1, right] {};\n\t\t\\draw[<->, thick, red] plot[domain = -0.125:4] (\\x, {(3 * exp(2 * \\x) + 1) / (3 * exp(2 * \\x) - 1)});\n\t\t\\node[circle, inner sep = 1pt, fill = black, label = right:{$y\\p{0} = 2$}] at (0, 2) {};\n\t\t\\draw[<->, thick, red] plot[domain = -4:4] (\\x, {(exp(2 * \\x) - 1) / (exp(2 * \\x) + 1)});\n\t\t\\node[circle, inner sep = 1pt, fill = black, label = below right:{$y\\p{0} = 0$}] at (0, 0) {};\n\t\t\\draw[<->, thick, red] plot[domain = -4:0.125] (\\x, {(exp(2 * \\x) + 3) / (exp(2 * \\x) - 3)});\n\t\t\\node[circle, inner sep = 1pt, fill = black, label = right:{$y\\p{0} = -2$}] at (0, -2) {};\n\t\\end{tikzpicture}\n\\end{minipage}", "meta": {"hexsha": "3d9861f8589581e9d75be30cda8ca423b00b7e65", "size": 6743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/introduction.tex", "max_stars_repo_name": "stevenktruong/differential-equations-intro", "max_stars_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_stars_repo_licenses": ["MIT"], "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": "stevenktruong/differential-equations-intro", "max_issues_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_issues_repo_licenses": ["MIT"], "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": "stevenktruong/differential-equations-intro", "max_forks_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_forks_repo_licenses": ["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.5608108108, "max_line_length": 232, "alphanum_fraction": 0.5807504078, "num_tokens": 2869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969193, "lm_q2_score": 0.9124361580958427, "lm_q1q2_score": 0.7959612901044909}}
{"text": "\\subsection{Factoring Polynomials}\r\n\r\nWe want to break up a polynomial like $f(x) = a_0 + a_1x^1 + \\ldots a_nx^n$ into linear factors so that $f(x) = c(x-b_1)\\cdot \\ldots \\cdot(x - b_n)$. This form makes it simple to see that the roots of $f$, solutions to $f(x) = 0$, are $x = b_1 \\ldots b_n$.\\\\\r\n\r\n\r\nFor quadratics, $f(x) = ax^2 + bx + c$, there exists a simple formula that will give us both roots, the quadratic formula\r\n\\begin{equation*}\r\n\tx = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}.\r\n\\end{equation*}\r\n\r\n\r\nWe can see that when $b^2 - 4ac < 0$, like for $f(x) = x^2 + 5x + 10$, we will get complex roots $\\alpha \\pm \\beta i$. For any polynomial, these roots come in pairs, so if $\\alpha + \\beta i$ is a root, then so is $\\alpha - \\beta i$. This means that every conjugate pair $\\alpha \\pm \\beta i$ has a quadratic equation with those roots. Sometimes we will not factor quadratics with complex roots into linear terms.\\\\\r\n\r\n\r\nAlthough there do exist explicit formulas for finding roots for cubic (degree 3) and quartic (degree 4) equations, they are too long and not useful enough to memorize. When working by hand, we instead use other tricks to find roots.\\\\\r\n\r\n\r\nThere are a few useful tricks that can help. If the polynomial doesn't have a constant term, then 0 is a root. If all the coefficients sum to 0, then 1 is a root. For certain polynomials with an even number of terms, like all cubics of the form $ax^3 + bx^2 + cax + cb$ we can factor out a term from the first two and last two terms to get $x^2(ax+b)+c(ax+b) = (ax+b)(x^2+c)$. For other polynomials, we might just try guessing and checking values. However, we need a more efficient way that works in general.\\\\\r\n\r\n\r\nSince we are looking to find linear factors $f(x) = c(x-b_1)\\cdot \\ldots \\cdot(x-b_n)$, we can see that the constant term in the polynomial is the product of the roots $b_1 \\ldots b_n$. In fact, since the coefficients of polynomials are completely determined by the roots and the leading coefficient, all the coefficients are sums and products of roots. You might remember when factoring quadratics that the coefficient of $x$ term is the sum of the two roots. These rules are called Vieta's formulas.\\\\\r\n\r\n\r\nSo, if we have the constant term, we can check all of its integer factors to see if any are roots. For each root, we can divide, using a technique like synthetic division, to continue finding the rest of the roots. This method is especially useful on tests because the roots tend to be integers.\r\n\r\n\\input{./backgroundReview/algebraPreCalc/factoringPolynomials_example.tex}", "meta": {"hexsha": "a09ddfa41a465b423d624ea327e07a7168b970d2", "size": 2562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/backgroundReview/algebraPreCalc/factoringPolynomials.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/backgroundReview/algebraPreCalc/factoringPolynomials.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/backgroundReview/algebraPreCalc/factoringPolynomials.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": 98.5384615385, "max_line_length": 511, "alphanum_fraction": 0.7291178767, "num_tokens": 694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.7959612764779906}}
{"text": "\\sec{Exact ODEs}\n\\subsection{Introduction}\n\\begin{defn}[Exact ODEs] \n\tA first order ODE $M(x, y) + N(x, y)y' = 0$ is called exact if there is a function $u(x, y)$ such that\n\t\\[\\dfrac{\\partial u}{\\partial x} = M \\text{ and } \\dfrac{\\partial u}{\\partial y} = N.\\]\n\\end{defn}\n\\begin{mdframed}[style=boxstyle, frametitle={Identifying such an ODE}]\nIf the functions ($M$ and $N$) along with the domain are ``good enough'', then the ODE is exact if and only if\n\\[\\dfrac{\\partial M}{\\partial y} = \\dfrac{\\partial N}{\\partial x}.\\]\n\\end{mdframed}\n\\newpage\n\\begin{mdframed}[style=boxstyle, frametitle={The Solution}]\nGiven any such scalar function $u(x, y)$ as mentioned above, the solution is then given by \n\\[u(x, y) = c.\\]\nThus, the question now reduces to finding such a $u(x, y).$\\\\\nThis function can be found either via inspection or via the following method:\n\\begin{enumerate}[leftmargin = *, label = \\Roman*:]\n\t\\item Integrate $\\dfrac{\\partial u}{\\partial x} = M(x, y)$ with respect to $x$ to get \n\t\\[u(x, y) = \\int M(x, y) dx + k(y),\\]\n\twhere $k(y)$ is a constant of integration.\n\t\\item To determine $k(y),$ differentiate the above equation in Step I with respect to $y,$ to get:\n\t\\[\\frac{\\partial u}{\\partial y} = k'(y) + \\frac{\\partial}{\\partial y}\\left(\\int M(x, y) dx\\right).\\]\n\tAs the given ODE is exact, the LHS is simply $N(x, y).$ We rearrange this to get\n\t\\[k'(y) = N(x, y) - \\frac{\\partial}{\\partial y}\\left(\\int M(x, y) dx\\right).\\]\n\tThis can now be used to determine $k(y)$ and hence, $u.$\\\\\n\t\\emph{Remark.} Even though the RHS \\emph{looks} like a function of $x$ and $y$ both, it will simplify to just a function of $y.$ This happens precisely because $u$ is exact to begin with.\n\\end{enumerate}\n\\end{mdframed}\t\n\\exercise{\n\tSolve the following ODEs.\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item $(2x + y^2) + 2xy y' = 0.$\n\t\t\\item $(y\\cos x + 2xe^y) + (\\sin x + x^2 e^y - 1)y' = 0.$\n\t\\end{enumerate}\n}\n%\n\\newpage\n\\subsection{Integrating factors}\n\\begin{defn}[Integrating factor]\nConsider the scenario where we have the ODE\n\\[M(x, y) + N(x, y)y' = 0\\]\nand $M_y \\neq N_x,$ id est, the ODE is not exact.\\\\~\\\\\nSometimes, we may find a scalar function $\\mu(x, y)$ such that\n\\[\\mu(x, y)M(x, y) + \\mu(x, y)N(x, y)y' = 0\\]\nis exact, id est, \n\\[(\\mu M)_y = (\\mu N)_x.\\]\nSuch a function $\\mu(x, y)$ is called an \\defin{integrating factor} of the original ODE.\n\\end{defn}\n\n\\begin{mdframed}[style=boxstyle, frametitle={Actually solving it}]\nIn practice, we usually try to find an integrating factor which is only a function of $x$ (or $y$). In this case, we have $\\mu_y = 0$ (or $\\mu_x = 0,$ resp.).\\\\\nIn the respective cases, the equations simplify to:\n\\begin{enumerate}[leftmargin=*]\n\t\\item $\\dfrac{d \\mu}{dx} = \\left(\\dfrac{M_y - N_x}{N}\\right)\\mu.$\\\\~\\\\\n\tThus, our assumption that $\\mu$ is just a function of $x$ is valid precisely when the term in the bracket is independent of $y.$\\\\\n\tSimilarly, the other case gives us:\n\t\\item $\\dfrac{d \\mu}{dy} = \\left(\\dfrac{N_x - M_y}{M}\\right)\\mu.$\n\\end{enumerate}\n\\end{mdframed}\n\\exercise{%\n\tSolve the following ODEs.\n\t\\begin{enumerate}[leftmargin=*]\n\t\t\\item $(8xy - 9y^2) + (2x^2 - 6xy)y' = 0.$\n\t\t\\item $-y + xy' = 0.$\n\t\\end{enumerate}\n}", "meta": {"hexsha": "f891f05b80234574e2bbddacc345fa3b5d44f1e4", "size": 3180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/exact.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/exact.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/exact.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 48.1818181818, "max_line_length": 188, "alphanum_fraction": 0.6556603774, "num_tokens": 1130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.795940569781337}}
{"text": "%!TEX root = ../TTK18-Summary.tex\n\\section{Bi-level programming in constrained control}\nA bi-level program is an optimization problem that depends on the solution of another optimization problem, called ``upper level'' (UL) and ``lower level'' (LL) problems, respectively.\n%\n\\begin{equation}\\label{eq:bilevel-general}\n  \\begin{split}\n    \\min_x f\\sub{UL}(x,z) \\\\\n    G\\sub{UI}(x,z) \\leq 0 \\\\\n    G\\sub{UE}(x,z) = 0 \\\\\n    z = \\arg \\min_z f\\sub{LL}(x,z) \\\\\n    G\\sub{LI}(x,z) \\leq 0 \\\\\n    G\\sub{LE}(x,z) = 0\n  \\end{split}\n\\end{equation}\n\n\\subsection{Restricting problem classes}\nThe formulation \\eqref{eq:bilevel-general} is very general. Must restrict the problem in order to solve efficiently, by assuming:\n%\n\\begin{itemize}\n  \\item LL problem is convex and regular (TODO: what is regular?),\n  \\item linear constraints, and\n  \\item linear or quadratic objective functions.\n\\end{itemize}\n%\nThen we can replace the LL problem with its KKT conditions. The Lagrangian function is\n%\n\\begin{equation}\n  \\mathcal{L}(x,z,\\lambda,\\mu) = f\\sub{LL}(x,z) + \\lambda^T G\\sub{LI}(x,z) + \\mu^T G\\sub{LE}(x,z)\n\\end{equation}\n%\nand the KKT conditions are\n%\n\\begin{equation}\\label{eq:kkt-lower-level}\n  \\begin{split}\n    \\nabla_z \\mathcal{L}(x,z,\\lambda,\\mu) &= 0 \\\\\n    G\\sub{LI}(x,z) &\\leq 0 \\\\\n    G\\sub{LE}(x,z) &= 0 \\\\\n    \\lambda &\\geq 0 \\\\\n    \\lambda \\hadamard G\\sub{LI}(x,z) &= 0\n  \\end{split}\n\\end{equation}\n%\nwhere $\\hadamard$ is the entrywise product. Line by line, the KKT conditions can be interpreted as\n%\n\\begin{itemize}\n  \\item the Lagrangian does not change,\n  \\item the inequality constraints hold,\n  \\item the equality constraints hold,\n  \\item the Lagrange multipliers are nonnegative,\n  \\item each inequality constraint is either active, or its Lagrange multiplier is zero.\n\\end{itemize}\n%\nThe overall problem is then\n%\n\\begin{equation}\\label{eq:bilevel-kkt}\n  \\begin{split}\n    \\min_{x,z,\\lambda,\\mu} f\\sub{UL}(x,z) & \\\\\n    G\\sub{UI}(x,z) & \\leq 0 \\\\\n    G\\sub{UE}(x,z) &= 0 \\\\\n    \\nabla_z \\mathcal{L}(x,z,\\lambda,\\mu) &= 0 \\\\\n    G\\sub{LI}(x,z) &\\leq 0 \\\\\n    G\\sub{LE}(x,z) &= 0 \\\\\n    \\lambda &\\geq 0 \\\\\n    \\lambda \\hadamard G\\sub{LI}(x,z) &= 0 \\\\\n  \\end{split}\n\\end{equation}\n%\nwhich is solvable for smaller problems, using e.g. YALMIP.\n\n\\subsection{Big-M notation}\nBig-M formulation replaces nonlinear complementarity constraints\\footnote{In \\eqref{eq:kkt-lower-level} and \\eqref{eq:bilevel-kkt}, the complementarity constraint is $\\lambda \\hadamard G\\sub{LI}(x,z) = 0$, because it is a product of two variables.} with linear constraints using binary variables $s \\in \\{0,1\\}$ to indicate activeness for inequality constraints:\n%\n\\begin{equation}\\label{eq:big-M}\n  \\begin{split}\n    G\\sub{LI}(x,z) &\\leq 0 \\\\\n    G\\sub{LI}(x,z) &\\geq -M^u(1-s) \\\\\n    \\lambda        &\\geq 0 \\\\\n    \\lambda        &\\leq M^\\lambda s\n  \\end{split}\n\\end{equation}\n%\nThis notation fulfills the complementarity constraints, and given large enough $M^u$ and $M^\\lambda$, the solution is unchanged. When $s = 1$ we get $G\\sub{LI}(x,z) = 0$ (inequality constraint active), and when $s = 0$ we get $\\lambda = 0$ (inequality constraint inactive).\n\nThe overall problem formulation becomes\n%\n\\begin{equation}\n  \\begin{split}\n    \\min_{x,z,\\lambda,\\mu,s} f\\sub{UL}(x,z) \\\\\n    G\\sub{UI}(x,z) & \\leq 0 \\\\\n    G\\sub{UE}(x,z) &= 0 \\\\\n    \\nabla_z \\mathcal{L}(x,z,\\lambda,\\mu) &= 0 \\\\\n    G\\sub{LI}(x,z) &\\leq 0 \\\\\n    G\\sub{LE}(x,z) &= 0 \\\\\n    \\lambda &\\geq 0 \\\\\n    G\\sub{LI}(x,z) &\\geq -M^u(1-s) \\\\\n    \\lambda &\\leq M^\\lambda s \\\\\n    s &\\in \\{0,1\\}\n  \\end{split}\n\\end{equation}\n\nLinear $f\\sub{UL}$ gives a MILP\\footnote{Mixed integer linear program.}, quadratic $f\\sub{UL}$ gives a MIQP\\footnote{Mixed integer quadratic program.}. Nonconvex, $np$-hard, but efficient software exists.\n\n\\subsection{Solving MILP/MIQP}\nSome steps can be taken to make MILP/MIQPs easier to solve.\n\n\\subsubsection{Branch-and-bound}\nA branch-and-bound solver partitions the search space into regions, and finds an upper bound $UB$ and lower bound $LB$ for the solution in each region. If\n%\n\\begin{equation}\n  LB_i > UB_j\n\\end{equation}\n%\nthen we know the solution is not in $i$, and we discard that region.\n\nYou can also remove known symmetries from symmetric problems by adding extra constraints to make only one of the symmetric solutions feasible.\n\n\\subsubsection{Restrict combinations of binary variables}\nThe binary variables indicate which constraints are active, and some combinations of active constraints are known to be impossible. Linear constraints on the binary variables can remove these combinations from the search space.\n\n\\subsubsection{Use small $M^u$/$M^\\lambda$}\nFor a correct analytical solution, $M^u$ and $M^\\lambda$ must be sufficiently large. However, setting them too large gives numerical issues and an inaccurate solution.\n\nA good $M^u$ can sometimes be found by solving a series of LPs, if the LL constraints are bounded.\n\n$M^\\lambda$ may need trial-and-error: If a value of $\\lambda$ is constrained by $M^\\lambda$, retry after increasing the corresponding element of $M^\\lambda$.\n\nThis is made easier by setting $M^u$/$M^\\lambda$ diagonal and positive.\n\n\\subsection{Approximate explicit MPC}\nExplicit MPC means to solve the optimization problem of an MPC offline, so that the solution can be calculated quickly and explicitly online. Bilevel optimization can be used for this.\n%\n\\begin{itemize}\n  \\item Find a set of points $V$ whose convex hull describes the feasible region of the MPC.\n  \\item Solve MPC problem for each such point in the state space.\n  \\item Partition the convex hull of $V$ into simplices with triangulation.\n  \\item Use linear interpolation in each simplex $S_i$ to define a piecewise affine state feedback\n  \\begin{equation}\n    u = K^i x + k^i,\\quad x \\in S_i\n  \\end{equation}\n  which will be feasible and continuous.\n  \\item Further subdivide triangulation if $\\norm{u_0 - u}$ too large or stability cannot be proven.\n  \\begin{itemize}\n    \\item Can check difference from optimal input by solving a bilevel program for each simplex.\n    \\item If the error is too large, create a new point where the error is greatest.\n    \\item The bilevel program will be nonlinear ($f\\sub{UL} = \\max_x \\norm{u_0 - u}_\\infty$), but can be linearized using big M.\n  \\end{itemize}\n  \\item Can prove stability by showing that the value function is an LF for the closed loop system.\n\\end{itemize}\n", "meta": {"hexsha": "872733d520a965ab0c72dae7a3ba5b0566e81d33", "size": 6394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-bilevel.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-bilevel.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-bilevel.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.9127516779, "max_line_length": 362, "alphanum_fraction": 0.7000312793, "num_tokens": 1945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.7959405653672486}}
{"text": "\\section{Modeling with ordinary differential equations}\n\n\\begin{example}[Exponential growth]\n  Bacteria are living on a substrate with ample nutrients. Each\n  bacteria splits into two after a certain time $\\Delta t$. The time\n  span for splitting is fixed and independent of the individuum. Then,\n  given the amount $u_0$ of bacteria at time $t_0$, the amount at\n  $t_1 = t_0+\\Delta t$ is $u_1 = 2 u_0$. Generalizing, we obtain\n  \\begin{gather*}\n    u_n = u(t_n) = 2^n u_0, \\qquad t_n = t_0 + n\\Delta t.\n  \\end{gather*}\n\n  After a short time, the number of bacteria will be huge, such that\n  counting is not a good idea anymore. Also, the cell division does\n  not run on a very sharp clock, such that after some time, divisions\n  will not only take place at the discrete times $t_0+n\\Delta t$, but\n  at any time between these as well. Therefore, we apply the continuum\n  hypothesis, that is, $u$ is not a discrete quantity anymore, but a\n  continuous one that can take any real value. In order to accommodate\n  for the continuum in time, we make a change of variables:\n  \\begin{gather*}\n    u(t) = 2^{\\frac{t-t_0}{\\Delta t}} u_0.\n  \\end{gather*}\n\n  Here, we have already written down the solution of the problem,\n  which is hard to generalize. The original description of the problem\n  involved the change of $u$ from one point in time to the next. In\n  the continuum description, this becomes the derivative, which we can\n  now compute from our last formula:\n  \\begin{gather*}\n    \\tfrac{d}{dt} u(t) = \\frac{\\ln 2}{\\Delta t} 2^{\\frac{t-t_0}{\\Delta t}} u_0\n    = \\frac{\\ln 2}{\\Delta t} u(t).\n  \\end{gather*}\n  \n  We see that the derivative of $u$ at a certain time depends on $u$\n  itself at the same time and a constant factor, which we call the\n  growth rate $\\alpha$. Thus, we have arrived at our first\n  differential equation\n  \\begin{gather}\n    \\label{eq:models:1}\n    u'(t) = \\alpha u(t).\n  \\end{gather}\n  What we have seen as well is, that we had to start with some\n  bacteria to get the process going. Indeed, any function of the form\n  \\begin{gather*}\n    u(t) = c e^{\\alpha t}\n  \\end{gather*}\n  is a solution to equation~\\eqref{eq:models:1}. It is the initial\n  value $u_0$, which anchors the solution and makes it unique.\n\\end{example}\n\n\\begin{example}[Predator-prey systems]\n  We add a second species to our bacteria example. Let's say, we\n  replace the bacteria by sardines living in a nutrient rich sea, and\n  we add tuna eating sardines. The amount of sardines eaten depends on\n  the likelyhood that a sardine and a tuna are in the same place, and\n  on the hunting efficiency $\\beta$ of the tuna. Thus,\n  equation~\\eqref{eq:models:1} is augmented by a negative change in\n  population depending on the product of sardines $u$ and tuna $v$:\n  \\begin{gather*}\n    u' = \\alpha u - \\beta u v.\n  \\end{gather*}\n\n  In addition, we need an equation for the amount of tuna. In this\n  simple model, we will make two assumptions: first, tuna die of\n  natural causes at a death rate of $\\gamma$. Second, tuna procreate\n  if there is enough food (sardines), and the procreation rate is\n  proportional to the amount of food. Thus, we obtain\n  \\begin{gather*}\n    v' = \\delta u v - \\gamma v.\n  \\end{gather*}\n\n  Again, we will need initial populations at some point in time to\n  compute ahead from there.\n\\end{example}\n\n\\begin{remark}\n  The Lotka-Volterra-equations have periodic solutions. Even though\n  none of these exist in closed form the sulotions can be simulated:\n  \\begin{figure}[tp]\n    \\begin{center}\n      \\includegraphics[width=.6\\textwidth]{fig/lotkavolterra}\n      \\caption{Plot of a solution to the Lotka-Volterra equation with\n        parameters $\\alpha = \\frac 23$, $\\beta  = \\frac 43$, $\\delta = \\gamma = 1$\n        and initial values $u(0) = 3$, $v(0) = 1$. Solved with a Runge-Kutta\n        method of order five and step size $h = 10^{-5}$.}\n    \\end{center}\n    \\label{fig:lotkavolterra}  \n  \\end{figure}\n  Lotka and Volterra became interested in this system as they had\n  found that the amount of predatory fish caught had increased\n  during World War I. During the war years there was a strong\n  decrease of fishing effort. In conclusion, they thought, there had\n  to be more prey fish.\n  \n  A (far too rarely) applied consequence is that in order to diminish\n  the amount of e.g. foxes one should hunt rabbits as foxes feed\n  on rabbits.\n\\end{remark}\n\n\\begin{example}[Graviational two-body systems]\n  According to Newton's law of universal gravitation, two bodies of\n  masses $m_1$ and $m_2$ attract each other with a force\n  \\begin{gather*}\n    \\vec F_1 = G \\frac{m_1m_2}{r^3} \\vec r_1,\n  \\end{gather*}\n  where $\\vec F_1$ is the force vector acting on $m_1$ and $\\vec r_1$\n  is the vector pointing from $m_1$ to $m_2$ and $r = \\lvert\\vec r_1\\rvert = \\lvert\\vec r_2\\rvert$.\n\n  Newton's second law of motion on the other hand relates forces and\n  acceleration:\n  \\begin{gather*}\n    \\vec F = m \\vec x'',\n  \\end{gather*}\n  where $\\vec x$ is the position of a body in space.\n\n  Combining these, we obtain equations for the positions of the two bodies:\n  \\begin{gather*}\n    \\vec x''_i = G \\frac{m_{3-i}}{r^3} (\\vec x_i - \\vec x_{3-i}), \\qquad i=1,2.\n  \\end{gather*}\n  This is a system of 6 independent variables. Nevertheless, it can be\n  reduced to three by using that the center of mass moves\n  inertially. Then, the distance vector is the only variable to be\n  computed for:\n  \\begin{gather*}\n    \\vec r'' = - G \\frac{m}{r^3} \\vec r.\n  \\end{gather*}\n  Intuitively, that we need an initial position and an initial\n  velocity for the two bodies. Later on, we will see that this can\n  actually be justified mathematically.\n\\end{example}\n\n\\begin{example}[Celestial mechanics]\n  Now we extend the two-body system to a many-body system. Again, we\n  subtract the center of mass, such that we obtain $n$ sets of 3\n  equations for an $n+1$-body system. Since forces simply add up, this\n  system becomes\n  \\begin{gather}\n    \\label{eq:celestial}\n    \\vec x_i = -G \\sum_{j\\neq i} \\frac{m_j}{r_{ij}^3} \\vec r_{ij}.\n  \\end{gather}\n  Here, $\\vec r_{ij} = \\vec r_j - \\vec r_i$ and $r_{ij} = \\lvert \\vec r_{ij}\\rvert$.\n  Initial data for the solar system can be obtained from\n  \\begin{center}\n    \\texttt{https://ssd.jpl.nasa.gov/?horizons}\n  \\end{center}\n\\end{example}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"notes\"\n%%% End: \n", "meta": {"hexsha": "9d76710c8dda1cfc09d87490e9672caa9b859663", "size": 6351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode/models.tex", "max_stars_repo_name": "ahumanita/notes", "max_stars_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ode/models.tex", "max_issues_repo_name": "ahumanita/notes", "max_issues_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-05-24T07:31:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-31T12:58:14.000Z", "max_forks_repo_path": "ode/models.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": 41.5098039216, "max_line_length": 99, "alphanum_fraction": 0.6995748701, "num_tokens": 1920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.9086178926024028, "lm_q1q2_score": 0.795755739557027}}
{"text": "\\section{Discrete Fourier Transform}\n\nThe \\emph{Discrete Fourier Transform (DFT)} of a series of complex numbers $\\left\\{x_n\\right\\} = x_0, \\dots, x_{N-1}$\nare the $N$ numbers defined as\n\\begin{equation*}\n    X_k = \\symcal{F}\\left\\{x_n\\right\\}_k = \\frac{1}{\\sqrt{N}}\\sum_{n=0}^{N-1} x_n e^{-i\\frac{2\\pi}{N}n k}.\n\\end{equation*}\nAn example can be found in \\autoref{tab:ex}.\n% For intuitive understanding one can think of $X_k$ as the intensity of the frequency,\n% $\\nu =\\frac{\\omega}{2\\pi}= k / N$ in the signal.\n\n\\begin{table}\n    \\centering\n    \\caption{Example of the DFT of the sequence 4, 8, 15, 16, 23, 42.}\n    \\begin{tabular}{S[table-format=1.0] S[table-format=2.0] S[table-format=2.1] >{\\hspace{-1em}}c<{\\hspace{-.8em}} S[table-format=2.1]}\n        \\toprule\n        {$k$} & {$x_k$} & \\multicolumn{3}{c}{$X_k$}               \\\\\n        \\midrule\n        0     & 4       & 44.1                      & $+i$ & 0.0  \\\\\n        1     & 8       & -2.4                      & $+i$ & 14.8 \\\\\n        2     & 15      & -9.8                      & $+i$ & 9.1  \\\\\n        3     & 16      & -9.8                      & $+i$ & 0.0  \\\\\n        4     & 23      & -9.8                      & $-i$ & 9.1  \\\\\n        5     & 42      & -2.4                      & $-i$ & 14.8 \\\\\n        \\bottomrule\n    \\end{tabular}\n    \\label{tab:ex}\n\\end{table}\n\nFor a deeper, intuitive understanding let's take a step back and remember that Fourier\nfound that (nearly) any periodic function can be represented as a weighted sum of cosine and\nsine functions.\nThis does not only apply for continuous, but also discontinuous functions,\nsuch as a square wave.\nTo put it in a more mathematical way: The\n$L^2([0, T])$-space\\footnote{This means every complex-valued function defined on $[0, T]$, which's absolute square is integrable over $[0, T]$.}\nhas the orthonormal basis functions\n\\begin{equation*}\n    \\phi_k(x)=\\exp\\left({-2ikx\\frac{2\\pi}{T}}\\right) \\quad k\\in \\mathbb{Z},\n\\end{equation*}\nso any function $f(x)\\in L^{2}([0, T])$ can be written as\n\\begin{equation*}\n    f(x) \\equiv \\sum_{k=-\\infty}^{\\infty} \\underbrace{\\left< f, \\phi_k \\right>}_{a_k} \\phi_k(x)\n    = \\sum_{k=-\\infty}^{\\infty} {a_k} \\exp\\left({-2ikx\\frac{2\\pi}{T}}\\right)\n\\end{equation*}\nwhere $\\equiv$ means \"equals almost everywhere under the norm induced by the scalar product $\\left<\\cdot,\\cdot\\right>$\".\nThis sum is called a Fourier series.\nThe scalar product (inducing the norm) in this space is\n\\begin{equation*}\n    \\left< f, g\\right> = \\int_0^T f(x)g^*(x) \\dif x.\n\\end{equation*}\nThus, the Fourier coefficients $a_k$ are\n\\begin{equation*}\n    a_k = \\int_0^T f(x) \\exp\\left({ikx\\frac{2\\pi}{T}}\\right) \\dif x.\n\\end{equation*}\nThis is a very abstract definition, but if we get used to the math,\nthis only precises the findings of Fourier: A periodic function\n(our functions are restricted to $[0, T]$, but they can be thought of as being periodically continued everywhere else)\ncan be represented as a weighted (infinite) sum of sines and cosines (in our formulation hidden with the Euler identity in $e^{ix}$).\n\nIf we now have a function which is neither confined nor periodic, we can handwavely argue, that $T$ goes to infinity and\nthat we need a continues set of basis functions. This is a way of approaching the continuous \\emph{Fourier Transform (FT)}.\nThe idea of the FT is to transform the original function $f$ to another function $\\hat f$ without loosing any information and thus being\nable to transform the function back.\nThe transformation is similar to the definition of the Fourier coefficients\\footnote{Watch out for\n    different definitions of factors when comparing different sources}\n\\begin{equation*}\n    \\hat f(\\nu) = \\int_{-\\infty}^{\\infty} f(x) e^{-i2\\pi\\nu x} \\dif x.\n\\end{equation*}\nThe inverse Fourier transform is given by\\footnote{\n    To proof the corectness, expressing the Dirac $\\delta$-function as\n    $\\delta(x)~=~\\int_{-\\infty}^{\\infty} e^{-i2\\pi \\nu x} \\dif \\nu$ is helpful.\n}\n\\begin{equation*}\n    f(x) = \\int_{-\\infty}^{\\infty} \\hat f(\\nu) e^{i2\\pi\\nu x} \\dif \\nu.\n\\end{equation*}\nFor this the function $f: \\mathbb{R}\\to \\mathbb{C}$ only has to be absolutely integrable, so that\n$\\int_{\\mathbb{R}} \\abs{f(x)} \\dif x$ is defined.\nAgain $\\hat f(\\nu)$ can be thought of as the intensity of the frequency $\\nu$ in the function. That's\nwhy we name the domain $\\nu$ and $\\hat f$ is often called $f$ in frequency- or Fourier space.\nThis definition is easily extended to functions which take multi-dimensional input $f: \\mathbb{R}^n \\to \\mathbb{C}$\n\\begin{equation*}\n    \\hat f(\\vec \\nu) = \\int_{\\mathbb{R}^n} f(\\vec x) e^{-i2\\pi\\vec \\nu \\cdot \\vec x} \\dif{}^n x.\n\\end{equation*}\nAnd the inverse transform likewise.\n\nNow we can motivate the DFT: If we define a function (to be exact: a distribution) as\n\\begin{equation*}\n    f(x) = \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1} x_n\\ \\delta\\left(x-{n}\\right)\n\\end{equation*}\nthe DFT of the points is the FT of this function at the frequencies $k/N$\n\\begin{equation*}\n    \\begin{split}\n        \\hat f\\left(\\frac{k}{N}\\right) = \\int_{-\\infty}^{\\infty}  \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1}\n        x_n\\ \\delta\\left(x-{n}\\right) e^{-i2\\pi\\frac{k}{N} x} \\dif x\\\\\n        = \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1} x_n e^{-i2\\pi k \\frac{n}{N}}\n        = X_k.\n    \\end{split}\n\\end{equation*}\nAnd likewise, if we define the function\n\\begin{equation*}\n    F(\\nu) = \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1} X_n\\ \\delta\\left(\\nu-{n}\\right)\n\\end{equation*}\nit's inverse FT at $k/N$ is the inverse DFT of the points $X_k$\n\\begin{equation*}\n    \\begin{split}\n        \\hat F\\left(\\frac{k}{N}\\right)\n        = \\int_{-\\infty}^{\\infty}  \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1}\n        X_n\\ \\delta\\left(\\nu-{n}\\right) e^{i2\\pi\\frac{k}{N} \\nu} \\dif \\nu\\\\\n        = \\frac{1}{\\sqrt N} \\sum_{n=0}^{N-1} X_n e^{i2\\pi k \\frac{n}{N}}\n        = \\frac{1}{N} \\sum_{n,m=0}^{N-1}\n        x_m e^{-i2\\pi \\frac{n}{N}(m-k)}\\\\\n        =  \\sum_{m=0}^{N-1}\n        x_m\\delta_{m,k} = x_k.\n    \\end{split}\n\\end{equation*}\nWhere we have proofed the relation using the geometric series\n\\begin{equation*}\n    \\frac{1}{N}\n    \\sum_{n=0}^{N-1}\n    e^{-i2\\pi \\frac{n}{N}(m-k)}=\n    \\begin{cases}\n        \\frac{1-e^{-i2\\pi (m-k)}}{1-e^{-i2\\pi\\frac{m-k}{N}}} = 0 & \\forall m\\neq k \\\\\n        1                                                        & \\forall m=k\n    \\end{cases}\n    = \\delta_{m,k}.\n\\end{equation*}\nThe definition of the function might seem abstract at first glance, but it is nothing\nmore than a more mathematical way of expressing, that we only have $N$ samples of\nan unknown functions at these points.\nThe normalization factor of $1/\\sqrt N$ is chosen so the inverse transform does not rescale\nthe points.\n\nAs with the FT, the DFT is easily enlarged to more dimensions\n\\begin{equation}\n    X_{k,l} = \\frac{1}{\\sqrt{N_1N_2}}\\sum_{n=0}^{N_1-1}\\sum_{m=0}^{N_2-1}x_{n,m} \\ e^{-i{2\\pi}\\ \\left(\\!\\frac{kn}{N_1}+\\frac{ml}{N_2}\\right)}\n    \\label{eqn:dft2d}\n\\end{equation}\nand the inverse\n\\begin{equation}\n    x_{k,l} = \\frac{1}{\\sqrt{N_1N_2}}\\sum_{n=0}^{N_1-1}\\sum_{m=0}^{N_2-1} X_{n,m} \\ e^{i{2\\pi}\\ \\left(\\!\\frac{kn}{N_1}+\\frac{ml}{N_2}\\right)}.\n    \\label{eqn:idft2d}\n\\end{equation}\nI chose the three-dimensional example here, since we are going to look at images with a color channel, which is three-dimensional data.\nOther dimensionality are analogous.\n\n\\subsection{Real Numbered Input Data}\nAn image will only contain real numbered input values. This yields the following symmetry in the transformation\n\\begin{equation}\n    X_{l,m,n} = X^*_{N_1-l,N_2-m,N_3-m}.\n    \\label{eqn:realFSymmetry}\n\\end{equation}\nOn the one hand, this is a very useful result: If we transform an image consisting of $N$ real numbers,\nwe do not want to end up with $N$ complex (or equivalently $2N$ real) numbers and thus having more numbers than we started with.\nOn the other hand the problem of displaying the transformed image still remains: we have to visualize a two-dimensional array of complex numbers.\nUsually we display the magnitude of the transformed image and its phase (also called the argument) separately.\n\nSince it seems quite artificial to introduce complex numbers in a problem only consisting of real numbers,\nfor image compression usually a very closely related transform is used, the \\emph{Discrete Cosine Transfrom (DCT)}.\nIt transforms $N$ real-valued input numbers to $N$ real-valued output numbers.\nThe transform is given by\n\\begin{equation}\n    \\begin{split}\n        X_k = \\symcal{C}\\left(\\vec x\\right)_k = \\frac{2c_k}{\\sqrt N}\\sum_{n=0}^{N-1}x_n \\cos \\left(\\frac{\\pi\\left(2n+1\\right)k}{2N} \\right)\n        \\\\\n        \\text{where }\n        c_k =\n        \\begin{cases}\n            \\frac{1}{\\sqrt{2}} \\quad & k=0           \\\\\n            1                        & \\text{ else }\n        \\end{cases}\n    \\end{split}\n\\end{equation}\nand it's inverse by\n\\begin{equation}\n    x_k = \\symcal{C}^{-1}\\left(\\vec X\\right)_k\n    =\\frac{1}{\\sqrt N}\\sum_{n=1}^{N-1}c_n X_n \\cos \\left(\\frac{\\pi(2k+1)}{2N}n\\right).\n\\end{equation}\n\\cite{DCT}\nThe DCT can be calculated using the DFT. An efficient algorithm for this from \\cite{DCTUFFT} first reorders the points to\n\\begin{equation*}\n    \\begin{rcases}\n        x'_k       & = x_{2k}  \\\\\n        x'_{N-1-k} & =x_{2k+1}\n    \\end{rcases}\n    k=0,1, \\dots, \\frac{N}{2}-1\n\\end{equation*}\nto obtain the relation\n\\begin{equation*}\n    \\symcal{C}\\left(\\vec x\\right)_k = X_k =2 c_k\n    \\Re e^{i\\pi\\frac{k}{2N}}\\symcal{F}^{-1}\\left(\\vec x'\\right)_k\n\\end{equation*}\nand it's inverse\n\\begin{equation*}\n    \\begin{split}\n        \\symcal{C}^{-1}\\left(\\vec X\\right)_{2k} =& x_{2k} =\n        \\Re \\symcal{F}^{-1}\\left\\{c_lX_le^{i\\frac{\\pi l}{2N}}\\right\\}_k\n        \\\\\n        &x_{2k+1} = x_{2(N-1-k)}.\n    \\end{split}\n\\end{equation*}\nNote, that we only need to calculate half of the Fourier coefficients, if we make use of\nEquation \\eqref{eqn:realFSymmetry}.\n\n\\section{The Fast Fourier Transform}\nOur goal is to find an efficient algorithm for our numerical implementation of\nthe discrete Fourier transform.\nFirstly, we notice that the multidimensional DFT is\nseparable into multiple one dimensional DFTs, performed one after another\n\\begin{equation*}\n    X_{l,m} = \\symcal{F} \\left\\{\\symcal{F}\\{(x_i)_j\\}_m\\right\\}_l.\n\\end{equation*}\nThus, we will concentrate on optimizing the one dimensional DFT.\n\nWe can see that the direct implementation of the DFT is nothing more than a matrix-multiplication\n\\footnote{In fact, it is possible to interpret the DFT as a curve fitting problem with the design matrix $A_{m,n}=e^{-i2\\pi\\frac{mn}{N}} / \\sqrt{N}$.}.\nAs that, the computational complexity of the bare DFT implementation scales with $\\symcal{O}(N^2)$.\nBut the concrete form of the transform allows us to get down to $\\symcal{O}(N\\log N)$.\nFrom this scaling law, we can already guess, that we will use a divide-and-conquer algorithm.\nThe basic idea is to express the Fourier transform of $N$ points in multiple smaller Fourier transforms, and thus dividing and conquering.\nLet's assume $N$ is even and observe that\n\\begin{equation*}\n    \\begin{split}\n        X_k &= \\frac{1}{\\sqrt{N}}\\sum_{n=0}^{N-1} x_n e^{-i\\frac{2\\pi}{N}n k}\\\\\n        &=\\frac{1}{\\sqrt N}\n        \\sum_{n=0}^{N/2-1} x_{2n} e^{-i\\frac{2\\pi}{N}2n k}+\n        \\frac{1}{\\sqrt N}\n        \\sum_{n=0}^{N/2-1} x_{2n+1} e^{-i\\frac{2\\pi}{N}(2n+1) k}\\\\\n        &= \\frac{1}{\\sqrt 2}\n        \\symcal{F}\\left\\{x_{2n}\\right\\}_k\n        +\\frac{1}{\\sqrt 2}\n        e^{-i\\frac{2\\pi}{N}k}\\symcal{F}\\left\\{x_{2n+1}\\right\\}_k.\n    \\end{split}\n\\end{equation*}\nThe last expression is only defined up to $k=N/2$, but for the other half we get\n\\begin{equation*}\n    X_{k+\\frac{N}{2}}=\\frac{1}{\\sqrt 2}\n    \\symcal{F}\\left\\{x_{2n}\\right\\}_k\n    -\\frac{1}{\\sqrt 2}\n    e^{-i\\frac{2\\pi}{N}k}\\symcal{F}\\left\\{x_{2n+1}\\right\\}_k.\n\\end{equation*}\nHere we have expressed the DFT of $N$ points as the DFT of the $N/2$ even points and $N/2$ odd points.\nIf now count the calculation steps, we have two times the DFT of $N/2$ points, so in total $2\\times N^2/2^2=N^2/2$ steps,\nreducing the original complexity.\nThis is called the \\emph{Fast Fourier Transform (FFT)}, to be precise the radix-2-decimation-in-time Cooley-Tukey algorithm.\nIt was originally discovered by Gauss, but due to the lack of computers at his time, it was not a very known result.\nCooley and Tukey rediscovered the algorithm 160 years later in the sixties and popularized it.\n\nWe can similarly express the inverse DFT by noticing\n\\begin{equation*}\n    \\symcal{F}^{-1}\\left\\{x_n\\right\\}\n    =\\symcal{F}\\left\\{x_{N-n}\\right\\}\n    =\\symcal{F}\\left\\{x_{n}^*\\right\\}^*.\n\\end{equation*}\nThus, we only need the implementation of the DFT to also get the inverse DFT.\n\nThe complete divide and conquer in this form only works for $N$, which are powers of two.\nBut, it is possible to generalize this to any composite number of the form $N=N_1N_2$.\nIn that case we will combine $N_1$ smaller DFTs with a DFT of size $N_2$\\footnote{Note that the combination rule for the even $N$ case can be understood as a DFT of two points.}.\nFor a full description see \\cite{CTAlg}.\nNote that this yields problems if our input data has prime-number length. For this special case there\nexists an algorithm allowing the DFT of prime-number-sized points in $N\\log N$ time, using group-theory\nof prime-numbered modulo groups.\nThe algorithm is called \\emph{Rader's algorithm} and a short overview can be found here \\cite{radersalg}\n\n\\subsection{Code}\nThe code which produced the results is written in \\texttt{C++} and can be found here\\cite{githubfft}.\nNo numerical algorithms outside the standard template library were used, which\nmeans I implemented a version of the FFT and DCT myself.\nThe code makes full use of every prime factor of $2$ in the number of transformed points,\nbut not the full powered Tukey-Cooley algorithm, since an efficient implementation of that\nrequires complicated reordering of the input numbers.\nThe used algorithm can handle arbitrary length input data, which makes it\nmore general than most implementations found online\\footnote{One implementation I took some inspiration from is for example \\cite{fftoreil}.}, since they are usually only implemented\nfor powers of 2.\nNonetheless, the implementation should be viewed more as a toy-implementation for testing\nand can't compete with industry-grade optimized algorithms\\cite{fftw}.\nThe FFT, DCT and their respective inverses where implemented in a generic fashion,\nso that they can be used on any data structure supporting the square-bracket indexing\noperator. Thus, it can be used on raw pointers as well as on higher level structures\nlike vectors.\n\nThe images in the Fourier space were represented by complex matrices from the \\texttt{Eigen}\nlibrary.\nTo handle images, as well as image-input and -output the Boost Generic Image Library \\texttt{Boost::GIL}\\cite{boostgil} was used.\n\n\\section{Applications}\nOne of the most notable places the Fourier transform appears in physics is the\nFraunhofer-diffraction equation. In the far-field approximation, the diffraction image\nof an incoming planar wave is proportional to the 2D-Fourier transform of the aperture\n\\begin{equation}\n    A(x, y, z) \\propto \\iint_{\\symup{Aperture}}\\hspace{-3em} e^{-i\\frac{2\\pi}{\\lambda z}(x'x+y'y)} \\dif x' \\dif y'.\n    \\label{eqn:fraunhofer}\n\\end{equation}\nThus, if we use a DFT of an image resembling an aperture, we can numerically approximate the diffraction image.\nEvery photograph taken is slightly distorted through diffraction effects through the aperture.\nIn space-telescopes for example the reflection mirror needs to be attached to the rest of the satellite,\nand the light from stars is diffracted at the attached rods, which creates the typical 4 or 6-fold diffraction\nsymmetry of star-pictures.\n\nAnother application is the lossy compression of images, sound and other media types.\nThis is what (among other tricks) the \\texttt{.jpg} image format does.\n\nImages can also be enhanced with Fourier transform. Assume for example we take a photograph through an insect-net.\nWe will have periodic information overlaying the picture. This can be easily removed in Fourier space.\nGenerally, a lot of interesting edits can be performed in Fourier space, having complex outcome in real space.\nAnd by removing high-frequencies the sharpness can be increased and by doing the inverse the image will be blurred.\n\n\n", "meta": {"hexsha": "5bb4d5ae94a14bcb50f58a390e7cb155b8d78d73", "size": 16320, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project08-ImageFourierTransform/report/introduction.tex", "max_stars_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_stars_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project08-ImageFourierTransform/report/introduction.tex", "max_issues_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_issues_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project08-ImageFourierTransform/report/introduction.tex", "max_forks_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_forks_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_forks_repo_licenses": ["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.6451612903, "max_line_length": 182, "alphanum_fraction": 0.6784926471, "num_tokens": 5198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8652240860523327, "lm_q1q2_score": 0.7956968647220276}}
{"text": "\\chapter{Math}\n\n\\section{Functions}\n\\rih{Equals.} Requirements for equals\n\\begin{enumerate}\n\\item Reflexive\n\\item Symmetric\n\\item Transitive\n\\item Non-null\n\\end{enumerate}\n\\rih{Compare.} Requirements for compares (total order):\n\\begin{enumerate}\n\\item Antisymmetry\n\\item Transitivity\n\\item Totality\n\\end{enumerate}\n\n\\section{Prime Numbers}\n\\subsection{Sieve of Eratosthenes}\n\\subsubsection{Basics}\nTo find all the prime numbers less than or equal to a given integer n by Eratosthenes' method:\n\\begin{enumerate}\n\\item Create a list of consecutive integers from 2 through n: (2, 3, 4, ..., n).\n\\item Initially, let $p$ equal 2, the first prime number.\n\\item Starting from $p$, enumerate its multiples by counting to n in increments of $p$, and mark them in the list (these will be $2p$, $3p$, $4p$, ... ; the $p$ itself should not be marked).\n\\item Find the first number greater than $p$ in the list that is not marked. If there was no such number, stop. Otherwise, let $p$ now equal this new number (which is the next prime), and repeat from step 3.\n\\end{enumerate}\n\nWhen the algorithm terminates, the numbers remaining not marked in the list are all the primes below $n$.\n\n\\subsubsection{Refinements}\nThe main idea here is that every value for $p$ is prime, because we have already marked all the multiples of the numbers less than $p$. Note that some of the numbers being marked may have already been marked earlier (e.g., 15 will be marked both for 3 and 5).\n\nAs a refinement, it is sufficient to mark the numbers in step 3 starting from $p^2$, because all the smaller multiples of $p$ will have already been marked at that point by the previous smaller prime factor other than $p$. From $p^2$, $p$ becomes the smaller prime factor of a composite number. This means that the algorithm is allowed to terminate in step 4 when $p^2$ is greater than n.\n\nAnother refinement is to initially list odd numbers only, (3, 5, ..., n), and count in increments of $2p$ in step 3, thus marking only odd multiples of $p$. This actually appears in the original algorithm. This can be generalized with wheel factorization, forming the initial list only from numbers coprime with the first few primes and not just from odds (i.e., numbers coprime with 2), and counting in the correspondingly adjusted increments so that only such multiples of $p$ are generated that are coprime with those small primes, in the first place.\n\nTo summarized, the refinements include:\n\\begin{enumerate}\n\\item Starting from $p^2$.\n\\item Preprocessing even numbers and then only process odd numbers; thus the increment becomes $2p$.\n\\end{enumerate}}\n\n\\subsubsection{code}\n\\begin{python}\ndef countPrimes(n):\n    \"\"\"\n    Find prime using Sieve's algorithm\n    :type n: int\n    :rtype: int\n    \"\"\"\n    if n < 3:\n        return 0\n\n    is_prime = [True for _ in xrange(n)]\n    is_prime[0], is_prime[1] = False, False\n    for i in xrange(2, int(math.sqrt(n))+1):\n        if is_prime[i]:\n            for j in xrange(i*i, n, i):\n                is_prime[j] = False\n\n    return is_prime.count(True)\n\\end{python}\n\n\\subsection{Factorization}\nBacktracking: Section-\\ref{factorization}.\n\n\\section{Median}\n\\subsection{Basic DualHeap}\nDualHeap to keep track the median when a method to find median is called multiple times. \\begin{python}\nimport heapq\n\nclass DualHeap(object):\n  def __init__(self):\n    self.min_h = []\n    self.max_h = []  # need to negate the value \n\n  def insert(self, num):\n    if not self.min_h or num > self.min_h[0]:\n      heapq.heappush(self.min_h, num)\n    else:\n      heapq.heappush(self.max_h, -num)\n    self.balance()\n\n  def balance(self):\n    l1 = len(self.min_h)\n    l2 = len(self.max_h)\n    if l1-l2 > 1:\n      heapq.heappush(self.max_h, \n                     -heapq.heappop(self.min_h))\n      self.balance()\n    elif l2-l1 > 1:\n      heapq.heappush(self.min_h, \n                     -heapq.heappop(self.max_h))\n      self.balance()\n    return\n\n  def get_median(self):\n    \"\"\"Straightforward\"\"\"\n\\end{python}\n\n\\subsection{DualHeap with Lazy Deletion}\\label{dh_lazy_del}\nClues:\n\\begin{enumerate}\n\\item Wrap the value and wrap the heap\n\\item When delete a value, mark it with tombstone. \n\\item When negate the value, only change the value, not the reference. \n\\item When heap pop, clean the op first. \n\\end{enumerate}\n\\begin{python}\nimport heapq\nfrom collections import defaultdict\n\n\nclass Value(object):\n    def __init__(self, val):\n        self.val = val\n        self.deleted = False\n\n    def __neg__(self):\n        \"\"\"negate without creating new instance\"\"\"\n        self.val = -self.val\n        return self\n\n    def __cmp__(self, other):\n        assert isinstance(other, Value)\n        return self.val - other.val\n\n    def __repr__(self):\n        return repr(self.val)\n\n\nclass Heap(object):\n    def __init__(self):\n        self.h = []\n        self.len = 0\n\n    def push(self, item):\n        heapq.heappush(self.h, item)\n        self.len += 1\n\n    def pop(self):\n        self._clean_top()\n        self.len -= 1\n        return heapq.heappop(self.h)\n\n    def remove(self, item):\n        \"\"\"lazy delete\"\"\"\n        item.deleted = True\n        self.len -= 1\n\n    def __len__(self):\n        return self.len\n\n    def _clean_top(self):\n        while self.h and self.h[0].deleted:\n            heapq.heappop(self.h)\n\n    def peek(self):\n        self._clean_top()\n        return self.h[0]\n\n\nclass DualHeap(object):\n    def __init__(self):\n        self.min_h = Heap()  # represent right side\n        self.max_h = Heap()  # represent left side\n    # others similar as the previous section's above DualHeap\n\\end{python}\n", "meta": {"hexsha": "00d7ef75f2d83dfc599b05ca668f6e1208a603bf", "size": 5582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterMath.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": "chapterMath.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": "chapterMath.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": 32.8352941176, "max_line_length": 554, "alphanum_fraction": 0.682551057, "num_tokens": 1445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.9032942125614059, "lm_q1q2_score": 0.7956189114577837}}
{"text": "\\section{Generating Functions}\n\nGenerating functions are functions that encode sequences of numbers as the coefficients of power series. One example are the moment generating functions in probability theory, though they are generally extremely useful in combinatorics problems and, almost equivalently, discrete probability problems. \n\n\\citeasnoun{bogart2004combinatorics} approaches the concept in terms of \\textit{Picture Functions}. For each element $s\\in S$, there is a picture function $P(s)$, so that, for example, the multiset $\\{1,1,2\\}$ can be written as $P(1)^1 P(2)$. Collections of combinations can be rewritten in terms of sums and products, which enables factorization and overall easier accounting. Combinations with particular properties can be filtered by looking at exponents. \n\nThe picture function enables writing down combinations of elements as an enumerating function $E_P(s)$. For example, the enumerating function for all multisets that include either one or two times some element $a$ and between zero and two times some element $b$ is written:\n\n\\begin{equation}\n\\begin{array}{rl}\nE_P(s) &= P(a)+ P(a)^2 + P(a)P(b) + P(a)^2P(b) +  + P(a)P(b)^2 + P(a)^2P(b)^2\\\\\n&\\left(P(a) + P(a)^2\\right)\\left(1 + P(b) + P(b)^2\\right)\n\\end{array}\n\\end{equation}\n\nGenerating functions get much more complicated. \\citeasnoun{wilf2013generating} is a good resource.\n\n\n\\subsection{Example: Binomial Coefficients}\n\nConsider the case of a collection of $n$ indistinguishable objects $s$, and write $P(s) = x$. Then the enumerator for selecting any subset of those $n$ objects is given by: \n\n\\begin{equation}\nE_P(s) = \\prod_i^n (x^0+x^1) = (1+x)^n = \\sum_i^n {n \\choose i}x^i\n\\end{equation}\n\nWhere each term $(x^0 + x^1)$ corresponds to the two options of either excluding a particular element ($x^0$) or including a particular element ($x^1$). The exponent of the expanded product encodes how many objects were included into a particular subset. This is one way of \"proving\" the binomial coefficients, and one can says $(1_x)^n$ is the generating function for the binomial coefficients ${n \\choose i}$. \n\n\n\\subsection{Example: Basket of Goods}\n\nAn apple costs $20c$, a pear costs $25c$ and a banana costs $30c$. How many different fruit baskets can be bought for $100c$?\n\nBy replacing the picture function $P(s)$ with $x$, it was possible to identify subsets of $n$ objects by looking at the exponent of $x^n$ in the enumerating function. In this case, the exponent is supposed to show the price. This can be done by writing $P(apple) = x^{20}, P(pear) = x^{25}$ and $P(banana) = x^{30}$. \n\n\\begin{equation}\nE_P(s) = \\left( \\sum_{i=0}^5 x^{20} \\right)\\left( \\sum_{i=0}^4 x^{25} \\right)\\left( \\sum_{i=0}^3 x^{30} \\right)\n\\end{equation}\n\nWhich results in some power series of the form:\n\n\\begin{equation}\nE_P(s) = 1x^0 + 1x^{20} + 1x^{25} + 1x^{30} + 1x^{40} +... + 2x^{60} + ... + 1x^{290}\n\\end{equation}\n\nTo obtain the number of combinations that correspond to a cost of exactly $100c$, one can apply the operator $\\frac{1}{n!}\\frac{d^n}{dx^n}$ and set $x=0$ to obtain the desired term. This is what is done with moment generating functions in statistics. \n\nBut actually it is easier to think through what the coefficients will be so that:\n\n\\begin{equation}\n\\sum_{l=0}^{n+m+h}d_l x^l = \\left(\\sum_{i=0}^n a_i x^i\\right)\\left(\\sum_{j=0}^m b_j x^j\\right)\\left(\\sum_{k=0}^h c_k x^k\\right)\n\\end{equation}\n\n\\begin{equation}\nd_l = \\sum_{\\begin{array}{c}i,j,k\\\\i+j+k=l\\end{array}} a_i b_j c_k\n\\end{equation}\n\nIf $a_i = b_j = c_k = 1$, then:\n\n\\begin{equation}\nd_l = \\sum_{\\begin{array}{c}i,j,k\\\\i+j+k=l\\end{array}} 1 = {l + 3 - 1 \\choose l}\n\\end{equation}\n\nWhich is the number of all multisets of size $l$ and 3 classes. \n\nIn this case, however, the coefficients are equal to 1 only for $i=a20$, $j=b25$, and $k=c30$ for $a,b,c \\in \\mathbb{N}_0$, and zero otherwise, so that there are 4 combinations of $a,b,c$ for which $20a+25b+30c=100$. Hence, $d_{100} = 4$ for the basket of goods above.\n\nThe sum can also be rewritten:\n\n\\begin{equation}\nd_l = \\sum^l_{i=0}\\sum^{l-i}_{j=0} a_i b_j c_{l-i-j}\n\\end{equation}\n\n\nOf course, this is the discrete version of a convolution. So, it is no surprise that the addition of random variables winds up being a convolution.\n\n\\subsection{Example: Dice}\n\nHow many ways are there for $n$ dice with $k$ faces to show $s$ eyes?\n\n\\begin{equation}\nE_P = \\left(\\sum_{i=0}^\\infty a_i x^i\\right)^n = \\sum_{i=0}^{\\infty}d_i x^i\n\\end{equation}\n\nWhere $a_i = 1\\ \\forall i\\in(1,k)$ and $a_i = 0$ otherwise.\n\n\\begin{equation}\nE_P = \\left(\\sum_{i=1}^k x^i\\right)^n = \\left(x(1-x^k)\\sum_{i=0}^\\infty x^i\\right)^n = x^n\\left(\\frac{1-x^k}{1-x}\\right)^n = x^n \\left(\\sum_{i=0}^n (-1)^i {n \\choose i} x^{ik}\\right)\\left(\\sum_{j=0}^{\\infty} (-1)^j {-n \\choose j} x^j\\right)\n\\end{equation}\n\nThe coefficient for $x^s$ is given the sum:\n\n\\begin{equation}\nd_s = \\sum_{ki+j=s-n} (-1)^{i+j}{n \\choose i}{-n \\choose j}\\\\\ni \\in [0,n] \\\\\nj \\in [0,\\infty]\n\\end{equation}\n\nWhere the indices $i$ and $j$ satisfy $ki+j = s-n$. For example, for $s=7$, $n=2$ and $k=6$:\n\n\\begin{equation}\n6i+j = 7-2 = 5s\n\\end{equation}\n\nHolds for $i=0, j=5$:\n\n\\begin{equation}\nd_s = (-1)^5 {2 \\choose 0}{-2 \\choose 5} = (-1)^{10} 1 {2+5-1 \\choose 5} = {6 \\choose 5} = \\frac{6!}{5!1!} = 6\n\\label{eq:d6}\n\\end{equation}\n\nIndeed, there are 6 ways for two d6 to add to 7:\n\n\\begin{equation}\n[6,1],[5,2],[4,3],[3,4],[2,5],[1,6]\n\\end{equation}\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.5]{d6throw.png}\n\\includegraphics[scale=0.5]{d20throw.png}\n\\caption{Probability of the sum of 6-sided and 20-sided dice, calculated with Eqn. \\ref{eq:d6}. Note that these are simply the convolutions of $n=1,2,3,...$ square waves, which rapidly adopts the shape of a Bell curve.}\n\\end{figure}\n", "meta": {"hexsha": "e594dfbdd9c0c9ec89eb026daf4f06d4dfda4171", "size": 5757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/comb_generatingfuncs.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/comb_generatingfuncs.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/comb_generatingfuncs.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": 46.056, "max_line_length": 459, "alphanum_fraction": 0.6923745006, "num_tokens": 1959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.8807970795424087, "lm_q1q2_score": 0.7956189015253721}}
{"text": "\\subsection{Dynamic programming}\n$$\na = \\begin{bmatrix}\n\t\\dot{x_1}\\\\\n\t\\dot{x_2}\n\\end{bmatrix} = \\begin{bmatrix}\n\tx_2\\\\\n\t-0.4x_1 -0.2x_2^2\n\\end{bmatrix} + \\begin{bmatrix}\n\t0\\\\\n\t1\n\\end{bmatrix}u\n$$\n$$\n\\begin{bmatrix}\n\tx_1(k+1)\\\\\n\tx_2(k+1)\n\\end{bmatrix} = \\begin{bmatrix}\n\tx_2(k)\\\\\n\t-0.4x_1(k) -0.2x_2^2(k) + u(k)\n\\end{bmatrix} \\Delta t + \\begin{bmatrix}\n\tx_1(k)\\\\\n\tx_2(k)\n\\end{bmatrix}\n$$\nIn MATLAB Code, Control law will save in .mat file and we can use for another initial condition very fast without so much processing.\n\\begin{figure}[H]\n\t\\caption{Dynamic Programming}\n\t\\centering\n\t\\includegraphics[width=11.5cm]{../Figure/Q4/DP.png}\n\\end{figure}", "meta": {"hexsha": "fb5866cb07e18d56cc8620892fa731a5aba2f264", "size": 647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW3/Report/Q4/Q4_c.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/Q4/Q4_c.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/Q4/Q4_c.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": 20.8709677419, "max_line_length": 133, "alphanum_fraction": 0.6692426584, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810407096791, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.795548045912258}}
{"text": "\\lab{Monte Carlo Integration}{Monte Carlo Integration}\n\\objective{Implement Monte Carlo integration to estimate integrals. Use Monte Carlo Integration to calculate the integral of the joint normal distribution.}\n\nSome multivariable integrals which are critical in applications are impossible to evaluate symbolically.\nFor example, the integral of the joint normal distribution\n\\[\n\\int_{\\Omega} \\frac{1}{\\sqrt{(2 \\pi)^k}} e^{- \\frac{\\bold{x}^T\\bold{x}}{2}}\n\\]\nis ubiquitous in statistics.\nHowever, the integrand does not have a symbolic antiderivative.\nThis means we must use numerical methods to evaluate this integral. The standard technique for numerically evaluating multivariable integrals is \\emph{Monte Carlo Integration}. In the next lab, we will approximate this integral using a modified version of Monte Carlo Integration. In this lab, we address the basics of Monte Carlo Integration.\n\nMonte Carlo integration is radically different from techniques like Simpson's rule. Whereas Simpson's rule is purely computational and deterministic, Monte Carlo integration uses randomly chosen points  in the domain to calculate the integral.\nAlthough it converges slowly, Monte Carlo integration is frequently used to evaluate multivariable integrals because the higher-dimensional analogs of methods like Simpson's rule are extremely inefficient.\n\n\\section*{A Motivating Example} % =============================================\n\nSuppose we want to numerically compute the area of a circle of radius 1.\nFrom analytic methods, we know the answer is $\\pi$.\nEmpirically, we can estimate the area by randomly choosing points in a $2 \\times 2$ square.\nThe percentage of points that land in the inscribed circle, times the area of the square, should approximately equal the area of the circle (see Figure \\ref{fig:MCCircle}).\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{figures/MC.png}\n\\caption{Finding the area of a circle using random points}\n\\label{fig:MCCircle}\n\\end{figure}\n\nWe do this in NumPy as follows. First generate 500 random points in the square $[0,1] \\times [0,1]$.\n\\begin{lstlisting}\n>>> N = 500 # Number of sample points\n>>> points = np.random.rand(2, N)\n\\end{lstlisting}\nWe rescale and shift these points to be uniformly distributed in $[-1,1]\\times[-1,1]$.\n\\begin{lstlisting}\n>>> points = points*2-1\n\\end{lstlisting}\nNext we determine the number of points in the unit circle.\nWe compute the Euclidean distance from the origin for each point, then count the points that are within a distance of 1 from the origin.\n%The function \\li{np.hypot(a, b)} returns the norm of the vector $(a, b)$ where $a$ and $b$ are the $x$- and $y$-components, respectively.\n\\begin{lstlisting}\n>>> # Compute the distance from the origin for each point\n>>> pointsDistances = np.linalg.norm(points,axis=0)\n>>> # Count how many are less than 1\n>>> numInCircle = np.count_nonzero(pointsDistances < 1)\n\\end{lstlisting}\nThe fraction of points inside the circle is \\li{numInCircle} divided by \\li{N}. By multiplying this fraction by the square's area, we can estimate the area of the circle.\n\\begin{lstlisting}\n>>> circleArea = 4.*(numInCircle/N)\n>>> circleArea\n3.024\n\\end{lstlisting}\nThis differs from $\\pi$ by about 0.117.\n\n\\begin{problem}\n\\label{prob:sphere}\nWrite a function that estimates the volume of the unit sphere. Your function should have a keyword argument \\li{N} that defaults to $10^5$. Your function should draw \\li{N} points uniformly from $[-1,1]\\times[-1,1]\\times[-1,1]$ to make your estimate. The true volume is $\\frac{4}{3}\\pi \\approx 4.189$.\n\\end{problem}\n\n%This demonstrates the main idea of Monte Carlo integration: that random points can be used to estimate a volume.\n%In the next section we will present the generalized method of Monte Carlo integration, which can be used to integrate any function.\n\n\\section*{Monte Carlo Integration} % ==========================================\n\nIn the examples above, we drew a bounding box around a volume, then used random points drawn from the box to estimate that volume.\nThis is easy and intuitive when the volume is a circle or sphere.\nBut it's hard to generalize this to any arbitrary integral - in order to draw the box, we have to already know something about the volume we are estimating.\nInstead, given an arbitrary function $f(x) : \\mathbb{R}^n \\mapsto \\mathbb{R} $ and a region $\\Omega \\subset \\mathbb{R}^n$ in the domain of $f$, we would like to use random points drawn from $\\Omega$ to estimate the integral\n$\\int_\\Omega f(x)\\:dV$,\n\\textit{without} having to specify a bounding box around the volume of integration.\n\nWe can estimate this integral using the approximation.\n\\begin{equation}\\label{equ:mc_eq}\n\\int_\\Omega f(x)\\:dV \\approx V(\\Omega) \\frac{1}{N} \\sum_{i=1}^N f(x_i)\n\\end{equation}\nwhere $x_i$ are uniformly distributed random points in $\\Omega$ and $V(\\Omega)$ is the volume of $\\Omega$.\nThis is the generalized formula for Monte Carlo integration.\n\nThe intuition behind \\eqref{equ:mc_eq} is that $\\frac{1}{N} \\sum_{i=1}^N f(x_i)$ approximates the average value of $f$ on $\\Omega$.\nWe multiply this (approximate) average value by the volume of $\\Omega$ to get the (approximate) integral of $f$ on $\\Omega$.\n\nFor further intuition, compare \\eqref{equ:mc_eq} to the Average Value Theorem from single-variable calculus.\nBy the Average Value Theorem, the average value of $f(x) : \\mathbb{R} \\mapsto \\mathbb{R} $ on ${[a,b]}$ is given by\n\\begin{equation}\\label{equ:avg_value_eq}\nf_{avg} = \\frac{1}{b-a}\\int_a^b f(x)\\:dx.\n\\end{equation}\n\nIf we let $\\Omega = {[a,b]}$ in \\eqref{equ:avg_value_eq} (noting that $V(\\Omega) = b - a$) and replace $f_{avg}$ with the approximation $\\frac{1}{N} \\sum_{i=1}^N f(x_i)$, then we get precisely the Monte Carlo integration formula in Equation \\eqref{equ:mc_eq}!\n\nAs it turns out, we can refactor the circle-area problem slightly so that it uses Equation \\eqref{equ:mc_eq}.\nLet $f$ be defined by\n$$f(x,y) = \\begin{cases} 1 &\\mbox{ if $(x$,$y)$ is in the unit circle} \\\\ 0 &\\mbox{ otherwise} \\end{cases}$$\nand let $\\Omega =   {[-1,1]} \\times {[-1,1]}$.\nThe area of the circle is given by\n$\\int_\\Omega f(x)\\:dV$,\nwhich we can estimate with the Monte Carlo integration formula:\n\\[\n\\mbox{Area of unit circle } \\approx V(\\Omega) \\frac{1}{N} \\sum_{i=1}^N f(x_i) = \\frac{4}{N} \\sum_{i=1}^N f(x_i).\n\\]\n\nTo summarize, we have the following steps to estimate the integral of any function $f$ over a region $\\Omega$ in the domain of $f$:\n\\begin{enumerate}\n\\item Draw $N$ random points uniformly distributed in $\\Omega$.\n\\item Find the image of each point under $f$, and take the average of these images.\n\\item Multiply by the volume of $\\Omega$.\n\\end{enumerate}\n\n\\begin{comment}\n% Part of the previous explanation of Monte Carlo integration, which was reworked above.\nYou can calculate the area of the unit circle with the following integration problem:\n\\[\n\\mbox{Area of unit circle } = \\int_{[-1,1]\\times[-1,1]} f(x,y) dA\n\\]\nwhere\n\\begin{equation}\\label{equ:mc_func}\nf(x,y) = \\begin{cases} 1 &\\mbox{ if $(x$,$y)$ is in the unit circle} \\\\ 0 &\\mbox{ otherwise.} \\end{cases}\n\\end{equation}\n%$\n\nThis method essentially draws a box around the function to estimate the integral. This works fine if we know the bounds of the function. However, if we don't know the bounds of the function we don't know the dimensions of the box much be to encapsulate the function.\n\nLuckily, we can still use a random-points method as above to approximate any integral, even if we don't know the bounds. Suppose we wish to evaluate\n\\[\n\\int_\\Omega f(x)\\:dV.\n\\]\nWe can approximate this integral using the formula\n\\begin{equation}\\label{equ:mc_eq}\n\\int_\\Omega f(x)\\:dV \\approx V(\\Omega) \\frac{1}{N} \\sum_{i=1}^N f(x_i),\n\\end{equation}\nwhere $x_i$ are uniformly distributed random vectors in $\\Omega$ and $V(\\Omega)$ is the volume of $\\Omega$.\nThis is the formula for Monte Carlo integration.\n\nIn our example, $\\Omega$ was the box $[-1,1] \\times [-1,1]$ and $f$ was the function defined in \\eqref{equ:mc_func}.\nThen $\\sum_{i=1}^N f(x_i)$ is the number of points in the unit circle, $N$ is the total number of points, and \\eqref{equ:mc_eq} is the same as the formula we derived previously.\n\nThe intuition behind \\eqref{equ:mc_eq} is that $\\frac{1}{N} \\sum_{i=1}^N f(x_i)$ approximates the average value of $f$ on $\\Omega$.\nWe multiply this (approximate) average value by the volume of $\\Omega$ to get the (approximate) integral of $f$ on $\\Omega$.\n\nAs a 1-dimensional example consider the integral\n\\[\n\\int_0^1 x\\,dx \\approx (1-0)\\frac{1}{N} \\sum_{i=1}^N x_i=\\frac{1}{N} \\sum_{i=1}^N x_i.\n\\]\n\nThe integral on the left-hand-side is $1/2$.\nIn the approximation on the right-hand-side, $x_i$ is drawn from a uniform distribution on $[0,1]$.\nThe average of $N$ such draws will converge to $1/2$.\n\n\\begin{problem}\n\\label{prob:crazy_sine}\nMonte Carlo Integration is particularly useful when trying to approximate integrals that would be difficult to calculate otherwise. Write a function that approximates the following integral:\n$$\\int_{1}^{5} \\left | \\text{sin}(10x)\\text{cos}(10x) + \\sqrt{x}\\text{sin}(3x) \\right | dx$$\nYour function should accept a keyword argument \\li{N} that defaults to $10^5$. Your answer should be approximately $4.502$.\n\\end{problem}\n\n\\end{comment}\n\n\\begin{problem}\n\\label{prob:mc_1d}\nWrite a function that performs 1-dimensional Monte Carlo integration.\nGiven a function $f: \\mathbb{R} \\mapsto \\mathbb{R}$, an interval ${[a,b]}$, and the number of random points to use, your function should return an approximation of the integral\n$\\int_a^b f(x)\\:dx$.\nLet the number of sample points default to $10^5$.\nTest your function by estimating integrals that you can calculate by hand.\n\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:mc}\nGeneralize Problem \\ref{prob:mc_1d} to multiple dimensions.\nWrite a function that accepts a function handle $f$ to integrate, the bounds of the interval to integrate over, and the number of points to use.\nLet the number of sample points default to $10^5$.\nYour implementation should be robust enough to integrate any function $f$ : $\\mathbb{R}^n \\mapsto \\mathbb{R}$ over any interval in $\\mathbb{R}^n$.\n\nHints:\n\\begin{enumerate}\n\\item To draw a random array of points from the given interval, first create a random array of points in $[0,1] \\times \\ldots \\times [0,1]$.\nMultiply this array by the dimensions of the interval to rescale it, then add the lower bounds of integration to shift it.\nThink about using array broadcasting.\n\n\\item You can use \\li{np.apply_along_axis()} to apply a function to each column of an array.\nHere is an example of applying a function to points in $\\mathbb{R}^2$:\n\n\\begin{lstlisting}\n>>> points = np.random.rand(2,4)\n>>> points\narray([[ 0.33144631,  0.52558001,  0.67766158,  0.45570083],\n       [ 0.70935864,  0.20985475,  0.25917177,  0.19431292]])\n# Apply the norm function to each point\n>>> np.apply_along_axis(np.linalg.norm,0,points)\narray([ 0.78297275,  0.565927  ,  0.72553099,  0.49539959])\n\\end{lstlisting}\n\nThis is especially useful for functions that don't work nicely with array inputs.\nFor example, the code below uses a simple thresholding function \\li{f}; calling \\li{f(points)} would throw an error, but using \\li{np.apply_along_axis} gives the expected result.\n(Note that \\li{points} must have at least 2 dimensions for this to work.)\nRefer to the NumPy docs for more information.\n\n\\begin{lstlisting}\n# Simple function that returns a 0 if x is less than 0.5\n>>> f = lambda x: x if x > 0.5 else 0.\n# Get 4 random points. The 1 forces the array to be 2-D.\n>>> points = np.random.rand(1,4)\n>>> points\narray([[ 0.2144746 ,  0.02490517,  0.86593995,  0.86401139]])\n# Evaluate f at each element of points\n>>> np.apply_along_axis(f,0,points)\narray([ 0.        ,  0.        ,  0.86593995,  0.86401139])\n\\end{lstlisting}\n\n%Experiment with this on your own to make sure the function does what you expect.\n%In this example, we chose the axis parameter to be 1 to evaluate the rows of the matrix.\n%If you would like a refresher on axes, see Lab \\ref{lab:NumPyArrays}.\n\n\\end{enumerate}\n\\end{problem}\n\n\\begin{comment}\n\n\\begin{problem}\n\\label{prob:mc_test}\nThe exact value of the integral of\n\\[\nf(x,y,z,w) = \\text{sin}(x) y^5 -y^3 + zw + yz^3\n\\]\non $[-1,1]\\times[-1,1]\\times[-1,1]\\times[-1,1]$ is 0.\nRun the function \\li{mc_int()} you wrote in Problem 3 on $f$ with 100, 1000, and 10000 sample points. Use the default value of 100 iterations for your approximations.\nPrint the errors of your estimates to the terminal.\n\\end{problem}\n\n\\begin{problem}\nThe standard normal distribution is an important object of study in probability and statistic.\nIt is defined by the density function $\\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{x^2}{2}}$.\n(Here we are assuming a mean of $0$ and a variance of $1$).\nThis is a function that cannot be integrated symbolically.\nWe can use monte carlo integration to estimate the probability that a normally distributed random variable will take a value below a given point.\nThe probability that the random variable we are considering is less than (or equal to) a given value $x$ is\n\\[\\int_{-\\infty}^x \\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{t^2}{2}} dt\\]\nThis function is essentially zero for values of $x$ that lie reasonably far from the mean, so we can estimate this probability by integrating from $-5$ to $x$ instead.\n\nCompare your result at $x = 1$ with the output of the code\n\n\\begin{lstlisting}\nfrom scipy.stats import norm\nN = norm()\nN.cdf(1)\n\\end{lstlisting}\n\n\\end{problem}\n\\end{comment}\n\nOne application of Monte Carlo integration is integrating probability density functions that do not have closed form solutions.\n\n\\begin{problem}\nThe joint normal distribution of $N$ independent random variables with mean 0 and variance 1 is\n\\[\nf(\\x) = \\frac{1}{\\sqrt{2 \\pi}^N} e^{- \\frac{\\x^T\\x}{2}}.\n\\]\nThe integral of $f(\\x)$ over a box is the probability that a draw from the distribution will be in the box.\nThis is an important distribution in statistics.\nHowever, $f(\\x)$ does not have a symbolic antiderivative.\n\\begin{enumerate}\n\\item Let $\\Omega=[-1.5, 0.75]\\times[0,1]\\times[0, 0.5]\\times[0,1] \\subset \\mathbb{R}^4$.\nUse the function you wrote in Problem \\ref{prob:mc} to integrate $f(\\x)$ on $\\Omega$.\nUse 50000 sample points.\n\\item SciPy has a built in function specifically for integrating the joint normal distribution.\nThe integral of $f(\\x)$ on $B = [-1,1]\\times [-1,1]\\times[-1,1] \\subset \\mathbb{R}^3$ can be computed in SciPy with the following code.\n\n\\begin{lstlisting}\n>>> from scipy import stats\n\n# Define the bounds of the box to integrate over\n>>> mins = np.array([-1, -1, -1])\n>>> maxs = np.array([1, 1, 1])\n\n# Each variable has mean 0\n>>> means = np.zeros(3)\n\n# The covariance matrix of N independent random variables\n#    is the NxN identity matrix.\n>>> covs = np.eye(3)\n\n# Compute the integral\n>>> value, inform = stats.mvn.mvnun(mins, maxs, means, covs)\n\\end{lstlisting}\n\nThen \\li{value} is the integral of $f(\\x)$ on $B$.\n\nUse SciPy to integrate $f(\\x)$ on $\\Omega$.\n\n\\item Return your Monte Carlo estimate, SciPy's answer, and (assuming SciPy is correct) the relative error of your Monte Carlo estimate.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Convergence} % ======================================================\n\nThe error of the Monte Carlo method is proportional to $1/\\sqrt{N}$, where $N$ is the number of points used in the estimation.\nThis means that to divide the error by 10, we must sample \\emph{100 times} more points.\n\nThis is a slow convergence rate, but it is independent of the number of dimensions of the problem.\nThe error converges at the same rate whether integrating a 2-dimensional or a 20-dimensional function.\nThis gives Monte Carlo integration an advantage over other methods, and makes it especially useful for estimating integrals in high dimensions.\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{figures/MC_error_2.pdf}\n\\caption{The Monte Carlo integration method was used to compute the volume of the unit sphere.\nThe blue line plots the average error in 50 runs of the Monte Carlo method on $N$ sample points.\nThe red line is a plot of $1/\\sqrt{N}$. }\n\\label{fig:mc_error_2}\n\\end{figure}\n\n\\begin{problem}\nIn this problem we will visualize how the error in Monte Carlo integration depends on the number of sample points.\n\nRun Problem \\ref{prob:sphere} with \\li{N} equal to 50, 100 and 500, as well as 1000, 2000, 3000, ..., 50000;\nhaving some additional small values of \\li{N} will help make the visualization better.\n\nFor each value of \\li{N}:\n\\begin{enumerate}\n\\item Estimate the volume of the unit sphere using Problem \\ref{prob:sphere}, and use the true volume to calculate the relative error of the estimate.\n\\item Repeat this multiple times to get an average estimate of the relative error. Your function should accept a keyword argument \\li{numEstimates} that defaults to 50.\n\\item Calculate and store the mean of the errors.\n\\end{enumerate}\n\nPlot the mean relative error as a function of \\li{N}.\nFor comparison, plot the function $1/\\sqrt{N}$ on the same graph.\nYour plot should resemble Figure \\ref{fig:mc_error_2}).\n\n\\end{problem}\n\n\\section*{A Caution} % ========================================================\n\nYou can run into trouble if you try to use Monte Carlo integration on an integral that does not converge.\nFor example, we may attempt to evaluate\n\\[\n\\int_0^1 \\frac{1}{x}\\:dx\n\\]\nwith Monte Carlo integragtion using the following code.\n\\begin{lstlisting}\n>>> k = 5000\n>>> np.mean(1/np.random.rand(k,1))\n21.237332864358656\n\\end{lstlisting}\n\nSince this code returns a finite value, we could assume that this integral has a finite value.\nIn fact, the integral is infinite.\nWe could discover this empirically by using larger and larger values of $k$, and noting that Monte Carlo integration fails to converge.\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:mc_flawed}\nCreate a new function (based upon the function from Problem \\ref{prob:mc}) that uses a ``flawed'' random number generator that doesn't produce numbers between $-.95$ and $-1$. Test your method on the function from Problem \\ref{prob:mc_test}. How bad is the error?\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "9efc04ec484da1b0050dd964e778b777c93c8a42", "size": 18107, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/MonteCarlo1-Integration/MonteCarlo1.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/MonteCarlo1-Integration/MonteCarlo1.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/MonteCarlo1-Integration/MonteCarlo1.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 51.1497175141, "max_line_length": 343, "alphanum_fraction": 0.7309327884, "num_tokens": 5029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677622198946, "lm_q2_score": 0.9381240108164656, "lm_q1q2_score": 0.7954989181367905}}
{"text": "\\subsection{Linearity}\r\n\\noindent\r\nWe already know from calculus that the integral is a linear operator.\r\nThat is, scalar multiplication can be pulled out of the integral, and the integral of the sum of two functions is the same as the sum of the integrals of the functions.\r\nSince the Laplace transform is just an integral, it is also a linear operator.\r\nSo we can say\r\n\\begin{equation*}\r\n\t\\Laplace{cf + g} = c\\Laplace{f} + \\Laplace{g} \\text{, } c \\in \\R.\r\n\\end{equation*}", "meta": {"hexsha": "e4128ec99a714bce534201bd23cdb0028e595df4", "size": 473, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/definition/stillLinear.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/stillLinear.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/stillLinear.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": 52.5555555556, "max_line_length": 169, "alphanum_fraction": 0.7399577167, "num_tokens": 131, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7954989167958695}}
{"text": "\\subsection{Gram-Schmidt process}\n\nThe Gram-Schmidt process is an algorithm to transform a set of vectors\ninto an orthonormal set spanning the same subspace, that is generating\nthe same collection of linear combinations (see Definition~\\ref{def:linear-combination}).\n\nThe goal of the Gram-Schmidt process is to take a linearly\nindependent set of vectors and transform it into an orthonormal set\nwith the same span.  The first objective is to construct an orthogonal\nset of vectors with the same span, since from there an orthonormal set\ncan be obtained by simply dividing each vector by its length.\n\n\\begin{algorithm}{Gram-Schmidt process}{gram-schmidt-algorithm}\nLet $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n} $ be a set of\nlinearly independent vectors in $\\R^{n}$.\n\n\\textbf{I:} Construct a new set of vectors $\\set{\\vect{v}_1,\\ldots,\\vect{v}_n} $ as follows:\n\\[ \\begin{array}{ll}\n\\vect{v}_1 & = \\vect{u}_1 \\\\\n\\vect{v}_{2} & = \\vect{u}_{2} - \\paren{\\dfrac{ \\vect{u}_2 \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2}}  \\vect{v}_1\\\\\n\\vect{v}_{3} & = \\vect{u}_{3} - \\paren{\\dfrac{\\vect{u}_3 \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2}}  \\vect{v}_1\n\t - \\paren{\\dfrac{\\vect{u}_3 \\dotprod \\vect{v}_2}{\\norm{\\vect{v}_2}^2}}  \\vect{v}_2\\\\\n\\vdots \\\\\n\\vect{v}_{n} & = \\vect{u}_{n} - \\paren{\\dfrac{\\vect{u}_n \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2}}  \\vect{v}_1\n\t - \\paren{\\dfrac{\\vect{u}_n \\dotprod \\vect{v}_2}{\\norm{\\vect{v}_2}^2}} \\vect{v}_2 - \\ldots\n\t - \\paren{\\dfrac{\\vect{u}_{n} \\dotprod \\vect{v}_{n-1}}{\\norm{\\vect{v}_{n-1}}^2}} \\vect{v}_{n-1} \\\\\n\\end{array} \\]\n\n\\textbf{II:} Now let $\\vect{w}_i = \\dfrac{\\vect{v}_i}{\\norm{\\vect{v}_i}}$ for $i=1,\\ldots,n$.\n\nThen\n\\begin{enumerate}\n\\item $\\set{\\vect{v}_1,\\ldots, \\vect{v}_n }$ is an orthogonal set.\n\\item  $\\set{\\vect{w}_1,\\ldots, \\vect{w}_n  } $ is an orthonormal set.\n\\item $\\sspan\\set{\\vect{u}_1,\\ldots,\\vect{u}_n } = \\sspan \\set{\\vect{v}_1,\\ldots, \\vect{v}_n } = \\sspan\\set{\\vect{w}_1,\\ldots,\\vect{w}_n }$.\n\\end{enumerate}\n\\end{algorithm}\n\n\\begin{proof}\nThe full proof of this algorithm is beyond this material, however here is an indication of the arguments.\n\nTo show that  $\\set{\\vect{v}_1,\\ldots, \\vect{v}_n  } $ is an orthogonal set, let\n\\[ a_2 =  \\dfrac{ \\vect{u}_2 \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2} \\]\nthen:\n\\[\n\\begin{array}{ll}\n \\vect{v}_1 \\dotprod \\vect{v}_2 &  =  \\vect{v}_1 \\dotprod (\\vect{u}_2 - a_2 \\vect{v}_1)  \\\\\n & = \\vect{v}_1 \\dotprod \\vect{u}_2 - a_2 (\\vect{v}_1 \\dotprod \\vect{v}_1  \\\\\n & = \\vect{v}_1 \\dotprod \\vect{u}_2 - \\dfrac{ \\vect{u}_2 \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2} \\norm{\\vect{v}_1}^2 \\\\\n & = ( \\vect{v}_1 \\dotprod \\vect{u}_2 ) - ( \\vect{u}_2 \\dotprod \\vect{v}_1 ) =0\\\\\n\\end{array}\n\\]\nNow that you have shown that $\\set{\\vect{v}_1, \\vect{v}_2}$ is orthogonal,  use the same method as above to show that\n$\\set{\\vect{v}_1, \\vect{v}_2, \\vect{v}_3}$ is also orthogonal,  and so on.\n\nThen in a similar fashion you show that $\\sspan\\set{\n\\vect{u}_1,\\ldots,\\vect{u}_n } = \\sspan\\set{\n\\vect{v}_1,\\ldots,\\vect{v}_n }$.\n\nFinally defining $\\vect{w}_i =\n\\dfrac{\\vect{v}_i}{\\norm{\\vect{v}_i}}$ for $i=1,\\ldots,n$ does not affect orthogonality and yields vectors of length 1,\nhence an orthonormal set. You can also observe that it does not affect\nthe span either and the proof would be complete.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{Find orthonormal set with same span}{orthonormal-same-span}\nConsider the set of vectors $\\set{\\vect{u}_1, \\vect{u}_2}$ given as in Example~\\ref{exa:span-vectors}. That is\n\\[\n\\vect{u}_1=\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix}, \\vect{u}_2=\\begin{mymatrix}{r}\n3 \\\\\n2 \\\\\n0\n\\end{mymatrix} \\in \\R^{3}\n\\]\n\nUse the Gram-Schmidt algorithm to find an orthonormal set of vectors $\\set{\\vect{w}_1, \\vect{w}_2}$ having the same span.\n\\end{example}\n\n\\begin{solution}\nWe already remarked that the set of vectors in $\\set{\\vect{u}_1,\n\\vect{u}_2}$ is linearly independent, so we can proceed with the\nGram-Schmidt algorithm:\n\\begin{eqnarray*}\n\\vect{v}_1 &=& \\vect{u}_1 =  \\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} \\\\\n&& \\\\\n\\vect{v}_{2} &=& \\vect{u}_{2} - \\paren{\\dfrac{\\vect{u}_2 \\dotprod \\vect{v}_1}{\\norm{\\vect{v}_1}^2}}  \\vect{v}_1\\\\\n&& \\\\\n&=& \\begin{mymatrix}{r}\n3 \\\\\n2 \\\\\n0\n\\end{mymatrix}\n-\n\\frac{5}{2}\n \\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} \\\\\n&&\\\\\n&=&  \\begin{mymatrix}{r}\n\\vspace{0.05in}\\frac{1}{2} \\\\\n-\\vspace{0.05in}\\frac{1}{2} \\\\\n0\n\\end{mymatrix}\n\\end{eqnarray*}\n\nNow to normalize simply let\n\\begin{eqnarray*}\n\\vect{w}_1  = \\frac{\\vect{v}_1}{\\norm{\\vect{v}_1}}  = \\begin{mymatrix}{r}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}  \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} \\\\\n0\n\\end{mymatrix} \\\\\n\\vect{w}_2  = \\frac{\\vect{v}_2}{\\norm{\\vect{v}_2}}  = \\begin{mymatrix}{r}\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}  \\\\\n-\\vspace{0.05in}\\frac{1}{\\sqrt{2}} \\\\\n 0\n\\end{mymatrix}\n\\end{eqnarray*}\n\nYou can verify that $\\set{\\vect{w}_1, \\vect{w}_2}$ is an orthonormal set of vectors  having the same span as\n$\\set{\\vect{u}_1, \\vect{u}_2}$,  namely the $XY$-plane.\n\\end{solution}\n\nIn this example, we began with a linearly independent set and found an orthonormal set of vectors which had the same span. It turns out that if we start with a basis of a subspace and apply the Gram-Schmidt algorithm, the result will be an orthogonal basis of the same subspace. We examine this in the following example.\n\n\\begin{example}{Find a corresponding orthogonal basis}{orthogonal-basis}\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\\mbox{ and }\n\\vect{x}_3=\\begin{mymatrix}{c} 1\\\\ 1\\\\ 0\\\\ 0 \\end{mymatrix},\\]\nand let $U=\\sspan\\set{\\vect{x}_1, \\vect{x}_2,\\vect{x}_3}$. Use the Gram-Schmidt Process\nto construct an orthogonal basis $B$ of $U$.\n\\end{example}\n\n\\begin{solution}\nFirst $\\vect{f}_1=\\vect{x}_1$.\n\nNext,\n\\[ \\vect{f}_2=\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 1 \\end{mymatrix}\n-\\frac{2}{2}\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix}\n=\\begin{mymatrix}{c} 0\\\\ 0\\\\ 0\\\\ 1 \\end{mymatrix}.\\]\n\nFinally,\n\\[ \\vect{f}_3=\\begin{mymatrix}{c} 1\\\\ 1\\\\ 0\\\\ 0 \\end{mymatrix}\n-\\frac{1}{2}\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix}\n-\\frac{0}{1}\\begin{mymatrix}{c} 0\\\\ 0\\\\ 0\\\\ 1 \\end{mymatrix}\n=\\begin{mymatrix}{c} 1/2\\\\ 1\\\\ -1/2\\\\ 0 \\end{mymatrix}.\\]\n\nTherefore,\n\\[ \\set{\n\\begin{mymatrix}{c} 1\\\\ 0\\\\ 1\\\\ 0 \\end{mymatrix},\n\\begin{mymatrix}{c} 0\\\\ 0\\\\ 0\\\\ 1 \\end{mymatrix},\n\\begin{mymatrix}{c} 1/2\\\\ 1\\\\ -1/2\\\\ 0 \\end{mymatrix}\n}\\]\nis an orthogonal basis of $U$.\nHowever, it is sometimes more convenient to deal with vectors\nhaving integer entries, in which case we take\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\\end{solution}\n", "meta": {"hexsha": "8bb0c8e873139ef708dd40b6caca2709a171de2d", "size": 6719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonalityGramSchmidt.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/RnVectorsOrthogonalityGramSchmidt.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/RnVectorsOrthogonalityGramSchmidt.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.9604519774, "max_line_length": 320, "alphanum_fraction": 0.6538175324, "num_tokens": 2704, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.9294404008810104, "lm_q1q2_score": 0.7954626331317222}}
{"text": "\\subsection{Resolution rule}\n\n\\subsubsection{Proof by resolution}\n\nIf we have a string of or statements, \\(A\\lor B\\lor C\\), and another which contains the completement of one element \\(X\\lor \\neg B\\lor Y\\), we can infer:\n\n\\(A\\lor C\\lor X\\lor Y\\)\n\nIf the second statement has only one formula, then we have:\n\n\\(A\\lor B\\lor C\\) and \\(\\neg B\\) implying \\(A\\lor C\\)\n\n\n", "meta": {"hexsha": "25277a3dad3e64d266917004f557dbaea440fec5", "size": 364, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-04-resolution.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-04-resolution.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-04-resolution.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.0, "max_line_length": 153, "alphanum_fraction": 0.6950549451, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680097, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.795387708401983}}
{"text": "\t\t\\subsubsection*{Max flow}\n\t\t\tWe can make nodes $v_{u,v},\\{u,v\\}\\in E$, $v_i,i\\in V$, a source $S$ and a sink $T$. Then connect edges from $S$ to $v_{u,v}$ with capacity of $1$, from $v_{u,v}$ to $v_u$ and $v_v$ with capacity of $1$ and from $v_i$ to $T$ with capacity of $c(i)$. If this graph has a maximum flow of $|E|$, then the original graph has a feasible orientation.\\par\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\\includegraphics[width=3in]{source/qwd/qa.eps}\n\t\t\t\\end{figure}\n\t\t\tFor a maximum flow $S$, since the flow is full and nodes $v_{u,v}$ has exactly one unit flow input, exactly one of the edges $<v_{u,v}, v_u>$ and $<v_{u,v}, v_v>$ will has a flow. We can simply orientate edge $\\{u,v\\}$ to $u\\to v$ if $<u_{u,v}, v_v>$ has a flow, or $v\\to u$ if $<u_{u,v}, v_u>$ has a flow. Thus, the in-dgree of $i$ is just the flow through $v_i$, which is less than or equal to the capacity to sink, $c(i)$. So, we get a feasible orientation.\\par\n\t\t\tFor a feasible orientation, %since convert ${u,v}$ to both $<u,v>$ and $<v,u>$ is meaningless(otherwise we can delete one of them and make maximum in-dgree of $u$ and $v$ decreas by $1$).\n\t\t\tif $\\{u, v\\}$ is converted to $u\\to v$, we can add the flow on path $S\\to v_{u, v}\\to v_v\\to T$ by one unit, or $S\\to v_{u, v}\\to v_u\\to T$ when converted to $v\\to u$. Since the in-degree of a node $i$ doesn't exceed $c(i)$, so the flow from $v_i$ to $T$ is less than or equal to the capacity $c(i)$.\n\t\t\\subsubsection*{Maximum matching}\n\t\t\tWe can make nodes $vl_{u,v},\\{u,v\\}\\in E$ as $X$ and $vr_{i,j},i\\in V,1\\leq j\\leq c(i)$ as $Y$. Then connect $c(u)$ edges between $vl_{u, v}$ and $vr_{u,j},1\\leq j\\leq c(u)$, $c(v)$ edges between $vl_{u, v}$ and $vr_{v,k},1\\leq k\\leq c(v)$. If this bipartite graph has a maximum matching of size $|E|$, then the original graph has a feasible orientation.\\par\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\\includegraphics[width=2in]{source/qwd/qb.eps}\n\t\t\t\\end{figure}\n\t\t\tFor a maximum matching $S$, since the size of matching is $|E|$, every node $vl_{u, v}$ has a paired node in $Y$, then we convert $\\{u, v\\}$ to $u\\to v$ if the paired node is $vr_{v,i}$, or to $v\\to u$ if that node is $vr_{u,i}$. Since nodes $vr_{i, j}$ in $Y$ is no more than $c(i)$, so the in-degree of $i$ is less or equal to $c(i)$. Then we get a feasible orientation.\\par\n\t\t\tFor a feasible orientaion, we processe edges one by one in an arbitrary order. If $\\{u, v\\}$ is converted to $u\\to v$, we can match $vl_{u, v}$ with $vr_{v, i}$, or $vr_{u, j}$ when converted to $v\\to u$, where $i$ and $j$ is the smallest one that $vr_{v, i}$, $vr_{u, j}$ has not matched before. Since the in-degree of a node $i$ doesn't exceed $c(i)$, so there is always an avalible $i$ or $j$.\n", "meta": {"hexsha": "b7bf2c0a941f3cc13f46dc75e2f24aef46081a5e", "size": 2717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Week 4/source/qwd/ex6.tex", "max_stars_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_stars_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Week 4/source/qwd/ex6.tex", "max_issues_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_issues_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Week 4/source/qwd/ex6.tex", "max_forks_repo_name": "PrayStarJirachi/Algorithm-Homework", "max_forks_repo_head_hexsha": "22ec83e6d4a202d994a177e3dcbfd9225736666f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 169.8125, "max_line_length": 467, "alphanum_fraction": 0.6499815974, "num_tokens": 975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7953866514531178}}
{"text": "% !TEX root = main.tex\n%=====================================================================\n\\chapter{Bayesian Inference}\\label{chap:randomprocesses}\n\n%----------------------------------------------------------------------\n%\\section{The Bayesian approach}\n%----------------------------------------------------------------------\n\nSo far we have looked at \\emph{frequentist inference}, which assumes that an unknown parameter $\\theta$ has a fixed (but unknown) value. \n\\bit\n\\it The PMF/PDF of an observation is written as $f(x;\\theta)$.\n\\it The likelihood function is written as $L(\\theta;x)$.\n\\it Estimators such as the MME and MLE claim to estimate the `true' value of $\\theta$.\n\\eit\n\nFor \\emph{Bayesian inference}, we instead think of an unknown parameter $\\theta$ as a \\emph{random variable}.\n\\bit\n\\it The PMF/PDF of an observation is written as $f(x|\\theta)$.\n\\it The likelihood function of is written as $L(\\theta|x)$.\n\\it We seek to estimate the distribution of $\\theta$.\n\\eit\n\n%----------------------------------------------------------------------\n\\section{Bayes' theorem}\n%----------------------------------------------------------------------\n\n% events\nIf the events $A_1,A_2,\\ldots$ form a partition of event $B$, Bayes' theorem states that\n\\[\n\\prob(A_j|B) \n%\t= \\frac{\\prob(B|A_j)\\prob(A_j)}{\\prob(B)} \n\t= \\frac{\\prob(B|A_j)\\prob(A_j)}{\\sum_k \\prob(B|A_k)\\prob(A_k)}.\n\\]\n\n% discrete\nLet $X$ and $Y$ be discrete random variables taking values in the sets $\\{x_1,x_2,\\ldots\\}$ and $\\{y_1,y_2,\\ldots\\}$ respectively. Because the events $\\{Y=y_1\\},\\{Y=y_2\\},\\ldots$ form a partition of the event $\\{X=x_i\\}$, we have % so applying Bayes' theorem we obtain\n\\[\n\\prob(Y=y_j|X=x_i) \n%= \\frac{\\prob(X=x_i|Y=y_j)\\prob(Y=y_j)}{\\prob(X=x_i)}\n= \\frac{\\prob(X=x_i|Y=y_j)\\prob(Y=y_j)}{\\sum_k \\prob(X=x_i|Y=y_k)\\prob(Y=y_k)}.\n\\]\nTo avoid cluttering the notation with subscripts, we write this as\n\\[\n\\prob(Y=y|X=x) \n%= \\frac{\\prob(X=x|Y=y)\\prob(Y=y)}{\\prob(X=x)}\n= \\frac{\\prob(X=x|Y=y)\\prob(Y=y)}{\\sum_y \\prob(X=x|Y=y)\\prob(Y=y)},\n\\]\nwhere the sum in the denominator is taken over the range of $Y$.\nIn terms of PMFs, this becomes\n\\[\nf_{Y|X}(y|x) \n%= \\frac{f_{X|Y}(x|y)f_Y(y)}{f_X(x)}\n= \\frac{f_{X|Y}(x|y)f_Y(y)}{\\sum_y f_{X|Y}(x|y)f_Y(y)}.\n\\]\n\n% continuous\nThis extends directly to the case of continuous random variables, the only difference being that the denominator (which is the marginal PDF of $X$) is expressed by an integral:\n\\[\nf_{Y|X}(y|x) \n%= \\frac{f_{X|Y}(x|y)f_Y(y)}{f_X(x)}\n= \\frac{f_{X|Y}(x|y)f_Y(y)}{\\int f_{X|Y}(x|y)f_Y(y)\\,dy}.\n\\]\n\n% parameter estimation\nFor Bayesian inference, the unknown parameter $\\theta$ takes the role of $Y$ in the above formulation. To simplify the notation we denote the PMF/PDF of $\\theta$ by the symbol $\\pi$: \n\\[\n\\pi(\\theta|\\mathbf{x}) = \\left\\{\\begin{array}{ll}\n\t\\displaystyle\\frac{f(\\mathbf{x}|\\theta)\\pi(\\theta)}{\\sum_{\\theta}f(\\mathbf{x}|\\theta)\\pi(\\theta)} \t\t\t& \\text{\\quad ($\\theta$ discrete)}, \\\\[5ex]\n\t\\displaystyle\\frac{f(\\mathbf{x}|\\theta)\\pi(\\theta)}{\\int f(\\mathbf{x}|\\theta)\\pi(\\theta)\\,d\\theta} \t& \\text{\\quad ($\\theta$ continuous)}.\n\\end{array}\\right.\n\\]\n\nThis can also be expressed in terms of likelihood functions,\n\\[\n\\pi(\\theta|\\mathbf{x}) = \\left\\{\\begin{array}{ll}\n\t\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi(\\theta)}{\\sum_{\\theta}L(\\theta|\\mathbf{x})\\pi(\\theta)} \t\t\t& \\text{\\quad ($\\theta$ discrete)}, \\\\[5ex]\n\t\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi(\\theta)}{\\int L(\\theta|\\mathbf{x})\\pi(\\theta)\\,d\\theta} \t& \\text{\\quad ($\\theta$ continuous)}.\n\\end{array}\\right.\n\\]\n\n%----------------------------------------------------------------------\n\\section{The prior and posterior distributions}\n%----------------------------------------------------------------------\n\n%----------------------------------------------------------------------\n\\subsection*{The prior distribution}\n%----------------------------------------------------------------------\n% prior\nSuppose we have an initial estimate for distribution of $\\theta$, perhaps obtained as a result of some preliminary experiments. \n\\bit\n\\it This is called the \\emph{prior distribution} of $\\theta$, which we denote by $\\pi_0(\\theta)$.\n\\eit\n\nAn initial point estimate of $\\theta$ can be computed from the prior distribution, for example\n\\bit\n\\it by the \\emph{mean} of the prior distribution: $\\hat{\\theta} = \\expe\\big[\\pi_0(\\theta)\\big]$ or\n\\it by the \\emph{mode} of the prior distribution: $\\hat{\\theta} = \\argmax_{\\theta}\\big[\\pi_0(\\theta)\\big]$.\n\\eit\n\nIf we have no prior knowledge, we should initially consider every value of $\\theta$ to be equally likely. For example, if $\\theta$ is continuous and all we know is that $\\theta$ belongs to some interval $[a,b]$, we should adopt the \\emph{uniform} distribution over $[a,b]$ as the prior distribution of $\\theta$,\n\\[\n\\pi_0(\\theta) = \\left\\{\\begin{array}{ll}\n\t1/(b-a)\t& \\text{if } a\\leq\\theta\\leq b, \\\\\n\t0\t& \\text{otherwise.}\n\\end{array}\\right.\n\\]\nIn this context, the uniform distribution is often called the \\emph{na\\\"{\\i}ve} or \\emph{non-informative} prior.\n\n%----------------------------------------------------------------------\n\\subsection*{The posterior distribution}\n%----------------------------------------------------------------------\n% posterior\nSuppose we now obtain some sample data $\\mathbf{x}=(x_1,\\ldots,x_n)$. \n\\bit\n\\it Bayes' theorem can be used to combine the prior distribution with the data.\n\\it This yields an updated PMF/PDF $\\pi_1(\\theta)$, called the \\emph{posterior distribution} of $\\theta$.\n\\eit\n\nBy Bayes' theorem, \n%\\[\n%\\pi_1(\\theta|\\mathbf{x}) = \\left\\{\\begin{array}{ll}\n%\t\\displaystyle\\frac{f(\\mathbf{x}|\\theta)\\pi_0(\\theta)}{\\sum_{\\theta}f(\\mathbf{x}|\\theta)\\pi_0(\\theta)} \t\t\t& \\text{\\quad ($\\theta$ discrete)}, \\\\[3ex]\n%\t\\displaystyle\\frac{f(\\mathbf{x}|\\theta)\\pi_0(\\theta)}{\\int_{\\theta}f(\\mathbf{x}|\\theta)\\pi_0(\\theta)\\,d\\theta} \t& \\text{\\quad ($\\theta$ continuous)}.\n%\\end{array}\\right.\n%\\]\n%\n%This can also be expressed in terms of likelihood functions,\n%\\[\n%\\pi_1(\\theta|\\mathbf{x}) = \\left\\{\\begin{array}{ll}\n%\t\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\sum_{\\theta}L(\\theta|\\mathbf{x})\\pi_0(\\theta)} \t\t\t& \\text{\\quad ($\\theta$ discrete)}, \\\\[3ex]\n%\t\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\int_{\\theta}L(\\theta|\\mathbf{x})\\pi_0(\\theta)\\,d\\theta} \t& \\text{\\quad ($\\theta$ continuous)}.\n%\\end{array}\\right.\n%\\]\n\n\\[\n\\pi_1(\\theta|\\mathbf{x}) \n\t= \\frac{f(\\mathbf{x}|\\theta)\\pi_0(\\theta)}{\\sum_{\\theta}f(\\mathbf{x}|\\theta)\\pi_0(\\theta)}\n\\qquad\\text{or}\\qquad\n\\pi_1(\\theta|\\mathbf{x}) \n\t= \\frac{f(\\mathbf{x}|\\theta)\\pi_0(\\theta)}{\\int f(\\mathbf{x}|\\theta)\\pi_0(\\theta)\\,d\\theta}.\n\\]\nIn terms of likelihood functions,\n\\[\n\\pi_1(\\theta|\\mathbf{x}) \n\t= \\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\sum_{\\theta}L(\\theta|\\mathbf{x})\\pi_0(\\theta)} \t\t\n\\qquad\\text{or}\\qquad\t\n\\pi_1(\\theta|\\mathbf{x}) \n\t= \\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\int L(\\theta|\\mathbf{x})\\pi_0(\\theta)\\,d\\theta}.\n\\]\n\nHaving obtained the posterior distribution, we can compute an updated estimate of $\\theta$, for example\n\\bit\n\\it by the mean of the posterior distribution: $\\hat{\\theta} = \\expe\\big[\\pi_1(\\theta)\\big]$, or\n\\it by the mode of the posterior distribution: $\\hat{\\theta} = \\argmax_{\\theta}\\big[\\pi_1(\\theta)\\big]$.\n\\eit\n\n% defn: MAP estimator\n\\begin{definition}\nThe mode of the posterior is called the \\emph{maximum a-posteriori} or \\emph{MAP} estimator of $\\theta$.\n\\end{definition}\n\n% remark\n\\begin{remark}\n%The posterior distribution is\n%\\[\n%\\pi_1(\\theta|\\mathbf{x}) = \n%\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\sum_{\\theta}L(\\theta|\\mathbf{x})\\pi_0(\\theta)}\n%\\text{\\quad or\\quad}\n%\\pi_1(\\theta|\\mathbf{x}) =\n%\\displaystyle\\frac{L(\\theta|\\mathbf{x})\\pi_0(\\theta)}{\\int_{\\theta}L(\\theta|\\mathbf{x})\\pi_0(\\theta)\\,d\\theta}\n%\\]\nThe denominator of the posterior depends only on $\\mathbf{x}$, so the posterior is proportional to the likelihood times the prior:\n%\\begin{align*}\n\\[\n\\pi_1(\\theta|\\mathbf{x}) \t\\propto L(\\theta|\\mathbf{x})\\pi_0(\\theta),\n%\\qquad\\text{or}\\qquad\n%\\text{\"posterior}\t\t\t\t\\propto \\text{likelihood}\\times\\text{prior\"}.\n\\]\nThe MAP estimator is the value of $\\theta$ that maximizes the numerator $L(\\theta|\\mathbf{x})\\pi_0(\\theta)$ of the posterior.\n\\bit \n\\it Note that when $\\pi_0$ is the uniform distribution, the MAP estimator is just the MLE.\n\\eit\nTo compute the mean of $\\pi_1(\\theta|\\mathbf{x})$ we also need to compute the denominator. This is not always easy, which is why the MAP estimator is more widely used in practical applications.\n\\end{remark}\n\n%% example\n%\\begin{example}\\label{ex:biscuits}\n%We have three tins of biscuits. The first tin contains $30$ chocolate and $10$ plain biscuits, the second tin contains $20$ chocolate and $20$ plain biscuits, and the third tin contains $10$ chocolate and $30$ plain biscuits. A tin is chosen at random, and a biscuit is chosen at random from the tin.\n%\\ben\n%\\it If a chocolate biscuit is observed, estimate which tin was chosen.\n%\\een\n%The experiment is repeated, but this time two biscuits are chosen at random from the tin.\n%\\ben\\stepcounter{enumi}\n%\\it If two chocolate biscuits are observed, estimate which tin was chosen.\n%\\it If one chocolate biscuit and one plain biscuit are observed, estimate which tin was chosen.\n%\\een\n%\\end{example}\n%\n%\\begin{solution}\n%\\ben\n%\\it % one chocolate\n%Let $\\Theta = \\{\\theta_1,\\theta_2,\\theta_3\\}$ where the value $\\theta_k$ indicates that tin $k$ was chosen ($k=1,2,3$). Before observing the biscuit, it is reasonable to suppose that each tin is equally likely to be chosen. Thus we adopt the \\emph{uniform} prior distribution for $\\theta$:\n%\\[\n%\\pi_0(\\theta) = \\frac{1}{3} \\quad\\text{for all}\\quad \\theta\\in\\Theta.\n%\\]\n%Let $A$ be the event that a chocolate biscuit was observed. Then\n%\\[\n%\\prob(A|\\theta_1)=3/4,\\qquad \\prob(A|\\theta_2)=1/2,\\qquad \\prob(A|\\theta_3)=1/4,\n%\\]\n%or equivalently\n%\\[\n%L(\\theta_1| A)=3/4,\\qquad L(\\theta_2| A)=1/2,\\qquad L(\\theta_3| A)=1/4.\n%\\]\n%By Bayes' theorem, the posterior distribution is\n%\\[\n%\\pi_1(\\theta_k|A) = \\frac{L(\\theta_k| A)\\pi_0(\\theta_k)}{\\sum_{k=1}^3 L(\\theta_k| A)\\pi_0(\\theta_k)}\n%\\text{\\quad\\qquad ($k=1,2,3$).}\n%\\]\n%For the first tin,\n%\\[\n%\\prob(\\theta_1|A) = \\frac{3/4\\times 1/3}{(3/4\\times 1/2) + (1/2\\times 1/3) + (1/4\\times 1/3)} = \\frac{1}{2}.\n%\\]\n%Similar calculations for the second and third tins yield the following posterior:\n%\\[\n%\\pi_1(\\theta_1) = 1/2,\\qquad \\pi_1(\\theta_2) = 1/3, \\qquad \\pi_1(\\theta_3) = 1/6.\n%\\]\n%The MAP estimate is $\\hat{\\theta}_{MAP} = \\theta_1$, so our best guess is that the first tin was chosen.\n%\n% % <<\n%\n%\\it % two chocolate\n%Let $B$ be the event that two chocolate biscuits are observed, \n%\\[\n%\\prob(B|\\theta_1)=87/156,\\qquad \\prob(B|\\theta_2)=38/156,\\qquad \\prob(B|\\theta_3)=9/156.\n%\\]\n%If we assume the uniform prior $\\pi_0$, we obtain the posterior distribution\n%\\[\n%\\pi_1(\\theta_1|B) = 87/134,\\qquad \\pi_1(\\theta_2|B) = 38/134, \\qquad \\pi_1(\\theta_3|B) = 9/134.\n%\\]\n%The MAP estimator again suggests that the first tin was chosen.\n%\n%\\it % one chocolate, one plain\n%Let $C$ be the event that one chocolate and one plain biscuit are observed, \n%\\[\n%\\prob(C|\\theta_1)=60/156,\\qquad \\prob(C|\\theta_2)=80/156,\\qquad \\prob(C|\\theta_3)=60/156.\n%\\]\n%If we assume the uniform prior $\\pi_0$,\n%\\[\n%\\pi_1(\\theta_1|C) = 3/10,\\qquad \\pi_1(\\theta_2|C) = 4/10, \\qquad \\pi_1(\\theta_3|C) = 3/10.\n%\\]\n%This time, the MAP estimator leads us to assert that the second tin was chosen.\n%\\een\n%\\end{solution}\n\n\n%----------------------------------------------------------------------\n%\\section{Example}\n%----------------------------------------------------------------------\n% example\n\\begin{example}\\label{ex:biscuits}\nSuppose we have three tins of biscuits. The first tin contains $30$ chocolate and $10$ plain biscuits, the second tin contains $20$ chocolate and $20$ plain biscuits, and the third tin contains $10$ chocolate and $30$ plain biscuits. A tin is selected at random, and a biscuit is chosen at random from the tin.\n\\ben\n\\it If a chocolate biscuit is chosen, estimate which tin was selected.\n\\een\nThe biscuit is replaced, then a biscuit is again chosen from the tin.\n\\ben\\stepcounter{enumi}\n\\it If a chocolate biscuit is chosen, update your estimate regarding which tin was selected.\n\\it If a plain biscuit is chosen, update your estimate regarding which tin was selected.\n\\een\n\\end{example}\n\n\\begin{solution}\nLet $\\Theta = \\{\\theta_1,\\theta_2,\\theta_3\\}$ where the value $\\theta_k$ indicates that tin $k$ was selected ($k=1,2,3$). Before the biscuit is chosen, it is reasonable to suppose that each tin is equally likely to be selected. Thus we adopt the \\emph{uniform} prior distribution for $\\theta$:\n\\[\n\\pi_0(\\theta) = \\frac{1}{3} \\quad\\text{for all}\\quad \\theta\\in\\Theta.\n\\]\n\n\\ben\n\\it % one chocolate\nLet $A$ be the event that a chocolate biscuit is chosen. Then\n%\\[\n%\\prob(A|\\theta_1)=3/4,\\qquad \\prob(A|\\theta_2)=1/2,\\qquad \\prob(A|\\theta_3)=1/4,\n%\\]\n%or equivalently\n\\[\nL(\\theta_1| A)=3/4,\\qquad L(\\theta_2| A)=1/2,\\qquad L(\\theta_3| A)=1/4.\n\\]\nUsing Bayes' theorem, the posterior distribution is\n\\[\n\\pi_1(\\theta_k|A) = \\frac{L(\\theta_k| A)\\pi_0(\\theta_k)}{\\sum_{k=1}^3 L(\\theta_k| A)\\pi_0(\\theta_k)}\n\\text{\\quad\\qquad ($k=1,2,3$).}\n\\]\nFor the first tin,\n\\[\n\\pi_1(\\theta_1|A) = \\frac{3/4\\times 1/3}{(3/4\\times 1/3) + (1/2\\times 1/3) + (1/4\\times 1/3)} = \\frac{1}{2}.\n\\]\nSimilar calculations for the second and third tins yield the following posterior distribution:\n\\[\n\\pi_1(\\theta_1) = 1/2,\\qquad \\pi_1(\\theta_2) = 1/3, \\qquad \\pi_1(\\theta_3) = 1/6.\n\\]\nThe MAP estimate is $\\hat{\\theta}_{MAP} = \\theta_1$, so our best guess is that the first tin was selected.\n\n % <<\n\n\\it % two chocolate\nLet $B$ be the event that the a chocolate biscuit was chosen the second time:\n\\[\nL(\\theta_1|B)=3/4,\\qquad L(\\theta_2|B)=1/2,\\qquad L(\\theta_3|B)=1/4.\n\\]\nUsing $\\pi_1$ as our prior distribution, we obtain an updated posterior distribution:\n\\[\n\\pi_2(\\theta_k|B) = \\frac{L(\\theta_k|B)\\pi_1(\\theta_k)}{\\sum_{k=1}^3 L(\\theta_k| B)\\pi_1(\\theta_k)}\n\\text{\\quad\\qquad ($k=1,2,3$).}\n\\]\nFor the first tin,\n\\[\n\\pi_2(\\theta_1|B) = \\frac{3/4\\times 1/2}{(3/4\\times 1/2) + (1/2\\times 1/3) + (1/4\\times 1/6)} = \\frac{9}{14}.\n\\]\nSimilar calculations for the second and third tins yield the following posterior:\n\\[\n\\pi_2(\\theta_1) = 9/14,\\qquad \\pi_2(\\theta_2) = 4/14, \\qquad \\pi_2(\\theta_3) = 1/14.\n\\]\nThe MAP estimator again leads us to estimate that the first tin was selected.\n\n\\it % one chocolate, one plain\nLet $C$ be the event that a plain biscuit was chosen the second time:\n\\[\nL(\\theta_1|C)=1/4,\\qquad L(\\theta_2|C)=1/2,\\qquad L(\\theta_3|C)=3/4.\n\\]\nAgain using $\\pi_1$ as our prior distribution, we obtain an updated posterior:\n\\[\n\\pi_2(\\theta_k|C) = \\frac{L(\\theta_k|C)\\pi_1(\\theta_k)}{\\sum_{k=1}^3 L(\\theta_k|C)\\pi_1(\\theta_k)}\n\\text{\\quad\\qquad ($k=1,2,3$).}\n\\]\nFor the first tin,\n\\[\n\\pi_2(\\theta_1|C) = \\frac{1/4\\times 1/2}{(1/4\\times 1/2) + (1/2\\times 1/3) + (3/4\\times 1/6)} = \\frac{3}{10}.\n\\]\nSimilar calculations for the second and third tins yield the following posterior distribution:\n\\[\n\\pi_2(\\theta_1) = 3/10,\\qquad \\pi_2(\\theta_2) = 4/10, \\qquad \\pi_2(\\theta_3) = 3/10.\n\\]\nThis time, the MAP estimator leads us to estimate that the second tin was selected.\n\\een\n\\end{solution}\n\n\n%%----------------------------------------------------------------------\n%\\section{The scientific method}\n%%----------------------------------------------------------------------\n%\n% remark\n\\begin{remark}%[The Scientific Method]\nWe can think of the biscuit tins in Example~\\ref{ex:biscuits} as competing scientific hypotheses:\n\\bit\n\\it The probability assigned to each hypothesis indicates its \\emph{relative plausibility}.\n\\it We update the relative plausibility of each competing hypothesis based on \\emph{observation}.\n\\eit\n\n%\\vspace*{2ex}\nIn this way, Bayesian inference embodies the \\emph{scientific method}.\n%\\ben\n%\\it Start with an initial set of beliefs about the relative plausibility of various hypotheses.\n%\\it Collect new data by conducting experiments.\n%\\it Refine the relative plausibility of the various hypotheses in the light of the new data. \n%\\it Repeat (2) and (3).\n%\\een\n\\end{remark}\n\n\n\\begin{exercise}\nSuppose we have three coins $A$, $B$ and $C$ which have probabilities $1/4$, $1/2$ and $3/4$ respectively of showing heads. A coin is chosen at random, and tossed three times. If exactly two heads are obtained, use the maximum a-posteriori (MAP) estimator to estimate which coin was chosen.\n\\begin{answer}\nFirst we define the parameter $\\theta\\in\\{1,2,3\\}$ such that $\\{\\theta=1\\}$ is the event that coin $A$ is chosen, $\\{\\theta=2\\}$ is the event that coin $B$ is chosen, and $\\{\\theta=3\\}$ is the event that coin $C$ is chosen. We should initially assume that each coin is equally likely to be chosen, so we choose the uniform prior distribution:\n\\begin{align*}\n\\pi_0(1) & = \\prob(\\theta=1) = 1/3 \\\\\n\\pi_0(2) & = \\prob(\\theta=2) = 1/3 \\\\\n\\pi_0(3) & = \\prob(\\theta=3) = 1/3 \n\\end{align*}\nLet $T$ be the event that exactly two heads are obtained. Then\n\\begin{align*}\n\\prob(T|\\theta=1)\t& = 3(1/4)^2(3/4) = 9/64 \\\\\n\\prob(T|\\theta=2)\t& = 3(1/2)^2(1/2) = 3/8 \\\\\n\\prob(T|\\theta=3)\t& = 3(1/4)(3/4)^2 = 27/64\n\\end{align*}\nThe denominator of the posterior is the overall probability of obtaining exactly two heads:\n\\begin{align*}\n\\prob(T) \t\n\t& = \\prob(T|\\theta=1)\\prob(\\theta=1) + \\prob(T|\\theta=2)\\prob(\\theta=2) + \\prob(T|\\theta=3)\\prob(\\theta=3) \\\\\n\t& = 3(1/4)^2(3/4)(1/3) + 3(1/2)^3(1/3) + 3(3/4)^2(1/4)(1/3) \\\\\n\t& = 3/64 + 8/64 + 9/64 \\\\\n\t& = 20/64\n\\end{align*}\nHence the posterior distribution is given by\n\\[\n\\pi_1(\\theta) = \\frac{\\prob(T|\\theta)\\pi_0(\\theta)}{\\prob(T)} = \n\\]\nfrom which we obtain\n\\begin{align*}\n\\pi_1(1) & = 3/20, \\\\\n\\pi_1(2) & = 8/20, \\\\\n\\pi_1(3) & = 9/20.\n\\end{align*}\nThe MAP estimator (mode of the posterior) is $\\theta=3$, which corresponds to coin $C$.\n\\end{answer}\n\\end{exercise}\n\n%----------------------------------------------------------------------\n\\section{The binomial model}\n%----------------------------------------------------------------------\nA suitable model for estimating the distribution of a parameter in the interval $[0,1]$ is provided by the \\emph{beta distribution}.\n\n% definition\n\\begin{definition}\\label{def:beta_distribution}\nThe beta distribution with parameters $\\alpha,\\beta>0$ is defined by the PDF\n\\[\nf(x;\\alpha,\\beta) = \\begin{cases}\n\t\\displaystyle\\frac{x^{\\alpha-1}(1-x)^{\\beta-1}}{B(\\alpha,\\beta)} & \\text{if $0\\leq x\\leq 1$}, \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise,}\n\\end{cases}\n\\]\nwhere $B(\\alpha,\\beta)$ is the so-called \\emph{beta function},\n\\[\nB(\\alpha,\\beta) = \\int_0^1 t^{\\alpha-1}(1-t)^{\\beta-1}\\,dt,\n\\]\nwhich is defined for all $\\alpha,\\beta>0$.\n\\end{definition}\n\n%\\begin{remark}[Special case]\n%If $X\\sim\\text{Beta}(1,1)$, then $X\\sim\\text{Uniform}(0,1)$.\n%\\end{remark}\n\n% lemma\n\\begin{lemma}\nLet $X\\sim\\text{Beta}(\\alpha,\\beta)$. Then $\\expe(X) = \\displaystyle\\frac{\\alpha}{\\alpha+\\beta}$ and $\\mode(X) = \\displaystyle\\frac{\\alpha-1}{\\alpha+\\beta-2}$ provided that $\\alpha,\\beta > 1$.\n%For $X\\sim\\text{Beta}(\\alpha,\\beta)$,\n%\\[\n%\\expe(X) = \\frac{\\alpha}{\\alpha+\\beta} \\text{\\quad and\\quad} \\var(Y) = \\frac{\\alpha\\beta}{(\\alpha+\\beta)^2(\\alpha+\\beta+1)}. \n%\\]\n%and if $\\alpha,\\beta > 1$,\n%\\[\n%\\mode(X) = \\frac{\\alpha-1}{\\alpha+\\beta-2}.\n%\\]\n\\end{lemma}\n\n% proof\n\\begin{proof}\nExercise.\n\\end{proof}\n\n% example\n\\begin{example}\nLet $X\\sim\\text{Binomial}(n,\\theta)$ where $n$ is known, but $0<\\theta<1$ is unknown. \n\\ben\n\\it We conduct a sequence of $n$ independent trials and observe $k$ successes. Find a suitable prior distribution for $\\theta$, compute the posterior distribution, and find its mean and mode.\n\\it We conduct a further sequence of $n$ independent trials, this time observing $k'$ successes. Compute an updated posterior distribution for $\\theta$, and find its mean and mode.\n\\een\n\\end{example}\n\n% solution\n\\begin{solution}\n\\ben\n\\it % <<< (i)\nLet $f(x|\\theta)$ be the PMF of the $\\text{Binomial}(n,\\theta)$ distribution:\n\\[\nf(x|\\theta) = \\binom{n}{k}\\theta^x(1-\\theta)^{n-x}\n\\]\n\nInitially we should consider every value of $\\theta$ to be equally likely. Thus we adopt the uniform prior distribution for $\\theta$.\n\\[\n\\pi_0(\\theta) = \\left\\{\\begin{array}{ll}\n\t1\t& \\text{if } \\theta\\in[0,1] \\\\\n\t0\t& \\text{otherwise.}\n\\end{array}\\right.\n\\]\nGiven $k$ successes in $n$ trials, the likelihood function is\n\\[\nL(\\theta|k) = f(k|\\theta) = \\binom{n}{k}\\theta^k(1-\\theta)^{n-k}\n\\]\n\nThe posterior distribution combines the observation with the prior distribution:\n\\[\n\\pi_1(\\theta) = \\pi_1(\\theta|k)\t\n\t= \\frac{L(\\theta|k)\\pi_0(\\theta)}{\\int L(\\theta|k)\\pi_0(\\theta)\\,d\\theta}\n\t= \\frac{\\theta^k(1-\\theta)^{n-k}}{\\int_0^1\\theta^k(1-\\theta)^{n-k}\\,d\\theta}.\n\\]\n\nWe recognise $\\pi_1(\\theta)$ as the PDF of the $\\text{Beta}(\\alpha,\\beta)$ distribution, with parameters \n\\[\n\\alpha=k+1 \\text{\\quad and\\quad}\\beta=n-k+1.\n\\]\n\n\\bit\n\\it The mode of $\\pi_1(\\theta)$ is $k/n$. This is the MAP estimator of $\\theta$.\n\\it Note that this co-incides with the MLE of $\\theta$.\n\\eit\n\\bit\n\\it The expected value of $\\pi_1(\\theta)$ is $(k+1)/(n+2)$.\n\\it This is approximately equal to the MAP estimator when $k$ and $n$ are both large.\n\\eit\n\n\\it % <<< (ii)\nGiven $k'$ successes in $n$ trials, the likelihood function is\n\\[\nL(\\theta|k') = f(k'|\\theta) = \\binom{n}{k'}\\theta^{k'}(1-\\theta)^{n-k'}.\n\\]\n\nUsing $\\pi_1$ as the new prior distribution for $\\theta$, the new posterior distribution $\\pi_2$ is\n\\[\n\\pi_2(\\theta) = \n\\pi_2(\\theta|k,k')\t\n\t= \\frac{L(\\theta|k')\\pi_1(\\theta)}{\\int_0^1 L(\\theta|k')\\pi_1(\\theta)\\,d\\theta} \n\t= \\frac{\\theta^{k+k'}(1-\\theta)^{2n-(k+k')}}{\\int_0^1\\theta^{k+k'}(1-\\theta)^{2n-(k+k')}\\,d\\theta}.\n\\]\n\nWe recognise $\\pi_2(\\theta)$ as the PDF of the $\\text{Beta}(\\alpha,\\beta)$ distribution, with parameters \n\\[\n\\alpha=k+k'+1 \\text{\\quad and\\quad}\\beta=2n-(k+k')+1.\n\\]\n\nHence our updated MAP estimate of $\\theta$ is\n\\[\n\\hat{\\theta}_{MAP} = \\frac{k+k'}{2n}.\n\\]\n\n\\bit\n\\it If $k'<k$, the mode shifts to the left (adjusted down).\n\\it If $k'>k$, the mode shifts to the right (adjusted up).\n\\eit\n\\een\n\\end{solution}\n\n%----------------------------------------------------------------------\n\\section{The exponential model}\n%----------------------------------------------------------------------\nA suitable model for estimating the distribution of a non-negative parameter $\\theta\\geq 0$ is provided by the \\emph{gamma distribution}.\n\n% definition\n\\begin{definition}\\label{def:gamma_distribution}\nThe \\emph{gamma distribution} with parameter $\\alpha,\\beta>0$ is defined by the PDF\n\\[\nf(x;\\alpha,\\beta) = \\begin{cases}\n\t\\displaystyle\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\, x^{\\alpha-1} e^{-\\beta x} & \\text{for $x>0$}, \\\\\n\t0\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nwhere $\\Gamma(\\alpha)$ is the so-called \\emph{gamma function},\n\\[\n\\Gamma(\\alpha) = \\int_0^{\\infty} t^{\\alpha-1}e^{-t}\\,dt,\n\\quad\\text{which is defined for all $\\alpha\\in\\R$.}\n\\]\n\\end{definition}\n\n%% remark\n%\\begin{remark}[Special cases]\n%\\bit\n%\\it If $X\\sim\\text{Exponential}(\\lambda)$, where $\\lambda$ is a rate parameter, then $X\\sim\\text{Gamma}(1,\\lambda)$.\n%\\it If $X\\sim\\text{Chi-squared}(k)$ then $X\\sim\\text{Gamma}(k/2,2)$\n%\\eit\n%\\end{remark}\n\n% lemma\n\\begin{lemma}\nLet $X\\sim\\text{Gamma}(\\alpha,\\beta)$. Then $\\expe(X) = \\displaystyle\\frac{\\alpha}{\\beta}$ and $\\mode(X) = \\displaystyle\\frac{\\alpha-1}{\\beta}$ provided that $\\alpha > 1$.\n%\\quad\\text{and}\\quad \n%(2)\\quad \\mode(X) = \\frac{\\alpha-1}{\\beta}\n%\\text{ provided that $\\alpha > 1$}.\n%\\]\n\\end{lemma}\n% proof\n\\begin{proof}\nExercise.\n\\end{proof}\n\n% example: exponential\n\\begin{example}\nLet $X\\sim\\text{Exponential}(\\lambda)$, where $\\lambda>0$ is an unknown rate parameter. Let $X_1,X_2,\\ldots,X_n$ be a random sample of observations from the distribution of $X$, and suppose that we adopt the $\\text{Gamma}(\\alpha,\\beta)$ distribution as a prior distribution for $\\lambda$, where $\\alpha,\\beta>0$ are fixed values (perhaps estimated in some preliminary experiments). \n\n\\ben\n\\it Find the mean and mode of the prior distribution.\n\\it Show that the posterior of $\\lambda$ is the $\\text{Gamma}(\\alpha+n,\\beta+\\sum_{i=1}^n x_i)$ distribution.\n\\it Find the mean and mode of the posterior distribution.\n\\een\n\\end{example}\n\n% solution\n\\begin{solution}\nLet $f(x|\\lambda)$ be the PDF of the $\\text{Exponential}(\\lambda)$ distribution:\n\\[\nf(x|\\lambda) = \\left\\{\\begin{array}{ll}\n\t\\lambda\\exp(-\\lambda x) & \\text{for $x>0$}, \\\\\n\t0\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{array}\\right.\n\\]\n\nThe PDF of the prior distribution is\n\\[\n\\pi_0(\\lambda) = \t\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\,\\lambda^{\\alpha-1}\\exp(-\\beta\\lambda).\n\\]\nwhich has mean $\\alpha/\\beta$ and mode $(\\alpha-1)/\\beta$.\n\nLet $\\boldx$ be a realisation of the sample. The likelihood function is\n\\[\nL(\\lambda|\\mathbf{x}) \n\t= \\prod_{i=1}^n f(x_i|\\lambda)\n\t= \\prod_{i=1}^n \\lambda\\exp(-\\lambda x_i)\n\t= \\lambda^n \\exp\\Big(-\\lambda\\textstyle\\sum_{i=1}^n  x_i\\Big).\n\\]\n\nThe PDF of the posterior distribution is\n\\[\n\\pi_1(\\lambda|\\mathbf{x})\t\n\t= \\frac{L(\\lambda|\\mathbf{x})\\pi_0(\\lambda)}{\\displaystyle\\int_0^{\\infty} L(\\lambda|\\mathbf{x})\\pi_0(\\lambda)\\,d\\lambda}.\n\\]\n\nThe numerator is the product of the likelihood $L(\\lambda|\\mathbf{x})$ and the prior $\\pi_0(\\lambda)$:\n\\begin{align*}\nL(\\lambda|\\mathbf{x})\\pi_0(\\lambda)\n\t& = \\Big[\\lambda^n \\exp\\big(-\\lambda\\textstyle\\sum_{i=1}^n  x_i\\big)\\Big]\\left[\\displaystyle\\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\lambda^{\\alpha-1}\\exp(-\\beta\\lambda)\\right] \\\\[1ex]\n\t& = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)} \\lambda^{\\alpha+n-1}\\exp\\Big[-\\big(\\beta+\\textstyle\\sum_{i=1}^n x_i\\big)\\lambda\\Big]\n\\end{align*}\n\n%Notice that this resembles the PDF of the $\\text{Gamma}\\Big(\\alpha+n,\\beta+\\sum_{i=1}^n x_i\\Big)$ distribution.\n\nThe PDF of the posterior distribution becomes\n\\[\n\\pi_1(\\lambda|\\mathbf{x})\t\n\t= \\frac{\\lambda^{\\alpha+n-1}\\exp\\Big[-\\big(\\beta+\\sum_{i=1}^n x_i\\big)\\lambda\\Big]}\n\t\t{\\displaystyle\\int_0^{\\infty} \\lambda^{\\alpha+n-1}\\exp\\Big[-\\big(\\beta+\\sum_{i=1}^n x_i\\big)\\lambda\\Big]\\,d\\lambda}\n\\]\n\nTo compute the denominator, change the variable of integration to $t = -\\big(\\beta+\\sum_{i=1}^n x_i\\big)\\lambda$. This yields\n\\[\n\\int_0^{\\infty} \\lambda^{\\alpha+n-1}\\exp\\Big[-\\big(\\beta+\\textstyle\\sum_{i=1}^n x_i\\big)\\lambda\\Big]\\,d\\lambda \n\t= \\displaystyle\\frac{\\Gamma(\\alpha+n)}{\\big(\\beta+\\sum_{i=1}^n x_i\\big)^{\\alpha+n}}\n\\]\n\nThus the PDF of the posterior distribution is \n\\[\n\\pi_1(\\lambda|\\mathbf{x})\t\n\t= \\frac{\\big(\\beta+\\sum_{i=1}^n x_i\\big)^{\\alpha+n}}{\\Gamma(\\alpha+n)}\n\t\\lambda^{\\alpha+n-1}\\exp\\Big[-\\big(\\beta+\\sum_{i=1}^n x_i\\big)\\lambda\\Big]\n\\]\nwhich is the PDF of the $\\text{Gamma}\\Big(\\alpha+n,\\beta+\\sum_{i=1}^n x_i\\Big)$ distribution.\n\n % << \n\nThe mean and mode of $\\lambda\\sim\\text{Gamma}\\Big(\\alpha+n,\\beta+\\sum_{i=1}^n x_i\\Big)$ are\n\\[\n\\expe(\\lambda) = \\frac{\\alpha+n}{\\beta+\\sum_{i=1}^n x_i}\n\\text{\\quad and\\quad}\n\\text{Mode}(\\lambda) = \\frac{\\alpha+n-1}{\\beta+\\sum_{i=1}^n x_i}\n\\text{\\quad respectively.}\n\\]\nHence the MAP estimator of $\\lambda$ is\n\\[\n\\hat{\\lambda}_{MAP} = \\frac{\\alpha+n-1}{\\beta+\\sum_{i=1}^n x_i}\n\\]\n\n\\bit\n\\it When $n=0$, this is simply the mode of the prior distribution, $\\text{Gamma}(\\alpha,\\beta)$.\n\\it As $n$ increases, the influence of the prior distribution decreases.\n\\it If we write $\\hat{\\lambda}_{MAP}$ as\n\\[\n\\hat{\\lambda}_{MAP} \n\t= \\frac{1 + \\left(\\frac{\\alpha-1}{n}\\right)}{\\frac{1}{n}\\sum_{i=1}^n x_i + \\left(\\frac{\\beta}{n}\\right)}.\n\\]\nwe see that $\\hat{\\lambda}_{MAP}=\\bar{X}^{-1}$ as $n\\to\\infty$.\n\\it This is the method-of-moments estimator (MME) of $\\lambda$, which is based entirely on the data and takes no account of the prior distribution.\n\\eit\n\\end{solution}\n\n%----------------------------------------\n\\begin{exercise}\n\\begin{questions}\n\n\\question \nLet $X\\sim\\text{Geometric}(\\theta)$ where $0<\\theta<1$ is unknown. \n\\begin{parts}\n\\part % << (i)\nA single experiment yields the observation $k$. Find a suitable prior distribution for $\\theta$, compute the corresponding posterior distribution, and find the MAP estimator of $\\theta$ for this posterior.\n\\begin{answer}\nLet $f(x|\\theta)$ be the PMF of the $\\text{Geometric}(\\theta)$ distribution:\n\\[\nf(x|\\theta) = \\theta^x(1-\\theta)^{n-x}\n\\]\nWithout any information about $\\theta$, we should choose the \\emph{na\\\"{\\i}ve} prior:\n\\[\n\\pi_0(\\theta) = \\begin{cases}\n\t1\t& \\text{if $0\\leq\\theta\\leq 1$,} \\\\\n\t0\t& \\text{otherwise.}\n\\end{cases}\n\\]\nFor the observation $X=k$, the likelihood function is\n\\[\nL(\\theta|k) = f(k|\\theta) = \\theta(1-\\theta)^{k-1}\n\\]\nThe posterior distribution is:\n\\[\n\\pi_1(\\theta|k)\t\n\t= \\frac{L(\\theta|k)\\pi_0(\\theta)}{\\int L(\\theta|k)\\pi_0(\\theta)\\,d\\theta}\n\t= \\frac{\\theta(1-\\theta)^{k-1}}{\\int_0^1\\theta(1-\\theta)^{k-1}\\,d\\theta}.\n\\]\nWe recognise this as the PDF of the $\\text{Beta}(\\alpha,\\beta)$ distribution, with parameters $\\alpha=2$ and $\\beta=k$. The mode of the $\\text{Beta}(\\alpha,\\beta)$ distribution is $(\\alpha-1)/(\\alpha+\\beta-2)$, so the MAP estimator is\n\\[\n\\hat{\\theta}_{MAP} = \\frac{1}{k}.\n\\]\n\\end{answer}\n\\part % << (ii)\nA second experiment yields the observation $k'$. Compute an updated posterior distribution for $\\theta$, and find a new MAP estimator for $\\theta$.\n\\begin{answer}\nFor the observation $X=k'$, the likelihood function is\n\\[\nL(\\theta|k') = f(k'|\\theta) = \\theta(1-\\theta)^{k'-1}\n\\]\nUsing $\\pi_1$ as the new prior distribution for $\\theta$, the new posterior distribution $\\pi_2$ is\n\\[\n\\pi_2(\\theta|k,k')\t\n\t= \\frac{L(\\theta|k')\\pi_1(\\theta)}{\\int_0^1 L(\\theta|k')\\pi_1(\\theta)\\,d\\theta} \n\t= \\frac{\\theta^2(1-\\theta)^{k+k'-2}}{\\int_0^1\\theta^2(1-\\theta)^{k+k'-2}\\,d\\theta}.\n\\]\nwhich we recognise as the PDF of the $\\text{Beta}(\\alpha,\\beta)$ distribution, with parameters $\\alpha=3$ and $\\beta=k+k'-1$. Hence the new MAP estimator is\n\\[\n\\hat{\\theta}_{MAP} = \\frac{2}{k+k'}.\n\\]\n\\end{answer}\n\\end{parts}\n\n\\question \nLet $X\\sim\\text{Poisson}(\\lambda)$, where $\\lambda>0$ is unknown, and let $X_1,X_2,\\ldots,X_n$ be a random sample of observations from the distribution of $X$. Suppose we adopt the $\\text{Gamma}(\\alpha,\\beta)$ distribution as a prior distribution for $\\lambda$, where $\\alpha,\\beta>0$ are fixed values.  \n\\begin{parts}\n\\part % << (i)\nShow that the MAP estimator of $\\lambda$ is given by\n\\[\n\\hat{\\lambda}_{MAP} = \\frac{\\alpha-1+\\sum_{i=1}^n X_i}{n+\\beta}\n\\]\n\\begin{answer}\nLet $f(x|\\lambda)$ be the PMF of the $\\text{Poisson}(\\lambda)$ distribution:\n\\[\nf(x|\\lambda) = \\begin{cases}\n\t\\frac{\\lambda^{x}e^{-\\lambda}}{x!} & \\text{for $x=0,1,2,\\ldots$}, \\\\\n\t0\t\t\t\t\t\t\t& \\text{otherwise.}\n\\end{cases}\n\\]\nThe PDF of the prior distribution is\n\\[\n\\pi_0(\\lambda) = \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\,\\lambda^{\\alpha-1}\\exp(-\\beta\\lambda).\n\\]\nwhich has mean $\\alpha/\\beta$ and mode $(\\alpha-1)/\\beta$.\n\nLet $\\boldx=(x_1,x_2,\\ldots,x_n)$ be a realisation of the sample. The likelihood function is\n\\[\nL(\\lambda|\\mathbf{x}) \n\t= \\prod_{i=1}^n f(x_i|\\lambda)\n\t= \\prod_{i=1}^n \\frac{\\lambda^{x_i}e^{-\\lambda}}{x_i!}\n\t= \\lambda^{\\sum x_i} e^{-n} \\prod_{i=1}^n \\frac{1}{x_i!}\n\\]\nThe PDF of the posterior distribution is\n\\[\n\\pi_1(\\lambda|\\mathbf{x})\t\n\t= \\frac{L(\\lambda|\\mathbf{x})\\pi_0(\\lambda)}{\\int_0^{\\infty} L(\\lambda|\\mathbf{x})\\pi_0(\\lambda)\\,d\\lambda}.\n\\]\nTo find the MAP estimator, we need to find the value of $\\lambda$ that maximises the numerator:\n\\[\nL(\\lambda|\\mathbf{x})\\pi_0(\\lambda)\n\t= c\\lambda^{(\\alpha-1+\\sum x_i)} e^{-(n+\\beta)\\lambda}\n\t\\quad\\text{where}\\quad\n\tc = \\left(\\prod_{i=1}^n \\frac{1}{x_i!}\\right) \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}\n\\]\nLet $g(\\lambda)=\\lambda^{\\alpha-1+\\sum x_i} e^{-(n+\\beta)\\lambda}$. Then\n\\[\ng'(\\lambda) = \\lambda^{(\\alpha-2+\\sum x_i)} e^{-(n+\\beta)\\lambda}\\left[(\\alpha-1+\\sum _{i=1}^n x_i) - \\lambda(n+\\beta)\\right]\n\\]\nSetting $g'(\\lambda)$ to zero and solving for $\\lambda$, we obtain the MAP estimator\n\\[\n\\hat{\\lambda}_{MAP} = \\frac{\\alpha-1+\\sum_{i=1}^n X_i}{n+\\beta}\n\\]\nas required.\n\\end{answer}\n\\part % << (ii)\nComment on the limiting cases (i) $n=0$ and (ii) $n\\to\\infty$.\n\\begin{answer}\n\\bit\n\\it When $n=0$, $\\hat{\\lambda}_{MAP}=(\\alpha-1)/\\beta$ is the mode of the prior distribution.\n\\it When $n\\to\\infty$, \n\\[\n\\hat{\\lambda}_{MAP}\n\t= \\frac{\\frac{\\alpha-1}{n}+\\frac{1}{n}\\sum_{i=1}^n X_i}{1+\\frac{\\beta}{n}}\n\t\\to \\frac{1}{n}\\sum_{i=1}^n X_i\n\\]\nAs the sample size increases, the effect of the prior decreases, and the MAP estimator approaches the sample mean in the limit as $n\\to\\infty$.\n\\eit\n\\end{answer}\n\\end{parts}\n\n\\question \nLet $X_1,\\ldots,X_n$ be a random sample from the $N(\\mu,\\sigma^2)$ distribution, where the mean $\\mu$ is unknown but the variance $\\sigma^2$ is known. Suppose we adopt the $N(\\mu_0,\\sigma_0^2)$ distribution as a prior for the unknown mean $\\mu$ (where $\\mu_0$ and $\\sigma_0^2$ are known constants). Compute the maximum a-posteriori (MAP) estimator of $\\mu$.\n\n\\begin{answer}\nLet $\\pi_0(\\mu)$ denote the prior density function of $\\mu$:\n\\[\n\\pi_0(\\mu) = \\frac{1}{\\sigma_0\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{\\mu-\\mu_0}{\\sigma_0}\\right)^2\\right].\n\\]\n\nFor the observed sequence $\\mathbf{x}=(x_1,x_2,\\ldots,x_n)$, the likelihood function is\n\\begin{align*}\nL(\\mu\\,|\\,\\mathbf{x}) \n\t& = \\prod_{i=1}^n \\left(\\frac{1}{\\sigma\\sqrt{2\\pi}}\\right)\\exp\\left[-\\frac{1}{2}\\left(\\frac{x_i-\\mu}{\\sigma}\\right)^2\\right] \\\\\n\t& = \\left(\\frac{1}{\\sigma\\sqrt{2\\pi}}\\right)^{n/2}\\exp\\left[-\\frac{1}{2}\\sum_{i=1}^n\\left(\\frac{x_i-\\mu}{\\sigma}\\right)^2\\right].\n\\end{align*}\n\nThe posterior density function of $\\mu$ combines the data and the prior:\n\\begin{align*}\n\\pi_1(\\mu)\t\n\t& = \\frac{L(\\mu\\,|\\,\\mathbf{x})\\pi_0(\\mu)}{\\int L(\\mu|\\mathbf{x})\\pi_0(\\mu)\\,d\\mu}.\n\\end{align*}\n\nThe MAP estimator of $\\mu$ is the value that maximises the posterior $\\pi_1(\\mu)$. Since the denominator in the above expression for $\\pi_1$ is a constant, it is sufficient to find the value of $\\mu$ that maximises the numerator,\n\\begin{align*}\nL(\\mu|\\mathbf{x})\\pi_0(\\mu)\n\t= \\left(\\frac{1}{\\sigma_0\\sqrt{2\\pi}}\\right)\\left(\\frac{1}{\\sigma\\sqrt{2\\pi}}\\right)^{n/2}\n\t\t\t\\exp\\left[-\\frac{1}{2}\\sum_{i=1}^n\\left(\\frac{x_i-\\mu}{\\sigma}\\right)^2 -\\frac{1}{2}\\left(\\frac{\\mu-\\mu_0}{\\sigma_0}\\right)^2\\right].\n\\end{align*}\nLet \n\\[\ng(\\mu) = \\exp\\left[-\\frac{1}{2}\\sum_{i=1}^n\\left(\\frac{x_i-\\mu}{\\sigma}\\right)^2 -\\frac{1}{2}\\left(\\frac{\\mu-\\mu_0}{\\sigma_0}\\right)^2\\right].\n\\]\nThe value of $\\mu$ that maximizes $L(\\mu|\\mathbf{x})\\pi_0(\\mu)$ also maximizes $g(\\mu)$. The first derivative of $g$ with respect to $\\mu$ is\n\\[\ng'(\\mu) = \\left[\\frac{1}{\\sigma^2}\\sum_{i=1}^n (x_i-\\mu) - \\frac{1}{\\sigma_0^2} (\\mu-\\mu_0)\\right]g(\\mu).\n\\]\nSetting this equal to zero,\n\\[\n\\frac{1}{\\sigma^2}\\sum_{i=1}^n (x_i-\\mu) = \\frac{1}{\\sigma_0^2}(\\mu-\\mu_0),\n\\]\nand solving for $\\mu$, we obtain the MAP estimator,\n\\[\n\\hat{\\mu}_{MAP} = \\left(\\frac{\\sigma^2\\sigma_0^2}{\\sigma^2+n\\sigma_0^2}\\right)\\left(\\frac{1}{\\sigma^2}\\sum_{i=1}^n x_i + \\frac{\\mu_0}{\\sigma_0^2}\\right).\n\\]\n\\bit\n\\it This expression can be rearranged to give\n\\[\n\\hat{\\mu}_{MAP}\\left(1 + \\frac{n\\sigma_0^2}{\\sigma^2}\\right) = \\frac{\\sigma_0^2}{\\sigma^2}\\sum_{i=1}^n x_i + \\mu_0.\n\\]\nThis shows that $\\hat{\\mu}=\\mu_0$ when $n=0$, so the $\\hat{\\mu}_{MAP}$ is equal to the mean of the prior distribution when there is no data. \n\\it The expression can also be rearranged to give\n\\[\n\\hat{\\mu}_{MAP}\\left(1 + \\frac{\\sigma^2}{n\\sigma_0^2}\\right) = \\frac{1}{n}\\sum_{i=1}^n x_i + \\left(\\frac{\\sigma^2}{n\\sigma_0^2}\\right)\\mu_0.\n\\]\nThis shows that $\\hat{\\mu}_{MAP} \\to \\bar{X}$ as $n\\to\\infty$ (which is independent of the prior).\n\\eit\n\\end{answer}\n\n%----------------------------------------\n\\end{questions}\n\\end{exercise}\n%----------------------------------------------------------------------\n\n\n", "meta": {"hexsha": "9e2ee3d4ac6c1cd4826301f451568e760a937de9", "size": 35425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/13_bayesian_inference.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/13_bayesian_inference.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/13_bayesian_inference.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.1918604651, "max_line_length": 382, "alphanum_fraction": 0.6381651376, "num_tokens": 12221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7953342131498955}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nIf we had an algorithm that finds the median of a sequence in linear time (worst case) - \\textsc{findMedian($A$, $p$, $r$)} which returns the index of the median of the sequence $A[p..r]$, describe a worst-case linear time algorithm that finds any order statistics.\nProvide a brief run-time analysis.\n\n\\subsection*{Solution}\n\nTo obtain any order statistics of a sequence \\textsc{findMedian($A$, $p$, $r$)} can be called to check if order is less than median, as proposed by Algorithm \\ref{alg2}.\n\nAlthough in worst case \\textsc{findMedian} is called $\\log n$ times, because the length of array that is given to \\textsc{findMedian} is different each time, the eventual runtime would be linear in $n$.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{findOrder($A$, $p$, $r$, $s$)}}\\label{alg2}\n\\begin{algorithmic}[1]\n\\State $q \\leftarrow $ \\textsc{findMedian($A$, $p$, $r$)}\n\\State \\textsc{Partition($A$, $p$, $r$, $q$)}\n\\If {$s < q$}\n\\State \\Return \\textsc{findMedian($A$, $p$, $q$)}\n\\ElsIf {$s = q$}\n\\State \\Return $A[q]$\n\\Else\n\\State \\Return \\textsc{findMedian($A$, $q$, $r$)}\n\\EndIf\n\\end{algorithmic}\n\\end{algorithm}\n\nwhere \\textsc{Partition($A$, $p$, $r$, $q$)} is a simple algorithm that partitions the array around pivot element with index $q$, as shown in Algorithm \\ref{alg3}.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Partition($A$, $p$, $r$, $q$)}}\\label{alg3}\n\\begin{algorithmic}[1]\n\\State $i \\leftarrow p - 1 $\n\\For {$j \\leftarrow p$ to $r - 1$}\n\\If {$A[j] \\leq q$}\n\\State $i \\leftarrow i + 1$\n\\State exchange A[i] with A[j]\n\\EndIf\n\\State exchange A[i+1] with A[r]\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\nA more rigorous run-time analysis can be obtained using recursion $T(n) = T(\\frac{n}{2}) + \\mathcal{O}(n)$.\nAs $T(\\frac{n}{2}) \\leq \\mathcal{O}(n)$ for all $n$, runtime would be bound by $O(n)$.\n", "meta": {"hexsha": "c450a36d1fcc71604a3f57c2101b377addf4c86c", "size": 2180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m01/m01q04.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/m01/m01q04.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/m01/m01q04.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 41.9230769231, "max_line_length": 265, "alphanum_fraction": 0.6449541284, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736773, "lm_q2_score": 0.9173026522382527, "lm_q1q2_score": 0.7953342083551911}}
{"text": "%----------------------------------------------------------------------------------------\n%   NEWTON-RAPHSON\n%----------------------------------------------------------------------------------------\n\n\\section{Newton-Raphson Method}\n\\subsection{Simple Newton-Raphson Algorithm}\n\nLet $f:\\mathbb{R}^{n}\\rightarrow \\mathbb{R}^{m}$ be a function that is differentiable along both dimentions. $f$ and its derivatives are defined as following:\n\\[f: \n\\begin{pmatrix}\n    x_1\\\\\n    \\vdots\\\\\n    x_N\n  \\end{pmatrix} \n  \\rightarrow\n  \\begin{pmatrix}\n    f_1(x_1,...,X_N)\\\\\n    \\vdots\\\\\n    f_N(x_1,...,x_N)\n  \\end{pmatrix},\\ \n  H: \\begin{pmatrix}\n    x_1\\\\\n    \\vdots\\\\\n    x_N\n  \\end{pmatrix}\n  \\rightarrow\n  \\begin{pmatrix}\n    \\frac{\\partial f_i(x_1,...,x_N)}{\\partial x_j}\n  \\end{pmatrix}_{i \\in [1,N], j \\in[1,N]},\n\\]\nwhere $H$ is the Jacobian matrix of $f$. \n\nThe Newton-Raphson method tries to solve the equation $f(U) = 0$. It assumes that given a current position $U$, the best direction leading to a root of the function is the direction given by the slope of $f$ at $U$.\n\nLet $U$ be an initial position chosen arbitrary. The algorithm looks for a point $V$ such that:\n\\[\nf(U+V) = 0\n\\]\nAnd\n\\begin{equation}\nf(U+V) = f(U) + H(U).V\n\\label{eq:equation1}\n\\end{equation}\nIt is easy to notice that:\n\\begin{equation}\nf(U) + H(U).V = 0\n\\label{eq:equation2}\n\\end{equation}\n\nThen, $U$ is replaced by $U+V$, and the process is repeated until either $U$ converges or a maximum number of iterations is reached. The Taylor approximation in Equation~\\vref{eq:equation1} ensures that we are looking for the root in the direction of the slope. However, no guarantee is given that the point reached at the end of this direction is minimizing the function $f$.\n\nThis is why the Newton-Raphson method has an unfortunate tendency to diverge if the initial guess is not sufficiently close to the root.   \n\n\\subsection{Backtracking}\nA global method is a one that converges to a solution from almost any starting point. In this section we will develop an algorithm called backtracking that combines the rapid superlinear speed of convergence of Newton's method, with a globally convergent strategy that will guarantee some progress towards the solution at each iteration. In other words, at each step of the algorithm, the next point given by Equation~\\vref{eq:equation2} is only chosen if it minimizes the function. Figure~\\vref{fig:backtracking} shows the full algorithm.\n\nThe complexity of the algorithm is $\\Theta(N x c)$ - $c$ is the complexity of the function solve.\n\n\\begin{figure}[ht]\n  \\centering\n  \\begin{algorithm}[H]\n    \\KwData{$f$: a function, $H$: the jacobian matrix of $f$, $U_0$: a starting position, $N$: maximal number of iterations, $\\varepsilon$: precision.}\n    \\KwResult{$U$: a root of $f$}\n    $U \\leftarrow U_0$\\\\\n    tmp $\\leftarrow 1$\\\\\n    \\For{$i$ from $1$ to $N$}{\n      $V \\leftarrow \\text{solve}(f(U) + H(U).V = 0)$\\\\\n      \\While{$\\|f(U + \\text{step}*V)\\|> \\|f(U)\\|$}{$\\text{step} \\leftarrow \\text{step}*2/3$}\n        $U \\leftarrow U + \\text{step}*V$\\\\\n        \\If{$\\|f(U)< \\varepsilon\\|$}\n          {return $U$}\n    }\n    return $U$\\\\\n  \\end{algorithm}\n  \\caption{Backtracking algorithm}\n  \\label{fig:backtracking}\n\\end{figure}\n \n\\subsection{Tests}\nOne way to easily test this method is to check if the point returned $U$ is a root of $f$. This can be done by computing $f(U)$. The next figures show the speed of...\n%Julien s'occupe de finaliser d'après ce qu'il m'a dit ", "meta": {"hexsha": "9d0ce2362465d0ea2bd15e98eb1dfe0447010d76", "size": 3481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-non-linear-systems-newton-raphson/doc/newton_raphson.tex", "max_stars_repo_name": "gdzx/numerical-algorithms", "max_stars_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_stars_repo_licenses": ["MIT"], "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-non-linear-systems-newton-raphson/doc/newton_raphson.tex", "max_issues_repo_name": "gdzx/numerical-algorithms", "max_issues_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_issues_repo_licenses": ["MIT"], "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-non-linear-systems-newton-raphson/doc/newton_raphson.tex", "max_forks_repo_name": "gdzx/numerical-algorithms", "max_forks_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_forks_repo_licenses": ["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.975308642, "max_line_length": 539, "alphanum_fraction": 0.6529732835, "num_tokens": 1029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8918110404058914, "lm_q1q2_score": 0.7953269388418241}}
{"text": "\\lab{Monte-Carlo Integration}{Monte-Carlo Integration}\n\\objective{Use Monte-Carlo integration to estimate areas.}\n\nSome multivariable integrals which are critical in applications are impossible to evaulate symbolically.\nFor example, the integral of the joint normal distribution\n\\[\n\\int_{\\Omega} \\frac{1}{\\sqrt{(2 \\pi)^k}} e^{- \\frac{\\bold{x}^T\\bold{x}}{2}}\n\\]\nis ubiquitous in statistics.\nHowever, the integrand does not have a symbolic antiderivative.\nThis means we must use numerical methods to evaluate this integral.\n\nThe standard technique for numerically evaluating multivariable integrals is \\emph{Monte-Carlo Integration}.\nMonte-Carlo (MC) integration is radically different from 1-dimensional techniques like Simpson's rule, relying on probability to calculate the integral.\nAlthough it converges slowly, MC integration is frequently used to evaluate multivariable integrals because the higher-dimensional analogs of methods like Simpson's rule are inefficient. \n\n\\section*{A motivating example}\nSuppose we want to numerically compute the area of a circle of radius 1.\nFrom analytic methods, we know the answer is $\\pi$.\nEmpirically, we can estimate this quantity by randomly choosing points in a $2 \\times 2$ square.\nThe percent of points that land in the inscribed circle, times the area of the square, should approximately equal the area of the circle (see Figure \\ref{fig:MCCircle}).\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{MC_Circle.pdf}\n\\caption{Finding the area of a circle using random points}\n\\label{fig:MCCircle}\n\\end{figure}\n\nWe do this in NumPy as follows. First generate 500 random points in the square $[0,1] \\times [0,1]$.\n\\begin{lstlisting}\n>>> numPoints = 500\n>>> points = np.random.rand(2, numPoints)\n\\end{lstlisting}\nWe rescale and shift these points to be uniformly distributed in $[-1,1]\\times[-1,1]$.\n\\begin{lstlisting}\n>>> points = points*2-1\n\\end{lstlisting}\nNext we compute the number of points in the unit circle.\nThe function \\li{np.hypot(a, b)} returns the norm of the vector $(a, b)$.\n\\begin{lstlisting}\n>>> # Create a mask of points in the circle\n>>> circleMask = np.hypot(points[0,:], points[1,:]) <= 1\n>>> # Count how many there are\n>>> numInCircle = np.count_nonzero(circleMask)\n\\end{lstlisting}\nFinally, we approximate the area.\n\\begin{lstlisting}\n>>> # Area is approximately (area of the square)*(num points in circle)/(total num points)\n>>> 4.*numInCircle/numPoints\n3.024\n\\end{lstlisting}\nThis differs from $\\pi$ by about 0.117.\n\n\n\n\n\n\nWe analyze the error of the MC method by repeating this experiment for many values of \\li{numPoints} and plotting the errors.\nThe result is the blue line in Figure \\ref{fig:mc_error}.\nThe error appears to be proportional to $1/\\sqrt{N}$ where $N=$\\li{numPoints} (the green line in Figure \\ref{fig:mc_error}).\nThis means that to divide the error by10, we must sample \\emph{100 times} more points.\n\n\\begin{figure}\n\\includegraphics[width=.7\\textwidth]{mc_error.pdf}\n\\caption{The Monte-Carlo integration method was used to compute the area of a circle of radius 1. \nThe blue line plots the average error in 100 runs of the MC method on $N$ sample points, where $N$ appears on the horizontal axis.\nThe green line is a plot of $1/\\sqrt{N}$. }\n\\label{fig:mc_error}\n\\end{figure}\n\nThis is a slow convergence rate, but it is independent of the number of dimensions of the problem. \nThis dimension independence is what makes the MC method useful for multivariable integrals.\n\n\\section*{Monte-Carlo Integration}\n\nYou can calculate the area of the unit circle with the following integration problem:\n\\[\n\\mbox{Area of unit circle } = \\int_{[-1,1]\\times[-1,1]} f(x,y) dA\n\\]\nwhere\n\\begin{equation}\\label{equ:mc_func}\nf(x,y) = \\begin{cases} 1 &\\mbox{ if $x$,$y$ is in the unit circle} \\\\ 0 &\\mbox{ otherwise.} \\end{cases}\n\\end{equation}\n\nWe can use a random-points method as above to approximate any integral.\nSuppose we with to evaluate\n\\[\n\\int_\\Omega f(x) dV.\n\\]\nWe can approximate this integral using the formula\n\\begin{equation}\\label{equ:mc_eq}\n\\int_\\Omega f(x) dV \\approx V(\\Omega) \\frac{1}{N} \\sum_{i=1}^N f(x_i),\n\\end{equation}\nwhere $x_i$ are uniformly distributed random vectors in $\\Omega$ and $V(\\Omega)$ is the volume of $\\Omega$.\nThis is the formula for Monte-Carlo Integration. \n\n\nIn our example, $\\Omega$ was the box $[-1,1] \\times [-1,1]$ and $f$ was the function defined in \\eqref{equ:mc_func}.\nThen $\\sum_{i=1}^N f(x_i)$ is the number of points in the unit circle, $N$ is the total number of points, and \\eqref{equ:mc_eq} is the same as the formula we derived previously.\n\nThe intuition behind \\eqref{equ:mc_eq} is that $\\frac{1}{N} \\sum_{i=1}^N f(x_i)$ approximates the average value of $f$ on $\\Omega$.\nWe multiply this (approximate) average value by the volume of $\\Omega$ to get the (approximate) integral of $f$ on $\\Omega$.\n\nAs an 1-dimensional example consider the integral \n\\[\n\\int_0^1 x dx \\approx (1-0)\\frac{1}{N} \\sum_{i=1}^N x_i=\\frac{1}{N} \\sum_{i=1}^N x_i.\n\\]\n\nThe integral on the left-hand-side is $1/2$. \nIn the approximation on the right-hand-side, $x_i$ is drawn from a uniform distribution on $[0,1]$. \nThe average of $N$ such draws will converge to $1/2$. \n\n\\begin{problem}\n\\label{prob:mc}\nImplement Monte-Carlo integration with the following function.\nYour implementation should run the Monte-Carlo algorithm several times and return the average of those runs.\n\\begin{lstlisting}\ndef mc_int(f, mins, maxs, numPoints=500, numIters=100):\n    '''Use Monte-Carlo integration to approximate the integral of f\n    on the box defined by mins and maxs.\n    \n    INPUTS:\n    f         - A function handle. Should accept a 1-D NumPy array \n    \t \tas input.\n    mins      - A 1-D NumPy array of the minimum bounds on integration.\n    maxs      - A 1-D NumPy array of the maximum bounds on integration.\n    numPoints - An integer specifying the number of points to sample in \n    \t\tthe Monte-Carlo method. Defaults to 500.\n    numIters - An integer specifying the number of times to run the \n    \t\tMonte Carlo algorithm. Defaults to 100.\n\t\t\n    ALGORITHM:\n    Run the Monte-Carlo algorithm `numIters' times and return the average\n    of these runs.\n                \n    EXAMPLES:\n    >>> f = lambda x: np.hypot(x[0], x[1]) <= 1\n    >>> # Integral over the square [-1,1] x [-1,1] should be pi\n    >>> mc_int(f, np.array([-1,-1]), np.array([1,1]))\n    3.1290400000000007\n    '''\n\\end{lstlisting}\n\nHints:\n\\begin{enumerate}\n\\item To create a random array of points on which to evaluate \\li{f}, first create a random array of points in $[0,1] \\times \\ldots \\times [0,1]$.\nThen multiply this array by the appropriate vector to stretch it the right amount in each direction.\nFinally, add the appropriate vector to shift the points to the right location.\n\\item You can evaluate \\li{f} on an array of points in one line using \\li{np.apply_along_axis()}.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:mc_test}\nThe exact value of the integral of\n\\[\nf(w,x,y,z) = sin(x) y^5 -y^3 + zw + yz^3\n\\]\non $[-1,1]x[-1,1]x[-1,1]x[-1,1]$ is 0.\n\\begin{enumerate}\n\\item Run the function \\li{mc_int()} you wrote in Problem \\ref{prob:mc} on $f$ 10 sample points.\nDo this 100 times and take the average. What is the error?\n\\item Repeat part (1) of this problem with 100, 1000, and 10000 sample points. \nPlot the errors of your estimates.\n\\end{enumerate}\n\\end{problem}\n\\end{comment}\n\nOne application of Monte Carlo integration is integrating probability density functions that do not have closed form solutions.\n\n\\begin{comment}\n\\begin{problem}\nThe standard normal distribution is an important object of study in probability and statistic.\nIt is defined by the density function $\\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{x^2}{2}}$.\n(Here we are assuming a mean of $0$ and a variance of $1$).\nThis is a function that cannot be integrated symbolically.\nWe can use monte carlo integration to estimate the probability that a normally distributed random variable will take a value below a given point.\nThe probability that the random variable we are considering is less than (or equal to) a given value $x$ is\n\\[\\int_{-\\infty}^x \\frac{1}{\\sqrt{2 \\pi}} e^{- \\frac{t^2}{2}} dt\\]\nThis function is essentially zero for values of $x$ that lie reasonably far from the mean, so we can estimate this probability by integrating from $-5$ to $x$ instead.\n\nCompare your result at $x = 1$ with the output of the code\n\\begin{lstlisting}\nfrom scipy.stats import norm\nN = norm()\nN.cdf(1)\n\\end{lstlisting}\n\\end{problem}\n\\end{comment}\n\n\\begin{problem}\nThe joint normal distribution of $N$ independent random variables with mean 0 and variance 1 is\n\\[\nf(\\x) = \\frac{1}{\\sqrt{(2 \\pi)^N}} e^{- \\frac{\\x^T\\x}{2}}.\n\\]\nThe integral of $f(\\x)$ over a box is the probability that a draw from the distribution will be in the box.\nHowever, $f(\\x)$ does not have a symbolic antiderivative.\n\\begin{enumerate}\n\\item The integral of this function on $B = [-1,1]\\times [-1,1]\\times[-1,1] \\subset \\mathbb{R}^3$ can be computed in SciPy with the following code.\n\\begin{lstlisting}\nimport scipy.stats as stats\n\n# Define the bounds of the box to integrate over\nmins = np.array([-1, -1, -1])\nmaxs = np.array([1, 1, 1])\n\n# Each variable has mean 0 and variance 1\nmeans = np.zeros(3)\ncovs = np.ones(3)\n\n# Compute the integral\nvalue, inform = stats.mvn.mvnun(mins, maxs, means, covs)\n\\end{lstlisting}\nThen \\li{value} is the integral of $f(\\x)$ on $B$.\nUse SciPy to integrate $f(\\x)$ on $\\Omega=[-0.5, 0.75]\\times[0,1]\\times[0, 0.5]\\times[0,1] \\subset \\mathbb{R}^4$.\n\n\\item Use the function \\li{mc_int()} you wrote in Problem \\ref{prob:mc} to integrate $f(\\x)$ on $\\Omega$ with 10, 100, 1000, and 10,000 sample points. \nPlot the errors of your estimates.\n\\end{enumerate}\n\\end{problem}\n\n\n\\section*{A caution}\nYou can run into trouble if you try to use MC integration on an integral that does not converge.\nFor example, we may attempt to evaluate\n\\[\n\\int_0^1 \\frac{1}{x}\n\\]\nwith MC integragtion using the following code.\n\\begin{lstlisting}\n>>> k = 5000\n>>> np.mean(1/np.random.rand(k,1))\n21.237332864358656\n\\end{lstlisting}\n\nSince this code returns a finite value, so we could assume that this integral has a finite value.\nIn fact, the integral is infinite.\nWe could discover this emprically by using larger and larger values of $k$, and noting that MC integration returns larger and larger values.\n\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:mc_flawed}\nCreate a new function (based upon the function from Problem \\ref{prob:mc}) that uses a ``flawed'' random number generator that doesn't produce numbers between $-.95$ and $-1$. Test your method on the function from Problem \\ref{prob:mc_test}. How bad is the error? \n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "cb256160f6b1fffe20a557f6cc2aba59fa5ad0c3", "size": 10698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/MonteCarloIntegration/MC.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/MonteCarloIntegration/MC.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/MonteCarloIntegration/MC.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.9638554217, "max_line_length": 264, "alphanum_fraction": 0.7276126379, "num_tokens": 3049, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8887587824432529, "lm_q1q2_score": 0.7952519864622348}}
{"text": "\\subsection{Reinforcement Learning}\n\nA \\textbf{Markov decision process (MDP)} is defined by\n\na set of states  $s\\in S$ a set of actions $a \\in A$;\n\nAction dependent transition probabilities $T(s,a,s')=P(s'|s, a)$ , so that for each state  s  and action  a ,  $\\displaystyle \\sum _{s'\\in S} T(s,a,s')=1$.\n\nReward functions $R(s, a, s')$ representing the reward for starting in state  $s$ , taking action  $a$  and ending up in state  $s'$  after one step. (The reward function may also depend only on  $s$ , or only  $s$  and  $a$ .)\n\nTherefore a Markov decision process is defined by $MDP = <S,A,T,R>$ MDPs satisfy the Markov property in that the transition probabilities and rewards depend only on the current state and action, and remain unchanged regardless of the history (i.e. past states and actions) that leads to the current state.\n\nRewards collected after the  $n$th  step do not depend on the previous states $s_1,s_2,\\cdots,s_{n-1}$\n\n\\textbf{Markov properties:}\\\\\n\nRewards collected after the $n$th  step do not depend on the previous actions $a_1,a_2,\\cdots,a_{n}$\n\n\\textbf{(Infinite horizon) discounted reward based utility}\\\\\n\n\\begin{align*}\nU[s_0,s_1,\\ldots ]= R(s_0) + \\gamma R(s_1) + \\gamma ^2 R(s_2) \\ldots = \\\\\n= \\sum _{t=0}^\\infty \\gamma ^ t R(s_ t) \\text {where }0\\leq \\gamma <1\\\\\n\\leq \\frac{R_{max}}{1-\\gamma}\n\\end{align*}\n\n\\textbf{Bellman Equations}\\\\\n\nvalue fn $V^{*}(s)$ --  is the expected reward from starting at state $s$ and\nacting optimally, i.e. following the optimal policy;\\\\\n\\begin{enumerate}\n  \\item \\textbf{value fn} $V^{*}(s)$ – is the expected reward from starting at state $s$ and\nacting optimally, i.e. following the optimal policy;\n  \\item \\textbf{Q-function} $Q^{*}(s,a)$ –is the expected reward from starting at state $s$, then\nacting with action $a$(not necessarily the optimal action), and acting optimally\nafterwards.\n\\end{enumerate}\n\n$V^{*}(s) = \\underset {a}{max}Q^{*}(s,a)$\\\\\n\n$Q^{*}(s,a)=\\sum _{s'}T(s,a,s')[R(s,a,s')+\\gamma V^{*}(s')]$\\\\\n\nQ-value: $Q(s,a)$ in state $s$ take action $a$ and act optimally afterwards. \n\nPolicy $\\pi^*: s \\rightarrow a$ is set of actions to maximize the expected reward for every state $s$.\n\n\\begin{align*}\n&\\pi^*(s) = argmax_a(Q^*(s,a))\\\\\n&Q^*(s,a)= \\sum_{s'} T(s,a,s')[R(s,a,s') + \\gamma max_{a}Q(s',a')]\n\\end{align*}\n\nTo find the policy two algos: Value iteration and Q-value iteration (look online).\n\n\\textbf{Bellman optimality equation}\n$Q^*(s,a)=E[R_{t+1} + \\gamma \\underset{a}{\\max{Q^*(s,a)}}]$\n\n\\textbf{Q-value Iteration Update Rule}\\\\\n$Q_{k+1}^*(s, a) = \\sum _{s'} T(s, a, s')(R(s, a, s') + \\gamma \\text {max}_{a'} Q_ k^*(s', a')).$\n\n\n\n\\subsection{Q value iteration by sampling}\n\nExponential running average is defined as\\\\\n$\\bar{x}_n = (1-\\alpha)*\\bar{x}_{n-1} + \\alpha x_n$\\\\\n\\begin{align*}\n&Q_{i+1}(s, a) = (1-\\alpha)\\cdot Q_{i}(s, a) + \\alpha \\cdot sample_i(s,a)\\\\\n&Q_{i+1}(s, a) = Q_{i}(s, a) + \\alpha (Q_{i}(s, a) - sample_i(s,a))\\\\\n&Q_{i+1}(s, a) = Q_{i}(s, a) + \\alpha (Q_{i}(s, a) - (R(s,a,s')\n+ \\gamma max_{a}Q(s',a')))\n\\end{align*}\\\\\n$Q_{i}(s, a)$ is not the Q-value of the sample $i$, but the average Q-value up\nto the sample $i$ including.  It already embed all the experience up to\nsample $i$.\\\\\nThe above equation should recall those of the stochastic gradient descent,\nit’s just a different form of this update.\n\n\n\n\n\n", "meta": {"hexsha": "fb4bedf403fd01cb2cd94d95547f3f36bb2ae56e", "size": 3323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/reinforcement.tex", "max_stars_repo_name": "sharov-am/MITx_capstone_2", "max_stars_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_stars_repo_licenses": ["MIT"], "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/reinforcement.tex", "max_issues_repo_name": "sharov-am/MITx_capstone_2", "max_issues_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_issues_repo_licenses": ["MIT"], "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/reinforcement.tex", "max_forks_repo_name": "sharov-am/MITx_capstone_2", "max_forks_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_forks_repo_licenses": ["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.5243902439, "max_line_length": 305, "alphanum_fraction": 0.6560337045, "num_tokens": 1153, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7952335101235275}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nProve that if $x$ and $y$ are any two distinct vertices in a tree, there is a unique simple path from $x$ to $y$.\n\n\\subsection*{Solution}\n\nProof is given by contradiction.\nAssume the statement is false.\nThe opposite of the claimed statement is either there is no simple path from $x$ to $y$ or there are more than two different simple paths.\nThe former can be rejected simply by going back to definition of the tree which requires all vertices to be connected, reserving a simple path from each node to another.\nLet us assume there are more than one paths from $x$ to $y$, like $p_1$ and $p_2$.\n\n\\begin{equation}\np_1: x \\rightarrow v_1 \\rightarrow v_2 \\rightarrow \\cdots \\rightarrow v_{k-1} \\rightarrow y\n\\end{equation}\n\n\\begin{equation}\np_2: x \\rightarrow v_{1}^{\\prime} \\rightarrow v_{2}^{\\prime} \\rightarrow \\cdots \\rightarrow v_{k-1}^{\\prime} \\rightarrow y\n\\end{equation}\nAs $p_1$ and $p_2$ are necessarily two different paths, they differ at least in one vertex.\nLet $v_i$ ($1<i<k-1$) be the last vertex common between $p_1$ and $p_2$ ($v_i = v_{i}^{\\prime}$).\nIn this case, there will be two simple paths from $v_i$ to $y$, one from vertices in $p_1$ and one from vertices in $p_2$.\nTherefore, a simple loop of the form $v_i \\rightarrow v_{i+1} \\rightarrow \\cdots v_{k-1} \\rightarrow y \\rightarrow v_{k-1}^{\\prime} \\rightarrow \\cdots \\rightarrow v_{i+1}^{\\prime} \\rightarrow v_i$ will exist.\nThis violates definition of the tree in which there should be no simple loops.\nTherefore, the assumption is false and there are no more than one simple path from $x$ to $y$.\n", "meta": {"hexsha": "31e0b61314df3c1f07fc40ead7a4360c4ad649b3", "size": 1950, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q04.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/hw03q04.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/hw03q04.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 59.0909090909, "max_line_length": 208, "alphanum_fraction": 0.6897435897, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8976952975813453, "lm_q1q2_score": 0.795027217566049}}
{"text": "\n\\subsection{k-means clustering}\n\n\\subsubsection{Introduction}\n\nK-means clustering is the most widely used unsupervised model.\n\nIn k-means clustering we identify \\(k\\) centroids in the feature space. We then calculate the distance from each data point to each of the centroids, and allocate the data point to the nearest centroid.\n\nThis requires a method for calculating the location of the centroids.\n\n\\subsubsection{Identifying the centroids}\n\nWe apply an iterative approach to identifying the centroids.\n\nWe first initialise by assigning centroids randomly to existing data points.\n\nWe then iteratively perform the following:\n\n\\begin{itemize}\n\\item Calculate the distances between each data point and each centroid.\n\\item Assign each data point to the closed centroid.\n\\item Update each centroid location to the mean of the data points allocated to it.\n\\end{itemize}\n\n\\subsubsection{Calculating distances}\n\nThis method requires us to calculate the distance between two points in the feature space.\n\nFor k-means we use the Euclidian distance.\n\n\\subsubsection{Potential issues}\n\nIt is possibile for a centroid to have no data assigned to it. If this happens we can eliminate the cluster, or reassign some data points.\n\nThe algorithm may only arrive at a local minima. In order to maximise the chance of an effective clustering, we can do k-means under different initialisations of the centroids in order to minimise risk of bad local optima.\n\n\\subsubsection{Choosing \\(k\\)}\n\nIf the points in each cluster follow a normal distribution, that's a good sign. This can be tested with Anderson-Darling.\n\nIf it's not normal, we can split the cluster into 2.\n\n\\subsubsection{Using clusting as part of data analysis}\n\nWe can choose \\(k\\) if output is being used in later data analysis (eg type assignment, complaint level or something)\n\n", "meta": {"hexsha": "0df4fb57d57f6d447aea442aaec52288b43f15ae", "size": 1829, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/clustering/01-02-kMeans.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/clustering/01-02-kMeans.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/clustering/01-02-kMeans.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.1041666667, "max_line_length": 222, "alphanum_fraction": 0.7966101695, "num_tokens": 382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8976953003183444, "lm_q1q2_score": 0.7950272172802131}}
{"text": "\nA {\\bf singleton set} (or just a {\\bf singleton}) is a set with {\\it exactly one} element. There is \"essentially just one\" singleton set.\nThis a very different situation than that for the {\\bf empty set}, where we know there's {\\it exactly one} empty set.\nWhy does this happen? How does this happen? We try to explain this.\n\n\\section{Any two singleton sets are \"essentially the same\"}\n\n$\\tab$ {\\bf Definition}. A {\\bf set-isomorphism} is a\n\\href{https://en.wikipedia.org/wiki/Bijection,_injection_and_surjection}{{\\bf bijection}}\nbetween sets.\n\n$\\tab$ {\\bf Theorem}. There exists a unique set-isomorphism between any two singleton sets.\nThere's \"exactly one\" singleton set, not necessarily because any two singleton sets have the same elements\n(which is how {\\bf equality} of sets is defined),\nbut because, given any two singleton sets, there's exactly one set-isomorphism (ie. a bijection) between the two.\nThis allows us to say there's \"exactly one\" singleton set even when there {\\it really} isn't exactly one singleton set.\nIn other words, this allows us to say there's a {\\it unique} singleton set,\nprovided we're willing to consider two singletons sets \"the same\" whenever there exists a unique set-isomorphism between the two.\nThe jargon for this is: there's a unique singleton set,\n\\href{https://en.wikipedia.org/wiki/Up_to}{up to}\nunique set-isomorphism.\n\n$\\tab$ {\\it Proof}. Why do we talk about \"the\" singleton set? Is there {\\it only one} singleton set?\nFor instance, using the\n\\href{https://en.wikipedia.org/wiki/Axiom_of_extensionality}{{\\bf axiom of extension}}\n(aka. the axiom of extensionality), we can prove that there's only one empty set.\nThis is because the axiom of extension says that {\\it equality of sets} is\n\\href{https://en.wikipedia.org/wiki/If_and_only_if}{{\\bf materially equivalent}}\nto {\\it equality of their elements}. More precisely, two sets are equal\n\\href{https://en.wikipedia.org/wiki/Logical_biconditional}{{\\bf IFF}}\nthey have exactly the same elements.\nIf there were two empty sets, then for them to be not equal they'd have to differ by (at least) one element:\none of the two empty sets would have to have an element that is not in the other.\nBut this can't happen because an empty set has, by definition, no elements.\n\nSo, what about singleton sets? There's certainly more than one,\nbecause, for instance, the singleton set $\\{0\\}$ is not the same as the singleton set $\\{1\\}$:\nthe set $\\{0\\}$ has the one element $0$, and the set $\\{1\\}$ has the one element $1$;\nand $0$ is {\\it not} equal to $1$, under {\\it most} reasonable interpretations of the symbol $0$ and the symbol $1$\n(for example, in the\n\\href{https://ncatlab.org/nlab/show/trivial+ring}{zero ring},\n$0$ {\\it does} equal $1$).\n\nBut these two sets are {\\bf set-isomorphic}: there exists a {\\bf set-isomorphism} (ie. a {\\bf bijection}) between the two.\nWhat does a bijection between $\\{0\\}$ and $\\{1\\}$ look like?\nWell, for starters, what does a {\\bf function} between $\\{0\\}$ and $\\{1\\}$ look like?\nConsider a function $f: \\{0\\} \\to \\{1\\}$ from $\\{0\\}$ to $\\{1\\}$.\nBy definition, the function $f$ must map each element of $\\{0\\}$ to exactly one element of $\\{1\\}$.\nBut $\\{0\\}$ has exactly one element, namely $0$, so all we need to decide is: what is the image of $0$ under $f$?\nIn other words, what is $f[0]$? Well, how many choices do we have?\nFor each element of $\\{1\\}$ we have one choice, and each choice leads to a different function.\nBut $\\{1\\}$ only has one elements, namely $1$, so there's only one choice:\nthe only possible answer is that $f$ must map $0$ to $1$, meaning $f: 0 \\mapsto 1$ or equivalently $f[0] = 1$.\n\nSo, there's only one function from $\\{0\\}$ to $\\{1\\}$. And this function $f$ is very special: it's a {\\it bijection}.\nWhy is $f$ a bijection? Because $f$ is an {\\bf injection} (distinct elements of $\\{0\\}$ go to distinct elements of $\\{1\\}$),\nand because $f$ is a {\\bf surjection} (every element of $\\{1\\}$ is the image of at least one element of $\\{0\\}$).\nSo, $f$ is an {\\bf isomorphism of sets}.\n\nAnd, since there's {\\it only one} function from $\\{0\\}$ to $\\{1\\}$, this bijection/set-isomorphism is {\\it unique}.\nThis is very important, so let's say it again: {\\it there's a unique set-isomorphism from $\\{0\\}$ to $\\{1\\}$}.\nBut when arguing this way we never used any specific properties of $0$ or of $1$.\nAll we used was the fact that the sets $\\{0\\}$ and $\\{1\\}$ have {\\it exactly one} element.\nSo, the same argument applies to any two sets with exactly one element (any two {\\bf singleton} sets). How?\n\nWell, let $A$ be an arbitrary (but fixed) singleton set, and let $B$ be an arbitrary (but fixed) singleton set. \\\\\nSince $A$ is a singleton set, we can write $A$ as $\\{a\\}$, where the symbol $a$ is an arbitrary label for whatever element the singleton set $A$ happens to contain. \\\\\nSince $B$ is a singleton set, we can write $B$ as $\\{b\\}$, where the symbol $b$ is an arbitrary label for whatever element the singleton set $B$ happens to contain. \\\\\n\nIf it happens that $a$ equals $b$, then $\\{a\\}$ and $\\{b\\}$ have exactly the same elements, and\nit follows that $\\{a\\}$ equals $\\{b\\}$ (by the {\\bf axiom of extension}).\n\nIf it happens that $a$ does {\\it not} equal $b$, then $\\{a\\}$ and $\\{b\\}$ don't have exactly the same elements,\nand it follows that $\\{a\\}$ does {\\it not} equal $\\{b\\}$ (by the {\\bf axiom of extension}).\nStill, we claim there's a unique set-isomorphism between $\\{a\\}$ and $\\{b\\}$.\nTo see this, let $f: \\{a\\} \\to \\{b\\}$ be a {\\bf function} from $\\{a\\}$ to $\\{b\\}$.\nBy the definition of function, $f$ must map each element of $\\{a\\}$ to exactly one element of $\\{b\\}$.\nBut $\\{a\\}$ has exactly one element (namely, $a$) and $\\{b\\}$ has exactly one element (namely, $b$), so the only possible function is $f : a \\mapsto b$,\nwhich is the function that maps $a$ to $b$.\nThis function is both an {\\bf injection} (distinct elements of $\\{a\\}$ go to distinct elements of $\\{b\\}$) and\na {\\bf surjection} (every element of $\\{b\\}$ is the image of at least one element of $\\{a\\}$).\nSo, it turns out that $f: a \\mapsto b$ is a {\\bf bijection}.\nSingle $f$ is the only possible function from $\\{a\\}$ to $\\{b\\}$, this bijection is {\\it unique}.\nBut a bijection is, by definition, a {\\bf set-isomorphism} (aka. an isomorphism of sets).\nSo, {\\it there's a unique set-isomorphism} from $\\{a\\}$ to $\\{b\\}$.\nSince $\\{a\\}$ and $\\{b\\}$ are arbitrary singleton sets, it follows that there's a unique set-isomorphism between any two singleton sets. \\\\\n$\\tab$ $\\square$\n", "meta": {"hexsha": "31663fc7bcc66e1af09995e0d94d9194035bd2c5", "size": 6510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tmp.tex", "max_stars_repo_name": "etale-cohomology/mathisart-website", "max_stars_repo_head_hexsha": "4bdcfc888d6b44350de7d1631d42bdefe27535c9", "max_stars_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-01T21:20:47.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-01T21:20:47.000Z", "max_issues_repo_path": "src/tmp.tex", "max_issues_repo_name": "etale-cohomology/mathisart-website", "max_issues_repo_head_hexsha": "4bdcfc888d6b44350de7d1631d42bdefe27535c9", "max_issues_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/tmp.tex", "max_forks_repo_name": "etale-cohomology/mathisart-website", "max_forks_repo_head_hexsha": "4bdcfc888d6b44350de7d1631d42bdefe27535c9", "max_forks_repo_licenses": ["Naumen", "Condor-1.1", "MS-PL"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-04-01T10:15:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-01T10:15:45.000Z", "avg_line_length": 73.9772727273, "max_line_length": 167, "alphanum_fraction": 0.6938556068, "num_tokens": 1872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953030553434, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.7950272102198552}}
{"text": "\\chapter{Sufficient statistics}\nIn this chapter the theory of sufficient statistics are introduced.\n\\\\\n\\\\\n% FIND REF. http://people.unica.it/musio/files/2008/10/Casella-Berger.pdf fra side 271 og ut.\nFirst we begin with understanding of a statistic. Information about this subject can be found in \\cite{casella2002statistical}. A statistic is a function that returns a summary of the data. Examples of this can be mean value and standard deviation of the sample. Lets assume our data is from a distrbution depending on some parameters $\\Theta$. The statistics we are interested in are those who contain information about the parameters $\\Theta$. This leads us to sufficient statistics. A sufficient statistic is a statistic that captures all information about the parameters $\\Theta$ and discard the rest. From \\cite{casella2002statistical} we have the following. \n\\begin{defn}\n(Sufficient statistic definition) A statistic $T(\\boldsymbol{X})$ is sufficient statistic for $\\Theta$ if the conditional distribution of sample $\\boldsymbol{X}$ gives the value for $T(\\boldsymbol{X})$ does not depend on $\\Theta$\n\\end{defn}\nTo find sufficient statistics can be difficult, however one can use the factorization theorem to find the statistics. The theorem is as follows.\n\\begin{theorem} % s276\n(Factorization theorem) Let $f(\\boldsymbol{x}| \\Theta)$ denote the joint pdf or pmf of a sample $\\boldsymbol{X}$. A statistic $T(\\boldsymbol{X})$ is a sufficient for $\\Theta$ if and only if there exist functions $g(t|\\Theta)$ and $h(\\boldsymbol{x})$ such that, for all sample points $\\boldsymbol{x}$ and all parameter points $\\Theta$,\n\\begin{equation}\nf(\\boldsymbol{x}|\\Theta) = g(T(\\boldsymbol{x})| \\Theta)h(\\boldsymbol{x}).\n\\end{equation}\n\\end{theorem}\n$h(\\boldsymbol{x})$ should not be dependent on $\\Theta$. Then the remaining part will be $g(T(\\boldsymbol{x})| \\Theta)$ and from this we can see the sufficient statistic.\n\n\\section{Sufficient statistics}\nTo find the sufficient statistics for our NHPP one can use the likelihood function as shown in \\ref{eq:like}. The likelihood function can be found by\n\\begin{equation}\nP(x_1,..., x_n) = P(x_1,...,x_n|N(\\tau)=n)P(N(\\tau)=n) \n\\end{equation}\nThe probability of event $x_i$ given number of events $n$ is\n\\begin{equation}\nP(x_i|n) = \\frac{\\lambda(x_i)}{\\Lambda(\\tau)}.\n\\end{equation}\nHence the joint probability given  $n$\n\\begin{equation}\nP(x_1,...,x_n| N(\\tau) = n) = \\prod_{i = 1}^{n} \\frac{\\lambda(x_i)}{\\Lambda(\\tau)}.\n\\end{equation}\nThe probability of $N=n$ events is as shown in equation ?? with $t = \\tau$. The joint probability of  $\\boldsymbol{x}$ becomes\n\\begin{equation}\nP(x_1,...,x_n) = e^{-\\Lambda(\\tau)} \\frac{\\Lambda(\\tau)}{n!} \\prod_{i=1}^n \\frac{\\lambda(x_i)}{\\Lambda(\\tau)}.\n\\end{equation}\nFrom this the log likelihood function becomes\n\\begin{equation}\nl = -\\Lambda + n\\log(a) + n\\log(b) + (b-1)\\sum_{i=1}^{n} \\log(x_i) + c\\sum_{i=1}^{n} x_i.\n\\label{eq:loglike}\n\\end{equation}\nThe $\\log(n!)$ term has been neglected because it can be treated as constant regarding the parameters $a$, $b$ and $c$. From the factorization theorem we can set $u(x) = 1$. Then we get the sufficient statistics $(n,\\displaystyle\\sum_{i=1}^{n} x_i, \\displaystyle\\sum_{i=1}^{n} \\log(x_i))$. \nThe last statistic can be rewritten to $\\displaystyle\\prod_{i=1}^{n} x_i$.\n", "meta": {"hexsha": "9cce6e53406c7bc7b4531eebef8d024a838e750f", "size": 3302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/Thesis/chapters/sufficientstats.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/sufficientstats.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/sufficientstats.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": 76.7906976744, "max_line_length": 664, "alphanum_fraction": 0.729254997, "num_tokens": 958, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336303, "lm_q2_score": 0.8688267643505193, "lm_q1q2_score": 0.794890440459672}}
{"text": "\\section{Integrating Factor Method}\r\nAll 1st order linear differential equations have the form\r\n\\begin{equation*}\r\n\ta_1(x)\\dd{y}{x} + a_0(x)y = b_1(x),\r\n\\end{equation*}\r\nwhich can be rewritten as\r\n\\begin{equation*}\r\n\t\\dd{y}{x} + a(x)y = b(x).\r\n\\end{equation*}\r\n\r\n\\noindent\r\nThis equation isn't always separable, and we can't just integrate both sides unless $a_1(x)y$ = 0.\\\\\r\n\r\n\\noindent\r\nIf $a_0(x) = a_1'(x)$, then we could rewrite the equation and solve by doing the product rule in reverse.\r\n\\begin{equation*}\r\n\t\\left(a_1(x)y\\right)' = b_1(x) \\implies y = \\frac{\\int{b_1(x) \\mathrm{d}x}}{a_1(x)}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nIt's possible to rearrange into this form by multiplying the equation by some function. Specifically, what were looking for is a function $\\mu(x)$ such that\r\n\\begin{equation*}\r\n\t\\mu(x)\\dd{y}{x} + \\mu(x)a(x)y = \\mu(x)b(x) \\text{ and } \\mu'(x) = \\mu(x)a(x).\r\n\\end{equation*}\r\nThis equation involving $\\mu(x)$ is one that we know how to solve because it's separable.\\footnote{Although we are taking an indefinite integral to find $\\mu(x)$, we do not have a $+ C$ term.}\r\n\\begin{equation*}\r\n\t\\mu'(x) = \\mu(x)a(x) \\implies \\mu(x) = e^{\\int{a(x) \\mathrm{d}x}}.\r\n\\end{equation*}\r\nSubstituting the solution for $\\mu(x)$ back,\r\n\\begin{equation*}\r\n\te^{\\int{a(x) \\mathrm{d}x}}\\dd{y}{x} + e^{\\int{a(x) \\mathrm{d}x}}a(x)y = e^{\\int{a(x) \\mathrm{d}x}}b(x) \\implies e^{\\int{a(x) \\mathrm{d}x}}\\dd{y}{x} + \\mu'(x)y = e^{\\int{a(x) \\mathrm{d}x}}b(x).\r\n\\end{equation*}\r\nApplying the product rule in reverse,\r\n\\begin{equation*}\r\n\ty = \\frac{\\int{\\mu(x)} b(x) \\mathrm{d}x}{\\mu(x)} \\text{, } \\mu(x) = e^{\\int{a(x) \\mathrm{d}x}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tSolve the following 1st order linear ODE.\r\n\t\\begin{equation*}\r\n\t\ty^\\prime - y = 2e^{x}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\n$a(x) = -1$, so\r\n\\begin{equation*}\r\n\t\\mu(x) = e^{\\int{-1 \\mathrm{d}x}} = e^{-x}.\r\n\\end{equation*}\r\nApplying to our equation and solving,\r\n\\begin{equation*}\r\n\ty^\\prime e^{-x} - ye^{-x} = 2 \\implies \\left(ye^{-x}\\right)^\\prime = 2 \\implies ye^{-x} = 2x + C \\implies y = \\frac{2x + C}{e^{-x}}.\r\n\\end{equation*}", "meta": {"hexsha": "6c4977c434ef2f2379f0fc8ac748e9ca1387eb62", "size": 2113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/1stOrderLinearODE/integratingFactor/integratingFactor.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/1stOrderLinearODE/integratingFactor/integratingFactor.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/1stOrderLinearODE/integratingFactor/integratingFactor.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 40.6346153846, "max_line_length": 194, "alphanum_fraction": 0.624704212, "num_tokens": 812, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.946596665680527, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7948893700605911}}
{"text": "\n\\subsection{Metric-preserving transformations and isometry groups}\n\nIf we have a bilinear form we can write the form as:\n\n\\(u^TMv\\)\n\nAfter a transformation \\(P\\) to the vectors it is:\n\n\\((Pu)^TM(Pv)\\)\n\n\\(u^TP^TMPv\\)\n\nSo the value of the metric will be unaffected if:\n\n\\(u^TP^TMPv=u^TMv\\)\n\n\\(P^TMP=M\\)\n\n\\subsubsection{Equivalent metrics}\n\nDifferent metrics can produce the same group. For example multiplying the metric by a constant.\n\n\\(P^TMP=M\\)\n\n", "meta": {"hexsha": "d3326df6ecb15f2d7240b2312aaf04c5415b3f81", "size": 449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-04-metricPreserving.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-04-metricPreserving.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-04-metricPreserving.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.2692307692, "max_line_length": 95, "alphanum_fraction": 0.714922049, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966641739774, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7948893687954901}}
{"text": "\\section{Statistics}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Probability Distributions\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\formdesc{Expected Value}\n\n\\begin{equation}\n\tE(X) = \\mu = \\sum_{i=1}^k x_i ~ P(X = x_i)\n\\end{equation}\n\nfor a discrete random variable with $k$ possible values.\n\\hformbar\n\n\n\n\n\\formdesc{General Variance Formula}\n\n\\begin{equation}\n\tVar(X) = \\sigma^2 = \\sum_{j=1}^k (x_j - \\mu)^2 ~ P(X = x_j),\n\\end{equation}\n\nor, the sum of the squared deviations $(x_j - \\mu)^2$ weighted by the corresponding probabilities $P(X=x_1),  \\ldots, P(X=x_k)$.\n\\hformbar\n\n\n\n\\formdesc{General Standard Deviation}\n\n\\begin{equation}\n\t\\sigma = \\sqrt{\\sigma^2} = \\sqrt{Var(X)}\n\\end{equation}\n\\hformbar\n\n\n\n\\formdesc{Linear Combinations of Variables}\n\n\\begin{equation}\n\tZ = aX + bY\n\\end{equation}\n\nis a linear combination of the independent, random variables $X$ and $Y$ (often $a$ and $b$ are $1$ or $-1$). \n\n\\begin{eqnarray}\n  E(Z) &=& a \\times E(X) + b \\times E(Y) \\\\\n  Var(Z) &=& a^2 \\times Var(X) + b^2 \\times Var(Y)\n\\end{eqnarray}\n\\hformbar\n\n\n\n\\formdesc{Probability Density Function (PDF)}\n\n\\begin{equation}\n\tP(a \\leq X \\leq b) = \\int_{a}^{b} f(x) ~ dx\n\\end{equation}\n\n\nis a PDF of $X$, for any two numbers $a$ and $b$ where $a \\leq b$. I.e., the probability that $X$ takes on a value in the interval $[a, b]$ is the area above this interval and below the graph of the density curve.\n\n\\begin{itemize}\n\t\\item $P(X=c) = 0$ for any constant (bins are infinitesimally small)\n\t\\item $\\sum P(x_i) = 1$\n\\end{itemize}\n\n\n\\hformbar\n\n\n\n\\formdesc{Normal Distribution v. Standard Normal}\n\nThere is any entire family of distributions that can be called normal, but the\nprototypical distribution with mean of $0$ and standard deviation of $1$ is\ncalled the standard normal. Formally defined by its PDF as:\n\n\\begin{equation}\n  f(x \\mid \\mu, \\sigma^2) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} \\, e^{ \\frac{-(x - \\mu)^2}{2 \\sigma^2}}\n\\end{equation}\n\n\\subsection*{Properties}\n\n\\begin{enumerate}\n\t\\item Symmetric around mean\n\t\\item Mean = mode = median\n\t\\item Denser at center than in tails\n\\end{enumerate}\n\nConsequently,\n\n\\begin{itemize}\n\t\\item 68 percent of distribution is within one standard deviation of the mean\n\t\\item 95 percent of distribution is within approximately two standard deviations of the mean\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Evaluating Normality}\n\n\\begin{center}\n    \\includegraphics[width=1.5in]{normal_qq}\n\\end{center}\n\n\\begin{itemize}\n\t\\item A normal probability plot using quartiles can be used to evaluate how closely a given distribution adheres to normality, where the straight line is a perfect normal curve\n\t\\item As $N$ increases, the deviation from normality will decrease\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Z Scores}\n\n\\begin{equation} Z = \\frac{x - \\mu}{\\sigma}\\end{equation}\n\nconverts any value from a normal distribution to its corresponding value on the standard normal distribution\n\n\\begin{itemize}\n\t\\item Describes the number of standard deviations a point is from the mean $\\mu$\n\t\\item Z scores to the left of $\\mu$ are negative, and positive to the right of $\\mu$\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Z Scores: Probabilities on Normal Distribution}\n\n\\subsection*{Ex. What is the probability $X > A$, given $X \\sim N(\\mu=1500, \\sigma=300)$?}\n\n\\begin{equation}\n\tZ = \\frac{x - \\mu}{\\sigma} = \\frac{1630 - 1500}{300} = 0.43\n\\end{equation}\n\nThis is 0.6664 on Z table, so 66.64 percent of $X$ is to the left of A so:\n\n\\begin{equation}\n\t1 - 0.6664 = 0.3336\n\\end{equation}\n\nThe probability $X > A$ is 33.36 percent.\n\n\n\\subsection*{Ex. Given $A = 1400$ and $X \\sim N(\\mu=1500, \\sigma=300)$, what is the percentile corresponding to A?}\n\n\\begin{equation}\n\tZ = \\frac{x - \\mu}{\\sigma} = \\frac{1400 - 1500}{300} = -0.33\n\\end{equation}\n\nThe corresponding value on the Z table is 0.3707, so $A$ is the 37th percentile.\n\n\n\\subsection*{Ex. Given $p = .40$ and $X \\sim N(\\mu=70, \\sigma=3.3)$, what is the value corresponding to percentile $p$?}\n\nLookup $p$ on Z table, getting a $Z = -0.25$. Work backwards:\n\n\\begin{equation}\n\t-0.25 = Z = \\frac{x - \\mu}{\\sigma} = \\frac{x - 70}{3.3}\n\\end{equation}\n\nand solve for $x = 69.18$.\n\n\n\\subsection*{Ex. What is the probability $X$ is between $A$ and $B$, given $X \\sim N(\\mu, \\sigma)$?}\n\nUsing Z-scores method, find the area to the left of $A$ and to the right of $B$, then $A - B = 1 -$ area left of $A -$ are to right of $B$.\n\\hformbar\n\n\n\n\\formdesc{Bernoulli Distribution}\n\n\\begin{equation}\n\tP(X = x) = \\left\\{\\begin{matrix}\n\t\t\t\t\t  p ~$for$~ x = 1\\\\ \n                      1 - p ~$for$~ x =0\n                \\end{matrix}\\right.\n\\end{equation}\n\ndescribes the distribution of individual trials with two possible outcomes, success or failure, described by proportion of successes $0 \\leq p \\leq 1$:\n\n\\begin{eqnarray}\n  \\hat{p}   &=& \\frac{\\mid successes \\mid}{\\mid failures \\mid} \\\\\n  \\mu       &=& p \\\\\n  \\sigma^2  &=& p(1 - p)\n\\end{eqnarray}\n\n\\begin{itemize}\n\t\\item The probability of success after $n$ trials is $(1 - p)^{n - 1} \\times p$\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Bernoulli: Geometric Distribution}\n\n\\begin{center}\n    \\includegraphics[width=2in]{geometric_dist}\n\\end{center}\n\ndescribes the wait time until a success for \\textit{independent} Bernoulli random variables; or, the probability of observing the $k$-th success by the $n$-th trial\n\n\\begin{eqnarray}\n  \\mu       &=& \\frac{1}{p} \\\\\n  \\sigma^2  &=& \\frac{1 - p}{p^2}\n\\end{eqnarray}\n\n\\begin{itemize}\n\t\\item Higher $p$ means fewer trials until success\n\t\\item Can never be approximated by a normal distribution\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Binomial Distribution}\n\n\\begin{center}\n    \\includegraphics[width=2in]{binomial}\n\\end{center}\n\ndescribes the probability of having exactly $k$ successes in $n$ independent Bernoulli trials (with probability of success $p$):\n\n\\begin{eqnarray}\n\tP(x = k \\mid n, \\mu, \\sigma) &=& \\begin{pmatrix}\n\t\tn\\\\ \n\t\tk\n\t\\end{pmatrix}\n\tp^k (1 - p)^{n -k} \\\\\n\t&=& \\frac{n!}{k!(n - k)!} ~p^k (1 - p)^{n - k} \n\\end{eqnarray}\n\nParameters, can be used to approximate to normal when $n$ is sufficiently large and $np$ and $n(1-p)$ are both greater than or equal to 10:\n\n\\begin{eqnarray}\n  \\mu       &=& np \\\\\n  \\sigma^2  &=& np(1 - p)\n\\end{eqnarray}\n\n\\hformbar\n\n\n\n\\formdesc{Poisson Distribution}\n\n\\begin{center}\n    \\includegraphics[width=2in]{poisson}\n\\end{center}\n\n\\begin{equation}\n\tP(X = x \\mid \\lambda) = \\frac{\\lambda^x e^{-\\lambda}}{x!}\n\\end{equation}\n\nDescribes the number of events in a larger population over a unit of time with rate $\\lambda$:\n\n\\begin{eqnarray}\n  \\mu       &=& \\lambda \\\\\n  \\sigma^2  &=& \\lambda\n\\end{eqnarray}\n\n\\hformbar\n\n\n\n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n%\n% Inferential Statistics\n%\n% See Statistical Inference by Casella p. 373 for alternative and better \n% notation for this\n%\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\formdesc{Inferential Statistics}\n\nThe body of thought governing the inferences of populations from samples,\nand how these sample statistics can vary.\n\\hformbar\n\n\n\n\\formdesc{Standard Error}\n\n\\begin{equation}\n\tSE = \\frac{\\sigma}{\\sqrt{n}}\n\\end{equation}\n\nis the standard deviation of distributions of sample statistics, when population $\\sigma$ is known. If it is unknown, and if $n > 30$, substitute sample standard deviation $s$\n\n\\begin{itemize}\n\t\\item $SE$ decreases as $n$ increases\n\t\\item $SE$ decreases as $\\sigma$ (or $s$) decreases\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{Confidence Intervals}\n\n\\begin{equation}\n\t\\bar{x} \\pm z \\times SE\n\\end{equation}\n\n\\begin{itemize}\n\t\\item $\\bar{x}$ is the sample statistic, such as sample mean\n\t\\item $z \\times SE$ is the \\textit{margin of error}\n\t\\item $z$ is the desired confidence level, e.g., $z = 1.96$ for a 95 percent confidence interval\n\\end{itemize}\n\n\\textit{Interpretation.} ``We are $Z$ percent confident the true population \\textit{statistic} is between $A$ and $B$''; or, ``$Z$ percent of samples will have a \\textit{sample statistic} between $A$ and $B$.''\n\n\\hformbar\n\n\n\n\\formdesc{Central Limit Theorem}\n\nGiven a population with a finite mean $\\mu$ and a finite non-zero variance\n$\\sigma^2$, the sampling distribution of the mean approaches a normal\ndistribution with a mean of $\\mu$ and a variance of $\\frac{\\sigma^2}{N}$, as\n$N$, the sample size, increases---regardless of the shape of the parent population.\n\\hformbar\n\n\n\n\n\\formdesc{Hypothesis Testing}\n\n\\begin{table}[htp]\n  \\begin{center}\n    \\begin{tabular}{c|c}\n      One-Sided      & Two-Sided       \\\\\n      \\hline\n      $H_0: x = A$   & $H_0: x = A$    \\\\\n      $H_A: x >/< A$ & $H_A: x \\neq A$\n    \\end{tabular}\n  \\end{center}\n\\end{table}\n\n\\vspace{-2em}\n\nThe process of comparing two point estimates, to determine if any difference between them is ``real'' or the result of natural variance in samples.\n\n\\begin{itemize}\n\t\\item \\textit{Type I} errors, or false positives, occur when $H_0$  is true, but rejected\n\t\\item \\textit{Type II} errors, or false negatives, occur when $H_A$ is true, and $H_0$ is not rejected\n\\end{itemize}\n\n\\subsection*{Quantifying Risk}\n\n\\begin{itemize}\n\t\\item The risk of Type I errors is quantified by $\\alpha$, i.e., the probability the point estimate is more than $z^*$ standard deviations away from the true population parameter\n\t\\item The $p$-value is the probability of observing data at least as favorable to the alternative hypothesis, i.e., as ``extreme,'' as the present data set, if $H_0$ is actually true\n\t\\item If the $p$-value is less than the chosen $\\alpha$, data is sufficient to reject $H_0$\n\\end{itemize}\n\\hformbar\n\n\n\n\\formdesc{P-Value Calculations}\n\n\\subsection*{One-Sided}\n\n%\\begin{enumerate}\n%\t\\item Look up test statistic, e.g., $\\bar{x}$, on $z$-table\n%\t\\item Determine the probability that $Z$ is more extreme than $\\bar{x}$:\n%\t    \\begin{equation}\n%\t    \tZ = \\frac{\\bar{x} - \\mu}{SE}}\n%\t    \\end{equation}\n%\t\\item Use \n%\\end{enumerate}\n\n\\subsection*{Two-Sided}\n\n\\hformbar\n\n\n\n\\formdesc{Sample Proportions}\n\nPopulation parameter $\\pi$ is sampled:\n\n\\begin{eqnarray}\n  \\mu       &=& \\hat{p} = \\frac{\\sum_n^{i=1} x_{i}}{n} \\\\\n  SE_{\\hat{p}}  &=& \\sqrt{\\frac{p(1-p)}{n}}\n\\end{eqnarray}\n\nwhere $0 \\leq \\hat{p} \\leq 1$ and $x_i = \\{0, 1\\}$\n\\hformbar\n\n\n\n\\formdesc{Sample Proportions: Confidence Intervals}\n\n\\begin{enumerate}\n\t\\item Assess normality:\n\t\t\\begin{itemize}\n\t\t\t\\item At least 10 observations for each $\\{0, 1\\}$\n\t\t\t\\item Sample is less than 10 percent of population and observations are independent\n\t\t\\end{itemize}\n\t\\item Calculate standard error $SE_{\\hat{p}} = \\sqrt{\\frac{p(1-p)}{n}}$\n\t\\item Determine $z^*$, e.g., 1.96\n\t\\item Put together point estimate and margin of error:\n\t\\begin{equation}\n\t\t\\hat{p} \\pm z^* \\times SE_{\\hat{p}}\n\t\\end{equation}\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{Sample Proportions: Hypothesis Tests}\n\n\\textbf{FIX}\n\n\\begin{eqnarray}\n  H_0: \\hat{p} = 0.5 \\\\\n  H_A: \\hat{p} >/\\neq 0.5\n\\end{eqnarray}\n\n\\begin{enumerate}\n\t\\item Evaluate normality\n\t\\item Compute $SE_{\\hat{p}}$ \\textit{using null hypothesis}:\n\t\t\\begin{equation}\n\t\t\tSE_{\\hat{p}} = \\sqrt{\\frac{p(1-p)}{n}},\n\t\t\\end{equation}\n\t\toften $ \\sqrt{\\frac{0.5(1-0.5)}{n}}$\n\t\\item Calculate Z-score using hypotheses:\n\t\t\\begin{equation}\n\t\t\t\\frac{\\hat{p} - \\hat{p}_0}{SE_{\\hat{p}}}\n\t\t\\end{equation}\t\n\t\\item Convert $Z$ to $p$-value and decide whether to reject the null or fail to\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{Sample Proportions: Sample Size}\n\\hformbar\n\n\n\n\\formdesc{Difference of Proportions}\n\\hformbar\n\n\n\n\\formdesc{Difference of Proportions: Confidence Intervals}\n\\hformbar\n\n\n\n\\formdesc{Difference of Proportions: Hypothesis Tests}\n\\hformbar\n\n\n\n\\formdesc{Difference of Proportions: Pooled Proportion}\n\\hformbar\n\n\n\n\\formdesc{$\\chi^2$ goodness of fit}\n\n\n\\begin{equation}\n\t\\chi^2 = \\sum_{k=1}^N \\frac{ (observed_k - expected_k)^2 }{ expected_k }\n\\end{equation}\n\n\\begin{itemize}\n\t\\item $k$ mutually exclusive classes\n\t\\item $n$ observations of $x_i$\n\t\\item one parameter, degrees of freedom $df$\n\t\\item follows the chi-square distribution if null hypothesis is true\n\\end{itemize}\n\nSummarizes how strongly observed count data deviates from the expected, or null, counts---larger values of $\\chi^2$ indicate stronger deviation\n\n\\subsection*{Does a statistical model fit this sample?}\n\n\\begin{enumerate}\n\t\\item Develop hypotheses:\n\t\t\\begin{enumerate}\n\t\t\t\\item $H_0$: Sample follows distribution $D$\n\t\t\t\\item $H_A$: Sample does not follow distribution $D$\n\t\t\\end{enumerate}\n\t\\item Check assumptions\n\t\t\\begin{enumerate}\n\t\t\t\\item Each expected count must be at least 5\n\t\t\t\\item Can use binning to get around this\n\t\t\\end{enumerate}\n\t\\item Establish expected counts (expected proportion of total count in each bin):\n\t\t\\begin{equation}\n\t\t\tE_k = expected_k \\times n\n\t\t\\end{equation}\n\t\\item Compute $\\chi^2$ statistic\n\t\\item Validate assumptions hold to apply $\\chi^2$ to $\\chi^2$ distribution\n\t\\item Using $k-1$ degrees of freedom, use $\\chi^2$ table to compute a $p$-value\n\t\\item Decide to reject or fail to reject $H_0$\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{$\\chi^2$: $p$-value}\n\\hformbar\n\n\n\n\\formdesc{Two-Way Tables: Independence}\n\\hformbar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n%%%%%%%%\n%\n% Trash?\n%\n%%%%%%%%\n\n\n\\formdesc{Sample Statistics: Mean and Variance}\n\n\\begin{itemize}\n  \\item $\\mu_M = \\mu$ is the mean of the sampling distribution of means\n  \\item $\\sigma_M^2 = \\frac{\\sigma^2}{N}$ is the variance of the sampling\n\tdistribution of the mean\n  \\item $\\sigma_M = \\frac{\\sigma}{\\sqrt{N}}$ is the standard error of the sampling\n\tdistribution of the mean\n\\end{itemize}\n\nAs $N$ increases, variance of sample mean decreases\n\\hformbar\n\n\n\n\n\\formdesc{Sample Statistics: Difference in Mean}\n\nTwo samples from a population the size $n_1$ and $n_2$, calculate the means\n$M_1$ and $M_2$, and the difference is $M_1 - M_2$\n\n\\begin{eqnarray}\n  \\mu_{M_1 - M_2} &=& M_1 - M_2 \\\\\n  \\sigma_{M_1 - M_2}^2 &=& \\sigma_{M_1}^2 + \\sigma_{M_2}^2 \\\\\n  \\sigma_{M_1 - M_2} &=& \\sqrt{\\frac{\\sigma_1^2}{n_1} + \\frac{\\sigma_2^2}{n_2}}\n\\end{eqnarray}\n\nWhen variance and sample size are the same, standard error becomes:\n\n\\begin{equation}\n  \\sigma_{M_1 - M_2} = \\sqrt{\\frac{\\sigma_1^2}{n_1} + \\frac{\\sigma_2^2}{n_2}}i\n  = \\sqrt{ \\frac{\\sigma^2}{n} + \\frac{\\sigma^2}{n}}\n  = \\sqrt{ \\frac{2 \\sigma^2}{n} }\n\\end{equation}\n\nIf $n_1 \\neq n_2$ then variance becomes:\n\n\\begin{equation}\n  \\sigma_{M_1 - M2}^2 = \\frac{\\sigma_1^2}{n_1} + \\frac{\\sigma_2^2}{n_2}\n\\end{equation}\n\n\\subsection*{What is the probability that the mean of sample 1 will exceed that of\nsample 2 by $N$ or more?}\n\n\\begin{enumerate}\n  \\item Find mean: $\\mu_{M_1 - M_2} = M_1 - M_2$\n  \\item Find standard error: $\\sigma_{M_1 - M_2}$\n  \\item Find area underneath distribution of sample 1 to the right of the mean\n\tof sample 2 plus $N$\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{Sample Statistics: $r$ and $\\rho$}\n\n\\begin{itemize}\n  \\item Not normally distributed---right-skewed---because correlation cannot\n\texceed 1\n  \\item As $\\rho$ increases, the more right-skewed the distribution\n\\end{itemize}\n\n\\hformbar\n\n\n\n\\formdesc{Sample Statistics: Proportion $\\pi$}\n\nSampling proportion is closely related to the binomial distribution---the\ntotal number of successes---where $p$ is the distribution of the mean number of\nsuccesses\n\n\\begin{eqnarray}\n  \\mu_p &=& \\pi \\\\\n  \\sigma_p &=& \\frac{\\sqrt{N \\pi (1 - \\pi)}}{N}\n           = \\sqrt{\\frac{\\pi (1 - \\pi)}{N}}\n\\end{eqnarray}\n\n\\subsection*{Find probability $p$ is greater than $A$}\n\nGiven $N$ and population proportion $\\pi$:\n\n\\begin{enumerate}\n  \\item Find mean of $p = \\pi$\n  \\item Calculate standard error as above\n  \\item Conduct as normal distribution given $N$ is sufficiently large and $\\pi$\n\tis not too close to 0 or 1\n\\end{enumerate}\n\n\\hformbar\n\n\n\n\\formdesc{Estimation}\n\nThe process of estimating population parameters from sample statistics. Usually\nresults in a point estimate as well as interval estimates called confidence\nintervals.\n\n\\hformbar\n\n\n\n\\formdesc{Degrees of Freedom}\n\n\n\n\\hformbar\n\n\n\n\n\\newpage\n", "meta": {"hexsha": "a46dfee1d54fd0385842958db1c9c275a422349d", "size": 15793, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/statistics.tex", "max_stars_repo_name": "benhorvath/math_notes", "max_stars_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/statistics.tex", "max_issues_repo_name": "benhorvath/math_notes", "max_issues_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/statistics.tex", "max_forks_repo_name": "benhorvath/math_notes", "max_forks_repo_head_hexsha": "47979bc9cbe52e6ccb9deca7afe9ff1b240e05f5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.9216255443, "max_line_length": 213, "alphanum_fraction": 0.6808712721, "num_tokens": 5120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8840392909114836, "lm_q1q2_score": 0.7948586319741071}}
{"text": "\\section{Introduction}\\label{introduction} \n\nWe start by discussing fundamental combinatorial constructions such as words of a fixed alphabet, permutations of finite\nsets and the number of subsets with a given number of elements. While we give some examples of how some combinatorial problems \nnaturally arise, our main goal in this first section is to provide an intuitive introduction to the topic of \nEnumerative Combinatorics. \n\n\\subsection{Words}\n\nThe first definition of this lecture is the definition of a word over a finite alphabet of symbols.\n\n\\begin{defn}[word]\nLet $A$ be a finite set, called \\textit{alphabet}. A \\textit{word} is a finite sequence of elements of $A$. The \\textit{size} of $A$ is its cardinality $|A|$.\nThe \\textit{size} or \\textit{length} of a word is its number of elements from $A$.\n\\end{defn}\n\\noindent\nWe might abuse language to a certain extent and call the elements of $A$ \\textit{letters}.\n\n\\begin{exmp}\nLet $A=\\{1, 2, 3, 4\\}$, then $112$, $132$, $1234$, $111$, $2345$, and so on, are all words over $A$.\nNotice that the length of the words is not fixed.    \n\\end{exmp}\n\nIn the study of combinatorics a very classical question is as follows. Given an alphabet $A$ of length $|A|=n$ , how many words over $A$ of length $k$ exist? This question leads us to the following theorem.\n\n\\begin{theorem}\nThe number of words of length $k$ in an alphabet consisting of $n$ letters is equal to $n^k$.\n\\label{thmNumWords}\n\\end{theorem}\n\\begin{proof}\nThere are $n$ possibilities for the first letter. The same holds for all other letters.\nThus, the total number of words equals\n$$\n\\underbrace{n \\cdot n \\cdot n \\cdots n}_\\text{$k$-times} = n^k\n$$\n\\end{proof}\n\nThe above proof is fairly simple, but there is a different possible interpretation of this problem. Let $X$ and $Y$ be sets. We might ask: what is the total\nnumber of maps of the form $X \\to Y$ without restrictions (an element in $Y$ can be hit multiple times)? It appears that this question can be solved using \nTheorem \\ref{thmNumWords}. For seeing this, we number the elements of $X$ and $Y$ using natural numbers.\nGiven a map $f:X \\to Y$, the sequence $f(1),f(2), \\cdots, f(k)$ forms a word of length $k$. The number of words is therefore equivalent to the number of such maps.\n\n\\subsection{Permutations}\n\nA notion that is closely related to the definition of a word, is the definition of a \\textit{permutation}. First of all, the basic idea is to count maps, but \nusually with certain properties. Let $X$ and $Y$ be sets with $|X|=k$ and $|Y|=n$. We might ask: how many bijections $f:X \\to Y$ are there? Recall that\na map is bijective if it is surjective and injective. In other words, given two elements $x,y \\in X$ such that $f(x)=f(y)$, then it is implied that $x=y$ (the injective property), and \nevery element of $Y$ appears in the preimage of a certain element of $X$ (the surjective property). It follows that the cardinalities of $X$ and $Y$ must be equal.\nThese observations lead us to the definition of a permutation.\n\n\\begin{defn}[permutation]\nA \\textit{permutation} is a bijection from $\\{1, 2, 3, \\cdots, n\\}$ to itself.\n\\end{defn}\n\\noindent\nIn that sense the number of permutations is the number of bijections from $\\{1, 2, \\cdots, n\\}$ to itself.\nEquivalently, a permutation might be interpreted as a total linear ordering of the set $\\{1, 2, 3, \\cdots, n\\}$.\nIf so, we need to arrange them in a certain way. How many ways to do this are there? \nThe following theorem provides one possible solution.\n\n\\begin{theorem}\nThe number of permutations of $\\{1, 2, \\cdots, n\\}$ is equal to $n!=1\\cdot 2 \\cdot 3 \\cdots n$.\\footnote{Recall that $0!=1$.}\n\\end{theorem}\n\n\\begin{proof}\nThere are $n$ choices for the first element. For the second element there are $n-1$ choices since\none element is already occupied. For the $k$-th element there are $n-k+1$ choices. For the last element there is one choice.\nThus, the total number of permutations is given by $n(n-1)(n-2)\\cdots 2 \\cdot 1=n!$. This completes the proof.\n\\end{proof}\n\nIn the following, we will generalize the above result to injective maps. Let $k \\leq n$. In how many ways can we produce a collection \nof $k$ elements out of $n$? Such a collection is called a $k$-permutation.\n\n\\begin{defn}[$k$-permutation]\nA $k$-permutation is a total linear ordering on a $k$-element subset of $\\{1, 2, \\cdots, n\\}$.\n\\end{defn}\n\n\\begin{exmp}\nLet $\\{1,2 ,3\\}$. A $1$-permutation is just a $1$-element subset, thus there is nothing order. The set of \n$2$-permutations is given by $\\{\\{1,2\\}, \\{1,3\\}, \\{2,1\\}, \\{2,3\\}, \\{3,1\\}, \\{3,2\\}\\}$.\nThus , there are six $2$-permutations in total.\n\\end{exmp}\n\nThe general case of the number of $k$-permutations is examined in the following theorem.\n\n\\begin{theorem}\nThe number of $k$-permutations of $\\{1,2, \\cdots, n\\}$ is equal to $$n(n-1)\\cdots (n-k+1).$$\n\\end{theorem}\n\n\\begin{proof}\nThere are $n$ possible choices for the first entry of the subset. There are $(n-1)$ possible choices for the second element because the second element can occupy any entry except the one of the first element. \nFor the $k$-th entry there are $n-k+1$ possible choices. All these possibilities are independent, hence\nthe total number of $k$-permutations is equal to their product $n(n-1)\\cdots (n-k+1)$.\n\\end{proof}\n\nThe number $n(n-1)\\cdots (n-k+1)$ is sometimes called the $k$ \\textit{decreasing power} and is denoted by $n^{\\downarrow k}$.\n\n\\subsection{Merry-go-rounds and Fermat's little theorem}\nThe problem which we are going to discuss next will illustrate a connection of combinatorics to algebra and possibly number theory.\n\\\\\nConsider a train $Q$ consisting of $p$ carriages. Suppose that we have $n$ colours. In how many ways can we paint $Q$, if we can paint \neach carriage with one of the $n$ colours? Consider figure \\ref{fig:marrygoroundtrain} as an example. There is a train with $5$ carriages which\nare coloured in a certain way using $3$ different colours.\n\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{marrygoroundtrain}\n    \\caption{Initial train colouring.}\n    \\label{fig:marrygoroundtrain}\n\\end{figure}\n\nNow, this is exactly the word problem, thus the solution is given by $n^p$.\n\\\\\n\\noindent\n\\textbf{Question:} Suppose that instead of a train we have a merry-go-round and suppose further, for some reason, that $p$ is prime. \nIn how many ways can we paint each carriage of a merry-go-round using $n$ colours?\n\n\\begin{figure}[ht!]\n    \\centering\n    \\scalebox{.3}{\\incfig{marrygoroundinitialcase}}\n    \\caption{Marry-go-round initial case.}\n    \\label{fig:marrygoroundinitialcase}\n\\end{figure}\n\nIn figure \\ref{fig:marrygoroundinitialcase} a marry-go-round with $5$ carriages is visualized. They are again coloured using $3$ colours.\\\\\nWhat is the difference to the problem we have considered before? In this case we can rotate the carriages without changing its colours, but these colourings are considered to be identical.\n\\\\\n\\\\\n\\textbf{Idea:} We cut the merry-go-round (consider the two lines in figure \\ref{fig:marrygoroundinitialcase} as the \"cutting point\") and make a train out of it and there are exactly $p$ places on which we could make a cut.\n\\\\\n\\\\\nThe first naive guess would be that the solution to our problem is equal to $\\frac{n^p}{p}$, since we can get $p$ trains from each merry-go-round. This is wrong for an obvious reason. The number $\\frac{n^p}{p}$\nis by no means always integer. So let us trying to understand what is wrong with this reasoning. First, if we cut at two different places in our merry-go-round, then we could get the same train. An easy way for seeing this\nis to consider a merry-go-round in which each carriage is coloured using the same colour. There are still $p$ ways to make a train out of it but each of them is identical. Compare this reasoning with figure \\ref{fig:marrygoroundonecolour}.\n\n\\begin{figure}[ht]\n    \\centering\n    \\incfig{marrygoroundonecolour2}\n    \\caption{Marry-go-round with only one colour.}\n    \\label{fig:marrygoroundonecolour}\n\\end{figure}\n\nTo say it in different words, if we rotate a merry-go-round by an arbitrary number of times, it will eventually coincide with itself, thus if a merry-go-round goes to itself after some nontrivial rotation, then all carriages have the same colour.\nNow, notice that this is not the case if not all carriages have the same colour, since then we get exactly $p$ different trains, but observe that this is only true provided that $p$ is prime. In order to see this, consider a merry-go-round with $4$ carriages,\nand assume that we have two colours. black and white. Then, there are only two different trains which we can get from this merry-go-round. Colour the merry-go-round as follows: black - white - black - white. Then after two rotations, we get the same train. Thus, \ninstead of four trains we get two. However, if $p$ is prime, then our claim is indeed true.\n\\newpage\nIf our merry-go-round has carriages of different colours, then we can compute the number of such merry-go-rounds.\nIt is the number of trains divided by $p$. What is the number of trains which have different colors?\nThis is $n$ to the power of $p$, which is the total number of trains, minus the number of trains of the same color, which is just $n$ and for each color, there is only one train for which all carriages have this given colour.\nHence, our final result is given by the following equation.\n$$\n\\frac{n^p-n}{p} + p\n$$\n\nIt is again surprising that the above number is always an integer. This is not obvious at all and proving this using number theory is quite more involved. In general, we have obtained a very nice result given by the following theorem.\n\n\\begin{theorem}\nGiven $n \\in \\mathbb{N}$ and a prime $p$, then $n^p -n\\ |\\ p$ ($n^p - n$ is divisible by $p$).  \n\\end{theorem}\n\\noindent\nThe above is Fermat's little Theorem and we have proven it in a completely combinatorial way.\n\n\\subsection{Binomial coefficients}\n\nNext, we consider the following important definition.\n\n\\begin{defn}[bionmial coefficient]\nLet $k \\leq n$. The number of $k$-element subsets of $\\{1, 2, \\cdots, n\\}$ is called a \\textit{binomial coefficient} ${n \\choose k}$ (\"$n$ choose $k$\").\n\\end{defn}\n\nHow do we interpret this number? Suppose that we are hiring people to certain positions and suppose that we have $n$ candidates and we have $k$ identical positions.\nThe number of selecting $k$ people out of $n$ is called ${n \\choose k}$. Notice that this is different than the problem from problem about $k$-permutations.\nIn our current case, the order of the $k$ elements that we choose does not matter. Thus, choosing all $k$ element subsets of a set and then ordering them in all possible ways\nis equal to the $k$-permutations that we have seen above. How do we count the number of $k$-element subsets of a set?\n\n\\begin{theorem}\nThe number of $k$-element subsets of a set with cardinality $n$ is equal to \n$$\n{n \\choose k}=\\frac{n!}{k!(n-k)!}=\\frac{n(n-1)\\cdots (n-k+1)}{k!}.\n$$\n\\label{thmBinomial}\n\\end{theorem}\n\n\\begin{proof}\nWe consider ordered collections of distinct elements of length $k$. There are $n$ ways of choosing the first element, and $n-k+1$ ways of choosing the $k$-th element.\nHence there are \n$$\nn(n-1)\\cdots (n-k+1)=\\frac{n!}{(n-k)!}\n$$\nways such ordered collections. Since we are concerned with the number of unordered subsets and each subset has cardinality $k$, each subset can be rearranged in $k!$ ways.\nTherefore, the number of ways to choose a $k$-element subset of a set with cardinality $n$ is given by \n$$\n\\frac{\\frac{n!}{(n-k)!}}{k!}=\\frac{n!}{k!(n-k)!}.\n$$\nThis completes the proof.\n\\end{proof}\n\nWith the above theorem, we have shown something additionally that is not obvious at all and not necessarily easy to prove either.\nWe have also shown that the number $\\frac{n(n-1)\\cdots (n-k+1)}{k!}$ is integer.\n\nAt this point we provide some properties of binomial coefficients. We leave the proof as an easy exercise to the reader.\n\n\\begin{enumerate}[(i)]\n    \\item $\\displaystyle {n \\choose 0}={n \\choose n}=1$.\n    \\item $\\displaystyle {n \\choose 1}={n \\choose n-1}=n$\n    \\item $\\displaystyle {n \\choose 1}={n \\choose n-k}$.\n    \\item $\\displaystyle {n \\choose k}={n - 1 \\choose k -1} + {n - 1 \\choose k}$.\n\\end{enumerate}\n\nLet us examine property $(iv)$ in more detail. Despite its obvious algebraic proof, there is an intuitive combinatorial version as well.\nWe provide a proof sketch.\n\n\\begin{theorem}\n$\\displaystyle {n \\choose k}={n - 1 \\choose k -1} + {n - 1 \\choose k}$\n\\label{recurrencePascal}\n\\end{theorem}\n\n\\begin{proof}[Proof-sketch]\nGiven a set $A=\\{1, \\cdots, n\\}$ with $n$ elements. The number of $k$-element subsets of $A$ is ${n \\choose k}$ according to theorem \\ref{thmBinomial}.\nSuppose that we pick the element $1$ of $A$, then all $k$-element subsets of $A$ are divided into two parts, some of them contain the element $1$, and the others do not.\nSince we have already picked one element, we need to pick $k-1$ elements out of the remaining $n-1$ elements. There are ${n-1 \\choose k-1}$ subsets containing $1$.\nThus, the subsets of cardinality $k$ that do not contain $1$ is equal to ${n - 1 \\choose k}$, because we want to pick a $k$-element subset out of $n-1$ elements since $1$ element is forbidden.\n\\\\\nAdding up the two parts are equal to ${n \\choose k}$. This completes the proof.\n\\end{proof}\n\n\n\\subsection{The Pascal triangle}\n\nBinomial coefficients can be arranged in a triangle which is called the Pascal triangle.\nIts rows are indexed by integers from $0$ up to infinity and in each row we write down all binomial coefficients.\nFor example, for ${n \\choose k}$, $n=4$ represents the fifth row of the Pascal triangle and since $k \\leq n$ there are $5$ binomial coefficients, namely ${4 \\choose 0}=1, {4 \\choose 1}=4, {4 \\choose 2}=6, {4 \\choose 3}=4$ and ${4 \\choose 4}=1$.\n\\\\\nThe relation given In Theorem \\ref{recurrencePascal} provides a way of constructing the Pascal triangle. It says that the sum of two neighbors, namely ${n-1 \\choose k-1}$ and ${n-1 \\choose k}$ is equal to ${n \\choose k}$. Thus, taking two neighbors in one row and\nadding them up gives as the element below them (e.g. $3+3$ in row $n=3$ provides the element $6$ in the row $n=4$).\n\\\\\n\\\\\n\\begin{tabular}{>{$n=}l<{$\\hspace{12pt}}*{13}{c}}\n    0 &&&&&&&1&&&&&&\\\\\n    1 &&&&&&1&&1&&&&&\\\\\n    2 &&&&&1&&2&&1&&&&\\\\\n    3 &&&&1&&3&&3&&1&&&\\\\\n    4 &&&1&&4&&6&&4&&1&&\\\\\n    5 &&1&&5&&10&&10&&5&&1&\\\\\n    6 &1&&6&&15&&20&&15&&6&&1\n\\end{tabular}\n\n\\begin{proposition}\n$\\displaystyle {n \\choose 0} + {n \\choose k} + \\cdots + {n \\choose n}=2^n.$\n\\label{propositionPascalTriangle}\n\\end{proposition}\n\n\\begin{proof}\nThe binomial coefficient ${n \\choose k}$ is the number of $k$-element subsets of a $n$-element set $A=\\{1, \\cdots, n\\}$. Hence,\n$$\n\\sum_{k=0}^n {n \\choose k}\n$$\nis equal to the number of all possible subsets of $A$. We can associate a subset of $A$ with a binary number of length $n$ \nwhereby each digit in this binary number represents a specific element in $A$. Now, setting a digit to $1$ means that we pick the element from $A$ at this position\nfor our subset. Setting it to $0$ means that we do not pick it. This is equal to the number of maps $\\{1, \\cdots, n\\} \\to \\{0,1\\}$ and the total number of such maps is equal to $2^n$ or in other words, the number of binary numbers that\ncan be represented with $n$ digits is equal to $2^n$. This completes the proof.\n\\end{proof}\n\nWe call the above binomial coefficients, because they arise as coefficients in the binomial formulas $(a+b)^n$. Let us prove this.\n\n\\begin{theorem}(Newton's Binomial Theorem)\n$$\n(a+b)^n = \\sum_{k=0}^n {n \\choose k} a^{n-k} \\cdot b^k=a^n+n \\cdot a^{n-1} \\cdot b+ \\frac{n(n-1)}{2} a^{n-2} \\cdot b^2+ \\cdots + n \\cdot a \\cdot b^{n-1}+b^n\n$$\n\\label{newtonBinomialThm}\n\\end{theorem}\n\n\\begin{proof}\nWe expand the left-hand-side.\n$$\n(a+b)^n=\\underbrace{(a+b)(a+b)(a+b)\\cdots (a+b)}_{n-times}\n$$\nEvery term in the above sum is the result of choosing either $a$ or $b$ from each of the $n$ factors. We want to calculate the coefficient for $a^{n-k}b^k$.\nSince $b^k$, we must choose $b$ from exactly $k$ of the factors and we choose $a$ from the remaining $n-k$ factors.\nThus, the coefficients for $a^{n-k}b^k$ is equal to ${n \\choose k}$. This completes the proof.\n\\end{proof}\n\n\\begin{corolarry}\n$\\displaystyle {n \\choose 0}- {n \\choose 1} + {n \\choose 2} - {n \\choose 3} + \\cdots + (-1)^n {n \\choose n}=0$\n\\end{corolarry}\n\n\\begin{proof}\nConsider the binomial formula as provided in Theorem \\ref{newtonBinomialThm}. Now, let $a=1$ and $b$ (or vice versa), it follows that \n$$\n(1-1)^n= \\sum (-1)^k {n \\choose k}.\n$$\n\\end{proof}\n\nNotice, that Newton's binomial Theorem provides an easy proof for proposition \\ref{propositionPascalTriangle} as well by considering $(1+1)^n=\\sum {n \\choose k}$.\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n    \\item Find the number of subsets of a $10$-element set with an odd number of elements.\n    \\item Compute the sum $\\displaystyle \\sum_{k=0}^n 2^k {n \\choose k}$.\n    \\item Find the number of ways to rearrange the letters of the word \\textit{EULER}.\n    \\item Find the number of ways to rearrange the letters of the word \\textit{CATALAN}.\n    \\item How many necklaces can be formed with $7$ distinct beads? Necklaces can be rotated and/or flipped over. All beads must be used.\n\\end{enumerate}", "meta": {"hexsha": "f957a54ffb8a2610a3837377fa925eefaea57ecc", "size": 17290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/introduction.tex", "max_stars_repo_name": "pgrepds/Enumerative-Combinatorics", "max_stars_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/introduction.tex", "max_issues_repo_name": "pgrepds/Enumerative-Combinatorics", "max_issues_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/introduction.tex", "max_forks_repo_name": "pgrepds/Enumerative-Combinatorics", "max_forks_repo_head_hexsha": "ee8fbf2789cc1d17474d8ccbdd9a860788aa54ca", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.875, "max_line_length": 263, "alphanum_fraction": 0.7167148641, "num_tokens": 5102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8840392771633079, "lm_q1q2_score": 0.7948586148334753}}
{"text": "\n\\section{Machine Learning - Supervised Learning}\n\n\nSupervised learning concerns the problems where the objective is to predict something based on previous data. The counterpart Unsupervised Learning tries to find patterns in unlabelled data.\n\nMore generally, the dataset for supervised learning problems consists on a feature vector $\\mathbf{x}$ and a output vector $\\mathbf{y}$ as opposed to unsupervised learning where everything is features / data.\n\n\nThere are two main types of problems, regression and classification. The only difference between them is the expected output: regression aims to predict continuous outcomes while classification regards separating inputs in classes, thus a discrete output.\n\nSome tools can be used to solve both problems, like Neural Networks. We'll have a look which tools are best for which problems.\n\n\n\\subsection{Regression Problems - Least Squares}\nThese are the two most commons types of problems. Probably every supervised learning problem can be \\ii{classified} as one of these.\n\nRegression is when the output should be continuous, classification when the output should be in discrete classes. \n\nAbout the first, a measure to minimize is the difference between our prediction to the value we want to achieve. The Sum of the Square Errors (SSE) is very standard cost function to minimize.\n\nThe function that is required to minimize is loss/cost/risk function. Nomenclature wise is a problem... Therefore, the following letters/terms can be will be used interchangibly: $L$ (Loss Function) or $J$ (more used when the weights or coefficients are $\\theta$) or $R$ (Risk Function):\n\\begin{equation}\n    R = \\frac{1}{2m} \\sum_{i = 1}^m \\left(y^{(i)} - \\hat{y}^{(i)}\\right)^2\n\\end{equation}\n\nWhere $\\hat{y}$ is our prediction or estimation of the true value of $y$ and \\bb{m} is the number of training samples we have. Therefore $y^(i)$ constitutes the outcome of sample $i$.\n\nOne prediction can be made with:\n\\begin{equation}\n    \\hat{y} = \\beta_0 + \\beta_1 x_1 + \\dots + \\beta_n x_n\n\\end{equation}\nWhere \\bb{n} is the number of features we are using. Note that features and data points are different things. We can have data regarding only one measure but take the square and the cube of the measure multiplied to different coefficients in order to try to better estimate the function.\n\n$\\beta$'s are usually used in regressions while in neural networks letters like $\\theta$ or $w$ are more common.\n\n\nOne intuition that is important to have is that \\bb{the more we increase the features, the more likely it is that we end up overfitting our training set and loosing generalization capabilities for the actual test data}. This is why it is important to divide all the available data in sets, the model will be trained to guess the training samples, not samples that it never saw before.\n\\begin{itemize}\n    \\item One set for training and one set for testing the prediction capabilities;\n    \\item One training set, one validation set and one test set.\n\\end{itemize}\n\nThe last option is meant to validate the model. The model is trained with the training set, then some parameters are tuned with the validation set, namely the number of polynomial features, regularization term and step size related parameters (like momentum or adaptive step size), and the actual performance is testing in the test set. This way, we avoid optimistic measures of performance by not testing in data used for training. \n\n\\quickimage{AIML/AA-cap1-017.png}{0.4}\n\nThe result wouldn't be very different if done with the number of iterations or number of features. In particular, it is called doing an ``early stop'' when the iteration that minimises the loss in the test set is early in the minimization process. It is useful when the model starts overfitting the data.\n\n\n\n\\subsubsection{How to calculate the coefficientes}\n\\label{sec:calcBetas}\nAfter having the coefficients, given any other set of data points we can already give predictions on the output.\n\nNote that we are trying to minimize the cost/risk/loss function. The actual cost function would have to be some sort of prediction because it's impossible to know exactly how much the actual outcome will be, despite knowing  exactly what the outcome of the model will be to a certain feature vector. As opposed to the empirical risk function where the training outcome and the training predicted result are used, therefore being able to calculate the difference between each estimation and the supposed outcome. To compute the real risk, the expected value of the SSE is necessary. Also, there are continuous results so an integral is required:\n\\begin{equation}\n    R = E[y-\\hat{y}] = \\int_{-\\infty}^{+\\infty} L(y, x) \\phi(y) dx dy \n\\end{equation}\n\nBecause a potential function to give us a measure on how frequent certain values are is not known, the only way is to approximate the actual error empirically, using the model with some test data. This will degenerate in the actual cost function presented before. L here is meant to denote the loss of one sample which is nothing more than the squared error.\n\n\nOne thing that won't happen in all problems is having an analytical and optimum solution for them. Actually, minimizing the SSE is a kind of problem is called the \\bb{Least Squares}. \\ul{This kind of problem is very usually used in optimisation and often a closed solution is possible.}\n\n\nIn this case, since we are searching for the function's minimum, the functions partial derivatives need to be zero in order to have a critical point (maximum, minimum or saddle point).\n\nIn this case, \n\n\\begin{align*}\n    \\frac{\\delta R}{\\delta \\beta_0} = -2 \\sum_{i = 1}^n (y^{(i)} - \\beta_0 - \\beta_1 x^{(i)}) = 0 \\\\\n    \\frac{\\delta R}{\\delta \\beta_1} = -2 \\sum_{i = 1}^n (y^{(i)} - \\beta_0 - \\beta_1 x^{(i)})x^{(i)} = 0 \\\\\n\\end{align*}\n\nIs possible to simplify further these equations, putting the $\\beta$'s in evidence and separating sums, arriving at:\n\n\\quickimage{AIML/AA-cap1-001.png}{0.6}\n\nIs possible to invert these equations and get the expressions for the coefficients. However there's one important factor to have in mind. Are we aiming at a minimum, maximum or something different like a saddle point? The Hessian Matrix will tell us.\n\n\n\n\\subsubsection{Extrema Conditions and Hessian Matrix} \\label{sec:Hessian}\n\nVideos: \\href{https://www.youtube.com/watch?v=nRJM4mY-Pq0&list=PLSQl0a2vh4HC5feHa6Rc5c0wbRTx56nF7&index=87}{\\ul{87 - Warm up to the second partial derivative test}} to\\dots \\href{https://www.youtube.com/watch?v=sJo7D74PAak&list=PLSQl0a2vh4HC5feHa6Rc5c0wbRTx56nF7&index=89}{\\ul{89 - Second partial derivative test intuition}}\n\n\n\\quickimage{AIML/AA-cap1-002.png}{0.6}\n\nIn one dimension, to find an extrema is necessary to equalise the first derivative to zero, and the second derivative must be positive - in case of a minimum - or negative - in case of a maximum. If the second derivative is zero at the critical point, then there's an inflexion point. A similar analysis must be done in ($n$+1)-D where $n$ is the number of features used in the regression.\n\nGuaranteeing that the first derivative is zero, which in N dimensions is correspondent to guaranteeing that the gradient is zero in that point, is the first step. Setting $\\triangledown f = 0$ means that, in that point, the function is not increasing or decreasing in any of the N directions. So the first derivative makes sense.\n\nHowever, when we go to the second derivative, the meanings get a bit more complicated.\n\nIn 2D, if the second derivative was 0, it was certainly a saddle point, if it was $> 0$ or $< 0$ it was, respectively, a local minimum or maximum.\n\nThe conditions we should impose in 3D is to have a positive (for finding a minimum) or negative (for finding a maximum) definite Hessian Matrix. While it is possible to attribute a meaning to second derivatives in order to just one variable, being nothing more than the concavity in those 2 directions, why do the cross derivatives play a role as well? And, why do they mean really?\n\nWell, first the explanation on why it is needed: there are functions that across multiple dimensions still show that it is an extrema but then there's an inflexion along directions that are not along the axis. So, checking the axis is not enough. Why checking the cross partial derivatives makes it enough?\n\n\\ul{The Second Derivative Test}\n\n\\begin{equation}\n    f_{xx}(x_o, y_o) f_{yy}(x_o, y_o) - f_{xy}(x_o, y_o)^2 \\gtrless 0\n\\end{equation}\n\nIf it is greater than 0, we have a maximum or a minimum and have to check the value of $f_{xx}$ or $f_{yy}$ to be sure. If it is less than 0, we have a saddle point. If it equals 0, then we don't know if it is a saddle point, but it is not a min or max therefore, at least for now, we certainly don't care.\n\nCross or Mixed partial derivatives can be switched? Yes if the function is $C^2$. \n(Boring to prove theorem called: Schwarz' Theorem)\n\nTherefore, we just need to compute one of the cross derivatives.\n\n\nAlso this works because the second derivative test is nothing more than the determinant of the Hessian matrix. The determinant is the product of every eigenvalue of that matrix, therefore it can only be positive if they are both positive or both negative, in which cases there is, respectively, a minimum or a maximum. \n\nBut why do eigenvalues tell us this? Because they tell us how the eigenvectors are scaled! And the eigenvectors of such matrix will be the greatest and the least curvatures. Therefore, they either have the same signal / are scaled the same amount, or \n\n\n\nSome other links that helped with this:\n\\begin{itemize}\n    \\item \\href{http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MORSE/diffgeom.pdf}{\\ul{Differential Geometry}}\n    \\item \\href{http://math.mit.edu/classes/18.013A/HTML/chapter11/section02.html}{\\ul{Criterior for critical points - Maximum, Minimum or Saddle?}}\n    \\item \\href{https://www.adelaide.edu.au/mathslearning/play/seminars/evalue-magic-tricks-handout.pdf}{David Butler - Facts about Eigenvalues}\n\\end{itemize}\n\n\nThe two main properties of eigenvalues that allow us to quickly calculate them from the Hessian matrix (specially if it is 2x2) are:\n\n\\begin{equation}\n    \\text{tr}(A) = \\sum^n_{i = 1} \\lambda_i    \n\\end{equation}\n\n\\begin{equation}\n    \\text{det}(A) = \\prod^n_{i = 1} \\lambda_i\n\\end{equation}\n\nBecause there are only 2 variables, there can't be very big changes across more than 2 main directions, so it is possible to quantify the main directions which will be the eigenvectors directions.\n\n\\bb{The eigenvalues of the Hessian Matrix are also called principal curvatures and the eigenvectors the principal directions.}\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsubsection{Analytical Expression for the Coefficientes}\n\nFrom the equation presented in the end of \\ref{sec:calcBetas}, we can re-write the SSE and the normal equations in the following way. \n\n\n\\quickimage{AIML/AA-cap1-003.png}{0.6}\n\nAnd arrive at the analytical expression through the simple inversion of the normal equations. Another way of reaching the analytical expression is deriving the cost function.\n\\quickimage{AIML/AA-cap1-004.png}{0.6}\n\\quickimage{AIML/AA-cap1-006.png}{0.6}\n\n\nNote however that:\n\\quickimage{AIML/AA-cap1-005.png}{0.6}\n\n\nA final remark on multiple outputs: in case our feature vector serves to estimate more than one output, we can simply use it separately for each output!\n\n\n\\subsubsection{Regularization}\n\nThis is the method of taking importance away from the minimization of the errors between the training set supposed outcomes and the actual model outcomes for those samples. If we don't take importance away, the model may become too good at predicting training examples and may forget that it should predict a tendency and generalize well for the test data.\n\n\\quickimage{AIML/overfitting.png}{0.3}\n\nPerforming a regularization consists on nothing more than adding a new parameter to the cost function, in order to shift away the focus of minimizing the SSE.\n\nThere are generally two terms that can be added. One with the \\bb{norm of the coefficients squared} and the other is the with the module of the coefficients squared.\n\nFor the norm squared, if the regularization is applied to a regression - \\bb{which is not a necessity since regularization can even be applied to Neural Networks} - it's called Ridge Regression:\n\\quickimage{AIML/AA-cap1-007.png}{0.6}\n\n\n\\quickimage{AIML/AA-cap1-008.png}{0.6}\n\nTwo key things to note:\n\n\\begin{itemize}\n    \\item Note that $\\beta_0$ is usually not included as the data should be normalised already for much better results. Normalised data means data that has zero mean in every feature and outcome.\n    \\item If $\\left(X^TX\\right)$ is singular, the least squares estimate is not unique. Regularization will help finding an estimate even then because $\\left(X^TX + \\lambda I\\right)$ is always non-singular.\n\\end{itemize}\n\nFor the simple norm of the coefficients, when applied to a regression problem it is called the Lasso Regression:\n\n\\quickimage{AIML/AA-cap1-009.png}{0.6}\n\n\\begin{equation}\n    ||\\beta||_1 = \\sum_{j=1}^{n} |\\beta_j|\n\\end{equation}\n\nThe key difference between the two is that Ridge aims to minimize the norm of all of them while Lasso aims to minimize the sum of module of each of them. Therefore, Ridge it is much likely to pull closer to zero the biggest ones as those are the ones that matter the most for the Euclidean norm, while Lasso will try to pull each of them to 0, there's a direct dependency between a coefficients and the cost function. This is also why the Lasso Regression is called to do feature selection: because if the SSE doesn't depend on the coefficients, the regularization term with the sum of the norms will put that coefficients to zero very quickly.\n\n\\quickimage{AIML/AA-cap1-010.png}{0.4}\n\n\n\nAgain, recall that the data should be centered - have zero mean - and that after calculating the model we need to de-centre it to obtain the real predictions!\n\\quickimage{AIML/AA-cap1-011.png}{0.5}\n\n\\subsubsection{Optimization problems - Gradient Descent and Newton's Method}\n\nThe gradient descent is probably the most know method to approximate a functions minimum. By changing the direction of the step we have the gradient ascent. \n\n\\quickimage{AIML/AA-cap1-012.png}{0.6}\n\nThe above expression works because the gradient points the direction of the maximum growth of the function. Therefore, taking a step in the opposite direction will lead to the minimum.\n\n\\subsubsection*{Momentum and Adaptive StepSize}\nMomentum $0 \\leq \\alpha \\leq 1$:\n\\quickimage{AIML/AA-cap1-013.png}{0.6}\n\n\nNote that we want to pick the $\\mathbf{x}$ that brings the function to a minimum. Therefore, the ``exponent'' will simply refer to the iteration number, not the sample like in the previous section.\nIf $\\alpha$ is closer to 1 the memory of the previous increment is more taken into account, meaning that the increment will change only slightly. The closer the parameter gets to 0, the closer we get to the normal situation. This is called the momentum term because it gives the convergence some inercia, the behaviour of momentum. By changing the increment slowly, it may converge faster and have less abrupt changes.\n\n\nAdaptive Step size, with typical values: $u = 1.2, d = 0.8$:\n\n\\quickimage{AIML/AA-cap1-014.png}{0.6}\n\nLet f be the function where the objective minimum lies, the Divergence criterium is given by:\n\\begin{equation}\n    f(x^{(n+1)}) > f(x^{(n)})\n\\end{equation}\nWhere the threshold is found in the equality.\n\n\\subsubsection*{Newton's method}\n\nGiven by:\n\\quickimage{AIML/AA-cap1-015.png}{0.4}\n\n\nWhere the gradient and the Hessian Matrix are given by:\n\n\\quickimage{AIML/AA-cap1-016.png}{0.4}\n\nThe Newton's method converges insanely fast! But requires the inversion of the Hessian matrix which can be a serious problem...\n\n\n\\subsubsection*{Newton's Method - Intuition and Demonstration}\nThis is a very very good proof!\n\n%do. it. It is in the notebook...\n\n\n\\subsubsection{How to optimise hyperparameters}\nThere will always be parameters to optimise in order to obtain the best model possible.\nIt was said before that 3 sets should be selected: training, validation and testing.\nAnd that it was in the validation set that all hyperparameter tunning should be done.\nThe simplest way is calculate the model with all combinations of the parameters possible and see which one performs better in the validation set. \n\nThere can be one other problem: little data. If the data is too little, dividing it into sets can start to give biased results to the accuracy.\n\nOne way of calculating the accuracy with more ... accuracy \\dots is splitting the data in k folds and rotate:\n\n\\quickimage{AIML/AA-cap1-018.png}{0.4}\n\n\n\nFinally, if both things need to be done at the same time, then:\n1- k folds need to be made. \n2- for each fold, all values of the hyperparameters need to be used for training and tested in the test set.\nNote: it will be used for training T except ($T_i$ and $T_j$) that are, respectively, the test set and the validation set. So the hyperparameters testing will be done with $T_i$.\nWhen the all combinations are done, the hyperparameters are selected for the bet one and the actual model is trained with T except $T_i$ depending on the fold considered.\n3- use the performances of each fold to get the best average of performance.\n\n(Note that this is not very used...)\n\\quickimage{AIML/AA-cap1-019.png}{0.4}\n\n\n\n\n\n\n\n\n\\subsection{Neural Networks}\n\n\\subsubsection{Formalisation}\n\n\n\nOn the surface, a NN is nothing more than a set of weights connecting a set of neurons. This is represented in Figure \\ref{mlp}.\n\n\\image{AIML/mlp.png}{Overview of a Neural Network}{mlp}{.7}\n\nThis particular architecture is called a Multilayer Perceptron (MLP), the standard NN. In other architectures not all layers are required to be fully connected e.i every neuron from the previous layer is connected to all neurons from the next layer, however, for simplicity, let's restrict this formalisation to MLPs.\n\nLet $w_{ij}^{(l)}$ be the weight that connects the output of the $j$-th neuron of layer $l-1$ to the $i$-th neuron of layer $l$. If we call the output of a neuron $j$-th of layer $l$, $z_j^{(l)}$, and the input of the $i$-th neuron of layer $l$ $s_i^{(l)}$, one may write Equation \\eqref{eq:s}.\n\n\\begin{equation} \\label{eq:s}\n    s_{i}^{(l)} = w_{i 0}^{(l)} + \\sum_{j=1}^{N^{(l)}} w_{ij}^{(l)} z_j^{(l-1)}\n\\end{equation}\n\nWith $N^{(l)}$ being the number of neurons of layer $l$. Also, the input of the first layer is the input of the network, i.e $z^{(0)} = \\mathbf{x}$. \n\nNote further that is possible to relate the input of a neuron to its output through that neuron's activation function $g(x)$. Equation \\eqref{eq:act} shows this relation, with L the number of layers in the MLP. \n\n\\begin{equation}\\label{eq:act}\n    z_{i}^{(l)} = g\\left(s_{i}^{(l)}\\right) \\quad , i = 1, ..., N^{(l)} \\quad, l = 1, ... , L\n\\end{equation}\n\nActivation functions of neurons may vary across layers and they simply relate the input with the output. \n\nThere are many kinds of activation functions, each with its advantages and disadvantages - refer to \\href{towardsdatascience.com/comparison-of-activation-functions-for-deep-neural-networks-706ac4284c8a}{\\ul{actFunctions}} for a more in-depth analysis. In this work only two are used, Rectified Linear Unit (ReLu) and Softmax, which are represented in the set of Equations \\eqref{eq:actFuncs}.\n\n\\begin{equation} \\label{eq:actFuncs}\n    \\begin{cases}\n        \\text{ReLu}\\left(s_{i}^{(l)}\\right) = \\max\\left(0,s_{i}^{(l)}\\right) \\\\\n        \\text{Softmax}\\left(s_{i}^{(l)}\\right) = \\frac{\\exp\\left(s_i^{(l)}\\right)}{\\sum_{j=1}^{N^{(l)}} \\exp(s_j)} \n    \\end{cases}\n\\end{equation}\n\nSo far we've see how to get the input to the output - forward propagation is the technical term - but wasn't explained yet how to adjust the weights such that the networks starts behaving like expected. It is done with backpropagation.\n\nBackpropagation is an algorithm that consists of calculating the effect that each weight has on the output and adjust that weight accordingly to that relation and accordingly to how wrong the output is. Backpropagation can be done with Gradient Descent methods and all their associated optimization techniques. The simple version of backpropagation with the classic gradient descent is presented in Equation \\eqref{gradDesc} where $\\eta$ denotes the step size.\n\n\\begin{equation} \\label{gradDesc}\n    w_{ij}^{(l)} = w_{ij}^{(l)} - \\eta \\ \\bigtriangledown_{ij}^{(l)} \\quad , \\text{with} \\ \\ \\bigtriangledown_{ij}^{(l)} = \\frac{\\delta J}{\\delta w_{ij}^{(l)}}\n\\end{equation}\n\nThe complete expression for the partial derivatives of every weight is in Equation \\eqref{gradExpr}.\n\n\\begin{equation} \\label{gradExpr}\n    \\bigtriangledown_{ij}^{(l)} = \\delta_i^{(l)} z_j^{(l-1)} \\quad,  \n\\end{equation}\n\n\\begin{equation}\n    \\text{with} \\ \n    \\begin{cases}\n    \\delta_i^{(l)} = g\\left(s_i^{(l)}\\right) \n    \\sum_{k=1}^{N^{(l+1)}} \\delta_k^{(l+1)} w_{ki}^{(l+1)} \\quad, \\text{for} \\ l = 1, ..., L-1\\\\ \n    \n    \\delta_i^{(L)} = g\\left(s_i^{(L)}\\right) \\ \\frac{\\delta J}{\\delta z_i^{(L)}}\n    \\quad, \\ \\text{otherwise, i.e for} \\ l = L)\n    \\end{cases}\n\\end{equation}\n\n\n\n\nNote that $z_i^{(L)} = \\hat{y_i}$. Additionally, J is the cost/loss function, the function that tells us how far from the correct result the output is. For classification problems, a good cost function usually is Cross Entropy, Equation \\eqref{crossEnt}. However, bear in mind that modifying the cost function to one that is more frequently used in Regression problems one can easily use the NN in regression problems.\n\n\n\\begin{equation} \\label{crossEnt}\n    J(y, \\hat{y}) = -\\frac{1}{N} \\sum_{i=1}^{N} \\sum_{k=1}^K \\mathbb{1}_{y_i = y_k} \\log\\left(\\hat{y_i}\\right)\n\\end{equation}\n\nWhere $N$ is the number of samples and $\\mathbb{1}_{y_i = y_k}$ denotes the indicator function that only is 1 when the supposed output is $y_k$. In other words, the inner sum should always have just one term corresponding to the logarithm of exit of the neural network that should be 1 for that class. This is because due to the common use of Softmax activation function in the last layer, the outputs will be percentages of certainty. And the cost function should be the logarithm of that the certainty of that class only.\n\nMore specifically, if we want to categorise images of digits, our neural networks will have 10 outputs, one for each class/digit. When a sample that has the number 3 written on it is propagated until the end, the loss of that computation should be the logarithm of the probability in the $3^{rd}$ exit, because a perfect NN would output a 1 in the $3^{rd}$ exit and 0 in the others. In fact, $\\log(1)$ is 0 loss and $-\\log(0)$ is infinite (positive) loss.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsubsection*{Further optimizations}\n\n\nIn order to achieve an efficient implementation, the previous equations can be written in a vectorized way and the forward and backward propagation will be reduced to matrix multiplications. Additionally, for a low level analysis it becomes relevant to keep track of all matrices dimensions, thus they are the following:\n\\begin{itemize}\n    \\item $z^{(l)}$ is $\\left(1 + N^{(l)}\\right) \\times 1$ and   $z^{(l)} = $ %that vertical matrix;\n    \\item $s^{(l)}$ is $N^{(l)} \\times 1$ and $s^{(l)} = W^{(l)} z^{(l-1)}$;\n    \\item $W^{(l)}$ is the weights matrix and is $ N^{(l)} \\times \\left(1 + N^{(l-1)}\\right)$ which should make sense when looking for the above formula and that along its rows are the weights multiplied to the previous layer plus one for the bias unit;\n    \\item $\\bigtriangledown^{(l)} = \\delta^{(l)} \\dots$\n\\end{itemize}\n\nNote that feed forward of all samples at once is possible through the correct definition of $X$ matrix and the correct changes.\n\n\n\n\n\n\n\n\n\\subsubsection*{Some history}\n\\quickimage{AIML/AA-cap1-018.png}{0.4}\n\n\\quickimage{AIML/AA-cap1-023.png}{0.4}\n\nHowever, there's a big problem with only being able to distinguish data that can be separate with an hyperplane: very often the data doesn't behave that way.\n\n\\quickimage{AIML/AA-cap1-024.png}{0.4}\n\nOne can make a more complex analysis of the situation...\n\n\n\n\\subsubsection*{Activation Functions and Architecture}\n\nSome activation functions: \n\n\\quickimage{AIML/AA-cap1-021.png}{0.4}\n\nTwo other are Rectifier Linear Unit and the softmax:\n\\quickimage{AIML/AA-cap1-022.png}{0.4}\n\n\\quickimage{AIML/softmax.png}{0.2}\n\n\nIn the all layers with the exception of the last one, ReLu or the logistic function work very well. The last layer must have a function that returns results between 0 and 1, therefore only SoftMax and sigmoid functions like the logistic function would work properly.\n\n\n\n\n\nTraining methods:\n\\quickimage{AIML/AA-cap1-025.png}{0.4}\n\n\n\nOne very interesting fact is that the image features are not selected by anyone. The network itself crafts its features throught backpropagating the changes required to get the images right. This is true for all Neural Networks.\n\nAlso, in image recognition for instance, but in deep neural networks in general, the last layers usually are fully connected.\n\n\\subsubsection{Neural Networks - BackPropagation}\n\nSome of the most useful websites to check while trying to demonstrate the backpropagation algorithm:\n\\begin{itemize}\n    \\item \\href{https://medium.com/@pdquant/all-the-backpropagation-derivatives-d5275f727f60}{\\ul{all backpropagation derivatives}}\n    \\item \\href{https://stats.stackexchange.com/questions/94387/how-to-derive-errors-in-neural-network-with-the-backpropagation-algorithm}{\\ul{Error (deltas) derivation for backpropagation in neural networks}}\n    \\item \\href{https://www.youtube.com/playlist?list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi}{3Blue1Brown Neural Networks} - Specially the last one, on backpropagation.\n\\end{itemize}\n\nThe fastest way is the following:\n\nHand written demonstration on Drive, link in Intro - the first page.\n\n\\vspace{1cm}\n\nNote that multiple training modes are possible. The normal one is on-line, where the increment to the weight is nothing more than the step multiplied by the respective partial derivative - Equation \\eqref{eq1:online}. Then one can do the batch-mode where all the samples are considered for the weights update - Equation \\eqref{eq2:batch}. Finally, there's the mini-batch mode that doesn't use all the training samples.\n\n\\begin{align}\n    w_{ij}^{(l)} &= w_{ij}^{(l)} + \\bigtriangleup w_{ij}^{(l)} \\\\\n    \\bigtriangleup w_{ij}^{(l)} &= -\\eta \\frac{\\delta C^k}{\\delta w_{ij}^{(l)}} \\label{eq1:online} \\\\\n    \\bigtriangleup w_{ij}^{(l)} &= -\\frac{\\eta}{m} \\sum_{k=1}^m  \\frac{\\delta C^k}{\\delta w_{ij}^{(l)}} \\label{eq2:batch}\n\\end{align}\n\n\n\n\\subsubsection{Neural Networks - Convolutional} \n\nConvolutional Neural Networks are extremely useful for applications like image recognition. They take a width x height x image depth 3D array and convolve it with a kernel, generating an 2D array. \n\nBecause many elements in an image are translation invariant, considering patches of the image is one of the best ways of acquiring features.\n\nConvolutional neural networks allow us to use less inputs to our neural networks. We map a region of a picture to just one pixel/input. We tend to use many different kernels - a set of weights to multiply to each of pixel in the set we chose - to perform this step.\n\n\n\\quickimage{AIML/AA-cnn.png}{0.6}\n\n\nAt the end of the convolution, an activation function (like ReLu) is applied.\n\nNote that this convolutional layer can be applied to a 3D array to reduce it to 2D. Moreover, many different kernels can be convolved with the section of the 3D array creating several layers. If there are 20 kernels, we'll have 20 2D arrays, therefore a new 3D array that is all the pixels in the several vicinities, weighted with different kernels.\n\n\\quickimage{AIML/AA-cnn3.png}{0.6}\n\n\n\n\n\\subsubsection*{Pooling}\n2D to 2D but with smaller dimensions.\nDownsize the feature array by choosing what we consider to be the most important values. For instance, for each 4x4 square of pixels, we choose the maximum of them (the highest value in grey scale, for instance). Therefore, the end result will have 16x less pixels/inputs. \n\n\\quickimage{AIML/AA-cnn2.png}{0.6}\n\n\nOverall, the tendency is the kernel to be smaller, but the network to have many many layers.\n\n\n\\subsubsection{Kernels}\nWhy kernels are important? They facilitate a lot the mapping of features to higher dimensions!\n\n\\href{https://medium.com/@zxr.nju/what-is-the-kernel-trick-why-is-it-important-98a98db0961d}{\\ul{Why kernels?}}\n\nThey will become specially important in support vector machines when the data is not separable in certain dimensions but if we increase the dimensions is possible to separate the data by an hyperplane.\n%therefore, I'll write here in a few days/weeks\n\n\n\n\\subsubsection{Classification Problems}\n\nWhen the required output is a discrete class. Instead of regressing something, the objective is to separate data into classes. Through the learning of what features each class has, be able to classify new data accordingly.\n\n\nA Bayes Estimator is a Maximum Likelihood estimator, a perfect estimator. However, it requires information that we usually don't have. Estimators like the Naive Bayes are useful because they enable simplifications if one is willing to accept the assumptions they entail.\n\nWe'll start with the maximum likelihood estimator and then particularize to Naive Bayes. \n\nLet's assume K classes and $y_k$ being each one. We want to choose $y_k$ such that $k = \\underset{k}{\\operatorname{argmax}} p(y_k|\\mathbf{x})$.\nThis is a maximum likelihood estimator because we want to choose the class that is more likely given the data we received.\n\nFrom the Bayes Theorem, one can rewrite that probability as $p(y_k|\\mathbf{x}) = \\frac{p(\\mathbf{x}|y_k) p(y_k)}{p(\\mathbf{x})}$. Given the denominator as a scaling factor and, normally, an equal probability of each class, one can rewrite the maximum likelihood estimator as:\n\n\\begin{equation}\n    y_k : k = \\underset{k}{\\operatorname{argmax}} \\ p(\\mathbf{x}|y_k)\n\\end{equation}\n\nNote that the rigorous shape of the above probability is $p(x_1, x_2, ..., x_n|y_k)$, where $n$ is the number of features in our feature vector $\\mathbf{x}$.\n\nSo far, some considerations have been made but no approximations. The Naive Bayes estimator simplifies the estimation at a cost: assuming the features are independent. If the features are independent of each other, the joint probability distribution degenerates in the multiplication of the marginal PDFs. Likewise, the joint conditional probability density function degenerates in the multiplication of the marginal probability density functions. Mathematically:\n\n\n\\begin{equation}\n    p(x_1, x_2, ..., x_n|y_k) = \\prod_{i=1}^{n} p(x_i|y_k)\n\\end{equation}\n\nFurther, one should note that due to the logarithmic function being monotone, maximizing a function or the its logarithmic has the same maximizing argument. This is a way of transforming the above multiplication into $\\sum_{i=1}^{n}\\log(p(x_i|y_k))$.\n\nOne particular case where the Naive Bayes Estimator performs decently is language recognition. Not because the letters in the \\ii{ngrams} considered are independent - that is certainly not the case, e.g `ã' is much more likely to be followed by a `o' in portuguese - but because the assumption of independence throughout the languages has somewhat of the same effect, not influencing the estimation too much. Therefore, assuming independence between characters in a case where there are so many characters and so many \\ii{ngrams} combinations to derive our estimator from, doesn't return that bad results and is quite a good application of Naive Bayes, a very simple estimator.\n\n\n\\subsection{Support Vector Machines}\n\n\n\\subsubsection{Linear Classifiers}\nWe call linear methods the classifiers whose decision boundaries are linear, hyperplanes.\n\nA way of classifying multiple classes is to assign to class i, a discriminant $f_i(x) = \\left[1 x^\\text{T}\\right] \\beta_i$.\n\nThe purpose of this function is to be 1 when the class of the input is class i, and be 0 when the class of the input is not $y_i$.\n\nTherefore, decisions are made with $\\hat{y}_i : i = \\underset{i}{\\operatorname{argmax}} f_i(x)$.\n\nLogistic Regression is a Generalized Linear Model (GLM) which can perform prediction and inference while linear Perceptrons can only achieve predictions, and in this case will perform similarly as to logistic regression. Statistical Modelling versus Machine Learning in practice.\n\nIn logistic regression, since each output represents a probability, the maximisation of the correct probability is the aim. Therefore gradient ascent (the same apart from a signal) is used.\n\n\n\\subsubsection{SVM's}\n\nThis is a great tutorial on the vector math part of SVM.\n\n\\href{https://www.svm-tutorial.com/2014/11/svm-understanding-math-part-2/}{\\ul{Vectors of SVMs}}\n\nThis is a very very good and complete tutorial about SVM:\n\\href{https://cling.csd.uwo.ca/cs860/papers/SVM_Explained.pdf}{\\ul{Fletcher: SVM explained}}\n\n\n\nSVMs can only separate between two classes, then is necessary to do strategies like 1 vs All to separate more classes. This is our $n$ sample dataset with $p$ features per sample.\n\\quickimage{AIML/AA-cap8-001.png}{0.6}\n\n\nFrom Fletcher's:\n\\quickimage{AIML/AA-cap8-002.png}{0.6}\n\n\nWe'll now have a look to some of the whys. Note that this is for a Linearly Separable Binary Classification. \n\\begin{itemize}\n    \\item How about non-Binary? One vs All.\n    \\item What if it is not Linearly Separable? Kernels.\n    \\item What else, Linear Regression? Yes.\n    \\item But the SVM always separates with an hyperplane right, always linearly? Unless a Non-linear SVM is created.\n\\end{itemize}\n\n\n\\subsubsection{One vs All approach}\n\nApplies to SMVs and all classification problems that can only distinguish between 2 classes.\n\nIt consists of training K classifiers that will make decisions between the K classes of option. Each classifier will consider the labels of that class against the ``other'' label that will be all the other samples. \n\nThe class with higher certainty is the correct one.\n\n\\quickimagesidebyside{AIML/AA-002.png}{0.6}{AIML/AA-001.png}{0.6}\n\\quickimagesidebyside{AIML/AA-003.png}{0.6}{AIML/AA-004.png}{0.6}\n\n\n\n\\subsubsection{Formulation of SVMs}\n\nAll the edge cases explained above will be constructed above this, usually being a simple modification.\n\nWe want to define a plane in an n-dimension space that divides our data in its classes.\n\nAlso, the best plane will be the one that has the highest margin of error, thus choosing correctly with higher probability.\n\n\nOne can define a plane in $\\mathds{R}^n$ like:\n\n\\begin{equation}\n    \\vec{n} \\cdot (\\vec{r} - \\vec{r}_o) = 0\n\\end{equation}\n\n$\\vec{n}$ is the vector normal to the plane, $\\vec{r}$ is a random point and $\\vec{r}_o$ is the vector that has the point $x_o = (x_1, x_2, \\dots, x_n)$.\n\nFor instances, in 3D, calling now the normal to the plane $\\vec{w} = (a,b,c)$ and $\\vec{x} = (x,y,z)$ and representing vectors in bold:\n\n\\begin{gather}\n    \\vec{n} \\cdot (\\vec{r} - \\vec{r}_o) = 0  \\\\\n    \\Leftrightarrow  \\ a (x-x_o) + b (y-y_o) + c (z-z_o) = 0 \\\\\n    \\Leftrightarrow  \\ a x + b y + c z + d = 0 \\\\\n    \\Leftrightarrow  \\ \\mathbf{w} \\cdot \\mathbf{x} + b = 0\n\\end{gather}\n\n\nTo compute the distance of a point to the hyperplane, we simply have to calculate the norm of the projection to the unitary normal vector.\n\n\\begin{equation}\n    dist = \\mathbf{x} \\cdot \\frac{\\mathbf{w}}{||\\mathbf{w}||} \n\\end{equation}\n\nNote now that if we want the distance of the plane to the origin, calling $\\mathbf{v}$ to our vector such that $\\mathbf{v} = (x_1 - x_o, y_1 - y_o, z_1 - z_o)$, where $P_o$ belongs to the plane and $P_1$ is the point in question, and $\\mathbf{n}$ to our unitary normal just so:\n\n\\begin{align}\n    dist &= \\left|v \\cdot \\frac{\\mathbf{w}}{||\\mathbf{w}||}\\right| \\\\\n    dist &= \\left|(x_1 - x_o, y_1 - y_o, z_1 - z_o) \\cdot \\frac{\\mathbf{w}}{||\\mathbf{w}||}\\right| \\\\\n    dist &= \\frac{\\left|A(x_1 - x_o) + B(y_1 - y_o) + C(z_1 - z_o)\\right|}{\\sqrt{A^2 + B^2 + C^2}}\n\\end{align}\n\n\nNote now that we need the point in the plane that is closer to the origin to calculate this distance. In fact is possible to find that point by intersecting with the plane a line directed with the normal to the place from the origin. This point however is not required for this analysis. \nAlso, note that if $P_1$ is the origin, and $P_o$ is the nearest point to the origin belonging to the plane, because it belongs to the plane $\\mathbf{w} \\cdot \\mathbf{x_o} + b = 0$, so the expression degenerates in:\n\n\\begin{equation}\n    dist = \\frac{b}{||\\mathbf{w}||}\n\\end{equation}\n\nMore generally:\n\\begin{enumerate}\n    \\item Is possible to calculate the distance of any point to the plane if we choose any point in the plane and get a vector from that point to the point the distance is required. This is because the plane is not defined uniquely by the orthogonal vector. \n    \\item A sign can be given to the distance $\\frac{b}{||\\mathbf{w}||}$. If it is below the plane, the distance is negative. If above it is positive. Before only the absolute value was considered, however if we consider w to always be the normal pointing up, we can choose this convention;\n\\end{enumerate}\n\nThis is where everything gets interesting: \n\n\\bb{This is called Support Vector Machines because they use Support vectors that are the points that are closer together.} The amount of support vectors required will depend on the dimensions, in 2 dimensions, 2 points are enough to define a plane of equal distance to both. In 3 dimensions 2 points are not enough because there's a line of points of equal distance and infinite planes can pass through that line. Therefore, 3 points are required. N dimensions, n points to define the problem. Actually, these points will be used to define $\\mathbf{w}$. The value of $b$ will be set with the margin between the hyperplanes!\n\n\nTwo hyperplanes can be defined as:\n\n\\begin{equation}\n    \\mathbf{w} \\cdot \\mathbf{x} + b = \\pm \\delta\n\\end{equation}\n\nThe actual value of $\\delta$ won't matter because it won't be more than a factor of scale.\n\nThe mid way between the two hyperplanes will be the boundary. And the decision will be based on what side of the boundary the point lies in.\n\n\\quickimage{AIML/AA-005.png}{0.6}\n\n\n\\bb{We want to maximise the distance between the two planes in order to have the boundary as far from the support vector as possible.}\n\nAlso, may be it is a good idea to take more than the $n$ closest points because those might generate a plane that doesn't divide the data properly. But this can be taken into account later. First, what is the margin between the two described planes and how to maximise it?\n\nNote that since the hyperplanes are parallel, the constant will be the only thing moving them along the normal direction and the distance between them can certainly be deduced directly from that constant.\n\nThe constants of both planes are $b \\pm \\delta$. To calculate the distance between them, is doing $\\frac{\\left| D_1 - D_2 \\right|}{||w||}$. This formula can be explained by the calculation of the difference of both planes' distance to the origin. Note now that the $b$ will be $b-\\delta$.\n\nTherefore, we get:\n\n\\begin{equation}\n    d = \\frac{2 \\delta}{||w||}\n\\end{equation}\n\nAnd to maximize this distance is necessary to minimize $||w||$, with the a constraint per training sample:\n\\quickimage{AIML/AA-010.png}{0.6}\n\n\nConstraint optimization is a problem for the Lagrange multipliers. See Section \\ref{sec:Lagrange} to see how to apply the method carefully.\n\nThe first application gets us to the primary Lagrangean function:\n\n\\quickimage{AIML/AA-011.png}{0.6}\n\nThen, by doing the gradient and replacing it in the above expression:\n\\quickimage{AIML/AA-012.png}{0.6}\n\nNote that this is a problem dual from the first one. We are still solving the same optimization problem but with this substitution, the final expression to optimize depends only on the dot inner product of $x^{(i)}$ and $x^{(j)}$ which will be very important for the \\bb{kernel trick}. Also, with the formulation below (after some simplifications) it's possible to use a \\ul{Converx Quadratic Programming (QP) Solver}. See the end of Section \\ref{sec:Lagrange} for more info on this Duality.\n\n\\quickimage{AIML/AA-013.png}{0.6}\n\nIn conclusion, with $f(x) = x cdot w + b$, the SVM provides more than a decision, a score, a certainty associated with that decision.\n\n\\subsubsection{Soft Margin - Slack Variables}\nThis was performed for an hard margin in linear separable data. If the data is not linear separable, either some \\bb{Kernel Trick} is performed or some slack is added to account for variables in the other side of the boundary. Slack variables are the penalties that will be added to points in the wrong side of the boundary and thieir sum should be minimised, i.e $C \\sum_{i=1}^n \\epsilon_i$, where C is the scale of the penalty. \n\n\\quickimage{AIML/AA-014.png}{0.6}\n\n\\subsubsection{Non-Linear SVM \\& The Kernel Trick}\n\nIn higher dimensions the data may be separable, but in the current one it may not be.\n\nThere are mappings/transformations to increase the feature space dimensionality. With higher dimensions and more complex features that are the weird combinations of the current ones, is possible that there's a separation.\n\n\\begin{equation}\n    \\tilde{\\mathbf{x}} = \\phi(\\mathbf{x}) = \n    \\begin{bmatrix}\n    \\phi_1(\\mathbf{x})\\\\\n    \\phi_2(\\mathbf{x})\\\\\n    \\vdots\\\\\n    \\phi_p(\\mathbf{x})\n    \\end{bmatrix}\n\\end{equation}\n\nThe kernel function $\\phi(\\mathbf{x})$ will map n features to p, where (usually at least) $p \\geq n$.\n\nThe biggest problem is that this high dimensionality may drive the problem infeasible since that each sample will have much more information. And the process of mapping all samples, apply the SVM and them map the boundary back to the first feature space is quite time consuming.\n\nInstead of that, since the dual formulation just requires the inner product of features, is possible to define a kernel function that is the product of the two mappings and compute the inner products in the low dimension input space instead of really having to climb the dimensionality ladder.\n\n\n\\quickimage{AIML/AA-015.png}{0.6}\n\nThe typical kernels:\n\\quickimage{AIML/AA-016.png}{0.6}\n\n\n\\subsection{Decision Trees \\& Random Forests}\n\nOnly used for classification problems.\nIt's a technique used with discrete features - this does not limit it's usage because continuous features can be discretized in a finite number of intervals.\n\nIt works by figuring out what is the best question to ask in each node (the question that separates better que labels) and when the sample reaches que bottom of the tree\n\nA measure that is used to know which variable to ask about is the impurity. There are multiple impurity functions.\n\n\n\\quickimage{AIML/AA-017.png}{0.6}\n\nThe impurity drop is what is used to choose which feature to use at a certain node.\n\n\n\\subsubsection{ID3 algorithm}\n\nImpurity criterion is entropy. And stops either when every leaf is pure or if all attributes (features) have been tested along the path to the root.\n\nIf the data or attributes are noisy (there are multiple instants with different results for supposedly the same label or attributes), then ID3 may overfit because it will ask enough questions to properly and thoroughly separate the data. One way of avoiding this is to \\bb{stop early} (when the impurity drop gets below a threshold) or do \\bb{post-processing pruning}.\n\nNote that the first method may provide problematic solutions because the impurity droop in a certain iteration may be smaller than it will be in the next one, therefore the algorithm would stop before checking the tree properly.\n\n\\subsubsection{Pruning}\n\nSimplifying the tree improves it's performance since ``less questions'' need to be asked on each sample evaluation. Additionally, pruning can lead to the exact same classification errors, therefore is very worth to do.\n\nThe actual way of implementing pruning is by testing splitting notes - not worth to check the leafs - in a bottom-up way. For each tested node, replace it by a leaf with the most likely result of the subtree. Then check if the number of classification errors improved. If it improved or stayed the same, then that simplification is viable.\n\n\\subsubsection{Boostrapping with aggregation (Bagging)} \nTo understand how random forests work, one needs to look at \\bb{Bootstrapping aggregation} first, also called \\bb{bagging}. \nGiven an $m$ sample training set, one samples it $m$ times with replacement, and repeats the process B times. This way, B training sets can be created from the original one. \n\n\\quickimage{AIML/AA-018.png}{0.6}\n\n\\bb{Bootstrapping is sampling with replacement}.\n\nThe ``with aggregation'' parts refers to final part of taking the average, i.e aggregating the results into one.\n\nThis allows us to reduce the uncertainty of $f(x)$.\n\n\\subsubsection{Random Forest}\n\nA random forest is using multiple random trees, each with a subset of features, in order to have approaches as distinct as possible in order to avoid errors of noisy labels. Each tree is trained with one of B sets of training data achieved by Bootstrapping. Then each tree is used for the estimation, and the most popular final result is considered the correct one.\n\nThe random selection of features is called \\bb{Random Subspace} and the actual percentage of features that will be used in each tree/each splitting node is a algorithm parameter. \n\n\\subsection{Leading with data anomalies - Data imbalances}\n\n\\href{https://towardsdatascience.com/handling-imbalanced-datasets-in-machine-learning-7a0e84220f28}{\\ul{Good link}}\n\nIf the data is imbalanced, for instances: 99\\% of data is class A and only one percent is class B, it is possible to find a trivial classifier that has 99\\% accuracy in this dataset by only guessing A. This is very bad as the outliers will never be found. \n\nThere are two ways of proceeding:\n\\begin{itemize}\n    \\item Reworking the dataset;\n    \\item Reworking the problem - (spoiler: this is the solution)\n\\end{itemize}\n\nFirst of all, one has to identify a naive behaviour. This can be done with a confusion matrix, computing precision, recall and F1 measure.\n\n\\bb{``}The precision of a class define how trustable is the result when the model answer that a point belongs to that class. The recall of a class expresses how well the model is able to detect that class. The F1 score of a class is given by the harmonic mean of precision and recall ($\\frac{2\\times precision \\times recall}{precision + recall})$, it combines precision and recall of a class in one metric. For a given class, the different combinations of recall and precision have the following meanings :\n\n\\begin{itemize}\n    \\item high recall + high precision : the class is perfectly handled by the model\n    \\item low recall + high precision : the model can’t detect the class well but is highly trustable when it does\n    \\item high recall + low precision : the class is well detected but the model also include points of other classes in it\n    \\item low recall + low precision : the class is poorly handled by the model\n\\end{itemize}\\bb{''}\n\nNote: recall is also called True Positive Rate (TP or TPR). Precision can be obtained from TP and False Positive Rate. Mathematically:\n\\begin{itemize}\n    \\item Recall = True positive rate = $P(\\hat{y} = T | y = T)$\n    \\item False positive rate = $P(\\hat{y} = T | y = F)$\n    \\item Precision = $\\frac{\\text{TP}}{\\text{TP}+\\text{FP}}$\n\\end{itemize}\n\nAdditionally Received Operating Characteristic (ROC) is something common to compute for each class. The Area Under ROC is an objective measure how good the performance is - the closer to 1 the better, the closer to 0.5 the worst (a cube with side 1 has area 1 and the random guess is a diagonal, thus area 0.5).\n\n\n\n\\quickimage{AIML/roc.jpeg}{0.12}\n\n\n\\subsubsection{Working the problem}\n\nThe alternative to this would be to work the dataset. To undersample the most common (throw away some samples), oversample the least common one (replicate samples) or some more fancy stuff like SMOTe (search...). All of these try to rebalance the dataset which will show the wrong proportions of data to the classifier. Therefore it will be more likely to guess the least likely class but at a considerable cost of guessing correctly the common one, specially if the data is not separable.\n\nA better way is enriching the dataset with additional features. If we find a new feature that helps distinguish the classes, the classifier can be more accurate.\n\n\n\n\n\n\n\\section{Machine Learning - Unsupervised Learning}\n\n\n\\section{Reinforcement Learning}\n\n\\subsection{Introduction}\n\nAn agent to make the wisest decision in its situation has to have knowledge on what state he is in, how the environment will evolve, how it will be like if he performs a certain action (taking into account stochastic environments) and a utility function to  know how much that state contributes to its happiness.\n\n\\quickimage{AIML/RL-001.png}{0.6}\n\n\\quickimage{AIML/RL-002.png}{0.6}\n\nThe state is the information used to determine what to do next. \nThe environment state $S_t^e$ is how the environment uses the history to choose the reward and the observation based on the action chosen by the agent.\nThe agent state $S_t^a$ is how the agent takes the history and chooses what action to do next.\n\n\\subsubsection{Markov Property}\n\nWhen a state is a sufficient statistic for the future, i.e the next state only depends on the previous state and not on the complete history, then it's said to be a \\bb{Markov State}. In other words, a Markov State is a State that has all useful information about the past.\n\n\\quickimage{AIML/RL-003.png}{0.6}\n\nTherefore, we can thrown away all the previous states because the current state has all the information I need to know the probability of the state of the future.\n\nAlso, what our representation of state is will influence what the agent will think about the outcome. If the state is the last 3 items, then shock, if it's the count, then cheese. Or it may even be impossible to tell from our state what will happen next.\n\\quickimage{AIML/RL-004.png}{0.6}\n\n\\subsubsection{Observability}\nWhen the agent fully observes the environment, then $O_t = S_t^e = S_t^a$, this is known as a \\bb{Markov Decision Process}.\n\nPartial observability is when the environment is more than what the agent can see. This is very often the case in the real world since it's hard to get the complete information about the environment. In this case, the agent must construct it's own representation of the state. That construct may be estimated with a \\ul{Recurrent Neural Network}.\n\n\\subsubsection{Agent Components}\n\n\\quickimage{AIML/RL-005.png}{0.6}\n\nThe less obvious is the value function. It's a prediction of the future rewards, not necessary only in the next state but long term future can be included as well. It's used to evaluate how good a state is.\n\nFrom the policy, it should choose an action $a = \\pi(s)$: \n\n\\quickimage{AIML/RL-007.png}{0.6}\n\n\nThe value function will put a value in the state that each action will lead to:\n\n\\quickimage{AIML/RL-006.png}{0.6}\n\n\\quickimage{AIML/RL-008.png}{0.6}\n\n\nThe model is something that predicts the next state or the next immediate reward given a certain action.\n\n\\quickimage{AIML/RL-009.png}{0.6}\n\n\\subsubsection{Agent Categories}\n\\begin{itemize}\n    \\item Value Based - only has value function (the policy is implicit)\n    \\item Policy Based - only has policy\n    \\item Actor Critic - has both policy and value function\n    \\item Model Free -  Policy and/or Value function, no model\n    \\item Model Based - Policy and/or Value function, with model\n\\end{itemize}\n\nIn one image:\n\\quickimage{AIML/RL-010.png}{0.6}\n\n\n\\subsubsection{Exploration vs Exploitation}\nOne may set some rules to make the choice much more straightforward for the machine, but also letting it learn by itself can be interesting. This is the difference between Planning and Learning. One exploits useful information to maximise the reward when the other find more information about the environment.\n\n\\bb{Something important in RL is how to balance Exploration and Exploitation. If we know some rules, we can simply program something that heuristicly would give a good result. However, exploring unknown strategies and simply let the machine learn by itself can also provide a very good insight on the game and even return higher rewards.}\n\nTherefore, this balance is key.\n\nIs it worth to give up some reward only to know more about the environment? This tradeoff is unique to RL.\n\n\n\n\\subsection{Markov Decision Processes}\n\n", "meta": {"hexsha": "2a4b857d2ea025c15c20614b744d20a7778f44a3", "size": 52658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/ML.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/ML.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/ML.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": 57.6757940854, "max_line_length": 677, "alphanum_fraction": 0.7590679479, "num_tokens": 13305, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491797, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7947245342267412}}
{"text": "\\section{Finite field in depth}\n\n\\subsection{Preliminaries}\n\n\\begin{frame}[t]{Group}\n\t\n\tAn group \\cite{Paar2010understanding} $(G, +)$ consists of a set $G$ and an operation defined on its elements, here denoted by $\\circ$:\n\t\\[\\circ: G \\times G \\to G : (a, b) \\to a \\circ b = c, c \\in G\\]\n\t\n\tA group has the following properties: \n\t\n\t\\begin{enumerate}[i.]\n\t\t\\item \\textbf{Closed}: $\\forall a, b \\in G: a \\circ b \\in G$\n\t\t\\item \\textbf{Associative}: $\\forall a, b, c \\in G: (a \\circ b) \\circ c = a \\circ (b \\circ c)$\n\t\t\\item \\textbf{Neutral element}: $\\exists 0 \\in G, \\forall a \\in G: 0 \\circ a = a$\n\t\t\\item \\textbf{Inverse elements}: $\\forall a \\in G, \\exists b \\in G: a \\circ b = 0$\n\t\\end{enumerate}\n\n\\end{frame}\n\n\\begin{frame}[t]{Group Examples}\n\t\n\tSome easy examples of groups are:\n\t\n\t\\medskip\n\t\n\t\\begin{enumerate}[i.]\n\t\t\\item $\\left( \\mathbb{Z}, +\\right)$\n\t\t\\item $\\left( \\mathbb{Z}_m, +\\right)$ with:\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $Z_m = \\left\\{z \\in \\mathbb{Z}: z < m \\right\\}$\n\t\t\t\t\\item $+: G \\times G \\to G$ is $+(a, b) = a + b \\mod m$\n\t\t\t\\end{itemize}  \n\t\\end{enumerate}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Abelian Group}\n\n\tA group \\cite{Paar2010understanding, Menezes2012handbook} $G$ is abelian if the operation $\\circ$ is abelian (commutative). \n\t\n\t\\bigskip\n\t\n\tSo, the properties would be written as: \n\t\n\t\\medskip\n\t\n\t\\begin{enumerate}[i.]\n\t\t\\item \\textbf{Closed commutative}: $\\forall a, b \\in G: a \\circ b = b \\circ a = c, c \\in G$\n\t\t\\item \\textbf{Associative}: $\\forall a, b, c \\in G: (a \\circ b) \\circ c = a \\circ (b \\circ c)$\n\t\t\\item \\textbf{Neutral element}: $\\exists 0 \\in G, \\forall a \\in G: 0 \\circ a = a \\circ 0 = a$\n\t\t\\item \\textbf{Inverse elements}: $\\forall a \\in G, \\exists b \\in G: a \\circ b = b \\circ a = 0$\n\t\\end{enumerate}\n\n\\end{frame}\n\n\\begin{frame}[t]{Ring}\n\n\tA ring \\cite{Rijndael2020design} $(R, +, \\times)$ consists of a set $R$ with two operations defined on its elements, here denoted by $+$ and $\\times$. For $R$ to qualify as a ring, the operations have to fulfill the following conditions:\n\t\n\t\\medskip\n\n\t\\begin{enumerate}[i.]\n\t\t\\item The structure $(R, +)$ is an Abelian group.\n\t\t\\item The operation $\\times$ is closed, and associative over $R$. There is a neutral element for $\\times$ in $R$ usually denoted by $1$.\n\t\t\\item The two operations $+$ and $\\times$ are related by the distributive law: $\\forall a, b, c \\in R : (a + b) \\times c = (a \\times c) + (b \\times c)$. \n\t\\end{enumerate}\n\n\t\\medskip\n\n\tA ring $(R, +, \\times)$ is called a commutative ring if the operation $\\times$ is commutative.\n\\end{frame}\n\n\\begin{frame}[t]{Field}\n\tA field \\cite{Rijndael2020design, Paar2010understanding} $F$ is a set of elements with the following properties:\n\t\n\t\\medskip\n\t\n\t\\begin{enumerate}[i.]\n\t\t\\item The structure $(F, +, \\times)$ is a commutative ring:\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item All elements of $F$ form an additive group with the group operation $+$ and the neutral element $0$.\n\t\t\t\t\\item All elements of $F$ except for the $0$ form a multiplicative group with the operation $\\times$ and the neutral element $1$. \n\t\t\t\\end{itemize}\n\t\t\\item For all elements of $F$, there is an inverse element in $F$ with respect to the operation $\\times$, except for the element 0, the neutral element of $(F, +)$.\n\t\\end{enumerate}\n\t\n\\end{frame}\n\n\\begin{frame}[t]{Finite fields}{Definition}\n\tA field $F$ is a \\textbf{finite field} (or Galois Field) if the number of elements ($|F|$) is finite. \n\t\n\t\\medskip\n\t\n\t\\begin{itemize}\n\t\t\\item The number of elements in the set is called the \\textbf{order} of the field.\n\t\t\\item A field with \\textbf{order} $m$ exists iff $m$ is a prime power. This is, \\[m = p^n\\] with $n \\in \\mathbb{Z}$ and $p$ a prime number. \n\t\t\\item $p$ is called the \\textbf{characteristic} of the finite field.\n\t\\end{itemize}\n\t\n\t\\bigskip\n\t\n\tFinite fields used in the description of Rijndael have characteristic $2$.\n\\end{frame}\n\n\\begin{frame}[t]{Finite fields}{Remarks}\n\t\\begin{itemize}\n\t\t\\item The previous definition implies there are finite fields with $11$ elements or with $169$ elements because $169 = 13^2$. But not all $orders$ are possible. For example, there's no finite field with $24$ elements because $24=3*2^3$.\n\t\t\\item The most intuitive examples of finite fields use $p=1$ and are called prime fields. In fact, $GF(2)$ plays an important role in Rijndael.\n\t\t\\item The notation from now on for a Galois Field will be $GF(p^n)$.\n\t\\end{itemize}\n\\end{frame}\n\n\n\n\n", "meta": {"hexsha": "770a59339424c446f57df235e8f669e4e87a2b45", "size": 4405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "presentation/2_mathematics/finite_fields.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/finite_fields.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/finite_fields.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": 37.6495726496, "max_line_length": 238, "alphanum_fraction": 0.665153235, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567085, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7946912300285898}}
{"text": "\\chapter{Bayesian theory}\n\\section{Probability theory and statistics}\n\\subsection[Sigma-algebra]{$\\boldsymbol\\sigma$-algebra}\n%\nThe following mathematical object is necessary in order to define probability properly:\n\n\\begin{definition}\n  Let $X$ be a set. A $\\sigma$-algebra is a set $Y$ of subsets of $X$ satisfying:\n  \\begin{enumerate}\n    \\item $\\emptyset \\in Y$\n    \\item $Z \\in Y \\implies Z^C \\in Y$ where $Z^C$ denotes the complement of $Z$, $X \\setminus Z$.\n    \\item $\\left(\\bigcup_{i=1}^\\infty Z_i\\right) \\in Y$ where $n \\in \\Nat$ and $Z_i \\in Y$ where $i = 1, 2, \\ldots$.\n  \\end{enumerate}\n\\end{definition}\nWhen $X$ is a finite set, we may limit the third condition to a finite union.\n\n\\begin{example}\n  Let $X \\coloneqq \\set{a, b, c, d}$ and $Z \\coloneqq \\set{\\set{a}}$. We extend $Z$ to a $\\sigma$-algebra $Y$:\n  \\[ Y = \\set{\\set{}, \\set{a,b,c,d}, \\set{a}, \\set{b,c,d}} \\]\n\\end{example}\nThe notion of the $\\sigma$-algebra is essential to define the notion of the probability space and the random variable rigorously.\nIn this thesis, our discussion is rigorous when $X$ is a finite set.\nWhen $X$ is an infinite set, we need a full general discussion of measure theory.\nThen our discussion will sometimes be intuitive or informal.\n\n\\subsection{Basic definitions}\n\\label{sec:bp-def}\n%\nProbability theory is concerned with random experiments and random phenomena. Probability in its basic form is the fraction of events with a certain outcome to the total number of events.\n%\n\\begin{definition}\n  \\label{def:prob}\n  \\index{Probability space}\n  \\index{Probability measure}\n  \\index{Event}\n  \\index{Random variable}\n  A \\emph{probability space} $(\\Omega, \\mathcal A, \\Prob)$ denotes\n    the set of possible outcomes, a set of events, and a map from an element of $\\mathcal A$ to a real value in $[0,1]$.\n    $\\mathcal A$ is a $\\sigma$-algebra. As elements of $\\mathcal A$ are sets, we can apply set operations on them.\n    Let $\\Omega$ be a finite set.\n    \\emph{Probability measure} $\\Prob$ satisfies the following conditions:\n    \\begin{align}\n      &\\Prob[A] \\geq 0 \\text{ for } A \\in \\mathcal A \\label{def:prob-1} \\\\\n      &\\Prob[A \\cup B] = \\Prob[A] + \\Prob[B] \\text{ for } A, B \\in \\mathcal A \\text{ and } A \\cap B = \\emptyset \\label{def:prob-2} \\\\\n      &\\Prob[\\Omega] = 1 \\label{def:prob-3}\n    \\end{align}\n    These axioms are due to Kolmogorov~\\cite{kolmogorov1950foundations}.\n    Property~\\ref{def:prob-2} implies linearity of the probability measure (for mutually exclusive events $A$):\n    \\begin{align}\n      \\Prob\\left[\\bigcup_{A \\in \\mathcal A} A\\right] &= \\sum_{A \\in \\mathcal A} \\Prob\\left[A\\right] \\label{eq:prob-linear}\n    \\end{align}\n  For $R$ \\emph{taking the value $k$}, we write,\n  \\[ \\Prob[R=k] \\coloneqq \\Prob\\left(\\set{\\omega \\in \\Omega \\mid R(\\omega) = k}\\right) \\]\n  An \\emph{event} is an element $A$ of $\\mathcal A$, hence a subset $A$ of $\\Omega$.\n  A \\emph{$\\mathbb Z$-valued random variable $R$} is a map from $\\Omega$ to $\\mathbb Z$\n  such that $R^{-1}(z) \\in \\mathcal A$ for any $z \\in \\mathbb Z$.\n  A \\emph{$\\mathbb R$-valued random variable $R$} is a map from $\\Omega$ to $\\mathbb R$\n  such that $R^{-1}((r, s]) \\in \\mathcal A$ for any real numbers $r < s$.\n\\end{definition}\n\\begin{example}\n  \\label{ex:cointoss}\n  A coin toss has two possible outcomes, heads (\\textit h) or tails (\\textit t).\n  We consider two coin tosses.\n  Then $\\Omega = \\set{(h, h), (h, t), (t, h), (t, t)}$ and $\\mathcal A$ is the powerset of $\\Omega$ (i.e. set of all subsets).\n  Let $\\Prob[A] = \\card{A} / \\card{\\Omega}$, the size of set $A$ divided by $4$.\n  Let $R$ be our random variable mapping to $\\mathbb Z$ defined as result of the first coin toss (1 represents head, 0 represents tails).\n  Then $\\Prob[R=1] = \\Prob[\\setdef{\\omega \\in \\Omega}{R(\\omega) = 1}] = \\Prob[\\set{(h, h), (h, t)}] = \\frac24$.\n\\end{example}\n\nIn the following, we will declare random variables, but won't specify the group explicitly.\nEither it is obvious from context (because of the numbers we use) or our statements work for both groups.\nIn that sense, a \\emph{random variable} is either {$\\mathbb Z$-valued} or {$\\mathbb R$}-valued here.\n\n%\\subsection{Average Value}\n%\\label{sec:bp-av}\n%%\n%\\begin{definition}\n%  \\index{Average value}\n%  \\index{Population mean}\n%  \\index{Sample mean}\n%  Let $\\Omega$ be a finite set and $R$ be a random variable.\n%  The \\emph{average value} $\\avg{R}$ of random variable $R$ is defined as,\n%  \\begin{align}\n%    \\avg{R} &\\coloneqq \\frac{1}{\\card{\\Omega}} \\sum_{a \\in \\Omega} R(a)\n%  \\end{align}\n%  If all outcomes of the sample space $\\Omega$ are considered,\n%  we call $\\avg{R}$ the \\emph{population mean} (denoted $\\mu$), otherwise \\emph{sample mean}.\n%\\end{definition}\n\n\\subsection{Expected Value}\n\\label{sec:bp-ev}\n%\n\\begin{definition}\n  \\index{Expected value}\n  \\index{Mean value}\n  The \\emph{expected value} $\\E$ (also \\emph{mean value}) of a random variable $R$ is defined by:\n  \\begin{align}\n    \\E[R]      &\\coloneqq \\mu\n%              = \\sum_{a \\in \\Omega} \\Prob[a] \\cdot R(\\set{a})\n%              = \\sum_{z \\in E} \\Prob[R = z] \\cdot z \\\\\n               = \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot R(\\omega) \\qquad\n    \\E_{A}[R]  = \\sum_{a \\in A} \\Prob[\\set{a}] \\cdot R(a)\n  \\end{align}\n  %where $\\Prob[R = z]$ is the probability of the random variable $R$ taking the value $z$.\n  %In other words, $\\Prob[R = z] \\coloneqq \\Prob[A_z]$ with $A_z \\coloneqq \\setdef{e \\in \\Omega}{R(e) = z}$.\n  Let $R$ be a map of $\\Omega$ to $E$.\n  Applying a function to an expected value means applying the function to the element of $E$.\n  Let $f$ be any function with domain $E$, then\n  \\[\n    \\E[f(R)]      = \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot f(R(\\omega)) \\qquad\n    \\E_{A}[f(R)]  = \\sum_{a \\in A} \\Prob[\\set{a}] \\cdot f(R(a))\n  \\]\n\\end{definition}\n\nLet $R$ and $S$ be two random variables. Let $c \\in \\mathbb R$.\nThe following properties are satisfied:\n\\begin{align}\n  \\E[c]     &= \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot c = 1 \\cdot c = c \\\\\n  \\E[R + c] &= \\sum_{\\omega \\in \\Omega} \\left(\\Prob[\\set{\\omega}] \\cdot (R(\\omega) + c)\\right) \\notag\\\\\n            &= \\sum_{\\omega \\in \\Omega} \\left(\\Prob[\\set{\\omega}] \\cdot R(\\omega)\\right) + \\sum_{\\omega \\in \\Omega} \\left(\\Prob[\\set{\\omega}] \\cdot c\\right) \\notag\\\\\n            &= \\E[R] + c \\cdot \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\notag\\\\\n            &= \\E[R] + c \\cdot 1 = \\E[R] + c \\\\\n  \\E[R + S] &= \\sum_{\\omega \\in (\\Omega_R \\cup \\Omega_S)}\n              \\begin{cases}\n                \\sum_{\\omega \\in \\Omega_R} \\Prob[\\set{\\omega}] \\cdot R(\\omega) & \\text{if } \\omega \\in \\Omega_R \\\\\n                \\sum_{\\omega \\in \\Omega_S} \\Prob[\\set{\\omega}] \\cdot R(\\omega) & \\text{if } \\omega \\in \\Omega_S\n              \\end{cases}\\notag\\\\\n            &= \\sum_{\\omega \\in \\Omega_R} \\Prob[\\set{\\omega}] \\cdot R(\\omega) + \\sum_{\\omega \\in \\Omega_S} \\Prob[\\set{\\omega}] \\cdot R(\\omega) \\notag\\\\\n            &= \\E[R] + \\E[S] \\label{eq:ERS-RpS} \\\\\n  \\E[c \\cdot R]\n            &= \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot (c \\cdot R(\\omega)) \\notag\\\\\n            &= c \\cdot \\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot R(\\omega) \\notag\\\\\n            &= c \\cdot \\E[R]\n\\end{align}\nIt immediately follows, that this holds true for $\\E_A$ for any $A \\in \\mathcal A$.\n\n\\subsection{Equivalence of the continuous probability model}\n\\label{sec:bp-continuous}\n%\n\\begin{definition}\n  \\index{Probability Density Function}\n  Let $R$ be an $\\mathbb R$-valued random variable and\n  $f$ be a continuous function defined in $(-\\infty, \\infty) \\subseteq \\mathbb R$.\n  Let $f$ satisfy the following properties:\n  \\[\n    \\Prob[R \\leq y] \\coloneqq \\int\\limits_{-\\infty}^y f(x) \\, dx \\hspace{28pt}\n    \\Prob[z \\leq R \\leq y] \\coloneqq \\int\\limits_z^y f(x) \\, dx \\hspace{28pt}\n    \\Prob[z \\leq R] \\coloneqq \\int\\limits_z^\\infty f(x) \\, dx\n  \\]\n  This establishes a relation between function $f$ and random variable $R$.\n  Because $\\Prob[R \\leq y]$ satisfies properties~\\ref{def:prob-1} and \\ref{def:prob-3} of probability measures,\n  $f$ also satisfies:\n  \\begin{align}\n    f(x) &\\geq 0 \\qquad \\forall x \\in (-\\infty, \\infty) \\label{prop:pdf1} \\\\\n       1 &= \\int_{-\\infty}^{\\infty} f(x) \\, dx \\label{prop:pdf2}\n  \\end{align}\n  $f$ is called a \\emph{Probability Density Function} (PDF).\n\\end{definition}\n\\begin{example}\n  \\[ f(x \\; | \\; \\mu, \\sigma^2) = \\frac{1}{\\sqrt{2\\pi\\sigma^2} } \\; e^{ -\\frac{(x-\\mu)^2}{2\\sigma^2} } \\]\n  The normal distribution function, depending on parameters $\\mu$ and $\\sigma^2$, is one example for a probability density function.\n  The function is introduced in Section~\\ref{sec:bp-norm-dist} in detail.\n\\end{example}\n\nWe have seen that the continuous model follows equivalent properties like the discrete model.\nThis is also true for the expected value.\n\n\\begin{definition}\n  \\index{Expected value}\n  The \\emph{expected value} of random variable~$R$ %in the continuous model\n  is defined as,\n  \\begin{align}\n    \\E[R] &\\coloneqq \\int_{-\\infty}^\\infty \\left(\\Prob[R=x] \\cdot x\\right) \\, dx\n  \\end{align}\n  Since intuitively $\\int_{-\\infty}^\\infty \\Prob[R=x] \\, dx = \\int_{\\mathbb R} f(x) \\, dx$,\n  \\[ \\E[R] = \\int_{\\mathbb R} x \\cdot f(x) \\, dx \\]\n\\end{definition}\n%\n\\begin{proof}\n  Let $R$ and $S$ be two random variables. Let $c \\in \\mathbb R$.\n  The expected value satisfies:\n  %\n  \\begin{align}\n    \\E[c]     &\\coloneqq c \\label{eq:Ec} \\\\\n    \\E[R + c] &\\coloneqq \\int_{\\mathbb R} \\Prob[R=x] \\cdot (x + c) \\, dx \\notag\\\\\n              &= \\int_{\\mathbb R} \\left(\\Prob[R=x] \\cdot x + \\Prob[R=x] \\cdot c\\right) \\, dx \\notag\\\\\n              &= \\int_{\\mathbb R} \\Prob[R=x] \\cdot x \\, dx + c \\cdot \\int_{\\mathbb R} \\Prob[R=x] \\, dx \\notag\\\\\n              &= \\E[R] + c \\cdot 1 = \\E[R] + c \\\\\n    \\E[R + S] &\\coloneqq \\int_{\\mathbb R} \\left(\\Prob[R=x] \\cdot x + \\Prob[S=x] \\cdot x\\right) \\, dx \\notag\\\\\n              &= \\int_{\\mathbb R} \\Prob[R=x] \\cdot x \\, dx + \\int_{\\mathbb R} \\Prob[S=x] \\cdot x \\, dx \\notag\\\\\n              &= \\E[R] + \\E[S] \\label{eq:Evv} \\\\\n    \\E[c \\cdot X] &\\coloneqq \\int_{\\mathbb R} \\Prob[R=x] \\cdot (x \\cdot c) \\, dx \\notag\\\\\n              &= c \\cdot \\int_{\\mathbb R} \\Prob[R=x] \\cdot x \\, dx\n              = c \\cdot \\E[X] \\label{eq:Ecv}\n  \\end{align}\n\\end{proof}\nBecause $\\Prob$ and $\\E$ provide the same properties in the discrete and continuous case,\nwe often do not distinguish between these cases. The statements hold true for $\\mathbb Z$-valued\nas well as $\\mathbb R$-valued random variables.\n\n\\subsection{Variance and standard deviation}\n\\label{sec:bp-var-sd}\n%\n\\begin{definition}\n  \\index{Variance}\n  \\emph{Variance} quantifies how strong values are spread out from $\\E[R]$: %the expected value $\\E[R]$:\n  \\[ \\sigma^2 \\coloneqq \\E\\left[(R - \\E[R])^2\\right] \\]\n\\end{definition}\nConsidering the entire population, the variance can also quantify over the population mean $\\mu$:\n\\[ \\sigma^2 = \\Var[R] \\coloneqq \\E[(R - \\mu)^2] \\]\nIn the discrete case, this is equivalent to,\n\\[ \\Var[R] = \\E\\left[\\sum_{\\omega \\in \\Omega} \\Prob[\\set{\\omega}] \\cdot \\left(R(\\omega) - \\mu\\right)^2\\right] \\]\nand in the continuous case, we have:\n\\[ \\Var[R] = \\E\\left[\\int_{\\mathbb R} \\Prob[R=x] \\cdot \\left(x + \\mu\\right)^2 \\, dx\\right] \\]\n\\begin{definition}\n  \\index{Standard deviation}\n  The \\emph{standard deviation} is defined as its second root:\n  \\[ \\sd = \\sqrt{\\Var[R]} \\]\n\\end{definition}\n\n\\subsection{Covariance}\n\\label{sec:covar}\n%\n\\index{Covariance}\n\\emph{Covariance} measures the joint variability of two given random variables.\nIt is defined as:\n\\begin{align}\n  \\Cov[X,Y]\n    &= \\E[(X - \\E[X])(Y - \\E[Y])] \\label{eq:cov}\\\\\n    &= \\E[XY - Y\\cdot\\E[X] - X\\cdot\\E[Y] + \\E[X]\\E[Y]] \\notag\\\\\n    &= \\E[XY] - \\E[Y]\\cdot\\E[X] - \\E[X]\\cdot\\E[Y] + \\E[X]\\E[Y] \\notag\\\\\n    &= \\E[XY] - \\E[X]\\cdot\\E[Y] \\label{eq:cov-exy}\n\\end{align}\n%\nIf $X$ and $Y$ are independent (Section~\\ref{sec:bp-ev-indep}), then the covariance is zero.\n\\begin{align}\n  \\Cov[X,Y] &= \\E[XY] - \\E[X] \\cdot \\E[Y] = \\E[X] \\cdot \\E[Y] - \\E[X] \\cdot \\E[Y] = 0 \\label{eq:CovXY0}\n\\end{align}\nWe will exploit the following properties:\n\\begin{align}\n  \\Cov[X,Y] &= \\E[(X - \\E[X])(Y - \\E[Y])] = \\E[(Y - \\E[Y])(X - \\E[X])] = \\Cov[Y,X] \\\\\n  \\Cov[X,X] &= \\E[(X - \\E[X])^2] = \\Var[X]\n\\end{align}\n%\nLet $X$ be a set of $n$ independent variables $X_{1 \\leq i \\leq n}$.\nThen it holds that:\n\\begin{align}\n  \\Var\\left[\\sum_{i=1}^n X_i\\right]\n    &= \\E\\left[\\left(\\sum_{i=1}^n X_i - \\E\\left[\\sum_{i=1}^n X_i\\right]\\right)^2\\right] \\notag \\\\\n    &= \\E\\left[\\left(\\sum_{i=1}^n \\left(X_i - \\E\\left[X_i\\right]\\right)\\right)^2\\right] \\notag \\\\\n    &= \\E\\left[\\sum_{i=1}^n \\left(X_i - \\E[X_i]\\right) \\cdot \\sum_{j=1}^n \\left(X_j - \\E[X_j]\\right)\\right] \\notag \\\\\n    &= \\E\\left[\\sum_{j=1}^n \\left(\\sum_{i=1}^n (X_i - \\E[X_i])\\right) (X_j - \\E[X_j]) \\right] \\notag \\\\\n    &= \\E\\left[\\sum_{i,j \\in [1,n]} \\left(X_i - \\E[X_i]\\right) \\left(X_j - \\E[X_j]\\right)\\right] \\notag \\\\\n    &= \\sum_{i,j \\in [1,n]} \\E[(X_i - \\E[X_i])(X_j - \\E[X_j])] \\notag \\\\\n    &= \\sum_{i,j \\in [1,n]} \\Cov[X_i, X_j] \\notag \\\\\n    &= \\sum_{i \\in [1,n]} \\Cov[X_i, X_i] + \\sum_{\\substack{i \\neq j \\\\ i,j \\in [1,n]}} \\Cov[X_i, X_j] \\notag \\\\\n    &= \\sum_{i=1}^n \\Var[X_i] + \\sum_{\\substack{i \\neq j \\\\ i,j \\in [1,n]}} \\Cov[X_i, X_j] \\notag \\\\\n    &= \\sum_{i=1}^n \\Var[X_i] + 2 \\cdot \\sum_{1 \\leq i < j \\leq n} \\Cov[X_i, X_j] \\label{eq:sumVarCov}\n\\end{align}\n\n\\subsection{Law of Large Numbers}\n\\label{sec:bp-lln}\n%\nThe Law of Large Numbers stresses the practical importance of the expected value.\n\nTo prove this theorem, we use Chebyshev's Inequality, the Weak Law of Large numbers,\nBorel-Cantelli Lemma, and the Strong Law of Large Numbers.\nDepending on your requirements of certainty, either the \\emph{Weak} Law of Large numbers or\nthe \\emph{Strong} Law of Large Numbers might be considered as Law of Large Numbers.\nOur proof structure is based on Craig A. Tracy's~\\cite{cnfgen}\\footnote{\n  Please recognize that there is a small typographical error on page~3.\n  \\enquote{$S_n(\\omega) = 1$ for every $n$} should be \\enquote{$X_n(\\omega) = 1$ for every $n$}.\n}.\n\n\\subsubsection{Chebyshev's Inequality}\n\\label{sec:bp-chebyshev}\n%\nConsider the continuous case.\nLet $R$ be a random variable, $f$ be a PDF over $R$,\n$a \\in \\mathbb R_{\\geq 0}$, $p \\in \\mathbb N$ and let $\\E[R^p]$ be defined as follows:\n\\begin{align*}\n  \\E[R^p]\n          = \\int\\limits_{\\mathbb R} x^p \\cdot f(x) \\, dx \n          \\geq \\int\\limits_{x \\geq a} x^p \\cdot f(x) \\, dx \n          \\geq a^p \\int\\limits_{x \\geq a} f(x) \\, dx \n          = a^p \\cdot \\Prob[R \\geq a]\n\\end{align*}\nThe discrete case follows immediately.\nThis concludes the correctness of the following theorem:\n\\begin{theorem}[Chebyshev's Inequality Theorem]\\label{thm:chebyshev}\n  Let $R$ be a random variable, $a \\in \\mathbb R_{\\geq 0}$, and $p \\in \\mathbb N$ is arbitrary.\n  Assume $\\E[R^p] < \\infty$.\n  Then it holds that,\n  \\[ \\Prob[R \\geq a] \\leq \\frac{1}{a^p} \\E[R^p] \\]\n\\end{theorem}\n\n\\subsubsection{Weak Law of Large Numbers}\n\\label{sec:bp-weak-law}\n%\nThe next theorem is called Weak Law of Large Numbers.\n\\begin{theorem}[Weak Law of Large Numbers, Bernoulli's Theorem]\\label{thm:weak-lln}\n  Let $R_i$ be a sequence of independent and identically distributed random variables\n  (see section~\\ref{sec:bp-iid} for a definition of i.i.d.)\n  with common mean $\\mean$ and variance $\\var$. Let\n  \\[\n      S_n \\coloneqq \\sum_{i=1}^n R_i \\hspace{50pt}\n      T_n \\coloneqq \\frac{S_n}{n} - \\mean\n  \\]\n  Then for any $\\varepsilon > 0$,\n  \\[ \\lim_{n\\to\\infty} \\Prob[T_n \\geq \\varepsilon] = 0 \\]\n\\end{theorem}\n\n\\begin{proof}\n  First, we determine the expected values.\n  \\begin{align}\n      \\E[S_n] &= \\E\\left[\\sum_{i=1}^n R_i\\right] = \\sum_{i=1}^n \\E[R_i] = \\sum_{i=1}^n \\mu = n \\cdot \\mu & \\eqref{eq:Evv} \\label{eq:ES_n} \\\\\n%      \\E[T_n] &= \\E\\left[\\frac{1}{n}\\left(R_1 + R_2 + \\ldots + R_n\\right) - \\mu\\right] \\notag\\\\\n%              &= \\frac1n \\left(\\E[R_1] + \\E[R_2] + \\ldots + \\E[R_n]\\right) - \\E[\\mu] & \\eqref{eq:Ecv} \\notag\\\\\n%              &= \\frac{n \\cdot \\mu}{n} - \\mu = 0 \\label{eq:tn0}\n      \\E[T_n] &= \\E\\left[\\frac{S_n}{n} - \\mu\\right] = \\frac{\\E\\left[S_n\\right]}{\\E\\left[n\\right]} - \\E\\left[\\mu\\right] & \\eqref{eq:Evv} \\notag\\\\\n              &= \\frac{n \\cdot \\mu}{n} - \\mu = 0  & \\eqref{eq:ES_n}, \\eqref{eq:Ecv} \\label{eq:tn0}\n  \\end{align}\n  We also need a result regarding the variance.\n  In the continuous and discrete case, it holds that $a^2 \\cdot \\Var[X] = \\Var[a \\cdot X]$:\n  \\begin{align}\n    a^2 \\cdot \\Var[X] &= a^2 \\cdot \\int (x - \\mu)^2 \\cdot f(x) \\, dx = \\int (a \\cdot (x - \\mu))^2 \\cdot f(x) \\, dx \\notag \\\\\n    a^2 \\cdot \\Var[X] &= a^2 \\cdot \\sum_{i=1}^n p_i \\cdot (x_i - \\mu)^2 = \\sum_{i=1}^n p_i \\cdot a^2 \\cdot (x_i - \\mu)^2 = \\sum_{i=1}^n p_i \\cdot (a \\cdot (x_i - \\mu))^2 \\label{eq:a2V}\n  \\end{align}\n  The relation $\\E[X^2] = \\Var[X] + \\E[X]^2$ holds as well,\n  \\begin{align}\n    \\Var[X] &= \\E[(X - \\mu)^2] = \\E[X^2] - \\E[2X\\mu] + \\E[\\mu^2] \\notag & \\eqref{eq:Evv} \\\\\n            &= \\E[X^2] - 2 \\cdot \\E\\left[X \\cdot \\E[X]\\right] + \\E\\left[\\E[X]^2\\right] & \\eqref{eq:Ecv} \\notag\\\\\n            &= \\E[X^2] - 2 \\cdot \\E[X]^2 + \\E[X]^2 & \\eqref{eq:Ecv} \\notag\\\\\n            &= \\E[X^2] - \\E[X]^2 \\label{eq:VXisEX2-EX2}\n  \\end{align}\n  We use this result to prove $\\Var[T_n] = \\frac{\\sigma^2}{n}$.\n  \\begin{align}\n    \\Var[T_n] &= \\E[T_n^2] - \\E[T_n]^2 = \\E[T_n^2] - 0^2 = \\E[T_n^2] & \\eqref{eq:VXisEX2-EX2} \\eqref{eq:tn0} \\label{eq:EVT_n}\\\\\n              &= \\E\\left[\\left(\\frac{S_n}{n} - \\mu\\right)^2\\right] = \\E\\left[\\left(\\frac{S_n}{n}\\right)^2 - 2\\frac{S_n}{n}\\mu + \\mu^2\\right] \\notag \\\\\n              &= \\E\\left[\\left(\\frac{S_n}{n}\\right)^2\\right] - 2\\cdot\\E\\left[\\frac{\\mu}{n} S_n\\right] + \\E\\left[\\mu^2\\right] & \\eqref{eq:Evv}\\eqref{eq:Ecv} \\notag\\\\\n              &= \\Var\\left[\\frac{S_n}{n}\\right] + \\E\\left[\\frac{S_n}{n}\\right]^2 - 2\\mu \\cdot \\E\\left[\\frac{S_n}{n}\\right] + \\mu^2 & \\eqref{eq:VXisEX2-EX2}\\eqref{eq:Ec} \\notag \\\\\n              &= \\frac1{n^2} \\cdot \\Var\\left[S_n\\right] + \\left(\\frac1{n} \\cdot \\E\\left[S_n\\right]\\right)^2 - \\frac{2\\mu}{n} \\cdot (n \\cdot \\mu) + \\mu^2 & \\eqref{eq:Ecv}\\eqref{eq:a2V} \\notag \\\\\n              &= \\frac1{n^2} \\cdot \\left(\\Var\\left[S_n\\right] + \\E[S_n]^2\\right) - 2\\mu^2 + \\mu^2 \\notag \\\\\n              &= \\frac{1}{n^2} \\left(\\Var\\left[\\sum_{i=1}^n R_i\\right] + \\E[S_n]^2\\right) - \\mu^2 \\notag\\\\\n              &= \\frac{1}{n^2} \\left(\\sum_{i=1}^n \\Var[R_i] + 2\\sum_{\\substack{i<j \\\\ i,j=1}}^n \\Cov[R_i,R_j] + \\E[S_n]^2\\right) - \\mu^2 & \\eqref{eq:sumVarCov} \\notag\\\\\n              &= \\frac{1}{n^2} \\left(\\sum_{i=1}^n \\sigma^2 + 0 + (n \\cdot \\mu)^2\\right) - \\mu^2 & \\eqref{eq:ES_n} & \\eqref{eq:CovXY0} \\notag\\\\\n              &= \\frac{1}{n^2} \\left(n \\cdot \\sigma^2 + n^2 \\cdot \\mu^2\\right) - \\mu^2 = \\frac{\\sigma^2}{n} + \\mu^2 - \\mu^2 = \\frac{\\sigma^2}{n}\n  \\end{align}\n\\end{proof}\n%\n%% REMARK: Yes, this is a quote from Wikipedia. Yes, it is true. But it is too short, because we didn't show that the covariance is zero and whether they are uncorrelated or not. So I prefer the approach above\n%\\index{Bienaym\\'e formula}\n% This proves the so-called Bienaym\\'e formula.\n% A shorter approach uses the definition of the mean:\n% \\[ \\Var[\\avg{T_n}] = \\Var\\left(\\frac1n \\sum_{i=1}^n X_i\\right) = \\frac1{n^2} \\sum_{i=1}^n \\Var[X_i] = \\frac{\\sigma^2}{n} \\]\n%\n%Furthermore, the following equation holds:\n%\\begin{align}\n%    \\Var[T_n] &= \\E\\left[(T_n - \\E[T_n])^2\\right] = \\E\\left[(T_n - 0)^2\\right] = \\E\\left[T_n^2\\right] \\label{eq:EVT_n}\n%\\end{align}\n%\nNow we can apply Chebyshev's Inequality Theorem ($R = T_n$, $a = \\varepsilon \\in \\mathbb R, p = 2$):\n\\begin{align}\n  \\Prob[\\abs{T_n} \\geq \\varepsilon]\n    &\\leq \\frac{1}{\\varepsilon^2} \\E\\left[\\abs{T_n}^2\\right]\n    = \\frac{1}{\\varepsilon^2} \\Var\\left[\\abs{T_n}\\right]\n    = \\frac{1}{\\varepsilon^2} \\frac{\\sigma^2}{n}\n    & \\eqref{eq:EVT_n} \\label{eq:cheby-applied}\n\\end{align}\nFor any $\\varepsilon > 0$ with $n \\to \\infty$, it holds that\n\\[ \\Prob[\\abs{T_n} \\geq \\varepsilon] \\to 0 \\]\n\\[\n    \\Leftrightarrow \\forall \\varepsilon > 0:\n    \\lim_{n\\to\\infty} \\Prob[\\abs{T_n} \\geq \\varepsilon] = 0\n\\]\n\nThis concludes the proof of the Weak Law of Large Numbers.\nIn order to finish our proof of the Strong Law of Large numbers,\nwe will use the Borel-Cantelli Lemma, an important result of measure theory.\n\n\\subsubsection{Borel-Cantelli Lemma}\n\\label{sec:bp-borel-cantelli}\n%\n\\begin{lemma}[Borel-Cantelli Lemma]\\label{lemma:bcl}\n  Let $R_i$ with $1 \\leq i < \\infty$ be a sequence of events.\n  Assume the sum of these probabilities is finite, then it holds that:\n  \\begin{align}\n    \\sum_{i=1}^\\infty \\Prob[R_i] < \\infty\n    &\\implies\n    \\Prob\\left(\\limsup\\limits_{i\\to\\infty} R_i\\right) = 0\n  \\end{align}\n  So the probability, that the occuring event is an event which occurs infinitely often, is 0.\n\\end{lemma}\n\n\\begin{proof}\n  Please consider, that the limsup is defined as,\n  \\begin{align}\n    \\limsup\\limits_{i\\to\\infty} R_i &\\coloneqq \\bigcap_{j=1}^\\infty \\bigcup_{i \\geq j}^\\infty R_i \\label{eq:limsup-char}\n  \\end{align}\n\n  The condition requires, that $\\sum_{i=1}^\\infty \\Prob[R_i] < \\infty$.\n  This statement is equivalent to\n  \\begin{align}\n    \\inf_{j \\geq 1} \\sum_{i=j}^\\infty \\Prob[R_i] &= 0  \\label{eq:inf0}\n  \\end{align}\n\n  We can make our final conclusion to prove the Borel-Cantelli Lemma:\n  \\begin{align}\n    \\Prob\\left[\\limsup_{i\\to\\infty} R_i\\right]\n      &= \\Prob\\left[\\bigcap_{j=1}^\\infty \\bigcup_{i=j}^\\infty R_i\\right] & \\eqref{eq:limsup-char} \\notag\\\\\n      &\\leq \\inf_{j \\geq 1} \\Prob\\left[\\bigcup_{i=j}^\\infty R_i\\right] & \\eqref{eq:prob-linear}\\notag\\\\\n      &\\leq \\inf_{j \\geq 1} \\sum_{i=j}^\\infty \\Prob\\left[R_i\\right] \\notag\\\\\n      &= 0 & \\eqref{eq:inf0}\n  \\end{align}\n  The result of an intersection of elements creates a set, which\n  is an actual subset in any of these sets. However, the infimum\n  is not necessarily an element of the set. Hence, an inequality\n  is introduced in the second line.\n\\end{proof}\n\n\\subsubsection{Strong Law of Large Numbers}\n\\label{sec:bp-strong-law}\n%\n\\begin{theorem}[Strong Law of Large Numbers]\\label{thm:slln}\n  Assume the definitions of Theorem~\\ref{thm:weak-lln}.\n  Therefore, $R_1, R_2, \\ldots$ is an infinite sequence of independent random variables\n  with a common distribution ($\\mu = \\E[R_j]$, $\\sigma^2 = \\Var[R_j]$). $S_n$ and $T_n$\n  are defined. Now consider event $\\mathcal E$:\n  \\[\n    \\mathcal E = \\set{\n      \\omega \\in \\Omega: \\lim_{n\\to\\infty} \\frac{S_n(\\omega)}{n} = \\mu\n    }\n  \\]\n  Then it holds that\n  \\[ \\Prob[\\mathcal E] = 1 \\]\n\\end{theorem}\n\n\\begin{proof}\n  The following proof assumes $\\sigma^2 = \\E[R_j^2] < \\infty$ and $\\E[R_j^4] < \\infty$.\n  This restriction makes our proof easier, but the less restricted case $\\E[R_j] < \\infty$ suffices as assumption\n  (but this is not proven in this thesis).\n\n  Without loss of generality we assume $\\mu = 0$. \\\\\n  If $\\mu = 0$ is not satisfied, we consider $P_j \\coloneqq R_j - \\mu$ instead.\n\n  First of all, we want to give a brief outline of the proof. If it holds that,\n  \\[ \\lim_{n\\to\\infty} \\frac{S_n(\\omega)}{n} \\neq 0 \\]\n  then $\\exists \\varepsilon \\in \\mathbb R$ with $\\varepsilon > 0$ such that for infinitely many $n$\n  \\[ \\frac{S_n(\\omega)}{n} > \\varepsilon \\]\n  So to prove the theorem, we will prove that for every $\\varepsilon > 0$,\n  \\[ \\Prob[S_n > n \\cdot \\varepsilon \\text{ infinitely often}] = 0 \\]\n  In the following, this reveals that\n  \\[ \\Prob[\\mathcal E] = \\Prob\\left[\\frac{S_n}{n} = 0\\right] = 1 \\]\n  proving Theorem~\\ref{thm:slln}. Hence condition $\\frac{S_n}{n} = 0$ holds with probability $1$.\n\n  Now we will actually carry out the proof. We define\n  \\[ A_n = \\set{\\omega \\in \\Omega: S_n \\geq n \\cdot \\varepsilon} \\]\n  and look at $\\Prob[A_n]$ using the Chebyshev inequality (Theorem~\\ref{thm:chebyshev}) with $p=4$ and $a=(n\\cdot\\varepsilon)$:\n  \\[ \\Prob[S_n \\geq (n\\cdot\\varepsilon)] \\leq \\frac{1}{(n\\cdot\\varepsilon)^4} \\E[S_n^4] \\]\n  We must determine $\\E[S_n^4]$ which equals to\n  \\begin{align*}\n    \\E\\left[\\sum_{1 \\leq i,j,k,l}^n R_i R_j R_k R_l\\right]\n      &= \\E\\left[\\sum_{1\\leq i}^n \\sum_{1\\leq j}^n \\sum_{1\\leq k}^n \\sum_{1\\leq l}^n R_i R_j R_k R_l\\right] \\notag\\\\\n%      &= \\E\\left[(R_1^4 + \\ldots + R_1 R_n^3) + (R_2^4 + \\ldots) + \\ldots + (R_n^4 + \\ldots) \\right]\n      &= \\E\\left[(R_1^4 + R_1^3 R_2 + \\ldots + R_1^4 R_n) + \\ldots + (R_n R_1^3 + \\ldots + R_n^4)\\right]\n  \\end{align*}\n  Here the expected value of an addition of multiplication of random variables is asked for.\n  As far as the random variables are i.i.d.,\n  we equivalently look for the addition of multiplication of the expected value of a random variable\n  (compare with Equation~\\ref{eq:ERS-RpS} and Section~\\ref{sec:bp-ev-indep}).\n  Because $\\E[R_i] = 0$, we can remove all terms containing $R_j$ of degree 1 for any $j$.\n  These are terms of the structure (assuming $i, j, k$ and $l$ distinct),\n  \\[\n    \\E[R_i^3 R_j], \\,\n    \\E[R_i^2 R_j R_k], \\,\n    \\E[R_i R_j R_k R_l]\n  \\]\n  The non-zero terms are $\\E[R_i^4]$ and $\\E[R_i^2 R_j^2] = \\left(\\E[R_i^2]\\right)^2 = \\sigma^4$.\n  Now, we need to quantify the occurences of these non-zero terms.\n  $\\E[R_i^4]$ occurs $n$ times.\n  Terms $\\E[R_i^2 R_j^2]$ occur $3n \\cdot (n-1)$ times,\n    as there are $\\frac{(n-1) \\cdot n}{2}$ ways to choose 2 indices\n    and 6 ways to find $R_i^2 R_j^2$.\n  In conclusion, we determined,\n  \\[\n    \\E\\left[S_n^4\\right]\n      = n \\cdot \\E\\left[R_1^4\\right] + 3n \\cdot (n - 1) \\cdot \\sigma^4\n      = n \\cdot \\left( \\E\\left[R_1^4\\right] + 3n \\cdot \\sigma^4 - 3 \\sigma^4 \\right)\n  \\]\n  In this expression, $n$ is our only constant occuring with polynomial degree $2$. So for any $n$ sufficiently large, there exists $C \\in \\mathbb R$ such that\n  \\begin{align}\n    3 \\sigma^4 n^2 + \\left(\\E\\left[R_1^4\\right] - 3 \\sigma^4\\right) \\cdot n &\\leq C \\cdot n^2 \\label{eq:3sigman2}\n  \\end{align}\n  \\[ \\Rightarrow \\E\\left(S_n^4\\right) \\leq C n^2 \\]\n\n  We return back to Chebyshev's inequality\n  \\[\n      \\Prob[S_n \\geq (n\\cdot\\varepsilon)]\n      \\leq \\frac{1}{(n\\cdot\\varepsilon)^4} \\E[S_n^4]\n      \\leq \\frac{C \\cdot n^2}{\\varepsilon^4 \\cdot n^2 \\cdot n^2}\n  \\]\n  Let $n_0$ be the smallest $n$ such that Equation~\\eqref{eq:3sigman2} is satisfied.\n  Then it follows that,\n  \\[\n      \\sum_{n \\geq n_0} \\Prob\\left[S_n \\geq n \\cdot \\varepsilon\\right]\n      \\leq \\sum_{n \\geq n_0} \\frac{C}{\\varepsilon^4 n^2} < \\infty\n  \\]\n  With this approach, we skip a finite number of elements of the sum. This does not affect its convergence or divergence.\n  Therefore, the conditions to apply the Borel-Cantelli Lemma (Lemma~\\ref{lemma:bcl}) are satisfied.\n  For every $\\varepsilon > 0$ it holds that,\n  \\[ \\Prob\\left[S_n \\geq n \\varepsilon \\text{ infinitely often}\\right] = 0 \\]\n\\end{proof}\n\n\\subsection{Marginal distribution}\n\\label{sec:bp-marginalization}\n%\n\\begin{definition}\n  \\index{Marginal probability}\n  \\index{Marginalization}\n  Let $\\Omega$ be finite.\n  Let $R$ and $S$ be two, discrete random variables. Then we define,\n  \\[\n    \\Prob[R=r, S=s] \\coloneqq \\Prob[\\setdef{\\omega \\in \\Omega}{R(\\omega) = r \\land S(\\omega) = s}]\n  \\]\n  This definition enables us to define the \\emph{marginal distribution of $R$ and $S$}.\n  We also say, we \\emph{marginalize $S$ out of $R$}:\n  \\[ \\Prob[R=r] = \\sum_{s \\in S} \\Prob[R=r, S=s] \\]\n\\end{definition}\n\\begin{example}\n  Consider our coin tossing example again.\n  Let $R$ be our random variable mapping to $\\mathbb Z$ defined as result of the first coin toss\n  (1 represents head, 0 represents tails).\n  $\\mathbb Z$-valued random variable $S$ is defined as result of the second coin toss.\n  Then\n  \\[\n    \\Prob[R=1, S=0] = \\Prob[\\setdef{\\omega \\in \\Omega}{R(\\omega) = 1 \\land S(\\omega) = 0}]\n                    = \\Prob[\\set{(h, t)}] = \\frac14\n  \\]\n  Marginalization applies, if we query $\\Prob[R=1]$:\n  \\[\n    \\Prob[R=1] = \\Prob[R=1, S=0] + \\Prob[R=1, S=1] = \\Prob[\\set{(h, t)}] + \\Prob[\\set{(h, h)}] = \\frac14 + \\frac14 = \\frac24\n  \\]\n\\end{example}\n\n\\subsection{Joint distribution}\n\\label{sec:bp-joint-distribution}\n%\n\\begin{definition}\n  Let $R_i$ be discrete random variables in $1 \\leq i \\leq n$.\n  Joint distribution is given by the \\emph{chain rule of probability}:\n  \\begin{align*}\n    \\Prob[R_1=r_1, \\ldots, R_n=r_n]\n        &= \\Prob[R_1=r_1] \\cdot \\Prob[R_2=r_2|R_1=r_1] \\cdots \\\\\n        &\\cdot \\Prob[R_n=r_n|R_1=r_1,R_2=r_2,\\ldots,R_{n-1}=r_{n-1}]\n  \\end{align*}\n  If independence (see Section~\\ref{sec:bp-indep}) of the random variables is given, it holds that\n  \\[ \\Prob[R_i=r_i|R_1=r_1,\\ldots,R_{i-1}=r_{i-1}] = \\Prob[R_i=r_i] \\qquad \\forall i=1,\\ldots,n \\]\n  \\[ \\Rightarrow \\Prob[R_1=r_1, \\ldots, R_n=r_n] = \\prod_{i=1}^n \\Prob[R_i=r_i] \\]\n\\end{definition}\n\\begin{example}\n  In our coin tossing example, we have that:\n  \\[ \\Prob[R=1, S=0] = \\Prob[\\set{(h, t), (h, h)}] \\cdot \\Prob[\\set{(t, t), (h, t)}] = \\frac24 \\cdot \\frac24 = \\frac14 \\]\n  In the marginalization example, we used the same query and used a different approach to get the same result.\n\\end{example}\n\n\\subsection{Independence}\n\\label{sec:bp-indep}\n%\n\\index{Independence}\n\\index{Mutual independence}\n\\index{Conditional independence}\n\\begin{definition}\n  We assume $\\Omega$ is a finite set and consider\n  the probability space $(\\Omega, \\mathcal A, \\Prob)$.\n  Two $\\mathbb Z$-valued random variables $R$ and $S$ are called \\emph{(mutually) independent} if\n  \\[ \\Prob[R=r, S=s] = \\Prob[R=r] \\cdot \\Prob[S=s] \\]\n  for any $r, s \\in {\\mathbb Z}$ (see, e.g.,~\\cite[p.~27]{ito},~\\cite[p.~143]{grindstead}).\n\\end{definition}\n\nLet $A$ be an element of the $\\sigma$-algebra ${\\mathcal A}$.\nWe denote by $1_A$ the indicator function of $A$ defined as\n\\[\n  1_A(a) = \\begin{cases}\n    1 & \\text{ if } a \\in A \\\\\n    0 & \\text{ if } a \\not\\in A\n  \\end{cases}\n\\]\nThe indicator function $1_A$ defines a ${\\mathbb Z}$-valued random variable.\nLet $A$ and $B$ be elements of the $\\sigma$-algebra ${\\mathcal A}$.\nThe sets (events) $A$ and $B$ are called independent\nwhen the random variables $1_A$ and $1_B$ are independent.\n\nIt is important to distinguish between \\emph{mutual independence} and \\emph{pairwise independence}.\nPairwise independence of events is a weaker condition.\n\n\\begin{example}\n  Consider our previous coin tossing example (Example~\\ref{ex:cointoss}).\n  Let us denote coin tosses $ij$, where $i$ and $j$ are the results of the first and second coin toss respectively.\n  Define the random variable $R$ as\n  \\[ R(00)=0, \\quad R(01)=0, \\quad R(10)=1, \\quad R(11)=1 \\]\n  and define the random variable $S$ (intuitively the result of the second toss) as\n  \\[ S(00)=0, \\quad S(01)=1, \\quad S(10)=0, \\quad S(11)=1 \\]\n  Then we have\n  \\[\n    \\Prob[R=0, S=0] = \n    \\Prob[R=0, S=1] = \n    \\Prob[R=1, S=0] = \n    \\Prob[R=1, S=1] = 1/4\n  \\]\n  Since $\\Prob[R=i] = \\frac12$ and $\\Prob[S=j] = \\frac12$,\n  we can see $\\Prob[R=i, S=j] = \\Prob[R=i] \\cdot \\Prob[S=j]$.\n  Therefore $R$ and $S$ are independent random variables.\n  The elements of $\\sigma$-algebra\n  $A = \\set{01, 11} = R^{-1}(1)$ and $B = \\set{10, 11} = S^{-1}(1)$\n  are independent.\n  Intuitively speaking, the event getting $1$ at the first toss\n  and the event getting $1$ at the second toss\n  are independent.\n\\end{example}\n\n\\subsection{Expected value of independent random variables}\n\\label{sec:bp-ev-indep}\n%\nLet $R$ and $S$ be two random variables. We prove $\\E[R \\cdot S] = \\E[R] \\cdot \\E[S]$\nfor the discrete and continuous case:\n%\n\\begin{align*}\n  \\E[R \\cdot S] &= \\int_{-\\infty}^{\\infty} \\Prob[R=x] \\cdot \\Prob[S=y] \\cdot R(x) \\cdot S(y) \\, dx \\, dy \\\\\n                &= \\left(\\int_{-\\infty}^{\\infty} \\Prob[R=x] \\cdot R(x) \\, dx\\right) \\left(\\int_{-\\infty}^{\\infty} \\Prob[S=y] \\cdot S(y) \\, dy\\right) \\\\\n                &= \\E[R] \\cdot \\E[S] \\\\\n  \\E[R \\cdot S] &= \\sum_{a \\in \\mathcal A_R} \\sum_{b \\in \\mathcal A_S} \\left(\\Prob[R=a] \\cdot \\Prob[S=b] \\cdot R(a) \\cdot S(b)\\right) \\\\\n                &= \\left(\\sum_{a \\in \\mathcal A_R} \\Prob[R=a] \\cdot R(a)\\right) \\cdot \\left(\\sum_{b \\in \\mathcal A_S} \\Prob[S=b] \\cdot S(b)\\right) \\\\\n                &= \\E[R] \\cdot \\E[S]\n\\end{align*}\n\n\\subsection{Conditional independence}\n\\label{sec:bp-cond-indep}\n%\nLet $R$, $S$, and $T$ be $\\mathbb Z$-valued random variables.\nThe random variables $R$ and $S$ are conditionally independent under the given random variable $T$\nif\n\\[\n  \\ProbCond{R=r, S=s}{T=t} =\n  \\ProbCond{R=r}{T=t} \\cdot \\ProbCond{S=s}{T=t}\n\\]\nfor any $r, s, t \\in \\mathbb Z$ (see, e.g.,~\\cite[3.1]{dawid}).\nLet\n\\[\n  A_r = R^{-1}(r) \\subseteq \\Omega \\qquad\n  B_s = S^{-1}(s) \\subseteq \\Omega \\qquad\n  C_t = T^{-1}(t) \\subseteq \\Omega\n\\]\nThen we can consider $\\Prob[A_r]$, $\\Prob[B_s]$, and $\\Prob[C_t]$ as probability distribution functions associated to $R$, $S$, and $T$ respectively.\nWe note that we have\n\\begin{align*}\n  \\ProbCond{R=r, S=s}{T=t} &= \\frac{\\Prob[A_r \\cap B_s \\cap C_t]}{\\Prob[C_t]} \\\\\n  \\ProbCond{R=r}{T=t} &= \\frac{\\Prob[A_r \\cap C_t]}{\\Prob[C_t]} \\\\\n  \\ProbCond{S=r}{T=t} &= \\frac{\\Prob[B_r \\cap C_t]}{\\Prob[C_t]}\n\\end{align*}\nby the definition of the conditional probability.\n\n\\subsection{Bayes' Theorem}\n\\label{sec:bp-bayes}\n%\n\\begin{theorem}[Bayes' Theorem]\n  Let $A$ and $B$ be two events. Let $\\Prob[B] \\neq 0$. Then:\n  \\[ \\Prob[A|B] = \\frac{\\Prob[B|A] \\cdot \\Prob[A]}{\\Prob[B]} \\]\n\\end{theorem}\n\\begin{proof}\n  Due to the chain of probability, the following statement holds:\n  \\[ \\Prob[A,B] = \\Prob[B|A] \\cdot \\Prob[A] = \\Prob[A|B] \\cdot \\Prob[B] \\]\n  Bayes' theorem follows immediately:\n  \\[ \\frac{\\Prob[B|A] \\cdot \\Prob[A]}{\\Prob[B]} = \\Prob[A|B] \\]\n\\end{proof}\n\nBayes' Theorem is fundamental to theory we will cover in the following.\n$\\Prob[A]$ is called \\emph{prior probability} and $\\Prob[A|B]$ is called \\emph{posterior probability} in the Bayesian interpretation.\nThe names derive from the fact, that $\\Prob[A]$ is known beforehand in most applications and $\\Prob[A|B]$ is the degree of belief in $A$ after $B$ happened.\n\n\\section{Probability distributions}\n\\label{sec:bp-dist}\n%\nProbability distributions are templates for probability density functions\nsatisfying the criteria mentioned in Section~\\ref{sec:bp-continuous}.\nThey are parameterized by one or more variables.\nBesides the continuous distributions presented here, discrete distributions also exist.\n\n\\subsection{Normal distribution}\n\\label{sec:bp-norm-dist}\n%\n\\index{Normal distribution}\n\\index{Gaussian distribution}\n\\index{Bell curve}\nThe \\emph{Normal distribution} (also \\emph{Gaussian distribution} or informally \\emph{Bell curve}) is a continuous\nprobability distribution parameterized by $\\mu$ (the mean of the distribution) and $\\sigma^2$ (variance).\n\\[ f(x \\,|\\, \\mu, \\sigma^2) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{(x - \\mu)^2}{2 \\sigma^2}} \\]\nThe distribution is visualized with 4 configurations in Figure~\\ref{fig:norm-dist}.\n\n\\begin{figure}[p]\n  \\begin{center}\n    \\includegraphics[width=0.7\\textwidth]{img/normal_distribution.pdf}\n    \\caption{\n      Four different normal distributions with $\\mu=0$ and $\\sigma^2 = 0.2$ [blue],\n      $0.5$ [red], $1.0$ [green], and $5.0$ [yellow]\n    }\n    \\label{fig:norm-dist}\n  \\end{center}\n\\end{figure}\n\n\\subsection{Beta distribution}\n\\label{sec:beta-dist}\n%\n\\index{Beta distribution}\nThe \\emph{Beta distribution} is parameterized by $a$ and $b > 0$.\n\\[ f(x \\,|\\, a, b) = \\frac{1}{B(a, b)} x^{a - 1} (1 - x)^{b-1} \\]\nwhere $B(a, b) = \\int_0^1 x^{a-1} (1 - x)^{b-1} \\, dx$, the so-called beta function.\nThe distribution is visualized with 4 configurations in Figure~\\ref{fig:beta-dist}.\n\n\\begin{figure}[p]\n  \\begin{center}\n    \\includegraphics[width=0.7\\textwidth]{img/beta_distribution.pdf}\n    \\caption{\n      Four different beta distributions:\n      $(a=0.5, b=1.5)$ [blue], $(1, 2)$ [red], $(2.5, 4)$ [green], and $(5, 5)$ [yellow]\n    }\n    \\label{fig:beta-dist}\n  \\end{center}\n\\end{figure}\n\n\\subsection{Independent and identically distributed}\n\\label{sec:bp-iid}\n%\nLet $R_i$ be a set of $n$ random variables. $R_i$ are called \\emph{independent and\nidentically distributed} (i.i.d.) if they are mutually independent and each\nvariable follows the same probability distribution.\n\n\\begin{example}\n  Three board game players possess two fair dice each.\n  Every player is asked to throw them and tell the sum of these two thrown dice.\n\n  All three die sums share the same distribution.\n  Sum $2$ is thrown with a chance of $\\frac{1}{36}$.\n  Sum $7$ is thrown with a chance of $\\frac{6}{36}$ (etc.).\n  The result of one player does not influence the result of the other player.\n  They are mutually independent.\n\\end{example}\n\n\\section{Graphical models}\n\\label{sec:gm}\n%\n\\index{Bayesian network}\n\\index{Graphical model}\nIn order to specify a probabilistic model, you have to provide the following definitions:\n\\begin{itemize}\n  \\item A set of random variables and their co-domain ($E$ is either $\\mathbb Z$ or $\\mathbb R$)\n  \\item The random variables' dependencies (according to Section~\\ref{sec:bp-indep})\n  \\item You can assign probabilities (conditional probabilities or unconditioned probabilities)\n\\end{itemize}\n%\nA graphical model explicitly defines the dependencies using a graph.\nParticularly, we looked at \\emph{Bayesian networks}, which use a directed acyclic graph (DAG).\n\nGiven a Bayesian network, we can make queries (ask for determination of a probability).\nUsing all the rules about probability theory we learned before, we can derive new knowledge\nand might be able to answer the query.\n\nGraphical models furthermore employ two interesting properties.\n\n\\subsection{Joint probability of the network}\n\\label{sec:gm-joint-prob}\n%\nThe joint probability of the Bayesian network with random variables $R_1, R_2, \\ldots, R_n$ is given with\n\\[ \\Prob[R_1, \\ldots, R_n] = \\prod_{i=1}^n \\ProbCond{R_i}{\\operatorname{ParentNodes}(R_i)} \\]\nwhere $\\operatorname{ParentNodes}(R_i)$ denotes all the nodes $R_i$ depends on.\nThis property can be helpful to answer queries.\n\n\\subsection[d-separation]{$d$-separation}\n\\label{sec:gm-d-separation}\n%\n\n\n\\subsection{Tool: Bayesian inference}\n\n\n\n\\TODO{Show symmetry, decomposition, weak union and contraction, via Dawid et al.}\n\n\\section{Example: Polynomial curve fitting problem}\n\\label{sec:bp-curve-fitting}\n%\n\\subsection{The problem}\n%\n\\TODO{visualization}\n\nIn the following, we introduce the curve fitting problem similar to Bishop~\\cite[p.~4~ff.]{Bishop}.\nThe problem is defined as follows:\n\n\\begin{problem}[Polynomial curve fitting problem]\n  Consider a polynomial of arbitrary degree.\n\n  \\begin{description}\n  \\item{Given}\n  $x = (x_1, \\ldots, x_n)^N$ as a vector of $N$ x-values and\n  $t = (t_1, \\ldots, t_n)^N$ as the corresponding y-values drawn from the polynomial.\n  Furthermore let $E(w)$ be an error function for given polynomial coefficients $w$.\n\n  \\item{Find}\n  a polynomial with coefficients $w$ which approximates values $t$ minimizing $E(w)$.\n  \\end{description}\n\\end{problem}\n\nThe degree of the polynomial is purposely unknown.\n\\emph{Model selection} is a branch of Machine Learning dedicated to finding appropriate models for given problems.\nSo for polynomial degree choice for our curve fitting problem, we refer to research literature in Model Selection. \\TODO{provide useful references for Curve Fitting}\n\\index{Error function}\nAn \\emph{error function} in this context is any function using $w$, $x$ and $t$ to determine a numeric value representing how much $w$ deviates from $t$ at $x$.\nPopular error functions include\n\\begin{align}\n  E(w) &= \\frac12 \\sum_{n=1}^N \\left(y(x_n, w) - t_n\\right)^2 \\tag{Mean squared error, MSE} \\\\\n  E(w) &= \\sqrt{\\frac{1}{N} \\sum_{n=1}^N (y(x_n, w) - t_n)^2} \\tag{Root mean square, RMS} \\\\\n  E(w) &= \\frac1N \\sum_{n=1}^N (y(x_n, w) - t_n)              \\tag{Mean signed deviation, MSD}\n\\end{align}\n% TODO: error function does not need to be derivable, right? But in our design, we derive it to find the gradient to minimize it. So probably it is not required because of backpropagation, but by gradient descent.\n\n\\begin{figure}[!h]\n  \\begin{center}\n    \\begin{subfigure}[b]{0.45\\textwidth}\n      \\includegraphics[width=\\textwidth]{img/interpolation-linear.pdf}\n      \\caption{Linear interpolation}\n      \\label{fig:linear-interpolation}\n    \\end{subfigure}%\n    \\begin{subfigure}[b]{0.45\\textwidth}\n      \\includegraphics[width=\\textwidth]{img/interpolation-nonlinear.pdf}\n      \\caption{Nonlinear interpolation}\n      \\label{fig:nonlinear-interpolation}\n    \\end{subfigure}\n    \\caption{\n      In Figure~\\ref{fig:linear-interpolation}, y-values $t_1$ and $t_2$ can be interpolated\n      easily using a linear approach. But with more $y$-values (3, in the case of Figure~\\ref{fig:nonlinear-interpolation}),\n      the problem often requires non-linear solutions.\n    }\n    \\label{fig:interpolation}\n  \\end{center}\n\\end{figure}\n\n\\subsection{Overfitting}\n\\label{sec:bp-overfitting}\n%\n\\index{Training data}\n\\index{Validation data}\n\\index{Test data}\n\\index{Overfitting}\nMachine Learning distinguishes between a \\emph{training} and \\emph{validation} dataset as input.\nIt uses the training set to learn which output is desired for some given input.\nTherefore all elements of the training set are labelled such that the error in the output can be quantified.\n\\emph{Overfitting} describes the situation, when the learning algorithm approximates the output with little error,\nbut input from the validation set (which contains different inputs) is computed with high error.\nSo the algorithm perfectly adapted itself to recognize the training data, but performs badly for any other input.\n\n\\TODO{visualization}\n\n\\subsection{Regularization as countermeasure}\n\nIn order to restrict the neural network from overfitting, you penalize it for using\nlarge weights.\n\n\\[ E(w) = \\frac12 \\sum_{n=1}^N (y(x_n, w) - t_n)^2 + \\frac{\\lambda}{2} \\abs{w}^2 \\]\n\nHere, the term $\\frac{\\lambda}{2} \\abs{w}^2$ was added where $\\abs{w}^2$ denotes the\nmatrix multiplication\n\\[ \\abs{w}^2 = w^T \\cdot w = w_0^2 + w_1^2 + \\ldots + w_M^2 \\]\n\n% introduce gaussian distribution to every data point\n\nWe now model the problem from a probabilistic view:\n\n\\subsection{Maximum Likelihood Estimator}\n%\n% In particular, explain a theoretical reason of adding the term $|w|^2$ for\n% the MLE problem in terms of the Baysian theorem.\n%\n% The Bayesian prior is exponentially to |w|^2. This is a common criticism of the application\n% of MLE to Bayesian theory. There is always the prior as assumption, which in this case has computational implications.\n% Computational experiments are required to verify the use.\n%\nThe Maximum Likelihood Estimator (MLE) is a technique to estimate the parameters of a probability distribution.\nIt maximizes the likelihood that the given data actually occurs.\n\n\\TODO{Illustrate that the Curve Fitting problem is considered Bayesian here}\n\n\\begin{theorem}\n  Consider input data $x$, mean $\\mu$ and variance $\\sigma^2$:\n  \\[ \\ln{\\Prob[x | \\mu, \\sigma^2]} = -\\frac1{2\\sigma^2} \\sum_{n=1}^N (x_n - \\mu)^2 - \\frac{N}{2} \\ln{\\sigma^2} - \\frac{N}{2} \\ln(2\\pi) \\]\n  Then\n  $\\mu_{\\text{ML}} = \\frac{1}{N} \\cdot \\sum_{n=1}^N x_n$ for maximized $\\mu$ and \\\\\n    $\\sigma_{\\text{ML}} = \\frac{1}{N}\\cdot \\sum_{n=1}^N (x_n - \\mu_{\\text{ML}})^2$ for maximized $\\sigma^2$\n\\end{theorem}\n\nSo we want to determine the 2 parameters of a Gaussian distribution, namely $\\mu$ and $\\sigma^2$, in the maximum likelihood case.\nWe begin with $\\mu$:\n\n\\begin{proof}\n\\begin{enumerate}\n  \\item Derive $\\ln{\\Prob[x| \\mu, \\sigma^2]}$ for $\\mu$\n    \\begin{align*}\n      \\frac\\partial{\\partial \\mu} \\ln{\\Prob[x | \\mu, \\sigma^2]}\n      &= \\frac\\partial{\\partial \\mu} \\left(-\\frac{1}{2\\sigma^2} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 - \\frac{N}{2} \\ln{\\sigma^2} - \\frac{N}{2} \\ln(2\\pi)\\right) \\\\\n      &= \\frac\\partial{\\partial \\mu} \\left(-\\frac{1}{2\\sigma^2} \\cdot \\sum_{n=1}^N (x_n^2 - 2 x_n \\mu + \\mu^2) - \\frac{N}{2} \\ln{\\sigma^2} - \\frac{N}{2} \\ln(2\\pi)\\right) \\\\\n      &= -\\frac{1}{2\\sigma^2} \\cdot \\sum_{n=1}^N (-2x_n + 2\\mu) \\\\\n      &= -\\frac1{\\sigma^2} \\cdot \\sum_{n=1}^N (\\mu - x_n)\n    \\end{align*}\n  \\item Set result zero\n    \\[ 0 = -\\frac{1}{\\sigma^2} \\cdot \\sum_{n=1}^N (\\mu - x_n) = \\sum_{n=1}^N (\\mu - x_n) = N \\cdot \\mu - \\sum_{n=1}^N x_n \\]\n    \\[ \\implies \\mu_{\\text{ML}} = \\frac1N \\cdot \\sum_{n=1}^N x_n \\qquad \\text{commonly called \\enquote{sample mean}} \\]\n\\end{enumerate}\n\\end{proof}\n\nWe continue with $\\sigma^2$ and use the same approach:\n\n\\begin{proof}\n  \\begin{enumerate}\n  \\item Derive $\\ln{\\Prob[x | \\mu, \\sigma^2]}$ for $\\sigma^2$\n    \\begin{align*}\n      \\frac{\\partial}{\\partial \\sigma^2} \\ln{\\Prob[x | \\mu, \\sigma^2]}\n      &= \\frac{\\partial}{\\partial \\sigma^2} \\left(-\\frac{1}{2\\sigma^2} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 - \\frac{N}2 \\ln{\\sigma^2} - \\frac{N}2 \\ln(2\\pi)\\right) \\\\\n      &= \\frac{1}{2\\sigma^4} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 - \\frac{N}{2} \\cdot \\frac{1}{\\sigma^2} \\\\\n      &= \\frac{1}{2\\sigma^2} \\left(\\frac{1}{\\sigma^2} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 - N\\right)\n    \\end{align*}\n  \\item Set result zero\n    \\begin{align*}\n      0 &= \\frac{1}{2\\sigma^2} \\left(\\frac{1}{\\sigma^2} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 - N\\right) \\\\\n      N \\cdot \\sigma^2 &= \\sum_{n=1}^N (x_n - \\mu)^2 \\\\\n      \\sigma^2_{\\text{ML}} &= \\frac{1}{N} \\cdot \\sum_{n=1}^N (x_n - \\mu)^2 \\qquad \\text{commonly called \\enquote{sample variance}}\n    \\end{align*}\n  \\end{enumerate}\n\\end{proof}\n\nAnd now we derive the precision parameter $\\beta$ in the maximum likelihood case:\n\n\\begin{theorem}\n  Given\n  \\[ \\ln{\\Prob[t | x, w, \\beta]} = -\\frac{\\beta}{2} \\cdot \\sum_{n-1}^N \\left(y(x_n,w) - t_n\\right)^2 + \\frac{N}2 \\ln{\\beta} - \\frac{N}{2} \\ln(2\\pi) \\]\n  then find\n  \\[ \\frac{1}{\\beta_{\\text{ML}}} = \\frac{1}{N} \\cdot \\sum_{n=1}^N (y(x_n, w_{\\text{ML}}) - t_n)^2 \\] by maximizing $\\beta$\n\\end{theorem}\n\n\\begin{proof}\n\\begin{enumerate}\n  \\item Derive $\\ln{\\Prob[t | x,w,\\beta]}$ with $\\beta$\n    \\begin{align*}\n      \\frac{\\partial}{\\partial \\beta} \\ln{\\Prob[t | x,w,\\beta]}\n      &= \\frac{\\partial}{\\partial \\beta} \\left(-\\frac{\\beta}{2} \\sum_{n=1}^N (y(x_n,w) - t_n)^2 + \\frac{N}{2} \\ln\\beta - \\frac{N}{2} \\ln(2\\pi)\\right) \\\\\n      &= -\\frac12 \\cdot \\sum_{n=1}^N \\left(y(x_n,w) - t_n\\right)^2 + \\frac{N}{2} \\cdot \\frac1\\beta\n    \\end{align*}\n  \\item Set result zero\n    \\begin{align*}\n      0 &= -\\frac{1}{2} \\cdot \\sum_{n=1}^N \\left(y(x_n,w) - t_n\\right)^2 + \\frac{N}{2\\beta} \\\\\n      \\frac{N}{\\beta} &= \\sum_{n=1}^N \\left(y(x_n,w) - t_n\\right)^2 \\\\\n      \\frac{1}{\\beta_{\\text{ML}}} &= \\frac{1}{N} \\cdot \\sum_{n=1}^N (y(x_n,w) - t_n)^2\n    \\end{align*}\n\\end{enumerate}\n\\end{proof}\n\n\n\n\n\n\n\nThe maximum of the logarithm of an expression corresponds to the minimum of the negative logarithm of the same expression. \\TODO{so why do we minimize and not maximize?}\n\n\\begin{align}\n  -\\log{\\Prob[\\omega|x,t,\\alpha,\\beta]}\n    &\\propto -\\log\\left[\\Prob[t|x,\\omega,\\beta] \\cdot \\Prob[\\omega|\\alpha]\\right] \\\\\n\\intertext{due to proportionality, $\\exists c \\in \\mathbb R$ such that} \\\\\n    &= -\\log{\\Prob[t|x,\\omega,\\beta]} - \\log\\Prob[\\omega|\\alpha] - \\log{c} \\\\\n\\intertext{insert formula Bishop 1.62} \\\\\n    &= \\frac\\beta2 \\sum_{n=1}^N \\left(y(x_n,\\omega)-t_n\\right)^2 - \\frac{N}{2} \\ln\\beta + \\frac{N}{2} \\ln{2\\pi} - \\log\\left(\\left(\\frac{\\alpha}{2\\pi}\\right)^{\\frac{M+1}{2}} \\cdot \\exp\\left(-\\frac{\\alpha}{2} \\omega^\\transpose \\omega\\right)\\right) - \\log{c} \\\\\n    &= \\frac\\beta2 \\sum_{n=1}^N \\left(y(x_n,\\omega)-t_n\\right)^2 - \\frac{N}{2} \\ln\\beta + \\frac{N}{2} \\ln{2\\pi} - \\frac{M+1}{2} \\log\\alpha + \\frac{M+1}{2} \\log{2\\pi} + \\frac{\\alpha}{2} \\omega^\\transpose \\omega - \\log{c}\n\\end{align}\n\nLet $f$ be any function with a minimum. Then $\\argmin_{\\omega} f(\\omega) = \\argmin_{\\omega} c \\cdot f(\\omega) + a$ for any $c, a \\in \\mathbb R$.\nThis applies also to our case:\n\n\\begin{align}\n  \\argmin_{\\omega} -\\log{\\Prob[\\omega|x,t,\\alpha,\\beta]}\n    &= \\argmin_{\\omega} \\left(\\frac\\beta2 \\cdot \\sum_{n=1}^N \\left(y(x_n, \\omega) - t_n\\right)^2 + \\frac\\alpha2 \\omega^\\transpose \\omega\\right) \\\\\n    &= \\argmin_{\\omega} \\beta\\left(\\frac12 \\sum_{n=1}^N \\left(y(x_n, \\omega) - t_n\\right)^2 + \\frac{\\frac\\alpha\\beta}{2} \\omega^\\transpose \\omega^\\transpose\\right) \\\\\n    &= \\argmin_{\\omega} \\frac12 \\sum_{n=1}^N \\left(y(x_n, \\omega) - t_n\\right)^2 + \\frac{\\frac\\alpha\\beta}{2} \\omega^\\transpose \\omega^\\transpose \\\\\n\\end{align}\n\nHence, the coefficients maximizing the probability that the coefficients correspond to our model parameters ($x, t, \\alpha, \\beta$) are given in the last line.\nConsidering we determine the best coefficients by minimizing the error function, it is justified to consider these coefficients as optimum. Let $\\lambda = \\frac{\\alpha}{\\beta}$, then \\dots\n\n\\[ \\tilde{E}(\\omega) = \\frac12 \\sum_{n=1}^N \\left(y(x_n, \\omega) - t_n^2\\right)^2 + \\frac{\\lambda}{2} \\|\\omega\\|^2 \\]\n\n", "meta": {"hexsha": "10850e11736d4e78b25263dd898a4262bf0919a2", "size": 48431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/bayesian.tex", "max_stars_repo_name": "prokls/bakk_kobe", "max_stars_repo_head_hexsha": "795061ae69a5130d0d553bcaa0cdf2af9e9c9d30", "max_stars_repo_licenses": ["MIT"], "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/bayesian.tex", "max_issues_repo_name": "prokls/bakk_kobe", "max_issues_repo_head_hexsha": "795061ae69a5130d0d553bcaa0cdf2af9e9c9d30", "max_issues_repo_licenses": ["MIT"], "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/bayesian.tex", "max_forks_repo_name": "prokls/bakk_kobe", "max_forks_repo_head_hexsha": "795061ae69a5130d0d553bcaa0cdf2af9e9c9d30", "max_forks_repo_licenses": ["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.5767301906, "max_line_length": 258, "alphanum_fraction": 0.6385785964, "num_tokens": 17379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480248488136, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7946912271712973}}
{"text": "\n\\subsection{Lagrange's theorem}\n\nLagrange's theorem states that for any finite group \\(G\\), the order of every subgroup is a divisor of the order of \\(G\\).\n\nConsider subset \\(H\\). We know that all cosets are disjoint, and that the union of all cosets is \\(G\\).\n\nAs cosets are the same size, we know that:\n\n\\(|G|=m|H|\\), where \\(m\\) is the number of cosets.\n\nThis means that if a group has order \\(10\\), a subgroup must have order \\(1\\), \\(2\\) \\(5\\) or \\(10\\).\n\n", "meta": {"hexsha": "978c0fcad49616133e51840fc1a41f926aac91ef", "size": 462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/06-02-lagrange.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/06-02-lagrange.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/06-02-lagrange.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": 122, "alphanum_fraction": 0.670995671, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.8652240825770432, "lm_q1q2_score": 0.7946912226405427}}
{"text": "\n\\subsection{Big \\(O\\) and little-\\(o\\) notation}\n\n\\subsubsection{Big \\(O\\) notation}\n\nIn big \\(O\\) notation we are interested in t he size of a function as it getes larger. We ignore constant multiples.\n\n\\(cx\\in O(x)\\)\n\nAnd addition of constants.\n\n\\(cx+b\\in O(x)\\)\n\nIf there are two terms and one is larger, we keep the largest.\n\n\\(x+x^2\\in O(x^2)\\)\n\nMore generally we write:\n\n\\(f(x)\\in O(g(x))\\)\n\n\\subsubsection{Little-\\(o\\) notation}\n\n\n", "meta": {"hexsha": "fde4becce44eec5d7a087a0db8dce3301c337b6f", "size": 439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctions/02-01-analysisBigO.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/propertiesFunctions/02-01-analysisBigO.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/propertiesFunctions/02-01-analysisBigO.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.56, "max_line_length": 116, "alphanum_fraction": 0.6651480638, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7946573384866754}}
{"text": "\n\\section*{Problem 1: Background Material [20pts] (Devendra \\& Hyun-Ah)}\n\n\\subsection*{1.1 Probability review (Devendra)}\n\nConsider a naive classifier which stochastically assigns labels to data points; specifically, for each label $l$, it assigns that label with probability proportional to the number of times that label appears in the training dataset. Let the size of training set be $N$, total number of classes be $C$ and $n_i$ be number of datapoints of class $i$ ($\\sum_i^C{n_i} = N$), then the probability of labelling a datapoint with class $i$ is $n_i/N$.\n\n1) Consider a training set with $N=100$, $C=2$, $n_1 = 50$, $n_2=50$ and a test set with, $N=100$, $C= 2$, $n_1 = 30$, $n_2 = 70$.\\\\\na) What is the expected accuracy of the classifier on the training set?\\\\\nb) What is the expected accuracy of the classifier on the test set?\\\\\n\n2) Now consider a training set with $N=100$, $C=3$, $n_1 = 50$, $n_2=20$, $n_3=30$ and a test set with, $N=100$, $C= 3$, $n_1 = 20$, $n_2 = 20$, $n_3 = 60$.\\\\\na) What is the expected accuracy of the classifier on the training set?\\\\\nb) What is the expected accuracy of the classifier on the test set?\\\\\n\nThis kind of analysis can be used to calculate a baseline accuracy for various Machine Learning algorithms. \n\n\\subsection* {Problem 1.2: Bayes Rule [10 pts] (Hyun-Ah) }\n\nSmith owns a retail store for selling phones. The phones are manufactured at three different factories: $A, B, C$. Factory A, B, and C produces $20\\%, 30\\%,$ and $50\\%$ of the phone being sold at Smith's store. The probabilities of the defective phones from stores $A, B,$ and $C$ are $2\\%, 1\\%,$ and $0.05\\%$, respectively. The total number of phones being sold at Smith's store is $10000$. \nOne day, a customer walks up to Smith's store, and ask for a refund for a defective phone.\n\na) What is the probability of a phone being defective?\n\nb) What is the probability that this defective phone is manufactured at factory $A$?\n\nc) What is the probability that this defective phone is manufactured at factory $B$?\n\nd) What is the probability that this defective phone is manufactured at factory $C$?\n\n\\newpage", "meta": {"hexsha": "21178f6949c2d17f176c876437b98f253248f669", "size": 2127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem1.tex", "max_stars_repo_name": "DylanFrank/Learn", "max_stars_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-24T09:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T12:55:26.000Z", "max_issues_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem1.tex", "max_issues_repo_name": "DylanFrank/Learn", "max_issues_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "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": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem1.tex", "max_forks_repo_name": "DylanFrank/Learn", "max_forks_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-10T02:18:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T07:45:23.000Z", "avg_line_length": 68.6129032258, "max_line_length": 443, "alphanum_fraction": 0.7202632816, "num_tokens": 611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7946525861959346}}
{"text": "\\chapter{True Statements in Propositional Logic}\n\\label{chapter:propositional-truth}\n\\marginurl{%\n  Proofs Using Truth Tables:\\\\\\noindent\n  Introduction to Mathematical Logic \\#2\n}{youtu.be/DOAxnmScpPc}\n\n\nTypical theorem in mathematics have the following template:\n``if some statements are true, then another statement is also true''.\nIn propositional logic statements are described using propositional formulas.\nSo our goal is to present a way to describe proofs of results that looks like:\nif $\\phi_1$, \\dots, $\\phi_k$ are true, then $\\psi$ is also true.\n\nThis section discusses the method which is based on truth tables (we discussed\nthem before in \\Cref{chapter:predicates}).\n\nWe start from an example similar to\nthe proof gaven in the beginning of the \\Cref{chapter:proofs}. Assume that we\nknow that if $x$ is a real number such that $x < -2$ or $x > 2$, then $x^2 > 4$.\nWe can derive that if $\\lnot (x^2 > 4)$, then $\\lnot (x < -2)$ and \n$\\lnot (x > 2)$.\n\nIn order to emphasize the logical structure of the argument let us denote the\nstatement $x > 2$ by $p$, the statement $x < -2$ by $q$, and the statement \n$x^2 > 4$ by $r$. In this case the argument is as follows:\nif $(p \\lor q) \\limplies r$ is true, then\n$\\lnot r \\limplies (\\lnot p \\land \\lnot q)$ is true as well.\n\nThe simplest way to explain why this argument is true is to use\na truth table.\n\\begin{center}\n  \\begin{tabular}{l l l l l}\n    \\toprule\n    $p$ & $q$ & $r$ & $(p \\lor q) \\limplies r$ &\n    $\\lnot r \\limplies (\\lnot p \\land \\lnot q)$ \\\\\n    \\midrule\n    T & T & T & T & T \\\\\n    T & T & F & F & F \\\\\n    T & F & T & T & T \\\\\n    T & F & F & F & F \\\\\n    F & T & T & T & T \\\\\n    F & T & F & F & F \\\\\n    F & F & T & T & T \\\\\n    F & F & F & T & T \\\\\n    \\bottomrule\n  \\end{tabular}\n\\end{center}\nNote that each line where $(p \\lor q) \\limplies r$ is true has\n$\\lnot r \\limplies (\\lnot p \\land \\lnot q)$ true as well. So we proved that\nthe argument is indeed correct.\n\nWe may also note that we showed that\n\\[\n  \\bigl((p \\lor q) \\limplies r\\bigr) \\iff\n  \\bigl(\\lnot r \\limplies (\\lnot p \\land \\lnot q) \\bigr)\n\\]\nis always true (we say that this propositional formula is a\n\\emph{tautology}). A generalization of this saying the if $p \\limplies q$ is\ntrue, then $\\lnot q \\limplies \\lnot p$ is also true is called the\n\\emph{contraposition} argument.\n\nLet us now consider another argument. If we know that Joe was a good boy and we\nknow that if Joe is a good boy, then Santa gives a present to Joe. We may\nconclude that Santa gives a present to Joe. We can similarly to the previous\nexample write this argument using variables and connectives.\nIf we know that $p$ and $p \\limplies q$, we may conclude that $q$ is true.\n\\begin{exercise}\n  Show that $(p \\land (p \\limplies q)) \\limplies q$ is a tautology.\n\\end{exercise}\nSuch an argument is called \\emph{modus ponens}.\n\nA notion connected to being a tautology is the notion of being satisfiable.\nWe say that a formula (a set of formulas) is \\emph{satisfiable} iff there\nis a substitution to the variables such that the value of the formula is true\n(the values of all the formulas are true). Note that a formula is not\nsatisfiable (the formula is \\emph{unsatisfiable}) iff its negation is\na tautology. Therefore, using truth tables one may check whether a formula\nis satisfiable or not.\\footnote{%\n  Note that the procedure is awfully not efficient since if the formula\n  uses $n$ variables we need to do $2^n$ operations. Unfortunately,\n  we do not know anything that always works better since\n  satisfiability problem (the problem of determining whether a given formula is\n  satisfiable or not) is NP complete.\n}\n\n\\section{Semantic Implication}\nAs we mentioned at the beginning of the chapter, most of the\nstatements in mathematics are in the form\n``if some statements are true, then some statement is also true'';\nthis type of statements can be described using the notion of semantic\nimplication. We say that a set $\\Sigma$ of propositional formulas with\nvariables from a set $V$ \\emph{semantically implies} a propositional formula\n$\\phi$ with variables from the set $V$ (we denote it by $\\Sigma \\models \\phi$)\niff whenever all the formulas from $\\Sigma$ are true under some propositional\nassignement to $V$, the formula $\\phi$ is also true under this propositional\nassignement; i.e.,\n$\\Sigma \\models \\phi$ iff for any $\\rho : V \\to \\set{\\ltrue, \\lfalse}$,\n$\\substitute{\\phi}{\\rho} = \\ltrue$ provided that\n$\\substitute{\\psi}{\\rho} = \\ltrue$ for all $\\psi \\in \\Sigma$.\n(Note that the set $\\Sigma$ may be infinite.)\n\nWe explained that if we have a finite set $\\Sigma$, then it is possible to check\nwhether a formula $\\phi$ is semantically implied by $\\Sigma$. Let us try to find\nout whether we can do the same for infinite sets $\\Sigma$.\n\nPartial answer to this question is given by the following theorem.\n\\begin{theorem}[compactness theorem]\n  A set $\\Sigma$ of propositional formulas is satisfiable iff every finite\n  subset is satisfiable.\n\\end{theorem}\n\\begin{proof}\n  We say that a set is \\emph{finitely satisfiable} if every finite subset\n  is satisfiable.\n\n  Let us enumerate all the propositional formulas $\\alpha_1$, $\\alpha_2$, \\dots.\n  We define a family of sets $\\Delta_1$, \\dots, $\\Delta_n$, \\dots\n  such that $\\Delta_1 = \\Sigma$ and\n  \\[\n    \\Delta_{n + 1} =\n    \\begin{cases}\n      \\Delta_n \\cup \\set{\\alpha_{n + 1}} & \\text{if }\n        \\Delta_n \\cup \\set{\\alpha_{n + 1}} \\text{is finitely satisfiable,} \\\\\n      \\Delta_n \\cup \\set{\\lnot \\alpha_{n + 1}} & \\text{otherwise.}\n    \\end{cases}\n  \\]\n  Note that all the $\\Delta_n$ are finitely satisfiable.\n\n  Let $\\Delta = \\cup_{n \\in \\N} \\Delta_n$. It is clear that $\\Delta$ is\n  finitely satisfiable and for any propositional formula $\\alpha$,\n  either $\\alpha$ or $\\lnot \\alpha$ belongs to $\\Delta$.\n\n  Let us consider a substitution $v_1$, \\dots, $v_n$, \\dots to the variables\n  $x_1$, \\dots, $x_n$, \\dots such that $v_i = \\ltrue$ iff the formula $x_i$\n  belongs to $\\Delta$. We may note that this substitution satisfies any\n  formula $\\phi \\in \\Delta$.\n\\end{proof}\n\nUsing this theorem, we can show that any implication of an infinite set is\nactually an implication of a finite subset of it.\n\\begin{corollary}\n  Let $\\Sigma$ be a set of propositional formulas over the variables\n  $x_1$, $x_2$, \\dots, $x_n$, \\dots, and $\\phi$ be a propositional formula\n  over the same set. If $\\Sigma \\models \\phi$, then there is a finite\n  $\\Sigma' \\subseteq \\Sigma$ such that $\\Sigma' \\models \\phi$.\n\\end{corollary}\n\\begin{proof}\n  Note that $\\Sigma \\not\\models \\phi$ iff $\\Sigma \\cup \\set{\\phi}$ is\n  satisfiable.\n\n  Let us now assume that for any finite $\\Sigma' \\subseteq \\Sigma$,\n  $\\Sigma' \\not\\models \\phi$. This implies that $\\Sigma' \\cup \\set{\\phi}$\n  is satisfiable for all finite $\\Sigma'$. Therefore, $\\Sigma \\cup \\set{\\phi}$\n  is satisfiable, which is a contradiction to the assumption that\n  $\\Sigma \\models \\phi$.\n\\end{proof}\n\nTherefore if we wish to check whether a formula $\\phi$ is semantically implied\nby $\\Sigma$, we just need to brute-force all the finite subsets of $\\Sigma$ and\ncheck whether they semantically imply $\\phi$. By the previous argument, if\n$\\phi$ is implied by $\\Sigma$, this procedure reports ``yes'' at some point,\nand in the opposite case it will work infinitely long.\n\n\\begin{chapterendexercises}\n  \\exercise Show that $((A \\land B) \\lor C) \\limplies (A \\lor C)$ is a\n    tautology.\n  \\exercise Show that $((A \\limplies B) \\land (\\lnot A \\limplies C)) \\limplies\n    (B \\lor C)$ is a tautology.\n  \\exercise Show that \n    $((W \\limplies X) \\land (Y \\limplies Z)) \\limplies \n      ((W \\lor Y) \\limplies (X \\lor Z))$\n     is a tautology.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "09cae04eea1d3d1f38b4c1717c1dbb981a39b195", "size": 7672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_7/chapter_31_true_statements.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_31_true_statements.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_31_true_statements.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": 44.091954023, "max_line_length": 80, "alphanum_fraction": 0.6987747654, "num_tokens": 2252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.9005297841157157, "lm_q1q2_score": 0.7946525788603557}}
{"text": "\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{./Figures/tiled_room.pdf}\n\\end{center}\n\nSuppose you have an oddly shaped room with square tiles, and you want to estimate its square footage. Let $n$ be the number of full tiles you count, and let $m$ stand for the number of broken tiles. Denote the area of a single tile -- which can be computed: it is the square of the side length -- by $A_0$. Then we have the lower and upper bounds\n\\[n \\cdot A_0 \\leq A \\leq (n+m) \\cdot A_0\\]\nfor the area $A$ of the room. Now, convince yourself that this estimate would be better (tighter), if the tiles were smaller\\footnote{Mark the areas $n \\cdot A_0$ and $(n+m) \\cdot A_0$ in the sketch above, and then think about what would happen if we had tiles of half the side length}!\n\nFinding areas under curves or volumes under surfaces is called \\emph{integration}. It is one of the most fundamental and important concepts of mathematics, and it has applications in every scientific discipline. The above approach of approximating areas with large numbers of simple pieces can be quite cumbersome. Fortunately, there is very powerful connection to differentiation, which allows to compute integrals in a more efficient way.\n\n\\begin{application}[Centre of mass]\nA large metal plate of uniform thickness and the shape in the sketch (let us call it $S$; the area under $f(x)=\\sqrt{x}$ for $x$ from $0$ to $9$) needs to be balanced on a single point.\n\\begin{center}\n\t\\includegraphics[width=0.6\\textwidth]{./Figures/centre_of_mass.pdf}\n\\end{center}\nThat is, the centre of mass of $S$ needs to be found.\n\nThis can be solved with integration: The $x$ and $y$ coordinates of the centre of mass of $S$ are\n\\begin{align*}\nx_c &= \\frac{\\iint_S x \\: \\d A}{\\iint_S 1 \\: \\d A} = 5.4, \\\\\ny_c &= \\frac{\\iint_S y \\: \\d A}{\\iint_S 1 \\: \\d A} = 1.125.\n\\end{align*}\nWe will learn how to compute those integrals in this chapter.\n\\end{application}\n\n\n\\section{Theory of Integration in One Dimension}\n\n\\begin{definition}[Definite Integral, Riemann Sum]\nLet $f(x)$ be continuous on $a \\le x \\le b$ and divide the interval\n$[a,b]$ into $n$ subintervals of equal width $\\Delta x = \\rfrac{(b-a)}{n}$. Let\n\\[ x_0 = a, \\:\\: x_1 = a + \\Delta x, \\:\\: x_2 = x_1 + \\Delta x = x_0 + 2 \\Delta x, \\:\\:\n\\dots, \\:\\: x_n = x_0 + n \\Delta x = b \\]\nbe the endpoints of these subintervals. \n\\begin{enumerate}[(i)]\n\\item\nThen the \\emph{definite integral} of $f$ from $a$ to $b$ is defined as\n\\begin{equation}\n\\label{eq:def_itgr}\n\\itgr{a}{b}{f(x)}{x} := \\lim_{n \\to \\infty} \\sum_{j=1}^{n} f(c_j) \\Delta x,\n\\end{equation}\nwhere $x_{j-1} \\le c_j \\le x_{j}$. Here $f(x)$ is called the \\emph{integrand}, $a$ the lower boundary, and $b$ the upper boundary.\n\\item\nThe sum appearing in the above definition is called a \\emph{Riemann sum} of $f$ over $[a,b]$. If the points $c_j$ are always chosen to be the right-hand end point of their subinterval, that is $c_j=x_j$, we obtain the right-hand Riemann sum\n\\[ \\sum_{j=1}^{n} f(x_j) \\Delta x. \\]\nUsing the left end points of the subintervals, $c_j=x_{j-1}$, gives the left-hand Riemann sum\n\\[ \\sum_{j=1}^{n} f(x_{j-1}) \\Delta x = \\sum_{j=0}^{n-1} f(x_{j}) \\Delta x. \\]\n\\end{enumerate}\t\n\\end{definition}\n\n\\begin{remark}\n\\label{rem:def_int}\n\\begin{enumerate}[(i)]\n\t\\item Equation~\\eqref{eq:def_itgr} introduces a new quantity -- the definite integral of $f$ over $[a,b]$ -- and \\emph{defines} (that is what the ``$:=$'' means) it to be equal to the limit for $n \\rightarrow \\infty$ of the Riemann sums on the right. Note that on the right-hand side of \\eqref{eq:def_itgr}, different choices could be made for the points $c_j$. One should therefore show now that all these possible different choices lead to the same limit. That is, one should show that $\\itgr{a}{b}{f(x)}{x}$ as defined above is \\emph{well-defined}! This will be given as an exercise at the end of this section.\n\t\\item The following figure illustrates the right-hand Riemann sum for $n=4$, \n\t\\[ \\sum_{j=1}^{4} f(x_j) \\Delta x, \\]\n\tof some function $f$.\n\t\\figbox{Right-hand Riemann sum of $f$ for $n=4$:}\n\tThe rectangles in this figure have areas ``height'' $\\cdot$ ``width'' \n\t$= f(x_j)\\cdot \\Delta x$, and they are added up to obtain the Riemann sum. For comparison, the left-hand Riemann sum is\n\t\\figbox{Left-hand Riemann sum of $f$ for $n=4$:}\n\tWe see that in both cases, the Riemann sums approximate the area under the curve $y=f(x)$, and as in the example of the oddly-shaped room in the introduction, those approximations will get better if we choose $n$ to be larger. We can therefore interpret their limit, i.e., $\\itgr{a}{b}{f(x)}{x}$, as the signed area under the curve $y=f(x)$:\n\t\\figbox{Definite integral of $f$ over the integral $[a,b]$:}\n\tHere, the word ``signed'' was added since areas below the $x$-axis contribute negatively to the definite integral.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\nConsider $f(x)=\t\\rfrac35 \\, x$, $a=0$, $b=5$. First, let us find the left-hand Riemann sum for $n=5$ of $f$. The partition of $[a,b]=[0,5]$ is\n\\begin{equation*}\n\\begin{split}\n\\Delta x &= \\frac{b-a}{n} = \\frac{5-0}{5} = 1,\\\\\nx_0 &= 0, \\: x_1 = 1, \\: x_2 = 2, \\: \\dots, x_5 = 5,\n\\end{split}\n\\end{equation*}\nand therefore\n\\begin{equation*}\n\\begin{split}\n\\itgr{0}{5}{\\frac{3}{5} \\, x}{x} & \\approx \\sum_{j=0}^4 f(x_j) \\Delta x \n= [f(0)+f(1)+f(2)+f(3)+f(4)] \\cdot 1 \\\\\n& = \\frac35 \\, [0+1+2+3+4] = 6.\n\\end{split}\n\\end{equation*}\nWe now generalise this computation to find the definite integral $f$ over the interval $[a,b]$.\nThe partition of the interval is\n\\begin{equation*}\n\\begin{split}\n\\Delta x &= \\frac{b-a}{n} = \\frac{5-0}{n} = \\frac{5}{n},\\\\\nx_0 &= 0, \\: x_1 = \\frac{5}{n}, \\: x_2 = 2\\frac{5}{n}, \\: \\dots, x_n = n\\frac{5}{n}=5,\n\\end{split}\n\\end{equation*}\nand therefore\n\\begin{equation*}\n\\begin{split}\n\\itgr{0}{5}{\\frac{3}{5} \\, x}{x} & = \\lim_{n \\to \\infty} \\sum_{j=0}^{n-1} f(x_j) \\Delta x \n= \\lim_{n \\to \\infty} \\frac{5}{n} \\sum_{j=0}^{n-1} \\frac{3}{5} x_j  \\\\\n& = \\lim_{n \\to \\infty} \\frac{5}{n} \\sum_{j=0}^{n-1} \\frac{3}{5} \\frac{5}{n} \\, j\n= \\lim_{n \\to \\infty} \\frac{15}{n^2} \\sum_{j=0}^{n-1} j \\\\\n& = \\lim_{n \\to \\infty} \\frac{15}{n^2} \\frac{(n-1)n}{2}\n= \\lim_{n \\to \\infty} \\frac{15}{2} \\frac{n-1}{n} = 7.5,\n\\end{split}\n\\end{equation*}\nNote that this result agrees with the area\n\\[ A = \\frac{3\\cdot5}{2}, \\]\nfound by noticing that the region under the curve $y=f(x)$ is a right-angled triangle.\n\\end{example}\n\n\\begin{properties}\n\\label{prop:di}\nLet $a,b,\\alpha\\in\\mathbb{R}$, $a<b$, and let $f(x),g(x)$ be continuous functions on $[a,b]$. Then:\n\\begin{equation*}\n\\begin{split}\n(1) \\qquad & \\itgr{a}{a}{f(x)}{x} = 0, \\\\\n(2) \\qquad & \\itgr{a}{b}{f(x)}{x} = -\\itgr{b}{a}{f(x)}{x}, \\\\\n(3) \\qquad & \\itgr{a}{b}{[f(x)+g(x)]}{x} = \\itgr{a}{b}{f(x)}{x} + \\itgr{a}{b}{g(x)}{x}, \\\\\n(4) \\qquad & \\itgr{a}{b}{\\alpha \\cdot f(x)}{x} = \\alpha \\cdot \\itgr{a}{b}{f(x)}{x}, \\\\\n(5) \\qquad & \\itgr{a}{b}{f(x)}{x} = \\itgr{a}{c}{f(x)}{x} + \\itgr{c}{b}{f(x)}{x}  \\\\\n(6) \\qquad & \\text{If~} f(x) \\ge 0 \\text{~on~} [a,b] \\text{,~then} \\itgr{a}{b}{f(x)}{x} \\ge 0.\n\\end{split}\n\\end{equation*}\nNow suppose that $f(x)$ is continuous on the interval $[-a,a]$, where $a>0$. Then we have\n\\begin{equation*}\n\\begin{split}\n(7) \\qquad & \\text{If $f(x)$ is even, i.e. $f(-x)=f(x)$, then} \n\t\\itgr{-a}{a}{f(x)}{x} = 2\\itgr{0}{a}{f(x)}{x}, \\\\\n(8) \\qquad & \\text{If $f(x)$ is odd, i.e. $f(-x)=-f(x)$, then} \\itgr{-a}{a}{f(x)}{x} = 0.\n\\end{split}\n\\end{equation*}\n\\end{properties}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item All those properties are proven starting from the definition~\\ref{eq:def_itgr} of the definite integral. (There is nothing else to start from, is there?) Only the proof of the last property is written out below.\n\t\\item Properties (3) and (4) state that integration is \\emph{linear}, and they can by proven by using the corresponding laws for sums and limits (e.g., pull the constant $\\alpha$ out of the sum and then out of the limit in definition~\\ref{eq:def_itgr}).\n\\end{enumerate}\t\n\\end{remark}\n\n\\begin{proof}\nFor the proof of (8), we consider an odd function and we use only even $n$ for the limit $n\\to\\infty$. Since all choices for the points $c_j$ lead to the same limit, we make a choice that suits our purpose well: let the $c_j$ be the midpoints of their subintervals. The Riemann sums are\n\\[ \\sum_{j=1}^n f(c_j) \\Delta x \n= \\Delta x \\cdot \\left[ f(c_1) + f(c_2) + \\dots f(c_{n-1}) + f(c_n) \\right], \\]\nand comparing to \n\\figbox{An odd function and its Riemann sum, using midpoints:}\nwe see that this Riemann sum is zero since $f(c_1)+f(c_n)=0$, $f(c_2)+f(c_{n-1})=0$, \\ldots This gives \n\\[ \\itgr{-a}{a}{f(x)}{x} = \\lim_{n \\to \\infty} 0 = 0.\\]\n\nNow, the above assertion that $f(c_{j})+f(c_{n-j+1})=0$ seems to be confirmed by the sketch, but we should prove it properly: After working out formulas for the partition points $x_j$, we find\n\\[ c_j = -a+\\Delta x\\left(j-\\frac12\\right) = -a+\\frac{2a}{n}\\left(j-\\frac12\\right) \\]\nfor the midpoints $c_j$ of the subintervals. This gives\n\\begin{equation*}\n\\begin{split}\nc_{n-j+1} & = -a+\\frac{2a}{n}\\left(n-j+1-\\frac12\\right) \\\\\n& = -a+2a+\\frac{2a}{n}\\left(-j+\\frac12\\right) = -c_j,\n\\end{split}\n\\end{equation*}\nand therefore, since $f$ is odd,\n\\[ f(c_j)+f(c_{n-j+1})=f(c_j)+f(-c_j)=f(c_j)-f(c_j) = 0. \\]\n\\end{proof}\n\n\\begin{definition}[Mean]\nFor continuous $f:[a,b]\\rightarrow\\mathbb{R}$, the real number\n\\[ \\bar{f}:= \\frac{1}{b-a} \\itgr{a}{b}{f(x)}{x} \\]\nis called the \\emph{mean} or \\emph{average} of $f$ over the interval $[a,b]$.\n\\end{definition}\n\n\\begin{remark}\nWe have\n\\[ \\bar{f}\\cdot(b-a) = \\itgr{a}{b}{f(x)}{x}, \\]\nthat is, the area under the constant function $\\bar{f}$ over $[a,b]$ is the same as the area under the graph of $f$:\n\\figbox{Definite integrals of $f$ and of the constant function $\\bar{f}$:}\nNote that this is similar for the average of numbers -- if Alice has an average of $\\bar{m}$ on all the tests in a module, and Bob scored exactly $\\bar{m}$ each time, then they have the same total mark.\n\\end{remark}\n\n\\begin{theorem}[Mean Value Theorem (MVT)]\nLet $f:[a,b]\\rightarrow\\mathbb{R}$ be continuous. Then there exists a point $c\\in(a,b)$ such that\n\\[ f(c) = \\frac{1}{b-a} \\itgr{a}{b}{f(x)}{x}. \\]\nThat is, $f$ attains its mean value at some point in $(a,b)$.\n\\end{theorem}\n\n\\begin{proof}\nLet\n\\[ M:=\\max_{x\\in[a,b]} f(x), \\qquad m:=\\min_{x\\in[a,b]} f(x).\\]\nSince $f$ is continuous, it takes every value between $m$ and $M$. Therefore, we need to show that\n\\begin{equation}\n\\label{eq:proof_mvt}\n m \\le \\bar{f} \\le M.\n\\end{equation}\nWe have\n\\begin{equation*}\n\\begin{split}\n& M-f(x) \\ge 0 \\qquad \\text{on~} [a,b] \\\\\n\\stackrel{\\text{prop. (6)}}{\\Longrightarrow} \\quad & \\itgr{a}{b}{M-f(x)}{x} \\ge 0 \\\\\n\\stackrel{\\text{prop. (3)}}{\\Longrightarrow} \\quad & \\itgr{a}{b}{M}{x}-\\itgr{a}{b}{f(x)}{x} \\ge 0 \\\\\n\\Longrightarrow \\quad & \\itgr{a}{b}{f(x)}{x} \\le \\itgr{a}{b}{M}{x} = M(b-a).\n\\end{split}\n\\end{equation*}\nCombining this with the outcome of the analogous computation for $f(x)-m$ gives\n\\[ m(b-a) \\le \\itgr{a}{b}{f(x)}{x} \\le M(b-a). \\]\nDivision by $(b-a)$ gives the inequality~\\ref{eq:proof_mvt}, and hence completes the proof.\n\\end{proof}\n\n\\begin{definition}[Area Function]\nFor continuous $f:[a,b]\\rightarrow\\mathbb{R}$, the \\emph{area function}\n\\[ A : [a,b] \\rightarrow \\mathbb{R} \\]\nof $f$ is\n\\[ A(x):=\\itgr{a}{x}{f(t)}{t}. \\]\n\\end{definition}\n\n\\begin{remark}\nWe use the variable $t$ in the integrand to avoid confusion with the variable of $A$.\n\\figbox{The area function for a continuous function $f$:}\n\\end{remark}\n\n\\begin{theorem}[Fundamental Theorem of Calculus (FTC)]\nLet $f:[a,b]\\rightarrow\\mathbb{R}$ be continuous.\n\\begin{enumerate}[(i)]\n\t\\item The derivative of the area function is\n\t\\[ A'(x) = \\Df{}{x} A(x) = f(x).\\]\n\tThat is,\n\t\\[ \\Df{}{x} \\itgr{a}{x}{f(t)}{t} = f(x). \\]\n\t\\item If $F$ is any \\emph{antiderivative} of $f$, i.e. a function with $F'(x)=f(x)$, then\n\t\\[ \\itgr{a}{b}{f(x)}{x} = F(b) - F(a). \\]\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{example}\nWe solve the following definite integral by guessing a function whose derivative is the integrand. Once this guessed antiderivative is written down, one should always check whether it really differentiates to the original integrand. \n\\begin{equation*}\n\\begin{split}\n\\itgr{1}{3}{(x^3-6x)}{x} \n& = \\left( \\eval{\\frac{x^4}{4} - 3x^2}{1}{3} \\right) \n\t\\qquad \\left[ \\text{check :~} \\Df{}{x} \\left( \\frac{x^4}{4} - 3x^2 \\right) \n\t= x^3-6x \\quad \\text{\\checkmark} \\right] \\\\\n& = \\left( \\frac{3^4}{4} - 3\\cdot 3^2 \\right)\n- \\left( \\frac{1^4}{4} - 3\\cdot 1^2 \\right) \n= \\frac{81}{4} - 27 - \\frac{1}{4} + 3 = -4\n\\end{split}\n\\end{equation*}\nThe vertical line in the second expression stands for ``evaluate at $x=3$ and then subtract the evaluation at $x=1$'' -- as on the right-hand side of FTC (ii). To foreshadow the proof of the FTC, note that the choice of antiderivative is not unique, but different choices seem to be leading to the same result; e.g.,\n\\[ \\itgr{1}{3}{x^3-6x}{x} = \\left( \\eval{\\frac{x^4}{4} - 3x^2 + 42}{1}{3} \\right)\n= \\frac{81}{4} - 27 + 42 - \\frac{1}{4} + 3 - 42 = -4. \\]\n\\end{example}\n\n\\begin{proof}\n\\begin{enumerate}[(i)]\n\t\\item Using the definition of the derivative, the definition of the area function, and property (5) of the definite integral, we obtain\n\t\\[ A'(x) = \\lim_{h \\to 0} \\frac{A(x+h)-A(x)}{h}\n\t= \\lim_{h \\to 0} \\frac{1}{h} \\itgr{x}{x+h}{f(t)}{t}. \\]\n\tThe expression within the limit on the right is the average of $f$ over the interval $[x,x+h]$. By the MVT, there exist $c_h\\in[x,x+h]$ such that\n\t\\[ f(c_h) = \\frac{1}{h} \\itgr{x}{x+h}{f(t)}{t}. \\]\n\tThis allows to continue the computation of $A'(x)$ above as follows:\n\t\\begin{equation*}\n\t\\begin{split}\n\tA'(x) & = \\lim_{h \\to 0} f(c_h) \\qquad \\text{where~} c_h\\in[x,x+h] \\\\\n\t\t  & = f\\left(\\lim_{h \\to 0} c_h \\right) = f(x). \\\\\t\n\t\\end{split}\n\t\\end{equation*}\n\t\\item The area function $A(x)$ is an antiderivative of $f$ -- by (i) -- and for it, the claim is true by definition:\n\t\\[ A(b) - A(a) = A(b) = \\itgr{a}{b}{f(t)}{t}. \\]\n\tNow let $F(t)$ be a different antiderivative of $f$. Then\n\t\\[ \\Df{}{x} \\left( F(x) -A(x) \\right) = f(x) -f(x) = 0, \\]\n\tand therefore $F$ and $A$ differ only by a constant,\n\t\\[ F(x) = A(x) + c.\\]\n\tThis gives\n\t\\[ F(b) - F(a) = (A(b)+c) - (A(a)+c) = A(b)-A(a) = \\itgr{a}{b}{f(t)}{t}. \\]\n\\end{enumerate}\n\\end{proof}\n\n\\begin{corollary}\n\\label{thm:cor_ftc}\n\\begin{enumerate}[(i)]\n\t\\item \\[ \\itgr{a}{b}{F'(t)}{t} = F(b)-F(a). \\]\n\t\\item \\[ \\Df{}{x} \\itgr{a(x)}{b(x)}{f(t)}{t} = f(b(x))\\,b'(x) - f(a(x))\\,a'(x). \\]\n\\end{enumerate}\n\\end{corollary}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item The word ``corollary'' is usually used for results that follow from important theorems.\n\t\\item The first identity is also called the ``Total Change Theorem'', and it follows immediately from FTC (ii). It reads: ``Integrating the rate of change of a function over an interval gives the total change over that interval.'' \n\t\\item Make sure to take note of the second identity -- it is important for differentiating more complicated integral expressions. It follows from the chain rule:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\Df{}{x} \\itgr{c}{b(x)}{f(t)}{t} & = \\Df{}{x} \\itgr{c}{y}{f(t)}{t} \\qquad\\qquad (y=b(x)) \\\\\n\t& = \\Df{}{y} \\itgr{c}{y}{f(t)}{t} \\cdot \\Df{y}{x} \\qquad\\qquad (\\text{chain rule})\\\\\n\t& = f(y) \\cdot \\Df{y}{x} = f(b(x))\\,b'(x),\n\t\\end{split}\n\t\\end{equation*}\n\tand using property (5) of the definite integral, we can prove the formula in full generality, that is, for the case when the lower bound is a function of $x$ as well.\n\\end{enumerate}\t\n\\end{remark}\n\n\\begin{definition}[Indefinite Integral]\nThe \\emph{indefinite integral}\n\\[ \\itgr{}{}{f(x)}{x} \\]\nof $f(x)$ is the collection of all antiderivatives of the function $f$.\n\\end{definition}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item For \n\t\\[ F(x) = \\itgr{1}{x^3}{t^5}{t}, \\]\n\twe find, identifying $f(t)=t^5$ and using the formula from theorem~\\ref{thm:cor_ftc},\n\t\\[ F'(x) = \\Df{}{x} \\itgr{1}{x^3}{f(t)}{t}\n\t= f(x^3)\\cdot\\Df{}{x}\\left(x^3\\right) - f(1)\\cdot\\Df{}{x}(1) \n\t= \\left(x^3\\right)^5 \\cdot 3x^2 + 0 = 3x^{17}. \\]\n\t\n\tWe can check this by finding $F(x)$ explicitly,\n\t\\[ F(x) = \\itgr{1}{x^3}{t^5}{t} \n\t= \\left(\\left. \\frac{t^6}{6} \\right|_1^{x^3}\\right)\n\t= \\frac{\\left(x^3\\right)^6}{6} - \\frac{1}{6}, \\]\n\tand then differentiating:\n\t\\[ F'(x) = \\Df{}{x} \\left( \\frac{x^{18}}{6} - \\frac{1}{6} \\right) \n\t= 18\\cdot\\frac{x^{17}}{6} - 0 = 3x^{17} \\quad \\text{\\checkmark}\\]\n\t\\item \\[ \\itgr{}{}{\\e^{3x}}{x} = \\frac{1}{3} \\e^{3x} + c. \\]\n\tHere, we use the constant $c$ as a place holder to cover all the infinitely many possible antiderivatives, e.g.\n\t\\[ \\frac{1}{3} \\e^{3x}, \\quad \\frac{1}{3} \\e^{3x} - 5, \\quad\n\t\\frac{1}{3} \\e^{3x} + 117.38, \\quad \\dots, \\]\n\tof $f(x)=\\e^{3x}$.\n\\end{enumerate}\t\n\\end{example}\n\n\\begin{remark}\nWe conclude this section with the following remarks:\n\\begin{enumerate}[(i)]\n\t\\item Integration is ``the opposite of differentiation''.\n\t\\item Integrals with boundaries are definite integrals, and then the result is a real number.\n\t\\item Integrals without boundaries are indefinite integrals, and then the result is a function! Make sure to not forget the constant of integration!\n\\end{enumerate}\n\\end{remark}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Interpret the properties~\\ref{prop:di} -- perhaps add a few sketches to your notes -- and prove one or two of them.\n\t\\item Find the area function $A_0$ of $f(x)=x^3-6x$ with $a=0$. Then set $a=1$ and find the corresponding area function $A_1$. Compare $A_0$ and $A_1$ to each other and to the indefinite integral of\\footnote{$A_0(x)$ and $A_1(x)$ should differ by the constant $\\rfrac{-11}{4}$ -- where does this number come from? By choosing the constant of integration suitably, you should be able to obtain both $A_0$ and $A_1$ from the indefinite integral.} $f(x)$.\n\t\\item Find the definite integral\n\t\\[ \\itgr{0}{1}{\\e^x}{x} \\]\n\tusing Riemann sums\\footnote{You will need the formula for the sum of the first $n$ terms of the geometric series.}, and then compare to the value found via direct integration.\n\t\\item Show that the definite integral, \\eqref{eq:def_itgr}, is well-defined\\footnote{Cf. remark~\\ref{rem:def_int} for the meaning of `well-defined'' in this context. For fixed $n$, we obtain the largest possible Riemann sum by letting the $c_j$ be the points at which $f$ takes its maximal value on $[x_{j-1},x_j]$. Similarly for the smallest possible Riemann sum. What is the difference between those two extremes, and what happens for $n\\to\\infty$?}.\n\t\\item Find the derivative of\\footnote{Careful, the FTC can not immediately by applied, because the $x$ appears in the integrand as well. Hence pull out the $x$ and then differentiate the product $x \\cdot \\int_0^{x^2}\\dots$. Note that there is a different way to solve this: find an explicit formula for $F$ in terms of $x$ -- without an integral -- and then differentiate. Try this approach as well and make sure your answers agree!}\n\t\\[ F(x) = \\itgr{0}{x^2}{x}{t}. \\]\n\\end{enumerate}\n\\end{exercise}\n\n\n\\section{Methods of Integration}\n\n\\subsection{Basic Integrals}\n\n\\begin{properties}[Basic Integrals]\n\\label{prop:bi}\n\\begin{equation*}\n\\begin{split}\n(1) \\qquad & \\itgr{}{}{x^r}{x} = \\frac{x^{r+1}}{r+1} + c \\qquad \\text{for~} r\\not=-1,  \\\\\n(2) \\qquad & \\itgr{}{}{\\frac{1}{x}}{x} = \\ln\\abs{x} + c, \\\\\n(3) \\qquad & \\itgr{}{}{\\e^x}{x} = \\e^x + c, \\\\\n(4) \\qquad & \\itgr{}{}{a^x}{x} = \\frac{a^x}{\\ln a} + c \\qquad \\text{for~} a>0,  \\\\\n(5) \\qquad & \\itgr{}{}{\\cos x}{x} = \\sin x + c, \\\\\n(6) \\qquad & \\itgr{}{}{\\sin x}{x} = -\\cos x + c, \\\\\n(7) \\qquad & \\itgr{}{}{\\frac{1}{\\cos^2 x}}{x} = \\tan x + c, \\\\\n(8) \\qquad & \\itgr{}{}{\\frac{1}{\\sin^2 x}}{x} = -\\cot x + c, \\\\\n(9) \\qquad & \\itgr{}{}{\\frac{1}{1+x^2}}{x} = \\arctan x + c, \\\\\n(10) \\qquad & \\itgr{}{}{\\frac{1}{\\sqrt{1-x^2}}}{x} = \\arcsin x + c, \\\\\n(11) \\qquad & \\itgr{}{}{\\cosh x}{x} = \\sinh x + c, \\\\\n(12) \\qquad & \\itgr{}{}{\\sinh x}{x} = \\cosh x + c. \n\\end{split}\n\\end{equation*}\n\\end{properties}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item The function $\\arctan x$ is the inverse function of $\\tan x$. It is sometimes denoted $\\tan^{-1}$, but this carries potential for confusion, as $\\arctan x \\not= \\rfrac{1}{\\tan x}$ ! Similarly, for $\\cos x$ and $\\sin x$ and their inverse functions. The expressions appearing in (7) and (8) could be rewritten using the conventions\n\t\\[  \\sec x = \\frac{1}{\\cos x}, \\quad \\csc x = \\frac{1}{\\sin x}, \\quad\n\t\\cot x = \\frac{\\cos x}{\\sin x}.\\]\n\t\\item The linearity properties (3) and (4) of \\ref{prop:di} remain true for indefinite integrals. Therefore, we can now integrate all linear combinations of functions appearing in the integrands of properties~\\ref{prop:bi}.\n\t\\item All the integrals above are verified by differentiating the antiderivative on the right and comparing to the integrand on the left. For example,\n\t\\[ \\Df{}{x} (-\\cos x + c) = \\sin x, \\]\n\tand hence (6) is correct.\n\t\\item Formula (2) can be used to evaluate definite integrals such as $\\itgr{1}{2}{\\rfrac{1}{x}}{x}$ or $\\itgr{-23}{-5}{\\rfrac{1}{x}}{x}$, but definite integrals across $x=0$ are not permitted since $f(x) = \\rfrac1x$ is not defined at $x=0$. This means that in this context, $x$ is either always positive or always negative. This allows to verify (2) by considering two cases: \\\\\n\t{\\it Case (a):} $x>0$ \\\\\n\t\\phantom{abc}If $x$ is positive, then $\\abs{x}=x$ and\n\t\\[ \\Df{}{x} (\\ln \\abs{x} + c) = \\Df{}{x} \\ln x = \\frac1x \\qquad \\text{\\checkmark} \\]\n\t{\\it Case (b):} $x<0$ \\\\\n\t\\phantom{abc}If $x$ is negative, then $\\abs{x}=-x$ and we obtain\n\t\\[ \\Df{}{x} (\\ln \\abs{x} + c) = \\Df{}{x} \\ln(-x) = \\frac{1}{-x}\\cdot(-1) = \\frac1x \\]\n\t\\phantom{abc}as well.\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{ x^{11} + 5\\cos x - 7^x }{x} \n\t& = \\itgr{}{}{x^{11}}{x} + 5\\itgr{}{}{\\cos x}{x} - \\itgr{}{}{7^x}{x} \\\\\n\t& = \\frac{x^{12}}{12} + 5\\sin x - \\frac{7^x}{\\ln 7} + c.\n\t\\end{split} \n\t\\end{equation*}\n\t\\item \\[ \\itgr{1}{\\e}{\\frac1x}{x} = \\eval{ \\ln \\abs{x} }{1}{\\e} = \\ln e - \\ln 1 = 1, \\]\n\twhich some calculus text books use to define the constant $\\e\\approx2.718$.\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\nIn the following example, recognising an expression coming from the chain rule allows us to ``guess'' an integral:\n\\[ \\itgr{}{}{2x\\,\\cosh(x^2)}{x} = \\sinh(x^2)+c. \\]\nThe next theorem makes the application of this idea more systematic.\n\\end{remark}\n\n\\subsection{Substitution}\n\n\\begin{theorem}[Substitution] \n\\label{thm:subst}\nIf $u=u(x)$ is differentiable and $f$ continuous, then\n\\begin{enumerate}[(i)]\n\t\\item \\[ \\itgr{}{}{f(u(x)) \\cdot u'(x) }{x} = \\itgr{}{}{f(u)}{u}. \\]\n\t\\item \\[ \\itgr{a}{b}{f(u(x)) \\cdot u'(x) }{x} = \\itgr{u(a)}{u(b)}{f(u)}{u}. \\]\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{x\\,\\left(1+x^2\\right)^{13}}{x} & \n\t\t\\qquad \\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\n\t\tu & = & 1+x^2 \\\\ 1 \\cdot \\d u & = & 2x \\cdot \\d x \\\\\n\t\t\\rightarrow \\: x \\d x & = & \\rfrac12 \\, \\d u\n\t\t\\end{array}\\right] \\\\\n\t& = \\itgr{}{}{u^{13}\\,\\frac12}{u} \\\\ \n\t& = \\frac12 \\frac{u^{14}}{14} + c \n\t  = \\frac{\\left( 1 + x^2 \\right)^{14}}{28} + c. \n\t\\end{split}\n\t\\end{equation*}\n\tCheck:\n\t\\[ \\Df{}{x} \\left( \\frac{\\left( 1 + x^2 \\right)^{14}}{28} + c \\right)\n\t= \\frac{14}{28} \\left( 1 + x^2 \\right)^{14-1} \\cdot 2x\n\t= x\\,\\left( 1 + x^2 \\right)^{13} \\qquad \\text{\\checkmark}\\]\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{0}{\\rfrac{\\pi}{2}}{\\cos(\\cos x)\\sin x}{x} &  \n\t\t\\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\n\t\tu & = & \\cos x \\\\ \\d u & = & -\\sin x \\, \\d x \\\\\n\t\t\\rightarrow \\: \\sin x \\, \\d x & = & - \\d u \\\\\n\t\tu=0 & \\leftrightarrow & x = \\rfrac\\pi2\\\\\n\t\tu=1 & \\leftrightarrow & x = 0\\\\\n\t\t\\end{array}\\right] \\\\\n\t& = \\itgr{1}{0}{\\cos u \\cdot (-1)}{u} \\\\ \n\t& = \\itgr{0}{1}{\\cos u}{u} = \\eval{\\sin u}{0}{1}   \n\t  = \\sin 1. \n\t\\end{split}\n\t\\end{equation*}\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\tI = \\itgr{0}{\\sqrt{3}}{\\e^{\\sqrt{1+x^2}}\\frac{x}{\\sqrt{1+x^2}}}{x} &  \n\t\t\\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\n\t\tu & = & \\sqrt{1+x^2} \\\\ \\d u & = & \\frac{x}{\\sqrt{1+x^2}} \\d x \\\\\n\t\tu=2 & \\leftrightarrow & x = \\sqrt{3}\\\\\n\t\tu=1 & \\leftrightarrow & x = 0\\\\\n\t\t\\end{array}\\right] \\\\\n\t& = \\itgr{1}{2}{\\e^u}{u} \\\\ \n\t& = \\eval{\\e^u}{1}{2} = \\e^2-\\e^1 = \\e(\\e-1).\n\t\\end{split}\n\t\\end{equation*} \n\tAlternatively, one could leave the boundaries in terms of $x$ and evaluate the antiderivative after substituting back to $x$:\n\t\\[ I = \\eval{\\e^u}{\\cdot}{\\cdot} = \\eval{\\e^{\\sqrt{1+x^2}}}{0}{\\sqrt{3}}\n\t= \\e^{\\sqrt{1+3}} - \\e^{\\sqrt{1}} = \\e(\\e-1). \\]\n\\end{enumerate}\t\n\\end{example}\n\n\\begin{remark}\nIn the integrands of the previous examples, we have seen the inner functions\n\\[ 1+x^2, \\quad \\cos x, \\quad \\sqrt{1+x^2}, \\]\nto which the outer functions\n\\[ x^{13}, \\quad \\cos x, \\quad \\e^x, \\]\nrespectively, are applied. A first attempt for solving integrals of that kind should always be to substitute for the identified inner function. The question is then whether the other factors in the integrand are absorbed by the transformation of the differential $\\d\\cdot$. If not, then more work or a different approach is required.\n\\end{remark}\n\n\\begin{example}\n\\label{expl:arctan-int}\nCompute the indefinite integral\n\\[ I = \\itgr{}{}{\\frac{1}{4+x^2}}{x}. \\]\nNote that we could read off the answer immediately from the list in properties~\\ref{prop:bi} if the $4$ in the denominator was a $1$. We therefore bring the integral in that form using substitution:\n\\begin{equation*}\n\\begin{split}\nI = \\itgr{}{}{\\frac{1}{4+x^2}}{x}\n& = \\itgr{}{}{\\frac{1}{4\\left(1+\\rfrac{x^2}{4}\\right)}}{x} \\\\\n& = \\frac{1}{4} \\itgr{}{}{\\frac{1}{1+\\left(\\rfrac{x}{2}\\right)^2}}{x}\n\\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\nu & = & \\rfrac{x}{2} \\\\ \\d u & = & \\rfrac{1}{2} \\, \\d x \\\\\n\\end{array}\\right] \\\\\n& = \\frac{1}{2} \\itgr{}{}{\\frac{1}{1+u^2}}{u} \\\\ \n& = \\frac{1}{2} \\arctan u + c = \\frac{1}{2} \\arctan \\left(\\frac{x}{2} \\right) + c.\n\\end{split}\n\\end{equation*} \n\\end{example}\n\n\\subsection{Trigonometric Identities}\n\n\\begin{properties}[Trigonometric Identities]\n\\label{prop:ti}\n\\begin{equation*}\n\\begin{split}\n(1) \\qquad & \\cos^2 x + \\sin^2 x = 1,  \\\\\n(2) \\qquad & \\cos(x+y) = \\cos x \\cos y - \\sin x \\sin y, \\\\\n(3) \\qquad & \\sin(x+y) = \\sin x \\cos y + \\cos x \\sin y, \\\\\n(4) \\qquad & \\cos(2x) = 2\\cos^2 x - 1 = 1 - 2 \\sin^2 x, \\\\\n(5) \\qquad & \\sin(2x) = 2\\sin x \\cos x, \\\\\n(6) \\qquad & 2\\sin x \\cos y = \\sin(x-y)+\\sin(x+y), \\\\\n(7) \\qquad & 2\\cos x \\cos y = \\cos(x-y)+\\cos(x+y), \\\\\n(8) \\qquad & 2\\sin x \\sin y = \\cos(x-y)-\\cos(x+y), \\\\\n(9) \\qquad & \\cosh^2 x - \\sinh^2 x = 1, \\\\\n\\end{split}\n\\end{equation*}\n\\end{properties}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{0}{\\pi}{\\sin^2 x}{x} & = \\itgr{0}{\\pi}{\\sin x \\cdot \\sin x}{x} \n\t\\stackrel{(8)}{=} \\itgr{0}{\\pi}{\\frac12 \\left[\\cos(x-x)-\\cos(x+x)\\right]}{x} \\\\\n\t& = \\itgr{0}{\\pi}{\\frac12 \\left[\\cos(0)-\\cos(2x)\\right]}{x}\n\t= \\frac12 \\itgr{0}{\\pi}{ 1-\\cos(2x)}{x} \\\\\n\t& = \\frac12 \\left( \\eval{x-\\rfrac12 \\sin(2x)}{0}{\\pi} \\right) = \\frac{\\pi}{2}.\n\t\\end{split}\n\t\\end{equation*}\n\tA better way to compute this integral would be to use the identity (4) -- this allows to go directly from the first expression to the fifth.\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{\\cos^4 x}{x} & = \\itgr{}{}{\\left( \\cos^2 x \\right)^2}{x} \n\t\\stackrel{(4)}{=} \\itgr{}{}{\\left( \\frac{\\cos(2x)+1}{2} \\right)^2}{x} \\\\\n\t& = \\itgr{}{}{\\frac14 \\left(\\cos^2(2x)+2\\cos(2x)+1\\right)}{x} \\\\\n\t& \\stackrel{(4)}{=} \\itgr{}{}{\\frac14 \\left(\\frac{\\cos(4x)+1}{2}+2\\cos(2x)+1\\right)}{x} \\\\\n\t& = \\frac{1}{32} \\sin(4x) + \\frac14 \\sin(2x) + \\frac38 x + c.\n\t\\end{split}\n\t\\end{equation*}\n\t\\item \n\t\\[ \\itgr{}{}{\\sin(2x)\\sin(7x)}{x} \n\t\\stackrel{(8)}{=} \\itgr{}{}{\\frac12 \\left[ \\cos(-5x) - \\cos(9x) \\right]}{x}\n\t= \\frac{\\sin(5x)}{10} - \\frac{\\sin(9x)}{18} + c. \\]\n\t\\item The following example contains a typical substitution with trigonometric functions, and some comments on it will be made in the next remark. \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{2.5}{5}{\\frac{\\sqrt{25-x^2}}{x^2}}{x} &  \n\t\t\\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\n\t\tx & = & 5\\sin\\theta \\\\ \\d x & = & 5\\cos\\theta \\, \\d \\theta \\\\\n\t\tx=5 & \\leftrightarrow & \\theta = \\rfrac{\\pi}{2} \\\\\n\t\tx=2.5 & \\leftrightarrow & \\theta = \\rfrac{\\pi}{6}\\\\\n\t\t\\end{array}\\right] \\\\\n\t& = \\itgr{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{2}}\n\t{\\frac{\\sqrt{25-(5\\sin\\theta)^2}}{(5\\sin\\theta)^2}\\,5\\cos\\theta}{\\theta} \\\\ \n\t& = \\itgr{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{2}}\n\t{\\frac{\\sqrt{1-\\sin^2\\theta}}{\\sin^2\\theta}\\,\\cos\\theta}{\\theta} \n\t\\stackrel{(1)}{=} \\itgr{\\rfrac{\\pi}{6}} {\\rfrac{\\pi}{2}}{\\frac{\\cos^2\\theta}{\\sin^2\\theta}}{\\theta} \\\\\n\t& \\stackrel{(1)}{=} \\itgr{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{2}}\n\t{\\frac{1-\\sin^2\\theta}{\\sin^2\\theta}}{\\theta} \n\t= \\itgr{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{2}}{\\frac{1}{\\sin^2\\theta}-1}{\\theta} \\\\\n\t& = \\eval{-\\cot \\theta - \\theta}{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{2}}\n\t= - 0 - \\frac{\\pi}{2} + \\frac{\\rfrac{\\sqrt{3}}{2}}{\\rfrac{1}{2}} + \\frac{\\pi}{6} \n\t= \\sqrt{3} - \\frac{\\pi}{3}.\n\t\\end{split}\n\t\\end{equation*}\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{\\frac{1}{\\sqrt{x^2-a^2}}}{x} &  \n\t\t\\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\left[ \\begin{array}{rcl}\n\t\tx & = & a\\cosh t \\\\ \\d x & = & a\\sinh t \\, \\d t \\\\\n\t\t\\end{array}\\right] \\\\\n\t& = \\itgr{}{}{\\frac{a\\sinh t}{\\sqrt{(a\\cosh t)^2-a^2}}}{t} \\\\\n\t& \\stackrel{(9)}{=} \\itgr{}{}{1}{t} = t+c = \\text{arccosh} \\left( \\frac{x}{a} \\right) + c.\n\t\\end{split}\n\t\\end{equation*}\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item Note the similarities in the approaches for (iv) and (v) above, and also note the differences: In both cases, we have square roots of expressions $\\pm(a^2-x^2)$ in the integrand, and we use the trigonometric Pythagoras formula (1) of properties~\\ref{prop:ti} and the corresponding hyperbolic version $(9)$ to simplify them. The following thoughts might help you to avoid confusion of the two. For $\\sqrt{a^2-x^2}$, we need $x$ to be small, namely in the range $[0,a]$, and the trigonometric functions have a bounded range. For $\\sqrt{x^2-a^2}$, we need $x$ to be large, and the function $g(t) = a\\cosh t$ has the correct range, $ R(g) = [a,\\infty)$.\n\t\\item For our next integration method, we apply the product rule to differentiate the product $fg$, and then bring one of the terms on the other side,\n\t\\[ f'g = (fg)' - fg'.\\]\n\tIntegrating this expression with respect to $x$, we obtain the following result.\n\\end{enumerate}\n\\end{remark}\n\n\\subsection{Integration by Parts}\n\n\\begin{theorem}[Integration by Parts]\n\\[ \\itgr{}{}{f'(x)g(x)}{x} = f(x)g(x) - \\itgr{}{}{f(x)g'(x)}{x}. \\]\n\\end{theorem}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item \n\tThe integration by parts formula allows us to find an import integral that was missing in properties~\\ref{prop:bi} -- the integral of the logarithm:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{\\ln x}{x} \n\t& =\t\\itgr{}{}{\\underbrace{1}_{\\text{int.}} \\cdot \\underbrace{\\ln x}_{\\text{diff.}}}{x}\n\t= x\\ln x - \\itgr{}{}{x \\cdot \\Df{}{x}(\\ln x)}{x} \\\\\n\t& = x\\ln x - \\itgr{}{}{x\\cdot\\frac{1}{x}}{x}\n\t= x\\ln x - \\itgr{}{}{1}{x} = x\\ln x - x + c.\n\t\\end{split}\n\t\\end{equation*}\n\tWe have integrated $\\ln x$ by differentiating it!\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\t\\itgr{}{}{\\underbrace{x^2}_{\\text{diff.}} \\underbrace{\\e^{3x}}_{\\text{int.}}}{x} \n\t& = \\frac13\\e^{3x}x^2 - \\itgr{}{}{\\frac13\\e^{3x}2x }{x}\n\t= \\frac13\\e^{3x}x^2 - \\frac23 \\left[ \n\t\\itgr{}{}{\\underbrace{\\e^{3x}}_{\\text{int.}}\\underbrace{x}_{\\text{diff.}} }{x} \\right] \\\\\n\t& = \\frac13\\e^{3x}x^2 - \\frac23 \n\t\\left[ \\frac13 \\e^{3x}x - \\itgr{}{}{\\frac13\\e^{3x}}{x}  \\right] \\\\\n\t& = \\frac13\\e^{3x}x^2 - \\frac23 \n\t\t\\left[ \\frac13 \\e^{3x}x - \\frac19\\e^{3x} + \\wtd{c} \\right] \n\t= \\frac13 \\e^{3x} \\left[ x^2-\\frac23x+\\frac29 \\right] + c.\n\t\\end{split}\n\t\\end{equation*}\n\t\\item When applying integration by parts to definite integrals, all terms need to be evaluated over the interval; e.g.,\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\itgr{0}{1}{\\underbrace{x}_{\\text{diff.}}\\underbrace{(1+x)^{17}}_{\\text{int.}}}{x} \n\t& = \\eval{x\\frac{(1+x)^{18}}{18}}{0}{1} - \\itgr{0}{1}{\\frac{(1+x)^{18}}{18}}{x} \\\\\n\t& = 1 \\cdot \\frac{2^{18}}{18}-0-\\frac{1}{18 \\cdot 19} \n\t\t\\left( \\eval{(1+x)^{19}}{0}{1} \\right) \\\\\n\t& = \\frac{1}{18 \\cdot 19} \\left( 19 \\cdot 2^{18} - 2^{19} + 1 \\right)\n\t= \\frac{495161}{38}.\n\t\\end{split}\n\t\\end{equation*}\n\t\\item \\begin{equation*}\n\t\\begin{split}\n\tI & = \\itgr{}{}{\\underbrace{\\e^x}_{\\text{int.}}\\underbrace{\\cos x}_{\\text{diff.}}}{x} \n\t= \\e^x\\cos x - \\itgr{}{}{\\e^x (-\\sin x)}{x} \\\\\n\t& = \\e^x\\cos x + \\itgr{}{}\n\t\t{\\underbrace{\\e^x}_{\\text{int.}}\\underbrace{\\sin x}_{\\text{diff.}}}{x} \\\\\n\t& = \\e^x\\cos x + \\e^x\\sin x - \\itgr{}{}{\\e^x \\cos x}{x} \\\\\n\t& = \\e^x\\cos x + \\e^x\\sin x - I\n\t\\end{split}\n\t\\end{equation*}\n\tThis computation does not seem to lead anywhere, as the integral we need to compute reappears after two applications of the integration by parts rule. Differentiating $\\e^x$ and integrating the trigonometric term instead, leads to a similar situation. However, we can solve the equation for $I$ ! This gives\n\t\\[ I = \\itgr{}{}{\\e^x \\cos x}{x} = \\frac12 \\e^x(\\cos x + \\sin x) +c.\\]\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item When faced with an integrand that contains a power of $x$ and other, more complicated terms, one should first try substitution. If this does not work, integration by parts is the next best option. In this case, one would usually choose the power of $x$ as the term that is to be differentiated -- the reason for this is that differentiation makes powers simpler and repeated integration by parts will eventually dispose of them. However, there are no firm rules for integration and one should remain open-minded to non-standard approaches.\n\t\\item Many of the examples above are specifically designed so that the computations work out relatively smoothly. In general, integration is quite hard and sometimes even impossible. It is therefore important to keep in mind that differentiation provides a straight-forward way to verify the integrals you have found. Here is an integral that cannot be solved:\n\t\\[ \\itgr{}{}{\\e^{-x^2}}{x}. \\]\n\t\\item Consider the computation\n\t\\[ \\frac{2}{x+4}-\\frac{3}{x-1} \n\t= \\frac{2(x-1)-3(x+4)}{(x+4)(x-1)} = \\frac{-(x+14)}{x^2+3x-4}, \\]\n\tand note that, while we can integrate the expression on the left-hand side -- e.g.,\n\t\\[ \\itgr{}{}{\\frac{2}{x+4}}{x} = 2\\ln(x+4) + c \\]\n\t-- the expression on the right is not covered by the integration methods we have developed so far. Reversing finding the common denominator therefore extends the set of functions we can integrate. This is called integration by partial fractions.\n\\end{enumerate}\n\\end{remark}\n\n\\subsection{Partial Fractions}\n\n\\begin{example}\n\\label{expl:partial_fractions}\n\\begin{enumerate}[(i)]\n\t\\item Find the integral\n\t\\[ I = \\itgr{}{}{\\frac{2x+16}{x^2+2x-35}}{x}. \\]\n\t{\\it Sol.:}\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\frac{2x+16}{x^2+2x-35} & =\\frac{2x+16}{(x-5)(x+7)}\n\t= \\frac{A}{x-5} +\\frac{B}{x+7} \\\\\n\t& = \\frac{A(x+7)+B(x-5)}{(x-5)(x+7)}\n\t= \\frac{(A+B)x+(7A-5B)}{(x-5)(x+7)}\n\t\\end{split}\n\t\\end{equation*}\n\t\\[ \\Longrightarrow \\quad \\begin{cases} A+B &= 2 \\\\ 7A-5B &= 16 \\end{cases} \n\t\t\\qquad \\Longrightarrow \\quad \n\t\t\\begin{cases} A &= \\rfrac{13}{6} \\\\ B &= \\rfrac{-1}{6} \\end{cases} \\]\n\t\\begin{equation*}\n\t\t\\begin{split}\n\t\t\t\\Longrightarrow \\quad I & = \\itgr{}{}{\\frac{2x+16}{x^2+2x-35}}{x}\n\t\t\t= \\itgr{}{}{ \\frac{\\rfrac{13}{6}}{x-5} +\\frac{\\rfrac{-1}{6}}{x+7} }{x} \\\\\n\t\t\t& = \\frac{13}{6} \\itgr{}{}{\\frac{1}{x-5}}{x} \n\t\t\t\t- \\frac{1}{6} \\itgr{}{}{\\frac{1}{x+7}}{x}\n\t\t\t= \\frac{13}{6} \\ln\\abs{x-5}\t- \\frac{1}{6} \\ln\\abs{x+7} + c.\n\t\t\\end{split}\n\t\\end{equation*}\n\t\\item Integrate\n\t\\[ f(x) = \\frac{x^4-x^3-3x^2+x-2}{x^3+9x} \\]\n\tover the interval $[1,2]$. \\\\\n\t{\\it Sol.:}\n\tBefore we can ``split up'' the fraction as above, we have to bring it in a form in which the degree of the numerator is smaller than the degree of the denominator. The idea for doing that is\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\frac{x^4-x^3-3x^2+x-2}{x^3+9x} & = \\frac{x^4\\colorbox{olive!20}{+$9x^2-9x^2$}-x^3-3x^2+x-2}{x^3+9x} \\\\\n\t& = \\frac{x^4+9x^2}{x^3+9x} + \\frac{-9x^2-x^3-3x^2+x-2}{x^3+9x} \\\\\n\t& = x + \\frac{-x^3-12x^2+x-2}{x^3+9x} = \\dots\n\t\\end{split}\n\t\\end{equation*}\n\tThis is long division of polynomials, and it is usually written out more systematically as\n\t\\begin{equation*}\n\t\\begin{array}{rrrrrrrrrrr}\n\t\t( & x^4 & - x^3 & - 3x^2 & + x & - 2 & ) & : & (x^3+9x) & = & \n\t\t\t\t\t\t\t\t\t\t\tx-1 + \\frac{-12x^2+10x-2}{x^3+9x}. \\\\\n\t   -( & x^4 &       & + 9x^2 & )   &&&&&& \\\\\n\t      &   ( & - x^3 & -12x^2 & + x & - 2 & ) &&&& \\\\\n   \t      &  -( & - x^3 &        & -9x & ) &&&&& \\\\\n   \t      &     &     ( & -12x^2 &+10x & - 2 & ) &&&&\n\t\\end{array}\n\t\\end{equation*}\n\tNext, we split up the remaining fraction, as in the example above:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\frac{-12x^2+10x-2}{x^3+9x} & =\\frac{-12x^2+10x-2}{x(x^2+9)}\n\t= \\frac{A}{x} +\\frac{Bx+C}{x^2+9} \\\\\n\t& = \\frac{A(x^2+9)+(Bx+C)x}{x(x^2+9)}\n\t= \\frac{(A+B)x^2+Cx+9A}{x(x^2+9)}.\n\t\\end{split}\n\t\\end{equation*}\n\tGeneral guidelines for how to make the ansatz involving the constants $A,B,C$ in the middle expression will be given in the remark below. The next step is to compare coefficients in the numerator on the left and on the right:\t\n\t\\[ \\begin{cases} A+B &= -12 \\\\ C &= 10 \\\\ 9A &= -2 \\end{cases} \n\t\\qquad \\Longrightarrow \\quad \n\t\\begin{cases} A &= \\rfrac{-2}{9} \\\\ B &= \\rfrac{-106}{9} \\\\ C &= 10. \\end{cases} \\]\n\tWe can now write the definite integral as a sum of simpler integrals:\n\t\\begin{equation*}\n\t\\begin{split}\n\tI & = \\itgr{1}{2}{\\frac{x^4-x^3-3x^2+x-2}{x^3+9x}}{x}\n\t= \\itgr{1}{2}{x-1+\\frac{\\rfrac{-2}{9}}{x}+\\frac{\\rfrac{-106}{9}\\,x+10}{x^2+9} }{x} \\\\\n\t& = \\itgr{1}{2}{x}{x} - \\itgr{1}{2}{1}{x} -\\frac{2}{9}\\itgr{1}{2}{\\frac{1}{x}}{x}\n\t\t\t\t\t\t\t\t+\\itgr{1}{2}{\\frac{\\rfrac{-106}{9}\\,x+10}{x^2+9}}{x}.\n\t\\end{split}\n\t\\end{equation*}\n\tThe first integrals are basic integrals, denote them $I_1,I_2,I_3$. The fourth we split up further as\n\t\\[ I = I_1 + I_2 + I_3 \n\t\t-\\frac{53}{9}\\itgr{1}{2}{\\frac{2x}{x^2+9}}{x}\n\t\t+10\\itgr{1}{2}{\\frac{1}{x^2+9}}{x}, \\]\n\tso that the fourth integral can be computed with a straightforward substitution, and the last one as in example~\\ref{expl:arctan-int}. Computing the five definite integrals and adding them together gives the answer,\n\t\\[ I = \\frac12 -\\frac29\\ln(2)-\\frac{53}{9}\\ln(1.3)\n\t\t+\\frac{10}{3}\\left(\\arctan (\\rfrac23) - \\arctan(\\rfrac13) \\right)\n\t\t\\approx -0.312. \\]\n\t\\item Find the integral\n\t\\[ I = \\itgr{}{}{\\frac{x-\\rfrac32}{x^2-3x+7}}{x}. \\]\n\t{\\it Sol.:}\n\tFlexibility is key for integration -- this is a substitution problem:\n\t\\begin{equation*}\n\t\\begin{split}\n\tI & = \\frac12 \\itgr{}{}{\\frac{2x-3}{x^2-3x+7}}{x}\n\t= \\frac12 \\itgr{}{}{\\frac1u}{u} \\\\\n\t& = \\frac12 \\ln \\abs{u} + c\n\t= \\frac12 \\ln \\abs{x^2-3x+7} + c.\n\t\\end{split}\n\t\\end{equation*}\n\tThere are examples where both approaches -- the substitution here in (iii), and the partial fraction approach in (i) -- can be used, cf. the exercise below. However, for the problem at hand, the partial fraction approach would not work, as the denominator $x^2-3x+7$ can not be factored.\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\nThe steps for integration by partial fractions are:\n\\begin{enumerate}[(1)]\n\t\\item If necessary, use polynomial division to transform to a polynomial plus a fraction in which the degree of the numerator is smaller than degree of the denominator.\n\t\\item Write the denominator as a product of irreducible factors. Each of them will have degree at most two. In this module, we only consider the case where none of these factors is repeated.\n\t\\item For each factor, define a fraction that has that factor in the denominator and a general polynomial of degree one less in the numerator. That is, if the denominator is a linear expression (polynomial of degree $1$), then the numerator is just a constant $c$ (polynomial of degree $0$). If the denominator is a quadratic expression (polynomial of degree $2$), then the numerator should be of the form $c_1 x + c_2$ (polynomial of degree $1$).\n\t\\item Make the ansatz that the sum of the fractions from the previous step is equal to the original fraction. This will lead to a system of equations for all the constants appearing in the numerators defined in the previous step. Solve it.\n\t\\item In the computation of the integral, replace the original integrand with the sum of partial fractions you have found, plus possibly the polynomial that was obtained in step $(1)$. Now use the linearity of the integral to obtain a combination of simple integrals that can be solved with the methods we have seen in this section. (In general, it is possible to obtain integrals at this point that can not be solved with the methods we have learned so far -- but there will not be any such examples in the exam.) \n\\end{enumerate}\n\\end{remark}\n\n\n\\begin{application}[\\texttt{Signal conversion}]\n\\texttt{\\ldots}\n\\end{application}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item I recommend to practise integration intensively by working through a large number of examples. This is important as integration is a very fundamental skill for all branches of mathematics, engineering, and other sciences. Besides the material here, you can look for more practice examples and exercises in online lecture notes and tutorial sheets. You can even make up you own examples and check your results using differentiation. Mathematics software such as WolframAlpha can compute many integrals, but \\emph{do not rely on this}. \n\t\\item Make sure to complete all the steps in this section that were only sketched, e.g. the last lines of~\\ref{expl:partial_fractions} (ii). Following the comment at the end of~\\ref{expl:partial_fractions} (iii), compute\n\t\\[ \\itgr{}{}{\\frac{x+1}{x^2+2x-3}}{x} \\]\n\tin two different ways.\n\t\\item Using integration, find the area inside the circle of radius\\footnote{First, you need a function whose graph is the circle or part of the circle -- use the formula $x^2+y^2=R^2$ for that.} $R$.\n\t\\item Find\\footnote{The value you obtained is correct if it rounds to $0.309$.}\n\t\\[ \\itgr{\\rfrac{\\pi}{6}}{\\rfrac{\\pi}{4}}{\\frac{\\cos 2x}{\\cos^2 x \\sin^2 x}}{x}. \\]\n\t\\item Find\\footnote{It is useful to consider the area function with $a=0$, $A(x)=\\itgr{0}{x}{(1+\\abs{t})^2}{t}$.}\n\t\\[ \\itgr{}{}{(1+\\abs{x})^2}{x}. \\]\n\t\n\\end{enumerate}\t\t\n\\end{exercise}\n\n\n\\section{Improper Integrals}\n\n\\begin{definition}[Improper Integral]\nA definite integral $\\itgr{a}{b}{f(x)}{x}$ is called \\emph{improper} if\n\\begin{enumerate}[(I)]\n\t\\item the interval of integration is infinite, i.e. $a=-\\infty$, or $b=\\infty$, or both;\n\t\t\t or if \n\t\\item the interval of integration contains a \\emph{singularity} of $f$, that is, a point where $f$ is not defined, e.g. a zero of the denominator.\n\\end{enumerate}\nIf $b=\\infty$ (type I) or $b$ is a singularity (type II), then\n\\[ \\itgr{a}{b}{f(x)}{x} := \\lim_{\\substack{t \\to b \\\\ t<b}} \\itgr{a}{t}{f(x)}{x}, \\]\nand the improper integral is said to exist / not exist depending on whether the limit on the right-hand side exists.\n\nSimilarly if $a$ is the boundary that causes the integral to be improper. If both boundaries are infinite (type I) or if the singularity lies inside the interval (type II), then the improper integral should be split up, cf. example~\\ref{expl:ii_t2} (i) below.\n\\end{definition}\n\n\\begin{example}[Type I]\n\\begin{enumerate}[(i)]\n\t\\item \n\\begin{equation*}\n\\begin{split}\n\\itgr{-\\infty}{0}{\\e^{2x}}{x} & = \\lim_{R \\to -\\infty} \\itgr{R}{0}{\\e^{2x}}{x}\n= \\lim_{R \\to -\\infty} \\left. \\frac12 \\e^{2x} \\right|_R^0 \n= \\lim_{R \\to -\\infty} \\frac{\\e^{2 \\cdot 0} - \\e^{2 \\cdot R}}{2} \\\\ \n& = \\frac12 \\qquad \\qquad \\Longrightarrow\n\\text{the impr. int. does exist and is equal to $\\rfrac12$.}\n\\end{split}\n\\end{equation*}\n\t\\item\n\\begin{equation*}\n\\begin{split}\n\\itgr{1}{\\infty}{\\frac1x}{x} & = \\lim_{R \\to \\infty} \\itgr{1}{R}{\\frac1x}{x}\n= \\lim_{R \\to \\infty} \\left. \\ln x \\right|_1^R\n= \\lim_{R \\to \\infty} \\ln R - \\ln 0 \\\\\n& = \\infty \\qquad \\qquad \\Longrightarrow \\text{the impr. int. does not exist.}\n\\end{split}\n\\end{equation*}\n\\end{enumerate}\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item The first example states that the area under the curve\n\t\\[ f(x) = \\e^{2x} \\qquad x\\leq0 \\]\n\tis finite! Here, the word ``area'' refers to the total amount of area -- as in ``square footage'' -- rather than the set of points under that curve. The latter is an infinitely long ``spike''.\n\t\\item Improper integrals of type I are similar to series, and (ii) corresponds to the fact that the harmonic series $\\sum \\rfrac1n$ diverges.\n\t\\item Recalling the definition of the area function $A(x)$, we see that the limit that is to be found for an improper integral of a continuous function on $[a,\\infty)$ is that of the area function:\n\t\\[ \\itgr{a}{\\infty}{f(x)}{x} = \\lim_{R\\to\\infty} A(R). \\]\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}[Type II]\n\\label{expl:ii_t2}\n\\begin{enumerate}[(i)]\n\t\\item Integrate $f(x)=\\rfrac{1}{\\sqrt[3]{x^2}}$ over the interval $[-1,+1]$.\\\\\n{\\it Sol.:}\n\\begin{equation*}\n\\begin{split}\n\\itgr{-1}{+1}{\\frac{1}{\\sqrt[3]{x^2}}}{x} \n& = \\itgr{-1}{0}{\\frac{1}{\\sqrt[3]{x^2}}}{x} + \\itgr{0}{+1}{\\frac{1}{\\sqrt[3]{x^2}}}{x} \\\\\n& = 2 \\itgr{0}{1}{\\frac{1}{\\sqrt[3]{x^2}}}{x} \n\t\\qquad \\qquad \\text{(since $f$ is an even function)} \\\\\n& = 2\\,\\lim_{\\varepsilon \\to 0} \\itgr{\\varepsilon}{1}{x^{-\\rfrac23}}{x}\n= 2\\,\\lim_{\\varepsilon \\to 0} \\left. 3 x^{\\rfrac13} \\right|_\\varepsilon^1\n= 6 - 6\\,\\lim_{\\varepsilon \\to 0} \\varepsilon^{\\rfrac13} = 6.\n\\end{split}\n\\end{equation*}\nThe improper integral exists and is equal to $6$.\n\t\\item\n\\begin{equation*}\n\\begin{split}\n\\itgr{0}{\\rfrac\\pi2}{\\frac{1}{\\sin^2x}}{x} \n& = \\lim_{\\varepsilon \\to 0} \\itgr{\\varepsilon}{\\rfrac\\pi2}{\\frac{1}{\\sin^2x}}{x} \n= \\lim_{\\varepsilon \\to 0} \\left( \\left. -\\cot x \\right|_\\varepsilon^{\\rfrac\\pi2} \\right) \\\\\n& = \\lim_{\\varepsilon \\to 0} \\left( -\\frac{\\cos\\rfrac\\pi2}{\\sin\\rfrac\\pi2} \n\t+ \\frac{\\cos\\varepsilon}{\\sin\\varepsilon} \\right)\n= - 0 + \\lim_{\\varepsilon \\to 0} \\frac{\\cos\\varepsilon}{\\sin\\varepsilon} = \\infty.\n\\end{split}\n\\end{equation*}\nTherefore, the improper integral does not exist.\n\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item For which powers $p\\in\\mathbb{R}$ do the integrals\n\t\t\\[ \\itgr{0}{1}{x^p}{x}, \\qquad \\itgr{1}{\\infty}{x^p}{x} \\]\n\texist\\footnote{Taking the union of the set of $p$ values, for which the first improper exists, with the set of $p$'s for the second, you should obtain the whole real line with only one point missing.}?\t\t\n\t\\item Evaluate the improper integral\\footnote{Compute $I_0$ directly and use integration by parts to find a recursive formula for $I_n$. Can you derive an explicit formula!}\n\t\t\\[ I_n = \\itgr{0}{\\infty}{x^n\\e^{-x}}{x}. \\]\n\t\\item The goal of this exercise is to go through a quite difficult integration that consists of a number of steps: Evaluate the improper integral\n\t\t\\[ \\itgr{\\rfrac12}{\\rfrac32}{\\frac{1}{\\sqrt{\\abs{x-x^2}}}}{x} \\]\n\tby (1) considering two cases, (2) using the identities\n\t\\[ x-x^2 = \\frac14\\left[ 1-(2x-1)^2 \\right], \n\t\\quad x^2-x = \\frac14\\left[ (2x-1)^2-1 \\right], \\]\n\t(3) substituting $u=2x-1$, and (4) using a basic integral from the table~\\ref{prop:bi} and\\footnote{The value you obtained is correct if it rounds to $1.571+1.317=2.888$.}\n\t\\[ \\itgr{}{}{\\frac{1}{\\sqrt{t^2-1}}}{t} =\\ln \\left( \\sqrt{t^2-1}+t \\right)+c.\\]\n\\end{enumerate}\t\t\n\\end{exercise}\n\n\n\\section{Integrals of Functions of Several Variables}\n\n\\begin{example}\n\\label{expl:first_higher-dim_int}\nAs an introduction to this section, we compute a simple double-integral. That is done systematically starting from the innermost integral. In the following example, a $\\d x$ integral is to be found first. For this step, the other variable, $y$, is treated like a constant, as it is not the variable with respect to which the current integration is carried out:\n\\begin{equation*}\n\\begin{split}\nI & = \\itgr{0}{1}{\\itgr{0}{1}{x+y}{x}}{y} \n= \\itgr{0}{1}{\\left[\\itgr{0}{1}{x+y}{x}\\right]}{y} \\\\\n& = \\itgr{0}{1}{\\left[ \\left. \\frac{x^2}{2} + xy \\right|_{x=0}^{x=1} \\right]}{y} \n= \\itgr{0}{1}{\\left[ \\frac{1}{2} + 1 \\cdot y - \\frac{0^2}{2} - 0 \\cdot y \\right]}{y} \\\\\n& = \\itgr{0}{1}{\\frac12+y}{y} = \\left. \\frac{y}{2} + \\frac{y^2}{2} \\right|_0^1 \n= \\frac12 + \\frac 12 - 0 - 0 = 1.\n\\end{split}\n\\end{equation*}\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item Just as the integral $\\itgr{a}{b}{f(x)}{x}$ is the area between the curve $y=f(x)$ and the interval $[a,b]$ of the $x$-axis, the double integral\n\t\\[ \\itgr{a}{b}{\\itgr{c}{d}{f(x,y)}{y}}{x} \\]\n\tis the volume between the surface $z=f(x,y)$ and the rectangle \n\t\\[ [a,b]\\times[c,d] = \n\t\t\\{ (x,y)\\in\\mathbb{R}^2 \\: | \\: a \\leq x \\leq b,\\, c \\leq y \\leq d \\} \\]\n\tof the $xy$-plane.\n\t\\item To check whether this interpretation agrees with the result $I=1$ we have found above, note that the graph of the integrand $f(x,y)=x+y$ is a plane and has heights\n\t\\[ f(0,0)=0, \\quad f(0,1)=1, \\quad f(1,0)=1, \\quad f(1,1)=2, \\]\n\tover the corner points of the domain of integration, $D=[0,1]\\times[0,1]$. This means that the volume that is to be found is that of a cuboid of size $1 \\times 1 \\times 2$ that is diagonally cut in half:\n\t\\figbox{Sketch corresponding to example \\ref{expl:first_higher-dim_int}:}\n\tThis solid has the volume\n\t\\[ V = \\frac{1\\cdot1\\cdot2}{2}=1, \\]\n\twhich we had also obtained with the integration above.\n\t\\item We write $\\d A$ for $\\d x \\d y$,\n\t\\[ \\d A = \\d x \\d y, \\]\n\tmeaning, roughly, that the change of area is equal to the change of $x$ times the change of $y$. $\\d A$ is called the \\emph{area element}. The order of the integrations $\\d x$ and $\\d y$ can be swapped, but one needs to be careful about the boundaries, cf. later examples.\t\n\t\\item There also is a formulation of Riemann sums for functions of several variables. We will not address this further in MTH1002, but the idea is as follows:\n\t\\figbox{Riemann Sum of a 2D function:}\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\nIntegrate the function $f(x,y)=\\rfrac{y}{x}$ over the domain $D=[3,6]\\times[1,2]$. \\\\\n{\\it Sol.:}\n\\[ I = \\iint_D f \\: \\d A \n= \\itgr{1}{2}{\\itgr{3}{6}{\\frac{y}{x}}{x}}{y}\n= \\itgr{1}{2}{\\left[ \\itgr{3}{6}{\\frac{y}{x}}{x}\\right]}{y}. \\]\nThe inside integral is with respect to $x$, and it therefore treats $y$ like a constant -- it is therefore permissible to pull out $y$,\n\\[ I = \\itgr{1}{2}{y \\left[ \\itgr{3}{6}{\\frac{1}{x}}{x}\\right]}{y}\n= \\itgr{1}{2}{y \\left[ \\left. \\ln x \\right|_3^6 \\right]}{y} \n= \\ln 2 \\, \\itgr{1}{2}{y}{y} = \\ln \\sqrt{8}. \\]\n\\end{example}\n\n\\begin{remark}\nAll domains of integration so far have been rectangles. In this case, the $x$ and $y$ boundaries are constant, and the order of integration can be swapped easily -- convince yourself of that by re-doing one of the problems above integrating with respect to $y$ and then w.r.t. $x$. Next we study non-rectangular domains of integration, for which the boundaries of the inner integral depend on the outer variable.\n\\end{remark}\n\n\\begin{example}\n\\label{expl:non-rect}\n\\begin{equation*}\n\\begin{split}\nI & = \\itgr{0}{1}{\\itgr{0}{x^2}{1}{y}}{x} \n= \\itgr{0}{1}{\\left[\\itgr{0}{x^2}{1}{y}\\right]}{x} \\\\\n& = \\itgr{0}{1}{\\left(\\left.y\\right|_{0}^{x^2}\\right)}{x} \n= \\itgr{0}{1}{\\left(x^2-0\\right)}{x} = \\itgr{0}{1}{x^2}{x} = \\frac13.\n\\end{split}\n\\end{equation*}\n\\end{example}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item In the previous example, the domain of integration was\n\t\\[ D = \\{ (x,y) \\: | \\: 0 \\leq x \\leq 1,\\, 0 \\leq y \\leq x^2 \\}. \\]\n\tIntegrating the function $f(x,y)=1$ over a subset of $\\mathbb{R}^2$ gives the area of that set. This is similar to 1D integration: integrating $f(x)=1$ over an interval gives the length of that interval.\n\t\\item Our choice to integrate first w.r.t. $y$ and then w.r.t. $x$ in the previous example corresponds to the following steps: (1) for each $x\\in[0,1]$, integrate over each vertical line in the sketch, then (2) collect those values in the $x$ direction. \n\t\\figbox{Order of integration for example \\ref{expl:non-rect}:}\n\tWe could also find $I=\\iint_D 1 \\: \\d A$ by integrating the other way around. For this, one has to solve the equations that define the boundaries for the other variable:\n\t\\[ I = \\itgr{0}{1}{\\itgr{\\sqrt{y}}{1}{1}{x}}{y} \\]\n\t-- check that this gives the same result.\n\t\\figbox{Illustration of integration in the other order:}\n\\end{enumerate}\n\\end{remark}\n\n\\begin{example}\n\\label{expl:mult_int_1}\nIntegrate $f(x,y)=y \\sin x$ over the triangle $D$ with corner points $(0,0)$, $(\\pi,0)$, and $(\\pi,1)$. \\\\\n{\\it Sol.:}\n\\figbox{Sketch of the domain of integration:}\n\\begin{equation*}\n\\begin{split}\n\\iint f \\d A & = \\itgr{0}{\\pi}{\\itgr{0}{\\rfrac{x}{\\pi}}{y\\sin x}{y}}{x} \n= \\itgr{0}{\\pi}{\\sin x \\left[\\itgr{0}{\\rfrac{x}{\\pi}}{y}{y}\\right]}{x} \\\\ \n& = \\itgr{0}{\\pi}{\\sin x \\left(\\left.\\frac{y^2}{2}\\right|_0^{\\rfrac{x}{\\pi}}\\right)}{x} \n= \\itgr{0}{\\pi}{\\sin x \\frac{x^2}{2\\pi^2}}{x} \\\\\n& = \\frac{1}{2\\pi^2}\\itgr{0}{\\pi}{x^2 \\cdot \\sin x}{x} = \\dots = \\frac{\\pi^2-4}{2\\pi^2}.\n\\end{split}\n\\end{equation*}\n\\end{example}\n\n\\begin{remark}\nIt is helpful to always start a computation of a 2D integral with a sketch of the domain of integration. Labelling its boundaries with the formulas that describe them helps to correctly write out $\\iint_D f(x,y) \\: \\d A$ as $\\itgr{\\cdot}{\\cdot}{\\itgr{\\cdot}{\\cdot}{f(x,y)}{y}}{x}$. The integration can be carried out in either order, but the next example and the corresponding exercise below show that for some domains, one order of integration is easier than the other.\n\\end{remark}\n\n\\begin{example}\n\\label{expl:mult_int_2}\n\\begin{enumerate}[(i)]\n\t\\item \nLet $D$ be the region bounded by the line $y=x+1$ and by the parabola $y=x^2-1$. Find\n\\[ I = \\iint_D xy+2 \\: \\d A. \\]\n{\\it Sol.:} \nThe domain of integration is the region between the line and the parabola below. We find the intersection points as follows:\n\\begin{equation*}\n\\begin{split}\nx + 1 & \\stackrel{\\text{!}}{=} x^2 - 1 \\\\\n\\rightarrow \\quad 0 & = x^2-x-2 \\\\\n& \\Longrightarrow \\quad x_1 = -1, \\quad x_2 = 2.\n\\end{split}\n\\end{equation*}\n\\figbox{The domain of integration $D$:}\nLet us integrate with respect to $x$ first and then w.r.t. $y$; that is, the outside integral is w.r.t. $y$. The sketch shows that $y$ ranges from $y=-1$ to $y=3$. Note that the right $x$ boundary is $x=+\\sqrt{y+1}$ for any $y\\in[-1,3]$. However, for the left $x$ boundary, we have to distinguish two cases: $x=-\\sqrt{y+1}$ for any $y\\in[-1,0]$, and $y=x+1 \\: \\leftrightarrow \\: x=y-1$ for any $y\\in[0,3]$. We therefore split $D$ along $y=0$ to obtain\n\\begin{equation*}\n\\begin{split}\nI & = \\iint_{D_-} xy + 2 \\: \\d A + \\iint_{D_+} xy + 2 \\: \\d A \\\\\n& = \\itgr{-1}{0}{\\itgr{-\\sqrt{y+1}}{+\\sqrt{y+1}}{xy+2}{x}}{y}\n  + \\itgr{0}{3}{\\itgr{y-1}{+\\sqrt{y+1}}{xy+2}{x}}{y} \\\\\n& = \\itgr{-1}{0}{\\left( \\left. \\frac{x^2y}{2}+2x \\right|_{-\\sqrt{y+1}}^{+\\sqrt{y+1}} \\right)}{y}\n  + \\itgr{0}{3}{\\left( \\left. \\frac{x^2y}{2}+2x \\right|_{y-1}^{\\sqrt{y+1}} \\right)}{y} \\\\\n& = \\itgr{-1}{0}{\\frac{(y+1)y}{2}+2\\sqrt{y+1}-\\frac{(y+1)y}{2}+2\\sqrt{y+1}}{y} \\\\  \n  & \\qquad \\qquad \\qquad \n  + \\itgr{0}{3}{\\frac{(y+1)y}{2}+2\\sqrt{y+1}-\\frac{(y-1)^2y}{2}-2y+2}{y} \\\\\n& = \\itgr{-1}{0}{4\\sqrt{y+1}}{y} + \\itgr{0}{3}{\\frac{-y^3+3y^2-4y+4}{2}+2\\sqrt{y+1}}{y} \\\\\n& = \\frac83 \\left( \\left. (y+1)^{\\rfrac32} \\right|_{-1}^{0} \\right)\n\t+ \\frac12 \\left( \\left. -\\frac{y^4}{4}+\\frac{3y^3}{3} \n\t\t-\\frac{4y^2}{2} + 4y \\right|_0^3 \\right)\n\t+ \\frac43\\left( \\left. (y+1)^{\\rfrac32} \\right|_0^3 \\right) \\\\\n& = \\left(\\frac83-0\\right) + \\frac12\\left( -\\frac{3^4}{4}+3^3-2 \\cdot 3^2+4 \\cdot 3- 0\\right) \n    +\\frac43\\left( 4^{\\rfrac32}-1 \\right) \\\\\n& = \\frac{8}{3} + \\frac{3}{8} + \\frac{28}{3} = \\frac{99}{8}.\n\\end{split}\n\\end{equation*}\n\t\\item\nFor $D = [0,2]\\times[0,1]$, find\n\\[I = \\iint_D \\abs{(x+y)^2-1} \\: \\d A. \\]\n{\\it Sol.:} Let $f(x,y)=(x+y)^2-1$. In order to integrate its \\emph{absolute value} over $D$, one first has to split $D$ into the subset $D_+$ on which $f$ is positive and the subset $D_-$ where it is negative, and then use the definition of the absolute value,\n\\[ \\abs{f} = \\begin{cases}\n\\phantom{-}f,& \\quad \\text{when~} f\\geq0, \\\\\n-f,& \\quad \\text{when~} f<0. \n\\end{cases} \\]\nThe boundary between these subsets is the level set $f=0$:\n\\[ (x+y)^2-1=0 \\quad \\Longrightarrow \\quad \\begin{cases}\ny_1&=1-x, \\\\\ny_2&=-1-x,\n\\end{cases} \\]\nbut only $y_1$ intersects $D$. This gives\n\\begin{equation*}\n\\begin{split}\nI &= \\iint_{D_-}-\\left[(x+y)^2-1\\right]\\:\\d A + \\iint_{D_+}+\\left[(x+y)^2-1\\right]\\:\\d A \\\\\n&= \\itgr{0}{1}{\\itgr{0}{1-y}{1-(x+y)^2}{x}}{y}+\\itgr{0}{1}{\\itgr{1-y}{2}{(x+y)^2-1}{x}}{y} \\\\\n&= \\itgr{0}{1}{\\left(\\left.x-\\frac{(x+y)^3}{3}\\right|_0^{1-y}\\right)}{y}\n\t+\\itgr{0}{1}{\\left(\\left.\\frac{(x+y)^3}{3}-x\\right|_{1-y}^2\\right)}{y} \\\\\n&= \\itgr{0}{1}{1-y-\\frac{1^3}{3}-0+\\frac{y^3}{3}+\\frac{(2+y)^3}{3}-2-\\frac{1^3}{3}+1-y}{y} \\\\\n&= \\itgr{0}{1}{-\\frac{2}{3}-2y+\\frac{y^3}{3}+\\frac{(2+y)^3}{3}}{y}=\\dots=\\frac{23}{6}.\n\\end{split}\n\\end{equation*}\nNote that you do not need to multiply out $\\rfrac{(2+y)^3}{3}$ to integrate it: similar to the integration of $(x+y)^2$ earlier in the computation, its antiderivative is $\\rfrac{(2+y)^4}{4 \\cdot 3}$ -- check using differentiation in case you have doubts!\n\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Complete the computation in~\\ref{expl:mult_int_1}. Also re-do example \\ref{expl:mult_int_2} (i), now integrating the other way around: first w.r.t. $y$ and then w.r.t. $x$ -- this is a very important exercise, as it provides crucial insight on how to best choose the order of integration.\n\t\\item Using integration, find the volume of the pyramid with base $[-2,2]\\times[-2,2]$ and height\\footnote{The pyramid is quite symmetric -- this allows to consider a sub-domain $S$ of the base and later multiply the volume that is sitting on top of it by a suitable factor. Choose $S$ so that the walls of the pyramid do not have any edges over it -- i.e. the restriction of the shell to $S$ is a plane!} $h=3$. Compare your result to the volume obtained with geometry formulas.\n\t\\item Let $f(x)$ be continuous on $[0,1]$ with\n\t\\[ \\itgr{0}{1}{f(x)}{x} = \\alpha. \\]\n\tFind\\footnote{Sketch the domain and the smallest rectangle that contains it, and argue that the integrand $f(x) \\cdot f(y)$ integrates to $2I$ over the rectangle.}\n\t\\[ I = \\itgr{0}{1}{\\itgr{x}{1}{f(x) \\cdot f(y)}{y}}{x}. \\]\n\\end{enumerate}\n\\end{exercise}\n\n\\section{Change of Variables and Integration in Polar Coordinates}\n\n\\begin{remark}\n\\begin{enumerate}[(i)]\n\t\\item The theory and computations in this section require familiarity with polar coordinates. You can review the material from the foundations module MTH1000 to refresh your memory on that.\n\t\\item The next theorem states a change-of-variables formula for two-dimensional integrals, and it is very similar to theorem~\\ref{thm:subst}. It is first stated in full generality, (i), and then for the special case when the transformation of variables is that from polar coordinates to Cartesian coordinates, (ii). The derivation of (ii) from (i) is given as an exercise, but both this derivation and (i) itself are not examinable. You do have to be able to integrate in polar coordinates though, i.e., you do have to know (ii).\n\t\\item Suppose we need to find the volume between the paraboloid $z=f(x,y)=x^2+y^2$ and the disk $D= \\{x^2+y^2 \\leq a^2\\}$ in the $xy$-plane. Note that both the function and the domain of integration are simpler in polar coordinates, $(x,y)=(r\\cos\\theta,r\\sin\\theta)$:\n\t\\[ f(x,y) = x^2+y^2=(r\\cos\\theta)^2+(r\\sin\\theta)^2 \n\t\t= r^2 \\left( \\cos^2\\theta + \\sin^2\\theta \\right) = r^2, \\]\n\tand $D$ corresponds to a rectangular domain in polar coordinates,\n\t\\[ (x,y) \\in D \\quad \\leftrightarrow \\quad (r,\\theta) \\in [0,a]\\times[0,2\\pi]. \\]\n\tYou know from the previous section that 2D integrals over rectangular domains are the easier ones, and the next theorem allows us to ``pull back'' the integrand $f$ and the domain of integration $D$ into that setting. \n\\end{enumerate}\n\\end{remark}\n\n\\begin{theorem}[Substitution in Higher Dimensions]\n\\label{thm:higher_dim_subst}\n\\begin{enumerate}[(i)]\n\t\\item Let a differentiable and injective (or ``one-to-one'') transformation\n\t\\begin{equation*}\n\t\\begin{array}{cccccc}\n\t\\Phi & : & U & \\rightarrow & \\mathbb{R}^2 & \\qquad(U\\subseteq\\mathbb{R}^2) \\\\\n\t     &   & (u,v) & \\mapsto & (x,y) &\n\t\\end{array}\n\t\\end{equation*}\n\tand a continuous function $f=f(x,y)$ be given. Then we have \n\t\\[ \\iint_{\\Phi(U)} f(x,y) \\: \\d x \\d y =\n\t\t\\iint_U f(\\Phi(u,v)) \\abs{\\det J_{\\phi}(u,v)} \\: \\d u \\d v, \\]\n\twhere $J_{\\Phi}$ is the \\emph{Jacobian} of the transformation $(u,v)\\leadsto(x,y)$,\n\t\\[ J_{\\Phi} = \\begin{bmatrix}\n\t\\rfrac{\\partial x}{\\partial u} & \\rfrac{\\partial x}{\\partial v} \\\\\n\t\\rfrac{\\partial y}{\\partial u} & \\rfrac{\\partial y}{\\partial v} \n\t\\end{bmatrix}. \\]\n\t\\item Consider the transformation\n\t\\begin{equation*}\n\t\\begin{array}{cccccc}\n\t\\Phi & : & \\mathbb{R}^+_0\\times[0,2\\pi] & \\rightarrow & \\mathbb{R}^2 & \\\\\n\t&   & (r,\\theta) & \\mapsto & (x,y) & = \\: (r\\cos\\theta,r\\sin\\theta)\n\t\\end{array}\n\t\\end{equation*}\n\tfrom polar coordinates to Cartesian coordinates, and let a continuous function $f=f(x,y)$ be given. Then we have for some set $U$ in the domain of $\\Phi$ that\n\t\\[ \\iint_{\\Phi(U)} f(x,y) \\: \\d x \\d y =\n\t\\iint_U f(r\\cos\\theta,r\\sin\\theta) \\: r \\: \\d r \\d \\theta. \\]\n\tThat is, the area element is\n\t\\[ \\d A = r \\: \\d r \\d \\theta \\]\n\tin polar coordinates.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{remark}\nYou may have noticed that the transformation $\\Phi:\\mathbb{R}^+_0\\times[0,2\\pi]\\rightarrow\\mathbb{R}^2$\nin (ii) above is not injective. For example, all points $(r,\\theta)=(0,\\theta)$ are mapped to $(x,y)=(0,0)$, and $(r,0),(r,2\\pi)$ are mapped to the same points $(x,y)=(r,0)$. This is not problematic, as the sets on which this non-injectiveness happens are of lower dimension and therefore do not contribute to the integral. Also, the choice of domain for the angle $\\theta$ is flexible and can more generally be taken as $[\\theta_0,\\theta_0+2\\pi]$, where $\\theta_0\\in\\mathbb{R}$, cf. example (ii) below.\n\\end{remark}\n\n\\begin{example}\n\\begin{enumerate}[(i)]\n\t\\item Find \n\t\\[ I = \\iint_D x^2+y^2 \\: \\d A, \\]\n\twhere $D$ is the disk of radius $a$, $D=\\{x^2+y^2 \\leq a^2\\}$. \\\\\n\t{\\it Sol.:}\n\tThis is the integral from the remark at the beginning of this section. We have\n\t\\[ f(r\\cos\\theta,r\\sin\\theta) = r^2 \\]\n\tand $D=\\Phi(U)$, where\n\t\\[ U = [0,a]\\times[0,2\\pi] \\]\n\tand $\\Phi$ is the transformation from polar to Cartesian coordinates. This gives\n\t\\[  I = \\itgr{0}{2\\pi}{\\itgr{0}{a}{r^2 \\cdot r}{r}}{\\theta}\n\t\t  = \\itgr{0}{2\\pi}{\\left( \\left. \\frac{r^4}{4}\\right|_0^a \\right)}{\\theta}\n\t\t  = \\frac{a^4\\pi}{2}.\\]\n\tYou could now also carry out that integration in Cartesian coordinates $x,y$ -- as an additional exercise for the previous section and to convince yourself of the benefits of integrating in polar coordinates. Of course, not all 2D integrals are easier to solve in polar coordinates.\n\t\\item Let\n\t\\[ D = \\{ (x,y)\\in\\mathbb{R}^2 \\: \n\t\t\t\t\t| \\: x\\geq 0, \\, \\abs{y}\\leq x, \\, 9 \\leq x^2+y^2 \\leq 25 \\}, \\]\n\tand find $\\iint_D x \\: \\d A$. \\\\\n\t{\\it Sol.:}\n\tThe domain of integration is a segment of the ring with outer radius $r=5$ and inner radius $r=3$:\n\t\\figbox{Domain of integration $D$:}\n\tWe see that $r$ ranges from $3$ to $5$ and $\\theta$ from $-\\rfrac{\\pi}{4}$ to $\\rfrac{\\pi}{4}$ -- again, a rectangle! That is, for \n\t\\[ U = \\left[3,5\\right]\\times\\left[-\\frac{\\pi}{4},\\frac{\\pi}{4}\\right], \\]\n\twe have $D=\\Phi(U)$. This gives\n\t\\begin{equation*}\n\t\\begin{split}\n\\iint_D x \\: \\d A \n& = \\itgr{3}{5}{\\itgr{-\\rfrac{\\pi}{4}}{\\rfrac{\\pi}{4}}{r\\cos\\theta \\: r}{\\theta}}{r} \n = \\itgr{3}{5}{r^2\\itgr{-\\rfrac{\\pi}{4}}{\\rfrac{\\pi}{4}}{\\cos\\theta}{\\theta}}{r} \\\\\n& = \\itgr{3}{5}{r^2\\left(\\left.\\sin\\theta\\right|_{-\\rfrac{\\pi}{4}}^{\\rfrac{\\pi}{4}}\\right)}{r}\n = \\sqrt{2}\\itgr{3}{5}{r^2}{r} = \\sqrt{2}\\cdot\\frac{98}{3} \\approx 46.198.\n\t\\end{split}\n\t\\end{equation*}\n\tThis result, $46.2$, has a physical meaning -- compare to the application in the introduction to this chapter to see what it is\\footnote{If you divide that number by $\\iint_D 1 \\: \\d A$, the result will help you balance a cut-out of $D$ on a single point.}. Note that integration in Cartesian coordinates would have been more laborious, as one would have to split up $D$ into at least three pieces\\footnote{E.g., letting $y$ be the outer integral: there are three different sets of formulas for the $x$ boundaries.}. \n\t\\item Find the area $A$ enclosed by one loop of the four-leaved rose $r=\\cos(2\\theta)$.\\\\\n\t{\\it Sol.:} Here, a curve in the $xy$-plane is not given by an explicit (e.g. $y=x^2$) or implicit (e.g. $x^2+y^2=1$) formula in $x$ and $y$, but via an equation in polar coordinates. Those are \\emph{polar curves}. For example, $r=1$ is the unit circle centred at the origin, and $\\theta = \\rfrac{\\pi}{3}$ describes the ray that leaves the origin at an angle of $60^{\\circ}$. You should be able to find lots of interesting material on polar curves online. You can also enter commands like \\texttt{polar plot r=cos(2t)} into WolframAlpha. To find the area within one loop of the four-leaved rose,\n\t\\figbox{The four-leaved rose:}\n\twe integrate the function $f=1$ over $\\theta\\in[\\rfrac{\\pi}{4},\\rfrac{3\\pi}{4}]$ and $r\\in[0,\\cos2\\theta]$:\n\t\\begin{equation*}\n\t\\begin{split}\n\tA & = \\iint_D 1 \\: \\d A \n\t= \\itgr{\\rfrac{\\pi}{4}}{\\rfrac{3\\pi}{4}}{\\itgr{0}{\\cos 2\\theta}{r}{r}}{\\theta}\n\t= \\frac12 \\itgr{\\rfrac{\\pi}{4}}{\\rfrac{3\\pi}{4}}{\\cos^2(2\\theta)}{\\theta} \\\\\n\t& = \\frac14 \\itgr{\\rfrac{\\pi}{4}}{\\rfrac{3\\pi}{4}}{1+\\cos(4\\theta)}{\\theta} \n\t= \\frac{\\pi}{8} + \\frac{1}{16} \\left( \\left. \\sin(4\\theta)\n\t\t\t\t\\right|_{\\rfrac{\\pi}{4}}^{\\rfrac{3\\pi}{4}} \\right) = \\frac{\\pi}{8}.\t\n\t\\end{split}\n\t\\end{equation*}\n\\end{enumerate}\n\\end{example}\n\n\\begin{example}\nFind the volume within the ball of radius $R$ in $\\mathbb{R}^3$ (centred at the origin).\\\\\n{\\it Sol.:} Denote that ball by $B_R$,\n\\[ B_R = \\{ (x,y,z)\\in\\mathbb{R}^3 \\: | \\: x^2+y^2+z^2 \\leq R^2 \\} \n\t\t\t\t\t\t\t\t\t\\subseteq \\mathbb{R}^3. \\]\nBesides using a basic geometry formula, there are two approaches to finding the volume of $B_R$: (1) compute the volume of the upper hemisphere by integrating the 2D function whose graph forms the surface of the upper hemisphere over the the disk $D_R$ of radius $R$, and then multiply by $2$; or (2) find the integral of the 3D function $f(x,y,z)=1$ over $B_R$. In maths terms:\n\\begin{equation*}\n\\begin{split}\n(1) & \\qquad V = 2\\iint_{D_R} \\sqrt{R^2-x^2-y^2} \\: \\d A,\\\\\n(2) & \\qquad V = \\iiint_{B_R} 1 \\: \\d V.\n\\end{split}\n\\end{equation*}\n(1) can be carried out nicely in polar coordinates, but we will take the second approach now, as it is a good opportunity to apply the general form of theorem~\\ref{thm:higher_dim_subst}.\n\nFor this, we need \\emph{spherical polar coordinates}, i.e. a form of polar coordinates for $\\mathbb{R}^3$. You do not need to know this transformation for the MTH1002 exam, but it is good to preview it for your second year in the programme:\n\\begin{equation*}\n\\begin{array}{cccccc}\n\\Phi & : & \\mathbb{R}^+_0\\times[0,2\\pi]\\times[0,\\pi] & \\rightarrow & \\mathbb{R}^3 & \\\\\n&   & \\begin{pmatrix} r \\\\ \\phi \\\\ \\theta \\end{pmatrix} \n& \\mapsto & \\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix}  \n& = \\begin{pmatrix} r\\cos\\phi\\sin\\theta \\\\ r\\sin\\phi\\sin\\theta \\\\ r\\cos\\theta \\end{pmatrix} \n\\end{array}\n\\end{equation*}\nFor example, for fixed $r=r_0$, the points $(x,y,z)$ will traverse the surface of the ball of radius $r_0$, with $\\theta = 0$ corresponding to the north pole, $\\theta = \\pi$ to the south pole, and $\\theta = \\rfrac{\\pi}{2}$ to the equator.\n\\figbox{Spherical polar coordinates in $\\mathbb{R}^3$:}\nThe Jacobian for this transformation is\n\\[ J_\\Phi = \\begin{bmatrix}\n\\cos\\phi\\sin\\theta & -r\\sin\\phi\\sin\\theta & r\\cos\\phi\\cos\\theta \\\\\n\\sin\\phi\\sin\\theta &  r\\cos\\phi\\sin\\theta & r\\sin\\phi\\cos\\theta \\\\\n\\cos\\theta & 0 & -r\\sin\\theta  \n\\end{bmatrix}, \\]\nwhose determinant has an absolute value of $\\abs{\\det J_\\Phi} = r^2\\sin\\theta$. Hence the \\emph{volume element} (the 3D version of the area element) is\n\\[ \\d V = r^2\\sin\\theta \\: \\d r \\d\\phi\\d\\theta. \\]\nThis allows to find the volume of the ball of radius $R$ with 3D integration:\n\\begin{equation*}\n\\begin{split}\nV & = \\iiint_{B_R} 1 \\: \\d V \\\\\n& = \\itgr{0}{\\pi}{\\itgr{0}{2\\pi}{\\itgr{0}{R}{r^2\\sin\\theta}{r}}{\\phi}}{\\theta} \\\\\n& = \\itgr{0}{\\pi}{\\itgr{0}{2\\pi}\n\t\t{\\sin\\theta\\left(\\left.\\frac{r^3}{3}\\right|_0^R\\right)}{\\phi}}{\\theta} \\\\\n& = \\frac{R^3}{3}\\itgr{0}{\\pi}{\\sin\\theta\\itgr{0}{2\\pi}{1}{\\phi}}{\\theta} \\\\\n& = \\frac{2\\pi R^3}{3}\\itgr{0}{\\pi}{\\sin\\theta}{\\theta}\n= \\frac{2\\pi R^3}{3}\\left( \\left. -\\cos\\theta\\right|_0^\\pi \\right) = \\frac{4\\pi}{3}R^3.\n\\end{split}\n\\end{equation*}\n\\end{example}\n\n\\begin{application}[\\texttt{One more application of integration}]\n\\texttt{\\ldots}\n\\end{application}\n\n\\begin{exercise}\n\\begin{enumerate}[(i)]\n\t\\item Review polar coordinates (not covered here) -- e.g., practise converting to and from polar coordinates, look up polar curves online.\n\t\\item Evaluate\n\t\\[ \\iint_D \\abs{\\sin\\left( \\sqrt{x^2+y^2} \\right)} \\: \\d A, \\]\n\twhere $D$ is the upper half of the disk of radius\\footnote{The value you obtained is correct if it rounds to $39.478$.} $2\\pi$,\n\t\\[ D = \\{ y \\geq 0, \\, x^2 + y^2 \\leq (2\\pi)^2 \\}. \\]\n\t\\item In theorem~\\ref{thm:higher_dim_subst}, derive the special case (ii) from the general formula (i).\n\t\\item Evaluate the integral\n\t\\[ \\iiint_V r \\: \\d V, \\]\n\twhere $V$ is the volume between the the two spheres of radius $1$ and $2$ in $\\mathbb{R}^3$ (both centred at the origin)\\footnote{You will need the general version of theorem~\\ref{thm:higher_dim_subst} and ``spherical polar coordinates'' for this.\n\t\t\n\tAnswer: The value you obtained is correct if it rounds to $47.124$.}.\n\\end{enumerate}\n\\end{exercise}", "meta": {"hexsha": "bbfffa79d5447bbbebe7d324ad75dbc5f87ac5c3", "size": 69529, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/ch_i.tex", "max_stars_repo_name": "pasc85/MathematicalMethods", "max_stars_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Chapters/ch_i.tex", "max_issues_repo_name": "pasc85/MathematicalMethods", "max_issues_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-11-26T21:39:11.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-28T11:35:22.000Z", "max_forks_repo_path": "Chapters/ch_i.tex", "max_forks_repo_name": "pasc85/MathematicalMethods", "max_forks_repo_head_hexsha": "1dd151a72deebbcb0da09955d897bbad1691597b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 56.162358643, "max_line_length": 656, "alphanum_fraction": 0.6401357707, "num_tokens": 26268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.9005297821135385, "lm_q1q2_score": 0.7946525743091776}}
{"text": "\\section{Attenuation}\nAssociated external model: \\texttt{attenuate.py}\n\nAttenuation evaluation for quantity of interest $u$ with input parameters $Y=[y_1,\\ldots,y_N]$:\n\\begin{equation}\nu(Y) = \\prod_{n=1}^N e^{-y_n/N}.\n\\end{equation}\nThis is the solution to the exit strength of a monodirectional, single-energy beam of neutral particles\nincident on a unit length material divided into $N$ sections with independently-varying absorption cross\nsections.  This test is useful for its analytic statistical moments as well as difficulty to represent\nexactly using polynomial representations.\n\n\\subsection{Uniform}\nLet all $y_n$ be uniformly distributed between 0 and 1.  The first two statistical moments are:\n\\subsubsection{mean}\n\\begin{align}\n\\expv{u(Y)} &=\\int_{0}^1 dY \\rho(Y)u(Y),\\notag \\\\\n  &=\\int_{0}^1 dy_1\\cdots\\int_{0}^1 dy_N \\prod_{n=1}^N e^{-y_n/N},\\notag \\\\\n  &=\\left[ \\int_{0}^1 dy e^{-y/N}\\right]^N,\\\\\n  &=\\left[\\left(-Ne^{-y/N}\\right)\\bigg|_0^1\\right]^N,\\notag \\\\\n  &=\\left[N\\left(1-e^{-1/N}\\right)\\right]^N. \\notag\n\\end{align}\n\\subsubsection{variance}\n\\begin{align}\n\\expv{u(Y)^2} &= \\int_{0}^1 dY \\rho(Y)u(Y), \\notag \\\\\n  &=\\int_{0}^1 dy_1\\cdots\\int_{0}^1 dy_N \\frac{1}{1^N} \\left(\\prod_{n=1}^N e^{-y_n/N}\\right)^2,\\notag \\\\\n  &=\\left[\\left(\\int_{0}^1 dy\\ e^{-2y/N} \\right)\\right]^N,\\notag \\\\\n  &=\\left[\\left(\\frac{N}{2}e^{-2y/N} \\right)\\bigg|_{0}^1 \\right]^N, \\\\\n  &=\\left[\\frac{N}{2}\\left(1-e^{-2/N}\\right)\\right]^N.\\notag \\\\\n\\text{var}[u(Y)] &= \\expv{u(Y)^2}-\\expv{u(Y)}^2, \\notag \\\\\n  &= \\left[\\frac{N}{2}\\left(1-e^{-2/N}\\right)\\right]^N - \\left[N\\left(1-e^{-1/N}\\right)\\right]^{2N}.\n\\end{align}\n\\subsubsection{numeric values}\nSome numeric values for the mean and variance are listed below for several input cardinalities $N$.\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c|c|c}\n$N$ & mean & variance \\\\ \\hline\n2 & 0.61927248698470190 & 0.01607798775751018 \\\\\n4 & 0.61287838657652779 & 0.00787849640356994 \\\\\n6 & 0.61075635579491642 & 0.00520852933409887\n\\end{tabular}\n\\end{table}\n\n\\subsection{Multivariate Normal}\nLet $Y$ be $N$-dimensional, and have a multivariate normal distribution:\n\\begin{equation}\nY \\thicksim N(\\mu,\\Sigma)\n\\end{equation}\nwith $N$-dimensional mean vector $\\mu=[\\mu_{y_1},\\mu_{y_2},\\ldots,\\mu_{y_N}]$, and $N X N$ covariance matrix:\n\\begin{equation}\n\\Sigma = [Cov[y_i,y_j]],i = 1,2,\\ldots,N; j = 1,2,\\ldots,N\n\\end{equation}\n\nTo be simplicity, we assume there are no correlations between the input parameters. Then, the covariance matrix can be written\nas:\n\\begin{equation}\n\\Sigma =\n\\begin{pmatrix}\n\\sigma_{y_1}^2 & 0 &\\ldots & 0 \\\\\n0 & \\sigma_{y_2}^2 &\\ldots & 0 \\\\\n\\vdots &\\vdots &\\ddots & \\vdots \\\\\n0 & 0 & \\ldots & \\sigma_{y_N}^2\\\\\n\\end{pmatrix}\n\\end{equation}\nwhere $\\sigma_{y_i}^2 = Cov[y_i,y_i]$, for $i = 1,2,\\ldots,N$. Based on this assumption, the first two statistical moments are:\n\\subsubsection{mean}\n\\begin{align}\n\\expv{u(Y)} &=\\int_{-\\infty}^\\infty dY \\rho(Y)u(Y) \\notag \\\\\n  &=\\int_{-\\infty}^\\infty dy_1 (1/\\sqrt{2 \\pi \\sigma_{y_1}}e^{-\\frac{(y_1-\\mu_{y_1})^2}{2\\sigma_{y_1}^2}})\\cdots\\int_{-\\infty}^\\infty dy_N  (1/\\sqrt{2 \\pi \\sigma_{y_N}}e^{-\\frac{(y_N-\\mu_{y_N})^2}{2\\sigma_{y_N}^2}})\\prod_{n=1}^N e^{-y_n/N} \\\\\n  &=\\prod_{n=1}^N e^{\\frac{\\sigma_{y_i}^2}{2n^2}-\\frac{\\mu_{y_i}}{n}}. \\notag\n\\end{align}\n\\subsubsection{variance}\n\\begin{align}\n\\text{var}[u(Y)]=\\expv{(u(Y)-\\expv{u(Y)})^2} &= \\int_{-\\infty}^\\infty dY \\rho(Y)(u(Y)-\\expv{u(Y)})^2 \\notag \\\\\n  &=\\int_{-\\infty}^\\infty dy_1 (1/\\sqrt{2 \\pi \\sigma_{y_1}}e^{-\\frac{(y_1-\\mu_{y_1})^2}{2\\sigma_{y_1}^2}})\\\\\n  &\\cdots\\int_{-\\infty}^\\infty dy_N  (1/\\sqrt{2 \\pi \\sigma_{y_N}}e^{-\\frac{(y_N-\\mu_{y_N})^2}{2\\sigma_{y_N}^2}})(\\prod_{n=1}^N e^{-y_n/N}-\\expv{u(Y)})^2 \\notag\\\\\n  &=\\prod_{n=1}^N e^{\\frac{2 \\sigma_{y_i}^2}{n^2}-\\frac{2\\mu_{y_i}}{n}}. \\notag\n\\end{align}\n\\subsubsection{numeric values}\nFor example, for given mean $\\mu = [0.5, -0.4, 0.3, -0.2, 0.1]$, and covariance\n\\begin{equation}\n\\Sigma =\n\\begin{pmatrix}\n0.64 & 0 & 0 & 0 & 0 \\\\\n0 & 0.49 & 0 & 0 & 0 \\\\\n0 & 0 & 0.09 & 0 & 0 \\\\\n0 & 0 & 0 & 0.16 & 0 \\\\\n0 & 0 & 0 & 0 & 0.25 \\\\\n\\end{pmatrix}\n\\end{equation}\nThe mean and variance can computed using previous equation, and the results are:\n\\begin{equation}\n\\expv{u(Y)} = 0.97297197488624509\n\\end{equation}\n\\begin{equation}\n\\text{var}{u(Y)} = 0.063779804051749989\n\\end{equation}\n\n\\subsection{Changing lower, upper bounds}\nA parametric study can be made by changing the lower and upper bounds of the material opacities.\n\nThe objective is to determine the effects on the exit strength $u$ of a beam impinging on a\nunit-length material subdivided into two materials with opacities $y_1, y_2$.  The range of values for\nthese opacities varies from lower bound $y_\\ell$ to higher bound $y_h$, and the bounds are always\nthe same for both opacities.\n\nWe consider evaluating the lower and upper bounds\non a grid, and determine the expected values for the opacity means and exit strength.\n\nThe analytic values for the exit strength expected value depends on the lower and upper bound\nas follows:\n\\begin{align}\n  \\bar u(y_1,y_2) &= \\int_{y_\\ell}^{y_h}\\int_{y_\\ell}^{y_h} \\left(\\frac{1}{y_h-y_\\ell}\\right)^2\n    e^{-(y_1+y_2)/2} dy_1 dy_2, \\\\\n    &= \\frac{4e^{-y_h-y_\\ell}\\left(e^{y_h/2}-e^{y_\\ell/2}\\right)^2}{(y_h-y_\\ell)^2}.\n\\end{align}\n\nNumerically, the following grid points result in the following expected values:\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{c c|c|c}\n$y_\\ell$ & $y_h$ & $\\bar y_1=\\bar y_2$ & $\\bar u$ \\\\ \\hline\n0.00 & 0.50 & 0.250 & 0.782865 \\\\\n0.00 & 0.75 & 0.375 & 0.695381 \\\\\n0.00 & 1.00 & 0.500 & 0.619272 \\\\\n0.25 & 0.50 & 0.375 & 0.688185 \\\\\n0.25 & 0.75 & 0.500 & 0.609696 \\\\\n0.25 & 1.00 & 0.625 & 0.541564 \\\\\n0.50 & 0.50 & 0.500 & 0.606531 \\\\\n0.50 & 0.75 & 0.625 & 0.535959 \\\\\n0.50 & 1.00 & 0.750 & 0.474832\n\\end{tabular}\n\\end{table}\n\n", "meta": {"hexsha": "b406a19c294fd10e52820dcacbb005baa61528e1", "size": 5769, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/attenuate.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/attenuate.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/attenuate.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.1094890511, "max_line_length": 242, "alphanum_fraction": 0.6566129312, "num_tokens": 2333, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7945797368213203}}
{"text": "\\subsection{An illustrate of deconvolution}\n\nHere the prolongation operator is also corresponded to some\nwell-know operators in CNN which is often called as: deconvolution, transposed convolution or even up-pooling.\n\n\n\\subsubsection{Recall convolution in 1D}\nSuppose the input data is denoted as $X$, the kernel for the convolution layer is $K_1$. We can obtain the encoded output $Y$ by convolution as\n\\begin{align}\n    K_1 \\ast X  = Y.\n\\end{align}\n\nIf we rewrite the convolution in the form of matrix multiplication, it becomes\n\\begin{align}\n   Y = K_1 \\ast X = T \\cdot X.\n\\end{align}\nFor the purpose of illustration, we take $K_1 \\in \\mathbb{R}^4$, $X \\in \\mathbb{R}^8$ with the stride  2 without padding. Then we have $Y \\in \\mathbb{R}^5$ and $T \\in \\mathbb{R}^{5*8}$.\n\nSuppose $K_1=(k_1, k_2, k_3, k_4)$ and $X=(x_1, x_2, ..., x_8)$. The corresponding coefficient matrix $T$ can be represented as \n\\begin{align}\n   T = \\mathcal S \\cdot \\tilde{T} &= \n%  \\begin{bmatrix}\n%    (1-2r)  & -r      & 0       & \\cdots  & 0  \\\\\n%    -r      & (1-2r)  & -r      & \\ddots  & \\vdots   \\\\\n%     0      &  \\ddots & \\ddots  & \\ddots  & 0  \\\\\n%    \\vdots  &         & -r      & (1-2r)  & -r  \\\\\n%     0      & \\cdots  & 0       & -r      & (1-2r)\n%  \\end{bmatrix}\n\\left(\n  \\begin{array}{ccccccccc}\n     1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n  \\end{array}\n\\right)_{5*9}\n\\left(\n  \\begin{array}{cccccccc}\n     k_3 & k_4 & 0 & 0 & 0 & 0 & 0 & 0  \\\\\n     k_2 & k_3 & k_4 & 0 & 0 & 0 & 0 &  0 \\\\\n     k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0 & 0  \\\\\n     0 & k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0  \\\\\n     0 & 0 & k_1 & k_2 & k_3 & k_4 & 0 & 0  \\\\\n     0 & 0 & 0 & k_1 & k_2 & k_3 & k_4 & 0  \\\\\n     0 & 0 & 0 & 0 & k_1 & k_2 & k_3 & k_4  \\\\\n     0 & 0 & 0 & 0 & 0 & k_1 & k_2 & k_3   \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & k_1 & k_2  \\\\\n  \\end{array}\n\\right)_{9*8}\\\\ \\notag \n&= \n\\left(\n  \\begin{array}{cccccccc}\n     k_3 & k_4 & 0 & 0 & 0 & 0 & 0 & 0  \\\\\n     k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0 &  0 \\\\\n     0 & 0 & k_1 & k_2 & k_3 & k_4 & 0 &  0  \\\\\n     0 & 0 & 0 &0 & k_1 & k_2 & k_3 & k_4   \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & k_1 & k_2    \\\\\n  \\end{array}\n\\right)_{5*8}.\n\\end{align}\nHere $\\mathcal S$ denote the operation of stride being 2 and $\\tilde{T}$ is the standard convolution operation.\n\nThe procedure can be illustrated as below.\n\\begin{figure}[htbp]\n\\centering{\n\\includegraphics[width=.6\\textwidth]{conv.jpeg}}\n\\caption{Depiction of usual convolution process with 1-d input}\n\\end{figure}\n\n\n\\subsubsection{Deconvolution in 1D as example}\nSuppose the data is denoted as $Y$ and the wanted output as $\\tilde{X}$. \nIn TensorFlow, $\\tilde{X}$ is obtained from $Y$ with the function tf.nn.conv3d$\\_$transpose. \nSimilar case can be found in PyTorch as: torch.nn.ConvTranspose2d.\n\nFor example, here is what tf.nn.conv3d$\\_$transpose does.\nIt construct another CNN with a convolution layer only, which takes $Y$ as \nthe output and $\\tilde{X}$ as the input. Then  the input is updated with the \nbackpropagation by the function gen$\\_$nn$\\_$ops.conv3d$\\_$backprop$\\_$input$\\_$v2. \n%This function does the following operation.\n\nIf we rewrite the deconvolution in the form of matrix multiplication, it becomes\n\\begin{align}\n   \\tilde{X} = K_2 \\ast Y = T^\\top \\cdot Y.\n\\end{align}\n\n%Suppose $Y$ can be obtained by convolution as\n%\\begin{align}\n%    K_2 \\ast \\tilde{X}  = Y.\n%\\end{align}\n%Then with the backpropagation, the input and the parameters can be updated as\n%\\begin{align}\n%   dY \\ast(K_2)^\\top  = d\\tilde{X},   \\\\\n%   dY \\ast \\tilde{X}      = dK_2.\n%\\end{align}\n%After $\\tilde{X}$ is updated, the $L^2$ loss function is used to compute the difference between $X$ and $\\tilde{X}$. \n\nWith the same notation as above, the corresponding coefficient matrix $T^\\top$ can be represented as \n\\begin{align}\n   T^\\top = \\tilde{T}^\\top\\cdot  \\mathcal S^\\top &= \n%  \\begin{bmatrix}\n%    (1-2r)  & -r      & 0       & \\cdots  & 0  \\\\\n%    -r      & (1-2r)  & -r      & \\ddots  & \\vdots   \\\\\n%     0      &  \\ddots & \\ddots  & \\ddots  & 0  \\\\\n%    \\vdots  &         & -r      & (1-2r)  & -r  \\\\\n%     0      & \\cdots  & 0       & -r      & (1-2r)\n%  \\end{bmatrix}\n\\left(\n  \\begin{array}{ccccccccc}\n     k_3 & k_2 & k_1 & 0 & 0 & 0 & 0 & 0  & 0\\\\\n     k_4 & k_3 & k_2 & k_1 & 0 & 0 & 0 &  0 & 0\\\\\n     0 & k_4 & k_3 & k_2 & k_1 & 0 & 0 & 0 & 0\\\\\n     0 & 0 & k_4 & k_3 & k_2 & k_1 & 0 & 0  & 0\\\\\n     0 & 0 & 0 & k_4 & k_3 & k_2 & k_1 & 0  & 0\\\\\n     0 & 0 & 0 & 0 & k_4 & k_3 & k_2 & k_1  & 0\\\\\n     0 & 0 & 0 & 0 & 0 & k_4 & k_3 & k_2 & k_1  \\\\\n     0 & 0 & 0 & 0 & 0 & 0  & k_4 & k_3 & k_2   \\\\\n  \\end{array}\n\\right)_{8*9}\n\\left(\n  \\begin{array}{ccccc}\n     1 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 1 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 1 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 1 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 1  \\\\\n  \\end{array}\n\\right)_{9*5}\n\\\\ \\notag \n&= \n\\left(\n  \\begin{array}{ccccc}\n     k_3 & k_1 & 0 & 0 & 0   \\\\\n     k_4 & k_2 & 0 & 0 & 0   \\\\\n     0 & k_3 & k_1 & 0 & 0  \\\\     \n     0 & k_4 & k_2 & 0 & 0  \\\\\n     0 & 0 & k_3 & k_1 & 0  \\\\\n     0 & 0 & k_4 & k_2 & 0  \\\\\n     0 & 0 & 0 & k_3 & k_1  \\\\\n     0 & 0 & 0 & k_4 & k_2  \\\\\n  \\end{array}\n\\right)_{8*5}.\n\\end{align}\nHere $\\mathcal S^\\top$ denote the operation of padding(adding zeros) and $\\tilde{T}$ is the standard deconvolution operation.\n\nThe procedure can be illustrated as below.\n\\begin{figure}[htbp]\n\\centering{\n\\includegraphics[width=.6\\textwidth]{deconv.jpeg}}\n\\caption{Deconvolution}\n\\end{figure}\n\n\\subsection{Some linear and nonlinear mappings and extractors}\nA data-feature map $A$ and feacture extractor $B$ can be either\nlinear or nonlinear.   The nonlinearity can be obtained from\nappropriate application of an activation function\n\\begin{equation}\n\\label{act}\n\\sigma: \\mathbb{R} \\to \\mathbb{R} .\n\\end{equation}\nIn this paper, we mainly consider a special activation function, known \nas the {\\it rectified linear unit} (ReLU), which is defined by\n\\begin{equation}\n\\label{relu}\n\\sigma(x)= {\\rm ReLU}(x) :=\\max(0,x), \\quad x\\in\\mathbb{R}. \n\\end{equation}\nBy applying the function to each component, we can extend this\n\\begin{equation}\n\\label{vector-act}\n\\sigma:\\mathbb R^{m\\times n\\times c}\\mapsto \\mathbb R^{m\\times n\\times c}.  \n\\end{equation}\n\n\nA linear data-feature mapping can simply given by a convolution as in \\eqref{con1}:\n\\begin{equation}\n\\label{linearA}\nA(f)=\\xi\\ast f\n\\end{equation}\nA nonlinear mapping can be given by compositions of convolution and\nactivation functions:\n\\begin{equation}\n\\label{nonlinearA}\nA=\\xi\\circ\\sigma\\circ\\eta ,\n\\end{equation}\n\nand \n\\begin{equation}\n\\label{extractor}\nB=\\sigma\\circ \\gamma \\circ\\sigma  .\n\\end{equation}\nHere $\\xi$, $\\eta$ and $\\gamma$ are all \nappropriate convolution mappings.\n\n\n\\subsection{An iterative feacture extraction scheme}\nOne key idea in this paper is that we use a simple iterative\nprocess to approximately solve \\eqref{Auf} using \\eqref{vBf}. Namely,\nfor $i=1:\\nu$\n\\begin{equation}\\label{eq:smoothB}\nu^{i} = u^{i-1} + B^{i}(f- A(u^{i-1})) \n\\end{equation}\nfor an appropriately chosen $u^0$.  We refer to \\cite{xu1992iterative}\nfor more discussion on iterative scheme in the form of \\eqref{eq:smoothB}.\n\n\n", "meta": {"hexsha": "46bd8a9909635fd1805d69ec0b20985f79ef1b61", "size": 7357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_Deconv.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_Deconv.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_Deconv.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.8672985782, "max_line_length": 185, "alphanum_fraction": 0.5801277695, "num_tokens": 3003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582612793112, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7945301805844385}}
{"text": "\\subsubsection{The $QR$ factorization and eigenvalues}\n\nThe $QR$ factorization of a matrix has a very useful application. It turns out that it can be used repeatedly to estimate the eigenvalues of a matrix. Consider the following procedure.\n\n\\begin{procedure}{Using the $QR$ factorization to estimate eigenvalues}{qr-eigenvalues}\nLet $A$ be an invertible matrix. Define the matrices $A_1, A_2, \\ldots$ as follows:\n\\begin{enumerate}\n\\item\n$A_1 = A$ factored as $A_1 = Q_1R_1$\n\\item\n$A_2 = R_1Q_1$ factored as $A_2 = Q_2R_2$\n\\item\n$A_3 = R_2Q_2$ factored as $A_3 = Q_3R_3$\n\\end{enumerate}\n\nContinue in this manner, where in general $A_k = Q_kR_k$ and $A_{k+1} = R_kQ_k$.\n\nThen it follows that this sequence of $A_i$ converges to an upper triangular matrix which is similar to $A$. Therefore the eigenvalues of $A$ can be approximated by the entries on the main diagonal of this upper triangular matrix.\n\\end{procedure}\n", "meta": {"hexsha": "156919bba85cb6f78bb68beba26cc3299dcd7a92", "size": 917, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityQRFactorizationEigenvalues.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/spectraltheoryOrthogonalityQRFactorizationEigenvalues.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/spectraltheoryOrthogonalityQRFactorizationEigenvalues.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.85, "max_line_length": 230, "alphanum_fraction": 0.7579062159, "num_tokens": 285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.794451226288668}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Determine the rank and nullity and find a basis of the column\n  space, row space, and null space of each of the following matrices.\n  \\begin{enumerate}\n  \\item\n    \\begin{equation*}\n      A = \\begin{mymatrix}{rrr}\n        1 & 3 & 2 \\\\\n        3 & 9 & 6 \\\\\n        1 & 3 & 2 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{rrrr}\n        1 & 3 & 0 & 2 \\\\\n        3 & 9 & 1 & 7 \\\\\n        1 & 3 & 1 & 3 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      C = \\begin{mymatrix}{rrr}\n        1 & 0 & 3 \\\\\n        3 & 1 & 10 \\\\\n        1 & 1 & 4 \\\\\n        1 & -1 & 2 \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      D = \\begin{mymatrix}{rrrrr}\n        0 & 0 & -1 & 0 & 1 \\\\\n        1 & 2 & 3 & -2 & -18 \\\\\n        1 & 2 & 2 & -1 & -11 \\\\\n        -1 & -2 & -2 & 1 & 11\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      E = \\begin{mymatrix}{rrrr}\n        1 & 0 & 3 & 0 \\\\\n        3 & 1 & 10 & 0 \\\\\n        -1 & 1 & -2 & 1 \\\\\n        1 & -1 & 2 & -2\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Find $\\nullspace(A)$ for the following matrices.\n  \\begin{enumerate}\n  \\item\n    \\begin{equation*}\n      A = \\begin{mymatrix}{rr}\n        2 & 3 \\\\\n        4 & 6\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      A = \\begin{mymatrix}{rrr}\n        1 & 0 & -1 \\\\\n        -1 & 1 & 3 \\\\\n        3 & 2 & 1\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      A = \\begin{mymatrix}{rrr}\n        2 & 4 & 0 \\\\\n        3 & 6 & -2 \\\\\n        1 & 2 & -2\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      A = \\begin{mymatrix}{rrrr}\n        2 & -1 & 3 & 5 \\\\\n        2 & 0 & 1 & 2 \\\\\n        6 & 4 & -5 & -6 \\\\\n        0 & 2 & -4 & -6\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_5$ of integers\n  modulo $5$ instead of real numbers (see Section~\\ref{sec:fields},\n  ``Fields'').  Determine the rank and nullity and find a basis of the\n  column space, row space, and null space of the following matrix over\n  $\\Z_5$.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2 & 4 & 1 \\\\\n      1 & 2 & 3 \\\\\n      3 & 1 & 2 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    Rank 2, nullity 1, basis of column space\n    $\\set{\\begin{mymatrix}{r}2\\\\1\\\\3\\end{mymatrix},\n    \\begin{mymatrix}{r}1\\\\3\\\\2\\end{mymatrix}}$, basis of row space\n    $\\set{\\mat{1,2,0}, \\mat{0,0,1}}$, basis of null space\n    $\\set{\\begin{mymatrix}{r}3\\\\1\\\\0\\end{mymatrix}}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that if $A$ is an $m\\times n$-matrix, then $\\nullspace(A)$\n  is a subspace of $\\R^n$.\n  \\begin{sol}\n    Clearly $\\vect{0}\\in\\nullspace(A)$, since $A\\vect{0}=\\vect{0}$.\n    If $\\vect{x},\\vect{y}\\in\\nullspace(A)$, then\n    $A(\\vect{x}+\\vect{y}) = A\\vect{x}+A\\vect{y} = \\vect{0}+\\vect{0} =\n    \\vect{0}$, and therefore\n    $\\vect{x}+\\vect{y}\\in\\nullspace(A)$. Similarly, if\n    $\\vect{x}\\in\\nullspace(A)$ and $k$ is a scalar, then\n    $A(k\\vect{x})=k(A\\vect{x})=k\\vect{0}=\\vect{0}$, so\n    $k\\vect{x}\\in\\nullspace(A)$. So $\\nullspace(A)$ contains\n    $\\vect{0}$, and is closed under addition and scalar\n    multiplication. It is therefore a subspace of $\\R^n$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:column-space-is-image}\n  Let $A$ be an $m\\times n$-matrix. Show that $\\col(A) =\n  \\set{A\\vect{u} \\mid \\vect{u}\\in\\R^n}$.\n  \\begin{sol}\n    Let\n    \\begin{equation*}\n      A = \\begin{mymatrix}{ccc}\n        a_{11} & \\cdots & a_{1n} \\\\\n        \\vdots & \\ddots & \\vdots \\\\\n        a_{m1} & \\cdots & a_{mn} \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    Since $\\col(A)$ is the span of the columns of $A$, we have\n    $\\vect{v}\\in\\col(A)$ if and only if there exists scalars\n    $u_1,\\ldots,u_n$ such that\n    \\begin{equation*}\n      \\vect{v}\n      = u_1 \\begin{mymatrix}{c} a_{11} \\\\ \\vdots \\\\ a_{m1} \\end{mymatrix}\n      + \\ldots\n      + u_n \\begin{mymatrix}{c} a_{1n} \\\\ \\vdots \\\\ a_{mn} \\end{mymatrix}.\n    \\end{equation*}\n    But this equation is equivalent to\n    \\begin{equation*}\n      \\vect{v} =\n      \\begin{mymatrix}{ccc}\n        a_{11} & \\cdots & a_{1n} \\\\\n        \\vdots & \\ddots & \\vdots \\\\\n        a_{m1} & \\cdots & a_{mn} \\\\\n      \\end{mymatrix}\n      \\begin{mymatrix}{c} u_1 \\\\ \\vdots \\\\ u_n \\end{mymatrix}\n      = A\\vect{u}.\n    \\end{equation*}\n    Therefore, $\\vect{v}\\in\\col(A)$ if and only if $\\vect{v}$ is of\n    the form $A\\vect{u}$, for some $\\vect{u}\\in\\R^n$. In other words,\n    $\\col(A) = \\set{A\\vect{u}\\mid\\vect{u}\\in\\R^n}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that $\\rank(A)=\\rank(A^T)$.\n  \\begin{sol}\n    The row space of $A$ is the same as the column space of $A^T$\n    (except that it uses row vectors instead of column\n    vectors). Therefore, $\\rank(A) = \\dim(\\row(A)) = \\dim(\\col(A^T)) =\n    \\rank(A^T)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  For invertible matrices $B$ and $C$ of appropriate size, show that\n  $\\rank(A) = \\rank(BA) = \\rank(AC)$.\n  \\begin{sol}\n    From the theory of elementary matrices, we know that $B$ can be\n    written as a product of elementary matrices $B=E_1\\cdots E_k$.  It\n    follows that $BA = E_1\\cdots E_kA$. Since each elementary matrix\n    corresponds to an elementary row operation, it follows that $BA$\n    and $A$ are row equivalent. Therefore, $BA$ and $A$ have the same\n    row space. It follows that\n    $\\rank(BA) = \\dim(\\row(BA)) = \\dim(\\row(A)) = \\rank(A)$. This\n    proves the first claim. To show the claim about $AC$, first note\n    that by the above argument, $\\rank(C^TA^T) = \\rank(A^T)$, because\n    $C^T$ is invertible. Then $\\rank(AC)=\\rank(A)$ follows by taking\n    the transpose.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is an $m\\times n$-matrix and $B$ is an $n\\times p$-matrix.\n  Show that\n  \\begin{equation*}\n    \\nullity(AB) \\leq \\nullity(A) + \\nullity(B).\n  \\end{equation*}\n  \\textbf{Hint:} Consider the subspace $\\col(B)\\cap\\nullspace(A)$ and\n  suppose a basis for this subspace is\n  $\\set{\\vect{w}_1,\\ldots,\\vect{w}_k}$. Let\n  $\\set{\\vect{z}_1,\\ldots,\\vect{z}_k}$ be such that\n  $B\\vect{z}_i=\\vect{w}_i$. Now suppose\n  $\\set{\\vect{u}_1,\\ldots,\\vect{u}_r}$ is a basis for\n  $\\nullspace(B)$, and argue that\n  $\\nullspace(AB) \\subseteq \\sspan\\set{\\vect{u}_1,\\ldots,\n    \\vect{u}_r,\\vect{z}_1,\\ldots,\\vect{z}_k}$.\n  \\begin{sol}\n    Let $\\set{\\vect{w}_1,\\ldots,\\vect{w}_k}$ be a basis of\n    $\\col(B)\\cap\\nullspace(A)$. Then for each $i$, we have\n    $\\vect{w}_i\\in\\col(B)$, and therefore by\n    Exercise~\\ref{ex:column-space-is-image}, we can find $\\vect{z}_i$\n    such that $\\vect{w}_i = B\\vect{z}_i$. Also let\n    $\\set{\\vect{u}_1,\\ldots,\\vect{u}_r}$ be a basis for\n    $\\nullspace(B)$. Now assume $\\vect{x}\\in\\nullspace(AB)$. Then\n    $AB\\vect{x}=\\vect{0}$, and therefore\n    $B\\vect{x} \\in \\nullspace(A)\\cap \\col(B)$. We therefore have\n    \\begin{equation*}\n      B\\vect{x} = c_1\\vect{w}_1+\\ldots+c_k\\vect{w}_k\n      = B(c_1\\vect{z}_1+\\ldots+c_k\\vect{z}_k).\n    \\end{equation*}\n    This implies\n    \\begin{equation*}\n      \\vect{x}-(c_1\\vect{z}_1+\\ldots+c_k\\vect{z}_k)\\in \\nullspace(B)\n    \\end{equation*}\n    and so it is of the form\n    \\begin{equation*}\n      \\vect{x}-(c_1\\vect{z}_1+\\ldots+c_k\\vect{z}_k) =\n      d_1\\vect{u}_1 + \\ldots + d_r\\vect{u}_r.\n    \\end{equation*}\n    It follows that\n    \\begin{equation*}\n      \\vect{x}\\in \\sspan\\set{\\vect{z}_1,\\ldots,\\vect{z}_k,\n        \\vect{u}_1,\\ldots,\\vect{u}_r}.\n    \\end{equation*}\n    Since we have shown that every element of $\\nullspace(AB)$ is in\n    the span of these $k+r$ vectors, it follows that\n    \\begin{eqnarray*}\n      \\dim(\\nullspace(AB))\n      &\\leq & k+r \\\\\n      &=& \\dim(\\col(B)\\cap\\nullspace(A)) + \\dim(\\nullspace(B)) \\\\\n      &\\leq & \\dim(\\nullspace(A)) + \\dim(\\nullspace(B)),\n    \\end{eqnarray*}\n    and therefore $\\nullity(AB) \\leq \\nullity(A) + \\nullity(B)$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "9950c0c7d09dbd8987680b420f1bba26ea69053f", "size": 7994, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SpanIndependenceBasis-ColumnRowNullSpace.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SpanIndependenceBasis-ColumnRowNullSpace.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SpanIndependenceBasis-ColumnRowNullSpace.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.8486055777, "max_line_length": 74, "alphanum_fraction": 0.5536652489, "num_tokens": 3133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002492, "lm_q2_score": 0.8596637487122111, "lm_q1q2_score": 0.7944512177125519}}
{"text": "\\lab{Markov Chains}{Markov Chains}\n\\label{lab:Markov}\n\\objective{\nA 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.\nIn this lab, we learn to construct, analyze, and interact with Markov chains, then apply a Markov chain to a natural language processing problem.}\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 player's current location; where the player was on a previous turn does not affect their current turn.\n\nFinite Markov chains have an associated \\emph{transition matrix} that stores the information about the transitions between the states in the chain.\nThe $(i,j)$th entry of the matrix gives the probability of moving \\textbf{from state $j$ to state $i$}.\nThus each of the columns of the transition matrix sum to $1$.\n\n\\begin{info} % Generate random row stochastic transitino matrices.\nA transition matrix where the columns sum to 1 is called \\emph{column stochastic} (or \\emph{left stochastic}).\nThe rows of a \\emph{row stochastic} (or \\emph{right stochastic}) transition matrix each sum to 1 and the $(i,j)$th entry of the matrix is the probability of moving from state $i$ to state $j$.\nBoth representations are common, but in this lab we exclusively use column 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 today}} & \\text{\\textcolor{blue}{cold today}} \\\\\n\\begin{block}{c[cc]}\n\\text{\\textcolor{red}{hot tomorrow}}   & 0.7 & 0.6 \\\\\n\\text{\\textcolor{blue}{cold tomorrow}} & 0.3 & 0.4 \\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nThe $0$th column of the matrix says that if it is hot today, there is a $70\\%$ chance that tomorrow will be hot ($0$th row) and a $30\\%$ chance that tomorrow will be cold ($1$st row).\nThe $1$st column says if it is cold today, then there is a $60\\%$ chance of heat and a $40\\%$ chance of cold tomorrow.\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\\begin{figure}[H] % 2-state chain.\n\\centering\n\\begin{tikzpicture}[normalcircle/.style={draw, circle, minimum size=1.5cm, thick, node distance=2.5cm}]\n    % Place the circles\n    \\node[normalcircle] (Hot) {};\n    \\node[red] at (Hot) {Hot};\n\n    \\node[normalcircle, right=of Hot] (Cold) {};\n    \\node[blue] at (Cold) {Cold};\n\n    % Draw loop, place number, draw line\n    \\draw[thick,->,>=stealth',red!50!black] (Hot)+(-.52,.52) arc (325:40:.35 and -.85);\n    \\node[left,red!50!black] at (Hot.west) [shift={+(-.5,0)}] {0.7};\n    \\draw[thick,->,>=stealth',red!50!black] (Hot.north east) -- node[above] {0.3} (Cold.north west);\n\n    \\draw[thick,->,>=stealth',blue!50!black] (Cold)+(.52,.52) arc (325:40:-.35 and -.85);\n    \\node[right,blue!50!black] at (Cold.east) [shift={+(.5,0)}] {0.4};\n    \\draw[thick,->,>=stealth',blue!50!black] (Cold.south west) -- node[below] {0.6} (Hot.south east);\n\n\\end{tikzpicture}\n\\end{figure}\n\n%\n\\begin{problem} % Make a column stochastic matrix.\nTransition matrices for Markov chains are efficiently stored as NumPy arrays.\nWrite a function that accepts an integer $n$ and returns the transition matrix for a random Markov chain with $n$ states.\n\\\\ (Hint: use array broadcasting to avoid looping.)\n\\label{prob:random-markov-chain}\n\\end{problem}\n\n\\subsection*{Simulating State Transitions} % ----------------------------------\n\nA single draw from a \\emph{binomial distribution} with parameters $n$ and $p$ indicates the number of successes out of $n$ independent experiments, each with probability $p$ of success.\nThe classic example is a series of coin flips, where $p$ is the probability that the coin lands heads side up.\nNumPy's \\li{random} module has an efficient tool, \\li{binomial()}, for drawing from a binomial distribution.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n# Draw from the binomial distribution with n = 1 and p = .5 (flip 1 coin).\n>>> np.random.binomial(1, .5)\n0                             # The coin flip resulted in tails.\n\\end{lstlisting}\n\nConsider again the simple weather model and suppose that today is hot.\nThe column that corresponds to ``hot''in the transition matrix is $[0.7, 0.3]$.\nTo determine whether tomorrow is hot or cold, draw from the binomial distribution with $n = 1$ and $p = 0.3$.\nIf the draw is 1, which has $30\\%$ likelihood, then tomorrow is cold.\nIf the draw is 0, which has $70\\%$ likelihood, then tomorrow is hot.\nThe following function implements this idea.\n\n\\begin{lstlisting}\ndef forecast():\n    \"\"\"Forecast tomorrow's weather given that today is hot.\"\"\"\n    transition = np.array([[0.7, 0.6], [0.3, 0.4]])\n\n    # Sample from a binomial distribution to choose a new state.\n    return np.binomial(1, transition[1, 0])\n\\end{lstlisting}\n\n\\begin{problem} % 2-state chain with binomial transitioning.\nModify \\li{forecast()} so that it accepts an integer 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\\label{prob:small-markov-transitions}\n\\end{problem}\n\n\\subsection*{Larger Chains} % -------------------------------------------------\n\nThe \\li{forecast()} function makes one random draw from a binomial distribution to simulate a state change.\nLarger Markov chains require draws from a \\emph{multinomial distribution}, a multivariate generalization of the binomial distribution.\nA draw from a multinomial distribution parameters $n$ and $(p_1,\\ p_2,\\ \\ldots,\\ p_k)$ indicates which of $k$ outcomes occurs in $n$ different experiments.\nIn this case the classic example is a series of dice rolls, with $6$ possible outcomes of equal probability.\n\n\\begin{lstlisting}\n>>> die_probabilities = np.array([1./6, 1./6, 1./6, 1./6, 1./6, 1./6])\n\n# Draw from the multinomial distribution with n = 1 (roll a single die).\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} % 4-state chain with multinomial transitioning.\nLet the following matrix be the transition matrix 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.1 & 0   \\\\\n\\text{\\textcolor[rgb]{0,.6,0}{mild}}     & 0.3 & 0.3 & 0.3 & 0.3 \\\\\n\\text{\\textcolor{blue}{cold}}            & 0.2 & 0.3 & 0.4 & 0.5 \\\\\n\\text{\\textcolor{cyan}{freezing}}        &   0 & 0.1 & 0.2 & 0.2 \\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nWrite a new function that accepts an integer parameter and runs the same kind of simulation as \\li{forecast()}, but that uses this new four-state transition matrix.\nThis time, assume that 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:markov-larger-chain}\n\\end{problem}\n\n% TODO: Turn this into a Note down below?\n% \\begin{info}\n% A single experiment with probability $p$ of success is called a \\emph{Bernoulli trial}.\n% In general, the binomial distribution is the sum of $n$ repeated Bernoulli trials.\n% Like the Bernoulli is a special case of the binomial, the \\emph{categorical distribution} is a special case of the \\emph{multinomial distribution}, when n = 1.\n% NumPy only has direct implementations for the binomial and multinomial distributions, since the Bernoulli and categorical distributions are just special cases of these.\n% \\end{info}\n\n\n\\section*{General State Distributions} % ======================================\n\n\\begin{comment} % The 1-Norm. Might be able to get away without this.\nFor an $n\\times 1$ vector $\\x$ with entries $x_i$ and an $n\\times n$ matrix $A$ with entries $a_{ij}$, the \\emph{1-norm} is defined as follows.\n\\begin{align*}\n\\|\\x\\|_1 = \\sum_{i=1}^n|x_i| && \\|A\\|_1 = \\sup_j \\sum_{i=1}^n |a_{ij}|\n\\end{align*}\nIn other words, the $1$-norm for both vectors and matrices is the maximum absolute column sum.\nThen if $A$ is a transition matrix, $\\|A\\|_1 = 1$, since each of the entries of the matrix are positive and each of the columns sum to $1$ by definition.\nThe power method with the 1-norm can be used to find the unique stable steady state distribution of $A$.\n\\end{comment}\n\nFor a Markov chain with $n$ states, the probability of being in each of the states can be encoded by a single $n \\times 1$ vector $\\x$, called a \\emph{state distribution vector}.\nThe entries of $\\x$ must be nonnegative and sum to 1.\nThen the $i$th entry $x_i$ of $\\x$ is the probability of being in state $i$.\nFor example, the state distribution vector $\\x = [0.8,\\ 0.2]\\trp$ corresponding to the 2-state weather model of Problem \\ref{prob:small-markov-transitions} indicates that there is a $80\\%$ chance that today is hot and a $20\\%$ chance that today is cold.\nOn the other hand, the vector $\\x = [0, 1]\\trp$ implies that today is, with $100\\%$ certainty, cold.\n\nIf $A$ is an $n\\times n$ transition matrix for a Markov chain and $\\x$ is a state distribution vector, then $A\\x$ is also a state distribution vector.\n% To verify this fact, let $a_{ij}$ be the entries of $A$ and $x_i$ the entries of $\\x$.\n% The columns of $A$ sum to $1$, so $\\sum_{j=1}^n a_{ij} = 1$ for $i = 1,\\ 2,\\ \\ldots,\\ n$.\n% In addition, $\\sum_{j=1}^n x_j = 1$ since the entries of $\\x$ also sum to $1$.\n% From matrix multiplication, the $i$th entry of $A\\x$ is given by $\\sum_{j=1}^n a_{ij}x_j$, so the sum of the entries of $A\\x$ is\n% \\[\\sum_{i=1}^n\\sum_{j=1}^n a_{ij}x_j\n% = \\sum_{j=1}^n\\left(x_j\\left(\\sum_{j=1}^n a_{ij}\\right)\\right)\n% = \\sum_{j=1}^n x_j = 1.\\]\nIn fact, if $\\x_k$ is the state distribution vector corresponding to a certain time $k$, then $\\x_{k+1} = A\\x_k$ contains the probabilities of being in each state after allowing the system to transition again.\nFor the weather model, this means that if there is an $80\\%$ chance that it will be hot 5 days from now, written $\\x_{5} = [0.8,\\ 0.2]\\trp$, then since\n\\[\n\\x_{6} = A\\x_{5} =\n\\left[\\begin{array}{cc}\n0.7 & 0.6 \\\\\n0.3 & 0.4 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}0.8 \\\\ 0.2\\end{array}\\right]\n=\n\\left[\\begin{array}{c}0.68 \\\\ 0.32\\end{array}\\right],\n\\]\nthere is a $68\\%$ chance that 6 days from now will be a hot day.\n\n\\subsection*{Convergent Transition Matrices} % --------------------------------\n\nGiven an initial state distribution vector $\\x_{0}$, defining $\\x_{k+1} = A\\x_k$ yields the following significant relation.\n\\[\\x_k = A\\x_{k-1} = A(A\\x_{k-2}) = A(A(A\\x_{x-3})) = \\cdots = A^k\\x_{0}\\]\n\nThis indicates that the $(i,j)$th entry of $A^k$ is the probability of transition from state $j$ to state $i$ in $k$ steps.\nFor the transition matrix of the 2-state weather model, something curious happens to $A^k$ for even small values of $k$.\n\\[\nA = \\left[\\begin{array}{cc}\n0.7 & 0.6 \\\\\n0.3 & 0.4 \\\\\n\\end{array}\\right]\n\\quad\nA^2 = \\left[\\begin{array}{cc}\n0.67 & 0.66 \\\\\n0.33 & 0.34 \\\\\n\\end{array}\\right]\n\\quad\nA^3 = \\left[\\begin{array}{cc}\n0.667 & 0.666 \\\\\n0.333 & 0.334 \\\\\n\\end{array}\\right]\n\\]\nAs $k\\rightarrow\\infty$, the entries of $A^k$ converge, written as follows.\n\\begin{equation}\n\\lim_{k \\rightarrow \\infty} A^k = \\left[\\begin{array}{ccc}\n2/3 & 2/3 \\\\\n1/3 & 1/3 \\\\\n\\end{array}\\right].\n\\label{eq:markov-steady-transition}\n\\end{equation}\nIn addition, for any initial state distribution vector $\\x_{0} = [a,\\ b]\\trp$, $a + b = 1$,\n\\[\n\\lim_{k \\rightarrow \\infty} \\x_k = \\lim_{k \\rightarrow \\infty}A^k\\x_{0}\n=\n\\left[\\begin{array}{ccc}\n2/3 & 2/3 \\\\\n1/3 & 1/3 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}a\\\\b\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2(a+b)/3\\\\(a+b)/3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2/3\\\\1/3\\end{array}\\right].\n\\]\n\nThus as $k\\rightarrow\\infty$, $\\x_k \\rightarrow \\x = [2/3,\\ 1/3]\\trp$, regardless of the initial state distribution $\\x_{0}$.\nSo according to this model, no matter the weather today, the probability that it is hot a week from now is approximately $66.67\\%$.\nIn fact, approximately 2 out of 3 days in the year should be hot.\n\n\\subsection*{Steady State Distributions} % ------------------------------------\n\nThe state distribution $\\x = [2/3,\\ 1/3]\\trp$ has another important property.\n\\[\nA\\x =\n\\left[\\begin{array}{cc}\n7/10 & 3/5 \\\\\n3/10 & 2/5 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}2/3 \\\\ 1/3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}14/30 + 3/15 \\\\ 6/30 + 2/15\\end{array}\\right]\n=\n\\left[\\begin{array}{c}2/3 \\\\ 1/3\\end{array}\\right]\n= \\x.\n\\]\nAny $\\x$ satisfying $A\\x = \\x$ is called a \\emph{steady state distribution} or a \\emph{stable fixed point} of $A$.\nIn other words, a steady state distribution is an eigenvector of $A$ with corresponding eigenvalue $\\lambda = 1$.\n\n% TODO: Verify this paragraph.\nEvery Markov chain has at least one steady state distribution.\nIf some power $A^k$ of $A$ has all positive (nonzero) entries, then the steady state distribution is unique.%\n\\footnote{This is a consequence of the \\emph{Perron-Frobenius theorem}, which is presented in conjunction with spectral calculus in Volume I.}\nIn this case, $\\lim_{k\\rightarrow\\infty}A^k$ is the matrix whose columns are all equal to the unique steady state distribution, as in (\\ref{eq:markov-steady-transition}).\nUnder these circumstances, the steady state distribution $\\x$ can be found by iteratively calculating $\\x_{k+1} = A\\x_k$, as long as the initial vector $\\x_{0}$ is a state distribution vector.\n\n\\begin{warn}\nThough every Markov chain has at least one steady state distribution, the procedure described above fails if $A^k$ fails to converge.\nConsider the following example.\n\\[\nA = \\left[\\begin{array}{ccc}\n0 & 0 & 1 \\\\\n0 & 1 & 0 \\\\\n1 & 0 & 0\n\\end{array}\\right]\n,\\quad A^k = \\begin{cases}\nA\\quad\\text{if } k\\ \\text{is odd}\n\\\\\nI\\quad\\text{if } k\\ \\text{is even}\n\\end{cases}\n\\]\nIn this case as $k\\rightarrow\\infty$, $A^k$ oscillates between two different matrices.\n\nFurthermore, the steady state distribution is not always unique; the transition matrix defined above, for example, has infinitely many.\n\\end{warn}\n\n\\begin{problem} % Use the power method (simple) to get the steady state.\nWrite a function that accepts an $n\\times n$ transition matrix $A$, a convergence tolerance $\\epsilon$, and a maximum number of iterations $N$.\nGenerate a random state distribution vector $\\x_{0}$ and calculate $\\x_{k+1} = A\\x_k$ until $\\|\\x_{k-1} - \\x_k\\| < \\epsilon$.\nIf $k$ exceeds $N$, raise a \\li{ValueError} to indicate that $A^k$ does not converge.\nReturn the approximate steady state distribution $\\x$ of $A$.\n\nTo test your function, use Problem \\ref{prob:random-markov-chain} to generate a random transition matrix $A$.\nVerify that $A\\x = \\x$ and that the columns of $A^k$ approach $\\x$ as $k\\rightarrow\\infty$.\nTo compute $A^k$, use NumPy's (very efficient) algorithm for computing matrix powers. % (which is not part of \\li{scipy.linalg}).\n\n\\begin{lstlisting}\n>>> A = np.array([[.7, .6],[.3, .4]])\n>>> np.linalg.matrix_power(A, 10)       # Compute A^10.\narray([[ 0.66666667,  0.66666667],\n       [ 0.33333333,  0.33333333]])\n\\end{lstlisting}\n\nFinally, use your function to validate the results of Problems \\ref{prob:small-markov-transitions} and \\ref{prob:markov-larger-chain}:\n\\begin{enumerate}\n    \\item Calculate the steady state distributions corresponding to the transition matrices for each simulation.\n    \\item Run each simulation for a large number of days and verify that the results match the steady state distribution (for example, check that approximately 2/3 of the days are hot for the smaller weather model).\n\\end{enumerate}\n\n\\label{prob:markov-power-method}\n\\end{problem}\n\n\\begin{info}\nProblem \\ref{prob:markov-power-method} is a special case of the \\emph{power method}, an algorithm for calculating an eigenvector of a matrix corresponding to the eigenvalue of largest magnitude.\nThe general version of the power method, together with a discussion of its convergence conditions, is discussed in another lab.\n\\end{info}\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.\n% \\footnote{The term \\emph{natural language} refers to 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 reflect the sort of English that the source authors speak.\nThus the Markov chain built from \\emph{The Complete Works of William Shakespeare} differs greatly from, say, the Markov chain built from a collection of academic journals.\nWe 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 a training set with $N$ unique words has an $(N+2)\\times (N+2)$ transition matrix.\n\nThe start state only transitions 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 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 from Dr. Seuss 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]{.3,.6,.1}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c[ccccccc]}\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}}    & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I}        & 3 & 0 & 0 & 2 & \\ldots & 0 & 0\\\\\n\\text{am}       & 0 & 1 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{Sam}      & 0 & 0 & 1 & 1 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.}     & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}}        & 0 & 0 & 0 & 0 & \\ldots & 1 & 1\\\\\n\\end{block}\\end{blockarray}\n\\end{align*}\n\nNow divide each column by its sum so that each column sums to 1.\n\n\\begin{align*}\n\\begin{blockarray}{cccccccc}\n& \\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & \\text{I} & \\text{am} & \\text{Sam} & & \\text{ham.} & \\text{\\textcolor[rgb]{1,0,0}{\\$top}} \\\\\n\\begin{block}{c[ccccccc]}\n\\text{\\textcolor[rgb]{.3,.6,.1}{\\$tart}} & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{I}        & 3/4 & 0 & 0 & 2/3 & \\ldots & 0 & 0\\\\\n\\text{am}       & 0 & 1/5 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{Sam}      & 0 & 0 & 1 & 1/3 & \\ldots & 0 & 0\\\\\n& \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots\\\\\n\\text{ham.}     & 0 & 0 & 0 & 0 & \\ldots & 0 & 0\\\\\n\\text{\\textcolor[rgb]{1,0,0}{\\$top}}    & 0 & 0 & 0 & 0 & \\ldots & 1 & 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 column 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.\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 \\textbf{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 $(x, y)$ 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 $x$ to state $y$.\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 column by dividing by the column sums.\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} % 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 as described in Algorithm \\ref{alg:MarkovSentencesTransitionMatrix}.\n\nYou may assume that the file has one complete sentence written on each line, and your implementation may be either column- or row-stochastic.\n\\label{problem:markov-random-sentences-init}\n\\end{problem}\n\n\\begin{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:markov-larger-chain} 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\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 _ in range(3):\n... \tprint(yoda.babble())\n...\n<<Impossible 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.>>\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 from \\li{scipy.sparse} for the transition matrix instead of a regular NumPy array.\nSpecifically, construct the transition matrix as a \\li{lil_matrix} (which is easy to build incrementally), then convert it to the \\li{csc_matrix} format (which supports fast column operations).\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\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\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 together with hidden Markov models.\n\n\\item Construct the state space so that the next state depends on both the current and previous states.\nThis kind of Markov chain is called a \\emph{Markov chain of order 2}.\nThis way, every set of three consecutive words in a randomly generated sentence should be part of the training set, as opposed to only every consecutive pair of words coming from the set.\n\n\\item Instead of generating random sentences from a single source, simulate a random conversation between $n$ people.\nConstruct a Markov chain $M_i,$ for each person, $i=1,\\ \\ldots,\\ n$, then create a Markov chain $C$ describing the conversation transitions from person to person; in other words, the states of $C$ are the $M_i$.\nTo create the conversation, generate a random sentence from the first person using $M_1$.\nThen use $C$ to determine the next speaker, generate a random sentence using their Markov chain, and so on.\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 a \\emph{natural language processing} application.\nPython's \\li{nltk} module (natural language toolkit) has many tools for parsing and analyzing text for these kinds of problems.\nFor example, \\li{nltk.sent_tokenize()} reads a single string and splits it up into sentences.\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": "14153fbf04c72701f43eabccadca6eb3a1d09318", "size": 30832, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/MarkovChains/MarkovChains.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/MarkovChains/MarkovChains.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/MarkovChains/MarkovChains.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": 56.7808471455, "max_line_length": 293, "alphanum_fraction": 0.7114361702, "num_tokens": 8682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.9241418225903233, "lm_q1q2_score": 0.7944512119203868}}
{"text": "\n\\subsection{Bilinear maps}\n\nA bilinear map (or function) is a map from two inputs to an output which preserves addition and scalar multiplication. This is in contrast to a linear map, which only has one input.\n\nIn addition, the function is linear in both arguments.\n\nThat is if function \\(f\\) is bilinear then:\n\n\\(X=aM+bN\\)\n\n\\(Y=cO+dP\\)\n\n\\(f(X,Y)=f(aM+bN,cO+dP)\\)\n\n\\(f(X,Y)=f(aM,cO+dP)+f(bN,cO+dP)\\)\n\n\\(f(X,Y)=f(aM,cO)+f(aM,dP)+f(bN,cO)+f(bN,dP)\\)\n\n\\(f(X,Y)=acf(M,O)+adf(M,P)+bcf(N,O)+bdf(N,P)\\)\n\nNote that:\n\n\\(f(X,Y)=f(X+0,Y)\\)\n\n\\(f(X,Y)=f(X,Y)+f(0,Y)\\)\n\n\\((0,Y)=0\\)\n\nThat is, if any input is \\(0\\) in an additative sense, the value of the map must be zero.\n\n", "meta": {"hexsha": "6d8e6345cfc85d7604665421464baa168d670853", "size": 661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/fields/02-01-bilinearMaps.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/fields/02-01-bilinearMaps.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/fields/02-01-bilinearMaps.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.65625, "max_line_length": 181, "alphanum_fraction": 0.6308623298, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517095103499, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7944301179387034}}
{"text": "\\section{Topological Spaces}\r\n\\begin{definition}\r\n    Consider a set $X$.\r\n    A topology $\\tau$ is a collection of subsets of $X$ such that the following axioms hold:\\\\\r\n    1. $\\varnothing, X\\in\\tau$.\\\\\r\n    2. $\\forall i\\in I,U_i\\in\\tau\\implies \\bigcup_{i\\in I}U_i\\in\\tau$.\\\\\r\n    3. $U,V\\in\\tau\\implies U\\cap V\\in\\tau$.\\\\\r\n    A topological space is a pair $(X,\\tau)$ where $X$ is a set and $\\tau$ is a topology on $X$.\r\n\\end{definition}\r\nNote that the third axiom can be extended to any finite set of elements of $\\tau$.\\\\\r\nMembers of $\\tau$ are called open sets of $X$.\r\n\\begin{example}\r\n    For any metric space, we can induce the metric topology by Proposition \\ref{metric_topology}.\r\n    For example, the Euclidean distance on $\\mathbb R^n$ induce the usual topology on $\\mathbb R^n$.\r\n\\end{example}\r\n\\begin{definition}\r\n    A topological space $X$ (or the topology of $X$) is called metrizable if it can be induced by some metric on $X$.\r\n\\end{definition}\r\nIn the case where the topology is metrizable, any other metric that is equivalent to the previous metric gives the same topology.\r\n\\begin{example}\r\n    The indiscrete topology on a set $X$ is $\\{\\varnothing, X\\}$.\r\n\\end{example}\r\n\\begin{definition}\r\n    Give topologies $\\tau_1,\\tau_2$ on $X$, we say $\\tau_1$ is coarser than $\\tau_2$ or $\\tau_2$ is finer than $\\tau_1$ if $\\tau_1\\subset\\tau_2$.\r\n\\end{definition}\r\nWe know that the indiscrete topology is coarser than any topology on $X$.\r\nIt is then immediate that if $|X|\\ge 2$, then the indiscrete topology is not metrizable.\r\nIndeed, suppose $x,y\\in X$, the open ball $D_{d(x,y)}(x)$, then it contains $x$ but not $y$ and is open under the metric topology under $d$, so $d$ cannot induce the indiscrete topology on $X$.\r\n\\begin{example}\r\n    The discrete topology on a set $X$ is $\\tau=2^X$.\r\n    This is metrizable.\r\n    Indeed, it can be induced by the discrete metric.\r\n    It is also the finest topology on $X$.\r\n\\end{example}\r\n\\begin{example}\r\n    The cofinite topology on a set $X$ consists of all subsets of $X$ whose complement is finite and the empty set.\r\n    When $X$ is finite, this topology is just the discrete topology.\r\n    If it is infinite, it is not metrizable.\r\n    Fix $x\\neq y\\in X$, whenever there is open sets $U,V$ such that $x\\in U, y\\in V$, we know that $X\\setminus(U\\cap V)$ is finite, thus $U\\cap V$ is not empty, but it would mean that the topological space that is not Hausdorff (which we will define below), but any metric space is (also below), so it is not metrizable.\r\n\\end{example}\r\n\\begin{definition}\r\n    A topological space $X$ is called Hausdorff if any two distinct elements $x,y$ in $X$, there are open sets $U,V$ such that $x\\in U,y\\in V$ and $U\\cap V=\\varnothing$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Any metric space is Hausdorff.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Consider $U=D_{d(x,y)/2}(x),V=D_{d(x,y)/2}(y)$, they obviously contain $x,y$ respectively and have empty intersection due to triangle inequality.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A subset of $X$ is called closed if its complement is open.\r\n\\end{definition}\r\nThis coincides with the definition of closed sets in a metric space by Lemma \\ref{metric_complement}.\r\n\\begin{proposition}\r\n    1. $\\varnothing,X$ are closed\\\\\r\n    2. If $A_i$ is closed for all $i\\in I$, then $\\bigcap_{i\\in I}A_i$ is closed.\\\\\r\n    3. If $A,B$ are closed, then $A\\cup B$ is closed.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nAgain the last one can be generalized to any finite indices.\r\n\\begin{example}\r\n    In cofinite topology, a subset is closed if and only if it is finite.\r\n\\end{example}\r\n\\begin{definition}\r\n    For a topological space $X$, $x\\in X$ and $U\\subset X$.\r\n    We say $U$ is a neighbourhood of $x$ if $\\exists V\\subset X$ open such that $x\\in V\\subset U$.\r\n\\end{definition}\r\nNote again that in a metric space, this reduced to our previous definition.\r\nThe proof of this is trivial.\r\n\\begin{proposition}\r\n    Let $U\\subset X$, then $U$ is open if and only if every $x\\in U$ has a neighbourhood contained in $U$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Completely trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A sequence $(x_n)\\in X$ converges to some $x\\in X$, or $x_n\\to x$, if for any neighbourhood $V$ of $x$, $\\exists N\\in\\mathbb N,\\forall n>N, x_n\\in V$.\r\n\\end{definition}\r\nThis again and again coincides with previous definition in metric spaces by Proposition \\ref{metric_nbhdconv}.\r\n\\begin{example}\r\n    In a indiscrete space, any sequence converge to any element.\r\n\\end{example}\r\n\\begin{theorem}\r\n    In a Hausdorff space, limits are unique.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    If $x_n\\to x$ and $x_n\\to y$ but $x\\neq y$, then there are disjoint open sets $U,V$ containing $x,y$ respectively.\r\n    But then there is some $N_1\\in\\mathbb N,\\forall n>N, x_n\\in U$, and there is also some $N_2\\in\\mathbb N,\\forall n>N, x_n\\in V$, but then for any $n>\\max\\{N_1,N_2\\}$, $x_n\\in U\\cap V=\\varnothing$, contradicion.\r\n\\end{proof}\r\n\\begin{remark}\r\n    In a metric space, $A$ is closed if and only if whenever $x_n$ converges in the metric space, then its limit is in $A$.\r\n    The $\\implies$ part is true in all topological space, but not necessarily $\\impliedby$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $X$ be a topological space and $A\\subset X,x\\in X$.\r\n    $x$ is called an accumulation point (aka limit point/cluster point) of $A$ if for any neighbourhood $U$ of $x$, $(A\\setminus\\{x\\})\\cap U\\neq\\varnothing$.\\\\\r\n    The derived set $A'$ of $A$ is the set of all accumulation points of $A$.\r\n\\end{definition}\r\n\\begin{example}\r\n    In $\\mathbb R$, suppose $A=[0,1)\\cup \\{2\\}$, then $A'=[0,1]$.\r\n    Also $\\mathbb Q'=\\mathbb R$, and $\\mathbb Z'=\\varnothing$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $X$ be a topological space and $A\\subset X$, then $A$ is closed if and only if $A'\\subset A$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If $A$ is closed, then $U=X\\setminus A$ is open, so for any $x\\in X\\setminus A$, $U$ is a neighborhood of $x$ but $U\\cap A=\\varnothing$, so every accumulation points of $A$ are inside of $A$.\\\\\r\n    Conversely, given $x\\in X\\setminus A$, then $x\\notin A'$, so there is a neighbourhood $U$ of $x$ with $U\\cap A=\\varnothing$, so $x\\in U\\subset X\\setminus A$, so $X\\setminus A$ is open, hence $A$ is closed.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Let $A$ be a subset of a topological space $X$, then the interior of $A$, $\\operatorname{int}A$ or $A^\\circ$ is defined by\r\n    $$\\operatorname{int}A=\\bigcup_{U\\subset A\\text{, $U$ open}}U$$\r\n    The closure, $\\operatorname{cl}A$ or $\\bar A$, is defined by\r\n    $$\\operatorname{cl}A=\\bigcap_{A\\subset F\\text{, $F$ closed}}F$$\r\n\\end{definition}\r\nNote that $A^\\circ\\subset A\\subset\\bar{A}$, and $A^\\circ =A$ if and only if $A$ is open, $\\bar A=A$ if and only if $A$ is closed.\r\n\\begin{proposition}\r\n    \\begin{align*}\r\n        A^\\circ&=\\{x\\in X:\\text{$A$ is a neighbourhood of $x$}\\}\\\\\r\n        \\bar{A}&=\\{x\\in X:\\text{$\\forall U\\subset X$ such that $U$ is a neighbourhood of $x$, $U\\cap A=\\varnothing$}\\}\\\\\r\n        &=A\\cup A'\r\n    \\end{align*}\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    In $\\mathbb R$, $\\overline{[0,1)\\cup\\{2\\}}=[0,1]\\cup\\{2\\}$, $([0,1)\\cup\\{2\\})^\\circ=(0,1)$, $\\bar{\\mathbb{Q}}=\\mathbb R, \\mathbb Q^\\circ=\\varnothing=\\mathbb Z^\\circ, \\bar{\\mathbb Z}=\\mathbb Z$.\r\n\\end{example}\r\n\\begin{remark}\r\n    Convergent sequences determine the metric topology, since $x\\in\\bar{A}\\iff \\exists (x_n)\\in A, x_n\\to x$.\r\n    Again we have the $\\impliedby$ direction for all topological spaces but not necessarily for the $\\implies$ direction.\r\n\\end{remark}\r\n\\begin{definition}\r\n    Let $X$ be a topological space and $A\\subset X$.\r\n    We say $A$ is dense if $\\bar{A}=X$.\\\\\r\n    We say $X$ is seperable if there is a countable dense set in $X$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    1. $\\mathbb R^n$ is seperable since $\\bar{\\mathbb Q^n}$.\r\n    2. (non-example) An uncountable set in the discrete topology is not seperable.\r\n\\end{definition}\r\nAs usual we can try to construct new spaces from old.\r\n\\begin{definition}\r\n    Let $(X,\\tau)$ be a topological space and $Y\\subset X$.\r\n    The subspace (or relative) topology on $Y$ is the collection $\\{U\\cap Y:U\\in\\tau\\}$.\r\n    This is also called the topology on $Y$ induced by $\\tau$.\r\n\\end{definition}\r\nOne can check that this is indeed a topology.\r\n\\begin{example}\r\n    Let $X=\\mathbb R$, $Y=[0,2]$, then $U=(1,2]$ is open in $Y$ since $U=Y\\cap (1,3)$.\r\n    Note that $U$ is not open in $X$.\r\n\\end{example}\r\n\\begin{remark}\r\n    1. If $Z\\subset Y\\subset X$, then the topology on $Z$ induced by the topology on $X$ is the topology on $Z$ induced by the topology on $Y$ which is induced by the topology on $X$.\r\n    So the subspace of a subspace is a subspace.\\\\\r\n    2. If $N\\subset M$ where $N,M$ are metric spaces, then the metric on $N$ induced by the metric on $M$ induces the metric topology on $N$ induced by the metric topology on $M$.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Let $Y$ be the subspace of a topological space $X$.\\\\\r\n    1. $A\\subset Y$ is closed in $Y$ if and only if there is closed set $B\\subset X$ such that $B\\cap Y=A$.\\\\\r\n    2. $\\forall A\\subset Y, \\bar{A}^Y=Y\\cap\\bar{A}^X$.\r\n\\end{proposition}\r\n\\begin{remark}\r\n    The analogy of $2$ on interiors does not always work.\r\n    Take $X=\\mathbb R,Y=\\{0\\}$.\r\n\\end{remark}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A base for a topological space $(X,\\tau)$ is a family $\\mathscr B\\subset\\tau$ such that $\\forall U\\in\\tau,\\exists \\mathscr C\\subset\\mathscr B$ such that\r\n    $$U=\\bigcup_{B\\in\\mathscr C}B$$\r\n\\end{definition}\r\nIn other words, the topology $\\tau$ consists of the arbitrary unions of some family of open sets which is a subset of $\\mathscr B$.\r\nSo a base determines topology.\r\n\\begin{example}\r\n    1. The set of all open intervals is a base of the usual topology on $\\mathbb R$.\r\n    In general, the collection of all open balls in a metric space is a base for the metric topology on it.\r\n\\end{example}\r\nHowever, what we want to do is not to construct $\\mathscr B$ from $\\tau$, but the other way around.\r\n\\begin{lemma}\r\n    let $X$ be a set and $\\mathscr B\\subset 2^X$.\r\n    Assume that\\\\\r\n    1. $X=\\bigcup_{B\\in\\mathscr B}B$.\\\\\r\n    2. $\\forall B_1,B_2\\in\\mathscr B,\\forall x\\in B_1\\cap B_2, \\exists B\\in\\mathscr B,x\\in B\\subset B_1\\cap B_2$.\\\\\r\n    Then there is an unique topology on $X$ that is generated by the base $\\mathscr B$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We must have the topology\r\n    $$\\tau=\\left\\{\\bigcup_{B\\in\\mathscr C}B:\\mathscr C\\subset\\mathscr B\\right\\}$$\r\n    It is immediate that $\\tau$ is a topology on $X$.\r\n    Indeed, $\\varnothing,X\\in\\tau$ and it is closed under arbitrary union.\r\n    For intersection, consider\r\n    $$U_1=\\bigcup_{B\\in\\mathscr C_1}B,U_2=\\bigcup_{B\\in\\mathscr C_2}B$$\r\n    Given $x\\in U_1\\cap U_2$, so $\\exists B_1\\in\\mathscr C_1, B_2\\in\\mathscr C_2$, so there is some $B_x\\in\\mathscr B$ such that $x\\in B_x\\subset B_1\\cap B_2\\subset U_1\\cap U_2$, thus\r\n    $$U_1\\cap U_2=\\bigcup_{x\\in U_1\\cap U_2}B_x$$\r\n    By definition $\\mathscr B$ is a base for $\\tau$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A topological space is called second-countable if it has a countable base.\r\n\\end{definition}\r\n\\begin{example}\r\n    The set of all open balls of rational radii and centres is a countable base for $\\mathbb R^n$.\r\n    So $\\mathbb R^n$ is seond-countable.\r\n\\end{example}\r\n\\begin{definition}\r\n    A map $f:(X,\\tau)\\to (Y,\\rho)$ is continuous if $V\\in\\rho\\implies f^{-1}(V)\\in\\tau$.\r\n\\end{definition}\r\nThis extends our previous defintion of continuity in metric space by Proposition \\ref{metric_preimage}.\r\n\\begin{proposition}\r\n    Let $f:X\\to Y$ be a map between topological spaces, then\\\\\r\n    1. $f$ is continuous if and only if the preimage of any closed set is closed.\\\\\r\n    2. If $\\mathscr B$ is a base for $Y$, then $f$ is continuous if and only if for all $B\\in\\mathscr B$, $f^{-1}(B)$ is open in $X$.\\\\\r\n    3. Composition of continous functions is continuous.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{example}\r\n    Constant, identity and inclusion are always continuous.\r\n    Hence the restriction of a continuous map is continuous.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $f:X\\to Y$ be a map between topological spaces, then we say $f$ is a homeomorphism if $f$ is a bijection and both $f,f^{-1}$ are continuous.\r\n    We say $X,Y$ are homeomorphic, or $X\\cong Y$, if there is a homeomorphism between them.\r\n\\end{definition}\r\n\\begin{definition}\r\n    $f$ is a open map if for every $U$ open in $X$, $f(U)$ is open in $Y$.\r\n    So $f$ is a homeomorphism if and only if $f$ is a continuous open bijection.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A property $P$ of topological spaces is called a topological property if it is preserved under homeomorphisms.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $(X,\\tau),(Y,\\rho)$ be topological spaces and let\r\n    $$\\mathscr B=\\{U\\times V:U\\in\\tau, V\\in\\rho\\}$$\r\n    Then $X\\times Y\\in\\mathscr B$ and $U_1\\times V_1\\cap U_2\\times V_2=(U_1\\cap U_2)\\times (V_1\\times V_2)\\in\\mathscr B$.\r\n    Thus there is an unique topology on $X\\times Y$ with base $\\mathscr B$.\r\n    This is called the product topology.\r\n\\end{definition}\r\nSo a set $W$ in the product topological space is open if and only if $\\forall (x,y)\\in W,\\exists U\\in\\tau, V\\in\\rho, x\\in U\\times V\\subset W$.\r\n\\begin{example}\r\n    $\\mathbb R^2$ in the usual topology is homeomorphic to $\\mathbb R\\times\\mathbb R$ in the product topology.\r\n    In general, the topology induced by the ($p$-)product metric is the product topology of metric topologies.\r\n    So products of metrizable topologies are metrizable.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Consider $\\pi_X:X\\times Y\\to X,\\pi_Y:X\\times Y\\to Y$ be the projections.\r\n    Then $\\pi_X,\\pi_Y$ are continuous and if $Z$ is a topological space, and $f:Z\\to X\\times Y$ is continuous if and only if $\\pi_X\\circ f,\\pi_Y\\circ f$ are both continuous.\r\n\\end{proposition}\r\nNote that $f(z)=(\\pi_X\\circ f(z),\\pi_Y\\circ f(z))$.\r\n\\begin{proof}\r\n    Given an open set $U\\subset X$, $\\pi_X^{-1}(U)=U\\times Y$, which is open in $X\\times Y$, so $\\pi_X$ is continuous.\r\n    Similarly, $\\pi_Y$ is continuous.\\\\\r\n    Given such an $f$, if $f$ is continuous, then both of $\\pi_X\\circ f,\\pi_Y\\circ f$ are continuous since composition of continuous functions is continuous.\r\n    Conversely, if both of $\\pi_X\\circ f,\\pi_Y\\circ f$ are continuous, then it is enough to check that any member of the base $U\\times V\\subset X\\times Y$ has an open preimage.\r\n    Indeed,\r\n    \\begin{align*}\r\n        f^{-1}(U\\times V)&=f^{-1}(U\\times Y)\\cap f^{-1}(X\\times V)\\\\\r\n        &=f^{-1}(\\pi_X^{-1}(U))\\cap f^{-1}(\\pi_Y^{-1}(V))\\\\\r\n        &=(\\pi_X\\circ f)^{-1}(U)\\cap (\\pi_Y\\circ f)^{-1}(V)\r\n    \\end{align*}\r\n    which is open by assumption.\r\n\\end{proof}\r\nIt is trivial to extend all the above to finite products.\r\nIt is interesting to know that $(X\\times Y)\\times Z\\cong X\\times (Y\\times Z)$, and $X\\times Y\\cong Y\\times X$.\r\n%But how about arbitrary products?\r\nNow we turns to quotient topology.\r\n\\begin{definition}\r\n    Start with a topological space $(X,\\tau)$ and let $R$ be an equivalence relation on $X$.\r\n    We let $X/R$ be the set of equivalence classes (the ``quotient set'').\r\n    Let $q:X\\to X/R$ be the quotient map sending $x\\mapsto [x]$ where $[x]=\\{y\\in X:yRx\\}$ is the equivalence class containing $x$.\r\n    The quotient topology on $X/R$ is the family\r\n    $$\\tau_R=\\{V\\subset X/R:q^{-1}(V)\\in\\tau\\}$$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    the quotient topology is indeed a topology.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    $q^{-1}(X/R)=X,q^{-1}(\\varnothing)=\\varnothing$, so $\\varnothing,X\\in\\tau_R$.\r\n    $$\\forall (V_i)_{i\\in I}\\in\\tau_R,q^{-1}\\left(\\bigcup_{i\\in I}V_i\\right)=\\bigcup_{i\\in I}q^{-1}(V_i)$$\r\n    which is open.\r\n    $$\\forall U,V\\in\\tau_R,q^{-1}(U\\cap V)=q^{-1}(U)\\cap q^{-1}(V)$$\r\n    which is also open.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. Note that $q$ is surjective and continuous under $\\tau_R$.\\\\\r\n    2. For $x\\in X,t\\in X/R, x\\in t\\iff q(x)=t$, hence\r\n    $$\\forall V\\subset X/R,q^{-1}(V)=\\{x\\in X:q(x)\\in V\\}=\\{x\\in X:\\exists t\\in V, q(x)=t\\}=\\bigcup_{t\\in V}t$$\r\n\\end{remark}\r\n\\begin{example}\r\n    $\\mathbb Q\\le\\mathbb R$ as (additive) groups, so $\\mathbb R/\\mathbb Q$ gives a equivalence relation.\r\n    So we can induce a quotient topology on $\\mathbb R/\\mathbb Q$, which immediately we can find to be the indiscrete topology which is not metrizable, which is why we do not do quotients in metric spaces.\r\n\\end{example}\r\nConsider $q:X\\to X/R$ the quotient map and any map $f:X\\to Y$ such that $xRy\\implies f(x)=f(y)$, then there is a map $\\tilde{f}:X/R\\to Y$ such that $\\tilde{f}\\circ q=f$.\r\nThat is, the following diagram commutes.\r\n$$\r\n\\begin{tikzcd}\r\n    X\\arrow{r}{f}\\arrow[swap]{d}{q}&Y\\\\\r\n    X/R\\arrow[swap,dashed]{ur}{\\tilde{f}}&\r\n\\end{tikzcd}\r\n$$\r\nIf $f$ is surjective, so is $\\tilde{f}$.\r\nAlso, if $f(x)=f(y)\\iff xRy$, then $\\tilde{f}$ is injective.\r\n\\begin{proposition}\r\n    Let $X,Y$ be topological spaces, $R$ an equivalence relation on $X$, $q:X\\to X/R$ the quotient map, $f:X\\to Y$ some map with $xRy\\implies f(x)=f(y)$, then let $\\tilde{f}$ be as above, then\\\\\r\n    1. If $f$ is continuous so is $\\tilde{f}$.\\\\\r\n    2. If $f$ is an open map so is $\\tilde{f}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1. Let $V$ be open in $Y$, then $f^{-1}(V)$ is open in $X$, so $q^{-1}(\\tilde{f}^{-1}(V))=f^{-1}(V)$ is open, so $\\tilde{f}^{-1}(V)$ is open, hence $\\tilde{f}$ is continuous.\\\\\r\n    2. Given open $V\\in X$, $U=q^{-1}(V)$ is open in $X$, and $V=q(U)$, so $\\tilde{f}(V)=f(U)$ which is open.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f(x)=f(y)\\iff xRy$, $f$ is surjective, continuous and open, then $\\tilde{f}$ is a homeomorphism.\r\n\\end{corollary}\r\n\\begin{remark}\r\n    Work ``upstairs''!\r\n\\end{remark}\r\n\\begin{example}\r\n    Take $\\mathbb R/\\mathbb Z$ where the equivalence relation is as if they are additive groups.\r\n    $\\mathbb R/\\mathbb Z\\cong S^1=\\{z\\in\\mathbb C:|z|=1\\}$.\r\n    Indeed, consider the map $f(t)=e^{2\\pi it}$, then the induced $\\tilde{f}$ is a homeomorphism by the preceding corollary.\r\n    If $f$ is not open, then there is some open $U\\in\\mathbb R$ such that $f(U)$ is not open.\r\n    $\\exists (z_n)\\in S^1\\setminus f(U)$ such that $z_n\\to z$, then due to surjectivity we know that there is some $x\\in U$ such that $f(x)=z$ and $(x_n)\\in [x-1/2,x+1/2]$ such that $f(x_n)=z_n$ and we know that $x_n\\notin U$, but $x_n$ has a convergent subsequence $(x_{k_n})\\to y\\in \\mathbb R\\setminus U$ which is closed, so due to continuity we must have $f(x)=f(y)\\implies x-y\\in\\mathbb Z\\implies x=y\\notin U$, which is a contradiction.\r\n\\end{example}", "meta": {"hexsha": "33ceee206c97a97a639fd4cbb4cf26c5bf617edf", "size": 18768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/topology.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": "5/topology.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": "5/topology.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": 57.0455927052, "max_line_length": 441, "alphanum_fraction": 0.6627770673, "num_tokens": 6206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.7944090903998727}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsfonts, amsmath, enumitem, float, graphicx, hyperref}\n\n\\title{Numerical Computing - Notes}\n\\author{Matteo Alberici}\n\\date{January 2022}\n\n\\begin{document}\n\n\\maketitle\n\\newpage\n\\tableofcontents\n\\newpage\n\n% --------------------------------- %\n% Assignment 1 - PageRank Algorithm\n% --------------------------------- %\n\\section{PageRank Algorithm}\n\\subsection{Eigenvectors}\nAn \\textbf{eigenvector} $v \\in \\mathbb{R}$ of a matrix $A$ is a nonzero vector such that the relation\n\\begin{center}\n    $Av = \\lambda v$ \n\\end{center}\nholds, where $\\lambda$ is the \\textbf{eigenvalue} associated with vector $v$. \\\\\nAn \\textbf{eigenbasis} is a basis in which every vector is an eigenvector. \\\\\nGiven a vector $v$, the \\textbf{Rayleigh quotient} computes the eigenvalue of $v$ whether $v$ is an eigenvector, or the eigenvalue associated with closest eigenvector of $v$ otherwise:\n\\begin{center}\n    $\\mu(v) = \\displaystyle\\frac{v^TAv}{v^Tv}$\n\\end{center}\n\\subsection{PageRank Algorithm}\nThe \\textbf{PageRank} is determined by the structure of the World Wide Web. For any query, Google lists the matching Web pages in their PageRank order: a Web page has a high rank if other pages with a high rank link to it. \\\\\nThe algorithm is based on the \\textbf{Random Surfer Model}, in which a user goes from one page to another by randomly choosing an outgoing link through \\textbf{exploitation}. Since surfing randomly could lead to dead ends or cycles of Web pages, a random Web page is chosen through \\textbf{exploration}. The random walk generated by exploitation and exploration is known as the \\textbf{Markov chain}. \\\\ \nLet's introduce some definitions for the PageRank computation:\n\\begin{itemize}\n    \\item $n \\ = \\ $ number of Web pages\n    \\item $G \\ = \\ $ $n-$by$-n$ connectivity matrix of a Web portion with:\n        \\begin{center}\n            $g_{ij} = \n            \\begin{cases}\n                1 & \\text{hyperlink from page } j \\text{ to page } i  \\\\\n                0 & \\text{otherwise}\n            \\end{cases}$\n        \\end{center}\n    \\item $r_i \\ = \\ $ row sum of $G$ and in-degree of $j-$th page:\n        \\begin{center}\n            $r_i = \\displaystyle\\sum_j g_{ij}$\n        \\end{center}\n    \\item $c_j \\ = \\ $ column sum of $G$ and out-degree of $j-$th page:\n        \\begin{center}\n            $c_j = \\displaystyle\\sum_i g_{ij}$\n        \\end{center}\n    \\newpage\n    \\item $p \\ = \\ $ probability that the random walk follows a link\n        \\begin{itemize}\n            \\item the typical value is: $\\ p = 0.85$\n            \\item the probability that some arbitrary page is chosen is: $\\ 1 - p$\n            \\item the probability that a particular random page is chosen is:\n                \\begin{center}\n                    $\\delta = \\displaystyle\\frac{1 - p}{n}$\n                \\end{center}\n        \\end{itemize}\n    \\item $A \\ = \\ $ $n-$by$-n$ transition probability matrix of the Markov chain with:\n        \\begin{center}\n            $a_{ij} = \n            \\begin{cases}\n                p \\cdot \\frac{g_{ij}}{c_j} + \\delta & c_j \\neq 0 \\\\\n                \\frac{1}{n} & c_j = 0\n            \\end{cases}$\n        \\end{center}\n\\end{itemize}\nAll the elements in matrix $A$ are strictly between $0$ and $1$ and all the column sums are equal to $1$. \\\\\nThe \\textbf{Perron-Frobenius theorem} states that a nonzero solution of the equation\n\\begin{center}\n    $x = Ax$\n\\end{center}\nexists and is unique to within a scaling factor. If this factor is chosen so that:\n\\begin{center}\n    $\\displaystyle\\sum_i x_i = 1$,\n\\end{center}\nthen $x$ is the \\textbf{state vector} of the Markov chain and Google's PageRank. Its elements are strictly between $0$ and $1$ and it is the solution to the following linear system:\n\\begin{center}\n    $(I - A)x = 0$\n\\end{center}\nThe best way to compute PageRank in MATLAB is defining matrix $A$ as follows:\n\\begin{center}\n    $A = p GD + ez^T$, where:\n\\end{center}\n\\begin{itemize}\n    \\item $D\\ = \\ $ diagonal matrix formed from the out-degrees reciprocals:\n        \\begin{center}\n            $d_{jj} = \n            \\begin{cases}\n                1/ c_j & c_j \\neq 0 \\\\\n                0 & c_j = 0\n            \\end{cases}$\n        \\end{center}\n    \\item $e \\ = \\ $ $n-$vector of all ones\n    \\item $z \\ = \\ $ vector with:\n        \\begin{center}\n            $z_j = \n            \\begin{cases}\n                \\delta & c_j \\neq 0 \\\\\n                1/n & c_j = 0\n            \\end{cases}$\n        \\end{center}\n\\end{itemize}\nThe assignment statement can now be written as follows:\n\\begin{center}\n    $(I - pGD)x = \\lambda e$,\n\\end{center}\nwhere $ \\ \\lambda = z^Tx \\ $ has the temporary value of $1$.\n\\subsection{Power Method}\nThe \\textbf{power method} is used to compute the dominant eigenvector $\\lambda_1$ of a matrix $A$:\n\\begin{enumerate}\n    \\item Start with an initial guess vector $v_0$:\n    \\item Compute $w$ in the following way:\n    \\begin{center}\n        $w = Av_k$\n    \\end{center}\n    \\item Set $v_{k+1} = ||w||$\n    \\item Find the eigenvalue of $v_{k+1}$ by using the Rayleigh quotient\n    \\item Repeat from step $2$ incrementing $k$ by $1$ until the difference between the previous and the current eigenvectors is lower than a certain threshold\n\\end{enumerate}\nIn order to guarantee convergence, we assume that matrix $A$ has an eigenvalue $\\lambda$ whose magnitude is strictly greater than the others and that vector $x$ has a nonzero component in the direction of the eigenvector associated with $\\lambda$.\n\\subsection{Shift and Invert Method}\nSince the power method converges linearly and its error constant is $|\\lambda_2 / \\lambda_1|$, the convergence could be too slow if $||\\lambda_2||$ and $||\\lambda_1||$ are close: the \\textbf{shift and invert method} is used to improve the power method's converging rate. \\\\\nGiven a matrix $A$, we define matrix $B$ as:\n\\begin{center}\n    $B = (A - \\alpha I)^{-1}$\n\\end{center}\nThe eigenvalues of $B$ are defined as:\n\\begin{center}\n    $u_j = \\displaystyle\\frac{1}{\\lambda_j - \\alpha}$.\n\\end{center}\nBy applying the power method to matrix $B$ and assuming $\\lambda_2$ is the closest-to-$\\lambda_1$ eigenvalue of $A$, we obtain the following improved converging rate:\n\\begin{center}\n    $|\\displaystyle\\frac{u_2}{u_1}| = |\\displaystyle\\frac{\\lambda_1 - \\alpha}{\\lambda_2 - \\alpha}|$\n\\end{center}\nThe cost of a power method iteration is given by a vector-matrix product, the cost of an iteration in the shift and invert method is given by a linear system.\n\n\\newpage\n\n% ------------------------------ %\n% Assignment 2 - Social Networks\n% ------------------------------ %\n\\section{Social Networks}\n\\subsection{Cholesky Factorization}\nThe \\textbf{Cholesky factorization} is the decomposition of a symmetric, positive-definite matrix $A$ into the product of its lower triangular form $L$ and its conjugate transpose $L^T$:\n\\begin{center}\n    $A = LL^T$\n\\end{center}\nIt is twice as efficient as the LU decomposition. \n\\subsection{Reverse Cuthill McKee Ordering}\nThe \\textbf{reverse Cuthill McKee ordering} is the permutation of a symmetric sparse matrix into a banded matrix with a smaller bandwidth. The resulting matrix has the non-zero elements closer to the diagonal. \\\\\nIn MATLAB, we can use the following implementation:\n\\begin{verbatim}\n    1) r = symrcm(A(2:end, 2:end));\n    2) prcm = [1 r+1];\n\\end{verbatim}\nThis method is useful to reduce the number of fill-ins, making less expensive the Cholesky factorization.\n\\subsection{Spectral Graph Partitioning}\nIn \\textbf{spectral graph partitioning}, we plant a random partition assigning values to the probabilities of intra-sets and inter-sets edges, then use the \\textbf{Fiedler's vector}, which is the eigenvector $v_2$ associated with the second smallest eigenvalue $\\lambda_2$, to find the partition. \\\\\nIn the Fiedler's vector, all indices of entries $ > 0$ belong to one set and those of entries $< 0$ belong to the other. The partition minimizes the number of edges between the sets.\n\\subsection{Degree Centrality}\nThe \\textbf{degree centrality} consists of ranking the number of incident links upon a node. For a given graph $G = (V,E)$ it is defined as the number of edges of a vertex $v$. \\\\\nThe \\textbf{eigenvector centrality} measures the influence of a node in a network. The relationships between nodes with a high score contribute more to the node score.\n\n% --------------------------------- %\n% Assignment 3 - Graph Partitioning\n% --------------------------------- %\n\\section{Graph Partitioning}\n\\subsection{Graphs Matrices}\n\\subsubsection{Degree Matrix}\nA \\textbf{degree matrix} $D$ is a diagonal matrix containing the degree of each vertex. If the graph is weighted, the entries are the sum of all the weights of the connected edges.\n\\subsubsection{Adjacency Matrix}\nAn \\textbf{adjacency matrix} is a square matrix representing the connections of an unweighted graph and its entries are defined as follows:\n\\begin{center}\n    $a_{ij} = \n    \\begin{cases}\n        1 & v_i \\text{ connected to } v_j \\\\\n        0 & \\text{otherwise}\n    \\end{cases}$\n\\end{center}\n\\subsubsection{Weight Matrix}\nA \\textbf{weight matrix} $W$ is a square matrix representing the connections of a weighted graph and its entries are defined as follows:\n\\begin{center}\n    $w_{ij} = \n    \\begin{cases}\n        w & v_i \\text{ connected to } v_j \\\\\n        0 & \\text{otherwise}\n    \\end{cases}$\n\\end{center}\n\\subsubsection{Laplacian Matrix}\nThe \\textbf{Laplacian matrix} $L$ is the matrix representation of a graph and is computed in the following ways:\n\\begin{itemize}\n    \\item For an undirected and unweighted graph\n        \\begin{center}\n            $L = D - A $\n        \\end{center}\n    \\item For an undirected and weighted graph\n        \\begin{center}\n            $L = D - W $\n        \\end{center}\n\\end{itemize}\nMatrix $L$ only has real and non-negative eigenvalues and its eigenvectors are real and orthogonal.\n\\subsection{Graph Partitioning}\nThe \\textbf{graph partitioning} problem is defined on a graph $G = (V, E) $ such that it is possible to partition $G$ into smaller components with specific properties, generally with small cuts and equal-size partitions.\n\\subsection{Spectral Bisection}\n\\textbf{Spectral bisection} enables the decomposition of a symmetric matrix into eigenvalues within an orthonormal base of eigenvectors. The following procedure performs a spectral bisection:\n\\begin{enumerate}\n    \\item Compute the Laplacian matrix $L$\n    \\item Compute the Fiedler's vector $w_2$\n    \\item Set a threshold to $0$ or to the median of $w_2$\n    \\item Choose $V_1 = \\{v_i \\in V | w_i < \\text{threshold}\\}$ and $V_2 = \\{v_i \\in V | w_i \\geq \\text{threshold}\\}$\n    \\item Return $V_1$ and $V_2$\n\\end{enumerate}\nThresholding the values of $w_2$ around $0$ results in two roughly equal-sized partitions with minimum edgecut, while thresholding around the median value of $w_2$ produces two strictly balanced partitions.\n\\subsection{Inertial Bisection}\n\\textbf{Inertial bisection} relies on the vertices' geometric coordinates: it finds the hyperplane running through the center of mass of the points. \\\\\nIn $2D$, the line is chosen such that the sum of squares of the distances of the nodes to the line is minimized. \\\\\nThe following procedure performs an inertial bisection:\n\\begin{enumerate}\n    \\item Compute the center of mass of the points as follows:\n        \\begin{center}\n            $x = \\displaystyle\\frac{1}{n} \\displaystyle\\sum_{i = 1}^n x_i \\ \\ \\ \\ \\ y = \\displaystyle\\frac{1}{n}\\displaystyle\\sum_{i = 1}^n y_i$\n        \\end{center}\n    \\item Compute matrix $M$ as follows:\n        \\begin{center}\n            $S_{xx} = \\displaystyle\\sum_{i = 1}^n(x_i - x)^2 \\ \\ \\ \\ S_{yy} = \\displaystyle\\sum_{i = 1}^n(y_i - y)^2 \\ \\ \\ \\ S_{xy} = \\displaystyle\\sum_{i = 1}^n((x_i - x)(y_i - y))$ \\\\\n            \\vspace{0.5cm}\n            $ M = \n            \\begin{bmatrix}\n                S_{xx} & S_{xy} \\\\\n                S_{xy} & S_{yy}\n            \\end{bmatrix}$\n        \\end{center}\n    \\item Compute the smallest eigenvalue of matrix $M$ and the associated eigenvector $u$ \\item Minimize the distance of the nodes to the line:\n        \\begin{center}\n            $u^TMu$\n        \\end{center}\n    \\item Project each point to the line and compute the median to partition the nodes\n    \\item Return $V_1$ and $V_2$\n\\end{enumerate}\n\\subsection{Recursive Bisection}\n\\textbf{Recursive bisection} depends on the decisions made during the earlier stages of the process and lacks of global information, meaning that it may result in suboptimal partitions.\n\\subsection{$K-$Way Partitioning}\n\\textbf{$K-$way partition} starts with partitioning a small set of vertices, then projects it back towards the original set to refine it. The main difference with recursive bisection is that $k-$way partitioning stores global information about the graph.\n\\subsection{Partitioning Metrics}\nThe number of cut edges between partitions determines the result's quality. The size of an \\textbf{edgecut} partitioning the graph into two complementary vertices subsets is defined as follows:\n\\begin{center}\n    $cut(V_1,V_2) = \\displaystyle\\sum_{i \\in V_1, j \\in V_2} w_{ij}$\n\\end{center}\nThe \\textbf{cardinality}, i.e. the number of nodes, of each subset is given by:\n\\begin{center}\n    $x^Tx = ||x||_2^2 = |V_1|$\n\\end{center}\nLet $\\Tilde{V}$ be the average partition weight, then for a $k-$way partition the \\textbf{load imbalance} $b^k$ is defined as follows:\n\\begin{center}\n    $b^k = max_{|V_i^k|} \\ \\ \\displaystyle\\frac{|V_i^k|}{|\\Tilde{V}^k|}$ \\\\\n    \\vspace{0.3cm}\n    $b^k = 1 + b^k_r \\geq 1$ \\\\\n    \\vspace{0.35cm}\n    $b^k_r \\geq 0 $\n\\end{center}\nIt characterizes the deviation from obtaining a balanced partitioning. \\\\\nThe optimal value for $b^k_r$ is $0$ and implies that the $k$ partitions contain the same number of nodes.\n\n\\newpage\n\n% ---------------------------------------- %\n% Assignment 4 - Spectral Graph Clustering\n% ---------------------------------------- %\n\\section{Spectral Graph Clustering}\n\\subsection{Graph Clustering}\nGiven a set of data points $x_1,...,x_n$ and some notion of similarity $s_{ij} \\geq 0$, clustering extracts information by grouping similar data points.\n\\subsection{Trees}\nA \\textbf{tree} is an undirected graph in which any two vertices are connected by exactly one path. A \\textbf{minimum spanning tree} is a subgraph including all the vertices of the graph, the minimum possible number of edges and the minimum possible total weight.\n\\subsection{Similarity Graphs}\nIn \\textbf{similarity graphs} two vertices $v_i$ and $v_j$ are connected based on the similarity $s_{ij}$ between the corresponding data points $x_i$ and $x_j$. The edge between them is weighted by $s_{ij}$. \\\\\nThe goal is to model the neighborhood relationships between the data points.\n\\subsubsection{$\\epsilon-$Neighborhood Graph}\nIn $\\epsilon-$neighborhood graphs, we connect two vertices if their pairwise distances are smaller than $\\epsilon$. Weighting the edges would not incorporate more information about the data to the graph, thus they are unweighted.\n\\subsubsection{$k-$Nearest Neighbor Graphs}\nIn \\textbf{$k-$nearest neighbor graphs}, we connect vertices $v_i$ and $v_j$ if the latter is among the $k-$nearest neighbors of the first. The graph is directed and we have two ways to make it undirected: either we ignore the directions obtaining a simple $k-$nearest neighbors graph, or we connect the vertices if each of them is among the $k-$nearest neighbors of the other, obtaining a \\textbf{mutual $k-$nearest neighbors graph}.\n\\subsubsection{Fully Connected Graph}\nIn \\textbf{fully connected graphs}, we connect two vertices if the similarity $s_{ij} > 0$. This construction is useful only if the similarity function models local neighborhoods.\n\\newpage\n\\subsection{Spectral Clustering}\nIn \\textbf{spectral clustering}, we create clusters with the same number of nodes through the following procedure:\n\\begin{enumerate}\n    \\item Compute the minimum spanning tree to determine $\\epsilon$\n    \\item Create the $\\epsilon-$neighbourhood graph\n    \\item Compute the adjacency matrix $W$ as follows:\n    \\begin{center}\n        $W = S \\odot G$\n    \\end{center}\n    \\item Compute the Laplacian matrix\n    \\item Compute the $k-$smallest eigenvectors based on $L$\n    \\item Use k-means algorithm to cluster the nodes\n    \\item Use the eigenvector matrix in order to obtain the clusters\n\\end{enumerate}\n\\subsection{K-Means Clustering}\nThe \\textbf{k-means clustering} divides the clusters based on the distance between a node and a \\textbf{centroid}, which represents the center of a cluster. The algorithm is the following:\n\\begin{enumerate}\n    \\item Start with some random centroids\n    \\item Assign each node to the nearest cluster based on its centroid\n    \\item Recompute the centroids as the mean of the points in the cluster\n    \\item Repeat from step $2$ until no further improvement can be made\n\\end{enumerate}\n\n\\newpage\n\n% ------------------------------------------------------ %\n% Assignment 5 - Image Deblurring and Conjugate Gradient\n% ------------------------------------------------------ %\n\\section{Image Deblurring and Conjugate Gradient}\n\\subsection{Blurred Image Problem Definition}\nLet matrix $B \\in \\mathbb{R}^{n^2 \\times n^2}$ be a blurred image we want to deblur given the transformation and let $X \\in \\mathbb{R}^{n \\times n}$ be the original square and greyscale image matrix where each entry corresponds to a pixel value. We can perform \\textbf{vectorization} by converting matrix $X$ into a column vector $x \\in \\mathbb{R}^{n^2}$ and matrix $B$ into vector $b \\in \\mathbb{R^{n^2}}$. \\\\\nWe can write the following equation:\n\\begin{center}\n    $Ax = b$,\n\\end{center}\nwhere $A \\in \\mathbb{R}^{n^2 \\times n^2}$ indicates the transformation matrix coming from the repeated application of the image kernel. A blurred pixel is the weighted average of the surrounding ones, with the weights defined by the kernel matrix $K \\in \\mathbb{R}^{d\\times d}$. The non-zero elements of each row of matrix $A$ correspond to the values of matrix $K$.\nMatrix $A$ ignores the elements outside the matrix borders:\n\\begin{center}\n    $(max(i, j) > n)$\n\\end{center}\nMatrix $A$ is a $d^2-$banded matrix, where:\n\\begin{center}\n    $d << n$,\n\\end{center}\nmeaning that matrix $A$ is sparse.\n\\subsection{Direct and Iterative Methods}\nSince the complexity of Gaussian elimination for large linear systems is too high, we need another approach: we use \\textbf{direct methods} to compute the exact solution in $n$ steps, while we use \\textbf{iterative methods} with an arbitrary starting point to compute an approximate solution. Iterative methods converge after a few iterations, but they are less robust and not as general as direct ones.\n\\subsection{Error and Residual}\nLet $x$ be an exact solution and $x^m$ be the computed point, then the \\textbf{error} in step $m$ is the deviation of the computed point from the exact solution:\n\\begin{center}\n    $e^{m} = x - x^m$,\n\\end{center}\nThe error is not known during the iterations, otherwise we would know the solution. \\\\\nThe \\textbf{residual} provides us with a measure of the real error:\n\\begin{center}\n    $r^m = b - Ax^m$\n\\end{center}\n\\newpage\n\\subsection{Steepest Descent}\nThe \\textbf{steepest descent} algorithm is a precursor to the Conjugate Gradient algorithm that performs the following procedure:\n\\begin{enumerate}\n    \\item Start with a random initial guess\n    \\item Take the \\textbf{gradient}, i.e. the direction of the deepest descent\n    \\item Compute the minimum of the gradient\n    \\item Take the new gradient such that it is orthogonal to the previous one\n    \\item Repeat from step $2$ until a certain convergence criterion is met\n\\end{enumerate}\nThis algorithm has a low convergence rate, but it does not take optimal steps to find the next approximate solution.\n\\subsection{Conjugate Gradient}\nThe \\textbf{conjugate gradient method} is used to solve equations of the type:\n\\begin{center}\n    $Ax = b$,\n\\end{center}\nwhere $A$ is symmetric and positive-definite. It can be used as an iterative method since it provides monotonically improving approximations $x_k$ to the exact solution after each iteration, with a number of iterations not larger than the size of the matrix, in the absence of round-off error. The improvement is typically linear and its speed is determined by the \\textbf{condition number} $\\kappa(A)$ of the matrix $A$: \n\\begin{center}\n    $\\kappa(A) = \\displaystyle\\frac{\\sigma_{max}}{\\sigma_{min}}$,\n\\end{center}\nwith $\\sigma$ indicating the singular values of $A$. For a real symmetric matrix, the values are equal to the eigenvalues absolute value:\n\\begin{center}\n    $\\sigma = |\\lambda|$ \\\\\n\\end{center}\nThe larger the condition number is, the slower the improvement.\n\\newpage\nThe algorithm starts from an initial guess $x_0$ and applies a series of operations until the desired tolerance is reached:\n\\begin{enumerate}\n    \\item $r = b - Ax_0$\n    \\item $d = r$\n    \\item $\\rho_{old} = <r,r>$\n    \\item $for \\ i = 0,1,... \\ do:$\n    \\begin{enumerate}[label=\\arabic*.]\n        \\item $ s = A \\cdot d_i$\n        \\item $\\alpha = \\rho_{old} / <d,s>$\n        \\item $x = x + \\alpha \\cdot d$\n        \\item $r = r - \\alpha \\cdot s$\n        \\item $\\rho_{new} = <r,r>$\n        \\item $\\beta = \\rho_{new} / \\rho_{old}$\n        \\item $d = r + \\beta \\cdot d$\n        \\item $\\rho_{old} = \\rho_{new}$\n    \\end{enumerate} \n    \\item $end \\ for$\n\\end{enumerate}\n\\vspace{0.2cm}\nSince matrix $A$ is not positive-definite we must solve the following equations:\n\\begin{center}\n    $A^TAx = A^Tb \\ \\rightarrow \\ \\Tilde{A}x = \\Tilde{b}$\n\\end{center}\nThe pre-multiplication with $A^T$ results in the positive-definite augmented transformation matrix $\\Tilde{A}$. \\\\\nThe condition number is the relation of the sensitivity of the solution $x$ to changes in $b$: if small changes result in large changes in $x$, then the system is \\textbf{ill-conditioned} and its condition number is large. The convergence rate of the algorithm is hindered when the system has a high condition number.\n\\subsection{Preconditioned Conjugate Gradient}\nIn the \\textbf{preconditioned conjugate gradient method} (PCG), a symmetric and positive-definite \\textbf{preconditioner} $P$ is selected such that:\n\\begin{center}\n    $P^{-1} \\Tilde{A} \\approx I$\n\\end{center}\nFurthermore, we can decompose the preconditioner such that:\n\\begin{center}\n    $P = LL^T$,\n\\end{center}\nwhere $L$ is the Cholesky factor.\n\\newpage\nNow we have to solve the preconditioned augmented system:\n\\begin{center}\n    $P^{-1}\\Tilde{A}x = P^{-1}\\Tilde{b}$ \\\\\n    \\vspace{0.25cm}\n    $(L^{-1}\\Tilde{A}L^{-1})(Lx) = L^{-1}\\Tilde{b}$\n\\end{center}\nThis is done to decrease the condition number and the range of the eigenvalues. The preconditioner should be computationally inexpensive to find.\nWe can use the \\textbf{incomplete Cholesky factorization} to compute the Cholesky factorization of the non-zero elements of $\\Tilde{A}$, returning the following preconditioner: \n\\begin{center}\n    $P = F^TF$,\n\\end{center}\nwhere $F$ is the sparse incomplete Cholesky factor. Due to the fact that the routine fail since the existence of $F$ is not guaranteed, a heuristic approach is used to apply a diagonal shift of $P$, enforcing positive-definiteness and making $F$ computable. \\\\\nPCG would be worth the added computational cost whether the conditional number $\\kappa(A)$ is large, i.e. matrix $A$ is ill-conditioned since with CG it will require a lot of iterations. While deblurring lots of images with PCG, the computational cost would decrease since it is possible to use the same precondition in order to save time.\n\n\\newpage\n\n% -------------------------------------------------------- %\n% Assignment 6 - Linear Programming and the Simplex Method\n% -------------------------------------------------------- %\n\\section{Linear Programming and the Simplex Method}\n\\subsection{Linear Programming}\n\\textbf{Linear Programming} is an optimization technique used to either maximize or minimize a linear objective function subject to linear equality and inequality constraints. An example of a linear program is the following:\n\\begin{align*}\n\t\\max~~ & \\sum_{i = 1}^n c_ix_i \\\\\n\t\\text{s.t.}~~ & \\sum_{j = 1}^n a_{1,j}x_j \\leq h_1 \\\\\n\t~~&~~ \\vdots \\\\\n\t~~& \\sum_{j = 1}^n a_{m,j}x_j \\leq h_m\n\\end{align*}\nVector $x_i$ must satisfy some constraints and the non-negativity condition. \\\\\nLinear programming problems can be written in the following \\textbf{standard form}:\n\\begin{equation*}\n  \\begin{split}\n    \\max~~ & z = c^Tx \\\\\n\t\\text{s.t.}~~ & Ax \\leq h \\\\\n\t~~& x \\geq 0\n  \\end{split}\n\\quad\\quad\\quad\\quad\n  \\begin{split}\n    \\min~~ & z = c^Tx \\\\\n\t\\text{s.t.}~~ & Ax \\geq h \\\\\n\t~~& x \\geq 0\n  \\end{split}\n\\end{equation*} \\\\\nwhere $z $ is the value of the objective function, $c \\in \\mathbb{R}^n$ is the coefficients vector, $x \\in \\mathbb{R}^n$ is the unknowns vector, $A \\in \\mathbb{R}^{m \\times n}$ is the coefficients matrix, and $h \\in \\mathbb{R}^m$ is the vector of the constraints coefficients. \\\\\nGiven that the \\textbf{feasible region} is generated by the vertices that satisfy the constraints, the optimal value can be found with the \\textbf{Fundamental Theorem of Linear Programming}: \\\\ \\\\\n\\textbf{Theorem 1} \\textit{If a linear program admits a solution, it will lie on a vertex of the polytope defined by the feasible region. If two vertices are both maximizers or minimizers of the function, then all the points lying on the segment between them will represent the optimal solutions to the problem.}\n\\subsection{The Simplex Method}\nSince computing the value of $z$ at all the vertices of the feasible region could be expensive, we use the \\textbf{simplex method}, which has an exponential worst-case complexity.\n\\newpage\n\\subsubsection{Slack and Surplus Variables}\nThe method introduces \\textbf{slack variables} for maximization and \\textbf{surplus variables} for minimization to the standard form of the problem, denoting them with $s_m$ as in the following example:\n\\begin{equation*}\n  \\begin{split}\n  \t\\max~~ & z = 3x+2y \\\\\n\t\\text{s.t.}~~ & x+2y+s_1 = 4 \\\\\n\t~~& x-y+s_2 = 1 \\\\\n\t~~& x,y \\geq 0; \\ ~ s_1, s_2 \\geq 0\n  \\end{split}\n\\quad\\quad\\quad\\quad\n  \\begin{split}\n    \\min~~ & z = 3x+2y \\\\\n\t\\text{s.t.}~~ & x+2y-s_1 = 4 \\\\\n\t~~& x-y-s_2 = 1 \\\\\n\t~~& x,y \\geq 0;~ \\ s_1, s_2 \\geq 0\n  \\end{split}\n\\end{equation*}\n\\subsubsection{Basic and Nonbasic Variables}\nWe can swap the rows of matrix $A$ as long as we swap the elements of vector $h$. Furthermore, we can swap the columns of matrix $A$ as long as we swap the elements of vector $x$. Matrix $A$ can be split in two submatrices:\n\\begin{center}\n    $A = [B \\ D]$,\n\\end{center}\nwhere matrix $B$ contains the linearly independent columns of $A$, while matrix $D$ contains the remaining ones. We can split vectors $x$ and $c$ in the same way:\n\\begin{center}\n    $x =\n    \\begin{bmatrix}\n    x_B \\\\\n    x_D\n    \\end{bmatrix}\n    ~~~~ c =\n    \\begin{bmatrix}\n    c_B \\\\\n    c_D\n    \\end{bmatrix}$\n\\end{center}\nFinally, we obtain the following relation:\n\\begin{center}\n    $x_B = B^{-1}h - B^{-1}Dx_D$\n\\end{center}\nVector $x_B$ contains the \\textbf{basic variables}, while vector $x_D$ contains the \\textbf{nonbasic variables}. By setting $ \\ x_D = 0 \\ $, we obtain the following equation:\n\\begin{center}\n    $x_B = B^{-1}h$,\n\\end{center}\nand if the non-negativity condition for $x_B$ is satisfied, then this is a \\textbf{basic solution} and corresponds to the feasible region. If $x_B$ has some zero values, then the solution is \\textbf{degenerate}. \\\\\nThe existence of a feasible solution implies the existence of a feasible basic solution, and the existence of an optimal solution implies the existence of an optimal basic solution. \\\\\nThe number of possible basic solutions grows exponentially with unknowns and constraints. The maximum possible number of iteration $N$ is:\n\\begin{center}\n    $N = \\displaystyle\\frac{(m +n)!}{m! n!}$\n\\end{center}\n\\subsubsection{Optimality Condition}\nWe must check if the solution satisfies the \\textbf{optimality condition}, based on the basis of the \\textbf{reduced cost coefficients}, at every iteration:\n\\begin{center}\n    $r_D = c_D^T - c_B^T B^{-1}D$,\n\\end{center}\nwhere $c_B$ is the basic coefficient vector, $c_D$ is the nonbasic coefficient vector, $B$ is the basic matrix, and $D$ is the nonbasic matrix. \\\\\nThe optimality condition for maximization is $r_D \\leq 0$, while it is $r_D \\geq 0$ for minimization. Both are satisfied when all the components of the reduced cost coefficients vectors are less or bigger than $0$, respectively.\n\\subsubsection{Iterative Rule}\nIf the optimality condition is not met, we take the variable with the highest reduced cost coefficient, in the case of maximization, or the variable with the lowest cost coefficient, in the case of minimization, into the basis. \\\\\nIf two variables have the same value, we could end up swapping them over and over again creating a \\textbf{cycle}. The \\textbf{iterative rule} identifies the variables that must be taken out of the basis:\n\\begin{center}\n    $\\displaystyle\\frac{B^{-1}h}{B^{-1}D}$\n\\end{center}\nWe select the ratio with the smallest positive value.\n\\subsubsection{Simplex Method Procedure}\nThe method procedure can be summarized as follows:\n\\begin{enumerate}\n    \\item Write the problem in standard form\n    \\item Add slack or surplus variables\n    \\item Apply the iterative rule by exchanging basic with nonbasic variables\n    \\item Repeat from step $3$ until the optimality condition is met\n\\end{enumerate}\n\\subsection{The Auxiliary Problem}\nWe could find a feasible initial basic solution by solving an \\textbf{auxiliary problem}, which can be defined by introducing the \\textbf{artificial variables} $u_m$:\n\\begin{align*}\n\t\\max~~ & z_{\\text{aux}} = \\sum_{i = 1}^n u_i \\\\\n\t\\text{s.t.}~~ & \\sum_{j = 1}^n a_{1,j}x_j+s_1+u_1 = h_1 \\\\\n\t~~&~~ \\vdots \\\\\n\t~~& \\sum_{j = 1}^n a_{m,j}x_j+s_m+u_m = h_m \\\\\n\t~~& x_i, ..., x_n \\geq 0;~ s_1, ..., s_m \\geq 0;~ u_1, ..., u_m \\geq 0\n\\end{align*}\nThe auxiliary problem aims at minimizing the sum of artificial variables and its optimal solution would be achieved when all the artificial variables are $ = 0$. If $z_{aux} = 0$ is not achieved, then the auxiliary problem and the original problem do not admit a feasible solution. \\\\\nIn order to obtain a starting basic solution for the auxiliary problem, we can set the original and the slack variables to $0$ and the artificial variables equal to the right-hand side.\n\n\\end{document}\n", "meta": {"hexsha": "d8c2c0203d625409e4e2bc3111abad23684f9ecb", "size": 30439, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Numerical Computing/nc_cheatsheet.tex", "max_stars_repo_name": "matteoalberici4/computer-science-cheatsheets", "max_stars_repo_head_hexsha": "5f2b9a6a4bd06f7a39dec198525b441a4f6a4399", "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": "Numerical Computing/nc_cheatsheet.tex", "max_issues_repo_name": "matteoalberici4/computer-science-cheatsheets", "max_issues_repo_head_hexsha": "5f2b9a6a4bd06f7a39dec198525b441a4f6a4399", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Numerical Computing/nc_cheatsheet.tex", "max_forks_repo_name": "matteoalberici4/computer-science-cheatsheets", "max_forks_repo_head_hexsha": "5f2b9a6a4bd06f7a39dec198525b441a4f6a4399", "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.2643253235, "max_line_length": 434, "alphanum_fraction": 0.6972305266, "num_tokens": 8370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.7944090903998727}}
{"text": "\\section{Bottleneck structure in MgNet by using subspace correction}\nRecall the standard MgNet iteration\n\\begin{equation}\\label{eq:mgnetiteration}\nu^{\\ell,i} = u^{\\ell,i-1} + \\sigma \\circ B^{\\ell,i} \\ast \\sigma ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}),\n\\end{equation}\nwhich corresponds to the classical residual correction scheme in multigrid as\n\\begin{equation}\\label{key}\nu^{\\ell,i} = u^{\\ell,i-1} + B^{\\ell,i} ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n\\end{equation}\n\nNow let us recall the subspace correction scheme on a fixed level (for example $\\ell$-th level),\nwe have the following iterative scheme \n\\begin{equation}\\label{eq:bottleneckmgnet}\nu^{\\ell,i} = u^{\\ell,i-1} + P^{\\ell,i} B^{\\ell,i} R^{\\ell,i}({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n\\end{equation}\n\nHere let us recall the dimension of $f^\\ell$ and $u^{\\ell,i}$ as\n\\begin{equation}\\label{key}\nf^\\ell, u^{\\ell,i} \\in \\mathbb{R}^{c_\\ell \\times m_\\ell \\times n_\\ell },\n\\end{equation}\nwhich leads to the dimension of $B^{\\ell,i}$ in standard MgNet in \\eqref{eq:mgnetiteration} to be\n\\begin{equation}\\label{key}\nB^{\\ell,i} \\in \\mathbb{R}^{c_\\ell \\times c_\\ell \\times 3 \\times 3}.\n\\end{equation}\n\n\n\nHowever, for a subspace correction scheme, we can take $R^{\\ell,i}$ as the restriction operator as\n\\begin{equation}\\label{key}\nR^{\\ell,i}: \\mathbb{R}^{c_\\ell \\times m_\\ell \\times n_\\ell } \\mapsto \\mathbb{R}^{ \\alpha c_\\ell \\times m_\\ell \\times n_\\ell },\n\\end{equation}\nwhere $\\alpha \\in (0,1]$ so example $\\alpha = \\frac{1}{4}$. \nA rational choice for $R^{\\ell,i}$ and $P^{\\ell,i}$ should be\n\\begin{equation}\\label{key}\nR^{\\ell,i} \\in \\mathbb{R}^{\\alpha c_\\ell \\times c_\\ell \\times 1 \\times 1},\n\\end{equation}\nand \n\\begin{equation}\\label{key}\nP^{\\ell,i} \\in \\mathbb{R}^{ c_\\ell \\times \\alpha c_\\ell \\times 1 \\times 1}.\n\\end{equation}\nOf course, we can just take the $R^{\\ell,i} = [P^{\\ell.i}]^T$ based on the \ntheory of subspace corrections. \n\nThen, the size of $B^{\\ell,i}$ in \\eqref{eq:bottleneckmgnet} can be reduced to\n\\begin{equation}\\label{key}\nB^{\\ell,i} \\in \\mathbb{R}^{\\alpha c_\\ell \\times\\alpha c_\\ell \\times 3 \\times 3}.\n\\end{equation}\nThus the dimension of all operations $R^{\\ell,i}$, $P^{\\ell,i}$ and $B^{\\ell,i}$ will be\n\\begin{equation}\\label{key}\n\\begin{aligned}\n&\\alpha c_\\ell \\times c_\\ell \\times 1 \\times 1 +  c_\\ell \\times \\alpha c_\\ell \\times 1 \\times 1 + \\alpha c_\\ell \\times\\alpha c_\\ell \\times 3  \\times 3 \\\\ \n&= ((3\\alpha)^2 +  2\\alpha) c_\\ell^2\\\\\n&= \\frac{17}{16} c_\\ell^2 \\quad ( \\alpha = \\frac{1}{4}),\n\\end{aligned}\n\\end{equation}\nwhich is much less than the size of $B^{\\ell,i}$ in original MgNet in~\\eqref{eq:mgnetiteration} which\nis $9c_\\ell^2$.\n\nTo follow the linear constrained model assumption, we may take the nonlinearity as\n \\begin{equation}\\label{eq:bottleneckmgnet-1}\n u^{\\ell,i} = u^{\\ell,i-1} +   \\sigma \\circ P^{\\ell,i} \\ast  \\sigma \\circ B^{\\ell,i} \\ast  \\sigma \\circ R^{\\ell,i} \\ast \\sigma ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,i-1}}).\n \\end{equation}\n \n Following the similar derivation from MgNet to ResNet, we can also derive\n the next \"enhanced\" bottleneck ResNet from \\eqref{eq:bottleneckmgnet-1} as\n \\begin{equation}\\label{key}\n  r^{\\ell,i} = r^{\\ell,i-1} -  A^\\ell \\ast \\sigma \\circ   P^{\\ell,i} \\ast  \\sigma \\circ B^{\\ell,i} \\ast  \\sigma \\circ R^{\\ell,i} \\ast \\sigma (r^{\\ell,i-1}).\n \\end{equation}\n\n", "meta": {"hexsha": "4c86c2da5c0d1e6423b8ab31873d79016f245561", "size": 3311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Bottleneck-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/Bottleneck-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/Bottleneck-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": 47.3, "max_line_length": 168, "alphanum_fraction": 0.6590154032, "num_tokens": 1251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533163686646, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7944062173374472}}
{"text": "\\subsection{Test 2 Answers}\r\n\\begin{enumerate}[label=\\arabic*.]\r\n\t\\item\r\n\t\tFor both (a) and (b), we'll need to compute the general solution to make sure any terms that we'd guess as part of the particular solution aren't already part of the general solution.\r\n\t\tThe auxiliary equation and its roots are\r\n\t\t\\begin{equation*}\r\n\t\t\tr^2 + 10r + 25 \\implies r = -5 \\text{ (double root)}.\r\n\t\t\\end{equation*}\r\n\t\tSo, the general solution is\r\n\t\t\\begin{equation*}\r\n\t\t\tC_1e^{-5t} + C_2te^{5t}.\r\n\t\t\\end{equation*}\r\n\t\t\\begin{enumerate}[label=(\\alph*)]\r\n\t\t\t\\item\r\n\t\t\t\tWe have a trig term and a linear term times a trig term, so the particular solution has the form\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_p = A\\cos{(-5t)} + B\\sin{(-5t)} + Ct\\cos{(-5t)} + Dt\\sin{(-5t)}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, without solving for $A$, $B$, $C$, and $D$, the general form of a particular solution is\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tC_1e^{-5t} + C_2te^{5t} + A\\cos{(-5t)} + B\\sin{(-5t)} + Ct\\cos{(-5t)} + Dt\\sin{(-5t)}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\tWe have a linear term time $e^{-5t}$.\r\n\t\t\t\tHowever, up to linear terms are already represented in the general solution, so we need to include another factor of $t$.\r\n\t\t\t\tSo, the particular solution has the form\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_p = At^2e^{-5t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, without solving for $A$, the general form of a particular solution is\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tC_1e^{-5t} + C_2te^{5t} + At^2e^{-5t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\\end{enumerate}\r\n\t\\item\r\n\t\tFinding $p(\\lambda)$,\r\n\t\t\\begin{equation*}\r\n\t\t\tp(\\lambda) = \\det\\begin{bmatrix}\r\n\t\t\t\t1 & 0 & 6 \\\\\r\n\t\t\t\t3 & 1 & 3 \\\\\r\n\t\t\t\t-3 & 3 & -8\r\n\t\t\t\\end{bmatrix} = -\\lambda^3 - 6\\lambda^2 + 6\\lambda + 55.\r\n\t\t\\end{equation*}\r\n\t\tSo, $p(\\lambda) = 0$ when\r\n\t\t\\begin{equation*}\r\n\t\t\t\\lambda = -5, \\frac{-1 \\pm 3\\sqrt{5}}{2}.\r\n\t\t\\end{equation*}\r\n\t\tWe'll find the eigenvector for $\\lambda = -5$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left[\r\n\t\t\t\t\\begin{array}{ccc|c}\r\n\t\t\t\t\t6 & 0 & 6 & 0\\\\\r\n\t\t\t\t\t3 & 6 & 3 & 0\\\\\r\n\t\t\t\t\t-3 & 3 & 3 & 0\r\n\t\t\t\t\\end{array}\r\n\t\t\t\\right] \\to \\left[\r\n\t\t\t\t\\begin{array}{ccc|c}\r\n\t\t\t\t\t1 & 0 & 1 & 0 \\\\\r\n\t\t\t\t\t0 & 1 & 0 & 0 \\\\\r\n\t\t\t\t\t0 & 0 & 0 & 0\r\n\t\t\t\t\\end{array}\r\n\t\t\t\\right] \\implies \\vec{v} = t\\begin{bmatrix}\r\n\t\t\t\t-1 \\\\\r\n\t\t\t\t0 \\\\\r\n\t\t\t\t1\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item\r\n\t\tThe instructions say only do one, but we'll do both for the answers.\r\n\t\t\\begin{enumerate}[label=(\\alph*)]\r\n\t\t\t\\item\r\n\t\t\t\tThe auxiliary equation and its roots are\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tr^2 - 5r + 6 = 0 \\implies r = 2, 3.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, the homogeneous solution is\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_h = C_1e^{2t} + C_2e^{3t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tWe use the method of undetermined coefficients to find $y_p$.\r\n\t\t\t\tWe'll guess that $y_p$ has the form\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_p = Ae^{4t} + Be^{t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSolving for $A$ and $B$\\footnote{The algebra of solving for $A$ and $B$ have been omitted for brevity.},\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_p'' - 5y_p' + 6y_p = 6e^{4t} - 10e^t \\implies A = 3, B = -5.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, we can write the particular solution\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_p = 3e^{4t} - 5e^{t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, the general solution is\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty = C_1e^{2t} + C_2e^{3t} + 3e^{4t} - 5e^{t}.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\\item\r\n\t\t\t\tAlthough this is a second-order equation, we'll do the version of variation of parameters that also works for higher orders too.\r\n\t\t\t\tFirst, we need to find our fundamental solutions that are part of the homogeneous solution by finding the roots of the auxiliary equation.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tr^2 + 9 = 0 \\implies r = \\pm 3i.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tSo, the homogeneous solution is\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty_h = C_1\\cos{(3t)} + C_2\\sin{(3t)},\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tand the fundamental solutions are\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\ty_1 &= \\cos{(3t)} \\\\\r\n\t\t\t\t\ty_2 &= \\sin{(3t)}.\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\tSo, the Wronskian matrix and its determinant are\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\left[W\\right] = \\begin{bmatrix}\r\n\t\t\t\t\t\t\\cos{(3t)} & \\sin{(3t)} \\\\\r\n\t\t\t\t\t\t-3\\sin{(3t)} & 3\\cos{(3t)}\r\n\t\t\t\t\t\\end{bmatrix} \\text{, } W = 3\\cos^2{(3t)} + 3\\sin^2{(3t)} = 3.\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tThe sub-matrices are\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\tW_1 &= \\det\\begin{bmatrix}\r\n\t\t\t\t\t\t0 & \\sin{(3t)} \\\\\r\n\t\t\t\t\t\t1 & 3\\cos{(3t)}\r\n\t\t\t\t\t\\end{bmatrix} = -\\sin{(3t)} \\\\\r\n\t\t\t\t\t W_2 &= \\det\\begin{bmatrix}\r\n\t\t\t\t\t\t\\cos{(3t)} & 0 \\\\\r\n\t\t\t\t\t\t-3\\sin{(3t)} & 1\r\n\t\t\t\t\t\\end{bmatrix} = \\cos{(3t)}.\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\tSolving for $v_1$ and $v_2$,\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\tv_1 &= \\int{\\frac{-\\csc{(3t)}\\sin{(3t)}}{3} \\mathrm{d}t} = \\frac{-1}{3}t + C_1 \\\\\r\n\t\t\t\t\tv_2 &= \\int{\\frac{\\csc{(3t)}\\cos{(3t)}}{3} \\mathrm{d}t} = \\frac{1}{9}\\ln{\\abs{\\sin{(3t)}}} + C_2.\r\n\t\t\t\t\\end{align*}\r\n\t\t\t\tSolving for $y$,\r\n\t\t\t\t\\begin{align*}\r\n\t\t\t\t\ty &= \\cos{(3t)}\\left(\\frac{-1}{3}t + C_1\\right) + \\sin{(3t)}\\left(\\frac{1}{9}\\ln{\\abs{\\sin{(3t)}}} + C_2\\right) \\\\\r\n\t\t\t\t\t&= C_1\\cos{(3t)} + C_2\\sin{(3t)} - \\frac{1}{3}t\\cos{(3t)} + \\frac{1}{9}\\sin{(3t)}\\ln{\\abs{\\sin{(3t)}}}.\r\n\t\t\t\t\\end{align*}\r\n\t\t\\end{enumerate}\r\n\t\t\\item\r\n\t\t\tBelow is a diagram that depicts the situation.\r\n\t\t\t\r\n\t\t\t\\begin{center}\r\n\t\t\t\t\\begin{tikzpicture}\r\n\t\t\t\t\t\\tikzstyle{spring}=[thick,decorate,decoration={zigzag, pre length=0.5cm, post\r\n\t\t\t\t\t\tlength=0.5cm, segment length=0.33cm, amplitude=0.25cm}]\r\n\t\t\t\t\t\r\n\t\t\t\t\t\\tikzstyle{ground}=[fill, pattern=north east lines, draw=none, minimum\r\n\t\t\t\t\twidth=1cm, minimum height=0.5cm]\r\n\t\t\t\t\t\r\n\t\t\t\t\t\\fill[pattern = north east lines] (0, 0) rectangle (0.5cm, 2.5cm);\r\n\t\t\t\t\t\\draw[thick] (0, 0) -- (8cm, 0);\r\n\t\t\t\t\t\\node (m) at (5cm, 1cm) [draw, thick, minimum width=2cm, minimum height=2cm] {$m = 1$};\r\n\t\t\t\t\t\\draw[spring] (0.5cm, 1cm) -- (m);\r\n\t\t\t\t\t\\node (k) at (1.5cm, 1.75cm) {$k = 8$};\r\n\t\t\t\t\t\\node (b) at (5cm, 2.5cm) {$b = 6$};\r\n\t\t\t\t\t\\node (ini) at (10cm, 1cm) {$\\begin{cases} y'(0) = 1 \\\\ F_\\text{ext}(t) = 8\\sin{(2t)} \\end{cases}$};\r\n\t\t\t\t\t\\draw[dashed] (5cm, -0.25cm) -- (5cm, 0.25cm);\r\n\t\t\t\t\t\\node (y) at (5cm, -0.5cm) {$y = 0$};\r\n\t\t\t\t\\end{tikzpicture}\r\n\t\t\t\\end{center}\r\n\t\t\t\r\n\t\t\t\\begin{enumerate}[label=(\\alph*)]\r\n\t\t\t\t\\item\r\n\t\t\t\t\tOur IVP to model this is\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\\begin{cases}\r\n\t\t\t\t\t\t\ty'' + 6y' + 8y = 8\\sin{(2t)} \\\\\r\n\t\t\t\t\t\t\ty'(0) = 1 \\\\\r\n\t\t\t\t\t\t\ty(0) = 0\r\n\t\t\t\t\t\t\\end{cases}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSolving the auxiliary equation,\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\tr^2 + 6r + 8 = 0 \\implies r = -4, -2.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSo, our homogeneous solution is\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_h = C_1e^{-4t} + C_2e^{-2t}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tWe'll use the method of undetermined coefficients to find $y_p$.\r\n\t\t\t\t\tWe'll guess that $y_p$ has the form\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_p = A\\cos{(2t)} + B\\sin{(2t)}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSolving for $A$ and $B$\\footnote{The algebra of solving for $A$ and $B$ has been omitted for brevity.},\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_p'' + 6y_p' + 8y_p = 8\\sin{(2t)} \\implies A = \\frac{-3}{5}, B = \\frac{1}{5}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSo, our particular solution is\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_p = \\frac{-3}{5}\\cos{(2t)} + \\frac{1}{5}\\sin{(2t)},\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tand our general solution is\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty = C_1e^{-4t} + C_2e^{-2t} - \\frac{3}{5}\\cos{(2t)} + \\frac{1}{5}\\sin{(2t)}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tPlugging in our initial condition to solve for $C_1$ and $C_2$\\footnote{The algebra of solving for $C_1$ and $C_2$ has been omitted for brevity.},\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty'(0) = 1, y(0) = 0 \\implies C_1 = \\frac{-9}{10}, C_2 = \\frac{3}{2}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSo, our solution to the IVP is\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty(t) = \\frac{-9}{10}e^{-4t} + \\frac{3}{2}e^{-2t} - \\frac{3}{5}\\cos{(2t)} + \\frac{1}{5}\\sin{(2t)} \\text{ m}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\\item\r\n\t\t\t\t\tAs $t$ grows large, the exponential terms will decrease to 0 and have minimal effect.\r\n\t\t\t\t\tSo, the steady-state solution $y_{ss}$ is just the terms with $\\cos$ and $\\sin$.\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_{ss}(t) = \\frac{-3}{5}\\cos{(2t)} + \\frac{1}{5}\\sin{(2t)} \\text{ m}\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\\item\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\ty_{ss}(t) = \\sqrt{\\frac{2}{5}}\\cos{\\left(2x + \\arctan{\\left(\\frac{1}{3}\\right)} + \\pi\\right)} \\text{ m}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tThe amplitude, frequency, period, and phase shift are\r\n\t\t\t\t\t\\begin{align*}\r\n\t\t\t\t\t\tA &= \\sqrt{\\frac{2}{5}} \\text{ m} \\\\\r\n\t\t\t\t\t\tf &= \\frac{1}{\\pi} \\text{ Hz} \\\\\r\n\t\t\t\t\t\tT &= \\pi \\text{ secs} \\\\\r\n\t\t\t\t\t\t\\phi &= \\arctan{\\left(\\frac{1}{3}\\right)} + \\pi.\r\n\t\t\t\t\t\\end{align*}\r\n\t\t\t\\end{enumerate}\r\n\t\t\\item\r\n\t\t\tThe instructions say only do one, but we'll do both for the answers.\r\n\t\t\t\\begin{enumerate}[label=(\\alph*)]\r\n\t\t\t\t\\item\r\n\t\t\t\t\t\\begin{enumerate}[label=(\\roman*)]\r\n\t\t\t\t\t\t\\item\r\n\t\t\t\t\t\t\tThe system in matrix form is\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t2 & -3 \\\\\r\n\t\t\t\t\t\t\t\t\t1 & -2\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}\\vec{x} \\text{, } \\vec{x}(0) = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t2 \\\\\r\n\t\t\t\t\t\t\t\t\t3\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\t\\item\r\n\t\t\t\t\t\t\tWe'll check the first vector.\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t3e^t \\\\\r\n\t\t\t\t\t\t\t\t\te^t\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t2 & -3 \\\\\r\n\t\t\t\t\t\t\t\t\t1 & -2\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t3e^t \\\\\r\n\t\t\t\t\t\t\t\t\te^t\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t3e^t \\\\\r\n\t\t\t\t\t\t\t\t\te^t\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\t\tNext we'll check the second vector.\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t-e^{-t} \\\\\r\n\t\t\t\t\t\t\t\t\t-e^{-t}\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t2 & -3 \\\\\r\n\t\t\t\t\t\t\t\t\t1 & -2\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\te^{-t} \\\\\r\n\t\t\t\t\t\t\t\t\te^{-t}\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t-e^{-t} \\\\\r\n\t\t\t\t\t\t\t\t\t-e^{-t}\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\t\tSo, both vectors are solutions to the homogeneous equation.\r\n\t\t\t\t\t\t\\item\r\n\t\t\t\t\t\t\tSince we know two linearly independent solutions from (ii), we can write the general solution as\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\vec{x} = C_1 \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t3e^t \\\\\r\n\t\t\t\t\t\t\t\t\te^t\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} + C_2 \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t-e^{-t} \\\\\r\n\t\t\t\t\t\t\t\t\t-e^{-t}\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\t\tApplying the initial conditions\\footnote{The algebra of solving for $C_1$ and $C_2$ has been omitted for brevity},\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\vec{x}(0) = \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t2 \\\\\r\n\t\t\t\t\t\t\t\t\t3\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} \\implies C_1 = \\frac{-1}{2}, C_2 = \\frac{-7}{2}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\t\tSo, the solution to the IVP is\r\n\t\t\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\t\t\\vec{x} = \\frac{-1}{2} \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t3e^t \\\\\r\n\t\t\t\t\t\t\t\t\te^t\r\n\t\t\t\t\t\t\t\t\\end{bmatrix} - \\frac{7}{2} \\begin{bmatrix}\r\n\t\t\t\t\t\t\t\t\t-e^{-t} \\\\\r\n\t\t\t\t\t\t\t\t\t-e^{-t}\r\n\t\t\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\t\\end{enumerate}\r\n\t\t\t\t\\item\r\n\t\t\t\t\tSince the eigenvalues are a complex conjugate pair, we only need to consider one eigenvalue to find both corresponding eigenvectors.\r\n\t\t\t\t\tWe'll use $\\lambda = -2 + i$.\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\\left[\r\n\t\t\t\t\t\t\t\\begin{array}{cc|c}\r\n\t\t\t\t\t\t\t\t1-i & 2 & 0 \\\\\r\n\t\t\t\t\t\t\t\t-1 & -1-i & 0\r\n\t\t\t\t\t\t\t\\end{array}\r\n\t\t\t\t\t\t\\right] \\to \\left[\r\n\t\t\t\t\t\t\t\\begin{array}{cc|c}\r\n\t\t\t\t\t\t\t\t1 & 1-i & 0 \\\\\r\n\t\t\t\t\t\t\t\t0 & 0 & 0\r\n\t\t\t\t\t\t\t\\end{array}\r\n\t\t\t\t\t\t\\right] \\to t\\left(\\begin{bmatrix}\r\n\t\t\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t\t\t1\r\n\t\t\t\t\t\t\\end{bmatrix} + \\begin{bmatrix}\r\n\t\t\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t\t\t0\r\n\t\t\t\t\t\t\\end{bmatrix}\\right).\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tSo, the two eigenvectors are\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\\begin{bmatrix}\r\n\t\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t\t1\r\n\t\t\t\t\t\t\\end{bmatrix}, \\begin{bmatrix}\r\n\t\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t\t0\r\n\t\t\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\t\tRemembering our solution form for complex eigenvalues, we get the solution\r\n\t\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\t\\vec{x} = C_1e^{-2t}\\left(\\cos{(t)}\\begin{bmatrix}\r\n\t\t\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t\t\t1\r\n\t\t\t\t\t\t\\end{bmatrix} - \\sin{(t)}\\begin{bmatrix}\r\n\t\t\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t\t\t0\r\n\t\t\t\t\t\t\\end{bmatrix}\\right) + C_2e^{-2t}\\left(\\cos{(t)}\\begin{bmatrix}\r\n\t\t\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t\t\t0\r\n\t\t\t\t\t\t\\end{bmatrix} + \\sin{(t)}\\begin{bmatrix}\r\n\t\t\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t\t\t1\r\n\t\t\t\t\t\t\\end{bmatrix}\r\n\t\t\t\t\t\t\\right).\r\n\t\t\t\t\t\\end{equation*}\r\n\t\t\t\\end{enumerate}\r\n\t\t\\item\r\n\t\t\tWe'll use the method of undetermined coefficients for systems to find $\\vec{x_p}$.\r\n\t\t\tWe'll guess that $\\vec{x_p}$ has the form\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\vec{x_p} = \\vec{a}t + \\vec{b}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSolving for $\\vec{a}$ and $\\vec{b}$\\footnote{The algebra of solving for $\\vec{a}$ and $vec{b}$ has been omitted for brevity.},\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\vec{x_p}' = \\begin{bmatrix}\r\n\t\t\t\t\t2 & -1 \\\\\r\n\t\t\t\t\t3 & -2\r\n\t\t\t\t\\end{bmatrix}\\vec{x_p} \\implies \\vec{a} = \\begin{bmatrix}\r\n\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t0\r\n\t\t\t\t\\end{bmatrix}, \\vec{b} = \\begin{bmatrix}\r\n\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t3\r\n\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tSo, we have our solution for $\\vec{x_p}$,\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\vec{x_p} = t\\begin{bmatrix}\r\n\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t0\r\n\t\t\t\t\\end{bmatrix} + \\begin{bmatrix}\r\n\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t3\r\n\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\\end{equation*}\r\n\t\t\tThe general solution is thus\r\n\t\t\t\\begin{equation*}\r\n\t\t\t\t\\vec{x} = C_1e^{t}\\begin{bmatrix}\r\n\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t1\r\n\t\t\t\t\\end{bmatrix} + C_2e^{-t}\\begin{bmatrix}\r\n\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t3\r\n\t\t\t\t\\end{bmatrix} + t\\begin{bmatrix}\r\n\t\t\t\t\t-1 \\\\\r\n\t\t\t\t\t0\r\n\t\t\t\t\\end{bmatrix} + \\begin{bmatrix}\r\n\t\t\t\t\t1 \\\\\r\n\t\t\t\t\t3\r\n\t\t\t\t\\end{bmatrix}.\r\n\t\t\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "b576416699c77874a4d093dc0d0cf7bb71a356c7", "size": 13353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/additionalResources/tests/test2_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/test2_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/test2_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": 33.4661654135, "max_line_length": 186, "alphanum_fraction": 0.5210065154, "num_tokens": 5243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7944062145991165}}
{"text": "\\subsection{Finding the angle between the sun and the line perpendicular to the solar panels}\\label{subsec:findingTheAngleBetweenTheSunAndTheLinePerpendicularToTheSolarPanels}\nTo find the angle $\\alpha$ between the sun and the line perpendicular to the solar panel, we determined both lines in spherical coordinates (with the same distance to the origin) and then calculated the angle between the two.\n\n\nFor the sun this would be\n\\[\n    \\vvec{x \\\\ y \\\\ z} =\n    \\vvec{\\cos \\gamma_s \\sin \\left(\\frac{\\pi}{2} - \\theta_s\\right) \\\\\n    \\sin \\gamma_s \\sin \\left(\\frac{\\pi}{2} - \\theta_s\\right) \\\\\n    \\cos \\left(\\frac{\\pi}{2} - \\theta_s\\right)}\n\\]\nwhere $ \\gamma_s $ is the azimuth, and $ \\theta_s $ the altitude of the sun.\n\n\nFor the line perpendicular to the solar panels this would be\n\\[\n    \\vvec{x \\\\ y \\\\ z} =\n    \\vvec{\\cos \\gamma_p \\sin \\left(\\frac{\\pi}{2} - \\theta_p\\right) \\\\\n    \\sin \\gamma_p \\sin \\left(\\frac{\\pi}{2} - \\theta_p\\right) \\\\\n    \\cos \\left(\\frac{\\pi}{2} - \\theta_p\\right)}\n\\]\nwhere $ \\gamma_p $ is the azimuth (direction of the solar panels in respect to the South), and $ \\theta_p $ the altitude of the solar panels.\n\nThen, to find the angle $\\alpha$ between these two lines, we take the $ \\arccos $ of the dot product.\nThis gives us\n\n\\[\n    \\alpha = \\arccos (\\cos (\\gamma_p - \\gamma_s) \\cos \\theta_s \\sin \\theta_p + \\sin \\theta_s \\cos \\theta_p)\\,.\n\\]\n\n\\subsection{Implementation of calculations to find optimal angles}\n\n\\subsubsection{Mathematica calculations}\\label{subsec:mathematicaCalculations}\n\nThe Mathematica package (imported with \\verb|<< SolArduino`|, be sure to place it in your\n\\url{\\%AppData\\%\\\\Mathematica\\\\Applications} folder) can calculate the optimal angle for a given day.\nTo do that, it calculates for each angle between $0$ and $90$ the total of the insolation (power received by the sun) at each half hour of that day.\nThen it finds the angle for which that value is maximal.\nTo find the insolation at a given hour, the function \\verb|angle| calculates the misalignment with the sun using the formula from the previous subsection, and then calculates the insolation using a formula from \\href{http://www.powerfromthesun.net/Book/chapter02/chapter02.html#ZEqnNum929295 }{www.powerfromthesun.net}, where parameters for urban haze compared a lot better with real life values (17/8) than clear day parameters.\n\nIt can therefore make graphs for optimal angles for a month, and averaging the values for a month, also for a year, and lots more as seen in the demonstration notebook.\nWhen plotting real data, for example days like 13/5, 19/7 and 17/8 are all cloudless days with the solar panels at around 25 degrees.\n\nIt is important to note that the functions \\verb|angle|, \\verb|directPower| and more do not take the hour of the day as input, but the index of the \\verb|sunPositions| table which contains the azimuth and altitude of the sun over the day.\nTherefore, \\textit{before you call functions which take an index as parameter you need to make sure you have }\\verb|sunPositions| \\textit{initialised} at the right day, done by calling \\verb|calculatesunPos[DateObject[{2016,7,18}]]| with whatever day you want in the table.\n\nExporting the angles for ten times a day for two years, like\n\n\\verb|exportPeriod[DateObject[{2016, 9, 7}], DateObject[{2018, 9, 15}], 10]| took only ten minutes (Lenovo W541 laptop on high performance).\n\n\\subsubsection{Haskell calculations}\n\nBecause Mathematica is proprietary, we decided to also provide a Haskell implementation.\nIt uses the \\href{https://hackage.haskell.org/package/astro}{Astro package} to find the position of the sun.", "meta": {"hexsha": "5696d3f2ccf80cb2656d31fa026254808038c2ba", "size": 3608, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/src/calculations.tex", "max_stars_repo_name": "PHPirates/SolArduino", "max_stars_repo_head_hexsha": "d7fee339dd4af896cee267306127a13b160e032b", "max_stars_repo_licenses": ["ISC"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-12-22T16:24:16.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-19T13:37:24.000Z", "max_issues_repo_path": "Documentation/src/calculations.tex", "max_issues_repo_name": "PHPirates/SolArduino", "max_issues_repo_head_hexsha": "d7fee339dd4af896cee267306127a13b160e032b", "max_issues_repo_licenses": ["ISC"], "max_issues_count": 91, "max_issues_repo_issues_event_min_datetime": "2016-10-22T16:35:57.000Z", "max_issues_repo_issues_event_max_datetime": "2020-03-12T18:30:56.000Z", "max_forks_repo_path": "Documentation/src/calculations.tex", "max_forks_repo_name": "PHPirates/SolArduino", "max_forks_repo_head_hexsha": "d7fee339dd4af896cee267306127a13b160e032b", "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": 66.8148148148, "max_line_length": 429, "alphanum_fraction": 0.7466740576, "num_tokens": 963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533032291501, "lm_q2_score": 0.8519527963298946, "lm_q1q2_score": 0.7944061991331216}}
{"text": "\n\\color{black}\n\\subsection*{Sampling a Markov model}\n\nGiven a given Markov chain $\\lambda$ over some state space $\\set{S}$, the following procedure generates a sequence of states $\\vec{s} = s[0] s[1] s[2] \\cdots$ \n\\begin{itemize}\n\\item[] manually initialize $s[0] \\in \\set{S}$\n\\item[] if $s[t-1] = s_i$, \\emph{draw} $s[t] = s_j$ according to $\\cprob{s_j}{s_i}$, that is select\n\\begin{equation*}\ns_j \\sim \\bigl( \\mat{P}_\\lambda \\bigr)_{ji}\n\\end{equation*}\n\\end{itemize}\nwhere $\\mat{P}_\\lambda$ is the state transition probability matrix of the process $\\lambda$. \\\\[1ex]\n\nUsing matrix $\\mat{P}_{\\lambda_1}$, generate a sequence $\\vec{s}$ of $200$ states where $s[0] = A$. That is, replace the dots in the following expression by $199$ symbols sampled according to the above algorithm. \n\\color{blue}\n%%%%%\n%%%%% enter your answer after the letter 'A'\n%%%%%\n\\\\\\\\\n$ \\vec{s} = $ A A B B A A B A B B C A A C A A A C C B B A C C A B C A B A B A B C A B C A B A C A A A B C C B C A B C A A A A A B C C A B B B C A B A B C C C C A C C A B C A B C A B B C C A A B B C C B C C A B C B A B C A C C A B C C B C B B C A A B C B C B B A A B C A A B C A C C A B B C C A B B C A B B A C C C B C A C A B C A B C A C B A B A B B C B A B C C B C B C A A B B C A A A B C A B C C A C A A A B A B\n\\\\ \n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\nUsing matrix $\\mat{P}_{\\lambda_1}$, generate $n=1000$ sequences $\\vec{s}_l$ of length $200$ where $s_l[0] = A$ for all $l$. Compute their average log-likelihood \n\\color{blue}\n%%%%%\n%%%%% enter your answer after the '=' sign\n%%%%%\n\\begin{equation*}\n\\frac{1}{n} \\sum_{l=1}^n  \\mathcal{L}\\bigl( \\vec{s}_l \\bigr) = -205.06\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}", "meta": {"hexsha": "5ebfa6e8268f406a070e700a9b69163fa923b565", "size": 1677, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SelfTest1SS2020/selfTestProblem2.tex", "max_stars_repo_name": "baraaHassan/Game-AI-Course", "max_stars_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SelfTest1SS2020/selfTestProblem2.tex", "max_issues_repo_name": "baraaHassan/Game-AI-Course", "max_issues_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SelfTest1SS2020/selfTestProblem2.tex", "max_forks_repo_name": "baraaHassan/Game-AI-Course", "max_forks_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.0, "max_line_length": 413, "alphanum_fraction": 0.6076326774, "num_tokens": 640, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436167620237, "lm_q2_score": 0.8705972768020108, "lm_q1q2_score": 0.7943644427858415}}
{"text": "\n\\vspace{1em}\n%\\pagebreak\n\\section*{APPENDIX}\n\\subsubsection*{Part A}\nIn this part, we develop the details of the approximate solution\nof the recursive equation defined in Section~\\ref{sec-analyses}.\n\n\\[ f(N) = \\frac{N}{2} + 2f(\\frac{N}{2}) \\]\n\nDeveloping the second term of this equation one step, we obtain:\n\n\\[ f(N) = \\frac{N}{2} + 2f(\\frac{N}{2}) = \\]\n\\[ = \\frac{N}{2} + 2(\\frac{N}{4} + 2f(\\frac{N}{4})) =\\]\n\\[ = \\frac{N}{2} + \\frac{N}{2} + 4f(\\frac{N}{4}) =\\]\n\\[ = 2\\frac{N}{2} + 4f(\\frac{N}{4})\\]\n\nDeveloping the second term of this equation one more step, we obtain:\n\n\\[ f(N) = 2\\frac{N}{2} + 4f(\\frac{N}{4}) = \\]\n\\[ = 2\\frac{N}{2} + 4(\\frac{N}{8} + 2f(\\frac{N}{8})) =\\]\n\\[ = 2\\frac{N}{2} + \\frac{N}{2} + 8f(\\frac{N}{8}) =\\]\n\\[ = 3\\frac{N}{2} + 8f(\\frac{N}{8}) \\]\n\nAfter developing the second term $p-1$ times, we obtain:\n\n\\[ f(N) = p\\frac{N}{2} + 2^pf(\\frac{N}{2^p})\\]\n\nWhen $p = n = \\mathsf{lb}~N$, this equation turns into:\n\n\\[ f(N) = \\frac{N}{2}\\mathsf{lb}~N + Nf(1) = \\frac{N}{2}\\mathsf{lb}~N\\]\n\n\\subsubsection*{Part B}\nIn this part, we develop the details of the approximate solution\nof the recursive equation defined in Section~\\ref{sec-analyses}.\n\n\\[ f(N) = \\left\\{ \\begin{array}{ll}\n    N-1 & \\mbox{if $N \\le K$} \\\\\n    \\frac{N}{2} + 2f(\\frac{N}{2}) &\\mbox{otherwise}\n  \\end{array} \\right. \\]\n\nSince the second equation is the same as for the basic technique,\ndeveloping the second equation $p-1$ times, we again obtain:\n\n\\[ f(N) = p\\frac{N}{2} + 2^pf(\\frac{2^n}{2^p})\\]\n\nWhen $p = n - k = \\mathsf{lb}~\\frac{N}{K}$ we get:\n\n\\[ f(N) = \\frac{N}{2}\\mathsf{lb}~\\frac{N}{K} + \\frac{N}{K}f(K)\\]\n\nSubstituting $K-1$ for $f(K)$ and factoring out $N$, we obtain:\n\n\\[ f(N) = N(\\frac{1}{2}\\mathsf{lb}~\\frac{N}{K} + \\frac{K - 1}{K})\\]\n\nOr:\n\n\\[ f(N) = N(1 - \\frac{1}{K} + \\frac{1}{2}\\mathsf{lb}~\\frac{N}{K})\\]\n\nClearly, the term $\\frac{1}{K}$ can be ignored, giving:\n\n\\[ f(N) \\approx N(1 + \\frac{1}{2}\\mathsf{lb}~\\frac{N}{K})\\]\n\n\\subsubsection*{Part C}\nIn this part, we develop the details of the approximate solution\nof the recursive equation defined in Section~\\ref{sec-analyses}.\n\n\\[ f(N) = \\left\\{ \\begin{array}{ll}\n                    0 & \\mbox{if $N = 1$} \\\\\n                    N - \\frac{N}{M} + Mf(\\frac{N}{M}) &\\mbox{otherwise}\n                  \\end{array} \\right. \\]\n\nSolving as before, after developing the last term once, we obtain:\n\n\\[ f(N) = N - \\frac{N}{M} + Mf(\\frac{N}{M}) = \\]\n\\[ = N - \\frac{N}{M} + M(\\frac{N}{M} - \\frac{N}{M^2} + Mf(\\frac{N}{M^2})) = \\]\n\\[ = N - \\frac{N}{M} + N - \\frac{N}{M} + M^2f(\\frac{N}{M^2}) = \\]\n\\[ = 2(N - \\frac{N}{M}) + M^2f(\\frac{N}{M^2}) \\]\n\nDeveloping the last term a second time, we obtain:\n\n\\[ f(N) = 2(N - \\frac{N}{M}) + M^2f(\\frac{N}{M^2}) = \\]\n\\[ = 2(N - \\frac{N}{M}) + M^2(\\frac{N}{M^2} - \\frac{N}{M^3} + Mf(\\frac{N}{M^3})) = \\]\n\\[ = 2(N - \\frac{N}{M}) + N - \\frac{N}{M} + M^3f(\\frac{N}{M^3}) = \\]\n\\[ = 3(N - \\frac{N}{M}) + M^3f(\\frac{N}{M^3}) \\]\n\nAfter developing the last term $p-1$ times, we obtain:\n\n\\[ f(N) = p(N - \\frac{N}{M}) + M^pf(\\frac{N}{M^p}) = \\]\n\nSetting $p = \\frac{n}{m} = \\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M}$ so\nthat $M^p = N$, we get:\n\n\\[ f(N) = \\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M}(N - \\frac{N}{M}) + Nf(1)\n   = \\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M}(N - \\frac{N}{M}) \\]\n\nFactoring out $N$, we obtain:\n\n\\[ f(N) = N(1 - \\frac{1}{M})\\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M} \\]\n\nand thus:\n\n\\[ F(N) = N(1 + (1 - \\frac{1}{M})\\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M}) \\]\n\nand again:\n\n\\[ F(N) \\approx N(1 + \\frac{\\mathsf{lb}~N}{\\mathsf{lb}~M}) \\]\n", "meta": {"hexsha": "3c99f2e855650fa9686b3ac12a56377ec1424f2e", "size": 3503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Papers/Reverse-order/sec-appendix.tex", "max_stars_repo_name": "gwerbin/SICL", "max_stars_repo_head_hexsha": "ec5cc25de783ecce373081ab72d2a04359155ad6", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 842, "max_stars_repo_stars_event_min_datetime": "2015-01-12T15:44:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-30T14:03:04.000Z", "max_issues_repo_path": "Papers/Reverse-order/sec-appendix.tex", "max_issues_repo_name": "gwerbin/SICL", "max_issues_repo_head_hexsha": "ec5cc25de783ecce373081ab72d2a04359155ad6", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 85, "max_issues_repo_issues_event_min_datetime": "2015-03-25T00:31:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T11:06:19.000Z", "max_forks_repo_path": "Papers/Reverse-order/sec-appendix.tex", "max_forks_repo_name": "gwerbin/SICL", "max_forks_repo_head_hexsha": "ec5cc25de783ecce373081ab72d2a04359155ad6", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 80, "max_forks_repo_forks_event_min_datetime": "2015-03-06T12:52:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T05:30:33.000Z", "avg_line_length": 32.738317757, "max_line_length": 85, "alphanum_fraction": 0.5361119041, "num_tokens": 1550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525463, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.7943644144893898}}
{"text": "\n\\subsection{Classical principal component analysis}\n\n\\subsubsection{Introduction}\n\nPrincipal component analysis takes a dataset \\(X\\) with \\(m\\) variables and returns a principal component matrix \\(A\\) with size \\(m\\times k\\).\n\nEach new dimension is a linear function of the existing data. \\(Z=XA\\).\n\nEach dimension in uncorrelated, and ordered, in order of descending explanation of variability.\n\nThe problem of principal component analysis is to find these weightings \\(A\\).\n\n\\subsubsection{Classical PCA}\n\nWe take the first \\(k\\) eigenvectors of the covariance matrix, ordered by eigenvalue.\n\n\\subsubsection{Getting the eigenvectors using SVD}\n\nWe can decompose \\(X=U\\Sigma A^T\\).\n\nWe can take the eigenvectors from \\(A\\).\n\n\\subsubsection{Choosing the number of dimension}\n\nWe can choose \\(k\\) such that a certain percentage of the variance is retained.\n\n", "meta": {"hexsha": "cd83ee18d16ce0e55ae188623c4f2ab029b02a40", "size": 859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/dimensionality/01-01-PCA.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/dimensionality/01-01-PCA.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/dimensionality/01-01-PCA.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.6785714286, "max_line_length": 143, "alphanum_fraction": 0.7671711292, "num_tokens": 195, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012640659996, "lm_q2_score": 0.8397339656668286, "lm_q1q2_score": 0.7942214462068412}}
{"text": "\\subsection{Real-valued functions}\\label{subsec:real_valued_functions}\n\n\\begin{definition}\\label{def:epigraph}\n  Let \\( X \\) be an arbitrary set. The \\term{epigraph} of the function \\( f: X \\to \\BbbR \\) is defined as\n  \\begin{equation*}\n    \\epi f \\coloneqq \\{ (x, r) \\in X \\times \\BbbR \\colon r \\geq f(x) \\},\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "9360141fd16489a0117b3f8a2c6364e2c0eda022", "size": 345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_valued_functions.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_valued_functions.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_valued_functions.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": 38.3333333333, "max_line_length": 105, "alphanum_fraction": 0.6753623188, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951625409307, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7942089566092021}}
{"text": "\\section*{Chapter 11: Permutation Algorithms}\n\n\\paragraph{Exercise 11.1}\nProve \\textsl{Cayley's theorem}: Any group $G$ is isomorphic to a subgroup of\nthe symmetric group on $G$, \\Sym{G}.\n\n\\begin{proof}\n\nFor any $a \\in G$, consider the following function $F_a: G \\rightarrow G$:\n$$F_a(x) = a x$$\n\\begin{itemize}\n    \\item $F_a$ is one-to-one, since $F_a(x) = a x = a y = F_a(y)$ implies \n    that $x = y$ (left multiplying by \\Inv{a}).\n    \\item $F_a$ is onto: for a given $y \\in G$, $F_a(\\Inv{a} y) = a (\\Inv{a} y)\n    = (a \\Inv{a}) y = y$.\n\\end{itemize}\nThus, $F_a$ is a bijection on $G$, which in turn means that $F_a$ is a permutation\nof the elements in $G$. Thus, $S = \\{ F_a \\, / \\, a \\in G \\}$ is a subset of \\Sym{G}.\nMoreover, $S$ is a subgroup of \\Sym{G}:\n\\begin{itemize}\n    \\item $S$ contains the identity permutation: $F_{\\Id{G}}(x) = \\Id{G} \\, x = x$.\n    \\item $S$ is closed by composition: $(F_a \\circ F_b)(x) = F_a(F_b(x)) = a (b x)\n    = (a b) x = F_{ab}(x)$.\n    \\item $S$ is closed by inverses: $\\Inv{F_a} = F_{\\Inv{a}}$, since\n    $(F_a \\circ F_{\\Inv{a}})(x) = a (\\Inv{a} x) = x$.\n\\end{itemize}\nLet $\\mathcal{F} : G \\rightarrow S$  be a function defined as follows:\n$$\\mathcal{F}(a) = F_a$$\nThen, $\\mathcal{F}$ is a group isomorphism from $G$ to $S$:\n\\begin{itemize}\n    \\item $\\mathcal{F}(ab) = F_{ab} = F_a \\circ F_b =\n    \\mathcal{F}(a) \\circ \\mathcal{F}(b)$, using that $S$ is closed by composition.\n    \\item $\\mathcal{F}$ is one-to-one, since $\\mathcal{F}(a) = \\mathcal{F}(b)$\n    implies that $F_a(x) = a x = b x = F_b(x)$, and so $a = b$ after right\n    multiplying by \\Inv{x}.\n    \\item $\\mathcal{F}$ is onto, since for a given $F_a \\in S$, $\\mathcal{F}(a) = F_a$.\n\\end{itemize}\n\\end{proof}\n\n\\paragraph{Exercise 11.2}\nWhat is the order of $S_n$?\n\n\\begin{proof}[Answer]\n$S_n$ contains every permutation of $\\{1,\\dots,n\\}$. Since there are $n!$ of\nthem, the order of $S_n$ is $n!$.\n\\end{proof}\n\n\\paragraph{Exercise 11.3}\nProve that, if $n > 2$, $S_n$ is not abelian.\n\n\\begin{proof}\nLet $P_1 = (2 \\, 1 \\, 3 \\, \\dots \\, n)$ and let\n$P_2 = (3 \\, 1 \\, 2 \\, \\dots \\, n)$. Then,\n\\begin{itemize}\n    \\item $P_1 \\circ P_2 = (1 \\, 3 \\, 2 \\, \\dots \\, n)$, and\n    \\item $P_2 \\circ P_1 = (3 \\, 2 \\, 1 \\, \\dots \\, n)$.\n\\end{itemize}\nSince $P_1 \\circ P_2 \\neq P_2 \\circ P_1$, $S_n$ is not commutative.\n\\end{proof}\n\n\n\\paragraph{Exercise 11.9}\nProve that if a rotation of $n$ elements has a trivial cycle, then it has $n$\ntrivial cycles.\n\n\\begin{proof}\nLet $\\rho$ be an $n$ by $k$ rotation. That is,\n$$\\rho = (k \\MOD{n}, k+1 \\MOD{n}, \\dots, k+n-1 \\MOD{n})$$\nSuppose that $\\rho$ has a trivial cycle. This means that there is an\n$0 \\leq i < n$ such that $i = k + i \\MOD{n} \\Rightarrow \nk = 0 \\MOD{n}$. Then, \n\\begin{eqnarray*}\n    \\rho &=& (0 \\MOD{n}, 1 \\MOD{n}, \\dots, n-1 \\MOD{n}) \\\\\n         &=& (0, 1, \\dots, n-1)\n\\end{eqnarray*}\nwhich means that $\\rho$ does not move any element.\n\\end{proof}\n\n\n\\paragraph{Exercise 11.11}\nHow many assignments does 3-reverse rotate perform?\n\n\\begin{proof}[Answer]\nCall $\\alpha_r(f,m,l)$ the number of assignments we seek.\nFirst, let $\\sigma(f,l)$ be the number of swaps performed by \\Rev{f}{l}. Since this\nfunction swaps element $f$ with element $l-1$, element $f+1$ with element\n$l-2$, and so on, we have that \n$$\\sigma(f, l) = \\floor{\\frac{l-f}{2}}$$\nThen, if we note the number of swaps performed by 3-reverse rotate by \n$\\sigma_r(f,m,l)$,\n\\begin{eqnarray*}\n\\sigma_r(f,m,l) &=& \\floor{\\frac{m-f}{2}} + \\floor{\\frac{l-m}{2}} + \n                    \\floor{\\frac{l-f}{2}} \\\\\n             &\\leq& \\frac{m-f}{2} + \\frac{l-m}{2} + \\frac{l-f}{2} \\\\\n                &=& \\frac{(m-f) + (l-m) + (l-f)}{2} \\\\ \n                &=& \\frac{2l - 2f}{2} \\\\\n                &=& l - f \\\\\n                &=& n\n\\end{eqnarray*}\nbeing $n$ the number of elements being rotated. Thus, at most $n$ swaps are \nperformed by 3-reverse rotate (and at least $n-1$, following a similar\napproach). Since each swap takes three assignments,\n$$3(n-1) \\leq \\alpha_r(f,m,l) \\leq 3n$$\n\\end{proof}\n", "meta": {"hexsha": "939bd51b6d3582546cd11b1203f97e9f08cc72c4", "size": 4007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter11.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter11.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter11.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 38.1619047619, "max_line_length": 87, "alphanum_fraction": 0.5877214874, "num_tokens": 1536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772450055545, "lm_q2_score": 0.9086179012632543, "lm_q1q2_score": 0.7942022318989143}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Completeness of the Real Numbers}\nOur next goal is to prove the IVT for continuous functions.\n\n\\begin{theorem}[Intermediate Value Theorem]\n\tIf $f$ is a continuous function on $[a,b]$ and $k$ is a real number lying between $f(a)$ and $f(b)$ then there exists a real number $ c $ lying between $a$ and $b$ such that $f(c) = k$.\n\\end{theorem}\n\nThe proof of this trivial looking theorem relies on a defining axiom of the system of real numbers called {\\it completeness} which we'll now try to understand. For this we'll need to rigorously define the simple notions of {\\it min} and {\\it max}.\\\\\n\n\nFor a non-empty set $S$ of real numbers, it's maximum element can be defined as follows.\n\\begin{definition}\n\t\\label{def:maximum}\n\t$\\max S$ is the element $a \\in S$ such that $a \\ge x$ for all elements $x \\in S$.\n\\end{definition}\nThis definition exposes a subtle shortcoming of $\\max S$. It doesn't exist even for {\\it nice} sets.\n\\begin{exercise}\n\tWhat is $\\max \\: (0,1)$? Make sure that your answer agrees with Definition \\ref{def:maximum}.\n\\end{exercise}\n\nThere is a more intricately defined number, called the {\\bf supremum}, that we can associate to a set of real numbers which also captures the {\\it largest-element} property. For sets containing infinitely many elements, the supremum, rather than the maximum gives us the correct {\\it largest-element}.\n\n\\begin{definition}\n\tAn {\\bf upper bound} of a set $S$ is any real number $a$ satisfying $a \\ge x$ for all elements $x \\in S$. (Note that $a$ does not have to be in $S$.)\n\\end{definition}\n\n\\begin{exercise}\n\t\\label{q:upper_bounds}\n\tUpper bounds are not unique. Find all the possible upper bounds on the following sets. (No proofs needed. Make sure you've found {\\it all} the upper bounds.)\n\t\\begin{enumerate}\n\t\t\\item $[0,1]$\n\t\t\\item $(0,1)$\n\t\t\\item $\\R$\n\t\t\\item $\\{ 1/n :$ where $n$ is a positive integer$\\}$\n\t\t\\item The set of rational numbers $x$ satisfying $x^2 < 2$\n\t\t\\item The set of irrational numbers in interval $[0,1]$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{definition}\n\tThe {\\bf supremum} or the {\\bf least upper bound} of a set $S$ of real numbers, denoted $\\sup S$, is the smallest real number $a$ such that $a$ is an upper bound of $S$.\n\\end{definition}\n\n\\begin{exercise}\n\tFind the supremum of the sets in Exercise \\ref{q:upper_bounds}.\n\\end{exercise}\n\n\n\\begin{definition}\n\tWe say that a set $S$ is {\\bf bounded from above} if it has at least one upper bound i.e. there exists a real number $a$ such that $a \\ge x$ for all elements $x \\in S$.\n\\end{definition}\n\n\\begin{exercise}\n\tWhich of the sets in Exercise \\ref{q:upper_bounds} are bounded from above?\\\\\n\\end{exercise}\n\nWe can now state the {\\bf Completeness of the Real Numbers}:\n\\begin{theorem}\n\tIf a non-empty set $S$ is bounded from above then $S$ has a supremum.\n\\end{theorem}\n\nDepending on exactly how the real numbers are constructed, this is either a theorem or an axiom. This theorem/axiom is the precise way of saying that there are no holes in the real line. (Read the Wikipedia article titled {\\it Completeness of the real numbers}.) We'll next restate the property of being a supremum using our (favorite) language of $\\epsilon$'s and $\\delta$'s.\n\n\n\\begin{exercise}\n\t\\label{q:supremum_closeness}\n\tLet $S$ be a non-empty set that is bounded from above and let $L = \\sup S$.\n\t\\begin{enumerate}\n\t\t\\item Show that for every $ \\delta > 0 $, there exists an element $x \\in S$ such that $L - x < \\delta$. \\hint{Proof by Contradiction.}\n\t\t\\item Let $a$ be an upper bound of $S$. Prove that, if for every $ \\delta > 0 $, there exists an element $x \\in S$ such that $a - x < \\delta$, then $a = L$. \\hint{Prove by Contrapositive.}\n\t\\end{enumerate}\n\\end{exercise}\nThus we're saying that elements of $S$ get infinitely close to the supremum.\n\n\n\n\\subsection*{Optional Problems}\n\nSimilarly to the supremum we can define the {\\bf infimum} of a set $S$, denoted $S$, which corresponds to $\\min S$.\n\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Define $\\inf S$.\n\t\t\\item Find the infimum of all the sets in Exercise \\ref{q:upper_bounds}.\n\t\t\\item Show that \\begin{align*}\n\t\t\t      \\inf S = - \\sup (-S)\n\t\t      \\end{align*} (if they exist), where $-S$ is the set containing elements of the form $-x$ where $x \\in S$.\n\t\t\\item State the analogue of Exercise \\ref{q:supremum_closeness} for $\\inf S$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\n\n\\newpage\n\\subsection{Intermediate Value Theorem}\n\nWe'll now prove the Intermediate Value Theorem. This is our first encounter with a complicated proof which requires multiple steps. You probably won't see the full picture until you completely write down the proof yourself. It'll help you a lot to draw pictures to keep a track of all the variables. \\\\\\\\\n\\begin{tabular}{|p{\\textwidth}|}\n  \\hline \\\\{\\it Once you have solved all the exercises in the proof of Theorem \\ref{theorem:IVT}, submit your final solution as one single logically coherent proof of the IVT, also include all the text that is in between the exercises, so that you yourself see how all the pieces fit together. This will also teach you to write complex proofs.}\\\\\\\\\n  \\hline\n\\end{tabular}\n\n\\vspace{1em}\nWe'll need the following proposition from the previous section, which says that the elements of a set $S$ are infinitely close to it's supremum.\n\\begin{prop}\n  \\label{thm:sup_lemma}\n  For a set $S$, if $L = \\sup S$, then\n  for every $ \\delta > 0 $, there exists an element $x \\in S$ such that $L - x < \\delta$.\n\\end{prop}\n\n\\begin{theorem}[Intermediate Value Theorem]\n\t\\label{theorem:IVT}\n\tLet $f$ be a continuous function on $[a,b]$ and let $k$ be a real number satisfying\n\t\\begin{align*}\n\t\tf(a) < k < f(b).\n\t\\end{align*}\n\tThen, there exists a real number $c$ satisfying $a < c < b$ such that\n\t\\begin{align*}\n\t\tf(c) = k.\n\t\\end{align*}\n\\end{theorem}\n\n\n\\begin{proof}[Proof of \\ref{theorem:IVT}]\n\n\tWe'll first prove the following slightly easier version.\n\t\\begin{prop}\n\t\t\\label{theorem:easy_IVT}\n\t\tIf $g$ is a continuous function on $[a,b]$ satisfying\n\t\t\\begin{align*}\n\t\t\tg(a) < 0< g(b)\n\t\t\\end{align*}\n\t\tthen, there exists a real number $c$ satisfying $a < c < b$ such that\n\t\t\\begin{align*}\n\t\t\tg(c) = 0.\n\t\t\\end{align*}\n\t\\end{prop}\n\t\\begin{proof}[Proof of \\ref{theorem:easy_IVT}]\n\t\tLet $g,a,b$ be as in the statement of the Proposition. We'll construct a number $c$ that satisfies $a < c < b$ and $g(c) = 0$.\n\n\t\tLet $S$ be a set defined as follows,\n\t\t\\begin{align*}\n\t\t\tS = \\{ x \\mid a \\le x \\le b \\mbox{ and } g(x) \\le 0\\}.\n\t\t\\end{align*}\n\t\t\\begin{exercise}\n\t\t\tArgue that $S$ is non-empty and is bounded from above.\n\t\t\\end{exercise}\n\t\tHence, $S$ has a supremum by the {\\it Completeness Property of Real Numbers}. Denote this supremum by $c$. We'll prove that\\\\\n\n    \\begin{indentPara}\n      {\\bf Claim: } $g(c) = 0$.\\\\\n    \\end{indentPara}\n\n\t\tWe'll prove this claim by contradiction. Suppose on the contrary that $g(c) \\neq 0$. There are two possible cases:\\\\\n\t\t\\begin{indentPara}\n      \\begin{description}\n  \t\t\t\\item[Case 1:] $g(c) < 0$\n  \t\t\t\\item[Case 2:] $g(c) > 0$\\\\\n  \t\t\\end{description}\n    \\end{indentPara}\n\t\tSuppose {\\bf Case 1} is true i.e. $g(c) < 0$.\n\t\t\\begin{exercise}\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Use the formal definition of continuity (from right) of $g$ to prove that there exists an $x > c$ such that $f(x) < 0$.\\hint{Use $\\epsilon = -g(c)/2$.}\n\t\t\t\t\\item Argue that this contradicts one of your assumptions, hence $g(c)$ cannot be less than 0.\n\t\t\t\\end{enumerate}\n\t\t\\end{exercise}\n\t\t\\noindent Suppose {\\bf Case 2} is true i.e. $g(c)> 0$.\n\t\t\\begin{exercise}\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item Use the formal definition of continuity (from left) of $g$ to prove that there exists a $\\delta$ such that, for every $x$, if $c - x < \\delta$ then $g(x) > 0$.\\hint{Use $\\epsilon = g(c)/2$.}\n  \t\t\t\t\\item For this particular $\\delta$, prove that, for every $x$ in $S$, $c - x > \\delta$.\n\t\t\t\t\\item Argue that this contradicts Proposition \\ref{thm:sup_lemma}, hence $g(c)$ cannot be greater than 0.\n\t\t\t\\end{enumerate}\n\t\t\\end{exercise}\n\t\tThus we've contradicted both the possible cases, which completes the proof by contraction and proves the Claim that $g(c) = 0$.\n\n    By construction $c$ satisfies $ a < c < b$. So we've constructed a $c$ such that $a < c < b$ and $g(c) = 0$ which completes the proof of Proposition \\ref{theorem:easy_IVT}.\n\t\\end{proof}\n\t\\begin{exercise}\n\t\tGoing back to $f$, use the function $g(x) = f(x) - k$ in Proposition \\ref{theorem:easy_IVT} to complete the proof of Theorem \\ref{theorem:IVT}.\n\t\\end{exercise}\n\\end{proof}\n\n\nBoth the hypotheses are necessary for the IVT to be true.\nThis means that we must be crucially using these hypotheses in our proof somewhere and the proof should fail if we do not have these assumptions. It is clear where we are using continuity, the other one is more subtle.\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Find the {\\it exact} argument in your proof of Proposition \\ref{theorem:easy_IVT} which fails if we assume $0 < g(a) < g(b)$.\n\t\t\\item Find the {\\it exact} argument in your proof of Proposition \\ref{theorem:easy_IVT} which fails if we assume $ g(a) < g(b) < 0$.\n\t\\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "0d04c5b7cbdd76813c24d54e67b84c08ccf96d24", "size": 9121, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/04Supremum.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/04Supremum.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/04Supremum.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": 46.2994923858, "max_line_length": 376, "alphanum_fraction": 0.6947703103, "num_tokens": 2762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.9086179055936797, "lm_q1q2_score": 0.7942022207816666}}
{"text": "\\section{Roots of complex numbers}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Understand De Moivre's theorem and be able to use it to find\n    the roots of a complex number.\n  \\end{enumerate}\n\\end{outcome}\n\nA fundamental identity is the\n\\index{De Moivre's theorem} formula of De Moivre with which we begin this section.\n\n\\begin{theorem}{De Moivre's theorem}{de-moivre-theorem}\nFor any positive integer $n$, we have\n\\begin{equation*}\n(e^{i \\theta})^n = e^{i n \\theta}\n\\end{equation*}\nThus for any real number $r>0$ and any positive integer $n$, we have:\n\\begin{equation*}\n(r(\\cos \\theta+i\\sin \\theta)) ^{n}=r^{n}(\\cos n \\theta +i\\sin\nn\\theta)\n\\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n The proof is by induction on $n$. It is clear the formula holds if $n=1$. Suppose it is true\nfor $n$. Then, consider $n+1$.\n\\begin{equation*}\n(r(\\cos \\theta+i\\sin \\theta)) ^{n+1}=(r(\\cos\n\\theta+i\\sin \\theta)) ^{n}(r(\\cos \\theta+i\\sin \\theta))\n\\end{equation*}\nwhich by induction equals\n\\begin{eqnarray*}\n&=&r^{n+1}(\\cos n\\theta+i\\sin n\\theta) (\\cos \\theta+i\\sin \\theta) \\\\\n&=& r^{n+1}((\\cos n\\theta\\cos \\theta-\\sin n\\theta\\sin \\theta) +i(\\sin\nn\\theta\\cos \\theta+\\cos n\\theta\\sin \\theta))\\\\\n&=&r^{n+1}(\\cos (n+1) \\theta+i\\sin (n+1) \\theta)\n\\end{eqnarray*}\nby the formulas for the cosine and sine of the sum of two angles.\n\\end{proof}\n\nThe process used in the previous proof, called {\\em mathematical\ninduction} is very powerful in Mathematics and Computer Science\nand explored in more detail in the Appendix.\n\nNow, consider a corollary of Theorem~\\ref{thm:de-moivre-theorem}.\n\n\\begin{corollary}{Roots of complex numbers}{roots-complex-numbers}\nLet $z$ be a non-zero complex number.\n\\index{complex numbers!roots}Then there are always exactly $k$ many  $k\\th$\nroots of $z$ in $\\C$.\n\\end{corollary}\n\n\\begin{proof}\nLet $z=a+bi$ and let $z=\\abs{z}(\\cos\n\\theta+i\\sin \\theta) $ be the polar form of the complex number. By De Moivre's\ntheorem, a complex number\n\\begin{equation*}\nw= r e^{i \\alpha} = r(\\cos \\alpha +i\\sin \\alpha)\n\\end{equation*}\nis a $k\\th$ root of $z$ if and only if\n\\begin{equation*}\nw^k = (r e^{i \\alpha})^k = r^k e^{ik\\alpha} = r^{k}(\\cos k\\alpha +i\\sin k\\alpha) =\\abs{z}(\\cos \\theta+i\\sin \\theta)\n\\end{equation*}\nThis requires $r^{k}=\\abs{z}$ and so $r=\\abs{z}^{1/k}$. Also, both $\\cos (k\\alpha) =\\cos \\theta$ and\n$\\sin (k\\alpha) =\\sin \\theta$. This can only happen if\n\\begin{equation*}\nk\\alpha =\\theta+2 \\ell \\pi\n\\end{equation*}\nfor $\\ell$ an integer. Thus\n\\begin{equation*}\n\\alpha =\n\\frac{\\theta+2 \\ell \\pi }{k},\\; \\ell = 0, 1, 2,\\ldots, k-1\n\\end{equation*}\nand so the $k\\th$ roots of $z$ are of the form\n\\begin{equation*}\n\\abs{z}^{1/k}\\paren{\\cos \\paren{\\frac{\\theta+2 \\ell \\pi }{k}}\n+i\\sin \\paren{\\frac{\\theta+2 \\ell \\pi }{k}}} ,\\;\\ell = 0, 1, 2,\\ldots, k-1\n\\end{equation*}\nSince the cosine and sine are periodic of period $2\\pi$, there are exactly $\nk$ distinct numbers which result from this formula.\n\\end{proof}\n\nThe procedure for finding the $k$ $k\\th$ roots of $z \\in \\C$ is as follows.\n\n\\begin{procedure}{Finding roots of a complex number}{finding-kth-roots}\nLet $w$ be a complex number. We wish to find the $n\\th$ roots of $w$, that is all $z$ such that $z^n = w$.\n\nThere are $n$ distinct $n\\th$ roots and they can be found as follows:.\n\n\\begin{enumerate}\n\\item Express both $z$ and $w$ in polar form $z=re^{i\\theta}, w=se^{i\\phi}$. Then $z^n = w$ becomes:\n\\[\n(re^{i\\theta})^n = r^n e^{i n \\theta} = se^{i\\phi}\n\\]\nWe need to solve for $r$ and $\\theta$.\n\\item Solve the following two equations:\n\\begin{eqnarray*}\nr^n &=& s\n\\end{eqnarray*}\n\\begin{eqnarray}\ne^{i n \\theta} &=& e^{i \\phi}\n\\label{roots-eqns}\n\\end{eqnarray}\n\\item The solutions to $r^n = s$ are given by $r = \\sqrt[n]{s}$.\n\n\\item The solutions to $e^{i n \\theta} = e^{i \\phi}$ are given by:\n\\[\nn\\theta = \\phi + 2\\pi \\ell,  \\; \\mbox{for} \\; \\ell = 0,1,2,\\ldots, n-1\n\\]\nor\n\\[\n\\theta = \\frac{\\phi}{n} + \\frac{2}{n} \\pi \\ell, \\; \\mbox{for} \\; \\ell = 0,1,2,\\ldots, n-1\n\\]\n\\item\nUsing the solutions $r, \\theta$ to the equations given in (\\ref{roots-eqns})\nconstruct the $n\\th$ roots of the form $z = re^{i\\theta}$.\n\\end{enumerate}\n\\end{procedure}\n\nNotice that once the roots are obtained in the final step, they can then be converted to standard form if necessary. Let's consider an example of this concept. Note that according to Corollary~\\ref{cor:roots-complex-numbers},\nthere are exactly $3$ cube roots of a complex number.\n\n\\begin{example}{Finding cube roots}{cube-roots}\nFind the three cube roots of $i$. In other words find all $z$ such that $z^3 = i$.\n\\end{example}\n\n\\begin{solution}\nFirst, convert each number to polar form: $z = re^{i\\theta}$ and $i = 1 e^{i \\pi/2}$. The equation now becomes\n\\[\n(re^{i\\theta})^3 = r^3 e^{3i\\theta} = 1 e^{i \\pi/2}\n\\]\nTherefore, the two equations that we need to solve are $r^3 = 1$ and $3i\\theta = i \\pi/2$. Given that $r \\in \\R$ and $r^3 = 1$ it follows that $r=1$.\n\nSolving the second equation is as follows. First divide by $i$. Then, since the argument of $i$ is not unique we write $3\\theta = \\pi/2 + 2\\pi\\ell$ for $\\ell = 0,1,2$.\n\\begin{eqnarray*}\n3\\theta &=& \\pi/2 + 2\\pi\\ell \\; \\mbox{for} \\; \\ell = 0,1,2 \\\\\n\\theta &=& \\pi/6 + \\frac{2}{3} \\pi\\ell \\; \\mbox{for} \\; \\ell = 0,1,2\n\\end{eqnarray*}\n\nFor $\\ell = 0$:\n\\[\n\\theta = \\pi/6 + \\frac{2}{3} \\pi (0) = \\pi/6\n\\]\n\nFor $\\ell = 1$:\n\\[\n\\theta = \\pi/6 + \\frac{2}{3} \\pi(1) = \\frac{5}{6} \\pi\n\\]\n\nFor $\\ell = 2$:\n\\[\n\\theta = \\pi/6 + \\frac{2}{3} \\pi(2) = \\frac{3}{2} \\pi\n\\]\n\nTherefore, the three roots are given by \\[\n1e^{i \\pi/6}, 1e^{i \\frac{5}{6}\\pi}, 1e^{i \\frac{3}{2}\\pi}\n\\]\n\nWritten in standard form, these roots are, respectively,\n\\[\n\\frac{\\sqrt{3}}{2} + i \\frac{1}{2}, -\\frac{\\sqrt{3}}{2} + i \\frac{1}{2}, -i\n\\]\n\n\\end{solution}\n\nThe ability to find $k\\th$ roots can also be used to factor some\npolynomials.\n\n\\begin{example}{Solving a polynomial equation}{solving-polynomial}\nFactor the polynomial $x^{3}-27$.\n\\end{example}\n\n\\begin{solution}\nFirst find the cube roots of 27. By the above procedure\n\\index{polynomials!factoring}, these cube roots\nare $3,3\\paren{\\displaystyle\n\\frac{-1}{2}+i\\displaystyle\\frac{\\sqrt{3}}{2}}$, and $3\\paren{\n\\displaystyle\\frac{-1}{2}-i\\displaystyle\\frac{\\sqrt{3}}{2}}$. You may wish to verify\nthis using the above steps.\n\nTherefore, $x^{3}-27 =$\n\\begin{equation*}\n (x-3) \\paren{x-3\\paren{\\frac{-1}{2}+i\\frac{\\sqrt{3}}{2}}\n} \\paren{x-3\\paren{\\frac{-1}{2}-i\\frac{\\sqrt{3}}{2}}}\n\\end{equation*}\nNote also $\\paren{x-3\\paren{\\frac{-1}{2}+i\\frac{\\sqrt{3}}{2}}}\n\\paren{x-3\\paren{\\frac{-1}{2}-i\\frac{\\sqrt{3}}{2}}}\n=\\allowbreak x^{2}+3x+9$ and so\n\\begin{equation*}\nx^{3}-27=(x-3) (x^{2}+3x+9)\n\\end{equation*}\nwhere the quadratic polynomial $x^{2}+3x+9$ cannot be factored without using\ncomplex numbers.\n\\end{solution}\n\nNote that even though the polynomial $x^{3}-27$ has all real coefficients,\nit has some complex zeros, $3\\paren{\\displaystyle\n\\frac{-1}{2}+i\\displaystyle\\frac{\\sqrt{3}}{2}}$, and $3\\paren{\n\\displaystyle\\frac{-1}{2}-i\\displaystyle\\frac{\\sqrt{3}}{2}}$.\nThese zeros are complex conjugates of each other. It is always the case that if a polynomial has real\ncoefficients and a complex root, it will also\nhave a root equal to the complex conjugate.\n", "meta": {"hexsha": "6a8174b7c8e0b7d927c5460f122f2b57d5718d59", "size": 7149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/complexnumbersRoots.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/complexnumbersRoots.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/complexnumbersRoots.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.0441176471, "max_line_length": 225, "alphanum_fraction": 0.6571548468, "num_tokens": 2665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.9086179018818865, "lm_q1q2_score": 0.7942022175372725}}
{"text": "\\section{Induction}\n\nInduciton is an important tool in computer science, as it provides us one with\nan procedure to show correctness of our algorithms, and two can be directly\ntranslated to recursion.\n\n\\subsection{Definition and Examples}\n\n\\begin{definition*}\n\n\\textbf{Induction} is a mathematical proof technique. Formally, suppose we have\nsome program $P$, which has input $n$. Furthermore, suppose we can show that:\n\\begin{enumerate}[1)]\n\\item $[$Base Case$]$ $P(0)$ is provably correct.\n\\item $[$Inductive Step$]$ Suppose that $P(0), \\dots, P(k)$ is correct for some\nfixed $k \\in \\N$.  Then we can show that $P(k+1)$ is provably correct.\n\\end{enumerate}\nThen it must be true that $\\forall n, P(n)$ is correct. (Note that we don't need\nfor \\textit{zero} that $P(0)$ is provably correct, but rather that $P(n_0)$ is\nprovably correct, for some fixed $n_0$. We will typically take $n_0 = 0, 1$.)\n\nConceptually you can envision this as a staircase. Suppose that you can stand at\nthe bottom of the staircase, and that if you're on step $k$, you can move to\nstep $k+1$. Then we know that $\\forall n$, we can stand on step $n$.\n\n\\end{definition*}\n\nTake the following as applications of induction.\n\n\\begin{itemize}\n\n\\item Prove that $1 + 2 + \\dots + n = \\frac{n(n+1)}{2}$.\n\n\\begin{proof}\n\nClearly for $n = 1$, we have that $1 = \\frac{1(1+1)}{2} = 1$. Now suppose that\n$1 + 2 + \\dots + n = \\frac{n(n+1)}{2}$. We want to show that $1 + \\dots + n+1 =\n\\frac{(n+1)(n+2)}{2}$. Notice that:\n$$\n\\sum_{i=1}^{n+1} i = n+1 + \\sum_{i=1}^{n}i = n+1 + \\frac{n(n+1)}{2}\n$$\nThe last equality being true by our assumption. Now notice we can write\n$n(n+1)/2 = (n^2 + n)/2$, and we can write $n+1 = \\frac{2n + 2}{2}$. Therefore\nadding the two expresions together results in $(n^2 + 3n + 2)/2 =\n(n+1)(n+2)/2$.\n\n\\end{proof}\n\n\\item We call a \\textbf{perfect binary tree} a tree structure such that each\nnon-leaf vertex has exactly two children. So for example, a perfect binary tree\nof height $2$ would be:\n\n\\Tree [.a [.b d e ] [.c f g ] ]\n\nProve that a perfect binary tree of height $n$ has exactly $2^n - 1$ vertices.\n\n\\begin{proof}\n\nFirst suppose $n = 1$. Clearly a tree of height $1$ has only one vertex, and\nindeed $2^1 - 1 = 1$.\n\nNow suppose a tree of height $n$ has $2^n - 1$ vertices. We want to show that a\ntree of height $n+1$ must have $2^{n+1} - 1$ vertices. Consider the root of such\na tree (in the example above it's vertex $a$). Notice that it's left subchild is\na perfect binary tree of height $n$, and so is it's right subtree. Therefore,\ncounting the verteces in each of those subtrees using our supposition that a\ntree of height $n$ has $2^n - 1$ vertices gives us a count of $2(2^n - 1)$ for\nthe vertices under the root. Therefore a tree of height $n+1$ has $2(2^n - 1) +\n1$ vertices ($+1$ for the root). Notice that:\n$$\n2(2^n - 1) + 1 = 2^{n+1} -2  + 1 = 2^{n+1} - 1\n$$\nand therefore we've shown our inductive step.\n\nThus, a perfect binary tree of height $n$ has $2^n - 1$ vertices.\n\n\\end{proof}\n\n\\end{itemize}\n\n\\subsection{Towers of Hanoi and thinking recursively}\n\nThe reason why we're reviewing induction, is that induction is very (read:\n\\textit{\\textbf{VERY}}) useful for proving correctness for recursive functions.\nYou will use it in literally every single part of the rest of the course so it\npays to get it down well. A classical example is Towers of Hanoi.\n\n\\begin{definition*}\n\nTowers of Hanoi is a mathematical puzzle. Suppose we have three rods, and a\nnumber of disks of different sizes $1 \\to n$. which can slide onto any rod. The\npuzzle starts with the disks all arranged on the first rod in descending\norder such that $n$ is at the bottom, and $1$ is at the top. For example, for $n\n= 3$, the beginning configuration is:\n\n$$\n\\begin{matrix}\n-   & | & | \\\\\n--  & | & | \\\\ \n--- & | & | \\\\ \nA & B & C \n\\end{matrix}\n$$\n\nThe goal of this game is to move the entire stack of rings from pole $A$ to pole\n$B$, while obeying the constraints:\n\n\\begin{itemize}\n\n\\item You may move one disk at a time with the command $Move(arg1, arg2)$ where\nthis moves the disk on top of pole $arg1$ to the top of pole $arg2$.\n\n\\item No larger disk may be placed on top of a smaller disk.\n\n\\end{itemize}\n\n\\end{definition*}\n\nWe want to write an algorithm to solve this puzzle, but to also do so with a\nminimal amount of $Move$ calls.\n\n\n", "meta": {"hexsha": "353d87145a010f0e2632246d26e7de7f50e1dbeb", "size": 4317, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/src/src/induction.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/induction.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/induction.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": 35.0975609756, "max_line_length": 80, "alphanum_fraction": 0.6882094047, "num_tokens": 1351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.9086178926024028, "lm_q1q2_score": 0.7942022094262872}}
{"text": "\n\\subsection{Sample variance}\n\nWe previously defined the population variance as \\(\\sigma^2=E[(X-\\mu)^2]\\).\n\nWe define the sample variance as \\(\\sigma^2=\\dfrac{1}{n}\\sum_i(x_i-\\bar x)^2\\).\n\nWe can calculate this using matrices:\n\n\\(M=X-\\bar x\\)\n\n\\(\\sigma^2=\\dfrac{1}{n}M^TM\\).\n\n\\subsubsection{Centred variance}\n\nIf \\(\\bar x =0\\) then:\n\n\\(\\sigma^2=\\dfrac{1}{n}X^TX\\).\n\n", "meta": {"hexsha": "2ee6faafe3763e723e5d1c216e3e67ffb177cacc", "size": 366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summary/02-02-variance.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/summary/02-02-variance.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/summary/02-02-variance.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.3, "max_line_length": 79, "alphanum_fraction": 0.650273224, "num_tokens": 127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545304202039, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7941931591615224}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Properties of Derivatives}\n\n\\objective{Calculate derivates using the Power, Product, and Quotient Rules.}\n\n\n\\index{Derivative!properties}\nThe derivative of a sum of two functions is the sum of the derivatives of each function.\n\nThe derivative of a constant times a function is the constant times the derivative of the function.\n\nThe derivative of a constant is 0.\n\n\\subsubsection{Product Rule (inductive)}\n\\index{Product Rule}\\index{Derivative!of a product}\nThe following proof is very arbitrary and does not feel like something anyone would try\nunprompted (especially in the second line: who would ever think of adding and subtracting the same\nterm in just that way?!).  We will use the following \\textbf{Product Rule} some over the coming chapters,\nbut a full proof that you are responsible for reproducing does not come until §8.3\n\n\\begin{align*}\n  (fg)'(x) & = \\lim_{h\\rightarrow0}\\frac{f(x+h)g(x+h) - f(x)g(x)}{h} \\\\\n  \t&= \\lim_{h\\rightarrow0}\\frac{f(x+h)g(x+h) - f(x)g(x+h) + f(x)g(x+h) + f(x)g(x)}{h} \\\\\n\t&= \\lim_{h\\rightarrow0}\\frac{f(x+h)g(x+h) - f(x)g(x+h)}{h} + \\lim_{h\\rightarrow0}\\frac{f(x)g(x+h)-f(x)g(x)}{h} \\\\\n\t&= \\lim_{h\\rightarrow0}\\left[\\frac{f(x+h) - f(x)}{h} \\cdot g(x+h)\\right] + \\lim_{h\\rightarrow0}\\left[\\frac{g(x+h)-g(x)}{h} \\cdot f(x)\\right] \\\\\n\t&= \\lim_{h\\rightarrow0}\\left[\\frac{f(x+h) - f(x)}{h}\\right] \\cdot g(x) + \\lim_{h\\rightarrow0}\\left[\\frac{g(x+h)-g(x)}{h}\\right] \\cdot f(x)\\\\\n\t&=f'(x)g(x) + f(x)g'(x)\n\\end{align*}\n\n\\subsubsection{Quotient Rule}\n\\index{Quotient Rule}\\index{Derivative!of a quotient}\nThe \\textbf{Quotient Rule} is presented here with a very similar arbitrary trick.  Wait to memorize the proof until chapter 8.\n\n\\begin{align*}\n\\frac{f}{g}' & = \\lim_{h\\rightarrow0}\\cfrac{\\frac{f(x+h)}{g(x+h)}-\\frac{f(x)}{g(x)}}{h} \\\\\n\t&=  \\lim_{h\\rightarrow0}\\frac{g(x)f(x+h)-f(x)g(x+h)}{g(x)g(x+h)h} \\\\\n\t&=  \\lim_{h\\rightarrow0}\\frac{g(x)f(x+h)-f(x)g(x)+f(x)g(x)-f(x)g(x+h)}{g(x)g(x+h)h} \\\\\n\t&=  g(x)\\left[\\lim_{h\\rightarrow0}\\frac{1}{g(x)g(x+h)}\\cdot{}\\frac{f(x+h)-f(x)}{h}\\right]-f(x)\\left[\\lim_{h\\rightarrow0}\\frac{1}{g(x)g(x+h)}\\cdot{}\\frac{g(x+h)-g(x)}{h}\\right] \\\\\n\t&= \\frac{g(x)f'(x) - f(x)g'(x)}{[g(x)]^2}\n\\end{align*}\n\n\\subsection{Power Rule}\n\\index{Power Rule}\\index{Derivative!of a power}\nThe algebraic derivative of $x^n$ is $n\\cdot x^{n-1}$.  While we will furnish a systematic proof \nlater (also in section 8.3), we have seen enough inductive\nexamples of the \\textbf{Power Rule} in this chapter\nthat you are formally responsible for knowing it and using it in all cases.", "meta": {"hexsha": "76a7e411b1eb4af07ea364e661883d36441890dd", "size": 2560, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/0305.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/0305.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/0305.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": 53.3333333333, "max_line_length": 179, "alphanum_fraction": 0.671875, "num_tokens": 919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.8902942290328344, "lm_q1q2_score": 0.7939742373811146}}
{"text": "\\subsubsection{Isothermal Processes}\nIsothermal processes are compression/expansion processes in which the temperature of the gas remains constant ($\\Delta T = 0$). These processes occur very slowly. As an example, we consider a scenario where I have some gas in a cylinder (closed off at the top by a piston), where I push down on the piston very very slowly. Doing so, the gas inside the piston remains at thermal equilibrium with its surroundings. Hence, I as I do work on the gas, an equal amount of energy leaves the gas in the form of heat, and the gas inside the piston stays at the same temperature. \\\\\n\\noindent\nOne immediate consequence that we obtain from $\\Delta E = nc_v\\Delta T$ is that:\n\\begin{equation}\n    \\Delta E = 0\n\\end{equation}\nAnd by the first law of thermodynamics, we have that:\n\\begin{equation}\n    W = -Q\n\\end{equation}\nWhat exactly is the amount of work done in an isothermal process? We once again return to the definition of work:\n\\[ W = -\\int_{V_1}^{V_2}P(V)dV \\]\nWe have to be very careful here though; in this situation, the pressure is not constant as we vary/integrate over the volume. So we have to be a bit clever, and think of a way in which we can express the pressure as a function of volume so we can carry out the integral. If your intution was \"ideal gas law\", then you'd be exactly right! Let us make the substition:\n\\[ P(V) = \\frac{nRT}{V} \\]\nWhich turns the integral into:\n\\[ W = -\\int_{V_1}^{V_2}nRT\\frac{dV}{V}\\]\nThroughout this process $T$ is held constant, and the amount of gas does not change, so we can take most of the terms out of the integral as a constant:\n\\[ W = -nRT\\int_{V_1}^{V_2}\\frac{dV}{V}\\]\nThe remaining integral is straightforward:\n\\[ W = -nRT \\left. \\ln(V) \\right|_{V_1}^{V_2} = -nRT\\left(\\ln(V_2)-\\ln(V_1)\\right) = nRT\\left(\\ln(V_1)-\\ln(V_2)\\right) \\]\nSo applying some laws of logarithms, we hence obtain our expression for the work done on the gas in an isothermal process:\n\\begin{equation}\nW = nRT\\ln\\left(\\frac{V_1}{V_2}\\right)\n\\end{equation}\nAs we found earlier, the heat flow during an isothermal process is simply the negative of this, so:\n\\begin{equation}\n    Q = -nRT\\ln\\left(\\frac{V_1}{V_2}\\right) = nRT\\ln\\left(\\frac{V_2}{V_1}\\right)\n\\end{equation}\n\\noindent\nFinally, we consider how isothermal curves show up on PV diagrams. From how the expression for the work looks (with the $\\ln$ term), you may suspect that we might get a \"curved\" curve rather than a straight diagonal line, and you would be right. Pictured here is an isothermal expansion from initial state $P_1,V_1$ to final state $P_2,V_2$. The temperature stays constant at every point on the curve. \n\n\\begin{center}\n    \\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=bottom,\n        axis y line=left,\n        xmin=0, xmax=10,\n        ymin=0, ymax=10,\n%        % (made labels more common)\n%        % (because of the \"sketch\" type of the plot these should not be needed)\n%        xlabel={Volume $(\\mathrm{m}^3)$},\n%        ylabel={Pressure (Pa)},\n        % (changed ticks + labels to normal ticks instead of extra ticks)\n        xtick={3,6},\n        xticklabels={$V_1$,$V_2$},\n        ytick={1.5,6},\n        yticklabels={$P_2$,$P_1$},  % <-- (changed order of entries)\n    ]\n        % fill the area below the curve\n        % (draw it first, so it is below everything else)\n\n\n        % draw the dashed lines\n        % (using two different approaches)\n        \\addplot [dashed,domain=0:3,samples=2] {6};\n        \\addplot [dashed,domain=0:6,samples=2] {1.5};\n\n        \\draw [dashed,thin] (axis cs:6,1.5) -- (axis cs:6,0);\n        \\draw [dashed,thin] (axis cs:3,6)   -- (axis cs:3,0);\n\n        % now draw the curve\n        \\draw [\n            fleche={0.6:black},              % <-- added\n        ] (axis cs:3,6) to [bend right=30]\n            % store start and end coordinates\n            coordinate [pos=1] (start)\n            coordinate [pos=0] (end)\n        (axis cs:6,1.5);\n\n        % draw start and end point\n        \\fill [radius=2pt]\n            (start) circle[]\n            (end)   circle[];\n    \\end{axis}\n        \\node[below] at (6.5,0) {$V$};\n        \\node[left] at (0,5.5) {$P$};\n        \\node[right] at (2.2,3.4) {$T_1$};\n        \\node[right] at (4.25,0.9) {$T_1$};\n\\end{tikzpicture}\n\\end{center}\n", "meta": {"hexsha": "297254310951c066f7980dfa9d7311eaa1aa424c", "size": 4257, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/isothermal.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/isothermal.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/isothermal.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": 51.9146341463, "max_line_length": 573, "alphanum_fraction": 0.6528071412, "num_tokens": 1281, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110483133799, "lm_q2_score": 0.8902942355821459, "lm_q1q2_score": 0.7939742355418727}}
{"text": "\\subsection{Method} \\label{subsec:method_linear_regression}\n\nConsider that we have a data set of inputs and their corresponding output. Regression is a process of arriving at a relation between the independent input variables and the dependent output variables. In the field of statistical learning, regression is considered to be a supervised learning method. This is because the model parameters generated in regression are learned from labeled data which is data that comprises both inputs and their corresponding output, i.e the labels. In this report, we assume that there are multiple input variables and a single output variable for each member of the data set.\n\\newline \\newline\nThe dataset with $n$ members is defined as $\\mathcal{D} := [({x}_1, y_1 ), ({x}_2, y_2 ), ..., ({x}_n, y_n )]$. Where ${x}_i$ and $y_i$  are the $i^{th}$ input and output respectively. Let, $m$ be the number of components of the input such that ${x}_i := (x_{i1}, x_{i2}, ..., x_{im})$. In linear regression we assume that the data is of the form\n\\begin{equation}\n    {y}_i = 1 \\cdot\\beta_0 + x_{i1}\\beta_1 + x_{i2}\\beta_2 + ... + x_{im}\\beta_m + \\epsilon_i \\label{eq:lin_reg_data}\n\\end{equation}\nwhere $\\beta_0, \\beta_1, \\dots, \\beta_m$ are unknown fixed regression parameters and $\\epsilon_i$ is a random error or noise process consisting of independent identically (iid) normally distributed variables with mean zero and variance $\\sigma^2$ \\cite{shumway_time_2017}. Equation \\ref{eq:lin_reg_data} can be rewritten as $y=\\beta \\phi(x) + \\epsilon$ with\n\\begin{equation}\n    \\phi(x):=[1, x_{i,1}, x_{i,2}, \\dots, x_{i,m}].\n\\end{equation}\nMoreover, it can be shown that $\\mathbb{E}[y] = \\beta \\phi(x)$ and $var(y) = \\sigma^2$. Therefore, $y \\sim \\mathcal{N}(\\beta \\phi(x),\\,\\sigma^{2})$ \\cite{murphy_machine_2012}.\n\\newline \\newline\nIn linear regression, we seek to fit a best-fit line between input, or some transformation of the input, and the output. This best-fit line is chosen such that it minimizes an error or a cost function. The best fit line is a function of input variables and its value is called the predicted value or the fit. We denote this with $\\hat{y}$. The linear regression model has the form:\n\\begin{equation}\n    \\hat{y}_i = 1 \\cdot\\beta_0 + x_{i1}\\beta_1 + x_{i2}\\beta_2 + ... + x_{im}\\beta_m\n\\end{equation}\nThe $\\beta$'s are chosen such that they minimize a cost function. If this cost function is chosen to be the mean squared error (MSE) then we call the regression \\textit{least squares} regression. The mean squared error is defined as \n\\begin{equation}\n    \\mathcal{C} = \\frac{1}{n}\\sum_{i=1}^{n}(y_i-\\hat{y}_i)^2 \\label{eq:cost_function_sum}\n\\end{equation}\n\nBy extending the input such that ${x}_i = (1_i, x_{i1}, x_{i2}, ..., x_{im})$, i.e. the first entry of $x_i$ is a vector which only contains 1, and denoting the parameter vector by ${\\beta} = (\\beta_0, \\beta_1, ..., \\beta_m)$, we can express the predicted value as an inner product such that   \n\\begin{equation*}\n    \\hat{y}_i = {x_i}\\cdot {\\beta} = {x_i}^T{\\beta}.\n\\end{equation*}\nMoreover, we can express the set of predicted outputs as a vector which allows us to write the previous equation as a matrix-vector product:\n\\begin{equation}\n    \\hat{y} = {X}{\\beta} \\label{eq:lin_reg_matrix_model}\n\\end{equation}\nwhere, $\\hat{y}$, ${X}$ and ${\\beta}$ have dimensions $n \\times 1$, $n \\times (m+1)$ and $(m+1) \\times 1$. $X$ is called design matrix. However, such a description is only useful if the output is a linear or near-linear function of the input variables.  We can make the model more \"complex\" by allowing higher powers of input variables and their products to be the features. One possibility is to consider polynomial functions of the input variables. For simplicity, we consider input vectors where $m=2$ as they are the only ones relevant for this project. Then, we can express the predicted output $\\hat{y}$ as a polynomial function of order $p$ such that\n\\begin{equation}\n    \\hat{y}_i = \\beta_0 + \\sum_{k=1}^{k=p}\\sum_{l=0}^{l=p}\\beta_{\\frac{k(k+1)}{2}+l}x_{i1}^{p-l}x_{i2}^{l}\n\\end{equation}\nwhich is equivalent to\n\\begin{equation}\n\\resizebox{.9\\hsize}{!}{$\n    \\underbrace{\\begin{bmatrix}y_1 \\\\ y_2 \\\\ \\vdots \\\\ y_n\\end{bmatrix}}_{n \\times 1} = \\underbrace{\\begin{bmatrix} \n    1 & x_{11} & x_{12} & x_{11}^2 & \\dots & x_{11}^p & x_{11}^{p-1}x_{12} & \\dots & x_{11}x_{12}^{p-1} & x_{12}^p \n    \\\\ 1 & x_{21} & x_{22} & x_{21}^2 & \\dots & x_{21}^p & x_{21}^{p-1}x_{22} & \\dots & x_{21}x_{22}^{p-1} & x_{22}^p \n    \\\\ \\vdots &&&&& \\ddots &&&&\\vdots \\\\ \n    1 & x_{n1} & x_{n2} & x_{n1}^2 & \\dots & x_{n1}^p & x_{n1}^{p-1}x_{n2} & ... & x_{n1}x_{n2}^{p-1} & x_{n2}^p\n    \\end{bmatrix}}_{n \\times \\frac{p^2+5p}{2}}\\underbrace{\\begin{bmatrix}\\beta_0 \\\\ \\beta_1 \\\\ \\vdots \\\\ \\beta_{\\frac{p^2+3p}{2}}\\end{bmatrix}.}_{\\frac{p^2+5p}{2} \\times 1}$}\n\\end{equation}\nFor clarity if $p=2$\n\\begin{equation*}\n    \\hat{y}_i = \\beta_0+\\beta_1 x_{i1} + \\beta_2 x_{i2}.\n\\end{equation*}\nWe see that the output vector is linear in the vector of parameters even though it is nonlinear in the features. Note that $p$ determines the model complexity and therefore the number of columns in the design matrix and the number of parameters. The output vector though depends only on the number of inputs. By changing $p$ we are changing the basis with which we describe $y_i$. \n\\newline \\newline\nAs mentioned before our aim is to find $\\beta$ such that the cost function is minimized. We start by rewriting the equation \\ref{eq:cost_function_sum}:\n\\begin{equation}\n    \\mathcal{C}(\\beta) = \\frac{1}{n}\\sum_{i=1}^{n}(y_i-\\hat{y}_i(\\beta))^2 = \\frac{1}{n}( y -  {\\hat y})^T( y -  {\\hat y}) = \\frac{1}{n}( y -  {X\\beta})^T( y -  {X\\beta}).\n\\end{equation}\n\nThe cost function is at its minimum when its gradient with respect to all parameters is 0, i.e.\n\\begin{equation*}\n    \\nabla_{\\beta}\\mathcal{C}(\\beta) = X^T(y-X\\beta) = 0.\n\\end{equation*}\n\nAssuming that $X$ has full column rank, and hence $X^T X$ is positive definite, solving the above equation provides us with the optimal parameters as follows\n\\begin{equation}\n    \\beta = (X^TX)^{-1}X^Ty.\n\\end{equation}\nThe cost function for a linear regression problem is convex. Hence, there is only one global extremum. This is not proven in this report.\n\\newline \\newline\nIn the case where $X^T X$ is near singular or singular calculating the pseudoinverse (specifically the\nMoore-Penrose inverse) is a very useful and well-known method. It calculates the inverse by using the Singular Value Decomposition algorithm. Moreover, this approach is more efficient than computing the regular inverse \\cite{geron_hands-machine_2019}.\n\\newline \\newline\nAn important step when calculating the best suited model for given input and output data is the splitting of the dataset $\\mathcal{D}$ into a training dataset $\\mathcal{D}_{train} = \\{\\boldsymbol{x}_{train}, y_{train}\\}$ and a test dataset $\\mathcal{D}_{test} = \\{\\boldsymbol{x}_{test}, y_{test}\\}$. The ratio of the number of data points in the $\\mathcal{D}_{test}$ to the number of data points in the $\\mathcal{D}_{train}$ is called the test ratio $r$. The model parameters are learned on the training dataset in the training phase. While, the performance of the model is assessed by various indicators that compare the output of fitting the model, on the input of the test set, with the output of the test set. \\newline\n\nLet the mean squared error(MSE) be \n\\begin{equation}\n    MSE(y, \\hat{y}) = \\frac{1}{n}\\sum_{i=1}^{n}(y_i - \\hat{y_i})^2\n\\end{equation}\nthe squaring is important so that the positive and negative errors do not cancel each other. Certainly, the lower the value of MSE the closer is our prediction($\\hat{y}$) to the ground truth($y$). The training MSE is given as $MSE_{train} = MSE(y_{train}, \\hat{y}_{train})$ and the testing MSE as $MSE_{test} = MSE(y_{test}, \\hat{y}_{test})$. \n\nThe MSE can be decomposed into bias and variance as \n\\begin{equation}\n    MSE = \\underbrace{\\mathbb{E}[(y - \\mathbb{E}[\\hat{y}])^2]}_{\\text{bias}} + \\underbrace{\\mathbb{E}[(\\hat{y} - \\mathbb{E}[\\hat{y}])^2]}_{\\text{variance}} + \\sigma^2\n\\end{equation}\n\nLet the $R^2$ score be \n\\begin{equation}\n    R^2(y, \\hat{y}) = 1 - \\frac{\\sum_{i=1}^{n}(y_i-\\hat{y})^2}{\\sum_{i=1}^{n}(y_i-\\mathbb{E}[\\hat{y}])^2}.\n\\end{equation} \nIt measures the ability of the model to capture the true variance relative to the actual variance. When the model fits the data perfectly $R^2=1$. While, the least possible value of $R^2_{train}$ is 0, but $R^2_{test}$ can be negative.  \n\nThe difference in the MSE values  for the training and testing set determines the degree of generalization of the model from trained data to new unseen data. The average generalization error is \\cite{mehta2019high}\n\\begin{equation*}\n    |MSE_{train} - MSE_{test}| = 2\\sigma^2\\frac{m}{n}.\n\\end{equation*}\nIf $m >> n$ then the model is not generalising, i.e. learning. In addition, the error can be large if the intrinsic noise $\\sigma^2$ in the data is large. To counter this problem, regularisation is performed. In regularisation, the parameter values are penalized. In ridge regression, the $L^2$ norm of the parameter vector is penalized and in lasso regression, the $L^1$ norm of the parameter vector is penalized. This is done by modifying the cost functions as follows\n\\begin{align}\n    \\mathcal{C}_{ridge}(\\beta) &=  \\frac{1}{n}( y -  {X\\beta})^T( y -  {X\\beta}) + \\lambda||\\beta||_2^2, \\\\\n    \\mathcal{C}_{lasso}(\\beta) &=  \\frac{1}{n}( y -  {X\\beta})^T( y -  {X\\beta}) + \\lambda||\\beta||_1.\n\\end{align}\n\n\\subsubsection{Feature Scaling}\\label{subsubsec:scaling}\nIn general, machine learning algorithms do not perform well if the scales of the data vary a lot. There exist different scaling methods. We focus on min-max scaling, also known as min-max normalization. In this approach, the values are scaled and shifted such that they range from 0 to 1, i.e. \n\\begin{equation*}\n    x^{'} = \\frac{x - min(x)}{max(x) - min(x)}.\n\\end{equation*}\n\n\\subsubsection{Need for resampling}\nTypically, data contains outliers. These outliers can be erroneously obtained data. They can also be the true data that sometimes deviates from the established patterns of the system due to intrinsic noise. The presence of outliers in both the training and the testing set can either influence the fitting of parameters or the statistics. Therefore, it is essential to subdue the effects of outliers using methods that usually involve multiple iterations of training and testing on different subsets of the data. Moreover, the statistics obtained for a single fit are not necessarily the true indicator of the model performance. There is intrinsic variance in those statistics. To ameliorate the effect of variance we utilize resampling techniques. In resampling, we repeatedly learn the model with a different training set and find their statistical performance on the different test sets. In the end, the mean of the statistics of individual iterations is taken to be the final statistic. \\newline \\newline In the following sections we discuss two of the most commonly used methods: the bootstrap algorithm and cross-validation. \n\\subsubsection{Bootstrap Algorithm}\\label{subsubsec:bootstrap}\nThe bootstrap algorithm is a resampling technique that uses sampling with replacement. There are multiple variants of the bootstrap method. We use one that is distinct from the lecture notes. \\newline\nThe steps of the algorithm are as follows:\n\\begin{enumerate}\n    \\item Let the number of bootstrap iterations on given data be: $n_{boots}$\n    \\item For each bootstrap iteration $n_{bi}$:\n    \\begin{enumerate}\n        \\item Randomly divide the input data consisting of $n$ samples into two categories. The two categories are the training and test set. The training set has $(1-r)n$  number of samples which are randomly selected with replacement. The rest of the samples then make up the testing set. Therefore the number of samples in the testing set is greater than or equal to $rn$. Here, $r$ is the testing ratio.\n        \\item Train parameters for the training set and fit them to the testing set.\n        \\item Compute statistics on the training set: $MSE_i, R^2_i$\n    \\end{enumerate}\n    \\item The final statistics of the bootstrap algorithm are the mean of the statistics of all the bootstrap iterations.\n\\end{enumerate}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1\\linewidth]{Images/bootstrap_diagram.png}\n    \\caption{Flowchart of the bootstrap algorithm.}\n    \\label{fig:bootstrap_algorithm}\n\\end{figure}\n\n\\subsubsection{K-fold Cross-Validation}\\label{subsubsec:cross_validation}\nK-fold cross-validation is an ideal method to circumvent the problem that data is often scarce and there is usually not enough data to set aside a validation set. To avoid this problem the data into $k$ parts of the same size \\cite{friedman2001elements}. \\newline\nThe steps of the algorithm are as follows:\n\\begin{enumerate}\n    \\item The data is divided into a finite number $k_{folds}$ of equal-sized sets called folds.\n    \\item For each fold $k_{fi}$:\n    \\begin{enumerate}\n        \\item Take the fold as the testing set while the rest of the folds comprise the training set.\n        \\item Train parameters for the training set and fit them to the testing set.\n        \\item Compute statistics on the training set: $MSE_i, R^2_i$\n    \\end{enumerate}\n    \\item The final statistics of the cross-validation algorithm are the mean of the statistics obtained by considering each fold as the testing set.\n\\end{enumerate}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=1\\linewidth]{Images/cross_validation_diagram.png}\n    \\caption{Flowchart of the k-fold cross-validation algorithm with $k_{folds}=3$ and $n=9$.}\n    \\label{fig:cross_val_algorithm}\n\\end{figure}\n\n%\\subsubsection{Stochastic Gradient Descent}\\label{subsubsec:SGD}\n%SGD is not a machine learning technique but an optimization technique. It is useful in the optimization %requirement for logistic regression. \n\n%SGD comes in various variants. The most common variant due to its good empirical performance is a mix of epoch and mini-batches. Mini-batches are a subset of data of size m obtained by sampling the whole training data without replacement. This is where randomness and stochasticity come from.", "meta": {"hexsha": "d86c1af527125537cf2a07169674b0458c00a57b", "size": 14284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/report/sections/method_linear_regression.tex", "max_stars_repo_name": "am-kaiser/CompSci-Project-1", "max_stars_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documentation/report/sections/method_linear_regression.tex", "max_issues_repo_name": "am-kaiser/CompSci-Project-1", "max_issues_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-11-01T08:32:11.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-16T19:51:18.000Z", "max_forks_repo_path": "documentation/report/sections/method_linear_regression.tex", "max_forks_repo_name": "am-kaiser/CompSci-Project-1", "max_forks_repo_head_hexsha": "098363c47c9409d6ffce1d03a968b6f2265c5fcc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-17T10:51:25.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-17T10:51:25.000Z", "avg_line_length": 93.9736842105, "max_line_length": 1131, "alphanum_fraction": 0.7275273033, "num_tokens": 4087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8479677583778257, "lm_q1q2_score": 0.7939395035572335}}
{"text": "\\subsection{Combining Two Functions}\r\nLet $f$ and $g$ be two functions.\r\nThen we can form new functions by adding, subtracting, multiplying, or dividing.\r\nThese new functions, $f+g$, $f-g$, $fg$ and $f/g$, are defined in the usual way.\r\n\r\n\\begin{formulabox}[Operations on Functions]\r\n$$(f+g)(x)=f(x)+g(x)\\qquad \\qquad (f-g)(x)=f(x)-g(x)$$\r\n$$(fg)(x)=f(x)g(x)\\qquad \\qquad \\left(\\frac{f}{g}\\right)(x)=\\frac{f(x)}{g(x)}$$\r\n\\end{formulabox}\r\n\r\nSuppose $D_f$ is the domain of $f$ and $D_g$ is the domain of $g$.\r\nThen the domains of $f+g$, $f-g$ and $fg$ are the same and are equal to the intersection $D_f\\cap D_g$ (that is, everything that is in \\ifont{common} to both the domain of $f$ and the domain of $g$).\r\nSince division by zero is \\ifont{not allowed}, the domain of $f/g$ is $\\{x\\in D_f\\cap D_g:g(x)\\neq 0\\}$.\r\n\r\nAnother way to combine two functions $f$ and $g$ together is a procedure called composition.\r\n\r\n\\begin{formulabox}[Function Composition]\r\nGiven two functions $f$ and $g$, the \\ffont{composition} of $f$ and $g$, denoted by $f\\circ g$, is defined as:\r\n$$(f\\circ g)(x)=f(g(x)).$$\r\n\\end{formulabox}\r\n\r\nThe domain of $f\\circ g$ is $\\{x\\in D_g:g(x)\\in D_f\\}$, that is, it contains all values $x$ in the domain of $g$ such that $g(x)$ is in the domain of $f$.\r\n\r\n\\begin{example}{Domain of a Composition}{DomainofaComposition}\r\nLet $f(x)=x^2$ and $g(x)=\\sqrt x$.\r\nFind the domain of $f\\circ g$.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThe domain of $f$ is $D_f=\\{x\\in\\R\\}$. \r\nThe domain of $g$ is $D_g=\\{x\\in\\R:x\\geq 0\\}$.\r\nThe function $(f\\circ g)(x)=f(g(x))$ is:\r\n$$f(g(x))=\\left(\\sqrt x\\right)^2=x.$$\r\nTypically, $h(x)=x$ would have a domain of $\\{x\\in\\R\\}$, but since it came from a {\\bf composed function}, we must consider $g(x)$ when looking at the domain of $f(g(x))$. \r\nThus, the domain of $f\\circ g$ is $\\{x\\in\\R:x\\geq 0\\}$.\r\n\\end{solution}\r\n\r\n\\begin{example}{Combining Two Functions}{CombiningTwoFunctions}\r\nLet $f(x)=x^2+3$ and $g(x)=x-2$.\r\nFind $f+g$, $f-g$, $fg$, $f/g$, $f\\circ g$ and $g\\circ f$.\r\nAlso, determine the domains of these new functions.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nFor $f+g$ we have:\r\n$$(f+g)(x)=f(x)+g(x)=(x^2+3)+(x-2)=x^2+x+1.$$\r\nFor $f-g$ we have:\r\n$$(f-g)(x)=f(x)-g(x)=(x^2+3)-(x-2)=x^2+3-x+2=x^2-x+5.$$\r\nFor $fg$ we have:\r\n$$(fg)(x)=f(x)\\cdot g(x)=(x^2+3)(x-2)=x^3-2x^2+3x-6.$$\r\nFor $f/g$ we have:\r\n$$\\left(\\frac{f}{g}\\right)(x)=\\frac{f(x)}{g(x)}=\\frac{x^2+3}{x-2}.$$\r\nFor $f\\circ g$ we have:\r\n$$(f\\circ g)(x)=f(g(x))=f(x-2)=(x-2)^2+3=x^2-4x+7.$$\r\nFor $g\\circ f$ we have:\r\n$$(g\\circ f)(x)=g(f(x))=g(x^2+3)=(x^2+3)-2=x^2+1.$$\r\nThe domains of $f+g$, $f-g$, $fg$, $f\\circ g$ and $g\\circ f$ is $\\{x\\in\\mathbb{R}\\}$, while the domain of $f/g$ is $\\{x\\in\\mathbb{R}\\,:\\,x\\neq 2\\}$.\r\n\\end{solution}\r\n\r\nAs in the above problem, $f\\circ g$ and $g\\circ f$ are generally different functions.", "meta": {"hexsha": "76188bf75d9ade07ace6d1e9891526ba1e321e6b", "size": 2827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-2-2-compositions.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-2-compositions.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-2-compositions.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.1166666667, "max_line_length": 200, "alphanum_fraction": 0.609833746, "num_tokens": 1119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7939278698294285}}
{"text": "\\section{Trace and Determinant}\r\n\\begin{definition}\r\n    Let $A\\in M_n(F)=M_{n,n}(F)$ be a square $n\\times n$ matrix.\r\n    The trace of $A$ is defined to be\r\n    $$\\operatorname{tr}A=\\sum_{i=1}^nA_{ii}$$\r\n\\end{definition}\r\n\\begin{remark}\r\n    The map sending a matrix to its trace is a linear form.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    $\\operatorname{tr}(AB)=\\operatorname{tr}(BA)$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write stuff out.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    Similar matrices have the same trace.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    $\\operatorname{tr}(P^{-1}AP)=\\operatorname{tr}(APP^{-1})=\\operatorname{tr}(A)$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    If $\\alpha:V\\to V$ is linear, then $\\operatorname{tr}\\alpha=\\operatorname{tr}[\\alpha]_B$ for any choice of basis $B$ of $V$.\r\n    It is well-defined by the preceding corollary.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    Let $\\alpha:V\\to V$ be linear and $\\alpha^\\ast:V^\\ast\\to V^\\ast$ be the dual map, then $\\operatorname{tr}\\alpha=\\operatorname{tr}\\alpha^\\ast$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Choose any basis $B$ of $V$, then\r\n    $$\\operatorname{tr}\\alpha=\\operatorname{tr}[\\alpha]_B=\\operatorname{tr}[\\alpha]_B^\\top=\\operatorname{tr}[\\alpha^\\ast]_{B^\\ast}=\\operatorname{tr}\\alpha^\\ast$$\r\n    as desired.\r\n\\end{proof}\r\nRecall that we can decompose any permutation $\\sigma\\in S_n$ into a product of transpositions.\r\n\\begin{definition}\r\n    The signature of a permutation is the (necessarily unique) homomorphism $\\epsilon:S_n\\to\\{1,-1\\}$ that sends any transposition to $-1$.\r\n\\end{definition}\r\nThis map $\\epsilon$ is well-defined as we know that the parity of the number of transpositions that builds up a permutation is fixed.\r\n\\begin{definition}\r\n    Let $A=(a_{ij})\\in M_n(F)$.\r\n    We define the determinant of $A$ as\r\n    $$\\det A=\\sum_{\\sigma\\in S_n}\\epsilon(\\sigma)a_{\\sigma(1)1}a_{\\sigma(2)2}\\cdots a_{\\sigma(n)n}$$\r\n\\end{definition}\r\n\\begin{example}\r\n    For $n=2$, we have\r\n    $$\\det\\begin{pmatrix}\r\n        a_{11}&a_{12}\\\\\r\n        a_{21}&a_{22}\r\n    \\end{pmatrix}=a_{11}a_{22}-a_{12}a_{21}$$\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $A=(a_{ij})$ is an upper (resp. lower) triangular matrix, i.e. $a_{ij}=0$ for $i>j$ (resp. $i<j$), then $\\det A=0$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    The only permutation $\\sigma$ such that $\\sigma(j)\\le j$ (resp. $\\sigma(j)\\ge j$) for all $j$ is the identity.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    $\\det A=\\det A^\\top$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    For any $\\sigma\\in S_n$ we know that $\\epsilon(\\sigma)=\\epsilon(\\sigma^{-1})$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A volumn form $d$ in $F^n$ is a function $(F^n)^n\\to F$ such that:\\\\\r\n    1. It is multilinear:\r\n    For any $i\\in\\{1,\\ldots,n\\}$ and $v_1,\\ldots,v_{i-1},v_{i+1},\\ldots,v_n\\in F^n$, the map\r\n    $$v\\mapsto d(v_1,\\ldots,v_{i-1},v,v_{i+1},\\ldots,v_n\\in F^n)$$\r\n    is linear.\\\\\r\n    2. It is an alternating form:\r\n    If $v_i=v_j$ for some $i\\neq j$, then $d(v_1,\\ldots,v_n)=0$.\r\n\\end{definition}\r\nWhat we want to prove that there is only one volumn form (up to multiplicative constant).\r\nIf this is true, then it necessarily equals $\\det$ in the following way:\r\n\\begin{lemma}\r\n    $\\det$ is a volumn form via the obvious identification $M_n(F)=(F^n)^n$ by grouping the $n$ column vectors as a tuple.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $\\det$ is linear as it is linear in any entry.\r\n    It is an alternating form as $\\epsilon$ sends any transposition to $-1$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $d$ be a volumn form, then swapping two entries changes the sign.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    For any $i\\neq j$, $d(v_1,\\ldots,v_i,\\ldots,v_j,\\ldots,v_n)+ d(v_1,\\ldots,v_j,\\ldots,v_i,\\ldots,v_n)= d(v_1,\\ldots,v_i+v_j,\\ldots,v_i+v_j,\\ldots,v_n)=0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    For any $\\sigma\\in S_n$ and volume form $d$,\r\n    $$d(v_{\\sigma_1},\\ldots,v_{\\sigma_n})=\\epsilon(\\sigma)d(v_1,\\ldots,v_n)$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Just decompose $\\sigma$ into transpositions.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $A\\in M_n(F)$ and let $A^{(i)}$ be the $i^{th}$ column of $A$.\r\n    For any volumn form $d$, we have\r\n    $$d(A^{(1)},\\ldots,A^{(n)})=\\det(A)d(e_1,\\ldots,e_n)$$\r\n    where $(e_i)_j=\\delta_{ij}$.\r\n\\end{theorem}\r\nThis is what we wanted.\r\n\\begin{proof}\r\n    Just expand using linearity and the preceding corollary.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $\\det$ is the unique volumn form that maps $(e_1,\\ldots,e_n)$ to $1$.\r\n\\end{corollary}", "meta": {"hexsha": "842f7570547b2f7d72eddd5b23d32994bb922979", "size": 4432, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/det.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": "11/det.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": "11/det.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": 41.8113207547, "max_line_length": 162, "alphanum_fraction": 0.6439530686, "num_tokens": 1535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267660487572, "lm_q2_score": 0.9136765322283324, "lm_q1q2_score": 0.7938266267105851}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[legalpaper, portrait, margin=1in]{geometry}\n\n\\title{Mathemaddict Arctan Integral}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\nEvaluate: $$\\int\\limits_{0}^{\\infty} \\frac{\\tan ^{-1}\\left(\\frac{3}{2 x}\\right)-\\tan ^{-1}\\left(\\frac{1}{x}\\right)}{x} \\: d x$$\n\\section{Solution}\n\nTaking Substitution,\n$$\\begin{aligned}\n\\frac{1}{x} &=t \\\\\n\\frac{-1}{x^{2}} \\: d x &=d t\n\\end{aligned}$$\nHence, our Integral becomes,\n$$I=\\int\\limits_{0}^{\\infty} \\frac{\\tan ^{-1}\\left(\\frac{3 t}{2}\\right)-\\tan ^{-1}(t)}{t} \\: dt$$\nLet's derive a general formula for:-\n$$I_{(a, b)}=\\int_{0}^{\\infty} \\frac{\\tan ^{-1}(a x)-\\tan ^{-1}(b x)}{x} \\: dx$$\nApplying Leibniz Rule w.r.t Parameter $a$, \n$$\\frac{\\partial I_{(a, b)}}{\\partial a}=\\int_{0}^{\\infty} \\frac{1}{1+a^{2} x^{2}}\\:  d x=\\frac{\\pi}{2 a}$$\nIntegrating it back, \n$$\\therefore \\quad I_{(a, b)}=\\frac{\\pi}{2} \\ln (a)+c$$\nIf we evaluate the special case for $a=b$,\nwe can calculate the value of $c$ as,\n$$c=-\\frac{\\pi}{2} \\ln b$$\nHence,\n$$\\begin{aligned}\nI_{(a, b)} \n&=\\frac{\\pi}{2} \\ln a-\\frac{\\pi}{2} \\ln b \\\\\nI_{(a, b)}\n&=\\frac{\\pi}{2} \\ln \\left(\\frac{a}{b}\\right)\n\\end{aligned}$$\nNow substituting:-\n$$a=\\frac{3}{2}, b=1$$\nThus,\n$$\\boxed{I_{\\left(\\frac{3}{2}, 1\\right)}=\\frac{\\pi}{2} \\ln \\frac{3}{2}}$$\n\\end{document}\n", "meta": {"hexsha": "974e2ae4371daaac74b0b8083579a3a91db6651b", "size": 1405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Mathemaddict's Questions/Arctan Integral.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Mathemaddict's Questions/Arctan Integral.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Mathemaddict's Questions/Arctan Integral.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 29.8936170213, "max_line_length": 127, "alphanum_fraction": 0.6056939502, "num_tokens": 589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.7938098466197765}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $T:\\Poly_2 \\to \\R$ be a linear transformation such that\n  \\begin{equation*}\n    T(x^2)=1,\n    \\quad\n    T(x^2+x)=5,\n    \\quad\\mbox{and}\\quad\n    T(x^2+x+1)=-1.\n  \\end{equation*}\n  Find $T(ax^2+bx+c)$.\n  \\begin{sol}\n    By linearity we have\n    $T(x^2)=1$, $T(x) = T(x^2+x - x^2)= T(x^2+x) - T(x^2)= 5-1=4$, and\n    $T(1) = T((x^2+x+1)-(x^2+x))=T(x^2+x+1)-T(x^2+x)= -1-5=-6$.\n    Thus $T(ax^2+bx+c) = aT(x^2) + bT(x) + cT(1) = a+4b-6c$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let vectors $\\vect{v}_1,\\ldots,\\vect{v}_n\\in\\R^n$ and\n  $\\vect{w}_1,\\ldots,\\vect{w}_n\\in\\R^m$ be given. Let $A$ be the\n  matrix whose columns are $\\vect{v}_1,\\ldots,\\vect{v}_n$, and assume\n  that $A^{-1}$ exists. Show that there exists a linear transformation\n  $T$ such that $T(\\vect{v}_i)=\\vect{w}_i$ for $i=1,\\ldots,n$.\n  \\begin{sol}\n    The matrix $A$ is invertible if and only if its rank is $n$, which\n    means that $\\vect{v}_1,\\ldots,\\vect{v}_n$ are linearly independent\n    and therefore a basis of $\\R^n$. The existence of $T$ then follows\n    from Theorem~\\ref{thm:transformation-basis}.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "02c57d6c61811326c861b04b083b229e234cae01", "size": 1131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsGeneral-Basis.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsGeneral-Basis.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsGeneral-Basis.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 32.3142857143, "max_line_length": 70, "alphanum_fraction": 0.5870910698, "num_tokens": 489, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8774767778695834, "lm_q1q2_score": 0.7938098434054782}}
{"text": "\n\\subsection{Goal}\n\nLet's prove that:\n\n\\(\\sum_{i=0}^n i= \\dfrac{n(n+1)}{2}\\)\n\n\\subsection{Proof by induction}\n\nWe use the inference rules Modus Ponens, which says that if \\(X\\) is true, and \\(X\\rightarrow Y\\) is true, then \\(Y\\) is true.\n\n\\subsection{True for \\(n=0\\)}\n\nWe know this is true for \\(n=0\\):\n\n\\(0=\\dfrac{0(0+1)}{2}\\)\n\n\\(0=0\\)\n\n\\subsection{If it's true for \\(n\\), it's true for \\(n+1\\)}\n\nWe can also prove that if it true for \\(n\\), it is true for \\(n+1\\).\n\n\\(\\sum_{i=0}^{n+1} i= \\dfrac{(n+1)(n+2)}{2}\\)\n\n\\((n+1)+\\sum_{i=0}^{n} i= \\dfrac{n^2 +3n +2}{2}\\)\n\nIf it is true for \\(n\\), then:\n\n\\((n+1)+\\dfrac{n(n+1)}{2}= \\dfrac{n^2 +3n +2}{2}\\)\n\n\\(\\dfrac{n^2+3n+2}{2}= \\dfrac{n^2 +3n +2}{2}\\)\n\n\\(1=1\\)\n\n\\subsection{Result}\n\nSo we know that it is true for \\(n=0\\), and if it is true for \\(n\\), then it is true for \\(n+1\\). As a result it is true for all natural numbers.\n\n", "meta": {"hexsha": "c1cbe8289487b9c77a06e70f08033c858acf2987", "size": 876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sequences/04-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/logic/sequences/04-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/logic/sequences/04-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": 21.9, "max_line_length": 145, "alphanum_fraction": 0.5742009132, "num_tokens": 363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741322079105, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7938034532268589}}
{"text": "\n\\subsection{Odds}\n\nGiven a set of outcomes for a variable, the odds of the outcome are defined as:\n\n\\(o_f=\\dfrac{P(E)}{P(E^C)}\\)\n\nFor example, the odds of rolling a \\(6\\) are \\(\\dfrac{1}{5}\\).\n\n", "meta": {"hexsha": "9d1321d0b43f0c07809b07b4f115526555edc585", "size": 195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityAxioms/04-01-odds.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-01-odds.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-01-odds.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.5, "max_line_length": 79, "alphanum_fraction": 0.6512820513, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9525741268224333, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7938034487390082}}
{"text": "\\section{Some proofs}\n\nIn this section, we prove Theorems~\\ref{thm:well-defined-determinant}\nand {\\ref{thm:determinant-row-operations}}. This section can be\nskipped by readers who are not interested in the proofs.\n\n% ----------------------------------------------------------------------\n\\subsection{Proof of Theorem~\\ref{thm:well-defined-determinant}}\n\n\\begin{lemma}{Expanding along any column}{well-defined-column-cofactor}\n  Let $A$ be an $n\\times n$-matrix. Expanding along any two columns\n  gives the same answer.\n\\end{lemma}\n\n\\begin{proof}\n  The result is proved by induction on $n$. This means, when we prove\n  the result for $n\\times n$-matrices, we already assume it is true\n  for $(n-1)\\times(n-1)$-matrices. We only sketch the proof in the\n  case where $n=4$. We also only show that expanding along the first\n  and second columns gives the same result. The proof for general $n$\n  and for two arbitrary columns $i$ and $j$ is very similar.\n\n  Expanding $A$ along the first column, we get\n  \\begin{equation}\\label{eqn:well-defined-column-cofactor1}\n    a_{11}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{21}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    + a_{31}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{41}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n    \\end{absmatrix}.\n  \\end{equation}\n  Expanding $A$ along the second column, we get\n  \\begin{equation}\\label{eqn:well-defined-column-cofactor2}\n    - a_{12}\\begin{absmatrix}{ccc}\n      a_{21} & a_{23} & a_{24} \\\\\n      a_{31} & a_{33} & a_{34} \\\\\n      a_{41} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    + a_{22}\\begin{absmatrix}{ccc}\n      a_{11} & a_{13} & a_{14} \\\\\n      a_{31} & a_{33} & a_{34} \\\\\n      a_{41} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{32}\\begin{absmatrix}{ccc}\n      a_{11} & a_{13} & a_{14} \\\\\n      a_{21} & a_{23} & a_{24} \\\\\n      a_{41} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    + a_{42}\\begin{absmatrix}{ccc}\n      a_{11} & a_{13} & a_{14} \\\\\n      a_{21} & a_{23} & a_{24} \\\\\n      a_{31} & a_{33} & a_{34} \\\\\n    \\end{absmatrix}.\n  \\end{equation}\n  To show these two expressions are equal, we expand each of the\n  $3\\times 3$-matrices along the first column. Expanding the matrices\n  in {\\eqref{eqn:well-defined-column-cofactor1}}, we get\n  \\begin{eqnarray*}\n    &&\n       a_{11}\\paren{\n       a_{22} \\begin{absmatrix}{cc}\n         a_{33} & a_{34} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{32} \\begin{absmatrix}{cc}\n      a_{23} & a_{24} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{42} \\begin{absmatrix}{cc}\n      a_{23} & a_{24} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       -a_{21}\\paren{\n       a_{12} \\begin{absmatrix}{cc}\n         a_{33} & a_{34} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{32} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{42} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       +a_{31}\\paren{\n       a_{12} \\begin{absmatrix}{cc}\n         a_{23} & a_{24} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{22} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{42} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{23} & a_{24} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       -a_{41}\\paren{\n       a_{12} \\begin{absmatrix}{cc}\n         a_{23} & a_{24} \\\\\n         a_{33} & a_{34} \\\\\n       \\end{absmatrix}\n    -a_{22} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}\n    +a_{32} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{23} & a_{24} \\\\\n    \\end{absmatrix}}.\n  \\end{eqnarray*}\n  Expanding the matrices in\n  {\\eqref{eqn:well-defined-column-cofactor2}}, we get\n  \\begin{eqnarray*}\n    &&\n     -a_{12}\\paren{\n       a_{21} \\begin{absmatrix}{cc}\n         a_{33} & a_{34} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{31} \\begin{absmatrix}{cc}\n      a_{23} & a_{24} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{41} \\begin{absmatrix}{cc}\n      a_{23} & a_{24} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       +a_{22}\\paren{\n       a_{11} \\begin{absmatrix}{cc}\n         a_{33} & a_{34} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{31} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{41} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       -a_{32}\\paren{\n       a_{11} \\begin{absmatrix}{cc}\n         a_{23} & a_{24} \\\\\n         a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    -a_{21} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{41} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{23} & a_{24} \\\\\n    \\end{absmatrix}}\n    \\\\\n    &&\n       +a_{42}\\paren{\n       a_{11} \\begin{absmatrix}{cc}\n         a_{23} & a_{24} \\\\\n         a_{33} & a_{34} \\\\\n       \\end{absmatrix}\n    -a_{21} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}\n    +a_{31} \\begin{absmatrix}{cc}\n      a_{13} & a_{14} \\\\\n      a_{23} & a_{24} \\\\\n    \\end{absmatrix}}.\n  \\end{eqnarray*}\n  Comparing the two expressions term by term, we see that they are\n  equal.\n\\end{proof}\n\n\\begin{lemma}{Expanding along any row}{well-defined-row-cofactor}\n  Let $A$ be an $n\\times n$-matrix. Expanding along any two rows gives\n  the same answer.\n\\end{lemma}\n\n\\begin{proof}\n  The proof is analogous to that of\n  Lemma~\\ref{lem:well-defined-column-cofactor}, expanding along rows instead\n  of columns.\n\\end{proof}\n\n\\begin{lemma}{Expanding along a column and row}{well-defined-column-row-cofactor}\n  Let $A$ be an $n\\times n$-matrix. Expanding along the first column\n  gives the same answer as expanding along the first row.\n\\end{lemma}\n\n\\begin{proof}\n  Again, we only illustrate the proof in case of a $4\\times 4$-matrix,\n  but the general proof is very similar. Expanding $\\det(A)$ along the\n  first column, we get:\n  Expanding $A$ along the first column, we get\n  \\begin{equation}\\label{eqn:well-defined-row-column-cofactor1}\n    a_{11}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{21}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    + a_{31}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{41}\\begin{absmatrix}{ccc}\n      a_{12} & a_{13} & a_{14} \\\\\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n    \\end{absmatrix}.\n  \\end{equation}\n  Expanding $A$ along the first row, we get:\n  \\begin{equation}\\label{eqn:well-defined-row-column-cofactor2}\n    a_{11}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} & a_{24} \\\\\n      a_{32} & a_{33} & a_{34} \\\\\n      a_{42} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{12}\\begin{absmatrix}{ccc}\n      a_{21} & a_{23} & a_{24} \\\\\n      a_{31} & a_{33} & a_{34} \\\\\n      a_{41} & a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    + a_{13}\\begin{absmatrix}{ccc}\n      a_{21} & a_{22} & a_{24} \\\\\n      a_{31} & a_{32} & a_{34} \\\\\n      a_{41} & a_{42} & a_{44} \\\\\n    \\end{absmatrix}\n    - a_{14}\\begin{absmatrix}{ccc}\n      a_{21} & a_{22} & a_{23} \\\\\n      a_{31} & a_{32} & a_{33} \\\\\n      a_{41} & a_{42} & a_{43} \\\\\n    \\end{absmatrix}.\n  \\end{equation}\n  To show these two expressions are equal, let us expand each of the\n  $3\\times 3$-matrices in\n  {\\eqref{eqn:well-defined-row-column-cofactor1}} along the first row,\n  except for the first matrix. This yields:\n  \\begin{eqnarray*}\n    &&\n       a_{11}\\begin{absmatrix}{ccc}\n         a_{22} & a_{23} & a_{24} \\\\\n         a_{32} & a_{33} & a_{34} \\\\\n         a_{42} & a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    \\\\\n    &&\n    - a_{21}\\paren{\n    a_{12}\\begin{absmatrix}{ccc}\n      a_{33} & a_{34} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    -a_{13}\\begin{absmatrix}{ccc}\n      a_{32} & a_{34} \\\\\n      a_{42} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{14}\\begin{absmatrix}{ccc}\n      a_{32} & a_{33} \\\\\n      a_{42} & a_{43} \\\\\n    \\end{absmatrix}\n    }\n    \\\\\n    &&\n    + a_{31}\\paren{\n    a_{12}\\begin{absmatrix}{ccc}\n      a_{23} & a_{24} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    -a_{13}\\begin{absmatrix}{ccc}\n      a_{22} & a_{24} \\\\\n      a_{42} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{14}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} \\\\\n      a_{42} & a_{43} \\\\\n    \\end{absmatrix}\n    }\n    \\\\\n    &&\n    - a_{41}\\paren{\n    a_{12}\\begin{absmatrix}{ccc}\n      a_{23} & a_{24} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}\n    -a_{13}\\begin{absmatrix}{ccc}\n      a_{22} & a_{24} \\\\\n      a_{32} & a_{34} \\\\\n    \\end{absmatrix}\n    +a_{14}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} \\\\\n      a_{32} & a_{33} \\\\\n    \\end{absmatrix}\n    }.\n  \\end{eqnarray*}\n  On the other hand, let us expand each of the\n  $3\\times 3$-matrices in\n  {\\eqref{eqn:well-defined-row-column-cofactor2}} along the first\n  column, except for the first matrix. This yields:\n  \\begin{eqnarray*}\n    &&\n       a_{11}\\begin{absmatrix}{ccc}\n         a_{22} & a_{23} & a_{24} \\\\\n         a_{32} & a_{33} & a_{34} \\\\\n         a_{42} & a_{43} & a_{44} \\\\\n       \\end{absmatrix}\n    \\\\\n    &&\n    - a_{12}\\paren{\n    a_{21}\\begin{absmatrix}{ccc}\n      a_{33} & a_{34} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    -a_{31}\\begin{absmatrix}{ccc}\n      a_{23} & a_{24} \\\\\n      a_{43} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{41}\\begin{absmatrix}{ccc}\n      a_{23} & a_{24} \\\\\n      a_{33} & a_{34} \\\\\n    \\end{absmatrix}\n    }\n    \\\\\n    &&\n    + a_{13}\\paren{\n    a_{21}\\begin{absmatrix}{ccc}\n      a_{32} & a_{34} \\\\\n      a_{42} & a_{44} \\\\\n    \\end{absmatrix}\n    -a_{31}\\begin{absmatrix}{ccc}\n      a_{22} & a_{24} \\\\\n      a_{42} & a_{44} \\\\\n    \\end{absmatrix}\n    +a_{41}\\begin{absmatrix}{ccc}\n      a_{22} & a_{24} \\\\\n      a_{32} & a_{34} \\\\\n    \\end{absmatrix}\n    }\n    \\\\\n    &&\n    - a_{14}\\paren{\n    a_{21}\\begin{absmatrix}{ccc}\n      a_{32} & a_{33} \\\\\n      a_{42} & a_{43} \\\\\n    \\end{absmatrix}\n    -a_{31}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} \\\\\n      a_{42} & a_{43} \\\\\n    \\end{absmatrix}\n    +a_{41}\\begin{absmatrix}{ccc}\n      a_{22} & a_{23} \\\\\n      a_{32} & a_{33} \\\\\n    \\end{absmatrix}\n    }.\n  \\end{eqnarray*}\n  The two expressions can be seen to be equal by comparing them term\n  by term.\n\\end{proof}\n\nTogether, Lemmas~\\ref{lem:well-defined-column-cofactor},\n{\\ref{lem:well-defined-row-cofactor}}, and\n{\\ref{lem:well-defined-column-row-cofactor}} imply\nTheorem~\\ref{thm:well-defined-determinant}.\n\n% ----------------------------------------------------------------------\n\\subsection{Proof of Theorem~\\ref{thm:determinant-row-operations}}\n\n\\begin{lemma}{}{L2}\n  Assume $A$, $B$ and $C$ are $n\\times n$-matrices and\n  $i\\in\\set{1,\\ldots,n}$ is an index such that the following holds.\n  \\begin{enumerate}\n  \\item The $k$th rows of all three matrices are identical, for $k\\neq i$.\n\n  \\item Each entry in the $i$th row of $A$ is the sum of the\n    corresponding entries in $i$th rows of $B$ and $C$, i.e.,\n    $a_{ij}=b_{ij}+c_{ij}$, for all $j=1,\\ldots,n$.\n  \\end{enumerate}\n  Then $\\det A=\\det B+\\det C$.\n\\end{lemma}\n\n\\begin{proof}\n  Notice that all three matrices have the same cofactors\n  $\\cofactor{A}{i1},\\ldots,\\cofactor{A}{in}$, since these cofactors\n  involve deleting the $i\\th$ row (and the matrices $A$, $B$, and $C$\n  only differ in the $i\\th$ row). Expanding all determinants along the\n  $i\\th$ row, we have\n  \\begin{eqnarray*}\n    \\det(A)\n    &=& a_{i1}\\cofactor{A}{i1} + \\ldots + a_{in}\\cofactor{A}{in} \\\\\n    &=& (b_{i1}+c_{i1})\\cofactor{A}{i1} + \\ldots + (b_{in}+c_{in})\\cofactor{A}{in} \\\\\n    &=& (b_{i1}\\cofactor{B}{i1} + \\ldots + b_{in}\\cofactor{B}{in})\n        + (c_{i1}\\cofactor{C}{i1} + \\ldots + c_{in}\\cofactor{C}{in}) \\\\\n    &=& \\det(B) + \\det(C).\n  \\end{eqnarray*}\n\\end{proof}\n\n% ======================================================================\n\\subsection{CONTINUE HERE...}\n\nFirst we recall the definition of a determinant. If $A=\\mat{a_{ij} }$\nis an $n\\times n$-matrix, then $\\det A$ is defined by computing the\nexpansion along the first row:\n\\begin{equation}\n  \\label{E1}\n  \\det A=\\sum_{i=1}^n a_{1,i} \\cofactor{A}{1,i}.\n\\end{equation}\nIf $n=1$ then $\\det A=a_{1,1}$.\n\nThe following example is straightforward and strongly recommended as a\nmeans for getting used to definitions.\n\n\\begin{example}{}{EX1}\n  (1) Let $E_{ij}$ be the elementary matrix obtained by interchanging\n  $i$th and $j$th rows of $I$.  Then $\\det E_{ij}=-1$.\n\n  (2) Let $E_{ik}$ be the elementary matrix obtained by multiplying\n  the $i$th row of $I$ by $k$.  Then $\\det E_{ik}=k$.\n\n  (3) Let $E_{ijk}$ be the elementary matrix obtained by multiplying\n  $i$th row of $I$ by $k$ and adding it to its $j$th row. Then\n  $\\det E_{ijk}=1$.\n\n  (4) If $C$ and $B$ are such that $CB$ is defined and the $i$th row\n  of $C$ consists of zeros, then the $i$th row of $CB$ consists of\n  zeros.\n\n  (5) If $E$ is an elementary matrix, then $\\det E=\\det E^T$.\n\\end{example}\n\nMany of the proofs in section use the Principle of Mathematical\nInduction. This concept is discussed in\nAppendix~\\ref{well-ordering-section} and is reviewed here for\nconvenience.  First we check that the assertion is true for $n=2$ (the\ncase $n=1$ is either completely trivial or meaningless).\n\nNext, we assume that the assertion is true for $n-1$ (where $n\\geq 3$)\nand prove it for $n$.  Once this is accomplished, by the Principle of\nMathematical Induction we can conclude that the statement is true for\nall $n\\times n$-matrices for every $n\\geq 2$.\n\nIf $A$ is an $n\\times n$-matrix and $1\\leq j \\leq n$, then the matrix\nobtained by removing $1$st column and $j$th row from $A$ is an\n$(n-1)\\times (n-1)$-matrix (we shall denote this matrix by $A(j)$\nbelow). Since these matrices are used in computation of cofactors\n$\\cofactor{A}{1,i}$, for $1\\leq i\\neq n$, the inductive assumption applies\nto these matrices.\n\nConsider the following lemma.\n\n\\begin{lemma}{}{L1}\n  If $A$ is an $n\\times n$-matrix such that one of its rows consists\n  of zeros, then $\\det A=0$.\n\\end{lemma}\n\n\\begin{proof}\n  We will prove this lemma using Mathematical Induction.\n\n  If $n=2$ this is easy (check!).\n\n  Let $n\\geq 3$ be such that every matrix of size $(n-1)\\times(n-1)$\n  with a row consisting of zeros has determinant equal to zero.  Let\n  $i$ be such that the $i$th row of $A$ consists of zeros.  Then we\n  have $a_{ij}=0$ for $1\\leq j\\leq n$.\n\n  Fix $j\\in \\set{1,2, \\dots ,n}$ such that $j\\neq i$. Then matrix\n  $A(j)$ used in computation of $\\cofactor{A}{1,j}$ has a row consisting of\n  zeros, and by our inductive assumption $\\cofactor{A}{1,j}=0$.\n\n  On the other hand, if $j=i$ then $a_{1,j}=0$.  Therefore\n  $a_{1,j}\\cofactor{A}{1,j}=0$ for all $j$ and by \\eqref{E1} we have\n  \\begin{equation*}\n    \\det A=\\sum_{j=1}^n a_{1,j} \\cofactor{A}{1,j}=0\n  \\end{equation*}\n  as each of the summands is equal to 0.\n\\end{proof}\n\n\\begin{theorem}{} {T1}\n  Let $A$ and $B$ be $n\\times n$-matrices.\n  \\begin{enumerate}\n  \\item If $A$ is obtained by interchanging $i$th and $j$th rows of\n    $B$ (with $i\\neq j$), then $\\det A=-\\det B$.\n  \\item If $A$ is obtained by multiplying $i$th row of $B$ by $k$ then\n    $\\det A=k\\det B$.\n  \\item If two rows of $A$ are identical then $\\det A=0$.\n  \\item If $A$ is obtained by multiplying $i$th row of $B$ by $k$ and\n    adding it to $j$th row of $B$ ($i\\neq j$) then $\\det A=\\det B$.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}\n  We prove all statements by induction. The case $n=2$ is easily\n  checked directly (and it is strongly suggested that you do check\n  it).\n\n  We assume $n\\geq 3$ and (1)--(4) are true for all matrices of size\n  $(n-1)\\times (n-1)$.\n\n  (1) We prove the case when $j=i+1$, i.e., we are interchanging two\n  consecutive rows.\n\n  Let $l\\in \\set{1, \\dots, n}\\setminus \\set{i,j}$.  Then $A(l)$ is\n  obtained from $B(l)$ by interchanging two of its rows (draw a\n  picture) and by our assumption\n  \\begin{equation}\n    \\label{E2}\n    \\cofactor{A}{1,l}=-\\cofactor{B}{1,l}.\n  \\end{equation}\n\n  Now consider $a_{1,i} \\cofactor{A}{1,l}$. We have that $a_{1,i}=b_{1,j}$\n  and also that $A(i)=B(j)$. Since $j=i+1$, we have\n  \\begin{equation*}\n    (-1)^{1+j}=(-1)^{1+i+1}=-(-1)^{1+i}\n  \\end{equation*}\n  and therefore $a_{1i}\\cofactor{A}{1i}=-b_{1j} \\cofactor{B}{1j}$ and\n  $a_{1j}\\cofactor{A}{1j}=-b_{1i} \\cofactor{B}{1i}$.  Putting this together with\n  \\eqref{E2} into \\eqref{E1} we see that if in the formula for\n  $\\det A$ we change the sign of each of the summands we obtain the\n  formula for $\\det B$.\n  \\begin{equation*}\n    \\det A=\\sum_{l=1}^n a_{1l}\\cofactor{A}{1l}\n    =-\\sum_{l=1}^n b_{1l} B_{1l}\n    =\\det B.\n  \\end{equation*}\n  We have therefore proved the case of (1) when $j=i+1$. In order to\n  prove the general case, one needs the following fact. If $i<j$, then\n  in order to interchange $i$th and $j$th row one can proceed by\n  interchanging two adjacent rows $2(j-i)+1$ times: First swap $i$th\n  and $i+1$st, then $i+1$st and $i+2$nd, and so on.  After one\n  interchanges $j-1$st and $j$th row, we have $i$th row in position of\n  $j$th and $l$th row in position of $l-1$st for $i+1\\leq l\\leq\n  j$. Then proceed backwards swapping adjacent rows until everything\n  is in place.\n\n  Since $2(j-i)+1$ is an odd number $(-1)^{2(j-i)+1}=-1$ and we have\n  that $\\det A=-\\det B$.\n\n  (2) This is like (1)\\dots{} but much easier.  Assume that (2) is\n  true for all $(n-1)\\times (n-1)$-matrices.  We have that\n  $a_{ji}=k b_{ji}$ for $1\\leq j\\leq n$.  In particular\n  $a_{1i}=kb_{1i}$, and for $l\\neq i$-matrix $A(l)$ is obtained from\n  $B(l)$ by multiplying one of its rows by $k$.  Therefore\n  $\\cofactor{A}{1l}=k\\cofactor{B}{1l}$ for $l\\neq i$, and for all $l$ we have\n  $a_{1l} \\cofactor{A}{1l}=k b_{1l}\\cofactor{B}{1l}$.  By \\eqref{E1}, we have\n  $\\det A=k\\det B$.\n\n  (3) This is a consequence of (1). If two rows of $A$ are identical,\n  then $A$ is equal to the matrix obtained by interchanging those two\n  rows and therefore by (1) $\\det A=-\\det A$. This implies $\\det A=0$.\n\n  (4) Assume (4) is true for all $(n-1)\\times (n-1)$-matrices and fix\n  $A$ and $B$ such that $A$ is obtained by multiplying $i$th row of\n  $B$ by $k$ and adding it to $j$th row of $B$ ($i\\neq j$) then\n  $\\det A=\\det B$.  If $k=0$ then $A=B$ and there is nothing to prove,\n  so we may assume $k\\neq 0$.\n\n  Let $C$ be the matrix obtained by replacing the $j$th row of $B$ by\n  the $i$th row of $B$ multiplied by $k$.  By Lemma~\\ref{lem:L2}, we\n  have that\n  \\begin{equation*}\n    \\det A=\\det B+\\det C\n  \\end{equation*}\n  and we `only' need to show that $\\det C=0$. But $i$th and $j$th rows\n  of $C$ are proportional. If $D$ is obtained by multiplying the $j$th\n  row of $C$ by $\\frac 1k$ then by (2) we have $\\det C=\\frac 1k\\det D$\n  (recall that $k\\neq 0$!).  But $i$th and $j$th rows of $D$ are\n  identical, hence by (3) we have $\\det D=0$ and therefore $\\det C=0$.\n\\end{proof}\n\n\\begin{theorem}{}{T2}\n  Let $A$ and $B$ be two $n\\times\n  n$-matrices. Then\\index{determinant!product}\n  \\begin{equation*}\n    \\det (AB) =\\det (A) \\det (B)\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  If $A$ is an elementary matrix of either type, then multiplying by\n  $A$ on the left has the same effect as performing the corresponding\n  elementary row operation. Therefore the equality\n  $\\det (AB) =\\det A\\det B$ in this case follows by\n  Example~\\ref{exa:EX1} and Theorem~\\ref{thm:T1}.\n\n  If $C$ is the {\\rref} of $A$ then we can write\n  $A=E_1\\cdot E_2\\cdot\\dots\\cdot E_m\\cdot C$ for some elementary\n  matrices $E_1,\\dots, E_m$.\n\n  Now we consider two cases.\n\n  Assume first that $C=I$. Then $A=E_1\\cdot E_2\\cdot \\dots\\cdot E_m$\n  and $AB= E_1\\cdot E_2\\cdot \\dots\\cdot E_m B$.  By applying the above\n  equality $m$ times, and then $m-1$ times, we have that\n  \\begin{align*}\n    \\det AB&=\\det E_1\\det E_2\\cdot \\det E_m\\cdot \\det B\\\\\n           &=\\det (E_1\\cdot E_2\\cdot\\dots\\cdot E_m) \\det B\\\\\n           &=\\det A\\det B.\n  \\end{align*}\n  Now assume $C\\neq I$. Since it is in {\\rref}, its last row consists\n  of zeros and by (4) of Example~\\ref{exa:EX1} the last row of $CB$\n  consists of zeros.  By Lemma~\\ref{lem:L1} we have\n  $\\det C=\\det (CB)=0$ and therefore\n  \\begin{equation*}\n    \\det A=\\det (E_1\\cdot E_2\\cdot  E_m)\\cdot  \\det (C)\n    =\n    \\det (E_1\\cdot E_2\\cdot  E_m)\\cdot 0=0\n  \\end{equation*}\n  and also\n  \\begin{equation*}\n    \\det AB=\\det (E_1\\cdot E_2\\cdot  E_m)\\cdot  \\det (C B)\n    =\\det (E_1\\cdot E_2\\cdot\\dots\\cdot E_m) 0\n    =0\n  \\end{equation*}\n  hence $\\det AB=0=\\det A \\det B$.\n\\end{proof}\n\nThe same `machine' used in the previous proof will be used again.\n\n\\begin{theorem}{}{T.T}\n  Let $A$ be a matrix where $A^T$ is the transpose of $A$. Then,\n  \\begin{equation*}\n    \\det(A^T) = \\det (A)\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{proof}\n  Note first that the conclusion is true if $A$ is elementary by (5)\n  of Example~\\ref{exa:EX1}.\n\n  Let $C$ be the {\\rref} of $A$. Then we can write\n  $A= E_1\\cdot E_2\\cdot \\dots\\cdot E_m C$.  Then\n  $A^T=C^T\\cdot E_m^T\\cdot \\dots \\cdot E_2^T\\cdot E_1$.  By\n  Theorem~\\ref{thm:T2} we have\n  \\begin{equation*}\n    \\det (A^T)=\\det (C^T)\\cdot \\det (E_m^T)\\cdot \\dots \\cdot \\det (E_2^T)\\cdot \\det(E_1).\n  \\end{equation*}\n  By (5) of Example~\\ref{exa:EX1} we have that $\\det E_j=\\det E_j^T$\n  for all $j$.  Also, $\\det C$ is either 0 or 1 (depending on whether\n  $C=I$ or not) and in either case $\\det C=\\det C^T$. Therefore\n  $\\det A=\\det A^T$.\n\\end{proof}\n\nThe above discussions allow us to now prove\nTheorem~\\ref{thm:well-defined-determinant}. It is restated below.\n\n\\begin{theorem}{}{}\n  Expanding an $n\\times n$-matrix along any row or column always gives\n  the same result, which is the determinant.\n\\end{theorem}\n\n\\begin{proof}\n  We first show that the determinant can be computed along any\n  row. The case $n=1$ does not apply and thus let $n \\geq 2$.\n\n  % Assume the theorem is true for all $(n-1)\\times (n-1)$-matrices.\n\n  Let $A$be an $n\\times n$-matrix and fix $j>1$. We need to prove that\n  \\begin{equation*}\n    \\det A=\\sum_{i=1}^n a_{j,i} \\cofactor{A}{j,i}.\n  \\end{equation*}\n  Let us prove the case when $j=2$.\n\n  Let $B$ be the matrix obtained from $A$ by interchanging its $1$st\n  and $2$nd rows.  Then by Theorem~\\ref{thm:T1} we have\n  \\begin{equation*}\n    \\det A=-\\det B.\n  \\end{equation*}\n  Now we have\n  \\begin{equation*}\n    \\det B=\\sum_{i=1}^n b_{1,i} \\cofactor{B}{1,i}.\n  \\end{equation*}\n  Since $B$ is obtained by interchanging the $1$st and $2$nd rows of\n  $A$ we have that $b_{1,i}=a_{2,i}$ for all $i$ and one can see that\n  $\\minor{B}{1,i}=\\minor{A}{2,i}$.\n\n  Further,\n  \\begin{equation*}\n    \\cofactor{B}{1,i}=(-1)^{1+i} minor B_{1,i}=- (-1)^{2+i} \\minor{A}{2,i} = - \\cofactor{A}{2,i}\n  \\end{equation*}\n  hence $\\det B=-\\sum_{i=1}^n a_{2,i} \\cofactor{A}{2,i}$, and therefore\n  $\\det A=-\\det B= \\sum_{i=1}^n a_{2,i} \\cofactor{A}{2,i}$ as desired.\n\n  The case when $j>2$ is very similar; we still have\n  $\\minor{B}{1,i}=\\minor{A}{j,i}$ but checking that\n  $\\det B=-\\sum_{i=1}^n a_{j,i} \\cofactor{A}{j,i}$ is slightly more\n  involved.\n\n  Now the cofactor expansion along column $j$ of $A$ is equal to the\n  cofactor expansion along row $j$ of $A^T$, which is by the above\n  result just proved equal to the cofactor expansion along row 1 of\n  $A^T$, which is equal to the cofactor expansion along column $1$ of\n  $A$. Thus the cofactor cofactor along any column yields the same\n  result.\n\n  Finally, since $\\det A=\\det A^T$ by Theorem~\\ref{thm:T.T}, we\n  conclude that the cofactor expansion along row $1$ of $A$ is equal\n  to the cofactor expansion along row $1$ of $A^T$, which is equal to\n  the cofactor expansion along column $1$ of $A$. Thus the proof is\n  complete.\n\\end{proof}\n", "meta": {"hexsha": "9f5833bde18e169ea884f5af157295bf28389426", "size": 24361, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/determinantsBasicTechniquesPropertiesPropertiesProofs.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/determinantsBasicTechniquesPropertiesPropertiesProofs.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/determinantsBasicTechniquesPropertiesPropertiesProofs.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.3712328767, "max_line_length": 96, "alphanum_fraction": 0.5839251262, "num_tokens": 9087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.7937484264516934}}
{"text": "\\section{Eigenvalues and Eigenvectors}\nIf $\\bfA$ is a square matrix, the \\emph{characteristic polynomial} of $\\bfA$ is defined by $p(\\lambda)=\\det(\\bfA-\\lambda I)$, the zeros of $p$ are \\emph{eigenvalues}, or characteristic values, of the matrix $\\bfA$.\n\n\\subsection{Spectral Radius}\n\\begin{defn}[Spectral Radius]\nThe \\emph{spectral radius} $\\rho(\\bfA)$ of a matrix $\\bfA$ is defined by\n\\[\n\\rho(\\bfA)=\\max\\abs{\\lambda},\\quad\\text{where $\\lambda$ is an eigen value of $\\bfA$.}\n\\]\n(For complex $\\lambda=\\alpha+\\beta i$, we define $\\abs{\\lambda}=(\\alpha^2+\\beta^2)^{1/2}.$)\n\\end{defn}\n\n\\begin{theo}\nIf $\\bfA$ is an $n\\times n$ matrix, then\n\\begin{enumerate}[(i)]\n    \\item $\\norms{\\bfA}_1=\\max_j\\sum_{i=1}^{n}\\abs{a_{ij}}$,(列和最大)\n    \\item $\\norms{\\bfA}_2=\\left[\\rho(A^tA)\\right]^{1/2}$,\n    \\item $\\norms{\\bfA}_\\infty=\\max_i\\sum_{j=1}^{n}\\abs{a_{ij}}$,(行和最大)\n    \\item $\\rho(\\bfA)\\leq\\norms{\\bfA}$, for any natural norm $\\norms{\\cdot}$.\n\\end{enumerate}\n\\end{theo}\n\n\\subsection{Convergent Matrices}\n\\begin{defn}[Convergent]\nWe call an $n\\times n$ matrix $\\bfA$  convergent if\n\\[\n\\lim_{k\\to\\infty}(\\bfA^k)_{ij}=0,\\quad\\text{for each $i=1,2,\\ldots,n$ and $j=1,2,\\ldots,n$.}\n\\]\n\\end{defn}\n\n\\begin{theo}\nThe following statements are equivalent\n\\begin{enumerate}[(i)]\n    \\item $\\bfA$ is a convergent matrix.\n    \\item $\\lim_{n\\to\\infty}\\norms{\\bfA^n}=0$, for some natural norm.\n    \\item $\\lim_{n\\to\\infty}\\norms{\\bfA^n}=0$, for all natural norms.\n    \\item $\\rho(\\bfA)<1$.\n    \\item $\\lim_{n\\to\\infty}\\bfA^n\\bfx=\\bf 0$, for every $\\bfx$.\n\\end{enumerate}\n\\end{theo}\n", "meta": {"hexsha": "f40ad228661264ac4f652dbc2ab7eaf9967d0190", "size": 1559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/7.2_Eigenvalues-and_eigenvectors.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/7.2_Eigenvalues-and_eigenvectors.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/7.2_Eigenvalues-and_eigenvectors.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": 38.0243902439, "max_line_length": 214, "alphanum_fraction": 0.6491340603, "num_tokens": 614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857204, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7936723552734292}}
{"text": "\\subsection{Fungi Interaction Model}\nThe \\textit{Logistic model}~\\cite{logisticmodel} can precisely analyze the growth phenomenon of animals, human and plants who naturally confront obstacles of survival attribute to the excess of the total population and the lack of food resources, so does microorganism, fungi. Therefore, it is suitable to use the \\textbf{Logistic model} to study the interactions of different kinds of fungi.\n\\par\nWhen a single fungal population lives, its number changes obey the \\textbf{Single-group Logistic model}.\n\\begin{equation}\n  \\label{12eq}\n  \\frac{1}{N(t)}\\frac{dN(t)}{dt} = r(1-\\frac{N(t)}{N_{max}})\n\\end{equation}\nwhere $N(t)$ represents current population size, and $r$ represents the growth rate of population.\nWhen considering two fungal populations living together, due to competition for habitat and food, the interaction between them would hinder each other's growth and reproduction. Therefore, we introduce the \\textbf{Relative Growth Blocking Index} (RGB) on the basis of Single-group Logistic model, and establish \\textbf{Multi-groups Logistic Model}~\\cite{multigroups} as follows.\n\\begin{equation}\n  \\begin{cases}\n    \\frac{1}{N_x(t)}\\frac{dN_x(t)}{dt} = r_x(1-\\frac{N_x(t)}{{N_x}_{max}} - RGB_x\\frac{N_y(t)}{{N_y}_{max}}) \\\\ \\\\\n    \\frac{1}{N_y(t)}\\frac{dN_y(t)}{dt} = r_y(1-\\frac{N_y(t)}{{N_y}_{max}} - RGB_y\\frac{N_x(t)}{{N_x}_{max}})\n  \\end{cases}\n\\end{equation}\nwhere $N_x(t)$ and $N_y(t)$ represents the numbers of the two populations $x$ and $y$, $r_x$ and $r_y$ represents the inherent growth rate of populations, ${N_x}_{max}$ and ${N_y}_{max}$ are maximum capacities of populations, $RGB_x$ means for resources that support $x$, the consumption of $y$ is $RGB_x$ times the consumption of $x$ per unit quantity, and $RGB_y$ has the similar definition to $RGB_x$.\n\\par\nTaking fungal species $F_A$ and $F_B$ proposed in the previous article as examples, analyze and predict the interaction between them. Calculate the values of parameters and list them as follows.\n\\begin{table}[H]\n  \\centering\n  \\caption{Values of parameters.}\n  \\label{valueofparameters}\n  \\begin{tabular*}{\\hsize}{@{\\extracolsep{\\fill}}ccccc}\n    \\toprule\n    \\textbf{Parameter} & $RGB_A$ & $RGB_B$ & $r_A$ & $r_B$ \\\\\n    \\midrule\n    \\textbf{Value} & $0.39$ & $0.60$ & $1$ & $1$ \\\\\n    \\bottomrule\n  \\end{tabular*}\n\\end{table}\nDraw the change curves of $N_A(t)$ and $N_B(t)$ as well as the phase trajectory of these two function variables as follows.\n\\par\n\\begin{figure}[H]\n  \\centering\n  \\subfigure[Curves of $N_A(t)$ and $N_B(t)$.]{\n    \\includegraphics[width=0.48\\textwidth]{figures/FA&FBN(t).png}\n  }\n  \\subfigure[Phase trajectory of $N_A(t)$ and $N_B(t)$.]{\n    \\includegraphics[width=0.48\\textwidth]{figures/FA&FBline.png}\n  }\n  \\caption{The interaction of $F_A\\ \\&\\ F_B$.}\n\\end{figure}\n\\par\nThe dynamics of the interaction between Fungi A and Fungi B are characterized and described in the above figures. \\textbf{In the short-term period} (about $1\\sim 7$ days), $F_A$ and $F_B$ are in a period of rapid growth and reproduction, the curves of which maintain exponential growth. \\textbf{In the long term} (after $8$ days), the growths of $F_A$ and $F_B$ would be both restricted by environmental resources. Meanwhile, because $F_A$ has a stronger ability to decompose, it has a stronger blocking effect on $F_B$. The final relative population numbers tend to $796$ and $522$ respectively and remain stable.\n\\par\nIn the same way, we calculate and analyze the interaction of Fungi C and Fungi E, and obtain the $N_C(t)$ and $N_E(t)$ function curves as well as the phase trajectory of the two function variables as follows.\n\\par\n\\begin{figure}[H]\n  \\centering\n  \\subfigure[Curves of $N_C(t)$ and $N_E(t)$.]{\n    \\includegraphics[width=0.48\\textwidth]{figures/FC&FEN(t).png}\n  }\n  \\subfigure[Phase trajectory of $N_C(t)$ and $N_E(t)$.]{\n    \\includegraphics[width=0.48\\textwidth]{figures/FC&FEline.png}\n  }\n  \\caption{The interaction between $F_C\\ \\&\\ F_E$.}\n\\end{figure}\n\\par\n\\textbf{In a short period of time} (about $1\\sim 5$ days), the numbers of $F_C$ and $F_E$ grow exponentially. \\textbf{From a long-term perspective} (after $6$ days), since the discrepancy of decomposition ability between $F_E$ and $F_C$ is greater than that between $F_A$ and $F_B$, the blocking effect of $F_E$ on $F_C$ is extremely obvious. The final relative populations numbers of $F_C$ and $F_E$ tend to $365$ and $894$ respectively and remain stable.", "meta": {"hexsha": "5adc9592bd65b56efa57ae686b7a78c58be1c75c", "size": 4458, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4/4.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/4.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/4.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": 74.3, "max_line_length": 614, "alphanum_fraction": 0.7261103634, "num_tokens": 1329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7936610070722208}}
{"text": "\\textbf{Modify the code diffusion} \\verb+eq1_Neumann.m+ \\textbf{to solve the diffusion equation with Neumann boundary conditions using finite differences.}\n\nIn this problem we use second order centered finite differences to calculate the second derivative in the interior\n\\begin{align*}\nu''_j=\\frac{u_{j-1}-2u_{j}+u_{j+1}}{h^2}.\n\\end{align*}\nThis discretization, if expressed in matrix form, gives us a tridiagonal matrix with $1,-2,1$ as lower diagonal, diagonal and upper diagonal, respectively. We only need to solve the following matrix equation\n\\begin{align*}\n\\frac{d}{dt}\\textbf{u}=D_2\\textbf{u},\n\\end{align*}\nfor the interior since we have the boundary conditions. They have been taking into account using a first order sided finite differences\n\\begin{align*}\nu'_1=\\frac{u_2-u_1}{h}=g_1(t)~\\Rightarrow~u_1=u_2-hg_1(t),\n\\end{align*}\n\\begin{align*}\nu'_{N+1}=\\frac{u_{N+1}-u_N}{h}=g_2(t)~\\Rightarrow~u_{N+1}=hg_2(t)+u_N,\n\\end{align*}\nWe will get rid of the first and last row and column the matrix $D_2$, obtaining $\\tilde{D}_2$ and add another term to account for the boundary conditions of the Neumann kind in this case. The system obtained is the following\n\\begin{align*}\n\\frac{d}{dt}\\tilde{\\textbf{u}}=\\tilde{D}_2\\tilde{\\textbf{u}}+\\frac{1}{h}\\begin{pmatrix} -1 & 1 \\end{pmatrix}\\begin{pmatrix} g_1(t) \\\\ g_2(t) \\end{pmatrix},\n\\end{align*}\nwhere $g_1(t)$ and $g_2(t)$ are the Neumann boundary condition functions at $x=-1$ and $x=1$, respectively. We defined them generally althought in this problem $g_1(t)=g_2(t)=1$. When solving for the interior, we will need the values at the boundaries that will be substituted by the two equations above. As a result, including the boundary conditions hasn't just altered the system adding that extra term, but it also changes the first and last entries of the matrix $\\tilde{D}_2$. Computing the first and last nodes of the interior, and including the boundary conditions, we have\n\\begin{align*}\nu''_2=\\frac{u_1-2u_2+u_3}{h^2}&=\\frac{u_2-hg_1(t)-2u_2+u_3}{h^2}\\\\\n&=\\frac{-u_2+u_3}{h^2}-\\frac{1}{h} g_1(t),\n\\end{align*}\nand\n\\begin{align*}\nu''_N=\\frac{u_{N-1}-2u_N+u_{N+1}}{h^2}&=\\frac{u_{N-1}-2u_N+hg_2(t)+u_N}{h^2}\\\\\n&=\\frac{u_{N-1}-u_N}{h^2}+\\frac{1}{h} g_2(t).\n\\end{align*}\nThis implies that the system is modified as showed above and the first and second entries of the matrix $\\tilde{D}_2$ are\n\\begin{align*}\n\\tilde{D}_2(1,1)=\\tilde{D}_2(N-1,N-1)=-\\frac{1}{h^2}.\n\\end{align*}\nNote that the $1/h^2$ factor is already included in $\\tilde{D}_2$. The solution for the PDE is shown in the next figure.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P3_surf.eps}}\n\\caption{Solution of the diffusion equation, $N=50$.}\n\\end{figure}\nWe can see how at time zero we have the initial condition and in two seconds we reach the steady state where the whole domain has a slope 1, as imposed by the boundary conditions in the first and last nodes.\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 3\n% Simple code to solve the diffusion equation\n% u_t = u_xx -1<x<1, with Neumann boundary conditions\nclear all; close all; clc\nlegendfontsize=14;\naxisfontsize=14;\nlabelfontsize=16;\nN = 50;\nL=2;\nh=L/N;\nx=-1:h:1;\nD2 = gallery('tridiag',N+1,1,-2,1); % In sparse form.\n%%\n\n% initial condition\nu0 = cos(pi*x)+0.2*cos(5*pi*x)+1;\n% boundary conditions\ng1 = @(t) 0*t+1;\ng2 = @(t) 0*t+1;\n\nA = D2(2:N,2:N)/h^2;\nA(1,1)=-1/h^2;\nA(end,end)=-1/h^2;\nB = zeros(N-1,2);\nB(1,1) = -1/h;\nB(end,end) = 1/h;\n\nt = 0:0.001:2;\n%%\n[T,U] = ode45(@(t,u) A*u+B*[g1(t);g2(t)], t, u0(2:end-1));\nfor k = 2:length(t)\n    plot(x(2:end-1),U(k,:)','*-')\n    ylim([-1 2])\n    shg\n    drawnow\nend\n[T,X]= meshgrid(t,x(2:end-1));\nsurf(T,X,U','edgecolor','none')\nxlabel('$t$','fontsize',labelfontsize,...\n            'interpreter','latex')\nylabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nzlabel('$u(x,t)$','fontsize',labelfontsize,...\n            'interpreter','latex')\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P3_surf';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}", "meta": {"hexsha": "a3626514f21a9f70c17fcb3c7ccdfbd41b8d8e99", "size": 4048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem3.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 3/Latex/problem3.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 3/Latex/problem3.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": 43.5268817204, "max_line_length": 581, "alphanum_fraction": 0.6914525692, "num_tokens": 1415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299591537478, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7936327537895055}}
{"text": "\n\\subsection{Ridge regression}\n\nRegularisation of LLS. The cost function now includes a norm on \\(M\\theta \\).\n\n\\(L_2\\) regularisation\n\nThis allows us to solve problems where there are too many features. \\(L_1\\) also allows us to to do this.\n\n\\subsubsection{Overspecified}\n\nIf \\(n>d\\) we can minimise weights subject to Xw=y. This is the same as the least norm.\n\n\\subsubsection{Maximum A-Priori (MAP) estimator for linear regression}\n\nMaximum a priori estimation. equiv to ridge regression with a priori estimate of \\(0\\)\n\n\\(W_{RR}=(\\lambda I+X^TX)^{-1}X^Ty\\)\n\n\\(E_[w{RR}]=(\\lambda I+X^TX)^{-1}X^TXw\\)\n\n\\(Var[W_{RR}]=a\\)\n\n\n", "meta": {"hexsha": "34c509ea8048510a60e87d9ebe040c8f87bab85f", "size": 622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/03-01-ridge.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/03-01-ridge.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/03-01-ridge.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.88, "max_line_length": 105, "alphanum_fraction": 0.7090032154, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.931462503162843, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7935620824953697}}
{"text": "\\paragraph{Mobius inversion formula}\n\n$$[x = 1] = \\sum_{d|x}\\mu(d)$$\n\n\\paragraph{Gcd inversion}\n\\begin{align*}\n\\sum_{a=1}^n\\sum_{b=1}^ngcd^2(a,b)&=\\sum_{d=1}^nd^2\\sum_{i=1}^{\\floor{\\frac{n}{d}}}\\sum_{j=1}^{\\floor{\\frac{n}{d}}}[gcd(i,j)=1]\\\\\n&=\\sum_{d=1}^nd^2\\sum_{i=1}^{\\floor{\\frac{n}{d}}}\\sum_{j=1}^{\\floor{\\frac{n}{d}}}\\sum_{t|gcd(i,j)}\\mu(t)\\\\\n&=\\sum_{d=1}^nd^2\\sum_{t=1}^{\\floor{\\frac{n}{d}}}\\mu(t)\\sum_{i=1}^{\\floor{\\frac{n}{d}}}[t|i]\\sum_{j=1}^{\\floor{\\frac{n}{d}}}[t|j]\\\\\n&=\\sum_{d=1}^nd^2\\sum_{t=1}^{\\floor{\\frac{n}{d}}}\\mu(t){\\floor{\\frac{n}{dt}}}^2\n\\end{align*}\n\nThe formula can be computed in $O(nlogn)$ complexity.\n\nMoreover, let $l=dt$, then\n\n\\begin{align*}\n\\sum_{d=1}^nd^2\\sum_{t=1}^{\\floor{\\frac{n}{d}}}\\mu(t){\\floor{\\frac{n}{dt}}}^2&=\\sum_{l=1}^n{\\floor{\\frac{n}{l}}}^2\\sum_{d|l}d^2\\mu(\\frac{l}{d})\n\\end{align*}\n\nLet $f(l)=\\sum_{d|l}d^2\\mu(\\frac{l}{d})$. It can be proven that $f(l)$ is multiplicative. Besides, $f(p^k)=p^{2k}-p^{2k-2}$.\n\nTherefore, with linear sieve the formula can be computed in $O(n)$ complexity.\n\n", "meta": {"hexsha": "cbf438b5bf76895ea81aac4a99f174c69f4840a8", "size": 1036, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/mathematics/computation/mobius-inversion.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/mobius-inversion.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/mobius-inversion.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": 41.44, "max_line_length": 143, "alphanum_fraction": 0.582046332, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.793545280831026}}
{"text": "\\section{Types of Matrices, Matrix Properties}\n\n\\subsection{$\\mathrm{sgn}\\left(\\mathbf{x}^{\\dagger}\\mathbf{H}\\mathbf{x}\\right)$ Definite}\n\\label{sec:definite}\n\nA hermitian matrix $\\mathbf{H}\\in\\mathbb{C}^n$ is positive definite, if for any non-zero column vector $\\mathbf{x}\\in\\mathbb{C}^n$, the quadratic form $\\mathbf{x}^{\\dagger}\\mathbf{H}\\mathbf{x} > 0$, and negative definite if $\\mathbf{x}^{\\dagger}\\mathbf{H}\\mathbf{x} < 0$. The matrix is positive or negative \\textit{semidefinite} if  $\\mathbf{x}^{\\dagger}\\mathbf{H}\\mathbf{x} \\geq 0$ or $\\mathbf{x}^{\\dagger}\\mathbf{H}\\mathbf{x} \\leq 0$, respectively. Definiteness plays a role in investigating the convexity of a function by looking at the Hessian (section \\ref{sec:hessian}). Sometimes notation with curly comparison symbols are used. The relationship between definiteness and eigenvalues is intuitive:\n\n\\begin{tabular}{lll}\n$\\mathbf{H} \\succ 0$ & positive definite & all eigenvalues are positive\\\\\n$\\mathbf{H} \\prec 0$ & negative definite & all eigenvalues are negative\\\\\n$\\mathbf{H} \\succeq 0$ & positive semidefinite & all eigenvalues are positive or 0\\\\\n$\\mathbf{H} \\preceq 0$ & negative semidefinite & all eigenvalues are negative or 0\n\\centering\n\\end{tabular}\n\nThe curly comparison symbols can mean other stuff though, for example in the context of partially ordered sets (order theory) or comparisons between multidimensional arrays.\n\n\n\n\n\n% unitary\n\\subsection{Triangular}\n\\label{sec:triangular}\nA lower triangular matrix is a matrix that has all-zero entries above the diagonal.\n\n\n\\begin{equation}\n\\mathbf{L} = \\left[\\begin{array}{cccccc} l_{1,1}&&&&&0\\\\l_{2,1}&l_{2,2}&&&&\\\\l_{3,1}&l_{3,2}&\\ddots&&&\\\\  \\vdots&\\vdots&\\ddots&\\ddots&&\\\\ \\vdots&\\vdots&&\\ddots&\\ddots&\\\\  l_{n,1}&l_{n,2}&\\hdots&\\hdots&l_{n,n-1}&l_{n,n}\\end{array}\\right]\n\\end{equation}\n\nUpper triangular matrices are matrices that have all-zero entries below the diagonal.\n\n\n\n% commuting \n\\subsection{$\\mathbf{AB}-\\mathbf{BA}=0$ Commuting}\nTwo matrices commute if $\\mathbf{AB}=\\mathbf{BA}$, or, equivalently, their \\textit{commutator} $[\\mathbf{A,B}] = \\mathbf{AB}-\\mathbf{BA}$ is zero. This means that $\\mathbf{A}$ and $\\mathbf{B}$ both have to be square. Matrices commute when they have the same eigenspace, i.e. they have the same eigenvectors. This can be seen by considering the diagonal representations of $\\mathbf{A}$ and $\\mathbf{B}$.\n\nLet $\\mathbf{A}$ and $\\mathbf{B}$ be two square matrices with the same eigenvectors $\\mathbf{V}$, then they can be diagonalized as:\n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{V\\Lambda_A V^{-1}}\\\\\n\\mathbf{B} = \\mathbf{V\\Lambda_B V^{-1}}\n\\end{equation}\n\nThey commute, because:\n\n\\begin{equation}\n\\mathbf{AB} = \\mathbf{V\\Lambda_A V^{-1}V\\Lambda_B V^{-1}} = \\mathbf{V\\Lambda_B \\Lambda_A V^{-1}} = \\mathbf{V\\Lambda_B V^{-1}V\\Lambda_A V^{-1}} = \\mathbf{BA} \n\\end{equation}\n\n\n\n% anticommuting\n\\subsection{$\\mathbf{AB}+\\mathbf{BA}=0$ Anticommuting}\nTwo matrices anticommute if $\\mathbf{AB}=-\\mathbf{BA}$, or, equivalently, their \\textit{anticommutator} $\\{\\mathbf{A,B}\\} = \\mathbf{AB}+\\mathbf{BA}$ is zero.\n\n\n% Hermitian / Symmetric\n\\subsection{$\\mathbf{A}^{\\dagger} = \\mathbf{A}$ Hermitian, Symmetric}\n\\label{sec:hermitian}\nHermitian matrices are matrices that are equal to their complex transpose. That is:\n\n\\begin{equation}\n{\\mathbf{A}^{*}}^T = \\mathbf{A}^\\dagger = \\mathbf{A} \n\\end{equation}\n\n\\subsubsection{Properties}\n(There are more)\n\\begin{itemize}\n\\item By definition: $\\mathbf{A} = \\mathbf{A}^\\dagger$\n\\item Diagonal Entries are all real, since $a_{i,i} = a_{i,i}^*$, but not necessarily positive (physics will mislead you there...)\n\\item Inverse is also hermitian:  $\\mathbf{A}^{-1} ={ \\mathbf{A}^{-1}}^\\dagger$\n\\item Diagonalizable with real eigenvalues and orthogonal eigenvectors $\\in \\mathbb{C}^n$.\n\\end{itemize}\n\n\nHermitian matrices with only real entries are called symmetric matrices. In that case $\\mathbf{A}^T = \\mathbf{A}$.\n\nHermitian matrices can only have real elements along their diagonal. \n\n\n\n% Skew Hermitian / Skew Symmetric\n\\subsection{$\\mathbf{A}^{\\dagger} = -\\mathbf{A}$ Skew Hermitian, Skew Symmetric}\nSkew Hermitian matrices that are equal to the negative of their complex transpose. That is:\n\n\\begin{equation}\n{\\mathbf{A}^{*}}^T = \\mathbf{A}^\\dagger = -\\mathbf{A} \n\\end{equation}\n\nReal matrices that are skew Hermitian are called skew symmetric. In that case:\n\n\\begin{equation}\n\\mathbf{A}^T = -\\mathbf{A} \n\\end{equation}\n\n\nSkew Hermitian matrices can only have complex values on their diagonal, and skew symmetric matrices can only have zeros as diagonal elements.\n\n\n\n\n% Involutory\n\\subsection{$\\mathbf{A}\\mathbf{A}=\\mathbf{I}$ Involutory}\nInvolutory matrixes are matrices that are their own inverse, so that:\n\n\\begin{equation}\n\\mathbf{A}\\mathbf{A}=\\mathbf{I}\n\\end{equation}\n\nInvolutory matrices are all square roots of the identity matrix. A famous example are the $2\\times 2$ Pauli matrices. \n\n\n\n\n% Isometric\n\\subsection{$||\\mathbf{A}\\mathbf{x}||_{\\alpha} = ||\\mathbf{x}||_{\\alpha}$ Isometric}\n\\label{sec:isometric}\nAn isometric transformation with respect to some norm $||\\cdot||_{\\alpha}$ preserves that norm (it's in the name: iso-metric). The linear case is represented by isometric matrices, which satisfy:\n\n\\begin{equation}\n||\\mathbf{A}\\mathbf{x}||_{\\alpha} = ||\\mathbf{x}||_{\\alpha} \n\\end{equation}\n\nFor some vector $\\mathbf{x}$. Isometries are also known as distance-preserving maps. To see this, define the distance between two points $\\mathbf{a}$ and $\\mathbf{b}$ as $||\\mathbf{a} - \\mathbf{b}||_{\\alpha} = ||\\mathbf{x}||_{\\alpha}$. Isometries are usually understood be bijective. \n\nIn terms of operator norms, isometries must satisfy $||\\mathbf{A}||_{(\\alpha)} = 1$ where $||\\cdot||_{(\\alpha)}$ denotes the operator norm (cf. section \\ref{sec:operatornorm}). However, operator norms give the upper bound on the distortion of the input, so a unit operator norm is necessary but not sufficient. \n\n\n\\subsubsection{Isometries with Respect to $L^2$}\nThe $L^2$ norm is unique in that the points $\\{\\mathbf{x}: ||\\mathbf{x}||_{2} = 1\\}$ lie on a perfect circle, which remains a circle regardless of the orientation of the underlying coordinate system. (A sphere looks the same regardless of angle.) This symmetry is broken for all other norms. Unitary matrices are isometries with respect to $L^2$, though unitarity is not a necessary condition for an isometry.\n\n\\subsubsection{Isometries with Respect to $L^1$ and general $L^q\\neq L^2$}\nIsometries with respect to $L^1$ are relevant because they are permissible transformations of (classical) probability distributions. For example, the transition matrix that describes the flow of probability between the time steps of a Markov Chain has to ensure that the entries of the state space probability still sum to $1$. \n\nFor norms $L^q$ with $q\\neq2$, the unit \"circle\" $\\{\\mathbf{x}: ||\\mathbf{x}||_{q\\neq2} = 1\\}$ is not perfectly round. Instead the symmetry is broken along the coordinate axes. That means that a rotation of the coordinate axes gives a different unit distance, and so two points $\\mathbf{a}$ and $\\mathbf{b}$ that are $||\\mathbf{a}-\\mathbf{b}||_{q\\neq2} = 1$ apart in one coordinate system may have a different separation in some other coordinate system. \n\nIn particular, for the $L^1$, or \\textit{Manhattan} norm (cf. section \\ref{sec:l1norm}), the points $\\{\\mathbf{x}: ||\\mathbf{x}||_{1} = 1\\}$ lie on a diamond with axes aligned to the axes of the coordinate system. In Manhattan, reaching a point that is $1$ mile away \"as the crow flies\", depends on the position of that point with respect to the grid of streets and avenues. When that grid is rotated, the point may be quicker or take longer to reach. \n\nSince this rules out rotations, the internet tells me that the only linear maps that are isometries for $L^q$ with $q\\neq 2$ are signed permutation matrices. That is, matrices that assign $\\hat{x}\\rightarrow \\hat{y}$ or $\\hat{z} \\rightarrow -\\hat{x}$ and so on. \n\nHowever, in general, any transformation that maps a point on the $L^q$ unit circle to another point on the $L^q$ unit circle is an isometry with respect to $L^q$, and this class of transformation is more general than signed permutations. The stochastic matrices are an example with respect to $L^1$.\n\n\\subsection{Stochastic}\n\nStochastic matrices are used to describe transitions between states of a Markov chain. The matrices are square and each entry is non-negative and represents a conditional probability of moving from one state to another. The entries along either the row or the column, or both, must sum to 1 according to the requirement of marginalization.\n\n\\begin{itemize}\n\\item Right stochastic has rows that sum to 1, so that $\\mathbf{P}\\mathbf{1}=\\mathbf{1}$. It is applied $\\mathbf{\\pi}\\mathbf{P}$. Column index gives \"from\", row index gives \"to\". \n\\item Left stochastic has columns that sum to 1, so that $\\mathbf{1}\\mathbf{P}=\\mathbf{1}$. It is applied $\\mathbf{P}\\mathbf{\\pi}$. Row index gives \"from\", column index gives \"to\".\n\\item doubly stochastic has rows and columns that sum to 1. \n\\end{itemize}\n\nProducts of stochastic matrices are also stochastic matrices. The spectral radius (largest eigenvalue) of a stochastic matrix is always $1$. Since $\\mathbf{1}$ is an eigenvector and the left and right eigenvalues of a square matrix are the same, there is at least one stationary state $\\mathbf{\\pi}\\mathbf{P}=\\mathbf{\\pi}$ (that is, in this case of a right stochastic matrix, a left eigenvector) with eigenvalue $1$. \n\n\n\n% Unitary / Orthogonal\n\\subsection{$\\mathbf{U}^{\\dagger} = \\mathbf{U}^{-1}$ Unitary, Orthogonal}\n\\label{sec:unitary}\nUnitary matrices satisfy $\\mathbf{U}^{\\dagger}\\mathbf{U} = \\mathbf{UU}^{\\dagger}=\\mathbf{I}$, and they have $det(\\mathbf{U}) = 1$. They are diagonalizable and can be expressed as $e^{i\\mathbf{H}}$ where $\\mathbf{H}$ is a Hermitian matrix.\n\nUnitary matrices that are real are called orthogonal.  Orthogonal matrices satisfy $\\mathbf{A}^{-1} = \\mathbf{A}^T$. The rows (and columns) of $\\mathbf{A}$ are an orthonormal basis in $\\mathrm{R}^n$.\n\nUnitary matrices are necessarily invertible, and have determinant $|U|=1$ or $|U|=-1$. They represent \\textit{unitary transformations}, which means that they preserve the inner product between two vectors.\n\nThe set of $n \\times n$ orthogonal matrices is known as the orthogonal group $O(n)$ and the subgroup of orthogonal matrices with determinant $1$ is known as the special orthogonal group $SO(n)$. The elements of $SO(n)$ are rotations, and the elements of $O(n)$ represent translations, reflections or rotations. Similarly, the group of $n \\times n$ unitary matrices is the unitary group $U(n)$ and the subgroup of $U(n)$ that has determinant $1$ is the special unitary group $SU(n)$.\n\nUnitary transformations preserve the $L^2$ norm of vectors.\n\n\n% Similarity\n\\subsection{$\\mathbf{A} = \\mathbf{TBT^{-1}}$ Similarity}\n\\label{sec:similiarity}\nTwo matrices are said to be similar if they can be related through a similarity transformation  $\\mathbf{A} = \\mathbf{TBT^{-1}}$ where $\\mathbf{T}$ is some nonsingular matrix (cf. section \\ref{sec:similaritytrans}). An important example is that square matrices are similar to diagonal matrices, see section \\ref{sec:diagonalization}. \n   \n\n", "meta": {"hexsha": "5f8005ab84d096808a7b2098475ddebfd0f8ee40", "size": 11232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_matrixtypes.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/linalg_matrixtypes.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/linalg_matrixtypes.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": 62.4, "max_line_length": 703, "alphanum_fraction": 0.7321937322, "num_tokens": 3338, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984213, "lm_q2_score": 0.8757869932689566, "lm_q1q2_score": 0.7934541073949966}}
{"text": "\\subsubsection{Review of matrix norms}\n%\n\\label{sec:matrix_norms}\n%\nGiven a matrix $A \\in \\R^{N \\times M}$, we define its {\\em operator\n  norm}\n\\begin{equation}\n  \\label{eq:defn_matrix_norm}\n  \\| A \\| := \\sup_{\\substack{h \\in \\R^N \\\\ |h| = 1}} |A h| = \\sup_{h\n    \\in \\R^N \\setminus \\{0\\}} \\frac{|Ah|}{|h|}.\n\\end{equation}\n\n\\begin{proposition}\n  \\label{th:matrix_norm}\n  (a) $\\|\\cdot\\|$ is a norm on $\\R^{N \\times M}$:\n  \\begin{enumerate}\\ilist\n  \\item $\\| A \\| \\geq 0$\n  \\item $\\| A \\| = 0$ if and only if $A = 0$\n  \\item $\\| A + \\lambda B \\| \\leq \\| A \\| + |\\lambda| \\| B \\|$ \\\\\n\n  (b) $\\|\\cdot\\|$ is an operator norm:\n\\item $| A h | \\leq \\| A \\| |h| \\qquad \\forall A \\in \\R^{N \\times M}, h\n  \\in \\R^M, \\quad \\text{and}$\n\\item $\\| A B \\| \\leq \\| A \\| \\, \\| B \\| \\qquad \\forall A \\in \\R^{N\n    \\times M}, B \\in \\R^{M \\times P}.$\n  \\end{enumerate}\n\\end{proposition}\n\\begin{exercise}\n  Prove Proposition \\ref{th:matrix_norm}.\n\\end{exercise}\n\n\nIn addition to the canonical operator norm $\\|\\cdot\\|$ we also define\nthe Frobenius norm\n\\begin{displaymath}\n  \\| A \\|_F := \\bg(\\sum_{i = 1}^N \\sum_{j = 1}^M |A_{ij}|^2 \\bg)^{1/2}\n  \\qquad \\text{ for } A \\in \\R^{N \\times M}.\n\\end{displaymath}\nThen we have the following relationship between $\\|\\cdot\\|$ and\n$\\|\\cdot\\|_F$. It is clear from its definition that $\\|\\cdot\\|_F$ is a\nnorm on $\\R^{N \\times M}$. In addition it is also an operator norm:\n\n\\begin{lemma}\n  \\label{th:opnrm_vs_frobnrm}\n  The Frobenius norm satisfies the following properties:\n  \\begin{enumerate} \\ilist\n  \\item  $|A h | \\leq \\|A\\|_F |h|$ for all $h \\in \\R^N$.\n\n  \\item $\\| A B \\|_F \\leq \\|A \\|_F \\| B \\|_F$ for all $A \\in \\R^{N\n      \\times M}, B \\in \\R^{M \\times P}$.\n\n  \\item $\\|A\\| \\leq \\|A\\|_F$ for all $A \\in \\R^{M \\times N}$.\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{exercise}\n  Prove Lemma \\ref{th:opnrm_vs_frobnrm}.\\footnote{HINT: Show (i),\n    using the Cauchy--Schwarz inequality on $\\R^N$. (ii), (iii) are\n    corollaries of (i).}\n\\end{exercise}\n\n\\begin{exercise}\n  (i) Show that $\\| A \\|_F = \\sqrt{{\\rm trace}(A^T A)}$.\n\n  (ii) Show that $(A, B) \\mapsto {\\rm trace}(A^T B)$ is an\n  inner product on $\\R^{M \\times N}$ (in fact, it is the standard\n  Euclidean inner product).\n\\end{exercise}\n\n% If $A \\in \\R^{M \\times N}$ is a matrix, then we define its operator norm\n% $\\|A\\|$ and its Frobenius norm, respectively, as\n% \\begin{align*}\n%   \\| A \\| &:= \\sup_{h \\in \\R^N \\setminus \\{h\\}} \\frac{|A h|}{|h|},\n%   \\qquad \\text{and} \\\\\n%   \\| A\\|_F &:= \\bigg( \\sum_{i=1}^M \\sum_{j=1}^N |A_{ij}|^2\n%   \\bigg)^{1/2}.\n% \\end{align*}\n\n\\subsubsection{Spectral decomposition}\n%\nLet $A \\in \\R^{N \\times N}$ be symmetric, then there exists an\northonormal basis (ONB) $\\{v_1, \\dots, v_N\\}$ of $\\R^N$ and\n$\\lambda_i \\in \\R, i = 1, \\dots, N$\n\\begin{displaymath}\n  A v_i = \\lambda_i v_i.\n\\end{displaymath}\nThe $\\lambda_i$ are called the eigenvalues of $A$ and $v_i$ the\nassociated eigenvectors.\n\n\\begin{remark}\n  In general, a matrix $A \\in \\mathbb{C}^{N \\times N}$ is unitarily\n  diagonalisable if and only if it is {\\em normal}: $A^* A = A A^*$,\n  where $A^* = (\\bar{A})^T$.\n\\end{remark}\n\n\\begin{exercise}\n  (i) Prove the spectral decomposition theorem for symmetric matrices.\n\n  (ii**) Prove the spectral decoposition theorem for normal matrices.\n\\end{exercise}\n\n\nWe call a matrix $A \\in \\R^{N \\times N}$ diagonalisable if there\nexists a basis $\\{v_1, \\dots, v_N\\}$ of $\\mathbb{C}^N$ (not\nnecessarily ONB) and eigenvalues $\\lambda_i \\in \\C$ such that $A v_i =\n\\lambda_i v_i$.\n\nWe call a matrix $A \\in \\R^{N \\times N}$ positive definite if $x^T A x\n> 0$ for all $x \\in \\R^N \\setminus \\{0\\}$. A symmetric and positive\nmatrix is simply called spd.\n\nNot all matrices are diagonalisable, but all matrices have a {\\em\n  Jordan normal form}. That is, there exists a basis $\\{v_1, \\dots,\nv_N\\}$ of $\\mathbb{C}^N$ such that, writing $V = (v_1, \\dots, v_N)$ we\nhave\n\\begin{displaymath}\n  V A V^{-1} = \\left( \\begin{matrix}\n      J_1 & 0 & \\cdots & \\\\\n      0 & J_2 & 0 & \\cdots \\\\\n      \\vdots & 0 & \\ddots &\n      \\end{matrix} \\right) \\quad \\text{where} \\quad\n      J_i = \\left(\\begin{matrix}\n      \\lambda_i & 1 & & & \\\\\n            & \\lambda_i & 1 & &   \\\\\n            &   & \\ddots & \\ddots &  \\\\\n            & & & \\lambda_i & 1 \\\\\n            & & & &  \\lambda_i\n    \\end{matrix} \\right).\n\\end{displaymath}\nThe $J_i$ are called {\\em Jordan blocks}.\n\n\n\\begin{exercise}\n  Prove that a matrix $C \\in \\R^{N \\times N}$ is spd if and only if it\n  is symmetric and all its eigenvalues are positive.\n\\end{exercise}\n\n\n\\subsubsection{Convexity}\n%\nA set $U \\subset \\R^N$ is convex if, for $x, y \\in U, \\lambda \\in [0,\n1]$, the point $(1-\\lambda) x + \\lambda y \\in U$ as well.\n\nIf $U$ is convex and $f : U \\to \\R$, then $f$ is convex if, for $x, y\n\\in U, \\lambda \\in [0, 1]$, we have\n\\begin{equation}\n  \\label{eq:convex_f}\n  f\\b( (1-\\lambda) x + \\lambda y \\b) \\leq (1-\\lambda) f(x) + \\lambda f(y).\n\\end{equation}\n\n\\begin{exercise}\n  (i) Prove that the functions $f(x) = |x|^n, n \\in \\N$, $f(x) =\n  \\exp(x), f(x) = \\min(0, x)$ are convex.\n\n  (ii) Prove that $f(x) = -x^2, f(x) = \\cos(x), f(x) = \\max(0, x)$ are\n  non-convex.\n\n  (iii) Prove that, if $C \\in \\R^{N \\times N}$ and $b \\in \\R^N$, then\n  $f(x) = \\smfrac12 x^T C x - b^T x$ is convex.\n\\end{exercise}\n\n\n\n\n\\subsection{Crash Course in Differentiation}\n\n\\examnote{ The material of this section is understood as background and\n  can/should be used in the exam without proofs. }\n\nThis section is intended as a rapid introduction into and reference\nfor differentiation of multi-variate and/or vector valued functions as\nrequired in the remainder of the lecture notes.\n\n\\subsubsection{Motivation and definition}\n%\n\\paragraph{Univariate:}\n%\nRecall first the definition of differentiability in 1D. Let $f : (a,\nb) \\to \\R$ and $t \\in (a, b)$. Then we say that $f$ is differentiable\nat $t$ if there exists $T \\in \\R$ such that\n\\begin{displaymath}\n  % \\label{eq:diff:diff_1d}\n  f(t+h) = f(t) + T h + o(h),\n\\end{displaymath}\nwhere $o(h) / h \\to 0$ as $h \\to 0$. We write $T = f'(t)$. In words:\n$f$ can be ``well approximated'' in a small neighbourhood of $t$ by an\naffine function.\n\nFor vector valued functions with scalar argument, nothing changes. $f\n: (a, b) \\to \\R^N$ is differentiable at $t$ if there exists $T \\in\n\\R^N$ such that\n\\begin{displaymath}\n  f(t+h) = f(t) + T h + o(h),\n\\end{displaymath}\nand we call $T = \\dot{f}(t)$. Clearly this is equivalent to saying\nthat $f_i$ is differentiable at $t$ for all $i = 1, \\dots, N$.\n\nWe define spaces of continuously differentiable functions. For an\ninterval $A \\subset \\R$ and $j \\geq 1$,\n\\begin{align*}\n  C^j(A;\\R^N) = \\b\\{ f \\in C(A;\\R^N) \\bsep & \\text{ $f$ is $j$ times\n    differentiable in ${\\rm int}(A)$} \\\\\n  & \\text{ and $f^{(k)} \\in C(A;\\R^N)$ for $k = 0, \\dots, j$} \\b\\}.\n\\end{align*}\n(Note that if $A$ contains one of its endpoints, then by $f^{(k)} \\in\nC(A; \\R^N)$ we mean that the derivative $f^{(k)}$ first defined on\n${\\rm int}(A)$ can be {\\em continuously extended} to $A$. This is\nsubtle point that can in fact be ignored for the purpose of these\nlecture notes.)\n\n\n\n\\paragraph{Multi-variate:} With this idea of differentiation in mind,\nthe generalisation to functions with vectorial arguments is\nimmediate. Let $U \\subset \\R^N$ be open and let $f : U \\to \\R^M$. We\nsay that $f$ is (Fr\\'echet) differentiable at $x \\in U$ if there\nexists a matrix $T \\in \\R^{M \\times N}$ (recall that every linear\nfunction from $\\R^N$ to $\\R^M$ is of the form $h \\mapsto T h$ for some\n$T \\in \\R^{M \\times N}$) such that\n\\begin{displaymath}\n  f(x+h) = f(x) + T h + o(|h|), \\qquad \\text{as $h \\to 0$,}\n\\end{displaymath}\nand we write $T = \\partial f(x)$.\n\nThere is also a second notion of differentiability: We say that $f$ is\nGateaux differentiable at $x \\in U$ if there exists $T \\in \\R^{M\n  \\times N}$ such that, for all $h \\in \\R^N$,\n\\begin{displaymath}\n  f(x + s h) = f(x) + s T h + o(s) \\qquad \\text{as $s \\to 0$.}\n\\end{displaymath}\nWe still write $T = \\partial f(x)$. The subtle difference of letting\nthe perturbation tend to zero in a straight line, or in an arbitrary\nfashion makes Gateaux differentiability a strictly weaker notion of\ndifferentiability.\n\n(WARNING: some authors define Gateaux derivative slightly\ndifferently. It is always useful to check what is meant. By contrast\nFrechet differentiability seems universally accepted as stated above.)\n\n\\begin{exercise}[Frechet versus Gateaux]\n  \\label{eq:diff:F_vs_G}\n  (i) Show that if $f$ is Frechet differentiable in $x$ then it is\n  continuous in $x$ as well as Gateaux differentiable in $x$.\n\n  (ii) Conversely, consider $f : \\R^2 \\to \\R$,\n  \\begin{displaymath}\n    f(x, y) = \\cases{\n      \\b(\\frac{x^2 y}{x^4+y^2} \\b)^2, & (x, y) \\neq (0, 0), \\\\\n      0, & (x, y) = (0, 0),\n    }\n  \\end{displaymath}\n  and show that $f$ is Gateaux differentiable at $(0, 0)$ but not even\n  continuous.\n\n  (iii) In other respects, Gateaux and Fr\\'echet differentiability are\n  not so far from one another: If $f$ is Gateaux differentiable in $U$\n  and $\\pp f$ is continuous at $x \\in U$, then $f$ is Fr\\'echet\n  differentiable at $x$. {\\it (HINT: If you don't see this\n    immediately, do Exercise \\ref{ex:diff:pd_frechet} first, from\n    which this results follows.)}\n\\end{exercise}\n\nREMINDER: If we say $f$ is {\\em differentiable}, then we mean the\nFrechet sense!\n\n\\begin{definition}\n  If $U \\subset \\R^N$, with ${\\rm int}(U) \\neq \\emptyset$, then we say\n  that $f \\in C^1(U; \\R^M)$ if $f : U \\to \\R^{M}$ is differentiable at\n  each point $x \\in {\\rm int}(U)$ and $\\pp f \\in C(U; \\R^{M \\times\n    N})$.\n\n  REMARK: From Exercise \\ref{eq:diff:F_vs_G}(iii) it follows\n  immediately that $f \\in C^1(U; \\R^M)$ if and only if $f$ is Gateaux\n  differentiable at each point in $U$ and $\\pp U \\in C(U; \\R^{M\\times\n    N})$, that is, the definition of $C^1$ is in fact independent of\n  which of the two notions of differentiability we employ.\n\\end{definition}\n\n\\subsubsection{Jacobi matrix and gradient}\n%\nTo actually compute the derivative $\\pp f(x)$, we simply test the\ndefinition\n\\begin{displaymath}\n  f(x + sh) = f(x) + s\\partial f(x) h + o(s)\n\\end{displaymath}\nwith $h = e_j$ ($e_j$ is a canonical basis vector). Hence, we obtain\nthat\n\\begin{displaymath}\n  \\frac{\\pp f_i(x)}{\\pp x_j} = \\lim_{s \\to 0} \\frac{f_i(x+s e_j) -\n    f_i(x)}{s} = \\b(\\partial f(x) e_j\\b)_i = \\b( \\partial f(x) \\b)_{ij}.\n\\end{displaymath}\nThat is, $\\pp f(x)$ is simply the matrix of partial derivatives, or,\n{\\em Jacobi matrix},\n\\begin{displaymath}\n  \\pp f(x) = \\left(\n    \\begin{array}{cccc}\n      \\frac{\\pp f_1}{\\pp x_1} & \\frac{\\pp f_1}{\\pp x_2} & \\cdots &\n      \\frac{\\pp f_1}{\\pp x_N} \\\\\n      \\frac{\\pp f_2}{\\pp x_1} & \\frac{\\pp f_2}{\\pp x_2} & \\cdots &\n      \\frac{\\pp f_2}{\\pp x_N} \\\\\n      \\vdots & \\vdots & \\ddots &  \\vdots\\\\\n      \\frac{\\pp f_M}{\\pp x_1} & \\frac{\\pp f_M}{\\pp x_2} & \\cdots &\n      \\frac{\\pp f_M}{\\pp x_N}\n    \\end{array} \\right).\n\\end{displaymath}\n\nIf $M = 1$, i.e. $f : U \\subset \\R^N \\to \\R$ and $f$ is (Frechet or Gateaux)\ndifferentiable at $x \\in U$ then we call\n\\begin{displaymath}\n  \\nabla f(x) := \\pp f(x)^T\n\\end{displaymath}\nthe {\\em gradient} of $f$ at $x$. Thus, in this case we can\nalternatively write Gateaux-differentiability in the form\n\\begin{displaymath}\n  f(x+sh) = f(x) + s \\nabla f(x) \\cdot h + o(s),\n\\end{displaymath}\nand similarly for F-differentiability.\n\n\\examrem{\n\\begin{remark}\n  \\notexam\n  This remark is to explain why one makes a distinction between $\\pp\n  f$ and $\\nabla f$. It is mostly semantic, until one starts thinking\n  in terms of infinite-dimensional vector spaces, or different inner\n  products. (But then it can become very relevant.)\n\n  We can think of the gradient in terms of the Riesz representation\n  theorem (RRT). Namely, $\\pp f(x)$ represents a linear functional\n  acting on $\\R^N$, $\\ell(h) = \\pp f(x) h$, and according to the RRT\n  there exists an element of $\\R^N$, namely $\\nabla f(x)$, that {\\em\n    represents} $\\ell$ in terms of an inner product: $\\ell(h) = \\nabla\n  f(x) \\cdot h$.\n\n  Suppose now that we change the inner product to $\\< x, y \\>_M = x^T\n  M y$ for some matrix $M$ (we need to check under which conditions\n  this defined an inner product: if and only if $M$ is symmetric and\n  positive definite). Then the gradient with respect to $\\< \\cdot,\n  \\cdot\\>_M$ is $\\nabla_M f(x) = M^{-1} \\nabla f(x)$, since $\\partial\n  f(x) h = \\< \\nabla_M f(x), h \\>_M$.\n\\end{remark}\n}\n\n\n\\begin{exercise}[Partial derivatives and differentiability]\n  \\label{ex:diff:pd_frechet}\n  We conclude this discussion with a remark on the relationship\n  between partial derivatives and Frechet differentiability, which\n  extends Exercise \\ref{eq:diff:F_vs_G} (iii):\n\n  Suppose that $f : U \\subset \\R^N \\to \\R^M$, $U$ open, has\n  well-defined partial derivatives $\\pp f(x)$ at each point $x \\in\n  U$. (I.e., $t \\mapsto f(x+t e_i)$ is differentiable at $t = 0$ for\n  all $x \\in U$.)  that $\\partial f : U \\to \\R^{M \\times N}$ is\n  continuous at a point $x \\in U$. Then $f$ is Frechet differentiable\n  at $x$.\n\\end{exercise}\n\n\\subsubsection{Some useful properties}\n%\n\\begin{exercise}\n  All the usual linearity properties of differentiation hold for\n  multivariate differentiation as well:\n\n  If $f, g$ are differentiable at $x$, then $f + \\lambda g$ is\n  differentiable at $x$ for any $\\lambda \\in \\R$.\n\\end{exercise}\n\nThe only other property we need is the chain rule. For scalar arguments, this reads\n\\begin{displaymath}\n  \\frac{\\dd}{\\dd t} f(g(t)) = \\frac{\\dd f}{\\dd g} (g(t)) \\cdot\n  \\frac{\\dd g}{\\dd t}(t) \\quad \\text{or} \\quad\n  (f \\circ g)' = (f' \\circ g) g'.\n\\end{displaymath}\nNote also that the statement for scalar-valued functions immediately\nimplies the same statement for vector-valued functions.\n\nThe multi-variate version is formally identical,\n\\begin{equation}\n  \\label{eq:diff:chain_rule}\n  \\pp \\b( f(g(x)) \\b) = (\\pp f)(g(x)) \\, \\pp g(x), \\quad \\text{or}\n  \\quad\n  \\pp(f \\circ g) = (\\pp f) \\circ g \\, \\pp g\n\\end{equation}\nAnother, possibly more memorable way to write this is\n\\begin{align*}\n  \\frac{\\pp (f(g(x)))}{\\pp x} &= \\frac{\\pp f(g)}{\\pp g}\\Big|_{g = g(x)} \\,\n  \\frac{\\pp g(x)}{\\pp x}\n\\end{align*}\n\n\\begin{proposition}\n  Let $f : U \\subset \\R^N \\to \\R^M$ and $g : V \\subset \\R^K \\to\n  \\R^N$. Suppose that $g$ is differentiable at $x \\in V$ and $f$ is\n  differentiable at $g(x) \\in U$, then $f \\circ g$ is differentiable\n  at $x$ and \\eqref{eq:diff:chain_rule} holds.\n\n  The same result holds if we replace ``differentiable'' with\n  ``Gateaux differentiable''.\n\\end{proposition}\n\\begin{proof}\n  \\begin{align*}\n    f(g(x+h)) &= f\\b( g(x) + \\pp g(x) h + o(|h|) \\b) \\\\\n    &= f(g(x)) + \\pp f(g(x)) \\, \\b(\\pp g(x) h + o(|h|)\\b)\n    + o\\b( |\\pp g(x) h + o(|h|)| \\b) \\\\\n    &= f(g(x)) + \\pp f(g(x)) \\, \\pp g(x) h  + o(|h|).\n  \\end{align*}\n\n  The proof for the Gateaux case is analogous.\n\\end{proof}\n\nAn important special case is the following: if $f \\in C^1(U;\\R^N)$, $U\n\\subset \\R^N$ open, and $g \\in C^1(a, b; U)$, then\n\\begin{displaymath}\n  \\frac{\\dd}{\\dd t} f(g(t)) = \\pp f(g(t)) \\dot{g}(t).\n\\end{displaymath}\nIn particular, if $N = 1$, then\n\\begin{displaymath}\n  \\label{eq:chain_rule_nabla}\n  \\frac{\\dd}{\\dd t} f(g(t)) =  \\nabla f(g(t)) \\cdot \\dot{g}(t).\n\\end{displaymath}\n\n\n\\subsubsection{Differentiation and integration of $f : \\R \\to \\R^N$}\n%\nWe will not be concerned with integrating over $\\R^N$, but we do need\nsome results on integrating vector-valued functions defined on an\ninterval.\n\nLet $f : [a, b] \\to \\R^N$ be continuous, then we define its integral\ncomponentwise:\n\\begin{displaymath}\n  \\int_a^b f(t) \\dt = \\bigg( \\int_a^b f_i(t) \\dt \\bigg)_{i = 1}^N.\n\\end{displaymath}\nClearly, we get the fundamental theorem of calculus again: if $f \\in\nC^1([a,b]; \\R^N)$, then\n\\begin{displaymath}\n  \\int_a^b \\dot f(t) \\dt = f(b) - f(a).\n\\end{displaymath}\n\nBut other results can fail:\n\n\\begin{exercise}\n  The integral mean value theorem is an example of a result that does\n  {\\em not} translate (and hence the differential MVT does not\n  either):\n\n  (i) Vector-valued, scalar argument: Show the integral MVT fails for\n  $f : (0, 2\\pi) \\to \\R^2$, $f(t) = (\\cos t, \\sin t)^T$.\n\n  \\examrem{\n  (ii) \\notexam For comparison, the integral MVT, scalar valued,\n  vectorial argument: Show that if $U \\subset \\R^N$ is the closed unit\n  cube (but any connected, measurable set with unit volume will do)\n  and if $f \\in C(U; \\R)$, then there exists $x_0 \\in U$ such that\n  $\\int_U f \\dx = f(x_0)$. (Of course we haven't defined multi-variate\n  integration. Either use your immagination or look up the definition\n  in a suitable textbook.)}\n\\end{exercise}\n\n\nAn important consequence of the fundamental theorem are path\nintegrals: If $\\gamma \\in C^1([a, b]; \\R^N)$, then the intregal of $f$\nalong its path is\n\\begin{displaymath}\n  \\int_a^b f(\\gamma(t)) \\dot\\gamma(t) \\dt.\n\\end{displaymath}\n\n\\begin{exercise}\n  (i) Show that, if $E \\in C^1(U; \\R)$ and $\\gamma \\in C^1((a, b);\n  \\R^N)$, then $E \\circ \\gamma \\in C^1((a,b); \\R)$ and $\\frac{\\dd}{\\dd\n    t} E(\\gamma(t)) = \\nabla E(\\gamma(t)) \\cdot \\dot\\gamma(t)$.\n\n  (ii) Therefore, if $f(x) = \\nabla E(x)$, then the integral\n  \\begin{displaymath}\n    \\int_a^b f(\\gamma(t)) \\cdot \\dot\\gamma(t) \\dt = E(\\gamma(b)) - E(\\gamma(a))\n  \\end{displaymath}\n  depends only on the end-points but not on the entire path.\n\n  \\examrem{\n  (iii) \\notexam {\\it (MORE DIFFICULT)} Show, conversely, that if $f \\in C(U;\n  \\R^N)$, where $U$ is open and simply connected, and if $f$ is {\\em\n    conservative} i.e. integrals along closed paths all vanish,\n  \\begin{displaymath}\n    \\int_a^b f(\\gamma(t)) \\dot\\gamma(t) \\dt = 0 \\qquad \\forall \\gamma \\in\n    C^1([a,b]; U), \\gamma(a) = \\gamma(b),\n  \\end{displaymath}\n  then there exists $E \\in C^1(U; \\R)$ such that $f = \\nabla E$.\n\n  (iv) \\notexam  {\\it (MORE DIFFICULT)} If $f \\in C^1(U; \\R^N)$, where $U$ is\n  open and simply connected, show that $f$ is conservative if and only\n  if $\\pp f(x)$ is symmetric for all $x \\in U$. For $N = 3$ connect\n  this to the curl-free condition.\n}\n\\end{exercise}\n\n\n\\subsubsection{Higher derivatives}\n%\nThe notation for higher derivatives can initially be confusing and we\nwill therefore avoid their use as much as possible. However, there are\nsome simple definitions and results that we require.\n\n\nFor $U \\subset \\R^N$ with ${\\rm int}(U) \\neq \\emptyset$ and for $k\n\\geq 2$, we define (recursively)\n\\begin{displaymath}\n  C^k(U; \\R^M) := \\b\\{ f \\in C^1(U; \\R^M) \\bsep \\partial f \\in\n  C^{k-1}(U; \\R^{M \\times N}) \\b\\}.\n\\end{displaymath}\n\nA useful result is the following:\n\n\\begin{exercise}\n  Let $f \\in C^2(U; \\R^M)$ where $U \\subset \\R^N$ is convex and\n  closed, then $\\pp f : U \\to \\R^{M \\times N}$ is Lipschitz\n  continuous, in the sense that\n  \\begin{displaymath}\n    \\| \\pp f(x) - \\pp f(y) \\|_F \\leq L |x - y| \\qquad \\text{ for } x,\n    y \\in U. \\qedhere\n  \\end{displaymath}\n\\end{exercise}\n\nThere is a particularly important case: Let $U \\subset \\R^N$ be open\nand let $E \\in C^2(U; \\R)$, then we define the Hessian matrix\n\\begin{displaymath}\n  \\D^2 E(x) := \\bg( \\frac{\\pp^2 E(x)}{\\pp x_i \\pp x_j}\n  \\bg)_{i, j = 1, \\dots, N}.\n\\end{displaymath}\n\n\\begin{exercise}\n  Let $E \\in C^2(U)$, where $U \\subset \\R^N$ is open. Prove the\n  following statements:\n\n  (i) $\\D^2 E(x) = \\pp \\D E(x)$.\n\n  (ii) $E(x+h) = E(x) + \\D E(x) \\cdot h + \\smfrac12 h^T \\D^2 E(x) h +\n  o(|h|^2)$.\n\n  (iii) If $E \\in C^3(U)$, then $E(x+h) = E(x) + \\D E(x) \\cdot h +\n  \\smfrac12 h^T \\D^2 E(x) h + O(|h|^3)$.\n\\end{exercise}\n", "meta": {"hexsha": "8f6a42cdc8832d351c27a5ed41c6e220a341acc4", "size": 19368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/backup.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/backup.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/backup.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": 35.8003696858, "max_line_length": 83, "alphanum_fraction": 0.6316088393, "num_tokens": 6994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8757869948899666, "lm_q1q2_score": 0.7934540999714652}}
{"text": "\\section*{Essentials}\n\\subsection*{Matrix/Vector}\n\\textbf{Multiplication:} $\\mathbf{C}=\\mathbf{AB} \\Leftrightarrow c_{ik} = \\sum_{j=1}^m a_{ij}\\cdot b_{jk}$ \\\\\n\\textbf{Orthogonal Matrix:} (full rank square matrix with orthonormal columns) $\\mathbf{A}^{-1} = \\mathbf{A}^\\top$, $\\mathbf{A} \\mathbf{A}^\\top = \\mathbf{A}^\\top \\mathbf{A} = \\mathbf{I}$, $\\operatorname{det}(\\mathbf{A}) \\in \\{+1, -1\\}$, $\\operatorname{det}(\\mathbf{A}^\\top \\mathbf{A}) = 1$,\n\tpreserves: inner product, norm, distance, angle, rank, mat. orthogon. \\\\\n\\textbf{Inner Product:} $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\mathbf{x}^\\top \\mathbf{y} = \\sum_{i=1}^{N} \\mathbf{x}_i \\mathbf{y}_i$. \\\\\n$\\langle \\mathbf{x} \\pm \\mathbf{y}, \\mathbf{x} \\pm \\mathbf{y} \\rangle = \\langle \\mathbf{x}, \\mathbf{x} \\rangle \\pm 2 \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{y}, \\mathbf{y} \\rangle$ \\\\\n$\\langle \\mathbf{x}, \\mathbf{y} + \\mathbf{z} \\rangle = \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{x}, \\mathbf{z} \\rangle$\\\\\n$\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\|\\mathbf{x}\\|_2 \\cdot \\|\\mathbf{y}\\|_2 \\cdot \\cos(\\theta)$\\\\\nIf $\\mathbf{y}$ is a unit vector then $\\langle \\mathbf{x}, \\mathbf{y} \\rangle$ projects $\\mathbf{x}$ onto $\\mathbf{y}$ \\\\\n$(\\mathbf{u}_i^T\\mathbf{v}_j)\\mathbf{v}_j = (\\mathbf{v}_j\\mathbf{v}_j^T)\\mathbf{u}_i$ \\\\\n\\textbf{Outer Product:} $\\mathbf{u} \\mathbf{v}^\\top$, \\quad $(\\mathbf{u} \\mathbf{v}^\\top)_{i, j} = \\mathbf{u}_i \\mathbf{v}_j$ \\\\\n\\textbf{Transpose:} $(\\mathbf{A}^\\top)^{-1} = (\\mathbf{A}^{-1})^\\top$ \\\\\n\\textbf{Determinant:} $|\\mathbf{A}|=\\sum_i \\lambda_i$, \\quad $|\\mathbf{A}^{-1}| = 1/|\\mathbf{A}|$\n\n\\subsection*{Norms}\n$\\|\\mathbf{x}\\|_0 = |\\{i | x_i \\neq 0\\}|$ \\quad\n$\\|\\mathbf{x}\\|_2 = \\sqrt{\\sum_{i=1}^{N} \\mathbf{x}_i^2} = \\sqrt{\\langle \\mathbf{x}, \\mathbf{x} \\rangle}$ \\\\\n$\\|\\mathbf{x}\\|_p = \\left( \\sum_{i=1}^{N} |x_i|^p \\right)^{\\frac{1}{p}}$ \\quad\n$\\|\\mathbf{M}\\|_F =\\allowbreak \\sqrt{\\sum_{i=1}^{m} \\sum_{j=1}^{n}\\mathbf{m}_{i,j}^2} \\allowbreak = \\sqrt{\\sum_{i=1}^{\\min\\{m, n\\}} \\sigma_i^2}$  $\\allowbreak = \\|\\sigma(\\mathbf{A})\\|_2  = \\sqrt{trace(\\mathbf{M}^T\\mathbf{M})} $\\\\\n$\\|\\mathbf{M}\\|_G=\\sqrt{\\sum_{ij}{g_{ij}x^2_{ij}}}$ (weighted Frobenius) \\\\\n$\\|\\mathbf{M}\\|_1 = \\sum_{i,j} | m_{i,j}|$ \\quad\n$\\|\\mathbf{M}\\|_p = \\max_{\\mathbf{v} \\neq 0} \\frac{\\|\\mathbf{M}\\mathbf{v}\\|_p}{\\|\\mathbf{v}\\|_p}$ \\\\\n$\\|\\mathbf{M}\\|_2 = \\sigma_{\\text{max}}(\\mathbf{M}) = \\|\\sigma(\\mathbf(M))\\|_\\infty$ \\\\\n$\\|\\mathbf{M}\\|_* = \\sum_{i=1}^{\\min(m, n)} \\sigma_i = \\|\\sigma(\\mathbf{A})\\|_1$ (nuclear norm) \\\\\n$\\text{rank}(\\mathbf{B}) \\geq ||\\mathbf{B}||_* \\ \\text{for} \\ ||B||_2 \\leq 1$\n\n\\subsection*{Derivatives}\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{x}) = \\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{b}) = \\mathbf{b}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{A}\\mathbf{x}) = (\\mathbf{A}^\\top + \\mathbf{A})\\mathbf{x}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{A}\\mathbf{x}) = \\mathbf{A}^\\top \\mathbf{b}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X} \\mathbf{b}) = \\mathbf{c}\\mathbf{b}^\\top$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X}^\\top \\mathbf{b}) = \\mathbf{b}\\mathbf{c}^\\top$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\| \\mathbf{x}-\\mathbf{b} \\|_2) = \\frac{\\mathbf{x}-\\mathbf{b}}{\\|\\mathbf{x}-\\mathbf{b}\\|_2}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}\\log(x) = \\frac{1}{x}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\|\\mathbf{Ax - b}\\|_2^2) = \\mathbf{2(A^\\top Ax-A^\\top b)}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}\\frac{1}{f(x)} = \\frac{-f'}{f^2}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(|\\mathbf{X}|) = |\\mathbf{X}|\\cdot \\mathbf{X}^{-1}$ \\quad $\\frac{\\partial}{\\partial x}(\\mathbf{Y}^{-1}) = -\\mathbf{Y}^{-1} \\frac{\\partial\\mathbf{Y}}{\\partial x} \\mathbf{Y}^{-1}$\n\n\\subsection*{Eigenvalues \\& Eigenvectors}\nEigenvalue problem: $\\mathbf{Ax}=\\lambda\\mathbf{x}$ \\\\\n1. solve $\\det(\\mathbf{A} - \\lambda \\mathbf{I}) = 0$ resulting in $\\{\\lambda_i\\}$ \\\\\n2. $\\forall \\lambda_i$ solve $(\\mathbf{A} - \\lambda_i \\mathbf{I})x_i = \\mathbf{0}$ for $\\mathbf{x}_i$\n\n\\subsection*{Eigendecomposition}\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times N}$ then $\\mathbf{A} = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q}^{-1}$ with $\\mathbf{Q} \\in \\mathbb{R}^{N \\times N}$\\\\\nif fullrank: $\\mathbf{A}^{-1} = \\mathbf{Q} \\boldsymbol{\\Lambda}^{-1} \\mathbf{Q}^{-1}$ and $(\\boldsymbol{\\Lambda}^{-1})_{i,i} = {1}/{\\lambda_i}$\\\\\nif $\\mathbf{A}$ symmetric: $A = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q^\\top}$ ($\\mathbf{Q}$ orthogonal)\n\n\\subsection*{Probability / Statistics}\n$P(x) = \\sum_{y \\in Y} P(x, y)$ \\quad\n$P(x, y) = P(x|y) P(y)$ \\\\\n$\\forall y \\in Y: \\sum_{x \\in X} P(x|y) = 1$ (property for any fixed $y$) \\\\\n$P(x|y) = \\frac{P(x,y)}{P(y)},\\quad \\text{if } P(y) > 0$ \\quad\n$P(x|y) = \\frac{P(y|x)P(x)}{P(y)}$ (Bayes' rule) \\quad\n$P(x_1, \\ldots, x_n) = \\prod_{i=1}^n P(x_i)$ (iff i.i.d) \\\\\n$P(x|y) = P(x) \\Leftrightarrow P(y|x) = P(y)$ (iff $X$, $Y$ indep.) \\\\\n$E[X]:=\\sum_{x \\in X}x\\cdot P(x)$ \\quad\n$Var[X]:= E[(X-\\mu_x)^2]:=\\sum_{x \\in X}(x-\\mu_x)^2P(x)= E(X^2) - E(X)^2$ \\\\\nstandard deviation $\\sigma_x := \\sqrt{Var[X]}$\n\n\\subsection*{Lagrangian Multipliers}\nProblem $\\min_Q g(Q)$ with constraint $\\forall j \\ \\sum_i Q_{ij}=1$ turn into $L(Q, \\alpha) = g(Q)+\\sum_j \\alpha_j (1-\\sum_i Q_{ij})$ and find $\\max_\\alpha \\min_Q L(Q,\\alpha)$ (can use constraint form.).\n\n\\subsection*{Convex Function}\n$\\forall x_1, x_2 \\in X, \\forall t \\in [0,1]: $ \\quad (also $\\text{iff} \\ \\forall x: \\  f''(x) \\geq 0$)\\\\\n$f(tx_1 + (1-t)x_2)\\leq t f(x_1) + (1-t)f(x_2)$ \\\\\n\\textbf{Sum} of convex functions is convex, \\textbf{log} is convex\n%\\vspace{1mm}\n\n\\textbf{Exercise:} Show that if $f$ is convex, any local optimum is global. Assume there is a local optimum $\\hat x$ that is not the global optimum $x^*$, then if we choose $t$ to be in the ball of the local optimum, so we know that $f(t\\hat x + (1-t)x^*) \\geq f(\\hat x)$. Since $f(x^*) < f(\\hat x)$,  we have $t\\cdot f(\\hat x) + (1-t) f(x^*) < f(\\hat x)$. So we get $f(t\\hat x + (1-t)x^*) \\geq f(\\hat x) > t\\cdot f(\\hat x) + (1-t)f(x^*)$, which contradicts the convexity of $f$.\n\n%vspace{1mm}\n\n\\subsection*{Jensen Inequality:} \nfor convex $\\phi$: $\\phi (\\sum_{i=1}^n \\lambda_i x_i) \\leq \\sum_{i=1}^n \\lambda_i f(x_i)$ if $\\sum_{i=1}^n \\lambda_i = 1$. Also $\\phi(E[X])\\leq E[\\phi(X)]$.", "meta": {"hexsha": "5b8cd7aff54b80dc35f91e217230767e0a081e2d", "size": 6431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Essentials.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": "Essentials.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": "Essentials.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": 83.5194805195, "max_line_length": 479, "alphanum_fraction": 0.593220339, "num_tokens": 2807, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474181553803, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7934485607628414}}
{"text": "\\subsection{Angles and Sectors of Circles}\nMathematicians tend to deal mostly with \\dfont{radians} and we \nwill see later that some formulas are more elegant when using \nradians (rather than degrees). The relationship between degrees \nand radians is:\n$$\\pi~\\mbox{rad}=180^\\circ.$$\nUsing this formula, some common angles can be derived:\n$$\\begin{array}{|c|c|c|c|c|c|c|c|c|c|c|c|}\n\\hline\n~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\\\\n\\mbox{Degrees} & 0^\\circ & 30^\\circ & 45^\\circ & 60^\\circ & 90^\\circ & 120^\\circ & 135^\\circ & 150^\\circ & 180^\\circ & 270^\\circ & 360^\\circ \\\\\n~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\\\\n\\hline\n~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\\\\n\\mbox{Radians} & 0 & \\ds{\\frac{\\pi}{6}} & \\ds{\\frac{\\pi}{4}} & \\ds{\\frac{\\pi}{3}} & \\ds{\\frac{\\pi}{2}} & \\ds{\\frac{2\\pi}{3}} & \\ds{\\frac{3\\pi}{4}} & \\ds{\\frac{5\\pi}{6}} & \\ds{\\pi} & \\ds{\\frac{3\\pi}{2}} & 2\\pi\\\\\n~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\\\\n\\hline\n\\end{array}$$\n\n\\begin{example}{Degrees to Radians}{DegreesToRadians}\nTo convert $45^\\circ$ to radians, multiply by $\\ds{\\frac{\\pi}{180^\\circ}}$ to get $\\ds{\\frac{\\pi}{4}}$.\n\\end{example}\n\n\\begin{example}{Radians to Degrees}{RadiansToDegrees}\nTo convert $\\ds{\\frac{5\\pi}{6}}$ radians to degrees, multiply by $\\ds{\\frac{180^\\circ}{\\pi}}$ to get $150^\\circ$.\n\\end{example}\n\nFrom now on, unless otherwise indicated, we will \\ifont{always} use radian measure.\n\nIn the diagram below is a sector of a circle with \\dfont{central angle} \n$\\theta$ and radius $r$ \\dfont{subtending} an arc with length $s$.\n\n$$\\includegraphics[width=50mm]{images/trig1}$$\n\nWhen $\\theta$ is measure in radians, we have the following \nformula relating $\\theta$, $s$ and $r$:\n$$\\theta=\\frac{s}{r}\\mbox{\\quad~or\\quad}s=r\\theta.$$\n\n\\begin{formulabox}[Sector Area]\nThe area of the sector is equal to:\n$$\\mbox{Sector Area}=\\frac{1}{2}r^2\\theta.$$\n\\end{formulabox}\n\n\\begin{example}{Angle Subtended by Arc}{AngleSubtendedArc}\nIf a circle has radius $3$ cm, then an angle of $2$ rad is subtended \nby an arc of $6$ cm ($s=r\\theta=3\\cdot 2=6$).\n\\end{example}\n\n\\begin{example}{Area of Circle}{AreaOfCircle}\nIf we substitute $\\theta=2\\pi$ (a complete revolution) into the sector \narea formula we get the area of a circle: \n$$A=\\frac{1}{2}r^2(2\\pi)=\\pi r^2.$$\n\\end{example}", "meta": {"hexsha": "005f02c9c08253ffe53fd8f3f4a252a662bfeb99", "size": 2281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-3-1-angles-sectors-circles.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1-review/1-3-1-angles-sectors-circles.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1-review/1-3-1-angles-sectors-circles.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.0377358491, "max_line_length": 210, "alphanum_fraction": 0.6159579132, "num_tokens": 835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620562254525, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7934466134319366}}
{"text": "\\section{Parabolas}\nAssociated external model: \\texttt{parabolas.py}\n\nThis model is a simple $N$-dimensional parabolic response $u(Y)$,\n\\begin{equation}\n  u(Y) = \\sum_{n=1}^N -y_n^2,\n\\end{equation}\nwhere the uncertain inputs are $Y=(y_1,\\cdots,y_N)$ and can be defined arbitrarily.  For optimization\nsearches, it is possible to obtain a maximum in the interior of the input by assuring the range of each\ninput variable include 0.  In this case, the maximum point will be ${0}^N$.\n", "meta": {"hexsha": "151302e11b8050cac6d12983e254dfa94bc89344", "size": 480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/parabolas.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/parabolas.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/parabolas.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.6363636364, "max_line_length": 103, "alphanum_fraction": 0.7458333333, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7934263311234268}}
{"text": "\\chapter{Interval}\n\n\n\\section{Introduction}\n\\rih{Two-way range.} The current scanning node as the pivot, need to scan its left neighbors and right neighbors. \n$$\n|\\leftarrow p \\rightarrow |\n$$\n\nIf the relationship between the pivot and its neighbors is symmetric, since scanning range is $[i-k, i+k]$ and iterating from left to right, only consider $[i-k, i]$ to avoid duplication.\n$$\n|\\leftarrow p\n$$\n\n\\section{Operations}\n\\runinhead{Merge intervals.} Given a collection of intervals, merge all overlapping intervals.\n\n\\textbf{Core clues}:\n\\begin{enumerate}\n\\item Sort the intervals\n\\item When does the overlapping happens?\n[0, 5) vs. [2, 6); [0, 5) vs. [2, 4)\n\\end{enumerate}\n\\begin{python}\ndef merge(self, itvls):\n    if not itvls:\n        return []\n\n    itvls.sort(key=lambda x: x.start)\n    ret = [itvls[0]]\n    for cur in itvls[1:]:\n        pre = ret[-1]\n        if cur.start <= pre.end:  # overlap\n            pre.end = max(pre.end, cur.end)\n        else:\n            ret.append(cur)\n\n    return ret\n\\end{python}\n\n\\runinhead{Insert intervals.} Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). Assume that the intervals were initially sorted according to their start times.\n\n\\textbf{Core clues}\n\\begin{enumerate}\n\\item Partition the original list of intervals to left-side intervals and right-side intervals according to the new interval. \n\\item Merge the intermediate intervals with the new interval. Need to mathematically prove it works as expected.\n\\end{enumerate}\n\n\\begin{python}\ndef insert(self, itvls, newItvl):\n    s, e = newItvl.start, newItvl.end\n    left = filter(lambda x: x.end < s, itvls)\n    right = filter(lambda x: x.start > e, itvls)\n    if len(left)+len(right) != len(itvls):\n        s = min(s, itvls[len(left)].start)\n        e = max(e, itvls[-len(right)-1].end)\n\n    return left + [Interval(s, e)] + right\n\n\\end{python}\n\n\\section{Event-driven algorithm}\n\\subsection{Introduction}\nThe core philosophy of event-driven algorithm:\n\\begin{enumerate}\n\\item \\textbf{Event}: define \\textit{event}; the event are sorted by time of appearance.\n\\item \\textbf{Heap}: define \\textit{heap meaning}.\n\\item \\textbf{Transition}: define \\textit{transition functions} among events impacting the.\nheap. \n\\end{enumerate} \n\n\\subsection{Questions}\n\\runinhead{Maximal overlaps.} Given a list of number intervals, find max number of overlapping\nintervals. \n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item \\textbf{Event}: Every new start of an interval is an event. Scan the sorted intervals (sort the interval by \\textit{start}).\n\\item \\textbf{Heap meaning}: Heap stores the \\textit{end} of the interval. \n\\item \\textbf{Transition}: Put the ending time into heap, and pop the ending time earlier than the new start time from heap.\n\\end{enumerate}\n\\newpage\n\\begin{python}\ndef max_overlapping(intervals):\n    maxa = 0\n    intervals.sort(key=operator.attrgetter(\"start\"))\n    h_end = []\n    for itvl in intervals:\n        heapq.heappush(end_heap, itvl.end)\n        \n        while h_end and h_end[0] <= itvl.start:\n            heapq.heappop(h_end)\n\n        maxa = max(maxa, len(h_end))\n\n    return maxa\n\\end{python}\n\n", "meta": {"hexsha": "ed28325df314f840e985b782eccd107b7e212f49", "size": 3171, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterInterval.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": "chapterInterval.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": "chapterInterval.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": 32.3571428571, "max_line_length": 214, "alphanum_fraction": 0.701986755, "num_tokens": 857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.8824278556326344, "lm_q1q2_score": 0.7934097441271355}}
{"text": "\\section{Linear Systems of Equations and Pivoting Strategies}\n\\subsection{Gaussian Elimination with Backward Substitution}\n\\begin{align*}\n    E1: & a_{11}x_{1}+a{12}x_{2}+\\cdots+a_{1n}x_{n} = a_{1,n+1} \\\\\n    E2: & a_{21}x_{1}+a{22}x_{2}+\\cdots+a_{2n}x_{n} = a_{2,n+1} \\\\\n    & \\vdots \\\\\n    En: & a_{n1}x_{1}+a{n2}x_{2}+\\cdots+a_{nn}x_{n} = a_{n,n+1} \\\\\n\\end{align*}\n\n\\subsection{Operation Counts}\n\\subsubsection{Multiplications / divisions}\n\\[\n\\sum_{i=1}^{n-1}(n-i)+(n-i)(n-i+1)=\\frac{2n^3+3n^2-5n}{6}\n\\]\n\\subsubsection{Additions / subtractions}\n\\[\n\\sum_{i=1}^{n-1}(n-i)(n-i+1)=\\frac{n^3-n}{3}\n\\]\n\\subsection{Backward substitution *\\&/}\n\\[\n1+\\sum_{i=1}^{n-1}((n-i)+1)=\\frac{n^2+n}{2}\n\\]\n\\subsection{Backward substitution +\\&-}\n\\[\n\\sum_{i=1}^{n-1}((n-i-1)+1)=\\frac{n^2-n}{2}\n\\]\n\n\\subsection{Gaussian Elimination with Partial Pivoting}\n\\begin{python}\ndef gaussian_elimination_partial_pivoting(A, b):\n    np_result = A**-1 * b\n    print(np_result.T)\n    n = A.shape[0]\n    x = np.zeros((n,1))\n    tmp = 0\n    for k in range(n-1):\n        M = k\n        for m in range(k+1,n):\n            if A[m,k] > A[M,k]: M = m\n        A[[k,M]] = A[[M,k]]\n        b[[k,M]] = b[[M,k]]\n        for i in range(k+1,n):\n            m = A[i,k] / A[k,k]\n            for j in range(k,n):\n                A[i,j] = A[i,j] - m*A[k,j]\n            b[i,0] = b[i,0] - m*b[k,0]\n    x[-1,0] = b[-1,0] / A[-1,-1]\n    for i in range(n-2,-1,-1):\n        for j in range(i+1,n):\n            tmp += A[i,j] * x[j,0]\n        x[i,0] = (b[i,0] - tmp) / A[i,i]\n        tmp = 0\n    return x\n\\end{python}\n\n\\subsection{Gaussian Elimination with Scaled Partial Pivoting}\n\\begin{python}\ndef gaussian_elimination_scaled_partial_pivoting(A, b):\n    np_result = A**-1 * b\n    print(np_result.T)\n    n = A.shape[0]\n    x = np.zeros((n,1))\n    tmp = 0\n    for k in range(n):\n        M = np.max(A[k,:])\n        A[k,:] /= M\n        b[k,0] /= M\n    for k in range(n-1):\n        for i in range(k+1,n):\n            m = A[i,k] / A[k,k]\n            for j in range(k,n):\n                A[i,j] = A[i,j] - m*A[k,j]\n            b[i,0] = b[i,0] - m*b[k,0]\n    x[-1,0] = b[-1,0] / A[-1,-1]\n    for i in range(n-2,-1,-1):\n        for j in range(i+1,n):\n            tmp += A[i,j] * x[j,0]\n        x[i,0] = (b[i,0] - tmp) / A[i,i]\n        tmp = 0\n    return x\n\\end{python}", "meta": {"hexsha": "7895bed04a9782a62f8aee640052b2ca55711389", "size": 2303, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/6.1.2_Linear_systems_of_equations_Pivoting_strategies.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/6.1.2_Linear_systems_of_equations_Pivoting_strategies.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/6.1.2_Linear_systems_of_equations_Pivoting_strategies.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": 28.4320987654, "max_line_length": 66, "alphanum_fraction": 0.494572297, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7933892838457464}}
{"text": "\\section{Naive Bayes}\n\nNaive Bayes methods perform classification based on a direct application of Bayes theorem. Let $y$ denote the sought-after class label and $x_1,x_2...,x_k$ be the features. One is looking for the probability of observing a specific class label conditional on the features that were observed:\n\n\\begin{equation}\nP(y|x_1,x_2,...,x_k) = \\frac{P(x_1,x_2,...,x_k|y)}{P(y)}{P(x_1,x_2,...,x_k)}\n\\end{equation}\n\nThe \"naivit\\'e\" comes in by assuming that the featues are conditionally independent from each other, i.e., given a specific class label $y$, the features are independent random variables. This means that the likelihood factorizes:\n\n\\begin{equation}\nP(x_1,x_2,...,x_k|y) = P(x_1|y)P(x_2|y)...P(x_k|y)\n\\end{equation}\n\nSince we are only interested in the relative probabilities of observing a certain class $y$, one need not worry about the evidence $P(x_1,x_2,...,x_k)$ because it does not depend on the class label. It follows the classification rule:\n\n\\begin{equation}\n\\hat{y} = \\mathrm{argmax}_{y} P(y)\\prod_i P(x_i|y)\n\\end{equation}\n\nA nice feature is that this requires the estimation of only one dimensional probability distributions, which requires less data. It can also be made very computationally efficient as it naturally lends itself to batch training and parallelizability. \n\nNaive Bayes methods differ among each other principally in the way that the conditional probabilities $P(x_i|y)$ are modeled. For example, Gaussian Naive Bayes assumes that the features have conditional Gaussian Distribution, Bernoulli Naive Bayes assumes conditional binary distribution, and so on. The assumption of conditional independence of the featues tends to hold up reasonably well in practice and amounts to the assumption that the features associated with a particular class label have a diagonal covariance matrix. In the case of Gaussian Naive Bayes, this assumption can be relaxed by instead implementing Quadratic Discriminant Analysis as a classifier, which turns out to be identical to Gaussian Naive Bayes except that it allows for the features to have general covariance matrixes. \n\nIn principle, one should be able to mix and match the way that the $P(x_i|y)$ are modeled, which enables naive Bayes to handle virtually any type of feature (though I have not seen implementations of that). \n", "meta": {"hexsha": "aabdfb1d532d53c858e40a3f738f2d1f015614ff", "size": 2324, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/sup_naivebayes.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/sup_naivebayes.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/sup_naivebayes.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": 89.3846153846, "max_line_length": 800, "alphanum_fraction": 0.7848537005, "num_tokens": 561, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7932954888656288}}
{"text": "\n\\subsection{Defining groups}\n\n\\subsubsection{Magma}\n\nA magma, or groupoid, is a set with a single binary operation.\n\nThese can be defined as an ordered pair \\((s,\\odot )\\) where \\(s\\) is the set, and \\(\\odot \\) is the binary operation.\n\nIf \\(a\\) and \\(b\\) are in \\(s\\), then \\(a\\odot b\\) is also in \\(s\\).\n\nThe following are magmas:\n\n\\begin{itemize}\n\\item Natural numbers and addition\n\\item \\(n\\times n\\) matrices with determinants other than \\(0\\)\n\\item Natural numbers above \\(0\\) and addition\n\\item Integers and addition\n\\item Rational numbers and division\n\\item \\(\\{-1, 1\\}\\) and multiplication\n\\end{itemize}\n\nThe following are not magmas:\n\n\\begin{itemize}\n\\item Natural numbers up to \\(10\\) and addition\n\\end{itemize}\n\n\\subsubsection{Semigroup}\n\nA semigroup is a magma whose binary operation is associative.\n\nThe following are semigroups:\n\n\\begin{itemize}\n\\item Natural numbers and addition\n\\item \\(n\\times n\\) matrices with determinants other than \\(0\\)\n\\item Natural numbers above \\(0\\) and addition\n\\item Integers and addition\n\\end{itemize}\n\nThe following are not semigroups:\n\n\\begin{itemize}\n\\item \\(\\{-1, 1\\}\\) and multiplication\n\\item Rational numbers and division\n\\item Natural numbers up to \\(10\\) and addition\n\\end{itemize}\n\n\\subsubsection{Monoid}\n\nA monoid is a semigroup with an identity element\n\nThe following are monoids:\n\n\\begin{itemize}\n\\item Natural numbers and addition\n\\item \\(n\\times n\\) matrices with determinants other than \\(0\\)\n\\item Integers and addition\n\\item \\(\\{-1, 1\\}\\) and multiplication\n\\end{itemize}\n\nThe following are not monoids:\n\n\\begin{itemize}\n\\item Natural numbers above \\(0\\) and addition\n\\item Rational numbers and division\n\\item Natural numbers up to \\(10\\) and addition\n\\end{itemize}\n\n\\subsubsection{Group}\n\nA group is a monoid where there is an inverse operation for the binary operation.\n\nThe following are groups:\n\n\\begin{itemize}\n\\item Integers and addition\n\\item \\(n\\times n\\) matrices with determinants other than \\(0\\)\n\\item \\(\\{-1, 1\\}\\) and multiplication\n\\end{itemize}\n\nThe following are not groups:\n\n\\begin{itemize}\n\\item Natural numbers above \\(0\\) and addition\n\\item Rational numbers and division\n\\item Natural numbers and addition\n\\item Natural numbers up to \\(10\\) and addition\n\\end{itemize}\n\n", "meta": {"hexsha": "f22f4b0dabf040256167881bb9294c04c1f0ee48", "size": 2256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/01-02-defining.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-02-defining.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-02-defining.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.5217391304, "max_line_length": 118, "alphanum_fraction": 0.7367021277, "num_tokens": 613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8615382165412809, "lm_q1q2_score": 0.7932954876859577}}
{"text": "\n\\subsection{Cramér-Rao lower bound}\n\nFor an unbiased estimator, the variance cannot be below the Cramer-Rao lower bound.\n\n\\(Var (\\hat \\theta )\\ge \\dfrac{1}{I(\\theta )}\\)\n\nWhere \\(I(\\theta )\\) is the Fisher information.\n\nWe can prove this.\n\nWe have the score:\n\n\\(V=\\dfrac{\\delta }{\\delta \\theta }\\ln f(X, \\theta )\\)\n\n\\(V=\\dfrac{1}{f(X, \\theta )}\\dfrac{\\delta }{\\delta \\theta } f(X, \\theta )\\)\n\nThe expectation of the score is \\(0\\):\n\n\\(E[V]=E[\\dfrac{1}{f(X, \\theta )}\\dfrac{\\delta }{\\delta \\theta } f(X, \\theta )]\\)\n\n\\(E[V]=\\int \\dfrac{1}{f(X, \\theta )}\\dfrac{\\delta }{\\delta \\theta } f(X, \\theta )dx\\)\n\n", "meta": {"hexsha": "d6b8a83188a0a954893865c1aec1de9b0f4aec73", "size": 604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/02-05-cramerRao.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-05-cramerRao.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-05-cramerRao.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1666666667, "max_line_length": 85, "alphanum_fraction": 0.6142384106, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9648551546097941, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7932934143425454}}
{"text": "\\section{Test statistic}\n\\label{sec:teststat}\n\nTo test the level of agreement between the data and the hypothesized value $\\mu$, a test statistic $t_{\\mu}$ can be defined as~\\cite{Cowan:2010js}:\n\\begin{equation}\n    t_{\\mu} = -2 ln \\lambda (\\mu)\n\\end{equation}\nFrom the definition of $\\lambda(\\mu)$ in equation~\\ref{eq:lambda}, one can see that $0 \\le \\lambda \\le 1$,\nwhile a $\\lambda$ with value close to 1 implies good agreement between data and $\\mu$.\nThus, smaller value of $t_{\\mu}$ means the increase of compatibility between data and $\\mu$.\nTo quantify the level of disagreement, one can calculate the $p$-value as:\n\\begin{equation}\n    p_{\\mu} = \\int_{t_{\\mu, obs}}^{\\infty} f(t_{\\mu}|\\mu) d t_{\\mu}\n\\end{equation}\nin which $t_{\\mu, obs}$ is the value of test statistic from observed data, \nand $f(t_{\\mu}|\\mu)$ is the pdf of $t_{\\mu}$ under the assumption of hypothesized value $\\mu$.\nThis is a one-side $p$-value with its corresponding observed significance, $Z$, is defined as:\n\\begin{equation}\n    Z = \\Phi^{-1}(1-2p_{\\mu})\n\\end{equation}\nThe relationship between the $t_{\\mu}$, $p$-value and significance $Z$ are depicted in figure~\\ref{fig:pvalue_Z}.\nWhen searching for a signal process, such as Higgs boson, the particle physics community tends to claim a discovery\nwhen the rejection of background-only hypothesis has a significance of at least $Z = 5$.\n\n\\begin{figure}[!htbp]\n\\begin{center}\n\\includegraphics[width=1.0\\textwidth]{figures/Statistic/test_statistic_pvalue_Z.png}\n\\end{center}\n\\caption{(a) Illustration of the relationship between the observed $t_{\\mu}$ and its $p$-value. \n         (b) The relationship between $p$-value and the observed significance $Z$, where $\\phi(x)$ is the standard normal distribution~\\cite{Cowan:2010js}.}\n\\label{fig:pvalue_Z}\n\\end{figure}\n\nIn most cases, one assumes that the presence of a new signal can only increase the event rate comparing to the background only model,\nwhich means the signal strength cannot be a negative value ($\\mu \\ge 0$).\nAnd for the case of discovery, the hypothesis of a positive signal strength should be tested against to the background-only (null) hypothesis by using the test statistic called $q_0$:\n\\begin{equation} \\label{eq:q0}\n    q_0 = \n    \\begin{cases}\n        -2 ln(\\lambda(0)) &\\hat{\\mu} \\ge 0 \\\\\n        0                 &\\hat{\\mu} < 0\n    \\end{cases}\n\\end{equation}\nwhich corresponds to the $p$-value called $p_0$:\n\\begin{equation}\n    p_0 = \\int_{q_{0, obs}}^{\\infty} f(q_0|0) d q_0\n\\end{equation}\nto quantify the level of disagreement between the data and the null hypothesis ($\\mu = 0$).\n", "meta": {"hexsha": "4d0bf58fe2b915ebecd1383aba4c54d30c130c60", "size": 2590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Statistic/teststat.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/Statistic/teststat.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/Statistic/teststat.tex", "max_forks_repo_name": "zhuhel/PhDthesis", "max_forks_repo_head_hexsha": "55ec32affb5c105143798989d78043467c88da8e", "max_forks_repo_licenses": ["LPPL-1.3c"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.8571428571, "max_line_length": 183, "alphanum_fraction": 0.7104247104, "num_tokens": 770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454895, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.793211048493477}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Generating functions}\\label{sec:gen_funs}\n\n%Generating functions are power series used to represent sequences of real numbers. It is often easier to work with generating functions than with the original sequences.\n%\n%% definition\n%\\begin{definition}\n%The \\emph{generating function} of a sequence $a_0,a_1,a_2,$ of real numbers is the function\n%\\[\n%G(t) = \\sum_{k=0}^{\\infty} a_k t^k,\n%\\]\n%which is defined for every $t\\in\\R$ for which the sum converges.\n%\\end{definition}\n%\n%The sequence can be reconstructed from $G(t)$ by setting \n%\\[\n%\\displaystyle a_n = \\frac{1}{n!} G^{(n)}(0),\n%\\]\n%where $G^{(n)}(t)$ is $n$th derivative of $G(t)$. In particular,\n%\\[\n%G(0) = a_0,\\quad G'(0) = a_1,\\quad G''(0) = a_2,\\quad \\text{and so on.}\n%\\]\n%\n%\nA \\emph{power series} is an infinite series of the form\n\\[\nG(t) = \\sum_{k=0}^{\\infty} a_k t^k.\n\\]\n%If $G(t)<\\infty$ we say that the power series \\emph{converges} at $t$; otherwise we say it \\emph{diverges} at $t$. If $G(t)$ converges at some $t\\neq 0$ (it clearly converges at $t=0$) then there exists a positive number $R>0$ such that $G(t)$ converges for $|t|<R$ and diverges for $|t|>R$. This number is called the \\emph{radius of convergence} of $G$.\n\nPower series can be used to represent sequences of real numbers $a_0,a_1,a_2,\\ldots$, in which case they are often called \\emph{generating functions}. The terms of the sequence can be recovered by repeatedly differentiating the power series and evaluating these derivatives at $t=0$:\n\\[\nG(0) = a_0,\\quad G'(0) = a_1,\\quad G''(0) = 2a_2,\\quad G'''(0) = 6a_3\\quad\\text{and so on.}\n\\]\nIn this way, the power series \\emph{generates} the sequence.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% PGFS\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Probability generating functions}\n\nGenerating functions allow probability distributions to be represented as functions of a single variable. \n\n% definition\n\\begin{definition}\nLet $X$ be a discrete random variable taking values in the range $\\{0,1,2,\\ldots\\}$ and let $f_X$ denote its PMF. The \\emph{probability generating function} (PGF) of $X$ is the generating function of its PMF,\n\\[\nG_X(t) = \\expe(t^X) = \\sum_{k=0}^{\\infty} f_X(k) t^k.\n\\]\n\\end{definition}\n\n\\begin{remark}\nBecause $f$ is a PMF, $G(t)$ converges for all $|t|\\leq 1$ with $G(0) = 0$ and $G(1)=\\sum_{k=0}^{\\infty} f(k) = 1$.\n\\end{remark}\n\nAs the following theorem shows, probability generating functions turn \\emph{sums} of independent random variables into \\emph{products} of independent random variables:\n% theorem\n\\begin{theorem}\\label{thm:PGF_sum_of_independent}\nIf $X$ and $Y$ are independent then $G_{X+Y}(t) = G_X(t)G_Y(t)$.\n\\end{theorem}\n\\begin{proof}\nIf $X$ and $Y$ are independent, then $t^X$ and $t^Y$ are also independent, so \n\\[\nG_{X+Y}(t) = \\expe(t^{X+Y}) = \\expe(t^X t^Y) = \\expe(t^X)\\expe(t^Y) = G_X(t)G_Y(t).\n\\]\n\\end{proof}\n\n\\begin{exercise}\nIf $Y = a + bX$, show that $G_Y(t) = t^a G_X(t^b)$.\n\\begin{answer}\n\\[\nG_Y(t) = \\expe\\big(t^{a+bX}\\big) = t^a \\expe\\big((t^b)^X\\big) = t^a G_X(t^b).\n\\]\n\\end{answer}\n\\end{exercise}\n\n% corollary\n\\begin{corollary}\\label{cor:PGF_sum_of_independent}\nIf $X_1,X_2,\\ldots,X_n$ are independent random variables taking values in the non-negative integers, the PGF of their sum is equal to the product of their individual PGFs,\n\\[\nG_{X_1+X_2+\\ldots+X_n}(t) = G_{X_1}(t)G_{X_2}(t)\\cdots G_{X_n}(t).\n\\]\n\\end{corollary}\n\nThe PGFs of some fundamental discrete distributions on $\\{0,1,2,\\ldots\\}$ are shown in Table~\\ref{tab:pmf_pgf}.\n\\begin{table}[ht]\n\\[\\begin{array}{lclcll}\n\t\t\t\t\t\t\t\t& & \\text{PMF} \t\t\t\t\t& & \\text{PGF}\t\t\t\t\t& \\\\ \\hline\nX\\sim\\text{Bernoulli}(p)\t\t& & p^k(1-p)^{1-k} \t\t\t\t& & 1 - p + pt\t\t\t& \\\\[1ex]\nX\\sim\\text{Binomial}(n,p)\t\t& & \\displaystyle\\binom{n}{k}p^k(1-p)^{n-k} \t& & (1 - p + pt)^n\t\t& \\\\[2ex]\nX\\sim\\text{Geometric}(p)\t\t& & (1-p)^{k}p \t\t\t\t\t& & \\displaystyle\\frac{p}{1-(1-p)t}\t& \\text{for $|t|<(1-p)^{-1}$}\t\\\\[2ex]\nX\\sim\\text{Poisson}(\\lambda)\t& & \\lambda^k e^{-\\lambda}/k! \t& & e^{\\lambda(t-1)} \\\\ \\hline\n\\end{array}\\]\n\\caption{The PGFs of some fundamental discrete distributions.\\label{tab:pmf_pgf}}\n\\end{table}\n\n\\begin{exercise}\nFor each of the distributions shown in Table~\\ref{tab:pmf_pgf} derive the expressions for their PGFs from the corresponding PMFs.\n\\begin{answer}\n\\ben\n% bernoulli\n\\it If $X\\sim\\text{Bernoulli}(p)$, then $\\prob(X=0)=1-p$, $\\prob(X=1)=p$ and $\\prob(X=k)=0$ for all $k\\geq 2$ so\n\\[\nG_X(t)\t= \\sum_{k=0}^\\infty f_X(k) t^k \n\t\t= (1-p)t^0 + pt^1 \n\t\t= 1 - p + pt.\n\\]\n% binomial\n\\it If $X\\sim\\text{Binomial}(n,p)$, it can be written as $X=X_1+X_2+\\ldots+X_n$ where each $X_i$ is independent with $X_i\\sim\\text{Bernoulli}(p)$. Thus by Corollary~\\ref{cor:PGF_sum_of_independent},\n\\[\nG_X(t)\t= G_{X_1+X_2+\\ldots+X_n}(t) \n\t\t= G_{X_1}(t)G_{X_2}(t)\\cdots G_{X_n}(t) \n\t\t= (1 - p + pt)^n.\n\\]\n% geometric\n\\it If $X\\sim\\text{Geometric}(p)$, then $\\prob(X=k) = (1-p)^k p \\text{ for } k=0,1,2,\\ldots$, so \n\\[\nG_X(t)\t= \\sum_{k=0}^\\infty f_X(k) t^k\n\t\t= \\sum_{k=0}^\\infty (1-p)^k p t^k \n\t\t= p\\sum_{k=0}^\\infty \\big[(1-p)t\\big]^k \n\t\t= \\frac{p}{1-(1-p)t} \\quad\\text{ for all } |t|<\\frac{1}{1-p}.\n\\]\nwhere we have used the fact that $\\displaystyle\\sum_{k=0}^{\\infty} r^k = \\frac{1}{1-r}$ for $|r|<1$.\n% poisson\n\\it If $X\\sim\\text{Poisson}(\\lambda)$, then $\\prob(X=k) = \\lambda^k e^{-\\lambda}/x!$ so\n\\[\nG_X(t)\t= \\sum_{k=0}^\\infty f_X(k) t^k\n\t\t= \\sum_{k=0}^{\\infty}\\left(\\frac{\\lambda^k e^{-\\lambda}}{k!}\\right)t^k\n\t\t= e^{-\\lambda}\\sum_{i=1}^\\infty \\frac{(\\lambda t)^k}{k!}\n\t\t= e^{-\\lambda}e^{\\lambda t}\n\t\t= e^{\\lambda(t-1)}.\n\\]\n\\een\n\\end{answer}\n\\end{exercise}\n\n%-----------------------------\n\\subsection{Moments}\n\nThe moments of a distribution can be recoverd by repeatedly computing the derivatives of its PGF and evaluating the resulting expressions at $t=1$.\n% theorem (factorial moments)\n\\begin{theorem}\nLet $G_X^{(n)}(t)$ denote the $n$th derivative of $G_X(t)$. Then\n\\[\nG_X^{(n)}(1) = \\expe\\big[X(X-1)\\ldots(X-n+1)\\big].\n\\]\nThese are called the \\emph{factorial moments} of $X$.\n\\begin{proof}\nTake $t < 1$, and compute the $n$th derivative of $G$ to obtain\n\\begin{align*}\nG^{(n)}(t) \n\t& = \\frac{d^n}{dt^n}\\left[\\sum_{k=0}^{\\infty} t^{k} f_X(k)\\right] \\\\\n\t& = \\sum_{k=0}^{\\infty} \\left[\\frac{d^n}{dt^n} t^{k}\\right] f_X(k) \\\\\n\t& = \\sum_{k=0}^{\\infty} k(k-1)\\cdots(k-n+1)t^{k-n} f_X(k) \\\\\n\t& = \\expe\\big[X(X-1)\\cdots(X-n+1)t^{X-n} \\big]\n\\end{align*}\nThus $G^{(n)}(1) = \\expe\\big[X(X-1)\\cdots(X-n+1)\\big]$, as required.\n\\end{proof}\n\\end{theorem}\n\n% exercise (mean and variance)\n\\begin{exercise}\nShow that $\\expe(X) = G'_X(1)$ and $\\var(X) = G''_X(1) + G'_X(1) - G'_X(1)^2$.\n\\begin{answer}\n\\begin{align*}\n\\var(X)\n\t& = \\expe(X^2) - \\expe(X)^2 \\\\\n\t& = \\expe\\big[X(X-1) + X\\big] - \\expe(X)^2 \\\\\n\t& = \\expe\\big[X(X-1)\\big] + \\expe(X) - \\expe(X)^2 \\\\\n\t& = G''_X(1) + G'_X(1) - G'_X(1)^2.\n\\end{align*}\n\\end{answer}\n\\end{exercise}\n\n%-----------------------------\n\\subsubsection{Sums with a random number of terms}\n\n% theorem\n\\begin{theorem}\\label{thm:GF-NofX}\nLet $X_1,X_2,\\ldots$ be independent and identically distributed random variables and let $G_X(t)$ denote their common PGF. Let $N$ be another random variable taking values in the non-negative integers and independent of the $X_i$, and let $G_N(t)$ denote its PGF. Then the PGF of the sum $S_N=X_1+X_2+\\ldots+X_N$ is \n\\[\nG_{S_N}(t) = G_N\\big[G_X(t)\\big].\n\\]\nand its expectation satisfies $\\expe(S_N) = \\expe(N)\\expe(X)$. (This is known as Wald's identity.)\n\\end{theorem}\n\n\\begin{proof}\n\\begin{align*}\nG_{S_N}(t) = \\expe(t^{S_N}) \n\t& = \\expe\\big(\\expe(t^{S_N}\\,|\\,N)\\big) \\text{\\quad(law of total expectation)}\\\\\n\t& = \\sum_{n=0}^{\\infty}\\expe(t^{S_N}\\,|\\,N=n)\\prob(N=n) \\\\\n\t& = \\sum_{n=0}^{\\infty}\\expe(t^{S_n})\\prob(N=n) \\\\\n\t& = \\sum_{n=0}^{\\infty}\\expe(t^{X_1+X_2+\\ldots+X_n}\\,|\\,N=n)\\prob(N=n) \\\\\n\t& = \\sum_{n=0}^{\\infty}\\expe(t^{X_1})\\expe(t^{X_2})\\cdots\\expe(t^{X_n})\\prob(N=n) \\quad\\text{(by independence)}\\\\\n\t& = \\sum_{n=0}^{\\infty}G_X(t)^n\\prob(N=n) \\\\\n\t& = G_N\\big[G_X(t)\\big].\n\\end{align*}\nTo find $\\expe(S_N)$, we find $G_{S_N}(t)$ then evaluate its first derivative at $t=1$.\n\\[\n\\frac{d}{dt}\\big[G_{S_N}(t)\\big]\n\t= \\frac{d}{dt}\\big[G_N\\big(G_X(t)\\big)\\big] \n\t= \\frac{dG_N(u)}{du}\\times\\frac{du}{dt}\n\t\\quad\\text{where $u=G_X(t)$.}\n\\]\nSetting $t=1$ so that $u=G_X(1)=1$,\n\\[\n\\expe(S_N) = G'_{S_N}(1) = \\big[G'_N(1)\\big]\\big[G'_X(1)\\big] = \\expe(N)\\expe(X).\n\\]\n\\end{proof}\n\n% example: compound distribution\n\\begin{example}\nA hen lays $N$ eggs where $N$ has Poisson distribution with parameter $\\lambda$. If each egg hatches independently with probability $p$ show that the total number of chicks has Poisson distribution with parameter $\\lambda p$.\n\\end{example}\n\\begin{solution}\nLet $S_N = X_1+X_2+\\ldots+X_N$ denote the total number of chicks. Each $X_i$ has $\\text{Bernoulli}(p)$ distribution; let $G_X(t)$ denote their common generatig function. Then\n\\[\nG_X(t) = 1 - p + pt \\qquad\\text{and}\\qquad G_N(t) = e^{\\lambda(t-1)},\n\\]\nso by Theorem~\\ref{thm:GF-NofX}, \n\\[\nG_{S_N}(t) = G_N\\big[G_X(t)\\big] = e^{\\lambda(-p+pt)} = e^{\\lambda p(t-1)}\n\\]\nwhich we recognise as the PGF of the $\\text{Poisson}(\\lambda p)$ distribution. Note that by Corollary~\\ref{cor:GF-NofX}, the expected number of chicks is $\\expe(S_N) = \\expe(N)\\expe(X) = \\lambda p$, which is the expected value of the $\\text{Poisson}(\\lambda p)$ distribution.\n\\end{solution}\n\n\\begin{exercise}\n\\begin{questions}\n\\question\nLet $X\\sim\\text{Binomial}(m,p)$ and $Y\\sim\\text{Binomial}(n,p)$ be independent. Show that $X+Y\\sim\\text{Binomial}(m+n,p)$.\n\\begin{answer}\nThe PGFs of $X$ and $Y$ are\n\\[\nG_X(t) = (1-p+pt)^m\n\\quad\\text{and}\\quad\nG_Y(t) = (1-p+pt)^n\n\\]\nUsing the properties of PGFs,\n\\[\nG_{X+Y}(t) = G_X(t)G_Y(t) = (1-p+pt)^m (1-p+pt)^n = (1-p+pt)^{m+n},\n\\]\nwhich we recognise as the PGF of the $\\text{Binomial}(m+n,p)$ distribution.\n\\end{answer}\n\n\\question\nLet $X\\sim\\text{Poisson}(\\lambda)$ and $Y\\sim\\text{Poisson}(\\mu)$ be independent. Show that $X+Y\\sim\\text{Poisson}(\\lambda+\\mu)$.\n\\begin{answer}\nThe PGFs of $X$ and $Y$ are respectively $G_X(t)= e^{\\lambda(t-1)}$ and $G_Y(t) = e^{\\mu(t-1)}$, so the PGF of $Z=X+Y$ is \n\\[\nG_Z(t) = G_X(t)G_Y(t) = e^{(\\lambda+\\mu)(t-1)}.\n\\]\nWe recognise this as the PGF of a $\\text{Poisson}(\\lambda+\\mu)$ random variable, so by the inversion theorem for PGFs, $Z\\sim\\text{Poisson}(\\lambda+\\mu)$.\n\\end{answer}\n\n\\question % GS 5.2.4\nLet $X\\sim\\text{Binomial}(n,p)$. Using the PGF of $X$, show that \n\\[\n\\expe\\left(\\frac{1}{1+X}\\right) = \\frac{1-(1-p)^{n+1}}{(n+1)p}.\n\\]\n\n\\begin{answer}\nLet $G(t)$ be the PGF of $X$. Then $G(t)=\\expe(t^X) = (q+pt)^n$ where $q=1-p$. \n\nNow\n\\[\n\\int_0^1 t^x\\,dt = \\left[\\frac{t^{1+x}}{1+x}\\right]_0^1 = \\frac{1}{1+x},\n\\]\nso\n\\[\n\\expe\\left(\\frac{1}{1+X}\\right) \n\t= \\expe\\left(\\int_0^1 t^X \\,dt\\right)\n\t= \\int_0^1 \\expe(t^X)\\,dt \n\t= \\int_0^1 (q+pt)^n\\,dt\n\t= \\frac{1-q^{n+1}}{(n+1)p}\n\\]\n\\end{answer}\n\n\\end{questions}\n\\end{exercise}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% MGFS\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Moment generating functions}\n\n% definition\n\\begin{definition}\nThe \\emph{moment generating function} (MGF) of a random variable $X$ is the function \n\\[\n\\begin{array}{rccl}\nM_X:\t& \\R\t& \\to\t\t& [0,\\infty] \\\\\n\t\t& t\t\t& \\mapsto\t& \\expe(e^{tX})\n\\end{array}\n\\]\n\\end{definition}\n\nBecaaus $e^{tX}$ is non-negative, its expectation is well-defined and $\\expe(e^{tX})\\geq 0$. It may however be that $\\expe(e^{tX})$ is infinite, which limits the usefulness of MGFs in some cases.\n\n\\begin{theorem}\nIf $X$ takes only non-negative integer values then $M_X(t) = G_X(e^t)$ where $G_X$ is the PGF of $X$.\n\\end{theorem}\n\\begin{proof}\n\\[\nM_X(t) = \\expe(e^{tX}) = \\expe\\big[(e^t)^X\\big] = G_X(e^t),\n\\]\n\\end{proof}\n\n% example: discrete (easy)\n\\begin{example}\nThe MGFs of some fundamental discrete distributions on $\\{0,1,2,\\ldots\\}$ can be computed as follows:\n\\[\n\\begin{array}{llll}\nX\\sim\\text{Bernoulli}(p):\\quad\t& G_X(t) = 1 - p + pt\\quad\t&\\quad\\Rightarrow\\quad & M_X(t) =  1 - p + pe^t\t\t\\\\[2ex]\nX\\sim\\text{Binomial}(n,p):\t\t& G_X(t) = (1-p+pt)^n\t\t\t&\\quad\\Rightarrow\\quad & M_X(t) = (1 - p + pe^t)^n\t\\\\[2ex]\nX\\sim\\text{Poisson}(\\lambda):\t& G_X(t) = e^{\\lambda(t-1)}\t&\\quad\\Rightarrow\\quad & M_X(t) = e^{\\lambda(e^t-1)}\t\\\\ \n\\end{array}\n\\]\n\\end{example}\n\n\n% theorem\n\\begin{theorem}[Properties of MGFs]\\label{thm:props_mgfs}\n\\ben\n\\it If $X$ and $Y$ are independent, then $M_{X+Y}(t) = M_X(t)M_Y(t)$.\n\\it If $Y = a + bX$, then $M_Y(t) = e^{at} M_X(bt)$\n\\een\n\\begin{proof}\n\\ben\n\\it By independence, \n\\[\nM_{X+Y}(t) = \\expe(e^{t(X+Y)}) = \\expe(e^{tX}e^{tY}) = \\expe(e^{tX})\\expe(e^{tY}) = M_X(t)M_Y(t).\n\\]\n\\it For $Y=a+bX$, \n\\[\nM_Y(t) = \\expe\\big(e^{t(a+bX)}\\big) = e^{at}\\expe\\big(e^{btX}\\big) = e^{at}M_X(bt).\n\\]\n\\een\n\\end{proof}\n\\end{theorem}\n\n\\begin{corollary}\\label{cor:mgfs_for_sums}\nIf $X_1,X_2,\\ldots,X_n$ are independent random variables, \n\\[\nM_{X_1+X_2+\\ldots+X_n}(t) = M_{X_1}(t)M_{X_2}(t)\\cdots M_{X_n}(t).\n\\]\n\\begin{proof}\nIf $X_1,X_2,\\ldots,X_n$ are independent, $e^{tX_1},e^{tX_2},\\ldots,e^{tX_n}$ are also independent, so\n\\begin{align*}\nM_{X_1+X_2+\\ldots+X_n}(t)\n\t& = \\expe(e^{t(X_1+x_2+\\ldots+X_n)}) \\\\\n\t& = \\expe(e^{tX_1})\\expe(e^{tX_2})\\ldots\\expe(e^{tX_n}) \\quad\\text{(by independence)}\\\\\n\t& = M_{X_1}(t)M_{X_2}(t)\\cdots M_{X_n}(t)\n\\end{align*}\t\n\\end{proof}\n\\end{corollary}\n\n%\n%\n%\\begin{example}\n%Find the MGFs of the $\\text{Bernoulli}(p)$ and $\\text{Binomial}(n,p)$ distributions.\n%\\begin{solution}\n%\\bit\n%\\it\n%For $X\\sim\\text{Bernoulli}(p)$, $\\prob(X=0)=1-p$ and $\\prob(X=1)=p$ (and zero otherwise) so\n%\\[\n%M_X(t)\t= \\expe(e^{tX}) = (1-p)e^0 + pe^t = 1 - p + pe^t.\n%\\]\n%\\it\n%If $X\\sim\\text{Binomial}(n,p)$ it can be written as $X=X_1+X_2+\\ldots+X_n$, where each $X_i$ is independent with $X_i\\sim\\text{Bernoulli}(p)$. Thus by Corollary~\\ref{cor:mgfs_for_sums},\n%\\[\n%M_X(t)\t= M_{X_1+X_2+\\ldots+X_n}(t) \n%\t\t= M_{X_1}(t)M_{X_2}(t)\\cdots M_{X_n}(t) \n%\t\t= (1 - p + pe^t)^n.\n%\\]\n%\\eit\n%\\end{solution}\n%\\end{example}\n%\n%The MGFs of some discrete distributions are shown in Table~\\ref{tab:mgfs}.\n%\\begin{table}[ht]\n%\\[\\begin{array}{lclcll}\n%Distribution\t\t\t\t\t& & \\text{PMF} \t\t\t\t\t& & \\text{MGF}\t\t\t\t\t& \\\\ \\hline\n%X\\sim\\text{Bernoulli}(p)\t\t& & p^k(1-p)^{1-k} \t\t\t\t& & 1 - p + pe^t\t\t\t& \\\\[1ex]\n%%X\\sim\\text{Binomial}(n,p)\t\t& & \\displaystyle\\binom{n}{k}p^k(1-p)^{n-k} \t& & (1 - p + pe^t)^n\t\t& \\\\[2ex]\n%X\\sim\\text{Geometric}(p)\t\t& & (1-p)^{k}p \t\t\t\t\t& & \\displaystyle\\frac{p}{1-(1-p)e^t}\t& \\text{for $|t|<(1-p)^{-1}$}\t\\\\[2ex]\n%X\\sim\\text{Poisson}(\\lambda)\t& & \\lambda^k e^{-\\lambda}/k! \t& & e^{\\lambda(e^t-1)} \\\\ \\hline\n%\\end{array}\\]\n%\\caption{MGFs of some discrete distributions\\label{tab:mgfs}}\n%\\end{table}\n\n% example\n\\begin{example}[Normal distribution]\\label{exa:mgf_normal}\nBy first considering the MGF of the $N(0,1)$ distribution, show that the MGF of the $N(\\mu,\\sigma^2)$ distribution is given by\n\\[\nM_X(t) = \\exp\\left(\\mu t + \\frac{1}{2}\\sigma^2t^2\\right).\n\\]\n\\end{example}\n\n\\begin{solution}\nLet $Z\\sim N(0,1)$ be a standard normal variable; this has PDF\n\\[\nf_Z(z) = \\frac{1}{\\sqrt{2\\pi}}e^{-\\frac{1}{2}z^2}\\qquad (z\\in\\R).\n\\]\nIts MGF is therefore given by\n\\[\nM_Z(t) = \\expe(e^{tZ})\n\t = \\int_{-\\infty}^{\\infty} e^{tz} f_Z(z)\\,dz \n\t = \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} e^{tz-\\frac{1}{2}z^2}\\,dz \n\\]\nThe exponent $tz-\\frac{1}{2}z^2$ can be written as $\\frac{1}{2}t^2 -\\frac{1}{2}(z-t)^2$, so\n\\begin{align*}\nM_Z(t)\n\t& = \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} e^{\\frac{1}{2}t^2} e^{-\\frac{1}{2}(z-t)^2}\\,dz \\\\\n\t& = e^{\\frac{1}{2}t^2} \\left(\\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} e^{-\\frac{1}{2}(z-t)^2}\\,dz\\right) \n\t= e^{\\frac{1}{2}t^2}.\n\\end{align*}\n\nLet $X=\\mu+\\sigma Z$. Then $X\\sim N(\\mu,\\sigma^2)$ and by the properties of MGFs,\n\\[\nM_X(t) = e^{\\mu t}M_Z(\\sigma t) = e^{\\mu t}e^{\\frac{1}{2}\\sigma^2t^2}= e^{\\mu t + \\frac{1}{2}\\sigma^2t^2},\n\\]\nas required.\n\\end{solution}\n\n\\begin{exercise}\n\\begin{questions}\n\n\\question\nLet $X\\sim\\text{Geometric}(p)$ be the distribution of the number of failures before the first success in a sequence of independent Bernoulli trials in which the probability of success is $p$. Show that $M_X(t) = p/\\big[1-(1-p)e^t\\big]$ for $|t|<-\\log(1-p)$.\n\\begin{answer}\nFor $X\\sim\\text{Geometric}(p)$, $\\prob(X=k) = (1-p)^k p \\text{ for } k=0,1,2,\\ldots$, so \n\\[\nM_X(t)\t= \\sum_{k=1}^\\infty e^{tk}\\prob(X=k)\n\t\t= \\sum_{k=1}^\\infty (1-p)^k p e^{tk}\n\t\t= p\\sum_{k=1}^\\infty \\big[(1-p)e^t\\big]^k \n\t\t= \\frac{pe^t}{1-(1-p)e^t} \\quad\\text{ for all } t < -\\log(1-p).\n\\]\nwhere we have used the fact that $\\sum_{k=0}^{\\infty} r^k = \\frac{1}{1-r}$ for $|r|<1$.\n\\end{answer}\n\n\\question\nLet $X\\sim\\text{Poisson}(\\lambda)$. Show that $M_X(t) = e^{\\lambda(e^t-1)}$.\n\\begin{answer}\nFor $X\\sim\\text{Poisson}(\\lambda)$, $\\prob(X=k) = \\lambda^k e^{-\\lambda}/x!$ so\n\\[\nM_X(t)\t= \\sum_{k=0}^\\infty e^{tk}\\prob(X=k)\n\t\t= \\sum_{k=0}^{\\infty}\\left(\\frac{\\lambda^k e^{-\\lambda}}{k!}\\right)e^{tk}\n\t\t= e^{-\\lambda}\\sum_{i=1}^\\infty \\frac{(\\lambda e^t)^k}{k!}\n\t\t= e^{-\\lambda}e^{\\lambda e^t}\n\t\t= e^{\\lambda(e^t-1)}.\n\\]\n\\end{answer}\n\\end{questions}\n\\end{exercise}\n\n%-----------------------------\n%\\subsubsection{Moments}\n\n% theorem\n\\begin{theorem}\\label{thm:taylor_mgf}\nIf $M_X(t)$ converges in some neighbourhood of $0$ then\n\\[\nM_X(t) = \\sum_{k=0}^{\\infty} \\frac{\\expe(X^k)}{k!} t^k.\n\\]\n\\begin{proof}\nUsing the series expansion of $e^{tX}$ and the linearity of expectation,\n\\[\nM_X(t) \n\t= \\expe(e^{tX}) \n\t= \\expe\\left(\\sum_{k=0}^{\\infty} \\frac{(tX)^k}{k!}\\right)\n\t= \\sum_{k=0}^{\\infty} \\frac{\\expe(X^k)}{k!} t^k\n\\]\n\\end{proof}\n\\end{theorem}\n\nThe moments of a distribution can be recovered from its MGF by repeated differentiation.\n\n\\begin{corollary}\nLet $X$ be a random variable and let $M_X(t)$ be its MGF. Then \n\\[\n\\expe(X^k) = M_X^{(k)}(0)\n\\]\nwhere $M_X^{(k)}(0)$ is the $k$th derivative of $M_X(t)$ evaluated at $t=0$. \n\\end{corollary}\n\n% example: exponential\n\\begin{example}[Exponential distribution]\nLet $X\\sim\\text{Exponential}(\\lambda)$ where $\\lambda>0$ is a rate parameter. \n\\ben\n\\it Show that $M_X(t)=\\displaystyle\\frac{\\lambda}{\\lambda-t}$.\n\\it Use $M_X(t)$ to find the mean and variance of $X$.\n\\een\n\\end{example}\n\n\\begin{solution}\n\\ben\n\\it % << (i)\nThe PDF of $X$ is $f(x)=\\lambda e^{-\\lambda x}$ for $x>0$ (and zero otherwise), so\n\\begin{align*}\nM_X(t) \n\t= \\int_0^\\infty e^{tx} f(x)\\,dx \n\t= \\lambda \\int_0^\\infty e^{tx} e^{-\\lambda x}\\,dx \n\t& = \\lambda \\int_0^\\infty e^{-(\\lambda-t)x}\\,dx \\\\\n\t& = \\frac{-\\lambda}{\\lambda-t} \\left[e^{-(\\lambda-t)x}\\right]_0^\\infty\n\t= \\frac{\\lambda}{\\lambda-t}.\n\\end{align*}\n\\it % << (ii)\n\\bit\n\\it $M'(t) = \\displaystyle \\frac{\\lambda}{(\\lambda-t)^2}$, which yields $\\mu_1 = M'(0)  = \\displaystyle\\frac{1}{\\lambda}$.\n\\it $M''(t) = \\displaystyle \\frac{2\\lambda}{(\\lambda-t)^3}$ which yields $\\mu_2 = M''(0)  = \\displaystyle\\frac{2}{\\lambda^2}$.\n\\it Thus $\\sigma^2 = \\mu_2 - \\mu_1^2 = \\displaystyle\\frac{1}{\\lambda^2}$.\n\\eit\n\\een\n\\end{solution}\n\n%%-----------------------------\n%\\subsection{Inversion}\n%\n%If the MGF of a random variable converges in some neighbourhood of $0$, the distribution of the random variable is uniquely specified by its MGF. Moreover if another random variable has the same MGF then both random variables have the same distribution. This is encapsulated in the following theorem (which we shall not prove).\n%\n%\\begin{theorem}[Inversion theorem for MGFs]\n%\\ben\n%\\it If $M_X(t)<\\infty$ in some neighbourhood of $0$, then $M_X$ uniquely determines the distribution of $X$.\n%\\it If $M_X(t) = M_Y(t)$ in some neighbourhood of $0$, then $X$ and $Y$ have the same distribution.\n%\\een\n%\\end{theorem}\n%\n%Most distributions we encounter are uniquely determined by their MGFs (a notable exception is the \\emph{Cauchy distribution}). It is not always easy however to recover a PMF/PDF by explicitly inverting the associated MGF. Instead they are usually inverted by inspection, where we compare the MGF in question with the known MGFs of various standard distributions.\n%\n%\\begin{example}\n%Let $X\\sim\\text{Binomial}(m,p)$ and $Y\\sim\\text{Binomial}(n,p)$ be independent. Show that $X+Y\\sim\\text{Binomial}(m+n,p)$,\n%\\begin{solution}\n%\\begin{align*}\n%M_{X+Y}(t) \t& = M_X(t)M_Y(t) \\\\\n%\t\t\t& = (1-p+pe^t)^m (1-p+pe^t)^n \\\\\n%\t\t\t& = (1-p+pe^t)^{m+n}.\n%\\end{align*}\n%We recognise this as the MGF of the $\\text{Binomial}(m+n,p)$ distribution. The result then follows by the inversion theorem for MGFs.\n%\\end{solution}\n%\\end{example}\n\n%-----------------------------\n\\begin{exercise}\n\\begin{questions}\n\n\\question % gamma\nLet $X\\sim\\text{Gamma}(\\alpha,\\beta)$ where $\\beta$ is a rate parameter. Find the MGF of $X$ and use this to show that $\\expe(X)=\\alpha/\\beta$ and $\\var(X)=\\alpha/\\beta^2$. \n\\begin{answer}\nLet $X\\sim\\text{Gamma}(\\alpha,\\beta)$. The PDF is\n\\[\nf(x) =  \\frac{\\beta^{\\alpha}}{\\Gamma(\\alpha)}\\, x^{\\alpha-1} e^{-\\beta x}\n\\quad\\text{where}\\quad\n\\Gamma(\\alpha) = \\int_0^{\\infty} t^{\\alpha-1}e^{-t}\\,dt\n\\]\nfor $x>0$, and zero otherwise. The MGF is\n\\begin{align*}\nM(t) = \\expe(e^{tX})\n\t = \\int_{-\\infty}^\\infty e^{tx} f(x)\\,dx \n\t& = \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}\\int_0^\\infty e^{tx} x^{\\alpha-1}e^{-\\beta x}\\,dx \\\\\n\t& = \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}\\int_0^\\infty x^{\\alpha-1}e^{-(\\beta-1)x}\\,dx \\\\\n\t& = \\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}\\frac{1}{(\\beta-t)^{\\alpha}}\\int_0^\\infty x^{\\alpha-1}e^{-u}\\,du \\\\\n\t& = \\left(\\frac{\\beta}{\\beta-t}\\right)^\\alpha.\n\\end{align*}\nElementary calculus yields \n\\[\nM'(t) = \\frac{\\alpha\\beta^\\alpha}{(\\beta-t)^{\\alpha+1}}\n\\quad\\text{and}\\quad\nM''(t) = \\frac{\\alpha(\\alpha+1)\\beta^\\alpha}{(\\beta-t)^{\\alpha+2}}. \n\\]\nEvaluating these at $t=0$, we get $\\expe(X)\t= \\alpha/\\beta$ and $\\expe(X^2)=\\alpha(\\alpha+1)/\\beta^2$, and hence \n$\\var(X)=\\alpha(\\alpha+1)/\\beta^2$ as required.\n\\end{answer}\n\n\\question % two poisson\nLet $X\\sim\\text{Poisson}(\\lambda)$ and $Y\\sim\\text{Poisson}(\\mu)$ be independent. Show that $X+Y\\sim\\text{Poisson}(\\lambda+\\mu)$.\n\\begin{answer}\nThe PGFs of $X$ and $Y$ are respectively $G_X(t)= e^{\\lambda(t-1)}$ and $G_Y(t) = e^{\\mu(t-1)}$, so the PGF of $Z=X+Y$ is \n\\[\nG_{X+Y}(t) = G_X(t)G_Y(t) = e^{\\lambda(t-1)}e^{\\mu(t-1)} = e^{(\\lambda+\\mu)(t-1)}.\n\\]\nwhich we recognise as the MGF of the $\\text{Poisson}(\\lambda+\\mu)$ distribution. (The result follows by the inversion theorem.)\n\\end{answer}\n\n\n\\question % two normal\nLet $X\\sim N(\\mu_1,\\sigma_1^2)$ and $Y\\sim N(\\mu_2,\\sigma_2^2)$ be independent. Show that \n$\nX+Y \\sim N(\\mu_1+\\mu_2,\\sigma_1^2+\\sigma_2^2).\n$\n\\begin{answer}\nBecause $X$ and $Y$ are independent, \n\\begin{align*}\nM_{X+Y}(t)\t\n\t& = M_X(t)M_Y(t) \\\\\n\t& = \\big[e^{\\mu_1 t + \\frac{1}{2}\\sigma_1^2t^2}\\big]\\big[e^{\\mu_2 t + \\frac{1}{2}\\sigma_2^2t^2}\\big] \\text{(as calculated in Example~\\ref{exa:mgf_normal})} \\\\\n\t& = e^{(\\mu_1+\\mu_2) t + \\frac{1}{2}(\\sigma_1^2+\\sigma_2^2)t^2} \\\\\n\\end{align*}\nWe recognise this as the MGF of the normal distribution with mean $\\mu_1+\\mu_2$ and variance $\\sigma_1^2+\\sigma_2^2$. By the inversion theorem for MGFs, we conclude that $X+Y \\sim N(\\mu_1+\\mu_2,\\sigma_1^2+\\sigma_2^2)$.\n\\end{answer}\n\n\\question % mixture\nLet $X$ and $Y$ be independent random variables and let $Z$ be equal to $X$ with probability $p$, and equal to $Y$ with probability $1-p$. Use the law of total expectation to show that\n\\[\nM_Z(t) = pM_X(t) + (1-p)M_Y(t).\n\\]\n\\begin{answer}\nBy the law of total expectation,\n\\begin{align*}\nM_Z(t)\n\t& = \\expe(e^{tZ}) \\\\\n\t& = \\expe(e^{tZ}|\\text{$X$ chosen})\\prob(\\text{$X$ chosen}) + \\expe(e^{tZ}|\\text{$Y$ chosen})\\prob(\\text{$Y$ chosen})  \\\\\n\t& = \\expe(e^{tX})\\prob(\\text{$X$ chosen}) + \\expe(e^{tY})\\prob(\\text{$Y$ chosen})  \\\\\n\t& = pM_X(t) + (1-p)M_Y(t).\n\\end{align*}\n\\end{answer}\n\n\\end{questions}\n\\end{exercise}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CFS\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Characteristic functions}\n%----------------------------------------------------------------------\n\nMGFs can be useful but the expectations that define them may be infinite or not even defined (a notable example is the Cauchy distribution). Characteristic functions do not suffer this disadvantage.\n\n% definition\n\\begin{definition}\nThe \\emph{characteristic function} (CF) of a random variable $X$ is the function \n\\[\n\\begin{array}{rccl}\n\\phi_X:\t& \\R\t& \\to\t\t& \\C \\\\\n\t\t& t\t\t& \\mapsto\t& \\expe(e^{itX})\n\\end{array}\n\\]\n\\end{definition}\n\n% fourier\n\\begin{remark}\n\\bit\n\\it $\\phi(t) = \\expe(\\cos tX)+ i\\expe(\\sin tX)$.\n\\it $\\phi:\\R\\to\\C$ exists for all $t\\in\\R$.\n\\it $\\phi(t) = M(it)$ provided the latter exists.\n\\eit\n\\end{remark}\n\n%The proof of the next result follows that of Theorem~\\ref{thm:props_mgfs}\n%-------------------------\n% theorem\n\\begin{theorem}[Properties of characteristic functions]\\label{thm:properties_cf}\n\\ben\n%\\it $\\phi(0)=1$ and $|\\phi(t)|\\leq 1$ for all $t$.\n\\it If $X$ and $Y$ are independent then $\\phi_{X+Y}(t) = \\phi_X(t)\\phi_Y(t)$.\n\\it If $Y = a + bX$ then $\\phi_Y(t) = e^{iat}\\phi_X(bt)$\n\\een\n\\end{theorem}\n\n% proof\n\\begin{proof}\n\\ben\n\\it % << (i)\n$\\phi(0)=\\expe(e^0)=\\expe(1) = 1$, and \n$\\displaystyle |\\phi(t)| = \\left|\\int e^{itx}\\,dF(x)\\right| \\leq \\int |e^{itx}|\\,dF(x) = 1$.\n\\it % << (ii)\nBy independence, $\\phi_{X+Y}(t) = \\expe(e^{it(X+Y)}) = \\expe(e^{itX}e^{itY})$, and since \n\\[\ne^{itX} = \\cos(tX) + i\\sin(tX)\\quad\\text{and}\\quad e^{itY} = \\cos(tY) + i\\sin(tY),\n\\]\nwe see that \n\\[\ne^{itX}e^{itY} = \\big[\\cos(tX)\\cos(tY) - \\sin(tX)\\sin(tY)\\big] + i\\big[\\cos(tX)\\sin(tY) + \\sin(tX)\\cos(tY)\\big]\n\\]\nTaking the expectation of both sides, and using the fact that $X$ and $Y$ are independent, \n\\begin{align*}\n\\phi_{X+Y}(t) \n\t& = \\expe\\big(\\cos(tX)+i\\sin(tX)\\big)\\expe\\big(\\cos(tY)+i\\sin(tY)\\big) \\\\\n\t& = \\expe(e^{itX})\\expe(e^{itY}) \\\\\n\t& = \\phi_X(t)\\phi_Y(t).\n\\end{align*}\n\\it % << (ii)\n$\\phi_Y(t) \n\t= \\expe\\big(e^{it(a+bX)}\\big) \n\t= \\expe\\big(e^{iat}e^{i(bt)X}\\big) \n\t= e^{iat}\\expe(e^{i(bt)X}) \n\t= e^{iat}\\phi_X(bt)$.\n\\een\n\\end{proof}\n\n\n%-----------------------------\n%\\subsubsection{Inversion and continuity}\nThe next two theorems are needed to prove the central limit theorem.\n\nThe \\emph{inversion theorem} states that the distribution a random variable is uniquely determined by its CF, and if another random variable has the same CF then they both have the same distribution. \n\n\\begin{theorem}[Inversion theorem for CFs]\n\\ben\n\\it $\\phi_X$ uniquely determines the distribution of $X$.\n\\it If $\\phi_X(t) = \\phi_Y(t)$ in some neighbourhood of $0$ then $X$ and $Y$ have the same distribution.\n\\een\n\\end{theorem}\n%\\proofomitted\n\nIt is not always easy to recover a distribution by explicitly inverting the associated CF. Instead they are usually inverted by inspection, where we compare the CF in question with the CFs of various standard distributions.\n\n\\begin{example}\nLet $X\\sim\\text{Binomial}(m,p)$ and $Y\\sim\\text{Binomial}(n,p)$ be independent. Show that $X+Y\\sim\\text{Binomial}(m+n,p)$,\n\\begin{solution}\n\\begin{align*}\n\\phi_{X+Y}(t) \t\n\t& = M_X(t)M_Y(t) \\\\\n\t& = (1-p+pe^{it})^m (1-p+pe^{it})^n \\\\\n\t& = (1-p+pe^{it})^{m+n}.\n\\end{align*}\nWe recognise this as the CF of the $\\text{Binomial}(m+n,p)$ distribution. The result then follows by the inversion theorem for CFs.\n\\end{solution}\n\\end{example}\n\nThe \\emph{continuity theorem} states that a sequence of distributions $F_1,F_2,\\ldots$ converges to a limiting distribution $F$ if and only if the corresponding sequence of characteristic functions $\\phi_1,\\phi_2,\\ldots$ converges to the characteristic function of $F$.\n\n%% convergence in distribution\n%\\begin{definition}\n%A sequence $F_1,F_2,\\ldots$ of CDFs is said to \\emph{converge} to $F$, denoted by $F_n\\to F$, if $F_n(x)\\to F(x)$ as $n\\to\\infty$ for each point $x$ at which $F$ is continuous. \n%\\end{definition}\n\n% theorem: continuity\n\\begin{theorem}[Continuity theorem for CFs]\nLet $F_1,F_2,\\ldots$ and $F$ be CDFs and let $\\phi_1,\\phi_2,\\ldots$ and $\\phi$ be the corresponding CFs. \nThen $F_n\\to F$ if and only if $\\phi_n\\to\\phi$ as $n\\to\\infty$.\n%\\ben\n%\\it If $F_n\\to F$ then $\\phi_n(t)\\to\\phi(t)$ for all $t$.\n%\\it If $\\phi_n(t)\\to\\phi(t)$ for all $t$ then $F_n\\to F$.\n%\\een\n\\end{theorem}\n%\\proofomitted\n\n\n\n\n", "meta": {"hexsha": "e30bc80facb752cbf96f4ba8b8adbab1423ed929", "size": 27729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/06A_generating_functions.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/06A_generating_functions.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/06A_generating_functions.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 37.2201342282, "max_line_length": 363, "alphanum_fraction": 0.6218038876, "num_tokens": 11072, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396141, "lm_q2_score": 0.8807970779778824, "lm_q1q2_score": 0.7931839948392907}}
{"text": "\\section{Orbitals}\n\\subsection{Normalisation of Primitive Contractions}\n\nConsider a generic primitive function,\n%\n\\begin{equation}\n\t\\phi_\\mu(\\mathbf{r}) = N x^\\ell y^m z^n \\exp\\Big[ -\\alpha \\mathbf{r}\\cdot \\mathbf{r} \\Big]\\,,\n\\end{equation}\n%\nwhere $N$ is an as yet undetermined normalisation constant. The normalisation condition is given by\n%\n\\begin{align}\n\t\\int^\\infty_{-\\infty} d\\mathbf{r} \\phi_\\mu^*(\\mathbf{r})\\phi_\\mu(\\mathbf{r}) &= 1 \\\\\n    N^2 \\int_{-\\infty}^{\\infty} d\\mathbf{r} x^{2\\ell} y^{2m} z^{2n} \\exp\\Big[ -2\\alpha \\mathbf{r}\\cdot\\mathbf{r} \\Big] &= 1 \\\\\n    N^2 \\int_{-\\infty}^\\infty dx x^{2\\ell} \\int_{-\\infty}^\\infty dy y^{2m} \\int_{-\\infty}^\\infty dz z^{2n} \\exp\\Big[ -2\\alpha \\mathbf{r}\\cdot\\mathbf{r} \\Big] &= 1 \\,,\n\\end{align}\n%\nwhere we have split $d\\mathbf{r} = dxdydz$. Further, the exponential can be split into a product of \nexponentials in the three Cartesian degrees of freedom\n%\n\\begin{equation}\\label{eq::Normalisation}\n\tN^2 \\int_{-\\infty}^\\infty dx x^{2\\ell} \\exp\\Big[ -2\\alpha x^2 \\Big] \\int_{-\\infty}^\\infty dy y^{2m} \\exp\\Big[ -2\\alpha y^2 \\Big] \\int_{-\\infty}^\\infty dz z^{2n} \\exp\\Big[ -2\\alpha z^2 \\Big]  = 1\\,.\n\\end{equation}\n%\nThe individual integrals can be evaluated in closed form. The integral with respect to $dx$, for \ninstance, can we written\n%\n\\begin{equation}\n\t\\int_{-\\infty}^\\infty dx x^{2\\ell} \\exp\\Big[ -2\\alpha x^2 \\Big] = \\sqrt{\\frac{\\pi}{2\\alpha}} \\frac{(2\\ell - 1)!!}{(4\\alpha)^\\ell}\\,.\n\\end{equation}\n%\nThe integrals with respect to $dy$ and $dz$ have similar solutions. Then, we can write \n\\eqref{eq::Normalisation} as\n%\n\\begin{equation}\n\tN^2 \\Bigg(\\frac{\\pi}{2\\alpha}\\Bigg)^{3/2} \\frac{(2\\ell - 1)!!}{(4\\alpha)^\\ell} \\frac{(2m - 1)!!}{(4\\alpha)^m}\\frac{(2n - 1)!!}{(4\\alpha)^n} = 1\\,.\n\\end{equation}\n%\nRearranging, the normalisation constant is given by\n%\n\\begin{align}\n\tN^2 &= \\Bigg( \\frac{2\\alpha}{\\pi} \\Bigg)^{3/2} \\frac{(4\\alpha)^{\\ell + m + n}}{(2\\ell - 1)!!(2m - 1)!!(2n - 1)!!} \\nonumber \\,, \\\\\n    N &= \\Bigg( \\frac{2\\alpha}{\\pi} \\Bigg)^{3/4} \\sqrt{\\frac{(4\\alpha)^{\\ell + m + n}}{(2\\ell - 1)!!(2m - 1)!!(2n - 1)!!}}\\,.\n\\end{align}\n%\nLet us take the trivial example of $\\ell = m = n = 0$ (note that $(-1)!! = 1$), where $N$ \nreduces to \n%\n\\begin{equation}\n\tN = \\Bigg( \\frac{2\\alpha}{\\pi} \\Bigg)^{3/4} \\sqrt{\\frac{(4\\alpha)^0}{(-1)!!(-1)!!(-1)!!}} = \\Bigg( \\frac{2\\alpha}{\\pi} \\Bigg)^{3/4}\\,.\n\\end{equation}\n\n\n\\subsection{Laplacian of Contracted Gaussian Atomic Orbitals}\n%\nConsider a Contracted Gaussian Atomic Orbital (CGO), $\\Psi$, which is centred on \n$\\mathbf{R} = \\big[ \\begin{array}{ccc} X & Y & Z \\end{array}\\big]^\\top$, and is a function of \nthe electronic position vector, $\\mathbf{r} = \\big[ \\begin{array}{ccc} x & y & z \\end{array}\\big]^\\top$. \n$\\Psi(\\mathbf{r}, \\mathbf{R})$ takes the form of a linear combination of $N$ primitive Gaussian functions\n%\n\\begin{equation}\n\t\\Psi(\\mathbf{r,R}) = (x - X)^\\ell (y - Y)^m (z - Z)^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i |\\mathbf{r-R}|^2 \\Big] \\,.\n\\end{equation}\n%\nBy changing our coordinate system so that $\\mathbf{R}$ is the origin, we can omit the difference \ncoordinates and write\n%\n\\begin{equation}\n\t\\Psi(\\mathbf{r}) = x^\\ell y^m z^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\,,\n\\end{equation}\n%\nwhere $r^2 = \\mathbf{r}\\cdot \\mathbf{r}$. Since the Laplacian is the divergence of the gradient, \n$\\nabla \\cdot \\nabla$, we can evaluate $\\nabla^2 \\Psi(\\mathbf{r})$ by consecutive operation of $\\nabla$. \nFor the sake of simplicity, we consider the action of $\\nabla_x^2$ on $\\Psi(\\mathbf{r})$ and save the \ngeneralisation for later. A key identity used throughout is\n%\n\\begin{displaymath}\n\t\\frac{d}{dx} \\exp\\Big[ -\\zeta_i r^2 \\Big] = -2x \\exp\\Big[ -\\zeta_i r^2 \\Big] \\,,\n\\end{displaymath}\n%\nwhich can be derived trivially. First, by the product theorem\n%\n\\begin{equation}\n\t\\nabla_x \\Psi(\\mathbf{r}) = \\ell x^{\\ell-1} y^m z^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] - 2x^{\\ell+1}y^m z^n \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\,.\n\\end{equation}\n%\nDealing with the action of $\\nabla_x$ on the first term,\n%\n\\begin{align}\\label{eq::FirstTerm}\n\t\\nabla_x \\Big(  \\ell x^{\\ell-1} y^m z^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\Big) &= \\ell(\\ell-1)x^{\\ell-2} y^m z^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\nonumber \\\\\n    &- 2 \\ell x^\\ell y^m z^n \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\,.\n\\end{align}\n%\nSimilarly, the action of $\\nabla_x$ on the second term\n%\n\\begin{align}\\label{eq::SecondTerm}\n\t\\nabla_x \\Big( 2x^{\\ell+1} y^m z^n \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\Big) &= 2(\\ell+1)x^\\ell y^m z^n \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\nonumber \\\\\n    &- 4x^{\\ell+2} y^m z^n \\sum_{i=1}^N \\zeta_i^2 c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\,.\n\\end{align}\n%\nCombining \\eqref{eq::FirstTerm} and \\eqref{eq::SecondTerm}, we are left with $\\nabla^2_x \\Psi(\\mathbf{r})$\n%\n\\begin{align}\n\t\\nabla^2_x \\Psi(\\mathbf{r}) &= \\ell(\\ell-1)x^{\\ell-2} y^m z^n \\sum_{i=1}^N c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] +  4x^{\\ell+2} y^m z^n \\sum_{i=1}^N \\zeta_i^2 c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\\\ \n    &- 2(2\\ell+1)x^\\ell y^m z^n \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\,.\n\\end{align}\n%\nBy replacing $ f_i(r) = c_i \\exp\\Big[ \\zeta_i r^2 \\Big]$ for the sake of clarity,\n%\n\\begin{equation}\n    \\nabla^2_x \\Psi(\\mathbf{r})= \\ell(\\ell-1)x^{\\ell-2} y^m z^n \\sum_{i=1}^n f_i(r) + 4x^{\\ell+2} y^m z^n \\sum_{i=1}^N \\zeta_i^2 f_i(r) - 2(2\\ell+1)x^\\ell y^m z^n \\sum_{i=1}^N \\zeta_i f_i(r) \\,.\n\\end{equation}\n%\nFurther, we introduce the notation $F_0(r) = \\sum_{i=1}^N f_i(r)$, $F_1(r) = \\sum_{i=1}^N \\zeta_i f_i(r)$ \nand $F_2(r) = \\sum_{i=1}^N \\zeta_i^2 f_i(r)$, so that\n%\n\\begin{equation}\n    \\nabla^2_x \\Psi(\\mathbf{r})= \\ell(\\ell-1)x^{\\ell-2} y^m z^n F_0(r) + 4x^{\\ell+2} y^m z^n F_2(r) - 2(2\\ell+1)x^\\ell y^m z^n F_1(r) \\,.\n\\end{equation}\n%\nIt should be obvious to the reader that expressions for $\\nabla^2_y \\Psi(\\mathbf{r})$ and \n$\\nabla^2_z \\Psi(\\mathbf{r})$ can be given in entirely equivalent manners, so that\n%\n\\begin{align}\n\t&\\nabla^2_y \\Psi(\\mathbf{r})= m(m-1)x^\\ell y^{m-2} z^n F_0(r) + 4x^\\ell y^{m+2} z^n F_2(r) - 2(2m+1) x^\\ell y^m z^n F_1(r) \\\\\n    &\\nabla^2_z \\Psi(\\mathbf{r})= n(n-1)x^\\ell y^{m} z^{n-2} F_0(r) + 4x^\\ell y^{m} z^{n+2} F_2(r) - 2(2n+1) x^\\ell y^m z^n F_1(r) \\,.\n\\end{align}\n%\nBy summing $\\Big( \\nabla^2_x + \\nabla^2_y + \\nabla^2_z \\Big)\\Psi(\\mathbf{r})$, we then have \nthe Laplacian of the CGO\n%\n\\begin{align}\n\t\\nabla^2 \\Psi(\\mathbf{r}) &= \\Big[ \\ell(\\ell-1)x^{\\ell-2} y^m z^n + m(m-1)x^\\ell y^{m-2} z^n + n(n-1)x^\\ell y^{m} z^{n-2} \\Big] F_0(r) \\nonumber \\\\\n    & + 4\\Big[x^{\\ell+2} y^m z^n + x^\\ell y^{m+2} z^n + x^\\ell y^{m} z^{n+2} \\Big] F_2(r) \\nonumber \\\\\n    &- \\Big[ 4(\\ell + m + n) + 6 \\Big] x^\\ell y^m z^n F_1(r) \\,.\n\\end{align}\n%\nConsider the case where $\\ell = m = n = 0$. Only the functions of $F_2(r)$ and $F_1(r)$ \nare non-zero. The coefficient of $F_1(r)$ is $6$ while that of $F_2(r)$ is $4(x^2 + y^2 + z^2) = 4r^2$. \nThen\n%\n\\begin{align}\n\t\\nabla^2 \\Psi(\\mathbf{r}) &= 4r^2 F_2(r) - 6 F_1(r) \\nonumber \\\\\n    &= 4r^2 \\sum_{i=1}^N \\zeta_i^2 c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] - 6 \\sum_{i=1}^N \\zeta_i c_i \\exp \\Big[ -\\zeta_i r^2 \\Big] \\nonumber \\\\\n    &= 2 \\sum_{i=1}^N c_i \\Big( 2\\zeta_i^2 r^2 - 3\\zeta_i \\Big) \\exp\\Big[ -\\zeta_i r^2 \\Big] \\,.\n\\end{align}\n%\nAny atomic orbitals of higher angular momentum necessitate the consideration of a number of \nadditional terms.\n", "meta": {"hexsha": "64f06591b9b9da847beaadc97f5a194f3fe884c7", "size": 7413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/manual/sections/orbitals.tex", "max_stars_repo_name": "savcardamone/tyche-", "max_stars_repo_head_hexsha": "ea89edea89a607291e4fe0ba738d75522f54dc1a", "max_stars_repo_licenses": ["MIT"], "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/manual/sections/orbitals.tex", "max_issues_repo_name": "savcardamone/tyche-", "max_issues_repo_head_hexsha": "ea89edea89a607291e4fe0ba738d75522f54dc1a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-28T13:30:16.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-29T10:30:33.000Z", "max_forks_repo_path": "doc/manual/sections/orbitals.tex", "max_forks_repo_name": "savcardamone/tyche", "max_forks_repo_head_hexsha": "ea89edea89a607291e4fe0ba738d75522f54dc1a", "max_forks_repo_licenses": ["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.42, "max_line_length": 198, "alphanum_fraction": 0.6090651558, "num_tokens": 3347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527684, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7931436926949176}}
{"text": "\\subsection{Matrix Calculus}\n\nThe chain rule for a vectors is similar to the chain rule for scalars. Except the order is important. For $\\mathbf{z} = f(\\mathbf{y})$ and $\\mathbf{y} = g(\\mathbf{x}) $ the chain rule is:\n\\begin{equation}\n    \\frac{\\partial \\mathbf{z}}{\\partial \\mathbf{x}} = \\frac{\\partial \\mathbf{y}}{\\partial \\mathbf{x}}     \\frac{\\partial \\mathbf{z}}{\\partial \\mathbf{y}}\n\\end{equation}\n\n\n\n\n\\begin{table}[h]\n    \\centering\n    \\begin{tabular}{cc}\n        \\toprule\n            $y$ & $\\frac{\\partial}{\\partial x} y$ \\\\\n        \\midrule\n            $Ax$     & $A^T$ \\\\\n            $x^T A$  & $A$   \\\\\n            $x^T x$  & $2x$  \\\\  \n            $x^T Ax$ & $Ax + A^Tx$  \\\\          \n        \\bottomrule\n    \\end{tabular}\n    \\caption{Useful derivatives equations}\n\\end{table}\n\n\n\\subsection{Fix-Point Arithmetic}\n\nMultiplication of two fix point values yields \n\\begin{equation}\n\tv_1 v_2 = \\text{right-shift}\\left( Q_1 Q_2 \\cdot 2^{-(m+m)} ; m\\right)\n\\end{equation}\nNote that for multiplication the exponent $m$ for the values can be different.\n\nAddition of two fix point values\n\\begin{equation}\n\tv_1 + v_2 = \\left( Q_1 + Q_2 \\right) \\cdot 2^{-m}\n\\end{equation}", "meta": {"hexsha": "5529134d69262db0a96f00db869e313c7de269b9", "size": 1174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/documentation/09_matrixcalculus.tex", "max_stars_repo_name": "marbleton/FPGA_MNIST", "max_stars_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-13T12:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-31T02:39:35.000Z", "max_issues_repo_path": "tex/documentation/09_matrixcalculus.tex", "max_issues_repo_name": "marbleton/FPGA_MNIST", "max_issues_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2019-12-17T22:06:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:20:45.000Z", "max_forks_repo_path": "tex/documentation/09_matrixcalculus.tex", "max_forks_repo_name": "marbleton/FPGA_MNIST", "max_forks_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:12:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-13T13:36:37.000Z", "avg_line_length": 30.8947368421, "max_line_length": 187, "alphanum_fraction": 0.597955707, "num_tokens": 394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7931436860447555}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For the following pairs of matrices, determine if the sum $A+B$\n  and the difference $A-B$ are defined. If so, calculate them.\n  \\begin{enumerate}\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix}$,\\quad\n    $B = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0\n    \\end{mymatrix}$.\n\n  \\item\n    $A = \\begin{mymatrix}{rrr}\n      2 & 1 & 2 \\\\\n      1 & 1 & 0\n    \\end{mymatrix}$,\\quad\n    $B = \\begin{mymatrix}{rrr}\n      -1 & 0 & 3 \\\\\n      0 & 1 & 4\n    \\end{mymatrix}$.\n\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      -2 & 3 \\\\\n      4 & 2\n    \\end{mymatrix}$,\\quad\n    $B = \\begin{mymatrix}{rrr}\n      2 & 7 & -1 \\\\\n      0 & 3 & 4\n    \\end{mymatrix}$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  For each matrix $A$, find the matrix $-A$.\n  \\begin{enumerate}\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      1 & 2 \\\\\n      2 & 1\n    \\end{mymatrix}$\n\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      -2 & 3 \\\\\n      0 & 2\n    \\end{mymatrix}$\n\n  \\item\n    $A = \\begin{mymatrix}{rrr}\n      0 & 1 & 2 \\\\\n      1 & -1 & 3 \\\\\n      4 & 2 & 0\n    \\end{mymatrix}$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrr}\n    1 & 2 & -1 \\\\\n    -1 & 4 & 0 \\\\\n  \\end{mymatrix}$ and\n  $B = \\begin{mymatrix}{rrr}\n    0 & 3 & 0 \\\\\n    1 & -1 & 1 \\\\\n  \\end{mymatrix}$.\\par\\noindent\n  Find a matrix $X$ such that $(A+X)-(B+0) = B+A$. Hint: first use\n  the properties of matrix addition to simplify the equation and\n  solve for $X$.\n  \\begin{sol}\n    The equation simplifies to $X=B+B$, so $X = \\begin{mymatrix}{rrr}\n    0 & 6 & 0 \\\\\n    2 & -2 & 2 \\\\\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{add-inv-rst-unique}\n  Using only the properties given in\n  Proposition~\\ref{prop:properties-of-addition}, show that if $A+B=0$, then\n  $B=-A$.\n  \\begin{sol}\n    Suppose $A+B=0$. Then we have\n    $-A = (-A)+0 = (-A)+(A+B) = ((-A)+A)+B = (A+(-A))+B = 0+B = B+0 =\n    B$.  Here, we have used the additive unit law, the assumption\n    $A+B=0$, associativity, commutativity, the additive inverse law,\n    commutativity, and the additive unit law, in that order.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Using only the properties given in\n  Proposition~\\ref{prop:properties-of-addition}, show $A+B=A$ implies $B=0$.\n  \\begin{sol}\n    Suppose $A+B=A$. Then $B=B+0=0+B=(A+(-A))+B = ((-A)+A)+B =\n    (-A)+(A+B) = (-A)+A = A+(-A) = 0$. Here, we have used the additive\n    unit law, commutativity, the additive inverse law, commutativity,\n    associativity, the assumption $A+B=A$, commutativity, and the\n    additive inverse law, in that order.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "1652f96ff1c81c8b2a7cd4e8e8da2f5c30fa47b4", "size": 2660, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-Addition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-Addition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-Addition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 24.1818181818, "max_line_length": 76, "alphanum_fraction": 0.5413533835, "num_tokens": 1062, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206738932334, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.7929206392915166}}
{"text": "\\documentclass[11pt]{article}\n\n\n\\usepackage{amsfonts}\n\\usepackage{fancyvrb}\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 Knapsack}\n\\normalsize\n\n\n\\section{Problem Statement}\n\nIn this assignment you will design an algorithm to solve the infamous {\\em Knapsack Problem}, which plagues Indiana Jones.  You are provided with a knapsack with limited space and a collection of items with different values and weights.  Your task is to maximize the value of items packed into your knapsack without exceeding its total capacity.\n\n\\section{Assignment}\n\nWrite an algorithm to solve the knapsack problem.  The problem is mathematically formulated in the following way.  Given $n$ items to choose from, each item $i \\in 0 \\ldots n-1$ has a value $v_i$ and a weight $w_i$.  The knapsack has a limited capacity $K$.  Let $x_i$ be a variable that is $1$ if you choose to take item $i$ and $0$ if you leave item $i$ behind. Then the knapsack problem is formalized as the following optimization problem,\n$$\n\\begin{array}{ll}\n\\mbox{maximize:} & \\displaystyle \\sum_{i \\in 0 \\ldots n-1} v_i x_i \\\\\n\\mbox{subject to:} & \\\\\n     & \\displaystyle \\sum_{i \\in 0 \\ldots n-1} w_i x_i \\leq K \\\\\n     & x_i \\in \\{0,1\\} \\;\\;\\; (i \\in 0 \\ldots n-1)\n\\end{array}\n$$\n\n\\section{Data Format Specification}\n\nA knapsack input contains $n+1$ lines.  The first line contains two integers, the first is the number of items in the problem, $n$.  The second number is the capacity of the knapsack, $K$.  The remaining lines present the data for each of the items.  Each line, $i \\in 0 \\ldots n-1$ contains two integers, the item's value $v_i$ followed by its weight $w_i$.\n\n\\vspace{0.2cm}\n\\noindent\nInput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\nn K\nv_0 w_0\nv_1 w_1\n...\nv_n-1 w_n-1\n\\end{Verbatim}\n%\nThe output contains a knapsack solution and is made of two lines.  The first line contains two values $obj$ and $opt$.  $obj$ is the total value of the items selected to go into the knapsack (i.e. the objective value).  $opt$ should be $1$ if your algorithm proved optimality and $0$ otherwise.  The next line is a list of $n$ $0/1$-values, one for each of the $x_i$ variables.  This line encodes the solution.\n\\clearpage\n%\n\\vspace{0.2cm}\n\\noindent\nOutput Format\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\nobj opt\nx_0 x_1 x_2 ... x_n-1\n\\end{Verbatim}\n%\nIt is essential that the value order in the solution output matches the value order of the input.  Otherwise the grader will misinterpret the output.\n\n\\paragraph{Examples} \\mbox{}\n%\\vspace{0.1cm}\n\n\\vspace{0.2cm}\n\\noindent\nInput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n4 11\n8 4\n10 5\n15 8\n4 3\n\\end{Verbatim}\n\n\\vspace{0.2cm}\n\\noindent\nOutput Example\n\\vspace{-0.2cm}\n\\begin{Verbatim}[frame=single]\n19 0\n0 0 1 1\n\\end{Verbatim}\n\n\\section{Instructions}\n\n%Edit \\texttt{solver.py} and modify the \\texttt{solveIt(inputData)} function to solve the knapsack problem.  The function argument, \\texttt{inputData}, contains a knapsack problem in the format described above.  The return value of \\texttt{solveIt} is a solution to the problem in the output format described above.  Your \\texttt{solveIt} implementation can be tested with the command, \n%\\[ \n%\\texttt{python ./solver.py ./data/<inputFileName>} \n%\\] \n%You should limit the \\texttt{solveIt} method to terminate within 5 hours, otherwise the submission will not be eligible for full credit.  You may choose to implement your solver directly in python or modify the \\texttt{solveIt()} function to call an external application.\n\n\\input{instructions.tex}\n\n\\paragraph{Resources}\nYou will find several knapsack instances in the \\texttt{data} directory provided with the handout.  \\texttt{Solver.java} and \\texttt{solverJava.py} are included in this assignment to demonstrate how to implement your assignment in another language.  If you wish to use the Java solver, you will need to rename \\texttt{solverJava.py} to \\texttt{solver.py}.\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{Warnings} \n%\n%\\begin{enumerate}\n%\\item It is recommended you do not modify the \\texttt{data} directory.  Modifying the files in the data directory risks\n%making your assignment submissions incorrect.\n%\\item You cannot rename the \\texttt{solver.py} file.\n%\\item \\texttt{solver.py} must remain in the same directory as  \\texttt{submit.pyc}.\n%\\end{enumerate}\n\n\\input{techReqs.tex}\n\n\\end{document}\n\n\n\n\n", "meta": {"hexsha": "2f27c13f287b77650fd303dcbfcb31ea61e9f326", "size": 4896, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "handouts/knapsack.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/knapsack.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/knapsack.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": 34.7234042553, "max_line_length": 442, "alphanum_fraction": 0.746119281, "num_tokens": 1462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424217727027, "lm_q2_score": 0.9372107922798332, "lm_q1q2_score": 0.7928263673327155}}
{"text": "\\subsection{Functions of the vertices}\n\\label{sec:vertices}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Vertex surround angle}\n\\label{sec:vertex_surround_angle}\n\n\\paragraph{Non-boundary case}\n\\label{sec:non_boundary_vertex_surround_angle}\n\n\\begin{figure}[!htp]\n\\centering\n\\begin{verbatim}\n                v2/e2 o           o v1/e1\n                       \\   f1    /\n                        \\       /\n                     f2  \\ g1  /   f0\n                          \\ ^ /\n                       g2( \\ / )g0\n             v3/e3 o--------o--------o v0/e0\n                       g3( / \\ )gn-1\n                          / v \\\n                     f3  /     \\  fn-1\n                        /       \\\n                 v4/e4 o   ...   o vn-1/en-1\n\\end{verbatim}\n\\caption{Vertex surround angle.\n\\label{fig:vertex_surround_angle}}\n\\end{figure}\n\nConsider the non-boundary vertex\nlabeled $\\v$ in figure \\ref{fig:vertex_surround_angle}.\n$\\v$ has degree $n$;\nthe incident edges are labeled $\\e_0, \\e_1, \\ldots, \\e_{n-1}$;\nthe incident faces are labeled $\\f_0, \\f_1, \\ldots, \\f_{n-1}$;\nand the neighboring vertices are labeled $\\v_0, \\v_1, \\ldots, \\v_{n-1}$.\nThe angle between edges $\\e_j$ and $\\e_{j + 1 \\bmod n}$ is $\\gamma_j$.\n\n$\\gamma_j = \\gamma(\\f_j,\\v)$ is the {\\em corner angle} in face $\\f_j$\nof vertex $\\v$.\n\nThe {\\em surround angle} of $\\v$ is the sum of all its corner angles:\n\\begin{equation}\n\\alpha(\\v) = \\sum_{j=0}^{n-1} \\gamma(\\f_j,\\v),\n\\end{equation}\n\nIf the neighborhood of $\\v$ is flat, then $\\alpha(\\v)=2\\pi$.\nA neighborhood with $\\alpha(\\v) < 2\\pi$, corresponds very roughly\nto positive Gaussian curvature,\nand, $\\alpha(\\v) > 2\\pi$,\nis analogous to negative Gaussian curvature.\nHowever, it's important to remember that, unlike the case\nwith smooth surfaces, where the most complicated local\nshape is a saddle,\nthe crinkling of a vertex neighborhood can be arbitrarily complicated,\nfor any non-zero surround angle.\n\nAlthough a mesh with all surround angles of $2\\pi$ is not guaranteed\nto be flat,\na mesh with surround angles different from $2\\pi$ is guaranteed\nto be not-flat,\nand, in some sense,\nthe more different the surround angles are from $2\\pi$\nthe more non-flat is the mesh.\nThis leads to the following as a mesh roughness measure:\n\\begin{eqnarray}\nf(\\M)\n& = & \\sum_{\\v \\in \\V(\\M)} \\left[ \\alpha(\\v) - 2\\pi \\right]^2\n\\\\\n& = & \\sum_{\\v \\in \\V(\\M)}\n\\left[ \\left(\\sum_{\\f \\in \\F(\\v)} \\gamma(\\f,\\v)\\right)\n - 2\\pi \\right]^2\n\\nonumber\n\\end{eqnarray}\nThe natural implementation of this function is to first compute\nall the corner angles and cache them with the faces,\nthen compute the surround angles and cache with each vertex,\nand then do a lookup while computing the sum.\n\nIn computing the gradient, it's simplest to re-arrange the\norder of summation:\n\\begin{eqnarray}\n\\Ga{f}\n& = & \\Ga{ \\left[ \\sum_{\\v \\in \\V(\\M)} \\left[ \\alpha(\\v) - 2\\pi \\right]^2 \\right]}\n\\\\\n& = & 2 \\sum_{\\v \\in \\V(\\M)} \\left[ \\alpha(\\v) - 2\\pi \\right] \\Ga{\\alpha(\\v)}\n\\nonumber\n\\\\\n& = & 2 \\sum_{\\v \\in \\V(\\M)} \\left[ \\alpha(\\v) - 2\\pi \\right]\n\\sum_{\\f \\in \\F(\\v)} \\Ga{\\gamma(\\f,\\v)}\n\\nonumber\n\\\\\n& = & 2 \\sum_{\\v \\in \\V(\\M)}\n\\sum_{\\f \\in \\F(\\v)}\n\\left[ \\alpha(\\v) - 2\\pi \\right]\n\\Ga{\\gamma(\\f,\\v)}\n\\nonumber\n\\\\\n& = & 2\n\\sum_{\\f \\in \\F(\\M)}\n\\sum_{\\v \\in \\V(\\f)}\n\\left[ \\alpha(\\v) - 2\\pi \\right]\n\\Ga{\\gamma(\\f,\\v)}\n\\nonumber\n\\\\\n& = & 2\n\\sum_{\\f \\in \\F(\\M)}\n\\sum_{i=0}^2\n\\left[ \\alpha(\\v_i(\\f)) - 2\\pi \\right]\n\\Ga{\\gamma(\\p_i(\\f),\\p_{i+1 \\% 2}(\\f),\\p_{i+2 \\% 3}(\\f))}\n\\nonumber\n\\end{eqnarray}\n\nConsider the partial gradient with respect to\nlocation of one of the vertices:\n\\begin{eqnarray}\n\\label{eq:surround_angle_partial_gradient}\n\\Gc{\\p_j}{f}{q}\n& = 2 \\sum_{\\f \\in \\F(\\M)} &\n\\sum_{i=0}^2\n\\left[ \\alpha(\\v_i(\\f)) - 2\\pi \\right]\n\\Gc{\\p_j}{\\gamma(\\p_i(\\f),\\p_{i+1 \\% 2}(\\f),\\p_{i+2 \\% 3}(\\f))}{\\q}\n\\\\\n& = 2 \\sum_{\\f \\in \\F(\\v_j)} &\n\\sum_{i=0}^2\n\\left[ \\alpha(\\v_i(\\f)) - 2\\pi \\right]\n\\Gc{\\p_j}{\\gamma(\\p_i(\\f),\\p_{i+1 \\% 2}(\\f),\\p_{i+2 \\% 3}(\\f))}{\\q}\n\\nonumber\n\\\\\n& = 2 \\sum_{\\f \\in \\F(\\v_j)} & \\left(\n\\left[ \\alpha({\\mathrm p}(\\v_j,\\f) - 2\\pi \\right]\n\\Gc{\\p_j}{\\gamma({\\mathrm p}(\\p_j,\\f),\\p_j,{\\mathrm s}(\\p_j,\\f))}{\\q}\n\\right.\n\\nonumber\n\\\\\n& & +\n\\left[ \\alpha(\\v_j) - 2\\pi \\right]\n\\Gc{\\p_j}{\\gamma(\\p_j,{\\mathrm s}(\\p_j,\\f),{\\mathrm p}(\\p_j,\\f)}{\\q}\n\\nonumber\n\\\\\n& & +\n\\left.\n\\left[ \\alpha({\\mathrm s}(\\v_j,\\f) - 2\\pi \\right]\n\\Gc{\\p_j}{\\gamma({\\mathrm s}(\\p_j,\\f),{\\mathrm p}(\\p_j,\\f),\\p_j)}{\\q}\n\\right)\n\\nonumber\n\\end{eqnarray}\nwhere ${\\mathrm p}(\\v,\\f)$ is $\\v$'s {\\em predecessor},\nthe vertex that comes before $\\v$ in the oriented face $\\f$,\n${\\mathrm s}(\\v_j,\\f)$ the {\\em successor}\nthe vertex that comes after $\\v$,\nand similarly for the vertex positions $\\p$.\n\nConsider the term corresponding to a particular face $\\f$ in\nthe sum in equation \\ref{eq:surround_angle_partial_gradient}.\nCall that face's vertices and positions $\\v_0, \\v_1, \\v_2$\nand $\\p_0, \\p_1, \\p_2$.\n\\begin{eqnarray}\n\\Gc{\\p_0}{f_{\\f}}{q}\n& = &\n\\left[ \\alpha(\\v_0) - 2\\pi \\right] \\Gc{\\p_0}{\\gamma(\\p_0,\\p_1,\\p_2)}{\\q}\n\\\\\n& + &\n\\left[ \\alpha(\\v_1) - 2\\pi \\right] \\Gc{\\p_0}{\\gamma(\\p_1,\\p_2,\\p_0)}{\\q}\n\\nonumber\n\\\\\n& + &\n\\left[ \\alpha(\\v_2) - 2\\pi \\right] \\Gc{\\p_0}{\\gamma(\\p_2,\\p_0,\\p_1)}{\\q}\n\\nonumber\n\\\\\n&  &\n\\nonumber\n\\\\\n& = &\n\\left[ \\alpha(\\v_0) - 2\\pi \\right]\n{{(\\q_1 - \\q_0) \\perp (\\q_2 - \\q_0) + (\\q_2 - \\q_0) \\perp (\\q_1 - \\q_0)}\n\\over\n{\n\\sqrt{\n\\| \\q_2 - \\q_0 \\|^2 \\| \\q_1 - \\q_0 \\|^2\n-\n\\left( ( \\q_1 -\\q_0 ) \\bullet ( \\q_2 -\\q_0 ) \\right)^2\n}\n}}\n\\nonumber\n\\\\\n& - &\n\\left[ \\alpha(\\v_1) - 2\\pi \\right]\n{{(\\q_0 - \\q_1) \\perp (\\q_2 - \\q_1)}\n\\over\n{\n\\sqrt{\n\\| \\q_0 - \\q_1 \\|^2 \\| \\q_2 - \\q_1 \\|^2\n-\n\\left( ( \\q_0 -\\q_1 ) \\bullet ( \\q_2 - \\q_1 ) \\right)^2\n}\n}}\n\\nonumber\n\\\\\n& - &\n\\left[ \\alpha(\\v_2) - 2\\pi \\right]\n{{(\\q_0 - \\q_2) \\perp (\\q_1 - \\q_2)}\n\\over\n{\n\\sqrt{\n\\| \\q_0 - \\q_2 \\|^2 \\| \\q_1 - \\q_2 \\|^2\n-\n\\left( ( \\q_0 -\\q_2 ) \\bullet ( \\q_1 -\\q_2 ) \\right)^2\n}\n} }\n\\nonumber\n\\end{eqnarray}\n", "meta": {"hexsha": "0512b1a13f9b31bc92dd329b6e933e33735a6854", "size": 5892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/vertices.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/vertices.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/vertices.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.5327102804, "max_line_length": 82, "alphanum_fraction": 0.5680583842, "num_tokens": 2374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.7927489569754397}}
{"text": "\n\\subsection{Units}\n\nA unit is an element of a ring which has a multiplicative inverse.\n\\subsubsection{Examples}\n\nThe ring of integers with addition and multiplication, only \\(-1\\) and \\(1\\) are units, as both have multiplicative inverses in the ring.\n\n", "meta": {"hexsha": "0da22c5c000bf0eb19cee47fbd10aaa920cf4e6d", "size": 253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/05-02-units.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-02-units.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-02-units.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.1111111111, "max_line_length": 137, "alphanum_fraction": 0.7628458498, "num_tokens": 59, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9304582477806521, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7927065165575615}}
{"text": "\\section{Methodologies}\n\\label{sec:methodologies}\n\n%Describe correlation matrix (methodology 1) in mathematics\nIn \\textbf{Methodology$_1$} we compute the autocorrelation matrix, also called series correlation, see \\cite{Devore-Berk}, between features to get a first view of the available data and the relationships between them.  To do this we use the autocorrelation matrix that explains the degree of dependence between the values of our features. \nGiven a sequence $x$, the autocorrelation is given by $$R_x_i=Corr(x,x)_i=\\sum_{i=0}^{\\infty}x_i x_{i+1}.$$\n\nIn this project we did not use this formula but simply applied the .corr() function of Pandas.\n\\bigskip\n\n%Describe conditional probability calculation (methodology 2) in mathematics\nIn \\textbf{Methodology$_2$}, we calculate the conditional probability of a response variable given an explanatory variable, $\\dfrac{P(A\\cup B)}{P(B)}$, where deeper explanation can be found at \\cite{Walsh-John-B}. This calculation assumes only a relationship between the single explanatory variable and the response and therefore we note that this calculation does \\emph{not} model joint probability distributions, because the number of features makes it infeasible to model all combinations of them. While this assumption is not true in practice (see discussion of methodology 1 in Section \\ref{sec:Results} for correlation between features), we can nonetheless analyze the likelihood of a given outcome from the perspective of only knowing a single feature (e.g. the chance of death given that one has pneumonia). To give a bound of estimates, we perform this calculation on samples of our dataset, using a sample of a size $N = \\dfrac{Length(Dataset)}{4}$. The data is sampled with replacement (\"bootstrapped\") and the proability is calculated on this sample of the data. We repeat this process 1000 times, and observe the quantiles of the resulting probability estimates to characterize the effect of each explanatory variable on the response. This process is repeated for synthetic, observational, and treatment data, and the details of the calculation $\\dfrac{P(A\\cup B)}{P(B)}$ is performed using the Pandas library (see the github repository for details of the groupby and division functions).\n\n\n\\bigskip\n%Describe logistic regression (methodology 3) in mathematics\nIn \\textbf{Methodology$_3$} we use a logistic regression model to estimate the probability that the input data ($\\textbf{x}$) leads to outcomes ($y_i$), for $i=1, 2, ..., m$, where $m$ is the number of possible labels for the outcome classes and $y_i \\in [0, 1]$. In the data we use, an outcome of $1$ corresponds to death, and $0$ to survival. The probability of the two outcomes is then as follows: $$\\mathbb{P}(y_i=1|x_i, \\beta) = \\frac{e^{\\beta^T x_i}}{1+e^{\\beta^T x_i}}$$\n$$\\mathbb{P}(y_i=0|x_i, \\beta) = 1 - \\mathbb{P}(y_i = 1|x_i, \\beta),$$\n\n\\noindent where $\\beta$ are the coefficients that will be estimated by the model, see \\cite{Geron-Aurelien}. \n\nWe also apply a regularization parameter $\\lambda \\geq 0$, which scales the model parameters. Then, the cost function of the model will be: $$C(\\boldsymbol{\\beta}) = (\\boldsymbol{z} - \\boldsymbol{X\\beta})^T(\\boldsymbol{z} - \\boldsymbol{X\\beta}) + \\lambda \\boldsymbol{\\beta}^T\\boldsymbol{\\beta}$$\n\nWhere \\textbf{X} is the input data and $z$ is the output (true) labels.\n\nWe train the logistic regression models on a balanced set of data points sampled from the full data, in order to ensure that the classifier properly learns to predict each class (rather than e.g. predicting only $Death = 0$ because the vast majority of patients survive). After this selection, we define a pipeline for feature selection and hyper-parameter tuning which is applied in randomized-search cross-validation ($CV=500$). This is to ensure that the model parameters are accurate and that we obtain a range of values with which to estimate them.\n\nThe logistic regression models will then learn coefficient values from the data corresponding to each feature, where higher coefficient values are predictive of death and negative coefficient values are predictive of survival. Lastly, we select the features with the highest and lowest (i.e. greatest absolute value) coefficients to determine which of them are most predictive of symptoms, for both vaccine side-effects as well as treatment effectiveness. \n\nWe implement the model pipeline, logistic regression model itself, and the cross-validation using the \\texttt{statsmodels} package. This is convenient because the library provides functionality to display a model summary, including summary statistics for coefficient values including mean, median, standard deviation error, p-values, and confidence intervals (the last of which we detail in Section \\ref{sec:Results}). The full printout of these results can be obtained by running the code contained in the GitHub repository.\n", "meta": {"hexsha": "9f4ee2b4be1d40ac9a3c4404bcba137ba46b6d0d", "size": 4886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project1/report/content/methodologies.tex", "max_stars_repo_name": "fabiorodp/IN_STK5000_Adaptive_methods_for_data_based_decision_making", "max_stars_repo_head_hexsha": "f8c049ceed6e3123e8676bcd9b29afaba9bd1f9b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "project1/report/content/methodologies.tex", "max_issues_repo_name": "fabiorodp/IN_STK5000_Adaptive_methods_for_data_based_decision_making", "max_issues_repo_head_hexsha": "f8c049ceed6e3123e8676bcd9b29afaba9bd1f9b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "project1/report/content/methodologies.tex", "max_forks_repo_name": "fabiorodp/IN_STK5000_Adaptive_methods_for_data_based_decision_making", "max_forks_repo_head_hexsha": "f8c049ceed6e3123e8676bcd9b29afaba9bd1f9b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-25T14:45:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-25T14:45:41.000Z", "avg_line_length": 157.6129032258, "max_line_length": 1501, "alphanum_fraction": 0.7812116251, "num_tokens": 1142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582497090321, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7927065059590591}}
{"text": "%\n% Chapter 3.4\n%\n\n\\section*{3.4 Limits at Infinity}\n\nLet \\(f\\) be a function defined on some interval \\((a, \\infty)\\). Then\n$$ \\lim_{x \\to \\infty}f(x) = L $$\nmeans that the values of \\(f(x)\\) can be made arbitrarily close to \\(L\\) by requiring \\(x\\) to be sufficiently large.\n\\\\\\\\\nLet \\(f\\) be a function defined on some interval \\((-\\infty, a)\\). Then\n$$ \\lim_{x \\to -\\infty}f(x) = L $$\nmeans that the values of \\(f(x)\\) can be made arbitrarily close to \\(L\\) by requiring \\(x\\) to be sufficiently large negative.\n\n\\subsection*{Horizontal Asymptotes}\n\nThe line \\(y=L\\) is called a \\textbf{horizontal asymptote} of the curve \\(y=f(x)\\) if either\n$$\\lim_{x \\to \\infty}f(x)=L \\quad \\text{or} \\quad \\lim_{x \\to -\\infty}f(x)=L$$\n\n\\subsubsection*{Theorem}\n\nIf \\(r>0\\) is a rational number, then\n$$ \\lim_{x \\to \\infty}\\frac{1}{x^r}=0 $$\nIf \\(r>0\\) is a rational number such that \\(x^r\\) is defined for all \\(x\\), then\n$$ \\lim_{x \\to -\\infty}\\frac{1}{x^r}=0 $$\n\n\\subsection*{Definition of a Limit at Positive Infinity}\n\nLet \\(f\\) be a function defined on some interval \\((a, \\infty)\\). Then\n$$ \\lim_{x \\to \\infty}f(x)=L$$\nmeans that for every \\(\\epsilon>0\\) there is a corresponding number \\(N\\) such that \n$$ \\text{if} \\quad x>N \\quad \\text{then} \\quad \\left| f(x)-L \\right| <\\epsilon $$ \n\n\\subsection*{Definition of a Limit at Negative Infinity}\n\nLet \\(f\\) be a function defined on some interval \\((-\\infty, a)\\). Then\n$$ \\lim_{x \\to -\\infty}f(x)=L$$\nmeans that for every \\(\\epsilon>0\\) there is a corresponding number \\(N\\) such that \n$$ \\text{if} \\quad x<N \\quad \\text{then} \\quad \\left| f(x)-L \\right| <\\epsilon$$ \n\n\\subsection*{Definition of an Infinite Limit at Infinity}\n\nLet \\(f\\) be a function defined on some interval \\((a, \\infty)\\). Then\n$$ \\lim_{x \\to \\infty}f(x)=\\infty$$\nmeans that for every positive number \\(M\\) there is a corresponding positive number \\(N\\) such that \n$$ \\text{if} \\quad x>N \\quad \\text{then} \\quad f(x)>M$$ \n\n", "meta": {"hexsha": "ce9c17dc349fc974df8caf289138cb7a473c41e2", "size": 1940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-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/3-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/3-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": 40.4166666667, "max_line_length": 126, "alphanum_fraction": 0.6458762887, "num_tokens": 647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8723473829749844, "lm_q1q2_score": 0.7926304488308848}}
{"text": "\\section{Green function method}\nLet's do an example.\nConsider the differential equation\n\\begin{align}\n    \\frac{d^2y}{dx^2} + y &= f(x)\n\\end{align}\nBoundary conditions $y=0$ at $x=0$\nand $y=0$ at $x=\\frac{\\pi}{2}$.\nIntroduce the green function $G(x, x')$ which satisfies\n\\begin{align}\n    \\frac{d^2 G}{dx^2} + G &=\n    \\delta\\left( x - x' \\right)\n\\end{align}\nWhy introduce $G$?\nIn general,\n$G$ is easier to find than $y$.\nOnce $G$ has been determined,\nwe can obtain $y$ with\n\\begin{align}\n    y(x) &=\n    \\int_{0}^{\\pi/2}\n    G\\left( x, x' \\right)\n    f\\left( x' \\right)\\,\n    dx'\n\\end{align}\nTo see that this is a solution,\nsubstitute it into the original ODE.\n\\begin{align}\n    \\frac{dd^2 y}{dx^2} + y\n    &=\n    \\int_{0}^{\\pi/2}\n    \\underbrace{\\left\\{ \n    \\frac{d^2 G}{dx^2} + G\n    \\right\\}}_{\n    \\delta\\left( x - x' \\right)\n    }\n    f\\left( x' \\right)\n    \\,dx'\\\\\n    &=\n    f(x).\n\\end{align}\nIt also satisfies boundary conditions\n\\begin{align}\n    y(x=0) &=\n    \\int_{0}^{\\pi/2}\n    \\underbrace{\\left.G\\left( x, x' \\right)\\right|_{x=0}}_{=0}\n    f\\left( x' \\right)\\,dx' = 0\n\\end{align}\nand\n\\begin{align}\n    y\\left( x=\\frac{\\pi}{2} \\right)\n    &=\n    \\int_{0}^{\\pi/2}\n    \\underbrace{\\left.G\\left( x, x' \\right)\\right|_{x=\\pi/2}}_{=0}\n    f\\left( x' \\right)\n    \\,dx'\n    =0\n\\end{align}\nBut how do we find $G$?\n\\begin{align}\n    \\frac{d^2G}{dx^2} + G &= \\delta\\left( x - x' \\right)\n\\end{align}\nAway from $x=x'$,\n\\begin{align}\n    \\frac{d^2 G}{dx^2 + G} = 0\n\\end{align}\nThe solutions are of the form\n\\begin{align}\n    G &=\n    A\\sin(x) + B\\cos(x)\n\\end{align}\nIn general the solution for $x<x'$ and $x>x'$ will be different\nbecause they must satisfy different boundary conditions at each end.\n\\begin{align}\n    G &=\n    \\begin{cases}\n        G_{<} = A_{<}\\sin(x) + B_{<}\\cos(x) & \\text{for } x < x'\\\\\n        G_{>} = A_{>}\\sin(x) + B_{>}\\cos(x) & \\text{for } x > x'\\\\\n    \\end{cases}\n\\end{align}\nRequiring $G=0$ at $x=0$,\nwe get $B_{<}=0$.\nRequiring $G=0$ at $x=\\frac{\\pi}{2}$,\nwe get $A_{>}=0$.\nNow we need match the two pieces across $x'$.\n\nIn quantum mechanics have you solved for a delta function potential?\nNow let's look at this differential equation here.\n\nI claim that this is what we mean.\nI want $G$ to be continuous across the boundary,\nbut $dG/dx$ is not necessarily continuous.\nThat's the way this works for this example.\n\nRequiring that $G$ be continuous at $x=x'$,\nwe have\n\\begin{align}\n    G_{<}\\left( x = x' \\right)\n    =\n    G_{>}\\left( x = x' \\right)\n\\end{align}\nwe get\n\\begin{align}\n    A_{,}\\sin\\left( x' \\right)\n    &=\n    B_{>}\\cos\\left( x' \\right)\n\\end{align}\nBut we need one more condition,\nand that has to come from the derivatives.\nSo what we do is integrate that differential equation for $G$ across $x=x'$.\n\\begin{align}\n    \\lim_{\\epsilon\\to 0}\n    \\int_{x'=\\epsilon}^{x' + \\epsilon}dx\\left\\{ \n    \\frac{d^2 G}{dx^2} + \\underbrace{G}_{O(\\epsilon)}\n    \\right\\}\n    &=\n    \\underbrace{\\int_{x' - \\epsilon}^{x' + \\epsilon}\n    dx\\,\n    \\delta\\left( x - x' \\right)}_{1}\n\\end{align}\nwhich gives\n\\begin{align}\n    \\left.\\frac{dG}{dx}\\right|_{x'-\\epsilon}^{x'+\\epsilon}\n    = 1\n\\end{align}\nwhich means\n\\begin{align}\n    \\left. \\frac{dG_{>}}{dx}\\right|_{x=x'}\n    -\n    \\left. \\frac{dG_{<}}{dx}\\right|_{x=x'}\n    &= 1\\\\\n    -B_{<}\\sin\\left( x' \\right) - A_{<}\\cos\\left( x' \\right) &= 1\n\\end{align}\nWhen all the dust settles,\nthe solution is\n\\begin{align}\n    A_{<} &= -\\cos\\left( x' \\right)\\\\\n    B_{>} &= -\\sin\\left( x' \\right)\n\\end{align}\nHence\n\\begin{align}\n    G\\left( x, x' \\right)\n    &=\n    \\begin{cases}\n        G_{<}\\left( x, x' \\right)\n        =\n        -\\sin\\left( x \\right)\\cos\\left( x' \\right)\n        &\\text{for } x<x'\\\\\n        G_{>}\\left( x, x' \\right)\n        =\n        -\\cos\\left( x \\right)\\sin\\left( x' \\right)\n        &\\text{for } x> x'\n    \\end{cases}\n\\end{align}\nNotice that\n\\begin{align}\n    G\\left( x, x' \\right) &= G\\left( x', x \\right)\n\\end{align}\nYou should check that your Greens function has this property.\nIf it doesn't your probably screwed up.\nIt's a powerful consistency check.\n\nSome people like to write it in shorthand\n\\begin{align}\n    G\\left( x, x' \\right)\n    &=\n    -\\sin\\left( x_{<} \\right)\\cos\\left( x_{>} \\right)\n\\end{align}\nwhere $x_{<}$ refers to the smaller of $x$ and $x'$\nand $x_{.}$ refers to the larger of $x$ and $x'$.\nTo get the final solution\n\\begin{align}\n    y(x) &=\n    \\int_{0}^{\\pi/2}dx'\\,\n    G\\left( x, x' \\right)\n    f\\left( x' \\right)\\\\\n    &=\n    \\int_{0}^{x}\n    dx'\n    f\\left( x' \\right)\n    G_{>}\\left( x, x' \\right)\n    +\n    \\int_{0}^{\\pi/2}dx\\,\n    f\\left( x' \\right)\n    G_{<}\\left( x, x' \\right)\\\\\n    &= -\\cos(\\pi)\\left[ \n    \\int_{0}^{\\pi}dx'\\,\n    f\\left( x' \\right)\n    \\sin\\left( x' \\right)\n    \\right]\n    -\n    \\sin\\left( x \\right)\n    \\left[ \n    \\int_{x}^{\\pi/2}dx'\\,\n    f\\left( x' \\right)\n    \\cos\\left( x' \\right)\n    \\right]\n\\end{align}\nSo that's the solution.\nThis is a standard way to solve inhomogeneous differential equations.\n\nYou've actually been using this method for a long time.\nThe potential from a point charge admits an interpretation as the Green function\nof the Laplacian operator $\\nabla^2$.\nConsider the Poisson equation\n\\begin{align}\n    \\nabla^2\\phi &=\n    -\\frac{\\rho}{\\epsilon_0}\n\\end{align}\nFor a point charge $q$ located at $\\vec{x}'$,\n\\begin{align}\n    \\rho\\left( \\vec{x}' \\right)\n    &=\n    q\\delta^{(3)}\\left( \\vec{x} - \\vec{x}' \\right).\n\\end{align}\nThe resulting potential $\\hat{\\phi}$ satisfies\n\\begin{align}\n    \\nabla^2\\hat{\\phi}\n    &=\n    -\\frac{q}{\\epsilon_0}\n    \\delta^{(3)}\\left( \\vec{x} - \\vec{x}' \\right)\n\\end{align}\nwith\n\\begin{align}\n    \\hat{\\phi}\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\frac{q}{\\left| \\vec{x} - \\vec{x}'\\right|}\n\\end{align}\nBy definition,\nthe Green function for the Laplacian operator is required to satisfy\n\\begin{align}\n    \\nabla^2 G\n    &=\n    -4\\pi \\delta^{(3)}\\left( \\vec{x} - \\vec{x}' \\right)\n\\end{align}\nThis Poisson equations is the kind of equation we're trying to solve.\nWe set up a Greens function,\nreplacing the source term by a delta function,\njust the way we did earlier.\nWe use the same differential operator,\nbut we replace the arbitrary source by a $\\delta$ function.\nThe only difference is the factor of $-4\\pi$.\nPreviously we set it to 1,\nwhich is more standard,\nbut in electrostatics,\nit's just a convention we put a $-4\\pi$ there.\n\nComparing we see that\n\\begin{align}\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    &=\n    \\frac{4\\pi\\epsilon_0}{q}\\hat{\\phi}\n    =\n    \\frac{1}{\\left|\\vec{x} - \\vec{x}'\\right|}\n\\end{align}\nThen the solution of the Poisson equation is\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    -\\frac{1}{4\\pi}\n    \\int d^3\\vec{x}\\,\n    G\\left( x, x' \\right)\n    \\left\\{ \n    -\\frac{\\rho(x)}{\\epsilon_0}\n    \\right\\}\\\\\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int d^3x\n    \\frac{\\rho(x)}{\\left|\\vec{x} - \\vec{x}'\\right|}\n\\end{align}\n\nLet's summarize the results.\nConsider the example we had\n\\begin{align}\n    y'' + y &= f(x)\\\\\n    G'' + G &= \\delta\\left( x - x' \\right)\\\\\n    G\\left( x, x' \\right) &= -\\sin\\left( x_{<} \\right)\\cos\\left( x_{>}\n    \\right)\\\\\n    y &= \\int dx\\, f\\left( x' \\right) G\\left( x, x' \\right)\n\\end{align}\nThe same method applies for electrostatics.\n\\begin{align}\n    \\nabla^2 \\phi &=\n    -\\frac{\\rho\\left( \\vec{x} \\right)}{\\epsilon_0}\\\\\n    \\nabla^2 G &=\n    -4\\pi \\delta^{(3)}\\left( \\vec{x} - \\vec{x}' \\right)\\\\\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    &=\n    \\frac{1}{\\left|\\vec{x} - \\vec{x}'\\right|}\\\\\n    \\phi &=\n    -\\frac{1}{4\\pi}\\int d^3\\vec{x}\\,\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    \\left\\{ \n    \\frac{-\\rho\\left( \\vec{x}' \\right)}{\\epsilon_0}\n    \\right\\}\n\\end{align}\nSo this is the general method for solving linear inhomogeneous differential\nequations.\n$G\\left( \\vec{x}, \\vec{x}' \\right)$\nis the potential from a charge $q=4\\pi\\epsilon_0$\nlocated at $\\vec{x}=\\vec{x}'$.\n\nConsider a charge $q$ near a grounded conducting sphere.\nFor a point charge $q$,\n\\begin{align}\n    \\phi(\\vec{x})\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\left\\{ \n    \\frac{q}{\\left|\\vec{x} - \\vec{x}'\\right|}\n    -\n    \\frac{aq}{\\left|\\vec{x}'\\right|}\n    \\frac{1}{\\left|\\vec{x} - \\frac{a^2}{\\left|\\vec{x}'\\right|^2}\\vec{x}'\\right|}\n    \\right\\}\n\\end{align}\nwhich we obtained by the method of images.\nNow consider \n\\begin{align}\n    \\nabla^2 \\phi\n    &=\n    -\\frac{q\\delta^{(3)}\\left( \\vec{x} - \\vec{x}' \\right)}{\\epsilon_0}\n\\end{align}\nwith boundary conditions\n$\\phi=0$ at $\\left|\\vec{x}\\right|=a$.\n$\\phi=0$ at $\\left|\\vec{x}\\right|=\\infty$.\n\nThen the Green function is\n\\begin{align}\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    &=\n    \\left\\{ \n    \\frac{1}{\\left|\\vec{x} - \\vec{x}'\\right|}\n    -\n    \\frac{a}{\\left|\\vec{x}'\\right|}\n    \\frac{1}{\\left|\n    \\vec{x}\n    -\n    \\frac{a^2}{\\left|\\vec{x}\\right|^2}\n    \\vec{x}'\n    \\right|}\n    \\right\\}\n\\end{align}\nsuch that for a more general charge distribution,\n\\begin{align}\n    \\phi(\\vec{x})\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int d^3\\vec{x}'\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    \\rho\\left(\\vec{x}'\\right)\n\\end{align}\n\nWe need to generalize the Green function method to problems where $\\phI$ or\n$\\vec{E}\\cdot\\hat{r}$ are specified on boundaries.\nStart from Green's theorem.\n\\begin{align}\n    \\int_V\n    \\left( \n    \\phi \\nabla^2 \\psi\n    - \\psi \\nabla^2 \\phi\n    \\right)\n    dV\n    &=\n    \\oint_S\n    \\left[ \n    \\phi\\left( \\vec{\\nabla}\\psi\\cdot\\hat{n} \\right)\n    - \\psi\\left( \\vec{\\nabla}\\phi\\cdot\\hat{n} \\right)\n    \\right]\n    dS\n\\end{align}\nTo prove this is straightforward.\n\\begin{align}\n    \\psi\\nabla^2 \\psi &=\n    \\vec{\\nabla}\\cdot\\left( \n    \\phi\\vec{\\nabla}\\psi\n    \\right)\n    - \\vec{\\nabla}\\psi\n    \\cdot \\vec{\\nabla} \\psi\\\\\n    \\psi\\nabla^2\\phi\n    &=\n    \\vec{\\nabla}\\cdot\\left( \n    \\psi\\vec{\\nabla}\\phi\n    \\right)\n    -\n    \\vec{\\nabla}\\phi\n    \\cdot\\vec{\\nabla}\\cdot\\vec{\\nabla}\\psi\n\\end{align}\nSubtract\n\\begin{align}\n    \\phi\\nabla^2\\psi\n    - \\psi\\nabla^2\\phi\n    &=\n    \\vec{\\nabla}\\cdot\\left( \n    \\phi\\vec{\\nabla}\\psi\n    -\n    \\psi\\vec{\\nabla}\\phi\n    \\right)\n\\end{align}\nIntegrate over volume and apply divergence theorem.\n\nFor $\\phi$ choose the potential.\nFor $\\psi$ choose the Green function $G\\left( \\vec{x}, \\vec{x}' \\right)$.\n\n\\begin{align}\n    \\vec{\\nabla}'^2 G\\left( \\vec{x}, \\vec{x}' \\right)\n    &= -4\\pi \\delta^{(3)}\\left( \\vec{x}' - \\vec{x} \\right)\n\\end{align}\nThen\n\\begin{align}\n    \\int_V \\left[ \n    \\phi\\left( \\vec{x}' \\right)\n    \\underbrace{\n    {\\nabla'}^{2}\n    \\psi\\left( \\vec{x}' \\right)\n    }_{-4\\pi\\delta^{3}\\left( \\vec{x}' - \\vec{x} \\right)}\n    -\n    \\psi\\left( \\vec{x}' \\right)\n    \\underbrace{{\\nabla'}^2 \\phi\\left( \\vec{x}' \\right)}_{\n    -\\rho\\left( \\vec{x}' \\right)/\\epsilon_0\n    }\n    \\right]\n    d^3\\vec{x}'\n    &=\n    \\int \\left[ \n    \\phi\\left( \\vec{x}' \\right)\n    \\left( \n    \\vec{\\nabla}' \\psi\\left( \\vec{x}' \\right) \\cdot \\hat{n}'\n    \\right)\n    -\n    \\psi\\left( \\vec{x}' \\right)\n    \\left( \n    \\vec{\\nabla}' \\phi\\left( \\vec{x}' \\right) \\cdot \\hat{n}'\n    \\right)\n    \\right]\n    dS'\n\\end{align}\nSo\n\\begin{align}\n    \\phi\\left( \\vec{x} \\right)\n    &=\n    \\frac{1}{4\\pi\\epsilon_0}\n    \\int_V\n    \\rho\\left( \\vec{x}' \\right)\n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    d^3\\vec{x}'\n    +\n    \\frac{1}{4\\pi}\n    \\oint_S\n    \\left[ \n    G\\left( \\vec{x}, \\vec{x}' \\right)\n    \\left( \n    \\vec{\\nabla}' \\phi\\left( \\vec{x}' \\right)\\cdot\\hat{n}'\n    \\right)\n    -\n    \\phi\\left( \\vec{x}' \\right)\n    \\left( \n    \\vec{\\nabla}' G\\left( \\vec{x}, \\vec{x}' \\right)\n    \\cdot \\hat{n}'\n    \\right)\n    \\right]\n    dS'\n\\end{align}\n", "meta": {"hexsha": "11246e75a55ef65d00e31e05eafb38f6bf1d59d9", "size": 11467, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/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": "phys610/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": "phys610/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": 24.713362069, "max_line_length": 80, "alphanum_fraction": 0.5662335397, "num_tokens": 4391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8918110511888303, "lm_q1q2_score": 0.7926049217608657}}
{"text": "\\subsection{Principled statistical inference}\n\\begin{frame}{Principle I: the sufficiency principle}\nSufficiency plays a central role in all of Statistics.\n\\begin{defn}[Sufficient statistic]\n Let $x \\sim f(x \\mid \\theta)$.\n We say $T : \\mathcal{X} \\to \\mathbb{R}$ is a \\textbf{sufficient statistic} for the parameter $\\theta$ if $\\pr(X = x \\mid T(x), \\theta)$ is independent of $\\theta$.\n\\end{defn}\nThis is the basis for a cornerstone of Statistics, \n\\begin{theo}[Factorisation theorem]\n Under mild regularity conditions, we can write:\n $$ f(x \\mid \\theta) = g(T(x) \\mid \\theta) h(x \\mid T(x)).$$\n\\end{theo}\nWe can now state\n\\begin{idea}[Sufficiency principle (SP)]\n\\label{idea:SP}\n For $x, y \\in \\mathcal{X}$, if $T$ is sufficient for $\\theta$ and $T(x) = T(y)$, then $x$ and $y$ should lead to the same inferences about $\\theta$.\n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}[allowframebreaks]{Principle II: the Likelihood principle}\nThe Likelihood Principle (LP) is a key concept in Statistics, of particular Bayesian Statistics.\n\\begin{idea}[Likelihood Principle]\n\\label{idea:LP}\n The information brought by an observation $x \\in \\mathcal{X}$ about a parameter $\\theta \\in \\boldsymbol{\\Theta}$ is \\textbf{completely} contained in the likelihood function $l(\\theta \\mid x) \\propto f(x \\mid \\theta)$.\n\\end{idea}\n\\begin{example}[Uma vez Flamengo...]\n Suppose a pollster is interested in estimating the fraction $\\theta$ of football fans that cheer for Clube de Regatas do Flamengo (CRF).\n They survey $n=12$ people and get $x=9$ supporters and $y=3$ ``antis''.\n Consider the following two designs:\n \\begin{itemize}\n  \\item[i)] Survey $12$ people and record the number of supporters; \n  \\item[ii)] Survey until they get $y=3$.\n \\end{itemize}\nThe likelihoods for both surveys are, respectively,\n\\begin{align*}\nx \\sim \\operatorname{Binomial}(n, \\theta) \\implies l_1(\\theta \\mid x, n) &= \\binom{n}{x} \\theta^{x}(1-\\theta)^{n-x},\\\\\nn \\sim \\operatorname{Negative Binomial}(y, 1-\\theta) \\implies l2(\\theta \\mid n, y) &=  \\binom{n-1}{y-1}y (1-\\theta)^{n-y} \\theta^y,\n\\end{align*}\nhence\n\\begin{equation*}\n l_1(\\theta) \\propto l_2(\\theta) \\propto \\theta^{3}(1-\\theta)^9.\n\\end{equation*}\nTherefore, we say that these two experiments bring exactly the same information about $\\theta$.\n\\end{example}\nA generalised version of the LP can be stated as follows:\n\\begin{theorem}[\\textbf{Likelihood Proportionality Theorem}~\\citep{Goncalves2019}]\n Let  $\\Theta$ be a nonempty set and $\\mathcal{P} = \\{ P_\\theta; \\theta \\in \\Theta \\}$ be a family of probability measures on $(\\Omega, \\mathcal{A})$ and $\\nu_1$ and $\\nu_2$ be $\\sigma$-finite measures on $(\\Omega, \\mathcal{A})$.\n Suppose $P \\ll \\nu_1$ and $P \\ll \\nu_2$ for all $P \\in \\mathcal{P}$.\n Then there exists  a measurable set $A \\in \\mathcal{A}$  such that $P_\\theta(A) = 1$ for all $\\theta \\in \\Theta$ and there exist $f_{1,\\theta} \\in \\left[ \\frac{dP_\\theta}{d\\nu_1}\\right]$ and $f_{2,\\theta} \\in \\left[ \\frac{dP_\\theta}{d\\nu_2}\\right]$ and a measurable function $h$ such that\n \\begin{equation*}\n  f_{1,\\theta}(\\omega) = h(\\omega)f_{2,\\theta}(\\omega), \\forall\\, \\theta \\in \\Theta\\, \\forall\\, \\omega \\in A.\n \\end{equation*}\n\\end{theorem}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Principle III: stopping rule principle}\nA subject of contention between inference paradigms is the role of stopping rules in the inferences drawn.\n\\begin{idea}[Stopping rule principle (SRP)]\n\\label{idea:SRP}\nLet $\\tau$ be a stopping rule directing a series of experiments $\\mathcal{E}_1, \\mathcal{E}_2, \\ldots$, which generates data $\\boldsymbol{x} = (x_1, x_2, \\ldots)$.\nInferences about $\\theta$ should depend on $\\tau$ only through $\\boldsymbol{x}$.\n\\end{idea}\n\\begin{example}[Finite stopping rules]\n Suppose experiment $\\mathcal{E}_i$ leads to the observation of $x_i \\sim f(x_i \\mid \\theta)$ and let $\\mathcal{A}_i \\subset \\mathcal{X}_1 \\times \\ldots \\times \\mathcal{X}_i$ be a sequence of events.\n Define \n $$ \\tau := \\inf \\left\\{ n : (x_1, \\ldots, x_n) \\in \\mathcal{A}_n \\right\\}.$$\n It can be shown that $\\pr(\\tau < \\infty) = 1$ (exercise 1.20 BC). \n\\end{example}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Principle IV: the conditionality principle}\nWe will now state one of the main ingredients of the derivation of the LP.\nThe Conditionality Principle (CP) is a statement about the permissible inferences from randomised experiments.\n\\begin{idea}[Conditionality Principle]\n\\label{idea:CP}\n Let $\\mathcal{E}_1$ and $\\mathcal{E}_2$ be two experiments about $\\theta$.\n Let $Z \\sim \\operatorname{Bernoulli}(p)$ and \n \\begin{itemize}\n  \\item If $Z=1$, perform $\\mathcal{E}_1$ to generate $x_1 \\sim f_1(x_1 \\mid \\theta)$;\n  \\item If $Z=0$ perform $\\mathcal{E}_2$ to generate $x_2 \\sim f_2(x_2 \\mid \\theta)$.\n \\end{itemize}\nInferences about $\\theta$ should depend \\textbf{only} on the selected experiment, $\\mathcal{E}_i$.\n\\end{idea}\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Deriving the Likelihood Principle}\n\\cite{Birnbaum1962} showed that the simpler and mostly uncontroversial Sufficiency and Conditionality principles lead to the Likelihood Principle.\n\\begin{theo}[Birnbaum's theorem~\\citep{Birnbaum1962}]\n\\label{thm:Birnbaum}\n \\begin{equation}\n  \\operatorname{SP} + \\operatorname{CP} \\implies \\operatorname{LP}.\n \\end{equation}\n\\end{theo}\n\\begin{proof}\n Sketch:\n \\begin{itemize}\n  \\item Define a function $\\operatorname{EV}(\\mathcal{E}, x)$ to quantify the evidence about $\\theta$ brought by data $x$ from experiment $\\mathcal{E}$ and consider a randomised experiment $\\mathcal{E}^*$ in which $\\mathcal{E}_1$ and $\\mathcal{E}_2$ are performed with probability $p$;\n  \\item Show that CP implies\n  $\\operatorname{EV}(\\mathcal{E}^*, (j, x_j)) = \\operatorname{EV}(\\mathcal{E}_j, x_j), j = 1, 2$;\n  \\item Show that SP implies\n  $\\operatorname{EV}(\\mathcal{E}^*, (1, x_1)) = \\operatorname{EV}(\\mathcal{E}^*, (2, x_2))$ when\n  $$ l(\\theta \\mid x_1) = c l(\\theta \\mid x_2).$$\n \\end{itemize}\n\\end{proof}\nSee~\\cite{Robert2007}, pg.18 for a complete proof.\n\\end{frame}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{frame}{Recommended reading}\n\\begin{itemize}\n \\item[\\faBook] \\cite{Robert2007} Ch. 1;\n \\item[\\faForward] Next lecture: \\cite{Robert2007} Ch. 2 and $^\\ast$ \\cite{Schervish2012} Ch.3;\n%  \\item {\\large\\textbf{Recommended exercises}}\n%  \\begin{itemize}\n%   \\item[\\faBookmark] \\cite{Robert2007}.\n%   \\begin{itemize}\n%    \\item Sections.\n%    \\item $^\\ast$ Sections .\n%   \\end{itemize}   \n%   \\end{itemize}\n \\end{itemize} \n\\end{frame}\n", "meta": {"hexsha": "ba9bdc5d925fe813d02d2b39cf2f4ee1cf35d26c", "size": 6546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/lecture_1.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_1.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_1.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": 53.6557377049, "max_line_length": 289, "alphanum_fraction": 0.6833180568, "num_tokens": 2129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.79255843712608}}
{"text": "\\chapter{Models, Statistical Inference and Learning}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Poisson}(\\lambda)$ and let\n  $\\widehat{\\lambda}=n^{-1}\\sum_{i=1}^nX_i$. Then\n  \\[\n    \\bias{\\widehat{\\lambda}}\n    =\\E{n^{-1}\\sum_{i=1}^nX_i}-\\lambda\n    =n^{-1}\\sum_{i=1}^n\\E{X_i}-\\lambda\n    =0,\n  \\]\n  \\[\n    \\var{\\widehat{\\lambda}}\n    =\\var{\\frac{1}{n}\\sum_{i=1}^n X_i}\n    =\\frac{1}{n^2}\\sum_{i=1}^n \\var{X_i}\n    =\\frac{n\\lambda}{n^2}=\\frac{\\lambda}{n},\n  \\]\n  and therefore\n  \\[\n    \\se(\\widehat{\\lambda})\n    =\\sqrt{\\frac{\\lambda}{n}},\n  \\]\n  and\n  \\[\n    \\mse{\\widehat{\\lambda}}=\n    0+\\var{\\widehat{\\lambda}}=\\frac{\\lambda}{n}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Uniform}(0,\\theta)$ and let\n  $\\widehat{\\theta} = \\max\\{X_1,\\ldots, X_n\\}$. Note that\n  \\[\n    \\P{\\max\\{X_1,\\ldots,X_n\\}\\leq x}\n    =\\P{X_1\\leq x}\\cdots\\P{X_n\\leq x}\n    =x^n/\\theta^n\n  \\]\n  for $0\\leq x\\leq\\theta$.\n\n  Therefore,\n  \\[\n    f_{\\widehat{\\theta}}(x)\n    =\\begin{cases}\n      nx^{n-1}/\\theta^n & 0\\leq x\\leq 1,    \\\\\n      0                 & \\text{otherwise},\n    \\end{cases}\n  \\]\n  and so\n  \\[\n    \\E{\\widehat{\\theta}}\n    =\\int_0^\\theta\\!xnx^{n-1}/\\theta^n\\,\\d{x}\n    =\\frac{n}{n+1}\\theta.\n  \\]\n  Hence,\n  \\[\n    \\bias{\\widehat{\\theta}}\n    =\\frac{n}{n+1}\\theta-\\theta=-\\frac{\\theta}{n+1}.\n  \\]\n  Moreover,\n  \\[\n    \\E{\\widehat{\\theta}^2}\n    =\\int_0^\\theta\\!x^2nx^{n-1}/\\theta^n\\,\\d{x}\n    =\\frac{n}{n+2}\\theta^2,\n  \\]\n  and therefore\n  \\[\n    \\var{\\widehat{\\theta}}\n    =\\E{\\widehat{\\theta}^2}\n    -\\E{\\widehat{\\theta}}^2\n    =\\frac{n}{n+2}\\theta^2\n    -\\frac{n^2}{(n+1)^2}\\theta^2\n    =\\frac{n}{(n+1)^2(n+2)}\\theta^2,\n  \\]\n  \\[\n    \\se(\\widehat{\\theta})\n    =\\frac{\\theta}{n+1}\\sqrt{\\frac{n}{n+2}},\n  \\]\n  and\n  \\[\n    \\mse{\\widehat{\\theta}}\n    =\\left[\\bias{\\widehat{\\theta}}\\right]^2+\\var{\\widehat{\\theta}}\n    =\\frac{2\\theta^2}{(n+1)(n+2)}.\n  \\]\n\\end{ex}\n\n\\begin{ex}\n  Let $X_1,\\ldots,X_n\\sim\\text{Uniform}(0,\\theta)$ and let\n  $\\widehat{\\theta} = 2\\overline{X}_n$. Then\n  \\[\n    \\E{\\widehat{\\theta}}\n    =\\E{\\frac{2}{n}\\sum_{i=1}^n X_i}\n    =\\frac{2}{n}\\sum_{i=1}^n \\E{X_i}\n    =\\frac{2}{n}\\cdot \\frac{n\\theta}{2}=\\theta,\n  \\]\n  and\n  \\[\n    \\bias{\\widehat{\\theta}}\n    =\\E{\\widehat{\\theta}}-\\theta\n    =0.\n  \\]\n  Likewise,\n  \\[\n    \\var{\\widehat{\\theta}}\n    =\\var{\\frac{1}{n}\\sum_{i=1}^n X_i}\n    =\\frac{1}{n^2}\\sum_{i=1}^n \\var{X_i}\n    =\\frac{n\\theta^2}{12n^2}\n    =\\frac{\\theta^2}{12n},\n  \\]\n  \\[\n    \\se(\\widehat{\\theta})\n    =\\frac{\\theta}{\\sqrt{12 n}},\n  \\]\n  and therefore\n  \\[\n    \\mse{\\widehat{\\theta}}\n    =\\left[\\bias{\\widehat{\\theta}}\\right]^2+\\var{\\widehat{\\theta}}\n    =\\frac{\\theta^2}{12n}.\n  \\]\n\\end{ex}", "meta": {"hexsha": "28519b4623dc852bda8bd4b309e99b99ed56718f", "size": 2634, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/ch06.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/ch06.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/ch06.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": 22.1344537815, "max_line_length": 66, "alphanum_fraction": 0.5072133637, "num_tokens": 1189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645894, "lm_q2_score": 0.8596637451167995, "lm_q1q2_score": 0.7925427735680904}}
{"text": "\n\\subsection{Determinants of 2x2 and 3x3 matrices}\n\n\\subsubsection{The determinant of a 2x2 matrix}\n\n\\(M=\\begin{bmatrix}a & b\\\\c & d\\end{bmatrix}\\)\n\n\\(|M|=ad-bc\\)\n\n\\subsubsection{The determinant of a 3x3 matrix}\n\n\\(M=\\begin{bmatrix}a & b & c\\\\d & e & f\\\\g & h & i\\end{bmatrix}\\)\n\n\\(|M|=aei+bfg+cdh-ceg-dbi-afh\\)\n\n", "meta": {"hexsha": "9c7c0b8cf13ccacf7787d08c44a104e872a7154d", "size": 313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystemsOperations/05-04-determinants23.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-04-determinants23.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-04-determinants23.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.5625, "max_line_length": 65, "alphanum_fraction": 0.6453674121, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.953275045356249, "lm_q2_score": 0.8311430436757312, "lm_q1q2_score": 0.7923079226575135}}
{"text": "\\subsubsection{Random Forest Regression}\n\\label{rf}\n\n\\cite{breiman1984} introduce the classification and regression tree\n    (CART) model that is built around the idea that a single binary\n    decision tree maps learned combinations of intervals of the feature\n    columns to a label.\nThus, each sample in the training set is associated with one leaf node that\n    is reached by following the tree from its root and branching along the\n    arcs according to some learned splitting rule per intermediate node that\n    compares the sample's realization for the feature specified by the rule to\n    the learned decision rule.\nWhile such models are computationally fast and offer a high degree of\n    interpretability, they tend to overfit strongly to the training set as\n    the splitting rules are not limited to any functional form (e.g., linear)\n    in the relationship between the features and the labels.\nIn the regression case, it is common to maximize the variance reduction $I_V$\n    from a parent node $N$ to its two children, $C1$ and $C2$, as the\n    splitting rule.\n\\cite{breiman1984} formulate this as follows:\n$$\nI_V(N)\n=\n\\frac{1}{|S_N|^2} \\sum_{i \\in S_N} \\sum_{j \\in S_N}\n    \\frac{1}{2} (y_i - y_j)^2\n- \\left(\n    \\frac{1}{|S_{C1}|^2} \\sum_{i \\in S_{C1}} \\sum_{j \\in S_{C1}}\n        \\frac{1}{2} (y_i - y_j)^2\n    +\n    \\frac{1}{|S_{C2}|^2} \\sum_{i \\in S_{C2}} \\sum_{j \\in S_{C2}}\n        \\frac{1}{2} (y_i - y_j)^2\n\\right)\n$$\n$S_N$, $S_{C1}$, and $S_{C2}$ are the index sets of the samples in $N$, $C1$,\n    and $C2$. \n\n\\cite{ho1998} and then \\cite{breiman2001} generalize this method by combining\n    many CART models into one forest of trees where every single tree is\n    a randomized variant of the others.\nRandomization is achieved at two steps in the training process:\nFirst, each tree receives a distinct training set resampled with replacement\n    from the original training set, an idea also called bootstrap\n    aggregation.\nSecond, at each node a random subset of the features is used to grow the tree.\nTrees can be fitted in parallel speeding up the training significantly.\nFor prediction at the tree level, the average of all the samples at a\n    particular leaf node is used.\nThen, the individual values are combined into one value by averaging again\n    across the trees.\nDue to the randomization, the trees are decorrelated offsetting the\n    overfitting.\nAnother measure to counter overfitting is pruning the tree, either by\n    specifying the maximum depth of a tree or the minimum number of samples\n    at leaf nodes.\n\nThe forecaster must tune the structure of the forest.\nParameters include the number of trees in the forest, the size of the random\n    subset of features, and the pruning criteria.\nThe parameters are optimized via grid search: We train many models with\n    parameters chosen from a pre-defined list of values and select the best\n    one by CV.\nRFs are a convenient ML method for any dataset as decision trees do not\n    make any assumptions about the relationship between features and labels.\n\\cite{herrera2010} use RFs to predict the hourly demand for water in an urban\n    context, a similar application as the one in this paper, and find that RFs\n    work well with time series type of data.\n", "meta": {"hexsha": "7ffd79f970fbc38a3b4da0e77860c6daf98e9cc1", "size": 3246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/3_ml/4_rf.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/4_rf.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/4_rf.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.447761194, "max_line_length": 78, "alphanum_fraction": 0.7399876771, "num_tokens": 824, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750373915658, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7923079200248769}}
{"text": "\\subsection{Dissimilarity metrics}\n\nThe reconstruction of the puzzle is based on a dissimilarity metric between all the pieces. The higher the dissimilarity between two given pieces, the lower priority is given to the fact that these pieces are placed next to each other. Several dissimilarity metrics are introduced.\n\n\\autoref{fig:side} depicts the working principle of the dissimilarity computation. The intensity of the red channel for the right side of a piece of the puzzle is plotted along with the left side of two others pieces. One can see that the matching piece has nearly the same profile as the starting piece (nearly superimposed), while the third one is very different. Of course, the difference between matching and non matching pieces are not always that obvious.\n\n\\begin{figure}[H]\n    \\centering\n    \\input{fig/side.tex}\n    \\caption{Illustration of the principle of dissimilarity computation by showing the red channel intensities for three pieces.}\n    \\label{fig:side}\n\\end{figure}\n\n\\paragraph{Sum of Squared Distances (SSD)} \\mbox{} \n\nThe SSD between two pieces $x_i$ and $x_j$ is obtained by summing up the squared differences of the pixels along the pieces' juxtaposing boundaries, for each color channel (red, green and blue) \\cite{robust}. For a piece $x$ of size $M \\times M$, $x(m,n,c)$ denotes the value of the pixel at the coordinates $(m,n)$ in the color channel $c$. The SSD between $x_i$ and $x_j$, $x_i$ being placed at the left of $x_j$, can be expressed as \n\n\\begin{equation}\n    D_{LR,SSD}(x_i, x_j) = \\sum_{c=1}^{3} \\sum_{k=1}^{M} \\left( x_i(k,M,c) - x_j(k,M,c)\\right)^2    \n\\end{equation}\n\nThis can be extended to the cases where $x_i$ is placed on the right, on the top or on the bottom of $x_j$.\n\n\\paragraph{$(L_p)^q$ norm} \\mbox{}\n\nThe SSD is actually the $L_2$ norm of the two vectors that form the boundaries of the two pieces. The $(L_p)^q$ can also be used, and it is defind as\n\n\\begin{equation}\\label{eq:lpq}\n    \\hspace{-0.3cm}\n    D_{LR,pq}(x_i, x_j) = \\left( \\sum_{c=1}^{3} \\sum_{k=1}^{M} \\left( \\left| x_i(k,M,c) - x_j(k,M,c)\\right|\\right)^p \\right)^{\\frac{p}{q}}\n\\end{equation}\n\nHence, the SSD is a particular case of $(L_p)^q$ norm with $p=q=2$. It was experimentally found in \\cite{greedy} that the good results were obtained for $p=3/10$ and $q=1/16$, they will thus be used in the solver. Instinctively, it is due to the fact that the $L_2$ norm penalizes a lot large boundary differences even though such differences may occur in natural images. \n\n\\paragraph{Mahalanobis Gradient Compatibility (MGC)}\n\nWhile the first two metrics penalize differences in the pixels intensities, the MGC (introduced in \\cite{Gallagher}) instead penalizes differences in the intensity of the gradient. If a piece has a strong gradient near its edge, it is expected that the juxtaposed piece will continue the gradient. The penalty for a deviation is computed with the Mahalanobis distance.\n\nLooking at the dissimilarity between the right side of $x_i$ and the left side of $x_j$, let $\\mu_{iL}(c)$ be the average color difference in the color channel $c$ between the two last columns of $x_i$:\n\n\\begin{equation}\n    \\mu_{iL}(c) = \\frac{1}{M} \\sum_{k=1}^{M} x_i(k,M,c) - x_i(k,M-1,c) \n\\end{equation}\n\nThe array of gradients of dimension $M$ by 3 $G_{ijLR}$ is then introduced, with $G_{ijLR}(k,c)$ denoting the color difference between the right side of $x_i$ and the left side of $x_j$ for the color channel $c$ at the row $k$:\n\n\\begin{equation}\n    G_{ijLR}(k,c) = x_j(k,1,c) - x_i(k,M,c) \n\\end{equation}\n\nBy denoting $S_{iL}$ the 3 by 3 covariance matrix obtained from the gradient difference at the right of $x_i$, the gradient dissimilarity is given by:\n\n\\begin{gather}\n    D'_{LR}(x_i,x_j) = \\sum_{k=1}^{M} D'_{LR,k}\\\\\n    D'_{LR,k} = \\left( G_{ijLR}(k) - \\mu_{iL} \\right) S_{iL}^{-1} \\left( G_{ijLR}(k) - \\mu_{iL} \\right)^T\n\\end{gather}\n\nThe final MGC symmetric dissimilarity metric for placing the piece $x_i$ at the left of $x_j$ is given by:\n\n\\begin{equation}\n    D_{LR,MGC}(x_i,x_j) = D'_{LR}(x_i,x_j) +  D'_{RL}(x_j,x_i)\n\\end{equation}\n\n\\paragraph{Combining MGC and SSD (M+S)} \\mbox{}\n\nIt was proposed in \\cite{robust} that the SSD and the MGC convey complementary information so that they could be combined to provide more accuracy. The M+S dissimilarity metric is hence defined as the weighed product of the SSD and the MGC:\n\n\\begin{equation}\\label{eq:ms}\n    D_{M+S}(x_i,x_j) = D_{MGC}(x_i,x_j) \\times \\left( D_{SSD}(x_i,x_j) \\right)^{\\frac{1}{r}}\n\\end{equation}\n\nThe value of the weighing parameter $r$ giving the best results is investigated later.\n\n%The obtained dissimilarities are then normalized \\cite{robust} \\cite{Gallagher}. For a given piece, all its dissimilarities are divided by the \n\n\\paragraph{Combining MGC and $(L_p)^q$ (M+pq)} \\mbox{}\n\nIn the same idea, the MGC and the $(L_p)^q$ can be combined in a weighed product. This method will be referred to as the M+pq in the latter.\n\n\\begin{equation}\\label{eq:mpq}\n    D_{M+pq}(x_i,x_j) = D_{MGC}(x_i,x_j) \\times \\left( D_{pq}(x_i,x_j) \\right)^{\\frac{1}{r}}\n\\end{equation}\n\n\\subsection{Placement algorithm}\n\nOnce the dissimilarity is evaluated between every piece of the puzzle, for every orientation (top, bottom, right, left), the pieces should be placed accordingly to these measures. The implemented algorithm is a two step iterative method, and it is inspired from what was proposed in \\cite{greedy}. An illustration of its functioning is depicted in \\autoref{fig:placement}.\n\nThe starting piece is chosen to be the one having the lowest dissimilarity with any other piece of the puzzle. During the first step, all the pieces that have already been placed are scanned. The next piece that will be placed on the puzzle  is the one that has the lowest dissimilarity with any of the already placed ones. Piece by piece, the puzzle is then reconstructed. When a piece has to be placed in between multiple others, the dissimilarity with all of these is taken into account.\n\n\nThe second step starts when the puzzle is full. The algorithm then looks for \\textit{symmetric matches} in all the juxtaposed pieces. Two pieces $x_i$ and $x_j$ are symmetrically matched if the best possible match for $x_i$ in every possible orientation is $x_j$ and the best possible match for $x_j$ is $x_i$ in the opposite orientation. For example, if the pieces labeled $x_3$ and $x_7$ are juxtaposed at the end of the first step, they will be considered as symmetric matches if the best possible match for $x_3$ is $x_7$ on its right, and the best match for $x_7$ is $x_3$ on its left. From these symmetric matches, a \\textit{segment} is extracted from the image. It is defined as the biggest portion of the puzzle only composed of symmetrically matched pieces, and will serve as starting point for the next iteration. The iteration process stops when the result after the reconstruction step is not changing anymore.\n\n\\begin{figure}[H]\n    \\centering\n%     \\subfloat[The puzzle is constructed piece by piece.]{\\includegraphics[height=0.25\\textheight]{fig/algo_start.eps}\n% \\label{fig:placement1}}\n% \\hfil\n%     \\subfloat[The puzzle is constructed piece by piece.]{\\includegraphics[height=0.25\\textheight]{fig/algo_start.eps}\n% \\label{fig:placement1}}\n% \\hfil\n%     \\subfloat[The puzzle is constructed piece by piece.]{\\includegraphics[height=0.25\\textheight]{fig/algo_start.eps}\n% \\label{fig:placement1}}\n% \\hfil\n%     \\subfloat[The puzzle is constructed piece by piece.]{\\includegraphics[height=0.25\\textheight]{fig/algo_start.eps}\n% \\label{fig:placement1}}\n% \\hfil\n    \\begin{subfigure}{0.25\\textheight}\n        \\centering\n        \\includegraphics[width=\\textwidth]{fig/algo_start.eps}\n        \\caption{The puzzle is constructed piece by piece.}    \n        \\label{fig:placement1}\n    \\end{subfigure}%\n    \n    \\begin{subfigure}[b]{0.25\\textheight}\n        \\centering\n        \\includegraphics[width=\\textwidth]{fig/algo_fin1.eps}\n        \\caption{At the end of the first placement phase, errors are present.}    \n        \\label{fig:placement2}\n    \\end{subfigure}%\n    \n    \\begin{subfigure}[b]{0.25\\textheight}\n        \\centering\n        \\includegraphics[width=\\textwidth]{fig/algo_cut.eps}\n        \\caption{The biggest segment is extracted from the previous image and will serve as start for the next iteration.}    \n        \\label{fig:placement3}\n    \\end{subfigure}%\n    \n    \\begin{subfigure}[b]{0.25\\textheight}\n        \\centering\n        \\includegraphics[width=\\textwidth]{fig/algo_fin2.eps}\n        \\caption{The reconstruction is nearly perfect after two iterations.}    \n        \\label{fig:placement4}\n    \\end{subfigure}\n    \n    \\caption{Illustration of the reconstruction algorithm}\n    \\label{fig:placement}\n\\end{figure}\n\nThe Matlab implementation of the algorithm was optimized using matrix computations, and the full solving of a 432 parts puzzle takes less than 10 seconds.", "meta": {"hexsha": "07c7d232753166d4b64ac8361f59bc6d3aa6fcb7", "size": 8887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/algo.tex", "max_stars_repo_name": "mpetitjean/JigSawPuzzle", "max_stars_repo_head_hexsha": "3880fd0be7f6e8efbd998f04c6314e4c3e0bc940", "max_stars_repo_licenses": ["MIT"], "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/algo.tex", "max_issues_repo_name": "mpetitjean/JigSawPuzzle", "max_issues_repo_head_hexsha": "3880fd0be7f6e8efbd998f04c6314e4c3e0bc940", "max_issues_repo_licenses": ["MIT"], "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/algo.tex", "max_forks_repo_name": "mpetitjean/JigSawPuzzle", "max_forks_repo_head_hexsha": "3880fd0be7f6e8efbd998f04c6314e4c3e0bc940", "max_forks_repo_licenses": ["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.9352517986, "max_line_length": 922, "alphanum_fraction": 0.7301676606, "num_tokens": 2523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7923071836851646}}
{"text": "%================================\n\\section{Review of Metric Spaces}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a set. A \\textit{metric} on $X$ is a function $\\rho: X \\times X \\to \\mathbb R_{\\ge 0}$, such that $\\forall x, y, z \\in X$, the following (metric axioms) holds:\n\t\\begin{enumerate}[M1.]\n\t\t\\item $\\rho(x,y) = 0 \\iff x = y$ (identity of indiscernibles);\n\t\t\\item $\\rho(x,y) = \\rho(y,x)$ (symmetry).\n\t\t\\item $\\rho(x,y) + \\rho(y,z) \\ge \\rho(x,z)$ (triangle inequality);\n\t\\end{enumerate}\n\tA \\textit{metric space} is a set together with a metric on it, or more formally, a pair $(X,\\rho)$ where $X$ is a set and $\\rho$ is a metric on $X$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example} \\ \n\t\\begin{enumerate}\n\t\t%--------------------------------\n\t\t\\item The function $\\rho_p: \\mathbb R^n \\times \\mathbb R^n \\to \\mathbb R_{\\ge 0}$ defined by $\\forall p \\in \\overline{\\mathbb R}_{\\ge 1}$, $\\forall x,y \\in \\mathbb R^n$,\n\t\t\t$$\n\t\t\t\\rho_p (x,y) = \\left( \\sum_{i = 1}^n |x_i - y_i|^p \\right)^\\frac{1}{p},\n\t\t\t$$\n\t\t\tis a metric on $\\mathbb R^n$. Clearly it satisfies identity of indiscernibles and symmetry. For triangle inequality, it is suggested by Minkowski inequality.\n\t\t\t\n\t\t\tGiven $x \\in \\mathbb R^3$, $r \\in \\mathbb R_{\\ge 0}$, and\n\t\t\t$$\n\t\t\tB_\\rho = \\left\\{ y \\in \\mathbb R^3 \\;|\\; \\rho (x,y) \\le r \\right\\}.\n\t\t\t$$\n\t\t\t\n\t\t\t\n\t\t\t$\\forall p, q \\in \\overline{\\mathbb R}_{\\ge 1}$, it is true that, $\\forall x,y \\in \\mathbb R^n$,\n\t\t\t$$\n\t\t\tp \\le q \\implies \\rho_p(x,y) \\ge \\rho_{q}(x,y).\n\t\t\t$$\n\t\t\tThus, $B_p \\subseteq B_q$.\n\t\t\t\n\t\t\tGeometrically, as $p = 1$, $B$ is a octahedron in $\\mathbb R^3$ with center $x$ and radius $r$; as $p = 2$, $B$ is a sphere in $\\mathbb R^3$ with center $x$ and radius $r$. It is easy to observe that as $p \\to \\infty$, $B$ tends to a cube in $\\mathbb R^3$ with center $x$ and edge length $2r$; i.e.,\n\t\t\t$$\n\t\t\t\\rho_\\infty(x,y) = \\lim_{p \\to \\infty} \\rho_p (x,y) = \\sup_{i \\in \\{1, \\ldots, n\\}} |x_i - y_i|.\n\t\t\t$$\n\t\t%--------------------------------\n\t\t\n\t\t\n\t\t%--------------------------------\n\t\t\\item Let $f: (X, \\rho) \\to \\mathbb R^n$ with $X \\subseteq \\mathbb R^m$ be a continuous map on $X$. Let $x, y \\in X$, then $\\rho': f[X] \\times f[X] \\to \\mathbb R_{\\ge 0}$ defined by\n\t\t\t$$\n\t\t\t\\rho_p'(x,y) = \\int_0^1 f(\\ell(t))d_ps(t)\n\t\t\t$$\n\t\t\twhere\n\t\t\t$$\n\t\t\t\\ell (t) = x + t(y - a)\n\t\t\t$$\n\t\t\tand\n\t\t\t$$\n\t\t\td_p s(t) = \\left( \\sum_{i = 1}^m \\left|\\frac{dg_i}{dt}(t)\\right|^p\\right)^\\frac{1}{p} dt.\n\t\t\t$$\n\t\t\twith $p \\ge \\overline{\\mathbb R}_{\\ge 1}$ is a metric on $f[X]$.\n\t\t\t\n\t\t\tFix $x$ and given $r \\in \\mathbb R_{\\ge 0}$, the set\n\t\t\t$$\n\t\t\tB_p = \\left\\{ y \\in \\mathbb R^m : \\rho_p'(x,y) \\le r \\right\\}\n\t\t\t$$\n\t\t\tdescribes a set ``attached'' on $f[X]$ with center $x$.\t\t\t\n\t\t\tIf $p = 2$, $m = 2$ and $n = 3$, and $f: [0, 2 \\pi) \\times [0, 2 \\pi) \\to \\mathbb R^3$ is defined by\n\t\t\t$$\n\t\t\tf(\\lambda, \\phi) = \\begin{cases}\n\t\t\t\tr \\cos \\lambda \\sin \\phi, \\\\\n\t\t\t\tr \\sin \\lambda \\sin \\phi, \\\\\n\t\t\t\tr \\cos \\phi,\n\t\t\t\\end{cases}\n\t\t\t$$\n\t\t\tthen $\\rho_2'$ here is a \\textit{great circle metric} defined by\n\t\t\t$$\n\t\t\t\\rho_2' (x,y) = r\\arccos(\\sin x_\\phi \\sin y_\\phi + \\cos x_\\phi \\cos y_\\phi \\cos(x_\\lambda - y_\\lambda)).\n\t\t\t$$\n\t\t%--------------------------------\n\t\t\n\t\t\n\t\t%--------------------------------\n\t\t\\item Let $a,b \\in \\mathbb R$ with $a \\le b$, and $p \\in \\overline{\\mathbb R}_{\\ge 1}$, and $C[a,b]$ denote the set of continuous function $[a,b] \\to \\mathbb R$.\n\t\t\n\t\t\tThen $d_p$ defined by $\\forall f, g \\in C[a,b]$,\n\t\t\t$$\n\t\t\t\\rho_{p}(f,g) = \\left( \\int_a^b |f - g|^{p} \\right)^\\frac{1}{p}\n\t\t\t$$\n\t\t\tis a metric on $C[a,b]$.\n\t\t\t\n\t\t\t\n\t\t\tSimilar to $\\rho_p$ on $\\mathbb R^n$,\n\t\t\t$$\n\t\t\tB_{p} = \\left\\{ g \\;|\\; \\rho(f, g) \\le r \\right\\}\n\t\t\t$$\n\t\t\tdefines a set with ``center'' $f$ and ``radius'' $r \\in \\mathbb R_{\\ge 0}$.\n\t\t\t\n\t\t\tIt also implies that, on $C[a,b]$, $\\forall p, q \\in \\overline{\\mathbb R}_{\\ge 1}$, $\\forall x,y \\in \\mathbb R^n$\n\t\t\t$$\n\t\t\tp \\le q \\implies d_p(f,g) \\ge d_q(f,g),\n\t\t\t$$\n\t\t\tand, naturally, $B_p \\subseteq B_q$. This is a straight corollary from the same case of $d_p$ on $\\mathbb R^n$.\n\t\t%--------------------------------\n\t\t\n\t\t\n\t\t%--------------------------------\n\t\t\\item Let $A$ be a set. The \\textit{Hamming metric} $\\rho$ on a set $A^n$ is given by $\\forall x,y \\in A^n$\n\t\t\t$$\n\t\t\t\\rho(x,y) = \\# \\left\\{ i \\in \\{1, \\ldots, n\\} : x_i \\ne y_i \\right\\}.\n\t\t\t$$\n\t\t\tAn example from Wikipedia. The word ``karolin'' and ``kathrin'' can be considered as tuples\n\t\t\t$$\n\t\t\tx = ( \\mathrm{ k, a, r, o, l, i, n } ), \\; y = ( \\mathrm{k, a, t, h, r, i, n} ).\n\t\t\t$$\n\t\t\tFor all $i \\in \\{0, \\ldots, 6\\} \\setminus \\{ 0, 1, 4, 6 \\}$, $x_i \\ne y_i$, and $\\# (\\{0, \\ldots, 6\\} \\setminus \\{ 0, 1, 4, 6 \\}) = 3$, thus\n\t\t\t$$\n\t\t\t\\rho(x,y) = 3.\n\t\t\t$$\n\t\t%--------------------------------\n\t\t\n\t\t\n\t\t%--------------------------------\t\n\t\t\\item Let $(M, \\rho)$ be a metric space (for example, $\\rho = \\rho_2$ on $\\mathbb R^n$), and $X, Y \\in \\mathcal P(M)$. The Hausdorff metric $\\rho_\\mathrm{H}$ on $\\mathcal P(M)$ is defined by\n\t\t\t$$\n\t\t\t\\rho_\\mathrm{H}(X,Y) = \\max \\left\\{ \\sup_{x \\in X} \\rho(x,Y), \\sup_{y \\in Y} \\rho(X,y) \\right\\},\n\t\t\t$$\n\t\t\twhere $\\rho(a, B) = \\inf_{b \\in B} \\rho(a,b)$ for all $B \\in \\mathcal P(M)$ and $a \\in M$.\n\t\t\t\n\t\t\tThis metric can be used to measure how close two figures (as sets of points) are.\n\t\t%--------------------------------\n\t\\end{enumerate}\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a metric space, let $x \\in X$, and $\\varepsilon > 0$. The \\textit{open ball with center $x$ and radius $\\varepsilon$}, or more briefly the \\textit{open $\\varepsilon$-ball about $x$} is the subset\n\t$$\n\tB(x, \\varepsilon) = \\{ y \\in X: \\rho (x,y) \\le \\varepsilon \\} \\subseteq X.\n\t$$\n\tSimilarly, the \\textit{closed $\\varepsilon$-ball around $x$} is\n\t$$\n\t\\overline B (x, \\varepsilon) = \\{ y \\in X: \\rho(x,y) \\le \\varepsilon \\} \\subseteq X.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tClearly, the word ``ball'' does not mean it should look like a ball. Clearly, for all $x \\in \\mathbb R^3$, the ball $\\{ y \\in \\mathbb R^3 : \\rho_\\infty (x,y) < 1 \\}$ is a cube without its surface.\n\t\n\tAnd it is interesting to think that on $C[a,b]$ with conditions above,\n\t$$\n\t\\{ g \\in C[a,b] : \\rho_p(f,g) < 1 \\}\n\t$$\n\tdefines a open ball in $C[a,b]$.\n\t\n\t\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tFor hamming metric $\\rho$ with conditions above, for $\\varepsilon \\in \\mathbb R_{(0,1)}$, the ball\n\t$$\n\t\\{ y \\in A^n : \\rho(x,y) < 1 \\} = \\{x\\}.\n\t$$\n\tis a singleton.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a metric space.\n\t\\begin{enumerate}[(i)]\n\t\t\\item A subset $U$ of $X$ is \\textit{open in $X$} (or an \\textit{open subset of $X$}) iff\n\t\t$$\n\t\t\\forall u \\in U, \\ \\exists \\varepsilon \\in \\mathbb R_{> 0} , \\;\\; B(u, \\varepsilon ) \\subseteq U.\n\t\t$$\n\t\t\\item A subset $V$ is \\textit{closed in $X$} iff $X\\setminus V$ is open in $X$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tEquivalently, $U$ is open in $X$ iff $\\exists \\varepsilon \\in \\mathbb R_{>0}$,\n\t$$\n\tU = \\bigcup_{x \\in U} B(x, \\varepsilon );\n\t$$\n\tand $V$ is closed in $X$ iff\n\t$$\n\tV = X \\setminus \\bigcup_{x \\in U} B(x, \\varepsilon) = \\bigcap_{x \\in U} (X \\setminus B(x, \\varepsilon)),\n\t$$\n\tby De Morgan's Law.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\tLet $X$ be a metric space, let $\\{x_n\\}_{n = 1}^{\\infty}$ be a sequence in $X$ and let $x \\in X$. Then $\\{x_n\\}$ \\textit{converges} in $X$ iff\n\t$$\n\t\\exists x \\in X, \\lim_{n \\to \\infty} d(x_n, x) = 0.\n\t$$\n\tExplicitly, then, $\\{ x_n \\}$ converges to $x$ iff\n\t$$\n\t\\forall \\varepsilon \\in \\mathbb R_{> 0}, \\exists N \\in \\mathbb N_{\\ge 1}, \\forall n \\in \\mathbb N_{\\ge N}, \\quad d(x_n , x) < \\varepsilon.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\ \n\t\\begin{enumerate}\n\t\t\\item Equivalently, $\\{x_n\\}$ converges in $X$ iff\n\t\t\t$$\n\t\t\t\\exists x \\in X, \\ \\forall \\varepsilon \\in \\mathbb R_{>0}, \\# (\\{ x_n \\} \\cap B(x,\\varepsilon)) = \\aleph_0 \\land \\# ( \\{x_n\\} \\setminus B(x, \\varepsilon)) < \\aleph_0.\n\t\t\t$$\n\t\t\tIn other words, $B(x, \\varepsilon)$ contains all but finitely many $x_n$.\n\t\t\\item Let $X \\subseteq S$. $\\{x_n\\}$ converges to $x \\in S$ does not means it need to converge in $X$. For example $\\mathbb Q \\subseteq \\mathbb R$, the sequence\n\t\t\t$$\n\t\t\t\\left\\{ x_n = \\frac{1}{x} + r : r^2 = 2 \\right\\}_{n \\in \\mathbb N}\n\t\t\t$$\n\t\t\tdoes converge to $\\sqrt{2} \\in \\mathbb R$, but $\\sqrt{2} \\notin \\mathbb Q$, so $\\{x_n\\}$ converges in $\\mathbb R$, but does not converge in $\\mathbb Q$.\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $X$ be a metric space and $V \\subseteq X$. Then $V$ is closed in $X$ iff\n\t$$\n\t\\forall \\{x_n\\}_{n = 1}^\\infty \\subseteq V, \\ \\forall x \\in X, \\quad \\lim_{n \\to \\infty} d(x_n, x) = 0 \\implies x \\in V.\n\t$$\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof}\n\tSuppose $V$ is closed in $X$, then $X \\setminus V$ is open in $X$. Suppose $\\exists x \\in X \\setminus V$, such that $\\exists \\{x_n\\}_{n = 1}^\\infty \\subseteq V$, $\\{x_n\\}$ converges to $x$, then $\\forall \\varepsilon \\in \\mathbb R_{> 0}$, $B(x, \\varepsilon) \\cap \\{x_n\\} \\ne \\emptyset$. $\\{x_n\\} \\subseteq V$, so $B(x, \\varepsilon) \\cap V \\ne \\emptyset$. This implies that $X \\setminus V$ is not open, then $V$ is not closed (for if $V$ is closed, then $X \\setminus V$ is open). It is contradicted to the assumption.\n\t\n\tNow, suppose $V$ is not closed in $X$, then $X \\setminus V$ is not open. Then, $\\exists p \\in X \\setminus V$, such that $\\forall \\varepsilon \\in \\mathbb R_{> 0}$, $B(p, \\varepsilon) \\cap V \\ne \\emptyset$. This implies there are some $\\{x_n\\}_{n = 1}^\\infty \\subseteq V$, such that $B(p, \\varepsilon)$ contains all but finite elements in $\\{x_n\\}$. Thus, $\\{x_n\\}$ converges to $p \\in X \\setminus V$, contradicting to the conditions.\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\t\\label{lem: open sets are closed under blah blah blah}\n\tLet $X$ be a metric space, and $\\mathcal T$ be the family of open subsets of $X$. Then,\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal T$ is closed under arbitrary union.\n\t\t\\item $\\mathcal T$ is closed under finite intersection.\n\t\t\\item $\\emptyset, X \\in \\mathcal T$.\n\t\\end{enumerate}\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof} \\ \n\t\\begin{enumerate}\n\t\t\\item Let $I$ be an index set. For all $i \\in I$, let $U_i \\in \\mathcal T$. Then for some $\\varepsilon \\in \\mathbb R_{> 0}$,\n\t\t\t$$\n\t\t\tU_i = \\bigcup_{x \\in U_i} B(x, \\varepsilon).\n\t\t\t$$\n\t\t\tLet $U = \\bigcup_{i \\in I} U_i$, then we have,\n\t\t\t$$\n\t\t\tU = \\bigcup_{i \\in I} \\bigcup_{x \\in U_i} B(x, \\varepsilon) = \\bigcup_{x \\in U} B(x, \\varepsilon)\n\t\t\t$$\n\t\t\tfor some $\\varepsilon \\in \\mathbb R_{> 0}$.\n\t\t\n\t\t\\item Let $\\mathcal C$ be the family of closed subsets of $X$, and let $U, V \\in \\mathcal C$. Then for all $\\{u_n\\}_{n = 1}^\\infty \\subseteq U$, $\\forall u \\in X$, $\\{u_n\\}$ converges to $u$ implies that $u \\in U$. It also holds for $U \\cup V \\supseteq U$. Similarly, for all $\\{v_m\\}_{m = 1}^\\infty$, $\\forall v \\in X$, $\\{v_m\\}$ converges to $v$ implies $v \\in V$. It also holds for $U \\cup V \\supseteq V$. Thus $U \\cup V$ is closed.\n\t\t\t\n\t\t\tThen, $X \\setminus (U \\cup V) = (X \\setminus U) \\cap (X \\setminus V)$ is open, where $X \\setminus U$ and $X \\setminus V$ are open for $U$ and $V$ are closed.\n\t\t\n\t\t\\item $\\emptyset = \\bigcup_{i \\in \\emptyset} U_i$ for all $U_i \\in \\mathcal T$, so $\\emptyset$ is open. $\\emptyset = U \\cap V$ for all mutually disjoint closed subsets $U, V \\subseteq X$, so $\\emptyset$ is closed, so $X = X \\setminus \\emptyset$ is open.\n\t\\end{enumerate}\n\\end{proof}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $X$ be a metric space, and $\\mathcal C$ be the family of all closed subsets of $X$. Then,\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\mathcal C$ is closed under arbitrary intersection.\n\t\t\\item $\\mathcal C$ is closed under finite union.\n\t\t\\item $\\emptyset, X \\in \\mathcal C$.\n\t\\end{enumerate}\n\\end{lemma}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proof}\n\tLet $\\mathcal T$ be the family of all open subset of $X$, and let $I$ be any index set.\n\t\\begin{enumerate}\n\t\t\\item It has been proved that $\\mathcal T$ is closed under arbitrary union, so by De Morgan's law, for any $i \\in I$, if $U_i \\in \\mathcal T$, then\n\t\t\t$$\n\t\t\tX \\setminus \\bigcup_{i \\in I} U_i = \\bigcap_{i \\in I} (X \\setminus U_i) \\in \\mathcal C.\n\t\t\t$$\n\t\t\\item It has been proved in Lemma \\ref{lem: open sets are closed under blah blah blah}.\n\t\t\\item It has been proved that $\\emptyset$ is open in $X$. So $X = X \\setminus \\emptyset$ is closed in $X$.\n\t\\end{enumerate}\n\\end{proof}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{definition}\n\t\\label{def: continuous function}\n\tLet $(X, \\rho)$ and $(Y, \\rho')$ be metric spaces. A function $f: (X, \\rho) \\to (Y, \\rho)$ is \\textit{continuous} on a point $p \\in X$ iff\n\t$$\n\t\\forall \\varepsilon \\in \\mathbb R_{> 0}, \\ \\exists \\delta \\in \\mathbb R_{> 0}, \\ \\forall x \\in B(p, \\delta), \\quad f(x) \\in B(f(p), \\varepsilon).\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note} \\\n\t\\begin{enumerate}\n\t\t\\item If $\\rho$ is a discrete metric on $X$, then $B(p, \\delta) = \\{p\\}$ for all $\\delta$. Then, by definition, for all $\\varepsilon$, $f(x) \\in B(f(p), \\varepsilon)$. So $f$ is continuous everywhere.\n\t\t\n\t\t\\item On the contrary, if $\\rho'$ is a discrete metric on $Y$, but for all $p\\in X$, $\\rho$ suffices for all $\\delta \\in \\mathbb R_{> 0}$, $\\# B(p, \\delta) \\ge \\aleph_0$, then for some $\\varepsilon \\in \\mathbb R_{>0}$, for all $\\delta \\in \\mathbb R_{> 0}$, there exists $x \\in B(p, \\delta)$, such that $f(x) \\notin B(f(p), \\varepsilon)$. Thus $f$ is not continuous on such $p$.\n\t\\end{enumerate}\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{lemma}\n\tLet $(X, \\rho)$ and $(Y, \\rho')$ be metric spaces and let $f: (X, \\rho) \\to (Y, \\rho)$ be a function. The following are equivalent:\n\t\\begin{enumerate}[(i)]\n\t\t\\item $f$ is continuous on $X$;\n\t\t\\item for all open $U \\subseteq Y$, the preimage $f^{-1}[U] \\subseteq X$ is open;\n\t\t\\item for all closed $V \\subseteq Y$, the preimage $f^{-1}[V] \\subseteq X$ is closed.\n\t\\end{enumerate}\n\\end{lemma}\n%--------------------------------\n\n\n\n\n\n\n\n\n\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": "928bfe8e545ed9416d47845aae7bb2d9d54c1161", "size": 14801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s1_review-of-metric-spaces.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s1_review-of-metric-spaces.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-by-tom-leinster/c1_topological-space/s1_review-of-metric-spaces.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.4441558442, "max_line_length": 516, "alphanum_fraction": 0.5266536045, "num_tokens": 5358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8615382058759128, "lm_q1q2_score": 0.7923071725632023}}
{"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{bm}\n\n\\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\var}{var}\n\\DeclareMathOperator*{\\expec}{E}\n\n\\begin{document}\n\\title{\\textsf{Homework 5 for Pattern Recognition}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 1.1}\n{\n    The optimal hyperplane satisfies $$f(x) = \\sum_{i=1}^{n}{\\alpha_i^{*} y_i K(x, x_i)} + b = 0.$$\n    \\begin{itemize}\n        \\item \\textbf{(b)(d)(f) are of Gaussian kernels.}\\quad This is obvious since the support vectors are distributed not only near the hyperplane, but also on the other side away from the hyperplane. This is a property of the Gaussian kernels. Moreover, \\textbf{(d)} corresponds to $\\sigma=0.1$ because it tends to overfit the positive samples. \\textbf{(b)} must be with $\\sigma=1$, as it has a straighter separate line. And \\textbf{(f)} is in the middle, with $\\sigma=0.5$.\n\n        \\item \\textbf{(c) is of linear kernels.}\\quad The hyperplane would follow a linear function of $x$ if the kernel $K(x, x_i)$ is linear. Thus, the straight line indicates a linear kernel in \\textbf{(c)}.\n\n        \\item \\textbf{(a) is of quadratic kernels.}\\quad The The hyperplane would follow a quadratic function of $x$ if the kernel $K(x, x_i)$ is quadratic. This can be shown using the fact that $$(w^T x)^2 = (w^T x)^T (w^T x) = x^T (w w^T) x,$$ which is a quadratic form. The parabola thus indicates a quadratic kernel in \\textbf{(a)}.\n\n        \\item \\textbf{(e) is of cubic kernels.}\\quad Similar to the quadratic kernels, a cubic hyperplane may come from the linear combination of many cubic terms with respect to $x$.\n    \\end{itemize}\n}\n\n\\section*{Question 1.2}\n{\n    We prefer the linear kernel since the samples are linearly separable. The linear kernel, as long as feasible, means \\emph{mathematical simplicity, intuitive interpretability, simple calulation,} as well as \\emph{property of superpostion}. For example, the linear dot product can be interpreted as projection to a certain direction in the space, while nonlinear ones hardly have such an intuitive demonstration. \n}\n\n\\section*{Question 2}\n{\n    \\subsection*{SVM-based classifiers}\n    {\n        Thanks to the ``Generate Code'' function of the Classification Learner toolbox in MATLAB, I saved the code of all the 6 SVM kernels in 6 function files: Linear, Quadratic, Cubic, Gaussian Fine ($\\sigma=0.1$), Gaussian Medium ($\\sigma=0.5$), and Gaussian Coarse ($\\sigma=1$). See Table 1 for the results.\n\n        \\begin{table}[!hbp]\n            \\centering\n            \\begin{tabular}{|c|c|c|}\n            \\hline\n            Method & Testing accuracy & Training speed \\\\\n            \\hline\n            \\hline\n            Linear SVM & 0.975389 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            Quadratic SVM & 0.982923 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            Cubic SVM & 0.983928 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            Gaussian Fine SVM & 0.546459 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            Gaussian Medium SVM & 0.976896 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            Gaussian Coarse SVM & 0.967855 & 1\\textasciitilde 3 mins\\\\\n            \\hline\n            \\hline\n            Fully Connected NN & 0.979407 & 30 secs\\\\\n            \\hline\n            Logistic Regression & 0.952788 & 5\\textasciitilde 10 mins\\\\\n            \\hline\n            \\hline\n            Naive Bayes Classifier & 0.760924 & 5 secs\\\\\n            \\hline\n            \\end{tabular}\n            \\caption{Accuracy on testing set}\n        \\end{table}\n    }\n\n    \\subsection*{FCNN-based classifiers}\n    {\n        In homework 4, we tried different sizes of the hidden layer, ranging from $5$, $10$, $20$, $40$, to $100$. Here is a copy of our conclusion in homework 4:\n\n        \\begin{itemize}\n            \\item \\textbf{Confusion matrix:}\\quad With more hidden nodes, the confusion rate drops accordingly. See the table below. \n            \\begin{table}[htb!]\n                \\centering\n                \\begin{tabular}{|c|c|}\n                \\hline\n                Hidden nodes & Total confusion rate \\\\\n                \\hline\n                5 & 11.5\\% \\\\\n                \\hline\n                10 & 8.9\\% \\\\\n                \\hline\n                20 & 5.6\\% \\\\\n                \\hline\n                40 & 2.9\\% \\\\\n                \\hline\n                100 & 1.9\\% \\\\\n                \\hline\n                \\end{tabular}\n                \\caption{Confusion rates}\n            \\end{table}\n\n            \\item \\textbf{Performance:}\\quad With more hidden nodes, the error rates drop at both validation set and testing set. Meanwhile, it takes a longer time before it stops and converges, in spite of fewer iterations. Another interpretation: The network has better capability of fitting the pattern with more hidden nodes, and therefore the training process is smoother and we need fewer iterations in training. But it takes more time since we have much more parameters to train, which leads to a longer time for each iteration step. \n            \\begin{table}[htb!]\n                \\centering\n                \\begin{tabular}{|c|c|}\n                \\hline\n                Hidden nodes & Total training epochs \\\\\n                \\hline\n                5 & 500 \\\\\n                \\hline\n                10 & 185 \\\\\n                \\hline\n                20 & 125 \\\\\n                \\hline\n                40 & 125 \\\\\n                \\hline\n                100 & 110 \\\\\n                \\hline\n                \\end{tabular}\n                \\caption{Training iterations}\n            \\end{table}\n\n            \\item \\textbf{ROC curve:}\\quad With more hidden nodes, the ROC curve is closer to the left top corner, which indicates a better performance of classification. \n        \\end{itemize}\n\n        It is obvious that a size of $100$ hidden nodes makes the best performance. The accuracy on the testing set is attached to Table 1.\n    }\n\n    \\subsection*{Logistic-regression-based classifiers}\n    {\n        We use the logistic regression classifier in the Classification Learner toolbox. The accuracy on the testing set is attached to Table 1.\n    }\n\n    \\subsection*{Naive Bayes classifiers}\n    {\n        There is no toolbox provided, so we manually call ``fitcnb'' function in MATLAB to train a naive Bayes model. The accuracy on the testing set is attached to Table 1. The training speed is ultrafast, only seconds.\n    }\n\n    \\subsection*{Comparison}\n    {\n        We obtain the testing accuracy, as well as the training speed, in Table 1. \n        \n        \\begin{itemize}\n            \\item \\textbf{SVM:}\\quad The SVM-based classifier with a cubic kernel function achieves the highest accuracy on the testing set. The SVM with a fine Gaussian kernel has been overfitting the data, since $\\sigma=0.1$ is too small and it makes the exponential term decay too fast. However, it takes minutes to train the model, which is not so competitive as the FCNN in terms of training speed.\n\n            \\item \\textbf{FCNN and LR:}\\quad Fully connected neural network with a hidden layer of 100 nodes also attains a high accuracy, with a training process faster than the SVMs above. It overwhelms the logistic regression model, which can be interpreted as a FCNN with no hidden layer. Here we see the crutial importance of the hidden layer. The additional layer provides a high capacity when fitting nonlinear function. \n        \n            \\item \\textbf{Naive Bayes:}\\quad The accuracy is not satisfactory, but it is super fast in training, much faster than other methods. I suppose that possible ways to improve this include feature selection and PCA. It also helps if we use advanced Bayes classifiers in place of the Naive Bayes classifier. \n        \\end{itemize}\n\n    }\n}\n\n\\section*{Source Code}\n{\n    Please download the souece code from http://39.106.23.58/files/PR5\\_2015011506.7z\n\n    For Question 2, please run ``main.m''. It may take minutes to train the network, but the result is reproducible because of the random seed.\n\n    For each model, I clicked ``Generate code'' button to transcript my operations into MATLAB codes, and stored each of them in the corresponding ``.m'' file. These files include:\n    \\begin{itemize}\n        \\item trainClassifierCubic.m\n        \\item trainClassifierLinear.m\n        \\item trainClassifierQuadratic.m\n        \\item trainClassifierGaussianFine.m\n        \\item trainClassifierGaussianMedium.m\n        \\item trainClassifierGaussianCoarse.m\n        \\item trainClassifierFullyConnected.m\n        \\item trainClassifierLogistic.m\n    \\end{itemize}\n    Thus, the steps above can be easily reproduced without using the GUI of the toolbox. \n\n}\n\n\\clearpage\n\\end{document}\n    ", "meta": {"hexsha": "b14d7caf55b1685dc70b8f8389738e40343e6da7", "size": 9028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW5/Homework5.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": "HW5/Homework5.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": "HW5/Homework5.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": 49.3333333333, "max_line_length": 541, "alphanum_fraction": 0.6462117856, "num_tokens": 2315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8705972600147106, "lm_q1q2_score": 0.7921625441979725}}
{"text": "\\chapter{Matrix manipulation}\n\\label{ChMatrix}\n\nIt is convenient to represent multivariate data by means of $n \\times p$ matrix such as $\\boldsymbol{X}$.  We could consider the \\texttt{USArrests} data in this way.   We follow the convention of using $n$ to denote the number of rows of individuals who have been observed, and $p$ to denote the number of columns (variables).   %Geneticists do this all back to front and put genes on the rows and individuals on the columns.   %This is a real nuisance, and is what happens when people insist on reinventing the wheel. \nWe will formalise some some aspects from linear algebra that will be important in understanding multivariate analysis.   These are very brief notes, there is a wealth of readable material on linear algebra as well as material specific for statistical applications such as \\cite{Healy:2000} and \\cite{Schott:1997}.   There is also an interesting presentation from a more geometric perspective in \\cite{Wickens:1995} which supplements more algebraic presentations of matrix concepts.\n\n\\section{Vectors}\n\\label{vectors}\n\nConsider a vector $\\boldsymbol{x} \\in \\mathbb{R}^{p}$, by convention this is thought of as a column vector:\n\n\\begin{displaymath}\n\\boldsymbol{x}  = \\left(\\begin{array}{r} x_{1} \\\\ x_{2} \\\\ \\vdots \\\\ x_{n} \\end{array}\\right)\n\\end{displaymath}\n\n A row vector such as $\\left(\\begin{array}{rrrr} x_{1} & x_{2} & \\ldots & x_{n} \\end{array} \\right)$ will be denoted by $\\boldsymbol{x}^{T}$.\n\nA vector is a basic unit of numbers within \\R, but the \\R objects don't entirely conform to a formal mathematical definition (look at the way vecctor recycling works for example) and some caution is needed.   The following instruction:\n\\singlespacing\n\\begin{verbatim}\n> x <- c(3.289, 4.700, 10.400) \n\\end{verbatim}\n\\onehalfspacing\nassigns the values to the object \\verb+x+ creating the following \\R vector:\n\n\\begin{displaymath}\n\\boldsymbol{x} = \\left( \\begin{array}{r} 3.289 \\\\  4.700 \\\\ 10.400 \\end{array} \\right)\n\\end{displaymath}\n\nThe default print method in \\R gives these in the most compact form:\n\\singlespacing\n\\begin{verbatim}\n> x \n[1]  [1]  3.289  4.700 10.400\n\\end{verbatim}\n\\onehalfspacing\nbut forcing this into a matrix object with \\verb+as.matrix()+ confirms its dimensionality:\n\\singlespacing\n\\begin{verbatim}\n> as.matrix(x)\n       [,1]\n[1,]  3.289\n[2,]  4.700\n[3,] 10.400\n\\end{verbatim}\n\\onehalfspacing\nand taking the transpose of this vector using \\verb+t()+ does produce a row vector as expected:\n\\singlespacing\n\\begin{verbatim}\n> t(x)\n      [,1] [,2] [,3]\n[1,] 3.289  4.7 10.4\n\\end{verbatim}\n\\onehalfspacing\n\n\n\\subsection{Vector multiplication; the inner product}\n\\label{vectormult}\n\nWe first define the inner product of two vectors.   For $\\boldsymbol{x}, \\boldsymbol{y} \\in  \\mathbb{R}^{p}$ this gives a scalar:\n\n\\begin{displaymath}\n\\langle \\boldsymbol{x}, \\boldsymbol{y} \\rangle = \\boldsymbol{x}^{T}\\boldsymbol{y} = \\sum_{j=1}^{p}x_{j}y_{j} = \\boldsymbol{y}^{T}\\boldsymbol{x}\n\\end{displaymath}\n\nIn other words, we find the product of corresponding elements of each vector (the product of the first element of the row vector and the first element of the column vector), and then find the sum of all these products:   \n\n\\begin{displaymath}\n\\left(\n\\begin{array}{rrrr}\nx_{1} & x_{2} & \\ldots & x_{n}\n\\end{array}\n\\right)\n\\left(\n\\begin{array}{r}\ny_{1}\\\\\ny_{2}\\\\\n\\ldots\\\\\ny_{n}\n\\end{array}\n\\right)\n=\n\\underbrace{x_{1}y_{1} + x_{2}y_{2} + \\ldots + x_{n}y_{n}}_{\\mbox{One number; the sum of all the individual products}}\n\\end{displaymath}\n\n\nTo give a simple example, with $\\boldsymbol{x}^{T} = (4,1,3,2)$ and $\\boldsymbol{y} = \\left( \\begin{array}{r} 1 \\\\ -1 \\\\ 3 \\\\ 0 \\end{array} \\right)$ we have:\n\n\\begin{displaymath}\n\\left(\n\\begin{array}{rrrr}\n4 & 1 & 3 & 2\n\\end{array}\n\\right) \\times\n\\left(\n\\begin{array}{r}\n1\\\\\n-1\\\\\n3\\\\\n0\n\\end{array}\n\\right)\n=\n\\underbrace{4 \\times 1 + 1 \\times (-1) + 3 \\times 3 + 2 \\times 0} = 12\n\\end{displaymath}\n\nIn \\R the inner product can be simply obtained using \\verb+%*%+, for example:\n\\singlespacing\n\\begin{verbatim}\n> x <- c(4, 1, 3, 2)\n> y <- c(1, -1, 3, 0)\n> t(x) %*% y\n     [,1]\n[1,]   12\n\\end{verbatim}\n\\onehalfspacing\nwhich returns the answer as a scalar.   Note that using \\verb+*+ without the enclosing \\verb+%%+ yields a vector of the same length of $\\boldsymbol{x}$ and $\\boldsymbol{y}$ where each element is the product of the corresponding elements of $\\boldsymbol{x}$ and $\\boldsymbol{y}$, and may do other unexpected things using vector recycling.\n\n\\subsection{Outer product}\n\nNote that if $\\boldsymbol{x}^{T}\\boldsymbol{y}$ is the inner product of two vectors $\\boldsymbol{x}$ and $\\boldsymbol{y}$, the \\emph{outer} product is given by  $\\boldsymbol{x}\\boldsymbol{y}^{T}$.   For vectors, it can be computed by \\verb+x %*% t(y)+; but as we will find later, outer product operations are defined for arrays of more than one dimension as \\verb+x %o% y+ and \\verb+outer(x,y)+ \n\n\\subsection{Vector length}\n\\label{vectorlength}\n\nAn important concept is the length of a vector, also known as the Euclidean norm or the modulus.   It is based on a geometric idea and expresses the distance of a given vector from the origin:\n\n\\begin{displaymath}\n|\\boldsymbol{x}| = \\langle \\boldsymbol{x}, \\boldsymbol{x} \\rangle^{1/2} = \\left( \\sum_{j=1}^{p} x_{j}^{2} \\right)^{1/2}\n\\end{displaymath}\n\nA \\emph{normalised} vector is one scaled to have unit length, for the vector $\\boldsymbol{x}$ this can be found by taking $\\frac{1}{|\\boldsymbol{x}|} \\boldsymbol{x}$ which is trivial in \\R:\n\\singlespacing\n\\begin{verbatim}\n> z <- x / sqrt(t(x) %*% x)\n> z\n[1] 0.7302967 0.1825742 0.5477226 0.3651484\n> t(z) %*% z ## check the length of the normalised vector\n     [,1]\n[1,]    1\n\\end{verbatim}\n\\onehalfspacing\n\n\\subsection{Orthogonality}\n\\label{orthogonality}\n\nTwo vectors \\textbf{x} and \\textbf{y}, of order $k \\times 1$ are orthogonal if $\\boldsymbol{x y} = 0$.   Furthermore, if two vectors $\\boldsymbol{x}$ and  $\\boldsymbol{y}$ are orthogonal \\emph{and} of unit length, i.e. if $\\boldsymbol{x y} = 0$,  $\\boldsymbol{x}^{T} \\boldsymbol{x} = 1$ and  $\\boldsymbol{y}^{T} \\boldsymbol{y} = 1$ then they are orthonormal.\n\nMore formally, a set $\\{\\boldsymbol{e}_{i}\\}$ of vectors in $\\mathbb{R}^{p}$ is orthonormal if\n\\begin{displaymath}\n\\boldsymbol{e}_{i}^{T}\\boldsymbol{e}_{j} = \\delta_{ij} = \\left\\{ \\begin{array}{ccc} \n0, && i \\neq j\\\\\n1, && i = j \\end{array} \\right.\n\\end{displaymath}\nWhere $\\delta_{ij}$ is referred to as the Kronecker delta.\n\n\\subsection{Cauchy-Schwartz Inequality}\n\\label{cauchyschwartz}\n\n\\begin{displaymath}\n\\langle \\boldsymbol{x}, \\boldsymbol{y} \\rangle \\leq |\\boldsymbol{x}|\\ |\\boldsymbol{y}|, \\mbox{ for all } \\boldsymbol{x}, \\boldsymbol{y} \\in \\mathbb{R}\n\\end{displaymath}\nwith equality if and only if $\\boldsymbol{x} = \\lambda \\boldsymbol{y}$ for some $\\lambda \\in \\mathbb{R}$.   Proof of this inequality is given in many multivariate textbooks such as \\cite{Bilodeau+Brenner:1999}.   We won't use this result itself, but will actually consider the extended Cauchy-Scwartz inequality later.\n\n\\subsection{Angle between vectors}\n\\label{angle}\n\nThe cosine of the angle between two vectors is given by:\n\n\\begin{displaymath}\n\\cos(\\theta) = \\frac{\\langle \\boldsymbol{x}, \\boldsymbol{y} \\rangle}{|\\boldsymbol{x}|\\ |\\boldsymbol{y}|}\n\\end{displaymath}\n\nIt can be conveniently calculated in \\R:\n\\singlespacing\n\\begin{verbatim}\n> cor(x,y)\n\\end{verbatim}\n\\onehalfspacing\n\n\n\n\\section{Matrices}\n\\label{matrices}\n\n%\\begin{quotation}\n%Points in this section:\n%\\begin{itemize}\n%\\item Matrices can be denoted by a bold capital letter (vectors by a bold lower case letter).\n%\\item Matrix dimensions are given as rows $\\times$ columns\n%\\item How to transpose matrices\n%\\end{itemize}\n%\\end{quotation}\n\nWe now consider some basic properties of matrices, and consider some basic operations on them that will become essential as we progress.   Consider the data matrix $\\boldsymbol{X}$, containing the \\verb+USArrests+ data, a $50 \\times 4$ matrix, i.e. with $n=50$ rows refering to States and $p=4$ columns refering to the variables measuring different arrest rates.   To indicate the order of this matrix it could be described fully as $\\boldsymbol{X}_{50,4}$; this convention is followed in \\R as a call to \\verb+dim(USArrests)+ will confirm.   Each element in this matrix can be denoted by $x_{ij}$ where $i$ denotes the particular row (here state) and $j$ the particular column (here arrest rate).   Hence $x_{6\\ 3} = 38.7$.\n\nIn order to create a matrix in \\R the dimension has to be specified in the call to \\verb+matrix()+.   It should be very carefully noted that the default is to fill a matrix by columns, as indicated here:\n\\singlespacing\n\\begin{verbatim}\n> mydata <- c(1,2,3,4,5,6)\n> A <- matrix(mydata, 3,2)\n> A\n     [,1] [,2]\n[1,]    1    4\n[2,]    2    5\n[3,]    3    6\n\\end{verbatim}\n\\onehalfspacing\nIf this is not convenient, \\R can be persuaded to fill matrices by rows rather than by columns by including the argument \\verb+byrow = TRUE+ in the call to \\verb+matrix+.   It is also possible to coerce other objects (such as data frames) to a matrix using \\verb+as.matrix()+ and \\verb+data.matrix()+; the former producing a character matrix if there are any non-numeric variables present, the latter coercing everything to a numeric format.\n\n\\subsection{Transposing matrices}\n\\label{matrixtranspose}\n\nTransposing matrices simply involves turning the first column into the first row.   A transposed matrix is denoted by a superscripted $T$, in other words $\\mathbf{A^{T}}$ is the transpose of $\\mathbf{A}$.\n\n\\begin{displaymath}\nIf\\ \\mathbf{A} = \\left(\n\\begin{array}{rr}\n3 &   1\\\\\n5 &    6\\\\\n4 &   4\n\\end{array}\n\\right)\n\\ \\mbox{then}\\ \\mathbf{A^{T}} =\n\\left( \\begin{array}{rrr}\n3 &   5 &   4\\\\\n1 &   6  &  4\n\\end{array}\n\\right)\n\\end{displaymath}\n\nAs with vectors, transposing matrices in \\textbf{R} simply requires a call to \\verb+t()+, the dimensions can be checked with  \\verb+dim()+.\n\n\\singlespacing\n\\begin{verbatim}\n> Atrans <- t(A)\n> Atrans\n     [,1] [,2] [,3]\n[1,]    1    2    3\n[2,]    4    5    6\n> dim(Atrans)\n[1] 2 3\n\\end{verbatim}\n\\onehalfspacing\n\n\n\\subsection{Some special matrices}\n\\label{specialmatrix}\n\n\\subsection{Symmetric matrices}\n\nWe mention a few ``special'' matrix forms that will be encountered.   We firstly note that \\emph{symmetric} matrices are symmetric around the diagonal $i=j$.  For matrix $\\boldsymbol{A}$, it is symmetric whenever $a_{ij} = a_{ji}$.    The correlation matrix and the variance-covariance matrix are the most common symmetric matrices we will encounter, we will look at them in more detail later, for now note that we can obtain the (symmetric) correlation matrix as follows:\n\\begin{verbatim}\n> cor(USArrests)\n             Murder   Assault   UrbanPop      Rape\nMurder   1.00000000 0.8018733 0.06957262 0.5635788\nAssault  0.80187331 1.0000000 0.25887170 0.6652412\nUrbanPop 0.06957262 0.2588717 1.00000000 0.4113412\nRape     0.56357883 0.6652412 0.41134124 1.0000000\n\\end{verbatim}\n\n\\subsection{Diagonal Matrices}\n\nGiven it's name, it is perhaps obvious that a diagonal matrix has elements on the diagonal (where $i = j$) and zero elsewhere (where $i \\neq j$).   For example, the matrix $\\boldsymbol{A}$ given as follows:\n\\begin{displaymath}\n\\mathbf{A} = \n\\left( \\begin{array}{rrr}\n13 & 0 & 0\\\\\n0 & 27 &  0\\\\\n0 & 0 & 16\n\\end{array}\n\\right)\n\\end{displaymath}\nis a diagonal matrix.   To save paper and ink, $\\boldsymbol{A}$ can also be written as:\n\\begin{displaymath}\n\\mathbf{A} = \ndiag \\left( \\begin{array}{rrr}\n13 & 27 & 16\n\\end{array}\n\\right)\n\\end{displaymath}\n\nIt is worth noting that the \\verb+diag()+ command in \\R, as shown below, lets you both \\emph{overwrite} the diagonal elements of matrix and \\emph{extract} the diagonal elements depending how it is used:\n\\singlespacing\n\\begin{verbatim}\n> mydataD <- c(13, 27, 16)\n> B <- diag(mydataD)\n> B\n     [,1] [,2] [,3]\n[1,]   13    0    0\n[2,]    0   27    0\n[3,]    0    0   16\n> diag(B)\n[1] 13 27 16\n\\end{verbatim}\n\\onehalfspacing\nIt is also worth noting that when ``overwriting'', the size of the matrix to be over-written can be inferred from the dimensionality of diagonal.   \n\n\\subsection{Identity Matrix}\n\nOne special diagonal matrix is the identity matrix, which has a value of 1 at each position on the diagonal and 0 elsewhere.   Here, all we need to know is the size.   So $\\mathbf{I_{4}}$ tells us that we have the following matrix:\n\\begin{displaymath}\n\\mathbf{I_{4}} = \n\\left( \\begin{array}{rrrr}\n1 & 0 & 0 & 0\\\\\n0 & 1 &  0 & 0\\\\\n0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 1\n\\end{array}\n\\right)\n\\end{displaymath}\n\nThis can be created in a variety of ways in \\R, such as \\verb+I4 <- diag(rep(1,4))+\n\n\\subsection{Ones}\n\nWe also need to define a vector of ones; $\\boldsymbol{1}_{p}$, a $p \\times 1$ matrix containing only the value 1.   There is no inbuilt function in \\textbf{R} to create this vector, it is easily added:\n\\singlespacing\n\\begin{verbatim}\n> ones <- function(p){\n  Ones <- matrix(1,p,1)\n  return(Ones)\n}\n\\end{verbatim}\n\\onehalfspacing\n\n\\subsection{Zero matrix}\n\nFinally, $\\mathbf{0}$ denotes the zero matrix, a matrix of zeros.   Unlike the previously mentioned matrices this matrix can be any shape you want.   So, for example:\n\\begin{displaymath}\n\\mathbf{0_{2\\ 3}} = \n\\left( \\begin{array}{rrr}\n0 & 0 & 0 \\\\\n0 & 0 &  0 \\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\n\n\\subsection{Equality and addition}\n\\label{matrixaddition}\n\n%\\begin{quotation}\n%Ensure you are happy with:\n%\\begin{itemize}\n%\\item Equality of matrices\n%\\item Addition and subtraction of matrices\n%\\end{itemize}\n%\\end{quotation}\n\nA little more care is needed in defining basic mathematical operations on matrices.   Considering the two matrices $\\boldsymbol{A}$ and $\\boldsymbol{B}$, we consider their equality $\\boldsymbol{A} = \\boldsymbol{B}$ if any only if:\n\\begin{itemize}\n\\item $\\boldsymbol{A}$ and $\\boldsymbol{B}$ have the same size, and\n\\item the $ij$th element of $\\boldsymbol{A}$ is equal to the $ij$th element of $\\boldsymbol{A}$ for all $1 \\leq i \\leq r$ and $1 \\leq j \\leq n$\n\\end{itemize}\n\nA consequence of this is that the following two matrices are equal:\n\\begin{displaymath}\n\\left[ \\begin{array}{rrr}\n138.8149 & 187.52 & 394.86\\\\\n187.5200 & 267.00 &  559.00\\\\\n394.8600 & 559.00 & 1200.00\\\n\\end{array}\n\\right]\n= \n\\left[ \\begin{array}{rrr}\n138.8149 & 187.52 & 394.86\\\\\n187.5200 & 267.00 &  559.00\\\\\n394.8600 & 559.00 & 1200.00\\\n\\end{array}\n\\right]\n\\end{displaymath}\n(which seems like an obvious and fussy thing to say) \\emph{but} the following two zero matrices are not equal:\n\\begin{displaymath} \n\\left( \\begin{array}{rrr}\n0 & 0 & 0 \\\\\n0 & 0 &  0 \\\\\n0 & 0 & 0 \\\\\n\\end{array}\n\\right)\n\\neq\n\\left( \\begin{array}{rrr}\n0 & 0 & 0 \\\\\n0 & 0 &  0 \\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\n%\\subsection{Matrix addition}\n\n Adding and subtracting are fairly straightforward.   Provided $\\boldsymbol{A}$ and $\\boldsymbol{A}$ have the same size, $\\boldsymbol{A} + \\boldsymbol{B}$ and $\\boldsymbol{A} - \\boldsymbol{B}$ are defined by each of these operations being carried out on individual elements of the matrix.   For example:\n\\begin{displaymath}\n\\left( \\begin{array}{rrr}\n1 & 3 & 5\\\\\n2 & 4 &  6\\\\\n\\end{array}\n\\right)\n+\n\\left( \\begin{array}{rrr}\n0 & 2 & 3\\\\\n-1 & -2 &  -3\\\\\n\\end{array}\n\\right)\n=\n\\left( \\begin{array}{rrr}\n1 + 0 & 3 + 2 & 5 + 3\\\\\n2 + -1 & 4 + -2 &  6 + -3\\\\\n\\end{array}\n\\right) = \n\\left( \\begin{array}{rrr}\n1 & 5 & 8\\\\\n1 & 2 &  3\\\\\n\\end{array}\n\\right)\n\\end{displaymath}\nand\n\\begin{displaymath}\n\\left( \\begin{array}{rrr}\n1 & 3 & 5\\\\\n2 & 4 &  6\\\\\n\\end{array}\n\\right)\n-\n\\left( \\begin{array}{rrr}\n0 & 2 & 3\\\\\n-1 & -2 &  -3\\\\\n\\end{array}\n\\right)\n=\n\\left( \\begin{array}{rrr}\n1 & 1 & 2\\\\\n3 & 6 &  9\\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\n\nAddition and subtraction are straightforward enough in \\R:\n\\singlespacing\n\\begin{verbatim}\n> A <- matrix(c(1,2,3,4,5,6),2,3)\n> A\n     [,1] [,2] [,3]\n[1,]    1    3    5\n[2,]    2    4    6\n> B <- matrix(c(0,-1,2,-2,3,-3),2,3)\n> B\n     [,1] [,2] [,3]\n[1,]    0    2    3\n[2,]   -1   -2   -3\n> A + B\n     [,1] [,2] [,3]\n[1,]    1    5    8\n[2,]    1    2    3\n> A - B\n     [,1] [,2] [,3]\n[1,]    1    1    2\n[2,]    3    6    9\n\\end{verbatim}\n\\onehalfspacing\n\nMatrix addition follows all the normal arithmetic rules, i.e.\n\\begin{eqnarray*}\n\\mbox{Commutative law} && \\mathbf{A} + \\mathbf{B} = \\mathbf{B} + \\mathbf{A}\\\\\n\\mbox{Associative law} && \\mathbf{A} + (\\mathbf{B} + \\mathbf{C}) = (\\mathbf{A} + \\mathbf{B}) + \\mathbf{C}\n\\end{eqnarray*}\n\nMatrix multiplication however follows vector multiplication and therefore does not follow the same rules as basic multiplication.\n\n\\subsection{Multiplication}\n\n%\\subsection{Scalar multiplication}\n%\\subsection{Scalars}\n \nA scalar is a matrix with just one row and one column, i.e. a single number.   In other words, 0.4 could be a scalar or a $1\\times1$ matrix.   It's worth re-capping that multiplication by a scalar is easy enough, we just multiply every element in the matrix by the scalar.\n\nSo if $\\mathbf{k} = 0.4$, and \n\\begin{displaymath}\n\\mathbf{A} = \n\\left( \\begin{array}{rrr}\n1 & 5 & 8\\\\\n1 & 2 &  3\\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\nwe can calculate $\\mathbf{kA}$ as:\n\n\\begin{displaymath}\n\\mathbf{kA} = 0.4 \\times\n\\left( \\begin{array}{rrr}\n1 & 5 & 8\\\\\n1 & 2 &  3\\\\\n\\end{array}\n\\right)\n=\n\\left( \\begin{array}{rrr}\n0.4 & 2 & 3.2\\\\\n0.4 & 0.8 &  1.6\\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\n%\\subsection{Matrix multiplication}\n\nWhen multiplying two matrices, it should be noted first that they must be conformable.   The number of columns in the first matrix must match the number of rows in the second.   As matrix multiplication has been defined, the result will be a matrix with as many rows as the first matrix and as many columns as the second.   For example, with our vectors above in section \\ref{vectormult} , we had $\\boldsymbol{A_{1\\ 4}} \\times \\boldsymbol{B_{4\\ 1}} = \\boldsymbol{C_{1\\ 1}}$.   More generally multiplication proceeds with matrix size as follows: $\\boldsymbol{A_{m\\ n}} \\times \\boldsymbol{B_{n\\ p}} = \\boldsymbol{C_{m\\ p}}$.\n\nIt \\emph{may} help to think about the vector operations and extend them to matrices.   There are other ways of thinking about matrix multiplication, most multivariate text books have an appendix on matrix algebra and there are vast tomes available covering introductory linear algebra.   However, one explanation of matrix multiplication is given here.   We want to find $\\boldsymbol{A} \\times  \\boldsymbol{B}$ where\n\\begin{displaymath}\n\\mathbf{A} = \n\\left( \\begin{array}{rr}\n1 & 5 \\\\\n1 & 2 \\\\\n3 & 8 \\\\\n\\end{array}\n\\right)\n\\ \\mbox{and}\\ \\mathbf{B} = \n\\left( \\begin{array}{rr}\n1 & 4 \\\\\n3 & 2 \\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\nIf \\textbf{A} is of size $m \\times n$ it could be considered as consisting of a row of vectors $\\boldsymbol{a_{1}^{T}}, \\boldsymbol{a_{1}^{T}}, \\ldots, \\boldsymbol{a_{m}^{T}}$, which in this case corresponds to $\\boldsymbol{a_{1}^{T}} = (1,5), \\boldsymbol{a_{2}^{T}} = (1,2)$ and $\\boldsymbol{a_{3}^{T}} = (3,8)$.   Likewise, we can consider $\\mathbf{B}$ consisting of $\\boldsymbol{b_{1}} = \\left( \\begin{array}{r} 1\\\\4 \\end{array} \\right)$ and  $\\boldsymbol{b_{1}} = \\left( \\begin{array}{r} 3\\\\2 \\end{array} \\right)$.   In other words, we are trying to multiply together:\n\\begin{displaymath}\n\\mathbf{A} = \n\\left( \\begin{array}{r}\na_{1}^{T} \\\\\na_{2}^{T}\\\\\na_{3}^{T}\\\\\n\\end{array}\n\\right)\n\\mbox{and}\\ \\mathbf{B} = \n\\left( \\begin{array}{rr}\nb_{1} & b_{2}\n\\end{array}\n\\right)\n\\end{displaymath}\n\n\nWe can define the multiplication operation for matrices generally as:\n\n\\begin{displaymath}\n\\mathbf{AB} = \n\\left( \\begin{array}{r}\na_{1}^{T} \\\\\na_{2}^{T}\\\\\n\\ldots\\\\\na_{m}^{T}\\\\\n\\end{array}\n\\right)\n\\left( \\begin{array}{rrrr}\nb_{1} & b_{2} & \\ldots & b_{p}\n\\end{array}\n\\right)\n=\n\\left( \\begin{array}{rrrr}\na_{1}^{T}b_{1} & a_{1}^{T}b_{2} & \\ldots & a_{1}^{T}b_{p} \\\\\na_{2}^{T}b_{1} & a_{2}^{T}b_{2} & \\ldots &  a_{1}^{T}b_{p}\\\\\n\\vdots & \\vdots & & \\vdots  \\\\\na_{3}^{T}b_{1} & a_{3}^{T}b_{2} & \\ldots &  a_{m}^{T}b_{p}\\\\\n\\end{array}\n\\right)\n\\end{displaymath}\n\nIn other words, we need to multiply row $i$ of $\\boldsymbol{A}$ by column $j$ of $\\boldsymbol{B}$ to give element $ij$ of the result.   For example, note that $\\boldsymbol{a_{1}^T}\\boldsymbol{b_{1}} = \\left(\\begin{array}{rr}1 & 5  \\end{array}\\right) \\left( \\begin{array}{r}1 \\\\4 \\end{array}\\right) = 1 \\times 1 + 5 \\times 3 = 16$.   Carrying out this operation on our matrices above gives:\n\\begin{displaymath}\n\\mathbf{AB} = \n\\left( \\begin{array}{rr}\n1 & 5 \\\\\n1 & 2 \\\\\n3 & 8 \\\\\n\\end{array}\n\\right)\n\\left( \\begin{array}{rr}\n1 & 4 \\\\\n3 & 2 \\\\\n\\end{array}\n\\right)\n=\n\\left(\n\\begin{array}{rr}\n 16 &  14\\\\\n 7  &  8\\\\\n 27 &  28\n\\end{array}\n\\right)\n\\end{displaymath}\n\n\nIn \\R, we only need to use the \\verb+%*%+ operator to ensure we are getting matrix multiplication:\n\\singlespacing\n\\begin{verbatim}\n> A <- matrix(c(1,1,3,5,2,8),3,2)\n> A\n     [,1] [,2]\n[1,]    1    5\n[2,]    1    2\n[3,]    3    8\n> B <- matrix(c(1,3,4,2),2,2)\n> B\n     [,1] [,2]\n[1,]    1    4\n[2,]    3    2\n> A %*% B\n     [,1] [,2]\n[1,]   16   14\n[2,]    7    8\n[3,]   27   28\n\\end{verbatim}\n\\onehalfspacing\n\nNote that you can't multiply non-conformable matrices; this is one place in \\R where you get a clearly informative error message:\n\\singlespacing\n\\begin{verbatim}\n> B %*% A\nError in B %*% A : non-conformable arguments\n\\end{verbatim}\n\\onehalfspacing\n\nIt is particularly important to use the correct \\emph{matrix multiplication} argument.   Depending on the matrices you are working with (if they both have the same dimensions), using the usual \\verb+*+ multiplication operator will give you the Hadamard product, the element by element product of the two matrices which is rarely what you want:\n\\singlespacing\n\\begin{verbatim}\n> C <- matrix(c(1,1,3,5),2,2)\n> C %*% B ## correct call for matrix multiplication\n     [,1] [,2]\n[1,]   10   10\n[2,]   16   14\n> C * B ## Hadamard Product!!!\n     [,1] [,2]\n[1,]    1   12\n[2,]    3   10\n\\end{verbatim}\n\\onehalfspacing\n\n\n\n%\\subsection{Some slightly obscure stuff}\n\nWe saw earlier that matrix addition was commutative and associative.   But as you can imagine, given the need for comformability some differences may be anticipated between conventional multiplication and matrix multiplication.   Generally speaking, matrix multiplication is not commutative (you may like to think of exceptions):\n\n\\begin{eqnarray*}\n\\mbox{(non-commutative)} &&\\mathbf{A} \\times \\mathbf{B} \\neq \\mathbf{B} \\times \\mathbf{A}\\ \\\\\n\\mbox{Associative law} && \\mathbf{A} \\times (\\mathbf{B} \\times \\mathbf{C}) = (\\mathbf{A} \\times \\mathbf{B}) \\times \\mathbf{C}\n\\end{eqnarray*}\n\nAnd the distributive laws of multiplication over addition apply as much to matrix as conventional multiplication:\n\n\\begin{eqnarray*}\n\\mathbf{A} \\times (\\mathbf{B} + \\mathbf{C}) = (\\mathbf{A} \\times \\mathbf{B}) + (\\mathbf{A} \\times \\mathbf{C}) \\\\\n(\\mathbf{A} + \\mathbf{B}) \\times \\mathbf{C} = (\\mathbf{A} \\times \\mathbf{C}) + (\\mathbf{B} \\times \\mathbf{C})\n\\end{eqnarray*}\n\n\nBut there are a few pitfalls if we start working with transposes.   Whilst\n\\begin{displaymath}\n(\\mathbf{A} + \\mathbf{B})^{T} = \\mathbf{A}^{T} + \\mathbf{B}^{T}\n\\end{displaymath}\nnote that:\n\\begin{displaymath}\n(\\mathbf{A} \\times \\mathbf{B})^{T} = \\mathbf{B}^{T} \\times \\mathbf{A}^{T}\n\\end{displaymath}\n\n\n\n\\subsection{Trace of a matrix}\n\nThe trace of a matrix is the quite simply the sum of its diagonal elements.   This is an interesting concept in many ways, but it turns out in one specific context, when applied to the covariance matrix, this has an interpretation as the total sample variance.   There is no inbuilt function in \\R to calculate this value, you need to use \\verb+sum(diag(X))+\n\nNote that if you have two conformable matrices $\\boldsymbol{A}$ $\\mbox{e.g.}\\ \\left( \\begin{array}{rr} 2 & 5 \\\\ 0 & 7 \\\\ 4 & 3\\\\ \\end{array} \\right)$ and $\\boldsymbol{B}$ $\\mbox{e.g.}\\ \\left( \\begin{array}{rrr} 4 & 2 & 1 \\\\ 6 & 3 & 2 \\end{array} \\right)$, $trace(\\boldsymbol{AB}) = trace(\\boldsymbol{BA})$\n\n\n\n\\section{Crossproduct matrix}\n\nGiven the data matrix $\\boldsymbol{X}$, the crossproduct, sometimes more fully referred to as the ``sum of squares and crossproducts'' matrix is given by $\\boldsymbol{X}^{T}\\boldsymbol{X}$.   The diagonals of this matrix are clearly the sum of squares of each column.   Whilst this can be computed in \\R using \\verb+X %*% t(X)+ there are some computational advantages in using the dedicated function \\verb+crossprod(X)+   For example, coercing the \\verb+USArrests+ data to a matrix we can obtain the sum of squares and crossproducts matrix for these data as follows:\n\\singlespacing\n\\begin{verbatim}\nB <- crossprod(as.matrix(USArrests))\n\\end{verbatim}\n\\onehalfspacing\n\nSo if $\\boldsymbol{X}$ is the \\verb+USArrests+ data, \n\n\\begin{displaymath}\n\\boldsymbol{X^{T}X} = \\left[ \\begin{array}{rrrr}\n3962.20 & 80756.00 & 25736.20 & 9394.32 \\\\\n80756.00 & 1798262.00 & 574882.00 & 206723.00 \\\\\n25736.20 & 574882.00 & 225041.00 & 72309.90 \\\\\n9394.32 & 206723.00 & 72309.90 & 26838.62 \\\\\n\\end{array}\n\\right]\n\\end{displaymath}\n\n%(If you square each of the values for murder arrests, and then sum them you get 3962.2.   If you multiply the murder arrests by the corresponding assault arrests you get 80756.0 and so on).   Firstly, note that this matrix is square (there as many columns as rows).  But also note that this is an example of a symmetric matrix.  For example, the bottom left element is the same as the top right element, the second element in the first column is the same as the second element in the first row (you may also note that the line of symmetry runs from top left to bottom right).   Another example of a square matrix (we will be using it a lot) is the dispersion, or ``variance-covariance'' matrix.   Here:\n\nIf we define some sample estimators as follows:\n\n\\begin{equation}\n\\bar{\\boldsymbol{x}} = \\frac{1}{n} \\sum_{i=1}^{n} \\boldsymbol{x}_{i} = \\frac{1}{n} \\boldsymbol{X}^{T}\\boldsymbol{1}\n\\end{equation}\n\nSo for example we can find the sample mean for the USArrests data as:\n\\singlespacing\n\\begin{verbatim}\n> n <- dim(USArrests)[1] ## extract n; here 50\n> one <- ones(n)\n> 1/n * t(USArrests) %*% one\n> mean(USArrests) ## check results against in-built function\n\\end{verbatim}\n\\onehalfspacing\n\nWe can use matrix algebra to obtain an unbiased estimate of the sample covariance matrix $\\boldsymbol{S}$ as follows:\n\\begin{eqnarray*}\n\\boldsymbol{S} &=& \\frac{1}{n-1} \\sum_{i=1}^{n} (\\boldsymbol{x}_{i} - \\boldsymbol{\\bar{x}})^{T} (\\boldsymbol{x}_{i} - \\boldsymbol{\\bar{x}}) \\\\\n&=&   \\sum_{i=1}^{n} \\boldsymbol{x}_{i} \\sum_{i=1}^{n} \\boldsymbol{x}_{i}^{T} - \\boldsymbol{\\bar{x}}  \\boldsymbol{\\bar{x}}^{T}\\\\\n &=& \\frac{1}{n-1}\\boldsymbol{X}^{T}\\boldsymbol{X} - \\boldsymbol{\\bar{x}}  \\boldsymbol{\\bar{x}}^{T} \\\\\n&=& \\frac{1}{n-1} \\left( \\boldsymbol{X}^{T}\\boldsymbol{X} - \\frac{1}{n} \\boldsymbol{X}^{T} \\boldsymbol{1} \\boldsymbol{1}^{T} \\boldsymbol{X} \\right)\n\\end{eqnarray*}\n\nFrom this, we can define the centering matrix $\\boldsymbol{H}$:\n\\begin{displaymath}\n\\boldsymbol{H} = \\boldsymbol{I} - \\frac{1}{n} \\boldsymbol{1}\\boldsymbol{1}^{T}\n\\end{displaymath}\nand so arrive at an alternative expression for $\\boldsymbol{S}$ using this centering matrix:\n\n\\begin{equation}\n\\boldsymbol{S} = \\frac{1}{n-1}\\boldsymbol{X}^{T}\\boldsymbol{H} \\boldsymbol{X}\n\\end{equation}\n\n\\subsection{Idempotent matrices}\n\nIt may be noted that $\\boldsymbol{H}$ is idempotent, i.e.  $\\boldsymbol{H} = \\boldsymbol{H}^{T}$ and  $\\boldsymbol{H} = \\boldsymbol{H}^{2}$.\n\nIn calculating $\\boldsymbol{H}$ in $\\R$ it might be clearer to set the steps out in a function:\n\\singlespacing\n\\begin{verbatim}\ncentering <- function(n){\n I.mat <- diag(rep(1, n)) \n Right.mat <- 1/n * ones(n) %*% t(ones(n))\n H.mat <- I.mat - Right.mat\n return(H.mat)\n}\n\\end{verbatim}\n\\onehalfspacing\n\nAnd our matrix method for finding an estimate of the sample covariance using this centering procedure can also be set out in a function:\n\\singlespacing\n\\begin{verbatim}\nS.mat <- function(X, H){\nn <- dim(X)[1] ## number of rows\nH.mat <- centering(n)\nS <- 1/(n-1) * t(X) %*% H.mat %*% X\nreturn(S)\n}\n\\end{verbatim}\n\\onehalfspacing\n\nSo, to estimate the sample covariance with this function we need to make sure our data are in the form of matrix.   We also compare the results with the inbuilt function \\verb+cov()+:\n\\singlespacing\n\\begin{verbatim}\nX <- as.matrix(USArrests)\nS.mat(X)\ncov(USArrests)\n\\end{verbatim}\n\\onehalfspacing\n\nIt may be worth clarifying the information contained in the matrix we have just obtained.   The covariance matrix (more fully referred to as the variance-covariance matrix) contains information on the variance of each of the variables as well as information on pairwise covariance.   We will formalise our understanding of estimators later, but for now note that it could be considered as an estimate of:\n\\begin{displaymath}\n\\boldsymbol{\\Sigma} = \\boldsymbol{V} \\left( \n\\begin{array}{c} \nX_{1} \\\\ X_{2} \\\\ X_{3} \\\\ X_{4}\n\\end{array} \\right) = \n\\left( \n\\begin{array}{llll}\nvar(X_{1}) & cov(X_{1},X_{2})  & cov(X_{1},X_{3}) & cov(X_{1},X_{4})\\\\\ncov(X_{2},X_{1}) & var(X_{2}) & cov(X_{2},X_{3}) & cov(X_{2},X_{4})\\\\\ncov(X_{3},X_{1})  & cov(X_{3},X_{2})\\ & var(X_{3}) & cov(X_{3},X_{4})\\\\\ncov(X_{4},X_{1})  & cov(X_{4},X_{2})\\ &  cov(X_{4},X_{3}) & var(X_{4}) \\\\\n\\end{array} \n\\right)\n\\end{displaymath}\n\n\nFor the US Arrests data, as we have seen:\n\\begin{displaymath}\n\\boldsymbol{S} = \n\\left( \n\\begin{array}{rrrr}\n18.97 & 291.06 & 4.39 & 22.99 \\\\\n291.06 & 6945.17 & 312.28 & 519.27 \\\\\n4.39 & 312.28 & 209.52 & 55.77 \\\\\n22.99 & 519.27 & 55.77 & 87.73 \\\\\n\\end{array} \n\\right)\n\\end{displaymath}\n\n\n\n\n\n\\subsection{Powers of matrices}\n\nWe set out some definitions of matrix powers as they will come in useful later.For all matrices, we define $\\mathbf{A^0} = \\mathbf{I}$, the identity matrix and $\\mathbf{A^1} = \\mathbf{A}$.  We will next define $\\mathbf{A^2} = \\mathbf{AA}$ (if you think about it a bit you could see that $\\mathbf{A}$ must be a square matrix, otherwise we couldn't carry out this multiplication).   Using these definitions for matrix powers means that all the normal power arithmetic applies.   For example, $\\mathbf{A^m} \\times \\mathbf{A^n} =  \\mathbf{A^n} \\times \\mathbf{A^m} = \\mathbf{A^{m+n}}$.   If you look closely, you can also see that the powers of a matrix are commutative which means that we can do fairly standard algebraic factorisation.   For example:\n\\begin{displaymath}\n\\mathbf{I} - \\mathbf{A^2} = (\\mathbf{I} + \\mathbf{A})(\\mathbf{I} - \\mathbf{A})\n\\end{displaymath} \nwhich is a result we can use later.\n\n\n\n\n\\subsection{Determinants}\n\nThe determinant of a \\emph{square} $p\\times p$ matrix \\textbf{A} is denoted as $\\lvert \\boldsymbol{A} \\rvert$.   Finding the determinant of a $2 \\times 2$ matrix is easy:\n\n\\begin{displaymath}\n\\lvert \\boldsymbol{A} \\rvert = det \\left(\\begin{array}{rr} a_{11} & a_{21} \\\\ a_{12} & a_{22} \\end{array} \\right) = a_{11} a_{22} - a_{12} a_{21}\n\\end{displaymath}\n\nFor matrices of order $>2$, partitioning the matrix into ``minors'' and ``cofactors'' is necessary.   Consider the following $3 \\times 3$ matrix.\n\n\\begin{displaymath}\n\\boldsymbol{A} = \\left( \\begin{array}{rrr} a_{11} & a_{12} & a_{13} \\\\\n a_{21} & a_{22} & a_{23} \\\\\n a_{31} & a_{32} & a_{13} \\end{array} \\right)\n\\end{displaymath}\n\nAny element $a_{ij}$ of this matrix has a corresponding square matrix formed by eliminating the row ($i$) and column ($j$) containing $a_{ij}$.   So if we were considering $a_{11}$, we would be interested in the square matrix $\\boldsymbol{A_{-11}} =  \\left( \\begin{array}{rr} \n a_{22} & a_{23} \\\\\n a_{32} & a_{13} \\end{array} \\right)$.   The determinant of this reduced matrix, $\\lvert \\boldsymbol{A_{-11}} \\rvert$ is called the minor of $a_{11}$, and the product $c_{ij} = (-1)^{i+j}\\lvert A_{-ij} \\rvert = -1^{1+1} \\lvert A_{-11}\\rvert = \\lvert A_{11} \\rvert$ is called the cofactor of $a_{11}$.   The determinant of $\\boldsymbol{A}$ can be expressed as the sum of minors and cofactors of any row or column of $\\boldsymbol{A}$.\n\nThus:\n\\begin{displaymath}\n\\lvert \\boldsymbol{A} \\rvert = \\Sigma_{j = 1}^{p} a_{ij} c_{ij}\n\\end{displaymath}\nand as can be seen, this can get terribly recursive if you're working by hand!   Working an example through:\n\\begin{displaymath}\n\\mbox{If} \\boldsymbol{A} = \\left( \\begin{array}{rrr} 3 & 4 & 6 \\\\\n 1 & 2 & 3 \\\\\n 5 & 7 & 9 \\end{array} \\right)\n\\end{displaymath}\n\nThen $\\lvert \\boldsymbol{A} \\lvert = a_{i1}c_{i1} +  a_{i2}c_{i2} +  a_{i3}c_{i3}$.   If $i=1$ then:\n\n\\begin{eqnarray*}\nc_{11} &=& (-1)^{1+1} \\left| \\begin{array}{rr} 2 & 3 \\\\7 & 9 \\end{array} \\right| = (18-21) = -3\\\\ \nc_{11} &=& (-1)^{1+2} \\left| \\begin{array}{rr} 1 & 3 \\\\5 & 9 \\end{array} \\right| = -(9-15) = 6\\\\\nc_{11} &=& (-1)^{1+1} \\left| \\begin{array}{rr} 1 & 2 \\\\5 & 7 \\end{array} \\right| = (7-10) = -3\n\\end{eqnarray*}\n\nSo $\\lvert \\boldsymbol{A}  \\rvert = 3(-3) + 4(6) + 6(-3) = -3$.\n\n%\\begin{displaymath}\n%|\\boldsymbol{A}| = \\Sigma_{j = 1}^{p} a_{1j}|\\boldsymbol{A_{1j}}|(-1)^{1+j}\n%\\end{displaymath}\n\n%where $k > 1$.\n\n\nIn \\R, \\texttt{det()} tries to find the determinant of a matrix.\n\n\\singlespacing\n\\begin{verbatim}\n> D <- matrix(c(5,3,9,6),2,2)\n> D\n     [,1] [,2]\n[1,]    5    9\n[2,]    3    6\n> det(D)\n[1] 3\n> E <- matrix(c(1,2,3,6),2,2)\n> E\n     [,1] [,2]\n[1,]    1    3\n[2,]    2    6\n> det(E)\n[1] 0\n\\end{verbatim}\n\\onehalfspacing\n\nSome useful properties of determinants:\n\n\\begin{itemize}\n\\item The determinant of a diagonal matrix (or a triangular matrix for that matter) is the product of the diagonal elements.   (Why?).   \n\\item For any scalar $k$, $|k\\boldsymbol{A}| = k^{n}|\\boldsymbol{A}|$, where $\\boldsymbol{A}$ has size $n \\times n$.   \n\\item If two rows or columns of a matrix are interchanged, the sign of the determinant changes.   \n\\item If two rows or columns are equal or proportional (see material on rank later), the determinant is zero.   \n\\item The determinant is unchanged by adding a multiple of some column (row) to any other column (row).   \n\\item If all the elements or a column / row are zero then the determinant is zero.   \n\\item If two $n \\times n$ matrices are denoted by $\\boldsymbol{A}$ and $\\boldsymbol{B}$, then $|\\boldsymbol{AB}| = |\\boldsymbol{A}|.|\\boldsymbol{B}|$.\n\\end{itemize}\n\nThe determinant of a variance-covariance has a rather challenging interpretation as the generalised variance.\n\n%\\section{Rank, determinants, inversion, positive and semi-positive definite matrices}\n%\\label{rankpd}\n\n%\\section{Eigen decomposition}\n%\\label{eigen}\n\n%\\section{Singular Value decomposition}\n%\\label{svd}\n\n%\\section{Outline of other matrix decompositions, square roots (e.g. LD / cholesky)}\n%\\label{other}\n\n\\subsection{Rank of a matrix}\n\nRank denotes the number of linearly independent rows or columns.   For example:\n\n\\begin{displaymath}  \n\\left( \\begin{array}{rrr} 1 & 1 & 1 \\\\ 2 & 5 & -1 \\\\ 0 & 1 & -1 \\end{array} \\right)\n\\end{displaymath}\n\nThis matrix has dimension $3 \\times 3$, but only has rank 2.   The second column $\\boldsymbol{a_{2}}$ can be found from the other two columns as   $\\boldsymbol{a_{2}}= 2 \\boldsymbol{a_{1}} - \\boldsymbol{a_{3}}$.\n\nIf all the rows and columns of a square matrix \\textbf{A} are linearly independent it is said to be of full rank and non-singular.\n\nIf \\textbf{A} is singular, then $\\lvert \\boldsymbol{A} \\rvert = 0$.\n\n\n\n\\section{Matrix inversion}\n\nIf \\textbf{A} is a non-singular $p \\times p$ matrix, then there is a unique matrix \\textbf{B} such that $\\boldsymbol{A B} = \\boldsymbol{B A} = \\boldsymbol{I}$, where \\textbf{I} is the identity matrix given earlier.   In this case, \\textbf{B} is the inverse of \\textbf{A}, and denoted $\\boldsymbol{A^{-1}}$.\n\n\nInversion is quite straightforward for a $2 \\times 2$ matrix.   \n\n\\begin{displaymath}\n\\mbox{If}\\ \\boldsymbol{A} = \\left( \\begin{array}{rr} a_{11} & a_{12} \\\\ a_{21} & a_{22} \\end{array} \\right)\\ \\mbox{then}\\ \\boldsymbol{A}^{-1} = \\frac{1}{|\\boldsymbol{A}|} \\left( \\begin{array}{rr} a_{22} & -a_{12} \\\\ -a_{21} & a_{11} \\end{array} \\right)\n\\end{displaymath}\n\nMore generally for a matrix of order $n \\times n$, the (j,k)th entry of $\\boldsymbol{A^{-1}}$ is given by:\n\\begin{displaymath}\n\\left[\\frac{\\lvert \\boldsymbol{A_{-jk}} \\rvert}{\\lvert \\boldsymbol{A}\\rvert}\\right]^{(-1)^{j+k}},\n\\end{displaymath}\nwhere $\\boldsymbol{A_{-jk}}$ is the matrix formed by deleting the $j$th row and $k$th column of $\\boldsymbol{A}$.   Note that a singular matrix has no inverse since its determinant is 0.\n\nIn \\R, we use \\texttt{solve()} to invert a matrix (or solve a system of equations if you have a second matrix in the function call, if we don't specify a second matrix R assumes we want to solve against the identity matrix, which mean finding the inverse).\n\n\\singlespacing\n\\begin{verbatim}\n> D <- matrix(c(5,3,9,6),2,2)\n> solve(D)\n     [,1]      [,2]\n[1,]    2 -3.000000\n[2,]   -1  1.666667\n\\end{verbatim}\n\\onehalfspacing\n\nSome properties of inverses:\n\n\\begin{itemize}\n\\item The inverse of a symmetric matrix is also symmetric.  \n\\item The inverse of the transpose of $\\boldsymbol{A}$ is the transpose of $\\boldsymbol{A}^{-1}$.   \n\\item The inverse of the product of several square matrices is a little more subtle:   $(\\boldsymbol{A} \\boldsymbol{B} \\boldsymbol{C})^{-1} = \\boldsymbol{C}^{-1} \\boldsymbol{B}^{-1} \\boldsymbol{A}^{-1}$.   If c is a non-zero scalar then $(c\\boldsymbol{A})^{-1} = c^{-1}\\boldsymbol{A}^{-1}$.   \n\\item The inverse of a diagonal matrix is really easy - the reciprocals of the original elements.\n\\end{itemize}\n\n%\\section{Length, Orthogonality and Normalisation}\n\n%\\subsection{Length}\n\n%The length of a vector is based on a geometrical idea - the distance from the origin.   It is given by the Pythagorean forumula:\n\n%\\begin{displaymath}\n%L = \\sqrt{x_{1}^{2} + x_{2}^{2} \\ldots x_{p}^{2}}\n%\\end{displaymath}\n\n%Using matrix (well vector) operations you could find this with $\\sqrt{\\boldsymbol{x}^{T}\\boldsymbol{x}}$.\n\n\n\n%\\subsection{Normalisation}\n\n%A vector \\textbf{x} is normalised if $\\boldsymbol{x}^{T} \\boldsymbol{x} = 1$.   Any vector $\\boldsymbol{x}$ can be normalised by diving each element of $\\boldsymbol{x}$ by $\\sqrt{\\boldsymbol{x}^{T} \\boldsymbol{x}}$ (i.e. the square root of the sum of squares of the elements.\n\n\n\n\n\\section{Eigen values and eigen vectors}\n\nThese decompositions will form the core of at least half our multivariate methods (although we need to mention at some point that we actually tend to use the singular value decomposition as a means of getting to these values).   If $\\boldsymbol{A}$ is a square $p \\times p$ matrix, the eigenvalues (latent roots, characteristic roots) are the roots of the equation:\n\n\\begin{displaymath}\n|\\boldsymbol{A} - \\lambda \\boldsymbol{I}| = \\boldsymbol{0}\n\\end{displaymath}\n\nThis (characteristic) equation is a polynomial of degree $p$ in $\\lambda$.   The roots, the eigenvalues of $\\boldsymbol{A}$ are denoted by $\\lambda_{1}, \\lambda_{2}, \\ldots, \\lambda_{p}$.   For each eigen value $\\lambda_{i}$ there is a corresponding eigen vector $\\boldsymbol{e}_{i}$ which can be found by solving:\n\n\\begin{displaymath}\n(\\boldsymbol{A} - \\lambda_{i} \\boldsymbol{I})\\boldsymbol{e_{i}} = \\boldsymbol{0}\n\\end{displaymath}\n\nThere are many solutions for $\\boldsymbol{e_{i}}$.   For our (statistical) purposes, we usually set it to have length 1, i.e. we obtain a normalised eigenvector for $\\lambda_{i}$ by $\\boldsymbol{a_{i}} = \\frac{\\boldsymbol{e_{i}}}{\\sqrt{\\boldsymbol{e_{i}}^{T}\\boldsymbol{e_{i}}}}$\n\nWe pause to mention a couple of results that will be explored in much more detail later:\n\\begin{itemize}\n\\item[(a)] $trace(\\boldsymbol{A}) = \\Sigma_{i = 1}^{p} \\lambda_{i}$\n\n\\item[(b)] $|\\boldsymbol{A}| = \\prod_{i = 1}^{p} \\lambda_{i}$\n\\end{itemize}\n\nAlso, if $\\boldsymbol{A}$ is symmetric:\n\n\\begin{itemize}\n\\item[(c)] The normalised eigenvectors corresponding to unequal eigenvalues are orthonormal   (this is a bit of circular definition, if the eigenvalues are equal the corresponding eigenvectors are not unique, and one ``fix'' is to choose orthonormal eigenvectors).\n\\item[(d)] Correlation and covariance matrices: are symmetric positive definite (or semi-definite).   If such a matrix is of full rank $p$ then all the eigen values are positive.   If the matrix is of rank $m < p$ then there will be $m$ positive eigenvalues and $p-m$ zero eigenvalues.\n\\end{itemize}\n\nWe will look at the \\texttt{eigen()} function in \\R to carry out these decompositions later.\n\n\n\\section{Singular Value Decomposition}\n\\label{svd}\n\nTo be added.\n\n%We wish to examine $p$ variables measured on $N$ objects.   These are usually denoted by the $n \\times p$ matrix $\\boldsymbol{X}$, a swarm of $n$ points in $p-$dimensional space.   Typically we assume that the measurements follow a Multivariate Normal Distribution\n\n%\\begin{itemize}\n%\\item In many situations the MVN has been found to be an acceptable approximation to the true distribution\n%\\item THe central limit theorem imples that variables may follow MVN\n%\\item Normal theory is amenable to exact mathematical treatment\n%\\end{itemize}\n\n%Multivariate normality can be assessed, and where necessary transofmral attempted.   However, calls to the CLT are often made.\n\n\n\\section{Extended Cauchy-Schwarz Inequality}\n\nWe met the rather amazing Cauchy Schwartz inequality earlier in section \\ref{cauchyschwartz}.   Beautiful as this result may be, we actually need to use the \\emph{extended} Cauchy Schwartz inequality.   For any non-zero vectors $\\boldsymbol{x} \\in \\mathbb{R}$ and $\\boldsymbol{y} \\in \\mathbb{R}$, with any positive definite $p \\times p$ matrix $\\boldsymbol{S}$:\n\\begin{displaymath}\n\\langle \\boldsymbol{x}, \\boldsymbol{y} \\rangle^{2} \\leq (\\boldsymbol{x}^{T}\\boldsymbol{S} \\boldsymbol{x})(\\boldsymbol{y}^{T}\\boldsymbol{S}^{-1} \\boldsymbol{y}), \\mbox{ for all } \\boldsymbol{x}, \\boldsymbol{y} \\in \\mathbb{R}\n\\end{displaymath}\nwith equality if and only if $\\boldsymbol{x} = \\lambda \\boldsymbol{S}\\boldsymbol{y}$ for some $\\lambda \\in \\mathbb{R}$.  Proofs are available for this result [page 291] \\cite{Flury:1997}.   We will use this result when developing methods for discriminant analysis.\n\n\\section{Partitioning}\n\nFinally, note that we can partition a large matrix into smaller ones:\n\\begin{displaymath}\n\\left( \\begin{array}{rr|r} 2 & 5 & 4 \\\\\n\\hline \n0 & 7 & 8 \\\\ \n4 & 3 & 4\\\\ \n\\end{array} \n\\right)\n\\end{displaymath}\n\nSo we could work with submatrices such as $\\left(\\begin{array}{rr} 0 & 7 \\\\ 4 & 3 \\end{array} \\right)$.\n\ne.g. If $\\boldsymbol{X}$ was partitioned as $\\left( \\begin{array}{r} \\boldsymbol{X_{1}} \\\\ \\boldsymbol{X_{2}} \\end{array} \\right)$ and $\\left( \\begin{array}{rrr} \\boldsymbol{Y_{1}} & \\boldsymbol{Y_{2}} & \\boldsymbol{Y_{3}} \\end{array} \\right)$ then:\n\n\\begin{displaymath}\n\\boldsymbol{XY} = \\left( \\begin{array}{rrr} \\boldsymbol{X_{1}Y_{1}} & \\boldsymbol{X_{1}Y_{2}} & \\boldsymbol{X_{1}Y_{3}} \\\\\n \\boldsymbol{X_{2}Y_{1}} & \\boldsymbol{X_{2}Y_{2}} & \\boldsymbol{X_{2}Y_{3}}\n\\end{array} \\right)\n\\end{displaymath}\n\n\n\n%More generally, if $\\boldsymbol{x} = \\left( \\begin{array}{r} height \\\\ weight \\end{array} \\right)$ then $E(\\boldsymbol{x}) = \\left( \\begin{array}{r} E(height) \\\\ E(weight) \\end{array} \\right) = \\left( \\begin{array}{r} \\hat{\\mu_{1}} \\\\ \\hat{\\mu_{2}} \\end{array} \\right) = \\boldsymbol{\\hat{\\mu}}$.   Likewise:\n\n%\\begin{displaymath}\n%Var(\\boldsymbol{x}) = \\left( \\begin{array}{rr} Var(height) & Cov(height,weight) \\\\ Cov(weight,height) & Var(weight) \\end{array} \\right) = \\boldsymbol{\\hat{\\Sigma}}\n%\\end{displaymath}\n\n%Note that:\n\n%\\begin{displaymath}\n%Var(\\boldsymbol{x}) = E[(\\boldsymbol{x} - \\boldsymbol{\\mu})(\\boldsymbol{x} - \\boldsymbol{\\mu})^{T}]\n%\\end{displaymath}\n\n%As we will find, we use linear combinations a lot in multivariate methods.   Therefore it may be worth noting that if $\\boldsymbol{y} = \\boldsymbol{a}^{T}\\boldsymbol{x}$\n\n%\\begin{displaymath}\n%E(\\boldsymbol{y}) = E(\\boldsymbol{a}^{T}\\boldsymbol{x}) = \\boldsymbol{a}^{T}E(\\boldsymbol{x}) = \\boldsymbol{a}^{T}\\boldsymbol{\\mu}\n%\\end{displaymath}\n\n%And also therefore that:\n\n%\\begin{displaymath}\n%Var(\\boldsymbol{y}) = E(\\boldsymbol{y} - \\boldsymbol{\\bar{y}}) = E(\\boldsymbol{a}^{T}\\boldsymbol{x} - \\boldsymbol{a}^{T}\\boldsymbol{\\mu}) \n%\\end{displaymath}\n\n%= \\boldsymbol{a}^{T}E(\\boldsymbol{x}) - \\boldsymbol{\\mu}) = \\boldsymbol{a}^{T}E(\\boldsymbol{x}) - \\boldsymbol{\\mu})][[\\boldsymbol{a}^{T}(\\boldsymbol{x}) - \\boldsymbol{\\mu})]\n\n\n\n\n\\section{Exercises}\n\n\\begin{enumerate}\n\\item Which of the following are orthogonal to each other:\n\n\\begin{displaymath}\n\\boldsymbol{x} = \\left( \\begin{array}{r} 1 \\\\ -2 \\\\ 3 \\\\ -4 \\end{array} \\right)\n\\boldsymbol{y} = \\left( \\begin{array}{r} 6 \\\\ 7 \\\\ 1 \\\\ -2 \\end{array} \\right)\n\\boldsymbol{z} = \\left( \\begin{array}{r} 5 \\\\ -4 \\\\ 5 \\\\ 7 \\end{array} \\right)\n\\end{displaymath}\n\nNormalise each of the two orthogonal vectors.\n\n\n\\item Find vectors which are orthogonal to:\n\n\n\\begin{displaymath}\n\\boldsymbol{u} =  \\left( \\begin{array}{r} 1 \\\\ 3 \\end{array} \\right)\n\\boldsymbol{v} = \\left( \\begin{array}{r} 2 \\\\ 4 \\\\ -1 \\\\ 2 \\end{array} \\right)\n\\end{displaymath}\n\n\\item Find vectors which are orthonormal to:\n\n\n\\begin{displaymath}\n\\boldsymbol{x} =  \\left( \\begin{array}{r} \\frac{1}{\\sqrt{2}} \\\\ 0 \\\\ -\\frac{1}{\\sqrt{2}} \\end{array} \\right)\n\\boldsymbol{y} = \\left( \\begin{array}{r} \\frac{1}{2} \\\\ \\frac{1}{6} \\\\ \\frac{1}{6} \\\\ \\frac{5}{6} \\end{array} \\right)\n\\end{displaymath}\n\n\n\\item What are the determinants of:\n\n\\begin{displaymath}\n(a) \\left( \\begin{array}{rr} 1 & 3 \\\\ 6 & 4 \\end{array} \\right)\n(b) \\left( \\begin{array}{rrr} 3 & 1 & 6 \\\\ 7 & 4 & 5 \\\\ 2 & -7 & 1 \\end{array} \\right)\n\\end{displaymath}\n\n\\item Invert the following matrices:\n\n\\begin{displaymath}\n(a) \\left( \\begin{array}{rrr} 3 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & 9 \\end{array} \\right)\n(b) \\left( \\begin{array}{rr} 2 & 3 \\\\ 1 & 5  \\end{array} \\right)\n(c) \\left( \\begin{array}{rrr} 3 & 2 & -1 \\\\ 1 & 4 & 7 \\\\ 0 & 4 & 2 \\end{array} \\right)\n(d) \\left( \\begin{array}{rrr} 1 & 1 & 1 \\\\ 2 & 5 & -1 \\\\ 3 & 1 & -1 \\end{array} \\right)\n\\end{displaymath}\n\n\n\\item Find eigenvalues and corresponding eigen vectors for the following matrices:\n\n\n\\begin{displaymath}\n\\boldsymbol{a} = \\left( \\begin{array}{rr} 1 & 4\\\\ 2 & 3 \\end{array} \\right)\n\\boldsymbol{b} = \\left( \\begin{array}{rr} 1 & 2 \\\\ 3 & 2  \\end{array} \\right)\n\\boldsymbol{c} = \\left( \\begin{array}{rr} 2 & -2 \\\\ -2 & 5 \\end{array} \\right)\n\\boldsymbol{d} = \\left( \\begin{array}{rr} 2 & 2 \\\\ 2 & 5 \\end{array} \\right)\n\\end{displaymath}\n\n\\begin{displaymath}\n\\boldsymbol{e} = \\left( \\begin{array}{rrr} 1 & 4 & 0\\\\ 4 & 1 & 0 \\\\ 0 & 0 & 1 \\end{array} \\right)\n\\boldsymbol{f} = \\left( \\begin{array}{rrr} 4 & 0 & 0 \\\\ 0  & 9 & 0 \\\\ 0 & 0 & 1  \\end{array} \\right)\n\\boldsymbol{g} = \\left( \\begin{array}{rrr} 13 & -4 & 2\\\\ -4 & 13 & -2 \\\\ 2 & -2 & 10 \\end{array} \\right)\n\\end{displaymath}\n\n\n\n\n\\item Convert the following covariance matrix (you've seen it earlier) to a correlation matrix, calculate the eigenvalues and eigenvectors and verify that the eigen vectors are orthogonal.\n\n\\begin{displaymath}\n\\boldsymbol{g} = \\left( \\begin{array}{rrr} 13 & -4 & 2\\\\ -4 & 13 & -2 \\\\ 2 & -2 & 10 \\end{array} \\right)\n\\end{displaymath}\n\n\\end{enumerate}\n\n\n\n%%% Local Variables: ***\n%%% mode:latex ***\n%%% TeX-master: \"../book.tex\"  ***\n%%% End: ***\n", "meta": {"hexsha": "a241afe9f95956e06ac4580c12038a0b52c45e6a", "size": 46944, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/matrices.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/matrices.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/matrices.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": 39.9523404255, "max_line_length": 747, "alphanum_fraction": 0.6789579073, "num_tokens": 15915, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8705972549785201, "lm_q1q2_score": 0.7921625417424485}}
{"text": "\\subsection{Complexity Estimate} \\label{complexity_estimate}\nThe Complexity Estimate (CE) is a complexity measure for time series and the authors of \\cite{batista2011complexity}\nintroduced one possible approach of a CE implementation. Given is a time series $Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$\nwith length $l$ over the domain set $\\mathbb{U}$ and a distance measure function $d$ with\n$d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$.\n\n\\begin{equation}\n    CE(Q) = \\sqrt[2]{\\sum \\limits_{i=1}^{l-1} d(q_i, q_{i + 1})^2}\n\\end{equation}\n\nThe CE would be a suitable time series measure for a measure based filter as mentioned in \\ref{sliding_window_filter}.\nBut the measure has been created in \\cite{batista2011complexity} under the assumption that two time series have the same\nlength. Therefore a length normalized version of CE fits better as underlying time series measure for a filter. The\nlength normalized CE (LNCE) can be calculated as follows.\n\n\\begin{equation}\n    LNCE(Q) = \\frac{1}{l-1}CE(Q)\n\\end{equation}\n", "meta": {"hexsha": "9e23a2af7f334bb0e83e00889ff261177e031f36", "size": 1020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/background_and_notation/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": "bachelor-thesis/background_and_notation/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": "bachelor-thesis/background_and_notation/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": 53.6842105263, "max_line_length": 120, "alphanum_fraction": 0.7470588235, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475794701961, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7921610133697078}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrr}\n    1 & 2 & 4 \\\\\n    0 & 1 & 3 \\\\\n    -2 & 5 & 1\n  \\end{mymatrix}$. Find the following minors and cofactors:\n  \\begin{enumerate}\n  \\item $\\minor{A}{11}$,\n  \\item $\\minor{A}{21}$,\n  \\item $\\minor{A}{32}$,\n  \\item $\\cofactor{A}{11}$,\n  \\item $\\cofactor{A}{21}$,\n  \\item $\\cofactor{A}{32}$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrrr}\n    0 & -1 &  3 & 1 \\\\\n    1 &  0 &  2 & 2 \\\\\n    2 &  3 & -1 & 0 \\\\\n    1 &  1 &  0 & 1 \\\\\n  \\end{mymatrix}$. Find $\\minor{A}{11}$, $\\minor{A}{21}$,\n  $\\minor{A}{32}$, $\\cofactor{A}{11}$, $\\cofactor{A}{21}$, and\n  $\\cofactor{A}{32}$.\n\\end{ex}\n\n\\begin{ex}\n  Compute the determinants of the following matrices using cofactor\n  expansion along any row or column.\n  \\begin{enumerate}\n  \\item $\\begin{mymatrix}{rrr}\n      1 &  2 & 0 \\\\\n      3 & -2 & 2 \\\\\n      0 &  3 & 1 \\\\\n    \\end{mymatrix}$\n  \\item $\\begin{mymatrix}{rrr}\n      1 & -2 & 2 \\\\\n      3 &  0 & 0 \\\\\n      4 &  3 & 1 \\\\\n    \\end{mymatrix}$\n  \\item $\\begin{mymatrix}{rrrr}\n      1 & 2 & -2 & 2 \\\\\n      1 & 3 &  2 & 3 \\\\\n      4 & 0 &  1 & 0 \\\\\n      1 & 2 &  1 & 2 \\\\\n    \\end{mymatrix}$\n  \\end{enumerate}\n  \\begin{sol}\n    (a) $-14$. (b) $24$. (c) $0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the following determinant by expanding (a) along the first row\n  and (b) along the second column.\n  \\begin{equation*}\n    \\begin{absmatrix}{rrr}\n      1 & 2 & 1 \\\\\n      2 & 1 & 3 \\\\\n      2 & 1 & 1\n    \\end{absmatrix}\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{absmatrix}{ccc}\n        1 & 2 & 1 \\\\\n        2 & 1 & 3 \\\\\n        2 & 1 & 1\n      \\end{absmatrix} =  6.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the following determinant by expanding (a) along the first\n  column and (b) along the third row.\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      2 & 3 & 1 & 1 \\\\\n      4 & 3 & 1 & 2 \\\\\n      1 & 1 & 0 & 1 \\\\\n      3 & 2 & 1 & 2 \\\\\n    \\end{absmatrix}\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{absmatrix}{rrrr}\n      2 & 3 & 1 & 1 \\\\\n      4 & 3 & 1 & 2 \\\\\n      1 & 1 & 0 & 1 \\\\\n      3 & 2 & 1 & 2 \\\\\n      \\end{absmatrix} =  2.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the following determinant by expanding (a) along the second row\n  and (b) along the first column.\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      1 & 2 & -1 & 1 \\\\\n      0 & 1 &  2 & 1 \\\\\n      0 & 2 &  1 & 3 \\\\\n      1 & 4 &  0 & 2 \\\\\n    \\end{absmatrix}\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{absmatrix}{rrrr}\n      1 & 2 & -1 & 1 \\\\\n      0 & 1 &  2 & 1 \\\\\n      0 & 2 &  1 & 3 \\\\\n      1 & 4 &  0 & 2 \\\\\n      \\end{absmatrix} = 6.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Compute the determinant by cofactor expansion. Pick the easiest row or\n  column to use.\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      1 & 0 & 0 & 1 \\\\\n      2 & 1 & 1 & 0 \\\\\n      0 & 0 & 0 & 2 \\\\\n      2 & 1 & 3 & 1\n    \\end{absmatrix}\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{absmatrix}{cccc}\n        1 & 0 & 0 & 1 \\\\\n        2 & 1 & 1 & 0 \\\\\n        0 & 0 & 0 & 2 \\\\\n        2 & 1 & 3 & 1\n      \\end{absmatrix} = -4.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "530c115b6d49a195ffe0a5fb6da033ec33bb6a0b", "size": 3275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-MinorsCofactors.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-MinorsCofactors.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-MinorsCofactors.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.4315068493, "max_line_length": 72, "alphanum_fraction": 0.4775572519, "num_tokens": 1410, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703476, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.7921513333740487}}
{"text": "\\subsubsection{Divergence of Curl}\r\n\\begin{theorem}\r\n\tLet $\\vec{F}(x,y,z) = \\langle P(x,y,z), Q(x,y,z), R(x,y,z) \\rangle$ be a twice differentiable vector field.\\\\\r\n\t$\\nabla \\cdot (\\nabla \\times \\vec{F}) = 0$\r\n\\end{theorem}\r\n\\begin{proof}\r\n\t$\\nabla \\times \\vec{F} = \\langle R_y-Q_z, P_z-R_x, Q_x-P_y \\rangle$\\\\\r\n\t$\\nabla \\cdot (\\nabla \\times \\vec{F}) = R_{yx}-Q_{zx} + P_{zy}-R_{xy} + Q_{xz}-P_{yz}$\\\\\r\n\t$P_{yz} = P_{zy}$, $Q_{xz} = Q_{zx}$, and $R_{xy} = R_{yx}$ by Fubini's Theorem.\\\\\r\n\tSo, $\\nabla \\cdot (\\nabla \\times \\vec{F}) = 0$\r\n\\end{proof}", "meta": {"hexsha": "5b67122309031b09c32c53eaeaf173631bdd6ba3", "size": 548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/divergenceOfCurl.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/divergenceOfCurl.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/divergenceOfCurl.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 49.8181818182, "max_line_length": 111, "alphanum_fraction": 0.5839416058, "num_tokens": 242, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7920008463621663}}
{"text": "\\PassOptionsToPackage{hyphens}{url}% allow line breaks at hyphens in urls\n\\documentclass[12pt]{matlatex}\n\\usepackage{examples}\n\\usepackage{pgfplots}\n\\usepackage{caption}\n\n\\begin{document}\n\n\\section*{Plotting Bessel functions}\n\nThis simple example uses Matlab to produce a plot of the first six Bessel functions. Two plots are shown, one created by Matlab and a second created by LaTeX using the plotting package {\\tt\\small pgfplots} and the data exported from Matlab.\n\nThis example is based upon the Mathworks example at%\n\\ \\url{https://au.mathworks.com/matlabcentral/fileexchange/35229-matlab-plot-gallery-standard-line-colors}.\n\n\n\\begin{matlab}\n   x  = 0:0.1:15;\n   y0 = besselj(0,x);\n   y1 = besselj(1,x);\n   y2 = besselj(2,x);\n   y3 = besselj(3,x);\n   y4 = besselj(4,x);\n   y5 = besselj(5,x);\n\n   plot(x, y0, 'r', x, y1, 'g', x, y2, 'b',  ...\n        x, y3, 'c', x, y4, 'm', x, y5, 'y');\n   legend('J_0','J_1','J_2','J_3','J_4','J_5');\n\n   print(gcf,'example_04_fig.png','-dpng');\n\n   % Note: using ' on [x;y0...]' ensures the six functions are written as columns of example_01.txt\n\n   dlmwrite ('example_04.txt',[x;y0;y1;y2;y3;y4;y5]','delimiter',' ','precision','% .8e');\n\n\\end{matlab}\n\n\\clearpage\n\n\\begin{figure}\n   \\centering\n   \\IfFileExists{example_04_fig.png}%\n   {\\includegraphics[width=6.4in]{example_04_fig.png}}{Failed to create png plot.}\n   \\caption{The first six Bessel functions.}\n\\end{figure}\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": "043cc7f54d7485fc5d6e7f2abd6ce185dc678392", "size": 3319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/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": "matlab/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": "matlab/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": 34.5729166667, "max_line_length": 240, "alphanum_fraction": 0.632720699, "num_tokens": 1151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916170039421, "lm_q2_score": 0.9173026635420488, "lm_q1q2_score": 0.7919914299575925}}
{"text": "\\documentclass{notes}\n\n  \\title{Graph Isomorphism Problem}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \\section*{Graph}\n    Simple graph: \\(G = (V,E)\\); \\(V\\) a set; \\(E\\) a set of two-subsets of \\(V\\).\n\n  \\section*{Isomorphism}\n    Graphs \\(G_1 = (V_1, E_1)\\) and \\(G_2 = (V_2, E_2)\\).\n    Bijection \\(f:V_1 \\rightarrow V_2\\) such that \\(f(E_1) = E_2\\) where \\(f(E_1) = \\{ \\{ f(v_1), f(v_2) \\} | \\{v_1, v_2\\} \\in E_1 \\} \\).\n\n  \\section*{Example}\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[every node/.style={circle, draw=black}]\n        \\node (a) at (1,1.5) {\\footnotesize a};\n        \\node (b) at (1,3) {\\footnotesize b};\n        \\node (c) at (0,0) {\\footnotesize c};\n        \\node (d) at (2,0) {\\footnotesize d};\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=black, thick}]\n        \\path (a) edge (b)\n              (a) edge (c)\n              (a) edge (d)\n              (c) edge (d);\n      \\end{scope}\n      \\begin{scope}[every node/.style={circle, draw=black}]\n        \\node (1) at (5,3) {\\footnotesize 2};\n        \\node (2) at (5,1) {\\footnotesize 1};\n        \\node (3) at (7,3) {\\footnotesize 3};\n        \\node (4) at (7,1) {\\footnotesize 4};\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=black, thick}]\n        \\path (1) edge (2)\n              (1) edge (3)\n              (1) edge (4)\n              (3) edge (4);\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=gmitred, dashed, ->, >=latex}]\n        \\path (a) edge[bend left]  (1)\n              (b) edge[bend right] (2)\n              (c) edge[] (3)\n              (d) edge[bend right] (4);\n      \\end{scope}\n      \\node at (1,-1) {\\( V_1 \\)};\n      \\node at (6,-1) {\\( V_2 \\)};\n      \\path (1.5,-1) edge[draw=gmitred, dashed, ->, >=latex] node[above] {\\( f \\)} (5.5,-1);\n    \\end{tikzpicture}\n  \\end{center}\n\n    \\begin{align*}\n      &f(E_1) &= &\\{\\{f(a),f(b)\\},\\{f(a),f(c)\\},\\\\\n      &       &  &\\ \\ \\{f(a),f(d)\\},\\{f(c),f(d)\\}\\} \\\\\n      &       &= &\\{\\{1,2\\},\\{1,3\\},\\{1,4\\},\\{3,4\\}\\} = E_2\\\\\n    \\end{align*}\n    \n\n  \\section*{Non-isomorphism}\n\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[every node/.style={draw=black,circle}]\n        \\node (a) at ( 0, 1) {\\footnotesize e};\n        \\node (b) at ( 0, 4) {\\footnotesize b};\n        \\node (c) at ( 2, 1) {\\footnotesize d};\n        \\node (d) at ( 2, 3) {\\footnotesize c};\n        \\node (e) at (-1, 1) {\\footnotesize g};\n        \\node (f) at (-1, 3) {\\footnotesize a};\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=black,thick}]\n        \\path (a) edge (b);\n        \\path (a) edge (d);\n        \\path (a) edge (e);\n        \\path (b) edge (c);\n        \\path (b) edge (d);\n        \\path (b) edge (e);\n        \\path (b) edge (f);\n        \\path (c) edge (d);\n        \\path (d) edge (e);           \n        \\path (d) edge (f);\n        \\path (e) edge (f);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[every node/.style={draw=black,circle}]\n        \\node (a) at (0  ,0) {\\footnotesize w};\n        \\node (b) at (0  ,2) {\\footnotesize r};\n        \\node (c) at (1.5,0) {\\footnotesize v};\n        \\node (d) at (1.5,2) {\\footnotesize s};\n        \\node (e) at (3  ,0) {\\footnotesize u};\n        \\node (f) at (3  ,2) {\\footnotesize t};\n      \\end{scope}\n      \\begin{scope}[every edge/.style={draw=black,thick}]\n        \\path (a) edge (b);\n        \\path (a) edge (c);\n        \\path (c) edge (e);\n        \\path (a) edge (d);\n        \\path (b) edge (c);\n        \\path (b) edge (d);\n        \\path (b) edge (e);\n        \\path (b) edge (d);\n        \\path (d) edge (f);\n        \\path (c) edge (d);\n        \\path (d) edge (e);\t            \n        \\path (e) edge (f);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n    \n  \\section*{No of maps}\n    \\(f(a) \\rightarrow 6\\) choices; \\(f(b) \\rightarrow 5\\) choices; \\(f(c) \\rightarrow 4\\) choices; etc.\n    So, \\(n!\\) maps between the vertex sets of two graphs with \\(n\\) vertices.\n  \n  \\section*{Some invariants}\n    \\begin{itemize}\n      \\item Degrees.\n      \\item Paths.\n      \\item Connection.\n    \\end{itemize}\n\n  \\section*{Adjacency matrix}\n    Fix a listing of \\(V\\).\n    \\([a_{ij}]\\) where \\(a_{ij}\\) is 1 if \\(\\{v_i,v_j\\} \\in E \\) else 0.\n  \n  \\section*{Example}\n  \\[\n    \\begin{bmatrix}\n      0 & 1 & 1 & 0 & 0 & 1 \\\\\n      1 & 0 & 1 & 1 & 1 & 1 \\\\\n      1 & 1 & 0 & 1 & 1 & 1 \\\\\n      0 & 1 & 1 & 0 & 0 & 0 \\\\\n      0 & 1 & 1 & 0 & 0 & 1 \\\\\n      1 & 1 & 1 & 0 & 1 & 0 \n    \\end{bmatrix}\n    \\qquad\n    \\begin{bmatrix}\n      0 & 1 & 0 & 1 & 1 & 1 \\\\\n      1 & 0 & 1 & 1 & 1 & 1 \\\\\n      0 & 1 & 0 & 1 & 0 & 0 \\\\\n      1 & 1 & 1 & 0 & 1 & 0 \\\\\n      1 & 1 & 0 & 1 & 0 & 1 \\\\\n      1 & 1 & 0 & 0 & 1 & 0 \\\\\n    \\end{bmatrix}\n  \\]\n\n  \\section*{Permutation matrix}\n  Isomorphic \\(\\leftrightarrow\\) \\(\\exists P\\) such that \\(A = PBP^\\intercal\\).\n\n  \\[\n    \\begin{bmatrix}\n      0 & 1 & 0 & 0 \\\\\n      1 & 0 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      0 & 1 & 1 & 1 \\\\\n      1 & 0 & 0 & 0 \\\\\n      1 & 0 & 0 & 1 \\\\\n      1 & 0 & 1 & 0 \\\\\n    \\end{bmatrix}\n    \\begin{bmatrix}\n      0 & 1 & 0 & 0 \\\\\n      1 & 0 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\n    \\end{bmatrix} \\]\n    \\[ =\n    \\begin{bmatrix}\n      0 & 1 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 \\\\\n      0 & 1 & 0 & 1 \\\\\n      0 & 1 & 1 & 0 \\\\\n    \\end{bmatrix}        \n  \\]\n\n\n  \\section*{Binary encoding}\n  \\[\n    \\begin{bmatrix}\n      0 & 1 & 1 & 0 & 0 & 1 \\\\\n      {\\color{gmitred} 1} & 0 & 1 & 1 & 1 & 1 \\\\\n      {\\color{gmitred} 1} & {\\color{gmitred} 1} & 0 & 1 & 1 & 1 \\\\\n      {\\color{gmitred} 0} & {\\color{gmitred} 1} & {\\color{gmitred} 1} & 0 & 0 & 0 \\\\\n      {\\color{gmitred} 0} & {\\color{gmitred} 1} & {\\color{gmitred} 1} & {\\color{gmitred} 0} & 0 & 1 \\\\\n      {\\color{gmitred} 1} & {\\color{gmitred} 1} & {\\color{gmitred} 1} & {\\color{gmitred} 0} & {\\color{gmitred} 1} & 0 \n    \\end{bmatrix}\\]\n\n    \\[ \\rightarrow 011001101111110111011000011001111010 \\]\n    \\[ \\textrm{or } { \\color{gmitred} 111011011011101 } \\]\n\n  \\section*{Decision problem}\n    \\[f(110101,101011) \\rightarrow \\textrm{Yes}\\]\n    \\[f(111011011011101,1011111101110011) \\rightarrow \\textrm{No}\\]\n    \\[f:\\{0,1\\}^* \\times \\{0,1\\}^* \\rightarrow \\{0,1\\} = 1 \\textrm{ iff isomorphic} \\]\n\n    \\[ \\mathbf{GRAPHISO} = \\{(G_1, G_2) | f(G_1, G_2) = 1\\} \\]\n\n  %\\bibliography{bibliography}\n\\end{document}", "meta": {"hexsha": "81fac03055ec21784c443004d98bcfc05ef00baf", "size": 6429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "graph-iso.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": "graph-iso.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": "graph-iso.tex", "max_forks_repo_name": "ianmcloughlin/latex-notes", "max_forks_repo_head_hexsha": "2ce8e4de828f7ff916d8e21d46ad610f62653acb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.2087378641, "max_line_length": 137, "alphanum_fraction": 0.4594804791, "num_tokens": 2648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8807970795424088, "lm_q1q2_score": 0.7919434880153395}}
{"text": "\\chapter{Counting and Sylow's Theorem}\r\n\\section {Basic Results}\r\n{\\bf Theorem 1:} If $X, Y \\leq G$,  $XY$ is a group iff $XY=YX$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nAssociativity and identity are inherited from $G$. If \r\n$x_1,x_2 \\in X$ and\r\n$y_1,y_2 \\in Y$, $x_1 y_1 x_2 y_2=\r\nx_1  x_2' y_1' y_2$ by the equality so $XY$ is closed. Further, $\r\n(x_1 y_1)^{-1}= \r\n(y_1)^{-1} x_1^{-1} =\r\n(y_1' x_1')^{-1} \\in XY$ so every element in $XY$ has an inverse.\r\n\\end{quote}\r\n{\\bf Theorem 2:} If $exp(G)=2$, $G$ is abelian.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$(xy)^2= xyxy=1$ so $x^2yxy= yxy= x$ and $yxy^2= yx= xy$ so $G$ is abelian.\r\n\\end{quote}\r\n\\section {Counting}\r\n{\\bf Lagrange's Theorem:} If $G>H$ $G= \\bigcup Hx_i$ for some $x_i \\in G$ and each pair of\r\ncosets is disjoint.\r\n\\begin{quote}\r\n\\emph{Proof:}  $G= \\bigcup_{x \\in G} Hx$ since $x \\in Hx$.  Since any\r\ntwo cosets coincide or are disjoint, this partition can be refined to disjoint sets all of\r\nsize $|H|$.   Thus $|H| \\mid |G|$.\r\n\\end{quote}\r\n{\\bf Group Actions:} A \\emph{group action} is a map $\\phi: \\Omega \\times G \\rightarrow \\Omega$\r\nsatisfying $\\phi(\\alpha,1)= \\alpha$, $\\phi(\\alpha, g_1 g_2)= \\phi(\\phi(\\alpha, g_1), g_2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Counting Theorem:} $|\\alpha^G|= |G:G_{\\alpha}|$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $G_{\\alpha} g$ be a coset.  Every element of the coset maps $\\alpha$ into the same element.  Further,\r\nif $G_{\\alpha} g_1$ and\r\n$G_{\\alpha} g_2$ map $\\alpha$ into the same element then\r\n$g_1 g_2^{-1} \\in G_{\\alpha}$.\r\n\\end{quote}\r\n{\\bf Cauchy's Theorem:}  If $G$ is abelian and $p \\mid |G|$ then $\\exists x \\in G, x \\ne 1: x^p=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  By induction on $|G|$; true if $|G|=1$.\r\nIf $a \\in G$ and $|a|= p^rm$, $(p, m)=1$ then $b=a^{p^{r-1}m}$ has order $p$ and where done.\r\nIf $p \\nmid |a|$, apply the inductive hypothesis to $G/ \\langle a \\rangle$.\r\n\\end{quote}\r\n{\\bf Sylow's Theorem:}  Let $|G|_p$ denote the largest $i$ such that $p^i \\mid |G|$.\r\n(1) $\\exists S \\le G, |S|= p^{|G|_p}$; (2) Let $S_p(G)= \\{S \\le G: |S|= p^{|G|_p} \\}$,\r\n$|S_p(G)| = 1 \\jmod{p}$ and $|S_p(G)| \\mid |G:P|$.\r\n\\begin{quote}\r\n\\emph{Proof of (1):}  By induction on $|G|$; true if $|G|=1$.\r\nLet $G$ act by conjugation on its elements and decompose these into disjoint orbits.  We get\r\n$|G|= |{\\mathbb Z}(G)|+\\sum_{x} |G:C_G(x)|$.  If $p \\nmid |{\\mathbb Z}(G)|$, $p \\nmid |C_G(x)|$\r\nfor some $x$ and we can apply the induction hypothesis to $C_G(x)$.  If $p \\mid |G|$, by Cauchy,\r\n$\\exists a \\in {\\mathbb Z}(G), a \\ne 1, a^p =1$.  $\\langle a \\rangle \\lhd G$.  \r\nApply the induction hypothesis to\r\n$G/ \\langle a \\rangle$.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of (2, 3):}\r\nLet $G$ act on $S_p(G)$ by conjugation and $P \\in S_p(G)$.  $P$ also acts on $S_p(G)$ by\r\nconjugation.  Let $\\Sigma$ be a $G$-orbit.  $\\Sigma= \\bigcup \\Delta_i$ where each\r\n$\\Delta_i$ is a $P$-orbit disjoint from $\\Delta_j, i \\ne j$.  If $P \\notin \\Sigma$\r\n$p \\mid |\\Delta_i|, \\forall i$ so $p \\mid |G:N(P)|$ which is a contradiction.  So $P \\in \\Sigma$ for\r\nall $G$-orbits and hence $G$ is transitive on $S_p(G)$.  In this decomposition, $P$ is in an orbit\r\nby itself and every other orbit has size divisible by $p$, so $|S_p(G)= |G:N_G(P)| = 1 \\jmod{p}$.\r\nFinally,\r\n$|S_p(G)| = |G:N_G(P)| \\mid |G:P|$.\r\n\\end{quote}\r\n{\\bf Frattini Argument:} If $H \\lhd G$ and $P \\in S_p(H)$ then $G= H N_G(P)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Let $g \\in G$.  $P^g \\in H$ so $\\exists x \\in H: P^x=P^g$.  $x^{-1}g \\in N(P)$ so\r\n$g \\in HN(P)$.\r\n\\end{quote}\r\n{\\bf Theorem 3:} If $P$ is a $p$-group and $S < P$ then $N_P(S) > S$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Let $P$ act on $S$ by conjugation and $\\Sigma$ be the resulting orbit.\r\nNow let $S$ act on $\\Sigma$.\r\n\\end{quote}\r\n\r\n", "meta": {"hexsha": "2282814fc47b436677606b364137edf3e7709488", "size": 3691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtSylow.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/gtSylow.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/gtSylow.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": 47.3205128205, "max_line_length": 120, "alphanum_fraction": 0.596586291, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.8807970654616712, "lm_q1q2_score": 0.7919434705932225}}
{"text": "\\chapter{Two examples of low discrepancy sequences}\\label{app:Sobol}\nLow discrepancy sequences are widely used in QMC methods. Here, we provide some details on two types of those sequences: The Van der Corput sequence and the Sobol sequence.\nIn the following we give a brief outline of the theory reported in \\cite{joe2008notes, leobacher2014introduction}.\n\\section{Van der Corput sequences}\n\\textit{Van der Corput} sequences take the name by its inventor Van der Corput who introduced it for the first time in 1935. In the following we show how to construct such sequence in one dimension, $d=1$. This kind of sequences are particularly relevant because many other kind of sequences in higher dimensions are based on this one-dimensional case. Below we give the definition of radical inverse function. \\\\ \\indent \nLet $\\variabile{b}\\geq 2$ be an integer number. Any natural number $\\variabile{n}\\in \\mathbb{N}_0$ has the following unique decomposition in base $\\variabile{b}$:\n\\begin{equation}\n\\variabile{n} = \\sum_{\\variabile{i}=0}^\\infty \\variabile{d}_{\\variabile{i}}\\variabile{b}^{\\variabile{i}},\n\\end{equation}\nwhere $\\variabile{d}_{\\variabile{i}} \\in \\{0, 1, \\cdots, \\variabile{b}-1\\}$ are called the digit numbers.\n\\begin{definition}\nThe \\textit{radical inverse function} $\\phi_{\\variabile{b}}:\\mathbb{N}_0\\rightarrow [0,1)$ in base $\\variabile{b}$ for a given number $\\variabile{n}\\in \\mathbb{N}_0$ is defined as:\n\\begin{equation}\n\\phi_{\\variabile{b}}(\\variabile{n}) = \\sum_{\\variabile{i}=1}^{\\infty}\\frac{\\variabile{d}_{\\variabile{i}-1}}{\\variabile{b}^{\\variabile{i}}}.\n\\end{equation}\n\\end{definition}\nAs an example we calculate the radical inverse function $\\phi_{\\variabile{b}}(5)$ in base $\\variabile{b} = 2$. \nThe digit expansion in base $\\variabile{b}$ of $\\variabile{n}=5$ is:\n\\begin{equation}\n5 = 1\\cdot 2^0+0\\cdot 2^1+1\\cdot 2^2.\n\\end{equation}\nTherefore, $\\variabile{d}_0 = 1, \\variabile{d}_1 = 0$ and $\\variabile{d}_2 = 1$. \nThe radical inverse function $\\phi_2(5)$ is:\n\\begin{equation}\n\\phi_2 (5) = \\frac{1}{2}+\\frac{0}{4}+\\frac{1}{8} = \\frac{5}{8}.\n\\end{equation}\n\\begin{definition}\nThe Van der Corput sequence in base $\\variabile{b}$ is defined as $\\{ \\phi_{\\variabile{b}}(\\variabile{n})\\}_{n\\in\\mathbb{N}_0}$.\n\\end{definition}\nTo clarify this concept we provide an example of a finite Van der Corput sequence.\nSuppose we have the finite sequence of numbers $\\variabile{n}\\in \\{0, 1,\\cdots, 8\\}$  the corresponding Van der Corput sequence \n$\\{ \\phi_{\\variabile{b}}(\\variabile{n})\\}_{\\variabile{n}\\in \\{0, 1,\\cdots, 8\\}}$ in base $\\variabile{b}=2$ is:\n\\begin{equation}\n\\big\\{\\phi_2(\\variabile{n})\\big\\}_{\\variabile{n}\\in \\{0, 1,\\cdots, 8\\}} = \\Bigg\\{0, \\frac{1}{2}, \\frac{1}{4}, \\frac{3}{4}, \\frac{1}{8},\\frac{5}{8}, \\frac{3}{8}, \\frac{7}{8}, \\frac{1}{16}\\Bigg\\} \\,.\n\\end{equation}\nIt can be proved that the Van der Corput sequence in base $\\variabile{b}$ is uniformly distributed modulo one \\cite{leobacher2014introduction}. \nThe van der Corput sequence has been extended to higher dimensions. \nSobol sequences can be seen as extended Van der Corput sequences in base $\\variabile{b}=2$ for every dimension $\\variabile{d}\\geq2$. Its construction is briefly explained below.\n\\section{Sobol sequences}\nThe aim is to generate a low-discrepancy sequence in the hypercube $[0,1]^{\\variabile{d}}$. \nThe construction of a Sobol sequence can be schematized as follows. \n\nLet us start from the simplest case of $\\variabile{d}=1$. Let $P_\\variabile{j}$ be a primitive polynomial in the field $\\mathbb{Z}_2[\\variabile{x}]$ that is a polynomial monic and irreducible over $\\mathbb{Z}_2[\\variabile{x}]$. The polynomial of degree $\\textrm{s}_\\variabile{j}$ has the form:\n\\begin{equation}\nP_{\\variabile{j}}:\\variabile{x}^{\\textrm{s}_{\\variabile{j}}}+\\variabile{a}_{1, \\variabile{j}}\\variabile{x}^{\\textrm{s}_{\\variabile{j}}-1}+\\cdots+\\variabile{a}_{\\textrm{s}_{\\variabile{j}}-1, \\variabile{j}}\\variabile{x}+1,\n\\end{equation}\nwhere the coefficients $\\{\\variabile{a}_{\\variabile{i},\\variabile{j}}\\}_{\\variabile{i}= 1, \\cdots, \\textrm{s}_{\\variabile{j}}-1}$ are either $0$ or $1$ and are chosen arbitrary\\cite{joe2008constructing}. \nThe next step is to select odd positive numbers $m_{\\variabile{k}, \\variabile{j}}$ such that $m_{\\variabile{k}, \\variabile{j}}<2^\\variabile{k}$ for $1\\leq\\variabile{k}\\leq\\variabile{s}_{\\variabile{j}}$ while, for $\\variabile{k}>\\variabile{s}_{\\variabile{j}}$, $m_{\\variabile{k}, \\variabile{j}}$ are defined recursively by:\n\\begin{equation}\\label{eq:m}\nm_{\\variabile{k}, \\variabile{j}} := 2\\variabile{a}_{1, \\variabile{j}}m_{\\variabile{k}-1, \\variabile{j}}\\oplus 2^2a_{2, \\variabile{j}}m_{\\variabile{k}-2, \\variabile{j}}\\oplus \\cdots \\oplus 2^{\\textrm{s}_{\\variabile{j}}-1}\\variabile{a}_{\\textrm{s}_{\\variabile{j}}-1, \\variabile{j}}m_{\\variabile{k}-\\textrm{s}_{\\variabile{j}}+1, \\variabile{j}}\\oplus 2^{\\textrm{s}_{\\variabile{j}}}m_{\\variabile{k}-\\textrm{s}_{\\variabile{j}}, \\variabile{j}}\\oplus m_{\\variabile{k}-\\textrm{s}_{\\variabile{j}}, \\variabile{j}},\n\\end{equation}\nwhere we have indicated with $\\oplus$ the bit-by-bit exclusive or operator which operates on two bit patterns giving as result $1$ if two bits are different or $0$ if both bits are equal. Now, the so-called direction numbers are defined by:\n\\begin{equation}\\label{eq:dir_numb}\n\\variabile{v}_{\\variabile{k}, \\variabile{j}}=\\frac{m_{\\variabile{k}, \\variabile{j}}}{2^\\variabile{k}}.\n\\end{equation}\nThen, for $\\variabile{n}\\in \\mathbb{N}_0$ with finite base $2$ expansion:\n\\begin{equation}\n\\variabile{n} = \\sum_{\\variabile{i}=0}^r \\variabile{n}_{\\variabile{i}}2^{\\variabile{i}}\n\\end{equation}\nthe sequence $\\{\\variabile{x}_{\\variabile{i}, \\variabile{j}}\\}$ is given by\n\\begin{equation}\\label{eq:x}\n\\variabile{x}_{\\variabile{n}, \\variabile{j}} = \\variabile{n}_o\\variabile{v}_{1,\\variabile{j}}\\oplus \\variabile{n}_1\\variabile{v}_{2,\\variabile{j}}\\oplus \\cdots\\oplus  \\variabile{n}_{r-1}\\variabile{v}_{r,\\variabile{j}}.\n\\end{equation}\n$\\variabile{x}_{\\variabile{n}, \\variabile{j}}$ is the $\\variabile{j}$-th component of the $n$-th points of a Sobol sequence.\nSobol sequence is the sequence of points $(\\variabile{x}_{\\variabile{n}})_{\\variabile{n}\\in\\mathbb{N}_0}$.\nIn the following we show with an example how to derive the first few points of a Sobol sequence for $\\variabile{d}=1$. \\\\ \\indent\nLet consider the primitive polynomial $Q_{\\variabile{j}}: \\variabile{x}^3+\\variabile{x}^2+1$ of degree $\\textrm{s}_{\\variabile{j}}=3$, where $a_{1, \\variabile{j}}=0$ and $a_{2, \\variabile{j}}=1$. We start from the first three coefficients $m_{1, \\variabile{j}}=1$, \n$m_{2, \\variabile{j}}=3$, and $m_{3, \\variabile{j}}=7$ (note that other choices are possible). \nThey lead to the following direction numbers:\n\\begin{equation}\n\\variabile{v}_{1,\\variabile{j}} = \\frac{1}{2}, \\qquad \\variabile{v}_{2,\\variabile{j}} = \\frac{3}{4}, \\qquad \\variabile{v}_{3,\\variabile{j}}= \\frac{7}{8},\n\\end{equation}\nthat in binary notation are:\n\\begin{equation}\n\\variabile{v}_{1,\\variabile{j}} = (0.1)_2 \\qquad \\variabile{v}_{1,\\variabile{j}} = (0.11)_2, \\qquad \\variabile{v}_{1,\\variabile{j}} = (0.111)_2.\n\\end{equation}\nFor the polynomial $Q_{\\variabile{j}}$, Equation (\\ref{eq:m}) becomes:\n\\begin{equation}\nm_{\\variabile{k}, \\variabile{j}} := 2\\variabile{a}_{1, \\variabile{j}}m_{\\variabile{k}-1, \\variabile{j}}\\oplus 2^2a_{2, \\variabile{j}}m_{\\variabile{k}-2, \\variabile{j}}\\oplus 2^{3}m_{\\variabile{k}-3, \\variabile{j}}\\oplus m_{\\variabile{k}-3, \\variabile{j}} = 4m_{\\variabile{k}-2, \\variabile{j}}\\oplus 8m_{\\variabile{k}-3, \\variabile{j}}\\oplus m_{\\variabile{k}-3, \\variabile{j}}.\n\\end{equation}\nTherefore, \n\\begin{subequations}\n\\begin{align*}\n\\begin{split}\nm_{4, \\variabile{j}} &=  4m_{2, \\variabile{j}}\\oplus 8m_{1, \\variabile{j}}\\oplus m_{1, \\variabile{j}} \\\\ &= 12\\oplus 8\\oplus1 \\\\ &= (1 1 0 0)_2\\oplus (1 0 0 0)_2 \\oplus (0 0 0 1)_2 \n\\\\ &= (0 1 0 1)_2 =5\n\\end{split}\\\\\n\\begin{split}\nm_{5, \\variabile{j}} &=  4m_{3, \\variabile{j}}\\oplus 8m_{2, \\variabile{j}}\\oplus m_{2, \\variabile{j}} \\\\ &= 28\\oplus 24\\oplus3 \\\\ &= (11100)_2\\oplus (11000)_2 \\oplus (00011)_2 \n\\\\ &= (00111)_2 =7,\n\\end{split}\n\\end{align*}\n\\end{subequations}\nand so on. The corresponding direction are vectors:\n\\begin{equation}\n\\variabile{v}_{4,\\variabile{j}} = \\frac{5}{16} = (0.0101)_2  \\qquad \\variabile{v}_{5,\\variabile{j}} = \\frac{7}{32}=(0.00111)_2.\n\\end{equation}\nFrom (\\ref{eq:x}) we find the $\\variabile{j}$-th component of the first five points:\n\\begin{center}\n\\begin{tabular}{ l l l}\n $0 = (0)_2$  & $x_{0, \\variabile{j}}$ & $= 0$ \\\\ \n $1 = (1)_2$ & $x_{1, \\variabile{j}}$ & $= (0.1)_2 = 0.5$ \\\\  \n $2 = (10)_2$ & $x_{2, \\variabile{j}}$ & $= (0.11)_2= 0.75$  \\\\\n$3 = (11)_2$ & $x_{3, \\variabile{j}}$ & $ = (0.1)_2\\oplus (0.11)_2 = (0.01)_2 = 0.25$\\\\\n$4 = (100)_2$ & $x_{4, \\variabile{j}}$ & $ = (0.111)_2= 0.875$\\\\\n$5 = (101)_2$ & $x_{5, \\variabile{j}}$ & $ = (0.1)_2\\oplus (0.111)_2 = (0.011)_2 = 0.375$.\n\\end{tabular}\n\\end{center}\nThe generalization of Sobol sequences to higher dimensions $d>1$ is calculated considering a sequence where the $\\variabile{n}$-th point has the form:\n\\begin{equation}\n\\variabile{q}_{n} = (\\variabile{x}_{\\variabile{n}, 1},\\variabile{x}_{\\variabile{n}, 2} \\cdots, \\variabile{x}_{\\variabile{n}, d}),\n\\end{equation}\nwhere the second index of the variables $\\variabile{x}_{\\variabile{n}, \\variabile{j}}$ refers to the polynomial $P_{\\variabile{j}}$ (with corresponding degree $\\textrm{s}_{\\variabile{j}}$) which is considered for calculating the direction numbers. Therefore, $d$ different sets of direction numbers are generated from a given polynomial $P_\\variabile{j}$ using Equation (\\ref{eq:dir_numb}) and each component $\\variabile{x}_{\\variabile{n},\\variabile{j}}$ is computed using the corresponding direction vector. ", "meta": {"hexsha": "68117fa30405fffd3dbdc0b5eda0b455f1e595d1", "size": 9718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Sobol.tex", "max_stars_repo_name": "melaniafilosa/ps_raytracing", "max_stars_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/Sobol.tex", "max_issues_repo_name": "melaniafilosa/ps_raytracing", "max_issues_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/Sobol.tex", "max_forks_repo_name": "melaniafilosa/ps_raytracing", "max_forks_repo_head_hexsha": "8f9111ea4ec3ac125b593f41b3ac6fe302ea6632", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 86.0, "max_line_length": 509, "alphanum_fraction": 0.6927351307, "num_tokens": 3465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.905989819114262, "lm_q1q2_score": 0.7919050791507668}}
{"text": "\\section{A First (Pen and Paper Style) Proof}\\label{sec:hol_ex1}\n%\nThe HOL4 features presented so far are exactly those of an interpreted\nprogramming language.\nNext, we will define our first function in HOL4, and prove a first theorem about\nit.\n\n%A common mathematical notation is $\\sum_{i=0}^n f (i)$,\n%summing the numbers from $0$ to $n$, and applying function $f$.\n%We define a specialized version for $f (x) = x$ in HOL4:\nThe function we will define is a sum of natural numbers up to $n$,\n$\\sum_{i=0}^n i$.\nA HOL4 definition looks like this:\n\n\\begin{lstlisting}\nDefinition sumFun_def:\n  sumFun (n:num) = if (n = 0) then 0 else n + sumFun (n-1)\nEnd\n\\end{lstlisting}\n\nThe \\lstinline{Definition} and \\lstinline{End} keyword tell the REPL that we\ndefine a HOL4 function and mark its end.\nIn the REPL, \\lstinline{sumFun_def} is the name of the definition, under which it\ncan be accessed.\nAs a convention, when defining function $f$ in HOL4, its definition should be\nnamed \\lstinline{f_def}.\nThe type annotation \\lstinline{n:num} tells the HOL4 REPL to parse variable \\texttt{n}\nas a natural number.\nTo load the definition into the HOL4 REPL, mark it completely, including the \\lstinline{Definition}\nkeyword and the \\lstinline{End} keyword, and send it to the REPL with \\ekey{M-h M-r}.\n\nAlternatively, HOL4 also supports defining a function by a system of equations,\nmoving the \\texttt{case} expression of the \\lstinline{sum} function to the\noutside:\n%\n\\begin{lstlisting}\nDefinition sum_def:\n  sum 0 = 0 /\\\n  sum (n:num) = n + sum (n-1)\nEnd\n\\end{lstlisting}\n\nTo avoid a name clash we have renamed the function into \\lstinline{sum}.\nAs for the definition of \\lstinline{sumFun_def}, to send the definition to the REPL,\nmark it and send it with \\ekey{M-h M-r}.\nChoosing one definition over the other has different benefits and downsides.\nAs a rule of thumb, it is recommended to choose the latter version, giving a\nsystem of equations if the function requires a top-level \\texttt{case}\nexpression.\nWe will do the proof for the function \\texttt{sum} here, and give a general\nguideline on when to prefer which version later in \\autoref{subsec:tipsAndTricks}.\n\nAs a simple, first example, we will prove a closed form for \\lstinline{sum n}:\n\\[\n  \\sum_{i=0}^{n} i = \\frac{n * (n + 1)}{2}\n\\]\n\nIn HOL4 this theorem is stated as\n\n\\begin{lstlisting}\nTheorem closed_form_sum:\n  ! n. sum n = n * (n + 1) DIV 2\nProof\nQED\n\\end{lstlisting}\n\nAgain, \\lstinline{Theorem}, \\lstinline{Proof}, and \\lstinline{QED} are the\nkeywords marking a theorem statement in the REPL and the indented line is\nthe statement that we want to prove.\nSimilar to a definition, the name \\lstinline{closed_form_sum} is an identifier\nwhich is used later to refer to the theorem statement proven in other proofs.\nThis makes theorems first class citizens of the HOL4 REPL, also allowing\nfunctions to manipulate and inspect their statements.\n\nWhen proving a theorem for the first time in HOL4, the proof is usually done\ninteractively.\nStarting an interactive proof is as simple as marking the indented line\n(\\lstinline{! n. sum n = n * (n + 1) DIV 2}) and pressing \\ekey{M-h g}.\nThe HOL4 REPL prints\n\n\\begin{lstlisting}[mathescape=true, frame=single]\n> val it =\n   Proof manager status: 1 proof.\n   1. Incomplete goalstack:\n        Initial goal:\n        $\\forall$ n. sum n = n * (n + 1) DIV 2\n   : proofs\n\\end{lstlisting}\n\nIn HOL4, theorems are proven by applying so-called \\emph{tactics} to the current\ngoal.\nThese tactics are a group of SML functions, implemented in the HOL4\ndistribution, and filled in between the \\lstinline{Proof} and the \\lstinline{QED}\nkeywords.\nIn this tutorial, we decouple learning how the theorem prover works from\nlearning the syntax of the tactics language by performing interactive proofs\nwith Lassie using natural language.\n\nTo load Lassie and the natural language descriptions required for the proof,\nrun\n\\begin{lstlisting}\nopen LassieLib arithTacticsLib logicTacticsLib arithmeticTheory;\nval _ = LassieLib.loadJargon \"Arithmetic\";\nval _ = LassieLib.loadJargon \"Logic\";\n\\end{lstlisting}\ninteractively.\n\nThe closed form is the standard example for proofs by induction in math classes.\nFollowing this example, we start the proof with\n\\begin{lstlisting}\nnltac `Induction on 'n'.`\n\\end{lstlisting}\n\nHere, \\lstinline{nltac} is a Lassie function that parses natural language and\ntranslates it into a HOL4 tactic.\nThe parameter \\lstinline{`Induction on 'n'.`} is the natural language\ndescription of the tactic used.\nTo apply the tactic, the line must be marked and run with \\ekey{M-h e}.\nAfter running the code, the HOL4 REPL shows\n\\begin{lstlisting}\n> OK..\n2 subgoals:\nval it =\n\n    0.  sum n = n * (n + 1) DIV 2\n   ------------------------------------\n        sum (SUC n) = SUC n * (SUC n + 1) DIV 2\n\n   sum 0 = 0 * (0 + 1) DIV 2\n\n2 subgoals\n   : proof\n\\end{lstlisting}\n\nThe line \\lstinline{2 subgoals} tells us that we must prove two separate goals\nto finish the proof.\nAs HOL4 keeps track of these subgoals for us, we need not manage them manually\nto make sure that the proof remains error-free.\nNote that in the induction step, HOL4 automatically adds the inductive\nhypothesis as an assumption (labeled with \\lstinline{0}) above a dashed line.\n\nFirst, we prove the base case \\lstinline{sum 0 = 0 * (0 + 1) DIV 2}, then we\nshow the induction step \\lstinline{sum (n + 1) = (n + 1) * (n + 2) DIV 2}.\nFunction \\lstinline{SUC} is the HOL4 version of Peano's successor function.\nIntuitively \\lstinline{SUC n} refers to the natural number after \\lstinline{n},\ni.e. \\lstinline{n + 1}.\n\nAs for a pen-and-paper proof, the base case of the induction is trivial, and\nsolved with the simple statement \\lstinline{nltac `use [sum_def] to simplify.`},\nleaving us only with the induction step from above.\nIn contrast to a pen-and-paper proof, we have to explicitly state that we\nsimplify with the definition of our summation function (\\lstinline{sum_def}).\nThis is part of the enforced rigour required by the theorem prover\\footnote{\nWe will show in \\autoref{subsec:tipsAndTricks} how one can get rid of this in certain cases.}.\n\nAs for a pen-and-paper proof, the first step on the induction step is to\nsimplify:\n\\begin{lstlisting}\nnltac `use [sum_def, GSYM ADD_DIV_ADD_DIV] to simplify.`\n\\end{lstlisting}\n\nHere, \\lstinline{ADD_DIV_ADD_DIV} is a theorem from the HOL4 standard library\nused to enrich the simplifier with the additional knowledge.\nTo find out its statement, mark the theorem name only, and send it to the\nREPL with \\ekey{M-h M-r}.\nSending \\lstinline{GSYM} to the REPL shows that the function has type\n\\lstinline{:thm -> thm}, meaning that it takes a theorem as input and returns a\ntheorem.\nFunction \\lstinline{GSYM} is a Poly/ML function rotating an equality theorem,\nreplacing equality $a = b$ with equality $b = a$.\nSending \\lstinline{GSYM ADD_DIV_ADD_DIV} and \\lstinline{ADD_DIV_ADD_DIV} to the REPL, one can\nobserve its effect easily.\n\nUsing \\lstinline{GSYM} can be useful from time to time as rewriting in HOL4 is\ndirected from left-to-right.\nIf we have a theorem showing $f x = b$, HOL4 will rewrite any occurence of\n$f x$ into an occurence of $b$, but it will never replace occurences of $b$\nwith occurences of $f x$.\n\nAfter applying the tactic, the REPL will show the subgoal that remains to be proven:\n\\begin{lstlisting}\n> OK..\n1 subgoal:\nval it =\n\n    0.  sum n = (n * (n + 1)) DIV 2\n   ------------------------------------\n        (2 * SUC n + n * (n + 1)) DIV 2 = SUC n * (SUC n + 1) DIV 2\n\n   : proof\n\\end{lstlisting}\n\nApplying the following tactics step-by-step closes the proof:\n\n\\begin{lstlisting}\nnltac `'2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)' suffices to show the goal.`\nnltac `show 'SUC n * (SUC n + 1) = (SUC n + 1) + n * (SUC n + 1)' using (simplify with [MULT_CLAUSES]).`\nnltac `simplify.`\nnltac `show 'n * (n + 1) = SUC n * n' using (trivial using [MULT_CLAUSES, MULT_SYM]).`\nnltac `'2 * SUC n = SUC n + SUC n' follows trivially.`\nnltac `'n * (SUC n + 1) = SUC n * n + n' follows trivially.`\nnltac `rewrite assumptions. simplify.`\n\\end{lstlisting}\n\n\\begin{sloppypar}\nThe natural language tactic \\lstinline{`show 'SUC n * (SUC n + 1) = (SUC n + 1) + n * (SUC n + 1)' using (simplify with [MULT_CLAUSES]).`}\nshows another feature of HOL4:\nWe can extend the list of assumptions with the theorem mentioned after\n\\lstinline{show}.\nBefore running the tactic, the state of the goal is\n\\end{sloppypar}\n\\begin{lstlisting}\n> OK..\n1 subgoal:\nval it =\n\n    0.  sum n = n * (n + 1) DIV 2\n   ------------------------------------\n        2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)\n\n   : proof\n\\end{lstlisting}\n\nand after running the tactic, the subgoal becomes\n\\begin{lstlisting}\n> OK..\n1 subgoal:\nval it =\n\n    0.  sum n = n * (n + 1) DIV 2\n    1.  SUC n * (SUC n + 1) = SUC n + 1 + n * (SUC n + 1)\n   ------------------------------------\n        2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)\n\n   : proof\n\\end{lstlisting}\n\nRunning all tactics, one after another, the REPL shows that the proof is finished by printiting\n\\begin{lstlisting}\n> OK..\n\nval it =\n   Initial goal proved.\n   $\\vdash$ $\\forall$ n. sum n = n * (n + 1) DIV 2: proof\n\\end{lstlisting}\n\nTo reuse the theorem later, and to make it automatically checkable by HOL4, we\nhave to put the natural language into a single call to \\lstinline{nltac}.\nThe full code for the theorem is given in \\autoref{fig:gaussProof}.\n%\n\\begin{figure}[t]\n\\begin{lstlisting}[mathescape=true]\nTheorem closed_form_sum:\n  $\\forall$ n. sum n = (n * (n + 1)) DIV 2\nProof\n  nltac `\n   Induction on 'n'.\n   use [sum_def] to simplify.\n   use [sum_def, GSYM ADD_DIV_ADD_DIV] to simplify.\n   use [sum_def, GSYM ADD_DIV_ADD_DIV] to simplify.\n   '2 * SUC n + n * (n + 1) = SUC n * (SUC n + 1)' suffices to show the goal.\n   show 'SUC n * (SUC n + 1) = (SUC n + 1) + n * (SUC n + 1)' using (simplify with [MULT_CLAUSES]).\n   simplify.\n   show 'n * (n + 1) = SUC n * n' using (trivial using [MULT_CLAUSES, MULT_SYM]).\n   '2 * SUC n = SUC n + SUC n' follows trivially.\n   'n * (SUC n + 1) = SUC n * n + n' follows trivially.\n   rewrite assumptions. simplify.`\nQED\n\\end{lstlisting}\n\\caption{Complete proof of the closed form for summing natural numbers until $n$ using Lassie}\\label{fig:gaussProof}\n\\end{figure}\n\nMarking the complete statement, and running it with \\ekey{M-h M-r} will save the\ntheorem under the name \\lstinline{closed_form_sum}.\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"lassie-tutorial\"\n%%% End:\n", "meta": {"hexsha": "c7255d97961d2767b5e2ed08c492f1ea1c2f41c7", "size": 10449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Manual/Lassie-Tutorial/example1.tex", "max_stars_repo_name": "dwRchyngqxs/HOL", "max_stars_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 492, "max_stars_repo_stars_event_min_datetime": "2015-01-07T16:36:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T22:18:48.000Z", "max_issues_repo_path": "Manual/Lassie-Tutorial/example1.tex", "max_issues_repo_name": "dwRchyngqxs/HOL", "max_issues_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 759, "max_issues_repo_issues_event_min_datetime": "2015-01-01T00:40:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T17:33:39.000Z", "max_forks_repo_path": "Manual/Lassie-Tutorial/example1.tex", "max_forks_repo_name": "dwRchyngqxs/HOL", "max_forks_repo_head_hexsha": "3b1931c130fcab243da332adb2c1413c42c59cf9", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 126, "max_forks_repo_forks_event_min_datetime": "2015-02-17T03:20:30.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T00:42:55.000Z", "avg_line_length": 37.4516129032, "max_line_length": 138, "alphanum_fraction": 0.70781893, "num_tokens": 3137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898229217591, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.7919050720773237}}
{"text": "\\chapter{Conditionals and recursion}\n\\label{conditionals}\n\nThe main topic of this chapter is the {\\tt if} statement, which\nexecutes different code depending on the state of the program.\nBut first we want to introduce two new operators: integer \ndivision and modulo.\n\n\n\\section{Integer division and modulo}\n\nThe {\\bf integer division} operator, \\verb\"div\", divides\ntwo numbers and rounds down to an integer.  For example, \nsuppose the\nrun time of a movie is 105 minutes.  You might want to know how\nlong that is in hours.  In Perl, conventional division\nreturns a rational number (in many languages, it returns a \nfloating-point number, which is another kind of internal \nrepresentation for non-integer numbers):\n\n\\begin{verbatim}\n> my $minutes = 105;\n> $minutes / 60;\n1.75\n\\end{verbatim}\n\nBut we don't normally write hours with decimal points.  Integer \ndivision returns the integer number of hours, dropping the\nfraction part:\n\\index{operator!div}\n\\index{div operator}\n\\index{integer division}\n\n\\begin{verbatim}\n> my $minutes = 105;\n> my $hours = $minutes div 60;\n1\n\\end{verbatim}\n\nIn arithmetic, the integer division is sometimes called \n\\emph{Euclidean division}, which computes a quotient and a \nremainder.\n\\index{Euclidean division}\n\\index{division remainder}\n\nTo get the remainder, you could subtract off one hour in minutes:\n\n\\begin{verbatim}\n> my $remainder = $minutes - $hours * 60;\n45\n\\end{verbatim}\n\n\\index{integer division}\n\\index{floating-point division}\n\\index{division!integer}\n\\index{division!floating-point}\n\\index{modulo operator}\n\\index{operator!modulo}\n\n\nAn alternative is to use the {\\bf modulo operator}, \\verb\"%\", which\ndivides two numbers and returns the remainder.\n%\\index{$%$ modulo operator}\n%\\index{operator!$%$ (modulo)}\n\n\\begin{verbatim}\n> my $remainder = minutes % 60;\n45\n\\end{verbatim}\n%\nThe modulo operator is very common in programming languages\nand is more useful than it seems.  For example, you can \ncheck whether one number is divisible by another---if \n{\\tt \\$dividend \\% \\$divisor} is zero, then {\\tt \\$dividend} \nis divisible by {\\tt \\$divisor}. This is commonly use, for \nexample, with a divisor equal to 2 in order to determine \nwhether an integer is even or odd. We will see an example \nof that later in this chapter (see Section~{alternative.execution}).\n\\index{divisibility}\n\\index{even number}\n\\index{odd number}\n\\index{integer!even}\n\\index{integer!odd}\n\nTo tell the truth, Perl~6 also has a specific operator for \ndivisibility, \\verb\"%%\". The \\verb'$dividend %% $divisor' \nexpression returns a true value if\n\\verb'$divisor % $dividend' is equal to 0,  \nthat is if {\\tt \\$dividend} is divisible by {\\tt \\$divisor} (and false otherwise):\n\\index{divisibility!operator}\n\nAlso, you can extract the right-most digit\nor digits from a number with the modulo operator.  For example, {\\tt \\$x \\% 10} yields the\nright-most digit of {\\tt \\$x} (in base 10).  Similarly, {\\tt \\$x \\% 100}\nyields the last two digits:\n\n\\begin{verbatim}\n> 642 % 100;\n42\n\\end{verbatim}\n%\n\\index{modulo operator}\n\\index{operator!modulo}\n\n\n\n\\section{Boolean expressions}\n\\index{Boolean expression}\n\\index{expression!Boolean}\n\\index{logical operator}\n\\index{operator!logical}\n\nA {\\bf Boolean expression} is an expression that is either true\nor false.  The following examples use the operator {\\tt ==}, \nwhich compares two numeric operands and produces\n{\\tt True} if they are equal and {\\tt False} otherwise:\n\n\\begin{verbatim}\n> 5 == 5;\nTrue\n> 5 == 6;\nFalse\n\\end{verbatim}\n%\n{\\tt True} and {\\tt False} are special\nvalues that belong to the type {\\tt Bool}; they are not strings:\n\\index{True!special value}\n\\index{False!special value}\n\\index{special value!True}\n\\index{special value!False}\n\\index{Bool type}\n\\index{type!Bool}\n\n\\begin{verbatim}\n> say True.WHAT\n(Bool)\n> say False.WHAT\n(Bool)\n\\end{verbatim}\n%\n\\index{operator!$==$ (numeric equality)}\n\\index{$==$ numeric equality operator}\nThe {\\tt ==} operator is one of the {\\bf numeric relational operators} \nand checks whether the operands are equal; the others are:\n\n\\begin{verbatim}\n      $x != $y            # $x is not numerically equal to $y\n      $x > $y             # $x is  numerically greater than $y\n      $x < $y             # $x is  numerically less than $y\n      $x >= $y            # $x is  numerically greater than or equal to $y\n      $x <= $y            # $x is  numerically less than or equal to $y\n      $x === $y           # $x and $y are truly identical\n\\end{verbatim}\n% TODO: get these entries working in plastex\n\\ifplastex \\else\n\\index{\"!= numeric inequality operator@\\texttt{\"!=} numeric inequality operator}\n\\index{< less than numeric operator@\\texttt{<} less than numeric operator}\n\\index{> greater than numeric operator@\\texttt{>} greater than numeric operator}\n\\index{>= greater than or equal operator@\\texttt{>=} greater than or equal operator}\n\\index{<= less than or equal operator@\\texttt{<=} less than or equal operator}\n\\index{=== value identity operator@\\texttt{===} value identity operator}\n\\index{operator!\"!= (numeric inequality)@\\texttt{\"!=} (numeric inequality)}\n\\index{operator!< (numerically less than)@\\texttt{<} (numerically less than)}\n\\index{operator!> (numerically greater than)@\\texttt{>} (numerically greater than)}\n\\index{operator!>= (greater than or equal)@\\texttt{>=} (greater than or equal)}\n\\index{operator!<= (less than or equal)@\\texttt{<=} (less than or equal)}\n\\index{operator!=== (value identity)@\\texttt{===} (value identity)}\n\\fi\nAlthough these operations are probably familiar to you, the Perl\nsymbols are different from the mathematical symbols.  A common error\nis to use a single equal sign ({\\tt =}) instead of a double equal sign\n({\\tt ==}).  Remember that {\\tt =} is an assignment operator and\n{\\tt ==} is a relational operator.   There is no such thing as\n{\\tt =<}, and there exists a {\\tt =>} operator, but it is not a relational \noperator, but something completely different (it is,  as we'll see later, a pair constructor).\n\\index{relational operator}\n\\index{relational operator!numeric}\n\\index{numeric relational operator}\n\\index{equality operator}\n\\index{operator!equal}\n\\index{operator!relational}\n\\index{pair constructor}\n\\index{constructor!pair}\n% TODO: get these entries working in plastex\n\\ifplastex \\else\n\\index{=> pair constructor@\\texttt{=>} pair constructor}\n\\index{operator!=> (pair constructor)@\\texttt{=>} (pair constructor)}\n\\fi\n\nThe difference between {\\tt ==} and {\\tt ===} is that the \nformer operator checks whether the values of the operands \nare equal and the latter checks whether the operands are \ntruly identical. As an example, consider this:\n\n\\begin{verbatim}\nsay 42 ==  42;           # True\nsay 42 ==  42.0;         # True\nsay 42 ===  42;          # True\nsay 42 === 42.0;         # False\n\\end{verbatim}\n%\n\n\nThese relational operators can only compare numeric values\n(numbers or variables containing numbers) or values that \ncan be coerced to numeric values, such as, for example, \nthe string \"42\" which, if used with these operators \n(except {\\tt ===}), will be coerced to number 42.\n\\index{coercion}\n\nFor comparing strings (in a lexicographic or ``pseudo \nalphabetic'' type of comparison), you need to use \nthe {\\bf string relational operators}:\n\n\\begin{verbatim}\n      $x eq $y            # $x is string-wise equal to $y\n      $x ne $y            # $x is string-wise not equal to $y\n      $x gt $y            # $x is greater than $y (alphabetically after)\n      $x lt $y            # $x is less than $y (alphabetically before)\n      $x ge $y            # $x is greater than or equal to $y\n      $x le $y            # $x is less than or equal to $y\n      $x eqv $y           # $x is truly equivalent to $y\n\\end{verbatim}\n%  \n\\index{relational operator}\n\\index{relational operator!string}\n\\index{string!relational operator}\n\\index{operator!relational}\n\\index{eq, string equality operator}\n\\index{operator!eq (string equality)}\n\\index{ne, string inequality operator}\n\\index{operator!ne (string inequality)}\n\\index{operator!gt (alphabetically after)}\n\\index{operator!lt (alphabetically before)}\n\n\n\nFor example, you may compare (alphabetically) two former \nUS presidents:\n\\begin{verbatim}\n> 'FDR' eq 'JFK';\nFalse\n> 'FDR' lt 'JFK';    # alphabetical comparison\nTrue\n\\end{verbatim}\n%  \n\nUnlike most other programming languages, Perl~6 allows you to chain relational operators transitively, just as in mathematical notation:\n\n\\begin{verbatim}\nsay 4 < 7 < 12;      # True\nsay 4 < 7 < 5;       # False\n\\end{verbatim}\n\\index{chained relational operator}\n\nIt may be useful to point out that numeric relational operators \nand string relational operators don't work the same way (and \nthat's a good reason for having different operators), because \nthey don't have the same idea of what is \\emph{greater than} \nor \\emph{less than}.\n\nWhen comparing two positive integers, a number with four digits\nis always greater than a number with only two or three digits. \nFor example, 1110 is greater than 886. \n\nString comparisons, in contrast, basically follow (pseudo) alphabetical rules: 'b' is greater than 'aaa', because the commonly accepted rule for string comparisons is to start by comparing the first letter of each string: which string is greater is known if the two letters are different, irrespective of what character comes next; you need to proceed to comparing the second letter of each word only if comparing the first letter of each string led to a draw, and so on. Thus, any word starting with 'a' is less than any word starting with 'b', irrespective of the length of these words. You may think that this is nitpicking, but this becomes essential when you start sorting items: you really have to think about which type of order (numeric or alphabetical) you want to use.\n\\index{sorting}\n\nThere are also some so-called ``three-way'' relational operators, \n{\\tt cmp}, {\\tt <=>} and {\\tt leg}, but we'll come back to them \nwhen we study how to sort the items of a list. Similarly, we need \nto learn quite a few other things about Perl before we can do \njustice to the incredibly powerful and expressive smart match \noperator, \\verb\"~~\".\n\\index{sorting}\n\\index{smart match operator}\n\\index{operator!smart match}\n\\index{three-way operator}\n\\index{operator!three-way}\n\\index{cmp operator}\n\\index{leg operator}\n\\index{operator!leg}\n% TODO: get these entries working in plastex\n\\ifplastex \\else\n\\index{<=> operator@\\texttt{<=>} operator}\n\\index{operator!<=> (numeric comparison)@\\texttt{<=>} (numeric comparison)}\n\\fi\n\nA final point to be noted about string comparisons is \nthat uppercase letters are always deemed smaller \nthan lowercase letters. So \"A\", \"B\", \"BB\" and \"C\" \nare \\emph{all} less than \"a\", \"b\", \"bb\" and \"c\". We \nwill not go into the details here, but this becomes \nmore complicated (and sometimes confusing) when \nthe strings to be compared contain non alphabetical \ncharacters (or non ASCII Unicode letters).\n\n\\section{Logical operators}\n\\index{logical operator}\n\\index{operator!logical}\n\nThere are three main pairs of {\\bf logical operators}: \n\\begin{itemize}\n\\item logical \\emph{and}: ``{\\tt and}'' and {\\tt \\&\\&}, \n\\item logical \\emph{or}: ``{\\tt or}'' and {\\tt ||}, \n\\item logical \\emph{not}: ``{\\tt not}'' and {\\tt !}.\n\\end{itemize}\n\nThe semantics (meaning) of these operators is\nsimilar to their meaning in English.  For example,\n{\\tt \\$x > 0 and \\$x < 10} is true only if {\\tt \\$x} is greater \nthan 0 {\\em and} less than 10.\n\\index{and operator}\n\\index{or operator}\n\\index{not operator}\n\\index{operator!and}\n\\index{operator!or}\n\\index{operator!not}\n\n{\\tt \\$n \\% 2 == 0 and \\$n \\% 3 == 0} is true if {\\em both} \nconditions are true, that is, if the number is divisible by 2\n{\\em and} by 3, i.e. is in fact divisible by 6 (which could be better \nwritten as: {\\tt \\$n \\% 6 == 0} or {\\tt \\$n \\%\\% 6}).\n\n{\\tt \\$n \\% 2 == 0 or \\$n \\% 3 == 0} is true if {\\em either or \nboth} of the conditions is true, that is, if the number is \ndivisible by 2 {\\em or} by 3 (or both).\n\nFinally, the {\\tt not} operator negates a boolean\nexpression, so {\\tt not (x > y)} is true if {\\tt x > y} \nis false, that is, if {\\tt x} is less than or equal \nto {\\tt y}.\n\nThe {\\tt \\&\\&}, {\\tt ||} and {\\tt !} operators have the same \nmeanings, respectively, as {\\tt and}, {\\tt or} and {\\tt not}, \nbut they have a tighter precedence, which means that when \nthey stand in an expression with some other operators, \nthey have a higher priority of execution. We will come \nback to precedence later, but let's say for the time being \nthat, in most common cases, the {\\tt and}, {\\tt or} and \n{\\tt not} operators will usually do what you want.\n\\index{precedence}  \t\n\\index{operator precedence}\n\nStrictly speaking, the operands of the logical operators should \nbe boolean expressions, but Perl, just like many languages \npartly derived from C, is not very strict on that. The \nnumbers~0 and 0.0 are false; and any nonzero number \nor nonempty string is interpreted as {\\tt True}:\n\n\\begin{verbatim}\n> 42 and True;\nTrue\n\\end{verbatim}\n%\nThis flexibility can be very useful, but there are some \nsubtleties to it that might be confusing.  You might want \nto avoid it unless you know what you are doing.\n\nThe {\\tt so} built-in function returns a boolean evaluation of \nits argument:\n\n\\begin{verbatim}\n> say so (0 and True);\nFalse\n\\end{verbatim}\n%\nHere, the expression {\\tt (0 and True)} is false because 0 \nis false and the expression could be true only if both arguments \nof the {\\tt and} operator were true.\n\nWhen several boolean conditions are linked with some logical \noperator, Perl will only perform the comparisons that are \nstrictly necessary to figure out the final result, starting \nwith those on the left. For example, if you write:\n\n\\begin{verbatim}\n> False and $number > 0;\nFalse\n\\end{verbatim}\n%\nthere is no need to evaluate the second boolean expression \nto know that the overall expression will be false. In this case, \nPerl does not try to check whether the number is positive or \neven whether it is defined. It is sometimes said that \nthese operators ``short circuit'' unnecessary conditions.\n\\index{short-circuit boolean operators}\n\\index{short-circuit evaluation}\n\nSimilarly, in the following code, the {\\tt compute-pension} \nsubroutine will not even be called if the person's age is \nless than 65:\n\n\\begin{verbatim}\n$age >= 65 and compute-pension();\n\\end{verbatim}\n%\nThe same goes with the {\\tt or} operator, but in the other way \naround: if the first boolean expression of an {\\tt or} \nstatement is true, then the next expression will not be \nevaluated. The following code is thus equivalent to the previous \none:\n\n\\begin{verbatim}\n$age < 65 or compute-pension();\n\\end{verbatim}\n% \nThis \\emph{can} be a way of running the {\\tt compute-pension} \nsubroutine conditionally, depending on the value of the age, and \nthis is sometimes used, notably in idiomatic constructs such as:\n\\index{idiomatic}\n\n\\begin{verbatim}\ndo-something() or die \"could not do something\";\n\\end{verbatim}\n%\nwhich aborts the program if {\\tt do-something} returns a false \nvalue, meaning that it was not able to do something \nso essential that it would not make sense to try to continue \nrunning it.\n\nWe will examine now clearer and much more common \nways of running conditional code.\n\n\n\\section{Conditional execution}\n\\label{conditional.execution}\n\n\\index{conditional!statement}\n\\index{statement!conditional}\n\\index{if statement}\n\\index{statement!if}\n\\index{conditional!execution}\nIn order to write useful programs, we almost always need the ability\nto check conditions and change the behavior of the program\naccordingly.  {\\bf Conditional statements} give us this ability.  The\nsimplest form is the {\\tt if} statement:\n\n\\begin{verbatim}\nif $number > 0 {\n    say '$number is positive';\n}\n\\end{verbatim}\n%\nThe boolean expression after {\\tt if} is called the \n{\\bf condition}.  If it is true, the subsequent \nblock of code runs.  If not, nothing happens. The block of \ncode may contain any number of statements.\n\\index{condition}\n\nIt is conventional and highly recommended (although not \nstrictly mandatory from the standpoint of the compiler) \nto indent the statements in the block, in order to help \nvisualize the \\emph{control flow} of the program, i.e. \nits structure of execution: with such indentation, we \ncan see much better that the statements within the \nconditional block will run only if the condition is true.\n\\index{indentation}\n\nThe condition may be a compound boolean expression:\n\\begin{verbatim}\nif $n > 0 and $n < 20 and $n %% 2 {\n    say '$n is an even and positive number smaller than 20'\n}\n\\end{verbatim}\n%\nNote that in the print statement above, the final semi-colon \nhas been omitted. When a statement is the last code line of \na block, immediately before the curly brace {\\tt \\}} closing \nthat code block, the final semi-colon is optional and may \nbe omitted, though it might be considered good form to include it.\n\\index{omitting the semi-colon}\n\\index{semi-colon, omitting}\n\\index{bracket!curly}\n\\index{curly bracket}\n\\index{curly brace}\n\nIn theory, the overall code snippet above is itself a statement \nand should also end with a semi-colon after the closing brace. \nBut a closing curly brace followed by a newline character implies a statement separator, so you don't need a semi-colon here and it is generally omitted.\n\\index{omitting the semi-colon}\n\\index{semi-colon, omitting}\n\n\n\n\\section{Alternative execution}\n\\label{alternative.execution}\n\\index{alternative execution}\n\\index{else keyword}\n\\index{keyword!else}\n\nA second form of the {\\tt if} statement is ``alternative execution'',\nin which there are two possibilities and the condition determines\nwhich one runs.  Given a \\verb'$number' variable containing an \ninteger, the following code displays two different messages \ndepending on whether the value of the integer is even or odd::\n\n\\begin{verbatim}\nif $number % 2 == 0 {\n    say 'Variable $number is even'\n} else {\n    say 'Variable $number is odd'\n}\n\\end{verbatim}\n%\n\\index{even number}\n\\index{odd number}\n\\index{integer!odd}\n\\index{integer!even}\nIf the remainder when {\\tt \\$number} is divided by 2 is 0, \nthen we know that {\\tt \\$number} is even, and the program \ndisplays an appropriate message.  If\nthe condition is false, the second set of statements runs.\nSince the condition must be true or false, exactly one of the\nalternatives will run.  The alternatives are called \n{\\bf branches}, because they are branches in the flow of \nexecution.\n\\index{branch}\n\nNote that if \\verb'$number' is evenly divisible by two, \nthis code will print:\n\n\\begin{verbatim} \nVariable $number is even\n\\end{verbatim}\n\nliterally, without interpolating the \\verb'$number' variable \nvalue, because we have used single quotes for the purpose \nof printing out the variable name rather \nthan its value. We would have to use double quotes if \nwe wanted to display the variable's value instead of its \nname.\n\\index{single quote}\n\\index{double quote}\n\\index{quote!single}\n\\index{quote!double}\n\\index{variable!interpolation}\n\\index{interpolation}\n\n\n\\section{Chained conditionals}\n\\index{chained conditional}\n\\index{conditional!chained}\n\nSometimes there are more than two possibilities and we need more than\ntwo branches.  One way to express a computation like that is a \n{\\bf chained conditional}:\n\n\\begin{verbatim}\nif $x < $y {\n    say 'Variable $x is less than variable $y'\n} elsif $x > $y {\n    say 'Variable $x is greater than variable  $y' \n} else {\n    say 'Variables $x and $y are equal')\n}\n\\end{verbatim}\n%\nThe {\\tt elsif} keyword is an abbreviation of ``else if'' that \nhas the advantage of avoiding nesting of blocks. Again, exactly one\nbranch will run.  There is no limit on the number of {\\tt\nelsif} statements.  \n\nIf there is an {\\tt else} clause, it has to be\nat the end, but there doesn't have to be one.\n\\index{elsif keyword}\n\\index{keyword!elsif}\n\n\\begin{verbatim}\nif $choice eq 'a' {\n    draw_a()\n} elsif $choice eq 'b' {\n    draw_b()\n} elsif $choice eq 'c' {\n    draw_c()\n}\n\\end{verbatim}\n%\nEach condition is checked in order.  If the first is false,\nthe next is checked, and so on.  If one of them is\ntrue, the corresponding branch runs and the statement\nends.  Even if more than one condition is true, only the\nfirst true branch runs.  \n\n\n\\section{Nested conditionals}\n\\index{nested conditional}\n\\index{conditional!nested}\n\nOne conditional can also be nested within another.  We could have\nwritten the example in the previous section like this:\n\n\\begin{verbatim}\nif $x == $y {\n    say 'Variables $x and $y are equal'\n} else {\n    if $x < $y {\n        say 'Variable $x is less than variable $y'\n    } else {\n        say 'Variable $x is greater than variable $y'\n    }\n}\n\\end{verbatim}\n%\nThe outer conditional contains two branches.  The\nfirst branch contains a simple statement.  The second branch\ncontains another {\\tt if} statement, which has two branches of its\nown.  Those two branches are both simple statements,\nalthough they could have been conditional statements as well. \nThe \\verb'if $x < $y' conditional is said to be nested within \nthe {\\tt else} branch of the outer conditional.\n\nSuch nested conditionals show how critical it is for your \nown comprehension to properly indent conditional statements, \nas it would be very difficult here to visually grasp the \nstructure without the help of correct indentation.\n\\index{indentation}\n\nAlthough the indentation of \nthe statements helps make the structure apparent, \n{\\bf nested conditionals} become difficult to read very \nquickly.  It is a good idea to avoid them when you can.\nLogical operators often provide a way to simplify nested \nconditional statements.  For example, consider the \nfollowing code (which assumes \\verb'$x' to be an integer):\n\\index{logical operator}\n\n\\begin{verbatim}\nmy Int $x;\n# ... $x = ...;\nif 0 < $x {\n    if $x < 10 {\n        say 'Value of $x is a positive single-digit number.'\n    }\n}\n\\end{verbatim}\n%\nThe {\\tt say} statement runs only if we make it past both\nconditionals, so we can get the same effect with the {\\tt and} \nboolean operator, and the code can be rewritten using a \nsingle conditional:\n\n\\begin{verbatim}\nif 0 < $x and $x < 10 {\n    say '$x is a positive single-digit number.'\n}\n\\end{verbatim}\n\nFor this kind of conditions, Perl~6 provides a more concise \noption using the chained relational operators described earlier:\n\n\\begin{verbatim}\nif 0 < $x < 10 {\n    say '$x is a positive single-digit number.'\n}\n\\end{verbatim}\n\\index{chained relational operator}\n\n\\section{If conditionals as statement modifiers}\n\\index{statement modifier} \\index{modifier!statement}\n\\index{postfix conditional} \\index{conditional!postfix }\n\nThere is also a form of {\\tt if} called a {\\bf statement \nmodifier} (or sometimes  ``postfix conditional'') form when there is only \none conditional statement. In this case, the {\\tt if} and the \ncondition come after the code you want to run conditionally. Note \nthat the condition is still always evaluated first:\n\n\\begin{verbatim}\nsay '$number is negative.' if $number < 0;\n\\end{verbatim}\n%\nis equivalent to:\n\\begin{verbatim}\nif $number < 0 {\n    say '$number is negative.' \n}\n\\end{verbatim}\n%\nThis syntactic form is more concise as it takes only one code \nline instead of three. The advantage is that you can see more\nof your program code on one screen, without having to scroll up \nand down. However, this syntax is neat and clean only when \nboth the condition and the statement are short and simple, so it \nis probably best used only in these cases.\n\nThe statement modifier form does not allow {\\tt else} and\n{\\tt elsif} statements.\n\n\\section{Unless conditional statement}\n\\index{unless statement}\n\\index{keyword!unless}\n\nIf you don't like having to write negative conditions in a conditional\n{\\tt if} statement such as:\n%\n\\begin{verbatim}\nif not $number >= 0 {\n    say '$number is negative.' \n}\n\\end{verbatim}\n%\n\nyou may write instead this:\n\\begin{verbatim}\nunless $number >= 0 {\n    say '$number is negative.' \n}\n\\end{verbatim}\n%\nThis {\\bf unless} keyword does exactly what the English says: \nit will display the sentence ``\\$number is negative.'' \n\\emph{unless} the number is greater than or equal to 0.\n\nYou cannot use {\\tt else} or {\\tt elsif} statements with \n{\\tt unless}, because that would end up getting confusing.\n\nThe {\\tt unless} conditional is most commonly used in its statement modifier (or postfix notation) form:\n\n\\index{statement modifier} \\index{modifier!statement}\n\\index{postfix conditional} \\index{conditional!postfix }\n\n\\begin{verbatim}\nsay '$number is negative.' unless $number >= 0;\n\\end{verbatim}\n%\n\n\\section{For loops}\n\\label{for_loops}\n\\index{for loop}\n\\index{loop!for}\n\\index{statement!for}\n\\index{factorial}\n\nSuppose you need to compute and print the product of the first \nfive positive digits (1 to 5). This product is known in mathematics \nas the \\emph{factorial} of 5 and sometimes written as $5!$. You could write this program:\n\n\\begin{verbatim}\nmy $product = 1 * 2 * 3 * 4 * 5;\nsay $product;           # prints 120\n\\end{verbatim}\n%\n\nYou could make it slightly simpler:\n\\begin{verbatim}\nsay 2 * 3 * 4 * 5;      # prints 120\n\\end{verbatim}\n%\n\nThe problem is that this syntactic construct does \nnot scale well and becomes tedious for the product of the first \nten integers (or factorial 10). And it becomes almost a \nnightmare for factorial 100. \nCalculating the factorial of a number is a fairly common computation \nin mathematics (especially in the fields of combinatorics \nand probability) and in computer science. We need to \nautomatize it, and using a {\\tt for} \nloop is one of the most obvious ways of doing that.\n\\index{factorial!using a for loop}\n\n\\begin{verbatim}\nmy $product = 1;\nfor 1..5 {\n    $product *= $_\n}\nsay $product;           # prints 120\n\\end{verbatim}\n\nNow, if you need to compute factorial 100, you just need to \nreplace the 5 in the code above with 100. Beware, though, \nthe factorial function is known to grow extremely rapidly, \nand you'll get a truly huge number, with 158 digits \n(i.e. a number much larger than the estimated total \nnumber of atoms in the known universe).\n\\index{factorial}\n\n\\index{range!operator}\n\\index{operator!range}\n\\index{special variable}\nIn this script, {\\tt 1..5} is the range operator, which is used here \nto generate a list of consecutive numbers between 1 and 5. The \n{\\tt for} keyword is used to iterate over that list, and  \n\\verb\"$_\" is a special variable which takes each successive \nvalue of this list: first 1, then 2, etc. until 5. In the code \nblock forming the body of the loop, the {\\tt \\$product} variable \nis multiplied successively by each value of \\verb\"$_\". The loop \nends with 5 and the result, 120, is printed in the last line.\n\nThis is a simple use of the {\\tt for} statement, \nbut probably not the most commonly used in Perl~6; \nwe will see more below. We will also see other types of loops. \nBut that should be enough for now to let you write some loops. Loops \nare found everywhere in computer programming.\n\n\\index{special variable}\n\\index{topical variable}\n\\index{default method invocant}\n\\index{invocant}\n\\index{topic}\nThe \\verb\"$_\" special variable is known as the \\emph{topical \nvariable} or simply the \\emph{topic}. It does not need to be declared \nand many syntactic constructs assign a value to it without \nexplicitly mentioning it. Also, \\verb\"$_\" is a implicit argument \nto methods called without an explicit invocant. For example, \nto print the first five integers, you might write:\n\n\\begin{verbatim}\nfor 1..5 {.say};  # prints numbers 1 to 5, each on its line\n\\end{verbatim} \n\nHere {\\tt .say} is a syntax short hand equivalent to \\verb\"$_.say\". \nAnd since, as we saw, \\verb\"$_\" takes each successive value of \nthe range introduced by the {\\tt for} keyword, this very short code \nline prints each number between 1 and 5, each on a different line. \nThis is a typical example of the \\verb\"$_\" topical variable being used \nwithout even being explicitly mentioned. We will see many other \nuses of the \\verb\"$_\" special variable. \n\nSometimes, you don't use the \\verb\"$_\" loop variable within the \nloop, for example if you just want to do something 5 times but don't \ncare each time through the loop at which iteration you \nhave arrived. A subroutine that prints a message \\emph{n} times \nmight look like this:\n\n\\begin{verbatim}\nsub print-n-times (Int $n, Str $message) {\n    for 1..$n { say $message }\n} \n\\end{verbatim} \n\n\nThe {\\tt for} loop also has a statement modifier or postfix form \nused here to compute again the factorial of 5:\n\\index{statement modifier}\n\\index{postfix notation}\n\\index{factorial!using a for statement modifier}\n\n\\begin{verbatim}\nmy $product = 1;\n$product *= $_ for 1..5;\nsay $product;           # prints 120\n\\end{verbatim} \n\nThere is another syntax for the {\\tt for} loop, using an explicit loop variable:\n\\index{factorial!using a for pointy block }\n\n\\begin{verbatim}\nsub factorial (Int $num) { \n    my $product = 1;  \n    for 1..$num -> $x { \n        $product *= $x\n    }\n    return $product\n}\nsay factorial 10;   # 3628800\n\\end{verbatim} \n\nThe {\\tt for} loop in this subroutine is using what is called \na ``pointy block'' syntax. It is essentially the same idea \nas the previous {\\tt for} loops, except that, \ninstead of using the \\verb\"$_\" topical variable, we \nnow declare an explicit \\verb\"$x\" loop variable with the \n\\verb\"1..$num -> $x\" syntax to iterate over the range \nof values. Using an explicit loop variable can make your \ncode clearer when things get more complicated, for example \nwhen you need to nest several {\\tt for} loops. We will \nsee more examples of that later.\n\\index{pointy block}\n\\index{for loop}\n\\index{loop!for}\n\nWe will also see several other ways of computing the factorial \nof a number in this book.\n\\index{factorial}\n\n\\section{Recursion}\n\\label{recursion}\n\\index{recursion}\n\nIt is legal for one function or subroutine to call another;\nit is also legal for a subroutine to call itself.  It may not \nbe obvious why that is a good thing, but it turns out to be \none of the most magical things a program can do. \nFor example, look at the following subroutine:\n\n\\begin{verbatim}\nsub countdown(Int $time-left) {\n    if $time-left <= 0 {\n        say 'Blastoff!';\n    } else {\n        say $time-left;\n        countdown($time-left - 1);\n    }\n}\n\\end{verbatim}\n%\nIf {\\tt \\$n} is 0 or negative, it outputs the word, \n``Blastoff!''. Otherwise, it outputs {\\tt \\$time-left} \nand then calls a subroutine named {\\tt countdown}---itself---\npassing {\\tt \\$n-1} as an argument.\n\nWhat happens if we call this subroutine like this?\n\n\\begin{verbatim}\ncountdown(3);\n\\end{verbatim}\n%\nThe execution of {\\tt countdown} begins with {\\tt \\$time-left \n= 3}, and since {\\tt \\$time-left} is greater than 0, it \noutputs the value 3, and then calls itself...\n\n\\begin{quote}\nThe execution of {\\tt countdown} begins with {\\tt \\$time-left = 2}, and since\n{\\tt \\$time-left} is greater than 0, it outputs the value 2, and then calls itself...\n\n\\begin{quote}\nThe execution of {\\tt countdown} begins with {\\tt \\$time-left = 1}, and since\n{\\tt \\$time-left} is greater than 0, it outputs the value 1, and then calls itself...\n\n\\begin{quote}\nThe execution of {\\tt countdown} begins with {\\tt \\$time-left = 0}, and since {\\tt\n\\$time-left} is not greater than 0, it outputs the word, ``Blastoff!'' and then\nreturns.\n\\end{quote}\n\nThe {\\tt countdown} that got {\\tt \\$time-left = 1} returns.\n\\end{quote}\n\nThe {\\tt countdown} that got {\\tt \\$time-left = 2} returns.\n\\end{quote}\n\nThe {\\tt countdown} that got {\\tt \\$time-left = 3} returns.\n\nAnd then you're back in the main program.  So, the\ntotal output looks like this:\n\n\\begin{verbatim}\n3\n2\n1\nBlastoff!\n\\end{verbatim}\n%\nA subroutine that calls itself is {\\bf recursive}; the process of\nexecuting it is called {\\bf recursion}.\n\\index{recursion}\n\\index{function!recursive}\n\nAs another example, we can write a subroutine that prints a\nstring {\\tt \\$n} times.\n\n\\begin{verbatim}\nsub print-n-times(Str $sentence, Int $n) {\n    return if $n <= 0;\n    say $sentence;\n    print-n-times($sentence, $n - 1);\n}\n\\end{verbatim}\n%\nIf {\\tt \\$n <= 0}, the {\\bf return statement} exits the\nsubroutine.  The flow of execution immediately returns to \nthe caller, and the remaining lines of the subroutine don't\nrun. This illustrates a feature of the {\\tt return} subroutine \nthat we had not seen before: it is used here for flow \ncontrol, i.e. to stop the execution of the subroutine and \npass control back to the caller. Note also that, here, the \n{\\tt return} statement does not return any value to the \ncaller; {\\tt print-n-times} is a void function.\n\n\\index{return!statement}\n\\index{statement!return}\n\\index{void function}\n\nThe rest of the subroutine is similar to {\\tt countdown}: it \ndisplays {\\tt \\$sentence} and then calls itself to display \n{\\tt \\$sentence} $\\$n - 1$ additional times.  So the number \nof lines of output is {\\tt 1 + (\\$n - 1)}, which\nadds up to {\\tt \\$n}.\n\nFor simple examples like this, it may seem easier to use a {\\tt\nfor} loop.  But we will see examples later that are hard to write\nwith a {\\tt for} loop and easy to write with recursion, so it is\ngood to start early.\n\\index{for loop}\n\\index{loop!for}\n\n\n\\section{Stack diagrams for recursive subroutines}\n\\label{recursive.stack}\n\\index{stack diagram}\n\\index{function frame}\n\\index{frame}\n\nIn Section~\\ref{stackdiagram}, we used a stack diagram to represent\nthe state of a program during a subroutine call.  The same kind of\ndiagram can help interpret a recursive subroutine.\n\nEvery time a subroutine gets called, Perl creates a\nframe to contain the subroutine's local variables and parameters.\nFor a recursive subroutine, there might be more than one frame \non the stack at the same time.\n\nFigure~\\ref{fig.stack2} shows a stack diagram for {\\tt countdown} called with\n{\\tt n = 3}.\n\n\\begin{figure}\n\\centerline\n{\\includegraphics[scale=0.6]{figs/stack2.png}}\n\\caption{Stack diagram.}\n\\label{fig.stack2}\n\\end{figure}\n\n\nAs usual, the top of the stack is the frame for the main \nprogram.\nIt is empty because we did not create any variables in \nit or pass any arguments to it.\n\\index{base case}\n\\index{recursion!base case}\n\nThe four {\\tt countdown} frames have different values for the\nparameter {\\tt \\$time-left}.  The bottom of the stack, where {\\tt \\$time-left = 0}, is\ncalled the {\\bf base case}.  It does not make a recursive call, so\nthere are no more frames.\n\nAs an exercise, draw a stack diagram for \\verb\"print-n-times\" \ncalled with\n\\verb\"$sentence = 'Hello'\" and {\\tt \\$n = 2}.\nThen write a function called \\verb\"do-n-times\" that takes a function\nand a number, {\\tt \\$num}, as arguments, and that calls\nthe given function {\\tt \\$num} times.\n\\label{do_n_times}\n\\emph{Solution}: see Section~\\ref{sol_do_n_times}\n\n\n\\section{Infinite recursion}\n\\index{infinite recursion}\n\\index{recursion!infinite}\n\\index{runtime error}\n\n\nIf a recursion never reaches a base case, it goes on making\nrecursive calls forever, and the program never terminates.  This is\nknown as {\\bf infinite recursion}, and it is generally not\na good idea. In fact, your program will not actually execute \nforever but will die at some point when the computer runs out of \nmemory or some other critical resource.\n\nYou have to be careful when writing recursive subroutines. \nMake sure that you have a base case, and make sure that \nyou are guaranteed to reach it. Actually, although this is not \nabsolutely required by the language, we would advise you to \ntake the good habit of treating the base case first.\n\n\n\\section{Keyboard input}\n\\index{keyboard input}\n\nThe programs we have written so far accept no input from \nthe user. They just do the same thing every time. Perl \nprovides built-in functions that stop the program and\nwait for the user to type something. \n\nFor example, the {\\tt prompt} function prompts the user with \na question or an instruction. When the user presses \n{\\sf Return} or {\\sf Enter}, the program resumes and \n\\verb\"prompt\" returns what the user typed as a string \n(without the newline character corresponding to the \n{\\sf Return} key typed by the user).\n\\index{prompt function}\n\\index{function!prompt}\n\n\\begin{verbatim}\nmy $user = prompt \"Please type in your name: \";\nsay \"Hello $user\";\n\\end{verbatim}\n%\n\nThis is probably one of the most common ways to obtain \ninteractive user input, because it is usually a good idea \nto tell the user what is expected.\n\nAnother possibility is to use the {\\tt get} method (which\n reads a single line) on standard input:\n\\index{get function}\n\\index{function!get}\n\n\\begin{verbatim}\nsay \"Please type in your name: \";\nmy $user = $*IN.get;\nsay \"Hello $user\";\n\\end{verbatim}\n%\nor the {\\tt get} function, which reads a line from standard input by default:\n\\begin{verbatim}\nsay \"Please type in your name: \";\nmy $user = get;\nsay \"Hello $user\";\n\\end{verbatim}\n%\n\n\\section{Program arguments and the MAIN subroutine}\n\\label{MAIN}\n\\index{MAIN}\n\nThere is another (and often better) way to have a program \nuse varying input defined by the user, which is to pass \ncommand line arguments to the program, just as we have \npassed arguments to our subroutines.\n\nThe easiest way to retrieve arguments passed to a program is \nto use a special subroutine named \\verb'MAIN'. A program that \nhas a \\verb'MAIN' subroutine defined will usually start its execution \nwith that subroutine and the command-line arguments supplied \nto the program will be passed as arguments to \\verb'MAIN', \nso that the \\verb'MAIN' signature will enable you to \nretrieve the arguments provided in the command line and \npossibly also to check their validity.\n\\index{signature}\n\nFor example, the {\\tt greet.pl6} program might look like \nthis:\n\\begin{verbatim}\nsub MAIN (Str $name) {\n    say \"Hello $name\";\n}\n\\end{verbatim}\n\nYou may call this program twice with a changing command line \nargument as follows:\n\n\\begin{verbatim}\n$ perl6 greet.pl6 Larry\nHello Larry\n\n$ perl6 greet.pl6 world\nHello world\n\\end{verbatim}\n\nIt is very easy to change the argument, since all you need \nto do is to use the up arrow and edit the end of the \nprevious command line.\n\nIf you forget to supply the argument (or provide the wrong \nnumber of arguments, or arguments not matching the signature), \nthe program will die and Perl~6 will nicely generate and \ndisplay a usage method:\n\n\\begin{verbatim}\n$ perl6 greet.pl6\nUsage:\n  greet.pl6 <name>\n\\end{verbatim}\n\n\n\\section{Debugging}\n\\label{whitespace}\n\\index{debugging}\n\\index{traceback}\n\nWhen a syntax or runtime error occurs, the error message contains\na lot of information, but it can be overwhelming.  The most\nuseful parts are usually:\n\n\\begin{itemize}\n\n\\item What kind of error it was, and\n\n\\item Where it occurred.\n\n\\end{itemize}\n\nSyntax errors are usually easy to find, but there are a few\ngotchas. In general, error messages indicate where the problem was discovered, but the actual error might be earlier in \nthe code, sometimes on a previous line or even many lines \nbefore.\n\\index{multiplication tables}\n\nFor example, the following code aimed at displaying the \nmultiplication tables:\n\n\\begin{verbatim}\nsub multiplication-tables {\n    for 1..10 -> $x {\n\t    for 1..10 -> $y {\n            say \"$x x $y\\t= \", $x * $y;\n        say \"\";\n\t}\n}\n\nmultiplication-tables();\n\\end{verbatim}\n\nfails at compilation with the following error:\n\n\\begin{verbatim}\n$ perl6 mult_table.pl6\n===SORRY!=== Error while compiling /home/Laurent/mult_table.pl6\nMissing block (taken by some undeclared routine?)\nat /home/Laurent/mult_table.pl6:9\n------> multiplication-tables();<HERE><EOL>\n\\end{verbatim}\n\nThe error message reports an error on line~9 of the program \n(the last line of the code), at the end of the line, but \nthe actual error is a missing closing brace after line~4 \nand before line~5. The reason for that is that, while the \nprogrammer made the mistake on line~4, the Perl interpreter \ncould not detect this error before it reached the \nend of the program. The correct program for displaying \nmultiplication \ntables might be:\n\n\\begin{verbatim}\nsub multiplication-tables {\n    for 1..10 -> $x {\n        for 1..10 -> $y {\n            say \"$x x $y\\t= \", $x * $y;\n        }\n        say \"\";\n    }\n}\nmultiplication-tables();\n\\end{verbatim}\n\nWhen an error is reported on the last line of a program, \nit quite commonly due to a missing closing parenthesis, \nbracket, brace or quote mark several lines earlier. An editor with \nsyntax highlighting can sometimes help you.\n\\index{syntax!highlighting}\n\n\\index{error!runtime}\n\\index{runtime error}\n\nThe same is true of runtime errors. Consider this program aimed at computing 360 degrees divided successively by the integers between 2 and 5:\n\n\\begin{verbatim}\nmy ($a, $b, $c, $d) = 2, 3, 5;\nmy $value = 360;\n$value /= $_ for $a, $b, $c, $d;\nsay $value;\n\\end{verbatim}\n\nThis programs compiles correctly but displays a warning and \nthen an exception on runtime:\n\n\\begin{verbatim}\nUse of uninitialized value of type Any in numeric context \nin block  at product.pl6 line 3\nAttempt to divide 12 by zero using div\n  in block <unit> at product.pl6 line 4\n\\end{verbatim}\n%\n\nThe error message indicates a ``division by zero'' exception \non line~4, but there is nothing wrong with that line. \nThe warning on line~3 might give us the clue that the \nscript attempts to use an undefined value, but the real error \nis on the first line of the script, where one of the four \nnecessary integers (4) was omitted by mistake from the list \nassignment.\n\n\\index{division by zero}\n\\index{uninitialized value}\n\nYou should take the time to read error messages carefully, \nbut don't assume they point to the root cause of the \nexception, they often point to subsequent problems.\n\n\n\\section{Glossary}\n\n\\begin{description}\n\n\\item[integer division:] An operation, denoted {\\tt div}, \nthat divides two numbers and rounds down (toward zero) the \nresult to an integer.\n  \\index{integer division} \n  \\index{division!integer}\n\n\\item[modulo operator:]  An operator, denoted with a percent sign\n({\\tt \\%}), that works on integers and returns the remainder when one\nnumber is divided by another.\n\\index{modulo operator}\n\\index{operator!modulo}\n\n\\item[Boolean expression:]  An expression whose value is either \n{\\tt True} or {\\tt False}.\n\\index{Boolean expression}\n\\index{expression!Boolean}\n\n\\item[relational operator:] One of the operators that compares\nits operands. The most common numeric relational operator are  {\\tt ==}, {\\tt !=}, {\\tt >}, {\\tt <}, {\\tt >=}, and {\\tt <=}. The equivalent string relational operator are {\\tt eq}, {\\tt ne}, {\\tt gt}, {\\tt lt}, {\\tt ge}, and {\\tt le}.\n\n\\item[logical operator:] One of the operators that combines boolean\nexpressions: {\\tt and}, {\\tt or}, and {\\tt not}. The equivalent higher-precedence operators are {\\tt \\&\\&}, {\\tt ||}, and {\\tt !}\n\n\\item[conditional statement:]  A statement that controls the \nflow of execution depending on some condition.\n\\index{conditional!statement}\n\\index{statement!conditional}\n\n\\item[condition:] The boolean expression in a conditional \nstatement that determines which branch runs.\n\\index{condition}\n\n\\item[branch:] One of the alternative sequences of statements in\na conditional statement.\n\\index{branch}\n\n\\item[chained conditional:]  A conditional statement with a \nseries of alternative branches.\n\\index{chained conditional}\n\\index{conditional!chained}\n\n\\item[nested conditional:]  A conditional statement that appears\nin one of the branches of another conditional statement.\n\\index{nested conditional}\n\\index{conditional!nested}\n\n\\item[statement modifier:] A postfix conditional expression, i.e. \na conditional expression (using for example {\\tt if}, {\\tt unless} or \n{\\tt for}) that is placed after the statement the executions of which \nit controls. It can also refer to a postfix looping expression.\n\\index{statement modifier}\n\n\\item[return statement:] A statement that causes a function to\nend immediately and return to the caller.\n\n\\item[recursion:]  The process of calling the function that is\ncurrently executing.\n\\index{recursion}\n\n\\item[base case:]  A conditional branch in a\nrecursive function that does not make a recursive call.\n\\index{base case}\n\n\\item[infinite recursion:]  A recursion that doesn't have a\nbase case, or never reaches it.  Eventually, an infinite \nrecursion causes a runtime error, for which you may not want \nto wait because it may take a long time.\n\\index{infinite recursion}\n\n\\end{description}\n\n\\section{Exercises}\n%\n\n\\begin{exercise}\n%\nUsing the integer division and the modulo operators:\n\\index{modulo operator}\n\\index{operator!mod}\n\\index{mod, modulo operator}\n\\index{integer division}\n\\index{operator!div}\n\\index{div operator}\n\\label{int_div_modulo}\n\n\\begin{enumerate}\n\n\\item Write a subroutine that computes how many days, hours, minutes and seconds there are in the number of seconds passed as an argument to the subroutine.\n\n\\item Write a script that computes how many days, hours, minutes and seconds there are in 240,000 seconds.\n\n\\item Change your script to compute the number of days, hours, minutes and seconds there are in a number of seconds entered by the script user when prompted to give a number of seconds.\n\n\\end{enumerate}\n\n\\emph{Solutions:} Subsection~\\ref{sol_int_div_modulo}.\n\n\\end{exercise}\n\n\n\\begin{exercise}\n\\index{Fermat's Last Theorem}\n\\label{fermat_ex}\n\nFermat's Last Theorem says that there are no positive integers\n$a$, $b$, and $c$ such that\n\n\\[ a^n + b^n = c^n \\]\n%\nfor any values of $n$ greater than 2.\n\n\\begin{enumerate}\n\n\\item Write a function named \\verb\"check-fermat\" that takes four\nparameters---{\\tt a}, {\\tt b}, {\\tt c} and {\\tt n}---and\nchecks to see if Fermat's theorem holds.  If\n$n$ is greater than 2 and \n\n\\[a^n + b^n = c^n \\]\n%\nthe program should print, ``Holy smokes, Fermat was wrong!''\nOtherwise the program should print, ``No, that doesn't work.''\n\n\\item Write a function that prompts the user to input values\nfor {\\tt a}, {\\tt b}, {\\tt c} and {\\tt n}, converts them to\nintegers, and uses \\verb\"check-fermat\" to check whether they\nviolate Fermat's theorem.\n\\end{enumerate}\n\nSolution: \\ref{sol_fermat_ex}\n\n\n\\end{exercise}\n\n\n\\begin{exercise}\n\\index{triangle}\n\\label{triangle}\n\nIf you are given three sticks, you may or may not be able to arrange\nthem in a triangle.  For example, if one of the sticks is 12 inches\nlong and the other two are one inch long, you will\nnot be able to get the short sticks to meet in the middle.  For any\nthree lengths, there is a simple test to see if it is possible \nto form a triangle:\n\n\\begin{quotation}\nIf any of the three lengths is greater than the sum of the other\n  two, then you cannot form a triangle.  Otherwise, you\n  can.  (If the sum of two lengths equals the third, they form\n    what is called a ``degenerate'' triangle.)\n\\end{quotation}\n\n\\begin{enumerate}\n\n\\item Write a function named \\verb\"is-triangle\" that takes three\npositive numbers as arguments, and that prints either \n``Yes'' or ``No'', depending on whether you can \nform a triangle from sticks with the given lengths.\n\n\\item Write a function that prompts the user to input \nthree stick lengths and uses \\verb\"is-triangle\" to check \nwhether sticks with the given lengths can form a triangle.\n\n\\end{enumerate}\n\nSolution: \\ref{sol_triangle}\n\n\n\\end{exercise}\n\n\\begin{exercise} \n\\index{Fibonacci!numbers}\n\\label{fibonacci}\nThe Fibonacci numbers were invented by Leonardo Fibonacci \n(a.k.a. Leonardo of Pisa or simply Fibonacci), an Italian \nmathematician of the thirteenth century.\n\\index{Fibonacci, Leonardo}\n\nThe Fibonacci numbers are a sequence of numbers such as:\n\n\\[1, \\;1, \\;2, \\;3, \\;5, \\;8, \\;13, \\;21, \\;34, \\ldots\\]\n%\nin which the first two numbers are equal to 1 and each \nsubsequent number of the sequence is defined as the sum of \nthe previous two (for example, $5 = 2 + 3$, $8 = 3 + 5$, etc.).\n\nIn mathematical notation, the Fibonacci numbers could be defined by recurrence as follows:\n\n\\[F_1 = 1, \\;F_2 = 1, \\;\\;and\\;\\;  F_n = F_{n-1} + F_{n-2} \\]\n%\n\\begin{enumerate}\n\n\\item Write a program using a {\\tt for} loop that prints on screen the first 20 Fibonacci numbers.\n\n\\item Write a program which prompts the user to enter a number \n$n$ and, using a {\\tt for} loop, computes and displays the \n$n^{th}$ Fibonacci number.\n\n\\end{enumerate}\n\nSolution: \\ref{sol_fibonacci}\n\n\n\\end{exercise}\n\n\\begin{exercise}\n\\label{sub_recurse}\n\\index{recursion}\n\nWhat is the output of the following program?\nDraw a stack diagram that shows the state of the program\nwhen it prints the result.\n\n\\begin{verbatim}[fontshape=up]\nsub recurse($n, $s) {\n    if ($n == 0) {\n        say $s;\n    } else {\n        recurse $n - 1, $n + $s;\n    }\n}\nrecurse 3, 0;\n\\end{verbatim}\n\n\\begin{enumerate}\n\n\\item What would happen if you called this function like \nthis: {\\tt recurse(-1, 0)}?\n\n\\item Write a documentation comment (maybe in the form of a multiline comment) that explains everything someone would need to know in order to use this function (and nothing else).\n\n\\end{enumerate}\n\nSolution: \\ref{sol_sub_recurse}\n\n\\end{exercise}\n\n\n", "meta": {"hexsha": "c4d7ed3a122fc9c34cdd776cff5eb34aaeec2b67", "size": 48791, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/Conditional_and_recursion.tex", "max_stars_repo_name": "AllenDowney/ThinkPerl6", "max_stars_repo_head_hexsha": "11a83a00e566b6a7ecfc7cacf0412f885e90cb79", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-03-11T02:28:03.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-09T21:31:35.000Z", "max_issues_repo_path": "book/Conditional_and_recursion.tex", "max_issues_repo_name": "afcarl/ThinkPerl6", "max_issues_repo_head_hexsha": "11a83a00e566b6a7ecfc7cacf0412f885e90cb79", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 8, "max_issues_repo_issues_event_min_datetime": "2017-03-20T13:39:44.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-22T11:41:52.000Z", "max_forks_repo_path": "book/Conditional_and_recursion.tex", "max_forks_repo_name": "afcarl/ThinkPerl6", "max_forks_repo_head_hexsha": "11a83a00e566b6a7ecfc7cacf0412f885e90cb79", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2017-04-16T07:20:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-09T21:40:59.000Z", "avg_line_length": 32.2052805281, "max_line_length": 778, "alphanum_fraction": 0.7306470456, "num_tokens": 12643, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.9005297867852853, "lm_q1q2_score": 0.7916978453954017}}
{"text": "\\chapter {Differentiating Polynomials}\n\n\\section{Differentiating polynomials}\n\nIf you had a function that gave you the height of an object, it would\nbe handy to be able to figure out a function that gave you the\nvelocity at which it was rising or falling. The process of converting\nthe position function into a velocity function is known as\n\\emph{differentiation} or \\emph{finding the derivative}.\n\nThere are a bunch of rules for finding a derivative, but\ndifferentiating polynomials only requires three:\n\\begin{itemize}\n\\item The derivative of a sum is equal to the sum of the derivatives.\n\\item The derivative of a constant is zero.\n\\item The derivative of a nonconstant monomial $at^b$ ($a$ and $b$ are constant numbers, $t$ is time) is $abt^{b-1}$ \n\\end{itemize}\\index{differentiation!polynomials}\n\nSo, for example, if I tell you that the height in meters of quadcopter\nat second $t$ is given by $2t^3 - 5t^2 + 9t + 200$. You could tell me\nthat its vertical velocity is $6t^{2} - 10t + 9$\n\n\\begin{Exercise}[title={Differentation of polynomials}, label=diffpoly]\n  Differentiate the following polynomials.\n\\end{Exercise}\n\\begin{Answer}[ref=diffpoly]\n\\end{Answer}\nNotice that the degree of the derivative is one less than the degree\nof the original polynomial. (Unless, of course, the degree of the\noriginal is already zero.)\n\nNow, if you know that a position is given by a polynomial, you can\ndifferentate it to find the object's velocity at any time.\n\nThe same trick works for acceleration: Let's say you know a function\nthat gives an object's velocity. To find its acceleration at any time,\nyou take the derivative of the velocity function.\n\n\\begin{Exercise}[title={Differentation of polynomials in Python}, label=pydiffpoly]\n  Write a function that returns the derivative of a polynomial in \\filename{poly.py}. It should look like this:\n\\begin{Verbatim}\ndef derivative_of_polynomial(pn):\n  ...Your code here...\n\\end{Verbatim}\nWhen you test it in \\filename{test.py}, it should look like this:\n\\begin{Verbatim}\n# 3x**3 + 2x + 5\np1 = [5.0, 2.0, 0.0, 3.0]\nd1 = poly.derivative_of_polynomial(p1)\n# d1 should be 9x**2 + 2\nprint(\"Derivative of\", poly.polynomial_to_string(p1),\"is\", poly.polynomial_to_string(d1))\n\n# Check constant polynomials\np2 = [-9.0]\nd2 = poly.derivative_of_polynomial(p2)\n# d2 should be 0.0\nprint(\"Derivative of\", poly.polynomial_to_string(p2),\"is\", poly.polynomial_to_string(d2))\n\\end{Verbatim}\n\\end{Exercise}\n\\begin{Answer}[ref=pydiffpoly]\n\\begin{Verbatim}\ndef derivative_of_polynomial(pn):\n\n    # What is the degree of the resulting polynomial?\n    original_degree = len(pn) - 1\n    if original_degree > 0:\n        degree_of_derivative = original_degree - 1\n    else:\n        degree_of_derivative = 0\n\n    # We can ignore the constant term (skip the first coefficient)\n    current_degree = 1\n    result = []\n\n    # Differentiate each monomial\n    while current_degree < len(pn):\n        coefficient = pn[current_degree]\n        result.append(coefficient * current_degree)\n        current_degree = current_degree + 1\n\n    # No terms? Make it the zero polynomial\n    if len(result) == 0:\n        result.append(0.0)\n\n    return result\n\\end{Verbatim}\n\\end{Answer}\n", "meta": {"hexsha": "72d70a82f15b53187157c112157643ae543bc2ff", "size": 3184, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/differentiating-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/Polynomials/differentiating-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/Polynomials/differentiating-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 36.1818181818, "max_line_length": 117, "alphanum_fraction": 0.7402638191, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.9005297827809309, "lm_q1q2_score": 0.7916978390235226}}
{"text": "\\chapter{Functions}\\label{ch:functions}\n\nSeveral mathematical and string functions are implemented in\n\\aprepro{}.  To cause a function to be used, you enter the name\nof the function followed by a list of zero or more arguments in\nparentheses. For example\n\\begin{apinp}\n\\{sqrt(min(a,b*3))\\}\n\\end{apinp}\nuses the two functions \\cmd{sqrt()} and \\cmd{min()}. The arguments \\cmd{a} \nand \\cmd{b*3} are passed to \\cmd{min()}. The result is then passed as an \nargument to \\cmd{sqrt()}. The functions in \\aprepro{} are listed below \nalong with the number of arguments and a short description of their effect.\n\n\\section{Mathematical Functions}\n\nThe following mathematical functions are available in \\aprepro{}.\n\n\\begin{longtable}{lp{4.0in}}\n\\caption{Mathematical Functions}\\label{t:functions}\\\\\nSyntax              & Description \\\\\n\\hline\n\\endhead\nabs(x)              &  Absolute value of $x$. $|x|$.\\\\\nacos(x)             &  Inverse cosine of $x$, returns radians.\\\\\nacosd(x)            &  Inverse cosine of $x$, returns degrees.\\\\\nacosh(x)            &  Inverse hyperbolic cosine of $x$.\\\\\nasin(x)             &  Inverse sine of $x$, returns degrees.\\\\\nasin(x)             &  Inverse sine of $x$, returns radians.\\\\\nasinh(x)            &  Inverse hyperbolic sine of $x$.\\\\\natan(x)             &  Inverse tangent of $x$, returns radians.\\\\\natan2(x,y)          &  Inverse tangent of $y/x$, returns radians.\\\\\natan2d(x,y)         &  Inverse tangent of $y/x$, returns degrees.\\\\\natand(x)            &  Inverse tangent of $x$, returns degrees.\\\\\natanh(x)            &  Inverse hyperbolic tangent of $x$.\\\\\nceil(x)             &  Smallest integer not less than $x$.\\\\\ncos(x)              &  Cosine of $x$, with $x$ in radians\\\\\ncosd(x)             &  Cosine of $x$, with $x$ in degrees\\\\\ncosh(x)             &  Hyperbolic cosine of $x$.\\\\\nd2r(x)              &  Degrees to radians.\\\\\ndim(x,y)            &  $x - \\min(x,y)$\\\\\ndist(x1,y1, x2,y2)  &  $\\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}$ \\\\\nexp(x)              &  Exponential  $e^x$ \\\\\nfind\\_word(word,svar,del)&  Find 1-based index of \\var{word} in \\var{svar}. Words are separated by one or more of the characters in the string variable del. Returns 0 if \\var{word} is not found.\\\\\nfloor(x)            &  Largest integer not greater than $x$.\\\\\nfmod(x,y)           &  Floating-point remainder of $x/y$.\\\\\nhypot(x,y)          &  $\\sqrt{x^2+y^2}$.\\\\\nint(x), [x]         &  Integer part of $x$ truncated toward 0.\\\\\njulday(mm, dd, yy)  &  Julian day corresponding to mm/dd/yy. \\\\\njuldayhms(mm, dd, yy, hh, mm, ss)&  Julian day corresponding to mm/dd/yy at hh:mm:ss \\\\\nlgamma(x)           &  $\\log(\\Gamma(x))$.\\\\\nln(x)               &  Natural (base e) logarithm of $x$.\\\\\nlog(x)              &  Natural (base e) logarithm of $x$.\\\\\nlog10(x)            &  Base 10 logarithm of $x$. \\\\\nlog1p(x)            &  $log(1+x)$ Accurate even for very small values of $x$\\\\\nmax(x,y)            &  Maximum of $x$ and $y$. \\\\\nmin(x,y)            &  Minimum of $x$ and $y$. \\\\\nnint(x)             &  Rounds $x$ to nearest integer. $<0.5$ down; $>=0.5$ up.\\\\\npolarX(r,a)         &  $r * \\cos(a)$, $a$ is in degrees \\\\\npolarY(r,a)         &  $r * \\sin(a)$, $a$ is in degrees \\\\\nr2d(x)              &  Radians to degrees. \\\\\nrand(xl,xh)         &  Random value between $xl$ and $xh$; uniformly distributed. \\\\\nrand\\_lognormal(m,s)&  Random value with lognormal distribution with mean $m$ and stddev $s$.\\\\\nrand\\_normal(m,s)   &  Random value normally distributed with mean $m$ and stddev $s$.\\\\\nrand\\_weibull(a, b) &  Random value with weibull distribution with $\\alpha=a$ and $\\beta=b$. \\\\\nsign(x,y)           &  $x * \\text{sgn}(y)$\\\\\nsin(x)              &  Sine of $x$, with $x$ in radians. \\\\\nsind(x)             &  Sine of $x$, with $x$ in degrees. \\\\\nsinh(x)             &  Hyperbolic sine of $x$ \\\\\nsqrt(x)             &  Square root of $x$. $\\sqrt{x}$\\\\\nsrand(seed)         &  Seed the random number generator with the given integer value. At the beginning of \\aprepro{} execution, \\cmd{srand()}\n                       is called with the current time as the seed. \\\\\nstrtod(svar)        &  Returns a double-precision floating-point number equal to the value represented by the character string pointed to by \\var{svar}.\\\\\ntan(x)              &  Tangent of $x$, with $x$ in radians. \\\\\ntand(x)             &  Tangent of $x$, with $x$ in radians. \\\\\ntanh(x)             &  Hyperbolic tangent of $x$. \\\\\nVangle(x1,y1,x2,y2) &  Angle (radians) between vector $x_1\\hat{i}+y_1\\hat{j}$ and $x_2\\hat{i}+y_2\\hat{j}$.\\\\\nVangled(x1,y1,x2,y2)&  Angle (degrees) between vector $x_1\\hat{i}+y_1\\hat{j}$ and $x_2\\hat{i}+y_2\\hat{j}$.\\\\\nword\\_count(svar,del)&  Number of words in \\var{svar}. Words are separated by one or more of the characters in the string variable del.\\\\\n\\hline\n\\end{longtable}\n\n\\begin{longtable}{lp{4.0in}}\n\\caption{String Functions}\\label{t:stringfunctions}\\\\\nSyntax              & Description \\\\\n\\hline\n\\endhead\nDUMP()              &  Output a list of all defined variables and their value. \\\\\nDUMP\\_FUNC()        &  Output a list of all double and string functions recognized by \\aprepro{}. \\\\\nDUMP\\_PREVAR()      &  Output a list of all predefined variables and their value. \\\\\nIO(x)               &  Convert x to an integer and then to a string. Can be used to output integer values if your output format (\\cmd{\\_FORMAT}) is set to something that doesn't output integers correctly.  \\\\\nUnits(svar)         &  See Chapter~\\ref{ch:units}. \\var{svar} is one of the defined units systems: 'si', 'cgs', 'cgs-ev', 'shock', 'swap', 'ft-lbf-s', 'ft-lbm-s', 'in-lbf-s' \\\\\nerror(svar)         &  Outputs the string \\var{svar} to stderr and then terminates the code with an error exit status. \\\\\nexecute(svar)       &  \\var{svar} is parsed and executed as if it were a line read from the input file. \\\\\nexodus\\_info(filename, prefix) & Open the \\exo{} file and return a\nstring which is the concatenation of all \\exo{} info lines that begin\nwith ``prefix''. The prefix is stripped from the line. \\\\\nexodus\\_info(filename, begin, end) & Open the \\exo{} file and return a\nstring which is the concatenation of all \\exo{} info lines following\nthe line that matches ``begin'' up to the line that matches ``end''. \\\\\nexodus\\_meta(filename) & Open the \\exo{} file and create several variables based on the metadata in the \\exo{} file. \\\\\nextract(s, b, e)    &  Return substring \\var{[b,e)}. \\var{b} is included; \\var{e} is not. If \\var{b} not found, return empty; If \\var{e} not found, return rest of string. If \\var{b} empty, start at beginning; if \\var{e} empty, return rest of string. \\\\\nfile\\_to\\_string(fn)&  Opens the file specified by \\var{fn} and returns the contents as a multi-line string. \\\\\nget\\_date()         &  Returns a string representing the current date in the form YYYY/MM/DD. \\\\\nget\\_iso\\_date()    &  Returns a string representing the current date in the form YYYYMMDD. \\\\\nget\\_time()         &  Returns a string representing the current time in the form HH:MM:SS. \\\\\nget\\_word(n,svar,del&  Returns a string containing the \\var{n}th word of \\var{svar}. The words are separated by one or more of the characters in the string variable \\var{del}  \\\\\ngetenv(svar)        &  Returns a string containing the value of the environment variable \\var{svar}. If the environment variable is not defined, an empty string is returned.  \\\\\nhelp()              &  Tell how to get help on variables, functions, \\ldots \\\\\ninclude\\_path(path) &  Specify an optional path to be prepended to a filename when opening a file. Can also be specified via the \\cmd{-I} command line option when executing aprepro. \\\\\noutput(filename)    &  Creates the file specified by filename and\nsends all subsequent output from aprepro to that file. Calling \\cmd{output(\\\"stdout\\\")} will close the current output file and return output to the terminal (standard output).\\\\\noutput\\_append(fn)  &  If file with name \\var{fn} exists, append output to it; otherwise create the file and send all subsequent output from aprepro to that file. \\\\\nrescan(svar)        &  The difference between \\cmd{execute(sv1)} and \\cmd{rescan(sv2)} is that \\var{sv1} must be a valid expression, but \\var{sv2} can contain zero or more expressions.  \\\\\nto\\_lower(svar)     &  Translates all uppercase characters in \\var{svar} to lowercase. It modifies \\var{svar} and returns the resulting string.   \\\\\ntolower(svar)       &  Translates all uppercase characters in \\var{svar} to lowercase. It modifies \\var{svar} and returns the resulting string.   \\\\\nto\\_string(x)       &  Returns a string representation of the numerical variable \\var{x}. The variable \\var{x} is unchanged.  \\\\\ntostring(x)         &  Returns a string representation of the numerical variable \\var{x}. The variable \\var{x} is unchanged.  \\\\\nto\\_upper(svar)     &  Translates all lowercase character in \\var{svar} to uppercase. It modifies \\var{svar} and returns the resulting string.  \\\\\ntoupper(svar)       &  Translates all lowercase character in \\var{svar} to uppercase. It modifies \\var{svar} and returns the resulting string.  \\\\\n\\hline\n\\end{longtable}\n\nThe following example shows the use of some of the string functions. The input:\n\\begin{apinp}\n\\{t1 = \"ATAN2\"\\} \n\\{t2 = \"(0, -1)\"\\} \n\\{t3 = tolower(t1//t2)\\} \n\\{execute(t3)\\} \n\\end{apinp}\nproduces the output:\n\\begin{apout}\nATAN2 \n(0, -1)\natan2(0, -1)   \\textit{The variable t3 is equal to the string atan2(0,-1)} \n3.141592654    \\textit{The result is the same as executing \\{atan2(0, -1)\\}}\n\\end{apout}\n\nThis is admittedly a very contrived example; however, it does\nillustrate the workings of several of the functions. In the example,\nan expression is constructed by concatenating two strings together and\nconverting the resulting string to lowercase.  This string is then\nexecuted and simply prints the result of evaluating the expression.\n\nThe following example uses the \\cmd{rescan} function to illustrate a basic\nmacro capability in \\aprepro{}. The example calculates the coordinates\nof eleven points (Point1 \\ldots{} Point11) equally spaced about the\ncircumference of a 180 degree arc of radius 10.\n\n\\begin{apinp}\n\\{ECHO(OFF)\\}\\\n\\{num = 0\\} \n\\{rad = 10\\} \n\\{nintv = 10\\} \n\\{nloop = nintv + 1\\} \n\\{line = 'Define \\{\"Point\"//tostring(++num)\\}, \\{polarX(rad, (num-1) * \n  180/nintv)\\} \\{polarY(rad, (num-1)*180/nintv)\\}'\\}\n\\{ECHO(ON)\\} \n\\{loop(nloop)\\}\n\\{rescan(line)\\} \n\\{endloop\\}\n\\end{apinp}\n\nOutput:\n\n\\begin{apout}\nDefine  Point1,  10    0\nDefine  Point2,  9.510565163    3.090169944\nDefine  Point3,  8.090169944    5.877852523\nDefine  Point4,  5.877852523    8.090169944\nDefine  Point5,  3.090169944    9.510565163\nDefine  Point6,  6.123233765e-16    10\nDefine  Point7,  -3.090169944    9.510565163\nDefine  Point8,  -5.877852523    8.090169944\nDefine  Point9,  -8.090169944    5.877852523\nDefine  Point10,  -9.510565163    3.090169944\nDefine  Point11,  -10    1.224646753e-15\n\\end{apout}\n\nNote the use of the \\cmd{ECHO(OFF\\textbar{}ON)} block to \nsuppress output during the initialization phase, and the loop construct\nto automatically repeat the rescan line. The variable \\cmd{num} is converted \nto a string after it is incremented and then concatenated to build the name of \nthe point. In the definition of the variable \\cmd{line}, single quotes are first \nused since this is a multi-line string; double quotes are then used to embed another \nstring within the first string. To modify this example to calculate the coordinates \nof 101 points rather than eleven, the only change necessary would be to set \\cmd{\\{nintv=100\\}}.\n\n\\section{Additional Functions }\n\n\\subsection{[{\\em var}] or [{\\em expression}]} Surrounding a variable or expression\nby square brackets will return the integer value of that variable or\nexpression truncated toward zero. For example \\cmd{[sqrt(2)]} will return the value\n\\cmd{1}.\n\n\\subsection{File Inclusion} \\aprepro{} can read input from multiple \nfiles using the \\cmd{include()} and \\cmd{cinclude()} functions. If a line \nof the form: \n\n\\cmd{\\{include(\\texttt{\"}\\textit{filename}\\texttt{\"})\\}}\\\\\n\\cmd{\\{include(string\\_variable)\\}}\n\nis read, \\aprepro{} will open and begin reading from the file\n\\file{filename}.  A string variable can be used as the\nargument instead of a literal string value.  When the end of the file\nis reached, it will be closed and \\aprepro{} will continue\nreading from the previous file. The difference between\n\\cmd{include()} and \\cmd{cinclude()} is that if\n\\file{filename} does not exist, \\cmd{include()} will\nterminate \\aprepro{} with a fatal error, but \\cmd{cinclude()} will just\nwrite a warning message and continue with the current file. The\n\\cmd{cinclude()} function can be thought of as a {\\em conditional\ninclude}, that is, include the file if it exists. Multiple include\nfiles are allowed and an included file can also include additional\nfiles. This option can be used to set variables globally in several\nfiles. For example, if two or more input files share common points or\ndimensions, those dimensions can be set in one file that is included\nin the other files.\n\nIf \\cmd{ECHO(OFF)} is in effect during in an included file, \\cmd{ECHO(ON)} \nwill automatically be executed at the end of the included file.\n\n\\subsection{Conditionals} Portions of an input file can be conditionally processed \nthrough the use of the \\cmd{if(expression)}, \\cmd{elseif(expression)}, \\cmd{else}, and \\cmd{endif} \nconstruct.\\footnote{The \\cmd{Ifdef(expression)} and \\cmd{Ifndef(expression)} construct is deprecated. Please use \\cmd{if(expression)} and \\cmd{if(!expression)} instead.}\nThe syntax is: \n\n\\begin{apinp}\n\\{if(expression)\\}\n\\ldots Lines processed if 'expression' is true or non-zero.\n\\{elseif(expression2)\\}\n\\ldots Lines processed if 'expression' is false and 'expression2' is true.\n\\{else\\}\n\\ldots Lines processed if both 'expression' and 'expression2' are false.\n\\{endif\\}\n\\end{apinp}\n\nThe \\cmd{elseif()} and \\cmd{else} are optional.  Note that if \\var{expression} is a simple \\var{variable}, then its value will be zero or false if it is undefined; a zero value evaluates to false and a non-zero value is true. The \\cmd{if} construct can be nested multiple levels.\nA warning message will be printed if improper nesting is detected. The \\cmd{if(expression)}, \n\\cmd{elseif(expression)}, \\cmd{else}, and \\cmd{endif} are the \nonly text parsed on a line. Text that follows these on the same line is\nignored.  For example:\n\n\\begin{apinp}\n\\{if(a > 10 && b < 10)\\} This will be ignored no matter what\n\\ldots Lines processed if \\var{a} > 10 and \\var{b} < 10.\n\\{endif\\}\n\\end{apinp}\n\n\\subsection{Switch Statements}\nThe \\cmd{switch} statement is a control construct which allows the value of a variable or expression to change the control flow via a multi-way branch.\nThe construct is begun with a \\cmd{switch(expression)} statement followed by one or more \\cmd{case(expression)} statements and an optional \\cmd{default} statement. The construct is ended with an \\cmd{endswitch} statement.  The expression in the \\cmd{switch(expression)} statement is evaluated and compared to each \\cmd{case(expression)} statement in order.  If the values of the two expressions are equal, then the code following that \\cmd{case(expression)} is evaluated up to the next \\cmd{case()} or \\cmd{default} statement. If the expressions in more than one \\cmd{case()} match the initial \\cmd{switch()} expression, only the first one will be activated.  If none of the \\cmd{case()} expressions match the \\cmd{switch()} expression, then the code following the \\cmd{default} command will be evaluated. An example of the syntax is:\n\n\\begin{apinp}\n\\{a = 10*PI\\}\n\\{switch(10*PI + sin(0))\\}\n\\ldots This is ignored since it is after the switch, but before any \\cmd{case()} statements\n\\{case(1)\\}\n\\ldots This is not executed since \\var{1} is not equal to \\var{10*PI+sin(0)}\n\\{case(a)\\}\n\\ldots This is executed since \\var{a} matches the value of \\var{10*PI+sin(0)}\n\\{case(10*PI+sin(0))\\}\n\\ldots This is not executed since a previous case was executed.\n\\{default\\}\n\\ldots This is not executed since a previous case was executed.\n\\{endswitch\\}\n\\ldots This is executed since the switch construct\n is finished.\n\\end{apinp}\n\nSwitch constructs cannot be nested, but a \\cmd{switch()} can be used inside an \\cmd{if()} construct and an \\cmd{if()} can be used inside a \\cmd{case()} construct. \nThe \\cmd{switch(expression)}, \\cmd{case(expression)}, \\cmd{default}, and \\cmd{endswitch} are the only text parsed on a line. Text that follows these on the same line is\nignored.\n\n\\subsection{Loops} Repeated processing of a group of lines can be controlled \nwith the \\cmd{loop(control)}, and \\cmd{endloop} commands. The syntax is:\n\\begin{apinp}\n\\{loop(variable)\\}\n\\ldots Process these lines \\var{variable} times\n\\{endloop\\}\n\\end{apinp}\n\nLoops can be nested. A numerical variable or constant must be specified as the \nloop control specifier. You cannot use an algebraic expression such as\n\n\\cmd{\\{loop(3+5)\\}}.\n\nThe \\cmd{endloop} command must be on a line by itself with no other text except optional whitespace (spaces or tabs).\n\n\\subsection{ECHO}\\label{echo} The printing of lines to the output file can be controlled \nthrough the use of the \\cmd{ECHO(OFF)} and \\cmd{ECHO(ON)} \ncommands. The syntax is:\n\n\\begin{apinp}\n\\{ECHO(OFF)\\}\n\\ldots These lines will be processed, but not printed to output\n\\{ECHO(ON)\\}\n\\ldots These lines will be both processed and printed to output.\n\\end{apinp}\n\n\\cmd{ECHO} will automatically be turned on at the end of an included file. The \ncommands \\cmd{ECHO} and \\cmd{NOECHO} are synonyms for \\cmd{ECHO(ON)} and \\cmd{ECHO(OFF)}.\n\n\\subsection{VERBATIM} The printing of all lines to the output file without processing \ncan be controlled through the use of the \\cmd{VERBATIM(ON)} and \\cmd{VERBATIM(OFF)} \ncommands. The syntax is:\n\n\\begin{apinp}\n\\{VERBATIM(ON)\\}\n\\ldots These lines will be printed to output, but not processed\n\\{VERBATIM(OFF)\\}\n\\ldots These lines will be printed to output and processed\n\\end{apinp}\nNOTE:  there  is  a  major  difference  between  the  \\cmd{ECHO/NOECHO} commands, \nthe \\cmd{Ifdef/Endif }commands, and the \\cmd{VERBATIM(ON\\textbar{}OFF)} commands:\n\n\\begin{itemize}\n\\item \\cmd{ECHO(ON\\textbar{}OFF)} Lines processed, but not printed if \\cmd{ECHO(OFF)}\n\\item \\cmd{Ifdef/Endif} Lines not processed or printed if in \\cmd{Ifndef} block\n\\item \\cmd{VERBATIM(ON\\textbar{}OFF)} Lines not processed, but are printed.\n\\end{itemize}\n\n\\subsection{IMMUTABLE}\\label{immutable_block} Variables can either be\ncreated as mutable or immutable.  By default, all variables created\nduring a run of aprepro are mutable unless the \\cmd{--immutable} or\n\\cmd{-X} command line option is used to execute \\aprepro{}.  An\n\\cmd{IMMUTABLE} block can also be used to change \\aprepro{} such that\nall variables are created as immutable.  The syntax is:\n\\begin{apinp}\n\\{IMMUTABLE(ON)\\}\n\\ldots All variables created will be immutable\n\\{IMMUTABLE(OFF)\\}\n\\ldots The mutable/immutable state changes back to the default which\nis typically mutable unless \\aprepro{} executed with the\n\\cmd{--immutable} or \\cmd{-X} options.\n\\end{apinp}\nNote that any variables created as immutable are still immutable\nfollowing the \\cmd{IMMUTABLE(OFF)} command.\n\n\\subsection{Output File Specification} The \\cmd{output} function can be used \nto change the file to which \\aprepro{} is outputting the processed\ndata.  The syntax is: \\cmd{\\{output(\"\\file{filename}\")\\}}, where\n\\file{filename} is the name of the new output file. A string variable\ncan be used as the function argument. The previous output file is\nclosed. An error message is written and the code terminates if the\nfile cannot be opened. If \\cmd{output(\"\\file{stdout}\")} is specified,\nthen the current output file is closed and output is again written to\nthe standard output which is where output is written by default.\n\n\\subsection{\\exo{} Metadata Extraction} \\aprepro{} can parse the\nmetadata from a binary \\exo{}~\\cite{exodus} file and create several\nvariables which can then be used for calculations or decisions.  The\nfunction syntax is \\cmd{exodus\\_meta(filename)}. The\nargument to the function is a string containing the filename of the\nExodus file.  If the file does not exist in the current directory,\n\\aprepro{} will prepend the path specified by the \\cmd{--include} or\n\\cmd{-I} command line option.\n\nThe following scalar variables will be defined:\n\n\\begin{longtable}{lp{4.0in}}\n\\caption{\\exo{} Scalar Variables}\\\\\nVariable              & Description \\\\\n\\hline\n\\endhead\nex\\_dimension        & Spatial dimension \\\\\nex\\_node\\_count      & Number of nodes \\\\\nex\\_element\\_count   & Number of elements \\\\\nex\\_block\\_count     & Number of element blocks \\\\\nex\\_sideset\\_count   & Number of sidesets \\\\\nex\\_nodeset\\_count   & Number of nodesets \\\\\nex\\_timestep\\_count  & Number of timesteps \\\\\nex\\_version          & Version of the \\exo{} database \\\\\n\\hline \n\\end{longtable}\n\nThe following string variables will be defined if the model contains\none or more of the specific entity type.  The strings will be a\ncomma-separated concatenation of the names of the entity.  The\n\\cmd{get\\_word} function can be used to extract a specific sub-string.\n\n\\begin{longtable}{lp{4.0in}}\n\\caption{\\exo{} String Variables}\\\\\nVariable              & Description \\\\\n\\hline\n\\endhead\nex\\_title            & The title of the database \\\\\nex\\_block\\_names     & Element Block names.  Will be ``block\\_'' +\nblock id if no names on the database. \\\\\nex\\_block\\_topology  & The topology of the element blocks.  Converted\nto all lowercase. \\\\\nex\\_sideset\\_names   & Sideset names.  Will be ``sideset\\_'' + sideset\nid if no names on the database. \\\\\nex\\_nodeset\\_names   & Nodeset names.  Will be ``nodeset\\_'' + nodeset\nid if no names on the database. \\\\\n\\hline \n\\end{longtable}\n\nThe following array variables will be defined if the model contains\none or more of the specific entity type.  \n\n\\begin{longtable}{lccp{4.0in}}\n\\caption{\\exo{} Array Variables}\\\\\nVariable              & Rows  & Columns & Description \\\\\n\\hline\n\\endhead\nex\\_block\\_ids\t      & ex\\_block\\_count & 1 & Element Block Ids. \\\\\nex\\_block\\_info\t      & ex\\_block\\_count & 4 & Element Block info:\nid, number of elements in block, number of nodes per element, number\nof attributes. \\\\\nex\\_sideset\\_ids      & ex\\_sideset\\_count & 1 & Sideset Ids. \\\\\nex\\_sideset\\_info     & ex\\_sideset\\_count & 3 & Sideset info: id,\nnumber of faces in sideset, number of distribution factors. \\\\\nex\\_nodeset\\_ids      & ex\\_nodeset\\_count & 1 & Nodeset Ids. \\\\\nex\\_nodeset\\_info     & ex\\_nodeset\\_count & 3 & Nodeset info: id,\nnumber of nodes in nodeset, number of distribution factors. \\\\\nex\\_timestep\\_times   & ex\\_timestep\\_count & 1 & Timestep times. \\\\\n\\hline \n\\end{longtable}\n\nThe following shows an example of the variables which are defined:\n\n\\begin{apinp}\n  {exodus\\_meta(\"filename.e\")}\n  {DUMP()}\n  Element Block IDs:\n  {print\\_array(transpose(ex\\_block\\_ids))}\n  \n  Element Block Info: (id, num, nnpe, nattrib)\n  {print\\_array(ex\\_block\\_info)}\n\\end{apinp}\n\n\\begin{apout}\n$   Variable    = Value\n$  {ex\\_block\\_count\t= 8}\n$  {ex\\_nodeset\\_ids\t (array) rows = 6, cols = 1}\n$  {ex\\_block\\_names\t= \"block\\_8,block\\_7,block\\_6,block\\_5,block\\_4,block\\_3,block\\_2,block\\_1\"}\n$  {ex\\_block\\_topology\t= \"hex,hex,hex,hex,hex,hex,hex,hex\"}\n$  {ex\\_nodeset\\_info\t (array) rows = 6, cols = 3}\n$  {ex\\_sideset\\_count\t= 0}\n$  {ex\\_dimension\t= 3}\n$  {ex\\_element\\_count\t= 64}\n$  {ex\\_nodeset\\_names\t= \"nodeset\\_10,nodeset\\_100,nodeset\\_20,nodeset\\_200,nodeset\\_30,nodeset\\_300\"}\n$  {ex\\_nodeset\\_count\t= 6}\n$  {ex\\_block\\_ids\t (array) rows = 8, cols = 1}\n$  {ex\\_block\\_info\t (array) rows = 8, cols = 4}\n$  {ex\\_timestep\\_times\t (array) rows = 11, cols = 1}\n$  {ex\\_version\t= 2.029999971}\n$  {ex\\_timestep\\_count\t= 11}\n$  {ex\\_title  \t= \"Sierra output: dummy title\"}\n$  {ex\\_node\\_count\t= 125}\n\nElement Block IDs:\n\t8\t7\t6\t5\t4\t3\t2\t1\n\nElement Block Info: (id, num, nnpe, nattrib)\n\t8\t8\t8\t0\n\t7\t8\t8\t0\n\t6\t8\t8\t0\n\t5\t8\t8\t0\n\t4\t8\t8\t0\n\t3\t8\t8\t0\n\t2\t8\t8\t0\n\t1\t8\t8\t0\n\\end{apout}\n\n\\subsection{\\exo{} Info Records Extraction} \\aprepro{} can extract all\nor a portion of the ``information records'' from a binary \\exo{} file\nand return the results as a string variable. \n\nThere are two forms of the function.  The first function has the\nsyntax:  \\cmd{exodus\\_info(filename, prefix)}.  This will read\nthe information records from the \\exo{} database specified by the\nstring variable \\var{filename} and search for lines\nthat begin with the specified \\var{prefix}.  If a line is found, the\n\\var{prefix} will be stripped from the line and the remaining\ncharacters on the line will be concatenated onto the return string\nfollowed by a newline character.\n\nThe second function has the syntax: \\cmd{exodus\\_info(filename, begin, end)}.\nThis will read the information records from the \\exo{} database\nspecified by the string variable \\var{filename} and search for a line\nthat matches the string variable \\var{begin}.  It will then append all\nsubsequent information lines onto the return string until a line that\nmatches the string variable \\var{end} or it reaches the end of the\ninformation records.  If there is another line matching \\var{begin},\nit will resume appending lines to the return string.\n\nThe returned string can then be operated on as a normal \\aprepro{}\nvariable.\n\n", "meta": {"hexsha": "b6906f3dc9d498566f5c3505bf76ac128af186c3", "size": 25222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "packages/seacas/doc-source/aprepro/functions.tex", "max_stars_repo_name": "mathstuf/seacas", "max_stars_repo_head_hexsha": "49b3466e3bba12ec6597e364ce0f0f149f9ca909", "max_stars_repo_licenses": ["BSD-3-Clause", "NetCDF", "Zlib", "MIT"], "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/seacas/doc-source/aprepro/functions.tex", "max_issues_repo_name": "mathstuf/seacas", "max_issues_repo_head_hexsha": "49b3466e3bba12ec6597e364ce0f0f149f9ca909", "max_issues_repo_licenses": ["BSD-3-Clause", "NetCDF", "Zlib", "MIT"], "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/seacas/doc-source/aprepro/functions.tex", "max_forks_repo_name": "mathstuf/seacas", "max_forks_repo_head_hexsha": "49b3466e3bba12ec6597e364ce0f0f149f9ca909", "max_forks_repo_licenses": ["BSD-3-Clause", "NetCDF", "Zlib", "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.2642276423, "max_line_length": 834, "alphanum_fraction": 0.7001823805, "num_tokens": 7350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240177362488, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7916782641564112}}
{"text": "\\problemname{Arithmetic Decoding}\n\nArithmetic coding is a method to represent a message as a real number\n$x$ such that $0 \\leq x < 1$. We will assume that the\nmessage consists only of uppercase `A's and `B's.  The two letters\nhave associated probabilities $p_A$ and $p_B = 1 - p_A$ such that\n$0 < p_A < 1$.\n\nThe current interval $[a,b)$ is initially set to $[0,1)$ and we will\nupdate this interval one letter at a time.  To encode\na letter, the current interval is divided into two subintervals\nas follows.  Let $c = a + p_A(b-a)$.  If the next letter is `A',\n$[a,c)$ becomes the current interval.  Otherwise, the current interval\nis now $[c,b)$.  This process is repeated for each letter in the\nmessage.  If $[k,\\ell)$ is the final interval, the encoded message is\nchosen to be $k$.\n\nFor example, if the original message is ``ABAB'' and $p_A = p_B = 0.5$,\nthe sequence of intervals encountered in the algorithm is\n\\[ [0,1) \\xrightarrow{A} [0, 0.5) \\xrightarrow{B} [0.25, 0.5)\n  \\xrightarrow{A} [0.25, 0.375) \\xrightarrow{B} [0.3125, 0.375). \\]\nThe encoded message is therefore 0.3125, or 0.0101 in binary.\n\nGiven the length of the message, the probabilities, and the encoded\nmessage, determine the original message.\n\n\\section*{Input}\n\nThe first line contains the integer $N$ ($1 \\leq N \\leq 15$), which\nis the length of the original message.  The\nsecond line contains the integer $D$ ($1 \\leq D \\leq 7$),\nwhich indicates that $p_A = \\frac{D}{8}$.\nThe third line contains the binary representation of the encoded message.\nIt is guaranteed that the binary representation of the encoded message\nstarts with ``0.'' and contains at most $3N+2$ characters.\n\nIt is guaranteed that the encoded message came from an initial message\nof length $N$ consisting only of `A' and `B' using this value of $p_A$.\n\n\\section*{Output}\n\nDisplay the original message.\n", "meta": {"hexsha": "91a1b6ed7053ccc1df631fc84988e51b8d8193f4", "size": 1846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems/arithmeticdecoding/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/arithmeticdecoding/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/arithmeticdecoding/problem_statement/problem.tex", "max_forks_repo_name": "icpc/na-rocky-mountain-2020-public", "max_forks_repo_head_hexsha": "d77cd0dfd9bd707f34497977251c4cc583647fef", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-03-11T18:15:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-24T00:15:32.000Z", "avg_line_length": 42.9302325581, "max_line_length": 73, "alphanum_fraction": 0.7237269772, "num_tokens": 545, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009503523291, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7915943370072318}}
{"text": "\\section{Indefinite Integrals \\& Ways to Solve Them}\r\n\r\n\\subsection{Definition of an Indefinite Integral}\r\nWe've seen in the previous section from the Fundamental Theorem of Calculus how we can let the upper bound of a definite integral be a variable, giving us a new function that is an antiderivative of the function being integrated.\r\nAnti-differentiation is a useful operation, so notationally we drop the bounds from the definite integral, which we call an indefinite integral.\r\n\\begin{definition}\r\n\tThe indefinite integral of some continuous function $f$ is\r\n\t\\begin{equation*}\r\n\t\t\\int{f(x)\\d{x}} = \\int_{a}^{x}{f(t)\\d{t}} = F(x) - F(a) = F(x) + C,\r\n\t\\end{equation*}\r\n\twhere $F(x)$ is the antiderivative of $f$.\r\n\\end{definition}\r\n\r\nRather than choose a particular value for $C$, we just write ``$+C$'' when integrating to capture all antiderivatives.\r\nNote that since we defined an indefinite integral in terms of a definite integral, all the basic properties of definite integrals still apply.\r\n\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{\\cos{x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe derived previously that the derivative of $\\sin{x}$ is $\\cos{x}$.\r\n\tSo, for any real constant $C$, $\\sin{x} + C$ is the antiderivative of $\\cos{x}$.\r\n\t\\begin{equation*}\r\n\t\t\\int{\\cos{x}\\d{x}} = \\sin{x} + C.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Indefinite Integrals Properties \\& Strategies}\r\nKnowing that the indefinite integral give us the antiderivative, we can simply apply the rules we derived for derivatives in reverse.\r\n\r\n\\subsubsection{Power Rule \\& Integral of $1/x$}\r\n\\begin{lemma}\r\n\tLet $n \\neq -1$ be a real number.\r\n\tThen\r\n\t\\begin{equation*}\r\n\t\t\\int{x^n \\d{x}} = \\frac{x^{n+1}}{n+1} + C.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\n\r\n$n = -1$ has to be a special case, otherwise the denominator would be 0. \\\\\r\n\r\n\r\nWe derived earlier that that the derivative of $\\ln{x}$ was $1/x$.\r\nHowever, we have to be a little more careful before we write the integral of $1/x$.\r\n$1/x$ is defined for all real values except 0, but $\\ln{x}$ is only defined for positive values.\r\nSo, we need a different antiderivative, which would have to be equal to $\\ln{x}$ for positive $x$, that's defined everywhere that $1/x$ is defined.\r\n$\\ln{\\abs{x}}$ works nicely because it's defined everywhere that $1/x$ is defined, it's the antiderivative for positive $x$, and its slope for negative values of $x$ corresponds exactly to how $1/x$ is negative for negative values of $x$.\r\n\\begin{lemma}\r\n\t\\begin{equation*}\r\n\t\t\\int{\\frac{1}{x}\\d{x}} = \\ln{\\abs{x}} + C.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\n\\subsubsection{Exponential Rule}\r\nSince $e^x$ is its own derivative, it's also its own antiderivative.\r\nA similar idea applies for any base.\r\n\\begin{lemma}\r\n\t\\begin{equation*}\r\n\t\t\\int{b^x\\d{x}} = \\frac{b^x}{\\ln{b}} + C.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\n\r\n\\input{./integrals/usub.tex}\r\n\\input{./integrals/integration_by_parts/integration_by_parts.tex}", "meta": {"hexsha": "ce6716931d6cbf3831133db82192f35496a7db74", "size": 2993, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/integrals/indefinite_integrals.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/integrals/indefinite_integrals.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/integrals/indefinite_integrals.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 43.3768115942, "max_line_length": 239, "alphanum_fraction": 0.7016371534, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.8596637559030338, "lm_q1q2_score": 0.7915695167790325}}
{"text": "%begin-include\n\n\\section{Propositions}\n\n\\begin{para}[Propositions]\nThe central concept in propositional logic is (you guessed it!) that of a proposition.\nA \\emph{proposition} is a statement that can be either true or false.\nIf a proposition is true, we say that its \\emph{truth value} is $1$; if it is false, we say that its truth value is $0$.\n\nPropositions can be modified and joined through the use of \\emph{connectives}.\nA connective is said to be $n$-ary if it takes $n$ propositions as input to return a new one.\nThe most basic example of a connective is the unary (1-ary) \\emph{negation} connective. As its name suggests, it takes a proposition $P$ and transforms it into a proposition $(\\lnot P)$ that is true if and only if $P$ is false.\nFor instance, let us consider the proposition ``I am human''. Since that proposition is true, the proposition $(\\lnot(\\tx{I am human}))$, which stands for ``I am not human'', is false. \n\nLet $*$ be an arbitrary binary connective that, when acting on two propositions $P$ and $Q$, yields a proposition $P* Q$. If $P * Q$ has the same truth value as $Q * P$ for any propositions $P$ and $Q$, we say that $*$ is \\emph{symmetric}.\nMoreover, if, for any propositions $P$, $Q$ and $R$, the truth value of $P * (Q * R)$ is the same as that of $(P* Q) * R$, we say that $*$ is \\emph{associative}.\n\\end{para}\n\n\\begin{para}[Propositional variables and forms]\nOur attention should not be focused on particular propositions, but on the way connectives act on them in an abstract way.\nFor that purpose, we shall use \\emph{propositional variables}, which are nothing more than symbols representing arbitrary propositions.\nKeep in mind, however, that propositional variables are not propositions by themselves: they only ``become'' propositions when they have been assigned a particular proposition, this is, a particular truth value.\nA statement involving only propositional variables and connectives (such as $(\\lnot p)$) is said to be a \\emph{propositional form}.\nNotice that propositional variables may well be used to represent arbitrary propositional forms.\n\nIt should be clear that there is no point in talking about the truth value of a propositional form in an absolute manner: we can only talk about it under a particular assignment of truth values to its propositional variables.\nNevertheless, there are two special cases that deserve some attention.\nIf a propositional form is true for any possible assignment of truth values to its variables, it is said to be a \\emph{tautology}; if it is false for every possible assignment, it is said to be a \\emph{contradiction}.\n\nIn order to better distinguish propositions from propositional variables, we will consistently use lower-case letters to represent propositional variables and upper-case letters for propositions.\n\\end{para}\n\n\\begin{para}[Conjunction and disjunction]\nMoving on to more sophisticated connectives, the \\emph{conjunction} connective ``and'' is a binary (2-ary) connective: if we consider the propositions ``I am human'' and ``I like cheese'', we can construct the proposition ``I am human \\und{and} I like cheese''.\nAs was to be expected, if $p$ and $q$ are propositional variables, the propositional form ``$p$ and $q$'' (written $(p\\land q)$) is true if and only if $p$ and $q$ are both true. This can be represented using what is known as a \\emph{truth table}.\n\\begin{center}\n\\begin{tabular}[]{|c|c||c|}\n\\hline $p$ & $q$ & $p\\land q$ \\\\\n\\hline\\hline 0 & 0 & 0 \\\\\n\\hline 0 & 1 & 0 \\\\\n\\hline 1 & 0 & 0 \\\\\n\\hline 1 & 1 & 1 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nAs you can see, a truth table is just a convenient way of writing down the truth value of a propositional form for each and every possible assignment of truth values to the propositional variables it consists of.\n\nWith the two connectives that we already have, we can now formulate our first contradiction! The propositional form $(p\\land (\\lnot p))$ is false for any possible truth value of $p$.\n\nAnother example of a binary connective is the \\emph{disjunction} connective ``or'', which, when applied on two propositional variables $p$ and $q$, transforms them into a propositional form $(p\\lor q)$ that is true if and only if at least one of $p$ and $q$ is true. Its corresponding truth table is the following.\n\\begin{center}\n\\begin{tabular}[]{|c|c||c|}\n\\hline $p$ & $q$ & $p\\lor q$ \\\\\n\\hline\\hline 0 & 0 & 0 \\\\\n\\hline 0 & 1 & 1 \\\\\n\\hline 1 & 0 & 1 \\\\\n\\hline 1 & 1 & 1 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nUsing the disjunction connective, we can now write down our first tautology: $(p\\lor \\lnot p)$. To be or not to be? That's the tautology!\n\\end{para}\n\n\\begin{para}\n\n\\label{hierarchy}\nWhen combining a group of propositions or propositional forms with connectives, it is important to use parentheses to define the order in which the connectives have to be applied.\nFor instance, given three propositional variables $p_1$, $p_2$ and $p_3$, we can construct the propositional form $(p_1 \\land (p_2 \\lor p_3))$. Notice how failing to use parentheses would lead to an ambiguous expression, for $p_1 \\land (p_2\\lor p_3)$ is not the same as $(p_1 \\land p_2) \\lor p_3$.\n\nThere are, nevertheless, a few exceptions where parentheses are unnecessary.\nThe first of them is result of convention (such as the order of operations that we all learn in elementary school):  whenever a unitary connective is acting on a propositional variable, there is no need to write a parentheses.\nIn this way, $\\lnot p \\land q$ is the same as $(\\lnot p)\\land q$ and should not be mistaken with $\\lnot(p\\land q)$.\nThe second exception is more natural: whenever we have a sequence of propositional variables joined by an associative binary connective, parentheses are not necessary within that sequence because, regardless of how we wrote them, the resulting proposition would always yield the same truth values.\nThus, for example, we can safely write $p_1\\land p_2 \\land p_3$ instead of $p_1\\land (p_2 \\land p_3)$ or $(p_1\\land p_2) \\land p_3$.\nLastly, there is an obvious exception: the parentheses that surround a full symbolic expression are completely dispensable in propositional logic, so $(p\\land q)$ can perfectly be written as $p\\land q$.\n\nAs a rule of thumb --- not just for propositions, but for everything in mathematics --- you can omit parentheses whenever doing so leads to no ambiguity, whenever the parentheses add no meaning or whenever a convention removes any possible ambiguity. \n\n\\end{para}\n\n\\begin{para}[Conditional connective]\nLet us now introduce one of the most important binary connectives --- and, unfortunately, one of the most problematic for newcomers, --- the conditional connective.\nThis connective takes two propositions (a \\emph{condition} $P$ and a \\emph{consequence} $Q$) and produces a new proposition $P\\limplies Q$, which is read ``if $P$, then $Q$''.\nThe truth table associated to the propositional form $p\\limplies q$  is the following:\n\\begin{center}\n\\begin{tabular}[]{|c|c||c|}\n\\hline $p$ & $q$ & $p\\limplies q$ \\\\\n\\hline\\hline 0 & 0 & 1 \\\\\n\\hline 0 & 1 & 1 \\\\\n\\hline 1 & 0 & 0 \\\\\n\\hline 1 & 1 & 1 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nPlease, take your time to digest what this means. What we are saying is that $p\\limplies q$ is true if and only if ``if the condition $p$ is true, so is the consequence $q$''.\n\nIf the condition is false, we do not care about the consequence: $p\\limplies q$ is automatically true.\nBut if the condition is true, we need the consequence to be true in order for $p\\limplies q$ to be true.\n\\end{para}\n\n\n\\begin{example}\nIn a attempt to make things a little bit clearer, let us consider a simple example.\nBoth of us, at some point in our lives, have heard the phrase ``if you study hard, you will pass the exam''. According to the way in which we have defined the conditional operator, the truth table corresponding to all the possible scenarios is the following:\n\\begin{center}\n\\begin{tabular}[]{|c|c||c|}\n\\hline Study hard & Pass the exam & Study hard $\\limplies$ Pass the exam \\\\\n\\hline\\hline 0 & 0 & 1 \\\\\n\\hline 0 & 1 & 1 \\\\\n\\hline 1 & 0 & 0 \\\\\n\\hline 1 & 1 & 1 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nLet us then examine each case in detail. The first case should be easy: if I do not study hard and I do not pass the exam, is the phrase still true? Of course it is! I did not study hard for the exam, so there was no reason to believe I should have passed it.\n\nNow, what about the second case? If I do not study for the exam but I manage to pass it, is it true that if I study, I will pass the exam? Yes! It is still true. What the statement ``if you study, you will pass the exam'' tells us is that, provided I have studied, I will pass the exam, but if I did not study, the statement says nothing about what will happen. Nevertheless, the situation would have been different had the phrase been ``only if you study, will you pass the exam''. Can you spot the difference? How would you express this last statement in an ``if\\ldots then\\ldots'' form?\n\nThe third case is easy: if I studied but I did not pass the exam, the phrase is, obviously, false. The last statement is equally trivial: if I study hard and I pass the exam, the statement ``if you study hard, you will pass the exam'' is, clearly, true. \n\\end{example}\n\n\\begin{remark}\nThere is something very significant that, at this point, should be highlighted.\nThe fact that, for any particular propositions $P$ and $Q$, the statement ``if $P$, then $Q$'' is true does not imply in any way the existence of a cause-effect relation between $P$ and $Q$.\nConnectives, such as the conditional connective, combine statements to create new statements.\nThus, the real meaning of a sentence is meaningless (no pun intended); this is all about whether things are true or false.\nFor instance, the statement ``if zero equals one, the Earth is flat'' is perfectly valid and true (in fact, it is true regardless of your ``beliefs'' concerning the roundness of our planet!).\n\nNonetheless, it is true that conditional connectives have something to do with deductions.\nIf we know the propositions $P$ and $P\\limplies Q$ to be true, we can indeed deduce $Q$ to be true, but, as I mentioned earlier, this does not imply the existence of any cause-effect relation between $P$ and $Q$.\nLet us, for example, take $P$ to be the statement ``humans need water'' and $Q$ to be ``the sun is a star''.\nIs the statement $P\\limplies Q$ true? Sure it is!\nBoth $P$ and $Q$ are true, hence so must be $P\\limplies Q$.\nThen, from a purely formal point of view, we can deduce that ``the sun is a star'' from the fact that ``humans need water'' and ``if humans need water, then the sun is a star''.\nEverything we have done is completely meaningless, but, from the perspective of formal logic, it is correct.\nNotice, by the way, how logic did not allow us to do anything suspicious: if we were able to deduce that ``the sun is a star'' from ``humans need water'' it was because, in order to show that ``if humans need water, then the sun is a star'', we had to assume that ``the sun is a star'' in the first place.\n\n\\end{remark}\n\n\\begin{para}\nSome people like to extend the conventions in \\ref{hierarchy} to give the disjunction connective precedence over the conjunction connective, and the conjunction connective precedence over the conditional one.\nIn this way, $p\\limplies q \\land r \\lor s$ would be interpreted as $p\\limplies ((q \\land r) \\lor s)$.\nAlthough this conventions are widespread, we shall not use them in this book.\n\\end{para}\n\n\\begin{para}[Biconditional connective]\nBy this point, you should have noticed a crucial fact: the conditional connective, unlike the other ones we have studied, is not symmetric, which is to say that he truth value of $p\\limplies q$ says nothing about that of its \\emph{converse} $q\\limplies p$.\nTrust me, this is a crucial bit.\n\nThis very asymmetry leads to the definition of the symmetric \\emph{biconditional} connective, which, when applied on some variables $p$ and $q$, yields a propositional form $p\\liff q$ that is defined to take the same truth value as $(p\\limplies q)\\land(q\\limplies p)$ for the same assignments on the propositional variables $p$ and $q$.\n\\end{para}\n\n\\begin{para}[Implication and equivalence]\nIf, for any propositional forms $p$ and $q$, $p\\limplies q$ is a tautology, it is said that $p$ \\emph{implies} $q$; if, in addition, so is $q\\limplies p$ (and, therefore, $p\\liff q$), then $p$ and $q$ are said \\emph{equivalent}.\nThe important thing here is that, if $p$ implies $q$, $q$ is true whenever $p$ is. Consequently, if $p$ and $q$ are equivalent, $p$ is true if $q$ is true and $q$ is true if $p$ is true.\nIt is then needless to say that, when two propositional forms are equivalent, their truth tables are identical.\n\nJust to have some examples, the propositional form $p\\land (p\\limplies q)$ implies $q$, and the propositional form $\\lnot(p\\land q)$ is equivalent to $\\lnot p \\lor \\lnot q$.\n\\end{para}\n\n\\begin{para}\nAt this point, our language has gotten a little bit confusing, so let us introduce some new expressions to make it simpler. We already know that ``if $p$ then $q$'' stands for $p\\limplies q$. Nevertheless, based on what we know, $p\\limplies q$ could also be read ``$p$ only if $q$''. Take some time to think about this.\nThen, if we want to say ``if $p$ then $q$ \\und{and} if $q$ then $p$'', we could say ``only if $q$ then $p$ \\und{and} if $q$ then $p$'' or, in other words, ``$p$ if and only if $q$''. There you have it! Saying that $p\\liff q$ is the same as saying ``$p$ if and only if $q$''.\n\nJust to finish with all this language overload, let me give you one more definition. If $p\\limplies q$ is true, then $q$ is said to be a necessary condition for $p$ because, according to what we know, for $p\\limplies q$ to hold, $p$ cannot be true if $q$ is false. Analogously, $p$ is said to be a sufficient condition for $q$ because if $p$ is true, taking into account that $p\\limplies q$ is true, we know, for sure, that $q$ is true too.\nThus, another fancy way of saying that $p\\liff q$ is stating that ``$p$ is a necessary and sufficient condition for $q$'' or vice-versa. \n\\end{para}\n\n\\begin{para}\nTruth tables are not only used to describe the behaviour of logical connectives in propositional logic; they can also be used to define them. So much so that --- as you probably had concluded on your own by now --- there exists a perfect correspondence between truth tables and connectives.\nThe reasons for this are obvious: every connective has its own truth table, every truth table can be used to define a connective, and any two connectives with the same truth table are equivalent.\n\nAnother way of introducing new connectives is defining them to be equivalent to some combination of known connectives.\nThe way in which we defined the biconditional connective is a good example.\nThe problem with this method is that, unlike with truth tables, we do not have a ``correspondence'' guaranteeing us that any connective can be expressed as a combination of others. Well, we did not have one\\ldots until now.\n\\end{para}\n\n\\begin{theorem}\n\\label{ads1}\nAny propositional form $p$ involving $n$ propositional variables $p_1,\\ldots,p_n$ is equivalent to a propositional form $q$ involving only those variables and the connectives $\\land$, $\\lor$ and $\\lnot$.\n\nIn particular, this shows that, given any $n$-ary connective $*$, the propositional form $p$ resulting from its application on $n$ distinct propositional variables can be written, equivalently, as a propositional form involving only the connectives $\\lor$, $\\land$ and $\\lnot$, which is to say that $*$ can be defined in terms of $\\land$, $\\lor$ and $\\lnot$.\n\\end{theorem}\n\n\\begin{proof}\nThe way we will prove this is by providing an effective algorithm for constructing the equivalent propositional form $q$ from the truth table of the propositional form $p$.\nIf $p$ is a contradiction, it suffices to take $q$ to be any contradiction such as $(p_1\\land \\lnot p_1) \\lor \\cdots \\lor (p_n \\land \\lnot p_n)$.\nIf, on the other hand, there exists at least a particular assignment of truth values to $p_1,\\ldots,p_n$ which makes $p$ true, we list all such assignments (mark them), and proceed as follows:\n\\begin{enumerate}\n\\item Set $q$ to be an empty propositional form.\n\\item \\label{stepcontinuepropalg} Find one marked assignment of truth values. Let $p_{i_1},\\ldots,p_{i_r}$ with $\\{i_1,\\ldots,i_r\\}\\subseteq \\{1,\\ldots,n\\}$ be all the elements that should be set to $1$ in this particular assignment and, analogously, let $p_{j_1},\\ldots,p_{j_s}$ with $\\{j_1,\\ldots,j_s\\}\\subseteq \\{1,\\ldots,n\\}$ be all the elements that, in this assignment, need to be set to $0$.\n\\item If $q$ is not the empty propositional form, set it to\n\\[(q) \\lor (p_{i_1} \\land \\cdots \\land  p_{i_r} \\land \\lnot p_{j_1} \\land \\cdots \\land \\lnot p_{j_s}).\\]\nOtherwise, if $q$ is empty, set it to\\\n\\[p_{i_1} \\land \\cdots \\land  p_{i_r} \\land \\lnot p_{j_1} \\land \\cdots \\land \\lnot p_{j_s}.\\]\n\\item Unmark the assignment we have been considering. If there are no marked assignments left, $p$ is already equivalent to $q$, so we have finished. Otherwise, go back to step \\ref{stepcontinuepropalg}.\n\\end{enumerate}\n\nThe reasoning we have followed is by all means valid and, with some thought on your part, should have already convinced you that what the result is true. Nevertheless, as we dive deeper into the world of mathematics, you will see that this same argument can be written in a much more elegant and clear manner. \n\\end{proof}\n\n\\begin{definition}\nAn \\emph{adequate set of connectives} is a collection of connectives such that, for any propositional form involving a certain number of propositional variables, there exists an equivalent propositional form involving only those variables and the connectives in that set.\n\nFor example, $\\{\\land,\\lor,\\lnot\\}$ is an adequate set of connectives.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{corollary}\nThe set $\\{\\lnot,\\limplies\\}$ is an adequate set of connectives.\n\\label{adequateni}\n\\end{corollary}\n\n\\begin{proof}\nSince, according to \\ref{ads1}, $\\{\\land,\\lor,\\lnot\\}$ is an adequate set of connectives, it suffices to show that, given any propositional variables $p$ and $q$, each of $p\\land q$ and $p\\lor q$ is equivalent to a propositional form that only uses the negation and implication connectives.\n\nIt is easy to see that $p\\land q$ is equivalent to $\\lnot(A\\limplies(\\lnot B))$ and that $p\\lor q$ is equivalent to $(\\lnot A)\\limplies B$.\n\\end{proof}\n\n", "meta": {"hexsha": "8ed3df2baba43e82a635562384cf254973ad7592", "size": 18470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch0/sec2.tex", "max_stars_repo_name": "gonzalezcastillo/leavingthecave", "max_stars_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ch0/sec2.tex", "max_issues_repo_name": "gonzalezcastillo/leavingthecave", "max_issues_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch0/sec2.tex", "max_forks_repo_name": "gonzalezcastillo/leavingthecave", "max_forks_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.9545454545, "max_line_length": 589, "alphanum_fraction": 0.7413643747, "num_tokens": 5020, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947140302197, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7915464338856123}}
{"text": "\n\\subsection{Overfitting}\n\nRole of lambda: high makes impact of more variables lower => high bias\n\nLow makes impacts of more variables strong => high variance\n\nCan trade off using cut off. only make positive if above \\(0.7\\)\n\nHow to use? difficult, as lambda within cost!\n\nCan do similarly to d:\n\nRun for a range of lambda (eg 0, 0.01, 0.02, 0.04, 0.08:~10), then pick from cross validation set\n\nLow lambda always has low cost for training set, but not for cv set..\n\nRegularisation: add to error term the size of the term. penalised large parameters\n\nMay not fit outside sample\n\nHigh bias: eg house prices and size. linear would have high bias for out of scope sample (underfitting)\n\nHigh variance: making polynomial passing through all data (overfitting)\n\nCan reduce overfitting by reducing features either manaually or using models\n\nOR regularisation: keep all features, but reduce magnitude of theta\n\n\\subsection{Regularisation}\n\nMake cost function include size of \\(\\theta^2\\) values\n\n\\(\\min \\dfrac{1}{2m} [\\sum (h(x)-y)^2 + 1000 \\theta 3 ^2 + 1000 \\theta 4 ^2]\\)\n\nor more broadly:\n\n\\(\\min \\dfrac{1}{2m}[\\sum ..... + \\lambda \\sum \\theta j^2]\\)\n\nTend to not include theta 0 as convention, no regularisation\n\nUpdate for linear regression is\n\n\\(\\theta j = \\theta j -\\alpha{(\\dfrac{1}{m})* sum(h(x)-y)xj + (\\lambda/m \\theta j)}\\)\n\n\\(\\theta j = \\theta j (1- \\alpha \\lambda / m) -alpha {(1/m)*\\sum(h(x)-y)xj}\\)\n\nThis is the same as before, but theta \\(j\\) updates from a smaller \\(\\theta \\) \\(j\\) each time.\n\nNormal equation needs a change\n\n\\((X'X)^-1X'y=\\theta''\\)\n\nNow is\n\n\\((X'X+\\lambda I)^-1X y'\\)\n\nalthough for theta 0, lambda zero, so indentiy matrix, but first element 0\n\nREGULARISATION FOR REGULARISATION\n\nadd to end of \\(J(\\theta)\\):\n\n\\(\\dfrac{\\lambda }{2m} \\sum \\theta j^2\\)\n\nupdate for \\(\\theta \\)\\(j\\) \\(j>0\\):\nis a as linear regression, but \\(h(x)\\) is a different function\n\n", "meta": {"hexsha": "be0ab04c1c771bd8773e41050e667ab2833d1c76", "size": 1886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/choosing/02-01-overfitting.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/choosing/02-01-overfitting.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/choosing/02-01-overfitting.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.3333333333, "max_line_length": 103, "alphanum_fraction": 0.697242842, "num_tokens": 563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794594, "lm_q2_score": 0.8723473663814338, "lm_q1q2_score": 0.7914914333486651}}
{"text": "\\section{Swap Specifications}\n\nFor the treatment of swaps within analytics we define the following quantities:\n\n\\begin{itemize}\n\\item $t_1^{fix} \\ldots t_M^{fix}$ is the set of fixed payment times \n\\item $t_1^{flt} \\ldots t_N^{flt}$ is the set of floating payment times\n\\item  $F_i$ is the reference rate for the floating payment at $t_i^{flt}$\n\\item  $\\alpha^{fix}_i = \\alpha^{fix}(t_{i-1}^{fix},t_{i}^{fix})$ is the period (accrual fraction), according to the day count convention, between fixed payments $i-1$ and $i$\n\\item  $\\alpha^{flt}_i = \\alpha^{flt}(t_{i-1}^{flt},t_{i}^{flt})$ is the period (accrual fraction), according to the day count convention, between floating payments $i-1$ and $i$\n\\item  $\\alpha^{F}_i$ is the accrual fraction for reference rate  $F_i$\n\\item  $\\Delta^s_i$ is the difference between the start (effective or fixing) time of $F_i$ and $t^{flt}_{i-1}$\n\\item $\\Delta^e_i$ is the difference between the end (maturity) time of $F_i$ and $t^{flt}_{i}$\n\\item $p^{fund}(T)$ is the funding discount curve\n\\end{itemize}\n\nAll times are expressed in years (i.e 0.5 is half a year). $t_0^{flt}$ is taken as the effective (start) date of the swap (not a payment date), which is usually two days after the trade date.  In general, one would expect  the start date of some reference rate to be the same as the end date of the previous reference rate, i.e.  $\\Delta^s_{i+1}=\\Delta^e_{i}$ which are typically of order a few days. \n\nThe present value of the fixed leg is\n\n\\begin{equation}\nPV(\\text{fixed}) = \\sum^M_{i=1} k \\alpha^{fix}_ip^{fund}(t^{fix}_i)\n\\end{equation}\n\nwhere $k$ is the fixed rate. The PV of the floating leg is \n\n\\begin{equation}\nPV(\\text{float}) = \\sum^N_{i=1} F_i \\alpha^{flt}_ip^{fund}(t^{flt}_i)\n\\end{equation}\n\nThe PV of a payer swap (i.e. pay the fixed leg) is\n\\begin{equation}\n\\begin{split}\nPV(\\text{payer swap}) &= PV(\\text{float}) - PV(\\text{fixed}) \\\\\n&=  \\sum^N_{i=1} F_i \\alpha^{flt}_ip^{fund}(t^{flt}_i)-\\sum^M_{i=1} k \\alpha^{fix}_ip^{fund}(t^{fix}_i)\n\\end{split}\n\\end{equation}\n\nA par swap has a swap rate such that its PV is zero. With this condition, the par-swap rate is\n\\begin{equation}\n\\label{eqn:SwapRate}\nk = \\frac{\\sum^N_{i=1} F_i \\alpha^{flt}_ip^{fund}(t^{flt}_i)}{ \\sum^M_{i=1} \\alpha^{fix}_ip^{fund}(t^{fix}_i)}\n\\end{equation}\n\n\\subsection{Libor Reference Rate}\n\nWe consider the (usual) case where the reference rate is Libor (with some tenor).  To keep things completely general, we assume that funding is not at Libor, and we define  $p^{libor}(T)$ as the Libor discount curve. The (forward) Libor reference rates can be expressed in terms of the discount factors as\n\n\\begin{equation}\n\\label{eqn:FowardRate}\nF_i = \\frac{1}{\\alpha^{F}_i }\\left(\\frac{p^{libor}(t^{flt}_{i-1}+\\Delta^s_i)} {p^{libor}(t^{flt}_i+\\Delta^e_i)} -1\\right)\n\\end{equation}\n\nwith the expression for the par-swap rate becoming\n\n\\begin{equation}\n\\label{eqn:ParSwapRate}\nk = \\frac{\\sum^N_{i=1}  \\frac{\\alpha^{flt}_i}{\\alpha^{F}_i} \\left(\\frac{p^{libor}(t^{flt}_{i-1}+\\Delta^s_i)} {p^{libor}(t^{flt}_i+\\Delta^e_i)} -1\\right)p^{fund}(t^{flt}_i)}{ \\sum^M_{i=1} \\alpha^{fix}_ip^{fund}(t^{fix}_i)}\n\\end{equation}\n\nAlmost certainly we have $\\alpha^{flt}_i = \\alpha^{F}_i$, but it is left in the expression for maximum generality. In the case that all the $\\Delta$s are zero and the funding curve is Libor, equation  \\ref{eqn:SwapRate} collapses to the usual textbook form\n\n\\begin{equation}\nk = \\frac{p(t^{flt}_0)-p(t^{flt}_N)}{ \\sum^M_{i=1} \\alpha^{fix}_ip(t^{fix}_i)}\n\\end{equation}\n\nIn both cases the swap rate is a function of the discount factors (possibly from multiple curves) at fixed times.\n\n\n\\section{Swap Rate Sensitivities}\n\\label{Sec:SwapRateSense}\nLet the fixed leg annuity be $A$ (i.e. $PV(fixed)$ with $k=1$) and $PV(float)=B$, then\n\n\\begin{equation}\n\\label{eqn:SwaprateSense}\n\\frac{\\partial k}{\\partial p^x(t)}=\\frac{1}{A}\\frac{\\partial B}{\\partial p^x(t)} - \\frac{B}{A^2}\\frac{\\partial A}{\\partial p^x(t)} \n\\end{equation}\n\nwhere the superscript $x$ indicates with respect to which curve we are taking the derivative. The fixed leg part is\n\n\\begin{equation}\n\\frac{\\partial A}{\\partial p^{x}(t)}=\n\\begin{cases}\n\\alpha^{fix}_k \\mathbf{1}(t^{fix}_k-t)& \\text{if $x$ is the funding curve},\\\\\n0 \\quad \\forall t & \\text{if $x$ is any other curve}\n\\end{cases}\n\\end{equation}\n\nwhere $\\mathbf{1}(x)$ is the indicator function which equals 1 if  $x=0$ and is 0 otherwise. The most general form of the floating leg is \n\n\\begin{equation}\n\\label{eqn:FloatSense}\n\\frac{\\partial B}{\\partial p^{x}(t)}=\n\\begin{cases}\n\\alpha^{flt}_k F_k\\mathbf{1}(t^{flt}_k-t)& \\text{if $x$ is the funding curve},\\\\\n\\sum^N_{i=1} \\frac{\\partial F_i}{\\partial p^{x}(t)} \\alpha^{flt}_ip^{fund}(t^{flt}_i) \\quad \\forall t & \\text{if $x$ is any other curve}\n\\end{cases}\n\\end{equation}\n\nIf the reference rate is linked to the funding curve (e.g. the reference is Libor and funding is at Libor) then both terms in the above equation must be considered. Returning to the case of a Libor reference rate, we have\n\n\\begin{equation}\n\\label{eqn:ForwardRateSense}\n\\begin{split}\n\\frac{\\partial F_i}{\\partial p(t)} &= \\frac{1}{\\alpha^{F}_i }\\frac{\\partial}{\\partial p(t)} \\left[ \\frac{p(t^{flt}_{i-1}+\\Delta^s_i)} {p(t^{flt}_i+\\Delta^e_i)} -1\\right]\\\\\n&=\\frac{\\mathbf{1}(t^{flt}_{i-1}+\\Delta^s_i-t)} {p(t^{flt}_i+\\Delta^e_i)} - \\frac{p(t^{flt}_{i-1}+\\Delta^s_i)\\mathbf{1}(t^{flt}_{i}+\\Delta^e_i-t)} {\\left(p(t^{flt}_i+\\Delta^e_i)\\right)^2}\n\\end{split}\n\\end{equation}\n\nwith $p(t)$ understood to be the discount factors for the Libor curve.  Putting this together with equation \\ref{eqn:FloatSense} we finally have \n\n\\begin{equation}\n\\label{eqn:FloatLegSense}\n\\frac{\\partial B}{\\partial p^{libor}(t)}=\n\\begin{cases}\n \\frac{\\alpha^{flt}_k}{\\alpha^{F}_k }\\frac{p^{fund}(t^{flt}_{k})} {p^{libor}(t^{flt}_k+\\Delta^e_k)}& \\text{for } t=t^{flt}_{k-1}+\\Delta^s_k,\\\\\n -\\frac{\\alpha^{flt}_k}{\\alpha^{F}_k }p^{fund}(t^{flt}_{k})\\frac{p^{libor}(t^{flt}_{k-1}+\\Delta^s_k)} {\\left(p^{libor}(t^{flt}_k+\\Delta^e_k)\\right)^2}& \\text{for } t=t^{flt}_{k}+\\Delta^e_k,\\\\\n 0 & \\text{for $t$ taking any other value}\n \\end{cases}\n\\end{equation}\n\nIt is clear from equation  \\ref{eqn:SwapRate} that the swap rate only depends on the values of discount factors (possibly from multiple curves) at a set of predefined times - the values of the curve away from these times are irrelevant (hence the indicator function popping up in the sensitivities). \n\n\\subsection{Present Value Sensitivity}\nUsing the same notation as above, the PV of a payer swap is\n%\n\\begin{equation}\nPV(\\text{payer}) = B-kA\n\\end{equation}\n%\nso\n%\n\\begin{equation}\n\\frac{\\partial PV}{\\partial p^{x}(t)}= \\frac{\\partial B}{\\partial p^{x}(t)}-k\\frac{\\partial A}{\\partial p^{x}(t)}\n\\end{equation}\nwith the sensitivities of the two legs being the same as above. \n\n\n\n\\section{Implying Yield Cuves}\nA discount curve is a monotonically decreasing function,\\footnote{providing the instantaneous forward rates never become negative} so does not provide much visual information nor  the best metric for interpolation. We work with yield curves, with the yield to time $t$ defined as $r^x(t)=-\\frac{1}{t}\\ln\\left(p^x(t)\\right)$. Clearly, our sensitivity to a point on yield curve $x$ is\n%\n\\begin{equation}\n\\frac{\\partial \\theta}{\\partial r^{x}(t)} = -tp^x(t)\\frac{\\partial \\theta}{\\partial p^{x}(t)}\n\\end{equation}\n%\nwhere $\\theta$ is any curve sensitive quantity (e.g. par swap rate, present value etc). \n\nGiven a yield curve (or set of curves), one can find the swap rates for any number of swaps\\footnote{with payments out to the last defined time on the curve}  using equation \\ref{eqn:SwapRate}.  We are interested in the inverse problem of finding yield curve(s) given a set of market swap rates for reference par swaps. For some list of swaps, adding an additional swap will add (many) more than one point to the list of required times for which a discount factor is needed. For this reason we must interpolate the yield curve through a set of nodes, and it is these nodes that we aim to find. \n\nIf we have $N$ swaps then we can in principle find a curve with $N$ nodes (or multiple curves with a total of $N$ nodes) that exactly recovers all the swap rates - this is an $N$-dimensional root finding problem.\\footnote{for less than $N$ nodes, this can be formulated as a optimisation  problem where one tries to minimise the sum of squares between the market swap rates and those from the candidate curve.}  Alternatively we can find the curve that gives a zero PV to all our swaps - of course this will give exactly the same answer, and has the advantages of allowing more general instruments in the curve construction (not everything has a rate associated with it) and producing a more useful Jacobian (see below).\n\n\n\\subsection{The Jacobian}\n\nThe standard method of inverting the vector equation $\\mathbf{y} = f(\\mathbf{x})$,  when  $\\mathbf{x}$ and  $\\mathbf{y}$ are the same length, is a Newton-Raphson approach which iterates from some initial guess $\\mathbf{x}_0$ using\n\\begin{equation*}\n\\mathbf{x}_{i+1} = \\mathbf{x}_i - \\mathbf{J}^{-1}(f(\\mathbf{x})-\\mathbf{y} )\n\\end{equation*}\nuntil $\\mathbf{x}_{i+1} - \\mathbf{x}_i= \\mathbf{0}$ or equivalently $f(\\mathbf{x}_i)-\\mathbf{y} =\\mathbf{0}$. The Jacobian, $\\mathbf{J}$ is\n\n\\begin{equation*}\n\\mathbf{J} = \\left(  \n\\begin{array}{cccc}\n\\frac{\\partial y_{1}}{\\partial x_1} & \\frac{\\partial y_1}{\\partial x_2} & \\ldots & \\frac{\\partial y_1}{\\partial x_N}\\\\\n\\frac{\\partial y_2}{\\partial x_1}&\\frac{\\partial y_2}{\\partial x_2} &\\ldots&\\frac{\\partial y_2}{\\partial x_N}\\\\\n\\vdots&\\ddots&\\ddots&\\vdots\\\\\n\\frac{\\partial y_N}{\\partial x_1}&\\ldots&\\ldots&\\frac{\\partial y_N}{\\partial x_N}\n\\end{array}\n\\right)\n\\end{equation*}\n\nAdditional heuristics are added to Newton-Raphson to improve stability  and the Broyden method can be used to update the Jacobian rather than recalculate it at every step\\footnote{alternatively, one could use Sherman-Morrison to update the inverse Jacobian directly}.\n\nFor a set of $N$ swaps, the Jacobian for a single curve is arranged as above, with some instrument value (par swap rates, PV etc) taking the place of the $y$s and the yields taking the place of the $x$s.  For two curves, e.g.  libor and funding, we arrange the Jacobian as follows \n%\n\\begin{equation}\n\\mathbf{J} = \\left(  \n\\begin{array}{cccccc}\n\\frac{\\partial \\theta_{1}}{\\partial r^{libor}_1} & \\ldots & \\frac{\\partial  \\theta_1}{\\partial r^{libor}_j} &  \\frac{\\partial  \\theta_1}{\\partial r^{fund}_1} &\\ldots & \\frac{\\partial  \\theta_1}{\\partial r^{fund}_{N-j}}\\\\\n\\frac{\\partial  \\theta_{2}}{\\partial r^{libor}_1} & \\ldots & \\frac{\\partial s_2}{\\partial r^{libor}_j} &  \\frac{\\partial  \\theta_2}{\\partial r^{fund}_1} &\\ldots & \\frac{\\partial  \\theta_2}{\\partial r^{fund}_{N-j}}\\\\\n\\vdots & \\ddots & \\vdots & \\vdots & \\ddots  &\\vdots\\\\\n\\frac{\\partial  \\theta_{N}}{\\partial r^{libor}_1} & \\ldots & \\frac{\\partial  \\theta_N}{\\partial r^{libor}_j} &  \\frac{\\partial  \\theta_N}{\\partial r^{fund}_1} &\\ldots & \\frac{\\partial  \\theta_N}{\\partial r^{fund}_{N-j}}\n\\end{array}\n\\right)\n\\end{equation}\n%\nwith $j$ nodes on the Libor curve and $N-j$ nodes on the funding curve.\\footnote{Clearly the vector $\\mathbf{x}$ has the $j$ nodes of the Libor curve as its first $j$ entries and the $N-j$ nodes of the funding curves as its remaining entries.} \n\nWhen $\\theta$ is a PV rather than a rate, the Jacobian provides direct hedging information - the PV01\\footnote{Strictly PV01 (present value of a basis point) is the change in PV with respect to a parallel move of the yield curve by one basis point. We have taken the derivative of PV with respect to a parallel shift of the yield curve scaled to one basis point.}  of instrument $i$ is just the sum of terms in the $i^{th}$ row (multiplied by one-thousandth). \n\n\\subsection{Interpolator Sensitivity}\n\nAs we have already mentioned, not all of the discount factors needed to calculate the swap rate can be nodes of the yield curve. This means we need to know the sensitivity of any point on the interpolated curve to the movement of the nodes. With this additional information we can form the analytical Jacobian.\\footnote{it is possible to obtain the Jacobian using central differencing, which is what we originally did - this requires $2N$ calls to $f(\\mathbf{x})$. }\n\n\nFor $N$ nodes $(x_1,y_1), (x_2,y_2),\\ldots,(x_N,y_N)$ many interpolators can be written in the form \n%\n\\begin{equation}\ny=\\sum^N_{i=1} a_i(x)y_i\n\\end{equation}\n%\nThe sensitivity of interest is \n\\begin{equation}\n\\frac{\\partial y}{\\partial y_k}=\\sum^N_{i=1}a_i(x)\\delta_{i,k} =a_k(x)\n\\end{equation}\n\nA local interpolator (e.g. linear) will only have sensitivity to the local nodes (i.e. the nodes $k$ and  $k+1$ for $x\\in(x_k,x_{k+1})$), while a global method, such as cubic spline, will have sensitivity to all the nodes - this is an important consideration for hedging. \nFor an instrument  which is sensitive to a set of yields at times $t_1,\\ldots,t_M$, the sensitivity to node $j$ is\n%\n\\begin{equation}\n\\frac{\\partial \\theta}{\\partial r_j}=\\sum_{i=1}^M \\frac{\\partial r(t_i)}{\\partial r_j}\\frac{\\partial  \\theta}{\\partial r(t_i)}\n\\end{equation}\n\nWe now have all the pieces in place to imply a yield curve(s) - the inputs are the market instruments (par swaps), the positioning of the yield curve nodes and the choice of interpolator. The output is the yields at those nodes, which (together with the choice of interpolator) will exactly recover the swap rates.  \n\nIn order to back out a single curve, the obvious choice of the node positions is at the last payment time of each of the swaps. If a linear interpolator is used, the Jacobian will be lower triangular, and the nodes could be found by bootstrapping - the value of the first node (yield) is chosen to give the correct swap rate for the first swap, with this fixed the second node is chosen to give the correct rate to the second swap, etc. We tested the system with a cubic spline, where every node to some extent has an effect on every swap rate. The system worked well both in an idealised test case\\footnote{We constructed a dummy curve, got swap rates off it for USD 6m, 1y, 2y, 3y, 5y, 7y, 10y, 15y, 20y, 25y \\& 30y, then used these rates to recover the curve} and using USD reference par-swap rates from Bloomberg.\n\nIt is also possible is recover two curves (funding and Libor) from the swap rates. The nodes cannot be placed at the last payment times of the swaps, but instead must be divided up between the two curves. The sensitivity of the swap rates to the funding curve only is small (that part of the Jacobian has much smaller values than the Libor part), and while for an idealised test case both curves can be recovered, there is no guarantee that a root even exists with market data. In practice, additional instruments are used (cash rates, FRAs, futures, basis swaps) to give the required sensitivity to various curves (and particular time periods on those curves). This is dealt with in the next section.\n\n\n\n\\section{Adding Additional Instruments}\n\n\\subsection{Forward Rate Agreements (FRA)}\n\nA FRA has three principle dates associated with it: the fixing date ($t_f$), when the reference Libor rate is observed, the maturity date of that Libor  ($t_m$) - e.g. three months after the fixing date, and the settlement date ($t_s$) when the net payment is made. Unlike swaps, where the payment is at or near maturity, the settlement date of a FRA is close to the fixing date (normally two days after it). \nThe actual payment is discounted from a hypothetical payment made at maturity by the observed forward rate.  \n\n\\begin{equation}\n\\text{payment at settlement} = \\frac{(L(t_f,t_m)-k)\\alpha}{1+\\tau L(t_f,t_m)}\n\\end{equation}\n%\nwhere the year fraction to calculate the payment ($\\alpha$) and that used to calculate the discount ($\\tau$) are not necessarily the same.  The PV of this instrument is given by\n\\begin{equation}\nPV = \\mathbb{E}^\\mathbb{P}\\left[e^{-\\int^{t_s}_0 r_t dt} \\frac{(L(t_f,t_m)-k)\\alpha}{1+\\tau L(t_f,t_m)}\\right]\n\\end{equation}\n%\nwhere $r_t$ is the funding rate. If funding is at Libor, we can change numeraire to the zero coupon bond maturing at $t_m$, and the expression becomes \n\\begin{equation}\n\\begin{split}\nPV &=p^{libor}(t_m) \\mathbb{E}^\\mathbb{T}\\left[(L(t_f,t_m)-k)\\alpha\\right] \\\\\n&= p^{libor}(t_{f}) -(1+\\alpha k) p^{libor}(t_m)\n\\end{split}\n\\end{equation}\n%\nsince \n\\begin{equation}\n\\mathbb{E}^\\mathbb{T}\\left[ L(t_f,t_m)\\right] = F(t_f,t_m)= \\frac{1}{\\alpha}\\left(\\frac{p^{libor}(t_{f})} {p^{libor}(t_m)} -1\\right)\n\\end{equation}\nwhich is also the strike, $k$, that makes the FRA fair (zero PV).  \n \n In the absence of a model for the joint dynamics of the forward and funding rates, we assume the PV to be given by\n \\begin{equation}\n \\label{eqn:FRA_PV}\nPV = p^{fund}(t_s)\\left(\\frac{(F(t_f,t_m)-k)\\alpha}{1+\\tau F(t_f,t_m)}\\right)\n\\end{equation}\n\n\nFor a fair FRA, the sensitivities of the strike purely to the Libor curve given by\n\n\\begin{equation}\n\\frac{\\partial k}{\\partial p^{libor}(t)}=\n\\begin{cases}\n \\frac{1}{\\alpha}\\frac{1} {p^{libor}(t_m)}& \\text{for } t=t_{f},\\\\\n - \\frac{1}{\\alpha }\\frac{p^{libor}(t_{f})} {\\left(p^{libor}(t_m)\\right)^2}& \\text{for } t=t_{m},\\\\\n 0 & \\text{for $t$ taking any other value}\n \\end{cases}\n\\end{equation}\n\nThe PV sensitivity for a Libor-funded FRA is \n\\begin{equation}\n\\frac{\\partial PV}{\\partial p^{libor}(t)}=\n\\begin{cases}\n 1& \\text{for } t=t_{f},\\\\\n  -(1+\\alpha k)  & \\text{for } t=t_{m},\\\\\n 0 & \\text{for $t$ taking any other value}\n \\end{cases}\n\\end{equation}\n%\nwhile for some other funding curve it is \n\\begin{equation}\n\\frac{\\partial PV}{\\partial p^{libor}(t)}=\\frac{\\alpha p^{fund}(t_s)}{1+\\tau F}\\left[ 1-\\frac{(F-k)\\tau}{1+\\tau F}  \\right] \\frac{\\partial F}{\\partial p^{libor}(t)}\n\\end{equation}\nwhere $\\frac{\\partial F}{\\partial p(t)}$ is given by equation \\ref{eqn:ForwardRateSense}.  Even though the funding curve cannot affect whether an instrument has zero PV (see equation \\ref{eqn:FRA_PV}), there is sensitivity to this curve, which is important for calculating the correct hedge ratio. \n\n\\subsection{Futures}\nFutures are traded based on price. The price implies a forward  rate given by $F = 1-\\frac{\\text{price}}{100}$, which is usually 3-month Libor with fixing date the third Wednesday of the contract month. The sensitivity of the implied rate can be treated the same as FRAs above  (i.e. we do not apply any convexity adjustment). \n\nNo money is paid upfront for a future. For a tenor of $\\alpha$, if the price rises by $\\Delta$ (implying a fall in the forward rate of $\\Delta/100$) , there is an immediate profit (paid into a margin account) of $N\\Delta \\alpha/100$ where $N$ is the notional of one contract.\\footnote{For Eurodollar futures  $\\alpha$ is 0.25 (i.e 90/360) and the notional is \\$1M so a 1bp fall in the forward rate gives a gain of \\$25. The minimum change of value (tick) is \\$12.50 or 0.5 bps}\nSo the PV can be written in terms of the current implied forward, $F(t_s,t_m)$, and the price of the future when  the contact was entered, $c$.\n%\n\\begin{equation}\nPV = \\alpha N\\left(1-F(t_s,t_m) -\\frac{c}{100}\\right)\n\\end{equation}\n%\nThen\n\\begin{equation}\n\\frac{\\partial PV}{\\partial p^{libor}(t)}=-\\alpha N\\frac{\\partial F}{\\partial p^{libor}(t)}\n\\end{equation}\n%\nwhere again $\\frac{\\partial F}{\\partial p(t)}$ is given by equation \\ref{eqn:ForwardRateSense}. So a future has the opposite sign of PV sensitivity to a FRA, and also no sensitivity to the funding curve due to mark-to-marketing. \n\n\n\\subsection{Spot Libor}\nToday's Libor (set at 11am) is available for a range of tenors (1 month, 2 months and 3 months being the most liquid). To be completely consistent when building a Libor curve, we should only use the tenor used in the swaps and FRAs (3 months for USD swaps and FRAs). In the OpenGamma system, spot Libor is treated as a FRA with fixing date and settlement date equal to the trade date, which is normally two days from now.\n\n\\subsection{Cash}\nShort term cash deposits (i.e. overnight O/N, 1W, 2W etc) which use simple interest can be treated as spot Libor above, but with sensitivity to the funding curve (assuming cash rates represent short term funding costs).  \n\n\\subsection{Floating Rate Notes (FRN)}\n\\label{sec:FRN}\nFRNs are bonds that pay a variable coupon based on a reference rate plus a spread. The notional is paid up front and returned at maturity. Using the same notation as for swaps, the present value (with unit notional)  is:\n%\n\\begin{equation}\nPV = - p^{fund}(t_0) + p^{fund}(t_N) +  \\sum^N_{i=1} (F_i+s) \\alpha_ip^{fund}(t_i)\n\\end{equation}\n%\nwhere  $t_0$ is the trade time (which may be zero) and $s$ is the spread. If funding is at Libor, with a zero spread the PV is zero - FRNs are always at par when funding at the reference rate.\\footnote{Strictly we  also need $\\Delta^s_i$ and  $\\Delta^e_i$ to be zero, and $\\alpha^{flt}_i=\\alpha^F_i$}\nTo trade at par for any other funding requires a spread of\n%\n\\begin{equation}\ns =  \\frac{p^{fund}(t_0) - p^{fund}(t_N)- \\sum^N_{i=1} F_i \\alpha_ip^{fund}(t_i) }{ \\sum^N_{i=1} \\alpha_ip^{fund}(t_i)}\n\\end{equation}\n%\nwhich will be negative if one can fund at less than Libor (e.g. by posting collateral). The sensitivity of this spread and the PV to the curves will follow through as for swaps. \n\n\\subsection{Basis Swaps}\n\nBasis swaps are float-for-float with each leg based on a different reference rate (interest-rate indices), with one leg typically paying a (fixed) spread.\n\n\\paragraph{Basis Swap in a Single Currency}\n\nA basis swap exchanges payments based on one index (e.g.Fed-Funds) for another (e.g. 3m-Libor) on the same notional amount. A tenor swap exchanges payments based on different Libor tenors, e.g. 3 month Libor paid quarterly for  6 month Libor paid semi-annually. \n\nIf legs of the swap ($a$ and $b$) have reference rates $F^a$ and $F^b$, the PV of the receiver of leg $a$ is \n\\begin{equation}\nPV = \\sum^M_{i=1} F^a_i \\alpha^{a}_ip^{fund}(t^{a}_i) -  \\sum^N_{i=1} (F^b_i+s) \\alpha^{b}_ip^{fund}(t^{b}_i)\n\\end{equation}\n %\nwhere $s$ is the spread, which can take positive or negative values. Making the PV zero, the spread becomes\n \n \\begin{equation}\ns = \\frac{\\sum^M_{i=1} F^a_i \\alpha^{a}_ip^{fund}(t^{a}_i)-\\sum^N_{i=1} F^b_i \\alpha^{b}_ip^{fund}(t^{b}_i)}{ \\sum^N_{i=1} \\alpha^{b}_ip^{fund}(t^{b}_i)}\n\\end{equation}\n\nIf both leg payments are at the same time, this reduces to\n%\n \\begin{equation}\ns = \\frac{\\sum^M_{i=1} (F^a_i-F^b_i) \\alpha_ip^{fund}(t_i)}{ \\sum^M_{i=1} \\alpha_ip^{fund}(t_i)}\n\\end{equation}\n%\nwhich is just equation \\ref{eqn:SwapRate} for the par swap rate, with $F_i = (F^a_i-F^b_i)$.  In the general case,  we again let the spread $s=B/A$ and proceed as in Section \\ref{Sec:SwapRateSense}.\n\n\\begin{align}\n\\frac{\\partial A}{\\partial p^{x}(t)}&=\n\\begin{cases}\n\\alpha^{b}_k \\mathbf{1}(t^{b}_k-t)& \\text{if $x$ is the funding curve},\\\\\n0 \\quad \\forall t & \\text{if $x$ is any other curve}\n\\end{cases}\\\\\n%\n\\frac{\\partial B}{\\partial p^{fund}(t)}&=\n\\begin{cases}\n\\alpha^{a}_k F^a_k& \\quad t=t^a_k,\\\\\n-\\alpha^{b}_k F^b_k& \\quad t=t^b_k,\\\\\n0& \\text{any other }t\n\\end{cases}\\\\\n%\n\\frac{\\partial B}{\\partial p^{x}(t)}&=\\sum^M_{i=1} \\frac{\\partial F^a_i}{\\partial p^{x}(t)} \\alpha^{a}_ip^{fund}(t^{a}_i) -\\sum^n_{i=1} \\frac{\\partial F^b_i}{\\partial p^{x}(t)} \\alpha^{b}_ip^{fund}(t^{b}_i) \n\\end{align}\n%\nIf  the reference rates are Libor (with different tenors) then terms like $\\frac{\\partial F^a_i}{\\partial p^{x}(t)}$  are given by equation \\ref{eqn:ForwardRateSense}. The PV sensitivity is similarly calculated. \n\n\\paragraph*{Example: Implying two curves - 3m Libor and Fed-Funds}  \nA general tenor swap will have sensitivity to three curves.\\footnote{funding and the two different tenor curves} To back out a Libor (e.g. 3m) and funding (e.g. Fed-Funds) curve, we could consider a set of $N$ collateralized swaps (so funding is at Fed-Funds), and a set of $M$ collateralized  Fed-Funds vs 3m Libor tenor swaps (again funding at Fed-Funds) - the swaps are mostly sensitive to the Libor curve, so the $N$ nodes on this curve should be at the swap maturities, while the FRNs are mainly sensitive to the spread between the Libor and Fed-fund curve, in which case the $M$ nodes of the fund curve should be at the maturity of the FRNs. This treats both curves on an equal footing. An alternative is to have a primary Libor curve and a spread curve (funding is Libor - spread) - the Libor curve could use more than $N$ nodes, with the remaining going to the spread curve.\\footnote{The point is that the two curves will most likely have very similar macro features that you want to capture with as many nodes as possible, while the spread could be a very simple thing represented by only a few nodes (or one for a constant spread).  The funding curve could equally take the role of the primary curve.}\n\n\\paragraph{Cross Currency Swaps (CCS)}\nA CCS is effectively an exchange of a domestic FRN on a notional of $N$ for a foreign FRN on a notional of $Nx(0)$ where $x(0)$ is the spot forex rate (units of foreign currency for 1 domestic). If both legs have spreads set up as in section \\ref{sec:FRN}, then they will both PV to zero and can be treated as separate FRNs (one being sensitive to domestic funding and a domestic index curve, and the other being sensitive to foreign funding and a foreign index curve).\n\nIn reality, a single spread is paid on one of the legs, which renders the whole contract fair. In general neither leg is separately PV zero. Of course, if the funding and index curve are the same for one leg, we can treat the other leg as a FRA provided it is the one that the spread is paid on.\n\nLet $p^d(t)$ and $p^f(t)$ be domestic and foreign discount factors for the respective funding curves and $F^d_i$ and $F^f_i$ be the domestic and foreign index rates which are paid at times $t^d_1\\ldots t^d_{N^d}$ and  $t^f_1\\ldots t^f_{N^f}$. The PV on the domestic side (i.e. paying the domestic index rate plus spread and receiving the foreign) for unit notional is:\n%\n\\begin{equation}\n\\begin{split}\nPV =  \\frac{x(t_0)}{x(0)}\\left[-p^f(t_0) + p^f(t^f_{N^f}) +\\sum^{N^f}_{i=1} F^f_i \\alpha^{f}_ip^{f}(t^{f}_i)\\right]\\\\\n-\\left[-p^d(t_0) + p^d(t^d_{N^d}) +\\sum^{N^d}_{i=1}( F^d_i+s) \\alpha^{d}_ip^{d}(t^{d}_i)\\right]\n\\end{split}\n\\end{equation}\n%\nThe term $\\frac{x(t_0)}{x(0)}$ arrises from exchanging notional amounts on the trade date $t_0$ (normally two days) and converting the foreign cash flow back to domestic now. The spread that makes this fair is\n%\n\\begin{equation}\ns =  \\frac{\\frac{x(t_0)}{x(0)}\\left[-p^f(t_0) + p^f(t^f_{N^f}) +\\sum^{N^f}_{i=1} F^f_i \\alpha^{f}_ip^{f}(t^{f}_i)\\right]+p^d(t_0) -p^d(t^d_{N^d}) -\\sum^{N^d}_{i=1}F^d_i \\alpha^{d}_ip^{d}(t^{d}_i)}\n{\\sum^{N^d}_{i=1}\\alpha^{d}_ip^{d}(t^{d}_i)}\n\\end{equation}\n%\nThe PV (and equivalently the spread) is sensitive to (up to) four curves\\footnote{the funding in both currencies, and the Libors in both currencies} - these sensitivities (and that for the spread) can be calculated in the same manner as the previous sections. \n\n\\paragraph*{Disscusion}\nThe tenors used in CCS do not necessarily match those of interest rate swaps (IRS), so one could easily be in a situation of needing strips of foreign and domestic IRSs (plus other instruments to take care of the short end of the curve), strips of overnight rates versus Libor basis swaps, Libor tenor swaps, and CCSs. In this situation one would most likely want base curves of the foreign and domestic funding rates, then all other curves implemented as spreads over these curves.\n\n\\section{Hedging}\nLet $x_1\\ldots x_N$ be the PV of the instruments\\footnote{we will use $x_i$ to refer to both an instrument and its price} used to build the curve(s), and  $r_1\\ldots r_N$ be the yields at the node points on the curve(s)\\footnote{the distinction between one and many curves is not relevant here, so we will just talk above the yields $r_i$ which could refer to one or many curves}. The Jacobian is\n\\begin{equation}\n\\mathbf{J} = \\left(  \n\\begin{array}{ccc}\n\\frac{\\partial x_{1}}{\\partial r_1} & \\ldots & \\frac{\\partial x_1}{\\partial r_N}\\\\\n\\vdots&\\ddots&\\vdots\\\\\n\\frac{\\partial x_N}{\\partial r_1}&\\ldots&\\frac{\\partial x_N}{\\partial r_N}\n\\end{array}\n\\right)\n\\end{equation}\n%\nThe sensitivity of the instruments to a parallel movement in the curve is given by summing each row. Mathematically this is \n\\[\n\\frac{\\partial \\mathbf{x}}{\\partial r}|_{\\text{parallel move}} = \\mathbf{J}\\mathbf{1} \\quad \\text{where} \\quad \\mathbf{1} = \\left(  \n\\begin{array}{c}\n1\\\\\n\\vdots\\\\\n1\n\\end{array}\n\\right)\n\\]\nSensitivities to other deformations of the curve can be found by replacing the vector $\\mathbf{1}$ with one describing the appropriate deformation (e.g. steepening of the curve).\n\\subsection{Delta Hedging a Curve Sensitive Instrument}\nLet $y$ be some other instrument whose price depends purely on the curve we have implied from the $N$ instruments $x_i$ above. A portfolio can be formed thus:\n%\n\\begin{equation}\n\\Pi = y-\\sum^N_{i=1}w_ix_i\n\\end{equation}\n%\nwhere the weights $w_i$ are the amounts held of $x_i$ (hold one unit of $y$). To be insensitive to any small movement of the curve requires \n%\n\\begin{equation}\n\\frac{\\partial \\Pi}{\\partial r_k}=0 \\quad \\Rightarrow \\quad  \\frac{\\partial y}{\\partial r_k} =\\sum^N_{i=0}w_i\\frac{\\partial x_i}{\\partial r_k} \\quad \\forall k\n\\end{equation}\n%\nWriting the weights $w_i$ and the curve sensitivity of $y$\\footnote{The quantities $ \\frac{\\partial y}{\\partial r_k}$ are calculated by the system exactly as the entries in the Jacobian are} in  vector form \n\\begin{equation}\n\\mathbf{w} = \\left(  \n\\begin{array}{c}\nw_1\\\\\n\\vdots\\\\\nw_N\n\\end{array}\n\\right)\n\\quad\n\\mathbf{y}' = \\left(  \n\\begin{array}{c}\n\\frac{\\partial y}{\\partial r_1 }\\\\\n\\vdots\\\\\n\\frac{\\partial y}{\\partial r_N}\n\\end{array}\n\\right)\n\\end{equation}\n%\ngives \n\\begin{equation}\n\\mathbf{y}'=\\mathbf{J}^T\\mathbf{w} \\quad \\Rightarrow \\quad \\mathbf{w} =\\left( \\mathbf{J}^{-1}\\right)^T\\mathbf{y}'\n\\end{equation}\n%\nIn general every entry in $\\mathbf{w}$ will have a non-zero value, implying some position will need to be taken in every instrument. Furthermore there is no guarantee that the weights will not contain large positive and negative values\\footnote{this is often seen in mean-variance portfolio optimisation, where mathematically the equation for the weights is the same}, making the hedge extremely sensitive to non-negligible movements of the curve (i.e large gamma).\nIn practice one wants to pick a few hedging instrument that are sensitive to the curve and match the properties of $y$ (e.g. similar maturity, etc). Let the M instruments be $h_1\\ldots h_M$, and again form a portfolio \n%\n\\begin{equation}\n\\Pi = y-\\sum^M_{i=1}w_ih_i\n\\end{equation}\n%\nWith $M<N$ it is not possible to meet the condition $\\frac{\\partial \\Pi}{\\partial r_k}=0$ for all $k$. We define the sensitivity matrix $\\mathbf{H}$ and the vector of small movements of the yields, $\\mathbf{\\Delta r}$ as\n\\begin{equation}\n\\mathbf{H} = \\left(  \n\\begin{array}{ccc}\n\\frac{\\partial h_{1}}{\\partial r_1} & \\ldots & \\frac{\\partial h_1}{\\partial r_N}\\\\\n\\vdots&\\ddots&\\vdots\\\\\n\\frac{\\partial h_M}{\\partial r_1}&\\ldots&\\frac{\\partial h_M}{\\partial r_N}\n\\end{array}\n\\right)\n\\quad\n\\mathbf{\\Delta r} = \\left(  \n\\begin{array}{c}\n\\Delta r_1\\\\\n\\vdots\\\\\n\\Delta r_N\n\\end{array}\n\\right)\n\\end{equation}\n%\nso a small change in the value of the portfolio can be written as\n\\begin{equation}\n\\Delta \\Pi \\approx - \\mathbf{\\Delta r} \\cdot (\\mathbf{H}^T\\mathbf{w}-\\mathbf{y}')\n\\end{equation}\nThis is a random variable, which depends on the random vector $\\mathbf{\\Delta r}$. To keep things tractable we aim to minimise the expectation of the square of this value:\n\\begin{equation}\n\\begin{split}\n\\mathbb{E}[\\Delta \\Pi^2] = (\\mathbf{H}^T\\mathbf{w}-\\mathbf{y}')^T \\mathbf{\\Theta} (\\mathbf{H}^T\\mathbf{w}-\\mathbf{y}')\\\\\n\\text{where}  \\quad\\mathbf{\\Theta}  = \\mathbb{E}[ \\mathbf{\\Delta r} \\mathbf{\\Delta r}^T]\n\\end{split}\n\\end{equation}\nSo $\\mathbf{\\Theta}$ should be available from time series data of the changes in the yields - if $\\mathbb{E}[\\Delta \\Pi]=0$ (i.e. there is no drift), then $\\mathbf{\\Theta}$ is the covariance matrix of changes in yields. Differentiating with respect to the weights we have\n %\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial \\mathbb{E}[\\Delta \\Pi^2]}{\\partial \\mathbf{w}} = \\mathbf{0} \\Rightarrow\\\\\n \\mathbf{H}^T\\mathbf{\\Theta} \\mathbf{H} \\mathbf{w}= \\mathbf{H}^T\\mathbf{\\Theta}\\mathbf{y}' \\Rightarrow\\\\\n \\mathbf{w}=( \\mathbf{H}^T\\mathbf{\\Theta} \\mathbf{H} )^{-1} \\mathbf{H}^T\\mathbf{\\Theta}\\mathbf{y}' \n\\end{split}\n\\end{equation}\nThis will in general give a more robust hedge to movements of the curve.\n\n\\section{Conclusion}\nAny interest rate product with price sensitivity to a set (possibly only one) of yield curves only, can be used to imply these curves provided one can write down a function from yield curves to price.  If when attempting to imply several curves, there are no instruments that are sensitive to all the curves, then the problem decouples and the different curves can be found separately.\n\n", "meta": {"hexsha": "91ab253215e34180946a1c8c8c45c13218421d2f", "size": 32976, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/docs-static/og_docs_yield_curve_maths.tex", "max_stars_repo_name": "Incapture/OG-Platform", "max_stars_repo_head_hexsha": "76be42671e692483125582d6dce1245b81de03a1", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-22T06:50:21.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-22T06:50:21.000Z", "max_issues_repo_path": "docs/docs-static/og_docs_yield_curve_maths.tex", "max_issues_repo_name": "antikas/OG-Platform", "max_issues_repo_head_hexsha": "aa683c63e58d33e34cca691290370d71a454077c", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/docs-static/og_docs_yield_curve_maths.tex", "max_forks_repo_name": "antikas/OG-Platform", "max_forks_repo_head_hexsha": "aa683c63e58d33e34cca691290370d71a454077c", "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.1556420233, "max_line_length": 1211, "alphanum_fraction": 0.7174308588, "num_tokens": 10372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.9019206659843131, "lm_q1q2_score": 0.7914144398819039}}
{"text": "\n\\subsection{The exterior (wedge) product}\n\nThe exterior product of two vectors is:\n\n\\(u\\land v\\)\n\n\\subsection{The exterior product is anticommutative}\n\nThis is anticommutative (alternating).\n\n\\(u\\land v=-v\\land u\\)\n\nThis implies that:\n\n\\(u\\land u=0\\)\n\n\\subsection{The exterior product is distributive}\n\n\\((a+b)\\land (c+d)=(a\\land c)+(a\\land d)+(b\\land c)+(b\\land d)\\)\n\n\\subsection{Expanding the exterior product of two vectors}\n\nWe can look at the exterior product in component-basis terms.\n\nConsider \\(2\\)-dimenional vector space with the following vectors:\n\n\\(u=ae_1+be_2\\)\n\n\\(v=ce_1+de_2\\)\n\nThe exterior product is:\n\n\\(u\\land v=(ae_1+be_2)\\land (ce_1+de_2)\\)\n\n\\(u\\land v=(ae_1\\land ce_1)+(ae_1\\land de_2)+(be_2\\land ce_1)+(be_2\\land de_2)\\)\n\n\\(u\\land v=ac(e_1\\land e_1)+ad(e_1\\land e_2)+bc(e_2\\land e_1)+bd(e_2\\land e_2)\\)\n\n\\(u\\land v=ad(e_1\\land e_2)-bc(e_1\\land e_2)\\)\n\n\\(u\\land v=(ad-bc)(e_1\\land e_2)\\)\n\n", "meta": {"hexsha": "d45497f6fe939e65f6995a695b1ca381094ba762", "size": 912, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/exteriorAlgebra/01-01-wedge.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/exteriorAlgebra/01-01-wedge.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/exteriorAlgebra/01-01-wedge.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.7272727273, "max_line_length": 80, "alphanum_fraction": 0.6907894737, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778000158575, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7913928413445437}}
{"text": "\n\\subsection{Von Neumann-Morgenstern utility theorem}\n\nWe can model any risk preference as:\n\n\\(U[L]=\\sum_i p_iu(x_i)\\)\n\nIf the agent is risk neutral we can use:\n\n\\(u(x_i)=x_i\\)\n\nIf the agent is risk averse:\n\n\\(u(x_i)=\\ln x_i\\)\n\nIf the agent is risk loving we can use:\n\n\\(u(x_i)=x_i^2\\)\n\n", "meta": {"hexsha": "12cded74b9e4fefa47c3394de90e3ae1a9de8c14", "size": 287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/uncertainty/01-02-neumann.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/uncertainty/01-02-neumann.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/uncertainty/01-02-neumann.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.35, "max_line_length": 52, "alphanum_fraction": 0.6794425087, "num_tokens": 96, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474246069458, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7913442944865005}}
{"text": "\\section{Fields}\n\\label{sec:fields}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Solve systems of equations using scalars from a field other\n    than the real numbers, such as $\\Z_2$ or $\\Z_5$.\n  \\end{enumerate}\n\\end{outcome}\n\nSo far in this chapter, we have worked with real numbers: all of the\nscalars we used, for coefficients, constant terms, variables, and\nparameters, were real numbers. But in fact, we have not used very many\nproperties of the real numbers, except for the fact that we can add,\nsubtract, multiply, and divide them. For example, we have never needed\nto take a square root or to compute a trigonometric function.\n\nIn fact, most of linear algebra only requires addition, subtraction,\nmultiplication, and division. This opens the door to doing linear\nalgebra using other kinds of scalars besides the real numbers. For\nexample, we can do linear algebra over the rational numbers, complex\nnumbers, or even over some more exotic number systems that you will\nlearn about in this section. A system of scalars that one can do\nlinear algebra with is called a {\\em field}.\n\n\\begin{definition}{Field}{field}\n  \\index{properties of addition!field}%\n  \\index{properties of multiplication!field}%\n  A \\textbf{field}%\n  \\index{field} is a set $K$, together with two operations called\n  \\textbf{addition}%\n  \\index{addition!in a field} and \\textbf{multiplication}%\n  \\index{multiplication!in a field}, and together with two distinct\n  elements $0$ and $1$, such that addition and multiplication satisfy\n  the following properties:\n  \\begin{itemize}\\setlength\\itemsep{0em}\n  \\item[(A1)] {Commutative law of addition:} $a+b=b+a$;\n    \\index{commutative law!of addition}%\n  \\item[(A2)] {Associative law of addition:} $(a+b)+c = a+(b+c)$;\n    \\index{associative law!of addition}%\n  \\item[(A3)] {Unit law of addition:} $0+a = a$;\n    \\index{additive unit}%\n  \\item[(A4)] {Additive inverse:} for each $a\\in K$, there exists an element $(-a)\\in K$ such that $a+(-a)=0$;\n    \\index{additive inverse}%\n    \\index{inverse!additive}%\n  \\item[(M1)] {Commutative law of multiplication:} $ab=ba$;\n    \\index{commutative law!of multiplication}%\n  \\item[(M2)] {Associative law of multiplication:} $(ab)c=a(bc)$;\n    \\index{associative law!of multiplication}%\n  \\item[(M3)] {Unit law of multiplication:} $1a=a$;\n    \\index{multiplicative unit}%\n    \\index{unit!of multiplication|see{multiplicative unit}}%\n  \\item[(M4)] {Multiplicative inverse:} for each non-zero $a\\in K$, there exists an element $a^{-1}\\in K$ such that $aa^{-1}=1$;\n    \\index{multiplicative inverse}%\n    \\index{inverse!multiplicative}%\n    \\index{inverse!in a field}%\n    \\index{inverse!modulo p@modulo $p$}%\n  \\item[(D)] {Distributive law:} $a(b+c)=ab+ac$.\n    \\index{distributive law!of fields}%\n  \\end{itemize}\n\\end{definition}\n\nProperties (A1)--(A4) are about addition, properties (M1)--(M4) are\nabout multiplication, and property (D) is about both addition and\nmultiplication. Here are some examples and non-examples of fields:\n\n\\begin{example}{Some fields and some non-fields}{fields-examples}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item The set $\\R$ of real numbers is a field.\n    \\item The set $\\Q$ of rational numbers is a field.\n    \\item The set $\\Z$ of integers satisfies all field\n      properties except for (M4). It is therefore not a field.\n    \\item The set $\\N=\\set{0,1,2,\\ldots}$ of natural numbers\n      satisfies all field properties except (A4) and (M4). It is\n      therefore not a field.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\nA field doesn't have to be infinite. The following is an example of a\nfield with only two elements.\n\n\\begin{example}{The integers modulo 2}{z-mod-2}\n  \\index{modulo}%\n  Consider the set of {\\em bits}%\n  \\index{bit} (binary digits) $\\set{0,1}$.  We can multiply them as\n  usual, and add them almost as usual, subject to the alternative rule\n  $1+1=0$ (instead of $1+1=2$). Here is a summary of the rules for\n  addition and multiplication:\n  \\begin{equation*}\n    \\begin{array}{l|ll}\n      + & 0 & 1 \\\\\\hline\n      0 & 0 & 1 \\\\\n      1 & 1 & 0\n    \\end{array}\n    \\quad\n    \\begin{array}{l|ll}\n      \\cdot & 0 & 1 \\\\\\hline\n      0 & 0 & 0 \\\\\n      1 & 0 & 1\n    \\end{array}\n  \\end{equation*}\n  This particular alternative arithmetic is called ``arithmetic modulo\n  2''.  In computer science, the addition is also called the ``logical\n  exclusive or'' operation%\n  \\index{logical operation!exclusive or}, and multiplication is also\n  called the ``logical and'' operation%\n  \\index{logical operation!and}. You can also think of $0$ as ``even''\n  and $1$ as ``odd'', and not that odd plus odd makes even. For\n  example, we can calculate like this:\n  \\begin{equation*}\n    \\begin{array}{lll}\n      1\\cdot((1+0)+1) + 1 &=& 1\\cdot(1+1) + 1 \\\\\n                          &=& 1\\cdot 0 + 1 \\\\\n                          &=& 0 + 1 \\\\\n                          &=& 1.\n    \\end{array}\n  \\end{equation*}\n  The binary digits form a field $\\Z_2 = \\set{0,1}$, also\n  called \\textbf{the field of integers modulo 2}%\n  \\index{field!integers modulo $p$}%\n  \\index{integers modulo $p$}.\n\\end{example}\n\nYou can convince yourself that the 9 properties of fields are all\nsatisfied by the integers modulo 2. This is a bit tedious, but it can\nbe checked by calculations.  For example, to verify (A1), we have to\ncheck that $0+0=0+0$, $0+1=1+0$, $1+0=0+1$, and $1+1=1+1$. Perhaps the\nmost interesting properties are (A4) and (M4). For (A4), we can set\n$(-0)=0$ and $(-1)=1$. It may be surprising that $(-1)=1$, but you can\ncheck for yourself that $1+(-1)=1+1=0$ when calculating modulo\n$2$. For (M4), we can set $1^{-1} = 1$.\n\nWhen solving systems of linear equations, we only used addition,\nsubtraction, multiplication, and division. Therefore, we can solve\nsystems of equations using the elements of any field as the scalars,\ninstead of the real numbers.\n\n\\begin{example}{Solving a system of equations over $\\Z_2$}{system-z2}\n  Solve the following system in the integers modulo 2:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x + y     &=& 0 \\\\\n      x     + z &=& 1 \\\\\n          y + z &=& 1.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  As usual, we write the augmented matrix of the system of equations,\n  then reduce it to {\\rref} using elementary row operations. The only\n  difference is that we will perform all arithmetic operations modulo\n  2, rather than in the real numbers. The augmented matrix is:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 1 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 \\\\\n      0 & 1 & 1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The first pivot entry is the $1$ in the upper left. We use a row\n  operation to create a zero below it. Note that, because we are\n  working modulo 2, adding $1$ and subtracting $1$ is the same thing,\n  so $0-1=1$.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 \\\\\n      0 & 1 & 1 & 1 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & 0 & 0 \\\\\n      0 & 1 & 1 & 1 \\\\\n      0 & 1 & 1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The next pivot entry is in row 2 and column 2. We create a zero\n  below it by subtracting row 2 from row 3, and a zero above it by\n  subtracting row 2 from row 1:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & 0 & 0 \\\\\n      0 & \\circled{1} & 1 & 1 \\\\\n      0 & 1 & 1 & 1 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_3\\rowop R_3-R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 1 & 0 & 0 \\\\\n      0 & \\circled{1} & 1 & 1 \\\\\n      0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1-R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 1 & 1 \\\\\n      0 & \\circled{1} & 1 & 1 \\\\\n      0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The resulting system is in {\\rref}. We can see that the system is\n  consistent, because there is no row whose left-hand side is zero and\n  whose right-hand side is non-zero. We also see that there are two\n  pivot columns, and therefore two pivot variables, $x$ and $y$. On\n  the other hand, $z$ is a free variable, so we set it equal to a\n  parameter: $z=t$. Notice that this time, the parameter $t$ is not a\n  real number, but an element of $\\Z_2$. From the equation\n  $x+z=1$, we get $x=1-z=1+t$. Can you guess why I have written $1+t$\n  instead of $1-t$? This is because $(-1)=1$ in the integers modulo 2.\n  So $1-t = 1+(-1)t = 1+1t = 1+t$. Similarly, from the equation\n  $y+z=1$, we get that $y=1+t$. Therefore, the general solution to the\n  system of equations is\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x &=& 1+t \\\\\n      y &=& 1+t \\\\\n      z &=& t,\n    \\end{array}\n  \\end{equation*}\n  where $t\\in\\set{0,1}$ is an arbitrary parameter. Recall that this\n  means that each time we plug in a particular value for $t$, we get a\n  solution.\n\n  There is one difference between solving equations in the real\n  numbers and solving equations in $\\Z_2$. In the real\n  numbers, a system of equations has either no solution, a unique\n  solution, or infinitely many solutions. This is because when there\n  is a parameter, we automatically get infinitely many solutions. By\n  contrast, in $\\Z_2$, there are only two scalars, and\n  therefore only two possible values for the parameter $t$, namely\n  $t=0$ and $t=1$. For $t=0$ we get the solution $(x,y,z) = (1,1,0)$,\n  and for $t=1$ we get the solution $(x,y,z) = (0,0,1)$.  Thus, when\n  the general solution has one parameter in $\\Z_2$, there are\n  only two solutions, instead of infinitely many.\n\\end{solution}\n\n\\begin{example}{A game with buttons and lights}{button-game}\n  Consider a game with 9 lights arranged in a square:\n  \\begin{center}\n    \\begin{tabular}{|c|c|c|}\n      \\hline\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} \\\\\\hline\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} \\\\\\hline\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lightoff} &\n      \\rule{0ex}{8.5mm}\\includegraphics[width=7mm]{figures/lighton} \\\\\\hline\n    \\end{tabular}\n  \\end{center}\n  Each light is also a button. When a button is pressed, its own\n  light, and all the lights neighboring it (i.e., above, below, to the\n  left and to the right) are toggled (i.e., any light that was off is\n  turned on and vice versa). Figure out which buttons to press to\n  turn off all the lights if the starting position is as shown above.\n\\end{example}\n\n\\begin{solution}\n  We number the lights and buttons from top to bottom, left to right,\n  like this:\n  \\begin{center}\n    \\begin{tabular}{|c|c|c|}\n      \\hline\n      1 & 2 & 3\\rule{0mm}{2.3ex}\\\\\\hline\n      4 & 5 & 6\\rule{0mm}{2.3ex}\\\\\\hline\n      7 & 8 & 9\\rule{0mm}{2.3ex}\\\\\\hline\n    \\end{tabular}~.\n  \\end{center}\n  Let $x_i$ be a variable in $\\Z_2$, corresponding to the event\n  ``button $i$ is pressed'' (or more precisely, ``button $i$ is\n  pressed an odd number of times'', because pressing a button twice is\n  the same as not pressing it at all. That is why we are working\n  modulo 2). The light in position 1 is initially on. It is toggled\n  each time buttons 1, 2, and 4 are pressed, i.e., it is toggled\n  $x_1+x_2+x_4$ times. We want this light to be off in the end. So we\n  must have $1+x_1+x_2+x_4=0$. Similarly, the light in position 2 is\n  initially off. To ensure that it stays off, we must have\n  $0+x_1+x_2+x_3+x_5=0$. In this way, we obtain 9 linear equations in\n  9 variables:\n  \\begin{equation*}\n    \\begin{array}{lclcl}\n      1 &+& x_1+x_2+x_4 &=& 0 \\\\\n      0 &+& x_1+x_2+x_3+x_5 &=& 0 \\\\\n      1 &+& x_2+x_3+x_6 &=& 0 \\\\\n      0 &+& x_1+x_4+x_5+x_7 &=& 0 \\\\\n      1 &+& x_2+x_4+x_5+x_6+x_8 &=& 0 \\\\\n      0 &+& x_3+x_5+x_6+x_9 &=& 0 \\\\\n      0 &+& x_4+x_7+x_8 &=& 0 \\\\\n      0 &+& x_5+x_7+x_8+x_9 &=& 0 \\\\\n      1 &+& x_6+x_8+x_9 &=& 0.\n    \\end{array}\n  \\end{equation*}\n  If we write this system in standard form, we obtain the following\n  augmented matrix:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrrrrr|r}\n      1&1&0 & 1&0&0 & 0&0&0 & 1 \\\\\n      1&1&1 & 0&1&0 & 0&0&0 & 0 \\\\\n      0&1&1 & 0&0&1 & 0&0&0 & 1 \\\\\n\n      1&0&0 & 1&1&0 & 1&0&0 & 0 \\\\\n      0&1&0 & 1&1&1 & 0&1&0 & 1 \\\\\n      0&0&1 & 0&1&1 & 0&0&1 & 0 \\\\\n\n      0&0&0 & 1&0&0 & 1&1&0 & 0 \\\\\n      0&0&0 & 0&1&0 & 1&1&1 & 0 \\\\\n      0&0&0 & 0&0&1 & 0&1&1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  We solve this system of equations by doing Gauss-Jordan\n  elimination with scalars in $\\Z_2$.  The {\\rref} is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrrrrrrr|r}\n      1&0&0 & 0&0&0 & 0&0&0 & 0 \\\\\n      0&1&0 & 0&0&0 & 0&0&0 & 0 \\\\\n      0&0&1 & 0&0&0 & 0&0&0 & 1 \\\\\n\n      0&0&0 & 1&0&0 & 0&0&0 & 1 \\\\\n      0&0&0 & 0&1&0 & 0&0&0 & 1 \\\\\n      0&0&0 & 0&0&1 & 0&0&0 & 0 \\\\\n\n      0&0&0 & 0&0&0 & 1&0&0 & 0 \\\\\n      0&0&0 & 0&0&0 & 0&1&0 & 1 \\\\\n      0&0&0 & 0&0&0 & 0&0&1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The unique solution is $(x_1,x_2,x_3,x_4,x_5,x_6,x_7,x_8,x_9) =\n  (0,0,1,1,1,0,0,1,0)$. This means that we must press buttons 3, 4,\n  5, and 8.\n\\end{solution}\n\n\\begin{example}{The integers modulo 5}{z-mod-5}\n  Consider the set $\\Z_5=\\set{0,1,2,3,4}$, called the \\textbf{integers\n    modulo 5}%\n  \\index{integers modulo $p$}. We define their addition and\n  multiplication by computing the usual addition and multiplication,\n  then ``reducing'' the answer modulo 5. Here, ``reducing'' a number\n  means repeatedly subtracting 5 until the answer is between $0$ and\n  $4$. Imagine a clock showing 5 numbers instead of the usual 12:\n  \\begin{center}\n    \\includegraphics[width=2.5cm]{figures/clock}\n  \\end{center}\n  If we want to calculate 3 o'clock plus 4 hours, we get 2 o'clock,\n  because whenever the clock reaches 5, it resets to 0. This is how\n  addition and multiplication modulo 5 are defined:\n  \\begin{equation*}\n    \\begin{array}{l|lllll}\n      +&0&1&2&3&4 \\\\\\hline\n      0&0&1&2&3&4 \\\\\n      1&1&2&3&4&0 \\\\\n      2&2&3&4&0&1 \\\\\n      3&3&4&0&1&2 \\\\\n      4&4&0&1&2&3 \\\\\n    \\end{array}\n    \\quad\n    \\begin{array}{l|lllll}\n      \\cdot&0&1&2&3&4 \\\\\\hline\n      0&0&0&0&0&0 \\\\\n      1&0&1&2&3&4 \\\\\n      2&0&2&4&1&3 \\\\\n      3&0&3&1&4&2 \\\\\n      4&0&4&3&2&1 \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\nWe note that the integers modulo 5 form a field. Most of the\nproperties are tedious but easy to verify. Perhaps the most\ninteresting of the field properties is (M4). It says that for each\nnon-zero element $a$, there is another element $a^{-1}$ such that\n$aa^{-1}=1$.  By looking at the multiplication table, we see that\n$1\\cdot 1=1$, $2\\cdot 3=1$, $3\\cdot 2=1$, and $4\\cdot 4=1$. Therefore\nwe can set $1^{-1}=1$, $2^{-1}=3$, $3^{-1}=2$, and $4^{-1}=4$.\n\n\\begin{example}{Division in $\\Z_5$}{division-z5}\n  What is 2 divided by 3 in $\\Z_5$?\n\\end{example}\n\n\\begin{solution}\n  There are no fractions in $\\Z_5$. The key to dividing is\n  this: instead of dividing by $a$, multiply by $a^{-1}$. So we have:\n  \\begin{equation*}\n    2/3 = 2\\cdot 3^{-1} = 2\\cdot 2 = 4.\n  \\end{equation*}\n  So 2 divided by 3 equals 4. This makes sense, because 4 times 3\n  equals 2, when calculating modulo 5.\n\\end{solution}\n\n\\begin{example}{Solving a system of equations over $\\Z_5$}{system-z5}\n  Solve the following system of linear equations over $\\Z_5$:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      2x + z &=& 1 \\\\\n      x+4y+z &=& 3 \\\\\n      x+2y+3z &=& 2. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We perform the usual Gauss-Jordan algorithm on the augmented\n  matrix. The only thing to keep in mind is that, instead of dividing\n  a row by $a$, we should multiply it by $a^{-1}$. And of course, we\n  should reduce all intermediate results modulo $5$. For example, to\n  change the first pivot entry from $2$ to $1$, we multiply by\n  $2^{-1}=3$, instead of dividing by $2$.\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{2} & 0 & 1 & 1 \\\\\n      1 & 4 & 1 & 3 \\\\\n      1 & 2 & 3 & 2\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop 3R_1}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 3 & 3 \\\\\n      1 & 4 & 1 & 3 \\\\\n      1 & 2 & 3 & 2\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-R_1}{\\stackrel{R_3\\rowop R_3-R_1}{\\roweq}}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 3 & 3 \\\\\n      0 & \\circled{4} & 3 & 0 \\\\\n      0 & 2 & 0 & 4\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop 4R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 3 & 3 \\\\\n      0 & \\circled{1} & 2 & 0 \\\\\n      0 & 2 & 0 & 4\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    {}\n    \\stackrel{R_3\\rowop R_3-2R_2}{\\roweq}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 3 & 3 \\\\\n      0 & \\circled{1} & 2 & 0 \\\\\n      0 & 0 & \\circled{1} & 4\n    \\end{mymatrix}\n    \\stackrel{R_1\\rowop R_1-3R_3}{\\stackrel{R_2\\rowop R_2-2R_3}{\\roweq}}\n    \\begin{mymatrix}{rrr|r}\n      \\circled{1} & 0 & 0 & 1 \\\\\n      0 & \\circled{1} & 0 & 2 \\\\\n      0 & 0 & \\circled{1} & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  The final matrix is in {\\rref}, and we see that the system has the\n  unique solution $(x,y,z) = (1,2,4)$. Please double-check the\n  solution with respect to the original equations.\n\\end{solution}\n\n\\begin{example}{The integers modulo 6 are not a field}{not-field-z6}\n  Do the integers modulo 6 form a field?\n\\end{example}\n\n\\begin{solution}\n  The integers modulo 6 are the set $\\Z_6=\\set{0,1,2,3,4,5}$, with the\n  addition and multiplication modulo 6:\n  \\begin{equation*}\n    \\begin{array}{l|llllll}\n      +&0&1&2&3&4&5 \\\\\\hline\n      0&0&1&2&3&4&5 \\\\\n      1&1&2&3&4&5&0 \\\\\n      2&2&3&4&5&0&1 \\\\\n      3&3&4&5&0&1&2 \\\\\n      4&4&5&0&1&2&3 \\\\\n      5&5&0&1&2&3&4 \\\\\n    \\end{array}\n    \\quad\n    \\begin{array}{l|llllll}\n      +&0&1&2&3&4&5 \\\\\\hline\n      0&0&0&0&0&0&0 \\\\\n      1&0&1&2&3&4&5 \\\\\n      2&0&2&4&0&2&4 \\\\\n      3&0&3&0&3&0&3 \\\\\n      4&0&4&2&0&4&2 \\\\\n      5&0&5&4&3&2&1 \\\\\n    \\end{array}\n  \\end{equation*}\n  Then $\\Z_6$ satisfies all of the field axioms except\n  (M3). To see why (M3) fails, let $a=2$, and note, by looking at the\n  multiplication table, that there is no $b\\in\\Z_6$ such that\n  $ab=1$. Therefore, $\\Z_6$ is not a field.\n\\end{solution}\n\nWe conclude this section with a fact that we will not prove.\n\n\\begin{theorem}{The integers modulo a prime}{z-mod-p}\n  Let $n$ be a positive integer. Then the set\n  $\\Z_n=\\set{0,\\ldots,n-1}$ of integers modulo $n$, with\n  addition and multiplication modulo $n$, forms a field if and only if\n  $n$ is prime. Thus, for example, $\\Z_2$, $\\Z_3$,\n  $\\Z_5$, $\\Z_7$, and $\\Z_{11}$ are fields,\n  whereas $\\Z_4$, $\\Z_6$, and $\\Z_9$ are not.\n\\end{theorem}\n\nAnother field that is very useful in mathematics and the natural\nsciences is the field $\\C$ of \\textbf{complex numbers}%\n\\index{complex number}%\n\\index{field!of complex numbers}. You can read about the complex\nnumbers in Appendix~\\ref{app:complex}.\n\n\\begin{example}{Solving a system of equations over $\\C$}{system-c}\n  Solve the following system of equations over the complex numbers:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c}\n      x - y  + z      &=& -1+i, \\\\\n      x + iy + 3z &=& ~~1+3i. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We perform Gauss-Jordan elimination on the augmented matrix. When\n  multiplying or dividing, we have to use complex number arithmetic.\n  For example,\n  \\begin{equation*}\n    \\frac{2}{1+i} = \\frac{2}{1+i}\\cdot\\frac{1-i}{1-i} = \\frac{2-2i}{2} = 1-i.\n  \\end{equation*}\n  The row operations are:\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc|c}\n      1 & -1 & 1 & -1+i \\\\\n      1 &  i & 3 & 1+3i \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2-R_1}{\\roweq}\n    \\begin{mymatrix}{ccc|c}\n      1 &  -1 & 1 & -1+i \\\\\n      0 & 1+i & 2 & 2+2i \\\\\n    \\end{mymatrix}\n    \\stackrel{R_2\\rowop R_2/(1+i)}{\\roweq}\n    \\begin{mymatrix}{ccc|c}\n      1 & -1 & 1 & -1+i \\\\\n      0 &  1 & 1-i & 2 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    \\stackrel{R_1\\rowop R_1+R_2}{\\roweq}\n    \\begin{mymatrix}{ccc|c}\n      1 &  0 & 2-i & 1+i \\\\\n      0 &  1 & 1-i & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Therefore the general solution is $z=t$, $y=2-(1-i)t$,\n  $x=1+i-(2-i)t$, where $t\\in\\C$ is a parameter, i.e., $t$ is any\n  complex number. In vector form, the general solution is\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1+i \\\\ 2 \\\\ 0 \\end{mymatrix}\n    + t\\begin{mymatrix}{c} -2+i \\\\ -1+i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "6936da362d37103082ac5a8f6075fda8e56639f0", "size": 20813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-Fields.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/SystemsofEquations-Fields.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/SystemsofEquations-Fields.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.4334532374, "max_line_length": 128, "alphanum_fraction": 0.6207658675, "num_tokens": 7744, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544446, "lm_q2_score": 0.8887587971755248, "lm_q1q2_score": 0.7912568333015403}}
{"text": "\\subsection{Quotients of Riemann Surfaces}\r\n\\begin{definition}\r\n    Let a group $G$ act by homeomorphism on a space $X$.\r\n    The action is called properly discontinuous if every compact $K\\subset X$ has $\\{g\\in G:g(K)\\cap K\\neq\\varnothing\\}$ finite.\\\\\r\n    The action is free if for every $x\\in X$ the stabiliser $\\operatorname{Stab}_G(x)$ is trivial.\r\n\\end{definition}\r\n\\begin{example}\r\n    If $\\Lambda$ is a lattice in $\\mathbb C$, then the action of $\\Lambda$ on $\\mathbb C$ by translation is properly discontinuous and free.\r\n\\end{example}\r\n\\begin{lemma}\r\n    Let $G$ be a group acting properly discontinuously and freely on a Riemann surface $R$.\r\n    The quotient $G\\backslash R$ is Hausdorff and the quotient map $\\pi:R\\to G\\backslash R$ is a regular covering map.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    For any $p,q\\in R$ with $\\pi(p)\\neq\\pi(q)$, as $R$ is Hausdorff and locally Euclidean, we can find open $U\\ni p,V\\ni q$ such that $\\bar{U},\\bar{V}$ are compact.\r\n    Then $K=\\bar{U}\\cap\\bar{V}$ is also compact, so $\\{g\\in G:g(K)\\cap K\\neq\\varnothing\\}\\supset\\{g\\in G:g(\\bar{U})\\cap\\bar{V}\\neq\\varnothing\\}$ is finite.\r\n    Say this set is $\\{g_1,\\ldots,g_n\\}$.\r\n    Then for each $i$ there are disjoint open neighbourhoods $U_i\\ni x$ and $V_i\\ni g_iy$.\r\n    Now $U'=U\\cap\\bigcap_iU_i$ and $V'=V\\cap\\bigcap_ig_i^{-1}(V_i)$ are disjoint open neighbourhoods of $p,q$ with $GU'$ disjoint from $GV'$.\r\n    Hence as $\\pi$ is open, $\\pi(U')$ and $\\pi(V')$ are the required disjoint open neighbourhoods of $\\pi(p),\\pi(q)$.\\\\\r\n    To see $\\pi$ is a regular covering map, we use a similar argument.\r\n    For any $p\\in R$, again take $U\\ni p$ with compact closure $K=\\bar{U}$ and let $\\{1,g_1,\\ldots,g_n\\}$ be the set $\\{g\\in G:g(K)\\cap K\\neq\\varnothing\\}$.\r\n    As the action is free, $g_ix\\neq x$ for each $i$, hence there exists disjoint open neighbourhoods $U_i\\ni x$ and $V_i\\ni g_ix$.\r\n    But then $U'=U\\cap\\bigcap_i(U_i\\cap g_i^{-1}V_i)$ is evenly covered via $\\pi$.\r\n    Hence $\\pi$ is a regular covering map.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $R$ be a Riemann surface and let $G$ be a group acting freely and properly discontinuously by conformal equivalences on $R$.\r\n    Then the quotient $S=G\\backslash R$ can be made a Riemann surface so that the quotient map $\\pi:R\\to S$ is analyic and a regular covering map.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    It is obvious that $S$ is connected since $R$ is.\r\n    The preceding lemma shows that $S$ is Hausdorff.\r\n    The conformal structure on $S$ can be constructed analogously to what we did for the complex torus.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $R$ be a compact Riemann surface of genus $g_R\\ge 2$ and suppose that a group $G$ acts freely and properly discontinuously on $R$ by conformal equivalences, then $G$ is finite and $|G|\\le g_R-1$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $S=G\\backslash R$ is a Riemann surface and the quotient map $\\pi:R\\to S$ is an analytic covering map.\r\n    $\\deg\\pi=|G|$ by construction, so in particular $G$ is finite.\r\n    \\footnote{Alternatively, just take $K=R$ in the definition of properly discontinuous action.}\r\n    Also $\\pi$ is a covering map, so it has to be unramified, therefore Riemann-Hurwitz gives $g_R-1=|G|(g_S-1)$.\r\n    As $g_R\\ge 2$, $g_S-1\\ge 1$, consequently $g_R-1\\ge |G|$.\r\n\\end{proof}\r\nNote that this fails when $g_R=1$.\r\n\\begin{example}[Non-example]\r\n    The torus $\\mathbb C/\\Lambda$ is a group as well, and it acts on itself by conformal equivalences via left translation $(z+\\Lambda)(z_0+\\Lambda)\\mapsto (z+z_0)+\\Lambda$.\r\n    Easily any finite subgroup of $\\mathbb C/\\Lambda$ acts on $\\mathbb C/\\Lambda$ properly continuously through the same action, but the size of these subgroups is unbounded.\r\n\\end{example}", "meta": {"hexsha": "7781e357f53f58e8ff99ac5c19bd3f7db51bcb31", "size": 3739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15/quotient.tex", "max_stars_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_stars_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "15/quotient.tex", "max_issues_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_issues_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "15/quotient.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": 74.78, "max_line_length": 204, "alphanum_fraction": 0.6862797539, "num_tokens": 1196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8902942341267435, "lm_q1q2_score": 0.7912568293757756}}
{"text": "\\section{Partial correlations}\n\n\\subsection{Definition of a partial correlation}\n\n\\marginnote{\nA partial correlation is a~measure of the degree of dependence between two random\nvariables while controlling for the~effect of other random variables:\n\\[\n\\pCorr(X,Y; Z) = \\frac{\\pCov(X,Y;Z)}{\\sqrt{\\pVar(X;Z)\\pVar(Y;Z)}}\n\\]\nwhere $\\pVar(X;Z) = \\Var(X - \\alpha Z)$, $\\alpha$ is such a~constant that $\\Cov(X - \\alpha Z, Z) = 0$,\nand $\\pCov(X,Y; Z) = \\Cov(X - \\alpha Z, Y - \\beta Z)$, $\\alpha$, $\\beta$ are such\nconstants that $\\Cov(X - \\alpha Z, Z) = \\Cov(Y - \\beta Z, Z) = 0$.\n}\n\nA partial correlation can be defined in two ways.\nWe will provide both definitions and show their equivalence.\n\n\\begin{definition}\nA partial correlation between random variables $X$ and $Y$ holding random variable $Z$\nfixed is the~correlation coefficient between the~residuals in regression of $X$ onto\n$Z$ and the~residuals in regression of $Y$ onto $Z$.\n\\end{definition}\n\nFirstly, we project a random variable $X$ onto $Z$, which yields $\\E(X \\vert Z)$.\nThe residuals in this regression are $X - \\E(X \\vert Z)$ — a vector in $\\Lin^{\\perp}(Z)$.\nWe will call this variable `cleansed' and label it as $\\widetilde X$.\nApplying the same procedure for $Y$ yields the `cleansed' variable $\\tilde Y = Y - \\E(Y \\vert Z) \\in \\Lin^{\\perp}(Z)$.\nThe~angle between $\\widetilde X$ and $\\widetilde Y$ ($\\varphi$ in Figure~\\ref{fig:pcorr_def1})\nis the~correlation coefficient between these `cleansed' random variables and\nthe~partial correlation between the~original ones.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.55\\linewidth]{figures/03_partial_correlation_definition.pdf}\n\\caption{Partial correlation between $X$ and $Y$ while $Z$ is fixed.}\n\\label{fig:pcorr_def1}\n\\end{figure}\n\n\\marginnote{\nLet us define $\\widetilde X$ and $\\widetilde Y$ as\n\\begin{align*}\n\\widetilde X &= \\alpha_{XY} \\widetilde Y + \\tilde{u}_{XY}, \\widetilde X \\perp Z \\\\\n\\widetilde Y &= \\alpha_{YX} \\widetilde X + \\tilde{u}_{YX}, \\widetilde Y \\perp Z\n\\end{align*}\nThen assuming that the~error term $u_{XY}$ is uncorrelated with $\\widetilde Y$,\nwe obtain:\n\\begin{align*}\n&\\Cov(\\widetilde Y, \\widetilde X - \\alpha_{XY} \\widetilde Y) = 0 \\\\\n&\\Cov(\\widetilde Y, \\widetilde X) - \\alpha_{XY} \\Cov(\\widetilde Y, \\widetilde Y) = 0 \\\\\n&\\alpha_{XY} = \\frac{\\Cov(\\widetilde Y, \\widetilde X)}{\\Var(\\widetilde Y)}\n\\end{align*}\nIn the same manner we get $\\alpha_{YX}$:\n\\[\n\\alpha_{YX} = \\frac{\\Cov(\\widetilde Y, \\widetilde X)}{\\Var(\\widetilde X)}\n\\]\nNote, that $\\alpha_{XY}$ and $\\alpha_{XY}$ are of the~same sign.\n}\n\n\\begin{definition}\nA partial correlation between random variables $X$ and $Y$ holding random variable $Z$\nfixed is the~geometric mean between the coefficient $\\beta_{XY}$ in regression\n\\[\nX = \\beta_{XY} Y + \\beta_{XZ} Z + u_X\n\\]\nand the~coefficinent $\\beta_{YX}$ in regression\n\\[\nY = \\beta_{YX} X + \\beta_{YZ} Z + u_Y\n\\]\nThe partial correlation has the same sign as the~coefficients $\\beta_{XY}$ and $\\beta_{YX}$.\n\\end{definition}\n\nFollowing the~definition, we need to start with regressing variable $X$ onto\n$Y$ and $Z$. Then, the vector we obtain $\\hat X = \\E(X \\vert Y, Z)$\ncan be broken up into the sum of $\\beta_{XY} Y$ and $\\beta_{XZ} Z$.\nProjecting $\\beta_{XY} Y$ onto $\\Lin^{\\perp}(Z)$ results in a~vector\n$\\alpha_{XY} \\widetilde Y$ where $\\widetilde Y = Y - \\E(Y \\vert Z)$\nis the projection of $Y$ onto $\\Lin^{\\perp}(Z)$.\n\n\\marginnote{\nMultiplying these coefficients, we get the final result:\n\\begin{multline*}\n\\alpha_{XY} \\cdot \\alpha_{XY} = \\frac{\\Cov^2(\\widetilde Y, \\widetilde X)}{\\Var(\\widetilde Y)\\Var)\\widetilde X} \\\\\n= \\Corr^2(\\widetilde X, \\widetilde Y) = \\pCorr^2(X,Y; Z)\n\\end{multline*}\n}\n\nBy the~properties of similar triangles\n\\[\n\\frac{\\beta_{XY} Y}{Y} = \\frac{\\alpha_{XY} \\widetilde Y}{\\widetilde Y} \\Leftrightarrow \\beta_{XY} = \\alpha_{XY}\n\\]\n\nIn the same way we perform a regression of $Y$ onto $X$ and $Z$ and repeat the\nsame steps for $X$. Finally, we get the whole picture:\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.55\\linewidth]{figures/03_partial_correlation_regression_definition.pdf}\n\\label{fig:part_corr_alt}}\n\\subfigure[]{\n\\includegraphics[width=0.35\\linewidth]{figures/03_partial_correlation_regression_definition_lin.pdf}\n\\label{fig:part_corr_alt_lin}}\n\\caption{\\subref{fig:part_corr_alt}: Alternative definition of the partial correlation;\n\\subref{fig:part_corr_alt_lin}: $\\Lin^{\\perp}(Z)$.}\n\\end{center}\n\\end{figure}\n\nHaving plotted $\\Lin^{\\perp}(Z)$, now we can express $\\cos \\varphi$ in terms of $\\beta_{XY}$\nand $\\beta_{YX}$. We use the fact that $\\beta_{XY} \\beta_{YX} > 0$:\n\n\\begin{equation*}%\\label{eq:part_cor_cos}\n\\begin{split}\n\\cos \\varphi &= \\frac{\\vert \\beta_{XY} \\widetilde Y \\vert}{\\vert \\widetilde X \\vert} \\\\\n\\cos \\varphi &= \\frac{\\vert \\beta_{YX} \\widetilde X \\vert}{\\vert \\widetilde Y \\vert} \\\\\n\\cos^2 \\varphi &= \\vert \\beta_{XY} \\beta_{YX} \\vert \\stackrel{\\beta_{XY} \\beta_{YX} > 0}{=} \\beta_{XY} \\beta_{YX}\n\\end{split}\n\\end{equation*}\n\nRecall that the angle $\\varphi$ can be interpreted as the correlation\nbetween $\\widetilde X$ and $\\widetilde Y$.\nThese random variables are constructed in such a way that both of them\nare uncorrelated with $Z$. Thus, it follows that\n\\[\n\\cos^2 \\varphi = \\Corr^2(\\widetilde X, \\widetilde Y) = \\pCorr^2(X,Y; Z) = \\beta_{XY} \\beta_{YX}\n\\]\n\n\\subsection{Partial correlation as correlation between residuals}\n\n\\marginnote{\nLet us define cleansed $X$ and $Y$ first as\n\\begin{align*}\n\\widetilde{X} &= \\alpha_1 \\widetilde{Y} + \\tilde{u}, \\widetilde{X} \\perp Z \\\\\n\\widetilde{Y} &= \\beta_1 \\widetilde{X} + \\tilde{v}, \\widetilde{Y} \\perp Z\n\\end{align*}\nThen\n\\begin{align*}\n\\alpha_1 &= \\frac{\\Cov(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{Y})} \\\\\n\\beta_1 &= \\frac{\\Cov(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X})}\n\\end{align*}\n}\n\n\n\n\\begin{theorem}\nThe partial correlation between $X$ and $Y$ holding $Z$ fixed is the negative\ncorrelation coefficient between the residuals $u$ in the regression model\n\\[\nX = \\alpha_1 Y + \\alpha_2 Z + u\n\\]\nand the residuals $v$ in the model\n\\[\nY = \\beta_1 X + \\beta_2 Z + v\n\\]\n\\end{theorem}\n\n\\begin{proof}\nThe first step is to find the residuals in the regressions.\nFor example, in order to get $u$ we regress $X$ onto $\\Lin(Y,Z)$\nwhich results in $\\hat X = X - \\E(X \\vert Y, Z)$.\nThen we take the difference $X - \\hat X = u$\nand project it and $X$ itself onto $\\Lin^{\\perp}(Z)$ as demonstrated\nin Figure~\\ref{fig:pcorr_t_x}.\nWe denote the result as $\\tilde u$ and $\\widetilde X$ respectively.\n\nFigure~\\ref{fig:pcorr_t_y} shows the same steps for obtaining $\\tilde v$ and $\\widetilde Y$.\n\n\\marginnote[-6\\baselineskip]{\nSubstituting these into $\\Cov(\\tilde{u}, \\tilde{v})$, we obtain:\n\\begin{align*}\n&\\Cov(\\tilde{u}, \\tilde{v}) = \\\\\n&\\Cov\\left(\\widetilde{X} - \\frac{\\Cov(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{Y})} \\widetilde{Y},\n\\widetilde{Y} -  \\frac{\\Cov(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X})} \\widetilde{X}\\right) \\\\\n&= \\Cov(\\widetilde{X}, \\widetilde{Y}) - \\Cov(\\widetilde{X}, \\widetilde{Y}) \\\\\n&- \\Cov(\\widetilde{X}, \\widetilde{Y}) + \\frac{\\Cov^3(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X})\\Var(\\widetilde{Y})} \\\\\n&= - \\Cov(\\widetilde{X}, \\widetilde{Y}) \\left(1 - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X})\\Var(\\widetilde{Y})} \\right)\n\\end{align*}\nNext, we deal with variances of $\\tilde{u}$ and $\\tilde{v}$:\n\\begin{align*}\n\\Var(\\tilde{u}) &= \\Var(\\widetilde{X}) - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y})}{\\Var^2(\\widetilde{Y})} \\Var(\\widetilde{Y}) \\\\\n&- 2 \\Cov(\\widetilde{X}, \\widetilde{Y}) \\frac{\\Cov(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{Y})} \\\\\n&= \\Var(\\widetilde{X}) \\left(1 - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y}}{\\Var(\\widetilde{X}) \\Var(\\widetilde{Y})}\\right) \\\\\n&\\Var(\\tilde{v}) = \\Var(\\widetilde{Y}) \\left(1 - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y}}{\\Var(\\widetilde{X}) \\Var(\\widetilde{Y})}\\right)\n\\end{align*}\nNow we can write out $\\Corr(\\tilde{u}, \\tilde{v})$:\n\\begin{align*}\n&\\Corr(\\tilde{u}, \\tilde{v}) = \\\\\n&= -\\frac{\\Cov(\\widetilde{X}, \\widetilde{Y}) \\left(1 - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X})\\Var(\\widetilde{Y})} \\right)}{\\sqrt{\\Var(\\widetilde{X})\\Var(\\widetilde{Y}) \\left(1 - \\frac{\\Cov^2(\\widetilde{X}, \\widetilde{Y})}{\\Var(\\widetilde{X}) \\Var(\\widetilde{Y})}\\right)^2 }} \\\\\n&= -\\Corr(\\widetilde{X}, \\widetilde{Y})\n\\end{align*}\n}\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/03_partial_correlation_residuals_x.pdf}\n\\label{fig:pcorr_t_x}}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/03_partial_correlation_residuals_y.pdf}\n\\label{fig:pcorr_t_y}}\n\\caption{\\subref{fig:pcorr_t_x}: $\\hat u$ form regression of $X$ onto $Y$ and $Z$, $\\hat u$ projected;\n\\subref{fig:pcorr_t_y}: $\\hat v$ from regression of $Y$ onto $X$ and $Z$, $\\hat v$ projected.}\n\\end{center}\n\\end{figure}\n\n\nAfter putting these figures together, we need to measure the angle\nbetween the $\\tilde u$ and $\\tilde v$.\nTranslating the $\\tilde v$ vector to the orgin of $\\tilde x$ as shown in Figure~\\ref{fig:pcorr_t_lin},\nwe conclude that the desired angle is the bigger of the vertical angles.\nHence, we can derive it from the property of the quadrilateral\nby substracting all the known angles from $360^\\circ$.\nThus, the desired angle is $180^\\circ - \\varphi$.\n\\begin{align*}\n\\cos\\varphi &= - \\cos(180^\\circ - \\varphi) \\\\\n\\Corr(\\widetilde X, \\widetilde Y) &= -\\Corr(\\tilde u, \\tilde v) \\\\\n\\pCorr(X,Y; Z) &= -\\Corr(u, v)\n\\end{align*}\n\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/03_partial_correlation_residuals_xy.pdf}\n\\label{fig:pcorr_t_xy}}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/03_partial_correlation_residuals_xy_lin.pdf}\n\\label{fig:pcorr_t_lin}}\n\\caption{\\subref{fig:pcorr_t_x}: The residuals of both regressions;\n\\subref{fig:pcorr_t_y}: $\\Lin^{\\perp}(Z)$.}\n\\setfloatalignment{b}\n\\end{center}\n\\end{figure}\n\\end{proof}\n", "meta": {"hexsha": "26c26ffba514f9f53e28e6d0a1d016cae8c8d0a2", "size": 9953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/3_partial_correlation.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/3_partial_correlation.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/3_partial_correlation.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 42.3531914894, "max_line_length": 302, "alphanum_fraction": 0.6864262032, "num_tokens": 3599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.7912568248847266}}
{"text": "\\section{Bayesian inference for the Gaussian distribution}\n\n\\subsection{The univariate Gaussian}\n\\begin{align}\nt &\\sim \\mathcal{N}(\\mu,\\sigma^2)\\\\\np(t|\\mu, \\sigma^2)&=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left( -\\frac{1}{2}\\left(\\frac{t-\\mu}{\\sigma} \\right)^2\\right)\n\\end{align}\n\\begin{itemize}\n\\item \nThe Gaussian has \\emph{mean} $\\mu$ and \\emph{variance} $\\sigma^2$ and \\emph{precision} $\\beta=1/\\sigma^2$\n\\end{itemize}\n\n\\begin{bbbox}{The univariate Gaussian}\n\n\\begin{flalign*}\n\t\\mu = 0; \\sigma^2 = 1, \\\\\n\tP(t) = \\frac{1}{\\sqrt{2\\pi}} \\mbox{e}^{-\\frac{1}{2}t^2} \\\\\n\t\\int_{-\\infty}^{\\infty} P(t) \n\t\t&= \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^{\\infty} \\mbox{e}^{-\\frac{1}{2}t^2} dt\\\\\n\t\t&= \\frac{1}{\\sqrt{2\\pi}} \\sqrt{2\\pi} = 1\n\\end{flalign*}\n\n\\begin{itemize}\n\\item  Q: What are the \\emph{mode} and the \\emph{median} of the Gaussian?\\\\\n\t\t  Mode and median of the Gaussian are equal to the mean. This can easily be seen graphically.\t\n\t\t  \n\\end{itemize}\n\\end{bbbox}\n\n\\begin{bbbox}{Maximum Likelihood estimation of $\\mu$ and $\\beta$}\n\n\t  \\begin{align*}\n\t  \tD &= \\{ t_1 , t_2 ,\\cdots , t_n \\} \\\\\n\t  \tL(D|\\mu,\\beta) &= \\prod_{n=1}^N \\mathcal{N} \\left( t_n,\\mu,\\sigma^2 \\right) \\\\\n\t  \t\t\t\t   &= \\sqrt{\\frac{\\beta}{2\\pi}}^N \\mbox{e}^{-\\frac{\\beta}{2} \\sum_{n=1}^N \\left(t_n - \\mu\\right)^2} \\\\\n\t\t\\log L &= \\frac{N}{2} \\log \\left( \\frac{\\beta}{2\\pi} \\right) - \\frac{\\beta}{2} \\sum_{n=1}^N \\left(t_n - \\mu\\right)^2 \\\\\n\t\t\\end{align*}\n\t\t\n\t\t\\text{Maximum likelihood solution for the mean } $\\mu$ \\\\\n\t\t\\begin{align*}\n\t\t0 &= \\frac{\\partial \\log L}{\\partial \\mu} = -\\frac{\\beta}{2} \\sum_{n=1}^N 2 \\left(t_n - \\mu \\right) (-1) \\\\\n\t\t0 &= \\sum_{n=1}^N t_n - \\sum_{n=1}^N \\mu \\\\\n\t\t\\mu &= \\frac{1}{N} \\sum_{n=1}^N t_n \\\\\n\t\t\\end{align*}\n\t\t\n\t\t\\text{Maximum likelihood solution for the variance } $\\sigma^2 = \\frac{1}{\\beta}$ \\\\\n\t\t\\begin{align*}\n\t\t0 &= \\frac{\\partial \\log L}{\\partial \\beta} = \\frac{N}{2\\beta} - \\frac{1}{2} \\sum_{n=1}^N 2 \\left(t_n - \\mu \\right)^2 \\\\\n\t\t\\sigma^2 &= \\frac{1}{\\beta} = \\frac{1}{N} \\sum_{n=1}^N 2 \\left(t_n - \\hat{\\mu} \\right)^2 \\\\\n\t  \\end{align*}\nQ: How would you find the conjugate prior for the Gaussian? \\\\\n\n\\end{bbbox}\n\n\\textbf{(very important) aside: Products of Gaussian pdfs are (unnormalized) Gaussians pdfs}\n\\begin{itemize}\n\\item Suppose $p_1(x)=\\mathcal{N}(x,\\mu_1, \\frac{1}{\\beta_1})$ and $ p_2(x)=\\mathcal{N}(x,\\mu_2, \\frac{1}{\\beta_2})$, then  \n \\begin{align}\np_1(x) p_2(x) &\\propto \\mathcal{N}(x, \\mu, 1/\\beta)\\\\\n\\beta&=\\beta_1+\\beta_2\\\\\n\\mu&=\\frac{1}{\\beta}(\\beta_1 \\mu_1 +  \\beta_2 \\mu_2)\n\\end{align}\n\n\\begin{bbbox}{Products of Gaussians}\n\tQuadratic form for the Gaussian:\n\t\\begin{align*}\n\t\tp(t|\\mu, \\sigma^2) \n\t\t&=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}\\exp\\left( -\\frac{1}{2}\\left(\\frac{t-\\mu}{\\sigma} \\right)^2\\right) \\\\\n\t\t&= \\frac{1}{Z} \\exp \\left( \\underbrace{a}_{-\\frac{1}{2}\\text{precision}}x^2 + \\underbrace{b}_{\\text{precision} \\times \\text{mean}}x \\right) \\\\\n\t\\end{align*}\n\t\n\tWe show that the product of two Gaussians $p_1(x)$ and $p_2(x)$ is again Gaussian: \\\\\n\t\\begin{align*}\n\tp_1(x) &= \\frac{1}{Z_1} \\exp \\left( -\\frac{\\beta_1}{2} \\left(x-\\mu_1 \\right)^2 \\right) \t\\\\\n\tp_2(x) &= \\frac{1}{Z_2} \\exp \\left( -\\frac{\\beta_2}{2} \\left(x-\\mu_2 \\right)^2 \\right) \t\\\\\n\tp_1(x) p_2(x) &= \\frac{1}{Z_s} \\exp \\left( -\\frac{\\beta_1}{2} \\left( x - \\mu_1 \\right)^2\n\t\t\t\t\t  -\\frac{\\beta_2}{2} \\left( x - \\mu_2 \\right)^2\t\\right)\\\\\n\t\t\t\t  &= \\frac{1}{Z_q} \\exp \\left( -\\left( \\frac{\\beta_1}{2} + \\frac{\\beta_2}{2}\\right) x^2\n\t                 + 2\\left( \\frac{\\beta_1}{2} \\mu_1 + \\frac{\\beta_2}{2} \\mu_2 \\right) x \\right)\\\\\n\t\\beta &= \\beta_1 + \\beta_2 \\\\\n\t\\beta \\mu &= = \\beta_1 \\mu_1 + \\beta_2 \\mu_2 \\\\\n\t\\mu &= \\frac{1}{\\beta} \\left( \\beta_1 \\mu_1 + \\beta_2 \\mu_2 \\right)\n\t\\end{align*}\n\tThe quadratic form helps us to simply read out the parameters of our resulting Gaussian. We will see later that this observation comes in handy for Bayesian inference with Gaussians.\n\\end{bbbox}\n \nIn general:\n\\begin{align}\np_1(x) p_2(x) ... p_n(x) &\\propto \\mathcal{N}(x, \\mu, 1/\\beta)\\\\\n\\beta&=\\sum_n \\beta_n\\\\\n\\mu&=\\frac{1}{\\beta} \\sum_n \\mu_n \\beta_n\n\\end{align}\n\n \nThis is also true for multivariate Gaussians!\n\n\\end{itemize}\n\n\n\n\\subsection{Bayesian inference for Gaussians}\n\n\\begin{itemize}\n\\item Suppose we are given data $D=\\{x_1, \\ldots, x_N\\}$. \n\\item We assume that the data is Gaussian-distribution with known variance $\\sigma^2$ and unknown mean $\\mu$.\n\\item Our prior for $\\mu$ is Gaussian: $\\mu \\sim \\mathcal{N}(\\mu_o, \\sigma^2_o)$\n\\item Posterior distribution over $\\mu$ given the data: [on board] \n\\end{itemize}\n\n\\begin{bbbox}{Posterior inference for the Gaussian}\n\tHere we want to derive the posterior  distribution for the mean of a Gaussian. For now we will assume that the variance $\\sigma^2$ of our Gaussian is known and that the only parameter of interest is $\\mu$. \\\\\n\tWe define a prior over $\\mu$:   $p(\\mu) = \\mathcal{N}(\\mu_0, \\sigma^2_0)$ which is again Gaussian. \\\\\n\tFrom before we know that our posterior distribution over $\\mu$ is again Gaussian:\n\t\\begin{align*}\n\t\tp(\\mu|\\sigma^2, \\underbrace{\\mu_0, \\sigma_0^2}_{Prior},D)\t\n\t\t            &\\propto p(D|\\mu,\\sigma^2,\\mu_0, \\sigma_0^2) p(\\mu|\\mu_0, \\sigma_0^2) \\\\\n\t\t            &\\propto \\prod_{n=1}^N \\mathcal{N}(x_n,\\mu,\\sigma^2) \\mathcal{N}(\\mu,\\mu_0, \\sigma_0^2) \\\\\n\t\t            &\\propto \\mathcal{N}(\\mu,\\mu_{post},\\sigma_{post}^2) \\\\\n\t\t\\frac{1}{\\sigma_{post}^2} &= \\sum_{n=1}^N \\left(\\frac{1}{\\sigma^2} \\right) + \\frac{1}{\\sigma_0^2} \\\\\n\t\t\\sigma_{post}^2 &= \\frac{1}{\\frac{N}{\\sigma^2} + \\frac{1}{\\sigma_0^2}} \\\\\n\t\t\\mu_{post} &= \\sigma_{post}^2 \\left( \\sum_{n=1}^N \\left( x_n\\frac{1}{\\sigma^2} \\right) + \\mu_0 \\frac{1}{\\sigma_0^2} \\right)\n\t\\end{align*}\n\t\nBehaviour for large $N$: [on board]\n\\begin{align*}\n\t\\text{for large N: } \\sigma_{post}^2 = \\frac{\\sigma^2}{N} \\\\\n\t\\mu_{ML} &= \\frac{1}{N} \\sum_{n=1}^N x_n \\\\\n\t\\mu_{post} &= \\frac{\\left( \\sum_{n=1}^N \\left( x_n\\frac{1}{\\sigma^2} \\right) + \\mu_0 \\frac{1}{\\sigma_0^2} \\right)}{\\frac{N}{\\sigma^2} + \\frac{1}{\\sigma_0^2}} \\\\\n\tN \\rightarrow \\infty: &\\mu_{post} = \\mu_{ML} \\\\\n\t\\sigma_0^2 \\rightarrow 0: &\\mu_{post} = \\mu_{ML} \\\\\n\\end{align*}\n\n\\end{bbbox}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.5\\textwidth]{./lecture4/Figure212.pdf}\n\t\\caption{Bishop Figure 2.12}\n\\end{figure}\n\n\\subsubsection{What if the variance is not given?}\n\\begin{itemize}\n\\item For simplicity, assume mean to be known.\n\\item More convenient to work with precision $\\lambda=1/\\sigma^2$.\n\\item Conjugate prior: Gamma distribution $\\mbox{Gam}(\\lambda|a,b)$\n\\begin{align}\np(\\lambda|a, b)=\\frac{1}{\\Gamma(a)}b^a \\lambda^{a-1} exp(-b\\lambda)\n\\end{align}\n\\item Posterior is $\\mbox{Gam}(\\lambda|a_N,b_B)$\n\\begin{align}\na_N &= a + \\frac{N}{2}\\\\\nb_N &= b + \\frac{1}{2} \\sum_{n=1}^N (x_n -\\mu)^2\n\\end{align}\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{./lecture4/Figure213b.pdf}\n    \\end{subfigure}%\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{./lecture4/Figure213c.pdf}\n    \\end{subfigure}%\n   \t\\caption{Gamma distribution with different parameterizations. The Gamma distribution is a conjugate prior for the presision of a Gaussian. Figures taken from Bishop page 100.}\n\t\n\\end{figure}\n\\end{itemize}\n\n\n\\subsubsection{What if both the mean and the variance are unknown?}\n\\begin{figure}[h]\n\t\\centering\n\t\t\\includegraphics[width=0.7\\textwidth]{./lecture4/Figure214.pdf}\n\t\t\\caption{The Gaussian-Gamma distribution, a conjugate prior for mean and precision of a Gaussian. Bishop figure 2.14, page 102.}\n\\end{figure}    \n\\begin{itemize}\n\\item Conjugate prior: Gaussian-Gamma distribution\n\\begin{align}\np(\\mu,\\lambda) & = \\mathcal{N}\\left(\\mu |\\mu_o (\\beta\\lambda)^{-1}\\right) \\mbox{Gam}(\\lambda|a,b)\n\\end{align}\n\\end{itemize}\n", "meta": {"hexsha": "a0b2a2a4f87600478c469117f7630073beed5a8a", "size": 7782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture4/lecture4.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/lecture4/lecture4.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/lecture4/lecture4.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": 42.2934782609, "max_line_length": 209, "alphanum_fraction": 0.6290156772, "num_tokens": 3089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392797, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7912492992894937}}
{"text": "\\subsubsection{Repeated Linear Factors}\r\nIf $Q(x)$ has repeated roots, it factors into\r\n\\begin{equation*}\r\n\tQ(x) = R(x)(x-a)^k\\text{, }k \\geq 2\\text{ and }R(a) \\neq 0.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nWhen making the common denominator for each repeated root of multiplicity $k$, we do\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{R(x)(x-a)^k} = \\left(\\text{Decomposition of }R(x)\\right) + \\frac{A_1}{x-a}+\\ldots+\\frac{A_k}{(x-a)^k}.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nYou would then multiply each side by the denominator like in the linear factors case and solve for the coefficients.\r\nThe only additional difficulty is that you might have to use previous results or solve a system of linear equations to get some of the constants.\r\n\r\n\\begin{example}\r\n\tFind the partial fraction of the following expression:\r\n\t\\begin{equation*}\r\n\t\t\\frac{x^2+5x-6}{x^3-7x^2+16x-12}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFactoring,\r\n\\begin{equation*}\r\n\tx^3-7x^2+16x-12 = (x-3)(x-2)^2.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{x^2+5x-6}{x^3-7x^2+16x-12} =  \\frac{A_1}{x-3} + \\frac{A_2}{x-2} + \\frac{A_3}{(x-2)^2}.\r\n\\end{equation*}\r\nMultiplying each side by the denominator,\r\n\\begin{equation*}\r\n\tx^2+5x-6 = A_1(x-2)^2 + A_2(x-2)(x-3) + A_3(x-3).\r\n\\end{equation*}\r\nAt $x=2$,\r\n\\begin{equation*}\r\n\t8 = A_3(2-3) \\implies A_3 = -8.\r\n\\end{equation*}\r\nAt $x=3$,\r\n\\begin{equation*}\r\n\t18 = A_1(3-2)^2 \\implies A_1 = 18.\r\n\\end{equation*}\r\nNow we'll use our results for $A_1$ and $A_3$ to find $A_2$ using a value for $x$ that isn't 2 or 3 so the $A_2$ term doesn't become 0. A good choice is $x=0$.\\\\\r\nAt $x=0$,\r\n\\begin{equation*}\r\n\t-6 = 18(0-2)^2 + A_2(0-2)(0-3) + -8(0-3) \\implies A_2 = -17.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{x^2+5x-6}{x^3-7x^2+16x-12} = \\frac{18}{x-3} - \\frac{17}{x-2} - \\frac{8}{(x-2)^2}.\r\n\\end{equation*}", "meta": {"hexsha": "0d3c090b1f58fc1d77cc34b19b63a86aab5b0f5b", "size": 1809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/repeatedLinearFactors.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/repeatedLinearFactors.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/repeatedLinearFactors.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 34.7884615385, "max_line_length": 162, "alphanum_fraction": 0.6390270868, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.791218869212992}}
{"text": "\\section{Addition}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute sums and differences of vectors algebraically and\n    geometrically.\n  \\item Use the laws of vector addition to prove equalities between\n    vector expressions.\n  \\end{enumerate}\n\\end{outcome}\n\nAddition of vectors in $\\R^n$ is defined as follows.\n\n\\begin{definition}{Addition of vectors in $\\R^n$}{vector-addition}\n  For vectors $\\vect{u}=\\begin{mymatrix}{c}\n    u_1 \\\\\n    \\vdots \\\\\n    u_n\n  \\end{mymatrix},\\; \\vect{v}= \\begin{mymatrix}{c}\n    v_1 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{mymatrix} \\in \\R^n$, the sum%\n  \\index{vector!addition}%\n  \\index{addition!of vectors} $\\vect{u}+\\vect{v}\\in \\R^n$ is defined\n  by\n  \\begin{equation*}\n    \\vect{u}+\\vect{v} = \\begin{mymatrix}{c}\n      u_1 \\\\\n      \\vdots \\\\\n      u_n\n    \\end{mymatrix} +  \\begin{mymatrix}{c}\n      v_1 \\\\\n      \\vdots \\\\\n      v_n\n    \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      u_1+v_1 \\\\\n      \\vdots \\\\\n      u_n+v_n\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nTo add vectors, we simply add corresponding components. Therefore, in\norder to add vectors, they must be the same size.  For example,\n$\\mat{1, 2, 3}^T + \\mat{4, 5, 6}^T = \\mat{1+4, 2+5, 3+6}^T =\n\\mat{5, 7, 9}^T$.\n\nThe geometric significance of vector addition in $\\R^n$ is given in\nthe following proposition.\n\n\\begin{proposition}{Geometry of vector addition}{geometry-of-vector-addition}\n  Let $\\vect{u}$ and $\\vect{v}$ be two vectors in $\\R^n$. Slide\n  $\\vect{v}$ so that the tail of $\\vect{v}$ is on the tip of\n  $\\vect{u}$. Then draw the arrow which goes from the tail of\n  $\\vect{u}$ to the tip of $\\vect{v}$.  This arrow represents the\n  vector $\\vect{u}+\\vect{v}$.\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, purple](0,0) -- node[above left]{$\\vect{u}+\\vect{v}$}(1.5,1);\n      \\draw[->, thick, blue](0,0) -- node[below]{$\\vect{u}$} (0.75,0);\n      \\draw[->, thick, red](0.75,0) -- node[below right]{$\\vect{v}$} (1.5,1);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{proposition}\n\n\\begin{example}{Commutative law}{commutative-law-geometric}\n  Let $\\vect{u}$ and $\\vect{v}$ be two vectors. Using the geometry of\n  vector addition, explain why $\\vect{u}+\\vect{v} = \\vect{v} + \\vect{u}$.\n\\end{example}\n\n\\begin{solution}\n  In the following diagram, the vectors $\\vect{u}$ and $\\vect{v}$ form\n  a parallelogram. Therefore, whether we line up the tail of\n  $\\vect{u}$ with the tip of $\\vect{v}$ or vice versa, we obtain the\n  same vector, which is both $\\vect{u}+\\vect{v}$ and\n  $\\vect{v}+\\vect{u}$.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2.5,rotate=-20]\n      \\draw[->, thick, purple](0,0) -- node[above]{$\\vect{v}+\\vect{u}$}\n      node[below]{$\\vect{u}+\\vect{v}$} (1.5,1);\n      \\draw[->, thick, blue](0,0) -- node[below]{$\\vect{u}$} (0.75,0);\n      \\draw[->, thick, red](0.75,0) -- node[below]{$\\vect{v}$} (1.5,1);\n      \\draw[->, thick, blue](0.75,1) -- node[above]{$\\vect{u}$} (1.5,1);\n      \\draw[->, thick, red](0,0) -- node[above]{$\\vect{v}$} (0.75,1);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{solution}\n\n\\begin{definition}{Negative}{vector-negative}\n  The \\textbf{negative}%\n  \\index{vector!negative}%\n  \\index{negative!of a vector} of a vector\n  $\\vect{u}=\\begin{mymatrix}{c}\n    u_1 \\\\\n    \\vdots \\\\\n    u_n\n  \\end{mymatrix}\\in\\R^n$ is defined by\n  $-\\vect{u} = \\begin{mymatrix}{c}\n    -u_1 \\\\\n    \\vdots \\\\\n    -u_n\n  \\end{mymatrix}$.\n\\end{definition}\n\nGeometrically, the vector $-\\vect{u}$ has the same magnitude as\n$\\vect{u}$, but the opposite direction.\n\\begin{center}\n  \\begin{tikzpicture}\n    \\draw[->, thick, blue](0,0) -- node[above]{$\\vect{u}$} +(2,1);\n    \\draw[->, thick, blue](5,1) -- node[above]{$-\\vect{u}$} +(-2,-1);\n  \\end{tikzpicture}\n\\end{center}\n\nTo define the \\textbf{subtraction}%\n\\index{vector!subtraction}%\n\\index{subtraction!of vectors} of two vectors, we simply regard\n$\\vect{u}-\\vect{v}$ as an abbreviation for $\\vect{u} + (-\\vect{v})$,\nexactly as we do with real numbers. Algebraically, this just amounts\nto componentwise subtraction:\n\\begin{equation*}\n  \\begin{mymatrix}{c}\n    u_1 \\\\\n    \\vdots \\\\\n    u_n\n  \\end{mymatrix} - \\begin{mymatrix}{c}\n    v_1 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{mymatrix}\n  = \\begin{mymatrix}{c}\n    u_1-v_1 \\\\\n    \\vdots \\\\\n    u_n-v_n\n  \\end{mymatrix}.\n\\end{equation*}\n\nThe following example illustrates how to subtract vectors\ngeometrically.\n\n\\begin{example}{Graphing vector addition}{graphing-vector-addition}\n  Consider the following picture of vectors $\\vect{u}$ and $\\vect{v}$.\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, blue] (0,0) -- node[above]{$\\vect{u}$} (2,1);\n      \\draw[->, thick, red] (4,1) -- node[above]{$\\vect{v}$} (5,0.5);\n    \\end{tikzpicture}\n  \\end{center}\n\n  Sketch a picture of $\\vect{u}+\\vect{v}$ and $\\vect{u}-\\vect{v}$.\n\\end{example}\n\n\\begin{solution}\n  We will first sketch $\\vect{u}+\\vect{v}$. Begin by drawing $\\vect{u}$\n  and then at the point of $\\vect{u}$, place the tail of $\\vect{v}$ as\n  shown. Then $\\vect{u}+\\vect{v}$ is the vector which results from\n  drawing a vector from the tail of $\\vect{u}$ to the tip of $\\vect{v}$.\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, blue] (0,0) -- node[above]{$\\vect{u}$} (2,1);\n      \\draw[->, thick, red] (2,1) -- node[above]{$\\vect{v}$} (3,0.5);\n      \\draw[->, thick, purple](0,0) -- node[below]{$\\vect{u}+\\vect{v}$} (3,0.5);\n    \\end{tikzpicture}\n  \\end{center}\n\n  Next consider $\\vect{u}-\\vect{v}$. This means $\\vect{u}+(-\\vect{v}\n  )$. From the above geometric description of vector addition, $-\\vect{v}$\n  is the vector which has the same length but which points in the\n  opposite direction to $\\vect{v}$. Here is a picture of $-\\vect{v}$\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[<-, thick, red] (4,1) -- node[above]{$-\\vect{v}$} (5,0.5);\n    \\end{tikzpicture}\n  \\end{center}\n\n  The following picture fully represents $\\vect{u}-\\vect{v}$:\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, blue](0,0) -- node[above]{$\\vect{u}$} (2,1);\n      \\draw[<-, thick, red] (1,1.5) -- node[above]{$-\\vect{v}$} (2,1);\n      \\draw[->, thick, purple](0,0) -- node[left]{$\\vect{u}-\\vect{v}$}(1,1.5);\n    \\end{tikzpicture}\n  \\end{center}\n\n  Given any two vectors $\\vect{u}$ and $\\vect{v}$ one can create a\n  parallelogram with sides these vectors and diagonals\n  $\\vect{u}+\\vect{v}$ and $\\vect{v}-\\vect{u}$:\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[->, thick, blue](-1,0.5) -- node[above]{$\\vect{u}$} (1,1.5);\n      \\draw[->, thick, red] (1,1.5) -- node[above]{$\\vect{v}$} (2,1);\n      \\draw[->, thick, purple](0,0) -- node[left, near start]{$\\vect{u}-\\vect{v}$}(1,1.5);\n      \\draw[->, thick, blue](0,0) -- node[below]{$\\vect{u}$} (2,1);\n      \\draw[->, thick, red](-1,0.5) -- node[below]{$\\vect{v}$} (0,0);\n      \\draw[->, thick, purple](-1,0.5) -- node[above, near end]{$\\vect{u}+\\vect{v}$} (2,1);\n    \\end{tikzpicture}\n  \\end{center}\n\\end{solution}\n\nAddition of vectors satisfies some important properties which are\noutlined in the following proposition.  Recall that $\\vect{0}$ is the\n\\textbf{zero vector}%\n\\index{zero vector}%\n\\index{vector!zero vector}, the vector from $\\R^n$ in which all\ncomponents are equal to $0$.\n\n\\begin{proposition}{Properties of vector addition}{properties-vector-addition}\n  The following properties hold for vectors\n  $\\vect{u},\\vect{v},\\vect{w}\\in\\R^n$.%\n  \\index{vector!properties of addition}%\n  \\index{vector!addition!properties}%\n  \\index{properties of addition!vectors}\n  \\begin{itemize}\n  \\item The commutative law of addition%\n    \\index{commutative law!of addition}%\n    \\index{vector!commutative law of addition}%\n    \\begin{equation*}\n      \\vect{u}+\\vect{v}=\\vect{v}+\\vect{u}.\n    \\end{equation*}\n  \\item The associative law of addition\n    \\index{associative law!of addition}%\n    \\index{vector!associative law of addition}%\n    \\begin{equation*}\n      (\\vect{u}+\\vect{v})+\\vect{w} = \\vect{u}+(\\vect{v}+\\vect{w}).\n    \\end{equation*}\n  \\item The existence of an additive unit%\n    \\index{additive unit}%\n    \\index{unit!of addition|see{additive unit}}%\n    \\index{vector!additive unit}%\n    \\begin{equation*}\n      \\vect{u}+\\vect{0}=\\vect{u}.\n    \\end{equation*}\n  \\item The existence of an additive inverse\n    \\index{additive inverse}%\n    \\index{vector!additive inverse}%\n    \\index{inverse!additive}%\n    \\begin{equation*}\n      \\vect{u}+(-\\vect{u}) =\\vect{0}.\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n\n", "meta": {"hexsha": "fc622d261cf95c33e4610f49ab19e38ded9caf31", "size": 8476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/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/content/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/content/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": 33.904, "max_line_length": 91, "alphanum_fraction": 0.6160924965, "num_tokens": 3106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8856314828740729, "lm_q1q2_score": 0.7911429289181905}}
{"text": "\\section{Exercises in Multivariate Random Variables}\\label{S:xsMultivariateRVs}\n\\begin{ExerciseList}\n%question 9 (cts )\n\\Exercise\nFind the probability that none of the three bulbs in a traffic signal, that are assumed to have independent life-times (i.e., the time during which they are operational), need to be replaced during the first 1200 hours of operation if the length of time before a single bulb needs to  be replaced is a continuous random variable $X$ with density\n$$f(x)\\;=\\;\\begin{cases}6\\left(0.25-(x-1.5)^2\\right)&1<x<2\\\\0&\\textrm{otherwise}\\end{cases}\\enspace.$$\nNote: $X$ is measured in multiples of 1000 hours.\n\\Answer\nThe probability that  \\emph{one}  light bulb doesn't need to be replaced in  1200 hours is:\n\\ba{\\P(X>1.2)&\\;=\\;1-\\P(X<1.2)\\\\[3pt]\n&=\\;1\\;-\\;\\int^{1.2}_1 6 (0.25-(x-1.5)^2)\\,dx\\\\[3pt]\n&=\\;1\\;-\\;\\int^{1.2}_1 6(0.25-x^2+3x-2.25)\\,dx\\\\[3pt]\n&=\\;1\\;-\\;\\int^{1.2}_1 (-6x^2+18x-12)\\,dx\\\\[3pt]\n&=\\;1\\;-\\;\\left[-2x^3+9x^2-12x\\right]^{1.2}_1\\\\[3pt]\n&=\\;1-0.1040\\\\[3pt]\n&\\;=\\;0.8960}\nAssuming  that   the three light bulbs function  independently of  each\nother, the probability that none of them need to be replaced in the\nfirst 1200 hours is\n$$\\P(\\{X_1>1.2\\}\\cap\\{X_2>1.2\\}\\cap\\{X_3>1.2\\}\\;=\\;0.8960^3\\;=\\;\n0.7193$$\nwhere $X_i$ is the length of time that bulb $i$ lasts.\n\n\\Exercise\nLet $(X,Y)$ be a continuous \\rv~with joint probability density function (JPDF)\n\\[\nf_{X,Y}(x,y)\n=\n\\begin{cases}\na (x^2+y) & \\text{ if } 0 < x < 1 \\text{ and } 0 < y < 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\nFind the following:\n\\be\n\\item~the normalizing constant $a$ which will ensure $\\P(\\Omega) = \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx dy = 1$\n\\item~$f_X(x) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy$ called the marginal probability density function (MPDF) of $X$\n\\item~$f_Y(y) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx$ called the marginal probability density function (MPDF) of $Y$\n\\item Check if $f_X(x)f_Y(y)=f_{X,Y}(x,y)$ for every $(x,y)$ and decide whether $X$ and $Y$ are independent random variables.  {Hint: $X$ and $Y$ are said to be independent if $f_X(x)f_Y(y)=f_{X,Y}(x,y)$ for every $(x,y)$.}\n\\item~$F_{X,Y}(x,y)$, the joint cumulative distribution function (JCDF) of $(X,Y)$ for any $(x,y) \\in (0,1) \\times (0,1)$ \n\\item~the probability that $X > 0.5$ and $Y<0.6$, i.e., $\\P(X>0.5,Y<0.6)$\n\\item~$E(X)$, the expectation of $X$ or the first moment of $X$\n\\item~$E(Y)$, the expectation of $Y$ or the first moment of $Y$\n\\item~$E(XY)$, the expectation of $XY$\n\\item~$\\cv(X,Y)=E(XY)-E(X)E(Y)$, the covariance of $X$ and $Y$.\n\\ee\n\n\\Answer\n~\\\\\n\\be\n\\item~To find $a$ we simply set $1=\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx dy$ and solve for $a$ as follows:\n\\begin{align*}\n1\n&=\n\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx dy = \\int_{0}^{1}\\int_{0}^{1} a(x^2+y) dx dy\\\\\n&=\na\\int_{0}^{1}\\int_{0}^{1} (x^2+y) dx dy = a\\int_{0}^{1} \\left[ \\frac{1}{3}x^3+yx \\right]_{x=0^1} dy\\\\\n&=\na\\int_{0}^{1} \\left( \\frac{1}{3}+y - 0 \\right) dy = a \\left[ \\frac{y}{3}+\\frac{1}{2}y^2 \\right]_{y=0}^{1}\\\\\n&=\na \\left( 0-\\left(\\frac{1}{3}+\\frac{1}{2}1^2\\right) \\right) = a \\left( \\frac{1}{3}+\\frac{1}{2} \\right)\\\\\n&=\na \\left( \\frac{5}{6} \\right)\n\\end{align*}\nTherefore $a=6/5$ and the joint PDF is\n\\[\nf_{X,Y}(x,y)\n=\n\\begin{cases}\n\\frac{6}{5} (x^2+y) & \\text{ if } 0 < x < 1 \\text{ and } 0 < y < 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\n\\item~First compute the marginal PDF $f_X(x)$ for any $x \\in (0,1)$ by integrating over $y$\n\\begin{align*}\nf_X(x) \n&= \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy\n= \\int_0^1 \\frac{6}{5} (x^2+y) dy \n= \\left[ \\frac{6}{5} (yx^2+y^2/2) \\right]_{y=0}^1\\\\\n&= \\frac{6}{5} \\left((1 \\times x^2 + 1^2/2) - 0 \\right)\n= \\frac{6}{5} \\left( x^2 + \\frac{1}{2} \\right)\n\\end{align*}\nFinally, the marginal PDF of the RV $X$ in the first component of the \\rv~$(X,Y)$ is\n\\[\nf_{X}(x)\n=\n\\begin{cases}\n\\frac{6}{5} \\left( x^2 + \\frac{1}{2} \\right) & \\text{ if } 0 < x < 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\n\\item~Similarly, the marginal PDF $f_Y(y)$ for any $y \\in (0,1)$ by integrating over $x$ is \n\\[\nf_Y(y)=\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx = \\int_0^1 \\frac{6}{5}(x^2+y) dx = \\frac{6}{5} \\left[ x^3/3+yx\\right]_{x=0}^1 = \\frac{6}{5}(y+1/3).\n\\]\nFinally, the marginal PDF of the RV $Y$ in the second component of the \\rv~$(X,Y)$ is\n\\[\nf_{Y}(y)\n=\n\\begin{cases}\n\\frac{6}{5} \\left( y + \\frac{1}{3} \\right) & \\text{ if } 0 < y < 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\n\\item The product of marginal PDFs of $X$ and $Y$ does not equal the joint PDF of $(X,Y)$ for values of $(x,y) \\in (0,1)^2$\n\\[\nf_X(x)f_Y(y) = \\frac{6}{5} \\frac{6}{5} \\left( y + \\frac{1}{3} \\right) \\left( x^2 + \\frac{1}{2} \\right) = \\frac{6}{25} \\left( 6 x^2y+2x^2+3y+1\\right) \\neq \\frac{6}{5}(x^2+y) = f_{X,Y}(x,y)\n\\]\nTherefore $X$ and $Y$ are not independent random variables (they are dependent!).\n\\item~The joint distribution function $F_{X,Y}(x,y)$ for any $(x,y) \\in (0,1)^2$ is\n\\begin{align*}\nF_{X,Y}(x,y) \n&= \\int_{-\\infty}^{y} \\int_{-\\infty}^{x} f_{X,Y}(u,v) du dv\n= \\int_{0}^{y} \\int_{0}^{x} \\frac{6}{5} (u^2+v) du dv\n= \\frac{6}{5} \\int_{0}^{y} \\left[ \\frac{u^3}{3}+vu) \\right]_{u=0}^{x} dv\\\\\n&= \\frac{6}{5} \\int_{0}^{y} \\left( \\frac{x^3}{3}+vx - 0 \\right) dv\n= \\frac{6}{5} \\left[ \\frac{x^3v}{3}+\\frac{v^2x}{2} \\right]_{v=0}^{y}\n= \\frac{6}{5} \\left( \\frac{x^3y}{3}+\\frac{y^2x}{2} - 0 \\right)\\\\\n&= \\frac{6}{5} \\left( \\frac{x^3y}{3}+\\frac{y^2x}{2} - 0 \\right)\n\\end{align*}\n\\item~\n\\begin{align*}\n\\P(X>0.5,Y<0.6) \n&= \\int_{-\\infty}^{0.6} \\int_{0.5}^{\\infty} f_{X,Y}(x,y) dx dy\n= \\int_{0}^{0.6} \\int_{0.5}^{1} \\frac{6}{5} (x^2+y) dx dy\\\\\n&= \\frac{6}{5} \\int_{0}^{0.6} \\left[ \\frac{x^3}{3}+yx \\right]_{x=0.5}^{1} dy\n= \\frac{6}{5} \\int_{0}^{0.6} \\left(\\frac{7}{24} + \\frac{y}{2} \\right) dy\\\\\n&= \\frac{6}{5} \\left[\\frac{7}{24}y + \\frac{y^2}{2} \\right]_{y=0}^{0.6}\n= \\frac{6}{5} \\left(\\frac{7}{24}\\times \\frac{6}{10} + \\frac{36}{400} \\right)\n=0.318\n\\end{align*}\n\\item~\n\\begin{align*}\nE(X) \n&= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} x f_{X,Y}(x,y) dx dy\\\\\n&=\\frac{6}{5} \\int_{0}^{1} \\int_{0}^{1}  x \\left( x^2 + y \\right) dx dy\n=\\frac{6}{5} \\int_{0}^{1} \\int_{0}^{1}  \\left( x^3 + xy \\right) dx dy\n= \\frac{6}{5} \\int_{0}^{1} \\left[ \\frac{x^4}{4} + \\frac{1}{2}x^2y\\right]_{x=0}^{1} dy\\\\\n&=\\frac{6}{5} \\int_{0}^{1} \\left( \\frac{1}{4} + \\frac{y}{2} - 0 - 0\\right) dy\n= \\frac{6}{5} \\left[ \\frac{y}{4} + \\frac{y^2}{4} \\right]_{y=0}^{1} \n= \\frac{6}{5} \\left(\\frac{1}{4} + \\frac{1}{4} - 0 - 0 \\right) = \\frac{6}{5}\\times \\frac{1}{2}=\\frac{3}{5}\n\\end{align*}\n\\item~\n\\begin{align*}\nE(Y) \n&= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} y f_{X,Y}(x,y) dx dy\\\\\n&= \\int_{0}^{1} \\int_{0}^{1} y \\frac{6}{5} \\left( x^2 + y \\right) dx dy\n= \\frac{6}{5} \\int_{0}^{1} \\int_{0}^{1}  \\left( x^2y + y^2 \\right) dx dy\n= \\frac{6}{5} \\int_{0}^{1} \\left[ \\frac{x^3y}{3} + y^2x \\right]_{x=0}^{1} dy\\\\\n&= \\frac{6}{5} \\int_{0}^{1} \\left( \\frac{y}{3} + y^2 -0-0\\right) dy\n= \\frac{6}{5} \\left[ \\frac{y^2}{6} + \\frac{y^3}{3} \\right]_{y=0}^{1} \n= \\frac{6}{5} \\left( \\frac{1}{6} + \\frac{1}{3} + - 0 -0 \\right) = \\frac{6}{5} \\times \\frac{3}{6}=\\frac{3}{5}\n\\end{align*}\n\\item~\n\\begin{align*}\nE(XY) \n&= \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} xy f_{X,Y}(x,y) dx dy\\\\\n&=\\frac{6}{5} \\int_{0}^{1} \\int_{0}^{1}  xy \\left( x^2 + y \\right) dx dy\n=\\frac{6}{5} \\int_{0}^{1} \\int_{0}^{1} x^3y+xy^2 dx dy\n=\\frac{6}{5} \\int_{0}^{1} \\left[ \\frac{x^4}{4}y+\\frac{x^2 y^2}{2} \\right]_{x=0}^1 dy\\\\\n&=\\frac{6}{5} \\int_{0}^{1} \\left( \\frac{y}{4} + \\frac{y^2}{2} -0-0\\right)dy\n=\\frac{6}{5} \\left[ \\frac{y^2}{8} + \\frac{y^3}{6}\\right]_{y=0}^1 \n=\\frac{6}{5} \\left(\\frac{1}{8} + \\frac{1}{6}-0-0\\right)\\\\\n&=\\frac{6}{5} \\left(\\frac{3}{24}+\\frac{4}{24}\\right)=\\frac{6}{5}\\times\\frac{7}{24}=\\frac{7}{20}\n\\end{align*}\n\\item~\n\\[\n\\cv(X,Y) = E(XY)-E(X)E(Y) = \\frac{7}{20}-\\left(\\frac{3}{5} \\times \\frac{3}{5} \\right) = \\frac{7}{20}-\\frac{9}{25} = \\frac{35}{100}-\\frac{36}{100} = -\\frac{1}{100}\n\\]\n\\ee\n\n\\Exercise\nLogs are milled to have a width of $\\mu$.\nThe actual width of a randomly selected item is $X$.\nIf $X$ is a $\\normal(\\mu,\\sigma^2)$ random variable then find the probability density function of the {\\em squared-error} of the milling process,\n\\[ Y\\,=\\, (X-\\mu)^2\\,.\\]\n\\Answer\nNote that $Y= (X-\\mu)^2$ is not on-to-one so it is better to use the direct method by differentiating the distribution function  of $Y$, $F_Y(y)$,  to obtain $f_Y(y)$.\n\nIf $y\\geqslant 0$,\n\\begin{align*}\n F_Y(y)\\;=&\\; \\P(Y \\leqslant y) \\\\[3pt]\n \\;=&\\;  \\P( (X-\\mu)^2 \\leqslant y) \\\\[3pt]\n \\;=&\\; \\P(-\\sqrt y \\leqslant X-\\mu \\leqslant \\sqrt y)\\\\[3pt]\n \\;=&\\; \\P(\\mu -\\sqrt y \\leqslant X  \\leqslant \\mu + \\sqrt y)\\\\[3pt]\n\\;=&\\; F_X( \\mu + \\sqrt y) \\,-\\, F_X( \\mu + \\sqrt y)\n\\end{align*}\n\nDifferentiating this expression gives\n\\begin{align*}\nf_Y(y) \\;=&\\; \\frac{d}{dy} \\left(F_X( \\mu + \\sqrt y) \\,-\\, F_X( \\mu - \\sqrt y)  \\right) \\\\[3pt]\n\\;=&\\;\\frac{1}{2} y^{-\\frac{1}{2}} \\, f_X (\\mu + \\sqrt y ) \\,- \\, \\left( -\\frac{1}{2} y^{-\\frac{1}{2}} \\right)\\, f_X (\\mu - \\sqrt y ) \\\\[3pt]\n\\;=&\\;\\frac{1}{2 \\sqrt y } \\left(  f_X (\\mu + \\sqrt y )  + f_X (\\mu - \\sqrt y )  \\right)\n\\end{align*}\n\nNote: If $y<0$ then $f_Y(y) = 0$  since  $F_Y(y)=0$ in this case.\n\n\\Exercise\nLet $(X,Y)$ be a discrete random vector (\\rv) with support:\n\\[\n\\mathcal{S}_{X,Y} = \\{(0,0),(0,1),(1,0),(1,1)\\} \\enspace .\n\\]\nLet its joint probability mass function (JPMF) be:\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\n\\frac{1}{4} & \\text{ if } (x,y)=(0,0)\\\\\n\\frac{1}{4} & \\text{ if } (x,y)=(0,1)\\\\\n\\frac{1}{4} & \\text{ if } (x,y)=(1,0)\\\\\n\\frac{1}{4} & \\text{ if } (x,y)=(1,1)\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\nAre $X$ and $Y$ independent? \n\\Answer\n~\\\\\nFirst derive the marginal PMF of $X$ and $Y$ and then check if the JPMF is the product of the marginal PMFs.\n\\[\nf_X(0) = \\sum_{y \\in \\mathcal{S}_{X,Y}} f_{X,Y}(0,y) = f_{X,Y}(0,0) + f_{X,Y}(0,1) = \\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2}\n\\]\nand\n\\[\nf_X(1) = \\sum_{y \\in \\mathcal{S}_{X,Y}} f_{X,Y}(1,y) = f_{X,Y}(1,0) + f_{X,Y}(1,1) = \\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2}\n\\]\nThus,\n\\[\nf_{X}(x) = \n\\begin{cases}\n\\frac{1}{2} & \\text{ if } x = 0\\\\\n\\frac{1}{2} & \\text{ if } x = 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\nSimilarly,\n\\[\nf_{Y}(y) = \n\\begin{cases}\n\\sum_{x \\in \\mathcal{S}_{X,Y}} f_{X,Y}(x,0)=f_{X,Y}(0,0) + f_{X,Y}(1,0) = \\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2} & \\text{ if } y = 0\\\\\n\\sum_{x \\in \\mathcal{S}_{X,Y}} f_{X,Y}(x,1)=f_{X,Y}(0,1) + f_{X,Y}(1,1) = \\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2} & \\text{ if } y = 1\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\nFinally, the product of $f_X(x)$ and $f_Y(y)$ is\n\\[\nf_{X}(x) \\times f_{Y}(y) = \n\\begin{cases}\n\\frac{1}{2} \\times \\frac{1}{2}=\\frac{1}{4} & \\text{ if } (x,y)=(0,0)\\\\\n\\frac{1}{2} \\times \\frac{1}{2}=\\frac{1}{4} & \\text{ if } (x,y)=(0,1)\\\\\n\\frac{1}{2} \\times \\frac{1}{2}=\\frac{1}{4} & \\text{ if } (x,y)=(1,0)\\\\\n\\frac{1}{2} \\times \\frac{1}{2}=\\frac{1}{4} & \\text{ if } (x,y)=(1,1)\\\\\n0 & \\text{ otherwise} \\enspace .\n\\end{cases}\n\\]\nwhich in turn is equal to the JPMF $f_{X,Y}(x,y)$ in the question.  Therefore we have shown that the component RVs $X$ and $Y$ in the \\rv~$(X,Y)$ are indeed indepedent.\n\n\\Exercise\nA semiconductor product consists of three layers that are fabricated independently.  \nIf the variances in thickness of the first, second and third third layers are $25$, $40$ and $30$ nanometers squared, what is the variance of the thickness of the final product? \n\\Answer\n~\\\\\nLet $X_1$, $X_2$, $X_3$ be independent RVs that denote the thickness of the first, second and third layer, respectively.  Let $X$ denote the thickness of the final product.  Then\n\\[\nX= X_1+X_2+X_3\n\\]\nBy the property that $V\\left(\\sum_{i=1}^n a_i X_i\\right) = \\sum_{i=1}^n a_i^2 V(X_i)$, Variance of $X$ is\n\\[\nV(X) = 1^2 V(X_1) + 1^2 V(X_2) + 1^2 V(X_3) = 25+40+30 = 95 nm^2 \\enspace .\n\\] \nThis shows how the variance in each layer is propagated to the variance of the final product.\n\n\\Exercise\nFind the covariance for the discrete \\rv~$(X,Y)$ with joint probability mass function\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\n0.2 & \\text{ if } (x,y)=(0,0)\\\\\n0.1 & \\text{ if } (x,y)=(1,1)\\\\\n0.1 & \\text{ if } (x,y)=(1,2)\\\\\n0.1 & \\text{ if } (x,y)=(2,1)\\\\\n0.1 & \\text{ if } (x,y)=(2,2)\\\\\n0.4 & \\text{ if } (x,y)=(3,3)\\\\\n0 & \\text{ otherwise } \\enspace .\n\\end{cases}\n\\]\n[Hint: Recall that $\\cv(X,Y)=E(XY)-E(X)E(Y)$]\n\\Answer\n~\\\\\nFind $E(XY)$, $E(X)$ and $E(Y)$ to get $\\cv(X,Y)=E(XY)-E(X)E(Y)$ as follows:\n\\begin{multline*}\nE(XY) = \\sum_{(x,y) \\in \\mathcal{S}_{X,Y}} x \\times y \\times f_{X,Y}(x,y) \\\\\n= 0 \\times 0 \\times 0.2 + 1 \\times 1 \\times 0.1+ 1 \\times 2 \\times 0.1 + 2 \\times 1 \\times 0.1 + 2 \\times 2 \\times 0.1 + 3 \\times 3 \\times 0.4 = 4.5\n\\end{multline*}\n\\begin{multline*}\nE((X,Y)) = \\sum_{(x,y) \\in \\mathcal{S}_{X,Y}} (x , y) \\times f_{X,Y}(x,y) \\\\\n= (0 , 0) \\times 0.2 + (1 , 1) \\times 0.1 + (1 , 2) \\times 0.1 + (2 , 1) \\times 0.1 + (2 , 2) \\times 0.1 + (3 , 3) \\times 0.4\\\\= (0,0)+(0.1,0.1)+(0.1,0.2)+(0.2,0.1)+(0.2,0.2)+(1.2,1.2) \\\\\n= (1.8,1.8) \n\\end{multline*}\nSince addition is component-wise $E((X,Y))=(E(X),E(Y))$ and therefore $E(X)=E(Y)=1.8$.\n\nAlternatively, you can first find the marginal PMFs $f_X$ and $f_Y$ for $X$ and $Y$ and then take the expectations $E(X)=\\sum_x x \\times f_X(x)$ and $E(Y)=\\sum_y y \\times f_Y(y)$.\n\nFinally, \n\\[\n\\cv(X,Y) = E(XY)-E(X)E(Y) = 4.5 - 1.8^2 = 1.26 \\enspace .\n\\]\n\n\\Exercise\nConsider two random variables (RVs) $X$ and $Y$ having marginal distribution functions\n\\[\nF_X(x) =\n\\begin{cases}\n0 & \\text{ if } x < 1\\\\\n\\frac{1}{2} & \\text{ if } 1 \\leq x < 2\\\\\n1 & \\text{ if } x \\geq 2\\\\\n\\end{cases}\n\\] \n\\[\nF_Y(y) =\n\\begin{cases}\n0 & \\text{ if } y < 0\\\\\n1-\\frac{1}{2}e^{-y}-\\frac{1}{2}e^{-2y} & \\text{ if } y \\geq 0\\\\\n\\end{cases}\n\\]\nIf $X$ and $Y$ are independent, what is their joint distribution function $F_{X,Y}(x,y)$? [Hint: you need to express $F_{X,Y}(x,y)$ for any $(x,y) \\in \\Rz^2$.]\n\\Answer\n~\\\\\nSince $X$ and $Y$ are independent, $F_{X,Y}(x,y) = F_X(x) F_Y(y)$ for all $(x,y) \\in \\Rz^2$, and we get:\n\\[\nF_{X,Y}(x,y) = \n\\begin{cases}\n0 & \\text{ if } x < 1 \\text{ or } y < 0\\\\\n\\frac{1}{2}\\left(1-\\frac{1}{2}e^{-y}-\\frac{1}{2}e^{-2y}\\right) & \\text{ if } 1 \\leq x < 2 \\text{ and } y \\geq 0\\\\\n1-\\frac{1}{2}e^{-y}-\\frac{1}{2}e^{-2y} & \\text{ if } x \\geq 2 \\text{ and } y \\geq 0\n\\end{cases}\n\\]\n{\\small\nYou can arrive at the answer by partitioning $x$-axis into $(-\\infty,1)$, $[1,2)$ and $[2,\\infty)$ where $F_X(x)$ takes distinct values.  Similarly, partition the $y$-axis into  $(-\\infty,0)$ and $[0,\\infty)$ where $F_Y(y)$ takes distinct values.  \nNow $(x,y)$ can take values in one of these $3 \\times 2=6$ partitions of the $x \\times y$ plane as follows (make a picture!):\n\\[\n(-\\infty,1) \\times (-\\infty,0), \\,\n[1,2) \\times (-\\infty,0), \\,\n[2,\\infty) \\times (-\\infty,0), \\,\n(-\\infty,1) \\times [0,\\infty), \\,\n[1,2) \\times [0,\\infty), \\,\n[2,\\infty) \\times [0,\\infty) \\enspace .\n\\]\nNow work out what $F_{X,Y}(x,y) = F_X(x) F_Y(y)$ is for $(x,y)$ in each of the above six partitions of the plane and you will get the the expression for $F_{X,Y}(x,y)$ given above.\n}\n\n\\Exercise\nLet $(X,Y)$ be a continuous \\rv~with joint probability density function (JPDF):\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\ne^{-x} & \\text{ if } x \\in [0,\\infty) \\text{ and }  y \\in [2,3]\\\\\n0 & \\text{otherwise} \\enspace .\n\\end{cases}\n\\]\nAre $X$ and $Y$ independent?\n\\Answer\n~\\\\\nFirst obtain marginal PDF of $Y$.  If $y \\in [2,3]$ then\n\\[\nf_Y(y) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx = \\int_0^{\\infty} e^{-x} dx = \\left[ -e^{-x} \\right]_0^{\\infty} = 0 - (-1)=1 \\enspace .\n\\]\nTherefore,\n\\[\nf_Y(y) =\n\\begin{cases}\n1 & \\text{ if } y \\in [2,3]\\\\\n0 & \\text{otherwise} \\enspace .\n\\end{cases}\n\\]\nNow, obtain the marginal PDF of $X$.  If $x \\in [0,\\infty)$ then\n\\[\nf_X(x) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy = \\int_2^3 e^{-x} dy  = e^{-x} \\int_2^3 1 dy = e^{-x} \\left[ y \\right]_2^3 = e^{-x} (3-2) = e^{-x} \\enspace .\n\\]\nTherefore,\n\\[\nf_X(x) =\n\\begin{cases}\ne^{-x} & \\text{ if } x \\in [0,\\infty)\\\\\n0 & \\text{otherwise} \\enspace .\n\\end{cases}\n\\]\nFinally, verifying that $f_{X,Y}(x,y) = f_X(x) f_Y(y)$ for any $(x,y) \\in \\Rz^2$ is done case by case.  \nDraw a picture on the plane to work out the cases from the distinct expressions taken by $f_{X,Y}(x,y)$.  \nThere are only two cases to consider (when $f_{X,Y}(x,y)$ takes zero values and when $f_{X,Y}(x,y)$ takes non-zero values):\n\\be\n\\item~If $x \\notin [0,\\infty)$ or $y \\notin [2,3]$ then $f_X(x)f_Y(y)=0=f_{X,Y}(x,y)$\n\\item~If $x \\in [0,\\infty)$ and $y \\in [2,3]$ then $f_X(x)f_Y(y)=e^{-x} \\times 1=e^{-x}=f_{X,Y}(x,y)$.\n\\ee\nThus, $X$ and $Y$ are independent.\n\n\\Exercise\nIn an electronic assembly, let the RVs $X_1,X_2,X_3,X_4$ denote the lifetimes of four components in hours.  \nSuppose that the JPDF of these variables is\n\\begin{align*}\n~& f_{X_1,X_2,X_3,X_4}(x_1,x_2,x_3,x_4) \\\\\n&\\qquad= \n\\begin{cases}\n9 \\times 10^{-12} e^{-0.001 x_1 - 0.002 x_2 - 0.0015 x_3 - 0.003 x_4} & \\text{ if } x_1 \\geq 0, x_2 \\geq 0, x_3 \\geq 0, x_4 \\geq 0\\\\\n0 & \\text{ otherwise} \\enspace.\n\\end{cases}\n\\end{align*}\nWhat is the probability that the device operates for more than 1000 hours without any failures? [Hint: The requested probability is $\\P(X_1>1000,X_2>1000,X_3>1000,X_4>1000)$ since each one of the four components of the device must not fail before 1000 hours.]\n\\Answer\n~\\\\\n\\begin{multline*}\n\\P(X_1>1000,X_2>1000,X_3>1000,X_4>1000) \\\\\n= \\int_{1000}^{\\infty} \\int_{1000}^{\\infty} \\int_{1000}^{\\infty} \\int_{1000}^{\\infty} 9 \\times 10^{-12} e^{-0.001 x_1 - 0.002 x_2 - 0.0015 x_3 - 0.003 x_4} dx_1 dx_2 dx_3 dx_4\\\\\n= 9 \\times 10^{-12} \\int_{1000}^{\\infty} \\int_{1000}^{\\infty} \\int_{1000}^{\\infty} \\int_{1000}^{\\infty}  e^{-0.001 x_1} e^{- 0.002 x_2} e^{- 0.0015 x_3} e^{- 0.003 x_4} dx_1 dx_2 dx_3 dx_4\\\\\n=  9 \\times 10^{-12} \\int_{1000}^{\\infty} e^{-0.001 x_1} \\int_{1000}^{\\infty} e^{- 0.002 x_2} \\int_{1000}^{\\infty} e^{- 0.0015 x_3} \\int_{1000}^{\\infty} e^{- 0.003 x_4} dx_4 dx_3 dx_2 dx_1\\\\\n\\end{multline*}\nSince\n\\[\n\\int_{1000}^{\\infty} e^{- a x_i} dx_i = \\left[ \\frac{e^{-a x_i}}{-a} \\right]_{1000}^{\\infty} = 0 + \\frac{e^{-1000\\times a}}{a} \\enspace ,\n\\]\nthe above quadruply iterated integral becomes\n\\begin{align*}\n&~ 9 \\times 10^{-12} \\times \\frac{e^{-1000 \\times 0.001}}{0.001} \\times \\frac{e^{-1000 \\times 0.002}}{0.002} \n\\times \\frac{e^{-1000 \\times 0.0015}}{0.0015} \\times \\frac{e^{-1000 \\times 0.003}}{0.003}\\\\\n&= 9 \\times 10^{-12} \\times \\frac{1000}{1} \\times \\frac{1000}{2} \\times \\frac{1000}{1.5} \\times \\frac{1000}{3} \\times\ne^{-1} \\times e^{-2} \\times e^{-1.5} \\times e^{-3} \\\\\n&= 9 \\times 10^{-12} \\times \\frac{1}{9} \\times 10^{12} \\times e^{-7.5} = e^{-7.5} \\approxeq 0.00055 \\enspace .\n\\end{align*}\n\n\\Exercise\nSuppose the RVs $Y_1$, $Y_2$ and $Y_3$ represent the thickness in micrometers of a substrate, an active layer, and a coating layer of a chemical product.  \nAssume $Y_1$, $Y_2$ and $Y_3$ are $\\normal(10000,250^2)$, $\\normal(1000,20^2)$ and $\\normal(80,4^2)$ RVs, respectively.  \nFurther suppose that they are independent.  \nThe required specifications for the thickness of the substrate, active layer and coating layer are $[9500,10500]$, $[950,1050]$ and $[75,85]$, respectively.  \nWhat proportion of chemical products meets all thickness specifications? [Hint: this is just $\\P(9500<Y_1<10500,950<Y_2<1050,75<Y_3<85)$]  Which one of the three thicknesses has the least probability of meeting specifications?   \n\\Answer\n~\\\\\nDue to independence of $Y_1$, $Y_2$ and $Y_3$\n\\begin{multline*}\n\\P(9500<Y_1<10500,950<Y_2<1050,75<Y_3<85)\\\\ = \\P(9500<Y_1<10500) \\P(950<Y_2<1050) \\P(75<Y_3<85)\n\\end{multline*}\nAfter standardizing each Normal RV (subtracting its mean and dividing by its standard deviation) we get\n\\begin{align*}\n&~ \\P(9500<Y_1<10500) \\P(950<Y_2<1050) \\P(75<Y_3<85)\\\\\n&=  P\\left(\\frac{9500-10000}{250}< Z < \\frac{10500-10000}{250} \\right) P\\left( \\frac{950-1000}{20}<Z<\\frac{1050-1000}{20}\\right)\\\\\n&\\qquad \\qquad \\qquad \\qquad \\qquad \\qquad P\\left(\\frac{75-80}{4}<Z<\\frac{85-80}{4}\\right)\\\\\n&= \\P(-2.0<Z<2.0) \\P(-2.5<Z<2.5) \\P(-1.25<Z<1.25) \\\\\n&= (\\Phi(2.0)-(1-\\Phi(2.0)) \\times (\\Phi(2.5)-(1-\\Phi(2.5)) \\times (\\Phi(1.25)-(1-\\Phi(1.25))\\\\\n&= (2\\Phi(2.0)-1) \\times (2\\Phi(2.5)-1) \\times (2\\Phi(1.25)-1)\\\\\n&= ((2 \\times 0.9772) -1) \\times ((2 \\times 0.9938) - 1) \\times ((2 \\times 0.8944)-1) \\qquad \\text{ using Table for $\\Phi(z)$} \\\\\n&= 0.9544 \\times 0.9876 \\times 0.7888 = 0.7435\n\\end{align*}\n%To follow the fourth-last equality above see Example 8.14(d) from EMTH119. % TODO? \nThe values for the distribution function $\\Phi(z)$ of the $\\normal(0,1)$ RV $Z$ are in the table on page 67. \n\nThe thickness of the coating layer represented by $Y_3$ has the least probability ($0.7888$) of meeting specifications.  Consequently, a priority should be to reduce variability in this part of the process.\n\n\\Exercise\nSoft drink cans are filled by an automated filling machine.  \nAssume the fill volumes of the cans are independent $\\normal(12.1,0.01)$ RVs.  \nWhat is the probability that the average volume of ten cans selected from this process is less than $12.01$ fluid ounces?\n\\Answer\n~\\\\\nLet $X_1,X_2,\\ldots,X_{10}$ denote the fill volumes of $10$ cans.  The average fill volume is the sample mean\n\\[\n\\ol{X}_{10} = \\frac{1}{10} \\sum_{i=1}^{10} X_i\n\\]\nBy property of Expectations and Variances for linear combinations\n\\[\nE(\\ol{X}_{10}) = E \\left(\\frac{1}{10} \\sum_{i=1}^{10} X_i \\right) = \\frac{1}{10}\\sum_{i=1}^nE(X_i) = \\frac{1}{10}\\sum_{i=1}^nE(X_1) = \\frac{1}{10} \\times 10 \\times E(X_1) = E(X_1) = 12.1\n\\]\nOr by directly using the ``formula'' $E(\\ol{X}_{10}) = E(X_1)=12.1$ for these $10$ identically distributed RVs.  \nSimilarly, \n\\[\nV\\left(\\ol{X}_{10}\\right) = V \\left(\\frac{1}{10} \\sum_{i=1}^{10} X_i \\right) = 10 \\times \\frac{1}{10^2} V(X_1) = \\frac{1}{10} \\times 0.01 = 0.001 \n\\]\nOr by directly using the ``formula'' $V(\\ol{X}_{10}) = V(X_1)/10$ for these $10$ independently and identically distributed RVs.\n \nBy the special property of Normal RVs -- a linear combination of independent normal RVs is also normal -- we know that \n$\\ol{X}_{10}$ is a $\\normal(12.1,0.001)$ RV.\nConsequetly, the probability of interest is\n\\begin{align*}\n\\P(\\ol{X}_{10} < 12.01) \n&= P \\left( \\frac{\\ol{X}_{10}-E(\\ol{X}_{10})}{\\sqrt{0.001}} < \\frac{12.01 - E(\\ol{X}_{10})}{\\sqrt{0.001}} \\right) = P\\left(Z < \\frac{12.01-12.1}{0.0316}\\right)\\\\ \n&\\approxeq \\P(Z<-2.85) = 1-\\P(Z<2.85) = 1-\\Phi(2.85) = 1-0.9978=0.0022\n\\end{align*}\n\n\\Exercise\nLet $X_1,X_2,X_3,X_4$ be RVs that denote the number of bits received in a digital channel that are classified as {\\em excellent}, {\\em good}, {\\em fair} and {\\em poor}, respectively.  \nIn a transmission of $10$ bits, what is the probability that $6$ of the bits received are {\\em excellent}, $2$ are {\\em good}, $2$ are {\\em fair} and none are {\\em poor} under the assumption that the classification of bits are independent events and that the probabilities of each bit being {\\em excellent}, {\\em good}, {\\em fair} and {\\em poor} are $0.6$, $0.3$, $0.08$ and $0.02$, respectively. \n[Hint: Think of $\\multinomial(n=10,\\theta_1=0.6,\\theta_2=0.3,\\theta_3=0.08,\\theta_4=0.02)$ as a model for bit classification in this digital channel.]\n\\Answer\n~\\\\\nUsing the $\\multinomial(n=10,\\theta_1=0.6,\\theta_2=0.3,\\theta_3=0.08,\\theta_4=0.02)$ \\rv~as our model\n\\begin{align*}\n&~ P\\left( (X_1,X_2,X_3,X_4)=(6,2,2,0); n=10,\\theta_1=0.6,\\theta_2=0.3,\\theta_3=0.08,\\theta_4=0.02 \\right)\\\\ \n&= \\frac{10!}{6! \\times 2! \\times 2! \\times 0!} \\times 0.6^6 \\times 0.3^2 \\times 0.08^2 \\times 0.02^0\\\\\n&= \\frac{10 \\times 9 \\times 8 \\times 7 \\times 6 \\times 5 \\times 4 \\times 3 \\times 2 \\times 1}{(6 \\times 5 \\times 4 \\times 3 \\times 2 \\times 1) \\times (2 \\times 1) \\times (2 \\times 1) \\times 1} \\times  0.6^6 \\times 0.3^2 \\times 0.08^2 \\times 1 \\approxeq 0.03386\\\\\n\\end{align*}\n\n\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "62ad7fe7b3fec868f22e962228daaa531b759a9d", "size": 23683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInMultivariateRVs.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/ExsInMultivariateRVs.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/ExsInMultivariateRVs.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 47.1772908367, "max_line_length": 397, "alphanum_fraction": 0.5964615969, "num_tokens": 10600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181876, "lm_q2_score": 0.8933094060543487, "lm_q1q2_score": 0.7911429258595627}}
{"text": "\\subsubsection{Repeated Quadratic Factors}\r\n\\noindent\r\nIf a quadratic factor that can't be broken into linear factors is repeated, then we can write\r\n$Q(x) = R(x)(ax^2+bx+c)^k$, $k \\geq 0$, and $R(x)$ is not divisible by $(ax^2+bx+c)^k$.\r\nNow we have to do a combination of what we did for repeated linear factors and quadratic factors.\r\nWe say\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{R(x)(ax^2+bx+c)^k}=\\left(\\text{Decomposition of }R(x)\\right)+\\frac{A_1x+B_1}{ax^2+bx+c}+\\ldots+\\frac{A_kx+B_k}{(ax^2+bx+c)^k}.\r\n\\end{equation*}\r\nWe then solve for the coefficients in the numerator.\r\n\r\n\\begin{example}\r\n\tFind the partial fraction decomposition of $\\frac{3x^4-2x^3+6x^2-3x+3}{x^5+3x^4+4x^3+12x^2+4x+12}$.\r\n\\end{example}\r\n\\noindent\r\nFactoring,\r\n\\begin{equation*}\r\n\tx^5+3x^4+4x^3+12x^2+4x+12 = (x+3)(x^2+2)^2.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{3x^4-2x^3+6x^2-3x+3}{x^5+3x^4+4x^3+12x^2+4x+12} = \\frac{A_1}{x+3}+\\frac{A_2x+B_2}{x^2+2}+\\frac{A_3x+B_3}{(x^2+2)^2}.\r\n\\end{equation*}\r\nMultiplying each side by the denominator,\r\n\\begin{equation*}\r\n\t3x^4-2x^3+6x^2-3x+3 = A_1(x^2+2)^2+(A_2x+B_2)(x^2+2)(x+3)+(A_3x+B_3)(x+3).\r\n\\end{equation*}\r\nAt $x=-3$,\r\n\\begin{equation*}\r\n\t363 = 121A_1 \\implies A_1 = 3.\r\n\\end{equation*}\r\nNow, we'll use our result for $A_1$ and pick a value for $x$ that minimizes the number of things we need to solve for. We'll have to solve a linear system with 4 unknowns, so we'll need up to 4 values.\r\nAt $x=0$,\r\n\\begin{equation*}\r\n\t3 = 3(2)^2 + B_2(2)(3)+B_3(3) \\implies 2B_2 + B_3 = -3.\r\n\\end{equation*}\r\nAt $x=1$,\r\n\\begin{equation*}\r\n\t7 = 3(3)^2 + (A_2+B_2)(3)(4) + (A_3+B_3)(4) \\implies 3A_2 + A_3 + 3B_2 + B_3 = -5.\r\n\\end{equation*}\r\nAt $x=-1$,\r\n\\begin{equation*}\r\n\t17 = 3(3)^2 + (-A_2+B_2)(3)(2) + (-A_3+B_3)(2) \\implies -3A_2 - A_3 + 3B_2 + B_3 = -5.\r\n\\end{equation*}\r\nAt $x=2$,\r\n\\begin{equation*}\r\n\t53 = 3(6)^2 + (2A_2+B_2)(6)(5) + (2A_3+B_3)(5) \\implies 12A_2 + 2A_3 + 6B_2 + B_3 = -11.\r\n\\end{equation*}\r\nNow we have the following system of equations:\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\t0A_2  + 0A_3 + 2B_2 + B_3 &= -3 \\\\\r\n\t\t3A_2  + A_3  + 3B_2 + B_3 &= -5 \\\\\r\n\t\t-3A_2 - A_3  + 3B_2 + B_3 &= -5 \\\\\r\n\t\t12A_2 + 2A_3 + 6B_2 + B_3 &= -11\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nSolving,\r\n\\begin{equation*}\r\n\tA_2 = 0, A_3 = 0, B_2 = -2, \\text{ and } B_3 = 1.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{3x^4-2x^3+6x^2-3x+3}{x^5+3x^4+4x^3+12x^2+4x+12} = \\frac{3}{x+3}-\\frac{2}{x^2+2}+\\frac{1}{(x^2+2)^2}.\r\n\\end{equation*}", "meta": {"hexsha": "b280300ee0693a1181c29574490990f48d367670", "size": 2447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/repeatedQuadraticFactors.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/repeatedQuadraticFactors.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/repeatedQuadraticFactors.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": 37.6461538462, "max_line_length": 202, "alphanum_fraction": 0.6117695137, "num_tokens": 1217, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361628580401, "lm_q2_score": 0.8670357735451835, "lm_q1q2_score": 0.7911147942742198}}
{"text": "\\section{Solving PDEs with Green's Functions}\r\n\\subsection{Diffusion Equation and Fourier Transform}\r\nRecall that the heat equation for a conducting wire is\r\n$$\\frac{\\partial\\Theta}{\\partial t}-D\\frac{\\partial^2\\Theta}{\\partial x^2}$$\r\nwith initial condition $\\Theta(x,0)=h(x)$ and boundary condition $\\Theta\\to 0$ as $x\\to\\pm\\infty$.\r\nTaking Fourier transform wrt $x$ gives\r\n$$\\frac{\\partial}{\\partial t}\\tilde{\\Theta}(k,t)=-Dk^2\\tilde\\Theta(k,t)\\implies\\tilde\\Theta(k,t)=Ce^{-Dk^2t}$$\r\nfor some $C$ that is constant in $t$.\r\nInitial condition $\\tilde{\\Theta}(k,0)=\\tilde{h}(k)$ gives $\\tilde\\Theta(k,t)=\\tilde{h}(k)e^{-Dk^2t}$.\r\nInverting it gives\r\n\\begin{align*}\r\n    \\Theta(x,t)&=\\frac{1}{2\\pi}\\int_{-\\infty}^\\infty \\tilde{h}(k)e^{-Dk^2t}e^{ikx}\\,\\mathrm dk\\\\\r\n    &=\\frac{1}{\\sqrt{4\\pi Dt}}\\int_{-\\infty}^\\infty h(u)\\exp\\left( -\\frac{(x-u)^2}{4Dt} \\right)\\,\\mathrm du\\\\\r\n    &=\\int_{-\\infty}^\\infty h(u)S_d(x-u,t)\\,\\mathrm du\r\n\\end{align*}\r\nwhere $S_d(x,t)=(4\\pi Dt)^{-1/2}e^{-x^2/(4Dt)}$ is called the fundamental solution (or diffusion kernel/sourse function), which is just the FT of $e^{-Dk^2t}$.\r\nNote that the case $\\Theta(x,0)=\\theta_0\\delta(x)$ gives our old friend $\\Theta=\\theta_0(4\\pi Dt)^{-1/2}e^{-\\eta^2}$ where $\\eta=x/(2\\sqrt{Dt})$ is the similarity parameter.\r\n\\begin{example}\r\n    Suppose initially $f(x)=\\theta_0\\sqrt{a/\\pi}e^{-ax^2}$.\r\n    Then\r\n    \\begin{align*}\r\n        \\Theta&=\\frac{\\theta_0\\sqrt{a}}{\\sqrt{4\\pi^2Dt}}\\int_{-\\infty}^\\infty\\exp\\left( -au^2-\\frac{(x-u)^2}{4Dt} \\right)\\,\\mathrm du\\\\\r\n        &=\\frac{\\theta_0\\sqrt{a}}{\\sqrt{4\\pi^2Dt}}\\int_{-\\infty}^\\infty\\exp\\left( -\\frac{1+4aDt}{4Dt}\\left( u-\\frac{x}{1+4aDt} \\right)^2 \\right)\\exp\\left( \\frac{-ax^2}{1+4aDt} \\right)\\,\\mathrm du\\\\\r\n        &=\\theta_0\\sqrt{\\frac{a}{\\pi(1+4aDt)}}\\exp\\left( \\frac{-ax^2}{1+4aDt} \\right)\r\n    \\end{align*}\r\n    Asymptotically the width of the Gaussian spreads as $\\sqrt{t}$ and the area under the curve being constant (which can be interpreted as the conservation of heat energy).\r\n\\end{example}\r\n\\subsection{Forced Diffusion Equation}\r\nConsider\r\n$$\\frac{\\partial\\Theta}{\\partial t}(x,t)-D\\frac{\\partial^2\\Theta}{\\partial x^2}(x,t)=f(x,t)$$\r\nwith homogeneous initial condition $\\Theta(x,0)=0$.\r\nThe Green's function $G$ of this problem would satisfy\r\n$$\\frac{\\partial G}{\\partial t}-D\\frac{\\partial^2G}{\\partial x^2}=\\delta(x-\\xi)\\delta(t-\\tau)$$\r\nwith $G(x,0;\\xi,\\tau)=0$.\r\nTake FT wrt $x$ gives\r\n$$\\frac{\\partial \\tilde{G}}{\\partial t}(k,t;\\xi,\\tau)+Dk^2\\tilde{G}(k,t;\\xi,\\tau)=e^{-ik\\xi}\\delta(t-\\xi)$$\r\nMultiplying both sides using the integration factor $e^{Dk^2t}$ allows us to integrate the equation and obtain\r\n$$e^{Dk^2t}\\tilde{G}=e^{-ik\\xi}\\int_0^te^{Dk^2t'}\\delta(t'-\\tau)\\,\\mathrm dt'$$\r\nThe appearance of Heaviside function is because we need to ensure that $[0,t]$ contains $\\tau$ in order to make use of the property of $\\delta$ function.\r\nInverting the whole thing gives\r\n\\begin{align*}\r\n    G(x,t;\\xi,\\tau)&=\\frac{H(t-\\tau)}{2\\pi}\\int_{-\\infty}^\\infty e^{ik(x-\\xi)}e^{-Dk^2(t-\\tau)}\\,\\mathrm dk\\\\\r\n    &=\\frac{H(t')}{2\\pi}\\int_{-\\infty}^\\infty e^{ikx'}e^{-Dk^2t'}\\,\\mathrm dk,x'=x-\\xi,t'=t-\\tau\\\\\r\n    &=\\frac{H(t')}{\\sqrt{4\\pi Dt'}}e^{-x'^2/(4Dt')}\\\\\r\n    &=H(t-\\tau)S_d(x-\\xi,t-\\tau)\r\n\\end{align*}\r\nwhere $S_d$ is again our good ol' fundamental solution.\r\nTherefore the general solution is\r\n\\begin{align*}\r\n    \\Theta(x,t)&=\\int_0^\\infty\\int_{-\\infty}^\\infty G(x,t;\\xi,\\tau)f(\\xi,\\tau)\\,\\mathrm d\\xi\\mathrm d\\tau\\\\\r\n    &=\\int_0^t\\int_{-\\infty}^\\infty f(u,\\tau)S_d(x-u,t-\\tau)\\,\\mathrm du\\mathrm d\\tau\r\n\\end{align*}\r\nwhich looks very familiar to our previous solution for the homogeneous case with initial conditions at $t=\\tau$.\r\nBut this time, the initial condition of $\\Theta(u,t)=f(u)$ at $t=\\tau$ is replaced by the forcing term $f(u,\\tau)$ in the equation, and the effect of this, as we see now, is just integrating the solution over $\\tau$.\r\nThis phenomenon is called Duhamel's Principle which relates the solution of forced PDE with homogeneous boundary conditions to solutions of homogeneous PDEs with inhomogenoeus boundary conditions.\r\nSo in this philosophy, the forcing term is acting like an initial conditions for subsequent evolution, and the integral represents a superposition of all these initial-condition-like effects for $0<\\tau<t$.\r\n\\subsection{Forced Wave Equation}\r\nConsider the forced wave equation\r\n$$\\frac{\\partial^2\\phi}{\\partial t^2}-c^2\\frac{\\partial^2\\phi}{\\partial x}=f(x,t)$$\r\nsubject to $\\phi(x,0)=\\phi_t(x,0)=0$.\r\nThe Green's function for this would satisfy\r\n$$\\frac{\\partial^2\\phi}{\\partial t^2}-c^2\\frac{\\partial^2\\phi}{\\partial x}=\\delta(x-\\xi)\\delta(t-\\tau)$$\r\nwith $G=G_t=0$ at $t=0$.\r\nTake FT wrt $x$ again,\r\n$$\\frac{\\partial^2\\tilde{G}}{\\partial t^2}+c^2k^2\\tilde{G}=e^{-ik\\xi}\\delta(t-\\tau)$$\r\nSolving it yields\r\n$$\\tilde{G}=\\begin{cases}\r\n    0\\text{, if $t<\\tau$}\\\\\r\n    e^{-ik\\xi}\\sin(kc(t-\\tau))/(kc)\\text{, if $t>\\tau$}\r\n\\end{cases}=e^{-ik\\xi}\\frac{\\sin(kc(t-\\tau))}{kc}$$\r\nInverting this gives\r\n\\begin{align*}\r\n    G(x,t;\\xi,\\tau)&=\\frac{H(t-\\tau)}{2\\pi c}\\int_{-\\infty}^\\infty e^{ik(x-\\xi)}\\frac{\\sin(kc(t-\\tau))}{k}\\,\\mathrm dk\\\\\r\n    &=\\frac{H(t-\\tau)}{2\\pi c}\\int_{-\\infty}^\\infty \\frac{\\cos(kA)\\sin(kB)}{k}\\,\\mathrm dk,A=x-\\xi,B=c(t-\\tau)\\\\\r\n    &=\\frac{H(t-\\tau)}{2\\pi c}\\int_{-\\infty}^\\infty \\frac{\\sin(k(A+B))-\\sin(k(A-B))}{k}\\,\\mathrm dk\\\\\r\n    &=\\frac{H(t-\\tau)}{2\\pi c}(\\operatorname{sgn}(A+B)-\\operatorname{sgn}(A-B))\\\\\r\n    &=\\frac{1}{2c}H(c(t-\\tau)-|x-\\xi|)\r\n\\end{align*}\r\nwhich is also called the causal fundamental solution since it hints the causal structure in $t$.\r\nThe general solution is then\r\n\\begin{align*}\r\n    \\phi(x,t)&=\\int_0^\\infty\\int_{-\\infty}^\\infty f(\\xi,t)G(x,t;\\xi,\\tau)\\,\\mathrm d\\xi\\mathrm d\\tau\\\\\r\n    &=\\frac{1}{2c}\\int_0^t\\int_{x-c(t-\\tau)}^{x+c(t-\\tau)}f(\\xi,\\tau)\\,\\mathrm d\\xi\\mathrm d\\tau\r\n\\end{align*}\r\nwhich, by relating to our previous solution, can also be seen as an example of Dudamel's principle.\r\n\\subsection{Poisson's Equation}\r\nWe want to solve Poisson's equation, which is just a forced Laplace equation $\\nabla^2\\phi=-\\rho$ on a domain $D$ subject to Dirichlet boundary conditions $\\phi|_{\\partial D}=0$.\r\nTo get its fundamental solution, note that we can get the notion of $\\delta$ function on $\\mathbb R^3$ analogously.\r\nSo the free space Green's function $G=G_{\\rm FS}(\\underline{r};\\underline{r}')$ is naturally the solution to $\\nabla^2G_{\\rm FS}(\\underline{r};\\underline{r}')=\\delta(\\underline{r}-\\underline{r}')$.\r\nWe can take this to be spherically symmetric $G(\\underline{r};\\underline{r}')=G(|\\underline{r}-\\underline{r}'|)=G(r)$.\r\nLet $B$ be the ball with centre $\\underline{r}'$ and radius $r$, then we have\r\n$$1=\\int_B\\delta(\\underline{r}-\\underline{r}')\\,\\mathrm d^3\\underline{r}=\\int_B\\nabla^2G_{\\rm FS}\\,\\mathrm d^3r=\\int_{\\partial B}\\nabla G_{\\rm FS}\\cdot\\underline{n}\\,\\mathrm dS=4\\pi r^2\\frac{\\partial G_{\\rm FS}}{\\partial r}$$\r\nSo $G_{\\rm FS}=-1/(4\\pi r)=-1/(4\\pi|\\underline{r}-\\underline{r}'|)$ because of the boundary condition $G\\to 0$ as $r\\to\\infty$.\r\nTherefore we get the general solution\r\n$$\\Phi(\\underline{r})=\\frac{1}{4\\pi}\\int_D\\frac{\\rho(\\underline{r}')}{|\\underline{r}-\\underline{r}'|}\\,\\mathrm d^3\\underline{r}'$$\r\nBy the way, we can derive the Green's function in 2D in the similar way and get $G_2(\\underline{r};\\underline{r}')=-(2\\pi)^{-1}\\log(|\\underline{r}-\\underline{r}'|)+C_2$ where $C_2$ is a constant (which we almost always set to $0$).\\\\\r\nWe now turn to Green's Identities.\r\nConsider two scalar functions $\\phi,\\psi$ twice differentiable on $D$.\r\nThen\r\n$$\\int_D(\\phi\\nabla^2\\psi+\\nabla\\phi\\cdot\\nabla\\psi)\\,\\mathrm d^3\\underline{r}=\\int_D\\nabla\\cdot(\\phi\\nabla\\psi)\\,\\mathrm d^3\\underline{r}=\\int_{\\partial D}\\phi\\nabla\\psi\\cdot\\underline{\\hat{n}}\\,\\mathrm dS$$\r\nby divergence theorem.\r\nThis is called Green's first identity.\r\nNow switch $\\psi$ and $\\phi$ and substract from the first identity to get Green's second identity.\r\n$$\\int_{\\partial D}\\left( \\phi\\frac{\\partial\\psi}{\\partial n}-\\psi\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS=\\int_D(\\phi\\nabla^2\\psi-\\psi\\nabla^2\\phi)\\,\\mathrm d^3\\underline{r}$$\r\nNow excise a small spherical ball $B_\\epsilon$ around $\\underline{r}'$ with radius $\\epsilon$.\r\nNow if $\\phi$ is a solution to $\\nabla^2\\phi=-\\rho$ and $\\psi=G_{\\rm FS}(\\underline{r};\\underline{r}')$, then the right hand side is\r\n$$\\int_{D-B_\\epsilon}(\\phi\\nabla^2G_{\\rm FS}-G_{\\rm FS}\\nabla^2\\phi)\\,\\mathrm d^3r=\\int_{D-B_\\epsilon}G_{\\rm FS}\\rho\\,\\mathrm d^3\\underline{r}$$\r\nand the left hand side becomes\r\n$$\\int_{\\partial D}\\left( \\phi\\frac{\\partial G_{\\rm FS}}{\\partial n}-G_{\\rm FS}\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS+\\int_{\\partial B_\\epsilon}\\left( \\phi\\frac{\\partial G_{\\rm FS}}{\\partial n}-G_{\\rm FS}\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS$$\r\nTaking $\\epsilon\\to 0$ gives\r\n$$\\int_{\\partial B_\\epsilon}\\left( \\phi\\frac{\\partial G_{\\rm FS}}{\\partial n}-G_{\\rm FS}\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS\\to-\\phi(\\underline{r}')$$\r\nTherefore we conclude Green's third identity\r\n$$\\phi(\\underline{r}')=\\int_DG_{\\rm FS}(\\underline{r};\\underline{r}')(-\\rho(\\underline{r}))\\,\\mathrm d^3\\underline{r}+\\int_{\\partial D}\\left( \\phi(\\underline{r})\\frac{\\partial G}{\\partial n}(\\underline{r};\\underline{r}')-G_{\\rm FS}(\\underline{r};\\underline{r}')\\frac{\\partial\\phi}{\\partial n}(\\underline{r}) \\right)\\,\\mathrm dS$$\r\nNow we want to solve $\\nabla^2\\phi=-\\rho$ on $D$ subject to inhomogeneous Dirichlet boundary conditions $\\phi|_{\\partial D}=h$.\r\nIn this case, we want the Green's function $G=G(\\underline{r};\\underline{r}')$ to satisfy:\\\\\r\n(i) $\\nabla^2G(\\underline{r};\\underline{r}')=0$ for any $\\underline{r}\\neq\\underline{r}'$.\\\\\r\n(ii) $G(\\underline{r};\\underline{r}')=0$ on $\\partial D$.\\\\\r\n(iii) $G(\\underline{r},\\underline{r}')=G_{\\rm FS}(\\underline{r};\\underline{r}')+H(\\underline{r},\\underline{r}')$ for some $H$ such that $\\nabla^2H=0$ in $D$.\\\\\r\nGreen's second identity with $\\nabla^2\\phi=-\\rho$ and $\\nabla^2H=0$ gives\r\n$$\\int_{\\partial D}\\left( \\phi\\frac{\\partial H}{\\partial n}-H\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS=\\int_DH\\rho\\,\\mathrm d^3\\underline{r}$$\r\nThe Green's third identity simplifies to\r\n\\begin{align*}\r\n    \\phi(\\underline{r}')&=\\int_D(G-H)(-\\rho)\\,\\mathrm d^3\\underline{r}+\\int_{\\partial D}\\left( \\phi\\frac{\\partial (G-H)}{\\partial n}-(G-H)\\frac{\\partial\\phi}{\\partial n} \\right)\\,\\mathrm dS\\\\\r\n    &=\\int_DG(\\underline{r};\\underline{r}')(-\\rho(\\underline{r}))\\,\\mathrm d^3\\underline{r}+\\int_{\\partial D}h(\\underline{r})\\frac{\\partial G(\\underline{r};\\underline{r}')}{\\partial n}\\,\\mathrm dS\r\n\\end{align*}\r\nSo this Green's function does give a way to obtain a particular solution.\r\nAlso $G(\\underline{r};\\underline{r}')=G(\\underline{r};\\underline{r}')$ by a simple use of Green's third identity again.\\\\\r\nFor Neumann boundary conditions with $\\partial\\phi/\\partial n=k(\\underline{r})$ on $\\partial D$, we can do a similar thing and obtain\r\n$$\\phi(\\underline{r}')=\\int_DG(\\underline{r};\\underline{r}')(-\\rho(\\underline{r}))\\,\\mathrm d^3\\underline{r}+\\int_{\\partial D}G(\\underline{r};\\underline{r}')(-k(\\underline{r}))\\,\\mathrm dS$$\r\n\\subsection{Method of Images}\r\nFor symmetric domain $D$ we can construct Green's function with $G=0$ on $\\partial D$ by cancelling the boundary potential with an opposite mirror image Green's function placed outside $D$.\\\\\r\nOur first target is Laplace's equation on the half-plane $D=\\{(x,y,z):z>0\\}$ subject to $\\phi(x,y,0)=h(x,y)$ and $\\phi\\to 0$ as $|\\underline{r}|\\to\\infty$.\r\nNow $G_{\\rm FS}(\\underline{r};\\underline{r}')\\to 0$ as $|\\underline{r}|\\to\\infty$, but it is nonzero at $z=0$.\r\nHowever, we can take $G(\\underline{r};\\underline{r}')=G(\\underline{r};\\underline{r}')-G(\\underline{r},\\underline{r}'')$ where $\\underline{r}''=(x',y',-z')$ which totally works.\r\nAlso at $z=0$, $\\partial G/\\partial n=\\partial G/\\partial z=(2\\pi)^{-1}z'((x-x')^2+(y-y')^2+z'^2)^{-3/2}$.\r\nThis means that the solution is\r\n$$\\Phi(x',y',z')=\\frac{z'}{2\\pi}\\int_{-\\infty}^\\infty\\int_{-\\infty}^\\infty((x-x')^2+(y-y')^2+z'^2)^{-3/2}h(x,t)\\,\\mathrm dx\\mathrm dy$$\r\nWe now turn to the wave equation for $x>0$.\r\nConsider $\\ddot{\\phi}-c^2\\phi^{\\prime\\prime}=f$ with Dirichlet boundary conditions $\\phi(0,t)=0$.\r\nThe same philosophy gives the Green's function\r\n$$G(x,t;\\xi,\\tau)=\\frac{1}{2c}H(c(t-\\tau)-|x-\\xi|)-\\frac{1}{2c}H(c(t-\\tau)-|x+\\xi|)$$\r\nSo if $f=0$ and the initial condition is a Gaussian pause, then this solves to\r\n$$\\phi(x,t)=\\exp((x-\\xi+ct)^2)-\\exp((-x-\\xi+ct)^2)$$", "meta": {"hexsha": "223208fca29c5f0dbabe5ee99d16c49f1accef68", "size": 12477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10/pdegreen.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": "10/pdegreen.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": "10/pdegreen.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": 87.2517482517, "max_line_length": 330, "alphanum_fraction": 0.6580107398, "num_tokens": 4531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7911147745470145}}
{"text": "\\lab{Conservation laws and heat flow}{Conservation laws and heat flow}\n\\label{lab:finitedifference1}\n\nA conservation law is a balance law, and corresponds to an equation that describes how a quantity is balanced in some system throughout a given process.\n(Consider how this is related to conservation laws in physics.)\nFor example, suppose we are keeping track of some measurable quantity in a physical system (e.g. heat, water, etc).\nThe fundamental conservation law then states that the rate of change of the total quantity in the system is equal to the rate of the quantity flowing into the system plus the rate at which the quantity is produced by sources inside the system.\n\n\\section*{Derivation of the Conservation equation in multiple dimensions}\nSuppose $\\Omega$ is a region in $\\mathbb{R}^n$, and $V \\subset \\Omega$ is bounded with a reasonably well-behaved boundary $\\partial V$.\nLet $u(\\vec{x},t)$ represent the density (concentration) of some quantity throughout $\\Omega$.\nLet $\\vec{n}(x)$ represent the normal direction to $V$ at $x \\in \\partial V$, and let $\\vec{J}(\\vec{x},t)$ be the flux vector for the quantity, so that $\\vec{J}(\\vec{x},t) \\cdot \\vec{n}(x) \\, dA$ represents the rate at which the quantity leaves $V$ by crossing a boundary element with area $dA$.\nNote that the total amount of the quantity in $V$ is\n\\[ \\int_V u(\\vec{x},t)\\, dt,\\]\nand the rate at which the quantity enters $V$ is\n\\[-\\int_{\\partial V} \\vec{J}(\\vec{x},t) \\cdot \\vec{n}(x) \\, dA.\\]\n\nWe let the source term be given by $f(\\vec{x},t,u)$; we may interpret this to mean that the rate at which the quantity is produced in $V$ is \n\\[\\int_V f(\\vec{x},t,u)\\, dt.\\]\nThen the integral form of the conservation law for $u$ is expressed as \n\\[\\frac{d}{dt} \\int_V u(\\vec{x},t) \\, d\\vec{x} = -\\int_V \\vec{J}\\cdot \\vec{n}\\, dA + \\int_V f(\\vec{x},t,u)\\, d\\vec{x}.\\]\n\nIf $u$ and $J$ are sufficiently smooth functions, then we have \n\\[ \\frac{d}{dt} \\int_V u\\, d\\vec{x} = \\int_V u_t \\, d\\vec{x},\\]\nand \n\\[ \\int_V \\vec{J}\\cdot \\vec{n}\\, dA = \\int_V \\nabla \\cdot \\vec{J}\\, d\\vec{x} .\\]\nSince this holds for all nice subsets $V \\subset \\Omega$ with $V$ arbitrarily small, we obtain the differential form of the conservation law for $u$: \n\\[ u_t + \\nabla \\cdot \\vec{J} = f(\\vec{x},t,u) .\\]\n\n\\section*{Constitutive Relations}\nCurrently our conservation law appears in the form \n\\[u_t + \\nabla \\vec{J} = f(\\vec{x},t,u).\\]\nThus the conservation law consists of one equation and 2 unknowns ($u$ and $J$).\nTo this equation we add other equations, called constituve relations, which are used to fully determine the system. \n\nFor example, suppose we wish to describe the flow of heat.\nSince heat flows from warmer regions to colder regions, and the rate of heat flow depends on the difference in temperature between regions, we usually assume that the flux vector $\\vec{J}$ is given by \n\\[\\vec{J}(x,t) = -\\nu \\nabla u(x,t),\\]\nwhere $\\nu$ is a diffusion constant.\nThis constitutive relation is called Fick's law, and is the basic model for any diffusive process.\nSubstituting into the conservation law we obtain \n\\[u_t -\\nu \\triangle u(x,t) = f(\\vec{x},t,u).\\]  \nThe function $f$ represents heat sources/sinks within the region. \n\n\\section*{Numerically modelling heat flow}\nConsider the heat flow equation in one dimension together with appropriate initial conditions and homogeneous Dirichlet boundary conditions: \n\\begin{align*}\n\t&{ } u_t = \\nu u_{xx}, \\quad x \\in [a,b],\\quad t \\in [0,T], \\\\\n\t&{ } u(a,t) = 0,\\quad u(b,t) = 0,\\\\\n\t&{ } u(x,0) = f(x).\n\\end{align*}\nWe will look for an approximation $U^j_i$ to $u(x_i,t_j)$ on the grid $x_i = a +  hi$, $t_j = kj$, where $h$ and $k$ are small changes in $x$ and $t$ respectively and $i$ and $j$ are indices.\nNote that the index $i$ ranges over different spacial grid points and the index $j$ ranges over different time steps.\nWe will denote the approximate value of $u$ at the $i$'th grid point and the $j$'th time step as $U_i^j$.\n\nA common method for modelling ordinary and partial differential equations is the finite difference method, so-named because equations containing derivatives are replaced with equations containing difference schemes.\nThese difference schemes can often be found using Taylor's theorem.\nFor example, the equation \n\\begin{align*}\n\tu(x,t_j + k) = u(x,t_j) + u_t(x,t_j)k + \\mathcal{O}(k^2)\n\\end{align*}\nyields a first-order forward difference approximation to $u_t(x,t_j)$, namely, \n\\begin{align*}\n\tu_t(x,t_j ) = \\frac{u(x,t_j+k) - u(x,t_j)}{k} + \\mathcal{O}(k).\n\\end{align*}\nSimilarly, by adding the equations \n\\begin{align*}\n\tu(x_i+h,t) &= u(x_i,t) + u_x(x_i,t)h + u_{xx}(x_i,t)\\frac{h^2}{2} + u_{xxx}(x_i,t)h^3 + \\mathcal{O}(h^4),\\\\\n\tu(x_i-h,t) &= u(x_i,t) + u_x(x_i,t)(-h) + u_{xx}(x_i,t)\\frac{(-h)^2}{2} + u_{xxx}(x_i,t)(-h)^3 + \\mathcal{O}(h^4),\n\\end{align*}\nwe obtain a second-order centered difference approximation to $u_{xx}(x_i,t)$:\n\\begin{align*}\n\tu_{xx}(x_i,t_j) &= \\frac{u(x_i + h,t_j )-2 u(x_i,t_j)- u(x_i - h,t_j)}{h^2} + \\mathcal{O}(h^2).\n\\end{align*}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{heatexercise1a.pdf}\n\\caption{The graph of $U^{0}$, the approximation to the solution $u(x,t=0)$ for Problem \\ref{prob:heat_exercise1}.}\n\\label{fig:heatexercise1a}\n\\end{figure}\n\n% A simple explicit method for numerically approximating the solution of this problem is to use a forward difference approximation in time and a centered difference approximation in space.\n% Recall that\n% \\[u_t(x_i,t_j) = \\frac{u(x_i,t_j + k) - u(x_i,t_j)}{k} + \\mathcal{O}(k)\n% \\]\n%  and \n% \\[u_{xx}(x_i,t_j) = \\frac{u(x_i + h,t_j )-2 u(x_i,t_j)- u(x_i - h,t_j)}{h^2} + \\mathcal{O}(h^2).\n% \\]\n% Let $U_{i,j}$ represent our approximation to $u(x_i,t_j)$. \nThese difference approximations give us the $\\mathcal{O}(h^2 + k)$ explicit method \n\\begin{align}\n\t\\begin{split}\n\t\\frac{U_{i}^{j+1} - U_{i}^{j}}{k} &= \\nu \\frac{U_{i+1}^{j}- 2U_{i}^{j} + U_{i-1}^{j} }{h^2} ,\\\\ \n\tU_{i}^{j+1} &= U_{i}^{j} + \\frac{\\nu k}{h^2} (U_{i+1}^{j}- 2U_{i}^{j} + U_{i-1}^{j} ). \n\t\\end{split}\\label{eqn:firstorder_explicit}\n\\end{align}\nThis method can be written in matrix form as \n\\[U^{j+1} = A U^j,\\]\nwhere $A$ is the tridiagonal matrix given by \n\\[A = \\left[\\begin{array}{cccccc}1-2\\lambda & \\lambda & & & \\\\ \\lambda & 1-2\\lambda & \\lambda & & \\\\ & \\ddots & \\ddots & \\ddots & \\\\ & & \\lambda & 1-2\\lambda & \\lambda \\\\  &  &  & \\lambda & 1-2\\lambda\\end{array}\\right],\\]\n$\\lambda = \\nu k/h^2$, and $U^j$ represents the approximation at time $t_j$.\nWe can get this method started by using the initial condition given in our problem, so that $U_{i}^{0} = f(x_i)$. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{heatexercise1b.pdf}\n\\caption{The graph of $U^{10}$, the approximation to the solution $u(x,t=.4)$ for Problem \\ref{prob:heat_exercise1}.}\n\\label{fig:heatexercise1b}\n\\end{figure}\n\n\\begin{info}\nFinite difference schemes, though they can be \\emph{represented} using matrix multiplication, should not be \\emph{implemented} using raw matrix multiplication.\nUsing NumPy, it is best to vectorize the difference scheme so that you do not have to loop over the spatial indices.\nIf you are using a language with faster loops (like C, C++, Fortran, or Cython), it could work well to loop directly through the indices in both time and space.\n\\end{info}\n\nTo account for boundary conditions using this differencing scheme, simply set the boundary points to the appropriate values in the initial conditions, then avoid modifying them as you update for each time step.\nThis would be the equivalent of replacing the first and last rows of the matrix representation of the differencing scheme with the first and last rows of the identity matrix.\n\n\\begin{problem}\n\\label{prob:heat_exercise1}\nConsider the specific initial boundary value problem\n\\begin{align}\n\t\\begin{split}\n\t&{ } u_t = .05 u_{xx}, \\quad x \\in [0,1], \\\\\n\t&{ } u(0,t) = 0,\\quad u(1,t) = 0,\\\\\n\t&{ } u(x,0) = 2\\max\\{.2 - |x-.5|,0\\}.\n\t\\end{split}\n\\end{align}\nApproximate the solution $u(x,t)$ at time $t = .4$ be taking 6 subintervals in the $x$ dimension and 10 subintervals in time. \nThe graphs for $U^0$ and $U^{10}$ are given in Figures \\ref{fig:heatexercise1a} and \\ref{fig:heatexercise1b}.\n\\end{problem}\n\nFor the next problem, we need to show how Matplotlib can be used to create a 2D animation.\nThe following is a simple working example that animates a sine wave.\n\n% Note: If an animation is running slowly, consider using the \\li{blit=True} option when creating the animation.\n% If you do this, also define an initialization function that sets the line's data to empty lists and returns a 1-tuple containing the line object.\n% Pass the initialization function to the \\li{FuncAnimation} function using the \\li{init_func} keyword argument.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom matplotlib import animation, pyplot as plt\n\ndef sine_animation(res=100):\n    # Make the x and y data.\n    x = np.linspace(-1, 1, res+1)[:-1]\n    y = np.sin(np.pi * x)\n    # Initialize a matplotlib figure.\n    f = plt.figure()\n    # Set the x and y axes by constructing an axes object.\n    plt.axes(xlim=(-1,1), ylim=(-1,1))\n    # Plot an empty line to use in the animation.\n    # Notice that we are unpacking a tuple of length 1.\n    line, = plt.plot([], [])\n    # Define an animation function that will update the line to\n    # reflect the desired data for the i'th frame.\n    def animate(i):\n        # Set the data for updated version of the line.\n        line.set_data(x, np.roll(y, i))\n        # Notice that this returns a tuple of length 1.\n        return line,\n    # Create the animation object.\n    # 'frames' is the number of frames before the animation should repeat.\n    # 'interval' is the amount of time to wait before updating the plot.\n    # Be sure to assign the animation a name so that Python does not\n    # immediately garbage collect (delete) the object.\n    a = animation.FuncAnimation(f, animate, frames=y.size, interval=20)\n    # Show the animation.\n    plt.show()\n\n# Run the animation function we just defined.\nsine_animation()\n\\end{lstlisting}\n\n\\begin{problem}\n\\label{prob:heat_exercise2}\nSolve the specific initial boundary value problem\n\\begin{align}\n\t\\begin{split}\n\t&{ } u_t = u_{xx}, \\quad x \\in [-12,12],\\quad t \\in [0,1], \\\\\n\t&{ } u(-12,t) = 0,\\quad u(12,t) = 0,\\\\\n\t&{ } u(x,0) = \\max\\{1 - x^2,0\\}\n\t\\end{split}\n\\end{align}\nusing the first order explicit method \\ref{eqn:firstorder_explicit}.\nUse 140 subintervals in the $x$ dimension and 70 subintervals in time.\nThe initial and final states are shown in Figure \\ref{fig:heatexercise2}.\nAnimate your results.\n\nExplicit methods usually have a stability condition, called a CFL condition (for Courant-Friedrichs-Lewy).\nFor method \\ref{eqn:firstorder_explicit} the CFL condition that must be satisfied is that\n\\[\\lambda \\leq \\frac{1}{2}.\\]\nRepeat your computations using 140 subintervals in the $x$ dimension and 66 subintervals in time.\nFor these values the CFL condition is broken; you should easily see the result of this instability in the approximation $U^{66}$.\n% Then the graphs for $U^0$ and $U^{70}$ are given in \\eqref{heatexercise2a} and \\ref{heatexercise2b}.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{heatexercise2.pdf}\n\\caption{The initial and final states for equation Problem \\ref{prob:heat_exercise2}.}\n\\label{fig:heatexercise2}\n\\end{figure}\n\nImplicit methods often have better stability properties than explicit methods.\nThe Crank-Nicolson method, for example, is unconditionally stable and has order $\\mathcal{O}(h^2 + k^2)$.\nTo derive the Crank-Nicolson method, we use the following approximations:\n\\begin{align*}\n\tu_t(x_i,t_{j+1/2}) &= \\frac{u_t(x_i,t_{j+1}) - u_t(x_i,t_j)}{k} + \\mathcal{O}(k^2), \\\\\n\tu_{xx}(x_i,t_{j+1/2}) &= \\frac{u_{xx}(x_i,t_{j+1}) + u_{xx}(x_i,t_j)}{2} + \\mathcal{O}(k^2).\n\\end{align*}\nThese approximations give the method\n\\begin{align}\n\t\\begin{split}\n\t\\frac{U^{j+1}_i - U^j_i}{k} &= \\frac{1}{2}\\left( \\frac{U^j_{i+1} - 2U^j_{i} + U^j_{i-1}}{h^2} + \\frac{U^{j+1}_{i+1} - 2U^{j+1}_{i} + U^{j+1}_{i-1}}{h^2}  \\right) ,\\\\\n\tU^{j+1}_i  &= U^j_i + \\frac{k}{2h^2} \\left( U^j_{i+1} - 2U^j_{i} + U^j_{i-1} + U^{j+1}_{i+1} - 2U^{j+1}_{i} + U^{j+1}_{i-1}   \\right).\n\\end{split}\n\\end{align}\nThis method can be written in matrix form as \n\\[BU^{j+1} = A U^j,\\]\nwhere $A$ and $B$ are tridiagonal matrices given by \n\\begin{align*}\nB &= \\left[\\begin{array}{cccccc}1+2\\lambda & -\\lambda &  &  &  \\\\ -\\lambda & 1+2\\lambda &  -\\lambda & &  \\\\ &  \\ddots &   \\ddots & \\ddots \\\\ & &  -\\lambda &  1+2\\lambda & -\\lambda \\\\ &  &  & -\\lambda & 1+2\\lambda\\end{array}\\right], \\\\\nA &= \\left[\\begin{array}{cccccc}1-2\\lambda & \\lambda &  &  &  \\\\ \\lambda & 1-2\\lambda &  \\lambda & &  \\\\ &  \\ddots &   \\ddots & \\ddots \\\\ & &  \\lambda &  1-2\\lambda & \\lambda \\\\ &  &  & \\lambda & 1-2\\lambda\\end{array}\\right], \n\\end{align*}\nwhere $\\lambda = \\nu k/(2h^2)$, and $U^j$ represents the approximation at time $t_j$.\nNote that here we have defined $\\lambda$ differently than we did before!\n\nHow do we know if a numerical approximation is reasonable?\nOne way to determine this is to compute solutions for various step sizes $h$ and see if the solutions are converging to something.\nTo be more specific, suppose our finite difference method is $\\mathcal{O}(h^p)$ accurate.\nThis means that the error $E(h) \\approx Ch^p$ for some constant $C$ as $h \\to 0$ (i.e., for $h>0$ small enough).\n\nSo compute the approximation $y_k$ for each stepsize $h_k$, $h_1 > h_2> \\ldots>h_m.$\nWe will think of $y_m$ as the true solution.\nThen the error of the approximation for stepsize $h_k, k < m,$ is\n\\begin{align*}\n\tE(h_k) &= \\max( \\abs{ y_k - y_m}) \\approx C h_k^p ,\\\\\n\t\\log(E(h_k)) &= \\log(C) + p \\log(h_k).\n\\end{align*}\nThus on a log-log plot of $E(h)$ vs. $h,$ these values should be on a straight line with slope $p$ when $h$ is small enough to start getting convergence.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{MaximumError.pdf}\n\\caption{$E(h)$ represents the (approximate) maximum error in the numerical solution $U$ to Problem \\ref{prob:heat_exercise3} at time $t=1$, using a stepsize of $h$.}\n\\label{fig:heatexercise3}\n\\end{figure}\n\n% If dgtsv is ever included in SciPy, it would probably be better to use that here instead of a custom routine.\nWhen implementing the Crank-Nicolson method, you will need some way to solve a tridiagonal system.\nThe following is a simple function that performs a tridiagonal solve.\n\\li{a}, \\li{b}, and \\li{c} are assumed to contain the first subdiagonal, main diagonal, and first superdiagonal of the tridiagonal matrix.\n\\li{x} is assumed to be the right hand side of the equation.\nThis function overwrites \\li{x} with the solution to the system.\nAs has been shown in earlier labs, this function is better implemented in Cython, C, Fortran, or some other language with less overhead for array accesses and loops.\n\\begin{lstlisting}\ndef tridiag(a, b, c, x):\n    # Overrides c and x.\n    # The contents of x after computation will be the solution to the system.\n    size = x.size\n    temp = 0.\n    c[0] = c[0] / b[0]\n    x[0] = x[0] / b[0]\n    for n in range(size-2):\n        temp = 1. / (b[n+1] - a[n]*c[n])\n        c[n+1] *= temp\n        x[n+1] = (x[n+1] - a[n]*x[n]) * temp\n    x[size-1] = (x[size-1] - a[size-2]*x[size-2]) / (b[size-1] - a[size-2]*c[size-2])\n    for n in range(b.size-2, -1, -1):\n        x[n] = x[n] - c[n] * x[n+1]\n\\end{lstlisting}\n\nTo account for boundary conditions when using the Crank-Nicolson method, set the boundary points at the beginning of the iteration and leave them constant when applying $A$ like you did before.\nIn the Tridiagonal solve, replace the first row of the matrix $B$ with the first row of the identity and the last row of the matrix $B$ with the last row of the identity.\n\n\\begin{problem}\n\\label{prob:heat_exercise3}\nUsing the Crank Nicolson method, numerically approximate the solution $u(x,t)$ of the problem\n\\begin{align}\n\t\\begin{split}\n\t&{ } u_t = u_{xx}, \\quad x \\in [-12,12],\\quad t \\in [0,1],\\\\\n\t&{ } u(0,t) = 0,\\quad u(1,t) = 0,\\\\\n\t&{ } u(x,0) = \\max\\{1 - x^2,0\\}.\n\t\\end{split}\n\\end{align}\nDemonstrate that the numerical approximation at $t = 1$ converges to  $u(x,t=1)$.\nDo this by computing $U$ at $t=1$ using $20,40,80,160,320$, and $640$ steps.\nUse the same number of steps in both time and space.\nReproduce the loglog plot shown in Figure \\ref{fig:heatexercise3}.\nThe slope of the line there shows the proper rate of convergence.\n\nTo measure the error, use the solution with the smallest $h$ (largest number of intervals) as if it were the exact solution, then sample each solution only at the x-values that are represented in the solution with the largest $h$ (smallest number of intervals).\nUse the $\\infty$-norm on the arrays of values at those points to measure the error.\n\nNotice that, since the Crank-Nicolson method is unconditionally stable, there is no CFL condition and we can use the same number of spaces in time and space.\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% Dm = np.ones((1,m**2))\n% for j in range(0,D2.shape[1]):\n%     if (j%m)==m-1:\n%         D2[0,j]=0\n%         if (j%m)==0:\n%             D3[0,j]=a0\n% diags = np.array([0,-1,1,-m,m])\n% data = np.concatenate((D1,D2,D3,Dm,Dm),axis=0)\n% \n% A = 1./h**2.*spdiags(data, diags, m**2,m**2).asformat('csr') \n% \\end{verbatim}\n% \n% \\subsection{2D Heat Equation}\n% Recall that the collection of finite difference equations\n% \\[\n% \\nabla^2_h U_{ij} = 0, \\quad 1 \\leq i,j\\leq m,\n% \\]\n% can be written in matrix form as\n% $$AU + q  = 0$$\n% \n% The 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, \\]\n% is a second order accurate in both space and time. Basically we're using a midpoint scheme in time, \n% and 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.\t\n% \\end{align*}\n% \n% TODO: What size must the time step be to ensure stability? \n% \n% We will need to take many time steps, where many equations must be solved with the matrix $(I - \\frac{\\Delta t}{2}A)$.\n% The function \\texttt{factorized} from \\texttt{scipy.sparse.linalg} computes the LU decomposition of the matrix.\n% This decomposition reduces the time required for solving consecutive time steps. \n% ", "meta": {"hexsha": "b81b8020f2abe01e9fe9496a3c999aff407c2ead", "size": 18760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/HeatFlow/HeatFlow.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/HeatFlow/HeatFlow.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/HeatFlow/HeatFlow.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": 55.1764705882, "max_line_length": 295, "alphanum_fraction": 0.6849147122, "num_tokens": 6016, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8670357460591569, "lm_q1q2_score": 0.7911147733239703}}
{"text": "%!TEX root = main.tex\n\\section{Modelling}\nThis report will analyze how a virus outbreak evolves over time on a global scale. To do so, firstly it will be described how one might model a virus outbreak in a small uniform population. Secondly, this model will be expanded to include multiple population groups and their interactions.\n\n\\subsection{The SIR Model}\n\\subsubsection{Assumption}\nThe Susceptible-Infected-Removed model is a compartmental model assuming that within some subdivision of the population containing $N$ individuals, infection rate, cure rate and spread rates are i.i.d. within each of the 3 ``compartments'' of individuals:\n\\begin{itemize}\n\t\\item Susceptible to the virus\n\t\\item Infected by the virus\n\t\\item Recovered and immune to the virus (or alternatively dead)\n\\end{itemize} \nIn reality economic status, job type, air-conditioning etc. will affect how a virus spread \\cite{zika-modelling}, however, depending on the heterogeneity of the population these assumptions constitute a good approximation.\n\n\\subsubsection{Governing equations}\nThe SIR model is governed by 3 differential equations \\cite{sir-basics}:\n\\begin{align}\n\\frac{d S(t)}{dt} &= - \\beta \\frac{I(t)}{N} S(t)   \\label{eq-S}\\\\\n\\frac{d I(t)}{dt} &= \\beta \\frac{I(t)}{N} S(t) - \\gamma I(t)  \\label{eq-I}\\\\\n\\frac{d R(t)}{dt} &= \\gamma I(t) \\label{eq-R}\n\\end{align}\n$S(t), I(t)$ and $R(t)$ are functions describing the number of susceptible, infected and removed (recovered and immune or dead) individuals at time t, $\\beta$ is the rate of infection, $\\gamma$ the rate of removal (dead or cured) and $N$ the total number of individuals.\n\nFrom equation \\eqref{eq-S} and \\eqref{eq-I} one can see that susceptible individuals become infected by some ratio $\\beta$ and the ratio of already infected individuals. From \\eqref{eq-I} and \\eqref{eq-R} one can see that infected individuals recover with a constant factor $\\gamma$. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 1.0 \\linewidth]{plots/sir_one_region.pdf}\n\t\\caption{Numerical solution to the nonlinear ODE system defining the SIR model.}\n\t\\label{fig:sir_one_region}\n\\end{figure}\n\nFrom figure \\ref{fig:sir_one_region} it seen how the number of infected individuals increases quickly in the beginning, until a point where there are not enough susceptible to sustain the infection rate. This is also seen from the differential equations:\n\\begin{equation}\n\\frac{d I(t)}{dt} = \\frac{\\beta}{N} I(t) S(t) - \\gamma I(t) = 0 \\Leftrightarrow \\beta\\frac{S(t)}{N} = \\gamma\n\\end{equation}\n\nIn this hypothetical case almost everybody got infected, but that is not necessarily the case and depends entirely on $\\gamma$ and $\\beta$.\n\n\\subsection{Multi-region SIR}\nLet it now be given that instead of having a single population, one has $K$ populations each with initial $N_k, S_k(0), I_k(0)$ and $R_k(0)$. Each of these populations have a probability of transferring individuals to other populations regardless of whether the individual is susceptible, infected or recovered. The governing equations are modified to add the transfers and become\n\\begin{equation}\n\\begin{aligned}\n\\frac{d S_k(t)}{dt} &= - \\frac{\\beta}{N_k} I(t) S(t) + \\sum_{i=1}^K \\left( S_i(t)\\tau_{i,k} - S_k(t)\\tau_{k, i}\\right)   &\\forall k \\in [1, K]\\\\\n\\frac{d I_k(t)}{dt} &= \\frac{\\beta}{N_k} I(t) S(t) - \\gamma I(t) + \\sum_{i=1}^K \\left( I_i(t)\\tau_{i,k} - I_k(t)\\tau_{k, i}\\right)  &\\forall k \\in [1, K]\\\\\n\\frac{d R_k(t)}{dt} &= \\gamma I(t) + \\sum_{i = 1}^K \\left( R_i(t)\\tau_{i,k} - R_k(t)\\tau_{k, i}\\right) &\\forall k \\in [1, K]\n\\end{aligned}\n\\end{equation}\n, where $\\tau_{i,j}$ is the probability density of transferring from population $i$ to $j$ per individual.\n\nAs an example of the above system let $K=3$ and the non zero transfer probabilities be defined by the graph:\n\\begin{figure}[H]\n\t\\centering\n\\begin{tikzpicture}\n\n\\def \\n {3}\n\\def \\radius {1.5cm}\n\\def \\margin {12} % margin in angles, depends on the radius\n\n\\foreach \\s in {1,...,\\n}\n{\n\t\\node[draw, circle] at ({360/\\n * (\\s - 1)}:\\radius) {$\\s$};\n\t\\draw[->, >=latex] ({360/\\n * (\\s - 1)+\\margin}:\\radius) \n\tarc ({360/\\n * (\\s - 1)+\\margin}:{360/\\n * (\\s)-\\margin}:\\radius);\n}\n\\end{tikzpicture}\n\\end{figure}\nSolving this system numerically with the outbreak starting in region 1 one yields the following curves:\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 1.0 \\linewidth]{plots/sir_three_region_theory.pdf}\n\t\\caption{Numerical solution of the nonlinear ODE system defining a 3-region SIR model.}\n\\end{figure}\n\nFrom the above plot it's seen that the virus first spreads in region 1. After a certain time enough infected individuals have been transferred to region 2 where the infection then accelerates. This continues to region 3.\n\n\\subsection{Stocastic Model}\n\nTo simulate the multi-region SIR model stochastically, a binomial distribution is used to sample how many people get infected, removed and transferred. The binomial probability is chosen such that the distribution's expectation is the same as the terms in the differential equations,\n\\begin{equation*}\n\\begin{aligned}\n\\Delta I_{k,t} &= \\textsc{Binom}\\left(S_{k,t}, \\beta \\frac{I_{k, t}}{N_k}\\right) \\\\\n\\Delta R_{k,t} &= \\textsc{Binom}\\left(I_{k,t}, \\gamma\\right) \\\\\nS_{k,t} &= S_{k,t-1} - \\Delta I_{k,t} + \\sum_{i = 1}^K \\left(\\textsc{Binom}(S_{i,t-1}, \\tau_{i,k}) - \\textsc{Binom}(S_{k,t-1}, \\tau_{k,i})\\right) \\\\\nI_{k,t} &= I_{k,t-1} + \\Delta I_{k,t} - \\Delta R_{k, t} + \\sum_{i = 1}^K \\left(\\textsc{Binom}(I_{i,t-1}, \\tau_{i,k}) - \\textsc{Binom}(I_{k,t-1}, \\tau_{k,i})\\right) \\\\\nR_{k,t} &= R_{k,t-1} + \\Delta R_{k, t} + \\sum_{i = 1}^K \\left(\\textsc{Binom}(R_{i,t-1}, \\tau_{i,k}) - \\textsc{Binom}(R_{k,t-1}, \\tau_{k,i})\\right)\n\\end{aligned}\n\\end{equation*}\n\n, where $\\tau_{i,j}$ now is the discretized transfer probability.\n\n\\subsubsection{Transfer using Dirichlet distribution}\nA problem with this approach, is the small risk that $\\textsc{Binom}(S_{i, t-1}, \\tau_{i,k}) = 0$ and $\\textsc{Binom}(S_{k, t-1}, \\tau_{k,i}) = S_k$ or similar unfortunate combination which would cause $S_{k,t}$ to become negative (i.e. there is a small non zero probability that if transfers are drawn independently that an unfeasible state would occur). In practice, this is a big problem if the number of regions is large. The only way to avoid this problem is to sample all the transfers for a region simultaneously such that $\\sum_{i = 1}^K \\textsc{Binom}(S_{k,t-1}, \\tau_{k,i}) \\le S_{k, t}$.\n\nAs there does not exist a multivariate version of the binomial distribution, the Dirichlet distribution is used as an approximation. This is convenient because $\\sum_{i} X_{k, i} = 1$ if $\\mathbf{X}_k \\sim \\textsc{Dir}(\\boldsymbol{\\alpha}_k)$. In addition the Dirichlet distribution has support $X_{k, i} \\in [0, 1]$, thus by using $\\iround*{N_k X_{k, i}}$ as the transfer amount we are guaranteed that each transfer is between $0$ and $N_k$ and that the sum of transfers is $N_k$.\n\nFurthermore to reduced the amount of sampling, the total transfer $T$ is sampled instead of sampling $S$, $I$ and $R$ independently.\n\nTo approximate the binomial distribution using a Dirichlet distribution the expectation is set to be equal the expectation of the corresponding binomial distribution. To simplify notation region $k$ is omitted from the subscript and the summation of $\\tau_k$ and $\\alpha_i$ is introduced:\n\\begin{equation}\n\\tau_s = \\sum_{i = 1}^{K} \\tau_i, \\quad \\alpha_s = \\sum_{i = 1}^{K+1} \\tau_i\n\\end{equation}\n\n\\begin{equation}\n\\mathbb{E}[T_{i}] = \\mathbb{E}[N X_i] \\Leftrightarrow N \\tau_i = N \\frac{\\alpha_i}{\\alpha_s} \\quad \\forall i \\in K\n\\label{dir-expected-trans}\n\\end{equation}\n\nTo allow $\\sum_{i} X_{i,k} \\le 1$ the Dirichlet distribution is extended with another variable $X_{k, K+1}$, which is how many individuals region $k$ should not transfer.\n\\begin{equation}\n\\mathbb{E}[T_{K+1}] = \\mathbb{E}[N X_{K+1}] \\Leftrightarrow N \\left(1 - \\tau_s\\right) = N \\frac{\\alpha_{K+1}}{\\alpha_s}\n\\label{dir-expected-stay}\n\\end{equation}\n  \nThis is a linear system with n variables and n equations, but it turns out that it doesn't have full rank. To add another equation the variance of $T_{K+1}$ is also set to be equal.\n\\begin{equation}\n\\textsc{Var}[T_{K+1}] = \\textsc{Var}[N X_{K+1}] \\Leftrightarrow N\\tau_s (1 - \\tau_s) = N^2 \\frac{\\alpha_{K+1}(\\alpha_s - \\alpha_{K+1})}{\\alpha_s^2 (\\alpha_s + 1)}\n\\label{dir-var}\n\\end{equation}\n\nThe trick to solving this set of equations, is to isolate the sum $\\alpha_s$ from \\eqref{dir-expected-stay} and insert it into \\eqref{dir-expected-trans} and \\eqref{dir-var}.\n\\begin{align}\n\\alpha_s &= \\frac{\\alpha_{K+1}}{1 - \\tau_s} \\label{dir-expected-intermediate} \\\\\nN \\tau_i &= N \\frac{\\alpha_i}{\\frac{\\alpha_{K+1}}{1 - \\tau_s}} \\quad \\forall i \\in K \\\\\nN\\tau_s (1 - \\tau_s) &= N^2 \\frac{\\alpha_{K+1}\\left(\\frac{\\alpha_{K+1}}{1 - \\tau_s} - \\alpha_{K+1}\\right)}{\\left(\\frac{\\alpha_{K+1}}{1 - \\tau_s}\\right)^2 \\left(\\frac{\\alpha_{K+1}}{1 - \\tau_s} + 1\\right)} \\label{dir-var-intermediate}\n\\end{align}\n\n$\\alpha_{K+1}$ can now be isolated from \\eqref{dir-var-intermediate} yielding\n\\begin{equation}\n\\alpha_{K+1} = (N - 1) - \\tau_s (N - 1)\n\\end{equation}\n, inserting this into \\eqref{dir-expected-intermediate} gives:\n\\begin{equation}\n\\alpha_{i} = \\tau_i (N - 1)\n\\end{equation}\nUsing the $\\alpha_{i}$ solution $\\alpha_{K+1}$ can now be reformulated as\n\\begin{equation}\n\\alpha_{K+1} = (N - 1) - \\sum_{i=1}^K \\alpha_k\n\\end{equation}\n, which is computationally slightly more convenient.\n\nUsing this method for choosing $\\alpha$, gives the distribution as seen in figure \\ref{fig:dirichlet-validation-marginal}. As seen it has only minor errors when comparing to the binomial distribution.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 0.8 \\linewidth]{plots/dirichlet-validation-marginal}\n\t\\caption{Comparison of the marginal probability $P(\\iround*{N X_1})$ with the binomial distribution. The Dirichlet distribution was scaled up by $N$, $\\tau = (0.1, 0.1)$ and $N = 100$.}\n\t\\label{fig:dirichlet-validation-marginal}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width= 0.8 \\linewidth]{plots/dirichlet-validation-pdf}\n\t\\caption{Shows the Dirichlet pdf with $X_3 = 1- X_1 - X_2$. The Dirichlet distribution is scaled with $N$, $\\tau = (0.1, 0.1)$ and $N = 100$.}\n\\end{figure}\n\n\\subsection{Transfer probabilities}\n\nThe GLEaM model \\cite{GLEaM} uses a gravity law for transferring people between neighboring regions within the same country and airline data for transferring people between airports. Unfortunately the GLEaM paper does not specify all the parameters for the gravity law equation and our airline dataset does not contain the traveling frequency. Instead a much simpler model, where the proportional transfer expectation is fixed to some constant, is used:\n\\begin{equation}\n\\sum_{i = 1}^{K_k} \\tau_{k, i} = p_{transfer}\n\\end{equation}\n\nUsing an equal transfer probability one gets $\\tau_{k, i} = \\frac{p_{transfer}}{K_k}$. To ensure that the population doesn't change over time, this value is used to transfer both from $k$ to $i$ and from $i$ to $k$, the equivalent transfer probability of this is:\n\\begin{equation}\n\\tau_{k, i} = \\frac{p_{transfer}}{K_k} + \\frac{p_{transfer}}{K_i} = p_{transfer} \\left(\\frac{1}{K_k} + \\frac{1}{K_i}\\right)\n\\end{equation}\n\nFinally one should be wary of transferring more people to the destination than what is already in the destination. To prevent this the transfer probability is scaled with the relative population.\n\\begin{equation}\n\\tau_{k, i} = p_{transfer} \\frac{N_i}{N_k + N_i} \\left(\\frac{1}{K_k} + \\frac{1}{K_i}\\right)\n\\end{equation}\n\nUsing these transfer probabilities the total population for each region will be unchanged since the transfer expectation is symmetric:\n\\begin{equation}\n\\mathbb{E}[N_k \\tau_{k, i}] = \\mathbb{E}[N_i \\tau_{i, k}] \\Leftrightarrow N_k \\tau_{k, i} = N_i \\tau_{i, k}\n\\end{equation}\n", "meta": {"hexsha": "d1464c6fea487fecc0c4c9b0241a01e52d976a9a", "size": 11845, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/modelling.tex", "max_stars_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_stars_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/modelling.tex", "max_issues_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_issues_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/modelling.tex", "max_forks_repo_name": "FrederikWR/course-02443-stochastic-virus-outbreak", "max_forks_repo_head_hexsha": "4f1d7f1fa4aa197b31ed86c4daf420d5a637974e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 66.5449438202, "max_line_length": 598, "alphanum_fraction": 0.7175179401, "num_tokens": 3715, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869981319862, "lm_q2_score": 0.9032942119105695, "lm_q1q2_score": 0.7910933262791559}}
{"text": "\\subsection{Conservative Vector Fields}\r\n\\begin{definition}\r\n\tA vector field $\\vec{F}$ is conservative if $\\int\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}$ is the same for all $C$ connecting the same endpoints.\r\n\\end{definition}\r\n\r\n\\noindent\r\nIt's easy to see from this definition that vector fields of constant direction and magnitude, like $\\vec{F}=\\langle c, c, c \\rangle$ is conservative, as its line integral only depends on the curve.\\\\\r\n\r\n\\begin{theorem}\r\n\tIf $\\vec{F}$ is conservative, then $\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = 0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n\tWe can break the simple, closed curve, $C$ into two simple curves $C_1$ and $C_2$ that have the same endpoints and direction such that $C = C_1-C_2$.\r\n\t\r\n\t[INSERT IMAGE]\r\n\t\r\n\t\\noindent\r\n\tSo, \r\n\t\\begin{equation*}\r\n\t\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = \\int\\limits_{C_1}{\\vec{f} \\cdot \\mathrm{d}\\vec{r}} - \\int\\limits_{C_2}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}.\r\n\t\\end{equation*}\r\n\tSince $C_1$ and $C_2$ have the same direction and endpoints, and $\\vec{F}$ is conservative, the line integrals have the same value, $L$.\r\n\t\\begin{equation*}\r\n\t\t\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = L - L = 0\r\n\t\\end{equation*}\r\n\\end{proof}", "meta": {"hexsha": "e8adc5949208d2f36f592f973336f9b9fc99006e", "size": 1233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/conservativeVFs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/conservativeVFs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/conservativeVFs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 47.4230769231, "max_line_length": 200, "alphanum_fraction": 0.6731549067, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.7910933156950022}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 6}\n\nShow that there is no comparison sort whose running time is linear for at least half of the $n!$ inputs of length $n$.\nWhat about a fraction of $1/n$ of the inputs of length $n$? What about a fraction $1/2^n$?\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item As comparison sorts apply to decision trees, let's assume that the decision tree constructed for $n!$ inputs has height H.\nThus for half of $n!$ inputs,\n\n\\begin{equation}\\label{eq61}\n\\frac{n!}{2} \\leq n! \\leq 2^H\n\\end{equation}\n\nTaking logarithms with base 2 from both sides leads to Equation \\ref{eq62}\n\n\\begin{equation}\\label{eq62}\nh \\geq \\log_2 (\\frac{n!}{2})\n\\end{equation}\n\nWe know that any comparison sort algorithm requires $\\Omega(n \\log n)$ comparisons in the worst case.\nThus we can find a lower bound can be found for $\\log_2(\\frac{n!}{2})$.\n\n\\begin{equation}\\label{eq63}\nh \\geq \\log_2 (n!) - 1 = \\mathcal{O}(n \\log n)\n\\end{equation}\n\nTherefore, Equation \\ref{eq63} proves no comparison sort algorithm would do better than $\\mathcal{O}(n\\log n)$.\n\n\\item With the same reasoning, even for a fraction of $\\frac{1}{n}$ elements of the $n!$ inputs, we will have\n\n\\begin{equation}\\label{eq64}\nh \\geq \\log_2 \\frac{n!}{n} = \\log_2 {(n-1)!}\n\\end{equation}\n\nTherefore the lower bound would change to the following.\n\n\\begin{equation}\\label{eq65}\nh \\geq \\log_2 n! - \\log_2 n = \\mathcal{O}(n \\log n) - \\mathcal{O}(\\log n) = \\mathcal{O}(n \\log n)\n\\end{equation}\n\nThis shows that achieving $\\mathcal{O}(n)$ for comparison sort of  even for a fraction of $1/n$ of $n!$ inputs is not possible.\n\n\\item Similarly, for fraction of $\\frac{1}{2^{n}}$ elements of the $n!$ inputs, we will have\n\n\\begin{equation}\\label{eq66}\nh \\geq \\log_2 \\frac{n!}{2^{n}} = \\log_2 {n!} - \\log_2 {2^{n}}\n\\end{equation}\n\nTherefore the lower bound would change to the following.\n\n\\begin{equation}\\label{eq67}\nh \\geq \\log_2 {n!} - n \\geq \\mathcal{O}(n \\log n) - \\mathcal{O}(n) = \\mathcal{O}(n \\log n)\n\\end{equation}\n\n\\end{enumerate}\n\n\n\n", "meta": {"hexsha": "9ff2470096a553cb3274dbb3a95e8cc84bc05d2d", "size": 2357, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q06.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/hw02q06.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/hw02q06.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": 34.6617647059, "max_line_length": 128, "alphanum_fraction": 0.6588884175, "num_tokens": 752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.894789457685656, "lm_q1q2_score": 0.7910290349537822}}
{"text": "\\section{Needles in a Haystack: the Class NP}\n\n\\subsection{Exercises}\n\n\\subsubsection{Exercise 1}\nIf a 2-coloring of a graph exists, then we can flip all of the colors in the graph to produce another valid\ntwo-coloring. Thus, we can proceed to construct a two-coloring by picking an uncolored vertex and then coloring\nit an arbitrary color, which then determines the colors of all of the vertices it is connected to. We do\nthis until either the graph is completely colored, or until we need to recolor an already colored vertex\n(in which case the graph is not 2-colorable). This algorithm is linear in the number of edges and vertices of the graph, so 2-coloring is in $P$.\n\n\\subsubsection{Exercise 2}\n\n\\subsubsection{Exercise 3}\nSuppose we wish to determine whether a graph $G$ with  $n$ vertices is  $k$-colorable. We can extend $G$ to\nbe a graph $G'$ with $n + 1$ vertices by adding an additional vertex that we then connect to all of the original\n$n$ vertices of  $G$ (this can be done in  $O(n)$ time). By construction, $G'$ is  $(k + 1)$-colorable if and\nonly if its subgraph $G$ is $k$-colorable (since node $n + 1$ is connected to all of $G$, the subgraph $G$\nmust be colored with only $k$ colors). \n\n\\subsubsection{Exercise 4}\nSince boolean operations are commutative, we can write $\\phi'$ as:\n\\begin{align*}\n        \\phi'(p, q, r) &= (p \\vee q) \\wedge (p \\vee \\bar{q}) \\wedge (r \\vee q) \\wedge (r \\vee \\bar{q}) \\wedge (\\bar{p} \\vee \\bar{r}) \\\\\n                       &= p \\wedge r \\wedge (\\bar{p} \\vee \\bar{r})\n\\end{align*}\nwhich is clearly not satisfiable, since $p = 1, r = 1 \\implies (\\bar{p} \\vee \\bar{r}) = 0$.\n\n\\subsubsection{Exercise 5}\nFor a graph to be 3-colorable (let our 3 colors be R, G, and B), each vertex in the graph must be colored\neither R, G, or B, and no adjacent vertices may have the same color. If we let $v_r^{(i)}, v_g^{(i)}, v_b^{(i)}$\ndenote boolean variables that are true when vertex $i$ is colored R, G, and B respectively and $N(i)$ denote\nall of the neighbors of vertex $i$, we can translate 3-colorability into the following boolean expression\nfor each vertex $i$:\n\\begin{align*}\n\\bigwedge_i (v_r^{(i)} \\vee v_g^{(i)} \\vee v_b^{(i)}) \\wedge \\big((v_r^{(i)} \\wedge_{j \\in N(i)} \\bar{v}_r^{(j)}) \\vee (v_b^{(i)} \\wedge_{j \\in N(i)} \\bar{v}_b^{(j)}) \\vee (v_g^{(i)} \\wedge_{j \\in N(i)} \\bar{v}_g^{(j)})\\big)\n\\end{align*}\nRepeatedly applying the distributive law to the part of the above expression that consists of ors of ands\nproduces a CNF expression that must be true for every vertex $i$. Since satisfiability of the resulting\nexpression corresponds directly to whether the original graph is 3-colorable or not, we have that\n3-colorability can be reduced to SAT.\n\n\\subsubsection{Exercise 6}\nFactoring out $x$ in the first expression leads to $x \\vee (z_1 \\wedge \\bar{z}_1) = x$. The second expression\nis even more straightforward; we just factor out $(x \\vee y)$.\n\n\\subsubsection{Exercise 7}\nIf any of the $x_i$ are true, then it is clear that the right-hand side can be made true by picking $(z_1, z_2)$\nsuch that the (at most) two clauses not containing a true $x_i$ value can be made true.\nFor the other direction, iterating through all possible $(z_1, z_2)$ values shows that the right-hand side is\nonly true if at least one of the $x_i$ (where $i$ depends on the values of $z_1, z_2$) is true.\n\nThere is probably a better approach here than the above ``brute force'' reasoning; I should come back to this.\n\n\\subsubsection{Exercise 8}\nThe approach from Exercise 5 still works.\n\n\\subsubsection{Exercise 9}\nThere are only $(2n)^k$ possible unique $k$-clauses (each of the $k$ literals can either be one of the \nvariables or its complement), so the number of bits needed to specify a satisfiability problem is polynomial\nin the number of variables (each of which requires only a single bit).\n", "meta": {"hexsha": "325e8aa7b9913cc4fedc89b66b94ad51158005b1", "size": 3838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Nature_of_Computation_Moore_Mertens/chapter_4.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_4.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_4.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.9032258065, "max_line_length": 224, "alphanum_fraction": 0.7154768108, "num_tokens": 1160, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.8947894639983208, "lm_q1q2_score": 0.7910290268658448}}
{"text": "\n\\subsection{Manifolds, charts and atlases}\n\nA manifold is a set of points and associated charts.\n\nA chart is a mapping from each point in a subset of the manifold to a point in a vector space.\n\nThese charts are invertible. If we are given coordinates, we can identify the point in the manifold it comes from.\n\nFor each point we have a topological neighbourhood. For each point in the neighbourhood, we can map to an element in the tangent space.\n\n\\subsubsection{Example: The sphere}\n\nWe can map a hemisphere to a subset of \\(R^2\\). Given a point in \\(R^2\\) we can identify a specific point on the hemisphere, and given a s specific point on the hemisphere we can identify a point in \\(R^2\\).\n\n\\subsubsection{Universal charts}\n\nIf the vector space is flat and non-repeating, then a single chart can be used to map the whole manifold.\n\n\\subsubsection{Atlases}\n\nIf we have a collection of charts which covers each point needs to be covered at least once, we have an atlas. Each chart needs to be to the same dimensional vector space.\n\n\n", "meta": {"hexsha": "c0ddadf94955737fbba60a46ea415e15fda17c68", "size": 1034, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/manifoldsTopological/01-01-chart.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/manifoldsTopological/01-01-chart.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/manifoldsTopological/01-01-chart.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": 41.36, "max_line_length": 207, "alphanum_fraction": 0.7707930368, "num_tokens": 236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9263037302939515, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.790982573570339}}
{"text": "\\subsection*{Ex.29.2-6}\n\\subsubsection{Solve the maximum--bipartite--matching problem}\n\nLet $G, V, E$ and $G', V', E'$ be given as in the section--26.3.\n\nFrom Corollary~26.11 we know that finding a max flow in $G'$ also tells us what the maximum matching in $G$ is. So we want to define a max flow problem.\n\\\\\nWe follow the approach as they do in the book, as section 29.2 \\emph{Maximum flow}.\n\nDefine the capacity of the edges as\n$$\nc(u,v) = \n\\begin{cases}\n1, & (u,v)\\in E'\\\\\n0, & \\text{else}\n\\end{cases}\n$$\n\nThe the problem can be stated as\n\n\\begin{align*}\n&\\max      \\quad  &\\sum_{v\\in V'}f_{sv}  &- \\sum_{v\\in V'}f_{vs}   &\\\\\n&\\text{s.t.}      & f_{uv}               &\\leq c(u,v)              &\\text{for all } u,v \\in V'\\\\\n&                 & \\sum_{v\\in V'}f_{uv} &= \\sum_{v\\in V'}f_{vu}   &\\text{for all } u \\in V\\\\\n&                 & f_{uv}               &\\geq 0                   &\\text{for all } u,v \\in V'\n\\end{align*}\n\nThis maximization problem will solve the max flow problem, which by Corollary~26.11 solves the maximum--bipartite--matching problem.", "meta": {"hexsha": "3d8c8aa470cabb9535f257191bc6b5cbcee08622", "size": 1062, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.29.2-6.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge2/Ex.29.2-6.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge2/Ex.29.2-6.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9285714286, "max_line_length": 152, "alphanum_fraction": 0.5856873823, "num_tokens": 372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7909825631776035}}
{"text": "\\chapter{Adaptive basis function models}\n\n\n\\section{AdaBoost}\n\n\n\\subsection{Representation}\n\\begin{equation}\ny=\\text{sign}(f(\\vec{x}))=\\text{sign}\\left(\\sum\\limits_{i=1}^m \\alpha_mG_m(\\vec{x})\\right)\n\\end{equation}\nwhere $G_m(\\vec{x})$ are sub classifiers.\n\n\n\\subsection{Evaluation}\n\\begin{equation} \\nonumber\nL(y,f(\\vec{x}))=\\exp[-yf(\\vec{x})] \\text{  i.e., exponential loss function}\n\\end{equation}\n\n\\begin{equation}\n(\\alpha_m,G_m(x))= \\arg\\min_{\\alpha,G} \\sum_{i=1}^N \\exp{[-y_i(f_{m-1}(\\vec{x}_i)+\\alpha G(\\vec{x}_i))]}\n\\end{equation}\n\nDefine $\\bar{w}_{mi}=\\exp{[-y_i(f_{m-1}(\\vec{x}_i)]}$, which is constant w.r.t. $\\alpha, G$\n\\begin{equation}\n(\\alpha_m,G_m(x))= \\arg\\min_{\\alpha,G} \\sum_{i=1}^N {\\bar{w}}_{mi} \\exp{(-y_i \\alpha G(x_i))}\n\\end{equation}\n\n\n\\subsection{Optimization}\n\n\n\\subsubsection{Input}\n\\begin{eqnarray*}\n& \\mathcal{D}=\\{(\\vec{x}_1,y_1),(\\vec{x}_2,y2),\\dots,(\\vec{x}_N,y_N)\\} \\\\\n& \\quad \\text{where } \\vec{x}_i \\in \\mathbb{R}^D,\\ y_i \\in \\{-1,+1\\} \\\\\n& \\text{ Weak classifiers } \\{G_1,G_2,\\dots,G_m\\}\n\\end{eqnarray*}\n\n\n\\subsubsection{Output}\nFinal classifier: $G(x)$\n\n\n\\subsubsection{Algorithm}\n\\begin{enumerate}\n\\item Initialize the weights' distribution of training data(when $m=1$)\n\\begin{equation}\\nonumber\n\\mathcal{D}_0=(w_{11},w_{12},\\cdots,w_{1n})=(\\frac{1}{N},\\frac{1}{N},\\cdots,\\frac{1}{N})\n\\end{equation}\n\\item Iterate over $m=1,2,\\dotsc,M$\n\\subitem (a) Use training data with current weights' distribution $\\mathcal{D}_m$ to get a classifier $G_m(\\vec{x})$\n\\subitem (b) Compute the error rate of $G_m(\\vec{x})$ over the training data \\\\\n\\begin{equation}\ne_m=P(G_m(\\vec{x}_i)\\neq y_i)=\\sum_{i=1}^N {w_{mi}\\mathbb{I}(G_m(\\vec{x}_i) \\neq y_i)}\n\\end{equation}\n\n\\subitem (c) Compute the coefficient of classifier $G_m(x)$\n\\begin{equation}\n\\alpha_m = \\frac{1}{2}\\log{\\frac{1-e_m}{e_m}}\n\\end{equation}\n\\subitem (d) Update the weights' distribution of training data\n\\begin{equation}\nw_{m+1,i}=\\frac{w_{mi}}{Z_m}\\exp(-\\alpha_m y_i G_m(\\vec{x}_i))\n\\end{equation}\nwhere $Z_m$ is the normalizing constant\n\\begin{equation}\nZ_m=\\sum_{i=1}^N w_{mi}\\exp(-\\alpha_m y_i G_m(\\vec{x}_i))\n\\end{equation}\n\n\\item Ensemble $M$ weak classifiers\n\\begin{equation}\nG(x)=\\text{sign}f(\\vec{x})=\\text{sign}\\left[\\sum_{m=1}^M \\alpha_m G_m(\\vec{x})\\right]\n\\end{equation}\n\\end{enumerate} \n\n\\subsection{The upper bound of the training error of AdaBoost}\n\\begin{theorem}\nThe upper bound of the training error of AdaBoost is \n\\begin{equation}\n\\frac{1}{N} \\sum_{i=1}^N \\mathbb{I}(G(\\vec{x}_i)\\neq y_i) \\leq \\frac{1}{N} \\sum_{i=1}^N \\exp(-y_i f(\\vec{x}_i))=\\prod_{m=1}^M Z_m\n\\end{equation}\n\nNote: the following equation would help proof this theorem\n\\begin{equation}\nw_{mi}\\exp(-\\alpha_m y_i G_m(\\vec{x}_i))=Z_m w_{m+1,i}\n\\end{equation}\n\\end{theorem}\n", "meta": {"hexsha": "2ff59ee28fa46fadbfd0913a627982a33cecc5a6", "size": 2746, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Adaptive basis function 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/Adaptive basis function 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/Adaptive basis function 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": 31.2045454545, "max_line_length": 129, "alphanum_fraction": 0.6744355426, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7909604738278346}}
{"text": "\\chapter{The Fundamental Theory For Spectral Methods}\n\\label{Chapter_2}\n    \n\t\\vspace{0.3cm}\n\tIn this chapter, we will present the elements necessary to solve partial differential equations using spectral methods given as follows\n\t\\begin{align}\n\t\\label{general_problem}\n\t\\left \\lbrace \\begin{array}{ll}\n\t\t&\\frac{\\partial u}{\\partial t} = \\mathcal{L} u, \\hspace{3mm} x \\in I, \\hspace{3mm} t > 0,\\\\\n\t\t\\\\\n\t\t&u(x, 0) = g(x), \\hspace{9mm} x \\in I, \n\t\t\\end{array}  \\right .\n\t\\end{align}\n\twhere $u$ is defined in some Hilbert space $\\mathcal{H}$, with initial condition $g(x) \\in \\mathcal{H}$ and $\\mathcal{L}$ is some spatial differential operator, which allows us to represent the previous problem in another whose solution $u$ will be given by a linear combination of already known functions. \\\\\n\t\n\tTo do this, suppose that $\\mathcal{H}$ is a separable Hilbert space with the inner product $\\langle \\cdot, \\cdot \\rangle$. Therefore, we can represent the function $u$ in terms of a known orthonormal base of $\\mathcal{H}$, which we will denote as $\\{\\phi_k \\}_{k \\in I}$, given as follows \n\t\\begin{align*}\n\t\t\\displaystyle u = \\sum_{k \\in I} \\langle \\phi_k, u \\rangle \\phi_k.\n\t\\end{align*}\n\t\n\tThere is a wide variety of families of base functions, which define different spectral methods. In this chapter, we will consider the well-known Fourier basis given by\n\t\\begin{align}\n\t\t\\label{base_phi}\n\t\t\\phi_n (x) = e^{inx}.\n\t\\end{align}\n\tthat form an orthogonal set with the standard interior product $L^2$ in the interval $(0, 2 \\pi)$, that is,\n\t\\begin{align}\n\t\\label{ortho_phi}\n\t\\displaystyle \\int_{0}^{2\\pi} \\phi_k (x) \\overline{\\phi_l (x)} dx = 2 \\pi \\delta{kl} = \\left \\lbrace \\begin{array}{ll}\n\t0 \\hspace{3mm} &\\text{if} \\hspace{3mm} k \\neq l, \\\\\n\t2 \\pi &\\text{if} \\hspace{3mm} k = l.\n\t\\end{array}  \\right.\n\t\\end{align}\n\t\n\tWe will denote as $B = span\\{e^{inx}: |n| \\leq \\infty \\}$ the set containing the Fourier bases. Therefore, we can define the Fourier series $F[u]$ for $u(x) \\in L^2 [0, 2\\pi]$ as follows \n\t\\begin{equation}\n\t\\label{fourier_series}  \n\t\tF[u] \\equiv \\displaystyle \\sum_{ |n| \\leq \\infty} \\hat{u}_{n} e^{inx},\n\t\\end{equation}\n\twhere\n\t\\begin{align}\n\t\\label{coeff_fourier}\n\t\\hat{u}_n = \\frac{1}{2 \\pi} \\displaystyle \\int_{0}^{2 \\pi} u(x) e^{-inx} dx, \\hspace{3mm}  k = 0, \\pm 1, \\pm 2, \\dots.\n\t\\end{align}\n\twhich is known as the classical continuous series of trigonometric polynomials, where $\\hat{u}_{n}$ are the Fourier coefficients. \\\\\n    \n    It is important noted that the integrals in (\\ref{coeff_fourier}) exist if $u$ is Riemann-integrable, i.e., if $u$ is bounded and piecewise continuous in $(0, 2 \\pi)$. More generally, the Fourier coefficients are defined for any function that is integrable in the Lebesgue sense. Also the relation (\\ref{coeff_fourier}) associates with $u$ a sequence of complex numbers called the Fourier transform of $u$. It is possible as well to introduce a Fourier cosine transform and a Fourier sine transform of $u$, respectively, through the formulas\n    \\begin{align}\n    \\label{coeff_a_n}\n    \ta_n = \\frac{1}{2 \\pi} \\displaystyle \\int_{0}^{2 \\pi} u(x) \\cos(nx) dx, \\hspace{3mm}  n = 0, \\pm 1, \\pm 2, \\dots,\n    \\end{align}\n    and\n    \\begin{align}\n    \\label{coeff_b_n}\n    \tb_n = \\frac{1}{2 \\pi} \\displaystyle \\int_{0}^{2 \\pi} u(x) \\sin(nx) dx, \\hspace{3mm}  n = 0, \\pm 1, \\pm 2, \\dots.\n    \\end{align}\n    The three Fourier transforms of $u$ are related by the formula $\\hat{u}_n = a_n - ib_n$ for $n = 0, \\pm 1, \\pm 2, \\dots$. Moreover, if $u$ is a real valued function, $a_n$ and $b_n$ are real numbers, and $\\hat{u}_{-n} = \\hat{u}_n$. \\\\\n\t\n\tBased on the above, we will present two tools to build the methods that will be used in Chapter \\ref{Chapter_3}, and that will be developed independently in the following two sections. In the first section, we will see that with the continuous Fourier expansion we can define a projection operator on a space of finite dimension that will allow us to approximate a function and its derivatives. In the second and last section, due to the complexity of the calculation of the previous integrals, we will see that it is possible to use quadrature rules to approximate them, and thus define an interpolation operator that will give us a discrete representation for a function and its derivatives.\n\t\n\tFor these two operators, at the end of each section we will discuss the factors that determine the behavior of the series when used to approximate smooth functions, showing how fast they approach, when, and in what sense they are convergent.\n\t\n\t\\newpage\n\t\\input{preliminaries/Projection_Operator}  \n\t\n\t\\newpage\n\t\\input{preliminaries/Interpolation_Operator}\t\n", "meta": {"hexsha": "cfbe1ba85660559d954e504c610d0370654331d8", "size": 4655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/preliminaries/Fundamental_Theory.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/preliminaries/Fundamental_Theory.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/preliminaries/Fundamental_Theory.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": 68.4558823529, "max_line_length": 694, "alphanum_fraction": 0.7059076262, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92414182206801, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7909278349795166}}
{"text": "\\section{Sentenial Logic}\n\\newcommand{\\definition}[1]{\\textbf{#1}}\n\\subsection{Deductive Reasoning and Logical Connectives}\n\\subsection{Truth Tables}\n\\definition{DeMorgan's laws}\n\\[\n\\lnot (P \\land Q) \\equiv \\lnot P \\lor \\lnot Q\n\\]\n\\[\n\\lnot (P \\lor Q) \\equiv \\lnot Q \\land \\lnot Q\n\\]\n\\definition{Commutative laws}\n\\[\nP \\land Q \\equiv Q \\land P\n\\]\n\\[\nP \\lor Q \\equiv Q \\lor P\n\\]\n\\definition{Associative laws}\n\\[\nP \\land (Q \\land R) \\equiv (P \\land Q) \\land R\n\\]\n\\[\nP \\lor (Q \\lor R) \\equiv (P \\lor Q) \\lor R\n\\]\n\\definition{Idempotent laws}\n\\[\nP \\land \\equiv P\n\\]\n\\[\nP \\lor P \\equiv P\n\\]\n\\definition{Distributive laws}\n\\[\nP \\land (Q \\lor R) \\equiv (P \\land Q) \\lor (P \\land R)\n\\]\n\\[\nP \\lor (Q \\land R) \\equiv (P \\lor Q) \\land (P \\lor R)\n\\]\n\\definition{Absorption laws}\n\\[\nP \\lor (P \\land Q) \\equiv P\n\\]\n\\[\nP \\land (P \\lor Q) \\equiv P\n\\]\n\\definition{Double Negation law}\n\\[\n\\lnot \\lnot P \\equiv P\n\\]\n\\definition{Tautology laws}\n\\[\nP \\land \\text{(a tautology)} \\equiv P\n\\]\n\\[\nP \\lor \\text{(a tautology)} \\equiv \\text{(a tautology)}\n\\]\n\\[\n\\lnot \\text{(a tautology)} \\equiv \\text{(a contradiction)}\n\\]\n\\definition{Contradiction laws}\n\\[\nP \\land \\text{(a contradiction)} \\equiv \\text{(a contradiction)}\n\\]\n\\[\nP \\lor \\text{(a contradiction)} \\equiv P\n\\]\n\\[\n\\lnot \\text{(a contradiction)} \\equiv \\text{(a tautology)}\n\\]\n\\subsection{Variables and Sets}\n\\[\n\\mathbb{R}^{+,-} = \\{x | x \\text{ is a real number}\\}\n\\]\n(a number that can be written on the number line)\n\\[\n\\mathbb{Q}^{+,-} = \\{x | x \\text{ is a rational number}\\}\n\\]\n(a number that can be written as a fraction $\\cfrac{p}{q}$)\n\\[\n\\mathbb{Z}^{+,-} = \\{x | x \\text{ is an integer}\\} = \\{ \\ldots, -3, -2, -1, 0, 1, 2, 3, \\ldots \\}\n\\]\n\\[\n\\mathbb{N} = \\{x | x \\text{ is a natural number}\\} = \\{0, 1, 2, 3, \\ldots \\}\n\\]\n\\subsection{Operations on Sets}\n\\definition{Intersection of two sets A and B}\n\\[\nA \\cap B = \\{ x | x \\in A \\text{ and } x \\in B \\}\n\\]\n\\definition{Union of two sets A and B}\n\\[\nA \\cup B = \\{ x | x \\in A \\text{ or } x \\in B \\}\n\\]\n\\definition{Difference of A and B}\n\\[\nA \\setminus B = \\{ x | x \\in A \\text{ and } x \\notin B \\}\n\\]\n\\definition{A is a subset of B if every element of A is also an element of B}\n\\[\nA \\subseteq B\n\\]\n\\definition{A and B are disjoint if they have no elements in common}\n\\[\nA \\land B = \\emptyset\n\\]\n\\subsection{The Conditional and Biconditional Connectives}\n\\definition{Conditional laws}\n\\[\nP \\to Q \\equiv \\lnot P \\lor Q\n\\]\n\\[\nP \\to Q \\equiv \\lnot (P \\land \\lnot Q)\n\\]\n\\definition{Contrapositive law}\n\\[\nP \\to Q \\equiv \\lnot Q \\to \\lnot P\n\\]\n", "meta": {"hexsha": "ebcb8d45b7d4630d47919e499c79d511630dbf49", "size": 2528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter1.tex", "max_stars_repo_name": "bdkoepke/htpi", "max_stars_repo_head_hexsha": "4acf00770954aa0e3484a3e4b31a8c3ed9dd2538", "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": "chapter1.tex", "max_issues_repo_name": "bdkoepke/htpi", "max_issues_repo_head_hexsha": "4acf00770954aa0e3484a3e4b31a8c3ed9dd2538", "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": "chapter1.tex", "max_forks_repo_name": "bdkoepke/htpi", "max_forks_repo_head_hexsha": "4acf00770954aa0e3484a3e4b31a8c3ed9dd2538", "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": 21.243697479, "max_line_length": 97, "alphanum_fraction": 0.6155063291, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567177, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.790907603925508}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%\n% Useful Observation %\n%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Useful Observations}\n\n\\begin{observation}{}{Bounding Measures}\n\n    The following inequalities to bound measures are \\emph{always} applicable, for \\emph{any} sets $A, B, C \\in \\CalF$:\n\n    \\begin{enumerate}\n        \\setlength{\\parskip}{0em}\n        \\item ``Dropping a set in an intersection gives an upper bound'' $\\Leftrightarrow$ ``Relaxing constraints'':\n\n            \\begin{align*}\n                \\mu(A \\cap B) \\leq \\mu(A).\n            \\end{align*}\n        \\item ``Dropping a set in a union gives an lower bound'':\n\n            \\begin{align*}\n                \\mu(A \\cup B) \\geq \\mu(A).\n            \\end{align*}\n        \\item ``Adding a set in a union gives an upper bound'' $\\Leftrightarrow$ ``Adding constraints'':\n\n            \\begin{align*}\n                \\mu(A \\cup B) \\leq \\mu(A \\cup B \\cup C).\n            \\end{align*}\n        \\item ``Intersections are less than a set and a set is less than a union'':\n\n            \\begin{align*}\n                \\mu(A \\cap B) \\leq \\mu(A) \\leq \\mu(A \\cup B).\n            \\end{align*}\n    \\end{enumerate}\n\n\\end{observation}\n\n\\begin{observation}{}{Adding $\\Omega$ by Intersection}\n\n    If you would like to introduce a property to an existing set $A$ to make it easier to work with, for instance easier to bound, you can add an intersection with $\\Omega$:\n\n        \\begin{align*}\n            \\mu(A) = \\mu(\\Omega \\cap A).\n        \\end{align*}\n\n    Then $\\Omega$ can be split into the set $B$ that represents the property and $B^C$ that does not have the property, where $\\Omega = B \\cup B^C$. Then:\n\n        \\begin{align*}\n            \\mu(A) = \\mu(\\Omega \\cap A) = \\mu((B \\cup B^C) \\cap A) = \\\\\n            \\mu((B \\cup B^C) \\cap A) = \\mu((B \\cap A) \\cup (B^C \\cap A)).\n        \\end{align*}\n\n    Using $\\sigma$-additivity, we get:\n\n        \\begin{align*}\n            \\mu(A) = \\mu(B \\cap A) + \\mu(B^C \\cap A).\n        \\end{align*}\n\n    Then by the observation on bounding measures, this can be made into an inequality:\n\n        \\begin{align*}\n            \\mu(A) &= \\mu(B \\cap A) + \\mu(B^C \\cap A) \\\\\n            &\\leq \\mu(B \\cap A) + \\mu(B^C).\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Increasing Sequence of Sets}\n\n    For an \\emph{increasing} sequence of sets $(A_n)_{n=1}^{\\infty}$ we can define:\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} A_n \\coloneqq \\bigcup_{n=1}^{\\infty} A_n\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Decreasing Sequence of Sets}\n\n    For an \\emph{decreasing} sequence of sets $(A_n)_{n=1}^{\\infty}$ we can define:\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} A_n \\coloneqq \\bigcap_{n=1}^{\\infty} A_n\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{$\\mu$-Almost Everywhere Finite, I}\n\n    If $f: \\Omega \\to \\mathbb{R}$ is $\\mu$-a. e. finite, then note that if $A_n \\coloneqq \\{ |f| \\geq n \\}$, then $(A_n)_{n=1}^{\\infty}$ is a decreasing sequence and so:\n\n        \\begin{align*}\n            \\mu\\left(\\bigcap_{n=1}^{\\infty} A_n\\right) = \\mu\\left(\\lim_{n \\to \\infty} A_n\\right) = \\mu(|f| = \\infty) \\\\ = 0.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{$\\mu$-Almost Everywhere Finite, II}\n\n    If $f: \\Omega \\to \\mathbb{R}$ is $\\mu$-a. e. finite, then observe\n\n        \\begin{align*}\n            \\mu(|f| = \\infty) = \\lim_{R \\to \\infty} \\mu(|f| \\geq R) = 0.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Almost Surely Finite, II}\n\n    If $f: \\Omega \\to \\mathbb{R}$ is a.s. finite, then observe\n\n        \\begin{align*}\n            P(|f| = \\infty) = \\lim_{R \\to \\infty} P(|f| \\geq R) = 0. \\\\\n            \\iff P(|f| < \\infty) = \\lim_{R \\to \\infty} P(|f| < R) = 1.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Almost Surely Finite}\n\n    If $f: \\Omega \\to \\mathbb{R}$ is a. s. finite, then note that if $A_n \\coloneqq \\{ |f| \\geq n \\}$, then $(A_n)_{n=1}^{\\infty}$ is a decreasing sequence and so:\n\n        \\begin{align*}\n            P\\left(\\bigcap_{n=1}^{\\infty} A_n\\right) = P\\left(\\lim_{n \\to \\infty} A_n\\right) = P(|f| = \\infty) \\\\ = 0.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{$\\mu$-Almost Everywhere Convergence I}\n\n    If $f_n \\to f$ $\\mu$-a.e., then $\\mu(f_n \\not\\to f) = 0$.\n\n\\end{observation}\n\n\\begin{observation}{}{$\\mu$-Almost Everywhere Convergence II}\n\n    If $A \\in \\CalF$ is a set such that $\\mu(A) = 0$ and\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} |f_n(\\omega) - f(\\omega)| = 0 \\quad \\forall \\omega \\in A^C,\n        \\end{align*}\n\n    then $f_n \\to f$ $\\mu$-almost everywhere.\n\n\\end{observation}\n\n\\begin{observation}{}{Almost Sure Convergence}\n\n    If $f_n \\to f$ a.s., then $P(f_n \\not\\to f) = 0$ or equivalently $P(f_n \\to f) = 1$.\n\n\\end{observation}\n\n\\begin{observation}{}{Splitting Measures of Inequalities}\n\n    Let $f,g$ be measurable functions and $a \\in \\mathbb{R}$, then observe that:\n\n        \\begin{align*}\n            \\mu(|f| \\geq a) \\leq \\mu\\left( |f - g| \\geq \\frac{a}{2} \\right) + \\mu\\left( |g| \\geq \\frac{a}{2} \\right)\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Using Borel-Cantelli}\n\n    If you can define sets $(A_k)_{k=1}^{\\infty}$ such that $\\mu(A_k) \\leq 1/k^2$, then you can use Borel-Cantelli as:\n\n        \\begin{align*}\n            \\sum_{k=1}^{\\infty} \\mu(A_k) \\leq \\sum_{k=1}^{\\infty} \\frac{1}{k^2} < \\infty.\n        \\end{align*}\n\n    In fact, the choice of $1/k^2$ is more or less arbitrary. This technique would work with any $r_k$ s.t. $\\sum_{k=1}^{\\infty} r_k < \\infty$ and $\\mu(A_k) \\leq r_k$. Caution: $r_k = 1/k$ does \\emph{not} work.\n\n\\end{observation}\n\n\\begin{observation}{}{Function As Integral}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative} measurable function, the obvserve that\n\n        \\begin{align*}\n            f(\\omega) = \\int\\limits_0^{f(\\omega)} \\, dx = \\int\\limits_0^{\\infty} \\Indicator{x \\leq f(\\omega)} \\, dx\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Bounding Complement Probabilities}\n\n    Note that $1 - x \\leq e^{-x}$. Therefore, we can bound probabilities of a product of complement events, for instance:\n\n        \\begin{align*}\n            \\prod_{n = 1}^{\\infty} P(A_n^C) = \\prod_{n = 1}^{\\infty} [1 - P(A_n)] \\leq \\\\ \\prod_{n = 1}^{\\infty} e^{-P(A_n)} = e^{\\sum_{n = 1}^{\\infty} -P(A_n)}\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Interchanging Expectation \\& Infinite Sum}\n\n    Observe that if $f$ is \\emph{non-negative}, then:\n\n        \\begin{align*}\n            E\\left(\\sum_{n=1}^{\\infty} f(X_n)\\right) = \n            E\\left(\\lim_{N \\to \\infty} \\sum_{n=1}^{N} f(X_n)\\right) = \\\\\n            = \\lim_{N \\to \\infty} \\sum_{n=1}^{N} E f(X_n) = \n            \\sum_{n=1}^{\\infty} E f(X_n),\n        \\end{align*}\n\n    where pulling the expectation through the sum can be done due to the Monotone Convergence Theorem, as $\\sum_{n=1}^{N} f(X_n)$ is an increasing sequence of \\emph{non-negative} random variables.\n\n\\end{observation}\n\n\\begin{observation}{}{Markov-Chebyshev's Inequality \\& Norm}\n\n    The following is the general Markov-Chebyshev Inequality rewritten using the norm instead of an integral. Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative}, measurable function in $L_{\\alpha}(\\Omega, \\CalF, \\mu)$, then\n\n        \\begin{align*}\n            \\mu(f \\geq \\lambda) \\leq \\lambda^{-\\alpha} \\Norm{f}_{\\alpha}^{\\alpha} \\, d\\mu \\quad \\forall \\lambda > 0, \\alpha > 0.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Distribution Function as Expectation}\n\n    Let $X$ be a random variable and $F_X$ its distribution function. Then:\n\n        \\begin{align*}\n            F_X(a) = P(X \\leq a) = \\int_{\\Omega} \\Indicator{X \\leq a} \\, dP = E\\Indicator{X \\leq a}.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Distribution Function as Expectation, II}\n\n    Let $X$ be a random variable and $F_X$ its distribution function. Then:\n\n        \\begin{align*}\n            F_X(x + a) - F_X(x) = E\\Indicator{x < X \\leq x + a}.\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Tightening/Relaxing Expectations}\n\n    Let $X$ be a random variable and $\\lambda \\in \\mathbb{R}$. Then the following  holds:\n\n        \\begin{align*}\n            EX \\geq E(\\Indicator{X \\geq \\lambda}X) \\geq E(\\Indicator{X \\geq \\lambda}\\lambda).\n        \\end{align*}\n\n    Left-to-right can be thought of as ``tightening'' the constraints and thus (potentially) decreasing the area that is integrated over, right-to-left as ``loosening'' and thus (potentially) increasing the area that is integrated over.\n\n\\end{observation}\n\n\\begin{observation}{}{Identical Distribution Giving Equal Probability}\n\n    Let $(X_n)_{n=1}^{\\infty}$ be a sequence of \\emph{independent, identically distributed} random variables. Let $A_n$ be an event depending on $X_n$, for instance $A_n \\coloneqq \\{ X_n \\geq K \\}$ for some $K \\in \\mathbb{R}$, then all $P(A_n)$ are equal due to $X_n$ being identically distributed, i.e.\n\n        \\begin{align*}\n            P(A_n) = p \\quad \\textrm{for } n \\geq 1, p \\in [0,1].\n        \\end{align*}\n\n\\end{observation}\n\n\\begin{observation}{}{Identical Distribution \\& Infinite Sum}\n\n    Let $(X_n)_{n=1}^{\\infty}$ be a sequence of \\emph{independent, identically distributed} random variables. Let $A_n$ be an event depending on $X_n$, for instance $A_n \\coloneqq \\{ X_n \\geq K \\}$ for some $K \\in \\mathbb{R}$, then \n\n        \\begin{align*}\n            \\sum_{n=1}^{\\infty} P(A_n) < \\infty \\Rightarrow P(A_n) = 0 \\textrm{ for } n \\geq 1.\n        \\end{align*}\n\n\\end{observation}\n", "meta": {"hexsha": "04a7a83ea80e5d4f5597af68c544e4b5ccdaafe5", "size": 9563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/observations.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/observations.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/observations.tex", "max_forks_repo_name": "smueksch/measure-theory-overview", "max_forks_repo_head_hexsha": "28d9c630ecac819b6aa1374e38caf218cf610b1c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-12-02T15:34:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-02T15:34:51.000Z", "avg_line_length": 35.4185185185, "max_line_length": 303, "alphanum_fraction": 0.5871588414, "num_tokens": 3232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8824278695464501, "lm_q1q2_score": 0.7908771971084391}}
{"text": "\\section{Definitions}\r\nNote, in our previous two examples of rotational symmetrical groups, the notion of composition is quite important:\r\nIn both of our proofs that the tetrahedron group and the isocagonal cone group are different, we have harness this notion.\r\nNaturally, we should have it in our definition of group.\r\n\\begin{definition}\r\n    Let $X$ be a set. A binary operation $\\cdot$ is a function $:X\\times X\\to X$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A group $G$ is a triple $(G,\\cdot,e)$, where $G$ is a nonempty set, $\\cdot$ is a binary operation on $G$ and $e\\in G$, that satisfies\\\\\r\n    G1. (Law of Associativity) $\\forall a,b,c\\in G, (a\\cdot b)\\cdot c=a\\cdot (b\\cdot c)$.\\\\\r\n    G2. (Identity) $\\forall a\\in G, a\\cdot e=a$.\\\\\r\n    G3. (Inverse) $\\forall a\\in G, \\exists b\\in G, a\\cdot b=e$\r\n\\end{definition}\r\nMost of the time we write $a\\cdot b$ as $ab$.\r\n\\begin{theorem}\r\n    Let $(G, \\cdot, e)$ be a group, then\\\\\r\n    1. $ab=e\\implies ba=e$.\\\\\r\n    2. $ea=a$.\\\\\r\n    3. $ab=e\\land ab^\\prime=e\\implies b=b^\\prime$.\\\\\r\n    4. $\\exists a, ae^\\prime=a\\implies e^\\prime=e$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    1. Choose $c$ such that $(ba)c=e$, so $e=bac=beac=b(ab)ac=ba((ba)c)=bae=ba$.\\\\\r\n    2. By part 1, we can choose $b$ such that $ab=ba=e$, so $ea=aba=ae=a$.\\\\\r\n    3. $b=bab^\\prime=eb^\\prime$ (due to part 1) $=b^\\prime$ (due to part 2).\\\\\r\n    4. By part 1, we choose $b$ such that $ba=e$, so $e^\\prime=ee^\\prime$ (by part 2) $=bae^\\prime=ba=e$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    There are a LOT of proofs to the preceding theorem.\r\n    For example, the lecturer used a somewhat different proof for part 1 of the theorem.\r\n    Therefore, you should try and come up with your own -- it's great fun.\r\n\\end{remark}\r\nBy part 3 and axiom G3, any $a$ in the group has a unique $b$ in the group such that $ab=ba=e$.\r\nThen we write $a^{-1}=b$ for this element.\r\nThis is called the \\textit{inverse} of $a$.\r\nNote as well that $(a^{-1})^{-1}=a$.\r\nIn addition, $(ab)^{-1}=b^{-1}a^{-1}$.\r\n\\begin{definition}\r\n    For any element $a\\in G$, declare $a^0=e$.\r\n    Say inductively that $a^n=a(a^{n-1})$ for a positive integer $n$.\r\n    Similarly for a negative integer $n$, $a^n=(a^{-1})^{-n}$\r\n\\end{definition}\r\nOne can check that the usual laws of indices apply.\r\n\\begin{proposition}\r\n    1. $a^na^m=a^{m+n}$.\\\\\r\n    2. $(a^n)^m=a^{nm}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nThere are some `fake axioms' that we do not actually have to be stated.\r\nFor example, the definition of binary operation includes the axiom of closure.\r\nHowever, we do have to verify the closure property to show that something is a group.", "meta": {"hexsha": "50ddd70bee695f205400741291bceb1522ca71de", "size": 2650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/defn.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": "1/defn.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": "1/defn.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": 50.0, "max_line_length": 140, "alphanum_fraction": 0.6422641509, "num_tokens": 881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8962513828326955, "lm_q1q2_score": 0.790877187246425}}
{"text": "\n\\subsection{Compact spaces}\n\nA space \\(X\\) is compact if each open cover has a finite subcover.\n\nIf we can define a cover which does not have a finite subcover, then the space is not compact.\n\nFor example an infinite cover could be tend towards \\((0,1)\\), eg as \\(\\dfrac{1}{n},1-\\dfrac{1}{n}\\)\n\nThis covers \\((0,1)\\), but there is no finite subcover. As a result \\((0,1)\\) is not compact.\n\n", "meta": {"hexsha": "ba077bdd1e663616390792015ae0128fe420bfcf", "size": 391, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/09-02-compactness.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/09-02-compactness.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/09-02-compactness.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.5833333333, "max_line_length": 100, "alphanum_fraction": 0.6930946292, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9465966686936261, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7908659310316838}}
{"text": "\\section{Sparse Matrices and Solid Boolean Algebras}\\label{boolean-algebras}\n%=================================================\n\nManuscript~\\cite{paoluzzi2019finite} shows that the set of join-irreducible atoms of the Boolean Algebra generated by a partition of $\\E^3$ are one-to-one with the basis of 3-chain space also generated by the partition, and hence with the columns of the $[\\partial_3]$ matrix, which provides a boundary representation (as 2-cycles) of the independent elements of 3-space. \nAn example of such space decomposition is shown in Figures~\\ref{fig:image1} and~\\ref{fig:image2}. The 3-cells are not in scale, and are suitably rotated to better exhibit their\ncomplex structure, even containing internal holes. Their assembly gives the union of the five cubes. Each\n\\emph{3-cell is generated} as \\emph{a column} of the \\emph{sparse matrix} of\n\\emph{chain map} $\\partial_3: C_3\\to C_2$,  with values in $\\{-1,0,1\\}$.\nThey are the join-irreducible \\emph{atoms} of the CSG algebra with closed regular cells.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{minipage}{0.475\\textwidth}\n        \\centering\n       \\includegraphics[width=0.6\\linewidth]{../figs/image1.png} \n       \\caption{A collection $\\mathcal{S}$ of five random cubes in 3D Euclidean space.}\n       \\label{fig:image1}\n    \\end{minipage}\\hfill\n    \\begin{minipage}{0.475\\textwidth}\n        \\centering\n       \\includegraphics[width=0.8\\linewidth]{../figs/image2.png} \n        \\caption{3-cells of the generated arrangement $\\mathcal{A}(\\mathcal{S})$ of $\\E^3$.\n        They are given by columns of $[\\partial_3]$ as \\emph{atoms} of a solid Boolean algebra.}\n       \\label{fig:image2}\n    \\end{minipage}\n\\end{figure}\n\nTo generate the $d$-space arrangement induced by a collection of cellular ($d$--1)-complexes, some numerical algebra and basic tools of linear algebra and algebraic topology are used. In particular, (sparse) matrices of operators and matrix multiplication and transposition. Interval-trees and $kd$-trees are also introduced for acceleration of clustering of face cells into subsets of congruent shape. \n\nUsing our approach with sparse matrices, the validity of topological computations is guaranteed, since these operator matrices must satisfy by construction the (graded) constraints: $[\\partial_2][\\partial_3]=[0]$ and $[\\partial_1][\\partial_2]=[0]$.  Similarly, we have $[\\delta_1][\\delta_0]=[0]$ and $[\\delta_2][\\delta_1]=[0]$.\n\nWith our approach based on boundary operators, the distinctions are removed between manifold and non-manifold representations (fairly standard in Solid Modeling), so allowing for mixing B-reps, cellular decompositions of elementary solids, and/or regular grids. This allows, e.g., for the generation of internal structures and mixed-dimensional objects needed in many applications, for example to make stronger and more resilient the ones to be produced via 3D printing.\n\nEven more, the evaluation of CSG expressions of arbitrary complexity is done in a novel way, by combining the binary columns of 3D basis elements (i.e., the elements of the $U_3$ basis) with native Julia's operators for bitwise operations. In other words, once the $3$-space partition is generated, and $3$-cells are classified w.r.t.~all solids terms, via a single point-set containment test,  \\emph{all CSG algebraic  expressions}---of any complexity---can be  evaluated simply by bitwise vectorized logical operations. \nFinally, the sparse matrix approach can be extended to general dimensions and/or implemented on highly parallel computational engines, even using standard GPU computing kernels.\n\n\n", "meta": {"hexsha": "6e1ee5f40757b3de1669ba129cab6a9803f3c2ec", "size": 3603, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/algebras.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/algebras.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/algebras.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": 94.8157894737, "max_line_length": 522, "alphanum_fraction": 0.7496530669, "num_tokens": 903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7908626993487095}}
{"text": "\\subsection{Height of Semilattice:}\n\\begin{itemize}\n    \\item \\textbf{Definition}: It is defined as the largest number of greater than($>$) relations that would fit in a descending order.\n    \\par It can also be defined as the longest path length in the semilattice diagram.\n    \\item \\textbf{Set of values $V$ and a partial order} For eg. in a semilattice with power set of $n$ definitions as the set of values $V$ and set intersection($\\cap$) as the meet operator there would be 2\\textsuperscript{n} number of elements but the height of the semilattice would be $n$ as that is the maximum path length in the graph(as can be seen in the figure \\ref{fig:height_semilattice}). As we go down on each edge the cardinality reduces by 1 and the longest path is from complete set to null set of length $n$.\n    \\begin{figure}\n    \\centering\n    \\includegraphics[width=1\\linewidth]{images/semilattice_height.png}\n    \\caption{Semilattice height example}\n    \\label{fig:height_semilattice}\n    \\end{figure}\n    \\par Similarly, for DFA of reaching definitions the height of the semilattice is the number of definitions whereas the number of values is exponential in number of definitions.\n    \\item Now, There could be infinite height semilattices also having infinite no. of values(eg. set of integers with $max$ as the meet operator) but even with infinite no. of elements in the semilattice it’s height can still be finite, for eg. in case of constant propagation.\n    \\item Height of the semilattice is an important property because, one of the requirements for the fixed point iteration to converge is that the semilattice height is finite, if it’s infinite then the iteration is not guaranteed to converge.\n\\end{itemize}\n", "meta": {"hexsha": "bad52688f8955ac016b3f3d7e46ee7a4e87571d4", "size": 1718, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module98.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": "module98.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": "module98.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": 107.375, "max_line_length": 525, "alphanum_fraction": 0.7677532014, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8807970842359877, "lm_q1q2_score": 0.7906873958205245}}
{"text": "\\chapter{Directed graphical models (Bayes nets)}\n\\label{chap:DGM}\n\n\\section{Introduction}\n\n\n\\subsection{Chain rule}\n\\begin{equation}\np(x_{1:V}) = p(x_1)p(x_2|x_1)p(x_3|x_{1:2})\\cdots p(x_N|x_{1:V-1})\n\\end{equation}\n\n\\subsection{Conditional independence}\n$X$ and $Y$ are \\textbf{conditionally independent} given $Z$, denoted $X \\perp Y|Z$, iff the conditional joint can be written as a product of conditional marginals, i.e.\n\\begin{equation}\nX \\perp Y|Z \\Longleftrightarrow p(X,Y|Z)=p(X|Z)p(Y|Z)\n\\end{equation}\n\nfirst order \\textbf{Markov assumption}: the future is independent of the past given the present, \n\\begin{equation}\nx_{t+1} \\perp x_{1:t-1}|x_t\n\\end{equation}\n\nfirst-order \\textbf{Markov chain}\n\\begin{equation}\np(x_{1:V}) = p(x_1)\\prod\\limits_{t=2}^V p(x_t|x_{t-1})\n\\end{equation}\n\n\n\\subsection{Graphical models}\nA \\textbf{graphical model}(GM) is a way to represent a joint distribution by making CI assumptions. In particular, the nodes in the graph represent random variables, and the (lack of) edges represent CI assumptions.\n\nThere are several kinds of graphical model, depending on whether the graph is directed, undirected, or some combination of directed and undirected. In this chapter, we just study directed graphs. We consider undirected graphs in Chapter 19.\n\n\n\\subsection{Directed graphical model}\nA \\textbf{directed graphical model}or \\textbf{DGM} is a GM whose graph is a DAG. These are more commonly known as \\textbf{Bayesian networks}. However, there is nothing inherently “Bayesian” about Bayesian networks: they are just a way of defining probability distributions. These models are also called \\textbf{belief networks}. The term “belief” here refers to subjective probability. Once again, there is nothing inherently subjective about the kinds of probability distributions represented by DGMs.\n\n\\textbf{Ordered Markov property}\n\\begin{equation}\nx_s \\perp x_{\\mathrm{pred}(s)\\ \\mathrm{pa}(s)} \\perp x_{\\mathrm{pa}(s)}\n\\end{equation}\nwhere pa$(s)$ are the parents of nodes, and pred$(s)$ are the predecessors of nodes in the DAG.\n\n\\textbf{\\textbf{Markov chain}} on a DGM\n\\begin{equation}\np(x_{1:V}|G)=\\prod\\limits_{t=1}^V p(x_t|x_{\\mathrm{pa}(t)})\n\\end{equation}\n\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{graphical-models.png}\n\\caption{(a) A simple DAG on 5 nodes, numbered in topological order. Node 1 is the root, nodes 4 and 5 are the leaves. (b) A simple undirected graph, with the following maximal cliques: {1,2,3}, {2,3,4}, {3,5}.}\n\\label{fig:graphical-models} \n\\end{figure}\n\n\n\\section{Examples}\n\n\n\\subsection{Naive Bayes classifiers}\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.60]{naive-bayes-as-DGM.png}\n\\caption{(a) A naive Bayes classifier represented as a DGM. We assume there are $D=4$ features, for simplicity. Shaded nodes are observed, unshaded nodes are hidden. (b) Tree-augmented naive Bayes classifier for $D=4$ features. In general, the tree topology can change depending on the value of $y$.}\n\\label{fig:naive-bayes-as-DGM} \n\\end{figure}\n\n\n\\subsection{Markov and hidden Markov models}\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{second-order-Markov-chain.png}\n\\caption{A first and second order Markov chain.}\n\\label{fig:second-order-Markov-chain} \n\\end{figure}\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.60]{first-order-HMM.png}\n\\caption{A first-order HMM.}\n\\label{fig:first-order-HMM} \n\\end{figure}\n\n\n\n\\section{Inference}\nSuppose we have a set of correlated random variables with joint distribution $p(\\vec{x}_{1:V}|\\vec{\\theta})$. Let us partition this vector into the \\textbf{visible variables} $\\vec{x}_v$, which are observed, and the \\textbf{hidden variables}, $\\vec{x}_h$, which are unobserved. Inference refers to computing the posterior distribution of the unknowns given the knowns:\n\\begin{equation}\np(\\vec{x}_h|\\vec{x}_v,\\theta) = \\frac{p(\\vec{x}_h, \\vec{x}_v|\\vec{\\theta})}{p(\\vec{x}_v|\\vec{\\theta})}=\\frac{p(\\vec{x}_h, \\vec{x}_v|\\vec{\\theta})}{\\sum_{\\vec{x}_h'}p(\\vec{x}_h', \\vec{x}_v|\\vec{\\theta})}\n\\end{equation}\n\nSometimes only some of the hidden variables are of interest to us. So let us partition the hidden variables into \\textbf{query variables}, $\\vec{x}_q$, whose value we wish to know, and the remaining \\textbf{nuisance variables}, $\\vec{x}_n$, which we are not interested in. We can compute what we are interested in by \\textbf{marginalizing out} the nuisance variables:\n\\begin{equation}\np(\\vec{x}_q|\\vec{x}_v,\\vec{\\theta}) = \\sum_{\\vec{x}_n}p(\\vec{x}_q, \\vec{x}_n|\\vec{x}_v, \\vec{\\theta})\n\\end{equation}\n\n\n\\section{Learning}\nMAP estimate:\n\\begin{equation}\n\\hat{\\vec{\\theta}} =\\arg\\max_{\\vec{\\theta}}\\sum\\limits_{i=1}^N \\log p(\\vec{x}_{i,v}|\\vec{\\theta})+\\log p(\\vec{\\theta})\n\\end{equation}\n\n\n\\subsection{Learning from complete data}\nIf all the variables are fully observed in each case, so there is no missing data and there are no hidden variables, we say the data is \\textbf{complete}. For a DGM with complete data, the likelihood is given by\n\\begin{equation}\\begin{split}\np(\\mathcal{D}|\\vec{\\theta}) & = \\prod_{i=1}^N p(\\vec{x}_i|\\vec{\\theta}) \\\\\n& = \\prod_{i=1}^N\\prod_{t=1}^V p(\\vec{x}_{it}|\\vec{x}_{i, \\mathrm{pa}(t)}, \\vec{\\theta}_t) \\\\\n& = \\prod_{t=1}^V p(\\mathcal{D}_t|\\vec{\\theta}_t)\n\\end{split}\\end{equation}\nwhere $\\mathcal{D}_t$ is the data associated with node $t$ and its parents, i.e., the $t$'th family.\n\nNow suppose that the prior factorizes as well:\n\\begin{equation}\np(\\vec{\\theta})=\\prod\\limits_{t=1}^V p(\\vec{\\theta}_t)\n\\end{equation}\n\nThen clearly the posterior also factorizes:\n\\begin{equation}\np(\\vec{\\theta}|\\mathcal{D}) \\propto p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}) = \\prod\\limits_{t=1}^V p(\\mathcal{D}_t|\\vec{\\theta}_t)p(\\vec{\\theta}_t)\n\\end{equation}\n\n\n\\subsection{Learning with missing and/or latent variables}\nIf we have missing data and/or hidden variables, the likelihood no longer factorizes, and indeed it is no longer convex, as we explain in detail in Section TODO. This means we will usually can only compute a locally optimal ML or MAP estimate. Bayesian inference of the parameters is even harder. We discuss suitable approximate inference techniques in later chapters.\n\n\n\\section{Conditional independence properties of DGMs}\n\n\n\\subsection{d-separation and the Bayes Ball algorithm (global Markov properties)}\n\\begin{enumerate}\n\\item P contains a chain\n\\begin{equation}\\begin{split}\np(x,z|y) & = \\frac{p(x,y,z)}{p(y)}\n= \\frac{p(x)p(y|x)p(z|y)}{p(y)} \\\\\n & = \\frac{p(x,y)p(z|y)}{p(y)} = p(x|y)p(z|y)\n\\end{split}\\end{equation}\n\n\\item P contains a fork\n\\begin{equation}\np(x,z|y) = \\frac{p(x,y,z)}{p(y)}\n= \\frac{p(y)p(x|y)p(z|y)}{p(y)}\n= p(x|y)p(z|y)\n\\end{equation}\n\\item P contains v-structure\n\\begin{equation}\np(x,z|y) = \\frac{p(x,y,z)}{p(y)}\n= \\frac{p(x)p(z)p(y|x,z)}{p(y)}\n\\neq p(x|y)p(z|y)\n\\end{equation}\n\\end{enumerate}\n\n\n\n\\subsection{Other Markov properties of DGMs}\n\n\n\\subsection{Markov blanket and full conditionals}\n\n\\begin{equation}\nmb(t) = ch(t)\\cup pa(t)\\cup copa(t)\n\\end{equation}\n\n\n\\subsection{Multinoulli Learning}\nMultinoulli Distribution：\n\\begin{equation}\\label{eqn:discrite}\nCat(x|\\mu) = \\prod_{k=1}^K\\mu_k^{x_k}\n\\end{equation}\nthen from \\ref{bayes_net} and \\ref{eqn:discrite}:\n\\begin{equation}\np(x|G,\\theta) = \\prod_{v=1}^V\\prod_{c=1}^{C_v}\\prod_{k=1}^K\n\\theta_{vck}^{y_{vck}}\n\\end{equation}\nLikelihood\n\\begin{equation}\np(D|G,\\theta) = \\prod_{n=1}^N p(x_n|G,\\theta)\n=\\prod_{n=1}^N\\prod_{v=1}^V\\prod_{c=1}^{C_{nv}}\\prod_{k=1}^K\n\\theta_{vck}^{y_{nvck}}\n\\end{equation}\nwhere $y_{nv} = f(pa(x_{nv}))$, f(x) is a map from x to a vector, there is only one element in the vector is 1.\n\n\n\\section{Influence (decision) diagrams *}\n\n", "meta": {"hexsha": "376875d62cebac873a8a029e4c56467f1fbf6dd3", "size": 7637, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterDGM.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/chapterDGM.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/chapterDGM.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": 40.4074074074, "max_line_length": 502, "alphanum_fraction": 0.7195233731, "num_tokens": 2476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7905833441742414}}
{"text": "\\chapter{Associative Memory Network}\nAssociative memory networks are single input, single output layer networks in which weights are determined in order to store a set of pattern associations. They are able to recall the desired response patterns when a given pattern is similar to the stored pattern. \n$$\\mathbf{{(x_1 y_1), (x_2 y_2), \\ldots, (x_p y_p)}}$$\nAssociation vectors are defined as:\n$$\\mathbf{x_k \\rightarrow y_k}$$\n\\begin{description}\n\\item[Auto-associative] $\\mathbf{x_k = y_k}$\n\\item[Hetero-associative] $\\mathbf{x_k \\ne y_k}$\n\\end{description}\n\n\\section{Linear Feed-forward Associative Memory network}\nLinear Feed-forward Associative Memory (LAM) network is a single input, single output layer with linear activation function. \\\\\nThe synaptic input:\n$$\\mathbf{u=Wx}$$\nThe output activation:\n$$\\mathbf{y=\\beta u}$$\n\\begin{center} where $\\beta$ is the slope of the linear function\\end{center}\n\\clearpage\n\\noindent LAM networks learn using the Hebbian rule. The weight matrix is \\emph{given} by:\n$$\\mathbf{W_k = y_k x_k^{T}}$$\n\\begin{center} where $\\mathbf{W_k}$ weight matrix learns the $k$ th pattern association\\end{center}\nThe weight matrix to learn all the associations is \\emph{given} by:\n\\begin{equation*}\n\\begin{split}\n\\mathbf{W} &= \\sum_{k=1}^{P} \\mathbf{W_k} \\\\\n&= \\sum_{k=1}^{P} \\mathbf{y_k x_k^{T}}\n\\end{split}\n\\label{weight_lam}\n\\end{equation*}\n\n\\section{Cross-Talk versus Perfect Recall}\nIf inputs are \\emph{uncorrelated or orthogonal} the Hebbian rule make \\emph{perfect recall}. Otherwise, the output is corrupted or has \\emph{cross-talk}. \\\\\nSubstituting \\ref{weight_lam} to output, with $\\mathbf{x_l}$ as input:\n\\begin{equation}\n\\begin{split}\n\\mathbf{y} &= \\mathbf{Wx_l} \\\\\n&= \\Big(\\sum_{k=1}^{P} \\mathbf{y_k x_k^{T}} \\Big) \\mathbf{x_l} \\\\\n&= \\mathbf{y_l x_l^{T} x_l} + \\sum_{k=1,k \\ne l} \\mathbf{y_k x_k^{T} x_l}\n\\end{split}\n\\end{equation}\nIf $\\mathbf{x_l}$ and $\\mathbf{x_k}$ are orthogonal:\n$$\\mathbf{x_l^{T} x_k} = 0$$\nThen, perfect recall of the learned pattern:\n$$\\mathbf{y = y_l \\| x_l \\|^{2}}$$\n$$\\mathbf{y \\propto y_l}$$\nOtherwise, cross-talk:\n$$\\sum_{k=1,k \\ne l} \\mathbf{y_k x_k^{T} x_l}$$\n\n\\section{Problem with LAM Network}\nBoth auto and heterogeneous associative memory network do not function well in the presence of noise. \nLet distorted input as:\n$$\\mathbf{x}_l^{i} = \\mathbf{x}_l + \\Delta_l$$\nThen the output:\n\\begin{equation*}\n\\begin{split}\n\\mathbf{y} &= \\mathbf{W} \\mathbf{x}_l' \\\\\n&= \\mathbf{W} (\\mathbf{x}_l + \\Delta_l) \\\\\n&= \\Big(\\sum_{k=1}^{P} \\mathbf{y_k x_k^{T}}\\Big) (\\mathbf{x_l} + \\Delta_l) \\\\\n&= \\mathbf{y_l x_l^{T} x_l + y_l x_l^{T} \\Delta_l + \\Big(\\sum_{k \\ne l}^{P} \\mathbf{y_k x_k^{T} x_l}\\Big) + \\Big(\\sum_{k \\ne l}^{P} \\mathbf{y_k x_k^{T} \\Delta_l}\\Big)}\n\\end{split}\n\\end{equation*}\nSince orthogonal: \n$$\\mathbf{y} = \\mathbf{y_l x_l^{T} x_l + y_l x_l^{T} \\Delta_l +  \\Big(\\sum_{k \\ne l}^{P} \\mathbf{y_k x_k^{T} \\Delta_l}\\Big)}$$\n\n\\section{Recurrent/Hopfield AMN}\nSuppressing noise component by thresholding the outputs and recycling of the output to the input. Weight is still based on Hebbian's learning rule, but $w_{ii} = 0$\n\n\\section{Bidirectional Associative Memory Network}\nBidirectional Associative Memory (BAM) network is a \\emph{recurrent hetero-associative memory} of two layers of neurons. \\\\\nSynaptic input to the output layer:\n$$\\mathbf{u = Wx}$$\nThe output:\n$$\ny_j = \n\\begin{cases}\n1 & u_j > 0 \\\\\n-1 & u_j \\le 0\n\\end{cases}\n$$\nSynaptic input back to the input layer:\n$$\\mathbf{v = W^{T} y}$$\nThe input:\n$$\nx_j = \n\\begin{cases}\n1 & v_i > 0 \\\\\n-1 & v_i \\le 0\n\\end{cases}\n$$\nRepeat until convergence", "meta": {"hexsha": "abb6c6d1c782a0be144cd704233187578b0fea6c", "size": 3576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter7.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": "chapter7.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": "chapter7.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": 39.7333333333, "max_line_length": 265, "alphanum_fraction": 0.6965883669, "num_tokens": 1252, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654119, "lm_q2_score": 0.865224084314688, "lm_q1q2_score": 0.7905349394317571}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\n\\begin{document}\n\n%--------------------------------------------------------------------------------\n\\section{First example}\n\nThe well known Pythagorean theorem \\(x^2 + y^2 = z^2\\) was \nproved to be invalid for other exponents. \nMeaning the next equation has no integer solutions:\n\n\\[ x^n + y^n = z^n \\]\n\n\n%--------------------------------------------------------------------------------\n\n\\section{Second example}\n\nIn physics, the mass-energy equivalence is stated by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.\n\nThe mass-energy equivalence is described by the famous equation\n\\[ E=mc^2 \\]\ndiscovered in 1905 by Albert Einstein. \nIn natural units ($c$ = 1), the formula expresses the identity\n\\begin{equation}\nE=m\n\\end{equation}\n\n\\section{Third example}\n\nThis is a simple math expression \\(\\sqrt{x^2+1}\\) inside text. \nAnd this is also the same: \n\\begin{math}\n\\sqrt{x^2+1}\n\\end{math}\nbut by using another command.\n\nThis is a simple math expression without numbering\n\\[\\sqrt{x^2+1}\\] \nseparated from text.\n\nThis is also the same:\n\\begin{displaymath}\n\\sqrt{x^2+1}\n\\end{displaymath}\n\n\\ldots and this:\n\\begin{equation*}\n\\sqrt{x^2+1}\n\\end{equation*}\n    \n    In physics, the mass-energy equivalence is stated \n    by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.\n\n    The mass-energy equivalence is described by the famous equation\n    \\[ E=mc^2 \\]\n    discovered in 1905 by Albert Einstein. \n    In natural units ($c = 1$), the formula expresses the identity\n    \\begin{equation}\n        E=m\n    \\end{equation}\n\n    Subscripts in math mode are written as $a_b$ and superscripts are written as $a^b$. These can be combined an nested to write expressions such as\n\n    \\[ T^{i_1 i_2 \\dots i_p}_{j_1 j_2 \\dots j_q} = T(x^{i_1},\\dots,x^{i_p},e_{j_1},\\dots,e_{j_q}) \\]\n    \n    We write integrals using $\\int$ and fractions using $\\frac{a}{b}$. Limits are placed on integrals using superscripts and subscripts:\n\n    \\[ \\int_0^1 \\frac{dx}{e^x} =  \\frac{e-1}{e} \\]\n\n    Lower case Greek letters are written as $\\omega$ $\\delta$ etc. while upper case Greek letters are written as $\\Omega$ $\\Delta$.\n\n    Mathematical operators are prefixed with a backslash as $\\sin(\\beta)$, $\\cos(\\alpha)$, $\\log(x)$ etc.\n\n\\end{document}", "meta": {"hexsha": "fe75f7be1d69117ac5c9918cccb83cd35ca01626", "size": 2315, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/Overleaf/10.addingMath.tex", "max_stars_repo_name": "Youngermaster/learning-programming-languages", "max_stars_repo_head_hexsha": "55ce852799ced3d656df01230e4fd9e619ed3f6b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-20T15:28:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T15:28:50.000Z", "max_issues_repo_path": "Latex/Overleaf/10.addingMath.tex", "max_issues_repo_name": "Youngermaster/learning-programming-languages", "max_issues_repo_head_hexsha": "55ce852799ced3d656df01230e4fd9e619ed3f6b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2022-03-02T13:16:03.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T13:16:03.000Z", "max_forks_repo_path": "Latex/Overleaf/10.addingMath.tex", "max_forks_repo_name": "Youngermaster/Learning-Programming-Languages", "max_forks_repo_head_hexsha": "b94d3d85abc6c107877b11b42a3862d4aae8e3ee", "max_forks_repo_licenses": ["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.0649350649, "max_line_length": 148, "alphanum_fraction": 0.6475161987, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026663679977, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7902912999501229}}
{"text": "\\section{Linear Support Vector Regression} \\label{section:svr}\n\nIn the case of regression the goal is to predict a real-valued output for $y'$ so that our training data is of the form:\n\n\\begin{equation}\n\t\\{(x_i,y_i), x\\in\\Re^m, y_i\\in\\Re, i=1, \\dots, n\\} \\label{eq:svr_data}\n\\end{equation}\n\nThe regression SVM use a loss function that not allocating a penalty if the predicted value $y'_i$ is less than a distance $\\epsilon$ away from the actual value $y_i$, i.e., if $|y_i-y'_i| \\leq \\epsilon$, where $y'_i = w^T x_i + b$. The region bound by $y'_i\\pm\\epsilon \\ \\forall_i$ is called an $\\epsilon$-insensitive tube. The output variables which are outside the tube are given one of two slack variable penalties depending on whether they lie above, $\\xi^+$, or below, $\\xi^-$, the tube, provided $\\xi^+ \\geq 0$ and $\\xi^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_consts}\n\t\\begin{aligned}\n\t\t& y_i\\leq y'_i+\\epsilon+\\xi^+ \\ \\forall_i \\\\\n    \t& y_i\\geq y'_i-\\epsilon-\\xi^- \\ \\forall_i \\\\\n    \t& \\xi_i^+, \\xi_i^- \\geq 0 \\ \\forall_i\n\t\\end{aligned}\n\\end{equation}\n\nThe objective function for SVR can then be written as:\n\n\\begin{equation} \\label{eq:quad_svr_obj}\n    \\begin{aligned}\n        \\min_{w,b,\\xi^+,\\xi^-} \\quad & \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n (\\xi_i^+ + \\xi_i^-) \\\\\n            \\text{subject to} \\quad & y_i - w^T x_i - b \\leq \\epsilon + \\xi_i^+ \\ \\forall_i \\\\ & w^T x_i + b - y_i \\leq \\epsilon + \\xi_i^- \\ \\forall_i \\\\ & \\xi_i^+, \\xi_i^- \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.6]{img/linear_dual_l1_svr_hyperplane}\n  \t\\caption{Linear SVR hyperplane}\n  \t\\label{fig:linear_dual_l1_svr_hyperplane}\n\\end{figure}\n\n\\pagebreak\n\n\\subsection{Epsilon-insensitive loss}\n\nThe \\emph{epsilon-insensitive} loss is defined as:\n\n\\begin{equation} \\label{eq:eps_loss1}\n\t\\mathcal{L}_\\epsilon^1 = \\max(0, |y - (w^T x + b)| - \\epsilon)\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:eps_loss2}\n\t\\mathcal{L}_\\epsilon^1 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ |y - (w^T x + b)| \\leq \\epsilon \\\\\n\t\t|y - (w^T x + b)| - \\epsilon & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nAs the \\emph{hinge} loss, also the \\emph{epsilon-insensitive} loss is a nondifferentiable convex function due to its nonsmoothness in $\\pm\\epsilon$, but has a subgradient that is given by:\n\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/distance/#L1EpsilonInsLoss-1\n\n\\begin{equation} \\label{eq:eps_loss_der}\n\t\\partial_w \\mathcal{L}_\\epsilon^1=\n\t\t\\begin{cases}\n            \\displaystyle \\frac{y - (w^T x + b)}{|y - (w^T x + b)|}x & \\text{if} \\ |y - (w^T x + b)| \\geq \\epsilon \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nThe general primal unconstrained formulation takes the same form of~\\eqref{eq:primal_svm}.\n\nThe quadratic optimization problem~\\eqref{eq:quad_svr_obj} can be equivalently formulated as:\n\n\\begin{equation} \\label{eq:primal_l1_svr}\n\t\\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)\n\\end{equation}\n\nwhere we make use of the \\emph{epsilon-insensitive} loss~\\eqref{eq:eps_loss1} or~\\eqref{eq:eps_loss2}.\n\nThe above formulation penalizes slacks $\\xi$ linearly and is called $\\mathcal{L}_1$-SVR.\n\nThe $\\mathcal{L}_1$-SVR objective~\\eqref{eq:primal_l1_svr} can be rewritten in form~\\eqref{eq:reg_bias_primal_svm1} or~\\eqref{eq:reg_bias_primal_svm2} as:\n\n\\begin{equation} \\label{eq:reg_bias_primal_l1_svr}\n\t\\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)\n\\end{equation}\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/l1_svr_loss}\n  \t\\caption{Epsilon-insensitive loss with different optimization steps}\n  \t\\label{fig:l1_svr_loss}\n\\end{figure}\n\n\\subsubsection{Wolfe dual formulation}\n\nTo reformulate the~\\eqref{eq:quad_svr_obj} as a \\emph{Wolfe dual}, we introduce the Lagrange multipliers $\\alpha_i^+, \\alpha_i^-, \\mu_i^+, \\mu_i^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_wolfe_dual}\n\t\\begin{aligned}\n    \t\\max_{\\alpha^+,\\alpha^-,\\mu^+,\\mu^-} \\min_{w,b,\\xi^+,\\xi^-} \\mathcal{W}(w,b,\\xi^+,\\xi^-,\\alpha^+,\\alpha^-,\\mu^+,\\mu^-) = \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n (\\xi_i^+ + \\xi_i^-)-\\sum_{i=1}^n (\\mu_i^+ \\xi_i^+ + \\mu_i^- \\xi_i^-) \\\\ -\\sum_{i=1}^n \\alpha_i^+(\\epsilon+\\xi_i^+ + y'_i-y_i)-\\sum_{i=1}^n \\alpha_i^-(\\epsilon+\\xi_i^- - y'_i+y_i)\n\t\\end{aligned}\n\\end{equation}\n\nSubstituting for $y_i$, differentiating wrt $w, b, \\xi^+$, $\\xi^-$ and setting the derivatives to $0$ gives:\n\n\\begin{equation} \\label{eq:svr_wolfe_der_w}\n\t\\frac{\\partial \\mathcal{W}}{\\partial w}=w-\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-) x_i \\Rightarrow w=\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-) x_i\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_wolfe_der_b}\n\t\\frac{\\partial \\mathcal{W}}{\\partial b}=-\\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)\\Rightarrow \\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)=0\n\\end{equation}\n\n\\begin{equation}\\label{eq:svr_wolfe_der_xip}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i^+}=0\\Rightarrow C=\\alpha_i^+ + \\mu_i^+\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_wolfe_der_xim}\n\t\\frac{\\partial \\mathcal{W}}{\\partial\\xi_i^-}=0\\Rightarrow C=\\alpha_i^- + \\mu_i^-\n\\end{equation}\n\nSubstituting~\\eqref{eq:svr_wolfe_der_w} and~\\eqref{eq:svr_wolfe_der_b} in, we now need to maximize $\\mathcal{W}$ wrt $\\alpha_i^+$ and $\\alpha_i^-$, where $\\alpha_i^+ \\geq 0,\\ \\alpha_i^- \\geq 0 \\ \\forall_i$:\n\n\\begin{equation} \\label{eq:svr_max_wolfe_dual}\n    \\max_{\\alpha^+,\\alpha^-} \\mathcal{W}(\\alpha^+,\\alpha^-) = \\sum_{i=1}^n y_i(\\alpha_i^+ - \\alpha_i^-)-\\epsilon\\sum_{i=1}^n (\\alpha_i^+ + \\alpha_i^-)-\\frac{1}{2}\\sum_{i,j}(\\alpha_i^+ - \\alpha_i^-)\\langle x_i, x_j \\rangle(\\alpha_j ^+ - \\alpha_j ^-)\n\\end{equation}\n\nUsing $\\mu_i^+ \\geq 0$ and $\\mu_i^- \\geq 0$ together with~\\eqref{eq:svr_wolfe_der_w} and~\\eqref{eq:svr_wolfe_der_b} means that $\\alpha_i^+ \\leq C$ and $\\alpha_i^- \\leq C$. We therefore need to find:\n\n\\begin{equation} \\label{eq:svr_min_wolfe_dual}\n    \\begin{aligned}\n        \\min_{\\alpha^+,\\alpha^-} \\quad & \\frac{1}{2}(\\alpha^+ - \\alpha^-)^TK(\\alpha^+ - \\alpha^-)+\\epsilon e^T(\\alpha^+ + \\alpha^-)-y^T(\\alpha^+ - \\alpha^-) \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i^+,\\alpha_i^- \\leq C \\ \\forall_i \\\\ & e^T(\\alpha^+ - \\alpha^-)=0\n    \\end{aligned}\n\\end{equation}\n\nwhere $e^T = [1, \\dots, 1]$.\n\nWe can write the~\\eqref{eq:svr_min_wolfe_dual} in a standard quadratic form as:\n\n\\begin{equation}\n    \\begin{aligned} \\label{eq:svr_min_qp_wolfe_dual}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T Q\\alpha-q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i \\\\ & e^T\\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nwhere the Hessian matrix $Q =\n\\begin{bmatrix}\nK & -K\\\\\n-K & K \n\\end{bmatrix}$\n, $\\alpha = \n\\begin{bmatrix}\n\\alpha^+\\\\\n\\alpha^-\n\\end{bmatrix}$\n, $q =\n\\begin{bmatrix}\n-y\\\\\ny\n\\end{bmatrix} + \\epsilon$\n, and $e =\n\\begin{bmatrix}\n1\\\\\n-1\n\\end{bmatrix}$.\n\nEach new predictions $y'$ can be found using:\n\n\\begin{equation} \\label{eq:svr_pred}\n    y'= \\sum_{i=1}^n (\\alpha_i^+ - \\alpha_i^-)\\langle x_i, x' \\rangle+b\n\\end{equation}\n\nA set $S$ of support vectors $x_s$ can be created by finding the indices $i$ where $0\\leq\\alpha\\leq C$ and $\\xi_i^+=0$ or $\\xi_i^-=0$.\n\nThis gives us:\n\n\\begin{equation} \\label{eq:svr_b}\n    b=y_s-\\epsilon-\\sum_{m\\in S}(\\alpha_m^+ -\\alpha_m^-) \\langle x_m, x_s \\rangle\n\\end{equation}\n\nAs before it is better to average over all the indices $i$ in $S$:\n\n\\begin{equation} \\label{eq:svr_b_avg}\n    b=\\frac{1}{N_s}\\sum_{s\\in S}y_s-\\epsilon-\\sum_{m \\in S}(\\alpha_m^+ - \\alpha_m^-)\\langle x_m, x_s \\rangle\n\\end{equation}\n\nFrom~\\eqref{eq:svr_min_qp_wolfe_dual} we can notice that the equality constraint $e^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. We report below the box-constrained dual formulation~\\cite{hsu2002simple} that arises from the primal~\\eqref{eq:reg_bias_primal_svm1} or~\\eqref{eq:reg_bias_primal_svm2} where the bias term $b$ is embedded into the weight vector $w$:\n\n\\begin{equation} \\label{eq:svr_min_bcqp_wolf_dual}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha+q^T\\alpha \\\\\n            \\text{subject to} \\quad & 0\\leq\\alpha_i\\leq C \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\n\\subsubsection{Lagrangian dual formulation}\n\nIn order to relax the constraints in the \\emph{Wolfe dual} formulation~\\eqref{eq:svr_min_wolfe_dual} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\\mu$ and $\\lambda_+, \\lambda_- \\geq 0$:\n\n\\begin{equation} \\label{eq:l1_svr_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha + \\mu^T (e^T \\alpha) + \\lambda_+^T (ub - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T Q\\alpha + (q + \\mu e^T + \\lambda_+ - \\lambda_-)^T \\alpha + \\lambda_+^T ub \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda_+, \\lambda_- \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere the upper bound $ub^T = [C, \\dots, C]$.\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow Q \\alpha + (q + \\mu e^T + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l1_svr_lagrangian_sol}\n    Q \\alpha = - (q + \\mu e^T + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradients wrt $\\mu$, $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-e \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - ub\n\\end{equation}\n\n\\begin{equation} \\label{eq:svr_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\nFrom~\\eqref{eq:svr_min_qp_wolfe_dual} we can notice that the equality constraint $e^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:l1_svr_lagrangian_dual} is reduced by removing the multipliers $\\mu$ which was allocated to control the equality constraint $e^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:svr_min_bcqp_wolf_dual}.\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda_+,\\lambda_-} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda_+,\\lambda_-) &= \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha+q^T\\alpha + \\lambda_+^T (ub - \\alpha) - \\lambda_-^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + ee^T)\\alpha + (q + \\lambda_+ - \\lambda_-)^T \\alpha + \\lambda_+^T ub \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda_+, \\lambda_- \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere, again, the upper bound $ub^T = [C, \\dots, C]$.\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + ee^T) \\alpha + (q + \\lambda_+ - \\lambda_-) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_lagrangian_sol}\n    (Q + ee^T) \\alpha = - (q + \\lambda_+ - \\lambda_-)\n\\end{equation}\n\nthe gradients wrt $\\lambda_+$ and $\\lambda_-$ are:\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_lagrangian_der_lp}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\lambda_+}=\\alpha - ub\n\\end{equation}\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_lagrangian_der_lm}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda_-}=-\\alpha\n\\end{equation}\n\n\\bigskip\n\nNote that since the Hessian matrix $Q$ of the $\\mathcal{L}_1$-SVR is not strictly positive definite, i.e., the Lagrangian function is not strictly convex since it will be linear along the eigenvectors correspondent to the null eigenvalues and so it will be unbounded below, the Lagrangian dual relaxation, i.e.,~\\ref{eq:l1_svr_lagrangian_sol} and~\\ref{eq:l1_svr_bcqp_lagrangian_sol}, will be nondifferentiable, so it will have infinite solutions and for each of them it will have a different subgradient. In order to compute an approximation of the gradient, we will choose $\\alpha$ in such a way as the one that minimizes the 2-norm since it is good almost like the gradient:\n\n\\begin{equation} \\label{eq:svr_lagrangian_krylov_sol}\n\t\\min_{\\alpha_n \\in K_n(Q, b)} \\| Q \\alpha_n - b \\|\n\\end{equation}\n\nSince we are dealing with a symmetric system we will choose a well-known Krylov method that performs the Lanczos iterate, i.e., symmetric Arnoldi iterate, called \\emph{minres}, i.e., symmetric \\emph{gmres}, to compute the vector $\\alpha_n$ that minimizes the norm of the residual $r_n = Q \\alpha_n - b$ among all vectors in $K_n(Q, b) = span(b, Qb, Q^2b, \\dots, Q^{n-1}b)$.\n\n\\bigskip\n\nSince the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as:\n\n\\begin{equation}\n    \\begin{aligned} \n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & G \\alpha \\leq h \\\\ & lb \\leq \\alpha \\leq ub\n    \\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & \\hat{G} \\alpha \\leq \\hat{h}\n    \\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n G \\\\\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\nh & -lb & ub\n\\end{bmatrix}$; we give the following \\emph{augmented Lagrangian dual}:\n\n\\begin{equation} \\label{eq:l1_svr_gen_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha + \\mu^T (A \\alpha - b) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| A \\alpha - b \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwith $\\rho > 0$.\n\n\\bigskip\n\nAccording to this definition, we change the formulation~\\ref{eq:l1_svr_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l1_svr_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T Q\\alpha+q^T\\alpha + \\mu^T (e^T \\alpha) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| e^T \\alpha \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nand the formulation~\\ref{eq:l1_svr_bcqp_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l1_svr_bcqp_aug_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + ee^T) \\alpha + q^T \\alpha + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\n-lb & ub\n\\end{bmatrix}$ with $lb^T = [0, \\dots, 0]$, $ub^T = [C, \\dots, C]$ and $\\rho > 0$.\n\n\\pagebreak\n\n\\subsection{Squared epsilon-insensitive loss}\n\nThe \\emph{squared epsilon-insensitive} loss is defined as:\n\n\\begin{equation} \\label{eq:squared_eps_loss1}\n\t\\mathcal{L}_\\epsilon^2 = \\max(0, |y - (w^T x + b)| - \\epsilon)^2\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation} \\label{eq:squared_eps_loss2}\n\t\\mathcal{L}_\\epsilon^2 = \n\t\\begin{cases}\n\t\t0 & \\text{if} \\ |y - (w^T x + b)| \\leq \\epsilon \\\\\n\t\t(|y - (w^T x + b)| - \\epsilon)^2 & \\text{otherwise} \\\\\n\t\\end{cases}\n\\end{equation}\n\nAs the \\emph{squared hinge} loss, also the \\emph{squared epsilon-insensitive} loss is a strictly convex function and its gradient is given by:\n\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/distance/#L2EpsilonInsLoss-1\n\n\\begin{equation} \\label{eq:squared_eps_loss_der}\n\t\\nabla_w \\mathcal{L}_\\epsilon^2=\n\t\t\\begin{cases}\n            \\displaystyle 2 \\operatorname{sign}(y - (w^T x + b)) (|y - (w^T x + b)| - \\epsilon) x & \\text{if} \\ |y - (w^T x + b)| \\geq \\epsilon \\\\\n            0 & \\text{otherwise} \\\\ \n        \\end{cases}\n\\end{equation}\n\n\\subsubsection{Primal formulation}\n\nTo provide a continuously differentiable function the optimization problem~\\eqref{eq:primal_l1_svr} can be formulated as:\n\n\\begin{equation} \\label{eq:primal_l2_svr}\n    \\min_{w,b} \\frac{1}{2} \\| w \\|^2 + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)^2\n\\end{equation}\n\nwhere we make use of the \\emph{squared epsilon-insensitive} loss that quadratically penalized slacks $\\xi$ and is called $\\mathcal{L}_2$-SVR.\n\nThe $\\mathcal{L}_2$-SVR objective~\\eqref{eq:primal_l2_svr} can be rewritten in form~\\eqref{eq:reg_bias_primal_svm1} or~\\eqref{eq:reg_bias_primal_svm2} as:\n\n\\begin{equation} \\label{eq:reg_bias_primal_l2_svr}\n\t\\min_{w,b} \\frac{1}{2} (\\| w \\|^2 + b^2) + C \\sum_{i=1}^n \\max(0, |y_i - (w^T x_i + b)| - \\epsilon)^2\n\\end{equation}\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.4]{img/l2_svr_loss}\n  \t\\caption{Squared epsilon-insensitive loss with different optimization steps}\n  \t\\label{fig:l2_svr_loss}\n\\end{figure}\n\n\\subsubsection{Wolfe dual formulation}\n\nAs done for the $\\mathcal{L}_1$-SVR we can derive the \\emph{Wolfe dual} formulation of the $\\mathcal{L}_2$-SVR by obtaining:\n\n\\begin{equation} \\label{eq:wolfe_dual_l2_svr}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T (Q + D) \\alpha + q^T \\alpha \\\\\n            \\text{subject to} \\quad & \\alpha_i \\geq 0 \\ \\forall_i \\\\ & e^T \\alpha=0\n    \\end{aligned}\n\\end{equation}\n\nor, alternatively, with the regularized bias term by obtaining:\n\n\\begin{equation} \\label{eq:reg_bias_wolfe_dual_l2_svr}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2}\\alpha^T (Q + ee^T + D) \\alpha + q^T \\alpha \\\\\n            \\text{subject to} \\quad & \\alpha_i \\geq 0 \\ \\forall_i\n    \\end{aligned}\n\\end{equation}\n\nwhere the diagonal matrix $\\displaystyle D_{ii} = \\frac{1}{2C} \\ \\forall_i$.\n\n\\subsubsection{Lagrangian dual formulation}\n\nIn order to relax the constraints in the $\\mathcal{L}_2$-SVR \\emph{Wolfe dual} formulation~\\eqref{eq:wolfe_dual_l2_svr} we define the problem as a \\emph{Lagrangian dual} relaxation by embedding them into objective function, so we need to allocate the Lagrange multipliers $\\mu$ and $\\lambda \\geq 0$:\n\n\\begin{equation} \\label{eq:l2_svr_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T (Q+D)\\alpha+q^T\\alpha + \\mu^T (e^T \\alpha) - \\lambda^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q+D)\\alpha + (q + \\mu e^T - \\lambda)^T \\alpha \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nTaking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l2_svr_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q+D) \\alpha + (q + \\mu e^T - \\lambda) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l2_svr_lagrangian_sol}\n    (Q+D) \\alpha = - (q + \\mu e^T - \\lambda)\n\\end{equation}\n\nthe gradients wrt $\\mu$ and $\\lambda$ are:\n\n\\begin{equation} \\label{eq:l2_svr_lagrangian_der_mu}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\mu}=-e \\alpha\n\\end{equation}\n\n\\begin{equation} \\label{eq:l2_svr_lagrangian_der_lalbda}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda}=-\\alpha\n\\end{equation}\n\nFrom~\\eqref{eq:svr_min_qp_wolfe_dual} we can notice that the equality constraint $e^T \\alpha = 0$ arises form the stationarity condition $\\partial_{{b}} \\mathcal{W}=0$. So, again, for simplicity, we can again consider the bias term $b$ embedded into the weight vector. In this way the dimensionality of~\\eqref{eq:l2_svr_lagrangian_dual} is reduced by removing the multipliers $\\mu$ which was allocated to control the equality constraint $e^T \\alpha=0$, so we will end up solving exactly the problem~\\eqref{eq:reg_bias_wolfe_dual_l2_svr}.\n\n\\begin{equation} \\label{eq:l2_svr_lb_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + ee^T + D) \\alpha+q^T\\alpha - \\lambda^T \\alpha \\\\\n    &= \\frac{1}{2} \\alpha^T (Q + ee^T + D)\\alpha + (q - \\lambda)^T \\alpha \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nNow, taking the derivative of the Lagrangian $\\mathcal{L}$ wrt $\\alpha$ and settings it to 0 gives:\n\n\\begin{equation} \\label{eq:l2_svr_lb_lagrangian_der_a}\n\t\\frac{\\partial \\mathcal{L}}{\\partial \\alpha}=0\\Rightarrow (Q + ee^T + D) \\alpha + (q - \\lambda) = 0\n\\end{equation}\n\nWith $\\alpha$ optimal solution of the linear system:\n\n\\begin{equation} \\label{eq:l2_svr_lb_lagrangian_sol}\n    (Q + ee^T + D) \\alpha = - (q - \\lambda)\n\\end{equation}\n\nthe gradient wrt $\\lambda$ is:\n\n\\begin{equation} \\label{eq:l2_svr_lb_lagrangian_der_l}\n    \\frac{\\partial \\mathcal{L}}{\\partial \\lambda}=-\\alpha\n\\end{equation}\n\n\\bigskip\n\nNote that since the Hessian matrix $Q$ of the $\\mathcal{L}_2$-SVR is symmetric and strictly positive definite, we can find the unique solution of the Lagrangian dual relaxation, i.e.,~\\ref{eq:l2_svr_lagrangian_sol} and~\\ref{eq:l2_svr_lb_lagrangian_sol}, by solving the system with the Cholesky factorization.\n\n\\bigskip\n\nSince the linear algebra methods in the ML context are crucial and also in order to deal with a per-iteration cost equals to the other algorithms described later to provide a coherent comparison of all at the end, we will solve it with a primal-dual optimization method and we modify its definition by adding a strictly convex augmentation term, i.e., a penalty term, in order to improve the actual convergence of the algorithms. So, if we consider a general quadratic optimization problem subject to linear constraints, i.e., equality and inequality constraints, defined as:\n\n\\begin{equation}\n    \\begin{aligned} \n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & G \\alpha \\leq h \\\\ & lb \\leq \\alpha \\leq ub\n    \\end{aligned}\n\\end{equation}\n\nor, equivalently:\n\n\\begin{equation}\n    \\begin{aligned}\n        \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha \\\\\n            \\textrm{subject to} \\quad & A \\alpha = b \\\\ & \\hat{G} \\alpha \\leq \\hat{h}\n    \\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n G \\\\\n-I \\\\\n I \n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\nh & -lb & ub\n\\end{bmatrix}$; we give the following \\emph{augmented Lagrangian dual}:\n\n\\begin{equation} \\label{eq:l2_svr_gen_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\quad & \\frac{1}{2} \\alpha^T Q \\alpha + q^T \\alpha + \\mu^T (A \\alpha - b) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| A \\alpha - b \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwith $\\rho > 0$.\n\n\\bigskip\n\nAccording to this definition, we change the formulation~\\ref{eq:l2_svr_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l2_svr_aug_lagrangian_dual}\n\t\\begin{aligned}\n\t\t    \\max_{\\mu,\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\mu,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + D) \\alpha+q^T\\alpha + \\mu^T (e^T \\alpha) + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| e^T \\alpha \\|^2 + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nand the formulation~\\ref{eq:l2_svr_lb_lagrangian_dual} as:\n\n\\begin{equation} \\label{eq:l2_svr_lb_aug_lagrangian_dual}\n\t\\begin{aligned}\n    \t\\max_{\\lambda} \\min_{\\alpha} \\mathcal{L}(\\alpha,\\lambda) &= \\frac{1}{2} \\alpha^T (Q + ee^T + D) \\alpha + q^T \\alpha + \\lambda^T (\\hat{G} \\alpha - \\hat{h}) + \\frac{\\rho}{2} \\| \\hat{G} \\alpha - \\hat{h} \\|^2 \\\\\n    \\text{subject to} \\quad & \\,\\, \\lambda \\geq 0\n\t\\end{aligned}\n\\end{equation}\n\nwhere $\\hat{G} =\n\\begin{bmatrix}\n-I\n\\end{bmatrix}$ and $\\hat{h} =\n\\begin{bmatrix}\n-lb\n\\end{bmatrix}$ with $lb^T = [0, \\dots, 0]$ and $\\rho > 0$.", "meta": {"hexsha": "2defa7bae5d097f42ae2bdefab534a0dd0cef8c3", "size": 24919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/linear_svr.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/linear_svr.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/linear_svr.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": 44.6577060932, "max_line_length": 676, "alphanum_fraction": 0.6714153859, "num_tokens": 9118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8774767746654974, "lm_q1q2_score": 0.7901939698704536}}
{"text": "\n\\subsection{Membership relation}\n\nSay we have a preterite \\(P(x)\\) which is true for some values of \\(x\\). Sets allow us to explore the properties of these values.\n\nWe may want to talk about a collection of terms for which \\(P(x)\\) is true, which we call a set.\n\nTo do this we need to introduce new axioms, however first we can add (conservative) definitions to help us do this.\n\nWe introduce a new relation: membership. If element \\(x\\) is in set \\(s\\) then the following relation is true, otherwise it is false:\n\n\\(x\\in s\\)\n\nSets are also terms. In first-order logic they will be included in quantifiers. Indeed, in set theory, we aim to treat everything as sets.\n\nIf a term is not a member of another term, we can write this using the non-member relation as follows:\n\n\\(\\forall x \\forall s [\\neg (x\\in s)\\leftrightarrow x\\not\\in s]\\)\n\n", "meta": {"hexsha": "d3b2a99227924c86b31d9fe2a035e74c6a927982", "size": 839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/02-01-relations.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/setsSpecification/02-01-relations.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/setsSpecification/02-01-relations.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.95, "max_line_length": 138, "alphanum_fraction": 0.7342073897, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897509188344, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7900131046244411}}
{"text": "\\documentclass[a4paper]{scrartcl}\n\\usepackage{amsmath} \n\n\\title{Important ML formulas}\n\\date{}\n\n\\begin{document}\n\\maketitle\n\n\\section{Gaussians}\n\nDefinition:\n\n\\begin{align}\n    \\mathcal{N}(x|\\mu, C) &= \\frac{1}{|C| (2 \\pi)^{d/2}} \\exp\\left[ -\\frac{1}{2} (x - \\mu)^T C^{-1} (c - \\mu) \\right]\n\\end{align}\n\nMarginals and conditionals (see Bishop, (2.113) - (2.117)):\n    \n\\begin{align}\n    p(x) &= \\mathcal{N}(x|\\mu, \\Lambda^{-1}) \\\\\n    p(y|x) &= \\mathcal{N}(y|A x + b, L^{-1}) \\\\\n    p(y) &= \\int \\mathrm{d}x\\; p(y|x)p(x) \n        = \\mathcal{N}(y|A\\mu + b, L^{-1} + A \\Lambda^{-1} A^T) \\\\\n    p(x|y) &= \\frac{p(y|x)p(x)}{p(y)} \n        = \\mathcal{N}(y|\\Sigma \\left\\{ A^T L (y - b) + \\Lambda \\mu \\right\\}, \\Sigma) \\\\\n    \\Sigma &= \\left( \\Lambda  + A^T L A \\right)^{-1}\n\\end{align}\n\nConditioning on blocks\n\n\\begin{align}\n    p(x) &= \\mathcal{N}(x|\\mu, C) \\\\\n    C &= \\begin{pmatrix}\n        C_N & k \\\\\n        k^T & c\n    \\end{pmatrix} \\\\\n    x &= (x_N, x_{N+1})^T \\\\\n    \\mu &= (\\mu_N, \\mu_{N+1})^T\n\\end{align}\n\nThen:\n\n\\begin{align}\n    p(x_{N+1}|x_{N}) &= \n        \\mathcal{N}\\left( x_{N+1} | \\tilde{\\mu}_{N+1}, \\tilde{C}_{N+1} \\right) \\\\\n    \\tilde{\\mu}_{N+1} &= \\mu_{N+1} + k^T C_N^{-1} (x_N - \\mu_N) \\\\\n    \\tilde{C}_{N+1} &= c - k^T C_N^{-1} k\n\\end{align}\n\n\\section{Laplace approximation}\n\\begin{align}\n    \\log p(x) \n        &\\approx \\log p(x^\\star) + \\frac{1}{2} \\left(x - x^\\star \\right)^T H \\left(x - x^\\star\\right) \\\\\n        &= \\mathcal{N}(x|x^\\star, H^{-1}) \\\\\n    &\\left. \\frac{\\partial}{\\partial x} \\log p(x) \\right|_{x^\\star} = 0 \\\\\n    &H_{ij} = \\frac{\\partial^2}{\\partial x_i \\partial x_j} \\log p(x) \n\\end{align}\n\n\\section{Sigmoids}\n\\begin{align}\n    \\sigma(x) &= \\frac{1}{1 - \\exp(-x)} \\\\\n    \\sigma(-x) &= 1 - \\sigma(x)  \\\\\n    \\log \\frac{\\sigma(x)}{1 - \\sigma(x)} &= x \\\\\n    \\frac{\\partial}{\\partial x}\\sigma(x) &= \\sigma(x) (1 - \\sigma(x))\n\\end{align}\n\n\\section{Block Matrix Inverse}\n\\begin{align}\n    \\begin{bmatrix} \n            A_{00} & A_{01} \\\\ \n            A_{10} & A_{11} \n    \\end{bmatrix}^{-1} \n    &= \\begin{bmatrix} \n        A_{00}^{-1} + F E^{-1} G & -F E^{-1} \\\\ \n        -E^{-1} G & E^{-1} \n    \\end{bmatrix} \\\\\n    E &= A_{11} - A_{10} A_{00}^{-1} A_{01} \\\\\n    F &= A_{00}^{-1}A_{01} \\\\\n    G &= A_{10} A_{00}^{-1}\n\\end{align}\n\n\\end{document}", "meta": {"hexsha": "d59d605ffe725146be33c3fd3221fd52570a7435", "size": 2279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "BuildingBlocks/formulas.tex", "max_stars_repo_name": "chmp/misc-exp", "max_stars_repo_head_hexsha": "2edc2ed598eb59f4ccb426e7a5c1a23343a6974b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-31T20:54:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-23T19:03:00.000Z", "max_issues_repo_path": "BuildingBlocks/formulas.tex", "max_issues_repo_name": "chmp/misc-exp", "max_issues_repo_head_hexsha": "2edc2ed598eb59f4ccb426e7a5c1a23343a6974b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 7, "max_issues_repo_issues_event_min_datetime": "2020-03-24T16:14:34.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-18T20:51:37.000Z", "max_forks_repo_path": "BuildingBlocks/formulas.tex", "max_forks_repo_name": "chmp/misc-exp", "max_forks_repo_head_hexsha": "2edc2ed598eb59f4ccb426e7a5c1a23343a6974b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-07-29T07:55:49.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-29T07:55:49.000Z", "avg_line_length": 27.4578313253, "max_line_length": 117, "alphanum_fraction": 0.4901272488, "num_tokens": 971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7899975459825012}}
{"text": "\\chapter{Algebraic Approach}\n\tIn this chapter we present some different approaches to the construction of $\\Zp$ and $\\Qp$, definitely with a more algebraic flavour. \n\t\\section{Definition and algebraic properties of $\\Zp$}\n\t\t\\label{section:Zp}\n\t\t\\begin{defn}\n\t\t\tA \\padic integer is a formal series $\\sum_{i \\geq 0} a_ip^i$ with integral coefficients $0 \\leq a_i \\leq p-1$.\n\t\t\\end{defn}\t\n\t\tThe set $\\Zp$ contains all the so called \\padic integers and is easily identified with \n\t\t\\[\n\t\t\t\\prod_{i\\geq0} \\{0, 1, \\dots, p-1\\} = \\{0, 1, \\dots, p-1\\}^\\N\n\t\t\\]\n\t\twhich is clearly not countable. We have a natural embedding $\\N \\hookrightarrow \\Zp$ just writing every number in base $p$.\\newline\n\t\tWe can define addition between two \\padic integer in a component-wise way with a carry system: given $a, b \\in \\Zp$ the first component of the sum is $a_0 + b_0$ if it's less than $p$, or $a_0 + b_0 - p$ otherwise and, in this case, we add a carry to the component of p and so on. Here's a quick example:\n\t\t\\begin{gather*}\n\t\t\t1 = 1\\cdot p^0 + 0\\cdot p^1 + 0 \\cdot p^2 + \\dots \\\\\n\t\t\tx = (p - 1)\\cdot p^0 + (p-1)\\cdot p^1 + (p-1)\\cdot p^2 + \\dots = \\sum_{i\\geq 0}(p-1)p^i\\\\\n\t\t\t1 + x = 0\\cdot p^0 + 0\\cdot p^1 + 0\\cdot p^2 + \\dots = 0\\\\\n\t\t\t\\implies -1 = \\sum_{i\\geq 0}(p-1)p^i.\n\t\t\\end{gather*} \n\t\tThis sum admits inverse in $\\Zp$, given $a = \\sum_{i\\geq0} a_ip^i$ we define $b := \\sigma(a) = \\sum_{i\\geq0}(p - 1 - a_i)p^i \\in \\Zp$ so $a + b + 1 = 0$, i.e. $-a = \\sigma(a) + 1$. So $(\\Zp, +)$ is an abelian group (easy to verify) and with an involution $\\sigma\\colon \\Zp \\to \\Zp$ ($\\sigma^2 = id$). \\newline\n\t\tWe can also define a product on $\\Zp$, multiplying the two expansions in a Cauchy way (exactly like the multiplication between polynomials) and using a system of carries to keep the digits in $\\{0, 1, \\dots, p-1\\}$. This procedure is simply the classical multiplication of natural integers written in base $p$, pursued indefinitely. For example\n\t\t\\begin{equation*}\n\t\t\t-1 = (p-1)\\sum_{i\\geq 0}p^i \\textrm{ ,  } -(p-1)\\sum_{i\\geq 0}p^i = 1 \\textrm{ ,  } \\sum_{i\\geq 0}p^i = \\frac{1}{1 - p}\n\t\t\\end{equation*}\n\t\twhich shows that $1-p \\in \\Zp$ is invertible. Not every element of $\\Zp$ admits inverse, for example $p$ is not invertible because\n\t\t\\begin{equation*}\n\t\t\tp \\cdot \\sum_{i\\geq 0}a_ip^i = a_0p + a_1p^2 + \\dots \\neq 1 + 0p + 0p^2 + \\dots = 1.\n\t\t\\end{equation*}\n\t\tThen $\\Zp$ equipped with these two operations is a commutative ring. We can now extend $\\N \\hookrightarrow \\Zp$ to $\\Z \\hookrightarrow \\Zp$, which is a ring injective homomorphism so we immediately deduct that $\\textrm{char}(\\Zp) = 0$.\n\t\t\\begin{prop}\t\t\t\t\t\t\n\t\t\tThe ring $\\Zp$ is an integral domain.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tGiven $a = \\sum_{i \\geq 0}a_ip^i \\neq 0, b = \\sum_{i\\geq 0}b_ip^i \\neq 0$ we have that $ab = \\sum_{i\\geq 0}c_ip^i \\neq 0$: infact if $a_v, b_w$ are the first non zero coefficients of $a$ and $b$ then $p \\nmid a_v, p \\nmid b_w \\implies p \\nmid a_vb_w$ which means that $c_{v+w} = a_vb_w \\neq 0$.\n\t\t\\end{proof}\n\t\tLet us emphasize the importance of $p$ being a prime number: in the last proposition we used the fact that $\\Z/p\\Z$ is a domain and this is obviously false if $p$ isn't a prime. If we choose to work with $n$-adic integers, with $n$ being a composite integer, then, since $\\Z/n\\Z$ is not a domain, we obtain that also $\\Z_n$ is not a domain, i.e. there are divisors of zero, so we can't even talk about the quotient field. \n\t\t\\begin{example}\n\t\t\tHere's an example with $n = 10$, using the definition of $\\Zp$ given in \\cref{thm:projective-lim}:\n\t\t\t\\begin{gather*}\n\t\t\t\tu = (u_n)_n \\in \\lim_{\\longleftarrow} \\Z/10^n\\Z \\qquad u_n := 2^{5^n} \\mod 10^n, \\\\\n\t\t\t\tv = (v_n)_n \\in \\lim_{\\longleftarrow} \\Z/10^n\\Z \\qquad v_n := 5^{2^n} \\mod 10^n.\n\t\t\t\\end{gather*}\n\t\t\tIt can be proved by induction that\n\t\t\t\\[\n\t\t\t\tu_n = 2^{5^n} \\equiv 2^{5^{n-1}} = u_{n-1}, \\qquad v_n = 5^{2^n} \\equiv 5^{2^{n-1}} = v_{n-1} \\mod 10^{n-1}\n\t\t\t\\]\n\t\t\tso our definitions are coherent. Obviously $u, v \\neq 0$ but it's easily seen that $u \\cdot v = 0$: infact $u_n \\cdot v_n \\equiv 0 \\mod 10^n$ (we recall that products in the projective limit are done component-wise). More facts about $10$-adic integers can be found at \\cite{michon:padic-arithmetic}.\n\t\t\\end{example}\n\t\tWe can define $\\ord\\colon \\Zp \\to \\N \\cup \\{\\infty\\}$ as follows\n\t\t\\begin{equation*}\n\t\t\t\\ord a := \n\t\t\t\\begin{cases*}\n\t\t\t\t+\\infty, & if $a = 0$; \\\\\n\t\t\t\tv, & otherwise;\n\t\t\t\\end{cases*}\n\t\t\\end{equation*}\n\t\twhere $v$ is the minimum integer such that $a_v > 0$. It's easily seen that $\\ord$ behaves exactly like a discrete valuation.\\newline\n\t\tCalled $\\Fp = \\Z/p\\Z$ the field with $p$ elements, the map $a = \\sum_{i \\geq0}a_ip^i \\mapsto a_0 \\mod p$ is a ring homomorphism $\\varepsilon\\colon \\Zp \\to \\Fp$, which is obviously surjective and with kernel $p\\Zp = \\Set{a\\in \\Zp | a_0 = 0}$. Then $\\Zp/p\\Zp$ is isomorphic to $\\Fp$ so $p\\Zp$ is a maximal ideal of $\\Zp$.\n\t\t\\begin{prop}\n\t\t\tThe group of invertible elements in $\\Zp$ is $\\Zp^{\\times} = \\Set{\\sum_{i \\geq 0}a_ip^i \\in \\Zp | a_0 \\neq 0}$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tIf $a \\in \\Zp$ is invertible also its reduction $\\varepsilon(a) \\in \\Fp$ must be, so we obtain\n\t\t\t\\[\n\t\t\t\t\\Zp^{\\times} \\subseteq \\Set{\\sum_{i \\geq 0}a_ip^i \\in \\Zp | a_0 \\neq 0 }.\n\t\t\t\\]\n\t\t\tThe other inclusion can be proved, but, for brevity, we'll show it using an equivalent definition of $\\Zp$.\n\t\t\\end{proof}\n\t\t\\begin{corollary}\n\t\t\tEvery non-zero \\padic integer $a \\in \\Zp$ has a canonical representation $a = p^vu$ where $v = \\ord a$ and $u \\in \\Zp^{\\times}$ is a \\padic unit.\n\t\t\\end{corollary}\n\t\t\\begin{prop}\n\t\t\tThe ring $\\Zp$ is a principal ideal domain whose ideals are $\\{0\\}$ and $p^k\\Zp := \\set{x \\in \\Zp | \\mathrm{ord}_p\\, x \\geq k}$ for $k \\in \\N$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet $I \\neq 0$ be a nonzero ideal a $\\Zp$. Chosen $0 \\neq a \\in I$ an element of minimal order, we have $a = p^ku$ with $u \\in \\Zp^{\\times}$ so $p^k = a \\cdot u^{-1} \\in I$ which implies $p^k\\Zp = (p^k) \\subseteq I$. Conversely if $b \\in I$ then $w = \\ord b \\geq k$ so $b = p^wu' = p^kp^{w-k}u' \\in p^k\\Zp$, which proves $I \\subseteq p^k\\Zp$.\n\t\t\\end{proof}\n\t\tLastly, we note that $\\Zp$ is a local ring, i.e. a commutative ring with a maximal ideal $p\\Zp$. \n\t\\section{Topological properties of $\\Zp$}\n\t\tNow we are ready to add a topological structure to the ring of \\padic integers.\n\t    Since we can identify every element of $\\Zp$ with the sequence of its coefficients $(a_n)_{n \\in \\N} \\in \\{0, 1, \\dots, p-1\\}^\\N =: X_p$ it's a natural choice to assign to $\\Zp$ the product topology of $X_p$, where each factor is a discrete set.\\newline\n\t\tBy Tychonoff theorem we immediately get that $\\Zp$ is compact and it's also easy to see that its connected components are points, i.e. it's totally disconnected. Since the discrete topology is metrizable (using the trivial metric) also $\\Zp$ is metrizable, being product of a countable number of metric spaces. Given $x = (a_n)_n, y=(b_n)_n \\in X_p \\leftrightarrow \\Zp$ we can define their distance as \n\t\t\\begin{equation*}\n\t\t\td(x, y) := \\sup_{i \\geq 0} \\frac{\\delta_{a_i, b_i}}{p^i} = \\frac{1}{p^{\\ord(x - y)}}.\n\t\t\\end{equation*}\n\t\tThis is exactly the metric induced by the \\padic absolute value $\\pabs{\\ }$ introduced above (and satisfies all of its properties)!\n\t\t\\begin{defn}\n\t\t\tA topological group is a group $G$ equipped with a topology such that the map $(x, y) \\mapsto xy^{-1}$ is continuous. A topological ring is a ring $A$ with a topology such that addition $(x, y) \\mapsto x + y$ and multiplication $(x, y) \\mapsto xy$ are continuous.\n\t\t\\end{defn}\n\t\t\\begin{prop}\n\t\t\t$\\Zp$ is a topological ring.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tFirst of all we prove that $(x, y) \\mapsto x - y$ is a continuous map, i.e. $(\\Zp, +)$ is a topological group. Using the \\padic metric, given $a, b \\in \\Zp$ we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{x - a} \\leq p^{-n}, \\qquad \\pabs{y - b} \\leq p^{-n} \\\\\n\t\t\t\t\\implies \\pabs{(x - y) - (a - b)} \\leq \\max\\left\\{\\pabs{x-a},\\pabs{y-b} \\right\\} \\leq p^{-n}\n\t\t\t\\end{gather*}\n\t\t\tso the map is continuous at every point $(a, b) \\in \\Zp \\times \\Zp$. Now we have to prove the continuity of multiplication. Fixed $a, b \\in \\Zp$ if $x = a + h, y = b + k \\in \\Zp$ we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{xy - ab} = \\pabs{(a + h)(b + k) - ab} = \\pabs{ak + hb + hk} \\leq \\\\\n\t\t\t\t\\leq \\max\\left\\{\\pabs{a}, \\pabs{b} \\right\\}\\cdot \\left(\\pabs{h} + \\pabs{k}\\right) + \\pabs{h}\\pabs{k} \\to 0, \\qquad \\text{as } \\pabs{h},\\pabs{k} \\to 0,\n\t\t\t\\end{gather*}\n\t\t\tproving the continuity of the multiplication at any point. These two conditions are equivalent to the ones given in the definition of topological ring: infact the map $(x, y) \\mapsto x + y$ can be obtained by composing the map $(x, y) \\mapsto (x, -y)$ (continuous thanks to product topology and continuity of multiplication) and the map $(x, y) \\mapsto x - y$.\n\t\t\\end{proof}\n\t\t\\begin{defn}\n\t\t\tA completion of a topological metrizable group $G$ is a pair $(\\widehat{G}, j)$ where $\\widehat{G}$ is a Cauchy-complete group and $j\\colon G \\to \\widehat{G}$ is a homomorphism such that\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $j(G)$ is dense in $\\widehat{G}$;\n\t\t\t\t\\item $j$ is a homeomorphism $G \\to j(G)$;\n\t\t\t\t\\item any continuous homomorphism $f\\colon G \\to G'$, where $G'$ is a complete group, can be uniquely factorized as $f = g \\circ j\\colon  G \\to \\widehat{G} \\to G'$ with a continuous homomorphism $g\\colon \\widehat{G} \\to G'$.\n\t\t\t\\end{itemize}\n\t\t\\end{defn}\n\t\tIt's clear that if $G$ admits a completion $\\widehat{G}$ then every other completion $\\widehat{G}'$ is isomorphic to $\\widehat{G}$ (from the definition we have a continuous bijective homomorphism $g\\colon \\widehat{G} \\to \\widehat{G}'$).\n\t\tOur aim is now to prove that $\\Zp$ is a complete space and $(\\Zp, +)$ is the completion of $(\\Z, +)$ equipped with the \\padic metric. We'll now show (and prove) some general results on topological groups which will help us.\n\t\t\\begin{lemma}\n\t\t\tLet $G$ be a topological group. $G$ is metrizable (i.e. there exists a metric which induces the topology) if and only if $G$ is Hausdorff and first countable (i.e. every point has a countable fundamental system of neighbourhoods).\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tThe $\\implies$ part is trivial. For the converse statement, check \\cite[Chap. \\RN{11}]{bourbaki:topologie}.\n\t\t\\end{proof}\n\t\t%%% Facts %%%\n\t\tA metrizable group $G$ always admits a metric $d$ invariant under left translations, i.e. $d(x, y) = d(gx, gy)$ for every $g \\in G$. A metrizable group can always be completed.\n\t\t%%% End of facts %%%\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:closure-group}\n\t\t\tIf $G$ is a topological group and $H$ is a subgroup of $G$ then the closure $\\overline{H}$ of $H$ is a subgroup of $G$. \n\t\t\t%%% This may be useful in future but not now %%%\n\t\t\t\\begin{comment}\n\t\t\t\\begin{enumerate}[label=(\\alph*)]\n\t\t\t\t\\item the closure $\\overline{H}$ of $H$ is a subgroup of $G$.\n\t\t\t\t\\item $G$ is Hausdorff exactly when its neutral element is closed.\n\t\t\t\\end{enumerate}\n\t\t\t\\end{comment}\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\t%\\textit{(a)}\n\t\t Let $\\phi\\colon G \\times G \\to G$ be the continuous map $(x, y) \\to xy^{-1}$. Since $H \\leq G$ we have $\\phi(H \\times H) \\subseteq H$ hence\n\t\t\t\\begin{equation*}\n\t\t\t\t\\phi(\\overline{H} \\times \\overline{H}) = \\phi(\\overline{H \\times H}) \\subseteq \\overline{\\phi(H \\times H)} \\subseteq \\overline{H}\n\t\t\t\\end{equation*}\n\t\t\twhich proves $\\overline{H} \\leq G$.\n\t\t\t\\begin{comment}\n\t\t\t\\textit{(b)} We recall that $G$ is Hausdorff exactly when its diagonal $\\Delta_G$ is closed in $G \\times G$. We have this chain of implications\n\t\t\t\\begin{center}\n\t\t\t\tG Hausdorff $\\implies$ $\\{e\\}$ closed $\\implies$ \\\\\n\t\t\t\t$\\Delta_G = \\phi^{-1}(e)$ closed in $G \\times G$ $\\implies$ G Hausdorff\n\t\t\t\\end{center}\n\t\t\twhich concludes the proof.\n\t\t\t\\end{comment}\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:clopen-group}\n\t\t\tLet $G$ be a topological group and $H \\leq G$. If $H$ contains a neighbourhood of the neutral element of $G$ then $H$ is a clopen of $G$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet $V$ be such neighbourhood; then $\\forall h \\in H$, $hV$ is a neighbourhood of $h$ in $G$ which is fully contained in $H$. This proves $H$ is open in $G$. Since maps like $x \\mapsto gx$ are homeomorphisms for every $g$ in $G$, we have that every coset $gH$ of $H$ in $G$ is open. Now $G\\backslash H = \\bigcup_{g \\notin H}gH$ is open, i.e. $H$ is closed in $G$.\n\t\t\\end{proof}\n\t\tFor example the subgroups $p^n\\Zp$ of $(\\Zp, +)$ are open and closed.\n\t\t\\begin{defn}\n\t\t\tA subspace $Y$ of a topological space $X$ is \\emph{locally closed} (in $X$) when each point $y \\in Y$ has an open neighbourhood $V$ in $X$ such that $Y \\cap V$ is closed in $V$.\n\t\t\\end{defn}\n\t\tIt can be proved that $Y \\subseteq X$ is locally closed if and only if $Y$ is open in its closure $\\overline{Y}$. \n\t\t\\begin{thm}\n\t\t\tLet $G$ be a topological group and $H$ a locally closed subgroup. Then $H$ is closed.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tIf $H$ is locally closed then it's open in its closure $\\overline{H}$. In particular, if $e$ is the neutral element of $G$ then $e \\in H$ and $\\exists V \\subseteq H$, which is a neighbourhood of $e$ in $\\overline{H}$. By \\cref{lemma:closure-group}, $\\overline{H} \\leq G$ so, applying \\cref{prop:clopen-group} with $H \\leq \\overline{H}$, we get that $H$ is closed in $\\overline{H}$, i.e. $H = \\overline{H}$, which clearly implies $H$ is closed in $G$.\n\t\t\\end{proof}\n\t\tIf we consider only Hausdorff spaces we immediately get that locally compact subsets are locally closed, because a compact set is closed in a Hausdorff space. We recall that a topological group is locally compact exactly when one of its points has a fundamental system of compact neighbourhoods (then by translation every point admits one).\n\t\t\\begin{corollary}\n\t\t\tLet $H$ be a locally compact subgroup of a Hausdorff topological group $G$. Then $H$ is closed.\n\t\t\\end{corollary}\n\t\t\n\t\tLet $G$ be a topological metrizable group which has $\\widehat{G}$ as its completion. If $G$ is locally compact then it must be closed in its completion (we identify $G$ with its image in $\\widehat{G}$). But since $G$ is dense in $\\widehat{G}$ we get $\\widehat{G} = G$.\n\t\t\\begin{corollary}\n\t\t\t\\label{corollary:locally_compact_group}\n\t\t\tA locally compact metrizable group is complete.\n\t\t\\end{corollary}  \n\t\tNow we can prove the following\n\t\t\\begin{prop}\n\t\t\t$\\Zp$ is a compact, complete metrizable space. More precisely, the topological group $\\Zp$ is the completion of $\\Z$, equipped with the \\padic metric.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tWe have already proved that $\\Zp$ is compact and metrizable. To see that it's complete we can just apply \\cref{corollary:locally_compact_group}, because $\\Zp$ is locally compact (from general topology we know that Hausdorff and compact implies that every point has a fundamental system of compact neighbourhoods).\\newline\n\t\t\tLet's consider $j\\colon \\Z \\hookrightarrow \\Zp$ the natural embedding: it is a continuous homomorphism ($\\Z$ with the \\padic metric has the topology induced by $\\Zp$) and $j(\\Z)$ is dense in $\\Zp$. Given $\\Zp \\ni x = \\sum_{i \\geq 0} a_ip^i$ if \n\t\t\t\\begin{gather*}\n\t\t\t\tx_n := \\sum_{0 \\leq i < n} a_ip^i \\in \\N\n\t\t\t\\end{gather*}\n\t\t\tthen $(x_n)_n \\subseteq \\Z$ is a Cauchy sequence converging to $x$. To verify the universal property, given a continuous homomorphism $f\\colon \\Z \\to X$, where $X$ is a complete group, we can define $\\tilde{f}\\colon  \\Zp \\to X$ as follows: given $x \\in \\Zp$ and $(x_n)_n \\subseteq \\Z$ a sequence convergent to $x$ then\n\t\t\t\\begin{gather*}\n\t\t\t\t\\tilde{f}(x) := \\lim_{n \\to +\\infty} f(x_n)\n\t\t\t\\end{gather*}\n\t\t\twhere the limit is taken in $X$. This is well defined: if $(y_n)_n \\subseteq \\Z$ is another sequence convergent to $x$ we have that $\\pabs{x_n - y_n} \\to 0$ as $n \\to +\\infty$ so\n\t\t\t\\begin{gather*}\n\t\t\t\t\\lim_{n \\to +\\infty} \\left( f(x_n) - f(y_n) \\right) = \\lim_{n \\to +\\infty} f(x_n - y_n) = f\\left(\\lim_{n \\to +\\infty} (x_n - y_n)\\right) = f(0) = 0\n\t\t\t\\end{gather*}\n\t\t\twhere we exploited the fact that $f$ is continuous and a homomorphism. The fact that $\\tilde{f}$ is a continuous homomorphism is easy to prove.\n\t\t\\end{proof}\n\t\t\\begin{corollary}\n\t\t\tThe addition and multiplication of \\padic integers are the only continuous operations on $\\Zp$ extending the classic addition and multiplication on $\\Z$.\n\t\t\\end{corollary}\n\t\\section{$\\Zp$ as a projective limit}\n\t\tWe now want to give another definition of $\\Zp$, using projective limits.\n\t\t\\begin{defn}\n\t\t\tA sequence $(E_n, \\varphi_n)_{n \\in \\N}$ of sets and maps $\\varphi_n\\colon E_{n+1} \\to E_n$ is called a \\textit{projective system}. \\newline\n\t\t\tA set $E$ together with maps $\\psi_n\\colon E \\to E_n$ such that $\\psi_n = \\varphi_n \\circ \\psi_{n+1}$ $\\forall n \\in \\N$ is called a \\textit{projective limit} of the sequence $(E_n, \\varphi_n)_n$ if the following holds: for each set $X$ and maps $f_n\\colon X \\to E_n$ satisfying $f_n = \\varphi_n \\circ f_{n+1}$ $\\forall n \\in \\N$ there is a unique $f\\colon X \\to E$ such that $f_n = \\psi_n \\circ f$ for every $n \\in \\N$ (universal factorization property).\n\t\t\\end{defn}\n\t\tThe maps $\\varphi_n\\colon E_{n+1} \\to E_n$ are called transition maps and the whole system, which is often called \\textit{inverse system}, can be represented by\n\t\t\\begin{gather*}\n\t\t\tE_0 \\xleftarrow{\\varphi_0} E_1 \\xleftarrow{\\varphi_1} E_2 \\xleftarrow{\\varphi_2} \\dots \\xleftarrow{\\varphi_{n}} E_{n+1} \\longleftarrow \\dots\n\t\t\\end{gather*}\n\t\tand denoting $E$ as $\\lim\\limits_{\\longleftarrow}E_n$, the complete scheme would look like this:\n\t\t\\begin{equation*}\n\t\t\t\\begin{tikzcd}[row sep = large, column sep = huge]\n\t\t\t\t& & & &  \\lim\\limits_{\\longleftarrow}E_n  \\arrow[dlll, \"\\psi_n\"']  \\arrow[dll, \"\\psi_{n+1}\"]\t\\\\\n\t\t\t\t\\dots & \\arrow[l] E_n & \\arrow[l, \"\\varphi_n\"] E_{n+1} & \\arrow[l] \\dots \\\\\n\t\t\t\t & & & &  X \\arrow[ulll, \"f_n\"]  \\arrow[ull, \"f_{n+1}\"'] \\arrow[uu, dashed, \"f\"]\n\t\t\t\\end{tikzcd}\n\t\t\\end{equation*}\n\t\t\\begin{thm}\n\t\t\tFor every projective system $(E_n, \\varphi_n)_{n \\in \\N}$ there exists a projective limit $E = \\lim\\limits_{\\longleftarrow} E_n \\subset \\prod_n E_n$ with maps $\\psi_n\\colon E \\to E_n$ given by (restriction of) projections.\\newline\n\t\t\tMoreover, given $(E', \\psi'_n)$ another projective limit of the system, there's a unique bijection $f\\colon E' \\to E$ such that $\\psi'_n = \\psi_n \\circ f$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tFirst we prove existence. Let \n\t\t\t\\begin{gather*}\n\t\t\t\tE := \\{(x_n)_n : \\varphi_n(x_{n+1}) = x_n \\text{   } \\forall n \\geq 0 \\} \\subset \\prod_{n \\geq 0} E_n\n\t\t\t\\end{gather*}\n\t\t\tbe the set of \\textit{coherent sequences} (with respect to the transition maps $\\varphi_n$). If $p_n\\colon \\prod_{i \\geq 0}E_i \\to E_n$ is the canonical projection then we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\varphi_n(p_{n+1}(x)) = p_n(x) \\qquad \\forall x \\in E.\n\t\t\t\\end{gather*}\n\t\t\tSo, if we define $\\psi_n := \\left.p_n\\right|_E\\colon E \\to E_n$ we have $\\varphi_n \\circ \\psi_{n+1} = \\psi_n$. We'll now show that $(E, \\psi_n)$ is a projective limit of the system. If $(E', \\psi'_n)$ is another set equipped with maps satisfying $\\varphi_n \\circ \\psi'_{n+1} = \\psi'_n$ (for every $n\\geq 0$) then we need to prove that there's a unique factorization of $\\psi'_n$ by $\\psi_n$. We can define a vector map\n\t\t\t\\begin{gather*}\n\t\t\t\t(\\psi'_n)\\colon E' \\to \\prod_{n \\geq 0}E_n, \\qquad y \\mapsto (\\psi'_n(y))_n.\n\t\t\t\\end{gather*} \n\t\t\tSince $\\varphi_n(\\psi'_{n+1}(y)) = \\psi'_n(y)$, the image of this map is fully contained in $E$ (i.e. $(\\psi'_n(y))_n$ is a coherent sequence). Thus there's a unique map $f\\colon E' \\to E$ such that $\\psi'_n = \\psi_n \\circ f$, and it's exactly the map $(\\psi'_n)$ considered with $E$ as target (uniqueness is easy to see, recalling that $\\psi_n$ is just the restrictions to $E$ of the canonical projection $p_n$).\\newline\n\t\t\tNow we have to prove uniqueness. If $(E, \\psi_n)$ and $(E', \\psi'_n)$ are both projective limits then, by the universal factorization property, there's a unique map $f'\\colon E \\to E'$ with $\\psi_n = \\psi'_n \\circ f'$. Using the same $f\\colon E' \\to E$ defined before and substituting in $\\psi'_n = \\psi_n \\circ f$ we obtain\n\t\t\t\\begin{gather*}\n\t\t\t\t\\psi'_n = \\psi_n \\circ f = \\psi'_n \\circ f' \\circ f\n\t\t\t\\end{gather*}\n\t\t\twhich means that $f' \\circ f$ is a factorization of $\\text{id}_{E'}$ (identity map). Since $(E', \\psi'_n)$ has also, by definition of projective limit, the unique factorization property we must have $f' \\circ f = \\text{id}_{E'}$. Similarly we can prove $f \\circ f' = \\text{id}_E$, so $f$ is the searched bijection.\n\t\t\\end{proof}\n\t\tThe projective limit can be defined for a lot of structures, like topological spaces, groups or vector spaces. For example, given $(G_n, \\varphi_n)_n$ a projective system of groups and homomorphisms $\\varphi_n\\colon G_{n+1} \\to G_n$, the projective limit $G=\\lim\\limits_{\\longleftarrow}G_n$ is a group and the projections $\\psi_n\\colon G \\to G_n$ are group homomorphisms. Likewise, a projective system of topological spaces and continuous maps will have a projective limit which is itself a topological space, equipped with continuous projections.\n\t\t\n\t\tWe can now give another definition of $\\Zp$. Let's consider the ring $\\Z$ and the decreasing sequence $(p^n\\Z)_n$ of ideals. The inclusion $p^{n+1}\\Z \\subset p^n\\Z$ gives us the canonical transition homomorphism\n\t\t\\begin{gather*}\n\t\t\t\\varphi_n\\colon \\Z/p^{n+1}\\Z \\to \\Z/p^n\\Z, \\qquad x + p^{n+1}\\Z \\mapsto x + p^n\\Z.\n\t\t\\end{gather*}\n\t\tIf we consider $\\Z/p^n\\Z$ as a topological ring (equipped with discrete topology) then we have the following theorem.\n\t\t\\begin{thm}\n\t\t\t\\label{thm:projective-lim}\n\t\t\tThe map $\\Phi\\colon \\Zp \\to \\lim\\limits_{\\longleftarrow}\\Z/p^n\\Z$ which associates to the \\padic integer $x = \\sum_{i \\geq 0} a_ip^i$ the sequence of its partial sums $x_n = \\sum_{i < n}a_ip^i \\mod p^n$ is an isomorphism of topological rings.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tThe map is well defined. In-fact, since the transition maps $\\varphi_n$ are given by\n\t\t\t\\begin{gather*}\n\t\t\t\t\\sum_{i \\leq n}a_ip^i \\mod p^{n+1} \\quad \\mapsto \\quad \\sum_{i < n}a_ip^i \\mod p^n\n\t\t\t\\end{gather*}\n\t\t\tthe set of coherent sequences in $\\prod \\Z/p^n\\Z$ is exactly the set of partial sums of a \\padic expansion. From the relations\n\t\t\t\\begin{gather*}\n\t\t\t\tx_1 = a_0 \\text{, } \\quad x_2 = a_0 + a_1p \\text{, } \\quad x_3 = a_0 + a_1p + a_2p^2 \\text{, \\dots} \\\\\n\t\t\t\ta_0 = x_1 \\text{, } \\quad a_1 = \\frac{x_2 - x_1}{p} \\text{, } \\quad a_2 = \\frac{x_3 - x_2}{p^2} \\text{, \\dots}\n\t\t\t\\end{gather*}\n\t\t\twe infer that $\\Phi$ is bijective. It's easily proved that it is a ring homomorphism (sum and product are done component-wise on $\\lim\\limits_{\\longleftarrow}\\Z/p^n\\Z$), so $\\Phi$ is a ring isomorphism. Finally, this map is continuous since for every $n \\in \\N$, if $\\pi\\colon \\prod_i \\Z/p^i\\Z \\to \\Z/p^n\\Z$ is the canonical projection, we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\t\\Zp \\xrightarrow{\\Phi} \\lim\\limits_{\\longleftarrow}\\Z/p^k\\Z \\xhookrightarrow{} \\prod_k \\Z/p^k\\Z \\xrightarrow{\\pi} \\Z/p^n\\Z, \\qquad\n\t\t\t\t\t\\sum_{i \\geq 0}a_ip^i \\mapsto \\sum_{i < n} a_ip^i \\mod p^n\n\t\t\t\t\\end{aligned}\n\t\t\t\\end{gather*}\n\t\t\twhich is continuous (we recall how product topology is defined). Now $\\Phi$ is a continuous invertible map between two compact spaces so it's a homeomorphism.\n\t\t\\end{proof}\n\t\tSo we can also think $\\Zp$ as the projective limit of $\\Z/p^n\\Z$, with canonical projection maps. Let us observe that we can choose any system of representatives $\\mathcal{S}$ for $\\Z/p\\Z$ and write any \\padic integer as $x = \\sum s_ip^i$ with $s_i \\in \\mathcal{S}$. For example, if $p$ is odd we can choose to use $\\mathcal{S} = \\{-\\frac{p-1}{2}, \\dots, 0, \\dots, \\frac{p-1}{2}\\}$. Although we are only working with $\\Zp$, where $p$ is a prime number, this theorem also gives us a factorization of $\\Z_n$, for each $n \\in \\N$. In-fact, since the projective limit of a cartesian product is exactly the cartesian product of the projective limits of the factors, if $m = p_1^{\\alpha_1} \\dotsm p_r^{\\alpha_r}$ we have \n\t\t\\begin{gather*}\n\t\t\t\\Z/m^n\\Z = \\Z/p_1^{\\alpha_1\\cdot n}\\Z \\times \\dotsm \\times \\Z/p_r^{\\alpha_r\\cdot n}\\Z \\\\\n\t\t\t\\implies \\Z_m = \\lim_{\\longleftarrow} \\left( \\Z/p_1^{\\alpha_1\\cdot n}\\Z \\times \\dotsm \\times \\Z/p_r^{\\alpha_r\\cdot n}\\Z \\right) = \\prod_{i = 1}^r \\lim_{\\longleftarrow} \\Z/p_i^{\\alpha_i\\cdot n}\\Z = \\prod_{i=1}^r \\Z_{p_i^{\\alpha_i}}.\n\t\t\\end{gather*}\n\t\tIn particular, for the already seen example $m=10$, we obtain $\\Z_{10} = \\Z_2 \\times \\Z_5$.\n\t\t\n\t\tLastly, we can give another description of $\\Zp$ using formal power series $\\Z\\llbracket X \\rrbracket$. We recall that on $\\Z\\llbracket X \\rrbracket$ sum is defined component-wise (obviously here there's no carry system, unlike in $\\Zp$) and product is done in a Cauchy way (there's a natural inclusion $\\Z[X] \\xhookrightarrow{} \\Z\\ser{X}$).\n\t\t\\begin{thm}\n\t\t\tThe map\n\t\t\t\\begin{gather*}\n\t\t\t\t \\Phi\\colon \\Z\\llbracket X \\rrbracket \\to \\Zp   \\qquad \\sum a_iX^i \\mapsto \\sum a_ip^i\n\t\t\t\\end{gather*}\n\t\t\tis a ring homomorphism, which defines a canonical isomorphism\n\t\t\t\\begin{gather*}\n\t\t\t\t\\frac{\\Z\\ser{X}}{(X - p)} \\xrightarrow{\\sim} \\Zp\n\t\t\t\\end{gather*}\n\t\t\twhere $(X - p)$ is the principal ideal of $\\Z\\llbracket X \\rrbracket$ generated by $X - p$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tTo prove this theorem we exploit the universal factorization property of $\\lim\\limits_{\\longleftarrow}\\Z/p^n\\Z$, i.e. $\\Zp$.  Let's consider this sequence of maps\n\t\t\t\\begin{gather*}\n\t\t\t\t\\Phi_n\\colon \\Z\\llbracket X \\rrbracket \\to \\Z/p^n\\Z \\text{,} \\qquad \\sum a_iX^i \\mapsto \\sum_{i < n}a_ip^i \\mod p^n.\n\t\t\t\\end{gather*}\n\t\t\tThey're actually ring homomorphisms; the condition $\\Phi_n(x + y) = \\Phi_n(x) + \\Phi_n(y)$ is immediate, to check $\\Phi_n(x\\cdot y) = \\Phi_n(x)\\cdot \\Phi_n(y)$ we write\n\t\t\t\\begin{gather*}\n\t\t\t\t\\Phi_n\\left( \\sum_ia_iX^i \\cdot \\sum_jb_jX^j \\right) = \\Phi_n\\left(\\sum_k c_kX^k\\right) = \\sum_{k < n} c_kp^k \\mod p^n = \\\\ = \\sum_{k < 2n} c_kp^k \\mod p^n = \\left(\\sum_{i < n}a_ip^i\\right) \\cdot \\left(\\sum_{j < n}b_jp^j\\right) \\mod p^n =\\\\\n\t\t\t\t= \t\\Phi_n\\left(\\sum_ia_iX^i \\right) \\cdot \\Phi_n\\left(\\sum_jb_jX^j \\right).\n\t\t\t\\end{gather*}\n\t\t\tIt's immediate that these maps are all compatible with the transition homomorphisms \n\t\t\t\\[\n\t\t\t\t\\varphi_n\\colon \\Z/p^{n+1}\\Z \\to \\Z/p^n\\Z, \\qquad x + p^{n+1}\\Z \\mapsto x + p^n\\Z\n\t\t\t\\]\n\t\t\tand so we infer there exists a unique homomorphism\n\t\t\t\\begin{gather*}\n\t\t\t\t\\Phi\\colon \\Z\\llbracket X \\rrbracket \\to \\lim\\limits_{\\longleftarrow}\\Z/p^n\\Z = \\Zp\n\t\t\t\\end{gather*}\n\t\t\tcompatible with the $\\Phi_n$ (i.e. such that $\\psi_n \\circ \\Phi = \\Phi_n$, where $\\psi_n\\colon \\lim\\limits_{\\longleftarrow}\\Z/p^k\\Z \\to \\Z/p^n\\Z$ is the canonical projection). This map is surjective: if $x = \\sum a_ip^i$ is a \\padic integer then $\\Phi\\left(\\sum a_iX^i \\right) = x$. Thanks to the first theorem of isomorphism for ring homomorphisms now we just need to prove $\\ker \\Phi = (X - p)$ (then we'll have $\\Z\\llbracket X \\rrbracket/\\ker \\Phi = \\Z\\llbracket X \\rrbracket/(X - p) \\simeq \\Ima \\Phi = \\Zp$).\n\t\t\tIn other words we need to show that if the formal power series $\\sum_{i \\geq 0} a_iX^i$ is such that $\\sum_{i < n} a_ip^i \\in p^n\\Z$ for every $n \\geq 1$, then it is divisible by $X - p$. For $n = 1$ the condition is $a_0 \\equiv 0 \\mod p$ so we find $\\alpha_0 \\in \\Z$ such that $a_0 = p\\alpha_0$. For $n = 2$ we get\n\t\t\t\\begin{gather*}\n\t\t\t\ta_0 + a_1p  = \\alpha_0p + a_1p \\equiv 0 \\mod p^2 \\implies \\alpha_0 + a_1 \\equiv 0 \\mod p\n\t\t\t\\end{gather*}\n\t\t\tso we find $\\alpha_1 \\in \\Z$ such that $\\alpha_0 + a_1 = p\\alpha_1$ so $a_1 = p\\alpha_1 - \\alpha_0$. For a general $n \\geq 1$ the condition is\n\t\t\t\\begin{gather*}\n\t\t\t\ta_0 + a_1p + \\dots + a_np^n = p^n\\alpha_{n-1} + a_np^n \\equiv 0 \\mod p^{n+1}\n\t\t\t\\end{gather*}\n\t\t\tand it furnishes an integer $\\alpha_n$ such that $\\alpha_{n-1} + a_n = p\\alpha_n$, which can be written as $a_n = p\\alpha_n - \\alpha_{n-1}$. These relations between the coefficients $a_n$ and $\\alpha_n$ are exactly the ones expressed by\n\t\t\t\\begin{gather*}\n\t\t\t\t\\sum a_iX^i = -(X - p) \\cdot \\sum \\alpha_i X^i\n\t\t\t\\end{gather*}\n\t\t\twhich concludes our proof.\n\t\t\\end{proof}\n\t\\section{The field $\\Qp$}\n\t\t\\label{section:Qp}\n\t\tWe have proved that $\\Zp$ is an integral domain hence we can define the field\n\t\t\\begin{equation*}\n\t\t\t\\Qp = \\textrm{Frac}(\\Zp).\n\t\t\\end{equation*}\n\t\tTo understand its structure, we recall that any \\padic integer can be written as $x = p^mu$ where $u \\in \\Zp^\\times$. Then, $1/x = p^{-m}u^{-1}$, with $u^{-1} \\in \\Zp$. So we can write\n\t\t\\begin{equation*}\n\t\t\t\\Qp = \\Zp[1/p] = \\bigcup_{m \\geq 0} p^{-m}\\Zp.\n\t\t\\end{equation*}\n\t\tSince a non-zero element of $\\Qp$ admits a unique such writing, $\\Qp^\\times = \\coprod_{m \\in \\Z} p^m\\Zp^\\times$. Similarly to Laurent expansions of meromorphic functions around a pole, we can write every non-zero element of $\\Qp$ as\n\t\t\\begin{equation*}\n\t\t\tx = p^m \\cdot \\sum_{i \\geq 0} a_ip^i = \\sum_{i \\geq m} a_{i-m}p^i, \\qquad m \\in \\Z, a_0 \\neq 0.\n\t\t\\end{equation*}\n\t\t\n\t\tWe can extend the function $\\ord$ to $\\Qp$ as follows:\n\t\t\\begin{equation*}\n\t\t\t\\ord x = \n\t\t\t\\begin{cases}\n\t\t\t\tm, & \\text{if $x = p^mu, u \\in \\Zp^{\\times}$;} \\\\\n\t\t\t\t+\\infty, & \\text{otherwise;} \\\\\n\t\t\t\\end{cases}.\n\t\t\\end{equation*}\n\t\tGiven $x = \ta/b$ with $a \\in \\Zp, b \\in \\Zp^\\times$ it's easy to see that $\\ord x = \\ord a - \\ord b$ and, writing every number as above, we immediately get $\\ord xy = \\ord x + \\ord y$ (this holds also when $xy = 0$, with the usual convention $m + \\infty = \\infty + m = \\infty$), i.e. $\\ord\\colon \\Qp^\\times \\to \\Z$ is a group homomorphism. Finally we see that $\\ord (x + y) \\geq \\min\\{\\ord x, \\ord y\\}$, with the equality holding when $\\ord x \\neq \\ord y$. These properties tell us exactly that $\\ord$ is a discrete valuation on the field $\\Qp$, and that $\\Zp$ is the ring of valuation of $\\left(\\Qp, \\ord\\right)$ because $x \\in \\Zp$ if and only if $\\ord x \\geq 0$ and $\\ord 1/x = - \\ord x$.\n\t\t\n\t\tWe recall that\n\t\t\\[\n\t\t\\Z_{(p)} = \\Set{\\frac{a}{b} | a,b \\in \\Z, p \\nmid b, b \\neq 0}.\n\t\t\\] \n\t\tThe relations between $\\Zp$ and $\\Qp$ are similar to the ones between $\\Z_{(p)}$ and $\\Q$. In-fact we have\n\t\t\\begin{equation*}\n\t\t\t\\Q = \\bigcup_{m \\geq 0} p^{-m}\\Z_{(p)} \\text{, } \\qquad  \\Q^\\times = \\coprod_{p \\in \\Z}p^m\\Z_{(p)}^\\times\n\t\t\\end{equation*}\n\t\twhere $\\Z_{(p)}^\\times$ consists of all the fractions with both numerator and denominator prime to $p$.\n\t\t\n\t\tWe can see that the definition of $\\Qp$ introduced here represents exactly the same object described in chapter 1. So we can introduce the \\padic absolute value, and its induced metric, in the exact same way and all properties proved before will be valid. So $\\Qp$ is a metric field equipped with a discrete valuation, which implies that $\\Qp$ is a topological field (i.e. a topological ring where the inverse map $\\Qp^\\times \\to \\Qp^\\times: x \\mapsto x^{-1}$ is continuous).\n\t\t\\begin{prop}\n\t\t\tThe field $\\Qp$ is a locally compact field of characteristic $0$ which induces on $\\Zp$ the \\padic topology. It can be identified with the completion of $\\Zp[1/p]$ or of $\\Q$, for the \\padic metric.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tWe have already observed that $\\Zp = B_{\\leq 1}(0) = \\{x \\in \\Qp \\mid \\pabs{x} \\leq 1\\}$ and, for every $k \\geq 0$ the ideal $p^k\\Zp$ is exactly $B_{\\leq p^{-k}}(0)$. Since $\\Zp$ is a compact neighbourhood of $0$, the topological field $\\Qp$ is locally compact ($x + \\Zp$ is a compact neighbourhood of $x$). From \\cref{corollary:locally_compact_group} we obtain that $\\Qp$ is complete. We now show that $\\Z[1/p]$ is dense in $\\Qp$; given\n\t\t\t\\begin{gather*}\n\t\t\t\tx = \\sum_{i \\geq v}^{+\\infty} x_ip^i \\qquad (v = \\ord x \\in \\Z)\n\t\t\t\\end{gather*}\n\t\t\twe immediately find that the sequence of truncated sums $x_n = \\sum_{v \\leq i < n} x_ip^i$ is a Cauchy sequence in $\\Z[1/p] \\subset \\Q$ which converges to $x$. Finally, we have already seen that $\\Qp$ is a field of characteristic $0$, since we have an immersion $\\Z \\hookrightarrow \\Qp$.\n\t\t\\end{proof}\n\t\tHere we have proved that $\\Qp$ is a complete field, a fact we already knew, in a very different way than before, by just using algebraic properties of topological groups.\n\t\t\n\t\tGiven a non-zero element $\\Qp \\ni x = \\sum_{i \\geq m}x_ip^i$ we can define\n\t\t\\begin{gather*}\n\t\t\t[x] := \\sum_{i \\geq 0}x_ip^i \\in \\Zp \\text{ : \\emph{integral part} of $x$ }; \\\\\n\t\t\t\\langle x \\rangle := \\sum_{i < 0} x_ip^i \\in \\Z[1/p] = \\{ap^v \\mid a,v \\in \\Z \\} \\subset \\Q \\text{ : \\emph{fractional part} of $x$}.\n\t\t\\end{gather*}\n\t\tHence we obtain the decomposition $\\Qp = \\Zp + \\Z[1/p]$, which is not canonical, because it depends on the choice of the representatives of $\\Z/p\\Z$ chosen for digits (here we have always chosen to use $\\mathcal{S} = \\{0, 1, \\dots, p-1\\}$). This sum is not a direct sum since $\\Zp \\cap \\Z[1/p] = \\Z$, so there's not a unique factorization of any $x \\in \\Qp$. If we consider the map $\\Z \\to \\Zp \\oplus \\Z[1/p]: m \\mapsto (m, -m)$ and the addition homomorphism $\\Zp \\oplus \\Z[1/p] \\to \\Zp + \\Z[1/p] = \\Qp: (a, b) \\mapsto a+b$ we obtain the short exact sequence:\n\t\t\\begin{equation*}\n\t\t\t\\Z \\hookrightarrow \\Zp \\oplus \\Z[1/p] \\twoheadrightarrow \\Qp\n\t\t\\end{equation*}\n\t\twhere the image of the first map is exactly the kernel of the second one.\n\t\\section{Hensel's Lemma}\n\t\tIn this section we present the important Hensel's lemma, a principle which gives us a method to find roots of polynomials in $\\Zp[X]$. \n\t\t\\begin{prop}\n\t\t\tLet $P(X) \\in \\Zp[X]$. The following properties are equivalent:\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item $P=0$ admits a solution in $\\Zp$;\n\t\t\t\t\\item for each $n \\geq 0$, $P=0$ admits a solution in $\\Z/p^n\\Z$.\n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tThe part \\textit{(i)} $\\implies$ \\textit{(ii)} is trivial: if $x = \\sum_{i \\geq 0} a_ip^i \\in \\Zp$ is a root of $P$ then $x_n = \\sum_{i < n}a_ip^i$ is in $\\Z/p^n\\Z$ and $P(x_n) = P(x) \\mod p^n$.\\\\\n\t\t\tTo prove the converse, let's consider the non-empty finite sets\n\t\t\t\\[\n\t\t\t\tX_n = \\{x \\in \\Z/p^n\\Z \\mid P(x) = 0 \\mod p^n \\}.\n\t\t\t\\]\n\t\t\tIt's immediate that if $x \\in X_{n+1}$ then $\\tilde{x} = x \\mod p^n$ is in $X_n$, because $P(\\tilde{x}) = P(x) \\mod p^n$. So reduction mod $p^n$ furnishes a map $\\phi_n\\colon X_{n+1} \\to X_n$. We can consider the projective system $(X_n, \\phi_n)_{n \\in \\N}$: it admits a projective limit $X = \\lim\\limits_{\\longleftarrow} X_n \\subset \\Zp$. It's now clear that if $x \\in X$ then $P(x) = 0$ in $\\Zp$. Since the projective limit of non-empty sets is not empty (it immediately follows from the fact that projective limit of non-empty compact space is non-empty, \\cite[30]{robert:padic-analysis}), we can conclude.\n\t\t\\end{proof}\n\t\tWe recall the elementary fact that if $A$ is a commutative ring and $P \\in A[X]$ then\n\t\t\\[\n\t\t\tP(X + h) = P(X) + h \\cdot P'(X) + h^2 \\cdot Q(X, h)\n\t\t\\]\n\t\twhere $Q$ is a polynomial in $A[X, Y]$ (we'll refer to this as the Taylor expansion of $P$, for obvious reasons). We're now ready to prove this proposition. For brevity, we'll write $v(\\zeta) := \\ord \\zeta$, for $\\zeta \\in \\Qp$.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:newton-algorithm}\n\t\t\tLet $P \\in \\Zp[X]$ and $x \\in \\Zp$ be such that $P(x) \\equiv 0 \\mod p^n$. If $k = v(P'(x)) < n/2$, then $\\widehat{x} := x - P(x)/P'(x)$ satisfies\n\t\t\t\\begin{enumerate}[label=(\\roman*)]\n\t\t\t\t\\item $P(\\widehat{x}) \\equiv 0 \\mod p^{n+1}$;\n\t\t\t\t\\item $\\widehat{x} \\equiv x \\mod p^{n-k}$;\n\t\t\t\t\\item $v(P'(\\widehat{x})) = v(P'(x))$.\n\t\t\t\\end{enumerate}\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tLet's write $P(x) = p^ny$ for $y \\in \\Zp$ and $P'(x) = p^ku$ with $u \\in \\Zp^\\times$. Then \n\t\t\t\\[\n\t\t\t\t\\widehat{x} - x = -\\frac{P(x)}{P'(x)} = - p^{n-k}yu^{-1} \\in p^{n-k}\\Zp\n\t\t\t\\]\n\t\t\twhich proves \\textit{(ii)}. To prove \\textit{(i)} we observe\n\t\t\t\\[\n\t\t\t\tP(\\widehat{x}) = P(x + (\\widehat{x} - x)) = P(x) -\\frac{P(x)}{P'(x)} P'(x) + (\\widehat{x} - x)^2 \\cdot t \n\t\t\t\\]\n\t\t\twhere $t \\in \\Zp$. Then\n\t\t\t\\[\n\t\t\t\tP(\\widehat{x}) = p^{2(n-k)}y^2u^{-2}t^2 \\in p^{n+1}\\Zp \\subseteq p^{2(n -k)}\\Zp\n\t\t\t\\]\n\t\t\tsince $n - k > n/2$. Now it only remains to compute the order of $P'(\\widehat{x})$. Let's use Taylor expansion:\n\t\t\t\\[\n\t\t\t\tP'(\\widehat{x}) = P'(x) + (\\widehat{x} - x)\\cdot s = p^ku + p^{n-k}zs = p^k(u + p^{n-2k}zs) = p^kw \\quad (z, s \\in \\Zp).\n\t\t\t\\]\n\t\t\tSince $n - 2k > 0$ and $u$ is a unit of $\\Zp$, we get\n\t\t\t\\[\n\t\t\t\tw = u + p^{n-2k}zs \\in u + p^{n-2k}\\Zp \\subset \\Zp^\\times\n\t\t\t\\]\n\t\t\twhich proves $v(P'(\\widehat{x})) = k$.\n\t\t\\end{proof}\n\t\tWe can finally prove the Hensel's Lemma.\n\t\t\\begin{thm}[Hensel's Lemma]\n\t\t\t\\label{thm:hensel-lemma}\n\t\t\tLet $P$ be a polynomial in $\\Zp[X]$ and $x \\in \\Zp$ such that $P(x) \\equiv 0 \\mod p^n$. If $k = v(P'(x)) < n/2$ then there exists a unique root $\\xi$ of $P$ in $\\Zp$ such that $\\xi \\equiv x \\mod p^{n-k}$ and $v(P'(\\xi)) = v(P'(x))$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tLet's first prove the existence of such $\\xi$. Let $x_0 = x$; we want to find $x_1 \\in \\Zp$ such that\n\t\t\t\\[\n\t\t\t\tx_1 \\equiv x_0 \\mod p^{n-k}, \\quad  P(x_1) \\equiv 0 \\mod p^{n+1}, \\quad v(P'(x_1)) = k.\n\t\t\t\\]\n\t\t\tBy \\cref{prop:newton-algorithm} we can build such an $x_1$, which represents an ``improved'' root of $P$. Similarly, we can find $x_2 \\in \\Zp$ such that\n\t\t\t\\[\n\t\t\t\tx_2 \\equiv x_1 \\mod p^{n-k+1}, \\quad P(x_2) \\equiv 0 \\mod p^{n+2}, \\quad v(P'(x_2)) = k.\n\t\t\t\\]\n\t\t\tIterating this process we get a coherent sequence $(x_m)_{m\\in \\N} \\subset \\Zp$: more specifically, letting $h = n-k$, we obtain\n\t\t\t\\begin{gather*}\n\t\t\t\tx_m \\equiv \\sum_{i=0}^{h+m} a_ip^i \\mod p^{h+m+1} \\text{, } \\quad  P(x_m) \\equiv 0 \\mod p^{n+m} \\\\\n\t\t\t\tx_{m+1} \\equiv \\sum_{i=0}^{h+m} a_ip^i + a_{h+m+1}p^{h+m+1} \\mod p^{h+m+2} \\text{, } \\quad P(x_{m+1}) \\equiv 0 \\mod p^{n+m+1} \\\\\n\t\t\t\\end{gather*}\n\t\t\tso it's clear that this sequence has \\padic limit $\\xi = \\sum_{i \\geq 0} a_ip^i$ satisfying $P(\\xi) = 0$ in $\\Zp$, $\\xi \\equiv x \\mod p^{n-k}$ and $v(P'(\\xi)) = k$. \\\\\n\t\t\tNow we prove uniqueness. Let $\\xi$ and $\\eta$ be two roots of $P$ in $\\Zp$ satisfying the above constraints. Then\n\t\t\t\\[\n\t\t\t\t0 = P(\\eta) = P(\\xi) + (\\eta - \\xi)P'(\\xi) + (\\eta - \\xi)^2a \\quad (a \\in \\Zp)\n\t\t\t\\]\n\t\t\tso, since $\\eta - \\xi \\in p^{n-k+1}\\Zp$, we have\n\t\t\t\\[\n\t\t\t\t0 = (\\eta - \\xi)(P'(\\xi) + (\\eta - \\xi)a).\n\t\t\t\\]\n\t\t\tClearly, since $v(P'(\\xi)) = k$ and $v((\\eta - \\xi)a) \\geq n-k+1 > k$, the term $(P'(\\xi) + (\\eta - \\xi)a)$ can't vanish so we must have $\\eta = \\xi$.\n\t\t\\end{proof}\n\t \tThe Hensel's Lemma is a very important tool in \\padic analysis, so we'll write again a weak version of it.\n\t \t\\begin{corollary}[Weak Hensel's Lemma]\n\t \t\tLet $P$ a polynomial in $\\Zp[X]$ and $a_0 \\in \\Zp$ such that $P(a_0) \\equiv 0 \\mod p$ and $P'(a_0) \\not\\equiv 0 \\mod p$. Then there is a unique $a \\in \\Zp$ such that $P(a) = 0$ and $a \\equiv a_0 \\mod p$.\n\t \t\\end{corollary}", "meta": {"hexsha": "cefb2c51287ef81c3ac57e833471bb727f7c2b11", "size": 38363, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mainmatter/chapter2.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/chapter2.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/chapter2.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": 81.2775423729, "max_line_length": 717, "alphanum_fraction": 0.6482808957, "num_tokens": 14304, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009480320036, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7899178024878898}}
{"text": "\\section{$\\mathbf{A} = \\mathbf{V\\Lambda V^{-1}}$ Spectral Theorems, Diagonalization}\n\\label{sec:diagonalization}\n\nSpectral theorems deal with diagonalizable linear operators. \n\\\\\n\nA diagonalization of a matrix $\\mathbf{A}$ is always possible when a matrix is square, and refers to a decomposition of the matrix into the matrix of eigenvectors $\\mathbf{V}$ and eigenvalues $\\mathbf{\\Lambda}$ as \n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{V\\Lambda V^{-1}} \n\\end{equation}\n\n\\subsection{$\\mathbf{A} = \\mathbf{V\\Lambda V}^T$ Eigendecomposition of Symmetric Matrices}\nA hermitian matrix $\\mathbf{A}$ has orthogonal eigenvectors, which means that $\\mathbf{V}$ is unitary, meaning that $\\mathbf{V}^{-1} = \\mathbf{V}^{\\dagger}$. In that case, the diagonalization is:\n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{V\\Lambda V}^{\\dagger} = \\left[\\begin{array}{cccc}\n\\vrule&\\vrule&\\hdots&\\vrule\\\\\nv_1&v_2&\\ddots&v_n\\\\\n\\vrule&\\vrule&\\hdots&\\vrule\n\\end{array}\\right]\\left[\\begin{array}{cccc}\n\\lambda_1&0&\\hdots&0\\\\ \n0&\\lambda_2&\\hdots&0\\\\\n\\vdots&\\vdots&\\ddots&\\vdots\\\\\n0&\\hdots&\\hdots&\\lambda_n\n\\end{array}\\right]\n\\left[\n\\begin{array}{ccc}\n\\rule[.5ex]{3.5em}{0.4pt}&v_1^{\\dagger}&\\rule[.5ex]{3.5em}{0.4pt}\\\\\n\\rule[.5ex]{3.5em}{0.4pt}&v_2^{\\dagger}&\\rule[.5ex]{3.5em}{0.4pt}\\\\\n\\vdots&\\ddots&\\vdots\\\\\n\\rule[.5ex]{3.5em}{0.4pt}&v_n^{\\dagger}&\\rule[.5ex]{3.5em}{0.4pt}\\\\\n\\end{array}\n\\right]\n\\end{equation}\n\nWhich is the same as saying that all hermitian matrices are \\textit{similar} to a diagonal matrix (cf. section \\ref{sec:similiarity}, two matrices $\\mathbf{A}$ and $\\mathbf{B}$ are similar if they are transmutable using unitary transformations as $\\mathbf{A} = \\mathbf{UBU^{\\dagger}}$). The diagonal representation also shows that in order for $\\mathbf{A}$ to satisfy the hermitian property $\\mathbf{A}^{\\dagger}=\\mathbf{A}$ its eigenvalues $\\lambda_i$ must be real. Further, it means that if $\\mathbf{A}$ is hermitian, $\\mathbf{A}$ can be written in terms of projections on the eigenvectors:\n\n\\begin{equation}\n\\mathbf{A} = \\sum_i \\lambda_i (v_i \\otimes v_i)\n\\end{equation}\n\nWhere $\\otimes$ is the (complex) outer product $v_i\\otimes v_i = v_i v_i^{\\dagger}$. I have seen the existence of this representation of a hermitian matrix be described as synonmous with \\textit{spectral theorem}. Since the eigenvectors $\\mathbf{V}$ are an orthonormal basis, $\\sum_i v_i \\otimes v_i = \\mathbb{I}$.\n\n\n\\subsection{$\\mathbf{H} = \\mathbf{U\\Lambda U}^T$ Eigendecomposition of Hermitian Matrices}\n\nSimilarly, a hermitian matrix $\\mathbf{H} \\in \\mathbb{C}^{n\\times n}$ (the complex equivalent to a symmetric matrix) has real eigenvalues and the matrix of eigenvectors is unitary, so that $\\mathbf{H} = \\mathbf{U\\Lambda U}^T$.\n\n\n\\subsection{Eigenvalue Sensitivity and Accuracy}\n\n\\subsubsection{General Case}\n\nIn general, the values of the eigenvalues of a square matrix $\\mathbf{A}$ may vary wildly under a slight cange of $\\mathbf{A} \\rightarrow \\mathbf{A}+\\delta\\mathbf{A}$. The sensitivity of the eigenvalues to a change in $\\mathbf{A}$ can be investigated using matrix norms \\cite{mathworkseig}. Let $||\\cdot||$ denote a submultiplicative matrix norm, then:\n\n\\begin{equation}\n\\begin{array}{rl}\n\\Lambda + \\delta\\Lambda &= \\mathbf{X^{-1}}\\left( \\mathbf{A} + \\delta\\mathbf{A} \\right)\\mathbf{X} \\\\\n\\delta\\Lambda &= \\mathbf{X^{-1}} \\delta \\mathbf{A} \\mathbf{X}\\\\\n||\\delta\\Lambda || &= ||\\mathbf{X^{-1}} \\delta \\mathbf{A} \\mathbf{X} || \\leq  ||\\mathbf{X^{-1}}|| ||\\mathbf{X}|| ||\\delta\\mathbf{A}||\n\\end{array}\n\\end{equation}\n\nWhen $||\\cdot||$ is chosen to be the operator norm with respect to $L^2$, $||\\cdot||_{(2)}||$, then $||\\mathbf{X^{-1}}|| = \\sigma_1$ and $||\\mathbf{X}|| = \\frac{1}{\\sigma_n}$ where $\\sigma_1$ and $\\sigma_2$ are the square roots of the largest and the smallest eigenvalue of $\\mathbf{X^{\\dagger}}\\mathbf{X}$ respectively (cf. section \\ref{sec:norms} on matrix norms). In that case, the sensitivity of the eigenvalues to a change in $\\mathbf{A}$ is:\n\n\\begin{equation}\n||\\delta\\mathbf{\\Lambda}||_{(2)} \\leq \\frac{\\sigma_1}{\\sigma_n} ||\\delta\\mathbf{A}||_{(2)} = \\kappa(\\mathbf{X})||\\delta\\mathbf{A}||_{(2)}\n\\end{equation}\n\nWhere $\\kappa(\\mathbf{X})$ is the conditioning number of the matrix $\\mathbf{X}$. Upper bounds on the error on individual eigenvalues can also be derived quite easily, which is shown in \\ref{mathworkseig} pp 10-12.\n\n\\subsubsection{Hermitian Matrices}\nFor hermitian (or orthogonal) matrices, the conditioning number for the individual eigenvalues  $\\kappa(\\lambda_i,\\mathbf{H}) = 1$, so that the error on an individual eigenvalue $||\\lambda_i||_{(2)} \\leq \\kappa(\\lambda_i,\\mathbf{H}) ||\\mathbf{H}||_{(2)} = 1\\times ||\\mathbf{H}||_{(2)}$. ", "meta": {"hexsha": "9f43f643711c256770b4d8be8deb981483b3e716", "size": 4644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_spectral.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/linalg_spectral.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/linalg_spectral.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": 62.7567567568, "max_line_length": 592, "alphanum_fraction": 0.7026270457, "num_tokens": 1642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857379, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7899035532841826}}
{"text": "\\section{Natural Smoothing Splines}\nNatural splines add the constrain that the function must be linear after\nthe knots at the end points. This forces 2 more restrictions since\n$f''$ must be 0 at the end points, i.e the space has $k + 4 - 2$\nparameters because of \nthis extra 2 constrains. \n\nSo where do we put the knots? How many do we use? There are some\ndata-driven procedures for doing this. Natural Smoothing Splines\nprovide another approach.\n\nWhat happens if the knots coincide with the dependent variables\n$\\{X_i\\}$. Then there is a function $g \\in \\cal G$, the space of cubic\nsplines with knots at $(x_1,\\dots,x_n)$, with\n$g(x_i) = y_i, i,\\dots,n$, i.e. we haven't smoothed at all.\n\nConsider the following problem: among all functions \n$g$ with two  continuous first two derivatives, find one that minimizes\nthe penalized residual sum of squares\n\\[\n\\sum_{i=1}^n \\{ y_i - g(x_i) \\}^2 + \\lambda \\int_a^b \\{g''(t)\\}^2 \\,\ndt\n\\]\nwhere $\\lambda$ is a fixed constant, and $a \\leq x_1 \\leq \\dots \\leq\nx_n \\leq b$. It can be shown (Reinsch 1967) that the solution to this\nproblem is a \nnatural cubic spline with knots at the values of $x_i$ (so there are\n$n-2$ interior knots and $n-1$ intervals). Here $a$ and\n$b$ are arbitrary as long as they contain the data.\n\nIt seems that this procedure is over-parameterized since a\nnatural cubic spline as this one will have $n$ degrees of\nfreedom. However we will see that the penalty makes this go down.\n\n\\subsection{Computational Aspects}\nWe use the fact that the solution is a natural cubic spline and write\nthe possible answers as\n\\[\ng(x) = \\sum_{j=1}^{n} \\theta_j B_j(x)\n\\]\nwhere $\\theta_j$ are the coefficients and $B_j(x)$ are the basis\nfunctions. Notice that if these were cubic splines the functions lie\nin a $n+2$ dimensional space, but the natural splines are an $n$\ndimensional subspace. \n\nLet $\\bB$ be the $n \\times n$ matrix defined by\n\\[\nB_{ij} = B_j(x_i)\n\\]\nand a penalty matrix $\\bg{\\Omega}$ by\n\\[\n\\Omega_{ij} = \\int_a^b B_i''(t)B_j''(t) \\, dt\n\\]\nnow we can write the penalized criterion as\n\\[\n(\\by - \\bB\\bg{\\theta})'(\\by - \\bB\\bg{\\theta}) +\n\\lambda\\bg{\\theta}'\\bg{\\Omega}\\bg{\\theta}\n\\]\nIt seems there are no boundary derivatives constraints but they are\nimplicitly imposed by the penalty term.\n\nSetting derivatives with respect to $\\bg{\\theta}$ equal to 0 gives\nthe estimating equation:\n\\[\n(\\bB'\\bB + \\lambda\\bg{\\Omega})\\bg{\\theta} = \\bB'\\by.\n\\]\nThe $\\hat{\\bg{\\theta}}$ that solves this equation will give us the\nestimate $\\hat{\\g} = \\bB \\hat{\\bg{\\theta}}$.\n\nIs this a linear smoother?\n\nWrite:\n\\[\n\\hat{\\g} = \\bB \\bg{\\theta} = \\bB(\\bB'\\bB + \\lambda \\bg{\\Omega})^{-1}\n\\bB'\\by =  ({\\mathbf I} + \\lambda {\\mathbf K})^{-1}\\by\n\\]\nwhere ${\\mathbf K} = \\bB -1 ' \\bg{\\Omega} \\bB^{-1}$. Notice we can\nwrite the criterion as\n\\[\n(\\by - \\g)'(\\by - \\g) + \\lambda \\g' {\\mathbf K} \\g\n\\]\n\nIf we look at the ``kernel'' of this linear smoother we will see that\nit is similar to the other smoothers presented in this class.\n\n\\begin{figure}[h] \n\\centerline{\\epsfig{figure=Plots/plot-04-02.ps,width=.8\\textwidth}}\n\\caption{Smoothing spline fitted using different penalties.}\n\\end{figure}\n\n\n", "meta": {"hexsha": "da7bd24706061b64c3081246b7d9611f1259f8ad", "size": 3126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-04-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-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-04.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 33.9782608696, "max_line_length": 72, "alphanum_fraction": 0.6992962252, "num_tokens": 979, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785201, "lm_q2_score": 0.907312213841788, "lm_q1q2_score": 0.7899035227791447}}
{"text": "% !TeX root = main.tex\n\n\\chapter{Fast Fourier Transform}\n\\glsresetall\n\\label{chapter:fft}\n\nPerforming the \\gls{dft} directly using matrix-vector multiply requires $\\mathcal{O}(n^2)$ multiply and add operations, for an input signal with $n$ samples.  It is possible to reduce the complexity by exploiting the structure of the constant coefficients in the matrix.  This $S$ matrix encodes the coefficients of the \\gls{dft}; each row of this matrix corresponds to a fixed number of rotations around the complex unit circle (please refer to Chapter \\ref{sec:DFTbackground} for more detailed information). These values have a significant amount of redundancy, and that can be exploited to reduce the complexity of the algorithm. \n\n\\begin{aside}\nThe 'Big O' notation used here describes the general order of complexity of an algorithm based on the size of the input data.  For a complete description of Big O notation and its use in analyzing algorithms, see \\cite{CLR}.\n\\end{aside}\n\nThe \\gls{fft} uses a divide-and-conquer approach based on the symmetry of the $S$ matrix.  The \\gls{fft} was made popular by the Cooley-Tukey algorithm \\cite{cooley65}, which requires $\\mathcal{O}(n \\log n)$ operations to compute the same function as the \\gls{dft}.  This can provide a substantial speedup, especially when performing the Fourier transform on large signals. %Other optimizations are also possible based on the fact that each element of the $S$ matrix has magnitude '1'.  We will mention some of these optimizations, but generally focus on the architectural tradeoffs in implementing the \\gls{fft}.\n\n\\begin{aside}\nThe divide-and-conquer approach to computing the \\gls{dft} was initially developed by Karl Friedrich Gauss in the early 19th century. However, since Gauss' work on this was not published during his lifetime and only appeared in a collected works after his death, it was relegated to obscurity.  Heideman et al.~\\cite{heideman84} provide a nice background on the history of the \\gls{fft}.\n\\end{aside}\n\nThe focus of this chapter is to provide the reader with a good understanding of the \\gls{fft} algorithm since that is an important part of creating an optimized hardware design. Thus, we start by giving a mathematical treatment of the \\gls{fft}. This discussion focuses on small \\gls{fft} sizes to give some basic intuition on the core ideas. After that, we focus on different hardware implementation strategies.\n\n\\section{Background}\n\nThe \\gls{fft} brings about a reduction in complexity by taking advantage of symmetries in the \\gls{dft} calculation. To better understand how to do this, let us look at \\gls{dft} with a small number of points, starting with the 2 point \\gls{dft}.  Recall that the \\gls{dft} performs a matrix vector multiplication, i.e., $G[] = S[][] \\cdot g[]$, where $g[]$ is the input data, $G[]$ is the frequency domain output data, and $S[][]$ are the \\gls{dft} coefficients. We follow the same notation for the coefficient matrix, and the input and output vectors as described in Chapter \\ref{sec:DFTbackground}.\n\nFor a 2 point \\gls{dft}, the values of $S$ are:\n\\begin{equation}\nS =\n \\begin{bmatrix}\n  W^{0 0}_2 & W^{0 1}_2  \\\\\n  W^{1 0}_2 & W^{1 1}_2 \\\\\n \\end{bmatrix}\n \\end{equation}\nHere we use the notation $W = e^{-j 2 \\pi}$. The superscript on $W$ denotes values that are added to the numerator and the subscript on the $W$ indicates those values added in the denominator of the complex exponential. For example, $W^{2 3}_4 = e^{\\frac{-j 2 \\pi \\cdot 2 \\cdot 3}{4}}$. This is similar to the $s$ value used in the \\gls{dft} discussion (Chapter \\ref{sec:DFTbackground}) where $s = e^{\\frac{-j 2 \\pi}{N}}$. The relationship between $s$ and $W$ is $s = W_N$.\n\n\\begin{aside}\nThe $e^{-j 2 \\pi}$ or $W$ terms are often called \\term{twiddle factors}. This term has its origin in the 1966 paper by Gentleman and Sande \\cite{gentleman1966fast}.\n\\end{aside}\n\n\\begin{equation}\n\\begin{bmatrix} \nG[0] \\\\ \nG[1] \\\\\n\\end{bmatrix} = \n \\begin{bmatrix}\n  W^{0 0}_2 & W^{0 1}_2  \\\\\n  W^{1 0}_2 & W^{1 1}_2 \\\\\n \\end{bmatrix}\n \\cdot\n  \\begin{bmatrix}\n  g[0] \\\\\n  g[1]\\\\\n\\end{bmatrix}\n\\end{equation}\n\nExpanding the two equations for a 2 point \\gls{dft} gives us:\n\\begin{equation}\n\\begin{array} {lll} \nG[0] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 0}{2}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 1}{2}} \\\\\n & = & g[0] + g[1] \\\\\n\\end{array}\n\\label{eq:2ptlower}\n\\end{equation} due to the fact that since  $e^{0}  =  1$. The second frequency term\n\\begin{equation}\n\\begin{array} {lll} \nG[1] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 0}{2}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 1}{2}} \\\\\n & = & g[0] - g[1] \\\\\n\\end{array}\n\\label{eq:2pthigher}\n\\end{equation} since  $e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 1}{2}}  = e^{-j \\pi } = -1$.\n\nFigure \\ref{fig:2pointFFT} provides two different representations for this computation.  Part a) is the data flow graph for the 2 point \\gls{dft}. It is the familiar view that we have used to represent computation throughout this book. Part b) shows a butterfly structure for the same computation. This is a typical structure used in digital signal processing, in particular, to represent the computations in an \\gls{fft}. \n\nThe butterfly structure is a more compact representation that is useful to represent large data flow graphs. When two lines come together this indicates an addition operation. Any label on the line itself indicates a multiplication of that label by the value on that line. There are two labels in this figure. The `$-$' sign on the bottom horizontal line indicates that this value should be negated. This followed by the addition denoted by the two lines intersecting is the same as subtraction. The second label is $W^0_2$. While this is a multiplication is unnecessary (since $W^0_2 = 1$ this means it is multiplying by the value `$1$'), we show it here since it is a common structure that appears in higher point \\gls{fft}s.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width= 0.8 \\textwidth]{images/2pointFFT}\n\\caption{Part a) is a data flow graph for a 2 point \\gls{dft}/\\gls{fft}. Part b) shows the same computation, but viewed as a butterfly structure. This is a common representation for the computation of an \\gls{fft} in the digital signal processing domain.}\n\\label{fig:2pointFFT}\n\\end{figure}\n\nNow let us consider a slightly larger \\gls{dft} -- a 4 point \\gls{dft}, i.e., one that has 4 inputs, 4 outputs, and a $4 \\times 4$ $S$ matrix. The values of $S$ for a 4 point \\gls{dft} are:\n\\begin{equation}\nS =\n \\begin{bmatrix}\n  W^{0 0}_4 & W^{0 1}_4 & W^{0 2}_4 & W^{0 3}_4 \\\\\n  W^{1 0}_4 & W^{1 1}_4 & W^{1 2}_4 & W^{1 3}_4 \\\\\n  W^{2 0}_4 & W^{2 1}_4 & W^{2 2}_4 & W^{2 3}_4 \\\\\n  W^{3 0}_4 & W^{3 1}_4 & W^{3 2}_4 & W^{3 3}_4 \\\\\n \\end{bmatrix}\n \\end{equation}\nAnd the \\gls{dft} equation to compute the frequency output terms are:\n\\begin{equation}\n\\begin{bmatrix} \nG[0] \\\\\nG[1] \\\\\nG[2] \\\\\nG[3] \\\\\n\\end{bmatrix} = \n \\begin{bmatrix}\n  W^{0 0}_4 & W^{0 1}_4 & W^{0 2}_4 & W^{0 3}_4 \\\\\n  W^{1 0}_4 & W^{1 1}_4 & W^{1 2}_4 & W^{1 3}_4 \\\\\n  W^{2 0}_4 & W^{2 1}_4 & W^{2 2}_4 & W^{2 3}_4 \\\\\n  W^{3 0}_4 & W^{3 1}_4 & W^{3 2}_4 & W^{3 3}_4 \\\\\n \\end{bmatrix}\n \\cdot\n  \\begin{bmatrix}\n  g[0] \\\\\n  g[1]\\\\\n  g[2]\\\\\n  g[3]\\\\\n\\end{bmatrix}\n\\end{equation}\n\n\nNow we write out the equations for each of the frequency domain values in $G[]$ one-by-one. The equation for G[0] is:\n\\begin{equation}\n\\begin{array} {lll} \nG[0] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 0}{4}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 1}{4}} + g[2] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 2}{4}} + g[3] \\cdot e^{\\frac{-j 2 \\pi \\cdot 0 \\cdot 3}{4}}\\\\\n & = & g[0] + g[1] + g[2] + g[3] \\\\\n\\end{array}\n\\end{equation} since $e^0 = 1$. \n\nThe equation for $G[1]$ is:\n\\begin{equation}\n\\begin{array} {lll} \nG[1] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 0}{4}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 1}{4}} + g[2] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 2}{4}} + g[3] \\cdot e^{\\frac{-j 2 \\pi \\cdot 1 \\cdot 3}{4}}\\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j 2 \\pi}{4}} + g[2] \\cdot e^{\\frac{-j 4 \\pi}{4}} + g[3] \\cdot e^{\\frac{-j 6 \\pi}{4}}\\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j 2 \\pi}{4}} + g[2] \\cdot e^{-j \\pi}   + g[3] \\cdot e^{\\frac{-j 2 \\pi}{4}} e^{-j \\pi} \\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j 2 \\pi}{4}} - g[2] - g[3] \\cdot e^{\\frac{-j 2 \\pi}{4}}\\\\\n\\end{array} \n\\end{equation} The reductions were done based upon the fact that $e^{-j \\pi} = -1$. \n\nThe equation for $G[2]$ is:\n\\begin{equation}\n\\begin{array} {lll} \nG[2] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 2 \\cdot 0}{4}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 2 \\cdot 1}{4}} + g[2] \\cdot e^{\\frac{-j 2 \\pi \\cdot 2 \\cdot 2}{4}} + g[3] \\cdot e^{\\frac{-j 2 \\pi \\cdot 2 \\cdot 3}{4}}\\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j 4 \\pi}{4}} + g[2] \\cdot e^{\\frac{-j 8 \\pi}{4}} + g[3] \\cdot e^{\\frac{-j 12 \\pi}{4}}\\\\\n & = & g[0] - g[1]  + g[2] -  g[3] \\\\\n\\end{array} \n\\end{equation} The reductions were done by simplifications based upon rotations. E.g., $e^{\\frac{-j 8 \\pi}{4}} = 1$ and $e^{\\frac{-12 j \\pi}{4}} = -1$ since in both cases use the fact that $e^{-j 2\\pi}$ is equal to $1$. In other words, any complex exponential with a rotation by $2 \\pi$ is equal.\n\nFinally, the equation for $G[3]$ is:\n\\begin{equation}\n\\begin{array} {lll} \nG[3] & = & g[0] \\cdot e^{\\frac{-j 2 \\pi \\cdot 3 \\cdot 0}{4}} + g[1] \\cdot e^{\\frac{-j 2 \\pi \\cdot 3 \\cdot 1}{4}} + g[2] \\cdot e^{\\frac{-j 2 \\pi \\cdot 3 \\cdot 2}{4}} + g[3] \\cdot e^{\\frac{-j 2 \\pi \\cdot 3 \\cdot 3}{4}}\\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j  6 \\pi}{4}} + g[2] \\cdot e^{\\frac{-j  12 \\pi}{4}} + g[3] \\cdot e^{\\frac{-j 18 \\pi}{4}}\\\\\n & = & g[0] + g[1] \\cdot e^{\\frac{-j 6  \\pi }{4}}  - g[2] +  g[3] \\cdot e^{\\frac{-j 10  \\pi}{4}}\\\\\n  & = & g[0] + g[1] \\cdot e^{\\frac{-j 6  \\pi }{4}}  - g[2] -  g[3] \\cdot e^{\\frac{-j 6  \\pi}{4}}\\\\\n\\end{array} \n\\end{equation} Most of the reductions that we have not seen yet deal with the last term. It starts out as $e^{\\frac{-j 18 \\pi}{4}}$. It is reduced to $e^{\\frac{-j 10 \\pi}{4}}$ since these are equivalent based upon a $2 \\pi$ rotation, or, equivalently, $e^{\\frac{-j 10 \\pi}{4}} \\cdot e^{\\frac{-j 8 \\pi}{4}}$ and the second term $e^{\\frac{-j 8 \\pi}{4}} = 1$. Finally, a rotation of $\\pi$, which is equal to $-1$, brings it to $e^{\\frac{-j 6  \\pi}{4}}$. Another way of viewing this is $e^{\\frac{-j 6 \\pi}{4}} \\cdot e^{\\frac{-j 4 \\pi}{4}}$ and $e^{\\frac{-j 4 \\pi}{4}} = -1$. We leave this term in this unreduced state in order to demonstrate symmetries in the following equations.\n\nWith a bit of reordering, we can view these four equations as:\n\\begin{equation}\n\\begin{array} {lll} \nG[0] & = & (g[0] + g[2]) + e^{\\frac{-j 2 \\pi 0}{4}} (g[1] + g[3])\\\\\nG[1] & = & (g[0] - g[2]) + e^{\\frac{-j 2 \\pi 1}{4}} (g[1] - g[3])\\\\\nG[2] & = & (g[0] + g[2]) + e^{\\frac{-j 2 \\pi 2}{4}} (g[1] + g[3])\\\\\nG[3] & = & (g[0] - g[2]) + e^{\\frac{-j 2 \\pi 3}{4}} (g[1] - g[3])\\\\\n\\end{array}\n\\end{equation}\n\nSeveral different symmetries are starting to emerge. First, the input data can be partitioned into even and odd elements, i.e., similar operations are done on the elements $g[0]$ and $g[2]$, and the same is true for the odd elements $g[1]$ and $g[3]$. Furthermore we can see that there are addition and subtraction symmetries on these even and odd elements. During the calculations of the output frequencies $G[0]$ and $G[2]$, the even and odd elements are summed together. The even and odd input elements are subtracted when calculating the frequencies $G[1]$ and $G[3]$.  Finally, the odd elements in every frequency term are multiplied by a constant complex exponential $W^i_4$ where $i$ denotes the index for the frequency output, i.e., $G[i]$. \n\nLooking at the terms in the parentheses, we see that they are 2 point \\gls{fft}. For example, consider the terms corresponding to the even input values $g[0]$ and $g[2]$. If we perform a 2 point \\gls{fft} on these even terms, the lower frequency (DC value) is $g[0] + g[2]$ (see Equation \\ref{eq:2ptlower}), and the higher frequency is calculated as $g[0] - g[2]$ (see Equation \\ref{eq:2pthigher}). The same is true for the odd input values $g[1]$ and $g[3]$. \n\nWe perform one more transformation on these equations.\n\\begin{equation}\n\\begin{array} {lll} \nG[0] & = & (g[0] + g[2]) + e^{\\frac{-j 2 \\pi 0}{4}} (g[1] + g[3])\\\\\nG[1] & = & (g[0] - g[2]) + e^{\\frac{-j 2 \\pi 1}{4}} (g[1] - g[3])\\\\\nG[2] & = & (g[0] + g[2]) - e^{\\frac{-j 2 \\pi 0}{4}} (g[1] + g[3])\\\\\nG[3] & = & (g[0] - g[2]) - e^{\\frac{-j 2 \\pi 1}{4}} (g[1] - g[3])\\\\\n\\end{array}\n\\label{eq:reduced4point}\n\\end{equation}\nThe twiddle factors in the last two equations are modified from $e^{\\frac{-j 2 \\pi 2}{4}} = -e^{\\frac{-j 2 \\pi 0}{4}}$ and $e^{\\frac{-j 2 \\pi 3}{4}} = -e^{\\frac{-j 2 \\pi 1}{4}}$. This allows for a reduction in the complexity of the multiplications since we can share multiplications across two terms. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .5 \\textwidth]{images/4ptFFT}\n\\caption{A four point \\gls{fft} divided into two stages. Stage 1 has uses two 2 point \\gls{fft}s -- one 2 point \\gls{fft} for the even input values and the other 2 point \\gls{fft} for the odd input values. Stage 2 performs the remaining operations to complete the \\gls{fft} computation as detailed in Equation \\ref{eq:reduced4point}. }\n\\label{fig:4ptFFT}\n\\end{figure}\n\nFigure \\ref{fig:4ptFFT} shows the butterfly diagram for the four point \\gls{fft}. We can see that the first stage is two 2 point \\gls{fft} operations performed on the even (top butterfly) and odd (bottom butterfly) input values. The output of the odd 2 point \\gls{fft}s are multiplied by the appropriate twiddle factor. We can use two twiddle factors for all four output terms by using the reduction shown in Equation \\ref{eq:reduced4point}.\n\nWe are seeing the beginning of trend that allows the a reduction in complexity from $\\mathcal{O}(n^2)$ operations for the \\gls{dft} to $\\mathcal{O}(n \\log n)$ operations for the \\gls{fft}. The key idea is building the computation through recursion. The 4 point \\gls{fft} uses two 2 point \\gls{fft}s. This extends to larger \\gls{fft} sizes. For example, an 8 point \\gls{fft} uses two 4 point \\gls{fft}s, which in turn each use two 2 point \\gls{fft}s (for a total of four 2 point \\gls{fft}s). An 16 point \\gls{fft} uses two 8 point \\gls{fft}s, and so on.\n\n\\begin{exercise}\nHow many 2 point \\gls{fft}s are used in a 32 point \\gls{fft}? How many are there in a 64 point \\gls{fft}? How many 4 point \\gls{fft}s are required for a 64 point \\gls{fft}? How about a 128 point \\gls{fft}?  What is the general formula for 2 point, 4 point, and 8 point \\gls{fft}s in an $N$ point \\gls{fft} (where $N > 8$)?\n\\end{exercise}\n\nNow let us formally derive the relationship, which provides a general way to describe the recursive structure of the \\gls{fft}.  Assume that we are calculating an $N$ point \\gls{fft}. The formula for calculating the frequency domain values $G[]$ given the input values $g[]$ is:\n\\begin{equation}\nG[k] = \\displaystyle\\sum\\limits_{n=0}^{N-1} g[n] \\cdot e^{\\frac{-j 2 \\pi k n}{N}} \\text{ for } k = 0,\\dots, N-1\n\\label{eq:fft-full}\n\\end{equation}\n\nWe can divide this equation into two parts, one that sums the even components and one that sums the odd components.\n\\begin{equation}\nG[k] = \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n] \\cdot e^{\\frac{-j 2 \\pi k (2n)}{N}} + \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n+1] \\cdot e^{\\frac{-j 2 \\pi k (2n+1)}{N}}\n\\label{eq:fft-split}\n\\end{equation}\nThe first part of this equation deals with the even inputs, hence the $2n$ terms in both $g[]$ and in the exponent of $e$. The second part corresponds to the odd inputs with $2n +1$ in both places. Also note that the sums now go to $N/2 -1$ in both cases which should make sense since we have divided them into two halves. \n\nWe transform Equation \\ref{eq:fft-split} to the following:\n\\begin{equation}\nG[k] = \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n] \\cdot e^{\\frac{-j 2 \\pi k n}{N/2}} + \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n+1] \\cdot e^{\\frac{-j 2 \\pi k (2n)}{N}} \\cdot e^{\\frac{-j 2 \\pi k}{N}}\n\\label{eq:fft-split-2}\n\\end{equation}\nIn the first summation (even inputs), we simply move the $2$ into the denominator so that it is now $N/2$. The second summation (odd inputs) uses the power rule to separate the $+1$ leaving two complex exponentials. We can further modify this equation to\n\\begin{equation}\nG[k] = \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n] \\cdot e^{\\frac{-j 2 \\pi k n}{N/2}} + e^{\\frac{-j 2 \\pi k}{N}} \\cdot \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n+1] \\cdot e^{\\frac{-j 2 \\pi k n}{N/2}} \n\\label{eq:fft-split-3}\n\\end{equation}\nHere we only modify the second summation. First we pull one of the complex exponentials outside of the summation since it does not depend upon $n$. And we also move the $2$ into the denominator as we did before in the first summation. Note that both summations now have the same complex exponential $e^{\\frac{-j 2 \\pi k n}{N/2}}$. Finally, we simplify this to \n\\begin{equation}\nG[k] = A_k + W_N^k B_k \n\\label{eq:fft-split-4}\n\\end{equation} where $A_k$ and $B_k$ are the first and second summations, respectively. And recall that $W = e^{-j 2 \\pi}$. This completely describes an N point \\gls{fft} by separating even and odd terms into two summations.\n\nFor reasons that will become clear soon, let us assume that we only want to use Equation \\ref{eq:fft-split-4} to calculate the first $N/2$ terms, i.e., $G[0]$ through $G[N/2 -1]$. And we will derive the remaining $N/2$ terms, i.e., those from $G[N/2]$ to $G[N-1]$ using a different equation. While this may seem counterintuitive or even foolish (why do more math than necessary?), you will see that this will allow us to take advantage of even more symmetry, and derive a pattern as we have seen in the 4 point \\gls{fft}.\n\nIn order to calculate the higher frequencies $G[N/2]$ to $G[N-1]$, let us derive the same equations but this time using $k = N/2, N/2 + 1, \\dots, N/2 -1$.  Thus, we wish to calculate\n\\begin{equation}\nG[k + N/2] = \\displaystyle\\sum\\limits_{n=0}^{N-1} g[n] \\cdot e^{\\frac{-j 2 \\pi (k + N/2) n}{N}} \\text{ for } k = 0, \\dots, N/2 - 1\n\\label{eq:fft-upper}\n\\end{equation}\nThis is similar to Equation \\ref{eq:fft-full} with different indices, i.e., we replace $k$ from Equation \\ref{eq:fft-full} with $k + N/2$. Using the same set of transformations that we did previously, we can move directly to the equivalent to Equation \\ref{eq:fft-split-3}, but replacing all instances of $k$ with $k + N/2$ which yields \n\\begin{equation}\nG[k + N/2] = \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n] \\cdot e^{\\frac{-j 2 \\pi (k + N/2) n}{N/2}} + e^{\\frac{-j 2 \\pi (k + N/2)}{N}} \\cdot \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n+1] \\cdot e^{\\frac{-j 2 \\pi (k + N/2) n}{N/2}} \n\\label{eq:fft-split-3-upper}\n\\end{equation}\n\nWe can reduce the complex exponential in the summations as follows:\n\\begin{equation}\ne^{\\frac{-j 2 \\pi (k + N/2) n}{N/2}} = e^{\\frac{-j 2 \\pi k n}{N/2}} \\cdot e^{\\frac{-j 2 \\pi (N/2) n}{N/2}} = e^{\\frac{-j 2 \\pi k n}{N/2}} \\cdot e^{-j 2 \\pi n} = e^{\\frac{-j 2 \\pi k n}{N/2}} \\cdot 1\n\\label{eq:fft-split-4-upper}\n\\end{equation}\nThe first reduction uses the power rule to split the exponential. The second reduction cancels the term $N/2$ in the second exponential. The final reduction uses that fact that $n$ is a non-negative integer, and thus $e^{-j 2 \\pi n}$ will always be a rotation of multiple of $2 \\pi$. This means that this term is always equal to $1$. \n\nNow let us tackle the second complex exponential\n\\begin{equation}\ne^{\\frac{-j 2 \\pi (k + N/2)}{N}} = e^{\\frac{-j 2 \\pi k }{N}} \\cdot e^{\\frac{-j 2 \\pi N/2 }{N}} = e^{\\frac{-j 2 \\pi k }{N}} \\cdot e^{-j  \\pi} = - e^{\\frac{-j 2 \\pi k }{N}}\n\\label{eq:fft-split-5-upper}\n\\end{equation}\nThe first reduction splits the exponential using the power rule. The second reduction does some simplifications on the second exponential. We get the final term by realizing that $e^{-j \\pi} = -1$.\n\nBy substituting Equations \\ref{eq:fft-split-4-upper} and \\ref{eq:fft-split-5-upper} into Equation \\ref{eq:fft-split-3-upper}, we get\n\\begin{equation}\nG[k + N/2] = \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n] \\cdot e^{\\frac{-j 2 \\pi k n}{N/2}} - e^{\\frac{-j 2 \\pi k}{N}} \\cdot \\displaystyle\\sum\\limits_{n=0}^{N/2-1} g[2n+1] \\cdot e^{\\frac{-j 2 \\pi k n}{N/2}} \n\\label{eq:fft-split-6-upper}\n\\end{equation}\nNote the similarity to Equation \\ref{eq:fft-split-3}. We can put it in terms of Equation \\ref{eq:fft-split-4} as\n\\begin{equation}\nG[k + N/2] = A_k - W_N^k B_k \n\\label{eq:fft-split-7-upper}\n\\end{equation}\n\nWe can use Equations \\ref{eq:fft-split-4} and \\ref{eq:fft-split-7-upper} to create an $N$ point \\gls{fft} from two $N/2$ point \\gls{fft}s. Remember that $A_k$ corresponds to the even input values, and $B_k$ is a function of the odd input values. Equation \\ref{eq:fft-split-4} covers the first $N/2$ terms, and Equation \\ref{eq:fft-split-7-upper} corresponds to the higher $N/2$ frequencies. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  .8 \\textwidth]{images/NptFFT}\n\\caption{Building an $N$ point \\gls{fft} from two $N/2$ point \\gls{fft}s. The upper $N/2$ point \\gls{fft} is performed on the even inputs; the lower $N/2$ \\gls{fft} uses the odd inputs. }\n\\label{fig:NptFFT}\n\\end{figure}\n\nFigure \\ref{fig:NptFFT} shows an $N$ point \\gls{fft} derived from two $N/2$ point \\gls{fft}s. $A_k$ corresponds to the top $N/2$ \\gls{fft}, and $B_k$ is the bottom $N/2$ \\gls{fft}.  The output terms $G[0]$ through $G[N/2-1]$ are multiplied by $W_N^0$ while the output terms $G[N/2]$ through $G[N-1]$ are multiplied by $-W_N^0$. Note that the inputs $g[]$ are divided into even and odd elements feeding into the top and bottom $n/2$ point \\gls{fft}s, respectively.\n\nWe can use the general formula for creating the \\gls{fft} that was just derived to recursively create the $N/2$ point \\gls{fft}. That is, each of the $N/2$ point \\gls{fft}s can be implemented using two $N/4$ point \\gls{fft}s. And each $N/4$ point \\gls{fft} uses two $N/8$ point \\gls{fft}s, and so on until we reach the base case, a 2 point \\gls{fft}.\n\nFigure \\ref{fig:8ptFFT} shows an 8 point \\gls{fft} and highlights this recursive structure. The boxes with the dotted lines indicate different sizes of \\gls{fft}. The outermost box indicates an 8 point \\gls{fft}. This is composed by two 4 point \\gls{fft}s. Each of these 4 point \\gls{fft}s have two 2 point \\gls{fft}s for a total of four 2 point \\gls{fft}s. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=  \\textwidth]{images/8ptFFT}\n\\caption{An 8 point \\gls{fft} built recursively. There are two 4 point \\gls{fft}s, which each use two 2 point \\gls{fft}s. The inputs must be reordered to even and odd elements twice. This results in reordering based upon the bit reversal of the indices.}\n\\label{fig:8ptFFT}\n\\end{figure}\n\nAlso note that the inputs must be reordered before they are feed into the 8 point \\gls{fft}. This is due to the fact that the different $N/2$ point \\gls{fft}s take even and odd inputs. The upper four inputs correspond to even inputs and the lower four inputs have odd indices. However, they are reordered twice. If we separate the even and odd inputs once we have the even set $\\{g[0], g[2], g[4], g[6] \\}$ and the odd set $\\{g[1], g[3], g[5], g[7] \\}$. Now let us reorder the even set once again. In the even set $g[0]$ and $g[4]$ are the even elements, and $g[2]$ and $g[6]$ are the odd elements. Thus reordering it results in the set $\\{g[0], g[4], g[2], g[6] \\}$. The same can be done for the initial odd set yielding the reordered set $\\{g[1], g[5], g[3], g[7] \\}$. \n\nThe final reordering is done by swapping values whose indices are in bit reversed order. Table \\ref{table:bit_reverse} shows the indices and their three bit binary values. The table shows the eight indices for the 8 point \\gls{fft}, and the corresponding binary value for each of those indices in the second column. The third column is the bit reversed binary value of the second column. And the last column is the decimal number corresponding the reversed binary number. \n\n\\begin{table}[htbp]\n\\caption{The index, three bit binary value for that index, bit reversed binary value, and the resulting bit reversed index.}\n\\begin{center}\n\\begin{tabular}{|c|c|c|c|}\n\\hline\nIndex & Binary & Reversed & Reversed \\\\\n & & Binary & Index \\\\\n\\hline\n0 & 000 & 000 & 0 \\\\\n1 & 001 & 100 & 4 \\\\\n2 & 010 & 010 & 2 \\\\\n3 & 011 & 110 & 6 \\\\\n4 & 100 & 001 & 1 \\\\\n5 & 101 & 101 & 5 \\\\\n6 & 110 & 011 & 3 \\\\\n7 & 111 & 111 & 7 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\label{table:bit_reverse}\n\\end{table}\n\nLooking at the first row, the initial index $0$, has a binary value of $000$, which when reversed remains $000$. Thus this index does not need to be swapped. Looking at Figure \\ref{fig:8ptFFT} we see that this is true. $g[0]$ remains in the same location. In the second row, the index 1 has a binary value $001$. When reversed this is $100$ or $4$. Thus, the data that initially started at index 1, i.e., $g[1]$ should end up in the fourth location. And looking at index 4, we see the bit reversed value is $1$. Thus $g[1]$ and $g[4]$ are swapped.  \n\nThis bit reversal process works regardless of the input size of the \\gls{fft}, assuming that the \\gls{fft} is a power of two. \\gls{fft} are commonly a power of two since this allows them to be recursively implemented.\n\n\\begin{exercise}\nIn an 32 point \\gls{fft}, index 1 is swapped with which index? Which index is index 2 is swapped with?\n\\end{exercise}\n\nThis completes our mathematical treatment of the \\gls{fft}. There are plenty of more details about the \\gls{fft}, and how to optimize it. You may think that we spent too much time already discussing the finer details of the \\gls{fft}; this is a book on parallel programming for FPGAs and not on digital signal processing. This highlights an important part of creating an optimum hardware implementation -- the designer must have a good understanding of the algorithm under development. Without that, it is difficult to create a good implementation. The next section deals with how to create a good \\gls{fft} implementation. \n\n\\section{Baseline Implementation}\n\nIn the remainder of this chapter, we discuss different methods to implement the Cooley-Tukey \\gls{fft} \\cite{cooley65} algorithm using the \\VHLS tool. This is the same algorithm that we described in the previous section. We start with a common version of the code, and then describe how to restructure it to achieve a better hardware design. \n\nWhen performed sequentially, the $\\mathcal{O}(n \\log n)$ operations in the \\gls{fft} require $\\mathcal{O}(n \\log n)$ time steps.   Typically, a parallel implementation will perform some portion of the \\gls{fft} in parallel.  One common way of parallelizing the \\gls{fft} is to organize the computation into $\\log n$ stages, as shown in Figure \\ref{fig:fftstages}.  The operations in each stage are dependent on the operations of the previous stage, naturally leading to a pipelining across the tasks.  Such an architecture allows $\\log n$ \\glspl{fft} to be computed simultaneously with a task interval determined by the architecture of each stage.  We discuss task pipelining using the \\lstinline|dataflow| directive in Section \\ref{sec:fft_task_pipelining}.\n\nEach stage in the \\gls{fft} also contains significant parallelism, since each butterfly computation is independent of other butterfly computations in the same stage.  In the limit, performing $n/2$ butterfly computations every clock cycle with a Task Interval of 1 can allow the entire stage to be computed with a Task Interval of 1.  When combined with a dataflow architecture, all of the parallelism in the \\gls{fft} algorithm can be exploited.  Note, however that although such an architecture can be constructed, it is almost never used except for very small signals, since an entire new block of \\lstinline|SIZE| samples must be provided every clock cycle to keep the pipeline fully utilized.  For instance, a 1024-point \\gls{fft} of complex 32-bit floating point values, running at 250 MHz would require 1024 \\text{points}*(8 {bytes}/{point})*250*$10^9$ Hz = 1Terabyte/second of data into the FPGA.   In practice, a designer must match the computation architecture to the data rate required in a system.\n\n\\begin{exercise}\nAssuming a clock rate of 250 MHz and one sample received every clock cycle, approximately how many butterfly computations must be implemented to process every sample with a 1024-point \\gls{fft}?  What about for a 16384-point \\gls{fft}?\n\\end{exercise}\n\nIn the remainder of this section, we describe the optimization of an \\gls{fft} with the function prototype \\lstinline|void fft(DTYPE X_R[SIZE], DTYPE X_I[SIZE])| where \\lstinline|DTYPE| is a user customizable data type for the representation of the input data. This may be \\lstinline|int|, \\lstinline|float|, or a fixed point type. For example, \\lstinline|#define DTYPE int| defines \\lstinline|DTYPE| as an \\lstinline|int|. Note that we choose to implement the real and imaginary parts of the complex numbers in two separate arrays. The \\lstinline|X_R| array holds the real input values, and the \\lstinline|X_I| array holds the imaginary values. \\lstinline|X_R[i]| and \\lstinline|X_I[i]| hold the $i$th complex number in separate real and imaginary parts. \n\n\\begin{aside}\nThere is one change in the \\gls{fft} implementation that we describe in this section. Here we perform an \\gls{fft} on complex numbers. The previous section uses only real numbers. While this may seem like a major change, the core ideas stay the same. The only differences are that the data has two values (corresponding to the real and imaginary part of the complex number), and the operations (add, multiply, etc.) are complex operations. \n\\end{aside}\n\nThis function prototype forces an in-place implementation. That is, the output data is stored in the same array as the input data. This eliminates the need for additional arrays for the output data, which reduces the amount of memory that is required for the implementation. However, this may limit the performance due to the fact that we must read the input data and write the output data to the same arrays. Using separate arrays for the output data is reasonable if it can increase the performance. There is always a tradeoff between resource usage and performance; the same is true here. The best implementation depends upon the application requirements (e.g., high throughput, low power, size of FPGA, size of the \\gls{fft}, etc.).\n\n%\\section{Initial ``Software'' \\gls{fft} Implementation}\n\nWe start with code for an \\gls{fft} that would be typical for a software implementation. Figure \\ref{fig:fft_sw} shows a nested three \\lstinline|for| loop structure. The outer \\lstinline|for| loop, labeled \\lstinline|stage_loop| implements one stage of the \\gls{fft} during each iteration. There are $log_2(N)$ stages where $N$ is the number of input samples. The stages are clearly labeled in Figure \\ref{fig:8ptFFT}; this 8 point \\gls{fft} has $log_2(8) = 3$ stages. You can see that each stage performs the same amount of computation, or the same number of butterfly operations. In the 8 point \\gls{fft}, each stage has four butterfly operations. \n\n\\begin{figure}\n\\lstinputlisting[format=none,firstline=34]{examples/fft_sw.cpp}\n\\caption{ A common implementation for the \\gls{fft} using three nested \\lstinline|for| loops.  While this may work well running as software on a processor, it is far from optimal for a hardware implementation.}\n\\label{fig:fft_sw}\n\\end{figure}\n\n\\begin{exercise}\nFor an $N$ point \\gls{fft}, how many butterfly operations are there in each stage? How many total butterfly operations are there for the entire \\gls{fft}?\n\\end{exercise}\n\nThe second \\lstinline|for| loop, labeled \\lstinline|butterfly_loop|, performs all of the butterfly operations for the current stage. \\lstinline|butterfly_loop| has another nested \\lstinline|for| loop, labeled \\lstinline|dft_loop|. Each iteration of \\lstinline|dft_loop| performs one butterfly operation. Remember that we are dealing with complex numbers and must perform complex additions and multiplications. \n\nThe first line in \\lstinline|dft_loop| determines the offset of the butterfly. Note that the ``width'' of the butterfly operations changes depending upon the stage. Looking at Figure \\ref{fig:8ptFFT}, Stage 1 performs butterfly operations on adjacent elements, Stage 2 performs butterfly operations on elements with index differing by two, and Stage 3 performs butterfly operations on elements with index differing by four. This difference is computed and stored in the \\lstinline|i_lower| variable. Notice that this offset, stored in the variable \\lstinline|numBF|, is different in every stage. \n\nThe remaining operations in \\lstinline|dft_loop| perform multiplication by the twiddle factor and an addition or subtraction operation. The variables \\lstinline|temp_R| and \\lstinline|temp_I| hold the real and imaginary portions of the data after multiplication by the twiddle factor $W$. The variables \\lstinline|c| and \\lstinline|s| are the real and imaginary parts of $W$, which is calculated using the \\lstinline|sin()| and \\lstinline|cos()| builtin functions. We could also use the CORDIC, such as the one developed in Chapter \\ref{chapter:cordic}, to have more control over the implementation. Twiddle factors are also commonly precomputed and stored in on-chip memory for moderate array sizes.  Lastly, elements of the \\lstinline|X_R[]| and \\lstinline|X_I[]| arrays are updated with the result of the butterfly computation.\n\n\\lstinline|dft_loop| and \\lstinline|butterfly_loop| each execute a different number of times depending upon the stage. However the total number of times that the body of \\lstinline|dft_loop| is executed in one stage is constant. The number of iterations for the \\lstinline|butterfly for| loop depends upon the number of unique $W$ twiddle factors in that stage. Referring again to Figure \\ref{fig:8ptFFT}, we can see that Stage 1 uses only one twiddle factor, in this case $W_8^0$. Stage 2 uses two unique twiddle factors and Stage 3 uses four different $W$ values. Thus, \\lstinline|butterfly_loop| has only one iteration in Stage 1, 2 iterations in stage 2, and four iterations in stage 3. Similarly, the number of iterations of \\lstinline|dft_loop| changes. It iterates four times for an 8 point \\gls{fft} in Stage 1, two times in Stage 2, and only one time in stage 3. However in every stage, the body of \\lstinline|dft_loop| is executed the same number of times in total, executing a total of four butterfly operations for each stage an 8 point \\gls{fft}. \n\n\\begin{aside}\n\\VHLS performs significant static analysis on each synthesized function, including computing bounds on the number of times each loop can execute.  This information comes from many sources, including variable bitwidths, ranges, and \\lstinline|assert()| functions in the code. When combined with the loop II, \\VHLS can compute bounds on the latency or interval of the \\gls{fft} function.  In some cases (usually when loop bounds are variable or contain conditional constructs), the tool is unable to compute the latency or interval of the code and returns `'?'.  When synthesizing the code in Figure \\ref{fig:fft_sw}, \\VHLS may not be able to determine the number of times that \\lstinline|butterfly_loop| and \\lstinline|dft_loop| iterate because these loops have variable bounds.\n\nThe \\lstinline|tripcount| directive enables the user to specify to the \\VHLS tool more information about the number of times a loop is executed which can be used by the tool to analyze the performance of the design. It takes three optional arguments \\lstinline|min|, \\lstinline|max|, and \\lstinline|average|. In this code, we could add a directive to \\lstinline|dft_loop|. By applying this directive, the \\VHLS tool can calculate bounds on the latency and interval value for the loop and the overall design.  Note that since the \\VHLS tool uses the numbers that you provide, if you give the tool an incorrect tripcount then the reported task latency and task interval will be incorrect -- garbage in, garbage out.   \n\\end{aside}\n\n\\begin{exercise}\nWhat is the appropriate way to use the \\lstinline|trip count| directive for the \\gls{fft} in Figure \\ref{fig:fft_sw}? Should you set the \\lstinline|max|, \\lstinline|min|, and/or \\lstinline|average| arguments? Would you need to modify the tripcount arguments if the size of the \\gls{fft} changes?  \n\\end{exercise}\n\n\\section{Bit Reversal}\n\\label{sec:fft_bit_reversal}\n\nWe have not talked about the bit reverse function, which swaps the input data values so that we can perform an in-place \\gls{fft}. This means that the inputs values are mixed, and the result is that the output data is in the correct order. We discuss that function in some detail now.\n\nFigure \\ref{fig:fft_bit_reverse} shows one possible implementation of the bit reverse function. It divides the code into two functions. The first is the bit reversal function (\\lstinline|bit_reverse|), which reorders data in the given arrays so that each data is in located at a different index in the array. This function calls another function, \\lstinline|reverse_bits|, which takes an input integer and returns the bit reversed value of that input.\n\n\\begin{figure}\n\\lstinputlisting[lastline=33]{examples/fft_sw.cpp}\n\\caption{ The first stage in our \\gls{fft} implementation reorders the input data. This is done by swapping the value at index $i$ in the input array with the value at the bit reversed index corresponding to $i$. The function \\lstinline|reverse_bits| gives the bit reversed value corresponding to the \\lstinline|input| argument. And the function \\lstinline|bit_reverse| swaps the values in the input array. }\n\\label{fig:fft_bit_reverse}\n\\end{figure}\n\nLet us start with a brief overview of the \\lstinline|reverse_bits| function. The function goes bit by bit through the \\lstinline|input| variable and shifts it into the \\lstinline|rev| variable. The \\lstinline|for| loop body consists of a few bitwise operations that reorder the bits of the input. Although these operations are individually not terribly complex, the intention of this code is that the for loop is completely unrolled and \\VHLS can identify that the bits of the input can simply be wired to the output.  As a result, the implementation of the \\lstinline|reverse_bits| function should require no logic resources at all, but only wires.  This is a case where unrolling loops greatly simplifies the operations that must be performed.  Without unrolling the loop, the individual `or' operations must be performed sequentially.  Although this loop can be pipelined, the `or' operation would still be implemented in logic resources in the FPGA and executing the the loop would have a latency determined by the number of bits being reversed (\\lstinline|\\gls{fft}_BITS| in this case).\n\n\\begin{exercise}\nWhat is the latency of the \\lstinline|reverse_bits| function when no directives are applied? What is the latency when the loop is pipelined?  What is the latency when the whole function is pipelined?\n\\end{exercise}\n\n\\begin{aside}\nIt is tempting to ``blindly'' apply directives in order to achieve a better design. However, this can be counterproductive. The best designer has a deep understanding of both the application and the available optimizations and carefully considers these together to achieve the best results. \n\\end{aside}\n\nNow let us optimize the parent \\lstinline|bit_reverse| function. This function has a single \\lstinline{for} loop that iterates through each index of the input arrays. Note that there are two input arrays \\lstinline{X_R[]} and \\lstinline{X_I[]}. Since we are dealing with complex numbers, we must store both the real portion (in the array \\lstinline{X_R[]}), and the imaginary portion (in the array \\lstinline{X_I[]}). \\lstinline{X_R[i]} and \\lstinline{X_I[i]} holds the real and imaginary values of the i-th input.\nIn each iteration of the \\lstinline{for} loop, we find the index reversed value by calling the \\lstinline{reverse_bits} function. Then we swap both the real and imaginary values stored in the index \\lstinline{i} and the index returned by the function \\lstinline{reverse_bits}. Note that as we go through all \\lstinline{SIZE} indices, we will eventually hit the reversed index for every value. Thus, the code only swaps values the first time based on the condition \\lstinline{if(i < reversed)}.\n\n%To me this doesn't say much that this point...  it would be better to discuss this in a case where it really matters\n%We can optimize this function in a number of different ways. Since the \\lstinline{reverse_bits} function is small and efficient, it make sense to use the \\lstinline{inline} pragma. This essentially copies all of the code from within the \\lstinline{reverse_bits} function directly into the \\lstinline{bit_reverse} function. Thus there is no function call, and any overhead associated with it goes away. Furthermore, this allows the \\VHLS tool to optimize the code within the \\lstinline{reverse_bits} function along with the code in the \\lstinline{bit_reverse} function, which can lead to some additional efficiencies. That being said, it may be the case when the \\lstinline{inline} directive does not help. \n\n\\section{Task Pipelining}\n\\label{sec:fft_task_pipelining}\n\nDividing the \\gls{fft} algorithm into stages enables \\VHLS to generate an implementation where different stages of the algorithm are operating on different data sets. This optimization, called \\gls{taskpipelining} is enabled using the \\lstinline{dataflow} directive. This is a common hardware optimization, and thus is relevant across a range of applications.\n\n\\begin{figure}\n\\lstinputlisting[format=none,firstline=35]{examples/fft_stages.cpp}\n\\caption{Code implementing an 8 point \\gls{fft} divided into stages, each of which is implemented by a separate function. The \\lstinline{bit_reverse} function is the first stage. Each following stage performs implements butterfly operations. }\n\\label{fig:fft_stages_code}\n\\end{figure}\n\nWe can naturally divide the \\gls{fft} algorithm into $\\log_2(N+1)$ stages where $N$ is the number of points of the \\gls{fft}.  The first stage swaps each element in the input array with the element located at the bit reversed address in the array. After this bit reverse stage, we perform $\\log_2(N)$ stages of butterfly operations. Each of these butterfly stages has the same computational complexity.  Figure \\ref{fig:fft_stages_code} describes how to divide an 8 point \\gls{fft} into four separate tasks. The code has separate function call for each of the tasks: one call to \\lstinline{bit_reverse}, and three calls to \\lstinline{fft_stage}. Each stage has two input arrays and two output arrays: one for the real portion and one for the imaginary portion of the complex numbers. Assume that the \\lstinline{DTYPE} is defined elsewhere, e.g., as an \\lstinline{int}, \\lstinline{float} or a fixed point data type.\n\nRefactoring the \\gls{fft} code allows us to perform \\gls{taskpipelining}. Figure \\ref{fig:fftstages} gives an example of this. In this execution, rather than wait for the first task to complete all four function calls in the code before the second task can begin, the second task can start after the first task has only completed the first function \\lstinline{bit_reverse}. The first task continues to execute each stage in the pipeline in order, followed by the remaining tasks in order.  Once the pipeline is full, all four subfunctions are executing concurrently, but each one is operating on different input data. Similarly, there are four 8 point \\glspl{fft} being computed simultaneously, each one executing on a different component of the hardware. This shown in the middle portion of Figure \\ref{fig:fftstages}. Each of the vertical four stages represents one 8 point \\gls{fft}. And the horizontal denotes increasing time. Thus, once we start the fourth 8 point \\gls{fft}, we have four \\glspl{fft} running simultaneously.  Note that for this to work, each call to the \\lstinline{fft_stage} function must be implemented with independent hardware.  In addition, enough storage is required to contain the intermediate computations of each \\gls{fft} being computed simultaneously.\n\n\\begin{figure}\n\\centering\n%\\includegraphics[width=  \\textwidth]{images/fftstages}\n{\\scriptsize \\includesvg{fftstages}}\n\\includesvg{fft_dataflow_behavior}\n\\caption{ Dividing the \\gls{fft} into different stages allows for task pipelining across each of these stages. The figure shows an example with three \\gls{fft} stages (i.e., an 8 point \\gls{fft}). The figure shows four 8 point \\gls{fft} executing at the same time. }\n\\label{fig:fftstages}\n\\end{figure}\n\nThe \\lstinline|dataflow| directive can construct separate pipeline stages (often called \\glspl{process}) from both functions and loops. The code in Figure \\ref{fig:fft_stages_code} uses functions only, but we could achieve a similar result with four loops instead of four functions.  In fact, this result could be achieved by unrolling the outer \\lstinline|stage_loop| in the original code either explicitly or using \\lstinline|#pragma HLS unroll|.  Such a code structure has several advantages.  Firstly, it is closer to the structure of the original algorithmic code, reducing the amount of code changes which need to be made.   Secondly, the code is less verbose, making it somewhat easier to write.  Thirdly, the code is again parameterized, supporting different values of size with the same code.  Code with a loop is shown in Figure \\ref{fig:fft_stages_loop_code}.\n\n\\begin{figure}\n\\lstinputlisting[format=none,firstline=64]{examples/fft_stages_loop.cpp}\n\\caption{Code implementing an arbitrary-sized FFT using a loop. After the loop is unrolled, each function call in the unrolled loop becomes a dataflow process. }\n\\label{fig:fft_stages_loop_code}\n\\end{figure}\n\nThe \\lstinline{dataflow} directive and the \\lstinline{pipeline} directive both generate circuits capable of pipelined execution.  The key difference is in the granularity of the pipeline. The \\lstinline{pipeline} directive constructs an architecture that is efficiently pipelined at the cycle level and is characterized by the II of the pipeline.  Operators are statically scheduled and if the II is greater than one, then operations can be shared on the same operator.  The \\lstinline{dataflow} directive constructs an architecture that is efficiently pipelined for operations that take a (possibly unknown) number of clock cycles, such as the behavior of a loop operating on a block of data.  These coarse-grained operations are not statically scheduled and the behavior is controlled dynamically by the handshake of data through the pipeline.  In the case of the \\gls{fft}, each stage is an operation on a block of data (the whole array) which takes a large number of cycles.  Within each stage, loops execute individual operations on the data in a block.  Hence, this is a case where it often makes sense to use the \\lstinline|dataflow| directive at the toplevel to form a coarse-grained pipeline, combined with the \\lstinline|pipeline| directive within each loop to form fine-grained pipelines of the operations on each individual data element.\n\nThe \\lstinline{dataflow} directive must implement memories to pass data between different processes. In the case when \\VHLS can determine that processes access data in sequential order, it implements the memory using a FIFO. This requires that data is written into an array in the same order that it is read from the array.  If the is not the case, or if \\VHLS can not determine if this streaming condition is met, then the memory can be implemented using a ping-pong buffer instead.   The ping-pong buffer consists of two (or more) conceptual blocks of data, each the size of the original array. One of the blocks can be written by the source process while another block is read by the destination process. The term ``ping-pong'' comes from the fact that the reading and writing to each block of data alternates in every execution of the task. That is, the source process will write to one block and then switch to the other block before beginning the next task. The destination process reads from the block that the producer is not writing to. As a result, the source and destination processes can never writing and reading from the same block at the same time. \n\nA ping-pong buffer requires enough memory to store each communication array at least twice.   FIFOs can often be significantly smaller, although determining a minimal size for each fifo is often a difficult design problem.  Unlike a FIFO, however, the data in a ping-pong buffer can be written to and read from in any order. Thus, FIFOs are generally the best choice when the data is produced and consumed in sequential order and ping-pong buffers are a better choice when there is not such regular data access patterns.\n\nUsing the \\lstinline{dataflow} directive effectively still requires the behavior of each individual process to be optimized. Each individual process in the pipeline can still be optimized using techniques we have seen previously such as code restructuring, pipelining, and unrolling.  For example, we have already discussed some optimizations for the \\lstinline{bit_reverse} function in Section \\ref{sec:fft_bit_reversal}.  In general, it is important to optimize the individual tasks while considering overall toplevel performance goals. Many times it is best to start with small functions and understand how to optimize them in isolation. As a designer, it is often easier to comprehend what is going on in a small piece of code and hopefully determine the best optimizations quickly. After optimizing each individual function, then you can move up the hierarchy considering larger functions given particular implementations of low level functions, eventually reaching the toplevel function.\n\nHowever, the local optimizations must be considered in the overall scope of the goals. In particular for dataflow designs the achieved interval for the overall pipeline can never be smaller than the interval of each individual process. Looking again at Figure \\ref{fig:fft_stages_code}, assume that \\lstinline{bit_reverse} has an interval of 8 cycles, \\lstinline{fft_stage(1,...)} has an interval of 12 cycles, \\lstinline{fft_stage(2,...)} has an interval of 12 cycles, and \\lstinline{fft_stage(3,...)} has an interval of 14 cycles. When using \\lstinline{dataflow}, the overal task interval is 14, determined by the maximum of all of the tasks/functions. This means that you should be careful in balancing optimizations across different processes with the goal of creating a balanced pipeline where the interval of each process is approximately the same. In this example, improving the interval of the \\lstinline{bit_reverse} function cannot improve the overall interval of the \\lstinline|fft| function. In fact, it might be beneficial to increase the latency of the \\lstinline{bit_reverse} function, if it can be achieved with significantly fewer resources.\n\n\\section{Conclusion}\n\\label{sec:fft_conclusion}\n\nThe overall goal is to create the most optimal design, which is a function of your application needs. This may be to create the smallest implementation. Or the goal could be creating something that can perform the highest throughput implementation regardless of the size of the FPGA or the power/energy constraints. Or the latency of delivering the results may matter if the application has real-time constraints. All of the optimizations change these factors in different ways. \n\nIn general, there is no one algorithm on how to optimize your design. It is a complex function of the application, design constraints, and the inherent abilities of the designer himself. Yet, it is important that the designer have a deep understanding of the application itself, the design constraints, and the abilities of the synthesis tool. \n\nWe attempted to illustrate these bits of wisdom in this chapter. While the \\gls{fft} is a well studied algorithm, with a large number of known hardware implementation tricks, it still serves as a good exemplar for high-level synthesis. We certainly did not give all of the tricks for optimization. %e leave that as an exercise in Chapter \\ref{chapter:ofdm} where we task the designer to create an simple orthogonal frequency-division multiplexing receiver. The core of this an \\gls{fft}.  \nRegardless, we attempted to provide some insight into the key optimizations here, which we hope serve as a guide to how to optimize the \\gls{fft} using the \\VHLS tool.\n\nFirst and foremost, understand the algorithm. We spent a lot of time explaining the basics of the \\gls{fft}, and how it relates to the \\gls{dft}. We hope that the reader understands that this is the most important part of building optimal hardware. Certainly, the designer could translate C/MATLAB/Java/Python code into \\VHLS and get an working implementation. And that same designer could somewhat blindly apply directives to achieve better results. But that designer is not going to get anywhere close to optimal results without a deep understanding of the algorithm itself.\n\nSecond, we provide an introduction to  task level pipelining using the \\lstinline{dataflow} directive. This is a powerful optimization that is not possible through code restructuring. I.e., the designer must use this optimization to get such a design. Thus, it is important that the designer understand its power, drawbacks, and usage.\n\nAdditionally, we give build upon some of the optimizations from previous chapters, e.g., loop unrolling and pipelining. All of these are important to get an optimized \\gls{fft} hardware design. While we did not spend too much time on these optimizations, they are extremely important.\n\nFinally, we tried to impress on the reader that these optimizations cannot be done in isolation. Sometimes the optimizations are independent, and they can be done in isolation. For example, we can focus on one of the tasks (e.g., in the \\lstinline{bit_reverse} function as we did in Section \\ref{sec:fft_bit_reversal}). But many times different optimizations will effect another. For example, the \\lstinline{inline} directive will effect the way the pipelining of a function. And in particular, the way that we optimize tasks/functions can propagate itself up through the hierarchy of functions.  The takeaway is that it is extremely important that the designer understand the effects of the optimizations on the algorithm, both locally and globally.\n", "meta": {"hexsha": "ece9a5184ae2cea886fc6c76b31a1a8e7a77a3f3", "size": 54462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fft.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": "fft.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": "fft.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": 118.6535947712, "max_line_length": 1349, "alphanum_fraction": 0.7399471191, "num_tokens": 15488, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192067652954, "lm_q2_score": 0.8757869997529962, "lm_q1q2_score": 0.7898904033129984}}
{"text": "\\textbf{Modify the code to} \\verb+diffusion_eq1_FD.m+  \\textbf{with sparse matrices}\n\n\\vspace{0.3in}\n\nIn this problem we want to show the need to take advantage of some properties of matrices. In particular, the need to use the fact that in some problems the matrices involved have a majority of its entries being zero. This type of matrices are called sparse matrices. If we code using this fact, the computer will store the value and position of the nonzero entries instead of the whole matrix, resulting in a much short computation time, as we will show. The code generates the following solution to the diffusion differential equation (for the case of $N=100$ nodes).\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P2_surf1.eps}}\n\\caption{Solution of the diffusion equation, $N=100$.}\n\\end{figure}\n\nWe have measured the time used to calculate the solution for different number of nodes. In figure 2 we can see how using sparse matrices makes our code run faster and the bigger $N$ the bigger the difference between the two speeds. \n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P2_times.eps}}\n\\caption{Elapsed time for regular and sparse matrices.}\n\\end{figure}\n\nIn the next table we can see the measured times for both cases for different values for $N$ as well as the ratio between the two. As we could observe in figure 2, the ratio gets bigger as we increase the dimesion of the matrices, which proves the importance of taking advantage of sparse matrices specially for bigger systems.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|c|c|c}\n%\\hline\n%\\multicolumn{3}{|c|}{Datos}\\\\\nN  & Regular Matrices & Sparse Matrices & Ratio\\\\\n\\hline\n$100$ & $0.6716$ & $   0.3347$ & $   2.0064$\\\\\n$200$ & $3.0701$ & $    1.4052$ & $    2.1848$\\\\\n$300$ & $8.3650$ & $    3.4260$ & $    2.4416$\\\\\n$400$ & $18.4907$ & $    6.4504$ & $    2.8666$\\\\\n$500$ & $36.2399$ & $   11.1142$ & $    3.2607$\\\\\n$600$ & $62.5694$ & $   16.6995$ & $    3.7468$\\\\\n$700$ & $118.2346$ & $   24.1097$ & $    4.9040$\\\\\n$800$ & $  217.2509$ & $   34.0877$ & $    6.3733$\\\\\n\\end{tabular}\n\\caption{$L_2$ error norm of different methods.}\n\\end{table}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 2\nclear all; close all\nlegendfontsize=14;\naxisfontsize=14;\nlabelfontsize=16;\n%% Original code, non-sparse matrices.\ntime=zeros(8,1);\nfor j=1:8\n    tic\n    N = 100*j;\n    x = linspace(-1,1,N)';\n    dx = x(2)-x(1);\n\n    unos = ones(N-2,1);\n    D2 = ( diag(unos(1:end-1),-1)+diag(unos(1:end-1),1)-2*diag(unos,0) )/dx^2;\n    B = zeros(N-2,2);\n    B(1,1) = 1/dx^2; B(end,end) =1/dx^2;\n    % initial condition\n    u0 = sin(pi*x)+0.2*sin(5*pi*x);\n    % boundary conditions\n    g1 = @(t) .5*sin(50*t);\n    g2 = @(t) 0*t;\n\n    t = 0:0.001:.5;\n\n    [T,U] = ode45(@(t,u) D2*u+B*[g2(t);g1(t)], t, u0(2:end-1));\n%     for k = 2:length(t)\n%         plot(x,[0;U(k,:)';g1(t(k))],'*-')\n%         ylim([-1.5 1.5])\n%         shg\n%         drawnow\n%     end\n    time(j)=toc;\n    if N==100\n        figure\n        [T,X]= meshgrid(t,x(2:end-1));\n        surf(T,X,U','edgecolor','none')\n        xlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\n        ylabel('$y$','fontsize',labelfontsize,...\n            'interpreter','latex')\n        zlabel('$\\phi_V(x,y)$','fontsize',labelfontsize,...\n            'interpreter','latex')\n        set(gca,'fontsize',axisfontsize)\n        txt='Latex/FIGURES/P2_surf1';\n        saveas(gcf,txt,'epsc')\n    end\nend\n\n%% Modified code, sparse matrices.\nsparsetime=zeros(8,1);\nfor j=1:8\n    tic\n    N = 100*j;\n    x = linspace(-1,1,N)';\n    dx = x(2)-x(1);\n\n    unos = ones(N-2,1);\n    D2 = sparse(( diag(unos(1:end-1),-1)+diag(unos(1:end-1),1)-2*diag(unos,0) )/dx^2);\n    B = sparse(zeros(N-2,2));\n    B(1,1) = 1/dx^2; B(end,end) =1/dx^2;\n    % initial condition\n    u0 = sin(pi*x)+0.2*sin(5*pi*x);\n    % boundary conditions\n    g1 = @(t) .5*sin(50*t);\n    g2 = @(t) 0*t;\n\n    t = 0:0.001:.5;\n\n    [T,U] = ode45(@(t,u) D2*u+B*[g2(t);g1(t)], t, u0(2:end-1));\n%     for k = 2:length(t)\n%         plot(x,[0;U(k,:)';g1(t(k))],'*-')\n%         ylim([-1.5 1.5])\n%         shg\n%         drawnow\n%     end\n    sparsetime(j)=toc;\n    if N==100\n        figure\n        [T,X]= meshgrid(t,x(2:end-1));\n        surf(T,X,U','edgecolor','none')\n        txt='Latex/FIGURES/P2_surf2';\n        saveas(gcf,txt,'epsc')\n    end\nend\n%%\nfigure\nNj=100:100:800;\nplot(Nj,time,'r*',Nj,sparsetime,'b*')\nlegend('Non-Sparse','Sparse')\ngrid on\ntxt='Latex/FIGURES/P2_times';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}", "meta": {"hexsha": "dc91355caca2608ca188ac0e4b10cef27e52fc63", "size": 4566, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.8222222222, "max_line_length": 569, "alphanum_fraction": 0.6003066141, "num_tokens": 1610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8872045922259088, "lm_q1q2_score": 0.789873133595115}}
{"text": "\\section{Greatest Common Divisor}\n\n\\frame{\n{Part 2: Greatest Common Divisors}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-5}]\n}\n\n\\begin{frame}{Greatest Common Divisor (GCD)}\n\n  The \\structure{Greatest Common Divisor} of $a$ and $b$ ($gcd(a,b)$), is the largest $c$ so that $c|a \\land c|b$.\\bigskip\n\n  Examples:\n  \\begin{itemize}\n  \\item $gcd(10,12)$ = 2 \\hfill $2|10 \\land 2|12$\n  \\item $gcd(13,12)$ = 1 \\hfill 13 and 12 have no common factors, and $1|x, \\forall x$\n  \\item $gcd(17,17)$ = 17\n  \\item $gcd(0,n)$ = n \\hfill $\\forall n\\in\\mathbb{N}, n > 0, n|0$\n  \\end{itemize}\n\\end{frame}\n\n\n\\subsection{Computing the GCD}\n\\begin{frame}{Euclidean Algorithm}{The Remainder Lemma}\n\n  The GCD is easy to compute, by using the \\structure{Remainder Lemma}:\\bigskip\n\n  \\begin{equation*}\n    gcd(a,b) = gcd(b, \\text{remainder}(a,b)), \\text{ for } b\\neq 0\n  \\end{equation*}\\bigskip\n\n  \\begin{block}{Proof Idea}\n\n    \\begin{itemize}\n    \\item The division axiom states that: $a = qb + r, 0\\leq r < b$;\n    \\item $c = gcd(a,b) \\implies c|a \\land c|qb$;\n    \\item $r = a - qb$, and $c|a \\land c|qb \\implies c|(a + (-1)*qb)$\n    \\item So $c|r$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n\n\\begin{frame}{Euclidean Algorithm}{Calculating with the Remainder Lemma}\n\n  To calculate the GCD of $a$ and $b$, we repeatedly calculate the remainder\n  of $a$ and $b$, and replace $a$ with the remainder.\\bigskip\n\n  \\begin{center}\n    GCD(899, 493) -- a = 899, b = 493\n  \\end{center}\\bigskip\n\n  \\begin{itemize}\n  \\item $899 = 493 \\times 1 + 406$ \\hfill \\structure{division axiom}\n  \\item GCD(899, 493) = GCD(493, 406) \\hfill \\structure{remainder lemma}\n  \\item GCD(493, 406) = GCD(406, 87) \\hfill \\structure{$493 =\n    406\\times 1 + 87$}\n  \\item GCD(406,87) = GCD(87,58) \\hfill \\structure{$406 = 87\\times 4 + 58$}\n  \\item GCD(87,58) = GCD(58,29) = GCD(29,0) = \\alert{29}\n  \\end{itemize}\n\\end{frame}\n\n\\subsection{Proof of correctness}\n\n\\begin{frame}{Euclidean Algorithm}{State Machine}\n  Let's use a State Machine to prove the correctness of Euclidean Algorithm:\\bigskip\n\n  \\begin{itemize}\n  \\item \\structure{States::=} $\\mathbb{N}\\times \\mathbb{N}$\\hspace{2cm} (values of $a$ and $b$)\\bigskip\n  \\item \\structure{Start State::=} $(a,b)$ \\bigskip\n  \\item \\structure{State Transitions::=}\n    $(x,y) \\rightarrow (y,rem(x,y))$ if $y\\neq 0$ \\bigskip\n  \\item \\structure{End State::=} $y = 0$\n  \\end{itemize}\\bigskip\n\n  Remember that to prove correctness, we have to:\n  \\begin{itemize}\n    \\item Prove \\structure{partial correctness}\n    \\item Prove \\structure{termination}\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Proof of GCD}{Proof of Partial Correctness}\n\n  To prove partial correctness, we have to prove the \\structure{preserved invariant} $P((x,y)) ::= [gcd(x,y) = gcd(a,b)]$.\n\n  \\begin{proof}\n    We prove the preserved invariant $P((x,y))$ by induction:\n\n    \\begin{itemize}\n      \\item P(start) is trivial: $gcd(a,b) = gcd(a,b)$\n      \\item If $P((x,y))$ is true, then it is still true for any transition.\n      \\begin{itemize}\n        \\item There is only one transition: $(x,y) \\to (y,\\text{rem}(x,y))$\n        \\item The \\structure{Remainder Lemma} says that: gcd(y,y) = gcd(y,rem(x,y));\n      \\end{itemize}\n    \\end{itemize}\n    By these two items, we proved that $P()$ holds for any state in the machine.\n  \\end{proof}\n\\end{frame}\n\n\\begin{frame}{Proof of GCD}{Proof of Termination}\n  \\begin{itemize}\n    \\item The transition is $(x,y) \\to (y,\\text{rem}(x,y))$;\n    \\item By the division axiom, $0 \\leq \\text{ rem}(x,y) < y$;\n    \\item So $y$ becomes smaller after every transition;\n    \\item When $y = 0$, \\structure{the machine halts};\n  \\end{itemize}\\bigskip\n\n  By the way, when the machine stops, the state is $(x_e,0)$. Because the preserved invariant state that $gcd(a,b) = gcd(x,y)$, and $gcd(x,0) = x$, the final result of the algorithm is that $gcd(a,b) = x_e$.\n\\end{frame}\n\n\\begin{frame}{How fast is the GCD?}\n\n  Analysing the state machine, we can calculate how fast the GCD terminates:\\bigskip\n\n  \\begin{itemize}\n    \\item At each transition, x is replaced by y. There are two cases:\n      \\begin{enumerate}\n      \\item $y \\leq x/2$: so x is halved this step.\\medskip\n      \\item $y > x/2$: so rem$(x,y) = x - y$ and x will get\n        halved at the \\emph{next} step.\n      \\end{enumerate}\\bigskip\n    \\item So every two steps, x gets halved (or even smaller)\n    \\item This means that after $\\leq 2\\log_2x$ steps, the algorithm stops.\n  \\end{itemize}\\bigskip\n\n  So GCD$(a,b)$ is calculated after $2\\log_2a$ steps.\n\\end{frame}\n\n\n\\subsection{The Pulverizer}\n\\begin{frame}{GCD and Linear Combinations}\n\n  Remember that we showed that a divisor $c$ of $a$ and $b$ is also a divisor of $(sa+tb)$.\\bigskip\n\n  Note that $c$ is a divisor of itself too, so we can represent $c$ as $(sa+tb)$ for some $s$ and $t$.\\bigskip\n\n  The \\structure{Extended Euclid Algorithm} (also called \"The Pulverizer\") can calculate $s$ and $t$ so that gcd$(a,b) = sa + tb$.\\bigskip\n\n  It is useful to note also that the gcd$(a,b)$ divides {\\bf every linear combination} of $a$ and $b$.\n\\end{frame}\n\n\\begin{frame}{The Pulverizer Algorithm}\n\n    \\structure{Calculate} Euclid's algorithm as usual:\n    \\begin{itemize}\n    \\item GCD(x,y) = GCD(y,rem(x,y)\\hspace{2cm} {\\bf Start}: GCD(a,b)\n    \\end{itemize}\n\n    \\bigskip\n\n    As we calculate GCD, \\structure{keep track of} four coefficients: {\\bf c,d,e,f}\n    \\begin{itemize}\n    \\item $x = ca+db$ and $y = ea+fb$\n    \\item {\\bf at start:} $x = 1a + 0b$, $y = 0a+1b$\n    \\item {\\bf update:} $x_{\\text{next}} = y = ea + fb$\n    \\item $y_{\\text{next}} =\n      \\text{rem}(x,y) = x - qy =\n      ca+db-q(ea+fb)$\n    \\item $y_{\\text{next}} = (c-qe)a+(d-qf)b$\n    \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{The Pulverizer Algorithm}{Example}\n\n    {\\bf a = 899, b = 493}\\\\\n    \\hfill (remember: $e_1 = c_0-q_0e_0, f_1 = d_0 - q_0f_0$)\n\n    \\vfill\n\n    \\begin{tabular}{l|l|l|l|r|r|r|r}\n      a & b & q & rem(a,b) & c & d & e & f\\\\\n      \\hline\n      899 & 493 & 1 & 406 & 1 & 0 & 0 & 1\\\\\n      493 & 406 & 1 & 87 & 0 & 1 & 1 & -1\\\\\n      406 & 87 & 4 & 58 & 1 & -1 & -1 & 2\\\\\n      87 & 58 & 1 & 29 & -1 & 2 & 5 & -9\\\\\n      58 & 29 & 2 & 0 & 5 & -9 & -6 & 11\\\\\n      29 & 0 & - & - & -6 & 11 & - & -\\\\\n    \\end{tabular}\n\n    \\begin{center}\n      GCD(899,493) = 29 = $-6\\times 899 +11\\times 493$\n    \\end{center}\n\\end{frame}\n\n\\begin{frame}{The Pulverizer Algorithm}{Positive coefficients}\n\n  So the Pulverizer calculates one linear combination of $a$ and $b$ which is equal to the GCD:\n\n  \\begin{equation*}\n  \\text{GCD}(899, 493) = -6\\times 899 + 11\\times 493\n  \\end{equation*}\\bigskip\n\n  It is possible to obtain other linear combinations, by defining $s$ and $t$ as follows:\n\n  \\begin{equation*}\n    \\text{GCD}(899, 493) = (-6 + 493k)899 + (11 - 899k)493, \\text{ for any }k\n  \\end{equation*}\\bigskip\n\n  For example, if we set $k = 1$, we can find the following coefficients for $s$ and $t$:\n\n  \\begin{equation*}\n    \\text{GCD}(899, 493) = 487\\times 899 - 888\\times 493\n  \\end{equation*}\n\n\\end{frame}\n\n\\begin{frame}{The Pulverizer Algorithm}{Positive coefficients}\n\n  Remember the robot from last class? The position of the robot was $x = 5a - 3b$. For any $x$, we can use the pulverizer to find $a$ and $b$.\\bigskip\n\n  \\begin{itemize}\n    \\item Let's say that we want to find the path of the robot for $x = 8$\n    \\item gcd$(5,3) = 1 = 2\\times5 - 3\\times 3$, using the pulverizer.\n    \\item $8 = 8\\times 1 = 8\\times(2\\times 5 - 3\\times3) = (8\\times2)5 - (8\\times 3)3$\n    \\item Result: 16 moves forward, 24 moves back.\n  \\end{itemize}\\bigskip\n\n  This may not be the best solution for $x=8$, but it is an easy and fast algorithm to calculate a solution.\n\\end{frame}\n", "meta": {"hexsha": "b15751ab1a22aa03760a5e9e04c26468556c31f8", "size": 7702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week03/02_CommonDivisor.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/02_CommonDivisor.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/02_CommonDivisor.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": 34.6936936937, "max_line_length": 207, "alphanum_fraction": 0.6297065697, "num_tokens": 2791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8933094046341532, "lm_q1q2_score": 0.7897206126373364}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Sequences}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to sequences.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}\nThe sequence $a_n = 1/n^3$ has limit $L = 0$. Suppose $\\epsilon = 1/64$; find a threshold $N$ such that\n\\[ |a_n -L| < \\epsilon \\]\nis guaranteed to hold for all $n > N$ (take your value of $N$ as small as possible).\n\\[ N = \\answer{4}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nThe sequence $a_n = (2n^2 + (-1)^n)/n^2$ has limit $L = 2$. Suppose $\\epsilon = 1/100$; find a threshold $N$ such that\n\\[ |a_n -L| < \\epsilon \\]\nis guaranteed to hold for all $n > N$ (take your value of $N$ as small as possible).\n\\[ N = \\answer{10}. \\]\n\\end{exercise}\n\n\\begin{exercise}%[APEX0801SEQS09]\nDetermine the \\(n^\\text{th}\\) term of the given sequence. $a_1 = 4$, $a_2 = 7$, $a_3 = 10$, $a_4 = 13$, $a_5 = 16$, \\(\\ldots\\)\n\\[ a_n = \\answer{3n+1}. \\]\n\\end{exercise}\n\\begin{exercise}%[APEX0801SEQS09]\nDetermine the \\(n^\\text{th}\\) term of the given sequence. $a_1 = 3$, $a_2 = -5/2$, $a_3 = 7/4$, $a_4 = -9/8$, $a_5 = 11/16$, \\(\\ldots\\)\n\\[ a_n = \\answer{\\frac{(-1)^{n-1} (2n+1)}{2^{n-1}}}. \\]\n\\end{exercise}\n\n\\begin{exercise}%[APEX0801SEQS17]\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\left\\{(-1)^n\\frac{n}{n+1}\\right\\} \\]\nThe sequence \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} to $\\answer{N/A}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}%[APEX0801SEQS18]\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{4n^2-n+5}{3n^2+1} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{4/3}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}%[APEX0801SEQS19]\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{4^n}{5^n} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{0}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\left(1 - \\frac{3}{n} \\right)^{-n} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{e^3}$ (enter N/A if the sequence does not converge to a finite answer).\n\\begin{hint}\nTake the reciprocal and compare to your reference list of commonly-occurring limits.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\left(1 - \\frac{3}{n}\\right)^{-n^2} \\]\nThe sequence \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} to $\\answer{N/A}$ (enter N/A if the sequence does not converge to a finite answer).\n\\begin{hint}\nIf a sequence $b_n$ tends to $e^3$, what will the sequence $(b_n)^n$ do?\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{(1.1)^n}{n} \\]\nThe sequence \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} to $\\answer{N/A}$ (enter N/A if the sequence does not converge to a finite answer).\n\\begin{hint}\nWhat are the relative orders of growth of numerator versus denominator?\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{(0.9)^n}{n} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{0}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = n^{1000000} (0.9)^n \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{0}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{\\ln n}{n} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{0}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_n = \\frac{\\ln n}{n^{0.00001}} \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{0}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\n\\begin{exercise}\nLet $b_n$ be the sequence given by\n\\[ b_1 = 0 \\ \\text{ and } \\ b_{n+1} = \\frac{2 + b_n}{3} \\ \\text{ for } n \\geq 1 \\]\nconverges. Compute its limit.\n\\[ \\lim_{n \\rightarrow \\infty} b_n = \\answer{1}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_1 = 1 \\ \\text{ and } \\ a_{n+1} = a_n + \\frac{1}{a_n} \\ \\text{ for } n \\geq 1 \\]\nThe sequence \\wordChoice{\\choice{converges}\\choice[correct]{diverges}} to $\\answer{N/A}$ (enter N/A if the sequence does not converge to a finite answer).\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the sequence converges or diverges. If convergent, give the limit of the sequence. \n\\[ a_1 = 1 \\ \\text{ and } \\ a_{n+1} = a_n + \\frac{1}{4} (4 - a_n^2) \\ \\text{ for } n \\geq 1 \\]\nThe sequence \\wordChoice{\\choice[correct]{converges}\\choice{diverges}} to $\\answer{2}$ (enter N/A if the sequence does not converge to a finite answer).\n\n\\end{exercise}\n\n\\begin{exercise}\nLet $a_n$ be the sequence given by\n\\[ a_1 = \\frac{1}{4}, \\ \\text{ and }  \\ a_{n+1} = 2 a_n(1-a_n) \\ \\text{ for } n \\geq 1 \\]\nconverges. Compute its limit.\n\\[ \\lim_{n \\rightarrow \\infty} a_n = \\answer{\\frac{1}{2}}. \\]\n\\begin{hint}\nIf $a_n$ happens to be positive and less than $1/2$, then $2 (1-a_n) > 1$, so this forces $2 a_n(1-a_n) > a_n$ (meaning that the term after $a_n$ will be larger than $a_n$.\n\\begin{hint}\nThe function $2 x(1-x)$ is nonnegative on the interval $[0,1]$ and has a maximum value of $1/2$ attained at $x = 1/2$. This means that if $a_n$ is anything between $0$ and $1$, the next term of the sequence will always be between $0$ and $1/2$.\n\\end{hint}\n\\end{hint}\n\\end{exercise}\n\n\\section*{Sample Quiz Questions}\n\n\\begin{question}%%%%%[SeqConvSQRT01]\n\nFind the limit of the sequence\n\\[\\lim_{n \\rightarrow \\infty} \\sqrt{\\frac{2n-2}{2n^2-4n+3}}.\\] \\offline{Justify your response.}\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle 0\\)}\n\\choice{\\(\\displaystyle \\frac{1}{3}\\)}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle 1\\)}\n\\choice{\\(\\displaystyle 2\\)}\n\\choice{\\(\\displaystyle 3\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nBecause the square root function is continuous, you can pass the limit through it and compute\n\\[ \\sqrt{\\lim_{n \\rightarrow \\infty} \\frac{2n-2}{2n^2-4n+3}}. \\]\n\\begin{hint}\nReduce numerator and denominator to the dominant terms (in the regime $n \\rightarrow \\infty$).\n\\begin{hint}\n\\[\\begin{aligned}\n\\lim_{n \\rightarrow \\infty} \\sqrt{\\frac{2n-2}{2n^2-4n+3}} & = \\lim_{n \\rightarrow \\infty} \\sqrt{\\frac{2n^{-1}-2n^{-2}}{2-4n^{-1}+3n^{-2}}} \\\\\n & = \\sqrt{\\frac{\\lim_{n \\rightarrow \\infty} 2n^{-1}-2n^{-2}}{\\lim_{n \\rightarrow \\infty} 2-4n^{-1}+3n^{-2}}} \\\\\n & = \\sqrt{\\frac{0}{2}} = 0. \n\\end{aligned}\\]\n\\end{hint}\n\\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[SeqConvORDER19]\n\nDetermine whether the limit below exists. If it exists, find its value.\n\\[\\lim_{n \\rightarrow \\infty} \\frac{(-1)^{n+1}n^2 - 2^{-n-1}}{(-1)^{n}n^2 + 4^{-n}}.\\] \\offline{Justify your response.}\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle -1\\)}\n\\choice{\\(\\displaystyle 0\\)}\n\\choice{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle 2\\)}\n\\choice{\\(\\displaystyle 3\\)}\n\\choice{limit does not exist}\n\\end{multiplechoice}\n\\begin{feedback}\nComparing the orders of growth of the terms in the numerator, the first term dominates because \\(|-1|>|1/2|\\). \n\\begin{hint} Likewise the first term dominates in the denominator because  \\(|-1|>|1/4|\\). \\begin{hint} Neglecting non-dominant terms leads to the limit \\[\\lim_{n \\rightarrow \\infty} \\frac{(-1)^{n+1}n^2}{(-1)^{n}n^2}\\] which simply equals \\(-1\\). \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[SeqConvEXPN43]\n\nDetermine whether the limit below exists. If it exists, find its value.\n\\[\\lim_{n \\rightarrow \\infty} \\left(\\frac{4n - 3}{4n + 1}\\right)^{n}.\\] \\offline{Justify your response.}\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle 0\\)}\n\\choice{\\(\\displaystyle 1\\)}\n\\choice[correct]{\\(\\displaystyle e^{-1}\\)}\n\\choice{\\(\\displaystyle e\\)}\n\\choice{\\(\\displaystyle e^2\\)}\n\\choice{limit does not exist}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\frac{4n - 3}{4n + 1} = 1 - \\frac{4}{4n + 1} \\rightarrow 1\\]\nas \\(n \\rightarrow \\infty\\). \\begin{hint} Next, in light of the known limit \\((1+x/k)^{k} \\rightarrow e^x\\) as \\(k \\rightarrow \\infty\\), manipulate exponents to see that  \\[\\left(1 - \\frac{4}{4n + 1}\\right)^n = \\left( \\left(1 - \\frac{4}{4n + 1}\\right)^{4n + 1} \\right)^{ 1/4} \\left(1 - \\frac{4}{4n + 1}\\right)^{-1/4}. \\] \\begin{hint} As \\(n \\rightarrow \\infty\\), the first term on the right-hand side tends to \\(e^{-1}\\) and the second term tends to \\(1\\). Thus the original sequence tends to \\(e^{-1}\\) as well. \\end{hint} \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[SeqConvEXPN39]\n\nDetermine whether the limit below exists. If it exists, find its value.\n\\[\\lim_{n \\rightarrow \\infty} \\left(\\frac{n + 3}{2n - 2}\\right)^{n^2}.\\] \\offline{Justify your response.}\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice[correct]{\\(\\displaystyle 0\\)}\n\\choice{\\(\\displaystyle 1\\)}\n\\choice{\\(\\displaystyle e^{-1}\\)}\n\\choice{\\(\\displaystyle e\\)}\n\\choice{\\(\\displaystyle e^2\\)}\n\\choice{limit does not exist}\n\\end{multiplechoice}\n\\begin{feedback}\nFirst observe that \n\\[\\frac{n + 3}{2n - 2} = \\frac{1}{2} + \\frac{2}{n - 1} \\rightarrow \\frac{1}{2}\\]\nas \\(n \\rightarrow \\infty\\). \\begin{hint} Since the limit is positive and less than one, raising this expression to increasingly large powers generates a sequence which converges rapidly to zero. \\end{hint}\n\\end{feedback}\n\n\\end{question}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2016C.08]\n\nDetermine whether the sequence \\(\\displaystyle a_n = (-1)^{n-1} \\frac{n^2}{1 + n^2 + n^3}\\) converges or diverges. If it converges, find its limit.\n\\begin{multiplechoice}\n\\choice{divergent, \\(\\displaystyle \\lim_{n \\rightarrow \\infty} a_n = 0\\)}\n\\choice{convergent, \\(\\displaystyle \\lim_{n \\rightarrow \\infty} a_n = 1\\)}\n\\choice[correct]{convergent, \\(\\displaystyle \\lim_{n \\rightarrow \\infty} a_n = 0\\)}\n\\choice{convergent, \\(\\displaystyle \\lim_{n \\rightarrow \\infty} a_n = -1\\)}\n\\choice{divergent, \\(\\displaystyle \\lim_{n \\rightarrow \\infty} a_n = \\infty\\)}\n\\choice{divergent, limit doesn't exist}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "afc5a7b5d523f49904fca00101957ac0d89cf461", "size": 11434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "series/18sequencepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "series/18sequencepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "series/18sequencepractice.tex", "max_forks_repo_name": "ptgressman/math104", "max_forks_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.736, "max_line_length": 534, "alphanum_fraction": 0.6876858492, "num_tokens": 3835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8947894527758053, "lm_q1q2_score": 0.7895871588055441}}
{"text": "\\subsection{Types of Matrices}\r\n\\noindent\r\nBelow is a list of different types of matrices and their special properties.\r\n\\begin{enumerate}[label=]\r\n\t\\item A square matrix has the same number of rows as columns.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t2 & 7 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item Row vectors have one column. Column vectors have one row.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t1 & 3 & 0\r\n\t\t\t\\end{bmatrix} \\text{, } \\begin{bmatrix}\r\n\t\t\t1 \\\\\r\n\t\t\t3 \\\\\r\n\t\t\t0\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item Upper triangular matrices have all 0's below the main diagonal. Lower triangular matrices have all 0's above the main diagonal.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 7 \\\\\r\n\t\t\t\t0 & 2 & -1 \\\\\r\n\t\t\t\t0 & 0 & 9\r\n\t\t\t\\end{bmatrix} \\text{, } \\begin{bmatrix}\r\n\t\t\t\t1 & 0 & 0 \\\\\r\n\t\t\t\t0 & 2 & 0 \\\\\r\n\t\t\t\t2 & 7 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item Diagonal matrices are both upper and lower triangular. They only have non-zero entries on the main diagonal.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\begin{bmatrix}\r\n\t\t\t\t1 & 0 & 0 \\\\\r\n\t\t\t\t0 & 2 & 0 \\\\\r\n\t\t\t\t0 & 0 & 9\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item The identity matrix is one of the most common matrices. It is square, diagonal, and has all 1's on the main diagonal. It's the multiplicative identity for matrices.\r\n\t\t\\begin{equation*}\r\n\t\t\tI_3 = \\begin{bmatrix}\r\n\t\t\t\t1 & 0 & 0 \\\\\r\n\t\t\t\t0 & 1 & 0 \\\\\r\n\t\t\t\t0 & 0 & 1\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\t\\item The inverse matrix of $A$, $A^{-1}$, is such that\r\n\t\t\\begin{equation*}\r\n\t\t\tA^{-1}A = AA^{-1} = I\r\n\t\t\\end{equation*}\r\n\t\\item The transpose matrix of $A$, $A^T$, is where the rows and columns of $A$ are swapped.\r\n\t\t\\begin{equation*}\r\n\t\t\tA = \\begin{bmatrix}\r\n\t\t\t\t1 & 3 & 2 & -1 \\\\\r\n\t\t\t\t-5 & 7 & 3 & 0 \\\\\r\n\t\t\t\\end{bmatrix} \\implies A^T = \\begin{bmatrix}\r\n\t\t\t\t1 & -5 \\\\\r\n\t\t\t\t3 & 7 \\\\\r\n\t\t\t\t2 & 3 \\\\\r\n\t\t\t\t-1 & 0\r\n\t\t\t\\end{bmatrix}\r\n\t\t\\end{equation*}\r\n\\end{enumerate}", "meta": {"hexsha": "024f76b3a40257239c6f81e7097326b1c7b4f29d", "size": 1948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/matrices/typesOfMatrices.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/backgroundReview/matrices/typesOfMatrices.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/backgroundReview/matrices/typesOfMatrices.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.0746268657, "max_line_length": 172, "alphanum_fraction": 0.5749486653, "num_tokens": 754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.894789468206764, "lm_q1q2_score": 0.7895871558223387}}
{"text": "\\section{Mallow's $C_p$}\nMallow's  $\\mbox{C}_p$  is a technique for model\nselection in regression (Mallows 1973). The $\\mbox{C}_p$ statistic is\ndefined  as a criteria \nto assess fits when models with different numbers of parameters are being\ncompared. It is given by\n\\begin{equation}\n\\label{Cpdef}\n\\mbox{C}_p = \\frac{\\mbox{RSS}(p)}{\\sigma^2} - N + 2p\n\\end{equation}\nIf model(p) is correct then  $\\mbox{C}_p$ will tend to be close to or\nsmaller than $p$. Therefore a simple plot of $\\mbox{C}_p$ versus $p$ can be used\nto decide amongst models.\n\nIn the case of ordinary linear regression, Mallow's method is based on \nestimating the mean squared error (MSE) of \nthe estimator $\\hat{\\bg{\\beta}\\:}\\!_p = {(\\mathbf{X}_p'\\mathbf{X}_p)^{-1}\\mathbf{X}_p'\\mathbf{Y}}$,\n\\[\n\\E [\\hat{\\bg{\\beta}\\:}\\!_p - \\bg{\\beta}]^2\n\\]\nvia a quantity based on the residual sum of squares (RSS)\n\\begin{eqnarray*}\n\\mbox{RSS}(p) &=& \\sum_{n=1}^N (y_n\n-\\mathbf{x}_n\\hat{\\bg{\\beta}\\:}\\!_p)^2\\\\ \n&=& (\\mathbf{Y}-\\mathbf{X}_p\\hat{\\bg{\\beta}\\:}\\!_p)'(\\mathbf{Y}-\\mathbf{X}_p\\hat{\\bg{\\beta}\\:}\\!_p)\\\\\n&=& \\mathbf{Y}' ( \\mathbf{I}_N - \\mathbf{X}_p(\\mathbf{X}_p'\\mathbf{X}_p)^{-1}\\mathbf{X}_p') \\mathbf{Y}\n\\end{eqnarray*}\nHere $\\mathbf{I}_N$ is an $N\\times N$ identity matrix.\nBy using a result for quadratic forms, presented for example as\nTheorem 1.17 in Seber's book, page 13, namely\n\\[\n\\E[\\mathbf{Y'AY}] = \\E\\mathbf{[Y']A}\\E[\\mathbf{Y}] + \\tr[\\bg{\\Sigma}\n\\mathbf{A}] \n\\]\n$\\bg{\\Sigma}$ being the variance matrix of $\\mathbf{Y}$,\nwe find that  \n\\begin{eqnarray*}\n\\E [\\mbox{RSS}(p)] \n&=& \\E[\\mathbf{Y}' ( \\mathbf{I}_N - \\mathbf{X}_p(\\mathbf{X}_p'\\mathbf{X}_p)^{-1}\\mathbf{X}_p') \\mathbf{Y}]\\\\\n&=&\\E [\\hat{\\bg{\\beta}\\:}\\!_p - \\bg{\\beta}]^2 + \\tr\\left[\\mathbf{I}_N - \\mathbf{X}_p(\\mathbf{X}_p'\\mathbf{X}_p)^{-1}\\mathbf{X}_p'\\right]\\sigma^2 \\\\\n&=& \\E[ \\hat{\\bg{\\beta}\\:}\\!_p - \\bg{\\beta}]^2 + \\sigma^2\\left(N - \\tr\n\\left[{(\\mathbf{X}_p'\\mathbf{X}_p)(\\mathbf{X}_p'\\mathbf{X}_p)^{-1}}\\right]\\right)\\\\\n&=& \\E [\\hat{\\bg{\\beta}\\:}\\!_p - \\bg{\\beta}]^2 + \\sigma^2(N - p)\n\\end{eqnarray*}\nwhere $N$ is the number of observations and $p$ is the number of\nparameters. Notice that when the true model has $p$ parameters\n$\\E[\\mbox{C}_p] = p$.  \nThis shows why, if model(p) is correct, $\\mbox{C}_p$ will\ntend to be close to $p$. \n\nOne problem with the $\\mbox{C}_p$  criterion is that\nwe have to find an \nappropriate estimate of $\\sigma^2$ to use for all values of $p$. \n\n\\subsection{$C_p$ for smoothers}\nA more direct way of constructing an estimate of PSE is to correct the\nASR. It is easy to show that\n\\[\n\\E\\{\\mbox{ASR}(\\lambda)\\} = \\left\\{ 1 - n^{-1}\\tr(2\\bS_{\\lambda} -\n    \\bS_{\\lambda} \\bS_{\\lambda}') \\right\\} \\sigma^2 + n^{-1}\n    \\bv_{\\lambda}'\\bv_{\\lambda}\n\\]\nnotice that \n\\[\n\\mbox{PSE}(\\lambda) - \\E\\{\\mbox{ASR}(\\lambda)\\} = n^{-1}\n2\\tr(\\bS_{\\lambda}) \\sigma^2\n\\]\n\nThis means that if we knew $\\sigma^2$ we could find a ``corrected''\nASR\n\\[\n\\mbox{ASR}(\\lambda) + 2\\tr(\\bS_{\\lambda}) \\sigma^2\n\\]\nwith the right expected value. \n\nFor linear regression $\\tr(\\bS_{\\lambda})$ is the number of parameters\nso we could think of $2\\tr(\\bS_{\\lambda}) \\sigma^2$ as a penalty\nfor large number of parameters or for un-smooth estimates. \n\nHow do we obtain an estimate for $\\sigma^2$? If we had a $\\lambda^*$\nfor which the bias is 0, then the usual unbiased estimate is\n\\[\n\\frac{\\sum_{i=1}^n \\{y_i - f_{\\lambda^*}(x_i)\\}^2}{n -\n  \\tr(2\\bS_{\\lambda^*} -   \\bS_{\\lambda^*} \\bS_{\\lambda^*}')}\n\\]\nThe usual trick is to chose one a $\\lambda^*$ that does little\nsmoothing and consider the above estimate. Another estimate that has\nbeen proposed it the first order difference estimate\n\\[\n\\frac{1}{2(n-1)} \\sum_{i=1}^{n-1} (y_{i+1} - y_i)^2\n\\]\n\nOnce we have an estimate $\\hat{\\sigma}^2$ then we can define \n\\[\nC_p = \\mbox{ASR}(\\lambda) + n^{-1} 2\\tr(S_{\\lambda})\\hat{\\sigma}^2\n\\]\nNotice that the $p$ usually means number of parameters so it should be\n$C_{\\lambda}$. \n\n\nNotice this motivates a definition for degrees of freedoms.\n", "meta": {"hexsha": "4f3c37e68fc03dcdc78f24e07a8bf6e300e1e7b1", "size": 3962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-09-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-09-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-09-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": 38.8431372549, "max_line_length": 147, "alphanum_fraction": 0.646138314, "num_tokens": 1543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705732, "lm_q2_score": 0.894789461192692, "lm_q1q2_score": 0.7895871496329263}}
{"text": "\\lab{Principal Component Analysis and Latent Semantic Indexing}{PCA and LSI}\n\\objective{Understand the basics of principal component analysis and latent semantic indexing.}\n\\label{lab:pca}\n\n\\section*{Principal Component Analysis}\nUnderstanding the variance in complex data is one of the first tasks encountered in exploratory data analysis. For an example, consider the scatter plot  displaying the sepal and petal lengths of 100 different irises shown in Figure \\ref{fig:iris_1}.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{iris0.pdf}\n\\caption{Sepal Length vs. Petal Length for 100 iris flowers. Note the strong correlation of these variables.}\n\\label{fig:iris_1}\n\\end{figure}\nThere are three distinct types of iris flowers present: \\emph{setosa}, \\emph{versicolor}, and \\emph{virginica}.\nConsidering this data, we might ask how to best distinguish the different types of irises based on their given sepal and petal lengths.\nWe can answer this question by finding the characteristic that causes the greatest variance in the data.\n(Greater variance implies a greater ability to distinguish between data points. If the variance is very small, the data are clustered tightly together, and it is difficult to distinguish well.)\n\nUpon examination, we see that the petal length ranges between $3$ and $7$ cm, while the sepal length only ranges between $5$ and $8$ cm. We might be tempted to say that the most distinguishing aspect of irises is their petal length, but this is only considering the features of the data individually, and not collectively. The two features of the data are clearly correlated, and a more careful consideration would lead us to conclude that the most distinguishing aspect of irises is their overall size. Some irises are are much larger than others, while the sepal and petal lengths stay roughly in proportion.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{iris2.pdf}\n\\caption{The vectors indicate the two principal components, which are weighted by their contribution to the variance.}\n\\label{fig:iris_2}\n\\end{figure}\n\nPrincipal Component Analysis (PCA) is a multivariate statistical tool used to orthogonally change the basis of a set of observations from the basis of original features (which may be correlated) into a basis of uncorrelated (in fact, orthonormal) variables called the \\emph{principal components}. It is a direct application of the singular value decomposition (SVD) from linear algebra. More specifically, the first principal component will account for the greatest variance in the set of observations, the second principal component will be orthogonal to the first, accounting for the second greatest variance in the set of observations, etc. The first several principal components capture most of the variance in the observation set, and hence provide a great deal of information about the data. By projecting the observations onto the space spanned by the principal components, we can reduce the dimensionality of the data in a manner that preserves most of the variance.\n\nIn our iris example, the two principal components are shown in Figure \\ref{fig:iris_2}. The first principal component, corresponding intuitively to iris size, accounts for $96\\%$ of the variance in the data. The second, which accounts for only $4\\%$ of the variance, corresponds to the relative sepal and petal length of irises of the same size.\n\n\\subsection*{Computing the Principal Components}\nWe now explore how to use the SVD to compute the principal components of a dataset.\nThroughout this lab we will use the \\li{sklearn} iris data set, which can be obtained as follows:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> import sklearn.datasets as datasets\n>>> iris = datasets.load_iris()\n>>> X = iris.data\n\\end{lstlisting}\nWe represent the collection of observations as an $n \\times m$ matrix $X$, where each row of $X$ is an observation, and each column is a specific feature.\nLet $k = \\min(m,n)$.  We will use this later.\nIn the iris example, $X$ contains 150 observations, each consisting of 4 features (so $k = 4$), as shown below:\n\\begin{lstlisting}\n>>> X.shape\n(150L, 4L)\n>>> iris.feature_names\n['sepal length (cm)',\n 'sepal width (cm)',\n 'petal length (cm)',\n 'petal width (cm)']\n\\end{lstlisting}\n\nThe first step in PCA is to pre-process the data. In particular, we first translate the columns of $X$ to have mean 0.\nThe data may then be optionally scaled to remove discrepancies arising from different units of measure (i.e. centimeters vs meters), and we call the new matrix containing the centered and scaled data $Y$.\nIn this lab, we will not have any scaling issues, so we won't address this issue any further.\nThus we can pre-process our iris data simply as follows:\n\\begin{lstlisting}\n>>> Y = X - X.mean(axis=0)\n\\end{lstlisting}\n\nWe next compute the truncated SVD of our centered and scaled data,\n\\[Y = U\\Sigma V^{T}\\]\nwhere $U$ is $n \\times k$, $\\Sigma$ is a $k\\times k$ diagonal matrix containing the singular values of $Y$ in decreasing order along the diagonal, and $V$ is $m \\times k$. The columns of $V$ are the principal components (which form an orthonormal basis for the space spanned by the observations), and the corresponding singular values provide us information about how much variance is captured in each principal component. More specifically, let $\\sigma_{i}$ be the $i$-th non-zero singular value. Then the value\n\\[\\frac{\\sigma^2_{i}}{\\sum_{j=1}^{k} \\sigma^2_{j}}\\]\nis the percentage of the variance captured by the $i$-th principal component.\nWe compute the truncated SVD of the iris data and show the variance percentages for each component below:\n\\begin{lstlisting}\n>>> U,S,VT = la.svd(Y, full_matrices=False)\n>>> S**2/(S**2).sum() # variance percentages\narray([ 0.92461621,  0.05301557,  0.01718514,  0.00518309])\n\\end{lstlisting}\n\nIn general, we are only interested with the first several principal components. But just how many principal components should we keep? There are a number of ways to decide this. One is to only keep the first two principal components, as these enable us to project the data into $2$-dimensional space, which is easy to visualize. Another way is to only keep the set of principal components accounting for a certain percentage (say $80\\%$) of the variance. A third method is to examine the \\emph{scree plot} of the variance percentages for each principal component, as in Figure \\ref{fig:iris_scree}.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{iris_scree.pdf}\n\\caption{Scree plot of the percentage of variance for PCA on the iris dataset.}\n\\label{fig:iris_scree}\n\\end{figure}\nUpon examination of the iris scree plot, we see that there is a distinct change after the first principal component. This method is referred to as finding the ``elbow\" of the scree plot, and we keep all the principal components on the left of the elbow. In the case of the iris data, that is simply the first principal component, which accounts for $92\\%$ of the variance.\n\nOnce we have decided how many principal components to keep (say the first $l$), we can project the observations from the original feature space onto the principal component space by computing\n\\begin{equation*}\n\\widehat{Y} = U_{:,:l}\\Sigma_{:l,:l}\n\\end{equation*}\nwhere $\\Sigma_{:l,:l}$ is the first $l$ rows and columns of $\\Sigma$ and $U_{:,:l}$ is the first $l$ columns of $U$.\nUsing the SVD formula, note that\n\\[\n\\widehat{Y} = YV_{:,:l},\n\\]\nwhere $V_{:,:l}$ is the first $l$ columns of $V$.\nIn this way, we see that the $i$-th row of $\\widehat{Y}$ is simply the projection of the $i$-th observation onto the orthonormal set of the first $l$ principal components.\nUnder this projection, the data is represented in fewer dimensions, and in such a way that accentuates the variance (which can help with finding patterns within the data).\n\nIn Figure \\ref{fig:iris_pca} we display the transformed iris data set, plotting the first principal component against the second. This reduction helps us to see the distinctions between the three different species, using only two dimensions instead of the full four dimensions of the feature space.\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{iris_pca.pdf}\n\\caption{Plot of the transformed iris data, keeping only the first two principal components.}\n\\label{fig:iris_pca}\n\\end{figure}\n\n\\begin{problem}\nRecreate the plot shown in Figure \\ref{fig:iris_pca} by performing PCA on the iris dataset, keeping the first two principal components.\n\n\\emph{Note:}\nIf \\li{Yhat} is your $150 \\times 2$ array of transformed observations, you can access the rows corresponding to the setosa flowers as follows:\n\\begin{lstlisting}\n>>> Yhat[iris.target==0]\n\\end{lstlisting}\nTo get the rows corresponding to versicolor and virginica specimens, simply replace the $0$ with $1$ and $2$, respectively.\n\\end{problem}\n\n\\section*{Latent Semantic Indexing}\n\\emph{Latent Semantic Indexing} (LSI) is an application of PCA which applies the ideas we have discussed to the realm of natural language processing.\nIn particular, LSI employs the SVD to reduce the dimensionality of a large corpus of text documents in order to enable us to evaluate the similarity between two documents.\nMany information-retrieval systems used in government and in industry are based on LSI.\n\nTo motivate the problem, suppose we have a large collection of documents dealing with various statistical and mathematical topics.\nHow can we find an article about PCA?\nWe might consider simply choosing the article which contains the acronym \\emph{PCA} the greatest number of times, but this is a crude method.\nA better way is to use a form of PCA on the collection of documents.\n\nIn order to do so, we need to represent the documents as numerical vectors.\nA standard way of doing this is to define an ordered set of words occurring in the collection of documents (called the \\emph{vocabulary}), and then to\nrepresent each document as a vector of word counts from the vocabulary.\nMore formally, let our vocabulary be $V = \\{w_1,w_2,\\ldots,w_m\\}$.\nThen a document is a vector $x  = (x_1,x_2,\\ldots,x_m) \\in \\mathbb{R}^m$ such that $x_i$ is the number of occurrences of word $w_i$ in the document.\nIn this setup, we represent the entire collection of $m$ documents as an $n \\times m$ matrix $X$, where $m$ is the number of vocabulary words and $n$ is the number of documents in our collection, each row being a document vector.\nAs expected, we let $X_{i,j}$ be the number of times term $j$ occurs in document $i$.\nNote that $X$ is often a sparse matrix, as any one document likely doesn't contain most of the vocabulary words.\nThis mode of representation is called the \\emph{bag of words} model for documents.\n\nWe calculate the SVD of $X$ without centering or scaling the data so that we may retain the sparsity.\nWe now have $X = U\\Sigma V^T$. Once we have selected the number of principal components to keep, say $l$, we can represent the corpus of documents by the matrix\n\\[\n\\widehat{X} = U_{:,:l}\\Sigma_{:l,:l} = XV_{:,:l}.\n\\]\nNote that $\\widehat{X}$ will no longer be a sparse matrix, but it has dimensions $n \\times l$, which is much smaller than $n \\times m$ when $l \\ll m$.\n\nNow that we have our documents represented in terms of the first $l$ principal components, we can find the similarity between two documents.\nOur measure for similarity is just the cosine of the angle between the vectors; a small angle (and hence large cosine) indicates greater similarity, while a large angle (hence small cosine)\nindicates greater dissimilarity.\nRecall that we can use the inner product to find the cosine of the angle between two vectors.\nUnder this metric, the similarity between document $i$ and document $j$ (represented by the $i$-th and $j$-th row of $\\widehat{X}$, notated $\\widehat{X}_i$ and $\\widehat{X}_j$, respectively) is just\n\\[\n\\frac{\\langle \\widehat{X}_i, \\widehat{X}_j\\rangle}{\\|\\widehat{X}_i\\|\\|\\widehat{X}_j\\|}.\n\\]\nTo find the document most similar to document $i$, we simply compute\n\\[\n\\argmax_{j\\neq i} \\frac{\\langle \\widehat{X}_i, \\widehat{X}_j\\rangle}{\\|\\widehat{X}_i\\|\\|\\widehat{X}_j\\|}.\n\\]\n\n\nWe now discuss some practical issues involved in creating the bag of words representation $X$ from the raw text.\nOur dataset will consist of the US State of the Union addresses from 1945 through 2013, each contained in a separate text file in the folder {\\tt Addresses}.\nWe would like to avoid loading in all of the text into memory at once, and so we will \\emph{stream} the documents one at a time.\n\nThe first thing we need to establish is the vocabulary set, i.e. the set of unique words that occur throughout the collection of documents.\nA Python set object automatically preserves the uniqueness of the elements, so we will create a set, and then iteratively read through the documents, adding the unique words of each\ndocument to the set. As we read in each document, we will remove punctuation and numerical characters and convert everything to lower case.\nThe following code will accomplish this task:\n\\begin{lstlisting}\n>>> # get list of filepaths to each text file in the folder\n>>> import string\n>>> from os import listdir\n>>> path_to_addresses = \"./Addresses/\"\n>>> paths = [path_to_addresses + p for p in os.listdir(path_to_addresses) if p[-4:]==\".txt\"]\n\n>>> # helper function to get list of words in a string\n>>> def extractWords(text):\n>>>     trans = string.maketrans(\"\", \"\")\n>>>     return text.strip().translate(trans, string.punctuation+string.digits).lower().split()\n\n>>> # initialize vocab set, then read each file and add to the vocab set\n>>> vocab = set()\n>>> for p in paths:\n>>>     with open(p, 'r') as f:\n>>>         for line in f:\n>>>             vocab.update(extractWords(line))\n\\end{lstlisting}\n\nWe now have a set containing all of the unique words in the corpus. However, many of the most common words do not provide important information.\nWe call these \\emph{stop words}. Examples in English include \\emph{the, a, an, and, I, we, you, it, there}, etc;\na list of common English stop words is given in {\\tt stopwords.txt}.\nWe remove the stop words from our vocabulary set as follows, and then fix an ordering to the vocabulary by creating a dictionary\nwhose key-value pairs are of the form (word, index):\n\\begin{lstlisting}\n>>> # load stopwords\n>>> with open(\"stopwords.txt\", 'r') as f:\n>>>     stopwords = set([w.strip().lower() for w in f.readlines()])\n\n>>> # remove stopwords from vocabulary, create ordering\n>>> vocab = {w:i for i, w in enumerate(vocab.difference(stopwords))}\n\\end{lstlisting}\n\nWe are now ready to create the word count vectors for each document, and we store these in a sparse matrix $X$.\nIt is convenient to use the \\li{Counter} object from the \\li{collections} module, as this\nobject automatically counts the occurrences of each distinct element in a list.\n\\begin{lstlisting}\n>>> from scipy import sparse\n>>> from collections import Counter\n>>> counts = [] # holds the entries of X\n>>> doc_index = [] # holds the row index of X\n>>> word_index = [] # holds the column index of X\n\n>>> # iterate through the documents\n>>> for doc, p in enumerate(paths):\n>>>     with open(p, 'r') as f:\n>>>         # create the word counter\n>>>         ctr = Counter()\n>>>         for line in f:\n>>>             ctr.update(extractWords(line))\n>>>         # iterate through the word counter, store counts\n>>>         for word, count in ctr.iteritems():\n>>>             try: # only look at words in vocab\n>>>                 word_index.append(vocab[word])\n>>>                 counts.append(count)\n>>>                 doc_index.append(doc)\n>>>             except KeyError: # if word isn't in vocab, skip it\n>>>                 pass\n\n>>> # create sparse matrix holding these word counts\n>>> X = sparse.csr_matrix((counts, [doc_index,word_index]), shape=(len(paths),len(vocab)), dtype=np.float)\n\\end{lstlisting}\n\n\\begin{problem}\nUsing the techniques of LSI discussed above--applied to the word count matrix $X$, and keeping the first 7 principal components--find the most similar and least similar speeches to both Bill Clinton's 1993 speech and to Richard Nixon's 1974 speech.\nAre the results plausible?\n\n\\emph{Hint:} Since $X$ is a sparse matrix, you will need to use the SVD method found in \\li{scipy.sparse.linalg}.\nThis method operates slightly differently than the SVD method found in \\li{scipy.linalg}, so make sure to read the\ndocumentation.\n\\label{prob:LSI1}\n\\end{problem}\n\nThe simple bag of words representation is a bit crude, as it fails to consider how some words may be more important than others\nin determining the similarity of documents.\nWords appearing in few documents tend\nto provide more information than words occurring in every document.\nFor example, while the word \\emph{war} might not be considered a stop word,\nit is likely to appear in quite a few addresses, whereas \\emph{Afghanistan} will not.\nThus two speeches sharing the word \\emph{Afghanistan} ought to be considered more\nrelated than two speeches sharing the word \\emph{war}.\nSo while $X_{i,j}$ is a good measure of the importance of term $j$ in document $i$,\nwe also need to consider some kind of global weight for each term $j$,\nindicating how important the term is over the entire collection.\nThere are a number of different weights we could choose; we choose to employ\nthe following approach:\n\nLet $t_{j}$ be the total number of times term $j$ appears in the entire\ncollection of documents.\nDefine\n\\begin{equation*}\np_{i,j} = \\frac{X_{i,j}}{t_{j}}.\n\\end{equation*}\nWe then let\n\\begin{equation*}\ng_{j} = 1 + \\sum_{i=1}^{m} \\frac{p_{i,j} \\log (p_{i,j} + 1)}{\\log m},\n\\end{equation*}\nwhere $m$ is the number of documents in the collection.\nWe call $g_{j}$ the \\emph{global weight} of term $j$.\nWe replace each term frequency in the matrix $X$ by weighting it globally.\nSpecifically, we define a matrix $A$ with entries\n\\begin{equation*}\nA_{i,j} = g_{j} \\log (X_{i,j} + 1).\n\\end{equation*}\nWe can now perform LSI on the matrix $A$, whose entries are both locally and globally weighted.\n\nTo calculate the matrix $A$ in a streaming manner, we must alter our code above somewhat:\n\\begin{lstlisting}\n>>> from itertools import izip\n>>> from math import log\n>>> t = np.zeros(len(vocab))\n>>> counts = []\n>>> doc_index = []\n>>> word_index = []\n\n>>> # get doc-term counts and global term counts\n>>> for doc, path in enumerate(paths):\n>>>     with open(path, 'r') as f:\n>>>         # create the word counter\n>>>         ctr = Counter()\n>>>         for line in f:\n>>>             words = extractWords(line)\n>>>             ctr.update(words)\n>>>         # iterate through the word counter, store counts\n>>>         for word, count in ctr.iteritems():\n>>>             try: # only look at words in vocab\n>>>                 word_ind = vocab[word]\n>>>                 word_index.append(word_ind)\n>>>                 counts.append(count)\n>>>                 doc_index.append(doc)\n>>>                 t[word_ind] += count\n>>>             except KeyError:\n>>>                 pass\n\n>>> # get global weights\n>>> g = np.ones(len(vocab))\n>>> logM = log(len(paths))\n>>> for count, word in izip(counts, word_index):\n>>>     p = count/float(t[word])\n>>>     g[word] += p*log(p+1)/logM\n\n>>> # get globally weighted counts\n>>> gwcounts = []\n>>> for count, word in izip(counts, word_index):\n>>>     gwcounts.append(g[word]*log(count+1))\n\n>>> # create sparse matrix holding these globally weighted word counts\n>>> A = sparse.csr_matrix((gwcounts, [doc_index,word_index]), shape=(len(paths),len(vocab)), dtype=np.float)\n\\end{lstlisting}\n\n\\begin{problem}\nRepeat Problem \\ref{prob:LSI1} using the matrix $A$. Do your answers seem more reasonable than before?\n\\end{problem}\n", "meta": {"hexsha": "a400299601d0d3d2ba71ec596a8cbd28c5063651", "size": 19648, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/PCA_LSI/PCA_LSI.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/PCA_LSI/PCA_LSI.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": 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": "Labs/PCA_LSI/PCA_LSI.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": 62.7731629393, "max_line_length": 974, "alphanum_fraction": 0.7372760586, "num_tokens": 4836, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7895871479215462}}
{"text": "\\section{Regression and classification}\n\nClassification:\n\\begin{align*}\nS_n = \\{(x^{(t)},y^{(t)}))|t=1,\\cdots,n\\}\\\\\nx^{(t)} \\in \\mathbb{R}^d, y^{(t)} \\in \\{-1,1\\}\n\\end{align*}\n\nRegression:\n\\begin{align*}\ny^{(t)} \\in \\mathbb{R}\\\\\nf(x,\\theta,\\theta_0) &= \\sum_{i=1}^d (\\theta_i x_i + \\theta_0) = \\\\\n&=\\theta \\cdot x + \\theta_0\n\\end{align*}\n\n\\subsection{Objective for linear regression}\n\nThe empirical risk  $R_n$  is defined as\n\\begin{align*}\nR_ n(\\theta ) = \\frac{1}{n} \\sum _{t=1}^{n} \\text {Loss}(y^{(t)} - \\theta \\cdot x^{(t)})\n\\end{align*}\n\nwhere  $(x^{(t)},y^{(t)})$  is the  $t$th training example (and there are $n$ in total), and  Loss  is some loss function, such as hinge loss.\n\nPossible to get \\textbf{closed form solution} for gradient because function is concave. Only possible if the $dxd$ matrix $A$ is invertible. Computationally expensive if dimensions are very high like in bag of words approach.\n\n\\begin{align*}\n\\nabla R_ n(\\theta ) &= A\\theta - b (=0)\\\\\n&= A^{-1}b\\\\\n\\text {where } \\\\\nA &= \\frac{1}{n} \\sum _{t=1}^{n} x^{(t)} ( x^{(t)})^ T\\\\\nb &= \\frac{1}{n} \\sum _{t=1}^{n} y^{(t)} x^{(t)}\n\\end{align*}\n\n$b$ is a vector with dimensionality $d$.\n\\subsection{Gradient based Approach}\nNudge gradient in the opposite direction to find (local) minima.\n\n\\begin{align*}\n\\nabla_{\\theta}(y^{(t)} - \\theta x^{(t)})^2 / 2 =\\\\\n= (y^{(t)} - \\theta x^{(t)}) \\nabla_{\\theta}(y^{(t)} - \\theta x^{(t)}) = \\\\\n= -(y^{(t)} - \\theta x^{(t)}) \\cdot x^{(t)}\n\\end{align*}\n\n\n\\begin{itemize}\n\\item initialize $\\theta=0$\n\\item randomly pick $t=\\{1,\\cdots,n\\}$\n\\item $\\theta = \\theta + \\eta(y^{(t)} - \\theta x^{(t)}) \\cdot x^{(t)}$\n\\end{itemize}\n\nWhere $\\eta$ is the learning rate (steps) and the learning rate gets smaller the closer you get $\\eta_k = \\frac{1}{1+k}$ \n\n\\subsection{Ridge Regression}\nRegularization is trying to push away from perfect fit.\n\n\\begin{align*}\nJ_{n, \\lambda } (\\theta , \\theta _0) &= \\frac{1}{n} \\sum _{t=1}^{n} \\frac{(y^{(t)} - \\theta \\cdot x^{(t)}-\\theta _0)^2}{2} + \\frac{\\lambda }{2} \\left\\|  \\theta  \\right\\| ^2\\\\\n\\nabla_{\\theta}(J_{n, \\lambda })&= \\lambda \\theta - (y^{(t)}-\\theta x^{(t)})x^{(t)}\n\\end{align*}\n\n\\begin{itemize}\n\\item initialize $\\theta=0$\n\\item randomly pick $t=\\{1,\\cdots,n\\}$\n\\item $\\theta = \\theta + \\eta\\lambda \\theta - (y^{(t)}-\\theta x^{(t)})x^{(t)} = (1-\\eta \\lambda)\\theta + \\eta(y^{(t)}-\\theta \\cdot x^{(t)})$\n\\end{itemize}\n\n\\subsection{Kernels}\n\n\\begin{align*}\n\\displaystyle  \\phi (x) \\displaystyle &= \\big [x_1, \\, x_2,\\,  {x_1}^2,\\,  \\sqrt{2}x_1x_2,\\,  {x_2}^2 \\big ]\\\\\n\\displaystyle \\phi (x') \\displaystyle &= \\big [x_1^\\prime ,\\,  x_2^\\prime ,\\,  {x_1^\\prime }^2,\\,  \\sqrt{2}x_1^\\prime x_2^\\prime ,\\,  {x_2^\\prime }^2 \\big ]\\\\\n\\displaystyle  \\phi (x) \\cdot \\phi (x^\\prime )&=\\displaystyle {x_1}{x_1^\\prime } + {x_2}{x_2^\\prime } + {x_1x_1^\\prime }^2 + 2{x_1}{x_1^\\prime }{x_2}{x_2^\\prime } + {x_2x_2^\\prime }^2\\\\\n&=\\displaystyle \\left({x_1}{x_1^\\prime } + {x_2}{x_2^\\prime }\\right)+ \\left({x_1}{x_1^\\prime } + {x_2}{x_2^\\prime }\\right)^2\\\\\n&=\\displaystyle \\left({x_1}{x_1^\\prime } + {x_2}{x_2^\\prime }\\right)+ \\left({x_1}{x_1^\\prime } + {x_2}{x_2^\\prime }\\right)^2\n\\end{align*}\n\n\\subsection{Kernel Perceptron}\n\nThe parameter vector of a preceptron algorithm can also be written as: \n\\begin{align*}\n\\displaystyle  \\displaystyle \\theta = \\sum _{j=1}^{n} \\alpha _ j y^{(j)} \\phi \\left(x^{(j)}\\right)\n\\end{align*}\n\nWhere $\\alpha_j$ represents the number of classification mistakes the perceptron algo made. Every time a missclassification happens the parameter vector is updated with the product of the label and the feature vector $\\theta  = \\theta + y^{(i)} x^{(i)}$. The goal of the Kernel Perceptron algo is to find the vector $\\alpha$ with the counts of the missclassifications.\n\n\\textbf{Kernel Perceptron}$\\displaystyle \\left(\\big \\{ (x^{(i)}, y^{(i)}), i=1,...,n, T \\big \\} \\right)$\n\\begin{enumerate}[\\indent {}]\n\t\\item initialize  $\\alpha _1, \\alpha _2, ..., \\alpha _ n;$ to some values\n\t\\begin{enumerate}[\\indent {}]\n\t\t\\item for $t=1,\\cdots,T$ do\n\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\\item for $i=1,\\cdots,n$ do\n\t\t\t\\begin{enumerate}[\\indent {}]\n\t\t\t\t\\item if $y^{(i)}\\sum _{j=1}^{n} \\alpha _ j y^{(j)} K(x^{j},x^{i}) \\leq 0$ then\n\t\t\t\t\\item update $\\alpha _ i = \\alpha _ i +1 y^{(i)}$\n\t\t\t\\end{enumerate}\n\t\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{enumerate}\n\n\\subsection{Radial basis Kernel}\n\\begin{align*}\nK(x,x') = e^{-\\frac{1}{2} {||x-x'||}^2}\n\\end{align*}", "meta": {"hexsha": "637af7e059403f96af363ed582afd4c9e2c430dd", "size": 4413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/regressions.tex", "max_stars_repo_name": "kpsunkara/MITx_capstone_2", "max_stars_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 19, "max_stars_repo_stars_event_min_datetime": "2020-03-30T18:06:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-12T10:26:16.000Z", "max_issues_repo_path": "content/regressions.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/regressions.tex", "max_forks_repo_name": "kpsunkara/MITx_capstone_2", "max_forks_repo_head_hexsha": "9ffbd54a0489edc2214e52bd65a65d4c92793971", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2020-08-20T14:25:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-07T01:02:57.000Z", "avg_line_length": 42.0285714286, "max_line_length": 368, "alphanum_fraction": 0.6102424654, "num_tokens": 1745, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802417938535, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7895841710809165}}
{"text": "\n\\subsection{Riemann sums}\n\nGiven a function \\(f(x)\\) and an interval \\([a,b]\\), we can divide \\([a,b]\\) into \\(n\\) sections and calculate:\n\n\\(\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})\\)\n\nThis is the Riemann sum.\n\n\\subsection{Riemann integral}\n\nWe take the limit of the Riemann sum as \\(n\\rightarrow \\infty\\)\n\n\\(\\int_a^b f(x)dx:= \\lim_{n\\rightarrow \\infty } \\sum_{j=0}^{n(b-a)} f(a+ \\dfrac{j}{n} )\\)\n\n\\subsection{Linearity}\n\n\\(\\int_a^bf(x)+g(x)dx=\\lim_{n\\rightarrow \\infty }\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+g(a+\\dfrac{j}{n})\\)\n\n\\(\\int_a^bf(x)+g(x)dx=\\lim_{n\\rightarrow \\infty }\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+\\lim_{n\\rightarrow \\infty }\\sum_{j=0}^{n(b-a)}g(a+\\dfrac{j}{n})\\)\n\n\\(\\int_a^bf(x)+g(x)dx=\\int_a^bf(x)dx +\\int_a^bg(x)dx\\)\n\n\\subsection{Continuation}\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\lim_{n\\rightarrow \\infty }\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+\\lim_{n\\rightarrow \\infty }\\sum_{j=0}^{n(c-b)}f(b+\\dfrac{j}{n})\\)\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\lim_{n\\rightarrow \\infty }[\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+\\sum_{j=0}^{n(c-b)}f(b+\\dfrac{j}{n})]\\)\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\lim_{n\\rightarrow \\infty }[\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+\\sum_{j=n(b-a)}^{n(c-b)+n(b-a)}f(b+\\dfrac{j-n(b-a)}{n})]\\)\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\lim_{n\\rightarrow \\infty }[\\sum_{j=0}^{n(b-a)}f(a+\\dfrac{j}{n})+\\sum_{j=n(b-a)}^{n(c-a)}f(a+\\dfrac{j}{n})]\\)\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\lim_{n\\rightarrow \\infty }[\\sum_{j=0}^{n(c-a)}f(a+\\dfrac{j}{n})]\\)\n\n\\(\\int_a^bf(x)dx+\\int_b^cf(x)dx=\\int_a^cf(x)dx\\)\n\n", "meta": {"hexsha": "bdea44c063ce261cfeb01585568d2415e2565079", "size": 1515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/integration/01-01-riemann.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/integration/01-01-riemann.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/integration/01-01-riemann.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.8684210526, "max_line_length": 161, "alphanum_fraction": 0.5867986799, "num_tokens": 699, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.8740772368049823, "lm_q1q2_score": 0.7895489019421494}}
{"text": "\\section{A Real Time Spectrum Analyser Using LMS}\n\\subsection{LS solution and relationship to DFT}\nGiven the cost function $\\mathcal{J}(\\mathbf w)$between estimated signal $\\mathbf {\\hat y}(n)=\\mathbf{F}\\mathbf{w}$ and true signal $\\mathbf y(n)$,\n\\begin{align}\n\\min_{\\mathbf{w}}\\|\\mathbf{y}-\\mathbf {\\hat y}\\|^2\n&=\\min_{\\mathbf{w}}\\|\\mathbf{y}-\\mathbf {\\hat y}\\|^H \\|\\mathbf{y}-\\mathbf {\\hat y}\\|\\notag\\\\\n&=\\min_{\\mathbf{w}}(\\mathbf{y}-\\mathbf{F}\\mathbf{w})^H (\\mathbf{y}-\\mathbf{F}\\mathbf{w}) \\notag\\\\\n&=\\min_{\\mathbf{w}}(\\mathbf{y}^H\\mathbf{y}-\\mathbf{y}^H\\mathbf{F}\\mathbf{w}-\\mathbf{w}^H\\mathbf{F}^H\\mathbf{y}+\\mathbf{w}^H\\mathbf{F}^H\\mathbf{F}\\mathbf{w})\n\\label{eq:cost}\n\\end{align}\nThus, in order to minise the cost function, take the derivation with respect to $\\mathbf w$ and equal to zero. The optimal weight can be obtained.\n\\begin{align}\n\\frac{\\partial \\mathcal{J}}{\\partial \\mathbf{w}} \n&=-\\mathbf{F}^H\\mathbf{y}-\\mathbf{F}^H\\mathbf{y}+2\\mathbf{F}^H\\mathbf{F}\\mathbf{w}=0\\notag\\\\\n\\mathbf{w}&=(\\mathbf{F}^H\\mathbf{F})^{-1}\\mathbf{F}^H\\mathbf{y}\n\\label{eq:ls}\n\\end{align}\nThe DFT of a sequence $x(n)$ is defined as\n\\begin{align}\nX_k =\\sum_{n=0}^{N-1}\\hat x_n e^{-j2\\pi kn/N}=\\sum_{n=0}^{N-1}\\hat x_n W^{nk}_N\n\\label{eq:dft}\n\\end{align}\nwhere $W_N=e^{-j2\\pi/N}$. In vector expression of Eq.\\ref{eq:dft}, it is \n\\begin{align}\n\\mathbf{X=W\\hat x}\n\\end{align}\nwhere transformation matrix $\\mathbf{W} is$\n\\begin{align}\n\\mathbf{W}=\n\\begin{bmatrix}\n    1 & 1 & 1 & \\dots  & 1 \\\\\n    1 & W_N & W_N^2 & \\dots  & W_N^{N-1} \\\\\n    \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    1 & W_N^{N-1} & W_N^{2(N-1)} & \\dots  & W_N^{(N-1)^2}\n\\end{bmatrix}\n\\end{align}\nDue to the transformation matrix $\\mathbf{W}$ is orthogonal and symmetric, the DFT is unitray transform. Therefore, the IDFT is \n\\begin{align}\n\\mathbf{\\hat x=W^{-1}X}\\quad \\text{with}\\quad \\mathbf{W^{-1}}=\\frac{1}{N}\\mathbf{W^H}\n\\end{align}\nWhich is corresponding to the estimated signal $\\mathbf {\\hat y}=\\mathbf{F}\\mathbf{w}$. Thus, the Eq.\\ref{eq:ls} can be expressed as\n\\begin{align}\n\\mathbf{w}\n=(\\mathbf{F}^H\\mathbf{F})^{-1}\\mathbf{F}^H\\mathbf{y}\n=(N\\mathbf{F^{-1}F})^{-1}\\mathbf{F}^H\\mathbf{y}\n=N\\mathbf{F}^H\\mathbf{y}\n=\\mathbf F^{-1}\\mathbf{y}\n\\end{align}\nwhere is corresponding to the DFT $\\mathbf{X=W\\hat x}$.\n\\subsection{Projection and baiss of DFT}\nDue to the transformation matrix of DFT is symmetric and orthogonal, the Fourier trainsfrom coefficients $\\mathbf{w}$ is formed by projecting the signal $y(n)$ onto the transformation matrix $\\mathbf{W}$ which is composed of harmonical sinusoids basises. In contrast, the IDFT is the inversely process to reconstruct the original signal by superposition of sinusoidal projections. However, the DFT and IDFT use finite length $N$ to estimate either coefficients $\\mathbf{w}$ or signal $\\mathbf{\\hat y}$, which makes errors occur comparing with true value.\n\\subsection{DFT-CLMS}\nThe DFT-CLMS algorithm is implimented on the non-stationary FM signal. Fig.\\ref{fig:3_3_c1} depicts the estimated time-varying frequencies. The trend of frequency is generally captured especially in perfectly estimation for constant segment. However, there exists an issue that the estimated frequency remains till the end of time index once it was obtained. Thus, the weights are not updated, which presents long smears in spectrum. The reason which causes this problem is that the gradient of back-propagation vanishes. Due to the gradient of the LMS algorithm is based on the eigenvalues of autocorrelation matrix. For the harmonically related sinusoids $\\mathbf x(n)$, there are zero eigenvalues of $\\mathbf R_{xx}$, resulting in hard back-propagation. \n\\begin{figure}[htb]\n     \\centering\n     \\includegraphics[width=0.4\\textwidth]{fig/33/33c1.eps}\n     \\caption{DFT-CLMS: estimated FM frequency}\n     \\label{fig:3_3_c1}\n\\end{figure}\\\\\nTo solve this problem, the Leaky CLMS is applied on the weight update with leakage coefficient, in expression of $\\gamma$ $\\mathbf{w}(n+1)=(1-\\gamma\\mu)\\mathbf{w}(n)+\\mu e^*(n)\\mathbf x(n)$. By changing previous value of weight, the weight will update along time. Fig.\\ref{fig:3_3_c2} illustrated the performance affected by different $\\gamma$. With small value of $\\gamma$, most of smears are removed presented as relatively distinct trends. The optimal value of $\\gamma$ is 0.1 with acceptable bias. If the leakage coefficient is too large, the estimation is inaccurate due to the large bias added.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/33/33c2.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/33/33c3.eps}\n     \\end{subfigure}\n    \\hspace{-0.4cm}\n     \\begin{subfigure}[b]{0.33\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/33/33c4.eps}\n     \\end{subfigure}\n     \\hspace{0.4cm}\n        \\caption{Leaky DFT-CLMS: estimated FM frequency with different $\\gamma$}\n        \\label{fig:3_3_c2}\n\\end{figure}\n\\subsection{DFT-CLMS estimated EEG signal}\nThe DFT-CLMS algorithm can also be used to analyse EEG signal. As shown in Fig.\\ref{fig:3_3_d}, the estimated spectrum agrees with the analysis in Part 1.2(b). A strong response at 8-10$Hz$ called alpha-rhythm is clear shown. The SSVEP at 13$Hz$ is detected as well, following its harmonic frequency at $26Hz$. However, the harmonic frequency at $39Hz$ is hard to recognize. Moreover, the recording apparatus is strongly detected at $50Hz$.\\\\\nNevertheless, the Leaky CLMS algorithm is not suitable for EEG data, since the EEG \\texttt{POz} is stationary signal. Thus, adding a leakage coefficient results in adding bias on the correct estimations.\n\\begin{figure}[htb]\n     \\centering\n     \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/33/33d1.eps}\n     \\end{subfigure}\n    \\hspace{0.4cm}\n     \\begin{subfigure}[b]{0.4\\textwidth}\n         \\centering\n         \\includegraphics[width=\\textwidth]{fig/33/33d2.eps}\n     \\end{subfigure}\n     \\caption{DFT-CLMS: estimated EEG frequency}\n     \\label{fig:3_3_d}\n\\end{figure}", "meta": {"hexsha": "d3428840f04d5360cabf9fe2b84ff4342f5811b1", "size": 6243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part3/33.tex", "max_stars_repo_name": "zdhank/Adaptive-Signal-Processing", "max_stars_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-09-05T10:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T08:55:10.000Z", "max_issues_repo_path": "Report/sections/Part3/33.tex", "max_issues_repo_name": "zdhank/Adaptive-Signal-Processing", "max_issues_repo_head_hexsha": "88d8c848909fdcbfd55907201575ef2b67601c93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/sections/Part3/33.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": 63.0606060606, "max_line_length": 757, "alphanum_fraction": 0.7035079289, "num_tokens": 2068, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525462, "lm_q2_score": 0.8652240930029117, "lm_q1q2_score": 0.7894617411309846}}
{"text": "% section7\r\n\r\n\\chapter{Dimension and Structure}\r\n\r\n\\section{Basis and Dimension}\r\n\r\n\\begin{exer} (\\textit{Linear Combination and Independence})\\\\\r\nAre any of the vectors in the set\r\n\\vspace{1mm}\r\n\\begin{displaymath}\r\nS = \\{ (2,6,3,4,2), \\hspace{1.5mm}(3,1,5,8,3), \\hspace{1.5mm}(5,1,2,6,7), \\hspace{1.5mm}(8,4,3,2,6), \\hspace{1.5mm}(5,5,6,3,4) \\}\r\n\\end{displaymath}\r\n\\vspace{1mm}\r\nlinear combinations of predecessors? Justify your answer.\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\nOne strategy is to form a matrix $V$ of the column vectors $\\mathbf{v}_{k}$ mentioned above and decide whether the system $V \\mathbf{x} = \\mathbf{0}$ has nontrivial solutions. If so, then at least one column is a linear combination of previous ones. Otherwise, the columns are linearly independent.\r\n\r\n\\begin{verbatim}\r\n\r\nv1 = [2 6 3 4 2]'; v2 = [3 1 5 8 3]'; v3 = [5 1 2 6 7]';\r\nv4 = [8 4 3 2 6]'; v5 = [5 5 6 3 4]';\r\n\r\n% Construct V of the column vectors v1,v2,v3,v4 and v5.\r\nV = [v1 v2 v3 v4 v5]; \r\n\r\nformat short;\r\n\r\n% Find the reduced row echelon form of V.\r\nrref_V = rref(V); \r\n\r\ndisp('The reduced row echelon form of A is'); disp(rref_V);\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\r\n\\begin{verbatim}\r\n\r\nThe reduced row echelon form of A is\r\n     1     0     0     0     0\r\n     0     1     0     0     0\r\n     0     0     1     0     0\r\n     0     0     0     1     0\r\n     0     0     0     0     1\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\r\n\\noindent Since the reduced row echelon form of $V$ has 5 pivots, the columns of V are linearly independent. Hence, no column of $V$ can be a linear combination of any other columns.\r\n\\end{sol}\r\n\r\n\\vspace{2mm}\r\n\r\n\\section{Properties of Bases}\r\n\r\n\r\n\\begin{exer}\r\nIn this problem, we make a function file \\verb\"CheckBasis.m\" to check that the vectors $\\mathbf{v}_{1}$, $\\mathbf{v}_{2}$, $\\mathbf{v}_{3}$ and $\\mathbf{v}_{4}$ form a basis of $\\mathbb{R}^4$ using the equivalent statements (a), (g), (h), and (o) of Theorem 7.2.7 in the textbook.\r\n\r\n\\begin{enumerate}\r\n\\item[(a)]\r\nComplete the shadow part (/////) of the m-file given below referring to the comments and the execution results.\r\n\r\n\\begin{verbatim}\r\n\r\n%--- your function file ---%\r\nfunction [Result]=CheckBasis(v1, v2, v3, v4, case_num)\r\n  %  if case_num=1, check the statement (a),\r\n  %  if case_num=2, check the statement (g),\r\n  %  if case_num=3, check the statement (h).\r\n\r\n  % Construct the matrix V.\r\n  ////////////////////////\r\n\r\n  % Use the switch statement to check \r\n  % whether one of the statements (a), (g), and (h) holds.\r\n  switch case_num\r\n    case 1  \r\n      fprintf('* You enter %d: statement (a) *\\n', case_num);\r\n      ////////////////////////\r\n      if ////////////////////////\r\n        disp('Given vectors form a basis of 4 dimensional space.');\r\n      else\r\n        disp('Given vectors do not form a basis of 4 dimensional space.');\r\n      end\r\n    case 2\r\n      fprintf('* You enter %d: statement (g) *\\n', case_num);\r\n      Result=det(V);\r\n      if Result~=0\r\n        disp('Given vectors form a basis of 4 dimensional space.');\r\n      else\r\n        disp('Given vectors do not form a basis of 4 dimensional space.');\r\n      end\r\n    ///////////////////////////  % check statement (h)\r\n        ////////////////////////\r\n        ////////////////////////\r\n        ////////////////////////\r\n        ////////////////////////\r\n        ////////////////////////\r\n        ////////////////////////\r\n        ////////////////////////\r\n  end\r\nend\r\n\\end{verbatim}\r\n\r\n\\vspace{3mm}\r\n\r\n\\noindent The execution results will be as follows:\r\n\\begin{verbatim}\r\n>> v1=[1 0 0 0]'; v2=[0 2 0 0]'; v3=[0 0 4 5]'; v4=[0 0 0 -1]'; v5=[0 0 0 1]';\r\n>> C=CheckBasis(v1, v2, v3, v4,3)\r\n* You enter 3: statement (h) *\r\n  Given vectors are basis of 4 dimensional space.\r\n\r\nC =\r\n\r\n     1\r\n     2\r\n    -1\r\n     4\r\n\r\n>> CheckBasis(v1, v2, v4, v5, 1);\r\n* You enter 1: statement (a) *\r\n  Given vectors do not form a basis of 4 dimensional space.\r\n\r\n>> determinant=CheckBasis(v1, v2, v3, v5, 2)\r\n* You enter 2: statement (g) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n\r\ndeterminant =\r\n     8\r\n\\end{verbatim}\r\n\r\n\\vspace{3mm}\r\n\\item[(b)] Using \\verb\"CheckBasis.m\" from (a), check whether\r\n\\begin{itemize}\r\n\\item[i.] $\\mathbf{v}_{1}=(-1, 0, 1, 0)^{T}$, $\\mathbf{v}_{2}=(2, 3, -2, 6)^{T}$, $\\mathbf{v}_{3}=(0, -1, 2, 0)^{T}$ and $\\mathbf{v}_{4}=(0, 0, 1, 5)^{T}$ form a basis of $\\mathbb{R}^4$.\r\n\r\n\\item[ii.] $\\mathbf{v}_{1}=(a, b, c, d)^{T}$, $\\mathbf{v}_{2}=(-b, a, d, -c)^{T}$, $\\mathbf{v}_{3}=(-c, -d, a, b)^{T}$ and $\\mathbf{v}_{4}=(-d, c, -b, a)^{T}$ form a basis of $\\mathbb{R}^4$. (Do not use the statement (h). Guess why not?)\r\n\\end{itemize}\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\vspace{1mm}\r\n\\verb\"\"\r\n\\begin{enumerate}\r\n\\item[(a)]\r\n\\verb\" \"\r\n\\verb\"% ----- your function file ----- %\"\\\\\r\n\\verb\"function [Result]=CheckBasis(v1, v2, v3, v4, case_num)\"\\\\\r\n\\verb\"  %  if case_num=1, check the statement (a),\"\\\\\r\n\\verb\"  %  if case_num=2, check the statement (g),\"\\\\\r\n\\verb\"  %  if case_num=3, check the statement (h).\"\\\\\r\n\\\\\r\n\\verb\" % Construct the matrix V.\"\\\\\r\n  \\textcolor{blue}{\\texttt{  V=[v1 v2 v3 v4];}}\\\\\r\n\r\n\\verb\"  % Use the switch statement to check\" \\\\\r\n\\verb\"  % whether one of the statements (a), (g), and (h) holds.\"\\\\\r\n\\verb\"  switch case_num\"\\\\\r\n\\verb\"    case 1\"  \\\\\r\n\\verb\"      fprintf('* You enter %d: statement (a) *', case_num);\"\\\\\r\n\\textcolor{blue}{\\texttt{ \\hspace{8mm}         Result=rref(V)}}\r\n\r\n\\hspace{8mm}      \\texttt{ if \\textcolor{blue}{det(Result)$\\sim$=0}}\\\\\r\n\\verb\"        disp('Given vectors form a basis of 4 dimensional space.');\"\\\\\r\n\\verb\"      else\"\\\\\r\n\\verb\"        disp('Given vectors do not form a basis of 4 dimensional space.');\"\\\\\r\n\\verb\"      end\"\\\\\r\n\\verb\"    case 2\"\\\\\r\n\\verb\"      fprintf('* You enter %d: statement (g) *', case_num);\"\\\\\r\n\\verb\"      Result=det(V);\"\\\\\r\n\\verb\"      if Result~=0\"\\\\\\\r\n\\verb\"        disp('Given vectors form a basis of 4 dimensional space.');\"\\\\\r\n\\verb\"      else\"\\\\\r\n\\verb\"        disp('Given vectors do not form a basis of 4 dimensional space.');\"\\\\\r\n\\verb\"      end\"\\\\\r\n\\textcolor{blue}{\\texttt{  \\hspace{4mm}  case 3}}\\verb\"  % check statement (h)\"\\\\\r\n\\textcolor{blue}{\\texttt{  \\hspace{8mm}      [Q D]=eig(V);}}\r\n\r\n\\textcolor{blue}{\\texttt{  \\hspace{8mm}            Result=diag(R);}}\r\n\r\n\\textcolor{blue}{\\texttt{  \\hspace{8mm}         if det(R)==0}}\r\n\r\n\\textcolor{blue}{\\texttt{   \\hspace{12mm}       disp('Given vectors form a basis of 4 dimensional space.');}}\r\n\r\n\\textcolor{blue}{\\texttt{  \\hspace{8mm}              else}}\r\n\r\n \\textcolor{blue}{\\texttt{  \\hspace{12mm}               disp('Given vectors do not form a basis of 4 dimensional space.');}}\r\n\r\n\\textcolor{blue}{\\texttt{  \\hspace{8mm}        end}}\r\n\r\n\\textcolor{blue}{\\texttt{  \\hspace{4mm}      end}}\r\n\r\n\r\n\\item[(b)-i.] \r\n\\begin{verbatim}\r\n>> v1=[-1 0 1 0]'; v2=[2 3 -2 6]';  v3=[0 -1 2 0]'; v4 = [0 0 1 5]';\r\n>> CheckBasis(v1, v2, v3, v4, 1);\r\n>> CheckBasis(v1, v2, v3, v4, 2);\r\n>> CheckBasis(v1, v2, v3, v4, 3);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\n* You enter 1: statement (a) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n* You enter 2: statement (g) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n* You enter 3: statement (h) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\item[(b)-ii.] \r\n\\begin{verbatim}\r\n>> syms a b c d;\r\n>> v1=[a;b;c;d]; v2=[-b;a;d;-c]; v3=[-c;-d;a;b]; v4 = [-d;c;-b;a];\r\n>> CheckBasis(v1, v2, v3, v4, 1);\r\n>> CheckBasis(v1, v2, v3, v4, 2);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\n* You enter 1: statement (a) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n* You enter 2: statement (g) *\r\n  Given vectors form a basis of 4 dimensional space.\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\r\n\r\n\\section{The Fundamental Spaces of a Matrix}\r\n\r\n\r\n\\begin{exer}\\label{ex1}\r\nIn this problem, we make a function file \\verb\"getFSinfo.m\" to get the dimension and basis of the fundamental spaces of a given matrix. For example, we execute the followings:\r\n\\begin{verbatim}\r\n>> A=[1 0 0 0 2; -2 1 -3 -2 -4; 0 5 -14 -9 0; 2 10 -28 -18 4];\r\n>> getFSinfo(A);\r\n\\end{verbatim}\r\nThen, the Command Window displays the results as follows:\r\n\\begin{verbatim}\r\nGiven matrix is:\r\n     1     0     0     0     2\r\n    -2     1    -3    -2    -4\r\n     0     5   -14    -9     0\r\n     2    10   -28   -18     4\r\n\r\n== Dimension of the fundamental spaces of a given matrix ==\r\ndim(row(A))=dim(col(A)): 3, \t dim(null(A)): 2, \t dim(null(A_trans)): 1\r\n\r\n== Basis of the fundamental spaces of a given matrix (in row vectors) ==\r\n row(A)\r\n     1     0     0     0     2\r\n     0     1     0     1     0\r\n     0     0     1     1     0\r\n\r\n col(A)\r\n     1     0     0     2\r\n     0     1     0     0\r\n     0     0     1     2\r\n\r\n null(A)\r\n     0    -1    -1     1     0\r\n    -2     0     0     0     1\r\n\r\n null(A_trans)\r\n    -2     0    -2     1\r\n\r\n*****************************************************\r\n\\end{verbatim}\r\n\\begin{enumerate}\r\n\\item[(a)] Complete the missing parts of the m-file \\verb\"getFSinfo\" given as follows:\r\n\\begingroup\r\n    \\fontsize{10pt}{12pt}\\selectfont\r\n\\begin{verbatim}\r\n\r\n%--- function file 'getFSinfo.m' ---%\r\nfunction [info]=getFSinfo(A)\r\n  % row(A): basis and dimension\r\n  /////// missing part ///////\r\n\r\n  % col(A): basis and dimension\r\n  /////// missing part ///////\r\n\r\n  % null(A): basis and dimension\r\n  /////// missing part ///////\r\n\r\n  % null(A'): basis and dimension\r\n  /////// missing part ///////\r\n\r\n  disp('Given matrix is:'); disp(A);\r\n  fprintf('== Dimension of the fundamental spaces of given matrix == \\n');\r\n  fprintf('dim(row(A))=dim(col(A)): %d,', rank_A);\r\n  fprintf('\\t dim(null(A)): %d,\\t dim(null(A_trans)): %d \\n\\n', nullity, nullity_T);\r\n  fprintf('== Basis of the fundamental spaces of given matrix (in row vectors) == \\n');\r\n  disp(' row(A)'); disp(double(rowA_basis));\r\n  disp(' col(A)'); disp(double(colA_basis));\r\n  disp(' null(A)'); disp(nullA_basis);\r\n  disp(' null(A_trans)'); disp(nullAtrans_basis);\r\n  fprintf('\\n*****************************************************\\n');\r\nend\r\n\\end{verbatim}\r\n\\endgroup\r\nYou may use the MATLAB commands \\textit{rank, colspace, rref, null} and so on.\r\n\\vspace{3mm}\r\n\\item[(b)] Using your function file \\verb\"getFSinfo.m\", find the dimension and basis of the fundamental spaces of\r\n\r\n$A = \\begin{bmatrix} 3 & 2& 1& 3& 5 \\\\ 6& 4& 3& 5& 7 \\\\ 9&6&5&7&9\\\\3&2&0&4&8 \\end{bmatrix}$, $B = \\begin{bmatrix} 3 & -1 & 3& 2& 5 \\\\ 5& -3&2&3&4\\\\ 1&-3&-5&0& -7\\\\ 7&-5&1&4&1\\end{bmatrix}$, $C = \\begin{bmatrix} 1& 3& 2& 1\\\\ -2 & -6 & 0& -6\\\\ 3& 9& 1& 8\\\\ -1& -3& -3& -6\\\\ 1& 3& 2& 1\\\\ 4& 12& 1&11 \\end{bmatrix}$.\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\r\n\\verb\"% ----- function file 'getFSinfo.m' ----- %\"\r\n\r\n\\verb\"function [info]=getFSinfo(A)\"\r\n\r\n\\verb\"  [m,n]=size(A)\"\r\n\r\n\\verb\"  % row(A): basis and dimension\"\r\n\r\n{\\color{blue}\\verb\"    rank_A=rank(A);    % rank of A;\"\r\n\r\n    \\verb\"    rowA=colspace(sym(A')); % find the row basis\"\r\n\r\n    \\verb\"    rowA_basis=rowA(:, 1:rank_A)';  % basis of row(A)\"\r\n    }\r\n\r\n\r\n\r\n\\verb\"  % col(A): basis and dimension\"\r\n\r\n{\\color{blue}\\verb\"    colA=colspace(sym(A)); % find the column basis\"\r\n\r\n\\verb\"    colA_basis=colA(:, 1:rank_A)';  % basis of col(A)\"\r\n    }\r\n\r\n\r\n\r\n\r\n\\verb\"  % null(A): basis and dimension\"\r\n\r\n{\\color{blue}\\verb\"    nullA=null(A, 'r');\"\r\n\r\n\\verb\"    nullity=n-rank_A;   % using Dimension theorem\"\r\n\r\n\\verb\"    nullA_basis=nullA(:, 1:nullity)';\"\r\n    }\r\n\r\n\\verb\"  % null(A'): basis and dimension\"\r\n\r\n{\\color{blue}\\verb\"    nullAtrans=null(A', 'r');\"\r\n\r\n    \\verb\"    nullity_T=m-rank_A;    \"\r\n\r\n    \\verb\"    nullAtrans_basis=nullAtrans(:,1:nullity_T)';\"\r\n    }\r\n\\begin{verbatim}\r\n  disp('Given matrix is:'); disp(A);\r\n  fprintf('== Dimension of the fundamental spaces of given matrix == \\n');\r\n  fprintf('dim(row(A))=dim(col(A)): %d,', rank_A);\r\n  fprintf('\\t dim(null(A)): %d,', nullity);\r\n  fprintf('\\t dim(null(A_trans)): %d \\n\\n', nullity_T);\r\n  fprintf('== Basis of the fundamental spaces ');\r\n  fprintf('of given matrix (in row vectors) == \\n');\r\n  disp(' row(A)'); disp(double(rowA_basis));\r\n  disp(' col(A)'); disp(double(colA_basis));\r\n  disp(' null(A)'); disp(nullA_basis);\r\n  disp(' null(A_trans)'); disp(nullAtrans_basis);\r\n  fprintf('\\n*****************************************************\\n');\r\nend\r\n\\end{verbatim}\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\nA=[3 2 1 3 5; 6 4 3 5 7; 9 6 5 7 9; 3 2 0 4 8];\r\nB=[3 -1 3 2 5; 5 -3 2 3 4; 1 -3 -5 0 -7; 7 -5 1 4 1];\r\nC=[1 3 2 1; -2 -6 0 -6 ;3 9 1 8; -1 -3 -3 -6; 1 3 2 1; 4 12 1 11];\r\ngetFSinfo(A);\r\ngetFSinfo(B);\r\ngetFSinfo(C);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nGiven matrix is:\r\n     3     2     1     3     5\r\n     6     4     3     5     7\r\n     9     6     5     7     9\r\n     3     2     0     4     8\r\n== Dimension of the fundamental spaces of given matrix ==\r\ndim(row(A))=dim(col(A)): 2,\t dim(null(A)): 3,\t dim(null(A_trans)): 2\r\n== Basis of the fundamental spaces of given matrix (in row vectors) ==\r\n row(A)\r\n    1.0000    0.6667         0    1.3333    2.6667\r\n         0         0    1.0000   -1.0000   -3.0000\r\n col(A)\r\n     1     0    -1     3\r\n     0     1     2    -1\r\n null(A)\r\n   -0.6667    1.0000         0         0         0\r\n   -1.3333         0    1.0000    1.0000         0\r\n   -2.6667         0    3.0000         0    1.0000\r\n null(A_trans)\r\n     1    -2     1     0\r\n    -3     1     0     1\r\n*****************************************************\r\n\r\nGiven matrix is:\r\n     3    -1     3     2     5\r\n     5    -3     2     3     4\r\n     1    -3    -5     0    -7\r\n     7    -5     1     4     1\r\n== Dimension of the fundamental spaces of given matrix ==\r\ndim(row(A))=dim(col(A)): 3,\t dim(null(A)): 2,\t dim(null(A_trans)): 1\r\n== Basis of the fundamental spaces of given matrix (in row vectors) ==\r\n row(A)\r\n    1.0000         0    1.7500    0.7500         0\r\n         0    1.0000    2.2500    0.2500         0\r\n         0         0         0         0    1.0000\r\n col(A)\r\n     1     0    -3     0\r\n     0     1     2     0\r\n     0     0     0     1\r\n null(A)\r\n   -1.7500   -2.2500    1.0000         0         0\r\n   -0.7500   -0.2500         0    1.0000         0\r\n null(A_trans)\r\n     3    -2     1     0\r\n*****************************************************\r\n\r\nGiven matrix is:\r\n     1     3     2     1\r\n    -2    -6     0    -6\r\n     3     9     1     8\r\n    -1    -3    -3    -6\r\n     1     3     2     1\r\n     4    12     1    11\r\n== Dimension of the fundamental spaces of given matrix ==\r\ndim(row(A))=dim(col(A)): 3,\t dim(null(A)): 1,\t dim(null(A_trans)): 3\r\n== Basis of the fundamental spaces of given matrix (in row vectors) ==\r\n row(A)\r\n     1     3     0     0\r\n     0     0     1     0\r\n     0     0     0     1\r\n col(A)\r\n    1.0000         0    0.5000         0    1.0000    0.5000\r\n         0    1.0000   -1.2500         0         0   -1.7500\r\n         0         0         0    1.0000         0         0\r\n null(A)\r\n    -3     1     0     0\r\n null(A_trans)\r\n   -0.5000    1.2500    1.0000         0         0         0\r\n   -1.0000         0         0         0    1.0000         0\r\n   -0.5000    1.7500         0         0         0    1.0000\r\n*****************************************************\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\\begin{exer}\r\n(\\textit{Bases for the Fundamental Spaces})\r\n\r\n\\begin{enumerate}\r\n\r\n\\item[(a)] Use the MATLAB commands \\textit{sym} and \\textit{colspace} to find a basis for the column space of the matrix\r\n\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} 2& \\hspace{2mm} -1& \\hspace{5mm} 3&\\hspace{4mm} 5\\\\ 4 & -3 & 1 & 3 \\\\ 3 & -2 & 3 & 4 \\\\ 4 & -1 & 15 & 17 \\\\ 7 & -6 & -7 & 0 \\end{array} \\right].\r\n\\end{displaymath}\r\n\r\n\\vspace{1mm}\r\n\r\n\\item[(b)] Use the same MATLAB commands in (a) to find a basis for the row space of $A$.\r\n\r\n\\vspace{1mm}\r\n\r\n\\item[(c)] Confirm that the basis obtained in (b) is consistent with the basis obtained from the reduced row echelon form of $A$.\r\n\r\n\\vspace{1mm}\r\n\r\n\\item[(d)] Tell what happens if you use the MATLAB command \\textit{orth}?\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\n\r\n%\\vspace{3mm}\r\n\r\n\r\n\\begin{itemize}\r\n\\item[(a)]\r\n\\begin{verbatim}\r\n% Set a matrix A whose entries are symbolic objects.\r\nA = sym([2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0]);\r\n\r\n% Find a basis for the column space of A.\r\ncol_basis = colspace(A);\r\n\r\ndisp('A basis for the column space of A is');\r\ndisp(col_basis(:,1)'); disp(col_basis(:,2)'); disp(col_basis(:,3)');\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nA basis for the column space of A is\r\n[ 1, 0, 0, 2, 1]\r\n\r\n[ 0, 1, 0, -3, 5]\r\n\r\n[ 0, 0, 1, 4, -5]\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Set a matrix A_transpose whose entries are symbolic objects.\r\nA_transpose = sym([2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0]');\r\n\r\n% Finding a basis for the row space of A is equivalent to\r\n% finding a basis for the column space of A_transpose.\r\nrowbasis = colspace(A_transpose);\r\n\r\ndisp('A basis for the row space of A is');\r\ndisp(rowbasis(:,1)'); disp(rowbasis(:,2)'); disp(rowbasis(:,3)');\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nA basis for the row space of A is\r\n[ 1, 0, 0, 6]\r\n\r\n[ 0, 1, 0, 7]\r\n\r\n[ 0, 0, 1, 0]\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\r\n\\item[(c)]\r\n\\begin{verbatim}\r\n% Set a matrix A.\r\nA = [2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0];\r\n\r\n% Find the reduced row echelon form of A.\r\nrref_A = rref(A); \r\n\r\n% The nonzero rows of the reduced row echelon form of A\r\n% form a basis for the row space of A.\r\n\r\ndisp('A basis for the row space of A is');\r\ndisp(rref_A(1,:)); disp(rref_A(2,:)); disp(rref_A(3,:));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nA basis for the row space of A is\r\n     1     0     0     6\r\n\r\n     0     1     0     7\r\n\r\n     0     0     1     0\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\item[(d)]\r\n\r\n\\begin{verbatim}\r\n% Set A.\r\nA = [2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0]; \r\n\r\n% The command orth gives an orthonormal basis for the column space of A.\r\nB = orth(A);\r\n\r\ndisp('An orthonormal basis for the column space of A is');\r\ndisp('q1='); disp(B(:,1)');\r\ndisp('q2='); disp(B(:,2)');\r\ndisp('q3='); disp(B(:,3)');\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nAn orthonormal basis for the column space of A is\r\nq1=\r\n   -0.2427   -0.1508   -0.2229   -0.9246    0.1177\r\n\r\nq2=\r\n   -0.1189   -0.3624   -0.2060    0.0253   -0.9008\r\n\r\nq3=\r\n    0.3760   -0.6016   -0.5930    0.1848    0.3331\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\\end{itemize}\r\n\\end{sol}\r\n\r\n\\section{The Dimension Theorem and Its Implications}\r\n\r\n\r\n\\begin{exer}\r\n(\\textit{Rank and Nullity})\r\n\r\n\\begin{enumerate}\r\n\r\n\\item[(a)] Use the MATLAB command \\textit{rank} and the Formula (2) in Section $7.4$ to find the nullity of the matrix\r\n\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrrr} 3& \\hspace{1mm} 2& \\hspace{1mm} 1&\\hspace{1mm} 3&\\hspace{1mm} 5\\\\ 6 & 4 & 3 & 5 & 7 \\\\ 9 & 6 & 5 & 7 & 9 \\\\ 3 & 2 & 0 & 4 & 8 \\end{array} \\right].\r\n\\end{displaymath}\r\n\r\n\r\n\\item[(b)] Confirm that the result obtained in (a) is consistent with the number of basis vectors which are obtained by using the MATLAB command \\textit{null}.\r\n\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\verb\"\"\r\n\\begin{itemize}\r\n\r\n\r\n\\item[(a)]\r\n\r\n\\begin{verbatim}\r\n% Set A.\r\nA = [3 2 1 3 5; 6 4 3 5 7; 9 6 5 7 9; 3 2 0 4 8]; \r\n\r\n% Find the rank of A by using the command rank.\r\nrank_A = rank(A); \r\n\r\n% Size of the matrix A.\r\n[ m n ] = size(A); \r\n% m = the number of rows of A, n = the number of columns of A.\r\n\r\n % By (2) in section 7.4, rankA + nullA = n.\r\nnull_A = n - rank_A;\r\n\r\ndisp('The nullity of A is'); disp(null_A);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe nullity of A is\r\n     3\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\\item[(b)]\r\n\\begin{verbatim}\r\n% Set A.\r\nA = [3 2 1 3 5; 6 4 3 5 7; 9 6 5 7 9; 3 2 0 4 8]; \r\n\r\n% Find a basis for the null space of A.\r\nnullA = null(A,'r'); \r\n% null(A,'r') returns a matrix \r\n% whose columns are a basis for the null space of A.\r\n\r\n[m n] = size(nullA);\r\n% Since the number of columns of nullA is n,\r\n% thus, n = the number of basis vectors of the null space of A.\r\n\r\ndisp('The nullity of A is'); disp(n);\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe nullity of A is\r\n     3\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\r\n\r\n\r\n\r\n\\end{itemize}\r\n\r\n\\end{sol}\r\n\r\n\r\n\r\n\r\n\\section{The Rank Theorem and Its Implications}\r\n\r\n\\begin{exer}\r\nNote that the rank of a nonzero matrix $A$ is equal to the order of the largest square submatrix of $A$ (formed by deleting rows and columns of $A$) whose determinant is nonzero. In this problem, we make a function file \\verb\"CheckRank.m\" to find the rank of the given matrix using this fact. We want to obtain the execution results as follows:\r\n\\begin{verbatim}\r\n>> A=[1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];\r\n>> rankA=CheckRank(A)\r\nrankA =\r\n     2\r\n\\end{verbatim}\r\nFor this, you may start with the largest square matrices to be found in $A$ and a search is started for the first submatrix with a nonzero determinant. Use the MATLAB command \\textit{nchoosek} to select all the combinations of rows and columns needed in the search process and you may use the several MATLAB commands if you need. Complete the m-file below and check the determinant of the matrices $A$, $B$, and $C$ given in the Exercise \\ref{ex1} (b). Also, compare the results using the MATLAB command \\textit{rank}.\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n%--- function file 'CheckRank.m' ---%\r\nfunction [rank_A]= CheckRank(A)\r\n\\end{verbatim}\r\n\r\n{\\color{blue}\r\n\\begin{verbatim}\r\n    [m,n]=size(A);  % size of given matrix\r\n    flg=1;  % flag for while loop\r\n    if m>n  % if (# of row) > (# of col)\r\n        A=A';\r\n    end\r\n    A=sym(A);   % Set A as a symbolic object\r\n\r\n    K = min(m,n);   N = max(m,n);   % k : row number, N: col number\r\n    k=K;    % from the largest size of submatrix\r\n    while flg == 1\r\n        comb_row=nchoosek(1:K, k);  % combinations of row\r\n        comb_col=nchoosek(1:N, k);  % combinations of columns\r\n        for ii=1:size(comb_row) %\r\n            selected_A=A(comb_row(ii,:),:); % selected row index\r\n            for jj=1:size(comb_col)\r\n                sub_A=selected_A(:,comb_col(jj, :));   % selected col index\r\n                if det(sub_A)~=0    % if non zeros determinant appears\r\n                    rank_A=k;   % the size at that time <- rank\r\n                    flg=0;  % stop the while loop.\r\n                end\r\n            end\r\n        end\r\n        k=k-1;  % if all submatrices of size k have a zero determinant,\r\n                % reduce the size of submatrix.\r\n    end\r\n\\end{verbatim}}\r\n\\begin{verbatim}\r\nend\r\n\\end{verbatim}\r\n\r\n\r\n\\noindent To check the determinant of the matrices $A$, $B$, and $C$ given in the Exercise \\ref{ex1}, you execute the followings:\r\n\\begin{verbatim}\r\nA=[3 2 1 3 5; 6 4 3 5 7; 9 6 5 7 9; 3 2 0 4 8];\r\nB=[3 -1 3 2 5; 5 -3 2 3 4; 1 -3 -5 0 -7; 7 -5 1 4 1];\r\nC=[1 3 2 1; -2 -6 0 -6 ;3 9 1 8; -1 -3 -3 -6; 1 3 2 1; 4 12 1 11];\r\n\r\nfprintf('my rank(A): %.5f, MATLAB rank(A): %.5f \\n', CheckRank(A), rank(A));\r\nfprintf('my rank(B): %.5f, MATLAB rank(B): %.5f \\n', CheckRank(B), rank(B));\r\nfprintf('my rank(C): %.5f, MATLAB rank(C): %.5f \\n', CheckRank(C), rank(C));\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nmy rank(A): 2.00000, MATLAB rank(A): 2.00000\r\nmy rank(B): 3.00000, MATLAB rank(B): 3.00000\r\nmy rank(C): 3.00000, MATLAB rank(C): 3.00000\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\noindent Those are the same results as given in Exercise\\ref{ex1}.\r\n\r\n\\end{sol}\r\n\r\n\r\n% 7.6\r\n\\section{The Pivot Theorem and Its Implications}\r\n\r\n\r\n\\begin{exer}(\\textit{Finding a Basis with the Pivot Theorem})\\\\\r\nConsider the vectors\r\n\\begin{displaymath}\r\n\\begin{array}{lll} \\vspace{1mm} \\hspace{2mm} \\mathbf{v}_{1} & \\hspace{1mm} = & \\hspace{1mm} (1, \\hspace{1mm} 2, \\hspace{1mm} 4, \\hspace{1mm} -6,  \\hspace{1mm} 11, \\hspace{1mm} 23, \\hspace{1mm} -14, \\hspace{1mm} 0, \\hspace{1mm} 2, \\hspace{1mm} 2), \\\\ \\vspace{1mm} \\hspace{2mm} \\mathbf{v}_{2} & \\hspace{1mm} = & \\hspace{1mm} (3, \\hspace{1mm} 1, \\hspace{1mm} -1, \\hspace{1mm} 7, \\hspace{1mm} 9, \\hspace{1mm} 13, \\hspace{1mm} -12, \\hspace{1mm} 8, \\hspace{1mm} 6, \\hspace{1mm} -30), \\\\ \\vspace{1mm} \\hspace{2mm} \\mathbf{v}_{3} & \\hspace{1mm} = & \\hspace{1mm} (5, \\hspace{1mm} 5, \\hspace{1mm} 7, \\hspace{1mm} -5, \\hspace{1mm} 31, \\hspace{1mm} 59, \\hspace{1mm} -40, \\hspace{1mm} 8, \\hspace{1mm} 10, \\hspace{1mm}-26), \\\\ \\vspace{1mm} \\hspace{2mm} \\mathbf{v}_{4} & \\hspace{1mm} = & \\hspace{1mm} (5, \\hspace{1mm} 0, \\hspace{1mm} -6, \\hspace{1mm} 20, \\hspace{1mm} 7, \\hspace{1mm} 3, \\hspace{1mm} -10, \\hspace{1mm} 16, \\hspace{1mm} 10, \\hspace{1mm} -62). \\end{array}\r\n\\end{displaymath}\r\nUse Algorithm $1$ in Section $7.6$ to find a subset of these vectors that forms a basis for span$\\{\\mathbf{v}_{1}, \\mathbf{v}_{2}, \\mathbf{v}_{3}, \\mathbf{v}_{4}\\}$, and express those vectors not in the basis as linear combinations of basis vectors.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\r\n\\begin{verbatim}\r\n\r\nv1 = [1 2 4 -6 11 23 -14 0 2 2]';\r\nv2 = [3 1 -1 7 9 13 -12 8 6 -30]';\r\nv3 = [5 5 7 -5 31 59 -40 8 10 -26]';\r\nv4 = [5 0 -6 20 7 3 -10 16 10 -62]';\r\n\r\n% Construct A whose column space is W=span(v1,v2,v3,v4).\r\nA = [v1 v2 v3 v4];\r\n\r\n% Find the reduced row echelon form R of A and the pivot columns of A.\r\n[R, pivotcols] = rref(A);\r\n\r\nformat short;\r\n\r\ndisp('The pivot columns of the reduced row echelon form of A are');\r\ndisp(pivotcols);\r\n\r\n% From the result, the leading 1's in R occur in columns 1 and 2.\r\n% (i.e., the pivot columns of A are 1 and 2.)\r\n% Hence, the basis vectors for W are v1 and v2.\r\n\r\ndisp('The reduced row echelon form R of A is'); disp(R);\r\n\r\n% Furthermore, from the reduced row echelon form R of A,\r\n% we can see that v3 = 2*v1 + v2, and v4 = -v1 + 2*v2.\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe pivot columns of the reduced row echelon form of A are\r\n     1     2\r\n\r\nThe reduced row echelon form R of A is\r\n     1     0     2    -1\r\n     0     1     1     2\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     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\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\r\n\r\n\\begin{exer}(\\textit{Finding Bases for the Fundamental Spaces})\\\\\r\nConsider the matrix\r\n\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} 1& \\hspace{5mm} 3& \\hspace{5mm} 2&\\hspace{5mm} 1\\\\ -2 & -6 & 0 & -6 \\\\ 3 & 9 & 1 & 8 \\\\ -1 & -3 & -3 & -6 \\\\ 1 & 3 & 2 & 1 \\\\ 4 & 12 & 1 & 11 \\end{array} \\right].\r\n\\end{displaymath}\r\n\r\n\\begin{enumerate}\r\n\r\n\\item[(a)] Use Algorithm 1 in Section 7.6 to find a subset of the column vectors of $A$ that forms a basis for the column space of $A$, and express each column vector of $A$ that is not in that basis as a linear combination of the basis vectors.\r\n\r\n\\vspace{2mm}\r\n\r\n\\item[(b)] Use Algorithm 2 in Section 7.6 to find a basis for the null space of the matrix $A^{T}$.\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nA = [1 3 2 1; -2 -6 0 -6; 3 9 1 8; -1 -3 -3 -6; 1 3 2 1; 4 12 1 11];\r\n\r\n% Find the reduced row echelon form R of A and the pivot columns of A.\r\n[R, pivotcols] = rref(A);\r\n\r\nformat short;\r\n\r\ndisp('The pivot columns of the reduced row echelon form of A are');\r\ndisp(pivotcols);\r\n% From the result, the leading 1's in R occur in columns 1, 3, and 4.\r\n% (i.e., the pivot columns of A are 1, 3, and 4.)\r\n% Hence, the columns 1, 3, and 4 of A are a basis for the column space of A.\r\n\r\ndisp('The reduced row echelon form R of A is'); disp(R);\r\n% Furthermore, from the reduced row echelon form R of A,\r\n% we can see that v2 = 3*v1, where v1 = A(:, 1), and v2 = A(:, 2).\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe pivot columns of the reduced row echelon form of A are\r\n     1     3     4\r\n\r\nThe reduced row echelon form R of A is\r\n     1     3     0     0\r\n     0     0     1     0\r\n     0     0     0     1\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\\end{sol}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n% 7.7\r\n\\section{The Projection Theorem and Its Implications}\r\n\r\n\r\n\\begin{exer}(\\textit{Standard Matrix for an Orthogonal Projection})\\\\\r\nOne way to find the standard matrix for the orthogonal projection onto a subspace $W$ spanned by a set of vectors $\\{\\mathbf{v}_{1}, \\mathbf{v}_{2}, ..., \\mathbf{v}_{k}\\}$ is first to find a basis for $W$, then create a matrix $A$ that has the basis vectors as columns, and then use the Formula (27) in the Section 7.7.\r\n\r\n\\vspace{2mm}\r\n\r\n\\begin{enumerate}\r\n\r\n\\item[(a)] Find the standard matrix for the orthogonal projection of $\\mathbb{R}^{4}$ onto the subspace $W$ spanned by\r\n\r\n\\begin{displaymath}\r\n\\begin{array}{ll} \\vspace{1mm} \\mathbf{v}_{1} = (1, \\hspace{1mm} 2, \\hspace{1mm} 3, \\hspace{1mm} -4), & \\hspace{2mm} \\mathbf{v}_{2} = (2, \\hspace{1mm}3, \\hspace{1mm} -4, \\hspace{1mm} 1), \\\\ \\vspace{1mm} \\mathbf{v}_{3} = (2, \\hspace{1mm} -5, \\hspace{1mm} 8, \\hspace{1mm} -3), & \\hspace{2mm} \\mathbf{v}_{4} = (5, \\hspace{1mm} 26, \\hspace{1mm} -9, \\hspace{1mm} -12), \\\\ \\vspace{1mm} \\mathbf{v}_{5} = (3, \\hspace{1mm} -4, \\hspace{1mm} 1, \\hspace{1mm} 2). \\end{array}\r\n\\end{displaymath}\r\n\r\n\\vspace{1mm}\r\n\r\n\\item[(b)] Use the matrix obtained in part (a) to find $\\mathrm{proj}_{\\tiny{W}} \\mathbf{x}$, where $\\mathbf{x} = (1, \\hspace{1mm} 0, \\hspace{1mm} -3, \\hspace{1mm} 7)$.\r\n\r\n\\vspace{3mm}\r\n\r\n\\item[(c)] Find $\\mathrm{proj}_{\\tiny{W^{\\perp}}} \\mathbf{x}$ for the vector in part (b).\r\n\r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nv1 = [1 2 3 -4]'; v2 = [2 3 -4 1]'; v3 = [2 -5 8 -3]';\r\nv4 = [5 26 -9 -12]'; v5 = [3 -4 1 2]';\r\n\r\n% Set A that has v1,v2,v3,v4 and v5, as column vectors.\r\nA = [v1 v2 v3 v4 v5]; \r\n\r\n% Find the reduced row echelon form R of A and the pivot columns of A.\r\n[R, pivotcols] = rref(A);\r\n\r\n% M is the matrix whose columns are a basis for the column space of A.\r\nM = A(:, pivotcols);\r\n\r\n% By (27) in section 7.7, find the standard matrix.\r\nP = M * inv(M'* M) * M';\r\n\r\nformat short;\r\ndisp('The standard matrix for the orthogonal projection of R^4 onto W=col(A) is');\r\ndisp(P);\r\n\r\nx = [1 0 -3 7]'; \r\nxproj = P*x; \r\nxperp = x - xproj;\r\ndisp('The projection of x onto W=col(A) is'); disp(xproj');\r\n\r\ndisp('The projection of x onto the orthogonal complement of W=col(A) is');\r\ndisp(xperp');\r\n\r\n% As a check, the dot product of the two projections should be zero.\r\ndisp('The dot product of the two projections is'); disp(dot(xproj, xperp));\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe standard matrix for the orthogonal projection of R^4 onto W=col(A) is\r\n    0.9992   -0.0144   -0.0161   -0.0195\r\n   -0.0144    0.7551   -0.2737   -0.3314\r\n   -0.0161   -0.2737    0.6941   -0.3703\r\n   -0.0195   -0.3314   -0.3703    0.5517\r\n\r\nThe projection of x onto W=col(A) is\r\n    0.9110   -1.5127   -4.6907    4.9534\r\n\r\nThe projection of x onto the orthogonal complement of W=col(A) is\r\n    0.0890    1.5127    1.6907    2.0466\r\n\r\nThe dot product of the two projections is\r\n -5.3291e-015\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\r\n% 7.8\r\n\\section{Best Approximation and Least Squares}\r\n\r\n\\begin{exer}\r\nMake a function file \\verb\"LinearSolver.m\" to find a least squares solution of $A\\mathbf{x}=\\mathbf{b}$ where $A$ has full column rank. Complete the missing part referring to the comments. Using this function file, solve the linear system\r\n$$\\begin{cases}\r\nx-y=4\\\\\r\n3x+2y=1\\\\\r\n-2x+4y=3\r\n\\end{cases}\r\n$$\r\nand compare the output with the result of the MATLAB syntax $A\\backslash \\mathbf{b}$.\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n%--- This is a function file 'LinearSolver.m' ---%\r\nfunction [rank_A sol]=LinearSolver(A, b)\r\n  [m,n]=size(A);\r\n  rank_A=rank(A);\r\n    \r\n  % Check that A has full column rank.   \r\n  if rank_A<n\r\n    fprintf('rank(A)=%d < %d  -> Not full column rank\\n', rank_A, n);\r\n    return; % If A does not have full column rank, then return.\r\n  else \r\n    fprintf('rank(A)=%d = %d -> Full column rank\\n', rank_A, n);\r\n  end\r\n   \r\n  % From the reduced row echelon form of [A'*A |A'*b],\r\n  % find a solution to the normal equation A'Ax=A'b.\r\n\r\n  Aug=[A'*A A'*b]; \r\n  rref_Aug=rref(Aug);\r\n  sol=rref_Aug(:,n+1);\r\n  \r\n  fprintf('The least squares solution is');disp(sol');\r\nend\r\n\\end{verbatim}\r\n\r\nYou execute the followings:\r\n\\begin{verbatim}\r\nA=[1 -1; 3 2; -2 4];   \r\nb=[4; 1; 3];\r\nLinearSolver(A, b);\r\nA\\b\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nrank(A)=2 = 2 -> Full column rank\r\nThe least squares solution is    0.1789    0.5018\r\nans =\r\n    0.1789\r\n    0.5018\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}\r\nThe least squares method can be used to estimate the center $(h,k)$ of a circle $(x-h)^2+(y-k)^2=r^2$ using measured data points on its circumference. Suppose that the data points are\r\n$$(x_1, y_1), (x_2, y_2), \\cdots, (x_n, y_n)$$\r\nand rewrite the equation of the circle in the form\r\n\\begin{equation}\\label{eq1}\\centering  2xh+2yk+s=x^2+y^2\r\n\\end{equation}\r\nwhere\r\n\\begin{equation}\\label{eq2}\\centering s=r^2-h^2-k^2\\end{equation}\r\nSubstituting the data points in \\eqref{eq1} yields a linear system in the unknowns $h$, $k$, and $s$, which can be solved by least squares to estimate their values. Equation~\\eqref{eq2} can then be used to estimate $r$. Use this method to approximate the center and radius of a circle from the measured data points on the circumference given in the accompanying table.\r\n\r\n\\begin{table}[h]\r\n\\centering\r\n\\caption{Data points of Problem 7(b)}\r\n\\label{my-label}\r\n\\begin{tabular}{|l|l|l|l|l|l|l|l|}\r\n\\hline\r\n$\\mathbf{x}$ & 19.880 & 20.919 & 21.735 & 23.375 & 24.361 & 25.375 & 25.979 \\\\ \\hline\r\n$\\mathbf{y}$ & 68.874 & 67.676 & 66.692 & 64.385 & 62.908 & 61.292 & 60.277 \\\\ \\hline\r\n\\end{tabular}\r\n\\end{table}\r\nGraph the circle you obtained and plot the data points with red circles in the same figure.\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\nYou execute the followings:\r\n\\begin{verbatim}\r\nformat short;\r\n\r\n% given data\r\nx=[19.880 20.919 21.735 23.375 24.361 25.375 25.979]; \r\ny=[68.874 67.676 66.692 64.385 62.908 61.292 60.277];\r\n\r\n% number of data points.\r\n[m,n]=size(x);\r\n\r\n% construct the system matrix\r\nA=[2*x' 2*y' ones(n,1)]; b=x.^2+y.^2;\r\n\r\n% solve the normal equation\r\nhks=inv(A'*A)*A'*b'\r\nh=hks(1); k=hks(2); s=hks(3);\r\n\r\n% compute the radius\r\nr=sqrt(s+h^2+k^2);\r\n\r\nfigure; \r\ntheta=0:0.01:2*pi; \r\nxx=h+r*cos(theta); \r\nyy=k+r*sin(theta);\r\n\r\n% plot the obtained circle\r\nplot(xx,yy); \r\nhold on; \r\n\r\n% plot the data points\r\nplot(x, y, 'o');\r\n\\end{verbatim}\r\n\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nhks =\r\n  -18.3534\r\n   35.4513\r\n  986.5129\r\n\\end{verbatim}\r\n\\begin{figure}[h]\r\n\\centering\r\n\\includegraphics[width=9cm]{leastSq.jpg}\r\n\\end{figure}\r\n\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n% 7.9\r\n\\section{Orthonormal Bases and the Gram Schmidt Process}\r\n\r\n\\begin{exer} (\\textit{Gram-Schmidt Process})\\\\\r\nPerform the Gram-Schmidt process to transform the vectors given in the Example 9 of the Section 7.9 to obtain an orthonormal basis for $\\mathbb{R}^{3}$.\r\n\r\nIn this problem, use a nested loop and the MATLAB command \\textit{norm}.\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\nw1 = [1 1 1]'; w2 = [0 1 1]'; w3 = [0 0 1]';\r\nA = [w1 w2 w3]; % Construct a matrix A whose columns are w1, w2, and w3.\r\nformat short; [m, n] = size(A);\r\nQ = zeros(m, n); % Initialize the matrix Q as an m*n zero matrix.\r\n\r\n% Find an orthonormal basis for the column space of A.\r\nfor j = 1 : n\r\n    v = A(:, j); % v begins as jth column of A.\r\n    for i = 1 : (j-1)\r\n        temp = Q(:, i)' * A(:, j);\r\n        % Subtract each component of orthogonal projection of v\r\n        % onto the subspace spanned by the vector Q(:, i).\r\n        v = v - temp * Q(:, i);\r\n    end\r\n    Q(:, j) = v / norm(v); % Normalize v by its 2-norm.\r\nend\r\ndisp('The orthonormal basis {q1,q2,q3} for R^3 from {w1,w2,w3} are as follows:')\r\ndisp('q1='); disp(Q(:,1)'); disp('q2='); disp(Q(:,2)'); disp('q3='); disp(Q(:,3)');\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe orthonormal basis {q1,q2,q3} for R^3 from {w1,w2,w3} are as follows:\r\nq1=\r\n    0.5774    0.5774    0.5774\r\n\r\nq2=\r\n   -0.8165    0.4082    0.4082\r\n\r\nq3=\r\n   -0.0000   -0.7071    0.7071\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\r\n\\vspace{3mm}\r\n\\begin{exer}\\label{GS} (\\textit{Orthonormal Bases for the Four Fundamental Spaces})\\\\\r\nFind orthonormal bases for the four fundamental spaces of the matrix\r\n\r\n\r\n\\begin{displaymath}\r\nA = \\left[\\begin{array}{rrrr} 2& \\hspace{2mm} -1& \\hspace{5mm} 3&\\hspace{4mm} 5\\\\ 4 & -3 & 1 & 3 \\\\ 3 & -2 & 3 & 4 \\\\ 4 & -1 & 15 & 17 \\\\ 7 & -6 & -7 & 0  \\end{array} \\right].\r\n\\end{displaymath}\r\n\\end{exer}\r\n\r\n\\begin{sol}\r\n\r\n\\begin{verbatim}\r\n\r\n%--- The following is the function file 'GramSchmidt.m'. ---%\r\n\r\n% Find an orthonormal basis for col(A) when A has full column rank.\r\nfunction Q = GramSchmidt(A)\r\n\r\n  [m, n] = size(A);\r\n\r\n  % Initialize the matrix Q as an m*n zero matrix.\r\n  Q = zeros(m, n); \r\n\r\n  for j = 1 : n\r\n    % v begins as jth column of A.\r\n    v = A(:, j); \r\n    for i = 1 : (j-1)\r\n      temp = Q(:, i)' * A(:, j);\r\n      % Subtract each component of orthogonal projection of v\r\n      % onto the subspace spanned by the vector Q(:, i).\r\n      v = v - temp * Q(:, i);\r\n    end\r\n    Q(:, j) = v / norm(v); % Normalize v by its 2-norm.\r\n  end\r\nend\r\n% Q is an m*n matrix whose columns form an orthonormal basis for col(A).\r\n\\end{verbatim}\r\n\r\nThe following commands are performed in the command window of MATLAB.\r\n\r\n\\begin{verbatim}\r\nA = [2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0];\r\nformat short;\r\n\r\n% Find the reduced row echelon form of A.\r\nrref_A = rref(A); \r\n\r\n% (1). Find an orthonormal basis for the row space of A.\r\n% From the result of rref_A, the first three nonzero rows in rref_A form\r\n% a basis for the row space of A.\r\n\r\n% Construct a matrix R_A whose columns are a basis for the row space of A.\r\nR_A = rref_A(1:3, :)';\r\n\r\n% Find an orthonormal basis for the column space of R_A by Gram-Schmidt process,\r\n% which is the same as finding an orthonormal basis for the row space of A.\r\nOrth_R_A = GramSchmidt(R_A);\r\n\r\na1 = Orth_R_A(:, 1); a2 = Orth_R_A(:, 2); a3 = Orth_R_A(:, 3);\r\n\r\ndisp('An orthonormal basis {a1, a2, a3} for the row space of A is');\r\ndisp('a1 = '); disp(a1'); disp('a2 = '); disp(a2'); disp('a3 = '); disp(a3');\r\n\r\n% (2). Find an orthonormal basis for the column space of A.\r\n% From the result of rref_A, the first three columns of A are the pivot columns\r\n% which form a basis for the column space of A.\r\n\r\n% Construct a matrix C_A whose columns are a basis for the column space of A.\r\nC_A = A(:, 1:3);\r\n\r\n% Find an orthonormal basis for the column space of C_A by Gram-Schmidt process,\r\n% which is the same as finding an orthonormal basis for the column space of A.\r\nOrth_C_A = GramSchmidt(C_A);\r\n\r\nb1 = Orth_C_A(:, 1); b2 = Orth_C_A(:, 2); b3 = Orth_C_A(:, 3);\r\n\r\ndisp('An orthonormal basis {b1, b2, b3} for the column space of A is');\r\ndisp('b1 = '); disp(b1'); disp('b2 = '); disp(b2'); disp('b3 = '); disp(b3');\r\n\r\n\r\n% (3). Find an orthonormal basis for the null space of A.\r\n% In addition, from the result of rref_A,\r\n% we can easily see that {[-6 -7 0 1]'} is a basis for N(A).\r\n\r\n% Construct a matrix N_A whose columns are a basis for the null space of A.\r\nN_A = [-6 -7 0 1]';\r\n\r\n% Find an orthonormal basis for the column space of N_A by Gram-Schmidt process,\r\n% which is the same as finding an orthonormal basis for the null space of A.\r\nOrth_N_A = GramSchmidt(N_A);\r\n\r\nc1 = Orth_N_A(:, 1);\r\ndisp('An orthonormal basis {c1} for the null space of A is');\r\ndisp('c1 = '); disp(c1');\r\n\r\n% (4). Find an orthonormal basis for the null space of A transpose.\r\n[L U P] = lu(A);\r\ntemp = [0 0 0 0 1]';\r\n\\% Make L a square matrix of order 5.\r\nL = [L temp]; \r\n\r\n% Make U have the same size of A.\r\nU(5, :) = 0; \r\n\r\n% Then, we have P*A = L*U, which is the same result as above.\r\n% Note that L^(-1)*P*A = U, where U is an upper triangular matrix.\r\n\r\nE = L^(-1)*P;\r\n\r\n% Since E = L^(-1)*P is a product of elementary matrices s.t. E*A=U,\r\n% E represents a set of elementary row operations\r\n% that makes A become a row echelon form U.\r\n\r\n% ref_par_A is the resulting partitioned matrix [U E].\r\nref_par_A = [U E]; \r\n\r\n% From the result of ref_par_A, we can see that ref_par_A([4:5], [1:4]) = 0.\r\n% Thus, the row vectors of E2 form a basis for null(A'),\r\n% where E2 = ref_par_A([4:5], [5:9]).\r\n\r\n% Construct a matrix N_Atrans whose columns are a basis for\r\n% the null space of A transpose.\r\nN_Atrans = ref_par_A(4:5, 5:9)';\r\n\r\n% Find an orthonormal basis for the column space of N_Atrans by Gram-Schmidt process,\r\n% which is the same as finding an orthonormal basis for the null space of A transpose.\r\nOrth_N_Atrans = GramSchmidt(N_Atrans);\r\n\r\nd1 = Orth_N_Atrans(:, 1); d2 = Orth_N_Atrans(:, 2);\r\ndisp('An orthonormal basis {d1, d2} for the null space of the transpose of A is');\r\ndisp('d1 = '); disp(d1'); disp('d2 = '); disp(d2');\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nAn orthonormal basis {a1, a2, a3} for the row space of A is\r\na1 =\r\n    0.1644         0         0    0.9864\r\n\r\na2 =\r\n   -0.7446    0.6559         0    0.1241\r\n\r\na3 =\r\n     0     0     1     0\r\n\r\nAn orthonormal basis {b1, b2, b3} for the column space of A is\r\nb1 =\r\n    0.2063    0.4126    0.3094    0.4126    0.7220\r\n\r\nb2 =\r\n    0.1873   -0.0887    0.0493    0.8378   -0.5027\r\n\r\nb3 =\r\n   -0.3699    0.5812    0.5878   -0.1321   -0.4029\r\n\r\nAn orthonormal basis {c1} for the null space of A is\r\nc1 =\r\n   -0.6470   -0.7548         0    0.1078\r\n\r\nAn orthonormal basis {d1, d2} for the null space of the transpose of A is\r\nd1 =\r\n    0.8649    0.3089         0   -0.3089   -0.2471\r\n\r\nd2 =\r\n    0.1936   -0.6234    0.7458   -0.1224    0.0512\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n\r\n\r\n\r\n\r\n\r\n\r\n% section 7.10\r\n\r\n\r\n\\section{$QR-$Decomposition; Householder Transformations}\r\n\r\n\r\n\\begin{exer}(\\textit{$QR-$Decomposition})\\\\\r\n\\begin{enumerate}\r\n\\item[(a)] Make a function file \\verb\"myQR.m\" to find a $QR$-decomposition of a given matrix. \r\nYou may use your function file \\verb\"GS_process.m\" from the \\textbf{Exercise}~\\ref{GS}.\r\n\\vspace{1mm}\r\n\\item[(b)] $$A=\\begin{bmatrix} 1 & 1 & 1\\\\ 1& 0 & 2\\\\ 0 & 1& 2\\end{bmatrix}.$$\r\nCompare your result with the output produced by the MATLAB command \\textit{qr}. \r\n\\end{enumerate}\r\n\\end{exer}\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\n%(a)\r\n%--- This is a function file myQR.m ---%\r\n\r\nfunction [Q R]=myQR(A)\r\n Q=GS_process(A);\r\n R=Q'*A;\r\nend\r\n\r\n%(b)\r\nA=[1 1 1; 1 0 2; 0 1 2];\r\n[Q1 R1]=myQR(A); [Q R]=qr(A);\r\n\r\ndisp('my QR result'); disp('Q');disp(Q1); disp('R');disp(R1);\r\ndisp('MATLAB QR result'); disp('Q');disp(Q); disp('R');disp(R);\r\n\\end{verbatim}\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nmy QR result\r\nQ\r\n    0.7071    0.4082   -0.5774\r\n    0.7071   -0.4082    0.5774\r\n         0    0.8165    0.5774\r\nR\r\n    1.4142    0.7071    2.1213\r\n    0.0000    1.2247    1.2247\r\n    0.0000   -0.0000    1.7321\r\n\r\nMATLAB QR result\r\nQ\r\n   -0.7071    0.4082   -0.5774\r\n   -0.7071   -0.4082    0.5774\r\n         0    0.8165    0.5774\r\nR\r\n   -1.4142   -0.7071   -2.1213\r\n         0    1.2247    1.2247\r\n         0         0    1.7321\r\n\\end{verbatim}\r\n\r\n\\end{outputs}\r\n\r\n\r\n\\noindent The results are the same.\r\n\\end{sol}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n% 7.11\r\n\r\n\\section{Coordinates with Respect to a Basis}\r\n\r\n\\begin{exer} (\\textit{Transition Matrices between Two Different Bases})\\\\\r\n\r\n\\begin{enumerate}\r\n\r\n\\item[(a)] Confirm that $B_{1} = \\{\\mathbf{u}_{1}, \\mathbf{u}_{2}, \\mathbf{u}_{3}, \\mathbf{u}_{4}, \\mathbf{u}_{5}\\}$ and $B_{2} = \\{\\mathbf{v}_{1}, \\mathbf{v}_{2}, \\mathbf{v}_{3}, \\mathbf{v}_{4}, \\mathbf{v}_{5}\\}$ are bases for $\\mathbb{R}^{5}$, and find the transition matrices $P_{\\tiny{B_{1} \\rightarrow B_{2}}}$ and $P_{\\tiny{B_{2} \\rightarrow B_{1}}}$, where\r\n\r\n\\begin{displaymath}\r\n\\begin{array}{lllllll}\r\n\\vspace{1mm} \\mathbf{u}_{1} & = & (3, \\hspace{1mm} 1, \\hspace{1mm} 3, \\hspace{1mm} 2, \\hspace{1mm} 6) & \\hspace{4mm} & \\mathbf{v}_{1} & = & (2, \\hspace{1mm} 6, \\hspace{1mm} 3, \\hspace{1mm} 4, \\hspace{1mm} 2) \\\\ \\vspace{1mm} \\mathbf{u}_{2} & = & (4, \\hspace{1mm} 5, \\hspace{1mm} 7, \\hspace{1mm} 2, \\hspace{1mm} 4) & \\hspace{4mm} & \\mathbf{v}_{2} & = & (3, \\hspace{1mm} 1, \\hspace{1mm} 5, \\hspace{1mm} 8, \\hspace{1mm} 3) \\\\ \\vspace{1mm} \\mathbf{u}_{3} & = & (3, \\hspace{1mm} 2, \\hspace{1mm} 1, \\hspace{1mm} 5, \\hspace{1mm} 4) & \\hspace{4mm} & \\mathbf{v}_{3} & = & (5, \\hspace{1mm} 1, \\hspace{1mm} 2, \\hspace{1mm} 6, \\hspace{1mm} 7) \\\\ \\vspace{1mm} \\mathbf{u}_{4} & = & (2, \\hspace{1mm} 9, \\hspace{1mm} 1, \\hspace{1mm} 4, \\hspace{1mm} 4) & \\hspace{4mm} & \\mathbf{v}_{4} & = & (8, \\hspace{1mm} 4, \\hspace{1mm} 3, \\hspace{1mm} 2, \\hspace{1mm} 6) \\\\ \\vspace{1mm} \\mathbf{u}_{5} & = & (3, \\hspace{1mm} 3, \\hspace{1mm} 6, \\hspace{1mm} 6, \\hspace{1mm} 7) & \\hspace{4mm} & \\mathbf{v}_{5} & = & (5, \\hspace{1mm} 5, \\hspace{1mm} 6, \\hspace{1mm} 3, \\hspace{1mm} 4) \\\\\r\n\\end{array}\r\n\\end{displaymath}\r\n\r\n\r\n\r\n\\item[(b)] Find the coordinate matrices with respect to $B_{1}$ and $B_{2}$ of $\\mathbf{w} = (1, \\hspace{1mm} 1, \\hspace{1mm} 1, \\hspace{1mm} 1, \\hspace{1mm} 1)$.\r\n\r\n\\end{enumerate}\r\n\r\n\\end{exer}\r\n\r\n\r\n\r\n\\begin{sol}\r\n\\begin{verbatim}\r\n\r\nu1 = [3 1 3 2 6]'; v1 = [2 6 3 4 2]';\r\nu2 = [4 5 7 2 4]'; v2 = [3 1 5 8 3]';\r\nu3 = [3 2 1 5 4]'; v3 = [5 1 2 6 7]';\r\nu4 = [2 9 1 4 4]'; v4 = [8 4 3 2 6]';\r\nu5 = [3 3 6 6 7]'; v5 = [5 5 6 3 4]';\r\n\r\nU = [u1 u2 u3 u4 u5]; \r\nV = [v1 v2 v3 v4 v5]; \r\n\r\nformat short;\r\n\r\n% Initialization.\r\nP_B1B2 = zeros(5); \r\nP_B2B1 = zeros(5); \r\n\r\nfor j = 1:5\r\n  % Find the coordinate vector of U(:, j) in B1 with respect to B2.\r\n  P_B1B2(:, j) = V\\U(:, j);\r\n  % Find the coordinate vector of V(:, j) in B2 with respect to B1.\r\n  P_B2B1(:, j) = U\\V(:, j);\r\nend\r\n\r\ndisp('The transition matrix from B1 to B2 is'); disp(P_B1B2);\r\ndisp('The transition matrix from B2 to B1 is'); disp(P_B2B1);\r\n\r\nw = [1 1 1 1 1]';\r\n\r\n% Find the coordinate matrix of w with respect to B1.\r\nw_B1 = U\\w; \r\n\r\n% Find the coordinate matrix of w with respect to B2.\r\nw_B2 = P_B1B2 * w_B1; \r\n\r\ndisp('The coordinate matrix of w with respect to B1 is'); disp(w_B1');\r\ndisp('The coordinate matrix of w with respect to B2 is'); disp(w_B2');\r\n\\end{verbatim}\r\n\r\n\r\n\\begin{outputs}\r\n\\begin{verbatim}\r\n\r\nThe transition matrix from B1 to B2 is\r\n   -0.4992   -0.2531    0.4843    1.8286   -0.2123\r\n   -0.7830   -0.3679    0.1604   -0.8019   -0.5849\r\n    1.3019    0.2925    0.4623    0.6887    1.4906\r\n   -0.9096   -0.6116    0.1918   -0.2091   -1.4104\r\n    1.4230    1.8082   -0.4591   -0.2044    1.8019\r\n\r\nThe transition matrix from B2 to B1 is\r\n   -0.6889   -1.3556    0.6222    1.2667   -0.0444\r\n    0.4067    0.3591    0.0278    1.2083    1.0873\r\n    0.3151    1.2675    1.3444    1.6833    0.6540\r\n    0.3615   -0.5433   -0.2056   -0.1417   -0.0746\r\n    0.2571    0.9714   -0.2000   -1.8000   -0.3429\r\n\r\nThe coordinate matrix of w with respect to B1 is\r\n   -0.0222    0.1508    0.1841   -0.0016   -0.0286\r\n\r\nThe coordinate matrix of w with respect to B2 is\r\n    0.0653    0.0094    0.0566    0.0039    0.1053\r\n\\end{verbatim}\r\n\\end{outputs}\r\n\r\n\\end{sol}\r\n", "meta": {"hexsha": "791b0f82efab72fc2af9465f3b329e464044f707", "size": 47115, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_codes/intro/Learning MATLAB with Linear Algebra (Jeon, Lee)/section7.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)/section7.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)/section7.tex", "max_forks_repo_name": "mireiffe/mas109_matlab_2021_2", "max_forks_repo_head_hexsha": "f955eb2789b463d8cffbfbbb321bcd057d32933a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.9904519414, "max_line_length": 1055, "alphanum_fraction": 0.5773532845, "num_tokens": 17394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564154, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.789431569303427}}
{"text": "\\section{Integer Linear Programming}\n\nInteger Linear Program (ILP): $max\\{c^Tx:x \\in P  \\cap Z^n\\}$ with $P = \\{x \\in R^n : Ax \\leq b\\}$ \\\\\n\\textit{All variables are integer}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/integerlp.png}\n\\caption{ILP}\n\\end{figure}\n\nMixed Integer LP (MIP): $max\\{c^T x:x\\in P \\cap Z_K^n\\}$ with $P = \\{x \\in R^n : Ax \\leq b\\}$ where $K  \\subseteq \\{1, ..., n\\}$ and $Z_K^n = \\{x \\in R^n : x_j \\in Z$ for $j \\in K\\}$ \\\\\n\\textit{Some variables are integer, others are not}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/mlp.png}\n\\caption{MIP}\n\\end{figure}\n\nIt is not possible to just run a linear programming algorithm and then round the result up or down. \n\\begin{itemize}\n    \\item Problem 1: Rounding the LP Solution may yield a non-feasible solution.\n    \\item Problem 2: The optimal LP Solution is maybe far away from the optimal ILP solution.\n\\end{itemize}\n\n\\clearpage\n\n\\subsection{Relaxations}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.5\\textwidth]{figures/relaxations.png}\n\\caption{Relaxations}\n\\end{figure}\n\n$\\Rightarrow f'(x)$ need to be higher or equal to $f(x)$ within the solution space.\n\n\\subsection{Branch and Bound Method}\nBranch-and-Bound (B\\&B) is a general solution method (independent from ILP). \n\nBasic Procedure\n\\begin{enumerate}\n    \\item Split solution space iteratively into smaller subspaces (\"Branch\"). In each subproblem:\n    \\item Calculate an upper bound (\"Bound\") e.g. through relaxation\n    \\item Calculate a feasible solution $\\Rightarrow$ Lower Bound (\"Bound\").\n    \\item Then use this information to \"cut away\" (\"prune\") certain subproblems.\n\\end{enumerate}\n\n\\clearpage\n\\subsubsection{Himmalaya Example}\n\n\\begin{itemize}\n    \\item We seperate the full solution space in several subspaces\n    \\item We send some helicopters to find the upper bound of these subspaces\n    \\item From the bottom, there are searching some sherpas for the lower bound\n    \\item At the end, we compare the values we got from each subspace.\n\\end{itemize}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/himmalayaExample.png}\n\\caption{Branch and Bound - Himmalaya Example}\n\\end{figure}\n\n\\begin{itemize}\n    \\item Stopping by Dominance means, that the upper bound is already lower than an already found maximum in the queue.\n    \\item Stopping by Optimum means, that we found the optimum in this area (upper and lower bound are the same).\n\\end{itemize}\n\n\\clearpage\n\\subsubsection{Knap-Sack Problem Example}\n\n\\begin{itemize}\n    \\item Items $j \\in J$ have a volume $a_j$ and a benefit $c_j$.\n    \\item The knapsack has a capacity of $b$\n    \\item $max\\{c^Tx:a^Tx\\leq b, x \\in \\{0,1\\}^j\\}$\n\\end{itemize}\nLP Solution easy:\n\\begin{enumerate}\n    \\item Sort the items by decreasing benefit per volume $\\frac{c_j}{a_j}$\n    \\item Choose items in this order, until the knapsack is full. The last item fractionally. \n    \\item After doing this, create two new branches. One branch with $x = 0$ for the fractional item and one branch with $x = 1$ for the fractional item. Continue until you discovered all options. \n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/bbknapsack.png}\n\\caption{Branch and Bound - Knapsack Example}\n\\end{figure}\n\n\\clearpage\n\n\\subsection{Cutting Plane Method}\n\n\\begin{itemize}\n    \\item Let $P$ and $P'$ be two formulations for the ILP: $max\\{c^Tx:x\\in P \\subseteq Z^n\\}$. $P'$ is called a better solution is $P' \\subseteq P$.\n    \\item And if $P' \\subseteq P$ then $max\\{c^Tx:x \\in P'\\} \\leq max\\{c^Tx:x \\in P\\}$\n\\end{itemize}\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.4\\textwidth]{figures/optimalilpsolution.png}\n\\caption{Cutting Plane Method - Optimal ILP Solution}\n\\end{figure}\n\n\\textbf{The best formulation for $P'$} would be the convex hull, which is the thightest polyhedrun around $P$, but this is nearly impossible to find. \n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{figures/convexhull.png}\n\\caption{Cutting Plane Method - Behavior Convex Hull}\n\\end{figure}\n\n\\textbf{The integer hull of a polyhedrun is the convex hull, but only with integers.}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/cuttingplanemethod.png}\n\\caption{Cutting Plane Method}\n\\end{figure}\n\n\\subsubsection{Gomory-Chvatal-Cut}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/gomory.png}\n\\caption{Gomory-Chvatal-Cut}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "dacd6ded3d52d25ff9a61195679aae9d53a05c50", "size": 4508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FTP_Optimiz/04_integerLp.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/04_integerLp.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/04_integerLp.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.1515151515, "max_line_length": 197, "alphanum_fraction": 0.7300354925, "num_tokens": 1360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8962513731336204, "lm_q1q2_score": 0.7894155905897576}}
{"text": "\n\\subsection{Indifference curves}\n\n\\subsubsection{Marginal rate of substitution}\n\nWe can consider how much of one good a consumer is willing to give up to get one of another.\n\nConsider the utility function:\n\n\\(U=f(x,y)\\)\n\nWe can examine the change in utility following changes in inputs by taking the total differential.\n\n\\(dU=\\dfrac{\\delta f}{\\delta x}dx+\\dfrac{\\delta f}{\\delta y}dy\\)\n\nWe want to examine changes where \\(dU\\) is \\(0\\), so:\n\n\\( \\dfrac{\\delta f}{\\delta x}dx+\\dfrac{\\delta f}{\\delta y}dy=0\\)\n\n\\( \\dfrac{\\delta f}{\\delta x}dx+\\dfrac{\\delta f}{\\delta y}dy=0\\)\n\n\\( MU_xdx+MU_ydy=0\\)\n\n\\( \\dfrac{dy}{dx}=-\\dfrac{MU_x}{MU_y}\\)\n\nThis is the form of the indifference curve.  We refer to \\(\\dfrac{MU_x}{MU_y}\\) as the marginal rate of substitution.\n\nADD GRAPH TO SHOW\n\n\\subsubsection{Multiple choices}\n\nIf the set of choices is more complex, say there are now apples and bananas, we have to be more careful with a representative function.\n\nThe agent still prefers more apples and more bananas, but the following imply different choices:\n\n\\(f=x^2.y^2\\)\n\n\\(f=ln(x)+ln(y)\\)\n\nIn the first example, the agent would always swap an apple for a banana, if they had more apples, whereas the opposite is true in the second case. Functional form is important with multiple goods.\n\n\\subsubsection{Solving}\n\n", "meta": {"hexsha": "a7341951bf88ce8b04b0cb1388a97add8e035896", "size": 1302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/singleAgent/04-01-RnIndifferenceCurves.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/04-01-RnIndifferenceCurves.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/04-01-RnIndifferenceCurves.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.5909090909, "max_line_length": 196, "alphanum_fraction": 0.7258064516, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7892634282413471}}
{"text": "\n\\subsection{Linear second-order Ordinary Differential Equations}\n\nThese are of the form\n\n\\(\\dfrac{d^2y}{dt^2}+p(t)\\dfrac{dy}{dt}+q(t)y=g(t)\\)\n\nThere are two types. Homogenous equations are where \\(g(t)=0\\). Otherwise they are heterogenous.\n\nWe explore the case with constants:\n\n\\(a\\dfrac{d^2y}{dt^2}+b\\dfrac{dy}{dt}+cy=0\\)\n\n\n", "meta": {"hexsha": "e2737cd30b58911ac33aecdd41e656d43d692cab", "size": 326, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/ODE/03-01-linearSecondODE.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/ODE/03-01-linearSecondODE.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/ODE/03-01-linearSecondODE.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.7333333333, "max_line_length": 96, "alphanum_fraction": 0.6993865031, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9546474194456936, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7892182808348881}}
{"text": "\\chapter{Elemental matrices}\n\n\\section{Deformation modes of four-nodes finite elements}\n\n\\subsection{Plane stress}\nFor plane-stress conditions the stiffness matrix of a four-nodes element reads\n\\begin{equation}\n  K = \\frac{E}{24(1 - \\nu^2)} \\hat{K}\n\\end{equation}\nwith\n\\begin{equation}\n  \\hat{K} = \n  \\begin{bmatrix}\n    12 - 4\\nu & 3 \\nu + 3 & - 2 \\nu - 6 & 9 \\nu - 3 & 2 \\nu - 6 & - 3 \\nu - 3 & 4 \\nu & 3 - 9\\nu\\\\\n    3 \\nu + 3 & 12 - 4\\nu & 3 - 9\\nu & 4 \\nu & - 3 \\nu - 3 & 2 \\nu - 6 & 9 \\nu - 3 & - 2 \\nu - 6\\\\\n    - 2 \\nu - 6 & 3 - 9\\nu & 12 - 4\\nu & - 3 \\nu - 3 & 4 \\nu & 9 \\nu - 3 & 2 \\nu - 6 & 3 \\nu + 3\\\\\n    9 \\nu - 3 & 4 \\nu & - 3 \\nu - 3 & 12 - 4\\nu & 3 - 9\\nu & - 2 \\nu - 6 & 3 \\nu + 3 & 2 \\nu - 6\\\\\n    2 \\nu - 6 & - 3 \\nu - 3 & 4 \\nu & 3 - 9\\nu & 12 - 4\\nu & 3 \\nu + 3 & - 2 \\nu - 6 & 9 \\nu - 3\\\\\n    - 3 \\nu - 3 & 2 \\nu - 6 & 9 \\nu - 3 & - 2 \\nu - 6 & 3 \\nu + 3 & 12 - 4\\nu & 3 - 9\\nu & 4 \\nu\\\\\n    4 \\nu & 9 \\nu - 3 & 2 \\nu - 6 & 3 \\nu + 3 & - 2 \\nu - 6 & 3 - 9\\nu & 12 - 4\\nu & - 3 \\nu - 3\\\\\n    3 - 9\\nu & - 2 \\nu - 6 & 3 \\nu + 3 & 2 \\nu - 6 & 9 \\nu - 3 & 4 \\nu & - 3 \\nu - 3 & 12 - 4\\nu\n  \\end{bmatrix} .\n  \\label{eq:stiff}\n\\end{equation}\n\nThe characteristic polynomial is given by\n\\[\\det(K - \\lambda I)= 0\\enspace ,\\]\nor\n\\begin{equation}\n  \\frac{\\lambda^3(E - \\lambda\\nu - \\lambda)^2 (E + \\lambda \\nu - \\lambda) (\\nu E - 3E - 6\\nu^2\\lambda + 6\\lambda)^2}{36 (\\nu - 1)^3 (1 + \\nu)^4} = 0 \\enspace .\n\\end{equation}\n\nWhat gives as eigenvalues\n\\[\\lambda \\in \\left\\{0,\n\t\\frac{E(3 - \\nu)}{6(1 - \\nu^2)},\n\t\\frac{E}{1 + \\nu},\n\t\\frac{E}{1 - \\nu} \\right\\} \\enspace .\n\\]\n\nAnd the corresponding eigenvectors are\n\\begin{equation}\n\\begin{array}{ll}\n\\lambda_1 = 0, \n\t&u^{(1)} = (1, 0, 1, 0, 1, 0, 1, 0)\\\\\n\t&u^{(2)} = (0, 1, 0, 1, 0, 1, 0, 1)\\\\\n\t&u^{(3)} = (0, 1, 0, -1, 2, -1, 2, 1)\\\\\n\\lambda_2 = \\frac{E(3 - \\nu)}{6(1 - \\nu^2)}, \n\t&u^{(4)} = (1, 0, -1, 0, 1, 0, -1, 0)\\\\\n\t&u^{(5)} = (0, 1, 0, -1, 0, 1, 0, -1)\\\\\n\\lambda_3 = \\frac{E}{1 + \\nu}, \n\t&u^{(6)} = (1, 0, 0, -1, -1, 0, 0, 1)\\\\\n\t&u^{(7)} = (0, 1, 1, 0, 0, -1, -1, 0)\\\\\n\\lambda_4 = \\frac{E}{1 - \\nu}, \n\t&u^{(8)} = (1, 1, -1, 1, -1, -1, 1, -1)\n\\end{array}\n\\end{equation}\n\n\\subsection{Plane strain}\nIn the case of plane strain the stiffness matrix of a four-nodes element reads\n\\begin{equation}\n  K = \\frac{E}{24(1 - 2\\nu)(1 + \\nu)} \\hat{K}\n\\end{equation}\nwith\n\\begin{equation}\n  \\hat{K} = \n  \\begin{bmatrix}\n    12 - 16\\nu & 3 & 4 \\nu - 6 & 12 \\nu - 3 & 8 \\nu - 6 & -3 & 4 \\nu & 3 - 12\\nu\\\\\n    3 & 12 - 16\\nu & 3 - 12\\nu & 4 \\nu & -3 & 8 \\nu - 6 & 12 \\nu - 3 & 4 \\nu - 6\\\\4 \\nu - 6 & 3 - 12\\nu & 12 - 16\\nu & -3 & 4 \\nu & 12 \\nu - 3 & 8 \\nu - 6 & 3\\\\\n    12 \\nu - 3 & 4 \\nu & -3 & 12 - 16\\nu & 3 - 12\\nu & 4 \\nu - 6 & 3 & 8 \\nu - 6\\\\\n    8 \\nu - 6 & -3 & 4 \\nu & 3 - 12\\nu & 12 - 16\\nu & 3 & 4 \\nu - 6 & 12 \\nu - 3\\\\\n    -3 & 8 \\nu - 6 & 12 \\nu - 3 & 4 \\nu - 6 & 3 & 12 - 16\\nu & 3 - 12\\nu & 4 \\nu\\\\4 \\nu & 12 \\nu - 3 & 8 \\nu - 6 & 3 & 4 \\nu - 6 & 3 - 12\\nu & 12 - 16\\nu & -3\\\\\n    3 - 12\\nu & 4 \\nu - 6 & 3 & 8 \\nu - 6 & 12 \\nu - 3 & 4 \\nu & -3 & 12 - 16\\nu\n  \\end{bmatrix}\n\\end{equation}\n\nThe characteristic polynomial is given by\n\\begin{equation}\n  \\frac{\\lambda^3 (E - \\nu\\lambda - \\lambda)^2(E + 2\\nu^2\\lambda + \\nu\\lambda - \\lambda)(4\\nu E - 3E - 12\\nu^2\\lambda - 6\\nu\\lambda + 6\\lambda)^2}{36(\\nu + 1)^5\\ (2\\nu - 1)^3}=0 \\enspace .\n\\end{equation}\n\nWhat gives as eigenvalues\n\\[\\lambda \\in \\left\\{0,\n\t\\frac{E(3 - 4\\nu)}{6(1 - 2\\nu)(1 + \\nu)},\n\t\\frac{E}{1 + \\nu},\n\t\\frac{E}{(1 + \\nu)(1 - 2\\nu)} \\right\\} \\enspace .\n\\]\n\nAnd the corresponding eigenvectors are\n\\begin{equation}\n\\begin{array}{ll}\n\\lambda_1 = 0, \n\t&u^{(1)} = (1, 0, 1, 0, 1, 0, 1, 0)\\\\\n\t&u^{(2)} = (0, 1, 0, 1, 0, 1, 0, 1)\\\\\n\t&u^{(3)} = (0, 1, 0, -1, 2, -1, 2, 1)\\\\\n\\lambda_2 = \\frac{E(3 - 4\\nu)}{6(1 - 2\\nu)(1 + \\nu)}, \n\t&u^{(4)} = (1, 0, -1, 0, 1, 0, -1, 0)\\\\\n\t&u^{(5)} = (0, 1, 0, -1, 0, 1, 0, -1)\\\\\n\\lambda_3 = \\frac{E}{1 + \\nu}, \n\t&u^{(6)} = (1, 0, 0, -1, -1, 0, 0, 1)\\\\\n\t&u^{(7)} = (0, 1, 1, 0, 0, -1, -1, 0)\\\\\n\\lambda_4 = \\frac{E}{(1 + \\nu)(1 - 2\\nu)}, \n\t&u^{(8)} = (1, 1, -1, 1, -1, -1, 1, -1)\n\\end{array}\n\\end{equation}\n\nAs expected, the eigenvectors are the same while the eigenvalues differ.\n\n", "meta": {"hexsha": "5200b8af218faba3f9ebb2e142f0005f323f6c22", "size": 4133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/elem_matrices.tex", "max_stars_repo_name": "jomorlier/FEM-Notes", "max_stars_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-04-15T01:53:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-15T01:53:14.000Z", "max_issues_repo_path": "src/elem_matrices.tex", "max_issues_repo_name": "jomorlier/FEM-Notes", "max_issues_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/elem_matrices.tex", "max_forks_repo_name": "jomorlier/FEM-Notes", "max_forks_repo_head_hexsha": "3b81053aee79dc59965c3622bc0d0eb6cfc7e8ae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-25T17:19:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-25T17:19:53.000Z", "avg_line_length": 38.2685185185, "max_line_length": 188, "alphanum_fraction": 0.467457053, "num_tokens": 2307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474155747541, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7892182776347366}}
{"text": "\\lab{The Finite Difference Method}{The Finite Difference Method}\n\\label{lab:finitedifference2}\n\nA \\textbf{finite difference} for a function $f(x)$ is an expression of the form $f(x+s)-f(x+t)$.\nFinite differences can give a good approximation of derivatives.\n\nSuppose we have a function $u(x)$, defined on an interval $[a,b]$.\nLet $a = x_0, x_1, \\ldots x_{n-1}, x_n=b$ be a grid of $n+1$ evenly spaced points, with $x_{i+1}-x_i = h$, where $h = (b-a)/n$.\n\nYou are used to seeing the derivative $u'(x)$, which can written in centered-difference form as:\n\\begin{align*}\nu'(x)=\\lim_{h\\to\\infty}\\frac{u(x+h)-u(x-h)}{2h}.\n \\end{align*}\nSuppose we are interested in knowing the value of the derivative at the points $\\{x_i\\}$. Even if we don't have a formula for $u'(x)$, we can approximate it using finite differences.\nWe first write the Taylor polynomial expansion of $u(x+h)$ and $u(x-h)$ centered at $x$. This gives\n\n\\begin{align}\nu(x+h)=u(x)+u'(x)h+\\frac{1}{2}u''(x)h^2+\\frac{1}{6}u'''(x)h^3+\\mathcal{O}(h^4)\\label{plus}\\\\\nu(x-h)=u(x)-u'(x)h+\\frac{1}{2}u''(x)h^2-\\frac{1}{6}u'''(x)h^3+\\mathcal{O}(h^4)\\label{minus}\n\\end{align}\nSubtracting \\eqref{minus} from \\eqref{plus} and rearranging gives\n\\begin{align*}\nu'(x)=\\frac{u(x+h)-u(x-h)}{2h}+\\mathcal{O}(h^2).\n\\end{align*}\n\nIn terms of our grid points $\\{x_i\\}$, we have:\n\\begin{align*}\nu'(x_i) \\approx \\frac{u(x_i+h)-u(x_i-h)}{2h}=\\frac{u(x_{i+1})-u(x_{i-1})}{2h}.\n\\end{align*}\nWe won't worry about the derivative at the endpoints, $u'(x_0)$ and $u'(x_n)$.\nThis allows us to approximate the values $\\{u'(x_i)\\}$ as the solution to a system of equations:\n\n\\begin{align}\n\\frac{1}{2h}\n\\begin{array}{c}\n\\begin{bmatrix}\n-1 &0 & 1 & \\\\\n& -1 & 0 & 1  \\\\\n& & \\ddots & \\ddots & \\ddots & \\\\\n& & & -1 & 0 & 1 \\\\\n& & & & -1 & 0 & 1\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times(n+1)}}\n\\end{array}\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}\nu(x_0) \\\\ u(x_1)\\\\ \\vdots  \\\\ u(x_{n-1}) \\\\ u(x_n)\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n+1)\\times1}}\n\\end{array} \\approx\n\\begin{array}{c}\n\\begin{bmatrix}\nu'(x_1) \\\\ u'(x_2)\\\\ \\vdots  \\\\ u'(x_{n-2}) \\\\ u'(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array}.\n\\label{finitedifference2:up}\n\\end{align}\n\n\\noindent This can be rewritten with a $(n-1)\\times(n-1)$ tridiagonal matrix instead:\n\\begin{align}\n\\frac{1}{2h}\n\\begin{array}{c}\n\\begin{bmatrix}\n0 & 1 & \\\\\n-1 & 0 & 1  \\\\\n& \\ddots & \\ddots & \\ddots \\\\\n& & -1 & 0 & 1 \\\\\n& & & -1 & 0\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times(n-1)}}\n\\end{array}\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}\nu(x_1) \\\\ u(x_2)\\\\ \\vdots  \\\\ u(x_{n-2}) \\\\ u(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array} +\n\\begin{array}{c}\n\\begin{bmatrix}\n-u(x_0)/(2h) \\\\ 0 \\\\ \\vdots  \\\\ 0 \\\\ u(x_n)/(2h)\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array} \\approx\n\\begin{array}{c}\n\\begin{bmatrix}\nu'(x_1) \\\\ u'(x_2)\\\\ \\vdots  \\\\ u'(x_{n-2}) \\\\ u'(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array}.\n\\label{finitedifference2:u}\n\\end{align}\n\n\\noindent Next, we will consider the approximation for $u''(x)$.\nIf we let\n\\[u'(x) \\approx \\frac{u(x+\\frac{h}{2})-u(x-\\frac{h}{2})}{h}\\]\nthen\n\\[u''(x) \\approx \\frac{u'(x+\\frac{h}{2})-u'(x-\\frac{h}{2})}{h} \\approx \\frac{\\frac{u((x+\\frac{h}{2})+\\frac{h}{2})-u((x+\\frac{h}{2})-\\frac{h}{2})}{h}-\\frac{u((x-\\frac{h}{2})+\\frac{h}{2})-u((x-\\frac{h}{2})-\\frac{h}{2})}{h}}{h}\\]\n\\[= \\frac{u(x+h) - 2u(x) + u(x-h)}{h^2}\\]\nYou can achieve the same result by again consider the Taylor polynomial expansion and adding \\eqref{plus} and \\eqref{minus} and rearranging.\nThus\n\\[u''(x_i) \\approx \\frac{u(x_i+h) - 2u(x_i) + u(x_i-h)}{h^2}= \\frac{u(x_{i+1}) - 2u(x_i) + u(x_{i-1})}{h^2}\\]\nAgain ignoring the second derivative at the endpoints, this can be written in matrix form as\n\\begin{align}\n\\frac{1}{h^2}\n\\begin{array}{c}\n\\begin{bmatrix}\n1 & -2 & 1 & \\\\\n& 1 & -2 & 1  \\\\\n& &\\ddots &\\ddots & \\ddots  \\\\\n& & & 1 & -2 & 1 \\\\\n& & & & 1 & -2 & 1\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times(n+1)}}\n\\end{array}\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}\nu(x_0) \\\\ u(x_1)\\\\ \\vdots  \\\\ u(x_{n-1}) \\\\ u(x_n)\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n+1)\\times1}}\n\\end{array}\n \\approx\n \\begin{array}{c}\n\\begin{bmatrix}\nu''(x_1) \\\\ u''(x_2)\\\\ \\vdots  \\\\ u''(x_{n-2}) \\\\ u''(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\label{finitedifference2:uppp}\n\\end{array}.\n\\end{align}\n\n\\noindent This can also be written with a $(n-1)\\times(n-1)$ tridiagonal matrix:\n\\begin{align}\n\\frac{1}{h^2}\n\\begin{array}{c}\n\\begin{bmatrix}\n-2 & 1 & \\\\\n1 & -2 & 1  \\\\\n& \\ddots & \\ddots & \\ddots \\\\\n& & 1 & -2 & 1 \\\\\n& & & 1 & -2\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times(n-1)}}\n\\end{array}\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}\nu(x_1) \\\\ u(x_2)\\\\ \\vdots  \\\\ u(x_{n-2}) \\\\ u(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array} +\n\\begin{array}{c}\n\\begin{bmatrix}\nu(x_0)/h^2 \\\\ 0 \\\\ \\vdots  \\\\ 0 \\\\ u(x_n)/h^2\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n \\end{array} =\n \\begin{array}{c}\n\\begin{bmatrix}\nu''(x_1) \\\\ u''(x_2)\\\\ \\vdots  \\\\ u''(x_{n-2}) \\\\ u''(x_{n-1})\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\label{finitedifference2:upp}\n\\end{array}\n\\end{align}\n\n\\begin{problem}\n\tLet $u(x) = \\sin((x+\\pi)^2-1)$. Use \\eqref{finitedifference2:up} - \\eqref{finitedifference2:upp} to approximate $\\frac{1}{2}u'' - u'$ at the grid points where $a=0$, $b=1$, and $n=10$. Graph the result.\n\\end{problem}\n\nThe previous equations are not only useful for approximating derivatives, but they can be also used to solve differential equations. Suppose that instead of knowing the function $u(x)$, we know that $\\frac{1}{2}u'' - u' = f$, where the function $f(x)$ is given. How do we solve for $u(x)$?\n\n\\section*{Finite Difference Methods}\n\nNumerical methods for differential equations seek to approximate the exact solution $u(x)$ at some finite collection of points in the domain of the problem.\nInstead of analytically solving the original differential equation, defined over an infinite-dimensional function space, they use a well-chosen finite system of algebraic equations to approximate the original problem.\n\nConsider the following differential equation:\n\\begin{align}\n\t\\begin{split}\n\t&{ } \\epsilon u''(x)-u(x)'= f(x), \\quad x \\in (0,1), \\\\\n\t&{ } u(0) = \\alpha, \\quad u(1) = \\beta.\n\t\\end{split} \\label{eqn:singular_perturbed_BVP}\n\\end{align}\nEquation \\eqref{eqn:singular_perturbed_BVP} can be written $D u = f,$ where $D = \\epsilon \\frac{d^2}{dx^2} - \\frac{d}{dx}$ is a differential operator defined on the infinite-dimensional space of functions that are twice continuously differentiable on $[0,1]$ and satisfy $u(0) = \\alpha$, $u(1) = \\beta$.\n\nWe look for an approximate solution $\\{U_i\\}$, where \\[U_i \\approx u(x_i)\\] on an evenly spaced grid of points, $a = x_0, x_1, \\ldots, x_n = b$,.\nOur finite difference method will replace the differential operator $D = \\epsilon \\frac{d^2}{dx^2} - \\frac{d}{dx}$, (which is defined on an infinite-dimensional space), with finite difference operators (defined on a finite dimensional space).\nTo do this, we replace derivative terms in the differential equation with appropriate difference expressions.\n\nRecalling that\n\\begin{align*}\n\\frac{d^2}{dx^2} u(x_i) &= \\frac{u(x_{i+1})- 2u(x_i) + u(x_{i-1})}{h^2} + \\mathcal{O}(h^2),\\\\\n\\frac{d}{dx} u(x_i) &= \\frac{u(x_{i+1})-u(x_{i-1})}{2h} + \\mathcal{O}(h^2).\n\\end{align*}\nwe define the finite difference operator $D_h$ by\n\\begin{align}\nD_h U_i = \\epsilon \\frac{1}{h^2}\\left(U_{i+1} -2U_i + U_{i-1}\\right) - \\frac{1}{2h} \\left(U_{i+1}-U_{i-1} \\right). \\label{fd_operator}\n\\end{align}\nThus we discretize equation \\eqref{eqn:singular_perturbed_BVP} using the equations\n\\begin{align*}\n\t\\frac{\\epsilon}{h^2} (U_{i+1}- 2U_i + U_{i-1}) - \\frac{1}{2h} \\left(U_{i+1}-U_{i-1} \\right)  &= f(x_i), \\quad i = 1, \\ldots, n-1,\n\\end{align*}\nalong with boundary conditions $U_{0} = \\alpha$, $U_{n} = \\beta$.\n\nThis gives $n+1$ equations and $n+1$ unknowns, and can be written in matrix form as\n\\[ \\frac{1}{h^2}\n\\begin{array}{c}\n\\begin{bmatrix}h^2 & 0 &0&\\hdots &0 \\\\ (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) &\\hdots &0\\\\ \\vdots &  & \\ddots & &\\vdots \\\\\n0 & \\hdots & (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) \\\\ 0 & \\hdots & & 0 & h^2\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n+1)\\times(n+1)}}\n\\end{array}\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}U_0\\\\U_1\\\\ \\vdots \\\\U_{n-1} \\\\U_{n}\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n+1)\\times1}}\n\\end{array}=\n\\begin{array}{c}\n\\begin{bmatrix}\\alpha\\\\f(x_1)\\\\ \\vdots \\\\ f(x_{n-1}) \\\\ \\beta \\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n+1)\\times1}}\n\\end{array}.\n\\]\nAs before, we can remove two equations to modify the system to obtain an $(n-1)\\times (n-1)$ tridiagonal system:\n\\begin{align}\n    \\label{eqn:practical_fin_dif}\n    \\begin{split}\n\\frac{1}{h^2}\n\\begin{array}{c}\n\\begin{bmatrix}-2\\epsilon & (\\epsilon - h/2) &0&\\hdots &0 \\\\ (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) &\\hdots &0\\\\ \\vdots &  & \\ddots & &\\vdots \\\\\n0 & \\hdots & (\\epsilon + h/2) &-2\\epsilon & (\\epsilon - h/2) \\\\ 0 & \\hdots & & (\\epsilon + h/2) &-2\\epsilon\n\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times(n-1)}}\n\\end{array}\n\\cdot\n\\begin{array}{c}\n\\begin{bmatrix}U_1\\\\U_2\\\\ \\vdots \\\\U_{n-2} \\\\U_{n-1}\\end{bmatrix}\\\\\n{\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n\\end{array}\\\\\n =\n \\begin{array}{c}\n \\begin{bmatrix}f(x_1) -\\alpha(\\epsilon + h/2)/h^2 \\\\f(x_2)\\\\ \\vdots \\\\ f(x_{n-2})\\\\ f(x_{n-1})-\\beta(\\epsilon - h/2)/h^2 \\end{bmatrix}\\\\\n {\\scriptstyle\\textcolor{red}{(n-1)\\times1}}\n \\end{array}.\n    \\end{split}\n\\end{align}\n\n\n\n\\begin{problem}\nUse equation \\eqref{eqn:practical_fin_dif} to solve the singularly perturbed BVP \\eqref{eqn:singular_perturbed_BVP} with $\\epsilon = 1/10$, $f(x) = -1$, $\\alpha=1$, and $\\beta=3$ on a grid with $n=30$ subintervals. Graph the solution.\nThis BVP is called singularly perturbed because of the location of the parameter $\\epsilon$.\nFor $\\epsilon = 0$ the ODE has a drastically different character - it then becomes first order, and can no longer support two boundary conditions.\n    \\label{prob:finitedifference2:prob1}\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{figure2.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob1}.\nThe solution gets steeper near $x = 1$ as $\\epsilon $ gets small.}\n\\end{figure}\n\n\n\\begin{comment}\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.sparse import spdiags\nfrom scipy.sparse.linalg import spsolve\nimport matplotlib.pyplot as plt\n\ndef bvp(func, epsilon, alpha, beta, N):\n\ta,b = 0., 1. \t# Interval for the BVP\n\th = (b-a)/N \t# The length of each subinterval\n\n\t# Initialize and define the vector F on the right\n\tF = np.empty(N-1.)\n\tF[0] = func(a+1.*h)-alpha*(epsilon+h/2.)*h**(-2.)\n\tF[N-2] = func(a+(N-1)*h)-beta*(epsilon-h/2.)*h**(-2.)\n\tfor j in xrange(1,N-2):\n\t\tF[j] = func(a + (j+1)*h)\n\n\t# Here we define the arrays that will go on the diagonals of A\n\tdata = np.empty((3,N-1))\n\tdata[0,:] = -2.*epsilon*np.ones((1,N-1)) # main diagonal\n\tdata[1,:]  = (epsilon+h/2.)*np.ones((1,N-1))  \t # off-diagonals\n\tdata[2,:] = (epsilon-h/2.)*np.ones((1,N-1))\n\t# Next we specify on which diagonals they will be placed, and create A\n\tdiags = np.array([0,-1,1])\n\tA=h**(-2.)*spdiags(data,diags,N-1,N-1).asformat('csr')\n\n\tU = np.empty(N+1)\n\tU[1:-1] = spsolve(A,F)\n\tU[0], U[-1] = alpha, beta\n\treturn np.linspace(a,b,N+1), U\n\nx, y = bvp(lambda x:-1., epsilon=.05,alpha=1, beta=3, N=400)\nplt.plot(x,y,'-k',linewidth=2.0)\nplt.show()\n\n\\end{lstlisting}\n\\end{comment}\n\n\n\\section*{A heuristic test for convergence}\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=12cm]{example_convergence.pdf}\n\\caption{Demonstration of second order convergence for the finite difference approximation \\eqref{fd_operator} of the BVP given in \\eqref{eqn:singular_perturbed_BVP} with $\\epsilon = .5$. } \\label{fig:finitedifference2}\n\\end{figure}\n\nThe finite differences used above are second order approximations of the first and second derivatives of a function.  It seems reasonable to expect that the numerical solution would converge at a rate of about $\\mathcal{O}(h^2)$. How can we check that a numerical approximation is reasonable?\n\nSuppose a finite difference method is $\\mathcal{O}(h^p)$ accurate.\nThis means that the error $E(h) \\approx Ch^p$ for some constant $C$ as $h \\to 0$ (in other words, for $h>0$ small enough).\n\nSo compute the approximation $y_k$ for each stepsize $h_k$, $h_1 > h_2> \\ldots>h_m$.\n$y_m$ should be the most accurate approximation, and will be thought of as the true solution.\nThen the error of the approximation for\nstepsize $h_k, k < m,$ is\n\\begin{align*}\n\tE(h_k) &= \\max( \\abs{ y_k - y_m}) \\approx C h_k^p ,\\\\\n\t\\log(E(h_k)) &= \\log(C) + p \\log(h_k).\n\\end{align*}\n\nThus on a log-log plot of $E(h)$ vs. $h$, these values should be on a straight line with slope $p$ when $h$ is small enough to start getting convergence. We should note that demonstrating second-order convergence does NOT imply that the numerical approximation is converging to the correct solution.\n\n\n\\begin{problem}\nVisualize the $\\mathcal{O}(h^2)$ convergence of this finite difference method by producing a loglog plot similar to Figure \\ref{fig:finitedifference2}, except in the case $\\epsilon=.1$. Implement a function \\li{singular_bvp} to compute the finite difference solution to \\ref{eqn:singular_perturbed_BVP}. Using $n = 5 \\times 2^0,5 \\times 2^1, \\dots ,5 \\times 2^9$ subintervals, compute 10 approximate solutions. \n\n\nTo produce the plot, treat the approximation with $n = 5 \\times 2^9$ subintervals as the \"true solution\", and measure the error for the other approximations against it. Note that, since the number of subintervals for each approximation is a multiple of 2, we can compute the $L_{\\infty}$ error for the $n=5 \\times 2^j$ approximation by using the \\li{step} argument in the array slicing syntax:\n\\begin{lstlisting}\n# best approximation\nsol_best = singular_bvp(eps,alpha,beta,f,5*(2**9))\n\n# approximation with 5*(2^j) intervals\nsol_approx = singular_bvp(eps,alpha,beta,f,5*(2**j))\n\n# approximation error\nerror = np.max(np.abs(sol_approx - sol_best[::2**(9-j)]))\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{problem}\nExtend your finite difference code to the case of a general second order linear BVP with boundary conditions:\n\\begin{align*}\n\t&{ } a_1(x)y'' +a_2(x)y'+ a_3(x) y = f(x), \\quad x \\in (a,b),\\\\\n\t&{ } y(a) = \\alpha, \\quad y(b) = \\beta.\n\\end{align*}\nUse your code to solve the boundary value problem\n\\begin{align*}\n\t\\epsilon y'' - 4(\\pi - x^2)y = \\cos x, \\\\\n\ty(0) = 0, \\quad y(\\pi/2) = 1,\n\\end{align*}\nfor $\\epsilon = 0.1$ on a grid with $n=30$ subintervals.\n\\label{prob:finitedifference2:prob3}\nBe sure to modify the finite difference operator $D_h$ in \\eqref{fd_operator} correctly.\n\n\\end{problem}\n\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=10cm]{figure3.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob3}.\n% The solution gets steeper near $x = 1$ as $\\epsilon $ gets small.\n}\n\\end{figure}\n\n\nThe next few problems will help you test your finite difference code.\n\n\\begin{problem}\nNumerically solve the boundary value problem\n\\begin{align*}\n\t\\epsilon y'' + xy' = -\\epsilon \\pi^2 \\cos(\\pi x) - \\pi x \\sin(\\pi x), \\\\\n\ty(-1) = -2, \\quad y(1) = 0,\n\\end{align*}\nfor $\\epsilon = 0.1, 0.01,$ and $0.001$. Use a grid with $n=150$ subintervals.\n\\label{prob:finitedifference2:prob4}\n\\end{problem}\n\n\\begin{problem}\nNumerically solve the boundary value problem\n\\begin{align*}\n\t(\\epsilon +x^2)y'' + 4xy' + 2y = 0, \\\\\n\ty(-1) = 1/(1+\\epsilon), \\quad y(1) = 1/(1+\\epsilon),\n\\end{align*}\nfor $\\epsilon = 0.05, 0.02$. Use a grid with $n=150$ subintervals.\n\\label{prob:finitedifference2:prob5}\n\\end{problem}\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=11cm]{figure4.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob4}.\n}\n\\end{figure}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=11cm]{figure5.pdf}\n\\caption{The solution to Problem \\ref{prob:finitedifference2:prob5}.\n}\n\\end{figure}\n", "meta": {"hexsha": "7530973353bc76ce587f05769abeeacd816fa13a", "size": 16078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume4/FiniteDifferenceMethod/FiniteDifferenceMethod.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": "Volume4/FiniteDifferenceMethod/FiniteDifferenceMethod.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": "Volume4/FiniteDifferenceMethod/FiniteDifferenceMethod.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": 39.5036855037, "max_line_length": 411, "alphanum_fraction": 0.6634531658, "num_tokens": 5905, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.7892059203859377}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following vectors are redundant? If there are redundant\n  vectors, write each of them as a linear combination of previous\n  vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 1 \\\\ 6 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $\\vect{u}_2$ and $\\vect{u}_4$ are redundant. We have\n    $\\vect{u}_2=2\\vect{u}_1$ and $\\vect{u}_4=3\\vect{u}_3-2\\vect{u}_1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following vectors are redundant? If there are redundant\n  vectors, write each of them as a linear combination of previous\n  vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} -1 \\\\ -2 \\\\ 2 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -3 \\\\ -4 \\\\ 3 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 4 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 0 \\\\ 2 \\\\ -3 \\\\ -6 \\end{mymatrix}.\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the method of\n  Theorem~\\ref{thm:characterization-linear-independence} to determine\n  whether the following vectors are linearly independent. If they are\n  linearly dependent, find a non-trivial linear combination of the\n  vectors that is equal to $\\vect{0}$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} -3 \\\\ -4 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 5 \\\\ 6 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    The vectors are linearly dependent. We have\n    $\\vect{u}_2+3\\vect{u}_3+2\\vect{u}_4=\\vect{0}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the method of\n  Theorem~\\ref{thm:characterization-linear-independence} to determine\n  whether the following vectors are linearly independent. If they are\n  linearly dependent, find a non-trivial linear combination of the\n  vectors that is equal to $\\vect{0}$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 0 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 6 \\\\ 7 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 3 \\\\ 5 \\\\ 8 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Are the following vectors linearly independent? If not, write one of\n  them as a linear combination of the others.\n  \\begin{equation*}\n    \\vect{u} = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{v} = \\begin{mymatrix}{r} 1 \\\\ 4 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{w} = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    The vectors are linearly dependent. We have\n    $\\vect{w} = 3\\vect{u}-2\\vect{v}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find a linearly independent set of vectors that has the same span as\n  the given vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 5 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 3 \\\\ 3 \\\\ 8 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 3 \\\\ -3 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $\n    \\begin{mymatrix}{rrrr}\n      2 & 1 & 3 & 3 \\\\\n      0 & 3 & 3 & -3 \\\\\n      3 & 5 & 8 & 1 \\\\\n    \\end{mymatrix}\n    \\roweq\n    \\begin{mymatrix}{rrrr}\n      1 & 4 & 5 & -2 \\\\\n      0 & 1 & 1 & -1 \\\\\n      0 & 0 & 0 &  0 \\\\\n    \\end{mymatrix}\n    $.\n    Linearly independent subset: $\\set{\\vect{u}_1,\\vect{u}_2}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find a linearly independent set of vectors that has the same span as\n  the given vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 3 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 2 \\\\ 6 \\\\ 6 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ -3 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Here are some vectors in $\\R^4$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ -1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 0 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_5 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ -1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Explain why these vectors cannot possibly be linearly\n  independent. Then obtain a linearly independent subset of these\n  vectors that has the same span as these vectors.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Here are some vectors in $\\R^4$.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ -1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -3 \\\\ 3 \\\\ 3 \\\\ -3 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ -1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 2 \\\\ -9 \\\\ -2 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_5 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Explain why these vectors cannot possibly be linearly\n  independent. Then find a non-trivial linear combination of these\n  vectors that equals $\\vect{0}$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Here are some vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ -4 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 2 \\\\ 7 \\\\ -4 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 5 \\\\ 7 \\\\ -10 \\end{mymatrix},\\quad\n    \\vect{u}_5 = \\begin{mymatrix}{r} 12 \\\\ 17 \\\\ -24 \\end{mymatrix}.\n  \\end{equation*}\n  Describe the span of these vectors as the span of as few vectors as\n  possible.\n  \\begin{sol}\n    \\begin{equation*}\n      \\begin{mymatrix}{rrrrr}\n        1 & 2 & 2 & 5 & 12 \\\\\n        1 & 2 & 7 & 7 & 17 \\\\\n        -2 & -4 & -4 & -10 & -24 \\\\\n      \\end{mymatrix}\n      \\roweq\n      \\begin{mymatrix}{rrrrr}\n        1 & 1 & 2 & 5 & 12 \\\\\n        0 & 0 & 5 & 2 & 5 \\\\\n        0 & 0 & 0 & 0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    Linearly independent subset: $\\set{\\vect{u}_1,\\vect{u}_3}$. Since\n    the rank is $2$, this is the smallest possible.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Here are some vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ -2 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_5 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ -1 \\end{mymatrix}.\n  \\end{equation*}\n  Describe the span of these vectors as the span of as few vectors as\n  possible.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_3$ of integers\n  modulo $3$ instead of real numbers (see Section~\\ref{sec:fields},\n  ``Fields'').  Use the extended casting-out algorithm to determine\n  which of the following vectors are redundant. If there are redundant\n  vectors, write each of them as a linear combination of previous\n  vectors.\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    We write the vectors as the columns of a matrix and reduce to\n    {\\rref} over $\\Z_3$:\n    \\begin{equation*}\n      \\begin{mymatrix}{rrrr}\n        2 & 1 & 2 & 0 \\\\\n        1 & 1 & 0 & 1 \\\\\n        0 & 2 & 2 & 1 \\\\\n      \\end{mymatrix}\n      \\quad\\roweq\\ldots\\roweq\\quad\n      \\begin{mymatrix}{rrrr}\n        1 & 0 & 2 & 2 \\\\\n        0 & 1 & 1 & 2 \\\\\n        0 & 0 & 0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    $\\vect{u}_3$ and $\\vect{u}_4$ are redundant. We have\n    $\\vect{u}_3=2\\vect{u}_1+1\\vect{u}_2$ and\n    $\\vect{u}_4=2\\vect{u}_1+2\\vect{u}_2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\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{w}-2\\vect{v}$ linearly independent?\n  \\begin{sol}\n    From\n    $a(\\vect{u}+\\vect{v}) + b(2\\vect{u}+\\vect{w}) +\n    c(\\vect{w}-2\\vect{v})=\\vect{0}$ we get\n    $(a+2b)\\vect{u} + (a-2c)\\vect{v} + (b+c)\\vect{w}=\\vect{0}$.  Since\n    $\\vect{u},\\vect{v},\\vect{w}$ are linearly independent, this last\n    system has only the trivial solution, so $a+2b=0$, $a-2c=0$, and\n    $b+c=0$. However, these three equations have non-trivial\n    solutions, for example $(a,b,c)=(2,-1,1)$. So the vectors\n    $\\vect{u}+\\vect{v}$, $2\\vect{u}+\\vect{w}$, and\n    $\\vect{w}-2\\vect{v}$ are linearly dependent.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u},\\vect{v},\\vect{w}$ be linearly independent vectors in\n  $\\R^n$. Are the vectors $\\vect{u}+\\vect{v}$, $\\vect{u}+\\vect{w}$,\n  and $\\vect{w}+\\vect{v}$ linearly independent?\n  \\begin{sol}\n    From\n    $a(\\vect{u}+\\vect{v}) + b(\\vect{u}+\\vect{w}) +\n    c(\\vect{w}+\\vect{v})=\\vect{0}$ we get\n    $(a+b)\\vect{u} + (a+c)\\vect{v} + (b+c)\\vect{w}=\\vect{0}$.  Since\n    $\\vect{u},\\vect{v},\\vect{w}$ are linearly independent, this last\n    system has only the trivial solution, so $a+b=0$, $a+c=0$, and\n    $b+c=0$. Solving, we find the unique solution\n    $(a,b,c)=(0,0,0)$. So the vectors $\\vect{u}+\\vect{v}$,\n    $\\vect{u}+\\vect{w}$, and $\\vect{w}+\\vect{v}$ are linearly\n    independent.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is an $m\\times n$-matrix and\n  $\\set{\\vect{w}_1,\\ldots,\\vect{w}_k}$ is a linearly independent\n  set of vectors in $\\R^m$. Now suppose\n  $A\\vect{z}_i=\\vect{w}_i$. Show\n  $\\set{\\vect{z}_1,\\ldots,\\vect{z}_k}$ is also linearly\n  independent.\n  \\begin{sol}\n    Assume\n    $a_1\\vect{z}_1+\\ldots+a_k\\vect{z}_k=\\vect{0}$. Multiplying\n    both sides of the equation by $A$, we get\n    \\begin{equation*}\n      a_1A\\vect{z}_1+\\ldots+a_kA\\vect{z}_k=\n      a_1\\vect{w}_1+\\ldots+a_k\\vect{w}_k=\\vect{0}.\n    \\end{equation*}\n    Since the $\\vect{w}_i$ are linearly independent, it follows that\n    each $a_i=0$. Therefore the $\\vect{z}_i$ are linearly\n    independent as well.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "1628265c0df9c7b608ce278d06c67f943ecc7a17", "size": 10688, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/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/exercises/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/exercises/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": 36.8551724138, "max_line_length": 76, "alphanum_fraction": 0.589258982, "num_tokens": 4401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8976952873175983, "lm_q1q2_score": 0.7892059043688278}}
{"text": "\n\\chapter[Initial value problems]{Initial value problems for Ordinary Differential Equations}\n\n\\section{Introduction}\n\nA system of first order differential equation (ODE) is a relationship\nbetween an unknown (vectorial) function $\\by(x)$ and its derivative\n$\\by'(x)$. The general system of first order differential equations\nhas the form\n%\n\\begin{equation}\n  \\by'(x)=\\boldsymbol{f}(x,\\by(x)). \\label{odedef}\n\\end{equation}\n%\nThe solution of the differential equation is a function $\\by(x)$ that\nsatisfies~(\\ref{odedef}). Analytic techniques produce a family of\nsolutions and an initial condition of the form\n%\n\\begin{equation}\\label{odeic}\n  \\by(0)= \\by_0\n\\end{equation}\n%\ncan be used to determine a member of this family. The differential\nequations~(\\ref{odedef}) and the initial condition~(\\ref{odeic})\nspecify an {\\it initial value problem}.  We assume that all the\ndifferential equations that we are going to analyse satisfy the\nconditions of the theorem that guarantees the existence and uniqueness\nof the solution of an initial value problem.\n\n\\noindent \\textbf{Remark} - If the original formulation of the problem\nis in the form of second or higher order differential equations, we\ncan always recast it in the form~(\\ref{odedef}) by introducing\nappropriate new variables.\n\n\\section{Numerical differentiation}\n\nWe can make use of Taylor's theorem to obtain numerically estimates of\nthe derivative of a function $f(x)$ at a point $x_0$.  Indicate with\n$h$ a small step in the variable $x$.  By Taylor's theorem we have\nthat:\n%\n\\begin{equation}\n  f(x_0+h) = f(x_0) + h f'(x_0) + \\frac{h^2}{2} f''(x_0) +\n  \\frac{h^3}{6} f'''(x_0) + \\order{h^4} .\n  \\label{IVP.eq:1}\n\\end{equation}\n%\nSolving for $f'(x_0)$ we obtain the \\textit{forward difference\n  estimate of the derivative}:\n%\n\\begin{equation}\n  f'(x_0) = \\frac{f(x_0+h)-f(x_0)}{h} + \\order{h} .\n  \\label{IVP.eq:2}\n\\end{equation}\n\n\\noindent\n\\textbf{Remark 1} - In other words the slope of the tangent to $f(x)$ at\n$x_0$ is approximated with that of the line through $[x_0,f(x_0)]$ and\n$[x_0+h,f(x_0+h)]$.\n\n\\noindent\n\\textbf{Remark 2} - The symbol $\\order{h}$ on the far right of\nequation~(\\ref{IVP.eq:2}) indicates that the error of this estimate\ndecreases linearly with the step size $h$.\n\nAnother estimate of the derivative can be obtained by taking a step\nbackward:\n%\n\\begin{equation}\n  f(x_0-h) = f(x_0) - h f'(x_0) + \\frac{h^2}{2} f''(x_0) -\n  \\frac{h^3}{6} f'''(x_0) + \\order{h^4} .\n  \\label{IVP.eq:3}\n\\end{equation}\n%\nSolving for $f'(x_0)$ we obtain the \\textit{backward difference\n  estimate of the derivative}:\n%\n\\begin{equation}\n  f'(x_0) = \\frac{f(x_0)-f(x_0-h)}{h} + \\order{h} .\n  \\label{IVP.eq:4}\n\\end{equation}\n\nBoth the forward and the backward estimate of the derivative are order\none methods, in the sense that the error in the approximation\ndecreases with the first power of the step size $h$.  It is possible\nto obtain a higher order method by using a more symmetric formula:\nsubtracting~(\\ref{IVP.eq:3}) from~(\\ref{IVP.eq:1}) we obtain the\n\\textit{central difference estimate of the derivative}:\n%\n\\begin{equation}\n  f'(x_0) = \\frac{f(x_0+h)-f(x_0-h)}{2 h} + \\order{h^2} .\n  \\label{IVP.eq:5}\n\\end{equation}\n\n\\noindent\n\\textbf{Remark 1} - The geometrical interpretation of this estimate is\nthat the slope of the tangent to $f(x)$ at $x_0$ is well approximated\nby the slope of the secant through $[x_0-h,f(x_0-h)]$ and\n$[x_0+h,f(x_0+h)]$.\n\n\\noindent\n\\textbf{Remark 2} - An intuitive explanation of why the central\ndifference is more accurate than either the forward and the backward\ndifference is that it contains information on the function on\n\\underline{both} sides of the point where the derivative is to be\nestimated.\n\n\\noindent\n\\textbf{Exercise} - Obtain an accurate estimate of $f''(x_0)$.\n\n\\section{Errors}\n\nAll procedures to solve numerically an initial value problem consist\nof transforming the continuous differential equation~(\\ref{odedef})\ninto a discrete iteration procedure that starting from the initial\ncondition~(\\ref{odeic}) returns the values of the dependent variables\n$\\by(x)$ at points $x_n = x_0 + n h$, with $h$ a small number called\nthe \\textit{discretisation step}.\n\nIn this discretisation and iteration procedure several types of errors\narise.  These are classified as follows:\n%\n\\begin{enumerate}\n  \\itemsep 0pt\n  %\n\\item Local truncation error\n  %\n\\item Local roundoff error\n  %\n\\item Global truncation error\n  %\n\\item Global roundoff error\n  %\n\\item Total error\n  %\n\\end{enumerate}\n%\nThe \\textbf{roundoff error} is caused by the limited precision of\ncomputers.  The \\textbf{global roundoff error} is the accumulation of\nthe local roundoff errors.  The \\textbf{total error} is the sum of the\nglobal truncation error and the global roundoff error.\n\nThe \\textbf{local truncation error} is the error made in one step when\nwe replace a continuous process (like a derivative) with a discrete\none (like the numerical estimate of the derivative using forward\ndifferences).  The local truncation error is inherent in any\nalgorithm.  The accumulation of all the local errors in the process of\nan iterative procedure (like those used to integrate a differential\nequation) give rise to the \\textbf{global truncation} error.  Again,\nthis error will be present even if all calculations are performed\nusing exact arithmetic.  If the local truncation errors are\n$\\order{h^{n+1}}$, where $h$ is the discretisation step used in evaluating\nthe derivatives, then the global truncation error must be $\\order{h^n}$\nbecause the number of steps necessary to reach an arbitrary point\n$x_f$, having started at $x_0$, is $(x_f-x_0)/h$.  We can proceed more\nformally to establish a better bound on the global truncation error\nand, more importantly, to understand better its relation with the\noriginal differential equation.  For simplicity we consider only a\nsingle first order differential equation instead of a system\nlike~(\\ref{odedef}).  Moreover, we assume that no roundoff error is\ninvolved.\n\nConsider the initial value problem\n%\n\\begin{equation}\n  y'=f(x,y), \\qquad y(0)=s, \\qquad 0\\le x\\le X>0.\n  \\label{IVP.eq:30}\n\\end{equation}\n%\nThe difference $y(x_n)-y_n$ is the global truncation error. This is\nnot simply the sum of all local truncation errors that entered at the\nprevious points. The key point is to understand how two solutions\ndiffer at any point if they are started with different initial\nconditions as each step in the numerical solution must use as its\ninitial value the approximated ordinate computed at the preceding\nstep.\n\nWe assume that $f_y=\\pdv{f}{y}(x,y)$ is continuous\nand satisfies the condition $f_y\\le \\lambda$ for $0\\le x\\le X>0$. The\nsolution is $y=y(x,s)$. We would like to know how the solution depends\non $s$. Define\n%\n\\begin{equation}\n  u(x)=\\pdv{y}{s}(x,s) \\, .\n \\label{IVP.eq:58}\n\\end{equation}\n%\nWe can obtain a differential equation - the variational equation - for\n$u$ by differentiating with respect to $s$ in the initial value\nproblem~(\\ref{IVP.eq:30}) to get\n%\n\\begin{equation}\n  u'(x) = \\pdv{u}{x} = \\pdv{y'}{s} = \\pdv{f}{s} = f_y(x,y) u, \\qquad u(0)=1, \\qquad 0 \\le x \\le X > 0.\n  \\label{IVP.eq:31}\n\\end{equation}\n%\nNote that if $f_y \\le \\lambda$ for $0 \\le x \\le X > 0$, then the solution\nof the variational equation satisfies the inequality\n%\n\\begin{equation}\n  |u(x)| \\le e^{\\lambda x}, \\qquad 0\\le x\\le X>0.\n  \\label{IVP.eq:33}\n\\end{equation}\n%\n{\\it Proof}: we have\n%\n\\begin{equation}\n  u' / u = f_y = \\lambda-\\alpha(x), \\qquad \\alpha(x)\\ge 0.\n  \\label{IVP.eq:32}\n\\end{equation}\n%\nIntegrating this inequality, we obtain\n%\n\\begin{equation}\n  \\log|u| = \\lambda x - \\mint{0}{x}{\\alpha(\\tau)}{\\tau}, \\implies\n  |u(x)| = e^{\\lambda x} - \\mint{0}{x}{\\alpha(\\tau)}{\\tau} \\le e^{\\lambda x}.\n  \\label{IVP.eq:34}\n\\end{equation}\n%\nThe last inequality is justified because\n%\n\\begin{equation}\n  \\mint{0}{x}{\\alpha(\\tau)}{\\tau} \\ge 0.\n  \\label{IVP.eq:35}\n\\end{equation}\n%\nUsing this inequality, it is easy to show that if the initial value\nproblem is solved with two initial values $s$ and $s+\\delta $, the\nsolutions differ at $x$ by at most $|\\delta|e^{\\lambda x}$, as\n%\n\\begin{equation}\n  |y(x,s) - y(x,s+\\delta )| = |\\delta|\n  \\left | \\pdv{}{s} y(x,s+\\theta\\delta) \\right| =\n  |u(x)| |\\delta| \\le e^{\\lambda x}|\\delta|, \\qquad 0<\\theta<1.\n \\label{IVP.eq:36}\n\\end{equation}\n\n\\noindent \\textbf{Global Error Theorem}: if all local truncation\nerrors $\\delta_1,\\delta_2,...,\\delta_n$ do not exceed $\\delta$ in\nmagnitude, then the global truncation error does not exceed\n%\n\\begin{equation}\n \\delta \\frac{1-e^{n\\lambda h}}{1-e^{\\lambda h}}  .\n \\label{IVP.eq:37}\n\\end{equation}\n\n\\noindent\n{\\it Proof}: In computing $y_1$ there was an error $|\\delta_1|$.  In\ncomputing $y_2$ the global error is\n%\n\\begin{equation}\n |\\delta_1| e^{\\lambda h} + |\\delta_2|,\n \\label{IVP.eq:38}\n\\end{equation}\nwhere the first term in the right-hand side is the error in the\ninitial condition, and the second term is the new truncation error. In\ncomputing $y_3$ the global error is\n%\n\\begin{equation}\n (|\\delta_1| e^{\\lambda h} + |\\delta_2| ) e^{\\lambda h} + |\\delta_3|,\n \\label{IVP.eq:39}\n\\end{equation}\n%\nand so on.  Finally, if $|\\delta_i|\\le \\delta$, $i=1,2,...,n$, we\nobtain for the global truncation error\n%\n\\begin{equation}\n |\\delta_1| e^{n\\lambda h} + |\\delta_2| e^{(n-1)\\lambda h} + \\ldots +\n |\\delta_n| \\le \\delta \\frac{1-e^{n\\lambda h}}{1-e^{\\lambda h}}.\n \\label{IVP.eq:40}\n\\end{equation}\n\nAs a consequence of this theorem, if all local truncation errors\n$\\delta_i=\\order{h^{n+1}})$, then the global truncation error is $\\order{h^n}$.\nIn fact the numerator of the fraction is either order one or of the\norder of $\\exp[\\lambda(b-a)]$.  The denominator is of the order of\n$h$, assuming that $\\lambda h \\ll 1$.  If the global truncation error\nis $\\order{h^n}$ the method is said to be of \\textbf{order\n  $\\boldsymbol{n}$}.\n\n\\section{Euler's methods}\n\nIn what follows, we assume that equation~(\\ref{odedef}) refers to a\nsingle variable, $y(x)$.  This makes the notation lighter: however,\nall the results obtained can be extended to systems of first ordinary\ndifferential equations.\n\nWe assume that we want to solve the initial value problem\n%\n\\begin{equation}\n  y' = f(x,y) , \\qquad y(x_0) = y_0 .\n  \\label{IVP.eq:6}\n\\end{equation}\n%\nWe introduce a step $h$ and we first obtain an estimate of $y(x)$ at\n$x_1 = x_0 + h$ using Taylor's theorem, exactly as we had done for the\nforward difference estimate of the derivative.  We obtain\n%\n\\begin{equation}\n  y(x_1) \\equiv y(x_0+h) = y(x_0) + y'(x_0) h + \\order{h^2} =\n  y(x_0) + h f(x_0,y(x_0)) + \\order{h^2} .\n  \\label{IVP.eq:7}\n\\end{equation}\n%\nBy analogy we obtain that the value $y_n$ of the function at the point\n$x_n = x_0 + n h$ is given by\n%\n\\begin{equation}\n  y_{n+1} \\equiv y(x_{n+1}) = y_{n} + h f(x_{n},y_{n}) + \\order{h^2} .\n  \\label{IVP.eq:10}\n\\end{equation}\n%\nThis iteration scheme to estimate the solution of the initial value\nproblem~(\\ref{IVP.eq:6}) at the points $x_n$ is called \\textit{Euler's\n  method}.  This method is extremely simple, but very inaccurate and\npotentially unstable.  It is reliable only if an extremely small step\n$h$ is used.  Its geometrical interpretation is that we use the slope\nof the function $y(x_n)$ at the beginning of the interval\n$[x_n,x_{n+1}]$ to estimate the value of $y(x_{n+1})$.  This suggests\nthat we can obtain a better estimate using an ``average'' of the slope\nover the same interval, i.e.\\ if we could compute\n%\n\\begin{equation}\n  y_{n+1} = y_n + h \\frac{f(x_n,y_n) + f(x_{n+1},y_{n+1})}{2} .\n  \\label{IVP.eq:8}\n\\end{equation}\n%\nHowever, we do not know $y_{n+1}$ and so we cannot use this relation\nas it stands.  However, we can use equation~(\\ref{IVP.eq:7}) to\nestimate the value of $y(x)$ at $x_{n+1}$ and use this value in\nequation~(\\ref{IVP.eq:8}) to obtain a refined estimate.  This\nprocedure is called the Euler predictor-corrector method and can be\nsummarised as:\n%\n\\begin{subequations}\n  \\label{IVP.eq:9}\n  \\begin{align}\n    y^{(p)}_{n+1} &= y_n + h f(x_n,y_n) & \\text{Predictor step} \\\\\n    y_{n+1} &= y_n + \\frac{h}{2}\n    \\left [f(x_n,y_n) + f(x_{n+1},y^{(p)}_{n+1}) \\right ] &\n    \\text{Corrector step}.\n  \\end{align}\n\\end{subequations}\n%\nWe can show that the predictor-corrector method is of order $\\order{h^3}$\nby comparing the Taylor expansion of~(\\ref{IVP.eq:6}) with that\nof~(\\ref{IVP.eq:9}).  However, we will not do this here as it is\nexactly the same procedure that is used to find the coefficients of\nthe second order Runge-Kutta method (shown below).\n\nOn the other hand, we can find the error for the modified Euler method by\nwriting the Taylor expansion of equation~(\\ref{IVP.eq:6}):\n%\n\\begin{equation}\n  y_{n+1} = y_n + y'_n h+ \\frac{1}{2} y''_n h^2 + \\order{h^3}.\n  \\label{IVP.eq:11}\n\\end{equation}\n%\nReplacing the second derivative by the forward-difference\napproximation, we obtain\n%\n\\begin{equation}\n  y_{n+1} = y_n + y'_n h + \\frac{1}{2} h^2 \\frac{y'_{n+1}-y'_n}{h} + \\order{h^3},\n  \\label{IVP.eq:12}\n\\end{equation}\n%\nand hence,\n%\n\\begin{equation}\n  y_{n+1} = y_n + \\frac{h}{2}(y'_{n+1}+y'_n) + \\order{h^3}.\n  \\label{IVP.eq:13}\n\\end{equation}\n%\nThis shows that the error of one step of the modified Euler method is\n$\\order{h^3}$. This is the \\textit{local error}. There is an accumulation\nof local errors from step to step, so that the error over the whole\nrange of application, the \\textit{global error}, is $\\order{h^2}$.\n\n\\section{Runge-Kutta Methods}\n\nThe Euler method is not very accurate. Much greater accuracy can be\nobtained more efficiently using a group of methods named after two\nGerman mathematicians, Runge and Kutta.  The idea behind these methods\nis to match the Taylor expansion of $y(x)$ at $x=x_n$ up to the\nhighest possible and/or convenient order.\n\nAs an example, let us consider the derivation of the second order\nmethod.  Here, the increment to $y$ is a weighted average of two\nestimates which we call $k_1$ and $k_2$. Thus for the equation\n%\n\\begin{equation}\n  \\dv{y}{x} = f(x,y),\n  \\label{IVP.eq:14}\n\\end{equation}\n%\nwe have\n%\n\\begin{align}\n  y_{n+1} & = y_n+a k_1+bk_2, \\label{kutta} \\\\\n  k_1    & = h f(x_n,y_n), \\label{IVP.eq:15} \\\\\n  k_2    & = h f(x_n + \\alpha h, y_n + \\beta k_1).\\label{IVP.eq:16}\n\\end{align}\n%\nWe fix the four parameter $a$, $b$, $\\alpha$ and $\\beta$ so that\n(\\ref{kutta}) agrees as well as possible with the Taylor series\nexpansion of the differential equation~(\\ref{IVP.eq:14})\n%\n\\begin{align}\n  y_{n+1} &= y_n + h y_n' + \\frac{h^2}{2} y_n'' + \\ldots \\nonumber \\\\\n  &= y_n + h f(x_n,y_n) + \\frac{h^2}{2} \\dv{}{x} f(x_n,\n  y_n) + \\dots, \\nonumber \\\\\n  &= y_n + h f_n + h^2 \\left (\\frac{1}{2} f_x +\n    \\frac{1}{2}f_y f_n \\right ) + \\dots\n  \\label{tay}\n\\end{align}\n%\nwhere $f_n \\equiv f(x_n,y_n)$.  On the other hand, using (\\ref{kutta})\nwe have\n%\n\\begin{equation}\n  y_{n+1} = y_n + a h f_n + b h f[x_n+\\alpha h, y_n+\\beta h f_n].\n  \\label{IVP.eq:18}\n\\end{equation}\n%\nExpand the right-hand side of~(\\ref{IVP.eq:18}) in a Taylor series\nin terms of $x_n,y_n$\n%\n\\begin{equation}\n  y_{n+1} = y_n + a h f_n + b h \\left [ f_n + f_x(x_n,y_n) \\alpha h +\n    f_y(x_n,y_n) f(x_n,y_n) \\beta h \\right ],\n  \\label{IVP.eq:19}\n\\end{equation}\n%\nor, rearranging,\n%\n\\begin{equation}\n  y_{n+1} = y_n + h (a+b) f_n + h^2 \\left [ f_x(x_n,y_n) \\alpha b +\n    f_y(x_n,y_n) f(x_n,y_n) \\beta b \\right ].\n  \\label{IVP.eq:20}\n\\end{equation}\n%\nThis result is identical to the Taylor series expansion (\\ref{tay}) if\n%\n\\begin{equation}\n  a+b=1, \\quad \\alpha b=\\frac{1}{2}, \\quad\\beta b=\\frac{1}{2}.\n  \\label{IVP.eq:21}\n\\end{equation}\n%\nNote that there are only three equations to be satisfied by the four\nunknowns. We can therefore assign an arbitrary value to one of the\nunknowns. For example, if we take $a=b=\\frac{1}{2}$, and\n$\\alpha=\\beta=1$, we obtain the Euler predictor-corrector method.\n\nFourth-order Runge-Kutta methods are the most widely used and are\nderived in a similar way. The most commonly used set of values leads\nto the algorithm\n%\n\\begin{equation}\n  y_{n+1} = y_n + \\frac{1}{6}(k_1+2k_2+2k_3+k_4),\n  \\label{IVP.eq:22}\n\\end{equation}\n%\nwith\n%\n\\begin{subequations}\n\\label{IVP.eq:23}\n  \\begin{align}\n    k_1 &= h f(x_n,y_n), &\n    k_2 &= h f(x_n+\\frac{1}{2}h,y_n+\\frac{1}{2}k_1), \\\\\n    k_3 &= h f(x_n+\\frac{1}{2}h,y_n+\\frac{1}{2}k_2), &\n    k_4 &= hf(x_n+h,y_n+k_3).\n  \\end{align}\n\\end{subequations}\n%\nThe local error term for the fourth-order Runge-Kutta methods is\n$\\order{h^5}$; the global error is $\\order{h^4}$.\n\n\\section{Error in Runge-Kutta methods}\n\nWhatever the method used one needs to check whether the results of the\nintegration are reliable, i.e.\\ one would like an estimate of the local\ntruncation error.  Moreover, the knowledge of this quantity would\nallow us to use a variable step in integrating the differential\nequation: if the local error is much smaller than a predefined\nthreshold then the step size can be increased.  If it is larger the\nstep size should be decreased.\n\nCall $y_e(x_0+h)$ the exact value of the solution $y(x)$ of the\ninitial value problem\n%\n\\begin{equation}\n  y'(x) = f(x,y) , \\qquad y(x_0) = y_0 .\n\\end{equation}\n%\nand indicate with $y_h(x_0+h)$ the solution obtained using a fourth\norder Runge-Kutta method with step $h$.  By construction we have that\n%\n\\begin{equation}\n  |y_e(x_0+h) - y_h(x_0+h)| = C h^5.\n  \\label{IVP.eq:41}\n\\end{equation}\n%\nHere $C$ is a number independent of $h$ but dependent on $x_0$ and on\nthe function $y_e$.  To estimate $C h^5$ and, hence, the local error\nwe assume that $C$ does not change as $x$ changes from $x_0$ to $x_0 +\nh$ (a similar procedure is used in Richardson's extrapolation).  Let\n$y_{h/2}(x_0+h)$ be the solution obtained using two steps of length\n$h/2$ of the fourth order Runge-Kutta method.  By assumption we have\nthat\n%\n\\begin{subequations}\n\\label{IVP.eq:42}\n  \\begin{align}\n    y_e(x_0+h) &= y_{h}(x_0+h) + C h^5 , \\\\\n    y_e(x_0+h) &= y_{h/2}(x_0+h) + 2 C (h/2)^5 .\n  \\end{align}\n\\end{subequations}\n%\nBy subtraction we obtain from these two equations that\n%\n\\begin{equation}\n  \\text{Local truncation error} = C h^5 =\n  \\frac{y_h - y_{h/2}}{1-2^{-4}} .\n  \\label{IVP.eq:43}\n\\end{equation}\n%\nThus the local truncation error is approximately $y_h - y_{h/2}$.\n\nThis estimate of the local error is rather expensive if used in a\nvariable step algorithm, because it requires two integrations to be\nrun at the same time for a total of 12 function evaluations.\n\nA second and more efficient method is to compare the result of the\nfourth order with those of a fifth order Runge-Kutta method.  As we\nhave seen in the derivation of the Runge-Kutta method of order 2, a\nnumber of parameters must be selected.  A similar selection process\noccurs in establishing higher order Runge-Kutta methods.\nConsequently, there is not just one Runge-Kutta method of each order,\nbut a family of methods.  As shown in the following table, the number\nof required function evaluations increases more rapidly than the order\nof the Runge-Kutta methods:\n\n\\begin{center}\n  \\begin{tabular}{l|llllllll}\n    Number of function evaluations & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\\\ \\hline\n    Maximum order of Runge-Kutta method & 1 & 2 & 3 & 4 & 4 & 5 & 6 & 6\n  \\end{tabular}\n\\end{center}\n\n\\noindent\nThis makes the higher-order Runge-Kutta methods less attractive than\nthe fourth order method, since they are more expensive to use.\nHowever, Fehlberg (1969) devised a fourth order Runge-Kutta method\nthat required five function evaluation and a fifth order Runge-Kutta\nmethod that required six function evaluations, five of which were the\nsame as those used for the fourth-order method.  Therefore, with only\nsix function evaluations we have a fourth-order Runge-Kutta method\nwith estimate of the local error.\n\n\\section{Multistep Methods}\n\n\\subsection{Introduction}\n\nThe modified Euler method and Runge-Kutta methods for solving initial\nvalue problem are single-step methods since they do not use any\nknowledge of prior values of $y(x)$ when the solution is being\nadvanced from $x$ and $x+h$. If $x_0,x_1,...,x_n$ are steps along the\n$x-$axis, then $y_{n+1}$ depends only on $y_n$, and knowledge of\n$y_{n-1},...,y_0$ is not used.\n\nIt is reasonable to expect that more accurate results may be obtained\nif previous values of $y(x)$ were used when estimating $y_{n+1}$.\nThis idea is at the heart of multi-step methods.  This principle is\ntransformed into an algorithm by writing the solution of the initial\nvalue problem,\n%\n\\begin{equation}\n  \\dv{y}{x} = f(x,y), \\quad y(x_0)=y_0,\n  \\label{IVP.eq:25}\n\\end{equation}\n%\nas\n%\n\\begin{equation}\n  y_{n+1} = y_n + \\mint{x_n}{x_{n+1}}{f(x,y(x))}{x}.\n  \\label{IVP.eq:24}\n\\end{equation}\n%\nThe integral on the right can be approximated by a numerical\nquadrature formula that depends on $\\{ x_{n-j}, y_{n-j} \\}$ and the\nresult will be a formula for generating the approximate solution step\nby step.\n\nThe general form of a multistep method to solve an initial value problem\n%\n\\begin{equation}\n  y' = f(x,y), \\qquad y(x_0) = y_0 ,\n  \\label{IVP.eq:44}\n\\end{equation}\n%\nis\n%\n\\begin{equation}\n  a_k y_{n+1} + a_{k-1} y_{n} + \\ldots  + a_0 y_{n+1-k} =\n  h [ b_k f_{n+1} + b_{k-1} f_{n} + \\ldots + b_0 f_{n+1-k}]\n  \\label{IVP.eq:45}\n\\end{equation}\n%\nSuch an algorithm is called a \\textit{$k$-step method}. The\ncoefficients $a_i$, $b_i$ are given. As before, $y_i$ denotes an\napproximation to the solution at $x_i=x_0+ih$, and\n$f_i=f(x_i,y_i)$. This formula is used to compute $y_{n+1}$, assuming\nthat $y_{n+1-k},y_{n-k},...,y_{n}$ are known. We assume that $a_k\\ne\n0$. If $b_k=0$, the method is said to be \\textit{explicit}, and\n$y_{n+1}$ can be computed directly. In the opposite case the method is\nsaid to be \\textit{implicit}.\n\n\\subsection{Adams-Bashforth formula}\n\nAn explicit multistep method of the type\n%\n\\begin{equation}\n  y_{n+1} = y_n + a f_n + b f_{n-1} + c f_{n-2} +...,\\label{adams}\n\\end{equation}\n%\nwhere $f_i=f(x_i,y_i)$ belongs to the class of Adam-Bashforth methods.\nThe Adam-Bashforth formula of order 5, based on the equally spaced\npoints $x_i = x_0 + i h$, $i=0,1,\\ldots,n$ is:\n%\n\\begin{equation}\n  y_{n+1} = y_n + \\frac{h}{720} [ 1901 f_n - 2774 f_{n-1} +\n  2616 f_{n-2} - 1274 f_{n-3} + 251 f_{n-4}].\\label{pred}\n\\end{equation}\n%\nTo obtain the coefficients that appear in this equation we start by\nobserving that we wish to approximate the integral\n%\n\\begin{equation}\n  \\mint{x_n}{x_{n+1}}{f[x,y(x)]}{x} \\approx h [A f_n + B f_{n-1} +\n  C f_{n-2} + D f_{n-3} + E f_{n-4}].\n  \\label{IVP.eq:26}\n\\end{equation}\nThe coefficients $A,B,C,D,E$ are determined by requiring that this\nequation is exact whenever the integrand is a polynomial of degree\nless than 5. For simplicity we assume that $x_n=0$, $x_{n-1}=-1$,\n$x_{n-2}=-2$, $x_{n-3}=-3$, $x_{n-4}=-4$, and $h=1$. We take as a\nbasis the following five polynomials:\n%\n\\begin{equation}\n  \\begin{aligned}\n    p_0(x)&=1, \\\\\n    p_1(x)&=x, \\\\\n    p_2(x)&=x(x+1), \\\\\n    p_3(x)&=x(x+1)(x+2), \\\\\n    p_4(x)&=x(x+1)(x+2)(x+3) \\\\\n  \\end{aligned}\n  \\label{IVP.eq:27}\n\\end{equation}\n%\nWhen these are substituted in the equation\n%\n\\begin{equation}\n  \\mint{0}{1}{p_m(x)}{x} \\approx A p_m(0)+B p_m(-1)+C p_m(-2)+D p_m(-3)+E p_m(-4)\n  \\label{IVP.eq:28}\n\\end{equation}\n%\nfor $m=0,1,2,3,4$, we obtain the system for determination of\n$A,B,C,D,E$\n%\n\\begin{equation}\n  \\left\\{\n    \\begin{aligned}\n      A + B + C + D + E & = 1,\\\\\n      -B - 2C - 3D - 4E & = 1/2,\\\\\n      2C + 6D + 12E     & = 5/6,\\\\\n      -6D - 24E         & = 9/4,\\\\\n      24E                & = 251/30.\n    \\end{aligned} \\right .\n  \\label{IVP.eq:29}\n\\end{equation}\n%\nThe coefficients of the Adam-Bashforth formula are obtained by back\nsubstitution.\n\n\\smallskip\n\n\\noindent \\textbf{Remark 1} - A special procedure must be employed to\nstart the method since initially only $y_0 \\equiv y(x_0)$ is known. A\nRunge-Kutta method is ideal for obtaining $y_1$, $y_2$, $y_3$ and\n$y_4$.\n\n\\smallskip\n\n\\noindent \\textbf{Remark 2} - The method is order five, i.e.\\ the local\nerror is $\\order{h^6}$ and the global error is $\\order{h^5}$.\n\n\\subsection{Adams-Moulton formula}\n\nThe Adam-Bashforth formulae are most often used in conjunction with\nother formulae to enhance their precision.  One such scheme can be set\nup by making use of the implicit version of equation~(\\ref{adams}):\n%\n\\begin{equation}\n  y_{n+1} = y_n + a f_{n+1} + b f_n + c f_{n-1} + \\ldots\n\\end{equation}\n%\nFollowing the same steps as in the derivation of the coefficients of\nthe Adams-Bashforth formula we obtain the \\textit{Adams-Moulton\n  formula} of order 5:\n%\n\\begin{equation}\n  y_{n+1} = y_n + \\frac{h}{720} [ 251 f_{n+1} + 646 f_n - 264 f_{n-1} +\n  106 f_{n-2} - 19 f_{n-3}].\n \\label{corr}\n\\end{equation}\n%\nThis cannot be used directly as $y_{n+1}$ occurs on both sides of the\nequation. However, we can set up a predictor-corrector algorithm that\nuses the Adam-Bashforth formula to predict a tentative value for\n$y^{(p)}_{n+1}$, and then the Adams-Moulton formula to compute a\ncorrected value of $y_{n+1}$ using $y^{(p)}_{n+1}$ on the right hand\nside of~(\\ref{corr}).  In other words, in~(\\ref{corr}) we evaluate\n$f_{n+1}$ as $f_{n+1}(x_{n+1},y^{(p)}_{n+1})$ using the predicted\nvalue $y^{(p)}_{n+1}$ obtained from the Adam-Bashforth formula.\n\nThe Adams-Moulton method is extremely efficient: only two function\nevaluations are needed per step for the former method, whereas six are\nneeded for the Runge-Kutta-Fehlberg method.  All have similar error\nterms.  On the other hand changing the step size with the multistep\nmethods is considerably more awkward than with single step methods.\n\n\\subsection{Order of multistep methods}\n\nThe \\textit{order} of a multistep method is the number of terms in the\nTaylor expansion of the solution that are correctly represented by the\nmethod.  The accuracy of a numerical solution is largely determined by\nthe order of the algorithm used to integrate the initial value\nproblems.  To determine the order of a given multistep method we\nintroduce the linear functional:\n%\n\\begin{equation}\n  L(y) = \\sum_{p=0}^k [a_p y(x_{n-k}+ p h) - h b_p y'(x_{n-k}+p h)].\n  \\label{IVP.eq:46}\n\\end{equation}\n%\nThis is a direct representation of~(\\ref{IVP.eq:45}) once we take into\naccount that $y'=f(x,y)$.  If the method~(\\ref{IVP.eq:45}) were exact\nthen we should have $L(y)=0$.  The order of the lowest non-zero term\nin the Taylor expansion of~(\\ref{IVP.eq:46}) is the order of the\nmethod.\n\n\\noindent\nUsing the Taylor series for $y(p h)$ and $y'(p h)$ with $p=0,1,...,k$\nwe obtain:\n%\n\\begin{equation}\n  y(x_0+p h) = \\sum_{j=0}^{+\\infty} \\frac{(p h)^j}{j!} y^{(j)} (x_0),\n  \\qquad\n  y'(x_0+p h) = \\sum_{j=0}^{+\\infty} \\frac{(p h)^j}{j!} y^{(j+1)}(x_0),\n\\end{equation}\n%\nso that\n%\n\\begin{equation}\n  L(y) = d_0 y(x_0) + d_1 h y'(x_0) + d_2 h^2 y''(x_0) + \\ldots \\, ,\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  d_0 = \\sum_{p=0}^k a_p, \\quad\n  d_1 = \\sum_{p=0}^k (p a_p-b_p), \\quad\n  d_2 = \\sum_{p=0}^k \\left ( \\frac{p^2}{2} a_p - p b_p \\right ), \\ldots\n\\end{equation}\n%\nand, in general,\n%\n\\begin{equation}\n  d_j = \\sum_{p=0}^k \\left( \\frac{p^j}{j!} a_p -\n    \\frac{p^{j-1}}{(j-1)!} b_p \\right) ,\n  \\qquad j \\ge 2 .\n\\end{equation}\n%\nIf $d_0=d_1=...=d_m=0$, then\n%\n\\begin{equation}\n  L(y) = d_{m+1} h^{m+1} y^{(m+1)}(x_0) + \\order{h^{m+2}}\n\\end{equation}\n%\nrepresents the local truncation error and the method has order $m$.\n\n\\smallskip\n\n\\noindent \\textbf{Remark} - For the Adam-Bashforth method\n$d_0=\\ldots=d_5 = 0$ and $d_6=95/288$.  Hence the method if of order\nfive and the local error is $\\order{h^6}$.\n\n\\subsection[Convergence, stability and consistency]{Convergence, stability and consistency of multistep methods}\n\nA method to solve numerically initial value problems is\n\\textit{convergent} if in the limit of infinitely small step size $h$\nthe numerical solution converges to the exact solution:\n%\n\\begin{equation}\n  \\lim_{h \\to 0} y(x;h) = y(x)\n\\end{equation}\n%\nwhere $y(x)$ is the exact solution of\n%\n\\begin{equation}\n  y' = f(x,y), \\qquad y(x_0) = y_0\n\\end{equation}\n%\nand $y(h;x)$ is the numerical solution obtained using an integration\nstep $h$.\n\nA method is called \\textit{stable} if the numerical solutions are\nbounded at all iteration steps over a finite interval.  It is called\n\\textit{consistent} if at lowest order it is a faithful representation\nof the differential equation we wish to integrate.\n\nConvergence, stability and consistency are related one to the other.\nIn fact, one can show that \\textit{a multistep method is convergent if\n  and only if it is stable and consistent}.\n\nIt is fairly straightforward to determine the stability and\nconsistency of a multistep method like~(\\ref{IVP.eq:45}).  Construct\nthe two polynomials:\n%\n\\begin{align}\n  p(z) &= a_k z^k + a_{k-1} z^{k-1} + \\ldots ... + a_0,\n  \\label{IVP.eq:47} \\\\\n  q(z) &= b_k z^k + b_{k-1} z^{k-1} + \\ldots + b_0. \\label{IVP.eq:48}\n\\end{align}\n%\nThe first polynomial is called the \\textit{stability polynomial}.  One\ncan show that a multistep method is consistent if $p(1)=0$ and\n$p'(1)=q(1)$.  The question of stability is more complex.\n\nA multi-step method is to all intents and purposes a difference\nequation that is (hopefully) based on the differential equation that\nwe wish to solve, in the sense that as the integration step tends to\nzero the difference equation tends to the differential equation\n(i.e.\\ that the difference equation is \\textit{consistent} with the\ndifferential equation).  We expect that a consistent difference\nequation has a solution that is close to the solution of the original\ndifferential equation.  However, it is also possible that it has other\nsolutions and that these may grow as the number of integration steps\nincreases so that they swamp the ``right'' solution.  We can,\ntherefore, consider two cases of stability: a method may be stable in\nthe sense that it represents faithfully the solution of the\ndifferential equation over a finite interval.  However, as the size of\nthe integration region increases the spurious solutions of the\ndifference equation grow and the numerical solution no longer has much\nto do with the exact solution of the differential equation.  We can\nalso require a stronger stability: we can, in fact, require that the\nspurious solutions tend to zero as the number of integration steps\nincreases.  In this case we can use the method to integrate a given\ndifferential equation for as long as we wish (within the limits of the\ngrowth of the global integration error).\n\nCall $\\{r_p\\}$, $=0,1,\\ldots,k$ the roots of $p(z)$.  The stability\npolynomial satisfies the \\textit{root condition} if\n%\n\\begin{equation*}\n  |r_p| \\le 1, \\qquad 0 \\le p \\le k ,\n\\end{equation*}\n%\nand all roots that satisfy $|r_j|=1$ are simple.  The stability\npolynomial satisfies the \\textit{strong root condition} if\n%\n\\begin{equation*}\n  r_0 = 1, \\, |r_p| < 1, \\qquad 1 \\le p \\le k.\n\\end{equation*}\n\nThe root conditions are related to the stability of the multi-step\nmethod.\n\n\\begin{enumerate}\n  %\n\\item If the stability polynomial satisfies the root condition, then\n  the method is stable, in the sense that for $h$ sufficiently small\n  it will deliver accurate results over a small interval.\n  %\n\\item If the stability polynomial satisfies the strong root condition,\n  then the method is \\textit{relatively stable}, meaning that, for $h$\n  sufficiently small, the spurious solutions of the difference\n  equation go to zero.\n  %\n\\item A method that is stable, but not relatively stable is called\n  \\textit{weakly stable} and may exhibit diverging solutions for long\n  integrations.\n  %\n\\end{enumerate}\n\n\\medskip\n\n\\section{Summary}\n\nSingle-step (multi-stage) and multi-step methods have advantages and\ndisadvantages.  The following table tries to summarise the main\nfeatures of these methods.\n\n\\smallskip\n\n\\begin{center}\n  \\begin{tabular}{l|c c}\n    & \\textbf{Multi-Stage} & \\textbf{Multi-Step} \\\\ \\hline\n    Self-starting & Yes & No \\\\\n    Easy for variable steps & Yes & No \\\\\n    Computationally efficient & No & Yes \\\\\n    Theory ``intuitive'' & No & Yes\n  \\end{tabular}\n\\end{center}\n\n% \\begin{center} \\begin{tabular}{|p{35mm}|p{35mm}||p{35mm}|p{35mm}|} \\hline\n%  \\multicolumn{2}{|c||}{\\textbf{Single-Step}} &\n%  \\multicolumn{2}{|c|}{\\textbf{Multi-Step}} \\\\ \\hline\n%  \\multicolumn{1}{|c|}{\\textbf{Pros}} &\n%  \\multicolumn{1}{|c||}{\\textbf{Cons}} &\n%  \\multicolumn{1}{|c|}{\\textbf{Pros}} &\n%  \\multicolumn{1}{|c|}{\\textbf{Cons}} \\\\ \\hline \\hline\n%  The theory is intuitive & Computationally intensive &\n%  Computationally efficient & The theory is rather involved \\\\\n%  Self-starting & & & Not self-starting \\\\\n%  Easily adapted to variable step algorithms & & &\n%  Not easily adapted to variable step algorithms \\\\ \\hline\n% \\end{tabular} \\end{center}\n\n\\smallskip\n\nThe following table, summarises the main numerical features of some of\nthe algorithms that we have described.\n\n\\smallskip\n\n\\begin{center} \\begin{tabularx}{1.1\\textwidth}{llccccXc} \\hline\n\\textbf{Method} & \\textbf{Type} & \\parbox[b]{12mm}{\\textbf{Local Error}} &\n\\parbox[b]{12mm}{\\textbf{Global Error}} &\n\\parbox[b]{10mm}{\\textbf{F.E. / Step\\footnote{Function Evaluations per Step}}} &\n\\textbf{Stability} &\n\\parbox[b]{15mm}{\\textbf{Ease of changing step size}} &\n\\parbox[b]{10mm}{\\textbf{Recom-mended?}} \\\\*[2mm] \\hline \\\\\nModified Euler & Single-step & $\\order{h^3}$ & $\\order{h^2}$ & $2$ &\n Good & Good & No \\\\*[3mm]\n\\parbox[t]{25mm}{Fourth-order Runge-Kutta} & Single-step & $\\order{h^5}$ &\n$\\order{h^4}$ & $4$ & Good & Good & Yes \\\\*[7mm]\n\\parbox[t]{25mm}{Runge-Kutta-Fehlberg} & Single-step & $\\order{h^6}$ &\n$\\order{h^5}$ & $6$ & Good & Good & Yes \\\\*[7mm]\nMilne & Multistep & $\\order{h^5}$ & $\\order{h^4}$ & 2 & Poor & Poor & No \\\\*[4mm]\nAdams-Moulton & Multistep & $\\order{h^5}$ & $\\order{h^4}$ & 2 & Good & Poor &\nYes \\\\*[3mm] \\hline\n\\end{tabularx} \\end{center}\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapter 10 of Linz \\& Wang, \\textit{Exploring Numerical Methods}\n  (QA297 LIN),\n\\item Chapter 8 of Kincaid \\& Cheney, \\textit{Numerical Analysis}\n  (QA297 KIN),\n\\item Chapter 12 of S{\\\"u}li \\& Mayers, \\textit{An Introduction to\n    Numerical Analysis} (not in library),\n\\item Part I (especially chapters 1--3, but chapters 4 and 5 are also\n  useful) of Iserles, \\textit{A First Course in the Numerical Analysis\n    of Differential Equations} (QA297 ISE).\n\\end{itemize}\nNote that notation and implied motivation, particularly around the\nmultistep methods, can be inconsistent with the presentation here.\n", "meta": {"hexsha": "b21a771276340fc393eeeb78f4007def9118cf8a", "size": 34280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/IVP.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/IVP.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/IVP.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 35.3038105046, "max_line_length": 112, "alphanum_fraction": 0.6994749125, "num_tokens": 11336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.9046505286741726, "lm_q1q2_score": 0.7891695196947142}}
{"text": "\\subsection{Average Values}\r\n\\noindent\r\nWe can think of the average value of a function over some interval as the answer to the question: “If I flattened this function into a box over the interval, what would the height of the box be?”\\\\\r\nFor single-variable functions, the answer is $\\bar{f} = \\frac{1}{b-a}\\int_{a}^{b}{f(x)\\mathrm{d}x} = \\frac{\\int_{a}^{b}{f(x)\\mathrm{d}x}}{\\int_{a}^{b}{\\mathrm{d}x}}$.\\\\\r\nThis idea of summing a function over a domain and the dividing by the size of that domain holds into multivariable as\r\n\\begin{equation*}\r\n\t\\bar{f} = \\frac{\\int\\limits_{D}{f(x,y)\\mathrm{d}D}}{\\int\\limits_{D}{\\mathrm{d}D}}\r\n\\end{equation*}\r\n\r\n\\input{./multipleIntegrals/meanValueTheorem}", "meta": {"hexsha": "5f9d922f15bd1a5150bd030a194726695ed07c33", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/averageValues.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/multipleIntegrals/averageValues.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/multipleIntegrals/averageValues.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": 69.4, "max_line_length": 198, "alphanum_fraction": 0.704610951, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087965937711, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7891207180958031}}
{"text": "\\subsection{The generalized eigenproblem}\n\\label{sec:generalized-eigenproblem}\n\nAn arbitrarily scaled vector $\\w_i$ is a \\emph{generalized eigenvector} (GEVec) for the ordered matrix pair $(\\Rss, \\Rnn)$ when the following holds:\n%\n\\begin{equation}\n\\label{eq:generalized-eigenproblem}\n\\Rss \\w_i = \\lambda_i \\Rnn \\w_i,\n\\end{equation}\n%\nfor some scalar $\\lambda_i$, which is called the \\emph{generalized eigenvalue} (GEVal) corresponding to $\\w_i$. The largest scalar $\\lambda_1$ for which \\cref{eq:generalized-eigenproblem} holds is the `first' GEVal, and as mentioned before, the corresponding GEVec $\\w_1$ is the solution $\\what$ to the optimization problem \\cref{eq:argmax_R}.\n\nSince the 1960's, numerically stable algorithms exist that solve the generalized eigenproblem \\cref{eq:generalized-eigenproblem} \\cite{Golub2013}. A specialized algorithm is applicable when the input matrices are symmetric -- as is the case for $\\Rss$ and $\\Rnn$. This algorithm (based on a Cholesky factorization and the classical QR-algorithm for ordinary eigenproblems) is implemented in the LAPACK software package (as \\texttt{ssygv} and \\texttt{dsygv}), and can be easily applied using e.g. the \\texttt{eig} function from MATLAB, or the \\texttt{eigh} function from SciPy's \\texttt{linalg} module.\n", "meta": {"hexsha": "ca2be65069279f4a82c0ace7513712ac25d2d8f8", "size": 1281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/GEVec/The-generalized-eigenproblem.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/GEVec/The-generalized-eigenproblem.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/GEVec/The-generalized-eigenproblem.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": 91.5, "max_line_length": 601, "alphanum_fraction": 0.7767369243, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7889680899986422}}
{"text": "\\lab{Applications}{Least-squares fitting I}{Least-squares fitting I}\n\\label{LeastSquaresCircle}\n\n\\objective{This section will introduce Least Squares and teach a more\nadvanced application of Least Squares: fitting a circle to data.}\n\\section*{Least Squares}\n\nIt is well known that the displacement of a spring is proportional\nto the force acting upon it, that is, $F = k x$.  The proportionality\nconstant $k$ is called Hooke's spring constant.  Consider a laboratory\nexperiment where different loads are placed on a spring and the displacement\nis measured and recorded in the table below:\n\\vspace{5mm}\\\\\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\t\\hline\nx & F \\\\\n(cm) & (dyne)\\\\\n\\hline\n1.04  & 3.11 \\\\\n2.03  &  6.01\\\\\n2.95  &  9.07\\\\\n3.92  &  11.99\\\\\n5.06  &  15.02\\\\\n6.00  &  17.91\\\\\n7.07  &  21.12\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\vspace{5mm}\nTo find the spring constant $k$, we simply need to solve the following linear system\n\\[\n\\begin{pmatrix}\n1.04\\\\\n2.03\\\\\n2.95\\\\\n3.92\\\\\n5.06\\\\\n6.00\\\\\n7.07\\\\\n\\end{pmatrix}\n\\begin{pmatrix}k\\end{pmatrix} =\n\\begin{pmatrix}\n3.11 \\\\\n6.01\\\\\n9.07\\\\\n11.99\\\\\n15.02\\\\\n17.91\\\\\n21.12\\\\\n\\end{pmatrix}.\n\\]\nHowever, there is no solution to this system because it is overdetermined.\nInstead, we seek the ``best'' $k$ that fits the data.\nLeast squares allows us to find that ``best'' solution.\nWe can find the least squares solution by computing the following in Python:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n>>> A = np.vstack([1.04,2.03,2.95,3.92,5.06,6.00,7.07])\n>>> b = np.vstack([3.11,6.01,9.07,11.99,15.02,17.91,21.12])\n>>> k = np.dot(np.dot(la.inv(np.dot(A.T,A)),A.T),b)\n>>> k\narray([[ 2.99568294]])\n\\end{lstlisting}\nHence, we find the spring constant to be $k = 2.9957$.\nNote that \\li{scipy.linalg} provides a built-in function for solving\nleast-squares problems.\nWe plot the data against the best fit as follows:\n\\begin{figure}[h!]\n\\label{fig1}\n\\begin{center}\n\\includegraphics[width=\\textwidth]{line_lstsq}\n\\caption{The graph of the spring data together with its linear fit}\n\\label{Fig:SpringFit}\n\\end{center}\n\\end{figure}\n\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x0 = np.linspace(0,8,100)\n>>> y0 = k[0]*x0\n>>> plt.plot(A,b,'*',x0,y0)\n>>> plt.show()\n\\end{lstlisting}\nSee Figure \\ref{Fig:SpringFit} to see how well the line fits the data.\n\n\n\\section*{General Line Fitting}\n\nSuppose that we wish to fit a general line, that is $y=m x+b$, to the data set\n$\\{(x_k,y_k)\\}^n_{k=1}$.  Assume that the line does not cross through the origin,\nas in the previous example.  Then we seek both a slope and a $y$-intercept.\nIn this case, we set up the following linear system $A x = b$, or more precisely\n\\[\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\nx_3 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nm\\\\\nb\n\\end{pmatrix}=\n\\begin{pmatrix}\ny_1\\\\\ny_2\\\\\ny_3\\\\\n\\vdots\\\\\ny_n\n\\end{pmatrix}.\n\\]\nNote that $A$ has rank $2$ as long as not all of the $x_k$ values are the same.\nHence, the least squares solution\nis given by\n$$\n\\widehat{x} = (A^HA)^{-1}A^Hb.\n$$\nIn what sense does this solution give us the best fit line for the data? Recall that since $A$ is injective,\nthe matrix $A(A^HA)^{-1}A^H$ is an orthogonal projector onto the range of $A$, which means that\n$A(A^HA)^{-1}A^Hb = A\\widehat{x}$ is the closest vector (with respect to the 2-norm) to $b$ that lies in the\nrange of $A$. That is, $\\widehat{x}$ minimizes the error between $Ax$ and $b$, where the error is given\nby the distance between these vectors, $\\|b-Ax\\|_2$. Another way to say this is that $\\widehat{x}$ gives the\nvalues $m$ and $b$ for which the sum of the squares of the distances from each data point $y_k$ to the value\n$y = mx_k + b$ is as small as possible.\n\n\\section*{Loading Data from .npz Files}\nFor Least Squares problems as well as in many other contexts, loading data is often a necessary step before\nproceeding with further analysis. Here we briefly review another data format in Python and the commands used\nto load the data.\n\nA \\li{.npz} file is a compressed binary file that contains an archive of NumPy data structures.\nA given file may therefore contain several arrays, each array associated with a unique string that identifies it.\nWhen you load a \\li{.npz} file in Python, a dictionary-like object is returned, and you can access the data by\nproviding the appropriate key. Note that when you load a \\li{.npz} file, you must also be sure to close it when\nyou are finished. This is taken care of automatically if you use the \\li{with ... as} keywords.\n\nAs an example, suppose that we have a file named \\li{grades.npz} that contains several arrays, each giving the\nhomework scores of a particular student in a particular class. Assuming that one of the arrays is associated with\nthe key \\li{'Abe'}, we can load this array in the following way:\n\n\\begin{lstlisting}\n>>> with np.load('grades.npz') as grades:\n>>>     abe_grades = grades['Abe']\n>>> abe_grades\narray([ 10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.])\n\\end{lstlisting}\n\nYou will need to apply this technique in the next problem.\n\n\\begin{problem}\nWrite a function \\li{fitLine} that takes no arguments and executes the following.\nLoad the \\texttt{linepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given data set.\nUse least squares to find the slope and $y$-intercept that best fits the data.\nThen plot the data points and the line on the same graph.\nThe function should not return anything.\n\\end{problem}\n\n\\section*{Fitting data to a circle}\n\nRecall that the equation of a circle, with radius $r$ centered at $(c_1,c_2)$, is given by\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nSuppose we are given a set of data points closely forming a circle $\\{(x_i,y_i)\\}^n_{i=1}$.\nThe ``best'' fit is found via least squares by expanding \\eqref{circle} to get\n\\[\n2 c_1 x + 2 c_2 y + c_3 = x^2 + y^2,\n\\]\nwhere $c_3 = r^2 - c_1^2 - c_2^2$.  Then we can write the linear system $A x = b$ as\n\\[\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix},\n\\]\nwhere the matrix $A$ and the vector $b$ are obtained by the given data and the unknown\n$x$ contains the information about the center and radius of the circle and is obtained\nby finding the least squares solution.\n\n\\section*{Example}\n\nIn this section, we fit the following points to a circle:\n\\begin{align*}\n&(134,76),(104,146),(34,176),(-36,146),\\\\\n&(-66,76),(-36,5),(34,-24),(104,5),(134,76)\n\\end{align*}\n\nWe enter them into Python as a $9\\times 2$ array:\n\\begin{lstlisting}\n>>> P = np.array([[134,76],[104,146],[34,176],[-36,146],\n                  [-66,76],[-36,5],[34,-24],[104,5],[134,76]])\n\\end{lstlisting}\nWe compute $A$ and $b$ by entering the following:\n\\begin{lstlisting}\n>>> A = A =np.hstack((2*P, np.ones((9,1))))\n>>> b = (P**2).sum(axis=1)\n\\end{lstlisting}\nHence, we get the least squares solution\n\\begin{lstlisting}\n>>> x = np.dot(np.dot(la.inv(np.dot(A.T,A)),A.T),b)\n\\end{lstlisting}\nThen we find $c_1$, $c_2$, and $r$ by:\n\\begin{lstlisting}\n>>> from math import sqrt\n>>> c1, c2, c3 = x\n>>> r = sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\nWe plot this by executing\n\\begin{lstlisting}\n>>> theta = np.linspace(0,2*np.pi,200)\n>>> plt.plot(r*np.cos(theta)+c1,r*np.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n>>> plt.show()\n\\end{lstlisting}\n\n\n\\begin{problem}\nWrite a function \\li{fitCircle} that does the following.\nLoad the \\texttt{circlepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given\ndata set.  Use least squares to find the center and radius of the circle that best\nfits the data.  Then plot the data points and the circle on the same graph.\nThe function should return nothing.\n\\end{problem}\n\n\\begin{problem}\nThe general equation for an ellipse is:\n\\[\nax^2 + bx + cxy + dy + ey^2 = 1\n\\]\n\nWrite a function \\li{fitEllipse} that uses least squares to fit data to an ellipse.\nThe function should take a $n\\times 2$ array as input, where the first column gives the $x$-coordinates\nand the second column gives the $y$-coordinates. Find the least squares solution for $a, b, c, d,$ and $e$,\nand return the solution.\n\\end{problem}\n\nIn these Least Squares problems, we have found best fit lines and ellipses relative to the 2-norm.\nIt is possible to generalize the idea of best fit curves relative to other norms.\nSee Figure \\ref{Fig:ellipse} for an illustration of this.\n\n\\begin{figure}[h]\n\\label{ellipsefit}\n\\centering\n\\includegraphics[width=\\textwidth]{ellipsefit.pdf}\n\\caption{Fitting an ellipse using different norms.}\n\\label{Fig:ellipse}\n\\end{figure} ", "meta": {"hexsha": "930a887b5bd0fc25419f98a776fc5bf39bdb2e99", "size": 8785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/LeastSquares/LeastSquares.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/LeastSquares/LeastSquares.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/LeastSquares/LeastSquares.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": 33.1509433962, "max_line_length": 113, "alphanum_fraction": 0.7010813887, "num_tokens": 2845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818409, "lm_q2_score": 0.899121379297294, "lm_q1q2_score": 0.7889581394620313}}
{"text": "\\lab{Nearest Neighbor Search}{Nearest Neighbor Search}\n\\label{lab:NNS}\n\n\\objective{Introduce the nearest neighbor search problem, K-D trees, and the curse of dimensionality.}%Teach about branch and bound and the curse of dimensionality using the nearest neighbor search problem.}\n\n\\section*{The Nearest Neighbor Search Problem}\n\nThe nearest neighbor search problem is an optimization problem that arises in many applications, including computer vision, pattern recognition, internet marketing, and data compression.\nThe premise is this: suppose that you move into a new city with several post offices.\nSince you are a busy individual, to minimize travel time you would like to know which post office is closest to your home.\nMore generally, the problem is to find the point in a set of points (the post offices) that is nearest to some other point (your home).\n\n% Problem 1: Euclidean Distance\n\\begin{problem}\nTo solve the nearest neighbor problem, we must define a metric.\nThat is, we need a way of determining the distance between two points.\nFor this lab, we will use standard euclidean distance.\n\n% should we say 1 x n (like usual) or 1 x k (to reflect the k-d tree idea)\nWrite a function that accepts two vectors (as $1$ x $k$ numpy arrays) and returns the distance between them.\nIf the two vectors do not have the same dimensions, raise a ValueError.\nMake sure the function can handle data in $\\mathbb{R}^n$ for any $n\\in\\mathbb{N}$\n\\end{problem}\n\n\nThe naive approach to solving the post office problem is to travel from your house to one of the post offices, then from your house to a different post office, and so on until all post offices have been visited. Then choose the post office that it took the least amount of time to get to from your house. This exhaustive method is clearly inefficient, and only feasible if the data set is very small.\n\n% Problem 2: Exhaustive search method\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by exhaustively checking all of the distances between a point of interest and each point in a data set.\n\n% what should the format of the data be?\nThe function should take in the set of data points (as a $m$ x $k$ numpy array) and a single target point (as a $1$ x $k$ numpy array).\nReturn the point in the set that is closest to the point of interest (the nearest neighbor) and the distance between those two points. As in the previous problem, your function should be able to take in data in $\\mathbb{R}^n$ for any $n\\in\\mathbb{N}$.\n\\end{problem}\n\n% Bad choice of variables k and n\nThe complexity of this algorithm is $O(kn)$, where $k$ is the number of dimensions and $n$ is the number of data points.\n\n\\section*{K-D Trees}\n\n\\begin{figure}\n\\caption{This 2-dimensional tree partitions $\\mathbb{R}^2$ at each level. (TODO: Make a figure like the one on Wikipedia or reference Wikipedia)}\n\\label{fig:k-binary-search}\n\\end{figure}\n\nFortunately, there is a particular data structure that lends itself well to solving this problem quickly.\nA \\emph{k-d tree}, or \\emph{k-dimensional tree}, is a specialized binary search tree.\nUsing a k-d tree to solve a nearest neighbor search problem speeds things up by travelling toward the target incrementally instead of exhaustively searching every option.\nJust as a regular binary search tree partitions the number line at every step of descent, a k-d tree partitions $\\mathbb{R}^k$ at every step of descent.\n\nAt each level of the tree, for some $i$ the nodes to the left of the parent nodes have a lower value in the $i^{th}$ dimension and the nodes to the right of the parent node have a greater value in the $i^{th}$ dimension.\nThe choice of dimension $i$ cycles through the possible choices as we descend deeper through the tree.\nIn the $3$-dimensional case the root node is divided in the $x$ dimension, the children in the $y$ dimension, the grandchildren in the $z$ dimension, the great-grandchildren in the $x$ dimension, and so on.\nSee figure \\ref{fig:k-binary-search} for an example in $\\mathbb{R}^2$.\n\nConstructing an optimal k-d tree requires sorting the data before each insertion, so the complexity is $O(n\\log^2{n})$. However, once the tree is built we can use it as needed with much lower Big-O rates.\n\nIn this lab we will construct our own k-d tree class by inheriting from the previous lab's \\li{BST} class. First, we need to create specialized nodes.\n\n% KDT Node class -- should probably become example code instead of a problem\n\\begin{problem}\nCopy or import your \\li{BSTNode} class from the previous lab.\nWrite a \\li{KDTNode} class that inherits from \\li{BSTNode}.\n% Optional vvv\nModify the constructor so that a \\li{KDTNode} can only hold a list or numpy list.\n% Optional ^^^\nAdd an attribute called \\li{axis}.\nThis attribute will track how deep the node is in the tree so we know which entry of \\li{data} to use as the bisector.\n\nWrite the \\li{__lt__} and \\li{__gt__} magic methods so that the $<$ and $>$ operators compare the $i^{th}$ entry of the data, where $i$ is the \\li{axis} attribute of the node on the \\emph{right side} of the operator.\nFor example,\n\n\\begin{lstlisting}\n>>> x = KDTNode([1,2])\n>>> y = KDTNode([3,1])\n>>> y.axis = 0\t\t\t# Compare the '0th' entry of the data \n>>> x < y\t\t\t\t# True, since 1 < 3\nTrue\n>>> x > y\nFalse\n\n>>> y.axis = 1\t\t\t# Compare the '1st' entry of the data\n>>> x < y\t\t\t\t# False, since 2 > 1\nFalse\n>>> x > y\nTrue\n\\end{lstlisting}\n\nFinally, write the \\li{__sub__} magic method so that \\li{x} - \\li{y} yields the euclidean distance between the data in node \\li{x} and the data in node \\li{y}.\n\n(Hint: use the function from problem 1)\n\\end{problem}\n\n\nNow we must construct the actual k-d tree class.\nThe structure requires an attribute that houses the dimension of the tree (the \\emph{k} of the k-d tree).\n\n\\begin{lstlisting}\ndef class KDT(BST)\n\t\"\"\"A k-dimensional tree object.\"\"\"\n\n\tdef __init__(self, k)\n\t\"\"\"Set the dimension attribute 'k'.\"\"\"\n\t\tBST.__init__(self)\n\t\tself.k = k\n\\end{lstlisting}\n\n\nThe only major difference between a k-d tree and a binary search tree is how the data is compared at each depth level.\nAs long as we set the \\li{axis} attribute correctly in each node as it is inserted into the tree, we should be able to do this fairly easily because of our work in the previous problem.\nThough we don't need to use a \\li{find} function in solving the nearest neighbor problem, we provide the k-d tree version of \\li{find} as an instructive example.\n\n\\begin{lstlisting}\nclass KDT(BST):\n\t# ...\n\n\tdef find(self, data):\n\t\t\"\"\"Return the node containing 'data'. Raise a ValueError if there is\n\t\tno such node in the tree or if the tree is empty.\"\"\"\n\t\t\n\t\tdef _step(current, target):\n\t\t\t\"\"\"Recursively approach the target node.\"\"\"\n\t\t\t\n\t\t\tif current is None:\t\t\t\t# Base case: target not found.\n\t\t\t\treturn current\n\t\t\tif current.data == target.data:\t# Base case: target found!\n\t\t\t\treturn current\n\t\t\tif target < current:\t\t\t# Recursively search to the left\n\t\t\t\treturn _step(current.left, target)\n\t\t\telse:\t\t\t\t\t\t\t# Recursively search to the right\n\t\t\t\treturn _step(current.right, target)\n\t\t\t\n\t\tif self.root is None:\t\t\t\t# Check for empty tree\n\t\t\traise ValueError(str(data) + \" is not in the tree.\")\n\t\t\n\t\t# Create a new node so that the KDTNode comparison operators can be used\n\t\tn = KDTNode(data)\n\t\tfound = _step(self.root, n)\n\t\tif found is None:\t\t\t\t\t# Report that the data was not found\n\t\t\traise ValueError(str(data) + \" is not in the tree.\")\n\t\treturn found\t\t\t\t\t\t# Return the node containing 'data'\n\\end{lstlisting}\n\nAt every comparison in the \\li{_step} function, the data of \\li{target} and \\li{current} are compared based on the \\li{axis} attribute of \\li{current}, since \\li{current} is the right-hand operand.\n% A little repetitive here\nThis way if each existing node in the tree has the correct \\li{axis}, the correct comparisons will be made as we descend.\n\n% This next bit should probably be part of the next problem.\n\\begin{comment}\nTo solve the nearest neighbor search problem, we only need to create the k-d tree once. Then we can use it multiple times with different target points. To prevent the user from messing with the tree, disable the \\li{remove} method:\n\\begin{lstlisting}\nclass KDT(BST):\n\t# ...\n\t\n\tdef remove(self, *args):\n\t\traise ValueError(\"remove() has been disabled for this class.\")\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem}\nFinish the \\li{KDT} class by overriding \\li{insert} and disabling \\li{remove}.\n\nTo insert a new node, first check to make sure the data is the proper format. Then find the correct insertion location using an approach similar to the \\li{find} method. Remember to double-link the nodes. Set the \\li{axis} of the new node appropriately. Do not allow for duplicates in the tree.\n\nTo solve the nearest neighbor search problem, we need only create the k-d tree once. Then we can use it multiple times with different target points. To prevent the user from altering the tree, disable the \\li{remove} method. Raise a \\li{ValueError} if the method is called, and allow it to receive any number of arguments.\n\n\\end{problem}\n\n\nNow that we have a k-d tree, we can use it to solve the nearest neighbor problem.\nFirst we must load the tree with data so that it can be searched.\n\n% This can be done by writing the following short function, or by adding stuff to the constructor of the KDT class.\n% I like the constructor idea, but I have only written it so far as a function.\n% This could also possibly be absorbed into the next problem.\n\\begin{problem}\nWrite a function that creates a \\li{KDT} instance and loads it with a set of data.\nThe data will be a $m$ x $k$ numpy array.\nFor an optimal k-d tree, the data needs to be inserted in a very particular order.\nHowever, inserting at random still usually produces a good tree.\nFor this problem, insert the data in the order that it is given (iterate through the rows).\n\\end{problem}\n\nTo solve the nearest neighbor problem, we need to do a careful recursive search through the tree.\nAt each step, we need to keep track of a current search node, the target point, the current best point (our current candidate for the nearest neighbor), and the current minimum distance (the distance from the nearest neighbor to the target).\nWe start the algorithm on the root node.\nFor each recursive step, we first check if the euclidean distance between the current search node and the target point is less than the current minimum distance.\nIf so, we update the nearest neighbor and calculate the new minimum distance.\nWe then descend through the tree and search recursively, similar to the \\li{find} function.\n\nWe aren't done, however; after descending we need to check that there truly is no other nearest neighbor.\nTechnically, we are checking to see if the hypersphere of radius `minimum distance' around the supposed nearest neighbor does not intersect with any other hyperplanes created by the tree.\nIn the code we accomplish this by adding the minimum distance to the $i^{th}$ entry of the target point's data, where $i$ is the \\li{axis} of the supposed nearest neighbor.\nIf this sum is greater than the $i^{th}$ entry of the current search node's data, then we need to descend in the \\emph{opposite} direction that we came.\n\nWe summarize the algorithm below.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n%d = euclidean\\_metric\n\\Procedure{KDTSearch}{current, target, neighbor, distance}\n\\State index = current.axis\n\\State d = euclidean\\_distance\n\t\\If {d(current,target) $<$ distance}\n\t\t\\State neighbor = current\n\t\t\\State distance = d(current,target)\n\t\\EndIf\n\t\n\t\\If {target.data[index] $<$ current.data[index]}\n\t\t\\State neighbor, distance = KDTSearch(current.left, target,\n\t\t\t\\State\t\t\t\t\t\t\t\t\tneighbor, distance)\n\t\t\\If {target.data[index] + distance $>=$ current.data[index]}\n\t\t\t\\State neighbor, distance = KDTSearch(current.right, target,\n\t\t\t\t\\State\t\t\t\t\t\t\t\t\tneighbor, distance)\n\t\t\\EndIf\n\t\\Else\n\t\t\\State neighbor, distance = KDTSearch(current.right, target,\n\t\t\t\\State\t\t\t\t\t\t\t\t\tneighbor, distance)\n\t\t\\If {target.data[index] + distance $<=$ current.data[index]}\n\t\t\t\\State neighbor, distance = KDTSearch(current.left, target,\n\t\t\t\t\\State\t\t\t\t\t\t\t\t\tneighbor, distance)\n\t\t\\EndIf\n\t\\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\\caption{k-d tree nearest neighbor search}\n\\label{alg:kdneighborz}\n\\end{algorithm}\n\n\\begin{comment}\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{KDSearch}{search\\_point,parent\\_node,b\\_point,b\\_distance,i}\n    \\If { Distance(search\\_point,parent\\_node.point) $<$ b\\_distance }\n        \\State b\\_point = parent\\_node.point\n        \\State b\\_distance = Distance from search\\_point to parent\\_node.point\n    \\EndIf\n\n    \\If{search\\_point[i] $<$ parent\\_node.point[i]}\n        \\State b\\_point, b\\_distance =\n            \\State KDSearch(search\\_point,parent\\_node.left\\_child,b\\_point,b\\_distance,i+1)\n        \\If { search\\_point[i] + b\\_distance $geq$ parent\\_node.point} \n            \\State b\\_point, b\\_distance = \n                \\State KDSearch(search\\_point,parent\\_node.right\\_child,b\\_point,b\\_distance,i+1)\n        \\EndIf\n    \\Else\n        \\State b\\_point, b\\_distance = \n            \\State KDSearch(search\\_point,parent\\_node.right\\_child,b\\_point,b\\_distance,i+1)\n        \\If {search\\_point[i] + b\\_distance $leq$ parent\\_node.point} \n            \\State b\\_point, b\\_distance = \n                \\State KDSearch(search\\_point,parent\\_node.left\\_child,b\\_point,b\\_distance,i+1)\n        \\EndIf\n    \\EndIf\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Nearest Neighbor}\n\\label{alg:nearestneighbor}\n\\end{algorithm}\n\\end{comment}\n\n\n\\begin{problem}\nUse Algorithm \\ref{alg:kdneighborz} to write a function that solves the nearest neighbor search problem by searching through a k-d tree.\nThe function should take in a k-d tree (already loaded with data) and a single point of interest.\nOutput the nearest neighbor in the tree and the distance from the nearest neighbor to the point of interest. \n\\end{problem}\n\n\\section*{Scipy.spatial.KDTree}\n\nScipy has a built-in k-d tree structure.\nIt functions the same way that the \\li{KDT} class does, except its operations have been heavily optimized.\nTo create the tree, we simply give it data in the initializer.\nTo solve the nearest neighbor search problem, we `query' the tree and give it a target point.\n\\li{query} returns a tuple of the minimum distance and the index of the nearest neighbor in the data.\n\n\\begin{lstlisting}\n>>> from scipy.spatial import KDTree\n>>> from numpy.random import random\n\n# Initialize the tree with data\n>>> data = random((100,20))\n>>> scipy_kdt =  KDTree(data)\n\n# Query the tree and print the minimum distance\n>>> min_distance, node_index = scipy_kdt.query(random(20))\n>>> print(min_distance)\n1.1769198641683098\n\n# Print the nearest neighbor by indexing into the tree's data\n>>> print scipy_kdt.data[node_index]\narray([ 0.30411204,  0.72439179,  0.81654881,  0.37483482,  0.37419281,\n        0.19786408,  0.28339901,  0.26042625,  0.95736655,  0.9898518 ,\n        0.3523297 ,  0.91607715,  0.91631037,  0.87982453,  0.66185015,\n        0.8003657 ,  0.73600775,  0.7150884 ,  0.1836229 ,  0.89556912])\n\\end{lstlisting}\n\n\\section*{The Curse of Dimensionality}\n\nIn almost all multidimensional optimization problems, as the number of dimensions increases, the amount of time it takes to solve the problem increases exponentially.\nThis is the so-called `Curse of Dimensionality'.\nIn Algorithm \\ref{alg:kdneighborz}, as the number of dimensions increases the number of times that we travel down both branches increases. Eventually using a k-d tree actually becomes less efficient than the exhaustive search method.\n\n\\begin{problem}\nWrite a function that creates three distinct figures.\nIn each figure, plot the time that it takes to solve the nearest neighbor search problem by exhaustive search, then by a k-d tree search using \\li{KDT}, then again using \\li{scipy.spatial.KDTree}.\n\nIn the first figure, use $n$ x 4 data sets with $n$ varying from 10,000 to 100,000 by multiples of 10,000.\nGenerate the data with \\li{numpy.random.random()}.\nTime only the searching of the k-d trees, not the building of them.\n\nIn the second figure, repeat the process with $n$ x 20 data sets, $n$ varying again from 10,000 to 100,000 by multiples of 10,000.\n\nIn the third figure, repeat the process with 20,000 x $k$ data sets, where $k$ varies from 2 to 50.\nHere we are increasing the dimension, not the number of data points, and we expect to suffer from the curse of dimensionality.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{fourDTime.pdf}\n\\caption{The first plot may look something like this.\nThe green line is the naive algorithm and blue line is the kd-tree search.\nThe kd-tree is the clear winner so far.}\n\\label{fig:fourDTime}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{twentyDTime.pdf}\n\\caption{The second graph may look something like this.\nThe green line is the naive version and blue line is using a kd-tree.\nNow the k-d tree search is slower than the naive algorithm.}\n\\label{fig:twentyDTime}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{curseD.pdf}\n\\caption{The third graph may look something like this.\nAround 15 dimensions the time spikes for the k-d tree search algorithm.\nAt that point using a kd-tree is even less effective than the naive algorithm.}\n\\end{figure}\n\n\\end{problem}\n\nCertain algorithms suffer less due to the curse of dimensionality, but are not as good in lower dimensions.\nOthers, like the one we have studied in this lab, are good in lower dimensions but suffer heavily in higher dimensions.\nKnowing how to pick your algorithm is an important skill in multidimensional data analysis.\n\n\n\n\n\n\n\\begin{comment} % END OF LAB. The rest of this needs to be moved elsewhere.\n\nThe complexity of this algorithm is $O(k\\log(n))$ in optimal time.\nIts worst case is $O(k*n^{1-\\frac{1}{k}})$ where $k$ is the number of dimensions and $n$ is the number of points in the tree.\nThe reasons for this are discussed in the next section.\n\n\\section{Curse of Dimensionality}\n\nAs you increase the number of dimensions the number of times that you have to go down both branches increases.\nYou get to the point where you eliminate very few points by using a k-d tree.\n\n\\begin{problem}\nTime both algorithms for the number of data points being $10,000-100,000$ every multiple of $10,000$ with $20$ dimensions.\nPlot both times on the same plot. Now how do the two algorithms compare?\n\\end{problem}\n\n\n\n\\begin{problem}\nTime the SciPy built in function for searching a k-d tree (do not time the building of the kd-tree) for the number of dimensions points being $2-50$ with $20,000$ data points.\nPlot the time.\nWhat do you notice?\n\\li{from scipy.spatial import KDTree} will import the built in k-d tree.\nCreate the tree by \\li{tree = KDTree(data)} and search it by \\li{tree.query(point)}.\n\n\\li{scipy.spatial} includes a \\li{cKDTree} object which is implemented in C.\nIs it any better?\n\\end{problem}\n\n\n\\section*{Classification}\nA common problem is correctly classifying data.  \nSuppose that you have a ten marbles, five of which are blue with a green stripe and the other five red with a purple stripe.  \nIf your friend gave you an eleventh marble that was blue with a brown stripe, which group would you put it in?  \nProbably you would include it with the other blue marbles.  \nWhat if the marble that your friend gave you was blue with a purple stripe?  \nThis marble shares characteristics with both groups.  \nWhere you end up grouping it will depend on which characteristics are most important to you.\n\nThis is the intuitive classfication problem.  \nIf we have data that is already grouped into distinct sets, into which set do we put new data?  \nClassification has myriad and sundry applications.  \nIn this lab we will use it in the context of optical character recognition.\n\n\\section*{Nearest Neighbor Classification}\nWe will now more formally describe the classification problem and explain the nearest neighbor classification algorithm.  \nSuppose we have a collection of vectors $\\{x_1, ..., x_m\\}$ in $\\R^n$ with corresponding labels $\\{l_1, ..., l_k\\}$ describing to which group each datum belongs.  \nThis collection of vectors and labels is called our training set.  \nEach entry of a vector is called a feature and $n$ is the size of our feature set.  \nFor example, consider the following vectors in $\\R^3$\n\n\\begin{center}\n\\begin{tabular}{cc}\n$(2,0,0)$ & $1$ \\\\\n$(3,0,0)$ & $1$ \\\\\n$(0,3,0)$ & $2$ \\\\\n$(0,2,0)$ & $2$ \\\\\n$(1/10,2,0)$ & $2$ \\\\\n$(0,0,4)$ & $3$ \\\\\n$(0,0,7)$ & $3$ \\\\\n\\end{tabular}\n\\end{center}\n\nIf we also have a metric on our space, we may determine the distance between all of these points.  \nIf we are given a new datum and we wish to decide which of the three groups to include it in, one option is to choose the group to which its closest neighbor belongs.  \nLet us use the euclidean metric to classify $(0,0,5)$ against our training set.  \nWe see that the distance from $(0,0,5)$ and $(0,0,4)$ is only $1$, while the distance to the remaining points is at least $2$.  \nThe label of $(0,0,4)$ is $3$, and so we assign $(0,0,5)$ the same label.\n\nNow, what if we wished to classify $(5/2,5/2,0)$?  \nThis presents a problem since this point is equidistant from the points in label $1$ and label $2$.  \nIn such a case it is up to the programmer to decide how to break the tie.\n\nOne case we need to consider is when the data that we are using in our search are on different scales. \nFor example, suppose we wished to classify people applying for a loan at a bank as `risky' or `safe.'  \nFurther suppose that we know their age, education level, current debt, and how many credit cards they have.  \nWe could encode their education level as integers between $0$ and $4$.\n\nSuppose that Bob is 30 years old, well educated, has a debt of \\$5000, and 3 credit cards.  \nLet's say that James is 18 years old, barely out of high school, \\$5000 dollars in debt, and owns 4 credit cards.  \nIf we were to use the Euclidean metric $d$ to measure how close Bob is to James, we would get a distance of\n\\[\nd((30,4,5000,3),(18,0,5000,4)) = 12^2 + 4^2 + 1^2 = 161.\n\\]\n\nHowever, if Alice is 29 years old, well educated, has a debt of \\$4900, and 3 credit cards, then her distance from Bob is\n\\[\nd((30,4,5000,3),(29,4,4900,3)) = 1^2 + 100^2 = 100001.\n\\]\n\nIs James closer to Bob than Alice?  Most Banks would say no.  \nIn order to classify these individuals better, we need to measure distance differently. \nThere are two different ways to handle this. \nThe first solution is to scale the data before inputting it into our algorithm. \nIn our previous example we could divide age by 100, education by 4, debt by 1000, and credit cards by 10 and then preform a nearest neighbor search on Bob. \nThen the distance from Bob to James is \n\\[\nd\\left( \\left( \\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10} \\right),\\left(\\frac{18}{100},\\frac{0}{4},\\frac{5000}{1000},\\frac{4}{10}\\right)\\right) = .12^2 + 1^2 + .1^2 = 1.0244.\n\\]\nwhile the distace from Alice to Bob is\n\\[\nd\\left(\\left(\\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10}\\right),\\left(\\frac{29}{100},\\frac{4}{4},\\frac{4900}{1000},\\frac{3}{10}\\right)\\right) = .1^2 + .01^2 = 0.0101.\n\\]\nSo now Bob is closer to Alice.\n\n\\begin{problem}\nWrite a function that takes in data points and the a vector that is used to be the scale. \nThe function outputs the scaled data points. \nSo if we were using it for our baking example it would take in the array representing the data Alice, Bob and James (where each person is a row) and the vector $[100,4,1000,10]$ and output the scaled data of Alice, Bob and James.\n\\end{problem}\n\nAnother alternative is to change the metric we use to measure distance with. \nIn both the examples above we used the Euclidean metric to measure distance. \nSuppose we wished to apply the Euclidean metric to data set of colors.\nWe could map each color to an integer, say red to 1, violet to 2, blue to 3, green to 4, yellow to 5, and orange to 6. \nIf we use Euclidean metric green is closer to red than orange is when we'd probably consider orange to be the same distance from red as violet is. \nIn this case the Euclidean metric is not satisfactory and so we might create a new metric to measure the distance between colors. \n\n\\section*{K-Nearest Neighbor Classification}\nOften we can improve the accuracy of a classifier by looking for other points besides the nearest neighbor.  \nInstead, we may choose an arbitrary number $k$ and give the point to be classified the majority label in from it's $k$ nearest neighbors. \n\nThere are pitfalls to this approach.  \nConsider a point that's closest neighbor has the label $0$.  \nIf we only considered the nearest neighbor, then we would be finished.  \nHowever, what if the next $10$ nearest neighbors all had the label $1$?  \nDo you think that we should still classify the point as $0$?  \nWhat if the nearest point has a distance of $0.1$ and the next $10$ points have a distance of at least $100$?  \nThe answer to these questions depend on the kind of data we are working with and the metric that we choose.  \nOne should ensure to consider how to treat situations like this when working on classification algorithms.\n\n\nThe sklearn library has a neighbors module with a class KNeighborsClassifier for solving the $k$ nearest neighbors problem\n\\begin{lstlisting}\nfrom sklearn import neighbors\nnbrs = neighbors.KNeighborsClassifier(n_neighbors=8, weights='distance', p=2)\n\\end{lstlisting}\n\nThe \\li{neighbors.KNeighborsClassifier} sets up the knearestnieghbor algorithm. \n\\li{n_neighbors} is how many neighbors you would like to find and \\li{weights} specifies how you would like to weight the neighbors you have to make the classification. \nWeights can be \\li{'uniform'}, where the majority classification of the $k$ nearest neighbors determines the new data point's classification, or \\li{'distance'}, where the neighbors nearer to the point have more weight than those farther away. \nThe argument \\li{p} correpsods to the distance metric. \nFor this lab we will use \\li{p=2} which is the Euclidean distance.  \n\n\\begin{lstlisting}\nnbrs.fit(points, labels)\n\\end{lstlisting}\nPoints and labels are your training data. \nThe \\li{fit} function makes \\li{nrbs} create a data structure containing those points and labels ready to be queried. \n\n\\begin{lstlisting}\nnbrs.predict(testpoints)\n\\end{lstlisting}\n\nThe function \\li{predict} takes in points to classify and outputs their respective labels.  \n%More information about this package can be found at http://scikit-learn.org/stable/modules/neighbors.html.\n\\begin{problem}\nGet the post office handwritten digit data set. Load them with\n\\begin{lstlisting}\nlabels, points, testlabels, testpoints = np.load('PostalData.npz').items()\n\\end{lstlisting}\nThis contains a training set and a test set. \nWhen you load the data the first entry of each array will be a name. \nSo \\li{points[1]} and \\li{labels[1]} point to the actual points and labels you want to use. \nEach point is a  image that is $28 \\times 28$ matrix of pixels that has been flattened. \nThe corresponding label indicates which number was written.  \nTry classifying the testpoints with \\li{n_neighbors} as 4 and then as 10 and with \\li{weights} \\li{'uniform'} and then \\li{'distance'}. Then do the classfication with \\li{n_neighbors} being 1. \nFor each one return a report indicating how your classifier performs in terms of misclassifications as a percentange (testlabels are the true labels that correspond to the testpoints). \nWhich combination gives the most correct classifications?\n(You may wish to streamline this process by writting a function that takes in \\li{n_neighbors} and \\li{weights} as arguments calls the neighbors functions appropriately)\n\n\nA similar classification process is used by the United States Postal Service to automatically determine the zip code to send a letter to.\n\n\\begin{figure}[H]\n\\includegraphics[width=.25\\textwidth]{Example.png}\n\\caption{An example of the number 6 taken from the data set}\n\\end{figure}\n\\end{problem}\n\n\\end{comment}", "meta": {"hexsha": "4236b00e780c95aa2aba068472324c01703c467d", "size": 27959, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/NearestNeighbor/new_Neighbor.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/NearestNeighbor/new_Neighbor.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/NearestNeighbor/new_Neighbor.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 52.6534839925, "max_line_length": 400, "alphanum_fraction": 0.7463428592, "num_tokens": 7173, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8774767746654976, "lm_q2_score": 0.8991213874066956, "lm_q1q2_score": 0.7889581350543945}}
{"text": "\\chapter{Random Variables}\\label{S:RandomVariable}\n\nWe are used to classical variables such as $x$ as an ``unknown'' in\nthe equation: $x+3\\;=\\;7 \\enspace$.\n\nWe also  use classical variables to represent geometric objects such as a line:\n\\[\ny\\;=\\;3x-2 \\enspace ,\n\\]\nwhere the variable $y$ for the $y$-axis is determined by the value taken\nby the variable $x$, as $x$ varies over the real line $\\mathbb{R} =\n(-\\infty,\\infty)$.\n\nYet another example is the use  of variables  to represent sequences such as:\n\\[\n\\{a_n\\}_{n=1}^{\\infty}\\; = \\;a_1,a_2,a_3,\\ldots \\enspace.\n\\]\n\nWhat these \\emph{classical variables} have in common is that they \\emph{take a} fixed or \\emph{deterministic value} when we can solve for them.\n\nWe need a different kind of variable to deal with real-world situations where the same variable may take \ndifferent values in a non-deterministic manner.  {\\bf Random variables} do this job for us.  \nRandom variables, unlike classical deterministic variables, can take a bunch of different values.\n\nCrucially, it can become inconvenient to work with a set of outcomes $\\Omega$ upon which arithmetic is not possible. \nWe are often measuring our outcomes with subsets of real numbers.  Some examples include:\n\n\\begin{table}[ht]\n\\begin{tabular}{c c} \\hline\nExperiment & Possible measured outcomes\\\\ \\hline\nCounting the number of typos up to now & $\\Zz_+:=\\{0,1,2,\\ldots\\} \\subset \\Rz$ \\\\\nLength in centi-meters of some shells on New Brighton beach & $(0,+\\infty) \\subset \\Rz$ \\\\\nWaiting time in minutes for the next Orbiter bus to arrive & $\\Rz_+:=[0,\\infty) \\subset \\Rz$\\\\\nVertical displacement from current position of a pollen on water & $\\Rz$ \\\\ \\hline\n\\end{tabular}\n\\end{table}\n\nThus, we want a \\textbf{random variable} to be a function from the sample space $\\Omega$ to the set of real numbers $\\mathbb{R}$, that is,  $X : \\Omega \\to \\mathbb{R}$ that should satisfy certain conditions to keep the meaning of the underlying probability space $(\\Omega, \\mathcal{F},\\P)$. \nLet us go through some examples before giving the formal definition of such a real-valued or $\\Rz$-valued random variable.\n\n\n\\begin{example}[Rain or Shine]\\label{Exmp:RainOrShine}\nSuppose our experiment is to observe whether it will $\\mathsf{rain}$ or $\\mathsf{not~rain}$ tomorrow. \nThe sample space of this experiment is $\\Omega= \\{ \\mathsf{rain},\\mathsf{not~rain} \\}$. \nWe can associate a random variable $X$ with this experiment as follows:\n\\[X(\\omega)=\n\\begin{cases}\n1, & \\text{if } \\omega = \\mathsf{rain}\\\\\n0, &  \\text{if } \\omega = \\mathsf{not~rain}\n\\end{cases}\n\\]\nThus, $X$ will take the value $1$ if it will rain tomorrow and $0$ otherwise.  \nNote that another equally valid (though possibly not so useful) random variable, say $Y$, for this experiment is:\n\\[Y(\\omega)=\n\\begin{cases}\n\\pi, & \\text{if } \\ \\omega = \\mathsf{rain}\\\\\n\\sqrt{2}, &  \\text{if } \\ \\omega = \\mathsf{not~rain}\n\\end{cases}\n\\]\n\\end{example}\n\n\\begin{example}[Rain Fall on Angstrom]\\label{Exmp:RainInmms}\nSuppose our experiment instead is to measure the volume of rain that falls into a large funnel stuck on top of a graduated cylinder that is placed on top of the middle of House 1 of Angstrom Laboratory. \nSuppose the cylinder is graduated in millimeters then our random variable $X(\\omega)$ can report a non-negative real number given by the lower miniscus of the water column, if any, in the cylinder tomorrow.  \nThus, $X(\\omega)$ will measure the volume of rain in millilitres that will fall into our funnel tomorrow. \n\\end{example}\n\n\\begin{example}[Counting Seedlings]\\label{Exmp:SeedPlanting}\nSuppose ten seeds are planted. Perhaps fewer than ten will actually germinate. \nThe number which do germinate, say $X$, must be one of the integer numbers in $\\Rz$ given by the set:\n\\[ \\Xz := \\{0,1,2,3,4,5,6,7,8,9,10\\} \\enspace .\\]\nBut until the seeds are actually planted and allowed to germinate it is\nimpossible to say which number $X(\\omega): \\Omega \\to \\Xz$ will take. \nThe number of seeds which germinate is a variable, but it is not necessarily the same for each group of ten\nseeds planted, but takes values from the same set $\\Xz$.  \nAs $X$ is not known in advance it is called a {\\bf random variable}. \nIts value cannot be known until we actually perform the experiment, i.e.,\nplant the seeds.\\\\[6pt]Certain things can be said about the value a\nrandom variable might take. In the case of these ten seeds we can be\nsure the number that germinate  is less than eleven, and not less than\nzero! It may also be known that that the probability of seven seeds\ngerminating is greater than the probability of one seed; or perhaps that\nthe number of seeds germinating averages eight. These statements are\nbased on probabilities unlike the sort of statements made about\ndeterministic variables.\n\\end{example}\n\n\\bigskip\n\n{\\bf \\large Discrete  versus continuous random variables.}\n\n\n\\medskip\n\nA {\\bf discrete}  random variable is one in which the set of possible values of the random variable \nis  finite or  at most  countably infinite,  whereas a {\\bf continuous} random variable may take on \nany value in some range, and its value may be any real value in that range (Think: uncountably infinite).  \nExamples~\\ref{Exmp:RainOrShine} and \\ref{Exmp:SeedPlanting} are about discrete random variables and \nExample~\\ref{Exmp:RainInmms} is about a continuous random variable.\n\nDiscrete random variables are usually generated from experiments where\nthings are ``counted'' rather than ``measured''  such\nas  the seed planting experiment in Example~\\ref{Exmp:SeedPlanting}.  \nContinuous random variables appear in\nexperiments in which we measure, such as the amount of rain, in \nmillilitres in Example~\\ref{Exmp:RainInmms}.\n\n\n{\\large \\bf{Random variables as functions.}}\n\n\nIn fact, random variables are actually functions, more formally measurable maps from $\\mathcal{F}$ to certain subsets of $\\mathbb{R}$ that you will learn carefully in more advanced courses.  They take you from\nthe ``world of random processes and phenomena'' to the world of real\nnumbers.  In other words, a random variable is a numerical value\ndetermined by the outcome of the experiment.\n\nWe said that a random variable can take one of many values, but we\ncannot be certain of which value it will take.  However, {\\em we can\n  make probabilistic statements about the value $x$ the random variable\n  $X$ will take}.   A question like,\n\\cen{``What  is the probability  of it raining tomorrow?''} in the\nrain/not experiment of Example~\\ref{Exmp:RainOrShine} becomes  \n\\cen{``What is $P\\left( \\{ \\omega: X(\\omega) = 1 \\} \\right) $?''}\nor, more simply,\n\\cen{``What is $P(X=1)$?''}\n\nWith this motivation we are ready to formally define such a random variable.\n\n\\section{Basic Definitions}\\label{S:RVBasicDefs}\n\nTo take advantage of our measurements over the real numbers, in terms of its  metric structure and arithmetic, we need to formally define this measurement process using the notion of a random variable.\n\\begin{definition}[Random Variable]\\label{D:RV}\nLet $(\\Omega, \\C{F},P)$ be some probability triple.  Then, a {\\bf Random Variable (RV)}, say $X$, is a function from the sample space $\\Omega$ to the set of real numbers $\\Rz$ \n\\[\nX : \\Omega \\rightarrow \\Rz\n\\]\nsuch that for every $x \\in \\Rz$, the inverse image of the half-open real interval $(-\\infty,x]$ is an element of the collection of events $\\C{F}$, i.e.:\n\\[\n\\text{for every $x$} \\in \\Rz, \\qquad X^{[-1]}(\\ (-\\infty,x] \\ ) := \\{\\omega: X(\\omega) \\leq x\\} \\in \\C{F} \\ .\n\\]\n{\\scriptsize This definition can be summarised by the statement that a RV is an  $\\C{F}$-measurable map.}\nWe assign probability to the RV $X$ as follows:\n\\begin{equation}\\label{E:ProbOfRV}\n\\P(X \\leq x)  = \\P(\\ X^{[-1]}(\\ (-\\infty,x] \\ ) \\ ) := \\P( \\ \\{\\omega: X(\\omega) \\leq x\\} \\ ) \\ .\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}[Distribution Function]\\label{D:DF}\nThe {\\bf Distribution Function (DF)} or {\\bf Cumulative Distribution Function (CDF)} of any RV $X$, over a  probability triple $(\\Omega, \\C{F},P)$, denoted by $F$ is:\n\\begin{framed}\n\\begin{equation}\\label{E:DF}\nF(x) := \\P(X \\leq x) = \\P( \\ \\{\\omega: X(\\omega) \\leq x\\} \\ ), \\qquad \\text{for any }\\quad x \\in \\Rz \\ .\n\\end{equation}\n\\end{framed}\nThus, $F(x)$ or simply $F$ is a non-decreasing, right continuous, $[0,1]$-valued function over $\\Rz$.  When a RV $X$ has DF $F$ we write $X \\sim F$.\n\\end{definition}\n\n\\begin{rem}[Notation] \nIt is enough to understand the idea of random variables as explained above, and work with \nrandom variables using simplified notation  like \\[P(2\\leq X\\leq 3)\\] rather than \\[P(\\{\\omega: 2\\leq  X(\\omega) \\leq 3\\})\\]\nbut note that when learning or doing more advanced work this sample space notation is usually needed to clarify the true meaning of the simplified notation at least to yourself! But in the exam you can use the simpler notation as done in the solutions to exercises.\n\\end{rem}\n\nFrom the idea of a distribution function, we get:\n\n\\begin{framed}\n\\begin{prop}\nThe probability that the random variable $X$ takes a value $x$ in the half-open interval $(a,b]$, i.e., $a < x \\leq b$, is:\n\\begin{equation}\\label{E:Fb-a}\nP(a < X \\leq b)\\; = \\;F(b) - F(a)\\enspace .\n\\end{equation}\n\\end{prop}\n\\end{framed}\n\n{\\scriptsize\n\\begin{proof}\nSince  $(X \\leq a)$ and $(a < X \\leq b)$ are disjoint events whose union is the event $(X \\leq b)$,\n\\[\nF(b)  = P(X \\leq b) = P(X \\leq a) + P(a < X \\leq b) = F(a) + P (a < X \\leq b) \\enspace .\n\\]\nSubtraction of $F(a)$ from both sides of the above equation yields\nEquation~\\ref{E:Fb-a}.\n\\end{proof}\n}\n\n\nA special RV that often plays the role of `building-block' in Probability and Statistics is the indicator function of an event $A$ that tells us whether the event $A$ has occurred or not.  Recall that an event belongs to the collection of possible events $\\C{F}$ for our experiment.\n\\begin{definition}[Indicator Function]\nGiven a probability triple $(\\Omega,\\C{F},\\P)$, the {\\bf Indicator Function} of an event $A \\in \\C{f}$ which is denoted $\\BB{1}_A$ is defined as follows:\n\\begin{equation}\n\\BB{1}_A(\\omega) := \n\\begin{cases}\n1 & \\qquad \\text{if} \\quad \\omega \\in A \\\\\n0 & \\qquad \\text{if} \\quad \\omega \\notin A\n\\end{cases}\n\\end{equation}\n\\end{definition}\n\n\n\\begin{model}[Indicator of an event as $\\bernoulli$ RV]\\label{M:IndicatorIsaRV}\nThis is the most primitive RV from which all others are obtained. \nLet us convince ourselves that $\\BB{1}_A$ is really a RV.  For $\\BB{1}_A$ to be a RV, we need to verify that \nfor any real number $x \\in \\Rz$, the inverse image $\\BB{1}_A^{[-1]}( \\ (- \\infty, x] \\ )$ is an event, ie :\n\\[\n\\BB{1}_A^{[-1]}( \\ (- \\infty, x] \\ ) := \\{\\omega: \\BB{1}_A(\\omega) \\leq x\\} \\in \\C{F} \\ .\n\\] \nAll we can assume about the collection of events $\\C{F}$ is that it contains the event $A$ and that it is a sigma algebra.  A careful look at the \\hyperref[F:RVIndic]{Figure \\ref*{F:RVIndic}} yields:\n\\begin{equation}\n\\BB{1}_A^{[-1]}( \\ (- \\infty, x] \\ ) := \\{\\omega: \\BB{1}_A(\\omega) \\leq x\\} =\n\\begin{cases}\n\\emptyset & \\text{if} \\quad x < 0 \\notag \\\\\nA^c       & \\text{if} \\quad 0 \\leq x < 1 \\notag \\\\\nA \\cup A^c  = \\Omega   & \\text{if} \\quad 1 \\leq x  \\notag \n\\end{cases}\n\\end{equation}\nThus, $\\BB{1}_A^{[-1]}( \\ (- \\infty, x] \\ )$ is one of the following three sets that belong to $\\C{F}$; (1) $\\emptyset$, (2) $A^c$ and (3) $\\Omega$ depending on the value taken by $x$ relative to the interval $[0,1]$.  We have proved that $\\BB{1}_A$ is indeed a RV.\n\nModel~\\ref{M:IndicatorIsaRV} is called the $\\bernoulli$ RV for event $A$ with a known probability $\\P(A)$. We will define as our next model the $\\bernoulli(\\theta)$ RV by introducing a paramater $\\theta \\in [0,1]$ for the typically unknown probability $\\P(A)$. \n\\end{model}\n\nSome useful properties of the Indicator Function are:\n\\[\n\\BB{1}_{A^c} = 1 - \\BB{1}_A, \\qquad \\BB{1}_{A \\cap B} = \\BB{1}_A \\BB{1}_B, \\qquad \\BB{1}_{A \\cup B} = \\BB{1}_A + \\BB{1}_B - \\BB{1}_A \\BB{1}_B\n\\]\nWe slightly abuse notation when $A$ is a single element set by ignoring the curly braces.\n\n\\begin{figure}[htpb]\n\\caption{The Indicator function of event $A \\in \\C{F}$ is a RV $\\BB{1}_A$ with DF $F$ \\label{F:RVIndic}}\n\\centering   \\makebox{\\includegraphics{figures/RVIndic}}\n\\end{figure}\n\n\\begin{Exercise}[title={Drawing discontinuous functions},label={drawDiscontFuncs}]\nIdentify the mistakes in how the  $\\BB{1}_A$ is drawn as a discontinous function in Figure~\\ref{F:RVIndic}.\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}\nThe first mistake is the solid vertical lines (blue) from $0$ in the domain or $x$-axis to $\\P( \\text{`not A'})$ in the range or $y$-axis and from $1$ in the domain to $1$ in the range. \nThis is ill-defined for any function if we are to interpret that the elements in the domain, namely $0$ and $1$, are to be associated with the uncountably many image values in the range of the function, namely $[0,\\P( \\text{`not A'})]$ and $[\\P( \\text{`not A'}),1]$, respectively. \nSo we should first replace them by dotted lines which merely help us track where the function jumped to at $0$ and $1$.\n\nThe second mistake is failing to emphasise that the value taken by the function at $0$ and $1$ is not $0$ and $\\P( \\text{`not A'})$, respectively. So it is best to introduce an empty circle like $\\circ$ at $(0,0)$ and $(1,\\P( \\text{`not A'}))$ to indicate the points of discontinuity. The same mistakes should be fixed in the next Figure~\\ref{F:RVABC}.\n\\end{Answer}\n\n\\begin{classwork}[A random variable with three values and eight sample points]\\label{CW:ARVwith3Values}\nConsider the RV $X$ of \\hyperref[F:RVABC]{Figure \\ref*{F:RVABC}}.  First draw this properly as done in Ex.~\\ref{drawDiscontFuncs}. Let the events $A = \\{\\omega_1, \\omega_2\\}$, $B = \\{\\omega_3, \\omega_4, \\omega_5\\}$ and $C = \\{\\omega_6, \\omega_7,\\omega_8 \\}$.  Define the RV $X$ formally.  What sets should $\\C{F}$ minimally include?  What do you need to do to make sure that $\\C{F}$ is a sigma algebra?\n\\end{classwork}\n\\begin{figure}[htpb]\n\\caption{A RV $X$ from a sample space $\\Omega$ with $8$ elements to $\\Rz$ and its DF $F$.\\label{F:RVABC}}\n\\centering   \\makebox{\\includegraphics{figures/RV}}\n\\end{figure}\n\n\\begin{Exercise}[title={Fair coin toss RV},label={xFairCoinRV}]\nConsider the {\\em fair coin toss experiment}  with $\\Omega= \\{ \\mathsf{H},\\mathsf{T} \\}$ and $P(\\mathsf{H}) = P(\\mathsf{T})=1/2$. \\\\[6pt] We can associate a $\\bernoulli$ random variable $X$ (in Model~\\ref{M:IndicatorIsaRV}) for the event that the coin lands as $\\mathsf{H}$, with this experiment as follows:\n\\[X(\\omega)=\n\\begin{cases}\n1, & \\text{if } \\ \\omega = \\mathsf{H}\\\\\n0, & \\text{if } \\ \\omega = \\mathsf{T}\n\\end{cases}\n\\]\nFind the distribution function for $X$.\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}\nThe probability that $X$ takes on a specific value $x$ is:\n$$\nP(X = x) = P(\\{\\omega: X(\\omega) = x \\}) =\n\\begin{cases}\nP(\\emptyset) = 0, & \\text{ if } \\  x \\notin \\{0,1\\} \\\\\nP(\\{\\mathsf{T} \\}) =  \\frac{1}{2}, & \\text{ if } \\  x = 0\\\\\nP(\\{ \\mathsf{H}\\}) = \\frac{1}{2}, & \\text{ if } \\  x = 1\n\\end{cases}\n$$\nor more simply,\n\\[\nP(X=x)=\n\\begin{cases}\n\\frac{1}{2} & \\text{if } x=0\\\\\n\\frac{1}{2} & \\text{if } x=1\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\nThe distribution function for $X$ is:\n$$\nF(x) \\;=\\; P(X \\leq x) \\;=\\; P(\\{\\omega: X(\\omega) \\leq x \\})\\; =\\;\n\\begin{cases}\nP(\\emptyset) = 0, & \\text{ if } \\ -\\infty < x < 0\\\\\nP(\\{\\mathsf{T} \\}) =  \\frac{1}{2}, & \\text{ if } \\ 0 \\leq x < 1\\\\\nP(\\{ \\mathsf{H} , \\mathsf{T} \\}) = P(\\Omega)  = 1,\n& \\text{ if } \\ 1 \\leq x < \\infty\n\\end{cases}\n$$\nor more simply, $$\nF(x)\\; = \\;P(X \\leq x) \\;=\\;\n\\begin{cases}\n 0, & \\text{ if } \\ -\\infty < x < 0\\\\\n \\frac{1}{2}, & \\text{ if } \\ 0 \\leq x < 1\\\\\n 1,\n& \\text{ if } \\ 1 \\leq x < \\infty\n\\end{cases}\n$$\n\\end{Answer}\n\n\\section{Discrete Random Variables}\n\nWhen a RV takes at most countably many values from a discrete set $\\Xz$, we call it a {\\bf discrete} RV.  \nRecall that a set $\\Xz$ is said to be discrete if we can enumerate its elements, i.e., find an enumerating or counting function $\\Xz \\ni x \\mapsto i \\in\\Nz$ that associates each element $x \\in \\Xz$ to a natural number $i \\in \\Nz$. \nSo, $\\Xz$ is either finite with $k$ elements in $\\Xz = \\{x_1,x_2,\\ldots,x_k\\}$ or countably infinite with the same cardinality as $\\Nz$ with $\\Xz = \\{x_1,x_2,\\ldots\\}$. \nWhen $\\Xz \\subset \\Rz$, we have a real-valued or $\\Rz$-valued discrete random variable.\n\n\\begin{definition}[probability mass function (PMF)]\nLet $X$ be a $\\Rz$-valued discrete RV over a probability triple $(\\Omega, \\C{F},\\P)$.  \nWe define the {\\bf probability mass function} (PMF) $f$ of $X$ to be the function \n$f : \\Rz \\rightarrow [0,1]$ defined as follows:\n\\begin{framed}\n\\begin{equation}\\label{Eq:DiscretePMF}\nf(x) := \\P(X=x) = \\P( \\ \\{\\omega: X(\\omega) = x\\} \\ ) = \n\\begin{cases}\n\\theta_i \\quad \\text{if $x=x_i \\in \\Xz$.}\\\\\n0 \\quad \\text{otherwise}. \n\\end{cases}\n\\end{equation}\n\\end{framed}\n\\end{definition}\n\nThe DF $F$ and PMF $f$ for a discrete RV $X$ satisfy the following:\n\\begin{enumerate}\n\\item  For any $x \\in \\Rz$, \n\\begin{equation}\\label{Eq:DiscreteDF}\n\\boxed{\\P(X \\leq x) = F(x)  = \\sum_{x_i \\leq x} f(x_i) = \\sum_{x_i \\leq x} \\theta_i \\ .}\n\\end{equation}\n\\item For any $a,b \\in \\Rz$ with $a<b$,\n\\begin{equation}\\label{E:DRVFab}\n\\boxed{\\P(a < X \\leq b) = F(b) - F(a) = \\sum_{a < x_i \\leq b} \\theta_i \\ .}\n\\end{equation}\nThis is just the sum of all probabilities $\\theta_i$ for which $x_i$ satisfies $a<x_i \\leq b$. \n\\item\nFrom the fact that $\\P(\\Omega)=1$, we get that the sum of all the probabilties is $1$:\n\\begin{equation}\\label{E:DRVsumofP}\n\\boxed{\\sum_i \\theta_i = 1 \\ .}\n\\end{equation}\n\\item\nWhen $X$ only has finitely many possibilities, say $k$ with $\\Xz = \\{x_1,x_2,\\ldots,x_k\\}$, then we may think of the probability $\\P$ specified by $(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ as a point in the \\textbf{unit $(k-1)$ simplex}:\n\\begin{equation}\\label{E:unitk-1simplex}\n\\Delta^{k-1} := \\{ (\\theta_1,\\theta_2,\\ldots,\\theta_k) \\in \\Rz^{k} : \\sum_i \\theta_i = 1 \\text{ and } \\theta_i \\geq 0, \\text{ for all } i\\}\n\\end{equation}\nIn particular when $X$ has only two possible values with $\\Xz = \\{x_1,x_2\\}$ then $\\theta_2=1-\\theta_1$, so we can avoid subscripts and take $\\theta := \\theta_1$ and realize that the probability $\\P$ is now specified by the point $(\\theta,1-\\theta)$ in the \\textbf{unit $1$ simplex}:\n\\begin{equation}\\label{E:unit1simplex}\n\\Delta^{1} := \\{ (\\theta,1-\\theta) \\in \\Rz^2 : 0 \\leq \\theta \\leq 1 \\} \\enspace .\n\\end{equation}\nSee \\url{https://en.wikipedia.org/wiki/Simplex} for the images scribed on the board.\n\\end{enumerate}\n\n\\begin{framed}\nDISCRETE RANDOM VARIABLES - SIMPLIFIED NOTATION\\\\\n\nNotice that in equations \\eqref{Eq:DiscretePMF}, \\eqref{Eq:DiscreteDF} and \\eqref{E:DRVFab} the use of the ``$\\omega \\in \\Omega$'' notation, where random variables are defined as functions, is\nmuch reduced. The reason is that in straightforward examples it is\nconvenient to associate the possible values $x_1,x_2,\\dots$ with the\noutcomes $\\omega_1,\\omega_2,\\dots$ Hence, we can describe a discrete\nrandom variable by the table:\n\n\n$$\\begin{array}{|c||c|c|c|c|}\\hline\n\\textrm{Possible values: $x_i$} & x_1 & x_2 & x_3 & \\ldots \\\\ \\hline\n&&&&\\\\\n\\textrm{Probability: $\\P(X=x_i)=\\theta_i$}& \\theta_1 & \\theta_2 & \\theta_3 & \\ldots \\\\ \\hline\n\\end{array}\n$$\nIt is customary to use $p_i$ instead of $\\theta_i$ for the probabilities. But we try to avoid it as it will hurt us when we start doing Inference Theory soon!\n\\quad \\\\\nNote that this table hides the more complex notation but it is still\nthere, under the surface. \nIn Probability Theory I, you should be able to  work with and manipulate discrete random variables using the simplified notation given above. \nThe same comment applies to the continuous random variables discussed later. But you are students of mathematics and should know more about what is ``under the hood''.\n\n\\end{framed}\n\n\nOut of the class of discrete random variables we will define specific kinds as they arise often in applications.  We classify discrete random variables into three types for convenience as follows:\n\\begin{itemize}\n\\item {Discrete uniform random variables with finitely many possibilities}\n\\item {Discrete non-uniform random variables with finitely many possibilities}\n\\item {Discrete non-uniform random variables with (countably) infinitely many possibilities}\n\\end{itemize}\n\n\\begin{framed}\n\\begin{model}[Discrete Uniform]{\\label{Df:DiscreteUniformRV}\nWe say that a discrete random variable $X$ is uniformly distributed over $k$ possible values in $\\Xz=\\{x_1,x_2,\\ldots,x_k\\}$ if its probability mass function is:\n\\begin{equation}\\label{E:DiscreteUniformPMF}\nf(x) =\n\\begin{cases}\n\\theta_i = \\frac{1}{k} &  \\quad\\textrm{if } x=x_i, \\quad\\textrm{where } i=1,2, \\ldots ,k \\enspace, \\\\\n0 & \\quad\\textrm{otherwise}\\enspace.\n\\end{cases}\n\\end{equation}\nThe distribution function for the discrete uniform random variable $X$ is:\n\\begin{equation}\\label{E:DiscreteUniformDF}\nF(x) = \\sum_{x_i\\leq x} f(x_i) = \\sum_{x_i\\leq x} \\theta_i =\n\\begin{cases}\n0 &\\quad \\textrm{if }-\\infty < x < x_1\\enspace ,\\\\\n\\frac{1}{k}  & \\quad \\textrm{if }x_1 \\leq x < x_2\\enspace , \\\\\n\\frac{2}{k}  & \\quad \\textrm{if }x_2 \\leq x < x_3\\enspace , \\\\\n\\vdots & \\\\\n\\frac{k-1}{k}  & \\quad \\textrm{if }x_{k-1} \\leq x < x_k\\enspace , \\\\\n1 & \\quad \\textrm{if }x_k \\leq x < \\infty\\enspace .\n\\end{cases}\n\\end{equation}\n}\nThe discrete uniform RV with values in $\\Xz = \\{1,2,\\ldots,k\\}$ is called the equi-probable $\\demoivre(k)$ RV as we will see in the sequel. \n\\end{model}\n\\end{framed}\n\n\\begin{example}\\label{ExFairCoinRV}\nThe {\\em fair coin toss experiment} of Exercise~\\ref{xFairCoinRV} is an example of a discrete uniform random variable with finitely many possibilities. \nIts probability mass function is given by \n\\[f(x)\\;=\\;\\P(X=x)\\;=\\;\n\\begin{cases}\n\\frac{1}{2} & \\text{if } x=0\\\\\n\\frac{1}{2} & \\text{if } x=1\\\\\n0 & \\text{otherwise}\n\\end{cases}\\] \nand its distribution function is given by\n\\[F(x)\\; = \\;\\P(X \\leq x) \\;=\\;\n\\begin{cases}\n 0, & \\text{ if } \\ -\\infty < x < 0\\\\\n \\frac{1}{2}, & \\text{ if } \\ 0 \\leq x < 1\\\\\n 1,\n& \\text{ if } \\ 1 \\leq x < \\infty\n\\end{cases}\n\\]\nLet us sketch the probability mass function and distribution function for $X$ below. \n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/faircoinfF}\n\\caption{$f(x)$ and $F(x)$ of {\\em the fair coin toss} random variable $X$, a discrete uniform RV on $\\{0,1\\}$.}\n\\end{center}\n\\end{figure}\n\\end{example}\n\n\\begin{example}[Fair dice RV]\\label{Eg:FairDicerandomVariable}\nNow consider the {\\em toss a fair die} experiment and define $X$ to be the number that shows up on the top face. \nNote that here $\\Omega$ is the set of numerical symbols $\\{\\mathsf{1}, \\mathsf{2}, \\mathsf{3}, \\mathsf{4}, \\mathsf{5}, \\mathsf{6}\\}$ \nthat label each face while each of these symbols are associated with the real number \n$x \\in \\{1,2,3,4,5,6\\}$. \nWe can describe this random variable by the table \n$$\\begin{array}{|c|cccccc|}\\hline\n\\textrm{Possible values, $x_i$}&1&2&3&4&5&6 \\\\ \\hline\n&&&&&&\\\\\n\\textrm{Probability, $\\theta_i$} &\\frac{1}{6}&\\frac{1}{6}&\\frac{1}{6}&\\frac{1}{6}&\\frac{1}{6}&\\frac{1}{6}\\\\ \\hline\n\\end{array}\n$$\nFind the probability mass function and distribution function for this random variable, and sketch their graphs.\n\nSolution:\\\\[4pt]\nThe probability mass function of this random variable is:\n\\[f(x)\\;=\\;\\P(X=x)\\;=\\;\n\\begin{cases}\n\\frac{1}{6} & \\text{if } x=1\\\\\n\\frac{1}{6} & \\text{if } x=2\\\\\n\\frac{1}{6} & \\text{if } x=3\\\\\n\\frac{1}{6} & \\text{if } x=4\\\\\n\\frac{1}{6} & \\text{if } x=5\\\\\n\\frac{1}{6} & \\text{if } x=6\\\\\n0 & \\text{otherwise}\n\\end{cases}\\] and the  distribution function is:\n\\[F(x)\\; = \\;\\P(X \\leq x) \\;=\\;\n\\begin{cases}\n 0, & \\text{ if } \\ -\\infty < x < 1\\\\\n \\frac{1}{6}, & \\text{ if } \\ 1 \\leq x < 2\\\\\n\\frac{1}{3}, & \\text{ if } \\ 2 \\leq x < 3\\\\\n\\frac{1}{2}, & \\text{ if } \\ 3 \\leq x < 4\\\\\n\\frac{2}{3}, & \\text{ if } \\ 4 \\leq x < 5\\\\\n\\frac{5}{6}, & \\text{ if } \\ 5 \\leq x < 6\\\\\n 1,& \\text{ if } \\ 6 \\leq x < \\infty\n\\end{cases}\n\\]\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/fairdiefF}\n\\caption{$f(x)$ and $F(x)$ of {\\em the fair die toss} random variable $X$, a discrete uniform RV on $\\{1,2,3,4,5,6\\}$.}\n\\end{center}\n\\end{figure}\n\\end{example}\n\n\\begin{example}[Astragali with a Kiwi sheep ankle bone]\\label{Eg:Astragali}\n{\\bf Astragali.} Board games involving chance\n  were known in Egypt, 3000 years before Christ. The element of chance\n  needed for these games was at first provided by tossing astragali, the\n  ankle bones of sheep. These bones could come to rest on only four\n  sides, the other two sides being rounded. The upper side of the bone,\n  broad and slightly convex counted four; the opposite side broad and\n  slightly concave counted three; the lateral side flat and narrow, one,\n  and the opposite narrow lateral side, which is slightly hollow, six.\n  You may examine an astragali of a kiwi sheep. \\\\[6pt] This is an example of a discrete\n  non-uniform random variable with finitely many possibilities.  A surmised probability mass function with $f(4)=\\frac{4}{10}$,\n  $f(3)=\\frac{3}{10}$, $f(1)=\\frac{2}{10}$, $f(6)=\\frac{1}{10}$ and\n  distribution function are shown below.\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/astragalifF}\n\\caption{$f(x)$ and $F(x)$ of surmised {\\em astragali toss} random variable $X$, a discrete (non-uniform) RV on $\\{1,2,3,4\\}$.}\n\\end{center}\n\\end{figure}\n\\end{example}\n\n\\subsection{An Elementary Family of Bernoulli Random Variables}\\label{S:ElemDiscRV}\nIn many experiments there are only two outcomes. For instance:\n\n\\bit\n\\item Flip a coin to see whether it is defective.\n\\item  Roll a die and determine whether it is a 6 or not.\n\\item  Determine whether it will be below $0$ degrees Celsius at 0600 hours in Uppsala tomorrow or not.\n\\eit\n\nPerforming such an experiment $\\EE{E}$ once to see if an event of interest $A$ occurs is called a {\\bf Bernoulli trial} and its probability model over a triple $(\\Omega,\\C{F},\\P)$, with $A \\in \\C{F}$, given by  the Indicator Function $\\BB{1}_A$ in Model~\\ref{M:IndicatorIsaRV} is called the $\\bernoulli$ RV. \n\nIf we do not know the probability $\\theta$ that `$A$ occurs', i.e., the $\\bernoulli$ RV will equal $1$, then we can define a whole family of $\\bernoulli$ RVs for each \n$\\theta \\in [0,1]$ or more precisely for each $(\\theta, 1-\\theta) \\in \\Delta^1$, the unit $1$-Simplex.\nNote that this family includes the fair Bernoulli trial of Example~\\ref{ExFairCoinRV} when $\\theta=0.5$. Let us formalise this as the $\\bernoulli(\\theta)$ RV for each $\\theta \\in [0,1]$ next.\n\n\\begin{model}[$\\bernoulli(\\theta)$ RV]\nGiven a parameter $\\theta \\in [0,1]$, the probability mass function (PMF) for the $\\bernoulli(\\theta)$ RV $X$ is:\n\\begin{equation}\\label{E:Bernoullipdf}\nf(x;\\theta)= \\theta^x (1-\\theta)^{1-x} \\BB{1}_{\\{0,1\\}}(x) =\n\\begin{cases}\n\\theta & \\text{if $x=1$,}\\\\\n1-\\theta & \\text{if $x=0$,}\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\nand its DF is:\n\\begin{equation}\nF(x;\\theta) =\n\\begin{cases}\n1 & \\text{if $1 \\leq x$,}\\\\\n1-\\theta & \\text{if $0 \\leq x < 1$,}\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\nWe emphasise the dependence of the probabilities on the parameter $\\theta$ by specifying it following the semicolon in the argument for $f$ and $F$ and by subscripting the probabilities, i.e.~$\\P_{\\theta}(X=1)=\\theta$ and $\\P_{\\theta}(X=0)=1-\\theta$.\n\\end{model}\n\\begin{figure}[htpb]\n\\centering   \\makebox{\\includegraphics{pstricks/bernouliThetafF}}\n\\caption{PMF $f(x;\\theta)$ and DF $f(x;\\theta)$ with $\\theta = 0.33$. You should see how PMF and DF change as $\\theta$ goes from $0$ to $1$}\n\\end{figure}\n\n\\subsection{Independent $\\bernoulli$ Trials}\n\nRandom variables make sense for a series of trials as well as just a single trial of an experiment.  \nWe now look at  what happens when we perform a sequence of independent Bernoulli trials.  \nFor instance:\n\\bit\n\\item Flip a coin 10 times; count the  number of heads \n\\bit\n\\item by possibly allowing for the coin's $\\P(\\mathsf{H})$ to change each time because each of them are manufactured in a terrible mint.\n\\eit\n\\item Test 50 randomly selected circuits from an assembly line; count\n  the  number of defective circuits.\n\\item  Roll a die 100 times; count the  number of sixes you throw.\n\\item Provide a property near a particular bridge in our archipelago with flood insurance\n  for 20 years; count the number of years, during the 20-year period,\n  during which the property is flooded. Note: we assume that flooding is\n  independent from year to year, and that the probability of flooding is the same\n  each year.\n\\eit\n\nSince the $\\bernoulli(\\theta)$ RV has only two outcomes, i.e., simple events, we know how to obtain the probability of each of the two outcomes in a given $\\bernoulli$ trial with the probability given by the deterministic variable or parameter $\\theta$. \nNow consider doing more than one trial so we have sequence of $\\bernoulli(\\theta_i)$ trials, say,\n\\[\nX_i \\sim \\bernoulli(\\theta_i) \\text{ with } i \\in \\mathbb{N} \\enspace ,\n\\] \nwith each $\\theta_i \\in [0,1]$ being possibly unkown but fixed as a parameter. \nNow, if we assume independence across trials, so one trial's outcome does not affect the outcome of any of the other trials, in the sense of Definition~\\ref{D:IndOfSeqOfEvents} \nabout \\emph{independence of a sequence of events}, then we can obtain the probability of the entire sequence of outcomes for this sequence of \\textbf{independently distributed} $\\bernoulli(\\theta_i)$ \\textbf{trails} which can be any infinite sequence of $0$'s and $1$'s, i.e., any element of $\\{0,1\\}^{\\infty}$, by simply multiplying the corresponding probabilities given by $\\theta_i$'s in $(\\theta_1,\\theta_2,\\ldots) \\in [0,1]^{\\infty}$, an infinite dimensional parameter space, as follows:\n\\begin{eqnarray}\\label{Eq:probofindependentBernoullithetaiTrials}\n\\P(x; (\\theta_1,\\theta_2,\\ldots)) &=& \\prod_i f(x_i;\\theta_i)= \\prod_i \\theta_i^{x_i} (1-\\theta_i)^{1-x_i} \\BB{1}_{\\{0,1\\}}(x_i), \\\\\n&~& \\qquad \\qquad \\text{ where } x:= (x_1,x_2,\\ldots) \\in \\mathbb{X}_{\\infty} = \\{0,1\\}^{\\infty} := \\{0,1\\} \\times \\{0,1\\} \\times \\cdots \\notag\n\\end{eqnarray}\nBy further assuming that all the $\\theta_i$'s are identical, say $\\theta = \\theta_1 = \\theta_2 = \\cdots$, with $\\theta \\in [0,1]$, a one-dimensional parameter space, we get the much simpler expression for the \\textbf{independent and identically distributed (IID)} $\\bernoulli(\\theta)$ \\textbf{trails} as follows:\n\\begin{eqnarray}\\label{Eq:probofindependentIdenticalBernoullithetaTrials}\n\\P(x; \\theta) &=& \\prod_i f(x_i;\\theta)= \\prod_i \\theta^{x_i} (1-\\theta)^{1-x_i} \\BB{1}_{\\{0,1\\}}(x_i) =  \\BB{1}_{\\{0,1\\}^{\\infty}}(x) \\, \\theta^{\\sum_i x_i} (1-\\theta)^{\\sum_i(1-x_i)} \\notag\\\\\n&=&  \n\\begin{cases}\n\\theta^{\\sum_i x_i} (1-\\theta)^{n-\\sum_i x_i} & \\text{if $x:= (x_1,x_2,\\ldots) \\in \\mathbb{X}_{\\infty} = \\{0,1\\}^{\\infty}$}\\\\ \n0 & \\text{otherwise}\\enspace .\n\\end{cases}\n\\end{eqnarray}\n\nRemembering that all other RVs can be derived from such IID $\\bernoulli(\\theta)$ trials using $\\theta=1/2$, as we will see in the sequel, \nwe are ready to take a tour through some common discrete and continuous random variables that are useful in many applications.\n \n\\subsection{Some Common Discrete Random Variables}\\label{S:SomeCommonDiscreteRVs}\n\nLet us start with the simplest example to fix ideas carefully.\n\\begin{example}[Waiting For the First Heads]\\label{Ex:WaitinfFor1stHeads}\nSuppose our experiment is to toss a fair coin independently and\n  identically (that is, the same coin is tossed in essentially the same\n  manner independent of the other tosses in each trial) as often as\n  necessary until we have a head, $\\mathsf{H}$.  Let the random\n  variable\n  $X$ denote the \\emph{Number of trials until the first $\\mathsf{H}$ appears}.\\\\[4pt]\nLet's first find the probability mass function of $X$.\n\nNow $X$ can take on the values\n$\\{1,\\,2,\\,3,\\,\\ldots\\}$, so we  have a  non-uniform random\nvariable with infinitely many possibilities.  Since\n\\ba{\n&f(1)\\; =\\; \\P(X=1)\\;=\\;P(\\mathsf{H})\\;=\\;\\frac{1}{2}\\enspace , & \\\\\n&f(2)\\; =\\; \\P(X=2)\\;=\\;P(\\mathsf{TH})\\;=\\;\\frac{1}{2}\\cdot \\frac{1}{2}\\;= \\;\\left(\\frac{1}{2}\\right)^2 \\enspace , \\\\\n&f(3)\\; = \\; \\P(X=3)\\;=\\;P(\\mathsf{TTH})\\;=\\;\\frac{1}{2}\\cdot \\frac{1}{2}\\cdot \\frac{1}{2}\\;= \\;\\left(\\frac{1}{2}\\right)^3 \\enspace, \\qquad \\textrm{etc.}\n}the  probability mass function of $X$ is:\n$$f(x)\\; =\\; \\P(X=x)\\;=\\;\\left(\\frac{1}{2}\\right)^x, \\quad x=1,2,\\dots \\enspace.$$\n\\end{example}\n\n\\bigskip\n\nIn the previous Example, % \\ref{Ex:WaitinfFor1stHeads},  %%cross-referencing needs fixing as the counters are clashing need change in new_base macro file\nnoting that we have independent trials, we get:\n\n\\[f(x)\\; = \\;\\P(X=x)\\;=\\;\\P(\\mathsf{\\underbrace{\\mathsf{TT}\\ldots\\mathsf{T}}_{n-1}\\mathsf{H}})\\;=\\; \\P(\\mathsf{T})^{x-1}\\,\\P(\\mathsf{H})\\;=\\;\n\\left(\\frac{1}{2}\\right)^{x-1}\\,\\frac{1}{2}\\,.\\]\nMore generally, let there be two possibilities, success ($\\mathsf{S}$) or failure\n($\\mathsf{F}$), with  $\\P(\\mathsf{S})=  \\theta$  and \\newline $\\P(\\mathsf{F})=1-\\theta$ so that:\n\\[\\P(X=x)\\;=\\;\\P(\\underbrace{\\mathsf{F F} \\ldots \\mathsf{F}}_{x-1}\\mathsf{S})\\;=\\; (1 - \\theta)^{x-1}\\, \\theta\\,.\\]\n\n This is called a {\\bf geometric random variable} with ``success\n probability'' parameter $\\theta$. We can spot a geometric distribution\n because there will be  {\\em a sequence of independent  trials with a constant\n   probability  of success. We are counting the number of trials until\n   the first success appears.} Let us define this random variable formally next.\n\n\\begin{model}[$\\geometric(\\theta)$ RV]\\label{M:GeomRV}\nGiven a parameter $\\theta \\in (0,1)$, the PMF of the $\\geometric(\\theta)$ RV $X$ is\n\\begin{equation}\\label{E:Geometricpdf}\nf(x;\\theta) =\n\\begin{cases}\n\\theta(1-\\theta)^{x} & \\text{if $x \\in \\Zz_+ := \\{0,1,2,\\ldots \\}$} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\nIt is straightforward to verify that $f(x;\\theta)$ is indeed a PMF :\n\\[\n\\sum_{x=0}^{\\infty} f(x;\\theta) = \\sum_{x=0}^{\\infty} \\theta(1-\\theta)^{x}\n= \\theta \\left( \\frac{1}{1-(1-\\theta)} \\right) =  \\theta \\left( \\frac{1}{\\theta} \\right) = 1\n\\]\n\n{\\scriptsize\nThe above equality is a consequence of the geometric series identity \\eqref{E:GeomSeries} with $a=\\theta$ and $\\vartheta:=1-\\theta$:\n\\begin{equation}\\label{E:GeomSeries}\n \\sum_{ x =0}^{\\infty} a \\vartheta^x = a \\left( \\frac{1}{1-\\vartheta} \\right) , \\ \\text{provided, } 0 < \\vartheta < 1 \\ .\n\\end{equation}\n\\begin{proof}\n\\[\na+a\\vartheta+a\\vartheta^2+\\cdots+a\\vartheta^n\n= \\sum_{0 \\leq x \\leq n} a \\vartheta^x\n= a+ \\sum_{1 \\leq x \\leq n} a \\vartheta^x\n= a +  \\vartheta  \\sum_{1 \\leq x \\leq n} a \\vartheta^{x-1}\n= a +  \\vartheta  \\sum_{0 \\leq x \\leq n-1} a \\vartheta^{x}\n= a +  \\vartheta  \\sum_{0 \\leq x \\leq n} a \\vartheta^{x} - a \\vartheta^{n+1}\n\\]\nTherefore,\n\\begin{eqnarray}\n\\sum_{0 \\leq x \\leq n} a \\vartheta^x\n&=&  a +  \\vartheta  \\sum_{0 \\leq x \\leq n} a \\vartheta^{x} - a \\vartheta^{n+1} \\notag \\\\\n\\left( \\sum_{0 \\leq x \\leq n} a \\vartheta^x \\right) - \\left( \\vartheta  \\sum_{0 \\leq x \\leq n} a \\vartheta^{x} \\right)\n&=&  a  - a \\vartheta^{n+1} \\notag \\\\\n\\left( \\sum_{0 \\leq x \\leq n} a \\vartheta^x \\right) (1-\\vartheta)\n&=&  a (1 -  \\vartheta^{n+1}) \\notag \\\\\n\\sum_{0 \\leq x \\leq n} a \\vartheta^x\n&=&  a \\left( \\frac{1 -  \\vartheta^{n+1}}{1-\\vartheta} \\right) \\notag\\\\\n \\sum_{ x =0}^{\\infty} a \\vartheta^x  := \\lim_{n \\rightarrow \\infty} \\sum_{0 \\leq x \\leq n} a \\vartheta^x\n&=&  a \\left( \\frac{1}{1-\\vartheta} \\right) , \\ \\text{provided, } 0 < \\vartheta < 1 \\notag\n\\end{eqnarray}\n\\end{proof}\n}\nThe outcome of a $\\geometric(\\theta)$ RV can be thought of as ``the number of tosses needed before the appearance of the first `Head' when tossing a coin with probability of `Heads' equal to $\\theta$ in a independent and identical manner.''\n\\end{model}\n\n\\begin{figure}[htpb]\n\\caption{PMF of $X \\sim \\geometric(\\theta=0.5)$ and the relative frequency histogram based on $100$ and $1000$ samples from $X$ according to Simulation~\\ref{SIM:Geometric} and Labwork~\\ref{LW:RelFreqHistForGeomSims} you will see in the sequel.\\label{F:PlotPdfSimHistGeomthetaHalf}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/PlotPdfSimHistGeomthetaHalf}}\n\\end{figure}\n\n\\begin{Exercise}[title={Coupon Collector's Probem},label={xCouponCollPr}]\nRecall the Coupon Collector's Problem from lectures.%TODO\n\\end{Exercise}\n\\begin{Answer}\nThis was done in week 1. Get notes from your mates or wait until Raaz scribes for virtual convenience.\n\\end{Answer}\n\n\\begin{example}\\label{Exmp:Flip10times}\nSuppose we flip a coin 10 times and count the number of heads.  Let's consider the probability of getting three  heads, say. \nThe probability that the first three flips are heads and the last  seven  flips are tails, \\emph{in order},  is \\[ \\underbrace{\\frac{1}{2} \\frac{1}{2}\n    \\frac{1}{2}}_{3 \\text{ successes}}\n  \\,\\underbrace{\\frac{1}{2} \\frac{1}{2} \\dots \\frac{1}{2}}_{7\n    \\text{ failures}} \\, .\\]\nBut there are \\[\\binom{10}{3} \\;=\\; \\frac{10!}{7!\\, 3!}\\;=\\;120 \\] ways\nof ordering three heads and seven tails,  so the\n  probability  of getting three  heads and seven  tails \\emph{in any order},  is\\[\\P( \\text{`} 3 \\text{ heads'}) \\;=\\; \\binom{10}{3}  \\left(\\frac{1}{2}\\right)^3\n  \\;\\left(\\frac{1}{2}\\right)^7 \\;\\approx\\; 0.117\\]\n\\end{example}\n\nWe can describe  this sort of situation by considering a random variable $X$ which counts the number of successes, as follows:\n\n\\remove{\nThe RV $Y$ in \\hyperref[T:T3XRVs]{Table \\ref*{T:T3XRVs}} may be generalized to an experiment $\\EE{E}_{\\theta}^{n}$ with $n$ coin tosses.  \n%}% end remove\nLet $X_i$ be the Indicator function of the event `Heads on the $i$-th toss' as before.  Then $Y$ defined by,\n \\[\n Y := \\sum_{i=1}^n X_i := X_1 + X_2 + \\cdots + X_n  \\ ,\n \\]\nis the number of `Heads' in $n$ tosses.  \n%\\remove{\nAkin to the second row of \\hyperref[T:T3XRVs]{Table \\ref*{T:T3XRVs}}, for the `Toss $n$ times' experiment $\\EE{E}_{\\theta}^{n}$ the\n%} \nRV $Y$ as defined above will take values in $\\{0,1,2,\\ldots,n\\}$ and is therefore a discrete RV.  This is called the Binomial RV as defined next.  \n%\\remove{\nBut, first we remind ourselves of some elementary definitions involving arrangements of objects from a collection (recall \\hyperref[S:PermsFactsCombs]{Section~\\ref*{S:PermsFactsCombs}}).\n%}%end remove\n}\n\n\\begin{model}[$\\binomial(n,\\theta)$ RV]\\label{M:binomial}\nLet the RV $X=\\sum_{i=1}^n X_i$ be the sum of $n$ independent and identically distributed $\\bernoulli(\\theta)$ RVs, i.e.:\n\\[\nX=\\sum_{i=1}^n X_i, \\qquad X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta) \\ .\n\\]\nGiven two parameters $n$ and $\\theta$, the PMF of the $\\binomial(n,\\theta)$ RV $X$ is:\n\\begin{equation}\n f(x; n,\\theta) =\n \\begin{cases}\n \\displaystyle\\binom{n}{x} \\theta^x (1-\\theta)^{n-x} & \\text{if $x \\in \\{0,1,2,3,\\ldots,n\\}$} \\ ,\\\\\n 0 & \\text{otherwise}\n \\end{cases}\n \\end{equation}\nwhere, $\\binom{n}{x}$ is:\n\\[\n\\binom{n}{x} = \\frac{n(n-1)(n-2)\\ldots(n-x+1)}{x(x-1)(x-2)\\cdots (2)(1)} =  \\frac{n !}{x! (n-x)!} \\ .\n \\]\n$\\binom{n}{x}$ is read as ``$n$ choose $x$.''\n \\end{model}\n{\\bf A Quick Justification:}  The argument from Example~\\ref{Exmp:Flip10times} generalises as follows.  \nSince the trials are independent and identical, the probability of $x$ successes followed by $n-x$ failures,\n\\emph{in order},  is\ngiven by\n\\[\\underbrace{\\mathsf{SS} \\dots \\mathsf{S}}_{x}\\underbrace{\\mathsf{FF} \\dots \\mathsf{F}}_{n-x}\\;=\\;\\theta^x (1-\\theta)^{n-x} \\,.\\]\n\n\nSince the $n$ symbols $\\mathsf{S S} \\dots \\mathsf{S} \\,\\mathsf{F F} \\dots \\mathsf{F}$ may be arranged in\n\\[\\displaystyle\\binom{n}{x} \\;=\\; \\frac{n!}{(n-x)! x!}\\]\nways, the probability of  $x$ successes and  $n-x$ failures,\n\\emph{in any order},  is\ngiven by\n\\[\\displaystyle\\binom{n}{x}\\;\\theta^x (1-\\theta)^{n-x}\\,.\\]\n\n{\\scriptsize\n\\begin{proof} This is only a sketch. A formal proof should start with the mathematical induction for the very formula for the binomial coefficient.\n\nObserve that for the $\\binomial(n,\\theta)$ RV $X$, $\\P(X=x) = f(x;n,\\theta)$ is the probability that $x$ of the $n$ $\\bernoulli(\\theta)$ trials result in an outcome of $1$'s.  Next note that if all $n$ $X_i$'s are $0$'s, then $X=0$, and if all $n$ $X_i$'s are $1$'s, then $X=n$.  In general, if some of the $n$ $X_i$'s are $1$'s and the others are $0$, then $X$ can only take values in $\\{0,1,2,\\ldots,n\\}$ and therefore $f(x;n,\\theta)=0$ if $x \\notin \\{0,1,2,\\ldots,n\\}$.\n\nNow, let us compute $f(x;n,\\theta)$ when $x\\in\\{0,1,2,\\ldots,n\\}$.  Consider the set of indices $\\{1,2,3,\\ldots,n\\}$ for the $n$ IID $\\bernoulli(\\theta)$ RVs $\\{X_1,X_2,\\ldots,X_n\\}$.  Now choose $x$ indices from $\\{1,2,\\ldots,n\\}$ to mark those trials in a particular realization of $\\{x_1,x_2,\\ldots,x_n\\}$ with the Bernoulli outcome of $1$.  The probability of each such event is $\\theta^x (1-\\theta)^{n-x}$ due to the IID assumption.  For each realization $\\{x_1,x_2,\\ldots,x_n\\} \\in \\{0,1\\}^{n} := \\{ \\text{all binary $(0-1)$ strings of length $n$}\\}$, specified by a choice of $x$ trial indices with Bernoulli outcome $1$, the binomial RV $X=\\sum_{i=1}^n X_i$ takes the value $x$.  Since there are exactly $\\binom{n}{x}$ many ways in which we can choose $x$ trial indices (with outcome $1$) from the set of $n$ trial indices $\\{1,2,\\ldots,n\\}$, we get the desired product for $f(x; n,\\theta) = \\binom{n}{x} \\theta^x (1-\\theta)^{n-x}$ when $x \\in \\{0,1,\\ldots,n\\}$.\n\\end{proof}\n}\n\\begin{figure}[htpb]\n\\caption{PDF of $X \\sim \\binomial(n=10,\\theta=0.5)$ and the relative frequency histogram based on $100,000$ samples from $X$ obtained according to Simulation~\\ref{SIM:BinomialFromGeoms}.\\label{F:PlotPdfSim10000HistBinomByGeomsn10thetaHalf}} % TODO check which of two simulation algs is coming from\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/PlotPdfSim10000HistBinomByGeomsn10thetaHalf}}\n\\end{figure}\n\n\\begin{example}\\label{Eg:70f10recover}\nFind the probability that seven of ten persons will recover from a\n  tropical disease where the probability is\n  identically $0.80$ that any one of them will recover from the\n  disease.\n\n{Solution:}\\\\[4pt]\nWe can assume independence here, so we have a binomial\nsituation with  $x=7$, $n=10$, and $\\theta=0.8$. Substituting these into the formula for the probability mass function for $\\binomial(10,0.8)$ random variable, we get:\n\\ba{f(7;10,0.8)&\\;=\\;\\binom{10}{7} \\times (0.8)^7 \\times\n  (1-0.8)^{10-7}\\\\[6pt]\n& \\;= \\frac{10!}{(10-7)! 7!} \\times (0.8)^7 \\times (1-0.8)^{10-7}\\\\[6pt]\n&=\\; 120 \\times (0.8)^7 \\times (1-0.8)^{10-7} \\qquad ^*\\text{{\\scriptsize In the exam you can give your answer as such an expression.}}\\\\[6pt]\n& \\approx \\; 0.20\n}\n\\end{example}\n\n\\begin{example}\\label{Eg:alteast2_6s}\n{Compute the probability of obtaining {\\em at least two\n    $\\mathsf{6}$'s} in rolling a fair die independently and identically\n  four times.}\n\n{Solution:}\\\\[4pt]\n{In any given toss let $\\theta=\\P(\\{\\mathsf{6}\\})=1/6$,\n$1-\\theta=5/6$, $n=4$.\n\nThe event {\\em at least two $\\mathsf{6}$'s} occurs if we obtain two or\nthree or four $\\mathsf{6}$'s.  Hence the answer is:\n\\ba{\n\\P(\\text{{\\em at least two $\\mathsf{6}$'s}})&\\;=\\; f\\left(2;4,\\frac{1}{6}\\right)\\;+\\;f\\left(3;4,\\frac{1}{6}\\right)\\;+\\;f\\left(4;4,\\frac{1}{6}\\right) \\\\[6pt]\n&=\\; \\binom{4}{2}\\left(\\frac{1}{6}\\right)^2\\left(\\frac{5}{6}\\right)^{4-2}\\;+\\;\n\\binom{4}{3}\\left(\\frac{1}{6}\\right)^3\\left(\\frac{5}{6}\\right)^{4-3}\\;+\\;\n\\binom{4}{4}\\left(\\frac{1}{6}\\right)^{4}\\left(\\frac{5}{6}\\right)^{4-4}\\\\[6pt]\n&=\\;\\frac{1}{6^4}\\,\\left(6\\cdot25+4\\cdot5+1\\right)\\\\[6pt]\n&\\approx \\;0.132\n}\n}\n\\end{example}\n\nTo make concrete sense of the $\\binomial(n,\\theta)$ and other more sophisticated concepts in the sequel, let us take a historical detour into some origins of statistical thinking in 19th century England.\n\n\\subsubsection{Sir Francis Galton's Quincunx}\\label{S:Quincunx}\nThis section is introduced to provide some forms for a kinesthetic (hands-on) and visual understanding of some elementary statistical distributions and laws.  The following words are from Sir Francis Galton, F.R.S., {\\em Natural Inheritance}, pp.~62-65, Macmillan, 1889.  In here you will already find the kernels behind the construction of $\\binomial(\\theta)$ RV as sum of IID $\\bernoulli(\\theta)$ RVs, Weak Law of Large Numbers, Central Limit Theorem, and more.  We will mathematically present these concepts in the sequel as a way of giving precise meanings to Galton's observations with his Quincunx.\n{\\it ``{\\em The Charms of Statistics}.--It is difficult to understand why statisticians commonly limit their inquiries to Averages, and do not revel in more comprehensive views.  Their souls seem as dull to the charm of variety as that of the native of one of our flat English counties, whose retrospect of Switzerland was that, it its mountains could be thrown into its lakes, two nuances would be got rid of at once.  An Average is but a solitary fact, whereas if a single other fact be added to it, an entire Normal Scheme, which nearly corresponds to the observed one, starts potentially into existence.\n\nSome people hate the very name of statistics, but I find them full of beauty and interest.  Whenever they are not brutalised, but delicately handled by the higher methods, and are warily interpreted, their power of dealing with complicated phenomenon is extraordinary.  They are the only tools by which an opening can be cut through the formidable thicket of difficulties that bars the path of those who pursue the Science of man.}\n\n\\begin{figure}[htpb]\n\\caption{Figures from Sir Francis Galton, F.R.S., {\\em Natural Inheritance}, , Macmillan, 1889.\\label{F:GaltonFigure78923}}\n\\mbox{\\subfigure[FIG.~7, FIG.~8, and FIG.~ 9 (p.~63)]{\\hspace{-0.15cm} \\includegraphics[width=3.250in,clip=,angle=0]{figures/GaltonsFigs789}} \\hspace{-0.5cm} \\subfigure[FIG.~2 and FIG.~3 (p.~38)]{\\includegraphics[width=3.40in,clip=,angle=0]{figures/GaltonsFigs23}} }\n\\end{figure}\n\n{\\it {\\em Mechanical Illustration of the Cause of the Curve of Frequency}.--The Curve of Frequency, and that of Distribution, are convertible : therefore if the genesis of either of them can be made clear, that of the other also becomes intelligible.  I shall now illustrate the origin of the Curve of Frequency, by means of an apparatus shown in Fig.~7, that mimics in a very pretty way the conditions\non which Deviation depends.  It is a frame glazed in front, leaving a depth of about a quarter of an inch behind the glass.  Strips are placed in the upper part to act as a funnel.  Below the outlet of the funnel stand a succession of rows of pins stuck squarely into the backboard, and below these again are a series of vertical compartments.  A charge of small shot is inclosed.  When the frame is held topsy-turvy, all the shot runs to the upper end; then, when it is turned back into its working position, the desired action commences.  Lateral strips, shown in the diagram, have the effect of directing all the shot that had collected at the upper end of the frame to run into the wide moutn of the funnel.  The shot passes through the funnel and issuing from its narrow end, scampers deviously down through the pins in a curious and interesting way; each of them darting a step to the right or left, as the case may be, every time it strikes a pin.  The pins are disposed in a quincunx fashion, so that every descending shot strikes against a pin in each successive row.  The cascade issuing from the funnel broadens as it descends, and, at length, every shot finds itself caught in a compartment immediately after freeing itself from the last row of pins.  The outline of the columns of shot that accumulate in the successive compartments approximates to the Curve of Frequency (Fig.~3, p.~38), and is closely of the same shape however often the experiment is repeated.  The outline of the columns would become more nearly identical with the Normal Curve of Frequency, if the rows of pins were much more numerous, the shot smaller, and the compartments narrower; also if a larger quantity of shot was used.}\n\n{\\it The principle on which the action of the apparatus depends is, that a number of small and independent accidents befall each shot in its career.  In rare cases, a long run of luck continues to favour the course of a particular shot towards either outside place, but in the large majority of instances the number of accidents that cause Deviation to the right, balance in a greater or less degree those that cause Deviation to the left.  Therefore most of the shot finds its way into the compartments that are situated near to a perpendicular line drawn from the outlet of the funnel, and the Frequency with which shots stray to different distances to the right or left of that line diminishes in a much faster ratio than those distances increase.  This illustrates and explains the reason why mediocrity is so common.'' }\n\n\nWe now consider the last of our common discrete random variables for now, the {\\bf Poisson} case.  \nA Poisson random variable counts the number of times an event occurs.\n\nWe might, for example, ask:\n\\bit\n\\item How many customers visit Cafe Angstrom each day?\n\\item How many sixes  are scored  in a cricket season? {\\scriptsize Cricket is a game played in the English-speaking worlds.}\n\\item How many bombs hit a city block in south London during World War II?\n\\eit\n\nA Poisson experiment has the following characteristics:\n\n\\bit\n\\item The average  rate of an event occurring is known. This rate is constant.\n\\item  The probability that an event  will occur during a short continuum is proportional to the size of the continuum.\n\\item  Events occur independently.\n\\eit\n\nThe number of events occurring  in a Poisson experiment is referred to as a\n{\\bf Poisson random variable}.\n\n\\begin{model}[$\\poisson(\\lambda)$ RV]\\label{M:Poisson}\nGiven a real parameter $\\lambda>0$, the discrete RV $X$ is said to be $\\poisson(\\lambda)$ distributed if $X$ has PDF:\n\\begin{equation}\\label{E:Poissonpdf}\nf(x;\\lambda) =\n\\begin{cases}\n \\frac{ e^{-\\lambda} \\lambda^x}{x!} & \\text{if $x \\in \\Zz_+ := \\{0,1,2,\\ldots\\}$} \\ , \\\\\n0 & \\text{otherwise} \\ .\n\\end{cases}\n\\end{equation}\n\nNote that the PDF integrates to $1$:\n\\[\n\\sum_{x=0}^{\\infty} f(x;\\lambda)\n= \\sum_{x=0}^{\\infty}  \\frac{ e^{-\\lambda} \\lambda^x}{x!}\n=  e^{-\\lambda} \\sum_{x=0}^{\\infty}  \\frac{\\lambda^x}{x!}\n=  e^{-\\lambda} e^{\\lambda}\n= 1 \\ ,\n\\]\nwhere we exploit the Taylor series of $e^{\\lambda}$ to obtain the second-last equality above.\n\nWe interpret $X$ as the number of times an event occurs during a\nspecified continuum given that the average value in the continuum is\n$\\lambda$. \n\\end{model}\n\n\n\\begin{example}{\\label{eqn:poi_cars}}\nIf on the average, 2 cars enter a certain parking lot per minute,\n  what is the probability that during any given minute three cars or\n  fewer\n  will enter the lot?\n\nThink: Why are the assumptions for a Poisson random variable likely to\nbe correct here?\n\nNote: Use calculators, or Excel or Maple, etc. In an exam you may be given needed values from Poisson tables.\n\n\nLet the random variable $X$ denote the number of cars\n  arriving per minute. Note that the continuum is 1 minute here. Then  $X$ can be considered to have  a Poisson distribution\n  with $\\lambda=2$ because 2 cars enter on\naverage.\n\n\\medskip\n\nThe probability that three cars or fewer enter the lot is:\n\\ba{\\P(X\\leq 3)&\\;=\\;\nf(0;2)+f(1;2)+f(2;2)+f(3;2)\\\\\n&\\;=\\;e^{-2}\\left(\\frac{2^0}{0!}+\\frac{2^1}{1!}+\\frac{2^2}{2!}+\\frac{2^3}{3!}\\right) \\qquad ^*\\text{\\scriptsize{This is a perfectly fine answer in the exam.}}\\\\\n&\\;=\\;0.857 \\quad \n\\quad (\\text{3 sig. fig.})\n}\n\\end{example}\n\n\n\\begin{example}[Arrivals at a Service Station]\\label{Eg:serviceStation}\nThe proprietor of a service station finds that, on average, $8$\n  cars arrive \\emph{per hour} on Saturdays. What is the probability\n  that during a randomly chosen $15$ \\emph{minute period} on a Saturday:\n\\be\n\\item[(a)] No cars arrive?\n\\item[(b)]  At least three cars arrive?\n\\ee\n\nSolution:\\\\[4pt]\nLet the random variable $X$ denote the number of cars\n  arriving in a 15 minute interval. The continuum is 15 minutes here so\n  we need the average number of cars that arrive in a 15 minute\n  period, or $\\frac{1}{4}$ of an hour.  We know that 8 cars arrive per\n  hour, so  $X$ has a Poisson distribution\n  with\n\\[\\lambda \\;=\\; \\frac{8}{4}\\;=\\; 2\\,.\\]\n\n\\be\n\\item[(a)]\n\n\\[\\P(X=0)\\;=\\;  f(0; 2)\\;=\\;  \\frac{ e^{-2} 2^0}{0!}\\;=\\; 0.135 \\quad (\\text{3 sig. fig})\\]\n\n\\item[(b)]\n \\ba{\\P(X\\geq  3 )&\\;=\\;  1\\,-\\, \\P(X <  3)\\\\\n&\\;=\\;  1\\,-\\, \\P(X = 0)\\,-\\, \\P(X = 1)\\,-\\, \\P(X = 2)\\\\\n&\\;=\\;  1\\,-\\, f(0; 2) \\,-\\, f(1; 2) \\,-\\, f(2; 2) \\\\\n&\\;=\\;1-  0.1353 \\,-\\, 0.2707\\,-\\, 0.2707\\\\\n&\\;=\\; 0.323 \\quad (\\text{3 sig. fig.})}\n\\ee\n\\end{example}\n\n\\begin{rem}\nIn the binomial case where $\\theta$ is small and $n$ is large, it can be shown that the\nbinomial distribution with parameters $n$ and $\\theta$ is closely\napproximated by the Poisson distribution having $\\lambda = n \\theta$. The\nsmaller the value of $\\theta$ and larger the value of $n$, the better the approximation.\n\nIn the sequel we will see more formally, after understanding notions of convergence of RVs, that the sum of a sequence of $n$ IID $\\bernoulli(\\theta)$ RVs with $\\lambda = n \\theta$ converges to the $\\poisson(\\lambda)$ RV as $n \\to \\infty$ and $\\theta \\to 0$ in a specific sense.\n\\end{rem}\n\n\\begin{example}[Still-born Babies]\\label{Eg:still-born}\n{ About 0.01\\% of babies are stillborn in a certain hospital. We find the probability that of\n  the next 5000 babies born, there will be no more than 1 stillborn baby.\n\n  Let the random variable $X$ denote the number of\nstillborn babies. Then $X$ has a binomial distribution with parameters\n$n=5000$ and $\\theta = 0.0001$.  Since $\\theta$ is so small and $n$ is\nlarge, this\nbinomial distribution may be approximated by a Poisson distribution\n  with parameter\n\\[\\lambda\\;=\\; n\\,\\theta\\;=\\; 5000 \\times 0.0001 \\;=\\; 0.5\\,. \\]\nHence\n \\[\\P(X\\leq 1)\\;=\\; \\P(X=0)\\,+\\, \\P(X=1)\\,=\\, f(0;0.5) \\,+\\, f(1;0.5)\\;=\\; 0.910 \\quad (\\text{3 sig. fig.})\\]\n}\n\\end{example}\n\n\\begin{Exercise}[title={Nazi Bombs on London},label={xbombsOnLondon}]\nFeller discusses the probability and statistics of flying bomb hits in an area of southern London during II world war.  \nThe area in question was partitioned into $24 \\times 24 = 576$ small squares.  \nThe total number of hits was $537$.  \nThere were $229$ squares with $0$ hits, $211$ with $1$ hit, $93$ with $2$ hits, $35$ with $3$ hits, $7$ with $4$ hits and $1$ with $5$ or more hits.  \nAssuming the hits were purely random, use the Poisson approximation to find the probability that a particular square would have exactly $k$ hits.  Compute the expected number of squares that would have $0$, $1$, $2$, $3$, $4$, and $5$ or more hits and compare this with the observed results (Snell 9.2.14).  \n\\end{Exercise}\n\n\\begin{Answer}\nWe are given that $537$ flying bombs hit an area $A$ of south London made up of $24 \\times 24=576$ small equal-sized areas, say $A_1,A_2,\\ldots,A_{576}$.  \nAssuming the hits were purely random over $A$ the probability that a particular bomb will hit a given small area, say $A_i$, is $\\frac{1}{576}$.  \nLet $X$ denote the number of hits that a small area $A_i$ receives in this German raid.  \nSince $537$ bombs fell over $A$, we can model $X$ as $\\binomial(n=537,\\theta=\\frac{1}{576})$ that is counting the number of `successes' (for German bombers) with probability $\\theta$ in a sequence of $n=537$ independent $\\bernoulli(\\theta)$ trials.  \nFinally, we can approximate this $\\binomial(n=537,\\theta=\\frac{1}{576})$ random variable by $\\poisson(\\lambda)$ random variable with $\\lambda=n\\theta=\\frac{537}{576} \\approxeq 0.933$.\nUsing the probability mass function formula for $\\poisson(\\lambda=0.933)$ random variable $X$ we can obtain the probabilities and compare them with the relative frequencies from the data as follows:\n\n\\begin{center}\n{\\small\n\\begin{tabular}{|c|c|c|c|}\n\\hline\n$x$ & observed frequency & observed relative frequency & Prob of $x$ hits\\\\\\hline\n$0$ & $229$ & $229/576=0.398$ & $f(0;0.933) = 0.394$\\\\\n$1$ & $211$ & $211/576=0.366$ & $f(1;0.933) = 0.367$\\\\\n$2$ & $93$ & $93/576=0.161$ & $f(2;0.933) = 0.171$\\\\\n$3$ & $35$ & $35/576=0.0608$ & $f(3;0.933) = 0.0532$\\\\\n$4$ & $7$ & $7/576=0.0122$ & $f(4;0.933) = 0.0124$\\\\\n$\\geq 5$ & $1$ & $1/576=0.00174$ & $1-\\sum_{x=0}^4f(x;0.933) = 0.00275$\\\\\\hline\n\\end{tabular}\n}\n\\end{center}\n\\end{Answer}\n\n\\bigskip\n\n\\begin{framed}\nTHINKING POISSON\\\\\n\nThe Poisson distribution has been described as a limiting version of the\nBinomial. In particular, Exercise~\\ref{eqn:poi_cars} thinks of a Poisson distribution as a model for the number of events (cars) that occur in a period of time (1 minute) when in each little chunk of time one car arrives with constant probability, independently of the other time intervals. This leads to the general view of the Poisson distribution as a good model when:\n\n\n\\cen{{\\emph{You count the number of events in a continuum when the events occur at constant rate, one at a time and independent of each other.}}}\n\n\\end{framed}\n\n\nDISCRETE RANDOM VARIABLE SUMMARY\\\\\n\nProbability mass function $$f(x)=\\P(X=x_i)$$\nDistribution function $$F(x)=\\sum_{x_i\\leq x}f(x_i)$$\n\n\\begin{center}\n{\\renewcommand{\\arraystretch}{1.5}\n\\begin{tabular}{|c|c|p{3.2cm}|p{6.2cm}|}\n\\multicolumn{1}{c}{\\bf Random  Variable} & \\multicolumn{1}{c}{\\bf Possible  Values}\n&\\multicolumn{1}{c}{\\bf Probabilities} &\\multicolumn{1}{c}{\\bf Modelled situations} \\\\\\hline\nDiscrete  uniform&$\\{x_1,x_2,\\dots,x_k\\}$&$\\P(X=x_i)=\\displaystyle\\frac{1}{k}$&Situations with $k$ equally likely values.  Parameter: $k$.\\\\\\hline\n$\\bernoulli(\\theta)$&$\\{0,1\\}$&$\\P(X=0)=1-\\theta$\\newline$\\P(X=1)=\\theta$&Situations with only 2 outcomes, coded 1 for success and 0 for failure.\\newline Parameter: $\\theta=\\P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nGeometric($\\theta$)&$\\{1,2,3,\\dots\\}$&$\\P(X=x)\\newline=(1-\\theta)^{x-1}\\theta$& Situations where you count the number of trials until the first success in a sequence of independent trails with a constant probability of success. \\newline Parameter: $\\theta=\\P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nBinomial($n,\\theta$)&$\\{0,1,2,\\dots,n\\}$&$\\P(X=x)$\\newline $=\\displaystyle\\binom{n}{x}\\theta^x(1-\\theta)^{n-x}$&Situations where you count the number of success in $n$ trials where each trial is independent and there is a constant probability of success.\\newline Parameters: $n \\in \\{1,2,\\ldots\\}$; $\\theta=\\P(\\textrm{success}) \\in (0, 1)$.\\\\\\hline\nPoisson($\\lambda$)&$\\{0,1,2,\\dots\\}$&$\\P(X=x)\\newline=\\displaystyle \\frac{\\lambda^xe^{-\\lambda}}{x!}$&Situations where you count the number of events in a continuum where the events occur one at a time and are independent of one another.\\newline Parameter: $\\lambda$= rate $\\in (0,\\infty)$.\\\\\\hline\n\\end{tabular}}\n\\end{center}\n\n\\input{ExsInDiscreteRVs.tex}\n\n\\section{Continuous Random Variables}\\label{S:ContRVs}\n\nIf $X$ is a measurement of a continuous quantity, such as,\n\\begin{itemize}\n\\item the maximum diameter in millimeters of a venus shell I picked up at New Brighton beach, \n\\item the distance you transported yourself to lectures today in meters, \n\\item the volume of rain that fell on the roof of this building over the past 365 days in litres,\n\\item the vertical position (in micro meters above sea-level) since the release of a pollen grain at a location in Lake Rogen in H\\\"arjedalen, as it traces through G\\\"ota~\\\"alv—Klar\\\"alven, the longest river of Sweden before discharging in a delta into V\\\"anern at Karlstad. \n\\item the volume of water (in cubic meters) that fell on the southern Alps of the South Island of New Zealand throughout last year.  \n\\item etc.,\n\\end{itemize}\nthen $X$ is a continuous random variable. Continuous random variables are based on measurements in a continuous scale of a given precision as opposed to discrete random variables that are based on counting.\n\n\\begin{example}\\label{EgTimeStudentLeaves}\nSuppose that  $X$ is  the time, in minutes, before the next student\n  leaves the lecture room. This is an example of a  continuous random\n  variable that takes one of (uncountably)  infinitely many values.\n  When a student leaves, $X$ will take on the value $x$ and this $x$\n  could be $2.1$ minutes, or $2.1000000001$ minutes,  or $2.9999999$\n  minutes, etc., depending the measurement precision of the clock being used to measure time.  \n\nFinding $\\P(X=2)$, for example,  doesn't make sense because\n  how can it ever be {\\em exactly} $2.00000 \\cdots$ minutes? It is more\n  sensible to consider  probabilities like  $\\P(X>x)$ or $\\P(X<x)$ or $\\P(a < X < b)$ with $a < b$, up to measurement precision of the time-measuring clock rather\n  than the discrete approach of trying to compute $\\P(X=x)$.\n\\end{example}\n\n The characteristics of continuous random variables are:\n\\bit\n\\item  The outcomes are measured, not counted.\n\\item  Geometrically, {\\em the probability of an outcome is equal to an area}\n  under a mathematical curve.\n\\item  Each individual value has zero probability of occurring. So we find the probability\n      that the value is between two endpoints of an interval, or a set of intervals, including half-lines in $\\Rz$.\n\\eit\n\n\\begin{definition}[probability density function (PDF)]\\label{D:PDF}\nA RV $X$ with distribution function (DF) given by $F$ is said to be {\\bf continuous} if there exists a piecewise-continuous function $f$, called the {\\bf probability density function (PDF)} of $X$, such that \n\\begin{equation}\\label{eqn:cdf_integral}\nF(x)\\;=\\; \\P(X\\leq x)\\;=\\;\\int_{-\\infty}^x f(v) \\;dv\n\\end{equation}\nwhere $f: \\Rz \\to \\Rz$ is a non-negative function, i.e., $f(x)\\geq 0$. \nWe write $v$ because $x$ is needed as the upper limit of the integral.\nPiecewise-continuity of $f$ means $f$ is continuous, perhaps possibly at the $x$-values where $f$ is discontinuous between the continuous pieces (see \\url{https://en.wikipedia.org/wiki/Piecewise}). \n\\end{definition}\n\nThe following hold for a continuous RV $X$ with PDF $f$:\n\\begin{enumerate}\n\\item For any $x \\in \\Rz$, $\\P(X=x)=\\P(X \\in [x,x]) = \\int_x^x f(v)dv = 0$.\n\\item By the fundamental theorem of calculus:\n\\begin{equation}\\label{eqn:density_dev_cdf}\nf(x) = \\frac{d}{dx} F(x) =: F'(x), \n\\end{equation}\nfor every $x$ at which $f(x)$ is continuous.\n\\item Consequentially, for any $a,b \\in \\Rz$ with $a<b$,\n\\begin{eqnarray}\\label{eqn:con_intval_prob}\n\\P(a < X < b ) &=& \\P(a < X \\leq b) = \\P(a \\leq X \\leq b) = \\P(a \\leq X < b)\\\\\n               &=& F(b)-F(a)\\;=\\;\\int^b_a f(v)dv\\enspace.\n\\end{eqnarray}\n\\item And $P(\\Omega)=1$ implies that:\n\\[\n\\int_{-\\infty}^{\\infty} f(x) \\ dx = \\P(-\\infty < X < \\infty) = 1 \\ .\n\\] \n\\end{enumerate}\n\n\nThe next set of examples illustrate notation and typical applications of the formulae above.\n\n\\begin{example}\\label{EgPdf3xsqon01}\n{Consider the continuous random variable, $X$, whose  probability density function is:\n$$f(x)\\;=\\;\\begin{cases}3x^2&0<x<1\\\\0&\\textrm{otherwise}\\end{cases}$$\n \\be\n\\item[(a)]Find the distribution function, $F(x)$.\n\\item[(b)] Find $P(\\frac{1}{3}\\leq X\\leq \\frac{2}{3})$.\n\\ee\n}\n\n%{\\scriptsize\n{\\em Solution}\\\\[4pt]\n\\be\n\n\\item[(a)]First note that if $x\\leq 0$, then  $$F(x)\\;=\\;\\int^x_{-\\infty}0dv\\;=\\;0\\,.$$\nIf $0<x<1$, then\n\\begin{align*}F(x)&=\\;\\int^0_{-\\infty}0dv\\;+\\;\\int^x_03v^2dv\\\\[3pt]\n&=\\;0\\;+\\;\\left[v^3\\right]^x_0\\\\[3pt]\n&=\\;x^3\\end{align*}\nIf $x\\geq 1$, then\n\\begin{align*}F(x)&=\\int^0_{-\\infty}0dv\\;+\\;\\int^1_03v^2dv+\\int^x_10dv\\\\[3pt]\n&=0\\;+\\;\\left[v^3\\right]^1_0\\;+\\;0\\\\[3pt]\n&=\\;1\\end{align*}\nHence  $$F(x)\\;=\\;\\begin{cases}0&x\\leq 0\\\\x^3&0<x<1\\\\1&x\\geq 1\\end{cases}$$\n\n\\item[(b)]\n\\begin{align*}\nP\\left(\\frac{1}{3} \\leq X\\leq\\frac{2}{3}\\right )\n&=\\; F\\left(\\frac{2}{3}\\right) \\,-\\, F\\left(\\frac{1}{3}\\right) \\\\[3pt]\n&=\\; \\left(\\frac{2}{3}\\right)^3\\,-\\, \\left(\\frac{1}{3}\\right)^3\\\\[3pt]\n&=\\;\\frac{7}{27}\n\\end{align*}\n\\ee\n%}\n\\end{example}\n\n\\begin{example}\\label{EgPdfSinxon0piover2}\n{Consider the continuous random variable, $X$, whose distribution function is:\n$$F(x)\\;=\\;\\begin{cases}0&x\\leq0\\\\\\sin(x)& 0<x<\\frac{\\pi}{2}\\\\1&x\\geq\n  \\frac{\\pi}{2}\\end{cases}\\,.$$\n\\begin{enumerate}\n\\item[(a)] Find the probability density function, $f(x)$.\n\\item[(b)] Find $P\\left(X>\\frac{\\pi}{4}\\right)$\n\\end{enumerate}\n\n%{\\scriptsize\n{\\em Solution}\n\n\\begin{enumerate}\n\\item[(a)] The probability density function, $f(x)$ is given by\n$$f(x)\\;=\\;F^\\prime(x)\\;=\\;\\begin{cases}0&x < 0\\\\\\cos x&\n  0<x<\\frac{\\pi}{2}\\\\0&x\\geq \\frac{\\pi}{2}\\end{cases}$$\n\\item[(b)]\n$$P\\left(X>\\frac{\\pi}{4}\\right)\\;=\\;1-P\\left(X\\leq\n  \\frac{\\pi}{4}\\right)\\;=\\;1\\,-\\,F\\left(\\frac{\\pi}{4}\\right)\\;=\\;1-\\sin\\left(\\frac{\\pi}{4}\\right)\\;=  \\; 0.293 \\;(\\text{3 sig. fig.})$$\n\\end{enumerate}\n\n$^*$ You may stop at $1-\\sin\\left(\\frac{\\pi}{4}\\right)$ for full credit in the exam.\n\nNote: $f(x)$  is not defined at $x=0$ as $F(x)$ is not\ndifferentiable at $x=0$. There is a ``kink'' in the distribution\nfunction at $x=0$ causing this problem. It is standard to define\n$f(0)=0$ in such situations,  as $f(x)=0$ for $x<0$. This choice is arbitrary but it simplifies things\nand makes no difference to the calculated probability.\n%}\n}\n\\end{example}\n\nNow that we have warmed-up with two examples of continuous RVs, let us define the most elementary continuous RV next.\n\n\\subsection{An Elementary Continuous Random Variable}\\label{S:ElemContRV}\n\nAn elementary and fundamental example of a continuous RV is the $\\uniform(0,1)$ RV of \\hyperref[M:Uniform01]{Model \\ref*{M:Uniform01}}.  It forms the foundation for all non-uniform random variate generation and simulation as we will see in Chapter~\\ref{S:RNG}.  \nIn fact, it is appropriate to call this the fundamental model since every other probability model can be obtained from this one!\n\n\\begin{model}[The Fundamental Model]\\label{M:Uniform01}\nThe probability density function (PDF) of the fundamental model or the $\\uniform(0,1)$ RV is\n\\begin{equation}\\label{E:Uniform01pdf}\nf(x) = \\BB{1}_{[0,1]}(x) = \n\\begin{cases}\n1 & \\text{if $0 \\leq x \\leq 1$,}\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\nand its distribution function (DF) or cumulative distribution function (CDF) is:\n\\begin{equation}\\label{E:Uniform01DF}\nF(x) := \\int_{- \\infty}^x f(y) \\ dy =\n\\begin{cases}\n0 & \\text{if $x < 0$,} \\\\\nx & \\text{if $0 \\leq x \\leq 1$,}\\\\\n1 & \\text{if $x > 1$} \n\\end{cases}\n\\end{equation}\nNote that the DF is the identity map in $[0,1]$.  The PDF and DF are depicted in \\hyperref[F:unif01]{Figure~\\ref*{F:unif01}}.\n\\end{model}\n\nLet us draw the PDF and DF for $\\uniform(0,1)$ RV next by hand.\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/unif01fF}\n\\caption{$f(x)$ and $F(x)$ of the $\\uniform(0,1)$ random variable $X$.}\n\\end{center}\n\\end{figure}\n\n\\begin{figure}[htpb]\n\\caption{A convenient but mathematically imprecise Matlab plot from a polyline interpolation for the PDF and DF or CDF of the $\\uniform(0,1)$ continuous RV $X$.\\label{F:unif01}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/Unif01pdfcdf}}\n\\end{figure}\n\n\\remove{\n\\begin{labwork}[PDF of $\\uniform(0,1)$ RV]\\label{LW:Unif01Pdf}\nLet us encode the PDF of $\\uniform(0,1)$ as an M-file in {\\sc Matlab}.  Notice that the PDF function assigns $1$ to every value of $x \\in [0,1]$ and $0$ to every value of $x \\notin [0,1]$.  So, the problem mostly boils down to finding the entries inside and outside the range.  We can use {\\sc Matlab}'s built-in {\\tt find} function for this purpose.  We give an example to illustrate the syntax of {\\tt find}.\n\\begin{VrbM}\n>> Xs=[0.2511    1.6160    0.4733    -5.3517    0.8308    0.5853    2.5497] % an array Xs with real values \nXs =    0.2511    1.6160    0.4733   -5.3517    0.8308    0.5853    2.5497\n\\end{VrbM}\nWe can obtain the indices of {\\tt Xs} whose values are $\\geq 0$, i.e.~$\\{i: {\\tt Xs}(i) \\geq 0 \\}$ and the indices of {\\tt Xs} whose values are $\\leq 1$, i.e.~$\\{i: {\\tt Xs}(i) \\leq 1 \\}$ as follows:\n\\begin{VrbM}\n>> find(Xs >= 0)\nans =     1     2     3     5     6     7\n>> find(Xs <= 1)\nans =     1     3     4     5     6\n\\end{VrbM}\nThe intersection of the two sets of indices, i.e.~$\\{i: {\\tt Xs}(i) \\geq 0 \\ \\text{ and } \\  {\\tt Xs}(i) \\leq 1 \\} = \\{i: 0 \\leq {\\tt Xs}(i) \\leq 1 \\}$ can be obtained by {\\tt \\&}, the Boolean and, as follows:\n\\begin{VrbM}\n>> find(Xs >= 0 & Xs <= 1)\nans =     1     3     5     6\n\\end{VrbM}\nFinally, we know which indices of the {\\tt Xs} array should have the PDF value of $1$.  The remaining indices of {\\tt Xs} should therefore have the PDF value of $0$.  Let us declare an array called {\\tt Pdf} for the PDF values corresponding to the {\\tt Xs}.  We can initialise this array with zeros using the {\\tt zeros} function and make it of the same size as {\\tt Xs} as follows:\n\\begin{VrbM}\n>> size(Xs)\nans =     1     7\n>> Pdf = zeros(1,7)\nPdf =     0     0     0     0     0     0     0\n\\end{VrbM}\nNow, we can set the indices $1,3,5,6$ (returned by {\\tt find(Xs >= 0 \\& Xs <= 1)}) of {\\tt Pdf} array to 1.\n\\begin{VrbM}\n>> Pdf([1     3     5     6])=1\nPdf =     1     0     1     0     1     1     0\n\\end{VrbM}\nWe can modularise this process for an arbitrary input array {\\tt x} via a function in the following M-file.\n\\VrbMf[label=Unif01Pdf.m]{scripts/Unif01Pdf.m} \nLet us call the function we wrote called {\\tt Unif01Pdf} next.\n\\begin{VrbM}\n>> help Unif01Pdf\n  Unif01Pdf(x) returns the PDF of Uniform(0,1) RV X\n  the input x can be an array\n>> Xs\nXs =    0.2511    1.6160    0.4733   -5.3517    0.8308    0.5853    2.5497\n>> Unif01Pdf(Xs)\nans =     1     0     1     0     1     1     0\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[CDF of $\\uniform(0,1)$ RV]\\label{LW:Unif01Cdf}\nUnderstand each step in the function {\\tt Unif01Cdf}:\n\\VrbMf[label=Unif01Cdf.m]{scripts/Unif01Cdf.m} \nWhen we type in {\\tt help Unif01Cdf}, {\\tt Xs} and {\\tt Unif01Cdf(Xs)} we can confirm that the {\\tt Unif01Cdf} function is correctly reporting the CDF values of the input array {\\tt Xs}.\n\\begin{VrbM}\n>> help Unif01Cdf\n  Unif01Cdf(x) returns the CDF of Uniform(0,1) RV X\n  the input x can be an array \n>> Xs\nXs =    0.2511    1.6160    0.4733   -5.3517    0.8308    0.5853    2.5497\n>> Unif01Cdf(Xs)\nans =    0.2511    1.0000    0.4733         0    0.8308    0.5853    1.0000\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[Plot of the PDF and the CDF for the $\\uniform(0,1)$ RV]\\label{LW:PlotUnif01PdfCdf}\nGenerate the plot of the PDF and the CDF for the $\\uniform(0,1)$ RV $X$ by following the commands below.  Go through every step and understand each command when you reproduce the plot.\n\\VrbMf[label=plotunif.m]{scripts/plotunif.m} \nThe plot was saved as an encapsulated postscript file from the File menu of the Figure window and is displayed in \\hyperref[F:unif01]{Figure~\\ref*{F:unif01}}.\n \\end{labwork}\n}\n\n{\\bf **tossing a fair coin infinitely often, i.e., IID sequence of $\\bernoulli(1/2)$ trials, and the fundamental model}\n\n%TODO\\input{figures/UnifsInUnif.tex}\n\n--- The fundamental model is equivalent to infinite tosses of a fair coin (see using binary expansion of any $x \\in (0,1)$ if you want as suggested in optional Exercise~\\ref{underMPSA} on intuiting a most primitive sigma-algebra)\n\n--- The fundamental model has infinitely many copies of itself within it! You can see this since its DF $F$ is the identity function on $[0,1]$ or equivalently how the dyadic binary tree is identical below a given node in the tree no matter which node in the tree you choose.\n\n\n{\\bf **universality of the fundamental model}\n\n--- one can obtain any other random variable from the fundamental model whose unique DF is its own inverse, i.e., $F(x)=F^{[-1]}(x)$, as you will See from von Neumann's Fundamental Theorem of Simulation in Chapter~\\ref{S:RNG}.\n\n\\subsection{Some Common Continuous Random Variables}\\label{S:CommonContRV}\n\nLet us warm-up with an example.\n\n\n\\begin{example}\\label{EgPdfeToTheminusx}\n{Let $X$ have  density function $f(x)\\,=\\,e^{-x}$, if $x\\geq0$,  and\n  zero otherwise.\n  \\be\n\\item[(a)]Find the distribution function.\n\\item[(b)] Find the probabilities, $P(\\frac{1}{4}\\leq X \\leq 2)$ and\n  $P\\left(-\\frac{1}{2}\\leq X\\leq \\frac{1}{2}\\right)$.\n\\item[(c)]Find $x$ such that $P(X\\leq x) =0.95$.\n\\ee\n}\n\nSolution:\\\\[4pt]\n{\\be\n\\item[(a)] \n$$\nF(x)\\;=\\;\\int_0^{x}e^{-v}dv\n\\;=\\;\\left.-e^{-v}\\right]^x_0 \n\\;=\\;-e^{-x}+1\\;=\\;1-e^{-x}\\qquad \\textrm{if }x \\geq 0\n$$\nTherefore, \n$$\nF(x)\\;=\\;\n\\begin{cases}\n1-e^{-x}& \\textrm{if }x \\geq 0\\enspace , \\\\\n0&\\textrm{otherwise}\\enspace.\n\\end{cases}\n$$\n\\item[(b)]\n$$\nP\\left(\\frac{1}{4}\\leq X\\leq 2\\right) \n\\;=\\;F(2)-\\,F\\left(\\frac{1}{4}\\right)\n\\;=\\;0.634\\;\\;(\\text{3 sig. fig.})\n$$\n$$\nP\\left(-\\frac{1}{2}\\leq X\\leq \\frac{1}{2}\\right) \n\\;=\\;\nF\\left(\\frac{1}{2}\\right)\\,-\\,F\\left(-\\frac{1}{2}\\right)\n\\;=\\;0.394 \\;\\;(\\text{3 sig. fig.})\n$$\n\\item[(c)] $$P(X\\leq x)\\;=\\;F(x)\\;=\\;1-e^{-x}\\;=\\;0.95$$\nTherefore, $$x\\;=\\;-\\log(1-0.95)\\;=\\;3.00\\;\\;(\\text{3 sig. fig.})\\enspace.$$\n\\ee\n}\n\\end{example}\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics[width=5.0in]{pstricks/exponentialLambdafF}\n\\caption{$f(x;\\lambda)$ and $F(x;\\lambda)$ of an exponential random variable where $\\lambda=1$ (dotted) and $\\lambda=2$ (dashed).}\n\\end{center}\n\\end{figure}\n\n\nThe previous example is a special case of the following parametric\nfamily of random variables.\n\n\\begin{model}[$\\exponential(\\lambda)$]\\label{M:exponential}\nFor a given $\\lambda > 0$, an $\\exponential(\\lambda)$ RV has the following PDF $f$ and DF $F$ and its complementary distribution function denoted by $\\overline{F}(x; \\lambda) := \\P(X > x) = 1-F(x;\\lambda)$:\n\\begin{eqnarray}\\label{E:Exponentialpdfcdf}\nf(x; \\lambda) &=& \\BB{1}_{(0,\\infty)} \\lambda e^{-\\lambda x} =\n\\begin{cases}\n\\lambda \\exp(-\\lambda x) & x>0 \\enspace ,\\\\\n0&\\textrm{otherwise} \\enspace ,\n\\end{cases}\\\\\nF(x; \\lambda) &=& 1-e^{-\\lambda x} \\enspace ,\\\\ \n\\overline{F}(x; \\lambda) = e^{-\\lambda x} \\enspace .\n\\end{eqnarray}\n\nThe last two equations are derived from definitions as follows:\n\\begin{multline*}\nF(x; \\lambda) = \\int_{-\\infty}^{x} \\BB{1}_{(0,\\infty)} \\lambda e^{-\\lambda v} dv = \\lambda \\int_0^x e^{-\\lambda v} dv = \\lambda \\left( -\\frac{1}{\\lambda} e^{-\\lambda v} \\right]_0^x =  \\left( - e^{-\\lambda v} \\right]_0^x \\\\ \\notag\n= -e^{-\\lambda x} - (-e^{-0}) = -e^{-\\lambda x} - (-1/e^0) = -e^{-\\lambda x} - (-1/1) = -e^{-\\lambda x} - (-1) = -e^{-\\lambda x} + 1 \\\\ \\notag\n\\end{multline*}\n\\[\\P(X > x) = 1- \\P(X \\leq x) = 1- F(x; \\lambda) = 1 - \\left( 1-e^{-\\lambda x}\\right) = e^{-\\lambda x}\\].\n\nThis distribution is unique because of its property of {\\bf memorylessness}, i.e., $\\P(X>x+y | X > y) = e^{-\\lambda x}$, and plays a fundamental role in modeling continuous time processes, such as time between occurrence of events of interest, as we will see in the sequel.\n\\end{model}\n\n\\remove{%%%%%%%%%%%%%%% SIMUL\nWe encode the PDF and DF of the $\\exponential(\\lambda)$ RV as \\Matlab functions {\\tt ExponentialPdf} and {\\tt ExponentialCdf} and use them to produce \\hyperref[F:plotPdfCdfExponentials]{Figure~\\ref*{F:plotPdfCdfExponentials}} in \\hyperref[Mf:ExponentialPdfCdf]{Labwork~\\ref*{Mf:ExponentialPdfCdf}}.\n}%end remove%%%%%%%%%%%%%%%% SIMUL?\n\n\\begin{figure}[htpb]\n\\caption{Density and distribution functions of $\\exponential(\\lambda)$ RVs, for $\\lambda=1, 10, 10^{-1}$, in four different axes scales.\\label{F:plotPdfCdfExponentials}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/plotPdfCdfExponentials}}\n\\end{figure}\n\n\\begin{example}[On a dark desert highway]\\label{darkDesHWWaitingTime}\n{At a certain location on a dark desert highway, the time in minutes between arrival of cars that exceed the speed limit is an $\\exponential(\\lambda=1/60)$ random variable. \nIf you just saw a car that exceeded the speed limit then what is the probability of waiting less than 5 minutes before seeing another car that will exceed the speed limit?}\n\n{\\em Solution:}\\\\[4pt]\n{\nThe waiting time in minutes is simply given by the $\\exponential(\\lambda=1/60)$ random variable.  \nThus, the desired probability is \n\\[\nP(0 \\leq X < 5)\n\\;=\\;\\int_0^5\\frac{1}{60}e^{-\\frac{1}{60}x}dx\n\\;=\\;\\left.-e^{-\\frac{1}{60}x}\\right]_0^5\n\\;=\\;-e^{-\\frac{1}{12}}\\,+\\,1\\;\\approx\\; 0.07996.\n\\]\nIn exam you can stop at the expression $-e^{-\\frac{1}{12}}+1$ for full credit.  \nYou may need a calculator for the last step (with answer $0.07996$).\n\nNote: We could use the distribution function directly:\n\\[P(0 \\leq X < 5)\\;=\\;  F\\left(5; \\frac{1}{60}\\right) \\,-\\, F\\left(0;\\frac{1}{60}\\right) \\;=\\;\nF\\left(5;\\frac{1}{60}\\right) \\;=\\; 1-e^{-\\frac{1}{60}5} \\;=\\; 1--e^{-\\frac{1}{12}} \\;\\approx\\; 0.07996\\]\n}\n\\end{example}\n\n\\begin{prop}[Memorylessness of $\\exponential(\\lambda)$ RV]\\label{P:memorylessnessOfExponentialLambdaRV}\nIf $X \\sim \\exponential(\\lambda)$, then $X$ has the property of {\\bf memorylessness}, i.e., \n\\begin{equation}\n\\boxed\n{\n\\P(X>x+y  | X > y) = \\P (X > x) \\enspace .\n} \n\\end{equation}\n\\end{prop}\n\\begin{proof}\nBy the definition of conditional probability,\n\\[\n\\P(X > x+y | X > y) =\\P( \\{X>x+y\\} |  \\{X > y \\}) = \\frac{\\P( \\{X>x+y\\} \\cap \\{X > y \\})}{\\P( \\{X>y\\} )}\n\\]\nDue to redundancy, i.e., $\\{X>x+y\\} \\subset \\{X > y \\} \\implies \\{X>x+y\\} \\cap \\{X > y \\}=\\{X>x+y\\}$, so\n\\begin{align*}\n\\P(X > x+y | X > y) \n&=  \\frac{\\P( \\{X>x+y\\}}{\\P( \\{X>y\\} )} = \\frac{\\overline{F}(x+y; \\lambda)}{\\overline{F}(y; \\lambda)} = \\frac{e^{-\\lambda(x+y)}}{e^{-\\lambda y}} \n= \\frac{e^{-\\lambda x} e^{-\\lambda y}}{e^{-\\lambda y}}\n= e^{-\\lambda x} = \\overline{F}(x; \\lambda) \\\\\n&= \\P(X > x)\n\\end{align*}\n\\end{proof}\n\n\\begin{Exercise}[title={Memoryless Server Times},label={xmemorylessnessOfExponentialLambdaRV}]\nSuppose customers in a Queue are served one at a time by a server whose service time is an independent and identical $\\exponential(\\lambda)$ RV, with $\\lambda=1/10$. The server is immediately free to serve the next customer once the current customer being served is done.\nSuppose you just arrive and are the first in the queue and know that the server is busy serving another customer. You do not know how long the customer has already been in service. \nWhat is the probability that the server will be free after $2$ units of time?\n\\end{Exercise}\n\\begin{Answer}\nLet $X \\sim \\exponential(\\lambda=0.1)$ denote the time taken to serve any given customer in an IID manner.\nLet $y$ denote the unknown time that the current customer being served has already been served before your arrival.\nBy memorylessness of $\\exponential(\\lambda=0.1)$ RV $X$, we know $\\P(X > 2 + y | X > y) = \\P(X > 2) = e^{-\\lambda 2} = e^{-2/10}$.\n\\end{Answer}\n\n\\bigskip\n\nLet us introduce parameters for the lower and upper bounds of the interval upon which a continuous RV is uniformly distributed using the following probability model.\n \n\\begin{model}[$\\uniform(\\theta_1,\\theta_2)$]\\label{M:Uniformab}\nGiven two real parameters $\\theta_1,\\theta_2 \\in \\Rz$, such that $\\theta_1 < \\theta_2$, the PDF of the $Uniform(\\theta_1,\\theta_2)$ RV $X$ is:\n\\begin{equation}\\label{E:Uniformabpdf}\nf(x;\\theta_1,\\theta_2) =\n\\begin{cases}\n\\frac{1}{\\theta_2 - \\theta_1} & \\text{if $\\theta_1 \\leq x \\leq \\theta_2$,}\\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\nand its DF given by $F(x;\\theta_1,\\theta_2) = \\int_{- \\infty}^x f(y; \\theta_1,\\theta_2) \\, dy$ is:\n\\begin{equation}\\label{E:Uniformabcdf}\nF(x; \\theta_1,\\theta_2) =\n\\begin{cases}\n0 & \\text{if $x < \\theta_1$} \\\\\n\\frac{x-\\theta_1}{\\theta_2-\\theta_1} & if~\\theta_1 \\leq x \\leq \\theta_2,\\\\\n1 & \\text{if $x > \\theta_2$}\n\\end{cases}\n\\end{equation}\nRecall that we emphasise the dependence of the probabilities on the two parameters $\\theta_1$ and $\\theta_2$ by specifying them following the semicolon in the argument for $f$ and $F$.\n\\end{model}\n\n\\begin{figure}[htbp]\n\\begin{center}\n\\includegraphics{pstricks/uniftheta1theta2fF}\n\\caption{$f(x)$ and $F(x)$ of the $\\uniform(\\theta_1,\\theta_2)$ random variable $X$.}\n\\end{center}\n\\end{figure}\n\n\n\\begin{Exercise}\\label{xPDFHeightOfUniformOn2_6}\n{Consider  a random variable with a probability density function\n\\[f(x)\\;=\\;\\begin{cases}\\displaystyle k & \\textrm{if} \\qquad  2\\leq\n  x\\leq 6 \\enspace,\\\\0& \\text{otherwise}\n\\end{cases}\n\\]\n\\be\n\\item[(a)] Find the value of $k$.\n\\item[(b)] Sketch the graphs of $f(x)$ and $F(x)$.\n\\ee\n}\n\\end{Exercise}\n\n\\begin{Answer}\n{\\be\n\\item[(a)] Since $f(x)$ is a density function which integrates to one,\n\\ba{\\int^6_2  f(x) \\,dx &\\;=\\; \\int^6_2  k \\, dx\\\\[3pt]\n1  &\\;=\\;\\left.  kx \\right]^6_2\\\\[3pt]\n1  &\\;=\\;6k \\,-\\, 2k\\\\[3pt]\n1  &\\;=\\;4k\\\\[3pt]\nk&\\;=\\; \\frac{1}{4}\n}\nas expected!\n\n\\medskip\n\n\\item[(b)] Now $$F(x)\\;=\\;\\begin{cases}0& x< 2 \\\\\n\\frac{1}{4} \\,( x-2)  & 2\\leq x<6\\\\\n1& x\\geq 6\\enspace.\n\\end{cases}\n$$\nso the graphs are:\n\n\\cen{Graphs of $f(x)$ and $F(x)$.}\n\\begin{center}\n\\includegraphics{pstricks/unif26fF}\n\\end{center}\n\n\\ee\n}\n\\end{Answer}\n%\\remove{%%%%%%%%%%%%%%%% drawn by hand\n%\\begin{figure}[htpb]\n%\\caption{A plot of the PDF, DF and inverse DF of the $\\uniform(-1,1)$ RV $X$.\\label{F:unifpm1}}\n%\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/Unifpm1pdfcdf}}\n%\\end{figure}\n%}%%%%%%%%%%%%% SHOULD go with Simulation?\n\nThe standard normal distribution is the most important continuous\nprobability distribution. It was first described by De Moivre in 1733\nand subsequently by C.~F.~Gauss (1777 - 1885).\nMany  random variables  have a normal distribution, or they are\napproximately normal, or can be transformed into normal random variables\nin a relatively simple fashion. Furthermore, the normal distribution is\na useful approximation of more complicated distributions.\n%%%%Location-scale Gaussian family as a linear transformation of the standard Gaussian RV\n\n\\begin{framed}\n\\begin{model}[$\\normal(0,1)$ or standard normal or Gaussian RV]\\label{Df:StandardNormal} \nA continuous random variable $Z$ is called \\textbf{standard normal} or {\\bf standard Gaussian} \nif its probability density function is\n\\begin{equation}\\label{E:StandardNormalPdf}\n\\phi(z) = \\frac{1}{\\sqrt{2\\pi}} \\exp{\\left( -\\frac{z^2}{2}\\right)} \\enspace.\n\\end{equation}\n\\end{model}\n\\end{framed}\n\nAn exercise in calculus yields the first two derivatives of $\\phi$ as follows:\n\\[\n\\frac{d \\phi}{dz} = - \\frac{1}{\\sqrt{2\\pi}}z \\exp{\\left( -\\frac{z^2}{2}\\right)}=-z\\phi(z), \\quad\n\\frac{d^2 \\phi}{dz^2} = \\frac{1}{\\sqrt{2\\pi}}(z^2-1) \\exp{\\left(-\\frac{z^2}{2} \\right)}=(z^2-1)\\phi(z) \\enspace .\n\\]\nThus, $\\phi$ has a global maximum at $0$, it is concave down if $z \\in (-1,1)$ and concave up if $z \\in (-\\infty,-1) \\cup (1,\\infty)$.  \nThis shows that the graph of $\\phi$ is shaped like a smooth symmetric bell centred at the origin over the real line.\n\n\n\\begin{classwork}\\label{xDrawPDFOfStdNormal}\nFrom the above exercise in calculus let us draw the graph of $\\phi$ by hand now!\n\nDo it step by step: $z^2$, $-z^2$, $-z^2/2$, $\\exp(-z^2/2)$, $\\phi(z) = \\frac{1}{\\sqrt{2\\pi}} \\exp(-z^2/2)$ now! \n\\vspace*{20mm}\n\\end{classwork}\n\nThe distribution function of $Z$ is given by\n\\begin{equation}\\label{E:StandardNormalDF}\n\\Phi(z) \\;=\\;\\frac{1}{\\sqrt{2\\pi}}\\int^z_{-\\infty}e^{-v^2/2}\\;dv \\enspace .\n\\end{equation}\n\n\\begin{rem}\n{The integral for $\\Phi(z)$ has no closed form expression and cannot be evaluated exactly by standard methods of calculus, but its values can be\nobtained numerically and tabulated.  Values of $\\Phi(z)$ are tabulated in the ``Standard Normal Distribution Function Table'' in Sec.~\\ref{S:NormalDFTable}.}\n\nWe can express $\\Phi(z)$ %$F(x;\\mu,\\sigma^2)$ \nin terms of the error function ($\\erf$) as follows:\n\\begin{equation}\\label{E:DFStandardNormalviaErf}\n%F(x;\\mu,\\sigma^2) = \\frac{1}{2} \\ \\erf \\left(  \\frac{x-\\mu}{\\sqrt{2 \\sigma^2}} \\right)+ \\frac{1}{2}\n\\Phi(z) = \\frac{1}{2} \\ \\erf \\left(  \\frac{z}{\\sqrt{2}} \\right)+ \\frac{1}{2}\n\\end{equation}\nAnd use \\Matlab's \\texttt{erf} function to get $\\Phi(z)$ numerically instead of looking up the Table.\n\\end{rem}\n\n\\begin{classwork}\\label{xDrawDFOfStdNormal}\n{Note that the curve of $\\Phi(z)$ is $S$-shaped, increasing in a strictly monotone way from $0$ at $-\\infty$ to $1$ at $\\infty$, and intersects the vertical axis at $1/2$. Draw this by hand too.}\\\\[4pt]\njust do it! \\vspace*{20mm}\n\\end{classwork}\n\n\\begin{example}\\label{Eg:UsingNormalTables}\nFind the probabilities, using  normal tables,  that a random variable having the standard\n  normal distribution will take on a value:\n\\bcols{2}\\begin{itemize}\n\\item [(a)] less that 1.72\n\\item [(b)]less than -0.88\n\\item [(c)]between 1.30 and 1.75\n\\item [(d)] between -0.25 and 0.45\n\\end{itemize}\\ecols\n\\begin{itemize}\n \\item [(a)]\n$$P(Z<1.72)\\;=\\;\\Phi(1.72) \\;=\\; 0.9573$$\n \\item [(b)] First note that $P(Z<0.88)\\;=\\;0.8106$, so that\n   \\ba{P(Z<-0.88) & \\;=\\;P(Z>0.88) \\\\\n     &\\;=\\;1-P(Z<0.88)\\\\&\\;=\\;1-\\Phi(0.88)\\\\ &\\;=\\;1-0.8106\\;=\\;0.1894}\n \\item [(c)]\n$P(1.30<Z<1.75)\\;=\\;\\Phi(1.75)-\\Phi(1.30)\\;=\\;0.9599-0.9032\\;=\\;0.0567$\n \\item [(d)]\n\\ba{P(-0.25<Z<0.45)&\\;=\\;P(Z<0.45)-P(Z<-0.25)\\\\&\\;=\\;P(Z<0.45)-(1-P(Z<0.25))\\\\&\\;=\\;\\Phi(0.45)-(1-\\Phi(0.25)) \\\\&=\\;(0.6736)-(1-0.5987)\\\\&\\;=\\;0.2723}\n\\end{itemize}\n\\end{example}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\bigskip\n{\n\\begin{framed}\nCONTINUOUS RANDOM VARIABLES: NOTATION\\\\\n\n$f(x)$: Probability density function (PDF)\n\\begin{itemize}\n\\item$f(x)\\;\\geq\\;0$\n\\item Areas underneath $f(x)$ measure probabilities.\n\\end{itemize}\n\n$F(x)$: Distribution function (DF)\n\\begin{itemize}\n\\item $0\\;\\leq\\;\\ F(x)\\;\\leq \\;1$\n\\item $F(x)\\;= \\;P(X\\leq x)$ is a probability\n\\item $F^{\\prime}(x)\\;=\\;f(x)$ for every $x$ where $f(x)$ is continuous\n\\item $F(x)\\;=\\;\\displaystyle\\int^x_{-\\infty}f(v)dv$\n\\item $P(a<X\\leq b)\\;=\\;F(b)-F(a)\\;=\\;\\displaystyle \\int^b_af(v)dv$\n\\end{itemize}\n\\end{framed}\n}\n\n\n\\remove{\n%The $\\exponential(\\lambda)$ random variable gives  the waiting times\\emph{ between} successive events of a process where the number of events in unit time is a $\\poisson(\\lambda)$  random variable.\n%Ben wants this justified - will do in MATH103 next year...\n\\Exmp\n}\n\n\\input{ExsInContinuousRVs.tex}\n\n\\section{Transformations of random variables}\\label{S:TransformationsOFRvs}\n\nSuppose we know the distribution of a random variable $X$.  How do we find the distribution of a transformation of $X$, say $g(X)$?\nBefore we answer this question let us ask a motivational question.  Why are we interested in functions of random variables?\n\n\\begin{example}\\label{EgProfitOn5With500cost}\nConsider a simple financial example where an individual sells $X$ items per day, the profit per item is $\\$ 5$ and the overhead costs are $\\$ 500$ per day.  The original random variable is $X$, but the random variable $Y$ which gives the daily profit is of more interest, where\n\\[\nY = 5X - 500 \\enspace . \n\\]\n\\end{example}\n\n\n\\begin{example}\\label{EgSignal2NoiseInDecibels10TimeslogBase10OfX}\nIn a cell-phone system a mobile signal may have a signal-to-noise-ratio of $X$, but engineers prefer to express such ratios in decibels, i.e.,\n\\[\nY = 10 \\log_{10}(X) \\enspace .\n\\]\n\\end{example}\n\n\\subsection{A Review of Inverse Images}\\label{S:RWInverseImages}\nHence in a great many situations we are more interested in functions of random variables. \nLet us return to our original question of determining the distribution of a transformation or function of $X$.  \nFirst note that this transformation of $X$ is itself another random variable, say $Y = g(X)$, \nwhere $g$ is a function from a subset $\\mathbb{X}$ of $\\mathbb{R}$ to a subset $\\mathbb{Y}$ of $\\mathbb{R}$, \ni.e., $g: \\mathbb{X} \\to \\mathbb{Y}$, $\\mathbb{X} \\subset \\mathbb{R}$ and $\\mathbb{Y} \\subset \\mathbb{R}$.\n\nThe {\\bf inverse image} of a set $A$ is the set of all real numbers in $\\mathbb{X}$ whose image is in $A$, i.e.,\n\\[\ng^{[-1]}(A) = \\{x \\in \\mathbb{X} : g(x) \\in A \\} \\enspace .\n\\] \nIn other words,\n\\[\nx \\in g^{[-1]}(A) \\ \\text{if and only if} \\ g(x) \\in A \\enspace .\n\\]\nFor example,\n\\begin{itemize}\n\\item if $g(x)=2x$ then $g^{[-1]}([4,6])=[2,3]$\n\\item if $g(x)=2x+1$ then $g^{[-1]}([5,7])=[2,3]$\n\\item if $g(x)=x^3$ then $g^{[-1]}([1,8])=[1,2]$\n\\item if $g(x)=x^2$ then $g^{[-1]}([1,4])=[-2,-1] \\cup [1,2]$\n\\item if $g(x)=\\sin(x)$ then $g^{[-1]}([-1,1])=\\mathbb{R}$\n\\item if ... %Raaz add other examples of the transformations done in the sequel here\n\\end{itemize}\nFor the singleton set $A = \\{y\\}$, we write $g^{[-1]}(y)$ instead of $g^{[-1]}(\\{y\\})$.  \nFor example,\n\\begin{itemize}\n\\item if $g(x)=2x$ then $g^{[-1]}(4)=\\{2\\}$\n\\item if $g(x)=2x+1$ then $g^{[-1]}(7)=\\{3\\}$\n\\item if $g(x)=x^3$ then $g^{[-1]}(8)=\\{2\\}$\n\\item if $g(x)=x^2$ then $g^{[-1]}(4)=\\{-2,2\\}$\n\\item if $g(x)=\\sin(x)$ then $g^{[-1]}(0)=\\{k \\pi: k \\in \\mathbb{Z}\\} = \\{\\ldots, -3 \\pi, -2 \\pi, -\\pi,0,\\pi, 2\\pi,3\\pi, \\ldots\\}$\n\\item if ... %Raaz add other examples of the transformations done in the sequel here\n\\end{itemize}\nIf $g:\\mathbb{X}\\to\\mathbb{Y}$ is one-to-one (injective) and onto (surjective), then the inverse image of a singleton set is itself a singleton set.  \nThus, the inverse image of such a function $g$ becomes itself a function and is called the {\\bf inverse function}.\nOne can find the inverse function, if it exists by the following steps:\n\\begin{itemize}\n\\item[{\\sf Step 1;}] write $y=g(x)$\n\\item[{\\sf Step 2;}] solve for $x$ in terms of $y$\n\\item[{\\sf Step 3;}] set $g^{-1}(y)$ to be this solution\n\\end{itemize}\nWe write $g^{-1}$ whenever the inverse image $g^{[-1]}$ exists as an inverse function of $g$.  \nThus, the inverse function $g^{-1}$ is a specific type of inverse image $g^{[-1]}$.  \nFor example,\n\\begin{itemize}\n\\item if $g(x)=2x$ then $g:\\mathbb{R} \\to \\mathbb{R}$ is injective and surjective and therefore its inverse function is:\\\\\n{\\sf Step 1;} $y=2x$, {\\sf Step 2;} $x=\\frac{y}{2}$, {\\sf Step 3;} $g^{-1}(y)=\\frac{y}{2}$\n\\item if $g(x)=2x+1$ then $g:\\mathbb{R} \\to \\mathbb{R}$ is injective and surjective and therefore its inverse function is:\\\\\n{\\sf Step 1;} $y=2x+1$, {\\sf Step 2;} $x=\\frac{y-1}{2}$, {\\sf Step 3;} $g^{-1}(y)=\\frac{y-1}{2}$\n\\item if $g(x)=x^3$ then $g:\\mathbb{R} \\to \\mathbb{R}$ is injective and surjective and therefore its inverse function is:\\\\\n{\\sf Step 1;} $y=x^3$, {\\sf Step 2;} $x={y}^{\\frac{1}{3}}$, {\\sf Step 3;} $g^{-1}(y)={y}^{\\frac{1}{3}}$\n\\end{itemize}\nHowever, you need to be careful by limiting the domain to obtain the inverse function for the following examples:\n\\begin{itemize}\n\\item if $g(x)=x^2$ and domain of $g$ is $[0,+\\infty)$ then its inverse function is $g^{-1}(y)=\\sqrt{y}$, \ni.e., if $g(x)=x^2 : [0,+\\infty) \\to [0,+\\infty)$ then the inverse image $g^{[-1]}(y)$ for $y \\in [0,+\\infty)$ is given by the inverse function $g^{-1}(y)=\\sqrt{y} : [0,+\\infty) \\to [0,+\\infty)$.\n\\item if $g(x)=x^2$ and domain of $g$ is $(-\\infty,0]$ then its inverse function is $g^{-1}(y)=-\\sqrt{y}$, \ni.e., if $g(x)=x^2 : (-\\infty,0] \\to [0,+\\infty)$ then the inverse image $g^{[-1]}(y)$ for $y \\in [0,+\\infty)$ is given by the inverse function $g^{-1}(y)=-\\sqrt{y} : [0,+\\infty) \\to (-\\infty,0]$.\n\\item if $g(x)=\\sin(x)$ and domain of $g$ is $[0,\\frac{\\pi}{2}]$ then its inverse function $g^{-1}(y)=\\arcsin(y)$, i.e., if $g(x)=\\sin(x) : [0,\\frac{\\pi}{2}] \\to [0,1]$ then the inverse image $g^{[-1]}(y)$ for $y \\in [0,1]$ is given by the inverse function $g^{-1}(y)=\\arcsin(y) : [0,1] \\to [0, \\frac{\\pi}{2}]$.\n\\item if $g(x)=\\sin(x)$ and domain of $g$ is $[-\\frac{\\pi}{2},\\frac{\\pi}{2}]$ then its inverse function $g^{-1}(y)=\\arcsin(y)$, i.e., if $g(x)=\\sin(x) : [-\\frac{\\pi}{2},\\frac{\\pi}{2}] \\to [-1,1]$ then the inverse image $g^{[-1]}(y)$ for $y \\in [-1,1]$ is given by the inverse function $g^{-1}(y)=\\arcsin(y) : [-1,1] \\to [-\\frac{\\pi}{2},\\frac{\\pi}{2}]$.\n\\item if ... %Raaz add other examples of the transformations done in the sequel here\n\\end{itemize}\n  \nNow, let us return to our question of determining the distribution of the transformation $g(X)$.  To answer this question we must first observe that the inverse image $g^{[-1]}$ satisfies the following properties:\n\\begin{itemize}\n\\item $g^{[-1]}(\\mathbb{Y}) = \\mathbb{X}$\n\\item For any set $A$, $g^{[-1]}(A^c) = \\left(g^{[-1]}(A)\\right)^c$\n\\item For any collection of sets $\\{A_1,A_2,\\ldots\\}$,\n\\[\ng^{[-1]}\\left( A_1 \\cup A_2 \\cup \\cdots \\right) = g^{[-1]}(A_1) \\cup g^{[-1]}(A_2) \\cup \\cdots \\enspace.\n\\]\n\\end{itemize}\nConsequentially, \n\\begin{equation}\\label{E:ProbOfgOfX}\n\\boxed{P \\left( g(X) \\in A \\right) = P \\left(X \\in g^{[-1]}(A) \\right)}\n\\end{equation} \nsatisfies the axioms of probability and gives the desired probability of the event $A$ from the transformation $Y=g(X)$ in terms of the probability of the event given by the inverse image of $A$ underpinned by the random variable $X$.  \nIt is crucial to understand this from the sample space $\\Omega$ of the underlying experiment in the sense that Equation~\\eqref{E:ProbOfgOfX} is just short-hand for its actual meaning:\n\\[\nP \\left( \\{\\omega \\in \\Omega: g(X(\\omega)) \\in A\\} \\right) \n= P \\left( \\left\\{ \\omega \\in \\Omega: X(\\omega) \\in g^{[-1]}(A) \\right\\} \\right) \\enspace .\n\\]\nBecause we have more than one random variable to consider, namely, $X$ and its transformation $Y=g(X)$ we will subscript the probability density or mass function and the distribution function by the random varaible itself.  For example we denote the distribution function of $X$ by $F_X(x)$ and that of $Y$ by $F_Y(y)$.\n\n\\subsection{Transformations of discrete random variables}\\label{TransformationsOFDiscreteRvs}\nFor a discrete random variable $X$ with probability mass function $f_X$ we can obtain the probability mass function $f_Y$ of $Y=g(X)$ using Equation~\\eqref{E:ProbOfgOfX} as follows:\n\\begin{eqnarray*}\nf_Y(y) \n&=& \\P(Y =y) = \\P(Y \\in \\{y\\}) \\\\\n&=& P \\left( g(X) \\in \\{y\\} \\right) = P \\left(X \\in g^{[-1]}(\\{y\\}) \\right)\\\\\n&=& P \\left(X \\in g^{[-1]}(y) \\right) = \\sum_{x \\in g^{[-1]}(y)} f_X(x) = \\sum_{x \\in \\{x: g(x)=y\\}} f_X(x) \\enspace .\n\\end{eqnarray*}\nThis gives the formula:\n\\begin{equation}\\label{E:PMFOfgOfX}\n\\boxed{\nf_Y(y) = \\P(Y =y) = \\sum_{x \\in g^{[-1]}(y)} f_X(x) = \\sum_{x \\in \\{x: g(x)=y\\}} f_X(x) \\enspace .\n}\n\\end{equation}\n\n\\begin{example}\\label{EXMP:Discrete1to1TransYis2X}\nLet $X$ be the discrete random variable with probability mass function $f_X$ as tabulated below:\\\\\n\\begin{center}\n\\begin{tabular}{r|rrr}\n$x$ & -1 & 0 & 1\\\\ \\hline\n &  &  & \\\\ \n$f_X(x)=\\P(X=x)$ & $\\frac{1}{4}$ & $\\frac{1}{2}$ & $\\frac{1}{4}$\n\\end{tabular}\n\\end{center}\nIf $Y=2X$ then the transformation $g(X)=2X$ has inverse image $g^{[-1]}(y)=\\{y/2\\}$.  \nThen, by Equation~\\eqref{E:PMFOfgOfX} the probability mass function of $Y$ is expressed in terms of the known probabilities of $X$ as:\\\\ \n$$f_Y(y)=\\P(Y=y)= \\sum_{x \\in g^{[-1]}(y)} f_X(x)  = \\sum_{x \\in \\{y/2\\}} f_X(x) = f_X(y/2) \\enspace ,$$\nand tabulated below:\\\\\n\\begin{center}\n\\begin{tabular}{r|rrr}\n$y$ & -2 & 0 & 2\\\\ \\hline\n &  &  & \\\\ \n$f_Y(y)$ & $\\frac{1}{4}$ & $\\frac{1}{2}$ & $\\frac{1}{4}$\n\\end{tabular}\n\\end{center}\n\\end{example}\n\n\\begin{example}\\label{EXMP:Discrete1to1TransYis2Xplus1}\nIf $X$ is the random variable in the previous Example then what is the probability mass function of $Y=2X+1$?\nOnce again,\n$$f_Y(y)=\\P(Y=y)= \\sum_{x \\in g^{[-1]}(y)} f_X(x)  = \\sum_{x \\in \\{(y-1)/2\\}} f_X(x) = f_X((y-1)/2) \\enspace ,$$\nand tabulated below:\\\\\n\\begin{center}\n\\begin{tabular}{r|rrr}\n$y$ & -1 & 1 & 3\\\\ \\hline\n &  &  & \\\\ \n$f_Y(y)$ & $\\frac{1}{4}$ & $\\frac{1}{2}$ & $\\frac{1}{4}$\n\\end{tabular}\n\\end{center}\n\\end{example}\n\nIn fact, obtaining the probability of a one-to-one transformation of a discrete random variable as in Examples~\\ref{EXMP:Discrete1to1TransYis2X} and \\ref{EXMP:Discrete1to1TransYis2Xplus1} is merely a matter of looking up the probability at the image of the inverse function.  This is because there is only one term in the sum that appears in Equation~\\eqref{E:PMFOfgOfX}.  When the transformation is not one-to-one the number of terms in the sum can be more than one as shown in the next Example.\n\n\\begin{example}\\label{Eg:DiscreteManyTo1TransYisXSquared}\nReconsider the random variable $X$ of the last two Examples and let $Y=X^2$.  \nRecall that $g(x)=x^2$ does not have an inverse function unless the domain is restricted to the positive or the negative parts of the real line.  \nSince our random variable $X$ takes values on both sides of the real line, namely $\\{-1,0,1\\}$, let us note that the transformation $g(X)=X^2$ is no longer a one-to-one function.  \nThen, by Equation~\\eqref{E:PMFOfgOfX} the probability mass function of $Y$ is expressed in terms of the known probabilities of $X$ as:\\\\ \n\\[\nf_Y(y)=\\P(Y=y)= \\sum_{x \\in g^{[-1]}(y)} f_X(x)  = \\sum_{\\{x:g(x)=y\\}} f_X(x) = \\sum_{\\{x:x^2=y\\}} f_X(x) \\enspace ,\n\\]\ncomputed for each $y \\in \\{0,1\\}$ as follows:\n\\begin{eqnarray*}\nf_Y(0) &=& \\sum_{\\{x:x^2=0\\}} f_X(x) = f_X(0)=\\frac{1}{2} \\enspace ,\\\\\nf_Y(1) &=& \\sum_{\\{x:x^2=1\\}} f_X(x) = f_X(-1)+f_X(1)=\\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2} \\enspace ,\n\\end{eqnarray*}\nand finally tabulated below:\\\\\n\\begin{center}\n\\begin{tabular}{r|ccc}\n$y$ & 0 & & 1\\\\ \\hline\n &  &  & \\\\ \n$f_Y(y)$ & $\\frac{1}{2}$ & \\quad & $\\frac{1}{2}$\n\\end{tabular}\\enspace .\n\\end{center}\n\\end{example}\n\n\\subsection{Transformations of continuous random variables}\\label{S:TransformationsOFContinuousRvs}\nSuppose we know $F_X$ and/or $f_X$ of a continuous random variable $X$.  \nLet $Y=g(X)$ be a transformation of $X$.  \nOur objective is to obtain $F_Y$ and/or $f_Y$ of $Y$ from $F_X$ and/or $f_X$.  \n%We will look at two techniques in Sections~\\ref{S:DirectMethod} and \\ref{S:f_YDirectlyFromf_X} to achieve our objective.\n\n\\subsubsection{One-to-one transformations}\\label{S:f_YDirectlyFromf_X}\nThe easiest case for transformations of continuous random variables is when $g$ is {\\bf one-to-one and monotone}.  \n\\begin{itemize}\n\\item{\nFirst, let us consider the case when $g$ is {\\bf monotone and increasing} on the range of the random variable $X$.  \nIn this case $g^{-1}$ is also an increasing function and we can obtain the distribution function of $Y=g(X)$ in terms of the distribution function of $X$ as   \n\\[\nF_Y(y) =P \\left(Y \\leq y \\right)=P \\left(g(X) \\leq y \\right) = P \\left(X \\leq g^{-1}(y) \\right) = F_X(g^{-1}(y)) \\enspace .\n\\]\nNow, let us use a form of chainrule to compute the density of $Y$ as follows:\n\\[\nf_Y(y) \n= \\frac{d}{dy} F_Y(y)\n= \\frac{d}{dy} F_X \\left(g^{-1}(y) \\right)\n= f_X \\left( g^{-1}(y) \\right) \\frac{d}{dy} \\left(g^{-1}(y) \\right) \\enspace . \n\\]\n}\n\\item{\nSecond, let us consider the case when $g$ is {\\bf monotone and decreasing} on the range of the random variable $X$.  \nIn this case $g^{-1}$ is also a decreasing function and we can obtain the distribution function of $Y=g(X)$ in terms of the distribution function of $X$ as   \n\\[\nF_Y(y) =P \\left(Y \\leq y \\right)=P \\left(g(X) \\leq y \\right) = P \\left(X \\geq g^{-1}(y) \\right) = 1- F_X(g^{-1}(y)) \\enspace ,\n\\]\nand the density of $Y$ as \n\\[\nf_Y(y) \n= \\frac{d}{dy} F_Y(y)\n= \\frac{d}{dy} \\left(1-F_X \\left(g^{-1}(y) \\right) \\right)\n= -f_X \\left( g^{-1}(y) \\right) \\frac{d}{dy} \\left(g^{-1}(y) \\right) \\enspace . \n\\]\nFor a monotonic and decreasing $g$, its inverse function $g^{-1}$ is also decreasing and consequently the density $f_Y$ is indeed positive because $\\frac{d}{dy} \\left(g^{-1}(y) \\right)$ is negative.  \n}\n\\end{itemize}\nWe can combine the above two cases and obtain the following \n{\\bf change of variable formula} for the probability density of $Y=g(X)$ when $g$ is one-to-one and monotone on the range of $X$.\n\\begin{equation}\\label{E:f_YFromf_X_Under_one-to-one-g}\n\\boxed{\nf_Y(y) = f_X \\left( g^{-1}(y) \\right) \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \\enspace .}\n\\end{equation}\n\nThe steps involved in finding the density of $Y=g(X)$ for a one-to-one and monotone $g$ are:\n\\begin{enumerate}\n\\item Write $y=g(x)$ for $x$ in range of $x$ and check that $g(x)$ is monotone over the required range to apply the change of variable formula. \n\\item Write $x=g^{-1}(y)$ for $y$ in range of $y$.\n\\item Obtain $\\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert$ for $y$ in range of $y$.\n\\item Finally, from Equation~\\eqref{E:f_YFromf_X_Under_one-to-one-g} get $f_Y(y) = f_X \\left( g^{-1}(y) \\right) \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert$ for $y$ in range of $y$. \n\\end{enumerate}\n\nLet us use these four steps to obtain the density of monotone transformations of continuous random variables.\n\n\\begin{example}\\label{Ex:1-UisU}\nLet $X$ be $\\uniform(0,1)$ random variable and let $Y=g(X)=1-X$.  \nWe are interested in the density of the tranformed random variable $Y$. Let us follow the four steps and use the change of variable formula to obtain $f_Y$ from $f_X$ and $g$.\n\\begin{enumerate}\n\\item $y=g(x)=1-x$ is a monotone decreasing function over $0 \\leq x \\leq 1$, the range of $X$.  \nSo, we can apply the change of variable formula. \n\\item $x=g^{-1}(y)=1-y$ is a monotone decreasing function over $1-0 \\geq 1-x \\geq 1-1$, i.e., $0 \\leq y \\leq 1$.  \n\\item For $0 \\leq y \\leq 1$,\n\\[\n \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= \\left\\vert \\frac{d}{dy} \\left( 1-y \\right) \\right\\vert \n= \\left\\vert -1 \\right\\vert = 1 \\enspace .\n\\]\n\\item we can use Equation~\\eqref{E:f_YFromf_X_Under_one-to-one-g} to find the density of $Y$ as follows:\n\\[\nf_Y(y) = f_X \\left( g^{-1}(y) \\right) \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= f_X \\left( 1-y \\right)  \\, 1\n= 1 \\enspace ,\n\\]\nfor $0 \\leq y \\leq 1$\n\\end{enumerate}\nThus, we have shown that if $X$ is a $\\uniform(0,1)$ random variable then $Y=1-X$ is also a $\\uniform(0,1)$ random variable.\n\\end{example}\n\n\\begin{example}\\label{Eg:Expontial1IsMinusLogOfUniform01}\nLet $X$ be a $\\uniform(0,1)$ random variable and let $Y=g(X)=-\\log(X)$.  \nWe are interested in the density of the tranformed random variable $Y$.  \nOnce again, since $g$ is a one-to-one monotone function let us follow the four steps and use the change of variable formula to obtain $f_Y$ from $f_X$ and $g$.\n\\begin{enumerate}\n\\item $y=g(x)=-\\log(x)$ is a monotone decreasing function over $0 < x < 1$, the range of $X$.  \nSo, we can apply the change of variable formula. \n\\item $x=g^{-1}(y)=\\exp(-y)$ is a monotone decreasing function over %$-\\log(0) > -\\log(x) > -\\log(1)$, i.e., %Ben does not like -\\log(0)=-\\infty because -\\log(0) is said to be undefined to these students -- raaz expected -\\log(0) = \\lim_{x \\to 0^+} \\log(x) = -\\infty is reasonable to assume here.\n$0 < y < \\infty$.  \n\\item For $0 < y < \\infty$,\n\\[\n \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= \\left\\vert \\frac{d}{dy} \\left( \\exp(-y) \\right) \\right\\vert \n= \\left\\vert -\\exp(-y) \\right\\vert = \\exp(-y) \\enspace .\n\\]\n\\item We can use Equation~\\eqref{E:f_YFromf_X_Under_one-to-one-g} to find the density of $Y$ as follows:\n\\[\nf_Y(y) = f_X \\left( g^{-1}(y) \\right) \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= f_X \\left( \\exp(-y) \\right)  \\, \\exp(-y)\n= 1 \\, \\exp(-y) = \\exp(-y) \\enspace .\n\\]\nNote that $0 < \\exp(-y) < 1$ for $0 < y < \\infty$.\n\\end{enumerate}\nThus, we have shown that if $X$ is a $\\uniform(0,1)$ random variable then $Y=-\\log(X)$ is an random variable with PDF $f_Y(y)=\\BB{1}_{(0,\\infty)}(y)\\exp(-y)$. \nWe can similarly show that for a parameter $\\lambda>0$, if $X \\sim \\uniform(0,1)$ then $Y=-\\lambda^{-1} \\log(X)$ yields a probability model of RVs that are parameterized by $\\lambda$ and extremely useful in applications. This is noting but our $\\exponential(\\lambda)$ RV.\n\\end{example}\n\nThe next example yields the {\\emph location-scale family} of normal random variables via a family of linear transformations of the standard normal random variable.\n\\begin{example}\\label{Eg:LinearTransfStdGaussianGaussian}\nLet $Z$ be the standard Gaussian or standard normal random variable with probability density function $\\phi(z)$ given by Equation~\\eqref{E:StandardNormalPdf}.  \nFor real numbers $\\sigma > 0$ and $\\mu$ consider the linear transformation of $Z$ given by \n$$Y = g(Z) = \\sigma Z +\\mu \\enspace .$$\nSome graphs of such linear transformations of $Z$ are shown in Figures~(a) and (b).\n\\begin{figure}[htbp]\n\\centering\\subfigure[{\\scriptsize $g(z)=z$, $g(z)=\\frac{1}{2}z+5$ and $g(z)=\\frac{1}{2}z-5$.}]{\n\\includegraphics[width=8cm]{figures/LinearTransOfStdGaussianA.eps}}\n\\subfigure[{\\scriptsize $g(z)=z$, $g(z)=(z+5)/0.5$ and $g(z)=(z-5)/0.5$.}]{\n\\includegraphics[width=8cm]{figures/LinearTransOfStdGaussianB.eps}}\n\\end{figure}\n\nWe are interested in the density of the tranformed random variable $Y=g(Z)=\\sigma Z + \\mu$.  \nOnce again, since $g$ is a one-to-one monotone function let us follow the four steps and use the change of variable formula to obtain $f_Y$ from $f_Z=\\phi$ and $g$.\n\\begin{enumerate}\n\\item $y=g(z)=\\sigma z + \\mu$ is a monotone increasing function over $-\\infty < z < \\infty$, the range of $Z$.  \nSo, we can apply the change of variable formula. \n\\item $z=g^{-1}(y)=(y - \\mu) / \\sigma$ is a monotone increasing function over the range of $y$ given by, %$(\\sigma \\times -\\infty) + \\mu < \\sigma z + \\mu < (\\sigma \\times \\infty) + \\mu$, i.e.,% Ben did not like these manipulaitons with infinities - raaz was doing arithmetic with diverging sequences with limits at infinity only. \n$-\\infty < y < \\infty$.  \n\\item For $-\\infty < y < \\infty$,\n\\[\n \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= \\left\\vert \\frac{d}{dy} \\left( \\frac{y - \\mu}{\\sigma} \\right) \\right\\vert \n= \\left\\vert \\frac{1}{\\sigma} \\right\\vert = \\frac{1}{\\sigma} \\enspace .\n\\]\n\\item we can use Equation~\\eqref{E:f_YFromf_X_Under_one-to-one-g} and Equation~\\eqref{E:StandardNormalPdf} which gives\n$$f_Z(z) = \\phi(z) = \\frac{1}{\\sqrt{2\\pi}} \\exp{\\left( -\\frac{z^2}{2}\\right)} \\enspace,$$\nto find the density of $Y$ as follows:\n\\[\nf_Y(y) = f_Z \\left( g^{-1}(y) \\right) \\left\\vert \\frac{d}{dy} g^{-1}(y) \\right\\vert \n= \\phi \\left( \\frac{y - \\mu}{\\sigma} \\right) \\frac{1}{\\sigma}\n= \\frac{1}{\\sigma \\sqrt{2 \\pi}} \\exp \\left[-\\frac{1}{2} \\left( \\frac{y-\\mu}{\\sigma} \\right)^2 \\right] \\enspace ,\n\\]\nfor $-\\infty < y < \\infty$. \n\\end{enumerate}\nThus, we have obtained the expression for the probability density function of the linear transformation $\\sigma Z + \\mu$ of the standard normal random variable $Z$.  This analysis leads to the following definition.\n\\end{example}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%Location-scale Gaussian family as a linear transformation of the standard Gaussian RV\n\n\\begin{framed}\n\n\\begin{model}[$\\normal(\\mu,\\sigma^2)$ RV]\nGiven a location parameter $\\mu \\in (-\\infty, +\\infty)$ and a scale parameter $\\sigma^2 > 0$, the $\\normal(\\mu,\\sigma^2)$ or Gaussian$(\\mu,\\sigma^2)$ random variable $X$ has probability density function:\n\\begin{equation}\\label{eqn:norm_pdf}\nf(x; \\mu,\n  \\sigma^2)=\\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right]\\qquad(\\sigma >0) \\enspace .\n\\end{equation}\n\\end{model}\n\\end{framed}\n\nThis is simpler than it may at first look. $f(x;\\mu, \\sigma^2)$ has the following features.\n\\bit\n\\item $\\mu$ is the expected value or mean parameter and $\\sigma^2$ is the variance parameter. These concepts, mean and variance, are described in more detail in the next section on expectations.\n\\item $1/(\\sigma\\sqrt{2\\pi})$ is a constant factor that makes the area under the curve of $f(x)$ from $-\\infty$ to $\\infty$ equal to 1, as it must be.\n\\item The curve of $f(x)$ is symmetric with respect to $x=\\mu$ because the exponent is quadratic. Hence for $\\mu=0$ it is symmetric with respect to the $y$-axis $x=0$.\n\\item The exponential function decays to zero very fast --- the faster the decay, the smaller the value of $\\sigma$.\n\\eit\n\n%\\newpage\n\n\\begin{framed}\nThe normal distribution has the {\\bf distribution function}\n\\begin{equation}\\label{eqn:norm_int_cdf}F(x; \\mu, \\sigma^2)=\\frac{1}{\\sigma\\sqrt{2\\pi}}\\int_{-\\infty}^x\\exp\\left[-\\frac{1}{2}\\left(\\frac{v-\\mu}{\\sigma}\\right)^2\\right]\\;dv\\enspace.\\end{equation}\nHere we need $x$ as the upper limit of integration and so we write $v$ in the integrand.\n\\end{framed}\n\n\n\\begin{figure}[ht]\n\\cen{\n\\includegraphics[scale=.3]{figures/normalpdf.eps}\n\\includegraphics[scale=.3]{figures/normaldis.eps}\n\\caption{PDF and DF of a $\\normal(\\mu,\\sigma^2)$ RV for different values of $\\mu$ and $\\sigma^2$\\label{F:plotPdfCdfNormals}}\n}\n\\end{figure}\n\nUsing the direct method's \\hyperref[Eqn:DirectMethod]{Equation~\\ref*{Eqn:DirectMethod}}, we can obtain the distribution function of the $\\normal(\\mu,\\sigma^2)$ random variable from that of the \ntabulated distribution function of the $\\normal(0,1)$ in the  \\hyperref[S:NormalDFTable]{Standard normal distribution function table in Sec.~\\ref*{S:NormalDFTable}}. \n  \n\\begin{prop}[One Table to Rule Them All Gaussians]\nThe distribution function $F_X(x;\\mu,\\sigma^2)$ of the $\\normal(\\mu,\\sigma^2)$ random variable $X$ \nand the distribution function $F_Z(z)=\\Phi(z)$  of the standard normal random variable $Z$ are related by:\n$$F_X(x;\\mu,\\sigma^2)\\;=\\; F_Z\\left(\\frac{x -\\mu}{\\sigma}\\right) \\;=\\; \\Phi\\left(\\frac{x-\\mu}{\\sigma}\\right)\\enspace .$$\n\n\\begin{proof}\nLet $Z$ be a $\\normal(0,1)$ random variable with distribution function $\\Phi(z) = P (Z \\leq z)$.  \nWe know that if $X=g(Z)=\\sigma Z+\\mu$ then $X$ is the $\\normal(\\mu,\\sigma^2)$ random variable.  \nTherefore, \n\\begin{eqnarray*}\nF_X(x;\\mu,\\sigma^2) \n&=& P(X \\leq x) = P\\left( g(Z) \\leq x \\right) =  P (\\sigma Z+\\mu \\leq x) = P\\left(Z \\leq \\frac{x -\\mu}{\\sigma} \\right)\\\\ \n&=& F_Z \\left(\\frac{x -\\mu}{\\sigma}\\right) = \\Phi \\left(\\frac{x -\\mu}{\\sigma}\\right) \\enspace .\n\\end{eqnarray*}\n\\end{proof}\n\\end{prop}\n\nHence we often transform a general $\\normal(\\mu,\\sigma^2)$ random\nvariable, $X$, to a standardised $\\normal(0,1)$ random variable, $Z$, by\nthe substitution:\n$$Z\\;=\\;\\frac{X-\\mu}{\\sigma}\\,.$$\n\n\\begin{example}\\label{EgGaussianProbLocScaleFromTableMremsInFlight}\nSuppose that the amount of cosmic radiation to which a person is exposed \nwhen flying by jet across the United States is a random\nvariable, $X$, having a normal distribution with a mean of $4.35$ mrem and a\nstandard deviation of $0.59$ mrem. What is the probability that a person\nwill be exposed to more than $5.20$ mrem of cosmic radiation on such a\nflight?\n\n{\\em Solution:}\n\\begin{align*}\nP(X> 5.20)\\;&=\\;1-P(X\\leq\n5.20)\\\\[3pt]&\\;=\\;1-F(5.20)\\\\[3pt]&\\;=\\;1-\\Phi\\left(\\frac{5.20-4.35}{0.59}\\right)\\\\[3pt]&\\;=\\;1-\\Phi(1.44)\\\\[3pt]&\\;=\\;1-\n0.9251\\\\[3pt]&\\;=\\;0.0749\n\\end{align*}\n\\end{example}\n\nAfter some more notions you will see that $\\normal(0,1)$ RV can actually be obtained from an IID process of $\\bernoulli(\\theta)$ RVs. This is an instance of the central limit theorem. To appreciate this we first need to understand what we mean by statistics and then familiarise ourselves with notions of convergence of random variables.\n\n\n\\subsubsection{Direct method}\\label{S:DirectMethod}\nIf the transformation $g$ in $Y=g(X)$ is not necessarily one-to-one then special care is needed to obtain the distribution function or density of $Y$.  \nFor a continuous random variable $X$ with a known distribution function $F_X$ we can obtain the distribution function $F_Y$ of $Y=g(X)$ using Equation~\\eqref{E:ProbOfgOfX} as follows:\n\\begin{eqnarray}\\label{Eqn:DirectMethod}\nF_Y(y)\n&=& P \\left(Y \\leq y \\right) = P \\left(Y \\in (-\\infty, y] \\right) \\notag \\\\\n&=& P \\left( g(X) \\in (-\\infty, y] \\right) = P \\left( X \\in g^{[-1]}((-\\infty, y]) \\right) = P \\left(X \\in \\{x: g(x) \\in (-\\infty,y]\\}  \\right) \\enspace . \n\\end{eqnarray}\nIn words, the above equalities just mean that the probability that $Y \\leq y$ is the probability that $X$ takes a value $x$ that satisfies $g(x) \\leq y$.  \nWe can use this approach if it is reasonably easy to find the set $g^{[-1]}((-\\infty,y]) = \\{x: g(x) = (-\\infty,y]\\}$.% as done in Section~\\ref{S:DirectMethod}.\n\n\\begin{example}\\label{Exm:DirectMethodforYisXSquared}\nLet $X$ be any random variable with distribution function $F_X$.  Let $Y=g(X)=X^2$.  \nThen we can find $F_Y$, the distribution function of $Y$ from $F_X$ as follows:\n\\begin{itemize}\n\\item {Since $Y=X^2 \\geq 0$, if $y < 0$ then $F_Y(y) = P\\left( X \\in \\{ x : x^2 < y\\} \\right) = \\P(X \\in \\emptyset) = 0$.}\n\\item {If $y \\geq 0$ then\n\\begin{eqnarray*}\nF_Y(y) = P \\left(Y \\leq y \\right) \n&=& P \\left( X^2 \\leq y \\right) \\\\\n&=& P \\left( -\\sqrt{y} \\leq X \\leq \\sqrt{y} \\right) \\\\\n&=& F_X(\\sqrt{y}) - F_X(-\\sqrt{y}) \\enspace .\n\\end{eqnarray*}\n}\n\\end{itemize}\nBy differentiation we get:\n\\begin{itemize}\n\\item {If $y<0$ then $f_Y(y)=\\frac{d}{dy}(F_Y(y)) = \\frac{d}{dy} 0 = 0$.}\n\\item {If $y \\geq 0$ then\n\\begin{eqnarray*}\nf_Y(y) \n= \\frac{d}{dy}\\left( F_Y(y) \\right) \n&=& \\frac{d}{dy}\\left( F_X(\\sqrt{y}) - F_X( - \\sqrt{y}) \\right)\\\\\n&=& \\frac{d}{dy}\\left( F_X(\\sqrt{y}) \\right) - \\frac{d}{dy}\\left( F_X( - \\sqrt{y}) \\right)\\\\\n&=& \\frac{1}{2}y^{-\\frac{1}{2}} f_X(\\sqrt{y}) - \\left( -\\frac{1}{2}y^{-\\frac{1}{2}} f_X( - \\sqrt{y}) \\right)\\\\\n&=& \\frac{1}{2 \\sqrt{y}} \\left( f_X(\\sqrt{y}) + f_X( - \\sqrt{y}) \\right) \\enspace .\n\\end{eqnarray*}\n}\n\\end{itemize}\nTherefore, the distribution function of $Y=X^2$ is:\n\\begin{equation}\\label{E:F_YofX^2}\nF_Y(y) = \n\\begin{cases}\n0 & \\text{ if } y < 0 \\\\\nF_X(\\sqrt{y}) - F_X(-\\sqrt{y}) & \\text{ if } y \\geq 0 \\enspace .\n\\end{cases}\n\\end{equation}\nand the probability density function of $Y=X^2$ is:\n\\begin{equation}\\label{E:f_YofX^2}\nf_Y(y) = \n\\begin{cases}\n0 & \\text{ if } y < 0 \\\\\n\\frac{1}{2 \\sqrt{y}} \\left( f_X(\\sqrt{y}) + f_X( - \\sqrt{y}) \\right) & \\text{ if } y \\geq 0 \\enspace .\n\\end{cases}\n\\end{equation}\n\\end{example} \n\n\\begin{example}\\label{Eg:SquaredStdNormalIsChiSquared}\n{If $X$ is the standard normal random variable with density \n$$f_X(x) = \\phi(x) = \\frac{1}{\\sqrt{2 \\pi}} \\exp{(-x^2/2)}$$ \nthen by Equation~\\eqref{E:f_YofX^2} the density of $Y=X^2$ is:\n\\[\nf_Y(y) = \n\\begin{cases}\n0 \n& \\text{ if } y < 0 \\\\\n\\frac{1}{2 \\sqrt{y}} \\left( f_X(\\sqrt{y}) + f_X( - \\sqrt{y}) \\right)\n=\n\\frac{1}{\\sqrt{2 \\pi y}} \\exp\\left(-\\frac{y}{2}\\right) \n& \\text{ if } y \\geq 0 \\enspace .\n\\end{cases}\n\\]\n$Y$ is called the {\\bf chi-square} random variable with one degree of freedom. This distribution plays a fundamental role in hypothesis testing as we will see in Inference Theory and was derived at the beginning of last century to settle ``supposedly evidence-based disputes'' among scientists using mathematics.\n}\n\\end{example}\n\\newpage\n\n\\input{ExsInTransformationsOfRVs.tex}\n\n\\section{Expectations}\\label{S:Expectations}\n\nExpectation is perhaps the most fundamental concept in probability theory. In fact, probability is itself an expectation as you will soon see!\n\nExpectation is one of the fundamental concepts in probability.  The\nexpected value of a real-valued random variable gives the population mean, a measure of the\ncentre of the distribution of the variable in some sense.  \nIts variance measures its spread and so on.\n\n\\begin{definition}[Expectation of a RV]\nThe {\\bf expectation}, or {\\bf expected value}, or {\\bf mean}, or {\\bf first moment}, of a random variable $X$, with distribution function $F$ and density $f$, is defined to be\n\\begin{equation}\\label{E:Mean}\n\\E(X) := \\int x\\,dF(x) = \n\\begin{cases}\n\\sum_x x f(x) & \\qquad \\text{if $X$ is discrete} \\\\\n\\int x f(x)\\,dx  & \\qquad \\text{if $X$ is continuous} \\  ,\n\\end{cases}\n\\end{equation}\nprovided the sum or integral is well-defined.  We say the expectation exists if\n\\begin{equation}\\label{E:ExpectationExists}\n\\int \\left|x\\right|\\,dF(x) < \\infty \\ .\n\\end{equation}\nSometimes, we denote $\\E(X)$ by $\\E X$ for brevity.  Thus, the expectation is a single-number summary of the RV $X$ and may be thought of  as the average.\nWe subscript $E$ to specify the parameter $\\theta \\in \\BB{\\Theta}$ with respect to which the integration is undertaken. \n\\[\n\\E_{\\theta} \\paren{X} := \\int x\\,dF(x;\\theta)\n\\]\n\\end{definition}\n\n\\begin{definition}[Variance of a RV]\\label{D:VarianceofX}\nLet $X$ be a RV with mean or expectation $\\E(X)$.  Variance of $X$ denoted by $\\V(X)$ or simply $\\V X$ is\n\\[\n\\V(X) := \\E \\left((X-\\E(X))^2\\right) = \\int (x-\\E(X))^2 \\,d F(x) \\ ,\n\\]\nprovided this expectation exists.  The {\\bf standard deviation} denoted by $\\sd(X) := \\sqrt{\\V(X)}$.\nThus variance is a measure of ``spread'' of a distribution.\n\\end{definition}\n\n\\begin{definition}[$k$-th moment of a RV]\nWe call \n\\[\n\\E \\paren{X^k} = \\int x^k\\,dF(x)\n\\]\nas the $k$-th moment of the RV $X$ and say that the $k$-th moment exists when $\\E\\paren{|X|^k} < \\infty$.  We call the following expectation as the $k$-th central moment:\n\\[\n\\E \\paren{(X- \\E(X))^k} \\ .\n\\]\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%% fromPrsStEng\n\n\\subsection{Expectations of functions of random variables}\\label{S:ExpectationsOfFunsOfRVs}\n\nMore generally, by taking the expected value of various functions of a random variable, we can measure many interesting features of its distribution, including spread and correlation.\n\n\\begin{definition}[Expectation of a function of a RV]\\label{Df:expectation}\nThe \\textbf{Expectation} of a function $g(X)$ of a random variable $X$ is defined as:\n\\[\n\\E(g(X))\\; :=\\; \\int g(x) dF(x) = \n\\begin{cases}\n\\displaystyle \\sum_x g(x) f(x) & \\text{if $X$ is a discrete RV}\\\\[12pt]\n\\displaystyle \\int_{-\\infty}^{\\infty} g(x) f(x) dx & \\text{if $X$ is a continuous RV}\n\\end{cases}\n\\]\nprovided $\\E(g(X))$ exists, i.e., $\\int |g(x)| dF(x) < \\infty$.\n\\end{definition}\n\nThe {\\bf mean} which characterises the central location of the random variable $X$ is merely the expectation of the identity function $g(x)=x$:\n\\[\n\\E(X)\\; =\\;\n\\begin{cases}\n\\displaystyle \\sum_x x f(x) & \\text{if $X$ is a discrete RV}\\\\[12pt]\n\\displaystyle\\int_{-\\infty}^{\\infty} x f(x) dx & \\text{if $X$ is a\n  continuous RV}\n\\end{cases}\n\\]\nOften, mean is denoted by $\\mu$.\n\nThe \\textbf{variance} which characterises the spread or the\n  variability of the random variable $X$ is also the expectation of the\n  function $g(x)=(x-\\E(X))^2$:\n\\[\n\\V(X)  = \\E \\paren{ (X-\\E(X))^2 }  = \n\\begin{cases}\n\\displaystyle\\sum_x (x-\\E(X))^2 f(x) & \\text{if $X$ is a discrete RV}\\\\[12pt]\n\\displaystyle\\int_{-\\infty}^{\\infty} (x-\\E(X))^2 f(x) dx & \\text{if $X$ is a continuous RV}\n\\end{cases}\n\\] \nOften, variance is denoted by $\\sigma^2$. \n\n%\\begin{framed}\nINTUITIVELY, WHAT IS EXPECTATION?\\\\\n\nDefinition \\ref{Df:expectation} gives expectation as a ``weighted average'' of the possible values. This is true but some intuitive idea of expectation is also helpful.\n\\begin{itemize}\n\\item Expectation is what you expect. \\\\[6pt]\nConsider tossing a fair coin. If it is heads you lose \\$10. If it is tails you win \\$10. \nWhat do you expect to win? Nothing. \nIf $X$ is the amount you win then $$\\E(X)\\;=\\;-10\\times \\frac{1}{2}+10\\times \\frac{1}{2}\\;=\\;0\\,.$$\n\nSo what you expect (nothing) and the weighted average ($\\E(X)=0$) agree.\n\n\n\\item Expectation is a long run average.\\\\[6pt]\nSuppose you are able to repeat an experiment independently, over and over again. \nEach experiment produces one value $x$ of a random variable $X$.  \nIf you take the average of the $x$ values for a large number of trials, then this average converges to $\\E(X)$ as the number of trials grows.  In fact, this is called the {\\bf law of large numbers}.\n\\end{itemize}\n%\\end{framed}\n\nWe can concretize the above two intuitive insights by the following two examples.\n\n\\begin{example}[Winnings on Average]\\label{EgWinningsOnAverage}\nLet $Y = r(X)$.  Then\n\\[\n\\E(Y) = \\E(r(X)) = \\int r(x)\\, d F(x) \\ .\n\\]\nThink of playing a game where we draw $x \\sim X$ and then I pay you $y=r(x)$.  Then your average income is $r(x)$ times the chance that $X=x$, summed (or integrated) over all values of $x$.\n\\end{example}\n\n\\begin{example}[Probability is an Expectation]\\label{EgProbIsAnExpectation}\nLet $A$ be an event and let $r(X)=\\BB{1}_{A}(x)$.  Recall $\\BB{1}_A(x)$ is $1$ if $x \\in A$ and $\\BB{1}_A(x)=0$ if $x \\notin A$.  Then\n\\begin{equation}\\label{E:ExpectationofIndicator}\n\\E\\paren{\\BB{1}_A(X)} = \\int \\BB{1}_A(x)\\, dF(x) = \\int_A dF(x) = \\P(X \\in A) = \\P(A)\n\\end{equation}\nThus, probability is a special case of expectation.  Recall our LTRF motivation for the definition of probability and make the connection.\n\\end{example}\n\n\\subsection*{Expectations of functions of $\\Rz^2$-valued random variables}\\label{S:ExpectationsOfFunsOf2RVs}\n\nIn the case of a single random variable we saw that its expectation gives the population mean, \na measure of the center of the distribution of the variable in some sense.  \nSimilarly, by taking the expected value of various functions of a $\\Rz^2$-valued random variable, we can measure many interesting features of its joint distribution.\n\n\\begin{definition}\\label{Df:2expectation}\nThe \\textbf{Expectation} of a function $g(X,Y)$ of the $\\Rz^2$-valued RV $(X,Y)$ is defined as:\n\\[\n\\E(g(X,Y))\\; =\\;\n\\begin{cases}\n\\displaystyle \\sum_{(x,y)} g(x,y) f_{X,Y}(x,y) & \\text{if $(X,Y)$ is a discrete \\rv}\\\\[12pt]\n\\displaystyle \\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} g(x,y) f_{X,Y}(x,y) dx dy & \\text{if $(X,Y)$ is a continuous \\rv}\n\\end{cases}\n\\]\n\\end{definition}\n\nSome typical expectations for $\\Rz^2$-valued random variables are:\n\n\\be\n\\item Joint Moments\n\\[\n\\E \\paren{X^r Y^s}\n\\]\nWhen $r=s=1$, we have $\\E(XY)$, the expectation of the product of two RVs.\n\\item \nWe need a new notion for the variance of two RVs.\n\nIf $\\E(X^2) < \\infty$ and $\\E(Y^2) < \\infty$ then $\\E(|X Y|) < \\infty$ and $\\E(|(X-\\E(X))(Y-\\E(Y))|) < \\infty$.  This allows the definition of {\\bf covariance} of $X$ and $Y$ as\n\\[\n\\cv(X,Y) := \\E \\left((X-\\E(X))(Y-\\E(Y))\\right) = \\E(X Y) - \\E(X) \\E(Y)\n\\]\n\\ee\n\nThe same ideas naturally extend, via multiple sums and integrals, to define the expectation of functions of $\\Rz^k$-valued random variables with $k>2$.\n\n\n\\subsection*{Viewing a deterministic real variable as a random variable}\n\nConsider the class of discrete RVs with distributions that place all probability mass on a single real number.  \nThis is the probability model for the deterministic real variable, which is often thought of as an unknown constant $\\theta \\in \\Rz$.\n\\begin{model}[$\\pointmass(\\theta)$]\nGiven a specific point $\\theta \\in \\Rz$, we say an RV $X$ has point mass at $\\theta$ or is $\\pointmass(\\theta)$ distributed if the DF is:\n\\begin{equation}\\label{E:PointMasscdf}\nF(x;\\theta) =\n\\begin{cases}\n0 & \\text{if $x < \\theta$} \\\\\n1 & \\text{if $x \\geq \\theta$}\n\\end{cases}\n\\end{equation}\nand the PMF is:\n\\begin{equation}\nf(x;\\theta) =\n\\begin{cases}\n0 & \\text{if  $x \\neq \\theta$} \\\\\n1 & \\text{if $x = \\theta$}\n\\end{cases}\n\\end{equation}\n\\end{model}\nThus, $\\pointmass(\\theta)$ RV $X$ is deterministic in the sense that every realisation of $X$ is exactly equal to $\\theta \\in \\Rz$.  We will see that this distribution plays a central limiting role in asymptotic statistics.\n\n\\begin{example}[Mean and variance of $\\pointmass(\\theta)$ RV]\nLet $X \\sim \\pointmass(\\theta)$.  Then:\n\\[\n\\E(X) = \\sum_{x} x f(x) = \\theta \\times 1 = \\theta \\ , \\qquad\n\\V(X) = \\E(X^2) - (\\E(X))^2 = \\theta^2 - \\theta^2 = 0 \\ .\n\\]\n\\end{example}\n\n\\subsection{Properties of expectations}\\label{S:PropOfEs}\nThe following results, where $a$ is a  constant, may easily be\nproved using the properties of summations and integrals:\n\n\\bit\n\\item[] $\\boxed{\\E(a ) \\,=\\, a}$\n\n\\item[] $\\boxed{\\E(a \\,g(X)) \\,=\\, a\\, \\E(g(X))}$\n\n\\item[] $\\boxed{\\E(g(X)+h(X))  \\,=\\, \\E(g(X)) \\,+\\, \\E(h(X))}$\n\\eit\nNote that here  $g(X)$ and $h(X)$ are functions of the random variable\n$X$: e.g.  $g(X)=X^2$.\n\nUsing these results we can obtain the following useful formula for variance:\n\\begin{eqnarray*}\n\\V(X)\n&=& \\E\\left((X-\\E(X))^2\\right)\\\\[3pt]\n& =& \\E \\left( X^2 - 2 X \\E(X) + (\\E(X))^2 \\right) \\\\[3pt]\n&=& \\E ( X^2) - \\E \\left( 2 X \\E(X) \\right) + \\E \\left( (\\E(X))^2\n\\right)\\\\[3pt]\n& =& \\E ( X^2) - 2 \\E(X) \\E \\left( X \\right) + (\\E(X))^2 \\\\[3pt]\n&=& \\E ( X^2) - 2 (\\E(X))^2 + (\\E(X))^2\\\\[3pt]\n&=& \\E(X^2) - (\\E(X))^2 \\enspace .\n\\end{eqnarray*}\nThat is, \\[\n\\boxed{\n\\V(X) \\;=\\; \\E(X^2) \\,- \\,(\\E(X))^2\n}.\n\\]\n\nThe above properties of expectations imply that for constants $a$ and $b$,\n%V(aX+b) = a^2 V(X) \\enspace .\n\\begin{equation}\\label{E:VofAffineofRVs}\n\\boxed{\n\\V(aX+b) = a^2\\V(X) \\ . \n}\n\\end{equation}\n\nMore generally, for random variables $X_1,X_2,\\ldots,X_n$ and constants $a_1,a_2,\\ldots,a_n$\n\\begin{itemize}\n\\item\n\\begin{equation}\\label{E:EofLinCombofRVs}\n\\E \\left( \\sum_{i=1}^n a_i X_i \\right) \n= \\sum_{i=1}^n a_i \\E(X_i) \\ .\n\\end{equation}\n%E \\left( \\sum_{i=1}^n a_i X_i \\right) = \\sum_{i=1}^n a_i \\E(X_i)}$\n%\\smallskip\n\\item\n%$\\boxed{V \\left(  \\sum_{i=1}^n a_i X_i \\right) = \\sum_{i=1}^n a_i^2 V(X_i)}$, provided $X_1,X_2,\\ldots,X_n$ are independent\n\\begin{equation}\\label{E:VofLinCombofRVs}\n\\V \\left(  \\sum_{i=1}^n a_i X_i \\right) = \\sum_{i=1}^n a_i^2 \\V(X_i) , \\text{ provided $X_1,X_2,\\ldots,X_n$ are independent}\\ .\n\\end{equation}\n\\item Let $X_1,X_2,\\ldots,X_n$ be independent RVs, then\n\\begin{equation}\\label{E:EofProdIndRVs}\n\\E \\left(  \\prod_{i=1}^n X_i \\right) = \\prod_{i=1}^{n} \\E(X_i) , \\text{ provided $X_1,X_2,\\ldots,X_n$ are independent}\\ .\n\\end{equation}\n\\end{itemize}\n\n%\\item If the $k$-th moment exists and if $j<k$ then the $j$-th moment exists.\n\n%\\item $\\V(X) = \\E(X^2) - (\\E(X))^2$ \\ . [prove by completing the square and applying \\eqref{E:EofLinCombofRVs}]\n%\\item If $a$ and $b$ are constants then:\n%\\item If $X_1,X_2,\\ldots,X_n$ are independent and $a_1,a_2,\\ldots,a_n$ are constants, then:\n%\\end{enumerate}\n\n\\subsection{Expectation of Common Random Variables}\n\nLet us compute the mean and variance of our familiar RVs.\n\n\\begin{example}[Mean and variance of $\\bernoulli(\\theta)$ RV]\\label{EgMeanAndVarOfBernoulli}\nLet $X \\sim \\bernoulli(\\theta)$.  Then, \n\\[\n\\E(X) = \\sum_{x=0}^1 x f(x) = (0 \\times (1-\\theta)) + (1 \\times \\theta) = 0+\\theta=\\theta \\ ,\n\\]\n\\[\n\\E(X^2) =  \\sum_{x=0}^1 x^2 f(x) =  (0^2 \\times (1-\\theta) ) + (1^2 \\times \\theta) = 0+\\theta= \\theta \\ ,\n\\]\n\\[\n\\V(X) = \\E(X^2) - (\\E(X))^2 = \\theta - \\theta^2 = \\theta(1-\\theta) \\ .\n\\]\nParameter specifically,\n\\[\n\\E_{\\theta}(X)=\\theta \\qquad \\text{and} \\qquad \\V_{\\theta}(X)=\\theta(1-\\theta) \\ .\n\\]\n\\begin{figure}[htpb]\n\\caption{Mean ($\\E_{\\theta}(X)$), variance ($\\V_{\\theta}(X)$) and the rate of change of variance ($\\frac{d}{d \\theta} \\V_{\\theta}(X)$) of a $\\bernoulli(\\theta)$ RV $X$ as a function of the parameter $\\theta$.\\label{F:MeanVarBernoulli}}\n\\centering   \\makebox{\\includegraphics[width=5.0in]{figures/PlotMeanVarBernoulli}}\n\\end{figure}\n\nMaximum of the variance $\\V_{\\theta}(X)$ is found by setting the derivative to zero, solving for $\\theta$ and showing the second derivative is locally negative, i.e.~$\\V_{\\theta}(X)$ is concave down:\n\\[\n\\V_{\\theta}'(X) := \\frac{d}{d \\theta} \\V_{\\theta}(X) = 1-2 \\theta = 0  \\iff \\theta = \\frac{1}{2} \\ , \n\\qquad \\V_{\\theta}''(X) := \\frac{d}{d \\theta} \\left( \\frac{d}{d \\theta} \\V_{\\theta}(X) \\right) = -2 < 0 \\ ,\n\\]\n\\[\n\\max_{\\theta \\in [0,1]} \\V_{\\theta}(X) = \\frac{1}{2} \\left(1-\\frac{1}{2} \\right) = \\frac{1}{4} \\ , \n\\text{since $\\V_{\\theta}(X)$ is maximized at $\\theta = \\frac{1}{2}$}\n\\]\nThe plot depicting these expectations as well as the rate of change of the variance are depicted in \\hyperref[F:MeanVarBernoulli]{Figure \\ref*{F:MeanVarBernoulli}}.  Note from this Figure that $\\V_{\\theta}(X)$ attains its maximum  value of $1/4$ at $\\theta=0.5$ where $\\frac{d}{d\\theta}\\V_{\\theta}(X)=0$.  Furthermore, we know that we don't have a minimum at $\\theta=0.5$ since the second derivative $\\V_{\\theta}''(X) = -2$ is negative for any $\\theta \\in [0,1]$.  This confirms that $\\V_{\\theta}(X)$ is concave down and therefore we have a maximum of $\\V_{\\theta}(X)$ at $\\theta=0.5$.  We will revisit this example when we employ a numerical approach called Newton-Raphson method to solve for the maximum of a differentiable function by setting its derivative equal to zero.\n\\end{example}\n\n\\begin{example}[Mean and variance of $\\uniform(0,1)$ RV]\\label{EgMeanAndVarOfUnif01}\nLet $X \\sim \\uniform(0,1)$.  Then, \n\\[\n\\E(X) = \\int_{x=0}^1 x f(x)\\, dx = \\int_{x=0}^1 x \\ 1 \\, dx = \\frac{1}{2} \\left( x^2 \\right]_{x=0}^{x=1} = \\frac{1}{2} \\left( 1-0 \\right) = \\frac{1}{2} \\ ,\n\\]\n\\[\n\\E(X^2) = \\int_{x=0}^1 x^2 f(x)\\, dx = \\int_{x=0}^1 x^2 \\ 1 \\, dx =  \\frac{1}{3} \\left( x^3 \\right]_{x=0}^{x=1} = \\frac{1}{3} \\left( 1-0 \\right) = \\frac{1}{3} \\ ,\n\\]\n\\[\n\\V(X) = \\E(X^2) - (\\E(X))^2 = \\frac{1}{3}  - \\left( \\frac{1}{2} \\right)^2  = \\frac{1}{3}  - \\frac{1}{4} = \\frac{1}{12} \\ .\n\\]\n\\end{example}\n\n\\begin{Exercise}[title={Mean and variance of $\\uniform(\\theta_1,\\theta_2)$ RV},label={xMeanAndVarOfUniformab}]\nLet $X \\sim \\uniform(\\theta_1,\\theta_2)$ of Model~\\ref{M:Uniformab}. Derive expressions for $\\E(X)$ and $\\V(X)$ in terms of the parameters $\\theta_1$ and $\\theta_2$. Make sure that when $\\theta_2=1$ and $\\theta_1=0$ you recover the expectation and variance of the $\\uniform(0,1)$ RV in Example~\\ref{EgMeanAndVarOfUnif01}.\n\\end{Exercise}\n\\begin{Answer}\nDerive the answers from the definition of $\\E(X)$ and $\\V(X) = \\E(X^2) - (\\E(X))^2$ when $X \\sim \\uniform(\\theta_1,\\theta_2)$ with PDF given in Model~\\ref{M:Uniformab}.\n\\[\\E(X) = \\frac{\\theta_1+\\theta_2}{2} \\quad \\V(\\X) = \\frac{(\\theta_2-\\theta_1)^2}{12}\\]\n\\end{Answer}\n\n\\begin{example}[Expected Exponential of the $\\uniform(0,1)$ RV]\\label{EgExpectedExponentialOfUniform01}\nLet $X \\sim \\uniform(0,1)$ and $Y=r(X)=e^X$.  Compute $\\E(Y)$. \n\nWe can simply apply the definition of $\\E(r(X))$, since $Y=r(X)$, is just a function of $X$, as follows: \n\\[\n\\E(Y) = \\int_0^1 e^x f(x) dx = \\int_0^1 e^x 1 \\ dx = e-1 \\ .\n\\]\n%You could have also found out that the density $f(y)=1/y$ for the RV $Y$, provided $1<y<e$, and $0$ otherwise.  Again,\n%\\[\n%\\E(Y) = \\int_1^e y f(y) dy = \\int_1^e y \\frac{1}{y} dy = \\int_1^e 1 \\ dy = e-1 \\ .\n%\\]\n\\end{example}\n\n\\begin{example}[Mean and variance of $\\exponential(\\lambda)$]\\label{EgmeanAndVarOfExponential}\nShow that the mean of an $\\exponential(\\lambda)$ RV $X$ is:\n\\[\n\\E_{\\lambda}(X) = \\int_{0}^{\\infty} x f(x;\\lambda)\\,dx\n=   \\int_{0}^{\\infty} x \\lambda e^{-\\lambda x}\\,dx\n= \\frac{1}{\\lambda} \\ ,\n\\]\nand the variance is:\n\\[\n\\V_{\\lambda}(X) = \\left(  \\frac{1}{\\lambda} \\right)^2 \\ .\n\\]\n\\end{example}\n\n\\begin{example}[Mean and variance of $\\geometric(\\theta)$ RV]\\label{EgmeanAndVarOfGeometric}\nLet $X \\sim \\geometric(\\theta)$ RV.  Then,\n\\[\n\\E(X) = \\sum_{x=0}^{\\infty} x \\theta(1-\\theta)^x =  \\theta \\sum_{x=0}^{\\infty} x (1-\\theta)^x\n\\]\nIn order to simplify the RHS above, let us employ differentiation with respect to $\\theta$:\n\\[\n\\frac{-1}{\\theta^2}= \\frac{d}{d\\theta} \\left( \\frac{1}{\\theta} \\right)= \\frac{d}{d\\theta} \\sum_{x=0}^{\\infty} (1-\\theta)^x  =  \\sum_{x=0}^{\\infty} -x (1-\\theta)^{x-1}\n\\]\nMultiplying the LHS and RHS above by $-(1-\\theta)$ and substituting in $\\E(X)=  \\theta \\sum_{x=0}^{\\infty} x (1-\\theta)^x$, we get a much simpler expression for $\\E(X)$ :\n\\[\n\\frac{1-\\theta}{\\theta^2}= \\sum_{x=0}^{\\infty} x (1-\\theta)^{x} \\implies \\E(X) = \\theta \\left( \\frac{1-\\theta}{\\theta^2} \\right) = \\frac{1-\\theta}{\\theta} \\ .\n\\]\nSimilarly, it can be shown that\n\\[\n\\V(X) = \\frac{1-\\theta}{\\theta^2} \\ .\n\\]\n\n\\begin{figure}[htpb]\n\\caption{Mean and variance of a $\\geometric(\\theta)$ RV $X$ as a function of the parameter $\\theta$.\\label{F:MeanVarGeom}}\n\\centering   \\makebox{\\includegraphics[width=5.0in]{figures/PlotMeanVarGeom}}\n\\end{figure}\n\\end{example}\n\n% binomial model above\n\\begin{example}[Mean and variance of $\\binomial(n,\\theta)$ RV]\\label{EgMeanAndVarOfBinomial}\nLet $X \\sim \\binomial(n,\\theta)$.  Based on the definition of expectation:\n\\[\n\\E(X) = \\int x \\, dF(x; n,\\theta) = \\sum_x x f(x;n,\\theta) = \\sum_{x =0}^n x \\binom{n}{x} \\theta^x (1-\\theta)^{n-x} \\ .\n\\]\nHowever, this is a nontrivial sum to evaluate.  Instead, we may use \\eqref{E:EofLinCombofRVs} and \\eqref{E:VofLinCombofRVs} by noting that $X = \\sum_{i=1}^n X_i$, where the $\\{X_1,X_2,\\ldots,X_n \\} \\overset{\\IID}{\\sim} \\bernoulli(\\theta)$, $\\E(X_i) = \\theta$ and $\\V(X_i)=\\theta(1-\\theta)$:\n\\[\n\\E(X) = \\E(X_1+X_2, \\cdots ,X_n) = \\E \\left( \\sum_{i=1}^n X_i \\right) = \\sum_{i=1}^n \\E(X_i) = n \\theta \\ ,\n\\]\n\\[\n\\V(X) = \\V \\left( \\sum_{i=1}^n X_i \\right) = \\sum_{i=1}^n \\V(X_i) = \\sum_{i=1}^n{\\theta(1-\\theta)} = n\\theta(1-\\theta) \\ .\n\\]\n\\end{example}\n\n\\begin{example}[Mean and variance of $\\poisson(\\lambda)$ RV]\\label{EgMeanAndVarOfPoisson}\nLet $X \\sim \\poisson(\\lambda)$.  Then:\n\\[\n\\E(X) = \\sum_{x=0}^{\\infty} x f(x;\\lambda)\n= \\sum_{x =0}^{\\infty} x \\frac{ e^{-\\lambda} \\lambda^x}{x!}\n= e^{-\\lambda} \\sum_{x =0}^{\\infty} x \\frac{  \\lambda^x}{x!}\n= e^{-\\lambda} \\sum_{x -1 =0}^{\\infty} \\frac{ \\lambda \\lambda^{x-1}}{(x-1)!}\n= e^{-\\lambda} \\lambda e^{\\lambda}\n= \\lambda\n\\ .\n\\]\nSimilarly,\n\\[\n\\V(X) = \\E(X^2)-(\\E(X))^2 = \\lambda + \\lambda^2 - \\lambda^2 = \\lambda \\ .\n\\]\nsince\n\\begin{align*}\n\\E(X^2)& = \\sum_{x=0}^{\\infty} x^2 \\frac{e^{-\\lambda} \\lambda^x}{x!} = \\lambda \\, e^{-\\lambda} \\sum_{x=1}^{\\infty} \\frac{x \\, \\lambda^{x-1}}{(x-1)!}\n= \\lambda \\, e^{-\\lambda} \\left( 1 + \\frac{2 \\lambda}{1} + \\frac{3 \\lambda^2}{2!} + \\frac{4 \\lambda^3}{3!} + ... \\right)\\\\\n&= \\lambda \\, e^{-\\lambda} \\left( \\left( 1 + \\frac{\\lambda}{1} + \\frac{\\lambda^2}{2!} + \\frac{\\lambda^3}{3!} + ... \\right) + \\left[ \\frac{\\lambda}{1} + \\frac{2 \\lambda^2}{2!} + \\frac{3 \\lambda^3}{3!} + ... \\right] \\right)\\\\\n&= \\lambda \\, e^{-\\lambda} \\left( \\left( e^{\\lambda} \\right) + \\lambda \\left( 1 + \\frac{2 \\lambda}{2!} + \\frac{3 \\lambda^2}{3!} + ... \\right) \\right)\n= \\lambda \\, e^{-\\lambda} \\left( e^{\\lambda} + \\lambda \\left( 1 + \\lambda + \\frac{\\lambda^2}{2!} + ... \\right) \\right)\\\\\n&= \\lambda \\, e^{-\\lambda} \\left( e^{\\lambda} + \\lambda \\left( e^{\\lambda} \\right) \\right)\n= \\lambda \\, e^{-\\lambda} \\left( e^{\\lambda} + \\lambda\\, e^{\\lambda}\\right) = \\lambda (1 + \\lambda) = \\lambda + \\lambda^2\n\\end{align*}\n\nNote that $\\poisson(\\lambda)$ distribution is one whose mean and variance are the same, namely $\\lambda$.\n\\end{example}\n\n%\\remove{\n\\begin{figure}[htpb]\n\\caption{PDF of $X \\sim \\poisson(\\lambda=10)$ and the relative frequency histogram based on 1000 samples from $X$ according to Simulation~\\ref{SIM:Poisson}.\\label{F:PlotPdfSim1000HistPoiss10}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/PlotPdfSim1000HistPoiss10}}\n\\end{figure}\n%}%end remove\n\nThe $\\poisson(\\lambda)$ RV $X$ is also related to the IID $\\exponential(\\lambda)$ RV $Y_1,Y_2,\\ldots$: $X$ is the number of occurrences, per unit time, of an instantaneous event whose inter-occurrence time is the IID $\\exponential(\\lambda)$ RV.  For example, the number of buses arriving at our bus-stop in the next minute, with exponentially distributed inter-arrival times, has a Poisson distribution.\n\n\\begin{example}[Mean and variance of $\\normal(\\mu,\\sigma^2)$ RV]\\label{EgMeanAndVarOfNormalMuSigmaSquareRV}\nThe location-scale family of RVs is indeed parameterised by its mean and variance, i.e., if  $X \\sim \\normal(\\mu,\\sigma^2)$ where $X=g(Z)= \\sigma Z+\\mu$ and $Z \\sim \\normal(0,1)$ then $\\E(X) = \\mu$ and $\\V(X) = \\sigma^2$ follows directly from the properties of Expectations, provided $\\E(Z)=0$ and $\\V(Z)=\\E(Z^2)-\\left(\\E(Z)\\right)^2=\\E(Z^2)=1$.\n\nThe mean of a $\\normal(0,1)$ RV $Z$ is:\n\\[\n\\E(Z) = \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} z \\exp{\\left( - \\frac{1}{2} z^2 \\right)}\\,dz\n = \\frac{1}{\\sqrt{2 \\pi}} \\left(  -\\exp{\\left( - \\frac{1}{2} z^2 \\right)} \\right]_{-\\infty}^{\\infty} \n= 0 \\ ,\n\\]\nand the variance is:\n\\[\n\\V(Z) =\\E(Z^2)-\\left(\\E(Z)\\right)^2=\\E(Z^2)-0=\\E(Z^2) = \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} z^2 e^{-z^2/2} dz .\n\\]\nUsing integration by parts with $u = z, dv=ze^{-z^2/2} \\implies du=1, v=-e^{-z^2/2}, \\, \\int u dv = uv - \\int v du$\n\\[\n\\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} z^2 e^{-z^2/2} dz =  \\frac{1}{\\sqrt{2 \\pi}} \\left( -z e^{-z^2/2} \\right]_{-\\infty}^{\\infty} + \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{-z^2/2} dz = 0 + 1 = 1\n\\]\nThe first term after the first equality above equals $0$ because the exponential goes to $0$ much faster than $z$ grows to $\\pm \\infty$. \nThe second term equals $1$ because it is exactly the total probability integral of the PDF of the $\\normal(0,1)$ RV.\n\\end{example}\n\nNext, let us become familiar with an RV for which the expectation does not exist.  %This will help us appreciate the phrase ``none of which is dominant'' in the informal statement of the CLT later.\n\\begin{model}[$\\cauchy$]\\label{M:Cauchy}\nThe density of the $\\cauchy$ RV $Y$ is:\n\\begin{equation}\\label{E:StandardCauchypdf}\nf(y) = \\frac{1}{\\pi (1+y^2)}, \\qquad -\\infty < y < \\infty \\enspace ,\n\\end{equation}\nand its DF is:\n\\begin{equation}\\label{E:StandardCauchycdf}\nF(y) = \\frac{1}{\\pi} \\tan^{-1} (y) + \\frac{1}{2} \\ .\n\\end{equation}\nRandomly spinning a LASER emitting improvisation of ``Darth Maul's double edged lightsaber'' that is centered at $(1,0)$ in the plane $\\Rz^2$ and recording its intersection with the $y$-axis, in terms of the $y$ coordinates of the point $(0,y)$, gives rise to the $Standard~Cauchy$ RV.\n\nThe Cauchy RV $Y$ can be derived from a RV $X \\sim \\uniform(-\\pi/2,\\pi/2)$ by the simple transformation $Y = \\tan(X)$ for the above construction. \nSince $\\tan(x)$ is one-to-one and monotone on the range of $X$ given by $(-\\pi/2,\\pi/2)$, \nwe can use the change of variable formula in \\hyperref[E:f_YFromf_X_Under_one-to-one-g]{Equation \\ref*{E:f_YFromf_X_Under_one-to-one-g}} to obtain the PDF $f_Y(y)$ from the PDF $f_X(x)=\\frac{1}{\\pi}\\BB{1}_{(-\\pi/2,\\pi/2)}(x)$ as follows:\n\\[\nf_Y(y) = f_X(g^{-1}(y)) \\left| \\frac{d}{dy} g^{-1}(y) \\right| = f_X(\\tan^{-1}(y)) \\left| \\frac{d}{dy} \\tan^{-1}(y) \\right| = \\frac{1}{\\pi} \\left| \\frac{1}{1+y^2} \\right|\n\\]\nNote that the construction is valid even if we sample $X$ uniformly from $(0,\\pi)$ and take its $\\tan(X)$.\n\\end{model}\n\n\\begin{example}[Mean of $\\cauchy$ RV]\nThe expectation of the $\\cauchy$ RV $X$, obtained via integration by parts (set $u=x$ and $v=\\tan^{-1}(x)$) does not exist  %\\eqref{E:ExpectationExists}\n, since:\n\\begin{equation}\\label{E:CauchyMeanDoesNotExist}\n\\int \\left|x\\right|\\,dF(x) = \\frac{2}{\\pi} \\int_0^{\\infty} \\frac{x}{1+x^2}\\,dx = \\left(x \\tan^{-1}(x) \\right]_0^{\\infty} - \\int_0^{\\infty} \\tan^{-1}(x)\\, dx = \\infty \\ .\n\\end{equation}\nNote that we consider symmetry of integral about the origin and take twice the integral over $(0,\\infty)$ above. \nVariance and higher moments cannot be defined when the expectation itself is undefined.\n\\end{example}\n\nNext let us consider a natural generalization of the $\\bernoulli(\\theta)$ RV with more than two outcomes but in the set $\\{1,2,\\ldots,k\\}$.\n\\begin{model}[{$\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$}]\\label{M:demoivre}\nGiven a specific point $(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ in the unit $k-1$-Simplex:\n\\[\n\\bigtriangleup^{k-1} :=  \\{ \\,  ( \\theta_1,\\theta_2,\\ldots,\\theta_k) :  \\theta_1 \\geq 0, \\theta_2 \\geq 0, \\ldots, \\theta_k \\geq 0, \\sum_{i=1}^k \\theta_i = 1 \\, \\}  \\ ,\n\\]\nwe say that an RV $X$ is $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ distributed if its PMF is:\n\\[\nf(x;\\theta_1,\\theta_2,\\ldots,\\theta_k) =\n\\begin{cases}\n0 & \\quad \\text{if $x \\notin [k] := \\{1,2,\\ldots,k\\}$,} \\\\\n\\theta_x & \\quad \\text{if $x \\in [k]$}   .\n\\end{cases}\n\\]\nThe DF for $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV $X$ is:\n\\begin{equation}\\label{E:deMoivreDF}\nF(x;\\theta_1,\\theta_2,\\ldots,\\theta_k) =\n\\begin{cases}\n0 & \\quad  \\text{if $-\\infty < x < 1$}\\\\\n\\theta_1 & \\quad \\text{if $1 \\leq x < 2$} \\\\\n\\theta_1+\\theta_2 & \\quad \\text{if $2 \\leq x < 3$} \\\\\n\\vdots & \\\\\n\\theta_1+\\theta_2+\\cdots+\\theta_{k-1} & \\quad \\text{if $k-1 \\leq x < k$} \\\\\n\\theta_1+\\theta_2+\\cdots+\\theta_{k-1}+\\theta_k=1 & \\quad \\text{if $k \\leq x < \\infty$} \\\\\n\\end{cases}\n\\end{equation}\nThe $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV can be thought of as a probability model for ``the outcome  of rolling a polygonal cylindrical die with $k$ rectangular faces that are marked with $1, 2, \\ldots, k$''.  The parameters $\\theta_1,\\theta_2,\\ldots,\\theta_k$ specify how the die is loaded and may be idealised as specifying the cylinder's centre of mass with respect to the respective faces.  Thus, when $\\theta_1=\\theta_2=\\cdots=\\theta_k=1/k$, we have a probability model for the outcomes of a fair die.\n\\end{model}\n\n\\paragraph{Mean and variance of $\\demoivre (\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV:}\nThe not too useful expressions for the first two moments of $X \\sim \\demoivre (\\theta_1,\\theta_2,\\ldots,\\theta_k)$ are,\n\\[\n\\E(X) = \\sum_{x=1}^k x \\theta(x) =  \\theta_1 + 2 \\theta_2 + \\cdots + k \\theta_k \\ , \\text{ and }\n\\]\n\\[\n\\V(X) = \\E(X^2) - (\\E(X))^2 =   \\left(\\theta_1 + 2^2 \\theta_2 + \\cdots + k^2 \\theta_k \\right) - \\left( \\theta_1 + 2 \\theta_2 + \\cdots + k \\theta_k \\right)^2 \\ .\n\\]\nHowever, if $X\\sim \\demoivre(1/k,1/k,\\ldots,1/k)$, then the mean and variance for the fair $k$-faced die based on Faulhaber's formula for $\\sum_{i=1}^k i^m$, with $m\\in\\{1,2\\}$, are,\n\\[\n\\E(X) = \\frac{1}{k} \\left( 1+2+\\cdots+k \\right)= \\frac{1}{k} \\frac{k(k+1)}{2} = \\frac{k+1}{2}  \\ ,\n\\]\n\\[\n\\E(X^2) = \\frac{1}{k} \\left( 1^2+2^2+\\cdots+k^2 \\right)  = \\frac{1}{k} \\frac{k(k+1)(2k+1)}{6} =  \\frac{2k^2+3k+1}{6} \\ ,\n\\]\n\\begin{align}\n\\V(X) = \\E(X^2) - (\\E(X))^2\n&= \\frac{2k^2+3k+1}{6} -  \\left( \\frac{k+1}{2} \\right)^2 = \\frac{2k^2+3k+1}{6} -  \\left( \\frac{k^2+2k+1}{4} \\right) \\notag \\\\\n&=  \\frac{8k^2+12k+4 - 6k^2-12k-6}{24} =  \\frac{2k^2-2}{24} = \\frac{k^2-1}{12} \\notag \\ .\n\\end{align}\n\n\n\\input{ExsInExpectations.tex}\n\n\\section{Multivariate Random Variables}\\label{S:RVecs}\n\nOften, in experiments we are measuring two or more aspects simultaneously.  \nFor example, we may be measuring the diameters and lengths of cylindrical shafts manufactured in a plant or heights, weights and blood-sugar levels of individuals in a clinical trial.  \nThus, the underlying outcome $\\omega \\in \\Omega$ needs to be mapped to measurements as realizations of random vectors in the real plane $\\Rz^2 = (-\\infty, \\infty) \\times (-\\infty, \\infty)$ or the real space $\\Rz^3 = (-\\infty, \\infty) \\times (-\\infty, \\infty) \\times (-\\infty, \\infty)$:\n\\[\n\\omega \\mapsto \\left( X(\\omega),Y(\\omega) \\right) : \\Omega \\to \\Rz^2  \\qquad \\qquad \\qquad \\omega \\mapsto \\left( X(\\omega),Y(\\omega), Z(\\omega) \\right) : \\Omega \\to \\Rz^3\n\\]\n%\\vspace{2cm}\n\nMore generally, we may be interested in heights, weights, blood-sugar levels, family medical history, known allergies, etc. of individuals in the clinical trial and thus need to make $m$ measurements of the outcome in $\\Rz^m$ using a ``measurable mapping'' from $\\Omega \\to \\Rz^m$.  \nTo deal with such multivariate measurements we need the notion of {\\bf random vectors} ({\\rv}s), i.e.~ordered pairs of random variables $(X,Y)$, ordered triples of random variables $(X,Y,Z)$, or more generally ordered $m$-tuples of random variables $(X_1,X_2,\\ldots,X_m)$.  \n\n\\subsection{$\\Rz^2$-valued Random Variables}\n\nWe first focus on understanding $(X,Y)$, a bivariate \\rv~or $\\Rz^2$-valued RV that is obtained from a pair of discrete or continuous RVs.  \nWe then generalize to $\\Rz^m$-valued RVs with $m>2$ in the next section.\n\n\\begin{definition}[JDF]\\label{Df:JDF}\nThe {\\bf joint distribution function (JDF)} or {\\bf joint cumulative distribution function (JCDF)}, $F_{X,Y}(x,y):\\mathbb{R}^2\\to [0,1]$, of the bivariate random vector $(X,Y)$ is\n\\begin{eqnarray}\\label{E:j2DF}\nF_{X,Y}(x,y)\\; \n&=& \\P(X\\leq x \\cap Y \\leq y) \\;= \\;\\P(X\\leq x , Y \\leq y)\\notag\\\\\n&=& P\\left( \\{ \\omega: X(\\omega) \\le x, Y(\\omega) \\le y \\} \\right) \\mbox{, for any } (x,y) \\in \\mathbb{R}^2 \\enspace ,\n\\end{eqnarray}\nwhere the right-hand side represents the probability that the random vector $(X,Y)$ takes on a value in \n$\\{(x',y'): x' \\leq x, y' \\leq y\\}$, the set of points in the plane that are south-west of the point $(x,y)$.\n\\end{definition}\n\nThe JDF $F_{X,Y}(x,y):\\Rz^2\\to\\Rz$ satisfies the following conditions to remain a probability: \n\\begin{enumerate}\n\\item $0 \\leq F_{X,Y}(x,y) \\leq 1$\n\\item $F_{X,Y}(x,y)$ is an non-decreasing function of both $x$ and $y$\n\\item $F_{X,Y}(x,y) \\to 1$ as $x\\to \\infty$ and $y\\to \\infty$\n\\item $F_{X,Y}(x,y) \\to 0$ as $x\\to -\\infty$ and $y\\to -\\infty$\n\\end{enumerate}\n\n\\begin{definition}[JPMF]\nIf $(X,Y)$ is a {\\bf discrete random vector} that takes values in a discrete support set $\\mathcal{S}_{X,Y} = \\{(x_i,y_j): i=1,2,\\ldots, \\, j=1,2,\\ldots\\} \\subset \\Rz^2$ with probabilities $p_{i,j}=\\P(X=x_i,Y=y_j)>0$, then its \\textbf{joint probability mass function} (or JPMF) is:\n\\begin{equation}\\label{Eq:j2DPMF}\nf_{X,Y}(x_i,y_j) = \\P(X=x_i,Y=y_j) %P\\left(\\{\\omega: X(\\omega) = x_i, Y(\\omega)=y_j \\}\\right) \n=\\begin{cases}\np_{i,j}&\\quad \\textrm{if } (x_i,y_j) \\in \\mathcal{S}_{X,Y}\\\\\n0&\\quad \\textrm{otherwise}\n\\end{cases}  \\enspace .\n\\end{equation}\n\nSince $\\P(\\Omega)=1$, $\\sum_{{\\substack{(x_i,y_j) \\in \\mathcal{S}_{X,Y}}}}f_{X,Y}(x_i,y_j)=1$.\n\\end{definition}\n\nFrom JPMF $f_{X,Y}$ we can get the values of the JDF $F_{X,Y}(x,y)$ and the probability of any event $B$ by simply taking sums,\n\\begin{equation}\\label{Eq:2DiscretejDFFromjPMF}\n\\boxed{F_{X,Y}(x,y)\\;=\\;\\sum_{x_i\\leq x, y_j \\leq y}f_{X,Y}(x_i,y_j) }\\enspace ,\n\\qquad \\boxed{\\P(B)\\;=\\;\\sum_{\\substack{(x_i, y_j) \\in B \\cap \\mathcal{S}_{X,Y}}}f_{X,Y}(x_i,y_j) }\\enspace ,\n\\end{equation}\n\n\\begin{example}\\label{Eg:Discrete2DPMF}\nLet $(X,Y)$ be a discrete bivariate \\rv with the following joint probability mass function (JPMF):\n\\[\nf_{X,Y}(x,y) := P (X=x,Y=y)  = \n\\begin{cases}\n0.1 & \\text{ if } (x,y)=(0,0)\\\\\n0.3 & \\text{ if } (x,y)=(0,1)\\\\\n0.2 & \\text{ if } (x,y)=(1,0)\\\\\n0.4 & \\text{ if } (x,y)=(1,1)\\\\\n0.0 & \\text{ otherwise.}\n\\end{cases} \n\\]\n\\begin{center}\n\\makebox{\\includegraphics[width=5.0in]{figures/Discrete2DPMF}}\n\\end{center}\nIt is helpful to write down the JPMF $f_{X,Y}(x,y)$ in a tabular form:\n\\begin{center}\n\\begin{tabular}{|c|c c|}\n\\hline\n& $Y=0$ & $Y=1$ \\\\ \\hline\n$X=0$& $0.1$ & $0.3$  \\\\\n$X=1$& $0.2$ & $0.4$  \\\\ \\hline\n\\end{tabular}\n\\end{center}\nFrom the above Table we can read for instance that the joint probability $f_{X,Y}(0,0)=0.1$.\n\nFind $\\P(B)$ for the event $B=\\{(0,0),(1,1)\\}$, $F_{X,Y}(1/2,1/2)$, $F_{X,Y}(3/2,1/2)$, $F_{X,Y}(4,5)$ and $F_{X,Y}(-4,-1)$.\n\n\\begin{enumerate}\n\\item $\\P(B) = \\sum_{(x,y) \\in \\{(0,0),(1,1)\\}}f_{X,Y}(x,y) = f_{X,Y}(0,0)+f_{X,Y}(1,1)=0.1+0.4$\n\\item $F_{X,Y}(1/2,1/2) = \\sum_{\\{(x,y): x\\leq 1/2, y \\leq 1/2\\}} f_{X,Y}(x,y)=f_{X,Y}(0,0)=0.1$\n\\item $F_{X,Y}(3/2,1/2) = \\sum_{\\{(x,y): x\\leq 3/2, y \\leq 1/2\\}} f_{X,Y}(x,y)=f_{X,Y}(0,0)+f_{X,Y}(1,0)=0.1+0.2=0.3$\n\\item $F_{X,Y}(4,5) = \\sum_{\\{(x,y): x\\leq 4, y \\leq 5\\}} f_{X,Y}(x,y)=f_{X,Y}(0,0)+f_{X,Y}(0,1)+f_{X,Y}(1,0)+f_{X,Y}(1,1)=1$\n\\item $F_{X,Y}(-4,-1) = \\sum_{\\{(x,y): x\\leq -4, y \\leq -1\\}} f_{X,Y}(x,y)=0$\n\\end{enumerate}\n%\\vspace{2cm}\n\\end{example}\n\n\\begin{definition}[JPDF] We say $(X,Y)$ is a {\\bf continuous $\\R^2$-valued random variable} if its JDF $F_{X,Y}(x,y)$ is differentiable and its {\\bf joint probability density function (JPDF)} is given by:\n\\[\nf_{X,Y}(x,y) = \\frac{\\partial^2}{\\partial x \\partial y} F_{X,Y}(x,y) \\enspace .\n\\]\n\\end{definition}\n\nFor notational convenience, we sometimes suppress the subscripting when the random variables are clear from the context and write $f(x,y)$ and $F(x,y)$ instead of $f_{X,Y}(x,y)$ and $F_{X,Y}(x,y)$, respectively.\n\nFrom JPDF $f_{X,Y}$ we can compute the JDF $F_{X,Y}$ at any point $(x,y) \\in \\Rz^2$ and more generally we can compute the probability of any event $B$, that can be cast as a region in $\\Rz^2$, by simply taking two-dimensional integrals:\n\\begin{equation}\\label{Eq:2ContjDFFromjPDF}\n\\boxed{F_{X,Y}(x,y) = \\int_{-\\infty}^{y} \\int_{-\\infty}^{x} f_{X,Y}(u,v) du dv}\\enspace ,\n\\end{equation}\nand\n\\begin{equation}\\label{Eq:2ContProbEventFromjPDF}\n\\boxed{\\P(B)\\;=\\; \\int\\int_{B} f_{X,Y}(x,y) dx dy}\\enspace .\n\\end{equation}\nIn particular, if $\\Bz_{\\delta}(x,y)$ denotes a square of a small area $\\delta>0$ that is centered at $(x,y)$, then the following approximate equality holds and improves as $\\delta \\to 0$:\n\\begin{equation}\\label{Eq:2ContProbEventFromjPDFInSmallBall}\n\\P\\left( (X,Y) \\in \\Bz_{\\delta}(x,y) \\right) \\approxeq \\delta f_{X,Y}(x,y) \\enspace .\n\\end{equation}\nThe JPDF satisfies the following two properties:\n\\be\n\\item integrates to $1$, i.e., $\\int_{-\\infty}^{\\infty} \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx dy=1$\n\\item is a non-negative function, i.e., $f_{X,Y}(x,y) \\geq 0$ for every $(x,y) \\in \\mathbb{R}^2$.\n\\ee\n\n\\begin{example}\\label{Eg:Unif2DPDFandCDF}\nLet $(X,Y)$ be a continuous \\rv~that is uniformly distributed on the unit square $[0,1]^2 := [0,1] \\times [0,1]$ with following JPDF:\n\\[\nf(x,y) =  \\BB{1}_{[0,1]^2}(x) \n\\begin{cases}\n1 & \\text{ if } (x,y) \\in [0,1]^2 \\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\nFind explicit expressions for the following: (1) DF $F(x,y)$ for any $(x,y) \\in [0,1]^2$, (2) $\\P(X \\leq 1/3, Y \\leq 1/2)$, (3) $P\\left( (X,Y) \\in [1/4,1/2]\\times[1/3,2/3] \\right)$.\n\n\\begin{center}\n\\makebox{\\includegraphics[width=6.5in]{figures/Unif2DPDFandCDF}}\n\\end{center}\n\nLet us begin to find the needed expressions.\n\\be\n\\item\nLet $(x,y) \\in [0,1]^2$ then by Equation~\\eqref{Eq:2ContjDFFromjPDF}:\n{\\small\n\\begin{align*}\nF_{X,Y}(x,y) \n&= \\int_{-\\infty}^{y} \\int_{-\\infty}^{x} f_{X,Y}(u,v) dudv\n= \\int_{0}^{y} \\int_{0}^{{x}} 1 dudv\n= \\int_{0}^{y} \\left[ u \\right]_{u=0}^{x}  dv\n= \\int_{0}^{y} x  dv\n&= \\left[ x v \\right]_{v=0}^{y}\n= {x}{y}\n\\end{align*}\n}\n\\item We can obtain $\\P(X \\leq 1/3, Y \\leq 1/2)$ by evaluating $F_{X,Y}$ at $(1/3,1/2)$:\n{\\small\n\\begin{align*}\n\\P(X \\leq 1/3, Y \\leq 1/2)\n&= F_{X,Y}(1/3,1/2)\n= \\frac{1}{3}\\frac{1}{2}\n= \\frac{1}{6}\n\\end{align*}\n}\nWe can also find $\\P(X \\leq 1/3, Y \\leq 1/2)$ by integrating the JPDF over the rectangular event $A=\\{X < 1/3, Y < 1/2 \\} \\subset [0,1]^2$ according to Equation~\\eqref{Eq:2ContProbEventFromjPDF}.  \nThis amounts here to finding the area of $A$, we compute $\\P(A) = (1/3) (1/2) = 1/6$.  \n\n\\item We can find $P\\left( (X,Y) \\in [1/4,1/2]\\times[1/3,2/3] \\right)$ by integrating the JPDF over the rectangular event $B=[1/4,1/2]\\times[1/3,2/3]$ according to Equation~\\eqref{Eq:2ContProbEventFromjPDF}:\n{\\small\n\\begin{align*}\nP\\left( (X,Y) \\in [1/4,1/2]\\times[1/3,2/3] \\right)\n&=\\int\\int_B f_{X,Y}(x,y)dxdy\n=\\int_{1/3}^{2/3}\\int_{1/4}^{1/2} 1 dx dy\\\\\n&=\\int_{1/3}^{2/3} \\left[ x \\right]_{1/4}^{1/2}  dy\n=\\int_{1/3}^{2/3} \\left[ \\frac{1}{2}-\\frac{1}{4} \\right]  dy\n=\\left(\\frac{1}{2}-\\frac{1}{4}\\right)\\left[ y \\right]_{1/3}^{2/3}\\\\ \n&=\\left(\\frac{1}{2}-\\frac{1}{4}\\right)\\left( \\frac{2}{3}-\\frac{1}{3} \\right) \n=\\frac{1}{4} \\left( \\frac{1}{3} \\right) =\\frac{1}{12}\n\\end{align*}\n}\n\\ee\n\nIn general, for a bivariate uniform \\rv~on the unit square the $\\P([a,b]\\times[c,d]) = (b-a)(d-c)$ for any event given by the rectangular region $[a,b]\\times[c,d]$ inside the unit square $[0,1]\\times[0,1]$.  \nThus any two events with the same rectangular area have the same probability (imagine sliding a small rectangle inside the unit square... no matter where you slide this rectangle to while remaining in the unit square, the probability of $\\omega \\mapsto (X(\\omega),Y(\\omega))=(x,y)$ falling inside this ``slidable'' rectangle is the same...).\n\\end{example}\n \n\\begin{example}\\label{Eg:PlotPDF2ServerTimes}\nLet the RV $X$ denote the time until a web server connects to your computer, and let the RV $Y$ denote the time until the server authorizes you as a valid user.  \nEach of these RVs measures the waiting time from a common starting time (in milliseconds) and $X < Y$.  \nFrom past response times of the web server we know that a good approximation for the JPDF of the \\rv~$(X,Y)$ is\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\n\\frac{6}{10^6} \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right)\n& \\text{ if } x>0,y>0,x <y\\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\nAnswer the following:\n\\be\n\\item identify the support of $(X,Y)$, i.e., the region in the plane where $f_{X,Y}$ takes positive values\n\\item check that $f_{X,Y}$ indeed integrates to $1$ as it should\n\\item Find $\\P(X \\leq 400, Y \\leq 800)$\n\\item It is known that humans prefer a response time of under $1/10$ seconds ($10^2$ milliseconds) from the web server before they get impatient.  What is $\\P(X+Y < 10^2)$? \n\\ee\n\\begin{center}\n\\makebox{\\includegraphics[width=6.0in]{figures/PlotPDF2ServerTimes}}\n\\end{center}\nLet us answer the questions.\n\\be\n\\item\nThe support is the intersection of the positive quadrant with the $y>x$ half-plane.\n\\item\n{\\scriptsize\n\\begin{align*}\n\\int_{y=-\\infty}^{\\infty}\\int_{x=-\\infty}^{\\infty} f_{X,Y}(x,y) dx dy \n&= \\int_{x=0}^{\\infty}\\int_{y=x}^{\\infty} f_{X,Y}(x,y) dy dx\\\\\n&= \\int_{x=0}^{\\infty}\\int_{y=x}^{\\infty} \\frac{6}{10^6} \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right) dy dx\\\\\n&= \\frac{6}{10^6} \\int_{x=0}^{\\infty} \\left(\\int_{y=x}^{\\infty} \\exp \\left( -\\frac{2}{1000}y \\right) dy \\right) \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\int_{x=0}^{\\infty} \\left[ -\\frac{1000}{2} \\exp \\left( -\\frac{2}{1000}y \\right) \\right]_{y=x}^{\\infty}  \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\int_{x=0}^{\\infty} \\left[0 +\\frac{1000}{2}\\exp \\left( -\\frac{2}{1000}x \\right) \\right]  \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\int_{x=0}^{\\infty} \\frac{1000}{2}\\exp \\left( -\\frac{2}{1000}x -\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\left[ -\\frac{1000}{3} \\exp \\left(-\\frac{3}{1000}x\\right)\\right]_{x=0}^{\\infty} \\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\left[0 +\\frac{1000}{3} \\right] \\\\\n&=1\n\\end{align*}\n}\n\\item\nFirst, identify the region with positive JPDF for the event $(X \\leq 400, Y \\leq 800)$\n{\\scriptsize\n\\begin{align*}\n&\\P(X \\leq 400, Y \\leq 800)\\\\\n&= \\int_{x=0}^{400} \\int_{y=x}^{800} f_{X,Y}(x,y) dy dx \\\\\n&= \\int_{x=0}^{400} \\int_{y=x}^{800} \\frac{6}{10^6} \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right) dy dx \\\\\n&= \\frac{6}{10^6}  \\int_{x=0}^{400} \\left[ -\\frac{1000}{2} \\exp \\left( -\\frac{2}{1000}y \\right) \\right]_{y=x}^{800}  \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\int_{x=0}^{400} \\left( - \\exp \\left( -\\frac{1600}{1000} \\right) + \\exp \\left( -\\frac{2}{1000}x \\right) \\right)  \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\int_{x=0}^{400} \\left( \\exp \\left( -\\frac{3}{1000}x \\right) - e^{-8/5} \\exp \\left(-\\frac{1}{1000}x\\right)\\right) dx\\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\left( \\left( -\\frac{1000}{3} \\exp \\left( -\\frac{3}{1000}x \\right) \\right)_{x=0}^{400} - e^{-8/5} \\left(-1000 \\exp \\left(-\\frac{1}{1000}x\\right)\\right)_{x=0}^{400} \\right) \\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} 1000 \\left( \\frac{1}{3}\\left(1- e^{-6/5} \\right) - e^{-8/5} \\left( 1-e^{-2/5}\\right) \\right) \\\\\n&= 3 \\left( \\frac{1}{3}\\left(1- e^{-6/5} \\right) - e^{-8/5} \\left( 1-e^{-2/5}\\right) \\right) \\\\\n&\\approxeq 0.499 \\enspace .\n\\end{align*}\n}\n\\item\nFirst, identify the region with positive JPDF for the event $(X+Y \\leq c)$, say $c=500$ (but generally $c$ can be any positive number).\nThis is the triangular region at the intersection of the four half-planes: $x>0$, $x < c$, $y>x$ and $y<c-x$. ({\\em Draw picture here})\n%\\vspace{2cm}\\\\\nLet's integrate the JPDF over our triangular event as follows:\n{\\scriptsize\n\\begin{align*}\n\\P(X+Y \\leq c) \n&= \\int_{x=0}^{c/2}\\int_{y=x}^{c-x} f_{X,Y}(x,y) dy dx \\\\\n&= \\int_{x=0}^{c/2}\\int_{y=x}^{c-x} \\frac{6}{10^6} \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right) dy dx \\\\\n&= \\frac{6}{10^6} \\int_{x=0}^{c/2}\\int_{y=x}^{c-x}  \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right) dy dx \\\\\n&= \\frac{6}{10^6} \\frac{1000}{2} \\int_{x=0}^{c/2} \\left[ - \\exp \\left( -\\frac{2}{1000}y \\right) \\right]_{y=x}^{c-x}  \\exp \\left(-\\frac{1}{1000}x\\right) dx\\\\\n&= \\frac{3}{10^3} \\int_{x=0}^{c/2} \\left[ - \\exp \\left( -\\frac{2c-2x}{1000} \\right) + \\exp \\left( -\\frac{2x}{1000} \\right) \\right]  \\exp \\left(-\\frac{x}{1000}\\right) dx\\\\\n&= \\frac{3}{10^3} \\int_{x=0}^{c/2} \\left(  \\exp \\left( -\\frac{3x}{1000} \\right) - \\exp \\left( \\frac{x-2c}{1000} \\right) \\right)  dx\\\\\n&= 3 \\left( \\left[-\\frac{1}{3} \\exp \\left( -\\frac{3x}{1000} \\right) \\right]_{x=0}^{c/2} - \\left[ e^{-2c/1000} \\exp \\left( \\frac{x}{1000} \\right)\\right]_{x=0}^{c/2} \\right)  \\\\\n&= 3  \\left(\\frac{1}{3} (1-e^{-3c/2000}) - e^{-2c/1000} (e^{c/2000}-1) \\right)\\\\\n&= 1 - e^{-3c/2000} + 3 e^{-2c/1000} - 3 e^{-3c/2000}\\\\\n&= 1 - 4 e^{-3c/2000} + 3 e^{-c/500}\n\\end{align*}\n}\n%\\vspace{1cm}\\\\\n\\item $\\P(X+Y<100) = 1 - 4 e^{-300/2000} + 3 e^{-100/500} \\approxeq 0.134$.  This means only about one in one hundred requests to this server will be processed within 100 milliseconds.\n\\ee\nWe can obtain $\\P(X+Y<c)$ for several values of $c$ using \\Matlab and note that about 96\\% of requests are processed in less than 3000 milliseconds or 3 seconds.\n\\begin{VrbM}\n>> c = [100 1000 2000 3000 4000]\nc =  100        1000        2000        3000        4000\n\n>> p = 1 - 4 * exp(-3*c/2000) + 3 * exp(-c/500)\n\np =  0.0134     0.5135      0.8558      0.9630      0.9911\n\\end{VrbM}\n\\end{example}\n\n\\begin{definition}[Marginal PDF or PMF]\nIf the \\rv~$(X,Y)$ has $f_{X,Y}(x,y)$ as its joint PDF or joint PMF, then the \n{\\bf marginal PDF or PMF} of a random vector $(X,Y)$ is defined by :\n\\[\nf_{X}(x) =\n\\begin{cases}\n\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy & \\text{if $(X,Y)$ is a continuous \\rv}  \\\\\n\\sum_{y} f_{X,Y}(x,y) & \\text{if $(X,Y)$ is a discrete \\rv} \\\\\n\\end{cases}\n\\]\nand the  {\\bf marginal PDF or PMF} of $Y$ is defined by:\n\\[\nf_{Y}(y) = \n\\begin{cases}\n\\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx & \\text{if $(X,Y)$ is a continuous \\rv}  \\\\\n\\sum_{x} f_{X,Y}(x,y) & \\text{if $(X,Y)$ is a discrete \\rv} \\\\\n\\end{cases}\n\\]\n\\end{definition}\n\n\\begin{example}\\label{EgGetMarginalFromJointDiscrete}\nObtain the marginal PMFs $f_Y(y)$ and $f_X(x)$ from the joint PMF $f_{X,Y}(x,y)$ of the discrete \\rv~in \\hyperref[Eg:Discrete2DPMF]{Example~\\ref*{Eg:Discrete2DPMF}}.\nJust sum $f_{X,Y}(x,y)$ over $x$'s and $y$'s (reported in a tabular form):\n\\begin{center}\n\\begin{tabular}{|c|c c|}\n\\hline\n& $Y=0$ & $Y=1$ \\\\ \\hline\n$X=0$& $0.1$ & $0.3$  \\\\\n$X=1$& $0.2$ & $0.4$  \\\\ \\hline\n\\end{tabular}\n\\end{center}\nFrom the above Table we can find:\n\\begin{align*}\nf_X(x) = \\P(X=x) \n&= \\sum_{y} f_{X,Y}(x,y) \\\\\n&= \nf_{X,Y}(x,0) + f_{X,Y}(x,1) = \n\\begin{cases}\nf_{X,Y}(0,0) + f_{X,Y}(0,1) = 0.1+0.3=0.4 & \\text{ if } x=0\\\\\nf_{X,Y}(1,0) + f_{X,Y}(1,1) = 0.2+0.4=0.6 & \\text{ if } x=1\\\\\n\\end{cases}\n\\end{align*}\nSimilarly,\n\\begin{align*}\nf_Y(y) = \\P(Y=y) \n&= \\sum_{x} f_{X,Y}(x,y) \\\\\n&= \nf_{X,Y}(0,y) + f_{X,Y}(1,y) \n= \n\\begin{cases}\nf_{X,Y}(0,0) + f_{X,Y}(1,0) = 0.1+0.2=0.3 & \\text{ if } y=0\\\\\nf_{X,Y}(0,1) + f_{X,Y}(1,1) = 0.3+0.4=0.7 & \\text{ if } y=1\\\\\n\\end{cases}\n\\end{align*}\nJust report the marginal probabilities as row and column sums of the JPDF table.\n\nThus marginal PMF gives us the probability of a specific RV, within a \\rv, taking a value irrespective of the value taken by the other RV in this \\rv. \n\\end{example}\n\n\\begin{example}\\label{EgGetMarginalFromJointContUnif2DPDFandCDF}\nObtain the marginal PDFs $f_Y(y)$ and $f_X(x)$ from the joint PDF $f_{X,Y}(x,y)$ of the continuous \\rv~in \\hyperref[Eg:Unif2DPDFandCDF]{Example~\\ref*{Eg:Unif2DPDFandCDF}} (the bivariate uniform \\rv~on $[0,1]^2$).\n\n\\begin{center}\n\\makebox{\\includegraphics[width=6.0in]{figures/PlotPDFSamplesMarginalsUnif2D}}\n\\end{center}\n\nLet us suppose $(x,y) \\in [0,1]^2$ and note that $f_{X,Y}=0$ if $(x,y) \\notin [0,1]^2$.  \nWe can obtain marginal PMFs $f_X(x)$ and $f_Y(y)$ by integrating the JPDF $f_{X,Y}=1$ along $y$ and $x$, respectively.\n\\[\nf_X(x) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dy = \\int_{0}^{1} f_{X,Y}(x,y) dy \n= \\int_{0}^{1} 1 dy = \\left[ y \\right]_0^1 = 1-0 = 1\n\\]\nSimilarly,\n\\[\nf_Y(y) = \\int_{-\\infty}^{\\infty} f_{X,Y}(x,y) dx = \\int_{0}^{1} f_{X,Y}(x,y) dx \n= \\int_{0}^{1} 1 dx = \\left[ x \\right]_0^1 = 1-0 = 1\n\\]\nWe are seeing a histogram of the {\\bf marginal samples} and their marginal PDFs in the Figure.\n\\end{example}\n\nThus marginal PDF gives us the probability density of a specific RV in a \\rv, irrespective of the value taken by the other RV in this \\rv. \n\n\\begin{example}\\label{EgGetMarginalFromJointContServerTimes}\nObtain the marginal PDF $f_Y(y)$ from the joint PDF $f_{X,Y}(x,y)$ of the continuous \\rv~in \\hyperref[Eg:PlotPDF2ServerTimes]{Example~\\ref*{Eg:PlotPDF2ServerTimes}} that gave the response times of a web server.\n\\[\nf_{X,Y}(x,y) = \n\\begin{cases}\n\\frac{6}{10^6} \\exp \\left( -\\frac{1}{1000}x-\\frac{2}{1000}y \\right)\n& \\text{ if } x>0,y>0,x <y\\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\nUse $f_Y(y)$ to compute the probability that $Y$ exceeds 2000 milliseconds.\n\n%\\vspace{5in}\nFirst we need to obtain an expression for $f_Y(y)$. For $y > 0$,\n{\\scriptsize\n\\begin{align*}\nf_Y(y) \n&= \\int_{x=-\\infty}^{\\infty} f_{X,Y}(x,y) dx\\\\\n&= \\int_{x=-\\infty}^{\\infty} 6 \\times 10^{-6} e^{-0.001 x - 0.002y} dx\\\\\n&= 6 \\times 10^{-6} \\int_{x=0}^{y} e^{-0.001 x - 0.002y} dx\\\\ \n&= 6 \\times 10^{-6} e^{-0.002y} \\int_{x=0}^{y}  e^{-0.001 x} dx\\\\ \n&= 6 \\times 10^{-6} e^{-0.002y} \\left[ \\frac{e^{-0.001 x}}{-0.001}\\right]_{x=0}^{x=y}\\\\ \n&= 6 \\times 10^{-6} e^{-0.002y} \\left( \\frac{e^{-0.001 y}}{-0.001} - \\frac{e^{-0.001 \\times 0}}{-0.001} \\right)\\\\ \n&= 6 \\times 10^{-6} e^{-0.002y} \\left( \\frac{1- e^{-0.001 y}}{0.001} \\right)\\\\ \n&= 6 \\times 10^{-3} e^{-0.002y} \\left({1- e^{-0.001 y}} \\right)\\\\ \n\\end{align*}\n}\nWe have the marginal PDF of $Y$ and from this we can obtain \n{\\scriptsize\n\\begin{align*}\n\\P(Y>2000)\n&= \\int_{2000}^{\\infty} f_Y(y) dy \\\\\n&= \\int_{2000}^{\\infty} 6 \\times 10^{-3} e^{-0.002y} \\left({1- e^{-0.001 y}} \\right) dy\\\\\n&= 6 \\times 10^{-3} \\int_{2000}^{\\infty}  e^{-0.002y} dy - \\int_{2000}^{\\infty} e^{-0.003 y} dy\\\\\n&= 6 \\times 10^{-3} \\left( \\left[ \\frac{e^{-0.002y}}{-0.002} \\right]_{2000}^{\\infty} \n- \\left( \\left[ \\frac{e^{-0.003y}}{-0.003} \\right]_{2000}^{\\infty} \\right) \\right)\\\\\n&= 6 \\times 10^{-3} \\left( \\frac{e^{-4}}{0.002} - \\frac{e^{-6}}{0.003} \\right)\\\\\n&= 0.05\n\\end{align*}\n}\n\n{\\scriptsize\nAlternatively, you can obtain $\\P(Y>2000)$ by directly integrating the joint PDF $f_{X,Y}(x,y)$ over the appropriate region (but you may now have to integrate two pieces: rectangular infinite strip ${(x,y): 0<x<2000, y>2000}$ and a triangular infinite piece $\\{(x,y): y>x, y>2000, x> 2000\\}$)... more involved but we get the same answer.\n\\begin{multline*}\n\\P(Y>2000) = \\int_{x=0}^{2000} \\left( \\int_{y=2000}^{\\infty} 6 \\times 10^{-6} e^{-0.001 x - 0.002y} dy \\right) dx + \\\\\n\\int_{x=2000}^{\\infty} \\left( \\int_{y=x}^{\\infty} 6 \\times 10^{-6} e^{-0.001 x - 0.002y} dy \\right) dx \n\\\\\n\\vdots \\text{(try as a tutorial problem)} \\\\\n\\P(Y>2000) = 0.0475 + 0.0025 = 0.05\n\\end{multline*}\n}\n\\end{example}\n\nWe have seen the notion of independnece of two events in \\hyperref[D:IndOf2Events]{Definition~\\ref*{D:IndOf2Events}} or of a sequence of events in \\hyperref[D:IndOfSeqOfEvents]{Definition~\\ref*{D:IndOfSeqOfEvents}}. \nRecall that independence amounts to having the probability of the joint occurrence of the events to be given by the product of the probabilities of each of the events.\n\nWe can use the definition of independence of two events to define the independence of two random variables using their distribution functions.\n\n\\begin{definition}[Independence of Two RVs]\\label{D:Ind2RVs}\nConsider an $\\Rz^2$-valued RV $X:=(X_1,X_2)$. Then the $\\Rz$-valued RVs $X_1$ and $X_2$ are said to be independent or independently distributed if and only if\n\\[\n\\P(X_{1} \\leq x_{1}, X_{2} \\leq x_{2} ) = \\P(X_{1} \\leq x_{1}) \\P(X_{2} \\leq x_{2})\n\\]\nor equivalently,\n\\[\nF_{X_{1},X_{2}}(x_{1},x_{2}) = F_{X_{1}}(x_{1}) F_{X_{2}}(x_{2}) \\enspace ,\n\\]\nfor any pair of real numbers $(x_{1},x_{2}) \\in \\Rz^2$.\n\nBy the above definition, for {\\bf discrete} RVs $X_1,X_2$ that are independent, the following equality is satisfied between the joint and marginal PMFs:\n\\[\nf_{X_1,X_2}(x_1,x_2) = \\P(X_{1}= x_{1}, X_{2} = x_{2}) = \\P(X_{1} = x_{1}) \\P(X_{2} = x_{2}) = f_{X_1}(x_1) f_{X_2}(x_2) \\text{ for any} (x_{1},x_{2}) \\in \\Rz^2 \\enspace ,\n\\]\nand for {\\bf continuous} RVs $X_1,X_2$ that are independent, the following equality is satisfied between the joint and marginal PDFs:\n\\[\nf_{X_1,X_2}(x_1,x_2) = f_{X_1}(x_1) f_{X_2}(x_2)  \\text{ for any} (x_{1},x_{2}) \\in \\Rz^2 \\enspace .\n\\] \n\\end{definition}\n\nIn summary, two RVs $X$ and $Y$ are said to be {\\bf independent} if and only if for every $(x,y)$\n\\[\n\\boxed{\nF_{X,Y}(x,y) = F_X(x) \\times F_Y(y) \\qquad \\text{ or } f_{X,Y}(x,y) = f_X(x) \\times f_Y(y)\n}\n\\]\n\nLet us confirm that our familiar experiment of tossing a fair coin twice independently when encoded by a pair of independent $\\bernoulli(1/2)$ RVs satisfies the above definition.\n\n\\begin{example}[Pair of independent $\\bernoulli(1/2)$ RVs]\\label{EgIndepPairOfBernoulis}\nLet $X_1$ and $X_2$ be a pair of independent $\\bernoulli(1/2)$ RVs each taking values in the set $\\{0,1\\}$ with the following tabulated probabilities. Verify that the JPMF $f_{X_1,X_2}(x_1,x_2)=1/4$ for each $(x_1,x_2) \\in \\{0,1\\}^2$ is indeed given by the marginal PMF $f_{X_i}(x_i)=1/2$ for each $i \\in \\{1,2\\}$ and each $x_i \\in \\{0,1\\}$.\n\n\\begin{center}\n\\begin{tabular}{|c|c c|c|}\n\\hline\n& $X_2=0$ & $X_2=1$ & \\\\ \\hline\n$X_1=0$& $1/4$ & $1/4$ & $1/2$ \\\\\n$X_1=1$& $1/4$ & $1/4$ & $1/2$ \\\\ \\hline\n& $1/2$ & $1/2$ & $1$\\\\ \\hline\n\\end{tabular}\n\\end{center}\nFrom the above Table we can read for instance that the {\\em joint probability} that $\\Rz^2$-valued RV $(X_1,X_2)$ takes the value or realization $(0,0)$ is $1/4$ from the first entry of the inner-most tabulated rectangle, \ni.e., $\\P((X_1,X_2)=(0,0))=1/4$, \nand that the {\\em marginal probability} that the RV $X_1$ takes the value or relaization $0$ is $1/2$, \ni.e., $\\P(X_1=0)=1/2$. \nClearly, $1/4=1/2 \\times 1/2$, and so our familiar experiment when seen as an $\\Rz^2$-valued RV is indeed composed of two independent$\\Rz$-valued $\\bernoulli(1/2)$ RVs. \n\\end{example}\n\n\\begin{example}\\label{EgShowIndepUnifDensityOnUnitSquare}\nRecall the $\\Rz^2$-valued continuous RV $(X,Y)$ of \\hyperref[Eg:Unif2DPDFandCDF]{Example~\\ref*{Eg:Unif2DPDFandCDF}} \nthat is uniformly distributed on the unit square $[0,1]^2$. \nFirst show that $X$ and $Y$ independent. \nThen show that both $X$ and $Y$ are identically distributed according to the $\\uniform(0,1)$ RV. \n\n{\\em Solution:}\\\\[4pt]\nThis can be shown by checking that the joint PDF is indeed equal to the product of the marginal PDFs of $\\uniform(0,1)$ RVs as follows:\n\\[\n\\begin{cases}\n1= f_{X,Y}(x,y) =  f_X(x) \\times f_Y(y) = 1 \\times 1 = 1 & \\text{ if } (x,y) \\in [0,1]^2\\\\\n0= f_{X,Y}(x,y) =  f_X(x) \\times f_Y(y) = 0 \\times 0 = 0 & \\text{ if } (x,y) \\notin [0,1]^2\n\\end{cases}\n\\]\n\\end{example}\n\nAre $X$ and $Y$ independent in the server times \\rv~from \\hyperref[Eg:PlotPDF2ServerTimes]{Example~\\ref*{Eg:PlotPDF2ServerTimes}}?\n\nWe can compute $f_X(x)$ and use the already computed $f_Y(y)$ to mechanically check if the JPDF is the product of the marginal PDFs.  But intuitively, we know that these RVs (connection time and authentication time) are dependent -- one is strictly greater than the other.  \nAlso the JPDF has zero density when $x>y$, but the product of the marginal densities won't.\n\nNow, let us take advantage of independent random variables and solve some problems.\n\n\\begin{example}[distance between random faults in a manufactured line]\\label{EgDistBetweenFaultsOnLine}\nSuppose two points are tossed independently and uniformly at random onto a line segment of unit length.  \nWhat is the probability that the distance between the two points does not exceed a given length $l$? \n\n\\vspace{5cm}\ndone in lectures...\n\n\\end{example}\n\n\\begin{example}[Buffon's Needle Experiment to Physically Estimate $\\pi$]\\label{EgBuffonsNeedle}\nSuppose a needle is tossed at random onto a plane ruled with parallel lines a distance $L$ apart. \nBy a ``needle'' we mean a line segment of length $ l \\leq L$.\n\nWhat is the probability that the needle intersects one of the parallel lines? Can you use repeated trials of this experiment to find an approximation to $\\pi$?\n\n{\\em Solution:}\\\\[4pt]\nLet $X_1$ be the angle between the needle and the direction of the rulings, and let $X_2$ be the distance between the bottom point of the needle and the nearest line above this point (see left sub-figure of Figure~\\ref{F:BuffonsNeedle}). \nThen the conditions of the ``needle tossing at random'' experiment are such that the RV $X_1$ is uniformly distributed in the interval $[0,\\pi]$, while the RV $X_2$ is uniformly distributed in the interval $[0,L]$. \nHence {\\em assuming that the RVs $X_1$ and $X_2$ are independent}, we find that their joint probability density function (JPDF) is:\n\\[\nf_{X_1,X_2}(x_1,x_2) = \\frac{1}{\\pi}\\BB{1}_{[0,\\pi]}(x_1) \\times \\frac{1}{L}\\BB{1}_{[0,L]}(x_2) = \\frac{1}{\\pi L} \\BB{1}_{[0,\\pi]}(x_1) \\BB{1}_{[0,L]}(x_2) = \\frac{1}{\\pi L} \\BB{1}_{[0,\\pi] \\times [0,L] }(x_1,x_2) \\enspace . \n\\]\nThe event $A$ that the needle intersects one of the parallel ruled lines occurs if and only if\n\\[\nX_2 \\leq l \\sin(X_1) \\enspace,\n\\]\ni.e., if and only if the corresponding point $X := (X_1,X_2)$ falls in the region $B$, where $B$ is part of the rectangle $[0,\\pi] \\times [0,L]$ lying between the $x_1$-axis and the curve $x_2=\\sin(x_1)$ (area under the curve in right-subfigure of Figure~\\ref{F:BuffonsNeedle}). \nHence, we can integrate the JPDF to get the probability of the event $A$ of interest:\n\\[\n\\P(A) = \\P \\left( (X_1,X_2) \\in B \\right) = \\underset{B}{\\int \\int} \\frac{dx_1 dx_2}{\\pi L} = \\frac{2l}{\\pi L}\n\\]\nwhere,\n\\[\nl \\int_0{\\pi} \\sin(x_1) dx_1 = l \\left( - \\cos(x_1)\\right]_0^{\\pi} = l(1-(-1))=l(1+1)=2l \\enspace,\n\\]\nis the area of $B$. \n\nThus, if the needle is repeatedly tossed onto the ruled plane and $n(A)$ is the number of times $A$ occurs out of $n$ trials, then the relative frequency of the event $A$ should approach $\\P(A)$ as $n \\to \\infty$ (we will see this as the Law of Large Numbers in the sequel, but recall that this is also how we motivated the LTRF or long-term relative frequency idea of probability):\n\\[\n\\frac{n(A)}{n} \\to \\frac{2l}{\\pi L}\n\\]\nHence, for large $n$,\n\\[\n\\frac{2 l}{L}\\frac{n}{n(A)}\n\\]\nshould be a good approximation to $\\pi=3.14\\ldots$. This is indeed the case.\n\\end{example}\n\\begin{figure}\n\\vspace{3cm}\n\\caption{Diagrams done on the board! \\label{F:BuffonsNeedle}}\n\\end{figure}\n\n\\subsection{Conditional Random Variables}\\label{S:CondRVs}\n\nOften we will have a condition where one of the two random variables that make up a random vector $(X_1,X_2)$ already occurs and takes a value. \nAnd we might want to compute the probability of the occurrence of the other random variable given this conditional information.\nFor this all we need to do is extend the idea of conditional probabiliies to $\\Rz^2$-valued random variables as defined below.\n\n\\begin{definition}[Conditional PDF or PMF]\nLet $(X_1,X_2)$ be a discrete bivariate \\rv.  The conditional PMF of $X_1|X_2=x_2$, where $f_{X_2}(x_2) := \\P(X_2=x_2) > 0$ is:\n\\[\nf_{X_1|X_2}(x_1 | x_2) := \\P(X_1=x_1 | X_2=x_2) = \\frac{\\P(X_1=x_1,X_2=x_2)}{\\P(X_2=x_2)} = \\frac{f_{X_1,X_2}(x_1,x_2)}{f_{X_2}(x_2)} \\ .\n\\]\nSimilarly, if $f_{X_1}(x_1) := \\P(X_1=x_1) >0$, then the conditional PMF of $X_2|X_1=x_1$ is:\n\\[\nf_{X_2|X_1}(x_2|x_1) := \\P(X_2=x_2 | X_1=x_1) = \\frac{\\P(X_1=x_1,X_2=x_2)}{\\P(X_1=x_1)} = \\frac{f_{X_1,X_2}(x_1,x_2)}{f_{X_1}(x_1)} \\ .\n\\]\nIf $(X_1,X_2)$ are continuous RVs such that the marginal PDF $f_{X_2}(x_2)>0$, then the conditional PDF of $X_1|X_2=x_2$ is:\n\\[\nf_{X_1|X_2}(x_1|x_2) = \\frac{f_{X_1,X_2}(x_1,x_2)}{f_{X_2}(x_2)}, \\qquad \\P(X_1 \\in A| X_2=x_2) = \\int_A f_{X_1|X_2}(x_1|x_2) dx_1 \\ .\n\\]\nSimilarly, if $f_{X_1}(x_1)>0$, then the conditional PDF of $X_2|X_1=x_1$ is:\n\\[\nf_{X_2|X_1}(x_2|x_1) = \\frac{f_{X_1,X_2}(x_1,x_2)}{f_{X_1}(x_1)}, \\qquad \\P(X_2 \\in A| X_1=x_1) = \\int_A f_{X_2|X_1}(x_2|x_1) dx_2 \\ .\n\\]\n\\end{definition}\n\nLet us consider a few discrete RVs for the simple coin tossing experiment $\\EE{E}_{\\theta}^{3}$ that build on the $\\bernoulli(\\theta)$ RV $X_i$ for the $i$-th toss in an {\\bf independent and identically distibuted (IID.)} manner.\n\\begin{table}[htpb]\n\\caption{The $8$ $\\omega$'s in the sample space $\\Omega$ of the experiment $\\EE{E}_{\\theta}^{3}$ are given in the first row above.  The RV $Y$ is the number of `Heads' in the $3$ tosses and the RV $Z$ is the number of `Tails' in the $3$ tosses.  Finally, the RVs $Y'$ and $Z'$ are the indicator functions of the event that `all three tosses were Heads' and the event that `all three tosses were Tails', respectively.\\label{T:T3XRVs}}\n \\begin{tabular}{r c c c c c c c c l}\n \\hline\n$\\omega$:    & {\\tt HHH} & {\\tt HHT} & {\\tt HTH} & {\\tt HTT} & {\\tt THH} & {\\tt THT} & {\\tt TTH} & {\\tt TTT} & RV Definitions / Model \\\\ \\hline\n \\\\\n$\\P(\\omega)$: & $\\frac{1}{8}$ & $\\frac{1}{8}$ & $\\frac{1}{8}$ & $\\frac{1}{8}$ &  $\\frac{1}{8}$ & $\\frac{1}{8}$ & $\\frac{1}{8}$ & $\\frac{1}{8}$  & $X_i \\overset{\\IID}{\\sim} \\bernoulli(\\frac{1}{2})$ \\\\\n \\\\\n$Y(\\omega)$: & 3         & 2         & 2         & 1         & 2         & 1         & 1         & 0        & $Y := X_1+X_2+X_3$ \\\\\n \\\\\n$Z(\\omega)$: & 0         & 1         & 1         & 2         & 1         & 2         & 2         & 3        & $Z := (1-X_1)+(1-X_2)+(1-X_3)$ \\\\\n \\\\\n$Y'(\\omega)$: & 1         & 0         & 0         & 0         & 0         & 0         & 0         & 0       & $Y' :=  X_1 X_2 X_3$ \\\\\n\\\\\n$Z'(\\omega)$: & 0         & 0         & 0         & 0         & 0         & 0         & 0         & 1       & $Y' :=  (1-X_1)(1-X_2)(1-X_3)$ \\\\ \\hline\n \\end{tabular}\n \\end{table}\n \\begin{classwork}[Two random variables of `toss a coin thrice' experiment]\nDescribe the probability of the RV $Y$ and $Y'$ of \\hyperref[T:T3XRVs]{Table \\ref*{T:T3XRVs}} in terms of its PMF.  Repeat the process for the RV $Z$ in your spare time.\n \\begin{eqnarray}\n \\P(Y=y) =%:= \\P(\\{\\omega: Y(\\omega)=y\\}) = \n \\begin{cases}\n \\qquad & \\qquad \\notag \\\\\n \\qquad & \\qquad \\notag \\\\\n \\qquad & \\qquad \\notag \\\\\n \\qquad & \\qquad \\notag\n \\end{cases} \n & \\qquad \\qquad \\qquad \\qquad \\qquad\n\\P(Y'=y') =%:= \\P(\\{\\omega: Y'(\\omega)=y'\\}) = \n \\begin{cases}\n \\qquad & \\qquad \\notag \\\\\n \\qquad & \\qquad \\notag \n \\end{cases}\n \\end{eqnarray}\n \\end{classwork}\n \n \\begin{classwork}[The number of `Heads' given there is at least one `Tails']\n Consider the following two questions.\n \\begin{enumerate}\n\\item What is conditional probability $\\P(Y|Y'=0)$ ?\n%{\\color{Gray}{\n \\[\n \\begin{array}{c c c c}\n \\hline \\\\\n \\P(Y=y | Y'=0) & =\\frac{\\P(Y=y,Y'=0)}{\\P(Y'=0)} & =\\frac{\\P(\\{\\omega: Y(\\omega)=y \\  \\cap \\ Y'(\\omega)=0\\})}{\\P(\\{\\omega: Y'(\\omega)=0\\})} & = ? \\\\ \\hline \\\\\n \\\\\n \\P(Y=0 | Y'=0) & \\frac{\\P(Y=0,Y'=0)}{\\P(Y'=0)} & \\frac{\\frac{1}{8}}{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}} & \\frac{1}{7} \\\\\n\\\\\n\\P(Y=1 | Y'=0) & \\frac{\\P(Y=1,Y'=0)}{\\P(Y'=0)} & \\frac{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}}{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}} & \\frac{3}{7} \\\\\n\\\\\n\\P(Y=2 | Y'=0) & \\frac{\\P(Y=2,Y'=0)}{\\P(Y'=0)} & \\frac{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}}{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}} & \\frac{3}{7} \\\\\n\\\\\n\\P(Y=3 | Y'=0) & \\frac{\\P(Y=3,Y'=0)}{\\P(Y'=0)} & \\frac{\\P(\\emptyset)}{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}} & 0 \\\\\n\\\\ \\hline\n\\P(Y \\in \\{0,1,2,3\\} | Y'=0) & \\frac{\\sum_{y=0}^3{\\P(Y=y,Y'=0)}}{\\P(Y'=0)} & \\frac {\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}}{\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}+\\frac{1}{8}} & 1 \\\\ \\hline\n \\end{array}\n \\]\n% }}\n\\item What is $\\P(Y|Y'=1)$ ?\n%{\\color{Gray}{\n \\[\n\\P(Y=y | Y'=1) = \n\\begin{cases}\n1 & \\text{if $y=3$} \\\\\n0 & \\text{otherwise}\n \\end{cases}\n \\]\n %}}\n \\end{enumerate}\n \\end{classwork}\n\n\\subsection{$\\Rz^m$-valued Random Variables}\\label{S:Rm-valuedRVs}\n\n%Extension to multivariate random vectors that are made of more than two RVs is straightforward.  \nConsider the \\rv~ $X$ whose components are the RVs $X_1,X_2,\\ldots,X_m$, i.e., $X := (X_1,X_2,\\ldots,X_m)$, where $m \\geq 2$.  \nA particular realization of this RV is a point $(x_1,x_2,\\ldots,x_m)$ in $\\Rz^m$.  \nNow, let us extend the notions of JCDF, JPMF and JPDF to $\\Rz^m$.  \n\n\\begin{definition}[multivariate JDF]\\label{Df:JmDF}\nThe {\\bf joint distribution function (JDF)} or {\\bf joint cumulative distribution function (JCDF)}, $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m):\\mathbb{R}^m\\to [0,1]$, of the multivariate random vector $(X_1,X_2,\\ldots,X_m)$ is\n\\begin{eqnarray}\\label{E:jmDF}\nF_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m)\\; \n&=& \\P(X\\leq x_1 \\cap X_2 \\leq x_2 \\cap \\cdots \\cap X_m \\leq x_m)\\notag\\\\ \n&=& \\P(X_1\\leq x_1 , X_2 \\leq x_2, \\ldots, X_m \\leq x_m)\\\\\n&=& P\\left( \\{ \\omega: X_1(\\omega) \\leq x_1, X_2(\\omega) \\leq x_2, \\ldots, X_m(\\omega) \\leq x_m \\} \\right), \\notag\n\\end{eqnarray}\nfor any $(x_1,x_2,\\ldots,x_m) \\in \\mathbb{R}^m$, \nwhere the right-hand side represents the probability that the random vector $(X_1,X_2,\\ldots,X_m)$ takes on a value in \n$\\{(x'_1,x'_2,\\ldots,x'_m): x'_1 \\leq x_1, x'_2 \\leq x_2, \\ldots, x'_m \\leq x_m\\}$, the set of points in $\\Rz^m$ that are less than the point $(x_1,x_2,\\ldots,x_m)$ in each coordinate $1,2,\\ldots,m$.\n\\end{definition}\n\nThe JDF $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m):\\Rz^m\\to\\Rz$ satisfies the following conditions to remain a probability: \n\\begin{enumerate}\n\\item $0 \\leq F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) \\leq 1$\n\\item $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m)$ is an increasing function of $x_1$, $x_2$, $\\ldots$ and $x_m$\n\\item $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) \\to 1$ as $x_1\\to \\infty$, $x_2\\to \\infty$, $\\ldots$ and $x_m\\to \\infty$\n\\item $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) \\to 0$ as $x_1\\to -\\infty$, $x_2\\to -\\infty$, $\\ldots$ and $x_m\\to -\\infty$\n\\end{enumerate}\n\n\\begin{definition}[Multivariate JPMF]\nIf $(X_1,X_2,\\ldots,X_m)$ is a {\\bf discrete random vector} that takes values in a discrete support set $\\mathcal{S}_{X_1,X_2,\\ldots,X_m}$, then its \\textbf{joint probability mass function} (or JPMF) is:\n\\begin{equation}\\label{Eq:jmDPMF}\nf_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) = \\P(X_1=x_1,X_2=x_2,\\ldots,X_m=x_m) \\enspace . \n\\end{equation}\n\\end{definition}\nSince $\\P(\\Omega)=1$, $\\sum_{{\\substack{(x_1,x_2,\\ldots,x_m) \\in \\mathcal{S}_{X_1,X_2,\\ldots,X_m}}}}f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m)=1$.\n\nFrom JPMF $f_{X_1,X_2,\\ldots,X_m}$ we can get the JCDF $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m)$ and the probability of any event $B$ by simply taking sums as in Equation~\\eqref{Eq:2DiscretejDFFromjPMF} but now over all $m$ coordinates.\n%\\begin{equation}\\label{Eq:2DiscretejDFFromjPMF}\n%\\boxed{F_{X_1,X_2,\\ldots,X_m}(x,y)\\;=\\;\\sum_{x_i\\leq x, y_j \\leq y}f_{X_1,X_2,\\ldots,X_m}(x_i,y_j) }\\enspace ,\n%\\qquad \\boxed{\\P(B)\\;=\\;\\sum_{\\substack{(x_i, y_j) \\in B \\cap \\mathcal{S}_{X_1,X_2,\\ldots,X_m}}}f_{X_1,X_2,\\ldots,X_m}(x_i,y_j) }\\enspace ,\n%\\end{equation}\n\n\\begin{definition}[Multivariate JPDF]\n$(X_1,X_2,\\ldots,X_m)$ is a {\\bf continuous random vector} if its JDF $F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m)$ is differentiable and the {\\bf joint probability density function (JPDF)} is given by:\n\\[\nf_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) = \\frac{\\partial^m}{\\partial x_1 \\partial x_2 \\cdots \\partial x_m} F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) \\enspace ,\n\\]\n\\end{definition}\n\nFrom JPDF $f_{X_1,X_2,\\ldots,X_m}$ we can compute the JDF $F_{X_1,X_2,\\ldots,X_m}$ at any point $(x_1,x_2,\\ldots,x_m) \\in \\Rz^m$ and more generally we can compute the probability of any event $B$, that can be cast as a region in $\\Rz^m$, by ``simply'' taking $m$-dimensional integrals (you have done such iterated integrals when $m=3$):\n\\begin{equation}\\label{Eq:mContjDFFromjPDF}\n\\boxed{F_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) = \\int_{-\\infty}^{x_m} \\cdots \\int_{-\\infty}^{x_2} \\int_{-\\infty}^{x_1} f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) dx_1 dx_2\\ldots d x_m}\\enspace ,\n\\end{equation}\nand\n\\begin{equation}\\label{Eq:mContProbEventFromjPDF}\n\\boxed{\\P(B)\\;=\\; \\int\\cdots\\int\\int_{B} f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) dx_1 dx_2\\ldots d x_m}\\enspace .\n\\end{equation}\nThe JPDF satisfies the following two properties:\n\\be\n\\item integrates to $1$, i.e., $\\int_{-\\infty}^{\\infty} \\cdots \\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty} f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) dx_1 dx_2\\ldots d x_m=1$\n\\item is a non-negative function, i.e., $f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) \\geq 0$.\n\\ee\n\nThe marginal PDF (marginal PMF) is obtained by integrating (summing) the JPDF (JPMF) over all other random variables.  \nFor example, the marginal PDF of $X_1$ is\n\\[\nf_{X_1}(x_1) =\n\\int_{x_2=-\\infty}^{\\infty}\\cdots \\int_{x_m=-\\infty}^{\\infty} f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m) dx_2\\ldots d x_m \n\\]\n\n\\begin{definition}[Independence of Sequence of RVs]\\label{D:IndRVs}\nA finite or infinite sequence of RVs $X_1,X_2,\\ldots$ is said to be independent or independently distributed if and only if\n\\[\n\\P(X_{i_1} \\leq x_{i_1}, X_{i_2} \\leq x_{i_2}, \\ldots,  X_{i_k} \\leq x_{i_k} ) = \\P(X_{i_1} \\leq x_{i_1}) \\P(X_{i_2} \\leq x_{i_2}) \\cdots,  \\P(X_{i_k} \\leq x_{i_k} )\n\\]\nor equivalently,\n\\[\nF_{X_{i_1},X_{i_2},\\ldots,X_{i_m}}(x_{i_1},x_{i_2},\\ldots,x_{i_m}) = F_{X_{i_1}}(x_{i_1}) F_{X_{i_2}}(x_{i_2}) \\cdots F_{X_{i_m}}(x_{i_m}) \\enspace ,\n\\]\nfor any distinct subset of indices $\\{i_1,i_2,\\ldots,i_m\\}$ of $\\{1,2,\\ldots\\}$, the index set of the sequence of RVs and any sequence of real numbers $x_{i_1},x_{i_2},\\ldots,x_{i_m}$.\n\nBy the above definition, the sequence of {\\bf discrete} RVs $X_1,X_2,\\ldots$ taking values in an at most countable set $\\Dz$ are said to be independently distributed if for any distinct subset of indices $\\{i_1,i_2,\\ldots,i_k\\}$ such that the corresponding RVs $X_{i_1},X_{i_2},\\ldots,X_{i_k}$ exists as a distinct subset of our original sequence of RVs $X_1,X_2,\\ldots$ and for any elements $x_{i_1}, x_{i_2},\\ldots,x_{i_k}$ in $\\Dz$, the following equality is satisfied:\n\\[\n\\P(X_{i_1}= x_{i_1}, X_{i_2} = x_{i_2}, \\ldots,  X_{i_k} = x_{i_k} ) = \\P(X_{i_1} = x_{i_1}) \\P(X_{i_2} = x_{i_2}) \\cdots  \\P(X_{i_k} = x_{i_k}) \\enspace ,\n\\]\nor equivalently,\n\\[\nf_{X_{i_1}, X_{i_2},\\ldots,X_{i_k}} (x_{i_1}, x_{i_2}, \\ldots,  x_{i_k} ) = f_{X_{i_1}} (x_{i_1}) f_{X_{i_2}}(x_{i_2}) \\cdots  f_{X_{i_k}} (x_{i_k}) \\enspace .\n\\]\n\\end{definition}\n\nFrom Definition~\\ref{D:IndRVs}, we say $m$ random variables $X_1,X_2,\\ldots,X_m$ are jointly independent or mutually independent if and only if for every $(x_1,x_2,\\ldots,x_m) \\in \\Rz^m$\n\\begin{eqnarray}\nF_{X_{1},X_{2},\\ldots,X_{m}}(x_{1},x_{2},\\ldots,x_{m}) &=& F_{X_{1}}(x_{1}) F_{X_{2}}(x_{2}) \\cdots F_{X_{m}}(x_{m}) \\enspace ,\\\\\nf_{X_{1},X_{2},\\ldots,X_{m}}(x_{1},x_{2},\\ldots,x_{m}) &=& f_{X_{1}}(x_{1}) f_{X_{2}}(x_{2}) \\cdots f_{X_{m}}(x_{m}) \\enspace .\n\\end{eqnarray}\n\n\\begin{prop}[Conditional probability of independent sequence of RVs]\nFor an independent sequence of RVs $\\{X_1,X_2,\\ldots\\}$, we have\n\\begin{equation}\\label{Eqn:CndProbOfIndepSeqOfRVs}\n\\P(X_{i+1} \\leq x_{i+1} | X_{i} \\leq x_{i}, X_{i-1} \\leq x_{i-1}, \\ldots, X_1 \\leq x_1) =  \\P(X_{i+1} \\leq x_{i+1}) \n\\end{equation}\n\\end{prop}\n\\begin{proof}\n\\begin{eqnarray}\n&&\\P(X_{i+1} \\leq x_{i+1} | X_{i} \\leq x_{i}, X_{i-1} \\leq x_{i-1}, \\ldots, X_1 \\leq x_1) \\notag\\\\\n\\notag \\\\\n&=& \\frac{\\P(X_{i+1} \\leq x_{i+1}, X_{i} \\leq x_{i}, X_{i-1} \\leq x_{i-1}, \\ldots, X_1 \\leq x_1)}{\\P(X_{i} \\leq x_{i}, X_{i-1} \\leq x_{i-1}, \\ldots, X_1 \\leq x_1)} \\notag \\\\\n\\notag \\\\\n&=& \\frac{\\P(X_{i+1} \\leq x_{i+1}) \\P(X_{i} \\leq x_{i}) \\P(X_{i-1} \\leq x_{i-1}) \\cdots \\P(X_1 \\leq x_1)}{\\P(X_{i} \\leq x_{i}) \\P(X_{i-1} \\leq x_{i-1}) \\cdots \\P(X_1 \\leq x_1)} \\notag \\\\\n\\notag \\\\\n&=& \\P(X_{i+1} \\leq x_{i+1}) \\notag \n\\end{eqnarray}\n\\end{proof}\nEquation~\\eqref{Eqn:CndProbOfIndepSeqOfRVs} simply says that the conditional distribution of the RV $X_{i+1}$ given all previous RVs $X_i,X_{i-1},\\ldots,X_1$ is simply determined by the distribution of $X_{i+1}$.\n\n\\begin{example}\\label{EgCovOf2IndepRVs}\nIf $X_1$ and $X_2$ are independent random variables then what is their covariance $\\cv(X_1,X_2)$?\n\n{\\em Solution:}\\\\[4pt]\nWe know for independent RVs from the properties of expectations that\n\\[\nE(X_1X_2) = E(X_1)E(X_2)\n\\]\nFrom the formula for covariance\n\\begin{align*}\n\\cv (X_1,X_2) \n&= E(X_1 X_2)-E(X_1)E(X_2)\\\\\n&= E(X_1) E(X_2)-E(X_1)E(X_2) \\qquad \\text{due to independence}\\\\\n&= 0\n\\end{align*}\n\\end{example}\n\n\\begin{rem}\nThe converse is not true: two random variables that have zero covariance are not necessarily independent.\n\\end{rem}\n\n\\subsubsection{Linear Combination of Independent Normal RVs is a Normal RV}\n\nWe can get the following special property of normal RVs using Eqn.~\\eqref{E:LinCombCF}. \nIf $X_1,X_2,\\ldots,X_m$ be jointly independent RVs, where $X_i$ is $\\normal(\\mu_i,\\sigma_i^2)$, for $i=1,2,\\ldots,m$ \nthen $Y=c+\\sum_{i=1}^m a_i X_i$ for some constants $c,a_1,a_2,\\ldots,a_m$ \nis the $\\normal\\left( c+\\sum_{i=1}^m a_i \\mu_i, \\sum_{i=1}^m a_i^2 \\sigma_i^2 \\right)$ RV.\n\n\\begin{example}\\label{EgLinCombOfNormals}\nLet $X$ be $\\normal(2,4)$, $Y$ be $\\normal(-1,2)$ and $Z$ be $\\normal(0,1)$ RVs that are jointly independent.  \nObtain the following:\n\\be\n\\item $E(3X-2Y+4Z)$\n\\item $V(2Y-3Z)$\n\\item the distribution of $6-2Z+X-Y$\n\\item the probability that $6-2Z+X-Y>0$\n\\item $\\cv(X,W)$, where $W=X-Y$.\n\\ee\n\n{\\em Solution}\\\\[4pt]\n\\be\n\\item\n\\[\nE(3X-2Y+4Z) = 3E(X)-2E(Y)+4(Z) = (3 \\times 2) + (-2 \\times (-1)) + 4 \\times 0 = 6 +2 +0 = 8\n\\]\n\\item\n\\[\nV(2Y-3Z) = 2^2V(Y) + (-3)^2V(Z) = (4 \\times 2) + (9 \\times 1) = 8 + 9 = 17 \n\\]\n\\item\nFrom the special property of normal RVs, the distribution of $6-2Z+X-Y$ is\n\\begin{align*}\n&~ \\normal\\left( 6+(-2 \\times 0)+(1 \\times 2)+(-1 \\times -1), ((-2)^2 \\times 1) + (1^2 \\times 4) + ((-1)^2 \\times 2)  \\right)\\\\\n&= \\normal\\left( 6+0+2+1, 4 + 4 +  2  \\right)\\\\\n&= \\normal(9,10)\n\\end{align*}\n\\item \nLet $U=6-2Z+X-Y$ and we know $U$ is $\\normal(9,10)$ RV.\n\\begin{align*}\nP(6-2Z+X-Y>0) \n&= P(U>0) = P(U-9>0-9) = P\\left( \\frac{U-9}{\\sqrt{10}} > \\frac{-9}{\\sqrt{10}} \\right)\\\\\n&= P\\left( Z > \\frac{-9}{\\sqrt{10}} \\right)\\\\ \n&= P\\left( Z < \\frac{9}{\\sqrt{10}} \\right) \\\\\n&\\approxeq P(Z < 2.85) = 0.9978\n\\end{align*}\n\\item\n\\begin{align*}\n\\cv(X,W) \n&= E(XW)-E(X)E(W) = E(X(X-Y))-E(X)E(X-Y)\\\\\n&= E(X^2-XY)-E(X)(E(X)-E(Y)) = E(X^2)-E(XY)-2\\times(2-(-1)) \\\\\n&= E(X^2)-E(X)E(Y)-6 = E(X^2)-(2 \\times (-1))-6\\\\\n&= (V(X)+(E(X))^2) +2-6 = (4+2^2)-4=4\n\\end{align*}\n\\ee\n\\end{example}\n\n\n\\subsection{Some Common $\\Rz^m$-valued RVs}\\label{S:SomeCommonRmValuedRVs} \n\n\nSo far, we have treated our random vectors as random points in $\\Rz^m$ and not been explicit about whether they are row or column vectors.  \nWe need to be more explicit now in order to perform arithmetic operations and transformations with them.\n\nLet $X=(X_1,X_2,\\ldots,X_{m_X})$ be a \\rv~in $\\Rz^{1 \\times m_X}$, i.e., $X$ is a random row vector with $1$ row and $m_X$ columns, with JCDF $F_{X_1,X_2,\\ldots,X_{m_X}}$ and JPDF $f_{X_1,X_2,\\ldots,X_{m_X}}$.  \nSimilarly, let $Y=(Y_1,Y_2,\\ldots,Y_{m_Y})$ be a \\rv~in $\\Rz^{1 \\times m_Y}$, i.e., $Y$ is a random row vector with $1$ row and $m_Y$ columns, with JCDF $F_{Y_1,Y_2,\\ldots,Y_{m_Y}}$ and JPDF $f_{Y_1,Y_2,\\ldots,Y_{m_Y}}$.\nLet the JCDF of the random vectors $X$ and $Y$ together be $F_{X_1,X_2,\\ldots,X_{m_X},Y_1,Y_2,\\ldots,Y_{m_Y}}$ and JPDF be $f_{X_1,X_2,\\ldots,X_{m_X},Y_1,Y_2,\\ldots,Y_{m_Y}}$.  \n\n\\subsubsection{Independent Random Vectors and their sums}\nThe notion of mutual independence or joint independence of $n$ random vectors is obtained similarly from ensuring the independence of any subset of the $n$ vectors in terms of their JCDFs (JPMFs or JPDFs) being equal to the product of their marginal CDFs (PMFs or PDFs). \n\nThus, for a given $m_X <\\infty$ and $m_Y < \\infty$, two {\\bf random vectors are independent} if and only if for any $(x_1,x_2,\\ldots,x_{m_X}) \\in \\Rz^{1 \\times m_X}$ and any $(y_1,y_2,\\ldots,y_{m_Y}) \\in \\Rz^{1 \\times m_Y}$\n\\begin{multline*}\nF_{X_1,X_2,\\ldots,X_{m_X},Y_1,Y_2,\\ldots,Y_{m_Y}}(x_1,x_2,\\ldots,x_{m_X},y_1,y_2,\\ldots,y_{m_Y})\\\\\n= F_{X_1,X_2,\\ldots,X_{m_X}}(x_1,x_2,\\ldots,x_{m_X}) \\times F_{Y_1,Y_2,\\ldots,Y_{m_Y}}(y_1,y_2,\\ldots,y_{m_Y})\n\\end{multline*}\nor, equivalently\n\\begin{multline*}\nf_{X_1,X_2,\\ldots,X_{m_X},Y_1,Y_2,\\ldots,Y_{m_Y}}(x_1,x_2,\\ldots,x_{m_X},y_1,y_2,\\ldots,y_{m_Y})\\\\\n= f_{X_1,X_2,\\ldots,X_{m_X}}(x_1,x_2,\\ldots,x_{m_X}) \\times f_{Y_1,Y_2,\\ldots,Y_{m_Y}}(y_1,y_2,\\ldots,y_{m_Y})\n\\end{multline*}\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)$.\nWe introduce a useful function called the indicator function of a set, say $A$.\n\\[\n\\BB{1}_A(x) = \n\\begin{cases}\n1 & \\text{ if } x \\in A\\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\n$\\BB{1}_A(x)$ returns $1$ if $x$ belongs to $A$ and $0$ otherwise.\n\n\\begin{example}\\label{EgVectorArithmetic}\nLet us recall the geometry and arithmetic of vector addition in the plane.  \n\\be\n\\item What is $(1,0)+(1,0)$, $(1,0)+(0,1)$, $(0,1)+(0,1)$?  \n\\item What is the relationship between $(1,0)$, $(0,1)$ and $(1,1)$ geometrically? \n\\item How does the diagonal of the parallelogram relate the its two sides in the geometry of addition in the plane?  \n\\item What is  $(1,0)+(0,1)+(1,0)$?\n\\ee\n\n{\\em Solution:}\\\\[4pt]\n\\be\n\\item addition is component-wise\n\\begin{align*}\n(1,0)+(1,0) &= (1+1,0+0) = (2,0)\\\\\n(1,0)+(0,1) &= (1+0,0+1) = (1,1)\\\\\n(0,1)+(0,1) &= (0+0,1+1)=(0,2)\n\\end{align*}\n\\item $(1,0)$ and $(0,1)$ are vectors for the two sides of unit square and $(1,1)$ is its diagonal.\n\\vspace{3cm}\n\\item Generally, the diagonal of the parallelogram is the resultant or sum of the vectors representing its two sides\n\\vspace{3cm}\n\\item\n\\[\n(1,0)+(0,1)+(1,0)=(1+0+1,0+1+0) = (2,1)\n\\] \n\\ee\n\\end{example}\n\n\n\\begin{model}[$\\bernoulli(\\theta)$ \\rv]\\label{M:BernoulliTheraRandomVector}\nGiven a parameter $(\\theta, 1-\\theta) \\in \\Delta^1$, the unit 1-Simplex, 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 realization $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{example}\\label{EgExpectationOfBernoulliRVector}\nLet us find the Expectation of $\\bernoulli(\\theta)$ \\rv in Model~\\ref{M:BernoulliTheraRandomVector}.\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\\end{example}\n%How 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\n\n\\begin{rem}\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\\end{rem}\n\n\\begin{Exercise}[title={Random walk in the first Quadrant},label={xRWsinIQ}]\nConsider an independent and identical random walk starting from $(0,0)$ in the first quadrant where you go east, \ni.e., add $(1,0)$ to your current position with probability $\\theta$, and go north, i.e., add $(0,1)$ to your current position with probability $1-\\theta$. \nSuppose you take $n$ such IID steps according to the $\\bernoulli(\\theta)$ \\rv.  \nAnswer the following questions:\n\\begin{enumerate}\n\\item How does the number of paths that lead to a $(x_1,x_2)$ with $x_1+x_2=n$ relate to the binomial coefficient $\\binom{n}{x_1}$? \n\\item What is the probability of taking $x_1$ steps east and $x_2$ steps north?\n\\end{enumerate}\n\\end{Exercise}\n\n\\begin{Answer}\n\\bit\n\\item The number of paths that lead to a $(x_1,x_2)$ with $x_1+x_2=n$ is equal to $\\binom{n}{x_1}$. We have already seen this as random walks in Manhatta. \n\\item $\\binom{n}{x_1} \\theta^{x_1}(1-\\theta)^{x_2}$\n\\eit\n\\end{Answer}\n\n\\begin{Exercise}[title={Random walks in  the first Quadrant and Galton's Quincunx},label={xRWsinIQAndQunicux}]\nCompare the probability models for the Random walk in the first quadrant and Galton's Quincunx and explain how they are related.\n\\end{Exercise}\n\\begin{Answer}\nThe probability of going east or north in the first quadrant (idealized Manhattan with streets and avenues) is the same as a ball falling left or right in the Galton's Quincunx. \nThe buckets that collect the balls after dropping through $n$ levels of nails are labelled by the number of right turns as $0, 1, \\ldots, n$ when modelled by a $\\binomial(n,\\theta)$, and this is analogous to the number of steps taken north in the random walk case.\n\\end{Answer}\n\n\\begin{labwork}[Quincunx Sampler Demo -- Sum of $n$ IID $\\bernoulli(1/2)$ \\rv{s}]\\label{LW:QuincunxSampler}\n{\\rm Let 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}\n}\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Visual Cognitive Tool GUI: Quincunx \\& Septcunx.\\label{F:guiMultinomialQuincunx}}\n\\centering   \\makebox{\\includegraphics[width=3.00in]{figures/guiMultinomialQuincunx}}\n\\centering   \\makebox{\\includegraphics[width=3.00in]{figures/guiMultinomialSeptcunx}}\n\\end{figure}\n%}%end remove\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 PMF 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\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 by extending $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV taking values in $\\{1,2,\\ldots,k\\}$ of Model~\\ref{M:demoivre} to its vector-valued cousin taking values in $\\{e_1, e_2,\\ldots,e_k\\}$, the ortho-normal basis vectors in $\\Rz^k$.\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_2 & \\text{if} \\quad x=e_2:=(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 realizations\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\nWe can visualize 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 visualize 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\\begin{labwork}[Septcunx Sampler Demo -- Sum of n IID $\\demoivre(1/3,1/3,1/3)$ \\rv{s}]\\label{LW:SeptcunxSampler}\n{\\rm\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}\n}\n\\end{labwork}\n\nMultinomial distributions are at the very foundations of various machine learning algorithms, including, filtering junk email, learning from large knowledge-based resources like www, Wikipedia, word-net, etc.\n\n\n\\begin{model}[$\\normal(\\mu,\\Sigma)$ \\rv]\\label{M:MultivariateNormal}\nThe univariate $\\normal(\\mu,\\sigma^2)$ RV has two parameters, $\\mu \\in \\Rz$ and $\\sigma^2 \\in (0,\\infty)$.  \nIn the multivariate version $\\mu \\in \\Rz^{m \\times 1}$ is a column vector and $\\sigma^2$ is replaced by a matrix $\\Sigma$.  To begin, let\n\\[\nZ = \n\\left( \n\\begin{array}{c}\nZ_1 \\\\\nZ_2 \\\\\n\\vdots \\\\\nZ_m \n\\end{array} \n\\right)\n\\]\nwhere, $Z_1,Z_2,\\ldots,Z_m$ are jointly independent $\\normal(0,1)$ RVs.  Then the JPDF of $Z$ is\n\\[\nf_Z(z) = f_{Z_1,Z_2,\\ldots,Z_m}(z_1,z_2,\\ldots,z_m) = \\frac{1}{(2 \\pi)^{m/2}} \\exp \\left( -\\frac{1}{2} \\sum_{j=1}^m z_j^2 \\right) = \\frac{1}{(2 \\pi)^{m/2}} \\exp \\left( -\\frac{1}{2} z^T z \\right)\n\\]\nWe say that $Z$ has a standard multivariate normal distribution and write $Z \\sim \\normal(0,I)$, where it is understood that $0$ represents the vector of $m$ zeros and $I$ is the $m \\times m$ identity matrix (with $1$ along the diagonal entries and $0$ on all off-diagonal entries).\n\nMore generally, a vector $X$ has a multivariate normal distribution denoted by $X \\sim \\normal(\\mu,\\Sigma)$, if it has joint probability density function\n\\[\nf_X(x;\\mu,\\Sigma) = f_{X_1,X_2,\\ldots,X_m}(x_1,x_2,\\ldots,x_m; \\mu,\\Sigma) \n= \\frac{1}{(2 \\pi)^{m/2} |(\\Sigma)|^{1/2}} \\exp \\left( -\\frac{1}{2} (x - \\mu)^T \\Sigma^{-1} (x - \\mu )\\right) \n\\]\nwhere $|\\Sigma|$ denotes the determinant of $\\Sigma$, $\\mu$ is a vector of length $m$ and $\\Sigma$ is a $m \\times m$ symmetric, positive definite matrix.  Setting $\\mu=0$ and $\\Sigma=I$ gives back the standard multivariate normal \\rv.\n\\end{model}\n\n\n\n%bivariate Normal\n\n\\begin{figure}[htpb]\n\\caption{JPDF, Marginal PDFs and Frequency Histogram of Bivariate Standard Normal \\rv.\\label{F:BivariateStdNormalJPDFMPDFsFreHist}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/BivariateStdNormalJPDFMPDFsFreHist.eps}}\n\\end{figure}\n\nWhen we have a non-zero mean vector \n$$\\mu=\\begin{pmatrix} \\mu_X\\\\ \\mu_Y \\end{pmatrix} =\\begin{pmatrix} 6.49\\\\ 5.07 \\end{pmatrix}$$ \nfor the mean lengths and girths of cylindrical shafts from a manufacturing process with  \nvariance-covariance matrix \n$$\\Sigma = \\begin{pmatrix} \\cv(X,X) & \\cv(X,Y)\\\\ \\cv(Y,X) & \\cv(Y,Y)\\end{pmatrix} = \\begin{pmatrix} V(X) & \\cv(X,Y)\\\\ \\cv(X,Y) & V(Y)\\end{pmatrix} = \\begin{pmatrix} 0.59 & 0.24\\\\ 0.24 & 0.26 \\end{pmatrix}$$\nthen the $\\normal(\\mu,\\Sigma)$ \\rv~has JPDF, marginal PDFs and samples with frequency histograms as shown in Figure~\\ref{F:BivariateShaftsNormalJPDFMPDFsFreHist}.\n\nWe can use \\Matlab to compute for instance the probability that a cylinder has length and girth below $6.0$ cms as follows:\n\\begin{VrbM}\n>> mvncdf([6.0 6.0],[6.49 5.07],[0.59  0.24; 0.24 0.26])\nans =    0.2615\n\\end{VrbM}\nOr find the probability (with numerical error tolerance) that the cylinders are within the rectangular specifications of $6\\pm1.0$ along $x$ and $y$ as follows:\n\\begin{VrbM}\n>> [F err] = mvncdf([5.0 5.0], [7.0 7.0], [6.49 5.07],[0.59  0.24; 0.24 0.26])\n\nF =    0.3352\n\nerr =   1.0000e-08\n\\end{VrbM}\n\n\n\\begin{figure}[htpb]\n\\caption{JPDF, Marginal PDFs and Frequency Histogram of a Bivariate Normal \\rv~for lengths of girths of cylindrical shafts in a manufacturing process (in cm).\\label{F:BivariateShaftsNormalJPDFMPDFsFreHist}}\n\\centering   \\makebox{\\includegraphics[width=6.50in]{figures/BivariateShaftsNormalJPDFMPDFsFreHist.eps}}\n\\end{figure}\n\n\\remove{\n\\iftoggle{PlaceTutsHere}{%\n\\subsection{Tutorial Exercises}\n\\input{Tutorials/Tut_RandVecs_preps.tex}\n~\\\\\n\\input{Tutorials/Tut_RandVecs_inTut.tex}\n}{%\n  % don't do anything otherwise\n}\n\n}%remove\n\n\n\\subsection{Dependent Random Variables}\nWhen a sequence of RVs are not independent they are said to be {\\bf dependent}.  \nThe simplest form of dependence is {\\em Markov dependence} that we will briefly see via a couple examples in Chapter~\\ref{C:FiniteMarkovChains}.\n\n\\input{ExsInMultivariateRVs.tex}\n\n\\newpage\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Characteristic Functions}\\label{S:CF}\nThe characteristic function (CF) of a random variable gives another way to specify its distribution. \nThus CF is a powerful tool for analytical results involving random variables\n(\\href{http://en.wikipedia.org/wiki/Characteristic_function_(probability_theory)}{more}).\n\n\\begin{definition}[Characteristic Function (CF)]\nLet $X$ be a RV and $\\imath=\\sqrt{-1}$. The function $\\cf_X(t) : \\Rz \\to \\Cz$ defined by\n\\begin{equation}\\label{E:CF}\n\\boxed{\n\\cf_X(t) := E \\left( \\exp \\left( \\imath t X\\right) \\right) = \n\\begin{cases}\n\\sum_{x} \\exp \\left( \\imath t x\\right) f_X(x) & \\text{ if $X$ is discrete RV}\\\\\n\\int_{-\\infty}^{\\infty} \\exp \\left( \\imath t x\\right) f_X(x) dx & \\text{ if $X$ is continuous RV}\n\\end{cases}\n}\n\\end{equation}\nis called the {\\bf characteristic function} of $X$.\n\\end{definition}\n\nNOTE: \n$\\cf_X(t)$ exists for any $t \\in \\Rz$, because\n\\begin{align*}\n\\cf_X(t) \n&= E \\left( \\exp \\left( \\imath t X\\right) \\right) \\\\\n&= E \\left( \\cos(tX)+ \\imath \\sin(tX) \\right)\\\\\n&= E \\left( \\cos(tX) \\right) + \\imath E \\left(\\sin(tX) \\right)\n\\end{align*}\nand the last two expected values are well-defined, because the sine and cosine functions are bounded by $[-1,1]$.\n\nFor a continuous RV, $\\int_{-\\infty}^{\\infty} \\exp \\left(- \\imath t x\\right) f_X(x) dx$ is called the {\\em Fourier transform} of $f_X$.  \nThis is the CF but with $t$ replaced by $-t$.  \nYou will also encounter Fourier transforms when solving differential equations.\n\n\\subsection{Obtaining Moments from Characteristic Function}\n\nRecall that the $k$-th moment of $X$ is $E(X^k)$ for any $k \\in \\Nz:=\\{1,2,3,\\ldots\\}$ is\n\\begin{framed}\n%\\Df{\\label{Df:KthMoment} % TODO make this a definition proper\n\\[\nE(X^k)\\; =\\;\n\\begin{cases}\n\\displaystyle \\sum_x x^k f_X(x) & \\text{if $X$ is a discrete RV}\\\\[12pt]\n\\displaystyle \\int_{-\\infty}^{\\infty} x^2 f_X(x) dx & \\text{if $X$ is a continuous RV}\n\\end{cases}\n\\]\n%}\n\\end{framed}\n\nThe characteristic function can be used to derive the moments of $X$ due to the following nice relationship between the the $k$-th moment of $X$ and the $k$-th derivative of the CF of $X$.\n\n\\begin{framed}\n\\begin{prop}[Moment \\& CF.]\nLet $X$ be a random variable and $\\cf_X(t)$ be its CF.  \nIf $E(X^k)$ exists and is finite, then $\\cf_X(t)$ is $k$ times continuously differentiable and\n\\begin{equation*}\nE(X^k) = \\frac{1}{\\imath^k} \\left[\\frac{d^k \\cf_X(t)}{dt^k}\\right]_{t=0} \\enspace .\n\\end{equation*}\nwhere $\\left[\\frac{d^k \\cf_X(t)}{dt^k}\\right]_{t=0}$ is the $k$-th derivative of $\\cf_X(t)$ with respect to $t$, evaluated at the point $t=0$.\n\\end{prop}\n\\end{framed}\n\n\\begin{proof}\nThe proper proof is very messy so we just give a sketch of the ideas in the proof.  \nDue to the linearity of the expectation (integral) and the derivative operators, we can change the order of operations:\n\\begin{align*}\n\\frac{d^k \\cf_X(t)}{dt^k}\n&= \\frac{d^k}{dt^k} E(\\exp(\\imath t X))\n= E \\left( \\frac{d^k}{dt^k} \\exp(\\imath t X) \\right)\n= E \\left( (\\imath X)^k \\exp(\\imath t X) \\right)\n= \\imath^k E \\left( X^k \\exp(\\imath t X) \\right)\n\\end{align*}\nThe RHS evaluated at $t=0$ is\n\\[\n\\left[ \\frac{d^k \\cf_X(t)}{dt^k} \\right]_{t=0}\n= \\left[ \\imath^k E \\left( X^k \\exp(\\imath t X) \\right) \\right]_{t=0} \n= \\imath^k E \\left( X^k \\right)\n\\]\nThis completes the sketch of the proof.\n\\end{proof}\n\nThe above Theorem gives us the relationship between the moments and the derivatives of the CF if we already know that the moment exists.  \nWhen one wants to compute a moment of a random variable, what we need is the following Theorem.\n\n\\begin{framed}\n\\begin{prop}[{\\bf Moments from CF.}]\nLet $X$ be a random variable and $\\cf_X(t)$ be its CF.  \nIf $\\cf_X(t)$ is $k$ times differentiable at the point $t=0$, then\n\\be\n\\item if $k$ is even, the $n$-th moment of $X$ exists and is finite for any $0 \\leq n \\leq k$;\n\\item if $k$ is odd, the $n$-th moment of $X$ exists and is finite for any $0 \\leq n \\leq k-1$.\n\\ee\nIn both cases,\n\\begin{equation}\\label{E:CFToMoments}\nE(X^k) = \\frac{1}{\\imath^k} \\left[\\frac{d^k \\cf_X(t)}{dt^k}\\right]_{t=0} \\enspace .\n\\end{equation}\nwhere $\\left[\\frac{d^k \\cf_X(t)}{dt^k}\\right]_{t=0}$ is the $k$-th derivative of $\\cf_X(t)$ with respect to $t$, evaluated at the point $t=0$.\n\\end{prop}\n\\end{framed}\n\n\\begin{proof}\nFor proof see e.g., Ushakov, N. G. (1999) Selected topics in characteristic functions, VSP (p.~39).\n\\end{proof}\n\n\n\\begin{example}\\label{EgCFOfBernoulli}\nLet $X$ be the $\\bernoulli(\\theta)$ RV.  \nFind the CF of $X$.   \nThen use CF to find $E(X)$, $E(X^2)$ and from this obtain the variance $V(X) = E(X^2)-(E(X))^2$.\n\nSolution: \n\n{\\bf Part 1}\n\nRecall the PMF for this discrete RV with parameter $\\theta \\in (0,1)$ is\n\\[\nf_X(x;\\theta) = \n\\begin{cases}\n\\theta & \\text{ if } x = 1\\\\\n1-\\theta & \\text{ if } x = 0\\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\nLet's first find the CF of $X$\n\\begin{align*}\n\\cf_X(t)\n&= E \\left( \\exp(\\imath t X) \\right) \n= \\sum_x  \\exp(\\imath t x) f_X(x;\\theta) \\qquad \\text{By Defn.~in Equation~\\eqref{E:CF}}\\\\\n&= \\exp(\\imath t \\times 0) (1-\\theta) + \\exp(\\imath t \\times 1) \\theta \n= \\exp(0) (1-\\theta) + \\exp(\\imath t) \\theta \n=  1-\\theta + \\theta \\exp(\\imath t)  \n\\end{align*}\n\n{\\bf Part 2:}\n\nLet's differentiate CF \n\\begin{align*}\n\\frac{d}{dt}\\cf_X(t)\n&= \\frac{d}{dt}\\left(1-\\theta + \\theta e^{\\imath t} \\right) \n=  \\theta \\imath \\exp(\\imath t)\n\\end{align*}\n\nWe get $E(X)$ by evaluating $\\frac{d}{dt}\\cf_X(t)$ at $t=0$ and dividing by $\\imath$ according to Equation~\\eqref{E:CFToMoments} as follows:\n\\begin{align*}\nE(X)\n&= \\frac{1}{\\imath} \\left[ \\frac{d}{dt}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath} \\left[ \\theta \\imath \\exp(\\imath t) \\right]_{t=0} \n= \\frac{1}{\\imath} \\left( \\theta \\imath \\exp(\\imath 0) \\right) \n=  \\theta \\enspace.\n\\end{align*}\nSimilarly from Equation~\\eqref{E:CFToMoments} we can get $E(X^2)$ as follows:\n\\begin{align*}\nE(X^2)\n&= \\frac{1}{\\imath^2} \\left[ \\frac{d^2}{dt^2}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\frac{d}{dt} \\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\theta \\imath \\exp(\\imath t) \\right]_{t=0}\\\\ \n&= \\frac{1}{\\imath^2} \\left[ \\theta \\imath^2 \\exp(\\imath t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left( \\theta \\imath^2 \\exp(\\imath 0) \\right) \n=  \\theta \\enspace.\n\\end{align*}\nFinally, from the first and second moments we can get the variance as follows:\n\\[\nV(X) = E(X^2) - (E(X))^2 = \\theta - \\theta^2 = \\theta(1-\\theta) \\enspace .\n\\]\nLet's check that this is what we have as variance for the $\\bernoulli(\\theta)$ RV if we directly computed it using weighted sums in the definition of expectations: $E(X)=1 \\times \\theta + 0 \\times (1-\\theta)=\\theta$, $E(X^2) = 1^2 \\times \\theta + 0^2 \\times (1-\\theta)=\\theta$and thus giving the same $V(X) = E(X^2) - (E(X))^2 = \\theta - \\theta^2 = \\theta(1-\\theta)$.\n\\end{example}\n\n\\begin{example}\\label{EgCFOfExponential}\nLet $X$ be an $\\exponential(\\lambda)$ RV. \nFirst show that its CF is $\\lambda/(\\lambda- \\imath t)$.  \nThen use CF to find $E(X)$, $E(X^2)$ and from this obtain the variance $V(X) = E(X^2)-(E(X))^2$.\n\nSolution:\n\nRecall that the PDF of an $\\exponential(\\lambda)$ RV for a given parameter $\\lambda \\in (0,\\infty)$ is $\\lambda e^{-\\lambda x}$ if $x \\in [0, \\infty)$ and $0$ if $x \\notin [0, \\infty)$.\n\n{\\bf Part 1:} Find the CF.\n\nWe will use the fact that \n$$\\int_0^{\\infty} \\alpha e^{-\\alpha x} dx = \\left[ -e^{-\\alpha x} \\right]_0^{\\infty} = 1$$\n\n\\begin{align*}\n\\cf_X(t)\n&= E(\\exp(\\imath X t))\n= E\\left( e^{\\imath X t} \\right)\n= \\int_{-\\infty}^{\\infty} e^{\\imath x t} \\lambda e^{-\\lambda x} dx\n= \\lambda  \\int_{0}^{\\infty} e^{-(\\lambda-\\imath t) x} dx\\\\\n&= \\frac{\\lambda}{\\lambda-\\imath t}  \\int_{0}^{\\infty} (\\lambda-\\imath t) e^{-(\\lambda-\\imath t) x} dx\n= \\frac{\\lambda}{\\lambda-\\imath t}  \\int_{0}^{\\infty} \\alpha e^{-\\alpha x} dx\n= \\frac{\\lambda}{\\lambda-\\imath t} \\enspace, \n\\end{align*}\nwhere $\\alpha = \\lambda-\\imath t$ with $\\lambda > 0$.\n\nAlternatively, you can use $e^{\\imath t x} = \\cos(tx)+\\imath \\sin(tx)$ and do integration by parts to arrive at the same answer starting from:\n\\begin{align*}\n\\cf_X(t)\n&= \\int_{-\\infty}^{\\infty} e^{\\imath x t} \\lambda e^{-\\lambda x} dx\n= \\int_{-\\infty}^{\\infty} \\cos(t x) e^{-\\lambda x} dx + \\imath \\int_{-\\infty}^{\\infty} \\sin(t x) e^{-\\lambda x} dx\n\\vdots \n= \\frac{\\lambda}{\\lambda-\\imath t} \\enspace .\n\\end{align*}\n\n{\\bf Part 2:}\n\nLet us differentiate the CF to get moments using Equation~\\eqref{E:CFToMoments} (CF has to be once and twice differentiable at $t=0$ to get the first and second moments).\n\\begin{align*}\n\\frac{d}{dt}\\cf_X(t)\n&= \\frac{d}{dt}\\left( \\frac{\\lambda}{\\lambda-\\imath t} \\right) \n= \\lambda \\left( -1 \\times (\\lambda-\\imath t)^{-2} \\times \\frac{d}{dt} (\\lambda-\\imath t) \\right) \\\\\n&= \\lambda \\left( \\frac{-1}{(\\lambda-\\imath t)^{2}} \\times (-\\imath ) \\right) \n= \\frac{\\lambda \\imath}{(\\lambda-\\imath t)^{2}} \n\\end{align*}\n\nWe get $E(X)$ by evaluating $\\frac{d}{dt}\\cf_X(t)$ at $t=0$ and dividing by $\\imath$ according to Equation~\\eqref{E:CFToMoments} as follows:\n\\begin{align*}\nE(X)\n&= \\frac{1}{\\imath} \\left[ \\frac{d}{dt}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath} \\left[ \\frac{\\lambda \\imath}{(\\lambda-\\imath t)^{2}} \\right]_{t=0} \n= \\frac{1}{\\imath} \\left( \\frac{\\lambda \\imath}{\\lambda^{2}} \\right) \n= \\frac{1}{\\imath} \\left( \\frac{\\imath}{\\lambda} \\right) \n=  \\frac{1}{\\lambda} \n\\end{align*}\n\nLet's pause and see if this makes sense.... Yes, because the expected value of $\\exponential(\\lambda)$ RV is indeed $1/\\lambda$ (recall from when we introduced this RV).\n\nSimilarly from Equation~\\eqref{E:CFToMoments} we can get $E(X^2)$ as follows:\n\\begin{align*}\nE(X^2)\n&= \\frac{1}{\\imath^2} \\left[ \\frac{d^2}{dt^2}\\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\frac{d}{dt} \\cf_X(t) \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\frac{d}{dt} \\frac{\\lambda \\imath}{(\\lambda-\\imath t)^{2}} \\right]_{t=0} \\\\\n&= \\frac{1}{\\imath^2} \\left[ \\lambda \\imath \\times \\frac{d}{dt} {(\\lambda-\\imath t)^{-2}} \\right]_{t=0} \n= \\frac{1}{\\imath^2} \\left[ \\lambda \\imath \\left( -2(\\lambda-\\imath t)^{-3} \\frac{d}{dt} {(\\lambda-\\imath t)} \\right) \\right]_{t=0}\\\\ \n&= \\frac{1}{\\imath^2} \\left[ \\lambda \\imath \\left( -2(\\lambda-\\imath t)^{-3} \\times (-\\imath ) \\right) \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left[ \\frac{2 \\lambda \\imath^2}{(\\lambda-\\imath t)^{3}} \\right]_{t=0}\n= \\frac{1}{\\imath^2} \\left( \\frac{2 \\lambda \\imath^2}{\\lambda^{3}} \\right) \n=  \\frac{2}{\\lambda^{2}}\\enspace.\n\\end{align*}\nFinally, from the first and second moments we can get the variance as follows:\n\\[\nV(X) = E(X^2) - (E(X))^2 = \\frac{2}{\\lambda^2} - \\left(\\frac{1}{\\lambda}\\right)^2  = \\frac{2}{\\lambda^2} - \\frac{1}{\\lambda^2} = \\frac{2-1}{\\lambda^2} = \\frac{1}{\\lambda^2}   \\enspace .\n\\]\n%\\vspace{3cm}\n\nLet's check that this is what we had as variance for the $\\exponential(\\lambda)$ RV when we first introduced it and directly computed using integrals for definition of expectation.\n\\end{example}\n\nCharacteristic functions can be used to characterize the distribution of a random variable.\n\nTwo RVs $X$ and $Y$ have the same DFs , i.e., $F_X(x) = F_Y(x)$ for all $x \\in \\Rz$, if and only if they have the same characteristic functions, i.e. $\\cf_X(t) = \\cf_Y(t)$ for all $t \\in \\Rz$ (for proof see Resnick, S. I. (1999) A Probability Path, Birkhauser). \n\nThus, if we can show that two RVs have the same CF then we know they are the same.  This can be much more challenging or impossible to do directly with their DFs.\n\nLet $Z$ be $\\normal(0,1)$, the standard normal RV.\nWe can find the CF for $Z$ using couple of tricks as follows\n\\begin{align*}\n\\cf_Z(t)\n&= E\\left(e^{\\imath t Z} \\right)\\\\\n&= \\int_{-\\infty}^{\\infty} e^{\\imath t z} f_Z(z) dz = \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{\\imath t z} e^{-z^2/2} dz = \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{\\imath t z -z^2/2} dz \\\\\n&= \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{-(t^2 + (z - \\imath t)^2)/2} dz = e^{-t^2/2} \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{ -(z - \\imath t)^2/2} dz \\\\\n&= e^{-t^2/2} \\frac{1}{\\sqrt{2 \\pi}} \\int_{-\\infty}^{\\infty} e^{ -y^2/2} dy  \\qquad \\text{substituting $y=z-\\imath t, dy=dz$}\\\\\n&= e^{-t^2/2} \\frac{1}{\\sqrt{2 \\pi}} \\sqrt{2 \\pi}  \\qquad \\text{using the normalizing constant in PDF of $\\normal(0,1)$ RV}\\\\\n&= e^{-t^2/2}\n\\end{align*}\n\nThus the CF of the standard normal RV $Z$ is\n\\begin{equation}\\label{E:cfStandardNormal}\n\\boxed{\n\\cf_Z(t) = e^{-t^2/2}\n}\n\\end{equation}\n\n\nLet $X$ be a RV with CF $\\cf_X(t)$.  Let $Y$ be a linear transformation of $X$\n\\[\nY= a + bX\n\\]\nwhere $a$ and $b$ are two constant real numbers and $b \\neq 0$.  \nThen the CF of $Y$ is\n\\begin{equation}\\label{E:cfofLinearTransformation}\n\\boxed{\n\\cf_Y(t) = \\exp(\\imath a t) \\cf_X(b t)\n}\n\\end{equation}\n\n\\begin{proof}\nThis is easy to prove using the definition of CF as follows:\n\\begin{align*}\n\\cf_Y(t)\n&= E\\left(\\exp(\\imath t Y) \\right)\n= E\\left(\\exp(\\imath t (a + bX) ) \\right)\n= E\\left(\\exp(\\imath t a + \\imath t b X) \\right)\\\\\n&= E\\left(\\exp(\\imath t a) \\exp(\\imath t b X) \\right)\n= \\exp(\\imath t a) E\\left( \\exp(\\imath t b X) \\right)\n= \\exp(\\imath t a) \\cf_X(b t)\n\\end{align*}\n\\end{proof}\n\n\\begin{example}\\label{EgCFOfNormalMuSigma}\nLet $Y$ be a $\\normal(\\mu,\\sigma^2)$ RV.  \nRecall that $Y$ is a linear transformation of $Z$, i.e., $Y = \\mu + \\sigma Z$ where $Z$ is a $\\normal(0,1)$ RV.  \nUsing Equations~\\eqref{E:cfStandardNormal} and \\eqref{E:cfofLinearTransformation} find the CF of $Y$.\n\nSolution:\n\n\\begin{align*}\n\\cf_Y(t) \n& = \\exp(\\imath \\mu t) \\cf_Z(\\sigma t), \\qquad \\text{ since $Y = \\mu + \\sigma Z$}\\\\\n& = e^{\\imath \\mu t} e^{(-\\sigma^2 t^2)/2}, \\qquad \\text{ since $\\cf_Z(t)=e^{-t^2/2}$}\\\\\n& = e^{\\imath \\mu t - (\\sigma^2 t^2)/2}\n\\end{align*}\n\\end{example}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA generalization of \\eqref{E:cfofLinearTransformation} is the following.  \nIf $X_1,X_2,\\ldots,X_n$ are independent RVs and $a_1,a_2,\\ldots,a_n$ are some constants, then the CF of the linear combination $Y=\\sum_{i=1}^n a_i X_i$ is\n\\begin{equation}\\label{E:LinCombCF} \n\\boxed{\n\\cf_Y (t) = \\cf_{X_1} (a_1 t) \\times \\cf_{X_2} (a_2 t) \\times \\cdots \\times \\cf_{X_n} (a_n t) = \\prod_{i=1}^n \\cf_{X_i} (a_i t) \\enspace .\n}\n\\end{equation}\n%In other symbols: $$\\cf_{\\sum_{i=1}^n a_i X_i}(t) = \\prod_{i=1}^n \\cf_{X_i} (a_i t) \\enspace .$o$ \n\\begin{example}\\label{EgCFOfBinomial}\nUsing the following three facts:\n\\bit \n\\item~~~ Eqn.~\\eqref{E:LinCombCF} \n\\item~~~ the $\\binomial(n,\\theta)$ RV $Y$ is the sum of $n$ independent $\\bernoulli(\\theta)$ RVs (from Probability Course)  \n\\item~~~ the CF of $\\bernoulli(\\theta)$ RV (from lecture notes for Inference Course)\n\\eit\nfind the CF of the $\\binomial(n,\\theta)$ RV $Y$.\n\nSolution:\n\nLet $X_1,X_2,\\ldots,X_n$ be independent $\\bernoulli(\\theta)$ RVs with CF $\\left( 1-\\theta + \\theta e^{\\imath t} \\right)$ then $Y=\\sum_{i=1}^n  X_i$ is the $\\binomial(n,\\theta)$ RV and by Eqn.~\\eqref{E:LinCombCF} \nwith $a_1=a_2=\\cdots=1$, we get\n\\[\n\\cf_Y (t) = \\cf_{X_1} ( t) \\times \\cf_{X_2} (t) \\cdots \\cf_{X_n} ( t)\n= \\prod_{i=1}^n \\cf_{X_i} ( t) = \\prod_{i=1}^n \\left( 1-\\theta + \\theta e^{\\imath t} \\right)\n= \\left( 1-\\theta + \\theta e^{\\imath t} \\right)^n \\enspace . \n\\]\n\\end{example}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{example}\\label{EgCFOfSumOf2IndepNormals}\nLet $Z_1$ and $Z_2$ be independent $\\normal(0,1)$ RVs.  \n\\be\n\\item~\nUse Eqn.~\\eqref{E:LinCombCF} \nto find the CF of $Z_1+Z_2$.  \n\\item~\nFrom the CF of $Z_1+Z_2$ identify what RV it is.\n\\item~\nUse Eqn.~\\eqref{E:LinCombCF} \nto find the CF of $2Z_1$.\n\\item~\nFrom the CF of $2Z_1$ identify what RV it is.\n\\item~\nTry to understand the difference between the distributions of $Z_1+Z_2$ and $2 Z_1$ inspite of $Z_1$ and $Z_2$ having the same distibution.\n\\ee\n{Hint: from lectures we know that $\\cf_X(t) = e^{\\imath \\mu t - (\\sigma^2 t^2)/2}$ for a $\\normal(\\mu,\\sigma^2)$ RV $X$.}\n\nSolution:\n\n\\be\n\\item~\nBy Eqn.~\\eqref{E:LinCombCF} \nwe just multiply the characteristic functions of $Z_1$ and $Z_2$, both of which are $e^{-t^2/2}$,\n\\[\n\\cf_{Z_1+Z_2}(t)= \\cf_{Z_1}(t) \\times \\cf_{Z_2}(t) = e^{-t^2/2} \\times e^{-t^2/2} = e^{-2t^2/2} = e^{-t^2} \\enspace . \n\\]  \n\\item~\nThe CF of $Z_1+Z_2$ is that of the $\\normal(\\mu,\\sigma^2)$ RV with $\\mu=0$ and $\\sigma^2=2$.  \nThus $Z_1+Z_2$ is the $\\normal(0,2)$ RV with mean parameter $\\mu=0$ and variance paramter $\\sigma^2=2$.\n\\item~\nWe can again use Eqn.~\\eqref{E:LinCombCF} \nto find the CF of $2Z_1$ as follows\n\\[\n\\cf_{2Z_1} = \\cf_{Z_1}(2 t) = e^{-2^2t^2/2} \\enspace .\n\\]\n\\item~\nThe CF of $2Z_1$ is that of the $\\normal(\\mu,\\sigma^2)$ RV with $\\mu=0$ and $\\sigma^2=2^2=4$.\nThus $2Z_1$ is the $\\normal(0,4)$ RV with mean parameter $\\mu=0$ and variance paramter $\\sigma^2=4$.\n\\item~\n$2Z_1$ has a bigger variance from multiplying the standard normal RV by $2$ while $Z_1+Z_2$ has a smaller variance from adding two independent standard normal RVs.  Thus, the result of adding the same RV twice does not have the same distribution as that of multiplying it by $2$.  In other words $2 \\times Z$ is not equal to $Z+Z$ in terms of its probability distribution! \n\\ee\n\\end{example}\n\n\n\\subsection{Moment Generating Function}\n\nMoment generating functions are special cases of characteristic functions and we won't be explicitly using them here as it is more convenient to work in the complex plane.\n\\remove{\n\\begin{definition}[MGF]\nMGF is ...\n\\end{definition}\n\n\\vspace{10cm}\n}\n\n\\input{ExsInCharacteristicFunctions.tex}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Statistics}\\label{S:Statistics}\n\n\\subsection{Data and Statistics}\\label{S:DataStats}\n\n\\begin{definition}[Data]\nThe function $X$ measures the outcome $\\omega$ of an experiment with sample space $\\Omega$ [Often, the sample space is also denoted by $S$].  Formally, $X$ is a random variable [or a random vector $X=(X_1,X_2,\\ldots,X_n)$, i.e.~a vector of random variables] taking  values in the {\\bf data space} $\\Xz$:\n\\[\nX(\\omega):\\Omega \\to \\Xz \\ .\n\\]\nThe realisation of the RV $X$ when an experiment is performed is the observation or data $x \\in \\Xz$.  That is, when the experiment is performed once and it yields a specific $\\omega \\in \\Omega$, the data $X(\\omega)=x \\in \\Xz$ is the corresponding realisation of the RV $X$.\n\\end{definition}\n\n\\begin{figure}[htpb]\n\\caption{Sample Space, Random Variable, Realisation, Data, and Data Space.\\label{F:Data}}\n\\vspace{2.5in}\n\\end{figure}\n\n\\begin{example}[Tossing a coin $n$ times]\nFor some given parameter $\\theta \\in \\BB{\\Theta} := [0,1]$, consider $n$ IID $\\bernoulli(\\theta)$ trials, i.e.~$X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\bernoulli(\\theta)$.  Then the random vector $X=(X_1,X_2,\\ldots,X_n)$, which takes values in the data space $\\Xz = \\{0,1\\}^n := \\{ (x_1,x_2,\\ldots,x_n) : x_i \\in \\{0,1\\}, \\ i=1,2,\\ldots,n \\}$, made up of vertices of the $n$-dimensional hyper-cube, measures the outcomes of this experiment.  A particular realisation of $X$, upon performance of this experiment, is the observation, data or data vector $(x_1,x_2,\\ldots,x_n)$.  For instance, if we observed $n-1$ tails and $1$ heads, in that order, then our data vector $(x_1,x_2,\\ldots,x_{n-1},x_n) = (0,0,\\ldots,0,1)$.\n\\end{example}\n\n\\begin{figure}\n\\caption{Data Spaces $\\Xz=\\{0,1\\}^2$ and $\\Xz=\\{0,1\\}^3$ for two and three Bernoulli trials, respectively.\\label{F:BernoulliDataSpace2and3}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/BernoulliDataSpace2and3}}\n\\end{figure}\n\n\\begin{definition}[Statistic]\\label{D:Statistic}\nA {\\bf statistic} $T$ is any \n%(measurable) \nfunction of the data:\n\\[\nT(x) : \\Xz \\to \\Tz \\ .\n\\]\nThus, a statistic $T$ is also an RV that takes values in the space $\\Tz$.  When $x \\in \\Xz$ is the realisation of an experiment, we let $T(x)=t$ denote the corresponding realisation of the statistic $T$. Sometimes we use $T_n(X)$ and $\\Tz_n$ to emphasise that $X$ is an $n$-dimensional random vector, i.e.~$\\Xz \\subset \\Rz^n$ \n\\end{definition}\n\n\\begin{classwork}[Is data a statistic?]\nIs the RV $X$, for which the realisation is the observed data $X(\\omega)=x$, a statistic?  In other words, is the data a statistic? [Hint: consider the identity map $T(x)=x: \\Xz \\to \\Tz=\\Xz$.]\n\\end{classwork}\n\nNext, we define two important statistics called the {\\bf sample mean} and {\\bf sample variance}.  Since they are obtained from the sample data, they are called {\\bf sample moments}, as opposed to the {\\bf population moments}.  The corresponding population moments are $\\E(X_1)$ and $\\V(X_1)$, respectively.\n\\begin{definition}[Sample Mean]\\label{D:SampleMean}\nFrom a given a sequence of RVs $X_1,X_2,\\ldots,X_n$, we may obtain another RV called the $n$-samples mean or simply the sample mean:\n\\begin{equation}\\label{E:SampleMeanRV}\nT_n( \\ (X_1,X_2,\\ldots,X_n) \\ ) = \\overline{X}_n( \\ (X_1,X_2,\\ldots,X_n) \\ ) := \\frac{1}{n} \\sum_{i=1}^n X_i  \\ .\n\\end{equation}\nFor brevity, we write $$\\overline{X}_n( \\ (X_1,X_2,\\ldots,X_n) \\ ) \\quad \\text{as} \\quad \\overline{X}_n \\ ,$$ and its realisation $$\\overline{X}_n( \\ (x_1,x_2,\\ldots,x_n) \\ ) \\quad \\text{as} \\quad \\overline{x}_n \\ .$$\n\\end{definition}\nNote that the expectation and variance of $\\overline{X}_n$ are:\n\\begin{eqnarray}\n\\E(\\overline{X}_n) &=& \\E \\left(  \\frac{1}{n} \\sum_{i=1}^n X_i \\right) \\qquad \\text{{\\scriptsize[by \\hyperref[E:SampleMeanRV]{definition \\eqref{E:SampleMeanRV}}]}} \\notag \\\\\n&=&  \\frac{1}{n} \\sum_{i=1}^n \\E \\left( X_i \\right) \\qquad \\text{{\\scriptsize [by \\hyperref[E:EofLinCombofRVs]{property \\eqref{E:EofLinCombofRVs}}]}} \\notag\n\\end{eqnarray}\nFurthermore, if every $X_i$ in the original sequence of RVs $X_1,X_2,\\ldots$ is {\\bf identically} distributed with the same expectation, by convention $\\E(X_1)$, then:\n\\begin{equation}\\label{E:ExpOfSampleMeanOfIDSeq}\n\\E(\\overline{X}_n) \n= \\frac{1}{n} \\sum_{i=1}^n \\E \\left( X_i \\right)\n=  \\frac{1}{n} \\sum_{i=1}^n \\E \\left( X_1 \\right) \n=  \\frac{1}{n} \\ n \\ \\E \\left( X_1 \\right)  = \\E \\left( X_1 \\right) \\ .\n\\end{equation}\nSimilarly, we can show that:\n\\begin{eqnarray}\n\\V(\\overline{X}_n) &=& \\V \\left(  \\frac{1}{n} \\sum_{i=1}^n X_i \\right) \\qquad \\text{{\\scriptsize[by \\hyperref[E:SampleMeanRV]{definition \\eqref{E:SampleMeanRV}}]}} \\notag \\\\\n&=& \\left( \\frac{1}{n} \\right)^2  \\V \\left( \\sum_{i=1}^n X_i \\right) \\qquad \\text{{\\scriptsize [by \\hyperref[E:VofAffineofRVs]{property \\eqref{E:VofAffineofRVs}}]}} \\notag\n\\end{eqnarray}\nFurthermore, if the original sequence of RVs $X_1,X_2,\\ldots$ is {\\bf independently} distributed then:\n\\begin{eqnarray}\n\\V(\\overline{X}_n) \n= \\left( \\frac{1}{n} \\right)^2 \\V \\left(  \\sum_{i=1}^n X_i \\right) \n=  \\frac{1}{n^2} \\ \\sum_{i=1}^n \\V \\left( X_i \\right) \\qquad \\text{{\\scriptsize [by \\hyperref[E:VofLinCombofRVs]{property \\eqref{E:VofLinCombofRVs}}]}} \\notag\n\\end{eqnarray}\nFinally, if the original sequence of RVs $X_1,X_2,\\ldots$ is {\\bf independently and identically} distributed with the same variance ($\\V(X_1)$ by convention) then:\n\\begin{equation}\\label{E:VarOfSampleMeanOfIIDSeq}\n\\V(\\overline{X}_n) \n=  \\frac{1}{n^2} \\ \\sum_{i=1}^n \\V \\left( X_i \\right)\n= \\frac{1}{n^2} \\ \\sum_{i=1}^n \\V \\left( X_1 \\right)\n=  \\frac{1}{n^2} \\ n \\ \\V \\left( X_1 \\right)\n=  \\frac{1}{n} \\ \\V \\left( X_1 \\right) \\ .\n\\end{equation}\n\n\\begin{labwork}[Sample mean]\\label{LW:XsFromUni01Twstr101mean}\nAfter initializing the fundamental sampler, we draw five samples and then obtain the sample mean using the {\\sc Matlab} function {\\tt mean}.  In the following, we will reuse the samples stored in the array {\\tt XsFromUni01Twstr101}.\n\\begin{VrbM}\n>> rand('twister',101); % initialise the fundamental Uniform(0,1) sampler \n>> XsFromUni01Twstr101=rand(1,5); % simulate n=5 IID samples from Uniform(0,1) RV\n>> SampleMean=mean(XsFromUni01Twstr101);% find sample mean\n>> disp(XsFromUni01Twstr101); % The data-points x_1,x_2,x_3,x_4,x_5 are:\n    0.5164    0.5707    0.0285    0.1715    0.6853\n>> disp(SampleMean); % The Sample mean is :\n    0.3945\n\\end{VrbM}\nWe can thus use {\\tt mean} to obtain the sample mean $\\overline{x}_n$ of $n$ sample points $x_1,x_2,\\ldots,x_n$.\n\nWe may also obtain the sample mean using the {\\tt sum} function and a division by sample size:\n\\begin{VrbM}\n>> sum(XsFromUni01Twstr101) % take the sum of the elements of the XsFromUni01Twstr101 array\nans =    1.9723\n>> sum(XsFromUni01Twstr101) / 5 % divide the sum by the sample size 5\nans =    0.3945\n\\end{VrbM}\n\nWe can also obtain the sample mean via matrix product or multiplication as follows:\n\\begin{VrbM}\n>> size(XsFromUni01Twstr101) % size(SomeArray) gives the size or dimensions of the arrar SomeArray\nans =     1     5\n>> ones(5,1) % here ones(5,1) is an array of 1's with size or dimension 5 X 1\nans =\n     1\n     1\n     1\n     1\n     1\n>> XsFromUni01Twstr101 * ones(5,1) % multiplying an 1 X 5 matrix with a 5 X 1 matrix of Ones\nans =    1.9723\n>> XsFromUni01Twstr101 * ( ones(5,1) * 1/5) % multiplying an 1 X 5 matrix with a 5 X 1 matrix of 1/5 's\nans =    0.3945\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{definition}[Sample Variance \\& Standard Deviation]\nFrom a given a sequence of random variables $X_1,X_2,\\ldots,X_n$, we may obtain another statistic called the $n$-samples variance or simply the sample variance :\n\\begin{equation}\\label{E:SampleVarianceRV}\nT_n( \\ (X_1,X_2,\\ldots,X_n) \\ ) = S^2_n( \\ (X_1,X_2,\\ldots,X_n) \\ )  := \\frac{1}{n-1} \\sum_{i=1}^n {(X_i - \\overline{X}_n)^2}  \\ .\n\\end{equation}\nFor brevity, we write $S^2_n( \\ (X_1,X_2,\\ldots,X_n) \\ )$ as $S^2_n$ and its  realisation $S^2_n( \\ (x_1,x_2,\\ldots,x_n) \\ )$ as $s^2_n$.\n\nSample standard deviation is simply the square root of sample variance:\n\\begin{equation}\\label{E:SampleStdDevRV}\nS_n( \\ (X_1,X_2,\\ldots,X_n) \\ ) = \\sqrt{S^2_n( \\ (X_1,X_2,\\ldots,X_n) \\ )}\n\\end{equation}\nFor brevity, we write $S_n( \\ (X_1,X_2,\\ldots,X_n) \\ )$ as $S_n$ and its  realisation $S_n( \\ (x_1,x_2,\\ldots,x_n) \\ )$ as $s_n$.\n\\end{definition}\nOnce again, if $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} X_1$, the expectation of the sample variance is:\n\\[\n\\E(S^2_n) = \\V(X_1) \\ .\n\\]\n\\begin{labwork}[Sample variance and sample standard deviation]\\label{LW:XsFromUni01Twstr101varstd}\nWe can compute the sample variance and sample standard deviation for the five samples stored in the array {\\tt XsFromUni01Twstr101} from \\hyperref[LW:XsFromUni01Twstr101mean]{Labwork \\ref*{LW:XsFromUni01Twstr101mean}} using {\\sc Matlab}'s functions {\\tt var} and {\\tt std}, respectively.\n\\begin{VrbM}\n>> disp(XsFromUni01Twstr101); % The data-points x_1,x_2,x_3,x_4,x_5 are :\n    0.5164    0.5707    0.0285    0.1715    0.6853\n>> SampleVar=var(XsFromUni01Twstr101);% find sample variance\n>> SampleStd=std(XsFromUni01Twstr101);% find sample standard deviation\n>> disp(SampleVar) % The sample variance is:\n    0.0785\n>> disp(SampleStd) % The sample standard deviation is:\n    0.2802\n\\end{VrbM}\n\\end{labwork}\nIt is important to bear in mind that the statistics such as sample mean and sample variance are random variables and have an underlying distribution.\n\n\\begin{definition}[Order Statistics]\nSuppose $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F$, where $F$ is the DF from the set of all DFs over the real line.  Then, the $n$-sample {\\bf order statistics} $X_{([n])}$ is:\n\\begin{equation}\\label{E:OrderStatistics}\nX_{([n])}( \\ (X_1,X_2,\\ldots,X_n) \\ ) := \\left(  X_{(1)},X_{(2)}, \\ldots X_{(n)} \\right), \\text{ such that, }\n X_{(1)} \\leq X_{(2)} \\leq \\ldots \\leq X_{(n)}  \\ .\n\\end{equation}\nFor brevity, we write $X_{([n])}( \\ (X_1,X_2,\\ldots,X_n) \\ )$ as $X_{([n])}$ and its realisation $X_{([n])}( \\ (x_1,x_2,\\ldots,x_n) \\ )$ as $x_{([n])} = (  x_{(1)},x_{(2)}, \\ldots x_{(n)} )$.\n\\end{definition}\nWithout going into the details of how to sort the data in ascending order to obtain the order statistics (an elementary topic of an Introductory Computer Science course), we simply use {\\sc Matlab}'s function {\\tt sort} to obtain the order statistics, as illustrated in the following example.\n\\begin{labwork}[Order statistics and sorting]\\label{LW:SortedXsFromUni01Twstr101}\nThe order statistics for the five samples stored in {\\tt XsFromUni01Twstr101} from \\hyperref[LW:XsFromUni01Twstr101mean]{Labwork \\ref*{LW:XsFromUni01Twstr101mean}} can be computed using {\\tt sort} as follows:\n\\begin{VrbM}\n>> disp(XsFromUni01Twstr101); % display the sample points\n    0.5164    0.5707    0.0285    0.1715    0.6853\n>> SortedXsFromUni01Twstr101=sort(XsFromUni01Twstr101); % sort data\n>> disp(SortedXsFromUni01Twstr101); % display the order statistics\n    0.0285    0.1715    0.5164    0.5707    0.6853\n\\end{VrbM}\nTherefore, we can use {\\tt sort} to obtain our order statistics $x_{(1)},x_{(2)},\\ldots,x_{(n)}$ from $n$ sample points $x_1,x_2,\\ldots,x_n$.\n\\end{labwork}\n\nNext, we will introduce a family of common statistics, called the $q^{\\text{th}}$ quantile, by first defining the function:\n\\begin{definition}[Inverse DF or Inverse CDF or Quantile Function]\nLet $X$ be an RV with DF $F$.  The {\\bf inverse DF} or {\\bf inverse CDF} or {\\bf quantile function} is:\n\\begin{equation}\\label{E:InverseCDF}\nF^{[-1]}(q) := \\inf { \\{ x: F(x) > q \\}}, \\quad \\text{ for some $q \\in [0,1]$} \\ .\n\\end{equation} \nIf $F$ is strictly increasing and continuous then $F^{[-1]}(q)$ is the unique $x \\in \\Rz$ such that $F(x)=q$.\n\\end{definition}\nA {\\bf functional} is merely a function of another function.  Thus, $T(F): \\{ \\text{All DFs }\\} \\to \\Tz$, being a map or function from the space of DFs to its range $\\Tz$, is a functional.  Some specific examples of functionals we have already seen include:\n\\begin{enumerate}\n\\item The {\\bf mean} of RV $X \\sim F$ is a function of the DF $F$:  \n\\[\nT(F) = \\E(X) = \\int x\\,dF(x) \\ .\n\\]\n\\item The {\\bf variance} of RV $X \\sim F$ is a function of the DF $F$:  \n\\[\nT(F) = \\E(X-\\E(X))^2 = \\int (x-\\E(X))^2\\,dF(x) \\ .\n\\]\n\\item The {\\bf value of DF at a given $x \\in \\Rz$} of RV $X \\sim F$ is also a function of DF $F$:\n\\[\nT(F) = F(x) \\  .\n\\]\n\\end{enumerate}\nOther functionals of $F$ that depend on the quantile function $F^{[-1]}$ are:\n\\begin{enumerate}\n\\item The {\\bf $q^{\\text{th}}$ quantile} of RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(q) \\ \\text{ where } q \\in [0,1] \\ .\n\\]\n\\item The {\\bf first quartile} or the {\\bf $0.25^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.25) \\ .\n\\]\n\\item The {\\bf median} or the {\\bf second quartile} or the {\\bf $0.50^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.50) \\  .\n\\]\n\\item The {\\bf third quartile} or the {\\bf $0.75^{\\text{th}}$ quantile} of the RV $X \\sim F$: \n\\[\nT(F) = F^{[-1]}(0.75) \\ .\n\\]\n\\end{enumerate}\n\n\\begin{definition}[Empirical Distribution Function (EDF or ECDF)]\\label{D:ECDF}\nSuppose we have $n$ IID RVs, $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F$, where $F$ is a DF from the set of all DFs over the real line.  Then, the $n$-sample empirical distribution function (EDF or ECDF) is the discrete  distribution function $\\widehat{F}_n$ that puts a probability mass of $1/n$ at each sample or data point $x_i$:\n\\begin{eqnarray} \\label{E:ECDF}\n\\widehat{F}_n(x) = \\frac{ \\sum_{i=1}^n \\BB{1}(X_i \\leq x) }{n} \\ ,  & \\quad where \\qquad\n\\BB{1}(X_i \\leq x) :=\n\\begin{cases}\n& 1  \\quad \\text{if $x_i \\leq x$} \\\\\n& 0  \\quad \\text{if $x_i > x$} \n\\end{cases}\n\\end{eqnarray}\n\\end{definition}\n\n\\begin{labwork}[Plot of empirical CDF]\\label{LW:ECDF}\nLet us plot the ECDF for the five samples drawn from the $Uniform(0,1)$ RV in \\hyperref[LW:XsFromUni01Twstr101mean]{Labwork \\ref*{LW:XsFromUni01Twstr101mean}} using the {\\sc Matlab} function {\\tt ECDF}. %(given in \\hyperref[Mf:ECDF]{Labwork \\ref*{Mf:ECDF}}).  \nLet us super-impose the samples and the true DF as depicted in \\hyperref[F:plotUniform01ECDF5]{Figure \\ref*{F:plotUniform01ECDF5}} with the following script:\n{\\VrbMf[label=plotunifecdf.m]{scripts/plotunifecdf.m}}\n\n\\begin{figure}[htpb]\n\\caption{Plot of the DF of $\\uniform(0,1)$, five IID samples from it, and the ECDF $\\widehat{F}_5$ for these five data points $x=(x_1,x_2,x_3,x_4,x_5)=(0.5164,    0.5707,    0.0285,    0.1715,    0.6853)$ that jumps by $1/5=0.20$ at each of the five samples.\\label{F:plotUniform01ECDF5}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/plotUniform01ECDF5}}\n\\end{figure}\n\\end{labwork}\n\n\\begin{definition}[$q^{\\text{th}}$ Sample Quantile]\nFor some $q \\in [0,1]$ and $n$ IID RVs $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F$, we can obtain the ECDF $\\widehat{F}_n$ using \\eqref{E:ECDF}.  The {\\bf $q^{\\text{th}}$ sample quantile} is defined as the statistic (statistical functional):\n\\begin{equation}\\label{E:qthSampleQuantile}\nT(\\widehat{F}_n) = \\widehat{F}_n^{[-1]}(q) := \\inf{ \\{ x:  \\widehat{F}_n^{[-1]}(x) \\geq q \\} } \\ .\n\\end{equation}\nBy replacing $q$ in this definition of the $q^{\\text{th}}$ sample quantile by $0.25$, $0.5$ or $0.75$, we obtain the first, second ({\\bf sample median}) or third {\\bf sample quartile}, respectively.\n\\end{definition}\n\nThe following algorithm can be used to obtain the $q^{\\text{th}}$ sample quantile of $n$ IID samples $(x_1,x_2,\\ldots,x_n)$ on the basis of their order statistics $(x_{(1)},x_{(2)},\\ldots,x_{(n)})$.\n\\begin{algorithm}\n\\caption{$q^{\\text{th}}$ Sample Quantile of Order Statistics}\n\\label{A:qthSampleQuantile}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:} \n\\begin{enumerate}\n\\item $q$ in the $q^{\\text{th}}$ sample quantile, i.e.~the argument $q$ of $ \\widehat{F}_n^{[-1]}(q)$,\n\\item order statistic $(x_{(1)},x_{(2)},\\ldots,x_{(n)})$, i.e.~the sorted $(x_1,x_2,\\ldots,x_n)$, where $n>0$.\n\\end{enumerate}\n}\n\\STATE {\\it output:} $ \\widehat{F}_n^{[-1]}(q)$, the $q^{\\text{th}}$ sample quantile\n\\STATE $i \\gets \\lfloor (n-1) q \\rfloor$\n\\STATE $\\delta \\gets (n-1) q - i$\n\\IF {$i = n-1$}\n\\STATE {$ \\widehat{F}_n^{[-1]}(q) \\gets x_{(i+1)}$}\n\\ELSE\n\\STATE $ \\widehat{F}_n^{[-1]}(q) \\gets (1 - \\delta) x_{(i+1)} + \\delta x_{(i+2)}$\n\\ENDIF\n\\STATE {{\\it return:} $ \\widehat{F}_n^{[-1]}(q)$}\n\\end{algorithmic}\n\\end{algorithm}\n\nThe $q^{\\text{th}}$ sample quantile, $ \\widehat{F}_n^{[-1]}(q)$, is found by interpolation from the order statistics $(x_{(1)},x_{(2)},\\ldots,x_{(n)})$ of the $n$ data points $(x_1,x_2,\\ldots,x_n)$, using the formula:\n\\[\n \\widehat{F}_n^{[-1]}(q) = (1 - \\delta) x_{(i+1)} + \\delta x_{(i+2)}, \\quad \\text{where, }\n\\quad i = \\lfloor (n-1) q \\rfloor  \\quad \\text{ and }\n\\quad \\delta = (n-1) q -  \\lfloor (n-1) q \\rfloor \\ .\n\\]\nThus, the {\\bf sample minimum} of the data points $(x_1,x_2,\\ldots,x_n)$ is given by $ \\widehat{F}_n^{[-1]}(0)$, the {\\bf sample maximum} is given by $ \\widehat{F}_n^{[-1]}(1)$ and the {\\bf sample median} is given by $ \\widehat{F}_n^{[-1]}(0.5)$, etc.\n\\begin{labwork}[The $q^{\\text{th}}$ sample quantile]\\label{LW:qthSampleQuantile}\nUse the implementation of \\hyperref[A:qthSampleQuantile]{Algorithm \\ref*{A:qthSampleQuantile}} %in \\hyperref[Mf:qthSampleQuantile]{Labwork \\ref*{Mf:qthSampleQuantile}} \nas the {\\sc Matlab} function {\\tt qthSampleQuantile} to find the $q^{\\text{th}}$ sample quantile of two simulated data arrays:\n\\begin{enumerate}\n\\item {\\tt SortedXsFromUni01Twstr101}, the order statistics that was constructed in \\hyperref[LW:SortedXsFromUni01Twstr101]{Labwork \\ref*{LW:SortedXsFromUni01Twstr101}} and\n\\item Another sorted array of $7$ samples called {\\tt SortedXs}\n\\end{enumerate}\n\\begin{VrbM}\n>> disp(SortedXsFromUni01Twstr101)\n    0.0285    0.1715    0.5164    0.5707    0.6853\n>> rand('twister',420);\n>> SortedXs=sort(rand(1,7));\n>> disp(SortedXs)\n    0.1089    0.2670    0.3156    0.3525    0.4530    0.6297    0.8682\n>> for q=[0, 0.25, 0.5, 0.75, 1.0]\n       disp([q, qthSampleQuantile(q,SortedXsFromUni01Twstr101) ...\n                qthSampleQuantile(q,SortedXs)])\n   end\n         0    0.0285    0.1089\n    0.2500    0.1715    0.2913\n    0.5000    0.5164    0.3525\n    0.7500    0.5707    0.5414\n    1.0000    0.6853    0.8682\n\\end{VrbM}\n\\end{labwork}\n\n%\\subsection{Exploring Data and Statistics}\\label{S:ExploringData}\n\n\\subsection{Univariate Data}\nA {\\bf histogram} is a graphical representation of the frequency with which elements of a data array:\n$$x = (x_1,x_2,\\ldots,x_n) \\ ,$$ \nof real numbers fall within each of the $m$ intervals or {\\bf bins} of some {\\bf interval partition}:\n$$b := ( b_1, b_2, \\ldots, b_m ) := ( [\\underline{b}_1,\\overline{b}_1], [\\underline{b}_2,\\overline{b}_2], \\ldots, [\\underline{b}_m,\\overline{b}_m] )$$\nof the {\\bf data range} of $x$ given by the closed interval: \n$$\\C{R}(x) := [\\min \\{x_1,x_2,\\ldots,x_n \\}, \\max \\{x_1,x_2,\\ldots,x_n \\}] \\ .$$  \nElements of this partition $b$ are called bins, their mid-points are called {\\bf bin centres}:\n$$c := ( c_1, c_2, \\ldots, c_m ) := ( (\\underline{b}_1+\\overline{b}_1)/2, (\\underline{b}_2 + \\overline{b}_2)/2, \\ldots, (\\underline{b}_m + \\overline{b}_m)/2 )$$\nand their overlapping boundaries, i.e.~$\\overline{b}_i=\\underline{b}_{i+1}$ for $1 \\leq i < m$, are called {\\bf bin edges}:\n$$d := (d_1,d_2,\\ldots,d_{m+1}) := (\\underline{b}_1, \\underline{b}_2, \\ldots, \\underline{b}_{m-1}, \\underline{b}_m, \\overline{b}_m) \\ .$$ \nFor a given partition of the data range $\\C{R}(x)$ or some superset of $\\C{R}(x)$, three types of histograms are possible: frequency histogram, relative frequency histogram and density histogram.  Typically, the partition $b$ is assumed to be composed of $m$ overlapping intervals of the same width $w=\\overline{b}_i - \\underline{b}_i$ for all $i=1,2,\\ldots,m$.  Thus, a histogram can be obtained by a set of bins along with their corresponding {\\bf heights}:\n$$h = (h_1,h_2,\\ldots,h_m) \\ , \\text{ where } h_k := g(\\# \\{x_i : x_i \\in b_k\\} )$$\nThus, $h_k$, the height of the $k$-th bin, is some function $g$ of the number of data points that fall in the bin $b_k$ Formally, a histogram is a sequence of ordered pairs:\n$$\\left(  (b_1,h_1), (b_2,h_2), \\ldots, (b_m,h_m) \\right) \\ .$$\n\nGiven a partition $b$, a {\\bf frequency histogram} is the histogram:\n$$\\left(  (b_1,h_1), (b_2,h_2), \\ldots, (b_m,h_m) \\right) \\ , \\text{ where } h_k := \\# \\{x_i : x_i \\in b_k\\} \\ ,$$\na {\\bf relative frequency histogram} is the histogram:\n$$\\left(  (b_1,h_1), (b_2,h_2), \\ldots, (b_m,h_m) \\right) \\ , \\text{ where } h_k := n^{-1} \\# \\{x_i : x_i \\in b_k\\} \\ ,$$\nand a {\\bf density histogram} is the histogram:\n$$\\left(  (b_1,h_1), (b_2,h_2), \\ldots, (b_m,h_m) \\right) \\ , \\text{ where } h_k := (w_k n)^{-1} \\# \\{x_i : x_i \\in b_k\\} \\ , w_k := \\overline{b}_k - \\underline{b}_k \\ .$$\n  \n\\begin{figure}[htpb]\n\\caption{Frequency, Relative Frequency and Density Histograms\\label{F:FreqRelFreqDensityHistograms100Unif01MT5489}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/FreqRelFreqDensityHistograms100Unif01MT5489}}\n\\end{figure}\n\n\\begin{labwork}[Histograms with specified number of bins for univariate data]\\label{LW:hist}\nLet us use samples from the {\\tt rand('twister',5489)} as our data set $x$ and plot various histograms.  Let us use {\\tt hist} function (read {\\tt help hist}) to make a default histogram with ten bins.  Then we can make three types of histogarms as shown in \\hyperref[F:FreqRelFreqDensityHistograms100Unif01MT5489]{Figure~\\ref*{F:FreqRelFreqDensityHistograms100Unif01MT5489}}  as follows:\n\\begin{VrbM}\n>> rand('twister',5489);\n>> x=rand(1,100); % generate 100 PRNs\n>> hist(x) % see what default hist does in Figure Window\n>> % Now let us look deeper into the last hist call\n>> [Fs, Cs] = hist(x) % Cs is the bin centers and Fs is the frequencies of data set x\nFs =\n     9    11    10     8     7    10     8    11    10    16\nCs =\n    0.0598    0.1557    0.2516    0.3474    0.4433    0.5392    0.6351    0.7309    0.8268    0.9227\n>> % produce a histogram plot the last argument 1 is the width value for immediately adjacent bars -- help bar\n>> bar(Cs,Fs,1) % create a frequency histogram\n>> bar(Cs,Fs/100,1) % create a relative frequency histogram\n>> bar(Cs,Fs/(0.1*100),1) % create a density histogram (area of bars sum to 1)\n>> sum(Fs/(0.1*100) .* ones(1,10)*0.1) % checking if area does sum to 1\n>> ans = 1\n\\end{VrbM}\nTry making a density histogram with 1000 samples from {\\tt rand} with 15 bins.  You can specify the number of bins by adding an extra argument to {\\tt hist}, for e.g. {\\tt [Fs, Cs] = hist(x,15)} will produce 15 bins of equal width over the data range $\\C{R}(x)$.\n\\end{labwork}\n\n\\begin{labwork}[Stem plots and ECDF plots for univariate data]\\label{LW:StemEcdf}\nWe can also visualise the 100 data points in the array {\\tt x} using stem plot and ECDF plot as shown in \\hyperref[F:StemECDF100Unif01MT5489]{Figure~\\ref*{F:StemECDF100Unif01MT5489}} as follows:\n\\begin{VrbM}\n>> rand('twister',5489);\n>> x=rand(1,100); % produce 100 samples with rand\n>> stem(x,'.') % make a stem plot of the 100 data points in x (the option '.' gives solid circles for x)\n>>% ECDF (type help ECDF) plot is extended to left and right by .2 and .6, respectively\n>>% (second parameter 6 makes the dots in the plot smaller).\n>> ECDF(x,6,.2,.6);\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Frequency, Relative Frequency and Density Histograms\\label{F:StemECDF100Unif01MT5489}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/StemECDF100Unif01MT5489}}\n\\end{figure}\n\nWe can also visually summarise univariate data using the {\\bf box plot} or {\\bf box-whisker plot} available in the Stats Toolbox of {\\sc Matlab}.  These family of plots display a set of sample quantiles, typically they are include, the median, the first and third quartiles and the minimum and maximum values of our data array $x$.\n\n\\subsection{Bivariate Data}\nBy bivariate data array $x$ we mean a $2 \\times n$ matrix of real numbers or equivalently $n$ ordered pairs of points $(x_{1,i},x_{2,i})$ as $i=1,2,\\ldots,n$.  The most elementary visualisation of these $n$ ordered pairs is in orthogonal Cartesian co-ordinates.  Such plots are termed 2D {\\bf scatter plots} in statistics.\n\\begin{labwork}[Visualising bivariate data]\\label{LW:2DScatter}\nLet us generate a $2 \\times 5$ array representing samples of $5$ ordered pairs sampled uniformly at random over the unit square $[0,1] \\times [0,1]$.  We can make 2D scatter plot as shown in \\hyperref[F:Twister5489X2x5Scatter2D]{Figure~\\ref*{F:Twister5489X2x5Scatter2D}}  as follows:\n\\begin{VrbM}\n>> rand('twister',5489);\n>> x=rand(2,5)% create a sequence of 5 ordered pairs uniformly from unit square [0,1]X[0,1]\nx =\n    0.8147    0.1270    0.6324    0.2785    0.9575\n    0.9058    0.9134    0.0975    0.5469    0.9649\n>> plot(x(1,:),x(2,:),'x') % a 2D scatter plot with marker cross or 'x'\n>> plot(x(1,:),x(2,:),'x', 'MarkerSize',15) % a 2D scatter plot with marker cross or 'x' and larger Marker size\n>> xlabel('x_1'); ylabel('x_2'); % label the axes\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{2D Scatter Plot\\label{F:Twister5489X2x5Scatter2D}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/Twister5489X2x5Scatter2D}}\n\\end{figure}\n\nThere are several other techniques for visualising bivariate data, including,\n2D histograms, surface plots, heat plots, and we will encounter some of them in the sequel.\n\n\\subsection{Trivariate Data}\nTrivariate data is more difficult to visualise on paper but playing around with the rotate 3D feature in \\Matlab's Figure window can help bring a lot more perspective.\n\n\\begin{labwork}[Visualising trivariate data]\\label{LW:3DScatter}\nWe can make {\\bf 3D scatter plots} as shown in \\hyperref[F:Twister5489X3x5Scatter3D]{Figure~\\ref*{F:Twister5489X3x5Scatter3D}}  as follows:\n\\begin{VrbM}\n>> rand('twister',5489);\n>> x=rand(3,5)% create a sequence of 5 ordered triples uniformly from unit cube [0,1]X[0,1]X[0,1]\nx =\n    0.8147    0.9134    0.2785    0.9649    0.9572\n    0.9058    0.6324    0.5469    0.1576    0.4854\n    0.1270    0.0975    0.9575    0.9706    0.8003\n>> plot3(x(1,:),x(2,:),x(3,:),'x') % a simple 3D scatter plot with marker 'x'\n>>% a more interesting one with options that control marker type, line-style, \n>>% colour in [Red Green Blue] values and marker size - read help plot3 for more options\n>> plot3(x(1,:),x(2,:),x(3,:),'Marker','*','LineStyle','none','Color',[1 0 1],'MarkerSize',15) \n>> plot3(x(1,:),x(2,:),x(3,:),'m*','MarkerSize',15) % makes same  figure as before but shorter to write\n>> box on % turn on the box and see the effect on the Figure\n>> grid on % turn on the grid and see the effect on the Figure\n>> xlabel('x_1'); ylabel('x_2'); zlabel('x_3'); % assign labels to x,y and z axes\n\\end{VrbM}\nRepeat the visualisation below with a larger array, say {\\tt x=rand(3,1000)}, and use the rotate 3D feature in the Figure window to visually explore the samples in the unit cube.  Do they seem to be uniformly distributed inside the unit cube?\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{3D Scatter Plot\\label{F:Twister5489X3x5Scatter3D}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/Twister5489X3x5Scatter3D}}\n\\end{figure}\n\n\nThere are several other techniques for visualising trivariate data, including,\niso-surface plots, moving surface or heat plots, and you will encounter some of them in the future.\n\n\\subsection{Multivariate Data}\nFor high-dimensional data in $d$-dimensional space $\\Rz^d$ with $d \\geq 3$ you have to look at several lower dimensional projections of the data.  We can simultaneously look at 2D scatter plots for every pair of co-ordinates $\\{(i,j) \\in \\{1,2,\\ldots,d\\}^2 : i \\neq j \\}$ and at histograms for every co-ordinate $i \\in \\{1,2,\\ldots,d\\}$ of the $n$ data points in $\\Rz^d$.  Such a set of low-dimensional projections can be conveniently represented in a $d \\times d$ matrix of plots called a {\\bf matrix plot}. \n\n\\begin{figure}[htpb]\n\\caption{Plot Matrix of uniformly generated data in $[0,1]^5$\\label{F:Twister5489X100x5PlotMatrixFirst6andAll100}}\n\\centering\n\\mbox{\\subfigure[First six samples]{\\hspace{-1.cm} \\includegraphics[width=3.750in]{figures/Twister5489X100x5PlotMatrixFirst6}} \\hspace{-1.cm}\n\t   \\subfigure[All thousand samples]{\\includegraphics[width=3.750in]{figures/Twister5489X100x5PlotMatrixAll100}} }\n\\end{figure}\n\n\\begin{labwork}\\label{LW:matrixplot5DUniform}\nLet us make matrix plots from a uniformly generated  sequence of $100$ points in 5D unit cube $[0,1]^5$ as shown in \\hyperref[F:Twister5489X100x5PlotMatrixFirst6andAll100]{Figure~\\ref*{F:Twister5489X100x5PlotMatrixFirst6andAll100}}.\n\\begin{VrbM}\n>> rand('twister',5489);\n>> % generate a sequence of 1000 points uniformly distributed in 5D unit cube [0,1]X[0,1]X[0,1]X[0,1]X[0,1]\n>> x=rand(1000,5);\n>> x(1:6,:) % first six points in our 5D unit cube, i.e., the first six rows of x\nans =\n    0.8147    0.6312    0.7449    0.3796    0.4271\n    0.9058    0.3551    0.8923    0.3191    0.9554\n    0.1270    0.9970    0.2426    0.9861    0.7242\n    0.9134    0.2242    0.1296    0.7182    0.5809\n    0.6324    0.6525    0.2251    0.4132    0.5403\n    0.0975    0.6050    0.3500    0.0986    0.7054\n>> plotmatrix(x(1:5,:),'r*') % make a plot matrix\n>> plotmatrix(x) % make a plot matrix of all 1000 points\n\\end{VrbM}\n\\end{labwork}\n\n\n\\subsection{Loading and Exploring Real-world Data}\\label{S:EDA}\n\nAll of the data we have played with so far were computer-generated.  It is time to get our hands dirty with real-world data.  The first step is to obtain the data.  \nOften, publicly-funded institutions allow the public to access their databases.  Such data can be fetched from appropriate URLs in one of the two following ways: \n\\begin{itemize}\n\\item[{\\sf Method~A}:] Manually download by filling the appropriate fields in an online request form.\n\\item[{\\sf Method~B}:] Automagically download directly from your \\Matlab session.\n\\end{itemize}\nThen we want to inspect it for inconsistencies, missing values and replace them with {\\tt NaN} values in \\Matlab that stand for not-any-number.  Finally, we can visually explore, transform and interact with the data to discover interesting patterns that are hidden in the data.  This process is called {\\em exploratory data analysis} and is the foundational first step towards subsequent computational statistical experiments [{\\em John W.~Tukey, Exploratory Data Analysis, Addison-Wesely, New York, 1977}].\n\n\\subsection{Geological Data}\n Let us focus on the data of earth quakes that heavily damaged Christchurch on February 22 2011.  This data can be fetched from the URL \\href{http://magma.geonet.org.nz/resources/quakesearch/}{\\url{http://magma.geonet.org.nz/resources/quakesearch/}} by {\\sf Method A} and loaded into \\Matlab for exploratory data analysis as done in \\hyperref[LW:NZEQChCch20110222]{Labwork~\\ref*{LW:NZEQChCch20110222}}.\n \n \\begin{labwork}\\label{LW:NZEQChCch20110222}\nLet us go through the process one step at a time using {\\sf Method~A}.  \n\\begin{enumerate}\n\\item Download the data as a CSV or {\\em comma separated variable} file in plain ASCII text (this has been done for this data already for you and saved as {\\tt NZ20110222earthquakes.csv} in the {\\tt CSEMatlabScripts} directory).\n\\item Open the file in a simple text editor such as {\\tt Note Pad} in Windows or one of the following editors in OS X, Unix, Solaris, Linux/GNU variants such as Ubuntu, SUSE, etc: {\\tt vi}, {\\tt vim}, {\\tt emacs}, {\\tt geany}, etc.  The first three and last two lines of this file look as follows:\n\\begin{VrbM} \nCUSP_ID,LAT,LONG,NZMGE,NZMGN,ORI_YEAR,ORI_MONTH,ORI_DAY,ORI_HOUR,ORI_MINUTE,ORI_SECOND,MAG,DEPTH\n3481751,-43.55432,172.68898,2484890,5739375,2011,2,22,0,0,31.27814,3.79,5.8559,\n3481760,-43.56579,172.70621,2486287,5738106,2011,2,22,0,0,43.70276,3.76,5.4045,\n.\n.\n.\n3469114,-43.58007,172.67126,2483470,5736509,2011,2,22,23,28,11.1014,3.117,3,\n3469122,-43.55949,172.70396,2486103,5738805,2011,2,22,23,50,1.06171,3.136,12,\n\\end{VrbM}\nThe thirteen columns correspond to fairly self-descriptive features of each measured earth quake given in the first line or row.  They will become clear in the sequel.  Note that the comma character (`{\\tt ,}') separates each unit or measurement or descpiption in any CSV file.\n\n\\item The next set of commands show you how to load,  manipulate and visually explore this data.\n\n\\begin{VrbM}\n%% Load the data from the comma delimited text file 'NZ20110222earthquakes.csv' with \n%% the following column IDs\n%% CUSP_ID,LAT,LONG,NZMGE,NZMGN,ORI_YEAR,ORI_MONTH,ORI_DAY,ORI_HOUR,ORI_MINUTE,ORI_SECOND,MAG,DEPTH\n%% Using MATLAB's dlmread command we can assign the data as a matrix to EQ; \n%% note that the option 1,0 to dlmread skips first row of column descriptors\n%\n% the variable EQall is about to be assigned the data as a matrix\nEQall = dlmread('NZ20110222earthquakes.csv', ',' , 1, 0); \nsize(EQall) % report the dimensions or size of the matrix EQall\nans =\n   145    14\n\\end{VrbM}\n\n\\item In order to understand the syntax in detail get {\\tt help} from \\Matlab!\n\\begin{VrbM}\n>> help dlmread\n DLMREAD Read ASCII delimited file.\n .\n .\n .\n \\end{VrbM}\n \n\\item When there are units in the CSV file that can't be converted to floating-point numbers, it is customary to load them as a {\\tt NaN} or {\\em Not-a-Number} value in \\Matlab.  So, let's check if there are any rows with {\\tt NaN} values and remove them from our analysis.  Note that this is not the only way to deal with missing data! After that let's remove any locations outside Christchurch and its suburbs (we can find the latitude and longitude bounds from online resources easily) and finally view the 4-tuples of (latitude, longitude, magnitude, depth) for each measured earth quake in Christchurch on February 22 of 2011 as a scatter plot shown in \\hyperref[F:NZEQ20110222ChchLtLnMgDpScatterMatrixPlot]{Figure~\\ref*{F:NZEQ20110222ChchLtLnMgDpScatterMatrixPlot}} (the axes labels were subsequently added from clicking {\\tt <Edit>} and {\\tt <Figure Properties...>} tabs of the output Figure Window).\n \\begin{VrbM}\n>> EQall(any(isnan(EQall),2),:) = []; %Remove any rows containing NaNs from the matrix EQall\n>> % report the size of EQall and see if it is different from before we removed and NaN containing rows\n>> size(EQall) \nans =   145    14\n>> % remove locations outside Chch and assign it to a new variable called EQ\n>> EQ = EQall(-43.75<EQall(:,2) & EQall(:,2)<-43.45 ... \n              & 172.45<EQall(:,3) & EQall(:,3)<172.9 & EQall(:,12)>3, :);\n>> % now report the size of the earthquakes in Christchurch in variable EQ\n>> size(EQ)\nans =   124    14\n>> % assign the four variables of interest\n>> LatData=EQ(:,2); LonData=EQ(:,3); MagData=EQ(:,12); DepData=EQ(:,13);\n>> % finally make a plot matrix of these 124 4-tuples as red points \n>> plotmatrix([LatData,LonData,MagData,DepData], 'r.');\n\\end{VrbM}\n\\end{enumerate}\nAll of these commands have been put in a script M-file {\\tt NZEQChCch20110222.m} %in \\hyperref[Mf:NZEQChCch20110222]{Labwork~\\ref*{Mf:NZEQChCch20110222}} \nand you can simply call it from the command window to automatically load the data and assign it to the variables {\\tt EQAll} {\\tt EQ}, {\\tt LatData}, {\\tt LonData}, {\\tt MagData} and {\\tt DepData}, instead of retyping each command above every time you need these matrices in \\Matlab, as follows:\n\\begin{VrbM}\n>> NZEQChCch20110222\nans =   145    14\nans =   145    14\nans =   124    14\n\\end{VrbM}\nIn fact, we will do exactly this to conduct more exploratory data analysis with these earth quake measurements in \\hyperref[LW:NZEQChCch20110222EDA]{Labwork~\\ref*{LW:NZEQChCch20110222EDA}}.\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Matrix of Scatter Plots of the latitude, longitude, magnitude and depth of the 22-02-2011 earth quakes in Christchurch, New Zealand.\\label{F:NZEQ20110222ChchLtLnMgDpScatterMatrixPlot}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/NZEQ20110222ChchLtLnMgDpScatterMatrixPlot}}\n\\end{figure}\n\n\n\\begin{labwork}\\label{LW:NZEQChCch20110222EDA}\nTry to understand how to manipulate time stamps of events in \\Matlab and the Figures being output by following the comments in the script file {\\tt NZEQChCch20110222EDA.m}.\n\\begin{VrbM}\n>> NZEQChCch20110222\nans =   145    14\nans =   145    14\nans =   124    14\nans =   145    14\nans =   145    14\nans =   124    14\nans = 22-Feb-2011 00:00:31\nans = 22-Feb-2011 23:50:01\n\\end{VrbM}\n\\VrbMf[label=NZEQChCch20110222EDA.m]{scripts/NZEQChCch20110222EDA.m}\n\\end{labwork}\n\n\\subsubsection{Geostatistical exploratory data analysis with Google Earth}\n\n\\begin{figure}[htpb]\n\\caption{Google Earth Visualisation of the earth quakes\\label{F:NZEQ20110222ChchLtLnMgDpInGoogleEarthViewFromUSGS}}\n\\centering   \\makebox{\\includegraphics[width=4.5in]{figures/NZEQ20110222ChchLtLnMgDpInGoogleEarthViewFromUSGS}}\n\\end{figure}\n\nA global search at \\href{http://neic.usgs.gov/cgi-bin/epic/epic.cgi}{\\url{http://neic.usgs.gov/cgi-bin/epic/epic.cgi}}\n%%?SEARCHMETHOD=1&FILEFORMAT=7&SEARCHRANGE=PP&SYEAR=2011&SMONTH=2&SDAY=22&EYEAR=2011&EMONTH=2&EDAY=22&LMAG=&UMAG=&NDEP1=&NDEP2=&IO1=&IO2=&CLAT=0.0&CLON=0.0&CRAD=0.0&SUBMIT=Submit+Search}\nwith the following parameters:\n\\begin{verbatim}\nDate Range: 2011 2 22 to 2011 2 22 \nCatalog: USGS/NEIC (PDE-Q) \n\\end{verbatim}\nproduced 43 earth quakes world-wide, including those in Christchurch as shown in \\hyperref[F:NZEQ20110222ChchLtLnMgDpInGoogleEarthViewFromUSGS]{Figure~\\ref*{F:NZEQ20110222ChchLtLnMgDpInGoogleEarthViewFromUSGS}}.  One can do a lot more than a mere visualisation with the USGS/NEIC  database of earth-quakes wolrd-wide, the freely available {\\tt Google earth} software bundle \\href{http://www.google.com/earth/index.html}{\\url{http://www.google.com/earth/index.html}} and the freely available \\Matlab package {\\tt googleearth} from \\href{http://www.mathworks.com/matlabcentral/fx_files/12954/4/content/googleearth/html/html_product_page.html}{\\url{http://www.mathworks.com/matlabcentral/fx_files/12954/4/content/googleearth/html/html_product_page.html}}.\n\n\\subsection{Metereological Data}\n\nNew Zealand's meteorological service NIWA provides weather data under it TERMS AND CONDITIONS FOR ACCESS TO DATA (See \\url{http://cliflo.niwa.co.nz/doc/terms_print.html}).  We will explore some data of rainfall and temperatures from NIWA.\n\n\\subsubsection{Daily Rainfalls in Christchurch}\n\n%Rainfall Data in Christchurch\n\nAutomagic downloading of the data by {\\sf Method B} can be done if the data provider allows automated queries.  It can be accomplished by {\\tt urlread} for instance.  %Try to download the file\n\n\n\n%is being  \\work.  But you can t\n\nPaul Brouwers has a basic CliFlo datafeed on \\url{http://www.math.canterbury.ac.nz/php/lib/cliflo/rainfall.php}.  %?range=20100425:20100501\nThis returns the date and rainfall in milli meters as measured from the CHCH aeroclub station. It is assumed that days without readings would not be listed. %It expects a range parameter such as: ?range=20100425:20100501 The first number is the starting search date (YYYYMMDD). Colon as separator. The first number is the ending search date (YYYYMMDD). CliFlo limits us to 2 million rows for the subscription and 40,000 rows per query (which is equivalent of over 100 years of data, so I we're safe - \nThe data doesn't go back much before 1944.\n\n%wetdataURL = 'http://www.math.canterbury.ac.nz/php/lib/cliflo/?range=20100101:20100510' wetdataURL = 'http://www.math.canterbury.ac.nz/php/lib/cliflo/rainfall.php'\n%\\work \n\n\n\\begin{labwork}\\label{LW:ChchDailyRainfallSince}\nUnderstand how \\hyperref[F:ChchDailyRainfallSince]{Figure~\\ref*{F:ChchDailyRainfallSince}} is obtained by the script file {\\tt RainFallsInChch.m} by typing and following the comments:\n\n\\begin{VrbM}\n>> RainFallsInChch\nRainFallsChch =     [24312x1 int32]    [24312x1 double]\nans =       24312           2\nFirstDayOfData =    19430802\nLastDayOfData =    20100721\n\\end{VrbM}\n\n\\VrbMf[label=RainFallsInChch.m]{scripts/RainFallsInChch.m}\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Daily rainfalls in Christchurch since March 27 2010 \\label{F:ChchDailyRainfallSince}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/ChchDailyRainfallSince}}\n\\end{figure}\n\n\\subsubsection{Daily Temperatures in Christchurch}\n\n\n\\begin{labwork}\\label{LW:ChchTempsLoad}\nUnderstand how \\hyperref[F:ChchTemps365DaysSince20100327]{Figure~\\ref*{F:ChchTemps365DaysSince20100327}} is being generated by following the comments in the script file {\\tt ChchTempsLoad.m} by typing:\n\\begin{VrbM}\n>> ChchTempsLoad\n\\end{VrbM}\n\\VrbMf[label=ChchTempsLoad.m]{scripts/ChchTempsLoad.m}\n\\end{labwork}\n\n\\begin{figure}[htpb]\n\\caption{Daily temperatures in Christchurch for one year since March 27 2010 \\label{F:ChchTemps365DaysSince20100327}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/ChchTemps365DaysSince20100327}}\n\\end{figure}\n\n\\subsection{Textual Data}\n\nProcessing and analysing textual data to make a decision is another important computational statistical experiment. An obvious example  is machine translation and a less obvious one is exploratory data analysis of the textual content of \n\\begin{itemize}\n\\item a large document\n\\item twitter messages within an online social network of interest\n\\item etc.\n\\end{itemize}\n\nAn interesting document with a current affairs projection is the Joint Operating Environment 2010 Report by the US Department of Defense.  This document was downloaded from \\href{http://www.jfcom.mil/newslink/storyarchive/2010/JOE_2010_o.pdf}{\\url{http://www.jfcom.mil/newslink/storyarchive/2010/JOE_2010_o.pdf}}.  The first paragraph of this 74 page document (JOE 2010 Reprort) reads:\n\n{\\small\nABOUT THIS STUDY The Joint Operating Environment is intended to inform joint concept development and experimentation throughout the Department of Defense. It provides a perspective on future trends, shocks, contexts, and implications for future joint force commanders and other leaders and professionals in the national security field. This document is speculative in nature and does not suppose to predict what will happen in the next twenty-five years. Rather, it is intended to serve as a starting point for discussions about the future security environment at the operational level of war. Inquiries about the Joint Operating Environment should be directed to USJFCOM Public Affairs, 1562 Mitscher Avenue, Suite 200, Norfolk, VA 23551-2488, (757) 836-6555. \n\nDistribution Statement A: Approved for Public Release\n}\n\n\\begin{figure}[htpb]\n\\caption{Wordle of JOE 2010\\label{F:joe_vs_wordle}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/joe_vs_wordle_RaazCroppedPhilWilsonsImage}}\n\\end{figure}\n\nWe can try to produce a statistic of this document by recording the frequency of words in its textual content. Then we can produce a ``word histogram'' or ``word cloud'' to explore the document visually at one of the coarsest possible resolutions of the textual content in the JOE 2010 Report.  The ``word cloud'' shown in \\hyperref[F:joe_vs_wordle]{Figure~\\ref*{F:joe_vs_wordle}} was produced by Phillip Wilson using {\\em wordle} from \\href{http://www.wordle.net/}{\\url{http://www.wordle.net/}}.  A description from the wordle URL says:\n\n{\\small\nWordle is a toy for generating Òword cloudsÓ from text that you provide. The clouds give greater prominence to words that appear more frequently in the source text. You can tweak your clouds with different fonts, layouts, and color schemes. The images you create with Wordle are yours to use however you like. You can print them out, or save them to the Wordle gallery to share with your friends.\n}\n\n\\begin{labwork}[favourite word cloud]\\label{LW:JoeWordle}  This is just for fun.  Produce a ``word cloud'' of your honours thesis or summer project or any other document that fancies your interest by using {\\em wordle} from \\href{http://www.wordle.net/}{\\url{http://www.wordle.net/}}. Play with the aesthetic features to change colour, shapes, etc.\\end{labwork}\n\n\\subsection{Machine Sensor Data}\n\nInstrumentation of modern machines, such as planes, rockets and cars allow the sensors in the machines to collect live data and dynamically take {\\em decisions} and subsequent {\\em actions} by executing algorithms to drive their devices in response to the data that is streaming into their sensors.  For example, a rocket may have to adjust its boosters to compensate for the prevailing directional changes in wind in order to keep going up and launch a satellite.  \nThese types of decisions and actions, theorised by {\\em controlled Markov processes}, typically arise in various fields of engineering such as, aerospace, civil, electrical, mechanical, robotics, etc.\n\nIn an observational setting, without an associated control problem, one can use machine sensor data to get information about some state of the system or phenomenon, i.e., what is it doing? or where is it?, etc.  Sometimes sensors are attached to a sample of individuals from a  wild population, say Emperor Penguins in Antarctica where the phenomenon of interest may be the diving habits of this species after the eggs hatch.  As an other example we can attach sensors to a double pendulum and find what it is doing when we give it a spin.\n\nBased on such observational data the experimenter typically tries to learn about the behaviour of the system from the sensor data to estimate parameters, test hypotheses, etc. Such types of experiments are typically performed by scientists in various fields of science, such as, astronomy, biology, chemistry, geology, physics, etc.  \n\n\\subsubsection{Chaotic Time Series of a Double Pendulum}\n\n\\begin{figure}[htbp]\n\\begin{center}\n{\\scriptsize\n\\begin{tabular}{ccc}\nA: DP Schematic & B: Streaming DP data & C: Enclosures of two initially close trajectories\\\\\n  \\includegraphics[scale=0.5]{figures/dp} &\n  \\includegraphics[scale=0.66]{figures/vlcsnap-2010-01-13-10h11m08s38_closeup} &\n  \\includegraphics[height=3cm,width=6.75cm]{figures/divergence_piers}\n\\end{tabular}\n}\n\\end{center}\n\\caption{Double Pendulum}\n\\label{F:DP3}\n\\end{figure}\n\nSensors called {\\em optical encoders} have been attached to the top end of each arm of a chaotic double pendulum in order to obtain the angular position of each arm through time as shown in \\hyperref[F:DP3]{Figure~\\ref*{F:DP3}}.  Time series of the angular position of each arm for two trajectories that were initialized very similarly, say the angles of each arm of the double pendulum are almost the same at the initial time of release.  Note how quickly the two trajectories diverge!  System with such a sensitivity to initial conditions are said to be {\\em chaotic}.\n\n\\begin{labwork}[A Challenging Task]\\label{LW:DPtrajectoryparsing}  Try this if you are interested.  Read any of the needed details about the design and fabrication of  the double pendulum at \\href{http://www.math.canterbury.ac.nz/~r.sainudiin/lmse/double-pendulum/}{\\url{http://www.math.canterbury.ac.nz/~r.sainudiin/lmse/double-pendulum/}}.  Then use \\Matlab to generate a plot similar to \\hyperref[F:DP3]{Figure~\\ref*{F:DP3}(C)} using time series data of {\\sf trajectory~1} and {\\sf  trajectory~2} linked from the bottom of the above URL.\n \\end{labwork}\n\n\\comment{\n\\subsection{Biological Data}\n\\work\n}\n\n\\input{ExsInStatistics.tex}\n\n%\\remove\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%% snipped above into csebook\n\n\n%\\newpage\n\n%\\section{Exercises}\\label{Exs:onRV}\n\n%\\begin{ExerciseList}\n\n%\\end{ExerciseList}\n%\\newpage\n", "meta": {"hexsha": "ed8414993b626c34d79d6e2b8f7a11facc8a4694", "size": 266585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/RandomVariables.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/RandomVariables.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/RandomVariables.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 54.5609905853, "max_line_length": 1714, "alphanum_fraction": 0.6702102519, "num_tokens": 96547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695836, "lm_q2_score": 0.8991213772699435, "lm_q1q2_score": 0.7889581290404922}}
{"text": "\\section*{Exercise 26.1-7}\n\\subsubsection*{Show that a flow network $G$ with vertex capacities can be transformed into a normal flow network $G'$. How many vertices and edges does $G'$ have?}\nLet the $G$, $G'$, $v$ and $l$ be defined as in the exercise.\n\nFirst we describes how a network $G_x$ where only one of the vertices, $x$, have a capacity constraint $l(x)$ and how it can be transformed into a new network without the vertex capacity constraint.\n\nWe define the set $E(x)$ of edges that have an edge going into the vertex with a capacity constraint. That is $E(x)  = \\{(v,x) \\in E: l(x)>0\\}$.\n\nTo transform the network, we can augment $G_x$ with a new vertex $x'$ such that  $G_x' = (V',E')$ where $V' = V \\cup \\{x'\\}$. We define $E'$ \nas $E' = E\\setminus E(x) \\cup E'(x) \\cup \\{(x',x)\\}'$ where $E'(x)$ is the set of edges in $E(x)$, but with entrance point into the new vertex $x'$. So the set of edges $E'$ in the new transformed network consist of all edges in the original network, that did not have an edge going into the vertex with a capacity constraint. And all the edges that did go into the vertex with a capacity constraint have been replaced with new edges that goes into the new vertex $x'$. And a new edge have been introduced that goes from the new vertex $x'$ to the old vertex $x$. Hence in total one new vertex and one new edge have been introduced and none have been removed.\n\n\\begin{figure}[H]\n\\caption{\\textit{Augmenting the network $G_x$ to $G_x'$}}\n\\vskip .2cm\n\\centering\n\\subfloat[Introducing the new vertex $x'$]{\\includegraphics[angle=0,width=12cm]{26-1-7}}\n\\end{figure}\n\nThe capacity of the edges in the transformed network, where no vertex have a capacity is\n\\begin{align*}\nc_{G_x'}(u,v) = \n\\begin{cases}\nc_{G_x}(u,x), & (u,v) = (u,x')\\\\\nl(x), & (u,v) = (x',x)\\\\\nc_{G_x}(u,v), & \\text{else}\n\\end{cases}\n\\end{align*}\nThat is, the capacity for an edge going into $x'$ is the same as the capacity of going into $x$ in the $G_x$ network. The new edge have a capacity of $l(x)$ that is the capacity of the vertex in the $G_x$ network. In all other cases the capacity in the transformed network is the same as in the original network.\n\n\\begin{figure}[H]\n\\caption{\\textit{Augmenting the network $G_x$ to $G_x'$}}\n\\vskip .2cm\n\\centering\n\\subfloat[Setting the edge capacities]{\\includegraphics[angle=0,width=12cm]{26-1-7-withCapacity}}\n\\end{figure}\n\nWe have now shown how a network with a single vertex capacity constraint can be transformed into a new network without a capacity constraint. This can easily be generalized to an arbitrary number of vertex capacity constraint. If $x$ and $x'$ is replaced with $x_i$ and $x'_i$ in the above, all of what we have shown still holds, and for each vertex with a capacity constraint, there will be one new vertex and one new edge. Hence if all of the vertices, including the source and sink, had a constraint there would be $\\abs{V}$ extra vertices and edges. So the total number of vertices in $G'$ would be $2\\abs{V}$ and the total number of edges in $G'$ would be $\\abs{E}+\\abs{V}$.", "meta": {"hexsha": "07ba5c97daaa2b5a63d1c7659796e615fa8dcc5d", "size": 3056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/Ex.26.1.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/Ex.26.1.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/Ex.26.1.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": 82.5945945946, "max_line_length": 679, "alphanum_fraction": 0.7189136126, "num_tokens": 873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8991213671331906, "lm_q1q2_score": 0.7889581287883128}}
{"text": "\\section{Relative Homology}\nFirst, let's recall a little about homology. We showed that homology factors as a functor $\\mathbf{Top}\\to\\mathrm{h}\\mathbf{Top}\\to\\mathbf{GrAb}$. As a corollary:\n\\begin{corollary}\nIf $f:X\\to Y$ is a homotopy equivalence (i.e., an isomorphism in the homotopy category), the induced map on homology $ H_\\ast(f): H_\\ast(X)\\to H_\\ast(Y)$ is an isomorphism. This is the same thing as saying that if $f:X\\to Y$ does not induce an isomorphism on homology, then $f$ can't be a homotopy equivalence. Homology's therefore often used to distinguish spaces.\n\\end{corollary}\n\\begin{example}\nIf $X\\times\\mathbf{R}^n\\to X$ is the projection map, this is a homotopy equivalence because $\\mathbf{R}^n$ is contractible. Therefore, $ H_\\ast(X\\times\\mathbf{R}^n)\\cong H_\\ast(X)$.\n\\end{example}\n\\subsection{Towards computing homology}\nFix a space $W$, and consider the functor $X\\mapsto [W,X]$. This is basically uncomputable - if you could, you'll win a Fields medal! But there's something more that homology has going for it is that it's ``local''. What do we mean by this? Homology is a bit like a measure:\n\t\\begin{enumerate}\n\t\\item If $A\\subseteq X$ is a subspace, then $ H_\\ast(X)$ is related to $ H_\\ast(A)+ H_\\ast(X-A)$. Called the lexseq of a pair.\n\t\\item The homology $ H_\\ast(A\\cup B)$ is like $ H_\\ast(A)+ H_\\ast(B)- H_\\ast(A\\cap B)$. Called the Mayer-Vietoris sequence.\n\t\\end{enumerate}\nThe thing we use is the notion of exact sequences. Let me tell you about exact sequences.\n\\subsection{Exact sequences}\nThis is a story about abelian groups.\n\\begin{definition}\nLet $A\\xrightarrow{i} B\\xrightarrow{p} C$ be a sequence of abelian groups and homomorphisms. We say that the sequence is exact (at $B$) if $\\ker p=\\img i$, i.e., $p\\circ i=0$ with no room for error.\n\\end{definition}\n\\begin{example}\nIf you have a chain complex $\\cdots\\to C_{n+1}\\to C_n\\to C_{n-1}\\to\\cdots$, it's exact at $C_n$ if the homology $ H_n(C)$ in dimension $n$ is zero. So homology is the obstruction to exactness. \n\\end{example}\n\\begin{example}\n$0\\to A\\xrightarrow{i}B$ is exact iff $i$ is injective, and $B\\xrightarrow{p}C\\to 0$ is exact iff $p$ is surjective.\n\\end{example}\nThere's a beautiful book by Eilenberg and Steenrod, published in 1952, which was the founding of algebraic topology.\n\\begin{example}\nIf you have a sequence that's exact at every point, it's called a long exact sequence (henceforth called lexseq in these notes). If you have a sequence like $0\\to A\\xrightarrow{i} B\\xrightarrow{p} C\\to 0$ that's exact, then this is called a short exact sequence (henceforth called sexseq in these notes). This means that $p\\circ i=0$, $i$ is injective, $p$ is surjective. Also, this sequence factors like:\n\t\\begin{equation*}\n\t\\xymatrix{\\ker(p) \\ar[dr] & & \\\\\n\tA\\ar[u]\\ar[r]^i & B\\ar[r]^p\\ar[dr] & C\\\\\n\t & & \\mathrm{coker}(i)\\ar[u]}\n\t\\end{equation*}\nSo $A\\cong \\ker p$ and $B\\cong \\mathrm{coker}(i)$. These things are equivalence to short exactness. \n\\end{example}\nLet's see how this appears in algebraic topology.\n\\begin{definition}\nA pair of spaces is a space $X$ together with subspaces $A\\subseteq X$, denoted $(X,A)$. We have a new category, called $\\mathbf{Top}_2$ where morphisms $(X,A)\\to (Y,B)$ are maps $f:X\\to Y$ that take $A\\to B$. There are two functors $\\mathbf{Top}\\to \\mathbf{Top}_2$, sending $X\\mapsto (X,\\emptyset)$ and $X\\mapsto (X,X)$. There are also two functors back to $\\mathbf{Top}$, sending $(X,A)\\mapsto A$ or $(X,A)\\mapsto X$.\n\\end{definition}\nHow does this behave on the level of chain complexes? If I have a pair $(X,A)$, I get a map $\\Sin_n(A)\\to \\Sin_n(X)$ that's clearly injective. Is this a split monomorphism? Yes, unless $A=\\empty$, because you can choose a point in $A$ and send everything not in $A$ to that point. Let's now apply the free abelian group functor to get $S_n(A)\\to S_n(X)$. Is this a monomorphism? Yes, because monomorphisms are preserved by this functor. This is also split because being a split mono is a categorical property. This is split even when $A=\\empty$ because then $S_n(\\empty)=0$.\n\\begin{definition}\nThe relative $n$-chains is defined as $S_n(X,A):= S_n(X)/S_n(A)$. So we have a sexseq (ses) $0\\to S_n(A)\\to S_n(X)\\to S_n(X,A)\\to 0$. Is $S_n(X,A)$ free abelian if $S_n(X)$ and $S_n(A)$ are? If you have a ses $0\\to A\\to B\\to C\\to 0$ such that $A\\to B$ is split, then it's homework to show that $B\\cong A\\oplus C$. So $C$ must also be free abelian if $B$ and $A$ are; i.e., $S_n(X,A)$ is free abelian.\n\\end{definition}\n\\begin{example}\nConsider $\\Delta^n$, which contains its boundary $\\partial\\Delta^n:=\\bigcup \\img d_i\\simeq S^{n-1}$. We have the identity map $\\iota_n:\\Delta^n\\to \\Delta^n$, the universal $n$-simplex, which is in $\\Sin_n(\\Delta^n)\\subseteq S_n(\\Delta^n)$. Its boundary $\\partial\\iota_n\\in S_{n-1}(\\Delta^n)$, but it actually lands in $S_{n-1}(\\partial\\Delta^n)$. So $\\partial\\iota_n$ is \\emph{not} a boundary in $\\partial\\Delta^n$, as we'll see, but it certainly is a cycle. So it determines a homology class, $[\\partial\\iota_n]$, which, it turns out, generates $ H_{n-1}(\\partial\\Delta^n)\\simeq H_{n-1}(S^{n-1})\\cong\\mathbf{Z}$.\n\nI can think of $\\iota_n\\in S_n(\\Delta^n,\\partial\\Delta^n)$, or rather the class of it mod $S_n(\\partial\\Delta^n)$. It's a relative chain. Is it a cycle? Let's branch off a bit.\n\\end{example}\nConsider the ses $0\\to S_n(A)\\to S_n(X)\\to S_n(X,A)\\to 0$. A $c\\in S_n(X)$ determines a relative cycle if $\\partial c\\in S_{n-1}(A)$. I'm sorry, I've messed this up a little bit. There's so much to say here. I'm getting ahead of myself a little bit here. What I meant to say is, let's think of what $\\partial$ does. We have a map of ses:\n\\begin{equation*}\n\\xymatrix{0\\ar[d]\\ar[r] & S_n(A)\\ar[d]\\ar[r] & S_n(X)\\ar[d]\\ar[r] & S_n(X,A)\\ar@{-->}[d]\\ar[r] & 0\\ar[d]\\\\\n0\\ar[r] & S_{n-1}(A)\\ar[r] & S_{n-1}(X)\\ar[r] & S_{n-1}(X,A)\\ar[r] & 0}\n\\end{equation*}\nDoes the dotted map exist? We can pull $\\overline{c}\\in S_n(X,A)$ to some $c\\in S_n(X)$, and then define $\\partial\\overline{c}$ to be the pushforward of $\\partial c$. Is this well-defined? If $c,c^\\prime$ both map to $\\overline{c}$, then $c-c^\\prime=0$, so there's some $a$ in $S_n(A)$ that is sent to $c-c^\\prime$, and $\\partial$ pushes this forward to say that $\\partial a$ maps to $\\partial(c-c^\\prime)=\\partial c-\\partial c^\\prime$. Since we're quotienting out by $S_{n-1}(A)$, this means that the pushforwards of $\\partial c$ and $\\partial c^\\prime$ are the same. I'll leave it to you (although Professor Miller explained this in detail) to show that $\\partial^2=0$. \n\nNow let's continue. A class $c\\in S_n(X)$ gives a relative cycle if and only if $\\partial c\\in S_{n-1}(A)$ because we want $\\partial c$ in $S_n(X,A)$ to be zero. So $\\iota_n\\in S_n(\\Delta^n,\\partial\\Delta^n)$ is indeed a relative cycle since $\\partial\\iota_n\\in S_{n-1}(\\partial\\Delta^n)$. Similarly, a class $c\\in S_n(X)$ is a relative boundary if and only if there is a $b\\in S_{n+1}(X)$ such that $\\partial b=c\\bmod S_n(A)$, i.e., $\\partial b-c\\in S_n(A)$. So $\\iota_n\\in S_n(\\Delta^n,\\partial\\Delta^n)$ isn't a relative boundary. Therefore $ H_n(\\Delta^n,\\partial\\Delta^n)\\cong\\mathbf{Z}=\\langle[\\iota_n]\\rangle$ where $ H_n(X,A)$ denotes the relative homology. This stuff takes a little bit of time to get used to.\n", "meta": {"hexsha": "eec5f98889d5d7e36cbaf523c4ad219e32c77fec", "size": 7252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-8-relative-homology.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-8-relative-homology.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-8-relative-homology.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": 125.0344827586, "max_line_length": 719, "alphanum_fraction": 0.7003585218, "num_tokens": 2404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765328159726, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7888606526632443}}
{"text": "\\section*{Clustering}\n\\subsection*{k-mean}\n$\\hat{R}(\\mu) = \\hat{R}(\\mu_1,...,\\mu_k) = \\sum_{i=1}^n \\underset{j\\in\\{1,...k\\}}{\\operatorname{min}}||x_i-\\mu_j||_2^2$\\\\\n$\\hat{\\mu} = arg \\underset{\\mu}{\\operatorname{min}}\\hat{R}(\\mu)$\\\\\nnot convex! $\\rightarrow$ only local optimum!\\\\\nchoosing k is difficult (plot)!\\\\\n\\textbf{Algorithm (Lloyd's heuristic):}\\\\\nInitialize cluster centers $\\mu^{(0)} = [\\mu_1^{(0)},...,\\mu_k^{(0)}]$\\\\\nWhile not converged\\\\\n$z_i \\leftarrow arg \\underset{j\\in\\{1,...,k\\}}{min}||x_i - \\mu_j^{(t-1)}||_2^2$; $\\mu_j^{(t)} \\leftarrow \\frac{1}{n_j}\\sum_{i:z_i=j}x_i$\n\n\\subsection*{k-mean++}\n- Start with random data point as center\\\\\n- Add centers 2 to k randomly, proportionally to squared distance to closest selected center\\\\\nfor $j=2$ to $k$:\n$i_j$ sampled with prob.\\\\\n$P(i_j=i) = \\frac{1}{z} \\underset{1\\leq l<j}{min}||x_i-\\mu_l||_2^2$; $\\mu_j \\leftarrow x_{i_j}$", "meta": {"hexsha": "3f16d0d5f60b8c8e20ad3181230a5705984d8645", "size": 890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Clustering.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/Clustering.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/Clustering.tex", "max_forks_repo_name": "meck93/intro_ml_ethz", "max_forks_repo_head_hexsha": "e769cf628739959efd6ded517d80f0f14b5aa39d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.3529411765, "max_line_length": 136, "alphanum_fraction": 0.6280898876, "num_tokens": 360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966702001757, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7888222890774342}}
{"text": "\\documentclass[10pt]{article}\n \n\\usepackage[margin=1in]{geometry} \n\\usepackage{amsmath,amsthm,amssymb, graphicx, multicol, array, enumerate, gensymb}\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\n\\begin{document}\n \n\\title{Mathematics problems}\n\\date{}\n\\maketitle\n\n \\section{Elementary algebra}\n \n\\begin{problem}{1.1}\nSimplify $$\\frac{x^{n+2}}{x^{n-2}}$$\n\\end{problem}\n\n\\begin{problem}{1.2}\nSolve for $x$:\n$$x^{-1}*8=2$$\n\\end{problem}\n\n\\begin{problem}{1.3}\nCalculate the missing value. If $a=5$ and $b=10$ then $(a^b)^0=\\dots$\n\\end{problem}\n\n\\begin{problem}{1.4}\nCalculate\n$$\\frac{\\sqrt{4x}}{\\sqrt{x}}$$\n\\end{problem}\n\n\\begin{problem}{1.5}\nSolve for $x$:\n$$x^2+(x+1)^2=(x+2)^2$$\n\\end{problem}\n\n\\begin{problem}{1.6}\nFind the solution set for the inequality below:\n$$2^x>1024$$\n\\end{problem}\n\n\\section{Functions of one variable}\n\n\\begin{problem}{2.1 (Based on SYD 2.5.6)}\nThe relationship between temperatures measured in Celsius and Fahrenheit is linear. 0\\degree C is equivalent to 32\\degree F and 100\\degree C is the same as 212\\degree F.\n Which temperature is measured by the same number on both scales?\n\\end{problem}\n\n\\begin{problem}{2.2}\nTake the following function $f(x)=5x+4$. Find y if $f(3)=y$.\n\\end{problem}\n\n\\begin{problem}{2.3}\nFind all values of x that satisfy:\n$$x^2-4x+3=0$$\n\\end{problem}\n\n\\begin{problem}{2.4}\nAssume that you invest 10 HUF for 90 years with a yearly compound interest of 2\\%. How much money do you receive 90 years later?\n\\end{problem}\n\n\\begin{problem}{2.5}\nCalculate the following value\n$$e^{\\ln 5}$$\n\\end{problem}\n\n\\section{Calculus}\n\n\\begin{problem}{3.1}\nCalculate the following sum\n$$\\sum\\limits_{i=1}^{\\infty} \\frac{12}{6^i}$$\n\\end{problem}\n\n\\begin{problem}{3.2}\nFind the following limit\n$$\\lim\\limits_{x \\rightarrow 1}\\frac{6^{1-x}}{x}$$\n\\end{problem}\n\n\\begin{problem}{3.3}\nFind the slope of the function $f(x)=x^5-8$ at $x=-3$.\n\\end{problem}\n\n\\begin{problem}{3.4}\nFind the following derivative\n$$\\frac{\\mathrm{d}}{\\mathrm{d}\\, x} \\frac{x^3+2x-1}{x-2}$$\n\\end{problem}\n\n\\begin{problem}{3.5}\nFind the following second derivative\n $$\\frac{\\mathrm{d^2}}{\\mathrm{d}\\, x^2} 4x^4+4x^2$$\n\\end{problem}\n\n\\begin{problem}{3.6}\nFind the following derivative:\n$$\\frac{\\mathrm{d}}{\\mathrm{d}\\, x} \\frac{\\ln x}{e^x}$$\n\\end{problem}\n\n\\begin{problem}{3.7}\nConsider the following function. Find all of its stationary points and classify them as local minima, local maxima or inflection points. Also decide whether it is convex or concave. If it has one or more inflection points then define where it is locally concave or locally convex. (You should create a table like we did in class)\n$$f(x)=3x^2-5x+2$$\n\\end{problem}\n\n\\begin{problem}{3.8}\nLet $f(x,y)=x^2+y^3$. Calculate $f(2,3)$\n\\end{problem}\n\n\\begin{problem}{3.9}\nConsider the following function: $f(x,y)=\\ln(x-y)$. For what combinations of $x$ and $y$ is this function defined?\n\\end{problem}\n\n\\begin{problem}{3.10}\nFind the following partial derivative:\n$$\\frac{\\partial}{\\partial \\, x} x^5+xy^3$$\n\\end{problem}\n\n\\begin{problem}{3.11}\nFind the local maxima or minima of the following function:\n$$f(x,y)=x^2y^2+10$$\n\\end{problem}\n\n\\begin{problem}{3.12}\nSolve the following constrained optimization problem using Lagrange's method:\n$\\max x^2y^2$ s.t. $x+y=10$\n\\end{problem}\n\n\\section{Linear algebra}\n\n\\begin{problem}{4.1}\nTake the following matrices:\n$$A=\\begin{bmatrix} 2 & 6\\\\ 5 & 1 \\\\ 1 & 9\\end{bmatrix}$$\n$$B=\\begin{bmatrix} 1 & 1 & 7\\\\2 & 8 & 2\\end{bmatrix}$$\nWhat is $A \\cdot B$?\n\\end{problem}\n\n\\begin{problem}{4.2}\nTake the following matrices:\n$$A=\\begin{bmatrix} 2 & 2\\\\ 4 & 6 \\\\ 1 & 3\\end{bmatrix}$$\n$$B=\\begin{bmatrix} 1 & 9 & 1\\\\2 & 1 & 2\\end{bmatrix}$$\nWhat is $B \\cdot A$?\n\\end{problem}\n\n\\begin{problem}{4.3}\nWhat is the transpose of the following matrix?\n$$\\begin{bmatrix}7.1 & 9.1 & 4.7\\\\ 2 & 7.8 & 1.1 \\\\ 4 & 4.44 & 0\\end{bmatrix}$$\n\\end{problem}\n\n\\begin{problem}{4.4}\nCalculate the determinant of\n$$\\begin{bmatrix}1 & 9 \\\\ 2 & 8 \\end{bmatrix} $$\n\\end{problem}\n\n\\section{Probability theory}\n\n\\begin{problem}{5.1}\nYou run an experiment where you throw a (regular, 6 sided) dice twice. The first number you get will be the first digit of a two-digit number, while the second number you get will be the second digit of the same two-digit number. What is the sample space of your experiment?\n\\end{problem}\n\n\\begin{problem}{5.2}\nAssume that in a certain country 1\\% of the population uses a certain drug. You have a way to test drug use, which will give you a positive result in 99\\% of the cases where the individual is indeed a drug user and a negative result in 99.5\\% of the cases where the individual doesn't use the drug. What is the probability that a randomly selected citizen will have a positive drug test?\n\\end{problem}\n\n\\begin{problem}{5.3}\nAssume that in a certain country 1\\% of the population uses a certain drug. You have a way to test drug use, which will give you a positive result in 99\\% of the cases where the individual is indeed a drug user and a negative result in 99.5\\% of the cases where the individual doesn't use the drug. What is the probability that someone with a positive drug test is indeed a drug user?\n\\end{problem}\n\\end{document}\n", "meta": {"hexsha": "6ea0f59adfa177ff578023baae4c583efa1edf48", "size": 5306, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exam/mathematics_tasks.tex", "max_stars_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_stars_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_stars_repo_licenses": ["MIT"], "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/mathematics_tasks.tex", "max_issues_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_issues_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_issues_repo_licenses": ["MIT"], "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/mathematics_tasks.tex", "max_forks_repo_name": "kiss-oliver/ba-pre-session-2018-archive", "max_forks_repo_head_hexsha": "7508efa839b8d8ae3adfa5c237bee3176a1de6e6", "max_forks_repo_licenses": ["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.0292397661, "max_line_length": 387, "alphanum_fraction": 0.7020354316, "num_tokens": 1797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7888222876699957}}
{"text": "\\section{Mathematics} \n \nTo perform mathematical operations such as {\\tt max}, and {\\tt rsin}, you may use this Add-on. It provides random number generations and contains a large amount of Mathematical primitives. \n \n \n\\subsection*{abs} \\index{\\verb+abs+} \n \n{\\tt abs} {\\it number} \n\\newline\\newline \nOutput the absolute value of the input \n\\begin{verbatimtab} \n@> print abs -4.78 \n4.78 \n\\end{verbatimtab} \n \n \n\\subsection*{av} \\index{\\verb+av+} \n \n{\\tt av} {\\it thing1 thing2 thing3 thing4 ...} \n\\newline\\newline \nOutput the average value of the input. The input may be a {\\it number} or a {\\it list}. Any input of other types will be ignored. \n\\begin{verbatimtab} \n@> print av 3 6 2 9.6 [3 2 4 0.5] \n3.762 \n\\end{verbatimtab} \n \n\\subsection*{ceil} \\index{\\verb+ceil+} \n \n{\\tt ceil} {\\it number} \n\\newline\\newline \nOutput the smallest integer that is not less than the input. \n\\begin{verbatimtab} \n@> print ceil 4.576\n5 \n\\end{verbatimtab} \n\n\\subsection*{deg2rad} \\index{\\verb+deg2rad+} \n \n{\\tt deg2rad} {\\it number} \n\\newline\\newline \nOutput the equivalent angle in radians for the degree given (converting degrees to radians)\n\\begin{verbatimtab} \n@> print deg2rad 120 \n2.094\n\\end{verbatimtab}\n \n\\subsection*{difference} \\index{\\verb+difference+} \n \n{\\tt difference} {\\it number1 number2} \n\\newline\\newline \nOutput the difference between {\\it number1} and {\\it number2}.\n\\begin{verbatimtab} \n@> print difference 4 5 \n1 \n\\end{verbatimtab}\n\n\\subsection*{dacos} \\index{\\verb+dacos+} \n \n{\\tt dacos} {\\it number} \n\\newline\\newline \nOutput the arccosine of the input given in degrees \n\\begin{verbatimtab} \n@> print dacos 45 \n0.9033\n\\end{verbatimtab}\n\n\\subsection*{dasin} \\index{\\verb+dasin+} \n \n{\\tt dasin} {\\it number} \n\\newline\\newline \nOutput the arcsine of the input given in degrees \n\\begin{verbatimtab} \n@> print dasin 180\nnan\n\\end{verbatimtab}\n\n\\subsection*{datan} \\index{\\verb+datan+} \n \n{\\tt datan} {\\it number} \n\\newline\\newline \nOutput the arctangent of the input given in degrees\n\\begin{verbatimtab} \n@> print datan 45\n0.6658\n\\end{verbatimtab}\n\n\\subsection*{dcos} \\index{\\verb+dcos+} \n \n{\\tt dcos} {\\it number} \n\\newline\\newline \nOutput the cosine of the input given in degrees \n\\begin{verbatimtab} \n@> print dcos 180 \n-1\n\\end{verbatimtab} \n\n\\subsection*{dcosh} \\index{\\verb+dcosh+} \n \n{\\tt rcosh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic cosine of the input given in degrees \n\\begin{verbatimtab} \n@> print dcosh 180\n11.59\n\\end{verbatimtab}\n\n\\subsection*{dsin} \\index{\\verb+dsin+} \n \n{\\tt dsin} {\\it number} \n\\newline\\newline \nOutput the sine of the input given in degrees \n\\begin{verbatimtab} \n@> print dsin 60 \n0.866\n\\end{verbatimtab}\n\n\\subsection*{dsinh} \\index{\\verb+dsinh+} \n \n{\\tt dsinh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic sine of the input given in degrees \n\\begin{verbatimtab} \n@> print dsinh 180\n11.55\n\\end{verbatimtab}\n\n\\subsection*{dtan} \\index{\\verb+dtan+} \n \n{\\tt dtan} {\\it number} \n\\newline\\newline \nOutput the tangent of the input given in degrees \n\\begin{verbatimtab} \n@> print dtan 140 \n-0.8391\n\\end{verbatimtab}\n\n\\subsection*{dtanh} \\index{\\verb+dtanh+} \n \n{\\tt dtanh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic-tangent of the input given in degrees \n\\begin{verbatimtab} \n@> print dtanh 78 \n0.8767\n\\end{verbatimtab}\n\n\\subsection*{erf} \\index{\\verb+erf+} \n \n{\\tt erf} {\\it number} \n\\newline\\newline \nOutput the error function of the input. \n\\begin{verbatimtab} \n@> print erf 4.5 \n1 \n\\end{verbatimtab}\n \n\\subsection*{erfc} \\index{\\verb+erfc+} \n \n{\\tt erfc} {\\it number} \n\\newline\\newline \nOutput the complementary error function of the input. \n\\begin{verbatimtab} \n@> print erfc 4.5 \n1.96616e-10 \n\\end{verbatimtab}\n \n\\subsection*{exp} \\index{\\verb+exp+} \n \n{\\tt exp} {\\it number} \n\\newline\\newline \nOutput the exponential value of the input. \n\\begin{verbatimtab} \n@> print exp 4.7 \n109.95 \n\\end{verbatimtab} \n \n\\subsection*{floor} \\index{\\verb+floor+} \n \n{\\tt floor} {\\it number} \n\\newline\\newline \nOutput the largest integer that is not greater than the input. \n\\begin{verbatimtab} \n@> print floor 4.576 \n4 \n\\end{verbatimtab} \n \n\\subsection*{gamma} \\index{\\verb+gamma+} \n \n{\\tt gamma} {\\it number} \n\\newline\\newline \nOutput the log gamma function of the input. \n\\begin{verbatimtab} \n@> print gamma 4.5 \n2.45374 \n\\end{verbatimtab} \n \n\\subsection*{hypot} \\index{\\verb+hypot+} \n \n{\\tt hypot} {\\it number1 number2} \n\\newline\\newline \nOutput the Euclidean distance function of the input \n\\begin{verbatimtab} \n@> print hypot 2.5 6.8 \n7.245 \n\\end{verbatimtab} \n \n\\subsection*{incr} \\index{\\verb+incr+} \n \n{\\tt incr} {\\it word (number)} \n\\newline\\newline \nIncrement the value stored in a variable by 1 or by the number specified as the second input. The first input must be a known variable name. \n\\begin{verbatimtab} \n@> make \"a 1 \n@> incr \"a -1 \n@> print :a \n0 \n\\end{verbatimtab}\n \n\\subsection*{int} \\index{\\verb+int+} \n \n{\\tt int} {\\it number} \n\\newline\\newline \nOutput a cast of the input into an integer. \n\\begin{verbatimtab} \n@> print int 4.576 \n4 \n\\end{verbatimtab}\n \n\\subsection*{log10} \\index{\\verb+log10+} \n \n{\\tt log10} {\\it number} \n\\newline\\newline \nOutput the logarithm (base 10) of the input. \n\\begin{verbatimtab} \n@> print log10 5000 \n3.699 \n\\end{verbatimtab}\n \n\\subsection*{ln} \\index{\\verb+ln+} \n \n{\\tt ln} {\\it number} \n\\newline\\newline \nOutput the natural logarithm of the input. \n\\begin{verbatimtab} \n@> print ln 5000 \n8.517 \n\\end{verbatimtab}\n \n \n\\subsection*{max} \\index{\\verb+max+} \n \n{\\tt max} {\\it thing1 thing2 thing3 thing4 ...} \n\\newline\\newline \nOutput the maximum value of the inputs.  The inputs may be {\\it numbers} or {\\it lists}. Any input of other types \nwill be ignored. \n\\begin{verbatimtab} \n@> print max 3 6 2 9.6 [3 2 4 0.5] \n9.6 \n\\end{verbatimtab} \n \n\\subsection*{min} \\index{\\verb+min+} \n \n{\\tt min} {\\it thing1 thing2 thing3 thing4 ...} \n\\newline\\newline \nOutput the minimum value of the inputs.  The inputs may be {\\it numbers} or {\\it lists}. Any input of other types \nwill be ignored. \n\\begin{verbatimtab} \n@> print min 3 6 2 9.6 [3 2 4 0.5] \n0.5 \n\\end{verbatimtab}\n \n\\subsection*{minus} \\index{\\verb+minus+} \n \n{\\tt minus} {\\it number} \n\\newline\\newline \nOutput the negative value of the input.  \n\\begin{verbatimtab} \n@> print minus -5 \n5 \n@> print minus 45.78 \n-45.78 \n\\end{verbatimtab}\n \n\\subsection*{product} \\index{\\verb+product+} \n \n{\\tt product} {\\it thing1 thing2 thing3 thing4 ...} \n\\newline\\newline \nOutput the product of all the inputs.  The inputs may be {\\it numbers} or {\\it lists}. Any input of other types \nwill be ignored. \n\\begin{verbatimtab} \n@> print product 3 6 2 9.6 [3 2 4 0.5] \n4147.2 \n\\end{verbatimtab}\n \n\\subsection*{quotient} \\index{\\verb+quotient+} \n \n{\\tt quotient} {\\it number1 number2 } \n\\newline\\newline \nOutput the quotient of {\\it number1} over {\\it number2.} \n\\begin{verbatimtab} \n@> print quotient 5 7 \n0.714 \n\\end{verbatimtab}\n \n\\subsection*{modulo} \\index{\\verb+modulo+} \n \n{\\tt modulo} {\\it number1 number2 } \n\\newline\\newline \nOutput the remainder from performing the integer quotient of {\\it number1} over {\\it number2}. Both numbers must be integers. \n\\begin{verbatimtab} \n@> print modulo 10 2 \n0 \n\\end{verbatimtab}\n \n\\subsection*{power} \\index{\\verb+power+} \n \n{\\tt power} {\\it number1 number2} \n\\newline\\newline \nOutput the power of {\\it number1} by {\\it number2}\n\\begin{verbatimtab} \n@> print power 3.4 5 \n454.354\n\\end{verbatimtab} \n \n\\subsection*{racos} \\index{\\verb+racos+} \n \n{\\tt racos} {\\it number} \n\\newline\\newline \nOutput the arccosine of the input given in radians \n\\begin{verbatimtab} \n@> print racos 0.4 \n1.159 \n\\end{verbatimtab}\n\n\\subsection*{rad2deg} \\index{\\verb+rad2deg+} \n \n{\\tt rad2deg} {\\it number} \n\\newline\\newline \nOutput the corresponding angle in degrees, given the angle in radians  (converting from radians into degrees)\n\\begin{verbatimtab} \n@> print rad2deg 2.094\n120\n\\end{verbatimtab}\n \n\\subsection*{random} \\index{\\verb+random+} \n \n{\\tt random} {\\it (min) max} \n\\newline\\newline \nOutput a random number between the given min and max.  If only one input is given, it will be interpreted as the max and the output will be a number between 0 and max. \n\\begin{verbatimtab} \n@> print random 40 \n15 \n\\end{verbatimtab}\n \n\\subsection*{rcos} \\index{\\verb+rcos+} \n \n{\\tt rcos} {\\it number} \n\\newline\\newline \nOutput the cosine of the input given in radians \n\\begin{verbatimtab} \n@> print rcos 60 \n-0.952 \n\\end{verbatimtab}\n \n\\subsection*{rcosh} \\index{\\verb+rcosh+} \n \n{\\tt rcosh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic cosine of the input given in radians \n\\begin{verbatimtab} \n@> print rcosh 0.56 \n1.160 \n\\end{verbatimtab}\n \n\\subsection*{rasin} \\index{\\verb+rasin+} \n \n{\\tt rasin} {\\it number} \n\\newline\\newline\nOutput the arcsine of the input given in radians \n\\begin{verbatimtab} \n@> print rasin 0.4 \n0.411 \n\\end{verbatimtab}\n \n\\subsection*{rsin} \\index{\\verb+rsin+} \n \n{\\tt rsin} {\\it number} \n\\newline\\newline \nOutput the sine of the input given in radians \n\\begin{verbatimtab} \n@> print rsin 60 \n-0.304 \n\\end{verbatimtab}\n \n\\subsection*{rsinh} \\index{\\verb+rsinh+} \n \n{\\tt rsinh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic sine of the input given in radians \n\\begin{verbatimtab} \n@> print rsinh 0.56 \n0.589 \n\\end{verbatimtab}\n \n\\subsection*{ratan} \\index{\\verb+ratan+} \n \n{\\tt ratan} {\\it number} \n\\newline\\newline \nOutput the arctangent of the input given in radians \n\\begin{verbatimtab} \n@> print ratan 0.6 \n0.540 \n\\end{verbatimtab}\n \n\\subsection*{rtan} \\index{\\verb+rtan+} \n \n{\\tt rtan} {\\it number} \n\\newline\\newline \nOutput the tangent of the input given in radians \n\\begin{verbatimtab} \n@> print rtan 60 \n0.32 \n\\end{verbatimtab}\n \n\\subsection*{rtanh} \\index{\\verb+rtanh+} \n \n{\\tt rtanh} {\\it number} \n\\newline\\newline \nOutput the hyperbolic tangent of the input given in radians \n\\begin{verbatimtab} \n@> print rtanh 0.7 \n0.604 \n\\end{verbatimtab}\n \n\\subsection*{sqrt} \\index{\\verb+sqrt+} \n \n{\\tt sqrt} {\\it number} \n\\newline\\newline \nOutput the square root of the input. \n\\begin{verbatimtab} \n@> print sqrt 25 \n5 \n\\end{verbatimtab} \n \n\\subsection*{sum} \\index{\\verb+sum+} \n \n{\\tt sum} {\\it thing1 thing2 thing3 thing4 ...} \n\\newline\\newline \nOutput the sum of the all the inputs.  The inputs may be {\\it numbers} or {\\it lists}. Any input of other types \nwill be ignored. \n\\begin{verbatimtab} \n@> print sum 3 6 2 9.6 [3 2 4 0.5] \n30.01 \n\\end{verbatimtab}\n", "meta": {"hexsha": "327fe6ac441bab0c2e2209b326187e1d4fdc5259", "size": 10361, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/Documents/Manuals/Guide/math.tex", "max_stars_repo_name": "clasqm/Squirrel99", "max_stars_repo_head_hexsha": "09fb4cf9c26433b5bc1915dee1b31178222d9e81", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-01-26T14:35:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-31T10:39:39.000Z", "max_issues_repo_path": "documentation/Documents/Manuals/Guide/math.tex", "max_issues_repo_name": "clasqm/Squirrel99", "max_issues_repo_head_hexsha": "09fb4cf9c26433b5bc1915dee1b31178222d9e81", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-12-12T17:04:17.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-12T17:04:17.000Z", "max_forks_repo_path": "documentation/Documents/Manuals/Guide/math.tex", "max_forks_repo_name": "clasqm/Squirrel99", "max_forks_repo_head_hexsha": "09fb4cf9c26433b5bc1915dee1b31178222d9e81", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-26T08:56:12.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-26T08:56:12.000Z", "avg_line_length": 22.7714285714, "max_line_length": 189, "alphanum_fraction": 0.7002219863, "num_tokens": 3429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966732132748, "lm_q2_score": 0.8333245911726381, "lm_q1q2_score": 0.7888222857108316}}
{"text": "\\newpage  \n\\section{Introduction to logistic regression}\nIn this section, we introduce techniques related to basic logistic regression, see \\cite{gelman2006data} for more details.\n\\subsection{Logistic regression}\\label{sec:LR}\n%We first introduce the next definition of the set of linearly classifiable weights.\n\nAssume that we are given $k$ linearly separable sets $A_1,A_2,\\cdots,A_k\\in \\mathbb{R}^d$, we define the set of classifiable weights as\n\t\\begin{equation}\n\t\\bm\\Theta = \\{\\bm\\theta = (W,b): w_ix+b_i>w_jx+b_j,~\\forall x\\in A_i, j\\neq i, i= 1,\\cdots,k\\}\n\t\\end{equation}\n\twhich means those $(W,b)$ can separate $A_1,A_2,\\cdots,A_k$ correctly. \n\t\n\nOur linearly separable assumption implies that $\\bm\\Theta\\neq \\emptyset$. \nNow we know the existence of linearly classifiable weights. But how can we find one element in $\\bm\\Theta$?\n\n\\begin{definition}[soft-max]\\label{softmax}\n Given $s = (s_1,s_2,\\cdots,s_k)^T\\in \\mathbb{R}^k$, we define the soft-max mapping $\\sigma: \\mathbb{R}^k \\rightarrow\\mathbb{R}^k $ as\n \\begin{equation}\n \\sigma(s)  = \\frac{e^{s}}{e^{s}\\cdot \\bm{1}} = \\frac{1}{\\sum\\limits_{i=1}^k e^{s_i}}\n \\begin{pmatrix}\n e^{s_1}\\\\\n e^{s_2}\\\\\n \\vdots\\\\\n e^{s_k}\n \\end{pmatrix}\n \\end{equation}\n where $e^{s} = \n \\begin{pmatrix}\n e^{s_1}\\\\\n e^{s_2}\\\\\n \\vdots\\\\\n e^{s_k}\n \\end{pmatrix}\n $, $\\bm{1} = \n \\begin{pmatrix}\n 1\\\\\n 1 \\\\\n \\vdots \\\\\n 1\n \\end{pmatrix} \\in\\mathbb{R}^k$.\n\\end{definition}\n\n\n\\begin{definition}\n Given parameter $\\bm\\theta = (W,b)$, we define a feature mapping $\\bm p: \\mathbb{R}^d \\rightarrow \\mathbb{R}^k$ as\n \\begin{equation}\n \\bm p(x; \\bm\\theta)  = \\sigma(Wx+b) = \\frac{1}{\\sum\\limits_{i=1}^k e^{w_i x+b_i}}\n \\begin{pmatrix}\n e^{w_1 x+b_1}\\\\\n e^{w_2 x+b_2}\\\\\n \\vdots\\\\\n e^{w_k x+b_k}\n \\end{pmatrix}\n = \\begin{pmatrix}\n p_1(x; \\bm\\theta) \\\\\n p_2(x; \\bm\\theta) \\\\\n \\vdots \\\\\n p_k(x; \\bm\\theta)\n \\end{pmatrix}\n \\end{equation}\n where the $i$-th component \n \\begin{equation}\\label{key}\n p_i(x; \\bm\\theta) = \\frac{e^{w_i x+b_i}}{\\sum\\limits_{i=1}^k e^{w_i x+b_i}}.\n \\end{equation}\n\\end{definition}\n\n\n\nThe soft-max mapping have several important properties.\n\\begin{enumerate}\n\t\\item \n\t$\\displaystyle 0< p_i(x; \\bm\\theta) <1,~\\sum_i p_i(x; \\bm\\theta) = 1$. \n\t\n\tThis implies that $\\bm p(x; \\bm\\theta)$ can be regarded as a probability distribution of data points which means that given $x\\in \\mathbb{R}^d$, we have $x\\in A_i$ with probability $p_i(x; \\bm{\\theta})$, $i = 1,\\cdots,k$. \n\t\\item \n\t$p_i(x; \\bm\\theta)>p_j(x; \\bm\\theta)\\Leftrightarrow w_ix+b_i>w_j x+b_j.$\n\t\n\tThis implies that the linearly classifiable weights have an equivalent description as\n\t\\begin{equation}\n\t\\bm{\\Theta} = \\left\\{\\bm\\theta: p_i(x; \\bm\\theta)>p_j(x; \\bm\\theta),~\\forall x\\in A_i, j\\neq i, i= 1,\\cdots,k\\right\\}\n\t\\end{equation}\n\t\\item We usually use the max-out method to do classification. For a given data point $x$, we first use a soft-max mapping to map it to $\\bm p(x; \\bm\\theta)$, then we attach $x$ to the class $i= \\arg\\max_j p_i(x; \\bm\\theta)$. \n\t\n\tThis means that we pick the label $i$ as the class of $x$ such that $x\\in A_i$ has the biggest probability $p_i(x; \\bm\\theta)$.\n\\end{enumerate}\nMore detailed discussion of logistic regression from the probability perspective will be presented in the nearly future. \n\nFrom the above properties, we can define the following likelihood function to help find elements in $\\bm{\\Theta}$:\n\\begin{equation}\nP (\\bm\\theta)=\n\\prod\\limits_{i = 1}^k \\prod\\limits_{x\\in A_i} p_i(x; \\bm\\theta).\n\\end{equation} \n%The next lemma shows that we can use this function to help us find some linearly classifiable weights.\n%\\begin{theorem}\\label{thm1-H}\n%\tIf $ \\bm \\theta \\notin \\Theta$, then there exists $ \\bm \\theta^* \\in\\bm \\Theta$ such that \n%\t\\begin{equation}\\label{key}\n%\tH( \\bm \\theta^*) > H(\\bm \\theta).\n%\t\\end{equation}\n%\\end{theorem}\nBased on the property that\n\\begin{equation}\\label{key}\np_i (x; \\bm \\theta) = \\max_{1\\le j \\le k} p_j(x; \\bm \\theta), \\quad\\forall x \\in A_i,\\ \\bm \\theta \\in \\Theta,\n\\end{equation}\nwe may use the next optimization problem\n\\begin{equation}\\label{key}\n\\max_{\\bm \\theta\\in \\bm{\\Theta}} P(\\bm \\theta).\n\\end{equation}\nto find an element in $\\bm{\\Theta}$. \nMore precisely, let us introduce the next lemmas (properties) of $P(\\bm \\theta)$.\n\\begin{lemma}\\label{lemm:H1/2}\n\tAssume that the sets $A_1,A_2,\\cdots,A_k$ are linearly separable. Then we have\n\t\\begin{equation}\n\t\\left\\{\\bm \\theta:~P(\\bm\\theta)>\\frac{1}{2}\\right\\}\\subset \\bm{\\Theta}.\n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tIt suffices to show that if $\\bm\\theta \\not\\in \\bm\\Theta$, we must have $P(\\bm\\theta)\\leq\\frac{1}{2}$.\n\tFor any $\\bm\\theta \\not\\in\n\t\\bm\\Theta$, there must exist an $i_0$ ,an $x_0\\in A_{i_0}$ and a\n\t$j_0\\neq i_0$ such that\n\t\\begin{equation}\n\tw_{i_0} x_0 + b_{i_0} \\leq w_{j_0}x_0 + b_{j_0}.\n\t\\end{equation}\n\tThen we have\n\t\\begin{equation}\n\tp_{i_0}(x_0; \\bm\\theta) \\leq \\frac{e^{w_{i_0} x_0 + b_{i_0}}}{e^{w_{i_0} x_0+b_{i_0}}+e^{w_{j_0} x_0+b_{j_0}}} \\leq\\frac{1}{2}.\n\t\\end{equation}\n\tNotice that $p_i(x; \\bm \\theta) < 1$ for all $i = 1,\\cdots,k$, $x\\in A$.\n\tSo\n\t\\begin{equation}\n\tP(\\bm\\theta) <  p_{i_0}(x_0; \\bm\\theta) \\leq \\frac{1}{2}.\n\t\\end{equation}\n\\end{proof}\n\n\\begin{lemma}\n\tIf $A_1,A_2,\\cdots,A_k$ are linearly separable and $\\bm\\theta \\in \\bm\\Theta$, we have\n\t\\begin{equation}\n\t\\lim_{\\alpha\\rightarrow +\\infty}p_i(x; \\alpha\\bm\\theta) = 1\\Leftrightarrow x\\in A_i. \n\t\\end{equation}\n\\end{lemma}\n\\begin{proof}\n\tWe first note that if  $x\\in A_i$,\n\t\\begin{equation}\n\t p_i(x,\\bm \\theta) = \\frac{1}{1+\\sum\\limits_{j\\neq i}e^{\\alpha[(w_j x+ b_j)-(w_i x+b_i)]}} \\to 1, \\quad \\text{as} \\quad \\alpha \\to \\infty.\n\t\\end{equation}\n\tOn the other hand, if $x\\not\\in A_i$, \n\t\\begin{equation}\n\tp_i(x; \\bm\\alpha\\bm\\theta) = \\frac{1}{1+\\sum\\limits_{j\\neq i}e^{\\alpha[(w_j x+ b_j)-(w_i x+b_i)]}} \\leq \\frac{1}{2}.\n\t\\end{equation}\n\tThis implies that if $x\\not\\in A_i$, $\\lim_{\\alpha\\rightarrow \\infty}p_i(x; \\alpha\\bm \\theta)\\neq 1$ which is equivalent to the proposition that if $\\lim_{\\alpha\\rightarrow \\infty}p_i(x; \\alpha\\bm \\theta)= 1$, then $x\\in A_i$.\n\\end{proof}\n\n\\begin{lemma}{\\label{thm2}} If $A_1,A_2,\\cdots,A_k$ are linearly separable, \n\t\\begin{equation}\n\t\\bm\\Theta = \\left\\{\\bm\\theta: \\lim_{\\alpha\\rightarrow +\\infty}P(\\alpha\\bm\\theta) = 1\\right\\}.\n\t\\end{equation}\n\\end{lemma}\n\n\\begin{proof}\n \tWe first note that if $\\bm\\theta \\in\\bm\\Theta$, we have $\\displaystyle\\lim_{\\alpha\\rightarrow +\\infty}p_i(x; \\alpha\\bm\\theta) = 1$ for all $x\\in A_i$. So\n\t\\begin{equation}\n\t\\lim\\limits_{\\alpha\\rightarrow +\\infty} P(\\alpha\\bm\\theta) = \\lim\\limits_{\\alpha\\rightarrow +\\infty} \\prod\\limits_{i = 1}^k \\prod\\limits_{x\\in A_i} p_i(x; \\alpha\\bm\\theta) = \\prod\\limits_{i = 1}^k \\prod\\limits_{x\\in A_i} \\lim\\limits_{\\alpha\\rightarrow +\\infty}p_i(x; \\alpha\\bm\\theta) = 1.\n\t\\end{equation}\n\tOn the other hand, if $\\lim\\limits_{\\alpha\\rightarrow +\\infty} P(\\alpha\\bm\\theta) = 1$, there must exist one $\\alpha_0>0$ such that $P(\\alpha_0\\bm\\theta) >\\frac{1}{2}$. From Lemma~\\ref{lemm:H1/2}, we have $\\alpha_0\\bm\\theta\\in\\bm\\Theta$, which means $\\bm\\theta\\in\\bm\\Theta$.\n\\end{proof}\n\n\nThese properties above imply that if we can obtain a classifiable weight through maximizing $P(\\bm\\theta)$, while lemma \\ref{thm2} tells us that $P(\\bm\\theta)$ will not have a global minimum actually.\n\nMore specifically, we just need to find some $\\bm \\theta \\in \\Theta$ such that\n\\begin{equation}\\label{key}\nP(\\bm \\theta) > \\frac{1}{2} \\Leftrightarrow  L(\\bm \\theta) : = -\\log P(\\bm \\theta )  < \\log(2).\n\\end{equation}\n%{\\bf Question:} how to find these element?\n\n\\blankpage\n\\break\n\\subsection{Regularized logistic regression}\nHere, we start from the regularization term $e^{-\\lambda R(\\|\\bm\\theta\\|)}$ with \nthese next properties:\n\\begin{enumerate}\n\t\\item $\\lambda > 0$.\n\t\\item $R(t)$ is a strictly increasing function on $\\mathbb{R}^+$ with $R(0) = 0$, $\\lim\\limits_{t\\rightarrow +\\infty} R(t) = +\\infty$.\n\tFor example, $R(t) = t^2$.\n\t\\item $\\|\\cdot\\|$ is a norm on $R^{k\\times(d+1)}$, a commonly used norm  is the \n\tfollowing Frobenius norm: \n\t\\begin{equation}\\label{key}\n\t\\|\\bm \\theta\\|_F = \\sqrt{\\sum_{i,j}W_{ij}^2 + \\sum_i b_i^2}.\n\t\\end{equation}\n\\end{enumerate}\n\nBased on this regularization term,  we may consider the following \nregularized likelihood function $P_\\lambda(\\bm\\theta)$ as \n\\begin{equation}\\label{key}\n P_\\lambda(\\bm\\theta) = P(\\bm\\theta)e^{-\\lambda R(\\|\\bm\\theta\\|)}.\n\\end{equation}\n\n\nHere, let us define \n\\begin{equation}\\label{key}\n\\bm\\Theta_{\\lambda} = \\mathop{{\\arg\\max}}_{\\bm\\theta}  P_\\lambda(\\bm\\theta),\n\\end{equation}\nwhere \n\\begin{equation}\\label{key}\n\\mathop{\\arg\\max}_{\\bm\\theta}  P_\\lambda(\\bm\\theta) = \\left\\{\\bm \\theta ~:~ P_\\lambda(\\bm \\theta) = \\max_{\\bm \\theta} P_\\lambda(\\bm \\theta) \\right\\}.\n\\end{equation}\n\n\nThe next lemma show that the maximal set of modified objective is not empty.\n\\begin{lemma}Suppose that $A_1,A_2, \\cdots, A_k$ are linearly separable, then\n\t\\begin{enumerate}\n\t\t\\item if $\\lambda = 0$, $\\bm\\Theta_0 = \\emptyset$,\n\t\t\\item $\\bm\\Theta_{\\lambda}$ must be nonempty for all $\\lambda>0$.\n\t\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\tLemma~\\ref{thm2} shows the first proposition. For the second proposition, \n\twe notice that \n\t\\begin{enumerate}\n\t\t\\item $ P_\\lambda(\\bm 0) = \\frac{1}{k^N}$.\n\t\t\\item $\\exists\\ M_{\\lambda}>0$ such that $e^{-\\lambda R(\\|\\bm\\theta\\|)}<\\frac{1}{k^N}$ whenever $\\|\\bm\\theta\\|> M_{\\lambda}$ because of the properties of $R(\\|\\bm\\theta\\|)$.\n\t\\end{enumerate}\n\tSo a maxima on $\\{\\bm\\theta: \\|\\bm\\theta\\| \\le M_{\\lambda}\\}$ must be a global maxima. Then we can easily obtain the result in the lemma from the boundedness and closeness of $\\{\\bm\\theta: \\|\\bm\\theta\\| \\le M_{\\lambda}\\}$.\n\\end{proof}\n\nFurthermore, we have the next theorem which shows that we can indeed get $\\Theta$ by maximizing $P_\\lambda(\\bm \\theta)$.\n\\begin{theorem}\\label{thm-L-Theta} If $A_1,A_2,\\cdots,A_k$ are linearly separable, \n\t\\begin{equation}\\label{key}\n\t\\bm\\Theta_{\\lambda} \\subset \\bm\\Theta,\n\t\\end{equation}\nwhen $\\lambda>0$ and sufficiently small.\n\\end{theorem}\n\\begin{proof}\nBy Lemma~\\ref{lemm:H1/2}, we can take $\\bm\\theta_0\\in \\bm\\Theta$ such that $P(\\bm\\theta_0)> \\frac{3}{4}$.\nThen, for any $\\lambda < \\frac{\\log \\frac{3}{2}}{R(\\|\\bm\\theta_0\\|)}$, $\\bm\\theta_{\\lambda}\\in \\bm\\Theta_{\\lambda}$, we have\n\t\t\\[\n\t\tP(\\bm\\theta_{\\lambda}) \\geq  P_\\lambda(\\bm\\theta_{\\lambda})  \\geq P_\\lambda(\\bm \\theta_0) = P(\\bm\\theta_0)e^{-\\lambda R(\\|\\bm\\theta_0\\|)} > \\frac{3}{4}\\cdot \\frac{2}{3} = \\frac{1}{2},\n\t\t\\]\n\t\twhich implies that $\\bm \\theta_{\\lambda} \\in \\Theta$.\n\t\tThus, for any $ 0< \\lambda < \\frac{\\log \\frac{3}{2}}{R(\\|\\bm\\theta_0\\|)}$, $\\bm\\Theta_{\\lambda} \\subset \\bm\\Theta$.\n\n\\end{proof}\n\n\nThe design of logistic regression is that \nmaximize $P_\\lambda(\\bm\\theta)$ is equivalent to minimize $-\\log P_\\lambda(\\bm\\theta)$, i.e.,\n\\begin{equation}\\label{key}\n\\max_{\\bm \\theta} \\left\\{ P_\\lambda(\\bm\\theta) \\right\\} \\Leftrightarrow \\min_{\\bm \\theta} \\left\\{ -\\log   P_\\lambda(\\bm\\theta)\\right\\},\n\\end{equation}\nwhile the second one is more convenient to evaluate the gradient. Meanwhile, we add a regularization term $R(\\bm\\theta)$ to the objective function which makes the optimization problem has a unique solution. \n\n Mathematically, we can formulate Logistic regression as\n\\begin{equation}\n\\min_{\\bm\\theta} L_\\lambda(\\bm \\theta),\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:logisticlambda}\nL_\\lambda(\\bm \\theta)  := -\\log P_\\lambda(\\bm\\theta) = -\\log P(\\bm\\theta) + \\lambda R(\\|\\bm\\theta\\|) = L(\\bm\\theta) + \\lambda R(\\|\\bm\\theta\\|),\n\\end{equation}\nwith\n\\begin{equation}\\label{logistic}\nL(\\bm \\theta) = - \\sum_{i=1}^k \\sum_{x\\in A_i} \\log p_{i}(x;\\bm \\theta).\n\\end{equation}\n\n\n\nThen we have the next logistic regression algorithm.\n\\begin{algorithm}[H]\n\t\\caption{Logistic Regression} \n\t\\label{alg:LR-R}\n\tGiven data $A_1, A_2, \\cdots, A_k$, find \n\t\\begin{equation}\\label{key}\n\t\\bm \\theta^* = \\mathop{\\arg\\min}_{\\bm \\theta}  L_\\lambda(\\bm \\theta),\n\t\\end{equation}\n\tfor some sufficient small $\\lambda > 0$.\n\\end{algorithm}\n\n\\begin{remark}\n\tHere\n\t\\begin{equation}\\label{key}\n\tL(\\bm \\theta)  = -\\log P(\\bm\\theta),\n\t\\end{equation}\n\tis known as the loss function of logistic regression model.\n\tThe next reasons may show that why $L(\\bm \\theta)$ is popular.\n\t\\begin{enumerate}\n\t\t\\item It is more convenient to take gradient for $L(\\bm \\theta)$ than $P(\\bm \\theta)$.\n\t\t\\item $L(\\bm \\theta)$ is related the so-called cross-entropy \n\t\tloss function which will be discussed in the next section.\n\t\t\\item $L(\\bm \\theta)$ is a convex function which will be discussed later.\n\t\\end{enumerate}\n\\end{remark}\n\n\n\n\\endinput\n\\begin{lemma}\n\tIf $A_1,A_2,\\cdots,A_k$ are linearly separable, $-\\log H(\\bm\\theta)$ has no global minimum.\n\\end{lemma}\n\n\\begin{theorem}\n\t$-\\log P(\\bm\\theta) + \\lambda R(\\bm\\theta)$ has a global minimizer for sufficiently small $\\lambda>0$. \n\\end{theorem}\n\n\nDenote the above objective function as\n\\begin{equation}\nL(\\theta,\\alpha) = \\alpha (\\max_i \\|w_i\\|_2) + \\displaystyle\\sum_{i=1}^k \\displaystyle\\sum_{x\\in A_i} \n\\left(\\log(\\mathbbm{1}^T\\exp(W x + b)) - (W x + b)_i\\right)\n\\end{equation}\nwhere $\\theta = (W,b)$. And we denote a linear separable parameter set $\\Theta$ as\n\\begin{equation}\n\\Theta = \\{\\theta~|w_ix + b_i > w_jx + b_j, x\\in A_i,~j\\neq i\\}\n\\end{equation}\nSet\n\\begin{equation}\np_i(\\theta,x) = \\frac{e^{w_i x+b_i}}{\\sum\\limits_{j=1}^k e^{w_j x+b_j}},   \\forall i = 1,\\cdots,k.\n\\end{equation}\nand define the LR classifiable parameter set $\\bar{\\Theta}$ as\n\\begin{equation}\n\\bar{\\Theta} = \\{\\theta~|p_i(\\theta,x)>p_j(\\theta,x), ~x\\in A_i,~j\\neq i\\}\n\\end{equation}\nEasy to observe that \n\\begin{equation}\n\\Theta = \\bar{\\Theta}\n\\end{equation}\n\n\n\n\n\\begin{theorem}\n\tAssume that $R(\\theta)\\geq 0$ is an non-negative function such that \n\t\\begin{equation}\n\t\\Theta^*(\\lambda)={\\rm argmax}\\ P(\\theta)e^{-\\lambda R(\\theta)} \\neq \\emptyset, \\quad \\forall \\lambda>0\n\t\\end{equation}\n\tthen for sufficiently small $\\lambda>0$, \n\t$$ \\Theta^*(\\lambda)\\subset \\left\\{ \\theta: P(\\theta)\\geq \\frac{1}{2} \\right\\}\\subset \\Theta.$$\n\\end{theorem}\n\n\\begin{proof}\n\tGiven $\\theta_0\\in\\Theta$. Let $\\alpha >0$ be such that \n\t$$P(\\alpha \\theta_0)\\geq \\frac{2}{3}$$\n\tLet $\\lambda>0$ be sufficiently small such that \n\t$$e^{-\\lambda R(\\theta)}>\\frac{3}{4}$$\n\tFor any $\\theta \\in \\Theta^*$  \n\t$$\n\tP(\\theta)e^{-\\lambda R(\\theta)} \\geq P(\\alpha \\theta_0) e^{-\\lambda R(\\alpha\\theta_0)} > \\frac{2}{3}\\cdot \\frac{3}{4}=\\frac{1}{2}$$\n\tThen $P(\\theta)>\\frac{1}{2}$.\n\\end{proof}  \n", "meta": {"hexsha": "954055ada78860533122da287fac865e60eb044e", "size": 14345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/2 Linear Machine Learning Models/2.2-IntroLR.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/2 Linear Machine Learning Models/2.2-IntroLR.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/2 Linear Machine Learning Models/2.2-IntroLR.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": 40.9857142857, "max_line_length": 289, "alphanum_fraction": 0.6704078076, "num_tokens": 5363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.905989822921759, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7887522680832826}}
{"text": "\n\\section{The \\upperbound algorithm}\n\\Label{sec:upperbound}\n\nThe \\upperbound algorithm of the \\cxx Standard Library \\cite[\\S 28.7.3.2]{cxx-17-draft} is a\nvariant of binary search and closely related to \\specref{lowerbound}.\nThe signature reads:\n\n\\begin{lstlisting}[style = acsl-block]\n\n  size_type \n  upper_bound(const value_type* a, size_type n, value_type v)\n\\end{lstlisting}\n\nAs with the other binary search algorithms, \\upperbound requires that\nits input array is in increasing order.\nThe index~\\inl{ub} returned by \\upperbound satisfies the inequality\n\n\\begin{align}\n\\Label{eq:upper-bound-result}\n0 \\leq \\mathtt{ub} \\leq n  \n\\end{align}\n\nand is involved in the following implications for a valid index~\\inl{k} of the array\nunder consideration\n\n\\begin{alignat}{3}\n\\Label{eq:upper-bound-left}\n0 &\\leq k < \\mathtt{ub} &&\\qquad\\Longrightarrow\\qquad && a[k] \\leq \\mathtt{v} \\\\\n\\Label{eq:upper-bound-right}\n\\mathtt{ub} &\\leq k < n &&\\qquad\\Longrightarrow\\qquad &&\\mathtt{v} < a[k]\n\\end{alignat}\n\nConditions~\\eqref{eq:upper-bound-left} and~\\eqref{eq:upper-bound-right} imply that~\\inl{v}\ncan only occur in the array section \\inl{a[0..ub-1]}.\nIn this sense \\upperbound returns a \\emph{upper bound} for the\npotential indices where \\inl{v} can occur.\nIt also means that the searched-for value \\inl{v} can\n\\emph{never} be located at the index~\\inl{ub}.\n\nFigure~\\ref{fig:upperbound} is a variant of Figure~\\ref{fig:lowerbound} for the case\nof \\upperbound and the same example array.\nThe arrows indicate which indices will be returned by \\upperbound for a given value.\nNote how, compared to Figure~\\ref{fig:lowerbound}, only the arrows from values\nthat \\emph{are present} in the array change their target index.\n\n\\begin{figure}[hbt]\n\\centering\n\\includegraphics[width=0.60\\textwidth]{Figures/upper_bound.pdf}\n\\caption{\\Label{fig:upperbound}Some examples for \\upperbound}\n\\end{figure}\n\n\\FloatBarrier\n\n\\subsection{Formal specification of \\upperbound}\n\nThe following listing shows the specification of \\specref{upperbound} which\nis quite similar to the specification of \\specref{lowerbound}.\nThe precondition \\inl{increasing} expresses\nthat the array values need to be in increasing order.\n\nThe postconditions reflect the conditions listed above and can be expressed\nusing predicates \\logicref{UpperBound} and \\logicref{StrictLowerBound}, namely,\n\n\n\\begin{itemize}\n\\item Condition~\\eqref{eq:upper-bound-result} becomes postcondition \\inl{result}\n\\item Condition~\\eqref{eq:upper-bound-left} becomes postcondition \\inl{left}\n\\item Condition~\\eqref{eq:upper-bound-right} becomes postcondition \\inl{right}\n\\end{itemize}\n\n\\input{Listings/upper_bound.h.tex}\n\n\\subsection{Implementation of \\upperbound}\n\nOur implementation of \\implref{upperbound} is shown in the following listing.\nThe loop invariants express that for each iteration step all indices less than \nthe temporary left bound \\inl{left} contain values not greater than \\inl{v}\nand all indices not less than the temporary right bound \\inl{right} contain\nvalues greater than \\inl{v}.\n\n\\input{Listings/upper_bound.c.tex}\n\n\\clearpage\n\n", "meta": {"hexsha": "25885b8d64623e191f48e3c3ce684817ba86dd78", "size": 3073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/binary-search/upper_bound.tex", "max_stars_repo_name": "fraunhoferfokus/acsl-by-example", "max_stars_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 90, "max_stars_repo_stars_event_min_datetime": "2017-06-14T04:17:53.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-07T06:07:36.000Z", "max_issues_repo_path": "Informal/binary-search/upper_bound.tex", "max_issues_repo_name": "fraunhoferfokus/acsl-by-example", "max_issues_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 22, "max_issues_repo_issues_event_min_datetime": "2017-10-18T13:30:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-17T07:10:16.000Z", "max_forks_repo_path": "Informal/binary-search/upper_bound.tex", "max_forks_repo_name": "fraunhoferfokus/acsl-by-example", "max_forks_repo_head_hexsha": "d8472670150fb3ff4360924af2d0eb14bc80d1e2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 19, "max_forks_repo_forks_event_min_datetime": "2017-06-21T13:49:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:27:06.000Z", "avg_line_length": 35.7325581395, "max_line_length": 92, "alphanum_fraction": 0.7731858119, "num_tokens": 872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.9059898146721821, "lm_q1q2_score": 0.7887522517757496}}
{"text": "\n\\subsection{Vector Autoregression (VAR)}\n\nWe consider a vector of observables, not just one\n\nAutoregressive (AR) model for a vector.\n\nVAR(p) looks \\(p\\) back.\n\nThe AR(\\(p\\)) model is:\n\n\\(y_t=\\alpha + \\sum_{i=1}^p\\beta y_{t-i}+\\epsilon_t\\)\n\nVAR(\\(p\\)) generalises this to where \\(y_t\\) is a vector. We define VAR(\\(p\\)) as:\n\n\\(y_t\\)\n\n\\(y_t=c + \\sum_{i=1}^pA_i y_{t-i}+\\epsilon_t\\)\n\n", "meta": {"hexsha": "99787e48f5742f11df8a8b97f37cd78a49aa51e5", "size": 382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticMultiple/01-01-VAR.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/stochasticMultiple/01-01-VAR.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/forecastingMulti/02-01-VAR.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.1, "max_line_length": 82, "alphanum_fraction": 0.6413612565, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566341975270266, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7887084712677958}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{amsmath,textcomp,amssymb,geometry,graphicx,enumerate}\n\\usepackage{hyperref}\n\\title{An Analysis of the Balance Problem}\n\\date{December 27, 2014}\n\\author{Ted Xiao\\\\ UC Berkeley EECS, 2017}\n\n\\begin{document}\n\n\\maketitle\n\nThis analysis was inspired by \\href{https://www.youtube.com/watch?v=wVPCT1VjySA}{a problem involving Santa Claus, 1024 wrapped gifts (with one slightly heavier), and a balance.}\\\\\n \n\\section*{1. The Balance Problem}\n\\textit{The problem:} We have a balance that can compare two different weights and tell us which is heavier or if they weigh the same. If we have 1024 boxes, with one box being slightly heavier than the others, what is the fewest number of weighs we'll need to find the heavier box?\\\\\\\n\\indent\\textit{The video answer:} A simple binary divide and conquer algorithm computes the solution in 10 comparisons every time. \\\\\n\\section*{2. The Binary Divide and Conquer Algorithm:} \ndef findBox(int[] weights):\\\\\n\\indent mid = len(weights)/2\\\\\n\\indent if totalWeight(weights[0:mid]) $<$ totalWeight(weights[mid:]):\\\\\n\\indent \\indent\treturn findBox(weights[mid:])\\\\\n\\indent\treturn findBox(weights[0:mid])\\\\\\\\\n\\newline\n\\indent Our recurrence relation is then $T(n) = T(n/2) + O(1)$, giving us a runtime of $log_2{n}$ comparisons. This is obviously a much better approach than a naïve approach, which makes $O(n)$ comparisons to see when two boxes weigh different. \n\\newline \n\\section*{3. The Ternary Divide and Conquer Algorithm:}\n\\indent However, my intuition was that instead of dividing the boxes into TWO groups every time, we could instead divide it into THREE. Then, we’d compare two of these thirds, and then if they were equal, we’d know the heavier box MUST be in the third we didn’t weigh, by simple parity. If they weren’t equal, we’d know the heavier box is in the third that was heavier. Thus, our problem size goes down by a factor of 3 each time. There was one problem that I thought about (that the original problem managed to circumvent since 1024 is a power of 2): what if the sample size can’t be divided into 3 groups? Well, I reasoned that at most you could have 2 leftover; we’d just put these in the third we aren’t putting on the balance. Then, if the two we’re weighing are equal, we’d have the other third (with the extras) be our new set. This still cuts the amount of boxes we look at asymptotically by 3 each iteration. \\\\\\\\\ndef heavierBoxByThirds(int[] weights):\\\\\n\\indent\tthird1, third2 = len(weights)/3, 2*len(weights)/3\\\\\n\\indent\tif totalWeight(weights[0:third1]) $>$ totalWeight(weights[third1:third2]):\\\\\n\\indent\\indent return heavierBoxByThirds(weights[0:third1])\\\\\n\\indent\telif totalWeight(weights[0:third1]) $<$ totalWeight(weights[third1:third2]):\\\\\n\\indent\\indent return heavierBoxByThirds(weights[third1:third2])\\\\\n\\indent\treturn heavierBoxByThirds(weights[third2:])\\\\\n\\\\\n\\\\\n\\indent The recurrence relation is thus $T(n) = T(n/3) + O(1)$, leading to a runtime of $log_3{n}$, asymptotically faster than the binary divide and conquer algorithm. \\\\\n\\indent One potential issue that came up: What if at each splitting into thirds, we find that the first two thirds are always equal in weight (so the heavier box is in the third with ‘extras’)? This would mean that our problem size wouldn’t be decreasing from n to n/3 at each iteration, but rather $n$ to $n/3 + 2$ (at worst case). Could this ever be worse than the binary divide and conquer, which is a decrease from $n$ to $n/2$?\n\\indent Well, $n/3 + 2 < n/2$ for all $n > 12$. And the problems we are looking at are all over a size of 12! So we are golden. Fun note: even for sizes under 12, it turns out binary and ternary splits are the SAME number of comparisons. Try it out!\\\\\n\\indent So this ternary divide and conquer algorithm should be the most optimal (based on worst case time) way of finding the heavier box. I confirmed my intuition with a simpler version of this \\href{http://en.wikipedia.org/wiki/Balance_puzzle}{problem}.\n\\\\\\\\\n\\textbf{Bonus:} \\\\\n\\indent I thought of a way to optimize the Binary Divide and Conquer Algorithm. It turns out a similar quarternary divide and conquer algorithm would have the same worst case run-time, but a MUCH better expected runtime! The thing about our binary divide and conquer algorithm is that is MUST go through $log_2{n}$ comparisons. There’s no way to ‘skip’ steps. If we instead to a quarternary divide, we could get lucky sometimes and cut the sample size from n to n/4 in just one comparison instead of two! Even if the two quarters are even, we will still have eliminated half of the boxes, and we still get a decrease from n to n/2 in one comparison, just as we did with the binary divide and conquer. \\newline\n\\indent So half of the time, we’ll get lucky and get a size reduction to $1/4$ and half the time we’ll just have to settle four a size reduction to $1/2$. This averages out to a size reduction to $1/2*1/4 + 1/2*1/2 = 3/8$ Which means the quarternary divide and conquer actually has an AVERAGE running time that is better than the binary divide and conquer but worse than ternary divide and conquer. \n\\indent Unfortunately, it seems like further splits wouldn’t be optimal. After you compare less than half of the original boxes each time $$(1/5 + 1/5 = 2/5 < 1/2)$$ you can’t really take advantage of divide and conquer anymore. \n\\indent To put my solution in context with the binary divide and conquer: $log_21024 = 10$ comparisons. $log_3{1024} = 6.3$ comparisons! That’s 37\\% faster. \\newline\n\\indent Anyways, it was fun thinking about the problem\\! It was fun using some of my Algorithms class knowledge, but most importantly, it’s cool that my solution works. \t\n\\end{document}\n", "meta": {"hexsha": "634be91f074cf3d2b0fe25dcd2e3d64c6e1d619e", "size": 5711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/santasearch.tex", "max_stars_repo_name": "txizzle/txizzle.github.io", "max_stars_repo_head_hexsha": "5ff77d3b2e5d1013b4ad34091eaa22ed99759f59", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-06-09T17:55:04.000Z", "max_stars_repo_stars_event_max_datetime": "2015-06-09T17:55:04.000Z", "max_issues_repo_path": "old/santasearch.tex", "max_issues_repo_name": "txizzle/txizzle.github.io", "max_issues_repo_head_hexsha": "5ff77d3b2e5d1013b4ad34091eaa22ed99759f59", "max_issues_repo_licenses": ["Apache-2.0"], "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/santasearch.tex", "max_forks_repo_name": "txizzle/txizzle.github.io", "max_forks_repo_head_hexsha": "5ff77d3b2e5d1013b4ad34091eaa22ed99759f59", "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": 116.5510204082, "max_line_length": 922, "alphanum_fraction": 0.7585361583, "num_tokens": 1498, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961706, "lm_q2_score": 0.8757869932689565, "lm_q1q2_score": 0.7886722830852226}}
{"text": "\\lab{Algorithms}{Line-Search Algorithms}{Line-Search Algorithms}\n\\objective{Investigate various Line-Search algorithms for one-dimensional optimization.}\n\nLine search procedures are an integral part of many nonlinear optimization techniques. \nIn some sense, they represent the simplest nontrivial case in general optimization, as \nwe only have to worry about one parameter. And yet far more sophisticated optimization \nalgorithms really crucially on the effectiveness and efficiency of line searches, since \nhigher-dimensional problems are often broken down into one-dimensional optimizations. \nThere are many different line search methods, and their effectiveness depends very much \non the nature of the optimization problem. Although the line search procedure is often \nonly a subroutine of the optimization algorithm at hand, understanding the basics of \nthe line search is necessary for understanding the robustness of the entire algorithm.\n\n\\subsection*{Derivative versus Derivative-Free Methods}\nAs you have seen in calculus classes, the derivative of a function gives information \nabout how the value of the function changes at each point, and can be used to determine \nlocal optima. However, not all objective functions are differentiable, so we need other \ntechniques at our disposal. Line search methods may be broadly separated into two groups \nbased on whether they use the derivative of the objective function. We discuss two \nsimple examples to illustrate this distinction.\n\n\\subsection*{Golden Section Search}\nThis method is appropriate when minimizing a real-valued function on the reals over a \nclosed interval. The function must further satisfy the \\emph{unimodal} property, i.e. \nit has just one local minimum, and in fact decreases monotonically to the minimum from \nthe left, and increases monotonically to the right. The goal, of course, find the \nglobal minimum. We do this by making a sequence of ``guesses\" that we hope will converge \nquickly to the minimum. Although we may not end up with the exact minimum, this method \nwill allow us to pin down the true minimum within an interval of any given width in a \nfinite number of steps.\n\nFor the Golden Section Search, each step consists of evaluating the function at two \npoints within the current interval, comparing these values, and then reducing the size \nof the interval for the next step. Let us consider typical step in the algorithm. At \nthe outset, we have our function $f$ and a closed interval $[a, b]$ over which we seek \nto minimize $f$. Choose two points $a'$ and $b'$ within the interval, and assume that \n$a' < b'$. Now calculate $f(a')$ and $f(b')$, and assume that $f(a') \\geq f(b')$. \nBecause of the unimodal condition, we now know that the minimizer must be in the \ninterval $[a', b]$, for otherwise the function $f$ would have a local minimum in \nboth $[a, a']$ and $[a', b]$. In the next step, we repeat the process over the interval \n$[a', b]$. If instead we had $f(b') \\geq f(a')$, then we choose the interval $[a, b']$ \nfor the next step, and if the two values are equal, then it does not matter which \ninterval is chosen.\n\nWe now have the basic description of the algorithm, but how do we choose the two test \npoints $a'$ and $b'$? There is in fact an optimal choice, which reduces the amount of \nwork we have to do. Given an interval $[a, b]$, choose $a'$ and $b'$ satisfying \n\\begin{equation*}\na' = a + \\rho(b - a) //\nb' = a + (1 - \\rho)(b - a),\n\\end{equation*}\nwhere $\\rho = \\frac{1}{2}(3 - \\sqrt{5}) \\approx 0.382$. By choosing these particular \npoints, we need to only evaluate the function at one additional point in the next step. \nTo demonstrate this fact, the reader may verify that, within the interval $[a, b']$, \nthe point $a'$ already satisfies the equation \n\\begin{equation*}\na' = a + (1 - \\rho)(b' - a),\n\\end{equation*}\nand so we need only evaluate the function at the point $c$ satisfying \n\\begin{equation*}\nc = a + \\rho(b' - a).\n\\end{equation*}\n(The constant $\\rho$ is not difficult to derive, and is related to the famous Golden Ratio, hence the name of this algorithm.)\n\nAt each step, the interval is reduced by a factor of $1-\\rho$, which means that after \n$n$ steps, we have pinned down the minimizer to within an interval approximately \n$(0.61803)^n$ times the length of the original interval. Note that this convergence is \nindependent of the objective function.\n\n\\begin{problem}\nImplement Golden Section Search as described above. Use this to minimize $\\exp{x} - 4x$ \non the interval $\\lbrack 0, 3 \\rbrack$. How many steps do you need to take to get \nwithin $.001$ of the true minimizer? Check that with the sentence preceding this \nproblem.\n\\end{problem}\n\n\\subsection*{Newton's Method}\nTo use this method, we need a real-valued function of a real variable that is twice \ndifferentiable. The idea is to approximate the function with a quadratic polynomial and \nthen solve the trivial problem of minimizing the polynomial. Doing so in an iterative \nmanner can lead us to the actual minimizer. Let $f$ be a function satisfying the \nappropriate conditions, and let us make an initial guess, $x_0$. The relevant quadratic \napproximation to $f$ is \n\\begin{equation*}\nq(x) = f(x_0) + f'(x_0)(x-x_0) + \\frac{1}{2}f''(x_0)(x-x_0)^2,\n\\end{equation*}\nor just the second-degree Taylor polynomial for $f$ centered at $x_0$. The minimum \nfor this quadratic function is easily found by solving $q'(x) = 0$, and we take the \nobtained $x$-value as our new approximation. The formula for the $(n+1)$-th \napproximation, which the reader can verify, is \n\\begin{equation*}\nx_{n+1} = x_n - \\frac{f'(x_n)}{f''(x_n)}.\n\\end{equation*}\n\nAs is typical with optimization algorithms, Newton's Method generates a sequence of \npoints or successive approximations to the minimizer. However, the convergence \nproperties of this sequence depend heavily on the initial guess $x_0$ and the function \n$f$. Roughly speaking, if $x_0$ is sufficiently close to the actual minimizer, and if \n$f$ is well-approximated by parabolas, then one can expect the sequence to converge \nquickly. However, there are cases when the sequence converges slowly or not at all.\n\n\\begin{problem}\nImplement Newton's Method as described above. Use this to again minimize $\\exp{x} - 4x$ \nwith an initial guess of $x_0 = 0$. Run the algorithm for as many steps as used for the \nGolden Section Search. Which method gives the better result?\n\\end{problem}\n\n\\subsection*{General Line Search Methods}\nWe now discuss some important conditions for line search methods in a more general \nsetting. We will deal here only with methods that use the derivative.\n\nLine-search methods require choosing a direction and a step size at each step in the \nalgorithm. The basic iteration is simply \n\\begin{equation*}\nx_{k+1} = x_k + \\alpha_kp_k,\n\\end{equation*}\nwhere $p_k$ \nis the search direction, and $alpha_k$ is the step size. We will not discuss how the \nsearch direction is selected, but only the step size. A common approach involves the \n\\emph{Wolfe conditions}:\n\n\\begin{align*}\n&f(x_k + \\alpha_kp_k) \\leq f(x_k) + c_1\\alpha_k\\nabla f_k^Tp_k, &(0 < c_1 < 1)\n\\\\ &\\nabla f(x_k + \\alpha_kp_k)^Tp_k \\geq c_2\\nabla f_k^Tp_k, &(c_1 < c_2 < 1)\n\\end{align*}\n\nHere, $f$ is the objective function, and we use the shorthand notation $\\nabla f_k$ to \nmean the gradient of $f$ evaluated at the point $x_k$. The search direction $p_k$ is \noften required to satisfy $p_k^T \\nabla f_k < 0$, in which case it is called a \n\\emph{descent direction}, since in this case the function is guaranteed to decrease in \nthis direction. Generally speaking, choosing a step size satisfying these conditions \nensures that we achieve sufficient decrease in the function and also that we do not \nterminate the search at a point of steep decrease (since then we could achieve even \nbetter results by choosing a slightly larger step size). The first condition is known \nas the \\emph{Armijo} condition. The second of the two conditions can be replaced by \n\\begin{equation*}\n| \\nabla f(x_k + \\alpha_kp_k)^Tp_k| \\leq c_2 | \\nabla f_k^Tp_k|,\n\\end{equation*}\nand in this case we have the \\emph{strong Wolfe conditions}.\n\nThe \\emph{Goldstein conditions} for choosing step size:\n\\begin{equation*}\nf(x_k) + (1-c)\\alpha_k\\nabla f_k^Tp_k \\leq f(x_k + \\alpha_kp_k) \\leq f(x_k) + \nc\\alpha_k\\nabla f_k^Tp_k,\n\\end{equation*}\nwhere $0 < c < 0.5$. Similar to the Wolfe conditions, the Goldstein conditions ensure \nsufficient decrease in the function and prevent the step size from being too small. In \nthe area of quasi-Newton optimization methods, however, the Wolfe conditions are \npreferred.\n\n\\emph{Sufficient Decrease and Backtracking:}\n\nAnother way to require a sufficient decrease without taking too short of a step \ninvolves the idea of backtracking: start with an assumed step size, and if it does not \nsatisfy a sufficient decrease requirement (which is to say, the step is too long), \nscale the step down repeatedly until the Armijo condition is satisfied.\n\n\\begin{problem}\nImplement the backtracking algorithm by writing a function that accepts as input an \nobjective function, the gradient of the function, the point at which to evaluate the \nfunction, and a search direction. Note that you also need to choose the scaling factor \nand the constant $c_1$ in the Armijo condition, as well as an initial step length.\n\\end{problem}\n\n\n\n", "meta": {"hexsha": "ff7398c466d1cab9019af3a87e78717b25882019", "size": 9343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/LineSearch/LineSearch.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/LineSearch/LineSearch.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/LineSearch/LineSearch.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": 55.9461077844, "max_line_length": 126, "alphanum_fraction": 0.7581076742, "num_tokens": 2399, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.9005297901222472, "lm_q1q2_score": 0.7886722699414485}}
{"text": "\\documentclass[11pt,letterpaper]{article}\n\\usepackage[T1]{fontenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\n\\usepackage[charter]{mathdesign}\n\\usepackage{fullpage}\n\\pagestyle{empty}\n\n\\input{../fncextra}\n\n\\addtolength{\\textheight}{2em}\n\n%\n% This project can be used after linear system solution (Chapter 2) has been covered.\n%\n\n\\begin{document}\n\t\n\\begin{center}\n  \\bf\n  Project: In the octopus' garden\n\\end{center}\n\t\nWe've done a little one-dimensional interpolation, and we will do more later in the course. We won't be going beyond one dimension, because things can get a little tricky out there. But there is a method known as \\textbf{radial basis functions} (RBF) that is not hard to get started with. RBFs have applications in machine learning, computer graphics, and differential equations. \n\nLet $\\phi(r)$ be a \\emph{shape function} defined for $r\\ge 0$. Popular choices include $\\phi(r)=r^3$ and $\\phi(r)=e^{-r^2}$. We'll limit ourselves to two dimensions, so let $(x_i,y_i)$, for $i=1,\\ldots,n$, be points in a plane region $R$. Each RBF has the form\n\\begin{equation}\n  \\label{eq:rbf}\n  u_i(x,y) = \\phi\\bigl( \\sqrt{(x-x_i)^2+(y-y_i)^2} \\bigr).\n\\end{equation}\nThe level curves of $u_i$ are circles centered at $(x_i,y_i)$, which is the reason for the adjective ``radial.''\n\nGiven a function $f(x,y)$ on the domain $R$, its RBF interpolant on the point set $\\{(x_i,y_i)\\}$ is \n\\begin{equation}\n  \\label{eq:interp}\n  s(x,y) = \\sum_{i=1}^n c_i u_i(x,y),\n\\end{equation}\nwhere the $c_i$ values are chosen so that\n\\begin{equation}\n  \\label{eq:constraint}\n  s(x_i,y_i) = f(x_i,y_i), \\qquad i=1,\\ldots,n.\n\\end{equation}\nThese conditions take the form of a linear system:\n\\begin{equation}\n  \\label{eq:linsys}\n  \\mA \\bfc = \\bfz, \\qquad A_{ij}=u_j(x_i,y_i), \\quad z_i=f(x_i,y_i).\n\\end{equation}\nOnce $\\bfc$ has been obtained, the interpolant can be computed anywhere using~\\eqref{eq:interp}. \n\n\nOne of the earliest applications of RBFs was to draw elevation contour lines on maps. Imagine you are given height data $z_i$ at each location instead of a function $f(x,y)$. You can replace the constraint~\\eqref{eq:constraint} with $s(x_i,y_i)=z_i$ for all $i$, and then $s$ is defined throughout the plane as an approximation to the true elevation. \n\n\\subsection*{Project assignment}\n\\label{sec:project-assignment}\n\nYou should submit only M-files. Four of them are scripts required to produce output as described in detail below.\n \\textbf{Each of these scripts should start with the lines}\n\\begin{verbatim}\n    close all, clear all, rng(foo)\n\\end{verbatim}\nwhere \\texttt{foo} is a 4-digit integer made up by your team. (The call to \\texttt{rng} makes your ``random'' results reproducible.)  \nYou may also use any function built into core MATLAB (not any toolboxes), any of the book functions, and any of your own helper functions. In your submission, \\textbf{include all other files needed, including those from the book.} You can locate all dependencies for file \\texttt{p1.m}, for example, with\n\\begin{verbatim}\n    matlab.codetools.requiredFilesAndProducts('p1')\n\\end{verbatim}\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 group, you may receive a zero on the entire assignment.}\n\n\\begin{description}\n\\item[script \\texttt{p1.m}:] This part is in one dimension, with $x_i=(i-1)/10$ and $y_i=0$ for $i=1,\\ldots,11$, $\\phi(r)=r^3$, and $f(x,y)=1/(20x^2+1)$. On one graph, plot the basis functions $u_2(x,0)$ and $u_7(x,0)$ for $0\\le x \\le 1$. Create and solve the linear system~\\eqref{eq:linsys}. Evaluate and print out the values of $s(x,0)$ and $f(x,0)-s(x,0)$ at $x=0.25$, $x=0.5$, and $x=0.75$. On a new graph, plot $f(x,0)$ and $s(x,0)$ together. \n\\item[script \\texttt{p2.m}:] Now you go into two dimensions, for the function\n  \\begin{equation}\n    \\label{eq:func}\n    f(x,y) = e^{ -x^2 + 2xy + 2y - y^2 }, \\quad 0\\le x \\le 1, \\: 0\\le y \\le 1,\n  \\end{equation}\n and with random points selected by\n\\begin{verbatim}\n  x = rand(n,1);  y = rand(n,1);\n\\end{verbatim}\nfor the values $n=100,200,\\ldots,1000$. Make a table showing the values of $n$, the error $f-s$ at the points $(0.5,0.5)$, $(0,0.6)$, and $(1,1)$, and $\\kappa(\\mA)$. \n\\item[script \\texttt{p3.m}:] Same as for \\texttt{p2}, except using $\\phi(r)=e^{-100r^2}$.\n\\item[script \\texttt{p4.m}:] MATLAB ships with a data set of elevation readings of an undersea mountain. You can load and see the data using\n\\begin{verbatim}\nload seamount\nplot3(x,y,z,'o')\n\\end{verbatim}\n(You do not need to include this plot in your submitted script.) Using the method described in the introduction, find an interpolating $s(x,y)$ using whatever you like for $\\phi(r)$. Then make a contour plot of the elevation as follows:\n\\begin{verbatim}\nxc = linspace(min(x),max(x),100);\nyc = linspace(min(y),max(y),100);\n[X,Y] = meshgrid(xc,yc);\n% ... you write some code here to define Z ...\ncontourf(X,Y,Z,32), axis equal\n\\end{verbatim}\nYou need to compute \\texttt{Z} such that its $(i,j)$ element is the value of $s$ at (\\texttt{X(i,j)},\\texttt{Y(i,j)}).\n\n\\end{description}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "212059e86743211b8b3529aef03549842c4bc6ef", "size": 5190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/rbf/rbf.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/rbf/rbf.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/rbf/rbf.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": 49.9038461538, "max_line_length": 448, "alphanum_fraction": 0.7098265896, "num_tokens": 1636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.9005297921244243, "lm_q1q2_score": 0.7886722687753934}}
{"text": "\\subsection{Fourier-Collocation}\n\t\\label{Collocation}\n\t\n\tThe main idea of ​​this method that we will see next is very similar to the Fourier-Galerkin method, except that we will use the interpolation operator described in (\\ref{Interpolation_operator_odd}) for an odd number of points in the grid. For this, we must use another polynomial space, which we already defined in chapter \\ref{Chapter_2} as $\\widetilde{B}_N$ given by\n\t\\begin{align*}\n\t\t\\widetilde{B}_N = span\\left\\{\\left(cos(nx), \\hspace{0.2cm} 0 \\leq n \\leq \\frac{N}{2} \\right)\\cup  \\left(sin(nx), \\hspace{0.2cm} 1 \\leq n \\leq \\frac{N}{2} - 1 \\right)\\right\\}.\n\t\\end{align*} \n\t\n\tNow we will look for a solution to the problem (\\ref{Bugers_Lineal}) in the space given by $S_N = \\widetilde{B}_N \\cap H^2_p [0, 2 \\ pi]$, using the discrete expansion for the function $\\varphi$ as follows\n\t\\begin{align}\n\t\\label{Discrete_phi}\t\t\n\t\t\\mathcal{J}_N \\varphi (x, t) =  \\displaystyle \\sum_{|n| \\leq \\frac{N}{2}} \\widetilde{\\varphi}_n (t) e^{inx}, \\hspace{2mm}\n\t\t\t\\widetilde{\\varphi}_n (t) =  \\displaystyle \\sum_{j=0}^{2N} \\varphi (x_j, t)  e^{-in x_j}\n\t\\end{align} \n\twhere $x_j$ are given by\n\t\\begin{align*}\n\t\txj = \\frac{2 \\pi j}{2N + 1}, \\hspace{2mm} j = 0, 1, \\dots, 2N.\n\t\\end{align*}\n\t\n\tRemember that by (\\ref{Lagrange_Odd}) the previous expansion can be written equivalently and also conveniently as\n\t\\begin{align*}\n\t\t\\mathcal{J}_N \\varphi (x, t) =  \\displaystyle \\sum_{j=0}^{2N} \\varphi (x_j, t) \\psi_j (x)\n\t\\end{align*}\n\twhere $\\psi_j (x_i) = \\delta_{ij}$ for $i, j = 0, 1, \\dots, 2N$, and satisfies $\\mathcal{J}_N \\varphi (x_j, t) = \\varphi (x_j, t)$ for each $j$.\n\t\n\tUsing the previous expansion in the equation (\\ref{Bugers_Lineal}) we can obtain a residual function as we obtained it in the Fourier-Galerkin method given as follows\n\t\\begin{align*}\n\t\tR_N (x, t) = \\frac{\\partial \\mathcal{J}_N \\varphi (x, t)}{\\partial t} - \\alpha \\frac{\\partial}{\\partial x^2} \\mathcal{J}_N \\varphi (x, t),\n\t\\end{align*}\t\n\tand similarly, we must force the orthogonality, for which we must remember by (\\ref{Coincidence_Inner}) that in this case, the discrete product coincides with the continuum, therefore, we have to\n\t\\begin{align*}\n\t\t\\langle R_N, \\psi_j \\rangle_N = \\int_{I} R_N (x, t) \\overline{\\psi}_j (x) dx = 0, \\hspace{2mm} \\text{for} \\hspace{2mm} j = 0, 1, \\dots, 2N.\n\t\\end{align*} \n\t\n\tSince $\\mathcal{J}_N \\varphi (x_j, t) = \\varphi (x_j, t)$ for every $j= 0, 1 \\dots, 2N$, the orthogonality can be satisfied by solving the following problem\n\t\\begin{align}\n\t\\label{Collocation_Linear}\t\n\t\t\\frac{d \\mathcal{J}_N \\varphi (x_j, t)}{dt} = \\alpha \\mathcal{J}_N \\frac{\\partial}{\\partial x^2} \\mathcal{J}_N \\varphi (x_j, t), \\hspace{2mm} j = 0, 1 \\dots, 2N\n\t\\end{align}\n\twhich is a system of $2N + 1$ ordinary differential equations that can be solved using the initial condition given by\n\t\\begin{align*}\n\t\t\\mathcal{J}_N \\varphi (x_j, t) =  \\varphi_0 (x_j), , \\hspace{2mm} j = 0, 1 \\dots, 2N\n\t\\end{align*}\n\t\n\tA convenient way to solve the above problem is to solve for each fixed $ j $ the following system of differential equations for the coefficients $ \\widetilde{\\varphi}_n$ given by\n\t\\begin{align*}\n\t\t\\frac{d \\widetilde{\\varphi}_n (t)}{dt} =  \\alpha n^2 \\widetilde{\\varphi}_n (t), \\hspace{2mm} |n| \\leq 2N\n\t\\end{align*}\n\twhich is exactly the same that we obtained in the Fourier-Galerkin method, with the solution given by\n\t\\begin{align*}\n\t\t\\widetilde{\\varphi}_n (t) = \\widetilde{\\varphi}_n (0) e^{- \\alpha n^2 t}, \\hspace{2mm} |n| \\leq 2N\n\t\\end{align*}\n\n\tFinally, after solving the previous problem for each $j$ we can express the solution with the expansion given by (\\ref{Discrete_phi}), which is basically the same solution that we have found using the Fourier-Galerkin method. \\\\\n\t\n\tWhen we need to use some numerical method to solve in the variable $ t $, it is better to express the system of differential equations by configuring the following vector\n\t\\begin{align*}\n\t\t\\varphi_N (t) = \\left[ \\varphi(x_0, t), \\varphi(x_1, t), \\dots, \\varphi(x_{2N}, t) \\right]^T\n\t\\end{align*} \n\tand using the differentiation matrix given by (\\ref{matrix_DN_odd}) to obtain\n\t\\begin{align*}\n\t\t\\frac{d}{dt} \\varphi_N (t) = \\alpha D^{(2)}_{2N} \\varphi_N (t)\n\t\\end{align*}\n\tIn this way we can calculate derivatives directly in real space, being a great advantage that we will discuss in the next section when implementing numerical methods based on the previous representation.", "meta": {"hexsha": "aa19de85de65544c8142cb8d600555991024b2f0", "size": 4410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/methods/Collocation.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/methods/Collocation.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/methods/Collocation.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": 68.90625, "max_line_length": 371, "alphanum_fraction": 0.6943310658, "num_tokens": 1578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7885718358580756}}
{"text": "\\section{Determinant and Trace}\n\n\\subsection{Exercise 1}\n(a) The discriminant already has ordered versions of all the $(i, j)$ difference terms.\nApplying a permutation only changes the signs of some of the difference terms, hence\n$\\sigma(p) = 1, -1$.\n\n(b) $\\sigma(p_1 \\circ p_2) = \\text{sign}(P(p_1 \\circ p_2 (x_1, ..., x_n)))  = \\sigma(p_1) \\text{sign}(P(p_2 (x_1, ..., x_n)))$.\n\n\\subsection{Exercise 2}\n(c) A transposition swaps two indices, and hence flips the sign of their associated\ndifference term in the discriminant.\n\n(d) If $p(i) = j$, then we can start with the permutation $(i \\: j)$.\nNext, if $p(j) = k$, we can compose with  $(i \\: k)$ to get $(i \\: k) \\circ (i \\: j)$.\nWe can do this until we have completely reconstructed the permutation using\ntranspositions.\n\n\\subsection{Exercise 3}\nBy starting with a different $i$ in Exercise 2 (d), we can obtain a different\ndecomposition of transpositions. However, the parity of the decomposition must\nbe the same, as otherwise $\\sigma(p)$ will take on two different values for\nthe same $p$.\n\n\\subsection{Exercise 4}\n(Property II): Each term in $D(a_1, ..., a_n)$ contains exactly one element\nfrom each of the $a_i$. Thus, scaling any of the $a_i$ by $k$ scales the entire\ndeterminant by $k$. Similar logic for vector addition.\n\n(Property III): The only non-zero term in $D(e_1, ..., e_n)$ is associated with\nthe identity permutation, hence $D(e_1, ..., e_n) = 1$.\n\n(Property IV): Swapping two arguments is the same as applying a transposition to\neach of the terms in $D(a_1, ..., a_n)$, which flips the sign of $D$.\n\n\\subsection{Exercise 5}\nSuppose $a_1 = a_2$. Then:\n\\begin{align*}\n        D(a_1, a_2, ..., a_n) &= -D(a_2, a_1, ..., a_n) \\\\\n        D(a_1, a_2, ..., a_n) + D(a_1, a_2, ..., a_n) &= 0\n\\end{align*}\n\n\\subsection{Exercise 6}\nWe can swap rows and columns until $A$ is in the same form as in Lemma 2.\nSince each row and column swap is equivalent to applying a transposition,\nwe get that $\\det A = (-1)^{i + j} \\det A_{ij}$.\n\n\\subsection{Exercise 7}\nEach term in the sum $D(a_1, ..., a_n) = \\sum \\sigma(p) a_{p_1 1} ... a_{p_n n}$ consists of\nexactly one element from each column and each row; swapping rows and columns does not\nchange the terms in the sum. However, the permutation associated with each term is changed.\nThe permutation $p$ that sends $1 \\to p_1$ becomes $p'$ sending $p_1 \\to 1$. This $p'$ \nis exactly $p^{-1} $. Since $\\sigma(1) = \\sigma(p^{-1}  \\circ p) = \\sigma(p^{-1}) \\sigma(p)$, \n$\\sigma(p^{-1}) = \\sigma(p)$ we are done.\n\n\\subsection{Exercise 8}\n$P$ is the linear transformation such that $P(e_j) = e_i$; in other words,\n$P$ rearranges the representation of $x$ by applying $p$ to the components of $x$.\nWe also have that $PQx = P q(x) = p \\circ q(x)$, since $Qx$ permutes the components\nof $x$ to produce $q(x)$, and $P q(x)$ permutes the components of $q(x)$ to produce\n$p \\circ q(x)$.\n\n\\subsection{Exercise 9}\n\\begin{align*}\n        &\\Tr AB = \\sum_{i = 1}^m (AB)_{ii} = \\sum_{i=1}^m \\sum_{j=1}^n a_{ij}b_{ji} \\\\\n        &\\Tr BA = \\sum_{j=1}^n (BA)_{jj} = \\sum_{j=1}^n \\sum_{i=1}^m b_{ji} a_{ij}\n\\end{align*}\n\n\\subsection{Exercise 10}\n\\begin{align*}\n        \\Tr A A^{\\top} &= \\sum (A A^{\\top})_{ii} = \\sum \\sum a_{ij} a^{\\top}_{ji} \\\\\n                       &= \\sum \\sum a_{ij}^2\n\\end{align*}\n\n", "meta": {"hexsha": "db5b9a7a743f9dde69137d465f18ffdd1e258e89", "size": 3289, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/chapter_5.tex", "max_stars_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_stars_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-09-19T07:33:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-19T07:33:25.000Z", "max_issues_repo_path": "Linear_Algebra_Lax/chapter_5.tex", "max_issues_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_issues_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Linear_Algebra_Lax/chapter_5.tex", "max_forks_repo_name": "2014mchidamb/Math-Exercise-Guides", "max_forks_repo_head_hexsha": "5ea4efe2267053695123a2c2d2c5171a672f61d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.8533333333, "max_line_length": 127, "alphanum_fraction": 0.6524779568, "num_tokens": 1096, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.888758803068433, "lm_q1q2_score": 0.7885108874875698}}
{"text": "In project 1 we used linear regression to predict a continuous output from a set of inputs \\cite{project1-eirik-joakim,project1-vege}. We used ordinary least squares regression (OLS), Ridge regression and Lasso regression, where the two latter impose a penalty to the OLS. In this project we will reuse the ideas and code of project 1, but we will also use neural networks to predict continuous variables. In addition we study situations where the outcome is discrete rather than continuous. This is a classification problem, and we will use logistic regression to model the probabilities of the classes.\n\n\\subsection{Logistic regression}\nJust like a linear regression model, a logistic regression model computes a weighted sum of the predictor variables, written in matrix notation as $\\bm{X}^T\\beta$. However, the logistic regression returns the logistic of this weighted sum as the probabilities. For a classification problem with $K$ classes, the model has the following form \\citep[p.119]{james2013introduction},\n\\begin{equation}\\label{eqT:logreg_def}\n\\begin{split}\n\\log\\frac{Pr(G=1|X=x)}{Pr(G=K|X=x)} &= \\beta_{10}\\ +\\ \\beta_{1}^Tx\\\\\n\\log\\frac{Pr(G=2|X=x)}{Pr(G=K|X=x)} &= \\beta_{20}\\ +\\ \\beta_{2}^Tx\\\\\n&\\vdots\\\\\n\\log\\frac{Pr(G=K-1|X=x)}{Pr(G=K|X=x)} &= \\beta_{(K-1)0}\\ +\\ \\beta_{K-1}^Tx\\\\\n\\end{split}\n\\end{equation}\nIt is arbitrary which class is used in the denominator for the log-odds above. Taking the exponential on both sides and solving for $Pr(G=k|X=x)$ gives the following probabilities,\n\\begin{equation}\\label{eqT:logreg_prob}\n\\begin{split}\nPr(G=k|X=x) &= \\frac{exp(\\beta_{k0}\\ +\\ \\beta_{k}^Tx)}{1+\\sum_{l=1}^{K-1}exp(\\beta_{l0}\\ +\\ \\beta_{l}^Tx)},\\ k=1,\\dots,K-1,\\\\\nPr(G=K|X=x) &= \\frac{1}{1+\\sum_{l=1}^{K-1}exp(\\beta_{l0}\\ +\\ \\beta_{l}^Tx)},\n\\end{split}\n\\end{equation}\nand the probabilities sum to one. To classify the output we choose the class with the highest probability.\n\n\\subsubsection{Fitting logistic regression model}\nThe usual way of fitting logistic regression models is by maximum likelihood. The log-likelihood for N observations is defined as,\n\\begin{equation}\\label{eqT:likelihood_def}\nl(\\theta)\\ =\\ \\sum_{i=1}^{N}\\log p_{g_i}(x_i;\\theta),\\\\\n\\end{equation}\nwhere $p_k(x_i;\\theta)\\ =\\ Pr(G=k|X=x_i;\\theta)$ and $\\theta\\ =\\ \\{\\beta_{10}, \\beta_1^T,\\dots, \\beta_{(K-1)0}, \\beta_{K-1}^T\\}$.\n\nOne very common classification problem is a situation with binary outcomes, either it happens or it does not. As we see from Equation \\ref{eqT:logreg_def} above, setting K=2 simplifies the model considerable, since there will now be only a single linear function. $\\theta$ in Equation \\ref{eqT:likelihood_def} will also be simplified: $\\theta = \\beta = \\{\\beta_{10}, \\beta_1^T\\}$. The two-class case is what is used in this project, and the following discussion will assume the outcome has two classes.\n\nWe start by coding the two-class $g_i$ with a 0/1 response $y_i$, where $y_i$ = 1 when $g_i$ = 1, and $y_i$ = 0 when $g_i$ = 2. Next, we let $p_1(x;\\theta)\\ =\\ p(x;\\beta)$, and $p_2(x;\\theta)\\ =\\ 1\\ -\\ p(x;\\beta)$. The log-likelihood can then be written\n\\begin{equation}\\label{eqT:loglike_binary}\n\\begin{split}\nl(\\beta) &= \\sum_{i=1}^N\\{y_i\\log p(x_i;\\beta)+(1-y_i)\\log(1-p(x_i;\\beta))\\}\\\\\n &= \\sum_{i=1}^N\\{y_i\\log\\frac{p(x_i;\\beta)}{1-p(x_i;\\beta)}+\\log(1-p(x_i;\\beta))\\}\\\\\n &= \\sum_{i=1}^N\\{y_i\\beta^Tx_i + \\log(1-\\frac{1}{1+exp(-\\beta^Tx_i)}\\}\\\\\n &= \\sum_{i=1}^N\\{y_i\\beta^Tx_i + \\log(\\frac{exp(1}{1+exp(\\beta^Tx_i)}\\}\\\\\n &= \\sum_{i=1}^N\\{y_i\\beta^Tx_i - \\log(1+exp(\\beta^Tx_i))\\}.\n\\end{split}\n\\end{equation}\nThis is the equation we want to maximize to find the best fit. Following the approach in Géron's book \\citep{Geron}, we chose the equivalent approach of minimizing the following,\n\\begin{equation}\\label{eq:Geron_cost}\nJ(\\beta) = -\\frac{1}{N}\\sum_{i=1}^N\\{y_i\\beta^Tx_i - \\log(1+exp(\\beta^Tx_i)).\\}\n\\end{equation}\nThis is just the negative of Equation \\ref{eqT:loglike_binary}, divided by the number of samples. This is our cost function, and dividing by the number of training samples finds the mean cost.\n\nAs with all cost functions, the goal is to minimize it. This introduces it's own potential pitfalls such as overfitting. In order to avoid that, we can introduce regularizations. Let us begin by looking at the optimization problem.\n", "meta": {"hexsha": "01e85e1313984dcc75c88f2bf348558bc5338b2a", "size": 4277, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory/logistic_regression.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/logistic_regression.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/logistic_regression.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": 89.1041666667, "max_line_length": 604, "alphanum_fraction": 0.7156885668, "num_tokens": 1391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.8887587890727755, "lm_q1q2_score": 0.7885108856730807}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{Numerically}\n\n\\objective{Calculate and graph reciprocal functions.}\n\nCalculating the reciprocal of a function is very straightforward.  For any given $x$,\ntake the output $f(x)$, and then reciprocate that number.  What that leads to is a\ncomplicated picture.  However, a pattern emerges.  The reciprocal of 1 is 1, and the\nreciprocal of -1 is -1.  That means points on the graph with a $y$ of 1 will not\nbe effected by reciprocation.  Other integer outputs will reciprocate to smaller and\nsmaller fractions, e.g. 2 to $\\frac{1}{2}$, 3 to $\\frac{1}{3}$, etc.\n\nWhat is unusual is the behavior around 0.  Zero has no reciprocal, so there will \ntypically be a vertical asymptote.\n\nEspecially in trigonometry, reciprocals can have names.\n\n\\begin{figure}\n\\begin{centering}\n\\begin{tikzpicture}[scale=0.5]\n\t\\draw [help lines] (-10, -10) grid (10, 10);\n\t\\draw [thick,<->] (-10.2, 0) -- (10.2, 0);\n\t\\draw [thick,<->] (0, -10.2) -- (0, 10.2);\n        % x-axis label\n        \\node at (10.5, 0) {x};\n        % y-axis label\n        \\node at (0, 10.5) {y};\n        \\draw[domain=-10:8.21,<->,ultra thick,samples=100,smooth] plot (\\x,{1/60*(\\x-4)*(\\x+1)*(\\x+8)});\n        \\draw[domain=-10.1:-8.065,<->,ultra thick,samples=100,smooth,dashed] plot (\\x,{60/((\\x-4)*(\\x+1)*(\\x+8))});\n        \\draw[domain=-7.93:-1.162,<->,ultra thick,samples=100,smooth,dashed] plot (\\x,{60/((\\x-4)*(\\x+1)*(\\x+8))});\n        \\draw[domain=-.83:3.9,<->,ultra thick,samples=100,smooth,dashed] plot (\\x,{60/((\\x-4)*(\\x+1)*(\\x+8))});\n        \\draw[domain=4.095:10.1,<->,ultra thick,samples=100,smooth,dashed] plot (\\x,{60/((\\x-4)*(\\x+1)*(\\x+8))});\n        \\draw[dashed, -] (-1,10) -- (-1,-10);\n        \\draw[dashed, -] (-8,10) -- (-8,-10);\n        \\draw[dashed, -] (4,10) -- (4,-10);\n\\end{tikzpicture}\n\\caption[Example of graphical reciprocation]{An example of a function and its reciprocal, $f(x)=\\frac{1}{60}(x-4)(x+1)(x+8)$.}\n\\end{centering}\n\\end{figure}", "meta": {"hexsha": "196ae4a3ef9e0099efcae6c426811dc74a73efdd", "size": 1953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch04/0404.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/0404.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/0404.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.825, "max_line_length": 126, "alphanum_fraction": 0.6149513569, "num_tokens": 720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.8887587853897074, "lm_q1q2_score": 0.7885108850560762}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\title{PDE: Assignment 2}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Problem 1}\n\tConsider the inner product defined as $<x,y> = x^*By$, where vectors $x,y \\in \\mathbb{C}^n$, and $B$ is positive definite Hermitian $n\\times n$ matrix.\n\t\n\t\\subsection{Part 1}\n\tShow that $<x,y> = \\overline{<y,x>}$.\n\t\\\\\\\\\n\t$\\overline{<y,x>} = \\overline{y^*Bx} = \\overline{Bx}y = x^*B^*y$.\n\t\\\\\\\\\n\tSince $B$ is Hermitian, $B^* = B$, so $\\overline{<y,x>} = x^*By = {<x,y>}$.\n\t\\\\\\\\\n\t\\subsection{Part 2}\n\tIf $M$ is an arbitrary $n\\times n$ matrix, define the adjoint $M^\\dag$ by $<x,My> = <M^\\dag x,y>$. Give an explicit formula for $M^\\dag$ in terms of $M$ and $B$.\n\t\\\\\\\\\n\t\\[ <x,My> = <M^\\dag x,y>\n\t\\]\n\t\\[ x^*BMy = (M^\\dag x)^*By\n\t\\]\n\t\\[ x^*BM = (M^\\dagger x)^*B\n\t\\]\n\t\\[ x^*BMB^{-1} = (M^\\dagger x)^* = x^*M^{\\dagger *}\n\t\\]\n\t\\[ BMB^{-1} = M^{\\dagger *}\n\t\\]\n\t\\[ M^\\dagger = (BMB^{-1})^*\n\t\\]\n\t\\\\\\\\\n\t\\subsection{Part 3}\n\tShow that if for some $A=A^*$, and $M=B^{-1}A$, then $M=M^\\dagger$.\n\t\\\\\\\\\n\t\\[ M^\\dagger = (BMB^{-1})^*\n\t\\]\n\t\\[ M^\\dagger = (BB^{-1}AB^{-1})^*\n\t\\]\n\t\\[ M^\\dagger = (AB^{-1})^*\n\t\\]\n\t\\[ M^\\dagger = B^{-1*}A^*\n\t\\]\n\tSince $B$ is Hermitian and $A=A^*$,\n\t\\[ M^\\dagger = B^{-1}A = M\n\t\\]\n\t\\\\\\\\\n\t\\section{Problem 2}\n\tConsider the following system:\n\t\\[ \\hat{A}u = \\frac{d}{dx}\\left[c\\frac{du}{dx}\\right]\n\t\\]\n\t\\subsection{Part 1}\n\tUsing center difference operations, approximate $\\hat{A}u$ at $m\\Delta x$.\n\t\\\\\\\\\n\tLet $u_m$ be the value of $u$ at point $m$, and $c_m$ be the value of $c$ at point $m$. $u'$ can then be approximated at point $m+0.5$ with center difference by\\\\\n\t\\[u'_{m} \\approx \\frac{u_{m+0.5} - u_{m-0.5}}{\\Delta x}\n\t\\]\\\\\n\twhere $\\Delta x$ is the difference between $m_n$ and $m_{n-1}$ The derivative of $c\\frac{du}{dx}$ can then be approximated by\n\t\\\\\n\t\\[\\frac{d}{dx}\\left[c_m\\frac{du}{dx}\\right] \\approx\n\t  \\frac{c_{m+0.5}u'_{m+0.5} - c_{m-0.5}u'_{m-0.5}}{\\Delta x}\n\t\\]\\\\\n\tand by substituting $u'(m)$ in\\\\\n\t\\[ \\frac{d}{dx}\\left[c_m\\frac{du}{dx}\\right] \\approx\n\t   \\frac{c_{m+0.5}\\left( \\frac{u_{m+1}- u_m}{\\Delta x}\\right) - c_{m-0.5}\\left( \\frac{u_m - u_{m-1}}{\\Delta x}\\right)}{\\Delta x}\n\t\\]\n\t\\\\\\\\\n\t\\subsection{Part 2}\n\tShow that the finite-difference estimation from Part 1 corresponds to approximating $\\hat{A}u$ by $A\\mathbf{u}$, where $\\mathbf{u}$ is the column vector of $M$ points $u_m$ and $A$ is the real-symmetric matrix $A = -D^TCD$.\n\t\\\\\\\\\n\t\\[ D = \\frac{1}{\\Delta x} \n\t\\begin{bmatrix}\n\t\t1 \t\t& 0\t\t&\\dots\t& 0\\\\\n\t\t-1 \t\t& 1 \t&\\ddots\t& 0\\\\\n\t\t0 \t\t& -1 \t&\\ddots & 0\\\\\n\t\t\\vdots \t&\\ddots\t&\\ddots\t& 1\\\\\n\t\t0\t\t& 0\t\t& 0\t\t&-1\\\\\n\t\\end{bmatrix}\n\t\\quad , \\quad C =  \n\t\\begin{bmatrix}\n\t\tc_{0.5}\t& 0\t\t& \\dots\t& 0 \\\\\n\t\t0\t\t&c_{1.5}&\\ddots\t& 0 \\\\\n\t\t\\vdots\t&\\ddots & \\ddots& 0\t\t\\\\\n\t\t0\t\t& 0\t\t& 0\t\t&c_{M+0.5}\\\\\n\t\\end{bmatrix}\n\t\\]\n\t\\\\\n\t\\[\n\tA\\mathbf{u} = -D^TCD = \\frac{1}{\\Delta x^2}\n\t\\begin{bmatrix}\n\t\t-c_{0.5} - c_{1.5} & c_{1.5} & 0 & \\dots\\\\\n\t\tc_{1.5} & -c_{1.5} - c_{2.5} & c_{2.5} & 0\\\\\n\t\t0 & c_{2.5} &\\ddots &\\ddots \\\\\n\t\t\\vdots & 0 & \\ddots &\\ddots \\\\\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\tu_0\\\\ u_1\\\\ \\vdots \\\\u_{M+1}\n\t\\end{bmatrix}\n\t\\]\n\t\\\\\n\t\\[ = \n\t\\begin{bmatrix}\n\t\t\\frac{c_{1.5}(u_{2} - u_1) - c_{0.5}(u_1 - u_0)}{\\Delta x^2}\\\\\n\t\t\\frac{c_{2.5}(u_{3} - u_2) - c_{1.5}(u_2 - u_{1})}{\\Delta x^2}\\\\\n\t\t\\vdots\\\\\n\t\t\\frac{c_{m+0.5}(u_{m+1} - u_m) - c_{m-0.5}(u_m - u_{m-1})}{\\Delta x^2}\n\t\\end{bmatrix}\n\t\\]\n\t\\\\\\\\\n\t\\subsection{Part 3}\n\tLet $c(x) = e^{3x}$. Use the above methods to attain the eigenvalues and eigenvectors. Plot the eigenvectors for the four smallest-magnitude eigenvalues. Verify that the first two eigenfunctions are orthogonal. Verify that you are getting second order convergence of the eigenvalues. ($L=1$, $M=100$)\n\t\\\\\\\\\n\t\\textit{see notebook}\n\t\\pagebreak\n\t\\section{Problem 3}\n\tConsider a metal bar with length $L$, cross sectional area $a$, and varying temperature $T$ along the rod. The rod is conceptually divided into $N$ pieces of length $\\Delta x = L/N$. Each piece has a uniform temperature $T_n$, giving a vector $\\mathbf{T}$ of $N$ temperatures. The rate at which heat flows from piece $n$ to piece $n+1$ is given by $q = \\frac{\\kappa a}{\\Delta x}(T_n - T_{n+1})$ ($\\kappa$ is the thermal conductivity of the rod). If an amount of heat $\\Delta Q$ flows into a piece, the temperature changes by $\\Delta T = \\Delta Q / (c\\rho a\\Delta x)$ where $c$ is the specific heat capacity, and $\\rho$ is the density of the metal. Assume the rod is ideally insulated.\n\t\\\\\n\t\\subsection{Part 1}\n\tShow that $\\frac{dT_n}{dt} = \\alpha(T_{n+1}-T_n) + \\alpha(T_{n-1}-T_n)$. (This is Newton's Law of Cooling).\n\t\\\\\\\\\n\t\\[ \\frac{\\Delta T_n}{\\Delta t} = \\frac{1}{c\\rho a\\Delta x}\\frac{\\Delta Q_n}{\\Delta t}\n\t\\]\\\\\n\t$\\frac{\\Delta Q_n}{\\Delta t}$ is the rate of heat flow into piece $n$, which is the sum of the heat flow from it's neighbors.\\\\\n\t\\[ \\frac{dT_n}{dt} = \\frac{1}{c\\rho a\\Delta x}\\left[\n\t\\frac{\\kappa a}{\\Delta x}(T_{n+1}-T_n) + \t\\frac{\\kappa a}{\\Delta x}(T_{n-1}-T_n) \\right]\n\t\\]\\\\\n\t\\[ \\frac{dT_n}{dt} = \\frac{\\kappa}{c\\rho \\Delta x^2}\\left[ (T_{n+1}-T_n)+(T_{n-1}-T_n) \\right]\n\t\\]\\\\\n\twhich matches Newton's Law of Cooling, with $\\alpha = \\frac{\\kappa}{c\\rho\\Delta x}$. At the end points,\\\\\n\t\\[ \\frac{dT_1}{dt} = \\frac{\\kappa}{c\\rho\\Delta x^2}(T_2 - T_1) \\quad , \\quad \\frac{dT_N}{dt} = \\frac{\\kappa}{c\\rho\\Delta x^2}(T_{N-1} - T_N)\n\t\\]\n\t\\\\\n\t\\subsection{Part 2}\n\tWrite the equation from Part 1 in matrix form: $\\frac{d\\mathbf{T}}{dt} = A\\mathbf{T}$, for some matrix $A$.\n\t\\\\\\\\\n\t\\[\\frac{d\\mathbf{T}}{dt}=A\\mathbf{T} = \\frac{\\kappa}{c\\rho\\Delta x^2}\n\t\\begin{bmatrix}\n\t\t-1     & 1    & 0    &\\dots & 0 \\\\\n\t\t 1     & -2   & 1    & 0    & \\vdots \\\\\n\t\t 0     &\\ddots&\\ddots&\\ddots& 0 \\\\\n\t\t \\vdots&  0   &   1  &  -2  & 1\\\\\n\t\t 0     &\\dots &  0   &   1  & -1 \\\\\n\t\\end{bmatrix}\n\t\\begin{bmatrix}\n\t\tT_1\\\\T_2\\\\ \\vdots \\\\ T_{N-1} \\\\ T_N\n\t\\end{bmatrix}\n\t\\]\\\\\\\\\n\t\n\t\\subsection{Part 3}\n\tLet $T(x,t)$ be the temperature along the rod. Suppose $T_n(t) = T([n-0.5]\\Delta x,t)$ (the temperature at the center of the $n^{th}$ piece). Take the limit $N \\rightarrow \\infty$ (with $L$ fixed), and derive the PDE $\\frac{\\partial T}{\\partial t}= \\hat{A}T$. What is $\\hat{A}$ (ignore the ends)?\n\t\\\\\\\\\n\tAs $N\\rightarrow\\infty$, $\\Delta x$ can be thought of as $\\partial x$, and $T_{n+1} - T_n$ can be thought of as $\\partial T(n,t)$.\n\t\\\\\\\\\n\t$(T_{n+1}-T_n) + (T_{n-1}-T_n)$ can also be expressed as  $(T_{n+1}-T_n) - (T_{n}-T_{n-1})$, which as $N \\rightarrow \\infty$ is $\\partial^2T$.\n\t\\\\\\\\\n\tThus\n\t\\[ \\lim\\limits_{N \\rightarrow \\infty} \\left\\{ \\frac{dT_n}{dt} = \\frac{\\kappa}{c\\rho \\Delta x^2}\\left[ (T_{n+1}-T_n)+(T_{n-1}-T_n) \\right] \\right\\}\n\t\\]\\\\\n\tbecomes\n\t\\[\\frac{\\partial T}{\\partial t} = \\frac{\\kappa}{c\\rho}\\frac{\\partial^2T}{\\partial x^2}\n\t\\]\n\t\\\\\\\\\n\tSo, ignoring the ends,\n\t\\[\\hat{A} = \\frac{\\kappa}{c\\rho}\\frac{\\partial^2}{\\partial x^2}\n\t\\]\\\\\n\t\\subsection{Part 4}\n\tWhat are the boundary conditions on $T(x,t)$ at $x=0$ and $L$? Check that if you go backwards and form a center-difference approximation of $\\hat{A}$ with these boundary conditions, you will recover matrix $A$.\n\t\\\\\\\\\n\tThe boundary condition is the $\\frac{\\partial T}{\\partial x} = 0$ at $x=0,L$ since there is 0 heat flow at the ends.\n\t\\\\\\\\\n\tThe center-difference approximation of $\\frac{\\partial T}{\\partial x}|_{n\\Delta x} \\approx T'_{n+0.5} = \\frac{T_{n+1} - T_n}{\\Delta x}$\n\t\\\\\\\\\n\tThe center difference approximation of $T''_n = \\frac{T'_{n+0.5} - T'_{n-0.5}}{\\Delta x} =\n\t\\frac{T_{n+1}-T_n - (T_n - T_{n-1})}{\\Delta x^2}$\n\t\\\\\\\\\n\tThis is equivalent to $\\frac{T_{n+1} - 2T_n + T_{n-1}}{\\Delta x^2}$, which is the same expression from Part 1 (with $\\frac{\\kappa}{c\\rho}=0$), and will thus result in the same $A$.\n\t\\\\\n\t\\subsection{Part 5}\n\tHow does $\\hat{A}$ change in the $N \\rightarrow \\infty$ limit if the conductivity is a function $\\kappa(x)$ of $x$?\n\t\\\\\\\\\n\t\\[ \\frac{\\partial T}{\\partial t} = \\frac{1}{c\\rho}\\frac{\\partial \\kappa \\partial T}{\\partial x^2}\n\t\\]\n\t\\\\\n\tThus,\n\t\\[A = \\frac{1}{c\\rho} \\frac{\\partial}{\\partial x}\\kappa\\frac{\\partial}{\\partial x}\\]\\\\\n\t\\subsection{Part 6}\n\tSuppose that instead of a thin bar (1D), you have a metal plate (2D) with a temperature $T(x,y,t)$ and constant conductivity $\\kappa$. If you go through the steps above and divide it into $N\\times N$ squares of size $\\Delta x \\times \\Delta y$, what PDE do you get for $T$ in the limit $N \\rightarrow \\infty$.\n\t\\\\\\\\\n\tThe PDE will be the sum of the partial derivatives in the $x$ and $y$ directions.\\\\\n\t\\[ \\frac{dT_{m,n}}{dt} = \\frac{\\kappa}{c\\rho}\n\t\\left[ \\frac{T_{m+1,n} - 2T_{m,n} + T_{m-1,n}}{\\Delta x^2} + \\frac{T_{m,n+1} - 2T_{m,n} + T_{m,n-1}}{\\Delta y^2} \\right]\n\t\\]\n\tAnd as $N \\rightarrow \\infty$,\\\\\n\t\\[ \\frac{\\partial T}{\\partial t} = \\hat{A}T =  \\frac{1}{c\\rho}\\bigtriangledown \\cdot \\kappa \\bigtriangledown T\n\t\\]\n\t\n\\end{document}", "meta": {"hexsha": "222d7ad1d54e200fa0863694523934f26502976f", "size": 8759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/A2/assn2.tex", "max_stars_repo_name": "markditsworth/linearPDE", "max_stars_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_stars_repo_licenses": ["MIT"], "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/A2/assn2.tex", "max_issues_repo_name": "markditsworth/linearPDE", "max_issues_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_issues_repo_licenses": ["MIT"], "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/A2/assn2.tex", "max_forks_repo_name": "markditsworth/linearPDE", "max_forks_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_forks_repo_licenses": ["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.3613861386, "max_line_length": 685, "alphanum_fraction": 0.5917342162, "num_tokens": 3690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544448, "lm_q2_score": 0.885631484383387, "lm_q1q2_score": 0.7884726047521138}}
{"text": "\\subsection{Composition}\n\nCan define the following (linear) transformation:\n\n\\[\\boxed{T_C(\\tb{x})=T_A(T_B(\\tb{x}))=(T_A\\circ T_B)(\\tb{x})}\\]\n\nFollowing diagram represents the composition:\n\n\\begin{center}\n    \\includegraphics[scale=0.5]{comp-trans.png}\n\\end{center}\n\nWould imply that $A$ is $n\\times p$, $B$ is $p\\times m$, and $AB$ is $n\\times m$.\nCan define the following:\n\n\\[\\boxed{\\text{The $i^{th}$ column of the matrix $AB$ is the matrix-vector product $A$($i^{th}$ column of the matrix $B$)}}\\]\n\n\\subsection{Proofs}\n\n\\textbf{\\textit{Claim:}} The product of 2 invertible matrices must be an invertible matrix.\\newline\n\\textbf{\\textit{Proof:}} Given that $(AB)(AB)^{-1}=I_n$:\n\n\\begin{align*}\n    &(AB)(AB)^{-1}=I_n\\\\\n    &A(B(AB)^{-1})=I_n\\\\\n    &A^{-1}A(B(AB)^{-1})=A^{-1}I_n\\\\ \n    &B(AB)^{-1}=A^{-1}\\\\ \n    &B^{-1}B(AB)^{-1}=B^{-1}A^{-1}\\\\\n    &(AB)^{-1}=B^{-1}A^{-1}\n\\end{align*}\n\n\\noindent\\textbf{\\textit{Claim:}} If $(AB)^{-1}$ exists, then $A$ and $B$ are both invertible.\\newline\n\\textbf{\\textit{Proof:}} Given that $(AB)(AB)^{-1}=I_n$ and $(AB)^{-1}(AB)=I_n$:\n\n\\begin{align*}\n    &A(B(AB)^{-1})=I_n\\\\ \n    &((AB)^{-1}A)B=I_n\\\\\n    &\\boxed{\\therefore\\;\\exists\\;A^{-1},\\:B^{-1}\\in \\R^n}\n\\end{align*}\n\n\\subsection{Properties}\n\n\\begin{itemize}\n    \\item Associativity: $(AB)C=A(BC)$\n    \\item Distribution: $A(B+C)=AB+BC$\n    \\item Respects scalar multiplication: $(kA)B=k(AB)=A(kB)$ \n\\end{itemize}\n", "meta": {"hexsha": "2c0b537f4fe1d5f1bcdbb0623aa48057fb0445c9", "size": 1408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/9_matrix-product.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/9_matrix-product.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/9_matrix-product.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.3333333333, "max_line_length": 125, "alphanum_fraction": 0.5973011364, "num_tokens": 540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8902942283051332, "lm_q1q2_score": 0.7884725841707657}}
{"text": "\\documentclass[12pt, a4paper]{article}\n\n\\usepackage{geometry}\n\\geometry{verbose,a4paper,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}\n \n\\usepackage[english]{babel}\n\\usepackage{amsmath}\n\\usepackage{mathtools}\n\\usepackage{cases}\n\\usepackage{hyperref}\n\\usepackage{longtable}\n\\usepackage{graphicx}\n\\graphicspath{ {../Media/} }\n\n\\title{SIR models for the spread of COVID-19}\n\\date{\\today}\n\\author{\n\tMaksim Gordienko \\\\\n\tAlexander Sysoev\n}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Introduction}\n\tIn this article we are going to show how Kermack and McKendrick SIR models can be used for epidemic process simulation. Then we add vital dynamics to SIR model. Next we solve simple models in analytical way. Finally, we introduce sophisticated SEIRS-like model especially for COVID-19 conditions, close to real life.\n\t\n\t\\section{Mathematical model of epidemics}\n\tLet's consider a group of $N$ people and classify them into these types:\n\t\\begin{itemize}\n\t\t\\item \\textbf{S} -- Susceptible\n\t\t\\item \\textbf{I} -- Infected\n\t\t\\item \\textbf{R} -- Recovered\n\t\\end{itemize}\n\n\tThis is called the SIR model for the spread of epidemic diseases that describes the changes in numbers of the three types of individuals. We denote the number of susceptible persons by $s(t)$, the number of infected individuals by $i(t)$ and the number of recovered people by $r(t)$. The time $t$ is measured in days. Also we suppose that each person is in contact with $m$ persons per day average. Hence the number of contacts between the susceptible and infected people becomes $\\frac{m}{N} i(t) s(t)$. If we set the probability of infection for each contact as $p$ then the number of newly infected individuals within $\\Delta t$ days becomes\n\t\\begin{equation}\n\t\t\\frac{m}{N} i(t) s(t) p \\Delta t\n\t\\end{equation}\n\tin total. Let $\\beta = mp$, the number of non-infected people \\textbf{(S)} from the $t$-th day to $ (t + \\Delta t) $-th day changes as\n\t\\begin{equation}\n\t\ts(t + \\Delta t) - s(t) = - \\frac{\\beta}{N} s(t) i(t) \\Delta t\n\t\\end{equation}\n\tWhen $\\Delta t \\rightarrow 0 $, we can rewrite it as differential equation\n\t\\begin{equation}\n\t\t\\frac{ds(t)}{dt} = - \\frac{\\beta}{N} s(t) i(t)\n\t\\end{equation}\n\tMeanwhile, the infected individuals recover at a removal rate $ \\gamma $ per day. Subsequently, increase in the number of the recovered persons becomes\n\t\\begin{equation}\n\t\t\\frac{dr(t)}{dt} = \\gamma i(t)\n\t\\end{equation}\n\tRespectively, $ \\dfrac{1}{\\gamma} $ is the expected duration of infection. Also the number of recovered people includes the amount of deceased persons because they cannot possibly infect others.\n\t\n\t\\newpage\n\t\n\tAs well as the total number of individuals is $N$, we can express $i(t)$\n\t\\begin{equation}\n\t\ti(t) = N - s(t) - r(t)\n\t\\end{equation}\n\tThe change in the number of infected people can be written as\n\t\\begin{equation}\n\t\t\\frac{di(t)}{dt} = - \\frac{ds(t)}{dt} - \\frac{dr(t)}{dt} = \\frac{\\beta}{N} s(t) i(t) - \\gamma i(t) = \\frac{\\beta}{N} (s(t) - \\gamma) i(t)\n\t\\end{equation}\n\tGathering the equations above, we have\n\t\\begin{numcases}{}\n\t\t\\frac{ds(t)}{dt} = - \\frac{\\beta}{N} s(t) i(t) \\label{eq:dsdt} \\\\\n\t\t\\frac{di(t)}{dt} = (\\frac{\\beta}{N} s(t) - \\gamma) i(t) \\label{eq:didt} \\\\\n\t\t\\frac{dr(t)}{dt} = \\gamma i(t) \\label{eq:drdt}\n\t\\end{numcases}\n\tAs initial conditions, we use\n\t\\begin{equation} \\label{eq:init_cond}\n\t\t\\begin{dcases}\n\t\t\ts(0) = N_1 \\\\\n\t\t\ti(0) = N_2 \\\\\n\t\t\tr(0) = 0\n\t\t\\end{dcases}\n\t\\end{equation}\n\tIf we introduce the following transformations of variables\n\t\\[\n\t\t\\tilde{s}(t) = \\frac{s(t)}{N}, \\tilde{i}(t) = \\frac{i(t)}{N}, \\tilde{r}(t) = \\frac{r(t)}{N}, \\tilde{t} = \\beta t\n\t\\]\n\tThen system of the equations becomes\n\t\\begin{equation}\n\t\t\\begin{dcases}\n\t\t\t\\frac{d \\tilde{s} (t)}{d \\tilde{t}} = - \\tilde{s}(t) \\tilde{i}(t) \\\\\n\t\t\t\\frac{d \\tilde{i}(t)}{d \\tilde{t}} = (\\tilde{s}(t) - \\frac{1}{R_0}) \\tilde{i}(t) \\\\\n\t\t\t\\frac{d \\tilde{r}(t)}{d \\tilde{t}} = \\frac{1}{R_0} \\tilde{i}(t)\n\t\t\\end{dcases}\n\t\\end{equation}\n\tThe number $R_0 = \\dfrac{\\beta}{\\gamma}$ is known as the basic reproduction number. The number of infected people increases when $R_0 > 1$ and decreases when $R_0 < 1$.\n\t\n\t\\section{Analytical solution of SIR model}\n\tWhen model is defined, we can solve the system of equations \\eqref{eq:dsdt} -- \\eqref{eq:drdt}. For simplicity forget about function arguments. Firstly, rewrite the equation \\eqref{eq:dsdt} as\n\t\\begin{equation} \\label{eq:dsdt_rewritten}\n\t\ti = - \\frac{1}{\\tilde{\\beta}} (\\frac{s'}{s})\n\t\\end{equation}\n\twhere $\\tilde{\\beta} = \\dfrac{\\beta}{N}$. Then differentiate both sides\n\t\\begin{equation} \\label{eq:di_1}\n\t\ti' = - \\frac{1}{\\tilde{\\beta}} (- \\frac{{s'}^2}{s^2} + \\frac{s''}{s})\n\t\\end{equation}\n\tNext insert the equation \\eqref{eq:dsdt_rewritten} into \\eqref{eq:didt}\n\t\\begin{equation} \\label{eq:di_2}\n\t\ti' = -(\\tilde{\\beta} s - \\gamma) \\frac{1}{\\tilde{\\beta}} (\\frac{s'}{s})\n\t\\end{equation}\n\n\t\\newpage\n\t\n\tComparing equations \\eqref{eq:di_1} and \\eqref{eq:di_2} we have\n\t\\begin{equation} \\label{eq:dsdt_combined}\n\t\ts \\frac{d^2 s}{dt^2} - (\\frac{ds}{dt})^2 + (\\gamma - \\tilde{\\beta} s) s \\frac{ds}{dt} = 0\n\t\\end{equation}\n\tNow we introduce the following function\n\t\\begin{equation} \\label{eq:phi_intro}\n\t\t\\phi = \\frac{dt}{ds}\n\t\\end{equation}\n\tAfterward \\eqref{eq:dsdt_combined} becomes\n\t\\begin{equation}\n\t\t\\frac{d \\phi}{ds} + \\frac{\\phi}{s} = (\\gamma - \\tilde{\\beta} s)\\phi^2\n\t\\end{equation}\n\tThis is a Bernoulli differential equation. Divide both parts by $ \\phi^2 $\n\t\\begin{equation}\n\t\t\\frac{\\phi'}{\\phi^2} + \\frac{1}{\\phi s} = \\gamma - \\tilde{\\beta} s\n\t\\end{equation}\n\tThen make a substitution\n\t\\begin{equation}\n\t\tz = \\frac{1}{\\phi}, z' = -\\frac{\\phi'}{\\phi^2}\n\t\\end{equation}\n\tNow solve the first-order linear ordinary equation\n\t\\begin{equation}\n\t\t-z' + \\frac{z}{s} = \\gamma - \\tilde{\\beta} s \n\t\\end{equation}\n\twith general solution where $C$ is constant\n\t\\begin{equation}\n\t\tz = -\\gamma s \\ln{s} + \\tilde{\\beta} s^2 + Cs\n\t\\end{equation}\n\tReturning back to $\\phi$\n\t\\begin{equation} \\label{eq:phi_res}\n\t\t\\phi = \\frac{1}{s(C - \\gamma \\ln{s} + \\tilde{\\beta} s)}\n\t\\end{equation}\n\tFrom the relation of inverse function in equation \\eqref{eq:phi_intro}, we have\n\t\\begin{equation}\n\t\t\\frac{1}{\\phi} = \\frac{ds}{dt}\n\t\\end{equation}\n\tUsing equation \\eqref{eq:dsdt}, we obtain\n\t\\begin{equation} \\label{eq:it_def}\n\t\ti(t) = -\\frac{1}{\\tilde{\\beta}} (C - \\gamma \\ln{s(t)} + \\tilde{\\beta} s(t))\n\t\\end{equation}\n\tMoreover, from equations \\eqref{eq:dsdt} and \\eqref{eq:drdt}, we get\n\t\\begin{equation}\n\t\t\\frac{dr}{dt} = -\\frac{\\gamma}{\\tilde{\\beta}} (\\frac{s'}{s})\n\t\\end{equation}\n\tSubsequently, the relation between s(t) and r(t) becomes\n\t\\begin{equation} \\label{eq:rt_def}\n\t\tr(t) = -\\frac{\\gamma}{\\tilde{\\beta}} \\ln{\\frac{s(t)}{C_1}}\n\t\\end{equation}\n\twhere $C_1$ is a constant. According to our initial conditions \\eqref{eq:init_cond} \n\t\\begin{equation}\n\t\tC_1 = N_1\n\t\\end{equation}\n\n\t\\newpage\n\t\n\tFrom the relation $s(0) + i(0) + r(0) = N$, we have\n\t\\begin{equation}\n\t\tC = -\\tilde{\\beta}N + \\gamma \\ln{N_1}\n\t\\end{equation}\n\tIf we substitute $C$ into equation \\eqref{eq:phi_res}, we obtain\n\t\\begin{equation}\n\t\t\\frac{dt}{ds} = \\frac{1}{s(-\\tilde{\\beta}N - \\gamma \\ln{\\dfrac{s}{N_1} + \\tilde{\\beta}s})}\n\t\\end{equation}\n\tIntegrate this and express $t$ as a function of $s$\n\t\\begin{equation} \\label{eq:t_eps}\n\t\tt = \\int_{s(0)}^{s(t)} \\frac{d \\varepsilon}{\\varepsilon(-\\tilde{\\beta}N - \\gamma \\ln{\\dfrac{\\varepsilon}{N_1}} + \\tilde{\\beta} \\varepsilon)}\n\t\\end{equation}\n\tFor convenience, we change a variable\n\t\\begin{equation}\n\t\t\\xi = \\frac{\\varepsilon}{N_1}\n\t\\end{equation}\n\tRewrite the equation \\eqref{eq:t_eps}\n\t\\begin{equation}\n\t\tt(s) = \\int_{1}^{\\frac{s(t)}{N_1}} \\frac{d \\xi}{\\xi(-\\beta - \\gamma \\ln{\\xi} + \\beta \\xi \\frac{N_1}{N})}\t\t\n\t\\end{equation}\n\tNow we can calculate $t(s)$ using numerical integration with a small step size and $s(t)$ as a parameter like that\n\t\\begin{equation}\n\t\t\\int_{a}^{b} f(\\xi) \\,d\\xi \\simeq \\sum_{i=0}^{n-1} f(a + ih)h,~ \\text{where} ~ h = \\frac{b-a}{n}\n\t\\end{equation}\n\tIf $t(s)$ is obtained, then $i(t)$ and $r(t)$ can be calculated from equations \\eqref{eq:it_def} and \\eqref{eq:rt_def} respectively.\n\t\n\t\\newpage\n\n\t\\section{SIR Model with natural deaths and births}\n\n\tLet's rewrite our system of equations \\eqref{eq:dsdt} -- \\eqref{eq:drdt} with an addition of the death and birth processes. Consider these rates are equal to each other, we introduce new variable $D$:\n\t\\begin{numcases}{}\n\t\t\\frac{ds(t)}{dt} = - \\frac{\\beta}{N} s(t) i(t) + D(N - s(t)) \\label{eq:death_s} \\\\\n\t\t\\frac{di(t)}{dt} = (\\frac{\\beta}{N} s(t) - \\gamma - D) i(t) \\label{eq:death_i} \\\\\n\t\t\\frac{dr(t)}{dt} = \\gamma i(t) - Dr(t) \\label{eq:death_r}\n\t\\end{numcases}\n\tAs we did before, we rewrite it into one equation:\n\t\\begin{equation} \\label{eq:re_death_s}\n\t\ti = \\frac{s' - D(N- s)}{-\\tilde{\\beta}s}\n\t\\end{equation}\n\tAgain we differentiate both sides (with $\\tilde{\\beta} = \\frac{\\beta}{N}$ substitution):\n\t\\begin{equation}\n\t\ti' = -\\frac{1}{\\tilde{\\beta}}(\\frac{(s'' + D s')s - (s' + D s - D N)s'}{s^2}),\n\t\\end{equation}\n\t\\begin{equation} \\label{eq:re_death_s_diff}\t\n\t\ti' = -\\frac{1}{\\tilde{\\beta}}(\\frac{s''}{s} - \\frac{s'^2 - D N s'}{s^2})\n\t\\end{equation} \n\tNow we can insert \\eqref{eq:re_death_s} into \\eqref{eq:death_i}:\n\t\\begin{equation}\n\t\ti' = (\\tilde{\\beta} s - \\gamma - D)(\\frac{s' - D(N- s)}{-\\tilde{\\beta}s})\n\t\\end{equation}\n\t\\begin{equation} \\label{eq:re_death_i_sub}\n\t\ti' = -\\frac{1}{\\tilde{\\beta}s}(\\tilde{\\beta}s - \\gamma - D)(s' + D s - D N)\n\t\\end{equation}\n\tAnd comparing \\eqref{eq:re_death_i_sub} and \\eqref{eq:re_death_s_diff} we get next equation:\n\t\\begin{equation} \n\t\ts s'' - s'^2 +(-\\tilde{\\beta}s^2 + (\\gamma + D)s + D N)s' - \\tilde{\\beta}D s^3 - (\\tilde{\\beta}D N + D(\\gamma + D))s^2 - (\\gamma + D)D N s = 0\n\t\\end{equation}\n\tWe can see that coefficients at $s^3, s^2$ and $s$ are $consts$ so we substitute them with \\\\ \n\t$A = -\\tilde{\\beta}D, B = - (\\tilde{\\beta}D N + D(\\gamma + D)),  C = - (\\gamma + D)D N$:\n\t\\begin{equation} \\label{eq:death_main}\n\t\ts s'' - s'^2 +(-\\tilde{\\beta}s^2 + (\\gamma + D)s + D N)s' +A s^3 + B s^2 + C s = 0\n\t\\end{equation}\n\tNow we introduce a function $\\phi = \\frac{dt}{ds}$, so the equation will be:\n\t\\begin{equation} \\label{eq:death_main_phi}\n\t\t-\\phi' - \\frac{\\phi}{s} +(-\\tilde{\\beta}s^2 + (\\gamma + D)s + D N)\\frac{\\phi^2}{s} + (A s^2 + B s + C)\\phi^3 = 0\n\t\\end{equation}\n\tAnd by substitution $v = \\phi s, v' = \\phi's + \\phi$ the following equation occur:\n\t\\begin{equation} \\label{eq:death_main_v}\n\t\tv' +(-\\tilde{\\beta} + \\frac{(\\gamma + D)}{s} + \\frac{D N}{s^2})v^2 + (A + \\frac{B}{s} + \\frac{C}{s^2})v^3 = 0\n\t\\end{equation}\n\n\t\\newpage\n\tThen we assume these three substitutions:\n\t\\begin{numcases}{}\n\t\tr(s) = \\frac{1}{v(s)}, \\\\\n\t\t\\xi(s) = (\\tilde{\\beta} - \\frac{(\\gamma + D)}{s} - \\frac{D N}{s^2}), \\\\\n\t\t\\eta(s) = -(A + \\frac{B}{s} + \\frac{C}{s^2})\n\t\\end{numcases}\n\tand we get Abel-type first-order second-kind equation:\n\t\\begin{equation}\n\t\tr r' = \\xi(s)r + \\eta(s)\n\t\\end{equation}\n\n\t\\newpage\n\t\n\t\\section{Modeling COVID-19 pandemic}\n\n\t\\subsection{Definitions}\n\n\tIn order to create lifelike COVID-19 infection model we need to introduce more parameters in our model and consider different spread cases.\n\t\\begin{itemize}\n\t\t\\item \\textbf{$S$} -- Susceptible. Includes all individuals who are not infected but are susceptible to contract the disease.\n\t\t\\item \\textbf{$E$} -- Exposed. Includes all persons who are exposed to infection, but not yet infections. Some of them might fall ill and some may not. We introduced that component due to incubation period of COVID-19 pandemic (approximated 5-6 days by WHO).\n\t\t\\item \\textbf{$I_s$} -- Symptomatic infected. It includes all the individuals who were symptomatic and infectious. They have approached some health-care facility, but have not yet been quarantined. This compartment was brought into the picture considering concerning news from worst-affected counties like Italy and the U.S. of the hospitals and health-care centers getting filled up very fast during this pandemic. A significant portion of the infected individuals may not be quarantined in case of the health-care system collapses.\n\t\t\\item \\textbf{$I_{as}$} -- Asymptomatic infected. It includes all those people who are affected but asymptomatic before they either recover or die or get permanently disabled. This compartment was formalized keeping after reports of various authentic studies claiming that around 30-40 percent of the infected individuals remain\n\t\tasymptomatic.\n\t\t\\item \\textbf{$Q$} -- Quarantined. Includes all persons who are currently under quarantine in healh-care facility.\n\t\t\\item \\textbf{$Q'$} -- In intensive care unit. Includes the quarantined patients who had to be moved to ICU after their condition worsened.\n\t\t\n\t\t\\item \\textbf{$C$} -- Carrier. This compartment includes individuals who have left quarantine after being tested negative but actually have not fully healed. So they can possibly infetct other susceptible individuals. They eventually either fall sick again or recover from disease. We introduced it due to multiple cases of re-infection being reported from countries like South Korea, China and Japan. It is safe to assume that one of the following happened:\n\t\t\\begin{enumerate}\n\t\t\t\\item Medical inefficiency (inaccurate test result)\n\t\t\t\\item Loss of immunity after recovery and subsequent re-infection\n\t\t\\end{enumerate}\n\t\tFor the first possibility we introduced the $C$ compartment. To account for the second possibility we have kept the transition from $R$ to $S$ compartment respectively.\n\t\t\\item $R_{wd}$ -- Recovered without disability. It includes all individuals who have recovered from infection without any disability and they can no longer infect any other individual\n\t\t\\item $D$ -- Deceased. Includes all deaths during the pandemic.\n\t\t\\item $R_d$ -- Recovered with disability. In this compartment we have kept all people who have recovered from the infection, can no longer infect anyone else but have been permanently disabled post recovery.\n\t\\end{itemize}\n\t \n\t\\newpage\n\n\t\\subsection{Formualting differential equations}\n\n\tNow we can define differential equations corresponding to described model above.\n\n\t\\begin{equation}\n\t\t\\frac{dS}{dt} = -\\alpha \\frac{S(I_s + I_{as} + C)}{N} + g R_{wd}\n\t\\end{equation}\n\tWhere $\\alpha$ is the disease transmission rate (same as $\\beta = mp$ in SIR model) and $g$ is the rate at which a fraction of recovered individuals lose their immunity.\n\n\t\\begin{equation}\n\t\t\\frac{dE}{dt} = \\alpha \\frac{S(I_s + I_{as} + C)}{N} - \\mu E\n\t\\end{equation}\n\tIf average incubation period is taken to be an exponential distribution $\\mu$.\n\n\t\\begin{equation}\n\t\t\\frac{d I_s}{dt} = r \\mu E - \\varepsilon I_s + fC - \\zeta_1 I_s - \\eta_1 I_s\n\t\\end{equation}\n\tWhere $f$ is rate at which a fraction of carriers gets re-infected. Here $0 \\le r \\le 1$ is a number which shows how many individuals in the exposed compartment moves to $I_s$ compartment rather than $I_{as}$ one. And $\\varepsilon, \\zeta_1, \\eta_1$ are the rates at which infected individuals get quarantined, deceased, disabled respectively.\n\n\t\\begin{equation}\n\t\t\\frac{d I_{as}}{dt} = (1 - r)\\mu E - \\beta_3 I_{as} - \\zeta_3 I_{as} - \\eta_3 I_{as}\n\t\\end{equation}\n\tWhere $\\beta_3, \\zeta_3$ and $\\eta_3$ are the recovery rate, death rate and disability rate of asymptomatic individuals respectively.\n\n\t\\begin{equation}\n\t\t\\frac{dQ}{dt} = \\varepsilon I_s - \\beta_1 Q - vQ - pQ - \\zeta_2 Q - \\eta_2 Q\n\t\\end{equation}\n\tWhere $v, p, \\zeta_2$ and $\\eta_2$ are the rates at which the quarantined individuals go to carrier state, ICU, deceased and disabled compartments respectively. $\\beta_1$ is the recovery rate for quarantined people.\n\t\n\t\\begin{equation}\n\t\t\\frac{d Q'}{dt} = pQ - \\beta_4 Q' - \\zeta_5 Q' - \\eta_5 Q'\n\t\\end{equation}\n\tWhere $\\beta_4, \\zeta_5$ and $\\eta_5$ are the rate with which individuals in ICU recover, die and get disabled respectively.\n\n\t\\begin{equation}\n\t\t\\frac{dC}{dt} = vQ - fC - \\beta_2 C - \\zeta_4 C - \\eta_4 C\n\t\\end{equation}\n\tWhere $\\beta_2, \\zeta_4$ and $\\eta_4$ are the rate with which carrier individuals recover, die and get disabled silently, respectively.\n\n\t\\begin{equation}\n\t\t\\frac{dR_{wd}}{dt} = \\beta_1 Q + \\beta_3 I_{as} + \\beta_2 C - gR_{wd}\n\t\\end{equation}\n\n\t\\begin{equation}\n\t\t\\frac{dD}{dt} = \\zeta_1 I_s + \\zeta_2 Q + \\zeta_3 I_{as} + \\zeta_4 C + \\zeta_5 Q'\n\t\\end{equation}\n\n\t\\begin{equation}\n\t\t\\frac{dR_d}{dt} = \\eta_1 I_s + \\eta_2 Q + \\eta_3 I_{as} + \\eta_4 C + \\eta_5 Q'\n\t\\end{equation}\n\n\tSystem of these equations can be solved using numerical methods.\n\n\t\\newpage\n\n\t\\subsection{Parameters and initial conditions selection}\n\n\t\\begin{longtable}[c]{| c | c | c | c | c | c |}\n\t\t\\caption{Initial condtions and rates}\\\\\n\t\t\\hline\n\t\tInitial condition & Value & Rate & Value & Rate & Value\\\\\n\t\t\\hline\n\t\t$N$ & 83783945 & $\\alpha$ & 0.42 & $v$ & 0.05 \\\\\n\t\t$S$ & 83783935 & $g$ & 0.0001 & $p$ & 0.01\\\\\n\t\t$E$ & 0 & $\\mu$ & 7 & $\\zeta_2$ & 0.2\\\\\n\t\t$I_s$ & 10 & $f$ & 0.2 & $\\eta_2$ & 0.1 \\\\\n\t\t$I_{as}$ & 0 & $r$ & 0.3 & $\\beta_1$ & 0.5\\\\\n\t\t$Q$ & 0 &$\\varepsilon$ & 0.5 & $\\beta_4$ & 0.05\\\\\n\t\t$Q'$ & 0 &$\\zeta_1$ & 0.025 & $\\zeta_5$ & 0.2 \\\\\n\t\t$C$ & 0 &$\\eta_1$ & 0.1 & $\\eta_5$ & 0.1\\\\\n\t\t$R_{wd}$ & 0 & $\\beta_3$ & 0.1458 & $\\beta_2$ & 0.1458\\\\\n\t\t$D$ & 0 & $\\zeta_3$ & 0.1 & $\\zeta_4$ & 0.05\\\\\n\t\t$R_d$ & 0 & $\\eta_3$ & 0.05 & $\\eta_4$ & 0.01\\\\\n\t\t\\hline\n\n\t\\end{longtable}\n\n\tWe decided to use early data from Germany for modeling epidemics. Data sources links provided at the end of article. Primarily, we relied on dataset by \\textit{Our World in Data}. Rates were calculated using correlation with recent observations, research news and publications. These values were actual on February 2, 2020. We take into account further statistics to fine tune the parameters closer to real life.\n\n\t\\subsection{Obtained results}\n\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{seirs.png}\n\t\t\\caption{SEIRS model with fixed disease transmission rate $\\alpha = 0.42$.}\n\t\\end{figure}\n\n\t\\newpage\n\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{seirs_2.png}\n\t\t\\caption{SEIRS model with fixed disease transmission rate $\\alpha = 0.42$. Zoomed to outbreak.}\n\t\\end{figure}\n\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=15cm]{germany_stats.png}\n\t\t\\caption{Official Germany COVID-19 Statistics}\n\t\\end{figure}\n\n\tComparing official data and our model, we can see, that the start of the outbreak is pretty much the same, but due to fixed disease transmission rate in the model, which indicates almost complete disregard of security measures, we get more dead and  infected people, whereas the real disease spread rate begins to slow down because of the lockdown and other measures such as improved tests. \n\t\n\t\\\n\n\tLet's see how conditions getting worse if people simply do not maintain social distance and neglet personal protective equipment like masks. Potentially number of contacts and probability of getiing infection increases as well as our $\\alpha$ rate.\n\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{seirs_bigalpha.png}\n\t\t\\caption{SEIRS model with increased $\\alpha = 0.55$.}\n\t\\end{figure}\n\n\t\\newpage\n\n\t\\begin{figure}[h!]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{seirs_bigalpha_2.png}\n\t\t\\caption{SEIRS model with increased $\\alpha = 0.55$. Zoomed to outbreak.}\n\t\\end{figure}\n\n\tWe observe that expected outbreak occured earlier. Number of asymptomatic infected people reaches 5 millon, comparing with about 1 millon before. Meanwhile, the amount of deaths has almost doubled. Rapidly decreasing susceptible people means the high rate of infection. Thus, the situation has greately worsened. It means a heavy burden on medical institutions and will affect every aspect of our life.\n\n\t\\section{Conclusion}\n\n\tWe have created two models, which can help students understand basics of the disease spread process, and one more accurate, which can give more valuable information about epidemics, specifically about consequences of \"covid-dissidence\" and ignorance of the safety measurements.\n\n\t\\section{References and data sources}\n\n\t\\begin{itemize}\n\t\t\\item Exact analytical solutions of the Susceptible-Infected-Recovered (SIR) epidemic\n\t\tmodel and of the SIR model with equal death and birth rates. Tiberiu Harko, Francisco S. N. Lobo, M. K. Mak.\n\n\t\t\\item A Mathematical Model of Epidemics—A Tutorial\n\t\tfor Students. Yutaka Okabe and Akira Shudo. Department of Physics, Tokyo Metropolitan University, Hachioji, Tokyo 192-0397, Japan.\n\n\t\t\\item Modelling and simulation of COVID-19 propagation in a large population with specific reference to India.\n\t\tAshish Menon, Nithin K Rajendran, Anish Chandrachud, Girish Setlur. Department of Physics, Indian Institute of Technology Guwahati.\n\n\t\t\\item Statistics of the COVID-19 pandemic in Germany: \\url{https://en.wikipedia.org/wiki/Statistics_of_the_COVID-19_pandemic_in_Germany}\n\n\t\t\\item Complete COVID-19 dataset maintained by Our World in Data: \\url{https://github.com/owid/covid-19-data/tree/master/public/data/}\n\t\\end{itemize}\n\\end{document}", "meta": {"hexsha": "f8a011175517db9ca07594f628dcc57a39843c49", "size": 20871, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Math/sir-model.tex", "max_stars_repo_name": "Mr3zee/SIR-Model-Python", "max_stars_repo_head_hexsha": "e1807f2b96935123ad0258df2c0e2c169bb6796c", "max_stars_repo_licenses": ["MIT"], "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/sir-model.tex", "max_issues_repo_name": "Mr3zee/SIR-Model-Python", "max_issues_repo_head_hexsha": "e1807f2b96935123ad0258df2c0e2c169bb6796c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-06-25T11:21:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-25T11:21:49.000Z", "max_forks_repo_path": "Math/sir-model.tex", "max_forks_repo_name": "Mr3zee/SIR-Model-Python", "max_forks_repo_head_hexsha": "e1807f2b96935123ad0258df2c0e2c169bb6796c", "max_forks_repo_licenses": ["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.8114558473, "max_line_length": 645, "alphanum_fraction": 0.6914857937, "num_tokens": 7095, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8840392939666335, "lm_q1q2_score": 0.7883960145866258}}
{"text": "% -*- root: Main.tex -*-\n\\section{Principle Component Analysis}\n$\\mathbf{X} \\in \\mathbb{R}^{D \\times N}$. $N$ observations, $K$ rank.\\\\\n1. Empirical Mean: $\\overline{\\mathbf{x}} = \\frac{1}{N} \\sum_{n=1}^N \\mathbf{x}_n$.\\\\\n2. Center Data: $\\overline{\\mathbf{X}} = \\mathbf{X} - [\\overline{\\mathbf{x}}, \\ldots, \\overline{\\mathbf{x}}] = \\mathbf{X} - \\mathbf{M}$.\\\\\n3. Cov.: $\\boldsymbol{\\Sigma} = \\frac{1}{N\t} \\sum_{n=1}^N (\\mathbf{x}_n - \\overline{\\mathbf{x}}) (\\mathbf{x}_n - \\overline{\\mathbf{x}})^\\top = \\frac{1}{N} \\overline{\\mathbf{X}}\\overline{\\mathbf{X}}^\\top$.\\\\\n4. Eigenvalue Decomposition: $\\boldsymbol{\\Sigma} = \\mathbf{U} \\boldsymbol{\\Lambda} \\mathbf{U}^\\top$.\\\\\n5. Select $K < D$, inly keep $\\mathbf{U}_K, \\boldsymbol{\\lambda}_K$.\\\\\n6. Transform data onto new Basis: $\\overline{\\mathbf{Z}}_K = \\mathbf{U}_K^\\top \\overline{\\mathbf{X}}$.\\\\\n7. Reconstruct to original Basis: $\\tilde{\\overline{\\mathbf{X}}} = \\mathbf{U}_k \\overline{\\mathbf{Z}}_K$.\\\\\n8. Reverse centering: $\\tilde{\\mathbf{X}} = \\tilde{\\overline{\\mathbf{X}}} + \\mathbf{M}$.\\\\\nFor compression save $\\mathbf{U}_k, \\overline{\\mathbf{Z}}_K, \\overline{\\mathbf{x}}$.\\\\\n$\\mathbf{U}_k \\in \\mathbb{R}^{D \\times K}, \\boldsymbol{\\Sigma} \\in \\mathbb{R}^{D \\times D}, \\overline{\\mathbf{Z}}_K \\in \\mathbb{R}^{K \\times N}, \\overline{\\mathbf{X}} \\in \\mathbb{R}^{D \\times N}$\n\n\\subsection*{Iterative View}\nResidual $r_i$: $x_i - \\tilde{x}_i = I - uu^T  x_i$\\\\\nCov of $r$:  $\\frac{1}{n} \\sum_{i=1}^n (I-uu^T)x_i x_i^T (I-uu^T)^T =$ \\\\\n$(I-uu^T) \\Sigma (I-uu^T)^T = \\Sigma - 2\\Sigma u u^T + u u^T \\Sigma u u ^T = \\Sigma - \\lambda uu^T$ \\\\\n1. Find principal eigenvector of $(\\Sigma - \\lambda u u^T)$\\\\\n2. which is the second eigenvector of $\\Sigma$\\\\\n3. iterating to get $d$ principal eigenvector of $\\Sigma$\n\n\\subsection*{Power Method \\textit{- good for small k, easy, robust}}\nPower iteration: $v_{t+1} = \\frac{Av_t}{||Av_t||}$, $\\lim_{t \\rightarrow \\infty} v_t = u_1$\\\\\nAssuming $\\langle u_1, v_0 \\rangle \\not = 0$ and $|\\lambda_1| > |\\lambda_j| (\\forall j \\geq 2)$. \n\\textbf{SVD:} + good for mid-sized problems, numerical techniques (QR decomposition),..\n", "meta": {"hexsha": "c6e4923f1e1baf0569851d73341582ee35942202", "size": 2110, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DimensionalityReduction.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": "DimensionalityReduction.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": "DimensionalityReduction.tex", "max_forks_repo_name": "Emilien-P/eth-cil-exam-summary", "max_forks_repo_head_hexsha": "ebda1cb98b2e3d17e055b05cb0fd1e7decce507f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.1481481481, "max_line_length": 206, "alphanum_fraction": 0.6279620853, "num_tokens": 861, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8652240860523328, "lm_q1q2_score": 0.7883746359981433}}
{"text": "\\section{Evaluating Dirichlet Integral}\n\nNot every integral can be evaluated by \\textbf{Newton-Leibniz formula}. Some of\nthem require certain tricks, and this integral is a perfect example:\n\n\\begin{equation}\n\t\\int_0^\\infty{\\sin(x)\\over x}dx\n\t\\label{int-sinc}\n\\end{equation}\n\nThe function inside the integral of (\\ref{int-sinc}) is called the\n\\textit{sinc} function, which is extremely useful in the field of signal and\nimage processing. To integrate this function, we could consider finding the\nLaplace transform of this function:\n\n\\begin{equation}\n\t\\int_0^\\infty{\\sin(x)\\over x}dx=\\mathcal{L}\n\t\\left\\{\\sin(x)\\over x\\right\\}(0)\n\t\\label{sinc-laplace}\n\\end{equation}\n\nTherefore, the integration of \\textit{sinc} is divided into two steps:\n\n\\begin{itemize}\n\t\\item Find the Laplace transform of \\textit{sinc}\n\t\\item Evaluate the Laplace transform at $s=0$\n\\end{itemize}\n\n\\subsection{Laplace transform of \\textit{sinc}}\n\nWe denote the Laplace transform of \\textit{sinc} as $F(s)$, conveniencing the\nevaluation.\n\n$$F(s)=\\int_0^\\infty{\\sin(x)\\over x}e^{-sx}dx$$\n$$\n\\begin{aligned}\n\tF'(s)&={d\\over ds}\\int_0^\\infty{\\sin(x)\\over x}e^{-sx}dx \\\\\n\t&=\\int_0^\\infty{\\partial\\over\\partial s}{\\sin(x)\\over x}e^{-sx}dx \\\\\n\t&=-\\int_0^\\infty\\sin(x)e^{-sx}dx=-\\mathcal{L}\\{\\sin(x)\\}\n\\end{aligned}\n$$\n\nNow we are to find the Laplace transform of sine function. It will take two\niterations of integration by parts if we evaluate the integral directly.\nHowever, if we complexify it, turning $\\sin(x)$ to $\\Im\\left(e^{ix}\\right)$ in\nother words, we can make use of the properties of exponential function so that\nthe process becomes easier.\n\n$$\n\\begin{aligned}\n\t\\mathcal{L}\\{\\sin(x)\\}&=\\int_0^\\infty\\Im\\left(e^{ix}\\right)e^{-sx}dx \\\\\n\t&=\\Im\\left(\\int_0^\\infty e^{ix-sx}dx\\right)\n\t=\\Im\\left(\\int_0^\\infty e^{(i-s)x}dx\\right) \\\\\n\t&=\\Im\\left(\\left.e^{(i-s)x}\\over i-s\\right|_0^\\infty\\right) \\\\\n\t&=\\Im\\left(\\lim_{x\\to\\infty}{e^{(i-s)x}\\over i-s}-{1\\over i-s}\\right) \\\\\n\t&=\\Im\\left(1\\over s-i\\right)=\\Im\\left(s+i\\over(s+i)(s-i)\\right) \\\\\n\t&=\\Im\\left(s+i\\over s^2+1\\right)={1\\over s^2+1}\n\\end{aligned}\n$$\n\nAfter plugging the result of this function, we simplify the expression of\n$F'(s)$:\n\n\\begin{equation}\n\tF'(s)=-{1\\over s^2+1}\n\t\\label{sinc-deriv}\n\\end{equation}\n\nBefore trying to find the exact $F(s)$, we also need to consider its property,\nespecially its horizontal assymptote.\n\n$$\n\\lim_{s\\to\\infty}F(s)=\\int_0^\\infty{\\sin(x)\\over x}\n\\lim_{s\\to\\infty}\\left(e^{-sx}\\right)dx=0\n$$\n\nTherefore, $F(s)$ can be represented by what was concluded in equation\n(\\ref{sinc-deriv}) via expressing it as a subtraction:\n\n$$\n\\begin{aligned}\n\tF(s)&=F(s)-\\lim_{b\\to\\infty}F(b) \\\\\n\t&=\\int_\\infty^sF'(t)dt=-\\int_s^\\infty F'(t)dt \\\\\n\t&=-\\int_s^\\infty{-1\\over t^2+1}dt=\\left.\\arctan(t)\\right|_s^\\infty \\\\\n\t&={\\pi\\over 2}-\\arctan(s)\n\\end{aligned}\n$$\n\n\\subsection{Evaluate the Laplace transform of \\textit{sinc} at $s=0$}\n\nSince we have all the necessary equations calculated, we can now take down the\nintegral by simply plugging in that sacred zero.\n\n$$\n\\begin{aligned}\n\t\\int_0^\\infty{\\sin(x)\\over x}dx&=\\mathcal{L}\\left\\{\\sin(x)\\over x\\right\\}(0) \\\\\n\t&=F(0)={\\pi\\over2}-0={\\pi\\over2}\n\\end{aligned}\n$$\n\nAs it turns out, the integral of \\textit{sinc} from zero to infinity is half of\n$\\pi$.\n", "meta": {"hexsha": "a7587ba8894200a942fa1622be85f9eac2dccc55", "size": 3242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dirichlet-integral.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "dirichlet-integral.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dirichlet-integral.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 31.4757281553, "max_line_length": 80, "alphanum_fraction": 0.6881554596, "num_tokens": 1150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7883746254911811}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Conditional probability}\\label{sec:cond_prob}\n\nRecall from elementary probability that the conditional probability of $A$ given $B$ is defined by\n\\[\n\\prob(A|B) = \\frac{\\prob(A\\cap B)}{\\prob(B)}.\n\\]\nprovided that $P(B)>0$. The following theorem shows that this defines a probability measure on subsets of $\\Omega$.\n\n\\begin{theorem}\nLet $\\prob$ be a probability measure on subsets of $\\Omega$ and let $B$ be an event with $\\prob(B)>0$. Then the function\n\\[\n\\mathbb{Q}(A) = \\prob(A|B)\n\\]\nis also probability measure on subsets of $\\Omega$.\n\n\\begin{proof}\nTo show that $\\mathbb{Q}$ is a probability measure, we need to verify that $\\mathbb{Q}(\\emptyset) = 1$, $\\mathbb{Q}(\\Omega) = 1$ and that $\\mathbb{Q}$ is countably additive. Firstly,\n\\begin{align*}\n\\mathbb{Q}(\\emptyset) \n\t& = \\prob(\\emptyset|B) = \\prob(\\emptyset\\cap B)/\\prob(B) = \\prob(\\emptyset)/\\prob(B) = 0; \\\\\n\\mathbb{Q}(\\Omega) \n\t& = \\prob(\\Omega|B) = \\prob(\\Omega\\cap B)/\\prob(B) = \\prob(B)/\\prob(B) = 1.\n\\end{align*}\nTo prove that $\\mathbb{Q}$ is countable additive, let $A_1,A_2,\\ldots$ be pairwise disjoint subsets of $\\Omega$. Then using the fact that $\\prob$ is countably additive,\n\\begin{align*}\n\\mathbb{Q}(\\medcup_{i=1}^{\\infty} A_i) \n\t= \\prob(\\medcup_{i=1}^{\\infty} A_i\\,|\\,B)\n\t& = \\frac{\\prob\\big[(\\medcup_{i=1}^{\\infty} A_i) \\cap B\\big]}{\\prob(B)} \\\\\n\t& = \\frac{\\prob\\big[\\medcup_{i=1}^{\\infty} (A_i \\cap B)\\big]}{\\prob(B)} \\quad\\text{(because intersection is distributive over union)},\\\\\n\t& = \\frac{\\sum_{i=1}^{\\infty} \\prob(A_i \\cap B)}{\\prob(B)} \\quad\\text{(because the sets $A_i\\cap B$ are disjoint)}, \\\\\n\t& = \\sum_{i=1}^{\\infty}\\frac{\\prob(A_i \\cap B)}{\\prob(B)}\n\t  = \\sum_{i=1}^{\\infty}\\prob(A_i|B)\n\t\t= \\sum_{i=1}^{\\infty} \\mathbb{Q}(A_i)\\quad\\text{as required.}\n\\end{align*}\n\\end{proof}\n\\end{theorem}\n\n", "meta": {"hexsha": "245d9c07a4e2aeb1548236c8d436a2af153f31ba", "size": 1862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/02B_conditional_probability.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/02B_conditional_probability.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/02B_conditional_probability.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.4146341463, "max_line_length": 182, "alphanum_fraction": 0.6299677766, "num_tokens": 671, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.7883746234043132}}
{"text": "\\section{Maximising the generalised Rayleigh quotient}\n\nIn the following, we assume two symmetric matrices $\\A \\in \\reals^{N \\cross\nN}$ and $\\B \\in \\reals^{N \\cross N}$ (i.e. $\\A = \\A^T$ and $\\B =\n\\B^T$).\n\n\n\n\\subsection{The generalised Rayleigh quotient}\n\nThe generalised Rayleigh quotient of a non-zero vector $\\w \\in \\reals^N$ and\nthe ordered 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\n\n\n\\subsection{The generalised eigenvalue decomposition}\n\nThe generalised eigenvalue problem for the ordered matrix pair $(\\A,\\B)$\nconsists of finding the scalars $\\lambda_i$ and corresponding vectors $\\w_i$\nfor which the following holds:\n%\n\\begin{equation}\n\\label{eq:GEVD}\n\\A \\w_i = \\lambda_i \\B \\w_i\n\\end{equation}\n\nWe can gather all generalised eigenvectors $\\w_i$ as columns of a matrix\n$\\W$, and gather the corresponding generalised eigenvalues $\\lambda_i$ in a\ndiagonal matrix $\\Lambda$. The generalised eigenvalue decomposition (GEVD) of\n$(\\A,\\B)$ is then:\n\\[\n\\A \\W = \\Lambda \\B \\W\n\\]\n\n\n\n\\subsection{Theorem}\n\nThe first generalised eigenvector $\\w_1$ of $(\\A,\\B)$ (which corresponds to\nthe largest generalised eigenvalue $\\lambda_1$) is also the vector $\\what$\nthat maximises the generalised Rayleigh quotient $r(\\w)$.\n\n\n\n\\subsection{Proof}\n\nAs a first step, we will show that if $\\what$ is the maximum of $r(\\w)$, that\nit is indeed an eigenvector of $(\\A,\\B)$. In the second step, we will show\nthat the largest eigenvalue $\\lambda_1$ of $(\\A,\\B)$ corresponds to the\nmaximum 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\nTo calculate the gradient of $r(\\w)$, we first expand the inner product\n\\begin{equation*}\n\\begin{split}\n\\w^T \\A \\w = & \\; w_1 w_1 a_{11} + w_1 w_2 a_{12} + \\tdots \\\\\n                 & +  w_2 w_1 a_{21} + w_2 w_2 a_{22} + \\tdots \\\\\n                 & +  \\tdots\n\\end{split}\n\\end{equation*}\n%\nThe partial derivative with respect to say, the second element of $\\w$ then\nbecomes:\n\\begin{align*}\n\\pdv{w_2}(\\w^T \\A \\w) &= \\sum_{i=1}^N w_i a_{2i} \n                             + \\sum_{j=1}^N w_j a_{j2} \\\\\n                             % \n                          &= 2 \\; \\sum_{i=1}^N w_i a_{2i},\n\\end{align*}\nwhere the two sums are equal because $\\A$ is symmetric. Note that\n$\\sum_{i=1}^N w_i a_{2i}$ is the second element of the vector $\\A \\w$.\nBecause analogous expressions hold for partial derivatives with respect to\nthe other elements of $\\w$, we have:\n\\[\n\\grad(\\w^T \\A \\w) = 2 \\A \\w\n\\]\n\nSimilarly, we have:\n\\begin{align*}\n\\pdv{w_2}(\\frac{1}{\\w^T \\B \\w})\n    &= \\frac{-1}{\\qty(\\w^T \\B \\w)^2} \\; \\pdv{w_2}(\\w^T \\B \\w) \\\\\n    &= \\frac{-1}{\\qty(\\w^T \\B \\w)^2} \\; 2 \\sum_{i=1}^N w_i b_{2i},\n\\end{align*}\nand\n\\[\n\\grad(\\frac{1}{\\w^T \\B \\w})\n    = \\frac{-1}{\\qty(\\w^T \\B \\w)^2} \\; 2 \\B \\w\n\\]\n\nWe can now calculate\n\\begin{align*}\n\\grad{r(\\w)} &= \\frac{1}{\\w^T \\B \\w} \\grad(\\w^T \\A \\w)\n                + \\qty(\\w^T \\A \\w) \\; \n                  \\grad(\\frac{1}{\\w^T \\B \\w})  \\\\[1em]\n             % &= \\frac{1}{\\w^T \\B \\w} 2 \\A \\w\n             %    + \\w^T \\A \\w \n             %      \\frac{-1}{\\qty(\\w^T \\B \\w)^2} 2 \\B \\w  \\\\\n             &= \\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 now have the following condition for our\nmaximising vector $\\what$:\n\\[\n2 \\A \\what \\qty(\\what^T \\B \\what) \n    &= 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 generalised eigenvalue/eigenvector definition (\\cref{eq:GEVD})\nfor $\\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 a\neigenvector of $(\\A,\\B)$, with $r(\\what)$ its corresponding eigenvalue.\n\nAs the second step, we now show that $r(\\what)$ is the \\emph{largest}\neigenvalue of $(\\A,\\B)$. We follow the reasoning of \\cite{Trefethen1997} (p.\n204), who prove a related result for the ordinary Rayleigh quotient.\n\nWe will rewrite the generalised Rayleigh quotient $r(\\w)$ by writing the\narbitrary vector $\\w$ as a linear combination of the generalised eigenvectors\n$\\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\nGeneralised eigenvectors are defined up to a scaling factor. We may therefore\ndefine 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 generalised Rayleigh quotient is thus a convex combination of\ngeneralised eigenvalues $\\lambda_i$. The maximum of a convex combination of\none-dimensional points is obtained in the largest of these points. If\n$\\lambda_1$ is thus the largest generalised eigenvalue of $(\\A,\\B)$, then\n$\\max{r(\\w)} = \\lambda_1$.\n\nWe have thus shown that $\\what = \\argmax r(\\w) = \\w_1$, where $\\w_1$ is an\neigenvector of $(\\A,\\B)$, and that its corresponding eigenvalue $\\lambda_1 =\n\\max r(\\w) = r(\\what)$ is the largest of the eigenvalues of $(\\A,\\B)$.\n\n% \\qed\n", "meta": {"hexsha": "9606db46ba138270450a58dcb38c51fa9020b2e1", "size": 5567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "modules/Scraps/GEVD/Rayleigh.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/Rayleigh.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/Rayleigh.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": 33.3353293413, "max_line_length": 77, "alphanum_fraction": 0.6003233339, "num_tokens": 1994, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760038, "lm_q2_score": 0.8652240808393984, "lm_q1q2_score": 0.7883746208138841}}
{"text": "\\lab{Algorithms}{Reduced Row Echelon Form}{Reduced Row Echelon Form}\n\\objective{Write your own code to put a matrix in Reduced Row Echelon Form}\n\nRecall that there are three elementary row operations:\n\n\\begin{description}\n\\item[Type I]  Swap two rows: $R_j \\longleftrightarrow R_k$\n\\item[Type II] Multiply a row by a constant:  $a* R_j \\longrightarrow R_j$\n\\item[Type III] Add a multiple of one row to another: $ a R_k + R_j \\longrightarrow R_j$\n\\end{description}\nBy combining these operations, we can perform row reduction. Type\nthe following three m-files.  Be sure the path is set to the correct\ndirectory and that the file names correspond to the function names.\n\n\\begin{verbatim}\nfunction A = type1(A,j,k)\n%\n% This function swaps the j-th and k-th rows\n%\n\ntemp = A(j,:); A(j,:) = A(k,:); A(k,:) = temp;\n\\end{verbatim}\n\n\\begin{verbatim}\nfunction A = type2(A,j,a)\n%\n% This function multiplies the j-th row by the constant a\n%\n\nA(j,:) = a*A(j,:);\n\\end{verbatim}\n\n\\begin{verbatim}\nfunction A = type3(A,j,k,a)\n%\n% This function multiplies the constant a times\n% the k-th row and adds it to the j-th row\n%\n\nA(j,:) = a*A(k,:) + A(j,:);\n\\end{verbatim}\nNow test your functions by running the following:\n\\begin{verbatim}\n>> A = [4 5 6 3; 2 4 6 4; 7 8 0 5]\n\n>> B = type1(A,1,2)\n\\end{verbatim}\nThis swaps the first two rows. Now continue with the other two\nfunctions:\n\\begin{verbatim}\n>> C = type2(B,1,0.5)\n\n>> D = type3(C,2,1,-4)\n\n>> E = type3(D,3,1,-7)\n\\end{verbatim}\nAt this point we've reduced the first column of the system.  Let's\ncontinue with the second column:\n\\begin{verbatim}\n>> F = type2(E,2,-1/3)\n\n>> G = type3(F,1,2,-2)\n\n>> H = type3(G,3,2,6)\n\\end{verbatim}\nWe're almost done.  Let's finish the reduce the third column.\n\\begin{verbatim}\n>> I = type2(H,3,-1/9)\n\n>> J = type3(I,2,3,-2)\n\n>> K = type3(J,1,3,1)\n\\end{verbatim}\nWe have successfully row reduced the matrix.  We can check our work\nby typing {\\tt rref(A)}.\n\n\\section*{Programming Row Reduction}\n\nWhen we do row reduction by hand, we usually take extra steps to\navoid fractions.  However, computers aren't slowed down by decimal\ncomputations.  Below we will re-do the above reduction, but a little\nmore efficiently.  In addition, rather than defining a new matrix in\nevery step, we will redefine the matrix $A$ to be the output from\nthe last calculation.\n\\begin{verbatim}\n>> A = [4 5 6 3; 2 4 6 4; 7 8 0 5]\n\n>> A = type3(A,2,1,-A(2,1)/A(1,1))\n\n>> A = type3(A,3,1,-A(3,1)/A(1,1))\n\\end{verbatim}\nNotice that we didn't row swap or multiply a row by a constant to\nmake the leading entry a one.  Let's continue:\n\\begin{verbatim}\n>> A = type3(A,3,2,-A(3,2)/A(2,2))\n\n>> A = type3(A,1,2,-A(1,2)/A(2,2))\n\\end{verbatim}\nThe second column is reduced.  Now for the third column:\n\\begin{verbatim}\n>> A = type3(A,2,3,-A(2,3)/A(3,3))\n\n>> A = type3(A,1,3,-A(1,3)/A(3,3))\n\\end{verbatim}\nThe final step is to divide each row by its leading coefficient:\n\\begin{verbatim}\n>> A = type2(A,1,1/A(1,1))\n\n>> A = type2(A,2,1/A(2,2))\n\n>> A = type2(A,3,1/A(3,3))\n\\end{verbatim}\nWe are finished.  Compare your answer with what you get from {\\tt\nrref}.  We can generalize this process by writing a function:\n\\begin{verbatim}\nfunction A = rref_3x4(A)\n%\n% Reduces a 3 x 4 augmented matrix into rref\n%\nA = type3(A,2,1,-A(2,1)/A(1,1)); A = type3(A,3,1,-A(3,1)/A(1,1)); A\n= type3(A,3,2,-A(3,2)/A(2,2)); A = type3(A,1,2,-A(1,2)/A(2,2)); A =\ntype3(A,2,3,-A(2,3)/A(3,3)); A = type3(A,1,3,-A(1,3)/A(3,3)); A =\ntype2(A,1,1/A(1,1)); A = type2(A,2,1/A(2,2)); A =\ntype2(A,3,1/A(3,3));\n\n\\end{verbatim}\nNow test your function and compare with {\\tt rref}.\n\\begin{verbatim}\n>> A = randn(3,4)\n\n>> rref_3x4(A)\n\n>> ref(A)\n\\end{verbatim}\n\n\\section*{Remarks}\n\n\\begin{itemize}\n\\item The above algorithm won't work on every matrix because there is\nno logic for dealing with under-determined systems. As a result,\nit's a good idea to test this algorithm with random matrices. Why is\nthat?\n\\item Fast computer algorithms don't really compute the RREF this\nway. They actually compute the REF and then use back-substitution to\nfinish.\n\\item The above algorithm is actually called ``Row Reduction Without\nPivoting''. It turns out that the swap operation is important in\ndealing with certain matrices that are ``almost'' under determined.\n\\end{itemize}\n\n\\begin{problem}\nWrite a MATLAB function called {\\tt myrref}, which takes as\ninput an $n\\times (n+1)$ matrix and performs the above naive row\nreduction. Compare your answers with MATLAB's {\\tt rref}. HINT:\nWrite a nested {\\tt for} loop and type {\\tt help continue} to get a\ngood idea of what to do when $j=k$.\n\\end{problem}\n", "meta": {"hexsha": "a14dafe702aed290c1881c82f483d4bdc2f63240", "size": 4581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/RREF/RREF.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/RREF/RREF.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/RREF/RREF.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 28.9936708861, "max_line_length": 88, "alphanum_fraction": 0.6863130321, "num_tokens": 1532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159129, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.7882811150078}}
{"text": "% Source: waynedisonitau123\n\n\\subsubsection{Kirchhoff's Theorem}\nDenote $L$ be a $n \\times n$ matrix as the Laplacian matrix of graph $G$, where $L_{ii} = d(i)$, $L_{ij} = -c$ where $c$ is the number of edge $(i, j)$ in $G$.\n\\begin{itemize}\n    \\item The number of undirected spanning in $G$ is $\\lvert \\det(\\tilde{L}_{11}) \\rvert$.\n    \\item The number of directed spanning tree rooted at $r$ in $G$ is $\\lvert \\det(\\tilde{L}_{rr}) \\rvert$.\n\\end{itemize}\n\n\\subsubsection{Tutte's Matrix}\nLet $D$ be a $n \\times n$ matrix, where $d_{ij} = x_{ij}$ ($x_{ij}$ is chosen uniformly at random) if $i < j$ and $(i, j) \\in E$, otherwise $d_{ij} = -d_{ji}$. $\\frac{rank(D)}{2}$ is the maximum matching on $G$.\n\n\\subsubsection{Cayley's Formula}\n\\begin{itemize}\n  \\item Given a degree sequence $d_1, d_2, \\ldots, d_n$ for each \\textit{labeled} vertices, there are $$\\frac{(n - 2)!}{(d_1 - 1)!(d_2 - 1)!\\cdots(d_n - 1)!}$$ spanning trees.\n  \\item Let $T_{n, k}$ be the number of \\textit{labeled} forests on $n$ vertices with $k$ components, such that vertex $1, 2, \\ldots, k$ belong to different components. Then $T_{n, k} = kn^{n - k - 1}$.\n\\end{itemize}\n\n\\subsubsection{Erdős–Gallai Theorem}\nA sequence of non-negative integers $d_1 \\geq d_2 \\geq \\ldots \\geq d_n$ can be represented as the degree sequence of a finite simple graph on $n$ vertices if and only if $d_1 + d_2 + \\ldots + d_n$ is even and\n$$ \\sum_{i = 1}^{k}d_i \\leq k(k - 1) + \\sum_{i = k + 1}^{n}\\min(d_i, k) $$\nholds for all $1 \\leq k \\leq n$.\n\n\\subsubsection{Burnside's Lemma}\nLet $X$ be a set and $G$ be a group that acts on $X$.\nFor $g \\in G$, denote by $X^g$ the elements fixed by $g$:\n\\[\nX^g = \\{ x \\in X \\mid gx \\in X \\}\n\\]\nThen\n\\[\n|X/G| = \\frac{1}{|G|} \\sum_{g \\in G} |X^g|.\n\\]\n", "meta": {"hexsha": "a186171412dba2f70a76f266f0bc451e956dc875", "size": 1739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nacl/math/theorems.tex", "max_stars_repo_name": "ToxicPie/NaCl", "max_stars_repo_head_hexsha": "8cb50bacc25f2b99a33fb5938ea4ec9906d8d65c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-08-31T17:51:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-13T16:22:25.000Z", "max_issues_repo_path": "nacl/math/theorems.tex", "max_issues_repo_name": "ToxicPie/NaCl", "max_issues_repo_head_hexsha": "8cb50bacc25f2b99a33fb5938ea4ec9906d8d65c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nacl/math/theorems.tex", "max_forks_repo_name": "ToxicPie/NaCl", "max_forks_repo_head_hexsha": "8cb50bacc25f2b99a33fb5938ea4ec9906d8d65c", "max_forks_repo_licenses": ["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.1470588235, "max_line_length": 211, "alphanum_fraction": 0.6371477861, "num_tokens": 677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.925229961215457, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7882522544446523}}
{"text": "\\documentclass{article}\n\n\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\n\n\\newtheorem{theorem}{Theorem}\n\n\\title{From Mass-Spring Systems to Spectral Graph Neural Networks}\n\\author{Nguyen Ngoc Khanh}\n\n\\begin{document}\n    \\maketitle\n\n    \\section{Mass-Spring System}\n\n    \\subsection{The two particles system}\n\n    Consider a spring follows Hook's law. Let two particles $i$ and $j$ connected by a spring located at $x_i$ and $x_j$ respectively and $e_{i j} = \\frac{x_j - x_i}{||x_j - x_i||_2}$ be the direction from $x_i$ to $x_j$ then the force that $i$ affects $j$ can be represented as:\n\n    \\begin{equation}\n        F_{i j} = - k (||x_j - x_i)||_2 - L) e_{i j} = - k (x_j - x_i) + k L e_{i j}\n    \\end{equation}\n\n    where $k$ is a positive real number, the characteristic of the spring and $L$ is the initial length the of spring. The magnitude of the force is proportional to the displacement from the initial distance between two particles.\n\n    Let two particles connected by a spring sit in an Euclidean space such that the particles can freely move on a particular $z$ axis. At the initial condition, the two particles are located at $x_i$ and $x_j$ and the spring is at its length ($||x_j - x_i||_2 = L$) (no force).\n\n    \\begin{figure}[h!]\n        \\centering\n        \\includegraphics[width=0.8\\textwidth]{fig1.png}\n        \\caption{subspace of $e_{i j}$ and $z$}\n        \\label{fig:fig1}\n    \\end{figure}\n\n    Since, $i$ and $j$ can only move in the $z$ axis, we can rewrite\n\n    \\begin{gather*}\n        x_i = x_i^{(0)} + z_i z \\\\\n        x_j = x_j^{(0)} + z_j z \\\\\n    \\end{gather*}\n\n    Where $x_i^{(0)}$ and $x_j^{(0)}$ are the initial positions of $i$ and $j$, $z_i$ and $z_j$ are the displacements on the $z$ axis. Hence, the projected force on the $z$ axis can be written as\n\n    \\begin{equation}\n        F_{i j} \\cdot z = (- k (x_j - x_i) + k L e_{i j}) \\cdot z = (- k (x_j^{(0)} - x_i^{(0)}) + k L e_{i j}) \\cdot z + (- k (z_j - z_i) z) \\cdot z\n    \\end{equation}\n\n    The first term is the dot product of the initial force with the $z$ direction which is essential zero since there is no force at the beginning. Hence, the projected force on the $z$ axis can be written as\n\n    \\begin{equation}\n        F_{i j} \\cdot z = - k (z_j - z_i)\n    \\end{equation}\n\n    The projected force on the $z$ axis linearly depends on the corresponding displacement.\n\n    \\subsection{The n particles system}\n\n    Let $n$ particles with the same weight $m$ on an an Euclidean space that can freely move on a particular $z$ axis. Some of them are connected by springs of the same characteristic $k$ which is denoted by a undirected unweighted graph $G = (V, E)$. A particular node $i$ is affected by all of its neighbours where the projected force on $i$ is\n\n    \\begin{figure}[h!]\n        \\centering\n        \\includegraphics[width=0.8\\textwidth]{fig2.png}\n        \\caption{4 particles system}\n        \\label{fig:fig2}\n    \\end{figure}\n\n    \\begin{equation}\n        F_i \\cdot z = - k \\sum_{e_{j i} \\in E} z_i - z_j = - k (d_i z_i - \\sum_{e_{j i} \\in E} z_j)\n    \\end{equation}\n\n    Where $d_i$ denotes the degree of the node $i$. Newton's Second Law of Motion:\n\n    \\begin{gather*}\n        a_i \\cdot z = \\frac{F_i}{m} \\cdot z \\\\\n        \\ddot{z_i} = - \\frac{k}{m} (d_i z_i - \\sum_{e_{j i} \\in E} z_j)\n    \\end{gather*}\n\n    We can rewrite in the matrix form\n\n    \\begin{equation}\n        \\ddot{z} =  - \\frac{k}{m} (D - A) z = - \\frac{k}{m} L z\n        \\label{eq:newton_2nd}\n    \\end{equation}\n\n    Where $z = (z_1, z_2, ..., z_n)^T$, $A$ is the adjacency matrix of $G$ and $D$ is the degree matrix of $A$ (diagonal matrix where each entry equals to the corresponding degree of the node). $L = D - A$ is called Laplacian matrix of $A$.\n\n    We are seeking the mode of oscillation of the system. A mode of oscillation is a particular frequency where all particles oscillate at the same frequency. At that frequency, the differential equation for each particle must be in the form:\n\n    \\begin{equation}\n        \\ddot{z_i} = - \\omega^2 z_i\n    \\end{equation}\n\n    Where $\\omega$ is the frequency. In the matrix form:\n\n    \\begin{equation}\n        \\ddot{z} = - \\omega^2 z\n        \\label{eq:oscillation_mode}\n    \\end{equation}\n\n    From \\ref{eq:newton_2nd} and \\ref{eq:oscillation_mode}, we have\n\n    \\begin{equation}\n        L z = \\frac{m}{k} \\omega^2 z\n        \\label{eq:oscillation_mode_freq}\n    \\end{equation}\n\n    From \\ref{eq:oscillation_mode_freq}, the oscillation mode frequencies are equivalent to the eigenvalues of the Laplacian matrix, and the initial condition to achieve each of the frequencies is the corresponding eigenvector.\n\n    Since $L$ is real symmetric, by the Spectral Theorem, it has an eigenbasis. Furthermore, $L$ is positive semi definite, then all of its eigenvalues are positive, hence the frequencies make sense.\n\n    For an arbitrary initial condition, since the system is linear, we can decompose the displacement $z$ into the eigenbasis of the Laplacian matrix then solve each of the component individually.\n\n    \\section{Graph Laplacian Basis}\n\n    Recall that, the eigen decomposition of $L$ is as follow:\n\n    \\begin{equation}\n        L = U \\Lambda U^T = U \\Lambda U^{-1}\n    \\end{equation}\n\n    Where each column vector in $U$ is a normalized eigenvector.\n\n    Analogous to Fourier Transform, the eigenvalues of Laplacian matrix can serve as the frequency and the eigenbasis is corresponding to the Fourier basis.\n\n    Let $x \\in \\mathbb{R}^n$ be a graph signal on $G = (V, E)$ where each component of $x$ is a real number corresponding to a node in $G$.\n\n    The convolution in spatial domain is equivalent to multiplication in spectral domain. Define the convolution operation as:\n\n    \\begin{equation}\n        y(x) =  U ( U^T w \\odot U^T x )\n        \\label{eq:conv_vec}\n    \\end{equation}\n\n    Where $w \\in \\mathbb{R}^n$ is called filter or kernel. Define $W = diag(U^T w)$ be the diagonal matrix whose entries are the entries of $U^T w$, we can rewrite \\ref{eq:conv_vec} as\n\n    \\begin{equation}\n        y(x) =  (U W U^T) x\n    \\end{equation}\n\n    \\subsection{ChebNet}\n\n\n    Let $\\mathcal{L}$ be the normalized laplacian matrix.\n\n    \\begin{equation}\n        \\mathcal{L} = D^{-\\frac{1}{2}} L D^{-\\frac{1}{2}} = I - D^{-\\frac{1}{2}} A D^{-\\frac{1}{2}}\n    \\end{equation}\n\n    The decomposition of $\\mathcal{L}$\n\n    \\begin{equation}\n        \\mathcal{L} = U \\Lambda U^T = U \\Lambda U^{-1}\n    \\end{equation}\n\n    \\begin{theorem}(Chung \\cite{chung1997spectral})\n        All eigenvalues of $\\mathcal{L}$ are in the interval $[0, 2]$.\n    \\end{theorem}\n\n    ChebNet \\cite{defferrard2016convolutional} approximate the diagonal matrix $W$ using Chebyshev polynomials as the orthogonal basis in the polynomial subspace of the vector space of all functions $f: [-1, +1] \\to \\mathbb{R}$ with respect to the inner product.\n\n    \\begin{equation}\n        \\int_{-1}^{+1} f(x) g(x) \\frac{dx}{\\sqrt{1-x^2}}\n    \\end{equation}\n\n    Chebyshev polynomials of the first kind:\n\n    \\begin{equation}\n        T_{n+1}(x) = 2x T_n(x) - T_{n-1}(x)\n    \\end{equation}\n\n    Where $x \\in [-1, +1]$, $T_0(x) = 1$ and $T_1(x) = x$. Let $f_i: [-1, +1] \\to \\mathbb{R}$ is an arbitrary function such that $f_i(\\Tilde{\\lambda_i}) = w_i$ where $\\Tilde{\\lambda_i} = \\frac{2 \\lambda_i}{\\lambda_{\\max}} - 1 \\in [-1, +1]$, $\\lambda_{\\max}$ is the largest eigenvalue. We want to project $f_i$ into the subspace with the orthogonal basis of the first $K$ terms of Chebyshev polynomials of the first kind. We can write $f_i$ as\n\n    \\begin{equation}\n        \\hat{f}_i(t) = \\sum_{k=0}^{K-1} \\theta_{k i} T_k(t)\n    \\end{equation}\n\n    Hence, $w_i$ is approximated as\n\n    \\begin{equation}\n        \\hat{w_i} = \\hat{f}_i(\\Tilde{\\lambda_i}) = \\sum_{k=0}^{K-1} \\theta_{k i} T_k(\\Tilde{\\lambda_i})\n    \\end{equation}\n\n    Matrix form of the approximation on $W$:\n\n    \\begin{equation}\n        \\hat{W} = \\sum_{k=0}^{K-1} \\theta_k T_k(\\Tilde{\\Lambda})\n    \\end{equation}\n\n    Where $\\Tilde{\\Lambda}$ is the diagonal matrix of $\\Tilde{\\lambda_i}$. Moreover,\n\n    \\begin{equation}\n        U \\hat{W} U^T = \\sum_{k=0}^{K-1} \\theta_k U T_k(\\Tilde{\\Lambda}) U^T = \\sum_{k=0}^{K-1} \\theta_k T_k(\\Tilde{\\mathcal{L}})\n    \\end{equation}\n\n    Where $\\Tilde{\\mathcal{L}} = \\frac{2 \\mathcal{L}}{\\lambda_{\\max}} - I$. It is a great exercise to prove the Chebyshev recurrence for $\\Tilde{\\mathcal{L}}$:\n\n    \\begin{equation}\n        T_{n+1}(\\Tilde{\\mathcal{L}}) = 2 \\Tilde{\\mathcal{L}} T_n(\\Tilde{\\mathcal{L}}) - T_{n-1}(\\Tilde{\\mathcal{L}})\n    \\end{equation}\n\n\n\n    Finally, The convolution operation is\n\n    \\begin{equation}\n        y(x) = \\sum_{k=0}^{K-1} \\theta_k T_k(\\Tilde{\\mathcal{L}}) x\n    \\end{equation}\n\n    The construction of ChebNet avoids decomposing the matrix $L$ as compare to \\ref{eq:conv_vec}.\n\n    \\subsection{Graph Convolutional Network}\n\n    Similar to ChebNet, GCN \\cite{kipf2016semi} limits $K = 2$ and sets $\\lambda_{\\max} = 2$ hence $\\Tilde{\\mathcal{L}} = \\mathcal{L} - I$.\n\n    \\begin{gather*}\n        U \\hat{W} U^T = \\theta_0 T_0(\\Tilde{\\mathcal{L}}) + \\theta_1 T_1(\\Tilde{\\mathcal{L}}) \\\\\n        = \\theta_0 I + \\theta_1 \\Tilde{\\mathcal{L}} \\\\\n        = \\theta_0 I - \\theta_1 D^{-\\frac{1}{2}} A D^{-\\frac{1}{2}}\n    \\end{gather*}\n\n    The convolution operation is\n\n    \\begin{equation}\n        y(x) = \\theta_0 x - \\theta_1 D^{-\\frac{1}{2}} A D^{-\\frac{1}{2}} x\n    \\end{equation}\n\n    The notes here is greatly inspired by \\cite{chen2020note}.\n\n    \\bibliographystyle{plain}\n    \\bibliography{references}\n\\end{document}", "meta": {"hexsha": "d947cb3a802285c3536d1387f0c75e9743a6b68b", "size": 9544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "blog/spectral/tex/main.tex", "max_stars_repo_name": "khanhhhh/khanhhhh.github.io", "max_stars_repo_head_hexsha": "f6313f0228a480b37e5f4ba9550e3cf011e60ba8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-12-14T08:27:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T14:51:34.000Z", "max_issues_repo_path": "blog/spectral/tex/main.tex", "max_issues_repo_name": "khanh-nguyen-code/khanh-nguyen-code.github.io", "max_issues_repo_head_hexsha": "4c047a941720e46b004d0bb922507c3b2bc7132f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "blog/spectral/tex/main.tex", "max_forks_repo_name": "khanh-nguyen-code/khanh-nguyen-code.github.io", "max_forks_repo_head_hexsha": "4c047a941720e46b004d0bb922507c3b2bc7132f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-07-30T05:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-30T05:30:49.000Z", "avg_line_length": 40.6127659574, "max_line_length": 442, "alphanum_fraction": 0.6428122381, "num_tokens": 3112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969137, "lm_q2_score": 0.8807970670261976, "lm_q1q2_score": 0.788127934877867}}
{"text": "\\begin{frame}\n\t\\frametitle{Random variables}\n\tA variable quantity whose possible values depend, in random manner, on a set of random outcomes events\\footnote{\\href{https://en.wikipedia.org/wiki/Random_variable}{Wikipedia}}\\vspace{1em}\n\t\n\tEvery random variables is defined over \\emph{probability space}: $(\\Omega, \\mathcal{F}, \\mathcal{P})$ \\footnote{Additional information can be found, among others, in \\href{http://vfu.bg/en/e-Learning/Math--Bertsekas_Tsitsiklis_Introduction_to_probability.pdf}{D.P. Bertsekas and J.N. Tsitsiklis. Introduction to Probability}}\\vspace{1em}\n\t\n\tConsider the toss of a coin\n\t\\begin{itemize}\n\t\t\\item $\\Omega=\\{H, T\\}$ is the set of possible outcomes. In this case, head or tail\n\t\t\\item $\\mathcal{F}=\\{\\{\\}, \\{H\\}, \\{T\\}, \\{H,T\\}\\}$ is the set of events we consider\n\t\t\\item $\\mathcal{P}$ probability function. It associates elements of $\\mathcal{F}$ with a probability value. For example $$\\mathcal{P}(\\{\\})=0,\\quad\\mathcal{P}(\\{H\\})=0.5, \\quad\\mathcal{P}(\\{T\\})=0.5, \\quad \\mathcal{P}(\\{H, T\\})=1$$\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Moments}\n\t$X$ is a random variable , taking values in $\\mathbb{R}$, and having probability density function $f(x)$\n\t\\begin{itemize}\n\t\t\\item Mean: $\\mu=E[X]=\\int_\\mathbb{R} sf(s)ds$\n\t\t\\item $n^{th}$ moment: $\\int_\\mathbb{R} s^nf(s)ds$ \n\t\t\\item $n^{th}$ central moment $E[(X-E[X])^n]=\\int_\\mathbb{R} (s-\\mu)^nf(s)ds$\n\t\t\\begin{itemize}\n\t\t\t\\item Variance: second central moment $E[(X-E[X])^2]=\\int_\\mathbb{R} (s-\\mu)^2f(s)ds$\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\n\t\\vspace{1em}\n\tSome variables have moments on infinite value. For example \\emph{heavy tailed distribution} \\footnote{\\href{https://en.wikipedia.org/wiki/Heavy-tailed_distribution}{\\small{ Wikipedia. Heavy-tailed distribution}}} \n\t$$f(x)=\\left\\{\\begin{aligned}\n\t\t\t\t\t\\frac{1}{x^2} && x \\geq 1\\\\\n\t\t\t\t\t0&&\\textrm{otherwise}\n\t\t\t\t   \\end{aligned}\n\t\\right.$$\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Mean and mode (most likely outcome)}\n\t\\emph{Mean} and \\emph{mode} are different concept\\vspace{0.5em}\n\t\\begin{itemize}\n\t\t\\item Mean: weighted sum of all of the possible outcomes\n\t\t\\begin{itemize}\n\t\t\t\\item Mean value could lie outside the set of possible outcomes\n\t\t\\end{itemize}\n\t\t\\item Mode: An outcome with the highest probability value\n\t\\end{itemize}\n\t\\vspace{0.5em}\n\t\\begin{columns}\n\t\t\\column{0.5\\textwidth}\n\t\t$X$ is a random variable taking values\n\t\t\\begin{itemize}\n\t\t\t\\item 0 with probability 0.2 \n\t\t\t\\item 1 with probability 0.8\n\t\t\\end{itemize}\n\t\t\\vspace*{0.5em}\n\t\n\t    Mean value: $\\mu=0.2\\cdot 0 + 0.8 \\cdot 1=0.8$\\\\\\vspace{0.5em}\n\t    \n\t\tMode: $\\argmax_{x\\in\\{0,1\\}} p(x) \\;=1$\n\t\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{block}{Probability of $X$}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t%\\draw[help lines, color=gray!30, dashed] (-4.9,-4.9) grid (4.9,4.9);\n\t\t\t\\draw[->, thick] (-0.5,0)--(1.5,0) node[right]{$x$};\n\t\t\t\\draw[->, thick] (-0.5,0)--(-0.5,1) node[above]{$p(x)$};\n\t\t\t\\draw (0, 0) -- (0, 0.2) node [above] {$0.2$};\n\t\t\t\\draw (1, 0) -- (1, 0.8) node [above] {$0.8$};\n\t\t\t\\node [below] at (0,0) {0};\n\t\t\t\\node [below] at (1,0) {1};\n\t\t\t\\filldraw[fill=black!40, draw=black](0,0.2) circle (0.05cm);\n\t\t\t\\filldraw[fill=black!40, draw=black](1,0.8) circle (0.05cm);\n\t\t\t\\end{tikzpicture}\n\t\t\\end{block}\n\t\\end{columns}\n\t\n\t\n\t%Under certain assumptions (e.g., Ergodicity) the average of \n\t\n\t\\takeaway{\\bf{The mean value is not even an element of the possible outcomes}}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{Sum of independent random variable}\n\t\\onslide<1->The distribution of the sum of two random variables must always be carefully computed\\vspace{0.5em}\n\t\\begin{columns}\\onslide<1->\n\t\t\\column{0.5\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item <1->$X$ uniformly distributed between 0 and 1%, $X\\sim\\mathcal{U}(0, 1)$\n\t\t\t\\item <1->$Y$ uniformly distributed between 0 and 1\n\t\t\t\\item <1->$Z=X+Y$ \\emph{is not} uniformly distributed between 0 and 1\n\t\t\t\\item <2-> The distribution of $Z$ depends on the joint distribution of $X$ and $Y$\n\t\t\t\\item <3-> If $X$ and $Y$ are independent variables, then $Z$ has a triangular distribution\\\\\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $X$ and $Y$ are independent if\n\t\t\t\tfor all $x$ and $y$ $$P(X\\leq x,Y\\leq y)=P(X\\leq x)\\cdot P(Y \\leq y)$$\t\n\t\t\t\\end{itemize}\t\n\t\t\\end{itemize}\n\t\n\t\t\\column{0.46\\textwidth}\n\t\t\\begin{block}{Probability density functions}\n\t\t\t\\onslide<1->{\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\draw[->] (-0.5,0)--(1.5,0) node[right]{$x$};\n\t\t\t\t\\draw[->] (-0.5,0)--(-0.5,1.5) node[above]{$p(x)$};\n\t\t\t\t\\draw[very thin, dashed] (-0.5, 1)node[left] {1} -- (0, 1);\n\t\t\t\t\\draw[thin](0, 0) node[below] {0}-- (0, 1);\n\t\t\t\t\\draw[thick] (0, 1) -- (1, 1); \n\t\t\t\t\\draw[thin] (1, 0)node[below] {1} -- (1, 1);\n\t\t\t\\end{tikzpicture}}\n\t\t\t\\onslide<3->{\n\t\t\t\\begin{tikzpicture}\n\t\t\t\\draw[->] (-0.5,0)--(2.5,0) node[right]{$z$};\n\t\t\t\\draw[->] (-0.5,0)--(-0.5,1.5) node[above]{$p(z)$};\n\t\t\t\\draw[very thin, dashed] (-0.5, 1)node[left] {1} -- (1, 1);\n\t\t\t\\draw[thick](0, 0) node[below] {0}-- (1, 1);\n\t\t\t\\draw[very thin, dashed] (1, 0)node[below]{1} -- (1, 1); \n\t\t\t\\draw[thick] (2, 0)node[below] {2} -- (1, 1);\n\t\t\t\\end{tikzpicture}}\n\t\t\\end{block}\n\t\\end{columns}\n\\end{frame}\n\\begin{frame}\n\t\\frametitle{Sum of variables normally distributed random variables}\n\tThe Gaussian distribution is also called \\emph{Normal} distribution and is denoted with the symbol $\\mathcal{N}$\\vspace{0.5em}\n\t\n\t\\begin{itemize}\n\t\t\\item The probability density function of a normally distributed random variable $X$ is\n\t\t$$f_X(x;\\mu,\\sigma)=\\frac{1}{\\sigma\\sqrt{2\\pi}}e^{-\\frac{(x-\\mu)^s}{2\\sigma^2}}$$\n\t\t\\item <2-> If $X\\sim\\mathcal{N}(\\mu_x, \\sigma_x^2)$ and $Y\\sim\\mathcal{N}(\\mu_y, \\sigma_y^2)$ and are independent, then\n\t\t\\item <2-> $Z=X+Y$ is also normally distributed;\\vspace{1em} $Z\\sim\\mathcal{N}(\\mu_x+\\mu_y, \\sigma_x^2+\\sigma_y^2)$\n\t\t%\\item <2-> If $\\alpha$ is a non-zero constant, then $\\alpha Z$ is normally distributed\n\t\t%\\begin{itemize}\n\t\t%\t\\item mean: $\\alpha \\mu_z$, variance: $\\alpha^2\\sigma_z^2$\n\t\t%\\end{itemize}\n\t\n\t\t\\item <3-> If $\\bm{Z}$  has a multivariate normal distribution with mean $\\bm{\\mu}_z$ and covariance $L=E[(Z-\\bm{\\mu}_z)(Z-\\bm{\\mu}_z)^T]$\n\t\tand $A$ is a matrix, then\n\t\t\\item <3-> The variable $\\bm{S}=A\\bm{Z}$ is normally distributed with mean $A \\bm{\\mu}_z$ and covariance matrix is $ALA^T$\n\t\\end{itemize} \n\\onslide<2>{\n\\takeaway{\\large Note however that $X\\cdot Y$ is \\emph{not} normally distributed}}\n\\end{frame}\n\n\\section{Random variables and dynamic systems}\n\\separatorslide\n\n\\begin{frame}\n\t\\frametitle{Gaussian distributions and linear systems}\n\tAssume \n\t\\begin{columns}\n\t\t\\column{0.6\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item $X(0)$ is normally distributed, $X(0)\\sim\\mathcal{N}(\\mu_0, \\sigma_0^2)$\n\t\t\t\\item $W(k)$ is normally distributed, $W(k)\\sim\\mathcal{N}(\\mu_{w,k}, \\sigma_{w,k}^2)$\n\t\t\t\\item $X(0)$ and $W(k)$ are independent for all $k$\n\t\t\t\\item for $k\\geq0$ the following recursive equation holds: $X(k+1) =X(k) + W(k)$\n\t\t\\end{itemize}\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{block}{Graphical representation}\n\t\t\t\\begin{tikzpicture}\n\t\t\t\\node(X0){$X(0)$};\n\t\t\t\\node[above=1em of X0](W0){$W(0)$};\n\t\t\t\\node[right=1em of X0](sum1){$+$};\n\t\t\t\\node[right=1em of sum1](X1){$X(1)$};\n\t\t\t\\node[above=1.2em of X1](W1){$W(1)$};\n\t\t\t\\node[right=1em of X1](sum2){$+$};\n\t\t\t\\node[right=1em of sum2](X3){$\\cdots$};\n\t\t\t\\draw[->] (W0) to (sum1);\n\t\t\t\\draw[->] (X0) to (sum1);\n\t\t\t\\draw[->] (sum1) to (X1);\n\t\t\t\\draw[->] (W1) to (sum2);\n\t\t\t\\draw[->] (X1) to (sum2);\n\t\t\t\\draw[->] (sum2) to (X3);\n\t\t\t\\end{tikzpicture}\t\t\n\t\t\\end{block}\n\t\\end{columns}\n\t\n\t\\vspace*{0.5em}\n\n\t\\onslide<1-> What is the distribution of $X(1)$ ?\n\t\\begin{itemize}\\onslide<2->\n\t\t\\item $X(1)$ is normally distributed (sum of two independent Gaussian variables)\n\t\t\\item Mean $\\mu_1=\\mu_0+\\mu_{w,0}$, variance $\\sigma_1^2 = \\sigma_0^2 + \\sigma_{w,0}^2$\n\t\\end{itemize}\n\n\t\\vspace*{0.5em}\n\t\\onslide<2-> What is the distribution of $X(k)$ ?\n\t\\begin{itemize}\\onslide<3->\n\t\t\\item $X(k)$ is Gaussian distributed% (sum of independent Gaussian variables)\n\t\t\\item Mean $\\mu_k=\\mu_0+\\sum_{j=0}^{k-1}\\mu_{w,j}$, variance $\\sigma_k^2=\\sigma_0^2 + \\sum_{j=0}^{k-1}\\sigma_{w,j}^2$\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Non Gaussian distributions and linear systems}\n\tAssume \n\t\\begin{columns}\n\t\t\\column{0.6\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item $X(0)$ is uniformly distributed, $X(0)\\sim\\mathcal{U}(0, 1)$\n\t\t\t\\item $W(k)$ is uniformly distributed, $W(k)\\sim\\mathcal{U}(0, 1)$\n\t\t\t\\item $X(0)$ and $W(k)$ are independent for all $k$\n\t\t\t\\item for $k\\geq0$ the following recursive equation holds: $X(k+1) =X(k) + W(k)$\n\t\t\\end{itemize}\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{block}{Graphical representation}\n\t\t\t\\begin{tikzpicture}\n\t\t\t\\node(X0){$X(0)$};\n\t\t\t\\node[above=1em of X0](W0){$W(0)$};\n\t\t\t\\node[right=1em of X0](sum1){$+$};\n\t\t\t\\node[right=1em of sum1](X1){$X(1)$};\n\t\t\t\\node[above=1.2em of X1](W1){$W(1)$};\n\t\t\t\\node[right=1em of X1](sum2){$+$};\n\t\t\t\\node[right=1em of sum2](X3){$\\cdots$};\n\t\t\t\\draw[->] (W0) to (sum1);\n\t\t\t\\draw[->] (X0) to (sum1);\n\t\t\t\\draw[->] (sum1) to (X1);\n\t\t\t\\draw[->] (W1) to (sum2);\n\t\t\t\\draw[->] (X1) to (sum2);\n\t\t\t\\draw[->] (sum2) to (X3);\n\t\t\t\\end{tikzpicture}\t\t\n\t\t\\end{block}\n\t\\end{columns}\n\t\n\t\\vspace*{0.5em}\n\t\n\t\\onslide<2-> What is the distribution of $X(1)$ ?\n\t\\begin{itemize}\\onslide<3->\n\t\t\\item $X(1)$ has a triangular distribution\n\t\t\\item Mean $\\mu_1=\\mu_0+\\mu_{w,0}$, variance $\\sigma_1^2 = \\sigma_0^2 + \\sigma_{w,0}^2\\;$\\footnote{\\href{http://eli.thegreenplace.net/2009/01/07/variance-of-the-sum-of-independent-variables}{See also here}}\n\t\\end{itemize}\n\t\n\t\\vspace*{0.5em}\n\t\\onslide<4-> What is the distribution of $X(k)$ ?\n\t\\begin{itemize}\\onslide<4->\n\t\t\\item The distribution of $X(k)$ depends on the distribution of $X(k-1)$ and of $W(k-1)$\n\t\t\\item Mean $\\mu_k=\\mu_0+\\sum_{j=0}^{k-1}\\mu_{w,j}$, variance $\\sigma_k^2=\\sigma_0^2 + \\sum_{j=0}^{k-1}\\sigma_{w,j}^2$\n\t\t\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Gaussian distributions and non linear systems}\n\tAssume \n\t\\begin{columns}\n\t\t\\column{0.6\\textwidth}\n\t\t\\begin{itemize}\n\t\t\t\\item $X(0)$ is normally distributed $X(0)\\sim\\mathcal{N}(0, 1)$\n\t\t\t\\item $W(k)$ is normally distributed $W(k)\\sim\\mathcal{N}(0, 1)$\n\t\t\t\\item $X(0)$ and $W(k)$ are independent for all $k$\n\t\t\t\\item for $k\\geq0$ we have $X(k+1) =X^2(k) + W(k)$\n\t\t\\end{itemize}\t\n\t\t\\column{0.4\\textwidth}\n\t\t\\begin{block}{Graphical representation}\n\t\t\t\\begin{tikzpicture}\n\t\t\t\\node(X0){$X(0)$};\n\t\t\t\\node[above=1em of X0](W0){$W(0)$};\n\t\t\t\\node[right=1em of X0](sum1){$+$};\n\t\t\t\\node[right=1em of sum1](X1){$X(1)$};\n\t\t\t\\node[above=1.2em of X1](W1){$W(1)$};\n\t\t\t\\node[right=1em of X1](sum2){$+$};\n\t\t\t\\node[right=1em of sum2](X3){$\\cdots$};\n\t\t\t\\draw[->] (W0) to (sum1);\n\t\t\t\\draw[->] (X0) to (sum1);\n\t\t\t\\draw[->] (sum1) to (X1);\n\t\t\t\\draw[->] (W1) to (sum2);\n\t\t\t\\draw[->] (X1) to (sum2);\n\t\t\t\\draw[->] (sum2) to (X3);\n\t\t\t\\end{tikzpicture}\t\t\n\t\t\\end{block}\n\t\\end{columns}\n\t\n\t\\vspace*{0.5em}\n\t\n\t\\onslide<2-> What is the distribution of $X(1)$ ?\n\t\\begin{itemize}\\onslide<3->\n\t\t\\item $X(1)$ is not normally distributed.\n\t\t\\item Mean $\\mu_1=E[X(0)^2]+\\mu_{w,0}$\n\t\t\\item Variance $\\sigma_1^2=var(X(0))+\\sigma_{w,0}^2$\n\t\\end{itemize}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Few remarks}\n\t\\begin{itemize}\n\t\t\\setlength\\itemsep{2em}\n\t\t\\item Mean of the sum is always equal to the sum of the means (linear operator)\n\t\t\\item If two random variables are independent, then the variance of the sum is equal to the sum of the variances \n\t\t%\\item Variables $X(k)$ are normally distributed for all $k\\geq0$ \\emph{only} in the case of linear systems and if the variables $w(k)$ are normally distributed\n\t\t\\item The knowledge of mean and variance rarely completely characterize the distribution of a random variable\n\t\\end{itemize}  \n\\end{frame}\n\n\\section{Marginal and conditional density functions}\n\\separatorslide\n\\begin{frame}\n\t\\frametitle{Marginal and conditional density functions}\n\tAssume $X$ and $Y$ are two random variables taking values in the interval $[0, 1]$\\vspace{0.5em}\\\\\n\tand $f_{X,Y}(x,y)$ is the joint probability density function of $X$ and $Y$\\vspace{0.5em}\n\t%The following probabilities can be computed from the joint distribution of $X$ and $Y$\n \t\\begin{itemize}%\\setlength\\itemsep{0.5em}\n \t\t\\item <1-> Marginal probability density functions are given by\n \t\t$$f_{X}(x)=\\int_0^1f_{X,Y}(x,z) dz\\;, \\qquad f_{Y}(y)=\\int_0^1f_{X,Y}(z,y) dz$$\n \t\t\n \t\t%Probability of $X$ taking value $x$ independently of the value taken by $Y$ \n \t\t%\\item Marginal probability density function\n \t\t%Probability of $X$ taking value $x$ independently of the value taken by $Y$ \n \t\t%\\item <1-> %Probability of $Y$ taking value $y$ independently of the value taken by $X$ \n \t\t%$P(Y\\leq y)=\\int_0^y\\int_0^1 P(X=z, Y=y) dz$ (Marginal distribution)\n \t\t%\\item <2-> %Probability of $Y$ taking value $y$ once we know that $X$ has value $x$\n \t\t% $P(Y\\leq y|X=x)=\\int_0^y \\frac{P(X=x, Y=y)}{P(X=x)}$ (Conditional distribution)\n \t\t%\\item <2->Probability of $X$ taking value $x$ once we know that $Y$ has value $y$ %$P(X=x|Y=y)=\\frac{P(X=x, Y=y)}{P(Y=y)}$ (Conditional distribution)\n \t\t\n \t\t\\item <2-> Conditional probability density function: $f_{X|Y}(x;y)=\\frac{f_{X,Y}(x,y)}{f_{Y}(y)},$ if $f_Y(x)>0$ \n \t\t\\item <3-> Conditional mean and variance of $X$ given $Y$ \n\t\t$$E[X|Y=y]\\!=\\int_0^1\\!\\! zf_{X|Y}(z;y)dz,\\quad var(X|Y=y)\\!=\\int_0^1 \\!\\!(z-E[X|Y=y])^2f_{X|Y}(z;y)dz$$\n \t\\end{itemize}\n \t\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{Conditional distribution and expected conditional risk}\n\tConsider the case of estimating the value of a variable $X$ from its measurement $Y$\n\t\\begin{itemize}\n\t\t\\item For example $Y=X+W$, where $W$ is random noise independent of $X$\n\t\t\\item The conditional distribution of $X|Y$ provides information about the probability of different values of $X$ given that $Y=y$\n\t\t\\item <3-> For selecting a best value, we need a cost function, e.g., the \\emph{expected conditional risk}\n\t\t$$R(t,y)=E[c(t-X)|Y=y]=\\int_{\\mathbb{R}}c(t-z)f_{X|Y}(z;y)dz$$\n\t\\end{itemize}\n\t\n\t\\onslide <3->If\n\t\\begin{itemize}\n\t\t\\item $c(t-x)$ is symmetric, e.g., $c(z-x)=(z-x)^2$ and\n\t\t\\item the conditional density function $f_{X|Y}(z;y)$ is symmetric around $E(X|Y=y)$,\n\t\\end{itemize}\n\tthen\n\t\\begin{itemize}\n\t\t\\item the minimum of $R(t,y)$ does not depends on the specific cost function $c(t-X)$\n\t\t\\item \\emph{the minimum of $R(t,y)$ is given by $E[X|Y=y]$}\n\t\\end{itemize}\n%\\onslide<2->\n%\\takeaway{Under these assumption, the best estimate of $X$ given $Y=y$ is $E[X|Y=y]$}\n\\onslide<2>\\takeaway{\\bf{How could we select a best \\emph{value} for $X$?}}\n\\end{frame}\n\n\\begin{frame}\n\t\\frametitle{The Maximum a posteriori estimator}\n\tAnother approach for selecting a best value for the estimation of $X$ given $Y=y$ could be to take the maximum of $f_{X|Y}(z;y)$ \\vspace{2em}\n\t\\begin{itemize}\n\t\t\\item We can define $$\\hat{x}(y)=\\argmax_{z\\in\\mathbb{R}}f_{X|Y}(z;y)$$\n\t\t\\item This estimator is called \\emph{Maximum a posteriori} (MAP) \n\t\\end{itemize}\n\t\\begin{itemize}\n\t\t\\item For unimodal and symmetric distributions, e.g., Gaussian distribution, then MAP estimator and the expected conditional value estimator coincide\n\t\\end{itemize}\n\\takeaway{In general, MAP and the expected conditional value are different}\t \n\\end{frame}\n\n%\\begin{frame}\n%\t\\frametitle{Some properties of the conditional expectation}\n%\tAssumptions:\n%\t\\begin{itemize}\n%\t\t\\item $c(z-x)$ is symmetric, e.g., $c(z-x)=(z-x)^2$\n%\t\t\\item the conditional distribution of $(X|Y=y)$ is symmetric around $E(X|Y=y)$\n%\t\\end{itemize}\\vspace{1em}\n%\tthen\n%\t\\begin{itemize}\n%\t\t\\item the minimum of $R(z,y)$ does not depends on the specific cost function $c(z-X)$\n%\t\t\\item the minimum of $R(z,y)$ is given by $E[X|Y=y]$\n%\t\\end{itemize}\\vspace{1.5 em}\n%\t\t\n%\t\\takeaway{Under these assumptions mean and mode of the conditional distribution coincide}\n%\\end{frame}", "meta": {"hexsha": "7ec56f2a43921d3cf02f50296f06beb631f8f54f", "size": 15673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "slides/random_variables.tex", "max_stars_repo_name": "lparolin/state_estimation", "max_stars_repo_head_hexsha": "68ac7ad2c4dabc568e47cb07102703527aee3386", "max_stars_repo_licenses": ["MIT"], "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/random_variables.tex", "max_issues_repo_name": "lparolin/state_estimation", "max_issues_repo_head_hexsha": "68ac7ad2c4dabc568e47cb07102703527aee3386", "max_issues_repo_licenses": ["MIT"], "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/random_variables.tex", "max_forks_repo_name": "lparolin/state_estimation", "max_forks_repo_head_hexsha": "68ac7ad2c4dabc568e47cb07102703527aee3386", "max_forks_repo_licenses": ["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.018766756, "max_line_length": 338, "alphanum_fraction": 0.6463344605, "num_tokens": 6121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970654616711, "lm_q2_score": 0.8947894604912848, "lm_q1q2_score": 0.7881279310067556}}
{"text": "\n\\subsection{Ordinary differential equations}\n\nAn ordinary differential equation is one with only one independent variable. For example:\n\n\\(\\dfrac{dy}{dx}=f(x)\\)\n\nThe order of a differential equation is the number of differentials of \\(y\\) included. For example one with the second derivative of \\(y\\) is of order \\(2\\).\n\nOrdinary equations can can either implicit or explicit. An explicit function shows the highest order derivative as a function of other terms.\n\nAn implicit function is one which is not explicit.\n\nA linear ODE is an explicit ODE where the derivative terms of \\(y\\) do not multiply together, that is, in the form:\n\n\\(y^{(n)}=\\sum_ia_i(x)y^{(i)}+r(x)\\)\n\n\\subsubsection{First-order ODEs}\n\nWe have an evolution:\n\n\\(\\dfrac{dy}{dt}=f(t,y)\\)\n\nAnd a starting condition:\n\n\\(y_0=f(t_0)\\)\n\nWe now discuss various ways to solve these.\n\n", "meta": {"hexsha": "801930fffe17145f88fffc379e8bad3d1b1d2a98", "size": 844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/ODE/02-01-diffEqODE.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/ODE/02-01-diffEqODE.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/ODE/02-01-diffEqODE.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.1333333333, "max_line_length": 157, "alphanum_fraction": 0.7369668246, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545333502202, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7880520506722508}}
{"text": "\n\\section{Generalized Linear Models}\nWe relax the assumption that $\\mu$ is linear. Instead, we assume that g $\\circ \\mu$ is linear, for some function $g$:\\\\\n\n$g(\\mu (\\mathbf x)) = \\mathbf x^ T \\beta$\n\nThe function $g$ is assumed to be known, and is referred to as the link function. It maps the domain of the dependent variable to the entire real Line.\n\nit has to be strictly increasing,\n\nit has to be continuously differentiable and\n\nits range is all of $\\mathbb{R}$\n\n\n\\subsection{The Exponential Family}\n\nA family of distribution $\\, \\{ \\mathbf{P}_{{\\boldsymbol \\theta }}: {\\boldsymbol \\theta }\\in \\Theta \\} ,\\,$  where the parameter space $\\Theta \\subset \\mathbb {R}^ k\\,$ is -$k$ dimensional, is called a $k$-parameter exponential family on $\\mathbb{R}^1$ if the pmf or pdf $\\, f_{\\boldsymbol \\theta }:\\mathbb {R}^ q\\to \\mathbb {R}\\,$ of $\\, \\mathbf{P}_{{\\boldsymbol \\theta }}\\,$ can be written in the form:\\\\\n\n$\\displaystyle  \\displaystyle f_{\\boldsymbol \\theta }(\\mathbf{y})=h(\\mathbf{y})\\, \\exp \\left({\\boldsymbol \\eta }({\\boldsymbol \\theta })\\cdot \\mathbf{T}(\\mathbf{y})-B({\\boldsymbol \\theta })\\right)\\qquad \\text {where } \\\\ \\begin{cases}  {\\boldsymbol \\eta }({\\boldsymbol \\theta })=\\begin{pmatrix} \\eta _1({\\boldsymbol \\theta })\\\\ \\vdots \\\\ \\eta _ k({\\boldsymbol \\theta })\\end{pmatrix}& :\\mathbb {R}^ k\\to \\mathbb {R}^ k\\\\ \\mathbf{T}(\\mathbf{y})=\\begin{pmatrix} T_1(\\mathbf{y})\\\\ \\vdots \\\\ T_ k(\\mathbf{y})\\end{pmatrix}& :\\mathbb {R}^ q\\to \\mathbb {R}^ k\\\\ B({\\boldsymbol \\theta })& :\\mathbb {R}^ k\\to \\mathbb {R}\\\\ h(\\mathbf{y})& :\\mathbb {R}^ q\\to \\mathbb {R}.\\\\ \\end{cases}$\\\\\n\n\nif $k=1$ it reduces to:\\\\\n\n$\\displaystyle  \\displaystyle f_\\theta (y)=h(y)\\, \\exp \\left(\\eta (\\theta ) T(y)-B(\\theta )\\right)$\n\n", "meta": {"hexsha": "ce1804f3a2cf106cb915ad0fbe2320b962ccb445", "size": 1721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Generalized_Linear_Models.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/Generalized_Linear_Models.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/Generalized_Linear_Models.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": 63.7407407407, "max_line_length": 675, "alphanum_fraction": 0.6507844277, "num_tokens": 600, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897558991953, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7880242732136427}}
{"text": "\\section{The CLs upper limit}\n\\label{sec:CLs}\n\nFor a signal hypothesized value $\\mu$, one can compute the probability that this hypothesis (called S+B hypothesis) gives a \\textbf{greater} test statistic value than the observed one $q_{obs}$ as:\n\\begin{equation}\n    p_{s+b} = \\int_{q_{obs}}^{\\infty} f(q_{\\mu}|\\mu) d q_{\\mu}\n\\end{equation}\nIn the meantime, the probability that the background-only hypothesis gives a \\textbf{smaller} test statistic than observed data can also be calculated as:\n\\begin{equation}\n    1 - p_{b} = \\int_{-\\infty}^{q_{obs}} f(q_{\\mu}|0) d q_{\\mu}\n\\end{equation}\nThen we define the CLs~\\cite{Read_2002} of a hypothesized value $\\mu$ as:\n\\begin{equation}\n    CLs = \\frac{p_{s+b}}{1-p_{b}}\n\\end{equation}\nFor purpose of excluding a signal hypothesis, a threshold CLs of 0.05 is often used.\nFor this reason, usually under the circumstance that no significant derivation between data and background-only hypothesis is found,\none would like to find the value of hypothesized signal strength $\\mu$ by requiring its $CLs = 0.05$ (called 95\\% CLs upper limit) for exclusion. \n\nThe sensitivity of an experiment to exclude a new signal process is quantified by \\textit{median upper limit}~\\cite{Bellos:2725027},\nwhich is obtained using ``Asimov dataset\".\nThe Asimov dataset is defined such that when one uses it to evaluate the estimators for all parameters, one obtains the true parameter values.\nMoreover, it is useful to use Asimov dataset to compute how much the sensitivity is expected to vary, given the expected fluctuations in the data.\nThe $\\hat{\\mu}$ is assumed to follow a Gaussian distribution with a mean value of $\\mu '$ and the standard deviation of $\\sigma$.\nFirst of all, the test statistic from profile likelihood ratio can be approximated as~\\cite{Cowan:2010js}:\n\\begin{equation}\n\t-2 ln \\lambda(\\mu) = \\frac{(\\mu - \\hat{\\mu})^2}{\\sigma^2} + \\mathcal{O}(1/\\sqrt{N})\n\\end{equation}\nGiven that the Asimov dataset corresponding to a signal strength $\\mu'$, one finds:\n\\begin{equation}\n\t-2 ln \\lambda_{A}(\\mu) \\approx \\frac{(\\mu - \\mu')^2}{\\sigma^2} = q_{\\mu,A}\n\\end{equation}\nwhere $q_{\\mu,A} = -2ln\\lambda_{A}(\\mu)$ is the observed test statistic of Asimov dataset.\nThen the standard derivation can be computed as:\n\\begin{equation}\n\t\\sigma_A^2 = \\frac{(\\mu - \\hat{\\mu})^2}{q_{\\mu,A}}\n\\end{equation}\nIn a special situation where one wants to find the median exclusion significance for the hypothesis $\\mu$ assuming that there is no signal ($\\mu' = 0$),\none gets:\n\\begin{equation}\n        \\sigma_A^2 = \\frac{\\hat{\\mu}^2}{q_{0,A}}\n\\end{equation}\n", "meta": {"hexsha": "37df6fd5dd36897c88f1c7a3b8ca09c0ab0102cc", "size": 2577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/Statistic/limit.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/Statistic/limit.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/Statistic/limit.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": 59.9302325581, "max_line_length": 197, "alphanum_fraction": 0.7283663174, "num_tokens": 759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897442783527, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7880242730135121}}
{"text": "\\subsection{An iterative feacture extraction scheme}\nOne key idea in this paper is that we consider different iterative\n\tprocesses to approximately solve \\eqref{Auf} and relate them to\n\tmany existing popular CNN models. Here, let us assume that \n\tthe feature-data mapping \\eqref{Auf}  is given as a linear form \\eqref{linearA}.\n\tWe next propose some iterative schemes to solve \\eqref{Auf}\n\tfor an appropriately chosen $u^0$.\n\t\\begin{itemize}\n\t\t\\item Residual correction method, \n\t\t\\begin{equation}\\label{eq:smoothB}\n\t\tu^{i} = u^{i-1} + B^{i}(f- A(u^{i-1})), \\quad i=1:\\nu.\n\t\t\\end{equation}\n\t\tHere $B^i$ can be chosen as linear like $B^{i}(f) = \\eta^i \\ast f$ or nonlinear\n\t\tlike \\eqref{extractor}. The reason why $B^{i}$ is taken\n\t\tthe nonlinear form as in \\eqref{extractor} will be discussed later based on our\n\t\tmain discovery about the relationship\n\t\tbetween MgNet and iResNet as discussed in \\S~\\ref{sec:CNNs} and \\S~\\ref{sec:relation}. \n\t\tWe refer to \\cite{xu1992iterative}\n\t\tfor more discussion on iterative schemes in the form of \\eqref{eq:smoothB}.\n\t\t\\item Chebyshev semi-iterative method, \n\t\t\\begin{equation}\\label{eq:chebysev-semi}\n\t\tu^{i} = \\omega^i\\left(u^{i-1} + B^{i}\\left(f- A(u^{i-1})\\right)\\right)+ (1- \\omega^i) u^{i-2},\\quad i=1:\\nu.\n\t\t\\end{equation}\n\t\tThe above scheme can be obtained from the above semi-iterative form\n\t\tby applying the Chebyshev polynomial theory \\cite{hackbusch1994iterative, golub2012matrix}. \n\t\tSimilar to the previous case, considering the iterative form of the residual $r^j = f - A(u^{j})$,\n\t\t\\eqref{eq:chebysev-semi} implies that\n\t\t\\begin{equation}\n\t\tr^{i} = \\omega^i r^{i-1} + (1-\\omega^i)r^{i-2} - AB^i r^{i-1}.\n\t\t\\end{equation}\n\t\tThis scheme corresponds to the LM-ResNet in \\cite{lu2018beyond} \n\t\twhich was obtained as a linear multi-step scheme for some underlying ODEs.\n\t\\end{itemize}", "meta": {"hexsha": "e6eb9e7c4b15bc7be730ccf1086af6a122a11d4f", "size": 1835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_iterativescheme.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_iterativescheme.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_iterativescheme.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.6060606061, "max_line_length": 110, "alphanum_fraction": 0.7133514986, "num_tokens": 624, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8723473763375643, "lm_q1q2_score": 0.7879863267370064}}
{"text": "\\section*{Two-state System}\n\n\\begin{center}\n  \\begin{tabular}{>{$\\textstyle}c<{$}*{2}{>{$\\textstyle}r<{$}}}\n    \\toprule %\n    \\multicolumn{1}{c}{$\\mathcal{O}$} %\n    &\\multicolumn{1}{c}{$\\lambda$} %\n    &\\multicolumn{1}{c}{$\\ket{\\psi^{\\text{(eigen)}}}$} %\n    \\\\ \\midrule %\n    \\arrayrulecolor{lightgray} %\n    \\sigma_x \\equiv X %\n    &\\num{+1} %\n    & \\frac{1}{\\sqrt{2}}\\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix} %\n    \\\\%\n    \\begin{pmatrix} 0 & 1\\\\ 1 & 0\\end{pmatrix} %\n      & \\num{-1} %\n      & \\frac{1}{\\sqrt{2}}\\begin{pmatrix} -1 \\\\ 1 \\end{pmatrix} %\n      \\\\ \\hline %\n      \\sigma_y\\equiv Y %\n      & \\num{+1} %\n      & \\frac{1}{\\sqrt{2}}\\begin{pmatrix} -1 \\\\ -i \\end{pmatrix} %\n      \\\\ %\n      \\begin{pmatrix} 0 & -i\\\\ i & 0\\end{pmatrix} %\n        & \\num{-1} %\n        & \\frac{1}{\\sqrt{2}}\\begin{pmatrix} -1 \\\\ i \\end{pmatrix} %\n        \\\\ \\hline %\n    \\sigma_z\\equiv Z %\n    & \\num{+1} %\n    & \\begin{pmatrix} 1 \\\\ 0 \\end{pmatrix} %\n    \\\\ %\n    \\begin{pmatrix} 1 & 0\\\\ 0 & -1 \\end{pmatrix} %\n        & \\num{-1} %\n    & \\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix} %\n    \\\\\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\n\\begin{align*}\n\\ket{\\psi} &= \\cos(\\theta/2)\\ket{0} + e^{i\\phi}\\sin(\\theta/2)\\ket{1} %\n\\\\ %\n(x, y, z) &= (\\sin\\theta \\cos\\phi, \\sin\\theta \\sin\\phi, \\cos\\theta)\n\\end{align*}\n\n\\begin{center}\n  \\begin{tabular}{>{$\\textstyle}c<{$}*{3}{>{$\\textstyle}r<{$}}}\n    \\toprule %\n    \\multicolumn{1}{c}{$\\mathcal{O}$} %\n    &\\multicolumn{1}{c}{$\\lambda$} %\n    &\\multicolumn{1}{c}{$\\ket{\\psi^{\\text{(eigen)}}}$} %\n    &\\multicolumn{1}{c}{$(\\theta, \\phi)$}%\n    \\\\ \\midrule %\n    \\arrayrulecolor{lightgray} %\n    \\sigma_x \\equiv X %\n    &\\num{+1} %\n    & \\frac{1}{\\sqrt{2}} \\left(\\ket{0} + \\ket{1} \\right) %\n    & (\\frac{\\pi}{2},0) %\n    \\\\%\n    \\dyad{0}{1} + \\dyad{1}{0} %\n    & \\num{-1} %\n    & \\frac{1}{\\sqrt{2}} \\left(\\ket{0} - \\ket{1} \\right) %\n    & (\\frac{\\pi}{2},-\\pi) %\n    \\\\ \\hline %\n    \n    \\sigma_y\\equiv Y %\n    & \\num{+1} %\n    & \\frac{1}{\\sqrt{2}} \\left( \\ket{0} + i \\ket{1} \\right) %\n    & (\\frac{\\pi}{2},\\frac{\\pi}{2}) %\n    \\\\ %\n    -i\\left( \\dyad{0}{1} - \\dyad{1}{0} \\right) %\n      & \\num{-1} %\n      & \\frac{1}{\\sqrt{2}} \\left(\\ket{0} - i \\ket{1} \\right) %\n    & (\\frac{\\pi}{2},-\\frac{\\pi}{2}) %\n      \\\\ \\hline %\n      \n    \\sigma_z\\equiv Z %\n    & \\num{+1} %\n    & \\ket{0} %\n    & (0,0) %\n    \\\\ %\n    \\dyad{0}{0} - \\dyad{1}{1} %\n    & \\num{-1} %\n    & \\ket{1} %\n    & (\\pi, 0)\n    \\\\\n    \\arrayrulecolor{black} %\n\\bottomrule\n\\end{tabular}\n\\end{center}\n\n% Matches the work in QIS-Exercises\n%\\begin{center}\n%  \\begin{tabular}{>{$\\textstyle}c<{$}*{3}{>{$\\textstyle}r<{$}}}\n%    \\hline %\n%    \\mathcal{O} & \\lambda & \\psi^{\\text{(eigen)}} & (\\theta, \\phi)%\n%    \\\\ \\hline %\n%    \\sigma_x \\equiv X %\n%    &\\num{+1} %\n%    & \\frac{1}{\\sqrt{2}} \\left( +\\ket{0} + \\ket{1} \\right) %\n%    & (\\frac{\\pi}{2},0) %\n%    \\\\%\n%    \\dyad{0}{1} + \\dyad{1}{0} %\n%    & \\num{-1} %\n%    & \\frac{1}{\\sqrt{2}} \\left( -\\ket{0} + \\ket{1} \\right) %\n%    & (\\frac{\\pi}{2},\\pi) %\n%    \\\\ \\hline %\n%    \n%    \\sigma_y\\equiv Y %\n%    & \\num{+1} %\n%    & \\frac{1}{\\sqrt{2}} \\left( -\\ket{0} - i \\ket{1} \\right) %\n%    & (\\frac{\\pi}{2},\\frac{\\pi}{2}) %\n%    \\\\ %\n%    -i\\left( \\dyad{0}{1} - \\dyad{1}{0} \\right) %\n%      & \\num{-1} %\n%      & \\frac{1}{\\sqrt{2}} \\left( -\\ket{0} + i \\ket{1} \\right) %\n%    & (\\frac{\\pi}{2},-\\frac{\\pi}{2}) %\n%      \\\\ \\hline %\n%      \n%    \\sigma_z\\equiv Z %\n%    & \\num{+1} %\n%    & \\ket{0} %\n%    & (0,0) %\n%    \\\\ %\n%    \\dyad{0}{0} - \\dyad{1}{1} %\n%    & \\num{-1} %\n%    & \\ket{1} %\n%    & (\\pi, 0)\n%    \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n\n\\subsection*{Commutators for Two-State System}\n", "meta": {"hexsha": "b081c9b4a4da75d0dbbd5a6ba26959332dfa63e9", "size": 3618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_TwoStateSystem.tex", "max_stars_repo_name": "tcburt/hodudodi", "max_stars_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_TwoStateSystem.tex", "max_issues_repo_name": "tcburt/hodudodi", "max_issues_repo_head_hexsha": "de0952ceaf00d97251dcec984d0099fcd0905867", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-01-18T22:55:02.000Z", "max_issues_repo_issues_event_max_datetime": "2020-01-18T23:01:00.000Z", "max_forks_repo_path": "CheatSheets/Series/Quantum-Information-Processing/units/unit_TwoStateSystem.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": 27.0, "max_line_length": 70, "alphanum_fraction": 0.4416804865, "num_tokens": 1608, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7879863214682129}}
{"text": "\\chapter{Stochastic Neural Networks}\nNeurons fire in a probabilistic manner. The activation function of a stochastic neuron is non-deterministic, but probabilistic. \n\n\\section{Boltzmann Machine}\nBoltzmann machine is a generalization of Hopfield network. Boltzmann-Gibbs distribution:\n$$P(1|u)=\\frac{1}{1+e^{-u/T}}$$\n\\begin{center}where T is the temperature of transitions \\end{center}\n\n\\section{Stochastic Recurrent Network}\nConsider transition from ($u_1$, $u_2$) to ($u_1'$, $u_2$). Number of state $N$ is 2.\n\\begin{equation*}\n\\begin{split}\nP(u_1\\ change\\ to\\ u_1') &= P(first\\ neuron\\ to\\ fire) \\times P(u_1' | u_1) \\\\\n&= \\frac{P(u_1' | u_1)}{N}\n\\end{split}\n\\end{equation*}\nIf $u_1$' is 1 and $u_1$ is 0, then:\n$$P(u_1\\ change\\ to\\ u_1') = \\frac{P(1| u_1)}{N}$$\nAnd the numerator can be found using Boltzmann equation and u is 0\n\n\\section{Network Entropy}\nEntrophy gives a measure of randomness of the network at a given state.\n$$H_i=-\\sum{p(i,j)log_e p(i,j)}$$\n\n\\section{State-Transition Matrix}\n$$\nS = \n\\begin{bmatrix}\np(0,0) & p(1,0) & \\cdots & p(m-1, 0) \\\\\np(0,1) & p(1,1) & \\cdots & p(m-1, 1) \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\np(0,m-1) & p(1,m-1) & \\cdots & p(m-1,m-1)\n\\end{bmatrix}\n$$\nColumns: current states \\\\\nRows: next states \\\\\n$p(i|j)$: probability of transition from state i to state j\n\n\\section{Markov Chain}\n$$\\boldsymbol{X}(0) \\rightarrow \\boldsymbol{X}(1) \\rightarrow \\ldots \\ \\boldsymbol{X}(k)$$\n$\\boldsymbol{X}(k)$ is the vector of state probabilities at time $k$ \\\\ \n$X_0(k)$ is probability of the network being at state $S_i$ at time $k$\n\n$$\\boldsymbol{X}(k+1) = \\boldsymbol{S}\\boldsymbol{X}(k)$$\n\n$$\\boldsymbol{X}(k) = \\boldsymbol{S}^{k} \\boldsymbol{X}(0)$$\n\n\\section{Simulated Annealing}\nSimulated Annealing provides a \\emph{scheme} that allows a network to jump out of a local minima towards the \\emph{global minima}. Simulated Annealing begins at high temperature to have sufficient randomness for the neurons to jump out of local minima and gradually lowers the temperature to facilitate settling down at global minima.\n", "meta": {"hexsha": "ed308a958a7fbfd95eed94e861d604e4accfca43", "size": 2055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter8.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": "chapter8.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": "chapter8.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": 41.1, "max_line_length": 334, "alphanum_fraction": 0.698296837, "num_tokens": 710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7879636563699066}}
{"text": "\\section{Exact couples}\nLet us begin with a conceptual discussion of exact couples. As a special case,\nwe will recover the construction of the spectral sequence associated to a\nfiltered chain complex (Theorem-Definition \\ref{filtered-sseq}).\n\\begin{definition}\n    An \\emph{exact couple} is a diagram of (possilby (bi)graded) abelian\n    groups\n    \\begin{equation*}\n\t\\xymatrix{\n\t    A\\ar[rr]^i & & A\\ar[dl]_j\\\\\n\t    & E\\ar[ul]_k & \n\t    }\n    \\end{equation*}\n    which is exact at each joint.\n\\end{definition}\nAs $jkjk = 0$, the map $E\\xar{jk} E$ is a differential, denoted $d$. An exact\ncouple determines a ``derived couple'':\n\\begin{equation}\\label{derived-couple}\n    \\xymatrix{\n\tA^\\prime\\ar[rr]^{i^\\prime = i|_{\\img i}} & &\n\tA^\\prime\\ar[dl]_{j^\\prime}\\\\\n\t& E^\\prime\\ar[ul]_{k^\\prime} & \n        }\n\\end{equation}\nwhere $A^\\prime = \\img(i)$ and $E^\\prime = H_\\ast(E,d)$. Iterating this\nprocedure, we get exact sequences \n\\begin{equation*}\n    \\xymatrix{\n\tA^r\\ar[rr]^{i_r} & & A^r\\ar[dl]_{j_r}\\\\\n\t& E^r\\ar[ul]_{k_r} & \n        }\n\\end{equation*}\nwhere the next exact couple is the derived couple of the preceding exact\ncouple.\n\nIt remains to define the maps in the above diagram. Define $j^\\prime(ia) = ja$.\n\\emph{A priori}, it is not clear that this well-defined. For one, we need $[ja]\n\\in E^\\prime$; for this, we must check that $dja = 0$, but $d=jk$, and $jkja =\n0$ so this follows. We also need to check that $j^\\prime$ is well-defined\nmodulo boundaries. To see this, suppose $ia = 0$. We then need to know that\n$ja$ is a boundary. But if $ia = 0$, then $a = ke$ for some $e$, so $ja = jke =\nde$, as desired.\n\nDefine $k^\\prime:H(E,d) \\to \\img i$ via $k^\\prime([e])\\mapsto ke$. As before,\nwe need to check that this is well-defined. For instance, we have to check that\n$ke\\in\\img i$. Since $de = 0$ and $d = jk$, we learn that $jke = 0$. Thus $ke$\nis killed by $j$, and therefore, by exactness, is in the image of $i$. We also\nneed to check that $k^\\prime$ is independent of the choice of representative of\nthe homology class. Say $e = de^\\prime$. Then $kd = kd e^\\prime = kjke^\\prime =\n0$.\n\\begin{exercise}\n    Check that these maps indeed make diagram \\eqref{derived-couple} into an\n    exact couple.\n\\end{exercise}\nIt follows that we obtain a spectral sequence, in the sense of\nTheorem-Definition \\ref{filtered-sseq}.\n\\begin{exercise}\\label{explicit-er}\n    By construction,\n    $$A^r = \\img(i^{r}|_{A}) = i^{r} A.$$\n    Show, by induction, that\n    $$E^r = \\frac{k^{-1}(i^{r}A)}{j(\\ker i^{r})}$$\n    and that\n    \\begin{equation*}\n\ti_r(a) = ia,\\ j_r(i^r a) = [ja],\\ k_r(e) = ke.\n    \\end{equation*}\n\\end{exercise}\nIntuitively: an element of $E^1$ will survive to $E^r$ if its image in $A^1$\ncan be pulled back under $i^{r-1}$. The differential $d^r$ is obtained by\nthe homology class of the pushforward of this preimage via $j$ to $E^1$.\n\\begin{remark}\\label{bigraded}\n    In general, the groups in consideration will be bigraded. It is clear by\n    construction that $\\deg(i') = \\deg(i)$, $\\deg(k') = \\deg(k)$, and $\\deg(j')\n    = \\deg(j)-\\deg(i)$. It follows by an easy inductive argument that\n    $$\\deg(d^r) = \\deg(j)+\\deg(k)-(r-1)\\deg(i).$$\n\\end{remark}\nThe canonical example of an exact couple is that of a filtered complex; the\nresulting spectral sequence is precisely the spectral sequence of\nTheorem-Definition \\ref{filtered-sseq}. If $C_\\ast$ is a filtered chain\ncomplex, we let $A_{s,t} = H_{s+t}(F_s C_\\ast)$, and $E^1_{s,t} = E_{s,t} =\nH_{s+t}(\\gr_s C_\\ast)$. The exact couple is precisely that which arises from\nthe long exact sequence in homology associated to the short exact sequence of\nchain complexes\n$$0\\to F_{s-1} C_\\ast\\to F_s C_\\ast \\to \\gr_s C_\\ast\\to 0.$$\nNote that in this case, the exact couple is one of bigraded groups, so Remark\n\\ref{bigraded} dictates the bidegrees of the differentials.\n\nWe will conclude this section with a brief discussion of the convergence of the\nspectral sequence constructed above.  Assume that $i:A\\to A$ satisfies the\nproperty that\n$$\\ker(i)\\cap\\bigcap i^r A = 0.$$\nLet $\\wt{A}$ be the colimit of the directed system\n$$A\\xar{i} A\\xar{i} A\\to\\cdots$$\nThere is a natural filtration on $\\wt{A}$. Let $I$ denote the image of the map\n$A\\to \\wt{A}$; the kernel of this map is $\\bigcup \\ker(i^r)$. The groups $i^r\nI$ give an exhaustive filtration of $\\wt{A}$, and the quotients $i^r I/i^{r+1}\nI$ are all isomorphic to $I/i I$ (since $i$ is an isomorphism on $\\wt{A}$).\nThen we have an isomorphism\n\\begin{equation}\\label{einfty}\n    E^\\infty \\simeq I/iI.\n\\end{equation}\nIndeed, we know from Exercise \\ref{explicit-er} that\n$$E^\\infty \\simeq \\frac{k^{-1}\\left(\\bigcap i^r A\\right)}{j\\left(\\bigcup \\ker\ni^{r}\\right)};$$\nby our assumption on $i$, this is\n$$\\frac{\\ker(k)}{j\\left(\\bigcup \\ker i^{r}\\right)} \\simeq\n\\frac{j(A)}{j\\left(\\bigcup \\ker i^r\\right)}.$$\nBut there is an isomorphism $A/iA\\to j(A)$ which clearly sends $iA + \\bigcup\n\\ker i^r$ to $j\\left(\\bigcup \\ker i^r\\right)$. By our discussion above,\n$A/\\bigcup \\ker i^r \\simeq I$, and $iA/\\bigcup \\ker i^r \\simeq iI$. Modding out\nby $iI$ on both sides, we get \\eqref{einfty}.\n\n%Our starting point is that you have a chain complex $F_\\ast C$.\n%We have a short exact sequence $0\\to F_{s-1} C\\to F_s C \\to \\gr_s C \\to 0$, giving a lexseq in homology:\n%$$\n%\\cdots\\to H_{s+t}(F_{s-1}) \\to H_{s+t}(F_s) \\to H_{s+t}(\\gr_s) \\to H_{s+t-1}(F_{s-1}) \\to \\cdots\n%$$\n%We let $A^1_{s,t} = H_{s+t}(F_{s})$ and $E^1_{s,t} = H_{s+t}(\\gr_s)$.\n%\\textbf{Note: }Weibel uses this notation for something else.\n%His $D$ is my $A$, but with different indexing.\n%\n%Anyway, our diagram can now be rewritten as:\n%$$\n%\\cdots\\to A^1_{s-1,t+1} \\xar{i} A^1_{s,t} \\xar{j} E^1_{s,t} \\xar{k} A_{s-1, t} \\to \\cdots\n%$$\n%Define:\n%$$\n%A^r_{s,t} := \\img(A^1_{s,t} \\xar{i^{r-1}} A^1_{s+r - 1, t-r + 1}) = A^1_{s,t}/\\ker(i^{r-1})\n%$$\n%One thing you can do is look at:\n%$$\n%\\cdots \\xar{i} \\to A_{s-1} \\xar{i} A_s \\xar{i} A_{s+1} \\xar{i} A_{s+2} \\xar{i} \\cdots\n%$$\n%We also have a surjection $\\img(i^{r-1}) \\to \\img(i^r)$ and an injection $i:\\img(i^r) \\to \\img(i^{r-1})$, giving a map $\\img(i^{r-1}) \\to \\img(i^{r-1})$, given by $i$.\n%There's another thing you can do: you also have a map $\\img(i^r) \\to \\img(i^{r-1}) \\to \\img(i^r)$, whose composite is $i$ itself.\n%Explicitly, we can write:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t& A^r_{s,t} \\ar@{->>}[dr]\\ar[rr]^i & & A^r_{s+1,t-1}\\ar@{->>}[dr] & \\\\\n%\tA^{r+1}_{s-1,t+1}\\ar@{>->}[ur]\\ar[rr]_i & & A^{r+1}_{s,t}\\ar@{>->}[ur]\\ar[rr]_i & & A^{r+1}_{s+1,t-1}\n%    }\n%\\end{equation*}\n%Great, so in our lexseq, we now have:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t\\cdots\\ar[r] & A^1_{s-1,t+1}\\ar@{->>}[d] \\ar[r]^i & A^1_{s,t} \\ar@{->>}[d] \\ar[r]^j & E^1_{s,t} \\ar[r]^k & A^1_{s-1,t}\\ar[r]^i & A^1_{s,t-1} \\ar[r] & \\cdots\\\\\n%\t& A^2_{s-1,t+1}\\ar@{->>}[d]\\ar[r]^i & A^2_{s,t}\\ar@{->>}[d] & & A^2_{s-2,t+1}\\ar[r]^i \\ar@{>->}[u] & A^2_{s-1,t}\\ar@{>->}[u] & \\\\\n%\t& A^3_{s-1,t+1}\\ar[r]^i\\ar@{->>}[d] & A^3_{s,t}\\ar@{->>}[d] & & A^3_{s-3,t+2}\\ar@{>->}[u]\\ar[r]^i & A^3_{s-2,t+1}\\ar@{>->}[u] &\\\\\n%\t& \\vdots & \\vdots & & \\vdots \\ar@{>->}[u] & \\vdots\\ar@{>->}[u] &\n%    }\n%\\end{equation*}\n%Recall that for a filtered complex, we really have a surjection:\n%$$\n%A^r_{s,t} = \\img(H_{s+t}(F_s) \\to H_{s+t}(F_{s+r-1}) \\to \\img(H_{s+t}(F_s) \\to H_{s+1}(C)) = F_s H_{s+t}(C)\n%$$\n%In particular, all the vertical surjections in our big diagram maps down surjectively to the filtration.\n%More precisely:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t\\cdots\\ar[r] & A^1_{s-1,t+1}\\ar@{->>}[d] \\ar[r]^i & A^1_{s,t} \\ar@{->>}[d] \\ar[r]^j & E^1_{s,t} \\ar[r]^k & A^1_{s-1,t}\\ar[r]^i & A^1_{s,t-1} \\ar[r] & \\cdots\\\\\n%\t& A^2_{s-1,t+1}\\ar@{->>}[d]\\ar[r]^i & A^2_{s,t}\\ar@{->>}[d] & & A^2_{s-2,t+1}\\ar[r]^i \\ar@{>->}[u] & A^2_{s-1,t}\\ar@{>->}[u] & \\\\\n%\t& A^3_{s-1,t+1}\\ar[r]^i\\ar@{->>}[d] & A^3_{s,t}\\ar@{->>}[d] & & A^3_{s-3,t+2}\\ar@{>->}[u]\\ar[r]^i & A^3_{s-2,t+1}\\ar@{>->}[u] &\\\\\n%\t& \\vdots\\ar@{->>}[d] & \\vdots\\ar@{->>}[d] & & \\vdots \\ar@{>->}[u] & \\vdots\\ar@{>->}[u] &\\\\\n%\t0\\ar[r] & F_{s-1} H_{s+t}(C) \\ar[r]^i & F_s H_{s+t}(C) \\ar[r] & \\gr_s H_{s+t}(C)\\ar[r] & 0 & & &\n%    }\n%\\end{equation*}\n%Note that if $F_\\ast C$ is exhaustive, then this filtration on homology is exhaustive, and, well, what it says is that $F_s H_{s+t}(C) = \\colim A^r_{s,t}$.\n%Also, if $F_\\ast C$ is bounded below ($F_{-1}(C) = 0$), then $A^1_{s,t} = 0$ for $s\\leq -1$.\n%Eventually, the groups in the vertical injections will be $0$, so that's good.\n%So, see, all I need to do now is fill in the missing column beneath $E^1_{s,t}$.\n%In particular:\n%\\begin{equation*}\n%    \\xymatrix{\n%\t\\cdots\\ar[r] & A^1_{s-1,t+1}\\ar@{->>}[d] \\ar[r]^i & A^1_{s,t} \\ar@{->>}[d] \\ar[r]^j & E^1_{s,t} \\ar[r]^k & A^1_{s-1,t}\\ar[r]^i & A^1_{s,t-1} \\ar[r] & \\cdots\\\\\n%\t& A^2_{s-1,t+1}\\ar@{->>}[d]\\ar[r]^i & A^2_{s,t}\\ar@{->>}[d]\\ar[r] & E^2_{s,t}\\ar[r] & A^2_{s-2,t+1}\\ar[r]^i \\ar@{>->}[u] & A^2_{s-1,t}\\ar@{>->}[u] & \\\\\n%\t& A^3_{s-1,t+1}\\ar[r]^i\\ar@{->>}[d] & A^3_{s,t}\\ar@{->>}[d] \\ar[r] & E^3_{s,t}\\ar[r] & A^3_{s-3,t+2}\\ar@{>->}[u]\\ar[r]^i & A^3_{s-2,t+1}\\ar@{>->}[u] &\\\\\n%\t& \\vdots\\ar@{->>}[d] & \\vdots\\ar@{->>}[d] & \\vdots & \\vdots \\ar@{>->}[u] & \\vdots\\ar@{>->}[u] &\\\\\n%\t0\\ar[r] & F_{s-1} H_{s+t}(C) \\ar[r]^i & F_s H_{s+t}(C) \\ar[r] & \\gr_s H_{s+t}(C)\\ar[r] & 0 & 0 & 0 &\n%    }\n%\\end{equation*}\n%We want to construct in the $E^r$ groups.\n%One way to do this is by exact couples, which is the easiest approach.\n%This is what I'll do.\n%\n%On Wednesday, we'll do examples.\n%Today was the guts, and the applications will come next week.\n", "meta": {"hexsha": "df6c7648838c0d8dc88c72956effac45cc001cb6", "size": 9469, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-62-exact-couples.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-62-exact-couples.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-62-exact-couples.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 50.9086021505, "max_line_length": 168, "alphanum_fraction": 0.5978456014, "num_tokens": 3993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8962513786759491, "lm_q1q2_score": 0.7879365052768361}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following linear transformations $T:\\C^2\\to\\C^2$ is unitary?\n  \\begin{enumerate}\n  \\item $T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{c} x \\\\ iy \\end{mymatrix}$.\n  \\item $T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{c} iy \\\\ -ix \\end{mymatrix}$.\n  \\item $\\def\\arraystretch{1.4}\n    T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{c}\n      x + iy \\\\\n      ix + y \\\\\n    \\end{mymatrix}$.\n  \\item $\\def\\arraystretch{1.3}\n    T\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{c}\n      \\frac{1}{\\sqrt{2}} x + \\frac{i}{\\sqrt{2}} y \\\\\n      \\frac{1}{\\sqrt{2}} x - \\frac{i}{\\sqrt{2}} y \\\\\n    \\end{mymatrix}$.\n  \\end{enumerate}\n  \\begin{sol}\n    (a) Yes. (b) Yes. (c) No. (d) Yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine which of the following matrices are unitary.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      0 & i \\\\\n      i & 0 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\frac{1}{5}\n    \\begin{mymatrix}{cc}\n      4 & 3i \\\\\n      3 & 4i \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\frac{1}{\\sqrt{5}}\n    \\begin{mymatrix}{cc}\n      1 & 2i \\\\\n      2i & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    (a) Yes. (b) No. (c) Yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine which of the following matrices are unitary.\n  \\begin{equation*}\n    A = \\frac{1}{2}\n    \\begin{mymatrix}{ccc}\n      1 & i & 0 \\\\\n      0 & 1 & i \\\\\n      i & 0 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\frac{1}{3}\n    \\begin{mymatrix}{ccc}\n      1   & 2  & 2i \\\\\n      -2i & 2i & 1  \\\\\n      2i  & i  & 2  \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\frac{1}{2}\n    \\begin{mymatrix}{cccc}\n      1 &  1 &  1 &  1 \\\\\n      1 &  i & -1 & -i \\\\\n      1 & -1 &  1 & -1 \\\\\n      1 & -i & -1 &  i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    (a) No. (b) Yes. (c) Yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Assume $A$ and $B$ are unitary $3\\times 3$-matrices. Then which of\n  the following matrices are unitary?\n  \\begin{equation*}\n    (a)~ AB\\quad\n    (b)~ A+B\\quad\n    (c)~ iA\\quad\n    (d)~ -A\\quad\n    (e)~ 2A\\quad\n    (f)~ B^{-1}\\quad\n    (g)~ A^T\\quad\n    (h)~ A^{\\adjoint}\\quad\n    (i)~ A^2\\quad\n    (j)~ ABA^{-1}\n  \\end{equation*}\n  \\begin{sol}\n    All except (b) and (e) are unitary.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Assume $A$ and $B$ are $3\\times 3$-matrices, and assume $A$ is\n  unitary and $B$ is invertible. Then which of the following matrices\n  are unitary?\n  \\begin{equation*}\n    (a)~ AB\\quad\n    (b)~ A+B\\quad\n    (f)~ BAB^{-1}\\quad\n    (g)~ ABA^{-1}\\quad\n    (h)~ BB^{\\adjoint}\\quad\n    (i)~ BB^{-1}\n  \\end{equation*}\n  \\begin{sol}\n    Only (f) is unitary.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following matrices are hermitian? Which ones are\n  symmetric?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc} 0 & 1 \\\\ 1 & 0 \\end{mymatrix}, \\quad\n    B = \\begin{mymatrix}{cc} i & 2 \\\\ 2 & -i \\end{mymatrix}, \\quad\n    C = \\begin{mymatrix}{cc} 0 & i \\\\ -i & 0 \\end{mymatrix}, \\quad\n    D = \\begin{mymatrix}{cc} 1 & 1+i \\\\ 1-i & 2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following matrices are hermitian? Which ones are\n  symmetric?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      0   & -2 & 1+i \\\\\n      -2  &  3 & i   \\\\\n      1-i &  i & 2   \\\\\n    \\end{mymatrix}, \\quad\n    B = \\begin{mymatrix}{ccc}\n      3     & i    & -1+2i \\\\\n      -i    & 0    & -1+i  \\\\\n      -1-2i & -1-i & 2     \\\\\n    \\end{mymatrix}, \\quad\n    C = \\begin{mymatrix}{ccc}\n      i & i & i \\\\\n      i & i & i \\\\\n      i & i & i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Assume $A$ and $B$ are hermitian $3\\times 3$-matrices, and $A$ is\n  invertible. Then which of the following matrices are hermitian?\n  \\begin{equation*}\n    (a)~ AB\\quad\n    (b)~ A+B\\quad\n    (c)~ iA\\quad\n    (d)~ -A\\quad\n    (e)~ 2A\\quad\n    (f)~ A^{\\adjoint}BA\\quad\n    (g)~ A^{-1}BA\\quad\n    (h)~ BB^{\\adjoint}\\quad\n    (i)~ A^2\n  \\end{equation*}\n  \\begin{sol}\n    All except (a), (c), and (d) are hermitian.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Unitarily diagonalize the hermitian matrix\n  $A=\\begin{mymatrix}{cc}\n    2  & 1+i \\\\\n    1-i & 3 \\\\\n  \\end{mymatrix}$.\n  \\begin{sol}\n    Eigenvalues: $\\eigenvar_1=1$ and $\\eigenvar_2=4$. Normalized\n    eigenvectors:\n    $\\vect{v}_1 = \\frac{1}{\\sqrt{3}}\\begin{mymatrix}{c} 1+i \\\\ -1 \\end{mymatrix}$,\n    $\\vect{v}_2 = \\frac{1}{\\sqrt{3}}\\begin{mymatrix}{c} 1 \\\\ 1-i \\end{mymatrix}$.\n    \\begin{equation*}\n      D = \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 4 \\end{mymatrix}, \\quad\n      P = \\frac{1}{\\sqrt{3}}\\begin{mymatrix}{cc} 1+i & 1 \\\\ -1 & 1-i \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Unitarily diagonalize the hermitian matrix\n  $A=\\begin{mymatrix}{cc}\n    0  & -1+2i \\\\\n    -1-2i & 4 \\\\\n  \\end{mymatrix}$.\n\\end{ex}\n\n\\begin{ex}\n  Unitarily diagonalize the hermitian matrix\n  $A=\\begin{mymatrix}{ccc}\n    2   & 1+i & 1-i  \\\\\n    1-i & 3   & -2i  \\\\\n    1+i & 2i  &   3  \\\\\n  \\end{mymatrix}$.\n\\end{ex}\n", "meta": {"hexsha": "ca8a2b0a9085bcce334f4002a160b23374912069", "size": 5054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Unitary.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Unitary.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Unitary.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.5339805825, "max_line_length": 84, "alphanum_fraction": 0.5215670756, "num_tokens": 2189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.7879364987976902}}
{"text": "%----------------------------------------------------------------------------------------\n%   LAGRANGIAN POINTS\n%----------------------------------------------------------------------------------------\n\n\\section{Computation of the Lagrangian points}\n\\subsection{Introduction}\nGiven a set of forces which apply to an object in the plane, our goal is to compute the equilibrium positions of this object. We will restrain ourselves to three kind of interactions: elastic, centrifugal and gravitational forces. We will need the previously written Newton-Raphson method, which will be applied to the resultant force. As a result, we will obtain the roots of this three-dimensional function, corresponding to the equilibrium positions.\n\n\\subsection{Forces}\nBefore explaining and analysing the method, we need to express both the general form of the forces and their Jacobian matrices. Each force will be parameterized with an integer - the intensity - and their origin.\n\nWe will start with the elastic force, which represent a spring action on an object. In a one dimensional space, this force is expressed by the following formula:\n\\[\\vec{f}_c = -k (l - l_0)\\vec{x},\\]\nwith $l$ the spring length and $l_0$ its free length.\n\nIn the plane $(O, \\vec{x}, \\vec{y})$, this force can be reduced using orthogonals projections to the following form:\n\\[f_e:\\begin{pmatrix}x\\\\y\\end{pmatrix}\\rightarrow \\begin{pmatrix}\\frac{-k(x-x_0)}{\\sqrt[]{(x-x_0)^2+(y-y_0)^2}}\\\\\\frac{-k(y-y_0)}{\\sqrt[]{(x-x_0)^2+(y-y_0)^2}}\\end{pmatrix},\\]\nwhere $\\begin{pmatrix}x_0\\\\y_0\\end{pmatrix}$ is the origin coordinate and $k$ the intensity.\n\nWe can now express the $f_e$ Jacobian matrix:\n\\[H_{f_e}:\\begin{pmatrix}x\\\\y\\end{pmatrix}\\rightarrow \\begin{pmatrix}\n\\frac{(y_0-y)^2}{((x_0-x)^2+(y_0-y)^2)^\\frac{3}{2}} & \n\\frac{(x_0-x)(y_0-y)}{((x_0-x)^2+(y_0-y)^2)^\\frac{3}{2}}\\\\\n-\\frac{(x_0-x)(y_0-y)}{((x_0-x)^2+(y_0-y)^2)^\\frac{3}{2}} & \n\\frac{(x_0-x)^2}{((x_0-x)^2+(y_0-y)^2)^\\frac{3}{2}}\n\\end{pmatrix}\\]\n\nSince the force expressions have already been given in the subject, we will only provide the forms of the Jacobian matrices for the centrifugal and gravitational forces:\n\\[H_{f_c}:\\begin{pmatrix}x\\\\y\\end{pmatrix}\\rightarrow \\begin{pmatrix}\nk & 0\\\\\n0 & k\n\\end{pmatrix}\\]\n\n\\[H_{f_g}:\\begin{pmatrix}x\\\\y\\end{pmatrix}\\rightarrow \\begin{pmatrix}\n\\frac{k(2x_0^2 - y_0^2 - 4x_0x + 2x^2 + 2y_0y - y^2)}{((x_0 - x)^2 + (y_0 - y)^2)^\\frac{5}{2}} &\n\\frac{3k(x_0 - x)(y_0 - y)}{((x_0 - x)^2 + (y_0 - y)^2)^\\frac{5}{2}}\\\\\n\\frac{3k(x_0 - x)(y_0 - y)}{((x_0 - x)^2 + (y_0 - y)^2)^\\frac{5}{2}} &\n-\\frac{c (x_0^2 - 2 y_0^2 - 2 x_0 x + x^2 + 4 y_0 y - 2 y^2)}{((x_0 - x)^2 + (y_0 - y)^2)^\\frac{5}{2}}\n\\end{pmatrix}\\]\n\n\\paragraph{Implementation} The implementation use a functionnal programming approach, which means that we use a kind of functions which will build and return a function as expression. This allow us to be more versatile by storing and using the function itself rather than using a general function, and to give it as a parameter to the Newton-Raphson method for example.\n\n\\paragraph{Tests} The tests check in particular cases the validity of the result for one force. In particular, we check for the gravitational force that the norm is invariant by rotation around the origin. Moreover, these tests rose the issue of dividing by a norm equal to zero. We handle this case by setting the value to the asymptotic value of the function in this point (either infinite or a constant). % Bring examples...\n\n\\subsection{Results}\n\\subsubsection{First approach}\nWe consider the following case:\n\\begin{itemize}\n  \\item Two gravitational forces with coefficients $1$ (resp. $0.01$) and originating from $\\begin{pmatrix}0\\\\0\\end{pmatrix}$ (resp. $\\begin{pmatrix}1\\\\0\\end{pmatrix}$).\n  \\item A centrifugal force with coefficient $1$ at the barycenter of the two masses, i.e., at $\\begin{pmatrix}\\frac{0.01}{1.01}\\\\0\\end{pmatrix}$.\n\\end{itemize}\n\nWe can easily plot the situation using the norm of the resultant force. So we get the Figure~\\vref{fig:resultant_force_norm}. From above, the graph is more explicit, as shown in the Figure~\\vref{fig:equilibrium}. The situation is similar to the Earth rotation around the Sun. Centrifugal force and gravitational attraction by the Sun are applied to the Earth. The centrifugal force applied to the barycenter of the two bodies is characteristic of a two-body interaction.\n\n\\begin{figure}[ht]\n\\centering \n\\subfloat[3D shape]{\\includegraphics[width=.6\\columnwidth]{resultant_force_norm}\\label{fig:resultant_force_norm}}\n\\subfloat[Equilibrium]{\\includegraphics[width=.45\\columnwidth]{equilibrium}\\label{fig:equilibrium}}\n\\caption[Resultant force norm]{Resultant force norm}\n\\end{figure}\n\n\\subsubsection{Lagrangian points}\nThe main issue is that the Newton-Raphson method can only compute one root while we seem to have an infinite number of roots. We can call the algorithm by specifying a step over the whole grid. We will see that in this kind of interaction, the equilibrium points are particular and well-known as the Lagrangian points.\n\nIt is not obvious with the last example that only five points correspond to an equilibrium situation. However, we can modify a bit the datas to make this phenomenon more clear and spread the values with the logarithm, as in Figure~\\vref{fig:lagrange_points}.\n\n\\begin{figure}[ht]\n  \\centering\n  \\includegraphics[width=0.8\\columnwidth]{lagrange_points} \n  \\caption[Lagrange points]{Lagrangian points.}\n  \\label{fig:lagrange_points}\n\\end{figure}\n\nAs the Newton-Raphson algorithm follows the slope of the curve, we can call it on equireparted points on the grid, distant by a fixed step we will note $\\tau$. The algorithm must work in a closed domain. Moreover, at each iteration, the algorithm will output a position corresponding to a root. Assuming that we will perform enough iterations to find at least all the roots, we must be able to determine a maximal precision on a root coordinate. The minimal distance between two distinct roots, noted $\\varepsilon$, will be another parameter of this algorithm.", "meta": {"hexsha": "7cf583dfdb6d61cc3cfefe1de89f008c6cf78662", "size": 6040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-non-linear-systems-newton-raphson/doc/lagrangian_points.tex", "max_stars_repo_name": "gdzx/numerical-algorithms", "max_stars_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_stars_repo_licenses": ["MIT"], "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-non-linear-systems-newton-raphson/doc/lagrangian_points.tex", "max_issues_repo_name": "gdzx/numerical-algorithms", "max_issues_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_issues_repo_licenses": ["MIT"], "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-non-linear-systems-newton-raphson/doc/lagrangian_points.tex", "max_forks_repo_name": "gdzx/numerical-algorithms", "max_forks_repo_head_hexsha": "1bdea5c70a5bb8fd589f95e73ed476b90693fcf0", "max_forks_repo_licenses": ["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.6216216216, "max_line_length": 560, "alphanum_fraction": 0.7235099338, "num_tokens": 1710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8962513689768735, "lm_q1q2_score": 0.7879364967499252}}
{"text": "\\chapter{Matrix Decomposition}\n\\label{chapter:Matrix Decomposition}\n\\section{LU Decomposition}\n\\section{QR Decomposition}\n\\section{Cholesky Decomposition}\n\\section{Eigen value Decomposition}\n\\begin{definition}\n\tAn $\\mathbf{eigenvector}$ of an $n\\times n$ matrix $A$ is a nonzero vector $\\vec{x}$ such that $A\\vec{x}=\\lambda\\vec{x}$ for some scalar $\\lambda$.A scalar $\\lambda$ is called $\\mathbf{eigenvalue}$ of $A$ if there is a nontrivial solution \\vec{x} of $A\\vec{x}=\\lambda\\vec{x}$;such an \\vec{x} is called an eigenvector corresponding to $\\lambda$\\footnote{An eigenvalue may be zero}.\n\\end{definition}\n\n\n\\section{Singular Value Decomposition}\n\n\\subsection{Definition}\n\\begin{definition}\n\tAny matrix can be decomposed as follows\n\t\\begin{equation}\\label{eqn:SVD}\n\t\\underbrace{\\vec{X}}_{N \\times D}=\\underbrace{\\vec{U}}_{N \\times N}\\underbrace{\\vec{\\Sigma}}_{N \\times D}\\underbrace{\\vec{V}^T}_{D \\times D}\n\t\\end{equation}\n\twhere $\\vec{U}$ is an $N \\times N$ matrix whose columns are orthornormal(so $\\vec{U}^T\\vec{U}=\\vec{I}$), $\\vec{V}$ is $D \\times D$ matrix whose rows and columns are orthonormal (so $\\vec{V}^T\\vec{V}=\\vec{V}\\vec{V}^T=\\vec{I}_D$), and $\\vec{\\Sigma}$ is a $N \\times D$ matrix containing the $r=\\min(N,D)$ singular values $\\sigma_i \\geq 0$ on the main diagonal, with 0s filling the rest of the matrix.\n\\end{definition}\n\\subsection{Proof}\nLet $A$ be an $m\\times n$ matrix.Then $A^TA$ is symmetric and can be orthogonally diagonalized with eigenvectors.The \\textbf{singular values} of $A$ are the square root of the eigenvalues of $A^TA$,denoted by $\\sigma_1,\\sigma_2,...,\\sigma_n$.That is $\\sigma_i = \\sqrt{\\lambda_i}$ for $1\\leq i \\leq n$.\nThe eigenvalues are usually arranged so that\n\\begin{equation}\n\\lambda_1 \\geq \\lambda_2 \\geq...\\geq \\lambda_n \\geq 0\n\\end{equation}\n\n\\begin{theorem}\n\tSuppose {$\\vec{v}_1,\\vec{v_2}...,\\vec{v_n}$} is an orthogonal basis of $\\mathbb{R}^n$ consisting of eigenvector of $A^TA$,arranged so that the corresponding eigenvalues of  $A^TA$ satisfy $\\lambda_1 \\geq \\lambda_2 \\geq...\\geq \\lambda_n \\geq 0$  and suppose $A$ has r nonzero singular values.Then {$A\\vec{v_1},...,A\\vec{v_r}$} is an orthogonal basis for $ColA$,and $rankA=r$. \n\\end{theorem}\n\\begin{proof}\n\tBecause $\\mathbf{v_i}$ and $\\vec{v_j}$ are orthogonal for $i\\neq j$,\n\t\\begin{equation}\n\t(A\\vec{v_i})^T(A\\vec{v_j}) = \\vec{v_i}^TA^TA\\vec{v_j} = \\vec{v_i}^T(\\lambda_j\\vec{v_j})=0\n\t\\end{equation} \n\\end{proof}\nWe therefore have\n\\begin{equation}\nA\\vec{v_i} = \\sigma_i\\vec{u_i}\n\\end{equation}\nFor a general vector $\\vec{x}$,since eigenvectors are orthogonal unit vectors,we have\n\\begin{equation}\n\\vec{x} = (\\vec{v_1}\\cdot\\vec{x})\\vec{v_1} + (\\vec{v_2}\\cdot\\vec{x})\\vec{v_2} +...+(\\vec{v_n}\\cdot\\vec{x})\\vec{v_n}\n\\end{equation}\nThis means that\n\\begin{align}\n& M\\vec{x} = (\\vec{v_1}\\cdot\\vec{x})M\\vec{v_1} + (\\vec{v_2}\\cdot\\vec{x})M\\vec{v_2} +...+(\\vec{v_n}\\cdot\\vec{x})M\\vec{v_n} \\\\\n& M\\vec{x} = (\\vec{v_1}\\cdot\\vec{x})\\sigma_1\\vec{u_1} + (\\vec{v_2}\\cdot\\vec{x})\\sigma_2\\vec{u_2} +...+(\\vec{v_n}\\cdot\\vec{x})\\sigma_n\\vec{u_n}\n\\end{align}\nRemember that dot product can be computed using the vector transpose\n\\begin{equation}\n\\vec{v}\\cdot\\vec{u} = \\vec{v^T}\\vec{u}\n\\end{equation}\nwhich leads to\n\\begin{align}\n& M\\vec{x} = \\vec{u_1}\\sigma_1\\vec{v_1^T}\\vec{x}+\\vec{u_2}\\sigma_2\\vec{v_2^T}\\vec{x}+...+\\vec{u_n}\\sigma_n\\vec{v_n^T}\\vec{x} \\\\\n&  M = \\vec{u_1}\\sigma_1\\vec{v_1^T}+\\vec{u_2}\\sigma_2\\vec{v_2^T}+...+\\vec{u_n}\\sigma_n\\vec{v_n^T}\n\\end{align}\nAnd this is usually expressed by writing \n\\begin{equation}\nM = U\\Sigma V^T\n\\end{equation}\nAs for $\\vec{u_i}$,we have\n\\begin{align*}\n&\\begin{cases}\n(A^TA)\\vec{v_i} = \\lambda_i\\vec{v_i}\t\\\\\nA\\vec{v_i}    = \\sigma_i\\vec{u_i}\t\\\\\n\\end{cases} \\\\\n&\\Rightarrow A^T\\sigma_i\\vec{u_i} = \\lambda_i\\vec{v_i} \\\\\n&\\Rightarrow \\sigma_iA^T\\vec{u_i} = \\lambda_i\\vec{v_i}\\\\\n&\\Rightarrow (AA^T)\\vec{u_i}=\\sigma_iA\\vec{v_i} = \\lambda_i\\vec{u_i}\\\\\n\\end{align*}\nSo we can see that $\\vec{u_i}$ is the eigenvector of symmetric matrix $AA^T$,and $\\vec{v_i}$ is the eigenvector of symmetric matrix $A^TA$.In summary,$\\vec{u_i}$ and \\vec{v_i} are the \\textbf{left-eigenvector} and \\textbf{right-eigenvectors} of matrix $A$.\n\\subsection{Application}\n\\subsubsection{Principal Component Analysis}\nThe projection vectors for principal component projection are the left-eigenvectors", "meta": {"hexsha": "b526748657b7eafee540252c000b677df7908eaf", "size": 4304, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/MatrixDecomposition.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/MatrixDecomposition.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/MatrixDecomposition.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": 55.8961038961, "max_line_length": 398, "alphanum_fraction": 0.6963289963, "num_tokens": 1637, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8791467580102418, "lm_q1q2_score": 0.7879364890526498}}
{"text": "\\section{Application: Simplification of quadratic forms}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether or not a function of several variables is a\n    quadratic form.\n  \\item Convert a quadratic form to and from matrix form.\n  \\item Apply a change of variables to a quadratic form.\n  \\item Diagonalize a quadratic form.\n  \\item Find the principal axes of a quadratic form.\n  \\item Sketch quadratic curves, such as circles and ellipses.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we will explore an application of the diagonalization\nof symmetric matrices, namely, the simplification of quadratic forms.\nQuadratic forms are special kinds of functions that arise, for\nexample, in calculus when we approximate some quantity up to terms of\nsecond order.\n\n\\begin{definition}{Quadratic form}{quadratic-form}\n  A \\textbf{quadratic form}%\n  \\index{quadratic form} is a polynomial in $n$ variables in which\n  each term is of degree 2. For example, the following is a quadratic\n  form in $3$ variables:\n  \\begin{equation*}\n    f(x,y,z) = 3x^2 + 3y^2 + 2xy - 4xz + 4yz.\n  \\end{equation*}\n  More generally, a quadratic form is a function of the form\n  \\begin{equation*}\n    f(x_1,\\ldots,x_n) = q_1\\,x_1^2 + \\ldots + q_n\\,x_n^2 + q_{12}\\,x_1x_2 +\n    \\ldots + q_{ij}\\,x_ix_j + \\ldots + q_{n-1,n}\\,x_{n-1}x_n.\n  \\end{equation*}\n  The numbers $q_1,\\ldots,q_n,q_{12},\\ldots,q_{n-1,n}$, which may be\n  positive, negative, or zero, are called the \\textbf{coefficients}%\n  \\index{coefficient!of a quadratic form}%\n  \\index{quadratic form!coefficient} of the quadratic form.\n\\end{definition}\n\n\\begin{example}{Quadratic forms}{quadratic-form}\n  Which of the following are quadratic forms?\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $f(x,y,z) = 2xy + 3xz - 5yz$.\n    \\item $g(x,y,z) = x^2 + 2xy + y^2 + 3$.\n    \\item $h(x,y,z) = (x+y)^2 - z^2$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  The function $f$ is a quadratic form. The function $g$ is not a\n  quadratic form, because the constant term, $+3$, is not of degree\n  2. It should be either a coefficient times the square of a variable,\n  or a coefficient times the product of two variables. The function\n  $h$ is a quadratic form. We can simplify it to $h(x,y,z) = x^2 + 2xy\n  + y^2 - z^2$.\n\\end{solution}\n\n\\begin{definition}{Matrix form of a quadratic form}{quadratic-form-matrix}\n  Let $A$ be a symmetric $n\\times n$-matrix, and let\n  $\\vect{v} = \\mat{x_1,\\ldots,x_n}^T$.  Then\n  \\begin{equation*}\n    f(x_1,\\ldots,x_n) = \\vect{v}^T A\\vect{v}\n  \\end{equation*}\n  is a quadratic form in $n$ variables. Conversely, every quadratic\n  form in $n$ variables can be uniquely written in this way. We call\n  this the \\textbf{matrix form} of the quadratic form%\n  \\index{quadratic form!matrix form}%\n  \\index{matrix form of quadratic form}.\n\\end{definition}\n\n\\begin{example}{Matrix form of a quadratic form}{quadratic-form-matrix}\n  Find the coefficients of the quadratic form $f(x,y,z) = \\vect{v}^T\n  A\\vect{v}$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 &  2 &  4 \\\\\n      2 &  0 & -1 \\\\\n      4 & -1 & -2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    f(x,y,z)\n    ~=~\n    \\begin{mymatrix}{ccc} x & y & z \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      1 &  2 &  4 \\\\\n      2 &  0 & -1 \\\\\n      4 & -1 & -2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    ~=~ x^2 - 2z^2 + 4xy + 8xz - 2yz.\n  \\end{equation*}\n  Note that there is a term $2xy$ and a term $2yx$, which together\n  yield $4xy$. Similarly the term $4xz$ and $4zx$ are combined into\n  $8xz$, and the terms $-yz$ and $-zy$ are combined into $-2yz$.\n\\end{solution}\n\n\\begin{example}{Matrix form of a quadratic form}{quadratic-form-matrix2}\n  Write the quadratic form\n  \\begin{equation*}\n    f(x,y,z) = 5x^2 - y^2 + z^2 + 2xy - 4xz + 3yz\n  \\end{equation*}\n  in matrix form.\n\\end{example}\n\n\\begin{solution}\n  We can write this as\n  \\begin{equation*}\n    f(x,y,z)\n    ~=~\n    \\begin{mymatrix}{ccc} x & y & z \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      5  &   1 &  -2 \\\\\n      1  &  -1 & 1.5 \\\\\n      -2 & 1.5 &   1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}.\n  \\end{equation*}\n  Note: since the matrix $A$ must be symmetric, we have no choice but\n  to split the term $2xy$ evenly into $1xy$ and $1yx$. This explains\n  why the $(1,2)$- and $(2,1)$-entries of the matrix are $1$. Also,\n  $-4xz$ has been split into $-2xz$ and $-2zx$, and $3yz$ has been\n  split into $1.5yz$ and $1.5zy$. In general, the matrix of the\n  quadratic form\n  \\begin{equation*}\n    f(x,y,z) = ax^2 + by^2 + cz^2 + dxy + exz + fyz\n  \\end{equation*}\n  is\n  \\begin{equation*}\n    \\def\\arraystretch{1.3}\n    A = \\begin{mymatrix}{rrr}\n      a & \\frac{d}{2} & \\frac{e}{2} \\\\\n      \\frac{d}{2} & b & \\frac{f}{2} \\\\\n      \\frac{e}{2} & \\frac{f}{2} & c \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWe will now turn to the question of how to simplify quadratic\nforms. The primary tool we have for doing so is a \\textbf{change of\n  variables}%\n\\index{change of variables!for a quadratic form}%\n\\index{quadratic form!change of variables}. This means replacing the\nvariables $x_1,\\ldots,x_n$ by new variables $y_1,\\ldots,y_n$ that are\nlinear combinations of $x_1,\\ldots,x_n$.\n\n\\begin{example}{Change of variables}{quadratic-form-change-of-variables}\n  Apply the change of variables\n  \\begin{eqnarray*}\n    x &=& u \\\\\n    y &=& v-w \\\\\n    z &=& w\n  \\end{eqnarray*}\n  to the quadratic form\n  \\begin{equation*}\n    3x^2 + y^2 + 2xy + 2xz + 2yz\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\begin{array}{l}\n      3x^2 + y^2 + 2xy + 2xz + 2yz \\\\\n      =~~ 3u^2 + (v-w)^2 + 2u(v-w) + 2uw + 2(v-w)w \\\\\n      =~~ 3u^2 + v^2 - w^2 + 2uv.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\nThe simplest kind of quadratic form is one that involves only squared\nvariables, and no products of two different variables. We call such\nquadratic forms \\textbf{diagonal}.\n\n\\begin{definition}{Diagonal quadratic form}{diagonal-quadratic-form}\n  A quadratic form is \\textbf{diagonal}%\n  \\index{diagonal quadratic form}%\n  \\index{quadratic form!diagonal} if it is of the form\n  \\begin{equation*}\n    f(x_1,\\ldots,x_n) = q_1\\,x_1^2 + \\ldots + q_n\\,x_n^2.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}{Diagonalization of quadratic forms}{quadratic-form-diagonalize}\n  Every quadratic form can be made diagonal by a change of variables.\n\\end{proposition}\n\n\\begin{proof}\n  We first write the quadratic form in matrix form, i.e.,\n  \\begin{equation*}\n    f(x_1,\\ldots,x_n) = \\vect{v}^T A \\vect{v},\n  \\end{equation*}\n  where $A$ is a symmetric matrix and\n  $\\vect{v}=\\mat{x_1,\\ldots,x_n}^T$. By\n  Theorem~\\ref{thm:diagonalization-symmetric}, $A$ is orthogonally\n  diagonalizable. So let $P$ be an orthogonal matrix such that\n  \\begin{equation*}\n    P^{-1}AP\n    ~=~ P^TAP\n    ~=~ D\n    ~=~ \\begin{mymatrix}{ccc}\n      \\eigenvar_1 & \\cdots & 0      \\\\\n      \\vdots & \\ddots & \\vdots \\\\\n      0      & \\cdots & \\eigenvar_{nn} \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  is diagonal. Let $\\vect{w}=\\mat{y_1,\\ldots,y_n}^T$ be a new set of\n  variables such that $\\vect{v} = P \\vect{w}$.  Then\n  \\begin{equation*}\n    \\vect{v}^T A \\vect{v}\n    ~=~ \\vect{w}^T P^TAP \\vect{w}\n    ~=~ \\vect{w}^T D \\vect{w}\n    ~=~ \\eigenvar_1y_1^2 + \\ldots + \\eigenvar_ny_n^2.\n  \\end{equation*}\n  So the quadratic form is diagonal in the variables $y_1,\\ldots,y_n$.\n\\end{proof}\n\n\\begin{example}{Diagonalization of quadratic forms}{quadratic-form-diagonalize}\n  Consider the quadratic form\n  \\begin{equation*}\n    f(x,y) = 3x^2 + 4xy + 6y^2.\n  \\end{equation*}\n  Perform a change of variables so that the quadratic form becomes diagonal.\n\\end{example}\n\n\\begin{solution}\n  We first write $f(x,y)$ in matrix form:\n  \\begin{equation*}\n    f(x,y)\n    = \\begin{mymatrix}{cc} x & y \\end{mymatrix}\n    \\begin{mymatrix}{rr} 3 & 2 \\\\ 2 & 6 \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}.\n  \\end{equation*}\n  Next, we orthogonally diagonalize the matrix\n  $A = \\begin{mymatrix}{rr} 3 & 2 \\\\ 2 & 6 \\end{mymatrix}$. In\n  Example~\\ref{exa:diagonalization-symmetric}, we found that $P^{-1}AP = D$, where\n  \\begin{equation*}\n    P = \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{rr} 1 & -2 \\\\ 2 & 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rr} 7 & 0 \\\\ 0 & 2 \\end{mymatrix}.\n  \\end{equation*}\n  Since $P$ is orthogonal, we also have $P^TAP=D$. Next, let $u,v$ be\n  new variables such that\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    = P \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix}\n    = \\begin{mymatrix}{c} (u-2v)/\\sqrt{5} \\\\ (2u+v)/\\sqrt{5} \\end{mymatrix}\n  \\end{equation*}\n  Then the change of variables gives\n  \\begin{equation*}\n    f(x,y)\n    ~=~ \\begin{mymatrix}{cc} x & y \\end{mymatrix}\n    A\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{cc} u & v \\end{mymatrix}\n    P^TAP\n    \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{cc} u & v \\end{mymatrix}\n    D\n    \\begin{mymatrix}{c} u \\\\ v \\end{mymatrix}\n    ~=~\n    7u^2 + 2v^2.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Diagonalization of quadratic forms}{quadratic-form-diagonalize2}\n  Diagonalize the quadratic form\n  \\begin{equation*}\n    f(x,y,z) = 3x^2 + 3y^2 + 2xy - 4xz + 4yz.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The matrix form of $f(x,y,z)$ is\n  \\begin{equation*}\n    f(x,y,z)\n    = \\begin{mymatrix}{ccc} x & y & z \\end{mymatrix}\n    \\begin{mymatrix}{rrr}\n      3  & 1 & -2 \\\\\n      1  & 3 &  2 \\\\\n      -2 & 2 &  0 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\vect{v}^T A\\vect{v}.\n  \\end{equation*}\n  We orthogonally diagonalize the matrix $A$. In\n  Example~\\ref{exa:diagonalization-symmetric}, we found that\n  $P^{-1}AP = D$, where\n  \\begin{equation*}\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    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{rrr} 4 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & -2 \\end{mymatrix}.\n  \\end{equation*}\n  Let $u,v,w$ be new variables such that\n  \\begin{equation*}\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = P \\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix}.\n  \\end{equation*}\n  Then the change of variables gives\n  \\begin{eqnarray*}\n    f(x,y,z)\n    &=& \\begin{mymatrix}{ccc} x & y & z \\end{mymatrix}\n    A\n    \\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix} \\\\\n    &=&\n    \\begin{mymatrix}{ccc} u & v & w \\end{mymatrix}\n    P^TAP\n    \\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix} \\\\\n    &=&\n    \\begin{mymatrix}{ccc} u & v & w \\end{mymatrix}\n    D\n    \\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix} \\\\\n    &=&\n    4u^2 + 4v^2 - 2w^2.\n  \\end{eqnarray*}\n\\end{solution}\n\nNext, we turn our attention to the task of sketching the solutions of\nquadratic equations in 2 or more variables.\n\n\\begin{example}{Sketching circles and ellipses}{sketching-circles-ellipses}\n  Sketch the following curves:\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $x^2+y^2=1$,\n    \\item $x^2+2y^2=1$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  (a) The curve $x^2+y^2=1$ is the familiar unit circle.\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[thick,red] (0,0) circle [radius=1];\n      \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n      \\draw[->] (0,-1.5) -- (0,1.5) node[below right] {$y$};\n      \\draw (-1,0) -- +(0,-.1) node[below left] {$-1$};\n      \\draw (1,0) -- +(0,-.1) node[below right] {$1$};\n      \\draw (0,-1) -- +(-.1,0) node[below left] {$-1$};\n      \\draw (0,1) -- +(-.1,0) node[above left] {$1$};\n    \\end{tikzpicture}\n  \\end{equation*}\n  (b) The curve $x^2+2y^2=1$ is the same, except that it has been\n  stretched by a factor of $1/\\sqrt{2}$ in the $y$-direction.\n  In other words, it is an ellipse with $x$-intercepts $\\pm 1$ and\n  $y$-intercepts $\\pm 1/\\sqrt{2}$.\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=2]\n      \\draw[thick,red,yscale={1/sqrt(2)}] (0,0) circle [radius=1];\n      \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n      \\draw[->] (0,-1.1) -- (0,1.1) node[below right] {$y$};\n      \\draw (-1,0) -- +(0,-.1) node[below left] {$-1$};\n      \\draw (1,0) -- +(0,-.1) node[below right] {$1$};\n      \\draw (0,{-1/sqrt(2)}) -- +(-.1,0) node[below left] {$-\\frac{1}{\\sqrt{2}}$};\n      \\draw (0,{1/sqrt(2)}) -- +(-.1,0) node[above left] {$\\frac{1}{\\sqrt{2}}$};\n    \\end{tikzpicture}\n  \\end{equation*}\n\\end{solution}\n\nIn general, for $a,b>0$, the curve $ax^2 + by^2 = 1$ is an ellipse\nwith $x$-intercepts $\\pm 1/\\sqrt{a}$ and $y$-intercepts\n$\\pm 1/\\sqrt{b}$. Similarly, for $a,b,c>0$, the equation\n$ax^2 + by^2 + cz^2 = 1$ describes a $3$-dimensional ellipsoid with\n$x$-intercepts $\\pm 1/\\sqrt{a}$, $y$-intercepts $\\pm 1/\\sqrt{b}$, and\n$z$-intercepts $\\pm 1/\\sqrt{c}$:\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=2]\n    \\begin{scope}[y={(1cm,-0.3cm)},x={(-0.8cm,-0.4cm)},z={(0cm,1cm)}]\n      \\draw[->] (-1.5,0,0) -- (1.5,0,0) node[left] {$x$};\n      \\draw[->] (0,-1.5,0) -- (0,1.5,0) node[right] {$y$};\n      \\draw[->] (0,0,-1.5) -- (0,0,1.5) node[below right] {$z$};\n    \\end{scope}\n    \\fill[ball color=red!70] (0,0,0) circle [x radius=1.17, y radius=0.7, rotate=-10];\n    \\begin{scope}[y={(1cm,-0.3cm)},x={(-0.8cm,-0.4cm)},z={(0cm,1cm)}]\n      \\draw[->] (0.7,0,0) -- (1.5,0,0);\n      \\draw[->] (0,1,0) -- (0,1.5,0);\n      \\draw[->] (0,0,0.58) -- (0,0,1.5);\n      \\draw (0.7,0,0) -- +(0,0,0.1) -- +(0,0,-0.1) +(0,0,-0.45) node {$\\frac{1}{\\sqrt{a}}$};\n      \\draw (0.7,0,0) -- +(0,0.1,0) -- +(0,-0.1,0);\n      \\draw (0,1,0) -- +(0,0,0.1) -- +(0,0,-0.1) +(0,0,-0.4) node {$\\frac{1}{\\sqrt{b}}$};\n      \\draw (0,1,0) -- +(0.1,0,0) -- +(-0.1,0,0);\n      \\draw (0,0,0.58) -- +(-0.1,0,0) -- +(0.1,0,0);\n      \\draw (0,0,0.58) -- +(0,0.1,0) -- +(0,-0.1,0) +(0,-0.3,0) node {$\\frac{1}{\\sqrt{c}}$};\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{equation*}\n\n\\noindent\nEach ellipse or ellipsoid has a set of \\textbf{principal axes}%\n\\index{principal axis}%\n\\index{quadratic form!principal axes}, which are its axes of\nsymmetry. When the quadratic forms are diagonal, as in the above\nexamples, the principal axes are the standard coordinate axes. When\nthe quadratic forms are not diagonal, the principal axes are the\neigenvectors of the matrix $A$. This is the content of the following\nproposition.\n\n\\begin{proposition}{Principal axes of a quadratic form}{principal-axes}\n  Consider a quadratic form in matrix form,\n  $f(\\vect{v}) = \\vect{v}^TA\\vect{v}$, where $A$ is a positive definite\n  $n\\times n$-matrix. Let $\\set{\\vect{u}_1,\\ldots,\\vect{u}_n}$ be an\n  orthonormal set of eigenvectors of $A$, and let\n  $\\eigenvar_1,\\ldots,\\eigenvar_n$ be the corresponding eigenvalues.\n  Then the solutions of the equation\n  \\begin{equation*}\n    \\vect{v}^TA\\vect{v} = 1\n  \\end{equation*}\n  form an $n$-dimensional ellipsoid whose principal axes are parallel\n  to $\\vect{u}_1,\\ldots,\\vect{u}_n$ and whose $\\vect{u}_i$-intercepts\n  are $\\pm\\frac{1}{\\sqrt{\\eigenvar_i}}$.\n\\end{proposition}\n\n\\begin{proof}\n  Let $P$ be the orthogonal matrix whose columns are\n  $\\vect{u}_1,\\ldots,\\vect{u}_n$. From the proof of\n  Proposition~\\ref{prop:quadratic-form-diagonalize}, we know that the\n  equation $\\vect{v}^TA\\vect{v} = 1$ is equivalent to\n  $\\eigenvar_1y_1^2 + \\ldots + \\eigenvar_ny_n^2=1$, where\n  $y_1,\\ldots,y_n$ are variables such that\n  \\begin{equation}\\label{eqn:principal-axes}\n    \\vect{v} = P\\begin{mymatrix}{c} y_1 \\\\ \\vdots \\\\ y_n \\end{mymatrix}.\n  \\end{equation}\n  Since $A$ is positive definite, we have\n  $\\eigenvar_1,\\ldots,\\eigenvar_n>0$ by\n  Proposition~\\ref{prop:characterize-positive}.  We therefore know\n  that in the $(y_1,\\ldots,y_n)$-coordinate system, the equation\n  $\\eigenvar_1y_1^2 + \\ldots + \\eigenvar_ny_n^2 = 1$ describes an\n  ellipsoid whose $y_1$-intercepts are $\\pm1/\\sqrt{\\eigenvar_1}$, whose\n  $y_2$-intercepts are $\\pm1/\\sqrt{\\eigenvar_2}$, and so on. The only\n  thing that remains to do is to figure out the direction of the\n  coordinate axes. The $y_1$-axis points in the direction of the point\n  with coordinates $(y_1,\\ldots,y_n) = (1,0,\\ldots,0)$.  Using the\n  change of variables formula {\\eqref{eqn:principal-axes}}, we find\n  that this corresponds to the first column of $P$, i.e.,\n  $\\vect{v}=\\vect{u}_1$. Similarly, the $y_2$-axis points in the\n  direction of $\\vect{u}_2$, and so on.\n\\end{proof}\n\n\\begin{example}{Sketching a quadratic curve}{sketching-quadratic}\n  Sketch the curve $3x^2 + 4xy + 6y^2 = 1$.\n\\end{example}\n\n\\begin{solution}\n  The matrix for the quadratic form $3x^2 + 4xy + 6y^2$ is\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr} 3 & 2 \\\\ 2 & 6 \\end{mymatrix}.\n  \\end{equation*}\n  From Example~\\ref{exa:quadratic-form-diagonalize}, we know that the\n  normalized eigenvectors of $A$ are\n  \\begin{equation*}\n    \\vect{u}_1\n    ~=~ \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{u}_2\n    ~=~ \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{r} -2 \\\\ 1 \\end{mymatrix},\n  \\end{equation*}\n  with respective eigenvalues $\\eigenvar_1 = 7$ and $\\eigenvar_2 =\n  2$. Therefore, by Proposition~\\ref{prop:principal-axes}, the curve\n  $3x^2 + 4xy + 6y^2 = 1$ is an ellipse with principal axes\n  $\\vect{u}_1$ and $\\vect{u}_2$, and with respective intercepts\n  $\\pm1/\\sqrt{7}$ and $\\pm1/\\sqrt{2}$.\n  \\begin{equation*}\n    \\begin{tikzpicture}[scale=3]\n      \\begin{scope}[color=black]\n        \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n        \\draw[->] (0,-1.5) -- (0,1.5) node[below right] {$y$};\n        \\draw (-1,0) -- +(0,-.1) node[below] {$-1$};\n        \\draw (1,0) -- +(0,-.1) node[below] {$1$};\n        \\draw (0,-1) -- +(-.1,0) node[left] {$-1$};\n        \\draw (0,1) -- +(-.1,0) node[left] {$1$};\n      \\end{scope}\n      \\begin{scope}[color=blue,cm={(1/sqrt(5),2/sqrt(5),-2/sqrt(5),1/sqrt(5),(0,0))}]\n        \\draw[thick,red] (0,0) circle [x radius={1/sqrt(7)}, y radius={1/sqrt(2)}];\n        \\draw[->,blue!50] (-1.5,0) -- (1.5,0);\n        \\draw[->,blue!50] (0,-1.5) -- (0,1.5);\n        \\draw[blue!50] (-1,0) -- +(0,.1) +(0,0.2) node {$-1$};\n        \\draw[blue!50] (1,0) -- +(0,.1) +(0,0.2) node {$1$};\n        \\draw[blue!50] (0,-1) -- +(-.1,0) +(-0.2,0) node {$-1$};\n        \\draw[blue!50] (0,1) -- +(-.1,0) +(-0.2,0) node {$1$};\n        \\draw ({-1/sqrt(7)},0) -- +(0,.1) +(-0.15,0.2) node {$-\\frac{1}{\\sqrt{7}}$};\n        \\draw ({1/sqrt(7)},0) -- +(0,.1) +(0.1,0.15) node {$\\frac{1}{\\sqrt{7}}$};\n        \\draw (0,{-1/sqrt(2)}) -- +(-.1,0) +(-0.25,0) node {$-\\frac{1}{\\sqrt{2}}$};\n        \\draw (0,{1/sqrt(2)}) -- +(-.1,0) +(-0.225,0) node {$\\frac{1}{\\sqrt{2}}$};\n        %\\fill[color=black] (1,0) circle [radius=0.9pt] node[right=5pt] {$(x,y)=(\\frac{1}{\\sqrt{5}},\\frac{2}{\\sqrt{5}})$};\n        %\\fill[color=black] (0,1) circle [radius=0.9pt] node[left=11pt] {$(x,y)=(-\\frac{2}{\\sqrt{5}},\\frac{1}{\\sqrt{5}})$};\n        \\draw[thick,blue,->] (0,0) -- (1,0) node[right] {$\\vect{u}_1$};\n        \\draw[thick,blue,->] (0,0) -- (0,1) node[above] {$\\vect{u}_2$};\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "cdd3a85c1cdd02393ed4632b2904b6d16d614d63", "size": 19322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Application-QuadraticForms.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Application-QuadraticForms.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Application-QuadraticForms.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.185770751, "max_line_length": 123, "alphanum_fraction": 0.6027843908, "num_tokens": 7655, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8962513682840825, "lm_q1q2_score": 0.7879364876271109}}
{"text": "\n\\subsection{Orthogonal vectors}\n\nGiven a metric \\(M\\), two vectors \\(v\\) and \\(u\\) are orthogonal if:\n\n\\(v^TMu=0\\)\n\nFor example if we have the metric \\(M=I\\), then two vectors are orthogonal if:\n\n\\(v^Tu=0\\)\n\n", "meta": {"hexsha": "35978d55b66e7e50dced89ad4ffc295eff5d6193", "size": 209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-03-orthogonalVectors.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-03-orthogonalVectors.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-03-orthogonalVectors.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.4166666667, "max_line_length": 78, "alphanum_fraction": 0.6555023923, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9609517106286379, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7878779015646274}}
{"text": "\\section{Portfolio Theory}\n\n\\subsection*{Preliminaries}\n\nPortfolio return and variance, two assets\n$ \\bar{r}_p = w_1 \\bar{r}_1 +  w_2 \\bar{r}_2 $ \\\\\n$ \\sigma_p^2 = w_1^2 \\sigma_1^2 + w_2^2 \\sigma_2^2 + 2 w_1 w_2 \\sigma_{12}  $ \\\\\n$ \\sigma_p^2 = w_1^2 \\sigma_1^2 + w_2^2 \\sigma_2^2 + 2 w_1 w_2 \\rho_{12} \\sigma_1 \\sigma_2  $ \\\\\t\t\n$  \\rho_{12} = \\frac{\\sigma_{12}}{\\sigma_1 \\sigma_2}$ \\\\\n\nQuadratic formula is handy when solving for weights in the two asset case:\n$x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$\n\nIn general, for a vector of weights $\\bm{w}$ , returns $\\bm{r}$ and covariance matrix $\\bm{\\Sigma}$:\n$ r_p = \\bm{w} \\cdotp \\bm{r} $ \\\\ \tand $\\bm{ \\sigma_p}^2 = \\bm{w}^\\prime \\cdot \\bm{\\Sigma} \\cdot \\bm{w} $\nin Excel  \\texttt{$\\sigma_p^2$=MMULT(MMULT(TRANSPOSE($\\bm{w}$),$\\bm{\\Sigma}$),$\\bm{w}$)  }\n\n\n\\subsection*{Sharpe Ratio}\n$SR = \\frac{r-r_f}{\\sigma}$ , \nReturn-to-Risk Ratio $RRR_{i,p} = \\frac{r_i-r_f}{Cov(r_i,r_p)/\\sigma_p}$\n\n\\subsection*{Portfolio and individual assets}\nIn the presence of a risk-free asset, portfolio’s return is: $\\bar{r}_p =r_F + \\sum_{i=1}^{N} w_i (\\bar{r}_i -r_F)$\n\n{Individual contribution to expected return:}\n$ \\frac{\\partial \\bar{r}_p}{\\partial w_i}  = \\bar{r}_i - r_F$\n\n{Individual contribution to volatility:}\n$ \\frac{\\partial \\sigma_p}{\\partial w_i}  = \\frac{Cov(\\bar{r}_i,\\bar{r}_p )}{\\sigma_p}$\n\n\\subsection*{Tangency Portfolio}\nNote $\\bm{\\bar{x}}$ is vector of excess returns and $\\bm{\\vec{1}}$ is a vector of ones of size $N$, number of stocks.\n\nmin $\\bm{w}^\\prime \\cdot \\bm{\\Sigma} \\cdot \\bm{w} $  s.t. $\\bm{w}^\\prime \\cdot \\bm{\\bar{x}} = m  $ solution: $w_T=\\lambda \\bm{\\Sigma}^{-1} \\bm{\\bar{x}}$ \nwhere $\\lambda = \\frac{1}{\\bm{\\bar{x}^\\prime}  \\bm{\\Sigma}^{-1}  \\bm{\\vec{1}}} $. \nIn summary, the tangency weights are: $w_T=\\frac{1}{\\bm{\\bar{x}^\\prime}  \\bm{\\Sigma}^{-1}  \\bm{\\vec{1}}} \\bm{\\Sigma}^{-1} \\bm{\\bar{x}}$.\nIn Excel use \\texttt{$\\bm{\\Sigma}^{-1}$=MINVERSE($\\bm{\\Sigma}$)}, then \\texttt{$\\lambda=$MMULT(MMULT(TRANSPOSE($\\bm{\\bar{x}}$),$\\bm{\\Sigma}^{-1}$)),$\\bm{\\vec{1}}$)  } , lambda is a scalar, \nthen \\\\\n\\texttt{$w_T=\\lambda$ MMULT($\\bm{\\Sigma}^{-1}$),$\\bm{\\bar{x}}$ )}. \\\\\nOnce the tangency portfolio is found, $RRR$ is the same for all stocks, meaning that we cannot perturb the weights of individual assets in this portfolio to further increase its risk return trade off.\n\n\n\n\\subsection*{R14Q4}\n$r_i = b_{1} F_1 + b_{2,i} F_2 + \\epsilon_i $\\\\\ninputs:\n$b_1=10$, $b_{2,i}=i$, \n$F_1$ has $E[F_1]=0\\%$ and $\\sigma_{F_1}=1\\%$ , $F_2$ has  $E[F_2]=1\\%$ and $\\sigma_{F_2}=1\\%$, and $\\epsilon_i$ has $E[\\epsilon_i]=0\\%$ and $\\sigma_{\\epsilon_i}=30\\%$. $F_1$, $F_2$, $\\epsilon_i$ are indep. of each other, and $r_f=0.75\\%$.\\\\\nfind sharpe ratio and return-to-risk ratio RRR \\\\\n$E[r_i] = b_1E[F_1] + b_2,iE[F_2] + E[\\epsilon_i]=i \\cdot 1\\%$ \\\\\n\n$V [r_i] = V [b_1F_1 + b_{2,i}F2 + \\epsilon_i]= b_1^2V[F_1] + b_{2,i}^2V [F_2] + V [\\epsilon_i] =  10^2  \\times 0.01^2 + i^2  \\times 0.01^2 + 0.3^2$ \\\\\n$Cov(r_i,r_j) = Cov(b_1 F_1 + b_{2,i}F+2 + \\epsilon_i, b_1 F_1 + b_{2,j} F_2 + \\epsilon_j) = V[b_1 F_1] + Cov(b_{2,i}F_2 , b_{2,j} F_2 ) = b_1^2 V[F_1] + b_{2,i}b_{2,j}V[F_2] = 10^2 \\times 0.01^2 + i \\times j \\times 0.01^2 $. With the variances (note variances have an extra-term) and covariances now we can form $\\Sigma$ and compute sharpe ratio.\n\n$RRR_{i,p} = \\frac{r_i-r_f}{Cov(r_i,r_p)/\\sigma_p}$  note $Cov(r_i, r_p) = Cov(r_i,\\sum_{j=1}^{I} w_j r_j) = \\sum_{j=I}^{I}w_j Cov(r_i, r_j) $ \\\\\n\n", "meta": {"hexsha": "439459a579702f18342b906c03ace7ccf35d27a9", "size": 3437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_14.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_14.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_14.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": 59.2586206897, "max_line_length": 347, "alphanum_fraction": 0.6165260402, "num_tokens": 1464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802373309982, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7878430459671882}}
{"text": "\\subsection{Periodic activation function}\nBy dilating $\\sigma$ if necessary, we may assume without loss of generality that $\\sigma$ is periodic on $[0,1]$. Consider the Fourier series of $\\sigma$\n\\begin{equation}\n\\sigma(x) = \\displaystyle\\sum_{i=-\\infty}^\\infty a_i e^{2\\pi ix},\n\\end{equation}\nwith coefficients\n\\begin{equation}\\label{eq_1027}\na_i =  \\int_0^{1} \\sigma(b)e^{-2\\pi ib}db. \n\\end{equation}\nThe assumption that $\\sigma$ is non-constant means that there exists some $i$ such that $a_i \\neq 0$. Note that we do not need the Fourier series to converge pointwise to $\\sigma$, all we need is for some $a_i$ to be non-zero and the integrals in \\eqref{eq_1027} to converge (which is does since $\\sigma\\in W^{m,\\infty}$). Notice that shifting $\\sigma$ by $t$, i.e. replacing $\\sigma$ by $\\sigma(\\cdot+t)$, scales the coefficient $a_i$ by $e^{it}$. Setting $t = (\\omega \\cdot x)$, we get\n\\begin{equation}\ne^{2\\pi i\\omega\\cdot x} = \\frac{1}{a_i}\\int_0^{1} \\sigma\\left(\\omega\\cdot x + b\\right)e^{-2\\pi ib}db.\n\\end{equation}\nPlugging this into the Fourier representation of $u$, we see that\n\\begin{equation}\nu(x) = \\int_{\\mathbb{R}^d} e^{2\\pi i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega = \\frac{1}{ a_i}\n\\int_{\\mathbb{R}^d}\\int_0^{1}\\sigma\\left(\\omega\\cdot x + b\\right)e^{-2\\pi ib}\\hat{u}(\\omega)dbd\\omega.\n\\end{equation}\nSince $u(x)$ is real, we can add this to its conjugate to obtain the representation\n\\begin{equation}\\label{eq_1029}\nu(x) = \\int_{\\mathbb{R}^d} e^{2\\pi i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega = \\frac{1}{|a_i|}\n\\int_{\\mathbb{R}^d}\\int_0^{1}\\sigma\\left(\\omega\\cdot x + b\\right)e^{-ib}\\hat{u}(\\omega)dbd\\omega.\n\\end{equation}\n \n \n", "meta": {"hexsha": "ae05a61d4abbb80eab35d7bfd169dea044a8f81e", "size": 1640, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/PeriodicActivation.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/PeriodicActivation.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/PeriodicActivation.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.0769230769, "max_line_length": 487, "alphanum_fraction": 0.687804878, "num_tokens": 597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.7878042207324829}}
{"text": "\\section{Continuity}\n\n\\subsection{Exercise 1}\nContinuity implies $\\lim_{h \\to 0} [f(x + h) - f(x - h)] = 0$, since we can choose $h$ to be within\n$\\delta$ of $x$ such that $\\abs{f(x + h) - f(x) + f(x) - f(x - h)} \\leq \\abs{f(x + h) - f(x)}\n+ \\abs{f(x - h) - f(x)} < \\epsilon$. However, the converse (as asked in the question) need not be\ntrue, since we don't have to have $\\lim_{h \\to 0} f(x + h) = f(x) = \\lim_{h \\to 0} f(x - h)$.\nFor example, consider $x \\neq 0 \\implies f(x) = \\frac{1}{\\abs{x}}, \\: f(0) = 0$. \n\n\\subsection{Exercise 2}\nSuppose $p$ is a limit point of $E$. Then there is a sequence $(x_n) \\in E \\: | \\: \\lim_{n \\to \\infty} x_n = p$.\nSince $f$ is continuous, we have that $lim_{n \\to \\infty} f(x_n) = f(p)$, which implies that $f(p)$ is\na limit point of $f(E)$ giving us that $f(\\overline{E}) \\subset  \\overline{f(E)}$.\n\nTo see that $f(\\overline{E})$ can be a proper subset, consider $f: \\mathbb{Z}^{+} \\to \\mathbb{Q}$ with\n$f(x) = \\frac{1}{x}$. Then $f$ is continuous and $0 \\notin f(\\overline{\\mathbb{Z}^{+}}) = f(\\mathbb{Z}^{+})$.\n\n\\subsection{Exercise 3}\nSimilar to Exercise 2: if $p$ is a limit point of $Z(f)$, then there exists some sequence $(x_n) \\in E \\: | \\: \n\\lim_{n \\to \\infty} x_n = p$. Since $f$ is continuous, we have that $\\lim_{n \\to  \\infty} f(x_n) = f(p)$. \nThen it follows that $x_n \\in Z(f) \\implies f(x_n) = 0 \\implies f(p) = 0$.\n\n\\subsection{Exercise 4}\nThe fact that $f(E)$ is dense in $f(X)$ follows from Exercise 2, since $X = \\overline{E}$.\nSimilarly, $\\lim_{n \\to \\infty} g(p_n) = g(p) \\implies \\lim_{n \\to \\infty} f(p_n) = g(p)$ \nsince $p_n \\in E$. Thus, $g(p) = f(p)$ for all $p \\in X$.\n\n\\subsection{Exercise 5}\nIf $f$ is defined on an open set in $\\mathbb{R}^1$, then it need not be defined at its endpoints.\nFor example, consider $f(x) = \\frac{1}{x}$ defined on $(0, 1)$. However, if $f$ is defined on a\nclosed subset $E \\subset \\mathbb{R}^1$, then $E^c$ is an open set in $\\mathbb{R}$ and can thus be\ndecomposed into the union of a countable number of open intervals $(a_n, b_n)$. We can thus take\n$g$ to be $g(x) = \\frac{b_n - x}{b_n - a_n} f(a_n) + (1 - \\frac{b_n - x}{b_n - a_n}) f(b_n)$ \n(the straight line interpolation between $f(a_n)$ and $f(b_n)$).\n\n\\subsection{Exercise 6}\n$f$ is a bijection from $E$ to its graph $G(E)$. If $f$ is continuous, then we can take the inverse image of\nan open cover of $G(E)$ to get an open cover of $E$. Since $E$ is compact, this open cover must have a\nfinite subcover whose image under $f$ will be a finite subcover for $G(E)$, thereby giving the compactness of\n$G(E)$.\n\nI looked up a hint on the reverse direction. Consider an infinite (finite case presents no issues) closed set \n$V \\subset G(E)$. Take some arbitrary subsequence $(x_k, f(x_k)) \\in V$. \nBy the compactness of $G(E)$, this subsequence has a limit point $(x, f(x)) \\in G(E)$, and this limit point is\ncontained in $V$ since $V$ is closed. Thus, $f^{-1} (V)$ also contains $x_k \\to x$, implying that $f^{-1} (V)$ \ncontains all of its limit points and is therefore closed. This shows that $f$ is continuous.\n\nFor what it's worth, I think \n\\href{http://at.yorku.ca/cgi-bin/bbqa?forum=ask_an_analyst_2005&task=show_msg&msg=3485.0001.0001.0001}{this}\nargument using projections is much nicer.\n\n\\subsection{Exercise 7}\nSuppose for any $M$ that $\\exists x, y \\: | \\: f(x, y) > M$ (we consider only the case where $x > 0$, as the\nother case is identical). Then we can solve the resulting quadratic to see that, if such $x$ and $y$ exist,\nthen $x > \\frac{y^2 (1 + \\sqrt{1 - 4M^2})}{2M}$. However, $\\sqrt{1 - 4M^2}$ is not defined in $\\mathbb{R}$\nfor $M > \\frac{1}{2}$, so $f$ must be bounded. Performing the same analysis for $g$ yields \n$x > \\frac{y^2 (1 + \\sqrt{1 - 4y^2M^2})}{2M}$. Since $y$ can be chosen to make the inequality for $x$ have\na solution in $\\mathbb{R}$, $g$ is unbounded.\n\nTo show that $f$ is discontinuous at $(0, 0)$, we need only consider the sequence consisting of \n$(0, \\frac{n}{n + 1})$ to see that $\\lim_{n \\to \\infty} f(0, \\frac{n}{n+1}) = 1 \\neq 0$. Plugging in\n$y = ax + b$ leads to $f$ and $g$ being quotients of two polynomials with non-zero denominator,\nindicating that they're both continuous.\n\n\\subsection{Exercise 8}\nSuppose $f$ is not bounded. Then there is a sequence $f(x_n) \\: | \\: \\forall N, \\exists m, n \\geq N \\: \\abs{f(x_n) - f(x_m)} > \\epsilon$ for some\n$\\epsilon$, since otherwise $f(x_n)$ would converge to some point of $\\mathbb{R}$. As $f$ is \nuniformly continuous, this means that $\\abs{x_n - x_m} > \\delta$ for infinitely many $n, m$.\nHowever, that would then imply that $E$ is not bounded, which is a contradiction. Thus, $f$ is bounded on\n$E$.\n\nIf $E$ is not bounded, we can just take $f(x) = x$.\n\n\\subsection{Exercise 9}\nLet $E$ consist of all $x, y \\: | \\: d_X (x, y) < \\delta$. Then $\\text{diam} E < \\delta$. Similarly, if\n$\\forall x, y \\: d_Y(f(x), f(y)) < \\epsilon$, then $\\text{diam} f(E) < \\epsilon$.\n\n\\subsection{Exercise 10}\nSuppose $f$ is not uniformly continuous. Then there is a sequence $x_n \\in X \\: | \\: x_n \\to x$, but\n$\\forall N, \\exists m, n \\geq N \\: | \\: d_Y(f(x_n), f(x_m)) > \\epsilon$ for some $\\epsilon > 0$. This,\nhowever, makes $f(x_n)$ an infinite subset of $f(X)$ which does not have a limit point, thereby \ncontradicting the fact that $f(X)$ is compact.\n\n\\subsection{Exercise 11}\nThe first part of this exercise is basically what I was doing for Exercises 8 and 10. Since $f$ \nis uniformly continuous, $\\exists \\delta \\: | \\: d_X(x_n, x_m) < \\delta \\implies d_Y(f(x_n), f(x_m)) < \\epsilon$\n. Since $(x_n)$ Cauchy converges, we can make $d_X(x_n, x_m)$ arbitrarily small, which then implies that\nwe can make $d_Y(f(x_n), f(x_m))$ arbitrarily small, indicating that $f(x_n)$ Cauchy converges as well.\n\n\\subsection{Exercise 12}\nTo state it more precisely: if $f: X \\to Y$ and $g: Y \\to Z$ are both uniformly continuous, then $g \\circ f$ \nis also uniformly continuous.\n\nFrom uniform continuity of $g$, $\\exists \\delta \\: | \\: d_Y(y_1, y_2) < \\delta \\implies d_Z(g(y_1), g(y_2)) < \\epsilon$.\nSince $f$ is uniformly continuous, $\\exists \\delta' \\: | \\: d_X(x_1, x_2) < \\delta' \\implies\nd_Y(f(x_1), f(x_2)) < \\delta$. The existence of this $\\delta'$ gives us that $g \\circ f$ is uniformly\ncontinuous.\n\n\\subsection{Exercise 13}\nSuppose $p$ is a limit point of $E$ and $x_n \\in E \\: | \\: x_n \\to p$.\nThen $f(x_n)$ Cauchy converges to a point $q$ in the codomain of $f$. We can simply take $g(p) = q$\nwhenever $p \\notin E$ to get a continuous extension of $f$. Since this proof depends only on the convergence\nof the Cauchy sequence $f(x_n)$ to a point in the codomain, it will hold for the codomain being any\ncomplete metric space.\n\n\\subsection{Exercise 16}\nThe function $[x]$ has a simple discontinuity at every integer $x$, since the left-hand limit is  $x-1$ \nand the right-hand limit is $x$. Similarly, the function $(x)$ also has a simple discontinuity at every integer,\n since the left-hand limit is 1 and the right-hand limit is 0.\n\n\\subsection{Exercise 17}\nWe proceed as hinted in the text. The two types of simple discontinuity we need to consider are\n$f(x-) \\neq f(x+)$ and $f(x-) = f(x+) \\neq f(x)$. For the first case, suppose (WLOG) that\n$f(x-) < f(x+)$. Then we can construct a rational triple $(p, q, r)$ such that \n\\begin{align*}\n        &f(x-) < p < f(x+) \\\\\n        &a < q < t < x \\implies f(t) < p \\\\\n        &x < t < r < b \\implies f(t) > p\n\\end{align*}\nTo see that such a triple can only be associated with one such $x$, consider $x' = x + \\epsilon$ with\n$\\epsilon > 0$ (the other case is identical). Then we can choose $t \\in (x, x')$ with $q < x < t < r < x'$,\nwhich means $t > q$ does not imply $f(t) < p$. This handles simple discontinuities of the form\n$f(x-) \\neq f(x+)$.\n\nWe can similarly handle the case where $f(x-) = f(x+) \\neq f(x)$. Suppose (WLOG) that $f(x) > f(x+)$ ; \nwe can then construct a rational triple $(p, q, r)$ such that\n\\begin{align*}\n        &f(x+) < p < f(x) \\\\ \n        &a < q < t < x \\implies f(t) < p \\\\\n        &x < t < r < b \\implies f(t) < p \n\\end{align*}\nAgain, such a triple can only be associated with a single $x$, since $x \\in (x, x + \\epsilon)$ and\n$f(x) > p$. Therefore $f$ has only countably many simple discontinuities.\n\n\\subsection{Exercise 23}\nFrom the definition of convexity, we have that\n\\begin{align*}\n        f(\\lambda x + (1 - \\lambda) p) &\\leq \\lambda f(x) + (1 - \\lambda) f(p) \\\\\n        f(\\lambda x + (1 - \\lambda) p) - f(p) &\\leq \\lambda (f(x) - f(p)) \\\\\n        f(p) - f(\\lambda x + (1 - \\lambda) p) &\\geq \\lambda (f(p) - f(x)) \\\\\n        \\implies \\lim_{\\lambda \\to 0} f(\\lambda x + (1 - \\lambda) p) &= f(p)\n\\end{align*}\nSince $\\lim_{\\lambda \\to 0} \\lambda x + (1 - \\lambda) p = 0$ for all choices of $x$, we have that $f$ \nis continuous.\n", "meta": {"hexsha": "a83364d4d7056a050a80087d2e739dceb0709538", "size": 8737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principles_of_Mathematical_Analysis_Rudin/chapter_4.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_4.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_4.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": 60.2551724138, "max_line_length": 145, "alphanum_fraction": 0.6406089047, "num_tokens": 3042, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.908617893221035, "lm_q1q2_score": 0.7878042054187477}}
{"text": "\\documentclass{tufte-handout}\n\n\\usepackage{xcolor}\n\\usepackage{graphicx}\n\n% set hyperlink attributes\n\\hypersetup{colorlinks}\n\n\\usepackage{amsmath}\n\n% set image attributes:\n\\usepackage{graphicx}\n\\graphicspath{ {images/} }\n\n% create environment for bottom paragraph:\n\\newenvironment{bottompar}{\\par\\vspace*{\\fill}}{\\clearpage}\n\n% ============================================================\n\n% define the title\n\\title{SOC 4930/5050: Week 03 Equations Quick \\\\Reference}\n\\author{Christopher Prener, Ph.D.}\n\\date{September 11\\textsuperscript{th}, 2017}\n% ============================================================\n\\begin{document}\n% ============================================================\n\\maketitle % generates the title\n% ============================================================\n\n\\vspace{5mm}\n\\section{Median (odd \\textit{n} of items)}\nLet $m =$ the median item's term:\n\\begin{equation}\n\\scalebox{2} {$ m = \\left( \\frac { n+1 }{ 2 }  \\right) ^{ th } $}\n\\end{equation}\n\n\\vspace{10mm}\n\\section{Median (even \\textit{n} of items)}\n\\begin{subequations}\n\\noindent Let ${ m }_{ a } =$ the median item's term:\n\\begin{align}\n\\scalebox{2} {$ m_{ a } = \\left( \\frac { n+1 }{ 2 }  \\right) ^{ th } $}\n\\end{align}\n\n\\vspace{2mm}\n\\noindent Let ${ x }_{ a } =$ the next lower value before ${ m }_{ a }$. Let ${ x }_{ b } =$ the next higher value after ${ m }_{ a }$.\n\n\\vspace{2mm}\n\\noindent Let ${ m }_{ b } =$ the median:\n\\begin{align}\n\\scalebox{2} {$ { m }_{ b } = \\left( \\frac { { x }_{ a } + { x }_{ b } }{ 2 } \\right) $}\n\\end{align}\n\\end{subequations}\n\n\\vspace{10mm}\n\\section{Mean}\n\\begin{equation}\n\\scalebox{2} {$ \\bar{ x } =\\frac { \\sum _{ i=1 }^{ n }{ x }  }{ n } $}\n\\end{equation}\n\n\\newpage\n\\section{Standard Deviation}\n\\begin{subequations}\n\n\\paragraph{Deviance}\n\\begin{equation}\n\\scalebox{2} {$ { D }= { (x-\\bar{ x } ) } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Total Error}\n\\begin{equation}\n\\scalebox{2} {$ { TE }= \\sum _{ i=1 }^{ n }{ (x-\\bar{ x } ) } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Sum of Squared Error}\n\\begin{equation}\n\\scalebox{2} {$ { SS }= \\sum _{ i=1 }^{ n }{ (x-\\bar{ x } )^{ 2 } } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Variance}\n\\begin{equation}\n\\scalebox{2} {$ { s }^{ 2 }=\\frac { \\sum _{ i=1 }^{ n }{ (x-\\bar{ x } )^{ 2 } }  }{ n-1 } $}\n\\end{equation}\n\n\\vspace{3mm}\n\\paragraph{Standard Deviation}\n\\begin{equation}\n\\scalebox{2} {$ { s }=\\sqrt { \\frac { \\sum _{ i=1 }^{ n }{ (x-\\bar{ x } )^{ 2 } }  }{ n-1 } } $}\n\\end{equation}\n\\end{subequations}\n\n% ============================================================\n\\end{document}", "meta": {"hexsha": "d5b0c8fdbefe468d92ae187b99056d9699548d4f", "size": 2557, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week-03-equations.tex", "max_stars_repo_name": "slu-soc5050/Equations", "max_stars_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "week-03-equations.tex", "max_issues_repo_name": "slu-soc5050/Equations", "max_issues_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "week-03-equations.tex", "max_forks_repo_name": "slu-soc5050/Equations", "max_forks_repo_head_hexsha": "6398ba3a3d351d95a37d3245fcc6eabb91fdd032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6354166667, "max_line_length": 135, "alphanum_fraction": 0.5365662886, "num_tokens": 876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.7877067892101659}}
{"text": "\\label{functions}\n\nFunctions are a form of expression that may take input arguments surrounded by parentheses. Most of the traditional BASIC \\emph{statements} that does not return a value are \\emph{functions} in \\tbas , and like those, while \\tbas\\ functions can be called without parentheses, it is highly \\emph{discouraged} because of the ambiguities in syntax. \\textbf{Always use parentheses on function call!}\n\n\\section{Mathematical}\n\n    \\subsection{ABS}\n        \\index{ABS (function)}\\codeline{Y \\textbf{= ABS(}X\\textbf{)}}\\par\n        Returns absolute value of \\code{X}.\n    \\subsection{ACO}\n        \\index{ACO (function)}\\codeline{Y \\textbf{= ACO(}X\\textbf{)}}\\par\n        Returns inverse cosine of \\code{X}.\n    \\subsection{ASN}\n        \\index{ASN (function)}\\codeline{Y \\textbf{= ASN(}X\\textbf{)}}\\par\n        Returns inverse sine of \\code{X}.\n    \\subsection{ATN}\n        \\index{ATN (function)}\\codeline{Y \\textbf{= ATN(}X\\textbf{)}}\\par\n        Returns inverse tangent of \\code{X}.\n    \\subsection{CBR}\n        \\index{CBR (function)}\\codeline{Y \\textbf{= CBR(}X\\textbf{)}}\\par\n        Returns cubic root of \\code{X}.\n    \\subsection{CEIL}\n        \\index{CEIL (function)}\\codeline{Y \\textbf{= CEIL(}X\\textbf{)}}\\par\n        Returns integer value of \\code{X}, truncated towards positive infinity.\n    \\subsection{COS}\n        \\index{COS (function)}\\codeline{Y \\textbf{= COS(}X\\textbf{)}}\\par\n        Returns cosine of \\code{X}.\n    \\subsection{COSH}\n        \\index{COSH (function)}\\codeline{Y \\textbf{= COSH(}X\\textbf{)}}\\par\n        Returns hyperbolic cosine of \\code{X}.\n    \\subsection{EXP}\n        \\index{EXP (function)}\\codeline{Y \\textbf{= EXP(}X\\textbf{)}}\\par\n        Returns exponential of \\code{X}, i.e. $e^X$.\n    \\subsection{FIX}\n        \\index{FIX (function)}\\codeline{Y \\textbf{= FIX(}X\\textbf{)}}\\par\n        Returns integer value of \\code{X}, truncated towards zero.\n    \\subsection{FLOOR, INT}\n        \\index{FLOOR (function)}\\codeline{Y \\textbf{= FLOOR(}X\\textbf{)}}\n        \\index{INT (function)}\\codeline{Y \\textbf{= INT(}X\\textbf{)}}\\par\n        Returns integer value of \\code{X}, truncated towards negative infinity.\n    \\subsection{LEN}\n        \\index{LEN (function)}\\codeline{Y \\textbf{= LEN(}X\\textbf{)}}\\par\n        Returns length of \\code{X}. \\code{X} can be either a string or an array.\n    \\subsection{LOG}\n        \\index{LOG (function)}\\codeline{Y \\textbf{= LOG(}X\\textbf{)}}\\par\n        Returns natural logarithm of \\code{X}.\n    \\subsection{ROUND}\n        \\index{ROUND (function)}\\codeline{Y \\textbf{= ROUND(}X\\textbf{)}}\\par\n        Returns closest integer value of \\code{X}, rounding towards positive infinity.\n    \\subsection{RND}\n        \\index{RND (function)}\\codeline{Y \\textbf{= RND(}X\\textbf{)}}\\par\n        Returns a random number within the range of $[0..1)$. If \\code{X} is zero, previous random number will be returned; otherwise new random number will be returned.\n    \\subsection{SIN}\n        \\index{SIN (function)}\\codeline{Y \\textbf{= SIN(}X\\textbf{)}}\\par\n        Returns sine of \\code{X}.\n    \\subsection{SINH}\n        \\index{SINH (function)}\\codeline{Y \\textbf{= SINH(}X\\textbf{)}}\\par\n        Returns hyperbolic sine of \\code{X}.\n    \\subsection{SGN}\n        \\index{SGN (function)}\\codeline{Y \\textbf{= SGN(}X\\textbf{)}}\\par\n        Returns sign of \\code{X}: 1 for positive, -1 for negative, 0 otherwise.\n    \\subsection{SQR}\n        \\index{SQR (function)}\\codeline{Y \\textbf{= SQR(}X\\textbf{)}}\\par\n        Returns square root of \\code{X}.\n    \\subsection{TAN}\n        \\index{TAN (function)}\\codeline{Y \\textbf{= TAN(}X\\textbf{)}}\\par\n        Returns tangent of \\code{X}.\n    \\subsection{TANH}\n        \\index{TANH (function)}\\codeline{Y \\textbf{= TANH(}X\\textbf{)}}\\par\n        Returns hyperbolic tangent of \\code{X}.\n    \\subsection{TEST}\n        \\index{TEST (function)}\\codeline{Y \\textbf{= TEST(}X\\textbf{)}}\\par\n        Tests if the value is truthy or not. If the value must be interpreted as \\code{TRUE} for the if-statement, said value is \\emph{truthy}.\n\n\\section{Input}\n\n    \\subsection{CIN}\n        \\index{CIN (function)}\\codeline{S \\textbf{= CIN()}}\\par\n        Waits for the user input and returns it.\n    \\subsection{DATA}\n        \\index{DATA (function)}\\codeline{\\textbf{DATA} CONST0 [\\textbf{,} CONST1]\\ldots}\\par\n        Adds data that can be read by \\code{READ} function. \\code{DATA} declarations need not be reacheable in the program flow.\n    \\subsection{DGET}\n        \\index{DGET (function)}\\codeline{S \\textbf{= DGET()}}\\par\n        Fetches a data declared from \\code{DATA} statements and returns it, incrementing the \\code{DATA} position.\n    \\subsection{DIM}\n        \\index{DIM (function)}\\codeline{Y \\textbf{= DIM(}X\\textbf{)}}\\par\n        Returns array with size of \\code{X}, all filled with zero.\n    \\subsection{GETKEYSDOWN}\n        \\index{GETKEYSDOWN (function)}\\codeline{K \\textbf{= GETKEYSDOWN()}}\\par\n        Stores array that contains keycode of keys held down into the given variable.\\par\n        Actual keycode and the array length depends on the machine: in \\thismachine , array length will be fixed to 8. For the list of available keycodes, see \\ref{implementation}.\n    \\subsection{INPUT}\n        \\index{INPUT (function)}\\codeline{\\textbf{INPUT} VARIABLE}\\par\n        Prints out \\code{? } to the console and waits for user input. Input can be any length and terminated with the return key. The input will be stored in the given variable.\\par\n        This behaviour is to keep compatibility with the traditional BASIC. For function-like usage, use \\code{CIN} instead.\n    \\subsection{READ}\n        \\index{READ (function)}\\codeline{\\textbf{READ} VARIABLE}\\par\n        Assigns data declared from \\code{DATA} statements to given variable. Reading starts at the current \\code{DATA} position, and the data position will be incremented by one. The position is reset to the zero by the \\code{RUN} command.\\par\n        This behaviour is to keep the compatibility with the traditional BASIC. For function-like usage, use \\code{DGET} instead.\n        \n\\section{Output}\n\n    \\subsection{EMIT}\n        \\index{EMIT (function)}\\codeline{\\textbf{EMIT(} EXPR [\\{\\textbf{,}|\\textbf{;}\\} EXPR]\\ldots\\ \\textbf{)}}\\par\n        Prints out characters corresponding to given number on the code page being used. For the code page itself, see \\ref{codepage}.\\par\n        \\code{EXPR} is numeric expression.\n    \\subsection{PRINT}\n        \\index{PRINT (function)}\\codeline{\\textbf{PRINT(} EXPR [\\{\\textbf{,}|\\textbf{;}\\} EXPR]\\ldots\\ \\textbf{)}}\\par\n        Prints out given string expressions.\\par\n        \\code{EXPR} is a string, numeric expression, or array.\\par\n        \\code{PRINT} is one of the few function that differentiates two style of argument separator: \\codebf{;} will simply concatenate two expressions (unlike traditional BASIC, numbers will not have surrounding spaces), \\codebf{,} tabulates the expressions.\n\n\\section{Program Manipulation}\n\n    \\subsection{CLEAR}\n        \\index{CLEAR (function)}\\codeline{\\textbf{CLEAR}}\\par\n        Clears all declared variables.\n    \\subsection{END}\n        \\index{END (function)}\\codeline{\\textbf{END}}\\par\n        Stops program execution and returns control to the user.\n    \\subsection{FOR}\n        \\index{FOR (function)}\\codeline{\\textbf{FOR} LOOPVAR \\textbf{=} START \\textbf{TO} STOP [\\textbf{STEP} STEP]}\n        \\codeline{\\textbf{FOR} LOOPVAR \\textbf{=} GENERATOR}\\par\n        Starts a FOR--NEXT loop.\\par\n        Initially, \\code{LOOPVAR} is set to \\code{START} then statements between the \\code{FOR} statement and corresponding \\code{NEXT} statements are executed and \\code{LOOPVAR} is incremented by \\code{STEP}, or by 1 if \\code{STEP} is not specified. The program flow will continue to loop around until \\code{LOOPVAR} is outside the range of \\code{START}--\\code{STOP}. The value of the \\code{LOOPVAR} is equal to \\code{STOP}$+$\\code{STEP} when the looping finishes.\n    \\subsection{FOREACH}\n        \\index{FOREACH (function)}\\codeline{\\textbf{FOREACH} LOOPVAR \\textbf{IN} ARRAY}\\par\n        Same as \\code{FOR} but fetches \\code{LOOPVAR} from given \\code{ARRAY}.\n    \\subsection{GOSUB}\n        \\index{GOSUB (function)}\\codeline{\\textbf{GOSUB} LINENUM}\\par\n        Jumps to a subroutine at \\code{LINENUM}. The next \\code{RETURN} statements makes program flow to jump back to the statement after the \\code{GOSUB}.\\par\n        \\code{LINENUM} can be either a numeric expression or a Label.\n    \\subsection{GOTO}\n        \\index{GOTO (function)}\\codeline{\\textbf{GOTO} LINENUM}\\par\n        Jumps to \\code{LINENUM}.\\par\n        \\code{LINENUM} can be either a numeric expression or a Label.\n    \\subsection{LABEL}\n        \\index{LABEL (function)}\\codeline{\\textbf{LABEL} NAME}\\par\n        Puts a name onto the line number where the statement is located.\n        \\subsubsection*{Notes}\n        \\begin{itemlist}\n        \\item \\code{NAME} must be a valid variable name.\n        \\end{itemlist}\n    \\subsection{NEXT}\n        \\index{NEXT (function)}\\codeline{\\textbf{NEXT}}\\par\n        Iterates FOR--NEXT loop and increments the loop variable from the most recent \\code{FOR} statement and jumps to that statement.\n    \\subsection{RESTORE}\n        \\index{RESTORE (function)}\\codeline{\\textbf{RESTORE}}\\par\n        Resets the \\code{DATA} pointer.\n    \\subsection{RETURN}\n        \\index{RETURN (function)}\\codeline{\\textbf{RETURN}}\\par\n        Returns from the \\code{GOSUB} statement.\n\n\\section{String Manipulation}\n\n    \\subsection{CHR}\n        \\index{CHR (function)}\\codeline{CHAR \\textbf{= CHR(}X\\textbf{)}}\\par\n        Returns the character with code point of \\code{X}. Code point is a numeric expression in the range of $[0-255]$.\n    \\subsection{LEFT}\n        \\index{LEFT (function)}\\codeline{SUBSTR \\textbf{= LEFT(} STR \\textbf{,} NUM\\_CHARS \\textbf{)}}\\par\n        Returns the leftmost \\code{NUM\\_CHARS} characters of \\code{STR}.\n    \\subsection{MID}\n        \\index{MID (function)}\\codeline{SUBSTR \\textbf{= MID(} STR \\textbf{,} POSITION \\textbf{,} LENGTH \\textbf{)}}\\par\n        Returns a substring of \\code{STR} starting at \\code{POSITION} with specified \\code{LENGTH}.\\par\n        When \\code{OPTIONBASE 1} is specified, the position starts from 1; otherwise it will start from 0. \n    \\subsection{RIGHT}\n        \\index{RIGHT (function)}\\codeline{SUBSTR \\textbf{= RIGHT(} STR \\textbf{,} NUM\\_CHARS \\textbf{)}}\\par\n        Returns the rightmost \\code{NUM\\_CHARS} characters of \\code{STR}.\n    \\subsection{SPC}\n        \\index{SPC (function)}\\codeline{STR \\textbf{= SPC(} STR \\textbf{,} NUM\\_CHARS \\textbf{)}}\\par\n        Returns a string of \\code{NUM\\_CHARS} spaces.\n\n\\section{Array Manipulation}\n        \n    \\subsection{HEAD}\n        \\index{HEAD (function)}\\codeline{K \\textbf{= HEAD(}X\\textbf{)}}\\par\n        Returns the head element of the array \\code{X}.\n    \\subsection{INIT}\n        \\index{INIT (function)}\\codeline{K \\textbf{= INIT(}X\\textbf{)}}\\par\n        Constructs the new array from array \\code{X} that has its last element removed.\n    \\subsection{LAST}\n        \\index{LAST (function)}\\codeline{K \\textbf{= LAST(}X\\textbf{)}}\\par\n        Returns the last element of the array \\code{X}.\n    \\subsection{TAIL}\n        \\index{TAIL (function)}\\codeline{K \\textbf{= TAIL(}X\\textbf{)}}\\par\n        Constructs the new array from array \\code{X} that has its head element removed.\n\n\\section{Monad Manipulation}\n\n    \\subsection{MJOIN}\n        \\index{MJOIN (function)}\\codeline{K \\textbf{= MJOIN(}M\\textbf{)}}\\par\n        Returns the inner value of the given monad.\n    \\subsection{MRET}\n        \\index{MRET (function)}\\codeline{M \\textbf{= MRET(}X\\textbf{)}}\\par\n        Returns a value-monad that contains a given value.\n        \n\\section{Graphics}\n\n    \\subsection{CLPX}\n        \\index{CLPX (function)}\\codeline{\\textbf{CLPX}}\\par\n        Clears plotted pixels.\n    \\subsection{CLS}\n        \\index{CLS (function)}\\codeline{\\textbf{CLS}}\\par\n        Clears text view and moves text cursor to top-left.\n    \\subsection{GOTOYX}\n        \\index{GOTOYX (function)}\\codeline{\\textbf{GOTOYX(} ROW \\textbf{,} COLUMN \\textbf{)}}\\par\n        Moves text cursor to given row and column.\\par\n        When \\code{OPTIONBASE 1} is specified, first row and column will be 1, otherwise it will be 0.\n    \\subsection{PLOT}\n        \\index{PLOT (function)}\\codeline{\\textbf{PLOT(} X\\_POS \\textbf{,} Y\\_POS \\textbf{,} COLOUR \\textbf{)}}\\par\n        Plots a pixel to the framebuffer of the display, at XY-position of \\code{X\\_POS} and \\code{Y\\_POS}, with colour of \\code{COLOUR}. For the available colours, see \\ref{colourpalette}\\par\n        Top-left corner of the pixel will be 1 if \\code{OPTIONBASE 1} is specified, otherwise it will be 0.\n\n\\section{Meta}\n\n    \\subsection{OPTIONBASE}\n        \\index{OPTIONBASE (function)}\\codeline{\\textbf{OPTIONBASE} \\{\\textbf{0}|\\textbf{1}\\}}\\par\n        Specifies at which number the array/string/pixel indices begin.\n    \\subsection{OPTIONDEBUG}\n        \\index{OPTIONDEBUG (function)}\\codeline{\\textbf{OPTIONDEBUG} \\{\\textbf{0}|\\textbf{1}\\}}\\par\n        Specifies whether or not the debugging messages should be printed out. The messages will be printed out to the \\emph{serial debugging console}, or to the stdout.\\par\n        {\\LARGE Big Warning Sign:} Do not turn debug mode on unless you know what you're doing; debug mode will severely slow down the interpreter and literally gigabytes of log messages will pile up in a minute or two of the execution.\n    \\subsection{OPTIONTRACE}\n        \\index{OPTIONTRACE (function)}\\codeline{\\textbf{OPTIONTRACE} \\{\\textbf{0}|\\textbf{1}\\}}\\par\n        Specifies whether or not the line numbers should be printed out. The messages will be printed out to the \\emph{serial debugging console}, or to the stdout.\n    \\subsection{TYPEOF}\n        \\index{TYPEOF (function)}\\codeline{X \\textbf{= TYPEOF(} VALUE \\textbf{)}}\\par\n        Returns a type of given value.\\par\n        \\begin{longtable}{*{2}{m{\\textwidth}}}\\hline\n        \\endfirsthead\n        \\endhead\n\n        \\endfoot\n        \\hline\n        \\endlastfoot\n        \\centering\n        \\begin{tabulary}{\\textwidth}{rl}\n        BASIC Type & Returned Value \\\\\n        \\hline\n        Number & \\ttfamily{num} \\\\\n        Boolean & \\ttfamily{bool} \\\\\n        String & \\ttfamily{str} \\\\\n        Array & \\ttfamily{array} \\\\\n        \\end{tabulary}\n        \\begin{tabulary}{\\textwidth}{rl}\n        BASIC Type & Returned Value \\\\\n        \\hline\n        Generator & \\ttfamily{generator} \\\\\n        User Function & \\ttfamily{usrdefun} \\\\\n        Monad & \\ttfamily{<subtype>-monad} \\\\\n        \\ & \\ \\\\\n        \\end{tabulary}\n        \\end{longtable}\n    \n\\section{System}\n\n    \\subsection{PEEK}\n        \\index{PEEK (function)}\\codeline{BYTE \\textbf{= PEEK(} MEM\\_ADDR \\textbf{)}}\\par\n        Returns whatever the value stored in the \\code{MEM\\_ADDR} of the Scratchpad- or Machine Memory.\\par\n        Address mirroring, illegal access, etc. are entirely up to the virtual machine which the BASIC interpreter is running on.\\par\n        For Machine Memory addresses, see \\ref{mmio}.\n    \\subsection{POKE}\n        \\index{POKE (function)}\\codeline{\\textbf{POKE(} MEM\\_ADDR \\textbf{,} BYTE \\textbf{)}}\\par\n        Puts a \\code{BYTE} into the \\code{MEM\\_ADDR} of the Scratchpad- or Machine Memory.\n\n\\section{Higher-order Function}\n\n    \\subsection{DO}\n        \\index{DO (function)}\\codeline{\\textbf{DO(} EXPR0 [\\textbf{;} EXPR1]\\ldots\\ \\textbf{)}}\\par\n        Executes \\code{EXPRn}s sequentially.\n    \\subsection{FILTER}\n        \\index{FILTER (function)}\\codeline{NEWLIST \\textbf{= FILTER(} FUNCTION \\textbf{,} FUNCTOR \\textbf{)}}\\par\n        Returns an array of values from the \\code{FUNCTOR} that passes the given function. i.e. values that makes \\code{FUNCTION(VALUE\\_FROM\\_FUNCTOR)} true.\n        \\subsubsection*{Parameters}\n        \\begin{itemlist}\n        \\item \\code{FUNCTION} is a user-defined or builtin function with single parameter.\n        \\item \\code{FUNCTOR} is either an array or a generator.\n        \\end{itemlist}\n    \\subsection{FOLD}\n        \\index{FOLD (function)}\\codeline{NEWVALUE \\textbf{= FOLD(} FUNCTION \\textbf{,} INIT\\_VALUE \\textbf{,} FUNCTOR \\textbf{)}}\\par\n        Iteratively applies given function with accumulator and the value from the \\code{FUNCTOR}, returning the final accumulator. Accumulator will be set to \\code{INIT\\_VALUE} before iterating over the functor. In the first execution, the accumulator will be set to \\code{ACC=FUNCTION(ACC,FUNCTOR(0))}, and the execution will continue to remaining values within the functor until all values are consumed. The \\code{FUNCTOR} will not be modified after the execution.\n        \\subsubsection*{Parameters}\n        \\begin{itemlist}\n        \\item \\code{FUNCTION} is a user-defined function with two parameters: first parameter being accumulator and second being a value.\n        \\end{itemlist}\n    \\subsection{MAP}\n        \\index{MAP (function)}\\codeline{NEWLIST \\textbf{= MAP(} FUNCTION \\textbf{,} FUNCTOR \\textbf{)}}\\par\n        Applies given function onto the every element in the functor, and returns an array that contains such items. i.e. returns tranformation of \\code{FUNCTOR} of which the transformation is \\code{FUNCTION}. The \\code{FUNCTOR} will not be modified after the execution.\n        \\subsubsection*{Parameters}\n        \\begin{itemlist}\n        \\item \\code{FUNCTION} is a user-defined or builtin function with single parameter.\n        \\end{itemlist}\n", "meta": {"hexsha": "90a49858499d19d3e20d150861e198fd46e7a847", "size": 17372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/functions.tex", "max_stars_repo_name": "curioustorvald/TerranBASIC", "max_stars_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-03T02:33:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-03T02:33:52.000Z", "max_issues_repo_path": "src/doc/functions.tex", "max_issues_repo_name": "curioustorvald/TerranBASIC", "max_issues_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-25T23:39:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-25T23:39:15.000Z", "max_forks_repo_path": "src/doc/functions.tex", "max_forks_repo_name": "curioustorvald/TerranBASIC", "max_forks_repo_head_hexsha": "837b5fb4ea967b772b62a3a0d3b70759d7782503", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.0884353741, "max_line_length": 467, "alphanum_fraction": 0.669813493, "num_tokens": 5127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7874873292113295}}
{"text": "% declare document class and geometry\n\\documentclass[12pt]{article} % use larger type; default would be 10pt\n\\usepackage[margin=1in]{geometry} % handle page geometry\n\n% import packages and commands\n\\input{../header.tex}\n\n\n\\title{Phys 220A -- Classical Mechanics -- HW01}\n\\author{UCLA, Fall 2014}\n\\date{\\formatdate{09}{10}{2014}} % Activate to display a given date or no date (if empty),\n         % otherwise the current date is printed \n\n\\begin{document}\n\\maketitle\n\n\n\\section*{Problem 1: Math recap (15 pts)}\n\\begin{description}\n\n\\item[(a)]\n\\textit{\nShow that\n\\begin{equation}\n(\\v{a} \\times \\v{b} ) \\times \\v{c} = (\\v{a} \\cdot \\v{c}) \\v{b} - (\\v{b} \\cdot \\v{c}) \\v{a}.\n\\end{equation}\n}\n\n\n\\item[(b)]\n\\textit{\nSpherical coordinates $r, \\theta, \\phi$ are defined as \n\\begin{equation}\nx = r \\sin\\theta \\cos\\phi, \\qquad y = r \\sin\\theta \\sin\\phi, \\qquad z = r \\cos\\theta.\n\\end{equation}\nExpress the cartesian differential operators \n\\begin{equation}\n\\v{\\nabla} = (\\pd_x, \\pd_y, \\pd_z), \\qquad \\v{\\nabla}^2 = \\pd_x^2 + \\pd_y^2 + \\pd_z^2\n\\end{equation}\nin spherical coordinates. \n}\n\n\n\\item[(c)]\n\\textit{\nShow the following identities:\n\\begin{align}\n\\v{\\nabla} \\times (\\v{\\nabla} f(\\v{x})) &= 0, \\text{ and} \\\\\n\\v{\\nabla} \\cdot (\\v{\\nabla} \\times \\v{a}) &= 0.\n\\end{align}\n}\n\n\n\\end{description}\n\n\n\n\\section*{Problem 2: Conservation is important in a drought! (15 pts)}\n\n\\begin{description}\n\n\\item[(a)]\n\\textit{\nShow that in an isolated system of $n$ point masses $m_i$ (no external forces), the momentum $\\v{p}_\\text{tot} = \\sum_{i=1}^n \\v{p}_i$ is conserved. \n}\n\n\n\\item[(b)]\n\\textit{\nShow that in an isolated system of $n$ point masses $m_i$ (no external forces) the total angular momentum $\\v{L}_\\text{tot} = \\sum_{i=1}^n \\v{r}_i \\times \\v{p}_i$ is conserved. \n}\n\n\n\\item[(c)]\n\\textit{\nWhat about the total energy of such an isolated system. Is it necessarily conserved? \n}\n\n\n\\end{description}\n\n\n\n\\section*{Problem 3: Work, work work (15 pts)}\n\n\\textit{\nCheck whether the following forces are conservative by calculating\n\\begin{equation}\nW_{if} = \\int_{i \\rightarrow f} d\\v{x} \\cdot \\v{F}\n\\end{equation}\nfor two different paths. (If you believe the force is non-conservative try to find a path which makes this clear.) \n}\n\n\\begin{description}\n\n\\item[(a)]\n\\textit{\nFor a central force $\\v{F} = r^2 \\uv{r}$.\n}\n\n\n\\item[(b)]\n\\textit{\nFor the Lorentz force $\\v{F} = -e\\v{v} \\times \\v{B}$ with a constant magnetic field $\\v{B}$. \n}\n\n\n\\item[(c)]\n\\textit{\nFor a friction force $\\v{F} = -b\\v{v}$.\n}\n\n\n\\end{description}\n\n\n\\section*{Problem 4: Central motion (30 pts)}\n\\textit{\nA planet of mass $m$ is moving around a Sun of mass $M$ subject to Newtonian gravitational force. \n}\n\n\\begin{description}\n\n\\item[(a)]\n\\textit{\nWrite down the Newtonian equation of motion for the planet and the sun, and show that they can be separated into a free motion of the center of mass and a motion in the central potential of a mass point with reduced mass $\\mu$.\n}\n\n\n\\item[(b)]\n\\textit{\nShow that conservation of angular momentum implies that the motion of the mass point lies in a plane with coordinates $\\rho, \\phi$.\n}\n\n\n\\item[(c)]\n\\textit{\nUse the substitution $u = 1 / \\rho$ to write down a differential equation for the trajectory $u = u(\\phi)$.\n}\n\n\n\\item[(d)]\n\\textit{\nWhat is the equilibrium solution of this equation? What does it represent?\n}\n\n\n\\item[(e)]\n\\textit{\nIf the planet is not initially on the equilibrium orbit, there will be small oscillations around the equilibrium point. What is the period of these oscillations?\n}\n\n\n\\item[(f)]\n\\textit{\nAssume there is a perturbing potential $V = -B / \\rho^2$, calculate the effect of this perturbation on the orbit $u(\\phi)$.\n}\n\n\n\\end{description}\n\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "b258275f5fcc0b9e8915b9e95d97b9a818cd7293", "size": 3694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "classical/hw01.tex", "max_stars_repo_name": "paulinearriaga/phys-ucla", "max_stars_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "classical/hw01.tex", "max_issues_repo_name": "paulinearriaga/phys-ucla", "max_issues_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "classical/hw01.tex", "max_forks_repo_name": "paulinearriaga/phys-ucla", "max_forks_repo_head_hexsha": "48084dbbac2f8a4748c1fdaaf63a4cebaae16809", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 22.119760479, "max_line_length": 227, "alphanum_fraction": 0.6829994586, "num_tokens": 1171, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8991213786215104, "lm_q1q2_score": 0.7874388043943175}}
{"text": "\\subsection{Network Operations}\n\n\\subsubsection*{Convolutional Layer}\n\nThe output of an convolutional layer is defined by\n\\begin{equation}\n   z(i,j) = (f*g)(i,j) = \\sum_{m=-\\infty}^{\\infty} \\sum_{n=-\\infty}^{\\infty} f(m,n) g(m-i,n-j)\n\\end{equation}\n\nIt is explained in more detail here: \\cite{dumoulin2016guide}\n\n\\subsubsection*{Pooling Layer}\n\n\n\n\\subsubsection*{Fully Connected Layer}\n\nThe output of an fully connected layer is defined by\n\\begin{equation}\n\tz = xW + b\n\\end{equation}\nwhere $x \\in \\mathbb{R}^{b,m}$,  $W \\in \\mathbb{R}^{m,n}$ and $b \\in \\mathbb{R}^{n}$. \n\n\\subsubsection*{Rectified Linear Unit (ReLU)}\n\n\\begin{equation}\n\tf(x) = \\begin{cases}\n\t\tx \\quad \\text{if} \\quad x > 0 \\\\\n\t\t0 \\quad \\text{else}\n\t\\end{cases}\n\\end{equation}\n\n\n\\subsubsection*{Softmax}\n\nFor a vector $x \\in \\mathbb{R}^{n}$ the softmax function is defined as\n\\begin{equation}\n\tf_{\\text{Softmax}}: f(x) = \\frac{\\exp{x_i}}{\\sum_i^n \\exp{x_i}}\n\\end{equation}", "meta": {"hexsha": "c0d5930275b7f33a40af599d0d3a9f0c1efb0122", "size": 938, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/documentation/09_nnmath.tex", "max_stars_repo_name": "marbleton/FPGA_MNIST", "max_stars_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2019-11-13T12:24:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-31T02:39:35.000Z", "max_issues_repo_path": "tex/documentation/09_nnmath.tex", "max_issues_repo_name": "marbleton/FPGA_MNIST", "max_issues_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 29, "max_issues_repo_issues_event_min_datetime": "2019-12-17T22:06:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-12T00:20:45.000Z", "max_forks_repo_path": "tex/documentation/09_nnmath.tex", "max_forks_repo_name": "marbleton/FPGA_MNIST", "max_forks_repo_head_hexsha": "4b4a30e0adca35de9adcad7b3fec08c516260790", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2019-10-20T15:12:52.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-13T13:36:37.000Z", "avg_line_length": 24.0512820513, "max_line_length": 94, "alphanum_fraction": 0.6727078891, "num_tokens": 341, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9658995742876885, "lm_q2_score": 0.8152324938410783, "lm_q1q2_score": 0.7874327187465882}}
{"text": "\\section{Plant Model}\n\\label{chap:Vehicle_model}\nThe starting point for Model-Based design is to develop and implement a plant model, a model representing the physics of the system considered.\\\\\nSeveral models are available in literature to model a vehicle. Since the target of the project is to develop a lateral controller, one of the most suitable model is the so called \\textit{Bicycle Model}.\\\\\nThe kinematic bicycle model is described by the following non linear system:\n\\begin{align}\n    \\dot{X} = Vcos(\\psi + \\beta)\\\\\n    \\dot{Y} = Vsin(\\psi + \\beta)\\\\\n    \\dot{\\psi} = \\frac{Vcos(\\beta)}{l_f + l_r}\\left(tan(\\delta_f) - tan(\\delta_r)\\right)\\\\\n    \\beta = tan^{-1}\\left(\\frac{l_ftan(\\delta_r) + l_rtan(\\delta_f)}{l_f + l_r}\\right)\n\\end{align}\nWhere:\n\\begin{itemize}\n    \\item X and Y are the coordinates of the body of the vehicle in the global reference frame;\n    \\item $\\psi$ is the yaw (orientation angle);\n    \\item $\\beta$ is the slip angle of the body;\n    \\item $\\beta + \\psi$ is the body speed direction known as \\textit{Course Angle};\n    \\item $\\delta_f$ is the front steering angle;\n    \\item $\\delta_r$ is the rear steering angle;\n    \\item V is the magnitude of the body speed;\n    \\item $l_f$ is a geometric parameter which indicates the distance of the CoG from the front wheel;\n    \\item $l_r$ is a geometric parameter which indicates the distance of the CoG from the rear wheel.\n\\end{itemize}\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{Figures/Bicycle_model.jpg}\n    \\caption{Bicycle kinematic vehicle model}\n    \\label{fig:Bicycle_kin}\n\\end{figure}\nThis model can be further simplified assuming that, as in most commercial vehicles, only the front wheels are able to steer, so the rear steering angle $\\delta_r$ is constant and equal to 0.\\\\\nStandard MPC controllers work on linear systems, so we have decided to implement a linearized version of the Bicycle Model to feed the controller. This linearized model is described by the following State Space equations:\n\\begin{equation}\n    \\label{equation:dynamic1}\n    \\Dot{x} = Ax + Bu \n\\end{equation}\n\\begin{equation}\n    \\label{equation:dynamic2}\n    y = Cx + Du \n\\end{equation}\nwhere:\n\n\\begin{equation}\n\\label{equation:sys_bicycle_kin}\n   \\begin{aligned}\n    x = \n        \\begin{bmatrix} % STATES\n        X \\\\ \n        Y \\\\\n        \\psi \\\\\n        v \\\\\n        \\end{bmatrix}\\quad\n    A =\n        \\begin{bmatrix} % MATRIX A\n       0 & 0 & -Vsin(\\psi) & cos(\\psi)\\\\ \n       0 & 0 & Vcos(\\psi) & sin(\\psi) \\\\\n       0 & 0 & 0 & \\frac{tan(\\delta)}{l_r + l_f}\\\\\n       0 & 0 & 0 & 0 \\\\\n        \\end{bmatrix}\\quad\n    B = \n        \\begin{bmatrix} % MATRIX B\n        0 & 0\\\\ \n        0 & 0 \\\\\n        0 & \\frac{Vtan(\\delta)^2 + 1}{l_r + l_f}\\\\\n        1 & 0 \\\\\n        \\end{bmatrix}\\\\[10pt]\n    u =\n        \\begin{bmatrix} % INPUTS\n        Throttle \\\\\n        \\delta \\\\\n        \\end{bmatrix}\\quad\\quad\\quad\n    C = I^{4\\times 4}\\quad\\quad\\quad\\quad\\quad\n    D =\n        \\begin{bmatrix} % MATRIX A\n      0 & 0 & 0 & 0\\\\\n      0 & 0 & 0 & 0\\\\\n        \\end{bmatrix}\n    \\end{aligned}\n\\end{equation} \n\nThese matrices are obtained evaluating the Taylor expansion of the non linear bicycle model, as explained in the MathWorks example \\cite{StaticObs}.\\\\\nA more complex vehicle model can be useful to test the performance of the controller to be developed. The \\textit{Dynamic Bicycle Model} \\cite{7225830} can be built starting from the previous non linear model, deriving the following second order derivative equations:\n\\begin{align}\n    \\ddot{x} = \\dot{\\psi}\\dot{y} + Throttle\\\\\n    \\ddot{y} = -\\dot{\\psi}\\dot{x} + \\frac{2}{m}\\left(F_fcos(\\delta) + F_r\\right)     \\label{dynamic_equation}\\\\\n    \\ddot{\\psi} = \\frac{2}{I_z}\\left(l_fF_f - l_rF_r\\right)\\\\\n    \\dot{X} = \\dot{x}cos(\\psi) - \\dot{y}sin(\\psi)\\\\\n    \\dot{Y} = \\dot{x}sin(\\psi) + \\dot{y}cos(\\psi)\n\\end{align}\nwhere $m$ is the mass of the vehicle, $I_z$ is the inertia of the vehicle with respect to the vertical axle passing for the CoG of it, while $F_f$ and $F_r$ are respectively the side slip forces acting on the front and rear wheels, and they can be evaluated as:\n\\begin{align}\n    F_f = 2C_f\\left(\\delta - \\theta_f\\right)\\\\\n    F_r = 2C_r\\left(-\\theta_r\\right)\n\\end{align}\nwith $C_i$ side slip friction coefficient of the i-th wheel couple and $\\theta_i$ side slip angle of the wheels.\\\\\nTyre side slip angles can be approximated by the following equations:\n\\begin{equation}\n    \\theta_f=tan^{-1}\\left(\\frac{\\dot{y} + l_f\\dot{\\psi}}{\\dot{x}}\\right)\n\\end{equation}\n\\begin{equation}\n    \\theta_r=tan^{-1}\\left(\\frac{\\dot{y} - l_r\\dot{\\psi}}{\\dot{x}}\\right)\n\\end{equation}\nThe models introduced are, more or less, independent of the longitudinal dynamics of the vehicle, since they link it to a simple coefficient, that is the $Throttle$. In our model, this coefficient is considered as an acceleration, hence it can be both positive (driving) or negative (braking). The range of values for this parameter is dependent on lots of variables, such as the engine power, the vehicle mass and inertia, the ground type, the rubber of the wheels and so on. Our assumption is to give a fixed interval of feasible values for this parameter, to simulate a small commercial vehicle on dry asphalt, with a maximum acceleration of 4 $m/s^2$ and a maximum braking deceleration of -0.8 $g$. To summarize:\n\\begin{itemize}\n    \\item $Throttle \\in [-7.85, 4.00]$ $m/s^2$\n    \\label{item:Throttle}\n\\end{itemize}\nThe parameters considered for the bicycle model are taken from real vehicle data \\cite{10.2307/44733900} and are reported in the following table:\n\n\\begin{table}[H]\n\\resizebox{\\textwidth}{!}{%\n\\begin{tabular}{|l|l|r|r|r|r|r|}\n\\hline\n\\textbf{ID} &\n  \\textbf{Vehicle name} &\n  \\multicolumn{1}{l|}{\\textbf{Wheel base {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{l\\_r {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{l\\_f {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{Mass {[}$kg${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{Inertia {[}$kg \\cdot m^2${]}}} \\\\ \\hline\n1 & \\textit{Hyundai Azera}    & 2.843 & 1.738 & 1.105 & 1200 & 1000 \\\\ \\hline\n2 & \\textit{BMW 325i}          & 2.570 & 1.369 & 1.201 & 1251 & 2027 \\\\ \\hline\n3 & \\textit{Ford E150}        & 3.505 & 1.634 & 1.871 & 2995 & 6536 \\\\ \\hline\n4 & \\textit{Suzuki Samurai}    & 2.032 & 0.870 & 1.162 & 1229 & 1341 \\\\ \\hline\n5 & \\textit{Volkswagen Beetle} & 2.408 & 0.996 & 1.412 & 857  & 1289 \\\\ \\hline\n\\end{tabular}%\n}\n\\caption{Vehicle data considered for development and validation}\n\\label{tab:vehicle_data}\n\\end{table}\nValues reported in Table \\ref{tab:vehicle_data} are stored in a MATLAB file and can be accessed through the \\textit{loadParameters} function, which takes as input the vehicle ID and returns the parameters associated with that vehicle. To avoid calling  this function improperly, a default set of parameters has been provided with the following values:\n\\begin{table}[H]\n\\resizebox{\\textwidth}{!}{\n\\begin{tabular}{|l|r|r|r|r|r|}\n\\hline\n\\textbf{Vehicle name} &\n  \\multicolumn{1}{l|}{\\textbf{Wheel base {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{l\\_r {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{l\\_f {[}$m${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{Mass {[}$kg${]}}} &\n  \\multicolumn{1}{l|}{\\textbf{Inertia {[}$kg \\cdot m^2${]}}} \\\\ \\hline\n\\textit{Default}    & 2 & 1 & 1 & 1000 & 1000 \\\\ \\hline\n\\end{tabular}\n}\n\\end{table}\nFor the development phase, we have used the set of data from Vehicle 1 ( \\textit{Hyundai Azera}), where the mass and inertia given, represent realistic values for the vehicle and not the real values. The other data contained in Table \\ref{tab:vehicle_data}, instead, are meant to be used during the validation phase in order to test the controller with different vehicles.\nFor what concerns the side slip friction coefficient values, we have considered two fixed values common to all the vehicles:\n\\begin{itemize}\n    \\item $C_f$ $=$ $1.0745\\times10^5$ $N/rad$\n    \\item $C_r$ $=$ $1.9032\\times10^5$ $N/rad$\n\\end{itemize}\nwhile in the \\textit{``Default\"} condition they are both equal to $10^5$ $N/rad$.\n\n\\subsection{Model comparison}\nAs specified in the subsection \\ref{partitioning_subsection} we have decided to use two models, a simplified and linearized model for the MPC and a more complex one for the simulation of the model. The former is defined as \\textit{Kinematic Bicycle Model} and the latter as \\textit{Dynamic Bicycle Model}.\nHence we have decided to test both systems to show how they behave with different throttle and steering inputs using the \\textit{Simulink Test} tool. Thus, the tests performed are:\n\\begin{itemize}\n    \\item \\textbf{Free evolution test}: this test has been performed considering a constant steering of $0^{\\circ}$ and a constant throttle of 0 $m/s^2$;\n    \\item \\textbf{Only throttle test}: this test has been performed keeping the steering angle constant and equal to $0^{\\circ}$ and varying the throttle as shown in Figure \\ref{fig:InputThrottle};\n    \\item \\textbf{Constant steering test}: this test has been performed keeping the throttle constant and equal to 0 $m/s^2$ and the steering angle constant and equal to $2^{\\circ}$;\n    \\item \\textbf{Ramp steering test}: this test has been performed keeping the throttle equal to 0 $m/s^2$ and giving a ramp steering angle signal (varying linearly from $0^{\\circ}$ to $36^{\\circ}$);\n    \\item \\textbf{Small sinusoidal steering test}: this test has been performed keeping the throttle constant and equal to 0 $m/s^2$ and giving a sinusoidal steering angle signal with frequency 0.2 $Hz$ and amplitude $5^{\\circ}$;\n    \\item \\textbf{Big sinusoidal steering test}: here we have performed the same test as before (sinusoidal steering input) but with a larger amplitude of the sine wave ($15^{\\circ}$);\n    \\item \\textbf{Combined test 1}: this test has been performed keeping the steering angle constant and equal to $2^{\\circ}$ and varying the throttle as shown in Figure \\ref{fig:InputThrottle};\n    \\item \\textbf{Combined test 2}: this test has been performed keeping the throttle equal to 0.2 $m/s^2$ and giving a ramp steering angle signal (varying linearly from $0^{\\circ}$ to $36^{\\circ}$).\n\\end{itemize}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.65\\textwidth]{Figures/InputThrottle.png}\n    \\caption{Throttle Input used in \\textit{Only throttle test} and \\textit{Combined test 1} (Maximum and minimum values are coherent with the range described in Section \\ref{item:Throttle} in order to explore the whole set of throttle values)}\n      \\label{fig:InputThrottle}\n\\end{figure}\n\n\n\n\n\n\n\\subsubsection{Simulink Test}\nThe above-mentioned tests have been performed using the \\textit{Simulink Test} tool implemented by MathWorks. Simulink Test provides tools for authoring, managing, and executing systematic, simulation-based tests of models, generated code, and simulated or physical hardware. It includes simulation, baseline, and equivalence test templates that let you perform functional, unit, regression, and back-to-back testing using software-in-the-loop (SIL), processor-in-the-loop (PIL), and real-time hardware-in-the-loop (HIL) modes. With Simulink Test you can create non-intrusive test harnesses to isolate the component under test. You can define requirements-based assessments using a text-based language, and specify test input, expected outputs, and tolerances in a variety of formats. \\cite{SimulinkTest}\n\n\\subsubsection{Results analysis}\n\nExploiting Simulink Test, we have created two test harnesses: \\textit{Dynamic} and \\textit{Kinematic}. Those are referred to the models described at the beginning of this section. Then, we have executed an Equivalence Test which allowed us to make a comparison between two simulations. In particular, the Dynamic Model has been considered as the \\textit{baseline} to which our Kinematic Model has been compared in the test. Being more accurate than the Kinematic model, the baseline represents the expected output, which in turn is called \\textit{Compare to} model inside the Simulink Test automatic report generator\\footnote{The ``Model Comparison - Test Report\" file generated by Simulink Test is included in the /Documentation/Test Reports/ file path.}. \nSince these tests aim to give a qualitative analysis of the two models and compare them, we have not included equivalence criteria.\nThe only parameter we have set up is the relative tolerance assigning to it a value of 1\\% in order to ignore the negligible offsets between the dynamic model and the kinematic model.\\\\\nFigure \\ref{fig:trajectories} shows the results of the simulations we have carried out. \nAs shown in Figures \\ref{subfig:free_evo} and \\ref{subfig:only_throttle} respectively, as expected the two models behave in the same way when no inputs are present or when only the longitudinal input (throttle) is changed. \\\\ Another relevant result is shown in Figures \\ref{subfig:small_sinusoidal} and \\ref{subfig:big_sinusoidal}: as long as the amplitude of the sinusoidal input is fairly small, the two models behave in a similar fashion but the greater the amplitude of the sinusoidal input, the greater the deviation of the kinematic model from the dynamic one.\\\\\nThe other images shown below, underline as well the offset between the two vehicle models, which is due to the fact that when using the dynamic model we take into account lateral slips which are not considered in the kinematic model.\n\n\n\\begin{figure}[H]\n\\centering\n\n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n   \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Free_evo_traj.png}\n    \\caption{Free evolution test - trajectories}\n    \\label{subfig:free_evo}\n    \\end{subfigure}%\n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Throttle_traj.png}\n    \\caption{Only throttle test - trajectories}\n    \\label{subfig:only_throttle}\n    \\end{subfigure}\n    \n    \\vspace{10mm}\n    \n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n   \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Const_steer_traj.png}\n   \\caption{Constant steering test - trajectories}\n   \\label{subfig:const_steer}\n    \\end{subfigure}%\n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Ramp_traj.png}\n    \\caption{Ramp steering test - trajectories}\n    \\label{subfig:ramp_steer}\n    \\end{subfigure}\n    \n     \\vspace{10mm}\n     \n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n   \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Small_sin_traj.png}\n   \\caption{Small sinusoidal test - trajectories}\n   \\label{subfig:small_sinusoidal}\n    \\end{subfigure}%\n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n    \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Big_sin_traj.png}\n    \\caption{Big sinusoidal test - trajectories}\n    \\label{subfig:big_sinusoidal}\n    \\end{subfigure}\n    \n     \\vspace{10mm}\n    \n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n  \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Comb1_traj.png}\n    \\caption{Combined 1 test - trajectories}\n    \\label{subfig:Comb_1}\n    \\end{subfigure}%\n    \\begin{subfigure}{.5\\textwidth}\n    \\centering\n  \\includegraphics[width=0.8\\textwidth,keepaspectratio]{Figures/Comb2_traj.png}\n    \\caption{Combined 2 test - trajectories}\n    \\label{subfig:Comb_2}\n    \\end{subfigure}\n    \n    \\caption{Output trajectories of the test set}\n    \\label{fig:trajectories}\n\\end{figure}\n\\pagebreak\n\n\nAfter the analysis of the results, we have decided to provide the MPC with the linearized bicycle model as the vehicle plant, because the controller is usually updated with the current state in some fractions of a second, and for this reason the differences between the model and the \\textit{``Real World\"} system, that in our case is represented by the dynamic model, shouldn't affect too much the behaviour of the controller itself. As a matter of fact, by looking at the images above it is clear that the difference between the two models output is negligible at the first time steps of the simulation.\\\\\nMoreover, as already discussed in this section, with small inputs the performances of the two models are very similar, and this condition is fulfilled if we consider to use our controller in normal driving scenarios, such as, for instance, a highway.\\\\\nKeeping these assumptions in mind, we have carried on the project, with the possibility of applying a change in the vehicle model for further improvements on the MPC performances.", "meta": {"hexsha": "13622bd914efb37b616566adf2371d767c47db2c", "size": 16501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documentation/Report/Chapters/4-PlantModel.tex", "max_stars_repo_name": "meltinglab/dynamic-obstacle-avoidance", "max_stars_repo_head_hexsha": "2290754436864a817851c71803d5275445cbcdb1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2021-05-24T07:00:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-19T16:44:04.000Z", "max_issues_repo_path": "Documentation/Report/Chapters/4-PlantModel.tex", "max_issues_repo_name": "meltinglab/dynamic-obstacle-avoidance", "max_issues_repo_head_hexsha": "2290754436864a817851c71803d5275445cbcdb1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Documentation/Report/Chapters/4-PlantModel.tex", "max_forks_repo_name": "meltinglab/dynamic-obstacle-avoidance", "max_forks_repo_head_hexsha": "2290754436864a817851c71803d5275445cbcdb1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-04-20T19:24:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T17:58:16.000Z", "avg_line_length": 63.2222222222, "max_line_length": 804, "alphanum_fraction": 0.7210472093, "num_tokens": 4668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465080392795, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7873986758228925}}
{"text": "\\subsection{The Quadratic Formula and Completing the Square}\r\nThe technique of \\dfont{completing the square} allows us to solve quadratic equations and also to determine the center of a circle/ellipse or the vertex of a parabola.\r\n\r\nThe main idea behind completing the square is to turn:\r\n$$ ax^2 + bx + c$$\r\ninto\r\n$$a(x - h)^2 + k.$$\r\nOne way to complete the square is to use the following formula:\r\n$$ax^2+bx+c=a\\left(x+\\frac{b}{2a}\\right)^2-\\frac{b^2}{4a^2}+c.$$\r\nBut this formula is a bit complicated, so some students prefer following the steps outlined in the next example. \\\\\r\n\r\n\\begin{example}{Completing the Square}{CompletingSquare}\r\nSolve $2x^2+12x-32=0$ by completing the square.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nIn this instance, we will \\ifont{not} divide by $2$ first (usually you would) in order to demonstrate what you should do when the `$a$' value is not $1$.\r\n\r\n\\bigskip\r\n\r\n\\begin{tabular}{rl}\r\n$2x^2+12x-32=0$ & Start with original equation.\\\\\r\n\\\\\r\n$2x^2+12x=32$ & Move the number over to the other side.\\\\\r\n\\\\\r\n$2(x^2+6x)=32$ & Factor out the $a$ from the $ax^2+bx$ expression.\\\\\r\n\\\\\r\n$6~~\\to~~\\frac{6}{2}=3~~\\to~~3^2=\\dfont{9}$ & Take the number in front of $x$, \\\\\r\n\t&  \\dfont{divide by $2$}, \\\\\r\n\t&  then \\dfont{square} it.\\\\\r\n\\\\\r\n$\\ifont{2}(x^2+6x+\\dfont{9})=32+\\ifont{2}\\cdot\\dfont{9}$ & Add the result to both sides, \\\\\r\n\t&  taking $a=2$ into account.\\\\\r\n\\\\\r\n$2(x+3)^2=50$ & Factor the resulting perfect square trinomial.\\\\\r\n\\\\\r\n~ & \\ifont{You have now completed the square!}\\\\\r\n\\\\\r\n$(x+3)^2=25~~\\to~~x=2 \\mbox{ or } x=-8$ & To solve for $x$, simply divide by $a=2$ \\\\\r\n\t& and take square roots.\\\\\r\n\\end{tabular}\r\n\\end{solution}\r\n\r\nSuppose we want to solve for $x$ in the quadratic\r\nequation $ax^2+bx+c=0$, where $a\\neq 0$.\r\nThe solution(s) to this equation are given by the \\dfont{quadratic formula}.\\\\\r\n\r\n\\begin{theorem}{The Quadratic Formula}{Quadratic Formula}\r\n\\label{QuadForm}\t \r\nThe solutions to $ax^2+bx+c=0$ (with $a\\neq 0$) are $\\ds{x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}}$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nTo prove the Quadratic Formula (Theorem \\ref{QuadForm} ) we use the technique of \\ifont{completing \r\nthe square}. The general technique involves taking an expression of the \r\nform $x^2+rx$ and trying to find a number we can add so that we end up \r\nwith a perfect square (that is, $(x+n)^2$). It turns out if you add $(r/2)^2$ \r\nthen you can factor it as a perfect square.\r\n\r\nFor example, suppose we want to solve for $x$ in the equation $ax^2+bx+c=0$, where $a\\neq 0$.\r\nThen we can move $c$ to the other side and divide by $a$ (remember, $a\\neq 0$ so we can divide by it) to get\r\n$$x^2+\\frac{b}{a}x=-\\frac{c}{a}.$$\r\nTo write the left side as a perfect square we use what was mentioned previously.\r\nWe have $r=(b/a)$ in this case, so we must add $(r/2)^2=(b/2a)^2$ to both sides\r\n$$x^2+\\frac{b}{a}x+\\left(\\frac{b}{2a}\\right)^2=-\\frac{c}{a}+\\left(\\frac{b}{2a}\\right)^2.$$\r\nWe know that the left side can be factored as a perfect square\r\n$$\\left(x+\\frac{b}{2a}\\right)^2=-\\frac{c}{a}+\\left(\\frac{b}{2a}\\right)^2.$$\r\nThe right side simplifies by using the exponent rules and finding a common denominator\r\n$$\\left(x+\\frac{b}{2a}\\right)^2=\\frac{-4ac+b^2}{4a^2}.$$\r\nTaking the square root we get\r\n$$x+\\frac{b}{2a}=\\pm\\sqrt{\\frac{-4ac+b^2}{4a^2}},$$\r\nwhich can be rearranged as\r\n$$x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}.$$\r\nIn essence, the quadratic formula is just completing the square.\r\n\\end{proof}", "meta": {"hexsha": "b2c9f5334e5e4bb6b220393c7f49d03bcb59129b", "size": 3429, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-3-quadratic-formula.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-3-quadratic-formula.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-3-quadratic-formula.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.72, "max_line_length": 168, "alphanum_fraction": 0.6640419948, "num_tokens": 1193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7873314602166971}}
{"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}{5^n-1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nWe need to find a fixed number $K > 0$ such that \r\n\\[ \\frac{1}{5^n-1} \\leq \\frac{K}{5^n}.\\]\r\nIn our scratch work, by multiplying both sides by $5^n(5^n-1)$, we want the following inequality to be true:\r\n\\[ 5^n \\leq K(5^n - 1) \\]\r\nNow, this inequality is false when $K=1$. However, when $K=2$, this inequality is already true for $n \\geq 1$. (Note when $K=2$ and $n=1$, we are looking at $5 \\leq 8$.\r\n\r\nSo, with that scratch work done, let us begin:\r\n\\[ 5^n \\leq 2(5^n - 1) \\]\r\nis true for all $n \\geq 1$. Then, dividing both sides of this inequality by $5^n(5^n-1)$, we get\r\n\\[ \\frac{1}{5^n-1} \\leq \\frac{2}{5^n}.\\]\r\n\r\nSince \r\n\\[ \\frac{1}{5^n+1} \\leq \\frac{2}{5^n}\\]\r\nand since $\\displaystyle \\sum_{n=1}^\\infty  \\frac{2}{5^n}$ converges by the Geometric Series Test ($r=\\frac15$), the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{5^n+1}$ converges by the Direct Comparison Test.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{5^n-1}$ converges absolutely.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nLet $a_n =  \\frac{1}{5^n-1}$ and $b_n = \\frac{1}{5^n}$. Then\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} \\frac{a_n}{b_n}\r\n&= \\lim_{n \\to \\infty} \\frac{5^n-1}{5^n} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{5^n \\ln 5}{5^n \\ln 5}\\quad\\text{by L'hopital's rule} \\\\\r\n& = \\lim_{n \\to \\infty} 1\\\\\r\n& = 1\r\n\\end{align*}\r\nwhich is a finite positive number. Since the series  $\\displaystyle \\sum_{n=1}^\\infty  \\frac{1}{5^n}$ converges by the Geometric Series Test ($r=\\frac15$), the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{5^n-1}$ converges by the Limit Comparison Test.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{5^n-1}$ converges absolutely.\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": "c07087ab2087dd01e847ddd4c88fe227982cca7b", "size": 2536, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/j2.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/j2.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/j2.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": 39.625, "max_line_length": 257, "alphanum_fraction": 0.6332807571, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770433, "lm_q2_score": 0.9099070017626537, "lm_q1q2_score": 0.7872734508305201}}
{"text": "\\subsection{Real-valued functions}\\label{subsec:real_valued_functions}\n\n\\begin{definition}\\label{def:functions_vanish_nowhere}\n  Let \\( \\mathcal{F} \\) be a family of functions from a set \\( S \\) to a ring \\( R \\). We say that \\( \\mathcal{F} \\) \\term{vanishes nowhere} if for every \\( x \\in S \\) there exists a function \\( f \\in \\mathcal{F} \\) such that \\( f(x) \\neq 0_R \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:epigraph}\n  Let \\( X \\) be an arbitrary set. The \\term{epigraph} of the function \\( f: X \\to \\BbbR \\) is defined as\n  \\begin{equation*}\n    \\epi f \\coloneqq \\{ (x, r) \\in X \\times \\BbbR \\colon r \\geq f(x) \\},\n  \\end{equation*}\n\\end{definition}\n", "meta": {"hexsha": "435a36e5c73a41e4724f7da0066a74e4c92016d1", "size": 665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_valued_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/real_valued_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/real_valued_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": 51.1538461538, "max_line_length": 246, "alphanum_fraction": 0.6586466165, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7872408210484378}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\title{Calculus With Calvin QD. 27}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\nCompute the Integral:\n$$I=\\int\\limits_{0}^{1} \\frac{\\ln (1+x) \\ln (x)}{x} \\: d x$$\n\n\\section{Solution}\nWe know the Series Expansion:\n$$\\ln (1+x)=\\sum_{n=1}^{\\infty} \\frac{(-1)^{n-1} x^{n}}{n}$$\n$$\\Rightarrow I=\\int\\limits_{0}^{1} \\sum_{n=1}^{\\infty} \\frac{(-1)^{n-1} x^{n-1}}{n} \\: \\ln (x) \\: d x$$\n\n$$\\therefore I=\\sum_{n=1}^{\\infty} \\frac{(-1)^{n-1}}{n} \\int\\limits_{0}^{1} x^{n-1} \\ln (x) \\: d x$$\n\nWe know the Formula,\n$$I_{(m, n)}=\\int\\limits_{0}^{1} x^{m} \\ln ^{n}(x) \\: d x=(-1)^{n} \\frac{n !}{(m+1)^{n+1}}$$\n\n[This can be derived using IBP and Recursion] \\\\\n\nComparing $I_{(m, n)}$ with $I$, we have,\n$$m = n-1$$\n$$n = 1$$\n\n$$\\therefore I_{(n-1,1)}=\\frac{(-1)}{n^{2}}$$\n\n$$\\begin{array}{l}\n\\begin{aligned}\n\\Rightarrow \\quad I &=\\sum_{n=1}^{\\infty} \\frac{(-1)^{n-1}}{n} \\times \\frac{(-1)}{n^{2}} \\\\\n&=\\sum_{n=1}^{\\infty} \\frac{(-1)^{n}}{n^{3}}\n\\end{aligned}\n\\end{array}$$\n\nExpanding this, we have:\n\n$$\\begin{aligned}\nI&=-\\frac{1}{1^{3}}+\\frac{1}{2^{3}}-\\frac{1}{3^{3}}+\\frac{1}{4^{3}}-\\ldots \\\\\n&=-\\frac{1}{1^{3}}-\\frac{1}{2^{3}}-\\frac{1}{3^{3}}-\\frac{1}{4^{3}}-\\ldots \n{+2\\left[\\frac{1}{2^{3}}+\\frac{1}{4^{3}}+\\ldots\\right]}\\\\\n&=-\\zeta(3)+\\left(\\frac{1}{2^{3} \\cdot 1^{3}}+\\frac{1}{2^{3} \\cdot 2^{3}}+\\frac{1}{2^{3} \\cdot 3^{3}}+\\ldots\\right) \\\\\n&=-\\zeta(3)+\\frac{1}{4} \\zeta(3) \\\\\n\\end{aligned}$$\n\nThus, the final answer is:\n$$\\boxed{I=-\\frac{3 \\: \\zeta(3)}{4}}$$\n\n\\end{document}\n", "meta": {"hexsha": "a5fafd9da83e4c002e434a9e9f1216801f87a948", "size": 1611, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Calculus_Calvin's Qustions/QD 27 (Aligned Integral).tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Calculus_Calvin's Qustions/QD 27 (Aligned Integral).tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Calculus_Calvin's Qustions/QD 27 (Aligned Integral).tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 28.2631578947, "max_line_length": 118, "alphanum_fraction": 0.5468653011, "num_tokens": 771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765304654121, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7871672371839838}}
{"text": "\\chapter{Set Theory I}\n\n\\epigraph{A set is a Many that allows itself to be thought of as a One.}{\\emph{Georg Cantor}}\n\nWatch the \\href{https://www.khanacademy.org/math/statistics-probability/probability-library/basic-set-ops/v/intersection-and-union-of-sets}{Khan Academy} videos on basic set operations!\n\n\\begin{boxdefine}{Set}{}\n\tA {\\bf set} is a collection of distinct objects. Each object that appears in this collection is called an {\\bf element} of the set.\n\\end{boxdefine}\n\nElements in sets must be well-defined, unordered, and distinct. You may \\emph{describe} sets with duplicate elements, but duplicates do not enlarge the set at all. For example $\\{1,2,3,2\\}=\\{1,2,3\\}$, and the number of elements in $\\{1,2,3,2\\}$ is 3.\n\n\\begin{boxexample}{}{}\n\tHere are a few examples of sets.\n\n\t\\begin{itemize}\n\t\t\\item Known speices of birds\n\t\t\\item Coke brands\n\t\t\\item The numbers 6, 28, 496, and 8128\n\t\\end{itemize}\n\\end{boxexample}\n\n\\section{Describing a Set}\n\nThere are three ways that a set can be described.\n\n\\begin{enumerate}\n\t\\item A written description. For example, ``The set of even negative numbers.''\n\t\\item A list (also called roster method/tabular form). For example, $S = \\{2,3,5,7\\}$.\n\t\\item Set-builder notation (or rule notation). For example, $P = \\{2n+1\\;:\\;n \\in \\mathbb{Z}\\}$.\n\\end{enumerate}\n\n\\section{Set-Builder Notation}\n\nI think the first two are fairly self explanitory, so lets break down builder notation. Consider $P = \\{2n+1\\;:\\;n \\in \\mathbb{Z}\\}$.\n\n\\begin{itemize}\n\t\\item The first term, ``$2n+1$'', defines the elements in the set. Note that $n$ is variable.\n\t\\item The symbol ``$:$'' mean ``such that'', and signals we are doing something with $n$.\n\t\\item The symbol $\\in$ means ``is an element of''. ``$n \\in \\mathbb{Z}$'' means that $n$ is an integer.\n\t\\item $\\mathbb{Z}$ is the symbol for the set of integers ($\\{\\dots,-2,-1,0,1,2,3,\\dots\\}$).\n\\end{itemize}\n\nSo, this reads as ``the set of numbers $2n+1$, where $n$ is an integer.'' This also known as the set of odd numbers. Take your time to understand reading this, you will see this notation a lot.\n\n\\begin{boxnotation*}{}{}\n\tThe such-that symbol ``$:$'' can also be written as ``$|$'' or ``$\\ni$''.\n\\end{boxnotation*}\n\n\\begin{boxexample}{}{}\n\tHere are a few examples of set-builder notation.\n\n\t\\begin{itemize}\n\t\t\\item $S = \\{x \\;:\\; x > 5, x \\in \\mathbb{N}\\}$. This is the set of natural numbers above 5\n\t\t\\item $P = \\{n \\;:\\; \\text{factors}(n) = \\{1,n\\}, 1 < n\\}$. This is the set of prime numbers\n\t\t\\item $F = \\{g \\;:\\; 0\\% \\leq g < 55\\%\\}$. This is the set of where you don't want your final grade to end up\n\t\\end{itemize}\n\\end{boxexample}\n\t\n\\section{Some Common Definitions}\n\nHere are some terms and definitions you might run into. The rational number definition looks scary, but try to understand it piece-by-piece.\n\n\\medskip\n\\begin{tabular}{r|c|l}\n\t\\hline\n\tSymbol & Name & Definition\\\\\n\t\\hline\n\t$\\varnothing$ & Null Set & The set with no elements\\\\\n\t & Singleton Set & A set with one element\\\\\n\t & Finite Set & A set with finite elements\\\\\n\t & Infinite Set & A set with infinite elements\\\\\n\t$\\mathbb{N}$ & Natural Numbers & $\\{1,2,3,\\dots\\}$\\\\\n\t$\\mathbb{W}$ & Whole Numbers & $\\{0,1,2,3,\\dots\\}$\\\\\n\t$\\mathbb{Z}$ & Integers & $\\{\\dots, -2, -1, 0, 1, 2, \\dots\\}$\\\\\n\t$\\mathbb{Q}$ & Rational Numbers &\n\t$\\displaystyle \\bigg\\{ \\frac{p}{q} : p \\in \\mathbb{Z}, q \\in \\mathbb{Z}, q \\neq 0 \\bigg\\}$\\\\\n\t$\\mathbb{R}$ & Real Numbers & The set of all points on the number line\\\\\n\t$\\mathbb{R}\\setminus\\mathbb{Q}$ & Irrational Numbers & Real numbers that are not rational, like $\\pi$\\\\\n\t$\\mathbb{C}$ & Complex Numbers & $\\{a+b\\mathrm{i} : a \\in \\mathbb{Z}, b \\in \\mathbb{Z}\\}$\\\\\n\t\\hline\n\\end{tabular}\n\\medskip\n\n\\begin{boxnotation*}{}{}\n\tThe null set can also be written as ``$\\{\\}$''.\n\\end{boxnotation*}\n\n\\begin{boxremark*}{Imaginary Numbers}{}\n\t{\\bf This is completely optional!} I don't think we'll encounter complex numbers in this course. But they're included in the official notes, for some reason. If you're wondering what they are, than good for you! Here's an example. Solve the following system for $y \\in \\mathbb{R}$:\n\n\t\\begin{align*}\n\t\t(x-4)^2+36=0\\\\\n\t\t\\frac{x^2}{2}-4x=y\\\\\n\t\\end{align*}\n\tWe solve the first equation for $x$:\n\t\\begin{align*}\n\t\t(x-4)^2+36=0\\\\\n\t\t\\implies (x-4)^2=-36\\\\\n\t\t\\implies x-4=\\pm\\sqrt{-36}\\\\\n\t\\end{align*}\n\n\tBut it is impossible to take the square root of a negative number! Does that mean this system is \\emph{unsolveable}? Trust me for a moment here, we will get a \\emph{real} answer. Suppose we define the imaginary unit $\\mathrm{i} = \\sqrt{-1}$ (and $\\mathrm{i}^2=-1$). Then we have\n\n\t\\begin{align*}\n\t\tx-4=\\pm\\sqrt{-36}\\\\\n\t\t\\implies x-4=\\pm6\\sqrt{-1}\\\\\n\t\t\\implies x-4=\\pm6\\mathrm{i}\\\\\n\t\t\\implies x=4\\pm6\\mathrm{i}\\\\\n\t\\end{align*}\n\n\tNow we have two complex values for $x$! Substitute $x$ into the second equation to get $y$.\n\n\t\\begin{align*}\n\t\ty=\\frac{x^2}{2}-4x\\\\\n\t\t=\\frac{(4\\pm6\\mathrm{i})^2}{2}-4(4\\pm6\\mathrm{i})\\\\\n\t\t=\\frac{16\\pm48\\mathrm{i}+36\\mathrm{i}^2}{2}-16\\mp24\\mathrm{i}\\\\\n\t\t=8\\pm24\\mathrm{i}+18\\mathrm{i}^2-16\\mp24\\mathrm{i}\\\\\n\t\t=18\\mathrm{i}^2-8\\\\\n\t\t=-18-8=-26\\\\\n\t\\end{align*}\n\n\tEven though $x$ has two posible complex values, we managed to get one real solution for $y$! There is no physical interpretation for imaginary numbers, but we sometimes see them when we break physical phenomenon into systems of equations. If you've reached this far, than congrats for learning complex numbers!\n\\end{boxremark*}\n\n\\section{Compairing Sets}\n\nThere are multiple ways to compair sets. We can look at their {\\bf cardinality} (number of elements), or we can check if they're {\\bf equivalent} (same size) or {\\bf equal} (same elements).\n\n\\begin{boxdefine}{Cardinality}{}\n\tThe number of elements in a finite set $S$ is called the {\\bf cardinality} of $S$, denoted by $|S|$.\n\\end{boxdefine}\n\n\\begin{boxnotation*}{}{}\n\tThe cardinality of set $S$ is also denoted by $n(S)$.\n\\end{boxnotation*}\n\n\\begin{boxexample}{}{}\n\t$|\\{ n \\;:\\; n \\leq 5, n \\in \\mathbb{W}\\}| = |\\{0,1,2,3,4,5\\}| = 6$\n\\end{boxexample}\n\n\n\\begin{boxdefine}{Equivalent}{}\n\tThe sets $A$ and $B$ are said to be {\\bf equivalent} if $|A| = |B|$, denoted by $A \\sim B$.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\tThe set $A = \\{1,2,3,4,5\\}$ is equivalent to the set $B = \\{5,-2,17,32,12\\}$, because $|A| = |B| = 5$.\n\\end{boxexample}\n\n\n\\begin{boxdefine}{Equal}{}\n\tThe sets $A$ and $B$ are said to be {\\bf equal} if they have the same elements, and the same number of elements.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\t$\\{1,2,3\\} = \\{3,2,1\\}$, but $\\{1,2,3\\} \\ne \\{1,2,5\\} \\ne \\{1,2\\}$.\n\\end{boxexample}\n\nWe can also check to see if a set is a {\\bf subset} of another. For example, the even numbers are a subset of the integers. {\\bf Proper subsets} are simular, except that they strictly have less elements than the other set.\n\n\\begin{boxdefine}{Subset}{}\n\tA set $S$ is called a {\\bf subset} of a set $T$, written as $S \\subseteq T$, when every element of $S$ belongs to $T$.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\t$\\{1,2,3\\} \\subseteq \\{1,2,3,4\\}$, and $\\{1,2,3,4\\} \\subseteq \\{1,2,3,4\\}$\n\\end{boxexample}\n\n\\begin{boxdefine}{Proper Subset}{}\n\tA set $S$ is called a {\\bf proper subset} of a set $T$, written as $S \\subset T$, when $S$ is a subset of $T$ and there exists an element in $T$ which does not belong to $S$.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\t$\\{1,2,3\\} \\subset \\{1,2,3,4\\}$, but $\\{1,2,3,4\\}$ is not a proper subset of $\\{1,2,3,4\\}$.\n\\end{boxexample}\n\nThe {\\bf superset} and {\\bf proper superset} are the opposite definition. For example, if $A \\subset B$, then $B \\supset A$. When sets share no elements, they are called {\\bf disjoint}.\n\n\n\\begin{boxdefine}{Disjoint}{}\n\tTwo sets are {\\bf disjoint} when they do not share any elements, ie $S \\cap T=\\varnothing$.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\tThe sets $\\{1,2,3\\}$ and $\\{4,5,6\\}$ are disjoint, since they share no members.\n\\end{boxexample}\n\n\\section{Set Operations}\n\nOperations are used to transform existing sets into news sets.  The first operation is the {\\bf power set}. Basically, it's the set of all the possible combinations.\n\n\\begin{boxdefine}{Powerset}{}\n\tThe {\\bf power set} is the set of all subsets, denoted by $\\mathcal{P}(A)$.\n\\end{boxdefine}\n\n\\begin{boxproposition}{Cardinality of the Power Set}{}\n\tThe cardinality of the power set of $A$ is given by $2^{|A|}$.\n\\end{boxproposition}\n\n\\begin{boxexample}{}{}\n\tIf $A=\\{a,b\\}$, than $\\mathcal{P}(A) = \\{\\varnothing,\\{a\\},\\{b\\},\\{a,b\\}\\}$. The cardinality of $\\mathcal{P}(A)$ is $2^{2}=4$.\n\\end{boxexample}\n\nThe {\\bf compliment} of a set is ``everything that's not in the set''. Since we cannot literally put ``everything'' into a set, we first define what {\\bf universe} we're in. \n\n\\begin{boxdefine}{Universe of Discourse}{}\n\tThe {\\bf universe of discourse} (or {\\bf universal set}) contains all of the objects we might encounter in a given situation, denoted by $\\mathcal{U}$.\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\tThere are 400 Pokemon in the Galar Pokedex. You might say those Pokemon are our universal set $\\mathcal{U}$, if we are trying to complete the Pokedex.\n\\end{boxexample}\n\n\\begin{boxdefine}{Complement}{}\n\tThe {\\bf compliment} of a set $S$, written as $S^\\complement$, is the set of all elements in $\\mathcal{U}$ but not in $S$. It can be written as\n\n\t\\[\n\t\tS^\\complement = \\{x \\;:\\; \\in \\mathcal{U}, x \\notin S\\}\n\t\\]\n\\end{boxdefine}\n\n\\begin{boxnotation*}{}{}\n\tThe complement of a set can also be written as $\\overline{S}$ or $S'$\n\\end{boxnotation*}\n\n\\begin{boxexample}{}{}\n\tOn a six-sided die, what is the compliment of the even sides $\\{2,4,6\\}$? Answer: the odd sides $\\{1,3,5\\}$.\n\\end{boxexample}\n\nFinally, lets talk about what we can do with two sets. We can combine them with a {\\bf union}, we can find shared elements with the {\\bf intersection}, and we can remove elements with the {\\bf set-difference}.\n\n\\begin{boxdefine}{Union}{}\n\tThe {\\bf union} of two sets $S$ and $T$, denoted as $S \\cup T$, is the set of all elements belonging to either set $S$ or set $T$. We can define it as\n\n\t\\[\n\t\tS \\cup T = \\{x \\;:\\; x \\in S \\;\\text{OR}\\; x \\in T \\} = \\{x \\;:\\; x \\in S \\lor x \\in T \\}\n\t\\]\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\t$\\{a,b,c\\} \\cup \\{1,2,a\\} = \\{1,2,a,b,c\\}$\n\\end{boxexample}\n\nIf the sets $A$ and $B$ are disjoint ($A \\cap B = \\phi$), we call their union ($A \\cup B$) a {\\bf disjoint union}.\n\n\\begin{boxdefine}{Intersection}{}\n\tThe {\\bf intersection} of two sets $S$ and $T$, denoted by $S\\cap T$, is the set of all elements belonging to both set $S$ and set $T$. We can define it as\n\n\t\\[\n\t\tS \\cap T = \\{ x : x \\in S \\;\\text{AND}\\; x \\in T\\} = \\{ x : x \\in S \\land x \\in T\\}\n\t\\]\n\\end{boxdefine}\n\n\\begin{boxexample}{}{}\n\tThe intersection between even numbers and prime numbers is ${2}$, because 2 is the only number that is even and prime.\n\\end{boxexample}\n\n\\begin{boxdefine}{Set-Difference}{}\n\tThe {\\bf set-difference} of two sets $S$ and $T$, denoted by $S \\setminus T$, is the set of all elements belonging to $S$, but not $T$. We can define it as\n\n\t\\[\n\t\tS \\setminus T = \\{x : x \\in S \\;\\text{AND}\\; x \\notin T\\} = \\{x : x \\in S \\land x \\notin T\\}\n\t\\]\n\\end{boxdefine}\n\n\\begin{boxnotation*}{}{}\n\tThe set-different symbol ``$S \\setminus T$'' is also written as ``$S-T$''.\n\\end{boxnotation*}\n\n\\begin{boxexample}{}{}\n\t$\\{1,2,3\\} \\setminus \\{3\\} = \\{1,2\\}$.\n\\end{boxexample}\n", "meta": {"hexsha": "968c7246567d7120c09686db17c77f4537a44ca9", "size": 11322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture1.tex", "max_stars_repo_name": "munshaw/math1910-notes", "max_stars_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture1.tex", "max_issues_repo_name": "munshaw/math1910-notes", "max_issues_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture1.tex", "max_forks_repo_name": "munshaw/math1910-notes", "max_forks_repo_head_hexsha": "d707618aacb3eaee62d83fb94c982fcee989fa8c", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.3211678832, "max_line_length": 311, "alphanum_fraction": 0.6606606607, "num_tokens": 3867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898102301019, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.7871482184355525}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each matrix $A$, determine whether the formula\n  $\\iprod{\\vect{u},\\vect{v}} = \\vect{u}^T A\\vect{v}$ determines an\n  inner product on $\\R^2$.\n  \\begin{equation*}\n    (a)~ A = \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & 2 \\end{mymatrix},\\quad\n    (b)~ A = \\begin{mymatrix}{cc} 3 & 1 \\\\ 1 & 3 \\end{mymatrix},\\quad\n    (c)~ A = \\begin{mymatrix}{cc} 1 & 1 \\\\ 0 & 2 \\end{mymatrix},\\quad\n    (d)~ A = \\begin{mymatrix}{cc} 1 & 0 \\\\ 0 & -1 \\end{mymatrix},\\quad\n    (e)~ A = \\begin{mymatrix}{cc} 1 & 1 \\\\ 1 & 1 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Yes, it is an inner product. Since $A=A^T$, symmetry and\n      linearity follow as in Example~\\ref{exa:rn-with-inner-product}.\n      For the positive definite property, note that \n      $\\iprod{\\vect{u},\\vect{u}} = u_1^2 + 2u_2^2\\geq 0$, and equality\n      holds if and only if $u_1,u_2=0$.\n    \\item Yes, it is an inner product. Since $A=A^T$, symmetry and\n      linearity follow as in Example~\\ref{exa:rn-with-inner-product}.\n      For the positive definite property, we have\n      $\\iprod{\\vect{u},\\vect{u}} = 3u_1^2 + 2u_1u^2 + 3u_2^2 =\n      (u_1+u_2)^2 + 2u_1^2 + 2u_2^2 \\geq 0$. Equality holds if and\n      only if $u_1+u_2$, $u_1$, and $u_2$ are all zero, which is the\n      case if and only if $\\vect{u}=0$.\n    \\item No, it is not symmetric. For example,\n      $\\iprod{\n        \\begin{mymatrix}{c}1\\\\0\\end{mymatrix},\n        \\begin{mymatrix}{c}0\\\\1\\end{mymatrix}\n      } = 1$\n      but\n      $\\iprod{\n        \\begin{mymatrix}{c}0\\\\1\\end{mymatrix},\n        \\begin{mymatrix}{c}1\\\\0\\end{mymatrix}\n      } = 0$.\n    \\item No, it is not positive definite. For example,\n      $\\iprod{\n        \\begin{mymatrix}{c}0\\\\1\\end{mymatrix},\n        \\begin{mymatrix}{c}0\\\\1\\end{mymatrix}\n      } = -1$.\n    \\item No, it is not positive definite. For example,\n      $\\iprod{\n        \\begin{mymatrix}{c}1\\\\-1\\end{mymatrix},\n        \\begin{mymatrix}{c}1\\\\-1\\end{mymatrix}\n      } = 0$\n      although $\\begin{mymatrix}{c}1\\\\-1\\end{mymatrix}\\neq \\vect{0}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the inner product space $C[0,1]$ as in\n  Example~\\ref{exa:continuous-interval}. Compute the following inner\n  products:\n  \\begin{equation*}\n    (a)~ \\iprod{1,x}, \\quad\n    (b)~ \\iprod{x,x^2}, \\quad\n    (c)~ \\iprod{1+x,2+x^2}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\iprod{1,x} = \\int_{0}^{1} 1\\cdot x\\,dx\n      = \\int_{0}^{1} x\\,dx = \\frac{1}{2}$.\n    \\item $\\iprod{x,x^2} = \\int_{0}^{1} x\\cdot x^2\\,dx\n      = \\int_{0}^{1} x^3\\,dx = \\frac{1}{4}$.\n    \\item $\\iprod{1+x,2+x^2}\n      = \\int_{0}^{1} (1+x)(2+x^2)\\,dx\n      = \\int_{0}^{1} 2 + x^2 + 2x + x^3\\,dx\n      = \\frac{43}{12}.$\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the inner product space $C[0,1]$ as in\n  Example~\\ref{exa:continuous-interval}. Compute the following norms:\n  \\begin{equation*}\n    (a)~ \\norm{1}, \\quad\n    (b)~ \\norm{x}, \\quad\n    (c)~ \\norm{x^2+1}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\norm{1}^2 = \\iprod{1,1} = \\int_{0}^{1} 1\\,dx\n      = 1$, therefore $\\norm{1}=1$.\n    \\item $\\norm{x}^2 = \\iprod{x,x} = \\int_{0}^{1} x^2\\,dx\n      = \\frac{1}{3}$, therefore $\\norm{x} = \\frac{1}{\\sqrt{3}}$.\n    \\item $\\norm{x^2+1}^2 = \\iprod{x^2+1,x^2+1}\n      = \\int_{0}^{1} x^4 + 2x^2 + 1\\,dx\n      = \\frac{1}{5} + \\frac{2}{3} + 1 = \\frac{28}{15}$, therefore\n      $\\norm{x^2+1} = \\sqrt{\\frac{28}{15}}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  For $\\vect{u},\\vect{v}$ vectors in $\\R^3$, define the product\n  $\\vect{u}\\ast \\vect{v} = u_1v_1+2u_2v_2+3u_3v_3$. Show\n  that\n  \\begin{equation*}\n    \\abs{\\vect{u}\\ast \\vect{v}} \\leq (\\vect{u}\\ast \\vect{u})^{1/2}\n    (\\vect{v}\\ast \\vect{v})^{1/2}.\n  \\end{equation*}\n  Hint: first show that the operation\n  $\\iprod{\\vect{u},\\vect{v}}=\\vect{u}\\ast\\vect{v}$ is an inner product\n  on $\\R^3$, then use Proposition~\\ref{prop:inner-product-and-norm}.\n  \\begin{sol}\n    The operation $\\iprod{\\vect{u},\\vect{v}}=\\vect{u}\\ast\\vect{v}$ is\n    an inner product on $\\R^3$. Symmetry and linearity are\n    straightforward to check, as is the positive definite\n    property. Therefore, the claimed inequality holds by\n    Proposition~\\ref{prop:cauchy-schwarz-inequality}.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In $C[-1,1]$, find (a) the angle between $x$ and $x^2$, (b) the\n  angle between $x$ and $x^3$.\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item We have $\\iprod{x,x} = \\int_{-1}^1 x^2\\,dx = \\frac{2}{3}$,\n      $\\iprod{x^2,x^2} = \\int_{-1}^1 x^4\\,dx = \\frac{2}{5}$, and\n      $\\iprod{x, x^2} = \\int_{-1}^1 x^3\\,dx = 0$.  Therefore\n      \\begin{equation*}\n        \\cos\\theta\n        ~=~ \\frac{\\iprod{x,x^2}}{\\norm{x}\\norm{x^2}}\n        ~=~ 0.\n      \\end{equation*}\n      Therefore, the angle $\\theta$ is $\\pi/2$ radians, or $90$\n      degrees. In other words, $x$ and $x^2$ are orthogonal in\n      $C[-1,1]$.\n    \\item We have $\\iprod{x,x} = \\int_{-1}^1 x^2\\,dx = \\frac{2}{3}$,\n      $\\iprod{x^3,x^3} = \\int_{-1}^1 x^6\\,dx = \\frac{2}{7}$, and\n      $\\iprod{x, x^3} = \\int_{-1}^1 x^4\\,dx = \\frac{2}{5}$.  Therefore\n      \\begin{equation*}\n        \\cos\\theta\n        ~=~ \\frac{\\iprod{x,x^3}}{\\norm{x}\\norm{x^3}}\n        ~=~ \\frac{\\frac{2}{5}}{\\sqrt{\\frac{2}{3}}\\sqrt{\\frac{2}{7}}}\n        ~=~ \\frac{\\sqrt{21}}{5}.\n      \\end{equation*}\n      The angle $\\theta$ is $\\cos^{-1}(\\frac{\\sqrt{21}}{5})$, which is\n      approximately $0.4115$ radians or $23.58$ degrees.\n    \\end{enumerate}\n  \\end{sol}    \n\\end{ex}\n\n\\begin{ex}\\label{ex:hilbert-space}.\n  In this exercise, we will work out the details of\n  Example~\\ref{exa:hilbert-space}. We must show that $\\Hilb_{\\R}$ is a\n  vector space. We will do this by showing that it is a subspace of\n  $\\Seq_{\\R}$. Further, we must show that the inner product is\n  well-defined. This requires some knowledge of convergent series from\n  calculus.\n  \\begin{enumerate}\n  \\item Assume $a=(a_0,a_1,\\ldots)$ and $b=(b_0,b_1,\\ldots)$ are\n    square summable sequences. Show that the series\n    $a_0b_0 + a_1b_1 + a_2b_2 + \\ldots$ converges to a real\n    number. Hint: consider the series\n    $\\abs{a_0b_0} + \\abs{a_1b_2} + \\ldots$ and use the Cauchy-Schwarz\n    inequality and the absolute convergence test.\n  \\item Using the result of part (a), show that $\\Hilb_{\\R}$ is a\n    subspace of $\\Seq_{\\R}$.\n  \\item Show that the operation $\\iprod{a,b} = a_0b_0 + a_1b_1 +\n    a_2b_2 + \\ldots$ is an inner product on $\\Hilb_{\\R}$.\n  \\end{enumerate}\n  \\begin{sol}\n    (a) By assumption, $a$ and $b$ are square summable. Let\n    $N=a_0^2 + a_1^2 + \\ldots$ and $M=b_0^2 + b_1^2 + \\ldots$.\n    By the Cauchy-Schwarz inequality, for all $n$, we have\n    \\begin{equation*}\n      \\abs{a_0}\\abs{b_0} + \\ldots + \\abs{a_n}\\abs{b_n}\n      ~\\leq~ \\sqrt{\\abs{a_0}^2 + \\ldots + \\abs{a_n}^2} \\sqrt{\\abs{b_0}^2 + \\ldots + \\abs{b_n}^2}\n      ~\\leq~ \\sqrt{N}\\sqrt{M}.\n    \\end{equation*}\n    Therefore the series $\\abs{a_0b_0} + \\abs{a_1b_1} + \\ldots$ is\n    bounded. By the absolute convergence test from calculus, it\n    follows that the series $a_0b_0 + a_1b_1 + \\ldots$ converges.\n\n    (b) It is clear that the zero sequence is square summable, and\n    also that a scalar multiple of a square summable sequence is\n    square summable. Hence $\\Hilb_{\\R}$ contains the zero vector and\n    is closed under scalar multiplication. To show that it is closed\n    under addition, assume $a,b\\in\\Hilb_{\\R}$, and let $c=a+b$. We\n    must show that $c$ is square summable. But\n    \\begin{equation*}\n      c_0^2 + c_1^2 + \\ldots\n      ~=~\n      (a_0+b_0)^2 + (a_1+b_1)^2 + \\ldots\n      ~=~ (a_0^2 + a_1^2 + \\ldots) + (b_0^2 + b_1^2 + \\ldots)\n      + (2a_0b_0 + 2a_1b_1 + \\ldots).\n    \\end{equation*}\n    The series $a_0^2 + a_1^2 + \\ldots$ and $b_0^2 + b_1^2 + \\ldots$\n    converge by assumption, and the series $2a_0b_0 + 2a_1b_1 +\n    \\ldots$ converges by part (a). It follows that $\\Hilb_{\\R}$ is\n    closed under addition.\n\n    (c) Symmetry and linearity follow straightforwardly from\n    properties of convergent series. For example,\n    \\begin{eqnarray*}\n      \\iprod{a,kb+\\ell c}\n      &=& a_0(kb_0+\\ell c_0) + a_1(kb_1+\\ell c_1) + \\ldots \\\\\n      &=& k(a_0b_0 + a_1b_1 + \\ldots) + \\ell(a_0c_0 + a_1c_1 + \\ldots) \\\\\n      &=& k\\iprod{a,b} + \\ell\\iprod{a,c}.\n    \\end{eqnarray*}\n    As for the positive definite property, note that\n    \\begin{equation*}\n      \\iprod{a,a}\n      ~=~ a_0^2 + a_1^2 + \\ldots\n      ~\\geq~ 0.\n    \\end{equation*}\n    Moreover, since all terms in the series are $\\geq 0$, it follows\n    that $\\iprod{a,a}=0$ if and only if $a_i=0$ for all $i$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "c1573d15c32efee520a7dd171a49f124d47bc377", "size": 8600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.6313364055, "max_line_length": 96, "alphanum_fraction": 0.5802325581, "num_tokens": 3539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.9005297874526776, "lm_q1q2_score": 0.7871325927081302}}
{"text": "\\chapter{Floating point numbers}\\label{appA:fp-numbers}\nComputers must represent real numbers with a finite amount of bits. In order to do this, they use a fixed amount of bits for the significand and the exponent, and one bit for sign. A comprehensive introduction to floating point numbers and arithmetic can be found in many textbooks, for instance \\cite{overton-num-analysis-book}; in this appendix we only recall concepts related to the thesis subjects.\n\nNormal values are represented as a significand (or coefficient) $c$, determined by $t$ bits, an exponent $q$, by $e$ bits, and the sign. In this thesis, we interpret the significand $c$ as the positive integer number whose binary representation is the sequence of $t$ bits multiplied by $2^{-t+1}$: this ensures that, if the binary representation of $c$ begins with a $1$ (as it is always the case for normal values), its value is always in the interval $[1, 2)$. We interpret the exponent $q$ as the signed integer whose binary representation is the sequence of $e$ bits, so that its range is $[-2^e, 2^e - 1]$.\nSpecial values as $0$, $-0$, $+\\infty$ and $-\\infty$ are defined by the standard as well and represented with special combination of bits, but we don't care about their exact representation.\n\nThe significand $c$ of a floating point number can be interpreted as the binary representation of a non integer value with the decimal point right after the first digit, that is always $1$. For instance, if $t = 4$, the bit sequence $1010$ is interpreted as the binary number $1.010$, that is $1.25$ in decimal. With this interpretation in mind, the first bit of the significand has value $2^0$ while the last $2^{1-t}$.\nThis means for instance that $1$ is represented as $c = 1.00 \\dots 00$ and $q = 0$, that the smallest floating point number greater than $1$ is $c = 1.00 \\dots 01$ and $q = 0$, that is $1 + 2^{1-t}$. The greatest floating point number smaller than $1$ is instead represented as $1.11 \\dots 11$ and $q = -1$, and is $1 - 2^{-t}$.\n\nMany real numbers can't be represented as floating points with $t + e$ bits, hence the need to approximate them. Without dwelling into details, we denote with $\\fp(x)$ the floating point approximation of the real number $x$, a common choice being rounding to nearest. The choice of representable numbers guarantee that, independently of $x$\n\\[\n\\left\\lvert \\frac{\\fp(x) - x}{x} \\right\\rvert < \\macheps\n\\]\nwhere $\\macheps$ is called machine precision, and we're guaranteed that $\\macheps \\le 2^{1-t}$, the value of the least significant bit. The actual value of $\\macheps$ depends on the kind of approximation performed. Moreover, all approximation techniques ensures that $\\fp$ is monotone, that is if $x \\le y$ then $\\fp(x) \\le fp(y)$. Of course, it is not strictly monotone: even if $x < y$ it can be the case that $\\fp(x) = \\fp(y)$.\nMoreover, floating point approximation $\\fp$ preserves powers of $2$:\n\\[\n\\fp(x \\cdot 2^q) = \\fp(x) \\cdot 2^q\n\\]\n\nAn arithmetic operation on a pair of floating point numbers may not be a floating point number. To solve this issue, the standard requires a floating point version of each operation, that we denote with a circle around the standard operator symbol, whose output is always a floating point number. The definition of those operations require that they are performed on their inputs as if in infinite precision, and then the result is approximated to a floating point number. In formula, if $\\times$ is a generic binary operation, its floating point approximation $\\otimes$ is defined as\n\\[\nx \\otimes y = \\fp(x \\times y)\n\\]\nSome of the properties of operations are kept by their floating point counterparts, while other are not. For instance, associativity is often lost because of approximation. On the other hand, if $\\times$ is commutative, also $\\otimes$ is because\n\\[\nx \\otimes y = \\fp(x \\times y) = \\fp (y \\times x) = y \\otimes x\n\\]\n\n\\section{Multiplications}\nIn this section we enunciate and prove some properties of floating point multiplications. We denote by $\\cdot$ the exact product and by $\\odot$ its approximation.\n\nSince $\\cdot$ is commutative, as observed above also $\\odot$ is.\nBy monotonicity of $\\cdot$ and $\\fp$, for any two floating point numbers $x \\le y$ and any positive floating point number $z > 0$ we have\n\\[\nx \\odot z = \\fp(x \\cdot z) \\le \\fp(y \\cdot z) = y \\odot z\n\\]\nSince $\\fp$ preserves powers of $2$ we have that, for any two floating point numbers $x = c \\cdot 2^q$ and $y = c' \\cdot 2^{q'}$, their floating point product can be computed as\n\\[\nx \\odot y = \\fp((c \\cdot 2^q) \\cdot (c' \\cdot 2^{q'})) = \\fp(c \\cdot c') \\cdot 2^{q + q'} = (c \\odot c') \\cdot 2^{q + q'}\n\\]\n\nWe now present some results on floating point multiplications that aren't classic from numerical analysis, so we also prove them.\n\\begin{prop}\\label{appA:th:mult-no-fixpoints}\n\tLet $y$ be a floating point number different from $1$ and $0$. Then, if $t \\ge 2$ and $\\fp$ is rounding to nearest, for any floating point number $x \\neq 0$ we have\n\t\\[\n\tx \\odot y \\neq x\n\t\\]\n\\end{prop}\n\\begin{proof}\n\tIf $y < 0$ the thesis clearly hold because $x$ and $x \\odot y$ have different signs. So assume $y > 0$.\n\tLet $x = c \\cdot 2^q$, assuming without loss of generality that $x > 0$, and let us distinguish four cases on $y = c_0 \\cdot 2^{q_0}$.\n\n\tIf $q_0 \\ge 1$, since $c_0 \\ge 1$ we have\n\t\\begin{align*}\n\t\tx \\odot y &= (c \\odot c_0) \\cdot 2^{q + q_0} \\\\\n\t\t&\\ge (c \\odot 1) \\cdot 2^{q + 1} \\\\\n\t\t&= c \\cdot 2^{q} \\cdot 2 = 2 x > x\n\t\\end{align*}\n\n\tIf $q_0 \\le -2$, since $c_0 < 2$ we have\n\t\\begin{align*}\n\t\tx \\odot y &\\le (c \\odot 2) \\cdot 2^{q + q_0} \\\\\n\t\t&\\le (c \\odot 1) \\cdot 2^{q + q_0 + 1} \\\\\n\t\t&= c \\cdot 2^{q} \\cdot 2^{q_0 + 1} \\le x / 2 < x\n\t\\end{align*}\n\n\tIf $q_0 = 0$, since $y \\neq 1$, it must be the case that $c \\neq 1$ too, hence $c \\ge 1 + 2^{1-t}$. From this it follows\n\t\\begin{align*}\n\t\tx \\odot y &= (c \\odot c_0) \\cdot 2^q \\\\\n\t\t&\\ge (c + c \\cdot 2^{1-t}) \\cdot 2^q\n\t\\end{align*}\n\tSince $c \\ge 1$ we have that $c \\cdot 2^{-t+1} \\ge 2^{1-t}$ and hence this is an increase in one of the bits of the machine representation of $c \\cdot c_0$, thus $c \\odot c_0 \\neq c$ because they differ in at least one bit.\n\tFor instance, assume $t = 4$, $c = 1.011$ and $c_0 = 1.001$ (that is its smallest possible value). Then the product is\n\t\\begin{center}\n\t\t\\begin{tabular}{c@{\\;}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c}\n\t\t\t& & & & 1. & 0 & 1 & 1 \\\\\n\t\t\t$\\times$ & & & & 1. & 0 & 0 & 1 \\\\\n\t\t\t\\hline\n\t\t\t& 0. & 0 & 0 & 1 & 0 & 1 & 1 \\\\\n\t\t\t$+$ & 1. & 0 & 1 & 1 & 0 & 0 & 0 \\\\\n\t\t\t\\hline\n\t\t\t& 1. & 1 & 0 & 0 & 0 & 0 & 1\n\t\t\\end{tabular}\n\t\\end{center}\n\tso the result is represented as $1.100$, that is different from $c = 1.011$.\n\n\tLastly, if $q_0 = -1$ it must be the case that $y = c_0 \\cdot 2^{-1} \\le 1 - 2^{-t}$, that is $c_0 \\le 2 - 2^{1-t}$. Suppose without loss of generality that $x = c \\cdot 2^0$, if that is not the case just scale all computations by $2^q$.\n\tIf $c = 1$ then $x \\odot y = c \\odot (2 - 2^{1-t}) \\cdot 2^{-1} = (2 - 2^{1-t}) \\cdot 2^{-1} < 1 = c = x$. If $c > 1$ then\n\t\\begin{align*}\n\t\tx \\cdot y &= c \\cdot c_0 \\cdot 2^{-1} \\\\\n\t\t&\\le c \\cdot (2 - 2^{1-t}) \\cdot 2^{-1} \\\\\n\t\t&= (2 c - 2^{1-t} c) \\cdot 2^{-1} \\\\\n\t\t&< (2 c - 2^{1-t}) \\cdot 2^{-1} = c - 2^{-t}\n\t\\end{align*}\n\tSince $2^{-t}$ is exactly half the value of the least significant bit of $c$, this means $c - 2^{-t}$ is exactly in the middle between $c$ and $c - 2^{1-t}$, that is the greatest floating point smaller than $c$. Note that this is the case only because $c > 1$, because it implies $c \\ge 1 + 2^{1-t}$, hence $c - 2^{1-t} \\ge 1$.\n\t\\begin{center}\n\t\\begin{tikzpicture}\n\t\t\\tikzset{func/.style = {->,> = latex'}}\n\n\t\t% number line\n\t\t\\draw[func] (-6, 0) to (6, 0);\n\n\t\t% c-2^{-t}, c-2^{1-t} and c\n\t\t\\draw (0, 0.2) -- (0, -0.2);\n\t\t\\node[label=below:$c-2^{-t}$] at (0, 0){};\n\t\t\\draw (3, 0.2) -- (3, -0.2);\n\t\t\\node[label=below:$c$] at (3, 0){};\n\t\t\\draw (-3, 0.2) -- (-3, -0.2);\n\t\t\\node[label=below:$c-2^{1-t}$] at (-3, 0){};\n\n\t\t% c \\cdot c_0\n\t\t\\fill[red] (-1, 0) circle (2pt);\n\t\t\\node[label=above:$x \\cdot y$] at (-1, 0){};\n\t\\end{tikzpicture}\n\t\\end{center}\n\tAs shown in the line number, given that $x \\cdot y = c \\cdot c_0 \\cdot 2^{-1} < c - 2^{-t}$, if $\\fp$ rounds to the nearest floating point we have that $c - 2^{1-t}$ is closer to $x \\cdot y$ than $c$, hence\n\t\\[\n\tx \\odot y = \\fp(x \\cdot y) \\neq c = x\n\t\\]\n\\end{proof}\n\nWe remark that multiplication by a floating point is not injective. For instance, if $t = 4$, both products\n\\begin{center}\n\t\\parbox{0.45\\textwidth}{\\centering\n\t\t\\begin{tabular}{c@{\\;}c@{\\;}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c}\n\t\t\t& & & & & 1. & 1 & 1 & 0 \\\\\n\t\t\t$\\times$ & & & & & 1. & 0 & 1 & 0 \\\\\n\t\t\t\\hline\n\t\t\t& & 0. & 0 & 1 & 1 & 1 & 0 & 0 \\\\\n\t\t\t$+$ & & 1. & 1 & 1 & 0 & 0 & 0 & 0 \\\\\n\t\t\t\\hline\n\t\t\t& 1 & 0. & 0 & 0 & 1 & 1 & 0 & 0\n\t\\end{tabular}}\n\t\\parbox{0.45\\textwidth}{\\centering\n\t\t\\begin{tabular}{c@{\\;}c@{\\;}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c@{\\,}c}\n\t\t\t& & & & & 1. & 1 & 1 & 1 \\\\\n\t\t\t$\\times$ & & & & & 1. & 0 & 1 & 0 \\\\\n\t\t\t\\hline\n\t\t\t& & 0. & 0 & 1 & 1 & 1 & 1 & 0\\\\\n\t\t\t$+$ & & 1. & 1 & 1 & 1 & 0 & 0 & 0 \\\\\n\t\t\t\\hline\n\t\t\t& 1 & 0. & 0 & 1 & 0 & 1 & 1 & 0\n\t\\end{tabular}}\n\\end{center}\nare approximated by the same floating-point number $1.001 \\cdot 2^1$ (assuming rounding to nearest) but their first arguments differ by the last bit.\n\n\\begin{prop}\\label{appA:th:fp-inverse}\n\tIf $t > 1$ and we assume a rounding to nearest, every floating point number $y = c \\cdot 2^q$ such that $1 \\le c < 3/2$ and $q$ is different from both the maximum and the minimum exponents has an inverse floating point, that is a floating point $y'$ such that $y \\odot y' = 1$\n\\end{prop}\n\\begin{proof}\n\tIf $c = 1$ there is such $y'$, that is $1 \\cdot 2^{-q}$. This is a floating point number since $q \\neq -2^e$, hence $-q \\in [-2^e, 2^e - 1]$. So assume $c \\neq 1$. This in particular entails $c \\ge 1 + 2^{1-t}$.\n\n\tConsider $d = c^{-1}$, and the two floating point numbers obtained rounding it up and down to $t$ binary digits. Since this number is between $2/3$ and\n\t\\[\n\t\\frac{1}{1 + 2^{1-t}} < 1 - 2^{-t}\n\t\\]\n\twhere the inequality holds whenever $2^{-t} < 1/2$, hence when $t > 1$, these two floating point numbers are in the range $[1/2, 1 - 2^{-t}]$, that means that they have exponent $-1$. Said $\\overline{d}$ and $\\underline{d}$ to be respectively the rounding up and down of $d = c^{-1}$, since they have both exponent $-1$ and their difference is exactly one least significant bit, we have\n\t\\[\n\t\\overline{d} - \\underline{d} = 2^{1-t} \\cdot 2^{-1} = 2^{-t}\n\t\\]\n\tBy monotonicity of multiplication\n\t\\[\n\tc \\odot \\overline{d} = \\fp(c \\cdot \\overline{d}) \\ge \\fp(c \\cdot d) = \\fp(1) = 1\n\t\\]\n\tand analogously $c \\odot \\underline{d} \\le 1$.\n\tSuppose by way of contradiction that $c \\odot \\overline{d} > 1$ and $c \\odot \\underline{d} < 1$. This implies that\n\t\\[\n\tc \\odot \\overline{d} \\ge 1 + 2^{1-t}\n\t\\]\n\tthat, by the rounding to nearest approximation hypothesis, implies\n\t\\[\n\tc \\cdot \\overline{d} \\ge \\frac{1 + (1 + 2^{1-t})}{2} = 1 + 2^{-t}\n\t\\]\n\tAnalogously, $c \\odot \\underline{d} < 1$ implies\n\t\\[\n\tc \\cdot \\underline{d} \\le \\frac{1 + (1 - 2^{-t})}{2} = 1 - 2^{-t-1}\n\t\\]\n\tThis means\n\t\\[\n\tc \\cdot \\overline{d} - c \\cdot \\underline{d} \\ge 1 + 2^{-t} - 1 + 2^{-t-1} = 3/2 \\cdot 2^{-t}\n\t\\]\n\tBut we also know\n\t\\[\n\tc \\cdot \\overline{d} - c \\cdot \\underline{d} = c \\cdot (\\overline{d} - \\underline{d}) = c \\cdot 2^{-t}\n\t\\]\n\tthat yields the desired contradiction because $c < 3/2$ and\n\t\\[\n\tc \\cdot 2^{-t} \\ge 3 / 2 \\cdot 2^{-t}\n\t\\]\n\tTo show the proof graphically, we marked on the number line $1$, the two floating point nearest to $1$, the middle points of the two segments connecting these to $1$ and the two products $c \\cdot \\underline{d}$ and $c \\cdot \\overline{d}$.\n\t\\begin{center}\n\t\\begin{tikzpicture}\n\t\t\\tikzset{func/.style = {->,> = latex'}}\n\n\t\t% number line\n\t\t\\draw[func] (-6, 0) to (6, 0);\n\n\t\t% 1, 1- and 1+\n\t\t\\draw (0, 0.2) -- (0, -0.2);\n\t\t\\node[label=below:$1$] (1) at (0, 0){};\n\t\t\\draw (4, 0.2) -- (4, -0.2);\n\t\t\\node[label=below:$1+2^{1-t}$] (1p) at (4, 0){};\n\t\t\\draw (-2, 0.2) -- (-2, -0.2);\n\t\t\\node[label=below:$1+2^{-t}$] (1m) at (-2, 0){};\n\n\t\t% middle points\n\t\t\\draw (-1, 0.15) -- (-1, -0.15);\n\t\t\\draw (2, 0.15) -- (2, -0.15);\n\n\t\t% c \\cdot d^ and d_\n\t\t\\fill[red] (-1.2, 0) circle (2pt);\n\t\t\\node[label=above:$c \\cdot \\underline{d}$] at (-1.2, 0){};\n\t\t\\fill[red] (2.2, 0) circle (2pt);\n\t\t\\node[label=above:$c \\cdot \\overline{d}$] at (2.2, 0){};\n\t\\end{tikzpicture}\n\t\\end{center}\n\tIn order to have that $c \\odot \\overline{d} \\ge 1 + 2^{1-t}$ we need the real result $c \\cdot \\overline{d}$ to the right of the middle point of the segment. Analogously, to have $c \\odot \\underline{d}$ we need $c \\cdot \\underline{d}$ to the left of the other middle point. However, the distance between the two can't be more than that between the two middle points, that is exactly $3/2 \\cdot 2^{-t} \\le c \\cdot 2^{-t}$, thus yielding the contradiction.\n\\end{proof}\n\n\\begin{prop}\\label{appA:th:interval-number-elem}\n\tIf $t \\ge 3$, given a floating point number $w$, the interval\n\t\\[\n\t\\left[ (1 - 2 \\macheps) w, (1 + 2 \\macheps) w \\right]\n\t\\]\n\tcontains at most $17$ floating point numbers.\n\\end{prop}\n\\begin{proof}\n\tLet $w = c \\cdot 2^q$. Since $t \\ge 3$ we have $1 + 2 \\macheps < 2$ and $1 - 2 \\macheps \\ge 1/2$, hence all floating point numbers in that interval have a distance from $w$ of at most a factor of $2$. This implies that their exponent is at least $q - 1$, hence their least significant bit has value at least $2^{1-t} \\cdot 2^{q-1}$. Using that $\\macheps \\le 2^{1-t}$ and $c < 2$ we get\n\t\\[\n\t2^{1-t} \\cdot 2^{q-1} \\le \\macheps \\cdot 2^{q-1} < \\macheps \\cdot c / 2 \\cdot 2^{q} \\cdot 2^{-1} = \\frac{1}{4} w \\cdot \\macheps\n\t\\]\n\tSince the length of the interval is $4\\macheps \\cdot w$ and two floating point in it have distance at least $\\macheps \\cdot w /4$, there are at most $17$ of them in it.\n\\end{proof}", "meta": {"hexsha": "826f3739a2eddc2aa1d37f2febab11152e18c027", "size": 13846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/appendixA.tex", "max_stars_repo_name": "flavio-a/master-thesis", "max_stars_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_stars_repo_licenses": ["MIT"], "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/appendixA.tex", "max_issues_repo_name": "flavio-a/master-thesis", "max_issues_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_issues_repo_licenses": ["MIT"], "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/appendixA.tex", "max_forks_repo_name": "flavio-a/master-thesis", "max_forks_repo_head_hexsha": "9f23d79c205b82ca22106890dd297e64ce10c878", "max_forks_repo_licenses": ["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.4248927039, "max_line_length": 612, "alphanum_fraction": 0.6271125235, "num_tokens": 5188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8740772269642948, "lm_q1q2_score": 0.7871325689150371}}
{"text": "\n\\subsection{Injective, bijective and surjective functions}\n\n\\subsubsection{Injective functions}\n\n\\(f(a)=f(b)\\rightarrow a=b\\)\n\n\\subsubsection{Surjective functions}\n\nAll points in codomain have at least one matching point in domain\n\nMapping info, details\n\n\\subsubsection{Bijective}\n\nBoth injective and surjective\n\n\\subsubsection{Other}\n\nIdentity function\n\nThe identity function maps a term to itself.\n\nIdempotent\n\nAn idempotent function is a function which does not change the term if the function is used more than once. An example is multiplying by \\(0\\).\n\n\\subsubsection{Inverse functions}\n\nAn inverse function of a function is one which maps back onto the original value.\n\n\\(g(x)\\) is an inverse function of \\(f(x)\\) if\t\n\n\\(g(f(x))=x\\)\n\n\\subsubsection{Properties of binary functions}\n\nBinary functions can be written as:\n\n\\(f(a,b)=a\\oplus b\\)\n\nA function is commutative if:\n\n\\(x\\oplus y = y\\oplus x\\)\n\nA function is associative if:\n\n\\((x\\oplus y)\\oplus z = x\\oplus (y\\oplus z)\\)\n\nA function \\(\\otimes \\) is left distributive over \\(\\oplus \\) if:\n\n\\(x\\otimes (y\\oplus z)=(x\\otimes y) \\oplus (x\\otimes z)\\)\n\nAlternatively, function \\(\\otimes \\) is right distributive over \\(\\oplus \\) if:\n\n\\((x\\oplus y)\\otimes z=(x\\otimes z) \\oplus (y\\oplus z)\\)\n\nA function is distributive over another function if it both left and right distributive over it.\n\n", "meta": {"hexsha": "4ffd9369de1fafd3ba4ee1b389b6d8aad626b769", "size": 1347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/preteriteLogic/01-06-functionsProperties.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-06-functionsProperties.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-06-functionsProperties.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.45, "max_line_length": 143, "alphanum_fraction": 0.7305122494, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.787114127729165}}
{"text": "% Created 2020-01-29 Wed 15:17\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\\date{}\n\\title{Universal Constructions}\n\\hypersetup{\n pdfauthor={Vaibhav Pujari},\n pdftitle={Universal Constructions},\n pdfkeywords={},\n pdfsubject={},\n pdfcreator={Emacs 26.3 (Org mode 9.3)}, \n pdflang={English}}\n\\begin{document}\n\n\\maketitle\n\n\\section{Terminal objects}\n\\label{sec:orgfe6dc0d}\nObjects that have a unique morphism coming into them from every other object in the category\n\n\\begin{equation}\n\\forall c \\in \\zeta \\exists! c \\to T\n\\end{equation}\n\nIf there are more than one such objects, they are isomorphic\n\n\\subsection{Example}\n\\label{sec:orgc179554}\nIn a category of sets, the terminal object is a singleton set, because there can be only one unique function from any set to a singleton set.\n\n\\subsection{Code}\n\\label{sec:org9dd47c1}\n\\begin{verbatim}\ndata Terminal = MkTerm\nbang :: a -> Terminal\nbang _ = MkTerm\n\\end{verbatim}\nIn haskell, the object \\texttt{()} is a terminal object\n\n\\section{Initial object}\n\\label{sec:org3548e7d}\nObjects that have a unique morphism going out to every other object in the category\n\n\\begin{equation}\n\\forall c \\in \\zeta \\exists! I \\to c\n\\end{equation}\n\nIf there are more than one such objects, they are isomorphic\n\n\\subsection{Example}\n\\label{sec:org802f106}\nIn a category of sets, the initial object is a null set, because there can be\nonly one unique function from a null set to any other set.\n\n\\subsection{Code}\n\\label{sec:org9ea2a9b}\n\\begin{verbatim}\ndata Void\nabsurd :: Void -> a\nabsurd x = absurd x\n\\end{verbatim}\n\n\\section{Products}\n\\label{sec:org99e3acd}\nA product of two objects \\(a\\) and \\(b\\) is an object \\(a \\times b\\) that has projections \\(\\pi_1\\) and\n\\(\\pi_2\\) to \\(a\\) and \\(b\\) respectively. These projections factorize any other\nprojections that exist from other objects \\(c\\) (potential products) to \\(a\\) and \\(b\\)\n\n\\subsection{Example}\n\\label{sec:org639505e}\nA pair/tuple is a product\n\n\\subsection{Code}\n\\label{sec:org5e9fdb6}\n\\begin{verbatim}\ndata Pair a b = MkPair a b\nfst :: Pair a b -> a\nfst (MkPair a _) = a\nsnd :: Pair a b -> b\nsnd (MkPair _ b) = b\n\n-- For potential products c\ntuple :: (c->a, c->b) -> c -> Pair a b\ntuple f g = \\c -> MkPair (f c) (g c)\n\nuntuple :: (c -> Pair a b) -> (c->a, c->b)\nuntuple h = (fst . h, snd . h)\n\n-- Bifunctor\n-- Code easily obtained by visualizing that Pair a' b' is\n-- a product of a' and b', and thinking of Pair a b as a potential\n-- product c. So what we are basically doing is finding a mapping\n-- from potential product to actual product\nbimap :: (a->a', b->b') -> Pair a b -> Pair a' b'\nbimap f g = tuple (f . fst) (g . snd)\n\\end{verbatim}\n\n\\section{Coproducts}\n\\label{sec:orga821aab}\nIf \\(c,d \\in Ob(\\zeta)\\), then the coproduct of \\(c\\) and \\(d\\) consists of:\n\\begin{enumerate}\n\\item An object \\(c \\oplus d \\in Ob(\\zeta)\\)\n\\item A morphism \\(Left: c \\to c \\oplus d\\)\n\\item A morphism \\(Right: d \\to c \\oplus d\\)\n\\end{enumerate}\nsatisfying the property that \\(\\forall X \\in Ob(\\zeta)\\), and morphisms \\(L: c \\to\nX\\), \\(R: d \\to X\\) there exists a unique morphism \\(c \\oplus d \\to X\\), and the\ndiagram commutes.\n\n\\subsection{Code}\n\\label{sec:org4033af4}\n\\begin{verbatim}\ndata Either a b = Left a | Right b\n-- Left :: a -> Either a b\n-- Right :: b -> Either a b\n\neither :: (c -> x, d -> x) -> Either c d -> x\neither (f, g) (Left c) = f c\neither (f, g) (Right d) = g d\n\n-- Bifunctor\n-- Code can be easily obtained by drawing a diagram\nbimap :: (c->c', d->d') -> Either c d -> Either c' d'\nbimap (f, g) = either (Left . f) (Right . g)\n\\end{verbatim}\n\n\\section{Exponentials}\n\\label{sec:org938c44b}\nGiven a function from a product \\((a, b)\\) to \\(c\\), we can always get a function\nfrom \\(a\\) to a function \\(f: b \\to c\\). A function \\(f: b \\to c\\) is an exponential\nobject \\(c^b\\)\n\n\\subsection{Code}\n\\label{sec:org5c6e419}\n\\begin{verbatim}\ncurry :: ((a, b) -> c) -> a -> b -> c\ncurry f = \\a -> (\\b -> f (a,b))\n\n-- And the counterpart\nuncurry :: (a -> (b -> c) -> ((a, b) -> c)\nuncurry f = \\(a,b) -> (f a) b\n\\end{verbatim}\n\\end{document}\n", "meta": {"hexsha": "6b2801c95a66e01afa58977d7d68807171bee386", "size": 4343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05-universal-construction.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": "05-universal-construction.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": "05-universal-construction.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.6624203822, "max_line_length": 141, "alphanum_fraction": 0.6831683168, "num_tokens": 1449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8887588038050467, "lm_q1q2_score": 0.7871127665999201}}
{"text": "\\section{Preliminaries}\n\n\\subsection{Complexity of counting}\n\n\\begin{frame}\n  \\begin{definition}[The complexity class $\\# \\mathsf{P}$]\n    A function $f \\colon \\{0,1\\}^{*} \\to \\mathbb{N}$ is in $\\# \\mathsf{P}$ if there is a\n    nondeterministic polynomial-time Turing machine $M_f$ such that, for each input $w$, $M_f$\n    has exactly $f(w)$ accepting paths.\n  \\end{definition}\n  \\begin{example}[$\\#SAT$]\n    \\textbf{Instance:} A boolean formula $F$ in conjunctive normal form. \\textit{Example:}\n    $F \\equiv (x_1 \\lor \\neg x_2 \\lor \\neg x_3) \\wedge (x_1 \\lor x_3) \\wedge (\\neg x_2 \\lor x_4)$.\n\n    \\textbf{Output:} The number of satisfying assignments of $F$. \\\\\n  \\end{example}\n\n  \n  \\begin{definition}[$\\# P$-hardness]\n    A computational problem $C$ is $\\# \\mathsf{P}$-hard if, for any $f \\in \\# \\mathsf{P}$, the problem ``evaluating $f$'' is Turing reducible to $C$.\n    \n    %A function $f$ is $\\# \\mathsf{P}$-complete if  $f \\in \\#P$ and the existence of a polynomial-time algorithm that computes $f$ implies the existence of such an algorithm for any other function in $\\# \\mathsf{P}$.\n  \\end{definition}\n\\end{frame}\n\n\\begin{frame}\n\t  \\begin{definition}[$\\# P$-completeness]\n\t  \tA function $f \\colon \\{0,1\\}^{*} \\to \\mathbb{N}$ is $\\# \\mathsf{P}$-complete if $f \\in \\# \\mathsf{P}$ and evaluating $f$ is $\\# \\mathsf{P}$-hard.\n\t  \\end{definition}\n\n    \\begin{enumerate}\n    \t\\item {\\color{TurkishRose} \\textbf{Cook-Levin theorem:}} $\\#SAT$ is $\\# \\mathsf{P}$-complete.\n    \t\\item There are $\\# \\mathsf{P}$-complete problems whose decision version is trivial.\n    \\end{enumerate}\n\n  \\begin{example}[Counting independent sets is $\\# \\mathsf{P}$-complete]\n  \t\\begin{minipage}{0.4\\textwidth}\n    \\textbf{Instance:} A graph $G$. \\\\\n    \\textit{Example: }\n  \t\\end{minipage}\n  \t\\begin{minipage}{0.4\\textwidth}\n      \\begin{tikzpicture}\n      \\begin{scope}[every node/.style={circle,thick,draw}]\n      \\node (A) at (0,0) {A}; \\node (B) at (1,0.5) {B}; \\node (C) at (2,0) {C}; \\node (D) at (3.5,0) {D};\n      \\end{scope}\n      \n      \\begin{scope}[>={Stealth[black]},\n      every edge/.style={draw=black,very thick}]\n      \\path [-] (A) edge node {} (B); \\path [-] (A) edge node {} (C); \\path [-] (B) edge\n      node {} (C); \\path [-] (C) edge\n      node {} (D);\n      \\end{scope}\n      \\end{tikzpicture}\n  \t\\end{minipage}\n      \n     \n     \\vspace{3mm} \n    \\textbf{Output:} The number of independent sets of $G$.\\\\\n  \\end{example}\n\\end{frame}\n\n\\subsection{Partition functions}\n\n\\begin{frame}\n  \n  \\begin{definition}[Partition function]\n    Given a family $\\mathcal{F}_n$ of subsets of the set $\\{1, \\ldots, n\\}$, we define the partition\n    function of $\\mathcal{F}_n$ as the polynomial\n    \\begin{equation*}\n      P_{\\mathcal{F}_n}(x_1, \\ldots, x_n) = \\sum_{S \\in \\mathcal{F}_n} \\prod_{j \\in S} x_j.\n    \\end{equation*}\n    \\vspace*{-2mm}\n  \\end{definition}\n  \n  \\begin{itemize}\n  \\item Hard to compute: enumerating $\\mathcal{F}_n$ is usually not feasible.\n    \n%    \\begin{itemize}\n%    \\item     \\normalsize\n%     the family $\\mathcal{F}$ is exponentially large on $n$;\n%    \\item     \\normalsize\n%     enumerating $\\mathcal{F}$ is believed to not be feasible in polynomial-time.\n%    \\end{itemize}\n  \\item Many partition functions arise in statistical mechanics.\n  \\end{itemize}\n\n  \\begin{example}[The independent sets polynomial]\n    \\vspace*{-1mm}\n    Let $G$ be a graph. The independent sets polynomial of $G$ is\n    \\begin{equation*}\n      Z(G; y) = \\sum_{I \\text{ independent set of } G} y^{|I|}.    \n    \\end{equation*}     \n    \\vspace*{-1mm}\n  \\end{example}\n  \n\\end{frame}\n", "meta": {"hexsha": "7b8d01f54dba7c698d369bb3cd7958d3205cb6cc", "size": 3585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Slides/Sections/preliminaries.tex", "max_stars_repo_name": "andreshp/LatexTemplates", "max_stars_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2015-10-14T17:46:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-22T20:02:09.000Z", "max_issues_repo_path": "Slides/Sections/preliminaries.tex", "max_issues_repo_name": "andreshp/PlantillasLatex", "max_issues_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2016-04-11T09:14:42.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-11T09:21:16.000Z", "max_forks_repo_path": "Slides/Sections/preliminaries.tex", "max_forks_repo_name": "andreshp/LatexTemplates", "max_forks_repo_head_hexsha": "64fdc06ddf76702b9392e871b1fdd0aee6000b30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2015-10-14T17:54:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-15T06:39:01.000Z", "avg_line_length": 36.9587628866, "max_line_length": 216, "alphanum_fraction": 0.6181311018, "num_tokens": 1249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7870771121157133}}
{"text": "\\section{Singular Isothermal Sphere (SIS) Model}\n\n% lensing_ipy1/Gravtational lensing\nSingular Isothermal Sphere\n\n$\\rho = \\rho_0r^{-2}$\n\nSurface density:\n\n$\\Sigma(\\xi) =\\displaystyle\\int^\\infty_{-\\infty} \\mathrm{d}r_3 \\rho\\sqrt{\\xi^2+r_3^2}$\n\n$=\\rho_0 \\displaystyle\\int^\\infty_{-\\infty} \\dfrac{\\mathrm{d}r_3}{(\\xi^2+r_3^2)}$\n\n$=\\dfrac{\\pi\\rho_0}{\\xi}$\n\n$\\rightarrow \\kappa(\\theta) = \\dfrac{\\Sigma(D_L\\theta)}{\\Sigma_{cr}}=\\dfrac{\\pi\\rho_0}{\\Sigma_{cr}\\xi}=\\dfrac{\\pi\\rho_0}{\\Sigma_{cr}D_L \\theta}$\n\nNow using:\n\n$\\alpha(\\theta) =  \\dfrac{2}{|\\vec\\theta|}\\displaystyle\\int^\\theta_{\\theta'=0} \\kappa(\\theta')\\theta' \\mathrm{d}\\theta'$\n\n$\\rightarrow \\alpha(\\theta) = \\dfrac{2}{|\\vec\\theta|}\\displaystyle\\int^\\theta_{\\theta'=0}  \\dfrac{\\pi\\rho_0}{\\Sigma_{cr}D_L \\theta'}\\theta' \\mathrm{d}\\theta'$\n\n$=\\dfrac{2\\pi\\rho_0}{\\Sigma_{cr}D_L \\theta} \\left[\\theta'\\right]^\\theta_{\\theta'=0}$\n\n$=\\dfrac{2\\pi\\rho_0}{\\Sigma_{cr}D_L}$\n\ni.e. a constant bend angle\n", "meta": {"hexsha": "271d1c03cfaec7c4948cbb9568843d6586dfc5dd", "size": 945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Prospectus/prospectus/sections/sis.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/sis.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/sis.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": 32.5862068966, "max_line_length": 158, "alphanum_fraction": 0.6656084656, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474155747541, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7870704493139332}}
{"text": "\n\\subsection{Family-Wise Error Rate (FWER)}\n\nWhat is the chance of making at least one false positive result?\n\nNumber of tests: \\(m\\)\n\nNumber of false positive results: \\(V\\)\n\n\\(FWER=P(V>0)\\)\n\n\\subsection{False Discovery Rate (FDR)}\n\nThe proportion of false discoveries is:\n\n\\(Q=\\frac{V}{V+S}\\)\n\nWhere:\n\\(V\\) is the number of false positives\n\n\\(S\\) is the number of true positives\n\nThe FRD is \\(E[Q]\\).\n\n\\subsection{The Bonferroni correction}\n\nWe change the significance level.\n\nreject if \\(p\\le \\frac{\\alpha }{m}\\)\n\nIf \\(m=1\\) this is the standard test.\n\n", "meta": {"hexsha": "c7321cebf6149443715dbe1d50b5a34fe11505e8", "size": 556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/hypothesisMultiple/01-02-FWE.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/hypothesisMultiple/01-02-FWE.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/hypothesisMultiple/01-02-FWE.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.8484848485, "max_line_length": 64, "alphanum_fraction": 0.690647482, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7870634070735305}}
{"text": "\n\\subsection{Sufficient statistics}\n\nWe can make estimates of a population parameter using statistics from the same.\n\nA statistic is sufficient if it contains all the information needed to estimate the parameter.\n\nWe can describe the role of a parameter as:\n\n\\(P(x|\\theta, t)\\)\n\n\\(t\\) is a sufficient statistic for \\(\\theta \\) if:\n\n\\(P(x|t)=P(x|\\theta, t)\\)\n\n", "meta": {"hexsha": "57032f1485981098f6289a5d9da5ef5b4df6c72d", "size": 359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generative/01-02-sufficient.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generative/01-02-sufficient.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generative/01-02-sufficient.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.4375, "max_line_length": 94, "alphanum_fraction": 0.7270194986, "num_tokens": 86, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107931567176, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.7870077416417219}}
{"text": "\\section{Siamese Network}\\label{sec:Siamese}\n\n\\textit{Few-shot learning} encompasses classification tasks where there is a large number of classes but very limited labeled data per class --- as few as a single example in the case of ``one-shot learning.''  Few-shot learning is particularly common in computer vision spaces such as facial recognition~\\cite{Guo:2017} and fingerprint identification~\\cite{Marasco:2016}.\n\nFirst proposed by Koch\\etal~\\cite{Koch:2015}, the \\textit{Siamese neural network} is specifically targeted towards these few-shot, vision-based learning tasks.  Formally, the network is a function, $\\SiamFunc:\\xDomain\\mapsto\\mathbb{R}^m$, where ${m\\in\\mathbb{Z}_{{+}}}$ is a hyperparameter. Consider two examples, $\\xBase,\\xBase'\\in\\xDomain$, with labels $y$ and $y'$, and distance metric ${\\delta:\\mathbb{R}^m\\times\\mathbb{R}^{m}\\mapsto\\mathbb{R}_{{\\geq}0}}$ satisfying the identity, symmetry, and triangle-inequality properties.  The \\textbf{fundamental intuition} of Siamese networks is that if ${y=y'}$, then $\\siamDist{\\SiamFunc}{\\xBase}{\\xBase'}$ should be \\textit{small}.  Otherwise if ${y\\ne y}'$, $\\siamDist{\\SiamFunc}{\\xBase}{\\xBase'}$ should be \\textit{large}.  The relative definitions of ``small'' and ``large'' vary by application and as a function of~$m$.\n\nSiamese networks are trained to satisfy this fundamental intuition through a unique \\textit{triplet loss function} --- whose name derives from the three training examples required for each loss calculation.  Define $\\exA$ as the \\underline{a}nchor example used as the reference for comparison.  \\underline{P}ositive example,~$\\exP$, has the same label as~$\\exA$ while \\underline{n}egative example,~$\\exN$, has a different label than both $\\exA$~and~$\\exP$.\n\nEq.~\\eqref{eq:Loss:Triplet} defines the triplet loss formally.  Hyperparameter ${\\alpha\\in\\mathbb{R}_{{>}0}}$ enforces the relative distinctions of ``small'' and ``large'' mentioned earlier.   The loss is minimized by either reducing the distance between the mapped representation of examples in the same class --- i.e.,~$\\siamDist{\\SiamFunc}{\\exA}{\\exP}$ --- or by increasing the distance between the mapped representation of instances with different labels, i.e.,~$\\siamDist{\\SiamFunc}{\\exA}{\\exN}$.\n\n\\begin{equation}\\label{eq:Loss:Triplet}\n  \\lTrip = \\max\\Big\\{ \\siamDist{\\SiamFunc}{\\exA}{\\exP} - \\siamDist{\\SiamFunc}{\\exA}{\\exN} + \\alpha, 0 \\Big\\}\n\\end{equation}\n", "meta": {"hexsha": "d88604828f7d567bccb3745943c5c7fefd394e09", "size": 2417, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "project/final_report/siamese.tex", "max_stars_repo_name": "ZaydH/cis572", "max_stars_repo_head_hexsha": "8b57f99c268ddb0c160266803ca96b3999beab4c", "max_stars_repo_licenses": ["MIT"], "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/final_report/siamese.tex", "max_issues_repo_name": "ZaydH/cis572", "max_issues_repo_head_hexsha": "8b57f99c268ddb0c160266803ca96b3999beab4c", "max_issues_repo_licenses": ["MIT"], "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/final_report/siamese.tex", "max_forks_repo_name": "ZaydH/cis572", "max_forks_repo_head_hexsha": "8b57f99c268ddb0c160266803ca96b3999beab4c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 172.6428571429, "max_line_length": 870, "alphanum_fraction": 0.7426561854, "num_tokens": 705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107843878721, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.787007732398732}}
{"text": "\\chapter{Timestepping}\nWe now briefly discuss how to solve initial value problems. For more on this see Bradie~\\cite[Chap. 7]{Bra06}. A slightly longer but still quick introduction to these ideas can also be found in Boyce and DiPrima~\\cite{BoyDip10}.\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Forward Euler}\nIn order to compute solutions to differential equations on computers efficiently, it is convenient to do our calculations at a finite number of specified points and then interpolate between these points. For many calculations it is convenient to use a grid whose points are equally distant from each other. \n\nFor the rest of the section $h$ will be our step size, which is assumed to be constant.  When solving an ODE or PDE, the choice of $h$ isn't selected at random, but rather requires some intuition and/or theoretical analysis. We are going to start with the forward Euler method which is the most basic numerical method. Let us first denote the time at the $n$th time-step by $t^n$ and the computed solution at the $n^{th}$ time-step by $y^n$, where $y^n \\equiv y(t=t^n)$. The step size $h$ in terms of $t$ is defined as $h=t^{n+1}-t^n$. Lets first start with a basic ODE with initial conditions, in which $f(t,y)$ is some arbitrary function and $y(t)$ is our solution,\n\\begin{eqnarray}\\label{eq:ode}\n\\ \\frac{dy}{dt} = f(t,y) \\qquad y(t^0)=y^0.\n\\end{eqnarray}\nThe differential equation can be approximated by finite differences, \n\\begin{eqnarray}\n\\frac{y^{n+1}-y^n}{h} = f(t^n,y^n).\n\\end{eqnarray}\nNow all we have to do is solve for $y^{n+1}$ algebraically,\n\\begin{eqnarray}\\label{eq:odeFE}\n\\ y^{n+1}=y^n+h f(t^n,y^n) \\qquad \\text{(Forward Euler/Explicit method)}\n\\end{eqnarray}\nIf we wanted to calculate $\\frac{dy}{dt}$ at time $t^0$, then we could generate an approximation for the value at time $t^{n+1}$ using \\eqref{eq:odeFE} by first finding $y(t^0)$ and using it to compute $y^{n+1}$. We then repeat this process until the final time is reached.\n\n%Subsection\n\\subsection{An Example Computation}\nLet us consider the ODE in eq.\\ \\eqref{eq:ode} with $f(t,y)=y$ and initial conditions $y(t^0)=1$ where $t^0=0$. Two numerical solutions are computed using the forward Euler method with $h=1$ and $h=.1$\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.6]{./Timestepping/Forward_Euler.jpg}\n\\caption{A numerical solution to the ODE in eq.\\ \\eqref{eq:ode} with $f(t,y)=y$ demonstrating the accuracy of the Forward Euler method for different choices of timestep.} \\label{fig:FEexample}\n\\end{center}\n\\end{figure}\n\nIt should be no surprise that a smaller step size like $h=.1$ compared to $h=1$ will be more accurate. Looking at the line for $h=1$, you can see that $y(t)$ is calculated at only 4 points then straight lines interpolate between each point. This is obviously not very accurate, but gives a rough idea of what the function looks like. The solution for $h=.1$ might require 10 times more steps to be taken, but it is clearly more accurate. Forward Euler is an example of a first-order method and approximates the exact solution using the first two terms in the Taylor expansion\\footnote{The derivation of the Taylor expansion can be found in most books on calculus.}\n\\begin{eqnarray}\ny(t^n+h)=y(t^n)+h \\left.\\frac{dy}{dt}\\right|_{t^n}+\\text{O}(h^2),\n\\end{eqnarray}\nwhere terms of higher order than O$(h^2)$ are omitted in the approximate solution. Substituting this into eq.\\ \\eqref{eq:odeFE} we get that\n\\begin{align*}\n&{} y^n +h \\left.\\frac{dy}{dt}\\right|_{t^n}+\\text{O}(h^2) = y^n +hf(t^n,y^n)\n\\end{align*}\nafter cancelling terms and dividing by $h$, we get that\n\\begin{align*}\n&{} \\left.\\frac{dy}{dt}\\right|_{t^n}+\\text{O}(h) = f(t^n,y^n),\n\\end{align*}\nfrom which it is clear that the accuracy of the method changes linearly with the step size, and hence it is first-order accurate.\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Backwards Euler}\nA variation of forward Euler can be obtained by approximating a derivative by using a backward difference quotient. Using eq.\\ \\eqref{eq:ode} and applying\n\\begin{eqnarray}\n\\frac{y^{n}-y^{n-1}}{h}&\\approx&f(t^n,y^n) \\\\\ny^{n}&=&y^{n-1}+h f(t^n,y^n).\n\\end{eqnarray}\nStepping the index up from $n$ to $n+1$ we obtain,\n\\begin{eqnarray}\ny^{n+1}=y^n+h f(t^{n+1},y^{n+1})\\qquad \\text{(Backwards Euler/Implicit method)}\n\\end{eqnarray}\nNotice how $y^{n+1}$ is not written explicitly like it was in the forward Euler method. This equation instead implicitly defines $y^{n+1}$ and must be solved  to determine the value of $y^{n+1}$. How difficult this is depends entirely on the complexity of the function $f$. For example, if $f$ is just $y^2$, then the quadratic formula could be used, but many nonlinear PDEs require other methods. Some of these methods will be introduced later.\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Crank-Nicolson}\nBy taking an average of the forward and backward Euler methods, we can find the Crank-Nicolson method:\n\\begin{eqnarray}\n\\frac{y^{n+1}-y^{n}}{h}&=&\\frac{1}{2}f(t^{n+1},y^{n+1})+\\frac{1}{2}f(t^n,y^n)\n\\end{eqnarray}\nRearranging we obtain,\n\\begin{eqnarray}\ny^{n+1}=y^n+\\frac{h}{2}\\left[ f(t^{n+1},y^{n+1})+f(t^n,y^n) \\right] \\qquad \\text{(Crank-Nicolson)}\n\\end{eqnarray}\nNotice again how $y^{n+1}$ is not written explicitly like it was in forward Euler. This equation instead implicitly defines $y^{n+1}$ and so the equation must be solved algebraically to obtain $y^{n+1}$. \n%%%%%%%\n%Section\n%%%%%%%\n\\section{Stability of Forward Euler, Backward Euler and Crank-Nicolson}\nLet's look at the following ODE\n\\begin{eqnarray}\n\\frac{dy}{dt}= -\\lambda y(t) \\label{eq:ODEstability}\n\\end{eqnarray}\nwhere $\\lambda$ is a constant and $y(t^0)=1$ where $t^0=0$. Lets numerically solve this ODE using the forward Euler, backward Euler and Crank-Nicolson time-stepping schemes. The results are as follows\n\\begin{eqnarray}\ny^{n+1}=y^n-\\lambda h y^n \\qquad \\text{(Forward Euler)}\\\\\ny^{n+1} = \\frac{y^n}{(1+\\lambda h)} \\qquad \\text{(Backward Euler)} \\\\\ny^{n+1} = y^n\\left(\\frac{2-\\lambda h}{2+\\lambda h}\\right) \\qquad \\text{(Crank-Nicolson)} \n\\end{eqnarray}\nand the exact solution is given by\n\\begin{eqnarray}\ny(t)= e^{-\\lambda t} \\qquad \\text{(Exact solution)}\n\\end{eqnarray}\n\n\\begin{figure}[h]\n\\begin{center}\n\\includegraphics[scale=.4]{./Timestepping/unstable_forward_Euler.jpg}\n\\caption{A numerical solution to the ODE in eq.\\ \\eqref{eq:ODEstability} with $\\lambda=20$ and with a timestep of $h=0.1$ demonstrating the instability of the Forward Euler method and the stability of the Backward Euler and Crank Nicolson methods.} \\label{fig:ODEstability}\n\\end{center}\n\\end{figure}\nFigure \\ref{fig:ODEstability} above shows how both methods converge to the solution, but the forward Euler solution is unstable for the chosen timestep. Listing \\ref{lst:MatlabInstability} is a Matlab program where you can play around with the value of $\\lambda$ to see how, for a fixed timestep, this changes the stability of the method. \n\\lstinputlisting[style=matlab_style,language=Matlab,label=lst:MatlabInstability,caption={A Matlab program to demonstrate instability of different timestepping methods.}]{./Timestepping/Programs/Simple_ODE_Example_of_Unstable_FE.m}\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Stability and Accuracy of Forward Euler, Backward Euler and Crank-Nicolson Time Stepping Schemes for $y'=-\\lambda y$}\n\nThe examples discussed show that numerical stability is an important consideration when finding approximate solutions to differential equations on computers. Numerical stability requires a careful choice of numerical method and timestep for each numerical solution to a differential equation. We now try to understand these observations so that we have some guidelines to design numerical methods that are stable. The numerical solution to an initial value problem with a bounded solution is {\\bf stable} if the numerical solution can be bounded by functions which are independent of the step size. There are two methods which are typically used to understand stability. The first method is linearized stability, which involves calculating eigenvalues of a linear system to see if small perturbations grow or decay. A second method is to calculate an energy like quantity associated with the differential equation and check whether this remains bounded. \n\nWe shall assume that $\\lambda\\geq0$ so that the exact solution to the ODE does not grow without bound. The forward Euler method gives us\n\\begin{align*}\n&{} \\frac{y^{n+1}-y^n}{h}=-\\lambda y^n\n\\\\&{} y^{n+1}=(1-\\lambda h)y^n\n\\\\&{} \\Rightarrow \\lvert y^{n+1} \\rvert \\geq \\lvert (1-\\lambda h) \\rvert \\lvert y^n \\rvert \\quad \\text{ if } \\lvert (1-\\lambda h) \\rvert > 1\n\\\\&{} \\Rightarrow \\lvert y^{n+1} \\rvert \\leq \\lvert (1-\\lambda h) \\rvert \\lvert y^n \\rvert \\quad \\text{ if } \\lvert (1-\\lambda h) \\rvert <1.\n\\end{align*}\n\nWe can do a similar calculation for backward Euler to get\n\\begin{align*}\n&{} \\frac{y^{n+1}-y^n}{h}=-\\lambda y^{n+1}\n\\\\&{} y^{n+1}=\\frac{y^n}{1+\\lambda h}\n\\\\&{} \\Rightarrow \\lvert y^{n+1} \\rvert \\leq \\left\\lvert \\frac{y^n}{1+\\lambda h} \\right\\rvert \\leq \\lvert y^n \\rvert \\quad \\text{ since } \\left\\lvert \\frac{1}{1+\\lambda h} \\right\\rvert <1.\n\\end{align*}\nThus, the backward Euler method is unconditionally stable, whereas the forward Euler method is not. We leave the analysis of the Crank-Nicolson method as an exercise.\n\nA second method, often used to show stability for partial differential equations is to look for an energy like quantity and show that this bounds the solution and prevents it from becoming too positive or too negative. Usually, the quantity is chosen to be non negative, then all one needs to do is deduce there is an upper bound. We sketch how this is done for an ordinary differential equation so that we can use the same ideas when looking at partial differential equations. Recall that the forward Euler algorithm is given by\n$$\\frac{y^{n+1}-y^n}{h}=-\\lambda y^n.$$\nMultiplying this by $y^{n+1}$ we find that\n\\begin{align*}\n&{} (y^{n+1})^2=(1-h\\lambda)y^ny^{n+1}.\n\\end{align*}\nNow to obtain a bound on $\\lvert y^{n+1}\\rvert$ in terms of $\\lvert y^n \\rvert$, we use the following fact\n$$(a-b)^2\\geq0\\Rightarrow a^2+b^2\\geq2ab\\Rightarrow\\frac{(y^{n+1})^2+(y^n)^2}{2}\\geq y^ny^{n+1}.$$\nHence a sufficient condition for stability if \n$$(1-h\\lambda)>0$$\nis that\n\\begin{align*}\n&{} (y^{n+1})^2\\leq(1-h\\lambda)\\frac{(y^{n+1})^2+(y^n)^2}{2}\n\\\\&{} (y^{n+1})^2\\frac{1+h\\lambda}{2}\\leq\\frac{1-h\\lambda}{2}(y^n)^2\n\\\\&{} (y^{n+1})^2\\leq\\frac{1-h\\lambda}{1+h\\lambda}(y^n)^2,\n\\end{align*}\nthus if $1-h\\lambda>0$, then $0<\\frac{1-h\\lambda}{1+h\\lambda}<1$ and so we have stability, we again see that the algorithm is stable provided the timestep is small enough. There are many situations for which $\\lambda$ is large and so the timestep, $h$ needs to be very small. In such a situation, the forward Euler method can be very slow on a computer.\n\nStability is not the only requirement for a numerical method to approximate the solution to an initial value problem. We also want to show that as the timestep is made smaller, the numerical approximation becomes better. For the forward Euler method we have that\n\\begin{align*}\n  &{} \\frac{y^{n+h}-y^{n}}{h}=-\\lambda y^n\n\\end{align*}\nnow if\n\\begin{align*}\n&{}y^n=y(t) \\\\\n&{}y^{n+1}=y(t+h)\n\\end{align*}\nthen\\footnote{We will use big `Oh' to mean that there exists a constant so that if $f~O(h)$, then for $h\\rightarrow0$, we have that $\\left|\\frac{f}{h}\\right|<C$, where $C$ is some constant.}\n\\begin{align*}\n\\\\&y^{n+1}= y(t)+h\\frac{\\mathrm{d}y}{\\mathrm{d}t} + O(h^2)\n\\end{align*}\nso\n\\begin{align*}\n\\frac{y^{n+1}-y^n}{h}+\\lambda y^n &{} = \\frac{y(t+h)-y(t)}{h} +\\lambda y(t)\n\\\\&{} =\\frac{\\mathrm{d}y}{\\mathrm{d}t} +O(h)+\\lambda y(t)\n\\\\&{} = O(h).\n\\end{align*}\nWe can do a similar calculation to show that the Crank-Nicolson method is second-order. In this case however, we use Taylor expansions around $y(t+h/2)$.\n\\begin{align*}\n&{}\\frac{y^{n+1}-y^n}{h}=-\\lambda \\frac{ y^{n+1} + y^n}{2}\n\\end{align*}\nso\n\\begin{align*}\n&{} y^{n+1} =y(t+h)=y(t+h/2)+(h/2)\\frac{\\mathrm{d}y}{\\mathrm{d}t} +(h/2)^2\\frac{1}{2}\\frac{\\mathrm{d}^2y}{\\mathrm{d}t^2} + O(h^3)\n\\\\&{} y^{n} =y(t)=y(t+h/2)-(h/2)\\frac{\\mathrm{d}y}{\\mathrm{d}t} +(h/2)^2\\frac{1}{2}\\frac{\\mathrm{d}^2y}{\\mathrm{d}t^2} + O(h^3)\n\\end{align*}\nhence\n\\begin{align*}\n\\frac{y^{n+1}-y^n}{h}+\\lambda \\frac{ y^{n+1} + y^n}{2} &{} =\\frac{\\mathrm{d}y}{\\mathrm{d}t} + O(h^2) +\\lambda \\left[y(t+h/2)+O(h^2) \\right]\n\\\\&{} = O(h^2).\n\\end{align*}\nThus this is a second-order method.\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Exercises}\n\\begin{enumerate}\n\\item[1)] Determine the real values of $\\lambda$ and timestep $h$ for which the implicit midpoint rule is stable for the ODE \n\\begin{equation*}\n\\frac{\\mathrm{d}y}{\\mathrm{d}t}=-\\lambda y\n\\end{equation*}\nSketch the stable region in a graph of $\\lambda$ against timestep $h$.\n\\item[2)] Show that the backward Euler method is a first-order method.\n\\end{enumerate}\n\n", "meta": {"hexsha": "44713dbae1449d2c8cb63a6cd4c3470aabf01b32", "size": 12839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Timestepping/Timestepping.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": "Timestepping/Timestepping.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": "Timestepping/Timestepping.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": 67.5736842105, "max_line_length": 954, "alphanum_fraction": 0.7133733157, "num_tokens": 4043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110540642805, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7869589215823091}}
{"text": "\\section{Numerical Quadrature}\nDefine\n$$\n\\Sigma_{n, M}(\\mathbb{P}_t^d)=\\{ \\sum_{i=1}^n a_i\\sigma_k(\\omega_i\\cdot x + b_i):  \\omega_i\\in \\mathbb{S}^{d-1},\\ |b_i|\\le 2\\}.\n$$\n\\begin{lemma}\nIt holds that $\\Sigma_{n, M}(\\mathbb{P}_t^d)\\subset W^{k,\\infty}(\\Omega)$ and\n$$\n\\|v\\|_{k,\\infty}\\le M,\\quad \\forall v\\in \\Sigma_{n, M}(\\mathbb{P}_t^d),\n$$\nwhere $M=\\|u\\|_{\\mathcal{K}_1(\\mathbb{P}_t^d)}$.\n\\end{lemma}\n\nFor any $n>0$, there exists $\\displaystyle \\omega_i\\in \\mathbb{S}^{d-1}$, $\\displaystyle |b_i|\\le 2, \\sum_{i=1}^n |a_i|\\le M$ such that\n$$\nu_n(x)= \\sum_{i=1}^n a_i\\sigma_k(\\omega_i\\cdot x + b_i)\n$$\nsatisfies\n$$\n\\|u-u_n\\|_a\\lesssim n^{-\\frac12-\\frac{2k+1}{2d}}\\|u\\|_{\\mathcal{K}_1(\\mathbb{P}_k^d)}.\n$$\nFor a bounded domain $\\Omega$, \nthe activation function $\\sigma_k\\in W^{k,\\infty}(\\Omega)$.\nSuppose quadrature points $x_i$  and weights $w_i$ satisfies \n$$\n\\int_\\Omega g(x)dx - |\\Omega|\\sum_{i=1}^{N} w_ig(x_i)=0, \\quad \\forall g(x)\\in P_{r} (\\Omega)\n$$\nwith $N=\\frac{(k-1)d}{2}$, and \n$$\n\\left |\\int_\\Omega g(x)dx - |\\Omega|\\sum_{i=1}^N w_ig(x_i)\\right |\\lesssim N^{-\\frac{r+1}{d}}\\|g\\|_{r,\\infty}.\n$$ \nRecall $J(v)$ in \\eqref{auv} and \\eqref{Jv} with $m=1$ and consider \n$$\nJ(u)=\\min J(v),\\quad J_N(u_N)=\\min J_N(v_N),\n$$\nwhere \n$$\nJ_N(v_N)=|\\Omega |\\sum_{i=1}^Nw_i \\left(\\frac12 |\\nabla v_N(x_i)|^2 - f(x_i)v_N(x_i)\\right).\n$$ \nFor any conforming $v$,\n\\begin{align}\n|J_N(v) - J(v)|&\\le N^{-\\frac{k-1}{d}}\\|v\\|_{k,\\infty}.\n\\end{align}\nSince $\\Omega$ is bounded, $\\displaystyle \\omega_i\\in \\mathbb{S}^{d-1}$, $|b_i|\\le 2, \\sum_{i=1}^n |a_i|\\le M$, \n$$\n\\|u_N\\|_{k,\\infty}\\lesssim 1.\n$$\nSince $J_N(u_N)\\le J_N(v_N)$,\n\\begin{align*}\n\\frac12 \\|u_N-u\\|_a^2\n=&J(u_N)- J(u) \n\\\\\n\\le &J(u_N)- J_N(u_N) + J_N(v_N) - J(v_N)+ J(v_N)- J(u)\n\\\\\n\\lesssim &N^{-\\frac{k-1}{d}}  + \\|v_N-u\\|_a^2\n\\lesssim N^{-\\frac{k-1}{d}} +n^{-\\frac12-\\frac{2k+1}{2d}}.\n\\end{align*}\nChoose \n$ N = \\mathcal{O}(n^{2+\\frac{d+2}{2(k-1)}})$, then\n\\begin{align*}\n\\|u_N-u\\|_a^2\n\\lesssim & n^{-\\frac12-\\frac{2k+1}{d}}.\n\\end{align*}\n\n\n\n\n\n\n\n", "meta": {"hexsha": "3f81fcfc899918fcf1be7db65be9cd637fe20889", "size": 2002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/quadrature.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/quadrature.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/quadrature.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.1971830986, "max_line_length": 135, "alphanum_fraction": 0.5834165834, "num_tokens": 969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632316144274, "lm_q2_score": 0.8267117962054048, "lm_q1q2_score": 0.7869165619498446}}
{"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 applications throughout the sciences.\nWhen these distributions are complicated, as is often the case when modeling the world, 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 that are found,\nfor example, in the denominator of Bayesian posterior distributions.\n\nLike Gibbs sampling, the Metropolis algorithm is a MCMC sampling method, and generates a sequence of random\nvariables forming 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(\\theta) = ch(\\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 combine these functions 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 } $x_0$.\n    \\For{$t=1,2,\\ldots$}\n        \\State \\textrm{Draw } $x' \\sim Q(\\cdot, x_{t-1})$\n        \\State \\textrm{Draw } $a \\sim \\text{unif}(0,1)$\n        \\If{$a \\leq A(x',x_{t-1})$}\n            \\State $x_t = x'$\n        \\Else\n            \\State $x_t = x_{t-1}$\n        \\EndIf\n    \\EndFor\n    \\State \\textrm{Return } $x_1,x_2,x_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$, and continue the process. So long as $Q$ defines an irreducible, non-null recurrent, and aperiodic 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 Bayesian analysis.\nConsider the problem of computing the posterior distribution over the mean $\\mu$ and variance $\\sigma^2$\nof a normal distribution for which we have $N$ data points $y_1,\\ldots,y_N$. For concreteness,\nwe use the data in {\\tt examscores.csv} and we assume\nthe prior distributions\n\\begin{align*}\n\\mu &\\sim N(\\mu_0=80,\\sigma_0^2=16)\\\\\n\\sigma^2 &\\sim IG(\\alpha=3,\\beta=50).\n\\end{align*}\nIn this situation, we wish to sample from posterior distribution\n\\[\np(\\mu,\\sigma^2 \\,|\\,y_1,\\ldots,y_N) = \\frac{p(\\mu)p(\\sigma^2)\\prod_{i=1}^N N(y_i \\, | \\, \\mu, \\sigma^2)}\n{\\int_{-\\infty}^\\infty\\int_{0}^\\infty p(\\mu)p(\\sigma^2)\\prod_{i=1}^N N(y_i \\, | \\, \\mu, \\sigma^2)\\,d\\sigma^2d\\mu}\n\\]\nbut we can conveniently calculate only the numerator of the expression on the right. Since the denominator\nis simply a constant with respect to $\\mu$ and $\\sigma^2$, the numerator can serve as the function $f$\nin the Metropolis algorithm. We choose our proposal function to be based on a bivariate Normal distribution:\n\\[\nQ(x,y) = N(x\\, | \\, y, sI),\n\\]\nwhere $I$ is the $2\\times 2$ identity matrix and $s$ is some positive scalar.\nLet's create these functions in Python:\n\\begin{lstlisting}\nimport numpy as np\nfrom math import sqrt, exp, log\nimport scipy.stats as st\nfrom matplotlib import pyplot as plt\nfrom scipy.stats import gaussian_kde\n\n# load in the data\nscores = np.loadtxt('examscores')\n\n# initialize the hyperparameters\nalpha=3\nbeta=50\nmu0 = 80\nsig20 = 16\n\n# initialize the prior distributions\nmuprior=st.norm(loc=mu0, scale=sqrt(sig20))\nsig2prior = st.invgamma(alpha,scale=beta)\n\n# define the proposal function\ndef proposal(y, s):\n    return st.multivariate_normal.rvs(mean=y, cov=s*np.eye(len(y)))\n\n# define the log of the proportional density\ndef propLogDensity(x):\n    return muprior.logpdf(x[0])+sig2prior.logpdf(x[1])+st.norm.logpdf(scores,loc=x[0],scale=sqrt(x[1])).sum()\n\\end{lstlisting}\n\\begin{figure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{mu_traces.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.75\\textwidth]{mu_kernel.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{sig_traces.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.75\\textwidth]{sig_kernel.pdf}\n\t\\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\\begin{figure}\n\\centering\n\\includegraphics[width=.75\\textwidth]{logprobs.pdf}\n\\caption{Log densities of the first 500 Metropolis samples.}\n\\label{fig:logprobs}\n\\end{figure}\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\nsamples and the proportion of proposed samples that were accepted. Study the implementation below to make sure\nyou understand the process:\n\\begin{lstlisting}\ndef metropolis(x0, s, n_samples):\n    \"\"\"\n    Use the Metropolis algorithm to sample from posterior.\n\n    Parameters\n    ----------\n    x0 : ndarray of shape (2,)\n        The first entry is mu, the second entry is sigma2\n    s : float > 0\n        The standard deviation parameter for the proposal function\n    n_samples : int\n        The number of samples to generate\n\n    Returns\n    -------\n    draws : ndarray of shape (n_samples, 2)\n        The MCMC samples\n    logprobs : ndarray of shape (n_samples)\n        The log density of the samples\n    accept_rate : float\n        The proportion of proposed samples that were accepted\n    \"\"\"\n    accept_counter = 0\n    draws = np.empty((n_samples,2))\n    logprob = np.empty(n_samples)\n    x = x0.copy()\n    for i in xrange(n_samples):\n        xprime = proposal(x,s)\n        u = np.random.rand(1)[0]\n        if log(u) <= propLogDensity(xprime) - propLogDensity(x):\n            accept_counter += 1\n            x = xprime\n        draws[i] = x\n        logprob[i] = propLogDensity(x)\n    return draws, logprob, accept_counter/float(n_samples)\n\\end{lstlisting}\nNow let's sample from the posterior. We will choose an initial guess of $\\mu=40$ and $\\sigma^2=10$,\nand we will set $s = 20$. We draw $10000$ samples as follows:\n\\begin{lstlisting}\n>>> draws, lprobs, rate = metropolis(np.array([40, 10], dtype=float), 20., 10000)\n>>> print \"Acceptance Rate:\", r\nAcceptance Rate: 0.3531\n\\end{lstlisting}\n\nWe can evaluate the quality of our results by plotting the log probabilities, the $\\mu$ samples, the $\\sigma^2$ samples,\nand kernel density estimators for the marginal posterior distributions of $\\mu$ and $\\sigma^2$. The code\nbelow will accomplish these tasks:\n\\begin{lstlisting}\n>>> # plot the first 500 log probs\n>>> plt.plot(lprobs[:500])\n>>> plt.show()\n>>> # plot the mu samples\n>>> plt.plot(draws[:,0])\n>>> plt.show()\n>>> # plot the sigma2 samples\n>>> plt.plot(draws[:,1])\n>>> plt.show()\n>>> # build and plot KDE for posterior mu\n>>> mu_kernel = gaussian_kde(draws[50:,0])\n>>> x_min = min(draws[50:,0]) - 1\n>>> x_max = max(draws[50:,0]) + 1\n>>> x = np.arange(x_min, x_max, step=0.1)\n>>> plt.plot(x,mu_kernel(x))\n>>> plt.show()\n>>> # build and plot KDE for posterior sigma2\n>>> sig_kernel = gaussian_kde(draws[50:,1])\n>>> x_min = 20\n>>> x_max = 200\n>>> x = np.arange(x_min, x_max, step=0.1)\n>>> plt.plot(x,sig_kernel(x))\n>>> plt.show()\n\\end{lstlisting}\nYour results should be close to those given in Figures \\ref{fig:metropolis_results} and \\ref{fig:logprobs}.\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} \\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. As 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. We 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]{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]{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\\section*{The Ising Model}\nIn statistical mechanics, the Ising model describes how atoms interact in ferromagnetic material. More specifically, we assume that there is some lattice $\\Lambda$ of sites. We say $i \\sim j$ if $i$ and $j$ are adjacent sites. With each site $i$ in our lattice is an associated \\emph{spin} $\\sigma_{i} \\in \\{\\pm 1\\}$. A \\emph{state} in our Ising model is a particular spin configuration $\\sigma = (\\sigma_{j})_{j \\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. The adjacent sites for a given site are those directly above, below, to the left, and right of the site, so to speak. For sites on the edge of the grid, we assume it wraps around. In other words, a site at the furthest left of the grid is adjacent to the corresponding site on the furthest right. Thus, a single spin configuration can be represented as a $100 \\times 100$ array, with entries from $\\{\\pm 1\\}$.\n\n\\begin{problem}\nWrite a function that initializes a spin configuration for an $n \\times n$ lattice. It should return an $n \\times n$ array, each entry of which is either $1$ or $-1$, chosen randomly. Test this for the grid described above, and plot the spin configuration using \\li{matplotlib.pyplot.imshow}. It should look fairly random, as in Figure \\ref{fig:random_spin}.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=.5\\textwidth]{init.pdf}\n\\caption{Spin configuration from random initialization.}\n\\label{fig:random_spin}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that computes the energy of a spin configuration with an $n \\times n$ lattice described above. Make sure that you do not double count site pair interactions!\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. More 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)}$. Because for our particular lattice there are $2^{100 \\cdot 100} = 2^{10000}$ possible spin configurations, computing this sum is unfeasible. However, the numerator is quite simple, provided we can efficiently compute the energy $H(\\sigma)$ of a spin configuration. Thus the ratio of the probability densities of two spin configurations is simple:\n\\begin{align*}\n\\frac{\\mathbb{P}_{\\beta}(\\sigma^{*})}{\\mathbb{P}_{\\beta}(\\sigma)} & = \\frac{e^{-\\beta H(\\sigma^{*})}}{e^{-\\beta H(\\sigma)}} \\\\\n& = e^{\\beta (H(\\sigma) - H(\\sigma^{*}))}\n\\end{align*}\n\nThe simplicity of this ratio should lead us to think that a Metropolis algorithm might be appropriate by which to sample from the spin configuration probability distribution, in which case our 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\\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. We 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. Thus, 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}$. Note that we would never actually write out this matrix (it would be $2^{10000} \\times 2^{10000}$!!!). Computing the proposed sites energy is simple: if the spin flip site is $i$, then we have $H(\\sigma^{*}) = H(\\sigma) + 2\\sum_{j: j \\sim i} \\sigma_{i}\\sigma_{j}$.\n\n\\begin{problem}\nWrite a function that proposes a new spin configuration given the current spin configuration on an $n \\times n$ lattice described above. This function simply needs to return a pair of indices $(i,j)$, chosen with probability $\\frac{1}{n^{2}}$.\n\\end{problem}\n\n\\begin{problem}\nWrite a function that computes the energy of a proposed spin configuration, given the current spin configuration, its energy, and the proposed spin flip site indices.\n\\end{problem}\n\n\\begin{problem}\nWrite a function that accepts or rejects a proposed spin configuration, given the current configuration. It should accept the current energy, proposed energy, and $\\beta$, and return a boolean.\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 as we explained previously is generally the reason we have to use a Metropolis algorithm to begin with.\nWe can get away with examining only $-\\beta H(\\sigma)$. We should see this increase as the algorithm proceeds, and converge once we are sampling from the correct distribution. Note that we don't expect these values to converge\nto a specific value, but rather a restricted range of values.\n\n\\begin{problem}\nWrite a function that initializes a spin configuration for an $n \\times n$ lattice as done previously, and then performs the Metropolis algorithm, choosing new spin configurations and accepting or rejecting them. It should burn in first, and then iterate $n\\_samples$ times, keeping every $100^{\\text{th}}$ sample (this is to prevent memory failure) and all of the above values $-\\beta H(\\sigma)$ (keep the values even for the burn in period). It should also accept $\\beta$ as an argument, allowing us to effectively adjust the temperature for the model.\n\\end{problem}\n\n\\begin{problem}\nTest your Metropolis sampler on a $100 \\times 100$ grid, with $200000$ iterations, with $n\\_samples$ large enough to get $50$ samples, testing with $\\beta = 1$ and then with $\\beta = 0.2$. Plot the proportional log probabilities, and also plot a late sample from each test using \\li{matplotlib.pyplot.imshow}. How does the ferromagnetic material behave differently with differing temperatures? Recall that $\\beta$ is an inverse function of temperature. You should see more structure with lower temperature, as illustrated in Figures \\ref{fig:config1} and \\ref{fig:config2}.\n\\end{problem}\n\n\\begin{figure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{beta1_logprobs.pdf}\n\t\t\\caption{Proportional log probs when $\\beta = 1$.}\n\t\t\\label{fig:lprobs1}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.75\\textwidth]{beta1.pdf}\n\t\t\\caption{Spin configuration sample when $\\beta = 1$.}\n\t\t\\label{fig:config1}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{beta0_2_logprobs.pdf}\n\t\t\\caption{Proportional log probs when $\\beta = 0.2$.}\n\t\t\\label{fig:lprobs2}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.75\\textwidth]{beta0_2.pdf}\n\t\t\\caption{Spin configuration sample when $\\beta = 0.2$.}\n\t\t\\label{fig:config2}\n\t\\end{subfigure}\n\\end{figure}\n", "meta": {"hexsha": "dcf827d18c5a447377988b234e500b84de0a1821", "size": 21597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Metropolis/metropolis.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/Metropolis/metropolis.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/Metropolis/metropolis.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.0081967213, "max_line_length": 826, "alphanum_fraction": 0.7236190212, "num_tokens": 6027, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7868927754631398}}
{"text": "\\section{Convex Functions}\r\nWe take a break from calculus of variations and go back to calculus in $\\mathbb R^n$ for a moment.\r\nThere is a class of functions whose stationary points are easy to classify.\r\n\\begin{definition}\r\n    A set $S\\subset\\mathbb R^n$ is convex if for any $\\underline{x},\\underline{y}\\in S$ and $t\\in[0,1]$, we have $(1-t)\\underline{x}+t\\underline{y}\\in S$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A graph of a function $f:S\\to\\mathbb R$ where $S\\subset\\mathbb R^n$ is a surface described by $z-f(\\underline{x})=0$, which is a surface in $S\\times\\mathbb R$.\\\\\r\n    A chord of $f$ is a line segment in $\\mathbb R^n\\times\\mathbb R$ joining two points on the graph of $f$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $S\\subset\\mathbb R^n$ and $f:S\\to\\mathbb R$ be a function.\r\n    We say $f$ is convex if $S$ is convex and for any $\\underline{x},\\underline{y}\\in S$ and $t\\in[0,1]$ we have\r\n    $$f((1-t)\\underline{x}+t\\underline{y})\\le (1-t)f(\\underline{x})+tf(\\underline{y})$$\r\n\\end{definition}\r\nLoosely speaking, a function is convex iff its domain is convex and every chord of it is above (or on) it, where the notion of ``above'' is in the sense of the last component of $\\mathbb R^n\\times\\mathbb R$ in our above definition.\r\n\\begin{remark}\r\n    We can define concave functions correspondingly by saying a function $f$ is concave iff $-f$ is convex.\\\\\r\n    A function $f$ is strictly convex if the $\\le$ in the definition is replaced by $<$ given $t\\in (0,1)$.\r\n    It is obvious that $f$ is strictly convex only if it is convex.\r\n    This is due to the observation that the definition does not really change if we replace $t\\in[0,1]$ by $t\\in(0,1)$.\r\n\\end{remark}\r\n\\begin{example}\r\n    The function $f:\\mathbb R\\to\\mathbb R$ by $x\\mapsto x^2$ is convex as $\\mathbb R$ is convex and for any $x,y\\in\\mathbb R,t\\in (0,1)$,\r\n    \\begin{align*}\r\n        f((1-t)x+ty)-(1-t)f(x)-tf(y)&=((1-t)x+ty)^2-(1-t)x^2-ty^2\\\\\r\n        &=-(1-t)t(x-y)^2\\\\\r\n        &<0\r\n    \\end{align*}\r\n    Hence $f$ is strictly convex.\r\n\\end{example}\r\n\\begin{example}\r\n    Consider the function $f:\\mathbb R\\setminus\\{0\\}\\to\\mathbb R$ by $x\\mapsto x^{-1}$.\r\n    It is not convex as its domain is not, but its restriction on $\\mathbb R_{>0}$ is (strictly) convex.\r\n\\end{example}\r\n\\subsection{Conditions for Convexity}\r\nThere are quite a few tests for convexity of a function $f$ (mostly with some properties).\r\n\\begin{proposition}\r\n    Suppose $f:S\\to\\mathbb R$ is differentiable for some convex $S$, then $f$ is convex iff for any $\\underline{x},\\underline{y}\\in S$,\r\n    $$f(\\underline{y})\\ge f(\\underline{x})+(\\underline{y}-\\underline{x})\\cdot\\nabla f(\\underline{x})$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    If the inequality is true, then by applying it twice,\r\n    $$\\begin{cases}\r\n        f(\\underline{x})\\ge f(\\underline{z})+(\\underline{x}-\\underline{z})\\cdot\\nabla f(\\underline{z})\\\\\r\n        f(\\underline{y})\\ge f(\\underline{z})+(\\underline{y}-\\underline{z})\\cdot\\nabla f(\\underline{z})\r\n    \\end{cases}$$\r\n    So for $t\\in (0,1)$, we set $\\underline{z}=(1-t)\\underline{x}+t\\underline{y}\\in S$, then the result follows by adding $1-t$ times the first inequality to $t$ times the second.\\\\\r\n    Conversely, set $h:[0,1]\\to\\mathbb R$ by\r\n    $$h(t)=(1-t)f(\\underline{x})+tf(\\underline{y})-f((1-t)\\underline{x}+t\\underline{y})\\ge 0$$\r\n    by convexity.\r\n    It is also differentiable in $[0,1]$ as $f$ is.\r\n    Now\r\n    $$-f(\\underline{x})+f(\\underline{y})-(\\underline{y}-\\underline{x})\\cdot\\nabla f(\\underline{x})=h^\\prime(0)\\ge 0$$\r\n    as $h(0)=0$ and $h\\ge 0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $f$ is convex and has a stationary point at $\\underline{x}$, then $\\underline{x}$ is a global minimum of $f$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate from the preceding proposition.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Let $S$ be convex and $f:S\\to\\mathbb R$.\r\n    If $(\\nabla f(\\underline{y})-\\nabla f(\\underline{x}))\\cdot (\\underline{y}-\\underline{x})\\ge 0$ for any $\\underline{x},\\underline{y}\\in S$, then $f$ is convex.\r\n\\end{proposition}\r\nNote that if $S\\subset\\mathbb R$, then it is just saying that $f^\\prime$ is monotonically increasing\r\n\\begin{proof}\r\n    Exercise.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Assume that $f$ is twice differentiable, then $f$ is convex iff $H$ is always nonnegative definite where $H$ is the Hessian of $f$, i.e.\r\n    $$H_{ij}=\\frac{\\partial^2f}{\\partial x_i\\partial x_j}$$\r\n\\end{proposition}\r\nAn easy extension of this asserts the strict convexity of $f$ given that $H$ is positive definite.\r\nWe will only show the forward direction.\r\n\\begin{proof}\r\n    If $f$ is convex, then by taking $\\underline{y}=\\underline{x}+\\underline{h}$ in the preceding proposition we have\r\n    $$\\underline{h}\\cdot(\\nabla f(\\underline{x}+\\underline{h})-\\nabla f(\\underline{x}))\\ge 0$$\r\n    for any $\\underline{h}\\in S-\\underline{x}$.\r\n    So for small $|\\underline{h}|$,\r\n    $$\\frac{\\partial f}{\\partial x_i}(\\underline{x}+\\underline{h})=\\frac{\\partial f}{\\partial x_i}(\\underline{x})+h_jH_{ij}(\\underline{x})+O(|\\underline{h}|^2)$$\r\n    where the summation is implied.\r\n    Hence\r\n    $$h_ih_jH_{ij}+O(|\\underline{h}|^2)\\ge 0$$\r\n    by taking $|\\underline{h}|$ small, we obtain the nonnegative definiteness of $H(\\underline{x})$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $f(x,y)=1/(xy)$ defined on the domain $(\\mathbb R_{>0})^2$.\r\n    Then\r\n    $$H=\\frac{1}{xy}\\begin{pmatrix}\r\n        2/x^2&1/(xy)\\\\\r\n        1/(xy)&2/y^2\r\n    \\end{pmatrix}$$\r\n    which has positive determinant and trace, hence its eigenvalues are all positive, therefore $H$ is positive definite hence strictly convex.\r\n\\end{example}\r\n\\subsection{The Legendre Transform}\r\n\\begin{definition}\r\n    Let $S\\subset\\mathbb R^n$ and $f:S\\to\\mathbb R$ be a function.\r\n    Its Legendre transform is defined to be\r\n    $$f^\\star(\\underline{p})=\\sup_{\\underline{x}\\in S}(\\underline{p}\\cdot\\underline{x}-f(\\underline{x}))$$\r\n    provided that it exists and is always finite.\r\n\\end{definition}\r\n\\begin{example}\r\n    Take $S=\\mathbb R$, then the Legendre transform is simply the maximum (signed) distance between the line $z=f(x)$ and $z=px$, given that it exists.\\\\\r\n    Take for example $f(x)=ax^2$ where $a>0$ (not that if $a<0$ then the Legendre transform does not exist anywhere), then\r\n    $$f^\\star(p)=\\sup_{x\\in\\mathbb R}(px-ax^2)=\\frac{p^2}{4a}$$\r\n    by some calculation.\r\n    Now, by taking $a\\mapsto 1/(4a)$ we obtain $(f^\\star)^\\star(s)=as^2$, hence $(f^\\star)^\\star=f$.\r\n\\end{example}\r\nIt turns out to be always true that $(f^\\star)^\\star=f$ (in a domain where both of them are defined) if $f$ is convex.\r\n\\begin{proposition}\r\n    $f^\\star$ is convex in any convex subset $T$ of its domain.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    By definition, for any $\\underline{p},\\underline{q}\\in T$,\r\n    \\begin{align*}\r\n        f^\\star((1-t)\\underline{p}+t\\underline{q})&=\\sup_{\\underline{x}}((1-t)\\underline{p}\\cdot\\underline{x}+t\\underline{q}\\cdot\\underline{x}-f(\\underline{x}))\\\\\r\n        &=\\sup_{\\underline{x}}((1-t)(\\underline{p}\\cdot\\underline{x}-f(\\underline{x}))+t(\\underline{q}\\cdot\\underline{x}-f(\\underline{x})))\\\\\r\n        &\\le (1-t)f^{\\star}(\\underline{p})+tf^\\star(\\underline{q})\r\n    \\end{align*}\r\n    As desired.\r\n\\end{proof}\r\nIn practice, if $f$ is convex and differentiable, then if its Legendre transform at $\\underline{p}$ exists we can (given certain conditions on the domain and/or the function) find it by the equation\r\n$$\\nabla(\\underline{p}\\cdot\\underline{x}-f(\\underline{x}))=\\underline{0}\\implies \\underline{p}=\\nabla f$$\r\nIf $f$ is strictly convex, then there is an unique inversion $\\underline{x}=\\underline{x}(\\underline{p})$, so $f^\\star(p)=\\underline{p}\\cdot\\underline{x}(\\underline{p})-f(\\underline{x}(\\underline{p}))$.\r\n\\subsection{Applications to Thermodynamics}\r\nA many-particle system (like gas) are hard to study directly from the first principles (like Newton's Laws), hence are often analysed by looking at microscopic variables like the pressure $P$, volume $V$, temperature $T$ or entropy $S$ (which measures the global disorder of the system) or internal energy $u(S,V)$.\r\n\\begin{definition}\r\n    The Hermholtz free energy is defined by\r\n    $$F(T,V)=\\inf_{S}(u(S,V)-TS)$$\r\n\\end{definition}\r\nNow we can rewrite this in terms of Legendre transform, that is\r\n$$F(T,V)=\\inf_{S}(u(S,V)-TS)=-\\sup_{S}(TS-u(S,V))=-u^\\star(T,V)$$\r\nNote that the transformation of $u$ here is with respect to $T$ with $V$ fixed as a parameter.\r\nConsequently,\r\n$$\\left.\\frac{\\partial}{\\partial S}(TS-u(S,V))\\right|_{T,V}=0\\implies T=\\left.\\frac{\\partial u}{\\partial S}\\right|_V$$\r\nThere are other examples where we can make use of the Legendre transform too, for example:\r\n\\begin{definition}\r\n    The enthalpy of the system is described by\r\n    $$H(S,P)=\\inf_{V}(u(S,V)+pV)$$\r\n\\end{definition}\r\nThen $H(S,P)=-u^\\star(-P,S)$ where the Legendre transform is again taken with $S$ fixed.\\\\\r\nLike these, Legendre transforms can be a way to swap from $(S,V)$ dependence to dependence of other variables.", "meta": {"hexsha": "e1fe93797c5db2f457cbdf79a78bef558c4a88c0", "size": 9011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/convex.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/convex.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/convex.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.5763888889, "max_line_length": 316, "alphanum_fraction": 0.6626345578, "num_tokens": 2881, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970748488297, "lm_q2_score": 0.8933093996634687, "lm_q1q2_score": 0.7868243061585474}}
{"text": "\\section{Introduction}\nThe purpose of this paper is to study the relationships between ordered spaces and their induced topology. In particular, we want to study the p\n\\subsection{Topological spaces}\nUsing standard notation as in \\cite{Bour04}, a topological space is a set $X$ and a subset $\\tau \\subset \\mathcal{P}(X) = 2^X$ fulfulling the following axioms:\n\\begin{enumerate}\n\\item $X$ itself and the empty set $\\emptyset$ are elements in $\\tau$, and\n\\item $\\tau$ is closed under finite union and intersection.\n\\end{enumerate}\nSpeaking in the manner of abstract algebra, $\\tau$ is a monoid wrt. intersection $\\cap$ and union $\\cup$ with neutral elements $X$ and $\\emptyset$, respectively. Associativity is rather obvious and uniquness of the neutral elements follows immediately from uniqueness of $X$ itself and the empty set.\n\\subsubsection{Open and closed topological spaces}\nGiven a family of subsets $\\mathcal{U} \\subset \\tau$, we call $\\mathcal{U}$ a family of open subsets (and its elements the open subsets of $X$/in $\\tau$)if\n$$\\bigcup_{U \\in \\mathcal{U}'} U \\in \\tau,\\ \\forall \\mathcal{U}' \\subset \\mathcal{U}.$$\nIn other words, the topology $\\tau(\\mathcal{U})$, generated by a family of open sets $\\mathcal{U}$, is closed under arbitrary union. $\\tau(\\mathcal{U})$ is sometimes referred to as an open topology.\\\\\n\\indent Given a family of subsets $\\mathcal{F} \\subset \\tau$, we call $\\mathcal{F}$ a family of closed subsets\nif\n$$\\bigcap_{F \\in \\mathcal{F}'} F \\in \\tau,\\ \\forall \\mathcal{F}' \\subset \\mathcal{F}.$$\nIn other words, the topology $\\tau(\\mathcal{F})$, generated by a family of closed sets $\\mathcal{F}$, is closed under arbitrary intersection. $\\tau(\\mathcal{F})$ is sometimes referred to as a closed topology.\\\\\n\\paragraph{Exercise} Let us discuss some examples:\n\\begin{enumerate}\n\\item Given $X = \\{0, 1, 2, 3\\}$ which of the following families of subsets is a topology\n\\begin{enumerate}\n\\item $\\tau = \\left\\{\\emptyset, \\{0, 1\\}, \\{0, 1, 2\\}, \\{1, 2, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{0, 1\\}, \\{0, 1, 2\\}, \\{0, 1, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{2\\}, \\{3\\}, \\{2, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{0, 1\\}, \\{2, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{1, 2\\}, \\{2, 3\\}, \\{1, 2, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{1, 3\\}, \\{2, 3\\}, \\{1, 2, 3\\}, X\\right\\}$.\n\\item $\\tau = \\left\\{\\emptyset, \\{1, 2\\}, \\{0, 3\\}, \\{1, 2, 3\\}, X\\right\\}$.\n\\end{enumerate}\n\\item Compute the topology $\\tau(\\beta)$ generated by the following families $\\beta$ of subsets of $X$ as above:\n\\begin{enumerate}\n\\item $\\beta = \\left\\{\\{0\\}, \\{2\\}, \\{1, 3\\}\\right\\}$.\n\\item $\\beta = \\left\\{\\{1\\}, \\{2\\}, \\{1, 3\\}\\right\\}$.\n\\end{enumerate}\n\\end{enumerate}\n\\paragraph{Complement}\nThe complement of any given subset $X' \\subset X$ for some set $X$ - denoted by $X'^{c}$ - is simply:\n$$X'^c := \\{x \\in X : x \\notin X'\\}.$$\nThe complement of an open set $U \\in \\tau$ is closed in $\\tau$ and, conversely, the complement of a closed set is, indeed, open. Therefore, the topology of the complement of an open topology is closed and, conversely, the topology of the complement of a closed topology is open.\\\\\n\\indent More interestingly, the subset $\\emptyset, X \\in \\tau$ are closed and open at the same time (as $X$ can be seen as the union of all its open sets, whatever they are, and $\\emptyset$ is the intersection of all closed sets). Thus, $X^c = \\emptyset$ is open and $\\emptyset^c = X$ is closed. We call these sets clopen subsets in $\\tau$. A clopen topology $\\tau$ is generated by clopen sets. Furthermore, if all elements in $\\tau$ are clopen, we can show that $\\tau$ is a subtopology of $\\mathcal{P}(X)$.\n\\subsection{Ordered sets}\nGiven a non empty set $X$, a relation is a subset $R \\subset X \\times X$. We say a pair $(x,y) \\in X^2$ holds $R$ if $(x,y) \\in R$ or in a manner of notation: $x R y$. An equivalence relation $\\Delta \\subset X^2$ is a relation, fulfilling the following axioms\n\\begin{description}\n\\item[Reflexivity] $x \\Delta x$, for all $x \\in X$,\n\\item[Symmetry] $x \\Delta y \\Leftrightarrow y \\Delta x$, for all $x, y \\in X$ and\n\\item[Transitivity] $x \\Delta y$ and $y \\Delta z$ implies $x \\Delta z$, for all $x, y, z \\in X$.\n\\end{description}\n\n", "meta": {"hexsha": "eb8c830ffb60145dde03bc3d60f01770e29bafb6", "size": 4237, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "topo/ordered_topo/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": "topo/ordered_topo/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": "topo/ordered_topo/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": 86.4693877551, "max_line_length": 507, "alphanum_fraction": 0.6735898041, "num_tokens": 1407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569267, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.7867881297389883}}
{"text": "\\section{Constant Coefficients}\r\n\\begin{definition}\r\n\tThe general form of an nth order linear equation is\r\n\t\\begin{equation*}\r\n\t\ta_n(x)y^{(n)} + a_{n-1}y^{(n-1)} + \\ldots + a_1(x)y' + a_0y = b(x).\r\n\t\\end{equation*}\r\n\tIf each $a_i(x)$ is a constant, then the equation has constant coefficients.\r\n\\end{definition}\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\\begin{example}\r\n\tLet's try to solve the following equation by guessing and checking likely solutions.\r\n\t\\begin{equation*}\r\n\t\ty'' - 3y' + 2y = 0\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nExponentials seem like good guesses. Let's try an exponential of the form $y = Ce^{rx}$ first.\r\n\\begin{equation*}\r\n\t\\left(Ce^{rx}\\right)'' - 3\\left(Ce^{rx}\\right)' + 2\\left(Ce^{rx}\\right) =  0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tCr^2e^{rx} - 3rCe^{rx} + 2Ce^{rx} = Ce^{rx}\\left(r^2 - 3r + 2\\right) = 0.\r\n\\end{equation*}\r\nSince $Ce^{rx} \\neq 0$ unless $C = 0$, we only need to solve the quadratic.\r\nNote that the coefficients of the quadratic are the same as the coefficients in the original differential equation.\r\n\\begin{equation*}\r\n\tr^2 - 3r + 2 = 0 \\implies r = 1 \\text{, } 2.\r\n\\end{equation*}\r\nSo, our two fundamental solutions are\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\ty = C_1e^{x} \\\\\r\n\t\ty = C_2e^{2x}\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nSince these two fundamental solutions are linearly independent, the general solution is the sum of the fundamental solutions.\r\n\\begin{equation*}\r\n\ty = C_1e^{x} + C_2e^{2x}\r\n\\end{equation*}\r\n\r\n% Auxillary Equation\r\n\\input{./higherOrder/constCoeffs/auxillaryEquation.tex}", "meta": {"hexsha": "d591f7f14d1652dc9b9cf1c7cca7bab77c606a5d", "size": 1766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/constCoeffs/constCoeffs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 39.2444444444, "max_line_length": 236, "alphanum_fraction": 0.6919592299, "num_tokens": 572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476384, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7867049230498927}}
{"text": "\\chapter{Metric spaces}\n\\label{ch:metric_space}\nAt the time of writing, I'm convinced that metric topology is\nthe morally correct way to motivate point-set topology\nas well as to generalize normal calculus.\\footnote{Also,\n``metric'' is a fun word to say.}\nSo here is my best attempt.\n\nThe concept of a metric space is very ``concrete'', and lends itself easily to visualization. Hence throughout this chapter you should draw lots of pictures as you learn about new objects, like convergent sequences, open sets, closed sets, and so on.\n\n\\section{Definition and examples of metric spaces}\n\\prototype{$\\RR^2$, with the Euclidean metric.}\n\\begin{definition}\n\tA \\vocab{metric space} is a pair $(M, d)$ consisting of\n\ta set of points $M$\n\tand a \\vocab{metric} $d : M \\times M \\to \\mathbb R_{\\ge 0}$.\n\tThe distance function must obey:\n\t\\begin{itemize}\n\t\t\\ii For any $x,y \\in M$, we have $d(x,y) = d(y,x)$; i.e.\\ $d$ is symmetric.\n\t\t\\ii The function $d$ must be \\vocab{positive definite}\n\t\twhich means that $d(x,y) \\ge 0$ with equality if and only if $x=y$.\n\t\t\\ii The function $d$ should satisfy the \\vocab{triangle inequality}: for all $x,y,z \\in M$,\n\t\t\\[ d(x,z) + d(z,y) \\ge d(x,y). \\]\n\t\\end{itemize}\n\\end{definition}\n\\begin{abuse}\n\tJust like with groups, we will abbreviate $(M,d)$ as just $M$.\n\\end{abuse}\n\\begin{example}[Metric spaces of $\\RR$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The real line $\\RR$ is a metric space under the metric $d(x,y) = \\left\\lvert x-y \\right\\rvert$.\n\t\t\\ii The interval $[0,1]$ is also a metric space with the same distance function.\n\t\t\\ii In fact, any subset $S$ of $\\RR$ can be made into a metric space in this way.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}[Metric spaces of $\\RR^2$]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii We can make $\\RR^2$ into a metric space by imposing the Euclidean distance function\n\t\t\\[ d\\left( (x_1, y_1), (x_2, y_2) \\right) = \\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}. \\]\n\t\t\\ii Just like with the first example, any subset of $\\RR^2$ also becomes a metric space after we inherit it.\n\t\tThe unit disk, unit circle, and the unit square $[0,1]^2$\n\t\tare special cases.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}[Taxicab on $\\RR^2$]\n\tIt is also possible to place the \\vocab{taxicab distance} on $\\RR^2$:\n\t\\[ d\\left( (x_1, y_1), (x_2, y_2) \\right) = \n\t\t\\left\\lvert x_1-x_2 \\right\\rvert + \\left\\lvert y_1-y_2 \\right\\rvert.\n\t\t\\]\n\tFor now, we will use the more natural Euclidean metric.\n\\end{example}\n\n\\begin{example}[Metric spaces of $\\RR^n$]\n\tWe can generalize the above examples easily.\n\tLet $n$ be a positive integer.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii We let $\\RR^n$ be the metric space whose points are points in $n$-dimensional Euclidean space,\n\t\tand whose metric is the Euclidean metric\n\t\t\\[\n\t\t\td\\left( \n\t\t\t\\left( a_1, \\dots, a_n \\right), \\left( b_1, \\dots, b_n \\right)\n\t\t\t\\right)\n\t\t\t= \\sqrt{(a_1-b_1)^2 + \\dots + (a_n-b_n)^2}.\n\t\t\\]\n\t\tThis is the $n$-dimensional \\vocab{Euclidean space}.\n\t\t\\ii The open \\vocab{unit ball} $B^{n}$ is the subset of $\\RR^n$\n\t\tconsisting of those points $\\left( x_1, \\dots, x_n \\right)$\n\t\tsuch that $x_1^2 + \\dots + x_n^2 < 1$.\n\t\t\\ii The \\vocab{unit sphere} $S^{n-1}$ is the subset of $\\RR^n$\n\t\tconsisting of those points $\\left( x_1, \\dots, x_n \\right)$\n\t\tsuch that $x_1^2 + \\dots + x_n^2 = 1$, with the inherited metric.\n\t\t(The superscript $n-1$ indicates that $S^{n-1}$ is an $n-1$ dimensional space,\n\t\teven though it lives in $n$-dimensional space.)\n\t\tFor example, $S^1 \\subseteq \\RR^2$ is the unit circle,\n\t\twhose distance between two points is the length of the chord joining them.\n\t\tYou can also think of it as the ``boundary'' of the unit ball $B^n$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Function space]\n\tWe can let $M$ be the space of\n\tcontinuous functions $f \\colon [0,1] \\to \\RR$ and define the metric\n\tby $d(f,g) = \\int_0^1 \\left\\lvert f-g \\right\\rvert \\; dx$.\n\t(It admittedly takes some work to check $d(f,g) = 0$ implies $f=g$,\n\tbut we won't worry about that yet.)\n\\end{example}\n\nHere is a slightly more pathological example.\n\\begin{example}\n\t[Discrete space]\n\tLet $S$ be any set of points (either finite or infinite).\n\tWe can make $S$ into a \\vocab{discrete space} by declaring\n\t\\[\n\t\td(x,y)\n\t\t=\n\t\t\\begin{cases}\n\t\t\t1 & \\text{if $x \\neq y$} \\\\\n\t\t\t0 & \\text{if $x = y$}.\n\t\t\\end{cases}\n\t\\]\n\tIf $\\left\\lvert S \\right\\rvert = 4$ you might think of this space\n\tas the vertices of a regular tetrahedron, living in $\\RR^3$.\n\tBut for larger $S$ it's not so easy to visualize\\dots\n\\end{example}\n\\begin{example}[Graphs are metric spaces]\n\tAny connected simple graph $G$ can be made into a metric space\n\tby defining the distance between two vertices to be the\n\tgraph-theoretic distance between them.\n\t(The discrete metric is the special case when $G$ is the complete graph on $S$.)\n\\end{example}\n\\begin{ques}\n\tCheck the conditions of a metric space for the metrics on the discrete space\n\tand for the connected graph.\n\\end{ques}\n\n\\begin{abuse}\n\tFrom now on, we will refer to $\\RR^n$ with the Euclidean metric\n\tby just $\\RR^n$.\n\tMoreover, if we wish to take the metric space for a subset $S \\subseteq \\RR^n$\n\twith the inherited metric, we will just write $S$.\n\\end{abuse}\n\n\\section{Convergence in metric spaces}\n\\prototype{The sequence $\\frac1n$ (for $n=1,2,\\dots$) in $\\RR$.}\n\nSince we can talk about the distance between two points, we can talk about what it means for a sequence of points to converge.\nThis is the same as the typical epsilon-delta definition, with absolute values replaced by the distance function.\n\n\\begin{definition}\n\tLet $(x_n)_{n \\ge 1}$ be a sequence of points in a metric space $M$.\n\tWe say that $x_n$ \\vocab{converges} to $x$ if the following condition holds:\n\tfor all $\\eps > 0$, there is an integer $N$ (depending on $\\eps$)\n\tsuch that $d(x_n, x) < \\eps$ for each $n \\ge N$.\n\tThis is written \\[ x_n \\to x \\] or more verbosely as \\[ \\lim_{n \\to \\infty} x_n = x. \\]\n\tWe say that a sequence converges in $M$ if it converges to a point in $M$.\n\\end{definition}\nYou should check that this definition coincides with your intuitive notion of ``converges''.\n\\begin{abuse}\n\tIf the parent space $M$ is understood, we will allow ourselves\n\tto abbreviate ``converges in $M$'' to just ``converges''.\n\tHowever, keep in mind that convergence is defined relative to the parent space;\n\tthe ``limit'' of the space must actually be a point in $M$ for a sequence to converge.\n\\end{abuse}\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(9cm);\n\t\tDrawing(\"x_1\", (-9,0.1), dir(90));\n\t\tDrawing(\"x_2\", (-6,0.8), dir(90));\n\t\tDrawing(\"x_3\", (-5,-0.3), dir(90));\n\t\tDrawing(\"x_4\", (-2, 0.8), dir(90));\n\t\tDrawing(\"x_5\", (-1.7, -0.7), dir(-90));\n\t\tDrawing(\"x_6\", (-0.6, -0.3), dir(225));\n\t\tDrawing(\"x_7\", (-0.4, 0.3), dir(90));\n\t\tDrawing(\"x_8\", (-0.25, -0.24), dir(-90));\n\t\tDrawing(\"x_9\", (-0.12, 0.1), dir(45));\n\t\tdot(\"$x$\", (0,0), dir(-45), blue);\n\t\tdraw(CR(origin, 1.5), blue+dashed);\n\t\\end{asy}\n\\end{center}\n\n\\begin{example}\n\tConsider the sequence\n\t$x_1 = 1$, $x_2 = 1.4$, $x_3 = 1.41$, $x_4 = 1.414$, \\dots.\n\t\\begin{enumerate}[(a)]\n\t\t\\ii If we view this as a sequence in $\\RR$, it converges to $\\sqrt 2$.\n\t\t\\ii However, even though each $x_i$ is in $\\QQ$,\n\t\tthis sequence does NOT converge when we view it as a sequence in $\\QQ$!\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{ques}\n\tWhat are the convergent sequences in a discrete metric space?\n\\end{ques}\n\n\\section{Continuous maps}\nIn calculus you were also told (or have at least heard)\nof what it means for a function to be continuous.\nProbably something like\n\\begin{quote}\n\tA function $f \\colon \\RR \\to \\RR$\n\tis continuous at a point $p \\in \\RR$\n\tif for every $\\eps > 0$ there exists a $\\delta > 0$ such that\n\t$\\left\\lvert x-p \\right\\rvert < \\delta\n\t\t\\implies\n\t\t\\left\\lvert f(x) - f(p) \\right\\rvert < \\eps$.\n\\end{quote}\n\\begin{ques}\n\tCan you guess what the corresponding definition for metric spaces is?\n\\end{ques}\n\nAll we have do is replace the absolute values with the more general distance functions: this gives us a definition of continuity for any function $M \\to N$.\n\n\\begin{definition}\n\tLet $M = (M, d_M)$ and $N = (N, d_N)$ be metric spaces.\n\tA function $f \\colon M \\to N$ is \\vocab{continuous}\n\tat a point $p \\in M$\n\tif for every $\\eps > 0$ there exists a $\\delta > 0$ such that\n\t\\[ d_M(x,p) < \\delta \\implies d_N(f(x), f(p)) < \\eps. \\]\n\tMoreover, the entire function $f$ is continuous\n\tif it is continuous at every point $p \\in M$.\n\\end{definition}\nNotice that, just like in our definition of an isomorphism of a group,\nwe use the metric of $M$ for one condition\nand the metric of $N$ for the other condition.\n\nThis generalization is nice because it tells us immediately how we could carry over continuity arguments in $\\RR$ to more general spaces like $\\CC$.\nNonetheless, this definition is kind of cumbersome to work with,\nbecause it makes extensive use of the real numbers\n(epsilons and deltas).\nHere is an equivalent condition.\n\\begin{theorem}[Sequential continuity]\n\t\\label{thm:seq_cont}\n\tA function $f \\colon M \\to N$ of metric spaces\n\tis continuous at a point $p \\in M$\n\tif and only if the following property holds:\n\tif $x_1$, $x_2$, \\dots is a sequence in $M$ converging to $p$,\n\tthen the sequence $f(x_1)$, $f(x_2)$, \\dots in $N$ converges to $f(p)$.\n\\end{theorem}\n\\begin{proof}\n\tOne direction is not too hard:\n\t\\begin{exercise}\n\t\tShow that $\\eps$-$\\delta$ continuity implies sequential continuity\n\t\tat each point.\n\t\\end{exercise}\n\tConversely, we will prove if $f$ is not $\\eps$-$\\delta$ continuous at $p$\n\tthen it does not preserve convergence.\n\n\tIf $f$ is not continuous at $p$, then there is a ``bad'' $\\eps > 0$,\n\twhich we now consider fixed.\n\tSo for each choice of $\\delta = 1/n$,\n\tthere should be some point $x_n$ which is within $\\delta$ of $p$,\n\tbut which is mapped more than $\\eps$ away from $f(p)$.\n\tBut then the sequence $x_n$ converges to $p$,\n\tand $f(x_n)$ is always at least $\\eps$ away from $f(p)$, contradiction.\n\\end{proof}\n\nExample application showcasing the niceness of sequential continuity:\n\\begin{proposition}[Composition of continuous functions is continuous]\n\tLet $f \\colon M \\to N$ and $g \\colon N \\to L$ be continuous maps of metric spaces.\n\tThen their composition $g \\circ f$ is continuous.\n\\end{proposition}\n\\begin{proof}\n\tDead simple with sequences:\n\tLet $p \\in M$ be arbitrary and let $x_n \\to p$ in $M$.\n\tThen $f(x_n) \\to f(p)$ in $N$ and $g(f(x_n)) \\to g(f(p))$ in $L$, QED.\n\\end{proof}\n\n\\begin{ques}\n\tLet $M$ be any metric space and $D$ a discrete space.\n\tWhen is a map $f \\colon D \\to M$ continuous?\n\\end{ques}\n\n\n\n\\section{Homeomorphisms}\n\\prototype{The unit circle $S^1$ is homeomorphic to the boundary of the unit square.}\n\nWhen do we consider two groups to be the same?\nAnswer: if there's a structure-preserving map\nbetween them which is also a bijection.\nFor metric spaces, we do exactly the same thing,\nbut replace ``structure-preserving'' with ``continuous''.\n\n\\begin{definition}\n\tLet $M$ and $N$ be metric spaces.\n\tA function $f \\colon M \\to N$ is a\n\t\\vocab{homeomorphism} if it is a bijection,\n\tand both $f \\colon M \\to N$\n\tand its inverse $f\\inv \\colon N \\to M$ are continuous.\n\tWe say $M$ and $N$ are \\vocab{homeomorphic}.\n\\end{definition}\nNeedless to say, homeomorphism is an equivalence relation.\n\nYou might be surprised that we require $f\\inv$ to also be continuous.\nHere's the reason: you can show that if $\\phi$ is\nan isomorphism of groups, then $\\phi\\inv$ also preserves the group operation,\nhence $\\phi\\inv$ is itself an isomorphism.\nThe same is not true for continuous bijections,\nwhich is why we need the new condition.\n\\begin{example}\n\t[Homeomorphism $\\neq$ continuous bijection]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii There is a continuous bijection\n\t\tfrom $[0,1)$ to the circle, % chktex 9\n\t\tbut it has no continuous inverse.\n\t\t\\ii Let $M$ be a discrete space with size $|\\RR|$.\n\t\tThen there is a continuous function $M \\to \\RR$\n\t\twhich certainly has no continuous inverse.\n\t\\end{enumerate}\n\\end{example}\n\nNote that this is the topologist's definition of ``same'' --\nhomeomorphisms are ``continuous deformations''.\nHere are some examples.\n\n\\begin{example}[Examples of homeomorphisms]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Any space $M$ is homeomorphic to itself\n\t\tthrough the identity map.\n\t\t\\ii The old saying: a doughnut (torus) is\n\t\thomeomorphic to a coffee cup.\n\t\t(Look this up if you haven't heard of it.)\n\t\t\\ii The unit circle $S^1$ is homeomorphic\n\t\tto the boundary of the unit square.\n\t\tHere's one bijection between them, after an appropriate scaling:\n\t\t\\begin{center}\n\t\t\t\\begin{asy}\n\t\t\t\tsize(1.5cm);\n\t\t\t\tdraw(unitcircle);\n\t\t\t\tpair A = (1.4, 1.4);\n\t\t\t\tpair B = rotate(90)*A;\n\t\t\t\tpair C = rotate(90)*B;\n\t\t\t\tpair D = rotate(90)*C;\n\t\t\t\tdraw(A--B--C--D--cycle);\n\t\t\t\tdot(origin);\n\t\t\t\tpair P = Drawing(dir(70));\n\t\t\t\tpair Q = Drawing(extension(origin, P, A, B));\n\t\t\t\tdraw(origin--Q, dashed);\n\t\t\t\\end{asy}\n\t\t\\end{center}\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Metrics on the unit circle]\n\tIt may have seemed strange that our metric function on $S^1$\n\twas the one inherited from $\\RR^2$,\n\tmeaning the distance between two points\n\ton the circle was defined to be the length of the chord.\n\tWouldn't it have made more sense to use the circumference of the\n\tsmaller arc joining the two points?\n\n\tIn fact, it doesn't matter:\n\tif we consider $S^1$ with the ``chord'' metric\n\tand the ``arc'' metric, we get two homeomorphic spaces,\n\tas the map between them is continuous.\n\n\tThe same goes for $S^{n-1}$ for general $n$.\n\\end{example}\n\n\\begin{example}\n\t[Homeomorphisms really don't preserve size]\n\tSurprisingly, the open interval $(-1,1)$\n\tis homeomorphic to the real line $\\RR$!\n\tOne bijection is given by\n\t\\[ x \\mapsto \\tan(\\pi/2 x) \\]\n\twith the inverse being given by $t \\mapsto \\frac2\\pi \\arctan(t)$.\n\n\tThis might come as a surprise,\n\tsince $(-1,1)$ doesn't look that much like $\\RR$;\n\tthe former is ``bounded'' while the latter is ``unbounded''.\n\\end{example}\n\n\\section{Extended example/definition: product metric}\n\\prototype{$\\RR \\times \\RR$ is $\\RR^2$.}\n\nHere is an extended example which will occur later on.\nLet $M = (M, d_M)$ and $N = (N, d_N)$ be metric spaces (say, $M = N = \\RR$).\nOur goal is to define a metric space on $M \\times N$.\n\nLet $p_i = (x_i,y_i) \\in M \\times N$ for $i=1,2$.\nConsider the following metrics on the set of points $M \\times N$:\n\\begin{align*}\n\td_{\\text{max}} ( p_1, p_2 )\n\t\t&\\defeq \\max \\left\\{ d_M(x_1, x_2), d_N(y_1, y_2) \\right\\}  \\\\\n\td_{\\text{Euclid}} ( p_1, p_2 )\n\t\t&\\defeq \\sqrt{d_M(x_1,x_2)^2 + d_N(y_1, y_2)^2} \\\\\n\td_{\\text{taxicab}} \\left( p_1, p_2 \\right)\n\t\t&\\defeq d_M(x_1, x_2) + d_N(y_1, y_2).\n\\end{align*}\nAll of these are good candidates.\nWe are about to see it doesn't matter which one we use:\n\\begin{exercise}\nVerify that\n\\[ d_{\\text{max}}(p_1,p_2)\n\t\\le d_{\\text{Euclid}}(p_1, p_2)\n\t\\le d_{\\text{taxicab}}(p_1, p_2)\n\t\\le 2d_{\\text{max}}(p_1, p_2). \\]\nUse this to show that the metric spaces we obtain\nby imposing any of the three metrics are homeomorphic,\nwith the homeomorphism being just the identity map.\n\\end{exercise}\n\n\\begin{definition}\n\tHence we will usually simply refer to\n\t\\emph{the} metric on $M \\times N$,\n\tcalled the \\vocab{product metric}.\n\tIt will not be important which of the three metrics we select.\n\\end{definition}\n\n\\begin{example}[$\\RR^2$]\n\tIf $M = N = \\RR$, we get $\\RR^2$, the Euclidean plane.\n\tThe metric $d_{\\text{Euclid}}$ is the one we started with,\n\tbut using either of the other two metric works fine as well.\n\\end{example}\n\nThe product metric plays well with convergence of sequences.\n\\begin{proposition}\n\t[Convergence in the product metric is by component]\n\tWe have $(x_n, y_n) \\to (x,y)$\n\tif and only if $x_n \\to x$ and $y_n \\to y$.\n\\end{proposition}\n\\begin{proof}\n\tWe have $d_{\\text{max}} \\left( (x,y), (x_n, y_n) \\right)\n\t= \\max\\left\\{ d_M(x, x_n), d_N(y, y_n) \\right\\}$\n\tand the latter approaches zero as $n \\to \\infty$\n\tif and only if $d_M(x,x_n) \\to 0$ and $d_N(y, y_n) \\to 0$.\n\\end{proof}\n\nLet's see an application of this:\n\\begin{proposition}\n\t[Addition and multiplication are continuous]\n\t\\label{prop:arithmetic_continuous}\n\tThe addition and multiplication maps\n\tare continuous maps $\\RR \\times \\RR \\to \\RR$.\n\\end{proposition}\n\\begin{proof}\n\tFor multiplication: for any $n$ we have\n\t\\begin{align*}\n\t\tx_n y_n &= \\left( x + (x_n-x) \\right)\n\t\t\\left( y + (y_n-y) \\right) \\\\\n\t\t&= xy + y(x_n-x) + x(y_n-y) + (x_n-x)(y_n-y) \\\\\n\t\t\\implies \\left\\lvert x_n y_n - xy \\right\\rvert\n\t\t&\\le \\left\\lvert y \\right\\rvert\n\t\t\t\\left\\lvert x_n - x \\right\\rvert\n\t\t+ \\left\\lvert x \\right\\rvert\n\t\t\t\\left\\lvert y_n - y \\right\\rvert\n\t\t+ \\left\\lvert x_n - x \\right\\rvert\n\t\t\t\\left\\lvert y_n - y \\right\\rvert.\n\t\\end{align*}\n\tAs $n \\to \\infty$, all three terms on the\n\tright-hand side tend to zero.\n\tThe proof that $+ \\colon \\RR \\times \\RR \\to \\RR$ is continuous\n\tis similar (and easier): one notes for any $n$ that\n\t\\[ |(x_n + y_n) - (x+y)| \\le |x_n-x| + |y_n-y| \\]\n\tand both terms on the right-hand side\n\ttend to zero as $n \\to \\infty$.\n\\end{proof}\n\\Cref{prob:subtract_divide} covers the other two operations,\nsubtraction and division.\nThe upshot of this is that, since compositions are also continuous,\nmost of your naturally arising real-valued functions\nwill automatically be continuous as well.\nFor example, the function $\\frac{3x}{x^2+1}$\nwill be a continuous function from $\\RR \\to \\RR$,\nsince it can be obtained by composing $+$, $\\times$, $\\div$.\n\n\\section{Open sets}\n\\prototype{The open disk $x^2+y^2<r^2$ in $\\RR^2$.}\n\nContinuity is really about what happens ``locally'':\nhow a function behaves ``close to a certain point $p$''.\nOne way to capture this notion of ``closeness''\nis to use metrics as we've done above.\nIn this way we can define an $r$-neighborhood of a point.\n\n\\begin{definition}\n\tLet $M$ be a metric space.\n\tFor each real number $r > 0$ and point $p \\in M$, we define\n\t\\[ M_r(p) \\defeq \\left\\{ x \\in M: d(x,p) < r \\right\\}. \\]\n\tThe set $M_r(p)$ is called an \\vocab{$r$-neighborhood} of $p$.\n\\end{definition}\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(4cm);\n\t\tbigblob(\"$M$\");\n\t\tpair p = Drawing(\"p\", (0.3,0.1), dir(-90));\n\t\treal r = 1.8;\n\t\tdraw(CR(p,r), dashed);\n\t\tlabel(\"$M_r(p)$\", p+r*dir(-65), dir(-65));\n\t\tdraw(p--(p+r*dir(130)));\n\t\tlabel(\"$r$\", midpoint(p--(p+r*dir(130))), dir(40));\n\t\\end{asy}\n\\end{center}\n\nWe can rephrase convergence more succinctly in terms of $r$-neighborhoods.\nSpecifically, a sequence $(x_n)$ converges to $x$\nif for every $r$-neighborhood of $x$,\nall terms of $x_n$ eventually stay within that $r$-neighborhood.\n\nLet's try to do the same with functions.\n\\begin{ques}\n\tIn terms of $r$-neighborhoods,\n\twhat does it mean for a function $f \\colon M \\to N$\n\tto be continuous at a point $p \\in M$?\n\\end{ques}\n\nEssentially, we require that the pre-image of every $\\eps$-neighborhood has\nthe property that some $\\delta$-neighborhood exists inside it.\nThis motivates:\n\\begin{definition}\n\tA set $U \\subseteq M$ is \\vocab{open} in $M$\n\tif for each $p \\in U$, some $r$-neighborhood of $p$\n\tis contained inside $U$.\n\tIn other words, there exists $r>0$ such that $M_r(p) \\subseteq U$.\n\\end{definition}\n\\begin{abuse}\n\tNote that a set being open is defined\n\t\\emph{relative to} the parent space $M$.\n\tHowever, if $M$ is understood we can abbreviate\n\t``open in $M$'' to just ``open''.\n\\end{abuse}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{asy}\n\t\tsize(5cm);\n\t\tdraw(unitcircle, dashed);\n\t\tpair P = Drawing(\"p\", (0.6,0.2), dir(-90));\n\t\tdraw(CR(P, 0.3), dotted);\n\t\tMP(\"x^2+y^2<1\", dir(45), dir(45));\n\t\\end{asy}\n\t\\caption{The set of points $x^2+y^2<1$ in $\\RR^2$ is open in $\\RR^2$.}\n\t\\label{fig:example_open}\n\\end{figure}\n\n\\begin{example}[Examples of open sets]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii Any $r$-neighborhood of a point is open.\n\t\t\\ii Open intervals of $\\RR$ are open in $\\RR$, hence the name!\n\t\tThis is the prototypical example to keep in mind.\n\t\t\\ii The open unit ball $B^n$ is open in $\\RR^n$ for the same reason.\n\t\t\\ii In particular, the open interval $(0,1)$ is open in $\\RR$.\n\t\tHowever, if we embed it in $\\RR^2$, it is no longer open!\n\t\t\\ii The empty set $\\varnothing$ and the whole set of points $M$ are open in $M$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Non-examples of open sets]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The closed interval $[0,1]$ is not open in $\\RR$.\n\t\tThere is no $\\eps$-neighborhood of the point $0$\n\t\twhich is contained in $[0,1]$.\n\t\t\\ii The unit circle $S^1$ is not open in $\\RR^2$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{ques}\n\tWhat are the open sets of the discrete space?\n\\end{ques}\n\nHere are two quite important properties of open sets.\n\\begin{proposition}\n\t[Intersections and unions of open sets]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The intersection of finitely many open sets is open.\n\t\t\\ii The union of open sets is open, even if there are infinitely many.\n\t\\end{enumerate}\n\\end{proposition}\n\\begin{ques}\n\tConvince yourself this is true.\n\\end{ques}\n\\begin{exercise}\n\tExhibit an infinite collection of open sets in $\\RR$\n\twhose intersection is the set $\\{0\\}$.\n\tThis implies that infinite intersections of open sets are not necessarily open.\n\\end{exercise}\n\nThe whole upshot of this is:\n\\begin{theorem}[Open set condition]\n\t\\label{thm:open_set}\n\tA function $f \\colon M \\to N$ of metric spaces is continuous\n\tif and only if the pre-image of every open set in $N$ is open in $M$.\n\\end{theorem}\n\\begin{proof}\n\tI'll just do one direction\\dots\n\t\\begin{exercise}\n\t\tShow that $\\delta$-$\\eps$ continuity follows from\n\t\tthe open set continuity.\n\t\\end{exercise}\n\tNow assume $f$ is continuous.\n\tFirst, suppose $V$ is an open subset of the metric space $N$;\n\tlet $U = f\\pre(V)$. Pick $x \\in U$, so $y = f(x) \\in V$; we want an\n\topen neighborhood of $x$ inside $U$.\n\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(12cm);\n\t\t\tbigblob(\"$N$\");\n\t\t\tpair Y = Drawing(\"y\", origin, dir(75));\n\t\t\treal eps = 1.5;\n\t\t\tdraw(CR(Y, eps), dotted);\n\t\t\tlabel(\"$\\varepsilon$\", Drawing(Y--(Y+eps*dir(255))));\n\t\t\tlabel(\"$V$\",\n\t\t\t\tDrawing(shift(-0.5,0)*rotate(190)*scale(3.2,2.8)*unitcircle, dashed));\n\t\t\tadd(shift( (13,0) ) * CC());\n\t\t\tlabel(\"$f$\", Drawing( (4.5,0)--(8,0), EndArrow));\n\n\t\t\tbigblob(\"$M$\");\n\t\t\treal delta = 1.1;\n\t\t\tpair X = Drawing(\"x\", (-1.5,-0.5), dir(-45));\n\t\t\tlabel(\"$\\delta$\", Drawing(X--(X+delta*dir(155))));\n\t\t\tdraw(CR(X, delta), dotted);\n\t\t\tlabel(\"$U = f^{\\text{pre}}(V)$\",\n\t\t\t\tDrawing(shift(-1.5,-0.3)*rotate(235)*scale(2.4,1.8)*unitcircle, dashed));\n\t\t\\end{asy}\n\t\\end{center}\n\n\tAs $V$ is open, there is some small $\\eps$-neighborhood around $y$\n\twhich is contained inside $V$.\n\tBy continuity of $f$, we can find a $\\delta$ such that the $\\delta$-neighborhood\n\tof $x$ gets mapped by $f$ into the $\\eps$-neighborhood in $N$,\n\twhich in particular lives inside $V$.\n\tThus the $\\delta$-neighborhood lives in $U$, as desired.\n\\end{proof}\n\n%From this we can get a new definition of homeomorphism\n%which makes it clear why open sets are good things to consider.\n%\\begin{theorem}\n%\t[Open set formulation of homeomorphism]\n%\tA function $f \\colon M \\to N$ of metric spaces is a\n%\thomeomorphism if and only if\n%\t\\begin{enumerate}[(i)]\n%\t\t\\ii It is a bijection of the underlying points.\n%\t\t\\ii It induces a bijection of the open sets of $M$ and $N$:\n%\t\tfor any open set $U \\subseteq M$ the set $f\\im(U)$ is open,\n%\t\tand for any open set $V \\subseteq N$ the set $f\\pre(V)$ is open.\n%\t\\end{enumerate}\n%\\end{theorem}\n\n\\section{Closed sets}\n\\prototype{The closed unit disk $x^2+y^2 \\le r^2$ in $\\RR^2$.}\nIt would be criminal for me to talk about open sets\nwithout talking about closed sets.\nThe name ``closed'' comes from the definition in a metric space.\n\\begin{definition}\n\tLet $M$ be a metric space.\n\tA subset $S \\subseteq M$ is \\vocab{closed} in $M$ if the following property holds:\n\tlet $x_1$, $x_2$, \\dots be a sequence of points in $S$\n\tand suppose that $x_n$ converges to $x$ in $M$.\n\tThen $x \\in S$ as well.\n\\end{definition}\n\\begin{abuse}\n\tSame caveat: we abbreviate ``closed in $M$'' to just ``closed''\n\tif the parent space $M$ is understood.\n\\end{abuse}\nHere's another way to phrase it.\nThe \\vocab{limit points} of a subset $S \\subseteq M$ are defined by\n\\[ \\lim S \\defeq \\left\\{ p \\in M :\n\t\\exists (x_n) \\in S \\text{ such that } x_n \\to p \\right\\}. \\]\nThus $S$ is closed if and only if $S = \\lim S$.\n\n\\begin{exercise}\n\tProve that $\\lim S$ is closed even if $S$ isn't closed. (Draw a picture.)\n\\end{exercise}\nFor this reason, $\\lim S$ is also called the\n\\vocab{closure} of $S$ in $M$, and denoted $\\ol S$.\nIt is simply the smallest closed set which contains $S$.\n\n\\begin{example}\n\t[Examples of closed sets]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii The empty set $\\varnothing$ is closed in $M$ for vacuous reasons:\n\t\tthere are no sequences of points with elements in $\\varnothing$.\n\t\t\\ii The entire space $M$ is closed in $M$ for tautological reasons.\n\t\t(Verify this!)\n\t\t\\ii The closed interval $[0,1]$ in $\\RR$ is closed in $\\RR$, hence the name.  Like with open sets, this is the prototypical example of a closed set to keep in mind!\n\t\t\\ii In fact, the closed interval $[0,1]$ is even closed in $\\RR^2$.\n\t\\end{enumerate}\n\\end{example}\n\\begin{example}\n\t[Non-examples of closed sets]\n\tLet $S=(0,1)$ denote the open interval.\n\tThen $S$ is not closed in $\\RR$\n\tbecause the sequence of points\n\t\\[\n\t\t\\frac12, \\;\n\t\t\\frac14, \\;\n\t\t\\frac18, \\;\n\t\t\\dots\n\t\\]\n\tconverges to $0 \\in \\RR$, but $0 \\notin (0,1)$.\n\\end{example}\n\nI should now warn you about a confusing part of this terminology.\nFirstly, \\textbf{``most'' sets are neither open nor closed}.\n\\begin{example}[A set neither open nor closed]\n\tThe half-open interval $[0,1)$ %chktex 9\n\tis neither open nor closed in $\\RR$.\n\\end{example}\nSecondly, it's \\textbf{also possible for a set to be both open and closed};\nthis will be discussed in \\Cref{ch:top_more}.\n\nThe reason for the opposing terms is the following theorem:\n\\begin{theorem}[Closed sets are complements of open sets]\n\tLet $M$ be a metric space, and $S \\subseteq M$ any subset.\n\tThen the following are equivalent:\n\t\\begin{itemize}\n\t\t\\ii The set $S$ is closed in $M$.\n\t\t\\ii The complement $M \\setminus S$ is open in $M$.\n\t\\end{itemize}\n\\end{theorem}\n\\begin{exercise}\n\t[Great]\n\tProve this theorem!\n\tYou'll want to draw a picture to make it clear what's happening:\n\tfor example, you might take $M = \\RR^2$ and $S$ to be the closed unit disk.\n\\end{exercise}\n\n\\section{\\problemhead}\n\\begin{problem}\n\tLet $M = (M,d)$ be a metric space.\n\tShow that \\[ d \\colon M \\times M \\to \\RR \\]\n\tis itself a continuous function\n\t(where $M \\times M$ is equipped with the product metric).\n\\end{problem}\n\n\\begin{problem}\n\tAre $\\QQ$ and $\\NN$ homeomorphic subspaces of $\\RR$?\n\t\\begin{hint}\n\t\tNo.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tIn $\\QQ$, no singleton set is open,\n\t\twhereas in $\\NN$, they all are (in fact $\\NN$ is discrete).\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t[Continuity of arithmetic continued]\n\t\\label{prob:subtract_divide}\n\tShow that subtraction is a continuous map $- \\colon \\RR \\times \\RR \\to \\RR$,\n\tand division is a continuous map $\\div \\colon \\RR \\times \\RR_{>0} \\to \\RR$.\n\t\\begin{hint}\n\t\tYou can do this with bare hands.\n\t\tYou can also use composition.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tFor subtraction, the map $x \\mapsto -x$ is continuous\n\t\tso you can view it as a composed map\n\t\t\\begin{center}\n\t\t\\begin{tikzcd}\n\t\t\t\\RR \\times \\RR \\ar[r, \"{(\\id,-x)}\"]\n\t\t\t\t& \\RR \\times \\RR \\ar[r, \"+\"] & \\RR \\\\[1ex]\n\t\t\t(a,b) \\ar[r, mapsto] & (a,-b) \\ar[r, mapsto] &  a-b.\n\t\t\\end{tikzcd}\n\t\t\\end{center}\n\t\tSimilarly, if you are willing to believe $x \\mapsto 1/x$\n\t\tis a continuous function, then division is composition\n\t\t\\begin{center}\n\t\t\\begin{tikzcd}\n\t\t\t\\RR \\times \\RR_{>0} \\ar[r, \"{(\\id, 1/x)}\"]\n\t\t\t\t& \\RR \\times \\RR_{>0} \\ar[r, \"\\times\"] & \\RR \\\\\n\t\t\t(a,b) \\ar[r, mapsto] & (a,1/b) \\ar[r, mapsto] & a/b.\n\t\t\\end{tikzcd}\n\t\t\\end{center}\n\t\tIf for some reason you are suspicious that $x \\mapsto 1/x$ is continuous,\n\t\tthen here is a proof using sequential continuity.\n\t\tSuppose $x_n \\to x$ with $x_n > 0$ and $x > 0$\n\t\t(since $x$ needs to be in $\\RR_{>0}$ too).\n\t\tThen \\[ \\left\\lvert \\frac{1}{x} - \\frac 1{x_n} \\right\\rvert\n\t\t\t= \\frac{\\left\\lvert x_n-x \\right\\rvert}{\\left\\lvert x x_n \\right\\rvert}.\n\t\t\\]\n\t\tIf $n$ is large enough, then $\\left\\lvert x_n \\right\\rvert > x/2$;\n\t\tso the denominator is at least $x^2/2$,\n\t\tand hence the whole fraction is at most\n\t\t$\\frac{2}{x^2} \\left\\lvert x_n-x \\right\\rvert$,\n\t\twhich tends to zero as $n \\to \\infty$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\tExhibit a function $f \\colon \\RR \\to \\RR$ such that\n\t$f$ is continuous at $x \\in \\RR$ if and only if $x=0$.\n\t\\begin{hint}\n\t\t$\\pm x$ for good choices of $\\pm$.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tLet $f(x) = x$ for $x \\in \\QQ$ and $f(x) = -x$ for irrational $x$.\n\t\\end{sol}\n\\end{problem}\n\n\\begin{problem}\n\t\\yod\n\tProve that a function $f \\colon \\RR \\to \\RR$ which is strictly increasing\n\tmust be continuous at some point.\n\t\\begin{hint}\n\t\tProject gaps onto the $y$-axis.\n\t\tUse the fact that uncountably many positive reals cannot have finite sum.\n\t\\end{hint}\n\t\\begin{sol}\n\t\tAssume for contradiction it is completely discontinuous;\n\t\tby scaling set $f(0) = 0$, $f(1) = 1$ and focus just on $f : [0,1] \\to [0,1]$.\n\t\tSince it's discontinuous everywhere,\n\t\tfor every $x \\in [0,1]$ there's an $\\eps_x > 0$\n\t\tsuch that the continuity condition fails.\n\t\tSince the function is strictly increasing,\n\t\tthat can only happen if the\n\t\tfunction misses all $y$-values in the interval\n\t\t$(fx-\\eps_x, fx)$ or $(fx, fx+\\eps_x)$ (or both).\n\n\t\tProjecting these missing intervals to the $y$-axis you find uncountably\n\t\tmany intervals (one for each $x \\in [0,1]$) all of which are disjoint.\n\t\tIn particular, summing the $\\eps_x$ you get that a sum of uncountably\n\t\tmany positive reals is $1$.\n\n\t\tBut in general it isn't possible for an uncountable family $\\mathcal F$\n\t\tof positive reals to have finite sum.\n\t\tIndeed, just classify the reals into buckets $\\frac1k \\le x < \\frac1{k-1}$.\n\t\tIf the sum is actually finite then each bucket is finite,\n\t\tso the collection $\\mathcal F$ must be countable, contradiction.\n\t\\end{sol}\n\\end{problem}\n", "meta": {"hexsha": "a904dd6cc7a6e54c1601f3785ba595f264167210", "size": 29904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/topology/metric-top.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/topology/metric-top.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/topology/metric-top.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.8729963009, "max_line_length": 250, "alphanum_fraction": 0.6799090423, "num_tokens": 9890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.9073122307591682, "lm_q1q2_score": 0.7866721556086798}}
{"text": "\n\\subsection{Axiom of union}\n\n\n\\subsubsection{Motivation}\n\nWhile we have described various sets, we have not said that they exist. That is, if \\(A\\) and \\(B\\) both exist, then currently we cannot ensure \\(A\\land B\\) exists, just that it can be described.\n\nThe axiom of union enables us to ensure all sets from unions and intersections exist.\n\n\\subsubsection{Axiom of union}\n\n\\(\\forall a\\exists b \\forall c [c\\in b\\leftrightarrow \\exists d(c\\in d\\land d\\in a)]\\)\n\nThat is, for every set \\(a\\), there exists a set \\(b\\) where all the elements in \\(b\\) are the elements of the elements in \\(a\\).\n\nHere, \\(b\\) is the union of the sets in \\(a\\).\n\n", "meta": {"hexsha": "c1dde996fc909ed83cf558ebae0c3346db549e6a", "size": 642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsAxiomUnion/01-01-union.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/setsAxiomUnion/01-01-union.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/setsAxiomUnion/01-01-union.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.7894736842, "max_line_length": 195, "alphanum_fraction": 0.7056074766, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299529686201, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7864187856039785}}
{"text": "\\chapter{Logistic Regression and Regularization}\n\nNow we turn away from regression to classification problems. Don't be confused by the name `logistic regression,' it's actually just named for the mathematical function and it's a common approach to classification.\n\n\\section{Binary Classification}\nIn classification problems, instead of our output being continuous, we expect it to fall into discrete classes. We'll start with the simplest case: binary classification. Here, we have our output variable $y \\in \\{0, 1\\}$. Typically, we take $0$ as the negative class and $1$ as the positive class. \n\nConsider the following example: we have a sample of eight tumors, and we want to determine if they're malignant based on the tumor size. These are plotted in Figure \\ref{logreg-eg-maltumor-noregline}. One thing we can do is assume a linear relationship with hypothesis $h_\\theta\\left( \\vec{x} \\right) = \\vec{\\theta}^\\intercal \\vec{x}$. This shown in Figure \\ref{logreg_eg1_maltumor_linreg1}.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n  \t\t\\includegraphics[scale=0.3]{logreg_eg1_maltumor.pdf} \n   \t\t\\caption[]{Sample tumor data.}\n   \t\t\\label{logreg-eg-maltumor-noregline}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.3]{logreg_eg1_maltumor_linreg1.pdf} \n   \t\t\\caption[]{Plot of tumors by size with linear regression line $y =  \\frac{x-1}{6} - 0.25$.}\n   \t\t\\label{logreg_eg1_maltumor_linreg1}\n\t\\end{subfigure}\n\t\\caption[]{Plots of tumors by size.}\n\\end{figure}\n\nTo try and make predictions, we can threshold the output at $h_\\theta\\left( x \\right) = 0.5$, and then:\n\\begin{itemize}\n\\item If $h_\\theta\\left(x\\right) \\geq 0.5$, then predict $y = 1$\n\\item If $h_\\theta\\left( x \\right) < 0.5$, then predict $y = 0$\n\\end{itemize}\nand you can see this in Figure \\ref{logreg_eg1_maltumor_linreg1_threshold.pdf}.\n\n\\begin{figure}[h] \n\t\\centering\n\t\\graphicspath{{./Figures/}} \n\t\\includegraphics[scale=0.4]{logreg_eg1_maltumor_linreg1_threshold.pdf} \n\t\\caption[]{Linear regression plotted with classification regions. }\n\t\\label{logreg_eg1_maltumor_linreg1_threshold.pdf}\n\\end{figure}\n\n\nIn this example, it would seem like linear regression is a good classifier. However, what if we add a new data point for a large tumor. Suddenly, our results look like this\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.4]{logreg_eg1_maltumor_linreg1_newpoint.pdf} \n\t\\caption[]{Linear regression plotted with classification regions after a new data point is added. Notice how one of the malignant tumors is now being misclassified as benign.}\n\t\\label{logreg_eg1_maltumor_linreg1_newpoint.pdf}\n\\end{figure}\n\nand now, we have a malignant tumor being misclassified as benign. Ergo, maybe linear regression isn't the best way to build a binary classifier. \n\n\n\n\n\n\n\\section{Hypothesis Representation}\nIn linear regression, our hypothesis was $h_\\theta\\left(\\vec{x}\\right) = \\vec{\\theta}^\\intercal \\vec{x}$ For logistic regression, we want our hypothesis to satisfy $0 \\leq h_\\theta\\left(x\\right) \\leq 1$. To do this, we use the sigmoid function.\\footnote{This is also called the logistic function, and is the namesake for logistic regression.} To make this work, we modify our hypothesis to be\n\\begin{equation}\nh_\\theta\\left(x\\right) = g\\left(\\vec{\\theta}^\\intercal \\vec{x}\\right)\n\\end{equation}\nwhere the function $g\\left(z\\right)$ is defined as\n\\begin{equation}\ng\\left(z\\right) = \\frac{1}{1 + e^{-z}}\n\\end{equation}\nThus, to get the hypothesis function using the sigmoid function, just set $z = \\vec{\\theta}^\\intercal \\vec{x}$. \n\nThe sigmoid function, shown in Figure \\ref{logreg_eg2_sigmoid_func_plot.pdf}, maps any real number onto the interval $\\left(0, 1\\right)$. This makes it immensely useful for transforming an arbitrary function for use with classification.\n\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.4]{logreg_eg2_sigmoid_func_plot.pdf} \n\t\\caption[]{Sample plot of the sigmoid function.}\n\t\\label{logreg_eg2_sigmoid_func_plot.pdf}\n\\end{figure}\n\n\n\\subsection{Interpretation of the Logistic Hypothesis Function}\n\nWhen examining the hypothesis function output for logistic regression, we interpret $h_\\theta\\left(x \\right)$ is the estimated probability that $y=1$ on an input example $x$. For example, let's revisit the tumor size question from above. We have \n$$\n\\vec{x} = \\left[\\begin{array}{c}x_0 \\\\ x_1 \\end{array}\\right] = \\left[\\begin{array}{c}1 \\\\ \\text{tumor size} \\end{array}\\right]\n$$\nIf our hypothesis $h_\\theta\\left( x \\right) = 0.7$, then we can tell the patient that there is a 70\\% chance of the tumor being malignant. \n\nSlightly more formally, we interpret $h_\\theta\\left(x\\right)$ as:\\footnote{This is read as \"the probability that $y = 1$, given $x$, parameterized by $\\theta$.}\n\\begin{equation}\nh_\\theta\\left(x\\right) = P\\left(y=1 | x; \\theta\\right)\n\\end{equation}\nThus, by the rules of probability:\n\\begin{align}\nP\\left(y=0 | x; \\theta\\right) + P\\left(y=1 | x; \\theta\\right) = 1 \\\\\nP\\left(y=0 | x; \\theta\\right) = 1 - P\\left(y=1 | x; \\theta\\right)\n\\end{align}\n\n\n\\subsection{Fitting Logistic Regression to a Binary Classifier}\n\\label{chaplogreg-sect-hyporeg-subsectbinclasfit}\nNow, we need to fit our hypothesis function into a binary classfier: $0$ or $1$. Using our probabilistic interpretation of the logistic hypothesis function, we can make the following supposition:\n\n\\begin{align}\ny  = 1 &\\text{ given that } h_\\theta\\left(x\\right) \\geq 0.5 \\\\\ny = 0 &\\text{ given that } h_\\theta\\left(x\\right) < 0.5\n\\end{align}\n\nRecall the plot of the sigmoid function in Figure \\ref{logreg_eg2_sigmoid_func_plot.pdf}. We see that $g\\left(z\\right) \\geq 0.5$ when $z \\geq 0$. In our case, if we're setting $z = \\vec{\\theta}^\\intercal \\vec{x}$, then we have:\n\n\\begin{equation}\nh_\\theta\\left(x\\right) = g\\left(\\vec{\\theta}^\\intercal\\vec{x}\\right) \\geq 0.5 ~~\\mbox{ when }~~ \\vec{\\theta}^\\intercal\\vec{x} \\geq 0\n\\end{equation}\n\n\\noindent From this, we can now state\n\\begin{align}\n\\vec{\\theta}^\\intercal\\vec{x} \\geq 0 &\\implies y = 1 \\\\\n\\vec{\\theta}^\\intercal\\vec{x} < 0 &\\implies y= 0\n\\end{align}\n\n\\noindent When utilizing the sigmoid function, keep the following in mind:\n\\begin{itemize}\n\\item When $z = 0$, then $e^0 = 1$ so $g\\left(x\\right) = \\frac{1}{2}$\n\\item When $z$ goes to $\\infty$, we have $e^{-\\infty} \\to 0$, and this implies $g\\left(x\\right) = 1$\n\\item As $z \\to -\\infty$, $e^\\infty \\to \\infty \\implies g\\left(z\\right) = 0$\n\\end{itemize}\n\n\n\\section{Decision Boundary}\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.4]{logreg_eg3_decision_bndy_noline.pdf} \n\t\\caption[]{Sample data.}\n\t\\label{logreg_eg3_decision_bndy_noline.pdf}\n\\end{figure}\n\nConsider the data plotted in Figure \\ref{logreg_eg3_decision_bndy_noline.pdf}. Suppose our hypothesis is given by\n$$\nh_\\theta\\left(x\\right) = g\\left(\\theta_0 + \\theta_1x_1 + \\theta_2x_2\\right)\n$$\nWe haven't yet discussed how to fit the parameters of this model (that's coming up next), but suppose we choose the following values for the parameters\n$$\n\\vec{\\theta} = \\left[\\begin{array}{c}\\theta_0 \\\\ \\theta_1 \\\\ \\theta_2\\end{array}\\right] = \\left[\\begin{array}{c} -3 \\\\ 1 \\\\ 1 \\end{array}\\right]\n$$\n\nGiven this choice of parameters, let's figure out where $y=1$ and where $y=0$. From \\S\\ref{chaplogreg-sect-hyporeg-subsectbinclasfit}, recall that we predict $y=1$ when $\\vec{\\theta}^\\intercal\\vec{x} \\geq 0$, so here, we predict $y=1$ if $-3 + x_1 + x_2 \\geq 0$. If we solve this for $x_1 + x_2$ we get\n$$\nx_1 + x_2 \\geq 3 \\implies y = 1\n$$\nIf we change this to a pure equality, $x_1 + x_2 = 3$, we have the equation of a straight line (shown on Figure \\ref{logreg_eg3_decision_bndy_withline.pdf}). The line drawn, is called the \\textbf{decision boundary}. The decision boundary is the line created by the hypothesis function that separates the area where we classify $y=0$ and where $y=1$.\n\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.4]{logreg_eg3_decision_bndy_withline.pdf} \n\t\\caption[]{Some sample binary data with a plotted decision boundary. Here, the blue circles represent $y=0$, the green triangles $y=1$ and the purple line is the decision boundary.}\n\t\\label{logreg_eg3_decision_bndy_withline.pdf}\n\\end{figure}\n\nTo be clean, the decision boundary is a property of the hypothesis function, and not a property of the dataset. We fit the parameters of the hypothesis based on the training data, but once those parameters are set, the decision boundary is a property solely of the hypothesis function. \n\nNow, suppose we have data as shown below in Figure \\ref{logreg_eg3_decision_bndy_nonlinear_nocirc.pdf}. It's fairly obvious that no straight line decision boundary will work for this data. Again, we don't know how to fit the parameters for this model yet, but say our hypothesis function looks like this\n$$\nh_\\theta\\left(x\\right) = g\\left(\\theta_0 + \\theta_1x_1 + \\theta_2x_2 + \\theta_3x_1^2 + \\theta_4x_2^2\\right)\n$$\nImagine we fit the parameters appropriately, and we get\n$$\n\\vec{\\theta} = \\left[\\begin{array}{c} \\theta_0 \\\\ \\theta_1 \\\\ \\theta_2 \\\\ \\theta_3 \\\\ \\theta_4 \\end{array}\\right] = \\left[\\begin{array}{c}-1 \\\\ 0 \\\\ 0 \\\\ 1 \\\\ 1 \\end{array}\\right]\n$$\nThen, our hypothesis predicts that $y=1$ when $x_1^2 + x_2^2 \\geq 1$. This is the equation for a circle of radius $1$, centered at the origin (see Figure \\ref{logreg_eg3_decision_bndy_nonlinear.pdf}).\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n  \t\t\\includegraphics[scale=0.4]{logreg_eg3_decision_bndy_nonlinear_nocirc.pdf} \n   \t\t\\caption[]{This is a sample of data with no clear linear decision boundary.}\n   \t\t\\label{logreg_eg3_decision_bndy_nonlinear_nocirc.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.4]{logreg_eg3_decision_bndy_nonlinear.pdf} \n   \t\t\\caption[]{By altering our hypothesis function to include polynomial terms, we can have a non-linear decision boundary.}\n   \t\t\\label{logreg_eg3_decision_bndy_nonlinear.pdf}\n\t\\end{subfigure}\n\t\\caption[]{Data that can't be fit with a linear decision line.}\n\\end{figure}\nIn this case, we predict $y=1$ everywhere outside the purple circle, and $y=0$ everywhere inside the circle. \n\nWith even higher order polynomials, we can get even more complicated decision boundaries. \n\n\n\\section{Cost Function}\nImagine we have a training set of data with $m$ examples\n$$\n\\left\\{ \\left(x^{\\left(1\\right)}, y^{\\left(1\\right)}\\right), \\left(x^{\\left(2\\right)}, y^{\\left(2\\right)}\\right), \\cdots, \\left(x^{\\left(m\\right)}, y^{\\left(m\\right)}\\right) \\right\\}\n$$\nand $n$ features, represented by an $n+1$-dimensional feature vector\n$$\nx \\in \\left[\\begin{array}{c} x_0 \\\\ x_1 \\\\ \\vdots \\\\ x_n \\end{array}\\right]\n$$\nwhere $x_0 = 1$ and our output $y \\in \\{0, 1\\}$. Our hypothesis is given by\n\\begin{equation}\nh_\\theta\\left(x\\right) = \\frac{1}{1 + e^{-\\theta^{{}^\\intercal}x}}\n\\end{equation}\nHow do we choose the parameters for this model? For linear regression, we had the following cost function (adjusted slightly, we moved the $\\tfrac{1}{2}$ to the inside of the summation)\n\\begin{equation}\nJ\\left(\\theta\\right) = \\frac{1}{m} \\sum_{i=1}^m \\frac{1}{2} \\left(\t\th_\\theta\\left(x^{\\left(i\\right)}\\right) - y^{\\left(i\\right)}\t\\right)^2\n\\end{equation}\nbut we're going to change how we write this function a little bit. Instead, we'll write\n\\begin{equation}\nJ\\left(\\theta\\right) = \\frac{1}{m} \\sum_{i=1}^m \\text{Cost}\\left(\th_\\theta\\left(x^{\\left(i\\right)}\\right), y^{\\left(i\\right)}\\right)\n\\end{equation}\nwhere we'll define the cost to be\n\\begin{equation}\n\\text{Cost}\\left(\th_\\theta\\left(x^{\\left(i\\right)}\\right), y^{\\left(i\\right)}\\right) = \\frac{1}{2} \\left(h_\\theta\\left(x^{\\left(i\\right)}\\right) - y^{\\left(i\\right)}\t\\right)^2\n\\end{equation}\nThis allows us to see more clearly that the cost function is really the sum over the cost term. To simplify even further, we'll remove the superscripts $\\left(i\\right)$\n\\begin{equation}\n\\text{Cost}\\left(h_\\theta\\left(x\\right), y\\right) = \\frac{1}{2} \\left(\th_\\theta\\left(x\\right) - y \\right)^2\n\\end{equation}\n\n\nIf we try to minimize this function called Cost, it turns out to be a non-convex function. That means that the may be several local minima, which would prevent our gradient descent algorithm from working well. You can see a sample non-convex function in Figure \\ref{logreg_eg4_sample_nonconvex_curve.pdf}. What we want instead, is a convex function (like a parabola) that only has a single minimum that is the global minimum. The sigmoid function is a non-linear signal function, so $J\\left(\\theta\\right)$ ends up being non-convex. \n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.6]{logreg_eg4_sample_nonconvex_curve.pdf} \n\t\\caption[]{A non-convex curve. Notice all of the local minima.}\n\t\\label{logreg_eg4_sample_nonconvex_curve.pdf}\n\\end{figure}\n\nWe need to define a new (convex) function that will allow us to determine the parameters in our hypothesis. For logistic regression, we use the following function\n\\begin{equation}\n\\text{Cost}\\left(h_\\theta\\left(x\\right), y\\right) = \\begin{cases} -\\log\\left(h_\\theta\\left(x\\right)\\right) & \\text{if } y = 1 \\\\ -\\log\\left(1 - h_\\theta\\left(x\\right)\\right) &\\text{if } y = 0 \\end{cases}\n\\end{equation}\nWe plot this function below in Figure \\ref{chaplogreg-sectcostfunct-plotcostfuncsample}. \n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n  \t\t\\includegraphics[scale=0.5]{logreg_eg5_cost_func_y1.pdf} \n   \t\t\\caption[]{$y=1$.}\n   \t\t\\label{logreg_eg5_cost_func_y1.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.5]{logreg_eg5_cost_func_y0.pdf} \n   \t\t\\caption[]{$y=0$}\n   \t\t\\label{logreg_eg5_cost_func_y0.pdf}\n\t\\end{subfigure}\n\t\\caption[]{The piecewise function used for the logistic regression cost function. }\n\t\\label{chaplogreg-sectcostfunct-plotcostfuncsample}\n\\end{figure}\n\nThe shape of the curve comes from standard plot of $\\log\\left(x\\right)$, and we just use a negative to flip it upside-down. This function, has some very desirable properties for us right now. \n\n\n\\noindent \\begin{minipage}{\\linewidth}\n\\begin{itemize}\n\\item If $y = 1$, then $h_\\theta\\left(x\\right) = 1$ and the cost is zero. However, as $h_\\theta\\left(x\\right) \\to 0$ then $\\text{cost} \\to \\infty$. This captures the intuition that if $h_\\theta\\left(x\\right) = 0$, but $y=1$, we'll penalize the learning algorithm by a very large cost. \n\\item For $y=0$, this is reversed. If we have $y=0$ and $h_\\theta\\left(x\\right) = 0$, then the cost is $0$. If $y=0$, the cost grows very large as $h_\\theta\\left(x\\right)$ increases towards $1$. \n\\end{itemize}\n\\end{minipage}\n\n\n\\subsection{Simplified Cost Function}\nRecall our cost function \n\\begin{equation}\nJ\\left(\\theta\\right) = \\frac{1}{m} \\sum_{i=1}^m \\text{Cost}\\left(\th_\\theta\\left(x^{\\left(i\\right)}\\right), y^{\\left(i\\right)}\\right)\n\\end{equation}\nwhere the cost is \n\\begin{equation}\n\\text{Cost}\\left(h_\\theta\\left(x\\right), y\\right) = \\begin{cases} -\\log\\left(h_\\theta\\left(x\\right)\\right) & \\text{if } y = 1 \\\\ -\\log\\left(1 - h_\\theta\\left(x\\right)\\right) &\\text{if } y = 0\n\\end{cases}\n\\end{equation}\nand $y \\in \\{0, 1\\}$. \nSince $y$ is always either $0$ or $1$, we can take advantage of this to write a simplified version of our cost function:\n\\begin{equation}\n\\text{Cost}\\left(h_\\theta\\left(x\\right), y\\right) = -y\\log\\left(h_\\theta\\left(x\\right)\\right) - \\left( 1-y \\right) \\log\\left(1 - h_\\theta\\left(x\\right)\\right)\n\\end{equation}\nFor either value of $y$, one of the terms will be multiplied by zero and disappear. So now, our cost function is\\footnote{Just as an FYI, this cost function is derived statistically using maximum likelihood estimation}\n\\begin{align}\nJ\\left(\\theta\\right) &= \\frac{1}{m} \\sum_{i=1}^m \\text{Cost}\\left(\th_\\theta\\left(x^{\\left(i\\right)}\\right), y^{\\left(i\\right)}\\right) \\nonumber \\\\\n\\label{chaplogreg-sectsimpcostfunct-simpcostfuncformula}\n&= -\\frac{1}{m} \\left[ \\sum_{i=1}^m y^{\\left(i\\right)} \\log h_\\theta\\left(x^{\\left(i\\right)}\\right) + \\left(1 - y^{\\left(i\\right)}\\right) \\log \\left(1 - h_\\theta\\left(x^{\\left(i\\right)}\\right)\\right)\\right]\n\\end{align}\nWe want to minimize the cost function$J\\left(\\theta\\right)$ to fit the parameters $\\theta$, so we can make our predictions using the hypothesis function. Again, we determine $\\theta$ by calculating \n$$\n\\min_\\theta J\\left(\\theta\\right) \n$$\nand predict using \n$$\nh_\\theta\\left(x\\right) = \\frac{1}{1 + e^{\\theta^{{}^\\intercal}x}}\n$$\nusing the calculated parameters. Now, we just need to determine how to minimize $J\\left(\\theta\\right)$. \n\n\\subsection{Gradient Descent for Logistic Regression}\n\nWe again return to gradient descent, of the form \n\n\n\\textbf{Repeat until convergence:}\n\\begin{equation}\n\\label{chaplogreg-sectcostfunct-subsectgraddscnt-logreggraddscnt}\n\\theta_j := \\theta_j - \\alpha \\frac{\\partial}{\\partial \\theta_j} J\\left( \\theta \\right)\n\\end{equation}\nwhere we simultaneously update all $\\theta_j$. If we calculate the partial derivative $\\frac{\\partial}{\\partial \\theta_j} J\\left(\\theta\\right)$, we find\n\\begin{equation}\n\\frac{\\partial}{\\partial \\theta_j} J\\left(\\theta\\right) = \\frac{1}{m}\\sum_{i=1}^m \\left( h_\\theta\\left(x^{\\left(i\\right)}\\right) - y^{\\left(i\\right)}\\right) x_j^{\\left(i\\right)}\n\\end{equation}\nPlugging this back into the formula for gradient descent, we get\n\n\n\\textbf{Repeat until convergence:}\n\\begin{equation}\n\\theta_j := \\theta_j - \\frac{\\alpha}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{\\left(i\\right)}\\right) - y^{\\left(i\\right)}\\right) x_j^{\\left(i\\right)}\n\\end{equation}\nBut wait! This looks exactly like the formula for linear regression! Is this actually a different algorithm? Yes! It is! The difference here is that the hypothesis function $h_\\theta\\left(x\\right)$ is a different function. \n\nRemember that for gradient descent, we often need to apply feature scaling to make the algorithm run faster. \n\n\n\\section{Vectorized Equations}\nIn equation \\ref{chaplogreg-sectsimpcostfunct-simpcostfuncformula}, we derived a simplified version of the cost function. We can do the same thing with a vectorized implementation. First, we state the vectorized hypothesis function as\n\\begin{equation}\nh = g\\left( X\\vec{\\theta}\\right)\n\\end{equation}\nand then we can write the simplified cost function as\n\\begin{equation}\nJ\\left(\\theta\\right) = \\frac{1}{m}\\cdot \\left( -\\vec{y}^\\intercal \\log\\left(h\\right) - \\left(1 - \\vec{y}\\right)^\\intercal \\log \\left(1 - h\\right)\\right)\n\\end{equation}\nFinally, we write out the vectorized form for gradient descent\n\\begin{equation}\n\\vec{\\theta} := \\vec{\\theta} - \\frac{\\alpha}{m}X^\\intercal \\left( g\\left(X\\vec{\\theta}\\right) - \\vec{y}\\right)\n\\end{equation}\n\n\\section{Advanced Optimization}\n\nThere are other, more sophisticated algorithms that are able to more quickly optimize $\\theta$. These algorithms are a little more complicated, so you shouldn't try to write them yourself unless you're an expert in numerical computing. \n\nIn particular, there are three algorithms that we'll mention:\n\\begin{itemize}\n\\item Conjugate gradient algorithm\n\\item Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm\n\\item L-BFGS-B\n\\end{itemize}\nIn Python, these algorithms (and several others) are available in the {\\tt scipy.optimize} package. The algorithm is chosen using the {\\tt method='X'} flag, where X can be CG, BFGS, or L-BFGS-B, respectively, to use any of the above algorithms. \n\\begin{minted}{python}\nfrom scipy.optimize import minimize\n\\end{minted}\nWe'll go through an example or two in the coding section.\n\n%%%%%%%%%%%%%%%%%%%%%%%%\n%\t\t\t\t\t\t\t\t%\n%\t\tAdd hyperlink to coding\t\t\t%\n%\t\t\t\t\t\t\t\t%\n%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\section{Multiclass Classification: One-vs-All}\n\nWhat is a multiclass classification problem? Here are some examples:\n\\begin{itemize}\n\\item You want to build an algorithm to automatically tag your email with different categories: work, friends, family, and hobby. Here, you have a classification problem for four classes. \n\\item For a medical visit, you might want to classify patients into not ill, having a cold, or having the flu. \n\\item To build an algorithm that classifies the weather into sunny, cloudy, rain, and snow.\n\\end{itemize}\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n  \t\t\\includegraphics[scale=0.45]{logreg_eg6_binary_eg_data.pdf} \n   \t\t\\caption[]{Binary Classification}\n   \t\t\\label{logreg_eg6_binary_eg_data.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.45]{logreg_eg6_multiclass_eg_data.pdf} \n   \t\t\\caption[]{Multiclass Classification}\n   \t\t\\label{logreg_eg6_multiclass_eg_data.pdf}\n\t\\end{subfigure}\n\t\\caption[]{Examples of binary and multiclass classification.}\n%\t\\label{}\n\\end{figure}\nPreviously, for a binary classification problem, our data looked like the data in Figure \\ref{logreg_eg6_binary_eg_data.pdf}, with multiclass classification, the data looks more like Figure \\ref{logreg_eg6_multiclass_eg_data.pdf}.\n\\begin{figure}[h] %  figure placement: here, top, bottom, or page\n\t\\centering\n\t\\graphicspath{{./Figures/}} %Use this to import an image from a subfolder.\n\t\\includegraphics[scale=0.45]{logreg_eg6_multiclass_onevall_step1.pdf} \n\t\\caption[]{One-vs-all classification. We're selecting one class to be our positive class, and the rest all become the negative class.}\n\t\\label{logreg_eg6_multiclass_onevall_step1.pdf}\n\\end{figure}\n\nWe know how to perform binary classification, but how to we make this work with more classes? We can use the idea of one-vs-all classification.\\footnote{This can also be called one-vs-rest classification.} Here's how it works; let's say we have a training set of three classes (such as in Figure \\ref{logreg_eg6_multiclass_eg_data.pdf}). What we can do is turn this into three separate binary classification problems.\\footnote{If we have $n$ different classes, our problem splits into $n+1$ different binary classification problems.This is because the vector $\\vec{y}$ starts at index $0$, so $\\left|\\left|\\vec{y}\\right|\\right| = n+1$.} Start by picking a class, say the blue circles, and make it our positive class; then lump all the other data into the negative class (see Figure \\ref{logreg_eg6_multiclass_onevall_step1.pdf}).\n\nWe fit a classifier to this, called $h_\\theta^{\\left(1\\right)}\\left(x\\right)$. We then do this for the two other classes, and fit them to logistic regression classifiers $h_\\theta^{\\left(2\\right)}\\left(x\\right)$ and $h_\\theta^{\\left(3\\right)}\\left(x\\right)$. Here, we've fit three classifiers\n\\begin{equation}\nh_\\theta^{\\left(i\\right)}\\left(x\\right) = P\\left(y=i | x; 0\\right)\t~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } i = \\{1, 2, 3\\}\n\\end{equation}\nthat are trying to estimate the probability that $y$ is equal to class $i$, given $x$ and parameterized by $\\theta$. So  $h_\\theta^{\\left(i\\right)}\\left(x\\right)$ is trying to estimate the probability that a data point is of class $i$. \n\nFor a new input $x$, to make a prediction, we pick the class $i$ that maximizes \n\\begin{equation}\n\\max_i  h_\\theta^{\\left(i\\right)}\\left(x\\right)\n\\end{equation}\nand this tells us which class to assign the new input to. \n\n\n\n\n\n\\section{Regularization}\nFor the two machine learning algorithms we've seen so far, they tend to work pretty well. But when applied to specific datasets, they can run into a problem called overfitting, and this can cause them to perform very poorly. We're going to discuss a little more detail about this problem, and then go into ways to ameliorate it and increase our algorithm performance. Let's plot some housing data, and then take a look at three potential regressions. \n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[t]{0.3\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n  \t\t\\includegraphics[scale=0.35]{logreg_eg7_housing_data_linreg.pdf} \n   \t\t\\caption[]{Linear Regression}\n   \t\t\\label{logreg_eg7_housing_data_linreg.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.3\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.35]{logreg_eg7_housing_data_quadreg.pdf} \n   \t\t\\caption[]{Quadratic Regression}\n   \t\t\\label{logreg_eg7_housing_data_quadreg.pdf}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.3\\textwidth}\n   \t\t\\centering\n    \t\t\\graphicspath{{./Figures/}}\n   \t\t\\includegraphics[scale=0.35]{logreg_eg7_housing_data_quadreg_overfit.pdf} \n   \t\t\\caption[]{Quadratic Regression with Additional Terms}\n   \t\t\\label{logreg_eg7_housing_data_quadreg_overfit.pdf}\n\t\\end{subfigure}\n\t\\caption[]{Plots of linear and quadratic regressions with varying amounts of terms (features). }\n%\t\\label{}\n\\end{figure}\n\nFigure \\ref{logreg_eg7_housing_data_linreg.pdf} is a linear regression on this data. This is the simplest regression, but looking at the data, it seems pretty clear that this isn't really a good fit. As the size of the house increases, the housing prices seem to plateau after a certain point, whereas the linear regression line keeps increasing. This is known as \\textbf{underfitting}, or \\textbf{high bias}.\\footnote{The term \\textit{bias} is somewhat or a historical or technical term. It carries with it the idea that if fitting a straight line to the data, it's as if the algorithm has a preconception (or bias) that the housing prices should vary linearly with their size, despite evidence in the data that this is not the case. Irrespective of the evidence to the contrary, the algorithm fits the data to a straight line, and it ends up not being a very good fit.} Both of these roughly mean that the regression just isn't fitting to the training data very well. In Figure \\ref{logreg_eg7_housing_data_quadreg.pdf}, we can fit a quadratic function to the data. This seems to work pretty well, and looks like a better fit than the linear regression. Figure \\ref{logreg_eg7_housing_data_quadreg_overfit.pdf} shows what happens when we \\textbf{overfit} the line. This is also known as \\textbf{high variance}. The curve fits the training set very well, but it particular to the specific training set, so it doesn't work well for any other data set. \n\nLet's formally define these terms now:\n\\begin{description}\n\\item[Overfitting] If we have too many features, the learned hypothesis may fit the training set very well ($J\\left(\\theta\\right) \\approx 0$), but fails to generalize to new examples. This is also called high variance. \n\\item[Underfitting] This occurs when the form of our hypothesis function maps poorly to the trend of the data. It is usually caused by a function that is too simple or uses too few features. This is also called high bias. \n\\end{description}\nThis apply to both linear and logistic regression. \n\nSo how do we prevent our models from overfitting to the data? For the simple examples where we have one or two features, we can plot the data and determine it that way; but when we start working with data sets that have hundreds of features, this no longer works. We have two main options to address overfitting:\n\\begin{enumerate}\n\\item Reduce the number of features\n\t\\begin{itemize}\n\t\\item Manually select which features to keep, or\n\t\\item Use a model selection algorithm (which we'll see later)\n\t\\end{itemize}\n\\item Regularization\n\t\\begin{itemize}\n\t\\item Keep all the features, but reduce the parameters $\\theta_j$\n\t\\end{itemize}\n\\end{enumerate}\nRegularization works well when we have a lot of slightly-useful features. \n\n\\subsection{Cost Function}\nIf we suspect overfitting in our hypothesis function, we can reduce the weight of some of the terms in our function by increasing their cost. Say we have a hypothesis of the form\n$$\nh_\\theta\\left(x\\right) = \\theta_0 + \\theta_1x + \\theta_2x^2 + \\theta_3x^3 + \\theta_4x^4\n$$\nTo reduce the effect of $\\theta_3x^3$ and $\\theta_4x^4$ without actually getting rid of those features, we instead modify our cost function to something like this\n$$\n\\min_\\theta \\frac{1}{2m} \\sum_{i=1}^m \\left(h_\\theta \\left(x ^{\\left(i\\right)}\\right) - y^{\\left(i\\right)}\\right)^2 + 1000\\left(\\theta_3\\right)^2 + 1000 \\left(\\theta_4\\right)^2\n$$\nwhere $1000$ is an arbitrary large number that we chose. This inflates the cost of both $\\theta_3$ and $\\theta_4$, so to reduce our cost function, we end up reducing the values of $\\theta_3$ and $\\theta_4$ to near zero. This will greatly reduce the values of $\\theta_3x^3$ and $\\theta_4x^4$ in our hypothesis function. This usually yields a simpler hypothesis that is less prone to overfitting. \n\nIn a more general sense, having small values for \\textit{all} parameters typically decreases the likelihood that we'll overfit our regression. \n\nTo implement regularization, we modify the cost function by adding a regularization term at the end to shrink every parameter, where $\\lambda$ is called the regularization parameter. \n\\begin{equation}\nJ_\\theta = \\frac{1}{2m}\\left[ \\sum_{i=1}^m \\left(h_\\theta\\left( x^{(i)}\\right) - y^{(i)}\\right)^2 + \\lambda\\sum_{j=1}^n \\theta_j^2\\right]\n\\end{equation}\nBy convention, these summations start at $1$, so we don't regularize $\\theta_0$. In this equation, the regularization parameter $\\lambda$ controls the trade-off between two different goals: fitting the training data well (the first term of the equation), and keeping the parameters small (the regularization term). \n\nConceptually, it can be somewhat difficult to see why keeping the parameters small reduces overfitting, but if you program this yourself, you'll see this effect firsthand. What actually happens is that by using the above cost function with regularization, the resulting output of the hypothesis function is smoothed out to reduce overfitting. However, if $\\lambda$ is chosen to be too large, it may smooth out the function too much and underfit. For example, if $\\lambda \\sim 10^{10}$ for our housing data problem, then $\\theta_j \\to 0$ for $j \\neq 0$.This leaves us with a regression that looks like $h_\\theta\\left(x\\right) = \\theta_0$, meaning our hypothesis is just a horizontal line. \n\n\n\\subsection{Regularized Linear Regression}\nWe've previously looked at two algorithms for linear regression: one based on gradient descent, and one based on the normal equation. Now, we'll take these two algorithms and generalize them to regularized linear regression. Here is our cost function\n\\begin{equation}\nJ_\\theta = \\frac{1}{2m}\\left[ \\sum_{i=1}^m \\left(h_\\theta\\left( x^{(i)}\\right) - y^{(i)}\\right)^2 + \\lambda\\sum_{j=1}^n \\theta_j^2\\right]\n\\end{equation}\nand our goal is to get\n\\begin{equation}\n\\min_\\theta J\\left(\\theta\\right)\n\\end{equation}\n\n\\subsubsection{Gradient Descent}\nOur standard gradient descent algorithms looks something like this:\n\n\\textbf{Repeat \\{}\n$$\n\\theta_j := \\theta_j - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)} ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 0, 1, 2, \\dots, n\n$$\n\\textbf{\\}} \\\\\n\n\\noindent To make this easier, we're just going to write the update for $\\theta_0$ separately.\n\n\\textbf{Repeat \\{}\n\\begin{subequations}\n\\begin{align}\n\\theta_0 &:= \\theta_0 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_0^{(i)} \\\\\n\\theta_j &:= \\theta_j - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)} ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 1, 2, \\dots, n \\label{chaplogreg-sectregular-subsect-linreg-graddesc-oldeqtn}\n\\end{align}\n\\end{subequations}\n\\textbf{\\}} \\\\\nNow, we want to modify these equations to include our new regularization parameter. The $\\theta_0$ equation stays the same since we don't regularize $\\theta_0$, but equation \\ref{chaplogreg-sectregular-subsect-linreg-graddesc-oldeqtn} becomes\n\\begin{subequations}\n\\begin{align}\n\\theta_0 &:= \\theta_0 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_0^{(i)} \\\\\n\\theta_j &:= \\theta_j - \\alpha \\left[\\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)} + \\frac{\\lambda}{m}\\theta_j \\right] ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 1, 2, \\dots, n \\label{chaplogreg-sectregular-subsect-linreg-graddesc-neweqtn}\n\\end{align}\n\\end{subequations}\nIf you do the calculus out, you can prove that the large term in brackets in equation \\ref{chaplogreg-sectregular-subsect-linreg-graddesc-neweqtn} is the partial derivative of the new $J\\left(\\theta\\right)$ with the regularization term. \n$$\n\\frac{\\partial}{\\partial \\theta_j} J\\left(\\theta\\right)\n$$\nWith some manipulation, we can rewrite our update rule as\n\\begin{equation}\n\\theta_j := \\theta_j\\left(1 - \\alpha\\frac{\\lambda}{m}\\right) - \\alpha\\frac{1}{m}\\sum_{i=1}^m \\left(h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)}\n\\end{equation}\nwhere in the first term in the equation, the value $1 - \\alpha\\frac{\\lambda}{m}$ will always be less than one. Intuitively, the term that's always less than one will serve to reduce $\\theta_j$ by a small amount, and the other term is actually exactly the same as our previous gradient descent algorithm before we introduced regularization. \n\n\\subsubsection{The Normal Equation}\nGradient descent was just one of the two algorithms we've explored as a solution to linear regression; the second algorithm was based on the normal equation. With the normal equation, we crafted the design matrix $X$ where each row corresponds to a separate training example, and we have an $m$-dimensional vector $\\vec{y}$ that contains our labels. \n$$\nX = \\left[\\begin{array}{c}\n\\left(x^{(1)}\\right)^\\intercal \\\\ \\left(x^{(2)}\\right)^\\intercal \\\\ \\vdots \\\\ \\left(x^{(m)}\\right)^\\intercal\n\\end{array}\\right] ~~\\mbox{ \\;\\;\\;\\;\\;\\;\\;\\;\\;\\; }~~ \\vec{y} = \\left[\\begin{array}{c} y^{(1)} \\\\ y^{(2)} \\\\ \\vdots \\\\ y^{(m)} \\end{array}\\right]\n$$\nwhere we calculated the vector $\\vec{\\theta}$ as \n$$\n\\vec{\\theta} = \\left( X^\\intercal X\\right)^{-1} X^\\intercal \\vec{y}\n$$\nThis minimized the unregularized cost function $J\\left(\\theta\\right)$. To add in regularization, we add another term inside the parentheses\n\\begin{equation}\n\\vec{\\theta} = \\left( X^\\intercal X + \\lambda L \\right)^{-1} X^\\intercal \\vec{y}\n\\end{equation}\nwhere the matrix $L$ is a diagonal matrix\\footnote{In linear algebra, a diagonal matrix is a matrix (usually a square matrix) in which the off-diagonal elements are all zero. The main diagonal entries themselves may or may not be zero.} given by:\n\\begin{equation}\nL = \\left[\\begin{array}{cccccc}\n0 &  &  &  &  &  \\\\\n & 1 & & & & \\\\\n& & 1 & & & \\\\\n& & & 1 & & \\\\\n& & & & \\ddots & \\\\\n& & & & & 1\n\\end{array}\\right]\n\\end{equation}\nThe matrix $L$ has $0$ in it's top left spot, then $1$'s down the diagonal and zeros everywhere else. It has dimensions $\\left(n+1\\right) \\times \\left(n+1\\right)$. Intuitively, this is the identity matrix (sans $x_0$), multiplied by a single number $\\lambda \\in \\mathbb{R}$.\n\nRecall that if the number of examples $m \\leq$ the number of features $n$, then $X^\\intercal X$ is non-invertible.\\footnote{A non-invertible square matrix is also called singular or degenerate.} We got around this programatically by using the pseudoinverse. Fortunately, regularization also takes care of this for us as well. As long as $\\lambda \\in \\mathbb{R}_{>0}$ is strictly greater than zero, then $X^\\intercal X + \\lambda L$ will be strictly invertible. \n\n\n\\subsection{Regularized Logistic Regression}\nLogistic regression, just like linear regression, is prone to overfitting if you overfit with higher order polynomials. As we saw in equation \\ref{chaplogreg-sectsimpcostfunct-simpcostfuncformula}, our logistic regression cost function is given by\n$$\nJ\\left(\\theta\\right) = -\\frac{1}{m} \\left[ \\sum_{i=1}^m y^{\\left(i\\right)} \\log h_\\theta\\left(x^{\\left(i\\right)}\\right) + \\left(1 - y^{\\left(i\\right)}\\right) \\log \\left(1 - h_\\theta\\left(x^{\\left(i\\right)}\\right)\\right)\\right]\n$$\nTo morph this into a regularized equation, we need to add a regularization term at the end, resulting in\n\\begin{equation}\nJ\\left(\\theta\\right) = -\\frac{1}{m} \\left[ \\sum_{i=1}^m y^{\\left(i\\right)} \\log h_\\theta\\left(x^{\\left(i\\right)}\\right) + \\left(1 - y^{\\left(i\\right)}\\right) \\log \\left(1 - h_\\theta\\left(x^{\\left(i\\right)}\\right)\\right)\\right] + \\frac{\\lambda}{2m}\\sum_{j=1}^n \\theta_j^2\n\\end{equation}\nNote that in the second summation, $j \\in \\left[1, n\\right]$, so this excludes $\\theta_0$. \n\nIn a similar fashion to what we did with linear regression, we're going to make the same changes to gradient descent for logistic regression. We start with our standard gradient descent equation (equation \\ref{chaplogreg-sectcostfunct-subsectgraddscnt-logreggraddscnt}), and separate out the $\\theta_0$ term into its own equation. This gives us the same initial result as linear regression. \n\\begin{align}\n\\theta_0 &:= \\theta_0 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_0^{(i)} \\\\\n\\theta_j &:= \\theta_j - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)} ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 1, 2, \\dots, n \n\\end{align}\nThen, we again modify the second update rule\n\\begin{subequations}\n\\begin{align}\n\\theta_0 &:= \\theta_0 - \\alpha \\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_0^{(i)} \\\\\n\\theta_j &:= \\theta_j - \\alpha \\left[\\frac{1}{m} \\sum_{i=1}^m \\left( h_\\theta\\left(x^{(i)}\\right) - y^{(i)}\\right) x_j^{(i)} + \\frac{\\lambda}{m}\\theta_j \\right] ~~\\mbox{\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; for } j = 1, 2, \\dots, n\n\\end{align}\n\\end{subequations}\nCosmetically, this is the same formula as for linear regression, but the hypothesis is different, so the equations end up being different. Again, the bracketed term is the new partial derivative of $J\\left(\\theta\\right)$ with the regularized cost function. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\section{Python Labs: Coding Logistic Regression in Python}\n\\section{Homework}\n\n\n\n\n\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": "d2e75735a17f4013de8369fee744224a203e3048", "size": 38527, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LaTeX Notes/Chapters/3-Logistic_Regression.tex", "max_stars_repo_name": "Sz593/coursera_ml_notes", "max_stars_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_stars_repo_licenses": ["MIT"], "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 Notes/Chapters/3-Logistic_Regression.tex", "max_issues_repo_name": "Sz593/coursera_ml_notes", "max_issues_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_issues_repo_licenses": ["MIT"], "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 Notes/Chapters/3-Logistic_Regression.tex", "max_forks_repo_name": "Sz593/coursera_ml_notes", "max_forks_repo_head_hexsha": "098e0bd81759312b2c14640772112e9accb63a93", "max_forks_repo_licenses": ["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.8245341615, "max_line_length": 1452, "alphanum_fraction": 0.7256729047, "num_tokens": 11805, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.9032942138630786, "lm_q1q2_score": 0.7864054690927255}}
{"text": "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{The Lebesgue function spaces $L^p$}\n\\label{sec:lp}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Integral inequalities}\n\n\\begin{lemma}[Young's inequality]\n  \\defindex{Young's inequality}\n  For two arbitrary numbers $a$ and $b$, and a positive number\n  $\\gamma$ holds\n  \\begin{gather}\n    \\label{eq:lp:1}\n    2\\left|ab\\right| \\le \\gamma a^2 + \\frac1\\gamma b^2.\n  \\end{gather}\n\\end{lemma}\n\\begin{proof}\n  From the binomial formulas we have\n  \\begin{gather*}\n    0 \\le\n    \\begin{cases}\n      (a+b)^2 &= a^2+b^2+2ab,\n      \\\\\n      (a-b)^2 &= a^2+b^2-2ab,\n    \\end{cases}\n  \\end{gather*}\n  and thus by bringing $2ab$ to the left,\n  \\begin{gather}\n    \\label{eq:lp:2}\n    \\pm 2ab \\le a^2+b^2.\n  \\end{gather}\n  For $\\gamma \\neq 1$, the inequality is obtained by replacing $a$\n  with $\\gamma a$ and $b$ with $b/\\gamma$ in~\\eqref{eq:lp:2} and\n  observing that this does not change the left hand side.\n\\end{proof}\n\n\\begin{lemma}[Cauchy-Bunyakovsky-Schwarz inequality\\footnote{Also known as\n    Cauchy-Schwarz or Schwarz's inequality}]\n  \\defindex{Cauchy-Bunyakovsky-Schwarz inequality}\n  If functions $f$ and $g$ and their squares are integrable on a\n  subset $\\Omega$ of $\\R^d$, so is their pointwise product $fg$, and\n  there holds\n  \\begin{gather}\n    \\label{eq:lp:3}\n    \\int_\\Omega f(x)g(x)\\dx \\le \\sqrt{\\int_\\Omega f^2(x)\\dx} \\sqrt{\\int_\\Omega g^2(x)\\dx}.\n  \\end{gather}\n\\end{lemma}\n\n\\begin{proof}\n  First, by Young's inequality we obtain for arbitrary\n  $\\gamma$ that\n  \\begin{gather*}\n    2 \\int_\\Omega f(x)g(x)\\dx\n    \\le \\gamma \\int_\\Omega f^2(x)\\dx\n    + \\frac1\\gamma \\int_\\Omega g^2(x)\\dx.\n  \\end{gather*}\n  Choosing $\\gamma$ such that both terms on the right are equal,\n  namely\n  \\begin{gather*}\n    \\gamma = \\left. \\sqrt{\\int_\\Omega g^2(x)\\dx} \\right/ \\sqrt{\\int_\\Omega f^2(x)\\dx},\n  \\end{gather*}\n  the inequality is obtained.\n\\end{proof}\n\n\\begin{note}\n  The Cauchy-Bunyakovsky-Schwarz inequality is an immediate extension\n  of the Cauchy inequality for discrete sums\n  \\begin{gather}\n    \\sum_k a_k b_k \\le \\sqrt{\\sum_ka_k^2} \\sqrt{\\sum_kb_k^2}\n  \\end{gather}\n\\end{note}\n\n\\begin{lemma}[Hölder's inequality]\n  Assume that the functions $|f|^p$ and $|g|^q$ are integrable with\n  $1<p,q<\\infty$ and\n  \\begin{gather}\n    \\label{eq:lp:5}\n    \\frac1p+\\frac1q=1,\n  \\end{gather}\n  then the function $fg$ is integrable on $\\Omega$ and\n  \\begin{gather}\n    \\label{eq:lp:6}\n    \\int_\\Omega |fg| \\dx \\le \\sqrt[p] {\\int_\\Omega |f|^p \\dx} \\sqrt[q] {\\int_\\Omega |g|^q \\dx}.\n  \\end{gather}\n\\end{lemma}\n\n\\begin{lemma}[Minkowski's inequality]\n  Let the functions $|f|^p$ and $|g|^p$ be integrable on $\\Omega$ for\n  $1\\le p < \\infty$. Then, the function $|f+g|^p$ is integrable on\n  $\\Omega$ and\n  \\begin{gather}\n    \\label{eq:lp:7}\n    \\sqrt[p] {\\int_\\Omega |f+g|^p \\dx}\n    \\le \\sqrt[p] {\\int_\\Omega |f|^p \\dx}\n    +\\sqrt[p] {\\int_\\Omega |g|^p \\dx}\n  \\end{gather}\n\\end{lemma}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{The real Hilbert spaces $L^2(\\Omega)$}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  For a bounded or unbounded subset $\\Omega\\subseteq \\R^d$, the set of\n  functions with squares, which are integrable with finite integrals\n  forms a vector space. This is assured by the Minkowski's\n  inequality~\\eqref{eq:lp:7}. Our goal in this section is equipping this\n  space with an inner product and a norm. Once a norm has been\n  defined, we will show that the space obtained is complete, thus a\n  \\putindex{Hilbert space}.\n  We start this section by the attempt to introduce an inner\n  product.\n\\end{intro}\n\n\\begin{lemma}\n\\label{lemma:lp:bilinear}\n  Let $\\Omega \\subseteq \\R^d$ be bounded or unbounded.\n  The form\n  \\begin{gather}\n    \\label{eq:lp:4}\n    \\scal(f,g) = \\int_\\Omega f(x)g(x)\\dx\n  \\end{gather}\n  is defined and bounded for functions $f$ and $g$ with integrable\n  squares. It is bilinear, positive semidefinite, and symmetric.\n\\end{lemma}\n\n\\begin{proof}\n  According to the Cauchy-Bunyakovsky-Schwarz\n  inequality~\\eqref{eq:lp:3}, boundedness of $\\scal(f,g)$ follows from\n  boundedness of the integrals of $f^2$ and $g^2$.\n  Linearity in $f$ and $g$ are an immediate consequence of the\n  linearity of the integral in\n  equation~\\eqref{eq:integral:3}. Symmetry follows from the fact that\n  we can change the order of $f$ and $g$ in the product under the\n  integral. Finally, we have\n  \\begin{gather*}\n    0 \\le \\int_\\Omega f^2(x)\\dx = \\scal(f,f).\n  \\end{gather*}\n\\end{proof}\n\n\\begin{intro}\n  We have obtained $\\scal(f,f) \\ge 0$, but the definiteness of an\n  inner product requires that $\\scal(f,f) = 0$ implies $f=0$. On the\n  other hand, $\\scal(f,f) = 0$ holds for any function, which is zero\n  almost everywhere in $\\Omega$, but can have arbistrary values on a\n  set of measure zero. Thus, we have no hope to define a definite\n  inner product by integration on a function space. The solution to\n  this dilemma is a modification of the function space by a little\n  trick. Essentially, we turn around the definitions and define the\n  relation $f=0$ through the condition $\\scal(f,f) = 0$. We will now\n  do this in a mathematically sound way.\n\\end{intro}\n\n\\begin{lemma}\n  Let $F$ be a set of functions on $\\R^d$. We introduce the relation\n  $f\\simeq g$ if $f$ and $g$ differ at most on a set of measure zero,\n  or\n  \\begin{gather}\n    f\\simeq g\n    \\quad\\Leftrightarrow f(x)-g(x)=0 \\text{a.e.}\n  \\end{gather}\n This relation is an \\putindex{equivalence relation}.\n\\end{lemma}\n\n\\begin{proof}\n  We have to show reflexivity, symmetry, and transitivity of\n  ``$\\simeq$''. Obviously, since $f(x)=f(x)$ for all $x$, we have\n  $f\\simeq f$. Similarly obvious from the definition is that $f\\simeq\n  g$ implies $g\\simeq f$. Finally, let $f\\simeq g$ and $g\\simeq\n  h$. Then,\n  \\begin{gather*}\n    f(x)-h(x) = \\bigl(f(x)-g(x)\\bigr) + \\bigl(g(x)-h(x)\\bigr).\n  \\end{gather*}\n  Accordingly, the set on which $f$ and $h$ differ is at most the union of\n  two set of measure zero, thus $f\\simeq h$.\n\\end{proof}\n\n\\begin{lemma}\n  The set of functions\n  \\begin{gather*}\n    Z = \\bigl\\{ f \\big| f\\equiv 0 \\bigr\\},\n  \\end{gather*}\n  where ``0'' is the function which is zero everywhere, is a vector\n  space. Thus, for any vector space $V$ of functions, the quotient set\n  $V/Z$ is a vector space.\n\\end{lemma}\n\n\\begin{proof}\n  The first part of the proof is obvious. Thus, for any element of $V$\n  vector addition and scalar multiplication can be split into their\n  components in $Z$ and the remainder, which makes them well defined\n  on the quotient set.\n\\end{proof}\n\n\\begin{definition}\n  \\defindex{L2@$L^2$}\n\n  Let $V$ be the space of functions with bounded square integrals on a\n  set $\\Omega\\subseteq \\R^d$. Let $Z$ be the equivalence class of the\n  zero function according to the preceding lemmas. We define the\n  vector space $L^2(\\Omega)$ as the quotient space $V/Z$. The space\n  $L^2(\\Omega)$ is equipped with the inner product $\\scal(.,.)$\n  according to equation~\\eqref{eq:lp:4} and the norm\n  \\begin{gather}\n    \\norm{f} = \\norm{f}_2 := \\sqrt{\\scal(f,f)}.\n  \\end{gather}\n\\end{definition}\n\n\\begin{note}\n  We say for two functions $f$ and $g$ in $L^2(\\Omega)$ that ``$f=g$''\n  if the functions coincide almost everywhere.\n  Thus, the missing definiteness of the inner product in\n  Lemma~\\ref{lemma:lp:bilinear} is obviously cured by considering\n  equivalence classes. Thus, the norm is actually a norm, and\n  $L^2(\\Omega)$ for the moment is a pre-Hilbert space, that is, an\n  inner product space, which is not necessarily complete.\n\\end{note}\n\n\\begin{remark}\n  Consistent with other authors, we usually refer to an element of\n  $L^2(\\Omega)$ as a \\define{square integrable function} or\n  $L^2$-function. Nevertheless, it is important to keep in mind that\n  these elements are not functions at all. In particular, they do not\n  assign a value $f(x)$ to a given point $x\\in \\R^d$, since $\\{x\\}$ is\n  a set of measure zero, and thus we would be allowed to change this\n  value any time. This observation is important whenever we deal with\n  function spaces $L^2(\\Omega)$ and similar objects. Later we will\n  have to answer the question what kind of evaluation of an\n  $L^2$-function is actually permitted.\n\\end{remark}\n\n\\begin{definition}\n  We say that a sequence $f_n$ in $L^2(\\Omega)$ converges to an\n  element $f\\in L^2(\\Omega)$ if $\\norm{f_n-f}\\to 0$ as $n\\to\\infty$. A\n  sequence $f_n$ in $L^2(\\Omega)$ is called a \\define{Cauchy\n    sequence}, if the \\define{Cauchy criterion}\n  \\begin{gather}\n    \\label{eq:lp:cauchy}\n    \\forall \\epsilon>0\n    \\quad \\exists n_\\epsilon\n    \\quad\\forall m,n>n_\\epsilon :\n    \\norm{f_m-f_n} < \\epsilon.\n  \\end{gather}\n  For the latter, we also say $\\norm{f_m-f_n}\\to 0$ as\n  $n,m\\to\\infty$. \n\\end{definition}\n\n\\begin{theorem}[Fischer-Riesz]\n  Let $\\Omega\\subseteq \\R^d$. Then,\n  $L^2(\\Omega)$ is a Hilbert space, that is, it is complete, that is,\n  every Cauchy sequence $f_n$ in $L^2(\\Omega)$ converges to an\n  element $f\\in L^2(\\Omega)$.\n\\end{theorem}\n\n\\begin{proof}\n  First, we note that the Cauchy criterion is necessary for\n  convergence, since by the triangle inequality, we have for\n  $m,n\\to\\infty$:\n  \\begin{gather*}\n    \\norm{f_m-f_n} \\le \\norm{f_m-f} + \\norm{f-f_n} \\to 0.\n  \\end{gather*}\n  Now we assume that the Cauchy criterion holds. Then, there exists\n  a sequence $n_1,n_2,\\dots$ such that $\\norm{f_{n_{k+1}}- f_{n_k}}\n  <2^{-k}$. Now we have to distinguish between bounded domains\n  $\\Omega$ and unbounded domains. First, for bounded domains, the\n  Cauchy-Bunyakovsky-Schwarz inequality implies that\n  \\begin{gather*}\n    \\int_\\Omega 1 \\left|f_{n_{k+1}}(x)- f_{n_k}(x)\\right|\\dx \\le \\sqrt{m(\\Omega)}\n    \\norm{f_{n_{k+1}}- f_{n_k}} \\le \\sqrt{m(\\Omega)}2^{-k},\n  \\end{gather*}\n  hence the series\n  \\begin{gather*}\n    \\sum_{k=1}^\\infty \\int_\\Omega |f_{n_{k+1}}(x)- f_{n_k}(x)|\\dx\n  \\end{gather*}\n  converges to a finite value. The sequence of functions defined by\n  \\begin{gather*}\n    s_m(x) = \\sum_{k=1}^m |f_{n_{k+1}}(x)- f_{n_k}(x)|,\n  \\end{gather*}\n  is monotonically increasing. Furthermore, we have seen above that\n  their integrals are uniformly bounded. Thus, by the Beppo-Levi\n  theorem, $s_m(x)$ converges almost everywhere to an integrable\n  function. This on the other hand implies that for almost every $x\\in\n  \\Omega$ the sequence $f_{n_k}(x)$ is a Cauchy sequence and thus\n  converges to a limit value $f(x)$.\n  \n  If the domain $\\Omega$ is unbounded and its measure is not finite,\n  the above argument can be applied to any finite subdomain. Covering\n  $\\Omega$ with a countable sequence of such subdomains, we can\n  likewise conclude convergence to a limit function $f$ for\n  almost every $x\\in\\Omega$.\n\n  Now we prove that $f\\in L^2(\\Omega)$. We observe that\n  \\begin{gather*}\n    \\norm{f_{n_k}} \\le \\norm{f_{n_1}} + \\norm{f_{n_k}-f_{n_1}} \\le \\norm{f_{n_1}}+\\frac12.\n  \\end{gather*}\n  Thus, $\\norm{f_{n_k}}^2$ is uniformly bounded and as $|f_{n_k}(x)|^2\n  \\to |f(x)|^2$ almost everywhere, Fatou's lemma asserts that\n  $\\norm{f}$ is finite and accordingly $f\\in L^2(\\Omega)$.\n\n  It remains to show that $\\norm{f_n-f}\\to 0$.\n  \\begin{todo}\n    Show that norms converge\n  \\end{todo}\n\\end{proof}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{The real Banach spaces $L^p(\\Omega)$}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\begin{intro}\n  We saw that the Cauchy-Bunyakovsky-Schwarz inequality has a\n  generalization for exponents different from 2 in Hölder's\n  inequality, further that Minkowski's inequality holds for arbitrary\n  $p$ with $1\\le p<\\infty$. This suggests to define a norm through\n  \\begin{gather}\n    \\label{eq:lp:8}\n    \\norm{f}_p = \\sqrt[p] {\\int_\\Omega |f|^p \\dx},\n  \\end{gather}\n  and it is indeed an easy exercise to prove the norm properties\n  analogue to the previous subsection.\n\\end{intro}\n\n\\begin{definition}\n  A function $f:\\Omega \\to \\R$ is called \\define{essentially bounded}\n  from above, if there is a number $a$ such that the set\n  \\begin{gather*}\n    (f>a) := \\bigl\\{x\\in\\Omega \\big| f(x)>a \\bigr\\},\n  \\end{gather*}\n  has measure zero. The number $a$ is called an \\define{essential\n    upper bound}. For an essentially bounded function, we define the\n  \\define{essential supremum} $\\esssup f$ as the infimum of all\n  essential upper bounds:\n  \\begin{gather*}\n    \\esssup f = \\inf_{a\\in \\R} (f>a) \\text{ has measure zero.}\n  \\end{gather*}\n\\end{definition}\n\n\\begin{definition}\n  For $1\\le p < \\infty$, the space $L^p(\\Omega)$ is the space of all\n  functions such that $|f|^p$ is integrable with its norm defined\n  in~\\eqref{eq:lp:8}. The space $L^\\infty(\\Omega)$ is the space of all\n  essentially bounded functions on $\\Omega$, and its norm is\n  \\begin{gather*}\n    \\norm{f}_\\infty = \\esssup_{x\\in\\Omega} f\n  \\end{gather*}\n\\end{definition}\n\n\\begin{note}\n  For $p\\neq2$, the $L^p$-norm is not defined by an inner product,\n  thus $L^p(\\Omega)$ cannot be a Hilbert space.\n\\end{note}\n\n\\begin{theorem}\n  The spaces $L^p(\\Omega)$ are complete, thus, they are Banach spaces.\n\\end{theorem}\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End: \n", "meta": {"hexsha": "01341b7a90fa3ce59ca242cca391b62087bf7b63", "size": 13359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integration/lp.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": "integration/lp.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": "integration/lp.tex", "max_forks_repo_name": "ahumanita/notes", "max_forks_repo_head_hexsha": "73f23770e2b02f1b4a67987744ceffbd9ce797d7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2018-05-15T19:28:53.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-05T19:07:29.000Z", "avg_line_length": 36.7005494505, "max_line_length": 95, "alphanum_fraction": 0.6505726477, "num_tokens": 4307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.903294206053042, "lm_q1q2_score": 0.7864054622933289}}
{"text": "\\chapter{Likelihood and estimators}\n\\label{chap:like}\nIn this chapter likelihood and its estimators are introduced.\n\\\\\n\\\\ % Casella berger, s290, s315\nAnother way to summarize data is the likelihood function. The theory presented here is from \\cite{casella2002statistical}. The likelihood function is defined as,\n\\begin{defn}\nLet $f(\\boldsymbol{x}|\\theta)$ denote the joint pdf or pmf of the sample $\\boldsymbol{X} = (X_1,...,X_n)$. Then, given that $\\boldsymbol{X} = \\boldsymbol{x}$ is observed, the function $\\theta$ is defined by\n\\begin{equation}\nL(\\theta | \\boldsymbol{x}) = f(\\boldsymbol{x}|\\theta)\n\\label{eq:like}\n\\end{equation}\nis called the likelihood function.\n\\end{defn}\nBy using this function one can find estimators for $\\theta$. These estimators are the ones that maximizes the likelihood function. Furthermore these estimators are most likely. Hence the they are given the name maximum likelihood estimators. The formal definition is as follows\n\\begin{defn} % side 316\nFor each sample point $\\boldsymbol{x}$, let $\\hat{\\theta}(\\boldsymbol{x})$ be parameter value at which $L(\\theta | \\boldsymbol{x})$ attains its maximum as a function of $\\theta$, with $\\boldsymbol{x}$ held fixed. A maximum likelihood estimator(MLE) of the parameter $\\theta$ based on a sample $\\boldsymbol{X}$ is $\\hat{\\theta}(\\boldsymbol{x})$.\n\\end{defn}\nTo maximum of the likelihood can be found analytically or numerically. Analytically it is recommended to take the log of the likelihood function. This for easier derivation.", "meta": {"hexsha": "870183fcd2fd4de8031644e265f876185f1cc485", "size": 1512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/likelihood.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/likelihood.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/likelihood.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": 79.5789473684, "max_line_length": 344, "alphanum_fraction": 0.7585978836, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404057671712, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7862530803827442}}
{"text": "\\section{Uniform Continuity}\r\nLet $U\\in\\mathbb C$ and $f$ a scalar function on $U$.\r\nWe know what continuity means in the sense of metric space.\r\n\\begin{definition}\r\n    We say $f$ is uniformly continuous on $U$ if for any $\\epsilon>0,\\exists\\delta>0,\\forall x,y\\in U$, $|x-y|<\\delta\\implies |f(x)-f(y)|<\\delta$.\r\n\\end{definition}\r\nNote that the difference between uniform convergence and our initial form of convergence is that the value of $\\delta$ does not depend on the point $x$.\r\n\\begin{example}\r\n    The standard example that a function is continuous but not uniformly continuous is that $f(x)=x^2$ on $\\mathbb R$.\r\n    To see why, observe that we take $\\epsilon=1$, then choose any $\\delta>0$,\r\n    $$(x+\\delta/2)^2-x^2=\\delta x+\\delta^2/4$$\r\n    We can just choose $x>1/\\delta$ and the value would exceed $1$.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Let $f$ be a scalar function defined on a closed interval $[a,b]$, then if $f$ is continuous then it is uniformly continuous.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    (Heine-Borel Theorem gives compactness of the interval which provides a direct proof.)\\\\\r\n    Assume that it is not the case, so\r\n    $$\\exists\\epsilon>0,\\forall\\delta>0,\\exists x,y\\in[a,b], |x-y|<\\delta\\land |f(x)-f(y)|>\\epsilon$$\r\n    Choose such a `bad' $\\epsilon$, consider $\\delta_n=1/n$ and choose $x_n,y_n$ accordingly.\\\\\r\n    By Bolzano-Wiestrass, there is a subsequence $x_{k_m}$ of $x_n$ that converges to some $x$ as $x\\to\\infty$.\r\n    Note that since the interval is closed $x\\in[a,b]$.\r\n    Then, $|y_{k_m}-x|\\le |x_{k_m}-x|+|x_{k_m}-y_{k_m}|<\\frac{1}{k_m}+\\epsilon$\r\n    for any $\\epsilon>0$. so $y_{k_m}\\to x$.\\\\\r\n    Since $f$ is continuous at $x$, there is some $\\delta$ such that for every $y\\in[a,b]$, $|x-y|<\\delta\\implies |f(x)-f(y)|<\\epsilon/2$.\r\n    There is some $N$ such that $m>N\\implies |x_{k_m}-x|<\\delta,|y_{k_m}-x|<\\delta$.\r\n    So $\\epsilon<|f(x_{k_m})-f(y_{k_n})|\\le |f(x_{k_m})-f(x)|+|f(x)-f(y_{k_m})|<2\\epsilon/2=\\epsilon$\r\n    This is a contradiction.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    A continuous function on a closed interval is integrable.\r\n\\end{corollary}\r\nIt follows that a continuous function on a closed interval is integrable.\r\n%So given $\\epsilon$, by the above theorem, there is some $\\delta>0,\\forall x,y\\in[a,b]$, $|x-y|<\\delta\\implies |f(x)-f(y)|<\\epsilon$, so\r\n", "meta": {"hexsha": "750ba9aff850aed0e2ac5eee19b2fa44f9f3ea63", "size": 2331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/unifcont.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": "2/unifcont.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": "2/unifcont.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": 64.75, "max_line_length": 153, "alphanum_fraction": 0.6623766624, "num_tokens": 776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8976952859490985, "lm_q1q2_score": 0.7861898626289419}}
{"text": "\\section{Interpolation Operator: Discrete Fourier Expansion}\n    \n    The continuous Fourier series method requires the evaluation of the coefficients\n    \\begin{align}\n        \\hat{u}_n = \\displaystyle \\frac{1}{2\\pi} \\int_{0}^{2\\pi} u(x) e^{-inx} dx.\n    \\end{align}\n    In general, these integrals cannot be computed analytically, and one resorts to the approximation of the Fourier integrals by using quadrature formulas. This procedure defines a discrete transform between the set of values of $u$ at the quadrature points and the set of approximate, or discrete, coefficients. The finite series defined by the discrete transform is actually the interpolate of $u$ at the quadrature nodes. If the properties of accuracy (in particular the spectral accuracy) are retained by replacing the finite transform with the discrete transform, then the interpolant series can be used instead of the truncated series to approximate functions. Also, quadrature formulas differ based on the exact position of the grid points, and the choice of an even or odd number of grid points results in slightly different schemes.\n    \n    \\subsection{The Even Expansion}\n    \n    Define an equidistant grid, consisting of an even number $N$ of gridpoints $x_j \\in [0, 2\\pi)$, defined by\n\t\\begin{align*}\n        x_j = \\frac{2 \\pi j}{N} , \\hspace{0.5cm} j\\in [0, \\cdots , N -1]. \n    \\end{align*}\n    The trapezoidal rule yields the discrete Fourier coefficients $\\widetilde{u}_n$, which approximate the continuous Fourier coefficients $\\hat{u}_n$ given as follows    \n    \\begin{align}\n        \t\\widetilde{u}_n = \\frac{1}{N}  \\displaystyle \\sum_{j = 0}^{N - 1} u(x_j) e^{-in x_j}.\n    \\end{align}\n\tThe difference between the continuous and the discrete approximation is very clear since here we only need precision in the points $ x_j $. This may somehow be an advantage in the numerical calculation because in some cases it is possible to obtain the same order of precision, as shown in the following theorem when trigonometric polynomials are involved, the trapezoidal quadrature rule is a very natural approximation. \\\\\n\t\n\t\\begin{teor}\n\t\\label{Exactness_Even}\t\n\tFor the points $x_j$ defined as above, the quadrature formula\n    \\begin{align*}\n         \\frac{1}{2\\pi}\\displaystyle \\int^{2\\pi}_{0} f(x) dx = \\frac{1}{N} \\displaystyle \\sum^{N-1}_{j=0} f(x_j), \n    \\end{align*}\n    is exact for any trigonometric polynomial $f(x) = e^{inx}$ , $|n| < N$.\n    \\end{teor}\n\t\\begin{proof}\n\tGiven a function $f(x) = e^{in x}$, It is easy to observe that\n\t\n    \\begin{align*}\n        \\frac{1}{2\\pi}\\displaystyle \\int^{2\\pi}_{0} f(x) dx =  \\left \\lbrace \\begin{array}{ll}\n    \t1 \\hspace{3mm} & \\text{if } n = 0, \\\\\n    \t0 \\hspace{3mm} & \\text{otherwise.}\n    \t\\end{array}  \\right . \n    \\end{align*}\n\n\t\\noindent On the other hand,    \n    \\begin{align*}\n        \\frac{1}{N}  \\displaystyle \\sum_{j = 0}^{N - 1} f(x_j) &= \\frac{1}{N}  \\displaystyle \\sum_{j = 0}^{N - 1} e^{in (\\frac{2\\pi j}{N})} \\\\\n        &= \\frac{1}{N}  \\displaystyle \\sum_{j = 0}^{N - 1} q^j\n    \\end{align*}\n    where $q = e^{i \\frac{2\\pi n}{N}}$. If $n$ is an integer multiple of $N$ , i.e., $n = m N$, then, we have to\n    \\begin{align*}\n    \t\\displaystyle \\frac{1}{N} \\sum^{N-1}_{j=0}  e^{i Nm (\\frac{2\\pi j}{N})} = \\frac{1}{N} \\sum^{N-1}_{j=0}  e^{i(2\\pi j m)} = 1\n    \\end{align*} \n\tOtherwise, \n\t\\begin{align*}\n\t\t\\displaystyle \\frac{1}{N} \\sum^{N-1}_{j=0} q^j = \\frac{q^{N} - 1}{q - 1} = 0\n\t\\end{align*}\n\tThus, the quadrature formula is exact for any function of the form $f(x) = e^{inx}$, $|n| < N$.\n\t\\end{proof}\n\n\tMoreover, we can see that the quadrature formula is exact for $f(x) \\in \\hat{B}_{2N-2}$ where $\\hat{B}_N$ is defined as before. Then using the trapezoid rule, the discrete Fourier coefficients become\n\t\\begin{align}\n\t\\label{coeficients_IN}\n\t    \\widetilde{u}_n = \\frac{1}{N \\widetilde{c}_n}  \\displaystyle \\sum_{j = 0}^{N - 1} u(x_j) e^{-in x_j},\n\t\\end{align}\n\twhere we introduce the coefficients\n\t\\begin{align}\n\t\\label{constants_IN}\t\n\t    \\widetilde{c}_n = \\left \\lbrace \\begin{array}{ll}\n\t    2  \\hspace{0.25cm}\\text{if} & |n| =  N/2, \\\\\n\t    \\\\\n\t    1  \\hspace{0.25cm} \\text{if} & |n| < N/2.\n\t\\end{array}  \\right .\n\t\\end{align}\n\n\t\\noindent These relations define a new projection of $u$\n\t\\begin{equation}\n\t\\label{collocation_operator_even}\n\t\t\\mathcal{I}_N u(x) =  \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\widetilde{u}_n e^{inx}\n\t\\end{equation}\n\tThis is the complex discrete Fourier transform, based on an even number of quadrature points. From the above, we can see that\n\t\\begin{align*}\n\t    \\widetilde{u}_{-N/2} = \\widetilde{u}_{N/2},\n\t\\end{align*}\n\tso we have exactly $N$ independent Fourier coefficients, corresponding to the $N$ quadrature points. As a consequence, $\\mathcal{I}_N \\sin( \\frac{N}{2} x) = 0$, so that the function $\\sin( \\frac{N}{2} x)$ is not represented in the above expansion. Therefore, the space $\\hat{B}_N$ does not include $\\sin( \\frac{N}{2} x)$, and the correct space must be as follows\n\t\\begin{align*}\n\t    \\widetilde{B}_N = span\\left\\{\\left(\\cos(nx), \\hspace{0.2cm} 0 \\leq n \\leq \\frac{N}{2} \\right)\\cup  \\left(\\sin(nx), \\hspace{0.2cm} 1 \\leq n \\leq \\frac{N}{2} - 1 \\right)\\right\\},\n\t\\end{align*}\n\twhich has dimension dim$(\\widetilde{B}_N) = N$.\\\\\n\t\n\t\\noindent In the same way, as in the previous subsection using the discrete expansion for Examples \\ref{Example1} and \\ref{Example2}, we can observe the same behavior as with continuous expansion, but now we have that the error at each point $x_j$ of the grid is zero.\n\n\t\\begin{example}\n\t    Consider the $C^{\\infty}_p [0, 2 \\pi]$ function\n    \t\\begin{align}\n    \t\t\\label{Example4}\n    \t    u(x) = \\frac{1}{5 - 4 \\cos(x)}.\n    \t\\end{align}\n    \tIts expansion coefficients are\n    \t\\begin{align*}\n    \t     \\hat{u}_{n} = \\frac{2^{-|n|}}{3}.\n    \t\\end{align*}\n    \t\\begin{figure}[H]\n        \\includegraphics[width=\\textwidth]{preliminaries/figures/example23.png}\n        \\caption{(a) Discrete Fourier series approximation of the equation (\\ref{Example4}). (b) Pointwise error of approximation for increasing resolution.}\n        \\label{fig3}\n        \\end{figure}\n\t\\end{example} \n\t\n\t\\begin{example}\n\t    The expansion coefficients of the function\n    \t\\begin{align}\n    \t\t\\label{Example5}\n    \t    u(x) = \\frac{\\pi}{2} \\sin(\\frac{x}{2}),\n    \t\\end{align}\n   \t\tare given by\n    \t\\begin{align*}\n    \t     \\hat{u}_{n} = \\frac{1}{(1 - 4n^2)}.\n    \t\\end{align*}\n    \t\\begin{figure}[H]\n        \\includegraphics[width=\\textwidth]{preliminaries/figures/example24.png}\n        \\caption{(a) Discrete Fourier series approximation of the equation (\\ref{Example5}). (b) Pointwise error of approximation for increasing resolution.}\n        \\label{fig4}\n        \\end{figure}\n\t\\end{example} \n\t\n\tTherefore, we can see that the discrete expansion is, in fact, an interpolation operator as mentioned. This can be shown in the following theorem.\\\\\n\t\n\t\\begin{teor}\n\tLet the discrete Fourier transform be defined by Equations (\\ref{coeficients_IN})-(\\ref{collocation_operator_even}). For any periodic function, $C^{0}_p [0, 2\\pi]$, we have\n\t\\begin{align*}\n\t\t\\mathcal{I}_N u(x_j) = u(x_j), \\hspace{0.3cm} \\forall x_j = \\frac{2 \\pi j}{N} , \\hspace{0.3cm} j = 0, \\dots, N - 1. \n\t\\end{align*}\n\t\\end{teor}\n\n\t\\begin{proof}\n\tSubstituting Equation (\\ref{coeficients_IN}) into Equation (\\ref{collocation_operator_even}) we obtain\n\t\n\t\\begin{equation*}\n    \t\\mathcal{I}_N u(x) =  \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\left(\\frac{1}{N \\widetilde{c}_n}  \\displaystyle \\sum_{j = 0}^{N - 1} u(x_j) e^{-in x_j}\\right) e^{inx}.\n\t\\end{equation*}\n\tExchanging the order of the sum gives\n\t\\begin{align}\n\t    \\mathcal{I}_N u(x) = \\displaystyle \\sum_{j=0}^{N-1} u(x_j) g_j (x),\n\t\\end{align}\n\twhere\n\t\\begin{align*}\n\t    g_j (x) &= \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\frac{1}{N \\widetilde{c}_n} e^{in(x -x_j)}\\\\\n\t    &= \\frac{1}{N} \\sin\\left[N \\frac{x - x_j}{2} \\right] \\cot\\left[\\frac{x - x_j}{2} \\right]\n\t\\end{align*}\n\tby summing as a geometric series. It is easily verified that $g_j (x_i) = \\delta_{ij}$\\\\\n\t\\\\\n\tWe still need to show that $g_j (x) \\in \\widetilde{B}_N$. Clearly, $g_j (x) \\in \\hat{B}_N$ as $g_j (x)$ is a polynomial of degree $\\leq N/2$. However, since\n\t\n\t\\begin{align*}\n\t    \\frac{1}{2} e^{-i \\frac{N}{2} x_j} = \\frac{1}{2} e^{i \\frac{N}{2} x_j} = \\frac{(-1)^j}{2},\n\t\\end{align*}\n\t\n\tand, by convention $\\widetilde{u}_{-N/2} = \\widetilde{u}_{N/2}$, we do not get any contribution from the term $\\sin(\\frac{N}{2} x)$, hence $g_j (x) \\in \\widetilde{B}_N$.\n\t\\end{proof}\n\t\n\t\\subsection{The Odd Expansion}\n\t\n\tSimilarly, we define a grid with an odd number of grid points as follows\n\t\\begin{align*}\n        x_j = \\frac{2 \\pi}{N + 1} j , \\hspace{0.5cm} j\\in [0, \\dots , N],\n    \\end{align*}\n    and using the trapezoidal rule we get\n\t\\begin{align}\n\t\\label{coefficients_JN}\n        \\widetilde{u}_n = \\frac{1}{N + 1}  \\displaystyle \\sum_{j = 0}^{N} u(x_j) e^{-in x_j},\n    \\end{align}\n    to obtain the interpolation operator\n    \\begin{equation}\n    \\label{Interpolation_operator_odd}\n    \t\\mathcal{J}_N u(x) =  \\displaystyle \\sum_{ |n| \\leq \\frac {N}{2}} \\widetilde{u}_n e^{inx}.\n\t\\end{equation}\n\t\n    \\noindent Again as before, the quadrature formula is highly accurate. \\\\\n    \\begin{teor}\n    \\label{Exactness_Odd}\t\n    For the points $x_j$ defined as above, the quadrature formula\n    \\begin{align*}\n         \\frac{1}{2\\pi}\\displaystyle \\int^{2\\pi}_{0} f(x) dx = \\frac{1}{N+1} \\displaystyle \\sum^{N}_{j=0} f(x_j),\n    \\end{align*}\n    is exact for any $f(x) = e^{inx}$ , $|n| < N$, i.e., for all $f(x) \\in \\widetilde{B}_{2N}$.\n    \\begin{proof}\n    \tGiven a function $f(x) = e^{in x}$, It is easy to observe that\n    \t\n    \t\\begin{align*}\n    \t\t\\frac{1}{2\\pi}\\displaystyle \\int^{2\\pi}_{0} f(x) dx =  \\left \\lbrace \\begin{array}{ll}\n    \t\t\t1 \\hspace{3mm} & \\text{if } n = 0, \\\\\n    \t\t\t0 \\hspace{3mm} & \\text{otherwise.}\n    \t\t\\end{array}  \\right . \n    \t\\end{align*}\n    \tOn the other hand,    \n    \t\\begin{align*}\n    \t\t\\frac{1}{N+1}  \\displaystyle \\sum_{j = 0}^{N} f(x_j) &= \\frac{1}{N+1}  \\displaystyle \\sum_{j = 0}^{N} e^{in (\\frac{2\\pi j}{N+1})} \\\\\n    \t\t&= \\frac{1}{N+1}  \\displaystyle \\sum_{j = 0}^{N} q^j\n    \t\\end{align*}\n    \twhere $q = e^{i \\frac{2\\pi n}{N+1}}$. If $n$ is an integer multiple of $N+1$ , i.e., $n = (N+1)m$, then we have to\n    \t\\begin{align*}\n    \t\t\\displaystyle \\frac{1}{N+1} \\sum^{N}_{j=0}  e^{i(N+1)m (\\frac{2\\pi j}{N+1})} = \\frac{1}{N+1} \\sum^{N}_{j=0}  e^{i (2\\pi jm)} = 1\n    \t\\end{align*}\n    \t Otherwise, \n    \t\\begin{align*}\n    \t\t\\displaystyle \\frac{1}{N+1} \\sum^{N}_{j=0} q^j = \\frac{q^{N+1} - 1}{q - 1} = 0\n    \t\\end{align*}\n    \tThus, the quadrature formula is exact for any function of the form $f(x) = e^{inx}$, $|n| < N$.\n    \\end{proof}\n    \n    \\end{teor}\n    The scheme may also be expressed through the use of a Lagrange interpolation polynomial,\n    \\begin{align}\n    \\label{Lagrange_Odd}\t\n    \t\\mathcal{J}_N u(x) =  \\displaystyle \\sum_{j=0}^{N} u(x_j) h_j (x)\n\t\\end{align}\n\twhere\n\t\\begin{align}\n\t    h_j (x) = \\displaystyle \\frac{1}{N+1} \\sum_{|k| \\leq \\frac{N}{2}} e^{ik (x - x_j)} = \\frac{1}{N + 1} \\frac{\\sin(\\frac{N+1}{2}(x - x_j))}{\\sin(\\frac{x - x_j}{2})}\n\t\\end{align}\n    One easily shows that $h_j (x_l) = \\delta_{jl}$ and that $h_j (x) \\in \\hat{B}_N $.\n\t\n\t\\newpage\n    \\subsection{Differentiation of the discrete expansions}\n    \n    Similarly, as in continuous expansion, we require compute derivatives of the discrete approximation. In the following subsections, we assume that our function $u$ and all its derivatives are continuous and periodic on $[0, 2\\pi]$.\\\\\n    \\\\\n    We consider the case of an even number of grid points. Using expansion coefficients given the values of the function $u(x)$ at the points $x_j$ , differentiating the basis functions in the interpolant yields\n    \\begin{align}\n        \\frac{d}{dx} \\mathcal{I}_N u(x) = \\displaystyle \\sum_{|n| \\leq N/2} in \\widetilde{u}_n e^{inx}, \\hspace{2mm} \\widetilde{u}_n = \\displaystyle \\frac{1}{N \\widetilde{c}_n} \\sum_{j=0}^{N-1} u(x_j) e^{-in x_j},   \n    \\end{align}\n    where $\\widetilde{c}_n$ is given by (\\ref{constants_IN}). Higher order derivatives can be obtained simply by further differentiating the basis functions.\\\\\n    \n    \\noindent Similarly, for the case of an odd number of grid points\n    \\begin{align}\n    \t\\frac{d}{dx} \\mathcal{J}_N u(x) = \\displaystyle \\sum_{|n| \\leq N/2} in \\widetilde{u}_n e^{inx}, \\hspace{2mm} \\widetilde{u}_n = \\displaystyle \\frac{1}{N + 1} \\sum_{j=0}^{N} u(x_j) e^{-in x_j},   \n    \\end{align} \n    The procedure for differentiating using expansion coefficients can be described as follows: first, we transform the point values $u(x_j)$ in physical space into the coefficients $\\widetilde{u}_n$ in mode space. We then differentiate in mode space by multiplying  $\\widetilde{u}_n$ by $in$, and return to physical space.\\\\\n    \n    There are other ways to obtain these derivatives, which may have greater advantage and be more efficient to calculate. In the literature, it can commonly find the use of differentiation matrices, for which there is a great variety. We will present some matrices that have been studied in \\cite{gottlieb2007}, \\cite{Canuto2012}, and we will observe the difference between the cases of an even and odd number of grid points. \\\\\n    \n    \\paragraph{Differentiation Matrix.} Recall that to the case of an even number of grid points, the interpolation operator can be written as\n    \\begin{align*}\n        \\mathcal{I}_N u(x) = \\displaystyle \\sum^{N-1}_{j=0} u(x_j) g_j (x),\n    \\end{align*}\n    where $g_j$ are the Lagrange interpolation polynomials given by\n    \\begin{align*}\n        g_j (x) = \\frac{1}{N} \\sin\\left[N \\frac{x - x_j}{2} \\right] \\cot\\left[\\frac{x - x_j}{2} \\right].\n    \\end{align*}\n    Then, by differentiating the interpolation directly, it can get an approximation to the derivative of $u(x)$ at the points $x_j$ as follows\n    \\begin{align*}\n        \\displaystyle \\frac{d}{dx} \\mathcal{I}_N (x) \\Big|_{x_l} = \\sum^{N-1}_{j=0} u(x_j) \\frac{d}{dx} g_j (x) \\Big|_{x_l} = \\sum^{N-1}_{j=0} D_{lj} u(x_j),\n    \\end{align*}\n    where $D_{lj}$ are the differentiation matrix entries given by\n    \\begin{align}\n    \\label{matrix_DN_even}\n        D_{ij} = \\frac{d}{dx} g_j (x) \\Big|_{x_i} = \\begin{cases} \\frac{(-1)^{i+j}}{2} \\cot \\left[ \\frac{x_i - x_j}{2}\\right] &   i \\neq j, \\\\ \\hspace{1mm} 0 &  i=j, \\end{cases}\n    \\end{align}\n    it is also well known that $D$ is circulant and skew-symmetric matrix. In the same way, the entries of the second order differentiation matrix $D^{(2)}$ gives us\n    \\begin{align}\n    \\label{matrix_D2N_even}\n        D_{ij}^{(2)} = \\frac{d^2}{dx^2} g_j (x) \\Big|_{x_i} = \\begin{cases} -\\frac{(-1)^{i+j}}{2} \\left[\\sin \\left[ \\frac{x_i - x_j}{2}\\right]\\right]^{-1} &   i \\neq j, \\\\ -\\frac{N^2 + 2}{12} &  i=j. \\end{cases}\n    \\end{align}\n\t\n    The approximation of higher derivatives follows exactly the same route, and similarly to obtain the entries of the differentiation matrix $\\widetilde{D}$ for the interpolation based on an odd number of points given by\n    \\begin{align}\n    \\label{matrix_DN_odd}\n        \\widetilde{D}_{ij} = \\begin{cases} -\\frac{(-1)^{i+j}}{2} \\left[\\sin \\left[ \\frac{x_i - x_j}{2}\\right]\\right]^{-2} &   i \\neq j, \\\\ \\hspace{1mm} 0 &  i=j. \\end{cases}\n    \\end{align}\n\n    It is also known that $\\widetilde{D}$ is a circulant, skew-symmetric matrix. The advantage of this method is that the differentiation matrix takes us from physical space to physical space, and the act of differentiation is hidden in the matrix itself. \\\\\n    \n    It is interesting to observe that the differentiation operator for the interpolation based on an odd number of grid points, takes elements of $\\widetilde{B}_N$ out of $\\widetilde{B}_N$ and then\n    \\begin{align*}\n    \t\\mathcal{I}_N \\frac{d^2}{dx^2} \\mathcal{I}_N \\neq \\left( \\mathcal{I}_N \\frac{d}{dx} \\right)^2 \\mathcal{I}_N.\n    \\end{align*}\n\t\n\tBut for the interpolation based on an odd number of grid points the differentiation operator remain in $\\hat{B}_N$ when takes elements of $\\hat{B}_N$, and thus,\n\t\\begin{align*}\n\t\t\\mathcal{J}_N \\frac{d^2}{dx^2} \\mathcal{J}_N = \\left( \\mathcal{J}_N \\frac{d}{dx} \\right)^2 \\mathcal{J}_N\n\t\\end{align*}\n    Moreover, for all values of $q$ we have\n    \\begin{align*}\n        \\widetilde{D}^{(q)} = \\mathcal{J}_N \\frac{d^q}{dx^q} \\mathcal{J}_N = \\widetilde{D}^q\n    \\end{align*}\n\tallowing us to calculate approximate high derivatives by just multiplying the $D$ matrix as many times as necessary.\n    \n    For the above, and for some interesting properties that we will see later about interpolation operator based on an odd number of grid points, it has been decided to use it for the study of this work.\n    \n    \\subsection{Approximation theory for Discrete Expansion.}\n    \n    Based on the theory developed in \\cite{gottlieb2007} with respect to the interpolation operator analysis for the case of an even number of grid points, we will adapt the results for the case of an odd number of grid points in the most detailed way possible. \\\\\n    \n    \\noindent First of all, we can define a discrete version of the inner product $L^2$ as follows\n    \\begin{align*}\n    \t\\langle f_N, g_N \\rangle_N = \\displaystyle \\frac{1}{N + 1} \\sum_{j = 0}^{N} f_N (x_j) \\bar{g}_N (x_j),\n    \\end{align*}\n\tand the associated norm\n\t\\begin{align*}\n\t\t\\| f_N \\|_N^2 = \\langle f_N, f_N \\rangle_N\n\t\\end{align*}\n\twhere $f_N$ , $g_N \\in \\hat{B}_N$ and there are an odd number of grid points $x_j$ , $j = 0, \\dots , N$. Note also that the interpolant $\\mathcal{J}_N u$ of a continuous function $u$ and for all $v \\in \\hat{B}_N$, satisfies trivially the identity\n\t\\begin{align*}\n\t\t\\langle \\mathcal{J}_N u, v \\rangle_N = \\langle u, v \\rangle_N.\n\t\\end{align*} \n\t\n\tMoreover, as a consequence of the exactness of the quadrature rule for trigonometric functions, as have seen in Theorem \\ref{Exactness_Even}, we have\n\t\\begin{align}\n\t\\label{Coincidence_Inner}\t\n\t\t\\langle f_N, g_N \\rangle_N = \\displaystyle \\frac{1}{2 \\pi} \\int_{0}^{2 \\pi} f_N \\bar{g}_N dx, \\hspace{3mm} \\|f_N\\|_{L^2 [0, 2 \\pi]} = \\|f_N\\|_N\n\t\\end{align}\n\n\tHence, in $\\hat{B}_N$ , the continuous and discrete inner product are the same.\\\\\n\t\n\tThe situation is different when we discuss an even number of grid points. If $f_N , g_N \\in \\tilde{B}_N$ and we have an even number of grid points $x_j$ , the discrete inner product\n\t\\begin{align*}\n\t\t\\langle f_N, g_N \\rangle_N = \\displaystyle \\frac{1}{N} \\sum_{j = 0}^{N - 1} f_N (x_j) \\bar{g}_N (x_j), \\hspace{3mm} \\|f_N\\|_N^2 = \\langle f_N, f_N \\rangle_N\n\t\\end{align*}\n\tis not equal to the continuous inner product. However, using the fact that $f_N \\in L^2 [0, 2 \\pi]$ it can be shown that there exists a $K > 0$ such that\n\t\\begin{align}\n\t\\label{equivalent_discrete_continous}\n\t\tK^{-1} \\|f_N\\|^2_{L^2 [0, 2 \\pi]} \\leq \\|f_N\\|^2_N \\leq K \\|f_N\\|^2_{L^2 [0, 2 \\pi]}.\n\t\\end{align}\n    \n    Something very interesting and useful in the use of discrete expansion to approximate functions and their derivatives is that the behavior is very similar to that shown in the previous subsection for continuous expansion. We will see that the approximation theory for the discrete expansion yields essentially the same results as for the continuous expansion. The proofs are based on the fact that the Fourier coefficients of the discrete approximation are sufficiently close to those of the continuous approximation. \\\\\n    \n    Recall that the interpolation operator associated with an odd number of grid points is given by\n    \\begin{align*}\n    \t\\mathcal{J}_{2N} u = \\displaystyle \\sum_{|n|\\leq N} \\widetilde{u}_n e^{inx},\n    \\end{align*}\n    with expansion coefficients\n    \\begin{align*}\n    \t\\widetilde{u}_n = \\displaystyle \\frac{1}{2N + 1} \\sum^{2N}_{j=0} u(x_j)e^{-in x_j}, \\hspace{2mm} x_j = \\frac{2 \\pi j}{2N+1}.\n    \\end{align*}\n    \n    First we observe the following, the interpolation operator associated with an odd number of grid points are based on the points $x_j$, for which the $(n + Mm)$th mode, where $M = 2N + 1$, is indistinguishable from  the $n$th mode, i.e.,\n    \\begin{align*}\n    \te^{i(n + Mm)x_j} = e^{in x_j} e^{i 2 \\pi m j} = e^{in x_j}\n    \\end{align*}\n\tThis phenomenon is known as aliasing.\\\\\n\t\n\tMoreover, due to the orthogonality relation as before seen we have to\n    \\begin{align*}\n    \t\\frac{1}{M} \\displaystyle \\sum^{M-1}_{j=0} e^{-inx_j} =  \\left \\lbrace \\begin{array}{ll}\n    \t1 \\hspace{4mm} &\\text{if} \\hspace{2mm} n=M m, \\hspace{2mm} m = 0, \\pm 1, \\pm 2, \\dots, \\\\\n    \t0 &\\text{otherwise.}\n    \t\\end{array}  \\right .\n    \\end{align*} \n    \n    The relationship between the discrete expansion coefficients $\\widetilde{u}_n$ , and the continuous expansion coefficients $\\hat{u}_n$, is given in the following lemma. \n    \n    \\begin{lemma}\n    \\label{lemma_2.1}\n    Consider $u(x) \\in W^q_p [0, 2\\pi]$, where $q > 1/2$. For $|n| \\leq N$ we have\n\t    \\begin{align}\n\t    \\label{alias}   \n\t        \\widetilde{c}_n \\widetilde{u}_n = \\displaystyle \\hat{u}_n + \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm}\n\t    \\end{align}\n\t\\end{lemma}\n\t\\begin{proof}\n    Substituting the continuous Fourier expansion into the discrete expansion yields\n    \\begin{align*}\n        \\widetilde{c}_n \\widetilde{u}_n = \\frac{1}{M} \\displaystyle \\sum_{j=0}^{M - 1} \\sum_{|l| \\leq \\infty} \\hat{u}_l e^{i(l -n)x_j}\n    \\end{align*}\n    To interchange the two summations we must ensure uniform convergence, i.e., $\\sum_{|l| \\leq \\infty} |\\hat{u}_l| < \\infty$. This is satisfied, since if $q> 1/2$ then, as before there is $m \\in \\mathbb{N}$ such that for $l \\geq m$ we have to\n    \\begin{align*}\n    \t(1 + |l|)^{2q} \\leq 2q(1 + l^{2q}) \n    \\end{align*}\n\ttaking $m$ as follows \n\t\\begin{align*}\n\t\t\\frac{1}{m} \\leq (2q)^{\\frac{1}{2q}} - 1 \n\t\\end{align*}\n\n\t\\noindent Therefore\n    \\begin{align*}\n        \\displaystyle \\sum_{|l| \\leq \\infty} |\\hat{u}_l| &= \\sum_{|l| \\leq \\infty} (1 + |l|)^q \\frac{|\\hat{u}_l|}{(1 + |l|)^q}  \\\\\n        &\\leq \\left( 2q \\sum_{|l| \\leq \\infty}  (1 + l^{2q}) |\\hat{u}_l|^2 \\right)^{1/2} \\left(\\sum_{|l| \\leq \\infty} (1 + |l|)^{-2q}  \\right)^{1/2},\n    \\end{align*}\n    where the last expression follows from the Cauchy-Schwarz inequality. As $u(x) \\in W^q_p [0, 2\\pi]$ the first part is clearly bounded. Furthermore, the second term is a $p$-series and then converges provided $q > 1/2$, ensuring boundedness. \\\\\n    \n    Interchanging the order of summation and using orthogonality of the exponential function at the grid yields the desired result\n    \\begin{align*}\n    \t\\widetilde{c}_n \\widetilde{u}_n &= \\frac{1}{M} \\displaystyle \\sum_{j=0}^{M - 1} \\sum_{|l| \\leq \\infty} \\hat{u}_l e^{i(l -n)x_j} =  \\sum_{|l| \\leq \\infty} \\frac{1}{M} \\sum_{j=0}^{M - 1} \\hat{u}_l e^{i(l -n)x_j} \\\\\n    \t&= \\sum_{|m| \\leq \\infty}  \\frac{1}{M} \\sum_{j=0}^{M - 1} \\hat{u}_{n + Mm} e^{i(n + Mm)x_j} \\\\\n    \t&= \\frac{1}{M} \\sum_{j=0}^{M - 1} \\hat{u}_n e^{inx_j}\n    \t+ \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\frac{1}{M} \\sum_{j=0}^{M - 1} \\hat{u}_{n + Mm} e^{i(n + Mm)x_j} \\\\\n    \t&= \\hat{u}_n + \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm}\n    \\end{align*}\n\t\\end{proof}\n\t\n\tThe conclusions of the previous discussion are equally valid in the number of odd or even points. An equivalent formulation of (\\ref{alias}) is\n\t\\begin{align*}\n\t\t\\mathcal{J}_N u = \\mathcal{P}_N u + \\mathcal{A}_N u\n\t\\end{align*}\n\tIt is orthogonal to the truncation error, $u - \\mathcal{P}_N u$, so that\n\t\\begin{align*}\n\t\t\\| u - \\mathcal{J}_N u \\|^2 = \\|u - P_N u \\|^2 + \\| \\mathcal{A}_N u \\|^2\n\t\\end{align*}\n\tHence, the error due to the interpolation is actually always larger than the error due to the truncation of the Fourier series.\\\\\n\t\n\tRather than deriving the estimates of the approximation error directly, we shall use the results obtained in the previous section and then estimate the difference between the two different expansions, which we recognize as the aliasing error given by\n\t\\begin{align*}\n\t\t\\| \\mathcal{A}_N \\|_{L^2 [0, 2\\pi]} = \\left\\| \\displaystyle \\sum_{|n|<N} \\left( \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm}  \\right) \\right\\|_{L^2 [0, 2\\pi]}\n\t\\end{align*}\n    \n    As before, we first consider the behavior of the approximation in the $L^2$-norm. We will first show that the bound on the aliasing error, $\\mathcal{A}_N$ , in equation above is of the same order as the truncation error. The error caused by truncating the continuous expansion is essentially the same as the error produced by using the discrete coefficients rather than the continuous coefficients.\n    \\begin{lemma}\n    \\label{estimating_aliasing_error}\t\n    For any $u(x) \\in W_p^r [0, 2\\pi]$, where $r > 1/2$, the aliasing error\n    \\begin{align*}\n        \\| \\mathcal{A}_N \\|_{L^2 [0, 2\\pi]} = \\displaystyle \\left(\\sum_{|n| \\leq \\infty} |\\widetilde{c}_n \\widetilde{u}_n - \\hat{u}_n|^2 \\right)^{1/2} \\leq CN^{-r} \\|u^{r}\\|_{L^2 [0, 2\\pi]}\n    \\end{align*}\n\t\\end{lemma}\n\t\\begin{proof}\n    From Lemma \\ref{lemma_2.1} we have\n    \\begin{align*}\n        |\\widetilde{c}_n \\widetilde{u}_n - \\hat{u}_n|^2 = \\displaystyle \\left|\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm} \\right|^2\n    \\end{align*}\n    To estimate this, we first note that\n    \\begin{align*}\n        \\displaystyle \\left|\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm} \\right|^2 &= \\left|\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} |n + Mm|^r \\hat{u}_{n + Mm} \\frac{1}{|n + Mm|^r} \\right|^2 \\\\ \n        &\\leq \\left(\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} |n + Mm|^{2r} |\\hat{u}_{n + Mm}|^2 \\right) \\left(\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\frac{1}{|n + Mm|^{2r}}  \\right)\n    \\end{align*}\n    using the Cauchy-Schwartz inequality. Since $M =2N + 1$ and  $|n| \\leq N$, we have to $N(2m - 1) = 2Nm - N \\leq |n + Mm|$. Hence, bounding of the second term is ensured by\n    \\begin{align*}\n        \\displaystyle \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\frac{1}{|n + Mm|^{2r}} \\leq \\frac{2}{N^{2r}} \\sum^{\\infty}_{m=1} \\frac{1}{(2m - 1)^{2r}} = C_1 N^{-2r},\n    \\end{align*}\n    provided $r > 1/2$. Here, the constant $C_1$ is a consequence of the fact that the power series converges, and it is independent of $N$.\\\\\n    Summing over $n$, we have\n    \\begin{align*}\n        \\displaystyle \\sum_{|n|\\leq N} \\left|\\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} \\hat{u}_{n + Mm} \\right|^2 &\\leq \\sum_{|n| \\leq N} C_1 N^{-2r} \\sum_{\\substack{|m|\\leq \\infty \\\\ m \\neq 0}} |n + Mm|^{2r} |\\hat{u}_{n + Mm}|^2 \\\\\n        &\\leq C_2 N^{-2r} \\| u^{(r)} \\|^2_{L^2[0, 2\\pi]}\n    \\end{align*}\n\t\\end{proof}\n\n    We are now in a position to state the error estimate for the discrete approximation.\n    \\begin{teor}\n    \\label{estimating_error_I_N_L2}\t\n    For any $u(x) \\in W_p^r [0, 2\\pi]$ with $r > 1/2$, there exists a positive constant $C$, independent of $N$ , such that\n    \\begin{align*}\n        \\| u - \\mathcal{J}_{2N}u \\|_{L^2 [0, 2\\pi]} \\leq CN^{-r} \\| u^{(r)} \\|_{L^2 [0, 2\\pi]}\n    \\end{align*}\n\t\\end{teor}\n    \\begin{proof}\n    Let’s write the difference between the function and its discrete approximation\n    \\begin{align*}\n        \\| u - \\mathcal{J}_{2N}u \\|_{L^2 [0, 2\\pi]} &= \\| (\\mathcal{P}_{2N} - \\mathcal{J}_{2N})u + u - \\mathcal{P}_{2N}u \\|_{L^2 [0, 2\\pi] } \\\\\n        &\\leq  \\| (\\mathcal{P}_{2N} - \\mathcal{J}_{2N})u \\|_{L^2 [0, 2\\pi] } + \\| u - \\mathcal{P}_{2N}u \\|_{L^2 [0, 2\\pi] }\n    \\end{align*}\n    Thus, the error has two components. The first one, which is the difference between the continuous and discrete expansion coefficients, is the aliasing error, which is bounded in Lemma \\ref{estimating_aliasing_error}. The second, which is the tail of the series, is the truncation error, which is bounded by the result of Theorem \\ref{estimating_error_PN_L2}. The desired result follows from these error bounds.\n\t\\end{proof}\n\n    Theorem above confirms that the approximation errors of the continuous expansion and the discrete expansion are of the same order, as long as $u(x)$ has at least half a derivative. Furthermore, the rate of convergence depends, in both cases, only on the smoothness of the function being approximated.   ", "meta": {"hexsha": "6d578b5e4060590fc45250f38c26d082989d9fd5", "size": 28033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/preliminaries/Interpolation_Operator.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/preliminaries/Interpolation_Operator.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/preliminaries/Interpolation_Operator.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 62.5736607143, "max_line_length": 842, "alphanum_fraction": 0.6439196661, "num_tokens": 9975, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.9086178981700932, "lm_q1q2_score": 0.7861580873573002}}
{"text": "\\chapter{Abstract Framework for DNN Models}\n\n\\section{An abstract framework for ANN}\n\\subsection{Problem: function interpolation}\nWhat we want to do is to approximate a function $f^*: V \\to U$, with some given data $\\{X^i, Y^i\\}_{i=1}^N$. {\\bf{But the fact is that, we know only few things about $f^*$!}} If we can know more things about $f^*$, we can design some better model for interpolation such as: \n\\begin{itemize}\n\\item FEM: $f^*$ is a solution of elliptic PDE,\n\\item Spectral method: $f^*$ has sufficient high smoothness,\n\\item Deep learning: $f^*$ is produced by the human neural network. \n\\item $\\cdots$\n\\end{itemize}\nA general idea is to construct a parameters depended function family such $f(W; x)$, where $W \\in \\mathcal{W}$, so we can have the next simple problem:\n\\begin{problem}\nFind the parameter $\\theta^{*}$ such that:\n\\begin{equation}\n\\theta^* = \\mathop{\\arg\\min}_{\\theta \\in \\Theta} \\sum_{i}^N L(f(\\theta;X^i) , Y^i).\n\\end{equation}\nHere $L(\\cdot, \\cdot)$ is a general metric to define the difference between the real function value $Y^i$ and the predicted out put $f(\\theta;X^i)$, a simple example is $ L(f(\\theta;X^i) , Y^i) = \\|f(\\theta;X^i) - Y^i\\|^2_{U}$. \n\\end{problem}\nThen we could choose $f(\\theta^*; x)$ as the interpolation of $f$ by given data $\\{X^i, Y^i\\}_{i=1}^N$.\n\nSo, all problem reduced to how to construct a suitable function family $f(W;x): V \\to U$. In my opinion, different kinds of machine learning models mean different function families. For example, linear regression means that: \n\\begin{equation}\nf(\\theta; x) = w x + b, \\quad \\theta = \\{w, b \\},\n\\end{equation}\nwhere\n\\begin{equation}\nw \\in L(V, U) \\quad \\text{and} \\quad b \\in U .\n\\end{equation}\n\n\n\\subsection{Function family with abstract auxiliary space}\nSo, now we want to explain the deep learning model based on the idea of function family. The model for deep learning is a little different from the traditional models. The main idea is to imitate the human neural network structure that is the composition of many neurons because $f$ is the reaction of humans for the \"input\" from real world. But in fact we don't know what real human neural network connection is, so we use a simple idea that those neurons have the hierachical structure. (I will show in the latter, it seems that adding the shortcut connection into those pure hireachical structure will be better.)\n\nFrom the discussion above, We can take the fully connected feedforward neural network as the composition of affine map and nonlinear map in just some abstract linear space. It means that we construct a nonlinear function from $V$ to $U$ with the auxiliary space $V_i$ with $i = 1:J$ such that we have those next functions:\n\\begin{equation}\\label{equ:affinemap}\nA_i: V_{i-1} \\to V_i  \\quad \\text{with} \\quad A_i(x) = W_i (x)  + \\theta_i  \\quad \\text{with} \\quad W_i \\in L(V_{i-1}, V_i) ~~ \\theta_i \\in V_i.\n\\end{equation}\nand\n\\begin{equation}\ng_i: V_i \\to V_i \\quad \\text{is a general nonlinear function}\n\\end{equation}\nwhere $i = 0:J$ with $V_0 = V$ and $V_J = U$. \n\n$$\nA_i=(W_i, \\theta_i).\n$$\n\nSo the abstract nonlinear iterative form for $f$ is like:\n\\begin{equation}\\label{equ:abstractNN1}\nf = f_{out}\\circ f_J,\n\\end{equation}\nwith\n\\begin{equation}\\label{equ:abstractNN2}\nf_j = g_j(A_j(f_{j-1})), \\quad j = 1:J,\n\\end{equation}\nand\n\\begin{equation}\\label{equ:abstractNN3}\nf_0 = f_{in}(x), \\quad x \\in V.\n\\end{equation}\nHere in most cases, $f_0(x)=x$.  But sometimes we can also view $f_0$ as \ndenoising process?\n\nWe note that\n$$\nf_j: V\\times {\\cal W}^j\\mapsto V_j. \n$$\nand \n$$\nf_j(x,{\\mathbf A}_j)\n$$\nwhere \n$$\n{\\mathbf A}_j=(A_1,\\ldots A_j)=({\\mathbf A}_{j-1},A_j).\n$$\n\nNotice that\n$$\nf_0=f_{\\rm in}: V=V_0\\mapsto V\n$$\nwhich is pre-process, and\n$$\nf_{J+1}=f_{\\rm out}: U=V_{J}\\mapsto U\n$$\nwhich is a post-process.\n\nGenerally speaking, if we fix those auxiliary space $V_i$, $g_i$, $f_{in}$ and $f_{out}$, then $f$ only depends on those affine map $A_i \\in A(V_{i-1}, A_{i})$ defined in \\ref{equ:affinemap}.  So in the abstract form,\n\\begin{equation}\n{\\cal W}^j = \\Pi_{i=1}^j A(V_{i-1}, V_i).\n\\end{equation}\n\\begin{equation}\n\\mathcal{W} = \\Pi_{i=1}^J A(V_{i-1}, V_i).\n\\end{equation}\n\n\\subsection{Loss functions and optimization problems}\nForget about \"BP\", we first express our problem as:\n\\begin{problem}Fix $V_i$, $g_i$, $f_{in}$ and $f_{out}$, then the optimization problem is:\n\\begin{equation}\n\\mathop{\\arg\\min}_{{\\mathbf A}\\in {\\cal W}} \\sum_{j=1}^N \\| f(X^j, {\\mathbf A}) - Y^j \\|^2_{U}\n\\end{equation}\n\\end{problem}\n\nWe need to discuss other possible loss functions ....\n\n\n\\section{ANN: a fully connected model}\nOnce we use general vector space like $\\mathbb{R}^n$, $\\mathbb{R}^{n_i}$ and $\\mathbb{R}^c$ to represent $V$, $V_i$ and $U$. So the affine map from $V_{i-1}$ to $V_i$ can be represented as: \n\\begin{equation}\nA_i(x) = W_i x + \\theta_i, \\quad \\text{with} \\quad W_i \\in \\mathbb{R}^{n_i \\times n_{i-1}} \\quad \\theta_i \\in \\mathbb{R}^{n_i}.\n\\end{equation}\nAnd if the nonlinear map $g_i$ is a little special like:\n\\begin{equation}\ng_i(x_1, \\cdots, x_{n_i}) = (g(x_1), \\cdots, g(x_{n_i}))^T, \\quad \\forall i = 1:J,\n\\end{equation}\nwhere $g$ is a certain nonlinear function form $\\mathbb{R}$ to $\\mathbb{R}$. Some general choose for $g$ can be: Sigmiod, ReLU and etc.\n\nSo the vector representation of the \\ref{equ:abstractNN1} to \\ref{equ:abstractNN3} is the ANN model exactly. And $J$ is the number of hidden layers and $dim(V_i)$ is the neural numbers for the hidden layer $i$. \n\nThe model will be expressed like:\n\\begin{equation}\\label{equ:repNN1}\nf(W;x) = f_{out}\\circ f_J,\n\\end{equation}\nwith\n\\begin{equation}\\label{equ:repNN2}\nf_j = g_j(W_jf_{j-1} + \\theta_j), \\quad j = 1:J,\n\\end{equation}\nand\n\\begin{equation}\\label{equ:repNN3}\nf_0 = f_{in}(x), \\quad x \\in V.\n\\end{equation}\nSo if we fix those auxiliary space by $n_i$, $g_i$, $f_{in}$ and $f_{out}$, all parameters are:\n\\begin{align}\n\\mathcal{W} &= \\{ (W_i, \\theta_i) ~ :  ~ W_i \\in \\mathbb{R}^{n_{i} \\times n_{i-1}} ~ ~\\theta_i \\in \\mathbb{R}^{n_i}, i = 1:J \\}, \\\\\n&= \\Pi_{i=1}^J ( \\mathbb{R}^{n_{i} \\times n_{i-1}} \\times  \\mathbb{R}^{n_i}).\n\\end{align}\n\n\n\\section{Classification problems}\nNow we will state some observation about the classification problems. First is about what kinds of set can be split by linear model(neural network without hidden layers).\n\\begin{definition}(linear separate)\\label{assum:linsep}\nAssume that $\\{A_i\\}_{i=1}^c \\subset \\mathbb{R}^n$ can be separated by hyperplane by $\\{H_i\\}_{i=1}^c$ i.e for every $A_i$ there exists $H_i$ such $H_i$ will separate $A_i$ and $\\{A_1, \\cdots, A_{i-1}, A_{i+1}, \\cdots, A_c\\}$.\n\\end{definition}\n\\begin{lemma}\nIf the different finite sets $\\{A_i\\}_{i=1}^c \\subset \\mathbb{R}^n$ satisfy the assumption \\ref{assum:linsep}, then there exists a simple neural network such that \n\\begin{equation}\nf(x_i) = e_i \\quad \\forall x_i \\in A_i ~~ i= 1:c.\n\\end{equation}\n\\end{lemma}\n\\begin{proof}We can just choose \n\\begin{equation}\nf(x; \\{W,b\\})  = H(Wx + b)\n\\end{equation}\nwith $W_i$ and $b_i$ define the hyperplane $H_i$ and $H$ is the Heaviside function. Then this $f$ is what we want. So this is a simple neural network without hidden layers.\n\\end{proof}\n\n%\\begin{theorem}[Kernel function]For different finite set $\\{A_i\\}_{i=1}^c$in $\\mathbb{R}^n$(may we need some other conditions), there exists a function $g: \\mathbb{R}^n \\to \\mathbb{R}^m$ such that $\\{g(A_i)\\}_{i=1}^c$ will satisfy the assumption of linear separable \\ref{assum:linsep}.\n%\\end{theorem}\n%\\begin{proof}Xiaodong or check literature.\n%\\end{proof}\n\n\\begin{definition}[Separabel]\nFor different finite set $\\{A_i\\}_{i=1}^c$in $\\mathbb{R}^n$, we say they are separable if there exists a kernel function $g \\in (C^0({I^n}))^m$ such that $\\{g(A_i)\\}_{i=1}^c$ will satisfy the assumption of linear separable \\ref{assum:linsep}.\n\\end{definition}\n\n\\begin{remark} Here we show some some cases about the mapping $g$. We can construct a partition of $\\mathbb{R}^n$ based on $\\{A_i\\}_{i=1}^c$, and then use partition of unity we get\n$\\{g_i\\}_{i=1}^c$ with \n\\begin{equation}\ng_{i}(x) = \\delta_{ij} \\quad \\forall i ~~ \\text{and}~~  x \\in A_j.\n\\end{equation}\nThen we will have:\n\\begin{align}\ng: \\mathbb{R}^n &\\to \\mathbb{R}^c \\\\\nx &\\mapsto (g_1, \\cdots, g_c).\n\\end{align}\nThis means that, if $x\\in A_i$ then\n\\begin{align}\ng(x) = e_i \\quad \\forall i = 1:c.\n\\end{align}\n\nThis means $\\{g(A_i)\\}_{i=1}^c$ are just $ m = c$ points and can be linearly separated with sparse structure for $W$. Here one can just take $W = I_{m \\times c} = I_{c\\times c}$ and $b_i = -\\frac{1}{2}$.\n\nWhat's more, we can think about the binary problems $A_0$ and $A_1$, if there is a manifold $\\mathcal{M}$ such that $\\mathcal{M}$ can separate them.(We can fix the orientation of $\\mathcal{M}$, and makes this statement in mathematics.) If \n\\begin{align}\n\\mathcal{M} = \\{ x ~ | ~ \\phi(x) = 0\\},\n\\end{align}\nwith $\\phi \\in C^{\\infty}(\\mathbb{R}^n)$. So, here you have two ways to choose the mapping,\n\\begin{itemize}\n\\item Just choose $g = \\phi$, then this satisfy this condition of the continuity of $\\phi$.\n\\item If $\\phi = \\sum_{i=1}^m w_i \\phi_i + b = 0$, so we can take $g = (\\phi_1, \\cdots, \\phi_m)$, and the separation hyperplane is:\n\\begin{align}\n\\sum_{i=1}^m w_i y_i + b = 0,\n\\end{align}\nin $\\mathbb{R}^m$.\n\\end{itemize}\n\n{\\bf But, how to extend this binary problems into multi-classification problems in this way seems to \nnon-trival.}\n\n\\end{remark}\n\n\n\\begin{theorem}\nFor different finite set $\\{A_i\\}_{i=1}^c$in $\\mathbb{R}^n$ satisfy the separable condition, then there exists a DNN model with one hidden layer such that \n\\begin{equation}\nf_\\theta(x_i) = e_i \\quad \\forall x_i \\in A_i \\quad i = 1:c,\n\\end{equation}\nwith \n\\begin{align}\nf_{\\theta}(x) = H(W_2\\sigma(W_1x + b_1) + b_2).\n\\end{align}\nWhat's more, we can set $W_2 \\in \\mathbb{R}^{c \\times N}$ with \n\\begin{equation}\nW_2 = W \\cdot K,\n\\end{equation}\nsuch that $W \\in \\mathbb{R}^{c \\times m}$ and $K \\in \\mathbb{R}^{m \\times N}$.\n\\end{theorem}\n\\begin{proof}\nFirst, there exists a $g$ and $H(Wx + b)$ such that\n\\begin{align}\n\\tilde{f}_{\\theta}(x_i) = H(W\\tilde{g}(x_i) + b) = e_i \\quad \\forall x_i \\in A_i \\quad i = 1:c.\n\\end{align}\n\nThen by the continuous and properties of Heaviside function, there exists $\\epsilon > 0$ such that so for any $g \\in  (C^0({I^n}))^m$ with \n\\begin{align}\n\\|g - \\tilde{g}\\|_{L^{\\infty}} \\le \\epsilon.\n\\end{align}\nWe will have\n\\begin{align}\nf_{\\theta}(x_i) = H(Wg(x_i) + b) = e_i \\quad \\forall x_i \\in A_i \\quad i = 1:c.\n\\end{align}\n\nBecause of the universal approximation theory for artificial neural network, i.e. there exists a network like \n\\begin{align}\ng(x) = K\\sigma(W_1 x + b_1) + \\alpha,\n\\end{align}\nwith \n\\begin{align}\nK = \\mathrm{diag}\\{K_1, \\cdots, K_m\\}, \\quad K_i \\in \\mathbb{R}^{1\\times n_i}  \\quad N = \\sum_{i=1}^m n_i,\n\\end{align}\nsuch that\n\\begin{align}\n\\|g - \\tilde{g}\\|_{L^{\\infty}} \\le \\epsilon.\n\\end{align}\n\nSo \n\\begin{align}\nf_{\\theta}(x_i) = H(W_2\\sigma(W_1x_i + b_1) + b_2) = e_i \\quad \\forall x_i \\in A_i \\quad i = 1:c,\n\\end{align}\nand \n\\begin{equation}\nW_2 = W \\cdot K,\n\\end{equation}\nwith $W \\in \\mathbb{R}^{c \\times m}$ and $K \\in \\mathbb{R}^{m \\times N}$.\n\n\\end{proof}\n\n\n\\section{CNN model under this framework}\n\\subsection{Simple convolution introduction(without multichannel)}\nThere is a kind of special linear map from some general finite dimension tensor space to another is called ``convolution\".  Generally, we have a tensor like $X \\in \\mathbb{R}^{n \\times m}$ and a small kernel such as $K \\in \\mathbb{R}^{k\\times k}$, then we have:\n\\begin{definition}[Original Convolution with stride 1 for CNN]\n\\begin{equation}\\label{equ:conv}\n(X\\ast K)_{i,j} = \\sum_{s, t = 1}^k X_{i-1 + s, j-1 + t} K_{s,t}.\n\\end{equation}\nIt's easy to see that $(X\\ast K) \\in \\mathbb{R}^{(n-k + 1) \\times (m-k + 1)}$.\n\\end{definition}\nIf we use stride $p$, we have:\n\\begin{definition}[Original Convolution with stride $p$ for CNN]\n\\begin{equation}\\label{equ:convstride}\n(X\\ast_{p} K)_{i,j} = \\sum_{s, t = 1}^k X_{(i-1)p + s, (j-1)p + t} K_{s,t}.\n\\end{equation}\nSo, we have \n$\n(X\\ast_p K) \\in \\mathbb{R}^{((n-k)/p + 1) \\times ((m-k)/p+1)}.\n$\n\\end{definition}\nThis stride properties in some application is be used as pooling(subsampling, coarsening).  \n\nHere we can define a special pooling operator as $S^p$ which likes the $C/F$ split for choosing coarse point:\n\\begin{equation}\nS^p(X)_{i,j} = X_{(i-1)p + 1, (j-1)p + 1},\n\\end{equation}\nthen we have:\n\\begin{equation}\\label{equ:stride}\nX \\ast_p K = S^p(X\\ast K),\n\\end{equation}\nwith the $\\ast$ and $\\ast_p$ defined by \\ref{equ:conv} and \\ref{equ:convstride}\n\\begin{proof}\n\\begin{align}\nS^p(X \\ast K)_{i,j} &= (X \\ast K)_{(i-1)p+1, (j-1)p + 1}  \\\\\n&= \\sum_{s,t = 1}^k X_{(i-1)p + 1 -1 +s, (j-1)p +1 -1 +t}K_{s,t}  \\\\\n&= (X \\ast_p K)_{i,j}.\n\\end{align}\n\\end{proof}\n\n\\subsubsection{Convolution(without changing size)}\nFor many case kernel size is some small odd numbers such as 1, 3, 5... So we ca have those next definition for convolution:\n\\begin{definition}[Convolution with Padding]\n\nWe write $K\\in \\mathbb R^{2k+1, 2k+1}$, we then write\n\\begin{equation}\\label{ConvPadding}\n(X \\hat{\\ast} K)_{i,j} := (\\rm{P}^k(X) \\ast K)_{i,j} = \\sum_{s, t = -k}^k X_{i + s, j + t} K_{s,t},\n\\end{equation}\nwith $\\rm{P}^k$ means Padding. \n\\end{definition}\nHere we see that, to make this definition well-defined, we have $X\\ast K \\in \\mathbb{R}^{n-2k, m-2k}$, because if the index of $X$ start from $1$ to $n(m)$, then $X \\ast K$ from $k+1$ to $n(m) - k$. To make the convolution don't change size, we can use Padding strategy like in image process. \n%In fact, if the resolution is very high, which means the measure of the boundary of the image is close to 0, so in traditional image process, this strategy hasn't been studied very well. There are basic three strategy:\n\\begin{description}\n\\item[Zero Padding] The simplest and most common used strategy is zero padding with:\n\\begin{equation}\n\\rm{P}^k_0: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_0^k(X)_{i,j} = \\begin{cases}\n0 &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \n\\end{cases}\n\\end{equation}\n\\item[Reflection Padding] This strategy is defined by:\n\\begin{equation}\n\\rm{P}^k_r: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_r^k(X)_{i,j} = \\begin{cases}\nX_{1-i, 1-j} &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \\\\\n0 &\\text{others} \n\\end{cases}\n\\end{equation}\n\\item[Shift Padding] This strategy is defined by:\n\\begin{equation}\n\\rm{P}^k_s: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{n+2k \\times m+2k}\n\\end{equation}\nwith \n\\begin{equation}\n\\rm{P}_s^k(X)_{i,j} = \\begin{cases}\nX_{k-i, k-j} &i(j)=-k+1:0 ~~\\text{and}~~ i(j) = n(m)+1:n(m)+k \\\\\nX_{i,j} &i(j) = 1:n(m) \\\\\n0 &\\text{others} \n\\end{cases}\n\\end{equation}\n\\end{description}\n\nSo we can have:\n\\begin{equation}\n\\rm{dim}(X\\hat{\\ast}K) = \\rm{dim}(\\rm{P}^k(X) \\ast K) = \\rm{dim}(X),\n\\end{equation}\nand the $i,j$ index is consistent for both side of the above equation where $\\rm{P}^k = \\rm{P}_0^k, \\rm{P}_{r}^k$ or $\\rm{P}_s^k$.\n\n\n\\begin{remark}We note all the later convolution as the \\eqref{ConvPadding} for consistent.\n\n\\end{remark}\n\n\\subsection{Convolution with multichannel}\n\\subsubsection{Traditional convolution for multichannel case}\nHere in real data, we have some special data like colour image $X \\in \\mathbb{R}^{n \\times m \\times3}$. Here this image is a 2D graph, with $3$ means the $RGB$ channels. So, we cannot just think $X$ as a general $3$-order tensor. We may just use this as an example, $X \\in \\mathbb{R}^{n\\times m \\times c}$, we say that $n \\times m$ is the essential dimension and $c$ is the channel dimension for $X$. If we want to do convolution for $X$, here we cannot just use $K \\in \\mathbb{R}^{k\\times k}$ because of multichannel. A simple idea is to use also different $c$ kernels and collect them together as $K \\in \\mathbb{R}^{k\\times k \\times c}$, and then we can do the general convolution for signal channel separately. This means that \n\\begin{equation}\n(X\\ast_{p} K)_{i,j,l} = \\sum_{s, t = 1}^k X_{(i-1)p + s, (j-1)p + t,l} K_{s,t,l},\n\\end{equation}\nand $(X\\ast_p K) \\in \\mathbb{R}^{((n-k)/p + 1)\\times ((m-k)/p+1) \\times c}$. But we need to recall that, even for $X \\in \\mathbb{R}^{n\\times m \\times c}$ it is in fact only stand for just one 2D image(with multi-channel). So if we talk about features in AI, $(X\\ast_p K) \\in \\mathbb{R}^{((n-k)/p + 1)\\times ((m-k)/p+1) \\times c}$ should be reduced to the essential dimension, one simple way is just to add all the channels value together w.r.t essential dimension(this is equal to added with weights because we can reduce those DoF into the previous $c$ kernels.):\n\\begin{equation}\n(X \\hat{\\ast}_p K)_{i,j} = \\sum_{l=1}^{c} \\sum_{s, t = 1}^k X_{(i-1)p + s, (j-1)p + t,l} K_{s,t,l},\n\\end{equation}\nthen we have\n\\begin{equation}\n(X \\hat{\\ast}_p K) \\in \\mathbb{R}^{((n-k)/p + 1) \\times ((m-k)/p+1)} \\quad \\text{with} \\quad K \\in \\mathbb{R}^{n \\times m \\times c}.\n\\end{equation}\nSo, for a given real data with $c$ channels like $X \\in  \\mathbb{R}^{n\\times m \\times c}$ if we use kernel $K \\in \\mathbb{R}^{k\\times k \\times c}$ we can only get a signal channel output. To get multichannel form $X$, we just need to use $d$ kernels $K \\in \\mathbb{R}^{k\\times k \\times c}$, or we say $K \\in \\mathbb{R}^{k\\times k \\times c \\times b}$, then we have:\n\\begin{equation}\\label{6.6}\n(X \\hat{\\ast}_p K)_{i,j,g} = \\sum_{l=1}^{c} \\sum_{s, t = 1}^k X_{(i-1)p + s, (j-1)p + t,l} K_{s,t,l,g},\n\\end{equation}\nwith \n\\begin{equation}\n(X \\hat{\\ast}_p K) \\in \\mathbb{R}^{((n-k)/p + 1) \\times ((m-k)/p+1) \\times b} \\quad \\text{with} \\quad K \\in \\mathbb{R}^{n \\times m \\times c \\times b}.\n\\end{equation}\n\nIn the next section, we set that all tensor is with\nmultichannel(signal channel is a special case, and we note it as $X\n\\in \\mathbb{R}^{n \\times m \\times 1}$), and we just use $\\ast_p$ no\nlonger $\\hat{\\ast}_p$.\n\n\\subsubsection{New version}\nHere we consider our data like $T = (T_1, T_2, T_3)$ with $T_i \\in \\mathbb{R}^{n\\times n}$.\n\nProf. Xu's idea is to say that, we need to keep the original ``channel\" parallel i.e we just need three kernels like \n\\begin{align}\nK_0 = \\begin{pmatrix}\nK^1 \\\\ K^2 \\\\ K^3\n\\end{pmatrix}.\n\\end{align} So we get:\n\\begin{equation}\nT \\to T\\tilde{\\ast} K_0 = (T_1 \\ast K^1, T_2\\ast K^2, T_3 \\ast T^3),\n\\end{equation}\nand then we apply the active function $a$ to $(T_1 \\ast K^1, T_2\\ast K^2, T_3 \\ast T^3)$ element by element. And then use \n\\begin{align}\nT^{new} = (a(T_1 \\ast K^1), a(T_2\\ast K^2), a(T_3 \\ast T^3))\n\\end{align} as the next input for the CNN network.\n \nNow we want to show that the traditional method with more kernels can reproduce the $T^{new}$ in Prof. Xu's case.\n\nHere we set we have some more kernels like \n\\begin{align}\nK = \n\\begin{pmatrix}\nK_1^1 & \\cdots & K_1^N \\\\\nK_2^1 & \\cdots & K_2^N \\\\\nK_3^1 & \\cdots & K_3^N \n\\end{pmatrix},\n\\end{align} with $K_i^j \\in \\mathbb{R}^{3\\times3}$.\n\nWhat we have at most are:\n\\begin{equation}\n\\tilde{T} = T\\tilde{\\ast} K =  \\begin{pmatrix}\nT_1 \\ast K_1^1 & \\cdots & T_1\\ast K_1^N \\\\\nT_2 \\ast K_2^1 & \\cdots & T_2\\ast K_2^N \\\\\nT_3 \\ast K_3^1 & \\cdots & T_3\\ast K_3^N \n\\end{pmatrix}\n\\end{equation}\n\n{\\bf Here in fact we can have a simple question: why we don't just put $a(\\tilde{T})$ as the next input for the next layer of CNN? Maybe this dimension is to large?}\n\nTraditional method for convolution with channel is to say we need to compress the original ``channel\" dimension by take \n\\begin{equation}\n\\tilde{T}  \\to ( \\sum_{j=1:3} T_j\\ast K_{j}^1, \\cdots, \\sum_{j=1:3} T_j\\ast K_{j}^N),\n\\end{equation} \nand then apply the active function $a$ getting:\n\\begin{equation}\n(a( \\sum_{j=1:3} T_j\\ast K_{j}^1), \\cdots, a(\\sum_{j=1:3} T_j\\ast K_{j}^N)).\n\\end{equation}\n\nSo we can see that, if we take $ N = 3$ then we can reproduce the \n$T^{new} = (a(T_1 \\ast K^1), a(T_2\\ast K^2), a(T_3 \\ast T^3))$ from $(a( \\sum_{j=1:3} T_j\\ast K_{j}^1), \\cdots, a(\\sum_{j=1:3} T_j\\ast K_{j}^N))$ by just take\n\\begin{align}\nK^i = \\sum_{j=1:3} K_j^i, \\quad \\forall i = 1:3.\n\\end{align}\n\n\\begin{remark}\nHere we can take Prof. Xu's idea and the traditional convolution as consistent by means that because the dimension for $a(\\tilde{T})$ is too large({\\bf In fact, we like redundancy some times, why we just use this directly?}), we need some ways to compress $\\tilde{T}$ first and then apply active function $a$. The simplest next two ways is:\n\\begin{itemize}\n\\item Compress(sum) $\\tilde{T}$ in row. This leads to Prof. Xu's idea keeping the ``channel\" number as 3.\n\\item Compress(sum) $\\tilde{T}$ in column. This leads to traditional idea changing the ``channel\" into $N$.\n\\end{itemize}\n\n{\\bf Another questions is how to compress this $\\tilde{T}$ ``better\"?  What dose better means?}\n \n\\end{remark}\n \n\\subsection{Convolution with vectorization and matrix tensor product}\n\\subsubsection{Vectorization and matrix tensor product}\nFirst, we can define the next vectorization operator:\n\\begin{equation}\n\\rm{Vec}: \\mathbb{R}^{n \\times m} \\to \\mathbb{R}^{nm}\n\\end{equation}\nwith \n\\begin{equation}\n(\\rm{Vec}(X))_{(i-1)m + j} = X_{ij}.\n\\end{equation}\n\nIn this notation, for a discrete $u_{i,j}$ with $ i, j = 1:n$, we can have the next 5-points difference scheme with:\n\\begin{equation}\n\\rm{Vec}(\\Delta_h u) = M_5 \\rm{Vec}(u),\n\\end{equation}\nwith \n\\begin{equation}\nM_5 = T\\otimes I_{n} + I_{n} \\otimes T,\n\\end{equation}\nwhere $T$ is the $1-D$ mid-point difference matrix like: \n\\begin{equation}\nT = \\rm{tridiag}(-1,2,-1) \\in \\mathbb{R}^{n \\times n}\n\\end{equation}\n\n\\subsubsection{5-points difference as a special convolution}\nFor general convolution definition, the convolution operator will reduce the dimension for the input data. Here we begin with $1-D$ case, like $K \\in \\mathbb{R}^{3}$, then for a vector $X \\in \\mathbb{R}^n$, we do the general convolution with stride 1, then we have \n\\begin{equation}\nX \\ast K \\in \\mathbb{R}^{n-2},\n\\end{equation}\nand if we take $K = (-1, 2, -1)$, then\n\\begin{equation}\nX \\ast K = \\Delta_h X_{2:n-1},\n\\end{equation}\nwith boundary condition $X_{\\rm{left}} = X_1$ and $X_{\\rm{right}} = X_n$.  \n\nTo preserve the dimension, we can use the ``Padding\" operator for $1-D$:\n\\begin{equation}\n\\rm{Pad}(X) = (0, X, 0),\n\\end{equation}\nthere are similar definition for $n-D$ tensor. \n\nThen we have:\n\\begin{equation}\n\\rm{Pad}(X) \\ast K = \\Delta_h X = T X.\n\\end{equation}\n\nSo for $2-D$ case $u \\in \\mathbb{R}^{n \\times n}$, and \n\\begin{equation}\nK = \n\\begin{pmatrix}\n0 & -1 & 0 \\\\\n-1 & 4 & -1 \\\\\n0 & -1 & 0 \n\\end{pmatrix}\n\\end{equation}\nthen we have: \n\\begin{equation}\n\\rm{Vec}(\\rm{Pad}(u) \\ast K ) = \\rm{Vec}(\\Delta_h u) = M_5 \\rm{Vec}(u).\n\\end{equation}\n\n\n\\subsection{Convolution explained by liner map with special structure}\nCNN can also be recovered by the abstract form above with the represent of $V_i$ to be general tensor space. For example, $V_{i-1} = \\mathbb{R}^{n \\times m}$ and $V_i = \\mathbb{R}^{l}$, then we can just set \n\\begin{equation}\nA_i(X) = WX + \\theta \\in V_i,\n\\end{equation}\nwhere\n\\begin{equation}\n(WX)_{g} = \\sum_{s,t=1}^{n,m}W_{s,t,g}X_{s,t}, \\quad W \\in \\mathbb{R}^{l \\times n \\times m}\n\\end{equation}\n\nJust as what we see above, the dimension of $V_i$ can not be arbitrary, it is defined by the kernel and stride size and the numbers of the kernel. \n\nAn example for this is like that, $X \\in V_{i-1}$ is a signal channel 2D tensor, and we choose just one kernel $K \\in \\mathbb{R}^{k\\times k}$ with stride p, which means that $V_i = \\mathbb{R}^{(n-k)/p + 1)\\times ((m-k)/p+1)}$.  Then the $W \\in \\mathbb{R}^{((n-k)/p + 1)\\times ((m-k)/p+1) \\times n \\times m}$ should be like: \n{\\small{\n\\begin{equation}\nW_{i,j, s,t} = \\begin{cases}\nK_{s-(i-1)p,t-(j-1)p} ~ &\\text{if} ~ s \\in (i-1)p+1:(i-1)p+k ~ \\& ~ t \\in (j-1)p+1:(j-1)p+k \\\\\n&0.\n\\end{cases}\n\\end{equation}\n}}\nNow if we consider $X \\in V_{i-1} = \\mathbb{R}^{n \\times m \\times c }$ with $c$ channels and we choose kernel as $K \\in \\mathbb{R}^{k\\times k \\times c \\times b}$ and use convolution with stride p, which means $V_{i} = \\mathbb{R}^{((n-k)/p + 1)\\times ((m-k)/p+1) \\times b}$. So we have \n\\begin{equation}\nW \\in L(V_{i-1}, V_i) = \\mathbb{R}^{(((n-k)/p + 1)\\times ((m-k)/p+1) \\times b) \\times (n \\times m \\times c)},\n\\end{equation}\nwith \n{\\small{\n\\begin{equation}\nW_{i,j,g, s,t,l} = \\begin{cases}\nK_{s-(i-1)p,t-(j-1)p,l,g} ~ &\\text{if} ~ s \\in (i-1)p+1:(i-1)p+k ~ \\& ~ t \\in (j-1)p+1:(j-1)p+k \\\\\n&0.\n\\end{cases}\n\\end{equation}\n}}\nThen we have:\n\\begin{equation}\nWX = X \\ast_p K.\n\\end{equation} \n\n\nAt last, in the CNN model, the shift vector $\\tilde\\theta \\in V_i$ is also have a special structure with\n\\begin{equation}\n\\tilde\\theta_{i,j,l} = \\theta_l,\n\\end{equation}\nwhich means $dim(\\tilde\\theta) = b = $ the number of kernels in $K$. Which means that:\n\\begin{equation}\ndim(W) + dim(\\tilde\\theta) = dim(K) + dim(\\tilde\\theta) = k\\times k \\times c \\times b + b \\neq dim(L(V_{i-1}, V_i)) + dim(V_i).\n\\end{equation}\n\n\\subsection{Active function}\n\n\n\\subsection{Pooling and convolution with stride}\nJust as saying before, if $X \\in V_{i-1} = \\mathbb{R}^{n \\times m \\times c }$ with $c$ channels and we choose kernel as $K \\in \\mathbb{R}^{k\\times k \\times c \\times b}$ and use convolution with stride p, then we have\n\\begin{equation} \nV_{i} = \\mathbb{R}^{((n-k)/p + 1)\\times ((m-k)/p+1) \\times b},\n\\end{equation}\nwhich means that the essential dimension of $X$ was almost decreased to $\\frac{1}{p}$, which is almost like result of the pooling(subsampling or coarsening) operation. So, in some recent popular CNN models, they often choose the convolution with stride $2$ as the a combination of convolution and pooling layers.\n\nHowever, we can say that, some general pooling operation is in fact nonlinear operation but convolution with stride $p$ is still a special linear map and this may also change the channel dimensions. So we would like to added the pooling operation as a special kind of restriction, such as $X \\in V_{i-1} = \\mathbb{R}^{2n \\times 2m \\times c }$ then \n\\begin{equation}\nR(X)_{i,j,l} = r(X_{(2i - 1:2i), (2j-1:2j),l}),\n\\end{equation}\nwith $r(\\bm{x})$ can be:\n\\begin{itemize}\n\\item Maxout: $r(\\bm{x}) = \\max \\{x_1, \\cdots, x_4\\}$,\n\\item Average: $r(\\bm{x}) = \\frac{\\sum_{i=1}^4 x_i}{4}$,\n%\\item $L^2$ normal: $r(\\bm{x}) = \\|x\\|$,\n\\item $\\cdots$\n\\end{itemize}\nHere we see that $R: V_i \\to \\hat{V}_i$ only change the essential dimension for $X$ and apply $r$ separately w.r.t channel dimension. In real application, you can also use the channel-cross pooling strategy which will a little like the convolution with stride.\n\n\\subsection{General structure for CNN}\nA general CNN model is the composition of convolution, nonlinear map and pooling layers then followed with few ANN layers. \nNow we still assume that data is like $\\{X^i, Y^i\\}_{i=1}^N$ with $X_i \\in V_0$ and $Y_i \\in U$. We choose some auxiliary space $V_i$, $\\hat{V}_i$ with $i = 1:J$ and $U_i$ with $i = 1:L$. \n\nWe can use just $f_{ANN}(W_A; x)$ to denote the ANN model from $V_J$ to $U$ with auxiliary space $U_i$ with $i = 1:L$.\n\nAnd the CNN part can be expressed as:\n\\begin{align}\nf_{CNN} &= f_J(W_{CNN};x), \\\\\nf_j &= R_j \\circ g(W_i f_{j-1} + \\tilde{\\theta}_i), \\quad j = 1:J \\\\\nf_0 &= x.\n\\end{align}\n\\begin{itemize}\n\\item For many real CNN models, $R_j = \\rm{id}$ for many $j \\in 1:J$. \n\\item This likes a slash cycle with many smooth steps in every level.\n\\item The reason why they need so many smooth steps is to increase the parameter numbers, so try general cycle might be a interesting method.\n\\end{itemize}\n\nAna at last, we get a general CNN model as:\n\\begin{equation}\nf(W;x) = f_{ANN}(W_{ANN}; f(W_{CNN};x)), \\quad \\text{with} \\quad W = \\{W_{ANN}, W_{CNN}\\}.\n\\end{equation}\n\n\n\n\\section{RNN model under this framework}\n\\subsection{A simple example of RNN}\nHere we consider our problem with data like $X^i = (x^{i,(1)}, \\cdots, x^{i,(t)}, \\cdots, x^{i,(\\tau)})$ with $x^{i,(t)} \\in V^{(t)} = V$ for all $t = 1:\\tau$ and $Y^i = (y^{i,(1)}, \\cdots, y^{i,(t)}, \\cdots, y^{(i,\\tau)})$ with $y^{i,(t)} \\in U^{(t)} = U$ for all $t = 1:\\tau$. So, we can say that:\n\\begin{equation}\nX \\in \\bar{V} = \\underbrace{V\\times V \\times\\cdots \\times V }_{\\tau} ~\\text{and}~ Y \\in \\bar{U} =  \\underbrace{U\\times U \\times\\cdots \\times U }_{\\tau}.\n\\end{equation}\nSo we can use the similar idea in ANN, by choose auxiliary space $V_i$ and construct:\n\\begin{equation}\n\\bar{V}_i = \\underbrace{V_i \\times V_i \\times \\cdots \\times V_i}_{\\tau}, \\quad i = 1:J.\n\\end{equation}\n\nSo, we can also talk about the ANN with $\\bar{V}_i$ $i = 0:J+1$ like the definition in \\ref{equ:abstractNN1} to \\ref{equ:abstractNN3}. What's more, if \n\\begin{equation}\n\\bar{W}_i = \\text{diag}(W^{(1)}_i, \\cdots, W_i^{(\\tau)}),\n\\end{equation}\nand $g_i$ is a nonlinear map form $V_i^{(t)}$ to $V_i^{(t)}$. Then the ANN model form $\\bar{V}$ to $\\bar{U}$ is just $\\tau$ separate ANN model form $V$ to $U$. So, a naive idea to change this should be choose $\\bar{W}_i$ not be block diagonal matrix. {\\bf{But, this is not RNN!}}\n\nNow we show a simple RNN model with:\n\\begin{align}\nf_{1}^{(t)} &= g_1^{(t)}(\\theta_1 + W_1f_1^{(t-1)} + U_1x^{(t)}), \\\\\nf_{2}^{(t)} &= \\theta_2 + U_2f_{1}^{(t)}, \\\\\nf^{(t)} &= \\rm{softmax}(f_2^{(t)}).\n\\end{align}\n\nAlso we can have this kind of RNN network:\n\\begin{align}\nf_{1}^{(t)} &= g_1^{(t)}(\\theta_1 + W_1f_2^{(t-1)} + U_1x^{(t)}), \\\\\nf_{2}^{(t)} &= \\theta_2 + U_2f_{1}^{(t)}, \\\\\nf^{(t)} &= \\rm{softmax}(f_2^{(t)}).\n\\end{align}\n\nSo it seems that, we can have the next definition for RNN:\n\\begin{equation}\\label{equ:abstractRNN1}\nf = f_{out}\\circ f_J,\n\\end{equation}\nwith\n\\begin{equation}\\label{equ:abstractRNN2}\nf^{(t)}_j = g_j(\\bar{A}_j(f^{(t)}_{j-1}) + \\bar{W}_{j}^j f^{(t-1)}_{j}),\n\\end{equation}\nand\n\\begin{equation}\\label{equ:abstractRNN3}\nf_0 = f_{in}(x), \\quad x \\in \\bar{V}.\n\\end{equation}\nHere \n\\begin{equation}\n\\bar{W}_j^{j} \\in L(\\bar{V}_j, \\bar{V}_j), \\text{is a blocked lower triangular matrix}.\n\\end{equation}\nwhich is invariant through all timesteps from $t=1$ to $\\tau$. \\\\\nThis formula seems the symmetric form for the next section about the shortcut connection form.\n\\subsection{Development of the simple RNN}\nNote that $\\bar{W}_j^j$ denotes the relation between $V_j^{(t-1)}$ with $V_j^{(t)}$,we suppose that the relation is the same through all the timesteps, which is similar to the model of Markov chain. \\\\\nHowever, there exists some problems is the $\\bar{W}_j^j$ is a simple affine transformation. With the same matrix multiplied by many times, the eigenvalues will explode or decay to zero quickly. That leads to gradient exploding or gradient vanishing, which makes the simple model hard to capture the long-term dependence. Here we introduce the LSTM model to solve the problem. \\\\\nHere we transforms the $\\bar{A}_j$ and $\\bar{W}_j^J$ into the following form:\n\\begin{equation}\nf^{(t)}_j = g_j (\\bar{W}_{j}^j (f^{(t-1)}_{j},f^{(t)}_{j-1})),\n\\end{equation}\n\\begin{equation}\n\\bar{W}_{j}^j (f^{(t-1)}_{j},f^{(t)}_{j-1}) = \\sigma_1 \\ast s_j^{(t-1)} + \\sigma_2 \\ast q_j^{(t)}\n\\end{equation}\nwhere\n\\begin{align}\ns_j^{(t-1)} & = g_j^{-1} f_j^{(t-1)} = \\bar{A}_j(f^{(t-1)}_{j-1}) + \\bar{W}_{j}^{j} f^{(t-2)}_{j} \\\\\n\\sigma_1 & = g_j^{(f)}(\\bar{A}_j^{(f)}(f^{(t)}_{j-1}) + \\bar{W}_{j}^{j^{(f)}} f^{(t-1)}_{j}) \\\\\n\\sigma_2 & = g_j^{(g)}(\\bar{A}_j^{(g)}(f^{(t)}_{j-1}) + \\bar{W}_{j}^{j^{(g)}} f^{(t-1)}_{j}) \\\\\nq_j^{(t)} & = g_j^{(n)}(\\bar{A}_j^{(n)}(f^{(t)}_{j-1}) + \\bar{W}_{j}^{j^{(n)}} f^{(t-1)}_{j})\n\\end{align}\nThe superscripts f and g denote the 'forget' and 'get' gating, which control which part of $f_j^{(t-1)}$ and $f_{j-1}^{(t)}$ can be transformed into $f_j^{(t)}$.Here $\\bar{A}_j^{(f)} $,$\\bar{W}_{j}^{j^{(f)}}$,$\\bar{A}_j^{(g)}$ and $\\bar{W}_{j}^{j^{(g)}}$ are of the same definition in the simple RNN model. That's exactly the LSTM model. \\\\\nAlso,the LSTM model can be simplified into the GRU model, which keeps $\\sigma_1$ with the same definition, while$\\ \\sigma_2 = 1 - \\sigma_1$.That saves some cost of the computation.\n\n\n\\section{Shortcut connection}\nFirst, we would like to talk about the so called ``shortcut connection\" in general neural network. It can be defined more generally by\n\\begin{equation}\nf_j = g_j(A_j(f_{j-1} + \\sum_{i=0}^{j-2}\\tilde{W}_i^j f_i)) = g_j( \\sum_{i=0}^{j-1}W_i^{j}f_i + \\theta_j),\n\\end{equation}\nwhere \n\\begin{equation}\nW_i^j \\in  L(V_i, V_j) \\quad \\text{and} \\quad W_j = W_{j-1}^j. \n\\end{equation}\n\\subsection{ResNet}\nThe most important structure in ResNet model is the ``shortcut connection'' with 2-shortcusts, i.e:\n\\begin{align}\n&f = f_{out}\\circ f_J, \\\\\n&\\begin{cases}\nf_j = g_j(A_jf_{j-1} + I_jf_{j-2}), \\quad &\\text{for} ~j~ \\text{is odd} \\\\\nf_j = g_j(A_jf_{j-1}), \\quad  &\\text{for} ~j~ \\text{is even},\n\\end{cases} \\\\\n&f_0 = x.\n\\end{align}\n\nHere the convolution in ResNet adopt padding with zero such that the essential dimension will not change expect after the pooling layers. So in many case $I_j$ is just identity operator. If the are dimension reduction in essential dimension the $I_j$ is a simple restrict operator which needs to learn and just add zeros for the channel dimension. \n\n\\subsection{Two-grid method}\nSo, if we use the shortcut connection in a general ANN model, we can recover the simple two-grid scheme to solve $Au = b$ from $u^k$ to $u^{k+1}$ with $u^k \\in V = U = \\mathbb{R}^n$.\n\nOne thing I need to mention again is that, here we just use the network frame to recover the two-grid iterative scheme, all $A_i$ and $g_i$ is defined by ourself, one on need to be learnt. \n\nHere we set $g_i = id$ for $i = 1:6$.  And $V_i = V$ for $i = 1,4,5,6$ and $V_i = V_c$ for $i = 2,3$, where $V_c$ is the coarse space. $P$ is the interpolation operator form $V_c$ to $V$ and $A_c = P^T A P$, $R$ is the smoother on the fine grid. So we have the next definition of $A_i$: \n\\begin{itemize}\n\\item $f_1 = A_1(f_0) = b - Af_0$,\n\\item $f_2 = A_2(f_1) = P^T f_1$,\n\\item $f_3 = A_3(f_2) = A^{-1}_c f_2$,\n\\item $f_4 = A_4(f_3) = P f_3$,\n\\item $f_5 = A_5(f_4) + W_1^5 f_1 =f_1 -  Af_4$,\n\\item $f_6 = A_6(f_5) + W_0^6 f_0 + W_4^6 f_4 = f_0 + f_4 + Rf_5$.\n\\end{itemize}\nThen if we take $f_0 = u_k$ we will have $f_6 = u^{k+1}$ comes from a two-grid step with \n\\begin{equation}\nu^{k+1} = u^{k} + B(b - A u^k),\n\\end{equation}\nwith $Bg$ is defined by\n\\begin{align}\nw &= PA_c^{-1}P^{T}g, \\\\\nBg &= w + R(g - Aw). \n\\end{align}\n\nIn this point of view, it seems that adopting the shortcut connection in deep learning seems to make sense. And just as we mentioned before, we don't know what real human neural connections, and deep learning with shortcut connection will more general to approximate the human neural network. What's more, a popular CNN model ResNet used this structure and won the ImageNet classification challenge in 2015.\n\n\\section{U-Net and multigrid model in CNN}\nFro traditional CNN model, especially for classification or locallization problem, the general CNN model w.r.t essential dimension like a slash cycle very much, such as AlexNet, VGGNet or ResNet. But for segmentation problem, because of the high dimension of both input and output data, CNN model wasn't very popular for some reasons. Traditional method with image process still is the main methods. But in 2105, [ ] proposed a network to dealt with biology cell image segmentation problem, and win the ISBI challenge for segmentation of neuronal structures in electron microscopic stacks. The U-Net structure of essential dimension likes the V-cycle very much. \n\n\\begin{figure}[!htb]        \n\t\\center{\\includegraphics[width=12cm] {UNetAIMedical1.png}}        \n\t\\caption{Architecture for U-Net}      \n\t\\label{U-Net-model}\n\\end{figure}\n\n\\newpage", "meta": {"hexsha": "8f0edd0745d1cf2c874bed0fb16c98e8995f7d23", "size": 35520, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/AbstractDNN.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/AbstractDNN.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/AbstractDNN.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.2608695652, "max_line_length": 730, "alphanum_fraction": 0.6685810811, "num_tokens": 12985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7861580719694466}}
{"text": "\\section{Rational Homology and Euler Characteristics}\r\n\\subsection{Rational Homology}\r\nWhen we defined the $n$-chains of simplicial homology, we took it as the free abelian group, i.e. free $\\mathbb Z$-module, generated by the $n$-simplices.\r\nBut there is no reason why we should just restrict ourself to $\\mathbb Z$-modules.\r\n\\footnote{Well, you have the universal coefficient theorem.}\r\nIf we replace $\\mathbb Z$ by $\\mathbb Q$, we get a vector space.\r\nAnd the homology theory on this is called the rational homology.\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex.\r\n    Define the $\\mathbb Q$-vector space of rational $n$-chains to be the $\\mathbb Q$-vector space with basis being the set of $n$-simplices of $K$.\r\n    Denote this space by $C_n(K;\\mathbb Q)$.\\\\\r\n    The boundary map $\\partial_n:C_n(K;\\mathbb Q)\\to C_{n-1}(K;\\mathbb Q)$, the cycles $Z_n(K;\\mathbb Q)$, the boundaries $B_n(K;\\mathbb Q)$ and the homology groups $H_n(K;\\mathbb Q)$ are defined exactly as before.\r\n\\end{definition}\r\nCorrespondingly, by viewing abelian groups as $\\mathbb Z$-modules, we can think of the objects $C_n(K),Z_n(K),B_n(K),H_n(K)$ appeared in our original simplicial homology theory instead as $C_n(K;\\mathbb Z),Z_n(K;\\mathbb Z),B_n(K;\\mathbb Z),H_n(K;\\mathbb Z)$.\r\nThis base ring (e.g. $\\mathbb Z$ or $\\mathbb Q$ as we have seen) is called the coefficient of the simplicial homology.\\\\\r\nPerhaps unsurprisingly, homology with coefficient in $\\mathbb Q$ actually contains less information than homology with coefficients in $\\mathbb Z$.\r\n\\begin{lemma}\r\n    If $H_n(K;\\mathbb Z)\\cong\\mathbb Z^b\\oplus F$ where $F$ is a finite abelian group, then $H_n(K;\\mathbb Q)=\\mathbb Q^b$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    There is a natural map $C_n(K;\\mathbb Z)\\to C_n(K;\\mathbb Q)$ via the inclusion of $\\mathbb Z$ in $\\mathbb Q$.\r\n    This induces a chain map $C_\\bullet(K;\\mathbb Z)\\to C_\\bullet(K;\\mathbb Q)$ and hence a natural homomorphism $H_n(K;\\mathbb Z)\\to H_n(K;\\mathbb Q)$.\r\n    If $c\\in Z_n(K;\\mathbb Q)$, then there is an integer $m$ such that $mc\\in Z_n(K;\\mathbb Z)$ has integer coefficients.\r\n    So $mc$ is in the image of the map $Z_n(K;\\mathbb Z)\\to Z_n(K;\\mathbb Q)$.\r\n    Now $H_n(K;\\mathbb Q)\\cong\\mathbb Q^{b'}$ for some natural number $b'$ as it has to be a finite dimensional vector space.\r\n    But the above argument then shows $b'\\le b$.\r\n    Let $[c_1],\\ldots,[c_b]\\in H_n(K;\\mathbb Z)$ generate the $\\mathbb Z^b$ factor in $H_n(K;\\mathbb Z)$.\r\n    Then it makes sense to talk about them as elements of $H_n(K;\\mathbb Q)$ as well.\r\n    Suppose there is $\\lambda_1,\\ldots,\\lambda_b\\in\\mathbb Q$ not all zero such that $\\sum_i\\lambda_i[c_i]=0$ in $H_n(K;\\mathbb Q)$, then there exists $c\\in C_{n+1}(K;\\mathbb Q)$ such that $\\partial_{n+1}c=\\sum_i\\lambda_ic_i$.\r\n    Pick integer $m>0$ such that $m\\lambda_i$ are all integers, then $\\partial_{n+1}(mc)=\\sum_i(m\\lambda_i)c_i$, therefore $\\sum_i(m\\lambda_i)[c_i]=0$ in $H_n(K;\\mathbb Z)$.\r\n    But $[c_i]$ are linearly independent in $H_n(K;\\mathbb Z)$, so $m\\lambda_i=0$ for all $i$, hence $\\lambda_i=0$ and therefore $[c_i]$ are linearly independent in $H_n(K;\\mathbb Q)$.\r\n    This means $b'\\ge b$.\r\n    Combining the two gives $b'=b$.\r\n\\end{proof}\r\nConsequently we cannot distinguish $\\mathbb RP^2$ and a point with rational homology.\r\nThen what is the point of having it?\r\nWell, throwing away information isn't necessarily bad.\r\n\\subsection{Euler Characteristics}\r\n\\begin{definition}\r\n    Let $K$ be a simplicial complex.\r\n    The Euler characteristic of $K$ is\r\n    $$\\chi(K)=\\sum_{n=0}^\\infty(-1)^n\\dim_{\\mathbb Q}H_n(K;\\mathbb Q)$$\r\n    If $X$ is a topological space with $X=|K|$, then we write $\\chi(X)=\\chi(K)$ which is well-defined as the homology groups do not depend on specific triangulation.\r\n\\end{definition}\r\nThere is no issue about the convergence of the series as eventually $H_n=0$ and hence the series terminates.\r\n\\begin{lemma}\\label{euler}\r\n    $$\\chi(K)=\\sum_{n=0}^\\infty(-1)^n\\dim_{\\mathbb Q}C_n(K;\\mathbb Q)=\\sum_{n=0}^\\infty(-1)^n|\\{\\sigma\\in K:\\dim\\sigma=n\\}|$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Write $\\dim=\\dim_\\mathbb Q$.\r\n    Note that we have\r\n    $$\\dim H_n(K;\\mathbb Q)=\\dim Z_n(K;\\mathbb Q)-\\dim B_n(K;\\mathbb Q)$$\r\n    $$\\dim C_n(K;\\mathbb Q)=\\dim\\ker\\partial_n+\\dim\\operatorname{Im}\\partial_n=\\dim B_{n-1}(K;\\mathbb Q)+\\dim Z_n(K;\\mathbb Q)$$\r\n    Thus we can just write\r\n    \\begin{align*}\r\n        \\sum_{n=0}^\\infty(-1)^n\\dim C_n(K;\\mathbb Q)&=\\sum_{n=0}^\\infty (-1)^n\\dim Z_n(K;\\mathbb Q)+\\sum_{n=1}^\\infty (-1)^n\\dim B_{n-1}(K;\\mathbb Q)\\\\\r\n        &=\\sum_{n=0}^\\infty (-1)^n(\\dim Z_n(K;\\mathbb Q)-\\dim B_n(K;\\mathbb Q))\\\\\r\n        &=\\sum_{n=0}^\\infty(-1)^n\\dim_{\\mathbb Q}H_n(K;\\mathbb Q)\r\n    \\end{align*}\r\n    as desired.\r\n\\end{proof}\r\n\\begin{example}\r\n    If $\\dim K=2$, we get the familiar $\\chi(K)=V-E+F$.\r\n    So for example $\\chi(S^2)=1-0+1=2$.\r\n    Consequently any triangulation of the $2$-sphere, i.e. any polyhedron, has $V-E+F=2$.\r\n\\end{example}\r\n\\subsection{The Lefschetz Fixed-Point Theorem}\r\n\\begin{definition}\r\n    Let $X$ be triangulable and $\\phi:X\\to X$.\r\n    The Lefschetz number of $\\phi$ is\r\n    $$L(\\phi)=\\sum_{n=0}^\\infty(-1)^n\\operatorname{tr}(\\phi_\\ast:H_n(X;\\mathbb Q)\\to H_n(X;\\mathbb Q))$$\r\n\\end{definition}\r\nAgain the sum is eventually zero.\r\n\\begin{example}\r\n    $L(\\operatorname{id}_X)=\\chi(X)$.\r\n\\end{example}\r\n\\begin{lemma}\r\n    If $f:K\\to K$ is a simplicial map, then\r\n    $$L(|f|)=\\sum_{n=0}^\\infty (-1)^n\\operatorname{tr}(f_n:C_n(K;\\mathbb Q)\\to C_n(K;\\mathbb Q))$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Given a commutative diagram of vector spaces\r\n    \\[\r\n        \\begin{tikzcd}\r\n            0\\arrow{r}&A\\arrow{d}{\\alpha}\\arrow{r}&B\\arrow{d}{\\beta}\\arrow{r}&C\\arrow{d}{\\gamma}\\arrow{r}&0\\\\\r\n            0\\arrow{r}&A'\\arrow{r}&B'\\arrow{r}&C'\\arrow{r}&0\r\n        \\end{tikzcd}\r\n    \\]\r\n    with exact rows, then it is easy to check that $\\operatorname{tr}\\beta=\\operatorname{tr}\\alpha+\\operatorname{tr}\\gamma$.\r\n    The proof follows almost immediately by using the same idea as we did in Lemma \\ref{euler}.\r\n\\end{proof}\r\n\\begin{theorem}[Lefschetz Fixed-Point Theorem]\r\n    Let $\\phi:X\\to X$ be a map where $X$ is triangulable.\r\n    If $L(f)\\neq 0$, then $\\phi$ has a fixed point.\r\n\\end{theorem}\r\nWe can actually count the fixed point in the full version of the theorem, which is out of the scope of this course.\r\n\\begin{proof}\r\n    We shall show that if $\\phi$ has no fixed point, then $L(\\phi)=0$.\r\n    As $X$ is triangulable, it has to be compact, so there is some $\\delta>0$ such that $\\|x-\\phi(x)\\|>\\delta$ for all $x\\in X$.\r\n    Choose $K$ such that $X=|K|$ and, possibly using barycentric subdivision, $\\operatorname{mesh}K<\\delta/2$.\r\n    Then if $x\\in\\sigma\\in K$, then $\\phi(x)\\notin\\sigma$.\r\n    Let $f:K^{(r)}\\to K$ be a simplicial approximation to $\\phi$.\r\n    If $v\\in K^{(r)}$ is a vertex with $v\\in\\sigma\\in K$, then $\\phi(v)\\in\\operatorname{St}_K(f(v))$, consequently $\\|\\phi(v)-f(v)\\|<\\delta/2$.\r\n    But $\\|\\phi(v)-v\\|>\\delta$, so $\\|v-f(v)\\|>\\delta/2$, so $f(v)\\notin\\sigma$.\r\n    Let $i_\\bullet:C_\\bullet(K;\\mathbb Q)\\to C_\\bullet(K^{(r)};\\mathbb Q)$ be a chain map that induces the canonical isomorphism on homology, which is supposed to map an $n$-simplex in $K$ to the sum of the $n$-simplices in $K^{(r)}$ supported in it.\r\n    Since $f$ takes vertices of $\\sigma$ out of it, it follows that $f_n\\circ i_n(\\sigma)$ is supported on simplices disjoint from $\\sigma$.\\\\\r\n    Since $\\phi_\\ast$ is induced at the level of chains by $f_n\\circ i_n$, we now have\r\n    $$L(\\phi)=\\sum_{n=0}^\\infty(-1)^n\\operatorname{tr}f_n\\circ i_n$$\r\n    by the preceding lemma.\r\n    But $i_n\\circ i_n$ throws any $n$-simplex elsewhere, hence $\\operatorname{tr}f_n\\circ i_n=0$, so $L(\\phi)=0$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $X$ is triangulable and contractible, then any map $\\phi:X\\to X$ has a fixed point.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    We just need to show that it has nonzero Lefschetz number.\r\n    $X\\simeq\\{\\ast\\}$, so essentially $H_n(X;\\mathbb Q)=0$ if $n>0$ and $\\dim H_0(X;\\mathbb Q)=\\mathbb Q$.\r\n    So the only nonzero map $\\phi_\\ast$ is $\\phi_\\ast:H_0(X;\\mathbb Q)\\to H_0(X;\\mathbb Q)$ which is the identity.\r\n    Thus $L(\\phi)=1$.\r\n\\end{proof}", "meta": {"hexsha": "0792832376a97f7f02893492755e5653ed25aec5", "size": 8212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/rational.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": "7/rational.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": "7/rational.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": 68.4333333333, "max_line_length": 259, "alphanum_fraction": 0.6591573307, "num_tokens": 2826, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7860823720042984}}
{"text": "\n\\subsection{Orthogonal groups \\(O(n, 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 orthogonal group}\n\nIf the metic is \\(M=I\\) then the condition is:\n\n\\(P^TP=I\\)\n\n\\(P^T=P^{-1}\\)\n\nThese form the orthogonal group.\n\nWe use \\(O\\) instead of \\(P\\):\n\n\\(O^T=O^{-1}\\)\n\n\\subsubsection{Rotations and reflections}\n\nThe orthogonal group is the rotations and reflections.\n\n\\subsubsection{Parameters of the orthogonal group}\n\nThe orthogonal group depends on the dimension of the vector space, and the underlying field. So we can have:\n\\begin{itemize}\n\\item \\(O(n, R)\\); and\n\\item \\(O(n, C)\\).\n\\end{itemize}\n\n\\subsubsection{We generally refer only to the reals}\n\n\\(O(n)\\) means \\(O(n,R)\\).\n\nThe generally refer to the reals only.\n\n", "meta": {"hexsha": "22c71987f86be375334f8e96ebb0c1f8601800e3", "size": 847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/02-05-O.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-05-O.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-05-O.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.4130434783, "max_line_length": 108, "alphanum_fraction": 0.7024793388, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8558511396138366, "lm_q1q2_score": 0.7860823654716014}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n\\chapter{Derivative Formulæ}\n\\section{General Functions}\nFor any two functions $u$ and $v$:\n\\[ (u + v)' = u' + v' \\]\nWhen there is a constant, $c$:\n\\[ (c \\cdot u)' = c \\cdot u' \\]\n\\section{Trigonometric Functions}\n\\begin{align*}\n    \\frac{d}{dx} \\sin x &= \\cos x\\\\\n    \\frac{d}{dx} \\cos x &= - \\sin x\n\\end{align*}\n\\section{Product Rule}\n\\begin{equation}\n    (u \\cdot v)' = v \\cdot u' + u \\cdot v'\n    \\label{eqn:product-rule}\n\\end{equation}\n\\begin{exmp}\n    To differentiate $f(x) = x^3 \\sin x$, we let \n    $u = x^3$ and $v = \\sin x$:\n    \\begin{align*}\n        \\therefore \\quad u' &= 3x^2\\\\\n                         v' &= \\cos x\n    \\end{align*}\n    From Equation \\ref{eqn:product-rule}, we know:\n    \\begin{align*}\n        f'(x)   &= vu' + uv'\\\\\n                &= 3x^2 \\sin x + x^3 \\cos x\n    \\end{align*}\n\\end{exmp}\n\\section{Quotient Rule}\n\\[ \\left( \\frac{u}{v} \\right)' = \\frac{vu' - uv'}{v^2} \\]\n\\section{Chain Rule}\nThe \\emph{chain rule} (in Leibniz's notation) can be written \nin the following way:\n\\[ \\frac{dy}{dt} = \\frac{dy}{dx} \\cdot \\frac{dx}{dt} \\]\n\\begin{exmp}\n    To differentiate $y = \\sin^{10} t$, we let \n    $x = \\sin t$:\n    \\begin{align*}\n        y &= x^{10}\\\\\n        \\therefore \\quad \\frac{dy}{dx} &= 10x^9\n    \\end{align*}\n    From the chain rule, we get:\n    \\[ \\frac{dy}{dt} = 10x^9 \\cos t \\quad \\because \\quad \\frac{dx}{dt} = \\cos t \\]\n    Finally, we need to substitute $x = \\sin t$:\n    \\[ \\frac{dy}{dt} = 10 \\sin^9 t \\cos t \\]\n\\end{exmp}\n\\begin{exmp}\n    To differentiate $\\sin (10t)$, we let \n    $x = 10t$ and $y = \\sin x$:\n    We now have:\n    \\[ \\frac{dx}{dt} = 10 \\quad , \\quad \\frac{dy}{dx} = \\cos x \\]\n    \\begin{align*}\n        \\frac{d}{dt} \\sin (10t) &= \\frac{dy}{dt}\\\\\n        \\frac{dy}{dt}           &= \\frac{dy}{dx} \\cdot \\frac{dx}{dt}\\\\\n                                &= 10 \\cos x\\\\\n                                &= 10 \\cos (10t)\n    \\end{align*}\n\\end{exmp}\n\\end{document}", "meta": {"hexsha": "1f8c07e82ef319c1c3374f5cc6b2223cc54c9753", "size": 1976, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter3.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/chapter3.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/chapter3.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": 31.3650793651, "max_line_length": 82, "alphanum_fraction": 0.5136639676, "num_tokens": 756, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802395624257, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7860823631192785}}
{"text": "\n\\subsection{Autoregressive Conditional Heteroskedasticity (ARCH)}\n\n\\subsubsection{Variance of the AR(\\(1\\)) model}\n\nThe standard AR(\\(1\\)) model is:\n\n\\(y_t=\\alpha + \\beta y_{t-1}+\\epsilon_t \\)\n\nThe variance is:\n\n\\(Var(y_t)=Var(\\alpha + \\beta y_{t-1}+\\epsilon_t)\\)\n\n\\(Var(y_t)(1-\\beta^2)=Var(\\epsilon_t)\\)\n\nAssuming the errors are IID we have:\n\n\\(Var(y_t))=\\dfrac{\\sigma^2 }{1-\\beta^2 }\\)\n\nThis is independent of historic observations, which may not be desirable.\n\n\\subsubsection{Conditional variance}\n\nConsider the alternative formulation:\n\n\\(y_t=\\epsilon_t f(y_{t-1})\\)\n\nThis allows for conditional heteroskedasticity.\n\n", "meta": {"hexsha": "1e8c751904c361e116b5dde60c10be4e143e96f5", "size": 622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticWold/01-03-ARCH.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochasticWold/01-03-ARCH.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/forecastingUni/02-03-ARCH.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.7333333333, "max_line_length": 73, "alphanum_fraction": 0.7106109325, "num_tokens": 186, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7860143496154322}}
{"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 5}\n\nConsider the following optimization problem.\n\n\\begin{equation}\n\\begin{aligned}\n& \\underset{\\mathbf{x}}{\\text{minimize}} & & x_1^2 + 2x_2^2\\\\\n& \\text{subject to} & & x_1 + x_2 - 1 \\leqslant 0.\\\\\n\\end{aligned}\n\\label{eq51}\n\\end{equation}\n\nFind a point satisfying the Kuhn-Tucker conditions.\nIs that point an optimal solution?\n\n\\subsection*{Solution}\n\nLet $\\mathbf{x}(x_1, x_2)$ be a feasible solution of the optimization problem given in Eq. \\ref{eq51}.\nWe define $f(\\mathbf{x}) = x_1^2 + 2x_2^2$ and $g_1(\\mathbf{x}) = x_1 + x_2 - 1$.\nTo verify Kuhn-Tucker conditions for any feasible solution $\\mathbf{x}$, we first need to show that both functions $f$ and $g_1$ are convex and differentiable at $\\mathbf{x}$.\nUsing the convexity theorem, $f$ is convex on $\\mathbb{R}^2$ if and only if the Hessian matrix $H_f(\\mathbf{x})$ is positive semidefinite for every $x\\in \\mathbb{R}^2$.\nHessian matrices $H_f(\\mathbf{x})$ and $H_{g_1}(\\mathbf{x})$ are computed in Eq. \\ref{eq52} and Eq. \\ref{eq53}, respectively.\n\n\\begin{equation}\nH_f(\\mathbf{x})\n= \\begin{pmatrix}\n\\frac{\\partial^2 f}{\\partial^2 x_1} & \\frac{\\partial^2 f}{\\partial x_1 \\partial x_2}\\\\[0.6em]\n\\frac{\\partial^2 f}{\\partial x_2 \\partial x_1} & \\frac{\\partial^2 f}{\\partial^2 x_2}\\\\\n\\end{pmatrix}\n= \\begin{pmatrix}\n2 & 0\\\\[0.6em]\n0 & 4\\\\\n\\end{pmatrix}\n\\label{eq52}\n\\end{equation}\n\n\\begin{equation}\nH_{g_1}(\\mathbf{x})\n= \\begin{pmatrix}\n\\frac{\\partial^2 g_1}{\\partial^2 x_1} & \\frac{\\partial^2 g_1}{\\partial x_1 \\partial x_2}\\\\[0.6em]\n\\frac{\\partial^2 g_1}{\\partial x_2 \\partial x_1} & \\frac{\\partial^2 g_1}{\\partial^2 x_2}\\\\\n\\end{pmatrix}\n= \\begin{pmatrix}\n0 & 0\\\\[0.6em]\n0 & 0\\\\\n\\end{pmatrix}\n\\label{eq53}\n\\end{equation}\n\nSince $H_f(\\mathbf{x})$ is a diagonal matrix, its eigenvalues are the elements on its principle diagonal.\nAlso, since $H_{g_1}(\\mathbf{x})$ is a zero matrix, it has only one eigenvalue $0$ of multiplicity $2$.\nSince eigenvalues of both matrices are non-negative, both $H_f(\\mathbf{x})$ and $H_{g_1}(\\mathbf{x})$ are positive semi-definite.\nHence, we have shown both $f$ and $g_1$ are convex functions.\n\nTherefore, according to Kuhn-Tucker theorem, any point $\\mathbf{x}$ should satisfy conditions stated in Eq. \\ref{eq54} and Eq. \\ref{eq55} as well as the active constraint presented in Eq. \\ref{eq56} to satisfy the Kuhn-Tucker Sufficient conditions.\n\n\\begin{equation}\n(\\nabla f)_\\mathbf{x} + u_1 (\\nabla g_1)_\\mathbf{x} = \\mathbf{0}\n\\label{eq54}\n\\end{equation}\n\\begin{equation}\nu_1 \\geq 0\n\\label{eq55}\n\\end{equation}\n\\begin{equation}\nu_1 g_1(\\mathbf{x}) = 0\n\\label{eq56}\n\\end{equation}\n\nGiven that $f(\\mathbf{x}) = x_1^2 + 2x_2^2$ and $g_1(\\mathbf{x}) = x_1 + x_2 - 1$, Eq. \\ref{eq54} can be rewritten as shown in Eq. \\ref{eq57}.\n\\begin{equation}\n\\begin{pmatrix} 2x_1 \\\\ 4x_2 \\end{pmatrix} + u_1 \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix} = \\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix}\n\\label{eq57}\n\\end{equation}\nTherefore,\n\\begin{equation}\n\\left\\{ \\begin{array}{ll} 2x_1+u_1 = 0\\\\ 4x_2 + u_1 = 0\\\\ \\end{array}\\right.\n\\label{eq58}\n\\end{equation}\nHence,\n\\begin{equation}\n2(2x_2-x_1) = 0\n\\label{eq59}\n\\end{equation}\nBut at the same time, Eq. \\ref{eq56} requires\n\\begin{equation}\nu_1(x_1 + x_2 - 1) = 0\n\\label{eq60}\n\\end{equation}\nTherefore, either $u_1 = 0$ or $x_1 + x_2 - 1 = 0$.\nIn case, $u_1 \\neq 0$,using Eq. \\ref{eq59} $x_1$ and $x_2$ are obtained as $x_1 = 2/3$ and $x_2 = 1/3$.\nHowever, substituting these values in Eq. \\ref{eq58} would necessarily result in $u_1 \\leq 0$ and this will contradict the Kuhn-Tucker condition in Eq. \\ref{eq55}.\nTherefore, $u_1 = 0$.\nFinally, by substituting $u_1$ in Eq. \\ref{eq55}, the point will be obtained as $\\mathbf{x}(x_1, x_2) = (0, 0)$.\nSince this point adheres to all Kuhn-Tucker conditions, it is an optimal point which minimizes the function $f = x_1^2 + 2x_2^2$ and satisfies $g(x) = -1 \\leq 0$.\n", "meta": {"hexsha": "f54ac27ea3a8678a24a54ace4bf8e11f0ea873a8", "size": 4185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-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-cs671-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-cs671-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": 40.6310679612, "max_line_length": 248, "alphanum_fraction": 0.6712066906, "num_tokens": 1584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267830311354, "lm_q2_score": 0.904650527388829, "lm_q1q2_score": 0.7859846074786563}}
{"text": "\\label{capitulo FCINO}\n\n\\section{Introduction}\n\n% Esta es la definición general de la FFT que habrá que definir en el futuro\n% http://es.mathworks.com/help/symbolic/mupad_ref/ifourier.html\n\nThe continuous Fourier transform (CFT) of a function $f(t)$ and its inverse will be defined here as\n\\begin{equation}\n\\begin{gathered}\nF(p) = \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} f(x)\\,\\, e^{-ipx}\\,dx\n\\\\\nf(x) = \\frac{1}{\\sqrt{2\\pi}}\\int_{-\\infty}^{\\infty} F(p)\\,\\, e^{ipx}\\,dp\n\\end{gathered}\n\\end{equation}\nwhere $i$ is the imaginary unit. The discrete Fourier Transform (DFT) and the inverse DFT of a\nsecuence $\\mathbf{z}=\\{z_1,z_2,\\ldots,z_n\\}$ (which may have real or complex values) will be defined as\n\\begin{equation}\n\\begin{gathered}\nD_k(z) = \\sum_{j=1}^n z_j e^{-2\\pi i(j-1)(k-1)/n}\\qquad\\therefore\\qquad k=1,2,\\ldots,n\n\\\\\nD_k^{-1}(z) = \\frac{1}{n}\\sum_{j=1}^n z_j e^{2\\pi i(j-1)(k-1)/n}\\qquad\\therefore\\qquad k=1,2,\\ldots,n\n\\end{gathered}\n\\end{equation}\nAn Fast Fourier Transform (FFT) computes the DFT and produces exactly the same result as evaluating the DFT definition directly; the most important difference \nis that an FFT is much faster.\n\nLet us assume that $f(x)$ is a zero outside the interval $(-L/2,L/2)$. Let $\\Delta x=L/n$ be the interval in $x$ for the $n$ input values of $f(x)$.\n\nFurther, Fourier transform software routines require a fixed discrete grid spacing.\nThen the sampling interval on grid spacing is $\\Delta x=a/n$, and $\\Delta p =2\\pi/(n\\Delta x)$ on momentum spacing.\n\\begin{equation}\n\\begin{gathered}\nx_j = j\\Delta x, \\qquad f_j = f(x_j) \\qquad\\therefore\\qquad j=-\\frac{n}{2},\\ldots,\\frac{n}{2}\n\\\\[4mm]\np_k = k\\Delta p, \\qquad F_k = F(p_k) \\qquad\\therefore\\qquad k=-\\frac{n}{2},\\ldots,\\frac{n}{2}\n\\end{gathered}\n\\end{equation}\nThen, we can write CFT as follows\n\\begin{equation}\nF_k = \\frac{\\Delta x}{\\sqrt{2\\pi}}\\sum_{j=-n/2}^{n/2} f_j\\,\\, e^{-2\\pi i kj/n}\n\\qquad\\therefore\\qquad\nk=-\\frac{n}{2},\\ldots,\\frac{n}{2}\n\\label{eq: CFT raw}\n\\end{equation}\nHowever most of implementations use positive indices, and therefore the spatial samples inside the sum must be re-arranged.\nAccording with the FFTW library we use the standard order (\\textit{s-order}) vector. This means that the\npositive values are stored in the first half of the vector and the negative frequencies\nare stored in backwards order in the second half of the vector, with the zero-value component\nin the first element. We will represent this format as a \\textit{tilde}, for example: $\\mathbf{z}$\nrepresent the array in \\textit{s-order} and $\\mathbf{\\tilde{z}}$ in \\textit{n-order}.\n\\begin{equation}\n\\text{$s$-order:}\\qquad \\boldsymbol{z} = \\Bigl( z \\Bigr)_{J=1}^n\n\\qquad\\qquad\\qquad\\qquad\\qquad\\qquad\n\\text{$n$-order:}\\qquad \\tilde{\\boldsymbol{z}} = \\Bigl( z \\Bigr)_{j=-n/2}^{n/2}\n\\end{equation}\nwhere both sequences are related throught the following functions,\n\\begin{equation}\n\\tilde{\\boldsymbol{z}} = \\text{fftshift}(\\boldsymbol{z}) \\qquad\\qquad \\boldsymbol{z} = \\text{ifftshift}(\\tilde{\\boldsymbol{z}})\n\\end{equation}\nThe next table represents the structure corresponds in the case where $n$ is an even number\n\\vspace{5mm}\n\\begin{center}\n\\begin{tabular}{c|rrrrrrrr}\n$n$ & \\multicolumn{4}{c|}{$n/2-1$} & \\multicolumn{4}{c}{$n/2+1$}\n\\\\\\hline\n$j$ & $-\\frac{n}{2}+1$ & $-\\frac{n}{2}+2$ & $\\cdots$ & $-1$ &\n$0$ & $\\cdots$ & $\\frac{n}{2}-1$ & $\\frac{n}{2}$\n\\\\\n$J$ & $\\frac{n}{2}+2$ & $\\frac{n}{2}+3$ & $\\ldots$ & $n$ &\n$1$ & $\\ldots$ & $\\frac{n}{2}$ & \n$\\frac{n}{2}+1$\n\\\\\\hline\n\\end{tabular}\n\\\\[5mm]\n\\begin{tabular}{c|rrrrrrrr}\n$n=8$& \\multicolumn{3}{c|}{$3$} & \\multicolumn{5}{c}{$5$}\n\\\\\\hline\n$j$ & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$ & $4$\n\\\\\n$J$ & $6$ & $7$ & $8$ & $1$ & $2$ & $3$ & $4$ & $5$\n\\\\\\hline\n\\end{tabular}\n\\end{center}\nIf $n$ is odd then general structure of the table above still applies, but $n/2+1$ does not appear. \n\\begin{center}\n\\begin{tabular}{c|rrrrrrrr}\n$n$ & \\multicolumn{4}{c|}{$\\lfloor\\frac{n}{2}\\rfloor$} & \\multicolumn{4}{c}{$\\lfloor\\frac{n}{2}\\rfloor+1$}\n\\\\\\hline\n$j$ & $-\\lfloor\\frac{n}{2}\\rfloor$ & $-\\lfloor\\frac{n}{2}\\rfloor+1$ & $\\cdots$ & $-1$ &\n$0$ & $\\cdots$ & $\\lfloor\\frac{n}{2}\\rfloor-1$ & \n$\\lfloor\\frac{n}{2}\\rfloor$\n\\\\\n$J$ & $\\lfloor\\frac{n}{2}\\rfloor+1$ & $\\lfloor\\frac{n}{2}\\rfloor+2$ & $\\ldots$ & $n$ &\n$1$ & $\\ldots$ & $\\lfloor\\frac{n}{2}\\rfloor-1$ & \n$\\lfloor\\frac{n}{2}\\rfloor$\n\\\\\\hline\n\\end{tabular}\n\\\\[5mm]\n\\begin{tabular}{c|rrrrrrr}\n$n=7$& \\multicolumn{3}{c|}{$3$} & \\multicolumn{4}{c}{$4$}\n\\\\\\hline\n$j$ & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$\n\\\\\n$J$ & $5$ & $6$ & $7$ & $1$ & $2$ & $3$ & $4$\n\\\\\\hline\n\\end{tabular}\n\\end{center}\nAfter this transformation Equation (\\ref{eq: CFT raw}) can be reexpressed as follow\n\\begin{equation}\nF_K = \\frac{\\Delta x}{\\sqrt{2\\pi}}\\sum_{J=1}^{n} f_J\\,\\, e^{-2\\pi i (K-1)(J-1)/n}\n\\qquad\\therefore\\qquad\nK=1,2,\\ldots,n\n\\label{eq: CFT end}\n\\end{equation}\nThe reordering of spatial samples means that the frequency samples should be re-arranged as well. \nNow it is clear that we can use the DFT definition to express the FT\n(Denote K the new index in the frequency domain, which leads to the following expression:)\n\\begin{equation}\nF_K = \\frac{\\Delta x}{\\sqrt{2\\pi}}D_K( \\boldsymbol{f} )\n\\qquad\\therefore\\qquad\nK=1,2,\\ldots,n\n\\end{equation}\n\n\n\n\\clearpage\nTo be specific, the abscissas for the input data are,\n\\begin{equation}\nx_j = \\left(j-1-\\frac{n}{2}\\right)\\Delta x \\qquad\\therefore\\qquad j=1,2,\\ldots,n\n\\end{equation}\nThe abscissas for the output data set will be defined as,\n\\begin{equation}\np_k = \\left(k-1-\\frac{n}{2}\\right)\\Delta p \\qquad\\therefore\\qquad k=1,2,\\ldots,n\n\\end{equation}\nwhere $\\Delta p = 2\\pi/a = 2\\pi/n\\Delta x$ which conduce to the incertidumbre principle $\\Delta x \\Delta p = 2\\pi/n$ and the important known as\n``angular Nyquist frequency'' $\\Omega=\\pi/\\Delta x$, which corresponds to the maximum and the negative mimimum value of frequency for the series.\n\n% http://www.mvkonnik.info/2014/06/fft-ifft-and-why-do-we-need-fftshift.html\n% Usually most of implementations uses positive indices, and therefore the spatial samples inside the sum must be rearranged:\n\n\\section{Convention}\n\nTo facilitate our discusion, we first define two general functions $f(x)$ and $F(p)$, which are\nFourier transforms of each other,\n\\begin{equation}\n\\begin{gathered}\n\\psi(x) = \\frac{1}{\\sqrt{2\\pi\\hbar}}\\int_{-\\infty}^{\\infty} \\psi(p)\\,\\, e^{ipx/\\hbar}\\,dp\n\\\\\n\\psi(p) = \\frac{1}{\\sqrt{2\\pi\\hbar}}\\int_{-\\infty}^{\\infty} \\psi(x)\\,\\, e^{-ipx/\\hbar}\\,dx\n\\end{gathered}\n\\end{equation}\nIn general we are going to use atomic units ($\\hbar=1$).\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{|c|c|}\n\\hline\n\\texttt{FFT}($\\mathbf{f}$, $\\tilde{\\mathbf{F}}^\\pm\\rightarrow\\mathbf{f}$, $\\text{sign}=+1$) &\n${\\displaystyle\n\\tilde{F}_\\alpha^\\pm =\n\\frac{1}{\\sqrt{2\\pi}}\\sum_{\\beta=1}^{n} f_\\beta\\,\\exp\\left\\{\\pm 2\\pi i\\,\\,\\frac{(\\alpha-1)(\\beta-1)}{n}\\right\\}, \\qquad \\alpha = 1, 2, \\ldots, n\n}$\n\\\\\\hline\n\\texttt{iFFT}($\\mathbf{\\tilde{F}}$, $\\mathbf{f}^\\pm\\rightarrow\\mathbf{\\tilde{F}}$, $\\text{sign}=-1$) &\n${\\displaystyle\nf_\\beta =\n\\frac{1}{n\\sqrt{2\\pi}}\\sum_{\\alpha=1}^{n} \\tilde{F}_\\alpha^\\pm\\,\\exp\\left\\{\\mp 2\\pi i\\,\\,\\frac{(\\beta-1)(\\alpha-1)}{n}\\right\\}, \\qquad \\beta = 1, 2, \\ldots, n\n}$\n\\\\\\hline\n\\end{tabular}\n\\caption{\\footnotesize{\nasdasd\n}}\n\\label{table: fft transforms}\n\\end{table}\n\n\n% \\translation{\n\\section{Fast Fourier transform (FFT)}\n\nLet $\\mathbf{f}=\\{f_1,f_2,\\ldots,f_n\\}$ and $\\mathbf{F}=\\{F_1,F_2,\\ldots,F_n\\}$ two arrays of complex numbers.\nThe direct Discrete Fourier Transform (dDFT) of the array $\\mathbf{f}$ is defined by the formula\n\\begin{equation}\nF_\\alpha^\\pm = \\sum_{\\beta=1}^{n} f_\\beta\\,\\exp\\left\\{\\pm 2\\pi i\\,\\,\\frac{(\\alpha-1)(\\beta-1)}{n}\\right\\}, \\qquad \\alpha = 1, 2, \\ldots, n\n\\end{equation}\nThe inverse DFT (iDFT) for the array $\\mathbf{F}$ is defined as\n\\begin{equation}\nf_\\beta = \\frac{1}{n}\\sum_{\\alpha=1}^{n} F_\\alpha^\\pm\\,\\exp\\left\\{\\mp 2\\pi i\\,\\,\\frac{(\\beta-1)(\\alpha-1)}{n}\\right\\}, \\qquad \\beta = 1, 2, \\ldots, n\n\\end{equation}\nIt differs from the direct transform by the normalization constant $1/n$.\n\nThe forward DFT (fDFT) corresponds to a sign of $+1$ in the exponent and backward DFT (bDFT) to a sign $-1$. Traditionally\nthe dDFT is associated with the sign $+$ and a the iDFT with the sign $-1$, in such case dDFT is equivalent to fDFT and\niDFT is equivalent to bDFT. However, here we will keep this difference.\n\nAccording with the FFTW library we use the standard order (\\textit{s-order}) output. This means that the\npositive frequencies are stored in the first half of the output and the negative frequencies\nare stored in backwards order in the second half of the output, with the zero-frequency component\nin the first element. We will represent this format as a \\textit{tilde}, for example: $\\mathbf{x}$\nrepresent the array in \\textit{n-order} and $\\mathbf{\\tilde{x}}$ in \\textit{s-order}.\n\nThere are three different ways to use the available methods available in scift\nto calculate the FFT. \n\\begin{equation}\n\\left[\\mathbf{x},\\mathbf{f}\\right]\n\\mathrel{\\substack{ \\xrightarrow{\\text{dFFT}(\\pm)} \\\\ \\xleftarrow{\\text{iFFT}(\\mp)} \\\\ . }}\n\\left[\\boldsymbol{\\tilde{\\omega}},\\mathbf{\\tilde{F}}^\\pm\\right]\n\\mathrel{\\substack{ \\xrightarrow{\\text{shift}} \\\\ \\xleftarrow{\\text{ishift}} \\\\ . }}\n\\left[\\boldsymbol{\\omega},\\mathbf{F}^\\pm\\right]\n\\mathrel{\\substack{ \\xrightarrow{\\text{dFFT}(\\pm)} \\\\ \\xleftarrow{\\text{iFFT}(\\mp)} \\\\ . }}\n\\left[\\boldsymbol{\\tilde{x}},\\mathbf{\\tilde{f}}^\\pm\\right]\n\\mathrel{\\substack{ \\xrightarrow{\\text{shift}} \\\\ \\xleftarrow{\\text{ishift}} \\\\ . }}\n\\left[\\boldsymbol{x},\\mathbf{f}^\\pm\\right]\n\\end{equation}\n\n\\begin{equation}\n\\left[\\mathbf{x},\\mathbf{f}\\right]\n\\longrightarrow\n\\left[\\boldsymbol{\\tilde{\\omega}},\\mathbf{\\tilde{F}}\\right]\n\\longrightarrow\n\\left[\\boldsymbol{\\omega},\\mathbf{F}\\right]\n\\end{equation}\nWhen $n$ is even the location $n/2$ contains the most positive and negative frequencies\n$\\pm \\frac{n/2}{nh}$ $\\left( = \\pm \\frac{1}{2h} \\right)$ which are equivalent.\nThis frequency is called Nyquist frequency. This is the highest frequency component that\nshould exist in the input series for the DFT to yield \"uncorrupted\" results. More\nspecifically if there are no frequencies above Nyquist the original signal can be exactly\nreconstructed from the samples. \n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\multicolumn{5}{c|}{$n/2+1$} & \\multicolumn{4}{c}{$n/2-1$} \\\\\n\\hline\n$\\tilde{\\omega}_1$ & $\\tilde{\\omega}_2$ & $\\tilde{\\omega}_3$ & $\\ldots$ & $\\tilde{\\omega}_{n/2+1}$ & $\\tilde{\\omega}_{n/2-1}$ & $\\ldots$ & \n$\\tilde{\\omega}_{n-1}$ & $\\tilde{\\omega}_n$ \\\\\n\\hline\\hline\n$0$ & $\\frac{1}{nh}$ & $\\frac{2}{nh}$ & $\\ldots$ & $\\frac{n/2}{nh}$ & -$\\frac{n/2-1}{nh}$ & $\\ldots$ & $-\\frac{2}{nh}$ & $-\\frac{1}{nh}$ \\\\\n\\hline\n\\end{tabular}\n\\\\[6mm]\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\multicolumn{4}{c|}{$n/2-1$} & \\multicolumn{5}{c}{$n/2+1$} \\\\\n\\hline\n$\\omega_1$ & $\\ldots$ & $\\omega_{n/2}$ & $\\omega_{n/2+1}$ & $\\omega_{n/2}$ & $\\omega_{n/2+1}$ & $\\omega_{n/2+2}$ & $\\ldots$ & $\\omega_n$ \\\\\n\\hline\\hline\n$\\tilde{\\omega}_{n/2+1}$ & $\\ldots$ & $\\tilde{\\omega}_{n-1}$ & $\\tilde{\\omega}_{n}$ & $\\tilde{\\omega}_{1}$ & $\\tilde{\\omega}_{2}$ & $\\tilde{\\omega}_3$ & \n$\\ldots$ & $\\tilde{\\omega}_{n/2}$ \\\\\n\\hline\n-$\\frac{n/2-1}{nh}$ & $\\ldots$ & $-\\frac{2}{nh}$ & $-\\frac{1}{nh}$ & $0$ & $\\frac{1}{nh}$ & $\\frac{2}{nh}$ & $\\ldots$ & $\\frac{n/2}{nh}$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\vspace{5mm}\nIf $n$ is odd then general structure of the table above still applies, but $n/2+1$ does not appear. \n\\begin{center}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\multicolumn{5}{c|}{$n/2$} & \\multicolumn{4}{c}{$n/2-1$} \\\\\n\\hline\n$\\tilde{\\omega}_1$ & $\\tilde{\\omega}_2$ & $\\tilde{\\omega}_3$ & $\\ldots$ & $\\tilde{\\omega}_{n/2}$ & $\\tilde{\\omega}_{n/2+1}$ & $\\ldots$ & $\\tilde{\\omega}_{n-1}$ \n& $\\tilde{\\omega}_n$ \\\\\n\\hline\\hline\n$0$ & $\\frac{1}{nh}$ & $\\frac{2}{nh}$ & $\\ldots$ & $\\frac{n/2-1}{nh}$ & -$\\frac{n/2-1}{nh}$ & $\\ldots$ & $-\\frac{2}{nh}$ & $-\\frac{1}{nh}$ \\\\\n\\hline\n\\end{tabular}\n\\\\[6mm]\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|}\n\\multicolumn{4}{c|}{$n/2-1$} & \\multicolumn{5}{c}{$n/2$} \\\\\n\\hline\n$\\omega_1$ & $\\ldots$ & $\\omega_{n/2}$ & $\\omega_{n/2+1}$ & $\\omega_{n/2}$ & $\\omega_{n/2+1}$ & $\\omega_{n/2+2}$ & $\\ldots$ & $\\omega_n$ \\\\\n\\hline\\hline\n$\\tilde{\\omega}_{n/2+1}$ & $\\ldots$ & $\\tilde{\\omega}_{n-1}$ & $\\tilde{\\omega}_{n}$ & $\\tilde{\\omega}_{1}$ & $\\tilde{\\omega}_{2}$ & $\\tilde{\\omega}_3$ & \n$\\ldots$ & $\\tilde{\\omega}_{n/2}$ \\\\\n\\hline\n-$\\frac{n/2-1}{nh}$ & $\\ldots$ & $-\\frac{2}{nh}$ & $-\\frac{1}{nh}$ & $0$ & $\\frac{1}{nh}$ & $\\frac{2}{nh}$ & $\\ldots$ & $\\frac{n/2-1}{nh}$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\vspace{5mm}\n\n% Given a window length n and a sample spacing d:\n% \t!! @returns:\tf : ndarray. Array of length n containing the sample frequencies.\n% \t!! f = [0, 1, ...,   n/2-1,     -n/2, ..., -1] / (d*n)   if n is even\n% \t!! f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)   if n is odd\n\n\\subsection{Directly (High level interface)}\nBy using this option, scift internally make the shift and normalization for the $x$ coordinate.\n\n\\begin{equation}\n\\Bigl[x,f(x)\\Bigr]\n\\stackrel{\\text{5}}{\\longrightarrow}\n\\Bigl[\\omega,\\hat{f}(\\omega)\\Bigr]\n\\end{equation}\n\n\\begin{equation}\n\\Bigl[\\omega,\\hat{f}(\\omega)\\Bigr]\n\\stackrel{\\text{8}}{\\longrightarrow}\n\\Bigl[x,f(x)\\Bigr]\n\\end{equation}\n\n\\lstset{language=Fortran}\n\\begin{lstlisting}\ncall xGrid.init( -3.0_8*Math_PI, 3.0_8*Math_PI, 1000 )\ncall funcA.init( xGrid, funcTestWithNoise )\ncall funcA.save(\"func\")  \n  \nfuncA = FFT_fft( funcA )  \ncall funcA.save(\"Ffunc\")  \n  \nfuncA = FFT_ifft( funcA )  \ncall funcA.save(\"iFFfunc\")  \n\\end{lstlisting}\n\nThis is the result\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.36]{images/FFT-func.eps}\n\\includegraphics[scale=0.36]{images/FFT-Ffunc.eps}\n\\caption{\\footnotesize{\nGeometria para s=3\n}}\n% \\label{}\n\\end{figure}\n\n\\subsection{By using plans (Low level interface)}\nIn this case is neccesary to keep in mind the reorganization on the frequency axis and the normalization\nof the Fourier transform\n\n\\begin{equation}\n\\Bigl[x,f(x)\\Bigr]\n\\stackrel{\\text{8}}{\\longrightarrow}\n\\Bigl[x,\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\stackrel{\\text{9}}{\\longrightarrow}\n\\Bigl[\\tilde{\\omega},\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\stackrel{\\text{10}}{\\longrightarrow}\n\\Bigl[\\omega,\\hat{f}(\\omega)\\Bigr]\n\\end{equation}\n\n\\begin{equation}\n\\Bigl[\\omega,\\hat{f}(\\omega)\\Bigr]\n\\stackrel{\\text{13}}{\\longrightarrow}\n\\Bigl[\\tilde{\\omega},\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\stackrel{\\text{14}}{\\longrightarrow}\n\\Bigl[\\tilde{\\omega},F(x)\\Bigr]\n\\stackrel{\\text{15}}{\\longrightarrow}\n\\Bigl[x,F(x)\\Bigr]\n\\stackrel{\\text{16}}{\\longrightarrow}\n\\Bigl[x,f(x)\\Bigr]\n\\end{equation}\n\n\\lstset{language=Fortran}\n\\begin{lstlisting}\ncall xGrid.init( -3.0_8*Math_PI, 3.0_8*Math_PI, 1000 )\ncall funcA.init( xGrid, funcTestWithNoise )\ncall funcA.save(\"func\")\n \t\t\nplanF = FFT_plan( funcA, FFT_FORWARD )\nplanB = FFT_plan( funcA, FFT_BACKWARD )\n \t\t\ncall FFT_execute( planF )\nfuncA.xGrid = FFT_omegaGrid( funcA.xGrid )\ncall FFT_shift( funcA )\ncall funcA.save(\"Ffunc\")\n\ncall FFT_ishift( funcA )\ncall FFT_execute( planB )\nfuncA.xGrid = FFT_xGrid( funcA.xGrid )\nfuncA = funcA/real( funcA.nPoints(), 8 )\ncall funcA.save(\"iFFfunc\")\n\ncall FFT_destroyPlan( planF )\n\\end{lstlisting}\n\n\\subsection{By using the oriented object interface}\nThe function \n\\begin{equation}\n\\begin{aligned}\n&\n\\xlongleftrightarrow{\\text{sync=F}\\qquad\\quad}\n\\quad\\Bigl[x,\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\\\\n\\Bigl[x,f(x)\\Bigr]\\quad\n&\n\\xlongleftrightarrow{\\text{sync=T}\\qquad\\quad}\n\\quad\\Bigl[\\tilde{\\omega},\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\\\\n&\n\\xlongleftrightarrow{\\text{sync=T,shift=T}}\n\\quad\\Bigl[\\omega,\\hat{f}(\\omega)\\Bigr]\n\\end{aligned}\n\\end{equation}\n\n\\lstset{language=Fortran}\n\\begin{lstlisting}\ncall xGrid.init( -3.0_8*Math_PI, 3.0_8*Math_PI, 1000 )\ncall funcA.init( xGrid, funcTestWithNoise )\ncall funcA.save(\"func\")  \n  \ncall fft.init( funcA, FFT_SPATIAL_DOMAIN )\n\ncall fft.execute( FFT_FORWARD, sync=.true., shift=.true. )\ncall funcA.save(\"Ffunc\")\n\ncall fft.execute( FFT_BACKWARD, sync=.true., shift=.true. )\ncall funcA.save(\"iFFfunc\")\n\\end{lstlisting}\n\n\\subsection{Calculating the derivative of second order of a signal}\nThe function \n\\begin{equation}\n\\frac{d^n}{dx^n}f(x) = (i\\omega)^n\\hat{f}(\\omega)\n\\end{equation}\n\n\\begin{equation}\n\\Bigl[x,f(x)\\Bigr]\n\\stackrel{\\text{7}}{\\longrightarrow}\n\\Bigl[x,\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\xlongrightarrow{\\text{9}}\n\\Bigl[x,(i\\tilde{\\omega})^2\\hat{f}(\\tilde{\\omega})\\Bigr]\n\\stackrel{\\text{11}}{\\longrightarrow}\n\\Bigl[x,\\frac{d^2}{dx^2}f(x)\\Bigr]\n\\end{equation}\n\n\\lstset{language=Fortran}\n\\begin{lstlisting}\ncall xGrid.init( -3.0_8*Math_PI, 3.0_8*Math_PI, 1000 )\ncall funcA.init( xGrid, funcTest )\ncall funcA.save(\"func\")\n\ncall fft.init( funcA, FFT_SPATIAL_DOMAIN )\n\ncall fft.execute( FFT_FORWARD )\n\nfuncA.yArray = ( Math_I*fft.omega )**2*funcA.yArray\n\ncall fft.execute( FFT_BACKWARD )\n\ncall funcA.save(\"dfunc\")\n\ncall funcB.init( xGrid, d2funcTest )\ncall funcB.save(\"exact\")\n\\end{lstlisting}\n\nThis is the result\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[scale=0.36]{images/FFT-func2.eps}\n\\includegraphics[scale=0.36]{images/FFT-dfunc.eps}\n\\caption{\\footnotesize{\nLeft panel: Original function. Right panel: Derivative of second order of the signal calculated by using\nthe FFT interface, the exact solution is also included.\n}}\n% \\label{}\n\\end{figure}\n", "meta": {"hexsha": "2c4e2fa9dd2c808c33f509c0d29712451aab1058", "size": 17279, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/userManual/FFT.tex", "max_stars_repo_name": "nfaguirrec/scift", "max_stars_repo_head_hexsha": "2a38018bd495ad42e57a674f525041c4a854dccd", "max_stars_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-05-28T02:04:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-28T02:04:45.000Z", "max_issues_repo_path": "doc/userManual/FFT.tex", "max_issues_repo_name": "bbw7561135/scift", "max_issues_repo_head_hexsha": "0e81e7d29889970d35cc563cc45e9a87fd1cf06d", "max_issues_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-10-14T21:21:21.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-15T04:37:58.000Z", "max_forks_repo_path": "doc/userManual/FFT.tex", "max_forks_repo_name": "bbw7561135/scift", "max_forks_repo_head_hexsha": "0e81e7d29889970d35cc563cc45e9a87fd1cf06d", "max_forks_repo_licenses": ["BSD-3-Clause-Open-MPI", "BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-30T04:43:43.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-30T04:43:43.000Z", "avg_line_length": 37.8925438596, "max_line_length": 160, "alphanum_fraction": 0.6621332253, "num_tokens": 6555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7859015331353215}}
{"text": "\\subsection{Euler Characteristic}\r\n\\begin{definition}\r\n    Let $S$ be a compact Riemann surface.\r\n    A topological triangle in $S$ is a continuous embedding $\\Delta\\hookrightarrow S$ where $\\Delta$ is a closed (non-degenerate) triangle in the plane $\\mathbb R^2$.\r\n    A triangulation of $S$ is a finite collection of topological triangles $\\{\\Delta_i\\}$ on $S$ such that:\\\\\r\n    1. $\\bigcup_i\\Delta_i=S$.\\\\\r\n    2. If $i\\neq j$ then $\\Delta_i\\cap\\Delta_j$ is either empty, a common vertex, or a common edge.\\\\\r\n    3. Each edge is contained in exactly two triangles.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The Euler characteristic of a triangulation of $S$ is $\\chi=V-E+F$, where $V$ is the number of vertices, $E$ is the number of edges and $F$ is the number of triangles.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    1. Every compact Riemann surface $S$ has a triangulation.\\\\\r\n    2. $\\chi$ does not depend on the triangulation we choose.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\n\\begin{definition}\r\n    The Euler characteristic $\\chi(S)$ of $S$ is the Euler characteristic of any of its triangulations.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\chi(\\mathbb C_\\infty)=4-6+4=2$ by identifying it with a regular tetrahedron.\r\n    $\\chi(\\mathbb C/\\Lambda)=0$ by attempting to triangulate its representation as a quotient space of $[0,1]^2$.\r\n\\end{example}\r\nTurns out, every compact Riemann surface is homeomorphic to an $g$-torus $\\Sigma_g$ for some $g$.\r\nMoreover, $\\chi(\\Sigma_g)=2-2g$.\r\nTherefore $\\chi(S)$ determines a compact Riemann surface $S$ up to homeomorphism.", "meta": {"hexsha": "1b6144de66cff285f3f9225aa4d803d20a8ff7d0", "size": 1585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "11/euler.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/euler.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/euler.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": 54.6551724138, "max_line_length": 172, "alphanum_fraction": 0.7015772871, "num_tokens": 461, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846386, "lm_q2_score": 0.8991213813246444, "lm_q1q2_score": 0.7859015281165377}}
{"text": "%!TEX root = TDT4265-Summary.tex\r\n\\section{Morphological image processing}\r\nMorphology is image manipulation via set theory. It's pretty cool. Sort of like spatial filtering, but with nonlinear operations.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Preliminaries}\r\nIn morphology, images are represented as sets. Usually images are binary, and the set of an image is the set of 1-valued pixels, defined on $\\mathbb{Z}^2$. An extension in $\\mathbb{Z}^3$ to greyscale exists, and also to color and so on.\r\n\r\n\\subsubsection{Some set theory}\r\n\\begin{itemize}\r\n    \\item The absolute complement of a set $A$ is\r\n    \\begin{equation}\r\n        A^c = \\{ w | w \\notin A \\},\r\n    \\end{equation}\r\n    which is all elements outside of $A$.\r\n    \\item The relative complement between two sets $A$ and $B$ is\r\n    \\begin{equation}\r\n        A \\setminus B = \\{ w | w \\in A, w \\notin B \\},\r\n    \\end{equation}\r\n    which is all elements that are \\emph{only} in $A$.\r\n    \\item The reflection (180 degree rotation) of a set is\r\n    \\begin{equation}\r\n        \\hat{B} = \\{ w | w = -b \\mbox{ for } b \\in B \\}.\r\n    \\end{equation}\r\n    \\item The translation of a set $A$ by a vector $z = (z_1, z_2)$ is\r\n    \\begin{equation}\r\n        (B)_z = \\{ c | c = b + z \\mbox{ for } b \\in B \\}\r\n    \\end{equation}\r\n\\end{itemize}\r\n\r\n\\subsubsection{Structuring elements (SEs)}\r\nAn SE is a small subimage or subset that is used to find properties of the image. They are usually symmetric and with their center defined in the middle.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Erosion and dilation}\r\n\r\n\\subsubsection{Erosion}\r\nThe erosion of $A$ by $B$ is defined as\r\n\\begin{equation}\r\n    A \\erode B = \\left\\{ z | (B)_z \\subseteq A \\right\\},\r\n\\end{equation}\r\nwhich is the set of all points where $B$ is completely inside $A$. ($A$ is an image and $B$ is an SE.) The operation shrinks objects, and removes anything smaller/thinner than the SE, such as thin lines.\r\n\r\n\\subsubsection{Dilation}\r\nThe dilation of $A$ by $B$ is defined as\r\n\\begin{equation}\r\n    A \\dilate B = \\left\\{ z | (\\hat{B})_z \\cap A \\neq \\emptyset \\right\\}\r\n\\end{equation}\r\nwhich is the set of all points where $\\hat{B}$ (the reflection of $B$) overlaps with $A$ by at least one element. This operation grows objects, and can fill gaps and small holes.\r\n\r\n\\subsubsection{Duality}\r\nErosion and dilation are dual operations:\r\n\\begin{equation}\r\n\\begin{split}\r\n    (A \\erode  B)^c &= A^c \\dilate \\hat{B} \\\\\r\n    (A \\dilate B)^c &= A^c \\erode  \\hat{B} \\\\\r\n\\end{split}\r\n\\end{equation}\r\nThis is useful for symmetric SEs ($\\hat{B} = B$), because then we can erode $A$ by instead dilating the background $A^c$.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Opening and closing}\\label{ssec:open-close}\r\n\\emph{Opening} is defined as\r\n\\begin{subequations}\r\n\\begin{align}\r\n    A \\open B &= (A \\erode B) \\dilate B \\\\\r\n              &= \\bigcup \\left\\{ (B)_z | (B)_z \\subseteq A \\right\\} \\label{eq:opening-as-set}\r\n\\end{align}\r\n\\end{subequations}\r\nIt is analogous to the area defined by moving a ball (or other shape) along the inner boundary of a set, as in Figure \\ref{fig:openclose}. Equation \\eqref{eq:opening-as-set} shows that opening can be expressed as ``all translates of $B$ that fit inside $A$''. Used for e.g. removing thin connections between components and removing noise pixels.\r\n\r\n\\emph{Closing} is defined as\r\n\\begin{equation}\r\n    A \\close B = (A \\dilate B) \\erode B,\r\n\\end{equation}\r\nwhich is analogous to the area defined by moving e.g. a ball along the outer boundary of a set, as in Figure \\ref{fig:openclose}. Used for e.g. filling holes.\r\n\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    \\subfigure[Opening]{\\includegraphics[width=.9\\linewidth]{images/opening.png}} \\\\\r\n    \\subfigure[Closing]{\\includegraphics[width=.9\\linewidth]{images/closing.png}}\r\n    \\caption{Analogies to the opening and closing operations}\r\n    \\label{fig:openclose}\r\n\\end{figure}\r\n\r\nNote that both opening and closing are idempotent operations.\r\n\r\n\\paragraph{Combining opening and closing}\r\nOpening followed by closing can remove noise, both specks of object pixels on the background and background pixels where there should be object. However, some connectivity may be lost.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{The hit-or-miss transformation}\r\nA basic tool for shape detection. Let $B = (B_1, B_2)$, $B_1$ be an object, and $B_2$ its background. Then the matches of $B$ in $A$ is\r\n\\begin{equation}\r\n    A \\match B = (A \\erode B_1) \\cap (A^c \\erode B_2).\r\n\\end{equation}\r\nThe set $(A \\erode B_1)$ are all locations where the object fits in, and $(A^c \\erode B_2)$ are all locations where the background fits. Locations where both fit are locations of all shapes in $A$ that perfectly match $B$. We assume that each object we want to find is separate from the other objects, and therefore each has a complete local background at least one pixel wide.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Some basic morphological algorithms}\r\nNow we can finally use this stuff.\r\n\r\n\\subsubsection{Boundary extraction}\r\nGet the boundary by subracting the eroded image from the original.\r\n\\begin{equation}\r\n    \\beta(A) = A - (A \\erode B)\r\n\\end{equation}\r\nThe erosion gives a ``smaller'' version of $A$, and subtracting that from the image leaves only the border.\r\n\r\n\\subsubsection{Hole filling}\r\nSame principle as in Section \\ref{sec:extract-connected} below.\r\n\\begin{equation}\r\n    X_k = (X_{k-1} \\dilate B) \\cap A^c\r\n\\end{equation}\r\nThe seed pixel must be in a hole. It will grow until it fills the hole. Stop when no further change happens.\r\n\r\n\\subsubsection{Extraction of connected components}\\label{sec:extract-connected}\r\nDone by iteration:\r\n\\begin{equation}\r\n    X_k = (X_{k-1} \\dilate B) \\cap A\r\n\\end{equation}\r\nChoose a starting pixel (seed) $X_0$. Dilate $X_0$, but only keep the pixels that are in the original. Continue dilating and only keeping pixels present in $A$ until convergence.\r\n\r\n\\subsubsection{Convex hull}\\label{sec:convex-hull}\r\nA set is convex if any line segment between two points in the set lies fully within the set. The \\emph{convex hull} $H$ of a set $S$ is the smallest convex set containing $S$. The difference $H - S$ is the \\emph{convex decifiency} of $S$. It can be computed by iterating\r\n\\begin{equation}\r\n    X_k^i = (X_{k-1} \\match B^i) \\cup A\r\n    ,\\quad i = 1,2,3,4\r\n    ,\\quad k = 1,2,\\dots\r\n\\end{equation}\r\nwith $X_0^i = A$ and $B^i$ being as shown in Figure \\ref{fig:convex-hull-SE}. For each SE, let $D^i = X_k^i$ when its iteration converges. Then the convex hull is\r\n\\begin{equation}\r\n    C(A) = \\bigcup_{i=4}^{4} D^i\r\n\\end{equation}\r\n\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    \\includegraphics[width=.5\\linewidth]{images/SE-for-convex-hull.png}\r\n    \\caption{SEs for convex hull extraction}\r\n    \\label{fig:convex-hull-SE}\r\n\\end{figure}\r\n\r\n\\subsubsection{Thinning}\\label{sec:thinning}\r\nUsed e.g. for skeletonization and to thin edge detector output. It is defined in terms of the hit-or-miss transformation as\r\n\\begin{equation}\r\n    A \\thin B = A \\cap (A \\match B)^c\r\n\\end{equation}\r\nwith a sequence of SEs\r\n\\begin{equation}\r\n    \\{ B \\} = \\{ B^1, \\dots, B^n \\}\r\n\\end{equation}\r\nwhere $B^i$ is a rotated $B^{i-1}$. Then just keep applying hit-or-miss with $B$ repeatedly, until continuing has no effect.\r\n\r\nOne pass of thinning is written as\r\n\\begin{equation}\r\n    A \\thin \\{ B \\} = ((\\dots ((A \\thin B^1) \\thin B^2) \\dots ) \\thin B^n)\r\n\\end{equation}\r\n\r\n\\subsubsection{Thickening}\r\nThickening is the dual of thinning:\r\n\\begin{equation}\r\n    A \\thick B = A \\cup (A \\match B)\r\n\\end{equation}\r\n\r\n\\subsubsection{Skeletons}\r\nThe skeleton is\r\n\\begin{equation}\r\n    S(A) = \\bigcup_{k=0}^{K} (A \\erode kB) - (A \\erode kB) \\open B\r\n\\end{equation}\r\nwhere $B$ is an SE and $(A \\erode kB)$ indicates $k$ successive erosions of $A$. $K$ is the number of erosions possible before resulting in the empty set.\r\n\r\n\\subsubsection{Pruning}\r\nSkeletons often have unwanted ``spurs''. Assuming the spurs are sufficiently small, pruning can remove them. We perform thinning with SEs designed to only detect end points.\r\n\\begin{equation}\r\n    X_1 = A \\thin \\{B\\}\r\n\\end{equation}\r\nThe SEs used are shown in Figure \\ref{fig:se-for-pruning}.\r\n\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    \\includegraphics[width=0.5\\linewidth]{images/SE-for-pruning.PNG}\r\n    \\caption{SEs for pruning}\r\n    \\label{fig:se-for-pruning}\r\n\\end{figure}\r\n\r\n\\subsubsection{Morphological reconstruction}\r\nUses two images, a marker $F$ with starting points, and a mask $G$ that constrains the transformation.\r\n\r\n\\paragraph{Geodesic dilation}\r\nGeodesic dilation is the intersection of the mask and the dilated marker. One pass is\r\n\\begin{equation}\\label{eq:geo-dilation}\r\n    D_G^{(1)}(F) = (F \\dilate B) \\cap G.\r\n\\end{equation}\r\nSeveral passes, denoted $D_G^{(n)}$, is just repeating the operation $n$ times.\r\n\r\n\\paragraph{Geodesic erosion}\r\nGeodesic erosion is the union of the mask and the eroded marker. One pass is\r\n\\begin{equation}\\label{eq:geo-erosion}\r\n    E_G^{(1)}(F) = (F \\erode B) \\cup G.\r\n\\end{equation}\r\n\r\n\\paragraph{Morphological reconstruction by dilation}\r\nReconstruction by dilation is just repeating \\eqref{eq:geo-dilation} until more passes have to effect:\r\n\\begin{equation}\r\n    R_G^D(F) = D_G^{(k)}(F)\r\n\\end{equation}\r\n\r\n\\paragraph{Morphological reconstruction by erosion}\r\nSame as by dilation, but using erosion:\r\n\\begin{equation}\r\n    R_G^E(F) = E_G^{(k)}(F)\r\n\\end{equation}\r\n\r\n\\paragraph{Opening by reconstruction}\r\nWith normal opening (Section \\ref{ssec:open-close}), erosion removes small things and dilation restores the original size/shape. Opening by reconstruction restores the precise original shape, and is done as reconstruction by dilation of $F$, from the erosion of size $n$ of $F$:\r\n\\begin{equation}\r\n    O_R^{(n)}(F) = R_F^D \\left[ (F \\erode nB) \\right]\r\n\\end{equation}\r\nwhere $(F \\erode nb)$ indicates $n$ erosions.\r\n\r\nThe SE for erosion $B$ determines the shapes we want to identify. The erosion itself leaves us with markers for all matching objects (because they are not removed by the erosion). Then, the image $F$ is used as a mask, and reconstruction is done by dilating the markers, subject to the mask. That way, all objects marked will be completely filled, and the result is removing all unmarked objects.\r\n\r\n\\paragraph{Filling holes}\r\nWith morphological reconstruction we can fill holes automatically, without knowing where they are. Create a marker image $F$ of zeros, except for the border, where it is $1 - I$. Then\r\n\\begin{equation}\r\n    H = \\left[ R_{I^c}^D(F) \\right]^c\r\n\\end{equation}\r\nis $I$ with all holes filled.\r\n\r\n\\paragraph{Border clearing}\r\nMorphological reconstruction can also be used to remove objects connected to the borders of an image. Create a marker image $F$ that is equal to the input image $I$ at the border, and 0 elsewhere. We can extract all border-touching objects by the morphological reconstruction $R_I^D(F)$, and subtract it from the original to get an image without border objects $X$:\r\n\\begin{equation}\r\n    X = I - R_I^D(F)\r\n\\end{equation}\r\n\r\n\\subsubsection{Summary}\r\nWe have now defined the following morphological operations:\r\n\\begin{itemize}\r\n    \\item Basic set operations:\r\n    \\begin{itemize}\r\n        \\item Translation\r\n        \\item Reflection\r\n        \\item Complement\r\n        \\item Difference\r\n    \\end{itemize}\r\n    \\item Basic morphological operations:\r\n    \\begin{itemize}\r\n        \\item Erosion\r\n        \\item Dilation\r\n        \\item Opening\r\n        \\item Closing\r\n    \\end{itemize}\r\n    \\item Complex morphological operations:\r\n    \\begin{itemize}\r\n        \\item Hit-or-miss transform\r\n        \\item Boundary extraction\r\n        \\item Hole filling\r\n        \\item Connected components\r\n        \\item Convex hull\r\n        \\item Thinning\r\n        \\item Thickening\r\n        \\item Skeletons\r\n        \\item Pruning\r\n    \\end{itemize}\r\n    \\item Morphological reconstruction operations:\r\n    \\begin{itemize}\r\n        \\item Geodesic dilation\r\n        \\item Geodesic erosion\r\n        \\item Morphological reconstruction by dilation\r\n        \\item Morphological reconstruction by erosion\r\n        \\item Opening by reconstruction\r\n        \\item Closing by reconstruction\r\n        \\item Hole filling\r\n        \\item Border clearing\r\n    \\end{itemize}\r\n\\end{itemize}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\subsection{Grey-scale morphology}\r\nWe can dilate, erode, open, and close grey-scale images too! Now we use images $f(x,y)$ and SEs $b(x,y)$. The SEs can now be either flat (uniform) or nonflat. We stick to flat SEs for simplicity.\r\n\r\n\\subsubsection{Erosion and dilation}\r\nErosion of $f$ by a flat SE $b$ is the minimum value of the image in the region covered by the SE:\r\n\\begin{equation}\r\n    \\left[ f \\erode b \\right](x,y) = \\min_{(s,t) \\in b} \\left\\{ f(x+s, y+t) \\right\\}.\r\n\\end{equation}\r\nDilation is similarly\r\n\\begin{equation}\r\n    \\left[ f \\dilate b \\right](x,y) = \\max_{(s,t) \\in b}  \\left\\{ f(x-s, y-t) \\right\\},\r\n\\end{equation}\r\nwhich uses  $\\hat{b} = b(-x,-y)$.\r\n\r\n\\subsubsection{Opening and closing}\\label{sssec:greyscale-open-close}\r\nThis is mathematically just as before:\r\n\\begin{subequations}\r\n\\begin{align}\r\n    f \\open b = (f \\erode b) \\dilate b \\\\\r\n    f \\close b = (f \\dilate b) \\erode b\r\n\\end{align}\r\n\\end{subequations}\r\n\r\nLooking at the image as a topographic surface, opening is pushing the SE up from below, clipping all peaks where it doesn't fit, and closing is pushing the SE down from above, clipping all valleys where it doesn't fit. See Figure \\ref{fig:greyscale-opening-closing}. This means that opening removes small, bright details, and closing removes small, dark details.\r\n\r\n\\begin{figure}[htbp]\r\n    \\centering\r\n    \\includegraphics[width=0.8\\linewidth]{images/greyscale-opening-closing}\r\n    \\caption{Analogy to opening and closing greyscale images}\r\n    \\label{fig:greyscale-opening-closing}\r\n\\end{figure}\r\n\r\n\\subsubsection{Some basic greyscale morphological algorithms}\r\n\r\n\\paragraph{Smoothing}\r\nThe ``small bright/dark details'' mentioned in Section \\ref{sssec:greyscale-open-close} might be noise. This means we can remove this type of noise by opening and then closing. The size of the SE then sets a threshold for what is image and what is noise.\r\n\r\n\\paragraph{Morphological gradient}\r\nThe morphological gradient is\r\n\\begin{equation}\r\n    g = (f \\dilate b) - (f \\erode b).\r\n\\end{equation}\r\nThe dilation thickens objects in the image, and the erosion shrinks them. Differencing these emphasises edges and removes homogenous areas, which gives a gradientlike effect.\r\n\r\n\\paragraph{Top-hat and bottom-hat transformations}\\label{par:top-hat}\r\nSubtracting the opening of an image from the image itself defined the top-hat transformation\r\n\\begin{equation}\r\n    T\\sub{hat}(f) = f - (f \\open b).\r\n\\end{equation}\r\nThe bottom-hat transformation is defined similarly:\r\n\\begin{equation}\r\n    B\\sub{hat}(f) = (f \\close b) - f\r\n\\end{equation}\r\n\r\nTop-hat can isolate light objects on a dark background, and bottom-hat does the opposite. This is a type of segmentation, and works well even with uneven lightning.\r\n\r\nOpening with an SE that is too large to fit in the objects you want to segment will remove all such objects and leave only an approximation of the background, including any uneven lightning. If you subtract the approximate background from the original, the unevenness will be reduced, and now thresholding methods can be used with success.\r\n\r\n\\paragraph{Granulometry}\r\n(Assuming light objects on a dark background.) Open the image with gradually larger SEs, and compute the sum of pixel values. As the SEs grow larger than the objects, they disappear, and the pixel sum decreases. Plotting pixel sum against SE size indicates by peaks in the plot the predominant sizes of objects in the image. This can be used to simply get the size distribution of objects, but also to identify defect objects (sizewise).\r\n\r\n\\paragraph{Textural segmentation}\r\n(Assuming light objects on a dark background.) Textural segmentation is to divide an image into regions based on their texture contents. If you have an image with some coarse and some fine texture, you can close it with an SE large enough to remove the fine objects. Then open it with an SE large enough to fill the gaps between the coarse objects. Now coarse areas are dark, and fine areas are bright, and the boundary can be extracted by e.g. a morph. gradient.\r\n\r\n\\subsubsection{Greyscale morphological reconstruction}\r\nLet $f$ be the marker, and $g$ be the mask. The basic operations are similar to their black-and-white counterparts.\r\n\\begin{itemize}\r\n    \\item Geodesic dilation:\r\n    \\begin{equation}\r\n        D_g^{(1)}(f) = (f \\dilate b) \\wedge g\r\n    \\end{equation}\r\n    \\item Geodesic erosion:\r\n    \\begin{equation}\r\n        E_g^{(1)}(f) = (f \\erode b) \\vee g\r\n    \\end{equation}\r\n    \\item Reconstruction by dilation:\r\n    \\begin{equation}\r\n        R_g^D(f) = D_g^{(k)}(f)\r\n    \\end{equation}\r\n    \\item Reconstruction by erosion:\r\n    \\begin{equation}\r\n        R_g^E(f) = E_g^{(k)}(f)\r\n    \\end{equation}\r\n    \\item Opening by reconstruction:\r\n    \\begin{equation}\r\n        O_R^{(n)}(f) = R_f^D \\left[ (f \\erode nb) \\right]\r\n    \\end{equation}\r\n    \\item Closing by reconstruction:\r\n    \\begin{equation}\r\n        C_R^{(n)}(f) = R_f^E \\left[ (f \\dilate nb) \\right]\r\n    \\end{equation}\r\n\\end{itemize}\r\n\r\n\\paragraph{Top-hat by reconstruction}\r\nThis method consists of subtracting an image's opening by reconstruction from the image.\r\n", "meta": {"hexsha": "7cab0692bfcf7fd7c1a8d827573c13deb277b9f8", "size": 17618, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TDT4265 Computer vision/09-morphological-image-processing.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/09-morphological-image-processing.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/09-morphological-image-processing.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": 47.1069518717, "max_line_length": 464, "alphanum_fraction": 0.6867408332, "num_tokens": 4874, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8418256452674009, "lm_q1q2_score": 0.7857859979252482}}
{"text": "%!TEX root = ../gfkg.tex\n\\subsection{Chapter 4}\n\\begin{p}\n{Show that $\\omega+\\mu$ and $f\\omega$ are really 1-forms, i.e.\\ show linearity over $C^\\infty(M)$.}\n\\end{p}\n\nThat $\\omega$ and $\\mu$ are 1-forms means they are (separately) linear over $C^\\infty(M)$. So $[\\omega+\\mu](v+w)=\n\\omega(v+w)+\\mu(v+w)=\\omega(v)+\\omega(w)+\\mu(v)+\\mu(w)=[\\omega+\\mu](v)+[\\omega+\\mu](w)$. $f\\omega$ is just\nmultiplication by $f$ of the result of applying $\\omega$, so $[f\\omega](v+w)=f\\omega(v+w)=f\\omega(v)+f\\omega(w)$.\n\n\\begin{p}{Show that $\\Omega^1(M)$ is a module over $C^\\infty(M)$.}\n\\end{p}\n\nThere are four conditions to check. Let $f,g\\in C^\\infty(M)$ and $\\omega,\\mu\\in C^\\infty(M)$. The first condition\nis $f(\\omega+\\mu)=f\\omega+f\\mu$, which is true by applying each side of the equation to a test vector $v$ and\nusing the previous exercise to show the two resulting expressions are equal. Same for the conditions $(f+g)\\omega=f\\omega+g\\omega$,\n$(fg)\\omega=f(g\\omega)$, and $1\\omega=omega$. Basically the point is that by applying the 1-forms to test vectors, everything\nturns into functions and the equality of the different expressions follows immediately.\\\\\n\n\\begin{p}\n{Show that $d(f+g)=df+dg, d(\\alpha f)=\\alpha\\, df, (f+g)dh=f\\,dh+g\\,dh$, and $d(fg)=f(dg)+g(df)$ for any\n$f,g,h\\in C^\\infty(M)$ and any $\\alpha\\in \\R$.}\n\\end{p}\n\nThe differential map $d$ is defined by $df(v)=vf$. Applying this definition to the first equation, we obtain $d(f+g)v=v(f+g)=vf+vg=df(v)+dg(v)=[df+dg](v)$ as intended. Similarly, $d(\\alpha f)(v)=v(\\alpha f)=\\alpha vf=\\alpha df(v)$\nand $(f+g)dh(v)=(f+g)vh=f\\,vh+g\\,vh=[f\\,dh+g\\,dh](v)$. For the last condition, compute $d(fg)(v)=v(fg).$ By the definition\nof $v$ as a vector field, $v(fg)=gv(f)+fv(g)$, so we obtain $d(fg)(v)=[f(dg)+g(df)](v)$.\\\\\n\n\\begin{p}{Suppose $f(x^1,\\dots,x^n)$ is a function on $\\R^n$. Show that $df=\\partial_\\mu f\\,dx^\\mu$.}\n\\end{p}\n\nConsider an arbitrary vector field $v=v^\\nu \\partial_\\nu$. Then $df(v)=vf=v^\\nu \\partial_\\nu f$. On the other hand, $(\\partial_\\mu f\\,dx^\\mu)v=\\partial_\\mu f\\, vx^\\mu=\\partial_\\mu f\\, v^\\nu\\partial_\\nu x^\\mu=\\partial_\\mu f\\, v^\\nu \\delta_\\nu^\\mu=v^\\nu \\partial_\\nu f$. \nSo $df=\\partial_\\mu f\\,dx^\\mu$ as intended.\n\n{\\begin{p}{Show that the 1-forms $\\{dx^\\mu\\}$ are linearly independent.}\n\\end{p}\n\nSuppose $\\omega=\\omega_\\mu\\,dx^\\mu=0$. Then $\\omega(\\partial_\\nu)=\\omega_\\mu\\,dx^\\mu(\\partial_\\nu)=\\omega_\\mu \\partial_\\nu x^\\mu\n=\\omega_\\nu=0$.\n\n\\begin{p}{Show that $\\omega(v)(p)$ really depends only on $v_p$, not on \nthe values of $v$ at other points. Also, show that a 1-form is determined by its values at points.\nIn other words, if $\\omega, \\nu$ are two 1-forms on $M$ with $\\omega_p=\\nu_p$ for \nevery point $p\\in M$, then $\\omega=\\nu$. }\n\\end{p}\n\nSuppose $w$ is a vector field for which $w_p=0$ but generally $w_q\\neq 0$. By linearity, $\\omega(v+w)=\\omega(v)+\\omega(w)$. \nSpecializing to the point $p$, we have $\\omega(v+w)(p)=\\omega(v)(p)+\\omega(w)(p)=\\omega_p(v_p)+\\omega_p(w_p)$. But\nsince $w_p=0$, the latter term is zero, and $\\omega(v+w)(p)=\\omega(v)(p)$. This means we can change the field $v$ at points\ndistinct from $p$ and still obtain the same action by $omega$ at the desired point. Note that this works due to the linearity of the\nmap $\\omega$.\\\\\n\nSince we can ``decompose'' the field $v$ into tangent vectors $v_p$ at each point $p\\in M$, (excercise 10), we have \n$\\omega_p(v_p)=\\nu_p(v_p) = \\omega(v)(p)=\\nu(v)(p)$. This has to hold for any $v$ and all $p$, so $\\omega=\\nu$.\\\\\n\n\\begin{p}{Show that the dual of the identity map on a vector space $V$ is the identity map on $V^*$. Suppose\nthat we have linear maps $f:V\\rightarrow W$ and $g:W\\rightarrow X$. Show that $(gf)^*=f^*g^*$. }\n\\end{p}\n\nThe dual of a function $f$ is defined by $(f^*\\omega)(v)=\\omega(f(v))$. So if $f$ is the identity, then $(f^*\\omega)(v)=\\omega(v)$,\nmeaning that $f^*$ must be the identity as well. \nNow we find $[(gf)^*\\omega](v)=\\omega(g(f(v)))=[g^*\\omega](f(v))=[f^*g^*\\omega](v)$,\nso  $(gf)^*=f^*g^*$.\n\n\\begin{p}{Show that the pullback defined by the equation $(\\phi^*\\omega)_p=\\phi^*(\\omega_q)$, where $\\phi(p)=q$,\nreally exists and is unique.}\n\\end{p}\n\nStart with  $(\\phi^*\\omega)_p(v_p)=\\phi^*\\omega(v)(p)=\\omega(\\phi_*v)(\\phi(p))=\\omega(\\phi_*v)(q)$. The other \nside of the equation gives $\\phi^*(\\omega_q)v_q=\\omega_q(\\phi_* v_q)$, the same. Uniqueness follows from linearity: if there were\ntwo possible outputs, we could consider their difference. By linearity this would be the result of applying the map to the difference of the\nfixed input, which is zero. But the output of zero is zero, so the two possible outputs are equal.\\\\\n\n\\begin{p}{Let $\\phi:\\R\\rightarrow \\R$ be given by $\\phi(t)=\\sin t$. Let $dx$ be the usual\n1-form on $\\R$. Show that $\\phi^*dx=\\cos t\\,dt$.}\n\\end{p}\n\n$\\phi^*(df)=d(\\phi^*f)$ since the exterior derivative is natural. Thus $\\phi^*(df)=d(\\sin t)=\\cos t\\,dt$.\n\n\\begin{p}{Let $\\phi:\\R^2\\rightarrow \\R^2$ denote rotation counterclockwise by the \nangle $\\theta$. Let $dx, dy$ be the usual basis of 1-forms on $\\R^2$. Show that $\\phi^*dx=\\cos\\theta\\,dx-\\sin\\theta\\,dy$\nand $\\phi^*dy=\\sin\\theta\\,dx+\\cos\\theta\\,dy$. }\n\\end{p}\n\n$\\phi^*dx=d(\\phi^*x)=d(x\\cos\\theta-y\\sin\\theta)=\\cos\\theta\\,dx-\\sin\\theta\\,dy$. Similarly for $\\phi^*dy$. \n\n\\begin{p}{Show that the coordinate 1-forms $dx^\\mu$ really are the differentials of the local coordinates $x^\\mu$ on $U$.}\n\\end{p}\n\nTechnically, $x^\\mu$ is the local coordinate on $\\R^n$ which picks out the $\\mu$th component. When speaking\nof $x^\\mu$ on $U$, we really mean $\\phi^*x^\\mu$, where $\\phi$ is the map from $U$ to $\\R^n$. Thus\n$dx^\\mu$ is really $d(\\phi^*x^\\mu)=\\phi^*dx^\\mu$, so the sloppiness of the notation doesn't injure the relationship\nbetween functions and 1-forms.\n\n\\begin{p}{Show that $dx'^\\nu=\\frac{\\partial x'^\\nu}{\\partial x^\\mu}dx^\\mu$. Show that for any 1-form $\\omega$ on $\\R^n$,\nwriting $\\om=\\om_\\mu dx^\\mu=\\om'_\\nu dx'^\\nu$, the components $\\omega'_\\nu$ are related to the components $\\omega_\\mu$ by\n$\\omega'_\\nu=\\frac{\\partial x^\\mu}{\\partial x'^\\nu}\\om_\\mu$.}\n\\end{p}\n\nFor the first equation, apply both sides to the partial $\\partial_\\alpha$: $dx'^\\nu(\\partial_\\alpha)=\n\\partial_\\alpha(x'^\\nu)$ and $\\frac{\\partial x'^\\nu}{\\partial x^\\mu}dx^\\mu(\\partial_\\alpha)=\n\\frac{\\partial x'^\\nu}{\\partial x^\\mu}\\partial_\\alpha(x^\\mu)=\n\\frac{\\partial x'^\\nu}{\\partial x^\\mu}\\delta^\\mu_\\alpha=\\frac{\\partial x'^\\nu}{\\partial x^\\alpha}=\n\\partial_\\alpha(x'^\\nu)$. For the second, use the same trick. Apply $\\om$ to \n$\\frac{\\partial}{\\partial x'^\\alpha}$. The left expression gives $\\om_\\mu dx^\\mu(\\frac{\\partial}{\\partial x'^\\alpha})=\n\\om_\\mu\\frac{\\partial x^\\mu}{\\partial x'^\\alpha}$, while the right expression gives $\\om'_\\alpha$.\\\\\n\n\\begin{p}{Show that $\\phi^*(dx'^\\nu)=\\frac{\\partial x'^\\nu}{\\partial x^\\mu}dx^\\mu$.}\n\\end{p}\n\n$\\phi^*(dx'^\\nu)\\partial_\\mu=d(\\phi^*x'^\\nu)\\partial_\\mu=\\partial_\\mu(\\phi^* x'^\\nu)=\\frac{\\partial x'^\\nu}{\\partial x^\\mu}$.\n\n\\begin{p}{Let $e_\\mu=T^\\nu_\\mu\\partial_\\nu$, where $\\partial_\\nu$ are the coordinate vector fields associated to local coordinates on\nan open set $U$ and $T^\\nu_\\mu$ are functions on $U$. Show that the vector fields $e_\\mu$ are a basis of vector fields on $U$ iff for \neach $p\\in U$ the matrix $T^\\nu_\\mu(p)$ is invertible.}\n\\end{p}\n\n\\begin{itemize}\n\\item[$\\Rightarrow$] The matrix $T^\\nu_\\mu(p)$ is invertible, so det$T\\neq 0$, meaning the $e_u$ are linearly independent at $p$ and thus \nform a basis at $p$. Since this works for all $p$, the vector fields $e_\\mu$ are a basis. \n\\item[$\\Leftarrow$] Try to expand an arbitrary $\\om$ in terms of the $e_\\mu$: $\\om=\\om^\\mu e_\\mu$. We can also express\n$\\om$ in terms of the $\\partial_\\nu$ as $\\om=\\om'^\\nu\\partial_\\nu$, with $\\om'^\\nu= T^\\nu_\\mu \\om^\\mu$. If $T$ were not invertible, \nwe would not be able to construct the $\\om^\\mu$ from the $\\om'^\\nu$ (which are the ones guaranteed to exist), so $e_\\mu$ wouldn't be \na basis. Since it is a basis, $T$ must be invertible. \n\\end{itemize}\n\n\\begin{p}{Use the previous exercise to show that the dual basis exists and is unique}\n\\end{p}\n\nLet $f^\\mu$ be the putative dual basis to the $e_\\nu$. Then $f^\\mu(e_\\nu)=\\delta^\\mu_\\nu=T^\\lambda_\\nu f^\\mu\\partial_\\lambda$.\nNow suppose $f^\\mu=S^\\mu_\\lambda dx^\\lambda$. Inserting into the previous equation we obtain $T^\\lambda_\\nu S^\\mu_\\lambda=\\delta^\\mu_\\nu$, so $S$ is the inverse of $T$. Since $T$ is invertible, the $f^\\mu$ are well-defined and unique.\n\n\\begin{p}{Let $e_\\mu$ be a basis of vector fields on $U$ and let $f^\\mu$ be the dual basis of 1-forms. Let $e'_\\mu=T^\\nu_\\mu e_\\nu$\nbe another basis of vector fields, and let $f'^\\mu$ be the corresponding dual basis of 1-forms. Show that $f'^\\mu=(T^{-1})^\\mu_\\nu f^\\nu$. Show\nthat if $v=v^\\mu e_\\mu=v'^\\mu e'_\\mu$, then $v'^\\mu=(T^{-1})^\\mu_\\nu v^\\nu$ and that if\n$\\om=\\om_\\mu f^\\mu=\\om'_\\mu f'^\\mu$ then $\\om'_\\mu=T^\\nu_\\mu \\om_\\nu$.}\n\\end{p}\n\nThis is where the ``historical'' definitions of co- and contra-variant come from, specifying whether something transforms like the components\nof a vector or like the basis vectors themselves. (Vectors, being susceptible to pushforward, are covariant. 1-forms are contravariant, but the components of a vector are also contravariant, while the components of 1-forms are covariant.) For $f'^\\mu$, apply it to $e'_\\nu$:\n$f'^\\mu(e'_\\nu)=\\delta^\\mu_\\nu$. Using the definition of $e'_\\nu$, $\\delta^\\mu_\\nu=T_\\nu^\\lambda f'^\\mu(e_\\lambda)$. \nThis works if $f'^\\mu=(T^{-1})^\\mu_\\nu f^\\nu$. All this can be done more easily in matrix notation. For the next case, let $\\mathbf{v}$ be the \nordered set of $v^\\mu$ and likewise $\\mathbf{e}$ the set of $e_\\mu$. Then $v=\\mathbf{v}\\cdot\\mathbf{e}$. Meanwhile, $\\mathbf{e}'=T\\mathbf{e}$, so clearly we're going to need $\\mathbf{v}'=(T^{-1})^T\\mathbf{v}$ so that \n$\\mathbf{v}'\\cdot\\mathbf{e}'=\\mathbf{v}T^{-1}T\\mathbf{e}=v$. Thus, we predict that $v'^\\mu=(T^{-1})^\\mu_\\nu v^\\nu$, using\nthe inverse and transposed $T$ as given in the definition of $e'_\\mu$. Similarly $\\om=\\mathbf{\\om}\\cdot\\mathbf{f}$, so \n$\\om'_\\mu=T^\\nu_\\mu \\om_\\nu$.\n\n\\begin{p}{Show that $u\\wedge v\\wedge w={\\rm det}\\left(\\begin{array}{ccc} u_x & u_y & u_z \\\\\nv_x & v_y & v_z\\\\ w_x & w_y & w_z\\end{array}\\right)\\,dx\\wedge dy\\wedge dz$. Compare this to $\\vec{u}\\cdot(\\vec{v}\\times\\vec{w})$.}\n\\end{p}\n\n...algebra\n\n\\begin{p}{Show that if $a,b,c,d$ are four 1-forms in a 3-dimensional space, then $a\\wedge b\\wedge c\\wedge d=0$.}\n\\end{p}\n\nSince there are only three linearly independent 1-forms in this space, the 4-fold wedge product will always contain two of the basis\nelements twice, which by antisymmetry, means the entire expression must be zero.\n\n\\begin{p}{Describe $\\bigwedge V$ if $V$ is 1-,2-,3-, or 4-dimensional.}\n\\end{p}\n\n1-dimensional: scalars and vectors. 2-dimensional: scalars, vectors, and areas. 3-dimensional: scalars, vectors, areas, and volumes. 4-dimensional:\nall the previous, plus 4-volumes.\n\n\\begin{p}{Let $V$ be an n-dimensional vector space. Show that $\\bigwedge^{\\!p} V$ is empty for $p>n$ and that for $0\\leq p\\leq n$ the dimension of $\\bigwedge^{\\!p} V$ is $n!/p!(n-p)!$.}\n\\end{p}\n\nAs in exercise 42, elements of $\\bigwedge^{\\!p} V$ are wedge products of $p$ different terms, but since there are only $n$ independent possibilities,\n$\\bigwedge^{\\!p} V$ is empty for $p>n$. Wedging $p$ different terms for $p\\leq n$ can be done in $\\binom{n}{p}$ ways since by antisymmetry \nthe order of the terms can only affect the sign of the result.\n\n\\begin{p}\n{Show that $\\bigwedge V=\\bigoplus_p \\bigwedge^{\\!p} V$.}\n\\end{p}\n\nSince we've defined $\\bigwedge V$ formally, as the linear space of wedge products of elements of $V$, we then immediately have\nthat the different sectors corresponding to different number of wedgings $p$ are disjoint. Thus we can treat these \ncompletely independently from one another and form $n$-tuples containing entries from each sector. This will be an element of\n$\\bigwedge V$ since adding elements of distinct grade is also purely formal and can always be resolved into the various\ngraded components. Thus, $\\bigwedge V=\\bigoplus_p \\bigwedge^{\\!p} V$.\n\n\\begin{p}{Given a vector space $V$, show that $\\bigwedge V$ is a graded commutative or supercommutative algebra;\nthat is, if $\\om\\in \\bigwedge^{\\!p}V$ and $\\mu\\in\\bigwedge^{\\!q}V$, then $\\om\\wedge\\mu=(-1)^{pq}\\mu\\wedge\\om$.}\n\\end{p}\n\nThis is essentially just a counting argument. $\\om$ is the wedge of $p$ things, $\\mu$ $q$. So to invert the order of wedging\nthem together means transporting $p$ elements of $V$ past $q$ elements of $V$, each time picking up a minus one.\n\n\\begin{p}{Show that differential forms are contravariant. That is, show that if $\\phi:M\\rightarrow N$ is a map from the manifold\n$M$ to the manifold $N$, there is a unique pullback map $\\phi^*:\\Omega(N)\\rightarrow\\Omega(M)$ agreeing with the usual pullback \non 0-forms (functions) and 1-forms, satisfying $\\phi^*(\\alpha\\om)=\\alpha\\phi^*\\om$, $\\phi^*(\\om+\\mu)=\\phi^*\\om+\\phi^*\\mu$ and\n$\\phi^*(\\om\\wedge \\mu)=\\phi^*\\om\\wedge\\phi^*\\mu$, for all $\\om,\\mu\\in\\Omega(N)$ and $\\alpha\\in\\R$.}\n\\end{p}\n\nI take the three conditions to almost be the definition of the map. For a general $\\om$, resolve it into a linear combination of \ngraded components using an arbitrary basis of 1-forms to generate the $p$-forms. The by condition two the pullback applies to each\nterm separately. By condition one the coefficients of each term don't interfere with the pullback. Finally, by condition three we apply the pullback\nto each of the 1-forms making up the basis $p$-forms, so the map is well-defined. Its unique because the pullback applied to 1-forms and \nfunctions is unique.\n\n\\begin{p}{Compare the transformation properties of 1-forms and 2-forms on $\\R^3$ under parity. That is, let $P:\\R^3\\rightarrow\\R^3$ be the map $P(x,y,z)=(-x,-y,-z)$, known as the `parity transformation'. \nNote that $P$ maps right-handed bases to left-handed bases and vice versa. Compute $\\phi^*\\om$ when $\\om$ is the 1-form\n$\\om_\\mu dx^\\mu$ and when it is the 2-form $\\frac{1}{2}\\omega_{\\mu,\\nu} dx^\\mu\\wedge dx^\\nu$.}\n\\end{p}\n\nIf prime variables refer to the output space, for instance $x'=-x$, the \nessential point is that $\\phi^*(dx'^\\mu)=d(\\phi^* x'^\\mu)=d(-x^\\mu)=-dx^\\mu$. Thus \n$\\phi^*\\om^{(1)}=-\\om$ and $\\phi^*\\om^{(2)}=\\om^{(2)}$.\n\n\\begin{p}{Show that on $\\rn$ the exterior derivative of any 1-form is given by $d(\\om_\\mu dx^\\mu)=\\partial_\\nu\\om_\\mu dx^\\nu\\wedge dx^\\mu$.}\n\\end{p}\n\n$d(\\om_\\mu dx^\\mu)=d\\om_\\mu\\wedge dx^\\mu=\\partial_\\nu\\om_\\mu dx^\\nu\\wedge dx^\\mu$.\n\n", "meta": {"hexsha": "4623aff2bd0c435cc7f4f92e04d836272e5e42e1", "size": 14470, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/I4.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/I4.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/I4.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": 66.9907407407, "max_line_length": 274, "alphanum_fraction": 0.6732550104, "num_tokens": 4974, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.7857363278702817}}
{"text": "\\chapter{Matrices}\n\nThe plural of \\emph{matrix} is \\emph{matrices}.\n\nMatrices were invented to abbreviate systems of linear equations?%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Matrix_(mathematics)\\#History}}\n\nA matrix is a rectangular array of numbers.\n\nWe write \\(A_{ij}\\) or \\(A(i,j)\\) to mean the cell at row \\(i\\) column \\(j\\).\n\n\\paragraph{Finding the dimension of a matrix}\n\nWe say that the dimension of a matrix \\(A\\) is \\((m,n)\\),\nwritten \\(\\dim(A) = (m,n)\\),\niff the matrix has \\(m\\) rows and \\(n\\) columns.\n\n\\paragraph{Example}\nThe following matrix has 2 rows and 3 columns, so its dimension is \\((2,3)\\).\n\\Formula{\\NoNumber\n    \\Matrix{\n        A_{11} & A_{12} & A_{13}\n        \\\\\n        A_{21} & A_{22} & A_{23}\n    }\n}\n\n\\section*{Don't confuse vectors and coordinate tuples}\n\nUse the phrases \\emph{column matrix} and \\emph{row matrix}\ninstead of \\emph{column vector} and \\emph{row vector}.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Row_and_column_vectors}}\n\nThe phrase \\emph{column vector} confuses a geometric vector and\nthe coordinate tuple that describes the vector.\n\nA vector is \\emph{not} a bunch numbers.\nA vector is a geometric object with length and direction.\nA vector can be \\emph{described} by a coordinate tuple under a coordinate system.\n\n\\section{Working with matrices}\n\n\\subsection{Multiplying matrices}\n\nMatrix addition is simple:\nadd the elements at the same positions:\n\\Formula{\n    (AB)_{ij} = A_{ij} + B_{ij}\n}\n\nThe cell \\((AB)_{ij}\\) depends on row \\(i\\) of \\(A\\) and column \\(j\\) of \\(B\\).\n\\Formula{\n    (AB)_{ij} = \\sum_k A_{ik} B_{kj}\n}\n\n\\subsection{Abbreviating a system of linear equations into a matrix equation}\n\nA matrix \\enquote{packs} a system of linear equations into one equation.\n\n\\[ AB = C \\]\n\n\\subsection{Linear function? Using matrix to describe a linear transformation?}\n\nA matrix is a linear map?\n\nA matrix is a vector of covectors?\n\nA linear function is called linear because it describes a line.\n\nA function \\(f\\) is \\emph{linear} iff \\( f(x+y) = f(x) + f(y) \\).\n\nA \\emph{transformation} is another word for function.\n\nTransformation.\nLinear transformation.\n$T(ax+by) = aTx + bTy$.\n\nMatrix arises naturally for describing linear transformations on a vector space.\n\n\\section{Generalizing vectors, matrices, and tensors to functions of indexes}\n\nThe notation \\(A(i)\\) suggests that a vector is a function \\( I \\to \\Real \\).\nThe notation \\(A(i,j)\\) suggests that a matrix is a function \\( (I,J) \\to \\Real \\).\n\n\\section{Thinking of a matrix as a linear operator}\n\n\\section{Tuple vs array vs matrix vs tensor}\n\nAn array is a bunch of numbers.\n\nA matrix is a \\emph{rectangular} array for which matrix operations are defined.\n\nA tensor carries with it a coordinate system?\n\nA tensor is \\emph{not only} a multi-dimensional array of numbers.\n\nA tuple is a one-dimensional (linear) array.\n\nA matrix is a two-dimensional (rectangular) array.\n\nA tensor is a multi-dimensional array.\n", "meta": {"hexsha": "5d20b2bee46d40df28ee772553373c4b4fbc6acb", "size": 2934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/matrix.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/matrix.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/matrix.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 28.7647058824, "max_line_length": 83, "alphanum_fraction": 0.712338105, "num_tokens": 785, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068041, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7857159555043468}}
{"text": "\\section{A short application to chemistry}\n\nThe following section applies the concepts of spanning and linear independence to the subject of chemistry.\n\nWhen working with chemical reactions, there are sometimes a large number of reactions and some are in a sense redundant. Suppose you have the following chemical\nreactions.\n\\begin{equation*}\n\\begin{array}{c}\nCO+\\vspace{0.05in}\\frac{1}{2}O_{2}\\rightarrow CO_{2} \\\\\nH_{2}+\\vspace{0.05in}\\frac{1}{2}O_{2}\\rightarrow H_{2}O \\\\\nCH_{4}+\\vspace{0.05in}\\frac{3}{2}O_{2}\\rightarrow CO+2H_{2}O \\\\\nCH_{4}+2O_{2}\\rightarrow CO_{2}+2H_{2}O\n\\end{array}\n\\end{equation*}\nThere are four chemical reactions here but they are not independent\nreactions. There is some redundancy. What are the independent reactions? Is\nthere a way to consider a shorter list of reactions? To analyze this\nsituation, we can write the reactions in a matrix as follows\n\\begin{equation*}\n\\begin{mymatrix}{cccccc}\nCO & O_{2} & CO_{2} & H_{2} & H_{2}O & CH_{4} \\\\\n1 & 1/2 & -1 & 0 & 0 & 0 \\\\\n0 & 1/2 & 0 & 1 & -1 & 0 \\\\\n-1 & 3/2 & 0 & 0 & -2 & 1 \\\\\n0 & 2 & -1 & 0 & -2 & 1\n\\end{mymatrix}\n\\end{equation*}\n\nEach row contains the coefficients of the respective elements in each reaction. For example, the top row of numbers comes from $CO+\\frac{1}{2}O_{2}-CO_{2}=0$ which\nrepresents the first of the chemical reactions.\n\nWe can write these coefficients in the following matrix\n\\begin{equation*}\n\\begin{mymatrix}{rrrrrr}\n1 & 1/2 & -1 & 0 & 0 & 0 \\\\\n0 & 1/2 & 0 & 1 & -1 & 0 \\\\\n-1 & 3/2 & 0 & 0 & -2 & 1 \\\\\n0 & 2 & -1 & 0 & -2 & 1\n\\end{mymatrix}\n\\end{equation*}\nRather than listing all of the\nreactions as above, it would be more efficient to only list those which are independent by throwing out that which is redundant. We can use the concepts of the previous section to accomplish this.\n\nFirst, take the {\\rref} of the above matrix.\n\\begin{equation*}\n\\begin{mymatrix}{rrrrrr}\n1 & 0 & 0 & 3 & -1 & -1 \\\\\n0 & 1 & 0 & 2 & -2 & 0 \\\\\n0 & 0 & 1 & 4 & -2 & -1 \\\\\n0 & 0 & 0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nThe top three rows represent \\textquotedblleft independent\" reactions which\ncome from the original four reactions. One can obtain each of the original\nfour rows of the  matrix given above by taking a suitable\nlinear combination of rows of this {\\rref} matrix.\n\nWith the redundant reaction removed, we can consider the simplified reactions as the following equations\n\\begin{equation*}\n\\begin{array}{c}\nCO+3H_{2}-1H_{2}O-1CH_{4}=0 \\\\\nO_{2}+2H_{2}-2H_{2}O=0 \\\\\nCO_{2}+4H_{2}-2H_{2}O-1CH_{4}=0\n\\end{array}\n\\end{equation*}\nIn terms of the original notation, these are the reactions\n\\begin{equation*}\n\\begin{array}{c}\nCO+3H_{2}\\rightarrow H_{2}O+CH_{4} \\\\\nO_{2}+2H_{2}\\rightarrow 2H_{2}O \\\\\nCO_{2}+4H_{2}\\rightarrow 2H_{2}O+CH_{4}\n\\end{array}\n\\end{equation*}\n\nThese three reactions provide an equivalent system to the original four equations. The idea is that, in terms of what happens chemically, you\nobtain the same information with the shorter list of reactions. Such a simplification is especially useful when dealing with very large lists of reactions which may result from experimental evidence.\n", "meta": {"hexsha": "26b1896c186893951aa8c5978b1fd6f947494941", "size": 3112, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsSpanIndependenceBasisChemistryApplication.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/RnVectorsSpanIndependenceBasisChemistryApplication.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/RnVectorsSpanIndependenceBasisChemistryApplication.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.4155844156, "max_line_length": 199, "alphanum_fraction": 0.7082262211, "num_tokens": 1038, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896132, "lm_q2_score": 0.8824278788223264, "lm_q1q2_score": 0.7856204377788996}}
{"text": "\\subsection{Numerical Experiments}\n    \n    Now, we will proceed to describe the steps necessary to implement the method based on the above:\n    \\begin{enumerate}\n    \t\\item We are going to consider the interval given by $[0, 1]$, which represents the domain of physical space, and similarly, the time will be set by the real value $t_f>0$ such that $[0, t_f]$. So, as a first step, we must define the problem well by choosing the parameters identified and required by the problem \\ref{infinite_system}, which in the same way will be denoted by: $N$, $M$, $N_1 \\in \\mathbb{N}$, and $\\alpha \\in \\mathbb{R}^+$.\n    \t\n    \t\\item Given the above information, it is possible to follow the same methodology that we have analyzed in \\ref{finite_system}, and define as a second step the calculation of the set $J^{M, N}$ given by \\ref{Conjunto_J}, and then, as an intermediate step, obtain the set of points for each domain that we have defined above. \n    \t\n    \tAs an observation, the choice of the set of points, in this case, is arbitrary, and for example, We could obtain them by calculating the points $\\xi_i \\in [0, 1]$ defined for each $i = 0, 1, \\dots, p \\in \\mathbb{N}^+$ as\n    \t\\begin{align*}\n    \t\t\\xi_i = \\xi_0 + i \\Delta \\xi, \\hspace{2mm} i = 0, 1, \\dots, p\n    \t\\end{align*}\n    \tand similarly for $t_j \\in [t_0, t_f]$ with $j = 0, 1, \\dots, l \\in \\mathbb{N}^+$ to obtain the following\n    \t\\begin{align*}\n    \t\tt_j = t_0 + j \\Delta t, \\hspace{2mm} \\Delta t = \\frac{t_f - t_0}{l} \n    \t\\end{align*}\n    \t\n    \t\\item Concluding with the previous steps will allow us to obtain everything that is required to begin to construct the initial value problem of the system \\ref{finite_system_vectorial}, which could be considered as the step that requires more attention because we must obtain the matrix $\\bar{C}_{n, m}$ using the simplification given in \\ref{Cnm}. \n    \t\n    \tHowever, this calculation gives the impression that it will give us a lot of work, but when observing its expression we can notice that we only have to focus on each of the combinations given by the multiplication of the Hermite polynomials that we must then integrate, for example, using some quadrature rule, and finally make its summation.\n    \t\n    \t\\item Successfully achieving this last step, what remains are to solve an eigenvalue problem given by \\ref{eigen}, which is solved by some conventional numerical method to obtain the eigenvalues $\\eta_i$ with their respective eigenvectors $V_i$. \n    \t\n    \tThen, Using the functional $u_0$ as in \\ref{IC_approx} to calculate the constants $c_k$ for each $k = 1, \\dots, M$, and by using the expansion given by \\ref{solution_finite_system} to obtain the solution of the problem as follows\n\n    \t\\begin{align*}\n    \t\tu^M(x_i, t_j) = \\displaystyle \\sum_{k=1}^{M} u_k (t_j) H_k (x_i), \\hspace{2mm} \\left\\{x_i\\right\\}_{i=0}^{p} \\in \\left[ 0, 1 \\right], \\left\\{t_j\\right\\}_{j=0}^{l} \\in \\left[ 0, t_f \\right]\n    \t\\end{align*}\n    \\end{enumerate}\n    \n    The following simulations that will be shown were performed using a discretization of $2048$ points in the spatial variable $\\xi$ over the interval $[0, 1]$, and $1024$ points in the variable time $t$ over the interval $[0, 10]$. In addition, the values of the parameters $N = 5$, $M = 11$, and $\\alpha = 1.0 \\times 10^{-2}$ were considered. With this information, the solutions obtained were calculated using the following initial condition and its truncated Chebysheb expansion given by\n    \\begin{align*}\n    \tx(\\xi) = \\sin(\\pi \\xi), \\hspace{3mm} y(\\xi) = \\displaystyle \\sum^{N}_{k=0} c_k T_k (\\xi),\n    \\end{align*}\n    \n    This numerical experiment consists of illustrating an interesting result given in \\cite{Delgado2019}, which tells us that the solutions obtained from two close initial conditions also remain close. This behavior allows characterizing what is known as the stability of the approximation, and it is described by means of continuity with respect to the initial conditions of the numerical approximations of the equation (\\ref{kolmogorov}). \\\\\n    \n    To understand this better, let us denote by $\\Psi^{x}_t$ the solution of (\\ref{kolmogorov}) obtained by\n    \\begin{align*}\n    \tu(x, t) = \\mathbb{E} \\left[ \\varphi (X^x_t) \\right]. \n    \\end{align*}\n    where $\\varphi: \\mathcal{H} \\rightarrow \\mathbb{R}$ is Lipschitz and $X^x_t$ is the solution to (\\ref{stochastic_equation}) with initial conditions $X_0 = x \\in \\mathcal{H}$. So, as before, its expansion is given by\n    \\begin{align*}\n    \t\\Psi^{x}_t = \\displaystyle \\sum _{n \\in \\mathcal{J}} u_n (t) H_n (x), \\hspace{2mm} x \\in \\mathcal{H}, \\hspace{2mm} t \\in [0, T].\n    \\end{align*}\n    \n    Therefore, following our reference, the above is summarized as follows: Given two different initial conditions $x, y \\in \\mathcal{H}$, then we have the following estimate\n\t\\begin{align*}\n\t\t\\| \\Psi^x_t - \\Psi^y_t \\|^2_{\\left( L^2 (\\mathcal{H}, \\mu)\\right)^2} \\leq \\exp(Ct) \\displaystyle \\int_{\\mathcal{H} \\times \\mathcal{H}} \\|x - y \\|^2_{\\mathcal{H}} \\mu (dx) \\mu (dy) + f(t) \\|x - y\\|_{\\mathcal{H}},\n\t\\end{align*}\n\tfor some $C$ finite and $f(t)$ is given by\n\t\\begin{align*}\n\t\tf(t) = \\displaystyle \\sum_{n \\in J} \\left[u^y_n (t)\\right]^2 + \\int_{\\mathcal{H}} \\mathbb{E}^2 \\left[\\varphi (X^y_t)\\right] \\mu (dy).\n\t\\end{align*}\t\n\t\n\tFrom the above, we can see that if $ \\| x - y \\|_{\\mathcal{H}} \\leq \\delta$, so we have to $\\| \\Psi^x_t - \\Psi^y_t \\| \\leq G (t) \\delta$. As we have already mentioned, this continuity defines a type of stability for approximations, which is of utmost importance in this field since characterizations of this type are still under construction and are essential for the analysis of a numerical method. \\\\\n\t\n\tThis behavior is shown in the following figures, which were obtained using codes that were created following the previous steps, and which can be found in \\url{https://github.com/alanmatzumiya/Paper.git}. In figure \\ref{IC_Cheb} it shows us the two initial conditions for which the equation (\\ref{kolmogorov}) will be solved by associating it with (\\ref{burgers_stochastic}), and in figure \\ref{Stochastic_Solutions} we can see that the solutions keep the distance. Finally, the figure \\ref{Continuity} shows the distances for each instant of time $t$, showing that they are actually getting closer as time passes.\n\t\n\\newpage\n\t\\begin{figure}[H]\t\n\t\t\\centering\t\n\t\t\\includegraphics[width=.55\\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/IC.png}\n\t\t\\caption{Initial condition for (\\ref{burgers_stochastic2}) and its approximation.}\n\t\t\\label{IC_Cheb}\t\n\t\t\\includegraphics[width=.9\\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/Numerical_Solution_Stochastic.png}\n\t\t\\caption{Numerical solutions for (\\ref{burgers_stochastic2}) with initial conditions $x(\\xi)$ and $y(\\xi)$.}\n\t\t\\label{Stochastic_Solutions}\t\n\t\\end{figure}\n\\newpage\n\t\\begin{figure}[H]\t\n\t\\centering\n\t\t\\includegraphics[width=.7\\textwidth]{burgers_equation/stochastic/numerical_experiments/figures/norms.png}\n\t\t\\caption{Distance between the numerical solutions for equation (\\ref{burgers_stochastic2}) with initial conditions $x(\\xi)$, and $y(\\xi)$.}\n\t\t\\label{Continuity}\n\t\\end{figure}", "meta": {"hexsha": "65dc8a0b35895d57caecc13430c94723dc756619", "size": 7178, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Numerical_Experiments.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Numerical_Experiments.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/stochastic/numerical_experiments/Numerical_Experiments.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": 94.4473684211, "max_line_length": 615, "alphanum_fraction": 0.7130119811, "num_tokens": 2139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8633916222765627, "lm_q1q2_score": 0.7856060860640006}}
{"text": "\\section{L'H\\^opital's Rule}\\label{sec:LH}\r\nThe following application of derivatives allows us to compute certain limits.\r\n\r\n\\begin{definition}{Limits of the Indeterminate Forms $\\frac{0}{0}$ and $\\frac{\\infty}{\\infty}$}{IndeterminateLimits}\r\nA limit of a quotient $\\lim\\limits_{x\\rightarrow a}\\frac{f\\left( x\\right) }{%\r\n\tg\\left( x\\right) }$ is said to be an \\textbf{indeterminate form of the type }%\r\n$\\frac{0}{0}$ if both $f\\left( x\\right) \\rightarrow 0$ and $g\\left( x\\right)\r\n\\rightarrow 0$ as $x\\rightarrow a.$ Likewise, it is said to be an \\textbf{%\r\n\tindeterminate form of the type} $\\frac{\\infty }{\\infty }$ if both $f\\left(\r\nx\\right) \\rightarrow \\pm \\infty $ and $g\\left( x\\right) \\rightarrow \\pm\r\n\\infty $ as $x\\rightarrow a$ (Here, the two $\\pm $ signs are independent of\r\neach other).\r\n\\end{definition}\r\n\r\n\\begin{theorem}{L'H\\^opital's Rule}{LHRule}\r\nFor a limit $\\lim\\limits_{x\\rightarrow a}\\frac{f\\left( x\\right) }{g\\left(\r\n\tx\\right) }$ of the indeterminate form $\\frac{0}{0}$ or $\\frac{\\infty }{%\r\n\t\\infty },$ $\\lim\\limits_{x\\rightarrow a}\\frac{f\\left( x\\right) }{g\\left(\r\n\tx\\right) }=\\lim\\limits_{x\\rightarrow a}\\frac{f^{\\prime }\\left( x\\right) }{%\r\n\tg^{\\prime }\\left( x\\right) }$ if $\\lim\\limits_{x\\rightarrow a}\\frac{%\r\n\tf^{\\prime }\\left( x\\right) }{g^{\\prime }\\left( x\\right) }$ exists or equals $%\r\n\\infty $ or $-\\infty$.\r\n\\end{theorem}\r\n\r\nThis theorem is somewhat difficult to prove, in part because it\r\nincorporates so many different possibilities, so we will not prove it\r\nhere.\r\n\r\nWe should also note that there may be instances where we would need to apply L'H\\^opital's Rule multiple times, but we must confirm that $\\lim_{x\\to a}\\frac{f'(x)}{g'(x)}$ is still indeterminate before we attempt to apply L'H\\^opital's Rule again. Finally, we want to mention that L'H\\^opital's rule is also valid for one-sided limits and limits at infinity.\r\n\r\n\\begin{example}{L'H\\^opital's Rule}{lhrule0}\r\nCompute $\\ds\\lim_{x\\to \\pi}\\frac{x^2-\\pi^2}{\\sin x}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe use L'H\\^opital's Rule: Since the numerator and denominator\r\nboth approach zero,\r\n$$\\lim_{x\\to \\pi}\\frac{x^2-\\pi^2}{\\sin x}=\r\n\\lim_{x\\to \\pi}\\frac{2x}{\\cos x},$$\r\nprovided the latter exists. But in fact this is an easy limit, since\r\nthe denominator now approaches $-1$, so \r\n$$\\lim_{x\\to \\pi}\\frac{x^2-\\pi^2}{\\sin x}=\\frac{2\\pi}{-1} = -2\\pi.$$\r\n\\end{solution}\r\n\r\n\\begin{example}{L'H\\^opital's Rule}{LHRule1}\r\nCompute $\\ds\\lim_{x\\to \\infty}{2x^2-3x+7\\over\r\nx^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, so we may apply L'H\\^opital's Rule:\r\n$$\\lim_{x\\to \\infty}\\frac{2x^2-3x+7}{x^2+47x+1}=\r\n\\lim_{x\\to \\infty}\\frac{4x-3}{2x+47}.$$\r\nIn the second quotient, it is still the case that the numerator and\r\ndenominator both go to infinity, so we are allowed to use\r\nL'H\\^opital's Rule again:\r\n$$\\lim_{x\\to \\infty}\\frac{4x-3}{2x+47}=\\lim_{x\\to \\infty}\\frac{4}{2}=2.$$\r\nSo the original limit is 2 as well.\r\n\\end{solution}\r\n\r\n\\begin{example} {L'H\\^opital's Rule}{LHRule2}\r\nCompute $\\ds\\lim_{x\\to 0}\\frac{\\sec x - 1}{\\sin x}$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nBoth the numerator and denominator approach zero, so applying \r\nL'H\\^opital's Rule:\r\n$$\\lim_{x\\to 0}\\frac{\\sec x - 1}{\\sin x}=\r\n\\lim_{x\\to 0}\\frac{\\sec x\\tan x}{\\cos x}=\\frac{1\\cdot 0}{1}=0.$$\r\n\\end{solution}\r\n\r\nL'H\\^{o}pital's rule concerns limits of a quotient that are indeterminate forms. But not all\r\nfunctions are given in the form of a quotient. But all the same, nothing\r\nprevents us from re-writing a given function in the form of a quotient.\r\nIndeed, some functions whose given form involve either a product $f\\left(\r\nx\\right) g\\left( x\\right) $ or a power $f\\left( x\\right) ^{g\\left( x\\right)\r\n} $ carry indeterminacies such as $0\\cdot \\pm \\infty $ and $1^{\\pm \\infty }.$\r\nSomething small times something numerically large (positive or negative)\r\ncould be anything. It depends on how small and how large each piece turns\r\nout to be. A number close to 1 raised to a numerically large (positive or\r\nnegative) power could be anything. It depends on how close to 1 the base is,\r\nwhether the base is larger than or smaller than 1, and how large the\r\nexponent is (and its sign). We can use suitable algebraic manipulations to\r\nrelate them to indeterminate quotients. We will illustrate with two\r\nexamples, first a product and then a power.\r\n\r\n\\begin{example}{L'H\\^opital's Rule}{LHRule3}\r\nCompute $\\ds\\lim_{x\\to 0^+} x\\ln x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThis doesn't appear to be suitable for L'H\\^opital's Rule, but it also\r\nis not ``obvious''. As $x$ approaches zero, $\\ln x$ goes to $-\\infty$,\r\nso the product looks like:\r\n$$(\\hbox{something very small})\\cdot(\\hbox{something very large and negative}).$$\r\nThis could be anything: it depends on {\\it how small} and\r\n{\\it how large} each piece of the function turns out to be. \r\nAs defined earlier, this is a type of $\\pm\\mathquotes{0\\cdot\\infty}$, which is\r\nindeterminate. So we can in fact apply L'H\\^opital's Rule after re-writing\r\nit in the form $\\frac{\\infty }{\\infty }$:\r\n$$x\\ln x = \\frac{\\ln x}{1/x}=\\frac{\\ln x}{x^{-1}}.$$\r\nNow as $x$ approaches zero, both the numerator and denominator\r\napproach infinity (one $-\\infty$ and one $+\\infty$, but only the size\r\nis important). Using  L'H\\^opital's Rule:\r\n$$\\lim_{x\\to 0^+} {\\ln x\\over x^{-1}}=\r\n\\lim_{x\\to 0^+} {1/x\\over -x^{-2}} =\\lim_{x\\to 0^+} {1\\over x}(-x^2)=\r\n\\lim_{x\\to 0^+} -x = 0.$$\r\nOne way to interpret this is that since $\\ds\\lim_{x\\to\r\n  0^+}x\\ln x = 0$, the $x$ approaches zero much faster than the $\\ln x$\r\napproaches $-\\infty$.\r\n\\end{solution}\r\n\r\nFinally, we illustrate how a limit of the type $\\mathquotes{1^\\infty}$ can be indeterminate.\r\n\r\n\\begin{example} {L'H\\^opital's Rule}{LHRule4}\r\nEvaluate $\\ds{\\lim_{x\\to 1^+}x^{1/(x-1)}}.$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nPlugging in $x=1$ (from the right) gives a limit of the type $\\mathquotes{1^\\infty}$.\r\nTo deal with this type of limit we will use logarithms.\r\nLet\r\n$$L=\\lim_{x\\to 1^+}x^{1/(x-1)}.$$\r\nNow, take the natural log of both sides:\r\n$$\\ln L=\\lim_{x\\to 1^+}\\ln\\left(x^{1/(x-1)}\\right).$$\r\nUsing log properties we have:\r\n$$\\ln L=\\lim_{x\\to 1^+}\\frac{\\ln x}{x-1}.$$\r\nThe right side limit is now of the type $0/0$, therefore, we can apply L'H\\^opital's Rule:\r\n$$\\ln L=\\lim_{x\\to 1^+}\\frac{\\ln x}{x-1}=\\lim_{x\\to 1^+}\\frac{1/x}{1}=1$$\r\nThus, $\\ln L=1$ and hence, our original limit (denoted by $L$) is: $L=e^1=e$. That is,\r\n$$L=\\lim_{x\\to 1^+}x^{1/(x-1)}=e.$$\r\nIn this case, even though our limit had a type of $\\mathquotes{1^\\infty}$, it actually had a value of $e$.\r\n\\end{solution}\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:LH}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\nCompute the following limits.\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds\\lim_{x\\to 0} {\\cos x -1\\over \\sin x}$\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\\lim_{x\\to \\infty} {e^x\\over x^3}$\r\n\\begin{sol}\r\n $\\infty$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds\\lim_{x\\to \\infty} {\\ln x\\over x}$\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\\lim_{x\\to \\infty} {\\ln x\\over \\sqrt{x}}$\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\\lim_{x\\to0}{\\sqrt{9+x}-3\\over x}$\r\n\\begin{sol}\r\n $1/6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n$\\ds\\lim_{x\\to2}{2-\\sqrt{x+2}\\over 4-x^2}$\r\n\\begin{sol}\r\n $1/16$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to1}{\\sqrt{x}-1\\over \\root 1/3\\of{x}-1}$\r\n\\begin{sol}\r\n $3/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{(1-x)^{1/4}-1\\over x}$\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\\lim_{t\\to 0}{\\left(t+{1\\over t}\\right)((4-t)^{3/2}-8)}$\r\n\\begin{sol}\r\n $-3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{t\\to 0^+}\\left({1\\over t}+{1\\over\\sqrt{t}}\\right)\r\n(\\sqrt{t+1}-1)$\r\n\\begin{sol}\r\n $1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to 0}{x^2\\over\\sqrt{2x+1}-1}$\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\\lim_{u\\to 1}{(u-1)^3\\over (1/u)-u^2+3/u-3}$\r\n\\begin{sol}\r\n $-1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to 0}{2+(1/x)\\over 3-(2/x)}$\r\n\\begin{sol}\r\n $-1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to 0^+}{1+5/\\sqrt{x}\\over 2+1/\\sqrt{x}}$\r\n\\begin{sol}\r\n $5$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to\\pi/2}{\\cos x\\over (\\pi/2)-x}$\r\n\\begin{sol}\r\n $1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{e^x-1\\over x}$\r\n\\begin{sol}\r\n $1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{x^2\\over e^x-x-1}$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to1}{\\ln x\\over x-1}$\r\n\\begin{sol}\r\n $1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{\\ln(x^2+1)\\over x}$\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\\lim_{x\\to1}{x\\ln x\\over x^2-1}$\r\n\\begin{sol}\r\n $1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{\\sin(2x)\\over\\ln(x+1)}$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to1}{x^{1/4}-1\\over x}$\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\\lim_{x\\to1}{\\sqrt{x}-1\\over x-1}$\r\n\\begin{sol}\r\n $1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{3x^2+x+2\\over x-4}$\r\n\\begin{sol}\r\n $-1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{\\sqrt{x+1}-1\\over \\sqrt{x+4}-2}$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{\\sqrt{x+1}-1\\over \\sqrt{x+2}-2}$\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\\lim_{x\\to0^+}{\\sqrt{x+1}+1\\over\\sqrt{x+1}-1}$\r\n\\begin{sol}\r\n $\\infty$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to0}{\\sqrt{x^2+1}-1\\over\\sqrt{x+1}-1}$\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\\lim_{x\\to1}{(x+5)\\left({1\\over 2x}+{1\\over x+2}\\right)}$\r\n\\begin{sol}\r\n $5$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex} \r\n $\\ds\\lim_{x\\to2}{x^3-6x-2\\over x^3+4}$\r\n\\begin{sol}\r\n $-1/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex}\r\nDiscuss what happens if we try to use L'H\\^{o}pital's rule to find the limit $\\lim\\limits_{x\\rightarrow \\infty}\\dfrac{x+\\sin x}{x+1}$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n", "meta": {"hexsha": "28e8a57d74b73c89b39caef363a7db6aa6399237", "size": 10437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-5-Lhospitals-rule.old.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-5-Lhospitals-rule.old.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-5-Lhospitals-rule.old.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.7615384615, "max_line_length": 359, "alphanum_fraction": 0.5991185206, "num_tokens": 4008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.9099070029841949, "lm_q1q2_score": 0.7856060818281312}}
{"text": "\\documentclass{amsart}\n\n\\title{Abstract Data Types}\n\\author{Todd D. Vance}\n\\date{\\today}\n\n\\begin{document}\n\\maketitle{}\n\n\\section{Abstract Data Type}\nOne method for designing classes in an object-oriented fashion is via an \\emph{abstract data type}.  The various abstract data types can be defined formally or semi-formally, or in a casual language.  There are benefits to each of the various levels of formality.  The author proposes an axiomatic approach (similar to Nell/Walker (http://dl.acm.org/citation.cfm?id=230973), though perhaps less formally; see also Liskov/Zilles 1974, Programming with Abstract Data Types) as a way of accurately communicating the specification of a class as well as unit tests.  This approach to abstract data types can be thought of as being to the design of a system as ``test driven development'' is to the writing of the programs for a system.\n\n\n\\section{Set}\nThe ADT $\\mathbf{set}$ can be specified by the following operations and axioms.  We assume another type $\\mathbf{E}$ representing the type of the elements of the set.  This specifies an immutable set, where elements are added or removed by returning a new set.  Here are the supported operations:\n\n\\begin{enumerate}\n\\item $\\mathrm{empty}:\\emptyset\\rightarrow\\mathbf{set}$.\n\\item $\\mathrm{size}:\\mathbf{set}\\rightarrow\\mathbf{N}$ (where $\\mathbf{N}$ represents nonnegative integers).\n\\item $\\mathrm{contains}:\\mathbf{set}\\times\\mathbf{E}\\rightarrow\\mathbf{bool}$ (where $\\mathbf{bool}=\\{\\mathrm{true},\\mathrm{false}\\}$ represents the Boolean type).\n\\item $\\mathrm{add}:\\mathbf{set}\\times\\mathbf{E}\\rightarrow\\mathbf{set}$\n\\item $\\mathrm{remove}:\\mathbf{set}\\times\\mathbf{E}\\rightarrow\\mathbf{set}$\n\\end{enumerate}\n\nInformally, $\\mathrm{empy}$ is a nullary operation, that is, a constant.  It represents the empty set.  The $\\mathrm{size}$ operation applied to any set returns the number of elements.  The $\\mathrm{contains}$ operation applied to a set and an element returns $\\mathrm{true}$ if the element is in the set.  Otherwise, it returns $\\mathrm{false}$.  The $\\mathrm{add}$ operation applied to a set and an element returns the set whose elements are the elements of the specified set along with the specified element.  The $\\mathrm{remove}$ operation applied to a set and an element returns the set whose elements are the elements of the specified set except for the specified element.\n\nThe axioms specifying the behavior of the operations are as follows:\n\n\\begin{enumerate}\n\\item $\\mathrm{size}(\\mathrm{empty})=0$\n\\item if $\\mathrm{contains}(s, e)=\\mathrm{false}$, then $\\mathrm{size}(\\mathrm{add}(s, e)) = \\mathrm{size}(s) + 1$\n\\item if $\\mathrm{contains}(s, e)=\\mathrm{true}$, then $\\mathrm{add}(s, e) = s$\n\\item if $\\mathrm{contains}(s, e)=\\mathrm{true}$, then $\\mathrm{size}(\\mathrm{remove}(s, e)) = \\mathrm{size}(s) - 1$\n\\item if $\\mathrm{contains}(s, e)=\\mathrm{false}$, then $\\mathrm{remove}(s, e) = s$\n\\item $\\mathrm{contains}(empty, e) = \\mathrm{false}$\n\\item $\\mathrm{contains}(\\mathrm{add}(s, e), e)=\\mathrm{true}$\n\\item If $e\\ne{f}$, then $\\mathrm{contains}(\\mathrm{add}(s, e), f)=\\mathrm{contains}(s,f)$\n\\item $\\mathrm{contains}(\\mathrm{remove}(s, e), e)=\\mathrm{false}$\n\\item If $e\\ne{f}$, then $\\mathrm{contains}(\\mathrm{remove}(s, e), f)=\\mathrm{contains}(s,f)$\n\\end{enumerate}\n\n\nOne could specify a mutable version of $\\mathbf{set}$ as a structure having just one modifiable attribute: the immutable set.  Thus, we have something like $s$, such that $s.\\mathrm{set}$ is a $\\mathbf{set}$.  We can modify $s$: $s.\\mathrm{set} \\leftarrow t$ where $t$ is some $\\mathbf{set}$.\n\nInstead of $\\mathrm{empty}$ is $\\mathrm{new~\\mathbf{set}}$ which is a structure whose attribute is equal to $\\mathrm{empty}$.    So, $s\\leftarrow \\mathrm{new~\\mathbf{set}}$ causes $s.\\mathrm{set}$ to equal $\\mathrm{empty}$.\n\nThe $\\mathrm{add}$ operation then modifies $s$ as follows: $\\mathrm{add}(s, e)$ performs the operation $s.\\mathrm{set}\\leftarrow \\mathrm{add}(\\mathrm{set}, e)$.\n\nSimilarly, the $\\mathrm{remove}$ operation modifies $s$ as follows: $\\mathrm{remove}(s, e)$ performs the operation $s.\\mathrm{set}\\leftarrow \\mathrm{remove}(\\mathrm{set}, e)$.\n\nThe remaining operations just operate directly on $s.\\mathrm{set}$.  So, $\\mathrm{contains}(s, e)$ is equal to $\\mathrm{contains}(s.\\mathrm{set}, e)$, and likewise for the other operations.\n\nThe analogous scheme can be used to turn any immutable ADT having operations that return different instances of the ADT into a corresponding mutable ADT.\n\n\n\n\\end{document}\n", "meta": {"hexsha": "4cf3cf53ca32dff6ad0a26a4bd112ba2e64605ce", "size": 4523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "adt.tex", "max_stars_repo_name": "tdvance/AbstractDataTypes", "max_stars_repo_head_hexsha": "7d158a0d7177fdc262e689f217b66b921e32dd5b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "adt.tex", "max_issues_repo_name": "tdvance/AbstractDataTypes", "max_issues_repo_head_hexsha": "7d158a0d7177fdc262e689f217b66b921e32dd5b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "adt.tex", "max_forks_repo_name": "tdvance/AbstractDataTypes", "max_forks_repo_head_hexsha": "7d158a0d7177fdc262e689f217b66b921e32dd5b", "max_forks_repo_licenses": ["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.9827586207, "max_line_length": 730, "alphanum_fraction": 0.7287198762, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.863391617003942, "lm_q1q2_score": 0.7856060791570689}}
{"text": "\\section{Estimating with Sums}\r\nIf we know how something changes, we can use sums to estimate, or sometimes even know exactly the net change.\r\n\r\n\\begin{example}\r\n\tA train moves at 80 miles per hour for 3 hours.\r\n\tHow far does it travel?\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis is the kind of simple problem you might see in a physics class.\r\n\t\\begin{equation*}\r\n\t\t\\frac{80\\text{mi}}{\\text{hr}} \\hspace{3pt} 3\\text{hr} = 80\\cdot 3\\text{mi} = 240 \\text{mi}.\r\n\t\\end{equation*}\r\n\tHowever, if we take a look at a graph of this situation, with speed in miles per hour on the $y$ axis and time in hours on the $x$ axis, we see that the area underneath the curve from $x=0\\text{hr}$ to $x=3\\text{hr}$ is exactly our answer of 240 miles.\r\n\tThis is not a coincidence, as what we effectively did mathematically is find the area of this rectangle.\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{constant_graph}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width = 0.33\\textwidth]{./integrals/constant_graph.png}\r\n\t\t\\caption{\\hyperref{}{}{}{Our answer is the area under the curve.}}\r\n\t\\end{figure}\r\n\t\\end{answer}\r\n\r\nThe same idea of finding the area under the curve works not just for constant speeds.\r\n\\begin{example}\r\n\tA particle moves at velocity $v(t) = 3t + 3$ meters per second for time $t \\geq 0$.\r\n\tWhat is the position of the particle at $t = 2$ seconds?\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{figure}[H]\r\n\t\t\\label{linear_graph}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width = 0.5\\textwidth]{./integrals/linear_graph.png}\r\n\t\t\\caption{\\hyperref{}{}{}{Our answer is still the area under the curve.}}\r\n\t\\end{figure}\r\n\t\\begin{align*}\r\n\t\tA &= \\frac{1}{2}h(b_1 + b_2) \\\\\r\n\t\t&= \\frac{1}{2}(2\\text{s}-0\\text{s})(v(0) + v(2)) \\\\\r\n\t\t&= \\frac{1}{2}(2\\text{s})(3\\text{m/s} + 9\\text{m/s}) \\\\\r\n\t\t&= 12\\text{m}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Left Endpoint Approximation}\r\nIn fact, the area under the curve even works for more complicated, non-linear curves like $v(t) = t^2 + 1$.\r\nWe just need a way to find the area underneath these curves.\r\nOne idea that was used to find areas as far back as Archimedes was to estimate the complex shape using easier shapes like rectangles.\r\nThe narrower the width of each rectangle, the better the estimate becomes.\r\n \r\n\\begin{figure}[H]\r\n\t\\label{cos_blocks}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.3\\textwidth]{./integrals/cos_blocks1.png}\r\n\t\\includegraphics[width = 0.3\\textwidth]{./integrals/cos_blocks2.png}\r\n\t\\includegraphics[width = 0.3\\textwidth]{./integrals/cos_blocks3.png}\r\n\t\\caption{\\hyperref{}{}{}{Left Endpoint: Block widths of 1/3, 1/10, and 1/100.}}\r\n\\end{figure}\r\n\r\n\r\nAlthough above we've used a left endpoint approximation, we could have also used the right endpoint or midpoint, which might give better approximations for certain types of curves.\r\nNo matter the approximation type, the estimate tends to get closer to the true area as the rectangle width is decreased.\r\nThe formulas for estimating the area of $f$ from $a$ to $b$ with $n$ rectangles are\r\n\\begin{align*}\r\n\tA_\\text{left} &= \\sum_{k=0}^{n-1}{f\\left(a+k\\Delta x\\right)\\Delta x} \\\\\r\n\tA_\\text{right} &= \\sum_{k=0}^{n-1}{f\\left(a+(k+1)\\Delta x\\right)\\Delta x} \\\\\r\n\tA_\\text{mid} &= \\sum_{k=0}^{n-1}{f\\left(a+\\frac{2k+1}{2}\\Delta x\\right)\\Delta x} \\\\\r\n\t\\text{where }\\Delta x &= \\frac{b-a}{n}.\r\n\\end{align*}\r\n\r\n\\subsubsection{Trapezoidal Rule}\r\nAnother common shape to use rather than rectangles is trapezoids.\r\nTrapezoids allow us to find the exact area of functions made of straight lines\\footnote{There are higher-order, more accurate estimations than the trapezoidal rule. The most common is Simpson's Rule. $A = \\frac{2M+T}{3}$ where $M$ is the midpoint formula area and $T$ is the trapezoidal rule area. It can exactly give the area of quadratics because it corresponds to estimating areas using parabolas that intersect the curve at the left, middle, and right of each ``strip''.} and like the left endpoint approximation, get better the narrower the width of each trapezoid.\r\nStarting from the formula, we can make some simplifications.\r\n\\begin{equation*}\r\n\tA = \\frac{1}{2}(b_1 + b_2)h.\r\n\\end{equation*}\r\nNow summing each of these trapezoids' areas to approximate our function $f$ from $a$ to $b$,\r\n\\begin{align*}\r\n\tA_\\text{trap} &= \\sum_{k=0}^{n-1}{\\frac{1}{2}\\left(f(a+i\\Delta a) + f(a + (i+1)\\Delta x)\\right)\\Delta x} \\\\\r\n\t&= \\frac{\\Delta x}{2}\\sum_{k=0}^{n-1}{f(a + i\\Delta x) + f(a + (i+1)\\Delta x)} \\\\\r\n\t&= \\frac{\\Delta x}{2}\\left(\\left(f(a)+f(a+\\Delta x)\\right)+\\left(f(a+\\Delta x)+f(a+2\\Delta x)\\right)+\\ldots+\\left(f(a+(n-1)\\Delta x)+f(a+n\\Delta x)\\right)\\right) \\\\\r\n\t&= \\frac{\\Delta x}{2}\\left(f(a) + 2f(a+\\Delta x) + 2f(a + 2\\Delta x) + \\ldots + 2f(a+(n-1)\\Delta x) + f(a+n\\Delta x)\\right) \\\\\r\n\t&= \\frac{A_\\text{left} + A_\\text{right}}{2}.\r\n\\end{align*}\r\n\r\nThe trapezoidal rule overestimates areas when the curve is concave up and underestimates when the curve is concave down.", "meta": {"hexsha": "4d8a91820ef89496dae71a1295700f84082088f3", "size": 4876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/integrals/estimating_with_sums.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/integrals/estimating_with_sums.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/integrals/estimating_with_sums.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.6976744186, "max_line_length": 571, "alphanum_fraction": 0.6931911403, "num_tokens": 1584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.9005297841157157, "lm_q1q2_score": 0.7855747929928792}}
{"text": "\\section{The Jordan Normal Form}\r\nWe are interested in how nice a matrix can an arbitrary $\\alpha\\in L(\\mathbb C^n)$ possibly have.\r\n\\begin{definition}\r\n    Let $A\\in M_n(\\mathbb C)$.\r\n    We say $A$ is in Jordan Normal Form (JNF) if it is a block diagonal matrix\r\n    $$A=\\begin{pmatrix}\r\n        J_{n_1}(\\lambda_1)&&&\\\\\r\n        &J_{n_2}(\\lambda_2)&&\\\\\r\n        &&\\ddots&\\\\\r\n        &&&J_{n_k}(\\lambda_k)\r\n    \\end{pmatrix}$$\r\n    for $\\{\\lambda_i\\}\\in\\mathbb C$ not necessarily distinct, $\\sum_in_i=n$ and $J_r(\\lambda)\\in M_r(\\mathbb C)$ are Jordan blocks of the form\r\n    $$J_r(\\lambda)=\\begin{pmatrix}\r\n        \\lambda&1&&\\\\\r\n        &\\ddots&\\ddots&\\\\\r\n        &&\\lambda&1\\\\\r\n        &&&\\lambda\r\n    \\end{pmatrix}$$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Every matrix $A\\in M_n(\\mathbb C)$ is similar to a matrix in JNF which is unique up to reordering the Jordan blocks.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\n\\begin{example}\r\n    For $n=2$, the possible JNFs are simply ($\\lambda,\\lambda_1,\\lambda_2\\in F,\\lambda_1\\neq\\lambda_2$)\r\n    $$\\begin{pmatrix}\r\n        \\lambda_1&0\\\\\r\n        0&\\lambda_2\r\n    \\end{pmatrix},\\begin{pmatrix}\r\n        \\lambda&0\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix},\\begin{pmatrix}\r\n        \\lambda&1\\\\\r\n        0&\\lambda\r\n    \\end{pmatrix}$$\r\n    with minimal polynomials $(t-\\lambda_1)(t-\\lambda_2),t-\\lambda,(t-\\lambda)^2$ respectively.\\\\\r\n    For $n=3$, the JNFs (and their respective minimal polynomials) are, up to reordering of the blocks, ($\\lambda,\\lambda_1,\\lambda_2,\\lambda_3\\in F$, $\\lambda_1,\\lambda_2,\\lambda_3$ all distinct)\r\n    $$\\begin{pmatrix}\r\n        \\lambda_1&&\\\\\r\n        &\\lambda_2&\\\\\r\n        &&\\lambda_3\r\n    \\end{pmatrix}:(t-\\lambda_1)(t-\\lambda_2)(t-\\lambda_3);\\begin{pmatrix}\r\n        \\lambda_1&&\\\\\r\n        &\\lambda_2&\\\\\r\n        &&\\lambda_2\r\n    \\end{pmatrix}:(t-\\lambda_1)(t-\\lambda_2)$$\r\n    $$\\begin{pmatrix}\r\n        \\lambda_1&&\\\\\r\n        &\\lambda_2&1\\\\\r\n        &&\\lambda_2\r\n    \\end{pmatrix}:(t-\\lambda_1)(t-\\lambda_2)^2;\\begin{pmatrix}\r\n        \\lambda&&\\\\\r\n        &\\lambda&\\\\\r\n        &&\\lambda\r\n    \\end{pmatrix}:(t-\\lambda)$$\r\n    $$\\begin{pmatrix}\r\n        \\lambda&&\\\\\r\n        &\\lambda&1\\\\\r\n        &&\\lambda\r\n    \\end{pmatrix}:(t-\\lambda)^2;\\begin{pmatrix}\r\n        \\lambda&1&\\\\\r\n        &\\lambda&1\\\\\r\n        &&\\lambda\r\n    \\end{pmatrix}:(t-\\lambda)^3$$\r\n\\end{example}\r\n\\begin{theorem}[Generalised Eigenspace Decomposition]\r\n    Let $V$ be a finite dimensional vector space over $\\mathbb C$ and $\\alpha\\in L(V)$.\r\n    Let $\\lambda+_1,\\ldots,\\lambda_k$ be distinct eigenvalues of $\\alpha$ such that $m_\\alpha(t)=(t-\\lambda_1)^{c_1}\\cdots(t-\\lambda_k)^{c_k}$, then\r\n    $$V=\\bigoplus_{i=1}^kV_j,V_j=\\ker((\\alpha-\\lambda_j\\operatorname{id})^{c_j})$$\r\n\\end{theorem}\r\nHere $V_j$ is called the generalised eigenspace.\r\n\\begin{remark}\r\n    When $\\alpha$ is diagonalisable, then $c_j=1$ for all $j$, consequently $V=\\bigoplus_j\\ker(\\alpha-\\lambda_j\\operatorname{id})$ as we already know.\r\n\\end{remark}\r\n\\begin{proof}\r\n    Define $p_j(t)=\\prod_{i\\neq j}(t-\\lambda_i)^{c_i}$, then $\\{p_j\\}$ has no common factor, so we can find $q_1,\\ldots,q_k$ such that $q_1p_1+\\cdots+q_kp_k=1$.\r\n    Define $\\pi_j=q_jp_j(\\alpha)$, then it follows that $\\sum_j\\pi_j=\\operatorname{id}$.\r\n    Also $(\\alpha-\\lambda_j\\operatorname{id})^{c_j}\\pi_j=0$, so $\\operatorname{Im}\\pi_j\\subset V_j$, hence $V$ is the sum of all $V_j$.\r\n    To see this sum is direct, simply observe that $\\pi_i\\pi_j=\\delta_{ij}\\pi_i$ for all $i,j$, so $\\pi_i|_{V_j}=\\delta_{ij}\\operatorname{id}$.\r\n    This completes the proof.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. This decomposition allows us to reduce the proof of JNF to just one eigenvalue, which can be done via the study of nilpotent matrices.\r\n    \\footnote{That is if you want to do it the linear algebra way -- I like the $\\mathbb C[X]$-module approach more.}\r\n    The relation is found from the observation\r\n    $$(J_m(\\lambda)-\\lambda\\operatorname{id})^k=\\begin{cases}\r\n        \\begin{pmatrix}\r\n            0&I_{m-k}\\\\\r\n            0&0\r\n        \\end{pmatrix}\\text{, if $k<m$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    2. We can very easily compute $a_\\lambda,g_\\lambda$ and $c_\\lambda$ if we know the JNF.\r\n    Indeed, $a_\\lambda$ is the sum of sizes if the blocks with eigenvalue $\\lambda$, $g_\\lambda$ is the number of Jordan blocks with eigenvalue $\\lambda$ and $c_\\lambda$ is the size of the largest Jordan block with eigenvalue $\\lambda$.\r\n    This can (sometimes) be used to compute the JNF as well.\r\n\\end{remark}\r\n\\begin{example}\r\n    Take\r\n    $$A=\\begin{pmatrix}\r\n        0&-1\\\\\r\n        1&2\r\n    \\end{pmatrix}$$\r\n    We want to find a basis in which $A$ is in JNF.\r\n    Now $\\chi_A(t)=m_A(t)=(t-1)^2$, so the JNF is in the form\r\n    $$\\begin{pmatrix}\r\n        1&1\\\\\r\n        0&1\r\n    \\end{pmatrix}$$\r\n    We want the basis, which naturally consists of eigenvectors.\r\n    Indeed, $\\ker(A-\\operatorname{id})$ is spanned by $(1,-1)^\\top$.\r\n    Choose $v_2$ such that $(A-\\operatorname{id})v_2=v_1$, which is nonunique but we can take $v_2=(-1,0)^\\top$.\r\n    So take the basis $\\{v_1,v_2\\}$ works.\r\n    To put it concretely,\r\n    $$A=\\begin{pmatrix}\r\n        1&-1\\\\\r\n        -1&0\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        1&1\\\\\r\n        0&1\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        1&-1\\\\\r\n        -1&0\r\n    \\end{pmatrix}^{-1}$$\r\n\\end{example}", "meta": {"hexsha": "600b87a09739d5b6a9d518ddf4141547bb2bc4d6", "size": 5372, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "17/jordan.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": "17/jordan.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": "17/jordan.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.6349206349, "max_line_length": 237, "alphanum_fraction": 0.5986597171, "num_tokens": 1833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.9005297754396142, "lm_q1q2_score": 0.7855747794471102}}
{"text": "\n\\section{Brownian Motion}\n\n\\problem{Brownian Motion. Finite-dimensional distributions.} \nLet $0=s_0 < s_1 < \\cdots < s_n$ be positive real numbers and $(B_{s_{1}},\\dots ,B_{s_n})$ \nbe a $n$-dimensional random vector with density given by\n\\begin{equation*}\n    f(y_1,\\dots ,y_n) = p(s_1, y_1, 0)p(s_2-s_1,y_2, y_1)\\dots p(s_n-s_{n-1}, y_n, y_{n-1})\n\\end{equation*}\nwith \n\\begin{equation*}\n    p(t, x,y ) = \\frac{1}{\\sqrt{2\\pi t}} \\exp(-\\frac{(x-y)^2}{2t}). \n\\end{equation*}\nShow that:\n\\begin{enumerate}\n    \\item The random variables $(B_{s_1}, B_{s_2}-B_{s_1},\\dots ,B_{s_n}-B_{s_{n-1}})$ \n        are independent.\n    \\item The distribution of $B_{s_i}-B_{s_{i-1}}$ is $\\cN(0, s_{i}-s_{i-1})$.\n\\end{enumerate}\n\n\\solution Use Jacobi's transformation formula with\n$g:\\bR^{n}\\to\\bR^{n}, (y_1,\\dots ,y_n)\\mapsto(y_1, y_2-y_1,\\dots\n,y_n-y_{n-1})$. \n\n\\problem{Maximum processes of the Brownian Motion. } Show that the process $W\n- W^*$ has independent increments. $W$ denotes Brownian Motion and $X^*_t=\n\\max_{0 \\leq s \\leq t} X_s$ is the maximum process of a c\\`adl\\`ag process $X$.\n\n\\problem{Independence and transformations. } Let random variables\n$X_1,\\ldots,X_n$ and $Y_1,\\ldots,Y_k$ satisfy $X_i \\upmodels Y_j$ for all $i$\nand $i$.\n\\begin{enumerate}\n    \\item It follows that $g(X_i)$ and $h(Y_j)$ are independent for any $i$ and\n        $j$.\n    \\item A generalization of the above result is not true. Given any Borel\n        functions $f$ and $g$ of suitable dimensionality $f(X_1,\\ldots,X_n)$\n        may be not independent of $g(Y_1,\\ldots,Y_k)$.\n\\end{enumerate}\n\n\n\n", "meta": {"hexsha": "12481ab84e4871d1cc8f2b79bb89ddc201a8e10d", "size": 1572, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "example/problem-db2.tex", "max_stars_repo_name": "jwergieluk/problem-extractor", "max_stars_repo_head_hexsha": "f72f88eb189c5ad812825301244697464c9599fa", "max_stars_repo_licenses": ["CNRI-Python"], "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/problem-db2.tex", "max_issues_repo_name": "jwergieluk/problem-extractor", "max_issues_repo_head_hexsha": "f72f88eb189c5ad812825301244697464c9599fa", "max_issues_repo_licenses": ["CNRI-Python"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2015-02-02T16:12:42.000Z", "max_issues_repo_issues_event_max_datetime": "2015-02-02T16:40:39.000Z", "max_forks_repo_path": "example/problem-db2.tex", "max_forks_repo_name": "jwergieluk/problem-extractor", "max_forks_repo_head_hexsha": "f72f88eb189c5ad812825301244697464c9599fa", "max_forks_repo_licenses": ["CNRI-Python"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4285714286, "max_line_length": 91, "alphanum_fraction": 0.6577608142, "num_tokens": 592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.785504562308373}}
{"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\nLet $ G $ be the context-free grammar $G = (\\{S,X_1,X_2,X_3\\},\\{a,b,c\\},S,P)$.\nConstruct an equivalent grammar in Chomsky's normal form if\n\n\\begin{equation}\n\\begin{aligned}\nP =\\ & \\{ S\\rightarrow X_1 X_2 X_3 X_1,\\ S\\rightarrow X_1 a X_2,\\ X_1 \\rightarrow X_1 X_2 X_3,\\\\\n& X_1 \\rightarrow a, X_2 \\rightarrow X_3 X_1, X_2 \\rightarrow b, X_3 \\rightarrow c\\}\n\\end{aligned}\n\\end{equation}\n\n\\subsection*{Solution}\n\nA Context-free grammar is in \\textit{Chomsky Normal Form} if all its productions are either of the form $X\\rightarrow YZ$ or of the form $X\\rightarrow a$ where $X,Y,Z \\in A_N$ and $a\\in A_T$.\nBy introducing the non-terminal symbol $X_a$ to $G$ we obtain\n\n\\begin{equation}\nG_1 = (\\{S, X_1, X_2, X_3, X_a\\},\\{a, b, c\\},S,P_1)\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n\\begin{aligned}\nP_1 =\\ & \\{ S\\rightarrow X_1 X_2 X_3 X_1,\\ S\\rightarrow X_1 X_a X_2,\\ X_1 \\rightarrow X_1 X_2 X_3,\\ X_2 \\rightarrow X_3 X_1,\\\\\n& X_1 \\rightarrow a,\\ X_2 \\rightarrow b,\\ X_3 \\rightarrow c,\\ X_a \\rightarrow a\\}\n\\end{aligned}\n\\end{equation}\n\nAlthough $G_1$ has no chain productions and every production in $G_1$ that contains a terminal symbol is of the form $X\\rightarrow a$, three productions $S\\rightarrow X_1 X_2 X_3 X_1$, $S\\rightarrow X_1 X_a X_2$ and $X_1 \\rightarrow X_1 X_2 X_3$ violate Chomsky Normal form.\nThus, $Z_0$, $Z_1$, $Z_2$ are introduced as new non-terminal symbols.\nA new equivalent grammar $G_2$ can be obtained as\n\n\\begin{equation}\nG_2 = (\\{S, X_1, X_2, X_3, X_a, Z_0, Z_1, Z_2\\},\\{a, b, c\\},S,P_2)\n\\end{equation}\n\nwhere\n\n\\begin{equation}\n\\begin{aligned}\nP_2 =\\ & \\{ X_2 \\rightarrow X_3 X_1,\\ X_1 \\rightarrow a,\\ X_2 \\rightarrow b,\\ X_3 \\rightarrow c,\\ X_a \\rightarrow a, \\\\\n& S\\rightarrow Z_0X_1,\\ S\\rightarrow X_1Z_2,\\ X_1\\rightarrow Z_1X_3, \\\\\n& Z_0\\rightarrow Z_1X_3,\\ Z_1\\rightarrow X_1X_2,\\ Z_2\\rightarrow X_aX_2 \\}\n\\end{aligned}\n\\end{equation}\n\nwhere all productions in $G_2$ follow conditions of a grammar in Chomsky Normal form.\n", "meta": {"hexsha": "7b8c73be1d1530ccafe0caf6499f5c1452aecc62", "size": 2329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q04.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q04.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw03/hw03q04.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.8596491228, "max_line_length": 274, "alphanum_fraction": 0.6728209532, "num_tokens": 845, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110339361276, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.7855045597756845}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Order statistics}\\label{sec:orderstats}\n\n% defn: quantile\n\\begin{definition}\nLet $X$ be a continuous random variable and let $F(x)$ denote its CDF. For $p\\in[0,1]$, the \\emph{$p$th quantile} of the distribution is the value $x_p = F^{-1}(p)$, i.e.\\ the value $x_p\\in\\R$ for which\n\\[\n\\prob(X\\leq x_p) = p \\qquad\\text{for $p\\in[0,1]$.}\n\\]\nIn particular, \n\\bit\n\\it $x_{0.5}$ is the \\emph{median} of the distribution,\n\\it $x_{0.25}$ is the \\emph{lower quartile},\n\\it $x_{0.75}$ is the \\emph{upper quartile},\n\\it $x_{0.75}-x_{0.25}$ is the \\emph{inter-quartile range}.\n\\eit\n\\end{definition}\n\n% remark: location and scale\n\\begin{remark}\nAs we shall see, the median and inter-quartile range represent \\emph{location} and \\emph{scale} respectively.\n\\end{remark}\n\n\\begin{example}\nFind the median and inter-quartile range of the $\\text{Exponential}(\\lambda)$ distribution, where $\\lambda>0$ is a rate parameter. \n\\begin{solution}\nLet $X\\sim\\text{Exponential}(\\lambda)$. Then $F(x) = 1 - e^{-\\lambda x}$, so\n\\[\nx_p = F^{-1}(p) = -\\frac{1}{\\lambda}\\log(1-p).\n\\]\nThus the median is $\\log(2)/\\lambda$ and the inter-quartile range is $\\log(3)/\\lambda$.\n\\end{solution}\n\\end{example}\n\n%-----------------------------\n\\subsection{Order statistics}\nThe quantiles of a distribution can be estimated using the \\emph{order statistics} of a random sample.\n\n%\\begin{definition}\n%Let $X_1,X_2,\\ldots,X_n$ be a random sample from an unknown distribution, let $X_{(1)}$ denote the smallest observation, let $X_{(2)}$ denote the second-smallest observation, and so on: \n%\\[\n%X_{(1)} \\leq X_{(2)} \\leq \\ldots \\leq X_{(n)}.\n%\\]\n%$X_{(1)},X_{(2)},\\ldots,X_{(n)}$ are called the \\emph{order statistics} of the random sample $X_1,X_2,\\ldots,X_n$.\n%\\end{definition}\n\n\\begin{definition}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from an unknown distribution. The \\emph{order statistic of rank $k$} is the $k$th smallest observation in the sample and denoted by $X_{(k)}$.\n\\end{definition}\n\nCertain functions of the order statistics $X_{(1)},X_{(2)},\\ldots,X_{(n)}$ are important statistics in their own right:\n\\bit\n\\it $X_{(1)}$ is the \\emph{sample minimum}.\n\\it $X_{(n)}$ is the \\emph{sample maximum}.\n\\it $X_{(n)} - X_{(1)}$ is the \\emph{sample range}.\n\\it \nThe \\emph{sample median} is $\\begin{cases} X_{(n/2+1/2)} & \\quad\\text{if $n$ is odd,} \\\\[2ex] \\frac{1}{2}\\big[X_{(n/2)}+X_{(n/2+1)}\\big] & \\quad\\text{if $n$ is even.} \\end{cases}$\n\\it\nThe \\emph{lower quartile} is the median of $X_{(1)},\\ldots,X_{(n/2)}$ if $n$ is even or $X_{(1)},\\ldots,X_{(n/2-1/2)}$ if $n$ is odd.\n\\it\nThe \\emph{upper quartile} is the median of $X_{(n/2+1)},\\ldots,X_{(n)}$ if $n$ is even or $X_{(n/2+3/2)},\\ldots,X_{(n)}$ if $n$ is odd.\n\\eit\n\n\\begin{remark}\nThe \\emph{five number summary} is a commonly used set of descriptive statistics consisting of the five most important sample quantiles:\n\\begin{center}\n[ sample minimum, lower quartile, median, upper quartile, sample maximum ]\n\\end{center}\nThese are sometimes illustrated using \\emph{box plots}.\n\\end{remark}\n\n% thm: distribution of order statistic\nThe distribution of $X_{(k)}$ can be expressed in terms of the common CDF of the sample points.\n\\begin{theorem}\nLet $X_1,X_2,\\ldots,X_n$ be a random sample from an unknown distribution and let $F$ denote their common CDF. Then the CDF of the $k$th order statistic $X_{(k)}$ is \n\\[\n\\prob(X_{(k)}\\leq x) = \\prob(W\\geq k) \\quad\\text{where}\\quad W\\sim\\text{Binomial}\\big(n,F(x)\\big). \n\\]\n\\begin{proof}\nBy independence,\n\\begin{align*}\n\\prob(X_{(k)}\\leq x)\n\t& = \\prob(\\text{at least $k$ observations are $\\leq x$}) \\\\\n\t& = \\prob\\big(\\text{at least $k$ successes in $n$ Bernoulli trials where P(success)$=F(x)$}\\big) \\\\\n\t& = \\prob(W\\geq k) \\quad\\text{where}\\quad W\\sim\\text{Binomial}\\big(n,F(x)\\big). \n\\end{align*}\n\\end{proof}\n\\end{theorem}\n\n%-----------------------------\n\\subsection{Empirical distribution functions}\n\n%%-------------------------------------------------\n%\\section{Empirical CDFs}\n\nLet $X$ be a random variable whose distribution is unknown, and let $X_1,X_2,\\ldots,X_n$ be a random sample from the distribution of $X$. \n\\begin{definition}\\label{def:empirical_cdf}\nThe \\emph{empirical cumulative distribution function} (ECDF) of $X$ is\n\\[\n\\hat{F}_X(x) = \\frac{1}{n}\\sum_{i=1}^n I(X_i\\leq x)\n\\]\nwhere $I(X_i\\leq x)$ is the indicator variable of the event $\\{\\omega:X_i(\\omega)\\leq x\\}$.\n\\end{definition}\n\nIn terms of order statistics, the ECDF can be written as\n\\[\n\\hat{F}_X(x) = \\begin{cases}\n\t0\t& \\text{ for $x < X_{(1)}$,} \\\\\n\ti/n\t& \\text{ for $X_{(i)} < x \\leq X_{(i+1)}$,} \\\\\n\t1\t& \\text{ for $x \\geq X_{(n)}$.}\n\\end{cases}\n\\]\n\n\\begin{remark}\n$\\hat{F}_X(x)$ is the proportion of observations that are less than or equal to $x$. By the law of large numbers applied to the indicator variables $I(X_i\\leq x)$,\n\\[\n\\hat{F}_X(x) \\to \\prob(X\\leq x) \\quad\\text{in probability as the sample size $n\\to\\infty$ for all $x\\in\\R$.}\n\\]\n\\end{remark}\n\n% remark: goodness of fit\n\\begin{remark}[Goodness-of-fit]\nLet $F$ be an estimate for the CDF of $X$. We can quanify the so-called \\emph{goodness of fit} using a number of test statistics based on the empirical $CDF$ of a random sample taken from the distribution of $X$, some of which are shown in Table~\\ref{tab:gof}.\n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{ll} \\hline\n%Test & Test statistic \\\\\n\\strut Kolmogorov-Smirnov &\n%$\\displaystyle T_n = \n$\\displaystyle \\max|\\hat{F}(x) - F(x)|$ \\\\[2ex]\nCramer-von~Mises &\n%$\\displaystyle T_n = \n$\\displaystyle \\int_{-\\infty}^{\\infty} \\big[\\hat{F}(x) - F(x)\\big]^2 f(x)\\,dx$ \\\\[2ex]\nAnderson-Darling &\n%$\\displaystyle T_n = \n$\\displaystyle \\int_{-\\infty}^{\\infty} \\frac{\\big[\\hat{F}(x) - F(x)\\big]^2}{F(x)\\big[1-F(x)]} f(x)\\,dx$ \\\\[2ex] \\hline\n\\end{tabular}\n\\caption{Test statistics for goodness-of-fit.\\label{tab:gof}}\n\\end{table}\n\\end{remark}\n\n\n\n", "meta": {"hexsha": "f4268984a568a15b7d14c5c8ffe9dba946635029", "size": 5881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/10A_quantiles.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/10A_quantiles.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/10A_quantiles.tex", "max_forks_repo_name": "gillardjw/notes", "max_forks_repo_head_hexsha": "58b3f7e8e2c289a88905bda689c95483bee04490", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-04T05:13:05.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T05:13:05.000Z", "avg_line_length": 40.0068027211, "max_line_length": 260, "alphanum_fraction": 0.6556708043, "num_tokens": 2073, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.9241418199787566, "lm_q1q2_score": 0.7854939162258869}}
{"text": "\\subsection{Diagonalization and Properties}\n\nDiagonal matrix has entries not along the main diagonal be all 0. Example:\n\n\\[A=\\begin{bmatrix}1&0&0\\\\0&3&0\\\\0&0&-1\\\\ \\end{bmatrix}\\]\n\nCharacteristic polynomial ends up being\n\n\\begin{align*}\n    p_A(\\lambda)&=\\mbox{det}\\begin{bmatrix}1-\\lambda&0&0\\\\ 0&3-\\lambda&0\\\\ 0&0&-1-\\lambda\\\\ \\end{bmatrix}\\\\\n    p_A(\\lambda)&=(1-\\lambda)(3-\\lambda)(-1-\\lambda)\n\\end{align*}\n\n\\noindent\nMatrix similar to diagonal matrix is \\textbf{diagonalizable}. Thus, $A$ is diagonalizable if\nthere exists an invertible $S$ and diagonal matrix $D$ such that $\\boxed{S^{-1}AS=D}$. \nBecause it is known that if $A\\sim B$, $p_A(\\lambda)=p_B(\\lambda)$, whenever $A$ is diagonalizable, the\neigenvalues of $A$ will be diagonal entries of any diagonal matrix $A$ is similar to.\n\n\\noindent\nAlso note that for a diagonal matrix $D$, $D^t$ consists of all the diagonal entries $\\lambda_1^t, \\lambda_2^t\\cdots, \\lambda_n^t$:\n\n\\[D^t=\\begin{bmatrix}\n    \\lambda_1^t&0&0&0\\\\\n    0&\\lambda_2^t&0&0\\\\\n    0&0&\\ddots&0\\\\\n    0&0&0&\\lambda_n^t\\\\\n\\end{bmatrix}\\]\n\nIt then follows that if $S^{-1}AS=D$:\n\n\\begin{align*}\n    S^{-1}AS&=D\\\\\n    (S^{-1}AS)^t&=D^t\\\\\n    (S^{-1}AS)(S^{-1}AS)(S^{-1}AS)\\dots(S^{-1}AS)&=D^t\\\\\n    S^{-1}A^tS&=D\\\\\n    A^t&=SD^tS^{-1}\\\\\n\\end{align*}\n\n\\subsection{Diagonalization and Eigenbasis}\n\n\\textbf{A square matrix is diagonalizable if it has an eigenbasis.}\n\n\\noindent\nLet the eigenbasis be $\\mathfrak{E}=\\left\\{\\tb v_1, \\tb v_2, \\tb v_3, \\dots, \\tb v_n\\right\\}$.\nTo show $A$ is diagonalizable, the $\\mathfrak{E}$-matrix can be shown to be diagonal. First, let\n$A$'s transformation be $T_A(\\tb{x})=A\\tb{x}$. The $\\mathfrak{E}$-matrix is $D$. Thus, $\\boxed{D[\\tb x]_\\mathfrak{E}=[T_A(\\tb x)]_\\mathfrak{E}}$.\nThe first column of $D$ is $[T_A(\\tb{v}_1)]_\\mathfrak{E}$. However, because $\\mathfrak{E}$ is an eigenbasis for $A$,\nit must hold true that:\n\n\\[A\\tb v_1=T_A(\\tb v_1)=\\lambda_1 \\tb v_1\\]\n\n\\noindent\nThus, first column of $D$ is $[\\lambda_1\\tb{v}_1]_\\mathfrak{E}$. Since $\\lambda _1 \\tb v_1=\\lambda_1 \\tb v_2+0\\tb v_2+0\\tb v_3+\\dots+0\\tb v_n$\nas it is part of an eigenbasis, $[\\lambda _1 \\tb v_1]_\\mathfrak{E}=\\begin{bmatrix}\\lambda_1\\\\0\\\\0\\\\ \\vdots \\\\ 0 \\end{bmatrix}$.\nIf repeated for all vectors in $\\mathfrak{E}$, it ends up being that:\n\n\\[D=\\begin{bmatrix}\\lambda_1&0&0&0\\\\\n    0&\\lambda_2&0&0\\\\\n    0&0&\\ddots&0\\\\\n    0&0&0&\\lambda_n\n\\end{bmatrix}\\]\n\nIt must also hold true that if $A$ is diagonalizable, it has an eigenbasis. It is known that:\n\n\\[S^{-1}AS=D=\\begin{bmatrix}\\lambda_1&0&0&0\\\\0&\\lambda_2&0&0\\\\ 0&0&\\ddots&0\\\\ 0&0&0&\\lambda_n \\end{bmatrix}\\]\n\nso a basis in $\\R^n$ consisting of eigenvectors must be found. This is found in the columns of $S$, the change of basis matrix.\nThe similarity formula can be rearranged to get $AS=SD$. Thus, for the first column of $S$, $S\\tb{e}_1$:\n\n\\begin{align*}\n    A(S\\tb e_1)&=(AS)\\tb e_1\\\\\n    &=(SD)\\tb e_1\\\\\n    &=S(D \\tb e_1)\\\\\n    &=S(\\lambda_1 \\tb e_1)\\\\\n    &=\\lambda_1 (S\\tb e_1)\\\\    \n\\end{align*}\n\n\\noindent\nThis is indeed a basis as $S$ is required to be invertible.", "meta": {"hexsha": "e47916053361b8e34eb28f7c508a374a384e51c6", "size": 3063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/20_diagonalization.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/20_diagonalization.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/20_diagonalization.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2875, "max_line_length": 145, "alphanum_fraction": 0.653281097, "num_tokens": 1225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.9136765175373274, "lm_q1q2_score": 0.7854545949591498}}
{"text": "\\subsection{Uncertainty of the slope of $T^2\\ vs.\\ M$}\nThe uncertainty of one period is $u_T/10=1\\times10^{-5}s$ and the uncertainty of mass is\n\\[\n\\begin{split}\n    M&=m_{objI}+\\frac{1}{3}m_{spr1}+\\frac{1}{3}m_{spr2}+m_i,\\\\\n    u_M&=\\sqrt{\n     (\\frac{\\partial M}{\\partial m_{objI}})^2(u_{m_{objI}})^2\n    +(\\frac{\\partial M}{\\partial m_{spr1}})^2(u_{m_{spr1}})^2\n    +(\\frac{\\partial M}{\\partial m_{spr2}})^2(u_{m_{spr2}})^2\n    +(\\frac{\\partial M}{\\partial m_i})^2(u_{m_i})^2\n    }\\\\\n    &=\\sqrt{\n     (1)^2(u_{m_{objI}})^2\n    +(\\frac{1}{3})^2(u_{m_{spr1}})^2\n    +(\\frac{1}{3})^2(u_{m_{spr2}})^2\n    +(1)^2(u_{m_i})^2\n    }\n\\end{split}\n\\]\n\nAs data provided \n$m_{objI}=(176.87\\pm0.01)\\times10^{-3}kg$, $m_{spr1}=(11.23\\pm0.01)\\times10^{-3}kg$, $m_{spr2}=(10.54\\pm0.01)\\times10^{-3}kg$ and $m_1=(4.65\\pm0.01)\\times10^{-3}kg$\n\n\\[\n\\begin{split}\n    u_M & = \\sqrt{0.00001^2+0.00001^2/9+0.00001^2/9+0.00001^2}=0.0000153\\\\\n        & = 1.5\\times10^{-5}kg.\n\\end{split}\n\\]\n\nFor $T^2$,\n$$   u_{T^2}=\\sqrt{(2T)^2(u_T)^2}=2Tu_T$$\n\nFrom the formula $T=2\\pi\\sqrt{\\frac{M}{k}}$ \nwe can drive the slope of $T^2\\ vs.\\ M$ is\n\n$$\tslope=\\frac{T^2}{M}=\\frac{4\\pi^2}{k}$$\n\nwhere k is the effective spring constant. In this experiment, the effective spring constant can be calculated by\n\n$$  F =k_1\\Delta x+k_2\\Delta x  =k_{eff}\\Delta x   $$\n\n%NOTE: finish here\n\n\\[\n\\begin{split}\nu_{slope} & = \\sqrt{\n\t(\\frac{\\partial slope}{\\partial slope_{hor}})^2\\cdot(u_{slope_{hor}})^2\n\t+(\\frac{\\partial slope}{\\partial slope_{inc1}})^2\\cdot(u_{sloinc1})^2\n\t+(\\frac{\\partial slope}{\\partial slope_{inc2}})^2\\cdot(u_{slope_{inc2}})^2} \\\\\n& = \\sqrt{\n\t(\\frac{1}{3})^2 \\cdot (0.22)^2\n\t+(\\frac{1}{3})^2 \\cdot (0.05)^2\n\t+(\\frac{1}{3})^2 \\cdot (0.22)^2} = 0.18s^2/kg\\\\\n\\end{split}\n\\]\n\n$$ u_{r,slope} = \\frac{u_{slope}}{\\bar{slope}} \\times 100 \\%\n               =\\frac{0.18}{8.37} \\times 100 \\% = 2.15\\% $$\n\nComparing the calculated data with the experiment data,\n$$   \\Delta slope = 8.37 - 8.45 = -0.08 s^2/kg        \t\t\t\t   $$\n$$   \\Delta_r slope = \\frac{ 8.37 - 8.45}{8.45} \\times 100\\% = 0.95 \\%  $$\n\nFor the deviation between theory calculation is not very large, it indicates that the experiment is quite success.\n\n%NOTE: finish here\n\n\\subsection{Uncertainty in the $v_{\\max}^2\\ vs.\\ A^2$ relation}\n\nFor analyzing the uncertainty of $\\Delta x$,\nFirst, investigate the uncertainty of $x_{in}$ and $x_{out}$. \nThe uncertainty of type-B of a calliper is \n\n$$\\Delta_{x,B} = \\Delta{dev} = 0.02 \\times 10^m   $$ \n\nTake the mean value of the three time measurements of the distance.\nTo determine type-A uncertainty, the standard deviation of the average value is \n\n$$   s_{\\overline{x_{in}}} = \\sqrt{\\frac{1}{n(n-1)}\\sum_{i=1}^n(x_{in,i}-\\overline{x_{in}})^2} $$\n$$   s_{\\overline{x_{in}}} = 5.3 \\times 10^{-3} m \t\t$$\n\n$$  u_{x_{in}}=\\sqrt{\\Delta_{x_{in},A}^2+\\Delta_{x_{in},B}^2}\n     = \\sqrt{(0.02 \\times 10^{-3} )^2\n\t +(5.3 \\times 10^{-3})^2} \n\t = 5.3 \\times 10^{-3} m $$\n$$  u_{r,x_{in}}=\\frac{u_{x_{in}}}{\\overline{x_{in}}}\\times 100\\%=1.8\\%$$\n\nSimilarly, we can calculate $x_{out}$ that\n\\[\n\\begin{split}\n    &\\Delta_{x_{out},A}=t_{0.95}\\cdot s_{\\overline{x_{out}}}=0.0287\\times10^{-3}m\\\\\n    &\\Delta_{x,B}=0.02\\times10^{-3}m\\\\\n    &u_{x_{out}}=0.03\\times10^{-3}m,\\quad\n    u_{r,x_{out}}=0.2 \\%    \\\\\n    &x_{out}=(15.41\\pm 0.03) \\times10^{-3}m,\\quad u_{r,x_{out}}=0.2\\%.\n\\end{split}\n\\]\n\nThen we can calculate the propagated uncertainty of $\\Delta x$\n\n$$\\frac{\\partial\\Delta x}{\\partial x_{in}}=\\frac{\\partial\\Delta x}{\\partial x_{out}}=\\frac{1}{2}  $$\n\n\\[\n\\begin{split}\n    u_{\\Delta x}&=\\sqrt{(\\frac{\\partial\\Delta x}{\\partial x_{in}})^2(u_{x_{in}})^2\n\t+(\\frac{\\partial\\Delta x}{\\partial x_{out}})^2(u_{x_{out}})^2}\\\\ \n    &=0.04\\times10^{-3}m,\\\\\n\\end{split}\n\\]\n\n$$    u_{r,\\Delta x}=\\frac{u_{\\Delta x}}{\\Delta x}\\times100\\%=0.4\\% $$\n$$     \\Delta x=(9.95\\pm0.04)\\times10^{-3}m,\\quad u_{r,\\Delta x}=0.4\\%  $$\n\nFor the Uncertainty of the maximum speed $v_{\\max}$\nThen we can calculate the propagated uncertainty of $v_{\\max}=\\Delta x/\\Delta t$. The partial derivatives are\n\\[\n\\begin{split}\n    \\frac{\\partial v_{\\max}}{\\partial \\Delta x}&=\\frac{1}{\\Delta t}.\\\\[0.5cm]\n    \\frac{\\partial v_{\\max}}{\\partial \\Delta t}&= - \\frac{\\Delta x}{(\\Delta t)^2}.    \n\\end{split}    \n\\]\n\n\\[\n\\begin{split}\n    u_{v_{\\max}}&=\\sqrt{(\\frac{\\partial v_{\\max}}{\\partial \\Delta x})^2(u_{\\Delta x})^2+(\\frac{\\partial v_{\\max}}{\\partial \\Delta t})^2(u_{\\Delta t})^2}     \\\\\n    &=\\sqrt{(\\frac{1}{\\Delta t})^2(u_{\\Delta x})^2+(\\frac{\\Delta x}{(\\Delta t)^2})^2(u_{\\Delta t})^2}\n\\end{split}\n\\]\n", "meta": {"hexsha": "2cf708e1d7168f449aa53fe9e5ed92fe77f27e44", "size": 4533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E3/part/6mua1.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E3/part/6mua1.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E3/part/6mua1.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": 34.8692307692, "max_line_length": 164, "alphanum_fraction": 0.5868078535, "num_tokens": 1884, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.785433887124889}}
{"text": "\n\\chapter{Nonlinear system stability}\n\nAll material is sourced from Ref. \\cite{hurtado2015}\n\n\\section{Linearization test}\n\nIf the linearized system's eigenvalues all satisfy $Re(\\lambda_i) < 0$, then the nonlinear system is stable.\n\nIf the any eigenvalues of the linearized system have positive real part, the nonlinear system is unstable.\n\nIf any eigenvalue has zero real part, nothing about stability of the nonlinear system is concluded.\n\n\\section{Lyapunov's direct method}\n\nLyapunov's direct method provides a test for stability of a system $\\dvec{x} = f(\\vec{x},t)$ about an equilibrium point $\\vec{x}^*$. A precondition for the test is the existence of function $V(\\vec{x})$ having the following three properties: (1) $V(\\vec{x}^*) = 0$; (2) $V(\\vec{x}\\neq \\vec{x}^*) > 0, \\vec{x}\\in W$; (3) $\\dot{V}(\\vec{x}^*) = 0$.\n\nIf the Lyapunov function may satisfy the following additional conditions, proving certain stability properties:\n\n\\begin{itemize}\n\t\\item $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) \\leq 0, \\vec{x}\\in W$ $\\rightarrow$ the system is \\textbf{locally stable} (or locally marginally stable).\n\t\\item $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) < 0, \\vec{x}\\in W$ $\\rightarrow$ the system is \\textbf{locally asymptotically stable} ($\\vec{x} \\in W$ tends to $\\vec{x}^*$ as $t\\rightarrow\\infty$).\n\t\\item $V(\\vec{x})$ is radially unbounded AND $\\dot{V}(\\vec{x}) < 0 \\ \\forall \\ \\vec{x}\\neq\\vec{x}^*$ $\\rightarrow$ the system is \\textbf{globally asymptotically stable}.\n\t\\item $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) > 0, \\vec{x}\\in W$ $\\rightarrow$ the system is \\textbf{unstable}.\n\\end{itemize}\n\n\\section{Mukherjee and Chen's theorem}\n\nSometimes $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) \\leq 0$ when the system is truly asymptotically stable. An extended test exists provided that $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) < 0 \\ \\forall \\ \\vec{x} \\in Z \\subset W$.\nMotion is asymptotically stable provided that $V(\\vec{x})$ is a Lyapunov function and the following are satisfied:\n\n\\begin{enumerate}\n\t\\item $\\dot{V}(\\vec{x}\\neq\\vec{x}^*) < 0 \\ \\forall \\ \\vec{x} \\in Z \\subset W$\n\t\\item $ \\frac{d^i V}{dt^i} (\\vec{x}) = 0 \\ \\forall \\ \\vec{x} \\in Z, i = 2,\\dots,k-1$\n\t\\item $ \\frac{d^k V}{dt^k} (\\vec{x}^*) = 0$\n\t\\item $ \\frac{d^k V}{dt^k} (\\vec{x}) < 0 \\ \\forall \\ \\vec{x} \\in Z, k = \\mathrm{odd}$\n\\end{enumerate}", "meta": {"hexsha": "719896e90e88ac006e1279dc2605d718d9e41ab8", "size": 2270, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lyapunov-stability/nonlinear-stability.tex", "max_stars_repo_name": "fatadama/study-summaries", "max_stars_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lyapunov-stability/nonlinear-stability.tex", "max_issues_repo_name": "fatadama/study-summaries", "max_issues_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lyapunov-stability/nonlinear-stability.tex", "max_forks_repo_name": "fatadama/study-summaries", "max_forks_repo_head_hexsha": "38649d903420549d75005ca39860f164dab106ee", "max_forks_repo_licenses": ["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.3513513514, "max_line_length": 345, "alphanum_fraction": 0.6713656388, "num_tokens": 779, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423873, "lm_q2_score": 0.8933094145755218, "lm_q1q2_score": 0.7853500898671016}}
{"text": "\\sec{Picard's Iterates}\n\\subsection{Introduction}\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tConsider the initial value problem (IVP)\n\t\\[y' = f(t, y); \\;\\; y(a) = b.\\]\n\tCorresponding to this, we set up the following \\emph{integral equation}\n\t\\[\\phi(t) = b + \\int_{a}^{t} f(s, \\phi(s)) ds.\\]\n\tIt can be verified a solution $\\phi_0$ to the integral equation is a solution of the original DE as well. (And vice-versa.)\\\\\n\\end{mdframed}\nNow, we describe a method to solve the integral equation.\n\n\\newpage\n\n\\begin{mdframed}[style=boxstyle, frametitle={Picard's Iteration Method}]\n\tWe recursively define a family of functions $\\phi_n(t)$ for every $n \\ge 0$ as follows:\n\t\\begin{align*} \n\t\t\\phi_0 &\\equiv b,\\\\\n\t\t\\phi_{n + 1}(t) &= b + \\int_{a}^{t} f(s, \\phi_n(s)) ds \\quad \\text{for }n \\ge 0.\n\t\\end{align*}\n\\end{mdframed}\nUnder suitable conditions, the sequence of functions $\\left(\\phi_n\\right)$ converges to a function\n\\[\\phi(t) = \\lim_{n\\to \\infty}\\phi_n(t),\\]\nwhich is a solution to the IVP.\n\n\\exercise{%\nSolve the IVP:\n\\[y'(t) = 2t(1 + y); \\;\\; y(0) = 0.\\]\n}", "meta": {"hexsha": "5ebad2f784500cbbdaa3a168fdc8a0f80e17f2d8", "size": 1071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/picard.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/picard.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/picard.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 38.25, "max_line_length": 126, "alphanum_fraction": 0.6657329599, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8933094032139577, "lm_q1q2_score": 0.7853500770500185}}
{"text": "\\section{Regression}\n\nThe concepts discussed in the following section could also be presented in\nrandom variables instead of sample ones. As the geometry of sample variables\nis almost of no difference comparing to the random ones, the logic of\nall the theorems is also the same.\n\n\n\\subsection{Geometry of sample variables}\n\n\\marginnote{\n\\begin{multline*}\n\\sCorr(x,y) = \\frac{\\sCov(x,y)}{\\sqrt{\\sVar(x)\\sVar(y)}} \\\\\n= \\frac{\\frac{1}{n-1}\\sum_{i=1}^n (x_i - \\bar x)(y_i - \\bar y)}\n{\\sqrt{\\frac{1}{n-1} \\sum_{i=1}^n (x_i - \\bar x)\\frac{1}{n-1} \\sum_{i=1}^n ( y_i -  \\hat y)}}\n\\end{multline*}\n}\n\nIn the~same manner it was done in the previous section, we define\nthe~scalar product of two sample variables\n$x =\n\\begin{pmatrix}\nx_1 \\\\\n\\vdots \\\\\nx_n\n\\end{pmatrix}$\nand\n$y =\n\\begin{pmatrix}\ny_1 \\\\\n\\vdots \\\\\ny_n\n\\end{pmatrix}$\nas a sample covariation between them:\n\\[\n\\langle x, y \\rangle = \\sCov(x, y).\n\\]\nThe main characteristics of a~vector are its length and direction.\nAgain, we introduce the~length\n\\[\n\\sqrt{\\sCov(x,x)} = \\sqrt{\\sVar(x)} = \\sigma_x\n\\]\nand the~angle between two sample variables\n\\[\n\\cos(x,y) = \\frac{\\sCov(x,y)}{\\sqrt{\\sVar(x)\\sVar(y)}} = \\sCorr(x,y).\n\\]\nNote that from the definition of the angle\nit follows that the~sample correlation coefficient can range from $-1$ to $1$.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.85]{figures/02_basic_projection.pdf}\n\\caption{Vector $y$ projected onto vector $x$.}\n\\label{fig:corr_proj}\n\\end{marginfigure}\n\nCompletely analogus to the~case of random variables,\nthe projection of such a sample variable $y$ onto\n$\\{cx| c \\in \\mathbb{R}\\}$ is $\\hat y = \\sCorr(x,y) \\cdot y$.\n\nLooking at Figure~\\ref{fig:corr_proj}, we can interpret the~square of sample correlation coefficient.\nUsing the fact that $\\cos^2 \\varphi$ is the~squared ratio of\nthe~leg adjacent to $\\varphi$ to hypotenuse, we can conclude that\n\\[\n\\sCorr^2(x,y) = \\frac{\\sVar(\\hat y)}{\\sVar(y)},\n\\]\nas the variance of a vector is associated with the square of its length.\nThus, the~sample correlation coefficient squared shows\nthe~fraction of variance in $y$ which can be explained\nwith the~most similar vector proportional to $x$.\n\n\n\\subsection{Sample correlation when a constatnt vector added}\n\n\\marginnote{\n\\begin{align*}\n\\sCorr(x + \\alpha \\mathbf{1}, y) &= \\frac{\\sCov(x + \\alpha \\mathbf{1}, y)}{\\sqrt{\\sVar(x + \\alpha \\mathbf{1}) \\sVar(y)}} \\\\\n&= \\frac{\\sCov(x,y) + \\sCov(\\alpha \\mathbf{1},y)}{\\sqrt{\\sVar(x)\\sVar(y)}} \\\\\n&= \\frac{\\sCov(x,y)}{\\sqrt{\\sVar(x)\\sVar(y)}} \\\\\n&= \\sCorr(x,y)\n\\end{align*}\n}\n\n\\begin{theorem}\nAdding a~vector of constants does not affect the sample correlation coefficient:\n\\[\n\\sCorr(x + \\alpha \\mathbf{1}, y) = \\sCorr(x,y)\n\\]\nwhere $\\alpha \\in \\mathbb{R}$.\n\\end{theorem}\n\n\\begin{proof}\nFirstly, we project vectors $x$ and $y$ onto $\\Lin^{\\perp}(\\mathbf{1})$\nin order to get $x^c = x - \\bar x$ and $y^c = y - \\bar y$ (`c' stands for `centred').\nIt can be shown that the~matrix corresponding to projecting onto the line spanned by\na~vector of all ones has the~following form\n\\[\n\\frac{\\mathbf{1} \\mathbf{1}^T}{\\mathbf{1}^T \\mathbf{1}} =\n\\frac{\n\\begin{pmatrix}\n  1 \\\\\n  \\vdots \\\\\n  1\n\\end{pmatrix}\n\\begin{pmatrix}\n  1 & \\ldots & 1\n\\end{pmatrix}\n}{\\sum_{i=1}^n 1} =\n\\begin{pmatrix}\n  \\frac{1}{n} & \\ldots & \\frac{1}{n} \\\\\n  \\vdots & \\ddots & \\vdots \\\\\n  \\frac{1}{n} & \\ldots & \\frac{1}{n}\n\\end{pmatrix}\n\\]\nThus, projecting onto the~orthogonal subspace is equivalent to\nsubstracting the~projected vector, i.e., the vector of averages, from the original one.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.65]{figures/02_correlation_constant_centered_variables.pdf}\n\\caption{Centred vectors $x^c$ and $y^c$.}\n\\label{fig:corr_xyc}\n\\end{marginfigure}\n\nAlso note that the~angle $\\varphi$ between the~original and centred vectors remains the~same.\nThe~result of this step is shown in Figure~\\ref{fig:corr_xyc}.\n\nThen we need to derive a new vector $\\tilde x$ with constants added to each component.\nGeometrically adding a vector of costants means adding a vector of all ones\nscaled by $\\alpha \\in \\mathbb{R}$, i.e., $\\alpha \\mathbf{1}$.\nThen the new vector $\\tilde x$ can be broken up into a sum of $\\alpha \\mathbf{1}$ and\n$\\beta x$, $\\alpha, \\beta \\in \\mathbb{R}$, which can be seen in Figure~\\ref{fig:corr_final}.\nAfter that we will project this new vector $\\tilde x$ onto $\\Lin^{\\perp}(\\mathbf{1})$.\nBy the properties of projection it is of no difference whether to project\nthe whole vector $\\tilde x$ or project its parts $\\alpha \\mathbf{1}$\nand $\\beta x$ — the result is the same.\nSo, while $\\beta x$ is projected onto the span of $x^c$, the projection of $\\alpha \\mathbf{1}$\nonto the orthohgonal space $\\Lin^{\\perp}(\\mathbf{1})$ yields zero as demonstrated\nin Figure~\\ref{fig:corr_final}.\nMoreover, it follows that the angle between $\\tilde x$ and $y$ is still $\\varphi$.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.6\\linewidth]{figures/02_correlation_constant_proof.pdf}\n\\label{fig:corr_final}\n\\caption{$\\sCorr(x + \\alpha \\mathbf{1}, y) = \\sCorr(x,y)$ as the corresponding angles are equal.}\n\\end{center}\n\\end{figure}\n\n\nFinally, putting everything together we finish the proof:\n\\[\n\\sCorr(x + \\alpha \\mathbf{1}, y) = \\sCorr(x,y)\n\\]\n\\end{proof}\n\n\n\\subsection{Sample correlation coefficient in simple linear regression}\n\n\\begin{theorem}\nA linear regression model with one explanatory variable and constant term\n\\[\ny = \\beta_1 \\mathbf{1} + \\beta_2 x + \\varepsilon\n\\]\nhas the property\n\\[\n\\sCorr(y, \\hat y) = \\sign(\\hat \\beta_2) \\sCorr(y, x)\n\\]\n\\end{theorem}\n\n\\marginnote{\nAssuming the underlying relationship between $x$ and $y$ to be\n\\[\ny_i = \\beta_1 + \\beta_2 x_i + \\varepsilon_i \\quad i=1,\\ldots,n\n\\]\nwhere $\\varepsilon_i$ is an error term the following holds\n\\begin{align*}\n\\sCorr(y, \\hat y) &= \\frac{\\sCov(y, \\hat y)}{\\sqrt{\\sVar(y)\\sVar(\\hat y)}} \\\\\n&= \\frac{\\sCov(y, \\hat \\beta_1 + \\hat \\beta_2 x)}{\\sqrt{\\sVar(y)\\sVar(\\hat \\beta_1 + \\hat \\beta_2 x)}} \\\\\n&= \\frac{\\sCov(y, \\hat \\beta_2 x)}{\\sqrt{\\sVar(y)\\sVar(\\hat \\beta_2 x)}} \\\\\n&= \\frac{\\hat \\beta_2 \\sCov(y, x)}{|\\hat \\beta_2| \\sqrt{\\sVar(y)\\sVar(x)}} \\\\\n&= \\sign(\\hat \\beta_2) \\frac{\\sCov(y,x)}{\\sqrt{\\sVar(y)\\sVar(x)}} \\\\\n&= \\sign(\\hat \\beta_2) \\sCorr(y, x)\n\\end{align*}\n}\n\n\\begin{proof}\nFirstly, we consider the case when $\\hat \\beta_2 > 0$.\nIt has been shown earlier that the correlation coefficient represents the angle\nbetween two random vectors.\nSo, in order to complete the proof we need to find the appropriate angles and compare them.\n\nHowever, it seems to be difficult to compare the angles in the three dimensional space.\nThat is why we start with projecting both $x$ and $y$ onto the plane perpendicular to the vector of all ones (denoted as $\\mathbf{1}$) as shown in Figure~\\ref{fig:corr_pos_xyc}.\nWe denote this space as $\\Lin^{\\perp}(\\mathbf{1})$. The resulting vectors are $x - \\bar x \\cdot \\mathbf{1}$  and $y - \\bar y \\cdot \\mathbf{1}$, respectively,\nsince projection of any vector $\\vec{a}$ onto the span of a vector of all ones yields the vector of averages $\\vec{\\bar a}$.\n\n\nIn order to get the angle between $y$ and $\\hat y$ we should start with regressing $y$ on $\\Lin(x, \\mathbf{1})$.\nThen the only thing left is to project $\\hat y$ onto $\\Lin^{\\perp}(\\mathbf{1})$ since the $y$ vector has already been projected.\nNote that the projected $\\hat y$ falls onto tha span of vector $x - \\bar x \\cdot \\mathbf{1}$ as it can be decomposed into a sum $a x + b \\mathbf{1}$ where $a, b \\in \\mathbb{R}$.\nThe first component $a x$ is projected in the same way as $x$ and $b \\mathbf{1}$ yields zero when projected onto the orthogonal space.\nThe result of this step is shown in Figure~\\ref{fig:corr_pos_yhatc}.\n\n\\begin{figure*}[h!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_simple_regression_coefficient_centred_variables.pdf}\n\\label{fig:corr_pos_xyc}}\n%\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_simple_regression_coefficient_yhat_projected.pdf}\n\\label{fig:corr_pos_yhatc}}\n\\caption{\\subref{fig:corr_pos_xyc}: `Centred' $x$ and $y$, i.e., projected onto $\\Lin^{\\perp}(\\mathbf{1})$;\n\\subref{fig:corr_pos_yhatc}: `Centred' $\\hat y$, i.e., projected onto $\\Lin^{\\perp}(\\mathbf{1})$.}\n\\end{center}\n\\end{figure*}\n\nSince the projection of $\\hat y$ lies exactly on the span of vector $x - \\bar x \\cdot \\mathbf{1}$,\nwe can conclude that $\\cos \\varphi = \\cos \\varphi '$ and to put it another way $\\sCorr(x,y) = \\sCorr(y, \\hat y)$.\n\nNow consider the case when $\\hat \\beta_2 < 0$.\nNote that the sign of $\\beta_1$ does not influence the correlation coefficient sign.\nThe only difference is that now $\\hat y$ is projected onto the span of  $x - \\bar x \\cdot \\mathbf{1}$ and not on this vector itself while the projections of $x$ and $y$ remain the same.\nLooking at Figure~\\ref{fig:corr_negative} we deduce\nthat the~angle between $y$ and $\\hat y$ is compelement to the angle between $x$ and $y$.\nUsing trigonometric properties, we simplify $\\cos(180^{\\circ} - \\varphi) = -\\cos\\varphi$\nwhich in turn implies $\\sCorr(x,y) = -\\sCorr(y,\\hat y)$.\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics{figures/02_simple_regression_coefficient_negative.pdf}\n\\label{fig:corr_negative}\n\\caption{Case of $\\beta_2 < 0$.}\n\\setfloatalignment{b}\n\\end{center}\n\\end{figure}\n\\end{proof}\n\n\n\\subsection{RSS + ESS = TSS}\n\n\\marginnote{\nConsider a regression model with $n$ observations and $k$ explanatory variables\nincluding a constant unit vector % unit?\n\\[\ny = X \\beta + \\varepsilon\n\\]\nThe OLS estimator for the vector of coefficients $\\beta$ is\n\\[\n\\hat \\beta = (X^T X)^{-1} X^T y\n\\]\nand the residual vector is\n\\begin{align*}\n\\hat e &= y - \\hat y \\\\\n&= y - X \\hat \\beta \\\\\n&= y - X (X^T X)^{-1} X^T y\n\\end{align*}\nThen we define residual sum of squares (RSS), explained sum of squares (ESS) and total sum of squares (TSS) as follows:\n\\begin{align*}\nRSS &= \\lVert y - \\hat y \\rVert^2_2 \\\\\nESS &= \\lVert \\hat y - \\bar y \\rVert^2_2 \\\\\nTSS &= \\lVert y - \\bar y \\rVert^2_2 \\\\\n\\end{align*}\n}\n\n\\begin{theorem}\nA linear regression model with $n$ observations and $k$ explanatory variables including a constant unit vector\n\\[\ny = X \\beta + \\varepsilon\n\\]\nhas the following property\n\\[\nRSS + ESS = TSS\n\\]\nwhere $RSS = \\lVert y - \\hat y \\rVert^2_2$, $ESS = \\lVert \\hat y - \\bar y \\rVert^2_2$, $TSS = \\lVert y - \\bar y \\rVert^2_2$.\n\\end{theorem}\n\n\\begin{proof}\nThe proof will be presented for the case of two regressor $x$ and $\\mathbf{1}$ in order for the picture to be clear.\nHowever, the same logic applies for the case of $k$ regressors.\n\nWe start with depicting the vectors $y \\in \\mathbb{R}^{n-2}$ and $x, \\mathbf{1} \\in \\mathbb{R}^2$.\nThen we project $y$ onto $\\Lin(x, \\mathbf{1})$ and obtain $\\hat y$ which is shown in Figure~\\ref{fig:rss}.\n\nFrom this picture we can immediately derive $\\sqrt{RSS}$ as by definition this is the squared difference between $y$ and $\\hat y$.\n\n\\begin{figure*}[h!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_rss_ess_tss_yhat.pdf}\n\\label{fig:rss}}\n\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_rss_ess_tss_sqr_tss_ess.pdf}\n\\label{fig:tss_ess}}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_rss_ess_tss_final.pdf}\n\\label{fig:final}\n}\n\\caption{\\subref{fig:rss}: Residual sum of squares;\n\\subref{fig:tss_ess}: Total sum of squares and residual sum of squares;\n\\subref{fig:final}: Illustration of the equality $(\\sqrt{RSS})^2 + (\\sqrt{ESS})^2 = (\\sqrt{TSS})^2$\nwhere $a$ stands for $\\sqrt{RSS}$, $b$ — $\\sqrt{TSS}$, $c$ — $\\sqrt{ESS}$.}\n\\end{center}\n\\end{figure*}\n\nSo as to visualize $ESS$ and $TSS$ we first need to visualize vector of averages $\\bar y$.\nGeometrically this means projecting a vector onto a line spanned by vector $\\mathbf{1}$.\n\nNow we both project $y$ and $\\hat y$ onto $\\mathbf{1}$ and following the definition obtain $\\sqrt{TSS}$ as the difference vector $y - \\bar y$ and $\\sqrt{ESS}$ as the vector $\\hat y - \\bar y$.\n\nThe final step is to put everything together.\nNote that since $y - \\hat y$ is perpendicular to $\\Lin(x, \\mathbf{1})$ it is also perpendicular to $\\hat y - \\bar y$ and $\\mathbf{1}$ as these vectoros are in $\\Lin(x, \\mathbf{1})$.\nThen, applying the theorem of three perpendiculars we conclude that the foot of vector $y - \\bar y$ is the same point as the foot of the vector $\\hat y - \\bar y$.\nThus, we obtain a right angle triangle and can apply the Pythagorean theorem for the catheti $\\sqrt{RSS}$ and $\\sqrt{ESS}$ and the\nhypotenuse $\\sqrt{TSS}$:\n\\[\n\\left(\\sqrt{RSS}\\right)^2 + \\left(\\sqrt{ESS}\\right)^2 = \\left(\\sqrt{TSS}\\right)^2\n\\]\n\n\\marginnote[-5\\baselineskip]{\nDisclosing parentheses and using the fact that $\\hat{y}^T y = \\hat{y}^T \\hat{y}$\n\\begin{align*}\n\\hat{y}^T y &= \\beta^T X^T y \\\\\n&=  y^T X (X^T X)^{-1} X^T y \\\\\n\\hat{y}^T \\hat{y} &= \\beta^T X^T X \\beta \\\\\n&= y^T X (X^T X)^{-1} X^T X (X^T X)^{-1} X^T y \\\\\n&= y^T X (X^T X)^{-1} X^T y\n\\end{align*}\nwe obtain\n\\begin{align*}\nRSS &= y^T y -\\hat{y}^T \\hat{y} \\\\\nESS &= \\hat{y}^T \\hat{y} - \\hat{y}^T \\bar{y} + \\bar{y}^T \\bar{y} \\\\\nTSS &= y^T y - 2 y^T \\bar y +  \\bar{y}^T \\bar{y}\n\\end{align*}\nWhen putting everything together all the terms cancel out which proves\n\\[\nESS + RSS = TSS\n\\]\n}\n\\end{proof}\n\n\\vspace{3.5cm}\n\\subsection{Determination coefficient}\n\n\\marginnote[-2\\baselineskip]{\n\\begin{align*}\n\\sCorr^2(y,\\hat y) &= \\left(\\frac{\\sCov(y, \\hat y)}{\\sqrt{\\sVar(y)\\sVar(\\hat y)}}\\right)^2 \\\\\n&= \\frac{\\sCov(y, \\hat y) \\sCov(y, \\hat y)}{\\sVar(y)\\sVar(\\hat y)} \\\\\n&= \\frac{\\sCov(\\hat y + e, \\hat y) \\sCov(\\hat y + e, \\hat y)}{\\sVar(y)\\sVar(\\hat y)} \\\\\n&= \\frac{\\sCov(\\hat y, \\hat y) + \\sCov(e, \\hat y)}{\\sVar(y)} \\\\\n&\\cdot \\frac{\\sCov(\\hat y, \\hat y) + \\sCov(e, \\hat y)}{\\sVar(\\hat y)} \\\\\n&= \\frac{\\sVar(\\hat y) \\sVar(\\hat y)}{\\sVar(y)\\sVar(\\hat y)} \\\\\n&= \\frac{\\sVar(\\hat y)}{\\sVar(y)} = \\frac{ESS}{TSS} = R^2\n\\end{align*}\n}\n\n\\begin{theorem}\nA linear regression model with $n$ observations and $k$ explanatory variables including a constant unit vector\n\\[\ny = X \\beta + \\varepsilon\n\\]\nhas the following property\n\\[\nR^2 = \\sCorr^2(y, \\hat y)\n\\]\n\\end{theorem}\n\n\\begin{proof}\nProving this theorem geometrically means showing that the determination coefficient can be interpreted as some squared angle\nwhich happens to be eqaul to the squared angle between centered $y$ and $\\hat y$.\n\nConsider Figure~\\ref{fig:final} from the previous proof.\nIt was shown there that the vectors $y - \\bar y$, $y - \\hat y$ and $\\hat y - \\bar y$ form a right triangle.\nHaving defined the determination coefficient as\n\\[\nR^2 = \\frac{ESS}{TSS}\n\\]\nwe conclude that its geometric interpretaion is\n\\[\nR^2 = \\frac{ESS}{TSS} = \\cos^2 \\varphi\n\\]\nas shown in Figure~\\ref{fig:r_sq_angle}.\n\n\\begin{marginfigure}\n  \\includegraphics{figures/02_determination_coefficient.pdf}\n  \\caption{Determination coefficient as squared $\\cos \\varphi$\n  where $a$ stands for $\\sqrt{RSS}$, $b$ — $\\sqrt{TSS}$, $c$ — $\\sqrt{ESS}$.}\n  \\label{fig:r_sq_angle}\n\\end{marginfigure}\n\nRecall that the sample correlation coefficient two vectors was defined earlier as the angle between these two vectors.\nThus, we conclude that $\\sCorr(y, \\hat y)$ is the angle between $y$ and $\\hat y$ which is also eqaul to $\\cos \\varphi$.\nFinally, squaring both sides, we obtain\n\\[\nR^2 = \\sCorr^2(y, \\hat y)\n\\]\n\\end{proof}\n\n\n\\subsection{Regression line and point of averages}\n\n\\marginnote[-1\\baselineskip]{\nThe following decomposition of $\\hat y$ holds:\n\\begin{align*}\n\\hat y  &= X \\hat \\beta = X (X^T X)^{-1} X^T y \\\\\n&= X (X^T X)^{-1} X^T X \\beta + X (X^T X)^{-1} X^T \\varepsilon\n\\end{align*}\nPremultiplying both sides by $X^T$, we obtain:\n\\begin{align*}\nX^T \\hat y &=  X^T X (X^T X)^{-1} X^T X \\beta \\\\\n&+ X^T X (X^T X)^{-1} X^T \\varepsilon \\\\\n&= X^T X \\beta + X^T \\varepsilon\n\\end{align*}\nThis is a system of equations. The first row of $X^T$ is $\\mathbf{1}$ vector, so we can write out the first equation:\n\\[\n\\sum_{i=1}^n \\hat y_i = \\sum_{i=1}^{n} \\sum_{j=1}^{k} x_{ij} \\beta_{j}\n\\]\nFrom the first equation in the system\n\\[\nX^T \\hat y = X^T y\n\\]\nwe obtain\n\\[\n\\sum_{i=1}^{n} \\hat y_i = \\sum_{i=1}^{n} y\n\\]\nAnd this finishes the proof:\n\\[\n\\frac{1}{n} \\sum_{i=1}^{n} y = \\frac{1}{n} \\sum_{i=1}^{n} \\sum_{j=1}^{k} x_{ij} \\beta_{j}\n\\]\n}\n\n\\begin{theorem}\nIn a linear regression model with one explanatory variable and constant term\n\\[\ny = \\beta_1 + \\beta_2 x + \\varepsilon\n\\]\nthe point of averages lies on the estimated regression line.\n\\end{theorem}\n\n\\begin{proof}\nFor the geometrical proof it suffices to show that $\\hat y$ is a linear combination of the regressors, which is true by construction,\nand that $\\frac{1}{n} \\sum_{i=1}^{n} \\hat y_i = \\frac{1}{n} \\sum_{i=1}^{n} y$. In order for the pictures to be more clear the proof will be presented for the case of two regressors.\n\nThe first step is regressing $y$ on $\\Lin(\\mathbf{1}, x)$. As shown in Figure~\\ref{fig:averages_lin}, we obtain $\\hat y$ as a linear combination of $\\mathbf{1}$ and $x$.\nThe next step is to regress both $y$ and $\\hat y$ on $\\mathbf{1}$ which results in $\\bar y$ and $\\bar{\\hat y}$ correspondingly.\nBy the theorem of three perpendiculars, $\\bar y = \\bar{\\hat y}$ which is shown in Figure~\\ref{fig:averages_bars}.\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.35\\linewidth]{figures/02_averages_yhat_decomposed.pdf}\n\\label{fig:averages_lin} }\n\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.35\\linewidth]{figures/02_averages_final.pdf}\n\\label{fig:averages_bars}}\n\\caption{\\subref{fig:averages_lin}: Regression of $y$ on $\\Lin(\\mathbf{1},x)$;\n\\subref{fig:averages_bars}: Regression of $y$ and $\\hat y$ on $\\mathbf{1}$.}\n\\setfloatalignment{b}\n\\end{center}\n\\end{figure}\n\\end{proof}\n\n\n\\subsection{Orthogonality of regressors}\n\n\\marginnote{\nConsider a model\n\\[\ny = \\beta_1 x_1 + \\beta_2 x_2 + \\varepsilon\n\\]\nwith centred regressors $x_1$, $x_2$ such that $\\bar x_1 = \\bar x_2 = 0$.\nSuppose we mistakenly believe in a model\n\\[\ny = \\beta_1^* x_1 + \\varepsilon^*\n\\]\nwhere $x_2$ is omitted. Then the new estimator\n\\begin{align*}\n\\E\\left(\\hat \\beta_1^*\\right) &= \\E\\left(\\frac{\\sCov(x_1, y)}{\\sVar(x_1)}\\right) \\\\\n&= \\E\\left(\\frac{\\sCov(x_1, \\beta_1 x_1 + \\beta_2 x_2 + \\varepsilon)}{\\sVar(x_1)}\\right) \\\\\n&= \\beta_1 + \\beta_2 \\frac{\\sCov(x_1,x_2)}{\\sVar(x_1)} + \\E\\left(\\frac{\\sCov(x_1, \\varepsilon)}{\\sVar(x_1)}\\right) \\\\\n&= \\beta_1 + \\beta_2 \\frac{\\sCov(x_1,x_2)}{\\sVar(x_1)}\n\\end{align*}\nwill be unbiased if either $\\beta_2 = 0$ or $\\sCov(x1,x2) = 0$.\n}\n\n\\begin{theorem}\nOmitting a variable in a regression model does not lead to a bias in coefficient\nestimators if either the coefficient of the omitted regressor equals zero\nor the regressors are uncorrelated.\n\\end{theorem}\n\n\\begin{proof}\nWe will not consider the case when the coefficient of the omitted regressor\nequals zero because this means that the model is not mis-specified.\nThe case of orthogonal regressors is less trivial.\nHowever, it can be easily proved once the geometric approach is implemented.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.7]{figures/02_uncorrelated_regressors.pdf}\n\\label{fig:uncorrelated_regressors}\n\\caption{In case of uncorrelated regressors omitting one of them\ndoes not result in bias of the estimator.}\n\\end{marginfigure}\n\nCondider the following regression model\n\\[\ny = \\beta_1 x_1 + \\beta_2 x_2 + \\varepsilon\n\\]\nwhere regressors $x_1$ and $x_2$ are uncorrelated, $x_1 \\perp x_2$.\nWhen we perform a regression of $y$ onto both $x_1$, $x_2$\nwe obtain predicted values $\\hat y$ which can be broken up into a sum:\n\\[\n\\hat y = \\hat \\beta_1 x_1 + \\hat \\beta_2 x_2.\n\\]\nSince $x_1$ and $x_2$ are orthogonal it folows that\nthe difference $\\hat y - \\hat \\beta_1 x_1$ must be orthogonal to $x_1$.\nThus, by the theorem of three perpendiculars the projection of $y$ onto\n$x_1$ also results in $\\hat \\beta_1 x_1$.\n\\end{proof}\n\n\\vspace{4cm}\n\\subsection{Geometry of formula for OLS estimators}\n\nThe following interpretation gives another view on the estimators obtained\nby the ordianry least squares method.\nPreviously, we illustrated the ideas in the observations space, $\\mathbb{R}^n$.\nApparantely, the OLS estimators can be depicted in the regressors space, $\\mathbb{R}^k$.\nThis result follows from the Cramer's rule.\n\nConsider a linear model with two regressors:\n\\[\n\\hat y = \\hat \\beta_1 x_1 + \\hat \\beta_2 x_2.\n\\]\nLet us denote $X = \\begin{pmatrix} x_1 \\\\ x_2 \\end{pmatrix}$ and\n$\\langle X, y \\rangle = \\begin{pmatrix} \\langle x_1,  y \\rangle \\\\\n\\langle x_2,  y \\rangle \\end{pmatrix}$.\nThen, taking scalar product, we obtain:\n\\[\n\\langle X, y \\rangle = \\hat \\beta_1 \\langle X, x_1 \\rangle + \\hat \\beta_2 \\langle X, x_2 \\rangle\n\\]\nAll the elements of this equation are illustrated in Figure~\\ref{fig:cramers}.\n\nThe area of each parallelogram is the determinant of the matrix with columns\nwhich form the corresponding parallelogram.\nFor instance, the area of parallelogram formed by vectors $\\langle X, y \\rangle$, $\\langle X, x_2 \\rangle$\nis equal to $\\det([\\langle X, y \\rangle  \\langle X,  x_2 \\rangle])$.\nThe parallelogram formed by vectors $\\langle X, \\hat \\beta_1 x_1 \\rangle$,\n$\\langle X, x_2 \\rangle$ has the area of $\\hat \\beta_1 \\det([\\langle X, x_1 \\rangle  \\langle X, x_2 \\rangle])$.\nSince both parallelograms must be of the same area we obtain a formula for $\\hat \\beta_1$:\n\\[\n\\hat \\beta_1 = \\frac{\\det([\\langle X, y \\rangle  \\langle X,  x_2 \\rangle])}{ \\det([\\langle X, x_1 \\rangle  \\langle X, x_2 \\rangle])}.\n\\]\n\n\\begin{marginfigure}\n  \\includegraphics[scale=0.5]{figures/02_cramers_rule.pdf}\n  \\label{fig:cramers}\n  \\caption{Illustration of estimators in $\\mathbb{R}^k$ as the ratio of parallelogram areas.}\n\\end{marginfigure}\n\nSo as to generalize this result we introduce a matrix $A = (y | X)$\nthat has $y$ as its first column and all the regressors as the rest ones.\nWe will denote this matrix without column $y$ or $x$ as $A_{-y}$, $A_{-x}$, respectively.\nThen, we can write out the formula for $\\beta_x$:\n\\[\n\\hat \\beta_x = \\frac{\\det(\\langle A_{-y}, A_{-x} \\rangle)}{\\det(\\langle A_{-y}, A_{-y} \\rangle)}.\n\\]\n\nIf there is a regression with unit vector among the regressors and\nthe Frisch-Waugh-Lovell theorem is applied, the formula above takes the followin form:\n\\[\n\\hat \\beta_x = \\frac{\\det(\\sCov(A_{-y}, A_{-x}))}{\\det(\\sVar(A_{-y}))}.\n\\]\n\n\n\\subsection{Frisch–Waugh–Lovell theorem}\n\n\\marginnote{From regression~(\\ref{eq:fwl_2}) we get the following estimator:\n\\begin{align*}\n\\hat\\beta_2 &= ((M_1 X_2)^T M_1 X_2)^{-1}(M_1 X_2)^T M_1 y \\\\\n&= (X_2^T M_1^T M_1 X_2)^{-1}  X_2^T M_1^T M_1 y \\\\\n&= (X_2^T M_1 X_2)^{-1}  X_2^T M_1 y\n\\end{align*}\nAs for regression~(\\ref{eq:fwl_1}), let us note that due to $y = \\hat y + \\hat u$ $y$ can be decomposed as follows:\n\\[\ny = Py + My = X_1 \\hat \\beta_1 + X_2 \\hat \\beta_2 + My\n\\]\nPremultiplying both sides by $X_2^T M_1$, we obtain:\n\\begin{align*}\nX_2^T M_1 y &= X_2^T M_1 X_1 \\hat\\beta_1 + X_2^T M_1 X_2 \\hat\\beta_2 + X_2^T M_1 M y \\\\\n&=  X_2^T M_1 X_2 \\hat\\beta_2 + X_2^T M_1 M y \\\\\n&= X_2^T M_1 X_2 \\hat\\beta_2\n\\end{align*}\nOn the last step we used the fact that\n\\begin{align*}\n(X_2^T M_1 M y)^T = y^T M^T M_1^T X_2 \\\\\n= y^T M M_1 X_2 = y^T M X_2 = 0^T\n\\end{align*}\nAssuming $X_2^T M_1 X_2$ is invertible, we get the same estimator\n\\[\n\\hat\\beta_2 = (X_2^T M_1 X_2)^{-1}  X_2^T M_1 y\n\\]\n}\n\n\\begin{theorem}\nConsider regression\n\\begin{equation} \\label{eq:fwl_1}\ny = X_1 \\beta_1 + X_2 \\beta_2 + u\n\\end{equation}\nwhere $X_{n \\times k} = [X_1 X_2]$, i.e. $X_1$ consists of first $k_1$ columns of $X$ and $X_2$ consists of remaining $k_2$ columns of $X$,\n$\\beta_1$ and $\\beta_2$ are comformable, $k_1 \\times 1$ and $k_2 \\times 1$ vectors.\nConsider another regression\n\\begin{equation}  \\label{eq:fwl_2}\nM_1 y = M_1 X_2 \\beta_2 + M_1 u\n\\end{equation}\nwhere $M_1 = I - P_1$ projects onto the~orthogonal complement of the~column space~of\n$X_1$ and $P_1 = X_1(X_1^TX_1)^{-1}X_1^T$ is the~projection onto the~column space of~$X_1$.\nThen the~estimate of $\\beta_2$ from regression~(\\ref{eq:fwl_1}) will be the~same\nas the~estimate from regression~(\\ref{eq:fwl_2}).\n\\end{theorem}\n\nThere are two ways to~visualize the~proof of~the~Frisch-Waugh-Lovell theorem\nusing geometric concepts. Both are presented below.\n\n\\begin{proof}\n1.~Consider the following model:\n\\begin{equation} \\label{eq:fwl_proof}\ny_i = \\beta_1 x_i + \\beta_2 z_i + u_i\n\\end{equation}\n\nWe start with a `one-step' regression  and will distinct its coefficients with\nan upper index $A$.\nThe~only step in~obtaining $\\beta_1^{A}$ is regressing $y$ on~$\\Lin(x,z)$ and\nthen expanding $\\hat y$ as a~linear combination of~basis vectors $x$ and $z$,\nwhich is shown in~Figure~\\ref{fig:fwl_1_regression_3d}. Figure~\\ref{fig:fwl_1_regression_lin}\ndepicts $\\Lin(x, z)$.\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_yhat_decomposed.pdf}\n\\label{fig:fwl_1_regression_3d}}\n\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_yhat_decomposed_lin.pdf}\n\\label{fig:fwl_1_regression_lin}}\n\\caption{\\subref{fig:fwl_1_regression_3d}: Regression of $y$ on $\\Lin(x,z)$;\n\\subref{fig:fwl_1_regression_lin}: $\\Lin(x, z)$.}\n\\end{center}\n\\end{figure}\n\nAs for the~model~(\\ref{eq:fwl_2}) where several regressions are performed consecutively\nwe start with regressing $y$~on~$z$, resulting in $\\tilde{y}$,\nwhich we will refer~to as~`cleansed' $y$.\nWe will denote its coefficients with an upper index $B$.\n\n\\begin{equation}\\label{eq:fwl_2_y_clean}\n\\begin{aligned}\ny &= \\alpha z + \\varepsilon \\\\\n\\hat\\alpha &= \\frac{y^T z}{z^T z} \\\\\n\\tilde{y} &= \\hat\\varepsilon = y - \\frac{y^T z}{z^T z}z\n\\end{aligned}\n\\end{equation}\n\nFollowing that, $x$ is regressed on $z$, resulting in $\\tilde{x}$ — `cleansed' $x$.\n\n\\begin{equation}\\label{eq:fwl_2_x_clean}\n\\begin{aligned}\nx &= \\gamma z + \\nu \\\\\n\\hat\\gamma &= \\frac{x^T z}{z^T z} \\\\\n\\tilde{x} &= \\hat\\nu = x - \\frac{x^T z}{z^T z}z\n\\end{aligned}\n\\end{equation}\n\nGeometric results of these two steps are presented in~\\ref{fig:fwl_2_regression_first}.\n\nFinally, `cleansed' $y$ must be regressed on `cleansed' $x$.\nHowever, it cannot be performed immediately as $\\tilde{y}$ and $\\tilde{x}$ are skew lines.\nSo at first, we fix this problem by translation and after that obtain\n$\\hat\\beta_1^{B}\\tilde x$ (see Figure~\\ref{fig:fwl_2_regression_trans}).\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_cleansed_variables.pdf}\n\\label{fig:fwl_2_regression_first} }\n\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_translation.pdf}\n\\label{fig:fwl_2_regression_trans}}\n\\caption{\\subref{fig:fwl_2_regression_first}: Regression of $y$ on $z$ and of $x$ on $z$;\n\\subref{fig:fwl_2_regression_trans}: Translation of $\\tilde{x}$.}\n\\end{center}\n\\end{figure}\n\nNow let us picture all the results in one figure and mark some main points.\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_final.pdf}\n\\label{fig:fwl_3_3d} }\n\\hspace{4ex}\n\\subfigure[]{\n\\includegraphics[width=0.4\\linewidth]{figures/02_fwl_v1_final_lin.pdf}\n\\label{fig:fwl_3_lin}}\n\\caption{\\subref{fig:fwl_3_3d}: Point A stands for the origin, B — $\\hat\\gamma z$,\nC — $x$, D — $\\hat\\alpha z$, E — intersection of vector $x$ and line parallel to $\\tilde x$,\nF — $\\hat\\beta_1^{A} x$, G — $\\hat\\beta_1^{B} \\tilde{x}$; \\subref{fig:fwl_3_lin}: $\\Lin(x,z)$.}\n\\end{center}\n\\end{figure}\n\nIn Figure~\\ref{fig:fwl_3_lin} segments $AF$ and $BH = DG$ stand for $\\hat\\beta_1^{A}x$\nand $\\hat\\beta_1^{B}\\tilde x$ respectively, while segments AC and BC represent $x$ and $\\tilde{x}$.\nHaving two congruent angles, triangles ABC and FHC are simillar.\nThen, it follows:\n\\[\n\\frac{AF}{AC} = \\frac{BH}{BC} \\Leftrightarrow \\frac{\\hat\\beta_1^{A}x}{x} = \\frac{\\hat\\beta_1^{B}\\tilde x}{\\tilde x} \\Leftrightarrow \\hat\\beta_1^{A} = \\hat\\beta_1^{B}\n\\]\n\n2. Alternatively, we could implement a~concept close to the~partial correlation.\nIn the~same model~(\\ref{eq:fwl_proof}) we wiil treat $z$ vector fixed and again\nconsecutively cleanse the $x$ and $y$ variables by projecting them onto\nthe~space orthogonal to $z$, i.e., $\\Lin^\\perp(z)$ as demonstrated in Figure~\\ref{fig:fwl_v2_rcleansed}.\nThen we perform a~regression of the~`cleansed' $\\tilde y$ on the~`cleansed' $\\tilde x$\n(see Figure\\ref{fig:fwl_v2_regression_cleansed}).\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_fwl_v2_cleansed_variables.pdf}\n\\label{fig:fwl_v2_rcleansed}}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_fwl_v2_cleansed_regression.pdf}\n\\label{fig:fwl_v2_regression_cleansed}}\n\\caption{\\subref{fig:fwl_2_regression_first}: `Cleansed' variables $\\tilde x$ and $\\tilde y$;\n\\subref{fig:fwl_2_regression_trans}: `Cleansed' $\\tilde y$ regressed on `cleansed' $\\tilde{x}$.}\n\\end{center}\n\\end{figure}\n\nNow we show that the~latter regression produces $\\hat \\beta_1$ coefficient which\nis exactly the~coefficient from the~`one-step' regression of~original $y$ onto\noriginal $x$ and $z$. Recall that the~vector $y$ can be split~up into a~sum of\nsome multiple of $x$ and some multiple of $z$. Since the second term is\nthe~orthogonal component its projection yields zero. The~multiple of $x$\nis equal to $\\hat \\beta_1$ by construction.\n\nAssume that the~coefficient at~$\\tilde x$ is some unknown variable $\\hat \\delta$.\nThen consider the~similar triangles in the $\\Lin(x,z)$. From the~proportions\nwe obtain:\n\\[\n\\frac{CE}{CA} = \\frac{CD}{CB} \\Leftrightarrow \\frac{\\hat \\beta_1 x}{x} = \\frac{\\hat \\delta \\tilde x}{\\tilde x} \\Rightarrow \\hat \\beta_1 = \\hat \\delta\n\\]\n\n\\begin{figure}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_fwl_v2_similar_triangles.pdf}\n\\label{fig:fwl_v2_triangles}}\n\\subfigure[]{\n\\includegraphics[width=0.45\\linewidth]{figures/02_fwl_v2_final.pdf}\n\\label{fig:fwl_v2_final}}\n\\caption{\\subref{fig:fwl_2_regression_first}: Similar triangles: $\\bigtriangleup ABC \\sim \\bigtriangleup EDC$;\n\\subref{fig:fwl_2_regression_trans}: Alternative proof for the Frisch-Waugh-Lovell theorem.}\n\\end{center}\n\\end{figure}\n\\end{proof}\n\n\n\\subsection{Duality of regressors and residuals}\n\nThe idea of duality is widely used in mathematics.\nThe concept is to apply some transformation twice and get the~original object.\nFor example, if $f(a) = 1/a$:\n\\[\nx \\stackrel{f}{\\to} \\frac{1}{x} \\stackrel{f}{\\to} \\frac{1}{1/x} = x\n\\]\nWe show that there is duality between regressors and residuals.\n\n\\begin{theorem}\nLet $x_i$ be a $n \\times 1$ regressor,\n$u_i$ — a residual in regression of $x_i$ on all the rest regressors,  $i = 1, \\ldots, k$.\nConsider a transformation of a vector $v$, $f(v) = v/\\lVert v \\rVert^2$.\nThen applying this transformation on the residuals $u_1, \\ldots, u_k$ yields\nnew regressors $v_1, \\ldots, v_k$.\nPerforming $k$ regressions of each $v_i$ on all the rest regressors and\napplying the same transformation to the new residuals results in\nthe original regressors $x_1, \\ldots, x_k$.\n\\end{theorem}\n\n\\begin{proof}\n\n\\begin{marginfigure}[-2\\baselineskip]\n\\includegraphics[scale=0.7]{figures/02_duality_original_regressors.pdf}\n\\caption{Two regressors in the unit circle.}\n\\end{marginfigure}\n\nWe start with $2$-dimensional case with two regressors,\nand discuss the~case of spaces of higher dimensions later.\n\nAs stated in the~theorem we need to keep the~measure of the~lengths of the~regressors.\nIn order to do this we choose a~basis in $\\mathbb{R}^2$ in such a~way that\n\\begin{align*}\n&x_1 = \\lambda_1 e_1, \\quad \\lVert e_1 \\rVert = 1 \\\\\n&x_2 = \\lambda_2 e_2, \\quad \\lVert e_2 \\rVert = 1\n\\end{align*}\nwhere $\\lambda_1, \\lambda_2 \\in \\mathbb{R}$.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.7]{figures/02_duality_first_residuals.pdf}\n\\label{fig:duality_fst_residuals}\n\\caption{Residuals $\\hat{u}_1$ and $\\hat{u}_2$.}\n\\end{marginfigure}\n\nThen we perform two regressions\n\\begin{align*}\n&x_1 = \\beta_1 x_2 + u_1 \\\\\n&x_2 = \\beta_2 x_1 + u_2\n\\end{align*}\nand get the residuals $\\hat{u}_1$, $\\hat{u}_2$.\nBeing orthogonal to $x_2$ and $x_1$, correspondingly, they can be written as follows\n\\begin{align*}\n&\\hat{u}_1 = \\sin \\alpha \\cdot \\lambda_1 \\tilde{e}_1, \\quad \\lVert \\tilde{e}_1 \\rVert = 1 \\\\\n&\\hat{u}_2 = \\sin \\alpha \\cdot \\lambda_2 \\tilde{e}_2, \\quad \\lVert \\tilde{e}_2 \\rVert = 1\n\\end{align*}\nwhere $\\tilde{e}_1 \\perp e_2$ and $\\tilde{e}_2 \\perp e_1$.\n\nFor convenience we translate all the vectors $x_1$, $x_2$, $\\hat{u}_1$, $\\hat{u}_2$\nto the origin of the unit circle as shown in Figure~\\ref{fig:duality_fst_residuals_translated}\nand after that we invert them.\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.7]{figures/02_duality_inversion.pdf}\n\\label{fig:duality_inversion}\n\\caption{Example of inversion for vector $a$.}\n\\end{marginfigure}\n\nIn order to illustrate inversion consider an example with an arbitrary vector $a$.\nKnowing its length, the aim is to find such an orthogonal vector $\\tilde a$\nthat the product $\\lVert a \\rVert^2 \\cdot \\lVert \\tilde a \\rVert^2 = 1$.\nIn other words, we need to find an edge of rectangle with area equal to $1$.\nSolving for $\\tilde a$, we obtain the length of the inverted vector $a$.\nThe only thing left is to rotate this inverted vector back\nto get a vector $\\tilde{\\tilde a}$ which satisfies both\n\\begin{align*}\n& \\lVert \\tilde{\\tilde a} \\rVert^2 = \\frac{1}{\\lVert a \\rVert^2} \\\\\n& \\cos(a, \\tilde{\\tilde a}) = 1\n\\end{align*}\n\n\\marginnote[-2\\baselineskip]{\nThe transformation stated in the theorem is $f(v) = v / \\lVert v \\rVert^2$.\nGenerally speaking, $g(v) = v / (c \\cdot \\lVert v \\rVert^2)$ where $c \\in \\mathbb{R}$\nwould also work.\n\\begin{multline*}\nv \\stackrel{g}{\\to} \\frac{v}{c \\cdot \\lVert v \\rVert^2} = w \\stackrel{g}{\\to} \\\\\n\\frac{w}{c \\cdot \\lVert w \\rVert^2} = \\frac{\\frac{v}{c \\cdot \\lVert v \\rVert^2}}{c \\frac{\\lVert v \\rVert^2}{c^2 \\lVert v \\rVert^4}} = v\n\\end{multline*}\n}\n\nHaving applied the inversion to $\\hat{u}_1$, $\\hat{u}_2$, we obtained\nnew vectors $y_1$, $y_2$. Moreover, there is an algebraic expression for them\nin terms of rotated basis $\\tilde{e}_1$, $\\tilde{e}_2$:\n\\begin{align*}\n&\\hat{u}_1 = \\sin \\alpha \\cdot \\lambda_1 \\tilde{e}_1 \\Rightarrow y_1 = \\frac{1}{\\sin \\alpha \\cdot \\lambda_1} \\tilde{e}_1 \\\\\n&\\hat{u}_2 = \\sin \\alpha \\cdot \\lambda_2 \\tilde{e}_2 \\Rightarrow y_2 = \\frac{1}{\\sin \\alpha \\cdot \\lambda_2} \\tilde{e}_2 \\\\\n\\end{align*}\n\nNext, we perform another two regressions:\n\\begin{align*}\n& y_1 = \\gamma_1 y_2 + v_1 \\\\\n& y_1 = \\gamma_2 y_1 + v_2\n\\end{align*}\n\n\\begin{figure*}[ht!]\n\\begin{center}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_duality_first_residuals_translated.pdf}\n\\label{fig:duality_fst_residuals_translated}}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_duality_new_regressors.pdf}\n\\label{fig:duality_new_regreesors}}\n\\subfigure[]{\n\\includegraphics[width=0.3\\linewidth]{figures/02_duality_new_residuals.pdf}\n\\label{fig:duality_new_residuals}}\n\\caption{\\subref{fig:duality_fst_residuals_translated}: Residuals translated to the orgin of the unit circle;\n\\subref{fig:duality_new_regreesors}: Regressors $v_1$, $v_2$ obtained from inversion of the residuals $\\hat{u}_1$, $\\hat{u}_2$;\n\\subref{fig:duality_new_residuals}: Regressions of $v_1$ onto $v_2$ and of $v_2$ onto $v_1$.}\n\\end{center}\n\\end{figure*}\n\nThere are two things to notice about the new residuals $\\hat{v}_1$, $\\hat{v}_2$.\nFirst, $\\hat{v}_1$ is perpendicular to the line spanned by $\\tilde{e}_2$.\nSimilarly, $\\hat{v}_2$ is perpendicular to the line spanned by $\\tilde{e}_1$.\nThis means, that they are parallel to $e_1$, $e_2$, correspondingly,\nand once translated, they can be expressed as a multiple of $x_1$, $x_2$.\n\nSecond, we can find the lengths of these new residuals from the~right\ntriangles depicted in Figure~\\ref{fig:duality_new_residuals}:\n\\begin{align*}\n& \\lVert \\hat{v}_1 \\rVert = \\sin \\alpha \\cdot \\lVert y_2 \\rVert = \\sin \\alpha \\cdot \\left\\lVert \\frac{1}{\\sin \\alpha \\cdot \\lambda_1} \\tilde{e}_1 \\right\\rVert = \\frac{1}{\\lambda_1} \\\\\n& \\lVert \\hat{v}_2 \\rVert = \\sin \\alpha \\cdot \\lVert y_1 \\rVert = \\sin \\alpha \\cdot \\left\\lVert \\frac{1}{\\sin \\alpha \\cdot \\lambda_2} \\tilde{e}_2 \\right\\rVert = \\frac{1}{\\lambda_2}\n\\end{align*}\nThus, when translated to the origin, the new resiuduals can be rewritten as\n\\begin{align*}\n& \\hat{v}_1 = \\frac{1}{\\lambda_1} e_1 \\\\\n& \\hat{v}_2 = \\frac{1}{\\lambda_2} e_2\n\\end{align*}\n\n\\begin{marginfigure}[4\\baselineskip]\n\\includegraphics[scale=0.6]{figures/02_duality_final.pdf}\n\\label{fig:duality_final}\n\\caption{New residuals translated to the origin of the unit circle.}\n\\end{marginfigure}\n\nThe last step is to invert $\\hat{v}_1$, $\\hat{v}_2$.\nFollowing the same procedure as described above, we finally get the desired result:\n\\begin{align*}\n& \\hat{v}_1 = \\frac{1}{\\lambda_1} e_1 \\to \\lambda_1 e_1 = x_1 \\\\\n& \\hat{v}_2 = \\frac{1}{\\lambda_2} e_2 \\to \\lambda_2 e_2 = x_2\n\\end{align*}\n\\end{proof}\n\n\\vspace{3.5cm}\n\\subsection{Gauss-Markov theorem}\n\n\\begin{theorem}\nIn the homoskedastic linear regression model the best (minimum-variance) linear\nunbiased estimator is given by the ordinary least squares.\n\\end{theorem}\n\n\n\\begin{proof}\n\nConsider an OLS estimator and an alternative one:\n\\begin{align*}\n\\hat{\\beta}_{OLS} &= (X^T X)^{-1} X^T y = A^T y \\\\\n\\hat{\\beta}_{alt} &= A^T_{alt} y\n\\end{align*}\n\n% Hansen\n\\marginnote[-4\\baselineskip]{\nConsider an estimator $\\beta$ which is a linear function of $Y$:\n\\[\n\\hat \\beta = A^T Y\n\\]\nwhere $A$ is an $n \\times k$ function of $X$ such that $A^T X = I_k$.\nFrom\n\\begin{align*}\n\\Var(\\hat\\beta_{OLS}) &= (X^T X)^{-1} \\sigma^2 \\\\\n\\Var(A^T y) &= A^T A \\sigma^2\n\\end{align*}\nit follows that it is sufficient to prove that $A^T A - (X^T X)^{-1}$\nis positive semi-definite. Set $C = A - X(X^T X)^{-1}$ and note that $X^T C = 0$, then\n\\begin{multline*}\nA^T A - (X^T X)^{-1} \\\\\n= (C + X(X^T X)^{-1})^T (C + X(X^T X)^{-1}) - (X^T X)^{-1} \\\\\n= C^T C + C^T X(X^T X)^{-1} + (X^T X)^{-1} X^T C + \\\\\n(X^T X)^{-1} X^T X(X^T X)^{-1} - (X^T X)^{-1} \\\\\n= C^T C\n\\end{multline*}\nMatrix $C^T C$ is positive semi-definite since\n\\[\n\\forall a \\not= 0 \\qquad a^T C^T C a = \\lVert C a \\rVert^2 \\geq 0\n\\]\n}\n\nNote that $A^T X = I_{k}$, then the following holds for all $\\beta$:\n\\begin{align*}\nA^T X \\beta &= \\beta \\\\\nA^T_{alt} X \\beta &= \\beta\n\\end{align*}\nTaking the difference of these equations, we obtain:\n\\[\n\\left(A^T_{alt} - A^T\\right) X \\beta = 0 \\Rightarrow \\left(A^T_{alt} - A^T\\right) \\perp X\n\\]\nIf we treat the coefficients separately and consider, for instance, $\\beta^{(2)}$,\nwe get the following result\n\\[\n\\left(a^T_{alt} - a^T\\right) \\perp X\n\\]\nwhere $a_{alt}$ and $a$ are the second columns of matrices\n$A_{alt}$ and $A$ correspondingly.\nSince $a \\in \\Lin(\\col X)$, it follows that $a_{alt} \\not \\in \\Lin(\\col X)$.\n\n\\begin{marginfigure}[1\\baselineskip]\n\\includegraphics[scale=0.7]{figures/02_gmt.pdf}\n\\label{fig:gmt}\n\\caption{Gauss-Markov theorem for the case of three regressors\nwhere $a^{(1)}$, $a^{(2)}$, $a^{(3)}$ are columns of matrix $A$.}\n\\end{marginfigure}\n\nNow we can express the variances of both estimators in terms of $a_{alt}$ and $a$:\n\\begin{align*}\n\\Var\\left(\\hat{\\beta}^{(2)}_{OLS}\\right) &= \\Var\\left(a^T y\\right) = a^T \\sigma^2 I_{k} a = \\sigma^2 \\left\\lVert a \\right\\rVert^2 \\\\\n\\Var\\left(\\hat{\\beta}^{(2)}_{alt}\\right) &= \\Var\\left(a^T_{alt} y\\right) =  a^T_{alt} \\sigma^2 I_{k} a_{alt} = \\sigma^2 \\left\\lVert a_{alt} \\right\\rVert^2\n\\end{align*}\nSince vectors $a$, $a_{alt}$ and $a - a_{alt}$\nform a right triangle and $a_{alt} \\not \\in \\Lin(\\col X)$,\nthe vector $\\left\\lVert a_{alt} \\right\\rVert^2$ must be longer than $a$,\nand the corresponding estimator must have higher variance.\n\n\\end{proof}\n\n\\vspace{1cm}\n\n\\subsection{Geometry of instrumental variables}\n\nConsifder a model with an endogenity problem, i.e. explanotary variable $x$\nis correlated with the error term $u$:\n\\[\ny = \\beta x + u\n\\]\nAssume there is an instrument $z$ which is dependent with the problematic regressor $x$\nbut uncorrelated with the error term $u$.\nThe 2SLS procedure tells us to perform the following steps.\n\\begin{enumerate}\n  \\item Regress $x$ onto $z$ and get the vector of predicted values $\\hat x$,\n  \\item Regress $y$ onto $\\hat x$.\n\\end{enumerate}\nThese steps result in $\\beta_{IV}$ estimator which is illustrated in Figure~\\ref{fig:instrumental}.\n\nThe same result could be obtained with the oblique projection.\nThat is projecting $y$ onto $x$ along the vector perpendicular to the span of $z$.\n\n\\begin{marginfigure}[10\\baselineskip]\n\\includegraphics[scale=0.85]{figures/02_instr.pdf}\n\\caption{Geometry of instrumental variables. $A$ stands for $\\hat \\beta_{IV} \\hat x$,\n$B$ — $\\hat x$, $C$ — $x$, $D$ — $\\hat \\beta_{IV} x$.}\n\\label{fig:instrumental}\n\\end{marginfigure}\n\nThe equivalence of these two methods holds due to the similarity of triangles.\nConsider a plane $\\alpha$ which satisfies the property of being perpendicular\nto the span of $z$, $\\alpha \\perp z$.\nVectors $x$, $z$ and $\\hat x$ form a triangle which is denoted as $\\bigtriangleup OBC$\nwhere $\\overrightarrow{OB} = \\hat{x}$, $\\overrightarrow{OC} = x$.\nIn order to get an oblique projection of $y$ onto $x$ we could either\nproject $y$ directly onto $x$ staying in the plane $\\alpha$\nor get the same result in two steps. First, project $y$ onto $z$\nand then project the result onto $x$ which gives the same outcome\nby the theorem of three perpendiculars. Thus, we get another triangle $\\bigtriangleup OAD$\nwhere $\\overrightarrow{OA} = \\hat \\beta_{IV} \\hat x$, $\\overrightarrow{OD} = \\hat \\gamma x$.\nSince triangles $\\bigtriangleup OBC$ and $\\bigtriangleup OAD$ are similar\nit follows that\n\\[\n\\frac{OD}{OC} = \\frac{OA}{OB}\n\\]\nwhich means that\n\\[\n\\hat \\gamma = \\hat \\beta_{IV}.\n\\]\n\n\n\\subsection{Geometry of proxy variables}\n\nConsider a model\n\\[\ny = \\beta_1 x + \\beta_2 w + u\n\\]\nwhere the error term $u$ is not correlated with the regressors.\nSuppose that $w$ is an unobservable variable.\nOne way to deal with this problem and get a consistent estimator of $\\beta_1$ is to use a proxy variable.\nIn order to clearly state its properties we decompose the unobservable variable\ninto a sum of a multiple of the proxy ($pr$) and a part that is uncorrelated\nwith the proxy ($\\hat \\nu$):\n\\[\n\\hat w = \\gamma \\cdot pr + \\hat \\nu\n\\]\nThen the proxy variable must satisfy the following properties.\n\\begin{enumerate}\n  \\item It must be correlated with the unobservable variable $w$, $pr \\not\\perp w$.\n  \\item The error term $\\hat u$ must be uncorrelated with the proxy variable, $pr \\perp \\hat u$.\n  \\item The error term $\\hat \\nu$ must be uncorrelated with the regressor $x$, $x \\perp \\hat \\nu$.\n\\end{enumerate}\n\n\\begin{marginfigure}\n\\includegraphics[scale=0.85]{figures/02_proxy.pdf}\n\\caption{Geometry of proxy variables.}\n\\label{fig:proxy}\n\\end{marginfigure}\n\nTo get a consistent estimator of $\\beta_1$ we need to regress $y$ onto $x$ and $pr$.\nConsistency is illustarted in Figure~\\ref{fig:proxy}.\nSuppose we could get the $\\hat y$ by performing the original regression of\n$y$ onto $x$ and $w$. Then, $\\hat y$ could be decomposed in a sum of\n$\\hat \\beta_1 x$ and $\\hat \\beta_2 w$.\nNotice, that $\\hat y$ is both projection of $y$ onto $w$, $x$ and\nonto $w$, $x$, $pr$ due to the property of $\\hat \\nu$ being orthogonal to $x$.\nWhen projected onto the plane spanned by $x$ and $pr$, the $\\hat \\beta_1 x$\ncomponent stays the same as it is already in this plane\nwhile $\\hat \\beta_2 w$ projects onto the span of $pr$ by the second property of proxy variable.\n", "meta": {"hexsha": "ecc87b230dfae28eff2a02b0078789927a624112", "size": 43201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2_regression.tex", "max_stars_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_stars_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-11-22T20:38:41.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-22T20:38:41.000Z", "max_issues_repo_path": "chapters/2_regression.tex", "max_issues_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_issues_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-06-29T09:11:36.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-28T19:35:55.000Z", "max_forks_repo_path": "chapters/2_regression.tex", "max_forks_repo_name": "olyagnilova/gauss-markov-pythagoras", "max_forks_repo_head_hexsha": "9e2abb700846997576144c77e440f48107bde0d2", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-05-21T18:32:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T18:32:18.000Z", "avg_line_length": 39.5613553114, "max_line_length": 191, "alphanum_fraction": 0.6988958589, "num_tokens": 15015, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.879146761176671, "lm_q1q2_score": 0.7853500685642156}}
{"text": "\\section{Convex Optimisation}\r\nConsider the simple problem of minimizing $f(x)$ subject to $a\\le x\\le b$ in the case where $f:\\mathbb R\\to\\mathbb R$ is twice differentiable.\r\n\\begin{theorem}\r\n    If $x^\\star\\notin \\{a,b\\}$ is an optimal solution of the problem, then $f^\\prime(x^\\star)=0$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For sufficiently small $\\epsilon>0$ we can have both $x^\\star-\\epsilon$ and $x^\\star+\\epsilon$ are feasible (a fancy way of saying $(x^\\star-\\epsilon,x^\\star+\\epsilon)\\subset [a,b]$), then by optimality\r\n    $$\\frac{f(x^\\star)-f(x^\\star-\\epsilon)}{\\epsilon}\\le0\\le\\frac{f(x^\\star+\\epsilon)-f(x)}{\\epsilon}$$\r\n    Sending $\\epsilon\\to0$ gives the result.\r\n\\end{proof}\r\nAs well known, there is a partial converse to this theorem.\r\n\\begin{theorem}[Sufficient Condition for Optimality]\r\n    Suppose $x^\\star$ is feasible and $f^\\prime(x^\\star)=0$.\r\n    If $f^{\\prime\\prime}\\ge 0$ for all feasible $x$, then $x^\\star$ is optimal.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    By Taylor's Theorem (used correctly!), let $x$ be a feasible solution, then\r\n    $$f(x)=f(x^\\star)+f^\\prime(x^\\star)(x-x^\\star)+\\frac{1}{2}f^{\\prime\\prime}(\\xi)(x-x^\\star)^2$$\r\n    for some $\\xi$ in between $x$ and $x^\\star$.\r\n    As $f^\\prime(x^\\star)=0$ and $f^{\\prime\\prime}(\\xi)\\ge 0$ by assumption, $f(x)\\ge f(x^\\star)$.\r\n\\end{proof}\r\nThe one-dimensional optimisation problems are widely studied and there is not much point to continue talking about it.\r\nLet's move on to higher dimensions.\r\nAs it turns out, convexity helps a lot on problems without a functional constraint.\r\n\\subsection{General Ideas on Convexity}\r\nNotationally, for a differentiable function $f:\\mathbb R^n\\to\\mathbb R$, we write $Df$ as its gradient and, when $f$ is twice differentiable, $D^2f$ as its Hessian.\r\nRecall that the Hessian is symmetric at $x$ when all the second order partial derivatives are continuous at $x$.\r\n\\begin{definition}\r\n    A set $X\\subset\\mathbb R^n$ is convex if for every pair of points $x,y\\in X$ and number $0<p<1$ we have $px+(1-p)y\\in X$.\\\\\r\n    Loosely speaking, the line segment joining $x$ and $y$ is still in $X$.\r\n\\end{definition}\r\nOne should note that our solution to the previous one dimensional optimisation problem somehow depends on the convexness of the contraint set.\r\n\\footnote{Of course, even if it is not, we can sometimes produce similar results as well}\r\n\\begin{definition}\r\n    Let $X\\subset\\mathbb R^n$ be convex.\r\n    A function $f:X\\to\\mathbb R$ is convex if for every pair of points $x,y\\in X$ and $p\\in (0,1)$,\r\n    $$f(px+(1-p)y)\\le pf(x)+(1-p)f(y)$$\r\n\\end{definition}\r\nRespectively, a function is concave if its negative is convex.\r\nThis definition is intuitive in one dimension, but might not be that easy to illustrate in higher dimensions on first sight.\r\nWe therefore need the following reformulation of the idea.\r\n\\begin{theorem}[Supporting Hyperplane]\\label{hyperplane}\r\n    Let $X\\subset\\mathbb R^n$ be convex.\r\n    The function $f:X\\to\\mathbb R$ is convex iff for every $x\\in X$ there exists a vector $\\lambda(x)\\in\\mathbb R^n$ such that\r\n    $$f(y)-f(x)\\ge\\lambda(x)^\\top(y-x)$$\r\n    for all $y\\in X$.\r\n\\end{theorem}\r\n\\begin{remark}\r\n    If $f$ is also differentiable, then we can take $\\lambda(x)=Df(x)$.\r\n\\end{remark}\r\nOne can picture it as if the hyperplane produced by $\\lambda(x)$ touches and supports the high-dimensional object that is the graph of the function.\r\nThis is the origin of the name.\\\\\r\nWe will prove the case when $f$ is differentiable, but the general case is also true.\r\n\\begin{proof}\r\n    Almost immediate but let's write this out.\r\n    First suppose $\\lambda(x)$ exists for all $x$.\r\n    Fix $y,z\\in X$ and $p\\in (0,1)$ and let $x=py+(1-p)z$, then\r\n    $$f(y)-f(x)\\ge\\lambda(x)^\\top(y-x),f(z)-f(x)\\ge\\lambda(x)^\\top(z-x)$$\r\n    So\r\n    $$pf(y)+(1-p)f(z)\\ge\\lambda(x)^\\top(py+(1-p)z-x)+f(x)=f(x)$$\r\n    Conversely, if $f$ is convex, we can just take $\\lambda(x)=Df(x)$.\r\n\\end{proof}\r\nHence, for the problem of minimising $f(x)$ subject to $x\\in X$ where $X$ is convex and $f:X\\to\\mathbb R$ is differentiable, we have\r\n\\begin{theorem}\r\n    Suppose $x^\\star$ is feasible and $Df(x^\\star)=0$.\r\n    If $f$ is convex, then $x^\\star$ is optimal.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Suppose $x$ is feasible, then by convexity of $f$,\r\n    $$f(x)-f(x^\\star)\\ge(x-x^\\star)^\\top Df(x^\\star)=0$$\r\n    which is what we wanted.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A symmetric $n\\times n$ matrix $A$ is non-negative definite if for every $x\\in\\mathbb R^n$ we have $x^\\top Ax\\ge 0$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $X\\subset\\mathbb R^n$ be convex and suppose $f:X\\to\\mathbb R^n$ is $C^2$.\r\n    If $D^2f$ is nonnegative definite for all $x$, then $f$ is convex.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    For any $x,y\\in X$ we have, by Taylor's Theorem that\r\n    $$f(y)=f(x)+(y-x)^\\top Df(x)+\\frac{1}{2}(y-x)^\\top D^2f(\\xi)(y-x)$$\r\n    where $\\xi=px+(1-p)y$ for some $p\\in(0,1)$.\r\n    Therefore $f(y)-f(x)\\ge Df(x)^\\top(y-x)$, hence it is convex.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Given a convex set $X\\subset\\mathbb R^n$, a function $f:X\\to\\mathbb R$ is strictly convex if for every $x,y\\in X$ where $x\\neq y$ and every number $p\\in (0,1)$ we have\r\n    $$f(px+(1-p)y)<pf(x)+(1-p)f(y)$$\r\n\\end{definition}\r\n\\begin{definition}\r\n    An $n\\times n$ matrix $A$ is positive definite if $x^\\top Ax>0$ for all $x\\in\\mathbb R^n\\setminus\\{0\\}$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Suppose $f:X\\to\\mathbb R$ is twice differentiable.\r\n    If $D^2f$ is positive definite over all of $X$, then $f$ is strictly convex.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Same idea as in the ordinary convex case.\r\n\\end{proof}\r\n\\begin{theorem}[Uniqueness of Optimal Solutions]\r\n    Suppose $x^\\star$ and $y^\\star$ are optimal solutions to the problem of minimising $f(x)$ subject to $x\\in X$ with $X$ convex and $f$ strictly convex, then $x^\\star=y^\\star$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    If $x^\\star\\neq y^\\star$, then let $z=(x^\\star+y^\\star)/2$, then\r\n    $$f(z)<\\frac{1}{2}f(x^\\star)+\\frac{1}{2}f(y^\\star)=f(x^\\star)$$\r\n    Contradiction.\r\n\\end{proof}\r\n\\begin{definition}\r\n    A function $f:X\\to\\mathbb R$ is strongly convex if there exists a constant $m>0$ such that the function $x\\mapsto f(x)-m\\|x\\|^2/2$ is convex.\r\n\\end{definition}\r\nThis defintion is certainly strange and unintuitive, but as we proceed, we will unveil the reason to introduce this notion.\r\n\\begin{theorem}\r\n    Suppose $f$ is twice differentiable.\r\n    Then $f$ is strongly convex if there exists $m>0$ such that for all $x\\in X$ the matrix $D^2f(x)-mI$ is non-negative definite.\r\n    Equivalently, $z^\\top D^2f(x)z\\ge m\\|z\\|^2$ for all $z\\in\\mathbb R^n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\nOne can check that strongly convex functions are also strictly convex.\r\n\\begin{theorem}[Existence of an Optimal Solution]\r\n    Suppose $X\\subset\\mathbb R^n$ is closed and $f$ is strongly convex, then there exists an optimal solution to the problem of minimising $f(x)$ subject to $x\\in X$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $g(x)=f(x)-m\\|x\\|^2/2$ where $m>0$ such that $g$ is convex, then there is a vector $\\lambda=\\lambda(0)$ such that\r\n    $$g(x)\\ge g(0)+\\lambda^\\top x\\ge g(0)-\\|\\lambda\\|\\|x\\|$$\r\n    by Cauchy-Schwartz.\r\n    So for $\\|x\\|>R=2\\|\\lambda\\|/m$ we have $f(x)>f(0)$ by rearranging.\r\n    So our problem reduces to minimising $f(x)$ subject to $x\\in X\\cap B$ where $B$ is the closed ball of radius $R$.\r\n    But $X\\cap B$ is closed and bounded, hence is compact, therefore $f$ attains a minimum somewhere in it, which is the optimal sulution we want.\r\n\\end{proof}\r\n\\begin{theorem}[Gradient Lower Bound]\\label{gradient_lower_bound}\r\n    Suppose $f:X\\to\\mathbb R$ is differentiable and strongly convex with constant $m>0$, then\r\n    $$\\|Df(x)\\|^2\\ge 2m(f(x)-f(y))$$\r\n    for any $x,y\\in X$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    From the Theorem \\ref{hyperplane},\r\n    $$f(y)-f(x)\\ge(y-x)^\\top Df(x)+\\frac{m}{2}\\|y-x\\|^2$$\r\n    However, by simply conpleting the square, for any $b,z\\in\\mathbb R^n$,\r\n    $$b^\\top z+\\frac{m}{2}\\|z\\|^2\\ge-\\frac{\\|b\\|^2}{2m}$$\r\n    Combining the inequalities give the solution.\r\n\\end{proof}\r\n\\subsection{Computing the Optimal Solution}\r\nOur most familiar example of a convex set is $X=\\mathbb R^n$.\r\nWe want to find algorithms to compute the optimal solution in this case.\r\nOur first method of interest is called gradient descent.\r\nSuppose $f$ is differentiable.\r\nThe rate of change of $f$ at a point $x\\in\\mathbb R^n$ in direction $u\\in\\mathbb R^n$ is\r\n$$\\lim_{t\\to 0}\\frac{f(x+tu)-f(x)}{t}=u^\\top Df(x)$$\r\nwhich attains minimum when $u$ is in the direction $-Df(x)$ by Cauchy-Schwartz.\\\\\r\nSo our algorithm will be as follows:\r\nStart with an initial guess $x_0\\in\\mathbb R^n$ and pick a step suze $t>0$.\r\nFor every $k\\ge 0$, we use the iteration\r\n$$x_{k+1}=x_k-tDf(x_k)$$\r\nto refine our guess.\r\nIntuitively, this should get closer and closer to an optimal solution.\r\nThis might or might not be true, but for a sufficiently nice function $f$ we have the following theorem:\r\n\\begin{theorem}\r\n    Suppose $f$ is $C^2$ and there exists positive constants $M>m>0$ such that $mI\\preceq D^2f(x)\\preceq MI$ for all $x\\in\\mathbb R^n$.\r\n    Here, two symmetric matrices $A,B$ has $A\\preceq B$ iff $x^\\top Ax\\le x^\\top Bx$ for every $x\\in\\mathbb R^n$.\r\n    The lower bound, in particular, implies the strong convexity, hence existence and uniqueness of $x^\\star$.\r\n    Then the gradient algorithm with step size $t=1/M$ has\r\n    $$f(x_k)-f(x^\\star)\\le\\left( 1-\\frac{m}{M} \\right)^k(f(x_0)-f(x^\\star))$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Fix $x,y\\in\\mathbb R^n$, then by Taylor's Theorem, there is some $p\\in (0,1)$ such that for $\\xi=px+(1-p)y$ we have\r\n    \\begin{align*}\r\n        f(y)&=f(x)+(y-x)^\\top Df(x)+\\frac{1}{2}(y-x)^\\top D^2f(\\xi)(y-x)\\\\\r\n        &\\le f(x)+(y-x)^\\top Df(x)+\\frac{M}{2}\\|y-x\\|^2\r\n    \\end{align*}\r\n    Apply this inequality to $y=x_{k+1},x=x_k$ gives\r\n    \\begin{align*}\r\n        f(x_{k+1})-f(x_k)&\\le (x_{k+1}-x_k)^\\top Df(x_k)+\\frac{M}{2}\\|x_{k+1}-x_k\\|^2\\\\\r\n        &=\\left( -t+\\frac{M}{2}t^2 \\right)\\|Df(x_k)\\|^2\\\\\r\n        &=-\\frac{1}{2M}\\|Df(x_k)\\|^2\\\\\r\n        &\\le-\\frac{m}{M}(f(x_k)-f(x^\\star))\r\n    \\end{align*}\r\n    Rearranging gives\r\n    $$f(x_{k+1})-f(x_k)\\le\\left( 1-\\frac{m}{M} \\right)(f(x_k)-f(x^\\star))$$\r\n    Using this recursively gives the estimate we need.\r\n\\end{proof}\r\nThis is certainly a very nice method since the rate of convergence we arrive at looks quite promising.\r\nThere is, of course, a better method similar to our familiar formualtion of Newton's method of finding root (since very roughly speaking we are finding a root of the derivative) but in high dimensions.\r\nTo confuse people, we shall also call this Newton's method.\\\\\r\nSuppose $f$ is $C^2$ and let $x_0$ be an initial guess for the optimiser, then by Taylor's Theorem,\r\n$$f(x)\\approx f(x_0)+(x-x_0)Df(x_0)+\\frac{1}{2}(x-x_0)^\\top D^2f(x_0)(x-x_0)$$\r\nas $x\\to x_0$ due to the continuity of $D^2f$.\r\nMinimising the quadratic term on the right yields the approximation\r\n$$x^\\star\\approx x_0-(D^2f(x_0))^{-1}Df(x_0)$$\r\nFormally, we are referring to the recursion\r\n$$x_{k+1}=x_k-(D^2f(x_0))^{-1}Df(x_0)$$\r\nAs before, we want to know if it works.\r\n\\begin{definition}\r\n    Let $A$ be an $n\\times n$ matrix.\r\n    We define the matrix norm $\\|A\\|$ as\r\n    $$\\|A\\|=\\inf\\{a\\ge 0:\\forall z\\in\\mathbb R^n,\\|Az\\|\\le a\\|z\\|\\}=\\sup_{\\|z\\|=1}\\|Az\\|$$\r\n    In particular, if $A$ is nonnegative definite, then $\\|A\\|$ is the smallest eigenvalue of $A$.\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Suppose $f$ is twice differentiable and there exists constants $m,L>0$ with $D^2f(x)\\succeq mI$ (so $f$ is strongly convex) and\r\n    $$\\forall x,y\\in\\mathbb R^n,\\|D^2f(x)-D^2f(y)\\|\\le L\\|x-y\\|$$\r\n    (so $D^2f$ is $L$-Lipschitz), then Newton's method guarantees that\r\n    $$f(x_k)-f(x^\\star)\\le \\frac{2m^3}{L^2}\\left(\\frac{L}{2m^2}\\|Df(x_0)\\|\\right)^{2^{k+1}}$$\r\n\\end{theorem}\r\nNote that this convergence rate is way quicker than using gradient descent.\r\n\\begin{proof}\r\n    Denote $\\Delta x_k=x_{k+1}-x_k=-(D^2f(x_0))^{-1}Df(x_0)$, then we have\r\n    \\begin{align*}\r\n        \\|Df(x_{k+1})\\|&=\\|Df(x_{k+1})-Df(x_k)-D^2f(x_k)\\Delta x_k\\|\\\\\r\n        &=\\left\\|\\int_0^1(D^2f(x_k+t\\Delta x_k)-D^2(x_k))\\Delta x_k\\,\\mathrm dt\\right\\|\\\\\r\n        &\\le\\int_0^1\\|(D^2f(x_k+t\\Delta x_k)-D^2(x_k))\\Delta x_k\\|\\,\\mathrm dt\\\\\r\n        &\\le L\\|\\Delta x_k\\|^2\\int_0^1t\\,\\mathrm dt\\\\\r\n        &=\\frac{1}{2}L\\|(D^2f(x_0))^{-1}Df(x_0)\\|^2\\\\\r\n        &\\le\\frac{L}{2m^2}\\|Df(x_k)\\|^2\r\n    \\end{align*}\r\n    Note here that we have used the fact that $A\\succeq mI\\implies \\|A^{-1}\\|\\le 1/m$ which is quite obvious.\r\n    Applying this inequality recursively yields\r\n    $$\\sqrt{2m(f(x_k)-f(x^\\star))}\\le\\|Df(x_k)\\|\\le\\frac{2m^2}{L}\\left( \\frac{L}{2m^2}\\|Df(x_0)\\| \\right)^{2^k}$$\r\n    by Theorem \\ref{gradient_lower_bound}.\r\n    Rearranging shows what we want.\r\n\\end{proof}", "meta": {"hexsha": "2e665301b800a27fa535e771a9a98863791a6e3f", "size": 12887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/convex.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "1/convex.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "1/convex.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.0495495495, "max_line_length": 207, "alphanum_fraction": 0.6503453092, "num_tokens": 4456, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8933094046341532, "lm_q1q2_score": 0.7853500669841751}}
{"text": "\n\\subsection{Martingale property}\n\nFor a process with the Martingale property, the expected value of all future variables is the current state.\n\nThis only restricts expectations.\n\n\\(E(X_{n+1}|X_0,...,X_n)=X_n\\)\n\n", "meta": {"hexsha": "48b6ae469567a558e0e5723b583fb00d69ce8012", "size": 212, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/martingale/01-01-martingale.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/martingale/01-01-martingale.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/martingale/01-01-martingale.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.2, "max_line_length": 108, "alphanum_fraction": 0.7547169811, "num_tokens": 57, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810511092412, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7853209155292022}}
{"text": "%---------------------------Skew---------------------------\n\\section{Skew\\label{s:hex-skew}}\n\nTo compute the skew, we'll need to compute normalized versions of the 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\\hat{X_3} &=& \\frac{\\vec X_3}{\\normvec{ X_3 }}\n\\end{array}\n\\]\nSkew measures the degree to which a pair of vectors are parallel using the dot product.\nThis means we have three skews to consider for a hexahedron, each of which is the\nabsolute value of the cosine of the angle between two principal axes:\n\\[\n\\begin{array}{lcl}\nskew_{12} &=& \\left| \\hat{X_1} \\cdot \\hat{X_2} \\right|\\\\\nskew_{13} &=& \\left| \\hat{X_1} \\cdot \\hat{X_3} \\right|\\\\\nskew_{23} &=& \\left| \\hat{X_2} \\cdot \\hat{X_3} \\right|.\n\\end{array}\n\\]\nThe metric is then the maximum of these skews\n\\[\n  q = \\max\\left\\{ skew_{12}, skew_{13}, skew_{23} \\right\\}\n\\]\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2}$ or $\\normvec{X_3} \\leq DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{skew}%\n{$1$}%                                        Dimension\n{$[0,0.5]$}%                                  Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[0,DBL\\_MAX]$}%                             Full range\n{$0$}%                                        Cube\n{Adapted from \\cite{tf:89}}%                  Citation\n{v\\_hex\\_skew}%                               Verdict function name\n", "meta": {"hexsha": "11d38b542aaf488458cdabe1f9040d7cde7b6169", "size": 1459, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexSkew.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/HexSkew.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/HexSkew.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.4324324324, "max_line_length": 104, "alphanum_fraction": 0.5352981494, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7852944868966456}}
{"text": "\\subsection{One-time pad}\n\\label{preliminaries:sym:otp}\n\nA one-time pad (OTP) is an symmetric encryption scheme where the keys, messages, and ciphertexts are of the same length and the key is never reused or repeated. The scheme is defined as follows~\\cite{kiagias:crypto, boneh_crypto}:\n\n\\begin{itemize}\n  \\item Space: $\\calm = \\calc = \\calk = \\{0, 1\\}^{n}$\n  \\item Encryption: $Enc_k(m) = k \\xor m$\n  \\item Decryption: $Dec_k(c) = k \\xor c$\n\\end{itemize}\n\nThe one-time pad is a \\textbf{perfectly secure} scheme~\\cite{kiagias:crypto, boneh_crypto}. The main drawback lies in the fact that the key must be at least the length of the original message. If a party wants to encrypt and sent 1GB video to another party, they must have already share a 1GB key. It is proven~\\cite{shannon_otp} that perfect security (or perfect secrecy) can only be achieved when the key size is at least as long as the size of the message. As a consequence, perfect security schemes are impossible to use in practice.\n\n\\subsection{Stream Ciphers}\n\\label{preliminaries:sym:stream}\n\nIn~\\ref{preliminaries:sym:otp} we saw that a symmetric scheme to be perfectly secure, keys and messages must have at least the same length. However, with weaker notion of security we can create symmetric encryption schemes where the size of the key $k$ is much shorter than the original message. Stream ciphers can encrypt or decrypt arbitrary long messages with small fixed length size keys. Instead of using a key of size $n$, a shorter seed $s$ of $l$-bits, where $l$ is much smaller than $n$, is used as the symmetric key. Then from the seed $s$ a $n$-bit key is derived and is used for encryption and decryption. The seed $s$ is expanded to $n$ by a deterministic polynomial algorithm $G$ that maps $l$-bit strings to $n$-bit strings. The algorithm $G$ is called \\textbf{pseudorandom generator} (PRG) and the following condition must hold for any PRG~\\cite{Katz:2014:IMC:2700550}:\n\n\\begin{itemize}\n  \\item Expansion: On input $s \\in \\{0, 1\\}^{l}$ outputs $k \\in \\{0, 1\\}^{n}$ where $\\forall l: n > l$\n  \\item Pseudorandomness: Lets $\\cald$ be a distribution over strings of length $n$. $\\cald$ is indistinguishable from the uniform distribution over strings of length $n$. In other words, it is infeasible for any polynomial-time algorithm to tell whether it is given a string sampled according to $\\cald$ or uniformly at random.\n\\end{itemize}\n\nSo, with the use of PRGs we can construct encryption schemes with short key sizes and long messages. A stream chipher is defined as follows:\n\n\\begin{itemize}\n  \\item The key generation algorithm $\\calg$: Takes as input a security parameter $1^{n}$ and outputs a seed $s \\in \\{0, 1\\}^{l}$ chosen uniformly at random.\n  \\item The encryption algorithm $\\cale$: Takes as input a seed $s \\in \\{0, 1\\}^{l}$ and a message $m \\in \\{0, 1\\}^{n}$ and outputs the ciphertext $c = Enc_s(m) = G(s) \\xor m$\n  \\item The decryption algorithm $\\cald$: Takes as input a seed $s \\in \\{0, 1\\}^{l}$ and a cipher $c \\in \\{0, 1\\}^{n}$ and outputs the plaintext $m = Dec_s(c) = G(s) \\xor c$\n\\end{itemize}\n\nAn important point, is that $s$ must be chosen uniformly at random and be long enough to withstand brute-force attacks.\n\nThere is a number of practical constructed stream ciphers. The most wide used are Salsa20~\\cite{Salsa20}, ChaCha~\\cite{chacha} and RC4.\n\n\\subsection{Diffie–Hellman key exchange}\n\\label{preliminaries:pub:dh}\n\nThe protocol works as follows~\\cite{Katz:2014:IMC:2700550, kiagias:crypto}:\n\n\\begin{enumerate}\n  \\item Alice and Bob  with the use of a group generation algorithm $\\calg$ agree on the description of a finite group $\\G$ with input $1^{n}$. The common input for Alice and Bob is the tuple $(p, m, g)$ where $p$ is a large prime and $g$ is the generator of the finite group $\\G$ of order $m$.\n  \\item Alice choose a random index $x_a \\rselect{\\Z_m}$ and computes $y_a \\leftarrow{g^{x_a}}modp$. Alice sends $y_a$ to Bob.\n  \\item Bob choose a random index $x_b \\rselect{\\Z_m}$ and computes $y_b \\leftarrow{g^{x_b}}modp$. Alice sends $y_b$ to Bob.\n  \\item Alice outputs $k = y_b^{x_a}modp = g^{{x_a}{x_b}}modp$\n  \\item Bob outputs $k = y_a^{x_b}modp = g^{{x_a}{x_b}}modp$\n\\end{enumerate}\n\nThe security of Diffie–Hellman key exchange is based on the difficulty of the discrete log problem (DLOG), which is the problem of computing $x$ given $g^{x}$ in a cyclic group $\\G$. A passive adversary cannot compute the private key $k$ because she does not know $x_a$ or $x_b$. To find them she have to compute the discrete log which is assumed to be hard.\n\n\\begin{figure}[!hb]\n  \\centering\n  \\begin{tikzpicture}\n    \\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=4mm, nodes={draw=none, anchor=center,text depth=0pt} ]{\n    Alice & & Bob\\\\\n    $x_a \\rselect{\\Z_m}$ & & $x_b \\rselect{\\Z_m}$ \\\\\n    $y_a \\leftarrow{g^{x_a}}modp$ & & $y_b \\leftarrow{g^{x_b}}modp$ \\\\\n     & $y_a$ & \\\\\n     & $y_b$ & \\\\\n     $k = y_b^{x_a}modp$ & & $k = y_a^{x_b}modp$ \\\\\n    };\n\n    \\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-1.south east)--(m-1-1.south west);\n    \\draw[shorten <=-1.5cm,shorten >=-1.5cm] (m-1-3.south east)--(m-1-3.south west);\n    \\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-4-2.south west)--(m-4-2.south east);\n    \\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-5-2.south east)--(m-5-2.south west);\n\n  \\end{tikzpicture}\n  \\caption{Diffie–Hellman key exchange}\n  \\label{fig:crypto:dh}\n\\end{figure}\n\n\\subsection{The RSA Cryptosystem}\n\\label{preliminaries:pub:rsa}\n\nThe RSA cryptosystem~\\cite{rsa} was developed in 1977 at MIT by Ron Rivest, Adi Shamer, and Leonard Adleman and is still the most widely used. It was the first public-key encryption scheme that could both encrypt and sign messages~\\cite{kiagias:crypto}.\n\nIt works as follows~\\cite{Katz:2014:IMC:2700550, kiagias:crypto}:\n\n\\begin{itemize}\n  \\item Key Generation:\n    \\begin{enumerate}\n      \\item Select randomly to large primes $p, q$ of length $n$ bits\n      \\item Compute $N = p*q$\n      \\item Calculate $\\phi(N) = (p - 1)(q - 1)$\n      \\item Find $e$ such that $gcd(e, \\phi(N)) = 1$\n      \\item Compute $d = e^{-1} mod\\phi(N)$\n      \\item Public key is $(N, e)$ and private key is $(N, d)$\n    \\end{enumerate}\n  \\item Encryption: On input a public key $p_k = (N, e)$ and a message $m$ it computes the ciphertext $c$ as $ Enc_{p_k}(m) = m^{e}modN$\n  \\item Decryption: On input a private key $s_k = (N, d)$ and a ciphertext $c$ it computes the message $m$ as $ Dec_{s_k}(c) = c^{d}modN = m^{ed}modN = m$\n\\end{itemize}\n\nIf $p, q$ are known or obvious any interested party can compute $\\phi(N)$ and therefore $d$. The RSA Cryptosystem is secure under the assumption that factorization of $N$ is believed to be hard.\n\nThe above mention protocol is not secure as the encryption function is deterministic and for the same input is produces the same output. As mention, a deterministic cryptosystem is not secure. One way to randomize the encryption function, is by appending random padding to message.\n\n\\subsection{The El Gamal Cryptosystem}\n\\label{preliminaries:pub:el_gamal}\n\nThe El Gamal Cryptosystem~\\cite{el_gamal} is another popular and wide-used encryption scheme. The security of the system is based on the hardness of discrete log problem. It works as follows~\\cite{Katz:2014:IMC:2700550, kiagias:crypto}:\n\n\\begin{itemize}\n  \\item Key generation:\n    \\begin{enumerate}\n        \\item Run a group generation algorithm $\\calg$ to produce the description of a finite group $\\G$ with input $1^{n}$. The output is the tuple $(p, m, g)$ where $p$ is a large prime and $g$ is the generator of the finite group $\\G$ of order $m$.\n        \\item Select randomly $x \\rselect{\\Z_m}$\n        \\item Calculate $h = g^{x}modp$\n        \\item The public key is $((p, m, g), h)$\n        \\item The secret key is $x$\n    \\end{enumerate}\n  \\item Encryption: Encrypts a message $m \\in \\G$\n    \\begin{enumerate}\n      \\item Choose randomly $r \\rselect{\\Z_m}$\n      \\item Compute $G = g^{r}modp$\n      \\item Compute $M = mh^{r}modp$\n      \\item Return $c = (G, M)$\n    \\end{enumerate}\n  \\item Decryption: Decrypts a ciphertext $c = (G, M)$\n    \\begin{enumerate}\n      \\item Compute $m = M / G^{x} modp$\n      \\item Return $m$\n    \\end{enumerate}\n\\end{itemize}\n\nAnother way to express the security of El Gamal scheme is under the decisional Diffie Hellman problem (DDH) which states that the tuples $(g^a, g^b, g^c)$ and $(g^a, g^b, g^{ab})$ are indistinguishable by a probabilistic polynomial-time (PPT) adversary.\n\n\\subsection{RSA signatures}\n\\label{preliminaries:sign:rsa}\n\nAs describes in~\\ref{preliminaries:pub:rsa} the RSA cryptosystem can be used to sign messages. The RSA digital signature scheme works as follows~\\cite{Katz:2014:IMC:2700550, kiagias:crypto}:\n\n\\begin{itemize}\n  \\item Key Generation:\n    \\begin{enumerate}\n      \\item Select randomly to large primes $p, q$ of length $n$ bits\n      \\item Compute $N = p*q$\n      \\item Calculate $\\phi(N) = (p - 1)(q - 1)$\n      \\item Find $e$ such that $gcd(e, \\phi(N)) = 1$\n      \\item Compute $d = e^{-1} mod\\phi(N)$\n      \\item Verification key is $(N, e)$ and signing key is $(N, d)$\n    \\end{enumerate}\n  \\item Sign: On input a sign key $s_k = (N, d)$ and a message $m \\in \\Z^{*}_{N}$ it computes the signature $\\sigma$ as $ Sign_{s_k}(m) = m^{d}modN$\n  \\item Verify: On input a verification key $p_k = (N, e)$, a message $m \\in \\Z^{*}_{N}$ and a signature $\\sigma \\in \\Z^{*}_{N}$ it outputs $1$ if and only if $m \\stackrel{?}{=} Verify_{p_k}(\\sigma, m) = \\sigma^{e}modN$\n\\end{itemize}\n\nThe above signature scheme is not secure as an adversary can forge a sign, based on the public key alone, by choosing an arbitrary $\\sigma \\in \\Z^{*}_{N}$ and compute $m = \\sigma^{e}modN$. Another attack on the RSA signature scheme allows the adversary to output a forgery on any message of the adversary's choice. One proposal to protect against those attacks, that can be proven secure under certain assumptions, is by applying a cryptographic hash function $H$ to the message before sign it. The minimal requirement for the system to be secure is that $H$ must be collision-resistant.\n\n\\subsection{Diffie-Hellman key exchange}\n\\label{preliminaries:el_curves:dh}\n\nThe elliptic curve analogue of Diffie-Hellman key exchange protocol (ECDH) defined in~\\ref{preliminaries:pub:dh} can implemented as follows~\\cite{elliptic_curves}:\n\n\\begin{enumerate}\n  \\item Alice and Bob agree on elliptic curve $E$ over a finite field $F_p$ for a prime $p$ such that the discrete log problem is hard in $E$ over $F_p$. They also agree on a point $P$ on $E$.\n  \\item Alice choose a secret integer $a$ and computes $P_a = aP$. Alice sends $P_a$ to Bob\n  \\item Bob choose a secret integer $b$ and computes $P_b = bP$. Bob sends $P_b$ to Alice\n  \\item Alice computes $k = aP_b = abP$\n  \\item Bob computes $k = bP_a = abP$\n\\end{enumerate}\n\nThe security of the protocol is based on ECDLP (§~\\ref{preliminaries:el_curves:key_gen}).\n\n\\subsection{The El Gamal Cryptosystem}\n\\label{preliminaries:el_curves:el_gamal}\n\nThe elliptic curve analogue of El Gamal cryptosystem defined in~\\ref{preliminaries:pub:el_gamal} can implemented as follows~\\cite{elliptic_curves_2}:\n\n\\begin{itemize}\n  \\item Key generation: Run elliptic curve key generation algorithm defined in~\\ref{preliminaries:el_curves:key_gen} and get a key pair $(Q, d)$.\n  \\item Encryption: Encrypts a message $m$ represented as a point $M$ in $E$ over $\\F_p$\n    \\begin{enumerate}\n      \\item Choose randomly $r \\rselect{\\in \\Z_q}$\n      \\item Compute $G = rP$\n      \\item Compute $C = M + rQ$\n      \\item Return $c = (G, C)$\n    \\end{enumerate}\n  \\item Decryption: Decrypts a ciphertext $c$\n    \\begin{enumerate}\n      \\item Compute $M = C - dG$, and extract $m$ from $M$\n      \\item return $M$\n    \\end{enumerate}\n\\end{itemize}\n\nAn eavesdropper adversary who wants to obtain $M$ needs to compute $rQ$; given $Q$, $P$ and $G = rP$ find $r \\in Z_q$. This is the elliptic curve analogue of the Diffie-Hellman problem.\n\n\\subsection{Enigma}\\label{blockchain:impl:enigma}\n\nEnigma is a decentralized computation platform with guaranteed privacy~\\cite{DBLP:journals/corr/ZyskindNP15}. It operates through a peer-to-peer network enabling\ndifferent parties to store and run computation on data while keeping privacy. Enigma uses a highly optimized version of secure multi-party computation (MPC)\nguaranteed by a verifiable secret-sharing scheme~\\cite{DBLP:journals/corr/ZyskindNP15}. A blockchain is utilized as the controller of the network, managing access to the data and identities.\nThe data are stored off-chain, encrypted in a distributed database, and a modified distributed hash table (DTH), accessible through the blockchain, is used for holding only references to the data.\n\n\\subsection{zksnarks}\\label{zksnarks}\n\nThe main idea for constructing zkSNARKs is firstly to transform the generic program as a quadratic equation of polynomials (QAP)~\\cite{ggpr}: $p(x)q(x) = s(x)r(x)$, where the equality holds if and only if the program is computed correctly. So the prover wants to convince the verifier that the equality holds.\n\nSuccinctness is achieved by random sampling. The verifier chooses a secret evaluation point $x_0$ to reduce the problem from polynomial multiplication and equality to simple number arithmetic checks: $p(x_0)q(x_0) = s(x_0)r(x_0)$. To allow the prover to compute the evaluation of the polynomials at $x_0$, without revealing $x_0$, Homomorphic encryption is used:  $E(p(x_0))E(q(x_0)) = E(s(x_0))E(r(x_0))$.\n\nFinally the prover obfuscates the encrypted values by multiplying with a number so that the verifier can still check the correctness of the structure without knowing the actual encrypted values: $E(k + p(x_0))E(k + q(x_0)) = E(k + s(x_0))E(k + r(x_0))$.\n\n% Introduction\n\nIn the big data era, huge amounts of data are constantly being collected and analyzed, evidently, leading innovation and\neconomic growth~\\cite{10.1109/SPW.2015.27}. Data origins are various including wearable and IoT devices.\nWhile data grows exponentially, gathering and storing them imposes high costs and liabilities.\n\nCentralized organizations, amass large quantities of personal and sensitive information on which individuals have little or no control ~\\cite{10.1109/SPW.2015.27}. Furthermore, there is a growing public concern about user privacy.\n\nHowever, data can be private and protected by acts, such as GDPR, making data processing impossible.\n\nBlockchain’s distributed nature eliminates the need for a trusted central authority and enables the connection between trustless entities.\nThe immutability and auditability of blockchain blocks and transactions, and cryptographical guarantees provided, can enforce liability, transparency and accountability without compromising privacy and security.\nIn addition, blockchain can significantly reduce data transaction costs between entities and increase transaction efficiency.\nLike all technology, blockchain has limitations. It is argued that blockchain is not suited for high performance transactions or as a database replacement. Due to the decentralized nature of blockchain and its necessity for a consensus mechanism the transaction rate remains quite low compared to financial services~\\cite{Sompolinsky2015,Zohar:2015:BUH:2817191.2701411}.\nBlockchain is not made for big data. The amount of data that blockchain can store and process is very limited so off-chain data frameworks are needed.\n", "meta": {"hexsha": "580a8f6b68777e4a7b0f404e5e9faffd7e79f9d3", "size": 15404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/_deprecated.tex", "max_stars_repo_name": "cnasikas/thesis", "max_stars_repo_head_hexsha": "e5bfd9d293fb7b8024863e389c9a2bc1f5d53509", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-06-21T17:44:21.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-21T17:44:21.000Z", "max_issues_repo_path": "chapters/_deprecated.tex", "max_issues_repo_name": "cnasikas/thesis", "max_issues_repo_head_hexsha": "e5bfd9d293fb7b8024863e389c9a2bc1f5d53509", "max_issues_repo_licenses": ["MIT"], "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/_deprecated.tex", "max_forks_repo_name": "cnasikas/thesis", "max_forks_repo_head_hexsha": "e5bfd9d293fb7b8024863e389c9a2bc1f5d53509", "max_forks_repo_licenses": ["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.9861751152, "max_line_length": 885, "alphanum_fraction": 0.7235133731, "num_tokens": 4471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425245706047, "lm_q2_score": 0.8539127473751341, "lm_q1q2_score": 0.7852944747590893}}
{"text": "\\section{Asymptotic Hypothesis tests}\n\nTwo hypotheses ($\\Theta_0$ disjoint set from $\\Theta_1$):\n$\\begin{cases}\n\t\tH_0: \\theta \\epsilon \\Theta_0\\\\\n\t\tH_1: \\theta \\epsilon \\Theta_1\\\\\n\\end{cases}$. Goal is to reject $H_0$ using a test statistic.\\\\\n\nA test $\\psi$ has \\textbf{level $\\alpha$} if $\\alpha_{\\psi}(\\theta) \\leq \\alpha, \\forall \\theta \\in \\Theta_0.$ and \\textbf{asymptotic level $\\alpha$} if $\\lim _{n \\to \\infty } P_\\theta ( \\psi = 1) \\leq \\alpha$.\\\\\n\n\\textbf{A hypothesis-test} has the form \n\n\\begin{align*}\n\\psi = \\textbf{1} \\lbrace  T_n \\geq c \\rbrace\n\\end{align*}\nfor some test statistic $T_n$ and threshold $c \\in \\mathbb{R}$. Threshold $c$ is usually $q_{\\alpha/2}$\\\\\n\\textbf{Rejection region:}\n\\begin{align*}\nR_{\\psi} = \\lbrace T_n > c \\rbrace\n\\end{align*}\n\\textbf{Symmetric about zero and acceptance Region interval:}\n\\begin{align*}\n\\psi = \\mathbf{1}\\{  |T_n| - c > 0 \\} .\n\\end{align*}\n\n\\textbf{Power of the test}:\\\\\n\\begin{align*}\n\\pi_\\psi = \\inf_{\\theta \\in \\Theta_1}(1 - \\beta_\\psi(\\theta))\n\\end{align*}\nWhere $\\beta_\\psi$ is the probability of making a Type2 Error and $inf$ is the maximum.\\\\\n\\textbf{Two-sided test}:\n\\begin{align*}\nH_1&: \\theta \\neq \\Theta_0\\\\\n\\mathbf{1}&(|T_ n| > q_{\\alpha /2})\n\\end{align*}\n\\textbf{One-sided tests}:\n\\begin{align*}\nH_1&: \\theta > \\Theta_0\\\\\n\\mathbf{1}&(T_ n < -q_{\\alpha})\nH_1&: \\theta < \\Theta_0\\\\\n\\mathbf{1}&(T_ n > q_{\\alpha})\n\\end{align*}\n\\textbf{Type1 Error:}\\\\\nTest rejects null hypothesis $\\psi = 1$ but it is actually true $H_0 = TRUE$ also known as the level of a test.\\\\\n\\textbf{Type2 Error:}\\\\\nTest does not reject null hypothesis $\\psi = 0$ but alternative hypothesis is true $H_1 = TRUE$\\\\\n\\textbf{Example:} Let $X_1, \\ldots , X_ n \\stackrel{i.i.d.}{\\sim } \\text {Ber}(p^*)$. Question: is $p^* = 1/2$.\\\\\n$H_0: p^* = 1/2; H_1:p^* \\neq 1/2$\\\\\nIf asymptotic level $\\alpha$ then we need to standardize the estimated parameter $\\hat{p} = \\overline{X}_ n$ first.\\\\\n\\begin{align*}\nT_n &= \\sqrt{n}\\frac{\\left| \\overline{X}_ n - 0.5\\right|}{\\sqrt{0.5(1 - 0.5)}}\\\\\n\\displaystyle \\psi _{n} &= \\displaystyle \\mathbf{1}\\left(T_n>q_{\\alpha /2} \\right)\n\\end{align*}\nwhere $q_{\\alpha /2}$ denotes the $q_{\\alpha /2}$ quantile of a standard Gaussian, and $\\alpha$ is determined by the required level of $\\psi$. Note the absolute value in $T_n$ for this two sided test.\\\\\n\\textbf{Pivot:}\\\\\nLet $T_n$ be a function of the random samples $X_1,\\dots ,X_ n,\\theta$. Let $g(T_ n)$ be a random variable whose distribution is the same for all $\\theta$ . Then, $g$ is called a pivotal quantity or a pivot.\\\\\n\\textbf{Example:} let $X$ be a random variable with mean $\\mu$ and variance $\\sigma^2$ . Let $X_1,\\dots ,X_ n$ be iid samples of $X$. Then,\n\\[\\displaystyle  g_ n \\triangleq \\frac{\\overline{X_ n} - \\mu }{\\sigma }\\]\nis a pivot with $\\theta = \\left[\\mu ~ ~  \\sigma ^2\\right]^ T$ being the parameter vector (not the same set of paramaters that we use to define a statistical model).\n\\subsection{P-Value}\nThe (asymptotic) p-value of a test $\\psi_{\\alpha}$ is the smallest (asymptotic) level $\\alpha$ at which $\\psi_{\\alpha}$ rejects $H_0$. It is random since it depends on the sample. It can also interpreted as the probability that the test-statistic $T_n$ is realized given the null hypothesis.\\\\\n\nIf $pvalue \\leq \\alpha$ , $H_0$ is rejected by $\\psi_{\\alpha}$ at the (asymptotic) level $\\alpha$\\\\\n\nThe smaller the p-value, the more confidently one can reject $H_0$.\\\\\n\\textbf{Left-tailed p-values:}\n\\begin{align*}\npvalue&=\\mathbb{P}(X\\leq x|H_0)\\\\\n&=\\mathbf{P}( Z < T_{n,\\theta _0}(\\overline{X}_ n)))\\\\\n&=\\Phi (T_{n,\\theta _0}(\\overline{X}_ n))\\\\\n&Z\\sim \\mathcal{N}(0,1)\t\n\\end{align*}\n\\textbf{Right-tailed p-values:}\n\\begin{align*}\n\tpvalue&=\\mathbb{P}(X\\geq x|H_0)\n\\end{align*}\n\\textbf{Two-sided p-values:}\nIf asymptotic, create normalized $T_n$ using parameters from $H_0$. Then use $T_n$ to get to probabilities.\n\\begin{align*}\n&pvalue=2 min\\{\\mathbb{P}(X\\leq x|H_0),\\mathbb{P}(X\\geq x|H_0)\\}\\\\\n&\\mathbb{P}(\\lvert Z\\rvert > \\lvert T_{n,\\theta _0}(\\overline{X}_ n)\\rvert = 2(1-\\Phi(T_n))\\\\\n&Z \\sim N(0,1)\n\\end{align*}\n\\subsection{Comparisons of two proportions}\n\nLet $X_1,\\dots ,X_ n \\stackrel{iid}{\\sim} Bern(p_x)$ and  $Y_1,\\dots ,Y_ n \\stackrel{iid}{\\sim} Bern(p_y)$ and be $X$ independent of $Y$. $\\hat{p}_x= 1/n \\sum_{i=1}^{n} X_i$ and $\\hat{p}_x= 1/n \\sum_{i=1}^{n} Y_i$\\\\\n\n$H_0: p_x = p_y; H_1: p_x \\neq p_y$\n\nTo get the asymptotic Variance use multivariate Delta-method. Consider $\\hat{p}_x - \\hat{p}_y = g(\\hat{p}_x,\\hat{p}_y); g(x,y)= x -y$, then\n\n$\\sqrt(n) (g(\\hat{p}_x,\\hat{p}_y) - g(p_x-p_y)) \\xrightarrow[n \\rightarrow \\infty]{(d)} N(0,\\nabla g(p_x-p_y)^T \\Sigma \\nabla g(p_x-p_y))$\\\\ \n\n$\\Rightarrow N(0,p_x(1-px) + p_y(1-py))$\n\n\\section{Non-asymptotic Hypothesis tests}\n\n\\subsection{Chi squared}\nThe $\\chi _ d^2$ distribution with $d$ degrees of freedom is given by the distribution of $Z_1^2 + Z_2^2 + \\cdots + Z_ d^2,$ where $Z_1, \\ldots , Z_ d \\stackrel{iid}{\\sim } \\mathcal{N}(0,1)$\n\nIf $V \\sim \\chi^2_k:$\\\\\n\n$\\mathbb{E}= \\mathbb{E}[Z_1^2] + \\mathbb{E}[Z_2^2] + \\ldots + \\mathbb{E}[Z_d^2] = d$\\\\ \n\n$Var(V) = Var(Z_1^2) + Var(Z_2^2) + \\ldots + Var(Z_d^2) = 2d$\n\n\\textbf{Cochranes Theorem:}\\\\\nIf $X_1, ..., X_n \\stackrel{iid}{\\sim} N(\\mu,\\sigma^2)$, then sample mean $\\bar{X}_n$ and the sample variance $S_n$ are independent. The sum of squares of $n$ variables follows a chi squared distribution with (n-1) degrees of freedom:\n\\begin{align*}\n\\frac{n S_ n}{\\sigma ^2} \\sim \\chi _{n -1}^2\n\\end{align*}\nIf formula for unbiased sample variance is used:\\\\\n\\begin{align*}\n\\frac{(n-1) S_ n}{\\sigma ^2} \\sim \\chi _{n -1}^2\n\\end{align*}\n\\subsection{Student's T Test}\nNon-asymptotic hypothesis test for small samples (works on large samples too), data must be gaussian.\\\\\n\n\\textbf{Student's T distribution} with $d$ degrees of freedom:\n$t_d := \\frac{Z}{\\sqrt{V/n}}$ where $Z \\sim \\mathcal{N}(0,1)$ and $V \\sim \\chi^2_k$ are independent.\\\\\n\n\\textbf{Student's T test (one sample + two-sided):}\\\\\n\nLet $X_1, ..., X_n \\stackrel{iid}{\\sim} N(\\mu,\\sigma^2)$ and suppose we want to test $H_0: \\mu = \\mu_0 = 0$ vs. $H_1: \\mu \\neq 0$.\\\\\n\nTest statistic follows Student's T distribution:\n\n\\begin{align*}\nT_n &= \\frac{Z}{\\tilde{S}} \\\\\n&= \\frac{\\bar{X}-\\mu}{\\frac{\\hat{\\sigma}}{\\sqrt{n}}}\\\\\n&=\\frac{\\displaystyle \\sqrt{n}\\frac{\\bar{X}_n - \\mu_0}{\\sigma}}{\\displaystyle \\sqrt{\\frac{\\tilde{S}_n}{\\sigma^2}}}\\\\\n&\\sim \\frac{N(0,1)}{\\sqrt{\\frac{\\chi^2_{n-1}}{n-1}}}\\\\\n&\\sim t_{n-1}\n\\end{align*}\n\nWorks bc. under $H_0$ the numerator $N(0,1)$ and the denominator $\\frac{\\tilde{S}_n}{\\sigma^2} \\sim \\frac1{n-1}\\chi^2_{n-1}$ are independent by Cochran's Theorem.\\\\\n\nStudent's T test at level $\\alpha$:\n\\begin{align*}\n\\psi_\\alpha = \\textbf{1}\\{|T_n| > q_{\\alpha/2}(t_{n-1})\\}\n\\end{align*}\n\n\\textbf{Student's T test (one sample, one-sided):}\n\\begin{align*}\n\\psi_\\alpha = \\textbf{1}\\{T_n > q_\\alpha(t_{n-1})\\}\n\\end{align*}\n\n\\textbf{Student's T test (two samples, two-sided):}\n\nLet $X_1, ..., X_n \\stackrel{iid}{\\sim} N(\\mu_X,\\sigma^2_X)$ and $Y_1, ..., Y_n \\stackrel{iid}{\\sim} N(\\mu_Y,\\sigma^2_Y)$, suppose we want to test $H_0: \\mu_X = \\mu_Y$ vs $H_1: \\mu_X \\neq \\mu_Y$.\n\n\\begin{align*}\nT_{n, m} = \\frac{\\bar{X}_n - \\bar{Y}_m}{\\displaystyle \\sqrt{\\frac{\\hat{\\sigma^2}_X}n + \\frac{\\hat{\\sigma^2}_Y}m}}\n\\end{align*}\n\n\n\\textbf{Welch-Satterthwaite formula:}\\\\\n\nWhen samples are different sizes we need to finde the Student's T distribution of: $T_{n, m} \\sim t_N$\\\\\n\nCalculate the degrees of freedom for $t_N$ with:\n\\begin{align*}\nN = \\frac{\\displaystyle \\left(\\frac{\\hat{\\sigma^2}_X}n + \\frac{\\hat{\\sigma^2}_Y}m\\right)^2}{\\displaystyle \\frac{\\hat{\\sigma^2}^2_X}{n^2(n-1)} + \\frac{\\hat{\\sigma^2}^2_Y}{m^2(m-1)}} \\geq \\min(n, m)\n\\end{align*}\n\n$N$ should be rounded down.\n\n\\subsection{Walds Test}\n\nSquared distance of $\\widehat{\\theta}_ n^{MLE}$ to true $\\theta_0$ using the fisher information $I(\\widehat{\\theta}_ n^{MLE})$ as metric.\n\nLet $\\, X_1, \\ldots , X_ n \\stackrel{iid}{\\sim } \\mathbf{P}_{\\theta ^*}$ for some true parameter $\\theta ^* \\in \\mathbb {R}^ d$ and the  maximum likelihood estimator $\\widehat{\\theta }_ n^{MLE}$ for $\\theta ^*$.\\\\\n\nTest $H_0: \\displaystyle  \\theta ^* = \\mathbf{0}$ vs $H_1: \\displaystyle  \\theta ^* \\neq \\mathbf{0}$\\\\\n\nUnder $H_0$, the asymptotic normality of the MLE $\\widehat{\\theta }_ n^{MLE}\\,$ implies that:\\\\\n\n$\\left\\lVert \\sqrt{n}\\, \\mathcal{I}(\\mathbf{0})^{1/2}(\\widehat{\\theta }_ n^{MLE}- \\mathbf{0}) \\right\\rVert ^2 \\xrightarrow [n\\to \\infty ]{(d)} \\chi ^2_ d\\,$\\\\\n\n\\textbf{Test statistic:}\n\\begin{align*}\nT_n = &\nn(\\widehat{\\theta}_ n^{MLE} - \\theta_0)^\\top I(\\widehat{\\theta}_ n^{MLE}) (\\widehat{\\theta}_ n^{MLE} - \\theta_0)\\\\\n&\\xrightarrow [n\\to \\infty ]{(d)} \\chi ^2_ d\n\\end{align*}\n\n\\textbf{Wald test} of level $\\alpha$:\n\\begin{align*}\n\\psi_\\alpha = \\mathbf{1}\\{T_n > q_\\alpha(\\chi^2_d)\\}\n\\end{align*}\n\n%\\textbf{Wald test with one dimensional model}\n%\\begin{align*}\n%W&=\\frac{(\\widehat{\\theta}_ n^{MLE} - \\theta_0)^2}{Var(\\widehat{\\theta})}\\\\\n%&=nI(\\widehat{\\theta) (\\widehat{\\theta }^{\\text {MLE}} -\\theta _0)^2\n%\\end{align*}\n\n\\subsection{Likelihood Ratio Test}\nParameter space $\\Theta \\subseteq \\mathbb{R}^d$ and $H_0$ is that parameters $\\theta_{r+1}$ through $\\theta_d$ have values $\\theta_c^{r+1}$ through $\\theta^c_d$ leaving the other $r$ unspecified. That is:\\\\\n$H_0: (\\theta_{r+1}, ..., \\theta_d)^T = \\theta_{r+1...d} = \\theta_0$\\\\\n\n\\textbf{Construct two estimators:}\n\\begin{align*}\n\\widehat{\\theta}_n^{MLE} = argmax_{\\theta \\in \\Theta}(\\ell_n(\\theta))\\\\\n\\widehat{\\theta}_n^c = argmax_{\\theta \\in \\Theta_0}(\\ell_n(\\theta))\n\\end{align*}\n\n\\textbf{Test statistic:}\n\\begin{align*}\nT_n = 2 ( \\ell(X_1,..X_n|\\widehat{\\theta}_n^{MLE}) - \\ell(X_1,..X_n|\\widehat{\\theta}_n^c)))\n\\end{align*}\n\\textbf{Wilk's Theorem:} under $H_0$, if the MLE conditions are satisfied: \n\\begin{align*}\nT_n& \\xrightarrow[n \\rightarrow \\infty]{(d)} \\chi_{d-r}^2\\\\\n\\end{align*}\n\\textbf{Likelihood ratio test} at level $\\alpha$:\n\\begin{align*}\n\\psi_\\alpha = \\textbf{1}\\{T_n > q_\\alpha(\\chi^2_{d-r})\\}\n\\end{align*}\n\\subsection{Implicit Testing}\nTodo\n\\subsection{Goodness of Fit Discrete Distributions}\n\nLet $X_1,...,X_n$ be iid samples from a categorical distribution. Test $H_0: p = p^0$ against $H_1: p \\neq p^0$. Example: against the uniform distribution $p^0 = (1/K, \\ldots, 1/K)^\\top$.\\\\\n\n\\textbf{Test statistic} under $H_0$:\n\\begin{align*}\nT_n = n\\sum_{k=1}^K\\frac{(\\hat{p}_k - p^0_k)^2}{p^0_k} \\xrightarrow[n \\rightarrow \\infty]{(d)} \\chi^2_{K-1}\n\\end{align*}\n\\textbf{Test at level alpha:}\n\\begin{align*}\n\\psi_\\alpha = \\mathbb{1}\\{T_n > q_\\alpha(\\chi^2_{K-1})\\}\n\\end{align*}\n\\subsection{Kolmogorov-Smirnov test}\n\\subsection{Kolmogorov-Lilliefors test}\n\\subsection{QQ plots}\n\\textbf{Heavier tails}: below > above the diagonal.\\\\\n\\textbf{Lighter tails}: above > below the diagonal.\\\\\n\\textbf{Right-skewed}: above > below > above the diagonal.\\\\\n\\textbf{Left-skewed}: below > above > below the diagonal.\\\\\n", "meta": {"hexsha": "3e00b32458a1a69b1e6f12f4f93fb33ce469de4d", "size": 10867, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Hypothesis_tests.tex", "max_stars_repo_name": "r2cp/MITx_capstone_1", "max_stars_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "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/Hypothesis_tests.tex", "max_issues_repo_name": "r2cp/MITx_capstone_1", "max_issues_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_issues_repo_licenses": ["MIT"], "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/Hypothesis_tests.tex", "max_forks_repo_name": "r2cp/MITx_capstone_1", "max_forks_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "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": 45.0912863071, "max_line_length": 293, "alphanum_fraction": 0.6550105825, "num_tokens": 4235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747658, "lm_q2_score": 0.8705972801594707, "lm_q1q2_score": 0.7852096970868522}}
{"text": "\\chapter{Sparse Kernel Machines}\n\\label{chap:Sparse Kernel Machines}\n\\section{Introduction}\nOne of significant limitations of kernel methods is that the kernel function $\\mathcal{k}(\\vec{x}_n,\\vec{x}_m)$ must be evaluated for all possible pairs $\\vec{x}_n$ and $\\vec{x}_m$ of training points,computationally infeasible.Kernel-based algorithms that have \\textbf{sparse} solutions predict for new inputs depend only on the kernel function evaluated at a subset of the training data points,such as \\textbf{suport vector machine}(SVM).\n\\section{Maximum Margin Classifiers}\nTwo-class classification problem using linear models\n\\begin{align}\\label{eqn:maximum margin classifier regpresentation}\ny(x) = \\vec{w}^T\\phi(x)+b\n\\end{align}\nwhere $\\phi(x)$ denotes a fixed feature-space transformation,and $b$ is bias parameter.\n\nFor linear separable feature space,the parameters satisfies $y(\\vec{x}_n)>0$ for points having $t_n=+1$ and $y(\\vec{x}_n)<0$ for $t_n=-1$,so that $t_ny(\\vec{x}_n)>0$ for all points.\n\n\\textbf{Margin} is the smallest distance between the decision boundary and any of the samples.The maximum margin solution can be motivated using \\textbf{computational learning theory},also known as \\textbf{statistical learning theory}.\n\\begin{figure*}\n\n\t\\includegraphics{prml/Figure7.1a.jpg}\n\t\\includegraphics{prml/Figure7.1b.jpg}\n\t\\caption{margin}\n\\end{figure*}\n\nThe \\textbf{funtional margin} $t_ny(\\vec{x}) > 0$ for data points correctly classified.The maximize it\n\\begin{align}\n\\vec{w},b = \\arg\\max\\limits_{\\vec{w},b}\\{\\dfrac{1}{\\parallel\\vec{w}\\parallel}\\min_n\n[t_n(\\vec{w}^T\\phi(\\vec{x}_n)+b)] \\}\n\\end{align}\nWe can rescale parameters to set\n\\begin{align}\nt_n(\\vec{w}^T\\phi(\\vec{x}_n)+b) &= 1\n\\end{align}\nfor point closet to the surface.Then all data points satisfies the constraint\n\\begin{align}\\label{ineqn:margin constraint}\nt_n(\\vec{w}^T\\phi(\\vec{x}_n)+b) \\geq 1,n=1,...,N.\n\\end{align}\nThis is the \\textbf{canonical representation of the decision hyperplane}.The optimization problem is equivalent to\n\\begin{align}\n\\arg\\min\\limits_{\\vec{w},b}\\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2\n\\end{align}\nsubject to constraints \\ref{ineqn:margin constraint},which is a \\textbf{quadratic programming} problem.\n\nIntroducing Lagrange multipliers $a_n\\geq 0$\n\\begin{align}\nL(\\vec{w},b,\\vec{a}) = \\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2-\n\\sum_{n=1}^{N}a_n\\{ t_n(\\vec{w}^T\\phi(\\vec{x}_n)+b)-1 \\}\n\\end{align}\nwhere $\\vec{a} = (a_1,...,a_N)^T$.Setting the derivatives of $L$ with respect to $\\vec{w}$ and $b$ equal to zero,we obtain conditions\n\\begin{align}\n\\vec{w}&=\\sum_{n=1}^{N}a_n t_n\\phi(\\vec{x}_n) \\\\\n0 &=\\sum_{n=1}^{N}a_n t_n\n\\end{align}\nEliminating $\\vec{w}$ and $b$ gives the \\textbf{dual representation} of the maximum margin problem\n\\begin{align}\n\\hat{L}(\\vec{a})=\\sum_{n=1}^{N}a_n -\\dfrac{1}{2}\\sum_{n=1}^{N}\\sum_{m=1}^{N}a_n a_m t_n t_m k(\\vec{x}_n,\\vec{x}_m)\n\\end{align}\nwith respect to $\\vec{a}$ subject to the constraints\n\\begin{align}\na_n &\\geq 0,n =1,...,N \\\\\n\\sum_{n=1}^{N}a_n t_n &= 0.\n\\end{align}\nThe kernel function is defined by $k(\\vec{x},\\vec{x}') = \\phi(\\vec{x})^T\\phi(\\vec{x}')$.\n\nThe solution to a quadratic programming problem in $M$ variables has computational complexity of $O(M^3)$.\n\n$y(\\vec{x})$ can be expressed by\n\\begin{align}\ny(\\vec{x}) = \\sum_{n=1}^{N}a_n t_n k(\\vec{x},\\vec{x}_n) + b.\n\\end{align}\nThe $Karush-Kuhn-Tucker(KKT)$ conditions require following the properties hold\n\\begin{align}\na_n \\geq 0 \\\\\nt_n y(\\vec{x}_n) -1 &\\geq 0 \\\\\na_n\\{t_n y(\\vec{x}_n) -1 &= 0\\}\n\\end{align}\nData points for which $a_n=0$ will disappear and remaining ones are called \\textbf{suport vectors}.They lie on the maximum margin hyperplanes in feature space.\n\nHaving solved the quadratic programming problem,the threshold parameter $b$\n\\begin{align}\nt_n(\\sum_{m\\in \\mathcal{S}}{a_m t_m k(\\vec{\\vec{x}_n,\\vec{x}_m})+b}) =1\n\\end{align}\nwhere $\\mathcal{S}$ denotes the set of indices of the support vectors.Multiply through by $t_n$,making use of $t_n2=1$,and then average these equations over all support vectors\n\\begin{align}\nb=\\dfrac{1}{N_{\\mathcal{S}}}\\sum_{n\\in\\mathcal{S}}(t_n-\\sum_{m\\in\\mathcal{S}}a_m t_m \\mathcal{k}(\\vec{x}_n,\\vec{x}_m))\n\\end{align}\nwhere $N_{\\mathcal{S}}$ is the total number of support vectors.\nExpress the maximum-margin classifier in terms of the minimization of an error function with a quadratic regularizer\n\\begin{align}\n\\sum_{n=1}^{N}E_{\\infty}(y(\\vec{x}_n)t_n-1) + \\lambda\\parallel\\vec{w}\\parallel^2\n\\end{align}\nwhere $E_{\\infty}(z)$ is zero if $z\\geq 0$ and $\\infty$ otherwise to ensure the margin constraint.\n\n\\subsection{Overlapping class distributions}\nIn practice,the class-conditional distributions may overlap,in which case exact separation of the training data can lead to poor generalization.Introduce \\textbf{slack variables}, $\\xi_n\\geq 0$ where $n=1,...N$,one for each training data points.We allow points on the 'wrong side' but with a penalty that increases of the distance from the boundary.\n\\begin{align}\n\\xi_n = \\mid t_n-y(\\vec{x}_n)\\mid\n\\end{align}\n\\begin{SCfigure*}\n\t\\caption{slack variables $\\epsilon_n\\geq 0$.Data points with circles around them are support vectors}\n\t\\includegraphics[]{prml/Figure7.3.jpg}\n\\end{SCfigure*}\n\nThen the classification constraint are replaced by\n\\begin{align}\nt_n y(\\vec{x}_n) \\geq 1-\\xi_n,n=1,...,N\n\\end{align}\nThis is described as relaxing the hard margin constraint to give a \\textbf{soft margin} and allows misclassification of training set data points.\n\nMaximize the margin with softly penalized points on the wrong side of the margin boundary.\n\\begin{align}\nC\\sum_{n=1}^{N}\\xi_n +\\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2\n\\end{align}\nwhere the parameter $C$ controls the trade-off between the slack variable penalty and the margin,minimizing errors and controlling model complexity.In the limit $C\\longrightarrow \\infty$,the model gets more complex,less data points are misclassified.\n\nMinimization with constraint\n\\begin{align}\nL(\\vec{w},b\\vec{a}) =\\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2+C\\sum_{n=1}^{N}\\xi_n-\\sum_{n=1}^{N}a_n\\{t_n y(\\vec{x}_n)-1+\\xi_n \\} -\\sum_{n=1}^{N}\\mu_n\\xi_n\n\\end{align}\nwhere $\\{a_n\\geq 0\\}$ and $\\{\\mu_n \\geq 0 \\}$ are Lagrange multipliers.The KKT set of conditions are given by\n\\begin{align}\na_n &\\geq 0 \\\\\nt_n y(\\vec{x}_n)-1+\\xi_n &\\geq 0 \\\\\na_n(t_n y(\\vec{x}_n)-1+\\xi_n) &= 0 \\\\\n\\mu_n &\\geq 0 \\\\\n\\xi_n &\\geq 0 \\\\\n\\mu_n\\xi_n &=0\n\\end{align}\nwhere $n=1,...,N$.\n\nOptimize out $\\vec{w},b$ and $\\{\\xi_n\\}$\n\\begin{align}\n\\dfrac{\\partial L}{\\partial\\vec{w}} =0 &\\Rightarrow \\vec{w}=\\sum_{n=1}^{N}a_n t_n \\\\ \n\\dfrac{\\partial L}{\\partial b}=0 &\\Rightarrow \\sum_{n=1}^{N}a_n t_n =0 \\\\\n\\dfrac{\\partial L}{\\partial \\xi_n} =0 &\\Rightarrow a_n = C-\\mu_n\n\\end{align}\nEliminated,the dual Lagrangian is in the form\n\\begin{align}\\label{eqn:SVM Lagrangian}\n\\hat{L}(\\vec{a}) = \\sum_{n=1}^{N}a_n -\\dfrac{1}{2}\\sum_{n=1}^{N}\\sum_{m=1}^{N}a_n a_m t_n t_m \\mathcal{k}(\\vec{x}_n,\\vec{x}_m)\n\\end{align}\nwhich is identical to the separable case,with different constraints:\n\\begin{align}\n0\\leq a_n \\leq C\\\\\n\\sum_{n=1}^{N}a_n t_n = 0\n\\end{align}\nfor $n=1,...,N$,where the former are known as \\textbf{box constraints}.\n\nA subset of data points having $a_n =0$ do not contribute to the predictive model.Support vectors have $a_n > 0$ and satisfy\n\\begin{align}\nt_n y(\\vec{x}_n) &= 1-\\xi_n\n\\end{align}\nif $a_n <C$,then implies that $\\mu_n > 0$,which requires $\\xi_n =0$ and hence such points lie on the margin.Points with $a_n=C$ can lie inside the margin and can either be correctly classified if $\\xi_n \\leq 1$ or misclassified if $\\xi_n >1$.\n\nTo determine $b$,we note that support vectors for which $0\\leq a_n \\leq C$ have $\\xi_n =0$ so that $t_n y(\\vec{x}_n)=1$ and hence satisfy\n\\begin{align}\nt_n(\\sum_{m\\in\\mathcal{S}}a_m t_m \\mathcal{k}(\\vec{x}_n,\\vec{x}_m)+b) =1\n\\end{align}\nA numerically stable solution is obtained by averaging:\n\\begin{align}\n\tb=\\dfrac{1}{N_{\\mathcal{M}}}\\sum_{n\\in\\mathcal{M}} (t_n - \\sum_{m\\in\\mathcal{S}}a_m t_m \\mathcal{k}(\\vec{x}_n,\\vec{x}_m))\n\\end{align}\nwhere $\\mathcal{M}$ denotes the set of indices of data points having $0\\leq a_n \\leq C$.\n\n\\subsection{Multiclass Support Vector Machine loss}\nthe score for the $j$-th class is the $j$-th element: $\\vec{s}_j=f(\\vec{x}_i,\\vec{W})_j$. The Multiclass SVM loss for the $i$-th example is then formalized as follows:\n\\begin{align}\n    L_i = \\sum_{j\\neq y_i} \\max(0, \\vec{s}_j - \\vec{s}_{y_i} + \\Delta)\n\\end{align}\nWith linear score function $f(\\vec{x}_i; \\vec{W}) =  \\vec{W} \\vec{x}_i$, rewrite the loss function in this equivalent form:\n\\begin{align}\n    L_i = \\sum_{j\\neq y_i} \\max(0, \\vec{w}_j^T x_i - \\vec{w}_{y_i}^T x_i + \\Delta)\n\\end{align}\nThe threshold at zero $max(0,-)$ is called \\textbf{hinge loss}.And there is a squared hinge loss (L2-SVM).\nThe gradient of loss function for a single point $i$:\n\\begin{align}\n    \\nabla_{w_{y_i}} L_i = - \\left( \\sum_{j\\neq y_i} \\mathbb{1}(w_j^Tx_i - w_{y_i}^Tx_i + \\Delta > 0) \\right) x_i\n\\end{align}\nwhere $\\mathbb{1}$ is the indicator function that is one if the condition inside is true or zero otherwise.\nFor the rows where $j \\neq y_i$ the gradient is:\n\\begin{align}\n    \\nabla_{w_j} L_i = \\mathbb{1}(w_j^Tx_i - w_{y_i}^Tx_i + \\Delta > 0) x_i\n\\end{align}\n\n\\subsubsection{$\\nu$-SVM}\nMaximize\n\\begin{align}\n\\hat{L}(\\vec{a})=-\\dfrac{1}{2}\\sum_{n=1}^{N}\\sum_{m=1}^{N}a_n a_m t_n t_m\\mathcal{k}(\\vec{x}_n,\\vec{x}_m)\n\\end{align}\nsubject to the constraints\n\\begin{align}\n0\\leq a_n \\leq 1/N\\\\\n\\sum_{n=1}^{N}a_n t_n = 0 \\\\\n\\sum_{n=1}^{N}a_n \\geq \\nu\n\\end{align}\nThe parameter $\\nu$,which replaces $C$,can be interpreted as both an upper bound on the fraction of \\textbf{margin errors} and a lower bound on the fraction of support vectors.\n\n\\subsubsection{Optimization}\n\\begin{description}\n\t\\item[\\textbf{chunking}]Lagrangian is unchanged if we remove the rows and columns of the kernel matrix corresponding to Lagrange multipliers.Implemented using \\textbf{protected conjugate gradients}.\n\t\\item[\\textbf{Decomposition methods}] solves a series of smaller quadratic programming problems but are designed so that each of these is of a fixed size.\n\t\\item[\\textbf{sequantial minimal optimization} or SMO] Takes the concept of chunking to the extreme limit and considers just two Lagrange multipliers at a time.Heuristics are given for choosing the pair of Lagrange multipliers to be considered at each step.\n\\end{description}\n\nSupport vector machines don't manage to avoid the curse of dimensionality because there are constraints amongst the feature values that restrict the effective dimensionality of feature space.\n\n\\subsubsection{Relation to Logistic Regression}\nThe objective function can be written \n\\begin{align}\n\\sum_{n=1}^{N}E_{SV}(y_n t_n) +\\lambda\\parallel\\vec{w}\\parallel^2\n\\end{align}\nwhere $\\lambda=(2C)^{-1}$,and $E_{SV}(\\cdot)$ is the \\textbf{hinge} error function defined by\n\\begin{align}\nE_{SV}(y_n t_n)= [1-y_n t_n]_{+}\n\\end{align}\nwhere $[\\cdot]_+$ denotes the positive part.\n\nFor logistic regression,target variable $t\\in \\{-1,1\\}$,so\n\\begin{align}\np(t|y)=\\sigma(yt)\n\\end{align}\nConstruct an error function by taking the negative logarithm of likelihood function with a quadratic regularizer\n\\begin{align}\n\\sum_{n=1}^{N}E_{LR}(y_n t_n)+\\lambda\\parallel\\vec{w}\\parallel^2\n\\end{align}\nwhere\n\\begin{align}\nE_{LR}(yt)=\\ln(1+\\exp(-yt))\n\\end{align}\n\\begin{SCfigure*}\n\t\\caption{Plot of the ‘hinge’ error function used in support vector machines, shown in blue, along with the error function for logistic regression, rescaled by a factor of 1/ ln(2) so that it passes through the point (0, 1), shown in red. Also shown are the misclassification error in black and the squared error in green.}\n\t\\includegraphics{prml/Figure7.5.jpg}\n\\end{SCfigure*}\n\n\\subsubsection{Multiclass SVMs}\n\\begin{description}\n\t\\item[\\textbf{one-versus-the-rest}] approach:$K$ separate SVMs for each class.\n\t\\item[\\textbf{one-versus-one}].$K(K-1)/2$ different 2-class SVMs on possible pairs of classes,which can lead to ambiguities.\n\t\\item[\\textbf{single-class}] support vector machines,which solve an unsupervised learning problem related to probability density estimation.\n\\end{description}\n\n\\subsubsection{SVMs for regression}\nIn simple linear regression we minimize a regularized error function given by\n\\begin{align}\n\\dfrac{1}{2}\\sum\\limits_{n=1}^{N}\\{y_n-t_n\\}^2+\\dfrac{\\lambda}{2}\\parallel\\vec{w}\\parallel^2.\n\\end{align}\nTo obtain \\textbf{sparse solutions},the quadratic error function is replaced by an \\textbf{$\\epsilon$-insensitive error function}.For example\n\\begin{align}\nE_{\\epsilon}(y(\\vec{x})-t) = \\begin{cases}\n0,&\\text{if}\\mid y(\\vec{x})-t\\mid < \\epsilon;\\\\\ny(\\vec{x})-t\\mid - \\epsilon,&\\text{otherwise}\n\\end{cases}\n\\end{align}\nWe therefore minimize\n\\begin{align}\nC\\sum\\limits_{n=1}^{N}E_{\\epsilon}(y(\\vec{x}_n)-t_n)+\\dfrac{1}{2}\\mid\\vec{w}\\mid^2\n\\end{align}\nwhere $y(\\vec{x})$ is the prediction function.The (inverse) regularization parameter denoted $C$,appears in front of the error term.\n\nIntroducing two \\textbf{slack variables} for each data point $\\vec{x}_n$.The condition for target points to lie inside the $\\epsilon$-tube is that $y_n -\\epsilon \\leq t_n \\leq y_n+\\epsilon$,and for those outside:\n\\begin{align}\n&\\begin{cases}\n\\xi_n &\\geq 0\\\\\n\\hat{\\xi_n} &\\geq 0,n=1,...,N\\\\\n\\end{cases}\\\\\n& y(\\vec{x}_n)+\\epsilon < t_n \\leq y(\\vec{x}_n)+\\epsilon +\\xi_n \\\\\n& y(\\vec{x}_n)-\\epsilon > t_n \\geq y(\\vec{x}_n)-\\epsilon -\\hat{\\xi_n}\n\\end{align}\n\\begin{SCfigure*}\n\t\\caption{Illustration of SVM regression, showing the regression curve together with the $\\epsilon$-insensitive tube. }\n\t\\includegraphics[]{prml/Figure7.7.jpg}\n\\end{SCfigure*}\n\nThe error function for support vector regression can then be written as\n\\begin{align}\nC\\sum\\limits_{n=1}^{N}(\\xi_n+\\hat{\\xi_n})+\\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2\n\\end{align}\nwhich must be minimized subject to the constraints.Introducing Lagrange multipliers\n\\begin{align}\\label{eqn:svm regression Lagrangian}\nL =& C\\sum\\limits_{n=1}^{N}(\\xi_n+\\hat{\\xi_n})+\\dfrac{1}{2}\\parallel\\vec{w}\\parallel^2\n- \\sum\\limits_{n=1}^{N}(\\mu_n\\xi_n+\\hat{\\mu_n}\\hat{\\xi_n}) \\\\\n&-\\sum\\limits_{n=1}^{N}a_n(\\epsilon+\\xi_n+y_n-t_n) -\\sum\\limits_{n=1}^{N}\\hat{a_n}(\\epsilon+\\hat{\\xi_n}+y_n-t_n)\n\\end{align}\nSubstitute for $y(\\vec{x})$ using \\ref{eqn:maximum margin classifier regpresentation} and set the derivatives of the Lagrangian with respect to $\\vec{x},b,\\xi_n,\\hat{\\xi_n}$ to zero,giving\n\\begin{align}\n\\dfrac{\\partial L}{\\partial\\vec{w}} =0 &\\Rightarrow \\vec{w}=\\sum_{n=1}^{N}(a_n-\\hat{a_n})\\phi(\\vec{x}_n) \\\\\n\\dfrac{\\partial L}{\\partial b} =0 &\\Rightarrow \\sum_{n=1}^{N}(a_n-\\hat{a_n})=0 \\\\\n\\dfrac{\\partial L}{\\partial\\xi_n} =0 &\\Rightarrow a_n+\\mu_n=0 \\\\\n\\dfrac{\\partial L}{\\partial\\hat{\\xi_n}} =0 &\\Rightarrow \\hat{a_n}+\\hat{\\mu_n}=0 \\\\\n\\end{align}\nUsing these to eliminate the corresponding variables,we see the dual problem of maximizing \n\\begin{align}\n\\hat{L}(\\vec{a},\\hat{\\vec{a}}) =&-\\dfrac{1}{2}\\sum_{n=1}^{N}\\sum_{m=1}^{N}(a_n-\\hat{a_n})(a_m-\\hat{a_m})\\mathcal{k}(\\vec{x}_n,\\vec{x}_m) \\\\\n &-\\epsilon\\sum_{n=1}^{N}(a_n+\\hat{a_n})+\\sum_{n=1}^{N}(a_n-\\hat{a_n})t_n\n\\end{align}\nwith respect to $\\{a_n\\},\\{\\hat{a_n}\\}\t$.We have the \\textbf{box constraints}\n\\begin{align}\n0\\leq a_n \\leq C\\\\\n0\\leq \\hat{a_n}\\leq C\n\\end{align}\nAfter substitution,the predictions can be made using\n\\begin{align}\ny(\\vec{x})=\\sum_{n=1}^{N}(a_n-\\hat{a_n})\\mathcal{k}(\\vec{x},\\vec{x}_n)+b\n\\end{align}\n\nThe corresponding $karush-Kuhn-Tucker$(KKT) conditons for \\ref{eqn:svm regression Lagrangian},which state that \\textbf{at the solution the product of the dual variables and the constraints must vanish} are given by\n\\begin{align}\na_n(\\epsilon+\\xi_n+y_n-t_n) &= 0\\\\\n\\hat{a_n}(\\epsilon+\\hat{\\xi_n}-y_n+t_n) &= 0\\\\\n(C-a_n)\\xi_n & = 0\\\\\n(C-\\hat{a_n})\\hat{\\xi_n} &=0\n\\end{align}\n\nThe support vectors are those data points that contribute to predictions,in other words those for which either $a_n \\neq 0$ or $\\hat{a_n} \\neq 0$.These are points lying on the boundary of the $\\epsilon$-tube or outside the tube.\n\nThe parameter $b$ satisfies \n\\begin{align}\n\\epsilon+y_n-t_n= 0\n\\end{align}\nfor points $0<a_n<C$.Solving for it\n\\begin{align}\nb &= t_n-\\epsilon-\\vec{w}^T\\phi(\\vec{x}_n) \\\\\n  &= t_n-\\epsilon-\\sum_{m=1}^{N}(a_m-\\hat{a_m})\\mathcal{k}(\\vec{x}_n,\\vec{x}_m)\n\\end{align}\n\nAn alternative formulation of SVM regression is $\\nu$ SVM.\n\\begin{align}\n\\hat{L}(\\vec{a},\\hat{\\vec{a}}) =&-\\dfrac{1}{2}\\sum_{n=1}^{N}\\sum_{m=1}^{N}(a_n-\\hat{a_n})(a_m-\\hat{a_m})\\mathcal{k}(\\vec{x}_n,\\vec{x}_m) \\\\\n&-0\\times\\epsilon\\sum_{n=1}^{N}(a_n+\\hat{a_n})+\\sum_{n=1}^{N}(a_n-\\hat{a_n})t_n\n\\end{align}\nsubject to constraints\n\\begin{align}\n0\\leq a_n &\\leq C/N\\\\\n0\\leq \\hat{a_n} &\\leq C/N \\\\\n\\sum_{n=1}^{N}(a_n-\\hat{a_n}) &=0 \\\\\n\\sum_{n=1}^{N}(a_n+\\hat{a_n}) &\\leq \\nu C \\\\\n\\end{align}\nThere are at most $\\nu N$ data points falling outside the insensitive tube,which at least $\\nu N$ data points are support vectors and so lie either on the tube or outside it.\n\n\\section{Relevance Vector Machines}\nTODO\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "6374c1136bd20217bfb1ac9dd13b4918491b9915", "size": 16910, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Sparse Kernel Machines.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/Sparse Kernel Machines.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/Sparse Kernel Machines.tex", "max_forks_repo_name": "Alexoner/Statistical-formula", "max_forks_repo_head_hexsha": "114a6c2424f206cb57715c7de29ae3d26abcb081", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-02-25T15:40:39.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-25T04:26:03.000Z", "avg_line_length": 48.591954023, "max_line_length": 439, "alphanum_fraction": 0.7108219988, "num_tokens": 5844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384593, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.7852096781367965}}
{"text": "\n\\subsection{Soft-margin SVC}\n\n\\subsubsection{Soft margin}\n\nSoft margin\n\nData may not be linearly separable, so we introduce a hinge loss function\n\n\\(Max(0, 1-y_i(wx-b))\\)\n\nWe then minimise\n\n\\(\\lambda ||w||^2+ [\\dfrac{1}{n}\\sum_{i=1}^n \\max (0, 1-y_i(wx_i-b)]\\)\n\nThis introduces \\(\\lambda\\) as a parameter.\n\n", "meta": {"hexsha": "f9efb35747c816a41f77415293689d614f5cb57d", "size": 308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/SVM/01-04-softMargin.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/SVM/01-04-softMargin.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/SVM/01-04-softMargin.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.1111111111, "max_line_length": 73, "alphanum_fraction": 0.6753246753, "num_tokens": 103, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9603611643025386, "lm_q2_score": 0.8175744673038222, "lm_q1q2_score": 0.7851667673239264}}
{"text": "\\chapter{CT Frequency Response}\n\nIn this lecture we are going to focus on the frequency response and highlight it's importance in linear systems theory.\n\n\\section{Determining the frequency response (FR) of a CT system}\n\nThe frequency response of a CT LTI system can be thought of as arising in several equivalent ways. What follows is a common, but not exhaustive, list of ways the frequency response can be derived from other representations.\n\n\\subsection*{Using the Eigenvalues / Transfer Function}\n\nRecall if we apply the Eigenfunction $e^{st}$ for the complex frequency $s \\in \\mathbb{C}$ as the input to a LTI system, the output is the Eigenfunction scaled by the Eigenvalue (transfer function) $H(s)$ for values of $s$ in the region of convergence, where\n\\[\nH(s) = \\int\\limits_{-\\infty}^{\\infty} h(t) e^{st}\\; dt \\; .\n\\]\nis the bilateral Laplace transform of the impulse response.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/18-ct-tf.pdf}\n\\end{center}\n\nIf a system is stable, then the region of convergence includes the imaginary axis $s = j\\omega$. In that case, evaluating the Eigenvalues on the imaginary axis $s = j\\omega$ gives the CT frequency response $H(j\\omega)$. This converts from a function of a complex variable, $s$, to one of a real variable $\\omega$.\n\n\\begin{example} Consider a system with Eigenvalues (transfer function)\n  \\[\n  H(s) = \\frac{2}{s+5}\\mbox{ for } \\Re{s} > -5\n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: We first need to check of the system is stable using the region-of-convergence. Since the real part of the region of convergence includes the imaginary axis ($\\Re s = 0$), the system is stable. To find the frequency response we substitute $s = j\\omega$ to give\n  \\[\n  H(j\\omega) = \\frac{2}{j\\omega+5}\n  \\]\n  \\\\$\\blacksquare$\n\\end{example}\n\n\\begin{example} Consider an apparently similar system with Eigenvalues\n  \\[\n  H(s) = \\frac{2}{s-5}\\mbox{ for } \\Re{s} > 5\n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: Again, we first need to check of the system is stable using the region-of-convergence. Since the real part of the region of convergence does not include the imaginary axis ($\\Re s = 0$), the system is unstable. Thus, the frequency response does not exist.\n  \\\\$\\blacksquare$\n\\end{example}\n\n\\subsection*{Using the CTFT}\n\nAnother way we can view the frequency response is as the CT Fourier Transform of the impulse response. If the system is stable, then the impulse response is absolutely integrable, and the Fourier transform exists giving $H(j\\omega) = \\mathcal{F}\\left\\{h(t)\\right\\}$. This is connected to the transfer function by noting the bilateral Laplace transform and the Fourier Transform are identical under the substitution $s = j\\omega$, which is allowed if the system is stable.\n\n\\begin{example} Suppose the impulse response of a CT LTI system is given by\n  \\[\n  h(t) = \\left(e^{-t}-e^{-6t}\\right)u(t) \n  \\]\n  Determine the frequency response of the system, if possible.\\\\\n\n  Solution: If the system is stable, the Fourier transform of the impulse response exists. Since\n  \\[\n  \\int\\limits_{0}^{\\infty} \\left| e^{-t}-e^{-6t} \\right| \\; dt < \\int\\limits_{0}^{\\infty} e^{-t} \\; dt < \\infty \n  \\]\n  the system is stable and the Fourier Transform exists, giving\n  \\[\nH(j\\omega) = \\mathcal{F}\\left\\{ \\left(e^{-t}-e^{-6t}\\right)u(t) \\right\\} = \\mathcal{F}\\left\\{ \\left(e^{-t}u(t) \\right\\} - \\mathcal{F}\\left\\{e^{-6t}\\right)u(t) \\right\\} = \\frac{1}{j\\omega + 1} - \\frac{1}{j\\omega + 6} = \\frac{7}{6-\\omega^2 + j7\\omega}\n\\]\\\\\n$\\blacksquare$\n\\end{example}\n\n\\subsection*{Directly from a LCCDE}\n\nBy the convolution theorem of the CTFT, the frequency response is the ratio of the output to input in the frequency domain, i.e.\n\\[\nH(j\\omega) = \\frac{Y(j\\omega)}{X(j\\omega)}\n\\]\nWe can easily determine this ratio from the LCCDE representation of the system using the derivative property of the Fourier Transform. Recall this property states if $\\mathcal{F}\\{x(t)\\} = X(j\\omega)$ then\n\\[\n\\mathcal{F}\\left\\{\\frac{d^n x}{dt^n}(t) \\right\\} = (j\\omega)^n  X(j\\omega) \\; .\n\\]\n\nIf the system is stable (and thus the frequency response exists) then \\textbf{all} roots of the characteriztic equation $Q(D)$ have real parts that are less than zero. If the system is stable we can take the Fourier transform of each term of the LCCDE using the derivative property, then algebrically solve for the ratio of output to input. Note this provides a signifigant savings in analysis effort since we do not have to first find the impulse response, then take it's Fourier transform to arrive at the frequency response (although that approach is still valid).\n\n\\begin{example} Consider a sytem decribed by the LCCDE\n  \\[\n\\frac{d^2y}{dt^2}(t) + 15\\frac{dy}{dt}(t) + 50y(t) = 10x(t) \n  \\]\n  Determine the frequency response of the system, if possible.\n\n  Solution: We first need to check for stability. The characteristic equation is $Q(D) = D^2 + 15D + 50$ which has two real roots $-10$ and $-5$. Since both are less than zero, the system is stable. Next we take the Fourier transform of both sides and apply the derivative property\n  \\[\n  (j\\omega)^2Y(j\\omega) + 15(j\\omega) Y(j\\omega) + 50Y(j\\omega) = 10X(j\\omega)\n  \\]\n  and rearrange to get the frequency response\n  \\[\n  H(j\\omega) = \\frac{Y(j\\omega)}{X(j\\omega)} = \\frac{10}{(j\\omega)^2 + 15(j\\omega) + 50} = \\frac{10}{50-\\omega^2 + j15\\omega}\n  \\]\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\section{Magnitude-phase representation of the CTFR}\n\nNote that any complex valued function can be expressed in polar form using the magnitude and phase. Specifically the input and output can be put into this form\n\\[\nX(j\\omega) = |X(j\\omega)|e^{\\angle X(j\\omega)}\n\\]\n\\[\nY(j\\omega) = |Y(j\\omega)|e^{\\angle Y(j\\omega)}\n\\]\n\nBy the convolution theorem then\n  \\[\n  H(j\\omega) = \\frac{Y(j\\omega)}{X(j\\omega)} = \\frac{|Y(j\\omega)|e^{\\angle Y(j\\omega)}}{X(j\\omega) = |X(j\\omega)|e^{\\angle X(j\\omega)}} = \\frac{|Y(j\\omega)|}{|X(j\\omega)|}e^{\\angle Y(j\\omega) - \\angle X(j\\omega)} = |H(j\\omega)|e^{\\angle H(j\\omega)}\n  \\]\n  Thus we see that\n  \\[\n  |H(j\\omega)| = \\frac{|Y(j\\omega)|}{|X(j\\omega)|}\n  \\]\n  and\n  \\[\n  \\angle H(j\\omega) = \\angle Y(j\\omega) - \\angle X(j\\omega)\n  \\]\n  This is the magnitude and phase representation of the frequency response.\n  \n\\section{CTFR acting on sinusoids}\n\nThe advantage of the magnitude and phase representation of the frequency response, is the ease with which we can find the output due to a sinusoidal input. If we apply a sinusoidal input $x(t) = A e^{j\\omega t}$, the output is a the same sinusoid scaled by the frequency response $y(t) = H(j\\omega) A e^{j\\omega t}$.\n\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/18-ct-fr.pdf}\n\\end{center}\n\nNow using the magnitude and phase representation\n\\[\ny(t) = H(j\\omega) A e^{j\\omega t} = |H(j\\omega)|e^{\\angle H(j\\omega)} A e^{j\\omega t} = A |H(j\\omega)| e^{j\\omega t + \\angle H(j\\omega)} \n\\]\nThus we can interpret the frequency response as telling us how the input sinsusoids are scaled in magnitude and phase shifted as they pass through the system.\n\nBy the linearity property this extends to real sinusoidal inputs since\n\\begin{align*}\n  x(t) &\\longrightarrow y(t)\\\\\n  \\sin(\\omega t) &\\longrightarrow \\frac{1}{2j}|H(j\\omega)| e^{j\\omega t + \\angle H(j\\omega)} - \\frac{1}{2j}|H(j\\omega)| e^{-j\\omega t + \\angle H(j\\omega)}\\\\\n  \\sin(\\omega t) &\\longrightarrow |H(j\\omega)|\\sin(\\omega t + \\angle H(j\\omega))  \n\\end{align*}\nand\n\\begin{align*}\n  x(t) &\\longrightarrow y(t)\\\\\n  \\cos(\\omega t) &\\longrightarrow \\frac{1}{2}|H(j\\omega)| e^{j\\omega t + \\angle H(j\\omega)} + \\frac{1}{2}|H(j\\omega)| e^{-j\\omega t + \\angle H(j\\omega)}\\\\\n  \\cos(\\omega t) &\\longrightarrow |H(j\\omega)|\\cos(\\omega t + \\angle H(j\\omega))  \n\\end{align*}\n\nAlso by the linearity property this analysis extends to the CT Fourier representation of a signal (an infinite sum of sinusoids):\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 = \\frac{1}{2\\pi}\\int\\limits_{-\\infty}^{\\infty} \\left| H(j \\omega)\\right| X(j \\omega) \\, e^{j \\omega t + \\angle H(j \\omega)}\\; d\\omega\n\\]\n\nThus we arrive at the reason for the name \\textit{Frequency Response} -- it specifies the the response of a stable system to any linear combination of sinusoidal inputs, i.e. any signal with a Fourier Transform.\n\n\n\\subsection{Bode plots}\n\nWe can visualize the frequency response as a plot of the real and imaginary part, or, of the magnitude and phase. Since the magnitude and phase allow us to directly see the system behavior at a given frequency, those plots are much more useful.\n\nRather than simply plot the magnitude and phase as a function of $\\omega$, it is common to change the abscissa (horizontal / $\\omega$-axis) to be on a logarithmic scale and so only plot the positive frequency portion of the spectrum (recall if the signal is real, the frequency response is even, so no information is lost). This is because the frequency response for physically realizable systems changes slowly as a function of frequency. Plotting on a log-scale compresses this information horizontally so that we can see how a wide range of frequency content is scaled. When plotting the magnitude spectrum it is also common to make the ordinate (vertical / gain axis) to be in decibels (dB). This is because of Weber's law, which states the humans perceive a doubling in strength of stimulus, when it is actually a ten-fold increase. Thus the magnitude of the frequency response in dB is $20 \\log_{10} |H(j\\omega)|$. When the frequency response is plotted this particular way we get what is called a \\textit{Bode plot} (after the engineer Hendrik Wade Bode, an important figure in the development of control theory).\n\nYou will likely encounter Bode plots at several points in your career, so it is important to understand them well enough to create them on your own using software and read them. Also data-sheets and other documentation for CT devices generally use a Bode plot rather than giving an explicit mathematical model of the frequency response. It is also instructive to learn how to plot them manually (which was the traditional way to do it) since it gives you insight that can help with reverse engineering a model, however we do not cover this in detail in this course. Note that we will plot the spectrum as a function of frequency in units of rad/s, but it is also common to see it plotted in units of Hz. Take care to read the horizontal axis label as mixing up the two is a common source of error.\n\n\\begin{example} Consider a frequency response given by\n  \\[\n  H(j\\omega) = \\frac{20000}{(j\\omega)^2 + 300(j\\omega) + 20000}\n  \\]\n  The following Matlab code shows you how to plot the spectrum as a Bode plot (with some extra code to make it look nicer). You should read the documentation for the \\texttt{bode} command in Matlab. It is also easy to just compute the magnitude and phase yourself.\n  \n\\begin{verbatim}\nH = tf([20000],[1,300,20000]);\n[mag,ph,w] = bode(H);\n\n% Create a nice bode plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = semilogx(w,20*log10(squeeze(mag)));\ngrid on;\nhTitle  = title ('Frequency Response');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, 'YTick', -60:10:20, ...\n    'Box', 'off', 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = semilogx(w,squeeze(ph*(pi/180)));\ngrid on;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/s)');\nset(gca, 'FontSize', 14, 'Box', 'off', 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\nThis gives the following plot\n\\begin{center}\n\\includegraphics[scale=0.5]{graphics/lecture20_1.png}\n\\end{center}\n\n$\\blacksquare$\n\\end{example}\n\nTo read a Bode plot to see the behavior of the system at a given frequency, one need only read the values off the plot and convert from dB to a unit-less gain. A common mistake is to not realize the horizontal axis is logarithmic.\n\n\\begin{example}\n  Suppose you are given the Bode plot (only) from the previous example and are asked what the output of the system is when the input is $x(t) = \\cos(2\\pi 32 t)$, i.e. a sinusoid at 32 Hz.\\\\\n  \\textbf{Solution:} First we determine the frequency in rad/s, $\\omega = 2\\pi 32 \\approx 200$ rad/s. We go to that frequency on the Bode plot and read off a value of about $-10$ dB for the magnitude and about $-1.9$ rad for the phase. To convert back from dB\n  \\[\n  |H(200)| = 10^{\\frac{-10}{20}} \\approx 0.3 \n  \\]\n  so the output would be\n  \\[\n  y(t) \\approx 0.3\\cos(2\\pi 32 t - 1.9)\n  \\]\n  $\\blacksquare$\n\\end{example}\n\n\\section{CTFR of first and second order systems}\n\nTODO\n", "meta": {"hexsha": "e7c5d10357a02552afc39ccaf4813b2a8493224c", "size": 12906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "18-ct-fr.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": "18-ct-fr.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": "18-ct-fr.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.8546255507, "max_line_length": 1120, "alphanum_fraction": 0.7064156206, "num_tokens": 3768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.8774767842777551, "lm_q1q2_score": 0.7851569882450163}}
{"text": "\\gotosection{2}{2}\n\\subsection{Solving equations with row reduction}\n\n\\begin{exercise}{3}\n\\begin{enumerate}\n\\item By row reduction, the soultion for this system is $x = w-2y$, $w = 3z$, $v = 0$, and $y, w$ are free variables. Now confirming the solution without using row reduction.\n\nLabel the four equations as $A, B, C, D$. Substituting $x+2y$ with $a$, $A+B$ gives $a = w$. Substituting this into $C$ and $D$ gives $3z + 2v = 9w$ and $z + v = 3w$, and in order to make these two compatible, $v = 0$, $z = 3w$. Since $a = x+2y = w$, $x=w-2y$.\n\n\\item Only $y, w$ are free variables, so the family of solutions depend on two variables.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{5}\n\\begin{enumerate}\n\\item If $a=0$, the system has a set of solutions $y=2, z=3$, and $x$ is a free variable.\n\nIf $a \\neq 0$, the matrix can be row reduced as:\n$[A|\\Vect{b}] = \\xmat{a&1&0&2\\\\0&a&1&3} \\rightarrow\n  \\rops{R_1: 1/aR_1}\n  \\xmat{1&1/a&0&2/a\\\\0&a&1&3} \\rightarrow\n  \\rops{R_2: 1/aR_2}\n  \\xmat{1&1/a&0&2/a\\\\0&1&1/a&3/a} \\\\ \\rightarrow\n  \\rops{R_1: R_1 - 1/aR_2}\n  \\xmat{1&0&-1/a^2&(2a-3)/a^2\\\\0&1&1/a&3/a}$\n  \nThen, as long as $a \\neq 0$, the result matrix is in echelon form and is consistent, so it has solutions. Therefore, for any value of $a$, the system has solutions.\n\n\\item There are three unknowns but only two equations, it's impossible for this system to have a unique solution.\n\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{7}\nThe matrix can be row reduced as:\n$[A|\\Vect{b}] = \\xmat{1&1&2&1 \\\\ 1&-1&a&b \\\\ 2&0&-b&0} \\rightarrow\n  \\rops{R_2: -R_1 + R_2 \\\\ R_2: -2R_1 + R_3} \\\\\n    \\xmat{1&1&2&1 \\\\ 0&-2&a-2&b-1 \\\\ 0&-2&-b-4&-2} \\rightarrow\n  \\rops{R_2: -1/2R_2}\n    \\xmat{1&1&2&1 \\\\ 0&1&(2-a)/2&(1-b)/2 \\\\ 0&-2&-b-4&-2} \\\\ \\rightarrow\n  \\rops{R_1: R_1 - R_2 \\\\ R_3: 2R_2 + R_3}\n    \\xmat{1&0 & (2+a)/2 & (1+b)/2 \\\\\n          0&1 & (2-a)/2 & (1-b)/2 \\\\\n          0&0 & 2+a+b   & b+1}$\n          \n\\begin{enumerate}\n\\item If $2+a+b = 0$, there exists two possibilities: first, $b+1 \\neq 0$, the linear system is inconsistent and thus has no solutions; second, $b + 1 = 0$, then $a=b=-1$, substitute $a,b$:\n$$\\xmat{1&0 & 1/2 & 0  \\\\\n        0&1 & 3/2 & -1 \\\\\n        0&0 & 0   & 0}$$\n        \nThe result matrix is in echelon form. The third column has no pivotal, so the system has infinitely many solutions with one free variable:\n\\begin{align*}\n  x &= 0 - 1/2s  \\\\\n  y &= -1 - 3/2s \\\\\n  z &= s\n\\end{align*}\nIf $2+a+b \\neq 0$, the matrix can be further reduced into the identity matrix, and therefore has a unique solution:\n$$x = \\frac{1}{2} \\cdot \\frac{b(b+1)}{2+a+b} \\quad\n  y = \\frac{1}{2} \\cdot \\frac{2a-3b-b^2}{2+a+b} \\quad\n  z = \\frac{b+1}{2+a+b}$$\n\\end{enumerate}\n\\end{exercise}", "meta": {"hexsha": "bfad0650c96ddd4d11f2e5620d1fb47504dfb005", "size": 2692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW4/sec0202.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/sec0202.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/sec0202.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": 43.4193548387, "max_line_length": 260, "alphanum_fraction": 0.6058692422, "num_tokens": 1122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.7851569806412267}}
{"text": "%\n% Chapter 4.4\n%\n\n\\section*{4.4 Indefinite Integrals and Net Change Theorem}\n\n$$ \\int f(x)dx \\quad \\text{ means } \\quad F'(x)=f(x) $$\n\\\\\nNotice that a definite integral is a number, while an indefinite integral is a function (or family of functions).\n\n\\subsection*{Formulae for Indefinite Integrals}\n\n$$ \\int cf(x)dx = c \\int f(x)dx $$\n$$ \\int kf(x)dx = kx + C $$\n$$ \\int [f(x) +  g(x)]dx = \\int f(x)dx + \\int g(x)dx $$\n$$ \\int x^n dx = \\frac{x^{n+1}}{n+1} + C \\quad \\text{ when } n \\neq -1 $$\n$$ \\int \\sin(x)dx = -\\cos(x) + C $$\n$$ \\int \\cos(x)dx = \\sin(x) + C $$\n$$ \\int \\sec^2(x)dx = \\tan(x) + C $$\n$$ \\int \\csc^2(x)dx = -\\cot(x) + C $$\n$$ \\int \\sec(x)\\tan(x)dx = \\sec(x) + C $$\n$$ \\int \\csc(x)\\cot(x)dx = -\\csc(x) + C $$\n\n\\subsection*{Net Change Theorem}\n\nThe integral of a rate of change is the net change\n$$ \\int_a^b F'(x)dx = F(b) - F(a) $$\n\n\n\n", "meta": {"hexsha": "8f61d166069671018497e42c3743e9a6926db795", "size": 852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4-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/4-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/4-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": 27.4838709677, "max_line_length": 113, "alphanum_fraction": 0.5551643192, "num_tokens": 346, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759489, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7851028639503255}}
{"text": "\\chapter{Golden Ratio}\n\nIn mathematics and the arts, two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities, i.e.~their maximum. The figure on the right illustrates the geometric relationship. Expressed algebraically, for quantities $a$ and $b$ with $a > b$,\n\\begin{equation}\n \\frac{a+b}{a} = \\frac{a}{b} \\ \\stackrel{\\text{def}}{=}\\ \\varphi,\n\\end{equation}\nwhere the Greek letter $\\varphi$ represents the golden ratio. Its value is:\n\\begin{equation}\n\\varphi = \\frac{1+\\sqrt{5}}{2} = 1.61803\\,39887\\ldots.\n\\end{equation}\n\n\\section{History}\n\nAncient Greek mathematicians first studied what we now call the golden ratio because of its frequent appearance in geometry. The division of a line into ``extreme and mean ratio'' (the golden section) is important in the geometry of regular pentagrams and pentagons. Euclid's Elements  provides the first known written definition of what is now called the golden ratio: ``A straight line is said to have been cut in extreme and mean ratio when, as the whole line is to the greater segment, so is the greater to the less.'' Euclid explains a construction for cutting (sectioning) a line ``in extreme and mean ratio'', i.e., the golden ratio. (See Figure~\\ref{fig:line:golden}.) Throughout the Elements, several propositions (theorems in modern terminology) and their proofs employ the golden ratio.\n\n\\begin{figure}[hbt!]\\centering\n\\includegraphics[width=.3\\textwidth]{220px-Golden-ratio-line}\n\\caption{Line segments in the golden ratio}\n\\label{fig:line:golden}\n\\end{figure}\n\n\\begin{figure}[hbt!]\\centering\n\\includegraphics[width=.3\\textwidth]{SimilarGoldenRectangles}\n\\caption{Golden rectangles}\n\\end{figure}\n\n\n\n\\section{Calculation}\nTwo quantities $a$ and $b$ are said to be in the golden ratio $\\varphi$ if:\n\\begin{equation}\n \\frac{a+b}{a} = \\frac{a}{b} = \\varphi.\n\\end{equation}\n\nOne method for finding the value of $\\varphi$ is to start with the left fraction. Through simplifying the fraction and substituting in $\\frac{b}{a} = \\frac{1}{\\varphi}$,\n\\begin{equation}\n\\frac{a+b}{a} = 1 + \\frac{b}{a} = 1 + \\frac{1}{\\varphi},\n\\end{equation}\n\nBy definition, it is shown that\n\\begin{equation}\n 1 + \\frac{1}{\\varphi} = \\varphi. \n\\end{equation}\nMultiplying by $\\varphi$ gives\n\\begin{equation*}\n\\varphi + 1 = \\varphi^2\n\\end{equation*}\nwhich can be rearranged to\n\\begin{equation*}\n{\\varphi}^2 - \\varphi - 1 = 0.\n\\end{equation*}\nUsing the quadratic formula, two solutions are obtained:\n\\begin{equation*}\n\\varphi = \\frac{1 + \\sqrt{5}}{2} = 1.61803\\,39887\\dots\n\\end{equation*}\nand\n\\begin{equation*}\n\\varphi = \\frac{1 - \\sqrt{5}}{2} = -0.6180\\,339887\\dots\n\\end{equation*}\nBecause $\\varphi$ is the ratio between positive quantities $\\varphi$ is necessarily positive:\n\\begin{equation*}\n\\varphi = \\frac{1 + \\sqrt{5}}{2} = 1.61803\\,39887\\dots .\n\\end{equation*}\n\nDifferent representations of the golden ratio are given in Table~\\ref{tab:goldenratio}.\n\n\\begin{table}[hbt!]\\centering\n\\caption{Number representations of the golden ratio}\n\\label{tab:goldenratio}\n\n\\begin{tabular}{|l|l|}\n\\hline\nForm & Representation\\\\\\hline\nBinary & 1.1001111000110111011\\ldots\\\\\\hline\nDecimal & 1.6180339887498948482\\ldots\\\\\\hline\nHexadecimal\t& 1.9E3779B97F4A7C15F39\\ldots\\\\\\hline\nContinued fraction & $1 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\cfrac{1}{1 + \\ddots}}}}$\\\\[6ex]\\hline\nAlgebraic form & $\\displaystyle\\frac{1 + \\sqrt{5}}{2}$\\\\[2ex]\\hline\nInfinite series & $\\displaystyle\\frac{13}{8}+\\sum_{n=0}^{\\infty}\\frac{(-1)^{(n+1)}(2n+1)!}{(n+2)!\\,n!\\,4^{(2n+3)}}$\\\\[2ex]\\hline\n\\end{tabular}\n\\end{table}\n", "meta": {"hexsha": "1ceb295d1efbcb6a4914d7c8c2392eb4e9478e30", "size": 3589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GayaUKM-LaTeX/chap-goldenratio.tex", "max_stars_repo_name": "gijswijs/phd_thesis_markdown", "max_stars_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GayaUKM-LaTeX/chap-goldenratio.tex", "max_issues_repo_name": "gijswijs/phd_thesis_markdown", "max_issues_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GayaUKM-LaTeX/chap-goldenratio.tex", "max_forks_repo_name": "gijswijs/phd_thesis_markdown", "max_forks_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_forks_repo_licenses": ["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.7682926829, "max_line_length": 797, "alphanum_fraction": 0.7230426303, "num_tokens": 1180, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122138417878, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7850283872917249}}
{"text": "\\pagebreak\n\\newpage\n\n\\pagebreak\n\\newpage\n\n\\section{Classifier}\n\nClassifiers were developed for three cases.\n\n\\begin{itemize}\n \\item Classifier with $\\Sigma = \\sigma^2 \\cdot \\mathbf{I}$\n \\item Classifier with $\\Sigma = \\Sigma_i$\n \\item Classifier with arbitrary $\\Sigma$\n\\end{itemize}\n\n\n\\subsection{Case A}\nFor the first case, $\\sigma$ was assigned as $\\sigma = 0.25$.\nGiven this restriction, the multivariate PDF was obtained, as shown in Figure \\ref{fig: case a PDF}\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width = 0.8\\textwidth]{pdfCaseA}\n \\caption{PDF for Case A}\n \\label{fig: case a PDF}\n\\end{figure}\n\n\\begin{align*}\n g_i(x) &= - \\frac{\\norm{x-\\mu_i}^2}{2\\sigma^2} + \\ln P(\\omega_i)\\\\\n \\norm{x-\\mu_i}^2 &= (x-\\mu_i)^T (x-\\mu_i)\\\\\n g_i(x) &= w^T_i x + \\omega_{i0}\\\\\n w_i &= \\frac{1}{\\sigma^2} \\mu\\\\\n w_{i0} &= \\frac{-1}{2 \\sigma^2} \\mu^T_i \\mu_i + ļn P(\\omega_i)\n\\end{align*}\n\n\n\\pagebreak\n\\newpage\n\n\nAfterwards, the \\emph{a posteriori} probability is obtained and the boundaries of the classifier are obtained.\nThe results are shown in Figure \\ref{fig: posteriori case A}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= 0.8\\textwidth]{classifierSetosaCaseA}\n \\caption{Case A - A posteriori probability}\n \\label{fig: posteriori case A}\n\\end{figure}\n\n\n\n\n\\pagebreak\n\\newpage\n\n\nThe classifier was tested against a sample of 75 entries from the dataset. Each entry was assigned a colour based on the assigned variety:\nyellow for Setosa, black for Versicolor and magenta for Virginica.\nThis is presented in Figure \\ref{fig: classifier case A}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= \\textwidth]{testClassifierCaseA}\n \\caption{Case A - Boundaries}\n \\label{fig: classifier case A}\n\\end{figure}\n\n\n\n\n\\pagebreak\n\\newpage\n\n\\pagebreak\n\\newpage\n\n\\subsection{Case B}\nFor the first case, $\\Sigma$ was assigned as\n\n\\begin{equation*}\n \\begin{pmatrix}\n  0.26 & 0.04 &  0.02 & 0.01 \\\\\n  0.04 &  0.22 & 0.03 & 0.02 \\\\\n  0.02 & 0.03 & 0.15 & 0.15\\\\\n  0.01 & 0.02 &  0.15 & 0.31\n \\end{pmatrix}\n\\end{equation*}\n\nThis new covariance matrix influenced the multivariate gaussian distribution of the system,\nas seen in Figure \\ref{fig: case b PDF}.\n\n\\begin{figure}[htb!]\n \\includegraphics[width = \\textwidth]{pdfCaseB}\n \\caption{PDF for Case B}\n \\label{fig: case b PDF}\n\\end{figure}\n\n\\pagebreak\n\\newpage\n\n\nAfterwards, the \\emph{a posteriori} probability is obtained and the boundaries of the classifier are obtained.\nThe results are shown in Figure \\ref{fig: posteriori case B}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= 0.8\\textwidth]{classifierSetosaCaseB}\n \\caption{Case B - A posteriori probability}\n \\label{fig: posteriori case B}\n\\end{figure}\n\n\\begin{align*}\n g_i(x) &= x^T W_i x + w^T_i x + \\omega_{i0}\\\\\n W_i &= -\\frac{1}{2}\\Sigma^{-1}_i\\\\\n w_i &= \\Sigma^{-1}_i \\mu_i\\\\\n \\omega_{i0}&= -\\frac{1}{2} \\mu^T_i \\Sigma^{-1}_i \\mu_i - \\frac{1}{2}\\ln \\det(\\Sigma_i) + \\ln P(\\omega_i)\n\\end{align*}\n\n\\pagebreak\n\\newpage\n\n\nThe classifier was tested against a sample of 75 entries from the dataset. Each entry was assigned a colour based on the assigned variety:\nyellow for Setosa, black for Versicolor and magenta for Virginica.\nThis is presented in Figure \\ref{fig: classifier case B}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= \\textwidth]{testClassifierCaseB}\n \\caption{Case B - Boundaries}\n \\label{fig: classifier case B}\n\\end{figure}\n\n\\pagebreak\n\\newpage\n\n\n\\pagebreak\n\\newpage\n\n\\subsection{Case C}\nFor the third case, $\\Sigma$ was left untouched, allowing the covariance matrix to\nreflect the nature of the data available.\nThis is observed in Figure \\ref{fig: case c PDF}.\n\n\\begin{figure}[htb!]\n \\includegraphics[width = \\textwidth]{pdfCaseC}\n \\caption{PDF for Case C}\n \\label{fig: case c PDF}\n\\end{figure}\n\n\\pagebreak\n\\newpage\n\n\nAfterwards, the \\emph{a posteriori} probability is obtained and the boundaries of the classifier are obtained.\nThe results are shown in Figure \\ref{fig: posteriori case C}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= 0.8\\textwidth]{classifierSetosaCaseC}\n \\caption{Case C - A posteriori probability}\n \\label{fig: posteriori case C}\n\\end{figure}\n\n\\pagebreak\n\\newpage\n\n\\begin{align*}\n g_i(x) &= -\\frac{1}{2} (x-\\mu_i)^T \\Sigma^{-1} (x-\\mu) + \\ln P(\\omega_i)\\\\\n g_i(x) &= w^T_i x + \\omega_{i0}\\\\\n w_i &= \\Sigma^{-1} \\mu_i\\\\\n w_{i0} &= \\frac{-1}{2}\\mu^T_i \\Sigma^{-1}  \\mu_i + ļn P(\\omega_i)\n\\end{align*}\n\nThe classifier was tested against a sample of 75 entries from the dataset. Each entry was assigned a colour based on the assigned variety:\nyellow for Setosa, black for Versicolor and magenta for Virginica.\nThis is presented in Figure \\ref{fig: classifier case C}.\n\n\\begin{figure}[htb!]\n\\centering\n \\includegraphics[width= \\textwidth]{testClassifierCaseC}\n \\caption{Case C - Boundaries}\n \\label{fig: classifier case C}\n\\end{figure}\n\n\\pagebreak\n\\newpage\n", "meta": {"hexsha": "54ad4c41a0e286b5faae8777760e3e1ad62b4a21", "size": 4847, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/classifier.tex", "max_stars_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_stars_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/classifier.tex", "max_issues_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_issues_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/classifier.tex", "max_forks_repo_name": "der-coder/CINVESTAV-Mathematics-II-2020", "max_forks_repo_head_hexsha": "ccd3364818c673f7a6bf13d495004034d2c6ecc0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3769633508, "max_line_length": 138, "alphanum_fraction": 0.7121931091, "num_tokens": 1574, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998822, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7850161272767856}}
{"text": "\\documentclass[12pt]{article}\n\n\\begin{document}\n\n\\def\\pair{\\stackrel{\\mbox{\\tiny FT}}{\\Longleftrightarrow}}\n\\def\\ft{{\\cal F}}\n\\def\\ift{{\\cal F}^{\\mbox{\\,-}1}}\n\\parindent 0pt\n\n\\section{Smoothing spectra via Fourier transforms}\n\nSmoothing data with an even smoothing function is equivalent to\nconvolving the data with that function. This can be achieved via\nFourier transforms.\n \n\\subsection{Definition of terms}\n\n\\begin{itemize}\n\\item Let $\\ft(g)$ denote the Fourier transform of a function $g$.\n\\item Let $\\ift(G)$ denote the inverse Fourier transform of a function $G$.\n\\item Let $.$ denote multiplication, and $\\otimes$ denote convolution.\n\\item Let the smoothing function be denoted by $s$.\n\\item Let the original arrays of data values and weights be denoted by $f$ and $w$, respectively.\n\\item Let the smoothed arrays of data values and weights be denoted by $\\overline{f}$ and $\\overline{w}$, respectively.\n\\end{itemize}\n\n\\subsection{Smoothing a discrete array using an unweighted convolution}\n\nThe Fourier convolution theorem says that multiplying the Fourier\ntransforms of two continuous functions by each other and then taking\nthe inverse transform of the result yields the convolution of the two\nfunctions.\n\n\\begin{eqnarray}\n     \\overline{f} &=& f \\otimes s \\\\\n%\n     \\label{convolve}\n     \\overline{f} &=& \\ift\\left[\\ft(f).\\ft(s)\\right]\n\\end{eqnarray}\n\nFor discretely sampled data one can either convolve the two functions\nexplicitly via\n\n\\begin{equation}\n \\overline{f_{i}} = \\frac{\\sum_{u} f_{u}.s_{i-u}}\n\t                 {\\sum_{u} s_{i-u}}\n\\end{equation}\n\nor substitute a discrete Fourier transform for each of the Fourier\ntransforms shown in equation~\\ref{convolve}. In practice, if the\nwidth of the smoothing function encompasses a significant number of\nelements of the function being smoothed then it will be faster to use the\nlatter approach, particularly if a Fast Fourier Transform can be used.\n\n\\subsection{Smoothing a discrete array using a weighted convolution}\n\nIf the data are weighted then one must take account of the weights\nduring convolution, and the convolution must be modified to\n\n\\begin{eqnarray}\n \\overline{f_{i}} &=& \\frac{\\sum_{u} f_{u}.w_{u}.s_{i-u}} {\\sum_{u} w_{u}.s_{i-u}}\\\\\n     \\overline{f} &=& \\frac {f.w \\otimes s} {w \\otimes s}\\\\\n     \\overline{f} &=& \\frac {\\ift[\\ft(f.w).\\ft(s)]} {\\ift[\\ft(w).\\ft(s)]}\n\\end{eqnarray}\n\nThe original weights of the unsmoothed data are also modified by smoothing.\nIf the weight of each $f_i$ is defined in terms of its variance\n$\\sigma_i^2$, as\n\n\\begin{equation}\n  w_{i}  = \\frac{1}{\\sigma_{i}^2},\n\\end{equation}\n\nThen the weight $\\overline{w_{i}}$ that should be assigned to\n$\\overline{f_{i}}$, is given by:\n\n\\begin{eqnarray}\n \\frac{1}{\\overline{w_{i}}} &=& \\sum_{j}\\left(\\frac{\\partial\\overline{f_{i}}}{\\partial f_{j}}\\right)^{2} . \\frac{1}{w_{j}} \\\\\n%\n \\frac{\\partial \\overline{f_{i}}}{\\partial f_{j}} &=& \\frac {w_{j}.s_{i-j}}{\\sum_{u} w_{u} . s_{i-u}} \\\\\n%\n \\frac{1}{\\overline{w_{i}}} &=& \\sum_{j}\\left(\\frac {w_{j}.s_{i-j}}{\\sum_{u} w_{u} . s_{i-u}}\\right)^{2} . \\frac{1}{w_{j}} \\\\\n%\n \\label{variance}\n \\frac{1}{\\overline{w_{i}}} &=& \\frac {\\sum_{j} w_{j}.s_{i-j}^2}{(\\sum_{u} w_{u} . s_{i-u})^{2}}\n\\end{eqnarray}\n\nIn terms of convolutions this can be re-expressed as\n\n\\begin{equation}\n \\frac{1}{\\overline{w_{i}}} = \\frac {w \\otimes s^{2} } {(w \\otimes s)^2}.\n\\end{equation}\n\nThe smoothed data array and its weights can then be obtained via\nFourier transforms as:\n\n\\begin{eqnarray}\n \\overline{f} =& \\frac {f.w \\otimes s} {w \\otimes s} &= \\frac{\\ift\\left[\\ft(f.w).\\ft(s)\\right]} {\\ift\\left[\\ft(w).\\ft(s)\\right]}\\\\\n \\overline{w} =& \\frac {(w \\otimes s)^2}{w \\otimes s^{2} } &= \\frac{\\left(\\ift\\left[\\ft(w).\\ft(s)\\right]\\right)^2}{\\ift\\left[\\ft(w).\\ft(s^{2})\\right]}\n\\end{eqnarray}\n\nThus, to account for data weights when smoothing an array, one must\nfirst determine $\\ft(s)$ and $\\ft(s^2)$ for the chosen smoothing\nfunction.\n\n\\section{Smoothing functions}\n\n\\def\\fwhm{\\mbox{\\tiny FWHM}}\n\nEach smoothing function will be described in terms of its full-width\nat half maximum value, denoted as $\\fwhm$. For convenience the\ndependent coordinate of each function will be defined such that it is\nunity where the function falls to half its maximum value. In terms of\nthe spectrum channel--based coordinates, $i$ this requires the\nfollowing change of coordinates.\n\n\\begin{equation}\n  \\delta x = \\frac{2 \\delta i}{\\fwhm}.\n\\end{equation}\n\nIn the Fourier plane this has the effect of modifying the delay\ncoordinate increment per channel $j$ from $1/n$ to $2.\\fwhm/n$,\nyielding\n\n\\begin{equation}\n  \\delta t = 2.\\delta j.\\fwhm / n.\n\\end{equation}\n\nNote that in order that the total power in the smoothed data be\nunchanged by smoothing. The area under the smoothing function and thus\nthe value at the origin of its Fourier transform, must be unity.\n\n\\subsection{Hanning}\n\n\\begin{eqnarray}\ns_{x} &=& \\frac{\\sin(\\pi x)} {2\\pi x(1-x^2)}\\\\\n\\ft(s_{x}) &=& \\left\\{\n              \\begin{array}{rl} \\frac{1}{2}[1 + \\cos(2\\pi t)] & |t| \\le \\frac{1}{2}\\\\\n                                                            0 & |t|   > \\frac{1}{2}\\\\\n              \\end{array}\n        \\right.\\\\\n\\ft(s_{x}^2) &=&  \\left\\{\n              \\begin{array}{rl} \\frac{1}{4}[(1 - |t|)(1+\\frac{1}{2}\\cos(2\\pi t)) + \\frac{3}{4\\pi}\\sin(2\\pi|t|)] & |t| \\le 1\\\\\n                                                            0 & |t|   > 1\\\\\n              \\end{array}\n        \\right.\n\\end{eqnarray}\n\n\\subsection{Gaussian}\n\n\\begin{eqnarray}\ns_{x} &=& \\sqrt{\\ln(2)/\\pi} \\; e^{-\\ln(2) x^{2}}\\\\\n\\ft(s_{x}) &=& e^{-\\frac{\\pi^2 t^2}{\\ln(2)}}\\\\\n\\ft(s_{x}^2) &=& \\sqrt{\\ln(2)/2\\pi} \\; e^{-\\frac{\\pi^2 t^2}{2 \\ln(2)}}\n\\end{eqnarray}\n\n\\subsection{Boxcar}\n\n\\begin{eqnarray}\ns_{x} &=& \\left\\{\n              \\begin{array}{ll} \\frac{1}{2} & |x| \\le 1\\\\\n                                          0 & |x|   > 1\\\\\n              \\end{array}\n        \\right.\\\\\n\\ft(s_{x}) &=& \\frac{\\sin(2\\pi t)}{2\\pi t}\\\\\n\\ft(s_{x}^2) &=& \\frac{1}{2} \\frac{\\sin(2\\pi t)}{2\\pi t}\n\\end{eqnarray}\n\n\\subsection{Sinc}\n\n\\begin{eqnarray}\ns_{x} &=& \\frac{\\beta}{\\pi} \\frac{\\sin(\\beta x)}{\\beta x}\\\\\n\\beta &=& 1.8954942670340\\\\\n\\ft(s_{x}) &=& \\left\\{\n              \\begin{array}{ll} 1 & |t| \\le \\frac{\\beta}{2\\pi}\\\\\n                                0 & |t|   > \\frac{\\beta}{2\\pi}\\\\\n              \\end{array}\n        \\right.\\\\\n\\ft(s_{x}^2) &=& \\left\\{\n                     \\begin{array}{ll} \\frac{\\beta}{\\pi} - t & |t| \\le \\frac{\\beta}{\\pi}\\\\\n                                                           0 & |t|   > \\frac{\\beta}{\\pi}\\\\\n                     \\end{array}\n                  \\right.\n\\end{eqnarray}\n\n\\end{document}\n", "meta": {"hexsha": "3758429ee7094636bf81b073903ef3320cb2d709", "size": 6605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/smooth.tex", "max_stars_repo_name": "sabourke/difmap", "max_stars_repo_head_hexsha": "390949f2a49070e52b5cc824ec8f5f37df735020", "max_stars_repo_licenses": ["ICU"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-05-27T20:09:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T14:56:50.000Z", "max_issues_repo_path": "doc/smooth.tex", "max_issues_repo_name": "sabourke/difmap", "max_issues_repo_head_hexsha": "390949f2a49070e52b5cc824ec8f5f37df735020", "max_issues_repo_licenses": ["ICU"], "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/smooth.tex", "max_forks_repo_name": "sabourke/difmap", "max_forks_repo_head_hexsha": "390949f2a49070e52b5cc824ec8f5f37df735020", "max_forks_repo_licenses": ["ICU"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-04-25T12:40:40.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-03T15:06:10.000Z", "avg_line_length": 35.320855615, "max_line_length": 150, "alphanum_fraction": 0.6127176382, "num_tokens": 2187, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640645, "lm_q2_score": 0.8615382076534743, "lm_q1q2_score": 0.7850161259018859}}
{"text": "\n\\subsection{Raising and lowering indices}\n\nWe showed that the inner product between two vectors with the same basis can be written as:\n\n\\(\\langle v, w\\rangle =\\langle \\sum_i e_iv^i, \\sum_j f_jw^j\\rangle \\)\n\n\\(\\langle v, w\\rangle =v^i\\overline {w^j}\\langle e_i, e_j\\rangle\\)\n\nDefining the metric as:\n\n\\(g_{ij}:=\\langle e_i,e_j\\rangle \\)\n\n\\(\\langle v, w\\rangle =v^i\\overline {w^j}g_{ij}\\)\n\n\\subsubsection{Metric inverse}\n\nWe can use this to define the inverse of the metric.\n\n\\(g^{ij}:=(g_{ij})^{-1}\\)\n\nWe can use this to raise and lower vectors.\n\n\\(v_i:=v^jg_{ij}\\)\n\n\\subsubsection{Raising and lowering indices of tensors}\n\nIf we have tensor:\n\n\\(T_{ij}\\)\n\nWe can define:\n\n\\(T_i^k=T_{ij}g^{jk}\\)\n\n\\(T^{il}=T_{ij}g^{jk}g^{kl}\\)\n\n\\subsubsection{Tensor contraction}\n\nIf we have:\n\n\\(T_{ij}x^j\\)\n\nWe can contract it to:\n\n\\(T_{ij}x^j=v_i\\)\n\nSimilarly we can have:\n\n\\(T^{ij}x_j=v^i\\)\n\n", "meta": {"hexsha": "c14c6a18900eec8e3f3d5acc64b9b487d12b854d", "size": 877, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/02-02-juggling.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/tensors/02-02-juggling.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/tensors/02-02-juggling.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.8653846154, "max_line_length": 91, "alphanum_fraction": 0.6659064994, "num_tokens": 306, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778073288128, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7848656885275515}}
{"text": "\\section{K-Nearest Neighbors}\nThe $k$-nearest neighbors algorithm, commonly known as\n$k$-NN, is a non-parametric approach where the response of a data point\nis determined by the nature of its $k$ neighbors from the training set.\nIt can be used in both classification and regression settings.\nThe higher the parameter $k$, the higher the bias, and the lower the parameter\n$k$, the higher the variance.\n\\subsection{Classification}\nIn $k$-NN classification, the output is a class membership. An object is\nclassified by a majority vote of its neighbors, with the object being assigned\nto the class most common among its $k$ nearest neighbors ($k$ is a positive integer,\ntypically small). If $k = 1$, then the object is simply assigned to the class\nof that single nearest neighbor.\n\\subsection{Regression}\nIn $k$-NN regression, the output is the property value for the object.\nThis value is the average of the values of its k nearest neighbors.\n\\begin{equation} y = \\frac{1}{k} \\sum_{x_i \\in \\mathcal{N}_k(x)} y_i \\end{equation}\nwhere $\\mathcal{N}_k(x)$ is the $k$ nearest points around $x$.\n", "meta": {"hexsha": "6c86585f64a061928f2d3f1d73d755c4f5e5cdba", "size": 1087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/knn.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/knn.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/knn.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.2105263158, "max_line_length": 84, "alphanum_fraction": 0.7635694572, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.957277806109987, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.784865685421823}}
{"text": "%---------------------------Maximum Aspect Frobenius---------------------------\n\\section{Maximum 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 take the maximum value of the eight unique tetrahedral aspects\n\\[\n  q = \\max\\left(F_{0134}, F_{1205}, F_{2316}, F_{3027}, F_{4750}, F_{5461}, F_{6572}, F_{7643} \\right).\n\\]\n\nIn the past, this metric was called the condition number and computed \nin terms of the Jacobian matrices $A_i$ and\ntheir determinants $\\alpha_i$ as in \\S\\ref{s:hex}.\nWe provide that method of computation below for reference purposes.\nFirst, define\n\\[\n\\kappa(A_i)\n  = \\left|A_i\\right| \\left|A_i^{-1}\\right|\n  = \\frac {\\left|A_i\\right| \\left|\\mathrm{adj}(A_i)\\right|}{\\alpha_i}.\n\\]\nThere are 9 of these matrices and we evaluate the condition number at each and take a third of the maximum:\n\\[\nq = \\frac {1}{3} \\max\\left\\{ \\kappa(A_0), \\kappa(A_1), \\ldots, \\kappa(A_8) \\right\\}\n\\]\nThe first 8 matrices represent the condition at the corners and the last represents the condition number\nat the element's center.\nNote that if $\\alpha_i \\leq DBL\\_MIN$, for any $i$, then $q = DBL\\_MAX$.\n\n\\hexmetrictable{maximum 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{\\cite{knu:00}}%                              Citation\n{v\\_hex\\_max\\_aspect\\_frobenius \\textnormal{or} %\n v\\_hex\\_condition$^*$}%                      Verdict function name\n\n\\noindent\\,$^*$ indicates a function that is deprecated and may be removed in future versions of \\verd.\n", "meta": {"hexsha": "89bf36136dc75a5c513125850559b120b507bd8f", "size": 2314, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexMaxAspectFrobenius.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/HexMaxAspectFrobenius.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/HexMaxAspectFrobenius.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": 49.2340425532, "max_line_length": 107, "alphanum_fraction": 0.6443388073, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.7848062057989132}}
{"text": "\\section{Transformations}\nIn this section we will show how to implement three transformations of the plane, in increasing difficulty. We will see that they all correspond to linear transformations on complex numbers, that is, functions of the form $f(p) = a \\ast p + b$ for $a,b,p \\in \\complex$, and deduce a way to compute a general transformation that combines all three.\n\n\\subsection{Translation}\nTo translate an object by a vector $\\vv{v}$, we simply need to add $\\vv{v}$ to every point in the object. The corresponding function is $f(p) = p + \\vv{v}$ with $\\vv{v} \\in \\complex$.\n\n\\centerFig{transfo0}\n\nThe implementation is self-explanatory:\n\\begin{lstlisting}\npt translate(pt v, pt p) {return p+v;}\n\\end{lstlisting}\n\n\\subsection{Scaling}\nTo scale an object by a certain ratio $\\alpha$ around a center $c$, we need to shorten or lengthen the vector from $c$ to every point by a factor $\\alpha$, while conserving the direction.\nThe corresponding function is $f(p) = c + \\alpha(p-c)$ ($\\alpha$ is a real here, so this is a scalar multiplication).\n%This is also a linear transformation on complex numbers: we can write $f(x) = \\alpha \\ast x + (1-\\alpha)p$.\n\n\\centerFig{transfo1}\n\nAgain, the implementation is just a translation of the expression into code:\n\\begin{lstlisting}\npt scale(pt c, double factor, pt p) {\n    return c + (p-c)*factor;\n}\n\\end{lstlisting}\n\n\\subsection{Rotation}\\label{ss:rotation}\nTo rotate an object by a certain angle $\\phi$ around center $c$, we need to rotate the vector from $c$ to every point by $\\phi$. From our study of polar coordinates in \\ref{polar-form} we know this is equivalent to multiplying by $\\cis\\phi$, so the corresponding function is $f(p) = c + \\cis\\phi\\ast(p-c)$.\n\n\\centerFig{transfo2}\n\nIn particular, we will often use the (counter-clockwise) rotation centered on the origin. We use complex multiplication to figure out the formula:\n\\begin{align*}\n(x+yi)\\ast\\cis\\phi &= (x+yi)\\ast(\\cos\\phi + i\\sin\\phi) \\\\\n&= (x\\cos\\phi - y\\sin\\phi) + (x\\sin\\phi + y\\cos\\phi)i\n\\end{align*}\nwhich gives the following implementation:\n\\begin{lstlisting}\npt rot(pt p, double a) {\n    return {p.x*cos(a) - p.y*sin(a), p.x*sin(a) + p.y*cos(a)};\n}\n\\end{lstlisting}\nwhich if using \\lstinline|complex| can be simplified to just\n\\begin{lstlisting}\npt rot(pt p, double a) {return p * polar(1.0, a);}\n\\end{lstlisting}\n\nAnd among those, we will use the rotation by $90\\degree$ quite often:\n\\begin{align*}\n(x+yi)\\ast\\cis(90\\degree) &= (x+yi)\\ast(\\cos(90\\degree) + i\\sin(90\\degree)) \\\\\n&= (x+yi)\\ast i = -y+xi\n\\end{align*}\nIt works fine with integer coordinates, which is very useful:\n\\begin{lstlisting}\npt perp(pt p) {return {-p.y, p.x};}\n\\end{lstlisting}\n\n\\subsection{General linear transformation}\nIt is easy to check that all those transformations are of the form $f(p) = a \\ast p + b$ as claimed in the beginning of this section. In fact, all transformations of this type can be obtained as combinations of translations, scalings and rotations.\\footnote{Actually, if $a = 1$ it is just a translation, and if $a \\neq 1$ it is the combination of a scaling and a rotation combination from a well-chosen center.}\n\nJust like for real numbers, to determine a linear transformation such as this one, we only need to know the image of two points to know the complete function. Indeed, if we know $f(p) = a \\ast p + b$ and $f(q) = a \\ast q + b$, then we can find $a$ as $\\frac{f(q)-f(p)}{q-p}$, and then $b$ as $f(p) - a \\ast p$.\n\nAnd thus if we want to know a new point $f(r)$ of that transformation, we can then compute it as:\n\\[f(r) = f(p) + (r-p) \\ast \\frac{f(q)-f(p)}{q-p}\\]\n\n%Note that the triangles $pqr$ and $f(p)f(q)f(r)$ formed this way are similar:\n\\centerFig{transfo3}\n\nThis is easy to implement using \\lstinline|complex|:\n\\begin{lstlisting}\npt linearTransfo(pt p, pt q, pt r, pt fp, pt fq) {\n    return fp + (r-p) * (fq-fp) / (q-p);\n}\n\\end{lstlisting}\n\nOtherwise, you can use the cryptic but surprisingly short solution from \\cite{kactl} (see the next sections for \\lstinline|dot()| and \\lstinline|cross()|):\n\\begin{lstlisting}\npt linearTransfo(pt p, pt q, pt r, pt fp, pt fq) {\n    pt pq = q-p, num{cross(pq, fq-fp), dot(pq, fq-fp)};\n    return fp + pt{cross(r-p, num), dot(r-p, num)} / sq(pq);\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "faf80e79c937ce371295ff5eea88e2ac9a4f1d7b", "size": 4242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/transfo.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/transfo.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/transfo.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": 50.5, "max_line_length": 412, "alphanum_fraction": 0.7034417727, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632247867715, "lm_q2_score": 0.8244619350028204, "lm_q1q2_score": 0.7847749961657262}}
{"text": "%================================\n\\section{Topological Spaces}\n%================================\n\n\n\n%--------------------------------\n\\begin{definition}\n\t[topology]\n\t\\label{def: topology}\n\tLet $X$ be a set, and let a family $\\mathcal T \\subseteq \\mathcal P(X)$. $\\mathcal T$ is called a \\textit{topology} on $X$ iff it satisfies the \\textit{open set axioms}:\n\t\\begin{enumerate}[\\bf O1.]\n\t\t\\item $X \\in \\mathcal T$;\n\t\t\\item $\\mathcal T$ is closed under arbitrary union;\n\t\t\\item $\\mathcal T$ is closed under finite intersection.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t$\\emptyset \\in \\mathcal T$.\n\t\n\t\\begin{proof}\n\t\tBy O2 in Definition \\ref{def: topology}, for all $\\mathcal A \\subseteq \\mathcal T$, $\\bigcup \\mathcal A \\in \\mathcal T$. Clearly, $\\emptyset \\in \\mathcal T$, then we have\n\t\t$$\n\t\t\\emptyset = \\bigcup \\emptyset \\in \\mathcal T.\n\t\t$$\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[topological spaces]\n\t\\label{def: topological spaces}\n\tWith the condition in Definition \\ref{def: topology}, the pair $(X, \\mathcal T)$ is called a \\textit{topological space}. All subsets of $X$ in $\\mathcal T$ are said to be \\textit{open} in $(X, \\mathcal T)$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[closed sets]\n\t\\label{def: closed sets}\n\tLet $(X, \\mathcal T)$ be a topological space. A subset $V$ of $X$ is said to be \\textit{closed} iff there is an open set $U$ in $X$ such that\n\t$$\n\tV = X \\setminus V.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{corollary}\n\t\\label{prop: dark side of topology}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $\\mathcal C$ be the family of all closed sets in $X$. Then\n\t\\begin{enumerate}[(i)]\n\t\t\\item\n\t\t$\\emptyset, X \\in \\mathcal C$;\n\t\t\n\t\t\\item\n\t\t$\\mathcal C$ is closed under arbitrary intersection;\n\t\t\n\t\t\\item\n\t\t$\\mathcal C$ is closed under finite union.\n\t\\end{enumerate}\n\t\n\t\\begin{proof}\n\t\t\\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\t$X \\in \\mathcal T$ implies $X \\setminus X = \\emptyset \\in \\mathcal C$; and $\\emptyset \\in \\mathcal T$ implies $X \\setminus \\emptyset = X \\in \\mathcal C$;\n\t\t\t\n\t\t\t\\item\n\t\t\tAs $\\mathcal T$ is closed under arbitrary union, then by Definition \\ref{def: closed sets} and De Morgan's Law, $\\mathcal C$ is closed under arbitrary intersection.\n\t\t\t\n\t\t\t\\item\n\t\t\tAs $\\mathcal T$ is closed under finite intersection, then by Definition \\ref{def: closed sets} and De Morgan's Law, $\\mathcal C$ is closed under finite union.\n\t\t\\end{enumerate}\n\t\\end{proof}\n\\end{corollary}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[finer and coarser topology]\n\t\\label{def: finer and coarser topology} Let $X$ be any set, and let $\\mathcal T, \\mathcal T'$ be topologies on $X$. $\\mathcal T$ is said to be \\textit{finer} than $\\mathcal T'$ iff $\\mathcal T \\supseteq \\mathcal T'$; respectively, $\\mathcal T$ is said to be \\textit{coarser} than $\\mathcal T'$ iff $\\mathcal T \\subseteq \\mathcal T'$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[neighbourhood]\n\t\\label{def: neighbourhood}\n\tGiven $(X, \\mathcal T)$ as a topological space and a point $x \\in X$, a subset $N \\subseteq X$ is called a \\textit{neighbourhood} iff it contains an open set $U$ containing $x$.\n\t% todo: find a place for neighbourhood.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\t\\label{prop: alt-def of open sets by neighbourhoods}\n\tGiven $(X, \\mathcal T)$ as a topological space and $U \\subseteq X$, $U$ is open iff for all $x \\in U$, there is a neighbourhood $N$ of $x$ such that $N \\subseteq U$.\n\t\n\t\\begin{proof}\n\t\tIf $U$ is open, then $U$ itself is a neighbourhood of $x$ contained in $U$.\n\t\t\n\t\tConversely, if for all $x \\in U$, there is a neighbourhood $N_x$ of $x$ contained in $U$, then there is a open neighbourhood $U_x \\ni x$ contained in $N_x$. Then we have\n\t\t$$\n\t\tU \\supseteq \\bigcup_{x \\in U} U_x.\n\t\t$$\n\t\tSuppose $U$ is not open, then $U$ is a proper superset in the relation above. Then there exists $y \\in U$ which is not in any $U_x$. This implies that such a $y$ does not have any neighbourhood $N_y$ in $U$, for such an $N_y$ must contains an open $U_y \\ni y$. For if it does, then there must be a $U_x$ contains $y$. This is a contradiction. Thus,\n\t\t$$\n\t\tU = \\bigcup_{x \\in U} U_x\n\t\t$$\n\t\tis open.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------", "meta": {"hexsha": "8976a15710f766891a9992eb84495979de216643", "size": 4622, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/topological-spaces.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/topological-spaces.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/topological-spaces.tex", "max_forks_repo_name": "Wenchuan5000/TeX", "max_forks_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.976, "max_line_length": 350, "alphanum_fraction": 0.5893552575, "num_tokens": 1388, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541659378681, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7847035826008586}}
{"text": "\\section{Formulary of Probability}\n\\label{sec:Formulary-Probability}\n\n\n\n\n\\subsection{Foundations}\n\n\\begin{description}\n\t\n\t\\item [Failure Rate]\n\t\t\\begin{equation}\n\t\tr(x) = \\frac{f(x)}{\\overline{F}(x)}\n\t\t\\end{equation}\n\t\n\t\\item [Coefficient of Variation]\n\t\t\\begin{equation}\n\t\tC_{X}^{2} = \\frac{\\variance{X}}{\\expected{X^{2}}}\n\t\t\\end{equation}\n\t\n\\end{description}\n\n\n\n\n\\subsection{Exponential Distribution}\n\n\\begin{description}\n\t\n\t\\item [Exponential p.d.f]\t\n\t\t\\begin{equation}\n\t\tf(x) = \\left\\{\\begin{matrix}\n\t\t\\lambda e^{-\\lambda x} & x \\geq 0\\\\ \n\t\t0 & x \\leq 0\n\t\t\\end{matrix}\\right.\n\t\t\\end{equation}\n\t\n\t\\item [Exponential c.d.f]\t\n\t\t\\begin{equation}\n\t\t\\begin{aligned}\n\t\tF(x) =  \n\t\t\\left\\{\\begin{matrix}\n\t\t1 - e^{-\\lambda x} & x \\geq 0\\\\ \n\t\t0 & x \\leq 0\n\t\t\\end{matrix}\\right.\n\t\t\\end{aligned}\n\t\t\\end{equation}\n\t\n\t\\item [Exponential Mean]\t\n\t\t\\begin{equation}\n\t\t\\expected{X} = \\frac{1}{\\lambda}\n\t\t\\end{equation}\t\n\t\n\t\\item [Exponential Variance]\t\n\t\t\\begin{equation}\n\t\t\\variance{X} = \\frac{1}{\\lambda^{2}}\n\t\t\\end{equation}\t\n\t\n\t\\item [Exponential Precedency]\t\n\t\t\\begin{equation}\n\t\t\\probability{X_{1} < X_{2}} = \\frac{\\lambda_{1}}{\\lambda_{1} + \\lambda_{2}}\n\t\t\\end{equation}\n\t\n\t\\item [Exponential Minimum]\t\n\t\t\\begin{equation}\n\t\t\\min(X_{1},X_{2}) \\sim Exp(\\lambda_{1} + \\lambda_{2})\n\t\t\\end{equation}\n\n\\end{description}\n\n\n\n\n\\subsection{Poisson Distribution}\n\n\\begin{description}\n\t\n\t\\item [Poisson p.m.f]\t\n\t\t\\begin{equation}\n\t\tf(k,t) = \\frac{(\\lambda t)^{k} e^{-\\lambda t}}{k!}\n\t\t\\end{equation}\n\t\n\t\\item [Poisson c.d.f]\t\n\t\t\\begin{equation}\n\t\tF(k,t) = \\sum_{x=0}^{t} f(k,x)\n\t\t\\end{equation}\n\t\n\t\\item [Poisson Mean]\t\n\t\t\\begin{equation}\n\t\t\\expected{N(t)} = \\lambda t\n\t\t\\end{equation}\n\t\n\t\\item [Poisson Variance]\t\n\t\t\\begin{equation}\n\t\t\\variance{N(t)} = \\lambda t\n\t\t\\end{equation}\n\t\n\t\\item [Poisson Inter-arrivals]\t\n\t\t\\begin{equation}\n\t\t\\probability{N(s+t)-N(s) = n} \\sim Poisson(\\lambda t)\n\t\t\\end{equation}\t\n\t\n\t\\item [Poisson Merging]\n\t\tGiven two independent Poisson process with rate $\\lambda_{1}$ and $\\lambda_{2}$, the merged process is a Poisson process with rate $(\\lambda_{1} + \\lambda_{2})$.\n\t\n\t\\item [Poisson Splitting]\n\t\tGiven a Poisson process with rate $\\lambda$, whose events are partitioned in class-A with probability $p$ and class-B with probability $(1-p)$, the class-A process is a Poisson process with rate $p \\lambda$ and the class-B process is a Poisson process with rate $(1-p) \\lambda$, and these processes are independent.\n\t\n\t\\item [Poisson Uniformity]\n\t\tIf $k$ events of a Poisson process occur by time $t$, then the $k$ events are distributed independently and uniformly in $[0,t]$. \n\t\t\n\\end{description}\n\n\n\n\n\\subsection{Pareto Distribution}\n\n\\begin{description}\n\t\n\t\\item [Pareto distribution]\n\t\t$X$ is Pareto distributed with order $\\alpha$ (that is, $X \\sim Pareto(\\alpha)$) if\n\t\t\\begin{equation}\n\t\t\\overline{F}(x) = \\probability{X > x} = x^{-\\alpha} \\quad \\forall x \\geq 1, 0 < \\alpha < 2\n\t\t\\end{equation}\n\t\n\t\\item [Bounded Pareto distribution]\n\t\t$X$ is Bounded Pareto distributed with order $\\alpha$ and bounds $k,p$ (that is, $X \\sim BP(k,p,\\alpha)$) if\n\t\t\\begin{equation}\n\t\tf(x) = \\probability{X \\leq x} = \\alpha x^{-\\alpha -1} \\cdot \\frac{k^{\\alpha}}{1-\\Big(\\frac{k}{p})^{\\alpha}} \\quad \\forall k \\leq x \\geq p, 0 < \\alpha < 2\n\t\t\\end{equation}\n\t\n\\end{description}", "meta": {"hexsha": "b9c8b7add734a754219f6b17039add6d11a25e95", "size": 3276, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/formulary-probability.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/formulary-probability.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/formulary-probability.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": 24.6315789474, "max_line_length": 317, "alphanum_fraction": 0.6483516484, "num_tokens": 1226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7847035687627604}}
{"text": "\\lab{Introduction to SymPy}{Introduction to SymPy}\n\n\\objective{Most implementations of numerical algorithms focus on crunching, relating, or visualizing numerical data.\nHowever, it is sometimes convenient or necessary to represent parts of an algorithm symbolically.\nThe SymPy module provides a way to do symbolic mathematics in Python, including algebra, differentiation, integration, and more.\nIn this lab we introduce SymPy syntax and emphasize how to use symbolic algebra for numerical computing.}\n\n\\section*{Symbolic Variables and Expressions} % ===============================\n\nMost variables in Python refer to a number, string, or data structure.\nDoing computations on such variables results in more numbers, strings, or data structures.\nA \\emph{symbolic variable} is a variable that represents a mathematical symbol, such as $x$ or $\\theta$, not a number or another kind of data.\nOperating on symbolic variables results in an \\emph{expression}, representative of an actual mathematical expression.\nFor example, if a symbolic variable \\li{Y} refers to a mathematical variable $y$, the multiplication \\li{3*Y} refers to the expression $3y$.\nThis is all done without assigning an actual numerical value to \\li{Y}.\n\nSymPy \\cite{meurer2017sympy} is Python's library for doing symbolic algebra and calculus.\nIt is typically imported with \\li{import sympy as sy}, and symbolic variables are usually defined using \\li{sy.symbols()}.\n% Expressions can also be derived from a string using \\li{sy.sympify()} or the shortcut \\li{sy.S()}.\n% \\li{sy.Symbol()} can also be used to define a single variable, but will not be used in this lab for consistency.\n\n\\begin{lstlisting}\n>>> import sympy as sy\n>>> x0 = sy.symbols('x0')                   # Define a single variable.\n\n# Define multiple symbolic variables simultaneously.\n>>> x2, x3 = sy.symbols('x2, x3')           # Separate symbols by commas,\n>>> m, a = sy.symbols('mass acceleration')  # by spaces,\n>>> x, y, z = sy.symbols('x:z')             # or by colons.\n>>> x4, x5, x6 = sy.symbols('x4:7')\n\n# Combine symbolic variables to form expressions.\n>>> expr = x**2 + x*y + 3*x*y + 4*y**3\n>>> force = m * a\n>>> print(expr, force, sep='\\n')\nx**2 + 4*x*y + 4*y**3\nacceleration*mass\n\\end{lstlisting}\n%\n% # Create an expression from a string.\n% >>> sy.S(\"x0**2+x1**3+x2\")\n% x0**2 + x1**3 + x2\n\n% Pre-defined variables, including greek letters, can be imported from \\li{sympy.abc}.\n% To see a list of these variables, run \\li{dir(sy.abc)} after \\li{sy.abc} has been imported.\n\nSymPy has its own version for each of the standard mathematical functions like $\\sin(x)$, $\\log(x)$, and $\\sqrt{x}$, and includes predefined variables for special numbers such as $\\pi$.\nThe naming conventions for most functions match NumPy, but some of the built-in constants are named slightly differently.\n\\[\n\\begin{array}{cl}\n\\text{Functions}\n&\n\\begin{tabular}{c|c|c|c|c|c}\n    $\\sin(x)$ & $\\arcsin(x)$ & $\\sinh(x)$ & $e^x$ & $\\log(x)$ & $\\sqrt{x}$\n    \\\\ \\hline\n    \\li{sy.sin()} & \\li{sy.asin()} & \\li{sy.sinh()} & \\li{sy.exp()} & \\li{sy.log()} & \\li{sy.sqrt()}\n\\end{tabular}\n\\\\ \\\\\n\\text{Constants}\n&\n\\begin{tabular}{c|c|c|c}\n    $\\pi$ & $e$ & $i = \\sqrt{-1}$ & $\\infty$\n    \\\\ \\hline\n    \\li{sy.pi} & \\li{sy.E} & \\li{sy.I} & \\li{sy.oo}\n\\end{tabular}\n\\end{array}\n\\]\nOther trigonometric functions like $\\cos(x)$ follow the same naming conventions.\nFor a complete list of SymPy functions, see \\url{http://docs.sympy.org/latest/modules/functions/index.html}.\n\n\\begin{warn}\nAlways use SymPy functions and constants when creating expressions instead of using NumPy's functions and constants.\nLater we will show how to make NumPy and SymPy cooperate.\n\\begin{lstlisting}\n>>> import numpy as np\n\n>>> x = sy.symbols('x')\n>>> np.exp(x)                       # Try to use NumPy to represent e**x.\n<<Traceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\nAttributeError: 'Symbol' object has no attribute 'exp'>>\n\n>>> sy.exp(x)                       # Use SymPy's version instead.\n<<exp(x)>>\n\\end{lstlisting}\n\\end{warn}\n\n\\begin{info}\nSymPy defines its own numeric types for integers, floats, and rational numbers.\nFor example, the \\li{sy.Rational} class is similar to the standard library's \\li{fractions.Fraction} class, and should be used to represent fractions in SymPy expressions.\n\n\\begin{lstlisting}\n>>> x = sy.symbols('x')\n>>> (2/3) * sy.sin(x)               # 2/3 returns a float, not a rational.\n0.666666666666667*sin(x)\n\n>>> sy.Rational(2, 3) * sy.sin(x)   # Keep 2/3 symbolic.\n2*sin(x)/3\n\\end{lstlisting}\nAlways be aware of which numeric types are being used in an expression.\nUsing rationals and integers where possible is important for simplifying expressions.\n% To keep $\\frac{2}{3}$ symbolic, use \\li{sy.Rational(2,3)*sy.sin(x)} or \\li{sy.Integer(2)/3*sy.sin(x)}.\n\\end{info}\n\n\\begin{problem} % Write a simple expression.\nWrite a function that returns the expression $\\frac{2}{5} e^{x^2-y}\\cosh(x+y) + \\frac{3}{7}\\log(xy+1)$ symbolically.\nMake sure that the fractions remain symbolic.\n\\end{problem}\n\n\\subsection*{Sums and Products} % ---------------------------------------------\n\nExpressions that can be written as a sum or a product can be constructed with \\li{sy.summation()} or \\li{sy.product()}, respectively.\nEach of these functions accepts an expression that represents one term of the sum or product, then a tuple indicating the indexing variable and which values it should take on.\nFor example, the following code constructs the sum and product given below.\n\\[\n\\sum_{i=1}^{4} x + iy\n\\qquad\\qquad\n\\prod_{i=0}^{5} x + iy\n\\]\n\n\\begin{lstlisting}\n>>> x, y, i = sy.symbols('x y i')\n\n>>> sy.summation(x + i*y, (i, 1, 4))    # Sum over i=1,2,3,4.\n<<4*x + 10*y>>\n\n>>> sy.product(x + i*y, (i, 0, 5))      # Multiply over i=0,1,2,3,4,5.\n<<x*(x + y)*(x + 2*y)*(x + 3*y)*(x + 4*y)*(x + 5*y)>>\n\\end{lstlisting}\n\n\\subsection*{Simplifying Expressions} % ---------------------------------------\n\nThe expressions for the summation and product in the previous example are automatically simplified.\nMore complicated expressions can be simplified with one or more of the following functions.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\nFunction & Description \\\\ \\hline\n% \\li{sy.apart()} & Partial fraction decomposition. \\\\\n\\li{sy.cancel()} & Cancel common factors in the numerator and denominator. \\\\\n% \\li{sy.collect()} & Factor out all rational powers of a specified variable. \\\\\n\\li{sy.expand()} & Expand a factored expression. \\\\\n\\li{sy.factor()} & Factor an expanded expression. \\\\\n% \\li{powsimp()} & Combine powers with similar bases and exponents. \\\\\n\\li{sy.radsimp()} & Rationalize the denominator of an expression. \\\\\n% \\li{sy.ratsimp()} & Return the simplest form of the addition of two rational expressions. \\\\\n% \\li{seperate()} & Rewrite a power of products to a product of powers. \\\\\n\\li{sy.simplify()} & Simplify an expression.\\\\\n% \\li{together()} & Combine rational functions.\\\\\n\\li{sy.trigsimp()} & Simplify only the trigonometric parts of the expression. \\\\\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n>>> x = sy.symbols('x')\n>>> expr = (x**2 + 2*x + 1) / ((x+1)*((sy.sin(x)/sy.cos(x))**2 + 1))\n>>> print(expr)\n(x**2 + 2*x + 1)/((x + 1)*(sin(x)**2/cos(x)**2 + 1))\n\n>>> sy.simplify(expr)\n(x + 1)*cos(x)**2\n\\end{lstlisting}\n\nThe generic \\li{sy.simplify()} tries to simplify an expression in any possible way.\nThis is often computationally expensive; using more specific simplifiers when possible reduces the cost.\n\n\\begin{lstlisting}\n>>> expr = sy.product(x + i*y, (i, 0, 3))\n>>> print(expr)\nx*(x + y)*(x + 2*y)*(x + 3*y)\n\n>>> expr_long = sy.expand(expr)         # Expand the product terms.\n>>> print(expr_long)\nx**4 + 6*x**3*y + 11*x**2*y**2 + 6*x*y**3\n\n>>> expr_long /= (x + 3*y)\n>>> print(expr_long)\n(x**4 + 6*x**3*y + 11*x**2*y**2 + 6*x*y**3)/(x + 3*y)\n\n>>> expr_short = sy.cancel(expr_long)   # Cancel out the denominator.\nx**3 + 3*x**2*y + 2*x*y**2\n\n>>> sy.factor(expr_short)               # Factor the result.\nx*(x + y)*(x + 2*y)\n\n# Simplify the trigonometric parts of an expression.\n>>> sy.trigsimp(2*sy.sin(x)*sy.cos(x))\n<<sin(2*x)>>\n\\end{lstlisting}\n\nSee \\url{http://docs.sympy.org/latest/tutorial/simplification.html} for more examples.\n\n\\begin{warn}\n% Keep the following in mind when simplifying expressions.\n\\begin{enumerate}\n\\item Simplifications return new expressions; they do not modify existing expressions in place.\n\n\\item The \\li{==} operator compares two expressions for exact structural equality, not algebraic equivalence.\nSimplify or expand expressions before comparing them with \\li{==}.\n\n\\item Expressions containing floats may not simplify as expected.\nAlways use integers and SymPy rationals in expressions when appropriate.\n\\end{enumerate}\n\n\\begin{lstlisting}\n>>> expr = 2*sy.sin(x)*sy.cos(x)\n>>> sy.trigsimp(expr)\nsin(2*x)\n>> print(expr)\n2*sin(x)*cos(x)                 # The original expression is unchanged.\n\n>>> 2*sy.sin(x)*sy.cos(x) == sy.sin(2*x)\n<<False>>                           # The two expression structures differ.\n\n>>> sy.factor(x**2.0 - 1)\nx**2.0 - 1                      # Factorization fails due to the 2.0.\n\\end{lstlisting}\n\\end{warn}\n\n\\begin{problem}\nWrite a function that computes and simplifies the following expression.\n\\[\\prod_{i=1}^{5} \\sum_{j=i}^{5}j(\\sin(x)+\\cos(x))\\]\n\\end{problem}\n\n\\section*{Evaluating Expressions} % ===========================================\n\nEvery SymPy expression has a \\li{subs()} method that substitutes one variable for another.\nThe result is usually still a symbolic expression, even if a numerical value is used in the substitution.\nThe \\li{evalf()} method actually evaluates the expression numerically after all symbolic variables have been assigned a value.\nBoth of these methods can accept a dictionary to reassign multiple symbols simultaneously.\n\n\\begin{lstlisting}\n>>> x,y = sy.symbols('x y')\n>>> expr = sy.expand((x + y)**3)\n>>> print(expr)\nx**3 + 3*x**2*y + 3*x*y**2 + y**3\n\n# Replace the symbolic variable y with the expression 2x.\n>>> expr.subs(y, 2*x)\n27*x**3\n\n# Replace x with pi and y with 1.\n>>> new_expr = expr.subs({x:sy.pi, y:1})\n>>> print(new_expr)\n1 + 3*pi + 3*pi**2 + pi**3\n>>> new_expr.evalf()                # Numerically evaluate the expression.\n71.0398678443373\n\n# Evaluate the expression by providing values for each variable.\n>>> expr.evalf(subs={x:1, y:2})\n27.0000000000000\n\\end{lstlisting}\n\nThese operations are good for evaluating an expression at a single point, but it is typically more useful to turn the expression into a reusable numerical function.\nTo this end, \\li{sy.lambdify()} takes in a symbolic variable (or list of variables) and an expression, then returns a callable function that corresponds to the expression.\n\n\\begin{lstlisting}\n# Turn the expression sin(x)^2 into a function with x as the variable.\n>>> f = sy.lambdify(x, sy.sin(x)**2)\n>>> print(f(0), f(np.pi/2), f(np.pi), sep='  ')\n0.0  1.0  1.4997597826618576e-32\n\n# Lambdify a function of several variables.\n>>> f = sy.lambdify((x,y), sy.sin(x)**2 + sy.cos(y)**2)\n>>> print(f(0,1), f(1,0), f(np.pi, np.pi), sep='  ')\n0.2919265817264289  1.708073418273571  1.0\n\\end{lstlisting}\n\nBy default, \\li{sy.lambdify()} uses the \\li{math} module to convert an expression to a function.\nFor example, \\li{sy.sin()} is converted to \\li{math.sin()}.\nBy providing \\li{\"numpy\"} as an additional argument, \\li{sy.lambdify()} replaces symbolic functions with their NumPy equivalents instead, so \\li{sy.sin()} is converted to \\li{np.sin()}.\nThis allows the resulting function to act element-wise on NumPy arrays, not just on single data points.\n\n\\begin{lstlisting}\n>>> f = sy.lambdify(x, 2*sy.sin(2*x), \"numpy\")\n>>> f(np.linspace(0, 2*np.pi, 9))   # Evaluate f() at many points.\narray([  0.00000000e+00,   2.00000000e+00,   2.44929360e-16,\n        -2.00000000e+00,  -4.89858720e-16,   2.00000000e+00,\n         7.34788079e-16,  -2.00000000e+00,  -9.79717439e-16])\n\\end{lstlisting}\n\n\\begin{info}\nIt is almost always computationally cheaper to lambdify a function than to use substitutions.\nAccording to the SymPy documentation, using \\li{sy.lambdify()} to do numerical evaluations ``takes on the order of hundreds of nanoseconds, roughly two orders of magnitude faster than the \\li{subs()} method.''\n\n\\begin{lstlisting}\n<g<In [1]:>g> import sympy as sy\n<g<In [2]:>g> import numpy as np\n\n# Define a symbol, an expression, and points to plug into the expression.\n<g<In [3]:>g> x = sy.symbols('x')\n<g<In [4]:>g> expr = sy.tanh(x)\n<g<In [5]:>g> points = np.random.random(10000)\n\n# Time using evalf() on each of the random points.\n<g<In [6]:>g> <p<%time>p> _ = [expr.subs(x, pt).evalf() for pt in points]\n<<CPU times: user 5.29 s, sys: 40.3 ms, total: 5.33 s\nWall time: 5.36 s>>\n\n# Lambdify the expression and time using the resulting function.\n<g<In [7]:>g> f = sy.lambdify(x, expr)\n<g<In [8]:>g> <p<%time>p> _ = [f(pt) for pt in points]\n<<CPU times: user 5.39 ms, sys: 648 micros, total: 6.04 ms\nWall time: 7.75 ms>>      # About 1000 times faster than evalf().\n\n# Lambdify the expression with NumPy and repeat the experiment.\n<g<In [9]:>g> f = sy.lambdify(x, expr, \"numpy\")\n<g<In [10]:>g> <p<%time>p> _ = f(points)\n<<CPU times: user 381 micros, sys: 63 micros, total: 444 micros\nWall time: 282 micros>>   # About 10 times faster than regular lambdify.\n\\end{lstlisting}\n\\end{info}\n\n\\begin{problem}\nThe Maclaurin series up to order $N$ for $e^x$ is defined as\n\\begin{equation}\ne^x \\approx \\sum_{n=0}^N \\frac{x^n}{n!}.\n\\label{eq:sympy-maclaurin-exponential}\n\\end{equation}\nWrite a function that accepts an integer $N$.\nDefine an expression for (\\ref{eq:sympy-maclaurin-exponential}), then substitute in $-y^2$ for $x$ to get a truncated Maclaurin series of $e^{-y^2}$.\nLambdify the resulting expression and plot the series on the domain $y\\in[-2,2]$.\nPlot $e^{-y^2}$ over the same domain for comparison.\n\\\\(Hint: use \\li{sy.factorial()} to compute the factorial.)\n\nCall your function with increasing values of $N$ to check that the series converges correctly.\n\\end{problem}\n\n\\section*{Solving Symbolic Equations} % =======================================\n\nA SymPy expression by itself is not an equation.\nHowever, \\li{sy.solve()} equates an expression with zero and solves for a specified variable.\nIn this way, SymPy can be used to solve equations.\n\n\\begin{lstlisting}\n>>> x,y = sy.symbols('x y')\n\n# Solve x^2 - 2x + 1 = 0 for x.\n>>> sy.solve(x**2 - 2*x + 1, x)\n[1]                                 # The result is a list of solutions.\n\n# Solve x^2 - 1 = 0 for x.\n>>> sy.solve(x**2 - 1, x)\n[-1, 1]                             # This equation has two solutions.\n\n# Solutions can also be expressions involving other variables.\n>>> sy.solve(x/(y-x) + (x-y)/y, x)\n[y*(-sqrt(5) + 3)/2, y*(sqrt(5) + 3)/2]\n\\end{lstlisting}\n\n\\begin{problem}\nThe following equation represents a rose curve in cartesian coordinates:\n\\begin{equation}\n0 = 1 - \\frac{(x^2 + y^2)^{7/2} + 18x^5 y - 60x^3 y^3 + 18xy^5}{(x^2 + y^2)^3}.\n\\label{eq:prob-polar-parametric}\n\\end{equation}\nThe curve is not the image of a single function (such a function would fail the vertical line test), so the best way to plot it is to convert (\\ref{eq:prob-polar-parametric}) to a pair of parametric equations that depend on the angle parameter $\\theta$.\n\nConstruct an expression for the nonzero side of (\\ref{eq:prob-polar-parametric}) and convert it to polar coordinates with the substitutions $x = r\\cos(\\theta)$ and $y = r\\sin(\\theta)$.\nSimplify the result, then solve it for $r$.\nThere are two solutions due to the presence of an $r^2$ term; pick one and lambdify it to get a function $r(\\theta)$.\nUse this function to plot $x(\\theta) = r(\\theta)\\cos(\\theta)$ against $y(\\theta) = r(\\theta)\\sin(\\theta)$ for $\\theta \\in [0,2\\pi]$.\n\\\\(Hint: use \\li{sy.Rational()} for the fractional exponent.)\n\\end{problem}\n\n\\subsection*{Linear Algebra} % ------------------------------------------------\n\nSympy can also solve systems of equations.\nA system of linear equations $A\\x = \\b$ is solved in a slightly different way than in NumPy and SciPy: instead of defining the matrix $A$ and the vector $\\b$ separately, define the augmented matrix $M = [A\\mid\\b]$ and call \\li{sy.solve_linear_system()} on $M$.\n\nSymPy matrices are defined with \\li{sy.Matrix()}, with the same syntax as $2$-dimensional NumPy arrays.\nFor example, the following code solves the system given below.\n\\[\n\\begin{array}{rrrrrrr}\n x & + &   y & + &  z & = & 5 \\\\\n2x & + &  4y & + & 3z & = & 2 \\\\\n5x & + & 10y & + & 2z & = & 4\n\\end{array}\n\\]\n\\begin{lstlisting}\n>>> x, y, z = sy.symbols('x y z')\n\n# Define the augmented matrix M = [A|b].\n>>> M = sy.Matrix([ [1,  1, 1, 5],\n                    [2,  4, 3, 2],\n                    [5, 10, 2, 4] ])\n\n# Solve the system, providing symbolic variables to solve for.\n>>> sy.solve_linear_system(M, x, y, z)\n{x: 98/11, y: -45/11, z: 2/11}\n\\end{lstlisting}\n\nSymPy matrices support the standard matrix operations of addition \\li{+}, subtraction \\li{-}, and multiplication \\li{@}.\nAdditionally, SymPy matrices are equipped with many useful methods, some of which are listed below.\nSee \\url{http://docs.sympy.org/latest/modules/matrices/matrices.html} for more methods and examples.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\nMethod & Returns \\\\ \\hline\n% \\li{applyfunc()} & Apply a function to every element of the matrix. \\\\\n% \\li{condition_number()} & The condition number. \\\\\n\\li{det()} & The determinant. \\\\\n% \\li{diagonalize()} & Diagonalize a matrix. \\\\\n\\li{eigenvals()} & The eigenvalues and their multiplicities. \\\\\n\\li{eigenvects()} & The eigenvectors and their corresponding eigenvalues. \\\\\n\\li{inv()} & The matrix inverse. \\\\\n\\li{is_nilpotent()} & \\li{True} if the matrix is nilpotent. \\\\\n% \\li{multiply_elementwise()} & Multiply matrices elementwise. \\\\\n\\li{norm()} & The Frobenius, $\\infty$, $1$, or $2$ norm. \\\\\n\\li{nullspace()} & The nullspace as a list of vectors. \\\\\n\\li{rref()} & The reduced row-echelon form. \\\\\n\\li{singular_values()} & The singular values. \\\\\n\\end{tabular}\n\\end{table}\n\n\\begin{warn}\nThe \\li{*} operator performs matrix multiplication on SymPy matrices.\nTo perform element-wise multiplication, use the \\li{multiply_elementwise()} method instead.\n\\end{warn}\n\n\\begin{problem}\nFind the eigenvalues of the following matrix by solving for $\\lambda$ in the characteristic equation $\\det(A - \\lambda I) = 0$.\n\\begin{align*}\nA =\n\\left[\\begin{array}{cccc}\nx-y & x   & 0   \\\\\nx   & x-y & x   \\\\\n0   & x   & x-y \\\\\n\\end{array}\\right]\n\\end{align*}\nAlso compute the eigenvectors by solving the linear system $A - \\lambda I = \\0$ for each eigenvalue $\\lambda$.\nReturn a dictionary mapping the eigenvalues to their eigenvectors.\n\\\\(Hint: the \\li{nullspace()} method may be useful.)\n\nCheck that $A\\v = \\lambda\\v$ for each eigenvalue-eigenvector pair $(\\lambda, \\v)$.\nCompare your results to the \\li{eigenvals()} and \\li{eigenvects()} methods for SymPy matrices.\n\\end{problem}\n\n\\section*{Calculus} % =========================================================\n\nSymPy is also equipped to perform standard calculus operations, including derivatives, integrals, and taking limits.\nLike other elements of SymPy, calculus operations can be temporally expensive, but they give exact solutions whenever solutions exist.\n\n\\subsection*{Differentiation} % -----------------------------------------------\n\nThe command \\li{sy.Derivative()} creates a closed form, unevaluated derivative of an expression.\nThis is like putting $\\frac{d}{dx}$ in front of an expression without actually calculating the derivative symbolically.\nThe resulting expression has a \\li{doit()} method that can be used to evaluate the actual derivative.\nEquivalently, \\li{sy.diff()} immediately takes the derivative of an expression.\n\nBoth \\li{sy.Derivative()} and \\li{sy.diff()} accept a single expression, then the variable or variables that the derivative is being taken with respect to.\n\n\\begin{lstlisting}\n>>> x, y = sy.symbols('x y')\n>>> f = sy.sin(y)*sy.cos(x)**2\n\n# Make an expression for the derivative of f with respect to x.\n>>> df = sy.Derivative(f, x)\n>>> print(df)\nDerivative(sin(y)*cos(x)**2, x)\n\n>>> df.doit()                       # Perform the actual differentiation.\n-2*sin(x)*sin(y)*cos(x)\n\n# Alternatively, calculate the derivative of f in a single step.\n>>> sy.diff(f, x)\n-2*sin(x)*sin(y)*cos(x)\n\n# Calculate the derivative with respect to x, then y, then x again.\n>>> sy.diff(f, x, y, x)\n2*(sin(x)**2 - cos(x)**2)*cos(y)    # Note this expression could be simplified.\n\\end{lstlisting}\n\n\\begin{problem} % Single-variable optimization with differentiation.\nLet $f:\\mathbb{R}\\rightarrow\\mathbb{R}$ be a smooth function.\nA \\emph{critical point} of $f$ is a number $x_0\\in\\mathbb{R}$ satisfying $f'(x_0) = 0$.\nThe second derivative test states that a critical point $x_0$ is a local minimum of $f$ if $f''(x_0) > 0$, or a local maximum of $f$ if $f''(x_0) < 0$ (if $f''(x_0) = 0$, the test is inconclusive).\n\nNow consider the polynomial\n\\[\np(x) = 2x^6 - 51x^4 + 48x^3 + 312x^2 - 576x - 100.\n\\]\nUse SymPy to find all critical points of $p$ and classify each as a local minimum or a local maximum.\nPlot $p(x)$ over $x\\in[-5,5]$ and mark each of the minima in one color and the maxima in another color.\nReturn the collections of the x-values corresponding to the local minima and local maxima as sets.\n\\end{problem}\n\nThe \\emph{Jacobian matrix} of a multivariable function $f:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m$ at a point $\\x_0 \\in \\mathbb{R}^n$ is the $m \\times n$ matrix $J$ whose entries are given by\n\\begin{equation*}\nJ_{ij} = \\frac{\\partial f_i}{\\partial x_j}(\\x_0).\n\\end{equation*}\nFor example, the Jacobian for a function $f:\\mathbb{R}^3 \\rightarrow \\mathbb{R}^2$ is defined by\n\\[\nJ = \\left[\\begin{array}{c|c|c}\n\\arrayrulecolor{gray}\n\\frac{\\partial f}{\\partial x_1}&\\frac{\\partial f}{\\partial x_2}&\\frac{\\partial f}{\\partial x_3}\n\\end{array}\\right]\n=\n\\left[\\begin{array}{ccc}\n\\frac{\\partial f_1}{\\partial x_1}&\\frac{\\partial f_1}{\\partial x_2}&\\frac{\\partial f_1}{\\partial x_3}\n\\\\ \\\\\n\\frac{\\partial f_2}{\\partial x_1}&\\frac{\\partial f_2}{\\partial x_2}&\\frac{\\partial f_2}{\\partial x_3}\n\\end{array}\\right],\n\\qquad\n\\text{where}\n\\qquad\nf(\\x) =\n\\left[\\begin{array}{c}\nf_1(\\x) \\\\ f_2(\\x)\n\\end{array}\\right],\n\\quad\n\\x = \\left[\\begin{array}{c}\nx_1 \\\\ x_2 \\\\ x_3\n\\end{array}\\right].\n\\]\n\nTo calculate the Jacobian matrix of a multivariate function with SymPy, define that function as a symbolic matrix (\\li{sy.Matrix()}) and use its \\li{jacobian()} method.\nThe method requires a list of variables that prescribes the ordering of the differentiation.\n\n\\begin{lstlisting}\n# Create a matrix of symbolic variables.\n>>> r, t = sy.symbols('r theta')\n>>> f = sy.Matrix([r*sy.cos(t), r*sy.sin(t)])\n\n# Find the Jacobian matrix of f with respect to r and theta.\n>>> J = f.jacobian([r,t])\n>>> J\nMatrix([\n[cos(theta), -r*sin(theta)],\n[sin(theta),  r*cos(theta)]])\n\n# Evaluate the Jacobian matrix at the point (1, pi/2).\n>>> J.subs({r:1, t:sy.pi/2})\nMatrix([\n[0, -1],\n[1,  0]])\n\n# Calculate the (symbolic) determinant of the Jacobian matrix.\n>>> sy.simplify(J.det())\nr\n\\end{lstlisting}\n\n\\subsection*{Integration} % ---------------------------------------------------\n\nThe function \\li{sy.Integral()} creates an unevaluated integral expression.\nThis is like putting an integral sign in front of an expression without actually evaluating the integral symbolically or numerically.\nThe resulting expression has a \\li{doit()} method that can be used to evaluate the actual integral.\nEquivalently, \\li{sy.integrate()} immediately integrates an expression.\n\nBoth \\li{sy.Derivative()} and \\li{sy.diff()} accept a single expression, then a tuple or tuples containing the variable of integration and, optionally, the bounds of integration.\n\n\\begin{lstlisting}\n# Calculate the indefinite integral of sec(x).\n>>> sy.integrate(sy.sec(x), x)\n-log(sin(x) - 1)/2 + log(sin(x) + 1)/2\n\n# Integrate cos(x)^2 from 0 to pi/2.\n>>> sy.integrate(sy.cos(x)**2, (x,0,sy.pi/2))\npi/4\n\n# Compute the integral of (y^2)(x^2) dx dy with x from 0 to 2, y from -1 to 1.\n>>> sy.integrate(y**2 * x**2, (x,0,2), (y,-1,1))\n16/9\n\\end{lstlisting}\n\n\\begin{problem}\n% Many unpleasant integrals can be made tractable by a \\emph{change of variables}, such as using polar, cylindrical, or spherical coordinates instead of the usual Cartesian system.\nLet $f:\\mathbb{R}^3\\rightarrow\\mathbb{R}$ be a smooth function.\nThe volume integral of $f$ over the sphere $S$ of radius $r$ can written in spherical coordinates as\n\\begin{align*}\n\\underset{S}{\\iiint} f(x,y,z) dV = \\int_0^\\pi\\int_0^{2\\pi}\\int_0^r f(h_1(\\rho, \\theta, \\phi), h_2(\\rho, \\theta, \\phi), h_3(\\rho, \\theta, \\phi)) |\\det(J)| \\:d\\rho\\:d\\theta\\:d\\phi,\n\\end{align*}\nwhere $J$ is the Jacobian of the function $h:\\mathbb{R}^3\\rightarrow\\mathbb{R}^3$ given by\n\\[\nh(\\rho, \\theta, \\phi) =\n\\left[\\begin{array}{c}\nh_1(\\rho, \\theta, \\phi) \\\\\nh_2(\\rho, \\theta, \\phi) \\\\\nh_3(\\rho, \\theta, \\phi)\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c}\n\\rho\\sin(\\phi)\\cos(\\theta) \\\\\n\\rho\\sin(\\phi)\\sin(\\theta) \\\\\n\\rho\\cos(\\phi)\n\\end{array}\\right].\n\\]\nCalculate the volume integral of $f(x,y,z) = (x^2 + y^2 + z^2)^2$ over the sphere of radius $r$.\nLambdify the resulting expression (with $r$ as the independent variable) and plot the integral value for $r \\in [0, 3]$.\nIn addition, return the value of the integral when $r=2$.\n\\\\ (Hint: simplify the integrand before computing the integral.\nIn this case, $|\\det(J)| = -\\det(J)$.)\n\nTo check your answer, when $r=3$, the value of the integral is $\\frac{8748}{7}\\pi$.\n\\end{problem}\n\n\\begin{warn}\nSymPy isn't perfect.\nIt solves some integrals incorrectly, simplifies some expressions poorly, and is significantly slower than numerical computations.\nHowever, it is generally very useful for simplifying parts of an algorithm, getting exact answers, and handling tedious algebra quickly.\n\\end{warn}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Pretty Printing} % -----------------------------------------------\n\nSymPy expressions, especially complicated ones, can be hard to read.\nCalling \\li{sy.init_printing()} changes the way that certain expressions are displayed to be more readable; in a Jupyter Notebook, the rendering is done with \\LaTeX, as displayed below.\nFurthermore, the function \\li{sy.latex()} converts an expression into actual \\LaTeX \\ code for use in other settings.\n\n\\begin{center}\n\\includegraphics[width=\\textwidth]{figures/pretty_printing.png}\n\\end{center}\n\n% SymPy also has a simplified plotting wrapper around Matplotlib.\n% See \\url{http://docs.sympy.org/latest/modules/plotting.html} for further details.\n% \\begin{lstlisting}\n% # Plot sin(x)e^x where x ranges from -3 to 3.\n% >>> expr = sy.sin(x) * sy.exp(x)\n% >>> sy.plot(expr, (x, -3, 3))\n% \\end{lstlisting}\n%\n% \\begin{figure}[H]\n% \\includegraphics[width=.7\\textwidth]{figures/plotting_wrapper.pdf}\n% \\end{figure}\n\n\\subsection*{Limits} % --------------------------------------------------------\n\nLimits can be expressed, similar to derivatives or integrals, with \\li{sy.Limit()}.\nAlternatively, \\li{sy.limit()} (lowercase) evaluates a limit directly.\n\n\\begin{lstlisting}\n# Define the limit of a^(1/x) as x approaches infinity.\n>>> a, x = sy.symbols('a x')\n>>> sy.Limit(a**(1/x), x, sy.oo)\n<<Limit(a**(1/x), x, oo, dir='-')>>\n\n# Use the doit() method or sy.limit() to evaluate a limit.\n>>> sy.limit((1+x)**(1/x), x, 0)\nE\n\n# Evaluate a limit as x approaches 0 from the negative direction.\n>>> sy.limit(1/x, x, 0, '-')\n-oo\n\\end{lstlisting}\n\nUse limits instead of the \\li{subs()} method when the value to be substituted is $\\infty$ or is a singularity.\n\n\\begin{lstlisting}\n>>> expr = x / 2**x\n>>> expr.subs(x, sy.oo)\nnan\n>>> sy.limit(expr, x, sy.oo)\n0\n\\end{lstlisting}\n\nRefer to \\url{http://docs.sympy.org/latest/tutorial/calculus.html} for SymPy's official documentation on calculus operations.\n\n\\begin{comment} % Too much additional material already.\n\\subsection*{Series Expansions} % ---------------------------------------------\n\nSeries can be depicted using the summation function, but SymPy also has built-in functions to depict them.\nExpressions involving series can be created using \\li{series()} as a function or as a method.\nThe function takes in the expression, variable, the point the series is centered at, and the order of the series.\nThe point the series is centered at defaults to zero and the order to six.\n\n\\begin{lstlisting}\n# Find the terms in the series for cos(x) centered around x = 0 of order 6.\n>>> sy.series(sy.cos(x),x)\n1 - x**2/2 + x**4/24 + O(x**6)\n\n# Center the series at x = pi of order 4.\n>>> sy.series(sy.cos(x),x,sy.pi, 4)\n-1 + (x - pi)**2/2 + O((x - pi)**4, (x,pi))\n\n# Use removeO() to remove the order from the output.\n>>> sy.series(sy.exp(sy.cos(x)),x,1,2).removeO()\n-(x - 1)*exp(cos(1))*sin(1) + exp(cos(1))\n\\end{lstlisting}\n\nPower series can be represented in SymPy with the ``Formal Power Series'' class.\nWhen an \\li{fps} object is created, it returns sequences of coefficients and powers, followed by the independent and then the common terms.\nUse the \\li{truncate()} or \\li{polynomial()} methods to visualize individual terms of the series.\nThese methods input the highest order to be visualized and default to six.\n\n\\begin{lstlisting}\n>>> f = sy.fps(sy.cos(x),x)\n>>> f.truncate()\n1 - x**2/2 + x**4/24 + O(x**6)\n>>> f.polynomial()\nx**4/24 - x**2/2 + 1\n\\end{lstlisting}\n\nFurther series features in SymPy include the computation of residues, laurent series and fourier series.\n\\end{comment}\n\n\\subsection*{Numerical Integration} % -----------------------------------------\n\nMany integrals cannot be solved analytically.\n% Additionally, the definite integral of a function may be undefined.\n% If SymPy is unable to compute an integral, it returns an integral object.\nAs an alternative to the \\li{doit()} method, the \\li{as_sum()} method approximates the integral with a summation.\nThis method accepts the number of terms to use and a string indicating which approximation rule to use (\\li{\"left\"}, \\li{\"right\"}, \\li{\"midpoint\"}, or \\li{\"trapezoid\"}).\n\n\\begin{lstlisting}\n>>> x = sy.symbols('x')\n\n# Try integrating e^(x^2) from 0 to pi.\n>>> I = sy.Integral(sy.exp(x**2), (x,0,sy.pi))\n>>> I.doit()\nsqrt(pi)*erfi(pi)/2                 # The result is not very helpful.\n\n# Instead, approximate the integral with a sum.\n>>> I.as_sum(10, 'left').evalf()\n1162.85031639195\n\\end{lstlisting}\n\n% In addition, SymPy includes several integral transforms, such as the Laplace, Fourier, sine, and cosine transforms.\n% It can also do several types of integrals, such as line integrals.\nSee \\url{http://docs.sympy.org/latest/modules/integrals/integrals.html} for more documentation on integration with SymPy.\n\n\\subsection*{Differential Equations} % ----------------------------------------\n\nSymPy can be used to solve both ordinary and partial differential equations.\nThe documentation for working with PDE functions is at \\url{http://docs.sympy.org/dev/modules/solvers/pde.html}\n\nThe general form of a first-order differential equation is $\\frac{dx}{dt} = f(x(t),t)$.\nTo represent the unknown function $x(t)$, use \\li{sy.Function()}.\nJust as \\li{sy.solve()} is used to solve an expression for a given \\textbf{variable}, \\li{sy.dsolve()} solves an ODE for a particular \\textbf{function}.\nWhen there are multiple solutions, \\li{sy.dsolve()} returns a list; when arbitrary constants are involved they are given as \\li{C1}, \\li{C2}, and so on.\nUse \\li{sy.checkodesol()} to check that a function is a solution to a differential equation.\n\n\\begin{lstlisting}\n>>> t = sy.symbols('t')\n>>> x = sy.Function('x')\n\n# Solve the equation x''(t) - 2x'(t) + x(t) = sin(t).\n>>> ode = x(t).diff(t, t) - 2*x(t).diff(t) + x(t) - sy.sin(t)\n>>> sy.dsolve(ode, x(t))\nEq(x(t), (C1 + C2*t)*exp(t) + cos(t)/2) # C1 and C2 are arbitrary constants.\n\\end{lstlisting}\n\nSince there are many types of ODEs, \\li{sy.dsolve()} may also take a hint indicating what solving strategy to use.\nSee \\li{sy.ode.allhints} for a list of possible hints, or use \\li{sy.classify_ode()} to see the list of hints that may apply to a particular equation.\n\n% Old problem.\n\\begin{comment}\n\\begin{problem}\nReturn the solution to the following differential equation.\n\\begin{equation*}\n y_{xxx} + 3y_{xx} + 3y_{x} + y = x^{5}e^x + x^{4}\\sin\\left(x\\right) + x^{3}\\cos\\left(3x\\right)\n\\end{equation*}\n\nCheck the result $y(x)$ by plugging it back into an expression where one side of the equation is subtracted to another.\nUse the \\li{doit()} and \\li{simplify()} methods to ensure that the new expression simplifies to $0$.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "0784661ac7ec89653f62938fefbcf8310d4a9002", "size": 32527, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PythonEssentials/SympyIntro/SympyIntro.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": "PythonEssentials/SympyIntro/SympyIntro.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": "PythonEssentials/SympyIntro/SympyIntro.tex", "max_forks_repo_name": "chrismmuir/Labs-1", "max_forks_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 76, "max_forks_repo_forks_event_min_datetime": "2015-08-06T02:53:11.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-27T11:08:57.000Z", "avg_line_length": 42.686351706, "max_line_length": 260, "alphanum_fraction": 0.6768223322, "num_tokens": 9573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8740772286044094, "lm_q2_score": 0.8976952907388474, "lm_q1q2_score": 0.7846550118602412}}
{"text": "\\newpage\n%!TEX root = 497Notes-Temple.tex\n\\section{Batch Normalization in DNN and CNN} \nRecall the classical (fully connected)  artificial deep neural network (DNN) $f^L$ in \\eqref{compress-dnn}. We can define\n%\\begin{equation}\\label{key}\n%\\mathcal{F}_\\text{DNN}:= \\{ f(x;\\Theta) = \\text{softmax} \\circ f^J(x;\\Theta) ~|~ x\\in\\mathbb{R}^n,\\Theta \\in \\mathbb{R}^{\\mathcal N} \\}.\n%\\end{equation}\n\\begin{equation}\\label{key}\n\\rm{DNN}_L:= \\{  f^L(x;\\Theta) ~|~ \\Theta \\in \\mathbb{R}^{\\mathcal N} \\}.\n\\end{equation}\nOr, we have a more comprehensive notation for classical DNN models.\n\\begin{equation}\\label{eq:DNNdef_J}\n\\begin{aligned}\n{\\rm{DNN}_L} :=\\{& f:f=\n\\theta^L \\circ \\sigma \\circ \\theta^{L-1} \\cdots \\sigma \\circ \\theta^1(x), \\\\\n&\\theta^\\ell \\in \\mathbb{R}^{n^{\\ell+1} \\times (n^\\ell+1)}, \\quad n^0 = d, \\quad n^{L} = 1, \\quad n^\\ell \\in \\mathbb{N}^+\\}.\n\\end{aligned}\n\\end{equation}\nGenerally speaking, a deep learning problem consists of the next few components:\n\\begin{equation}\\label{DL-process}\n\\text{Data}  \\rightarrow \\text{Model} \\rightarrow \\text{Training} \\rightarrow \\text{Testing}.\n\\end{equation}\nWe will try to give a different explanation for batch normalization based on the above outline.\n\n\n\\subsection{Ideas Behind the BN for DNN: Internal \\mbox{Covariate} Shift in Training}\nThe { Internal Covariate Shift} is defined in \\cite{ioffe2015batch} as\nthe change in the distribution of network activations \ndue to the change in network parameters during training.  \n\nFor example, considering the training data with \n$X=\\{(x^i,y^i)~|~i=1,..,N\\}\\subset \\mathcal{X} : =\\{(x,y)~|~x,\\in\\mathbb{R}^n, y \\in \\mathbb{R}^c\\}$,\nthen output of $\\nu$-th layer (the input of activation function in $\\nu+1$-the layer) $\\{f^\\nu ({x^i}) \\}_{i=1}^N$\nwill satisfy different discrete distributions if you have different parameters $\\Theta$ which  \nalways happened during training process. \n\nMore intuitively, fixed distribution of inputs to a sub-network would have positive\nconsequences for the layers {\\em outside} the sub-network, as\nwell. Consider a layer with a sigmoid activation function $f =\n\\sigma(W x+b)$ where $x$ is the layer input, the weight matrix $W$ and\nbias vector $b$ are the layer parameters to be learned, and $\\sigma(x) =\n\\frac{1}{1+e^{-x}}$.  It is easy to see\n$$\n\\sigma'(x) \\to 0 \\quad \\text{if} \\quad |x| \\to \\infty.\n$$\nThis means that for all dimensions of $y = Wx+b$ except those with\nsmall absolute values, the gradient flowing down to $x$ will vanish\nand the model will train slowly. However, since $y$ is affected by\n$W, b$ and the parameters of all the layers below, changes to those\nparameters during training will likely move many dimensions of $y$\ninto the saturated regime of the nonlinearity and slow down the\nconvergence. This effect is amplified as the network depth\nincreases. In practice, the saturation problem and the resulting\nvanishing gradients are usually addressed by using ${\\rm ReLU}(x)=\\max(x,0)$, careful initialization and small learning rates. \nHowever, if we could ensure that the distribution of nonlinearity inputs\nremains more stable as the network trains, then the optimizer would be\nless likely to get stuck in the saturated regime, and the training\nwould accelerate.\n\nIn summary, the gradient vanishes in the following two situations:\n\\begin{itemize}\n\t\\item Saturated problem:\n\t$$\n\t\\sigma'(x) \\to 0 \\quad \\text{for $x$ located in some saturated domain}.\n\t$$\n\t\\item Instability from multiplication:\n\t$$\n\t\\nabla_{W^1}  \\ell(f^L(x^i;\\Theta), y^i) \\approx \\Pi_{\\ell=1}^L W^{\\ell} {\\rm Diag}(\\sigma'(f^{\\ell-1})) \\to 0~ , \\quad \\text{ if $L$ is big}.\n\t$$\n\\end{itemize}\n\n\n\nUnder this principle,  \nit has been long known \\cite{lecun1998neural, wiesler2011convergence}\nthat the network training converges faster if its inputs are whitened, i.e.,\nlinearly transformed to have zero means and unit variances, and  decorrelated. \n\nThus to say, to improve the training,  one may seek to reduce the internal covariate shift.  \nBy fixing the distribution of the layer inputs $f^\\ell$ as the training progresses,\nit is expected to improve the training speed. As each layer\nobserves the inputs produced by the layers below, it would be advantageous to\nachieve the same whitening of the inputs of each layer.  By whitening the\ninputs to each layer, BN would take a step towards achieving the fixed\ndistributions of inputs that would remove the ill effects of the internal covariate shift. \n\n\nWithin this framework, whitening the layer inputs is expensive, as it requires\ncomputing the covariance matrix \n\\begin{equation}\n{\\rm Cov}[f^\\ell] = \\mathbb E_{ x \\in X} [f^\\ell(x) [f^\\ell(x)]^T]-\\mathbb E_{ x \\in X} [f^{\\ell}(x)]\\mathbb E_{ x \\in X} [f^\\ell(x)]^T\n\\end{equation}\nand its inverse square root, to produce the whitened activations \n\\begin{equation}\n\\tilde  f^\\ell = \\left({\\rm Cov}[f^\\ell \\right)^{-1/2}\\left(f^\\ell-\\mathbb E[f^\\ell]\\right),\n\\end{equation}\nas well as the derivatives of these transforms for backpropagation. \nHowever, this is impossible to take gradient for $\\left({\\rm Cov}[f^\\ell] \\right)^{-1/2}$\nw.r.t $\\Theta$ as $ f^\\ell = f^\\ell(x; \\Theta)$. \n\nThe original version is to do whitening in Batch i.e. $\\mathbb E_{ x \\in X} [\\cdot ]$, that. This\nis why this is called Batch Normalization not mini-batch normalization which \nis the practical version of batch normalization.\n\n\\subsection{Practical batch normalization: assume i.i.d and add scale and shift }\nSince the full whitening of each layer's inputs is costly and not\neverywhere differentiable, BN makes two necessary simplifications. \n\n\\paragraph{Take batch normalization for each scalar feature (neuron).}\n\nThe first is that instead of whitening the features in layer\ninputs and outputs {\\bf jointly}, batch normalization will normalize each {\\bf scalar feature (neuron)}\nindependently, by making it have the mean of zero and the variance of\n1.   Assume the distribution of\nscalar features to be i.i.d. \n\n\nFor a layer with $n^\\ell$-dimensional input $f^\\ell = (f^\\ell_1, \\ldots,  f^\\ell_{n^\\ell})$, we\nwill normalize each dimension \n$$ \\hat{f}^\\ell_k = \\frac{f^\\ell_k-\\mathbb E [ f^\\ell_k]}{\n\t\\sqrt{{\\rm Var}[f^\\ell_k]}}$$\nwhere the expectation and variance are\ncomputed over the training data set. As shown in\n\\cite{lecun1998neural}, such normalization speeds up convergence,\neven when the  features are not decorrelated.\n\n\\paragraph{Add scale and shift into batch normalization.}\nNote that simply normalizing each input of a layer may change what the\nlayer can represent. For instance, normalizing the inputs of a\nsigmoid would constrain them to the linear\nregime of the nonlinearity. To address this, we make sure that {\\em the transformation inserted in\n\tthe network can represent the identity transform}.  To\naccomplish this, we introduce, for each activation $\\hat f^\\ell_k$, a pair of\nparameters $\\gamma^\\ell_k, \\beta^\\ell_k$, which scale and shift the\nnormalized value: \n\\begin{equation}\n\\tilde{f^\\ell}_k  = \\gamma^\\ell_k \\hat{f^\\ell}_k +\\beta^\\ell_k.\n\\end{equation}\nThese parameters are learned along with the original model\nparameters, and restore the representation power of the\nnetwork. Indeed, by setting $\\gamma^\\ell_k = \\sqrt{{\\rm Var}[f^\\ell_k]}$ and\n$\\beta^\\ell_k = \\mathbb E [f^\\ell_k]$, we could recover the original activations, if that were the optimal thing to do.\n\n\n\n\\subsection{Batch normalization for DNN}\n\\paragraph{Definition of batch normalization operation based on the batch}\nFollowing the idea in \\eqref{DL-process}, we consider that we have the all\ntraining data as\n\\begin{equation}\\label{eq:trainingdata}\n(X,Y) := \\{x^i, y^i\\}_{i=1}^N.\n\\end{equation}\nSince the normalization is applied to\neach activation independently, let us focus on a particular activation $ f^\\ell_k$ and omit $k$ as $f^\\ell$ for clarity. \nWe have $N$ values of this activation\nin the batch,\n$$ X=\\{x_1, \\cdots, x_N\\}.$$ \nLet the normalized values be\n$\\hat f^\\ell$, and their linear transformations be $\\tilde f^\\ell$. \n\\begin{equation}\\label{def:BNeq}\n\\begin{aligned}\n\\mu^\\ell_{ X} & \\leftarrow \\mathbb{E}_{x \\sim X} [f^\\ell(x)] =  \\frac{1}{N}\\sum_{i=1}^N f^\\ell(x^i) & \\text{ batch mean}& \\\\\n\\sigma^\\ell_{ X} & \\leftarrow \\mathbb{E}_{x \\sim X}  \\left[(f^\\ell(x)-\\mathbb{E}_{x \\sim X}[ f^\\ell(x)])^2 \\right] = \\frac{1}{N}\\sum_{i=1}^N (f^\\ell(x^i)-\\mu_{ X}^\\ell)^2 &  \\text{ batch variance}&\\\\\n\\hat f^\\ell (x) & \\leftarrow \\frac{f^\\ell(x)-\\mu^\\ell_{ X}}{\\sqrt{\\sigma^\\ell_{ X}+\\epsilon}}   &\\text{ normalize}&\\\\\n\\tilde f^\\ell(x)  & \\leftarrow \\gamma^\\ell \\hat f^\\ell (x) + \\beta^\\ell \n&\\text{ scale and shift}&\n\\end{aligned}\n\\end{equation}\nHere we note that all these operations in the previous equation are defined  element-wise.\nThen at last, we define the batch normalization operation based on the batch set as\n\\begin{equation}\\label{eq:BNop}\n{\\rm BN}_{X}({f^\\ell(x)}) = \\tilde f^\\ell(x) := \\gamma^\\ell  \\frac{f^\\ell(x)-\\mu^\\ell_{ X}}{\\sqrt{\\sigma^\\ell_{ X}+\\epsilon}}  + \\beta^\\ell  ,\n\\end{equation}\nwhere $\\tilde f^\\ell(x)$, $\\mu^\\ell_{ X}$ and $\\sigma^\\ell_{ X}$  are given above.\n\n\\paragraph{Model with batch normalization}\nThen we have the new DNN model with batch normalization as:\n\\begin{equation}\\label{nn-BN0}\n\\begin{cases}\n\\tilde f^1(x^i)&= (\\theta^1 (x^i) ),\\\\\n\\tilde f^\\ell &= \\theta^{\\ell} \\circ \\sigma \\circ {\\rm BN}_{ X}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\n%Here we would like to notice that all these input data \n%$x_i \\in X$, it is already normalized over all the original data set with \n%the same fashion.\n%Thai is to say\n%$$\n%x_i = {\\rm BN}_{\\bar X}(\\bar x_i),\n%$$\n%for the original data $\\bar x_i \\in \\bar X$.\nFor a more comprehensive notation, \nwe can use the next notation\n\\begin{equation}\n\\sigma_{\\rm BN} := \\sigma \\circ {\\rm BN}_{ X}.\n\\end{equation}\nWe can remove the basis $b^\\ell$ in $\\theta^\\ell$, thus to say the real model we use should be\n\\begin{equation}\\label{nn-BN}\n\\begin{cases}\n\\tilde f^1(x^i)&= W^1 x^i ,\\\\\n\\tilde f^\\ell &= W^{\\ell}  \\sigma_{\\rm BN}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\nCombine the two definitions, we note\n\\begin{equation}\n\\tilde \\Theta := \\{W, \\gamma, \\beta\\},\n\\end{equation}\nwhere\n$W = \\{W^1, \\cdots, W^l \\}$, $\\gamma := \\{\\gamma^2, \\cdots, \\gamma^L\\}$ and $\\beta := \\{\\beta^2, \\cdots, \\beta^L\\}$. \nFinally, we have the loss function  \n\\begin{equation}\\label{eq:loss-BN}\n\\mathcal L(\\tilde \\Theta) = \\mathbb{E}_{(x,y)\\sim (X,Y)} \\approx \\frac{1}{N}\\sum_{i=1}^N \\ell(\\tilde f^L(x^i; \\tilde \\Theta), y^i).\n\\end{equation}\nA key observation in \\eqref{eq:loss-BN} and the new BN model \\eqref{nn-BN} is that\n\\begin{equation}\\label{eq:threeExpectation}\n\\begin{aligned}\n\\mu^\\ell_{ X} \n%& \\leftarrow \\frac{1}{N}\\sum_{i=1}^N f^\\ell(x_i)  \n&= \\mathbb{E}_{x \\sim X} [f^\\ell(x)],\\\\\n\\sigma^\\ell_{ X}\n%& \\leftarrow \\frac{1}{N}\\sum_{i=1}^N (f^\\ell(x_i)-\\mu_{ X})^2  \n&=  \\mathbb{E}_{x \\sim X}  \\left[(f^\\ell(x)-\\mathbb{E}_{x \\sim X}[ f^\\ell(x)])^2 \\right], \\\\\n\\mathcal L(\\tilde \\Theta) \n%&= \\sum_{i=1}^N L(\\tilde f^J(x_i; \\tilde \\Theta), y_i)   \n&=  \\mathbb{E}_{(x,y)\\sim (X,Y)}  \\left[\\ell(\\tilde f^L(x^i; \\tilde \\Theta), y^i) \\right].\n\\end{aligned}\n\\end{equation}\nHere we need to mention that\n$$\nx \\sim X\n$$\nmeans $x$ subjects to the discrete distribution of all data $X$. \n%For example:\n%$$\n%{p}_{X}(x = x_i) = \\frac{1}{N}.\n%$$\n%or more mathematically we can use the Dirac distribution as:\n%$$\n%p_{X}(x) = \\frac{1}{N} \\sum_{i=1}^N\\delta(x - x_i).\n%$$\n\n\n%Similar with the case from (batch) gradient descent to stochastic gradient descent.\n%Therefore, BN makes the second simplification: since we use mini-batches \n%in stochastic gradient training, {\\em each mini-batch produces estimates of the mean and variance} of each\n%activation for whole batch. \n\n\\subsection{Batch normalization: some ``modified\" SGD training algorithm}\nFollowing the key observation in \\eqref{eq:threeExpectation}, and recall the \nsimilar case in SGD, we do the the sampling trick in \\eqref{eq:loss-BN} and\nobtain the mini-batch SGD:\n\\begin{equation}\\label{eq:mini-batch-sample}\nx \\sim X \\approx x \\sim \\mathcal B,\n\\end{equation}\nhere $\\mathcal B$ is a mini-batch of batch $X$ with $\\mathcal B \\subset X$.\n\nHowever, for problem in \\eqref{eq:loss-BN}, it is very difficult to find some \nsubtle sampling method because of the composition of $\\mu^\\ell_{\\mathcal X}$\nand $[\\sigma^\\ell_{\\mathcal X}]$. However, one simple way for sampling \n\\eqref{eq:loss-BN} can be chosen as taking \\eqref{eq:mini-batch-sample} for\nall the expectation case in \\eqref{eq:loss-BN} and \\eqref{eq:threeExpectation}. \nThis is to say, in training process ($t$-th step for example), once we choose $B_t \\subset X$\nas the mini-batch, then the model becomes\n\\begin{equation}\\label{nn-BN-training}\n\\begin{cases}\n\\tilde f^1(x^i)&= W^1 x^i ,\\\\\n\\tilde f^\\ell &= W^{\\ell}  \\sigma_{\\rm BN}(\\tilde f^{\\ell-1}), \\quad  \\ell=2,...,L.\n\\end{cases}\n\\end{equation}\nwhere\n\\begin{equation}\n\\sigma_{\\rm BN} := \\sigma \\circ {\\rm BN}_{\\mathcal B_t},\n\\end{equation}\nor we can say that $X$ is replaced by $\\mathcal B_t$ in this case. \nHere ${\\rm BN}_{\\mathcal B_t}$ is defined by\n\\begin{equation}\\label{def:BNeq-traning}\n\\begin{aligned}\n\\mu^\\ell_{\\mathcal B_t} & \\leftarrow \\frac{1}{m}\\sum_{i=1}^m f^\\ell(x^i) & \\text{ mini-batch mean}& \\\\\n\\sigma^\\ell_{\\mathcal B_t} & \\leftarrow \\frac{1}{m}\\sum_{i=1}^m (f^\\ell(x^i)-\\mu_{\\mathcal B_t})^2 &  \\text{ mini-batch variance}&\\\\\n\\hat f^\\ell (x) & \\leftarrow \\frac{f^\\ell(x)-\\mu^\\ell_{\\mathcal B_t}}{\\sqrt{\\sigma^\\ell_{\\mathcal B_t}+\\epsilon}}   &\\text{ normalize}&\\\\\n{\\rm BN}_{\\mathcal B_t}(\\tilde f^{\\ell}) := \\tilde f^\\ell(x) & \\leftarrow \\gamma^\\ell \\hat f^\\ell (x) + \\beta^\\ell \n&\\text{ scale and shift}&\n\\end{aligned}\n\\end{equation}\nHere batch normalization operation introduces some new parameters such as $\\gamma$ and $\\beta$. \nThus to say, for training phase, if we choose mini-batch as $\\mathcal B_t$ in $t$-th training\nstep, we need to take gradient  \n\\begin{equation}\n\\frac{1}{m}\\nabla_{\\tilde \\Theta} \\sum_{i \\in \\mathcal B_t} \\ell(\\tilde f^L(x^i; \\tilde \\Theta), y^i),\n\\end{equation}\nwhich requires the gradient of $\\mu_{B_t}^\\ell$ or $[\\sigma_{B_t}^\\ell]$\nw.r.t $W^i$ for $i \\le \\ell$.\nTo derive the new gradient formula for batch normalization step,\n$$\n\\mu^\\ell_{\\mathcal B_t}, \\quad \\text{and} \\quad \\sigma^\\ell_{\\mathcal B_t},\n$$\ncontain the output of $\\tilde f^{\\ell-1}$.  \nThis is exact the batch normalization method described in \\cite{ioffe2015batch}.\n\n\n\\subsection{Final model  with BN in DNN after training}\nOne key problem is that, in the batch normalization operator, we need to compute the mean and variance \nin a data set (batch or mini-batch). However, in the inference step, we just input one data \ninto this DNN, how to compute the batch normalization operator in this situation. \n\nActually,  the $\\gamma$ and $\\beta$ parameter is fixed after training, the only problem is\nto compute the mean $\\mu$ and variance $\\sigma$. \nAll the mean $ \\mu_{\\mathcal B_t}  $ and variance $\\sigma_{\\mathcal B_t} $ during the training phase \nare just the approximation of the mean and variance of whole batch i.e.  $ \\mu_{X}  $ and $\\sigma_{X}$ \nas shown in \\eqref{eq:threeExpectation}. \n\nOne natural idea might be just use the batch normalization operator w.r.t to the whole training data set, thus to say\njust compute $\\mu_X$ and $\\sigma_X$ by definition in \\eqref{def:BNeq}.\n\n\nHowever, there are at least the next few problems:\n\\begin{itemize}\n\\item computation cost,\n\\item ignoring the statistical approximation (don't make use of the $ \\mu_{\\mathcal B_t}  $ and  $\\sigma_{\\mathcal B_t} $ in training phase).\n\\end{itemize}\n\nConsidering that we have the statistical approximation for $ \\mu_{X}  $ and $\\sigma_{X}$\nduring each SGD step, moving average might be a more straightforward way.\nThus to say, we define the $\\mu^\\ell$ and $[\\sigma^\\ell]$ for the inference (test) phase\nas\n\\begin{equation}\n\\mu^\\ell = \\frac{1}{T}\\sum_{t=1}^T \\mu^\\ell_{\\mathcal B_t}, \n\\quad \\sigma^\\ell =\\frac{1}{T} \\frac{m}{m-1}\\sum_{t=1}^T\\sigma^\\ell_{\\mathcal B_t}.\n\\end{equation}\nHere we take Bessel's correction for unbiased variance.\nThe above moving average step is found in the original paper of batch normalization in \\cite{ioffe2015batch}. \n\nAnother way to do this is to call the similar idea in momentum. \nAt each time step we update the running averages for mean and variance using an exponential decay based on the momentum parameter:    \n\\begin{equation}\n\\begin{aligned}\n\\mu^\\ell_{\\mathcal B_t} &=\\alpha \\mu^\\ell_{\\mathcal B_{t-1}} + (1-\\alpha)\\mu^\\ell_{\\mathcal B_t} , \\\\\n\\sigma^\\ell_{\\mathcal B_t} &=\\alpha \\sigma^\\ell_{\\mathcal B_{t-1}} + (1-\\alpha)\\sigma^\\ell_{\\mathcal B_t} .\n\\end{aligned}\n\\end{equation}\n$\\alpha$ is close to $1$, we can take it as $0.9$ generally. Then we all take bath mean and variance as\n$\\mu^\\ell_X  \\approx \\mu^\\ell_{\\mathcal B_T}$  and $\\sigma^\\ell_X  \\approx \\sigma^\\ell_{\\mathcal B_T}$.\n\nMany people argue that the variance here should also use Bessel's correction.\n\n\\subsection{Batch Normalization for CNN}\nOne key idea in batch normalization is to do normalization with each scalar features (neurons) \nseparately along a mini-batch. \nThus to say, we need to identify what is neuron in CNN. \nThis is a historical problem, some people think neuron in CNN\nshould be the pixel in each channel, some other people think that each channel is just \none neuron. Batch normalization chooses the later one. \nOne important reason for this choice is the fact of computation cost. \n\nFor convolutional layers, batch normalization additionally requires the normalization\nto  obey the convolutional property so that different elements\nof the same feature map, at different locations, are normalized in the\nsame way. \nTo compute $\\mu^\\ell_{\\mathcal B_t}$, we take mean of the set of all values in a feature map across both the\nelements of a mini-batch and spatial locations, so for a mini-batch\nof size $m$ and feature maps of size $m_\\ell \\times n_\\ell$ (image geometrical size), \nwe use the effective mini-batch of size $ m m_\\ell n_\\ell$. \nWe learn a pair of parameters $\\gamma_k$ and $\\beta_k$ per feature map (k-th channel), rather than per activation.\n\n\nFor simplicity, then have the following batch normalization scheme for CNN\n\\begin{equation}\\label{def:BNeq-traningCNN}\n\\begin{aligned}\n\\mu^{\\ell, j}_{\\mathcal B_t} & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell} f^{\\ell, j}_{s,t}(x^i)\n &&\\text{ mean on channel }j \\\\\n\\sigma^{\\ell, j}_{\\mathcal B_t} & \\leftarrow \\frac{1}{m \\times m_\\ell \\times n_\\ell }\\sum_{i=1}^m \\sum_{1\\le s\\le m_\\ell, 1\\le t \\le n_\\ell}\n (f^{\\ell, j}_{s,t}(x^i) - \\mu^{\\ell, j}_{\\mathcal B_t})^2   &&\\text{ variance on channel }j\\\\\n\\hat f^{\\ell, j}_{s,t} (x) & \\leftarrow \\frac{f^{\\ell, j}_{s, t}(x)] - \\mu^{\\ell, j}_{\\mathcal B_t}}{\\sqrt{\\sigma^{\\ell, j}_{\\mathcal B_t} +\\epsilon}}   &&\\text{ normalize }\\\\\n[{\\rm BN}_{\\mathcal B_t}(\\tilde f^{\\ell})]_{j;st} &:= \\tilde f^{\\ell, j}_{s,t}(x)  \\leftarrow \\gamma^{\\ell,j} \\hat f^{\\ell, j}_{s,t} (x)  + \\beta^{\\ell,j} \n&&\\text{ scale and shift on channel}\n\\end{aligned}\n\\end{equation}\n\n\\subsection{Batch normalization for MgNet}\nWhen we train MgNet, we also adopt the batch normalization mechanism. \nThis means that, when we do training for MgNet, we\napply the following basic block in MgNet\n\\begin{equation}\\label{key}\nu^{\\ell,\\nu} \\leftarrow u^{\\ell,\\nu-1} + {\\rm ReLU} \\circ {\\rm BN}_{\\mathcal B_t} \\circ B^{\\ell,\\nu}\\ast {\\rm ReLU} \\circ {\\rm BN}_{\\mathcal B_t} ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,\\nu-1}}),\n\\end{equation}\nor simply\n\\begin{equation}\\label{key}\nu^{\\ell,\\nu} \\leftarrow u^{\\ell,\\nu-1} + {\\rm ReLU}_{\\rm BN} \\circ B^{\\ell,\\nu}\\ast {\\rm ReLU}_{\\rm BN} ({f^\\ell -  A^{\\ell} \\ast u^{\\ell,\\nu-1}}),\n\\end{equation}\nwhere\n\\begin{equation}\\label{key}\n{\\rm ReLU}_{\\rm BN} =  {\\rm ReLU} \\circ {\\rm BN}_{\\mathcal B_t}.\n\\end{equation}\n\n\n", "meta": {"hexsha": "d5f62f991fab01378284821e492090e4b950c142", "size": 19794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/BN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/BN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/BN.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.9848484848, "max_line_length": 199, "alphanum_fraction": 0.7013741538, "num_tokens": 6376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7846550079039897}}
{"text": "\\section*{Bayesian decision theory}\nGiven:\\\\\n- Conditional distribution over labels $P(y|x)$\\\\\n- Set of actions $\\mathcal{A}$\\\\\n- Cost function $C:Y\\times \\mathcal{A} \\rightarrow \\mathbb{R}$\\\\\nPick action that minimizes the expected cost:\n$a^* = \\underset{a \\in \\mathcal{A}}{\\operatorname{argmin}} \\mathbb{E}_y[C(y,a)|x] = \\sum_y P(y|x) \\cdot C(y,a)$ \n\\subsection*{Optimal decision for logistic regression}\n$a^* = \\underset{y}{argmax} \\hat{P}(y|x) = sign(w^T x)$\n\n% \\subsection*{Example: logistic regression}\n% \\begin{itemize}\n% \t Est. cond. dist: $P(y|x,w) = Ber(\\sigma(w^Tx))$\n% \t Action set: $\\mathcal{A} = \\{ +1, -1\\}$\n% \t Cost function: $C(y,a) = [y \\not = a]$ \\\\ \n% \t$= \\left \\{ \n% \t\t\\begin{array}{lr}\n% \t\t\t1 \\text{ , if } y \\not = a\\\\\n% \t\t\t0 \\text{ , otherwise}\n% \t\t\\end{array}\n% \t\t$\n% \\end{itemize}\n% $a^* = \\underset{a \\in \\mathcal{A}}{\\operatorname{argmin}} \\mathbb{E}_y[C(y,a)|x]$\\\\\n% $= \\underset{a \\in \\mathcal{A}}{\\operatorname{argmin}} P(y=1|x,w)[a=1] + P(Y=-1|x,w)[a=+1]$\\\\\n% $= \\underset{a \\in \\mathcal{A}}{\\operatorname{argmin}} P(y \\not = a | x,w) = \\underset{a \\in \\mathcal{A}}{\\operatorname{argmin}} \\frac{1}{1+exp(aw^Tx)}$\\\\\n% $=\\underset{a \\in \\mathcal{A}}{\\operatorname{argmax}} (1 + exp(aw^Tx))$\n% $=\\underset{a \\in \\mathcal{A}}{\\operatorname{argmax}} (aw^Tx)$\\\\\n% $= sign (w^Tx)$\n\n%\\subsection*{Example: Asymmetric costs}\n%\t Est. cond. dist: $\\hat{P}(y|x,w) = Ber(\\sigma(w^Tx))$\n%\t Action set: $\\mathcal{A} = \\{ +1, -1\\}$\n%\t Cost function: $C(y,a) =\n%\t \\begin{cases}\n%\t \tc_{FP} \\text{ , if $y=-1$ and $y=+1$}\\\\\n%\t\t\tc_{FN} \\text{ , if $y=+1$ and $y=-1$}\\\\\n%\t\t\t0 \\text{ , otherwise}\n%\t \\end{cases}\n%\t\t$\n%The action that minimizes the expected cost is:\\\\\n%$C_+ = \\mathbb{E}_y[C(y,+1)|x] = P(y=+1|x) \\cdot 0 + (P(y=-1)|x) \\cdot c_{FP}$\\\\\n%$C_- = \\mathbb{E}_y[C(y,-1)|x] = P(y=+1|x) \\cdot c_{FN} + P(y=-1|x) \\cdot 0$\\\\\n%Predict +1 if $C_+ \\leq C_- \\Leftrightarrow P(y=+1|x) \\geq \\frac{c_{FP}}{c_{FP} + c_{FN}}$\n\n\\subsection*{Doubtful logistic regression}\n\t Est. cond. distr.: $\\hat{P}(y|x) = Ber(y;\\sigma(\\hat{w}^Tx))$\\\\\n\t Action set: $\\mathcal{A} = \\{ +1, -1, D\\}$;  Cost function:\\\\\n\t $C(y,a) = \\begin{cases}\n\t\t\t[y \\neq a] &\\text{if } a \\in \\{+1,-1\\}\\\\\n\t\t\tc &\\text{if } a = D\n       \\end{cases}$\\\\\nThe action that minimizes the expected cost\\\\\n$a^* = y \\text{ if } \\hat{P}(y|x) \\geq 1-c\\text{, D otherwise}$\n%$a^* = \\begin{cases}\n%\t\ty &\\hat{P}(y|x) \\geq 1-c\\\\\n%\t\tD &\\text{otherwise}\n%\t   \\end{cases}\n%$\n\n\\subsection*{Linear regression}\n\t Est. cond. distr.: $\\hat{P}(y|x,w) = \\mathcal{N}(y;w^Tx, \\sigma^2)$\\\\\n $\\mathcal{A} = \\mathbb{R}$; $C(y,a) = (y-a)^2$\\\\\nThe action that minimizes the expected cost\\\\\n$a^* = \\mathbb{E}_y[y|x] = \\int \\hat{P}(y | x) \\partial y = \\hat{w}^Tx$\n\n\\subsection*{Asymmetric cost for regression}\n\t Est. cond. distr.: $\\hat{P}(y|x) = \\mathcal{N}(\\hat{y};\\hat{w}^Tx, \\sigma^2)$\\\\\n\t $\\mathcal{A} = \\mathbb{R}$; $C(y,a) = c_1 \\max(y-a,0) + c_2 \\max(a-y,0)$\nAction that minimizes the expected cost:\\\\\n$a^* = \\hat{w}^Tx + \\sigma \\Phi^{-1} (\\frac{c_1}{c_1 + c_2})$, $\\Phi$: Gaussian CDF\\\\\n%$\\frac{\\partial}{\\partial a}$\\\\\n%$\\frac{\\partial}{\\partial a} \\mathbb{E}_y[C(y,a)|x] = \\int_{-\\infty}^{\\infty} C(y,a) P(y | x) dy \\overset{!}{=} 0$\\\\\n%$= -c_1 \\int_{a}^{\\infty} P(y | x) dy + c_2 \\int_{-\\infty}^{a} P(y | x) dy$\\\\\n%$= -c_1 [1-\\phi(a; w^Tx, \\sigma^2)] + c_2 \\phi(a; w^Tx, \\sigma^2)$\\\\\n%$\\phi(a; w^Tx, \\sigma^2) = \\frac{c_1}{c_1 + c_2}$\\\\\n%using $\\phi(u;v,w) = \\phi((u-v)/\\sqrt{w};0,1)$ and applying inverse CDF of std. ND $\\phi^{-1}$ we get\\\\\n%$a^* = w^Tx + \\sigma\\phi^{-1} (\\frac{c_1}{c_1 + c_2})$", "meta": {"hexsha": "767339cfef64cd0f137be3cc506a47e52202d360", "size": 3544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/DecisionTheory.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/DecisionTheory.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/DecisionTheory.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": 46.025974026, "max_line_length": 156, "alphanum_fraction": 0.5567155756, "num_tokens": 1593, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7846433538062804}}
{"text": "\\subsection{Intervals of Increase/Decrease, and the First Derivative Test}\\label{sec:FirstDer}\nThe method of Section~\\ref{subsec:LocalExtremaSubsection} for deciding whether there is a\nlocal maximum or minimum at a critical value is not always\nconvenient. We can instead use information about the derivative\n$f'(x)$ to decide; since we have already had to compute the derivative\nto find the critical values, there is often relatively little extra\nwork involved in this method.\n\nHow can the derivative tell us whether there is a maximum, minimum, or\nneither at a point? Suppose that $f$ is differentiable at and around $x=a$, and suppose further that $a$ is a critical point of $f$. Then we have several possibilities:\n\\begin{enumerate}\n\\item\tThere is a local maximum at $x=a$. This happens if $f'(x)>0$ as we approach $x=a$ from the left (i.e. when $x$ is in the vicinity of $a$, and $x<a$) and $f'(x)<0$ as we move to the right of $x=a$ (i.e. when $x$ is in the vicinity of $a$, and $x>a$).\n\\item\tThere is a local minimum at $x=a$. This happens if $f'(x)<0$ as we approach $x=a$ from the left (i.e. when $x$ is in the vicinity of $a$, and $x<a$) and $f'(x)>0$ as we move to the right of $x=a$ (i.e. when $x$ is in the vicinity of $a$, and $x>a$).\n\\item\tThere is neither a local maximum or local minimum at $x=a$. If $f'(x)$ does not change from negative to positive, or from positive to negative, as we move from the left of $x=a$ to the right of $x=a$ (that is, $f'(x)$ is positive on both sides of $x=a$, or negative on both sides of $x=a$) then there is neither a maximum nor minimum when $x=a$.\n\\end{enumerate}\nSee the first graph in Figure~\\ref{fig:max and min points}\nand the graph in Figure~\\ref{fig:non extremum}\nfor examples.\n\n\\begin{example}{Local Maximum and Minimum}{localmaxandmin}\nFind all local maximum and minimum points for $f(x)=\\sin x+\\cos\nx$ using the first derivative test.  \n\\end{example}\n\n\\begin{solution} \nThe derivative is $f'(x)=\\cos\nx-\\sin x$ and from Example~\\ref{max and min} the critical\nvalues we need to consider are $\\pi/4$ and $5\\pi/4$.\n\nWe analyze the graphs of $\\sin x$ and $\\cos x$.\nJust to the left of $\\pi/4$ the cosine is larger than the\n  sine, so $f'(x)$ is positive; just to the right the cosine is\n  smaller than the sine, so $f'(x)$ is negative. This means there is a\n  local maximum at $\\pi/4$. Just to the left of $5\\pi/4$ the cosine is\n  smaller than the sine, and to the right the cosine is larger than\n  the sine. This means that the derivative $f'(x)$ is negative to the\n  left and positive to the right, so $f$ has a local minimum at\n  $5\\pi/4$.\n\\end{solution}\n\nThe above observations have obvious intuitive appeal as\nyou examine the graphs in Figures~\\ref{fig:max and min points} and \\ref{fig:non extremum}. We can extend these ideas\nfurther and then formulate and prove a theorem: If the graph of $f$ is\nincreasing before (i.e., to the left of) $x=a$ and decreasing after (i.e.,\nto the right of) $x=a,$ then there is a local maximum at $x=a.$ If the graph\nof $f$ is decreasing before $x=a$ and increasing after $x=a,$ then there is\na local minimum at $x=a.$ If the graph of $f$ is consistently increasing on\neither side of $x=a$ or consistently decreasing on either side of $x=a,$\nthen there is neither a local maximum nor a local minimum at $x=a.$ We can\nprove the following theorem using the Mean Value Theorem.\n\n\\begin{theorem}{Intervals of Increase and Decrease}{IntervalsIncDecTheorem}\nIf $f^{\\prime }\\left( x\\right) >0$ for every $x$ in an interval, then $f$ is\nincreasing on that interval.\n\nIf $f^{\\prime }\\left( x\\right) <0$ for every $x$ in an interval, then $f$ is\ndecreasing on that interval.\n\\end{theorem}\n\\begin{proof}\nWe will prove the increasing case. The proof of the decreasing case\nis similar. Suppose that $f^{\\prime }\\left( x\\right) >0$ on an interval $I.$\nThen $f$ is differentiable, and hence also, continuous on $I.$ If $x_{1}$\nand $x_{2}$ are any two numbers in $I$ and $x_{1}<x_{2},$ then $f$ is\ncontinuous on $\\left[ x_{1},x_{2}\\right] $ and differentiable on $\\left(\nx_{1},x_{2}\\right) .$ By the Mean Value Theorem, there is some $c$ in $%\n\\left( x_{1},x_{2}\\right) $ such that \n\\begin{equation*}\nf^{\\prime }\\left( c\\right) =\\frac{f\\left( x_{2}\\right) -f\\left( x_{1}\\right) \n}{x_{2}-x_{1}}.\n\\end{equation*}%\nBut $c$ must be in $I,$ and thus, since $f^{\\prime }\\left( x\\right) >0$ for\nevery $x$ in $I,$ $f^{\\prime }\\left( c\\right) >0$. Also, since $x_{1}<x_{2},$\nwe have $x_{2}-x_{1}>0.$ Therefore, both the left hand side and the\ndenominator of the right hand side are positive. It follows that the\nnumerator of the right hand must be positive. That is, $f\\left( x_{2}\\right)\n-f\\left( x_{1}\\right) >0,$ or in other words, $f\\left( x_{1}\\right) <f\\left(\nx_{2}\\right) .$ This shows that between $x_{1}$ and $x_{2}$ in $I,$ the\nlarger one, $x_{2},$ necessarily has the larger function value, $f\\left(\nx_{2}\\right) ,$ and the smaller one, $x_{1},$ necessarily have the smaller\nfunction value, $f\\left( x_{1}\\right) .$ This means that $f$ is increasing\non $I$.\n\\end{proof}\n\n\\begin{example}{Local Minimum and Maximum}{LocalMaxMinExample}\nConsider the function $f\\left( x\\right) =x^{4}-2x^{2}.$ Find\nwhere $f$ is increasing and where $f$ is decreasing. Use this information to\nfind the local maximum and minimum points of $f$.\n\\end{example}\n\\begin{solution}\nWe compute $f^{\\prime }\\left( x\\right) $ and analyze its sign. \n\\begin{equation*}\nf^{\\prime }\\left( x\\right) =4x^{3}-4x=4x\\left( x^{2}-1\\right) =4x\\left(\nx-1\\right) \\left( x+1\\right) .\n\\end{equation*}%\nThe solution of the inequality $f^{\\prime }\\left( x\\right) >0$ is $\\left(\n-1,0\\right) \\cup \\left( 1,\\infty \\right) $. So, $f$ is increasing on the\ninterval $\\left( -1,0\\right) $ and on the interval $\\left( 1,\\infty \\right)\n. $ The solution of the inequality $f^{\\prime }\\left( x\\right) <0$ is $%\n\\left( -\\infty ,-1\\right) \\cup \\left( 0,1\\right) .$ So, $f$ is decreasing on\nthe interval $\\left( -\\infty ,-1\\right) $ and on the interval $\\left(\n0,1\\right) .$ Therefore, at the critical points $-1,$ $0$ and $1,$\nrespectively, $f$ has a local minimum, a local maximum and a local minimum.\n\\end{solution}\n\n%\\figure[!ht]\n%\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <1.5truecm,1.5truecm>\n%\\setplotarea x from 0 to 6.28, y from -1 to 1\n%\\axis left shiftedto x=0 /\n%\\axis bottom shiftedto y=0 ticks withvalues {${\\pi\\over4}$}\n%      {$5\\pi\\over4$} / at 0.7853981635 3.926990818 / /\n%\\setquadratic\n%\\plot\n%0.000 0.000 \n%0.063 0.063 0.126 0.125 0.188 0.187 0.251 0.249 \n%0.314 0.309 0.377 0.368 0.440 0.426 0.503 0.482 0.565 0.536 \n%0.628 0.588 0.691 0.637 0.754 0.685 0.817 0.729 0.880 0.771 \n%0.942 0.809 1.005 0.844 1.068 0.876 1.131 0.905 1.194 0.930 \n%1.257 0.951 1.319 0.969 1.382 0.982 1.445 0.992 1.508 0.998 \n%1.571 1.000 1.634 0.998 1.696 0.992 1.759 0.982 1.822 0.969 \n%1.885 0.951 1.948 0.930 2.011 0.905 2.073 0.876 2.136 0.844 \n%2.199 0.809 2.262 0.771 2.325 0.729 2.388 0.685 2.450 0.637 \n%2.513 0.588 2.576 0.536 2.639 0.482 2.702 0.426 2.765 0.368 \n%2.827 0.309 2.890 0.249 2.953 0.187 3.016 0.125 3.079 0.063 \n%3.142 0.000 3.204 -0.063 3.267 -0.125 3.330 -0.187 3.393 -0.249 \n%3.456 -0.309 3.519 -0.368 3.581 -0.426 3.644 -0.482 3.707 -0.536 \n%3.770 -0.588 3.833 -0.637 3.896 -0.685 3.958 -0.729 4.021 -0.771 \n%4.084 -0.809 4.147 -0.844 4.210 -0.876 4.273 -0.905 4.335 -0.930 \n%4.398 -0.951 4.461 -0.969 4.524 -0.982 4.587 -0.992 4.650 -0.998 \n%4.712 -1.000 4.775 -0.998 4.838 -0.992 4.901 -0.982 4.964 -0.969 \n%5.027 -0.951 5.089 -0.930 5.152 -0.905 5.215 -0.876 5.278 -0.844 \n%5.341 -0.809 5.404 -0.771 5.466 -0.729 5.529 -0.685 5.592 -0.637 \n%5.655 -0.588 5.718 -0.536 5.781 -0.482 5.843 -0.426 5.906 -0.368 \n%5.969 -0.309 6.032 -0.249 6.095 -0.187 6.158 -0.125 6.220 -0.063 \n%6.283 0.000 /\n%\\plot\n%0.000 1.000 0.063 0.998 0.126 0.992 0.188 0.982 0.251 0.969 \n%0.314 0.951 0.377 0.930 0.440 0.905 0.503 0.876 0.565 0.844 \n%0.628 0.809 0.691 0.771 0.754 0.729 0.817 0.685 0.880 0.637 \n%0.942 0.588 1.005 0.536 1.068 0.482 1.131 0.426 1.194 0.368 \n%1.257 0.309 1.319 0.249 1.382 0.187 1.445 0.125 1.508 0.063 \n%1.571 0.000 1.634 -0.063 1.696 -0.125 1.759 -0.187 1.822 -0.249 \n%1.885 -0.309 1.948 -0.368 2.011 -0.426 2.073 -0.482 2.136 -0.536 \n%2.199 -0.588 2.262 -0.637 2.325 -0.685 2.388 -0.729 2.450 -0.771 \n%2.513 -0.809 2.576 -0.844 2.639 -0.876 2.702 -0.905 2.765 -0.930 \n%2.827 -0.951 2.890 -0.969 2.953 -0.982 3.016 -0.992 3.079 -0.998 \n%3.142 -1.000 3.204 -0.998 3.267 -0.992 3.330 -0.982 3.393 -0.969 \n%3.456 -0.951 3.519 -0.930 3.581 -0.905 3.644 -0.876 3.707 -0.844 \n%3.770 -0.809 3.833 -0.771 3.896 -0.729 3.958 -0.685 4.021 -0.637 \n%4.084 -0.588 4.147 -0.536 4.210 -0.482 4.273 -0.426 4.335 -0.368 \n%4.398 -0.309 4.461 -0.249 4.524 -0.187 4.587 -0.125 4.650 -0.063 \n%4.712 0.000 4.775 0.063 4.838 0.125 4.901 0.187 4.964 0.249 \n%5.027 0.309 5.089 0.368 5.152 0.426 5.215 0.482 5.278 0.536 \n%5.341 0.588 5.404 0.637 5.466 0.685 5.529 0.729 5.592 0.771 \n%5.655 0.809 5.718 0.844 5.781 0.876 5.843 0.905 5.906 0.930 \n%5.969 0.951 6.032 0.969 6.095 0.982 6.158 0.992 6.220 0.998 \n%6.283 1.000 /\n%\\endpicture}\n%\\label{fig:sin and cos}\n%\\caption{The sine and cosine.}\n%\\endfigure\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:FirstDer}}\n\n\\begin{enumialphparenastyle}\n\nFind all critical points and identify them as local maximum points, local minimum points, or neither.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^2-x$ \n\\begin{sol}\n min at $x=1/2$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=2+3x-x^3$ \n\\begin{sol}\n min at $x=-1$, max at $x=1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^3-9x^2+24x$\n\\begin{sol}\n max at $x=2$, min at $x=4$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=x^4-2x^2+3$ \n\\begin{sol}\n min at $x=\\pm 1$, max at $x=0$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^4-4x^3$\n\\begin{sol}\n min at $x=1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=(x^2-1)/x$\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y=3x^2-(1/x^2)$ \n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $y=\\cos(2x)-x$ \n\\begin{sol}\n min at $x=7\\pi/12+k\\pi$, max at $x=-\\pi/12+k\\pi$, for integer $k$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n$\\ds f(x) = (5-x)/(x+2)$\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds f(x) = |x^2 - 121|$\n\\begin{sol}\n max at $x=0$, min at $x=\\pm 11$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds f(x) = x^3/(x+1)$\n\\begin{sol}\n min at $x=-3/2$, neither at $x=0$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%%\n%\\begin{ex}\n% $\\ds f(x)= \\cases{x^2 \\sin(1/x)  & $x\\neq 0$ \\cr\n% 0  & $x=0$\\cr}$\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds f(x) = \\sin ^2 x$\n\\begin{sol}\n min at $n\\pi$, max at $\\pi/2+n\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find the maxima and minima of $f(x)=\\sec x$.\n\\begin{sol}\n min at $2n\\pi$, max at $(2n+1)\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n  Let $\\ds f(\\theta) = \\cos^2(\\theta) -\n 2\\sin(\\theta)$.  Find the intervals where $f$ is increasing and the\n intervals where $f$ is decreasing in $[0,2\\pi]$.  Use this\n information to classify the critical points of $f$ as either local\n maximums, local minimums, or neither.\n\\begin{sol}\n min at $\\pi/2+2n\\pi$, max at $3\\pi/2+2n\\pi$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Let $r>0$. Find the local\nmaxima and minima of the function $\\ds f(x)\n=\\sqrt{r^2 -x^2 }$ on its domain $[-r,r]$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Let $\\ds f(x) =a x^2 + bx + c$ with $a\\neq 0$. Show that $f$\nhas exactly one critical point using the first derivative test. Give\nconditions on $a$ and $b$ which guarantee that the critical point will\nbe a maximum. It is possible to see this without using calculus at\nall; explain.\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "c8fa017fd9c5d292fb6b1f0eef4f408235f5bab1", "size": 11727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-6-1-inc-dec-first-derivative-test.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5-applications-of-derivatives/5-6-1-inc-dec-first-derivative-test.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5-applications-of-derivatives/5-6-1-inc-dec-first-derivative-test.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.7073954984, "max_line_length": 351, "alphanum_fraction": 0.6485034536, "num_tokens": 4794, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.9343951634543844, "lm_q1q2_score": 0.7846433467382243}}
{"text": "\\subsection{Fibonacci sequence}\n\n\\subsubsection{The generating function}\n\nLet's use a generating function to create a function for the Fibonacci sequence's \\(c\\)th digit.\n\\(F(c)=\\sum_{i=c} x^is_i\\)\n\nLet's look at it for other starts:\n\n\\(F(c+k)=\\sum_{i=c} x^{i+k}s_{i+k}\\)\n\n\\(F(c+k)=\\sum_{i=c+k} x^is_i\\)\n\n\\(F(c+1)=\\sum_{i=c} x^{i+1}s_{i+1}\\)\n\n\\(F(c+2)=\\sum_{i=c} x^{i+2}s_{i+2}\\)\n\nThis means\n\n\\(F(c)x^2+F(c+1)x=\\sum_{i=c} x^i s_i x^2 +\\sum_{i=c} x^{i+1} s_{i+1} x\\)\n\n\\(F(c)x^2+F(c+1)x=\\sum_{i=c} x^{i+2}s_i+\\sum_{i=c} x^{i+2}s_{i+1}\\)\n\n\\(F(c)x^2+F(c+1)x=\\sum_{i=c} x^{i+2}(s_i+s_{i+1})\\)\n\\subsubsection{Using the definiton of the Fibonacci sequence}\n\nFrom the definition of the fibonacci sequence, \\(s_{i}+s_{i+1}=s_{i+2}\\).\n\n\\(F(c)x^2+F(c+1)x=\\sum_{i=c} x^{i+2}(s_{i+2})\\)\n\n\\(F(c)x^2+F(c+1)x=F(c+2)\\)\n\n\\subsubsection{Reducing the functions}\n\nNext, we expand out \\(F(c+1)\\) and \\(F(c+2)\\).\n\n\\(F(c)-F(c+k)=\\sum_{i=c} x^i s_i -\\sum_{i=c+k} x^i s_i\\)\n\n\\(F(c)-F(c+k)=\\sum^{c+k}_{i=c} x^i s_i\\)\n\n\\(F(c+k)=F(c)-\\sum^{c+k}_{i=c} x^i s_i\\)\n\nSo:\n\n\\(F(c+1)=F(c)-\\sum^{c+1}_{i=c} x^i s_i\\)\n\n\\(F(c+1)=F(c)-x^c s_c\\)\n\n\\(F(c+2)=F(c)-\\sum^{c+2}_{i=c} x^i s_i\\)\n\n\\(F(c+2)=F(c)-x^{c+1}s_{c+1}-x^c s_c\\)\n\nLet's take our previous equation\n\n\\(F(c)x^2+F(c+1)x=F(c+2)\\)\n\n\\(F(c)x^2+[F(c)-x^c s_c]x=F(c)-x^{c+1}s_{c+1}-x^c s_c\\)\n\n\\(F(c)x^2+F(c)x-x^{c+1} s_c=F(c)-x^{c+1}s_{c+1}-x^c s_c\\)\n\n\\(F(c)[x^2+x-1]=x^{c+1}s_c-x^{c+1}s_{c+1}-x^c s_c\\)\n\n\\(F(c)=\\dfrac{x^c s_c + x^{c+1}s_{c+1}-x^{c+1}s_c}{1-x-x^2}\\)\n\n\\subsubsection{Using the first element in the sequence}\n\nFor the start of the sequence, \\(c=0\\), \\(s_0=s_1=1\\).\n\n\\(F(0)=\\dfrac{x^0 1 + x - x}{1-x-x^2}\\)\n\n\\(F(0)=\\dfrac{1}{1-x-x^2}\\)\n\nLet's factorise this:\n\n\\(F(0)=\\dfrac{-1}{(x+\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})(x+\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})}\\)\n\nWe can then use partial fraction decomposition\n\n\\(\\dfrac{1}{(M+\\delta)(M-\\delta)}=\\dfrac{1}{2\\delta}[\\dfrac{1}{M-\\delta}-\\dfrac{1}{M+\\delta}]\\)\n\nTo show that\n\n\\(F(0)=\\dfrac{-1}{\\sqrt 5}[\\dfrac{1}{x+\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2}}-\\dfrac{1}{x+\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2}}]\\)\n\n\\(F(0)=\\dfrac{-1}{\\sqrt 5}[\\dfrac{\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2}}{(x+\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})}-\\dfrac{\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2}}{(x+\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})}]\\)\n\n\\(F(0)=\\dfrac{-1}{\\sqrt 5}[\\dfrac{\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2}}{x(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})-1}-\\dfrac{\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2}}{x(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})-1}]\\)\n\n\\(F(0)=\\dfrac{1}{\\sqrt 5}[(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})\\dfrac{1}{1-x(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})}-(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})\\dfrac{1}{1-x(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})}]\\)\n\n\\subsubsection{Finishing off}\n\nAs we know\n\n\\(\\dfrac{1}{1-x}=\\sum_{i=0}x^i \\)\n\nSo\n\n\\(F(0)=\\dfrac{1}{\\sqrt 5}[(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})\\sum_{i=0} x^i(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})^i -(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})\\sum_{i=0}x^i(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})^i]\\)\n\n\\(F(0)=\\dfrac{1}{\\sqrt 5}[\\sum_{i=0} x^i(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})^{i+1} -\\sum_{i=0}x^i(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})^{i+1}]\\)\n\n\\(F(0)=\\dfrac{1}{\\sqrt 5}\\sum_{i=0} x^i[(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})^{i+1} -(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})^{i+1}]\\)\n\nSo the \\(n\\)th number in the sequence (treating \\(n=1\\) as the first number) is:\n\n\\(\\dfrac{1}{\\sqrt 5}[(\\dfrac{1}{2}+\\dfrac{\\sqrt 5}{2})^{n} -(\\dfrac{1}{2}-\\dfrac{\\sqrt 5}{2})^{n}]\\)\n\n", "meta": {"hexsha": "42b1532fb7579063306a29d11fe1c5716f282cea", "size": 3415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/generating/01-02-fibonacci.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-02-fibonacci.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-02-fibonacci.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.3302752294, "max_line_length": 249, "alphanum_fraction": 0.5449487555, "num_tokens": 1759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299612154571, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7845651744184751}}
{"text": "\\subsection{Open Delta Neighborhoods}\r\n\\noindent\r\nAn open delta neighborhood of a point $x_0$ is defined as the set\r\n\\begin{equation*}\r\n\tN\\left(x_0, \\delta\\right) = \\left\\{x \\in \\mathbb{R}^n \\mid \\norm{x-x_0} < \\delta\\right\\}.\r\n\\end{equation*}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./differentialMultivariableCalculus/open_delta.png}\r\n\t\\caption{An open delta neighborhood centered at $(x_0, y_0)$}\r\n\\end{figure}\r\n\r\n\\noindent\r\nThis simply means all points less than a distance $\\delta$ away from point $x_0$.\\\\\r\nFor example, $N( (1,2) , 7) = \\left\\{ (x,y) \\mid \\sqrt{(x-1)^2 + (y-2)^2}<7 \\right\\}$, which is a ball (filled-in circle) of radius 7 centered at $(1, 2)$.", "meta": {"hexsha": "324bc3aff5f0e6b2fa1cef95425674d9f3fc379d", "size": 702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/openDeltaNeighborhoods.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/openDeltaNeighborhoods.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/openDeltaNeighborhoods.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.875, "max_line_length": 155, "alphanum_fraction": 0.6809116809, "num_tokens": 248, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299529686199, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7845651638706258}}
{"text": "\\subsection{Spherical coordinate system}\nA sphere with center $O=(x_0,y_0,z_0)$ and radius $r$ is the set of points at distance exactly $r$ from $O$.\nWe can describe it this by equation\n\\[(x-x_0)^2+(y-y_0)^2+(z-z_0)^2 = r^2\\]\n\n\\centerFig{sph-0}\n\nTo describe a point on a sphere, we can either directly give its coordinates $x,y,z$ or use the spherical coordinate system: this is the system used to position locations on Earth. We use an angle $\\varphi$, the latitude, which tells us how far North the point is (or South, if $\\varphi<0$), and an angle $\\lambda$, the longitude, which tells us how far East the point is (or West, if $\\lambda<0)$. We usually take $\\varphi \\in [-\\frac{\\pi}{2},\\frac{\\pi}{2}]$ and $\\lambda \\in (-\\pi,\\pi]$.\n\n\\centerFig{sph-1}\n\nIf the sphere is centered at the origin, the position represented by coordinates $(\\varphi,\\lambda)$ is\n\\[(r\\cos\\varphi\\cos\\lambda, r\\cos\\varphi\\sin\\lambda, r\\sin\\varphi)\\]\nwhere the $z$-axis points North and the $x$-axis points towards meridian $\\lambda=0$ (on Earth, the Greenwich meridian).\n%Note that this also gives a parametric representation of the sphere.\n\nThe function below finds the position given angles in degrees:\n\\begin{lstlisting}\np3 sph(double r, double lat, double lon) {\n    lat *= M_PI/180, lon *= M_PI/180;\n    return {r*cos(lat)*cos(lon), r*cos(lat)*sin(lon), r*sin(lat)};\n}\n\\end{lstlisting}\n\n\\subsection{Sphere-line intersection}\nA sphere $(O,r)$ and a line $l$ have either 0, 1, or 2 intersection points.\n\n\\centerFig{sph-2}\n\nFinding them is exactly like circle-line intersection: first compute the projection $P$ of the center onto the line, then find the intersections by moving the appropriate distance forward or backward along $l$.\n\n\\centerFig{sph-3}\n\nThis function returns the number of intersection points and places them in pair \\lstinline|out| if they exist.\n\\begin{lstlisting}\nint sphereLine(p3 o, double r, line3d l, pair<p3,p3> &out) {\n    double h2 = r*r - l.sqDist(o);\n    if (h2 < 0) return 0; // the line doesn't touch the sphere\n    p3 p = l.proj(o); // point P\n    p3 h = l.d*sqrt(h2)/abs(l.d); // vector parallel to l, of length h\n    out = {p-h, p+h};\n    return 1 + (h2 > 0);\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "2677977db82f71a15ba3d001b433cef3e84f545e", "size": 2195, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/sph/sph-basics.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-basics.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-basics.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": 48.7777777778, "max_line_length": 489, "alphanum_fraction": 0.7034168565, "num_tokens": 656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391727723469, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7845566943672228}}
{"text": "\n\\subsection{Maximum A-Priori (MAP) estimation}\n\nMode estimate\n\n\\(Arg max_\\theta p(\\theta | X)\\)\n\nUsing Bayes theorem:\n\n\\(P(\\theta | X)= \\dfrac{P(X|\\theta )P(\\theta)}{P(X)}\\)\n\nSo:\n\n\\(P(\\theta | X)= \\dfrac{P(X|\\theta )P(\\theta)}{P(X)}\\)\n\n\\(Argmax_\\theta p(\\theta | X)=Argmax_\\theta \\dfrac{p(X|\\theta )P(\\theta)}{P(X)}\\)\n\nThe denominator isn't affected so:\n\n\\(Arg max_\\theta p(\\theta | X)=Arg max_\\theta p(X|\\theta )P(\\theta)\\)\n\nIf \\(P(\\theta )\\) is a constant then this is the same as the MLE estimator.\n\n\\subsubsection{Other}\n\n\\(Argmax_\\theta p(\\theta|X)\\)\n\nMode estimate\n\n\\(p(\\theta|X)= \\dfrac{p(X| \\theta)p(\\theta )}{p(X)}\\)\n\n\\(Argmax_\\theta \\dfrac{p(X| \\theta)p(\\theta )}{p(X)}\\)\n\n\\(\\theta \\) doesn't change denominator so can instead use:\n\n\\(Argmax_\\theta p(X| \\theta)p(\\theta )\\)\n\nIt is the same as maximum likelihood estimator if \\(p(\\theta )\\) is a constant. \n\n", "meta": {"hexsha": "b2a6b96696d26dd24004d1a0cf202d7ff8514ce7", "size": 868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MAP/01-01-MAP.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/MAP/01-01-MAP.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/MAP/01-01-MAP.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.7, "max_line_length": 81, "alphanum_fraction": 0.6347926267, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7844959648916076}}
{"text": "\\lab{Application}{Nearest Neighbor Search}{Nearest Neighbor Search}\n\\label{Ch:NNS}\n\n\\objective{Teach about branch and bound and the curse of dimensionality using the nearest neighbor search problem.}\n\n\\section*{The Nearest Neighbor Search Problem}\n\nYou move into a city that has several post offices.\nYou want to know which one is the closest.\nThis problem is  known as the nearest neighbor search problem or the post-office problem.\nThe general problem is to find the closest of a set of points to any new point.\n\nThis has many applications which include computer vision, pattern recognition, internet marketing and data compression.\n\nThe naive way to solve this problem is to check the distance of all the data against the point.\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by exhaustively checking all the distances.\nThe function should take in the set of points that is the data and a single point.\nThe output should be the distance to the closest data point and the index of that point.\nYour function should be able to take in data in an arbitrary dimension.\n\\end{problem}\n\nThe complexity of this algorithm is $O(kn)$.\nWhere  is the $k$ number of dimensions and $n$ is the number of data points.\n\n\\section*{K-D Trees}\n\nA faster way to solve this problem is to build a k-d tree and search the k-d tree for the nearest neighbor. \n\nA k-d tree is a binary tree where the nodes to the left of parent node have a lower value in the i-th dimension and the nodes to the right of the parent node have a greater value in the i-th dimension.\nWhich dimension you split the nodes alternates at different levels.\nIn the $3$ dimensional case the root node is divided in the $x$ dimension, children in the $y$ dimension, grandchildren in the $z$ dimension, and the great-grandchildren in the $x$ dimension and so on.\nEach node stores its location, left child and right child.\nThis requires sorting at each level so the complexity is $O(n log^2(n))$, but we only need to build the k-d tree once and after that we can query it as many times as we want.\n\nIncluded is a function that takes in a set of data and builds k-d tree.\nThe leaf nodes' children are  python's ``None\" object.\n\nTODO: revise algorithm description\n\nThe search of the tree is done recursively.\nWe will call the node that we are on the parent node.\nWe first see if the distance between the parent node at the less is current best.\nIf so, we update it.\nWe then compare the values in the i-th dimension of the point and the parent.\nIf it is point's value is less than the parent we recursively go down the left child, greater, the right child.\nThen we have to check if the hypersphere around the point with radius being the current best distance crosses the dividing hyperplane created by the parent.\nIf the point's value is less than the parent, we do this by checking to see if the value in the i-th dimension plus the current best distance is greater than the parent's value in the i-th dimension.\nIf the point's value is greater than the parent, we do this by checking to see if the value n the i-th dimension minus the current best distance is less than the parent's value in the i-th dimension.\nIf this be the case, we recursively go down the other child as well.\n\n\\begin{problem}\nWrite a function that solves the nearest neighbor search problem by searching through a k-d tree.\nThe function should take in k-d tree and a single point.\nThe output should be the distance to the closest data point and the coordinates of that point. \n\\end{problem}\n\n\\begin{problem}\nTime both the functions you have created with the number of data points being $10,000-100,000$ every multiple of $10,000$ with $4$ dimensions.\nTime only the searching of the k-d tree not the building of it.\nPlot both times on the same plot.\nHow do the two algorithms compare?\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[scale = .5]{4dTime.pdf}\n\\caption{Your graph should look like this.\nThe green line is the naive version and blue line is using a kd-tree.\nAs you can see the kd-tree is much faster.}\n\\end{figure}\n\nThe complexity of this algorithm is $O(klog(n))$ in optimal time.\nIts worst case is $O(k*n^{1-\\frac{1}{k}})$ where $k$ is the number of dimensions and $n$ is the number of points in the tree.\nThe reasons for this are discussed in the next section.\n\n\\section*{Curse of Dimensionality}\n\nAs you increase the number of dimensions the number of times that you have to go down both branches increases.\nYou get to the point where you eliminate very few points by using a k-d tree.\n\n\\begin{problem}\nTime both algorithms for the number of data points being $10,000-100,000$ every multiple of $10,000$ with $20$ dimensions.\nPlot both times on the same plot. Now how do the two algorithms compare?\n\\end{problem}\n\n\\begin{figure}[H]\n\\includegraphics[scale = .5]{20dTime.pdf}\n\\caption{\nYour graph should look like this.\nThe green line is the naive version and blue line is using a kd-tree.\nAs you can see the kd-tree is slightly slower than the naive version.}\n\\end{figure}\n\n\\begin{problem}\nTime the SciPy built in function for searching a k-d tree (do not time the building of the kd-tree) for the number of dimensions points being $2-50$ with $20,000$ data points.\nPlot the time.\nWhat do you notice?\n\\li{from scipy.spatial import KDTree} will import the built in k-d tree.\nCreate the tree by \\li{tree = KDTree(data)} and search it by \\li{tree.query(point)}.\n\n\\li{scipy.spatial} includes a \\li{cKDTree} object which is implemented in C.\nIs it any better?\n\n\\end{problem}\n\\begin{figure}[h!]\n\\includegraphics[scale = .5]{curseD.pdf}\n\\caption{\nYour graph should look similar to this.\nAround 15 dimensions the time jumps.\nAt that point using a kd-tree is not more effective than checking all the combinations.}\n\\end{figure}\n\n\n", "meta": {"hexsha": "ff2f667309a610ed6c076c0d5941262314815a76", "size": 5788, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/NearestNeighbor/NearestNeighbor.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/NearestNeighbor/NearestNeighbor.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/NearestNeighbor/NearestNeighbor.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": 50.3304347826, "max_line_length": 201, "alphanum_fraction": 0.7709053214, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.9086178888906091, "lm_q1q2_score": 0.7844930619402407}}
{"text": "\n\\subsection{k-medoids}\n\n\\subsubsection{Introduction}\n\nk-mediods is similar to k-means clustering, with two key differences:\n\n\\begin{itemize}\n\\item Centroids are now always located on data points, rather than floating freely.\n\\item We mimimise \\(l_1\\) distance, rathern than \\(l_2\\).\n\\end{itemize}\n\n\\subsubsection{Partitioning Around Medoids (PAM) algorithm}\n\nThis is the most common approach for k-medoids.\n\nWe initialise randomly, as we do for k-means.\n\nWe then iterate the following:\n\n\\begin{itemize}\n\\item Calculate the loss for the current allocation\n\\item For each medoid, see if swapping allocation with another (non-medoid) data point decreases the cost.\n\\item If it does, make the swap.\n\\end{itemize}\n\n", "meta": {"hexsha": "7565c909381c3c21d8ce16249e82944f62e020cc", "size": 711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/clustering/01-03-kMedoids.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/clustering/01-03-kMedoids.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/clustering/01-03-kMedoids.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.3333333333, "max_line_length": 106, "alphanum_fraction": 0.7721518987, "num_tokens": 182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.912436153333645, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7843882823950595}}
{"text": "% design and analysis\n%\n% DESIGN AND ANALYSIS: Objective of the study, data source, statistical model/tools/methodology, \n% validity of the assumptions if any, results of the study (graphs, tables will go here),\n% results discussion, (interpretations/consclusions/inferences)\n%\n%----------------------------------------------------------------------------------------\n%\tPACKAGES AND OTHER DOCUMENT CONFIGURATIONS\n%----------------------------------------------------------------------------------------\n% none\n\n\n\\section{Design and Analysis}\nTo best model the dichotomous response variable, Y\\textunderscore HighGradeCancer, in the Prostate Cancer case study, I will employ a multiple logistic regression model, where 1 indicates high grade cancer and 0 indicates not high grade cancer. \\par\nIn statistics, if \\(\\pi = f(x)\\) is a probability then \\(\\frac{\\pi}{1-\\pi}\\) is the corresponding \\textit{odds}, and the \\textbf{logit} of the probability is the logarithm of the odds:\n\\begin{equation}\n\tlogit(\\pi) = log(\\frac{\\pi}{1-\\pi})\n\\end{equation}\n\nNow, simple logistic regression means assuming that \\(\\pi(x)\\) is related to \\(\\beta_0 + \\beta_1x\\) (the \\textit{logit response function}) by the logit function. By equating \\(logit(\\pi)\\) to the logit response function, we understand that the logarithm of the odds is a linear function of the predictor. In particular, the slope parameter \\(\\beta_1\\) is the change in the log odds associated with a one-unit increase in \\textit{x}. This implies that the odds itself changes by the multiplicative factor \\(e^{\\beta_1}\\) when \\textit{x} increases by 1 unit.\n\n\\begin{equation}\n\tlog(\\frac{\\pi}{1-\\pi}) = \\beta_0 + \\beta_1x\n\\end{equation}\n\nFrom here, straightforward algebra will then show the Simple Linear Regression Model:\n\n\\begin{equation}\n\tE[Y] = \\pi(x) = \\frac{e^{\\beta_0 + \\beta_1x}}{1+e^{\\beta_0 + \\beta_1x}}\n\\end{equation}\n\nNext, this simple logistic regression model is easily extended to more than one predictor variable by inclusion of the following two vectors, in matrix notation:\n\n\\[\n\t\\boldsymbol{\\beta} = \n\t\\begin{bmatrix}\n\t\t\\beta_0 \\\\ \\beta_1 \\\\ \\vdots \\\\ \\beta_{p-1}\n\t\\end{bmatrix} \\quad\n\t\\textbf{X} = \n\t\\begin{bmatrix}\n\t\t1 \\\\ X_1 \\\\ X_2 \\\\ \\vdots \\\\ X_{p-1}\n\t\\end{bmatrix} \n\\]\n\nWith this notation, the simple logistic response function (Eqn. 3) extends to the multiple logistic response function as follows:\n\n\\begin{equation}\n\tE[Y] = \\pi(\\textbf{X}) = \\frac{exp(\\textbf{X}'\\boldsymbol{\\beta})}{1+exp(\\textbf{X}'\\boldsymbol{\\beta})}\n\\end{equation}\n\nFitting the logistic regression to the sample data requires that the parameters \\(\\beta_0\\), \\(\\beta_1\\),\\(\\cdots\\), \\(\\beta_{p-1}\\) be estimated. This will be done using the maximum likelihood technique provided within the statistical packages of both \\textbf{R} and \\textit{Python}.\n\n\\subsection{Data Transformations and Standardization}\nVariable transformation is an important technique to create robust models using logistic regression, and the appropriate transformations on continuous variables are necessary to optimize the model predictiveness. Because the predictors are linear in the log of the odds, it is often helpful to transform the continuous variables to create a more linear relationship. \\par \nThe raw data collected contained several predictors with high skewness values. A few concerning features were determined to be PSA Level (skewness = 4.39), Cancer Volume (skewness = 2.18), and Weight (skewness = 7.46). As a prepossessing step to reduce skewness, I elected to transform these continuous predictor variables using the log-transformation, and standardize \\textit{all} the data on top of that. The standardization step was used to normalize the data, and did not affect any underlying distributions among the predictor variables. \\par\nThe finalized data skewness is summarized directly below in Figure 1. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.9]{final_skewness}\n\t\\caption{Finalized Skewness Values of Transformed Predictor Variables.}\n\\end{figure}\n\nAdditionally, I've included the histogram of PSA Level vs. Cancer Volume in Figure 2 - a helpful visual for the two predictors which carried the most significance through much of my analysis, as we soon shall see. Notice how the distributions exhibit no notable skewness, are quite symmetrical, and are centered on zero.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics{psalevel_cancervol_skewness}\n\t\\caption{Finalized PSALevel vs. CancerVol Histogram.}\n\\end{figure}\n\n\\subsection{Model Selection}\nThe data of 97 individual men in the Prostate Cancer sample was split at 80\\% for train (model-building) and test (validation) sets. The training set is a random 76 observations and was used for fitting the model, and the remaining 21 cases were saved to serve as a validation data set. Figure 3 in columns 1-8 contains the variables, and shows a portion of the finalized and processed training data. \\par\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.7]{train_data_python}\n\t\\caption{Portion of Processed Model-Building Data Set - \\textit{Python} Dataframe.}\n\\end{figure}\n\n\\pagebreak\n\\subsubsection{Best Subsets Procedure}\nThe procedure outlined here will help identify a group of subset models that give the best values of a specified criterion. This technique has been developed by time-saving algorithms which can find the most promising models, without having to evaluate all \\(2^{p-1}\\) candidates. The use of the best subset procedure is based on the \\textit{AIC\\textsubscript{p}} criteria, where promising models will yield a relatively small value. \\par\nThe minimized \\textit{AIC\\textsubscript{p}} stepwise output given by \\textbf{R} is provided in Figure 4 below.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.9]{best_subset}\n\t\\caption{Full Linear Model  \\textit{AIC\\textsubscript{p}} Best Subset Results - \\textbf{R} Output.}\n\\end{figure}\n\nIn this procedure, I instructed \\textbf{R} to iterate \"backwards\" through all 7 predictor variables and it was determined \\textit{AIC\\textsubscript{p}} was minimized for \\(p=3\\). In particular, the results reveal that the best two-predictor model for this criteria is based on \\textit{PSA Level} and \\textit{Cancer Volume}. The \\textit{AIC\\textsubscript{p}} was minimized to 50.63, with a Null Deviance equal to 72.61 and Residual Deviance equal to 44.63. \n\n\\subsubsection{Model Fitting}\nA first-order multiple logistic regression model with two predictor variables was considered to be reasonable by \\S4.2.1: \n\n\\begin{equation}\n\\pi(\\textbf{X}) = \\frac{exp(\\textbf{X}'\\boldsymbol{\\beta})}{1+exp(\\textbf{X}'\\boldsymbol{\\beta})} = [1+exp(-\\textbf{X}'\\boldsymbol{\\beta})]^{-1}\n\\end{equation}\n\nwhere:\n\n\\begin{equation}\n\\textbf{X}'\\boldsymbol{\\beta} = \\beta_0+\\beta_1X_1+\\beta_2X_2\n\\end{equation}\n\nThis model was then fit by the method of maximum likelihood to the data from the 76 random training cases. Results are summarized in the Figure 5 \\textit{Python} output below. Provided in the output are the estimated coefficients, their standard errors, \\textit{z}-scores, \\textit{p}-values, and the accompanying 95\\% confidence intervals. \\par\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.9]{model_fit_python}\n\t\\caption{Maximum Likelihood Estimates of Logistic Regression Function - \\textit{Python} Output.}\n\\end{figure}\n\nThus, the estimated logistic response function is:\n\n\\begin{equation}\n\\hat{\\pi}=[ 1+ exp(-2.6867 + 1.0577X_1 + 1.5502X_2)]^{-1}\n\\end{equation}\n\n\\textbf{Note}: Although the PSALevel predictor is not of 5\\% significance (\\textit{p}-value=0.0879), I did find it necessary to maintain it within the model. When removed, the Residual Deviance score of 44.628 from Figure 4 rose to a value of 48.123. Therefore, I've deemed it significant, and a valuable and impactful variable to achieve high model accuracy, and have not removed it from this subset of predictors. \\par\nWith the estimated logistic regression equation now developed, it is left to consider second-order options and make adjustments if required, analyze the residuals and influential observations, test goodness of fit, apply a prediction rule for new observations, and finally apply the final model to the validation data and evaluate the results.\n\n\\subsubsection{Geometric Interpretation}\nWhen fitting a standard multiple logistic regression model with two predictors, the estimated regression shape is an S-shaped surface in three-dimensional space. Figure 6 displays a three-dimensional plot of the estimated logistic response function that depicts the relationship between the diagnosis of high grade prostate cancer (\\textit{Y}, the binary outcome) and two continuous predictors, PSA Level (\\textit{X}\\textsubscript{1}) and Cancer Volume (\\textit{X}\\textsubscript{2}). \\par\nThis surface increases in an approximately linear fashion with increasing values of PSA Level and Cancer Volume, but levels off and is nearly horizontal for very small and large values of these predictors.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.6]{3d_plot}\n\t\\caption{Three-Dimensional Fitted Logistic Response Surface.}\n\\end{figure}\n\n\\subsubsection{Second-Order Predictors}\nOccasionally, the first-order logistic model may not provide a sufficient fit to the data, and the inclusion of higher-order predictors may be considered. I'll conclude my model development stage by attempting to fit the Prostate Cancer data to a \\textit{polynomial logistic} regression model of the second order, and analyze the results. \\par \nFor simplicity, a 2\\textsuperscript{nd}-order polynomial model in \\textit{two} predictors has a logit response function as:\n\n\\begin{equation}\nlogit(\\pi) = \\beta_0 + \\beta_1x_1 + \\beta_2x_2 + \\beta_{11}x_1^2 + \\beta_{22}x_2^2 + \\beta_{12}x_1x_2\n\\end{equation}\n\n\\noindent and can be extended to more predictors by the inclusion of additional variables, their coefficients, and accompanying cross terms. Please recall, the Prostate Cancer data set considers 7 predictors. \\par\nIn many situations the true regression function has one or more peaks or valleys, and in such cases a polynomial function can provide a satisfactory approximation. However, a polynomial fit was not successful here, as indicated by non-significant \\textit{p}-values across all predictors, at 5\\% significance (Figure 7). \n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.9]{poly_output}\n\t\\caption{Logistic Regression Fit for Second-Order Model - \\textbf{R} Output.}\n\\end{figure}\n\nAdditionally, my preliminary scatter plot analysis did not indicate any reason to believe a polynomial fit would be suitable in this study. For example, PSALevel was a major focus of this study and I've provided the scatter plot below in Figure 8. Additional scatter plots are provided in the Appendix, \\S7.1.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics{psalevel_scatterplot}\n\t\\caption{PSALevel vs Y\\_HighGradeCancer Scatterplot - Train Data.}\n\\end{figure}\n\nWithout evidence to be concerned of successfully fitting a model with second-order predictors, I will move forward with my analysis of the previously developed multiple logistic linear regression model.\n\n\n\\subsection{Analysis of Residuals}\nIn this section I will discuss the analysis of residuals and the identification of any influential observations for logistic regression. Due to the nature of logistic regression, and the fact that non-constant variance is always present in this setting, I will focus only on the detection of model inadequacy.\n\n\\pagebreak\n\\subsubsection{Logistic Regression Residuals}\nIf the logistic regression model is correct, then \\(E[Y_i]=\\pi_i\\) and it follows that:\n\n\\begin{equation}\nE[Y_i-\\hat{\\pi}_i]=E[e_i]=0\n\\end{equation}\n\nThis suggests that if the model is correct, a lowess smooth of the plot of residuals against the linear predictor \\(\\hat{\\pi}^{'}_i\\) should result in approximately a horizontal line with zero intercept. Any significant departure from this suggests that the model may be inadequate. Shown in Figure 9 are the Pearson residuals plotted against the linear predictor, with the lowess smooth superimposed.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.70]{residual_plot}\n\t\\caption{Pearson Residual Plot with Lowess Smooth.}\n\\end{figure}\n\nLooking at the plot, the lowess smooth adequately approximates a line having zero slope and zero intercept, and I conclude that no significant model inadequacy is apparent. \n\n\\subsubsection{Influential Observations}\nTo aid in the identification of influential observations, I will use the \\textbf{Cook's Distance} statistic, \\(D_i\\), which measures the standardized change in the linear predictor \\(\\hat{\\pi}_i\\) when the \\textit{i}th case is deleted. Cook's distances are listed in the \\textbf{R} Appendix \\S7.2 for a portion of the Prostate Cancer testing data. \\par\nThe plot of distances in Figure 10 identifies observation 90 as being the most outlying in the \\textit{X} space, and therefore potentially influential - observations 37 and 91 also read relatively high values. Observation 90 was temporarily deleted and the logistic regression fit was obtained. The results were not particularly different from those obtained from the full test set, and the observation was retained. \\textbf{Note}: I additionally and temporarily removed observations 37 and 91 and obtained a fit to the updated final model. The results were not particularly different, and those records were also retained. Thus, no changes to the model are yet necessary.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.55]{cooks_distance}\n\t\\caption{Index Plot of Cook's Distances.}\n\\end{figure}\n\n\n\\subsection{Goodness Of Fit Evaluation}\nThe appropriateness of the fitted logistic regression model needs to be examined before it is accepted for use. In particular, we need to examine whether the estimated response function for the data is monotonic and sigmoidal in shape, as are logistic response functions. Here I will employ the Hosmer-Lemeshow test, which is useful for unreplicated data sets, as is the Prostate Cancer data. The test can detect major departures from a logistic response function, and the alternatives of interest are as follows:\n\n\\begin{align}\n\\begin{split}\n\tH_0: E[Y]=  [1+exp(-\\textbf{X}'\\boldsymbol{\\beta})]^{-1} \\\\\n\tH_1: E[Y] \\neq  [1+exp(-\\textbf{X}'\\boldsymbol{\\beta})]^{-1}\n\\end{split}\n\\end{align}\n\n\\subsubsection{Hosmer-Lemeshow}\nThe Hosmer-Lemeshow Goodness of Fit procedure consists of grouping that data into classes with similar fitted values \\(\\hat{\\pi}_i\\), with approximately the same number of cases in each class. Once the groups are formed, the Hosmer-Lemeshow goodness of fit statistic is calculated by using the Pearson chi-square test statistic of observed and expected frequencies. The test statistic is known to be well approximated by the chi-square distribution with \\(c-2\\) degrees of freedom.\n\n\\begin{equation}\n\t\\chi^2 = \\sum_{j=1}^{c} \\sum_{k=0}^{1} \\frac{(O_{jk}-E_{jk})^2}{E_{jk}}\n\\end{equation}\n\nThe output from \\textbf{R} using 5 groups is shown in Figure 11 below.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics{gof_detail}\n\t% \\caption{insert caption here}\n\t\\includegraphics{gof_results}\n\t\\caption{Hosmer-Lemshow Goodness of Fit Test for Logistic Regression Function.}\n\\end{figure}\n\nLarge values of the test statistic X\\textsuperscript{2} indicate that the logistic response function is not appropriate. The decision rule for testing the alternatives (Eqn. 10) when controlling the level of significance at \\(\\alpha\\) therefore is:\n\n\\begin{align}\n\\begin{split}\n\t\\textrm{If X\\textsuperscript{2}} \\leq \\chi^2(1-\\alpha; c-p)\\textrm{, conclude } H_0 \\\\\n\t\\textrm{If X\\textsuperscript{2}} > \\chi^2(1-\\alpha; c-p)\\textrm{, conclude } H_1\n\\end{split}\n\\end{align}\n\nThus, for \\(\\alpha=0.05\\) and \\(c-2=5-2=3\\), we require \\(\\chi^2(0.95; 3)=7.81\\). Since \\(X^2=0.838\\leq7.81\\), we conclude \\textit{H}\\textsubscript{0}, that the logistic response function is appropriate. The \\textit{p}-value of the test is 0.8403.\n\n\n\\subsection{Development of ROC Curve}\nMultiple logistic regression is often employed for making predictions for new observations.\nThe \\textit{receiver operating characteristic} (ROC) \\textit{curve} plots \\(P(\\hat{Y}=1 | Y=1)\\) as a function of \\(1-P(\\hat{Y}=0 | Y=0)\\) and is an effective way to graphically display prediction rule information, and possible cutoff points. \\par\nThe \"True Positive\" \\textit{y}-axis on an ROC curve is also known as \\textit{sensitivity}, and the \"False Positive\" \\textit{x}-axis is 1-\\textit{specificity}. Figure 12 below exhibits the ROC curve for my model (Eqn. 7) for all possible cut points between 0 and 1.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.45]{roc}\n\t\\caption{ROC Curve.}\n\\end{figure}\n\n\\subsubsection{Prediction Rule}\nIn the training data set (which represented a random 80\\% of the 97 provided observations), there were 14 men who were observed as high grade cancer patients; hence the estimated proportion of persons who had high grade cancer is \\(14/76=0.184\\). This proportion can be used as the starting point in the search for the best cutoff in the prediction rule. \\par\nThus, if \\(\\hat{\\pi}_h\\) represents a newly fitted observation, my first prediction rule investigated is:\n\n\\begin{equation}\n\t\\textrm{Predict 1 if } \\hat{\\pi}_h \\geq 0.184\\textrm{; predict 0 if } \\hat{\\pi}_h < 0.184\n\\end{equation}\n\nThe Confusion Matrix of Table 1 below provides a summary of the number of correct and incorrect classifications based on the initial prediction rule (Eqn. 13). Of the 62 men without high grade cancer, 13 would be incorrectly predicted to have high grade cancer, or an error rate of 21.0\\%. Furthermore, of the 14 persons with high grade cancer, 1 would be incorrectly predicted to not have high grade cancer, or 7.1\\%. Altogether, \\(13+1=14\\) of the 76 predictions would be incorrect, so that the prediction error rate for the rule is \\(14/76=0.184\\) or 18.4\\%. Coincidentally, the model exactly matches our training set proportions with the current prediction rule. \\par\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{ |c||c|c||c|  }\n \t\\hline\n \t\\multicolumn{4}{|c|}{Prediction Rule Eqn. 13} \\\\\n \t\\hline\\hline\n \tTrue Classification&\\(\\hat{Y}=0\\)&\\(\\hat{Y}=1\\)&Total\\\\\n \t\\hline\n \t\\(Y=0\\)&49&13&62\\\\\n \t\\(Y=1\\)&1&13&14\\\\\n \t\\hline\\hline\n \tTotal&50&26&76\\\\\n \t\\hline\n\t\\end{tabular}\n \t\\caption{Classification based on Logistic Response Function Eqn. 7 and Prediction Rule Eqn. 13.}\n\\end{table}\n\n\\pagebreak\nWith this baseline understood, it is straightforward to choose a stronger cutoff point in utilizing the ROC curve of Figure 12. As detailed above, the false-positive rate is not ideal at 21.0\\% - there are too many cases where a man may opt for additional screening and treatment, even invasive actions, because he believes he has high grade prostate cancer. It will be wise to now reference the ROC curve to better choose a prediction cutoff, while also not significantly disturbing the false-negative accuracy for the worse. \\par\nLooking at Figure 12, a step occurs at 0.20 and I use this value for my new cutoff candidate. Thus, my updated prediction rule is stated as follows:\n\n\\begin{equation}\n\t\\textrm{Predict 1 if } \\hat{\\pi}_h \\geq 0.20\\textrm{; predict 0 if } \\hat{\\pi}_h < 0.20\n\\end{equation}\n\nand the effects of this change can be summarized by the Confusion Matrix in Table 2 below.\n\n\\begin{table}[H]\n\t\\centering\n\t\\begin{tabular}{ |c||c|c||c| }\n \t\\hline\n \t\\multicolumn{4}{|c|}{Prediction Rule Eqn. 14} \\\\\n \t\\hline\\hline\n \tTrue Classification&\\(\\hat{Y}=0\\)&\\(\\hat{Y}=1\\)&Total\\\\\n \t\\hline\n \t\\(Y=0\\)&52&10&62\\\\\n \t\\(Y=1\\)&2&12&14\\\\\n \t\\hline\\hline\n \tTotal&54&226&76\\\\\n \t\\hline\n\t\\end{tabular}\n \t\\caption{Classification based on Logistic Response Function Eqn. 7 and Prediction Rule Eqn. 14.}\n\\end{table}\n\nHere, of the 62 men without high grade cancer, 10 are incorrectly predicted, or an error rate of 16.1\\%. Continuing, of the 14 men with high grade cancer, 2 would be incorrectly predicted, or an error rate of 14.3\\%. Altogether, updated prediction rule (Eqn. 14) now provides a total error rate of \\(12/76=0.158\\) or 15.8\\%. Thus, the model accuracy has now increased with a significantly better false-positive rate, which is intended to reduce unnecessary financial stress across the healthcare economy.\n\n\n\\subsection{Model: Strengths and Weaknesses}\n\\subsubsection{Strengths}\n-The two predictors which build the final logistic model are PSA Level and Cancer Volume, and they both are adequately correlated with the dependent (outcome) variable Y\\_HighGradeCancer - their correlation values are 0.489 and 0.493, respectively. In fact, they are more correlated to the dependent variable than any other predictors of the data set. A consumable heat-map version of a correlation matrix is provided by Figure 13 below, with a color legend given in the upper-left corner.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=0.7]{corr_map}\n\t\\caption{Correlation Heatmap - Train Data}\n\\end{figure}\n\n-The final model has an excellent accuracy score of 84.2\\% against training data. If this model also performs well in the validation step, then deploying such a model in use could possibly help non high grade cancer men be categorized as such, and thus not pursue unnecessary invasive testing and not inflate costs within the healthcare system. Also, by properly identifying those men who are high grade cancer patients, treatment and a plan can be devised sooner, as well as doing so by only use of PSA Level and Cancer Volume information, and not invasive testing. \\\\ \n\n\\subsubsection{Weaknesses}\n-An initial concern while building this model occurs at the level of the provided raw data, namely the existence of multicollinearity. Figure 14 below is the Correlation Matrix of the two final predictors which built the final logistic model: PSA Level and Cancer Volume.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1.0]{corr_matrix}\n\t\\caption{PSALevel vs. CancerVol Correlation Matrix - Train Data}\n\\end{figure}\n\n\\pagebreak\nAs shown, PSA Level and Cancer Volume have a mild correlation value of 0.738 in the full data set. One primary danger in designing models with multicollinearity is that small changes to the input data can lead to large changes in the model, which can further lead to over-fitting. Therefore, this logistic model may be considered mildly \"noisy\", sensitive, and not particularly robust. \\\\\n\n-The Goodness of Fit Evaluation of \\S4.4 deserves some concern regarding the Pearson chi-square test. As described previously, the Hosmer-Lemeshow procedure was utilized to determine a goodness of fit, and the test statistic is known to be well approximated by the chi-square distribution with \\(c-2\\) degrees of freedom (Eqn. 11). However, in view of the \\textbf{R} output (Figure 11) with 5 groupings, the expected values (\\textit{y\\textsubscript{1}}) returned were: 0, 0, 1, 4, 9. Because many values are less than 5, and two of the expected values equal 0, the conditions for a chi-square test may be voided, and it may not be an appropriate test procedure here. At the very lest, the results of the Hosmer-Lemeshow test should be accepted carefully. \\\\\n\n-The final model may produce high false-negative rates. In view of Figure 15-A we see that the first prediction cutoff of 0.184 produced 1 count of false-negatives (\\(7.1\\%\\) error rate), and an overall model accuracy of \\(81.6\\%\\). After ROC analysis the final prediction cutoff I've employed is 0.20. By Figure 15-B this rule produces 2 counts of false-negatives (\\(14.3\\%\\) error rate), and an overall model accuracy of 84.2\\%. Thus the overall model accuracy has improved 2.6 percentage points by correctly predicting more non high grade cancer cases, but has concurrently doubled the false-negative rate. Because correctly identifying high grade cancer patients may be considered most important, this arrangement may be a downfall of the final model.\n\n\\begin{figure}[H]\n\\centering\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{confusion_matrix_PR1}\n  \\caption{Confusion Matrix - 0.184 Cutoff Rule.}\n  \\label{fig:sub1}\n\\end{subfigure}%\n\\begin{subfigure}{.5\\textwidth}\n  \\centering\n  \\includegraphics[width=.8\\linewidth]{confusion_matrix_PR2}\n  \\caption{Confusion Matrix - 0.20 Cutoff Rule}\n  \\label{fig:sub2}\n\\end{subfigure}\n\\caption{Classification Based on Logistic Response Function (Eqn. 7) and Prediction Rules (Eqn. 13) and (Eqn. 14).}\n\\label{fig:test}\n\\end{figure}", "meta": {"hexsha": "12e4f7525690de1b3c884ac9b0c4bd4cd5acf641", "size": 24418, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/sections/design_and_analysis.tex", "max_stars_repo_name": "josiwala/prostate-cancer", "max_stars_repo_head_hexsha": "4920f3f3066bac5ceab241f724ff1cda8eda559b", "max_stars_repo_licenses": ["MIT"], "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/sections/design_and_analysis.tex", "max_issues_repo_name": "josiwala/prostate-cancer", "max_issues_repo_head_hexsha": "4920f3f3066bac5ceab241f724ff1cda8eda559b", "max_issues_repo_licenses": ["MIT"], "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/sections/design_and_analysis.tex", "max_forks_repo_name": "josiwala/prostate-cancer", "max_forks_repo_head_hexsha": "4920f3f3066bac5ceab241f724ff1cda8eda559b", "max_forks_repo_licenses": ["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.7768115942, "max_line_length": 757, "alphanum_fraction": 0.7651322795, "num_tokens": 6417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.78436435696105}}
{"text": "\\chapter{Latent linear models}\n\n\n\\section{Factor analysis}\nOne problem with mixture models is that they only use a single latent variable to generate the observations. In particular, each observation can only come from one of $K$ prototypes. One can think of a mixture model as using $K$ hidden binary variables, representing a one-hot encoding of the cluster identity. But because these variables are mutually exclusive, the model is still limited in its representational power.\n\nAn alternative is to use a vector of real-valued latent variables,$\\vec{z}_i \\in \\mathbb{R}^L$. The simplest prior to use is a Gaussian (we will consider other choices later):\n\\begin{equation}\\label{eqn:FA-prior}\np(\\vec{z}_i)=\\mathcal{N}(\\vec{z}_i|\\vec{\\mu}_0,\\vec{\\Sigma}_0)\n\\end{equation}\nIf the observations are also continuous, so $\\vec{x}_i \\in \\mathbb{R}^D$, we may use a Gaussian for the likelihood. Just as in linear regression, we will assume the mean is a linear function of the (hidden) inputs, thus yielding\n\\begin{equation}\\label{eqn:FA-class-conditional-density}\np(\\vec{x}_i|\\vec{z}_i,\\vec{\\theta})=\\mathcal{N}(\\vec{x}_i|\\vec{W}\\vec{z}_i+\\vec{\\mu},\\vec{\\Psi})\n\\end{equation}\nwhere \\vec{W} is a $D \\times L$ matrix, known as the \\textbf{factor loading matrix}, and $\\vec{\\Psi}$ is a $D \\times D$ covariance matrix. We take $\\vec{\\Psi}$ to be diagonal, since the whole point of the model is to “force” $\\vec{z}_i$ to explain the correlation, rather than “baking it in” to the observation’s covariance. This overall model is called \\textbf{factor analysis} or \\textbf{FA}. The special case in which $\\vec{\\Psi}=\\sigma^2\\vec{I}$ is called \\textbf{probabilistic principal components analysis} or \\textbf{PPCA}. The reason for this name will become apparent later.\n\n\n\\subsection{FA is a low rank parameterization of an MVN}\nFA can be thought of as a way of specifying a joint density model on $\\vec{x}$ using a small number of parameters. To see this, note that from Equation \\ref{eqn:Linear-Gaussian-system-normalizer}, the induced marginal distribution $p(\\vec{x}_i|\\vec{\\theta})$ is a Gaussian:\n\\begin{align}\np(\\vec{x}_i|\\vec{\\theta}) & = \\int \\mathcal{N}(\\vec{x}_i|\\vec{W}\\vec{z}_i+\\vec{\\mu},\\vec{\\Psi})\\mathcal{N}(\\vec{z}_i|\\vec{\\mu}_0,\\vec{\\Sigma}_0)\\mathrm{d}\\vec{z}_i \\nonumber \\\\\n & = \\mathcal{N}(\\vec{x}_i|\\vec{W}\\vec{\\mu}_0+\\vec{\\mu},\\vec{\\Psi}+\\vec{W}\\vec{\\Sigma}_0\\vec{W})\n\\end{align}\nFrom this, we see that we can set $\\vec{\\mu}_0=0$ without loss of generality, since we can always absorb $\\vec{W}\\vec{\\mu}_0$ into $\\vec{\\mu}$. Similarly, we can set $\\vec{\\Sigma}_0=\\vec{I}$ without loss of generality, because we can always “emulate” a correlated prior by using defining a new weight matrix, $\\tilde{\\vec{W}}=\\vec{W}\\vec{\\Sigma}_0^{-\\frac{1}{2}}$. So we can rewrite Equation \\ref{eqn:FA-prior} and \\ref{eqn:FA-class-conditional-density} as:\n\\begin{align}\np(\\vec{z}_i)&=\\mathcal{N}(\\vec{z}_i|\\vec{0},\\vec{I}) \\\\\np(\\vec{x}_i|\\vec{z}_i,\\vec{\\theta})&=\\mathcal{N}(\\vec{x}_i|\\vec{W}\\vec{z}_i+\\vec{\\mu},\\vec{\\Psi})\n\\end{align}\n\nWe thus see that FA approximates the covariance matrix of the visible vector using a low-rank decomposition:\n\\begin{equation}\\label{eqn:FA-prior}\n\\vec{C} \\triangleq \\mathrm{cov}[\\vec{x}]=\\vec{W}\\vec{W}^T+\\vec{\\Psi}\n\\end{equation}\nThis only uses $O(LD)$ parameters, which allows a flexible compromise between a full covariance Gaussian, with $O(D^2)$ parameters, and a diagonal covariance, with $O(D)$ parameters. Note that if we did not restrict $\\vec{\\Psi}$ to be diagonal, we could trivially set $\\vec{\\Psi}$ to a full covariance matrix; then we could set $\\vec{W}=0$, in which case the latent factors would not be required.\n\n\n\\subsection{Inference of the latent factors}\n\\begin{align}\np(\\vec{z}_i|\\vec{x}_i,\\vec{\\theta}) & = \\mathcal{N}(\\vec{z}_i|\\vec{\\mu}_i,\\vec{\\Sigma}_i) \\\\\n\\vec{\\Sigma}_i & \\triangleq (\\vec{\\Sigma}_0^{-1}+\\vec{W}^T\\vec{\\Psi}^{-1}\\vec{W})^{-1} \\\\\n               & =(\\vec{I}+\\vec{W}^T\\vec{\\Psi}^{-1}\\vec{W})^{-1} \\\\\n\\vec{\\mu}_i & \\triangleq \\vec{\\Sigma}_i[\\vec{W}^T\\vec{\\Psi}^{-1}(\\vec{x}_i-\\vec{\\mu})+\\vec{\\Sigma}_0^{-1}\\vec{\\mu}_0] \\\\\n            & =\\vec{\\Sigma}_i\\vec{W}^T\\vec{\\Psi}^{-1}(\\vec{x}_i-\\vec{\\mu})\n\\end{align}\nNote that in the FA model, $\\vec{\\Sigma}_i$ is actually independent of $i$, so we can denote it by $\\vec{\\Sigma}$. Computing this matrix takes $O(L^3+L^2D)$ time, and computing each $\\vec{\\mu}_i=\\mathbb{E}[\\vec{z}_i|\\vec{x}_i,\\vec{\\theta}]$ takes $O(L^2+LD)$ time. The $\\vec{\\mu}_i$ are sometimes called the \\textbf{latent scores}, or \\textbf{latent factors}.\n\n\n\\subsection{Unidentifiability}\nJust like with mixture models, FA is also unidentifiable. To see this, suppose $\\vec{R}$ is an arbitrary orthogonal rotation matrix, satisfying $\\vec{R}\\vec{R}^T=\\vec{I}$. Let us define $\\tilde{\\vec{W}}=\\vec{W}\\vec{R}$, then the likelihood function of this modified matrix is the same as for the unmodified matrix, since $\\vec{W}\\vec{R}\\vec{R}^T\\vec{W}^T+\\vec{\\Psi}=\\vec{W}\\vec{W}^T+\\vec{\\Psi}$. Geometrically, multiplying $\\vec{W}$ by an orthogonal matrix is like rotating $\\vec{z}$ before generating $\\vec{x}$.\n\nTo ensure a unique solution, we need to remove $L(L-1)/2$ degrees of freedom, since that is the number of orthonormal matrices of size $L \\times L$.\\footnote{To see this, note that there are $L-1$ free parameters in $\\vec{R}$ in the first column (since the column vector must be normalized to unit length), there are $L-2$ free parameters in the second column (which must be orthogonal to the first), and so on.} In total, the FA model has $D+LD-L(L-1)/2$ free parameters (excluding the mean), where the first term arises from $\\vec{\\Psi}$. Obviously we require this to be less than or equal to $D(D+1)/2$, which is the number of parameters in an unconstrained (but symmetric) covariance matrix. This gives us an upper bound on $L$, as follows:\n\\begin{equation}\nL_{\\mathrm{max}}=\\lfloor D+0.5(1-\\sqrt{1+8D}) \\rfloor\n\\end{equation}\n\nFor example, $D=6$ implies $L \\leq 3$. But we usually never choose this upper bound, since it would result in overfitting (see discussion in Section \\ref{sec:FA-Choosing-L} on how to choose $L$).\n\n\nUnfortunately, even if we set $L < L_{\\mathrm{max}}$, we still cannot uniquely identify the parameters, since the rotational ambiguity still exists. Non-identifiability does not affect the predictive performance of the model. However, it does affect the loading matrix, and hence the interpretation of the latent factors. Since factor analysis is often used to uncover structure in the data, this problem needs to be addressed. Here are some commonly used solutions:\n\\begin{itemize}\n\\item{\\textbf{Forcing $\\vec{W}$ to be orthonormal} Perhaps the cleanest solution to the identifiability problem is to force $\\vec{W}$ to be orthonormal, and to order the columns by decreasing variance of the corresponding latent factors. This is the approach adopted by PCA, which we will discuss in Section \\ref{sec:PCA}. The result is not necessarily more interpretable, but at least it is unique.}\n\\item{\\textbf{Forcing $\\vec{W}$ to be lower triangular} One way to achieve identifiability, which is popular in the Bayesian community (e.g., (Lopes and West 2004)), is to ensure that the first visible feature is only generated by the first latent factor, the second visible feature is only generated by the first two latent factors, and so on. For example, if $L=3$ and $D=4$, the correspond factor loading matrix is given by\n\\begin{equation*}\n\\vec{W}=\\left(\\begin{array}{ccc}\nw_{11} & 0 & 0 \\\\\nw_{21} & w_{22} & 0 \\\\\nw_{31} & w_{32} & w_{33} \\\\\nw_{41} & w_{32} & w_{43}\n\\end{array}\\right)\n\\end{equation*}\nWe also require that $w_{jj} >0$ for $j =1:L$. The total number of parameters in this constrained matrix is $D+DL-L(L-1)/2$, which is equal to the number of uniquely identifiable parameters. The disadvantage of this method is that the first $L$ visible variables, known as the \\textbf{founder variables}, affect the interpretation of the latent factors, and so must be chosen carefully.}\n\\item{\\textbf{Sparsity promoting priors on the weights} Instead of pre-specifying which entries in $\\vec{W}$ are zero, we can encourage the entries to be zero, using $\\ell_1$ regularization (Zou et al. 2006), ARD (Bishop 1999; Archambeau and Bach 2008), or spike-and-slab priors (Rattray et al. 2009). This is called sparse factor analysis. This does not necessarily ensure a unique MAP estimate, but it does encourage interpretable solutions. See Section 13.8 TODO.}\n\\item{\\textbf{Choosing an informative rotation matrix} There are a variety of heuristic methods that try to find rotation matrices $\\vec{R}$ which can be used to modify $\\vec{W}$(and hence the latent factors) so as to try to increase the interpretability, typically by encouraging them to be (approximately) sparse. One popular method is known as \\textbf{varimax}(Kaiser 1958).}\n\\item{\\textbf{Use of non-Gaussian priors for the latent factors} In Section \\ref{sec:ICA}, we will dicuss how replacing $p(\\vec{z}_i)$ with a non-Gaussian distribution can enable us to sometimes uniquely identify $\\vec{W}$ as well as the latent factors. This technique is known as ICA.}\n\\end{itemize}\n\n\n\\subsection{Mixtures of factor analysers}\nThe FA model assumes that the data lives on a low dimensional linear manifold. In reality, most\ndata is better modeled by some form of low dimensional \\emph{curved} manifold. We can approximate a curved manifold by a piecewise linear manifold. This suggests the following model: let the $k$'th linear subspace of dimensionality $L_k$ be represented by $\\vec{W}_k$, for $k=1:K$. Suppose we have a latent indicator $qi \\in \\{1,\\cdots,K\\}$ specifying which subspace we should use to generate the data. We then sample $\\vec{z}_i$ from a Gaussian prior and pass it through the $\\vec{W}_k$ matrix (where $k=q_i$), and add noise. More precisely, the model is as follows:\n\\begin{align}\np(q_i|\\vec{\\theta}) & =\\mathrm{Cat}(q_i\\vec{\\pi}) \\\\\np(\\vec{z}_i|\\vec{\\theta}) & =\\mathcal{N}(\\vec{z}_i|\\vec{0},\\vec{I}) \\\\\np(\\vec{x}_i|q_i=k,\\vec{z}_i,\\vec{\\theta}) & =\\mathcal{N}(\\vec{x}_i|\\vec{W}\\vec{z}_i+\\vec{\\mu}_k,\\vec{\\Psi})\n\\end{align}\nThis is called a \\textbf{mixture of factor analysers}(MFA) (Hinton et al. 1997).\n\nAnother way to think about this model is as a low-rank version of a mixture of Gaussians. In particular, this model needs $O(KLD)$ parameters instead of the $O(KD^2)$ parameters needed for a mixture of full covariance Gaussians. This can reduce overfitting. In fact, MFA is a good generic density model for high-dimensional real-valued data.\n\n\n\\subsection{EM for factor analysis models}\nBelow we state the results without proof. The derivation can be found in (Ghahramani and Hinton 1996a). To obtain the results for a single factor analyser, just set $r_{ic} =1$ and $c=1$ in the equations below. In Section \\ref{sec:EM-for-PCA} we will see a further simplification of these equations that arises when fitting a PPCA model, where the results will turn out to have a particularly simple and elegant interpretation.\n\nIn the E-step, we compute the posterior responsibility of cluster $k$ for data point $i$ using\n\\begin{equation}\nr_{ik} \\triangleq p(q_i=k|\\vec{x}_i,\\vec{\\theta}) \\propto \\pi_k\\mathcal{N}(\\vec{x}_i|\\vec{\\mu}_k,\\vec{W}_k\\vec{W}_k^T\\vec{\\Psi}_k)\n\\end{equation}\n\nThe conditional posterior for $\\vec{z}_i$ is given by\n\\begin{align}\np(\\vec{z}_i|\\vec{x}_i,q_i=k,\\vec{\\theta}) & = \\mathcal{N}(\\vec{z}_i|\\vec{\\mu}_{ik},\\vec{\\Sigma}_{ik}) \\\\\n\\vec{\\Sigma}_{ik} & \\triangleq (\\vec{I}+\\vec{W}_k^T\\vec{\\Psi}_k^{-1}\\vec{W})_k^{-1} \\\\\n\\vec{\\mu}_{ik} & \\triangleq \\vec{\\Sigma}_{ik}\\vec{W}_k^T\\vec{\\Psi}_k^{-1}(\\vec{x}_i-\\vec{\\mu}_k)\n\\end{align}\n\nIn the M step, it is easiest to estimate $\\vec{\\mu}_k$ and $\\vec{W}_k$ at the same time, by defining $\\tilde{\\vec{W}}_k=(\\vec{W}_k,\\vec{\\mu}_k)$, $\\tilde{\\vec{z}}=(\\vec{z},1)$, also, define\n\\begin{align}\n\\tilde{\\vec{W}}_k & =(\\vec{W}_k,\\vec{\\mu}_k) \\\\\n\\tilde{\\vec{z}} & =(\\vec{z},1) \\\\\n\\vec{b}_{ik} & \\triangleq \\mathbb{E}[\\tilde{\\vec{z}}|\\vec{x}_i,q_i=k]=\\mathbb{E}[(\\vec{\\mu}_{ik};1)] \\\\\n\\vec{C}_{ik} & \\triangleq \\mathbb{E}[\\tilde{\\vec{z}}\\tilde{\\vec{z}}^T|\\vec{x}_i,q_i=k] \\\\\n    & =\\left(\\begin{array}{cc}\n\\mathbb{E}[\\vec{z}\\vec{z}^T|\\vec{x}_i,q_i=k] & \\mathbb{E}[\\vec{z}|\\vec{x}_i,q_i=k] \\\\\n\\mathbb{E}[\\vec{z}|\\vec{x}_i,q_i=k]^T & 1\n\\end{array}\\right)\n\\end{align}\nThen the M step is as follows:\n\\begin{align}\n\\hat{\\pi}_k & = \\frac{1}{N}\\sum\\limits_{i=1}^N r_{ik} \\\\\n\\hat{\\tilde{\\vec{W}}}_k & = \\left(\\sum\\limits_{i=1}^N r_{ik}\\vec{x}_i\\vec{b}_{ik}^T\\right)\\left(\\sum\\limits_{i=1}^N r_{ik}\\vec{x}_i\\vec{C}_{ik}^T\\right)^{-1} \\label{eqn:FA-EM-W} \\\\\n\\hat{\\vec{\\Psi}} & = \\frac{1}{N}\\mathrm{diag}\\left[\\sum\\limits_{i=1}^N r_{ik}(\\vec{x}_i-\\hat{\\tilde{\\vec{W}}}_{ik}\\vec{b}_{ik})\\vec{x}_i^T\\right]\n\\end{align}\n\nNote that these updates are for “vanilla” EM. A much faster version of this algorithm, based on ECM, is described in (Zhao and Yu 2008).\n\n\n\\subsection{Fitting FA models with missing data}\n\\label{sec:Fitting-FA-models-with-missing-data}\nIn many applications, such as collaborative filtering, we have missing data. One virtue of the EM approach to fitting an FA/PPCA model is that it is easy to extend to this case. However, overfitting can be a problem if there is a lot of missing data. Consequently it is important to perform MAP estimation or to use Bayesian inference. See e.g., (Ilin and Raiko 2010) for details.\n\n\n\\section{Principal components analysis (PCA)}\n\\label{sec:PCA}\nConsider the FA model where we constrain $\\vec{\\Psi}=\\sigma^2\\vec{I}$, and $\\vec{W}$ to be orthonormal. It can be shown (Tipping and Bishop 1999) that, as $\\sigma^2 \\rightarrow 0$, this model reduces to classical (nonprobabilistic) \\textbf{principal components analysis}(PCA), also known as the Karhunen Loeve transform. The version where $\\sigma^2 > 0$ is known as \\textbf{probabilistic PCA}(\\textbf{PPCA}) (Tipping and Bishop 1999), orsensible PCA(Roweis 1997).\n\n\n\\subsection{Classical PCA}\n\n\n\\subsubsection{Statement of the theorem}\nThe synthesis viewof classical PCA is summarized in the forllowing theorem.\n\n\\begin{theorem}\nSuppose we want to find an orthogonal set of $L$ linear basis vectors $\\vec{w}_j \\in \\mathbb{R}^D$, and the corresponding scores $\\vec{z}_i \\in \\mathbb{R}^L$, such that we minimize the average \\textbf{reconstruction error}\n\\begin{equation}\nJ(\\vec{W},\\vec{Z})=\\frac{1}{N}\\sum\\limits_{i=1}^N \\lVert\\vec{x}_i-\\hat{\\vec{x}}_i\\rVert^2\n\\end{equation}\nwhere $\\hat{\\vec{x}}_i=\\vec{W}\\vec{z}_i$, subject to the constraint that $\\vec{W}$ is orthonormal. Equivalently, we can write this objective as follows\n\\begin{equation}\nJ(\\vec{W},\\vec{Z})=\\frac{1}{N} \\lVert\\vec{X}-\\vec{W}\\vec{Z}^T\\rVert^2\n\\end{equation}\nwhere $\\vec{Z}$ is an $N \\times L$ matrix with the $\\vec{z}_i$ in its rows, and $\\lVert A\\rVert_F$ is the \\textbf{Frobenius norm} of matrix $\\vec{A}$, defined by\n\\begin{equation}\n\\lVert A\\rVert_F \\triangleq \\sqrt{\\sum\\limits_{i=1}^M \\sum\\limits_{j=1}^N a_{ij}^2}=\\sqrt{\\mathrm{tr}(\\vec{A}^T\\vec{A})}\n\\end{equation}\n\nThe optimal solution is obtained by setting $\\hat{\\vec{W}}=\\vec{V}_L$, where $\\vec{V}_L$ contains the $L$ eigenvectors with largest eigenvalues of the empirical covariance matrix, $\\hat{\\vec{\\Sigma}}=\\frac{1}{N}\\sum_{i=1}^N \\vec{x}_i\\vec{x}_i^T$. (We assume the $\\vec{x}_i$ have zero mean, for notational simplicity.) Furthermore, the optimal low-dimensional encoding of the data is given by $\\hat{\\vec{z}}_i=\\vec{W}^T\\vec{x}_i$, which is an orthogonal projection of the data onto the column space spanned by the eigenvectors.\n\\end{theorem}\n\nAn example of this is shown in Figure \\ref{fig:PCA-PPCA}(a) for $D=2$ and $L=1$. The diagonal line is the vector $\\vec{w}_1$; this is called the first principal component or principal direction. The data points $\\vec{x}_i \\in \\mathbb{R}^2$ are orthogonally projected onto this line to get $\\vec{z}_i \\in \\mathbb{R}$. This is the best 1-dimensional approximation to the data. (We will discuss Figure \\ref{fig:PCA-PPCA}(b) later.)\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.60]{PCA-PPCA-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.60]{PCA-PPCA-b.png}}\n\\caption{An illustration of PCA and PPCA where $D=2$ and $L=1$. Circles are the original data points, crosses are the reconstructions. The red star is the data mean. (a) PCA. The points are orthogonally projected onto the line. (b) PPCA. The projection is no longer orthogonal: the reconstructions are shrunk towards the data mean (red star).}\n\\label{fig:PCA-PPCA} \n\\end{figure}\n\nThe principal directions are the ones along which the data shows maximal variance. This means that PCA can be “misled” by directions in which the variance is high merely because of the measurement scale. It is therefore standard practice to standardize the data first, or equivalently, to work with correlation matrices instead of covariance matrices. \n\n\n\\subsubsection{Proof *}\nSee Section 12.2.2 of MLAPP.\n\n\n\\subsection{Singular value decomposition (SVD)}\nWe have defined the solution to PCA in terms of eigenvectors of the covariance matrix. However, there is another way to obtain the solution, based on the \\textbf{singular value decomposition}, or \\textbf{SVD}. This basically generalizes the notion of eigenvectors from square matrices to any kind of matrix.\n\n\\begin{theorem}(\\textbf{SVD}).\nAny matrix can be decomposed as follows\n\\begin{equation}\\label{eqn:SVD}\n\\underbrace{\\vec{X}}_{N \\times D}=\\underbrace{\\vec{U}}_{N \\times N}\\underbrace{\\vec{\\Sigma}}_{N \\times D}\\underbrace{\\vec{V}^T}_{D \\times D}\n\\end{equation}\nwhere $\\vec{U}$ is an $N \\times N$ matrix whose columns are orthornormal(so $\\vec{U}^T\\vec{U}=\\vec{I}$), $\\vec{V}$ is $D \\times D$ matrix whose rows and columns are orthonormal (so $\\vec{V}^T\\vec{V}=\\vec{V}\\vec{V}^T=\\vec{I}_D$), and $\\vec{\\Sigma}$ is a $N \\times D$ matrix containing the $r=\\min(N,D)$ singular values $\\sigma_i \\geq 0$ on the main diagonal, with 0s filling the rest of the matrix.\n\\end{theorem}\n\nThis shows how to decompose the matrix $X$ into the product of three matrices: $\\vec{V}$ describes an orthonormal basis in the domain, and $\\vec{U}$ describes an orthonormal basis in the co-domain, and $\\vec{\\Sigma}$ describes how much the vectors in $\\vec{V}$ are stretched to give the vectors in $\\vec{U}$.\n\nSince there are at most $D$ singular values (assuming $N>D$), the last $N−D$ columns of $\\vec{U}$ are irrelevant, since they will be multiplied by 0. The \\textbf{economy sized SVD}, or \\textbf{thin SVD}, avoids computing these unnecessary elements. Let us denote this decomposition by $\\hat{\\vec{U}}\\hat{\\vec{\\Sigma}}\\hat{\\vec{V}}^T$.If $N>D$, we have\n\\begin{equation}\n\\underbrace{\\vec{X}}_{N \\times D}=\\underbrace{\\hat{\\vec{U}}}_{N \\times D}\\underbrace{\\hat{\\vec{\\Sigma}}}_{D \\times D}\\underbrace{\\hat{\\vec{V}}^T}_{D \\times D}\n\\end{equation}\nas in Figure \\ref{fig:SVD}(a). If $N<D$, we have\n\\begin{equation}\n\\underbrace{\\vec{X}}_{N \\times D}=\\underbrace{\\hat{\\vec{U}}}_{N \\times N}\\underbrace{\\hat{\\vec{\\Sigma}}}_{N \\times N}\\underbrace{\\hat{\\vec{V}}^T}_{N \\times D}\n\\end{equation}\nComputing the economy-sized SVD takes $O(ND\\min(N,D))$ time (Golub and van Loan 1996, p254).\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{SVD-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{SVD-b.png}}\n\\caption{(a) SVD decomposition of non-square matrices $\\vec{X}=\\vec{U}\\vec{\\Sigma}\\vec{V}^T$. The shaded parts of $\\vec{\\Sigma}$, and all the off-diagonal terms, are zero. The shaded entries in $\\vec{U}$ and $\\vec{\\Sigma}$ are not computed in the economy-sized version, since they are not needed. (b) Truncated SVD approximation of rank $L$.}\n\\label{fig:SVD} \n\\end{figure}\n\nThe connection between eigenvectors and singular vectors is the following:\n\\begin{align}\n\\vec{U}&=\\mathrm{evec}(\\vec{X}\\vec{X}^T) \\\\\n\\vec{V}&=\\mathrm{evec}(\\vec{X}^T\\vec{X}) \\\\\n\\vec{\\Sigma}^2&=\\mathrm{eval}(\\vec{X}\\vec{X}^T)=\\mathrm{eval}(\\vec{X}^T\\vec{X})\n\\end{align}\nFor the proof please read Section 12.2.3 of MLAPP.\n\nSince the eigenvectors are unaffected by linear scaling of a matrix, we see that the right singular vectors of $\\vec{X}$ are equal to the eigenvectors of the empirical covariance $\\hat{\\vec{\\Sigma}}$. Furthermore, the eigenvalues of $\\hat{\\vec{\\Sigma}}$ are a scaled version of the squared singular values.\n\nHowever, the connection between PCA and SVD goes deeper. From Equation \\ref{eqn:SVD}, we can represent a rank $r$ matrix as follows:\n\\begin{equation*}\n\\vec{X}=\\sigma_1\\left(\\begin{array}{c} | \\\\ \\vec{u}_1 \\\\ | \\end{array}\\right)\\left(\\begin{array}{ccc} - & \\vec{v}_1 & - \\end{array}\\right)+\\cdots+\\sigma_r\\left(\\begin{array}{c} | \\\\ \\vec{u}_r \\\\ | \\end{array}\\right)\\left(\\begin{array}{ccc} - & \\vec{v}_r^T & - \\end{array}\\right)\n\\end{equation*}\nIf the singular values die off quickly, we can produce a rank $L$ approximation to the matrix as follows:\n\\begin{align}\n\\vec{X} & \\approx \\sigma_1\\left(\\begin{array}{c} | \\\\ \\vec{u}_1 \\\\ | \\end{array}\\right)\\left(\\begin{array}{ccc} - & \\vec{v}_1 & - \\end{array}\\right)+\\cdots+\\sigma_r\\left(\\begin{array}{c} | \\\\ \\vec{u}_L \\\\ | \\end{array}\\right)\\left(\\begin{array}{ccc} - & \\vec{v}_L^T & - \\end{array}\\right) \\nonumber \\\\\n & = \\vec{U}_{:,1:L}\\vec{\\Sigma}_{1:L,1:L}\\vec{V}_{:,1:L}^T\n\\end{align}\nThis is called a \\textbf{truncated SVD} (see Figure \\ref{fig:SVD}(b)).\n\nOne can show that the error in this approximation is given by\n\\begin{equation}\n\\lVert \\vec{X}-\\vec{X}_L \\rVert_F \\approx \\sigma_L\n\\end{equation}\nFurthermore, one can show that the SVD offers the best rank $L$ approximation to a matrix (best in the sense of minimizing the above Frobenius norm).\n\nLet us connect this back to PCA. Let $\\vec{X}=\\vec{U}\\vec{\\Sigma}\\vec{V}^T$ be a truncated SVD of $\\vec{X}$. We know that $\\hat{\\vec{W}}=\\vec{V}$, and that $\\hat{\\vec{Z}}=\\vec{X}\\hat{\\vec{W}}$, so\n\\begin{equation}\n\\hat{\\vec{Z}}=\\vec{U}\\vec{\\Sigma}\\vec{V}^T\\vec{V}=\\vec{U}\\vec{\\Sigma}\n\\end{equation}\nFurthermore, the optimal reconstruction is given by $\\hat{\\vec{X}}=\\vec{Z}\\hat{\\vec{W}}$,so we find\n\\begin{equation}\n\\hat{\\vec{X}}=\\vec{U}\\vec{\\Sigma}\\vec{V}^T\n\\end{equation}\nThis is precisely the same as a truncated SVD approximation! This is another illustration of the fact that PCA is the best low rank approximation to the data.\n\n\n\\subsection{Probabilistic PCA}\n\\begin{theorem}((\\textbf{Tipping and Bishop 1999})).\nConsider a factor analysis model in which $\\vec{\\Psi}=\\sigma^2\\vec{I}$ and $\\vec{W}$ is orthogonal. The observed data log likelihood is given by\n\\begin{align}\n\\log p(\\vec{X}|\\vec{W},\\sigma^2\\vec{I}) & =-\\frac{N}{2}\\ln|\\vec{C}|-\\frac{1}{2}\\sum\\limits_{i=1}^N \\vec{x}_i^T\\vec{C}^{-1}\\vec{x}_i \\nonumber \\\\\n   & =-\\frac{N}{2}\\ln|\\vec{C}|+\\mathrm{tr}(\\vec{C}^{-1}\\vec{\\Sigma})\n\\end{align}\nwhere $\\vec{C}=\\vec{W}\\vec{W}^T+\\sigma^2\\vec{I}$ and $\\vec{\\Sigma}=\\frac{1}{N}\\sum_{i=1}^N \\vec{x}_i\\vec{x}_i^T=\\frac{1}{N}\\vec{X}\\vec{X}^T$. (We are assuming centred data, for notational simplicity.) The maxima of the log-likelihood are given by\n\\begin{equation}\n\\hat{\\vec{W}}=\\vec{V}(\\vec{\\Lambda}-\\sigma^2\\vec{I})^{\\frac{1}{2}}\\vec{R}\n\\end{equation}\nwhere $\\vec{R}$ is an arbitrary $L \\times L$ orthogonal matrix, $\\vec{V}$ is the $D \\times L$ matrix whose columns are the first $L$ eigenvectors of $\\vec{\\Sigma}$, and $\\vec{\\Lambda}$ is the corresponding diagonal matrix of eigenvalues. Without loss of generality, we can set $\\vec{R}=\\vec{I}$. Furthermore, the MLE of the noise variance is given by\n\\begin{equation}\n\\hat{\\sigma}^2=\\frac{1}{D-L}\\sum\\limits_{j=L+1}^D \\lambda_j\n\\end{equation}\nwhich is the average variance associated with the discarded dimensions.\n\\end{theorem}\n\nThus, as $\\sigma^2 \\rightarrow 0$, we have $\\hat{\\vec{W}} \\rightarrow \\vec{V}$, as in classical PCA. What about $\\hat{\\vec{Z}}$? It is easy to see that the posterior over the latent factors is given by\n\\begin{align}\np(\\vec{z}_i|\\vec{x}_i,\\hat{\\vec{\\theta}}) & = \\mathcal{N}(\\vec{z}_i|\\hat{\\vec{F}}^{-1}\\hat{\\vec{W}}^T\\vec{x}_i,\\sigma^2\\hat{\\vec{F}}^{-1}) \\label{eqn:PPCA-posterior}\\\\\n\\hat{\\vec{F}} & \\triangleq \\hat{\\vec{W}}^T\\hat{\\vec{W}}+\\sigma^2\\vec{I}\n\\end{align}\n(Do not confuse $\\vec{F} = \\vec{W}^T\\vec{W}+\\sigma^2\\vec{I}$ with $\\vec{C}=\\vec{W}\\vec{W}^T+\\sigma^2\\vec{I}$.) Hence, as $\\sigma^2 \\rightarrow 0$, we find $\\hat{\\vec{W}} \\rightarrow \\vec{V}$, $\\hat{\\vec{F}} \\rightarrow \\vec{I}$ and $\\vec{z}_i \\rightarrow \\vec{V}^T\\vec{x}_i$. Thus the posterior mean is obtained by an orthogonal projection of the data onto the column space of $\\vec{V}$, as in classical PCA.\n\nNote, however, that if $\\sigma^2 \\rightarrow 0$, the posterior mean is not an orthogonal projection, since it is shrunk somewhat towards the prior mean, as illustrated in Figure \\ref{fig:PCA-PPCA}(b). This sounds like an undesirable property, but it means that the reconstructions will be closer to the overall data mean, $\\hat{\\vec{\\mu}}=\\bar{\\vec{x}}$.\n\n\n\\subsection{EM algorithm for PCA}\n\\label{sec:EM-for-PCA}\nAlthough the usual way to fit a PCA model uses eigenvector methods, or the SVD, we can also use EM, which will turn out to have some advantages that we discuss below. EM for PCA relies on the probabilistic formulation of PCA. However the algorithm continues to work in the zero noise limit, $\\sigma^2=0$, as shown by (Roweis 1997).\n\nLet $\\tilde{\\vec{Z}}$ be a $L \\times N$ matrix storing the posterior means (low-dimensional representations) along its columns. Similarly, let $\\tilde{\\vec{X}}=\\vec{X}^T$ store the original data along its columns. From Equation \\ref{eqn:PPCA-posterior}, when $\\sigma^2=0$, we have\n\\begin{equation}\n\\tilde{\\vec{Z}}=(\\vec{W}^T\\vec{W})^{-1}\\vec{W}^T\\tilde{\\vec{X}}\n\\end{equation}\nThis constitutes the E step. Notice that this is just an orthogonal projection of the data.\n\nFrom Equation \\ref{eqn:FA-EM-W}, the M step is given by\n\\begin{equation}\n\\hat{\\vec{W}}=\\left(\\sum\\limits_{i=1}^N \\vec{x}_i\\mathbb{E}[\\vec{z}_i]^T\\right)\\left(\\sum\\limits_{i=1}^N \\mathbb{E}[\\vec{z}_i]\\mathbb{E}[\\vec{z}_i]^T\\right)^{-1}\n\\end{equation}\nwhere we exploited the fact that $\\vec{\\Sigma}=\\mathrm{cov}[\\vec{z}_i|\\vec{x}_i,\\vec{\\theta}]=\\vec{0}$ when $\\sigma^2=0$.\n\n(Tipping and Bishop 1999) showed that the only stable fixed point of the EM algorithm is the globally optimal solution. That is, the EM algorithm converges to a solution where $\\vec{W}$ spans the same linear subspace as that defined by the first $L$ eigenvectors. However, if we want $\\vec{W}$ to be orthogonal, and to contain the eigenvectors in descending order of eigenvalue, we have to orthogonalize the resulting matrix (which can be done quite cheaply). Alternatively, we can modify EM to give the principal basis directly (Ahn and Oh 2003).\n\nThis algorithm has a simple physical analogy in the case $D=2$ and $L=1$(Roweis 1997). Consider some points in $\\mathbb{R}^2$ attached by springs to a rigid rod, whose orientation is defined by a vector $\\vec{w}$. Let $\\vec{z}_i$ be the location where the $i$'th spring attaches to the rod. See Figure 12.11 of MLAPP for an illustration.\n\nApart from this pleasing intuitive interpretation, EM for PCA has the following advantages over eigenvector methods:\n\\begin{itemize}\n\\item{EM can be faster. In particular, assuming $N,D \\gg L$, the dominant cost of EM is the projection operation in the E step, so the overall time is $O(TLND)$, where $T$ is the number of iterations. This is much faster than the $O(\\min(ND^2,DN^2))$ time required by straightforward eigenvector methods, although more sophisticated eigenvector methods, such as the Lanczos algorithm, have running times comparable to EM.}\n\\item{EM can be implemented in an online fashion, i.e., we can update our estimate of $\\vec{W}$ as the data streams in.}\n\\item{EM can handle missing data in a simple way (see Section \\ref{sec:Fitting-FA-models-with-missing-data}).}\n\\item{EM can be extended to handle mixtures of PPCA/ FA models.}\n\\item{EM can be modified to variational EM or to variational Bayes EM to fit more complex models.}\n\\end{itemize}\n\n\n\\section{Choosing the number of latent dimensions}\n\\label{sec:FA-Choosing-L}\nIn Section \\ref{sec:Model-selection-for-LVM}, we discussed how to choose the number of components $K$ in a mixture model. In this section, we discuss how to choose the number of latent dimensions $L$ in a FA/PCA model.\n\n\n\\subsection{Model selection for FA/PPCA}\nTODO\n\n\\subsection{Model selection for PCA}\nTODO\n\n\n\n\\section{PCA for categorical data}\nIn this section, we consider extending the factor analysis model to the case where the observed data is categorical rather than real-valued. That is, the data has the form $y_{ij} \\in \\{1,...,C\\}$, where $j=1:R$ is the number of observed response variables. We assume each $y_{ij}$ is generated from a latent variable $\\vec{z}_i \\in \\mathbb{R}^L$, with a Gaussian prior, which is passed through the softmax function as follows:\n\\begin{align}\np(\\vec{z}_i) & = \\mathcal{N}(\\vec{z}_i|\\vec{0},\\vec{I}) \\\\\np(\\vec{y}_i|\\vec{z}_i,\\vec{\\theta}) & = \\prod\\limits_{j=1}^R \\mathrm{Cat}(y_{ir}|\\mathcal{S}(\\vec{W}_r^T\\vec{z}_i+\\vec{w}_{0r}))\n\\end{align}\nwhere $\\vec{W}_r \\in \\mathbb{R}^L$ is the factor loading matrix for response $j$, and $\\vec{W}_{0r} \\in \\mathbb{R}^M$ is the offset term for response $r$, and $\\vec{\\theta}=(\\vec{W}_r,\\vec{W}_{0r})_{r=1}^R$. (We need an explicit offset term, since clamping one element of $\\vec{z}_i$ to 1 can cause problems when computing the posterior covariance.) As in factor analysis, we have defined the prior mean to be $\\vec{\\mu}_0=\\vec{0}$ and the prior covariance $\\vec{V}_0=\\vec{I}$, since we can capture non-zero mean by changing $\\vec{w}_{0j}$ and non-identity covariance by changing $\\vec{W}_r$. We will call this categorical PCA. See Chapter 27 TODO for a discussion of related models.\n\nIn (Khan et al. 2010), we show that this model outperforms finite mixture models on the task of imputing missing entries in design matrices consisting of real and categorical data. This is useful for analysing social science survey data, which often has missing data and variables of mixed type.\n\n\n\\section{PCA for paired and multi-view data}\n\n\n\\subsection{Supervised PCA (latent factor regression)}\n\n\n\\subsection{Discriminative supervised PCA}\n\n\n\\subsection{Canonical correlation analysis}\n\n\n\\section{Independent Component Analysis (ICA)}\n\\label{sec:ICA}\nLet $\\vec{x}_t \\in \\mathbb{R}^D$ be the observed signal at the sensors at “time” $t$, and $\\vec{z}_t \\in \\mathbb{R}^L$ be the vector of source signals. We assume that\n\\begin{equation}\n\\vec{x}_t=\\vec{W}\\vec{z}_t+\\vec{\\epsilon}_t\n\\end{equation}\nwhere $\\vec{W}$ is an $D \\times L$ matrix, and $\\vec{\\epsilon}_t \\sim \\mathcal{N}(\\vec{0},\\vec{\\Psi})$. In this section, we treat each time point as an independent observation, i.e., we do not model temporal correlation (so we could replace the $t$ index with $i$, but we stick with t to be consistent with much of the ICA literature). The goal is to infer the source signals, $p(\\vec{z}_t|\\vec{x}_t,\\vec{\\theta})$. In this context, $\\vec{W}$ is called the \\textbf{mixing matrix}. If $L=D$ (number of sources = number of sensors), it will be a square matrix. Often we will assume the noise level, $|\\vec{\\Psi}|$, is zero, for simplicity.\n\nSo far, the model is identical to factor analysis. However, we will use a different prior for $p(\\vec{z}_t)$. In PCA, we assume each source is independent, and has a Gaussian distribution. We will now relax this Gaussian assumption and let the source distributions be any \\emph{non-Gaussian} distribution\n\\begin{equation}\np(\\vec{z}_t) =\\prod\\limits_{j=1}^L p_j(z_{tj})\n\\end{equation}\nWithout loss of generality, we can constrain the variance of the source distributions to be \\vec{1}, because any other variance can be modelled by scaling the rows of $\\vec{W}$ appropriately. The resulting model is known as \\textbf{independent component analysis} or \\textbf{ICA}.\n\nThe reason the Gaussian distribution is disallowed as a source prior in ICA is that it does not permit unique recovery of the sources. This is because the PCA likelihood is invariant to any orthogonal transformation of the sources $\\vec{z}_t$ and mixing matrix $\\vec{W}$. PCA can recover the best linear subspace in which the signals lie, but cannot uniquely recover the signals themselves.\n\nICA requires that $\\vec{W}$ is square and hence invertible. In the non-square case (e.g., where we have more sources than sensors), we cannot uniquely recover the true signal, but we can compute the posterior $p(\\vec{z}_t|\\vec{x}_t,\\hat{\\vec{W}})$, which represents our beliefs about the source. In both cases, we need to estimate Was well as the source distributions $p_j$. We discuss how to do this below.\n\n\n\\subsection{Maximum likelihood estimation}\nIn this section, we discuss ways to estimate square mixing matrices $\\vec{W}$ for the noise-free ICA model. As usual, we will assume that the observations have been centered; hence we can also assume $\\vec{z}$ is zero-mean. In addition, we assume the observations have been whitened, which can be done with PCA. \n\nIf the data is centered and whitened, we have $\\mathbb{E}[\\vec{x}\\vec{x}^T]=\\vec{I}$. But in the noise free case, we also have\n\\begin{equation}\n\\mathrm{cov}[\\vec{x}]=\\mathbb{E}[\\vec{x}\\vec{x}^T]=\\vec{W}\\mathbb{E}[\\vec{z}\\vec{z}^T]\\vec{W}^T\n\\end{equation}\nHence we see that $\\vec{W}$ must be orthogonal. This reduces the number of parameters we have to estimate from $D^2$ to $D(D-1)/2$. It will also simplify the math and the algorithms.\n\nLet $\\vec{V}=\\vec{W}^{-1}$; these are often called the recognition weights, as opposed to $\\vec{W}$, which are the generative weights.\n\nSince $\\vec{x}=\\vec{W}\\vec{z}$, we have, from Equation \\ref{eqn:Multivariate-transformation},\n\\begin{align}\np_x(\\vec{W}\\vec{z}_t) & =p_z(\\vec{z}_t)|\\mathrm{det}(\\vec{W}^{-1})| \\nonumber \\\\\n   & = p_z(\\vec{V}\\vec{x}_t)|\\mathrm{det}(\\vec{V})|\n\\end{align}\nHence we can write the log-likelihood, assuming $T$ iid samples, as follows:\n\\begin{equation*}\n\\frac{1}{T} \\log p(\\mathcal{D}|\\vec{V})=\\log|\\mathrm{det}(\\vec{V})|+\\frac{1}{T}\\sum\\limits_{j=1}^L \\sum\\limits_{t=1}^T \\log p_j(\\vec{v}_j^T\\vec{x}_t)\n\\end{equation*}\nwhere $\\vec{v}_j$ is the $j$'th row of $\\vec{V}$. Since we are constraining $\\vec{V}$ to be orthogonal, the first term is a constant, so we can drop it. We can also replace the average over the data with an expectation operator to get the following objective\n\\begin{equation}\n\\mathrm{NLL}(\\vec{V})=\\sum\\limits_{j=1}^L \\mathbb{E}[G_j(\\vec{z}_j)]\n\\end{equation}\nwhere $\\vec{z}_j=\\vec{v}_j^T\\vec{x}$ and $G_j(\\vec{z}) \\triangleq -\\log p_j(\\vec{z})$. We want to minimize this subject to the constraint that the rows of $\\vec{V}$ are orthogonal. We also want them to be unit norm, since this ensures that the variance of the factors is unity (since, with whitened data, $\\mathbb{E}[\\vec{v}_j^T\\vec{x}]=\\lVert \\vec{v}_j \\rVert^2$, which is necessary to fix the scale of the weights. In otherwords, $\\vec{V}$ should be an orthonormal matrix.\n\nIt is straightforward to derive a gradient descent algorithm to fit this model; however, it is rather slow. One can also derive a faster algorithm that follows the natural gradient; see e.g., (MacKay 2003, ch 34) for details. A popular alternative is to use an approximate Newton method, which we discuss in Section \\ref{sec:FastICA}. Another approach is to use EM, which we discuss in Section \\ref{sec:ICA-EM}.\n\n\n\\subsection{The FastICA algorithm}\n\\label{sec:FastICA}\n\n\n\\subsection{Using EM}\n\\label{sec:ICA-EM}\n\n\n\\subsection{Other estimation principles *}\n\n", "meta": {"hexsha": "51bf3aaaddafbd80379f11eca36133185e580ad7", "size": 35353, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterLatentLinearModels.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/chapterLatentLinearModels.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/chapterLatentLinearModels.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": 88.8266331658, "max_line_length": 744, "alphanum_fraction": 0.71716686, "num_tokens": 11050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404116305639, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7843502151403344}}
{"text": "%---------------------------Aspect Frobenius-----------------------------\n\\section{Aspect Frobenius\\label{s:tri-aspect-Frobenius}}\n\nThe aspect Frobenius is the sum of the edge lengths squared divided by the area\nand normalized so that a unit equilateral triangle has a value of $1$.\n\\[\n  q = \\frac{{\\normvec{{L_0}}}^{2} +\n            {\\normvec{{L_1}}}^{2} + \n            {\\normvec{{L_2}}}^{2}}{4A\\sqrt{3}}\n\\]\n\nNote that in earlier versions of \\verd{}, this metric was\ncalled the triangle aspect ratio.\n\n\\trimetrictable{aspect Frobenius}%\n{$1$}%                                                Dimension\n{$[1,1.3]$}%                                          Acceptable range\n{$[1,DBL\\_MAX]$}%                                     Normal range\n{$[1,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Unit equilateral triangle value\n{\\cite{pebay:03}}%                                    Reference(s)                   \n{v\\_tri\\_aspect\\_frobenius}%                            Verdict function name\n\n", "meta": {"hexsha": "8d7511d450a7aec22758920de364151e59589386", "size": 1056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriAspectFrobenius.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/TriAspectFrobenius.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/TriAspectFrobenius.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.0, "max_line_length": 85, "alphanum_fraction": 0.4564393939, "num_tokens": 241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294403979493139, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7843502017702828}}
{"text": "\\section{Serre classes}\\label{section-serre-classes}\n\\begin{definition}\\label{serre-class}\n    A class $\\cC$ of abelian groups is a \\emph{Serre class} if:\n    \\begin{enumerate}\n\t\\setcounter{enumi}{0}\n\t\\item $0\\in \\cC$.\n\t\\item if I have a short exact sequence $0\\to A\\to B\\to C\\to 0$, then\n\t    $A\\& C\\in \\cC$ if and only if $B\\in\\cC$.\n    \\end{enumerate}\n\\end{definition}\nSome consequences of this definition: a Serre class is closed under\nisomorphisms (easy). A Serre class is closed under subobjects and quotients,\nbecause there is a short exact equence\n$$0\\to A\\hookrightarrow B \\to B/A\\to 0.$$\nConsider an exact sequence $A\\to B\\to C$ (not necessarily a \\emph{short} exact\nsequence). If $A,C\\in \\cC$, then $B\\in \\cC$ because we have a short exact\nsequence:\n$$\n\\xymatrix{\n    & & & \\coker i\\ar[d]\\ar[r] & 0\\\\\n    & A\\ar[r]^i\\ar[d] & B\\ar[r]^p\\ar[ur] & C & 0\\\\\n    0\\ar[r] & \\ker p\\ar[ur] & & & \n}\n$$\nSome examples are in order.\n\\begin{example}\n    \\begin{enumerate}\n\t\\item $\\cC = \\{0\\}$, and $\\cC$ the class of all abelian groups.\n\t\\item Let $\\cC$ be the class of all torsion abelian groups. We need to\n\t    check that $\\cC$ satisfies the second condition of Definition\n\t    \\ref{}. Consider a short exact sequence\n\t    $$0\\to A\\xrightarrow{i} B\\xrightarrow{p} C\\to 0.$$\n\t    We need to show that $B$ is torsion if $A$ and $C$ are torsion. To\n\t    see this, let $b\\in B$. Then $p(b)$ is killed by some integer $n$,\n\t    so there exists $a\\in A$ such that $i(a) = nb$. SInce $A$ is\n\t    torsion, it follows that $b$ is torsion, too.\n\t\\item Let $\\cP$ be a set of primes. Define:\n\t    $$\n\t    \\cC_{\\cP} = \\{ A : \\text{if }p\\not\\in\\cP,\\text{ then }p:A\\xrightarrow{\\simeq} A\\text{, i.e., }A \\text{ is a } \\Z[1/p]\\text{-module}\\}\n\t    $$\n\t    Let $\\Z_{(\\cP)} = \\Z[1/p: p\\not\\in\\cP]\\subseteq\\QQ$.\n\t    \n\t    For instance, if $\\cP$ is the set of all primes, then $\\cC_\\cP$ is\n\t    the Serre class of all abelian groups. If $\\cP$ is the set of all\n\t    primes other than $\\ell$, then $\\cC_\\cP$ is the Serre class\n\t    consisting of all $\\Z[1/\\ell]$-modules. If $\\cP = \\{\\ell\\}$, then\n\t    $\\cC_{\\{\\ell\\}} =: \\cC_\\ell$ is the Serre class of all\n\t    $\\Z_{(\\ell)}$-modules. If $\\cP = \\emptyset$, then $\\cC_\\emptyset$\n\t    is all rational vector spaces.\n\t\\item If $\\cC$ and $\\cC^\\prime$ are Serre classes, then so is $\\cC\\cap\n\t    \\cC^\\prime$. For instance, $\\cC_\\text{tors} \\cap \\cC_\\text{fg}$ is\n\t    the Serre class $\\cC_\\text{finite}$. Likewise, $\\cC_p \\cap\n\t    \\cC_\\text{tors}$ is the Serre class of all $p$-torsion abelian\n\t    groups.\n    \\end{enumerate}\n\\end{example}\nHere are some straightforward consequences of the definition:\n\\begin{enumerate}\n    \\item If $C_\\bullet$ is a chain complex, and $C_n\\in \\cC$, then\n\t$H_n(C_\\bullet)\\in\\cC$.\n    \\item Suppose $F_\\ast A$ is a filtration on an abelian group. If\n\t$A\\in\\cC$, then $\\gr_nA\\in\\cC$ for all $n$. If $F_\\ast A$ is finite\n\tand $\\gr_n A\\in\\cC$ for all $n$, then $A\\in\\cC$.\n    \\item Suppose we have a spectral sequence $\\{E_r\\}$. If $E^2_{s,t}\\in \\cC$,\n\tthen $E^r_{s,t}\\in \\cC$ for $r\\geq 2$. It follows that if $\\{E^r\\}$ is\n\ta right half-plane spectral sequence, then $E^{s+1}_{s,t}\\fib\n\tE^{s+2}_{s,t}\\fib\\cdots\\fib E^\\infty_{s,t}\\in\\cC$.\n\n        Thus, if the spectral sequence comes from a filtered complex (which is\n\tbounded below, such that for all $n$ there exists an $s$ such that $F_s\n\tH_n(C) = H_n(C)$, i.e., the homology of the filtration stabilizes),\n\tthen $E^\\infty_{s,t} = \\gr_s H_{s+t}(C)$. This means that if the\n\t$E^2_{s,t}\\in\\cC$ for all $s+t = n$, then $H_n(C)\\in\\cC$.\n\\end{enumerate}\nTo apply this to the Serre spectral sequence, we need an additional axiom for\nDefinition \\ref{serre-class}:\n\\begin{enumerate}\n\t\\setcounter{enumi}{1}\n    \\item if $A,B\\in\\cC$, then so are $A\\otimes B$ and $\\Tor_1(A,B)$.\n\\end{enumerate}\nAll of the examples given above satisfy this additional axiom.\n\\begin{terminology}\n    $f:A\\to B$ is said to be a $\\cC$-epimorphism if $\\coker f\\in \\cC$, a\n    $\\cC$-monomorphism if $\\ker f\\in\\cC$, and a $\\cC$-isomorphism if it is a\n    $\\cC$-epimorphism and a $\\cC$-monomorphism.\n\\end{terminology}\n\\begin{prop}\n    Let $\\pi:E\\to B$ be a fibration and $B$ path connected, such that the fiber\n    $F = \\pi^{-1}(\\ast)$ is path connected. Suppose $\\pi_1(B)$ acts trivially\n    on $H_\\ast(F)$.\n\n    Let $\\cC$ be a Serre class satisfiying Axiom 2. Let $s\\geq 3$, and assume\n    that $H_n(E)\\in\\cC$ where $1\\leq n<s-1$ and $H_t(B)\\in \\cC$ for $1\\leq\n    t<s$. Then $H_t(F)\\in\\cC$ for $1\\leq t<s-1$.\n\\end{prop}\n\\begin{proof}\n    We will do the case $s=3$, for starters.\n    We're gonna want to relate the low-dimension homology of these groups.\n    What can I say?\n    We know that $H_0(E) = \\Z$ since it's connected.\n    I have $H_1(E)\\to H_1(B)$, via $\\pi$.\n    This is one of the edge homomorphisms, and thus it surjects (no possibility for a differential coming in).\n    I now have a map $H_1(F)\\to H_1(E)$.\n    But I have a possible $d^2:H_2(B)\\to H_1(F)$, which is a transgression that gives:\n    $$\n    H_2(B)\\xrightarrow{\\partial} H_1(F)\\to H_1(E)\\to H_1(B)\\to 0\n    $$\n    \n    Let me take a step back and say something general.\n    You might be interested in knowing when something in $H_n(F)$ maps to zero in $H_n(E)$.\n    I.e., what's the kernel of $H_n(F)\\to H_n(E)$.\n    The sseq gives an obstruction to being an isomorphism.\n    The only way that something can be killed by $H_n(F)\\to H_n(E)$ is described by:\n    $$\n    \\ker(H_n(F)\\to H_n(E)) = \\bigcup\\left(\\img \\text{ of }d^r\\text{ hitting }E^r_{0,n}\\right)\n    $$\n    You can also say what the cokernel is:\n    it's whatever's left in $E^\\infty_{s,t}$ with $s+t = n$.\n    These obstruct $H_n(F)\\to H_n(E)$ from being surjective.\n    \n    In the same way, I can do this for the base.\n    If I have a class in $H_n(E)$, that maps to $H_n(B)$, the question is: what's the image?\n    Well, the only obstruction is the possibility is that the element in $H_n(B)$ supports a nonzero differential.\n    Thus:\n    $$\n    \\img(H_n(E)\\xrightarrow{\\pi_\\ast} H_n(B)) = \\bigcap\\left(\\ker(d^r:E^r_{r,0}\\to\\cdots)\\right)\n    $$\n    Again, you can think of the sseq as giving obstructions.\n    And also, the obstruction to that map being a monomorphism that might occur in lower filtration along the same total degree line.\n\n    Back to our argument.\n    We had the low-dimensional exact sequence:\n    $$\n    H_2(B)\\xrightarrow{\\partial} H_1(F)\\to H_1(E)\\to H_1(B)\\to 0\n    $$\n    Here $p=3$, so we have $H_2(B)\\in\\cC$ and $H_1(E)\\in\\cC$.\n    Thus $H_1(F)\\in\\cC$.\n    That's the only thing to check when $p=3$.\n\n    Let's do one more case of this induction.\n    What does this say?\n    Now I'll do $p=4$.\n    We're interested in knowing if $E^2_{0,3}\\in\\cC$.\n    There are now two possible differentials!\n    I have $H_2(F) = E^2_{0,2}\\fib E^3_{0,2}$.\n    This quotient comes from $d^2:E^2_{2,1}\\to E^2_{0,2}$.\n    Now, $d^3:E^3_{3,0}\\to E^3_{0,2}$ which gives a surjection $E^3_{0,2}\\fib E^4_{0,2}\\simeq E^\\infty_{0,2}\\hookrightarrow H_2(E)$.\n    Now, our assumptions were that $E^2_{2,1},E^3_{3,0},H_2(E)\\in\\cC$.\n    Thus $E^3_{0,2}\\in\\cC$ and so $E^2_{0,2} = H_2(F)\\in\\cC$.\n    Ta-da!\n\\end{proof}\nWe're close to doing actual calculations, but I have to talk about the multiplicative structure on the Serre sseq first.\n", "meta": {"hexsha": "766cffaefbff9da0a792c9d705be65b9607102f9", "size": 7260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-65-serre-classes.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-65-serre-classes.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-65-serre-classes.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 47.4509803922, "max_line_length": 138, "alphanum_fraction": 0.6380165289, "num_tokens": 2649, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8856314768368161, "lm_q1q2_score": 0.7843430993971972}}
{"text": "\\subsection{Stratified sampling and analysis}\nStratified sampling  \\cite{bickel1984asymptotic} gives a more refined version of the Monte Carlo method. \n\n\\begin{lemma} \\label{lem:stratified}\n For any\n  nonoverlaping decomposition $G=G_1\\cup G_2\\cup \\cdots \\cup G_M$ and\n  positive integer $n$, let $n_i=\\lceil \\lambda(G_i)n\\rceil$ be the smallest integer larger than $\\lambda(G_i)n$ and $\\displaystyle N=\\sum_{i=1}^M n_i$.  Let $\\theta_{i,j}\\in G_i (1\\le j\\le n_i)$ and \n\\begin{equation}\ng_n=\\sum_{i=1}^M \\lambda(G_i)g_{n_i}^i \\quad \\mbox{with}\\quad g_{n_i}^i={1 \\over n_i}\\sum_{j=1}^{n_i} g(\\theta_{i,j}).\n\\end{equation} \nIt holds that  \n\\begin{equation}\n\\mathbb{E}_N(\\mathbb{E}_G g -g_N)^2=\\sum_{i=1}^M {\\lambda^2(G_i) \\over n_i} \\mathbb{E}_{G_i}\\big (g -\\mathbb{E}_{G_i}g\\big )^2\n\\le {1 \\over n} \\max_{1\\le i\\le M}\\sup_{\\theta, \\theta'\\in G_i}\\big |g(\\theta) - g(\\theta')\\big |^2.\n\\end{equation}\n\\end{lemma} \n\n\\begin{proof}%[Proof of Lemma \\ref{lem:stratified}]\nIt follows from definition that\n\\begin{equation}\ng(x, \\theta) = \\sum_{i=1}^M \\lambda(G_i) g(x, \\theta),\\qquad \\mathbb{E}_G g =\\sum_{i=1}^M\\lambda(G_i) \\int_{G_i} g\\lambda_i(\\theta)d\\theta = \\sum_{i=1}^M \\lambda(G_i) \\mathbb{E}_{G_i}g.\n\\end{equation}\nThus, the difference $g - \\mathbb{E}_G g$ is a linear combination of $g -\\mathbb{E}_{G_i}g$ on each $G_i$ as follows\n\\begin{equation}\ng - \\mathbb{E}_G g = \\sum_{i=1}^M \\lambda(G_i) \\big (g -\\mathbb{E}_{G_i}g\\big ).\n\\end{equation}\nIt follows from \n\\begin{equation}\n\\mathbb{E}_G g-g_n=\\sum_{i=1}^M \\lambda(G_i) (\\mathbb{E}_{G_i}g -  g^i_{ n_i})\n\\end{equation}\nand \\eqref{En} that\n\\begin{equation} \n\\mathbb{E}_n(\\mathbb{E}_G g -g_n)^2 =\\sum_{i,j=1}^M \\lambda(G_i) \\lambda(G_j) \\mathbb{E}_n \\big ((\\mathbb{E}_{G_i}g -  g^i_{ n_i})(\\mathbb{E}_{G_j}g -  g^j_{ n_j})\\big )\n=\\sum_{i,j=1}^M \\lambda(G_i) \\lambda(G_j) I_{ij}  \n\\end{equation}\nwith \n$$\nI_{ij} = \\mathbb{E}_n \\big ((\\mathbb{E}_{G_i}g -  g^i_{ n_i})(\\mathbb{E}_{G_j}g -  g^j_{ n_j})\\big ).\n$$\n\\iffalse\nIf $i\\neq j$,\n\\begin{equation}\\label{eq:Iij}\n\\begin{split}\nI_{ij}=&\\int_{G\\times \\cdots\\times G} (\\mathbb{E}_{G_i}g -  g^i_{ n_i})(\\mathbb{E}_{G_j}g -  g^j_{ n_j})\\lambda(\\theta_{i,n_1})\\cdots\\lambda(\\theta_{i,n_i})\\lambda(\\theta_{j,1})\\cdots \\lambda(\\theta_{j,n_j})d\\theta_{i,1}\\cdots d\\theta_{i,n_i}d\\theta_{j,1}\\cdots d\\theta_{j,n_j}\n\\\\\n=&\\int_{G\\times \\cdots\\times G} (\\mathbb{E}_{G_i}g -  g^i_{ n_i})\\lambda(\\theta_{i,n_1})\\cdots\\lambda(\\theta_{i,n_i})d\\theta_{i,1}\\cdots d\\theta_{i,n_i}\n\\\\\n&+\n\\int_{G\\times \\cdots\\times G} (\\mathbb{E}_{G_i}g -  g^j_{ n_j})\\lambda(\\theta_{j,1})\\cdots \\lambda(\\theta_{j,n_j})d\\theta_{j,1}\\cdots d\\theta_{j,n_j}\n\\\\\n=&\\lambda^{n_i}(G_i)\\int_{G_i\\times \\cdots\\times G_i} (\\mathbb{E}_{G_i}g -  g^i_{ n_i})\\lambda_i(\\theta_{i,n_1})\\cdots\\lambda_i(\\theta_{i,n_i})d\\theta_{i,1}\\cdots d\\theta_{i,n_i}\n\\\\\n&+\n\\lambda^{n_j}(G_j)\\int_{G\\times \\cdots\\times G} (\\mathbb{E}_{G_i}g -  g^j_{ n_j})\\lambda_j(\\theta_{j,1})\\cdots \\lambda_j(\\theta_{j,n_j})d\\theta_{j,1}\\cdots d\\theta_{j,n_j}\n\\\\\n=&0.\n\\end{split}\n\\end{equation}\n\\fi\nBy Lemma \\ref{MC},\n\\begin{equation}\nI_{ij} =  \\mathbb{E}_n \\big ((\\mathbb{E}_{G_i}g -  g^i_{ n_i})^2\\big )\\delta_{ij}= {1\\over n_i} \\mathbb{E} \\big ((\\mathbb{E}_{G_i}g -  g)^2\\big )\\delta_{ij}.\n\\end{equation}\nThus,\n\\begin{equation} \n\\mathbb{E}_n(\\mathbb{E}_G g -g_n)^2 =\\sum_{i=1}^M {\\lambda^2(G_i) \\over n_i} \\mathbb{E}_{G_i}\\big (g -\\mathbb{E}_{G_i}g\\big )^2, \n\\end{equation}\nwhich completes the proof.\n\\end{proof} \n\nLemma \\ref{MC} and Lemma \\ref{lem:stratified} represent two simple identities and subsequent inequalities that can be verified by a direct calculation. Actually Lemma \\ref{MC} is a special case of Lemma  \\ref{lem:stratified} with $M=1$. Lemma \\ref{MC} and Lemma \\ref{lem:stratified} are the basis of Monte-Carlo sampling and  stratified sampling in statistics. \n\n\\begin{lemma}\\label{lem:stratifiedapprox}\n\\textup{[Stratified Sampling]}\n\tFor $u(x)$ in \\eqref{uint}\n\twith positive $\\rho(\\theta)\\in L^1(G)$, given any positive integers $n$ and $M\\le n$, for  any nonoverlaping decomposition $G=G_1\\cup G_2\\cup \\cdots \\cup G_M$, there exists$\\{\\theta_i^\\ast\\}_{i=1}^N$ with $n\\le N \\le 2n$ such that\n\t\\begin{equation} \n\t\\|u - u_N\\|_{L^2(\\Omega)} \\leq N^{-1/2}\\|\\rho\\|_{L^1(G)}\\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\t\\end{equation}\n\twhere \n\t$$\n\tu_N(x)= {2\\|\\rho\\|_{L^1(G)}\\over N}\\sum_{i=1}^N\\beta_i g(x,\\theta_i^\\ast)\n\t$$ \n\tand $\\beta_i\\in [0,1]$.\n\t\\end{lemma}\n\n\\begin{proof}\nLet $n_j=\\lceil \\lambda(G_j)n\\rceil$ and $\\theta_{i,j} \\in G_j(1\\leq i\\leq n_j)$. Define $\\displaystyle N=\\sum_{j=1}^M n_j$ and\n$$\nu_N(x)=\\|\\rho\\|_{L^1(G)}\\sum_{i=1}^M \\lambda(G_i)g_{n_i}^i \\quad \\mbox{with}\\quad g_{n_i}^i={1 \\over n_i}\\sum_{j=1}^{n_i} g(\\theta_{i,j}).\n$$\nSince\n$\n\\displaystyle u(x)=\\|\\rho\\|_{L^1(G)}\\sum_{i=1}^M \\lambda(G_i)\\mathbb{E}_{G_i} g,\n$\nby Lemma \\ref{MC},\n\\begin{equation}\n\\begin{split}\n\\mathbb{E}_N\\|u- u_N \\|_{L^2(\\Omega)}^2=& \\|\\rho\\|_{L^1(G)}^2\n \\sum_{j=1}^{M}{\\lambda^2(G_j) \\over n_j}\\mathbb{E}_{G_j}\\|\\mathbb{E}_{G_j} g -  g\\|^2_{L^2(\\Omega)}\n\\\\\n\\le &\\|\\rho\\|_{L^1(G)}^2 \\sum_{j=1}^{M} {\\lambda^2(G_j)\\over n_j}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\| g(x,\\theta_j) - g(x,\\theta_j')\\|^2_{L^2(\\Omega)}.\n\\end{split}\n\\end{equation} \nSince ${\\lambda(G_j)\\over n_j}\\le {1\\over n}$ and $\\displaystyle \\sum_{j=1}^M \\lambda(G_j)=1$,\n\\begin{equation}\n\\mathbb{E}_N\\|u - u_N \\|_{L^2(\\Omega)}^2\\leq n^{-1}\\|\\rho\\|_{L^1(G)}^2\\max_{1\\le j\\le M}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\| g(x,\\theta_j) - g(x,\\theta_j')\\|^2_{L^2(\\Omega)}.\n\\end{equation}\nThere exist $\\{\\theta_{i,j}^\\ast\\}$ such that $\\theta_{i,j}^\\ast\\in G_i$ and \n\\begin{equation}\n\\| u-u_N \\|_{L^2(\\Omega)}^2\\leq n^{-1} \\|\\rho\\|_{L^1(G)}^2\\max_{1\\le j\\le M}\\sup_{\\theta_{j},\\theta_{j}'\\in G_j} \\| g(x,\\theta_j) - g(x,\\theta_j')\\|^2_{L^2(\\Omega)}.\n\\end{equation}\nNote that $n\\le N\\le n+M\\le 2n$,\n$$\nu_N(x) =  {2\\|\\rho\\|_{L^1(G)}\\over N}\\sum_{j=1}^{M}\\frac{N\\lambda(G_j)}{2n_j}\\sum_{i=1}^{n_j} g(x,\\theta_{i,j}^\\ast)\n =  {2\\|\\rho\\|_{L^1(G)}\\over N}\\sum_{j=1}^{M}\\beta_{i,j}\\sum_{i=1}^{n_j} g(x,\\theta_{i,j}^\\ast)\n$$ \nwith\n\\begin{equation}\n\\beta_{i,j}= \\frac{N\\lambda(G_j)}{2n_j}\\le \\frac{2\\lambda(G_j)n}{2\\lambda(G_j)n}\\le 1,\n\\end{equation}\nwhich completes the proof. \n\\end{proof} \n\n\n", "meta": {"hexsha": "e94b661d166394bbaf41ffeb12dd21b8b9ae7186", "size": 6239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MonteCarlo.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/MonteCarlo.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/MonteCarlo.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.5158730159, "max_line_length": 361, "alphanum_fraction": 0.6369610515, "num_tokens": 2832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7843020009329161}}
{"text": "\\subsection{Cross-Validation Criterion}\nThere are several popular information criteria for model selection: for example, Akaike information criterion (\\textbf{AIC}), corrected AIC (\\textbf{AIC\\textsuperscript{c}}), Schwarz Bayesian information criterion (\\textbf{SIC}), Hannan-Quinn (\\textbf{HQ}) and Mallows' C\\textsubscript{p} (\\textbf{C\\textsubscript{p}}). Most criteria have two components in their formulas: the first part measures model fit while the second penalizes overfitting. The quantity measuring in-sample fit are the same for most criteria, but they differ in the degree of penalization. For instance, AIC penalizes each additional parameter by $2$ while SIC penalizes overfitting by the logarithm of sample size, so SIC tends to select a more parsimonious model than AIC if the sample size is large.\n\nFor the forecasting analysis, what we care about is the test error rate assessing the model predictive ability, not the training error rate produced in the model estimation stage, so selecting a information criterion which gives a good estimate of the expected test error rate is crucial. Cross-validation is such a criterion. Specifically, we focus on the use of leave-one-out cross-validation for this paper, though other CV variants, such as K--fold cross-validation, may be considered. Cross-validation is computationally simple for one-step ahead predictive model selection and is shown robust to conditional heteroscedasticity in the econometrics and statistics literature. For forecast combination, researchers have applied CV to the quadratic programming based model averaging analysis, but its setting does not include structural break.\n\nThe sample leave-one-out cross-validation criterion can be computed by the following procedure:\n\\begin{equation} \\label{cv}\n\tCV_T(k) = \\frac{1}{T}\\sum_{t=1}^{T}\\tilde{e}_{t}(k)^{2}\n\\end{equation}\nwhere $\\tilde{e}_{t}(k) = y_t - \\tilde{\\beta}_{-t}(k)'x_t(k)$ are the residuals from the regression with the $t^{\\mathrm{th}}$ observation dropped and $\\tilde{\\beta}_{-t}(k) = (\\sum_{i\\not= t}x_i(k) x_i(k)')^{-1}(\\sum_{i\\not= t}x_i(k) y_i)$ is the associated vector of parameter estimates. Intuitively, this procedure is trying to estimate the expected test error rate based on the model training data. Though equation~\\ref{cv} implies that we need to run regression $T$ times for given sample size $T$, luckily, for linear models, we can calculate sample CV value by running regression only once. Formally, the leave-one-out cross validation residuals can be computed from the full sample least squares residuals, $\\tilde{e_{t}} = \\frac{\\hat{e_{t}}}{1 - h_{t}}$, where $h_{t} = x_{t}'(X_{t}'X_{t})^{-1}x_{t}$ is the leverage associated with observation $t$, $\\hat{e_{t}}$ is the full sample least squares residual and $\\tilde{e_{t}}$ is the cross-validation residual. So we can rewrite equation~\\ref{cv} as\n\\begin{equation}\n    CV_T(k) = \\frac{1}{T}\\sum_{t=1}^{T}\\left( \\frac{\\hat{e_{t}}(k)}{1 - h_{t}} \\right)^{2}\n\\end{equation}\nIn the next section we are going to show how model averaging weights are derived from the cross-validation criterion.", "meta": {"hexsha": "c044cc0fd8284bffcd379d5ec26ec43d59f4d46e", "size": 3108, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/theory_2_CV.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/theory_2_CV.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/theory_2_CV.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": 222.0, "max_line_length": 1007, "alphanum_fraction": 0.7664092664, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853655, "lm_q2_score": 0.8824278788223265, "lm_q1q2_score": 0.7842655421263057}}
{"text": "\\section{Integrating Factor Method}\r\nAll 1st order linear differential equations have the form\r\n\\begin{equation*}\r\n\ta_1(x)\\dd{y}{x} + a_0(x)y = b_1(x)\r\n\\end{equation*}\r\nwhich can be rewritten as\r\n\\begin{equation*}\r\n\t\\dd{y}{x} + a(x)y = b(x)\r\n\\end{equation*}\r\n\r\n\\noindent\r\nThis equation isn't always separable, and we can't just integrate both sides unless $a_1(x)y$ = 0.\\\\\r\n\r\n\\noindent\r\nIf $a_0(x) = a_1'(x)$, then we could rewrite the equation and solve by doing the product rule in reverse.\r\n\\begin{equation*}\r\n\t\\left(a_1(x)y\\right)' = b_1(x) \\implies y = \\frac{\\int{b_1(x) \\mathrm{d}x}}{a_1(x)}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nIt's possible to rearrange into this form by multiplying the equation by some function. Specifically, what were looking for is a function $\\mu(x)$ such that\r\n\\begin{equation*}\r\n\t\\mu(x)\\dd{y}{x} + \\mu(x)a(x)y = \\mu(x)b(x) \\text{ and } \\mu'(x) = \\mu(x)a(x)\r\n\\end{equation*}\r\nThis equation involving $\\mu(x)$ is one that we know how to solve because it's separable.\\footnote{Although we are taking an indefinite integral to find $\\mu(x)$, we do not have a $+ C$ term.}\r\n\\begin{equation*}\r\n\t\\mu'(x) = \\mu(x)a(x) \\implies \\mu(x) = e^{\\int{a(x) \\mathrm{d}x}}\r\n\\end{equation*}\r\nSubstituting the solution for $\\mu(x)$ back,\r\n\\begin{equation*}\r\n\te^{\\int{a(x) \\mathrm{d}x}}\\dd{y}{x} + e^{\\int{a(x) \\mathrm{d}x}}a(x)y = e^{\\int{a(x) \\mathrm{d}x}}b(x) \\implies e^{\\int{a(x) \\mathrm{d}x}}\\dd{y}{x} + \\mu'(x)y = e^{\\int{a(x) \\mathrm{d}x}}b(x)\r\n\\end{equation*}\r\nApplying the product rule in reverse,\r\n\\begin{equation*}\r\n\ty = \\frac{\\int{\\mu(x)} b(x) \\mathrm{d}x}{\\mu(x)} \\text{, } \\mu(x) = e^{\\int{a(x) \\mathrm{d}x}}\r\n\\end{equation*}\r\n\r\n%\\noindent\r\n%This method gives us a way to solve all first-order linear ODE's.\r\n\r\n\\ifodd\\includeFirstOrderLinearODEExamples\\input{./1stOrderLinearODE/integratingFactor/integratingFactor_example.tex}\\fi", "meta": {"hexsha": "fe453d0331ed1e6dd6c9d09287d3d99418fb494f", "size": 1851, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/1stOrderLinearODE/integratingFactor/integratingFactor.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/1stOrderLinearODE/integratingFactor/integratingFactor.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/1stOrderLinearODE/integratingFactor/integratingFactor.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.1463414634, "max_line_length": 193, "alphanum_fraction": 0.6591031875, "num_tokens": 676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.7841685515159748}}
{"text": "\\subsection{SVD as a geometrical interpretation}\n\nAnd what was the advantage of the factorization then? In simple terms,\ndecomposing the function behind matrix $A$, as a sequence of three\nsimpler (easier to understand) transformations. Here the geometric\ninterpretation helps to complete the picture, as orthogonal (change of\nbasis) matrices do represent rigid transformation in space, that is,\nthey do not alter the lengths of vectors (hence, preserve\nshapes). Strictly speaking, orthogonal matrices can be decomposed as a\nrotation and a reflection; but for geometric intuition, is often\ndesirable to think in the rotation part only. \\\\\n\nOn the other hand, diagonal matrices are the simplest transformation\npossible, they do not change the basis but just expand or contract the\ncoordinates along the axis given by the basis. Again, if we consider\nthe generic case of diagonal matrices, a negative element $D_{ii}$\nwould additional provoke a reflection in the axis $i$; but since the\nSVD decomposition produces only positive elements on the diagonal, we\nignore this case and just think in terms of contractions or\nexpansions along the axes. \\\\\n\nArmed with this geometrical insight, we can enhance our understanding\nof the action of $A$ through the SVD decomposition, by associating to\nthe simpler operations the corresponding geometrical transformations.\nThe geometric visualization usually requires a couple of\nsimplifications: first of all, the dimensions of domain and codomain\nmust be reduced; as it is easier to visualize things in \\R{2} or\n\\R{3}, than in an arbitrary \\R{n}. Given two dimensions fit well in a\nscreen, let us pick $\\R{n} = \\R{m} = \\R{2}$. \\\\\n\nSecondly, we need to focus our attention in an specific set of\npoints (as visualizing the effect of a linear transformation against\n``all'' vectors in space, even for \\R{2}, is a quite abstract and\ncomplex task). The usual procedure is to pick the vectors in the\nunitary sphere in \\R{2} (which contains in particular the columns of\n$V$, as they are unit orthogonal vectors). \\\\\n\nLet us proceed now: let the matrix $A$ be of\ndimensions $2  \\times 2$, the matrices $V$ and $U$ be formed\nby unit column vectors $\\{\\vec{v_1},\\vec{v_2}\\}$ and $\\{\\vec{u_1},\\vec{u_2}\\}$,\nrespectively; and let matrix $\\Sigma$ be $diag(\\sigma_1,\\sigma_2)$\nsuch that $\\sigma_1 > \\sigma_2 > 0$. We will additionally assume that\n$\\sigma_1 > 1$ and $\\sigma_2 < 1$, in order to allow them represent an\nexpansion and contraction, respectively. The previously described steps of\nthe SVD factorization, can be now augmented with the corresponding\ngeometrical transformations: \\\\\n\n\\begin{enumerate}\n\\item Start with unit sphere in \\R{2}, with the unit vectors \\vec{v_1}\n  and \\vec{v_2} living inside of it. \n\\item Action of \\trans{V}: Rotate the space such that \\vec{v_1} and\n  \\vec{v_2} become the new orthogonal basis (this transformation\n  leaves the shape of the sphere intact).\n\\item Action of $\\Sigma$: Once rotated, the unit sphere is expanded\n  in the direction of \\vec{v_1} (per $\\sigma_1$), and contracted in the\n  direction of \\vec{v_2} (per $\\sigma_2$). \n\\item Action of $U$: Once reshaped, the resulting ellipse is taken\n  from the basis $\\{u_1,u_2\\}$ back to the canonical basis (this\n  transformation changes the orientation of the ellipse, given that\n  is not a symmetric figure; but still it preserves it shape).\n\\end{enumerate}\n\\hfill\n\nThese steps can be summarized in the following figure \\footnote{Which\n  was taken from a \\href{http://math.stackexchange.com/questions/243811/visualization-of-singular-value-decomposition-of-a-symmetric-matrix}{MathStackExchange phorum post}, we\n  could not locate back the original source though.}: \\\\\n\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[width=15cm]{svd-geo-diag}\n  \\caption{Geometrical interpretation of $A = U \\Sigma \\trans{V}$,\n    over the unit sphere.}\n  \\label{fig:svd-geo-diag}\n\\end{figure}\n\\hfill\n", "meta": {"hexsha": "fcfc55eb2b9d0026df4cb89592e1ea4205c39b0e", "size": 3907, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-intuit-geoin.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-intuit-geoin.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-intuit-geoin.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": 51.4078947368, "max_line_length": 175, "alphanum_fraction": 0.7635014077, "num_tokens": 1018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511506439707, "lm_q2_score": 0.9161096216057903, "lm_q1q2_score": 0.7840534737673283}}
{"text": "\\subsection{From Langevin dynamics to Fokker-Planck equation}\n\nNow that we built a description for the probability distribution over the\nensemble of trajectories that a Markovian stochastic process can follow we are\nleft with the task of how to define the Fokker-Plank equation coefficients from\nthe stochastic dynamics defined by the Langevin equation. Specifically in its\nmore general form we derived \\eref{eq_fokker_planck} to depend on three things:\nthe probability distribution of allele frequencies $P(f, t)$, and the two jump\nmoments $a^{(1)}(f, t)$ and $a^{(2)}(f, t)$, where these moments are given by\n\\eref{eq_jump_mom}. A lot of the population genetics literature use a\nnon-mathematical argument to directly assign the values of these coefficients\ngiven the either deterministic or stochastic nature of the terms. For example,\ngiven the dynamics that we defined in \\secref{seq_determ_mut} for the\ndeterministic form of mutation and selection (\\eref{eq_sel_mut}) most texts\nwould directly assign these dynamics to be the first jump moment\n$a^{(1)}(f,t)$. There is nothing intrinsically wrong with this approach, since\nthis is actually the correct answer, but it is not necessarily obvious that\nthis should be the case especially since \\eref{eq_fokker_planck} requires us to\ntake a derivative with respect to $x$ of this coefficient multiplied by the\nallele frequency distribution.\n\nWe will take a more formal approach and find how the terms in the Langevin\ndynamics that we defined in \\secref{sec_langevin_intro} connect to the\ncoefficients of the Fokker-Planck equation. To do so first we introduce a\nquantity defined as\n\\begin{equation}\n    \\mathcal{A}^{(m)}(x; \\tau, t) \\equiv \\int_{-\\infty}^\\infty dx\\;\n    (x - x')^m P(x, t + \\tau \\mid x', t), \\; \\text{for } m \\geq 1.\n    \\label{eq_compute_jump_mom}\n\\end{equation}\nThis is nothing else than the average of $[x(t + \\tau) - x(t)]^m$ with a sharp\ninitial condition $x(t) = x'$ for a Markov process that obeys the transition\nprobability distribution $P(x, t + \\tau \\mid x', t)$. Given that our Langevin\ndynamics are Markov processes, the ensemble of trajectories must obey a\ncontinuous master equation with such transition probability. Therefore\n\\eref{eq_compute_jump_mom} can be thought as the average displacement between\ntwo time points $t$ and $t + \\tau$ for our Langevin dynamics. In other words\n$\\mathcal{A}^{(m)}(x; \\tau, t)$ can be expressed as\n\\begin{equation}\n    \\mathcal{A}^{(m)}(x; \\tau, t) \\equiv \n    \\ee{\\left[x(t + \\tau) - x(t)\\right]^m \\mid x(t) = x'}.\n    \\label{eq_average_A}\n\\end{equation}\nJust as we did to derive the master equation, for small $\\tau$ we can rewrite\nthe conditional distribution $P(x, t + \\tau \\mid x', t)$ using\n\\eref{eq_transition_short_time}. Using this we can rewrite\n\\eref{eq_compute_jump_mom} as\n\\begin{equation}\n    \\mathcal{A}^{(m)}(x; \\tau, t) = \\int_{-\\infty}^\\infty dx\\; (x - x')^m\n    \\underbrace{\n    \\left[ \\delta(x - x') \\left( 1 - a^{(0)}(x', t) \\tau \\right) +\n    \\phi_t(x \\mid x')\\tau \\right]\n    }_{P(x, t + \\tau \\mid x', t)}.\n\\end{equation}\nDistributing the integrals results in\n\\begin{equation}\n    \\begin{aligned}\n    \\mathcal{A}^{(m)}(x; \\tau, t) &= \n    \\int_{-\\infty}^\\infty dx\\; (x - x')^m \\delta(x - x') \\\\\n    &- \\int_{-\\infty}^\\infty dx\\; (x - x')^m \\delta(x - x') a^{(0)}(x', t) \n    \\tau \\\\ \n    &+ \\int_{-\\infty}^\\infty dx\\; (x - x')^m \\phi_t(x \\mid x') \\tau.\n    \\end{aligned}\n\\end{equation}\nFor the first two terms we have that the $\\delta$-function is one only when $x\n= x'$ while the term $(x - x')^m$ is zero for this particular case. Therefore\nboth of these terms cancel and we are only left with\n\\begin{equation}\n    \\mathcal{A}^{(m)}(x; \\tau, t) = \\int_{-\\infty}^\\infty dx\\; (x - x')^m \n    \\phi_t(x \\mid x') \\tau.\n\\end{equation}\nThis is non other than the definition of the jump moments times $\\tau$ given by\n\\eref{eq_jump_mom} since we defined $r \\equiv x - x'$ and $\\phi_t(x'; r) \\equiv\n\\phi_t(x \\mid x')$. Now we can see the connection; we started defining\n$\\mathcal{A}^{(m)}(x; \\tau, t)$ to be the average displacement defined by our\nLangevin dynamics over a small time interval $\\tau$, and we found that this is\nconnected to the jump moments that define the coefficients of the Fokker-Planck\nequation. So we have that\n\\begin{equation}\n    \\mathcal{A}^{(m)}(x; \\tau, t) = \\tau \\cdot a^{(m)}(x, t).\n\\end{equation}\nGiven this result we can compute the jump moment by taking the derivative of\n$\\mathcal{A}^{(m)}$ with respect to $\\tau$ and evaluating this derivative at\n$\\tau = 0$. This is\n\\begin{equation}\n    a^{(m)}(x, t) = \\left. {\\partial \\over \\partial \\tau} \n    \\mathcal{A}^{(m)}(x; \\tau, t) \\right\\vert_{\\tau = 0}.\n    \\label{eq_A_tau_deriv}\n\\end{equation}\nThe reason we evaluate $\\tau = 0$ is for convenience. In principle we could\nevaluate the derivative for any value of $\\tau$ since $a^{(m)}$ does not depend\non $\\tau$, but zero is the one that simplifies things the most. Using the\ndefinition of derivatives we then write \\eref{eq_A_tau_deriv} as\n\\begin{equation}\n    a^{(m)}(x, t) = \\lim_{\\Dt \\rightarrow 0}\n    \\left.{\\mathcal{A}^{(m)}(x, \\tau + \\Dt, t) - \n    \\mathcal{A}^{(m)}(x, \\tau, t) \\over \\Dt} \\right\\vert_{\\tau = 0}.\n\\end{equation}\nIf we now substitute the equivalence of $\\mathcal{A}^{(m)}$ with the average\ndisplacement on our Langevin dynamics, i.e. \\eref{eq_average_A} we obtain\n\\footnotesize\n\\begin{equation}\n    a^{(m)}(x, t) = \\lim_{\\Dt \\rightarrow 0} {1 \\over \\Dt}\n    \\left[\n    \\ee{\\left[x(t + \\tau + \\Dt) - x(t)\\right]^m \\mid x(t) = x'} -\n    \\ee{\\left[x(t + \\tau) - x(t)\\right]^m \\mid x(t) = x'}\n    \\right]_{\\tau = 0}.\n    \\label{eq_deriv_average}\n\\end{equation}\n\\normalsize\nNow we use the condition $\\tau = 0$ that we chose for simplification since the\nsecond term in \\eref{eq_deriv_average} cancels. We are then left with a simple\nexpression of the form\n\\begin{equation}\n    a^{(m)}(x, t) = \\lim_{\\Dt \\rightarrow 0}\n    {\\ee{\\left[x(t + \\Dt) - x(t)\\right]^m \\mid x(t) = x'} \\over \\Dt}.\n\\end{equation}\nThis result shows that given that our Langevin dynamics are a continuous Markov\nprocess, we can compute the displacement dynamics for a small time interval,\nelevate it to the $m\\tth$ power, and then average it, to then compute the $m$\ncoefficient for the Fokker-Planck equation. Let's do this first for the first\ncoefficient $a^{(m)}(x, t)$.\n\n\\subsubsection{Directional coefficient of the Fokker-Planck equation}\n\nFor the first coefficient of the Fokker-Planck equation that defines the\ndirectional terms of the dynamics we have\n\\begin{equation}\n    a^{(1)}(x, t) = \\lim_{\\Dt \\rightarrow 0}\n    {\\ee{x(t + \\Dt) - x(t) \\mid x(t) = x'} \\over \\Dt}.\n\\end{equation}\nRecall that we defined the Langevin equations as a stochastic differential\nequation given in \\eref{eq_langevin}. Since $x(t)$ is the solution to this\ndifferential equation we can use the fundamental theorem of calculus to rewrite\nthe average displacement as\n\\begin{equation}\n    \\ee{x(t + \\Dt) - x(t) \\mid x(t) = x'} =\n    \\ee{\\left. \\int_t^{t + \\Dt} dt'\\; {dx \\over dt'} \\right\\vert x(t) = x'}.\n\\end{equation}\nWe then substitute \\eref{eq_langevin} on the right-hand side to obtain\n\\begin{equation}\n    \\ee{x(t + \\Dt) - x(t) \\mid x(t) = x'} =\n    \\ee{\\left.\\int_t^{t + \\Dt} dt'\\; A(x, t') + B(x, t') \\xi(t')\\right\\vert \n    x(t) = x'}.\n\\end{equation}\nIf we distribute the integral and use the linearity of expected values this\nresults in\n\\begin{equation}\n    \\ee{x(t + \\Dt) - x(t) \\mid x(t) = x'} =\n    \\int_t^{t + \\Dt} dt\\; A(x, t') + \n    \\int_t^{t + \\Dt} dt\\; B(x, t') \\ee{ \\left.\\xi(t') \\right\\vert x(t) = x'},\n\\end{equation}\nwhere the only thing we needed to average over was the noise term $\\xi(t)$. For\nthe Langevin equation we defined the average of this noise term to be zero\nregardless of the initial position; that implies that the average displacement\nis then simply given by\n\\begin{equation}\n    \\ee{x(t + \\Dt) - x(t) \\mid x(t) = x'} =\n    \\int_t^{t + \\Dt} A(x, t').\n\\end{equation}\nAs a consequence the directional coefficient of the Langevin equation is then\nof the form\n\\begin{equation}\n    a^{(1)}(x, t) = \\lim_{\\Dt \\rightarrow 0} {1 \\over \\Dt}\n    \\int_t^{t + \\Dt} A(x, t').\n\\end{equation}\nSince we are taking the limit when $\\Dt \\rightarrow 0$ we can approximate the\nintegral simply as\n\\begin{equation}\n    a^{(1)}(x, t) \\approx \\lim_{\\Dt \\rightarrow 0}{1 \\over \\Dt} [A(x, t) \\Dt] =\n    A(x, t).\n    \\label{eq_approx_int_directional}\n\\end{equation}\nWe therefore mathematically justify the empirical argument commonly found in\nthe literature that the directional term associated with the Langevin equation\ncan be directly associated with the directional term of the Fokker-Planck\nequation. In other words we showed that\n\\begin{equation}\n    a^{(1)}(x, t) = A(x, t).\n\\end{equation}\n\n\\subsubsection{Diffusive coefficient of the Fokker-Planck equation}\n\nTo compute the second coefficient of the Fokker-Planck equation associated with\nthe diffusive random displacements we can follow the exact same recipe. First\nwe know that this coefficient is given by\n\\begin{equation}\n    a^{(2)}(x, t) = \\lim_{\\Dt \\rightarrow 0}\n    {\\ee{\\left[x(t + \\Dt) - x(t)\\right]^2 \\mid x(t) = x'} \\over \\Dt}.\n\\end{equation}\nAgain using the fundamental theorem of calculus gives us\n\\begin{equation}\n    a^{(2)}(x, t) = \\lim_{\\Dt \\rightarrow 0}\n    {\\ee{ \\left. \\left[ \n    \\int_t^{t + \\Dt} dt'\\; {dx \\over dt'}\n    \\right]^2 \\right\\vert x(t) = x'} \\over \\Dt}.\n    \\label{eq_diffusive_fp_lim}\n\\end{equation}\nSubstituting \\eref{eq_langevin} on the expected value on right-hand side gives\n\\begin{equation}\n    \\ee{ \\left. \\left[ \n    \\int_t^{t + \\Dt} dt'\\; {dx \\over dt'}\n    \\right]^2 \\right\\vert x(t) = x'} =\n    \\ee{ \\left. \\left[ \n    \\int_t^{t + \\Dt} dt'\\; A(x, t') + \n    \\int_t^{t + \\Dt} dt'\\; B(x, t') \\xi(t').\n    \\right]^2 \\right\\vert x(t) = x'},\n\\end{equation}\nwhere we already distributed the integral. We now expand the binomial on the\nright-hand side and use the linearity of expected values to obtain\n\\begin{equation}\n    \\begin{aligned}\n    \\ee{ \\left. \\left[ \n    \\int_t^{t + \\Dt} dt'\\; A(x, t') + \n    \\int_t^{t + \\Dt} dt'\\; B(x, t') \\xi(t')\n    \\right]^2 \\right\\vert x(t) = x'} =\n    \\left(  \n    \\int_t^{t + \\Dt} dt'\\; A(x, t')\n    \\right)^2\\\\\n    + 2 \n    \\int_t^{t + \\Dt} dt'\\; A(x, t')\n    \\int_t^{t + \\Dt} dt'\\; B(x, t') \\ee{ \\left.\\xi(t')\n    \\right\\vert x(t) = x'}\\\\\n    \\left(\n    \\int_t^{t + \\Dt} dt'\\; B(x, t') \\ee{\\left.\\xi(t')\n    \\right\\vert x(t) = x'}\n    \\right)^2,\n    \\end{aligned}\n    \\label{eq_int_binom}\n\\end{equation}\nwhere again we used the fact that the only variable we can average over is the\nwhite noise term $\\xi(t)$. We can see that the second term on the right-hand\nside cancels since the average of our stochastic variable is equal to zero. For\nthe two terms left we can rewrite the squared integrals as double integrals.\nLet's take a look at each of these terms one at the time. First the integral \ninvolving the directional term takes the form\n\\begin{equation}\n    \\left(  \n        \\int_t^{t + \\Dt} dt'\\; A(x, t')\n    \\right)^2 =\n    \\int_t^{t + \\Dt} dt'\\; \\int_t^{t + \\Dt} dt''\\;\n    A(x, t') A(x, t'').\n\\end{equation}\nJust as we did for \\eref{eq_approx_int_directional} we can use the fact that we\nare working at the limit where $\\Dt \\rightarrow 0$ to approximate the integral\nas \n\\begin{equation}\n    \\int_t^{t + \\Dt} dt'\\; \\int_t^{t + \\Dt} dt''\\;\n    A(x, t') A(x, t'') \\approx \\left[ A(x, t)  \\Dt\\right]^2.\n    \\label{eq_directional_int_approx}\n\\end{equation}\nFor the integral on \\eref{eq_int_binom} involving the diffusive term we again\nrewrite it as a double integral of the form\n\\begin{equation}\n    \\left(\n    \\int_t^{t + \\Dt} dt'\\; B(x, t') \\ee{\\left.\\xi(t')\n    \\right\\vert x(t) = x'}\n    \\right)^2 =\n    \\int_t^{t + \\Dt} dt'\\; \\int_t^{t + \\Dt} dt''\\;\n    B(x, t') B(x, t'') \\ee{\\left. \\xi(t') \\xi(t'') \\right\\vert x(t) = x}.\n\\end{equation}\nIn \\secref{sec_langevin_intro} where we introduced the Langevin equation we\ndefined the second moment of our noise term as given in \\eref{eq_noise_delta}.\nUsing this we evaluate one of the integrals first obtaining\n\\begin{equation}\n    \\int_t^{t + \\Dt} dt'\\; \\int_t^{t + \\Dt} dt''\\;\n    B(x, t') B(x, t'') \\ee{\\left. \\xi(t') \\xi(t'') \\right\\vert x(t) = x} =\n    2D \\int_t^{t + \\Dt} dt'\\; B(x, t')^2.\n\\end{equation}\nFinally we can again approximate the integral as\n\\begin{equation}\n    2D \\int_t^{t + \\Dt} dt'\\; B(x, t')^2 \\approx 2D B(x, t)^2 \\Dt.\n    \\label{eq_diffusive_int_approx}\n\\end{equation}\nPutting back \\eref{eq_directional_int_approx} and\n\\eref{eq_diffusive_int_approx} into our computation of the second coefficient\nof the Fokker-Planck equation in \\eref{eq_diffusive_fp_lim} results in\n\\begin{equation}\n    a^{(2)}(x, t) \\approx \\lim_{\\Dt \\rightarrow 0} {1 \\over \\Dt}\n    \\left[ A(x, t)^2\\Dt^2 + 2D B(x, t)^2\\Dt \\right].\n\\end{equation}\nOnce we simplify the corresponding $\\Dt$ terms and take the limit, the\ndirectional term goes to zero and we are left with a Fokker-Planck diffusive\ncoefficient of the form\n\\begin{equation}\n    a^{(2)}(x, t) = 2D B(x, t)^2.\n\\end{equation}", "meta": {"hexsha": "188eac9d935957bdd760ad3abea21df352933b4f", "size": 13020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/book_draft/chapters/classic_diffusion/05_fp_to_langevin.tex", "max_stars_repo_name": "mrazomej/stat_gen", "max_stars_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/book_draft/chapters/classic_diffusion/05_fp_to_langevin.tex", "max_issues_repo_name": "mrazomej/stat_gen", "max_issues_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-05T00:17:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-05T00:17:26.000Z", "max_forks_repo_path": "doc/book_draft/chapters/classic_diffusion/05_fp_to_langevin.tex", "max_forks_repo_name": "mrazomej/pop_gen", "max_forks_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.3658536585, "max_line_length": 79, "alphanum_fraction": 0.6668970814, "num_tokens": 4328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702032, "lm_q2_score": 0.8558511524823265, "lm_q1q2_score": 0.7840534725111125}}
{"text": "\\section{Exercises in Transformations of Random Variables}\\label{S:xsTransformationsOfRVs}\n\\begin{ExerciseList}\n%transformation of RVs\n\\Exercise\nLet $X$ be the outcome of a fair die roll with probability mass function given by\n\\[\nf_X(x) = \n\\begin{cases}\n\\frac{1}{6} & \\text{ if } x \\in \\{1,2,3,4,5,6\\}\\\\\n0 & \\text{ otherwise} \\, .\n\\end{cases}\n\\]\nIf $Y = (X-3)^2$ then find the probability mass function of $Y$,  $f_Y (y)$.\n\\Answer\nUsing Equation~\\eqref{E:PMFOfgOfX}, we can tabulate as follows:\n\n\\begin{tabular}{|c|c|c|c|c|}\n\\hline\n$y$ & $0$ & $1$ & $4$ & $9$\\\\\\hline\n$f_Y(y)$ & $f_X(3)=\\frac{1}{6}$ & $f_X(2)+f_X(4)=\\frac{2}{6}$ & $f_X(1)+f_X(5)=\\frac{2}{6}$ & $f_X(6)=\\frac{1}{6}$\\\\\\hline\n\\end{tabular}\n\n\\Exercise\nGiven a natural number $n$ as a parameter, i.e., given a parameter $n \\in \\{1,2,3,\\ldots\\}$, let $X$ be a discrete uniform random variable on the finite set\n$$\\mathbb{X}=\\{-n,-n+1,\\ldots,-1,0,1,\\ldots,n-1,n\\}$$\ni.e.~the probability mass function of $X$ is:\n\\[\nf_X(x;n) = \n\\begin{cases}\n\\frac{1}{2n+1} & \\text{ if } x \\in \\mathbb{X} \\\\\n0 & \\text{ otherwise}\\, .\n\\end{cases}\n\\]\nFind the probability mass function $f_Y(y;n)$ for $Y=|X|$, the absolute value of $X$.\n\\Answer\nThe probability mass function $f_Y(y;n)$ for $Y=|X|$, the absolute value of $X$, comes from applying the formula:\n\\[\nf_Y(y;n) = \\sum_{x \\in \\{ x: g(x)=y\\}} f_X(x;n) \\enspace ,\n\\]\nas follows:\n\\[\nf_Y(y) = \n\\begin{cases}\n\\sum_{x \\in \\{ x: |x|=0\\}} f_X(x;n) = f_X(0;n) = \\frac{1}{2n+1} & \\text{ if } y =0 \\\\\n \\sum_{x \\in \\{ x: |x|=y\\}} f_X(x;n) = \\left( f_X(y;n)+f_X(-y;n) \\right) = \\frac{2}{2n+1} & \\text{ if } y \\in \\{1,2,\\ldots,n\\} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\]\n\n\\Exercise\nIf $X$ is a $\\geometric(\\theta)$ random variable and $Y=\\left(\\frac{1}{2}\\right)^X$ then find an expression for $f_Y(y)$.\n\\Answer\nWe are given that $Y=2^{-X}$. Define the function\n$$g: \\{1,2,3,\\ldots\\} \\to \\{2^{-1},2^{-2},2^{-3},\\ldots\\}$$\nby $y=g(x)=2^{-x}$.  Then $g$ is one-to-one and onto and so by Equation~\\eqref{E:PMFOfgOfX},\n\\[\nf_Y(y) = \\sum_{x \\in g^{[-1]}(y)} f_X(x) = \\sum_{x \\in g^{-1}(y)} f_X(x) = \\sum_{x \\in \\{ -\\log_2(y) \\} } f_X(x) = f_X(-\\log_2(y))\\, .\n\\]\nNote that the second equality above is emphasizing that the inverse image $g{[-1]}(y)$ is indeed the inverse function $g^{-1}(y)$ for this $g:\\{1,2,3,\\ldots\\} \\to \\{2^{-1},2^{-2},2^{-3},\\ldots\\}$.  Therefore,\n\\[\nf_Y(y) = \n\\begin{cases}\nf_X(-\\log_2(y)) = \\theta (1-\\theta)^{-\\log_2(y)-1} & \\text{ if } y \\in \\{2^{-1},2^{-2},2^{-3},\\ldots\\}\\\\\n0 & \\text{ otherwise} \\, .\n\\end{cases}\n\\]\n\n\n\\Exercise\nIf $X$ is a $\\poisson(\\lambda)$ random variable find the probability mass function,  $f_Y (y)$, of\n\\[\nY\\,=\\,\\frac{1}{(X+1)^{2}} \\enspace .\n\\]\n\\Answer\nSince $X$ is a $\\poisson(\\lambda)$ random variable (by suppressing the `$;\\lambda$' in the argument to $f_X(\\cdot)$ for notational ease), we get\n\\[ f_X(x) \\,=\\, \\P(X=x)\\,=\\, \n\\begin{cases}\n\\frac{\\lambda^x \\, e^{-\\lambda} }{ x!} & \\text{ for }  x= 0, 1, 2, \\dots \\\\\n0 & \\text{ otherwise} \\,.\n\\end{cases}\n\\]\n\nIf $Y=(X+1)^{-2}=1/(X+1)^2$ then  \\[ \\{\\ldots,2,1,0\\} \\ni x \\xmapsto{(x+1)^{-2}} y \\,\\in\\, \\left\\{1, \\frac{1}{4}, \\frac{1}{9}, \\dots \\right\\} \\]\nand since $y=g(x)=(x+1)^{-2}$ {\\scriptsize as it maps or associates each $y \\in \\left\\{1, \\frac{1}{4}, \\frac{1}{9}, \\dots \\right\\}$ to exactly one $x \\in \\{0,1,2,\\ldots\\}$ given by $g^{-1}(y)=y^{-1/2}-1 = \\frac{1}{\\sqrt{y}}-1= x$, its inverse function, this is because $g$ is {\\em injective} or {\\em one-to-one} as explained here if you want to recall quickly \\url{https://en.wikipedia.org/wiki/Injective_function} again}, so we get:\n\\[\nf_Y(y)\\;=\\; \\P(Y=y)\\;=\\; \\sum_{\\{ x: g(x)=y\\}}f_X(x)  \\;=\\; f_X\\left( \\frac{1}{\\sqrt y}-1\\right) \\;=\\; \\frac{\\lambda^{(\\frac{1}{\\sqrt y} -1)} \\, e^{-\\lambda}}{(\\frac{1}{\\sqrt y} -1)!}\n\\]\nfor $y = 1, \\frac{1}{4}, \\frac{1}{9}, \\dots $, and $0$ otherwise.\\\\[4pt]\n{\\scriptsize CAUTION: This is a discrete RV and so don't just blindly apply the change of variable formula that only applies to continuous RV with a monotone and one-to-one function \n$g$ with inverse $g^{-1}$; it's just that in this discrete RV setting the inverse image also happens to satisfy these properties. But Poisson is discrete and `change of variable formula'' is hence inapplicable.}\n\n\\Exercise\nIf $X$ is a continuous random variable with probability density function\n\\[\nf_X(x)\\;=\\;\\begin{cases} x e^{- x} &  x\\geqslant 0\\\\ 0 & x< 0\\end{cases},\n\\]\nfind the probability density function of $Y\\,=\\, e^X$.\n\\Answer\nSince  $y=g(x) = e^x$ is a monotone increasing function for $x \\geqslant 0$,  we can apply the change of variable formula.\n\nNow $x= g^{-1}(y) = \\log_e(y)$ is a monotone increasing function for $y$ in $[1,\\infty)$\n\\[\\left|  \\frac{d}{dy}\\left(g^{-1}(y)\\right)\\right|\\;=\\; \\left|  \\frac{d}{dy}\\left(\\log_e(y)\\right)\\right|\\;=\\; \\frac{1}{y}\\,.\\]\n\nTherefore\n\\[\n  f_Y(y) \\;=\\; f_X\\left( \\log_e(y)\\right) \\times  \\left| \\frac{1}{y} \\right|\\;=\\;  \\log_e(y) \\,e^{-\\log_e(y)} \\times  \\frac{1}{y} \\;=\\; \\log_e(y) \\, \\frac{1}{y^2}\n\\]\nsince $e^{-\\log_e(y)} = e^{\\log_e(y^{-1})}  = y^{-1}$.\n\nSo the  probability density\n  function  of $Y$ is given by\n\\[f_Y(y)\\;=\\;\\begin{cases} \\displaystyle  \\frac{\\log_e(y)}{y^2} &   \\text{ if } x \\geqslant 1 \\\\ 0 &\n  \\text{otherwise}\n\\end{cases} \\,.\n\\]\n\n\\Exercise\nIf $X$, the received power at an antenna is an $\\exponential(\\lambda)$ random variable then find the probability density function of the amplitude $Y\\,=\\, \\sqrt X$.\n\\Answer\nSince $y=g(x) = \\sqrt{x}$ is a monotone increasing function for $x \\geqslant 0$,  we can apply the change of variable formula.\n\nNow $x= g^{-1}(y) = y^2$ is a monotone increasing function for $y\\geqslant 0$ so on this interval\n\\[\n\\left|  \\frac{d}{dy}\\left(g^{-1}(y)\\right)\\right|\\;=\\; \\left|  \\frac{d}{dy}\\left( y^2\\right)\\right|\\;=\\; 2y\\,.\\]\nTherefore\n\\[\nf_Y(y) \n\\;=\\; f_X\\left(  y^2\\right) \\times  \\left| 2y \\right|\n\\;=\\;  \\lambda e ^{-\\lambda y^2} \\times  2y  \\;=\\;   2 \\lambda y e ^{-\\lambda y^2}\\,.\n\\]\nSo the  probability density function  of $Y$ is given by\n\\[\nf_Y(y)\\;=\\;\\begin{cases} \\displaystyle  2 \\lambda y e ^{-\\lambda y^2}   &    y\\geqslant 0 \\\\ 0 & y <0\n\\end{cases} \\,.\n\\]\n\n\n\\Exercise\nIf $X$ is a $\\uniform(a,b)$ random variable where $0 < a < b$, find  the probability density function, $f_Y (y)$, of \\[ Y\\,=\\, \\log_e(X) \\, .\\]\n\\Answer\nFirst note that $y=g(x) = \\log_e(x)$ is a monotone increasing function over  $a \\leqslant x \\leqslant b$, so we can apply the change of variable formula.\n\n $x= g^{-1}(y) = e^y$ is a monotone increasing function over $\\log_e(a) \\leqslant   \\log_e(x) \\leqslant \\log_e(b)$, that is, over $\\log_e(a) \\leqslant   y \\leqslant   \\log_e(b)$.\n\nFor $\\log_e(a) \\leqslant   y \\leqslant   \\log_e(b)$,\n\n\\[\\left|  \\frac{d}{dy}\\left(g^{-1}(y)\\right)\\right|\\;=\\; \\left|  \\frac{d}{dy}\\left(e^y)\\right)\\right|\\;=\\; e^y\\,.\\]\n\nTherefore \n\\[\n  f_Y(y) \\;=\\; f_X\\left(g^{-1}(y)\\right) \\times  \\left|  \\frac{d}{dy} \\left(g^{-1}(y)\\right)\\right|\\;=\\; \\frac{1}{b-a} \\times e^y\\,.\n\\]\nSo the  probability density\n  function  of $Y$ is given by  \n\\[f_Y(y)\\;=\\;\\begin{cases} \\displaystyle  \\frac{e^y}{b-a}  &   \\log_e(a)\\leqslant x \\leqslant \\log_e(b)\\\\ 0 &\n  \\text{otherwise}\n\\end{cases} \\,.\n\\]\n\n\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "fdd342eadfa976c1c4b053722a29b33c1ec78bb8", "size": 7155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInTransformationsOfRVs.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/ExsInTransformationsOfRVs.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/ExsInTransformationsOfRVs.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": 43.8957055215, "max_line_length": 433, "alphanum_fraction": 0.5979035639, "num_tokens": 2903, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.9161096118716263, "lm_q1q2_score": 0.7840534553315208}}
{"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$.\r\nSince 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\\begin{example}\r\n\tFind the general solution to the following equation\r\n\t\\begin{equation*}\r\n\t\ty'' + y = \\csc{x}\r\n\t\\end{equation*}\r\n\tgiven that $y_h = C_1\\cos{x} + C_2\\sin{x}$.\r\n\\end{example}\r\n\\noindent\r\n$y_h$ gives us our two fundamental solutions\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\ty_1 = \\cos{x} \\\\\r\n\t\ty_2 = \\sin{x}\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nSo, our system of equations is\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tA'\\cos{x} + B'\\sin{x} = 0 \\\\\r\n\t\t-A'\\sin{x} + B'\\cos{x} = \\csc{x}\r\n\t\\end{cases} \\to \\begin{cases}\r\n\t\tA'\\cos{x} + B'\\sin{x} = 0 \\\\\r\n\t\t-A'\\cos{x} + B'\\frac{\\cos^{2}{x}}{\\sin{x}} = \\frac{\\cos{x}}{\\sin^{2}{x}}\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nSo, \r\n\\begin{equation*}\r\n\tB'\\frac{1}{\\sin{x}} = \\frac{\\cos{x}}{\\sin^{2}{x}} \\implies B' = \\frac{\\cos{x}}{\\sin{x}} = \\cot{x} \\implies B = \\ln{\\abs{\\sin{x}}} + C_2,\r\n\\end{equation*}\r\nand\r\n\\begin{equation*}\r\n\tA'\\cos{x} + \\cos{x} = 0 \\implies A' = -1 \\implies A = -x + C_1.\r\n\\end{equation*}\r\nSo, our general solution is\r\n\\begin{equation*}\r\n\ty = \\left(C_1 - x\\right)\\cos{x} + \\left(\\ln{\\abs{\\sin{x}}} + C_2\\right)\\sin{x} = C_1\\cos{x} + C_2\\sin{x} - x\\cos{x} + \\sin{x}\\ln{\\abs{\\sin{x}}}.\r\n\\end{equation*}\r\nNote how $y_h$ and $y_p$ appear together.", "meta": {"hexsha": "ea8237a4c1b4fe5914dc51e2d369460b32b517e8", "size": 2033, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_secondOrder.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_secondOrder.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/nonHomeg/variationParameters_secondOrder.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": 33.3278688525, "max_line_length": 163, "alphanum_fraction": 0.6133792425, "num_tokens": 776, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8791467690927439, "lm_q1q2_score": 0.7840327992379781}}
{"text": "\\subsection{Symbols}\n\nAs we saw earlier, symbols are defined using an equals sign.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN = 212^17\n\\end{Verbatim}\n\n\\noindent\nNo result is printed when a symbol is defined.\nTo see the value of a symbol, just evaluate it.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle N=3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nSymbols can have more that one letter.\nEverything after the first letter is displayed as a subscript.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nNA = 6.02214 10^23\nNA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle N_A=6.02214\\times10^{23}$\n\n\\bigskip\n\\noindent\nA symbol can be the name of a Greek letter.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nxi = 1/2\nxi\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\xi=\\tfrac{1}{2}$\n\n\\bigskip\n\\noindent\nGreek letters can appear in subscripts.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nAmu = 2.0\nAmu\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A_\\mu=2.0$\n\n\\bigskip\n\\noindent\nThe following example shows how\nEigenmath scans the entire symbol to find Greek letters.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nalphamunu = 1\nalphamunu\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\alpha_{\\mu\\nu}=1$\n\n\\bigskip\n\\noindent\nWhen a symbolic chain is defined,\nEigenmath follows the chain as far as possible.\nThe following example sets $A=B$ followed by $B=C$.\nThen when $A$ is evaluated, the result is $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = B\nB = C\nA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A=C$\n\n\\bigskip\n\\noindent\nAlthough $A=C$ is printed,\ninside the program the binding of $A$ is still $B$, as can be seen with\nthe $binding$ function.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nbinding(A)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle B$\n\n\\bigskip\n\\noindent\nThe {\\it quote} function returns its argument unevaluated\nand can be used to clear a symbol.\nThe following example clears $A$ so that its evaluation goes back to\nbeing $A$ instead of $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = quote(A)\nA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A$\n\n\\subsection{User defined functions}\n\nMost of the functions commonly used in math and physics are included in Eigenmath.\nSee the Reference section at the end of the manual for a complete list.\nThere is also a facility for the user to define additional functions.\n\n\\bigskip\n\\noindent\nUser functions are defined using the syntax {\\it function-name} ( {\\it arg-list} ) = {\\it expr}\nwhere {\\it arg-list} is a comma separated list of zero to nine symbols that receive arguments.\nUnlike symbol definitions, {\\it expr} is not evaluated when {\\it function-name} is defined.\nInstead, {\\it expr} is evaluated when {\\it function-name} is used in a subsequent computation.\n\n\\bigskip\n\\noindent\nThe following example defines a sinc function and evaluates it at $\\pi/2$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = sin(x)/x\nf(pi/2)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\frac{2}{\\pi}$\n\n\\bigskip\n\\noindent\nAfter a user function is defined, {\\it expr} can be recalled using the {\\it binding} function.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nbinding(f)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\frac{\\sin(x)}{x}$\n\n\\bigskip\n\\noindent\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\nThe scope of function arguments is limited to the function definition.\n", "meta": {"hexsha": "63ff982cf912f9ece185d068903d2c8b07372371", "size": 4083, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/symbols.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/symbols.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/symbols.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": 23.3314285714, "max_line_length": 95, "alphanum_fraction": 0.7301004164, "num_tokens": 1262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.891811038968166, "lm_q1q2_score": 0.7840327949620345}}
{"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\nThe operation \\textsc{Heap-Delete}$(A,i)$ deletes the item in node $i$ from heap $A$.\nGive an implementation of \\textsc{Heap-Delete} that runs in $\\mathcal{O}(\\log n)$ time for an $n$-element max-heap.\nYou are as well expected to show that your proposed algorithm run in $\\mathcal{O}(\\log n)$ time.\n\n\\subsection*{Solution}\n\nTo remove node $i$ from array $A$ where $A$ is a \\textit{Heap} data structure with $n$ elements, we first replace $A[i]$ with $A[n]$; last node in height $H$ where $H$ is height of the tree.\nThis is done to maintain \\textit{completeness} of the binary tree.\nObviously this step has a constant runtime cost which is negligible.\nAs it is likely that such modification violates the \\textit{heap} structure of the tree, we should \\textsc{Heapify} the modified binary tree to maintain the heap structure after deletion.\n\nNow the following two cases might occur:\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $A[n] < A[\\lceil \\frac{i}{2} \\rceil ] $\\\\\nIf node $n$ is within the subtree with root at node $i$, we can rest assured that the value of node $n$ is less than the value of parent of node $i$, in which case \\textsc{Heapify} can only be called for the subtree whose root is node $\\lceil \\frac{i}{2} \\rceil$, to move node $i$ one step lower.\n\n\\item $A[n] > A[\\lceil \\frac{i}{2} \\rceil ] $\nIf there is no subtree that includes nodes $i$ and $n$, the value of node $n$ may be higher than the value of parent of node $i$, in which case each call of \\textsc{Heapify} is likely to move node $i$ one step higher.\n\\end{enumerate}\n\nIn either case, the number of calls to \\textsc{Heapify} is surely less than or equal to the the height $H$ of the tree.\nSince $ 2^{H} - 1 < n $, we can derive $ h < \\log {n+1} $ and thus the runtime of proposed \\textsc{Heap-Delete} algorithm is $\\mathcal{O}(\\log n)$.\n", "meta": {"hexsha": "e90dc826db588d4a688fdb626d6cf20d5cc8f297", "size": 2189, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw02/hw02q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 66.3333333333, "max_line_length": 296, "alphanum_fraction": 0.6774783006, "num_tokens": 610, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8918110461567922, "lm_q1q2_score": 0.7840327928103226}}
{"text": "\\section{Divergence Theorem}\r\n\\begin{theorem}\r\n\tLet $V$ be a compact solid, and let $S$ be its boundary surface. For any differentiable vector field $\\vec{F}(x,y,z)$,\r\n\t\\begin{equation*}\r\n\t\t\\oint\\limits_{S}{\\oint{\\vec{F} \\cdot \\mathrm{d}\\vec{s}}} = \\iiint\\limits_{V}{\\nabla \\cdot \\vec{F}\\mathrm{d}V}\r\n\t\\end{equation*}\r\n\twhere $\\mathrm{d}\\vec{s} = \\hat{n}\\mathrm{d}s = (\\vec{r_u}\\times\\vec{r_v})\\mathrm{d}u\\mathrm{d}v$ and $\\mathrm{d}V$ is the volume differential.\r\n\\end{theorem}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis says that the flux through a closed surface is equal to the sum of the divergence inside that surface.\\\\\r\nIntuitively, divergence describes how much a vector field is going in or out at a point, so summing it up inside some solid would tell us the amount the vector field is going in or out on the solid’s boundary, which is flux.\\\\\r\n\r\n\\noindent\r\nFor example, let’s find the flux through the unit sphere centered at the origin from the vector field $\\vec{F}(x,y,z) = \\langle x, y, z^2 \\rangle$.\r\n\\begin{equation*}\r\n\tS = \\left\\{(\\rho, \\theta, \\phi) \\mid \\rho=1, 0 \\leq \\theta \\leq 2\\pi, 0 \\leq \\phi \\leq \\pi \\right\\}\t\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tV = \\left\\{(\\rho, \\theta, \\phi) \\mid 0 \\leq \\rho \\leq 1, 0 \\leq\\ theta \\leq 2\\pi, 0 \\leq \\phi \\leq \\pi \\right\\}\t\r\n\\end{equation*}\r\n\\begin{align*}\r\n\t\\text{Flux} &= \\oint\\limits_{S}{\\oint{\\vec{F} \\cdot \\mathrm{d}\\vec{s}}}\t\\\\\r\n\t&= \\int_{0}^{1}{\\int_{0}^{\\pi}{\\int_{0}^{2\\pi}{\\nabla \\cdot \\langle x, y, z^2 \\rangle\\rho^2\\sin{\\phi}\\mathrm{d}\\theta}\\mathrm{d}\\phi}\\mathrm{d}\\rho} \\\\\r\n\t&= \\int_{0}^{1}{\\int_{0}^{\\pi}{\\int_{0}^{2\\pi}{(2 + 2z)\\rho^2\\sin{\\phi}\\mathrm{d}\\theta}\\mathrm{d}\\phi}\\mathrm{d}\\rho} \\\\\r\n\t&= \\int_{0}^{1}{\\int_{0}^{\\pi}{\\int_{0}^{2\\pi}{(2 + 2\\rho\\sin{\\phi})\\rho^2\\sin{\\phi}\\mathrm{d}}\\mathrm{d}}\\mathrm{d}} \\\\\r\n\t&= 2\\pi\\int_{0}^{1}{\\int_{0}^{\\pi}{2\\rho^2\\sin{\\phi} + 2\\rho^3\\sin{\\phi}\\cos{\\phi}\\mathrm{d}\\phi}\\mathrm{d}\\rho} \\\\\r\n\t&= 4\\pi\\int_{0}^{\\pi}{\\frac{1}{3}\\sin{\\phi} + \\frac{1}{4}\\sin{\\phi}\\cos{\\phi}\\mathrm{d}\\phi} \\\\\r\n\t&= \\frac{8\\pi}{3}\r\n\\end{align*}\r\n\r\n\\input{./vectorAnalysis/gausssLaws}", "meta": {"hexsha": "bfe388aacdc2332d58be5c919b93c353efe5091c", "size": 2083, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/divergenceTheorem.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorAnalysis/divergenceTheorem.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorAnalysis/divergenceTheorem.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.2647058824, "max_line_length": 227, "alphanum_fraction": 0.6279404705, "num_tokens": 850, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7840113863373547}}
{"text": "\\lab{Application}{Newton's Method, Julia Sets and Basins of Attraction}{Newton's Method}\n\\label{lab:NewtonsMethod}\n\\objective{Understand Newton's Method. Understand definition of basin of attraction.  Basic understanding of Julia Sets.}\n\nOne important technique in technical computing is Newton's method.\nThe goal of Newton's method is to find $\\overline{x}$ such that $f\\left(\\overline{x}\\right) = 0$.\nThis method is especially important in optimization, where our goal is to find minima and maxima of functions.\nNewton's method is an iterative method.\nIn one dimension, it is defined as follows:\n\\[\nx_{n+1} = x_n - \\frac{f(x_n)}{f'(x_n)}\n\\]\n\nEssentially Newton's method approximates a function by its tangent line, and then uses the zero of the tangent line as the next guess for $x_n$.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\textwidth]{newton_iters}\n\\caption{An illustration of how one iteration of Newton's method works}\n\\end{figure}\n\nNewton's method is powerful because of the speed of convergence.\nIn many cases Newton's method converges to the actual root quadratically, meaning that the error term is squared at every iteration.\nThis fast convergence makes it a very powerful algorithm.\n\nNewton's method does suffer from the flaw that its convergence is dependent upon an initial guess.\nIf the initial guess is not sufficiently close the convergence can be much slower, or may never occur.\nThere are even certain pathological functions for which newton's method will never converge.\n\n\\begin{problem}\n\\label{prob:newton_arr}\nWrite a Newton's method function that runs whether or not the user inputs a derivative function.\nIn python this can be done by defining the derivative function as a keyword argument that defaults to \\li{None}.\nAlso accept a maximum of how many iterations it will run and a tolerance used for the stopping condition.\nReturn a tuple with the computed value and boolean value telling whether it converged or not.\n\nCompare the performance of Newton's method when you input the derivative and when you don't.\nHow well does each converge?\nWhich runs faster?\nTry the following functions:\n\n\\begin{itemize}\n\\item $cos(x)$\n\\item $x^2sin(\\frac{1}{x})$\n\\item $(\\frac{sin(x)}{x})-x$\n\\item $x^2-1$\n\\item $x^3 - x$\n\\end{itemize}\n\nFor the last two, look at the results of the iteration on equispaced points between -2 and 2.\nWhich points converge to which roots?\n\nThere are also examples of when Newton's Method does not converge.\nTest your newton's method function on $x^{1/3}$.\nHave it test at eqispaced starting points on a given interval and return the corresponding values after a given number of iterations.\nWhat do you see?\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nExtend your Newton's method even further so that it will work on systems of equations.\nSuppose that $F: \\mathbb{R}^n \\rightarrow \\mathbb{R}^n $.\nThe relevant equation is\n\\[\nx_{i+1} = x_i - J^{-1}F(x_i)\n\\]\nNote that you should not calculate the inverse Jacobian.\n\\li{scipy.linalg.solve(A,b)} gives you the solution $x$ to the equation $Ax=b$.\nUse this fact to calculate $J^{-1}F$ from $J$ and $F$.\nYou should be able to make this function work whether or not the user inputs a Jacobian.\nThis also means that you will have to use your own \\li{jacobian} function.\n\\end{problem}\n\\end{comment}\n\n\\section*{Basins of Attraction and Julia Sets}\nThus far we have only noted the fact that Newton's method converges under good circumstances.\nAnother topic of interest is determining which starting values converge to which roots.\nAn plot showing which points converge to which roots for the function $x^2 + x - 2$ is shown in Figure \\ref{Fig:basins1}.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=0.5]{basins1}\n\\caption{The plot of $f(x) = x^2 + x - 2$ along with 20 seed values for Newton's Method.\nThe green values all converge to the root at -2, and the black values will converge to the root at 1.}\n\\label{Fig:basins1}\n\\end{center}\n\\end{figure}\n\nIt turns out that for $f(x) = x^2 + x - 2$, any seed value will converge to one root or the other.\nWe call the set of points that converge to a single value through an iterative process a basin of attraction.\nWe can see in Figure \\ref{Fig:basins1} a set of seed values that are color coded to indicate which root they converge to with Newton's method.\n\nWe now extend these ideas to complex functions.\nThere is an entire field of mathematics devoted to the study of such functions, but here we only examine some basic properties as they pertain to the generation of Julia sets.\nLike other functions we have thus far been exposed to, a complex function maps an input to a unique output.\nHowever, in this case both the input and the output come from the space of complex numbers.\n\nGiven a sufficiently ``nice'' complex function, we can apply Newton's method in a similar way to how we applied it in the real case.\nHowever due to the nature of the space we are mapping from and to, we no longer have access to the intuitive visual representations of functions that we saw in the real case.\nWe can, however, graph the basins of attraction for Newton's method on the complex plane.\nFor example, let:\n\\[\nf(z) = z^2 - 1\n\\]\nDerivatives for nice complex functions behave much the same way as in the real case:\n\\[\nf'(z) = 2z\n\\]\nIt is straightforward to verify that $f$ has two roots at 1 and -1.\n\nIn order to better visualize basins of attraction in the complex plane we will use the function li{pcolormesh} from the pyplot library in matplotlib.\nThe following is an example of how to use this function.\nIt allows us to color different portions of a plane according to the value of a function at each point.\n\n\\begin{lstlisting}\nimport scipy as sp\nfrom matplotlib import pyplot as plt\nn=401\nx=sp.linspace(-2,2,n)\ny=sp.linspace(-2,2,n)\nX,Y=sp.meshgrid(x,y)\ndef func(x):\n    return sp.real(x**3-2*x**2-x+2)\nC=func(X+complex(0,1)*Y)\nplt.pcolormesh(X,Y,C)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nModify your code from Problem \\ref{prob:newton_arr} to graph the basins of attraction for a polynomial in the complex plane.\nExamine the basins of attraction for the following complex functions on the following domains.\n\\begin{itemize}\n\n\\item $z^3 - 2 z^2 - 2 z + 2$ on the set of complex numbers $a + b i$ such that $a \\in \\left[-\\frac{1}{2}, 0\\right]$ and $b \\in \\left[-\\frac{1}{4}, \\frac{1}{4}\\right]$.\n\n\\item $3 z^3 - 2 z^2 - 2 z + 2$ on the set of complex numbers $a + b i$ such that $a \\in \\left[-1, 1\\right]$ and $b \\in \\left[-1, 1\\right]$.\n\n\\item $z^4 + 3 z^3 - 2 z^2 - 2 z + 2$ on the set of complex numbers $a + b i$ such that $a \\in \\left[-1, 1\\right]$ and $b \\in \\left[-1, 1\\right]$.\n\n\\item $z^3 - 1$ on the set of complex numbers $a + b i$ such that $a \\in \\left[-1, 1\\right]$ and $b \\in \\left[-1, 1\\right]$.\n\n\\end{itemize}\nBe aware that Newton's method may not converge for every point in these intervals, so you will have to manually set the pixels that result in a value of \\li{nan} to something else.\nOne good approach is to set the roots of the polynomial to numbers $0, 1, \\dots, k$ and then set the values of \\li{nan} to $k+1$.\n\nMake sure that when plotting you start with low resolution.\nEven if you generate a plot using an array of $100$ by $100$ points, you will be running Newton's method on your test function $10,000$ times, so be careful.\n\\end{problem}\n\nAnother well-studied fractal in the complex plane is the Mandelbrot set.\nIt is defined as the points $c \\in \\mathbb{C}$ for which the sequence\n\\[z_n = z_{n-1}^2 + c\\]\nis bounded.\n\n\\begin{problem}\nGenerate another grid of complex numbers on $[-1.5,.5]\\times[-i,i]$.\nConsider the recurrence relation $x_n = x_{n-1}^2 + c$.\nRun this iteration 30 times with a resolution of $200 \\times 200$ and display the plot.\n\\end{problem}\n", "meta": {"hexsha": "a9d28743d3177a52eb8efac50cfc61d6cc15dcb5", "size": 7747, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/NewtonsMethod/NewtonsMethod.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/NewtonsMethod/NewtonsMethod.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/NewtonsMethod/NewtonsMethod.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": 48.41875, "max_line_length": 180, "alphanum_fraction": 0.7472570027, "num_tokens": 2087, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.9005297827809309, "lm_q1q2_score": 0.7839987750564383}}
{"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\\blue{Fixed-Point iterations} are very important, both in computer science and in mathematics.  As a first\nexample, we show how to solve an equation via a 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 $x = \\cos(x)$. \nFurthermore, from Figure \\ref{fig:xEqualsCosX.pdf} it is obvious that this value of $x$ is bigger than $0.6$\nand 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 lets us compute the exact value of $x$ is to use 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}\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/Logik/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{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    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{Verbatim} \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/Logik/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{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  firstnumber   = 1,\n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    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{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{A generic implementation of the fixed-point algorithm.}\n\\label{fig:fixpoint.py}\n\\end{figure}\n\nFigure \\ref{fig:fixpoint.py} on page \\pageref{fig:fixpoint.py} shows the program\n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/fixpoint.py}{\\texttt{fixpoint.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} since 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}.  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/Script/analysis.pdf}{analysis} in the second\nsemester. \\eox  \n\n\\section{Case Study: Computation of Poker Probabilities}\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/Logik/blob/master/Python/poker-triple.py}{poker-triple.py}\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{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.0cm,\n                  xrightmargin  = 0.0cm,\n                ]\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{Verbatim}\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$, which is pronounced as \\blue{club},\n      \\item ``\\texttt{h}'' is short for \\mbox{\\color{red}{$\\heart$}}, which is pronounced as \\blue{heart}, \n      \\item ``\\texttt{d}'' is short for \\mbox{\\color{red}{$\\diamondsuit$}}, which is pronounced as \\blue{diamond}, and \n      \\item ``\\texttt{s}'' is short for $\\spade$, which is pronounced as \\blue{spade}. \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\\%$.  A \\textsl{Jupyter} notebook showcasing this computation outlined above can be fount at\n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/Poker.ipynb}{Poker.ipynb}.\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}} \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}\nIn the following section, I will present an application that is more interesting since it is practically\nrelevant.  In order to prepare for this, we will now discuss the problem of finding a \\blue{path} in a\n\\href{https://en.wikipedia.org/wiki/Directed_graph}{directed graph}. \nAbstractly, a 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 streets connecting these\nvillages.  To simplify matters, let us assume for now that the vertices are given as natural numbers, while the\nedges are represented as pairs of natural numbers.  Then, the graph can be represented as the set of its edges,\nas the set of vertices is implicitly given once the edges are known.  To make things concrete, let us consider\nan example.  In this case, the set of edges is called \\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$.  It is important to note that 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 in the path.\n\nFurthermore,  two vertices $a$ and $b$ are said to be \\blue{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\n\\subsection{Computing the Transitive Closure of a Relation}\nWe have already noted that a graph can be represented as the set of its edges and hence as a \\blue{binary relation}.\nA \\blue{binary relation} is defined as a set of pairs.  We also need the notion of a \\blue{relational product}:\nIf $Q$ and $R$ are binary relations, then the \\blue{relational product} $Q \\circ R$ of $Q$ and $R$ is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$Q \\circ R := \\bigl\\{ \\pair(x, z) \\bigm| \\exists y:(\\pair(x,y) \\in Q \\wedge \\pair(y,z) \\in R) \\bigr\\}$.\n\\\\[0.2cm]\nFurthermore, for any $n \\in \\mathbb{N}^*$ we can define the $n$-th power of the relation $R$ by induction.\n\\begin{enumerate}\n\\item[B.C.:] $n = 1$.\n\n             $R^1 := R$\n\\item[I.S.:] $n \\mapsto n+1$ \n\n             $R^{n+1} := R^n \\circ R$.\n\\end{enumerate}\nIn order to decide whether there is a path connecting two vertices we have to compute the \n\\href{https://en.wikipedia.org/wiki/Transitive_closure}{transitive closure} $R^+$ of a relation $R$.  \nTo understand this notion, we first need to define the concept of \\blue{transitivity}:  A relation $R$ is\ntransitive if and only if the following holds:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\pair(x,y) \\in T \\wedge \\pair(y, z) \\in T \\rightarrow \\pair(x, z) \\in T$ \\quad for all $x,y,z$. \n\\\\[0.2cm]\nNow the \\blue{transitive closure} $R^+$ of a binary relation $R$ is the smallest relation $T$ such that the following\ncondition holds:\n\\begin{itemize}\n\\item $R$ is a subset of $T$, i.e. we have $R \\subseteq T$.\n\\item $T$ is transitive.\n\\end{itemize}\nThe lecture on\n\\href{https://github.com/karlstroetmann/Lineare-Algebra/blob/master/Script/lineare-algebra.pdf}{Lineare Algebra} \ngives a prove that the transitive closure $R^+$ of a binary relation can be computed as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$R^+ = \\bigcup\\limits_{n=1}^{\\infty} R^n = R^1 \\cup R^2 \\cup R^3 \\cup \\cdots$  \n\\\\[0.2cm]\nInitially, this formula might look intimidating as it suggests an infinite computation.\nFortunately, it turns out that we do not have to compute all powers of the form $R^n$.  Let me\nexplain the reason that allows us to cut the computation short.  \n\\begin{enumerate}\n\\item $R$ is the set of direct connections between two vertices.\n\\item $R^2$ is the same as $R \\circ R$ and this relational product is defined as\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n       $R \\circ R = \\bigl\\{ \\pair(x,z) \\bigm| \\exists y \\colon(\\pair(x,y) \\in R \\wedge \\pair(y,z)) \\in R \\bigr\\}$.\n      \\\\[0.2cm]\n      Hence, $R \\circ R$ contains those pairs $\\pair(x,z)$ that are connected via one intermediate vertex $y$,\n      i.e.~there is a path of the form $x \\mapsto y \\mapsto z$ that connects $x$ and $z$.  This path\n      has length 2.  In general, we can show by induction that $R^n$ connect those pairs that are\n      connected by a path of length $n$.  The induction step of this proof runs as follows:\n\\item $R^{n+1}$ is defined as $R^n \\circ R$ and therefore we have\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $R^n \\circ R = \\{ \\pair(x,z) \\mid \\exists y \\colon \\pair(x,y) \\in R^n \\wedge \\pair(y,z) \\in R \\}$.\n      \\\\[0.2cm]\n      As $\\pair(x,y) \\in R^n$, the induction hypothesis guarantees that the vertices $x$ and $y$ are\n      connected by a path of length $n$.  Hence, this \n      path has the form\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\underbrace{x \\mapsto \\cdots \\mapsto y}_{\\mbox{\\scriptsize path of length $n$.}}$\n      \\\\[0.2cm]\n      Adding $x$ at the end of this path will produce the path\n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $x \\mapsto \\cdots \\mapsto y \\mapsto z$.\n      \\\\[0.2cm]\n      This path has a length of $n + 1$ and, furthermore, connects $x$ and $z$.  Hence $R^{n+1}$\n      contains those pairs $\\pair(x, z)$ that are connected by a path of length $n+1$.\n\\end{enumerate}\nNow the important observation is the following. The set of all vertices is finite.  For the arguments sake, let\nus assume there are $k$ different vertices.  But then every path that has a length of $k$ or greater must\ncontain at least one vertex that is visited more than once and hence this path is longer than necessary,\ni.e.~there is a shorter path that connects the same vertices.  Therefore, for a finite graph with $k$ vertices,\nthe formula to compute the transitive closure can be simplified as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\ds R^+ = \\bigcup\\limits_{i=1}^{k-1} R^i$.\n\\\\[0.2cm]\nWhile we could use this formula as its stands, it is more efficient to use a \\blue{fixed-point iteration} instead.\nTo this end, we prove that the transitive closure $R^+$ satisfies the following equation:\n\\begin{equation}\n  \\label{fixpunkt}\n  R^+ = R \\cup R^+ \\circ R. \n\\end{equation}\nLet me remind you that the precedence of the operator $\\circ$ \nis higher than the precedence of the operator $\\cup$.  Therefore, the expression $R \\cup R^+ \\circ R$ is parenthesized\nas $R \\cup (R^+ \\circ R)$.  Equation \\ref{fixpunkt} can be proven algebraically.  We have:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\begin{array}{cll}\n    & R \\cup R^+ \\circ R \\\\[0.2cm]\n  = & R \\cup \\Bigl(\\bigcup\\limits_{i=1}^{\\infty} R^i \\Bigr) \\circ R \\\\[0.4cm]\n  = & R \\cup \\bigl(R^1 \\cup R^2 \\cup R^3 \\cup \\cdots \\bigr) \\circ R \\\\[0.2cm]\n  = & R \\cup \\bigl(R^1 \\circ R \\cup R^2 \\circ R \\cup R^3 \\circ R \\cup \\cdots \\bigr) \\\\[0.2cm]\n  = & R \\cup \\bigl(R^2 \\cup R^3 \\cup  R^4 \\cup \\cdots \\bigr)  \\\\[0.2cm]\n  = & R^1 \\cup \\bigl(R^2 \\cup R^3 \\cup  R^4 \\cup \\cdots \\bigr) \\\\[0.2cm]\n  = & \\bigcup\\limits_{i=1}^{\\infty} R^i \\\\[0.4cm]\n  = & R^+.\n\\end{array}\n$\n\\\\[0.2cm]\nEquation  \\ref{fixpunkt} can now be used to compute $R^+$ via a fixed-point iteration.\nTo this end, let us define a sequence of relations $(T_n)_{n \\in \\mathbb{N}}$ by induction on $n$:\n\\begin{enumerate}\n\\item[I.A.] $n = 0$: \n\n            $T_0 = R$\n\\item[I.S.] $n \\mapsto n+1$:\n\n            $T_{n+1} = R \\cup T_n \\circ R $. \n\\end{enumerate}\nThe relation  $T_n$ can be expressed via the relation $R$, we have\n\\begin{enumerate}\n\\item $T_0 = R$.\n\\item $T_1 = R \\cup T_0 \\circ R = R \\cup R \\circ R = R^1 \\cup R^2$.\n\\item$\\begin{array}[t]{lcl}\n       T_2  & = & R \\cup T_1 \\circ R \\\\\n            & = & R \\cup (R^1 \\cup R^2) \\circ R \\\\\n            & = & R^1 \\cup R^2 \\cup R^3. \\\\\n       \\end{array}\n      $\n\\end{enumerate}\nIn general, we can show by induction that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$T_n = \\bigcup\\limits_{i=1}^{n+1} R^i$\n\\\\[0.2cm]\nholds for all $n \\in \\mathbb{N}$.  The base case of this proof is immediate from the definition of $T_0$.\nIn the induction step we observe the following:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n \\begin{array}{lcll}\n   T_{n+1} & = & \\ds R \\cup T_n \\circ R & \\mbox{(by definition)} \\\\[0.2cm]\n           & = & \\ds R \\cup \\biggl(\\bigcup\\limits_{i=1}^{n+1} R^i\\biggr) \\circ R &\n                 \\mbox{(by induction hypothesis)} \\\\[0.4cm]\n           & = & \\ds R \\cup \\left(R \\cup \\cdots \\cup R^{n+1}\\right) \\circ R \\\\[0.2cm] \n           & = & \\ds R^1 \\cup R^2 \\cup \\cdots \\cup R^{n+2}  &\n                 \\mbox{(by the distributivity of $\\circ$ over $\\cup$)} \\\\[0.2cm]\n           & = & \\ds \\bigcup\\limits_{i=1}^{n+2} R^i & \\Box \n   \\end{array}\n$\n\\\\[0.2cm]\nThe sequence $(T_n)_{n\\in\\mathbb{N}}$ has another useful property:  It is \n\\blue{monotonically increasing}.  In general, a sequence of sets $(X_n)_{n\\in\\mathbb{N}}$ is called\n\\blue{monotonically increasing} iff we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\forall n \\in \\mathbb{N}: X_n \\subseteq X_{n+1}$,\n\\\\[0.2cm]\ni.e.~the sets $X_n$ get bigger with growing index $n$.\nThe monotonicity of the sequence  $(T_n)_{n \\in \\mathbb{N}}$ is an immediate consequence of the equation\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds T_n = \\bigcup\\limits_{i=1}^{n+1} R^i$ \n\\\\[0.2cm]\nbecause we have:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\begin{array}[t]{llcl}\n                & \\ds T_n \\subseteq T_{n+1} \\\\[0.2cm]\n\\Leftrightarrow & \\ds \\bigcup\\limits_{i=1}^{n+1} R^i \\subseteq \\bigcup\\limits_{i=1}^{n+2} R^i \\\\[0.5cm]\n\\Leftrightarrow & \\ds \\bigcup\\limits_{i=1}^{n+1} R^i \\subseteq \\bigcup\\limits_{i=1}^{n+1} R^i \\cup R^{n+2} \\\\\n\\end{array}\n$\n\\\\[0.2cm]\nIf the relation  $R$ is finite, then the transitive closure $R^+$ is finite, too.  The sets $T_n$ \nare all subsets of $R^+$ because we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds T_n = \\bigcup\\limits_{i=1}^{n+1} R^i \\subseteq \\bigcup\\limits_{i=1}^{\\infty} R^i = R^+$ \\quad for all $n \\in \\mathbb{N}$.\n\\\\[0.2cm]\nHence the sets $T_n$ can not grow indefinitely.  Because of the monotonicity of the sequence \n$(T_n)_{n\\in\\mathbb{N}}$ it follows that there exists an index  $k \\in \\mathbb{N}$ such that the sets $T_n$ do\nnot grow any further once $n$ has reached $k$, i.e.~we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds \\forall n \\in \\mathbb{N}:( n \\geq k \\rightarrow T_n = T_k)$.\n\\\\[0.2cm]\nBut this implies that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds T_n = \\bigcup\\limits_{i=1}^{n+1} R^i = \\bigcup\\limits_{i=1}^{\\infty} R^i = R^+$ \n\\quad holds for all $n \\geq k$.\n\\\\[0.2cm]\nTherefore, the algorithm for computing  $R^+$ iterates the equation \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\ds T_{n+1} = R \\cup T_n \\circ R$\n\\\\[0.2cm]\nuntil the equation  $T_{n+1} = T_n$ is satisfied, since this implies that $T_n = R^+$.\n\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    def product(R1, R2):\n        \"Compute the relational product of R1 and R2.\"\n        return { (x, z) for (x, y1) in R1 for (y2, z) in R2 if y1 == y2 }\n    \n    def transClosure(R):\n        \"Compute the transitive closure of the binary relation R.\"\n        T = R\n        while True:\n            oldT = T\n            T    = product(R,T).union(R)\n            if T == oldT:\n                return T\n    \n    R = { (1,2), (2,3), (1,3), (2,4), (4,5) }\n    print( \"R  = \", R );\n    print( \"Computing the transitive closure of R:\" );\n    T = transClosure(R);\n    print( \"R+ = \", T );\n\\end{Verbatim} \n\\vspace*{-0.3cm}\n\\caption{Computing the transitive closure.}  \n\\label{fig:transitive-closure.py}\n\\end{figure} %\\$\n\n\\noindent\nThe program \n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/transitive-closure.py}{\\texttt{transitive-closure.py}}\nthat is shown in Figure\n\\ref{fig:transitive-closure.py} on page \\pageref{fig:transitive-closure.py} shows an implementation of this idea.\nThe program produces the following output:\n\\begin{verbatim}\n    R  = {(1, 2), (1, 3), (4, 5), (2, 3), (2, 4)}\n    Computing the transitive closure of R:\n    R+ = {(1, 2), (1, 3), (4, 5), (1, 4), (1, 5), (2, 3), (2, 5), (2, 4)}\n\\end{verbatim}\nThe transitive closure $R^+$ of a relation $R$ has a very intuitive interpretation:\nIt contains all pairs $\\pair(x,y)$ such that there is a path leading from \n$x$ to $y$.  \nThe function $\\texttt{product}(R_1, R_2)$ computes the relational product $R_1\\circ R_2$ \naccording to the formula\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$R_1 \\circ R_2 = \\{ \\langle x, z \\rangle \\mid \\exists y:\\bigl(\\pair(x,y) \\in R_1 \\wedge \\pair(y,z) \\in R_2\\bigr) \\}$.\n\n\n\\subsection{Computing the Paths}\nSo far, given a graph represented by a relation $R$ and two vertices $x$ and $y$, we can only check\nwhether there is a path leading from $x$ to $y$, but we cannot compute this path.  In this\nsubsection we will extend the procedure \\texttt{transClosure} so that it will also compute the\ncorresponding path.  The main idea is to extend the notion of a relational product to the notion of\na \\blue{path product}, where a \\blue{path product} is defined on sets of paths.  In order to do so,\nwe introduce three functions for tuples.\n\\begin{enumerate}\n\\item Given a tuple $T$, the function $\\texttt{first}(T)$ returns the first element of $T$: \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\texttt{first}\\bigl(\\langle x_1,\\cdots,x_m\\rangle\\bigr) = x_1$.\n\\item Given a tuple $T$, the function $\\texttt{last}(T)$ returns the last element of $T$: \n      \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $\\texttt{last}\\bigl(\\langle x_1,\\cdots,x_m\\rangle\\bigl) = x_m$.\n\\item If $S = \\langle x_1, \\cdots, x_m\\rangle$ and $T = \\langle y_1, \\cdots, y_n \\rangle$ are two tuples  such that\n      $\\texttt{first}(S) = \\texttt{last}(S)$, we define the \\blue{join} $S \\oplus T$ of $S$ and $T$ as \\\\[0.2cm]\n      \\hspace*{1.3cm}\n      $S \\oplus T = \\langle x_1, \\cdots, x_m, y_2, \\cdots, y_n \\rangle$.\n\\end{enumerate}\nIf $\\mathcal{P}_1$ and $\\mathcal{P}_2$ are sets of tuples representing paths, we define the \\blue{path product} of\n$\\mathcal{P}_1$ and $\\mathcal{P}_2$ as follows: \\\\[0.2cm]\n\\hspace*{1.3cm} \n$\\mathcal{P}_1 \\bullet \\mathcal{P}_2 = \n\\bigl\\{\\; T_1 \\oplus T_2 \\mid T_1 \\in \\mathcal{P}_1 \\wedge T_2 \\in \\mathcal{P}_2 \\wedge \\texttt{last}(T_1) = \\texttt{first}(T_2) \\;\\bigr\\}\n$.\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    def findPaths(R):\n        P = R;\n        while True:\n            oldP = P\n            P    = R.union(pathProduct(P, R))\n            print(P)\n            if P == oldP:\n                return P\n\n    def pathProduct(P, Q):\n        return { join(S, T) for S in P for T in Q if S[-1] == T[0] }\n    \n    def join(S, T):\n        return S + T[1:]\n    \n    R = { (1,2), (2,3), (1,3), (2,4), (4,5) }\n    print(\"R = \", R)\n    print(\"Computing all paths:\" )\n    P = findPaths(R)\n    print(\"P = \", P)\n\\end{Verbatim} \n\\vspace*{-0.3cm}\n\\caption{Computing all connections.}  \\label{fig:path.py}\n\\end{figure} %\\$\n\n\\begin{figure}[!ht]\n  \\centering\n  \\vspace*{-9cm}\n\n  \\epsfig{file=Figures/graph-zykl,scale=0.5}\n  \\vspace*{-1cm}\n\n  \\caption{A graph with a cycle.}\n  \\label{fig:graph-zykl}\n\\end{figure}\n\nUsing the notion of a \\blue{path product} we are able to extend the program shown in Figure\n\\ref{fig:transitive-closure.py} such that it computes all paths between two vertices.\nThe resulting program\n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/path.py}{\\texttt{path.py}}\nis shown in Figure \\ref{fig:path.py} on page \\pageref{fig:path.py}.\nUnfortunately, the program does not work any more if the graph is \\blue{cyclic}.  A graph is defined\nto be \\blue{cyclic} if there is a path of length greater than $1$ that starts and ends at the same\nvertex.  This path is then called a \\blue{cycle}.\nFigure \\ref{fig:graph-zykl} on page \\pageref{fig:graph-zykl} shows a cyclic graph.  This graph is\ncyclic because it contains the path\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\langle 1, 2, 4, 1 \\rangle$\n\\\\[0.2cm]\nand this path is a cycle.\nThe problem with this graph is that it contains an infinite number of paths that connect the vertex\n1 with the vertex 2: \\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\langle 1, 2 \\rangle$, $\\langle 1, 2, 4, 1, 2 \\rangle$, \n$\\langle 1, 2, 4, 1, 2, 4, 1, 2 \\rangle$, \n$\\langle 1, 2, 4, 1, 2, 4, 1, 2, 4, 1, 2 \\rangle$, $\\cdots$\n\\\\[0.2cm]\nOf course, there is no point in computing a path that visits a vertex more than once as these paths\ncontain cycles.  Our goal is to eliminate all those paths that contain cycles.\n\n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{Verbatim}[ numbers       = left,\n                  numbersep     = -0.2cm,\n                  frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  xleftmargin   = 0.0cm,\n                  xrightmargin  = 0.0cm,\n                ]\n    def pathProduct(P, Q):\n        return { join(S, T) for S in P for T in Q\n                            if S[-1] == T[0] and noCycle(S, T)\n               }\n    \n    def noCycle(T1, T2):\n        return len({ x for x in T1 }.intersection({ x for x in T2 })) == 1\n\\end{Verbatim} \n\\vspace*{-0.3cm}\n\\caption{Computing the connections in a cyclic graph.}  \n\\label{fig:path-cyclic.py}\n\\end{figure} %\\$\n\nFigure \\ref{fig:path-cyclic.py} on page shows how the implementation of the function\n\\texttt{pathProduct} has to be changed so that the resulting program\n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/path-cyclic.py}{\\texttt{path-cyclic.py}}\nworks also for cyclic graphs. \n\\begin{enumerate}\n\\item In line 2 and 3, we compute only those paths that are not cyclic.\n\\item Line 6 defines a function \\texttt{noCycle} that tests, whether the join  $\\texttt{T1} \\oplus \\texttt{T2}$ is cyclic.  The join\n      of \\texttt{T1} and \\texttt{T2} is cyclic iff the tuples \\texttt{T1} and \\texttt{T2} have more\n      than one common element.  The tuples \\texttt{T1} and \\texttt{T2} will always have at least one common element, as we join\n      these tuples only if the last element of \\texttt{T1} is equal to the first element of  \\texttt{T2}.\n      If there would be an another vertex common to both \\texttt{T1} and \\texttt{T2}, then the path\n      $\\texttt{T1} \\oplus \\texttt{T2}$ would be cyclic.\n\\end{enumerate}\n\nIn general, we are not really interested to compute all possible paths between two given vertices\n\\texttt{x} and \\texttt{y}.  Instead, we just want to compute the shortest path leading from \\texttt{x} to \\texttt{y}.\nFigure \\ref{fig:find_path.py} on page \\pageref{fig:find_path.py} shows the procedure \\texttt{reachable}. \nThis procedure takes three arguments:\n\\begin{enumerate}\n\\item \\texttt{start} and \\texttt{goal} are vertices of a graph.\n\\item \\texttt{R} is a binary relation representing a directed graph.\n\\end{enumerate}\nThe call  \\texttt{reachable(start, goal, R)} checks whether \\texttt{start} and \\texttt{goal} are connected and, furthermore,\ncomputes the shortest path from \\texttt{start} to \\texttt{goal}, provided such a path exists.\nThe complete program can be found in the file\n\\href{https://github.com/karlstroetmann/Logik/blob/master/Python/find\\_path.py}{\\texttt{find\\_path.py}}.\nNext, we discuss the implementation of the procedure  \\texttt{reachable}.\n\\begin{enumerate}\n\\item Line 2 initializes the set \\texttt{P}.  After $n$ iterations, this set will contain all paths\n      that start with the vertex \\texttt{start} and that have a length of at most $n$.\n\n      Initially, there is just the trivial path $\\langle\\texttt{start}\\rangle$ that starts with vertex\n      \\texttt{start} and has length $0$.\n\\item Line 5 tries to extend all previously computed paths by one step.\n      If we are lucky, the set \\texttt{P} is increased in this step.\n\\item Line 6 selects all those paths from the set \\texttt{P} that lead to the vertex \\texttt{goal}.\n      These paths are stored in the set \\texttt{Found}.\n\\item Line 7 checks whether we have indeed found a path ending at \\texttt{goal}.  This is the case if\n      the set \\texttt{Found} is not empty.  \n      In this case, we return any of these paths.\n\\item If we have not yet found the vertex \\texttt{goal} and, furthermore, we have not been able to find\n      any new paths during this iteration,  the procedure returns in line 10.\n      As the \\texttt{return} statement in line 11 does not return a value, the procedure will\n      instead return the value \\texttt{None}.\n\\end{enumerate}\nThe procedure call \\texttt{reachable(start,goal R)} will compute the \\textbf{shortest} path connecting\n\\texttt{start} and \\texttt{goal} because it computes path with increasing length.  The first iteration\ncomputes all paths starting in \\texttt{start} that have a length of at most 1, the second iteration\ncomputes all paths starting in \\texttt{start} that have a length of at most 2, and in general the $n$-th\niteration computes all paths starting in \\texttt{start} that have a length of at most $n$.  Hence, if\nthere is a path of length $n$, then this path will be found in the $n$-iteration unless a shorter path has\nalready been found in a previous iteration.  \n\n\\remarkEng\nThe algorithm described above is known as \n\\href{https://en.wikipedia.org/wiki/Breadth-first_search}{breadth first search}. \\eox \n\n\\begin{figure}[!ht]\n  \\centering\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    def reachable(start, goal, R):\n        P = { (start,) }\n        while True:\n            oldP  = P\n            P     = P.union(path_product(P, R))\n            Found = { T for T in P if T[-1] == goal }\n            if Found != set({}):\n                return Found.pop()\n            if P == oldP:\n                return\n                \n    def path_product(P, R):\n        return set( add(T1, T2) for T1 in P for T2 in R\n                             if T1[-1] == T2[0] and noCycle(T1, T2)\n                  )\n    \n    def noCycle(T1, T2):\n        return len(set(T1).intersection(set(T2))) == 1\n    \n    def add(T, P):\n        return T + (P[-1],)\n\\end{Verbatim} \n\\vspace*{-0.3cm}\n\\caption{Finding the shortest path between two vertices.}  \n\\label{fig:find_path.py}\n\\end{figure}\n\n\\subsection{The Wolf, the Goat, and the 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]{14cm}\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\nis on the left side of the river. \nTherefore, the set of all possible states can be defined as 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. \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\nNext, 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}\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 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{P}.\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 an element of the power set\n      of \\texttt{S}. \n\\item Then  \\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 \\texttt{S-B} is an element of \\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.union(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\nFigure \\ref{fig:wolf-ziege} on page \\pageref{fig:wolf-ziege} shows the program\n\\href{https://github.com/karlstroetmann/Logik/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{Verbatim}[ codes         = {\\catcode`$=3\\catcode`_=8\\catcode`^=7},\n                  frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.3cm,\n                  xrightmargin  = 0.3cm,\n                ]\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.union(R2)\n    start = All\n    goal  = frozenset()\n    Path  = findPath(start, goal, R)\n\\end{Verbatim} \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{Verbatim}[ codes         = {\\catcode`$=3\\catcode`_=8\\catcode`^=7},\n                  frame         = lines, \n                  framesep      = 0.3cm, \n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    {\"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{Verbatim} \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}\nIn this section we will develop a program that reads an arithmetic expression like \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{\"x * exp(x)\"},\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}\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} represents 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(\"x*exp(x)\", \"x\")} will compute the output\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\"\\texttt{1*exp(x) + x*exp(x)}\"\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}.  The 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 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$\\langle\\texttt{\"}*\\texttt{\"}, \\texttt{\"}x\\texttt{\"}, \\langle \\texttt{\"}\\mathtt{exp}\\texttt{\"}, \\texttt{\"}x\\texttt{\"} \\rangle\\rangle$.\n\\\\[0.2cm]\nIn order to be able to convert string into nested tuples, we need a \\blue{parser}.  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 algorithms.\n\n\\noindent\nWe close this section by showing an example that demonstrates the power of matching.\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/Logik/blob/master/Python/diff.py}{\\texttt{diff.py}}.\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(\"x ** x\")}.\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{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  firstnumber   = 1,\n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    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{Verbatim}\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(\"x ** x\")}\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{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  firstnumber   = 1,\n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    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{Verbatim}\n\\vspace*{-0.3cm}\n\\caption{Testing symbolic differentiation.}\n\\label{fig:test-diff.py}\n\\end{figure}\n\n\n\n\\pagebreak\n\\vspace*{\\fill}\n\n\\section{Reflection}\nAfter having completed this chapter, you should be able to answer the following questions.\n\\begin{enumerate}\n\\item Which data types are supported in \\textsl{Python}?\n\\item What are the different methods to define a set in \\textsl{Python}?\n\\item Do you understand how to construct lists via iterator? \n\\item How can lists be defined in \\textsl{Python}?\n\\item How does \\textsl{Python} support binary relations?\n\\item How does list slicing and list indexing work?\n\\item What are nested tuples?\n\\item How does a fixed-point algorithm work?\n\\item What type of control structures are supported in \\textsl{Python}?\n\\end{enumerate}\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"logic\"\n%%% End:\n", "meta": {"hexsha": "048ff2e3fe36fc9fb471dc9dc7f29ed28c78354d", "size": 57245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-Notes-Python/case-studies.tex", "max_stars_repo_name": "AbdalrohmanGitHub/Logik", "max_stars_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-Notes-Python/case-studies.tex", "max_issues_repo_name": "AbdalrohmanGitHub/Logik", "max_issues_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-Notes-Python/case-studies.tex", "max_forks_repo_name": "AbdalrohmanGitHub/Logik", "max_forks_repo_head_hexsha": "62270c224061f38b637cb6920a0fbe5a56495bb9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7228434505, "max_line_length": 222, "alphanum_fraction": 0.6346929863, "num_tokens": 18184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.7839987543600179}}
{"text": "\\section{Regular expressions}\n\nIn \\Pascal, an identifier is a letter followed by zero or more letters\nor digits, that is, and identifier is a member of the set defined by\n\\(L(L \\cup D)^{*}\\). The notation we introduced so far is comfortable\nfor mathematics but not for computers. Let us introduce another\nnotation, called \\emph{regular expressions}, for describing the same\nlanguages and define its meaning in terms of the mathematical\nnotation. With this notation, we might define \\Pascal identifiers as\n\\begin{center}\n\\term{letter} \\lparen\\term{letter} \\disj \\term{digit}\\rparen\\kleene\n\\end{center}\nwhere the vertical bar means `or', the parentheses group\nsubexpressions, the star means `zero or more instances of' the\nprevious expression and juxtaposition means concatenation. A regular\nexpression~\\(r\\) is built up out of simpler regular expressions using\na set of rules, as follows. Let~\\(\\Sigma\\) be an alphabet and \\(L(r)\\)\nthe language denoted by~\\(r\\). Then\n\\begin{enumerate*}\n\n   \\item \\(\\epsilon\\) is a regular expression that denotes\n     \\(\\{\\varepsilon\\}\\);\\label{regexp_empty}\n\n   \\item if \\(a \\in \\Sigma\\), then \\(a\\)~is a regular expression that\n     denotes~\\(\\{a\\}\\). This is ambiguous: \\(a\\)~can denote a\n     language, a word or a letter --~it depends on the\n     context; \\label{regexp_sym}\n\n   \\item assume \\(r\\)~and~\\(s\\) denote the languages \\(L(r)\\)~and\n     \\(L(s)\\); \\(a\\)~denotes a letter. Then \\label{regexp_rec}\n   \\begin{enumerate*}\n    \n     \\item \\(r\\) \\disj \\(s\\) is a regular expression\n     denoting \\(L(r) \\cup L(s)\\);\n\n     \\item \\(r s\\) is a regular expression denoting \\(L(r) L(s)\\);\n\n     \\item \\(r\\)\\kleene{} is a regular expression\n     denoting \\((L(r))^{*}\\);\n\n     \\item \\lparen\\(r\\)\\rparen{} is a regular expression\n     denoting \\(L(r)\\);\n\n     \\item \\(\\overline{a}\\) is a regular expression denoting\n       \\(\\Sigma\\backslash \\{a\\}\\).\n\n   \\end{enumerate*}\n\n\\end{enumerate*}\nA language described by a regular expression is a \\emph{regular\n  language}. Rules~\\ref{regexp_empty} and~\\ref{regexp_sym} form the\nbase of the definition. Rule~\\ref{regexp_rec} provides the inductive\nstep. Unnecessary parentheses can be avoided in regular expressions if\n\\begin{itemize*}\n\n  \\item the unary operator \\kleene{} has the highest precedence and\n  is left associative,\n\n  \\item concatenation has the second highest precedence and is left\n  associative,\n\n  \\item \\disj{} has the lowest precedence and is left associative.\n\n\\end{itemize*}\nUnder those conventions, \\lparen\\(a\\)\\rparen{} \\disj\n\\lparen\\lparen\\(b\\)\\rparen\\kleene\\lparen\\(c\\)\\rparen\\rparen{} is\nequivalent to \\(a\\) \\disj \\(b\\)\\kleene\\(c\\). Both expressions denote\nthe language containing either the string \\(a\\) or zero or more\n\\(b\\)'s followed by one \\(c\\): \\(\\{a, c, bc, bbc, bbbc, \\dots\\}\\). For\nexample,\n\\begin{itemize*}\n\n  \\item the regular expression \\(a\\) \\disj \\(b\\) denotes the set\n    \\(\\{a, b\\}\\);\n\n  \\item the regular expression \\lparen\\(a\\) \\disj\n    \\(b\\)\\rparen\\lparen\\(a\\) \\disj \\(b\\)\\rparen{} denotes \\(\\{aa, ab,\n    ba, bb\\}\\), the set of all strings of \\(a\\)'s and \\(b\\)'s of\n    length two. Another regular expression for the set is \\(aa\\) \\disj\n    \\(ab\\) \\disj \\(ba\\) \\disj \\(bb\\);\n\n  \\item the regular expression \\(a\\)\\kleene{} denotes the set of all\n    strings of zero or more \\(a\\)'s, i.e. \\(\\{\\varepsilon, a, aa, aaa,\n    \\dots\\}\\);\n\n  \\item the regular expression \\lparen\\(a\\) \\disj\n    \\(b\\)\\rparen\\kleene{} denotes the set of all strings containing\n    zero of more instances of an \\(a\\) or \\(b\\), that is the language\n    of all words made of \\(a\\)'s and \\(b\\)'s. Another expression is\n    \\lparen\\(a\\)\\kleene\\(b\\)\\kleene\\rparen\\kleene.\n\n\\end{itemize*}\nIf two regular expressions \\(r\\)~and~\\(s\\) denote the same language,\nwe say that \\(r\\)~and~\\(s\\) are \\emph{equivalent} and write \\(r =\ns\\). In \\fig~\\vref{fig:laws},\n\\begin{figure}\n\\centering\n\\begin{tabular}{c|l}\n\\toprule\n  \\multicolumn{1}{c}{\\textsc{Law}}\n& \\multicolumn{1}{c}{\\textsc{Description}}\\\\\n\\midrule\n  \\(r\\) \\disj \\(s\\) = \\(s\\) \\disj \\(r\\)\n& \\disj is commutative\\\\\n\\hline\n  \\(r\\) \\disj \\lparen\\(s\\) \\disj \\(t\\)\\rparen{}\n  = \\lparen\\(r\\) \\disj \\(s\\)\\rparen{} \\disj \\(t\\)\n& \\disj is associative\\\\\n\\hline\n  \\lparen\\(rs\\)\\rparen \\(t\\) = \\(r\\)\\lparen\\(st\\)\\rparen\n& concatenation is associative\\\\\n\\hline\n  \\(r\\)\\lparen\\(s\\) \\disj \\(t\\)\\rparen{} = \\(rs\\) \\disj \\(rt\\)\n& concatenation distributes over \\disj\\\\\n  \\lparen\\(s\\) \\disj \\(t\\)\\rparen \\(r\\) = \\(sr\\) \\disj \\(tr\\)\n&\\\\\n\\hline\n  \\(\\epsilon r = r\\) \n& \\(\\epsilon\\) is the identity element\\\\\n  \\(r \\epsilon = r\\)\n& for the concatenation\\\\\n\\hline\n  \\(r\\)\\kleene\\kleene = \\(r\\)\\kleene\n& Kleene closure is idempotent\\\\\n\\hline\n  \\(r\\)\\kleene = \\(r\\)\\plus \\disj \\(\\epsilon\\)\n& Kleene closure and positive closure\\\\\n  \\(r\\)\\plus = \\(r r\\)\\kleene\n& are closely linked\\\\\n\\bottomrule\n\\end{tabular}\n\\caption{Algebraic laws on regular languages\\label{fig:laws}}\n\\end{figure}\nwe show useful algebraic laws on regular languages.\n\n\\subsection*{Regular definitions}\n\nIt is convenient to give names to regular expressions and define new\nregular expressions using these names as if they were symbols. If\n\\(\\Sigma\\) is an alphabet, then a \\emph{regular definition} is a\nseries of definitions of the form\n\\begin{align*}\n    d_1 &\\rightarrow r_1\\\\\n    d_2 &\\rightarrow r_2\\\\\n    &\\cdots\\\\\n    d_n &\\rightarrow r_n\n\\end{align*}\nwhere each \\(d_i\\) is a distinct name and each \\(r_i\\) is a regular\nexpression over the alphabet \\(\\Sigma \\cup \\{d_1, d_2, \\dots,\nd_{i-1}\\}\\), \\emph{i.e.,} the basic symbols and the previously defined\nnames. The restriction to \\(d_j\\) such \\(j < i\\) allows to construct a\nregular expression over \\(\\Sigma\\) only by repeatedly replacing all\nthe names in it. For instance, as we have stated, the set of \\Pascal\nidentifiers can be defined by the regular definitions\n\\begin{align*}\n\\term{letter} & \\rightarrow \\text{\\exc{A} \\disj \\exc{B} \\disj\n  \\ldots \\disj \\exc{Z} \\disj \\exc{a} \\disj \\exc{b} \\disj \\ldots \\disj\n  \\exc{z}} \\\\\n\\term{digit} & \\rightarrow \\text{\\exc{0} \\disj \\exc{1} \\disj \\exc{2}\n  \\disj \\exc{3} \\disj \\exc{4} \\disj \\exc{5} \\disj \\exc{6} \\disj\n  \\exc{7} \\disj \\exc{8} \\disj \\exc{9}}\\\\\n\\term{id} & \\rightarrow \\text{\\term{letter} \\lparen\\term{letter}\n  \\disj \\term{digit}\\rparen\\kleene}\n\\intertext{Unsigned numbers in \\Pascal are strings like\n\\texttt{5280}, \\texttt{39.37}, \\texttt{6.336E4}\nor \\texttt{1.894E-4}.}\n\\term{digit} & \\rightarrow \\text{ \\exc{0} \\disj \\exc{1} \\disj \\exc{2}\n  \\disj \\exc{3} \\disj \\exc{4} \\disj \\exc{5} \\disj \\exc{6} \\disj\n  \\exc{7} \\disj \\exc{8} \\disj \\exc{9}}\\\\\n\\term{digits} & \\rightarrow \\text{\\term{digit} \\term{digit}\\kleene}\\\\\n\\term{optional\\_fraction} & \\rightarrow \\text{\\exc{.} \\term{digits}\n  \\disj} \\, \\epsilon\\\\\n\\term{optional\\_exponent} & \\rightarrow \\text{\\lparen\\exc{E} \\lparen\n  \\exc{+} \\disj \\exc{-} \\disj} \\, \\epsilon \\, \\text{\\rparen{}\n  \\term{digits}\\rparen{} \\disj} \\, \\epsilon\\\\\n\\term{num} & \\rightarrow \\text{\\term{digits} \\term{optional\\_fraction}\n  \\term{optional\\_exponent}}\n\\end{align*}\nCertain constructs occur so frequently in regular expressions that it\nis convenient to introduce notational shorthands for them:\n\\begin{itemize}\n\n  \\item \\emph{Zero or one instance.} The unary operator `\\opt{}' means\n    `zero or one instance of.' Formally, by definition, if~\\(r\\) is a\n    regular expression then \\(r\\)\\opt = \\(r\\) \\disj \\(\\epsilon\\). In\n    other words, \\lparen\\(r\\)\\rparen\\opt{} denotes the language \\(L(r)\n    \\cup \\{\\varepsilon\\}\\).\n\\begin{align*}\n\\term{digit} & \\rightarrow \\text{\\exc{0} \\disj \\exc{1} \\disj \\exc{2}\n  \\disj \\exc{3} \\disj \\exc{4} \\disj \\exc{5} \\disj \\exc{6} \\disj\n  \\exc{7} \\disj \\exc{8} \\disj \\exc{9}}\\\\\n\\term{digits} & \\rightarrow \\text{\\term{digit}\\plus}\\\\\n\\term{optional\\_fraction} & \\rightarrow \\text{\\lparen\\exc{.}\n  \\term{digits}\\rparen\\opt}\\\\\n\\term{optional\\_exponent} & \\rightarrow \\text{\\lparen\\exc{E} \\lparen\n  \\exc{+} \\disj \\exc{-}\\rparen\\opt{} \\term{digits}\\rparen\\opt}\\\\\n\\term{num} & \\rightarrow \\text{\\term{digits} \\term{optional\\_fraction}\n  \\term{optional\\_exponent}}\n\\end{align*}\n\n \\item It is also possible to write:\n\\begin{align*}\n\\term{digit} & \\rightarrow \\text{\\exc{0} \\disj \\exc{1} \\disj \\exc{2}\n  \\disj \\exc{3} \\disj \\exc{4} \\disj \\exc{5} \\disj \\exc{6} \\disj\n  \\exc{7} \\disj \\exc{8} \\disj \\exc{9}}\\\\\n\\term{digits} & \\rightarrow \\text{\\term{digit}\\plus}\\\\\n\\term{fraction} & \\rightarrow \\text{\\exc{.} \\term{digits}}\\\\\n\\term{exponent} & \\rightarrow \\text{\\exc{E} \\lparen \\exc{+} \\disj\n  \\exc{-}\\rparen\\opt{} \\term{digits}}\\\\\n\\term{num} & \\rightarrow \\text{\\term{digits} \\term{fraction}\\opt{}\n  \\term{exponent}\\opt}\n\\end{align*}\n\n\\end{itemize}\nIf we want to specify the characters `\\texttt{?}', `\\texttt{*}',\n`\\texttt{+}', `\\texttt{|}', we write them with a preceding backslash,\n\\emph{e.g.,} `\\verb+\\?+', or between double-quotes, \\emph{e.g.,}\n\\verb+\"?\"+. Then, of course, the character double-quote must have a\nbackslash: \\verb+\\\"+. It is also sometimes useful to match against end\nof lines and end of files: \\verb+\\n+ stands for the control character\n`end of line' and \\term{\\$} is for `end of file'.\n\n\\subsection*{Non-regular languages}\n\nSome languages cannot be described by any regular expression. For\nexample, the language of balanced parentheses cannot be recognised by\nany regular expression: \\lparen\\rparen, \\lparen\\lparen\\rparen\\rparen,\n\\lparen\\rparen\\lparen\\rparen,\n\\lparen\\lparen\\lparen\\rparen\\rparen\\lparen\\rparen\\rparen{}\netc. Another example is the C programming language: it is not a\nregular language because it contains embedded blocs between `\\verb+{+'\nand `\\verb+}+'. Therefore, a lexer cannot recognise valid C programs:\nwe need a parser.\n\n\\paragraph{Exercises}\n\n\\input{regexp_question_01}\n\\input{regexp_answer_01}\n\\input{regexp_question_02}\n\\input{regexp_answer_02}\n\\input{regexp_question_03}\n\\input{regexp_answer_03}\n", "meta": {"hexsha": "929c5dcd8b0e02fdb8058e58a5f876376e1b3132", "size": 9795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "regexp.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.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.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.3086419753, "max_line_length": 70, "alphanum_fraction": 0.6725880551, "num_tokens": 3290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094145755219, "lm_q2_score": 0.877476793890012, "lm_q1q2_score": 0.7838582810534925}}
{"text": "\\subsubsection{Snapshots and Transformations to a Frequency Domain}\n\nWhile it is often useful to know the exact state of the system at any time step $q$, this actually leads to problems in practical implementations:\n\n\\begin{description}\n  \\item[Memory Consumption] Assuming that each value is a complex value with double precision leads to a space consumption of $2\\cdot\\SI{64}{bit}$ = \\SI{128}{bit} or \\SI{16}{byte} for every single point of $\\mathbf{E}$ and $\\mathbf{H}$. A cubic system with a side length of \\SI{200}{nm} and a grid size of \\SI{0.5}{nm} already has 64 million points which corresponds to about \\SI{976}{mb} of memory consumption just for the $\\mathbf{E}$ field for a single point in time.\n  \\item[Mixed $\\mathbf{E}$ and $\\mathbf{H}$ Fields] If the discretisation $\\Delta_t$ is not corresponding to the period of the electromagnetic wave there will be a mixture of $\\mathbf{E}$ and $\\mathbf{H}$ at any given timestep $q$ which is undesired in most cases because only the $\\mathbf{E}$ field might be of interest. The same problem arises for the spatial propagation of the wave.\n\\end{description}\n\nTo solve these problems most implementations of FDTD transform the electric field $\\mathbf{E}(\\mathbf{x},t)$ with a Fourier transformation to $\\mathbf{E}(\\mathbf{x}, \\nu)$ with $\\nu$ being the frequency of the electric field. In case only a specific frequency $\\nu$ is of interest all other values can already be discarded while the simulation is running which is greatly reducing the memory needed to perform a calculation.\n\nThis also solves the problem of mixed fields: Over many time steps $q$ the calculated $\\mathbf{E}$ values will average out the error that would be present by just using a single iteration.\n", "meta": {"hexsha": "47c7dca938f1e618ff2238897bcb37f5467f1e2b", "size": 1729, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/1_theoretical_basis/19_fourier_transform.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/19_fourier_transform.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/19_fourier_transform.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": 133.0, "max_line_length": 470, "alphanum_fraction": 0.7628687102, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765163620468, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7837225740138324}}
{"text": "% !TEX root = index.tex\n\n\\section{Vector spaces}\n\n\\subsection{Motivation}\n\\label{section:VectorSpaces}\nA \\emph{scalar} is a real number.\nA (column) \\emph{vector} $\\vec{v}$ of size $n$ is a column of $n$ scalars\n\\begin{align*}\n  \\vec{v} =\n  \\begin{bmatrix}\n    v_1 \\\\\n    v_2 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{bmatrix}\n\\end{align*}\nThe scalars $v_i$ are called the \\textit{coordinates} of $\\vec{v}$.\nThe set of all (column) vectors is called the \\emph{Euclidean space} of dimension $n$ and is denoted by $\\bbr^n$.\nDenote by $\\vec{0}$ the vector with all coordinates 0.\n$\\vec{e}_i$ is the vector whose $i^{th}$ coordinate is 1 and all other coordinates are 0.\nThe vector $\\vec{e}_i$ is called the \\emph{$i^{th}$ standard basis vector} and the collection $\\calb= \\set{\\vec{e}_1, \\dots, \\vec{e}_n}$ is called the \\emph{standard basis}.\n\nThe spaces $\\bbr^1$, $\\bbr^2$, $\\bbr^3$ are very commonly studied objects, but unfortunately, most of us are unable to visualize the higher dimensions.\nLinear algebra is the language that lets us do exactly this.\n\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n    \\input{images/r1.tex}\n    \\caption*{$\\bbr^1$ is the real line,}\n  \\end{subfigure}\n  \\hfill\n  \\begin{subfigure}[b]{0.45\\textwidth}\n    \\input{images/r2.tex}\n    \\caption*{$\\bbr^2$ is the Euclidean plane,}\n  \\end{subfigure}\n\\end{figure}\n\\begin{figure}[H]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n    \\input{images/r3.tex}\n    \\caption*{$\\bbr^3$ is the three dimensional space,}\n  \\end{subfigure}\n  \\hfill\n  \\begin{subfigure}[b]{0.45\\textwidth}\n    {\\Huge \\begin{align*}\n      ?\n    \\end{align*}}\n    \\caption*{What does $\\bbr^n$ look like?}\n  \\end{subfigure}\n\\end{figure}\n\n\nThere are two operations we can perform on vectors in $\\bbr^n$:\n\\begin{enumerate}\n  \\item\\textbf{Scalar multiplication:} Given a scalar $c$ and a vector $\\vec{v}$, the vector $c \\vec{v}$ is the vector obtained by multiplying every coordinate of $\\vec{v}$ by $c$.\n\n  Geometrically, this is scaling the vector $\\vec{v}$ by a factor of $c$.\\footnote{If $c$ is negative, we ``flip'' $\\vec{v}$ across the origin.}\n\n  \\item\\textbf{Addition:} Given two vectors $\\vec{v}$, $\\vec{w}$, the sum $\\vec{v} + \\vec{w}$ is the vector obtained by adding the respective coordinates.\n\n  Geometrically, vector addition is given by the Parallelogram Law.\n\\end{enumerate}\n\\begin{qbox}\n  \\label{q:parallelogramLaw}\n    Let $\\vec{v} = \\begin{bmatrix}v_1 \\\\ v_2\\end{bmatrix}$ and $\\vec{w} = \\begin{bmatrix}w_1 \\\\ w_2\\end{bmatrix}$ be vectors in $\\bbr^2$.\n    Verify that\n    \\begin{align*}\n      \\vec{0}, \\: \\vec{v}, \\: \\vec{v} + \\vec{w}, \\: \\vec{w}\n    \\end{align*}\n    form the vertices of a parallelogram.\\tablefootnote{Here we are thinking of vectors as points. It can be a bit confusing at first, to switch between points and arrows, but this flexibility is very useful once you get used to it.}\n    This is called the \\textit{parallelogram law of vector addition}. The parallelogram law holds even for $\\bbr^n$.\n    \\begin{figure}[H]\n      \\input{images/ParallelogramLaw.tex}\n      \\caption{Parallelogram law of vector addition.}\n    \\end{figure}\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\\subsubsection{Lines and planes in $\\bbr^3$}\nA line in $\\bbr^2$ is given by an equation $y = mx + c$. What about a line in $\\bbr^3$?\nOne way to decribe a line in $\\bbr^3$ is using vector notation.\n\\begin{ex}\n  \\label{example:lineAsSpan}\n  Every line $L$ in $\\bbr^3$ passing through the origin can be written as\n  \\begin{align*}\n    L = \\set{c \\vec{v} : c \\in \\bbr}\n  \\end{align*}\n  where $\\vec{v}$ is a vector in $\\bbr^3$.\n  We can then \\emph{define} a line passing through the origin in $\\bbr^n$ as $\\set{c \\vec{v} : c \\in \\bbr}$ for some $\\vec{v} \\in \\bbr^n$.\n\\end{ex}\n\nWhat about a plane? We needed one vector to describe a line. We will need two to describe a plane.\n\n\\begin{qbox}\n  \\label{q:planeAsSpan}\n    Let $\\vec{v}_1$ and $\\vec{v}_2$ be non-zero vectors in $\\bbr^2$ which are not scalar multiples of each other.\n    Using the Parallelogram Law from Q. \\ref{q:parallelogramLaw} , argue that for every vector $\\vec{v}$ in $\\bbr^2$ there exist scalars $c_1, c_2$ such that \\begin{equation*}\n      \\vec{v} = c_1 \\vec{v}_1 + c_2 \\vec{v}_2.\n  \\end{equation*}\n    \\begin{figure}[H]\n      \\input{images/planeBasis.tex}\n    \\end{figure}\n    So that we can write $\\bbr^2$ as\n    \\begin{align*}\n      \\bbr^2 = \\set{c_1 \\vec{v}_1 + c_2 \\vec{v}_2 : c_1, c_2 \\in \\bbr}\n    \\end{align*}\n\\end{qbox}\n\\begin{qbox}\n  What is the set $\\set{c_1 \\vec{v}_1 + c_2 \\vec{v}_2 : c_1, c_2 \\in \\bbr}$, if $\\vec{v}_1$ is a scalar multiple of $\\vec{v}_2$, for $\\vec{v}_1$, $\\vec{v}_2 \\in \\bbr^2$.\n\\end{qbox}\n\nOne can similarly check that if $\\vec{v}_1$ and $\\vec{v}_2$ are non-zero vectors in $\\bbr^3$ which are not scalar multiples of each other, the set $\\set{c_1 \\vec{v}_1 + c_2 \\vec{v}_2 : c_1, c_2 \\in \\bbr}$ describes planes passing through the origin.\nWe then \\emph{define} a plane in $\\bbr^n$ passing through the origin, to be a set of the form $\\set{c_1 \\vec{v}_1 + c_2 \\vec{v}_2 : c_1, c_2 \\in \\bbr}$.\n\n\\begin{qbox}\n  How would you define lines and planes in $\\bbr^n$ not necessarily passing through the origin (using vector notation)?\n\\end{qbox}\n\nOur goal then is to generalize this entire story to higher dimensions, by defining ``\\emph{$m$ dimensional subspaces of $\\bbr^n$}''.\nWe'll first define a subspace, then slowly move toward defining dimension\\footnote{Which is a surprisingly difficult thing to define!}.\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Subspaces}\n\\begin{definition}\n  A \\emph{subspace} of $\\bbr^n$ is a \\emph{non-empty} subset $V \\subseteq \\bbr^n$ satisfying the following conditions.\n  \\begin{enumerate}\n    \\item (closed under scalar multiplication) For every real number $c$ and vector $\\vec{v}$ in $V$, the vector $c \\vec{v}$ is in $V$.\n    \\item (closed under addition) For every $\\vec{v}$ and $\\vec{w}$ in $V$, the vector $\\vec{v} + \\vec{w}$ is in $V$.\n  \\end{enumerate}\n\\end{definition}\nSubspaces, and more generally abstract vector spaces, are the primary objects of study in linear algebra.\n\n\\begin{qbox}\n  \\begin{enumerate}\n    \\item Show that $\\bbr^n$ is a subspace of $\\bbr^n$.\n    \\item Show that the set $V = \\{\\vec{0}\\}$ is a subspace of $\\bbr^n$.\n    \\item For any subspace $V \\subseteq \\bbr^n$, show that the vector $\\vec{0}$ is in $V$.\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}\n  Determine, with proof, all the subspaces of $\\bbr^1$.\n\\end{qbox}\n\n\nWe already know two subspaces of $\\bbr^2$: $\\set{0}$ and $\\bbr^2$.\n$\\bbr^2$ has one other family of subspaces given by lines.\n\\begin{qbox}\n  When is the line in $\\bbr^2$ a subspace of $\\bbr^2$? What about $\\bbr^3$?\n\\end{qbox}\n\n\\begin{qbox}\n  When is a plane in $\\bbr^3$ a subspace of $\\bbr^3$?\n\\end{qbox}\n\n\\begin{qbox}\n  Make a guess as to what all the subspaces of $\\bbr^2$ and $\\bbr^3$ are. How would you prove this?\\tablefootnote{We will give a rigorous proof of this tomorrow.}\n\\end{qbox}\n\n\\begin{qbox}\n  Let $V$ and $W$ be subspaces of $\\bbr^n$.\n  \\begin{enumerate}\n    \\item Show that the intersection $V \\cap W$ is also a subspace.\n    \\item What can you say about the union $V \\cup W$?\n  \\end{enumerate}\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Span, Linear Independence, and Basis}\n$\\spn$ is a general procedure for constructing subspaces of $\\bbr^n$. It generalizes the concepts in Example \\ref{example:lineAsSpan} and Q. \\ref{q:planeAsSpan}.\n\n\\begin{definition}\n  For a subset $S$ of  $\\bbr^n$, the span of $S$ is defined to be the set of finite \\emph{linear combinations} of elements of $S$.\n  \\begin{align*}\n    \\spn(S) := \\{ c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k \\quad : \\quad\n    & c_1, \\dots, c_k \\mbox{ are real numbers}, \\\\\n    & \\vec{v}_1, \\dots, \\vec{v}_k \\mbox{ are vectors in } S \\}\n  \\end{align*}\n  For the empty set $ \\varnothing \\subseteq \\bbr^n$ we define $\\spn(\\varnothing):=\\{\\vec{0}\\}$.\n  We think of $S$ as being a \\emph{generating set} of the subspace $\\spn(S)$.\n\\end{definition}\n\n\\begin{qbox}\n  Let $S$ be a subset of $\\bbr^n$. Show that $\\spn(S)$ is a subspace of $\\bbr^n$.\n\\end{qbox}\n\n\\begin{qbox}[Practice problems]\n  \\label{q:span}\n  Find simple descriptions of $\\spn$s of the following subsets of $\\bbr^3$.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $\\set{ \\vec{e_1}}$\n      \\item $\\set{\\vec{e}_1, \\vec{e}_{2}}$\n      \\item $\\set{\\vec{e}_1, \\vec{e}_2 , \\vec{e}_3}$\n      \\item $\\bbr^3$\n      % \\item $\\set{\\begin{bmatrix} 1 \\\\ 0 \\\\ 0\\end{bmatrix}, \\begin{bmatrix} -1 \\\\ 1 \\\\ 0 \\end{bmatrix}}$\n      \\item $\\set{\\vec{e}_1,\\vec{e}_1 + \\vec{e}_2, \\vec{e}_3}$\n      \\item $\\set{\\vec{e}_1-\\vec{e}_2, \\vec{e}_2-\\vec{e}_3, \\vec{e}_3-\\vec{e}_1}$\n      \\item The plane $z = 0$\n      \\item The plane $z = 1$\n      % \\item $\\set{\\begin{bmatrix} 1 \\\\ 0 \\\\ 0\\end{bmatrix}, \\begin{bmatrix} -1 \\\\ 1 \\\\ 0 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 2 \\\\ 0\\end{bmatrix}}$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\\begin{qbox}\n  Let $S$ be a subset of $\\bbr^n$ and $V$ be a subspace of $\\bbr^n$.\n  Show that\n  \\begin{equation*}\n    \\mbox{if } S \\subseteq V \\mbox{ then }\\spn(S) \\subseteq V.\n  \\end{equation*}\n  Thus $\\spn(S)$ is the \\emph{smallest vector space} containing $S$.\n\\end{qbox}\n\nThe notion of $\\spn$ allows for redundancies. For example, the set $\\set{\\vec{e}_1, \\vec{e}_2 , \\vec{e}_3}$ has 3 elements and the set $\\bbr^3$ has infinitely many, but both of these sets have the same $\\spn$.\nThis redundancy is precisely captured by \\emph{linear dependence}.\n\n\\begin{definition}\n  \\label{def:linearIndependence}\n  A finite set of vectors $\\cals = \\set{\\vec {v}_1, \\dots, \\vec{v}_k} \\subseteq \\bbr^n$ is \\emph{linearly dependent} if there exist real numbers $c_1, \\dots, c_k$, not all 0, satisfying\n  \\begin{equation*}\n    c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k = 0.\n  \\end{equation*}\n  $\\cals$ is called \\emph{linearly independent} otherwise i.e. $\\cals$ is \\emph{linearly independent} if the only real numbers $c_1, \\dots, c_k$ for which\n  \\begin{equation*}\n    c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k = 0.\n  \\end{equation*}\n  are $c_1 = \\dots = c_k = 0$.\n\n  An infinite set $\\cals \\subseteq \\bbr^n$ is said to be \\emph{linearly dependent} if it contains a finite subset which is linearly dependent, it is called \\emph{linearly independent} otherwise.\n\\end{definition}\n\n\\begin{qbox}\n  Let $\\vec{v}_1$, $\\vec{v}_2$ be vectors in $\\bbr^n$.\n  \\begin{enumerate}\n    \\item When is the set $\\cals = \\set{\\vec{v}_1}$ linearly independent?\n    \\item When is the set $\\cals' = \\set{\\vec{v}_1, \\vec{v}_2}$ linearly independent?\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}\n  \\sout{Is the empty set $\\varnothing \\subset \\bbr^n$ linearly dependent or independent?}\n\\end{qbox}\n\n\\begin{qbox}\n  \\begin{enumerate}\n    \\item Show that a set $\\cals$ is linearly independent if and only if every subset of $\\cals$ is linearly independent.\n    \\item Is the statement still true if we replace linear independence with linear dependence?\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{definition}\n  For a subspace $V$ of $\\bbr^n$, a set $\\calb \\subseteq V$ is said to be a \\emph{basis} of $V$ if\n  \\begin{enumerate}\n    \\item $\\spn(\\calb) = V$,\n    \\item ${\\calb}$ is linearly independent.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{qbox}\n  For each of the sets $\\cals$ in Q. \\ref{q:span}, find a basis of $\\spn(\\cals)$.\n\\end{qbox}\n\nThe following theorem is what makes a basis extremely useful.\n\n\\begin{theorem}\n  \\label{theorem:generalizedCoordinates}\n  Let $V$ be a subspace of $\\bbr^n$ with a basis $\\calb = \\set{\\vec{v}_1, \\dots, \\vec{v}_k}$.\n  For every vector $\\vec{v}$ in $V$ there exist unique scalars $c_1, \\dots, c_k$ such that\n  \\begin{align*}\n    \\vec{v} = c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k.\n  \\end{align*}\n\\end{theorem}\n\n\\begin{qbox}\n  Prove Theorem \\ref{theorem:generalizedCoordinates}.\\hint{First show that the scalars $c_i$ exist. Then argue that they are unique using a proof by contradiction.}\n\\end{qbox}\n\n\\begin{definition}\n  Let $V$ be a subspace of $\\bbr^n$ with a basis $\\calb = \\set{\\vec{v}_1, \\dots, \\vec{v}_k}$.\n  If $\\vec{v} = c_1 \\vec{v}_1 + \\dots + c_k \\vec{v}_k$ as in Theorem \\ref{theorem:generalizedCoordinates}, we denote\n  \\begin{align*}\n    \\coords{v}{\\calb}\n    = \\begin{bmatrix}\n      c_1 \\\\\n      \\vdots \\\\\n      c_k\n      \\end{bmatrix}.\n  \\end{align*}\n  The $c_i$'s are the \\emph{coordinates} of $\\vec{v}$ in the basis $\\calb$.\n\\end{definition}\nThus if the subspace $V$ has a basis $\\calb$ of size $k$ then $V$ ``behaves'' like the Euclidean space $\\bbr^k$.\n\\begin{ex}\n  If $\\vec{v}$\n  is a vector in $\\bbr^n$ and $\\calb$ is the standard basis, then $\\coords{v}{\\calb} = \\vec{v}$, hence the name \\emph{standard basis}.\n  The standard basis is a special basis that exists only for $\\bbr^n$, for other vector spaces there is usually no natural choice of a basis.\n  But we will show that \\emph{a} basis always exists.\n\\end{ex}\n\n\\begin{qbox}\n    Let $V$ be a subspace of $\\bbr^n$ with a basis $\\calb = \\set{\\vec{v}_1, \\dots, \\vec{v}_k}$.\n    Let $\\vec{v}$, $\\vec{w}$ be vectors in $V$ and let $\\alpha$ be a scalar.\n    Show that\n    \\begin{enumerate}\n      \\item $[\\alpha \\vec{v}]_\\calb = \\alpha [\\vec{v}]_\\calb$\n      \\item $[\\vec{v} + \\vec{w}]_\\calb = [\\vec{v}]_\\calb + [\\vec{w}]_\\calb$\n      \\item $\\vec{v} = \\vec{w}$ if and only if $[\\vec{v}]_\\calb = [\\vec{w}]_\\calb$.\n    \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}[Practice problems]\n  Find $\\coords{v}{\\calb}$ of the vector $\\vec{v} = \\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\end{bmatrix} \\in V$ for $V$ and $\\calb$ as below.\n    \\begin{enumerate}\n      \\item $V = \\bbr^3$, $\\calb = \\set{\\vec{e}_1, \\vec{e}_2, \\vec{e}_3}$\n      \\item $V = \\bbr^3$, $\\calb = \\set{\\vec{e}_1, \\vec{e}_3, \\vec{e}_2}$\n      \\item $V = \\bbr^3$, $\\calb = \\set{\\vec{e}_1 + \\vec{e}_2, \\vec{e}_2, \\vec{e}_3}$\n      \\item $V = \\set{z = 0}$, $\\calb = \\set{\\vec{e}_1, \\vec{e}_2}$\n      \\item $V = \\set{x + y + z = 0}$, $\\calb = \\set{\\vec{e}_1 - \\vec{e}_3, \\vec{e}_2 - \\vec{e}_3}$\n      \\item $V = \\spn\\set{\\begin{bmatrix} 1 \\\\ -1 \\\\ 0 \\end{bmatrix}}$, $\\calb = \\set{\\begin{bmatrix} 2 \\\\ -2 \\\\ 0 \\end{bmatrix}}$\n      \\end{enumerate}\n\\end{qbox}\n\n\n\tGeneralized coordinates are \\emph{intrinsic} to the subspace and do not depend on the ambient vector space.\n  However, they are not unique and depend upon the choice of a basis.\n\n  We will show in the next section that the \\emph{number} of generalized coordinates, on the other hand, does not depend on the basis. The dimension is then defined to equal this number.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Optional: Abstract vector spaces}\nWe repeatedly used scalar multiplication and addition of vectors in the previous sections.\nEverything we did naturally carries over to any structure that has scalar multiplication and addition.\n\n\\begin{definition}\n  A \\emph{vector space} over the real numbers is any set $V$ which has addition and scalar multiplication.\n\\end{definition}\n\\begin{ex}\n  A subspace of $\\bbr^n$ is an example of a vector space.\n\\end{ex}\n\n\\begin{qbox}\n  Verify that the following are vector spaces.\n  \\begin{enumerate}\n    \\item Set of polynomials in a single variable $x$.\n    \\begin{align*}\n      \\mathrm{Poly} = \\set{a_0 + a_1 x + \\dots + a_n x^n \\mid n \\in \\bbz_{\\ge 0}, a_i \\in \\bbr}\n    \\end{align*}\n    \\item Set of polynomials $\\mathrm{Poly}_n$ in a single variable $x$ of degree $\\le n$.\n    \\begin{equation*}\n      \\mathrm{Poly}_n = \\set{ a_0 + \\dots + a_k x^k \\mid k \\le n, a_i \\in \\bbr}.\n    \\end{equation*}\n    \\item Set of functions $f: \\bbr \\rightarrow \\bbr$.\n    \\begin{align*}\n      \\Maps(\\bbr,\\bbr) = \\set{f:\\bbr \\rightarrow \\bbr}\n    \\end{align*}\n    \\item Set of functions $f: \\bbr \\rightarrow \\bbr$ with $f(0) = 0$.\n    \\begin{align*}\n      \\Maps_0(\\bbr,\\bbr) = \\set{f:\\bbr \\rightarrow \\bbr}\n    \\end{align*}\n  \\end{enumerate}\n\\end{qbox}\n\n\\begin{qbox}\n  The set of polynomials in a single variable $x$ of degree $= n$ is \\emph{not} a vector space. Why?\n\\end{qbox}\n\nThe notion of a subspace naturally extends to abstract vector spaces: $\\mathrm{Poly}_n$ is a subspace of $\\mathrm{Poly}$ and $\\Maps_0(\\bbr,\\bbr)$ is a subspace of $\\Maps(\\bbr,\\bbr)$.\nThe notions of spans, linear independence, and basis also naturally generalize.\n\n\\begin{qbox}\n  Find bases for $\\mathrm{Poly}_n$ and $\\mathrm{Poly}$.\n\\end{qbox}\n\n\\begin{qbox}\n  Can you find a basis for $\\Maps(\\bbr,\\bbr)$? Are you sure?\n\\end{qbox}\n", "meta": {"hexsha": "9a922fad1680c60ccbfc23d0ec99c30cd5155683", "size": 16232, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01.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": "01.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": "01.tex", "max_forks_repo_name": "apurvnakade/mc2019-linear-algebra", "max_forks_repo_head_hexsha": "6626512c3109bbe8696ab5787293037ed90d5058", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5558194774, "max_line_length": 249, "alphanum_fraction": 0.6529694431, "num_tokens": 5733, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680904463333, "lm_q2_score": 0.9136765193002482, "lm_q1q2_score": 0.7837225632458262}}
{"text": "\\section{Subspaces}\n\\label{sec:vector-space-subspaces}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a set of vectors is a subspace of a given\n    vector space.\n  \\item Determine whether two sets of vectors span the same subspace.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section we will consider subspaces of general vector spaces.\n\n\\begin{definition}{Subspace}{subspace-vector-space}\n  Let $V$ be a vector space over a field $K$. A subset $W\\subseteq V$\n  is said to be a \\textbf{subspace}%\n  \\index{subspace}%\n  \\index{subspace!of vector space} of\\/ $V$ if the following conditions hold:\n  \\begin{enumerate}\n  \\item $\\vect{0}\\in W$, where $\\vect{0}$ is the additive unit of\\/ $V$.\n  \\item $W$ is \\textbf{closed under addition}%\n    \\index{closed under!addition}%\n    \\index{addition!closed under}: Whenever $\\vect{u}, \\vect{v}\\in W$,\n    then $\\vect{u} + \\vect{v}\\in W$.\n  \\item $W$ is \\textbf{closed under scalar multiplication}%\n    \\index{closed under!scalar multiplication}%\n    \\index{scalar multiplication!closed under}: Whenever $k\\in K$ and\n    $\\vect{u}\\in W$, then $k\\vect{u}\\in W$.\n  \\end{enumerate}\n\\end{definition}\n\n\\begin{example}{Subspaces of $\\R^3$}{subspaces-r3}\n  As we have seen in Section~\\ref{sec:subspaces-rn}, the subspaces of\n  $\\R^3$ are:\n  \\begin{itemize}\n  \\item the zero subspace%\n    \\index{zero subspace} $\\set{\\vect{0}}$;\n  \\item lines through the origin;\n  \\item planes through the origin;\n  \\item $\\R^3$ itself.\n  \\end{itemize}\n\\end{example}\n\n\\begin{example}{Space of continuous functions}{subspace-continuous}\n  Let $V = \\Func_{\\R,\\R}$, the vector space of functions from real numbers to\n  real numbers. Let $W\\subseteq V$ be the subset of {\\em continuous}\n  functions%\n  \\index{continuous function}%\n  \\index{function!continuous}. Then $W$ is a subspace of\\/ $V$.\n\\end{example}\n\n\\begin{proof}\n  We know from calculus that:\n  \\begin{enumerate}\n  \\item the zero function, defined by $f(x)=0$ for all $x$, is\n    continuous;\n  \\item if $f,g$ are continuous functions, then $f+g$ is\n    continuous;\n  \\item if $f$ is a continuous function and $k$ a constant, then $kf$\n    is continuous.\n  \\end{enumerate}\n  It follows that $W$ contains $0$, and is closed under addition and\n  scalar multiplication. Therefore, $W$ is a subspace of\\/ $V$.\n\\end{proof}\n\n\\begin{example}{Space of differentiable functions}{subspace-differentiable}\n  Let $V = \\Func_{\\R,\\R}$. Recall from calculus that a function\n  $f:\\R\\to\\R$ is called \\textbf{differentiable}%\n  \\index{differentiable function}%\n  \\index{function!differentiable} if the derivative $f'(x)$ exists for\n  all $x\\in\\R$. Let $W\\subseteq V$ be the subset of differentiable\n  functions. Then $W$ is a subspace of\\/ $V$.\n\\end{example}\n\n\\begin{proof}\n  We know from calculus that:\n  \\begin{enumerate}\n  \\item The zero function, defined by $f(x)=0$ for all $x$, is\n    differentiable. In fact, its derivative is $f'(x) = 0$.\n  \\item If $f,g$ are differentiable functions, then $h=f+g$ is\n    differentiable. In fact, $h'(x) = f'(x) + g'(x)$.\n  \\item if $f$ is a differentiable function and $k$ a constant, then\n    $h=kf$ is differentiable. In fact, $h' = kf'$.\n  \\end{enumerate}\n  It follows that $W$ contains $0$, and is closed under addition and\n  scalar multiplication. Therefore, $W$ is a subspace of\\/ $V$.\n\\end{proof}\n\n\\begin{example}{Space of sequences satisfying a linear recurrence}{subspace-recurrence}\n  Let $V=\\Seq_{\\R}$, the vector space of sequences of real\n  numbers. Let\n  \\begin{equation*}\n    W = \\set{a \\in \\Seq_{\\R} \\mid \\mbox{for all $n\\geq 0$, $a_{n+2}=a_n+a_{n+1}$}}.\n  \\end{equation*}\n  In other words, $W$ is the set of all sequences satisfying the\n  recurrence%\n  \\index{recurrence!as a subspace} relation\n  $a_{n+2}=a_n+a_{n+1}$. Then $W$ is a subspace of\\/ $V$.\n\\end{example}\n\n\\begin{proof}\n  \\def\\x#1{\\makebox[1.2em][r]{$#1$}}\n  \\def\\y#1{\\makebox[3em][r]{$#1$}}\n  \\def\\z#1{\\makebox[0em][l]{$#1$}}\n  Before we prove that $W$ is a subspace, let us first consider an\n  example. The following sequences are elements of\\/ $W$, because they\n  both satisfy the recurrence:\n  \\begin{equation*}\n    \\begin{array}{rc@{}l}\n      \\y{a} &=& \\x{(1},\\x{1},\\x{2},\\x{3},\\x{5},\\x{8},\\x{13},\\x{21},\\x{\\ldots})\\z{\\,,} \\\\\n      \\y{b} &=& \\x{(1},\\x{3},\\x{4},\\x{7},\\x{11},\\x{18},\\x{29},\\x{47},\\x{\\ldots})\\z{\\,.}\n    \\end{array}\n  \\end{equation*}\n  Note that if we add these sequences, we get\n  \\begin{equation*}\n    \\begin{array}{rc@{}l}\n      \\y{a+b} &=& \\x{(2},\\x{4},\\x{6},\\x{10},\\x{16},\\x{26},\\x{42},\\x{68},\\x{\\ldots})\\z{\\,,} \\\\\n    \\end{array}\n  \\end{equation*}\n  which again satisfies the recurrence. Therefore, the set $W$ is\n  closed under the addition of these particular sequences $a$ and\n  $b$. We now prove the properties in general.\n  \\begin{enumerate}\n  \\item Let $z$ be the zero sequence%\n    \\index{zero sequence}%\n    \\index{sequence!zero sequence}, defined by $z_n=0$ for all $n$.\n    Then $z$ satisfies the recurrence relation, since for all $n\\geq 0$,\n    $z_{n+2}=0=z_n+z_{n+1}$. Therefore $z\\in W$.\n  \\item To show that $W$ is closed under addition, consider any two\n    sequences $a,b\\in W$, and let $c=a+b$. Then for all $n\\geq 0$,\n    \\begin{equation*}\n      c_{n+2}\n      = a_{n+2} + b_{n+2}\n      = (a_n + a_{n+1}) + (b_n + b_{n+1})\n      = (a_n + b_n) + (a_{n+1} + b_{n+1})\n      = c_n + c_{n+1},\n    \\end{equation*}\n    so $c$ satisfies the recurrence. It follows that $c\\in W$, and\n    therefore $W$ is closed under addition.\n  \\item To show that $W$ is closed under scalar multiplication,\n    consider any $k\\in\\R$ and $a\\in W$, and let $c=ka$. Then for all\n    $n\\geq 0$,\n    \\begin{equation*}\n      c_{n+2}\n      = ka_{n+2}\n      = k(a_n + a_{n+1})\n      = ka_n + ka_{n+1}\n      = c_n + c_{n+1},\n    \\end{equation*}\n    so $c$ satisfies the recurrence. It follows that $c\\in W$, and\n    therefore $W$ is closed under scalar multiplication.\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{example}{Solution space of a linear differential equation}{subspace-differential-equation}\n  Let $V=\\Func_{\\R,\\R}$. Recall from calculus that a\n  \\textbf{differential equation}%\n  \\index{differential equation} is an equation about an unknown\n  function and its derivatives. For example\n  \\begin{equation*}\n    f'' = -f\n  \\end{equation*}\n  is a differential equation. The functions $f(x)=\\sin x$,\n  $f(x)=\\cos x$, and $f(x)=0$ are examples of solutions of this\n  differential equation.  Let $W$ be the set of all functions that are\n  solutions of the differential equation $f'' = -f$. Then $W$ is a\n  subspace of\\/ $V$.\n\\end{example}\n\n\\begin{proof}\n  \\begin{enumerate}\n  \\item The zero function $f(x)=0$ is a solution of the differential\n    equation, and therefore an element of\\/ $W$.\n  \\item To show that $W$ is closed under addition, let $f,g\\in W$ and\n    consider $h=f+g$. Then $f''=-f$ and $g''=-g$, and therefore\n    $h'' = f'' + g'' = -f+(-g) = -h$. Therefore, $h\\in W$, and $W$ is\n    closed under addition.\n  \\item To show that $W$ is closed under scalar multiplication, let\n    $k\\in\\R$ and $f\\in W$, and consider $h=kf$. Then $f''=-f$, and\n    therefore $h'' = kf'' = k(-f) = -h$. It follows that $h\\in W$, and\n    therefore $W$ is closed under scalar multiplication.\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{example}{Subspace of polynomials}{polynomial-subspace}\n  Consider $\\Poly_2$, the vector space of polynomials of degree at\n  most 2, with coefficients in a field $K$. Fix some element $r\\in K$,\n  and let $W \\subseteq \\Poly_2$ be the subset of polynomials that have\n  $r$ as a root. Then $W$ is a subspace of $\\Poly_2$.\n\\end{example}\n\n\\begin{proof}\n  We can express $W$ as follows:\n  \\begin{equation*}\n    W = \\set{p\\in\\Poly_2 \\mid p(r)  = 0}.\n  \\end{equation*}\n  We need to show that $W$ is a subspace.\n  \\begin{enumerate}\n  \\item The zero polynomial, given by $0(x)=0$, satisfies $0(r)=0$, so\n    $0\\in W$.\n  \\item To show that $W$ is closed under addition, assume\n    $p, q\\in W$, and let $s=p+q$. Then $p(r)=0$ and $q(r)=0$,\n    therefore $s(r) = p(r)+q(r) = 0$. It follows that $s\\in W$.\n  \\item To show that $W$ is closed under scalar multiplication, assume\n    $p(x)\\in W$ and $k$ be a scalar. Then $(kp)(r)=k(p(r))=k0=0$, and\n    therefore $kp\\in W$.\n  \\end{enumerate}\n\\end{proof}\n\n\\begin{example}{Trivial subspaces of\\/ $V$}{trivial-subspaces}\n  Let $V$ be an arbitrary vector space over a field $K$. Then\n  $\\set{\\vect{0}}$ is a subspace of\\/ $V$, called the \\textbf{zero\n    subspace}. Also, $V$ is a subspace of itself.\n\\end{example}\n\n\\begin{proof}\n  Clearly $\\set{\\vect{0}}$ contains $\\vect{0}$, and is closed under\n  addition and scalar multiplication because\n  $\\vect{0}+\\vect{0}=\\vect{0}$ and $k\\vect{0}=\\vect{0}$ for all $k$.\n  Similarly, $V$ contains $\\vect{0}$ and is closed under addition and\n  scalar multiplication, because addition and scalar multiplication\n  are operations on $V$.  Therefore, both $\\set{\\vect{0}}$ and $V$ are\n  subspaces of\\/ $V$.\n\\end{proof}\n\nThe interest of subspaces lies in the fact that they are vector spaces\nin their own right, as stated in the following proposition.\n\n\\begin{proposition}{Subspaces are vector spaces}{subspaces-are-vector-spaces}\n  Let $W$ be a subspace of a vector space $V$. Then $W$ satisfies the\n  vector space axioms (A1)--(A4) and (SM1)--(SM4), with respect to the\n  same operations (addition and scalar multiplication) as those\n  defined on $V$.\n\\end{proposition}\n\n\\begin{proof}\n  Since $W$ is a subspace, it is closed under addition and scalar\n  multiplication. This ensures that addition and scalar multiplication\n  are well-defined operations on $W$. The axioms (A1), (A2), (A4), and\n  (SM1)--(SM4) all obviously hold in $W$, because they hold in $V$\n  (two elements of\\/ $W$ are equal in $W$ if and only if they are equal\n  in $V$). The axiom (A3) holds because $\\vect{0}\\in W$.\n\\end{proof}\n\nWe end this section with an observation about spans.\n\n\\begin{proposition}{Span is smallest subspace containing given vectors}{span-smallest-subspace}\n  Let $V$ be a vector space over some field $K$, and consider a set of\n  vectors $S\\subseteq V$. Then $\\sspan S$ is the smallest subspace of\\/\n  $V$ containing $S$. More explicitly, we have:\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item The set $\\sspan S$ is a subspace of\\/ $V$, and\n      $S\\subseteq \\sspan S$.\n    \\item If $W$ is any other subspace of\\/ $V$ such that\n      $S\\subseteq W$, then $\\sspan S\\subseteq W$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\n\\begin{proof}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item To show that $\\sspan S$ is a subspace, first note that\n      $\\vect{0}\\in\\sspan S$, because $\\vect{0}$ is the empty linear\n      combination. Also, if $\\vect{v},\\vect{u}\\in\\sspan S$, then by\n      definition of span, there exist\n      $\\vect{v}_1,\\ldots,\\vect{v}_k,\\vect{u}_1,\\ldots,\\vect{u}_{\\ell}\\in\n      S$ and $a_1,\\ldots,a_k,b_1,\\ldots,b_{\\ell}\\in K$ such that\n      \\begin{eqnarray*}\n        \\vect{v} &=& a_1\\vect{v}_1 + \\ldots + a_k\\vect{v}_k, \\\\\n        \\vect{u} &=& b_1\\vect{u}_1 + \\ldots + b_{\\ell}\\vect{u}_{\\ell}.\n      \\end{eqnarray*}\n      Then\n      \\begin{eqnarray*}\n        \\vect{v}+\\vect{u}\n        &=& a_1\\vect{v}_1 + \\ldots + a_k\\vect{v}_k\n            + b_1\\vect{u}_1 + \\ldots + b_{\\ell}\\vect{u},\n      \\end{eqnarray*}\n      and therefore $\\vect{v}+\\vect{u}\\in\\sspan S$. It follows that\n      $\\sspan S$ is closed under addition. The proof for scalar\n      multiplication is similar. Finally, every $\\vect{v}\\in S$ is\n      trivially a linear combination of itself, $\\vect{v}=1\\vect{v}$,\n      and therefore $S\\subseteq \\sspan S$.\n    \\item Consider any other subspace $W$ of $V$ such that\n      $S\\subseteq W$. To show that $\\sspan S\\subseteq W$, consider an\n      arbitrary element $\\vect{v}\\in\\sspan S$. By definition of span,\n      there exist $\\vect{v}_1,\\ldots,\\vect{v}_k\\in S$ and\n      $a_1,\\ldots,a_k\\in K$ such that\n      $\\vect{v}=a_1\\vect{v}_1 + \\ldots + a_k\\vect{v}_k$. By\n      assumption, $\\vect{v}_1,\\ldots,\\vect{v}_k\\in W$. Since $W$ is\n      closed under addition and scalar multiplication, it follows that\n      $\\vect{v}\\in W$. Since $\\vect{v}$ was an arbitrary element of\n      $\\sspan S$, it follows that $\\sspan S\\subseteq W$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proof}\n\nWhile the last proposition looks technical, it can actually be useful\nfor proving that two sets of vectors span the same subspace. The\nfollowing in an example of this.\n\n\\begin{example}{Equal spans}{equal-span}\n  Show that the sets $S=\\set{x^2-2x+1,~ x-1}$ and\n  $T=\\set{x^2-1,~ x^2-x}$ span the same subspace of $\\Poly_2$. In other\n  words, show that\n  \\begin{equation*}\n    \\sspan S = \\sspan T.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  To show that two sets are equal, we must show that each is a subset\n  of the other. So we will show $\\sspan S \\subseteq \\sspan T$ and\n  $\\sspan T \\subseteq \\sspan S$. By\n  Proposition~\\ref{prop:span-smallest-subspace}, it is sufficient to show that\n  $S\\subseteq \\sspan T$ and $T\\subseteq \\sspan S$, i.e., we must show\n  that every element of $S$ is a linear combination of elements of $T$\n  and vice versa.\n  \\begin{enumerate}\n  \\item $S \\subseteq \\sspan T$. We have\n    \\begin{equation*}\n      \\begin{array}{rclcl}\n      x^2-2x+1 &=& (-1)(x^2-1) + 2(x^2-x) &\\in& \\sspan T, \\\\\n      x-1 &=& 1(x^2-1) - 1(x^2-x) &\\in& \\sspan T.\n      \\end{array}\n    \\end{equation*}\n    Since each element of $S$ is an element of $\\sspan T$, it follows\n    that $S\\subseteq\\sspan T$. By\n    Proposition~\\ref{prop:span-smallest-subspace}, this implies that\n    $\\sspan S\\subseteq \\sspan T$.\n  \\item $T \\subseteq \\sspan S$. We have\n    \\begin{equation*}\n      \\begin{array}{rclcl}\n        x^2-1 &=& 1(x^2-2x+1) - 2(x-1) &\\in& \\sspan S, \\\\\n        x^2-x &=& 1(x^2-2x+1) - 1(x-1) &\\in& \\sspan S.\n      \\end{array}\n    \\end{equation*}\n    Since each element of $T$ is an element of $\\sspan S$, it follows\n    that $T\\subseteq\\sspan S$. By\n    Proposition~\\ref{prop:span-smallest-subspace}, this implies that\n    $\\sspan T\\subseteq \\sspan S$.\n  \\end{enumerate}\n\\end{solution}\n", "meta": {"hexsha": "610ba36e82f4a30441d49038c1c5ce9aa4260707", "size": 14057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces-Subspaces.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/VectorSpaces-Subspaces.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/VectorSpaces-Subspaces.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.7449275362, "max_line_length": 97, "alphanum_fraction": 0.6481468308, "num_tokens": 4792, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8947894682067639, "lm_q1q2_score": 0.7836449852218432}}
{"text": "\\section{08/26}\n\\subsection{Birthday Paradox}\nThe probability that no two people share a birthday is\n\\begin{align*}\\prob{E_1 \\cap E_2 \\cap \\dots \\cap E_n}\n    &= \\prob{E_1}\\prob{E_2 \\given E_1}\\cdots \\prob{E_n \\given E_1 \\cap E_2 \\cap \\dots \\cap E_{n - 1}}\\\\\n    &= 1 \\times \\left(1 - \\frac{1}{365}\\right) \\times \\left(1 - \\frac{2}{365}\\right) \\times \\cdots \\times \\left(1 - \\frac{365 - n + 1}{365}\\right)\n    \\shortintertext{Applying the inequality $1 - x \\leq e^{-x}$ when $\\abs{x} < 1$}\\\\\n    &\\leq 1 \\cdot e^{-\\frac{1}{365}} \\cdot e^{-\\frac{2}{365}} \\cdots e^{-\\frac{n - 1}{365}}\\\\\n    &= e^{-\\frac{n(n-1)}{2\\cdot365}}\n\\end{align*}\nSetting\n\\[e^{-\\frac{n(n-1)}{2\\cdot365}} \\leq \\frac{1}{2}\\]\nyields $n \\geq 23$. \n\n\\subsection{Randomized Algorithms}\n\\begin{problem}{Toy Problem}{}\nLet $A$ be an array of $n$ numbers with the property that at least one number\noccurs at least $\\sfrac{n}{2}$ times and the rest are distinct. Our goal is to\nfind the element with duplicate entries.\n\\end{problem}\n\nAny deterministic algorithm will require at least $\\sfrac{n}{2} + 1$ operations.\nHowever, we can construct a randomized algorithm that only requires\n$\\bigO{\\log{n}}$ operations.\n\nWe do this by \\emph{random sampling}. Assume that choosing a single element in\n$\\set{a_1, a_2, \\dots, a_n}$ requires $\\bigO{1}$ time and that we sample\n\\emph{with replacement}. We will frequently use sampling with replacement\nbecause it allows the samples to be independent, and therefore simplifies the\nanalysis. Now, consider the following algorithm:\n\n\\begin{algorithm}\n    \\caption{Randomized Algorithm for Toy Problem}\n    \\begin{algorithmic}[1]\n        \\Function{Rand-Duplicate-Toy}{\\texttt{arr}}\n            \\Loop\\label{line:toyloop}\n                \\State $\\texttt{sample}_1 \\gets \\Call{Sample}{\\texttt{arr}}$\n                \\State $\\texttt{sample}_2 \\gets \\Call{Sample}{\\texttt{arr}}$\n                \\If{$\\texttt{sample}_1 \\neq \\texttt{sample}_2$}\n                    \\State \\Return $\\texttt{sample}_1$\n                \\EndIf\n            \\EndLoop\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\nThis algorithm simply chooses two elements (not necessarily distinct) at random\nfrom the array and repeats until the two elements are identical, after which it\noutputs the sampled element as the duplicate.\n\nLet us analyze the probability that this algorithm outputs the duplicate value\nafter a single iteration. Suppose the two values chosen are $a_i$ and $a_j$.\nThen\n\\begin{align*}\\prob{a_i = a_j \\text{ and } i \\neq j}\n    &= \\frac{\\sfrac{n}{2}}{n} \\cdot \\frac{\\sfrac{n}{2} - 1}{n}\\\\\n    &= \\frac{1}{2} \\left(\\frac{1}{2} - \\frac{1}{n}\\right)\\\\\n    &= \\frac{1}{4} - \\frac{1}{2n}\\\\\n    &\\geq \\frac{3}{2} \\hbox{ for $n \\geq 5$} \n\\end{align*}\nWhat is the probability, then, that our algorithm fails after $k$ iterations of\n\\cref{line:toyloop}? These events are independent, hence the probability is\nbounded above by\n\\begin{align*}\\prob{\\text{failure}}\n    &\\leq \\left(1 - \\frac{3}{20}\\right)^k\\\\\n    &\\leq e^{-\\frac{3}{20}k}\n    \\shortintertext{Setting $k = \\frac{20}{3}\\ln{n}$,}\\\\\n    &= e^{-\\ln{n}}\\\\\n    &=\\frac{1}{n}\n\\end{align*}\n\n\\subsection{Bayes' Law}\n\\begin{theorem}{Bayes' Law}{}\n    For any events $A$ and $B$,\n    \\[\\prob{A \\given B} = \\frac{\\prob{B \\given A} \\prob{A}}{\\prob{B}}\\]\n\\end{theorem}\n\n\\subsection{Concepts in Randomized Algorithms}\n\\begin{definition}{}{}\n    An algorithm is \\emph{Monte Carlo} if it has a non-zero probability of\n    outputting an incorrect solution. If an algorithm will output the correct\n    solution with probability 1, it is \\emph{Las Vegas}.\n\\end{definition}\n\n\\begin{definition}{High Probability}{}\n    Given an input of size $n$, we say an event occurs \\emph{with high\n    probability} (whp) if it occurs with probability $1 - \\sfrac{1}{n^c}$ for\n    some $c > 0$.\n\\end{definition}\n\n\\begin{problem}{Modified Toy Problem}{}\n    Let $A$ be an array of $n$ numbers with the property that \\emph{either} all\n    elements are distinct \\emph{or} $\\sfrac{n}{2}$ elements are repeated.\n\\end{problem}\n\nLet us define\n\\begin{align*}\n    E_1 &= \\hbox{event that exactly $\\sfrac{n}{2}$ elements are distinct}\\\\\n    E_2 &= \\hbox{event that all $n$ elements are distinct}\n\\end{align*}\n\nAt first, our ``belief'' in $E_1$ and $E_2$ are approximately the same, i.e., we\nhave no information to determine which event is more likely. However, let us\nassume we have sampled two elements with replacement and determined that they\nare not equal (call this event $F$). We can update our ``belief'' via Bayes'\nLaw.\n\\begin{align*}\\prob{E_1 \\given F}\n    &= \\frac{\\prob{F \\given E_1} \\prob{E_1}}{\\prob{F}}\\\\\n    &\\leq \\frac{\\left(1 - \\frac{3}{20}\\right) \\cdot \\frac{1}{2}}{\\left(1 - \\frac{3}{20}\\right) \\cdot \\frac{1}{2} + \\frac{1}{2}}\\\\\n    &= \\frac{17}{37}\n\\end{align*}\nThus, we see that the probability has shifted from ``50-50'' to skewing \\emph{in\nfavor} of the belief that $E_2$ has occurred.\n\n\\subsection{Law of Total Probability}\n\\begin{theorem}{Law of Total Probability}{}\n    For any event $A$ and any countable partition of the sample space $B_1$,\n    $B_2$, \\dots, that is, the events $B_i$ are pairwise disjoint and their\n    union forms the entire sample space, we have\n    \\[\\prob{A} = \\sum_i \\prob{A \\cap B_i} = \\sum_i \\prob{A \\given B_i} \\prob{B_i}\\]\n\\end{theorem}\n\n\\subsection{Naive Bayesian Classifier}\nA Naive Bayesian Classifier is a classic example of how we can apply\nprobabilistic techniques and Bayes' Law in practice. Suppose we have a\n\\emph{feature set} $e$, a vector of boolean $n$ boolean variable. These could\nbe, for example, whether a certain keyword appears in an email in an attempt to\ndetect spam. Then, assuming the independence of the boolean variables (this is\nwhy it is referred to as \\emph{naive}), we have\n\\begin{align*}\\prob{E \\given e = (b_1, b_2, \\dots, b_n)}\n    &= \\frac{\\prob{e = (b_1, b_2, \\dots, b_n) \\given E} \\prob{E}}{\\prob{e = (b_1, b_2, \\dots, b_n)}}\\\\\n    &= \\frac{\\prob{b_1 \\given E} \\cdot \\prob{b_2 \\given E} \\cdots \\prob{b_n \\given E} \\cdot \\prob{event}}{\\prob{e = (b_1, b_2, \\dots, b_n)}}\n\\end{align*}", "meta": {"hexsha": "c38970d1ac2d5b046976baf7c1752e094386007f", "size": 6068, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0826.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/0826.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/0826.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": 45.9696969697, "max_line_length": 146, "alphanum_fraction": 0.6671061305, "num_tokens": 1984, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8947894618940992, "lm_q1q2_score": 0.7836449680895929}}
{"text": "\\chapter{Equations}\r\n\\section{Quadratic equations}\r\n\\begin{dfn}\r\nA quadratic equation is an equation of the form\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\n\\end{dfn}\r\n\\begin{thm}\r\nA quadratic equation (\\ref{quad}) has 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\n\\end{thm}\r\n\\begin{dfn}\r\n\\label{disc}\r\nThe \\emph{discrimimant} of a quadratic equation (\\ref{quad})\r\nis called \\( \\Delta \\) and it is defined as:\r\n\\[\r\n  \\Delta = b^2 - 4ac\r\n\\]\r\n\\end{dfn}\r\n\\begin{lem}\r\nIf the discrimimant \\( \\Delta \\) is zero, then the equation (\\ref{quad}) has a double solution: (\\ref{root}) becomes:\r\n\\[\r\n  x = - \\frac{b}{2a}\r\n\\]\r\n\\end{lem}\r\n\\begin{proof}\r\nThe equation \\eqref{quad} together with the definition \\ref{disc} becomes:\r\n\\begin{align*}\r\n  x_{1,2} &= \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a} \\\\\r\n          &= \\frac{-b \\pm \\sqrt{\\Delta}}{2a} \\\\\r\n          &= \\frac{-b \\pm \\sqrt{0}}{2a} \\\\\r\n          &= -\\frac{b}{2a} \\\\\r\n\\end{align*}\r\nand there exists only one solution.\r\n\\end{proof}\r\n", "meta": {"hexsha": "5cbd3c583e93089b037b6e7dce8b7c98863d7f15", "size": 1153, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter11/chapter1.tex", "max_stars_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_stars_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2019-05-11T01:15:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T21:30:11.000Z", "max_issues_repo_path": "Chapter11/chapter1.tex", "max_issues_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_issues_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter11/chapter1.tex", "max_forks_repo_name": "eagleqian/LaTeX-Beginner-s-Guide", "max_forks_repo_head_hexsha": "49f6c9c8e0c9f7a6554e720c8a82978a5f5d1042", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2019-05-11T00:40:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-01T21:30:13.000Z", "avg_line_length": 27.4523809524, "max_line_length": 118, "alphanum_fraction": 0.5949696444, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7836069856930371}}
{"text": "\\subsection{Variation of Parameters for Systems}\r\n\\noindent\r\nLet $X$ be a fundamental matrix for the homogeneous system.\r\n\\begin{equation*}\r\n\t\\vec{x_h}' = A\\vec{x_h}.\r\n\\end{equation*}\r\nThat is,\r\n\\begin{equation*}\r\n\t\\vec{x_h} = X\\vec{c}\r\n\\end{equation*}\r\nwhere\r\n\\begin{equation*}\r\n\t\\vec{c} = \\begin{bmatrix}\r\n\tC_1 \\\\\r\n\t\\vdots \\\\\r\n\tC_n\r\n\t\\end{bmatrix}\r\n\\end{equation*}\r\nand the entries of matrix $A$ can be any continuous functions of $t$.\r\n\r\n\\noindent\r\nWe are looking for the particular solution $\\vec{x_p}$, to the system\r\n\\begin{equation*}\r\n\t\\vec{x} = A\\vec{x} + \\vec{f}\r\n\\end{equation*}\r\nwhere $\\vec{x_p}$ is of the form\r\n\\begin{equation*}\r\n\t\\vec{x_p} = X\\vec{v}\r\n\\end{equation*}\r\nwhere $\\vec{v}$ is a vector of functions of $t$ that we'll have to find.\r\n\r\n\\noindent\r\nDifferentiating $\\vec{x_p}$,\r\n\\begin{equation*}\r\n\t\\vec{x_p}' = X\\vec{v}' + X'\\vec{v}.\r\n\\end{equation*}\r\nFrom the system we're trying to solve we know that\r\n\\begin{equation*}\r\n\tX\\vec{v}' + X'\\vec{v} = A(X\\vec{v}) + \\vec{f}.\r\n\\end{equation*}\r\nSince $X' = AX$,\r\n\\begin{equation*}\r\n\tX\\vec{v}' = \\vec{f}.\r\n\\end{equation*}\r\n\r\n\\noindent\r\nSince the columns of $X$ are always linearly independent, we know that $X^{-1}$ always exists.\r\nMultiplying by $X^{-1}$,\r\n\\begin{equation*}\r\n\t\\vec{v}' = X^{-1}\\vec{f}.\r\n\\end{equation*}\r\nIntegrating with respect to $t$,\r\n\\begin{equation*}\r\n\t\\vec{v} = \\int{X^{-1}\\vec{f} \\mathrm{d}t}.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\vec{x_p} = X\\int{X^{-1}\\vec{f} \\mathrm{d}t},\r\n\\end{equation*}\r\nand\r\n\\begin{equation*}\r\n\t\\vec{x} = X\\vec{c} + X\\int{X^{-1}\\vec{f} \\mathrm{d}t}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the general solution to the system by variation of parameters\r\n\t\\begin{equation*}\r\n\t\t\\vec{x}' = \\begin{bmatrix}\r\n\t\t\t2 & -3 \\\\\r\n\t\t\t1 & -2\r\n\t\t\\end{bmatrix}\\vec{x} + \\begin{bmatrix}\r\n\t\t\te^{2t} \\\\\r\n\t\t\t1\r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*}\r\n\tgiven the fundamental matrix\r\n\t\\begin{equation*}\r\n\t\tX = \\begin{bmatrix}\r\n\t\t\t3e^t & e^{-t} \\\\\r\n\t\t\te^t & e^{-t}\r\n\t\t\\end{bmatrix}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFinding $\\vec{x_h}$ is simply multiplying $X$ by a vector, so we'll save that for the end and focus on $\\vec{x_p}$. First we need to find $X^{-1}$. The details are left out, but the process is identical to that for matrices of numbers.\r\n\\begin{equation*}\r\n\tX^{-1} = \\begin{bmatrix}\r\n\t\t\\frac{1}{2}e^{-t} & -\\frac{1}{2}e^{-t} \\\\\r\n\t\t-\\frac{1}{2}e^t & \\frac{3}{2}e^t\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nMultiplying by $\\vec{f}$.\r\n\\begin{equation*}\r\n\tX\\vec{f} = \\begin{bmatrix}\r\n\t\t\\frac{1}{2}e^t - \\frac{1}{2}e^{-t} \\\\\r\n\t\t-\\frac{1}{2}e^{3t} + \\frac{3}{2}e^t\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nIntegrating with respect to $t$,\r\n\\begin{equation*}\r\n\t\\int{X^{-1}\\vec{f} \\mathrm{d}t} = \\begin{bmatrix}\r\n\t\t\\frac{1}{2}e^t + \\frac{1}{2}e^{-t} \\\\\r\n\t\t-\\frac{1}{6}e^{3t} + \\frac{3}{2}e^t\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nNote that although we are doing an indefinite integral, we don't have a constant (or in this case a vector) of integration.\r\nMultiplying by $X$ to obtain $\\vec{x_p}$,\r\n\\begin{equation*}\r\n\t\\vec{x_p} = X\\int{X^{-1}\\vec{f} \\mathrm{d}t} = \\begin{bmatrix}\r\n\t\t\\frac{4}{3}e^{2t} + 3 \\\\\r\n\t\t\\frac{1}{3}e^{2t} + 2\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nFinding $\\vec{x_h}$,\r\n\\begin{equation*}\r\n\t\\vec{x_h} = X\\vec{c} = \\begin{bmatrix}\r\n\t\t3C_1e^t + C_2e^{-t} \\\\\r\n\t\tC_1e^t + C_2e^{-t}\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nPutting $\\vec{x_h}$ and $\\vec{x_p}$ together to get the general solution,\r\n\\begin{equation*}\r\n\t\\vec{x} = \\begin{bmatrix}\r\n\t\t3C_1e^{3t} + C_2e^{-t} + \\frac{4}{3}e^{2t} + 3 \\\\\r\n\t\tC_1e^t + C_2e^{-t} + \\frac{1}{3}e^{2t} + 2\r\n\t\\end{bmatrix}.\r\n\\end{equation*}", "meta": {"hexsha": "8bc9fbda22701c849520f00bfb3d2b9d6c704e9d", "size": 3585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/heterogeneousSystems/variationOfParameters.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/linearSystems/heterogeneousSystems/variationOfParameters.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/linearSystems/heterogeneousSystems/variationOfParameters.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.2283464567, "max_line_length": 236, "alphanum_fraction": 0.6041841004, "num_tokens": 1471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218284193597, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7836069821178189}}
{"text": "\n\\subsection{Heteroskedasticity-Consistent (HC) standard errors}\n\n\\subsubsection{Variance of OLS estimators}\n\n\\(Var [\\hat \\theta ]=(X^TX)^{-1}X^T\\Omega X(X^TX)^{-1}\\)\n\n\\subsubsection{Robust standard errors for heteroskedasticity}\n\n\\(\\Omega_{ij}=\\delta_{ij}\\epsilon_i\\epsilon_j\\)\n\nThese are also known as the Eicker-Huber-White standard errors, or the White correction.\n\nThese are also refered to as robust standard errors.\n\n", "meta": {"hexsha": "ec4c1f098d869309133a8515ec12da2b42179bd8", "size": 424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsInference/02-02-HC.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/olsInference/02-02-HC.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/olsInference/02-02-HC.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": 88, "alphanum_fraction": 0.7547169811, "num_tokens": 124, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.950410972802222, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7835776635355711}}
{"text": "\\subsection{Definition and properties}\n\nWhen we take the dot product of two vectors, the result is a\nscalar. For this reason, the dot product is also called the\n\\textbf{scalar product}. Sometimes it is also called the \\textbf{inner\n  product}. The definition is as follows%\n\\index{dot product}%\n\\index{vector!dot product}%\n\\index{scalar product|see{dot product}}%\n\\index{inner product|seealso{dot product}}.\n\n\\begin{definition}{Dot product}{dot-product}\n  Let $\\vect{u}=\\begin{mymatrix}{c}\n    u_1 \\\\\n    u_2 \\\\\n    \\vdots \\\\\n    u_n\n  \\end{mymatrix}$, $\\vect{v}= \\begin{mymatrix}{c}\n    v_1 \\\\\n    v_2 \\\\\n    \\vdots \\\\\n    v_n\n  \\end{mymatrix}$ be two vectors in $\\R^n$. We\n  define their \\textbf{dot product} as\n  \\begin{equation*}\n    \\vect{u}\\dotprod \\vect{v} = u_1v_1+u_2v_2+\\ldots+u_nv_n.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{Compute a dot product}{dot-product}\n  Find $\\vect{u} \\dotprod \\vect{v}$ for $\\vect{u}=\\mat{1,2,0,-1}^T$\n  and $\\vect{v}=\\mat{0,1,2,3}^T$.\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{eqnarray*}\n    \\vect{u} \\dotprod \\vect{v}\n    &=&\n        (1)(0) + (2)(1) + (0)(2) + (-1)(3) \\\\\n    &=&\n        0 + 2 + 0 + -3 \\\\\n    &=&\n        -1.\n  \\end{eqnarray*}\n\\end{solution}\n\nThe dot product satisfies a number of important properties.\n\n\\begin{proposition}{Properties of the dot product}{properties-dot-product}\n  \\index{dot product!properties}%\n  \\index{properties of dot product}%\n  \\index{vector!dot product!properties}%\n  \\index{vector!properties of dot product}%\n  The dot product satisfies the following properties, where\n  $\\vect{u},\\vect{v},\\vect{w}$ are vectors and $k,\\ell$ are\n  scalars.\n  \\begin{itemize}\n  \\item $\\vect{u}\\dotprod\\vect{v}=\\vect{v}\\dotprod\\vect{u}$.\n  \\item $\\vect{u}\\dotprod\\vect{u}\\geq 0$, and $\\vect{u}\\dotprod\\vect{u}=0$ if and only if $\\vect{u}=\\vect{0}$.\n  \\item $(k\\vect{u}+\\ell\\vect{v})\\dotprod\\vect{w}=k(\\vect{u}\\dotprod\\vect{w})+\\ell(\\vect{v}\\dotprod\\vect{w})$.\n  \\item $\\vect{u}\\dotprod(k\\vect{v}+\\ell\\vect{w})\n    =k(\\vect{u}\\dotprod \\vect{v})+\\ell(\\vect{u}\\dotprod\\vect{w})$.\n  \\item $\\vect{u}\\dotprod\\vect{u}=\\norm{\\vect{u}}^2$.\n  \\end{itemize}\n\\end{proposition}\n\nThe proof is left as an exercise. Note that, by the last part of the\nproposition, we can also use the dot product to find the length of a\nvector.\n\n\\begin{example}{Length of a vector}{dot-product-length}\n  Use a dot product to find $\\norm{\\vect{u}}$, where\n  \\begin{equation*}\n    \\vect{u}\n    =\n    \\begin{mymatrix}{r}\n      2 \\\\\n      1 \\\\\n      4 \\\\\n      2\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By the last part of Proposition~\\ref{prop:properties-dot-product}, we have\n  $\\norm{\\vect{u}} = \\sqrt {\\vect{u} \\dotprod \\vect{u}}$. We have\n  $\\vect{u} \\dotprod \\vect{u} = 2^2+1^2+4^2+2^2 = 25$, and therefore\n  $\\norm{\\vect{u}} = \\sqrt{\\vect{u} \\dotprod \\vect{u}} = \\sqrt{25} = 5$.\n\\end{solution}\n", "meta": {"hexsha": "96fcb186fefad2a4b4ecc7c3894f9db1484b3c59", "size": 2880, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 31.3043478261, "max_line_length": 110, "alphanum_fraction": 0.6354166667, "num_tokens": 1055, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425333801889, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.783492036579372}}
{"text": "\\chapter{Basic Numerical Methods}\n\n\\section{Roundoff and Truncation Errors}\n\n\\newthought{Floating point numbers} can be represented using either single- (32 bits) or double-precision (64 bits). Single-precision usually stores out to six or seven decimal places while double-precision can usually store up to 16 decimal places. The main pitfall of roundoff error is when two numbers are treated as being equal when the user has not intended for this to be the case. For example, say $\\epsilon$ is the smallest number in single-precision that we can store and $\\xi<\\epsilon$. If for two single-precision floating point numbers $a,b>\\epsilon$ we attempt to perform the operation\n\\begin{equation}\n\t\\frac{b}{(a+\\xi)-a},\n\\end{equation}\nwe will have some serious problems as our computer will treat $a+\\xi$ as $a$, resulting in $0$ in the denominator. Using double-precision often helps to alleviate these problems. Roundoff error depends on the hardware (and probably software) we are using. Thus, it can be persistent across many different parts of the program we are writing.\n\nTruncation error, unlike roundoff error, is generally \\textit{not} dependent on our choice of hardware, but rather on our choice of method (i.e. Euler, Runge-Kutta, etc.). Consider the Taylor series\n\\begin{equation}\n\tf(x+h) = f(x) + hf^{\\prime}(x) + \\frac{1}{2}h^2f^{\\prime\\prime}(x) + \\ldots\n\\end{equation}\nThis can be rearranged to solve for the derivative of $f$,\n\\begin{equation}\n\tf^{\\prime}(x)=\\frac{f(x+h)-f(x)}{h} + \\mathcal{O}(h),\n\t\\label{eq:right_deriv}\n\\end{equation}\nwhere $\\mathcal{O}(h)$ represents the truncation error of order $h$. How is this applied in numerical integration? Consider the example of projectile motion. Our equations of motion can be written as\n\\begin{align}\n\t\\frac{\\mathrm{d}\\mathbf{v}}{\\mathrm{d}t} &= \\mathbf{a}(\\mathbf{r},\\mathbf{v}), \\\\[0.5em]\n\t\\frac{\\mathrm{d}\\mathbf{r}}{\\mathrm{d}t} &= \\mathbf{v},\n\\end{align}\nwhere $\\mathbf{a}$ is the acceleration. Let's rewrite these equations of motion in terms of Eq. \\ref{eq:right_deriv},\n\\begin{align}\n\t\\frac{\\mathbf{v}(t+\\tau) - \\mathbf{v}(t)}{\\tau} + \\mathcal{O}(\\tau) &= \\mathbf{a}(\\mathbf{r}(t),\\mathbf{v}(t)) \\\\[0.5em]\n\t\\frac{\\mathbf{r}(t+\\tau) - \\mathbf{r}(t)}{\\tau} + \\mathcal{O}(\\tau) &= \\mathbf{v}(t)\n\\end{align}\nand then solving for the updated values of $\\mathbf{v}$ and $\\mathbf{r}$,\n\\begin{align}\n\t\\mathbf{v}(t+\\tau) &= \\mathbf{v}(t) + \\tau\\mathbf{a}(\\mathbf{r}(t),\\mathbf{v}(t)) + \\mathcal{O}(\\tau^2), \\\\[0.5em]\n\t\\mathbf{r}(t+\\tau) &= \\mathbf{r}(t) + \\tau\\mathbf{v}(t) + \\mathcal{O}(\\tau^2).\n\\end{align}\nThus, the truncation error for an Euler scheme is quadratic in $\\tau$, the timestep. However, we should be careful to draw the distinction between \\textit{local} and \\textit{global} truncation error. The global error is the sum of all the local truncation errors made at each iteration and is highly dependent on our choice of scheme. Consider a projectile motion problem on $t\\in(0,T)$ solved using the Euler method such that the number of steps is $N_{\\tau}=T/\\tau$. The global error is thus expressed as \n\\begin{equation}\n\t\\varepsilon_{G}\\propto N_{\\tau}\\times \\varepsilon_L.\n\\end{equation}\nIn the Euler method case, $\\varepsilon\\propto T/\\tau\\times\\mathcal{O}(\\tau^2)=\\mathcal{O}(\\tau)$. Thus, the global truncation error of the Euler scheme is $\\mathcal{O}(\\tau)$.\n\n\\section{Curve Fitting and Interpolation}\n\n\\newthought{Suppose we have $N$ data points} $(x_i,y_i)$ and we want to fit them to a curve $Y(x;\\{a_j\\})$ where $\\{a_j\\}$ is a set of $M$ adjustable parameters. If each point $y_i$ has an associated error $\\sigma_i$, the fit parameters can be determined by minimizing the $\\chi^2$-function\n\\begin{equation}\n\t\\label{eq:chi_squared}\n\t\\chi^2(\\{a_j\\})=\\sum^{N}_{i=1}\\left(\\frac{\\Delta_i}{\\sigma_i}\\right)= \\sum^{N}_{i=1}\\frac{[Y(x_i;\\{a_j\\}) - y_i]^2}{\\sigma_i^2}.\n\\end{equation}\nThe set of parameters $\\{a_j\\}$ are determined by finding all $a_j$ which satisfy $\\partial\\chi^2/\\partial a_j=0$. Now, say we want to fit $N$ data points to a function of the form\n\\begin{equation}\n\t\\label{eq:gen_func_lsq}\n\tY(x;\\{a_j\\}) = \\sum_{j=1}^Ma_jY_j(x).\n\\end{equation}\nTo find $\\{a_j\\}$, we compute $\\partial \\chi^2/\\partial a_j=0$ which for Eq. \\ref{eq:gen_func_lsq} can be expressed as\n\\begin{align}\n\t\\sum^N_{i=1}\\frac{1}{\\sigma_i^2}Y_j(x_i)\\left(\\sum_{k=1}^Ma_kY_k(x_i) - y_i\\right) = 0 \\\\[0.5em]\n\t\\sum^N_{i=1}\\sum^M_{k=1}\\frac{Y_jYk}{\\sigma_i^2} = \\sum^N_{i=1}\\frac{Y_jy_i}{\\sigma_i^2},\n\\end{align}\nfor $j=1,\\ldots,M$. We can rewrite this equation as \n\\begin{equation}\n\t\\sum^N_{i=1}\\sum^M_{k=1}A_{ij}A_{ik}a_k = \\sum^N_{i=1}A_{ij}\\frac{y_i}{\\sigma_i},\n\\end{equation}\nwhere $A_{ij}=Y_j(x_i)/\\sigma_i$ are the matrix elements of the so-called design matrix. In matrix form, this can be expressed as \n\\begin{equation}\n\t(\\mathbf{A}^T\\mathbf{A})\\mathbf{a} = \\mathbf{A}^T\\mathbf{b},\n\\end{equation}\nwhere $b_i=y_i/\\sigma_i$. This can be easily inverted to solve for $\\mathbf{a}$. The estimated errors for $a_j$ can be calculated using the equation\n\\begin{equation}\n\t\\sigma_{a_j} = \\sqrt{C_{jj}},\n\\end{equation}\nwhere $\\mathbf{C} = (\\mathbf{A}^T\\mathbf{A})^{-1}$ \\cite{garcia_numerical_2000}. How does one evaluate whether the curve $Y$ is a good fit to the data $y$? On average, we can say that the difference between the data and the fit should be roughly equal to the error bar such that $\\sigma_i\\approx|y_i - Y(x_i)|$. Plugging this into Eq. \\ref{eq:chi_squared} then gives that $\\chi^2\\approx N$. However, recalling that we have $M$ degrees of freedom, our condition should be revised such that $\\chi^2\\approx N-M$ implies an adequate fit. $\\chi^2\\gg N-M$ suggests that a poor choice of $Y$ or very small $\\sigma_i$ and $\\chi^2\\ll N-M$ implies either overfitting or that the error bars may be too large \\cite{garcia_numerical_2000}. \n%\n\\par \\hl{Still need something about interpolation}\n\n\\section{Numerical Integration}\n\\section{Basic Linear Algebra: Analytical and Numerical}\n\\section{Ordinary Differential Equations: Analytical and Numerical}\n\\section{Partial Differential Equations: Analytical and Numerical}\n", "meta": {"hexsha": "2ee5b8feb6ccfb1d4a02cc536c28fcec36803152", "size": 6085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/ch_numerical_methods.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_numerical_methods.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_numerical_methods.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": 78.0128205128, "max_line_length": 727, "alphanum_fraction": 0.716516023, "num_tokens": 1999, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.9284088015458666, "lm_q1q2_score": 0.7834796480830355}}
{"text": "% !TEX root = lectures.tex\n\\section{Math Basics}\n\\bigskip\n\n\\subsection{Scalars, Vectors and Matrices}\n\nA scalar is something with a value that is independent of coordinate system. Examples are mass, or the relative time between events. A vector has magnitude and direction. Under rotation, the magnitude stays the same but the direction changes. Scalars have no spatial index, whereas a three-dimensional vector has 3 indices, e.g. the position $\\vec{r}$ has components $r_1,r_2,r_3$, which are often referred to as $x,y,z$.\n\nThere are several categories of changes of coordinate system. The observer can translate the origin, might move with a different velocity, or might rotate his/her coordinate axes. For instance, a particle's position vector changes when the origin is translated, but its velocity does not. When you study relativity you will find that quantities you thought of as scalars, such as time or electric potential, are actually parts of four-dimensional vectors and that changes of the velocity of the reference frame act in a similar way to rotations.\n\nIn addition to vectors and scalars, there are matrices, which have two indices. One also has objects with 3 or four indices. These are called tensors of rank $n$, where $n$ is the number of indices. A matrix is a rank-two tensor. The Levi-Civita symbol, $\\epsilon_{ijk}$ used for cross products, is a third-rank tensor.\n\n\\subsubsection*{Unit Vectors}\n\nAlso known as basis vectors, unit vectors point in the direction of the coordinate axes, have unit norm, and are orthogonal to one another. Sometimes this is referred to as an orthonormal basis,\n\\begin{equation}\n\\hat{e}_i\\cdot\\hat{e}_j=\\delta_{ij}=\\left(\\begin{array}{ccc}\n1 & 0 & 0\\\\\n0& 1 & 0\\\\\n0 & 0 & 1\n\\end{array}\\right).\n\\end{equation}\nHere, $\\delta_{ij}$ is unity when $i=j$ and is zero otherwise. This is called the unit matrix, because you can multiply it with any other matrix and not change the matrix. The ``dot'' denotes the dot product, $\\vec{A}\\cdot\\vec{B}=A_1B_1+A_2B_2+A_3B_3=|A||B|\\cos\\theta_{AB}$. Sometimes the unit vectors are called $\\hat{x}$, $\\hat{y}$ and $\\hat{z}$. Vectors can be decomposed in terms of unit vectors,\n\\begin{equation}\n\\vec{r}=r_1\\hat{e}_1+r_2\\hat{e}_2+r_3\\hat{e}_3.\n\\end{equation}\nThe vector components $r_1$, $r_2$ and $r_3$ might be called $x$, $y$ and $z$ for a displacement of $v_x$, $v_y$ and $v_z$ for a velocity.\n\n\\subsubsection*{Rotations}\n\nHere, we use rotations as an example of matrices and their operations. One can consider a different orthonormal basis $\\hat{e}'_1$, $\\hat{e}'_2$ and $\\hat{e}'_3$. The same vector $\\vec{r}$ mentioned above can also be expressed in the new basis,\n\\begin{equation}\n\\vec{r}=r'_1\\hat{e}'_1+r'_2\\hat{e}'_2+r'_3\\hat{e}'_3.\n\\end{equation}\nEven though it is the same vector, the components have changed. Each new unit vector $\\hat{e}'_i$ can be expressed as a linear sum of the previous vectors,\n\\begin{equation}\n\\hat{e}'_i=\\sum_j U_{ij}\\hat{e}_j,\n\\end{equation}\nand the matrix $U$ can be found by taking the dot product of both sides with $\\hat{e}_k$,\n\\begin{eqnarray}\n\\nonumber\n\\hat{e}_k\\cdot\\hat{e}'_i&=&\\sum_jU_{ij}\\hat{e}_k\\cdot\\hat{e}_j\\\\\n\\label{eq:lambda_angles}\n\\hat{e}_k\\cdot\\hat{e}'_i&=&\\sum_jU_{ij}\\delta_{jk}=U_{ik}.\n\\end{eqnarray}\nThus, the matrix lambda has components $U_{ij}$ that are equal to the cosine of the angle between new unit vector $\\hat{e}'_i$ and the old unit vector $\\hat{e}_j$.\n\\begin{equation}\nU = \\left(\\begin{array}{ccc}\n\\hat{e}'_1\\cdot\\hat{e}_1& \\hat{e}'_1\\cdot\\hat{e}_2& \\hat{e}'_1\\cdot\\hat{e}_3\\\\\n\\hat{e}'_2\\cdot\\hat{e}_1& \\hat{e}'_2\\cdot\\hat{e}_2& \\hat{e}'_2\\cdot\\hat{e}_3\\\\\n\\hat{e}'_3\\cdot\\hat{e}_1& \\hat{e}'_3\\cdot\\hat{e}_2& \\hat{e}'_3\\cdot\\hat{e}_3\n\\end{array}\\right),~~~~~U_{ij}=\\hat{e}'_i\\cdot\\hat{e}_j=\\cos\\theta_{ij}.\n\\end{equation}\nNote that the matrix is not symmetric, $U_{ij}\\ne U_{ji}$. One can also look at the inverse transformation, by switching the primed and unprimed coordinates,\n\\begin{eqnarray}\n\\label{eq:inverseU}\n\\hat{e}_i&=&\\sum_jU^{-1}_{ij}\\hat{e}'_j,\\\\\n\\nonumber\nU^{-1}_{ij}&=&\\hat{e}_i\\cdot\\hat{e}'_j=U_{ji}.\n\\end{eqnarray}\nThe definition of transpose of a matrix, $M^{t}_{ij}=M_{ji}$, allows one to state this as\n\\begin{eqnarray}\n\\label{eq:transposedef}\nU^{-1}&=&U^{t}.\n\\end{eqnarray}\nA tensor obeying Eq. (\\ref{eq:transposedef}) defines what is known as a unitary, or orthogonal, transformation.\n\nThe matrix $U$ can be used to transform any vector to the new basis. Consider a vector\n\\begin{eqnarray}\n\\vec{r}&=&r_1\\hat{e}_1+r_2\\hat{e}_2+r_3\\hat{e}_3\\\\\n\\nonumber\n&=&r'_1\\hat{e}'_1+r'_2\\hat{e}'_2+r'_3\\hat{e}'_3.\n\\end{eqnarray}\nThis is the same vector expressed as a sum over two different sets of basis vectors. The coefficients $r_i$ and $r'_i$ represent components of the same vector. The relation between them can be found by taking the dot product of each side with one of the unit vectors, $\\hat{e}_i$, which gives\n\\begin{eqnarray}\nr_i&=&\\sum_j \\hat{e}_i\\cdot\\hat{e}'_j~r'_j.\n\\end{eqnarray}\nUsing Eq. (\\ref{eq:inverseU}) one can see that the transformation of $r$ can be also written in terms of $U$,\n\\begin{eqnarray}\n\\label{eq:rotateR}\nr_i&=&\\sum_jU^{-1}_{ij}~r'_j.\n\\end{eqnarray}\nThus, the matrix that transforms the coordinates of the unit vectors, Eq. (\\ref{eq:inverseU}) is the same one that transforms the coordinates of a vector, Eq. (\\ref{eq:rotateR}). \n\n\\example\\label{ex:rotmat}\nFind the rotation matrix $U$ for finding the components in the primed coordinate system given from those in the unprimed system, given that the unit vectors in the new system are found by rotating the coordinate system by and angle $\\phi$ about the $z$ axis.\\\\\nSolution:\\\\\nIn this case\n\\begin{eqnarray*}\n\\hat{e}'_1&=&\\cos\\phi \\hat{e}_1-\\sin\\phi\\hat{e}_2,\\\\\n\\hat{e}'_2&=&\\sin\\phi\\hat{e}_1+\\cos\\phi\\hat{e}_2,\\\\\n\\hat{e}'_3&=&\\hat{e}_3.\n\\end{eqnarray*}\n\nBy inspecting Eq. (\\ref{eq:lambda_angles}),\n\\[\nU=\\left(\\begin{array}{ccc}\n\\cos\\phi&-\\sin\\phi&0\\\\\n\\sin\\phi&\\cos\\phi&0\\\\\n0&0&1\\end{array}\\right).\n\\]\n\\exampleend\n\nUnder a unitary transformation $U$ (or basis transformation) scalars are unchanged, whereas vectors $\\vec{r}$ and matrices $M$ change as\n\\begin{eqnarray}\nr'_i&=&U_{ij}~ r_j, ~~({\\rm sum~inferred})\\\\\n\\nonumber\nM'_{ij}&=&U_{ik}M_{km}U^{-1}_{mj}.\n\\end{eqnarray}\nPhysical quantities with no spatial indices are scalars (or pseudoscalars if they depend on right-handed vs. left-handed coordinate systems), and are unchanged by unitary transformations. This includes quantities like the trace of a matrix -- the matrix itself had indices but none remain after performing the trace.\n\\begin{eqnarray}\n{\\rm Tr} M&\\equiv& M_{ii}.\n\\end{eqnarray}\nBecause there are no remaining indices, one expects it to be a scalar. Indeed one can see this,\n\\begin{eqnarray}\n{\\rm Tr} M'&=&U_{ij}M_{jm}U^{-1}_{mi}\\\\\n\\nonumber\n&=&M_{jm}U^{-1}_{mi}U_{ij}\\\\\n\\nonumber\n&=&M_{jm}\\delta_{mj}\\\\\n\\nonumber\n&=&M_{jj}={\\rm Tr} M.\n\\end{eqnarray}\nA similar example is the determinant of a matrix, which is also a scalar.\n\n\\subsubsection*{Vector and Matrix Operations}\n\\begin{itemize}\\itemsep=0pt\n\\item Scalar Product (or dot product): For vectors $\\vec{A}$ and $\\vec{B}$,\n\\begin{eqnarray*}\n\\vec{A}\\cdot\\vec{B}&=&A_iB_i=|A||B|\\cos\\theta_{AB},\\\\\n|A|&\\equiv& \\sqrt{\\vec{A}\\cdot\\vec{A}}.\n\\end{eqnarray*}\nNote that the summation sign is inferred any time there are repeated indices. For example, \n\\begin{eqnarray}\nA_iB_i&=&\\sum A_iB_i.\n\\end{eqnarray}\n\\item Multiplying a matrix $C$ times a vector $\\vec{A}$:\n\\[\n(CA)_i=C_{ij}A_j.\n\\]\nFor the $i^{\\rm th}$ element one takes the scalar product of the $i^{\\rm th}$ row of $C$ with the vector $\\vec{A}$.\n\\item Mutiplying matrices $C$ and $D$:\n\\[\n(CD)_{ij}=C_{ik}D_{kj},\n\\]\nThis means the one obtains the $ij$ element by taking the scalar product of the $i^{\\rm th}$ of $C$ with the $j^{\\rm th}$ column of $D$.\n\\item Vector Product (or cross product) of vectors $\\vec{A}$ and $\\vec{B}$:\n\\begin{eqnarray*}\n\\vec{C}&=&\\vec{A}\\times\\vec{B},\\\\\nC_i&=&\\epsilon_{ijk}A_jB_k.\n\\end{eqnarray*}\nHere $\\epsilon$ is the third-rank anti-symmetric tensor, also known as the Levi-Civita symbol. It is $\\pm 1$ only if all three indices are different, and is zero otherwise. The choice of $\\pm 1$ depends on whether the indices are an even or odd permutation of the original symbols. The permutation $xyz$ or $123$ is considered to be $+1$. For the 27 elements,\n\\begin{eqnarray}\n\\epsilon_{ijk}&=&-\\epsilon_{ikj}=-\\epsilon_{jik}=-\\epsilon_{kji}\\\\\n\\nonumber\n\\epsilon_{123}&=&\\epsilon_{231}=\\epsilon_{312}=1,\\\\\n\\nonumber\n\\epsilon_{213}&=&\\epsilon_{132}=\\epsilon_{321}=-1,\\\\\n\\nonumber\n\\epsilon_{iij}&=&\\epsilon_{iji}=\\epsilon_{jii}=0.\n\\end{eqnarray}\nYou used cross products extensively when studying magnetic fields. Because the matrix is anti-symmetric, switching the $x$ and $y$ axes (or any two axes) flips the sign. If the coordinate system is right-handed, meaning the $xyz$ axes satisfy $\\hat{x}\\times\\hat{y}=\\hat{z}$, where you can point along the $x$ axis with your extended right index finger, the $y$ axis with your contracted middle finger and the $z$ axis with your extended thumb. Switching to a left-handed system flips the sign of the vector $\\vec{C}=\\vec{A}\\times\\vec{B}$. Note that $\\vec{A}\\times\\vec{B}=-\\vec{B}\\times\\vec{A}$. The vector $\\vec{C}$ is perpendicular to both $\\vec{A}$ and $\\vec{B}$ and the magnitude of $\\vec{C}$ is given by \n\\[\n|C|=|A||B|\\sin\\theta_{AB}.\n\\]\nVectors obtained by the cross product of two real vectors are called pseudo-vectors because the assignment of their direction can be arbitrarily flipped by defining the Levi-Civita symbol to be based on left-handed rules. Examples are the magnetic field and angular momentum. If the direction of a real vector prefers the right-handed over the left-handed direction, that constitutes a violation of parity. For instance, one can polarize the spins (angular momentum) of nuclei with a magnetic field so that the spins preferentially point along the direction of the magnetic field. This does not violate parity because both are pseudo-vectors. Now assume these polarized nuclei decay and that electrons are one of the products. If these electrons prefer to exit the decay parallel vs. antiparallel to the polarizing magnetic field, this constitutes parity violation because the direction of the outgoing electron momenta are a real vector. This is precisely what is observed in weak decays.\n\n\\item Differentiation of a vector with respect to a scalar: For example, the acceleration is $d\\vec{v}/dt$:\n\\[\n(d\\vec{v}/dt)_i=\\frac{dv_i}{dt}.\n\\]\n\n\\item Angular velocity: Choose the vector $\\vec{\\omega}$ so that the motion is like your fingers wrapping around your thumb on your right hand with $\\vec{\\omega}$ pointing along your thumb. The magnitude is $d|\\phi|/dt$.\n\n\\item Gradient operator $\\nabla$: This is the derivative $\\partial/\\partial x$, $\\partial/\\partial y$ and $\\partial/\\partial z$, where $\\partial _x$ means $\\partial/\\partial_x$. For taking the gradient of a scalar $\\Phi$,\n\\[\n{\\rm\\bf grad}~\\Phi, (\\nabla\\Phi(x,y,z,t))_i=\\partial/\\partial r_i\\Phi(\\vec{r},t)=\\partial_i\\Phi(\\vec{r},t).\n\\]\nFor taking the dot product of the gradient with a vector, sometimes called a divergence,\n\\[\ndiv \\vec{A}, \\nabla\\cdot\\vec{A}=\\partial_i A_i.\n\\]\nFor taking the vector product with another vector, sometimes called curl, $\\nabla\\times\\vec{A}$,\n\\[\n{\\rm\\bf curl}~\\vec{A}, (\\nabla\\times\\vec{A})_i=\\epsilon_{ijk}\\partial_j A_k(\\vec{r},t).\n\\]\n\\item The Laplacian is referred to as $\\nabla^2$ and is defined as\n\\[\n\\nabla^2=\\nabla\\cdot\\nabla=\\frac{\\partial^2}{\\partial x^2}+\\frac{\\partial^2}{\\partial y^2}+\\frac{\\partial^2}{\\partial z^2}.\n\\]\n\\end{itemize}\n\n\\subsubsection*{Some identities}\n\nHere we simply state these, but you may wish to prove a few. They are useful for this class and will be essential when you study E\\&M.\n\\begin{eqnarray}\n\\vec{A}\\cdot(\\vec{B}\\times\\vec{C})&=&\\vec{B}\\cdot(\\vec{C}\\times\\vec{A})=\\vec{C}\\cdot(\\vec{A}\\times\\vec{B})\\\\\n\\nonumber\n\\vec{A}\\times(\\vec{B}\\times\\vec{C})&=&(\\vec{A}\\cdot\\vec{C})\\vec{B}-(\\vec{A}\\cdot\\vec{B})\\vec{C}\\\\\n\\nonumber\n(\\vec{A}\\times\\vec{B})\\cdot(\\vec{C}\\times\\vec{D})&=&(\\vec{A}\\cdot\\vec{C})(\\vec{B}\\cdot\\vec{D})\n-(\\vec{A}\\cdot\\vec{D})(\\vec{B}\\cdot\\vec{C})\n\\end{eqnarray}\n\n\n\n\\example\nThe height of a hill is given by the formula \n\\[\nz(x,y)=2xy-3x^2-4y^2-18x+28y+12.\n\\]\nHere $z$ is the height in meters and $x$ and $y$ are the east-west and north-south coordinates. Find the position $x,y$ where the hill is the highest, and give its height.\n\n{\\bf Solution:} The maxima or minima, or inflection points, are given when $\\partial_x z=0$ and $\\partial_yz=0$.\n\\begin{eqnarray*}\n\\partial_xz(x,y)&=&2y-6x-18=0,\\\\\n\\partial_yz(x,y)&=&2x-8y+28=0.\n\\end{eqnarray*}\nSolving for two equations and two unknowns gives one solution $x=-2,y=3$. This then gives $z=72$. Although this procedure could have given a minimum or an inflection point you can look at the form for $z$ and see that for $x=y=0$ the height is lower, therefore it is not a minimum. You can also look and see that the quadratic contributions are negative so the height falls off to $-\\infty$ far away in any direction. Thus, there must be a maximum, and this must be it. Deciding between maximum or minimum or inflection point for a general problem would involve looking at the matrix $\\partial_i\\partial_j z$ at the specific point, then finding the eigenvalues of the matrix and seeing whether they were both positive (minimum) both negative (maximum) or one positive and one negative (saddle point).\n\n\\exampleend\n\n\\subsubsection*{Gauss's Theorem and Stokes's Theorem}\n\nFor an integral over a volume $V$ confined by a surface $S$, Gauss's theorem gives\n\\[\n\\int_V dv~\\nabla\\cdot\\vec{A}=\\int_Sd\\vec{S}\\cdot\\vec{A}.\n\\]\nFor a closed path $C$ which carves out some area $S$, \n\\[\n\\int_C d\\vec{\\ell}\\cdot\\vec{A}=\\int_Sd\\vec{s} \\cdot(\\nabla\\times\\vec{A})\n\\]\nStoke's law can be understood by considering a small rectangle, $-\\Delta x<x<\\Delta x$, $-\\Delta y<y<\\Delta y$. The path integral around the edges is\n\\begin{eqnarray}\n\\int_C d\\vec{\\ell}\\cdot\\vec{A}&=&2\\Delta y[A_y(\\Delta x,0)-A_y(-\\Delta x,0)]-2\\Delta x[A_x(0,\\Delta y)-A_x(0,-\\Delta y)]\\\\\n\\nonumber\n&=&4\\Delta x\\Delta y\\left\\{\n\\frac{A_y(\\Delta x,0)-A_y(-\\Delta x,0)}{2\\Delta x}-\\frac{A_x(0,\\Delta y)-A_x(0,-\\Delta y)}{2\\Delta y}\\right\\}\\\\\n\\nonumber\n&=&4\\Delta x\\Delta y\\left\\{\\frac{\\partial A_y}{\\partial x}-\\frac{\\partial A_x}{\\partial y}\\right\\}\\\\\n&=&\\Delta S \\cdot \\nabla\\times\\vec{A}.\n\\end{eqnarray}\nHere $\\Delta S$ is the area of the surface element.\n\n\\subsubsection*{Some Notation}\nFrom here on in, we may use bold face to denote vectors, e.g. ${\\bf v}$ instead of $\\vec{v}$. We also might use dots over quantities to represent time derivatives, e.g. $\\dot{\\bf v}=d{\\bf v}/dt$. As mentioned above, repeated indices infer sums, e.g.,\n\\begin{eqnarray}\nx_iy_i&=&\\sum_i x_iy_i=\\vec{x}\\cdot\\vec{y},\\\\\n\\nonumber\nx_iA_{ij}y_j&=&\\sum_{ij}x_iA_{ij}y_j,\n\\end{eqnarray}\n\n\n\\subsection{Exercises}\n\n\\begin{enumerate}\n\n\\item All physicists must become comfortable with thinking of oscillatory and wave mechanics in terms of expressions that include the form $e^{i\\omega t}$.\n\\begin{enumerate}\n\\item Perform Taylor expansions in powers of $\\omega t$ of the functions $\\cos\\omega t$ and $\\sin\\omega t$.\n\\item Perform a Taylor expansion of $e^{i\\omega t}$.\n\\item Using parts (a) and (b) show that $e^{i\\omega t}=\\cos\\omega t+i\\sin\\omega t$.\n\\item Show that $\\ln(-1)=i\\pi$.\n\\end{enumerate}\n\n\\item One of the many uses of the scalar product is to find the angle between two given vectors. Find the angle between the vectors $\\vec{b}=(1,2,4)$ and $\\vec{c}=(4,2,1)$ by evaluating their scalar product.\n\n\\item Use the product rule to show that\n\\[\n\\frac{d}{dt}(\\vec{r}\\cdot\\vec{s})=\\frac{d\\vec{r}}{dt}\\cdot\\vec{s}+\\vec{r}\\cdot\\frac{d\\vec{s}}{dt}.\n\\]\n\n\\item Multiply the rotation matrix in Example \\ref{ex:rotmat} by its transpose to show that the matrix is unitary or orthogonal, i.e. you get the unit matrix.\n\n\\item Find the matrix for rotating a coordinate system by 90 degrees about the $x$ axis.\n\n\\begin{comment}\n\n\\item Consider a rotation where in the new coordinate system the three axes are at angles $\\alpha$, $\\beta$ and $\\gamma$ relative to the original $x$ axis. Show that\n\\[\n\\cos^2\\alpha+\\cos^2\\beta+\\cos^2\\gamma=1.\n\\]\n\n\\item Find the rotation matrix for each of the three rotations, then find the matrix for the combined rotations.\nFirst rotate by 90$^\\circ$ around the $y$ axis to get to the primed system. Then rotate the primed system 90$^\\circ$ about the new $z$ axis to get to the doubly primed system. Then find the matrix that rotates the doubly primed coordinate system 90$^\\circ$ about the new $x$ axis to get to the triply primed system. Finally, find the matrix that performs all three operations sequentially.\n\n\\end{comment}\n\n\\item Consider a parity transformation which reflects about the $x=0$ plane. Find the matrix that performs the transformation. Find the matrix that performs the inverse transformation.\n\n\\item Show that the scalar product of two vectors is unchanged if both undergo the same rotation. Use the fact that the rotation matrix is unitary, $U_{ab}=U^{-1}_{ba}$.\n\n\\item Show that the product of two unitary matrices is a unitary matrix. \n\n\\item Show that\n\\[\n\\sum_k\\epsilon_{ijk}\\epsilon_{klm}=\\delta_{il}\\delta_{jm}-\\delta_{im}\\delta_{jl}.\n\\]\n\n\\item Consider a cubic volume $V=L^3$ defined by $0<x<L$, $0<y<L$ and $0<z<L$. Consider a vector $\\vec{A}$ that depends arbitrarily on $x,y,z$. Show how Gauss's law,\n\\[\n\\int_V dv\\nabla\\cdot\\vec{A}=\\int_Sd\\vec{S}\\cdot\\vec{A},\n\\]\nis satisfied by direct integration. I.e., you should use the fact that $\\int_a^b dx~(d/dx)f(x)=f(b)-f(a)$.\n\n\\item Consider the function $z=3x^2-4y^2+12xy-6x+24$. Find any maxima or minima and determine whether it is a maximum or a minimum or an inflection point.\n\n\\item A real $n-$dimensional symmetric matrix $\\lambda$ can always be diagonalized by a unitary transformation, i.e. there exists some unitary matrix $U$ such that,\n\\begin{eqnarray}\nU_{ij}\\lambda_{jk}U^{-1}_{km}&=&\\tilde{\\lambda}_{im}=\\left(\\begin{array}{cccc}\n\\tilde{\\lambda}_{11}&0&\\cdots&0\\\\\n0&\\tilde{\\lambda}_{22}&\\cdots&0\\\\\n\\vdots& & \\ddots & \\vdots\\\\\n0& \\cdots &\\cdots &\\tilde{\\lambda}_{nn}\n\\end{array}\\right).\n\\end{eqnarray}\nThe values $\\tilde{\\lambda}_{ii}$ are referred to as eigenvalues. The set of $n$ eigenvalues are unique, but their ordering is not -- there exists a unitary transformation that permutes the indices. \n\nConsider a function $f(x_1,\\cdots,x_n)$ that has the property,\n\\begin{eqnarray}\n\\left.\\partial_i f(\\vec{x})\\right|_{\\vec{x}=0}=0,\n\\end{eqnarray}\nfor all $i$. Show that if this function is a minimum, and not a maximum or an inflection point, that the $n$ eigenvalues of the matrix\n\\begin{eqnarray}\n\\lambda_{ij}&\\equiv&\\left.\\partial_i\\partial_j f(\\vec{x})\\right|_{\\vec{x}=0},\n\\end{eqnarray}\nmust be positive.\n\n\\item\n\\begin{enumerate}\n\\item For the unitary matrix $U$ that diagonalizes $\\lambda$ as shown in the previous problem. Show that each row of the unitary matrix represents an orthogonal unit vector by using the definition of a unitary matrix.\n\\item Show that the vector\n\\begin{eqnarray}\nx_i^{(k)}&\\equiv& U_{ki}=(U_{k1},U_{k2},\\cdots,U_{kn}),\n\\end{eqnarray}\nhas the property that\n\\begin{eqnarray}\n\\lambda_{ij}x^{(k)}_j&=&\\tilde{\\lambda}_{kk}x^{(k)}_i.\n\\end{eqnarray}\nThese vectors are known as eigenvectors, as they have the property that when multiplied by $\\lambda$ the resulting vector is proportional ( same direction) as the original vector. Because one can transform to a basis, using $U$, where $\\lambda$ is diagonalized, in the new basis the eigenvectors are simply the unit vectors.\n\\end{enumerate}\n\\end{enumerate} \n\n", "meta": {"hexsha": "e16657cd60a1d6fffdd2ee82184cc76d5a4811e3", "size": 19612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/AdminBackground/lectures/chapter1.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/chapter1.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/chapter1.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": 57.011627907, "max_line_length": 989, "alphanum_fraction": 0.721853967, "num_tokens": 6257, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7834796399572793}}
{"text": "\n\\subsection{Classic regression trees}\n\nIn a classical regression tree, we follow a decison process as before, but the outcome is real number.\n\nWithin each leaf, all inputs are assigned that same number.\n\n\\subsubsection{Training}\n\nWith a regression problem we cannot split nodes the same way as we did for classification.\n\nInstead by split by the residual sum of squares.\n\n", "meta": {"hexsha": "1aa7dd0eeb4f4d599f8d7bb1e5cf4e510657239d", "size": 373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treesRegression/01-01-regressionTrees.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treesRegression/01-01-regressionTrees.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treesRegression/01-01-regressionTrees.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.6428571429, "max_line_length": 102, "alphanum_fraction": 0.7935656836, "num_tokens": 75, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7834796326673324}}
{"text": "\\section{Results}\nAll the implemented transforms where tested for correctness by comparing the output\nof my implementation to other reference-implementations, like matlab's or scipy's.\nThe implementation was also tested for speed depending on the length of the input.\nFor a given input length the FFT algorithm was performed multiple times with random numbers\nand the\nruntime was measured and averaged. The number of times the algorithm was evaluated\nwas chosen, such that the uncertainty of the average was below \\SI{10}{\\nano\\second}.\nWhile the actual numbers will be more or less uninteresting, it is possible to see\nthe $\\symcal{O}(N\\log N)$ scaling for powers of 2, as shown in \\autoref{fig:timesp2}.\nEspecially for higher-length input the scaling is fulfilled, but for short length\ninput there is too much overhead, and thus the numbers are not following $N\\log N$ perfectly there.\n\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=\\linewidth]{build/plots/times_p2.pdf}\n    \\caption{Runtime of my FFT implementation in double-logarithmic-scaling depending on the length of the input sequence.\n        Each random-number input is transformed multiple time and the results were averaged.\n        The function $t(N)=c\\times N\\log N$ is fitted to the measurements, as we expect this scaling for\n        input lengths in the form of $2^p$. }\n    \\label{fig:timesp2}\n\\end{figure}\n\nFor arbitrary sized input, the actual runtime of this algorithm depends heavily on\nthe number of two's in the prime-factor decomposition of the input-length.\nIn easier words: the FFT of 48 numbers should be roughly twice as fast as 56, even though\n56 is the higher number.\nThe reason is 48 is divisible by 2 4 times ($48=2^4\\cdot 3$), where 56 is only divisble by\n2 3 times ($56=2^3\\cdot 7$).\nThis is also clearly seen in the data, as \\autoref{fig:times} shows.\n\\begin{figure}[t]\n    \\centering\n    \\includegraphics[width=.5\\textwidth]{build/plots/times_lin_c.pdf}\n    \\caption{Averaged runtime of the implemented FFT algorithm on random numbers depending on the input length.\n        A clear separation of the runtime scaling is seen. The data-points are colored\n        depending on the number of times the input length is divisible by 2.}\n    \\label{fig:times}\n\\end{figure}\n\n\n\\subsection{Depicting the Fourier Space}\nA digital image is nothing more than $N=h\\cdot w\\cdot C$ numbers $x_{k,l,c}$\n\\footnote{$k=0,\\dots, h-1\\quad l=0,\\dots,w-1\\quad c=0,\\dots,C-1$}\nbetween $0$ and $1$.\nWhere $w$ is the width, $h$ is the height and $C$ is the number of channels of the image.\nThere are a lot of different types of images out there, with different channel numbers and interpretation\nof them (different color encodings, transparent images, etc.), but we will focus on the\ncase of grayscale $C=1$ or colored RGB $C=3$ pictures.\nThe interpretation of the number in grayscale images is the illumination of the pixel ranging from $0=$~off~$=$~black\nto $1=$~on~$=$~white.\nIn colored RGB images, we have three channels: Red (R), Green (G), Blue (B). Where we can light up each color separately.\nBecause of how the eye works, we are able to trick the brain into perceiving most of the colors by just\nmixing these three.\nThe numbers are usually not stored as floating point numbers, but as unsigned integers, most commonly 8-bit unsigned integers.\nThis means that 1 is stored as 255 and 0 as 0 and all the numbers are mapped in an equally spaced fashion.\nIf we have multiple channels, we will Fourier transform each channel separately and\nequation \\eqref{eqn:dft2d} gets the form\n\\begin{equation*}\n    X_{k,l,c} = \\frac{1}{\\sqrt{hw}}\\sum_{n=0}^{h-1}\\sum_{m=0}^{w-1}x_{n,m,c} \\ e^{-i{2\\pi}\\ \\left(\\!\\frac{kn}{h}+\\frac{lm}{w}\\right)}.\n\\end{equation*}\nIn the Fourier space each pixel is a complex number.\nWe usually visualize the magnitude and the phase (the argument) of each number.\nBecause the magnitude of the Fourier transformed numbers is not guaranteed\nto be between 0 and 255, we scale the Fourier transformed numbers in such a way,\nthat the highest is 255 and the lowest is 0\n\\begin{equation*}\n    \\abs {X'_{k,l,c}} = 255\\frac{\\abs {X_{k,l,c}}-\\min_{n,m} \\abs {X_{n,m,c}}}{\\max_{n,m} \\abs {X_w{n,m,c}}-\\min_{n,m} \\abs {X_{n,m,c}}}.\n\\end{equation*}\nWe also scale the phases to the range of $(0, 255)$\n\\begin{equation*}\n    \\arg {X'_{k,l,c}} = 255\\frac{\\arg X_{k,l,c}}{2\\pi}.\n\\end{equation*}\nThis mode of visualization can be seen in \\autoref{subfig:ftm_n} and \\autoref{subfig:ftp_n}.\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.9\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{images/webb.png}\n        \\caption{Original}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.9\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/output/webb_mag_n.png}\n        \\caption{Fourier Transform Magnitude}\n        \\label{subfig:ftm_n}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.9\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/output/webb_phase_n.png}\n        \\caption{Fourier Transform Phase}\n        \\label{subfig:ftp_n}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.9\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/output/webb_mag_log.png}\n        \\caption{Fourier Transform magnitude in logarithmic space}\n        \\label{subfig:ftm_log}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.9\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/output/webb_mag.png}\n        \\caption{FT Magnitude in logarithmic space and rearranged}\n        \\label{subfig:ftm}\n    \\end{subfigure}\n    \\caption{An example of the Fourier transform. The image is the first calibration picture of the new James-Webb space telescope\\cite{webbimg}. }\n    \\label{fig:fourier_example_n}\n\\end{figure}\n\nAs you can see in the example image, the Fourier magnitude is mostly black, and the phases appear to be noise to the eye.\nTo better distinguish small features, we will now switch to logarithmic color-space for the magnitude\n\\begin{equation*}\n    \\abs {X''_{k,l,c}} = 255\\frac{\\log \\abs {X_{k,l,c}}-\\min_{n,m} \\log\\abs {X_{n,m,c}} } {\\max_{n,m} \\log\\abs {X_{n,m,c}}-\\min_{n,m} \\log\\abs {X_{n,m,c}}}.\n\\end{equation*}\nThis is depicted in \\autoref{subfig:ftm_log}.\nFinally, to better resemble the symmetries in the Fourier space and\nto have low frequencies in the middle of the picture, and high frequencies outside,\nthe indices are shifted\n\\begin{equation}\n    k' = \\lfloor k+h/2\\rfloor \\mod h \\qquad l'=\\lfloor l+w/2\\rfloor\\mod w.\n    \\label{eqn:shift}\n\\end{equation}\nThis will be our method of visualization from now on and can be seen in \\autoref{subfig:ftm}.\n\n\\subsection{Editing in Fourier Space}\nIf we now modify the numbers in the Fourier space and transform the modified numbers back,\nwe can achieve complex-looking outcome.\nFor example, if we take the high frequencies in the image away, we are only left with the\n\"long-range\" information, but the \"short-range\" information is lost.\nThis means the image will appear to be blurred.\nTaking away the high frequencies can be done in multiple ways.\nWe can just remove the highest frequencies combining the axes by calculating\n$(k'-h/2)^2+(l'-w/2)^2 < r^2$ for some $r$ and setting the pixel in Fourier space to 0, if\nthis evaluates to false. We can also do this for each axis independently\n($(k'-h/2)^2<r_y^2$, $(l'-w/2)^2<r_x^2$).\nWith these hard cut-offs it is easy to see periodic artifacts in the image.\nIf we do not want that, we can apply a smooth filter.\nA selection of different blurring techniques can be seen\nin \\autoref{fig:blur_2} to \\autoref{fig:blur_smooth}.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_mag.png}\n        \\caption{Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{images/dune.png}\n        \\caption{Original}\n    \\end{subfigure}\\\n    \\caption{A movie poster of Dune (2021) which serves as an example image being blurred in this section \\cite{dune}.}\n    \\label{fig:dune_orig}\n\\end{figure}\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur2_mask.png}\n        \\caption{Edit in Fourier space }\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur2.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The poster above blurred by only keeping the innermost frequencies with a radius of $20\\%$ of the width.}\n    \\label{fig:blur_2}\n\\end{figure}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur1_mask.png}\n        \\caption{Edit in Fourier space }\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur1.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The poster blurred by only keeping the innermost frequencies with a radius of $10\\%$ of the width. This is a circular filter.}\n    \\label{fig:blur_1}\n\\end{figure}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_rect_mask.png}\n        \\caption{Edit in Fourier space }\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur_rect.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The poster blurred by only keeping the $10\\%$ innermost frequencies along each axis independently. This is a rectangular filter.}\n    \\label{fig:blur_rect}\n\\end{figure}\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur_smooth_mask.png}\n        \\caption{Edit in Fourier space }\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/dune_blur_smooth.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The poster blurred by only multipliying each pixel in the Fourier space with $\\exp(-0.001 ((k'-h/2)^2+(l'-w/2)^2))$, where $k', l'$ are the shifted indices from above. This is a Gaussian filter.}\n    \\label{fig:blur_smooth}\n\\end{figure}\n\n\\FloatBarrier\n\nIf we do the opposite and take away some low frequencies, we are \"sharpening\" the image.\nWe must not understand \"sharpening\" in the literal meaning, like focusing the lens of a camera,\nsince we can not generate new information in the image. We can only enhance the short range information.\nThere are a couple of examples below in \\autoref{fig:blackhole} to \\autoref{fig:blackhole_sharp_g_g}.\nYou will notice the colors in the images are distorted, since we completely treat the\ncolor channels separately. In \\autoref{fig:blackhole_sharp_g_g} you can see a grayscale version\nof the edit, where the colors might be less distracting.\n\nIf we take it to the extreme and remove most low frequencies, we can seethe edges in the image, this\nis demonstrated in \\autoref{fig:edges}.\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp_smooth_mask.png}\n        \\caption{Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{images/blackhole.png}\n        \\caption{Original}\n    \\end{subfigure}\\\n    \\caption{The first image of a black hole, taken in 2021.\n        This appears not to be sharp and is taken as an example to experiment with sharpening in Fourier space in this section. }\n    \\label{fig:blackhole}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp1_mask.png}\n        \\caption{Edit in Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp1.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The black hole image sharpened by applying a circular filter with a radius of 1\\% of the height.}\n    \\label{fig:blackhole_sharp}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp3_mask.png}\n        \\caption{Edit in Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp3.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The black hole image sharpened by applying a circular filter with a radius of 3\\% of the height.}\n    \\label{fig:blackhole_sharp3}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp_smooth_mask.png}\n        \\caption{Edit in Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp_smooth.png}\n        \\caption{Transformed back to real space}\n    \\end{subfigure}\\\n    \\caption{The black hole image sharpened by applying a Gaussian filter of $1-\\exp(-0.01 ((k'-h/2)^2+(l'-w/2)^2))$.}\n    \\label{fig:blackhole_sharp_g}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp_smooth_mask_g.png}\n        \\caption{Edit in Fourier space}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/blackhole_sharp_smooth_g.png}\n        \\caption{Original}\n    \\end{subfigure}\\\n    \\caption{The black hole image sharpened by applying a Gaussian filter of $1-\\exp(-0.01 ((k'-h/2)^2+(l'-w/2)^2))$ in black and white.}\n    \\label{fig:blackhole_sharp_g_g}\n\\end{figure}\n\\begin{figure}\n    \\centering\n    \\begin{subfigure}[h]{.32\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{images/A.png}\n        \\caption{Original }\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.32\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/A_sharp_smooth_mask.png}\n        \\caption{Edit}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.32\\linewidth}\n        \\centering\n        \\includegraphics[width=.9\\linewidth]{build/output/A_sharp_smooth.png}\n        \\caption{Back to real space}\n    \\end{subfigure}\n    \\caption{An image sharpened with a Gaussian filter of $1-\\exp(-0.001 ((k'-h/2)^2+(l'-w/2)^2))$ to demonstrate edge-detecting capabilities of Fourier edits.}\n    \\label{fig:edges}\n\\end{figure}\n\\FloatBarrier\n\n\\subsection{Diffraction}\nAs already mentioned, we can\n\"simulate\" Fraunhofer diffraction by displaying the magnitude of the Fourier transformed image.\nIn the images in this section, you will be able to realize a couple of known features\nof diffraction images.\nLines in the diffraction images will be perpendicular to lines in the aperture (the original image).\nFor two double slits of width $b$ and distance $a$ the analytical expression for Fraunhofer diffraction\nis\n\\begin{equation*}\n    I(\\theta) = I_0 \\left(\\frac{\\sin(c b \\sin\\theta)}{c b \\sin\\theta} \\cos(c a \\sin\\theta)\\right)^2.\n\\end{equation*}\nWhich is calculated by solving equation \\eqref{eqn:fraunhofer}.\nWith some constant $c$. From this we can read that the smaller the slits are, the wider the\nencapsulating intensity is (since $b < a$) and the closer the slits are, the smaller the distance between\nthe peaks is. This can be seen in \\autoref{fig:double_slit}.\n\nThis calculation is rather simple, but also more complex apertures can be investigated, like a circular\naperture, seen in \\autoref{fig:circular}. The analytical solution to this is a Bessel function of the radius.\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/hole.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/hole_mag.png}\n        \\caption{Circular aperture.}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/hole_tiny.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/hole_tiny_mag.png}\n        \\caption{Circular aperture with smaller radius.}\n    \\end{subfigure}\n    \\caption{Fraunhofer diffraction image (right) for two different circular apertures (left).}\n    \\label{fig:circular}\n\\end{figure}\n\n\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/double_slit_small_norm.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/double_slit_small_norm_mag.png}\n        \\caption{Double slit.}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/double_slit_small_close.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/double_slit_small_close_mag.png}\n        \\caption{Double slit where the slits are closer.}\n    \\end{subfigure}\n    % \\begin{subfigure}[h]{\\linewidth}\n    %     \\centering\n    %     \\includegraphics[width=.49\\linewidth]{images/double_slit_small_wide.png}\n    %     \\includegraphics[width=.49\\linewidth]{build/output/double_slit_small_wide_mag.png}\n    %     \\caption{Simulated diffraction image (right) of aperture image (left).}\n    % \\end{subfigure}\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/double_slit_small_widest.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/double_slit_small_widest_mag.png}\n        \\caption{Double slit where the slits are further apart.}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{\\linewidth}\n        \\centering\n        \\includegraphics[width=.49\\linewidth]{images/double_slit_norm_widest.png}\n        \\includegraphics[width=.49\\linewidth]{build/output/double_slit_norm_widest_mag.png}\n        \\caption{Double slit with wider slits, but same distance as last image.}\n    \\end{subfigure}\n    \\caption{Different images of double slits with different features. The aperture image is on the left and the diffraction image is on the right.}\n    \\label{fig:double_slit}\n\\end{figure}\n\n\\subsection{Compression}\nIn this section we will very quickly review a naive compression algorithm, based on the discrete cosine transform.\nHere the images will not be displayed in the transformed space, since they were very uninformative in my testing.\nThey appeared to look like mostly a single color with very subtle variation.\nThe idea of our naive compression is to sort the cosine-space coefficient by magnitude and just\nset the lowest of them to zero. Then we only need to save the nonzero coefficients.\nThe results of removing the lowest coefficients in this way can be seen in \\autoref{fig:compr}.\n\nIt is fairly obvious, that this compression is not looking very good, except at low compression rates.\nBut would it save space on disk? To answer this question I implemented a very simple binary format,\nsaving the cosine coefficients and their indices in a binary, compressed format. Sadly, except\nat absurdly high compressions, this did not save disk space.\nOn the contrary: The file size actually increased, since now that we are not saving every\npixel, we also have to save the indices, which takes additional space.\nThe actual \\texttt{.jpg} format is a little bit more complicated.\nIt performs the DCT on each $8\\times 8$ tile in the image and instead of\nsetting small amplitudes to 0, it tries to find a smaller, finite set of amplitudes,\nso that setting the real amplitudes to the one closest to it in the smaller set of amplitudes, does\nnot change too much.\n\\begin{figure}[htbp]\n    \\centering\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/plots/A9.png}\n        \\caption{10\\% compression}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/plots/A5.png}\n        \\caption{50\\% compression}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/plots/A2.png}\n        \\caption{80\\% compression}\n    \\end{subfigure}\n    \\begin{subfigure}[h]{.49\\linewidth}\n        \\centering\n        \\includegraphics[width=\\linewidth]{build/plots/A1.png}\n        \\caption{90\\% compression}\n    \\end{subfigure}\n    \\caption{The same image with different \"compression levels\". 10\\% compression means that the lowest 10\\% of the\n        cosine coefficients have been set to 0.}\n    \\label{fig:compr}\n\\end{figure}", "meta": {"hexsha": "56e57efeaa5888178fdba1738ebda62b2b2699d8", "size": 21423, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project08-ImageFourierTransform/report/results.tex", "max_stars_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_stars_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Project08-ImageFourierTransform/report/results.tex", "max_issues_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_issues_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Project08-ImageFourierTransform/report/results.tex", "max_forks_repo_name": "The-Ludwig/ComputationalPhysicsSU22", "max_forks_repo_head_hexsha": "67cd47b1adf42087a300bcaa97f6ea5c6df691f2", "max_forks_repo_licenses": ["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.1415730337, "max_line_length": 208, "alphanum_fraction": 0.7150259067, "num_tokens": 5865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.8740772482857833, "lm_q1q2_score": 0.7833929436898364}}
{"text": "Galois theory involves studying polynomials over a field, which are ubiquitous in algebra and number theory. So we\nstart with the basics of fields.\n\\begin{defn}\nRecall that a \\term{field} $k$ is a commutative ring with $1$ such that $1\\ne 0$ and every nonzero element is\ninvertible, and $1\\ne 0$.\n\\end{defn}\nThat is: in a field we can add, subtract, multiply, and divide, though as usual we can't divide by zero. A ``field\nhomomorphism'' (meaning a structure-preserving map) is just a ring homomorphism; we ask to preserve addition and\nmultiplication, and subtraction and division come for free.\n\\begin{comp}{exm}{enumerate}\n\t\\item The rational numbers $\\Q$, the real numbers $\\R$, and the complex numbers $\\C$ are all fields.\n\t\\item Let $p$ be prime. Then, $\\Z/p$ is a field, called the \\term{finite field of order $p$} and denoted\n\t$\\F_p$.\n\t\\begin{proof}\n\tFirst, we show $\\Z/p$ is an integral domain: if $m\\cdot n\\equiv 0\\bmod p$, then $m\\cdot n = xp$ for some $x$,\n\tso $p$ divides either $m$ or $n$. Thus, either $m$ or $n$ is $0$ in $\\Z/p$.\n\n\tNow, for any nonzero $m\\in\\Z/p$, consider the multiplication map $\\vp_m\\cdot:\\Z/p\\to\\Z/p$ sending $n\\mapsto\n\tmn$. If $a,b\\in\\Z/p$ are such that $\\vp_m(a) = \\vp_m(b)$, then $\\vp_m(a-b) = m\\cdot(a-b) = 0$. Since $m$ is\n\tnonzero and $\\Z/p$ is an integral domain, then $a = b$, and so $\\vp_m$ is injective. Since $\\Z/p$ is finite, an\n\tinjective map from $\\Z/p$ to itself is a bijection. Thus, there's a unique $n\\in\\Z/p$ such that $\\vp_m(n) = 1$,\n\tor $1 = mn$. That is, every nonzero element is invertible.\n\t\\end{proof}\n\t\\item If $k$ is any field, we can form the \\term{field of rational functions} in $k$, denoted $k(x)$, to be\n\tratios $p/q$ for polynomials $p,q\\in k[x]$ with $q\\ne 0$. We'd like them to be ``in lowest terms,'' but this is\n\ta clunky definition and it's simpler to just say that two rational functions $p/q$ and $p'/q'$ are the same if\n\twe can cross-multiply: $pq' = p'q$.\n\\end{comp}\nThere's not a whole lot we can say about a field $k$ in total generality, without knowing more about it, but we\nknow $1\\in k$, and therefore $1+1\\in k$, and $1+1+1\\in k$, and so on. These numbers might all be distinct, like for\n$\\Q$, or might not be, like for $\\F_p$.\n\\begin{defn}\nThe \\term{characteristic} $\\chr(k)$ of a field $k$ is the smallest multiple of $1$ that is equal to $0$ in $k$, or\nis $0$ if no such multiple exists.\n\\end{defn}\nFor example, $\\chr(\\F_p) = p$, and $\\chr(\\Q) = \\chr(\\R) = 0$.\n\\begin{ex}\nShow that for any field $k$, $\\chr(k)$ is either $0$ or a prime number.\n\\end{ex}\nThe characteristic is an important property of a field: many important things in Galois theory are different in the\ncharacteristic $0$ case and the characteristic $p$ case.\n\nOne of the consistent lessons of algebra is to study objects by looking at their homomorphisms. In the case of\nfields, morphisms are the setting of Galois theory.\n\\begin{lem}\nLet $\\vp:k\\to K$ be a homomorphism of fields. Then, $\\vp$ is injective.\n\\end{lem}\n\\begin{proof}\nThe kernel $\\ker(\\vp)\\subset k$ is an ideal of $k$. Since $k$ is a field, its only ideals are $0$ and $k$ itself.\nIf $\\ker(\\vp) = 0$, then $\\vp$ is injective, as desired; if $\\ker(\\vp) = k$, then $\\vp(1) = 0$, which is\nimpossible, because ring morphisms must send $1$ to $1$.\n\\end{proof}\nThis is very different than for other kinds of algebraic objects: no interesting kernels and no interesting\nquotients.\n\\begin{defn}\nIf $k$ is a field, a \\term{field extension} of $k$ is a homomorphism $i:k\\inj L$, often written\n$L/k$.\\footnote{This notation looks like a quotient, but since we will never take the quotient by a field\nextension, this is not ambiguous. We will take quotients of rings, however.}\n\\end{defn}\nGalois theory is the study of field extensions and relations between them.\n\\begin{defn}\nLet $k$ be a field and $i_K:k\\inj K$ and $i_L:k\\inj L$ be field extensions. An \\term{embedding}\n(sometimes said to be an \\term{embedding over $k$}) is a field homomorphism $j:K\\inj L$ such that the following\ndiagram commutes:\n\\[\\xymatrix{\n\tK\\ar[rr]^j && L\\\\\n\t& k.\\ar[ul]_{i_K}\\ar[ur]^{i_L}\n}\\]\nThat is, $i_L = j\\circ i_K$.\n\\end{defn}\nEmbeddings keep track of how one field lies as a subfield of another.\n\\begin{defn}\nIf $k$ is a field, its \\term{prime subfield} is the subfield of $k$ generated by $1$.\n\\end{defn}\nThat is, the prime subfield is the smallest field containing $1$ inside $k$, meaning it must contain $1+1$,\n$1+1+1$, and so forth. If $\\chr(k) = 0$, this generates a copy of $\\Z$ inside $k$, and therefore $\\Q$ also, since\nwe can invert all nonzero elements of $\\Z$. That is, if $\\chr(k) = 0$, then the prime subfield of $k$ is $\\Q$.\nIn the same way, if $\\chr(k) = p$, then its prime subfield is $\\F_p$.\n\\begin{cor}\nIf $K/k$ is a field extension, then $\\chr(k) = \\chr(K)$.\n\\end{cor}\nThis is because the prime subfield of $K$ contains the prime subfield of $k$.\n\\begin{comp}{exm}{enumerate}\n\\label{fieldextexm}\n\t\\item Since $\\Q$ is a subfield of $\\R$, the inclusion $\\Q\\inj\\R$ is a field extension. In the same way,\n\t$\\R\\inj\\C$ is a field extension; this fixes $\\Q$, so it's an embedding over $\\Q$.\n\t\\item\\label{Gaussrat} The \\term{field of Gaussian rationals} is $\\Q(i) = \\set{a+bi\\mid a,b\\in\\Q}$.\n\t\\begin{ex}\n\tShow that $\\Q(i)$ is a field.\n\t\\end{ex}\n\tIf $a\\in\\Q$, $a = a+0i\\in\\Q(i)$, so $\\Q\\inj\\Q(i)$ is another example of a field extension. One can form a\n\tsimilar definition for, e.g.\\ $\\Q(\\sqrt 3)$ or $\\Q(\\sqrt{-2})$, but we'll soon define something much more\n\tgeneral.\n\\end{comp}\n\\begin{aside}[Categorical language in field theory]\nThe modern formulation of abstract algebra tends to use categorical language, defining categories of algebraic\nobjects such that useful constructions satisfy universal properties. However, this is uncommon for field\ntheory, as the category of fields is poorly behaved: few products exist (e.g.\\ the ring $\\Q\\times\\Q$ is not a\nfield), there are no initial or final objects, and the category is disconnected, since a map of fields must\npreserve the characteristic. Specializing to the category of fields of a given characteristic fixes some, but not\nall, of these problems.\n\nNonetheless, there are a few places where words from category theory will simplify things, and I'll try to mention\nthem as they happen. Since they may require knowledge beyond what I assume for these notes, they will also be\nmarked as asides.\n\nFixing a base field $k$, we can define the \\term{category of field extensions} $\\FExt_k$ to be the category whose\nobjects are field extensions $K/k$ and whose morphisms are embeddings $K\\inj L$ over $k$.\n\n{\\color{red}TODO}: talk about the poset? Eventually will be a lattice.\n\\end{aside}\n\\begin{lem}\nIf $i:k\\inj K$ is a field extension, then $K$ is a $k$-vector space.\n\\end{lem}\n\\begin{proof}\nWe need to define an action of $k$ on $K$, which will just be multiplication: if $\\lambda\\in k$ and $x\\in K$, let\n$\\lambda\\cdot x = i(\\lambda)x$. The field axioms of $K$ imply (since $k$ is realized as a subfield of $K$) that\nmultiplication satiafies the axioms for a vector space.\n\\end{proof}\n\\begin{defn}\n\\label{finite_ext}\nIf $K/k$ is a field extension, its \\term{degree}, written $[K:k]$, is the dimension of $K$ as a $k$-vector space.\nIf this is a finite number, $K/k$ is said to be a \\term{finite extension}; otherwise, it's an \\term{infinite\nextension}.\n\\end{defn}\nThis is analogous to the index of a subgroup $[G:H]$. For example, $[\\C:\\R] = 2$, so $\\C/\\R$ is a finite extension,\nbut $\\R/\\Q$ is an infinite extension.\n\n%The first important reason we care about field extensions is to discuss roots of polynomials. For example, $x^2-2$\n%doesn't have a root in $\\Q$, but it has $2$ roots in $\\Q(\\sqrt 2)$. This enables questions about polynomials to be\n%turned into questions about field extensions, which can be solved with algebraic methods.\n% \\begin{thm}\n% \\label{rootinext}\n% Let $f\\in k[x]$ be a nonconstant polynomial. Then, there's an extension $K/k$ such that $f$ has a root in $K$.\n% \\end{thm}\n% Algebraically, what does it actually mean that $f$ has a root in $K$, given that $f$ is only defined over $K$? The\n% extension $i:k\\inj K$ induces a map $i_*:k[x]\\inj K[x]$ by applying $i$ to each coefficient of a polynomial.\n% Technically, one says that $i_*f$ has a root in $K$, but there's rarely if ever a need to keep the two separate, so\n% we identify a polynomial with its image over an extension field.\n% \n% Another way of thinking of this is that a polynomial defines a function: $x^2+1$, for example, is a function\n% $\\Q\\to\\Q$ that doesn't vanish. However, we can define the same function with the same coefficients on $\\Q(i)$, and\n% there it vanishes for $x = \\pm i$.\n% \\begin{proof}\n% Without loss of generality, assume $f$ is irreducible: if not, replace $f$ with one of its irreducible factors. A\n% field containing a root of a factor of $f$ must then contain a root of $f$.\n% \n% Since $f$ is nonconstant and irreducible, the ideal $(f)\\subset k[x]$ is maximal, and therefore $K = k[x]/(f)$ is a\n% field. Let $j:k\\inj k[x]$ send $a\\in k$ to the constant polynomial $a$, and $\\pi:k[x]\\surj K$ be the canonical\n% projection, taking everything mod $(f)$. Then, $\\pi\\circ j: k\\to K$ is a field homomorphism, so it's an extension.\n% \n% Finally, we need to produce a root. Consider $\\alpha = \\pi(x)\\in K$. Since $\\pi$ is a ring homomorphism, it\n% commutes with polynomials, and therefore $p(\\alpha) = \\pi(p(x))$, and this is $p(x)\\bmod p(x) = 0$. Hence, $\\alpha$\n% is a root of $f$.\n% \\end{proof}\n% This is a very useful way of producing field extensions, as we'll see later. In particular, it generalizes\n% Example~\\ref{fieldextexm}\\eqref{Gaussrat}: $\\Q(i)$ is isomorphic to $\\Q[x]/(x^2+1)$, and similarly $\\Q(\\sqrt 3)\n% \\cong \\Q[x]/(x^2-3)$. Similarly, $\\C \\cong \\R[x]/(x^2+1)$ under the isomorphism $a+bi\\mapsto a+bx$. We could use\n% this to \\emph{define} the complex numbers concretely: rather than supposing that we had a square root of $-1$,\n% we've constructed the field $\\R[x]/(x^2+1)$, where $x^2 = -1$. In the same way, any polynomial in $\\Q[x]$ has a\n% root in an extension of $\\Q$, which motivates the existence of algebraic numbers.\n\n{\\color{red}TODO}: treat this in a unified way with adjoining an element; explain what it means to ``adjoin a\nsquare root of $2$,'' and that this is algebraically indistinguishable (maybe this should be another section, and\nthen irreducibility criteria is a third section).\n\n\\subsection*{Irreducibility criteria}\nThe key of Theorem~\\ref{rootinext} is that $f$ is irreducible; if we take $k[x]/(f)$ for a reducible $f$,\n$(f)$ isn't even prime, so the resulting quotient isn't a field, or even an integral domain! So in practice, we\nneed to know when a polynomial is irreducible. Here are a few criteria.\n\\begin{lem}\n\\label{cubirred}\nIf $f\\in k[x]$ has degree $2$ or $3$, then $f$ is irreducible iff it has no roots.\n\\end{lem}\nOf course, the hypothesis is necessary: $(x+2)^2\\in\\Q[x]$ is reducible, but has no roots.\n\\begin{thm}[Rational root theorem]\n{\\color{red}TODO}\n\\end{thm}\n\\begin{lem}[Gauss' lemma]\n\\label{gausslem}\nLet $R$ be a UFD and $k$ be its field of fractions. If $f\\in R[x]$, then if $f$ is reducible in $k[x]$, then it's\nreducible in $R[x]$.\n\\end{lem}\nThis is most often used when $R = \\Z$, so $k = \\Q$: then, it says that \\emph{an $f\\in\\Z[x]$ is irreducible iff it's\nirreducible in $\\Q[x]$}.\n\\begin{prop}\nLet $R$ be an integral domain and $I\\subset R$ be a proper ideal. If $f\\in R[x]$ and $f\\bmod I$ is irreducible in\n$(R/I)[x]$, then $f$ is irreducible over $R$.\\footnote{The converse is untrue: $x^4+1$ is irreducible over $\\Z$,\nbut reducible modulo every prime.}\n\\end{prop}\nThis is most often used when $R = \\Z$ and $I = (p)$ for some prime $p$.\n\\begin{prop}[Eisenstein's criterion]\nLet $R$ be an integral domain and $\\p\\subset R$ be a prime ideal. If $f(x) = x^n + a_{n-1}x^{n-1} + \\dotsb + a_1x +\na_0$ is such that $a_{n-1},\\dotsc,a_0\\in\\p$ and $a_0\\not\\in\\p^2$, then $f$ is irreducible in $R[x]$.\n\\end{prop}\nThis is generally used for $R = \\Z$ and $\\p = (p)$ for a prime number $p$. In this case, it says the following.\n\\begin{cor}\nLet $f\\in\\Z[x]$ be given by $f(x) = x^2 + a_{n-1}x^{n-1} + \\dotsc + a_1x + a_0$, and suppose there's a prime number\n$p\\in\\Z$ such that $p\\mid a_i$ for $i = 0,\\dotsc,n-1$, and $p^2\\nmid a_0$. Then, $f$ is irreducible in $\\Z[x]$.\n\\end{cor}\nBy Lemma~\\ref{gausslem}, this also implies $f$ is irreducible in $\\Q[x]$. The most common application of\nEisenstein's criterion is to show that a given polynomial in $\\Z[x]$ is irreducible over $\\Q$.\n\n{\\color{red}TODO} fill in these proofs.\n\nDoing a few exercises using these results will probably be more helpful than reading their proofs.\n\\begin{proof}[Proof of Lemma~\\ref{cubirred}]\nIf $f$ is reducible, then $f = gh$, where $g$ and $h$ are polynomials of degree at least $1$. Since $\\deg(g) +\n\\deg(h)\\le 3$, this means at least one of $g$ or $h$ has degree exactly $1$. Without loss of generality, assume\nit's $g$, so $g(x) = ax + b$ for $a,b\\in k$ and $a\\ne 0$; then, $-b/a$ is a root of $g$, and therefore of $f$.\n\nConversely, if $f$ has a root, then it's reducible.\n\\end{proof}\n\nIn the next few sections, we'll develop the theory of a few nice kinds of field extensions.\n", "meta": {"hexsha": "d6719f0773c96ab5e222cb95d0ccd3836edc0221", "size": 13181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture_notes/examples/notes_d_examples/basic_field_theory.tex", "max_stars_repo_name": "adebray/pset_d", "max_stars_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lecture_notes/examples/notes_d_examples/basic_field_theory.tex", "max_issues_repo_name": "adebray/pset_d", "max_issues_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture_notes/examples/notes_d_examples/basic_field_theory.tex", "max_forks_repo_name": "adebray/pset_d", "max_forks_repo_head_hexsha": "1d39e36341aab9778bd3e106f2e93c20c177932c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.0231481481, "max_line_length": 117, "alphanum_fraction": 0.6960776876, "num_tokens": 4237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7832964380823418}}
{"text": "\\subsection{Normal form}\n\nThis is where a formula is shown using only:\t\n\n\\begin{itemize}\n\\item And / Conjunction- \\(\\land \\)\n\\item Or / Disjunction   - \\(\\lor \\)\n\\item Negation - \\(\\neg \\)\n\\end{itemize}\n\nThe conjunctive normal form (CNF) is where a formula is converted to a normal form with the following layout:\n\n$a \\land b \\land c \\land d$\n\nThese letters can represent complex sub-formulae, in normal form.\n\nStatements in this form are easier to evaluate, as each subformula can be evaluated separately. The statement is true only if all formulaes within are also true.\n\nThe disjunctive normal form (DNF) is similar for \\(\\lor \\).\n\n$a \\lor b \\lor c \\lor d$\n\n\\subsection{Properties of the normal form}\n\nThe normal binary operators are commutitive - \\(A\\land B\\Leftrightarrow B\\land A\\) and \\(A\\lor B\\Leftrightarrow B\\lor A\\)\n\nBoth binary operators are associative - \\((A\\land B)\\land C\\Leftrightarrow A\\land (B\\land C)\\) and \\((A\\lor B)\\lor C\\Leftrightarrow A\\lor (B\\lor C)\\)\n\nNegation is complementary.\n\n\\(A\\land \\neg A\\Leftrightarrow F \\)\n\n\\(A\\lor \\neg A\\Leftrightarrow T\\)\n\nNormal binary operators are absorbative.\n\n\\(A\\land (A\\lor B)\\Leftrightarrow A\\)\n\\(A\\lor (A\\land B)\\Leftrightarrow A\\)\n\nIdentity.\n\n\\(A\\land T\\Leftrightarrow A\\)\n\n\\(A\\lor F \\Leftrightarrow A\\)\n\nDistributivity.\n\n\\(A\\land (B\\lor C)\\Leftrightarrow (A\\land B)\\lor (A\\land C)\\)\n\n\\(A\\lor (B\\land C)\\Leftrightarrow (A\\lor B)\\land(A\\lor C)\\)\t\t\n\n\n", "meta": {"hexsha": "254a1a3c8c80f000eef3c11f1e22e5529c07cb7c", "size": 1415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/04-04-normal.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogic/04-04-normal.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogic/04-04-normal.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.6981132075, "max_line_length": 161, "alphanum_fraction": 0.709540636, "num_tokens": 440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7832836301110355}}
{"text": "\n\\subsection{Likelihood function}\n\nWe want to estimate parameters. One way of looking into this is to look at the likelihood function:\n\n\\(L(\\theta ; X)=P(X|\\theta )\\)\n\nThe likelihood function shows the chance of the observed data being generated, given specific parameters.\n\nIf this has high peaks then it provides information that \\(\\theta \\) is located in this region.\n\n\\subsection{IID}\n\nFor multiple events, the likelihood function is:\n\n\\(L(\\theta ; X)=P(X|\\theta )\\)\n\n\\(L(\\theta ; X)=P(A_1 \\land B_2 \\land C_3 \\land D_4…|\\theta )\\)\n\nIf the events are independent, that is the chance of a flip doesn’t depend on any other outcomes, then:\n\n\\(L(\\theta ; X)=P(A_1|\\theta ).P(B_2|\\theta ).P(C_3|\\theta ).P(D_4|\\theta )...\\)\n\nIf the events are identically distributed, the chance of flipping a head doesn’t change across flips (for example the heads side doesn’t get heavier over time) then:\n\n\\(L(\\theta ; X)=P(A|\\theta ).P(B|\\theta ).P(C|\\theta ).P(D|\\theta )...\\)\n\n\\(L(\\theta ; X)=\\prod_{i=1}^n P(X_i|\\theta )\\)\n\n", "meta": {"hexsha": "49564c846e458f586d1a01c9c9143be07836bc02", "size": 1013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/likelihood/01-01-likelihood.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/likelihood/01-01-likelihood.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/likelihood/01-01-likelihood.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.7666666667, "max_line_length": 165, "alphanum_fraction": 0.6949654492, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7832836176333912}}
{"text": "\\section{Methods}\n\\subsection{Using Conditional Mutual Information}\n\\begin{itemize}\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": "b5816836f1e3273a3a63c3b7d766f899637aea77", "size": 610, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Treballs_nostres/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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/2019-07-UseR-A Shiny_App_for_SGRM/2019-07-UseR-Poster/sectionsUseR/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": 61.0, "max_line_length": 228, "alphanum_fraction": 0.7442622951, "num_tokens": 177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9693241947446617, "lm_q2_score": 0.8080672204860316, "lm_q1q2_score": 0.7832791077971796}}
{"text": "\n\\subsection{Normal matrices}\n\n\\(M^*M=MM^*\\)\n\nAll symmetrix matrices are normal\n\nAll hermetitian matrices (inc subset symmetric) are normal\n\nNormal matrix never defective\n\n", "meta": {"hexsha": "83d9c8c06a98c43951bbcb1549245cd5918f4756", "size": 172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/06-01-normal.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/06-01-normal.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/06-01-normal.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 14.3333333333, "max_line_length": 58, "alphanum_fraction": 0.7674418605, "num_tokens": 43, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9473810436809827, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7832110742004357}}
{"text": "\\lab{Algorithm}{Pseudorandom Number Generators}{Pseudorandom Number Generators}\n\\label{Ch:PRNG}\n\n\\objective{This section teaches about how to build pseudorandom number generators and the differences between the different kinds of PRNGs}\n\n\\section*{Linear congruential genterators}\n\n%Lab \\ref{PRNG}\n\nLotteries, most board games, and statistics need random numbers. In real life, we roll dice, take balls out of a bag, or spin a wheel. in order to rpresent random number on computer we use  psuedorandom number generators (PRNGs). The numbers are not truly random, but they are based on a complex formula that makes them look ``random.\" Another thing is that these generators have to be fast for their aplication. So you have to have something that is fast and looks random.\n\nOne of the oldest of theses is the Linear Congruiental Generator (LCG). The 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, and\n\\item[] $m$, $0<m$ is the modulus\n\\item[] $a$, $0<a<m$ is the multiplier\n\\item[] $c$, $0\\leq c<m$ is the increment\n\\item[] $X_0$, $0\\leq X_0 <m$ is the seed\n\\end{itemize}\n\n\neach of these are interger constansts.\n\n\n\n\\begin{problem}\nWrite a LCG that produces a number an array of psuedorandom numbers between $0.0$ and $1.0$. Let the arguments be size of array and let a,c,mod,and seed be optional arguments. I recommend $a=1103515245$, $c=12345$, $m=2^{31}-1$, and $seed=4329$ as the defualt values.\n\\end{problem}\n\n\\begin{problem}\nWrite a LCG that produces a number an array of psuedorandom numbers of integers between two input arguments. Do it by calling your agorithm from problem one and mutiplying it by the values and casting the array as as int using the .astype() function. Let the arguments be size of array and the two intergers. Let a,c,mod,and seed continue to be optional arguments.\n\\end{problem}\n\nOne easy way to ``see\" if your generator is random is to look at a bitmap of the output. In python, use the plt.imshow() function to see a bitmap of the array produced by your LCG. Resize your output to be $512 \\times 512$. \n\n\\begin{problem}\nFor what values of $a$, $c$, and $m$ does your LCG have a definite pattern.\n\\end{problem}\n\nThis method is not rigorist. There are several ways to test the randomness of your output. \n\nThe length over with your random number generator repeats is called the period. The period is at most m, but it may be shorter based on the values of a and c.\n \nAccording to the Hull-Dobell Theorem (find a source, used wikipedia), The LCG will only 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\nThis algorithm is used to generate random numbers in Java, C++ and other places.\n\n\\section*{Mersenne Twister and Bitwise operations}\n\n\nAll numbers can be represented in bits as a base two number. Computers are optimized to work with numbers in that manner. There are operations that work on the the bit representation of the two number. These are XOR, OR, and AND. \n\nAND - if both numbers have a 1 in the ith place then the ith place is 1. Otherwise 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. Otherwise 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. If 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 anumber of values. For example, shifting 10100 to the right by one yields 1010 and shifting it to the left by one yields 101000. This can be done by $\\ll$ and $\\gg$ in python. \n\n\nThe mersenne twister PRNG does a series of these operations to generate random numbers. the Random class in python uses the mersenne twister algorithm. \n\n\\begin{problem}\nLook at the bitmap of output of sp.rand(512,512). Can you see any patterns?\n\\end{problem}\n\n\\begin{problem}\nAnalyse the first of 10,000 outputs of the random class. Can you see a period?\n\\end{problem}\n", "meta": {"hexsha": "46e932ea5ebb5123ef134c123600d6dcb9be9eba", "size": 4211, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/PRNG/PRNG.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/PRNG/PRNG.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/PRNG/PRNG.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.6375, "max_line_length": 473, "alphanum_fraction": 0.751840418, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.9032942099580604, "lm_q1q2_score": 0.7831883909663764}}
{"text": "\\subsection{Multiplying a matrix and a vector}\n\nOne of the most important uses of a matrix is to multiply a matrix by\na vector. In fact, this is one of the reasons matrices were invented.\nLet us start by considering an alternative way of writing a system of\nlinear equations.\n\n\\begin{definition}{The vector form of a system of linear equations}{vector-form}\n  Suppose we have a system of equations given by\n  \\begin{equation*}\n    \\begin{array}{ccc}\n      a_{11}x_1 + \\ldots + a_{1n}x_n &=& b_1, \\\\\n      a_{21}x_1 + \\ldots + a_{2n}x_n &=& b_2, \\\\\n      \\vdots \\\\\n      a_{m1}x_1 + \\ldots + a_{mn}x_n &=& b_m.\n    \\end{array}\n  \\end{equation*}\n  We can express this system in \\textbf{vector form}%\n  \\index{system of linear equations!vector form}%\n  \\index{vector form!of a system of equations}, which is as follows:\n  \\begin{equation*}\n    x_1 \\begin{mymatrix}{c} a_{11} \\\\ a_{21} \\\\ \\vdots \\\\ a_{m1} \\end{mymatrix}\n    + x_2 \\begin{mymatrix}{c} a_{12} \\\\ a_{22} \\\\ \\vdots \\\\ a_{m2} \\end{mymatrix}\n    + \\ldots\n    + x_n \\begin{mymatrix}{c} a_{1n} \\\\ a_{2n} \\\\ \\vdots \\\\ a_{mn} \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c} b_1 \\\\ b_2 \\\\ \\vdots \\\\ b_m \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nNotice that each vector used here is one column from the corresponding\naugmented matrix. There is one vector for each variable in the system,\nalong with the constant vector. The left-hand side is a linear\ncombination of column vectors. Linear combinations of column vectors\nare so important that we introduce a special notation for them.\n\n\\begin{definition}{The product of a matrix and a vector, by columns}{matrix-times-vector-columns}\n  \\index{multiplication!matrix times vector}%\n  \\index{matrix!multiplication!matrix times vector}%\n  The product of an $m\\times n$-matrix $A$ and an $n$-dimensional\n  column vector $\\vect{x}$ is an $m$-dimensional column vector,\n  defined as a linear combination of the columns of $A$ as follows:\n  \\begin{equation*}\n    A\\vect{x} \\,~=~\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c}\n      x_1 \\\\\n      x_2 \\\\\n      \\vdots \\\\\n      x_n\n    \\end{mymatrix}\n    ~=~\n    x_1 \\begin{mymatrix}{c} a_{11} \\\\ a_{21} \\\\ \\vdots \\\\ a_{m1} \\end{mymatrix}\n    + x_2 \\begin{mymatrix}{c} a_{12} \\\\ a_{22} \\\\ \\vdots \\\\ a_{m2} \\end{mymatrix}\n    + \\ldots\n    + x_n \\begin{mymatrix}{c} a_{1n} \\\\ a_{2n} \\\\ \\vdots \\\\ a_{mn} \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nIn other words, we can think of the vector $\\vect{x}$ as encoding\ninstructions for how to take a linear combination of the columns of\n$A$. The product $A\\vect{x}$ is computed by taking $x_1$ times the\nfirst column of $A$, plus $x_2$ times the second column of $A$, and so\non. For this to work, $A$ must have the same number of columns as\n$\\vect{x}$ has components.\n\n\\begin{example}{Multiplying a matrix and a vector, by columns}{matrix-times-vector-columns}\n  Compute the product\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      7 \\\\\n      8 \\\\\n      9\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      7 \\\\\n      8 \\\\\n      9\n    \\end{mymatrix}\n    ~=~\n  7\\begin{mymatrix}{c}\n    1 \\\\\n    4\n  \\end{mymatrix}\n  + 8 \\begin{mymatrix}{c}\n    2 \\\\\n    5\n  \\end{mymatrix}\n  + 9 \\begin{mymatrix}{c}\n    3 \\\\\n    6\n  \\end{mymatrix}\n  = \\begin{mymatrix}{c}\n    50 \\\\\n    122\n  \\end{mymatrix}.\n\\end{equation*}\n\\end{solution}\n\nThere is another way of looking at the product of a matrix and a\nvector. Instead of looking at the columns of $A$, we can look at the\nrows.\n\n\\begin{proposition}{The product of a matrix and a vector, by rows}{matrix-times-vector-rows}\n  Let $A$ be an $m\\times n$-matrix and let $\\vect{x}$ be an $n$-dimensional\n  column vector. The product $A\\vect{x}$ can also be written like this:\n  \\begin{equation*}\n    A\\vect{x} \\,~=~\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c}\n      x_1 \\\\\n      x_2 \\\\\n      \\vdots \\\\\n      x_n\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c}\n      a_{11}x_1+a_{12}x_2+\\ldots+a_{1n}x_n \\\\\n      a_{21}x_1+a_{22}x_2+\\ldots+a_{2n}x_n \\\\\n      \\vdots \\\\\n      a_{m1}x_1+a_{m2}x_2+\\ldots+a_{mn}x_n \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{example}{Multiplying a matrix and a vector, by rows}{matrix-times-vector-rows}\n  Compute the product\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      7 \\\\\n      8 \\\\\n      9\n    \\end{mymatrix}\n  \\end{equation*}\n  by rows.\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6\n    \\end{mymatrix} \\begin{mymatrix}{r}\n      7 \\\\\n      8 \\\\\n      9\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c}\n      1\\cdot 7 + 2\\cdot 8 + 3\\cdot 9 \\\\\n      4\\cdot 7 + 5\\cdot 8 + 6\\cdot 9\n    \\end{mymatrix}\n    ~=~\n    \\begin{mymatrix}{c}\n      50 \\\\\n      122\n    \\end{mymatrix}.\n  \\end{equation*}\n  Note that the is exactly the same answer as before.\n\\end{solution}\n\nWhen we use Definition~\\ref{def:matrix-times-vector-columns}, we\ncalculate the product by looking at one column of $A$ at a time. When\nwe use Proposition~\\ref{prop:matrix-times-vector-rows}, we calculate the\nproduct by looking at one row of $A$ at a time.  As the above examples\nshow, both methods give exactly the same answer. Please convince\nyourself that this is true in general. This ability to switch back and\nforth between a column-based viewpoint and a row-based viewpoint is\none of the central tools of linear algebra.\n\nUsing the above operation, we can also write a system of linear\nequations in \\textbf{matrix form}. In this form, we express the system\nas a matrix multiplied by a vector.\n\n\\begin{definition}{The matrix form of a system of linear equations}{matrix-form}\n  Suppose we have a system of equations given by\n  \\begin{equation*}\n    \\begin{array}{c}\n      a_{11}x_1 + \\ldots + a_{1n}x_n = b_1, \\\\\n      a_{21}x_1 + \\ldots + a_{2n}x_n = b_2, \\\\\n      \\vdots \\\\\n      a_{m1}x_1 + \\ldots + a_{mn}x_n = b_m.\n    \\end{array}\n  \\end{equation*}\n  Then we can express this system in \\textbf{matrix form}%\n  \\index{system of linear equations!matrix form}%\n  \\index{matrix form!of a system of equations}, which is as follows:\n  \\begin{equation*}\n    \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & a_{m2} & \\cdots & a_{mn}\n    \\end{mymatrix}\n    \\begin{mymatrix}{c}\n      x_1 \\\\\n      x_2 \\\\\n      \\vdots \\\\\n      x_n\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{c}\n      b_1 \\\\\n      b_2 \\\\\n      \\vdots \\\\\n      b_m\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nThe matrix form of a system of equations is therefore written as\n$A\\vect{x}=\\vect{b}$, where $A$ is the coefficient matrix%\n\\index{coefficient matrix}%\n\\index{matrix!coefficient matrix} of the system, $\\vect{x}$ is an\n$n$-dimensional column vector constructed from the variables of the\nsystem, and $\\vect{b}$ is an $m$-dimensional column vector constructed\nfrom the constant terms of the system. Any system of linear equations\ncan be written in this form.\n", "meta": {"hexsha": "9ecf9a951eb602d28ded42088370e8183433712e", "size": 7691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Multiplication-MatrixTimesVector.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-Multiplication-MatrixTimesVector.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-Multiplication-MatrixTimesVector.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.3918367347, "max_line_length": 97, "alphanum_fraction": 0.6263164738, "num_tokens": 2696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005327, "lm_q2_score": 0.867035763237924, "lm_q1q2_score": 0.7831883796806984}}
{"text": "\n\\subsection{Span}\n\n\\subsubsection{Span function}\n\nWe can take a subset \\(S\\) of \\(V\\). We can then make linear combinations of these elements.\n\nThis is called the linear span - \\(span (S)\\).\n\n", "meta": {"hexsha": "135fa69720f2fd5f370ec253c24ed08360c2cf50", "size": 193, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/linearAlgebra/01-02-span.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/linearAlgebra/01-02-span.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/linearAlgebra/01-02-span.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.3, "max_line_length": 92, "alphanum_fraction": 0.6994818653, "num_tokens": 49, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693659780479, "lm_q2_score": 0.8244619306896956, "lm_q1q2_score": 0.7829662389911205}}
{"text": "%!TEX program = xelatex\n\n\\documentclass[a4paper,12pt]{article}\n\\usepackage{fontspec}\n\\usepackage{polyglossia}\n\\usepackage{csquotes}\n\\setdefaultlanguage{english}\n\\usepackage[titletoc,toc,title]{appendix}\n\\usepackage{mathpazo}\n\\setmainfont\n     [ BoldFont       = texgyrepagella-bold.otf ,\n       ItalicFont     = texgyrepagella-italic.otf ,\n       BoldItalicFont = texgyrepagella-bolditalic.otf ]\n     {texgyrepagella-regular.otf}\n\\usepackage{setspace}\n\n\\setstretch{1.10}\n\\usepackage{amsmath, amsfonts, amssymb, amsthm, dsfont,cancel}\n\\usepackage{graphicx, float}\n\\usepackage{tikz, color, xcolor} % For artists\n\\usepackage[hmargin=3.5cm,vmargin=3cm]{geometry}\n\\usepackage{setspace}\n\\usepackage{enumerate} % For (i) (ii) items in enumerate\n\n\\newcommand\\bhat[1]{\\hat{b}_#1}\n\\newcommand\\sumin{\\sum_{i=1}^N}\n\n\\title{Quick proof on univariate OLS estimator}\n\\author{Antoine Mayerowitz}\n\n\\begin{document}\n\n\\maketitle\n\nWe suppose that the data consist of $N$ observations $\\{y_i, x_i\\}_{i=1}^N$ where each observation $i$ consist of a dependent variable $y_i$ and an explanatory variable $x_i$. We suppose a linear relationship in our variables such that\n\\begin{equation}\n\ty_i = b_0 + b_1 x_i + \\varepsilon_i\n\\end{equation}\nWhere $b_0$ and $b_1$ are scalars, shared by all observations and $\\varepsilon_i$ is the error term.\n\nOur goal is to find $b_0$ and $b_1$ such that the \\emph{sum of squared of residuals}(SSR) is minimized. Where the SSR is defined by\n\\begin{align*}\n\tSRR &= \\sumin e^2 \\\\\n\t\t\t&= \\sumin (y_i-\\bhat{0}-\\bhat{1}x_i)^2\n\\end{align*}\n\nMathematicaly we seek\n\n\\begin{equation}\n\t\\min_{\\bhat{0},\\bhat{1}} \\sumin (y_i-\\bhat{0}-\\bhat{1}x_i)^2\n\\end{equation}\n\nAs we need to minimize a quadratic function, we take the derivative with respect to both argument and equalize to 0.\n\n\\[\n\\begin{cases}\n\t\\dfrac{\\partial \\; SSR}{\\partial \\bhat{0}} = -2 \\sumin (y_i-\\bhat{0}-\\bhat{1}x_i) \\\\\n\t~\\\\\n\t\\dfrac{\\partial \\; SSR}{\\partial \\bhat{1}} = -2 \\sumin x_i (y_i-\\bhat{0}-\\bhat{1}x_i) \\\\\n\\end{cases}\n\\]\n\nThen we equalize both equations to 0\n\\[\n\\begin{cases}\n\t-2 \\sumin (y_i-\\bhat{0}-\\bhat{1}x_i) &= 0 \\\\\n\t-2 \\sumin x_i (y_i-\\bhat{0}-\\bhat{1}x_i) &= 0 \\\\\n\\end{cases}\n\\]\n\nWe now have our system of 2 equations with 2 unknowns that we need to solve for $\\bhat{0}$ and $\\bhat{1}$\n\nWe simplify\n\\[\n\\begin{cases}\n\t\\cancel{-2} \\sumin (y_i-\\bhat{0}-\\bhat{1}x_i) &= 0 \\\\\n\t\\cancel{-2} \\sumin x_i (y_i-\\bhat{0}-\\bhat{1}x_i) &= 0 \\\\\n\\end{cases}\n\\]\n\nRewriting\n\n\\[\n\\begin{cases}\n\t\\sumin y_i &= \\sumin \\bhat{0} + \\bhat{1} \\sumin x_i\\\\\n\t\\sumin x_i y_i &= \\bhat{0} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nUsing the fact that $\\sum_{k=1}^K a = K\\times a$ and that $\\bhat{0}$ do not depends on $i$ we get\n\n\\[\n\\begin{cases}\n\t\\sumin y_i &= N \\bhat{0} + \\bhat{1} \\sumin x_i\\\\\n\t\\sumin x_i y_i &= \\bhat{0} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nWe multiply the first equation by $\\frac{1}{N}$\n\n\\[\n\\begin{cases}\n\t\\frac{1}{N}\\sumin y_i &= \\frac{1}{N} N \\bhat{0} + \\bhat{1} \\frac{1}{N} \\sumin x_i\\\\\n\t\\sumin x_i y_i &= \\bhat{0} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nWe define the average $z$ by $\\bar{z} := \\frac{1}{N}\\sumin z_i$.\n\n\\[\n\\begin{cases}\n\t\\bar{y} &= \\bhat{0} + \\bhat{1} \\bar{x}\\\\\n\t\\sumin x_i y_i &= \\bhat{0} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nWe rewrite to get an expression of $\\bhat{0}$\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t\\sumin x_i y_i &= \\bhat{0} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nWe substitute the first equation in the second\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t\\sumin x_i y_i &= (\\bar{y} - \\bhat{1} \\bar{x}) \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nDeveloping\n\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t\\sumin x_i y_i &= \\bar{y} \\sumin x_i - \\bhat{1} \\bar{x} \\sumin x_i  + \\bhat{1} \\sumin x_i^2 \\\\\n\\end{cases}\n\\]\n\nWe factor by $\\bhat{1}$\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t\\sumin x_i y_i &= \\bar{y} \\sumin x_i + \\bhat{1} \\left(\\sumin x_i^2 - \\bar{x} \\sumin x_i \\right)\\\n\\end{cases}\n\\]\n\nIsolating $\\bhat{1}$\n\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t~ \\\\\n\t\\bhat{1} &= \\dfrac{\\sumin x_i y_i - \\bar{y} \\sumin x_i}{\\sumin x_i^2 - \\bar{x} \\sumin x_i} \n\\end{cases}\n\\]\n\nAfter a bit of algebra (see appendix), one can simplify to\n\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t~ \\\\\n\t\\bhat{1} &= \\dfrac{\\sumin (y_i - \\bar{y}) (x_i - \\bar{x})}{\\sumin (x_i - \\bar{x})^2}\n\\end{cases}\n\\]\n\nWhich is strictly equivalent to \n\n\\[\n\\begin{cases}\n\t\\bhat{0} &= \\bar{y} - \\bhat{1} \\bar{x}\\\\\n\t~ \\\\\n\t\\bhat{1} &= \\dfrac{Cov(x,y)}{Var(x)}\n\\end{cases}\n\\]\n\n\n\\clearpage\n\\begin{appendices}\n\\section{Simplifying $\\bhat{1}$}\n\\subsection{Finding the covariance}\n\\[\n\\sumin x_i y_i - \\bar{y} \\sumin x_i =  N \\times Cov(x,y)\n\\]\nThis proof need some tricks and heavily play with the fact that $\\sumin x_i = \\bar{x}$ and that $\\sumin \\bar{y} = N \\bar{y}$. For example, one could write\n\\[\n\t\\bar{y} \\sumin x_i = N\\bar{y}\\bar{x} = \\sumin \\bar{x}\\bar{y} =\\sumin y_i \\bar{x}\n\\]\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t\\sumin x_i y_i - \\bar{y} \\sumin x_i &= \\sumin x_i y_i - N\\bar{y}\\bar{x}\\\\\n\t\t&= \\sumin x_i y_i - N\\bar{y}\\bar{x} - N\\bar{y}\\bar{x} +  N\\bar{y}\\bar{x}\\\\\n\t\t&= \\sumin x_i y_i - \\sumin x_i \\bar{y} - \\sumin \\bar{x} y_i +  \\sumin \\bar{y}\\bar{x} \\\\\n\t\t& = \\sumin (x_i y_i -  x_i \\bar{y} - \\bar{x} y_i + \\bar{y}\\bar{x}) \\\\\n\t\t&= \\sumin (y_i - \\bar{y}) (x_i - \\bar{x}) \\\\ \n\t\t&= N \\times Cov(x,y)\n\t\\end{align*}\n\\end{proof}\n\n\\subsection{Finding the variance}\n\\[\n\\sumin x_i^2 - \\bar{x} \\sumin x_i = N \\times Var(x)\n\\]\nThis proof is very similar to the one for covariance.\n\n\\begin{proof}\n\t\\begin{align*}\n\t\t\\sumin x_i^2 - \\bar{x} \\sumin x_i &= \\sumin x_i^2 - N\\bar{x}\\bar{x}\\\\\n\t\t&= \\sumin x_i^2 - 2N\\bar{x}\\bar{x} + N\\bar{x}\\bar{x} \\\\\n\t\t&= \\sumin x_i^2 - 2 \\bar{x} \\sumin x_i + N\\bar{x}^2 \\\\\n\t\t&= \\sumin (x_i^2 - 2\\bar{x}x_i + \\bar{x}^2) \\\\\n\t\t&= \\sumin (x - \\bar{x})^2 \\\\\n\t\t&= N \\times Var(x)\n\t\\end{align*}\n\\end{proof}\n\n\\end{appendices}\n\n\\end{document}", "meta": {"hexsha": "95f3f837fde8b4b35b2bb6d7d19e66f1f992d854", "size": 6009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Session_4/Proof/proof.tex", "max_stars_repo_name": "SuperMayo/ScPoEconometrics_Supplement", "max_stars_repo_head_hexsha": "ec3924fe39ede36f4efd02a9c352b44e409ea621", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Session_4/Proof/proof.tex", "max_issues_repo_name": "SuperMayo/ScPoEconometrics_Supplement", "max_issues_repo_head_hexsha": "ec3924fe39ede36f4efd02a9c352b44e409ea621", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Session_4/Proof/proof.tex", "max_forks_repo_name": "SuperMayo/ScPoEconometrics_Supplement", "max_forks_repo_head_hexsha": "ec3924fe39ede36f4efd02a9c352b44e409ea621", "max_forks_repo_licenses": ["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.9461883408, "max_line_length": 235, "alphanum_fraction": 0.6189049759, "num_tokens": 2576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.8840392817460332, "lm_q1q2_score": 0.7829330173430835}}
{"text": "\\subsection{Substitution}\n\nIf we have a tautology, then we can substitute the formula of any propositional variable with any formula to arrive at any other tautology.\n\nFor example, we know that \\(\\theta \\lor \\neg \\theta \\) is a tautology. This means that an arbitrary formula for \\(\\theta \\) is also a tautology.\n\nAn example is \\((\\gamma \\land \\alpha )\\lor \\neg (\\gamma \\land \\alpha )\\), which we know is a tautology, without having to examine each variable.\n\n\\subsection{Syntactic consequence}\n\nLet us call the first formula \\(A\\) and the second \\(B\\). We can then say:\n\n\\(A\\vdash B\\)\n\nThis says that: if \\(A\\) is true, then we can deduce that \\(B\\) is true using steps such as substitution.\n\n\\subsection{Modus Ponens}\n\nModus Ponens is a deduction rule. This allows us to use stpes other than substitution to derive new tautologies.\n\nIf \\(A\\) implies \\(B\\), and \\(A\\) is true, then \\(B\\) is also true.\n\n\\((\\theta \\rightarrow \\gamma )\\land \\theta \\Rightarrow \\gamma \\)\n\nThat is, if we can show that the following are true:\n\n\\(\\theta \\rightarrow \\gamma \\)\n\n\\(\\theta \\)\n\nWe can infer that the following is also true:\n\n\\(\\gamma \\)\n\n\\subsection{Theory}\n\nResults derived from substitution or induction are called theorems. Theorems often divided into:\n\n\\begin{itemize}\n\\item Theorems - important results\n\\item Lemmas - results used for later theorems\n\\item Corollaries - readily deduced from a theorem\n\\end{itemize}\n\nWe take a set of axioms, as true, and a deduction rule which enables us to derive additional formulae, or theorems. The collection of axioms and theorems is known as the theory.\n", "meta": {"hexsha": "69b003720d0a45d2024070bda94794e567587292", "size": 1590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-01-syntactic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-01-syntactic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-01-syntactic.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.5652173913, "max_line_length": 177, "alphanum_fraction": 0.7352201258, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623016, "lm_q2_score": 0.8840392725805823, "lm_q1q2_score": 0.7829329958829407}}
{"text": "\\lab{QR Decomposition}{QR decomposition}\n\\label{lab:QRdecomp}\n\\objective{Use the Gram-Schmidt algorithm and orthonormal transformations to perform the QR decomposition.}\n\nThe QR decomposition of a matrix $A$ is a factorization $A=QR$, where $Q$ has orthonormal columns and $R$ is upper triangular.\nThis decomposition is useful for computing least squares and finding eigenvalues.\nAs stated in the following theorem, the QR decomposition of $A$ always exists when the rank of $A$ equals the number of columns of $A$.\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\nIn this lab we will only discuss real matrices. \nAll of these results can be extended to the complex numbers by replacing ``orthogonal matrix'' with ``unitary matrix,'' ``transpose'' with ``hermitian conjugate,'' and ``symmetric matrix'' with ``hermitian matrix.''\n\n\\section*{Modified Gram-Schmidt}\nLet $A$ be an $m \\times n$ matrix of rank $n$.\nThere are many methods for computing the QR decomposition.\nFirst we will discuss the algorithm that computes $Q$ by applying Gram-Schmidt to the columns of $A$.\n\nLet $\\{\\x_i\\}_{i=1}^n$ be the columns of $A$ (the rank hypothesis implies that these are linearly independent vectors).\nThen the Gram-Schmidt algorithm computes an orthonormal basis $\\{\\q_i\\}_{i=1}^n$ for the span of the $\\x_i$. \nThe Gram-Schmidt algorithm defines  \\[ \\q_1 = \\frac{\\x_1}{\\norm{\\x_1}}.\\]\nIt recursively defines $\\q_k$ for $k>1$ 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, \\,\\,\\,\\, k=2, \\ldots, n\n\\]\nand $\\p_0 = 0$. \n\nIn the QR factorization of $A$, the matrix $Q$ has columns $\\{\\q_i\\}_{i=1}^n$. \nThe matrix $R$ is then the upper triangular matrix with entries $r_{jk}$ where $r_{kk} = \\|\\x_k-\\p_{k-1}\\|$ and $r_{j k} = \\langle \\q_j, \\x_k\\rangle$ when $j < k$. \nSee [TODO: ref textbook] for a proof that $QR=A$ and $R$ is nonsingular.\n\n\nWhen implemented with a computer, the Gram-Schmidt algorithm may produce a matrix $Q$ with columns that are not even close to orthonormal due to rounding errors. \nWe now introduce the modified Gram-Schmidt algorithm, which consistently produces matrices $Q$ whose columns are ``very close'' to orthonormal.\n\nIn the modified Gram-Schmidt algorithm, $\\q_1$ is the normalization of $\\x_1$ as before. \nWe then make each of the vectors $\\x_2, \\ldots, \\x_n$ orthogonal to $\\q_1$ by defining\n\\[\n\\x_k := \\x_k - \\langle \\q_1,\\x_{k} \\rangle \\q_1,\\quad k=2,\\ldots,n.\n\\]\n(Compare this to the usual Gram-Schmidt algorithm, where we only made $\\x_2$ orthogonal to $\\q_1$.) \nNext we define $\\q_2 = \\frac{\\x_2}{\\|\\x_2\\|}.$ Once again we make $\\x_3, \\ldots, \\x_n$ orthogonal to $\\q_2$ by defining\n\\[\n\\x_k := \\x_k - \\langle \\q_2,\\x_{k} \\rangle \\q_2,\\quad k=3,\\ldots,n.\n\\]\n(Each of these new vectors is a linear combination of vectors orthogonal to $\\q_1$, and hence is orthogonal to $\\q_1$ as well.) \nWe continue this process until we have an orthonormal set $q_1, \\ldots, q_k$. \nThe entire modified Gram-Schmidt algorithm is described in Algorithm \\ref{Alg:gram_schmidt}.\n\n%TODO: proofread this, explain notation, and make the LU decomposition alg. like this\n\\begin{algorithm}\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 $R \\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}^\\mathsf{T}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\\caption{The modified Gram-Schmidt. This algorithm returns orthogonal $Q$ and upper triangular $R$ such that $A = QR$.}\n\\label{Alg:gram_schmidt}\n\\end{algorithm}\n\n\n%TODO: put this section after the next? What algorithm does SciPy use?\n\\section*{QR decomposition in SciPy}\nThe linear algebra library in SciPy calculates the QR decomposition using a software package called LAPACK (Linear Algebra PACKage), which is incredibly efficient.\nHere is an example of using SciPy to compute the QR decomposition of a matrix.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n>>> A = np.random.rand(4,3)\n>>> Q, R = la.qr(A)\n>>> Q.dot(R) == A                      \narray([[ True, False, False],\n       [ True, False, False],\n       [ True,  True, False],\n       [ True,  True, False]], dtype=bool)\n\\end{lstlisting}\n Note that \\li{Q.dot(R)} does not equal \\li{A} exactly because of rounding errors. \n However, we can check that the entries of \\li{Q.dot(R)} are ``close'' to the entries of \\li{A} with the NumPy method \\li{np.allclose()}. \n This method checks that the elements of two arrays differ by less than a given tolerance, a tolerance specified by two keyword arguments \\li{rtol} and \\li{atol} that default to $10^{-5}$ and $10^{-8}$ respectively. \n You can read the documentation to learn how the tolerance is computed from these numbers.\n\\begin{lstlisting}\n>>> np.allclose(Q.dot(R), A) \nTrue\n\\end{lstlisting}\nWe can use the same method to check that \\li{Q} is ``very close'' to an orthogonal matrix.\n\\begin{lstlisting}\n>>> np.allclose(Q.T.dot(Q), np.eye(4)) \nTrue\n\\end{lstlisting}\n\n\n\\begin{problem}\n\\label{prob:QR}\nWrite a function that accepts as input a $m \\times n$ matrix of rank $n$ and computes its QR decomposition, returning the matrices $Q$ and $R$. \nYour function should use Algorithm \\ref{Alg:gram_schmidt}. \nHint: Read about the function \\li{np.inner()}.\nAnother hint: Check that your function works by using \\li{np.allclose()}.\n\\end{problem}\n\n\\begin{problem}\nWrite a function that accepts a square matrix $A$ of full rank and returns $\\abs{\\det(A)}$. \nUse the QR decomposition of $A$ to perform this calculation.\nHint: What is the determinant of an orthonormal matrix?\n\\end{problem}\n\n\\section*{Householder triangularization}\nAnother way to compute the QR decomposition of a matrix is with a series of orthonormal transformations. \nLike the Modified Gram-Schmidt algorithm, orthonormal transformations are numerically stable, meaning that they are less susceptible to rounding errors.\n\n\\subsection*{Householder transformations}\nThe \\emph{hyperplane} in $\\mathbb{R}^n$ with normal vector $\\mathbf{v}$ is the set $\\{ \\x \\in \\mathbb{R}^n \\mid \\langle \\x, \\mathbf{v} \\rangle = 0 \\}$. \nEquivalently, the hyperplane defined by $\\mathbf{v}$ is just the orthogonal complement $\\mathbf{v}^{\\perp}$. \nSee Figure \\ref{fig:Householder_reflector}.\n\nA \\emph{Householder transformation} of $\\mathbb{R}^n$ is a linear transformation that reflects about a hyperplane. \nIf a hyperplane $H$ has normal vector $\\mathbf{v}$, let $\\mathbf{u} = \\mathbf{v}/\\|\\mathbf{v}\\|$. \nThen the Householder transformation that reflects about $H$ corresponds to the matrix $H_{\\mathbf{u}} = I - 2 \\mathbf{u}\\mathbf{u}^T$. \nYou can check that $(I - 2 \\mathbf{u}\\mathbf{u}^T)^T(I - 2 \\mathbf{u}\\mathbf{u}^T)=I$, so Householder transformations are orthogonal.\n\n%\\newcommand{\\ipt}[2]{\\ensuremath{\\left\\langle #1,#2 \\right\\rangle}}\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}\n%\\draw[-, thick](0,-1.5)--(0,3); %x-axis\n%\\draw[-,thick](-1,0)--(4,0); %y-axis\n%\\node[draw, thick, minimum height=4.5cm, minimum width=5cm]()at(1.5,.75){};\n\\draw[-,dashed, gray](-2,-1.333)--(3, 2); % hyperplane\n\\draw[->, gray, >=stealth,ultra thick](0,0)--(.8,-1.2); % v\n\\draw[->, >=stealth, thick](0,0)--(2.815, .777); % H x\n\\draw[->, >=stealth, thick](0,0)--(1.8,2.3); % x\n\\node[draw=none](v)at(.65,-.6){$\\v$};\n\\node[draw=none](x)at(.75,1.5){$\\x$};\n\\node[draw=none](Hx)at(3, .5){$H_{\\v}\\x$};\n\\node[draw=none](H)at(-1.5,-.6){$H$};\n%\\node[draw=none](bullet)at(2.31, 1.53){\\textbullet};\n%\\node[draw=none](vandx)at(4.0,1.5){$\\x -\n%\\left \\langle \\dfrac{\\v}{\\|\\v\\|}, \\x \\right \\rangle \\dfrac{\\v}{\\|\\v\\|}$};\n\\end{tikzpicture}\n\\end{center}\n\\caption{This is a picture of a Householder transformation. \nThe normal vector $\\mathbf{v}$ defines the hyperplane $H$. \nThe Householder transformation $H_{\\mathbf{v}}$ of $\\mathbf{x}$ is just the reflection of $\\mathbf{x}$ across $H$.}\n\\label{fig:Householder_reflector}\n\\end{figure}\n\n\\subsection*{Householder triangularization}\nThe QR decomposition of an $m \\times n$ matrix $A$ can also be computed with Householder transformations via the Householder triangularization.\nWhereas Gram-Schmidt makes $A$ \\emph{orthonormal} using a series of transformations stored in an \\emph{upper triangular} matrix, Householder triangularization makes $A$ \\emph{triangular} by a series of \\emph{orthonormal} transformations.\nMore precisely, the Householder triangularization finds an $m \\times m$ orthogonal matrix $Q$ and and $m \\times n$ upper triangular matrix $R$ such that $QA = R$. \nSince $Q$ is orthogonal, $Q^{-1}=Q^T$ so $A = QR$.\n(Contrast this with the QR decomposition where $A = QR$, the matrix $Q$ is $m \\times n$, and $R$ is $n \\times n$). \nIf $A$ is square, then $A = Q^TR$ is the QR decomposition. \n\nLet's demonstrate the idea behind Householder triangularization on a $4 \\times 3$ matrix $A$.\nLet $e_1, \\ldots, e_4$ be the standard basis of $\\mathbb{R}^4$.\nFirst we find an orthonormal transformation $Q_1$ that maps the first column of A into the span of $e_1$. \nThis is diagrammed below, where $*$ represents an arbitrary entry.\n\n\\def\\mc#1{\\multicolumn{1}{c|}{#1}}\n\\def\\lc#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 = Q_1A$ be the matrix on the right above.\nNow find an orthonormal transformation $Q_2$ that fixes $e_1$ and maps the second column of $A_2$ into the span of $e_1$ and $e_2$. \nNotice that since $Q_2$ fixes $e_1$, the top row of $A_2$ will be fixed by $Q_2$, and only entries in the boxed submatrix will change.\n\n%\\def\\mc#1{\\multicolumn{1}{c|}{#1}}\n%\\begin{equation*}\n%\\begin{pmatrix}\n%* & * & * & \\\\ \\cline{2-3}\n%\\mc{0} & * & \\mc{*}& \\\\\n%\\mc{0} & * & \\mc{*} & \\\\\n%\\mc{0}& * & \\mc{*} & \\\\ \\cline{2-3}\n%\\end{pmatrix}\n%\n%\\underrightarrow{Q_1}\n%\n%\\begin{pmatrix}\n%* & * & * & \\\\ \\cline{2-3}\n%\\mc{0} & 0 & \\mc{*}& \\\\\n%\\mc{0} & 0 & \\mc{*} & \\\\\n%\\mc{0}& 0 & \\mc{*} & \\\\ \\cline{2-3}\n%\\end{pmatrix}\n%\\end{equation*}\n\nLet $A_3 = Q_2Q_1A$ be the matrix on the right above. \nFinally, find an orthonormal transformation $Q_3$ that fixes $e_1$ and $e_2$ and maps the third column of $A_3$ into the span of $e_1$, $e_2$, and $e_3$. \nThe diagram below summarizes this process, where boxed entries indicate those affected by the operation just performed.\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}  \\cline{2-4}\n&\\lc{*} & * & \\mc{*} & \\\\\n&\\lc{0} & * & \\mc{*}& \\\\\n&\\lc{0} & * & \\mc{*} & \\\\\n&\\lc{0}& * & \\mc{*} & \\\\ \\cline{2-4}\n\\end{pmatrix}\n= Q_3\n\\begin{pmatrix}\n* & * & * \\\\ \\cline{2-3}\n\\mc{0} & * & \\mc{*} \\\\\n\\mc{0} & 0 & \\mc{*} \\\\\n\\mc{0} & 0 & \\mc{*} & \\\\ \\cline{2-3}\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n* & * & * \\\\\n0 & * & * \\\\ \\cline{3-3}\n0 & \\mc{0} & \\mc{*} \\\\\n0 & \\mc{0} & \\mc{0} & \\\\ \\cline{3-3}\n\\end{pmatrix}.\n\\end{equation*}\n\nWe've accomplished our goal, which was to triangularize $A$ using orthonormal transformations.\nBut how do we construct the matrices $Q_k$?\n\nIt turns out that we can choose each $Q_k$ to be a Householder transformation. \nSuppose we have found Householder transformations $Q_1, \\ldots, Q_{k-1}$ such that $Q_{k-1}\\ldots Q_2Q_1 = A_k$ where \n\\[\nA_k = \\begin{pmatrix}\nT & X' \\\\\n0 & X''\n\\end{pmatrix}.\n\\]\nHere, $T$ is a $(k-1) \\times (k-1)$ upper triangular matrix. \nLet $\\x$ be the $k^{th}$ column of $A_k$. \nWrite $\\x = \\x' + \\x''$ where $\\x'$ is in the span of $e_1, \\ldots, e_{k-1}$. \nSo $\\x''$ looks like $k-1$ zeros followed by the first column of $X''$. \nThe idea is to reflect $\\x''$ about a hyperplane into the span of $e_k$. \nIt turns out that there are two choices that will work (see Figure \\ref{fig:two reflectors}). \nThese hyperplanes have normal vectors $\\x'' + \\| \\x'' \\|e_k$ and $\\x'' - \\| \\x'' \\|e_k$.\nIn fact, the more numerically stable transformation is to reflect about the hyperplane with normal vector $\\mathbf{v}_k = \\x'' +\\sign(x_k) \\| \\x'' \\|e_k$, where $x_k$ is the $k^{th}$ entry of $\\x''$ (or the top left entry of $X''$). \n(You can check that $\\mathbf{v}_k$ is orthonormal to $e_1, \\ldots, e_{k-1}$, so the plane orthonormal to $\\mathbf{v}_k$ contains $e_1, \\ldots, e_{k-1}$, and reflecting about it fixes $e_1, \\ldots, e_{k-1}$.)\nThus, $Q_k$ is the Householder transformation $H_{\\mathbf{v}_k}$.\n\nThe final question is to find an efficient algorithm for computing $Q = Q_nQ_{n-1} \\ldots Q_1$ and $R = Q_nQ_{n-1} \\ldots Q_1A$. \nThe idea is to start with $R=A$ and $Q = I$. Then we compute $Q_1$ and modify $R$ to be $Q_1A$ and $Q$ to be $Q_1$. \nNext we compute $Q_2$ and modify $R$ to be $Q_2Q_1A$ and $Q$ to be $Q_2Q_1$, and so forth. \nAs we have already discussed, $Q_k$ fixes the first $k-1$ rows and columns of any matrix it acts on. \nIn fact, if $\\x'' = (0, \\ldots, 0, x_k, x_{k+1}, \\ldots, x_n)$ as above, then $\\mathbf{v}_k = (0, \\ldots, 0, v_{k_0}, x_{k+1}, \\ldots, x_n)$ where $v_{k_0} = x_k + \\sign(x_k) \\| \\x'' \\|$. \nIf $\\mathbf{u}_k$ is the normalization of $(v_{k_0}, x_{k+1}, \\ldots, x_n) \\in \\mathbb{R}^{n-(k-1)}$, then\n\\[\nQ_k = I-\\frac{2\\x''(\\x'')^T}{\\|\\x''\\|^2} =  \\begin{pmatrix}\nI & 0 \\\\\n0 & I-2\\mathbf{u}_k\\mathbf{u}_k^T\n\\end{pmatrix}.\n\\]\nThis means that, using block multiplication,\n\\[\nQ_kA_k =  \\begin{pmatrix}\nI & 0 \\\\\n0 & I-2\\mathbf{u}_k\\mathbf{u}_k^T\n\\end{pmatrix}\\begin{pmatrix}\nT & X' \\\\\n0 & X''\n\\end{pmatrix} = \\begin{pmatrix}\nT & X' \\\\\n0 & ( I-2\\mathbf{u}_k\\mathbf{u}_k^T)X''\n\\end{pmatrix}.\n\\]\nSo at each stage of the algorithm, we only need to update the entries in the bottom right submatrix of $A_k$, and these change via matrix multiplication by $ I-2\\mathbf{u}_k\\mathbf{u}_k^T$. Similarly,\n\\[\nQ_kQ_{k-1}\\ldots Q_1 = Q_k \\begin{pmatrix}\nA\\\\\nB\n\\end{pmatrix} = \\begin{pmatrix}\nI & 0 \\\\\n0 & I-2\\mathbf{u}_k\\mathbf{u}_k^T\n\\end{pmatrix}\\begin{pmatrix}\nA\\\\\nB\n\\end{pmatrix} = \\begin{pmatrix}\nA\\\\\n(I-2\\mathbf{u}_k\\mathbf{u}_k^T)B\n\\end{pmatrix},\n\\]\nso to update $\\prod Q_i$, we need only modify the bottom rows. \nThese also change via matrix multiplication by $I-2\\mathbf{u}_k\\mathbf{u}_k^T$.\n\nThese arguments produce Algorithm \\ref{Alg:Householder}.\n\n%To find $Q_1$, we first identify an appropriate hyperplane to reflect $x$ into the span of $e_1$.\n%It 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.)\n%Between the two, the one that reflects $x$ further will be more numerically stable.\n%This is the hyperplane perpendicular to $v = sign(x_1)\\norm{x}_2 e_1 + x$.\n%\n%To see how this works, let $x$ be the first column of the submatrix that we want to project onto the span of $e_1$.\n%In order for this to be a unitary operation, this will need to preserve the norm of $x$.\n%This 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}\n%x_1 \\pm \\norm{x} \\\\\n%x_2 \\\\\n%x_3 \\\\\n%\\vdots \\\\\n%x_n\n%\\end{pmatrix}\\]\n%\n%Let $u$ be the vector on the right hand side of this expression.\n%It 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\n\\begin{figure}\n\\begin{tikzpicture}\n\n\\draw[-, dashed, gray](-3,-1)--(3,1);\n\\draw[-, dashed, gray](-.8,2.4)--(.6,-1.8);\n\\draw[-, gray, thick](-4,0)--(4,0);\n\\draw[->, thick, >=stealth'](0,0)--(2,1.6);\n\\draw[<->, thick, >=stealth'](-2.6,0)--(2.6,0);\n\\draw[->, gray,  ultra thick, >=stealth](0,0)--(1.5,.5);\n\\draw[->, gray, ultra thick, >=stealth](0,0)--(-.5,1.5);\n\n\\node[draw=none, node distance=3.5cm]\n\t(dummy)at(2.5,.2){};\n\\node[draw=none, node distance=.5cm](Hvx)\n\t[below of=dummy]{$H_{\\v_1}\\x$};\n\\node[draw=none, node distance=2cm](x)\n\t[above left of=Hvx]{$\\x$};\n\\node[draw=none](v1)[left of=x]{$\\v_1$};\n\\node[draw=none, node distance=.55cm](v2)[below of=x]{$\\v_2$};\n\\node[draw=none, node distance=4cm](hvx2)[left of=dummy]{$H_{\\v_2}\\x$};\n\n\\end{tikzpicture}\n\\caption{If we want to reflect $\\x$ about a hyperplane into the span of $e_1$, there are two hyperplanes that will work. \nThe two choices are defined by the normal vectors $\\v_1$ and $\\v_2$. \nReflecting about the hyperplane defined by $\\v_i$ produces  $H_{\\v_i}\\x$.}\n\\label{fig:two reflectors}\n\\end{figure}\n\n%TODO: explain notation, fix algorithm\n\\begin{algorithm}\n\\caption{Householder triangularization. \nThis algorithm returns orthonormal $Q$ and upper triangular $R$ satisfying $A = QR$.}\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 $u_k \\gets \\text{copy} \\left( R_{k:,k} \\right)$\n    \\State $u_{k_0} \\gets u_{k_0} + \\text{sign} \\left( u_{k_0} \\right) \\norm{u_k}$\n    \\State $u_k \\gets u_k / \\norm{u_k}$\n    \\State $R_{k:,k:} \\gets R_{k:,k:} - 2 u_k \\left( u_k^\\mathsf{T} R_{k:,k:} \\right)$\n    \\State $Q_{k:} \\gets Q_{k:} - 2 u_k \\left( u_k^\\mathsf{T} Q_{k:} \\right)$\n\\EndFor\n\\State \\pseudoli{return} $Q^\\mathsf{H}, R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\\begin{problem}\n\\label{prob:HouseholderQR}\nWrite a function that accepts as input a $m \\times n$ matrix of rank $n$ and computes its QR decomposition, returning the matrices $Q$ and $R$. \nYour function should use Algorithm \\ref{Alg:Householder}. \nHint: Read about the function \\li{np.outer()}.\n\\end{problem}\n\n\\begin{comment}\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\\end{comment}\n\n\\section*{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\nA fast algorithm for computing the QR decomposition of a Hessenberg matrix will be taught in Lab \\ref{lab:givens}. This algorithm in turn leads to a fast algorithm for finding eigenvalues of a matrix, which will be discussed in Lab \\ref{lab:EigSolve}.\n\nFor now, we will outline an algorithm for computing the upper Hessenberg form of any matrix. \nLike Householder triangularization, this algorithm uses Householder transformations.\nTo find orthogonal $Q$ and upper Hessenberg $H$ such that $A = Q^THQ$, it suffices to find such matrices that satisfy $Q^TAQ=H$. \nThus, 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.\n\nInstead, let's try choosing a $Q_1$ that fixes $e_1$ and reflects the first column of $A$ into the span of $e_1$ and $e_2$. \nBecause $Q_1$ fixes $e_1$, the product $Q_1A$ leaves the first row of $A$ alone, and $(Q_1A)Q_1^T$ leaves the first column of $(Q_1A)$ alone.\nIf $A$ is a $5 \\times 5$ matrix, this looks like\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\nThe pseudocode for computing the Hessenberg form of a matrix with Householder transformations is shown in Algorithm \\ref{Alg:Hessenberg}.\nAlthough the Hessenberg form exists for any square matrix, this algorithm only works for full-rank square matrices.\nNotice that this algorithm is very similar to Algorithm \\ref{Alg:Householder}.\n\n\n\\begin{algorithm}\n\\caption{Reduction to Hessenberg form for a nonsingular matrix. \nThis algorithm returns orthogonal $Q$ and upper Hessenberg $H$ such that $A = Q^THQ$.}\n\\label{Alg:Hessenberg}\n\\begin{algorithmic}[1]\n\\Procedure{Hessenberg}{$A$}\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 $u_k \\gets \\text{copy}\\left(H_{k+1:, k}\\right)$\n    \\State $u_{k_0} \\gets u_{k_0} + \\text{sign}(u_{k_0}) \\norm{u_k}$\n    \\State $u_k \\gets u_k/\\norm{u_k}$\n    \\State $H_{k+1:,k:} \\gets H_{k+1:,k:} - 2u_k(u_k^\\mathsf{T} H_{k+1:,k:})$\n    \\State $H_{:,k+1:} \\gets H_{:,k+1:} - 2(H_{:,k+1:} u_k) u_k^\\mathsf{T}$\n    \\State $Q_{k+1:} \\gets Q_{k+1:} - 2u_k(u_k^\\mathsf{T} Q_{k+1:})$\n\\EndFor\n\\State \\pseudoli{return} $Q, H$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nWhen $A$ is symmetric, its upper Hessenberg form is a tridiagonal matrix. \nThis is because the $Q_i$'s zero out everything below the first subdiagonal of $A$ and the $Q_i^T$'s zero out everything above the first superdiagonal.\nThus, the Hessenberg form of a symmetric matrix is especially useful, since as we saw in Lab \\ref{lab:complexity}, tridiagonal matrices make computations fast.\n\n\n\n\n%TODO: This doesn't work if $A$ is singular\n\\begin{problem}\n\\label{prob:hessenberg}\nWrite a function that accepts as input a nonsingular square matrix $A$ and computes its Hessenberg form, returning orthogonal $Q$ and upper Hessenberg $H$ satisfying $A = Q^THQ$. \nYour function should use Algorithm \\ref{Alg:hessenberg}. \nWhat happens when you compute the Hessenberg factorization of a symmetric 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": "2e402dc8912cd86e0552be8754302048e5aa59f4", "size": 26081, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/QR/QR.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/QR/QR.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/QR/QR.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": 43.9074074074, "max_line_length": 251, "alphanum_fraction": 0.6719834362, "num_tokens": 9025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8872046056466901, "lm_q1q2_score": 0.7828940727558072}}
{"text": "\\subsection{Definitions}\r\n\\begin{enumerate}\r\n\t\\item $f(x_0, y_0)$ is a local maximum of $f$ if for some $\\delta > 0$, $f(x_0, y_0) \\geq f(x, y) \\forall (x,y) \\in N((x,y),\\delta)$.\r\n\t\tThat is, you can draw a circle in the domain of $f$ centered at $(x_0, y_0)$ such that the value of $f$ at every point in the circle besides $(x_0, y_0)$ is less than $(x_0, y_0)$.\r\n\t\\item $f(x_0, y_0)$ is a local minimum of $f$ if for some $\\delta > 0$, $f(x_0, y_0) \\leq f(x,y) \\forall (x,y) \\in N((x,y),\\delta)$.\r\n\t\tThat is, you can draw a circle in the domain of $f$ centered at $(x_0, y_0)$ such that the value of $f$ at every point in the circle besides $(x_0, y_0)$ is greater than $(x_0, y_0)$.\r\n\t\\item $f(x_0, y_0)$ is a global max of $f$ if $f(x_0, y_0) \\geq f(x,y) \\forall (x,y) \\in D(f)$ where $D(f)$ is the domain of $f$.\r\n\t\\item $f(x_0, y_0)$ is a global min of $f$ if $f(x_0, y_0) \\leq f(x,y) \\forall (x,y) \\in D(f)$ where $D(f)$ is the domain of $f$.\r\n\\end{enumerate}\r\n\\begin{theorem}\r\n\tIf $(x_0, y_0)$ is in the domain of $f$ and a local extrema of $f(x,y)$, then $f_x(x_0, y_0)$ and $f_y(x_0, y_0)$ is either 0 or undefined.\r\n\\end{theorem}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\textwidth]{./Images/differentialMultivariableCalculus/optimization.png}\r\n\t\\caption{Critical points appear when the partial derivatives are 0 or undefined.}\r\n\\end{figure}", "meta": {"hexsha": "c83a70c5c63bc967cfd88cd993589c43c56ea5d1", "size": 1373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/definitions.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/definitions.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/definitions.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": 76.2777777778, "max_line_length": 186, "alphanum_fraction": 0.6482155863, "num_tokens": 534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.882427872638409, "lm_q1q2_score": 0.782894067492309}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rr}\n    1 & 2 \\\\\n    2 & 1\n  \\end{mymatrix}$. Find $A^{10}$ by diagonalization.\n  \\begin{sol}\n    First we write $A = PDP^{-1}$.\n    \\begin{equation*}\n      \\def\\arraystretch{1.3}\n      \\begin{mymatrix}{rr}\n        1 & 2 \\\\\n        2 & 1\n      \\end{mymatrix}\n      =\n      \\begin{mymatrix}{rr}\n        -1 & 1 \\\\\n        1 & 1\n      \\end{mymatrix}\n      \\begin{mymatrix}{rr}\n        -1 & 0 \\\\\n        0 & 3\n      \\end{mymatrix}\n      \\begin{mymatrix}{rr}\n        -\\frac{1}{2} & \\frac{1}{2} \\\\\n        \\frac{1}{2} & \\frac{1}{2}\n      \\end{mymatrix}\n    \\end{equation*}\n    Therefore $A^{10} = PD^{10}P^{-1}$.\n    \\begin{equation*}\n      \\def\\arraystretch{1.3}\n      \\begin{mymatrix}{rr}\n        1 & 2 \\\\\n        2 & 1\n      \\end{mymatrix}^{10}\n      ~=~\n      \\begin{mymatrix}{rr}\n        -1 & 1 \\\\\n        1 & 1\n      \\end{mymatrix}\n      \\begin{mymatrix}{rr}\n        (-1)^{10} & 0 \\\\\n        0 & 3^{10}\n      \\end{mymatrix}\n      \\begin{mymatrix}{rr}\n        -\\frac{1}{2} & \\frac{1}{2} \\\\\n        \\frac{1}{2} & \\frac{1}{2}\n      \\end{mymatrix} \\\\\n      ~=~\n      \\frac{1}{2}\\begin{mymatrix}{cc}\n        3^{10}+1 & 3^{10}-1 \\\\\n        3^{10}-1 & 3^{10}+1\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrr}\n    1 & 4 & 1 \\\\\n    0 & 2 & 5 \\\\\n    0 & 0 & 5\n  \\end{mymatrix}$. Find $A^{50}$ by diagonalization.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrr}\n    1 & -2 & -1 \\\\\n    2 & -1 & 1 \\\\\n    -2 & 3 & 1\n  \\end{mymatrix}$. Find $A^{100}$ by diagonalization.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rr}\n    -5 & -6 \\\\\n    9 & 10 \\\\\n  \\end{mymatrix}$. Find a square root of $A$, i.e., find a matrix $B$\n  such that $B^2=A$.\n  \\begin{sol}\n    $B=\\begin{mymatrix}{rr}\n      -1 & -2 \\\\\n      3  & 4 \\\\\n  \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A = \\begin{mymatrix}{rrr}\n    -2 & 0 & 6 \\\\\n    -3 & 1 & 6 \\\\\n    -3 & 0 & 7 \\\\\n  \\end{mymatrix}$. Find a square root of $A$.\n  \\begin{sol}\n    $A = \\begin{mymatrix}{rrr}\n      0  &  0 & 2 \\\\\n      -1 &  1 & 2 \\\\\n      -1 &  0 & 3 \\\\\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "2e68fdbf8b01a382ae7d7dc6a0201597b4dbb192", "size": 2228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Application-Power.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Application-Power.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Application-Power.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 20.6296296296, "max_line_length": 69, "alphanum_fraction": 0.4434470377, "num_tokens": 970, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8872046041554923, "lm_q1q2_score": 0.7828940604671318}}
{"text": "\\section{Scalar multiplication}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Multiply a scalar by a vector algebraically and geometrically.\n  \\item Use the laws of scalar multiplication to prove equalities\n    between vector expressions.\n  \\end{enumerate}\n\\end{outcome}\n\nScalar multiplication of vectors in $\\R^n$ is defined as\nfollows.\n\n\\begin{definition}{Scalar multiplication of vectors in $\\R^n$}{vector-scalar-multiplication}\n  If $k\\in\\R$ is a scalar and $\\vect{u}\\in \\R^n$ is a vector, then\n  their \\textbf{scalar multiplication}%\n  \\index{vector!scalar multiplication}%\n  \\index{scalar multiplication!of a vector} $k\\vect{u}\\in \\R^n$ is\n  defined by\n  \\begin{equation*}\n    k\\vect{u}=k\\begin{mymatrix}{c}\n      u_1 \\\\\n      \\vdots \\\\\n      u_n\n    \\end{mymatrix} = \\begin{mymatrix}{c}\n      ku_1 \\\\\n      \\vdots \\\\\n      ku_n\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nFor example $3 \\mat{1, 2, 3}^T = \\mat{3, 6, 9}^T$ and\n$-2\\mat{1, 2, 3}^T = \\mat{-2, -4, -6}^T$.\n\n\\begin{example}{Geometric meaning of scalar multiplication}{geometric-scalar-multiplication}\n  Let $\\vect{u}=\\mat{2,1}^T$, and draw the following vectors to scale:\n  $2\\vect{u}$, $\\vect{u}$, $\\frac{1}{2}\\vect{u}$, $0\\vect{u}$,\n  $-\\frac{1}{2}\\vect{u}$, $-\\vect{u}$, and $-2\\vect{u}$.  What is the\n  geometric meaning of scalar multiplication?\n\\end{example}\n\n\\begin{solution}\n  Here is a picture of the seven vectors. We draw their tails in\n  different places to make their relationship easier to see.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.7]\n      \\draw[->, thick, blue] (-10.5,-1)    -- node[above]{$2\\vect{u}$} +(4,2);\n      \\draw[->, thick, blue] (-6,-0.5)  -- node[above]{$\\vect{u}$} +(2,1);\n      \\draw[->, thick, blue] (-3,-0.25) -- node[above]{$\\frac{1}{2}\\vect{u}$} +(1,0.5);\n      \\draw[fill, blue](0,0) circle [radius=3pt] node[above]{$0\\vect{u}$};\n      \\draw[->, thick, blue] (3,0.25)   -- node[above]{$-\\frac{1}{2}\\vect{u}$} +(-1,-0.5);\n      \\draw[->, thick, blue] (6,0.5)    -- node[above]{$-\\vect{u}$} +(-2,-1);\n      \\draw[->, thick, blue] (10.5,1)      -- node[above]{$-2\\vect{u}$} +(-4,-2);\n    \\end{tikzpicture}\n  \\end{center}\n  We see that the vector $k\\vect{u}$ has the same direction as\n  $\\vect{u}$ when $k$ is positive, and the opposite direction when $k$\n  is negative. Further, the length of the vector is scaled by a factor\n  of $\\abs{k}$. It increases if $\\abs{k}>1$ and decreases if\n  $\\abs{k}<1$. For example, the vector $2\\vect{u}$ is exactly twice as\n  long as $\\vect{u}$.  (It is because of this scaling property that\n  scalars are called scalars%\n  \\index{scalar!for scaling}).\n\\end{solution}\n\nJust as with addition, scalar multiplication of vectors satisfies\nseveral important properties. These are outlined in the following\nproposition.\n\n\\begin{proposition}{Properties of scalar multiplication}{vector-scalar-multiplication}\n  The following properties hold for vectors\n  $\\vect{u},\\vect{v}\\in\\R^n$ and $k,\\ell$ scalars.%\n  \\index{vector!properties of scalar multiplication}%\n  \\index{vector!scalar multiplication!properties}%\n  \\index{properties of scalar multiplication!vector}%\n  \\begin{itemize}\n  \\item The distributive law over vector addition\n    \\index{distributive law!over vector addition}%\n    \\index{vector!distributive law}%\n    \\begin{equation*}\n      k(\\vect{u} + \\vect{v}) = k\\vect{u} + k\\vect{v}.\n    \\end{equation*}\n  \\item The distributive law over scalar addition\n    \\index{distributive law!over scalar addition}%\n    \\begin{equation*}\n      (k + \\ell) \\vect{u} = k\\vect{u} + \\ell\\vect{u}.\n    \\end{equation*}\n  \\item The associative law for scalar multiplication\n    \\index{associative law!of scalar multiplication}%\n    \\index{vector!associative law of scalar multiplication}%\n    \\begin{equation*}\n      k(\\ell\\vect{u}) = (k\\ell)\\vect{u}.\n    \\end{equation*}\n  \\item The rule for multiplication by $1$\n    \\index{rule for multiplication by 1}%\n    \\index{vector!rule for multiplication by 1}%\n    \\begin{equation*}\n      1\\vect{u}=\\vect{u}.\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  We will show the proof of:\n  \\begin{equation*}\n    k(\\vect{u} + \\vect{v}) = k\\vect{u} + k\\vect{v}.\n  \\end{equation*}\n  Assume $\\vect{u}=\\mat{u_1,\\ldots,u_n}^T$ and\n  $\\vect{v}=\\mat{v_1,\\ldots,v_n}^T$. We have:\n  \\begin{equation*}\n    \\begin{array}{ll}\n      k(\\vect{u} + \\vect{v}) & = k\\mat{u_1 + v_1,\\ldots,u_n + v_n}^T \\\\\n                             & = \\mat{k(u_1 + v_1), \\ldots, k(u_n + v_n)}^T \\\\\n                             & = \\mat{ku_1 + k v_1, \\ldots, ku_n + kv_n}^T \\\\\n                             & = \\mat{ku_1, \\ldots, ku_n}^T + \\mat{kv_1, \\ldots, kv_n}^T \\\\\n                             & = k\\vect{u} + k\\vect{v}.\n    \\end{array}\n  \\end{equation*}\n\\end{proof}\n\n", "meta": {"hexsha": "2d73e7d9a549007e45f687c31a0d90da07c2c918", "size": 4745, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-ScalarMultiplication.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-ScalarMultiplication.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-ScalarMultiplication.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 38.893442623, "max_line_length": 92, "alphanum_fraction": 0.6238145416, "num_tokens": 1642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.9086178870347122, "lm_q1q2_score": 0.7828090242226489}}
{"text": "%\n% Chapter 3.8\n%\n\n\\section*{3.8 Newton's Method}\n\nNewton's method (Newton-Raphson method) is a way for finding successively better approximations for roots of real-valued functions. The idea behind Newton's method is that the tangent line is close to the curve and so its \\(x\\)-intercept is close to the \\(x\\)-intercept of the curve (namely, root \\(r\\) that we are seeking).\n\n\\subsection*{Using Newton's Method}\n\nTo find the formula for \\(x_2\\), we use the fact that the slope of \\(L\\) is \\(f'(x_1)\\), so its equation is \n$$ y-f(x_1)=f'(x_1)(x-x_1) $$\nSince the \\(x\\)-intercept of \\(L\\) is \\(x_2\\), we know that the point \\((x_2, 0)\\) is on the line, and so \n$$ 0-f(x_1)=f'(x_1)(x_2-x_1) $$\nIf \\(f'(x_1) \\neq 0\\), we can solve this equation for \\(x_2\\):\nWe use \\(x_2\\) as the second approximation to \\(r\\).\nRepeat this procedure with \\(x_1\\) being replaced by the second approximation \\(x_2\\) giving \\(x_3\\) and so on.\n\\\\\\\\\\\\\nIn general if the \\(n\\)th approximation is \\(x_n\\) and \\(f'(x) \\neq 0\\), then the next approximation is given by\n$$ x_{n+1}=x_n-\\frac{f(x_n)}{f'(x_n)} $$\nIf the numbers \\(x_n\\) become closer and closer to \\(r\\) as \\(n\\) becomes large, then we say that the sequence converges to \\(r\\) and we write \n$$ \\lim_{n \\to \\infty}x_n=r $$\n", "meta": {"hexsha": "a79da2e9501280e1f78bc24a9b085a7b255fc936", "size": 1256, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/3-8.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-8.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-8.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": 54.6086956522, "max_line_length": 324, "alphanum_fraction": 0.6664012739, "num_tokens": 418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8991213664574069, "lm_q1q2_score": 0.7827726116429393}}
{"text": "\\chapter{Complex numbers}\n\\label{app:complex}\n\nThroughout history, mankind has invented more and more complicated\nnumber systems in an effort to make algebra easier.\n\\begin{itemize}\n\\item In the beginning, there were the \\textbf{natural numbers}%\n  \\index{natural number}%\n  \\index{number!natural} $\\N = \\set{1, 2, 3, \\ldots}$. However,\n  after a while, it became a problem that certain equations, such as\n  $x+5=3$, do not have a solution in the natural numbers.\n\\item To solve this problem, {\\em zero} and {\\em negative numbers}\n  were invented, resulting in the set of \\textbf{integers}%\n  \\index{integer}%\n  \\index{number!integer} $\\Z=\\set{\\ldots,-3,-2,-1,0,1,2,3,\\ldots}$. In\n  the integers, the equation $x+5=3$ has a solution, namely\n  $x=-2$. But some other equations, such as $2x=1$, still do not have\n  a solution in the integers.\n\\item To solve this problem, the \\textbf{rational numbers}%\n  \\index{rational number}%\n  \\index{number!rational} $\\Q$ were invented. In the rational\n  numbers, the equation $2x=1$ has a solution, namely\n  $x=\\frac{1}{2}$. However, some other equations, such as $x^2=2$,\n  still do not have a solution in the rational numbers.\n\\item To solve this problem, the \\textbf{real numbers}%\n  \\index{real number}%\n  \\index{number!real} $\\R$ were invented. In the real numbers,\n  the equation $x^2=2$ has a solution, namely $x=\\sqrt{2}$. However,\n  some other equations, such as $x^2=-1$, still don't have a solution\n  in the real numbers.\n\\item To solve this problem, the \\textbf{complex numbers}%\n  \\index{complex number}%\n  \\index{number!complex|see{complex number}} were invented.\n\\end{itemize}\nThe purpose of this section is to summarize the most important facts\nabout the complex numbers. We will also see that the above process\ndoes not continue. In the complex numbers, all non-trivial polynomial\nequations have a solution, and therefore, no additional numbers are\n``missing''.  This property is called the \\textbf{fundamental theorem\n  of algebra}%\n\\index{fundamental theorem of algebra}%\n\\index{algebra!fundamental theorem of}. Gauss is usually credited with\ngiving a proof of this theorem in 1797 but many others worked on it\nand the first completely correct proof was due to Argand in 1806.\n\n", "meta": {"hexsha": "9e61ea2e43b0d4928884c88169a350be218fba28", "size": 2235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/ComplexNumbers.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/ComplexNumbers.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/ComplexNumbers.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 48.5869565217, "max_line_length": 70, "alphanum_fraction": 0.7378076063, "num_tokens": 636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8991213786215105, "lm_q1q2_score": 0.7827726101579183}}
{"text": "\n    \\documentclass{article}\n    \\usepackage[utf8]{inputenc}\n    \\usepackage{amsmath}\n    \\begin{document}\n %Title \n \\section{Collatz Sequence for \\(n=25\\) }\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(25)}\\\\[3mm]f(n), n=25\n \\\\ \n \\Rightarrow 3(25) + 1\n \\\\ \n \\Rightarrow n=76\n \\\\[3mm] \nf(n), n=76\n \\\\ \n \\Rightarrow \\frac{76}{2} \n \\\\ \n \\Rightarrow n=38\n \\\\[3mm] \nf(n), n=38\n \\\\ \n \\Rightarrow \\frac{38}{2} \n \\\\ \n \\Rightarrow n=19\n \\\\[3mm] \nf(n), n=19\n \\\\ \n \\Rightarrow 3(19) + 1\n \\\\ \n \\Rightarrow n=58\n \\\\[3mm] \nf(n), n=58\n \\\\ \n \\Rightarrow \\frac{58}{2} \n \\\\ \n \\Rightarrow n=29\n \\\\[3mm] \nf(n), n=29\n \\\\ \n \\Rightarrow 3(29) + 1\n \\\\ \n \\Rightarrow n=88\n \\\\[3mm] \nf(n), n=88\n \\\\ \n \\Rightarrow \\frac{88}{2} \n \\\\ \n \\Rightarrow n=44\n \\\\[3mm] \nf(n), n=44\n \\\\ \n \\Rightarrow \\frac{44}{2} \n \\\\ \n \\Rightarrow n=22\n \\\\[3mm] \nf(n), n=22\n \\\\ \n \\Rightarrow \\frac{22}{2} \n \\\\ \n \\Rightarrow n=11\n \\\\[3mm] \nf(n), n=11\n \\\\ \n \\Rightarrow 3(11) + 1\n \\\\ \n \\Rightarrow n=34\n \\\\[3mm] \nf(n), n=34\n \\\\ \n \\Rightarrow \\frac{34}{2} \n \\\\ \n \\Rightarrow n=17\n \\\\[3mm] \nf(n), n=17\n \\\\ \n \\Rightarrow 3(17) + 1\n \\\\ \n \\Rightarrow n=52\n \\\\[3mm] \nf(n), n=52\n \\\\ \n \\Rightarrow \\frac{52}{2} \n \\\\ \n \\Rightarrow n=26\n \\\\[3mm] \nf(n), n=26\n \\\\ \n \\Rightarrow \\frac{26}{2} \n \\\\ \n \\Rightarrow n=13\n \\\\[3mm] \nf(n), n=13\n \\\\ \n \\Rightarrow 3(13) + 1\n \\\\ \n \\Rightarrow n=40\n \\\\[3mm] \nf(n), n=40\n \\\\ \n \\Rightarrow \\frac{40}{2} \n \\\\ \n \\Rightarrow n=20\n \\\\[3mm] \nf(n), n=20\n \\\\ \n \\Rightarrow \\frac{20}{2} \n \\\\ \n \\Rightarrow n=10\n \\\\[3mm] \nf(n), n=10\n \\\\ \n \\Rightarrow \\frac{10}{2} \n \\\\ \n \\Rightarrow n=5\n \\\\[3mm] \nf(n), n=5\n \\\\ \n \\Rightarrow 3(5) + 1\n \\\\ \n \\Rightarrow n=16\n \\\\[3mm] \nf(n), n=16\n \\\\ \n \\Rightarrow \\frac{16}{2} \n \\\\ \n \\Rightarrow n=8\n \\\\[3mm] \nf(n), n=8\n \\\\ \n \\Rightarrow \\frac{8}{2} \n \\\\ \n \\Rightarrow n=4\n \\\\[3mm] \nf(n), n=4\n \\\\ \n \\Rightarrow \\frac{4}{2} \n \\\\ \n \\Rightarrow n=2\n \\\\[3mm] \nf(n), n=2\n \\\\ \n \\Rightarrow \\frac{2}{2} \n \\\\ \n \\Rightarrow n=1\n \\\\[3mm] \n\n    \\section{Credits}\n    %Maybe add link to gitrepo and other shit, idk\n    This is created using Collatzer (https://github.com/Z1aaan/Collatzer).\n    Created By: Z1aaan\n    \n    README:\n    A program created to visualize and simulate a user-given value for \\textit{N} \n    and see what happens when it is put under the Collatz function.\n    \\end{document}", "meta": {"hexsha": "c92050fb8693a155d69d45748e56bad5b8567164", "size": 2448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "other_samples/sample(25).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(25).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(25).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": 14.8363636364, "max_line_length": 82, "alphanum_fraction": 0.5245098039, "num_tokens": 1001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391706552538, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7827074564354629}}
{"text": "\\documentclass{article}\n\\author{a1trl9}\n\\title{Probability Review}\n\\date{}\n\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{environ}\n\n\\newcommand{\\V}[1]{\\boldsymbol{#1}}\n\\newcommand{\\TM}{\\bigtriangledown}\n\n\\NewEnviron{mulequation}{%\n\\begin{equation}\\begin{split}\n  \\BODY\n\\end{split}\\end{equation}\n}\n\n\\setlength\\parindent{0pt}\n\\counterwithin*{equation}{section}\n\n\\begin{document}\n\\maketitle\n\n\\section{Random Variables}\n\n\\subsection{Characteristics of Random Variables}\n\n\\subsubsection{Expected Value}\n\nFor discrete random variable \\(X\\), expected value is denfined as:\n\n\\begin{equation}\n\\sum_{i=1}^{\\infty}x_ip_i\n\\end{equation}\n\nWhere \\(p_i\\) is the probability for \\(X=x_i\\).\n\nFor continuous random variable \\(X\\), expected value is defined as:\n\n\\begin{equation}\n    \\int_{\\mathbf{R}}f(x)xdx\n\\end{equation}\n\nWhere \\(f(x)\\) is the probability density function for \\(X=x\\).\n\n\\vspace{2mm}\n\\textbf{Proposition 1:} For random variables \\(X_1, X_2\\), no matter if\nthey are independent, \\(E(X_1+X_2)=E(X_1)+E(X_2)\\).\n\n\\textbf{Proof}\n\nIf \\(X_1, X_2\\) are continuous variables. Then:\n\n\\begin{equation}\n\\begin{split}\n    E(X_1 + X_2)&=\\int_{-\\infty}^{\\infty}\n    \\int_{-\\infty}^{\\infty}f(x_1, x_2)(x_1+x_2)dx_1dx_2\\\\\n    &=\\int_{-\\infty}^{\\infty}x_1dx_1\\int_{-\\infty}^{\\infty}f(x_1,x_2)dx_2\\\\\n    &+\\int_{-\\infty}^{\\infty}x_2dx_2\\int_{-\\infty}^{\\infty}f(x_1,x_2)dx_1\\\\\n    &=\\int_{-\\infty}^{\\infty}x_1f(x_1)dx_1+\\int_{-\\infty}^{\\infty}x_2f(x_2)dx_2\\\\\n    &=E(X_1)+E(X_2)\n\\end{split}\n\\end{equation}\n\nNoting it actually requires rigorous proof to show why the order of\nintegrations on \\(x_1, x_2\\) could be interchanged.\n\n\\vspace{2mm}\n\\textbf{Proposition 2:} If \\(X_1, X_2\\) are two independent random variables,\n\\(E(X_1X_2)=E(X_1)E(X_2)\\).\n\n\\vspace{2mm}\n\\textbf{Proof}\n\n\\textit{Only prove when \\(X_1, X_2\\) are continuous variables.}\n\nSince \\(X_1, X_2\\) are independent:\n\\begin{equation}\n    f(x_1, x_2)=f(x_1)f(x_2)\n\\end{equation}\n\nTherefore:\n\n\\begin{equation}\n\\begin{split}\n    E(X_1X_2)&=\\int_{-\\infty}^{\\infty}\\int_{-\\infty}^{\\infty}\n    x_1x_2f(x_1, x_2)dx_1dx_2\\\\\n    &=\\int_{-\\infty}^{\\infty}f(x_1)dx_1\\int_{-\\infty}^{\\infty}f(x_2)dx_2\\\\\n    &=E(X_1)E(X_2)\n\\end{split}\n\\end{equation}\n\n\\subsubsection{Variance}\n\n\\vspace{2mm}\n\\textbf{Proposition 3:} If \\(X_1, X_2\\) are two independent random variables,\n\\(Var(X_1+X_2)=Var(X_1)+Var(X_2)\\).\n\n\\vspace{2mm}\n\\textbf{Proof}\n\\begin{equation}\n\\begin{split}\n    &Var(X_1+X_2)=E\\{[(X_1+X_2)-E(X_1+X_2)]^2\\}\\\\\n    &=E[(X_1+X_2)^2]-E^2(X_1+X_2)\\\\\n    &=E(X_1^2)+E(X_2^2)+2E(X_1X_2)-E^2(X_1)-E^2(X_2)-2E(X_1)E(X_2)\\\\\n    &=E(X_1^2)-E^2(X_1)+E(X_2^2)-E^2(X_2)\\\\\n    &=Var(X_1)+Var(X_2)\n\\end{split}\n\\end{equation}\n\n\\section{Distributions}\n\\subsection{Discrete Distributions}\n\\subsubsection{Poisson Distribution}\n\\textbf{PDF}\n\n\\begin{equation}\np(k)=\\frac{e^{-\\lambda}\\lambda^k}{k!}\n\\end{equation}\n\nWhere \\(k \\in \\{0\\} \\cup \\mathbb{N}\\).\n\nAccording to Taylor series (at 0, Maclaurin series):\n\\begin{equation}\n\\begin{split}\nf(\\lambda)&=e^{\\lambda}=f(0)+\\frac{f'(0)\\lambda}{1!}+\\frac{f''(0)\\lambda^2}{2!}+\\cdots\\\\\n&=\\frac{\\lambda^0}{0!}+\\frac{\\lambda^1}{1!}+\\frac{\\lambda^2}{2!}+\\cdots\\\\\n&=\\sum_{k=0}^\\infty\\frac{\\lambda^k}{k!}\n\\end{split}\n\\end{equation}\n\nTherefore:\n\\begin{equation}\n\\begin{split}\n\\sum_{k=0}^{\\infty}\\frac{e^{-\\lambda}\\lambda^k}{k!}&=e^{-\\lambda}\\sum_{k=0}^{\\infty}\\frac{\\lambda^k}{k!}\\\\\n&=e^{-\\lambda}e^{\\lambda}\\\\\n&=1\n\\end{split}\n\\end{equation}\n\n\\subsection{Continuous Distributions}\n\\subsubsection{Exponential Distribution}\n\\textbf{PDF}\n\n\\begin{equation}\np(x)=\\lambda e^{-\\lambda x}\n\\end{equation}\n\nIt is obvious:\n\\begin{equation}\n\\begin{split}\n\\int_{0}^{\\infty}\\lambda e^{-\\lambda x}&=-e^{-\\lambda x}|^{\\infty}_0\\\\\n&=-e^{\\infty}+e^0=0+1=1\n\\end{split}\n\\end{equation}\n\n\\subsubsection{Gamma Distribution}\n\\vspace{2mm}\n\\textbf{PDF}\n\\begin{equation}\n\\int_0^1x^{a-1}(1-x)^{b-1}dx\n\\end{equation}\n\n\\subsubsection{Beta Distribution}\nBeta distribution is used as conjugate prior distibution for Bernoulli Distribution.\n\n\\vspace{2mm}\n\\textbf{PDF}\n\\begin{equation}\np(x)=x^{a-1}(1-x)^{b-1}dx\n\\end{equation}\n\n\\vspace{2mm}\n\\textbf{Further: Beta function}\n\nBeta function holds an interesting property that:\n\n\\begin{equation}\n\\mathbf{B}(a, b) = \\frac{\\Gamma{(a)}\\Gamma{(b)}}{\\Gamma{(a, b)}}\n\\end{equation}\n\n\\vspace{2mm}\n\\textbf{Proof}\n\nLet \\(\\Gamma(a)=\\int_0^{\\infty}e^{-x}x^{a-1}dx\\) and \\(\\Gamma(b)=\\int_0^{\\infty}e^{-y}y^{b-1}dy\\), then:\n\\begin{equation}\n\\begin{split}\n\\Gamma(a)\\Gamma(b)&=\\int_0^{\\infty}e^{-x}x^{a-1}dx \\cdot \\int_0^{\\infty}e^{-y}y^{b-1}dy\\\\\n&=\\int_0^{\\infty}\\int_0^{\\infty}e^{-(x+y)}x^{a-1}y^{b-1}dxdy\n\\end{split}\n\\end{equation}\n\nLet \\(f(u, v): (u, v) \\rightarrow (x, y), x=uv, y=u(1-v)\\), then:\n\\begin{equation}\n\\Gamma{(a)}\\Gamma{(b)}=\\int_0^{\\infty}\\int_0^1e^{-u}(uv)^{a-1}(u(1-v))^{b-1}\n|D(u, v)|dudv\n\\end{equation}\n\nWhere \\(D(\\mathbf{J}(u, v))\\) is the determinant of Jacobian matrix \\(\\mathbf{J}\\). As:\n\\begin{equation}\n\\mathbf{J}=\n\\begin{bmatrix}\nv & 1 - v \\\\\nu & -u\n\\end{bmatrix}\n\\end{equation}\n\n\\(|D(\\mathbf{J}(u, v))|=|-uv-u(1-v)=-u|=u\\). So:\n\\begin{mulequation}\n\\Gamma{(a)}\\Gamma{(b)}=\n&\\int_0^{\\infty}\\int_0^1e^{-u}u^{a+b-2}v^{a-1}(1-v)^{b-1}ududv\\\\\n&=\\int_0^{\\infty}\\int_0^1e^{-u}u^{a+b-1}v^{a-1}(1-v)^{b-1}dudv\\\\\n&=\\int_0^{\\infty}u^{a+b-1}du\\int_0^1v^{a-1}(1-v)^{b-1}dv\\\\\n&=\\Gamma{(a+b)}\\mathbf{B}(a, b)\n\\end{mulequation}\n\nHere one fact is important:\n\\(\\Gamma(a)=\\int_0^{\\infty}e^{-x}x^{a-1}dx\\) is convergent, which can be proved\nas:\n\\begin{equation}\n\\begin{split}\n\\Gamma{(a)}&=\\int_0^{k}e^{-x}x^{a-1}dx+\\int_k^{\\infty}e^{-x}x^{a-1}dx\\\\\n\\end{split}\n\\end{equation}\n\nAnd it can be shown \\(\\forall a, \\exists k\\):\n\\begin{equation}\n\\begin{split}\n\\int_k^{\\infty}e^{-x}x^{a-1}dx\n<\n\\int_k^{\\infty}e^{\\frac{-x}{2}}dx=-2e^{\\frac{-x}{2}}|^{\\infty}_1=2e^{\\frac{-k}{2}}\n\\end{split}\n\\end{equation}\n\nand:\n\n\\begin{equation}\n\\int_0^{k}e^{-x}x^{a-1}dx\n\\end{equation}\n\nis constant.\n\n\\section{Linear Regression}\n\\textbf{Least Square Approach in the form of matrix}\nAs for:\n\n\\begin{equation}\n\\mathbf{y}=X\\beta + \\epsilon\n\\end{equation}\n\nThe least square approach tries to minimize:\n\n\\begin{equation}\nf=||y-X\\beta||^2\n\\end{equation}\n\nLet each partial derivative of \\(f\\) on \\(\\beta\\) is equal to zero. That is,\nfor \\(\\beta_j\\):\n\\begin{equation}\n\\sum_{i=1}^nx_{ij}(y_i-\\mathbf{x}_i\\beta)=0\n\\end{equation}\n\nIt could be transformed to:\n\\begin{equation}\n\\begin{split}\n&\\sum_{i=1}^nx_{ij}y_i=\\sum_{i=1}^nx_{ij}\\mathbf{x}_i\\beta\\\\\n&\\mathbf{x}'_j\\mathbf{y}=\\mathbf{x}'_jX\\beta\n\\end{split}\n\\end{equation}\n\nNow for all partial derivatives:\n\\begin{equation}\nX'\\mathbf{y}=X'X\\beta\n\\end{equation}\n\nThat is:\n\\begin{equation}\n\\beta=(X'X)^{-1}X'\\mathbf{y}\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "ace34e1499b1920745b1b9a2a05e16f154c1bae7", "size": 6623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prob.tex", "max_stars_repo_name": "a1trl9/stle", "max_stars_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "prob.tex", "max_issues_repo_name": "a1trl9/stle", "max_issues_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "prob.tex", "max_forks_repo_name": "a1trl9/stle", "max_forks_repo_head_hexsha": "f6d58624bb9d7dabed13cf6e2ed01de598ef7426", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.4858156028, "max_line_length": 106, "alphanum_fraction": 0.65287634, "num_tokens": 2869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467738423874, "lm_q2_score": 0.8902942261220292, "lm_q1q2_score": 0.7826992966656869}}
{"text": "\\section{Mathematical Properties}\nConsider $\\mathcal{D}$ to be a set of observations, such that $\\mathcal{D} = X \\biguplus Y$, $\\mathcal{D}$ is the set of two sets $X$ and $Y$ with no shared elements between them; $X$ is the set of normal observations, while $Y$ is the set of outliers; Denote $\\epsilon$ as threshold; $Fe$ is the feature of a function $F$ of the an observation; Any function $F$ uses feature $Fe$ must satisfy the following properties:\n\n\\begin{def}\\textbf{(Outlier Existence)} If there are at least two clusters then we should check for outliers:\n\\begin{align}\ndegree(D) \\geq 2\n\\end{align}\n\\end{def}\n\n\\begin{def}\\textbf{(Normality)} To check whether a certain observation is normal:\n\\begin{align}\nx \\in D \\text{ is normal observation if } x \\in X | d(x) \\geq \\epsilon\n\\end{align}\n\\end{def}\n\n\\begin{def}\\textbf{(Outlier)} To check whether a certain observation is an outlier:\n\\begin{align}\ny \\in D \\text{ is an outlier if } y \\in Y | d(y) < \\epsilon\n\\end{align}\n\\end{def}\n\n\\section{Motivation}\nThe motivation of this research was to compare two algorithms of outlier detection. Precisely, One Class Support Vector Machine and Local Outlier Factor, bringing together two advantages:\n\\begin{itemize}\n\\item Ability to know the algorithm with the higher efficiency.\n\\item Ability to know the algorithm with the higher effectiveness.\n\\end{itemize}\n\n\\section{Objective}\nIn order to achieve the above goals, the following objectives must be satisfied:\n\\begin{itemize}\n\\item Simplicity of structure.\n\\item Functional Completeness.\n\\end{itemize}\n\n", "meta": {"hexsha": "e0e5865ee811fda40d222e03cf666b7abeab2ee5", "size": 1555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "temparary.tex", "max_stars_repo_name": "sustecha/MSc.-Thesis", "max_stars_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "temparary.tex", "max_issues_repo_name": "sustecha/MSc.-Thesis", "max_issues_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "temparary.tex", "max_forks_repo_name": "sustecha/MSc.-Thesis", "max_forks_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_forks_repo_licenses": ["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.1944444444, "max_line_length": 419, "alphanum_fraction": 0.7511254019, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7826648316432924}}
{"text": "\\documentclass[10pt]{article}\n\n\\usepackage{amsmath}\n\\usepackage{algpseudocode}\n\\usepackage{graphicx}\n\\usepackage{hyperref}\n\\usepackage{enumerate}\n\n\\title{Loop Diagonalization}\n\\author{Vedant Kumar \\\\ \\texttt{vsk@berkeley.edu}}\n\n\\begin{document}\n\\maketitle\n\n\\section{Abstract}\n\nThe eigenvalue equation $Mv = \\lambda v$ is a powerful statement about\nmatrix and scalar multiplications. In the context of compiler optimization,\nwe can use it to transform linearizable loops which run in $O(n)$ steps into\nmatrix operations which run in $O(\\log n)$ steps.  This paper defines loop\ndiagonalization (the process of rewriting linearizable loops as two\nmatrix multiplies), discusses the implementation of this optimization\nwith LLVM, and discusses the advantages and limitations of this method.\n\n\\section{Overview}\n\nRoughly speaking, a linearizable loop may equally well be represented as a\nmatrix $M$. Let the loop's state variables reside in a vector $v$. Each\niteration of the loop effects the update $v' = Mv$.  \n\nIt follows inductively that if one iteration of a linearizable loop gives\n$Mv$, $n$ iterations of the loop can be simulated by computing $M^n v$.\nPerforming this matrix exponentiation naively requires up to $O(nm^3)$\nscalar multiplictaions.\n\nLinear algebra comes to the rescue. Recall the equation $M = PDP^{-1}$.  The\ncolumn vectors of $P$ are the eigenvectors of $M$, and the diagonal matrix\n$D$ contains the corresponding eigenvalues. We can find this\neigendecomposition for any square $M$ so long as $P$ is invertible.\n\nIt is known that $M^n = PD^nP^{-1}$, and that $D^n$ can be computed in\n$O(m\\log n)$ steps using the repeated squaring algorithm. With these facts\nwe can replace linearizable loops with fast matrix operations.\n\n\\section{Diagonalization}\n\nThe following definitions are useful: \\\\\n\n\\noindent\n\\textbf{Def. Linearizable Loop}: A tuple $(L, M, v)$ where $L$ is a list of\nbasic blocks with a preheader and one backedge, $M$ is a $m$ by $m$ square\nmatrix with $m$ linearly independent eigenvectors, and $v$ is a vector of\nstate variables. Let $v' = Mv$: the \\emph{only} permissible instructions in\n$L$ are the arithmetic operations which contribute to the goal of updating\n$v$ to $v'$ with no other side effects, excepting the branch and jump\ninstructions required to construct a loop. \\\\\n\n\\noindent\n\\textbf{Def. Loop Diagonalization}: Given a program containing a linearizable\nloop $(L, M, v)$, replace $L$ with a single basic block that computes $M^n\nv$ using $PD^nP^{-1}v$. \\\\\n\nLoop diagonalization transforms functions in $O(nm^3)$ into two matrix\nmultiplications and a diagonal matrix exponentiation, which is in $O(m^3 +\nm\\log n)$. This can result in an appreciable increase in program efficiency,\nas will be shown.\n\n\\section{The Fibonacci Example}\n\nConsider the iterative procedure for computing the $n$-th Fibonacci number:\n\n\\begin{center}\n    \\parbox{4cm}{\n        \\begin{algorithmic}\n            \\Function{fib}{n}\n                \\State $a\\gets 1$\n                \\State $b\\gets 1$\n                \\For{$i \\in [2 ... n]$}\n                    \\State $tmp\\gets a$\n                    \\State $a\\gets b$\n                    \\State $b\\gets tmp + b$\n                \\EndFor\n                \\State \\Return b\n            \\EndFunction\n        \\end{algorithmic}\n    }\n\\end{center}\n\nThe state vector is $v = (a, b)^T$. Initially, $v_0 = (1, 1)^T$. After each\niteration of the loop, $a' = b$ and $b' = a + b$. These linear combinations\nare encoded by:\n\n\\begin{displaymath}\nM = \\begin{bmatrix}\n        0 & 1 \\\\\n        1 & 1\n    \\end{bmatrix}\n\\end{displaymath}\n\nLet $\\phi = \\frac{1 + \\sqrt{5}}{2}$. The eigenvalues of $M$ are $\\phi$ and\n$1-\\phi$. The corresponding eigenvectors are $(1, \\phi)^T$ and $(\\phi,\n-1)^T$. $M$ is diagonalizable because its eigenvalues are distinct and its\neigenvectors are linearly independent:\n\n\\begin{displaymath}\nM = \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    \\phi & 0 \\\\\n    0 & 1-\\phi\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}^{-1}\n\\end{displaymath}\n\nGiven $M = PDP^{-1}$, $M^n = PD^nP^{-1}$:\n\n\\begin{align*}\nM^n &= \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    \\phi & 0 \\\\\n    0 & 1-\\phi\n    \\end{bmatrix}^n\n    \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}^{-1} \\\\\n    &= \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    \\phi^n & 0 \\\\\n    0 & (1-\\phi)^n\n    \\end{bmatrix}\n    \\begin{bmatrix}\n    1 & \\phi \\\\\n    \\phi & -1\n    \\end{bmatrix}^{-1}\n\\end{align*}\n\nNow the Fibonacci loop has been diagonalized:\n\n\\begin{center}\n    \\parbox{6cm}{\n        \\begin{algorithmic}\n            \\Function{fib}{n}\n                \\State $(a, b)^T \\gets PD^{n-1}P^{-1}(1, 1)^T$\n                \\State \\Return b\n            \\EndFunction\n        \\end{algorithmic}\n    }\n\\end{center}\n\n\\section{Implementation}\n\nI implemented automatic loop diagonalization using the LLVM compiler\ninfrastructure. This involved creating an instance of\n\\texttt{llvm::LoopPass} (\\texttt{ADPass}) which can be loaded from a dynamic\nlibrary. \\texttt{ADPass} determines if a loop is linearizable by filtering\nout unsupported instructions. It then builds the loop matrix $M$ by\nperforming a depth-first search on the phi-nodes in the loop. This\nsearch allows the pass to determine the coefficients of every linear\ncombination of $v$ in the loop, which are exactly the entries of $M$. Next,\nthe pass uses the \\texttt{Eigen} library to find the eigendecomposition of\n$M$. Finally the pass deletes the original loop, inserts newly generated\nbitcode corresponding to the decomposition into the program, and rewires the\nvalues flowing into the exit phi-nodes. The source code is available under a\nnon-restrictive free software license\n\\href{https://github.com/vedantk/auto-diagonalize}{here}.\n\n\\section{Testing}\n\nTo test the loop diagonalization algorithm, I created a test suite of\niterative processes written in C++ and compiled them at the highest\noptimization levels available in LLVM 3.2 and clang++ on Linux x86-64. I\nthen created alternate versions of the binaries which were post-processed\nwith \\texttt{ADPass}. \\texttt{ADPass} was able to diagonalize basic loops\nbut depended upon pre-processing by the compiler to eliminate stack-spills\nand canonicalize loops. It produced good results for all tested programs. I\ndid not attempt to analyze loops which I knew the pass cannot optimize.\n\nConsider the iterative Fibonacci procedure discussed in a previous section.\nI measured the time it took to call $fib(0)$, ..., $fib(200)$ 50,000 times\neach. I first tried this with the normal binary and then compared its\nperformance to the auto-diagonalized binary. As expected, the normal program\n(left) scales linearly with the size of the input, whereas the diagonalized\nprogram (right) exhibits $O(\\log n)$ performance. \n\n\\begin{center}\n\\includegraphics[scale=0.42]{\"fib-O3\"}\n\\includegraphics[scale=0.42]{\"fib-O3-diag\"}\n\\end{center}\n\n\\section{Discussion}\n\nMatrix decompositions have applications in many fields, but their use in\ncompiler loop optimizations appears to be novel \\footnote{This might have\nbeen true when it was written in 2012, but papers on abstract acceleration\nof general linear loops have been published since then.}. It isn't clear if\nthis optimization pays for its implementation complexity.\n\nLeaving the issue of practicality aside, there are important technical\nlimitations to \\texttt{ADPass}. The most severe restriction is that function\ncalls, branches, and other instructions with unpredictable side effects\ncannot occur within a linearizable loop. In general it is not possible to\nlift this draconian restriction without solving undecidable problems such as\n`when exactly is this branch taken?' and `does this function call return?'.\nAnother problem is that there is inherent numerical instability in IEEE 754\nfloating point numbers, which means that the effects of auto-diagonalization\nare not always completely transparent.\n\nWith that said, we're left with a somewhat academic optimization that\nproduces some interesting results. It allows linearizable $O(nm^3)$\nprocesses to run in $O(m^3 + m\\log n)$, using the simple magic trick $Mv =\n\\lambda v$.\n\n\\section{References}\n\n\\begin{enumerate}[1.]\n    \\item LLVM, \\url{http://llvm.org/}.\n    \\item Eigen, v3. Ga\\\"{e}l Guennebaud and Beno\\^{i}t Jacob and others.\n        \\url{http://eigen.tuxfamily.org}.\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "350660229b99b4f331afef3357c284a281a15eb9", "size": 8505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/loop-tx.tex", "max_stars_repo_name": "vedantk/auto-diagonalize", "max_stars_repo_head_hexsha": "ca8917ac13afc507c86e0ab2f62c2aa35030523c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-05-06T01:23:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-06T02:56:44.000Z", "max_issues_repo_path": "doc/loop-tx.tex", "max_issues_repo_name": "vedantk/auto-diagonalize", "max_issues_repo_head_hexsha": "ca8917ac13afc507c86e0ab2f62c2aa35030523c", "max_issues_repo_licenses": ["MIT"], "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/loop-tx.tex", "max_forks_repo_name": "vedantk/auto-diagonalize", "max_forks_repo_head_hexsha": "ca8917ac13afc507c86e0ab2f62c2aa35030523c", "max_forks_repo_licenses": ["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.3461538462, "max_line_length": 77, "alphanum_fraction": 0.7100529101, "num_tokens": 2312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7826586325955389}}
{"text": "\\newpage\n\\section{Jinchao: XN}\nXN is independent with the SGD training process.\n\nAfter an update of the neural network, XN can be applied to each hidden layer successively, and won't change the output of it. In this example, we have only one hidden layer. The XN algorithm can be written as follows.\n\\begin{enumerate}\n\\item Denote \n$$\\Theta=(W_1\\ b_1)\\in\\mathbb{R}^{n_1\\times(n+1)}$$\nand\n$$\n\\hat X=(X;\\mathbf{1})\\in\\mathbb{R}^{(n+1)\\times m}, \nY=\\text{ReLU1}(W_1X+b_1).\n$$\n\tSplit the columns of $\\hat X$ to $X_I$, $X_J$, $X_K$, s.t. for every row $\\theta_i$ of $\\Theta$, $i=1,...,n_1$,\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\theta_i X_I\\leq 0,\\\\\n\t\\theta_i X_J\\geq 1,\\\\\n\t\\theta_i X_K\\in[0,1].\n\t\\end{aligned}\n\t\\end{equation}\n\tDenote IJ as the union of I and J. For every $\\theta_i$, the optimization problem can be rewritten as\n\t\\begin{equation}\\label{standardv2opt}\n\t\\begin{aligned}\n\t\\min_\\theta&\\quad\\|\\theta  X_{IJ}-Y_{IJ}\\|_2\\\\\n\t\\text{subject to}&\\quad\\theta X_{I}\\leq 0,\\\\\n\t&\\quad\\theta X_{J}\\geq 1,\\\\\n\t&\\quad\\theta X_{K}=Y_{K}.\n\t\\end{aligned}\n\t\\end{equation}\n\\end{enumerate}\n", "meta": {"hexsha": "aa8d689d869a60533717226bb3188070edd2ef3d", "size": 1077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/jinchao-XN.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/jinchao-XN.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/jinchao-XN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.65625, "max_line_length": 218, "alphanum_fraction": 0.6796657382, "num_tokens": 422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257062, "lm_q2_score": 0.8311430457670241, "lm_q1q2_score": 0.7826493074540972}}
{"text": "\\section{Linear smoothers}\nMost of the smoother presented here are linear smoothers which means\nthat the fit at any point $x_0$ can be written as \n\\[\ns(x) = \\sum_{j=1}^n S_{j}(x) y_j.\n\\]\n\nIn practice we usually have the model \n\\[\nY_i = f(X_i) + \\epsilon_i\n\\]\nand we have observations $\\{(x_i, y_i)\\}$. Many times it is the vector\n${\\mathbf f} = \\{f(x_1),\\dots,f(x_n)\\}'$ we are after. In this case\nthe vector of estimates $\\hat{\\mathbf f} =\n\\{\\hat{f}(x_1),\\dots,\\hat{f}(x_n)\\}'$ can be written as\n\\[\n\\hat{\\mathbf f} = \\bS \\by\n\\]\nwith $\\bS$ a matrix with the i,j-th entry $S_{j}(x_i)$. We will call\n$\\hat{\\mathbf f}$ the {\\it smooth}.\n\nThis makes it easy to figure out things like the variance of\n$\\hat{\\f}$ since \n\\[\n\\var[\\bS \\by] = \\bS \\var[\\by] \\bS' \n\\]\nwhich in the case of IID data is $\\sigma^2 \\bS\\bS'$.\n", "meta": {"hexsha": "1e985eab3ea688c65610274463c9dddef9ec0830", "size": 809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-02-05.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-02-05.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-02-05.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 28.8928571429, "max_line_length": 70, "alphanum_fraction": 0.6415327565, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9572778048911612, "lm_q2_score": 0.8175744717487329, "lm_q1q2_score": 0.7826458956506777}}
{"text": "\\section{Graphs}\n\n\\begin{definition}[Arborescence]\n    an arborescence is a directed graph in which, for a vertex u called the\n    root and any other vertex v, there is exactly one directed path from u to v.\n \\end{definition}\n\n\\begin{definition}[Clique]\n    A subset of vertices $C \\subset V$, such that in this subgraph all nodes\n    are connected, i.e.\\ there is an edge from every pair of nodes.\n\\end{definition}\n\n\\begin{definition}[Connected graph (component)]\\label{connectedcomp}\n    A graph in which, from any $v \\in V$, you can reach any other $u \\neq v$\n\\end{definition}\n\n\\begin{definition}[Directed graph]\n    Properties:\n    \\begin{itemize}\n        \\item $\\sum\\limits_{v \\in V}{d(v)} = 2|E|$\n        \\item $\\sum\\limits_{v \\in V}{indegree(v)} = \n            \\sum\\limits_{v \\in V}{outdegree(v)}$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Eularian]\\label{eularian}\n    Visit each \\textit{edge} once.\n\\end{definition}\n\n\\begin{definition}[Hamiltonian]\n    Visit each \\textit{vertex} once.\n\\end{definition}\n\n\\begin{definition}[Metric spaces]\\label{metric}\n    See also~\\nameref{semimetric}\n    Properties:\n    \\begin{itemize}\n        \\item $d_{u,v} = 0 \\iff u = v$\n        \\item $d_{u,v} = d_{v,u}$\n        \\item $\\forall k, d_{u,v} \\leq d_{u,k} + d_{k,v}$\n    \\end{itemize}\n\\end{definition}\n\n\\begin{definition}[Minimum mean cost]\n    minimize ratio of cost of arcs (directed edges) to number of arcs\n\\end{definition}\n\n\\begin{definition}[MST]\n    A mininum~\\nameref{spantree}, such the weight of this tree is less than\n    or equal to all other possible~\\nameref{spantree}.\n\\end{definition}\n\n\\begin{definition}[Offline Graph Algorithm]\n    Algorithms on a graph that requires knowing the entire structure\n    For example PageRank, Clustering, so on.\n\\end{definition}\n\n\\begin{definition}[Online Graph Algorithm]\n    Process the graph in a serial fashion, e.g. operate on the graph without knowing\n    the entire structure. For example shortest path, pattern matching, etc.\n\\end{definition}\n\n\\begin{definition}[Planar graph]\n    No edges need to cross each other.\n\\end{definition}\n\n\\begin{definition}[Semi-metric]\\label{semimetric}\n    Like a~\\nameref{metric}, without the property that\n    $d_{u,v} = 0 \\iff u = v$\n\\end{definition}\n\n\n\\begin{definition}[Spanning tree]\\label{spantree}\n    Connected, undriected graph that has all vertices and some subset\n    of edges to form a tree.\n\\end{definition}\n\n\\begin{definition}[Strongly connected component]\n    Similar to~\\nameref{connectedcomp}, but in a directed graph.\n\\end{definition}\n\n\\begin{definition}[Topological sort]\\label{topsort}\n    Runs in O(V + E), same as DFS, although it can be supered to $O(\\log_{2} n)$\n\\end{definition}\n\n\\begin{definition}[Tree]\\label{tree}\n    Properties of a tree:\n    \\begin{itemize}\n        \\item in a tree, there will always be an even amount of nodes that has\n            an uneven degree.\n        \\item Degree of nodes in a tree is at most twice the number of nodes\n    \\end{itemize}\n\\end{definition}\n\n\n\n\\begin{definition}[Vertex-cover]\n    A selection of vertices such that each edge is incident to at least one\n    of them.\n\\end{definition}\n\n", "meta": {"hexsha": "c8a80e1500f7252a5286807d52e7ed2b14d0e07f", "size": 3148, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/graph.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/graph.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/graph.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": 30.862745098, "max_line_length": 84, "alphanum_fraction": 0.6975857687, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896780646393, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7826446886973281}}
{"text": "\n\\subsection{The Ramsey RESET test}\n\nThe Ramsey Regression Equation Specification Error Test (RESET)\n\nOnce we have done our OLS we have \\(\\hat y\\).\n\nThe Ramsey RESET test is an additional stage, which takes these predictions and estimates:\n\n\\(y=\\theta x+\\sum_{i=1}^3\\alpha_i \\hat {y^i}\\)\n\nWe then run an F-test on \\(\\alpha\\), with the null that \\(\\alpha = 0\\).\n\n", "meta": {"hexsha": "ef873fa738bab1efa14409ba80bb3efd97f9bc2d", "size": 362, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/linearML/04-01-reset.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/linearML/04-01-reset.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/linearML/04-01-reset.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.8571428571, "max_line_length": 90, "alphanum_fraction": 0.7099447514, "num_tokens": 99, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.782597338276426}}
{"text": "\\chapter{The Definition of a Graph}\n\\label{chapter:graph-theory-basics}\nIn this chapter we start a very important topic in discrete mathematics, which\nbecame even more important with the rise of computers, we start the discussion\nof graph theory. Graphs are used in mathematics and computer science to describe\nnetworks, maps, and dependencies of objects.\n\n\\begin{definition}\n  A \\emph{graph} $G$ is a pair $(V, E)$ such that $E \\subseteq V^2$ is a multiset.\n\n  We say that $G$ is \\emph{unoriented} iff $(u, v) \\in E$ iff $(v, u) \\in E$ for\n  any $u, v \\in V$. Otherwise the graph is \\emph{oriented}.\n  We say that a graph does not have \\emph{loops} iff $(u, u) \\notin E$ for any\n  $u \\in V$. Finally, we say that the graph has \\emph{parallel edges} if\n  $E$ is not a set.\n\\end{definition}\nA graph is \\emph{simple} iff it has no loops, it has not parallel edges, and\nit is unoriented.\n\nFrom now on we will follow a standard convention and think about the set of\nedges of unoriented graphs as sets of \\emph{unordered} pairs.\n\nIt is very convenient to draw graphs using pictures like this.\n\\begin{center}\n  \\begin{tikzpicture}\n    \\node[shape=circle,draw=black] (v1) at (0,0) {\\tiny A};\n    \\node[shape=circle,draw=black] (v2) at (0,1) {\\tiny B};\n    \\node[shape=circle,draw=black] (v3) at (1,1) {\\tiny C};\n    \\node[shape=circle,draw=black] (v4) at (-1,2) {\\tiny D};\n\n    \\draw (v1) -- (v2);\n    \\draw (v1) -- (v3);\n    \\draw (v2) -- (v4);\n    \\draw (v2) -- (v3);\n\n  \\end{tikzpicture}\n\\end{center}\nIn this picture, each circle corresponds to a vertice and each line corresponds\nto a an edge; i.e. this diagram describes the graph\n\\[\n  (\\underbrace{\\set{A, B, C, D}}_V,\n  \\underbrace{\\set{(A, B), (A, C), (B, C), (B, D)}}_E).\n\\]\nNote that we already use the convention that in an unoriented graph the pairs\nare unordered and we have not listed $(B, A)$, $(C, A)$ etc.\n\nTo talk about graphs we need to fix the vocubulary.\nAn edge is said to \\emph{connect} its endpoints; two vertices that are\nconnected by an edge are called \\emph{adjacent}; and a vertex that is an\nendpoint of a loop is said to be \\emph{adjacent to itself}. An edge is said to\nbe \\emph{incident} on each of its endpoints, and two edges incident\non the same end point are called \\emph{adjacent}. A vertex on which no edges\nare incident is called \\emph{isolated}.\n\nOne of the most important examples of graphs are complete graphs defined as\nfollows.\n\\begin{definition}\n  Let $n$ be a natural number. A complete graph on $n$ vertices, denoted\n  $K_n$,\\footnote[][-2cm]{%\n    Some sources claim that the letter K in this notation stands for the German\n    word komplett, but the German name for a complete graph, vollst\\\"{a}ndiger\n    Graph, does not contain the letter K, and other sources state that the\n    notation honors the contributions of Kazimierz Kuratowski to graph theory.\n  } \n  is a simple graph with $n$ vertices and exactly one edge connecting\n  each pair of distinct vertices.\n\\end{definition}\n\\nomenclature[G]{$K_n$}{denotes the complete graph on $n$ vertices}\n\n\\begin{exercise}\n\\label{exercise:maximal-number-of-edges}\n  Show that for all natural numbers $n$, the number of edges of $K_n$\n  is $\\frac{n(n - 1)}{2}$.\n\\end{exercise}\n\n\\section{Operations on Graphs}\nQuite often in order to prove a theorem we need to modify a graph. The most\noften operations are the following four. Let $G = (V, E)$ be a graph,\n$F \\subseteq E$ be a set of edges, $U \\subseteq V$ be a set of edges,\n$e \\in E$ be an edge, and $v \\in V$ be a vertex.\n\\begin{enumerate}\n  \\item $G[U]$ denotes the graph $(U, \\set[e \\in U^2]{e \\in E})$,\n    $G[U]$ is called the induced subgraph of $G$ on the vertices $U$;\n    \\nomenclature[G]{$G[U]$}{denotes the induced subgraph of $G$ on the vertices $U$\n    (i.e. $(U, \\set[e \\in U^2]{e \\in E})$)}\n  \\item $G[F]$ denotes the graph $(V, F)$, $G[F]$ is called the induced\n    subgraph of $G$ on the edges $F$;\n    \\nomenclature[G]{$G[F]$}{denotes the induced subgraph of $G$ on the edges $F$\n    (i.e. $(V, F)$)}\n  \\item $G - e$ denotes the graph $(V, E \\setminus \\set{e})$, i.e., the graph $G$\n    without the edge $e$.\n    \\nomenclature[G]{$G - e$}{denotes the graph $(V, E \\setminus \\set{e})$}\n  \\item $G - v$ denotes the graph\n    $(V \\setminus \\set{v}, E \\cap (V \\setminus \\set{v})^2)$, i.e., the graph $G$\n    without the vertex $v$.\n    \\nomenclature[G]{$G - v$}{denotes the graph\n      $(V \\setminus \\set{v}, E \\cap (V \\setminus \\set{v})^2)$}\n\\end{enumerate}\n\nNote that we used the word ``subgraph'', in fact we can define formally the\nmeaning of this word.\n\\begin{definition}\n  We say that a graph $H = (U, F)$ is a \\emph{subgraph} of $G = (V, E)$ iff\n  $U \\subseteq V$ and $F \\subseteq E$.\n\\end{definition}\n\n\\section{Degrees of Vertices}\nThe degree of a vertex is the number of endsegments of edges that ``stick out\nof'' the vertex.\n\\begin{definition}\n  Let $G = (V, E)$ be a graph, and $v$ be a vertex. Then\n  $\\deg_G(v) = |\\set[{e \\text{is connected to } v}]{e \\in E}|$.\n\\end{definition}\n\n\\begin{exercise}\n  Let $G = (V, E)$ be a graph and $v \\in V$ be a vertex.\n  What are the possible values of $\\deg_G(v)$?\n\\end{exercise}\n\nNote that Lemma~\\ref{lemma:handshaking} shows that in any simple graph the\nnumber of vertices with an odd degree is even.\nThe essence of the proof of this lemma is the following statement.\n\\begin{theorem}\n\\label{theorem:handshaking-graphs}\n  Let $G = (V, E)$ be a simple graph. Then $\\sum_{v \\in V} \\deg_G(v) = 2|E|$.\n\\end{theorem}\n\nIt is intresting to note that this result allows to give another proof \n\\Cref{corollary:binommials-equality}. Let us consider a graph $H_n = \n(\\set{0, 1}^n, E_n)$ such that $(x, y) \\in E_n$ iff $x$ and $y$ are \ndifferent in exactly one position. Note that $\\deg_{H_n} x = n$ for all \n$x \\in \\set{0, 1}^n$; hence, $|E_n| = n 2^n / 2 = n 2^{n - 1}$. In addition,\nnote that there are $\\binom{n}{k}$ vertices with $k$ many 1's and there are\n$k$ edges that turn $1$ into $0$; i.e., there are \n$\\sum_{k = 0}^n k \\binom{n}{k}$ edges in $H_n$. Therefore, \n$\\sum_{k = 0}^n k \\binom{n}{k} = n 2^{n - 1}$.\n\n\\begin{chapterendexercises}\n  \\exercise Either draw a graph with the specified properties or explain why\n    no such graph exists:\n    \\begin{enumerate}[nolistsep]\n      \\item simple graph with five vertices of degrees $1$, $2$, $3$, $3$,\n        and $5$;\n      \\item simple graph with four vertices of degrees $1$, $2$, $3$, and $3$;\n      \\item simple graph with four vertices of degrees $1$, $1$, $1$, and $5$;\n      \\item simple graph with four vertices of degrees $1$, $2$, $3$, and $4$;\n      \\item simple graph with four vertices of degrees $1$, $2$, $3$, and $5$.\n    \\end{enumerate}\n  \\exercise Let $G$ be a \\emph{simple} graph. Show that there are two different\n    vertices $u$ and $v$ such that they have the same degree.\n    \\begin{solution}\n      Assume $G$ is a simple graph with $n$ vertices. Suppose all vertices in\n      $G$ have different degrees. The set of degrees of the vertices is then\n      $\\set{0, 1, \\dots, n - 1}$. However this means that one vertex is\n      connected to all other vertices and another vertex is connected to no\n      other vertices, it is a contradiction. Therefore there are at least two\n      different vertices $u$ and $v$ such that they have the same degree.\n    \\end{solution}\n  \\exercise Let $G = ([5] \\times [5], E)$ be a graph such that \n    $((x_1, y_1), (x_2, y_2)) \\in E$ iff\n    \\begin{itemize}\n      \\item either $x_1 = x_2$ and $|y_1 - y_2| = 1$, or\n      \\item $|x_1 - x_2| = 1$ and $y_1 = y_2$.\n    \\end{itemize}\n\n    \\begin{enumerate}\n      \\item Is it possible to cover the graph $G$ with $8$ paths of length $5$\n        (these paths should not visit any vertex twice)? Note that by covering we\n        mean that every edge of $G$ is an edge of one of the paths.\n      \\item Is it possible to cover the graph $G$ with $5$ paths of length $8$\n        (these paths should not visit any vertex twice)? Note that by covering\n        we mean that every edge of $G$ is an edge of one of the paths.\n    \\end{enumerate}\n  \\exercise Let $G$ be a graph on $n$ vertices such that every vertex has odd\n    degree. Show that $n$ is even.\n    \\begin{solution}\n      One may notice that for any odd and even numbers the following identities\n      hold:\n      $\\mathrm{odd} + \\mathrm{odd} = \\mathrm{even}$ and $\\mathrm{even} +\n      \\mathrm{odd} = \\mathrm{odd}$.\n\n      Assume there are $k$ edges in $G$ where $k \\in \\Z$ and let $v_i$ denote\n      the $i$th vertex of $G$ and $d_i$ denote degree of $v_i$, where $i \\in\n      \\range{n}$. Then the total degree of $G$ (i.e. $\\sum_{i = 1}^n d_i$)\n      is $2k$ by \\Cref{theorem:handshaking-graphs}. Since every vertex has odd\n      degree $2k = \\sum_{i = 1}^{n} d_i = \\mathrm{odd} + \\mathrm{odd} + \\dots +\n      \\mathrm{odd}$.\n\n      Notice if $n$ is odd then there is an odd number of vertices and\n      $\\sum_{i = 1}^n d(v_i) = \\mathrm{odd} \\neq 2k$ as $2k$ is even. Thus $n$\n      must be even.\n    \\end{solution}\n  \\exercise In a group of $25$ people, is it possible for each to shake hands\n    with exactly $3$ other people?\n  \\exercise Suppose that $G$ is a graph with $v$ vertices and $e$ edges and\n    that the degree of each vertex is at least $d_\\mathrm{min}$ and at most\n    $d_\\mathrm{max}$. Show that\n    \\[\n      \\frac{1}{2} v d_\\mathrm{min} \\le e \\le \\frac{1}{2} v d_\\mathrm{max}.\n    \\]\n\\end{chapterendexercises}\n", "meta": {"hexsha": "a61f7483d3000d92788c785cc2c00b73975be0b6", "size": 9383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_8/chapter_32_basics_of_graph_theory.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_32_basics_of_graph_theory.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_32_basics_of_graph_theory.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.4504950495, "max_line_length": 84, "alphanum_fraction": 0.6578919322, "num_tokens": 3025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8774767890838836, "lm_q1q2_score": 0.7825434976666977}}
{"text": "\n\\subsection{Axiom of regularity}\n\nThe axiom of regularity states that:\n\n\\(\\forall x[x\\ne \\varnothing \\rightarrow \\exists y \\in x (y\\land x )=\\varnothing]\\)\n\nThat is, for all non-empty sets, there is an element of the set which is disjoint from the set itself.\n\nThis means that no set can be a member of itself.\n\n", "meta": {"hexsha": "7baf1e0802e784b56e0257760fc3a4b8e8752709", "size": 313, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/04-03-regularity.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/04-03-regularity.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/04-03-regularity.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.0833333333, "max_line_length": 102, "alphanum_fraction": 0.7348242812, "num_tokens": 84, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9390248191350352, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7825124735066638}}
{"text": "\\lab{Anisotropic Diffusion}{Anisotropic Diffusion}\n\\label{lab:AnisotropicDiffusion}\n\n\\objective{Demonstrate the use of finite difference schemes in image analysis.}\n\nA common task in image processing is to remove extra static from an image.\nThis is most easily done by simply blurring the image, which can be accomplished by  treating the image as a rectangular domain and applying the diffusion (heat) equation:\n\\[u_t = c \\Delta u\\]\nwhere $c$ is some diffusion constant and $\\Delta$ is the Laplace operator.\nUnfortunately, this also blurs the boundary lines between distinct elements of the image.\n\nA more general form of the diffusion equation in two dimensions is:\n\\[u_t = \\nabla\\cdot \\left( c(x,y,t) \\nabla u \\right)\\]\nwhere $c$ is a function representing the diffusion coefficient at each given point and time.\nIn this case, $\\nabla \\cdot$ is the divergence operator and $\\nabla$ is the gradient.\n\nTo blur a picture uniformly, choose $c$ to be a constant function.\n% , but we are often interested in \\textit{preserving the edges} between features of the image.\nSince $c$ controls how much diffusion is allowed at each point, it can be modified so that diffusion is minimized across edges in the image.\nIn this way we attempt to limit diffusion near the boundaries between different features of the image, and allow smaller details of the image (such as static) to blur away.\nThis method for image denoising is especially useful for denoising low quality images, and was first introduced by Pietro Perona and Jitendra Malik in 1987.\nIt is known as Anisotropic Diffusion or Perona-Malik Diffusion.\n\n\\section*{A Finite Difference Scheme}\nSuppose we have some estimate $E$ of the rate of change at a given point in an image.\n$E$ will be largest at the boundaries in the image.\nWe will then let $c(x,y,t) = g(E(x,y,t))$ where $g$ is some function such that $g(0)=1$ and $\\displaystyle{\\lim_{x \\to \\infty} g(x) = 0}$.\nThus $c$ will be small where $E$ is large, so that little diffusion occurs near the boundaries of different portions of the image.\n\nWe will model this system using a finite differencing scheme with an array of values at a 2D grid of points, and iterate through time.\nLet $U_{l,m}^n$ be the discretized approximation of the function $u$, $n$ be the index in time, $l$ be the index along the $x$-axis, and $m$ be the index along the $y$-axis.\n\nThe Laplace operator can be approximated with the finite difference scheme\n\\[\\Delta u = u_{xx}+u_{yy} \\approx \\frac{U_{l-1,m}^n - 2 U_{l,m}^n + U_{l+1,m}^n}{(\\Delta x)^2} + \\frac{U_{l,m-1}^n-2 U_{l,m}^n + U_{l,m+1}^n}{(\\Delta y)^2}.\\]\nA good metric to use with images is to let the distance between each pixel be equal to one, so $\\Delta x = \\Delta y = 1$.\nRearranging terms, we obtain\n\\[\\Delta u \\approx (U_{l-1,m}^n - U_{l,m}^n) + (U_{l+1,m}^n - U_{l,m}^n) + (U_{l,m-1}^n - U_{l,m}^n) + (U_{l,m+1}^n - U_{l,m}^n).\\]\nAgain, since we are working with images and not some time based problem, we can without loss of generality let $\\Delta t = 1$, so we obtain the finite difference scheme\n\\[U_{l,m}^{n+1} = U_{l,m}^n + (U_{l-1,m}^n - U_{l,m}^n) + (U_{l+1,m}^n - U_{l,m}^n) + (U_{l,m-1}^n - U_{l,m}^n) + (U_{l,m+1}^n - U_{l,m}^n).\\]\nWe will now limit the diffusion near the edges of objects by making the modification\n\\begin{equation}\\label{eq:anisotropic}\n\\begin{aligned}\nU_{l,m}^{n+1} = U_{l,m}^n + & \\lambda \\Big(g(|U_{l-1,m}^n - U_{l,m}^n|)(U_{l-1,m}^n - U_{l,m}^n) \\\\\n\t\t\t&+ g(|U_{l+1,m}^n - U_{l,m}^n|)(U_{l+1,m}^n - U_{l,m}^n) \\\\\n\t\t\t&+ g(|U_{l,m-1}^n - U_{l,m}^n|)(U_{l,m-1}^n - U_{l,m}^n) \\\\\n\t\t\t&+ g(|U_{l,m+1}^n - U_{l,m}^n|)(U_{l,m+1}^n - U_{l,m}^n)\\Big),\n\\end{aligned}\n\\end{equation}\nwhere $\\lambda \\leq \\frac{1}{4}$ is the stability condition.\n\nIn this difference scheme, each term is affected most by nearby terms that are most similar to it, so less diffusion will happen anywhere there is a sharp difference between pixels.\nThis scheme also has the useful property that it does not increase or decrease the total brightness of the image.\nIntuitively, this is because the effect of each point on its neighbors is exactly the opposite effect its neighbors have on it.\n\nTwo commonly used functions for $g$ are $g(x) = e^{-\\left(\\frac{x}{\\sigma}\\right)^2}$ and $g(x) = \\frac{1}{1+\\left(\\frac{x}{\\sigma}\\right)^2}$.\nThe parameter $\\sigma$ allows us to control how much diffusion decreases across boundaries, with larger $\\sigma$ values allowing more diffusion.\nNote that $g(0) = 1$ and $\\displaystyle{\\lim_{x\\to \\infty} g(x) = 0}$ for both functions.\nIn this lab we use $g(x)=e^{-\\left(\\frac{x}{\\sigma}\\right)^2}$.\n\nIt is worth noting that this particular difference scheme is \\textit{not} an accurate finite difference scheme for the version of the diffusion equation we discussed before, but it \\textit{does} accomplish the same thing in the same way.\nAs it turns out, this particular scheme is the solution to a slightly different diffusion PDE, but can still be used the same way.\n\nFor this lab's examples we read in the image using the \\li{imageio.imread} function, and normalized it so that the colors are represented as floating point values between 0 and 1.\nAn image can converted to black and white when it is read by including the argument \\li{as_gray=True}.\n\n\\begin{lstlisting}\nfrom matplotlib import cm, pyplot as plt\nfrom imageio import imread\n\n# To read in an image, convert it to grayscale, and rescale it.\npicture = imread('balloon.png', as_gray=True) * 1./255\n\n# To display the picture as grayscale\nplt.imshow(picture, cmap=cm.gray)\nplt.show()\n\\end{lstlisting}\n\n\\subsection*{Simplifying Calculations}\\label{sec:simp}\n\nYou will notice that the algorithm given in \\ref{eq:anisotropic} does not describe what to do for the edges and corners of $U^{n+1}$.\nIn these cases we will simply eliminate the undefined terms in the algorithm.\nFor example, the top edge equation becomes\n\\begin{align*}\nU_{l,m}^{n+1} = U_{l,m}^n + & \\lambda (g(|U_{l+1,m}^n - U_{l,m}^n|)(U_{l+1,m}^n - U_{l,m}^n) \\\\\n                    & + g(|U_{l,m+1}^n - U_{l,m}^n|)(U_{l,m+1}^n - U_{l,m}^n)) \\\\\n\t\t\t\t\t& + g(|U_{l,m-1}^n - U_{l,m}^n|)(U_{l,m-1}^n - U_{l,m}^n)),\n\\end{align*}\nand top left corner equation becomes\n\\begin{align*}\nU_{l,m}^{n+1} = U_{l,m}^n + & \\lambda (g(|U_{l+1,m}^n - U_{l,m}^n|)(U_{l+1,m}^n - U_{l,m}^n) \\\\\n\t\t\t\t\t& + g(|U_{l,m+1}^n - U_{l,m}^n|)(U_{l,m+1}^n - U_{l,m}^n)).\n\\end{align*}\nEssentially we are only using the terms of the difference scheme that are actually defined.\n\nTo help facilitate this we can create a larger \"padded\" matrix that will make these calculations easy to do.\nThis padded matrix will have an extra row on the top and bottom, and an extra column on either side of the original matrix.\nThese extra rows and columns will duplicate the outer edge of the original matrix.\n\nSo if our original array \\li{X} has shape \\li{m,n}, then our padded array \\li{Y} has shape \\li{m+2,n+2}.\nThe top edge of \\li{Y} will be defined so that \\li{Y[0,1:-1] == X[0,:]} is true, and the rest of the edges of \\li{Y} follow the same pattern.\n\nNotice that this allows us to simply implement the algorithm found in \\ref{eq:anisotropic} without having to make special cases for the edges and corners, since those previously undefined terms become zero when using the padded matrix.\n\n\\begin{problem}\n\\label{prob:anisdiff_bw}\nComplete the following function, by implementing the anisotropic diffusion algorithm found in \\ref{eq:anisotropic} for black and white images.\nUse the padded array technique found in the Simplifying Calculations section.\n\n\nIn your function, use\n\\[g(x) = e^{-\\left(\\frac{x}{\\sigma}\\right)^2}\\]\n\n\\begin{lstlisting}\ndef anisdiff_bw(U, N, lambda_, g):\n    \"\"\" Run the Anisotropic Diffusion differencing scheme\n    on the array U of grayscale values for an image.\n    Perform N iterations, use the function g\n    to limit diffusion across boundaries in the image.\n    Operate on U inplace to optimize performance. \"\"\"\n    pass\n\\end{lstlisting}\nRun the function on \\li{balloon.jpg}.\nShow the original image and the diffused image for $\\sigma = .1$, $\\lambda = .25$, $N = 5, 20, 100$.\n\\end{problem}\n\n\\newpage\n\\vfill\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{balloon_grayscale.jpg}\n\\caption*{original image}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{balloon_grayscale_5.jpg}\n\\caption*{5 iterations with $\\sigma = .1$ and $\\lambda = .25$}\n\\end{minipage}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{balloon_grayscale_20.jpg}\n\\caption*{20 iterations}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{balloon_grayscale_100.jpg}\n\\caption*{100 iterations}\n\\end{minipage}\n\\end{figure}\n\\vfill\n\\clearpage\n\n\\section*{Color Schemes}\n\nColored images can be processed in a similar manner.\nInstead of being represented as a two-dimensional array, colored images are represented as three dimensional arrays.\nThe third dimension is used to store the intensities of each of the standard 3 colors.\nThis diffusion process can be carried out in the exact same way, on each of the arrays of intensities for each color, but instead of detecting edges just in one color, we need to detect edges in any color, so instead of using something of the form $g(|U_{l+1,m}^n - U_{l,m}^n|)$ as before, we will now use something of the form $g(||U_{l+1,m}^n - U_{l,m}^n||)$, where $U_{l+1,m}^n$ and $U_{l,m}^n$ are vectors now instead of scalars.\nThe difference scheme can be treated as an equation on vectors in 3-space and now reads:\n\\begin{align*}\nU_{l,m}^{n+1} = U_{l,m}^n + & \\lambda (g(||U_{l-1,m}^n - U_{l,m}^n||)(U_{l-1,m}^n - U_{l,m}^n) \\\\\n\t\t\t\t\t& + g(||U_{l+1,m}^n - U_{l,m}^n||)(U_{l+1,m}^n - U_{l,m}^n) \\\\\n\t\t\t\t\t& + g(||U_{l,m-1}^n - U_{l,m}^n||)(U_{l,m-1}^n - U_{l,m}^n) \\\\\n\t\t\t\t\t& + g(||U_{l,m+1}^n - U_{l,m}^n||)(U_{l,m+1}^n - U_{l,m}^n))\n\\end{align*}\n\nWhen implementing this scheme for colored images, use the $2$-norm on 3-space, i.e $||x||=\\sqrt{x_1^2+x_2^2+x_3^2}$ where $x_1$, $x_2$, and $x_3$ are the different coordinates of $x$.\n\n\\begin{problem}\nComplete the following function to process a colored image.\nYou may modify your code from the previous problem.\nMeasure the difference between pixels using the $2$-norm.\nUse the corresponding vector versions of the boundary conditions given in Problem \\ref{prob:anisdiff_bw}.\n\n\\begin{lstlisting}\ndef anisdiff_color(U, N, lambda_, sigma):\n    \"\"\" Run the Anisotropic Diffusion differencing scheme\n    on the array U of grayscale values for an image.\n    Perform N iterations, use the function g = e^{-x^2/sigma^2}\n    to limit diffusion across boundaries in the image.\n    Operate on U inplace to optimize performance. \"\"\"\n    pass\n\\end{lstlisting}\nRun the function on \\li{balloons_color.jpg}.\nShow the original image and the diffused image for $\\sigma = .1$, $\\lambda = .25$, $N = 5, 20, 100$.\n\nHint: If you have an $m \\times n \\times 3$ matrix representing the RGB differences of each pixel, then to find a matrix representing the norm of the differences, you can use the following code.\nThis code squares each value and sums along the last axis, and takes the square root.\nIn order to keep the dimension size of the matrix and aid in broadcasting, you must use \\li{keepdims=True}.\n\n\\begin{lstlisting}\n# x is mxnx3 matrix of pixel color values\nnorm = np.sqrt(np.sum(x**2, axis=2, keepdims=True))\n\\end{lstlisting}\n\n\\end{problem}\n\n\\newpage\n\\section*{Noisy Images}\n\n\\begin{problem}\nUse the following code to add noise to your grayscale image.\n\n\\begin{lstlisting}\nfrom numpy.random import randint\n\nimage = imread('balloon.jpg', as_gray=True)\nx, y = image.shape\nfor i in xrange(x*y//100):\n\timage[randint(x),randint(y)] = 127 + randint(127)\n\\end{lstlisting}\n\nRun \\li{anisdiff_bw()} on the noisy image with $\\sigma=.1$, $\\lambda=.25$, $N=20$.\nDisplay the original image and the noisy image.\nExplain why anisotropic diffusion does not smooth out the noise.\n\nHint: Don't forget to rescale.\n\\end{problem}\n\n\n\\section*{Minimum Bias (Optional)}\n\nThis sort of anisotropic diffusion can be very effective, but, depending on the image, it may also smear out edges that do not have large differences between them.\nAn example of this limitation can be seen in Figure \\ref{fig:anisdif_smearing}\n\n\\begin{figure}\n\\begin{minipage}[b]{.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_bw.jpg}\n\\caption*{original image}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_bw_50.jpg}\n\\caption*{after 50 iterations}\n\\end{minipage}\n\\caption{Smearing of similar colors when using an anisotropic diffusion filter.}\n\\label{fig:anisdif_smearing}\n\\end{figure}\n\nAs we can see, after 100 iterations, some of the boundaries between similar shades of grey have smeared unevenly. You may still have to look closely to see it.\nThis can be counteracted somewhat by further decreasing the $\\sigma$ value, but if we have random noise throughout the image, this will not remove it.\nIf we have random static in the image, we can remove this using a modified version of the filter.\nInstead of measuring the rate of change in the picture in each direction, we change each point according to whether or not any of its adjacent points have roughly the same value it has.\nThis is called a minimum-biased filter.\nThis sort of trick is especially good for removing isolated pixels that are different from those around them.\nA very simple way to do this is by taking the average of the two smallest differences between each pixel and its eight neighbors and using that in place of $g$ in the difference scheme above.\nAlong the boundaries, we do not have 8 neighbors for each pixel, but we can get by by just using the pixels we have and eliminating the other terms in the difference scheme, just as we did before.\nThis will make it so that points that neighbor points of similar value will not be changed, while points that do not match their surroundings will be faded to become more like the points surrounding them.\nThis does not have the same symmetrical diffusion as the other scheme, i.e. if one pixel changes, it does not necessarily change its neighboring pixels by the same amount.\nAs long as you leave $\\lambda \\leq \\frac{1}{4}$ and you have scaled the pixels to have floating point values between 0 and 1, the scheme will still remain within its minimum and maximum bounds, since the tendency is always to move points closer to the values of their neighbors.\nTo demonstrate the action of such a filter, we make changes to random pixels in the color version of the same photo and use both filters to remove the noise we have added.\nBelow, we include an example where we have added noise to the color version of that same picture, then used a minimum-biased filter to diminish the noise and the original filter to smooth what remains.\n\n\\begin{problem*}\n(Optional)\n\nImplement the minimum-biased finite difference scheme described above.\nAdd noise to \\li{balloons_color.jpg} using the provided code below, and clean it using your implementation.\nShow the original image, the noised image, and the cleaned image.\n\n\\begin{lstlisting}\nimage = imread('balloons_color.jpg')\nx,y,z = image.shape\nfor dim in xrange(z):\n    for i in xrange(x*y//100):\n        # Assign a random value to a random place\n        image[randint(x),randint(y),dim] = 127 + randint(127)\n\\end{lstlisting}\nHint: Don't forget to rescale.\n\n\\end{problem*}\n\n\\newpage\n\\vfill\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_color.jpg}\n\\caption*{original image}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_noisy.png}\n\\caption*{randomly changed 100000 color values}\n\\end{minipage}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_minbias.jpg}\n\\caption*{300 iterations of a min-biased scheme}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{baloons_resized_both.jpg}\n\\caption*{after 8 additional iterations of the first filter with $\\lambda=.25$ and $\\sigma=.04$.}\n\\end{minipage}\n\\end{figure}\n\\vfill\n\\clearpage\n\n\\nocite{Perona1988,Kim2009}\n", "meta": {"hexsha": "9012aeef87002380d352fccbc825e7b7c3a298ea", "size": 16365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume4/AnisotropicDiffusion/AnisotropicDiffusion.tex", "max_stars_repo_name": "chrismmuir/Labs-1", "max_stars_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 190, "max_stars_repo_stars_event_min_datetime": "2015-07-17T01:57:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T19:16:19.000Z", "max_issues_repo_path": "Volume4/AnisotropicDiffusion/AnisotropicDiffusion.tex", "max_issues_repo_name": "chrismmuir/Labs-1", "max_issues_repo_head_hexsha": "13c23611b90d73b0c2c7d275bce9808f829009f2", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 184, "max_issues_repo_issues_event_min_datetime": "2015-07-16T17:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-06T23:47:14.000Z", "max_forks_repo_path": "Volume4/AnisotropicDiffusion/AnisotropicDiffusion.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": 53.3061889251, "max_line_length": 433, "alphanum_fraction": 0.7316223648, "num_tokens": 4825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7825018245297202}}
{"text": "\n\\subsection{Real numbers aren't closed}\n\n\nDefine as an ordered pair of reals\n\nWe have a complete set of real numbers. Do we need any more?\n\nFor the real numbers, we showed there were functions on the rational numbers which did not have rational solutions. We can similarly show that there are functions on real numbers which do not have real solutions.\n\nConsider:\n\n\\(f(x)=\\sqrt x\\)\n\nThis has no real solution for \\(x<0\\).\n\nWe define:\n\n\\(i:=\\sqrt {-1}\\)\n\n\\(i\\) and \\(-i\\) can be used interchangeably.\n\n\\((-i)^2=(-1)^2i^2=i^2=-1\\)\n\nComplex numbers can be shown more generally as:\n\n\\(a+bi\\)\n\nWe define the complex conjugate of\n\n\\(x=a+bi\\)\n\nAs\n\n\\(\\bar x=a-bi\\)\n\nNote that\n\n\\(x\\bar x=(a+bi)(a-bi)=a^2-b^2\\)\n\nWe can take exponents of imaginary numbers\n\n\\(c^{i\\theta}=a+bi\\)\n\nWe know the opposite is true.\n\n\\(c^{-i\\theta}=a-bi\\)\n\nSo\n\n\\(c^{i\\theta}c^{-i\\theta}=(a+bi)(a-bi)\\)\n\n\\(1=a^2-b^2\\)\n\nThe case where \\(c=e\\) is of particular note. We explore this later.\n\n", "meta": {"hexsha": "a820a255ea43c8ad82d1b23ef5fce0ba52546110", "size": 955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/complex/01-02-closure.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/complex/01-02-closure.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/complex/01-02-closure.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.7543859649, "max_line_length": 212, "alphanum_fraction": 0.6659685864, "num_tokens": 299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404018582426, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7824267641877419}}
{"text": "\n\\subsection{The score}\n\nThe score is defined as the differential of the log-likelihood function with respect to \\(\\theta \\).\n\n\\(V(\\theta, X)=\\dfrac{\\delta }{\\delta \\theta }l(\\theta ; X) \\)\n\n\\(V(\\theta, X)=\\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}\\dfrac{\\delta }{\\delta \\theta}L(\\theta; X) \\)\n\n\\subsection{Expectation of the score}\n\nThe expectation of the score, given the true value of \\(\\theta \\) is:\n\n\\(E[V(X|\\theta)]=\\int V(X|\\theta) dX\\)\n\n\\(E[V(X|\\theta)]=E[\\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}\\dfrac{\\delta }{\\delta \\theta}L(\\theta; X) ]\\)\n\n\\(E[V(X|\\theta)]=\\int \\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}\\dfrac{\\delta }{\\delta \\theta}L(\\theta; X) \\)\n\n\\(E[\\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}]\\)\n\n\\(\\int \\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}P(\\theta )d\\theta \\)\n\nWe can show that the expected value of this is \\(0\\).\n\n\\subsection{Variance of the score}\n\nThe variance of the score is:\n\n\\(var [\\dfrac{\\delta }{\\delta \\theta }l(\\theta ; X) ]\\)\n\n\\(var [\\dfrac{1 }{\\prod_{i=1}^nP(X_i|\\theta )}]\\)\n\n", "meta": {"hexsha": "6850d32002e284675e6752aa26b7e4aa5513c275", "size": 1002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/likelihood/02-01-score.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/likelihood/02-01-score.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/likelihood/02-01-score.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.4705882353, "max_line_length": 106, "alphanum_fraction": 0.6137724551, "num_tokens": 379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172688214137, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7823461573780975}}
{"text": "\\section*{Dimension Reduction}\n\\subsection*{Principal component analysis (PCA)}\nGiven: $D={x_1,...,x_n} \\subset \\mathbb{R}^d$, $1\\leq k \\leq d$\\\\\n$\\Sigma_{d \\times d} = \\frac{1}{n}\\sum_{i=1}^n x_i x_i^T$, $\\mu =\\frac{1}{n}\\sum_{i = 1}^n x_i = 0$\\\\\nSol.:\n$(W,z_1,...,z_n) = argmin \\sum_{i=1}^n||W z_i - x_i||_2^2$,\\\\\nwhere $W \\in \\mathbb{R}^{d \\times k}$ is orthogonal, $z_1,...,z_n\\in\\mathbb{R}^k$ is given by $W = (v_1|...|v_k)$ and $z_i = W^T x_i$ where $\\Sigma = \\sum_{i=1}^d \\lambda_i v_i v_i^T$, $\\lambda_1 \\geq ... \\geq \\lambda_d \\geq 0$\n\n\\subsection*{Kernel PCA}\nFor general $k\\geq1$, the Kernel PC are given by $\\alpha^{(1)},...,\\alpha^{(k)}\\in \\mathbb{R}^n$, where $\\alpha^{(i)} = \\frac{1}{\\sqrt{\\lambda_i}}v_i$ is obtained from: $K = \\sum_{i=1}^n \\lambda_i v_i v_i^T$, $\\lambda_1 \\geq ... \\geq \\lambda_d \\geq 0$\\\\\nGiven this, a new point $x$ is projected as $z \\in \\mathbb{R}^k$:\\\\\n$z_i = \\sum_{j=1}^n\\alpha_j^{(i)}k(x,x_j)$\n\n\\subsection*{Autoencoders}\nTry to learn identity function: $x \\approx f(x;\\theta)$\\\\\n$f(x;\\theta) = f_2(f_1(x;\\theta_1);\\theta_2)$; $f_1:$ en-, $f_2:$ decoder\\\\\nTraining: $ \\underset{w}{\\operatorname{min}}\\sum_{i=1}^n||x_i-f(x_i;W)||_2^2$", "meta": {"hexsha": "bfa3646acfd3ab5bc80db7a206da5ca58e69ae88", "size": 1174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/DimensionReduction.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/DimensionReduction.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/DimensionReduction.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": 69.0588235294, "max_line_length": 253, "alphanum_fraction": 0.6056218058, "num_tokens": 531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172659321806, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7823461529496355}}
{"text": "\\subsubsection{Simulations for Fourier-Collocation Method}\n\t\n\tFollowing the same ideas from the previous section for Fourier-Collocation, we will seek solutions in the space given by $S_N = \\widetilde{B}_N \\cap H^2_p [0, 2 \\pi]$, and using the discrete expansion to the problem (\\ref{IVP_Burgers}) as follows\n\t\\begin{align*}\n\t\t\\mathcal{J}_N u (x, t) =  \\displaystyle \\sum_{|n| \\leq \\frac{N}{2}} \\widetilde{u}_n (t) e^{inx}, \\hspace{2mm}\n\t\t\\widetilde{u}_n (t) =  \\displaystyle \\sum_{j=0}^{2N} u (x_j, t)  e^{-in x_j}\n\t\\end{align*}\n\tor equivalently\n\t\\begin{align*}\n\t\t\\mathcal{J}_N u (x, t) =  \\displaystyle \\sum_{j=0}^{2N} u (x_j, t) \\psi_j (x)\n\t\\end{align*} \n\twhere $x_j$ are given by\n\t\\begin{align*}\n\t\txj = \\frac{2 \\pi j}{2N + 1}, \\hspace{2mm} j = 0, 1, \\dots, 2N.\n\t\\end{align*}\n\t\n\tFor this case, the Fourier-Collocation method will be given by the following problem\n\t\\begin{align}\n\t\\label{Collocation_Nonlinear}\t\n\t\tR_{N} (x_j, t) = \\frac{\\partial u_N}{\\partial t} (x_j, t) - \\frac{\\partial^2 u_N }{\\partial x^2} (x_j, t) + \\frac{1}{2} \\frac{\\partial \\left[ u_N \\right]^2}{\\partial x} (x_j, t) = 0\n\t\\end{align}\n\twhich is a system of $2N + 1$ ordinary differential equations that can be solved using the initial condition given by\n\t\\begin{align*}\n\t\t\\mathcal{J}_N u (x_j, t) =  u_0 (x_j), , \\hspace{2mm} j = 0, 1 \\dots, 2N\n\t\\end{align*}\n\t\n\tBy Setting a vector as follows\n\t\\begin{align*}\n\t\tu_N (t) &= (u_N (x_0 , t), u_N (x_1 , t), \\dots , u_N (x_{2N} , t))^T,\n\t\\end{align*} \n\tand the above system of ordinary differential equations can be written as follows\n\t\\begin{align*}\n\t\t\\frac{d u_N (t)}{dt} =  \\alpha D_N^2 u_N (t) - \\frac{1}{2} D_N u^2_N (t)\n\t\\end{align*}\n\twhere $D_N$ is the matrix given by (\\ref{matrix_DN_odd}), that represents discrete Fourier differentiation, which can be rewrite as\n\t\\begin{align}\n\t\tD_N = \\displaystyle C^{-1} \\Lambda^2_N C\n\t\\end{align}\n\twhere $\\Lambda_N = diag \\{ ik \\}_{|k|\\leq N}$, $C$ represents the discrete Fourier transform and $C^{-1}$ the inverse. \\\\\n\t\n\tNote that the situation here is very different compared to the systems obtained with Fourier-Galerkin. The representation of the non-linear term is more practical to handle with implicit methods, for example, an implicit approach is as follows\n\t\\begin{align*}\n\t\tu_N (t_{i + 1} ) =  C^{-1} \\Lambda_N C u_N (t_{i}) - \\frac{\\Delta t}{2} D_N u^2_N (t_{i+1}) \n\t\\end{align*}\n\t\n\tIt is possible to formulate the above problem as \n\t\\begin{align*}\n\t\tW(u_N (t_{i + 1})) =  C^{-1} \\Lambda_N C u_N (t_{i}) - u_N (t_{i + 1} ) - \\frac{\\Delta t}{2} D_N u^2_N (t_{i+1}), \n\t\\end{align*}\n\tand then we must find $u_N(t_{i + 1})$ that satisfies $W(u_N(t_{i + 1})) = 0$, for example, using the Newton-Raphson method. However, this formulation may require many calculations because the differentiation matrix increases as a function of $N$, and therefore the number of operations. Here we are going to develop a numerical solution that is more practical to implement, implicitly approaching as we did with Fourier-Galerkin on the linear term as follows\n\t\\begin{align*}\n\t\t\\left[I_N + \\frac{\\Delta t}{2} u_{0} \\Lambda_N \\right] u_N (t_{i + 1} ) =  \\displaystyle e^{-\\Delta t \\Lambda^0_N} \\left[ u_N (t_{i}) - \\frac{\\Delta t}{2} D_N u^2_N (t_{i}) \\right]\n\t\\end{align*}\n\twhere $\\Lambda^0_N = diag \\{ \\alpha k^2 + \\frac{ik}{2} u_0 \\}_{|k|\\leq N}$, and solving for $u_N (t_{i + 1})$ gives us\n\t\\begin{align}\n\t\\label{Collocation_Euler}\t\n\t\tu_N (t_{i + 1} ) =  \\displaystyle \\left[I_N + \\frac{\\Delta t}{2} u_{0} \\Lambda_N \\right]^{-1} e^{-\\Delta t \\Lambda^0_N} \\left[ u_N (t_{i})  - \\frac{\\Delta t}{2} D_N u^2_N (t_{i}) \\right]\n\t\\end{align}\n\twhich is very similar to \\ref{Galerkin_Euler}, except for the nonlinear term. \\\\\n\t  \n\tThis formulation will be used for its implementation, and we will present some numerical results that were obtained using the same information that was used with Fourier-Galerkin, the difference is that the calculations are performed in real space using the differentiation matrix $D_N$, and in this case, we have the advantage of approximating the second derivative with $D^2_N = D_N \\cdot D_N$. \\\\\n\t\n\tThe description of the following results is as follows. In the figure \\ref{Collocation_alphas} shows the maximum distance over every $t \\in [0, 100]$ between the exact solution and its approximations given by (\\ref{Collocation_Euler}) for $N = 2^m$, $m = 4, \\dots, 12$, $\\Delta t = 1.0 \\times 10^{-5}$, and different values of $\\alpha$. Furthermore, in Tables \\ref{Collocation_tabla_L2_alpha=1} and \\ref{Collocation_tabla_max_alpha=1}, we can see the numerical values ​​of these distances for different configurations of $N$ and $\\Delta t$. Similarly, in Tables \\ref{Collocation_tabla_L2_alpha=005} and \\ref{Collocation_tabla_max_alpha=005} but for $\\alpha = 0.005$.\n\t\n\t\\newpage\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/alphas_Error_N.png}\n\t\t\\caption{(a) $L^2$-norm between the exact solution and its approximations using Collocation method. (b) Max norm between the exact solution and its approximations.}\n\t\t\\label{Collocation_alphas}\n\t\\end{figure}\n\n\t\\newpage\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Collocation_Euler}) with $\\alpha = 1.0$, $N=2048$, and $\\Delta t = 1.0 \\times 10^{-5}$.}\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=1.png}\n\t\t\\label{Collocation_alpha=1}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Collocation_Euler}) at the time $T = 100$ with $\\alpha = 1.0$, and $\\Delta t = 1.0 \\times 10^{-5}$. (b) Point-wise error of approximation}\n\t\t\\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=1_T=100.png}\n\t\t\\label{Collocation_alpha=1_T}\n\t\\end{figure}\n\t\\begin{table}[H]\n\t\t\\begin{tabular}{lcccc}\n\t\t\t\\toprule\n\t\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 16 & 0.721112    & 0.721112    & 0.721112    & 0.721112    \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 32 & 4.71797 $\\times 10^{-2}$   & 4.72892 $\\times 10^{-2}$   & 4.73004 $\\times 10^{-2}$   & 4.73015 $\\times 10^{-2}$   \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 64 & 1.17954 $\\times 10^{-3}$  & 7.35344 $\\times 10^{-4}$ & 7.27561 $\\times 10^{-4}$ & 7.27283 $\\times 10^{-4}$  \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 128 & 9.43454 $\\times 10^{-4}$ & 1.75152 $\\times 10^{-4}$ & 1.74583 $\\times 10^{-4}$ & 1.74574 $\\times 10^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 256 & 9.43454 $\\times 10^{-4}$ & 1.15509 $\\times 10^{-4}$ & 1.14669 $\\times 10^{-4}$ & 1.14659 $\\times 10^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 512 & 9.43454 $\\times 10^{-4}$ & 9.41793 $\\times 10^{-5}$ & 7.78847 $\\times 10^{-5}$ & 7.78707 $\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 1024 & $\\ast$         & 9.41793 $\\times 10^{-5}$ & 5.32213 $\\times 10^{-5}$ & 5.32019 $\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 2048 & $\\ast$           & $\\ast$           & 3.56779 $\\times 10^{-5}$ & 3.56498 $\\times 10^{-5}$ \\\\\n\t\t\t\\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\\caption{Error using $L^2$-norm with $\\alpha=1.0$}\n\t\t\\label{Collocation_tabla_L2_alpha=1}\n\t\t\\vspace{1cm}\n\t\t\\begin{tabular}{lcccc}\n\t\t\t\\toprule\n\t\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 16 & 0.317617    & 0.317617    & 0.317617    & 0.317617    \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 32 & 1.95279 $\\times 10 ^{-2}$  & 1.96812 $\\times 10 ^{-2}$   & 1.96965 $\\times 10 ^{-2}$   & 1.96981 $\\times 10 ^{-2}$   \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 64 & 6.21793 $\\times 10 ^{-4}$ & 2.9813 $\\times 10 ^{-4}$  & 2.80086 $\\times 10 ^{-4}$ & 2.78934 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 128 & 4.74952 $\\times 10 ^{-4}$ & 1.64746 $\\times 10 ^{-4}$ & 1.6473 $\\times 10 ^{-4}$  & 1.64728 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 256 & 4.74936 $\\times 10 ^{-4}$ & 1.52482 $\\times 10 ^{-4}$ & 1.52467 $\\times 10 ^{-4}$ & 1.52465 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 512 & 4.74936 $\\times 10 ^{-4}$ & 1.47249 $\\times 10 ^{-4}$ & 1.47234 $\\times 10 ^{-4}$ & 1.47232 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 1024 & $\\ast$           & 1.45032 $\\times 10 ^{-4}$ & 1.45017 $\\times 10 ^{-4}$ & 1.45016 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 2048 & $\\ast$           & $\\ast$           & 1.43941 $\\times 10 ^{-4}$ & 1.4394 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\\caption{Error using Max norm with $\\alpha=1.0$}\n\t\t\\label{Collocation_tabla_max_alpha=1}\n\t\\end{table}\n\t\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Collocation_Euler}) with $\\alpha = 0.005$, $N=2048$, and $\\Delta t = 1.0 \\times 10^{-5}$.}\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=0005.png}\n\t\t\\label{Collocation_alpha=005}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Collocation_Euler}) at the time $T = 100$ with $\\alpha = 0.005$, and $\\Delta t = 1.0 \\times 10^{-5}$. (b) Point-wise error of approximation.}\n\t\t\\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=0005_T=100.png}\n\t\t\\label{Collocation_alpha=005_T}\n\t\\end{figure}\n\t%L2\n\t\n\t\\begin{table}[H]\n\t\\begin{tabular}{lcccc}\n\t\t\\toprule\n\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 16 & 1.36189   & 1.35883    & 1.35852   & 1.35849   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 32 & 2.67506   & 2.65305    & 2.65078   & 2.65055   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 64 & 2.50365   & 2.45855    & 2.45432   & 2.45387   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 128 & 2.15795   & 2.0632     & 2.05589   & 2.05497   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 256 & 1.362     & 1.18393    & 1.16697   & 1.16532   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 512 & 0.350775  & 0.304595   & 0.300865  & 0.300499  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 1024 & 0.168462  & 0.140332   & 0.13803   & 0.137804  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 2048 & 6.56161 $\\times 10^{-2}$ & 4.63808 $\\times 10^{-2}$  & 4.49226 $\\times 10^{-2}$ & 4.47813 $\\times 10^{-2}$ \\\\\n\t\t\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{Error using $L^2$-norm with $\\alpha=0.005$}\n\t\\label{Collocation_tabla_L2_alpha=005}\n\t\\vspace{1cm}\n\t\\begin{tabular}{lcccc}\n\t\t\\toprule\n\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 16 & 0.695784 & 0.695659  & 0.695646  & 0.695645 \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 32 & 1.20278  & 1.19418   & 1.19329   & 1.1932   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 64 & 1.22454  & 1.18903   & 1.18507   & 1.18467  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 128 & 1.11999  & 1.0238    & 1.01754   & 1.01701  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 256 & 0.927954 & 0.877058  & 0.872508  & 0.87201  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 512 & 0.664133 & 0.415288  & 0.39714   & 0.395563 \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 1024 & 0.247742 & 0.259451  & 0.260605  & 0.26072  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 2048 & 0.126824 & 0.103297  & 0.107102  & 0.10748  \\\\\n\t\t\\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{Error using Max norm with $\\alpha=0.005$}\n\t\\label{Collocation_tabla_max_alpha=005}\n\t\\end{table}", "meta": {"hexsha": "3c5b15b5832cf127448608e479a28c8566e26280", "size": 11843, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Collocation.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Collocation.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Collocation.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": 58.92039801, "max_line_length": 667, "alphanum_fraction": 0.6379295787, "num_tokens": 4823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7822776694666136}}
{"text": "In \\texttt{MoveUrBody} code there are various implementations: some of them simulate colliding bodies.\nIn this section we try to explain what kind of collisions are used if the implementation considers colliding bodies.\n\n\\subsection{Collisions detection}\nWe choose \\textit{a posteriori} method in order to detect collisions: this is a discrete and easy to implement method.\nWe detect the collisions after they append. \nThis is less expensive in term of computations than \\textit{a priori} method (continuous).\nIn \\texttt{MoveUrBody} we consider that \\textbf{the shape of all the bodies is a sphere}, so two bodies $i$ and $j$ are colliding if:\n\\begin{equation}\t\n\\label{eq:collsDetection}\n\t||\\vec{r_{ij}}|| - (r_i + r_j) \\leq 0,\n\\end{equation}\nwhere $r_i$ and $r_j$ are respectively the radii of body $i$ and body $j$.\n\n\\subsection{Elastic collisions}\nNotation: Throughout this section, $m$ is the mass and $v$ is the velocity.\nBe aware that $v = ||\\vec{v}||$.\nSubscripts $i$ and $j$ distinguish between the two colliding bodies. \nAn apostrophe after a variable means that the value is taken after the collision (called prime; i.e., $v$' is \"$v$ prime\").\\\\\n\nIn \\texttt{MoveUrBody} we consider that \\textbf{all collisions are perfectly elastic}.\nAn elastic collision is a collision in which kinetic energy is conserved. \nThat means no energy is lost as heat or sound during the collision. \nIn the real world, there are no perfectly elastic collisions on an everyday scale of size. \nBut you can get the sense of an elastic collision by imagining a perfect pool ball which doesn't waste any energy when it collides. \nIn an elastic collision, both kinetic energy and momentum are conserved (the total before and after the collision remains the same).\nMomentum is the product of mass and velocity: \n\\begin{equation}\t\n\\label{eq:momentum}\n\t\\vec{p} = m . \\vec{v}.\n\\end{equation}\nThe kinetic energy of an object is one-half times its mass times the square of its velocity:\n\\begin{equation}\t\n\\label{eq:kinetic}\n\tE_k = \\frac{1}{2} . m . v^2.\n\\end{equation}\nNow it is easy to write the conservation of momentum and kinetic energy as two equations:\n\\begin{enumerate}\n\t\\item Conservation of momentum\n\t\t\\begin{equation}\t\n\t\t\\label{eq:momentumCons}\n\t\t\tm_i . \\vec{v_i} + m_j . \\vec{v_j} = m_i . \\vec{v'_i} + m_j . \\vec{v'_j}\n\t\t\\end{equation}\n\t\t\n\t\\item Conservation of kinetic energy\n\t\t\\begin{equation}\t\n\t\t\\label{eq:kineticCons}\n\t\t\t\\frac{1}{2} . m_i . (v_i)^2 + \\frac{1}{2} . m_j . (v_j)^2 = \\frac{1}{2} . m_i . (v'_i)^2 + \\frac{1}{2} . m_j . (v'_j)^2\n\t\t\\end{equation}\n\\end{enumerate}\n\n\\subsubsection{1-Dimensional elastic collisions}\nCombining the two previous equations (Eq.~\\ref{eq:momentumCons} and \\ref{eq:kineticCons}) and doing a lot of algebra gives the final (after collision) velocities of body $i$ and $j$:\n\\begin{equation}\t\n\\label{eq:1DelasticSols}\n\tv'_i = \\frac{v_i(m_i-m_j) + 2.m_j.v_j}{m_i + m_j},~~v'_j = \\frac{v_j(m_j-m_i) + 2.m_i.v_i}{m_j + m_i}.\n\\end{equation}\nThis result allows us to find the velocity of two objects after undergoing a one-dimensional elastic collision. \nWe will use this result later in the 3-dimensional case.\n\n\\subsubsection{3-Dimensional elastic collisions}\nIn previous sub-section (1D elastic collisions) vectors representation was not very important.\nNow in 3D, we will use the component representation of a vector: $\\vec{v} = \\left\\{ v_x, v_y, v_z \\right\\}$.\\\\\n\nWe will follow a 7-step process to find the new velocities of two objects after a collision. \nThe basic goal of the process is to project the velocity vectors of the two objects onto the vectors which are normal (perpendicular) and tangent to the plan of the collision. \nThis gives us a normal component and two tangential components (defining a plan) for each velocity. \nThe tangential components of the velocities are not changed by the collision because there is no force along the tangent plan to the collision surface. \nThe normal components of the velocities undergo a one-dimensional collision, which can be computed using the one-dimensional collision formulas presented above.\nNext the unit normal vector is multiplied by the scalar (plain number, not a vector) normal velocity after the collision to get a vector which has a direction normal to the collision surface and a magnitude which is the normal component of the velocity after the collision. \nThe same is done with the unit tangent vectors and the tangential velocity components. \nFinally the new velocity vectors are found by adding the normal velocity and the two tangential velocity vectors for each object.\n\n\\paragraph{Step 1}\n~\\\\\nFind the unit normal and the two unit tangent vectors.\nThe unit normal vector is a vector which has a magnitude of 1 and a direction that is normal (perpendicular) to the surfaces of the objects at the point of collision. \nThe two unit tangent vectors are vectors with a magnitude of 1 which are forming a tangent plan to the circle's surfaces at the point of collision.\n\t\nFirst find a normal vector.\nThis is done by taking a vector whose components are the difference between the coordinates of the centers of the spheres. \nLet $q_i = \\left\\{q_{ix}, q_{iy}, q_{iz}\\right\\}$, $q_j = \\left\\{q_{jx}, q_{jy}, q_{jz}\\right\\}$ coordinates of the centers of the spheres (it does not matter which spheres is labelled $i$ or $j$; the end result will be the same).\nThen the normal vector $\\vec{n}$ is: \n\\begin{equation*}\t\n\t\\vec{n} = \\left\\{ q_{jx} - q_{ix},~q_{jy} - q_{iy},~q_{jz} - q_{iz}  \\right\\}.\n\\end{equation*}\nNext, we have to find the unit vector of $\\vec{n}$, which we will call $\\vec{un}$. This is done by dividing by the magnitude of $\\vec{n}$:\n\\begin{equation*}\t\n\t\\vec{un} = \\frac{\\vec{n}}{||\\vec{n}||} = \\frac{\\vec{n}}{\\sqrt{n_x^2 + n_y^2 + n_z^2}}.\n\\end{equation*}\nOnce it's done we need to find the two unit tangent vectors which are forming the collision tangent plan.\nThose two unit tangent vectors ($\\vec{ut_1}$ and $\\vec{ut_2}$) are perpendicular to the unit normal vector $\\vec{un}$ and there are also perpendicular between themselves (in order to form a Cartesian coordinate system).\nBefore trying to determine two unit tangent vectors $\\vec{ut_1}$ and $\\vec{ut_2}$ we will try to find a tangent vector $\\vec{t_1}$.\nIf $\\vec{t_1}$ is perpendicular to $\\vec{un}$ then the scalar product (alias dot product) of the two should be null:\n\\begin{equation*}\n\t\\vec{t_1} . \\vec{un} = 0 \\Leftrightarrow\t(t_{1x} . un_x) + (t_{1y} . un_y) + (t_{1z} . un_z) = 0.\n\\end{equation*}\nThe first and easy solution to this previous equation is the null vector $\\vec{0}$ but we obviously want to avoid it.\nAn idea is to fix one of the three components to 0 and an other to 1 in order to determine a perpendicular vector $\\vec{t_1}$ (be aware that there is an infinity of perpendicular vectors to $\\vec{un}$ and we just need to find one of them).\\\\\nIf $un_x \\neq 0$:\n\\begin{equation*}\n\t\\vec{t_1} = \\left\\{ -\\frac{un_y}{un_x}, 1, 0 \\right\\}.\n\\end{equation*}\nIf $un_y \\neq 0$:\n\\begin{equation*}\n\t\\vec{t_1} = \\left\\{ 1, -\\frac{un_x}{un_y}, 0 \\right\\}.\n\\end{equation*}\nIf $un_z \\neq 0$:\n\\begin{equation*}\n\t\\vec{t_1} = \\left\\{ 1, 0, -\\frac{un_x}{un_z} \\right\\}.\n\\end{equation*}\nWe have to choose one of the three previous propositions and be sure to avoid to divide by 0.\nNow we have to normalize $\\vec{t_1}$ in order to find the unitary $\\vec{ut_1}$ vector:\n\\begin{equation*}\n\t\\vec{ut_1} = \\frac{\\vec{t_1}}{||\\vec{t_1}||} = \\frac{\\vec{t_1}}{\\sqrt{t_{1x}^2 + t_{1y}^2 + t_{1z}^2}}.\n\\end{equation*}\nIt remains to determine the $\\vec{ut_2}$ vector, this can be done by computing the cross product (alias vector product) between $\\vec{un}$ and $\\vec{ut_1}$:\n\\begin{equation*}\n\t\\vec{ut_2} = \\vec{un} \\wedge \\vec{ut_1} = \\left\\{ (un_y . ut_{1z} - un_z . ut_{1y}), (un_z . ut_{1x} - un_x . ut_{1z}), (un_x . ut_{1y} - un_y . ut_{1x})\\right\\}.\n\\end{equation*}\n\n\\paragraph{Step 2}\n~\\\\\nCreate the initial (before the collision) velocity vectors, $\\vec{v_i}$ and $\\vec{v_j}$. \nThese are just the $x$, $y$ and $z$ components of the velocities put into vectors: $\\vec{v_i} = \\left\\{ v_{ix}, v_{iy} \\right\\}$ (and similarly for $\\vec{v_j}$). \nNote that this step really isn't necessary if the velocities are already represented as vectors. \nThis step is needed only if the velocities are initially represented as separate $x$, $y$ and $z$ values.\n\n\\paragraph{Step 3}\n~\\\\\nKeep in mind that after the collision the tangential components of the velocities are unchanged and the normal component of the velocities can be found using the one-dimensional collision formulas presented earlier. \nSo we need to resolve the velocity vectors, $\\vec{v_i}$ and $\\vec{v_j}$, into normal and tangential components. \nTo do this, project the velocity vectors onto the unit normal and unit tangent vectors by computing the dot product. \nLet $v_{in}$ be the scalar (plain number, not a vector) velocity of body $i$ in the normal direction. \nLet $v_{it1}$ and $v_{it2}$ be the scalar velocity of body $i$ in the tangential directions. \nSimilarly, let $v_{jn}$, $v_{jt1}$ and $v_{jt2}$ be for body $j$. \nThese values are found by projecting the velocity vectors onto the unit normal and unit tangent vectors, which is done by taking the dot (alias scalar) product:\n\\begin{equation*}\n\tv_{in} = \\vec{v_i}.\\vec{un},~~v_{it1} = \\vec{v_i}.\\vec{ut_1},~~v_{it2} = \\vec{v_i}.\\vec{ut_2},\n\\end{equation*}\n\\begin{equation*}\n\tv_{jn} = \\vec{v_j}.\\vec{un},~~v_{jt1} = \\vec{v_j}.\\vec{ut_1},~~v_{jt2} = \\vec{v_j}.\\vec{ut_2}.\n\\end{equation*}\n\n\\paragraph{Step 4}\n~\\\\\nFind the new tangential velocities (after the collision). \nThis is the simplest step of all. \nThe tangential components of the velocity do not change after the collision because there is no force between the spheres in the tangential direction during the collision. \nSo, the new tangential velocities are simply equal to the old ones:\n\\begin{equation*}\n\tv'_{it1} = v_{it1},~~v'_{it2} = v_{it2},\n\\end{equation*}\n\\begin{equation*}\n\tv'_{jt1} = v_{jt1},~~v'_{jt2} = v_{jt2}.\n\\end{equation*}\n\n\\paragraph{Step 5}\n~\\\\\nFind the new normal velocities. \nThis is where we use the one-dimensional collision formulas (Eq.~\\ref{eq:1DelasticSols}).\nThe velocities of the two spheres along the normal direction are perpendicular to the surfaces\nof the spheres at the point of collision, so this really is a one-dimensional collision:\n\\begin{equation*}\n\tv'_{in} = \\frac{v_{in}(m_i-m_j) + 2.m_j.v_{jn}}{m_i + m_j},\n\\end{equation*}\n\\begin{equation*}\n\tv'_{jn} = \\frac{v_{jn}(m_j-m_i) + 2.m_i.v_{in}}{m_j + m_i}.\n\\end{equation*}\n\n\\paragraph{Step 6}\n~\\\\\nConvert the scalar normal and tangential velocities into vectors. \nThis is easy just multiply the unit normal vector by the scalar normal velocity and you get a vector which has a direction that is normal to the surfaces at the point of collision and which has a magnitude equal to the normal component of the velocity. \nIt is similar for the tangential components:\n\\begin{equation*}\n\t\\vec{v'_{in}} = v'_{in} . \\vec{un},~~\\vec{v'_{it1}} = v'_{it1} . \\vec{ut_1},~~\\vec{v'_{it2}} = v'_{it2} . \\vec{ut_2},\n\\end{equation*}\n\\begin{equation*}\n\t\\vec{v'_{jn}} = v'_{jn} . \\vec{un},~~\\vec{v'_{jt1}} = v'_{jt1} . \\vec{ut_1},~~\\vec{v'_{jt2}} = v'_{jt2} . \\vec{ut_2}.\n\\end{equation*}\n\n\\paragraph{Step 7}\n~\\\\\nFind the final velocity vectors by adding the normal and tangential components for each body:\n\\begin{equation*}\n\t\\vec{v'_i} = \\vec{v'_{in}} + \\vec{v'_{it1}} + \\vec{v'_{it2}},\n\\end{equation*}\n\\begin{equation*}\n\t\\vec{v'_j} = \\vec{v'_{jn}} + \\vec{v'_{jt1}} + \\vec{v'_{jt2}}.\n\\end{equation*}\nNow we have the final (after collision) velocity of each body as a vector.", "meta": {"hexsha": "9ab662ffccffba6b133a247ee2a8e7f15f8d822a", "size": 11580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/murb/sections/collisions.tex", "max_stars_repo_name": "MisterFruits/MUrB", "max_stars_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2017-07-08T16:45:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-23T08:45:01.000Z", "max_issues_repo_path": "doc/murb/sections/collisions.tex", "max_issues_repo_name": "MisterFruits/MUrB", "max_issues_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-09-08T14:35:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-10T07:53:18.000Z", "max_forks_repo_path": "doc/murb/sections/collisions.tex", "max_forks_repo_name": "MisterFruits/MUrB", "max_forks_repo_head_hexsha": "b855332f3eb0fd4a8baa203c28dc0e8e5ce50538", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-09-09T07:08:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-09T07:08:08.000Z", "avg_line_length": 60.3125, "max_line_length": 274, "alphanum_fraction": 0.7207253886, "num_tokens": 3568, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099069987088003, "lm_q2_score": 0.8596637559030337, "lm_q1q2_score": 0.7822140680324641}}
{"text": "\\appendix\n\\chapter{Gaussian Integrals}\n\\section{Basic Gaussians}\nLots of Gaussian integrals happen in this subject. In the interests of not getting stuck, here are the results.\n\nThe basic Gaussian integral for \\( a \\in \\mathbb{R}^+\\) is\n\\[ \\int_\\mathbb{R} e^{-ax^2} \\dd{x} = \\sqrt\\frac{\\pi}{a} \\] which we can then use Feynman's trick of differentiation with respect to the parameter and symmetry arguments to find\n\\begin{align*}\n  \\int_\\mathbb{R} x^n e^{-ax^2} \\dd{x} &= \\begin{cases}\n    \\pdv[\\nicefrac{n}{2}]{a} \\sqrt\\frac{\\pi}{a} & \\text{if \\(n\\) even}\\\\\n    0 & \\text{otherwise}\n  \\end{cases}.\n\\end{align*}\n\nIf there is an \\(e^{bx} \\) power, this may be taken care of using completing the square, given\n\\begin{align*}\n  \\int_\\mathbb{R} e^{-ax^2+bx} \\dd{x} &= \\int_\\mathbb{R} e^{-a(x - \\nicefrac{b}{2a})^2+\\nicefrac{b^2}{4a}} \\dd{x}\\\\\n  &= \\sqrt\\frac{\\pi}{a} e^{\\nicefrac{b^2}{4a}}\n\\end{align*}\nand if we make \\(b = ik\\) this still works, which shows that the fourier transform of a Gaussian is still a Gaussian.\nWith these, Feynman's trick still works, and works even better than before as we now have single \\(x\\) powers to play with --- just keep differentiating.\n\nBy closing one's contour cleverly, one can also solve Fresnel (and similar) integrals with a complex integrand. This gives\n\\begin{align*}\n  \\int_\\mathbb{R} e^{-iax^2+ikx} \\dd{x}\n  &= \\sqrt\\frac{i\\pi}{a} e^{\\nicefrac{-k^2}{4a}}\n\\end{align*}\nwhich is the same as what you get if you just substitute into the previous result, but it's not obvious that that should be the case.\n\n\\section{Nested Gaussians}\\label{sec:nested-gaussians}\nWhen it is said that there are a lot of Gaussians, what makes it all the harder is that they all happen \\emph{all at once}.\n\nFirstly, we look at a double Gaussian, in the form\n\\begin{align*}\n  I &= \\int_{-\\infty}^\\infty e^{\\nicefrac{i}{a} {(x-u)^2}}e^{ \\nicefrac{i}{b}(u-y)^2}\\dd{u}\n\\end{align*}\nwhich is a bit tricky because they're coupled.\nWe use a clever trick, by which we use the translational invariance of these integrals, making a mapping \\( u \\mapsto u + y \\) which makes the whole thing a function of \\( z = x - y \\).\nUtilising this gives us\n\\begin{align*}\n  \\frac{i}{a}(z-u)^2 + \\frac{i}{b}u^2 &= \\frac{i}{a}(z^2 - 2zu + u^2) + \\frac{i}{b}u^2\\\\\n  &= i\\qty(\\frac{1}{a} + \\frac{1}{b})\\qty(u - \\frac{z}{a \\qty(\\frac{1}{a} + \\frac{1}{b})})^2 + \\frac{i}{a}z^2 + i \\frac{z^2}{a^2 \\qty(\\frac{1}{a}  + \\frac{1}{b})}\\\\\n  &= i\\qty(\\frac{1}{a} + \\frac{1}{b})\\qty(u - \\frac{z}{ia \\qty(\\frac{1}{a} + \\frac{1}{b})})^2 + iz^2\\frac{1}{a + b}\n\\end{align*}\nwhich with another translation gives us the really nice answer that \\[ I = e^{i\\frac{z^2}{a + b}} \\sqrt{\\frac{iab\\pi}{a+b}}.\\]\n\nThe $N$-th nested Gaussian, \\( I_N \\), is the logical extension of this, and telescopes rather nicely.\nWe set\n\\begin{align*}\n  I_N &= \\idotsint \\dd{x_1} \\cdots \\dd{x_N} e^{i \\qty[ (x_1 - x_0 )^2 + (x_2 - x_1)^2 + \\ldots + (x_{N+1} - x_{N})^2]}\\\\\n      &= \\sqrt{\\frac{i\\pi}{2}}\\idotsint \\dd{x_2} \\cdots \\dd{x_N} \\exp[i \\qty[ \\nicefrac{1}{2}(x_2 - x_0 )^2 + (x_2 - x_1)^2 + \\ldots + (x_{N+1} - x_{N})^2]]\\\\\n      &= \\sqrt{\\frac{i\\pi}{N+1}}\\exp[i \\nicefrac{(x_{N+1} - x_0)^2}{N+1}]\n\\end{align*}\nwhich is a nice enough statement.\n\n\\chapter{Functional Derivatives}\nA functional derivative generalises the derivative from\n\\begin{align*}\n  \\pdv{J_i}\\sum_j J_j x_j &= x_i & \\pdv{J_i} &= \\delta_{ij}\n\\end{align*}\nto cover a smooth function on a continuous domain such that\n\\begin{align*}\n  \\pdv{J(t)}J(t^\\prime) &= \\delta(t-t^\\prime) & \\fdv{J(t)}  \\int_{t_a}^{t_b} J(t^\\prime) x(t^\\prime) \\dd{t^\\prime} &= \\int_{t_a}^{t_b} \\delta(t - t^\\prime) x(t^\\prime) \\dd{t^\\prime}\\\\\n  &&&= \\begin{cases}\n    x(t) & t_a < t^\\prime < t_b\\\\\n    0 & \\text{otherwise}.\n  \\end{cases}\n\\end{align*}\n\nFunctional derivatives have the following properties:\n\\begin{description}\n  \\item [Linearity] \\[ \\fdv{(\\lambda F + \\mu G)[\\rho]}{\\rho(x)} = \\lambda \\fdv{F[\\rho]}{\\rho(x)} + \\mu \\fdv{G[\\rho]}{\\rho(x)}\\]\n  for \\(\\lambda, \\mu\\) constant,\n  \\item [Chain Rule] \\[ \\fdv{(FG)[\\rho]}{\\rho} = \\fdv{F[\\rho]}{\\rho(x)}G[\\rho] + F[\\rho]\\fdv{F[\\rho]}{\\rho(x)} \\]\n  \\item [Product Rules] These are logical. Look them up if you need them.\n\\end{description}\n\nWe can use an equivalent of the Euler-Lagrange equation to find the functional derivative, \\[ \\fdv{F}{\\rho(r)} = \\pdv{f}{\\rho} - \\partial^\\mu \\pdv{f}{\\qty(\\partial^\\mu \\rho)}.\\]\n", "meta": {"hexsha": "da4dcc2507668484be07db6236ed54802e559d57", "size": 4373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "includes/appendices.tex", "max_stars_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_stars_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "includes/appendices.tex", "max_issues_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_issues_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "includes/appendices.tex", "max_forks_repo_name": "penguinoneshaw/PHYS11019-quantum-theory", "max_forks_repo_head_hexsha": "3d03b83f055a3a71aa00c5f6753a008754f1d3a7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.3544303797, "max_line_length": 185, "alphanum_fraction": 0.635261834, "num_tokens": 1642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.9019206771886166, "lm_q1q2_score": 0.7819974734299665}}
{"text": "% arara: pdflatex\n% arara: pdflatex\n\n\\documentclass[letterpaper,10pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{siunitx}\n\\usepackage{physics}\n\\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}\n\n\\begin{document}\n\n\\section{Introduction}\n\nSimpson's rule is a method for performing numerical integration. While there are several different approximations under the name ``Simpson's rule'', the most\ncommon version, Simpson's 1/3 rule, is equivalent fitting a 2'nd degree polynomial to three points so that the integration can be carried out analytically.\nIt is usually written as:\n\\begin{equation}\n  \\label{eq:simpsons}\n  \\int_a^b f(x) \\dd x \\approx \\frac{b-a}{6}\\left[ f(a) + 4f\\qty(\\frac{a+b}{2}) + f(b)\\right]\n\\end{equation}\nThis can be extended to larger domains with more function evaluations by breaking the domain into sub-domains and applying\n\\ref{eq:simpsons} to each.\nHowever, equation \\ref{eq:simpsons} assumes that the function $f(x)$ is evaluated at equally spaced points. If we have a discretized\nfunction that is \\emph{not} evaluated at equally spaced points, equation \\ref{eq:simpsons} cannot be used.\n\n\\section{Generalizing to Non-Uniform Spacing}\n\nTo generalize equation \\ref{eq:simpsons} to non-equally spaced points, we just need to perform the polynomial fit using non-equally spaced points an\nperform the integration on the new fit. Using Lagrange polynomial interpolation, we have\n\\begin{equation}\n  f(x) \\approx f(x_1) \\frac{ (x-x_2)(x-x_3) }{ (x_1 - x_2)(x_1 - x_3) }\n             + f(x_2) \\frac{ (x-x_1)(x-x_3) }{ (x_2 - x_1)(x_2 - x_3) }\n             + f(x_3) \\frac{ (x-x_1)(x-x_2) }{ (x_3 - x_1)(x_3 - x_2) }\n\\end{equation}\nwhere $x_1$, $x_2$, and $x_3$ are the points at which the function is evaluated.\n\nThe Lagrange basis polynomials can be written as\n\\begin{equation}\n  \\label{eq:lagrange}\n  l(x,A,B,C) = \\frac{(x-A)(x-B)}{(C-A)(C-B)}\n\\end{equation}\nand we can rewrite the interpolation as\n\\begin{equation}\n  f(x) \\approx\n    f(x_1) l(x,x_2,x_3,x_1)\n  + f(x_2) l(x,x_1,x_3,x_2)\n  + f(x_3) l(x,x_1,x_2,x_3)\n\\end{equation}\n\n\\subsection{Method 1: Integrating the Lagrange polynomials directly}\nIntegrating the Lagrrange basis polynomials from $a$ to $b$ gives\n\\begin{equation}\n  L(A,B,C,a,b) = \\int_a^b l(x,A,B,C) \\dd x = \\frac{1}{(C-A)(C-B)} \\left[ \\frac{1}{3} \\qty(b^3 - a^3) + \\frac{A+B}{2}\\qty(b^2 - a^2) + AB(b-a)  \\right]\n\\end{equation}\nand the integral of $f(x)$ is then approximated as\n\\begin{equation}\n  \\int_a^b f(x) \\dd x \\approx\n    f(x_1) L(x_2,x_3,x_1,a,b)\n  + f(x_2) L(x_1,x_3,x_2,a,b)\n  + f(x_3) L(x_1,x_2,x_3,a,b)\n\\end{equation}\n\nTo reproduce equation \\ref{eq:simpsons}, we let $x_1 = a$, $x_2 = \\frac{a+b}{2}$, and $x_3 = b$. For example,\n\\begin{align}\n  L(x_2,x_3,x_1,a,b) = \\frac{1}{(a-\\frac{a+b}{2})(a-b)} \\qty[\\frac{1}{3} \\qty(b^3 - a^3) + \\frac{\\frac{a+b}{2} + b}{2}\\qty(b^2 - a^2) + \\frac{a+b}{2}b\\qty(b-a) ]\n\\end{align}\napparently reduces to $\\frac{b-a}{6}$...\n\n\n\\subsection{Method 2: Integrating the Lagrange polynomials by parts}\n\nIntegrating the Lagrange polynomials by parts gives\n\\begin{align}\n  L(A,B,C,a,b) &= \\int_a^b l(x,A,B,C) \\dd x = \\frac{1}{(C-A)(C-B)} \\int_a^b (x - A)(x - B) \\dd x  \\\\\n  \\dv{x} \\qty[\\frac{1}{2}(x-A)(x-B)^2] &= \\frac{1}{2}(x - B)^2 + (x-A)(x-B) \\\\\n  \\int (x-A)(x-B) \\dd x &= \\frac{1}{2}(x-A)(x-B)^2 - \\frac{1}{2} \\int (x-B)^2 \\dd x \\\\\n  L(A,B,C,a,b) &= \\left. \\frac{1}{(C-A)(C-B)} \\qty[ \\frac{1}{2}(x-A)(x-B)^2 - \\frac{1}{6} (x-B)^3] \\right|_a^b\n\\end{align}\n\n\\subsection{Interpolating to uniform spacing}\n\nSince Simpon's rule is derived by interpolating a function with a polynomial and integrating, we can use the polynomial to interpolate to the\nmedpoint of $[a,b]$ and just use the usual formula. Given the function at points $x_1$, $x_2$, and $x_3$, the interpolated function value at $\\frac{x_1 + x_2}{2}$ is\n\\begin{equation}\n  f\\qty(\\frac{x_1 + x_3}{2}) \\approx \n  f(x_1) l( \\frac{x_1+x_2}{2}, x_2,x_3,x_1)\n  + f(x_2) l( \\frac{x_1+x_2}{2}, x_1,x_3,x_2)\n  + f(x_3) l( \\frac{x_1+x_2}{2}, x_1,x_2,x_3)\n\\end{equation}\nOnce we interpolate to the midpoint, we can use equation \\ref{eq:simpsons}.\n\n\n\n\\end{document}\n\n", "meta": {"hexsha": "eae97588e9ffc7ead4ca428d001e1f02c009299d", "size": 4170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/writeups/SimpsonsRule/NonUniformGrids.tex", "max_stars_repo_name": "CD3/libIntegrate", "max_stars_repo_head_hexsha": "44067c9c579b79efa20fc4320ffaafa11224ec9f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 11, "max_stars_repo_stars_event_min_datetime": "2019-05-20T00:46:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T14:29:46.000Z", "max_issues_repo_path": "doc/writeups/SimpsonsRule/NonUniformGrids.tex", "max_issues_repo_name": "CD3/libIntegrate", "max_issues_repo_head_hexsha": "44067c9c579b79efa20fc4320ffaafa11224ec9f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-09-27T02:00:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T04:28:02.000Z", "max_forks_repo_path": "doc/writeups/SimpsonsRule/NonUniformGrids.tex", "max_forks_repo_name": "CD3/libIntegrate", "max_forks_repo_head_hexsha": "44067c9c579b79efa20fc4320ffaafa11224ec9f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-04-30T02:28:48.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-03T02:43:05.000Z", "avg_line_length": 42.1212121212, "max_line_length": 165, "alphanum_fraction": 0.66882494, "num_tokens": 1588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.9019206752113866, "lm_q1q2_score": 0.7819974686168604}}
{"text": "\\section{Vectors}\n\\subsection{Basics}\n\\emph{Vectors} are the fundamental objects of linear algebra: the entire field revolves around manipulation of vectors. In this chapter we deal with the so-called \\emph{real vectors}, which can be be defined in a geometric way:\n\n\\begin{definition}{Real vectors}{real vectors}\n\tA \\textit{real vector} is an object with a \\emph{magnitude} (also called \\emph{norm}) and a \\emph{direction}.\n\\end{definition}\n\nIn this chapter we refer to real vectors simply as \\textit{vectors}.\n\n\\begin{example}{Real vectors}{real vectors}\n\tThe following are all vectors in 2-dimensional space depicted as arrows:\n  \n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\draw[vector, xred] (0,0) -- ++(2,3);\n\t\t\\draw[vector, xblue] (-1,0) -- ++(-1,2);\n\t\t\\draw[vector, xgreen] (0,-1) -- ++(-3,0);\n\t\t\\draw[vector, xpurple] (2,0) -- ++(-1,-3);\n\t\t\\draw[vector, xorange] (-4,2) -- ++(0,-4);\n\t\t\\draw[vector, black] (-7,1) -- ++(1,-1);\n\t\\end{tikzpicture}\n\\end{example}\n\nVectors are usually denoted in one of the following ways:\n\n\\begin{descitemize}\n\t\\setlength\\itemsep{1em}\n\t\\addtolength{\\itemindent}{5mm}\n\t\\item[Arrow above letter] $\\vec{u},\\ \\vec{v},\\ \\vec{x},\\ \\vec{a},\\ \\dots$\n\t\\item[Bold letter] $\\bm{u},\\ \\bm{v},\\ \\bm{x},\\ \\bm{a},\\ \\dots$\n\t\\item[Bar below letter] $\\underline{u},\\ \\underline{v},\\ \\underline{x},\\ \\underline{a},\\ \\dots$\n\\end{descitemize}\n\nIn this book we use the first notation style, i.e. an arrow above the letter. In addition vectors will almost always be denoted using lowercase Lating script.\n\nWhen discussing vectors in a single context, we always consider them starting at the same point, called the \\emph{origin}, and \\emph{translating} (moving) vectors around in space does not change their properties: only their norms and directions matter.\n\n\\begin{example}{Real vectors}{real vectors}\n\tThe vectors from the previous translated (moved) such that their origins all lie on the same point:\n  \n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\draw[vector, xred] (0,0) -- ++(2,3);\n\t\t\\draw[vector, xblue] (0,0) -- ++(-1,2);\n\t\t\\draw[vector, xgreen] (0,0) -- ++(-3,0);\n\t\t\\draw[vector, xpurple] (0,0) -- ++(-1,-3);\n\t\t\\draw[vector, xorange] (0,0) -- ++(0,-4);\n\t\t\\draw[vector, black] (0,0) -- ++(1,-1);\n\t\t\\fill (0,0) circle (0.05);\n\t\\end{tikzpicture}\n\\end{example}\n\nA vector can be scaled by a real number $\\alpha$: when this happens, its norm is multiplied by $\\alpha$ while its direction stays the same. We call $\\alpha$ a \\emph{scalar}.\n\n\\begin{example}{Scaling vectors}{scaling vectors}\n\tThe following vector $\\vec{v}$ scaled by different scalars $\\alpha=2,2.5,-1,-2$:\n\n\t\\centering\n\t\\begin{tikzpicture}[every node/.style={midway, left, xshift=-2mm}]\n\t\t\\Large\n\t\t\\draw[vector, xred] (0,0) -- ++(1.5,1) node {$\\vec{v}$};\n\t\t\\draw[vector, xblue] (2,0) -- ++(3,2) node {$2\\cdot \\vec{v}$};\n\t\t\\draw[vector, xpurple] (4.5,0) -- ++(3.75,2.5) node {$2.5\\cdot \\vec{v}$};\n\t\t\\draw[stealth-, thick, xgreen!85!black] (7.5,0) -- ++(1.5,1) node {$-1\\cdot \\vec{v}$};\n\t\t\\draw[stealth-, thick, black] (9.5,0) -- ++(3,2) node {$-2\\cdot \\vec{v}$};\n\t\\end{tikzpicture}\n\\end{example}\n\n\\begin{note}{Negative scale}{negative scale}\n\tAs can be seen in the example above, when scaling a vector by a negative amount its direction reverses. However, we consider two opposing direction (i.e. directions that are $\\ang{180}$ apart) as being the same direction.\n\\end{note}\n\nIn this book we use the following notation for the norm of a vector $\\vec{v}$: $\\norm{v}$.\n\nA vector $\\vec{v}$ with norm $\\norm{v}=1$ is called a \\emph{unit vector}, and is usually denoted by replacing the arrow symbol by a hat symbol: $\\hat{v}$. Any vector (except $\\vec{0}$) can be scaled into a unit vector by scaling  the vector by $1$ over its own norm, i.e.\n\\begin{equation}\n\t\\hat{v} = \\frac{1}{\\norm{v}}\\vec{v}.\n\t\\label{eq:normalized vector}\n\\end{equation}\nThe result of normalization is a vector of unit norm which points in the same direction of the original vector.\n\nTwo vectors can be added together to yield a third vector: $\\vu+\\vv=\\vw$. To find $\\vw$ we use the following procedure (depicted in \\autoref{fig:vector addition geometric}):\n% The items need to be typeset without the chapter number\n\\begin{enumerate}\n\t\\item Move (translate) $\\vv$ such that its origin lies on the head of $\\vu$.\n\t\\item The vector $\\vw$ is the vector drawn from the origin of $\\vu$ to the head of $\\vv$.\n\\end{enumerate}\n\n\\renewcommand\\thesubfigure{\\arabic{subfigure}}\n\\begin{figure}[h]\n\t\\centering\n\t \\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\coordinate (O) at (0,0);\n\t\t\t\\coordinate (u) at (-2,1);\n\t\t\t\\coordinate (v) at (1.5,1);\n\t\t\t\\coordinate (w) at ($(u)+(v)$);\n\t\t\t\\draw[vector, xred] (O) -- (u) node[above left] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (O) -- (v) node[above right] {$\\vec{v}$};\n\t\t\t\\draworigin\n\t\t\\end{tikzpicture}\n\t\t\\caption{The vectors $\\vu$ and $\\vv$.}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[vector, xred] (O) -- (u) node[above left] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (u) -- ++(v) node[above right] {$\\vec{v}$};\n\t\t\t\\draworigin\n\t\t\\end{tikzpicture}\n\t\t\\caption{Translating $\\vv$ such that its origin lies at the head of $\\vu$.}\n\t\\end{subfigure}\n\n\t\\vspace{3em}\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[vector, xred] (O) -- (u) node[above left] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (u) -- ++(v) node[above right] {$\\vec{v}$};\n\t\t\t\\draw[vector, xpurple] (O) -- (w) node[right, yshift=-2mm] {$\\vec{w}$};\n\t\t\t\\draworigin\n\t\t\\end{tikzpicture}\n\t\t\\caption{Drawing the vector $\\vw$ from the origin to the head of $\\vv$.}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[vector, xred] (O) -- (u) node[above left] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (O) -- (v) node[above right] {$\\vec{v}$};\n\t\t\t\\draw[vector, xpurple] (O) -- (w) node[above] {$\\vec{w}$};\n\t\t\t\\draworigin\n\t\t\\end{tikzpicture}\n\t\t\\caption{Showing all three vectors.}\n\t\\end{subfigure}\n\t\\caption{Vector addition.}\n\t\\label{fig:vector addition geometric}\n\\end{figure}\n\nThe addition of vectors as depicted here is commutative, i.e. $\\vu+\\vv = \\vv+\\vu$. This can be seen by using the \\emph{parallogram law of vector addition} as depicted in \\autoref{fig:parallelogram}: drawing the two vectors $\\vu, \\vv$ and their translated copies (each such that its origin lies on the other vector's head) results in a parallelogram.\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\draw[vector, xred] (O) -- (u) node[above left] {$\\vec{u}$};\n\t\t\\draw[vector, xblue] (O) -- (v) node[above right] {$\\vec{v}$};\n\t\t\\draw[vector, xred] (v) -- ++(u);\n\t\t\\draw[vector, xblue] (u) -- ++(v);\n\t\t\\draw[vector, xpurple] (O) -- (w) node[above] {$\\vec{w}$};\n\t\t\\draworigin\n\t\\end{tikzpicture}\n\t\\caption{The parallogram law of vector addition.}\n\t\\label{fig:parallelogram}\n\\end{figure}\n\nAn important vector is the \\emph{zero-vector}, denoted as $\\vec{0}$. The zero-vector has a unique property: it is neutral in respect to vector addition, i.e. for any vector $\\vec{v}$,\n\\begin{equation}\n\t\\vec{v} + \\vec{0} = \\vec{v}.\n\t\\label{eq:zero-vector}\n\\end{equation}\n(we also say that $\\vec{0}$ is the \\emph{additive identity} in respect to vectors.)\n\nAny vector $\\vec{v}$ always has an \\emph{opposite} vector, denoted $-\\vec{v}$. The addition of a vector and its opposite always result in the zero-vector, i.e.\n\\begin{equation}\n\t\\vec{v} + \\left( -\\vec{v} \\right) = \\vec{0}.\n\t\\label{eq:opposite vector}\n\\end{equation}\n\n\\subsection{Components}\nVectors can be decomposed to their components, the number of which depends on the dimension of space we're using: 2-dimensional vectors can be decomposed into 2 components, 3-dimensional vectors can be decomposed into 3 components, etc. To decompose a vector, say $\\vec{v}$, we first choose a coordinate system: the most commonly used system, and the one we will use for most of this chapter, is the Cartesian coordinate system. We place the vector in the coordinate system such that its origin lies at the origin of the system. We then draw a perpendicular line from its head to each of the axes in the system (see \\autoref{fig:vector components}), the point of interception on each axis is the component of the vector in that axis (we label these points $v_{x},v_{y},v_{z}$ in the case of 2- or 3-dimensional spaces, and generally $v_{1},v_{2},v_{3},\\dots$). The vector can then be written as a column using these components:\n\\begin{equation}\n\t\\vec{v} = \\colvec{v_{1};v_{2};\\vdots;v_{n}}.\n\t\\label{eq:column vector}\n\\end{equation}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}[every node/.style={font=\\large}]\n\t\t\\pgfmathsetmacro{\\ux}{2.5}\n\t\t\\pgfmathsetmacro{\\uy}{2}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=8cm, height=8cm,\n\t\t\txmin=-1, xmax=3,\n\t\t\tymin=-1, ymax=3,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t\textra x ticks={\\ux},\n\t\t\textra x tick labels={$u_{x}$},\n\t\t\textra x tick style={color=xred},\n\t\t\textra y ticks={\\uy},\n\t\t\textra y tick labels={$u_{y}$},\n\t\t\textra y tick style={color=xred},\n\t\t\t]\n\t\t\t\\draw[dashed, black!50] (0,\\uy) -- (\\ux,\\uy) -- (\\ux,0);\n\t\t\t\\draw (\\ux,0.1) -- ({\\ux+0.1},0.1) -- ({\\ux+0.1},0);\n\t\t\t\\draw (0.1,\\uy) -- (0.1,{\\uy+0.1}) -- (0,{\\uy+0.1});\n\t\t\t\\draw[vector, xred] (0,0) -- (\\ux,\\uy) node[above] {$\\vec{u}=\\colvec{u_{x};u_{y}}$};\n\t\t\t\\draw[fill] (0,0) circle[radius=2pt];\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Placing a 2-dimensional vector $\\vu$ on the 2-dimensional Cartesian coordinate system, showing its $x$- and $y$-components.}\n\t\\label{fig:vector components}\n\\end{figure}\n\n\\begin{note}{Order of components}{}\n\tThe order of the components of a vector is important, and should always be consistent. In the case of $2$- and $3$-dimensional the order is always $v_{x},v_{y},v_{z}$.\n\\end{note}\n\n\\begin{example}{Vector components in two dimensions}{}\n\tThe following five $2$-dimensional vectors are decomposed each into its $x$- and $y$-components:\n\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=9cm, height=9cm,\n\t\t\txmin=-3, xmax=3,\n\t\t\tymin=-3, ymax=3,\n\t\t\tminor tick num=1,\n\t\t\t]\n\t\t\t\\veccomp{u}{-2}{1}{xred}\n\t\t\t\\veccomp{v}{1.5}{1}{xblue}\n\t\t\t\\veccomp{w}{-0.5}{2}{xpurple}\n\t\t\t\\veccomp{a}{0.5}{-2}{xgreen}\n\t\t\t\\veccomp{b}{-1}{-2}{xorange}\n\t\t\t\\draw[fill] (0,0) circle[radius=2pt];\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{example}\n\n\\begin{example}{Vector components in three dimensions}{}\n\tThe following $3$-dimensional vector is decomposed into its $x$-, $y$- and $z$-components:\n\t(THIS NEEDS TO BE IMPROVED AND FINISHED)\n\n\t\\centering\n\t\\tdplotsetmaincoords{75}{120}\n\t\\begin{tikzpicture}[\n\t\t\tscale=5,\n\t\t\ttdplot_main_coords,\n\t\t\tvector guide/.style={dashed, thick, gray}\n\t\t]\n\t\t%standard tikz coordinate definition using x, y, z coords\n\t\t\\coordinate (O) at (0,0,0);\n\n\t\t%tikz-3dplot coordinate definition using x, y, z coords\n\t\t\\pgfmathsetmacro{\\ax}{0.8}\n\t\t\\pgfmathsetmacro{\\ay}{0.8}\n\t\t\\pgfmathsetmacro{\\az}{0.8}\n\n\t\t\\coordinate (P) at (\\ax,\\ay,\\az);\n\n\t\t%draw axes\n\t\t\\draw[vector] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};\n\t\t\\draw[vector] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};\n\t\t\\draw[vector] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};\n\n\t\t%draw a vector from O to P\n\t\t\\draw[vector, xred] (O) -- (P);\n\n\t\t%draw guide lines to components\n\t\t\\draw[vector guide]         (O) -- (\\ax,\\ay,0);\n\t\t\\draw[vector guide] (\\ax,\\ay,0) -- (P);\n\t\t\\draw[vector guide]         (P) -- (0,0,\\az);\n\t\t\\draw[vector guide] (\\ax,\\ay,0) -- (0,\\ay,0);\n\t\t\\draw[vector guide] (\\ax,\\ay,0) -- (0,\\ay,0);\n\t\t\\draw[vector guide] (\\ax,\\ay,0) -- (\\ax,0,0);\n\t\t\\node[tdplot_main_coords, anchor=east] at (\\ax,-0.05,0) {$v_{x}$};\n\t\t\\node[tdplot_main_coords, anchor=west] at (-0.05,\\ay,0) {$v_{y}$};\n\t\t\\node[tdplot_main_coords, anchor=south] at (0.075,0,\\az){$v_{z}$};\n\t\\end{tikzpicture}\n\\end{example}\n\nThe column form of a vector is essentially equivalent to an order list of $n$ real numbers, i.e. $(v_{1},v_{2},\\dots,v_{n})$. Why then are we using the column form and not the list form (mostly known as \\emph{row vectors})? In fact, we could use either form - and even using both interchangeably - and with only minor adjusments the entire chapter would stay the same as it is now. However, there are some advantages of using only a single form, and consider the other form as a different object altogether. This idea will become clear in future chapters, when discussing \\emph{covariant vectors}, \\emph{contravarient vectors}, and \\emph{tensors}. For now, we stick with the column form of vectors to stay consistent with common notation.\n\nHowever, the row form of vectors highlights the space in which they exist: $n$-dimensional vectors live in a space we call $\\Rs{n}$. Recall from \\autoref{chapter:intro} that the set $\\Rs{n}$ is a Cartesian product made up of $n$ times the set of real numbers, i.e.\n\\begin{equation}\n\t\\Rs{n} = \\underbrace{\\mathbb{R} \\times \\mathbb{R} \\times \\cdots \\times \\mathbb{R}}_{n}.\n\t\\label{eq:Rn}\n\\end{equation}\n\nEach member of this set is a list of $n$ real numbers, and their order inside the list matters - very similar to vectors, be they in row or column form. For this reason, we refer to $\\Rs{n}$ as the space of $n$-dimensional real vectors. As mentioned, in this chapter we use $\\Rs{2}$ (the 2-dimensional real space) and $\\Rs{3}$ (the 3-dimensional real space) for most ideas and examples.\n\nLooking at vectors in $\\Rs{2}$, it is rather straight-forward to calculate their norm: since the origin, the head of the vector and the point $v_{x}$ form a right triangle (see \\autoref{fig:norm 2D vector}), we can use the Pythagorean theorem to calculate the norm of the vector, which is equal to the hypotenous of said triangle:\n\\begin{equation}\n\t\\norm{v} = \\sqrt{v_{x}^{2} + v_{y}^{2}}.\n\t\\label{eq:2D vector norm}\n\\end{equation}\n\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{tikzpicture}[every node/.style={font=\\large}]\n\t\t\\pgfmathsetmacro{\\vx}{2.5}\n\t\t\\pgfmathsetmacro{\\vy}{2}\n\t\t\\pgfmathsetmacro{\\an}{atan(\\vy/\\vx)}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=9cm, height=9cm,\n\t\t\txmin=-1, xmax=3,\n\t\t\tymin=-1, ymax=3,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t\t]\n\t\t\t\\fill[xgreen, fill opacity=0.07] (0,0) -- (\\vx,\\vy) -- (\\vx,0);\n\t\t\t\\draw[dashed, black!50] (\\vx,\\vy) -- (\\vx,0);\n\t\t\t\\draw (\\vx,0.1) -- ({\\vx-0.1},0.1) -- ({\\vx-0.1},0);\n\t\t\t\\draw[vector, black] (0,0) -- node[midway, above, rotate=\\an] {$\\norm{v}=\\sqrt{v_{x}^{2}+v_{y}^{2}}$} (\\vx,\\vy) node[above] {$\\vec{v}=\\colvec{v_{x};v_{y}}$};\n\t\t\t\\draw[fill] (0,0) circle[radius=2pt];\n\t\t\t\\draw[xgreen, ultra thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t\t(0,0) -- (\\vx,0) node[midway, below, yshift=-7pt]{$v_{x}$};\n\t\t\t\\draw[xgreen, ultra thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t\t(\\vx,0) -- (\\vx,\\vy) node[midway, right, xshift=7pt]{$v_{y}$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Calculating the norm of a 2-dimensional column vector.}\n\t\\label{fig:norm 2D vector}\n\\end{figure}\n\nIn $\\Rs{3}$ the norm of a vector $\\vec{v}$ is similarily\n\\begin{equation}\n\t\\norm{v} = \\sqrt{v_{x}^{2} + v_{y}^{2} + v_{z}^{2}}.\n\t\\label{eq:norm 3D vector}\n\\end{equation}\n\n\\begin{challenge}{Norm of a 3D vector}{}\n\tShow why \\autoref{eq:norm 3D vector} is valid, by calculating the length $AB$ in the following figure, depicting a box of sides $\\textcolor{xblue}{\\bm{a}},\\textcolor{xgreen}{\\bm{b}}$ and $\\textcolor{xpurple}{\\bm{c}}$:\n\n\t\\centering\n\t\\begin{tikzpicture}[every path/.style={very thick}, node distance=1mm]\n\t\t\\pgfmathsetmacro{\\xside}{4};\n\t\t\\pgfmathsetmacro{\\yside}{2};\n\t\t\\pgfmathsetmacro{\\zside}{3};\n\n\t\t\\coordinate (1) at (0,0,0);\n\t\t\\coordinate (2) at (\\xside,0,0);\n\t\t\\coordinate (3) at (0,\\yside,0);\n\t\t\\coordinate (4) at (\\xside,\\yside,0);\n\t\t\\coordinate (5) at (0,0,\\zside);\n\t\t\\coordinate (6) at (\\xside,0,\\zside);\n\t\t\\coordinate (7) at (0,\\yside,\\zside);\n\t\t\\coordinate (8) at (\\xside,\\yside,\\zside);\n\n\t\t\\draw (1) -- (2);\n\t\t\\draw (1) -- (3);\n\t\t\\draw (1) -- (5);\n\t\t\\draw[densely dotted, red] (5) -- (4);\n\t\t\\draw (5) -- (7);\n\t\t\\draw (6) -- (8);\n\t\t\\draw (2) -- (4);\n\t\t\\draw (2) -- (6);\n\t\t\\draw (3) -- (4);\n\t\t\\draw (3) -- (7);\n\t\t\\draw (4) -- (8);\n\t\t\\draw (5) -- (6);\n\t\t\\draw (7) -- (8);\n\n\t\t\\node[left=of 5] {$A$};\n\t\t\\node[above=of 4] {$B$};\n\n\t\t\\draw[xblue, thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t(5) -- (6) node[midway, below, yshift=-5pt]{$a$};\n\t\t\\draw[xgreen, thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t(6) -- (2) node[midway, right, xshift=2pt, yshift=-8pt]{$b$};\n\t\t\\draw[xpurple, thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t(2) -- (4) node[midway, right, xshift=5pt]{$c$};\n\t\\end{tikzpicture}\n\\end{challenge}\n\nGeneralizing the vector norms in $\\Rs{2}$ and $\\Rs{3}$ to $\\Rs{n}$ yields the following form:\n\\begin{equation}\n\t\\norm{v} = \\sqrt{v_{1}^{2} + v_{2}^{2} + v_{3}^{2} + \\dots + v_{n}^{2}} = \\sqrt{\\sum\\limits_{i=1}^{n}v_{i}^{2}}.\n\t\\label{eq:norm nD vector}\n\\end{equation}\n\n\\begin{note}{Other norms}{}\n\tThe norm shown here is called the $2$-norm. There are other possible norm that can be defined, and are used in different situations, such as the $1$-norm (also the called \\emph{taxicab norm}), general $p$-norm where $p\\geq1$ is a real number, the zero-norm, the max-norm, and many others. However, for the purpose of this chapter we use only the standard $2$-norm, since it is the most useful for describing basic concepts of linear algebra and its uses.\n\\end{note}\n\nScaling a vector $\\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}}$ by a real number $\\alpha$ is done by multiplying each of its components by $\\alpha$, i.e.\n\\begin{equation}\n\t\\alpha\\vec{v} = \\colvec{\\alpha v_{1};\\alpha v_{2};\\vdots;\\alpha v_{n}}.\n\t\\label{eq:scaling vectors}\n\\end{equation}\n\nWe can prove \\autoref{eq:scaling vectors} by directly calculating the norm of a scaled vector $\\vec{w}=\\alpha\\vec{v}$:\n\\begin{proof}{Scaling a column vector}{}\n\tLet $\\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}}$ and $\\vec{w}=\\colvec{\\alpha v_{1};\\alpha v_{2};\\vdots;\\alpha v_{n}}$, where $\\alpha\\in\\mathbb{R}$. Then $\\vec{w}$ has the following norm:\n\t\\begin{align*}\n\t\t\\norm{w} &= \\sqrt{\\sum\\limits_{i=1}^{n}(\\alpha v_{i})^{2}}\\\\\n\t\t&= \\sqrt{(\\alpha v_{1})^{2} + (\\alpha v_{2})^{2} + \\dots + (\\alpha v_{1})^{2}}\\\\\n\t\t&= \\sqrt{\\alpha^{2}v_{1}^{2} + \\alpha^{2}v_{2}^{2} + \\dots + \\alpha^{2}v_{n}^{2}}\\\\\n\t\t&= \\sqrt{\\alpha^{2}\\left( v_{1}^{2} + v_{2}^{2} + \\dots + v_{n}^{2} \\right)}\\\\\n\t\t&= \\alpha\\sqrt{v_{1}^{2} + v_{2}^{2} + \\dots + v_{n}^{2}}\\\\\n\t\t&= \\alpha\\norm{v}.\n\t\\end{align*}\n\n\tThis shows that indeed $\\vec{w}=\\alpha\\vec{v}$.\n\\end{proof}\n\nAnother idea we can prove in column form is vector normalization (\\autoref{eq:normalized vector}), by showing that dividing each component of a vector by its norm gives a vector of unit norm:\n\\begin{proof}{Norm of a vector}{}\n\tLet $\\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}}$. Its norm is then $\\norm{v}=\\sqrt{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}}$. Scaling $\\vec{v}$ by $\\frac{1}{\\norm{v}}$ yields\n\t\\begin{equation*}\n\t\t\\hat{v} = \\frac{1}{\\norm{v}}\\colvec{v_{1};v_{2};\\vdots;v_{n}} = \\frac{1}{\\sqrt{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}}}\\colvec{v_{1};v_{2};\\vdots;v_{n}}\n\t\\end{equation*}\n\n\tThe norm of $\\hat{v}$ is therefore\n\t\\begin{align*}\n\t\t\\left\\| \\hat{v} \\right\\| &= \\sqrt{\\frac{v_{1}^{2}}{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}} + \\frac{v_{2}^{2}}{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}} + \\dots + \\frac{v_{n}^{2}}{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}}}\\\\\n\t\t&= \\sqrt{\\frac{1}{v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2}}\\left(v_{1}^{2}+v_{2}^{2}+\\dots+v_{n}^{2} \\right)}\\\\\n\t\t&= \\sqrt{1} = 1,\n\t\\end{align*}\n\n\ti.e. $\\hat{v}$ is indeed a unit vector.\n\\end{proof}\n\n\\begin{example}{Normalizing a vector}{normalizing a vector}\n\tLet's normalize the vector $\\vec{v}=\\colvec{0;4;-3}$. Its norm is\n\t\\[\n\t\t\\norm{v} = \\sqrt{0^{2}+4^{2}+(-3)^{2}} = \\sqrt{0+16+9} = \\sqrt{25} = 5.\n\t\\]\n\tTherefore $\\hat{v}$ (the normalized $\\vec{v}$) is\n\t\\[\n\t\t\\hat{v} = \\colvec{0;\\frac{4}{5};-\\frac{3}{5}}.\n\t\\]\n\n\tBy calculating the norm of $\\hat{v}$ directly, we can see that it is indeed a unit vector:\n\t\\begin{align*}\n\t\t\\left\\|\\hat{v}\\right\\| = \\sqrt{0^{2} + \\frac{4^{2}}{5^{2}} + \\frac{3^{2}}{5^{2}}} = \\sqrt{\\frac{0^{2}+4^{2}+3^{2}}{5^{2}}} = \\sqrt{\\frac{16+9}{25}} = \\sqrt{\\frac{25}{25}} = \\sqrt{1} = 1.\n\t\\end{align*}\n\\end{example}\n\nThe addition of two column vectors $\\vec{u}=\\colvec{u_{1};u_{2};\\vdots;u_{n}}$ and $\\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}}$ is done by adding their respective components together, i.e.\n\\begin{equation}\n\t\\vec{u} + \\vec{v} = \\colvec{u_{1}+v_{1};u_{2}+v_{2};\\vdots;u_{n}+v_{n}}.\n\t\\label{eq:adding vectors}\n\\end{equation}\n\nTBW: how this addition is the same as the one shown in \\autoref{fig:vector addition geometric}.\n\n\\begin{note}{No addition of vectors of different number of components!}{}\n\tTwo vectors can only be added together if they have the same number of components. The addition of vectors with different number of components is undefined.\n\\end{note}\n\n\\subsection{Linear combinations, spans and linear dependency}\nAs seen above, scaling a vector by a scalar results in a vector that has the same number of dimensions as the original vector. The same is true for adding two vectors: both of them must be of the same dimension, and the result is also a vector of the same dimension. Therefore, any combination of scaling and addition of vectors results in a vector of the same dimension as the original vector(s). This kind of combination is called a \\emph{linear combination}.\n\nLet's define linear combinations a little more formaly:\n\n\\begin{definition}{Linear combinations}{}\n\tA linear combination of $n$ vectors $\\vec{v}_{1}, \\vec{v}_{2}, \\dots, \\vec{v}_{n}$ of the same dimension, using $n$ scalars $\\alpha_{1},\\alpha_{2},\\dots,\\alpha_{n}$, is an expression of the form\n\t\\begin{equation}\n\t\t\\vec{w} = \\alpha_{1}\\vec{v}_{1} + \\alpha_{2}\\vec{v}_{2} + \\dots + \\alpha_{n}\\vec{v}_{n} = \\sum\\limits_{i=1}^{n}\\alpha_{i}\\vec{v}_{i}.\n\t\t\\label{eq:linear combination}\n\t\\end{equation}\n\\end{definition}\n\nLinear combinations of real vectors have geometric meaningsc: we start with the set of all linear combinations of a single vector $\\vec{v}\\in\\Rs{n}$, i.e.\n\\begin{equation}\n\tV = \\left\\{\\alpha\\vec{v} \\mid \\alpha\\in\\mathbb{R} \\right\\}.\n\t\\label{eq:span of a single vector}\n\\end{equation}\nThe set $V$ represents a line in the direction of $\\vec{v}$ going through the origin (see \\autoref{fig:span of a single vector}). The set $V$ is itself a vector space of dimension $1$, and as such a \\emph{subspace} of $\\Rs{n}$. We say that it is the \\emph{span} of the vector $\\vec{v}$ (i.e. the vector $\\vec{v}$ \\emph{spans} the subspace $V$).\n\n\\def\\veccolor{xred}\n\\tikzset{\n\tdline/.style={densely dotted, thick, \\veccolor!50!gray},\n}\n\\begin{figure}[h]\n\t\\centering\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=7cm, height=7cm,\n\t\t\t\t\txticklabels={,},\n\t\t\t\t\tyticklabels={,},\n\t\t\t\t\tdeclare function={\n\t\t\t\t\t\tax=2; ay=1;\n\t\t\t\t\t\tbx=0; by=0;\n\t\t\t\t\t\tf(\\x)=(by-ay)/(bx-ax)*(\\x-ax)+ay;\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t\t\\coordinate (A) at ({ax}, {ay});\n\t\t\t\t\\coordinate (B) at ({bx}, {by});\n\t\t\t\t\\draw[vector, \\veccolor] (0,0) -- (A) node [above] {$\\vec{v}$};\n\t\t\t\t\\draw[dline] (A) -- (6,{f(6)});\n\t\t\t\t\\draw[dline] (B) -- (-6,{f(-6)});\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{$\\Rs{2}$}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[b]{0.49\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\taxis lines=center,\n\t\t\t\t\tz buffer=sort,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\t\txtick=\\empty,\n\t\t\t\t\tytick=\\empty,\n\t\t\t\t\tztick=\\empty,\n\t\t\t\t\tview={330}{20},\n\t\t\t\t]\n\t\t\t\t% Below surface\n\t\t\t\t\\draw[stealth-, thick] (0,0,-4) -- (0,0,0);\n\t\t\t\t\\draw[dline] (-4,-2.67,-4) -- (0,0,0);\n\n\t\t\t\t% Surface\n\t\t\t\t\\addplot3[surf, faceted color=xblue!50!black!50, fill=xblue!20, opacity=0.5, domain=-4:4, samples=7] {0};\n\n\t\t\t\t% Above surface\n\t\t\t\t\\draw[axisline] (-4,0,0) -- (4,0,0) node[pos=1.05] {$x$};\n\t\t\t\t\\draw[axisline] (0,-4,0) -- (0,4,0) node[pos=1.075] {$y$};\n\t\t\t\t\\draw[-stealth, thick] (0,0,0) -- (0,0,4) node[pos=1.075] {$z$};\n\t\t\t\t\\draw[dline] (3,2,3) -- (4,2.67,4);\n\t\t\t\t\\draw[vector, \\veccolor] (0,0,0) -- (3,2,3) node[above, right] {$\\vec{v}$};\n\t\t\t\t\\draw[dashed, black!50] (3,2,3) -- (3,2,0) -- (0,0,0);\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{$\\Rs{3}$}\n\t\\end{subfigure}\n\t\\caption{The span of a single vector $\\color{xred}{\\bm{\\vec{v}}}$, shown as a dashed line: in $\\Rs{2}$ (left) and $\\Rs{3}$ (right).}\n\t\\label{fig:span of a single vector}\n\\end{figure}\n\nSimilarily, the set of all linear combinations of two vectors $\\vec{u},\\vec{v}\\in\\Rs{n}$ that are not scales of each other (i.e. there is no such $\\alpha\\in\\mathbb{R}$ for which $\\vec{v}=\\alpha\\vec{u}$),\n\\begin{equation}\n\tV = \\left\\{\\alpha\\vec{u}+\\beta\\vec{v} \\mid \\alpha,\\beta\\in\\mathbb{R} \\right\\},\n\t\\label{eq:span of a two vectors}\n\\end{equation}\nis a plane that goes through the origin (see \\autoref{fig:span of two vectors}). Such vectors are also said to be \\emph{non-collinear}.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\taxis lines=center,\n\t\t\t\tz buffer=sort,\n\t\t\t\txmin=-4, xmax=4,\n\t\t\t\tymin=-4, ymax=4,\n\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\txtick=\\empty,\n\t\t\t\tytick=\\empty,\n\t\t\t\tztick=\\empty,\n\t\t\t\tview={50}{20},\n\t\t\t]\n\t\t\t% Behind surface at z=0\n\t\t\t\\draw[stealth-, thick] (0,0,-4) -- (0,0,0);\n\t\t\t\\addplot3[surf, faceted color=xgreen!50!black!50, fill=xgreen!20, opacity=0.9, domain=-4:4, y domain=-4:0, samples=7] {0.4*y};\n\n\t\t\t% Surface at z=0\n\t\t\t\\addplot3[surf, faceted color=xblue!50!black!50, fill=xblue!20, opacity=0.9, domain=-4:4, samples=7] {0};\n\n\t\t\t% Back axis line\n\t\t\t\\draw[axisline] (0,0,0) -- (0,4,0) node[pos=1.075] {$y$};\n\t\t\t\n\t\t\t% Infront of surface at z=0\n\t\t\t\\addplot3[surf, faceted color=xgreen!50!black!50, fill=xgreen!20, opacity=0.9, domain=-4:4, y domain=0:4, samples=7] {0.4*y};\n\n\t\t\t% Vectors\n\t\t\t\\draw[vector] (0,0,0) -- (-2,3,1.2) node[pos=1.15, fill=white, rounded corners] {$\\vec{a}$};\n\t\t\t\\draw[vector] (0,0,0) -- (+3,3,1.2) node[pos=1.12, fill=white, rounded corners] {$\\vec{b}$};\n\n\t\t\t% Front axis lines\n\t\t\t\\draw[axisline] (-4,0,0) -- (4,0,0) node[pos=1.05] {$x$};\n\t\t\t\\draw[stealth-, thick] (0,-4,0) -- (0,0,0);\n\t\t\t\\draw[-stealth, thick] (0,0,0) -- (0,0,4) node[pos=1.075] {$z$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Two vectors $\\vec{a}$ and $\\vec{b}$ span a plane (colored green) in $\\Rs{3}$. The $xy$-plane (i.e. $z=0$) is shown in blue for emphasis.}\n\t\\label{fig:span of two vectors}\n\\end{figure}\n\n\\begin{example}{Spanning $\\bm{\\Rs{2}}$ using two non-collinear vectors}{}\n\tSince any two non-collinear vectors span a 2-dimensional subspace of $\\Rs{n}$, in $\\Rs{2}$ this means that any vector $\\vec{w}$ can be written as a linear combination of any two vectors $\\vec{u},\\vec{v}$ that are not a scale of each other. For example, we can take the vector\n\t\\[\n\t\t\\vec{w} = \\colvec{7;-1},\n\t\\]\n\tand write it as a linear combination of any two non-collinear vectors, say\n\t\\[\n\t\t\\vec{u}=\\colvec{2;-3},\\ \\vec{v}=\\colvec{0;5}.\n\t\\]\n\n\tThe equation which forces the relation is\n\t\\[\n\t\t\\colvec{7;-1} = \\alpha\\colvec{2;-3} + \\beta\\colvec{0;5},\n\t\\]\n\tand we should solve it for $\\alpha$ and $\\beta$. This is possible since the equation above is actually a system of two equations in two variables (namely $\\alpha$ and $\\beta$):\n\t\\[\n\t\t\\begin{cases}\n\t\t\t\\ 7  = 2\\alpha,\\\\\n\t\t\t\\ -1 = -3\\alpha + 5\\beta.\n\t\t\\end{cases}\n\t\\]\n\tThe solution for the system is $\\alpha=3.5$ and $\\beta=1.9\\tikz{\\node(AAA){};}$, and therefore\n\t\\[\n\t\t\\colvec{7;-1} = 3.5\\colvec{2;-3} + 1.9\\colvec{0;5}.\n\t\\]\n\\end{example}\n%\\solvesym{AAA}\n\nGeneralizing the example above, any vector $\\vec{w}=\\colvec{w_{x};w_{y}}$ can be written as a linear combination of two vectors $\\vec{u}=\\colvec{u_{x};u_{y}}$ and $\\vec{v}=\\colvec{v_{x};v_{y}}$, as long as $\\vec{u}$ and $\\vec{v}$ are non-collinear. Let's prove this:\n\\begin{proof}{$\\bm{\\Rs{2}}$ is spanned by any two non-collinear vectors in $\\bm{\\Rs{2}}$}{fd}\n\tLet $\\vec{u},\\vec{v}\\in\\Rs{2}$ be two non-collinear vectors. Their non-collinearity means that the equation\n\t\\begin{equation}\n\t\t\\vec{u} = \\alpha\\vec{v}\n\t\t\\label{eq:collinear vectors}\n\t\\end{equation}\n\thas no solution, i.e. the system\n\t\\begin{equation}\n\t\t\\begin{cases}\n\t\t\t&u_{x} = \\alpha v_{x}\\\\\n\t\t\t&u_{y} = \\alpha v_{y}\n\t\t\\end{cases}\n\t\t\\label{eq:collinear system}\n\t\\end{equation}\n\thas no solution. The system has solution only when $u_{x}v_{y} = u_{y}v_{x}$, and so the restriction is translated to the simple equation\n\t\\begin{equation}\n\t\tu_{x}v_{y} \\neq u_{y}v_{x}.\n\t\t\\label{eq:restriction}\n\t\\end{equation}\n\n\tThe system which defines $\\vec{w}$ as a linear combination of $\\vec{u}$ and $\\vec{v}$ is\n\t\\begin{equation}\n\t\t\\begin{cases}\n\t\t\t&w_{x} = \\alpha u_{x} + \\beta v_{x}\\\\\n\t\t\t&w_{y} = \\alpha u_{y} + \\beta v_{y}\\\\\n\t\t\\end{cases}\n\t\t\\label{eq:linear combination of two vectors}\n\t\\end{equation}\n\n\tIsolating $\\alpha$ using the first equation yields\n\t\\begin{equation}\n\t\t\\alpha = \\frac{w_{x}-\\beta v_{x}}{u_{x}},\n\t\t\\label{eq:isolation1}\n\t\\end{equation}\n\tand subtituting it into the second equation yields\n\t\\begin{equation}\n\t\t\\beta = \\frac{w_{y}-\\alpha u_{y}}{v_{y}} = \\frac{w_{y}-\\frac{w_{x}-\\beta v_{x}}{u_{x}}}{v_{y}},\n\t\t\\label{eq:isolation2}\n\t\\end{equation}\n\twhich rearranges into\n\t\\begin{equation}\n\t\t\\beta = \\frac{u_{x} w_{y} - u_{y} w_{x}}{u_{x} v_{y} - u_{y} v_{x}},\n\t\t\\label{eq:test}\n\t\\end{equation}\n\tand thus\n\t\\begin{equation}\n\t\t\\alpha = \\frac{- v_{x} w_{y} + v_{y} w_{x}}{u_{x} v_{y} - u_{y} v_{x}}.\n\t\t\\label{eq:test2}\n\t\\end{equation}\n\n\tWe can see that $\\alpha$ and $\\beta$ exist iff $u_{x}v_{y}\\neq u_{y}v_{x}$, which is guaranteed by \\autoref{eq:restriction}. Therefore, $\\alpha$ and $\\beta$ always exist when $\\vec{u}$ and $\\vec{v}$ are non-collinear, and thus any vector in $\\Rs{2}$ can be written as a linear combination of any two non-collinear vectors in $\\Rs{2}$, i.e. any two non-collinear vectors in $\\Rs{2}$ span $\\Rs{2}$.\n\\end{proof}\n\nGoing a step further, any three vectors $\\vec{u},\\vec{v},\\vec{w}\\in\\Rs{n}$ that are not coplanar span a 3-dimensional subspace of $\\Rs{n}$ going through the origin. To generalize the notion of collinear and coplanar vectors to higher dimensions we introduct the concept of \\emph{linear dependency} of a set of vectors:\n\n\\begin{definition}{Linear dependent set of vectors}{linear dependency}\n\tA set of $n$ vectors\n\t\\begin{equation}\n\t\tS = \\left\\{ \\vec{v}_{1}, \\vec{v}_{2}, \\dots, \\vec{v}_{n} \\right\\}\n\t\t\\label{eq:set of n vectors}\n\t\\end{equation}\n\tis said to be linearly dependent if there exist a linear combination\n\t\\begin{equation}\n\t\t\\alpha_{1}\\vec{v}_{1} + \\alpha_{2}\\vec{v}_{2} + \\dots + \\alpha_{n}\\vec{v}_{n} = \\vec{0},\n\t\t\\label{eq:set of n vectors}\n\t\\end{equation}\n\tand \\textbf{at least} one the coefficients $\\alpha_{i}\\neq0$.\n\\end{definition}\n\nThe following examples shows that the definition above reduces to colinarity and coplanary in the case of $2$ and $3$ vectors:\n\\begin{example}{Linear dependency of $2$ vectors}{}\n\tLet $\\vec{u}$ and $\\vec{v}$ be two linearly dependent vectors in $\\Rs{n}$. Then there exist a linear combination\n\t\\[\n\t\t\\alpha\\vec{u} + \\beta\\vec{v} = \\vec{0},\n\t\\]\n\twith either $\\alpha\\neq0$ or $\\beta\\neq0$ (or both). We can look at the different possible cases:\n\t\\begin{itemize}\n\t\t\\item $\\alpha\\neq0,\\ \\beta=0$: in this case $\\alpha\\vec{u}=\\vec{0}$, i.e. $\\vec{u}=0$.\n\t\t\\item $\\alpha=0,\\ \\beta\\neq0$: in this case $\\beta\\vec{v}=\\vec{0}$, i.e. $\\vec{v}=0$.\n\t\t\\item $\\alpha\\neq0,\\ \\beta\\neq0$: in this case we can rearrange the equation and get\n\t\t\t\\[\n\t\t\t\t\\vec{u} = -\\frac{\\beta}{\\alpha}\\vec{v},\n\t\t\t\\]\n\t\t\ti.e. $\\vec{u}$ and $\\vec{v}$ are scales of each other and thus are collinear.\n\t\\end{itemize}\n\tWhat we learn from this is that two vectors form a linearly dependent set if at least one of the is the zero vector, or if they are collinear.\n\n\\end{example}\n\n\\begin{example}{Linear dependency of $3$ vectors}{}\n\tNow, let $\\vec{u},\\vec{v}$ and $\\vec{w}$ be three linearly dependent vectors in $\\Rs{n}$. Then there exists a linear combination\n\t\\[\n\t\t\\alpha\\vec{u} + \\beta\\vec{v} + \\gamma\\vec{w} = \\vec{0},\n\t\\]\n\twith either $\\alpha\\neq0$ or $\\beta\\neq0$ or $\\gamma\\neq0$ or any combination where two of the coefficients are non-zero, or all of the coefficients are non-zero. Again, we look at all the possible cases:\n\t\\begin{itemize}\n\t\t\\item $\\alpha\\neq0,\\ \\beta=\\gamma=0$: we get $\\alpha\\vec{u} = \\vec{0}$, thus $\\vec{u}=\\vec{0}$.\n\t\t\\item $\\alpha=0,\\ \\beta\\neq0,\\ \\gamma=0$: we get $\\beta\\vec{v} = \\vec{0}$, thus $\\vec{v}=\\vec{0}$.\n\t\t\\item $\\alpha=\\beta=0,\\ \\gamma\\neq0$: we get $\\gamma\\vec{w} = \\vec{0}$, thus $\\vec{w}=\\vec{0}$.\n\t\t\\item $\\alpha\\neq0,\\ \\beta\\neq0, \\gamma=0$: we get that $\\vec{u}$ and $\\vec{v}$ are collinear, since this is exactly as the case for two linearly dependent vectors.\n\t\t\\item $\\alpha\\neq0,\\ \\beta=0, \\gamma\\neq0$: similar to the previous case, this time $\\vec{u}$ and $\\vec{w}$ are collinear.\n\t\t\\item $\\alpha=0,\\ \\beta\\neq0, \\gamma\\neq0$: similar to the previous case, this time $\\vec{v}$ and $\\vec{w}$ are collinear.\n\t\t\\item $\\alpha\\neq0,\\ \\beta\\neq0,\\ \\gamma\\neq0$: by rearranging we get\n\t\t\t\\[\n\t\t\t\t\\vec{w} = -\\frac{1}{\\gamma}\\left( \\alpha\\vec{u} + \\beta\\vec{v} \\right),\n\t\t\t\\]\n\t\t\ti.e. $\\vec{w}$ lies on the the plane spanned by $\\vec{u}$ and $\\vec{v}$. If we isolate $\\vec{u}$ or $\\vec{v}$ instead, we get the same result: the isolated vector is a lienar combination of the other two vectors, and thus lies on the plan spanned by these vectors.\n\t\\end{itemize}\n\tFrom this example we learn that three vectors form a linearly dependent set if one or more of the vectors is the zero vector, or if any two vectors in the set are collinear, or if all three vectors are coplanar.\n\\end{example}\n\nJust like the case of $2$ and $3$ vectors seen above, any set of $m\\leq n$ vectors in $\\Rs{n}$ that are \\textbf{not} linearly dependent span an $m$-dimensional subspace of $\\Rs{n}$ (which goes throught the origin) - i.e. any vector $\\vec{v}\\in\\Rs{n}$ can be written as a linear combination of these vectors. We call such a set a \\emph{basis set} of $\\Rs{n}$.\n\n\\begin{example}{Basis sets in $n$ dimensions}{}\n\tThe following three vectors are non coplanar (i.e. they are linearly independent), and thus form a basis set of $\\Rs{3}$:\n\t\\[\n\t\tB = \\left\\{ \\colvec{0;4;5},\\ \\colvec{4;2;-2},\\ \\colvec{1;0;-5} \\right\\}.\n\t\\]\n\tThis means that any vector in $\\Rs{3}$ can be written as a linear combination of these vectors. We can show this by writing a generic vector $\\vec{v}=\\colvec{x;y;z}\\in\\Rs{3}$ as a linear combination of the vectors:\n\t\\[\n\t\t\\vec{v} = \\colvec{x;y;z} = \\alpha\\colvec{0;4;5} + \\beta\\colvec{4;2;-2} + \\gamma\\colvec{1;0;-5},\n\t\\]\n\twhich can be expanded to the system of equations\n\t\\[\n\t\t\\begin{cases}\n\t\t\t& x = \\cancel{0\\alpha}+4\\beta+1\\gamma,\\\\\n\t\t\t& y = 4\\alpha+2\\beta+\\cancel{0\\gamma},\\\\\n\t\t\t& z = 5\\alpha-2\\beta-5\\gamma.\n\t\t\\end{cases}\n\t\\]\n\n\tThe solution of the above system gives the coefficients of the linear combination to yield any vector in $\\Rs{3}$:\n\t\\begin{align*}\n\t\t\\alpha &= -\\frac{5x}{31} + \\frac{9y}{31} - \\frac{z}{31},\\\\\n\t\t\\beta  &= \\frac{10x}{31} - \\frac{5y}{62} + \\frac{2z}{31},\\\\\n\t\t\\gamma &= -\\frac{9x}{31} + \\frac{10y}{31} - \\frac{8z}{31}.\n\t\\end{align*}\n\n\tFor example, to yield the vector $\\vec{v}=\\colvec{1;-1;0}$ we sustitute $x=1,\\ y=-1,\\ z=0$ into the above solutions, and get that the following coefficients are needed:\n\t\\[\n\t\t\\alpha=-\\frac{28}{62},\\ \\beta=\\frac{25}{62},\\ \\gamma=-\\frac{38}{62},\n\t\\]\n\ti.e.\n\t\\[\n\t\t-\\frac{28}{62}\\colvec{0;4;5} + \\frac{25}{62}\\colvec{4;2;-2} -\\frac{38}{62}\\colvec{1;0;-5} = \\colvec{1;-1;0}.\n\t\\]\n\t(you, the reader, should verify this!)\n\\end{example}\n\nHaving described basis sets in somewhat general terms, we can now define them a bit more precisely:\n\n\\begin{definition}{Basis sets}{basis sets}\n\tLet $B$ be a \\textbf{linearly independent set} of vectors in $\\Rs{n}$. If any vector $\\vec{v}\\in\\mathbb{\\Rs{n}}$ can be written as a linear combination of the vectors in $B$, then $B$ is called a basis set of $\\Rs{n}$. The \\emph{dimension} of $B$ is the number of vectors in $B$.\n\\end{definition}\n\nThe dimension of a basis set $B$ of $\\Rs{n}$ is always $n$. In fact, in a later chapter we will see that the dimension of a vector space is defined by the dimension of its basis sets, i.e. given a vector space $V$ and a basis set $B\\subseteq V$, the dimension of $V$ is equal to $|B|$, or mathematically\n\\begin{equation}\n\t\\dim(V) = |B|.\n\t\\label{eq:dimension of a vector space}\n\\end{equation}\n\nIt can be easily shown that any set of vectors in $\\Rs{n}$ which has more than $n$ vectors must be a linearly dependent set:\n\n\\begin{proof}{Sets with more than $\\bm{n}$ vectors in $\\bm{\\Rs{n}}$}{label}\n\tLet $S$ be a set of $m\\in\\mathbb{N}$ vectors in $\\Rs{n}$, where $m>n$. Given a vector $\\vec{v}\\in S$ and the set of all vectors in $S$ except $\\vec{v}$ (call this set $\\tilde{S}$), there are two possibilities:\n\t\\begin{itemize}\n\t\t\\item $\\tilde{S}$ is a linearly dependent set in $\\Rs{n}$. In this case, the addition of $\\vec{v}$ doesn't change this fact, i.e. the set $S$ as a whole is linearly dependent.\n\t\t\\item The set $\\tilde{S}$ is linearly independent, and since it has $n$ vectors it forms a basis set of $\\Rs{n}$. Therefore, $\\vec{v}$ can be written as a linear combination of the vectors in $\\tilde{S}$, and thus the inclusion of $\\vec{v}$ in $S$ makes $S$ a linearly dependent set.\n\t\\end{itemize}\n\\end{proof}\n\nLet us now take a vector, for example $\\vec{v}=\\colvec{1;-3;7}$, and span it by three different basis sets:\n\\[\n\tB_{1} = \\left\\{ \\colvec{1;0;0},\\ \\colvec{0;1;0},\\ \\colvec{0;0;1} \\right\\}\\quad B_{2} = \\left\\{ \\colvec{5;1;2},\\ \\colvec{0;1;0},\\ \\colvec{4;-1;1} \\right\\},\\quad B_{3} = \\left\\{ \\colvec{-1;0;2},\\ \\colvec{0;2;-3},\\ \\colvec{2;2;3} \\right\\}.\n\\]\n\nAs can be seen in \\autoref{fig:vector in different basis sets}, for each basis set the coefficients (colored) are different. In this context we call the coefficients the \\emph{coordinates} of $\\vec{v}$ in that basis set. In the basis set $\\left\\{ \\colvec{1;0;0},\\ \\colvec{0;1;0},\\ \\colvec{0;0;1} \\right\\}$ the coordinates of $\\vec{v}$ are $(1,-3,7)$ (as we will see next, it is not a coincidense that these are equal to its components as a column vector), and in the basis set $\\left\\{ \\colvec{5;1;2},\\ \\colvec{0;1;0},\\ \\colvec{4;-1;1} \\right\\}$ its coordinates are $(9,-23,-11)$.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}[node distance=1.75cm]\n\t\t\\node (1-37) {$\\vec{v}=\\colvec{1;-3;7}$};\n\t\t\\node[above right of=1-37, xshift=3cm] (std) {$\\textcolor{xred}{\\bm{1}}\\colvec{1;0;0} \\textcolor{xred}{\\bm{-3}}\\colvec{0;1;0} \\textcolor{xred}{\\bm{+7}}\\colvec{0;0;1}$};\n\t\t\\node[below=of std.west, anchor=west] (b1) {$\\textcolor{xblue}{\\bm{9}}\\colvec{5;1;2} \\textcolor{xblue}{\\bm{-23}}\\colvec{0;1;0} \\textcolor{xblue}{\\bm{-11}}\\colvec{4;-1;1}$};\n\t\t\\node[below=of b1.west, anchor=west] (b2) {$\\textcolor{xgreen}{\\bm{1.4}}\\colvec{-1;0;2} \\textcolor{xgreen}{\\bm{+0.3}}\\colvec{0;2;-3} \\textcolor{xgreen}{\\bm{+1.2}}\\colvec{2;2;3}$};\n\t% !!!!!!!!!! LAST BASIS SET IS SOMEHOW WRONG - CHECK !!!!!!!!!! %\n\n\t\t\\draw[-stealth, thick] (1-37.east) to [out=0, in=180, looseness=0.7] node[pos=0.5, above, yshift=2pt] {$\\textcolor{xred}{B_{1}}$} (std.west);\n\t\t\\draw[-stealth, thick] (1-37.east) to [out=0, in=180, looseness=0.7] node[pos=0.6, above, yshift=0pt] {$\\textcolor{xblue}{B_{2}}$} (b1.west);\n\t\t\\draw[-stealth, thick] (1-37.east) to [out=0, in=180, looseness=0.7] node[pos=0.7, above, yshift=3pt] {$\\textcolor{xgreen}{B_{3}}$} (b2.west);\n\t\\end{tikzpicture}\n\t\\caption{The vector $\\vec{v}=\\colvec{1;-3;7}$ spanned in three different basis sets.}\n\t\\label{fig:vector in different basis sets}\n\\end{figure}\n\nChanging the coordinates of a vector between different basis sets is called \\emph{basis transformation}, and is generally done using \\emph{matrices}. We will discuss this in more details in the next sections of this chapter. For now, let's look at a graphical representation of a vector being expressed in a different basis set (\\autoref{fig:vector in two different basis sets}): in the figure, we see that the vector $\\vw=\\colvec{2;3}$ can be written in the basis set $B=\\left\\{ \\textcolor{xred}{\\colvec{2;1}},\\ \\textcolor{xblue}{\\colvec{-4;2}} \\right\\}$ using the coefficients $2$ and $\\frac{1}{2}$, i.e.\n\\[\n\t\\vw = \\textcolor{xpurple}{\\colvec{2;3}} = 2\\textcolor{xred}{\\colvec{2;1}} +\\frac{1}{2}\\textcolor{xblue}{\\colvec{-4;2}}.\n\\]\nTherefore, in the basis set $B$, the coordinates of $\\vw$ are $\\left(2,\\frac{1}{2}\\right)$.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=7.5cm, height=7.5cm,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\txtick={-4,-3,...,4},\n\t\t\t\t\tytick={-4,-3,...,4},\n\t\t\t\t]\n\t\t\t\t\\draw[vector, xpurple] (0,0) -- (2,3) node[pos=1.1] {$\\vec{w}$};\n\t\t\t\t\\draw[vector, xred] (0,0) -- (2,1) node[pos=1.1] {$\\vec{v}$};\n\t\t\t\t\\draw[vector, xblue] (0,0) -- (-4,2) node[above right] {$\\vec{u}$};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{subfigure}\n\t\\hfill\n\t\\begin{subfigure}[t]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=7.5cm, height=7.5cm,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\txtick={-4,-3,...,4},\n\t\t\t\t\tytick={-4,-3,...,4},\n\t\t\t\t]\n\t\t\t\t\\draw[vector, xpurple] (0,0) -- (2,3);\n\t\t\t\t\\draw[vector, xred] (0,0) -- (2,1);\n\t\t\t\t\\draw[vector, xred] (2,1) -- (4,2);\n\t\t\t\t\\draw[vector, xblue] (4,2) -- (2,3);\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\\end{subfigure}\n\t\\caption{The vector $\\vw=\\textcolor{xpurple}{\\colvec{2;3}}$ is spanned using the vectors $\\vu=\\textcolor{xred}{\\colvec{2;1}}$ and $\\vv=\\textcolor{xblue}{\\colvec{-4;2}}$, yielding the coordinates $\\left( 2,\\frac{1}{2} \\right)$ in the basis set $B$.}\n\t\\label{fig:vector in two different basis sets}\n\\end{figure}\n\nA bsis set $B$ in which all vectors are \\emph{orthogonal} (i.e. are at $\\ang{90}$) to each other is called a \\emph{orthogonal basis set}. If all vectors are unit vectors as well, i.e. their norms all equal to $1$, the basis set is then an \\emph{orthonormal basis set}.\n\n\\begin{example}{Orthogonal and orthonormal basis sets}{orthobasis}\n\tThe vectors $\\vec{a}=\\colvec{1;1}$ and $\\vec{b}=\\colvec{-1;1}$ are linearly independent and thus form a basis set of $\\Rs{2}$. We can calculate their respective angles in relation to the $x$-axis ($\\theta_{a}$ and $\\theta_{b}$) to find the angle between them ($\\varphi$):\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\tvector plane,\n\t\t\t\twidth=6cm, height=4.6cm,\n\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\tymin=-0.5, ymax=1.5,\n\t\t\t\txtick={-1,...,1},\n\t\t\t\tytick={1},\n\t\t\t]\n\t\t\t\\draw[thick, fill=xred!20] (0,0) -- (0.6,0) arc (0:45:0.6) -- cycle;\n\t\t\t\\draw[thick, fill=xblue!20] (0,0) -- (-0.6,0) arc (180:135:0.6) -- cycle;\n\t\t\t\\draw[thick, fill=xpurple!20] (0,0) -- (0.424,0.424) arc (45:135:0.6) -- cycle;\n\t\t\t\\draw[vector] (0,0) -- (1,1) node[pos=1.1] {$\\vec{a}$};\n\t\t\t\\draw[vector] (0,0) -- (-1,1) node[pos=1.1] {$\\vec{b}$};\n\t\t\t\\node at (0.4,0.14) {$\\theta_{a}$};\n\t\t\t\\node at (-0.4,0.14) {$\\theta_{b}$};\n\t\t\t\\node at (0,0.35) {$\\varphi$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{figure}\n\nThe angle of $\\vec{a}$ is\n\\[\n\t\\theta_{a} = \\arctan\\left( \\frac{a_{y}}{a_{x}} \\right) = \\arctan(1) = \\frac{\\pi}{4}\\ (=\\ang{45}).\n\\]\nSimilarily, the angle $\\alpha_{b}$ also equals $\\frac{\\pi}{4}$. Therefore, $\\varphi=2\\frac{\\pi}{4}=\\frac{\\pi}{2}$ ($=\\ang{90}$) - i.e. $\\vec{a}$ and $\\vec{b}$ are orthogonal, and thus form an orthogonal basis set of $\\Rs{2}$.\n\nTo get a similar \\textit{orthonormal} basis set we can simply normalize the two vectors. We start with $\\vec{a}$: its norm is\n\\[\n\t\\norm{a} = \\sqrt{1^{2}+1^{2}} = \\sqrt{2}.\n\\]\n\nThus, the vector $\\hat{a}=\\frac{1}{\\sqrt{2}}\\vec{a}=\\colvec{\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}}$ is a unit vector. The same argument is valid for $\\vec{b}$, i.e. $\\hat{b}=\\frac{1}{2}\\vec{b}=\\colvec{-\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}}$. We therefore get that\n\\[\n\t\\left\\{ \\colvec{\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}},\\ \\colvec{-\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}} \\right\\}\n\\]\nis an orthonormal basis set of $\\Rs{2}$.\n\\end{example}\n\n\\begin{challenge}{Orthonormal basis sets of $\\Rs{2}$}{}\nShow that all orthonormal basis sets of $\\Rs{2}$ are rotations of the set\n\\[\n\t\\left\\{ \\colvec{\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}},\\ \\colvec{-\\frac{1}{\\sqrt{2}};\\frac{1}{\\sqrt{2}}} \\right\\}\n\\]\nas a whole (i.e.\\ each rotation angle is applied to both vectors).\n\\end{challenge}\n\nSee example below for such sets in $\\Rs{2}$ and $\\Rs{3}$.\n\nOne common orthonormal basis set in any $\\Rs{n}$ is the so-called \\emph{standard basis set}. We saw the standard basis set in $\\Rs{3}$ in \\autoref{fig:vector in different basis sets}: it is the set $B_{1}=\\left\\{ \\colvec{1;0;0},\\ \\colvec{0;1;0},\\ \\colvec{0;0;1} \\right\\}$. Note how in this set, each vector has a special structure: one of its components is $1$ while the rest are $0$. In the first basis vector the non-zero component is the first component of the vector, in the second basis vector it is the second component, and in the third basis vector it is the third component. In $\\Rs{2}$ the standard basis set is simply $\\left\\{ \\colvec{1;0},\\ \\colvec{0;1} \\right\\}$, and generally in $\\Rs{n}$ it is\n\\begin{equation}\n\tB = \\left\\{ \\colvec{1;0;0;\\vdots;0;0},\\ \\colvec{0;1;0;\\vdots;0;0},\\ \\colvec{0;0;1;\\vdots;0;0}, \\dots, \\colvec{0;0;0;\\vdots;1;0},\\ \\colvec{0;0;0;\\vdots;0;1} \\right\\},\n\t\\label{eq:std basis set}\n\\end{equation}\ni.e. in the $n$-th basis vector the $n$-th component is $1$ while the rest are $0$. The standard basis vectors are generally labeled as $\\eb{1},\\ \\eb{2},\\ \\dots,\\ \\eb{n}$ - they get the ``hat`` symbol since they are all unit length.\n\nIn $\\Rs{2}$ and $\\Rs{3}$ we give $\\eb{1},\\ \\eb{2}$ and $\\eb{3}$ special notations: $\\hat{x},\\ \\hat{y}$ and $\\hat{z}$, respectively (obviously $\\hat{z}$ doesn't exists in $\\Rs{2}$). For historical reasons, these vectors are sometimes denoted in physics textbooks as $\\hat{i},\\ \\hat{j}$ and $\\hat{k}$.\n\n\\subsection{The scalar product}\nWhen given two vectors $\\vu,\\vv\\in\\Rs{n}$ it is often useful to know the angle between them: if the two vectors are linearly dependent then the angle is either $\\ath=0$ if they point in the same direction, or $\\ath=\\pi$ if the point in opposite directions (remember: we measure angles in radians). Otherwise, the angle $\\ath$ can take any value in $(0,\\pi)$. Angles are always measured on a plane, and in the case of two linearly independent vectors that plane is of course the one spanned by the two vectors (\\autoref{fig:angle between two vectors}).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\taxis lines=center,\n\t\t\t\tz buffer=sort,\n\t\t\t\txmin=-4, xmax=4,\n\t\t\t\tymin=-4, ymax=4,\n\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\txtick=\\empty,\n\t\t\t\tytick=\\empty,\n\t\t\t\tztick=\\empty,\n\t\t\t\tview={50}{10},\n\t\t\t]\n\t\t\t% Behind surface at z=0\n\t\t\t\\draw[stealth-, thick] (0,0,-4) -- (0,0,0);\n\t\t\t\\addplot3[surf, faceted color=black!25, fill=black!10, opacity=0.95, domain=-4:4, y domain=-4:0, samples=7] {0.5*y};\n\n\t\t\t% Back axis line\n\t\t\t\\draw[axisline] (0,0,0) -- (0,4,0) node[pos=1.075] {$y$};\n\t\t\t\n\t\t\t% Infront of surface at z=0\n\t\t\t\\addplot3[surf, faceted color=black!25, fill=black!10, opacity=0.95, domain=-4:4, y domain=0:4, samples=7] {0.5*y};\n\n\t\t\t% Angle and vectors\n\t\t\t%\\draw[thick, fill=white] (0,0,0) -- (1,0.667,0.334) arc (1:0:22.494) -- cycle;\n\t\t\t\\draw[vector, xred]  (0,0,0) -- (-1,3,1.5) node [pos=1.1] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (0,0,0) -- (3,3,1.5) node [pos=1.1] {$\\vec{v}$};\n\n\t\t\t% Front axis lines\n\t\t\t\\draw[axisline] (-4,0,0) -- (4,0,0) node[pos=1.05] {$x$};\n\t\t\t\\draw[stealth-, thick] (0,-4,0) -- (0,0,0);\n\t\t\t\\draw[-stealth, thick] (0,0,0) -- (0,0,4) node[pos=1.075] {$z$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{The angle between two linearly independent vectors lies on the plane spanned by the vectors.}\n\t\\label{fig:angle between two vectors}\n\\end{figure}\n\nIf considering only the plane the vectors span, we can rotate it such that one of the vectors, say $\\vu$, lies horizotally (see \\autoref{fig:angle between two vectors in plane}). We then drop a perpendicular line from the head of the $\\vu$ to the horizontal vector $\\vv$. We call the length from the origin to the intersection point of $\\vv$ and the perpendicular line the \\emph{projection} of $\\vu$ onto $\\vv$, and denote it as $\\projection$.\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\Large\n\t\t\\coordinate (o) at (0,0);\n\t\t\\coordinate (u) at (2.5,1.94);\n\t\t\\coordinate (v) at (3.6,0);\n\t\t\\coordinate (uv) at ($(u)+(v)$);\n\t\t\\filldraw[xpurple!20, draw=xpurple, thick] let\n\t\t\\p1=(u),\\p2=(v),\\n1={atan2(\\y1,\\x1)},\\n2={atan2(\\y2,\\x2)}\n\t\tin (o) -- ($(o)!1cm!(v)$) arc[start angle=\\n2, end angle=\\n1, radius=1cm]\n\t\tnode [text=xpurple, yshift=1pt] at ($(o)!7mm!(uv)$) {$\\theta$};\n\n\t\t\\draw[vector, xred] (o) -- ++(u) node [pos=1.1] {$\\vec{u}$};\n\t\t\\draw[vector, xblue] (o) -- ++(v) node [pos=1.1] {$\\vec{v}$};\n\t\t\\filldraw (o) circle (0.03);\n\n\t\t\\draw[thick, densely dashed] (u) -- ++(0,-1.94);\n\t\t\\filldraw[black] ($(u)+(0,-1.94)$) circle (0.04);\n\t\t\\draw [black, thick, decorate, decoration={brace, amplitude=3pt, raise=3pt, mirror}]\n\t\t(o) -- ($(u)+(0,-1.94)$) node[midway, below , yshift=-5pt]{$\\projection$};\n\t\\end{tikzpicture}\n\t\\caption{The projection of a vector $\\vu$ onto another vector $\\vv$ in the plane spanned by the two vectors.}\n\t\\label{fig:angle between two vectors in plane}\n\\end{figure}\n\nSince the origin, the head of $\\vu$ and the intersection point of the perpendicular line with $\\vv$ form a right triangle, using basic trigonometry we find that the cosine of the angle $\\ath$ is\n\\begin{equation}\n\t\\cos\\left(\\ath\\right) = \\frac{\\projection}{\\gnorm{\\vu}}.\n\t\\label{eq:cos from projection}\n\\end{equation}\n\nWe can now use this construct to define a product between $\\vu$ and $\\vv$: their \\emph{scalar product}. We define it as following:\n\\begin{equation}\n\t\\vu \\cdot \\vv = \\projection \\cdot \\gnorm{\\vv}.\n\t\\label{eq:scalar product}\n\\end{equation}\n\nSubtituting \\autoref{eq:cos from projection} into \\autoref{eq:scalar product} gives a very nice relation between the scalar product of two vectors and the angle between them:\n\\begin{equation}\n\t\\cos\\left( \\ath \\right) = \\frac{\\vu\\cdot\\vv}{\\gnorm{\\vu}\\gnorm{\\vv}}.\n\t\\label{eq:cos defined via scalar product}\n\\end{equation}\nThe angle between the two vectors is then isolated by applying the $\\arccos$ function on the right-hand side of \\autoref{eq:cos defined via scalar product}. A common form of this equation is the following:\n\\begin{equation}\n\t\\vu\\cdot\\vv = \\gnorm{\\vu}\\gnorm{\\vv}\\cos\\left( \\ath \\right).\n\t\\label{eq:scalar product via cos}\n\\end{equation}\n\nNote that the scalar product returns a number, i.e. in the terms of linear algebra - a scalar, and hence its name. Since it is commonly denoted with a dot between the two vectors, it is sometimes refered to as the \\emph{dot product}. A common notation for the scalar product is the so-called \\emph{bracket notation}:\n\\[\n\t\\langle \\vec{a},\\vec{b} \\rangle.\n\\]\nSometimes the comma in the notation is replaced by a vertical separator line:\n\\[\n\t\\langle \\vec{a}\\mid\\vec{b} \\rangle.\n\\]\nThis notation is very common in physics, and especially quantum physics where it is very useful and helps in simplifying many calculations. This will be discussed in more details in chapter/section TBD.\n\nLater in the section we will examine some common properties of the scalar product, and see how we can calculate it directly from the vectors in their column form. Beofre we do that, let's use what we learned about the scalar product so far to solve some easy problems in the examples below.\n\n\\begin{example}{Angle between two vectors}{}\n\tFind the scalar product of the vectors\n\t\\[\n\t\t\\vec{a} = \\colvec{1;1},\\ \\vec{b}=\\colvec{-1;1}.\n\t\\]\n\n\t\\textbf{Solution}:\n\t\n\tAs seen in \\autoref{example:orthobasis}, the angle between $\\vec{a}$ and $\\vec{b}$ is $\\frac{\\pi}{2}$. Therefore, their scalar product is \n\t\\begin{align*}\n\t\t\\vec{a}\\cdot\\vec{b} &= \\norm{a}\\norm{b}\\cos\\left(\\theta\\right)\\\\\n\t\t&= \\sqrt{2}\\sqrt{2}\\cos\\left( \\frac{\\pi}{2} \\right)\\\\\n\t\t&= 2\\cdot0 = 0.\n\t\\end{align*}\n\\end{example}\n\n\\begin{example}{Scalar product of two vectors}{scalar product two vectors}\n\tCalculate the scalar product of the two vectors $\\vec{u}=\\colvec{2;3;-1},\\ \\vec{v}=\\colvec{-1;0;2}$, given that the angle between them is $\\theta\\approx2.069\\approx\\ang{118.561}$.\n\n\t\\vspace{1em}\n\t\\textbf{Solution}:\n\n\tThe norms of the two vectors are\n\t\\begin{align*}\n\t\t\\norm{u} &= \\sqrt{2^{2}+3^{2}+(-1)^{2}} = \\sqrt{4+9+1} = \\sqrt{14} \\approx 3.742,\\\\\n\t\t\\norm{v} &= \\sqrt{(-1)^{2}+0^{2}+2^{2}} = \\sqrt{1+4} = \\sqrt{5} \\approx 2.236.\\\\\n\t\\end{align*}\n\n\tTherefore, their scalar product is\n\t\\[\n\t\t\\vec{u}\\cdot\\vec{v} \\approx \\sqrt{14}\\sqrt{5}\\cos(2.069) \\approx -4.\n\t\\]\n\\end{example}\n\nThe scalar product of any two vectors $\\vec{u},\\vec{v}$ has two important properties:\n\\begin{itemize}\n\t\\item It is commutative, i.e. $\\vec{u}\\cdot\\vec{v} = \\vec{v}\\cdot\\vec{u}$.\n\t\\item Scalars can be taken out of the product, i.e. $\\left(\\alpha \\vec{v}\\right)\\cdot\\vec{u} = \\vec{v}\\cdot\\left( \\alpha\\vec{u} \\right) = \\alpha\\left( \\vec{u}\\cdot\\vec{v} \\right)$.\n\t\\item It equals zero in only one of two cases:\n\t\t\\begin{enumerate}\n\t\t\t\\item One of the vectors (or both) is the zero vector, or\n\t\t\t\\item The angle $\\theta$ between the vectors is $\\frac{\\pi}{2}$, since then $\\cos(\\theta)=\\cos\\left(\\frac{\\pi}{2}\\right)=0$.\n\t\t\\end{enumerate}\n\\end{itemize}\n\nWhen the angle between two vectors is $\\frac{\\pi}{2}$ (remember: this is equivalent to $\\ang{90}$), we say that the two vectors are \\emph{orthogonal} to eacth other. Note that in the special case of 2- and 3-dimensional we say that the vectors are \\emph{perpendicular} to each other.\n\nThis is such an important fact that we will put effort into framing it nicely, so you (the reader) could memorize it well. How well should you memorize this? Such that if someone wakes you up in the middle of the night and asked you, you could easily repeat it\\footnote{For a humble fee, I'm willing to do this - just write me an email and we can discuss the terms ;)}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[\n\t\t\t%background rectangle/.style={fill=olive!2},\n\t\t\t%show background rectangle,\n\t\t\tevery node/.style={inner sep=0pt, text=xverydarkblue},\n\t\t\tnode distance=12mm\n\t\t]\n\t\t\\Large\n\n\t\t% Text\n\t\t\\node[text width=8cm, align=center] (u dot v){\n\t\t\t$\\vec{u}\\cdot\\vec{v} = 0$\n\t\t};\n\t\t\\node[align=center, below of=u dot v](equiv) {$\\Updownarrow$};\n\t\t\\node[align=center, below of=equiv](orthogonal) {$\\vec{u}$ and $\\vec{v}$ are orthogonal};\n\n\t\t% Corners\n\t\t\\node[shift={(-1cm,1cm)}, anchor=north west](CNW) at (u dot v.north west) {\\pgfornament[width=1.75cm, color=xverydarkblue]{63}};\n\t\t\\node[shift={(1cm,1cm)}, anchor=north east](CNE) at (u dot v.north east) {\\pgfornament[width=1.75cm, symmetry=v, color=xverydarkblue]{63}};\n\t\t\\node[shift={(-1cm,-3.7cm)}, anchor=south west](CSW) at (u dot v.south west) {\\pgfornament[width=1.75cm, symmetry=h, color=xverydarkblue]{37}};\n\t\t\\node[shift={(1cm,-3.7cm)}, anchor=south east](CSE) at (u dot v.south east) {\\pgfornament[width=1.75cm, symmetry=c, color=xverydarkblue]{41}};\n\n\t\t% Frames\n\t\t\\color{xverydarkblue}\n\t\t\\pgfornamenthline{CNW}{CNE}{north}{86}\n\t\t\\pgfornamenthline{CSW}{CSE}{south}{86}\n\t\t\\pgfornamentvline{CNW}{CSW}{west}{86}\n\t\t\\pgfornamentvline{CNE}{CSE}{east}{86}\n\t\\end{tikzpicture}\n\\end{figure}\n\nCalculating the scalar product of two vectors in $\\Rs{n}$ using their column form is extremely straight-forward: it is nothing more than the sum of the component-wise product of the two vectors, i.e. given\n\\[\n\t\\vec{u}=\\colvec{u_{1};u_{2};\\vdots;u_{n}},\\ \\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}},\n\\]\nthe scalar product $\\vec{u}\\cdot\\vec{v}$ is\n\\begin{equation}\n\t\\vec{u}\\cdot\\vec{v} = u_{1}v_{1} + u_{2}v_{2} + \\cdots + u_{n}v_{n} = \\sum\\limits_{k=1}^{n}u_{i}v_{i}.\n\t\\label{eq:scalar product in column form}\n\\end{equation}\n\n\\begin{example}{Angle between two vectors}{}\n\tCalculate the scalar product of the two vectors $\\vec{a}=\\colvec{1;1}$ and $\\vec{b}=\\colvec{-1;1}$ using the above formula (\\autoref{eq:scalar product in column form}).\n\n\t\\vspace{1em}\n\t\\textbf{Solution}:\n\t\n\tWe simply substitute $\\vec{a}$ and $\\vec{b}$ into the equation:\n\t\\[\n\t\t\\vec{a}\\cdot\\vec{b} = 1\\cdot(-1) + 1\\cdot1 = -1+1 = 0,\n\t\\]\n\twhich is exactly the result we got using the previous method.\n\\end{example}\n\n\\begin{example}{Scalar product of two vectors - algebraicly}{}\n\tCalculate the scalar product $\\vec{u}\\cdot\\vec{v}$ from \\autoref{example:scalar product two vectors} using \\autoref{eq:scalar product in column form}.\n\n\t\\vspace{1em}\n\t\\textbf{Solution}:\n\n\t\\[\n\t\t\\vec{u}\\cdot\\vec{v} = 2\\cdot(-1) + 3\\cdot0 + (-1)\\cdot2 = -2-2 = -4,\n\t\\]\n\texactly the result we got in \\autoref{example:scalar product two vectors}.\n\\end{example}\nThe norm of a vector can be calculated using the scalar product: given a vector $\\vec{v}=\\colvec{v_{1};v_{2};\\vdots;v_{n}}$,\n\\begin{equation}\n\t\\vec{v}\\cdot\\vec{v} = v_{1}v_{1} + v_{2}v_{2} + \\cdots + v_{n}v_{n} = v_{1}^{2} + v_{2}^{2} + \\cdots + v_{n}^{2} = \\norm{v}^{2}.\n\t\\label{eq:scalar product to norm}\n\\end{equation}\n\nWe therefore usually define the norm in terms of the scalar product:\n\\begin{equation}\n\t\\norm{v} = \\sqrt{\\vec{v}\\cdot\\vec{v}}.\n\t\\label{eq:norm from scalar product}\n\\end{equation}\nThis might seem unconsequential at the moment, but it will become very useful when we generalize linear algebra to more abstract vector spaces (\\autoref{chapter:linear algebra rigorous}).\n\nAny vector can be \\emph{decomposed} into its projections on $n$ orthogonal directions. In fact, this is exactly what we do when we write a vector as a linear combination of the vectors of an orthogonal basis: consider for example the vector\n\\[\n\t\\vec{v} = \\colvec{v_{1};v_{2};\\vdots;v_{n}}.\n\\]\nIt can be written as the linear combination\n\\[\n\t\\vec{v} = v_{1}\\eb{1} + v_{2}\\eb{2} + \\cdots + v_{n}\\eb{n} = \\sum\\limits_{i=1}^{n}v_{i}\\eb{i},\n\\]\nwhere in turn any element $v_{i}$ is the projection of $\\vec{v}$ on the basis vector $\\eb{i}$:\n\\begin{equation}\n\tv_{i} = \\proj{\\eb{i}}{\\vec{v}},\n\t\\label{eq:}\n\\end{equation}\nand thus the component $v_{i}\\eb{i}=\\left(\\proj{\\eb{i}}{\\vec{v}}\\right)\\eb{i}$ is itself a vector of norm $v_{i}$ pointing at the direction $\\eb{i}$. In general, given an orthogonal basis set $B=\\left\\{ \\vec{b}_{1},\\ \\vec{b}_{2},\\ \\cdots,\\ \\vec{b}_{n} \\right\\}$, any vector in $\\Rs{n}$ can be decomposed as follows:\n\\begin{equation}\n\t\\vec{v} = \\sum\\limits_{i=1}^{n}\\left(\\proj{\\hat{b}_{i}}{\\vec{v}}\\right)\\hat{b}_{i}.\n\t\\label{eq:vector decomposition to orthogonal directions}\n\\end{equation}\n\nIn the case where $B$ is an orthonormal basis set, we know that each of its vector is a unit vector (i.e. $\\norm{b_{i}}=1$), and using \\autoref{eq:scalar product} we can re-write \\autoref{eq:vector decomposition to orthogonal directions} as\n\\begin{equation}\n\t\\vec{v} = \\sum\\limits_{i=1}^{n}\\left( \\vec{v}\\cdot\\hat{b}_{i} \\right)\\hat{b}_{i}.\n\t\\label{eq:vector decomposition in orthonormal basis set}\n\\end{equation}\n\n\\begin{example}{Decomposing a vector}{}\n\tEXAMPLE TBD\n\\end{example}\n\n\n\\subsection{The cross product}\nAnother commonly used product of two vectors is the so-called \\emph{cross product}. Unlike the scalar product, it is only really valid in $\\Rs{2},\\ \\Rs{3}$ and $\\Rs{7}$, of which we will focus on $\\Rs{3}$ and touch a bit on its uses in $\\Rs{2}$. Also in contrast to the scalar product, the cross product in $\\Rs{3}$ results in a vector rather than a scalar - therefore the product is sometimes known as the \\emph{vector product}. The cross product uses the notation $\\vec{a}\\times\\vec{b}$, from which it derives its name.\n\nWe start with the definition of the cross product in $\\Rs{2}$: the cross product of two vectors $\\vu=\\vutd$ and $\\vv=\\vvtd$ is the (signed) area of the parallelogram defined by the two vectors (see \\autoref{fig:cross_product_in_R2}).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\txmin=-1, xmax=4,\n\t\t\tymin=-1, ymax=4,\n\t\t\txticklabels={,},\n\t\t\tyticklabels={,},\n\t\t]\n\t\t\t\\tikzset{every node/.style={font=\\large}}\n\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (1,2.5) -- (3,3) -- (2,0.5) -- cycle;\n\t\t\t\\draw[vector, xred] (0,0) -- (1,2.5) node[midway, above left] {$\\vec{u}$};\n\t\t\t\\draw[vector, xblue] (0,0) -- (2,0.5) node[midway, above] {$\\vec{v}$};\n\t\t\t\\draw[vector, xred, dashed] (2,0.5) -- (3,3);\n\t\t\t\\draw[vector, xblue, dashed] (1,2.5,0) -- (3,3);\n\t\t\t\\node[xpurple] at (1.5,1.75) {$\\vec{u}\\times\\vec{v}$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{The cross product in $\\Rs{2}$  of two vectors $\\vu=\\vutd$ and $\\vv=\\vvtd$ as the signed area of the parallogram defined by the vectors.}\n\t\\label{fig:cross_product_in_R2}\n\\end{figure}\n\nThe value of the parallelogram defined by $\\vu$ and $\\vv$ is\n\\begin{equation}\n\t\\vu\\times\\vv = \\gnorm{\\vu}\\gnorm{\\vv}\\sin \\left( \\ath \\right),\n\t\\label{eq:cross_product_geometric_area}\n\\end{equation}\nwhere $\\ath$ is the angle between the vectors. This is extremely similar to the scalar product, and we can use this fact to find how to calculate the cross product from vectors in column form: if we replace $\\vu$ by a vector orthogonal to it, denoted by $\\vu^{\\perp}$, the cross product is then\n\\begin{equation}\n\t\\vu\\times\\vv = \\gnorm{\\vu^{\\perp}}\\gnorm{\\vv}\\sin \\left( \\ath+\\frac{\\pi}{2} \\right),\n\t\\label{eq:cross_product_to_dot_product_part1}\n\\end{equation}\nsince the angle between $\\vu^{\\perp}$ and $\\vv$ is $\\frac{\\pi}{2}$ more than that between $\\vu$ and $\\vv$. Using the fact that $\\sin \\left( \\theta+\\frac{\\pi}{2} \\right) = \\cos \\left( \\theta \\right)$, we get the equality\n\\begin{align}\n\t\\vu\\times\\vv &= \\gnorm{\\vu^{\\perp}}\\gnorm{\\vv}\\sin \\left( \\ath+\\frac{\\pi}{2} \\right)\\nonumber\\\\\n\t\t\t\t &= \\gnorm{\\vu^{\\perp}}\\gnorm{\\vv}\\cos \\left( \\ath \\right)\\nonumber\\\\\n\t\t\t\t &= \\vu^{\\perp}\\cdot\\vv.\n\t\\label{eq:cross_product_to_dot_product_part2}\n\\end{align}\nIn $\\Rs{2}$, any vector $\\vu=\\vutd$ has two vectors orthogonal to it: $\\colvec{\\textcolor{xred}{-b};\\textcolor{xred}{a}}$ and $\\colvec{\\textcolor{xred}{b};\\textcolor{xred}{-a}}$. Choosing the former gives\n\\begin{equation}\n\t\\vu\\times\\vv = \\colvec{\\textcolor{xred}{-b};\\textcolor{xred}{a}} \\cdot \\vvtd = -\\textcolor{xred}{b}\\textcolor{xblue}{c}+\\textcolor{xred}{a}\\textcolor{xblue}{d},\n\t\\label{eq:cross_product_2d_algebraic}\n\\end{equation}\nwhile choosing the latter gives\n\\begin{equation}\n\t\\vu\\times\\vv = \\colvec{\\textcolor{xred}{b};\\textcolor{xred}{-a}} \\cdot \\vvtd = \\textcolor{xred}{b}\\textcolor{xblue}{c}-\\textcolor{xred}{a}\\textcolor{xblue}{d}.\n\t\\label{eq:}\n\\end{equation}\nThese two forms are the opposite of each other - i.e. if one yields the value $4$, the other yields the value $-4$. We will see which one is used in a moment.\n\nOn to $\\Rs{3}$: geometrically, the cross product of two vectors $\\vu,\\vv\\in\\Rs{3}$ is defined as a \\textbf{vector} $\\vw\\in\\Rs{3}$ which is \\textbf{orthogonal to both} $\\vu$ and $\\vv$, and with norm of the same magnitude as the product would have in $\\Rs{2}$, i.e.\n\\begin{equation}\n\t\\gnorm{\\vw} = \\gnorm{\\vu}\\gnorm{\\vv}\\sin\\left(\\ath\\right).\n\t\\label{eq:cross product geometry}\n\\end{equation}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\huge\n\n\t% Plane\n\t\t\\draw[-, dashed, very thick, fill=xgreen!30] (0,0,0) -- (0,0,7) -- (7,0,7) -- (7,0,0) -- cycle;\n\n\t% Coordinates\n\t\t\\coordinate (o) at (1,0,3);\n\t\t\\coordinate (u) at (2,0,2.5);\n\t\t\\coordinate (v) at (4,0,-2);\n\t\t\\coordinate (w) at (0,3,0);\n\n\t% Angle\n\t\t\\draw[very thick, xpurple, cap=round] (2,0,4.2) arc [start angle=-70, end angle=33, x radius=0.7, y radius=0.4];\n\t\t\\node[text=xpurple] at ($(o)+(0.5,-0.13,0)$) {\\large$\\theta$};\n\n\t% Vectors\n\t\t\\draw[vector, xred] (o) -- ++(u) node [pos=1.1, xshift=3pt] {$\\vec{u}$};\n\t\t\\draw[vector, xblue] (o) -- ++(v) node [pos=1.1, xshift=-5pt] {$\\vec{v}$};\n\t\t\\draw[vector, xpurple] (o) -- ++(w) node [pos=1.1, xshift=1cm] {$\\vw=\\vu\\times\\vv$};\n\n\t% Perpendiculars\n\t\t\\tikzset{rightangle/.style={-, thick, fill=gray!50, fill opacity=0.5}}\n\t\t\\draw[rightangle] (o) -- ++(0.3,0,-0.15) -- ++(0,0.3,0) -- ++(-0.3,0,0.15) -- cycle;\n\t\t\\draw[rightangle] (o) -- ++(0.4,0,0.5) -- ++(0,0.3,0) -- ++(-0.4,0,-0.5) -- cycle;\n\t\\end{tikzpicture}\n\t\\caption{The cross product of the vectors $\\vu$ and $\\vv$ relative to the plane spanned by the two vectors.}\n\t\\label{fig:cross product}\n\\end{figure}\n\nThe direction of $\\vu\\times\\vv$ is determined by the \\emph{right-hand rule}: using a person's right hand, when $\\vu$ points in the direction of their index finger and $\\vv$ points in the direction of their middle finger, then vector $\\vw=\\vu\\times\\vv$ points in the direction of their thumb:\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.35]{figures/linear_algebra/rhr.pdf}\n\\end{figure}\n\nThe cross product is \\textbf{anti-commutative}, i.e. changing the order of the vectors results in inverting the product:\n  \\begin{equation*}\n  \\vu\\times\\vv = -\\left( \\vv\\times\\vu \\right).\n  \\end{equation*}\n\nWhen the vectors are given as column vectors $\\vu=\\colvec{\\textcolor{xred}{u_{x}};\\textcolor{xred}{u_{y}};\\textcolor{xred}{u_{z}}},\\ \\vv=\\colvec{\\textcolor{xblue}{v_{x}};\\textcolor{xblue}{v_{y}};\\textcolor{xblue}{v_{z}}}$, the resulting cross product is\n\n\\begin{equation}\n\t\\vu\\times\\vv = \\begin{pmatrix}\\textcolor{xred}{u_{y}}\\textcolor{xblue}{v_{z}}-\\textcolor{xred}{u_{z}}\\textcolor{xblue}{v_{y}}\\\\\\textcolor{xred}{u_{z}}\\textcolor{xblue}{v_{x}}-\\textcolor{xred}{u_{x}}\\textcolor{xblue}{v_{z}}\\\\\\textcolor{xred}{u_{x}}\\textcolor{xblue}{v_{y}}-\\textcolor{xred}{u_{y}}\\textcolor{xblue}{v_{x}}\\end{pmatrix}\n\t\\label{eq:cross product calculation}\n\\end{equation}\n\n\\begin{note}{The cross product of the standard basis vectors}{}\n\tThe cross product of two of the standard basis vectors in $\\Rs{3}$ is the third basis vector. Its sign ($\\pm$) is determined by a cyclic rule:\n\t\\begin{equation*}\n\t\t\\text{sign}\\left( \\eb{i}\\times\\eb{j} \\right) =\n\t\t\\begin{cases}\n\t\t\t1 & \\text{if } (i,j)\\in \\left\\{(1,2),\\ (2,3),\\ (3,1)\\right\\},\\\\\n\t\t\t-1 & \\text{if } (i,j)\\in \\left\\{(3,2),\\ (2,1),\\ (1,3)\\right\\},\\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\end{equation*}\n\\end{note}\n\\begin{challenge}{Orthogonalily of the cross product}{}\n\tUsing component calculation and utilizing the dot product, show that $\\vec{a}\\times\\vec{v}$ is indeed orthogonal to both $\\vec{a}$ and $\\vec{b}$.\n\\end{challenge}\n\n\\subsection{Normal vectors}\n\nA special kind of vector in $\\Rs{3}$ is the so-called \\emph{normal vector} to a plane $\\mathbf{P}$: this vector, usually denoted as $\\normalVec{n}{P}$, is pointing at the orthogonal direction to any vector of the plane (see XXX). Given one knows three points on the plane, its normal vector can be calculated: say the following three points in $\\mathbf{P}$ are given (for visualizing the following steps see YYY):\n\\begin{align}\n\tp &= (p_{x}, p_{y}, p_{z})\\nonumber\\\\\n\tq &= (q_{x}, q_{y}, q_{z})\\nonumber\\\\\n\tr &= (r_{x}, r_{y}, r_{z}),\n\t\\label{eq:three points in a plane}\n\\end{align}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}{0.3\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\twidth=5cm, height=5cm,\n\t\t\t\t\taxis line style={draw=none},\n\t\t\t\t\ttick style={draw=none},\n\t\t\t\t\tz buffer=sort,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\t\txtick=\\empty,\n\t\t\t\t\tytick=\\empty,\n\t\t\t\t\tztick=\\empty,\n\t\t\t\t\tview={50}{20},\n\t\t\t\t]\n\t\t\t\t\\addplot3[surf, faceted color=xgreen!50!black!25, fill=xgreen!20, opacity=0.9, domain=-4:4, y domain=-4:4, samples=7] {0.4*y};\n\t\t\t\t\\draw[vector] (0,0,0) -- (0,-1.2,3) node[pos=1.3] {$\\normalVec{n}{P}$};\n\t\t\t\t\\draw[thick, fill=black!50, fill opacity=0.3] (0,1,0.4) -- (0,0.62860932,1.32847669) -- (0,-0.37139068,0.92847669) -- (0,0,0) -- cycle;\n\t\t\t\t\\draw[thick, fill=black!50, fill opacity=0.3] (0,0,0) -- (0,-0.37139068,0.92847669) -- (1,-0.37139068,0.92847669) -- (1,0,0) -- cycle;\n\t\t\t\t\\node[text=xgreen] at (4,3,3) {$\\mathbf{P}$};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{The normal vector to $\\mathbf{P}$.}\n\t\t\\label{fig:normalVec1}\n\t\\end{subfigure}\n\t\\begin{subfigure}{0.3\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\twidth=5cm, height=5cm,\n\t\t\t\t\taxis line style={draw=none},\n\t\t\t\t\ttick style={draw=none},\n\t\t\t\t\tz buffer=sort,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\t\txtick=\\empty,\n\t\t\t\t\tytick=\\empty,\n\t\t\t\t\tztick=\\empty,\n\t\t\t\t\tview={50}{20},\n\t\t\t\t]\n\t\t\t\t\\addplot3[surf, faceted color=xgreen!50!black!25, fill=xgreen!20, opacity=0.9, domain=-4:4, y domain=-4:4, samples=7] {0.4*y};\n\t\t\t\t\\addplot3[only marks, mark=*, point meta=explicit symbolic,nodes near coords] coordinates {\n\t\t\t\t\t(1,2,0.8)[$p$] (-2,-0.5,-0.2)[$q$] (1.5,-2,-0.8)[$r$]\n\t\t\t\t};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Finding three points on the plane.}\n\t\t\\label{fig:normalVec2}\n\t\\end{subfigure}\n\t\\begin{subfigure}{0.3\\textwidth}\n\t\t\\begin{tikzpicture}\n\t\t\t\\begin{axis}[\n\t\t\t\t\twidth=5cm, height=5cm,\n\t\t\t\t\taxis line style={draw=none},\n\t\t\t\t\ttick style={draw=none},\n\t\t\t\t\tz buffer=sort,\n\t\t\t\t\txmin=-4, xmax=4,\n\t\t\t\t\tymin=-4, ymax=4,\n\t\t\t\t\tzmin=-4, zmax=4,\n\t\t\t\t\txtick=\\empty,\n\t\t\t\t\tytick=\\empty,\n\t\t\t\t\tztick=\\empty,\n\t\t\t\t\tview={50}{20},\n\t\t\t\t]\n\t\t\t\t\\addplot3[surf, faceted color=xgreen!50!black!25, fill=xgreen!20, opacity=0.9, domain=-4:4, y domain=-4:4, samples=7] {0.4*y};\n\t\t\t\t\\draw[vector, xred]  (1,2,0.8) -- (-2,-0.5,-0.2) node[midway, above] {$\\vec{v}_{pq}$};\n\t\t\t\t\\draw[vector, xblue] (1,2,0.8) -- (1.5,-2,-0.8)  node[midway, right, yshift=-2pt] {$\\vec{v}_{pr}$};\n\t\t\t\t\\addplot3[only marks, mark=*, point meta=explicit symbolic,nodes near coords] coordinates {\n\t\t\t\t\t(1,2,0.8)[$p$] (-2,-0.5,-0.2)[$q$] (1.5,-2,-0.8)[$r$]\n\t\t\t\t};\n\t\t\t\\end{axis}\n\t\t\\end{tikzpicture}\n\t\t\\caption{Finding two vectors on the plane.}\n\t\t\\label{fig:normalVec3}\n\t\\end{subfigure}\n\t\\caption{A normal vector $\\normalVec{n}{P}$ to the plane $\\mathbf{P}$.}\n\t\\label{fig:normalVec}\n\\end{figure}\n\nWe can get two vectors lying on the plane by first considering the points as vectors, i.e.\n\\begin{equation}\n\t\\vec{p} = \\colvec{p_{x};p_{y};p_{z}},\\ \\vec{q} = \\colvec{q_{x};q_{y};q_{z}},\\ \\vec{r} = \\colvec{r_{x};r_{y};r_{z}}.\n\t\\label{eq:three points in a plane as vectors}\n\\end{equation}\n\nThen, we calculate two vectors on the plane by subtraction, e.g.\n\\begin{align}\n\t\\vec{v}_{pq} &= \\vec{q} - \\vec{p} = \\colvec{q_{x}-p_{x};q_{y}-p_{y};q_{z}-p_{z}},\\nonumber\\\\\n\t\\vec{v}_{pr} &= \\vec{r} - \\vec{p} = \\colvec{r_{x}-p_{x};r_{y}-p_{y};r_{z}-p_{z}}.\n\t\\label{eq:two vectors in the plane}\n\\end{align}\n\nThe normal vector $\\hat{n}_{\\bm{p}}$ must be orthogonal to both $\\vec{v}_{pq}$ and $\\vec{v}_{pr}$ - and so we use the cross product to find its direction:\n\\begin{equation}\n\t\\vec{n}_{\\mathbf{P}} = \\vec{v}_{pq} \\times \\vec{v}_{pr} = \\colvec{(q_{y}-p_{y})(r_{z}-p_{z}) - (r_{y}-p_{y})(q_{z}-p_{z});(p_{x}-q_{x})(r_{z}-p_{z}) - (r_{x}-p_{x})(q_{z}-p_{z});(q_{x}-p_{x})(r_{y}-p_{y}) - (r_{x}-p_{x})(p_{y}-q_{y})}.\n\t\\label{eq:normal to plane}\n\\end{equation}\n\nNormalizing $\\vec{n}_{\\mathbf{P}}$ will then yield the normal vector $\\normalVec{n}{P}$\\footnote{I leave this as a challenge to the reader, because I'm lazy.}.\n\n\\begin{note}{Sign of normal vectors}{}\n\tThe vector $\\vec{m}=-\\normalVec{n}{P}$ has all the properties of $\\normalVec{n}{P}$, and is indeed a normal vector to $\\mathbf{P}$. The choice of which of the two vectors to use depends on the application. For now, we do not elaborate on this further.\n\\end{note}\n\nTo wrap up the vectors section, we present and solve a single problem in the following example.\n\n\\begin{example}{Reflection of light rays}{reflection}\n\tA ray light hits a mirror, modelled by the plane $\\mathbf{P}$ which is defined by the normal vector $\\normalVec{n}{P}$. The direction of the light ray is given by $\\vec{d}$. What is the direction of the reflected light ray $\\vec{r}$? Recall that both the incident and reflected rays are at the same angle in respect to the normal vector of $\\normalVec{n}{P}$, and that the incident ray lie on the plane defined by $\\vec{d}$ and $\\normalVec{n}{P}$.\n\n\\centering\n\\begin{tikzpicture}\n\t\\begin{axis}[\n\t\t\twidth=6.5cm, height=6.5cm,\n\t\t\taxis line style={draw=none},\n\t\t\ttick style={draw=none},\n\t\t\tz buffer=sort,\n\t\t\txmin=-4, xmax=4,\n\t\t\tymin=-4, ymax=4,\n\t\t\tzmin=-4, zmax=4,\n\t\t\txtick=\\empty,\n\t\t\tytick=\\empty,\n\t\t\tztick=\\empty,\n\t\t\tview={80}{15},\n\t\t]\n\t\t\\addplot3[surf, faceted color=xblue!50, fill=xblue!20, opacity=0.9, domain=-4:4, y domain=-4:4, samples=7] {0.4*y};\n\t\t\\draw[vector] (0,0,0) -- (0,-0.6,1.5) node[pos=1.2] {$\\normalVec{n}{P}$};\n\t\t\\draw[vector, xred] (0,-2,1) -- (0,0,0) node[pos=-0.1] {$\\vec{d}$};\n\t\t\\draw[vector, xgreen] (0,0,0) -- (0,0.76,2.1) node[pos=1.1] {$\\vec{r}$};\n\t\t\\node[text=xblue!50!black] at (4,2.5,1.5) {$\\mathbf{P}$};\n\t\\end{axis}\n\\end{tikzpicture}\n%note: this figure needs to be converted into pespective view or something, right now its a bit meh\n\n\\flushleft\nWe can rotate our viewpoint of the problem, looking at $\\mathbf{P}$ from the side and in such a way that we look head-on at the plane spanned by $\\normalVec{n}{P}$ and $\\vec{d}$:\n\n\\vspace{1em}\n\\centering\n\\begin{tikzpicture}\n\t\\draw[thick, xred, fill=xred!20] (0,0) -- (0,1) arc (90:135:1) -- cycle;\n\t\\draw[thick, xgreen, fill=xgreen!20] (0,0) -- (0,1) arc (90:45:1);\n\t\\node[xred] at (-0.25,0.6) {$\\theta$};\n\t\\node[xgreen] at (0.25,0.6) {$\\theta$};\n\t\\draw[line width=2pt, xblue] (-2,0) -- (2,0) node[above] {$\\mathbf{P}$};\n\t\\draw[vector] (0,0) -- (0,2.5) node[pos=1.1] {$\\normalVec{n}{P}$};\n\t\\draw[vector, xred] (-2,2) -- (0,0) node[pos=-0.1] {$\\vec{d}$};\n\t\\draw[vector, xred, dashed] (0,0) -- (2,-2) node[pos=1.1] {$\\vec{d}$};\n\t\\draw[vector, xgreen] (0,0) -- (2,2) node[pos=1.05] {$\\vec{r}$};\n\\end{tikzpicture}\n\n\\flushleft\n(the dashed red vector in the above figure represents the vector incident ray, $\\vec{d}$, moved such that its origin lies at the origin of the other vectors)\n\nAs with any vector, we can decompose $\\vec{d}$ to its projections on the vectors of an orthonormal basis set (\\autoref{eq:vector decomposition in orthonormal basis set}). Since we reduced the problem to two dimensions, we need a basis of two orthonormal directions: we choose one to be $\\normalVec{n}{P}$, and the other orthogonal to it (in the figure above it is in the horizontal direction) which we call $\\hat{p}$. The decomposition of $\\vec{d}$ then reads:\n\\[\n\t\\vec{d} = \\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} + \\left( \\vec{d}\\cdot\\hat{p} \\right)\\hat{p}.\n\\]\nSince there are only two vectors in the basis set $\\left\\{ \\normalVec{n}{P},\\hat{p} \\right\\}$, we can actually write the component $\\left( \\vec{d}\\cdot\\hat{p} \\right)\\hat{p}$ as $\\vec{d}-\\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P}$, yielding a rather silly looking expression for $\\vec{d}$:\n\\[\n\t\\vec{d} = \\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} + \\left[ \\vec{d}-\\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} \\right].\n\\]\nHowever, in closer inspection the above expression is not at all silly, and is actually very similar to the reflected vector $\\vec{r}$: since they are both of same norm and oposing directions with respect to the direction $\\normalVec{n}{P}$, we can write $\\vec{r}$ as\n\\[\n\t\\vec{r} = -\\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} + \\left[ \\vec{d}-\\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} \\right].\n\\]\nFrom the above expressions for $\\vec{d}$ and $\\vec{r}$ we can isolate an expression for $\\vec{r}$ as a function of $\\vec{d}$ and $\\normalVec{n}{P}$:\n\\begin{align*}\n\t\\vec{r} &= d - \\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P} - \\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P}\\\\\n\t&= d-2\\left( \\vec{d}\\cdot\\normalVec{n}{P} \\right)\\normalVec{n}{P}.\n\\end{align*}\n\\end{example}\n\nNOTE: ADD DISCUSSION ABOUT RIGHT- AND LEFT-HANDED SPACES/ORIENTATIONS!\n", "meta": {"hexsha": "96d4f69c47f065409323d28eb1301cad63906761", "size": 75217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_intuitive/vectors.tex", "max_stars_repo_name": "pelegs/maths_book", "max_stars_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/linear_algebra_intuitive/vectors.tex", "max_issues_repo_name": "pelegs/maths_book", "max_issues_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/linear_algebra_intuitive/vectors.tex", "max_forks_repo_name": "pelegs/maths_book", "max_forks_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 50.1112591606, "max_line_length": 927, "alphanum_fraction": 0.6523658216, "num_tokens": 27867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.9136765163620469, "lm_q1q2_score": 0.781971084407533}}
{"text": "\\chapter{Signal Processing Basics}\r\n\\label{chap:appendixsignalprocessing}\r\nThe aim of this appendix chapter is to provide the reader some basic knowledge in signal processing, Fourier transformations and related mathematical concepts. It is recommended to understand all the mathematical concepts mentioned in this appendix chapter in order to be able to follow all derivation steps performed during this thesis. \r\n\r\n\\section{Signals in Signal Processing}\r\nA \\emph{signal} is a function that conveys information about the behavior or attributes of some phenomenon. In the physical world, any quantity that exhibits variation in time or in space (such as an image) is potentially a signal. Such a signal might carry information about the state of a physical system, or might convey a message between observers. \\\\\r\n\r\n\\section{Fourier Transformation}\r\nThe \\emph{Fourier transform} is a mathematical tool which allows to transform a given function or rather a given signal from defined over a time- (or spatial-) domain into its corresponding frequency-domain. \\\\\r\n\r\nThe Fourier transform is an important image processing tool which is used to decompose an image into its sine and cosine components. The output of such a Fourier transformation represents the image in its frequency domain. On the other hand, the input image is usually in the spatial domain. In the frequency domain of the Fourier transformation of an image, each point represents a particular frequency contained in the spatial domain image. \\\\\r\n\r\nNext let us consider some mathematical definitions of Fourier transformations. Let $f$ be a measurable function over $\\mathds{R}^n$. Then, its continuous \\emph{Fourier Transformation} (\\textbf{FT}) $\\mathcal{F}\\{f\\}$$\\footnote{Note that for simplification purposes we omit some constant factors in our definitions for the Fourier transformation.}$ is defined as:\r\n \r\n\\begin{equation}\r\n  \\mathcal{F}_{FT}\\{f\\}(w) = \\int_{\\mathds{R}^n} f(x)e^{-iwt} dt\r\n  \\label{eq:cft}\r\n\\end{equation}\r\n\r\nwhereas its \\emph{inverse transformation} is defined like the following which allows us to obtain back the original signal:\r\n\r\n\\begin{equation}\r\n  \\mathcal{F}_{FT}^{-1}\\{f\\}(w) = \\int_{\\mathds{R}} \\mathcal{F}\\{w\\}e^{iwt} dt\r\n  \\label{eq:icft}\r\n\\end{equation}\r\n\r\nWhere $w$ usually denotes the \\emph{angular frequency}, which is equal to \r\n\\begin{equation}\r\n  w = \\frac{2 \\pi}{T} = 2 \\pi v_f \r\n\\end{equation}\r\n\r\nFurthermore denotes $T$ the \\emph{period} of the spectrum and $v_f$ is its corresponding \\emph{frequency}. Notice that the definitions we use for the Fourier transformation correspond to the definition physicist and mathematicians typically use. However, there are other possibilities to define the Fourier transformation such as the definition used in electrical engineering. For further information about this kind of Fourier transformation please have a look at section $\\ref{sec:electricalengeneeringftconvention}$. \\\\\r\n\r\nBy using Fourier analysis$\\footnote{Fourier analysis is the technique to approximate a function by a sums of simpler trigonometric functions.}$ we can derive \\emph{Discrete Time Fourier Transform} (\\textbf{DTFT}). The DTFT operates on a discrete function. Such an input function is often created by digitally sampling a continuous function. The DTFT generates a continuous and periodic signal in the frequency domain. This operator is defined as the following:\r\n\r\n\\begin{equation}\r\n  \\mathcal{F}_{DTFT}\\{f\\}(w) = \\sum_{-\\infty}^{\\infty} f(x) e^{-iwk}\r\n  \\label{eq:dtft}\r\n\\end{equation}\r\n\r\nNote that the DTFT is not practically suitable for digital signal processing since there a signal can be measured only in a finite number of points. Thus, by discretize its frequency domain we get the \\emph{Discrete Fourier Transformation} (\\textbf{DFT}) of the input signal:\r\n\r\n\\begin{equation}\r\n  \\mathcal{F}_{DFT}\\{f\\}(w) = \\sum_{n=0}^{N-1} f(x) e^{-iw_{n}k}\r\n  \\label{eq:dft}\r\n\\end{equation}\r\n\r\nWhere the angular frequency $w_n$ is defined as the following:\r\n\r\n\\begin{equation}\r\n  w_n = \\frac{2\\pi n}{N} \r\n\\end{equation}\r\n\\noindent\r\nand $N$ is the number of samples within an equidistant period sampling. \\\\\r\n\r\nAny continuous function $f(t)$ can be expressed as a series of sines and cosines. This representation is called the \\emph{Fourier Series} (\\textbf{FS}) of $f(t)$.\r\n\\begin{equation}\r\n  f(t) = \\frac{1}{2}a_0 + \\sum_{n=1}^{\\infty} a_n cos(nt) + \\sum_{n=1}^{\\infty} b_n cos(nt)\r\n  \\label{eq:dfs}\r\n\\end{equation}\r\n\r\nwhere\r\n\r\n\\begin{align}\r\n    a_0 = \\int_{-\\pi}^{\\pi} f(t) dt \\nonumber \\\\\r\n    a_n = \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi} f(t) cos(nt) dt \\nonumber \\\\\r\n    b_n = \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi} f(t) sin(nt) dt\r\n\\end{align}\r\n\r\nFigure $\\ref{fig:contdiscft}$ illustrated the relationships between the different Fourier transformation types.\r\n\r\n\\begin{figure}[H]\r\n  \\centering\r\n  \\includegraphics[scale=0.5]{background/dcft.png}\r\n  \\caption[Relationships between of Different Fourier Transformations]{Relationship$\\footnotemark$ between the continuous Fourier transform and the discrete Fourier transform: Left column: A continuous function (top) and its Fourier transform $\\ref{eq:cft}$ (bottom). Center-left column: Periodic summation of the original function (top). Fourier transform (bottom) is zero except at discrete points. The inverse transform is a sum of sinusoids called Fourier series $\\ref{eq:dfs}$. Center-right column: Original function is discretized (multiplied by a Dirac comb) (top). Its Fourier transform (bottom) is a periodic summation (DTFT) of the original transform. Right column: The DFT $\\ref{eq:dft}$ (bottom) computes discrete samples of the continuous DTFT $\\ref{eq:dtft}$. The inverse DFT (top) is a periodic summation of the original samples.}\r\n\\label{fig:contdiscft}\r\n\\end{figure}\r\n\\footnotetext{This image has been taken from \\texttt{http://en.wikipedia.org/wiki/Discrete\\textunderscore Fourier\\textunderscore transform}}\r\n\r\nTable $\\ref{tab:ftoperatorsdependencies}$ represents a summary of the different Fourier transformation types. It tells the reader which Fourier Operator take what kind of input signal and what properties its corresponding output signal will have.\r\n\r\n\\begin{table}[H]\r\n    \\begin{tabular}{l|l|l}\r\n    \\hline\r\n    Spatial signal $f(t)$ is & Operator & Transformed frequency signal $\\hat{f}(\\omega)$ is\\\\\r\n    \\hline\r\n    continuous and periodic in $t$ & $FS$ see Eq. $\\ref{eq:dfs}$ & only discrete in $\\omega$ \\\\\r\n    only continuous in $t$ & $FT$ see Eq. $\\ref{eq:cft}$ & only continuous in $\\omega$\\\\\r\n    only discrete in $t$ & $DTFT$ see Eq. $\\ref{eq:dtft}$ & continuous and periodic in $\\omega$\\\\\r\n    discrete and periodic in $t$ & $DFT$ see Eq.$\\ref{eq:dft}$ & discrete and periodic in $\\omega$\\\\\r\n    \\hline\r\n    \\end{tabular}\r\n\\caption[Fourier Transform Mapping]{Fourier operator to apply for a given spatial input signal and the properties of its resulting output signal in frequency space}\r\n\\label{tab:ftoperatorsdependencies}\r\n\\end{table}\r\n\r\n\\section{The Convolution Operator}\r\nIn signal processing we use the \\emph{convolution} operator mostly for performing any kind of filtering operations applied on given signals.\r\nMathematically, this operator is a form of combining two signals (i.e. weighting one signal by the other). The output of a convolution is always a continuous function. The convolution $f*g$ of two functions $f$, $g$$\\colon \\mathds{R}^n \\to \\mathds{C} $ is defined as:  \r\n\\begin{equation}\r\n  \\mathcal (f*g)(t) = \\int_{\\mathds{R}^n} f(t)g(t-x) dx\r\n  \\label{eq:convolution}\r\n\\end{equation}\r\n\r\nNote that the Fourier transform of the convolution of two functions is equal to the product of their Fourier transforms. In other words a convolution in a spatial domain is equivalent to a multiplication in frequency domain. Therefore, the inverse Fourier transform of the product of two Fourier transforms is equal to the convolution of the two inverse Fourier transforms. \\\\\r\n\r\n\\section{Taylor Series}\r\nIn mathematics we use \\emph{Taylor series} in order to approximate functions by a series of its derivatives. Conceptually, a Taylor series is mathematical concept which allows to represent a function by a certain infinite series.  \\\\\r\n\r\nThe Taylor series $\\mathcal T$ of an infinitely differentiable real or complex valued function $f(x)$ evaluated on a point $a$ is equal to the following power series:\r\n\r\n\\begin{equation}\r\n  \\mathcal T(f;a)(x) = \\sum_{n=0}^{\\infty} \\frac{f^{n}(a)}{n!}(x-a)^n\r\n  \\label{eq:deftaylor}\r\n\\end{equation}", "meta": {"hexsha": "1f8107336f1b311fd41ace01cc22ebf8a8a4eca0", "size": 8457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "document/Source/Chapters/appendix_signalprocessing.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_signalprocessing.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_signalprocessing.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": 73.5391304348, "max_line_length": 846, "alphanum_fraction": 0.7460092231, "num_tokens": 2176, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012655937034, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.7819050550561887}}
{"text": "\n\\subsection{Bayesian parameter estimation}\n\n\\subsubsection{Bayes rule}\n\nWe want to generate the probability distribution of \\(\\theta \\) given the evidence \\(X\\).\n\nWe can transform this using Bayes rule.\n\n\\(P(\\theta | X)=\\dfrac{P(X|\\theta )P(\\theta )}{P(X)}\\)\n\nHere we have:\n\n\\begin{itemize}\n\\item Our prior - \\(P(\\theta )\\)\n\\item Our likelihood function - \\(P(X|\\theta )\\)\n\\item Our posterior - \\(P(\\theta | X)\\)\n\\end{itemize}\n\n\\subsubsection{ Normal priors and posteriors}\n\nIf our prior is a normal distribution then:\n\n\\(P(\\theta )=\\dfrac{1}{\\sqrt {(2\\pi )^n|\\Sigma_0|}}e^{-\\dfrac{1}{2}(x-\\mu )^T\\Sigma_0^{-1}(x-\\mu)}\\)\n\nSimilarly, if our likelihood function \\(P(X|\\theta )\\) is a normal distriubtion then:\n\n\\(P(X|\\theta )=\\dfrac{1}{\\sqrt {2\\pi \\sigma^2}}e^{-\\dfrac{(x-\\mu)^2}{2\\sigma ^2}}\\)\n\nWe can now plug these into Bayes rule:\n\n\\(P(\\theta |X)=\\dfrac{1}{P(X)}\\dfrac{1}{\\sqrt {2\\pi \\sigma_0^2}}e^{-\\dfrac{(\\theta-\\mu_0)^2}{2\\sigma_0^2}}\\dfrac{1}{\\sqrt {2\\pi \\sigma^2}}e^{-\\dfrac{(x-\\mu)^2}{2\\sigma ^2}}\\)\n\n\\(P(\\theta |X)\\propto e^{-\\dfrac{1}{2}[\\dfrac{(\\theta-\\mu_0)^2}{\\sigma_0^2}+\\dfrac{(x-\\mu)^2}{\\sigma ^2}]}\\)\n\nWe can then set this an a new Gaussian:\n\n\\(P(\\theta |X)=\\dfrac{1}{\\sqrt {(2\\pi )^{n}|\\Sigma|}^{\\dfrac{1}{2}}} e^{-\\dfrac{1}{2}[\\dfrac{(\\theta-\\mu_0)^2}{\\sigma_0^2}+\\dfrac{(x-\\mu)^2}{\\sigma ^2}]}\\)\n\n", "meta": {"hexsha": "e215588002fe9da655048bb329d7747f8782a42f", "size": 1319, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/bayesian/01-01-bayesian.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/bayesian/01-01-bayesian.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/bayesian/01-01-bayesian.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.975, "max_line_length": 174, "alphanum_fraction": 0.6171341926, "num_tokens": 521, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7818602867028107}}
{"text": "\\chapter{Analytic Approach}\n\t\\section{Basic concepts}\n\t\tHere we'll define some basic concepts about norms and metrics. \n\t\t\\begin{defn}\n\t\t\tLet $X$ be a non-empty set, a function $d\\colon  X \\times X \\to \\R_{\\geq 0}$ is a \\textit{metric} if, for every $x, y, z \\in X$, we have:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $d(x, y) = 0 \\iff x = y$;\n\t\t\t\t\\item $d(x, y) = d(y, x)$;\n\t\t\t\t\\item $d(x, y) \\leq d(x, z) + d(z, y)$.\n\t\t\t\\end{enumerate}\n\t\t\\end{defn}\n\t\t\\begin{defn}\n\t\t\t\\label{defn:field-norm}\n\t\t\tLet $F$ be a field, a function $\\norm{\\ }\\colon F \\to \\R_{\\geq 0}$ is a \\textit{field norm}\\footnote{Although usually the term ``field norm'' has a different definition in field theory, we choose to use this terminology, to distinguish between norms on fields and norms on vectorial spaces.}(or an \\textit{absolute value}) if, for every $x, y \\in F$, we have:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $\\norm{x} = 0 \\iff x = 0$;\n\t\t\t\t\\item $\\norm{x \\cdot y} = \\norm{x} \\cdot \\norm{y}$;\n\t\t\t\t\\item $\\norm{x + y} \\leq \\norm{x} + \\norm{y}$.\n\t\t\t\\end{enumerate}\n\t\t\\end{defn}\n\t\t\\begin{defn}\n\t\t\tLet $V$ be a vector space over the field $F$, which has its norm $\\norm{\\ }_F$. A function $\\norm{\\ }\\colon V \\to \\R_{\\geq 0}$ is a \\textit{norm} if, for every $v, w \\in V, \\alpha \\in F$, we have:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $\\norm{v} = 0 \\iff v = 0$;\n\t\t\t\t\\item $\\norm{\\alpha \\cdot v} = \\norm{\\alpha}_F \\cdot \\norm{v}$;\n\t\t\t\t\\item $\\norm{v + w} \\leq \\norm{v} + \\norm{w}$.\n\t\t\t\\end{enumerate}\n\t\t\\end{defn}\n\t\tBeginning from a (field) norm $\\norm{\\ }$ there's a natural metric defined as $d(x, y) = \\norm{x - y}$.\n\t\\section{Metrics on $\\Q$}\n\t\tThe metric we normally equip $\\Q$ with is the euclidean one, which comes from the usual absolute value $\\abs{\\ }$ (denoted also by $\\abs{\\ }_\\infty$). \n\t\t\\begin{defn}\n\t\t\tLet $p$ a fixed prime. We can define a function $\\ord\\colon \\Z \\to \\N \\cup \\{+\\infty \\}$ as follows: \n\t\t\t\\begin{equation*}\n\t\t\t\t\\ord a := \n\t\t\t\t\\begin{cases*}\n\t\t\t\t\t+\\infty, & \\text{if $a = 0$;} \\\\\n\t\t\t\t\tn_a, & \\text{otherwise;}\n\t\t\t\t\\end{cases*} \n\t\t\t\\end{equation*}\n\t\t\twhere $n_a \\in \\N$ is such that $p^{n_a} | a$ and $p^{n_a + 1} \\nmid a$. It's easy to prove that $\\ord ab = \\ord a + \\ord b$ (using the usual convention $\\infty + n = n + \\infty =+\\infty$).\n\t\t\\end{defn}\n\t\tWe can extend this function to $\\Q$:\n\t\t\\begin{equation*}\n\t\t\t\\ord \\left( \\frac{a}{b} \\right) := \n\t\t\t\\begin{cases*}\n\t\t\t\t+\\infty, & \\text{if $\\frac{a}{b} = 0$;} \\\\\n\t\t\t\t\\ord a - \\ord b, & \\text{otherwise;}\n\t\t\t\\end{cases*}.\n\t\t\\end{equation*}\n\t\tThis is of course well defined: $\\ord \\left( \\tfrac{ac}{bc} \\right) = \\ord ac - \\ord bc = \\ord a - \\ord b = \\ord \\left( \\tfrac{a}{b} \\right)$. \n\t\t\\begin{prop}\n\t \t\t$\\emph{ord}_p\\colon  \\Q \\to \\Z \\cup \\{+\\infty\\}$ is a discrete valuation.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tWe have to prove the following properties:\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item $\\ord x = +\\infty \\iff x = 0$;\n\t\t\t\t\\item $\\ord xy = \\ord x + \\ord y$;\n\t\t\t\t\\item $\\ord (x + y) \\geq \\min \\{\\ord x, \\ord y \\}$.\n\t\t\t\\end{itemize}\n\t\t\tThe first two properties are quite easy, to see why the third one is true it's sufficient to write \n\t\t\t\\[\n\t\t\t\tx = \\frac{a}{b} = p ^ {\\ord x} \\cdot \\frac{a'}{b'}, \\qquad y = \\frac{c}{d} = p^{\\ord y} \\cdot \\frac{c'}{d'}\n\t\t\t\\]\n\t\t\twith $a', b', c', d'$ coprime with $p$. Then\n\t\t\t\\begin{equation*}\n\t\t\t\tx + y = p^{\\min \\{\\ord x,\\,\\ord y \\}} \\cdot q \\qquad (q \\in \\Q).\n\t\t\t\\end{equation*}\n\t\t\tApplying property $2.$ from \\cref{defn:field-norm} we obtain\n\t\t\t\\begin{gather*} \n\t\t\t\t\\ord(x + y) = \\ord \\left(p^{\\min \\{\\ord x,\\,\\ord y \\}} \\cdot q\\right) \\geq \\min \\{\\ord x, \\ord y \\}.\\qedhere\n\t\t\t\\end{gather*}\n\t\t\\end{proof}\n\t\t\n\t\tUsing these functions we can define a field norm $\\pabs{\\ }\\colon \\Q \\to \\Q$ as follows:\n\t\t\\begin{equation*}\n\t\t\t\\pabs{x} = \n\t\t\t\\begin{cases*}\n\t\t\t\tp ^ {-\\ord x}, & if $x \\neq 0$; \\\\\n\t\t\t\t0, & otherwise;\n\t\t\t\\end{cases*}.\n\t\t\\end{equation*}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:padic-nonarchimedean}\n\t\t\t$\\pabs{\\ }$ is a field norm on $\\Q$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tProperty $1.$ is obvious. \\newline\n\t\t\tTo prove $2.$, given $x, y \\in \\Q^{\\times}$ we know that $\\ord xy = \\ord x + \\ord y$ so \n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{xy} = p^{- \\ord xy} = p^{-\\ord x - \\ord y} = p^{-\\ord x} \\cdot p^{-\\ord y} = \\pabs{x} \\cdot \\pabs{y}.\n\t\t\t\\end{gather*}\n\t\t\tTo prove $3.$ let $x, y \\in \\Q^{\\times}$; $\\ord(x + y) \\geq \\min \\{\\ord x, \\ord y\\}$ so\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{x + y} = p^{-\\ord(x + y)} \\leq p^{- \\min \\{\\ord x,\\, \\ord y \\} } = p ^ {\\max \\{-\\ord x,\\,-\\ord y\\} } \\\\\n\t\t\t\t= \\max \\left\\{p ^ {-\\ord x}, p^{-\\ord y} \\right\\} = \\max \\left\\{\\pabs{x}, \\pabs{y} \\right\\} \\leq \\pabs{x} + \\pabs{y}.\n\t\t\t\\end{gather*}\n\t\t\tWe actually proved a stronger inequality than $3.$, which is one of the key ingredients of \\padic analysis.\n\t\t\\end{proof}\n\t\t\\begin{defn}\n\t\t\tA norm on $X$ is called \\textit{non-Archimedean} if $\\norm{x + y} \\leq \\max \\left\\{\\norm{x}, \\norm{y} \\right\\}$ holds for every $x, y \\in X$. \n\t\t\\end{defn}\n\t\tIf $\\norm{\\ }$ is a non-Archimedean norm on $X$, it's immediate to see that\n\t\t\\begin{gather*}\n\t\t\t\\norm{n\\cdot x} \\leq \\norm{x} \\text{ for every $n \\in \\N, x \\in X$ }\n\t\t\\end{gather*}\n\t\twhich explains the name. We have already proved that $\\pabs{\\ }$ is a non-Archimedean norm on $\\Q$ in \\cref{prop:padic-nonarchimedean}.\n\t\t\\begin{prop}\n\t\t\tIf $\\norm{\\ }$ is a non-Archimedean norm on $X$ then\n\t\t\t\\[\n\t\t\t\t\\norm{x} \\neq \\norm{y} \\implies \\norm{x + y} = \\max \\left\\{\\norm{x}, \\norm{y} \\right\\}.\n\t\t\t\\] \n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tWe can assume that $\\norm{x} < \\norm{y}$. Then\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{y} = \\norm{(x + y) - x} \\leq \\max \\left\\{\\norm{x+y}, \\norm{x}\\right\\} \\leq \\norm{y}\n\t\t\t\\end{gather*}\n\t\t\tbut since $\\norm{x} < \\norm{y}$ we must have $\\norm{x+y} = \\norm{y}$.\n\t\t\\end{proof}\n\t\t\\begin{defn}\n\t\t\tIf $(X, d)$ is a metric space, a sequence $(a_n)_{n \\in \\N}$ is a \\textit{Cauchy sequence} if $\\forall \\varepsilon > 0$ $\\exists n_0 \\in \\N$ such that $n, m > n_0 \\implies d(a_n, a_m) < \\varepsilon$.\n\t\t\\end{defn}\n\t\t\\begin{defn}\n\t\t\tTwo metrics $d_1, d_2$ on $X$ are \\textit{equivalent} if every Cauchy sequence for $d_1$ is Cauchy for $d_2$ and vice-versa. Two norms are equivalent if they induce equivalent metrics.\n\t\t\\end{defn}\n\t\tNow we present a technical lemma we're going to need.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:equivalent-norm}\n\t\t\tIf $\\alpha \\in (0, 1]$ the function on $\\Q$ defined by $x \\mapsto \\abs{x}^\\alpha$ is a norm equivalent to $\\abs{\\ }_\\infty$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tFirst of all we show $\\abs{\\ }^\\alpha$ is actually a norm; property $1.$ and $2.$ are easily verified. To prove $3.$ we have to show that $\\abs{x + y}^\\alpha \\leq \\abs{x}^\\alpha + \\abs{y}^\\alpha$ for every $x, y \\in \\Q^{\\times}$. We can assume $0 < x < y$ and, dividing both sides by $\\abs{y}^\\alpha$, we just need to prove $(1 + t)^\\alpha \\leq 1 + t^\\alpha$ for $t \\in [0, 1]$. This easily follows studying the first derivative of $[0, 1] \\ni t \\mapsto 1 + t^\\alpha - (1 + t)^\\alpha$ (always non negative if $0 \\leq \\alpha \\leq 1$).\\newline\n\t\t\tThe equivalence of the two norms is easy to see if we use the above definition: let $(a_n)_n$ be Cauchy for $\\abs{\\ }$; fixed $\\varepsilon > 0$ we can find $n_0 \\in \\N$ such that $n, m > n_0 \\implies \\abs{a_n - a_m} < \\varepsilon ^ \\frac{1}{\\alpha}$ i.e. $\\abs{a_n - a_m}^\\alpha < \\varepsilon$ $\\forall n, m > n_0$ so $(a_n)_n$ is also Cauchy for $\\abs{\\ }^\\alpha$ (and vice-versa).\n\t\t\\end{proof}\n\t\tGeneralizing a little bit the previous lemma we can prove that if $\\norm{\\ }_1$ and $\\norm{\\ }_2$ are two field norms on $F$ which satisfy $\\norm{x}_1 = \\norm{x}_2^\\alpha$ $\\forall x \\in F$ for a fixed $\\alpha > 0$ then they're equivalent. For example, instead of defining $\\pabs{\\ }$ using $p ^ {- \\ord a}$, we could have used $\\rho \\in (0, 1)$ in place of $1/p$ and we would have obtained an equivalent norm because $p^ {-\\ord a} = \\left(\\rho ^ {\\ord a}\\right)^{-\\log_\\rho p}$.\n\t\t\\begin{defn}\n\t\t\tThe norm $\\norm{\\ }$ such that $\\norm{x} = 1 - \\delta_0^x$ is called \\textit{trivial}.\n\t\t\\end{defn}\n\t\tFinally we can prove the main theorem of this section.\n\t\t\\begin{thm}[Ostrowski]\n\t\t\tEvery non-trivial norm $\\norm{\\ }$ on $\\Q$ is equivalent to $\\pabs{\\ }$ for some prime $p \\in \\N$ or for $p = \\infty$.\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tWe distinguish two cases.\\newline\n\t\t\t\\textit{Case} (1). There exists a positive integer $n$ such that $\\norm{n} > 1$. Let $n_0$ be the minimum among those (for every field norm $\\norm{\\pm 1} = 1$ so $n_0 > 1$). Since $\\norm{n_0} > 1$ there exists $\\alpha = \\log_{n_0}\\norm{n_0} > 0$ such that $\\norm{n_0} = n_0^\\alpha$. Now if $n \\in \\N^{\\times}$ then, using base $n_0$, we can write\n\t\t\t\\begin{equation*}\n\t\t\t\tn = a_0 + a_1n + \\dots + a_sn_0^s, \\qquad a_i \\in \\{0, 1, \\dots, n_0-1\\}, a_s \\neq 0.\n\t\t\t\\end{equation*}\n\t\t\tThen, since norms are subadditive and multiplicative\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{n} \\leq \\norm{a_0} + \\norm{a_1n_0} + \\dots + \\norm{a_sn_0^s} = \\\\\n\t\t\t\t= \\norm{a_0} + \\norm{a_1}n_0^\\alpha + \\dots + \\norm{a_s}n_0^{s\\alpha}.\n\t\t\t\\end{gather*}\n\t\t\tBeing $n_0$ the minimum positive integer with $\\norm{n_0} > 1$ we have $\\norm{a_i} \\leq 1$ so\n\t\t\t\\begin{gather*}\n\t\t\t\t\\norm{n} \\leq 1 + n_0^\\alpha + \\dots + n_0^{s\\alpha} \\leq n_0^{s\\alpha}(1 + n_0^{-\\alpha} + \\dots + n_0^{-s\\alpha}) \\leq \n\t \t\t\tn^\\alpha \\left[\\sum_{i=0}^{\\infty} n_0^{-i\\alpha} \\right].\n\t\t\t\\end{gather*}\n\t\t\tThe last inequality is true because $n \\geq n_0^s$. The series at the right side is a geometric one which converges to a certain $C < +\\infty$ (since $0 < \\frac{1}{n_0} < 1$). Now we have obtained\n\t\t\t\\begin{equation*}\n\t\t\t\t\\norm{n} \\leq Cn^\\alpha.\n\t\t\t\\end{equation*}\n\t\t\tUsing $n^N$, for some large $N \\in \\N$, in place of $N$ in the last inequality, and then extracting $N$th roots, leads us to\n\t\t\t\\begin{equation*}\n\t\t\t\t\\norm{n} \\leq \\sqrt[N]{C}n^\\alpha.\n\t\t\t\\end{equation*}\n\t\t\tLetting $N \\to +\\infty$ we get $\\norm{n} \\leq n^\\alpha$ (obviously this is valid for every $n \\in \\N$). To get the other verse of the inequality, using $n$ written as above, we have $n_0^{s+1} > n \\geq n_0^s$. Using reverse triangular inequality and the one we obtained above, we get\n\t\t\t\\begin{equation*}\n\t\t\t\t\\norm{n} \\geq \\norm{n_0^{s+1}} - \\norm{n_0^{s+1} - n} \\geq n_0^{(s+1)\\alpha} - \\left(n_0^{s+1} - n\\right)^\\alpha.\n\t\t\t\\end{equation*}\n\t\t\tSince $n > n_0^s$\n\t\t\t\\begin{equation*}\n\t\t\t\t\\norm{n} \\geq n_0^{(s+1)\\alpha} - \\left(n_0^{s+1} - n_0^s\\right)^\\alpha = n_0^{(s+1)\\alpha} \\left[1 - \\left(1 - \\frac{1}{n_0} \\right) ^ \\alpha \\right] \\geq C'n^\\alpha\n\t\t\t\\end{equation*}\n\t\t\twith $C' := \\left[1 - \\left(1 - \\frac{1}{n_0} \\right) ^ \\alpha \\right]$ that doesn't depend on $n$. As before, using $n^N$ and taking $N$th roots and letting $N \\to +\\infty$ gives $\\norm{n} \\geq n^\\alpha$.\n\t\t\tSo we proved that $\\norm{n} = n^\\alpha$ for every $n \\in \\N$. Using property $2.$ of norms and $\\norm{-1} = 1$ we get $\\norm{q} = \\abs{q}^\\alpha$ for every $q \\in \\Q$. Now, using \\cref{lemma:equivalent-norm}, we conclude that $\\norm{\\ }$ is equivalent to $\\abs{\\ }_\\infty$.\\newline\n\t\t\t\\textit{Case} (2). For every $n \\in \\N$, $\\norm{n} \\leq 1$. Since $\\norm{\\ }$ is non-trivial by hypothesis we can find the minimum $\\N \\ni n_0 > 1$ such that $\\norm{n_0} < 1$. Easily $n_0$ is a prime number: if not, $n_0 = a \\cdot b$ with $1 < a,b < n_0$ and $1 > \\norm{n_0} = \\norm{ab} = \\norm{a}\\norm{b}$ so at least one from $\\norm{a}$ and $\\norm{b}$ must be strictly less than $1$, absurd because $a, b < n_0$ and $n_0$ is the minimum positive integer with this property. \\newline\n\t\t\tLet $p = n_0$ and we claim that if $q$ is a different prime from $p$ $\\norm{q} = 1$. If this is not true then $\\norm{q} < 1$ and we can find some large $N \\in \\N$ such that $\\norm{p^N}, \\norm{q^N} < 1/2$. Since $p^N$ and $q^N$ are coprime, from Bézout identity there are $n, m \\in \\Z$ such that $np^N + mq^N = 1$, but this leads to a contradiction:\n\t\t\t\\begin{equation*}\n\t\t\t\t1 = \\norm{1} = \\norm{np^N + mq^N} \\leq \\norm{n}\\norm{p^N} + \\norm{m}\\norm{q^N} \\leq \\norm{p^N} + \\norm{q^N} < \\frac{1}{2} + \\frac{1}{2} < 1.\n\t\t\t\\end{equation*}\n\t\t\tNow, given $n \\in N$ we can factorize it in a unique way into prime divisors $n = p_1^{b_1} \\cdots p_r^{b_r}$. At most one from the $p_i$-s is equal to $p$ so if, wlog, $p_1 = p$ then $b_1 = \\ord n$ and $\\norm{p_i} = 1$ if $i>1$ so\n\t\t\t\\begin{equation*}\n\t\t\t\t\\norm{n} = \\norm{p_1^{b_1} \\cdot \\dots \\cdot p_r^{b_r}} = \\norm{p_1}^{b_1}\\cdot \\dots \\cdot \\norm{p_r}^{b_r} = \\norm{p}^{\\ord n}.\n\t\t\t\\end{equation*}\n\t\t\tLetting $\\rho := \\norm{p} \\in (0, 1)$ we obtain $\\norm{a} = \\rho ^ {\\ord a}$ for $a \\in \\N^{\\times}$. Using property $2.$ of norms we can show this holds also if $a \\in \\Q^{\\times}$. We conclude that $\\norm{\\ }$ is equivalent to $\\pabs{\\ }$, using the general version of \\cref{lemma:equivalent-norm}.\n\t\t\\end{proof}\n\t\tThe standard topology of $\\Q$, induced by the euclidean metric, is very different from the \\padic topology, induced by the \\padic ultrametric. With the former, $\\Z \\subset \\Q$ is a discrete set while, in \\padic environment, $\\Z$ isn't discrete: $0$ is an accumulation point, $\\lim_{n \\to +\\infty}p^n = 0$. There are also some interesting algebraic properties, which we haven't in the standard topology, for example the one described in the following lemma.\n\t\t\\begin{lemma}\n\t\t\tFor every $r > 0$ the set $B_{<r}(0) \\cap \\Z = \\{x \\in \\Z \\mid \\pabs{x} < r\\}$ is an ideal of the ring $\\Z$, in the \\padic topology.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tIt's clear that we can only consider the case $r = p^k$ with $k \\in \\Z$. If $k \\geq 0$ the property is trivial since $\\Z \\subseteq B_{\\leq 1}(0) = \\{x \\in \\Q \\mid \\pabs{x} \\leq 1 \\}$. Let's consider $x, y \\in \\Z \\cap B_{< p^k}(0)$, i.e. $\\pabs{x}, \\pabs{y} < p^k$. We must show that $\\pabs{x - y} < p^k$ and that for every $z \\in \\Z$ we have $z \\cdot x \\in B_{<p^k}(0) \\cap \\Z$. For the first property we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{x - y} \\leq \\max \\left\\{\\pabs{x}, \\pabs{-y} \\right\\} = \\max \\left\\{\\pabs{x}, \\pabs{y} \\right\\} < p^k\n\t\t\t\\end{gather*}\n\t\t\tand for the second one, recalling that $\\Z \\ni z \\implies \\pabs{z} \\leq 1$, we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{z \\cdot x} = \\pabs{z} \\cdot \\pabs{x} \\leq \\pabs{x} < p^k. \\qedhere\n\t\t\t\\end{gather*}\n\t\t\\end{proof}\n\t\n\t\tThese non-Archimedean norms $\\pabs{\\ }$ have some very strange properties, far from our intuition (which is based on euclidean norms). We'll explore them in detail in \\cref{section:ultrametrics}.\n\t\\section{Construction of $\\Qp$}\n\t\t\\label{section:construction-Qp}\n\t\t\\begin{defn}\n\t\t\tA metric space $(X, d)$ is \\textit{complete} if every Cauchy sequence in $X$ converges to some element in $X$.\n\t\t\\end{defn}\n\t\t\\begin{defn}\n\t\t\tIf $(X, d)$ is a metric space, $(\\overline{X}, \\overline{d})$ is its completion if it is a complete metric space which contains $X$ as a dense subspace and satisfies this universal property: if $Y$ is a complete metric space and $f\\colon X \\to Y$ is uniformly continuous then there exists a unique $f'\\colon \\overline{X} \\to Y$ such that $f'$ is uniformly continuous and $f'|_X = f$.\n\t\t\\end{defn}\n\t\tIt's clear from the definition that the completion of a space is unique up to isometry.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:Q-not-complete}\n\t\t\t$(\\Q, \\pabs{\\ })$ is not complete.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tThis proof will heavily rely on the definition of $\\Zp$ proposed in \\cref{section:Zp}, and on Hensel's lemma (\\cref{thm:hensel-lemma}). Obviously we don't need any result depending on this statement to  build $\\Zp$ and prove the Hensel's lemma (in other words: this proof does not create any logical loop).\\newline\n\t \t\tWe have to show that there exists a Cauchy sequence in $(\\Q, \\pabs{\\ })$ which has no limit in $\\Q$. To do this, we'll use a polynomial $P(X) \\in \\Z[X] \\subset \\Zp[X]$ which has no roots in $\\Q$ but admits a root in $\\Z/p\\Z$. We'll then use Hensel's lemma to obtain $\\xi \\in \\Zp$ such that $P(\\xi) = 0$. We'll then have a Cauchy sequence in $\\Z \\subset \\Q$ (we can consider truncated sums of $\\xi$) which converges to $\\xi \\notin \\Q$. Let's distinguish four cases.\n\t \t\t\\begin{itemize}\n\t \t\t\t\\item $p = 2$: \\newline\n\t \t\t\t\t  Let's consider the polynomial $P(X) = X^3 - 7 \\in \\Z[X]$: obviously there are no rational roots of $P$ but $x_0 = 1$ is such that $P(x_0) \\equiv 0 \\mod 2$. We immediately see that $P'(X) = 3X^2$ so $2 \\nmid 3 = P'(1)$ and, applying Hensel's lemma, we infer there is a unique $\\xi \\in \\Z_2$ such that $P(\\xi) = 0$. \n\t \t\t\t\\item $p = 3$: \\newline\n\t\t \t\t\t  Let's consider the polynomial $P(X) = X^2 - 7 \\in \\Z[X]$: obviously there are no rational roots of $P$ but $x_0 = 1$ is such that $P(x_0) \\equiv 0 \\mod 3$. We immediately see that $P'(1) = 2 \\not\\equiv 0 \\mod 3$ and, applying Hensel's lemma, we infer there is a unique $\\xi \\in \\Z_3$ such that $P(\\xi) = 0$. \n\t \t\t\t\\item $p \\equiv 1 \\mod 4$: \\newline\n\t \t\t\t\t  Let's consider the polynomial $P(X) = X^2 - (p+1) \\in \\Z[X]$. We observe that $P$ has no rational roots; writing $p+1 = 4k + 2$ we immediately see that $p+1$ is not a perfect square, because $2 \\mid p+1$ but $4 \\nmid p+1$. Clearly, $p+1$ can't either be a square of some rational number: if it were, then we would have\n\t \t\t\t\t  \\[\n\t \t\t\t\t      p+1 = \\left( \\frac{a}{b} \\right) ^2 \\implies b^2\\cdot (p+1) = a^2\n\t \t\t\t\t  \\]\n\t \t\t\t\t  which is an absurd, since $p+1$ is not a perfect square. So $P$ has no roots in $\\Q$, but we easily see that $P(1) \\equiv 0 \\mod p$ and $P'(1) = 2 \\not\\equiv 0 \\mod p$. Applying Hensel's lemma we find $\\xi \\in \\Zp$ such that $P(\\xi) = 0$.\n\t \t\t\t\\item $p \\equiv 3 \\mod 4$: \\newline\n\t \t\t\t\t  Let's consider $\\left(\\frac{p-1}{2}\\right)^2 \\equiv 4^{-1} \\mod p$ and let $t \\in \\{0, \\dots, p-1\\}$ such that $4t \\equiv 1 \\mod p$. Obviously $0 \\neq t$ is a quadratic residue in $\\Z/p\\Z$; we claim that $\\sqrt{t} \\notin \\Q$. We just need to show that $t$ is not a perfect square (then we can use the same reasoning of the previous point). First of all, with a little abuse of notation, we observe that \n\t \t\t\t\t  \\[\n\t \t\t\t\t  \t  \\Fp^2 = \\Set{ x^2 | 0 \\leq x \\leq \\frac{p-1}{2}, x \\in \\N}.\n\t \t\t\t\t  \\]\n\t \t\t\t\t  Since the only perfect squares less than $p$ are exactly $\\Set{x^2 | 0 \\leq x \\leq \\lfloor{\\sqrt{p}}\\rfloor, x \\in \\N}$ and $\\frac{p-1}{2} \\geq \\sqrt{p}$ for $p \\geq 7$, we infer that $t$ cannot be a perfect square. \\newline\n\t \t\t\t\t  Now we can consider the polynomial $P(X) = X^2 - t \\in \\Z[X]$: we know that it has no rational root but $x_0 = -2^{-1}$ is a root of $P$ in $\\Z/p\\Z$, by construction. Obviously $P'(X) = 2X$ so $P'(x_0) = 2x_0 \\not\\equiv 0 \\mod p$. Then we can apply Hensel's lemma and obtain $\\xi \\in \\Zp$ such that $P(\\xi) = 0$.\\qedhere \n\t \t\t\\end{itemize}\n\t\t\\end{proof}\n\t\tActually, if $p \\neq 2$, there is an easier way to prove $(\\Q, \\pabs{\\ })$ is not complete, using the Cauchy sequence $(a^{p^n})_{n \\in \\N}$, where $a \\in \\{1, \\dots, p-2\\}$. The proof can be found at \n\t\t\\cite[3]{thorne:teichmuller}. Anyway the proof we gave is indeed a nice application of the Hensel's lemma.\n\t\t\n\t\tThe goal of this section is to build $\\Qp$, the completion field of $(\\Q, \\pabs{\\ })$ with $p$ a fixed prime. The building process is analogue to the construction of $\\R$, the completion of $(\\Q, \\abs{\\ }_\\infty)$ and it's actually the ``standard'' way to complete a metric space. This process is actually necessary, because $(\\Q, \\pabs{\\ })$ is not complete, so it's a very unfriendly setting to perform analysis. \n\t\t\\begin{defn}\n\t\t\tLet $\\mathcal{S} := \\Set{ (a_n)_{n \\in \\N} \\subseteq \\Q | (a_n)_{n \\in \\N} \\text{ Cauchy for } \\pabs{\\ }}$. Then \n\t\t\t\\begin{equation*}\n\t\t\t\t\\Qp := \\nicefrac{\\mathcal{S}}{\\sim}\n\t\t\t\\end{equation*}\n\t\t\twhere $\\sim$ is a relation on $\\mathcal{S}$: $(a_n)_n \\sim (b_n)_n$ if $\\pabs{a_i - b_i} \\to 0$ as $i \\to +\\infty$.\n\t\t\\end{defn}\n\t\t\\begin{prop}\n\t\t\t$\\Qp$ is well defined and there's a natural sum and product on $\\Qp$ which makes $(\\Qp, +, \\cdot)$ a field.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\t$\\Qp$ is well defined, in the sense that $\\sim$ is an equivalence relation on $\\mathcal{S}$ (easy to verify). First of all we can immerge $\\Q$ in $\\mathcal{S}$ (and then in $\\Qp$) sending $x$ to $\\{x\\}$, the constant sequence (it's immediate that $\\{x'\\} \\sim \\{x\\} \\iff x = x'$ so this is really an immersion). From now on we'll do a little abuse of notation, not to result too pedantic: $0$ will denote both $\\{0\\}$ (the constant sequence) and $[\\{0\\}]$ (its equivalence class), context will clarify which is the right meaning. \\newline\n\t\t\t% Sum and product\n\t\t\tThere's a natural extension of the classical sum and product on $\\Q$ to $\\Qp$, which makes it a field. Let $a, b \\in \\Qp$, we define $a + b := [(a_n + b_n)_n]$ where $(a_n)_n, (b_n)_n$ are two representatives of $a$ and $b$ respectively. It is easy to see that this is well defined: the sum of two Cauchy is still a Cauchy and $a + b$ doesn't depend on the choice of the representatives. Similarly the product of $a \\cdot b := [(a_n \\cdot b_n)_n]$ is well defined: product of two Cauchy is Cauchy and given $(a'_n)_n \\sim (a_n)_n$ and $(b'_n)_n \\sim (b_n)_n$ we have\n\t\t\t\\begin{gather*}\n\t\t\t\t0 \\leq \\lim_{i \\to +\\infty} \\pabs{a_ib_i - a'_ib'_i} = \\lim_{i \\to +\\infty} \\pabs{a_i(b_i - b'_i) + b'_i(a_i - a'_i)} \\leq  \\\\\n\t\t\t\t\\leq \\lim_{i \\to +\\infty} \\pabs{a_i}\\pabs{b_i -b'_i} + \\lim_{i \\to +\\infty} \\pabs{b'_i}\\pabs{a_i - a'_i} = 0\n\t\t\t\\end{gather*}\n\t\t\twhere we used that if $(a_n)_n$ is Cauchy then it is bounded in norm. Then the definition doesn't depend on the choice of the representatives (the first claim above can be proved in the exact same way).\\newline\n\t\t\tIt's easy to see $(\\Qp, +)$ is a group, because $0$ is the neutral element and additive inverses are defined in the trivial way. To see that also $(\\Qp^\\times, \\cdot)$ is a group let's first note that every sequence $(a_n)_n$ is equivalent to $(a'_n)_n$ where $a'_i = p^i$ if $a_i = 0$ and $a'_i = a_i$ otherwise. Associativity holds and the neutral element is $1 = [\\{1\\}] \\neq 0$. The only non-trivial property to prove is the existence of multiplicative inverses: if $a \\neq 0$ then if $a = [(a_n)_n]$ (where $(a_n)_n$ is chosen without zeros) then $1/a = [(1/a_n)_n]$. We have to show that $(1/a_n)_n$ is Cauchy: let $N \\in \\N$ large enough such that $\\exists \\varepsilon > 0$ and $\\pabs{a_n} > \\varepsilon$ $\\forall n > N$ (see proof of \\cref{prop:padic-is-norm}) and that $n, m > N \\implies \\pabs{a_n - a_m} < \\varepsilon^3$; if $n, m > N$ we obtain\n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{\\frac{1}{a_n} - \\frac{1}{a_m}} = \\pabs{\\frac{a_m - a_n}{a_na_m}} = \\frac{1}{\\pabs{a_na_m}}\\pabs{a_m - a_n} \\leq \\frac{1}{\\varepsilon^2} \\varepsilon^3 = \\varepsilon.\n\t\t\t\\end{equation*}\n\t\t\tUsing the same exact technique we can prove that $1/a$ is well defined, i.e. if $(a_n)_n$ and $(a'_n)_n$ are both non-zero representatives of $a$ then $(1/a_n)_n \\sim (1/a'_n)_n$. Obviously this product is abelian. It is also easy to prove that distributivity holds, i.e. given $a, b, c \\in \\Qp$ $a \\cdot (b + c) = a\\cdot b + a \\cdot c$ (it's sufficient to note that $a \\cdot (b + c) = [(a_n \\cdot (b_n + c_n))_n] = [(a_n \\cdot b_n + a_n \\cdot c_n)_n]$). So we have finally proved that $(\\Qp, +, \\cdot)$ is a field, containing $\\Q$ as a subfield (the immersion defined at the beginning is in-fact a ring morphism between $\\Q$ and $\\Qp$, representing the natural identification of $\\Q$ in $\\Qp$).\n\t\t\\end{proof}\n\t\t\n\t\t\n\t\t% Norm Extension\n\t\tWe have then to extend the norm $\\pabs{\\ }$ to $\\Qp$: if $a \\in \\Qp$ then $\\pabs{a} := \\lim_{i \\to +\\infty} \\pabs{a_i}$ where $(a_n)_n$ is any representative of $a$.\n\t\t\\begin{prop}\n\t\t\t\\label{prop:padic-is-norm}\n\t\t\t$\\pabs{\\ }$ is a norm on $\\Qp$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tFirst of all we prove that, chosen a representative $(a_n)_n$ of $a$, $\\exists \\lim_{i \\to +\\infty} \\pabs{a_i}$. We have two cases:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item if $a = 0$, by definition, $\\lim_{i \\to +\\infty}\\pabs{a_i} = 0$;\n\t\t\t\t\\item if $a \\neq 0$ then $(a_n)_n \\nsim 0$ so $\\exists \\varepsilon > 0$ and for every $N \\in \\N$ there exists $i_N > N$ such that $\\pabs{a_{i_N}} > \\varepsilon$. Since $(a_n)_n$ is Cauchy, choosing $N$ large enough such that $\\pabs{a_i - a_j} < \\varepsilon$ $\\forall i,j > N$ we have that $\\pabs{a_i - a_{i_N}} < \\varepsilon$ $\\forall i>N$. Using the isosceles triangle principle we get $\\pabs{a_i} = \\pabs{a_{i_N}}$ for every $i > N$, so trivially the limit exists.\n\t\t\t\\end{enumerate}\n\t\t\tNow we prove that this is well defined, i.e. $\\pabs{a}$ doesn't depend on the choice of the representative of $a$. Let $(a_n)_n, (b_n)_n$ two representatives of $a$, then $(a_n)_n \\sim (b_n)_n$ which means $\\lim_{i \\to +\\infty} \\pabs{a_i - b_i} = 0$. Now by the reverse triangular inequality\n\t\t\t\\begin{equation*}\n\t\t\t\t0 \\leq \\lim_{i \\to +\\infty} \\abs{\\pabs{a_i} - \\pabs{b_i} } \\leq \\lim_{i \\to +\\infty} \\pabs{a_i - b_i} = 0 \\implies \\lim_{i \\to +\\infty} \\pabs{a_i} = \\lim_{i \\to +\\infty} \\pabs{b_i}.\n\t\t\t\\end{equation*}\n\t\t\tThe property $1.$ of norms is proved in the case  above. Property $2.$ and $3.$ immediately follows from the ones of $\\pabs{\\ }$ on $\\Q$ and basic limit rules.\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\t$(\\Qp, \\pabs{\\ })$ is complete.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tWe have to prove that if $(a_n)_n$ is a Cauchy sequence in $\\Qp$ for $\\pabs{\\ }$ then there exists $a \\in \\Qp$ such that $a = \\lim_{i \\to +\\infty} a_i$. Let $a_n = [(a_{n,m})_{m \\in \\N}]$ where $(a_{n,m})_m$ is a Cauchy sequence in $\\Q$. Let $N_j \\in \\N$ such that $\\forall$ $n, m > N_j$ $\\pabs{a_{j, m} - a_{j, n}} < 1/j$. Now, choosing $k_j > \\max \\{N_j, k_{j-1} \\}$, we claim that $[(a_{n, k_n})_n] \\in \\Qp$ is the limit of the sequence at the beginning. First of all we prove that $(a_{n, k_n})_n$ is a Cauchy sequence in $\\Q$: \n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{a_{n, k_n} - a_{m, k_m}} = \\pabs{ a_{n, k_n} - a_{n, j} + a_{n, j} - a_{m, j} + a_{m, j} - a_{m, k_m} } \\leq  \\\\\n\t\t\t\t\\leq \\max \\left\\{\\pabs{a_{n, k_n} - a_{n, j} }, \\pabs{a_{n, j} - a_{m, j}}, \\pabs{a_{m, j} - a_{m, k_m} } \\right\\}.\n\t\t\t\\end{gather*} \n\t\t\tChoosing a large enough $j \\in \\N$ we obtain $\\pabs{a_{n, k_n} - a_{n, j} } < 1/n$ and $\\pabs{a_{m, j} - a_{m, k_m} } < 1/m$. Since $(a_n)_n \\subseteq \\Qp$ is a Cauchy sequence, for every $\\varepsilon > 0$ $\\exists N \\in N$ such that $n, m > N \\implies \\pabs{a_n - a_m} < \\varepsilon$, meaning $\\lim_{j \\to +\\infty} \\pabs{a_{n, j} - a_{m, j}} < \\varepsilon$. From here we can see that $\\exists N' \\in \\N$ such that $j > N' \\implies \\pabs{a_{n, j} - a_{m, j} } < \\varepsilon$ so we can also control the other term above. We proved that $(a_{n, k_n})_n$ is a Cauchy sequence. \\newline\n\t\t\tNow we show that its equivalence class, let it be $a \\in \\Qp$, is actually the limit of $(a_n)_n$, i.e. \n\t\t\t\\[\n\t\t\t\t0 = \\lim_{n \\to +\\infty} \\pabs{a_n - a} = \\lim_{n \\to +\\infty} \\left( \\lim_{j \\to +\\infty} \\pabs{a_{n, j} - a_{j, k_j} } \\right).\n\t\t\t\\]\n\t\t\tFixed $\\varepsilon > 0$ we know that $\\exists N \\in \\N$ such that $n, m > N \\implies \\pabs{a_{n, k_n} - a_{m, k_m} } < \\varepsilon$. Choosing $\\N \\ni n > \\max \\{N, 1/\\varepsilon \\}$ we have\n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{a_{n, j} - a_{j, k_j} } \\leq \\max \\left\\{\\pabs{a_{n, j} - a_{n, k_n}}, \\pabs{a_{n, k_n} - a_{j, k_j} } \\right\\}.\n\t\t\t\\end{equation*}\n\t\t\tIf $j > \\max\\{k_n, N\\}$ then $\\pabs{a_{n, j} - a_{n, k_n}} < 1/n < \\varepsilon$ and $\\pabs{a_{n, k_n} - a_{j, k_j} } < \\varepsilon$ so \n\t\t\t\\[\n\t\t\t\t\\lim_{j \\to +\\infty} \\pabs{a_{n, j} - a_{j, k_j} } \\leq \\varepsilon.\n\t\t\t\\]\n\t\t\tThesis easily follows from the fact that $\\varepsilon$ is arbitrary.\n\t\t\\end{proof}\n\t\t\\begin{prop}\n\t\t\t\\label{prop:Q-dense-in-Qp}\n\t\t\t$\\Q$ is dense in $\\Qp$.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tChosen $a = [(a_n)_n] \\in \\Qp$ and $\\varepsilon > 0$ we know that $\\exists N \\in \\N$ such that $n > m > N \\implies \\pabs{a_n - a_m} < \\varepsilon$. Now, fixed $n \\in \\N$ we have that $a_n \\in \\Q$ is identified with $a' = \\{a_n\\} \\in \\Qp$, the equivalence class of the constant sequence $(a_n, a_n, a_n, \\dots)$. Now $\\pabs{a - a'} = \\lim_{j \\to +\\infty} \\pabs{a_j - a_n}$ which is clearly no bigger than $\\varepsilon$ (we can consider $j > N$).\n\t\t\\end{proof}\n\t\tUp to now we have proved that $(\\Qp, \\pabs{\\ })$ is actually the completion of $(\\Q, \\pabs{\\ })$. Obviously we're not going to work using this abstract construction, thanks to the following result.\\newline\n\t\tFirst we'll need a technical lemma.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:integer-representation-Qp}\n\t\t\tIf $x \\in \\Q$ and $\\pabs{x} \\leq 1$ then $\\forall i \\in \\N$ $\\exists \\alpha \\in \\Z$ such that $\\pabs{\\alpha - x} \\leq p^{-i}$. The integer $\\alpha$ can be chosen in $\\{0, 1, \\dots, p^i-1\\}$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tLet $x = a/b$ written in lowest terms. The fact that $\\pabs{x} \\leq 1$ means exactly $p \\nmid b$ so, since $p$ is a prime number, $p^i$ and $b$ are coprime; thanks to Bézout identity $\\exists m, n \\in \\Z$ $mb + np^i = 1$. Letting $\\Z \\ni \\alpha := am$ we get\n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{\\alpha - x} = \\pabs{am - \\frac{a}{b}} = \\pabs{\\frac{a}{b}}\\pabs{mb - 1} \\leq \\pabs{mb - 1} = \\pabs{np^i} = \\frac{\\pabs{n}}{p^i} \\leq \\frac{1}{p^i}\n\t\t\t\\end{equation*}\n\t\t\tsince $\\pabs{x} = \\pabs{a/b} \\leq 1$ and $\\pabs{n} \\leq 1$ if $n \\in \\Z$. Adding the right multiple of $p^i$ to $\\alpha$ we can get an integer between $0$ and $p^i - 1$ still satisfying the above inequality.\n\t\t\\end{proof}\n\t\t\\begin{thm}\n\t\t\t\\label{thm:representation-Qp}\n\t\t\tEvery $a \\in \\Qp$ with $\\pabs{a} \\leq 1$ has exactly one representative $(a_i)_{i \\in \\N}$ such that for every $i \\in \\N$:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\\item $a_i \\in \\{0, 1, \\dots, p^{i+1}-1\\}$;\n\t\t\t\t\\item $a_i \\equiv a_{i+1} \\mod p^{i+1}$.\n\t\t\t\\end{enumerate}\n\t\t\\end{thm}\n\t\t\\begin{proof}\n\t\t\tWe first prove uniqueness: let $(a'_i)_i$ a different sequence satisfying \\textit{1}. and \\textit{2.} If $a_{i_0} \\neq a'_{i_0}$ then $a_{i_0} \\not\\equiv a'_{i_0} \\mod p^{i_0 + 1}$ since they are both between $0$ and $p^{i_0 + 1}$. Now if $i \\geq i_0$ we have\n\t\t\t\\[\n\t\t\t\ta_i \\equiv a_{i_0} \\not\\equiv a'_{i_0} \\equiv a'_i \\mod p^{i_0 + 1} \\implies \\pabs{a_i - a'_i} > \\frac{1}{p^{i_0 + 1}},\n\t\t\t\\]\n\t\t\tmeaning $(a'_i)_i \\nsim (a_i)_i$.\\newline\n\t\t\tNow we prove existence. Let $(b_i)_i$ be any of the representatives of $a$ and let $N(j) \\in \\N$ such that $n, m \\geq N(j) \\implies \\pabs{b_n - b_m} \\leq p^{-j-1}$ for every $j \\in \\N$. We can choose the sequence $(N(j))_{j \\in \\N} \\subseteq \\N$ strictly increasing with $j$, in particular with $N(j) > \\max \\{j, N(j-1)\\}$. We immediately note that if $i \\geq N(0)$ then $\\pabs{b_i} \\leq 1$ because for every $j \\geq N(0)$\n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{b_i} \\leq \\max\\left\\{\\pabs{b_j}, \\pabs{b_i - b_j} \\right\\} \\leq \\max\\left\\{\\pabs{b_j}, \\frac{1}{p}\\right\\}\n\t\t\t\\end{equation*}\n\t\t\tand $\\lim_{j \\to +\\infty} \\pabs{b_j} = \\pabs{a} \\leq 1$. Using \\cref{lemma:integer-representation-Qp} we can find $a_j \\in \\Z$ such that $0 \\leq a_j < p^{j+1}$ and $\\pabs{a_j - b_{N(j)} } \\leq 1/p^{j+1}$, because $\\pabs{b_{N(j)}} \\leq 1$. We'll show that $(a_n)_n$ is the desired sequence. Obviously it's Cauchy because\n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{a_n - a_m} \\leq \\max\\left\\{\\pabs{a_n - b_{N(n)} }, \\pabs{b_{N(n)} - b_{N(m)}}, \\pabs{b_{N(m)} - a_m}  \\right\\}\n\t\t\t\\end{equation*}\n\t\t\tand, choosing $n, m$ large enough, we can control all those three terms. Property \\textit{1}. is already verified by construction so we have only to prove that $a_{j+1} \\equiv a_j \\mod p^{j+1}$ and that $(a_n)_n \\sim (b_n)_n$. The former follows from\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{a_{j+1} - a_j} \\leq \\max\\left\\{ \\pabs{a_{j+1} - b_{N(j+1)} }, \\pabs{b_{N(j+1)} - b_{N(j)}}, \\pabs{b_{N(j)} - a_j} \\right\\} \\leq \\\\\n\t\t\t\t\\leq \\max\\left\\{\\frac{1}{p^{j+2}}, \\frac{1}{p^{j+1}}, \\frac{1}{p^{j+1}} \\right\\} \\leq \\frac{1}{p^{j+1}}.\n\t\t\t\\end{gather*}\n\t\t\tTo prove the latter, for every $j$, if $i > N(j)$ we have\n\t\t\t\\begin{gather*}\n\t\t\t\t\\pabs{a_i - b_i} \\leq \\max\\left\\{\\pabs{a_i - a_j}, \\pabs{a_j - b_{N(j)}}, \\pabs{b_{N(j)} - b_i} \\right\\} \\leq \\\\\n\t\t\t\t\\leq \\max\\left\\{\\frac{1}{p^{j+1}},  \\frac{1}{p^{j+1}}, \\frac{1}{p^{j+1}} \\right\\} = \\frac{1}{p^{j+1}}\n\t\t\t\\end{gather*}\n\t\t\tbecause $a_i \\equiv a_{i+1} \\equiv a_{i+2} \\equiv \\dots \\equiv a_j \\mod p^{i+1}$. So $\\lim_{j \\to +\\infty} \\pabs{a_j - b_j} = 0$, i.e. $(a_i)_i \\sim (b_i)_i$.\n\t\t\\end{proof}\n\t\tSo we have a ``canonical'' representative for every $a \\in \\Qp$ with $\\pabs{a} \\leq 1$, let it be $(a_n)_n$. Since $a_i \\in \\{0, 1, \\dots, p^{i+1} - 1\\}$ we can write it using base $p$, i.e.,\n\t\t\\begin{equation*}\n\t\t\ta_i = b_0 + b_1p + b_2p^2 + \\dots + b_ip^i\n\t\t\\end{equation*}\n\t\twhere $b_i \\in \\{0, 1, \\dots, p-1\\}$. Property \\textit{2}. of \\cref{thm:representation-Qp} tells us exactly that\n\t\t\\begin{equation*}\n\t\t\ta_{i+1} = b_0 + b_1p + b_2p^2 + \\dots + b_ip^i + b_{i+1}p^{i+1}\n\t\t\\end{equation*}\n\t\ti.e. the first $i+1$ digits (from $b_0$ to $b_i$) are the same, because $\\pabs{a_{i+1} - a_i} \\leq 1/p^{i+1}$. So we can write, just as a notation,\n\t\t\\begin{equation*}\n\t\t\ta = \\sum_{i=0}^{+\\infty} b_ip^i = b_0 + b_1p + b_2p^2 + \\dots\n\t\t\\end{equation*}\n\t\tthe so called \\padic expansion of $a$. It's easy to see that $\\pabs{a} = p^{-k}$ where $k$ is the minimum integer such that $b_k \\neq 0$ ($k = +\\infty$ if $a=0$). This notation makes sense only if $\\pabs{a} \\leq 1$ but it can be used for every element of $\\Qp$ with a little refinement: let $a' \\in \\Qp$ with $\\pabs{a'} = p^m > 1$ ($m \\in \\N^{\\times}$); then $\\pabs{p^{m}a'} = \\pabs{p^m}\\pabs{a'} = 1$ so we can expand it like before\n\t\t\\begin{equation*}\n\t\t\tp^ma' = \\sum_{i=0}^{+\\infty} b_ip^i\n\t\t\\end{equation*}\n\t\tand multiplying both sides by $p^{-m}$ we obtain\n\t\t\\begin{equation*}\n\t\t\ta' = p^{-m} \\sum_{i=0}^{+\\infty} b_ip^i = \\sum_{i=0}^{+\\infty} b_ip^{i-m} = \\frac{b_0}{p^m} + \\frac{b_1}{p^{m-1}} + \\dots + \\frac{b_{m-1}}{p} + b_m + b_{m+1}p + \\dots\n\t\t\\end{equation*}\n\t\twhich can be thought as a \\padic expansion with a finite number of decimal digits. So we have a unique canonical way to write every element of $\\Qp$, which is way more practical than the abstract description. For example it is now easy to actually perform arithmetic operations: sum, difference, multiplication and division can be done applying the exact same algorithm that we use to perform them between integers, except that now we have to proceed with infinite digits (and actions like ``carrying'' or ``borrowing'' work from left to right). \n\t\t\\begin{defn}\n\t\t\tGiven $a, b \\in \\Qp$ and $n \\in \\N^{\\times}$ we say that $a \\equiv b \\mod p^n$ if $\\pabs{a - b} \\leq 1/p^n$.\n\t\t\\end{defn}\n\t\tIt's easy to check that if $a, b \\in \\Z$ this definition is exactly the old-fashioned congruence.\n\t\t\\begin{defn}\n\t\t\t$\\Zp := \\Set{x \\in \\Qp | \\pabs{x} \\leq 1}$ is called the set of \\emph{\\padic integers}.\n\t\t\\end{defn}\n\t\tIt's easy to verify that $\\Zp$ is a subring of $\\Qp$ (immediate from properties of $\\pabs{\\ }$). Its invertible elements are exactly\n\t\t\\[\n\t\t\t\\Zp^{\\times} = \\Set{x \\in \\Zp | \\frac{1}{x}\\in \\Zp} = \\Set{x \\in \\Zp | x \\not \\equiv 0 \\mod p} = \\Set{x \\in \\Zp | \\pabs{x} = 1}.\n\t\t\\]\n\t\tWe can now justify our initial notations, which is actually a ``real'' equality and not just a way to write things, thanks to the following lemma.\n\t\t\\begin{lemma}\n\t\t\tLet $(c_i)_i \\subseteq \\Qp$ such that $\\lim_{i \\to +\\infty} c_i = 0$. Then the series\n\t\t\t\\begin{equation*}\n\t\t\t\t\\sum_{i=0}^{+\\infty} c_i\n\t\t\t\\end{equation*}\n\t\t\tconverges in $\\Qp$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t\t\tWe need to show that the sequence of partial sums converge, i.e. $(S_n)_n \\subseteq \\Qp$ has limit, where $S_n := c_0 + c_1 + \\dots + c_n$. Since $\\Qp$ is complete it's sufficient to prove $(S_n)_n$ is Cauchy. Fixed $\\varepsilon > 0$ $\\exists N \\in \\N$ such that $i > N \\implies \\pabs{c_i} < \\varepsilon$; so if $n, m > N$ we have \n\t\t\t\\begin{equation*}\n\t\t\t\t\\pabs{S_n - S_m} = \\pabs{c_{n+1} + \\dots + c_m} \\leq \\max\\left\\{\\pabs{c_{n+1}}, \\dots, \\pabs{c_m} \\right\\} < \\varepsilon\n\t\t\t\\end{equation*}\n\t\t\tso $(S_n)_n$ is Cauchy.\n\t\t\\end{proof}\n\t\tWe can use this lemma with $c_i = b_ip^{i-m}$, for $m \\in \\N$ and $b_i \\in \\{0, 1, \\dots, p^i - 1\\}$, because $\\pabs{c_i} = \\pabs{b_i}\\pabs{p^{i-m}} \\leq 1 \\cdot p^{m - i} \\to 0$ as $i \\to +\\infty$. We conclude that every \\padic expansion\n\t\t\\[\n\t\t\t\\sum_{i=0}^{+\\infty} b_ip^{i-m}\n\t\t\\]\n\t\tactually converges to some element in $\\Qp$ (and, clearly, our notation is coherent). This lemma is also a much cleaner results on series: they converge if and only if the general term approaches zero, unlike in $(\\R, \\abs{\\ }_\\infty)$ where there are divergent series like $1 + \\frac{1}{2} + \\frac{1}{3} + \\dots = \\sum_{n=1}^{+\\infty} 1/n$. There is a very nice result about \\padic expansions: while the writing of rational numbers using base 10 is not unique ($0.99999\\ldots = 1$), in $\\Qp$ \\padic expansions are unique, i.e. if two expansions have different digits they converge to totally different numbers.\n\t\t\\begin{lemma}\n\t\t\t\\label{lemma:Q-in-Qp}\n\t\t\tGiven $a = p^k \\sum_{i=0}^{+\\infty} a_ip^i \\in \\Qp$, its \\padic expansion is periodic, i.e. $\\exists r, N \\in \\N$ such that $a_i = a_{i+r}$ for every $i > N$, if and only if $a \\in \\Q$.\n\t\t\\end{lemma}\n\t\t\\begin{proof}\n\t \tTo see that every periodic \\padic number is rational we can write\n\t\t\t\\begin{equation*}\n\t\t\ta = \\sum_{i=-k}^{+\\infty} a_ip^i = (a_{-k}p^{-k} + \\dots + a_{m-1}p^{m-1}) + p^m\\sum_{i=0}^{+\\infty} (b_0 + b_1p + \\dots + b_{n-1}p^{n-1})p^{in}\n\t\t\t\\end{equation*}\n\t\t\twith the obvious meaning: $\\Q \\ni q := a_{-k}p^{-k} + \\dots + a_{m-1}p^{m-1}$ is the anti-period and $(b_0, \\dots, b_{n-1})$ is the period. It is an easy calculation to verify that if $\\alpha \\in \\N^{\\times}$\n\t\t\t\\begin{equation*}\n\t\t\t\\sum_{i=0}^{+\\infty} p^{i\\alpha} = \\frac{1}{1 - p^\\alpha}.\n\t\t\t\\end{equation*}\n\t\t\tUsing this identity we get\n\t\t\t\\begin{equation*}\n\t\t\t\ta = q + (b_0 + b_1p + \\dots + b_{n-1}p^{n-1})\\cdot p^m \\cdot \\sum_{i=0}^{+\\infty} p^{in} = q + (b_0 + b_1p + \\dots + b_{n-1}p^{n-1})\\cdot\\frac{p^m}{1 - p^n}\n\t\t\t\\end{equation*}\n\t\t\twhich is clearly in $\\Q$.\\newline\n\t\t\tTo prove that every $q \\in \\Q$ has a periodic \\padic expansion we'll need a little more work. First of all let's note that if $a \\in \\Qp$ admits a periodic representation also $-a$ admits one: given\n\t\t\t\\begin{equation*}\n\t\t\t\ta = \\sum_{i=-k}^{+\\infty} a_ip^i = (a_{-k}p^{-k} + \\dots + a_{m-1}p^{m-1}) + p^m\\sum_{i=0}^{+\\infty} (b_0 + b_1p + \\dots + b_{n-1}p^{n-1})p^{in}\n\t\t\t\\end{equation*}\n\t\t\twe have \n\t\t\t\\begin{gather*}\n\t\t\t\t-a = (p - a_{-k})p^{-k} + (p - 1 - a_{-k+1})p^{-k+1} +  \\dots + (p - 1 - a_{m-1})p^{m-1} +\\\\\n\t\t\t\t+ p^m\\sum_{i=0}^{+\\infty} \\left[(p - 1 - b_0) + (p - 1 - b_1)p + \\dots + (p - 1 - b_{n-1})p^{n-1}\\right]p^{in}\n\t\t\t\\end{gather*}\n\t\t\ti.e. the period is $(p-1-b_0, p-1-b_1, \\dots, p-1-b_n)$ (the relation above is true if $a$ admits a non zero anti-period, but it's almost the same if it does not).\\newline\n\t\t\tNow let $\\Q \\ni a/b = p^k\\cdot(t/s)$ with $p \\nmid ts$. We'll show that $t/s$ admits a periodic expansion (then we can conclude immediately). Since $p$ is prime $p \\nmid ts \\implies p \\nmid s$ so $p$ and $s$ are coprime and, thanks to Euler's theorem, $1 - p^{\\phi(s)} = \\alpha s$ with $\\alpha \\in \\Z_{\\leq0}$ (where $\\phi$ is the Euler's totient function). So we have\n\t\t\t\\begin{equation*}\n\t\t\t\t\\frac{t}{s} = \\frac{\\alpha t}{1 - p^{\\phi(s)} } = \\alpha t \\cdot \\left(\\frac{1}{1 - p^{\\phi(s)}} \\right).\n\t\t\t\\end{equation*}\n\t\t\tNow it's sufficient to prove that $\\abs{\\alpha t}/(1 - p^{\\phi(s)})$ is periodic (because sign doesn't matter). As said before we know that $(1 - p^{\\phi(s)})^{-1} = \\sum_{i=0}^{+\\infty} p ^ {\\phi(s)i}$ and that $\\abs{\\alpha t} \\in \\N$ has a finite \\padic expansion (i.e. definitively zero). It's easy to see that also their product is periodic.\n\t\t\\end{proof}\n\t\tUsing this characterization of $\\Q$ in $\\Qp$ we can give another proof (a posteriori) of the non-completeness of $(\\Q, \\pabs{\\ })$. Obviously, this proof is much easier than the proof of \\cref{prop:Q-not-complete}, because it already uses the structure of $\\Qp$.\n\t\t\\begin{prop}\n\t\t\t$(\\Q, \\pabs{\\ })$ is not complete.\n\t\t\\end{prop}\n\t\t\\begin{proof}\n\t\t\tUsing the density of $\\Q$ in $\\Qp$, proved in \\cref{prop:Q-dense-in-Qp}, we just need to find some element $e \\in \\Qp \\setminus \\Q$, because then we'll have a Cauchy sequence in $(\\Q, \\pabs{\\ })$ which doesn't converge to any rational. Thanks to \\cref{lemma:Q-in-Qp} we know that every element of $\\Q$ corresponds to a periodic expansion in $\\Qp$ and vice-versa, so $e$ can be every infinite \\padic expansion which is not periodic, like for example\n\t\t\t\\begin{equation*}\n\t\t\t\te = 1 + p^2 + p^4 + p^8 + \\dots = \\sum_{i=0}^{+\\infty} p^{2^i}.\\qedhere\n\t\t\t\\end{equation*}\n\t\t\\end{proof}", "meta": {"hexsha": "74f21aead658f13e6b01ceeeedbc3bf497982345", "size": 40133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mainmatter/chapter1.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/chapter1.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/chapter1.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": 86.4935344828, "max_line_length": 858, "alphanum_fraction": 0.6138090848, "num_tokens": 15967, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418158002491, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7817707746927942}}
{"text": "\\lab{Algorithms}{Limitations of Floating Point Computation}{Limitations of Floating Point Computation}\n\\label{lab:breakfloat}\n\\objective{Understand the limitations of floating point numbers and introduce numerical stability.}\n\n\\section*{Introduction}\n\nIn the last lab we discussed the structure and flexibility of floating point numbers.\nFloating point numbers are a remarkably versatile tool for performing computations that roughly approximate operations on real numbers.\nIn this lab we will see how the imperfections of floating point numbers can lead to all kinds of trouble.\nThere are a variety of common errors involved with floating point computations.\nIn order to safely use floating point computations it is necessary to know what their limitations are.\n\nWe will start by considering a simple example in Cython:\n\n\\begin{lstlisting}\ncimport numpy as np\ndef breakfloat(int n):\n    cdef np.float32_t a = 2<<26\n    cdef int i\n    actual = float(a) + n\n    for i in range(n):\n        a += 1\n    return a, actual\n\\end{lstlisting}\n\nWhen we run this code for \\li{n=2**26} we see that the actual answer is double the answer returned by adding 1 repeatedly.\nThis is because the floating point number is large enough that adding 1 to it is, after rounding, equivalent to adding 0.\nThis is effect is mitigated substantially by the use of double precision floating point numbers, but it is still a worry.\n\n\\begin{problem}\nconsider the cython function defined below\n\\begin{lstlisting}\nfrom numpy cimport ndarray as ar\ncimport numpy as np\nimport numpy as np\nfrom numpy.random import rand\ndef sumrand(int size, int number):\n    # takes the sum of <number> of random arrays\n    # with number of elements <size>\n    cdef np.float32_t tot=0.\n    cdef ar[np.float32_t] A = np.empty(size, dtype=np.float32)\n    cdef int i, j\n    for i in xrange(number):\n        A[:] = rand(size).astype(np.float32)\n        for j in xrange(size):\n            tot += A[j]\n    return tot\n\\end{lstlisting}\nThe function call \\li{breakfloat2(10**6, 10**3)} returns 16777216.0.\nThe answer should obviously be around 500000000.\nWhy is there such a large error?\nHow could you fix the function so that it would give the right result?\n\\end{problem}\n\n\\section*{Various Computational Considerations}\n\nThere are a wide variety of issues that must be considered when using floating point numbers.\nThe first thing to notice is that floating point numbers are not actually stored as decimal representations.\nWhen you define a decimal number, your computer does the best it can to \\emph{approximate} the decimal number given.\nFor example, when you give your computer a value of .1, the value it actually stores is 0.1000000000000000055511151231257827021181583404541015625 which is usually close enough to .1 that the difference goes unnoticed.\nThis is, in a sense, a sort of round off error.\nThere is usually always a certain amount of error involved in each floating point computation.\nThe floating point operations on modern computers are designed to minimize such error, but it will always exist due to the limitations of floating point representation.\nThe way that computers implement floating point arithmetic does imply that there is a certain bound on the error introduced in each operation.\nThe bound that is most common is called \"machine precision\" or \"machine epsilon.\"\nGiven two precisely represented floating point numbers the Fundamental Axiom of Floating Point Arithmetic states that there is an $\\epsilon$ with $|\\epsilon | \\leq \\epsilon_{machine}$ such that $x * y = (x y) (1+\\epsilon)$ where $*$ denotes a floating point operation between the two numbers.\nFor single precision floating point numbers $\\epsilon_{machine} = 2^{-24}$.\nFor double precision it is $2^{-53}$.\nThese errors are extremely small, but a poorly written algorithm can result in massive accumulation of error and incorrect results.\nThese sort of problems can pop up in all kinds of places.\nYou must also keep in mind that rounding occurs after each operation.\nThese two effects can combine to give unexpected results, for example\n\\begin{lstlisting}\n>>> 3. * .1 - .3\n5.551115123125783e-17\n>>> 3. * .1 == .3\nFalse\n\\end{lstlisting}\nThese sorts of effects can combine to give somewhat astonishing results, for example, all of the following should be equivalent.\nThey should all evaluate to 0.\n\\begin{lstlisting}\n>>> n = 19000001\n>>> (5*n)**2 - (4*n)**2 - (3*n)**2 # exact result using integers\n0\n>>> (5.*n)**2 - (4*n)**2 - (3*n)**2 # added a single decimal point\n1.0\n>>> (5*n)**2 - (4.*n)**2 - (3*n)**2 # added a single decimal point somewhere else\n-1.0\n>>> (5.*n)**2 - ((4*n)**2 + (3*n)**2) # added a decimal point and some parenthesis\n2.0\n\\end{lstlisting}\nNotice how four expressions that should, in theory, be equivalent returned four \\emph{different} answers.\nThe change caused by the inclusion of parenthesis is particularly troublesome because it means that floating point operations are only \\emph{approximately} associative.\nThis is an example of what is called catastrophic cancellation.\nCatastrophic cancellation occurs when we perform an operation on two floating point numbers that are already subject to rounding error.\nit is especially noticeable when subtracting numbers that are approximately equal.\nBecause different methods of computation may yield slightly different results it is imperative that equality tests and comparisons using floating point numbers be carried out with certain tolerances.\nIt is all too tempting to do some floating point computation that you would expect to give a result of 0 and then to test your result with something like\n\\begin{lstlisting}\nif result == expected:\n    print \"it worked\"\n\\end{lstlisting}\nand then try to debug a perfectly good bit of code because the way it does its computations gives a result that is minutely different than what you expect.\nA test like this should be replaced with something roughly along the lines of\n\\begin{lstlisting}\ntolerance = 1E-6\nif abs(result - expected) < tolerance:\n    print \"it worked\"\n\\end{lstlisting}\nFor a specific example, consider the square root function given in the previous lab for 32 bit floating point numbers.\nThe square root given is not a perfect match to the square root given by the built in square root function, but it can compute the proper value so that all but the last bit is accurate.\nTo test whether or not the algorithm converges for randomly generated numbers between 0 and 1 we may be tempted to do the following\n\\begin{lstlisting}\nA = rand(10000)\n(pysqrtacc32(A, 2) == np.sqrt(A)).all()\n\\end{lstlisting}\nWhich would return \\li{False} since some of the values returned by our \\emph{algorithm} may differ from the built in square root by an extremely small amount regardless of how many iterations we run.\nWe can test for accuracy properly using something like\n\\begin{lstlisting}\nA = rand(10000)\n(np.absolute(pysqrtacc32(A, 2) - np.sqrt(A)) < 2E-7).all()\n\\end{lstlisting}\nWhich returns \\li{True}.\n\n\\begin{problem}\nOne example where it is common to subtract numbers that are nearly equal is in the computation of numerical derivatives.\nWrite a simple approximation to the derivative of a function $f$ using the formula $\\frac{f(x+h) - f(x)}{h}$.\nCheck how accurate it is for varying sizes of \\li{h} by testing it on the \\li{sin} function included in Python's math library with \\li{x = 1}.\nUse Python's \\li{cos} function as the exact value of the derivative.\nWhat do you notice about accuracy as \\li{h} becomes smaller and smaller?\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{lnseries.pdf}\n\\caption{Floating point computation of $\\frac{\\ln \\left(x+1\\right)}{x}$ shown with a corresponding series approximation.}\n\\label{floatbreak:lnseries}\n\\end{figure}\n\n\\begin{problem}\nSometimes clever numerical methods can be used to avoid some of the issues involved in floating point computations.\nThe value for $\\frac{\\ln \\left(x+1\\right)}{x}$ can be approximated by the series\n\\[\n\\sum_{n=1}^{\\infty} \\frac{\\left( -1 \\right)^{n+1}}{n} x^n\n\\]\nwhere $\\| x \\| \\leq 1$.\nUse this series to obtain a more accurate approximation of $\\frac{\\ln \\left(x+1\\right)}{x}$ for extremely small floating point numbers.\nUsing the polynomial you have constructed plot the exact value and the approximation to the function $ln \\left( 10^{-x} + 1 \\right)10^{x}$.\nPlot the exact value on $[-5, 30]$.\nPlot the approximation on $[1, 30]$.\nYour plot should look roughly like the plot shown in Figure \\ref{floatbreak:lnseries}.\n\\end{problem}\n\nAnother limitation of floating point numbers is that they are subject to overflow.\nFloating point numbers do have restricted values set aside for values of $\\infty$, $-\\infty$, and \\li{Nan}, so you can often tell when overflow has occured, but it is best to avoid extremely large or extremely small floating point values in either case.\nFor a simple example of overflow, we will perform a computational demonstration that the $p$-norms approach the $\\infty$-norm as $p \\rightarrow \\infty$.\n\\begin{lstlisting}\ndef pnorm(A, p):\n    return (A**p).sum()**(1./p)\n\\end{lstlisting}\nIf you haven't seen p-norms before, the main thing you need to understand here is that as $p \\rightarrow \\infty$, \\li{pnorm(A, p)} should come arbitrarily close to \\li{np.absolute(A).max()}.\nTesting this computationally, we see that, for a randomly generated array of values between 0 and 1, we get the plot shown in Figure \\ref{pnorm_convergence} as $p \\rightarrow \\infty$.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{pnorm_convergence.pdf}\n\\caption{The convergence of the $p$-norms to the $\\infty$-norm for a randomly generated vector of 100 floating point values in $(1,2)$.\nNotice how the $p$-norms disappear when $p$ is roughly 1000.\nThis is because values of floating point infinity are introduced into the computation.\nThis is especially troublesome because the array is nearly at the middle of the range of possible floating point values.\nIf the maximum were less than 1, the norm would suddenly drop to zero instead of jumping to $\\infty$.}\n\\label{pnorm_convergence}\n\\end{figure}\n\nFor floating point numbers, overflow results in a value of $\\infty$ or $-\\infty$.\nOperations that cannot be well defined (like $\\infty - \\infty$) return a value of \\li{NAN}, which stands for \"Not A Number.\"\nWhen dealing with machine integers, for example integers that are stored in arrays or integers in programming languages other than Python, there are no specific values for things likt $\\infty$.\nThe operations can be performed, but the result will be incorrect.\nTo understand this, first consider an unsigned integer.\nUnsigned integers are always considered to be positive.\nUnsigned integers have no sign, so each bit is considered a binary digit.\nIn an eight bit unsigned integer there are 256 possible values.\nThey are used to represent the numbers 0 through 255.\nWhen we pass 255, the numbers cycle back around to 0 again, so, for example:\n\\begin{lstlisting}\n>>> np.arange(250, 260, dtype=np.uint8)\narray([250, 251, 252, 253, 254, 255,   0,   1,   2,   3], dtype=uint8)\n>>> np.arange(250, 260, dtype=np.uint8) * 2\narray([244, 246, 248, 250, 252, 254,   0,   2,   4,   6], dtype=uint8)\n>>> np.arange(250, 260, dtype=np.uint8)**2\narray([36, 25, 16,  9,  4,  1,  0,  1,  4,  9], dtype=uint8)\n\\end{lstlisting}\nAs you can see, the operations can be understood as operations in $\\mathbb{Z} / 256 \\mathbb{Z}$, which has operations equivalent to those in $\\mathbb{Z}$ only some of the time.\nThese sorts of issues can come up in computations involving integers or even typecasts to integers.\n\n% this is another possibly useful problem, but it can be removed if necessary\n\\begin{problem}\nYour friend writes the following Cython code to search for Pythagorean Triples.\n\\begin{lstlisting}\nfrom libc.math cimport sqrt\ndef find_triple(double start, int num):\n    cdef int i, j\n    cdef double temp\n    for i in xrange(num):\n        for j in xrange(i, num):\n            temp = sqrt((start+i)**2 + (start+j)**2)\n            if temp == int(temp):\n                print int(start+i), int(start+j), int(temp)\n\\end{lstlisting}\nBy running \\li{find_triple(600000000, 10000)}, he claims to have found the triples\n\n600001807  600004043  848532274\n\n600001924  600004742  848532851\n\n600004561  600009787  848538283\n\n600004738  600007261  848536622\n\n{\\setlength{\\parindent}{0cm}\nWhat is wrong with his code and how should it be fixed?\nBe sure to watch out for any integer overflow along the way.\n}\n\\end{problem}\n\n\\section*{Some Examples of Computation Error}\n\nThere have been several historical examples where incorrect numerical computing has caused terrible disasters.\n\nOur first example involves the explosion of the Ariane 5 rocket in 1996.\nThe Ariane 5 rocket was launched by the European Space Agency.\nRoughly 7 billion dollars were spent in its development.\nThe rocket and its cargo were, in themselves, worth an estimated 500 million dollars.\nAt an altitude of about 3700 meters the rocket veered off of its intended path and exploded.\nAfter some investigation it was discovered that the error was caused by the conversion of an excessively large 64 bit floating point number to a 16 bit signed integer.\nTo see how this could cause problems, consider the following example:\n\\begin{lstlisting}\n>>> from numpy.random import rand\n>>> A = rand(10) * 10**5\n>>> A.astype(np.int16) # incorrect cast, overflow has occured\narray([  6691,  24236, -28341,   4104,  18063, -19080,  -7500,  -4954,\n        25898,  11995], dtype=int16)\n>>> A.astype(np.int64) # what the values should be\narray([26802, 64425,  1339, 55901, 51665, 11992, 90368, 87717,    25, 38894], dtype=int64)\n\\end{lstlisting}\nKeep in mind that a simple error like this caused hundreds of millions of dollars of damage.\n\nThe Vancouver Stock Exchange is another example of a relatively simple propagation of error.\nWhen the exchange opened, the index to track its value was initialized at 1000 in January of 1982.\nAround 3000 times per day the index was updated and then truncated to three decimals of precision.\nAfter 22 months the computed value was 524.881 when the actual value should have been 1009.811.\nWhen it was discovered that the computation of the index was diminishing it's value, the index was reset to its actual value.\n\nAnother example which we will not discuss here was the sinking of the Sleipner A offshore platform in 1991.\nThat disaster was due to improper finite element analysis.\nThe total loss was estimated at 700 million dollars.\n\nThe final example we will consider here is the failure of the Patriot Missile Defense system at Dharan, Saudi Arabia during the gulf war.\nIn this disaster the patriot missile system failed to fire on an incoming missile.\nThe missile struck a barracks, killed 28 people, and injured around 100 others.\nThis failure was due to improper use of floating point numbers!\nThe system clock was incremented using every .1 seconds using integers, but the time was then converted back to float by multiplying by .1 for use in some floating point computations.\nAfter 100 hours of operation the roundoff error in the floating point representation of .1 became significant enough that it prevented the system from properly targeting an incoming missile.\n\n\\begin{problem}\nIn the floating point format used for the Patriot missile systems in the gulf war the closest floating point number to .1 was $\\frac{209715}{2097152}$.\nCalculate the error accumulated over 100 hours.\nIf a missile travels at 1676 meters per second, how far will it be able to travel in that amount of time?\n\\end{problem}", "meta": {"hexsha": "e1da3651a7d9f61e06c26b4fbf9606aad6e969d1", "size": 15533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/floatbreak/floatbreak.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/floatbreak/floatbreak.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/floatbreak/floatbreak.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.1760299625, "max_line_length": 292, "alphanum_fraction": 0.7627631494, "num_tokens": 3843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964035, "lm_q2_score": 0.9073122169746364, "lm_q1q2_score": 0.7816841524840501}}
{"text": "\\lab{Applications}{Wavelet Denoising and Compression}{Denoising and Compression}\n\n\\objective{This lab presents the two-dimensional Discrete Wavelet Transform\nas well as related applications in image denoising and compression.}\n\n\\section*{The two-dimensional Discrete Wavelet Transform}\nIn the previous lab, we explored wavelet analysis using the Haar wavelet and\nthe discrete wavelet transform. Our discussion focused on one-dimensional\ndiscrete signals, but it is not difficult to extend the same ideas into the\nrealm of two-dimensional arrays. As you know, a digital image can be represented\nas a matrix of pixel values (for simplicity we will consider grayscale images of\nsize $2^n \\times 2^n$ in this lab). We can perform the wavelet decomposition of\nan image in much that same way as with one-dimensional signals. We once again\ncalculate detail and approximation coefficients using an iterative filter\nbank, but now we generate four arrays of coefficients at each iteration as opposed to\njust two. In essence, we perform the one-dimensional wavelet transform first on each\nrow, and then on each column of the matrix. Given an input matrix of size $2^n \\times\n2^n$, after operating on the rows, we 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}$. Recall the issues associated with the function\n\\li{sp.signal.fftconvolve} discussed in the previous lab. Figure \\ref{fig:2dwt}\ngives a graphical depiction of one iteration of the algorithm.\n\n\\begin{figure}[t]\n    \\includegraphics[width=0.8\\textwidth]{2dwt.jpg}\n    \\caption{The 2-dimensional discrete wavelet transform.}\n    \\label{fig:2dwt}\n\\end{figure}\n\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). Here is some sample code for one iteration of the transform and the inverse.\n\n\\begin{lstlisting}\ndef dwt2_pass(image,lo_d,hi_d):\n\ttemp = sp.zeros([image.shape[0], image.shape[1]/2])\n\tLL = sp.zeros([image.shape[0]/2, image.shape[1]/2])\n    LH = sp.zeros([image.shape[0]/2, image.shape[1]/2])    \n\tfor i in xrange(image.shape[0]):\n\t\ttemp[i] = sp.signal.fftconvolve(image[i], lo_d, mode='full')[1::2]    \n\tfor i in xrange(image.shape[1]/2):    \n\t\tLL[:,i] = sp.signal.fftconvolve(temp[:,i],lo_d,mode='full')[1::2]    \n        LH[:,i] = sp.signal.fftconvolve(temp[:,i],hi_d,mode='full')[1::2]  \n\tHL = sp.zeros([image.shape[0]/2, image.shape[1]/2])        \n    HH = sp.zeros([image.shape[0]/2, image.shape[1]/2])        \n\tfor i in xrange(image.shape[0]):        \n\t\ttemp[i] = sp.signal.fftconvolve(image[i], hi_d, mode='full')[1::2]        \n\tfor i in xrange(image.shape[1]/2):        \n\t\tHL[:,i] = sp.signal.fftconvolve(temp[:,i],lo_d,mode='full')[1::2]\n        HH[:,i] = sp.signal.fftconvolve(temp[:,i],hi_d,mode='full')[1::2] \treturn [LL,LH,HL,HH]\n\ndef idwt2_pass(coeffs, lo_r, hi_r):\n\tLL, LH, HL, HH = coeffs\n    n = LL.shape[0]\n\ttemp1 = sp.zeros([2*n,n])\n\ttemp2 = sp.zeros([2*n,n])\n\tup1 = sp.zeros(2*n)\n\tup2 = sp.zeros(2*n) \n\tfor i in xrange(n):\n\t\tup1[1::2] = HH[:,i]\n\t\tup2[1::2] = HL[:,i]\n\t\ttemp1[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\t\tup1[1::2] = LH[:,i]\n\t\tup2[1::2] = LL[:,i]\t\t\n\t\ttemp2[:,i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\tresult = sp.zeros([2*n,2*n])\n\tfor i in xrange(2*n):\n\t\tup1[1::2] = temp1[i]\n\t\tup2[1::2] = temp2[i]\n\t\tresult[i] = fftconvolve(up1, hi_r)[1:] + fftconvolve(up2, lo_r)[1:]\n\treturn result\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 in the last lab, the input to your decomposition function should consist of\nthree arrays: the input image, the low-pass filter, and the high-pass filter.\nTo increase the flexibility, also include an integer parameter that determines\nthe level of the decomposition, i.e. how many iterations to perform. Have the\ndefault value of this parameter cause the function to compute the complete\ndecomposition.\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]]$. The reconstruction 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\nThese wavelet coefficients are very useful in a variety of image processing\ntasks. They allow us to analyze and manipulate images in terms of both their\nfrequency and spatial properties, and at differing levels of resolution.\nFurthermore, wavelet bases often have the remarkable ability to represent\nimages in a very \\textit{sparse} manner -- that is, most of the image\ninformation is captured by a small subset of the wavelet coefficients.\nIn the remainder of this lab, we will see how the discrete wavelet transform\nplays a role in edge detection, noise removal, and compression.\n\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. Once again\nusing the Haar Wavelet and its associated filters, execute the following\ncode:\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.misc import imread\nfrom matplotlib import pyplot as plt\nfrom matplotlib import cm\n\n# Get the standard Lenna image for processing\nlenna = np.array(imread(\"Lenna.png\",flatten=True),dtype=np.float32)\n\n# Use your 2-dimensional DWT function to calculate one level of coefficients\ncoeffs = dwt2(lenna,lo_d,hi_d,1)\n\n# Now visualize the original image together with the result\ntop = np.vstack([coeffs[0]/2.0,np.absolute(coeffs[1][0])])\nbottom = np.vstack([np.absolute(coeffs[1][1]),np.absolute(coeffs[1][2])])\nplt.imshow(np.hstack([lenna,np.hstack([top,bottom])),cmap=cm.Greys_r)\nplt.show()\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}\n\n\\section*{Noise Removal}\nNoise in an image can be defined as unwanted visual artifacts that\nobscure the true image. Images can acquire noise from a variety of\nsources, including the camera, transmission, and image processing\nalgorithms. Noise can be completely random and incoherent (as in\nFigure \\ref{fig:incoherent}), or it can be coherent and display\nvisual patterns (Figure \\ref{fig:coherent}). In this section, we will\nfocus on reducing a particular type of random noise in images, called\n\\textit{Gaussian white noise}.\n\n\\begin{figure}[t]\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_random.pdf}\n    \\caption{The Phantom image with incoherent noise}\n    \\label{fig:incoherent}\n\\endminipage\\hfill\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{phantom_coherent.pdf}\n    \\caption{The Phantom image with coherent noise}\n    \\label{fig:coherent}\n\\endminipage\n\\end{figure}\n\nAn image that is distorted by Gaussian white noise is one in which\nevery pixel has been perturbed by a small amount, such that the\nperturbations are normally distributed. We can easily add such noise\nto an image using the \\li{np.random.normal} function.\n\nGiven an image with Gaussian white noise, how do we go about reducing\nthe noise level? Our approach will be based on the idea of thresholding.\nAs discussed earlier, images are often sparse in the wavelet basis,\nparticularly in the high-frequency details. The Gaussian noise, however,\nis very high frequency, and thus its wavelet transform will be\nconcentrated in high-frequency wavelet coefficients (of magnitude\nroughly proportional to the variance of the noise). We can therefore\nreduce the noise while preserving the true image by shrinking the\ndetail coefficients via hard or soft thresholding.\n\nGiven a positive threshold value $\\tau$, hard thresholding sets\nevery wavelet coefficient whose magnitude is less than $\\tau$ to\nzero, while leaving the remaining coefficients untouched. Soft\nthresholding also zeros out all coefficients of magnitude less than\n$\\tau$, but in addition maps every other coefficient $\\beta$ to\n$\\beta - \\tau$ if $\\beta > 0$ or $\\beta + \\tau$ if $\\beta < 0$.\n\nOnce the coefficients have been thresholded, we take the inverse\nwavelet transform to recover the denoised image. The threshold\nvalue is generally a function of the variance of the noise,\nand in real situations, we do not know what this variance is. In fact,\nnoise variance estimation in images is a research area in its own\nright, but this goes beyond the scope of this lab, and so we will\nassume that we already have a decent estimate of the variance.\n\n\\begin{problem}\nWrite functions that implement the hard and soft thresholding\ntechniques. The inputs should be a list of wavelet coefficients\nin standard form, as well as the threshold value. The output\nshould be the thresholded wavelet coefficients (also in\nstandard form). Remember that we only want to threshold the\ndetail coefficients, and not the approximation coefficients.\nYou should therefore leave the first entry of the input\ncoefficient list unchanged.\n\\end{problem}\n\\begin{problem}\nCreate a noisy version of the Lenna image by adding Gaussian\nwhite noise of mean 0 and standard deviation $\\sigma = 20$. Compute four\nlevels of the wavelet coefficients, and 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. What do you notice? How does lowering or raising the\nthreshold affect the reconstructed images?\n\\end{problem}\n\n\\section*{Image Compression}\nWe now turn to the problem of image compression. Explicitly saving\nthe value of every pixel in an image can be very costly in both\nstorage and transmission, and numerous image compression techniques\nhave been developed over the years to deal with this problem.\nTransform methods have long played an important role in these\ntechniques; the popular JPEG image compression standard is based on\nthe discrete cosine transform. Starting from the early 1990's, much\nresearch has gone into compression methods using the discrete wavelet\ntransform, and to great success. The JPEG2000 compression standard\nand the FBI Fingerprint Image database, along with other systems,\ntake the wavelet approach.\n\nThe general framework for compression is fairly straightforward. First,\nthe image to be compressed undergoes some form of preprocessing (this\ncan include subtracting out its mean, tiling the image, or perhaps\nnothing at all). Next, the wavelet coefficients are computed using some\nspecially constructed wavelet (JPEG2000 uses the either the\nCohen-Daubechies-Feauveau 9/7 or 5/3 wavelet) and then \\textit{quantized},\n a process that we will explain shortly. The quantized coefficients are\n then grouped in a particular way and passed through an entropy encoder\n (such as Huffman coding, run length coding, or arithmetic coding). This\n coding step comes from the realm of information theory, and we will not\n worry about it in this lab. What you have left is a compact stream of bits\n that can then be saved or transmitted much more efficiently than the\n original image. All of the above steps are invertible, allowing us to\n reconstruct the image from the bitstream.\n\n The step in this process that we will focus on is quantization. Put simply,\n quantization is a process whereby the coefficients are converted into\n integers. If the coefficients are floating-point numbers, then this\n process introduces some loss of precision, and we call this \\textit{\n lossy compression}. In the situation where all the coefficients are already\n integers, it is possible to compress the image without any loss of precision,\n and this is called \\textit{lossless compression}. Quantization can be\n performed in a variety of ways, and we will explore one particular method\n called a uniform null-zone quantizer. Given a coefficient $x$, we assign\n to it an integer $q$ given by\n\\begin{equation*}\nq =\n \\begin{cases}\n   \\lceil x / \\delta - t/2 \\rceil, &  x \\geq 0\\\\\n   \\lfloor x / \\delta + t/2 \\rfloor & x \\leq 0\n \\end{cases}\n\\end{equation*}\nwhere $1 \\leq t \\leq 2$ and $\\delta > 0$ are adjustable parameters.\nThe inverse process, called de-quantization, consists of recovering\nthe coefficient $y$ from the quantized value $q$ via the equation\n\\begin{equation*}\n y =\n  \\begin{cases}\n   (q - 1/2 + t/2)\\delta & q > 0\\\\\n   (q + 1/2 - t/2)\\delta & q < 0\\\\\n   0,                    & q = 0\n  \\end{cases}\n \\end{equation*}\nWhat we are essentially doing is mapping all wavelet coefficients that\nfall in the interval $[-\\delta,\\delta]$ to 0 and all wavelet coefficients\nin the interval $[j\\delta,(j+1)\\delta]$ to $(2j+1)\\delta/2$ for integers\n$j \\geq 1$ and $j \\leq -2$. This greatly reduces the number of distinct\ncoefficient values (indeed, most of the coefficients are mapped to\nzero), allowing us, at the cost of some precision, to store less\ninformation. The larger we choose $\\delta$, the more compression we\ncan achieve, albeit with a correspondingly larger loss in precision.\n\\begin{problem}\nWrite quantize and dequantize functions based on the discussion above.\nIn both cases, the inputs should be a list of wavelet coefficients in\nstandard form, the $\\delta$ parameter, and the $t$ parameter with default\nvalue of 2. The functions should return the altered list of wavelet\ncoefficients.\n\nFor the Lenna image, calculate the wavelet coefficients and then\nquantize and de-quantize the coefficients, and reconstruct the image.\nDo this for a few different values of $\\delta$ (with $t=2$), and observe how\nthe image is distorted. Keep in mind that we are using the Haar wavelet,\nwhich is definitely not well-suited for compression, and so the\ndistortion will be greater than tolerable in real-life settings.\n\\end{problem} ", "meta": {"hexsha": "2a3a2d8c6a6048a47c5663b10cca96a8e72084a6", "size": 16070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/WaveletApps/WaveletApps.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/WaveletApps/WaveletApps.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/WaveletApps/WaveletApps.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": 51.6720257235, "max_line_length": 95, "alphanum_fraction": 0.76565028, "num_tokens": 4025, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7816841417475179}}
{"text": "\\subsection{Introduction}\n\n\\begin{frame}\n  \\frametitle{Integer Difference Logics (\\Idl)}\n\n  The \\tatoms of \\Idl consists of arithmetic\n  constraints of the form\n  $$\n  x - y \\leq c\n  $$\n  where $x, y$ are variables and $c$ is a numerical constant.\n  The domain of $x,y,c$ is that of the integers\n  \\vfill\n  \\pause\n  Notice that the following translations hold\n  \\begin{itemize}\n    \\item $x - y \\geq c  \\quad\\quad\\Longrightarrow\\quad\\quad  y - x \\leq -c$  \n    \\item $x - y < c     \\quad\\quad\\Longrightarrow\\quad\\quad  x - y \\leq  c-1$  \n    \\item $x - y > c     \\quad\\quad\\Longrightarrow\\quad\\quad  y - x \\leq -c-1$  \n    \\item $x - y = c     \\quad\\quad\\Longrightarrow\\quad\\quad (x - y \\leq c) \\wedge (x - y \\geq c)$  \n    \\item $x - y \\not= c \\quad\\quad\\Longrightarrow\\quad\\quad (x - y < c)    \\vee   (x - y > c)$  \n  \\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Integer Difference Logic (\\Idl)}\n  \n  \\Rdl is similar to \\Idl, but it is defined on the rationals. However\n  an \\Rdl formula can be reduced to an equisatisfiable \\Idl formula \n  \\vfill\n  \\pause \n  \\Idl/\\Rdl can be used to encode a large variety of verification probems\n  \\begin{itemize}\n    \\item scheduling\n    \\item TSP\n    \\item ASP\n    \\item timed-automata\n    \\item sorting algorithms\n  \\end{itemize}\n  \\vfill\n  Also, the worst-case complexity of solving a conjunction of \\Idl constraints is $O(m + n \\log n)$\n\n\\end{frame}\n", "meta": {"hexsha": "4c701cf096c7bdff02169d8fe2ca369be6baf28b", "size": 1404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture5/introduction.tex", "max_stars_repo_name": "formalmethods/smtlectures", "max_stars_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-11-07T19:34:12.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-24T08:05:50.000Z", "max_issues_repo_path": "lecture5/introduction.tex", "max_issues_repo_name": "formalmethods/smtlectures", "max_issues_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lecture5/introduction.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": 31.2, "max_line_length": 100, "alphanum_fraction": 0.6474358974, "num_tokens": 480, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.849971175657575, "lm_q1q2_score": 0.7816696396659504}}
{"text": "\\chapter{Simple Examples}\\label{simpleexampleschapter}\n\n\\subsection{Peano Arithmetic}\\label{peanosection}\n\nThis section introduces \\emph{Peano representation} of numbers (technically, \\emph{Peano numerals}).  The advantage of this representation is that we can use \\scheme|==| both to construct and to match against numbers.\n\nThe Peano representation of zero is \\scheme|`z|, while the immediate successor to a Peano number \\mbox{\\scheme|n|} is represented as \\mbox{\\scheme|`(s ,n)|}.  For example, one is the immediate successor of zero---the Peano representation of one is therefore \\mbox{\\scheme|`(s z)|}.  Two is the immediate successor of one, so the Peano representation of two is \\mbox{\\scheme|`(s (s z))|}.\n\nTypographically, we indicate a Peano number using corner brackets---for example, \\mbox{\\scheme|(peano 3)|} for \\mbox{\\scheme|`(s (s (s z)))|}. We represent \\mbox{\\scheme|`(s ,x)|} as \\mbox{\\scheme|(peano+ x 1)|}, \\mbox{\\scheme|`(s (s ,x))|} as \\mbox{\\scheme|(peano+ x 2)|}, and so forth, where \\scheme|x| is a variable or a reified variable (that is, a symbol).  \n\n\nHere is \\scheme|pluso|, which adds two Peano numbers.\n\n\\begin{schemedisplay}\n(define pluso\n  (lambda (n m sum)\n    (conde\n      ((== (peano 0) n) (== m sum))\n      ((exist (x y)\n         (== (peano+ x 1) n)\n         (== (peano+ y 1) sum)\n         (pluso x m y))))))\n\\end{schemedisplay}\n\n\\newpage\n\\noindent \\scheme|pluso| allows us to find all pairs of numbers that sum to six.\n\n\\begin{schemedisplay}\n(run* (q)\n  (exist (n m)\n    (pluso n m (peano 6))\n    (== `(,n ,m) q))) $\\Rightarrow$\n\\end{schemedisplay}\n\\nspace\n\\begin{schemeresponse}\n((,(peano 0) ,(peano 6))\n (,(peano 1) ,(peano 5))\n (,(peano 2) ,(peano 4))\n (,(peano 3) ,(peano 3))\n (,(peano 4) ,(peano 2))\n (,(peano 5) ,(peano 1))\n (,(peano 6) ,(peano 0)))\n\\end{schemeresponse}\n\nLet us define \\scheme|minuso| using \\scheme|pluso|, and use it to find ten pairs of numbers whose difference is six.\n\n\\begin{schemedisplay}\n(define minuso\n  (lambda (n m k)\n    (pluso m k n)))\n\n(run10 (q)\n  (exist (n m)\n    (minuso n m (peano 6))\n    (== `(,n ,m) q))) $\\Rightarrow$\n\\end{schemedisplay}\n\\nspace\n\\begin{schemeresponse}\n((,(peano 6) ,(peano 0))\n (,(peano 7) ,(peano 1))\n (,(peano 8) ,(peano 2))\n (,(peano 9) ,(peano 3))\n (,(peano 10) ,(peano 4))\n (,(peano 11) ,(peano 5))\n (,(peano 12) ,(peano 6))\n (,(peano 13) ,(peano 7))\n (,(peano 14) ,(peano 8))\n (,(peano 15) ,(peano 9)))\n\\end{schemeresponse}\n\nWe have chosen to have subtraction of a larger number from a smaller number\nfail, rather than be zero.\n\n\\begin{schemedisplay}\n(run* (q) (minuso (peano 5) (peano 6) q)) $\\Rightarrow$ `()\n\\end{schemedisplay}\n\nWe will also need \\scheme|eveno| and \\scheme|positiveo| in several examples below. \n\n\\begin{schemedisplay}\n(define eveno\n  (lambda (n)\n    (conde\n      ((== (peano 0) n))\n      ((exist (m)\n         (== (peano+ m 2) n)\n         (eveno m))))))\n\n(define positiveo\n  (lambda (n)\n    (exist (m)\n      (== (peano+ m 1) n))))\n\\end{schemedisplay}\n\n\\scheme|eveno| and \\scheme|positiveo| ensure that their\narguments represent even and positive Peano numbers, respectively.\n\n\\begin{schemedisplay}\n(run4 (q) (eveno q)) $\\Rightarrow$ `(,(peano 0) ,(peano 2) ,(peano 4) ,(peano 6))\n\n(run* (q) (positiveo q)) $\\Rightarrow$ `(,(peano+ '_.0 1))\n\\end{schemedisplay}\n\n\\noindent The value \\begin{schemebox}(peano+ '_.0 1)\\end{schemebox} shows that\n$n + 1$ is positive for every number $n$.\n\n", "meta": {"hexsha": "dacfc5b57774d23a5425e24f5d3f87fd995b3694", "size": 3408, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "simpleexamples.tex", "max_stars_repo_name": "holtzermann17/dissertation-single-spaced", "max_stars_repo_head_hexsha": "aca0e56a33916596c98709308342d9ccabd4718b", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2015-01-11T21:22:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T12:49:11.000Z", "max_issues_repo_path": "simpleexamples.tex", "max_issues_repo_name": "holtzermann17/dissertation-single-spaced", "max_issues_repo_head_hexsha": "aca0e56a33916596c98709308342d9ccabd4718b", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2018-08-08T18:10:18.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-09T02:33:25.000Z", "max_forks_repo_path": "simpleexamples.tex", "max_forks_repo_name": "holtzermann17/dissertation-single-spaced", "max_forks_repo_head_hexsha": "aca0e56a33916596c98709308342d9ccabd4718b", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-07-29T13:58:01.000Z", "max_forks_repo_forks_event_max_datetime": "2018-09-14T05:01:31.000Z", "avg_line_length": 31.8504672897, "max_line_length": 387, "alphanum_fraction": 0.6411384977, "num_tokens": 1185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111796979521253, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.781580884474348}}
{"text": "\\section{The Coordinate System}\\label{sec:3Dcoordinatesystem}\n\nThroughout the text thus far we have focused investigating functions of the form $y=f(x)$, with\none independent and one dependent variable. Such functions can be\nrepresented in two dimensions, using two numerical axes that allow us\nto identify every point in the plane with two numbers. We now shift our focus to three-dimensional space; to identify every point in three\ndimensions we require three numerical values. The obvious way to make\nthis association is to add one new axis, perpendicular to the $x$ and\n$y$ axes we already understand. We could, for example, add a third\naxis, the $z$ axis, with the positive $z$ axis coming straight out of\nthe page, and the negative $z$ axis going out the back of the\npage. This is difficult to work with on a printed page, so more often\nwe draw a view of the three axes from an angle:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 5, y from 0 to 5\n\\axis left /\n\\axis bottom /\n\\plot 0 0 -3 -3 /\n\\put {$x$} [l] <4pt,0pt> at 5 0\n\\put {$y$} [b] <0pt,4pt> at 0 5\n\\put {$z$} [tr] <-4pt,-4pt> at -3 -3\n\\endpicture\n}$$\n\\end{figure}\n\nYou must then imagine that the $z$ axis is perpendicular to the other\ntwo. Just as we have investigated functions of the form $y=f(x)$ in\ntwo dimensions, we will investigate three dimensions largely by\nconsidering functions; now the functions will (typically) have the\nform $z=f(x,y)$. Due to the fact that we are used to having the result of a\nfunction graphed in the vertical direction, it is somewhat easier to\nmaintain that convention in three dimensions. To accomplish this, we\nnormally rotate the axes so that $z$ points up; the result is then:\n\n\\begin{figure}[H]\n$$\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <6truemm,6truemm>\n\\setplotarea x from 0 to 5, y from 0 to 6\n\\axis left /\n\\axis bottom /\n\\plot 0 0 -3 -3 /\n\\setdashes\n\\plot 4 0 3 -1 /\n\\plot 3 -1 -1 -1 /\n\\plot 3 -1 3 4 /\n\\setdots\n\\plot 0 5 4 5 3 4 -1 4 0 5 /\n\\plot -1 4 -1 -1 /\n\\plot 4 5 4 0 /\n\\put {$\\bullet$} at 3 4\n\\put {$(2,4,5)$} [tr] <-4pt,-4pt> at 3 4\n\\put {$y$} [l] <4pt,0pt> at 5 0\n\\put {$z$} [b] <0pt,4pt> at 0 6\n\\put {$x$} [tr] <-4pt,-4pt> at -3 -3\n\\put {$4$} [b] <0pt,3pt> at 4 0\n\\put {$2$} [br] <-2pt,2pt> at -1 -1\n\\put {$5$} [r] <-3pt,0pt> at 0 5\n\\endpicture\n}$$\n\\end{figure}\n\nNote that if you imagine looking down from above, along the $z$ axis,\nthe positive $z$ axis will come straight toward you, the positive $y$\naxis will point up, and the positive $x$ axis will point to your\nright, as usual. Any point in space is identified by providing the\nthree coordinates of the point, as shown; naturally, we list the\ncoordinates in the order $(x,y,z)$. One useful way to think of\nthis is to use the $x$ and $y$ coordinates to identify a point in the\n$x$-$y$ plane, then move straight up (or down) a distance given by\nthe $z$ coordinate.\n\nIt is now fairly simple to understand some ``shapes'' in three\ndimensions that correspond to simple conditions on the coordinates. In\ntwo dimensions the equation $x=1$ describes the vertical line through\n$(1,0)$. In three dimensions, it still describes all points with\n$x$-coordinate 1, but this is now a plane, as in\nFigure~\\ref{fig:plane}.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize7cm\\epsfbox{images/plane.eps}}} at 0 0\n\\endpicture}}\n\\caption{The plane $x=1$. \\label{fig:plane}}\n\\end{figure}\n\nRecall the very useful distance formula in two dimensions which comes directly from the Pythagorean Theorem: the\ndistance between points $(x_1,y_1)$ and $(x_2,y_2)$ is\n$\\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$\\index{distance formula}. What is the distance between two points\n$(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ in three dimensions?\nGeometrically, we want the length of the long diagonal labelled $c$ in\nthe ``box'' in Figure~\\ref{fig:3d distance formula}. Since $a$,\n$b$, $c$ form a right triangle, $a^2+b^2=c^2$. $b$ is the vertical\ndistance between $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$, so\n$b=|z_1-z_2|$.  The length $a$ runs parallel to the $x$-$y$ plane, so\nit is simply the distance between $(x_1,y_1)$ and $(x_2,y_2)$, that\nis, $a^2=(x_1-x_2)^2+(y_1-y_2)^2$. Now we see that\n$c^2=(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2$ and\n$c=\\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}$. \n\nIt is sometimes useful to give names to points, for example we might\nlet $P_1=(x_1,y_1,z_1)$, or more concisely we might refer to the point\n$P_1(x_1,y_1,z_1)$, and subsequently use just $P_1$. Distance between\ntwo points in either two or three dimensions is sometimes denoted by\n$d$, so for example the formula for the distance between $P_1(x_1,y_1,z_1)$\nand $P_2(x_2,y_2,z_2)$ might be expressed as\n$$d(P_1,P_2)=\\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}.$$\n\n\\begin{formulabox}[Distance]\nThe distance between points  $P_1(x_1,y_1)$ and $P_2(x_2,y_2)$ in two dimensions is\n\\[\nd(P_1,P_2) = \\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}\n\\]\n\n\\medskip\n\nThe distance between points $P_1(x_1,y_1,z_1)$ and $P_2(x_2,y_2,z_2)$ in three dimensions is \\[\nd(P_1,P_2)=\\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}\n\\]\n\\end{formulabox}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <7truemm,7truemm>\n\\setplotarea x from 0 to 7, y from 0 to 6\n\\axis left /\n\\axis bottom /\n\\plot 0 0 -3 -3 /\n\\setdashes\n\\plot 5 2 4 1 /\n\\plot 4 1 1 1 1 5 4 5 5 6 5 2 /\n\\plot 4 1 4 5 /\n\\plot 5 6 2 6 1 5 /\n\\setdots\n\\plot 2 6 2 2 1 1 /\n\\plot 2 2 5 2 /\n\\setsolid\n\\plot 4 1 2 2 4 5 /\n\\put {$a$} [tr] <-2pt,-2pt> at 3 1.5\n\\put {$b$} [l] <2pt,0pt> at 4 3\n\\put {$c$} [br] <-2pt,2pt> at 3 3.5\n%\\put {$(2,4,5)$} [l] <4pt,0pt> at 3 4\n\\put {$y$} [l] <4pt,0pt> at 7 0\n\\put {$z$} [b] <0pt,4pt> at 0 6\n\\put {$x$} [tr] <-4pt,-4pt> at -3 -3\n\\endpicture}}\n\\caption{Distance in three dimensions. \\label{fig:3d distance formula}}\n\\end{figure}\n\nIn two dimensions, the distance formula immediately gives us the\nequation of a circle: the circle of radius $r$ and center at $(h,k)$\nconsists of all points $(x,y)$ at distance $r$ from $(h,k)$, so the\nequation is $r=\\sqrt{(x-h)^2+(y-k)^2}$ or $r^2=(x-h)^2+(y-k)^2$. Now\nwe can get the similar equation $r^2=(x-h)^2+(y-k)^2+(z-l)^2$, which\ndescribes all points $(x,y,z)$ at distance $r$ from $(h,k,l)$, namely,\nthe sphere with radius $r$ and center $(h,k,l)$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:3Dcoordinatesystem}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nSketch the location of the points $(1,1,0)$, $(2,3,-1)$,\nand $(-1,2,3)$ on a single set of axes.\n\\end{ex}\n\n\\begin{ex}\nDescribe geometrically the set of points $(x,y,z)$ that\nsatisfy $z=4$.\n\\end{ex}\n\n\\begin{ex}\nDescribe geometrically the set of points $(x,y,z)$ that\nsatisfy $y=-3$.\n\\end{ex}\n\n\\begin{ex}\nDescribe geometrically the set of points $(x,y,z)$ that\nsatisfy $x+y=2$.\n\\end{ex}\n\n\\begin{ex}\nThe equation $x+y+z=1$ describes some collection of points\nin $\\ds \\R^3$. Describe and sketch the points that satisfy $x+y+z=1$ and\nare in the $x$-$y$ plane, in the $x$-$z$ plane, and in the \n$y$-$z$ plane.\n\\end{ex}\n\n\\begin{ex}\nFind the lengths of the sides of the triangle with \nvertices $(1,0,1)$, $(2,2,-1)$, and $(-3,2,-2)$.\n\\begin{sol}\n$3$, $\\sqrt{26}$, $\\sqrt{29}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the lengths of the sides of the triangle with \nvertices $(2,2,3)$, $(8,6,5)$, and $(-1,0,2)$. Why do the results tell\nyou that this isn't really a triangle?\n\\begin{sol}\n$\\sqrt{14}$, $2\\sqrt{14}$, $3\\sqrt{14}$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the sphere with center at $(1,1,1)$ and\nradius 2.\n\\begin{sol}\n$(x-1)^2+(y-1)^2+(z-1)^2=4$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the sphere with center at $(2,-1,3)$ and\nradius 5.\n\\begin{sol}\n$(x-2)^2+(y+1)^2+(z-3)^2=25$.\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the sphere with center $(3,-2,1)$ and\nthat goes through the point $(4,2,5)$.\n\\end{ex}\n\n\\begin{ex}\nFind an equation of the sphere with center at $(2,1,-1)$ and\nradius 4. Find an equation for the intersection of this sphere with\nthe $y$-$z$ plane; describe this intersection geometrically.\n\\begin{sol}\n$(x-2)^2+(y-1)^2+(z+1)^2=16$,\n$(y-1)^2+(z+1)^2=12$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nConsider the sphere of radius 5 centered at $(2,3,4)$.  What is\nthe intersection of this sphere with each of the coordinate planes?\n\\end{ex}\n\n\\begin{ex}\nShow that for all values of $\\theta$ and $\\phi$, the point\n$(a\\sin\\phi\\cos\\theta,a\\sin\\phi\\sin\\theta,a\\cos\\phi)$ lies on the\nsphere given by $x^2+y^2+z^2=a^2$.\n\\end{ex}\n\n\\begin{ex}\nProve that the midpoint of the line segment connecting\n$(x_1,y_1,z_1)$ to $(x_2,y_2,z_2)$ is at \n$\\ds\\left({x_1+x_2\\over 2},{y_1+y_2\\over 2},{z_1+z_2\\over 2}\\right)$.\n\\end{ex}\n\n\\begin{ex}\nAny three points $P_1(x_1,y_1,z_1)$, $P_2(x_2,y_2,z_2)$,\n$P_3(x_3,y_3,z_3)$, lie in a plane and form a triangle.  The \\dfont{triangle inequality}\nsays that $ d(P_1,P_3)\\le d(P_1,P_2)+d(P_2,P_3)$.  Prove the triangle inequality\nusing either algebra (messy) or the law of cosines (less messy).\n\\end{ex}\n\n\\begin{ex}\nIs it possible for a plane to intersect a sphere in exactly two\npoints?  Exactly one point? Explain.  \n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "0b917260cbde87c9caa88f765cc303476aa56171", "size": 9302, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "12-three-dimensions/12-1-coordinate-system.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "12-three-dimensions/12-1-coordinate-system.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "12-three-dimensions/12-1-coordinate-system.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 33.3405017921, "max_line_length": 138, "alphanum_fraction": 0.6824338852, "num_tokens": 3487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.841825659156573, "lm_q2_score": 0.9284087926320945, "lm_q1q2_score": 0.7815583438242711}}
{"text": "\\lab{Least squares and Eigenvalues}{Least squares and Eigenvalues}\n\\objective{Use least squares to fit curves to data and use QR decomposition to find eigenvalues}\n\\label{lab:givens}\n\n\n\\section*{Least Squares}\n\nA linear system $A\\x=\\b$ is \\emph{overdetermined} if it has no solutions. \nIn this situation, the \\emph{least squares solution} is a vector $\\widehat{\\x}$ hat is ``closest'' to a solution. \nBy definition, $\\widehat{\\x}$ is the vector such that $A\\widehat{\\x}$ will equal the projection of $\\b$ onto the range of $A$. \nWe can compute $\\widehat{\\x}$ by solving the \\emph{Normal Equation} $A\\trp A\\widehat{\\x} = A\\trp \\b$ (see [TODO: ref textbook] for a derivation of the Normal Equation).\n\n\n\\subsection*{Solving the normal equation}\nIf $A$ is full rank, we can use its QR decomposition to solve the normal equation. \nIn many applications, $A$ is usually full rank, including when least squares is used to fit curves to data.\n\nLet $A=QR$ be the QR decomposition of $A$, so $R = \\left(\\begin{array}{c}R_0\\\\\n0\\\\ \\end{array} \\right)$\nwhere $R_0$ is $n \\times n$, nonsingular, and upper triangular. \nIt can be shown that $\\widehat{\\x}$ is the least squares solution to $A\\x=\\b$ if and only if $R_0\\widehat{\\x} = (Q\\trp \\b)[:n].$ \nHere, $(Q\\trp \\b)[:n]$ refers to the first $n$ rows of $Q\\trp \\b$.\nSince $R$ is upper triangular, we can solve this equation quickly with back substitution. \n\n\n\\begin{problem}\nWrite a function that accepts a matrix $A$ and a vector $b$ and returns the least squares solution to $Ax=b$.\nUse the QR decomposition as outlined above.\nYour function should use SciPy's functions for QR decomposition and for solving triangular systems, which are \\li{la.qr()} and \\li{la.solve_triangular()}, respectively.\n\\end{problem}\n\n\\subsection*{Using least squares to fit curves to data}\nThe least squares solution can be used to find the curve of a chosen type that best fits a set of points. \n\n\\subsubsection*{Example 1: Fitting a line}\nFor example, suppose we wish to fit a general line $y=mx+b$ to the data set $\\{(x_k, y_k)\\}_{k=1}^n$. \nWhen we plug the constants $(x_k, y_k)$ into the equation $y=mx+b$, we get a system of linear equations in the unknowns $m$ and $b$. \nThis system corresponds to the matrix equation\n\\[\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\nx_3 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nm\\\\\nb\n\\end{pmatrix}=\n\\begin{pmatrix}\ny_1\\\\\ny_2\\\\\ny_3\\\\\n\\vdots\\\\\ny_n\n\\end{pmatrix}.\n\\]\nBecause this system has two unknowns, it is guaranteed a solution if it has two or fewer equations. \nIn applications, there will usually be more than two data points, and these will probably not lie in a straight line, due to measurement error. \nThen the system will be overdetermined. \nThe least squares solution to this equation will be a slope $\\widehat{m}$ and $y$-intercept $\\widehat{b}$ that produce a line $y = \\widehat{m}x+\\widehat{b}$ which best fits our data points.\n\n\n\n%DO: spring constant as an example of this\n% circle fit\n% mention in this situation A will usually be full rank.\n%todo: least squares and invertibiility.\n\n\n\n\n\n\n\nLet us do an example with some actual data. Imagine we place different loads on a spring and measure the displacement, recording our results in the table below.\n%TODO: get data points that are not so close to an actual line\n\\begin{table}\n\\begin{tabular}{c|c|c|c|c|c|c|c}\ndisplacement (cm)& 1.04  &2.03  &2.95  &3.92  &5.06  &6.00  &7.07  \\\\ \\hline\nload (dyne) & 3.11&  6.01&  9.07&  11.99 &  15.02&  17.91&  21.12\\\\\n\\end{tabular}\n\\end{table}\n\nHooke's law from physics says that the displacement $x$ should be proportional to the load $F$, or $F = kx$ for some constant $k$.\nThe equation $F=kx$ describes a line with slope $k$ and $F$-intercept 0.\nSo the setup is similar to the setup for the general line we discussed above, except we already know $b=0$\nWhen we plug our seven data points $(x,F)$ pairs into the equation $F=kx$, we get seven linear equations in $k$, corresponding to the matrix equation\n\\[\n\\begin{pmatrix}\n1.04\\\\\n2.03\\\\\n2.95\\\\\n3.92\\\\\n5.06\\\\\n6.00\\\\\n7.07\\\\\n\\end{pmatrix}\n\\begin{pmatrix}k\\end{pmatrix} =\n\\begin{pmatrix}\n3.11 \\\\\n6.01\\\\\n9.07\\\\\n11.99\\\\\n15.02\\\\\n17.91\\\\\n21.12\\\\\n\\end{pmatrix}.\n\\]\nWe expect such a linear system to be overdetermined, and in fact it is: the equation is $1.04k = 3.11$ which implies $k=2.99$, but the second equation is $2.03k = 6.01$ which implies $k=2.96$.\n\nWe can't solve this system, but its least squares solution is a ``best'' choice for $k$.\nWe can find the least squares solution with the SciPy function \\li{linalg.lstlsq()}. \nThis function returns a tuple of several values, the first of which is the least squares solution.\n\\begin{lstlisting}\n>>> A = np.vstack([1.04,2.03,2.95,3.92,5.06,6.00,7.07])\n>>> b = np.vstack([3.11,6.01,9.07,11.99,15.02,17.91,21.12])\n>>> k = la.lstsq(A, b)[0]\n>>> k\narray([[ 2.99568294]])\n\\end{lstlisting}\nHence, to two decimal places, $k = 3.00$.\nWe plot the data against the best-fit line with the following code, whose output is in Figure \\ref{fig:spring_fit}\n\n\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x0 = np.linspace(0,8,100)\n>>> y0 = k[0]*x0\n>>> plt.plot(A,b,'*',x0,y0)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{line_lstsq}\n\\caption{The graph of the spring data together with its linear fit.}\n\\label{fig:spring_fit}\n\\end{figure}\n\n%TODO: find more interesting data and make a sample plot\n\\begin{problem}\nLoad the \\li{linepts} array from the file \\texttt{data.npz}. The following code stores this array as \\li{linepts}.\n\\begin{lstlisting}\nlinepts = np.load('data.npz')['linepts']\n\\end{lstlisting}\nThe \\li{linepts} array has two columns corresponding to the $x$ and $y$ coordinates of some data points.\n\\begin{enumerate}\n\\item Use least squares to fit the line $y=mx+b$ to the data.\n\\item Plot the data and your line on the same graph.\n\\end{enumerate}\n\\end{problem}\n\n\n\n\n\n\n%\n%\\section*{General Line Fitting}\n%\n%Suppose that we wish to fit a general line, that is $y=m x+b$, to the data set\n%$\\{(x_k,y_k)\\}^n_{k=1}$.  Assume that the line does not cross through the origin,\n%as in the previous example.  Then we seek both a slope and a $y$-intercept.\n%In this case, we set up the following linear system $A x = b$, or more precisely\n%\\[\n%\\begin{pmatrix}\n%x_1 & 1\\\\\n%x_2 & 1\\\\\n%x_3 & 1\\\\\n%\\vdots & \\vdots\\\\\n%x_n & 1\n%\\end{pmatrix}\n%\\begin{pmatrix}\n%m\\\\\n%b\n%\\end{pmatrix}=\n%\\begin{pmatrix}\n%y_1\\\\\n%y_2\\\\\n%y_3\\\\\n%\\vdots\\\\\n%y_n\n%\\end{pmatrix}.\n%\\]\n%Note that $A$ has rank $2$ as long as not all of the $x_k$ values are the same.\n%Hence, the least squares solution\n%is given by\n%$$\n%\\widehat{x} = (A^HA)^{-1}A^Hb.\n%$$\n%In what sense does this solution give us the best fit line for the data? Recall that since $A$ is injective,\n%the matrix $A(A^HA)^{-1}A^H$ is an orthogonal projector onto the range of $A$, which means that\n%$A(A^HA)^{-1}A^Hb = A\\widehat{x}$ is the closest vector (with respect to the 2-norm) to $b$ that lies in the\n%range of $A$. That is, $\\widehat{x}$ minimizes the error between $Ax$ and $b$, where the error is given\n%by the distance between these vectors, $\\|b-Ax\\|_2$. Another way to say this is that $\\widehat{x}$ gives the\n%values $m$ and $b$ for which the sum of the squares of the distances from each data point $y_k$ to the value\n%$y = mx_k + b$ is as small as possible.\n\n\n\\subsubsection*{Example 2: Fitting a circle}\nNow suppose we wish to fit a general circle to a data set $\\{(x_k, y_k)\\}_{k=1}^n$. Recall that the equation of a circle with radius $r$ and center $(c_1,c_2)$ is\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nWhat happens when we plug a data point into this equation? Suppose $(x_k, y_k)=(1,2)$.\n\\footnote{You don't have to plug in a point for this derivation, but it helps us remember which symbols are constants and which are variables.} Then\n\\begin{equation*}\\label{equ:example}\n5 = 2c_1+4c_2+(r^2-c_1^2-c_2^2).\n\\end{equation*}\nTo find $c_1$, $c_2$, and $r$ with least squares, we need \\emph{linear} equations. \nThen Equation \\ref{equ:example} above is not linear because of the $r^2$, $c_1^2$, and $c_2^2$ terms. \nWe can do a trick to make this equation linear: create a new variable $c_3$ defined by $c_3 = r^2-c_1^2-c_2^2$. \nThen Equation \\ref{equ:example} becomes\n\\[\n5=2c_1+4c_2+c_3,\n\\]\nwhich \\emph{is} linear in $c_1$, $c_2$, and $c_3$. Since $r^2 = c_3+c_1^2+c_2^2$, after solving for the new variable $c_3$ we can also find $r$.\n\nFor a general data point $(x_k, y_k)$, we get the linear equation\n\\[\n2c_1x_k+2c_2y_k+c_3=x_k^2+y_k^2.\n\\]\nThus, we can find the best-fit circle from the least squares solution to the matrix equation\n\n\\begin{equation}\\label{equ:circle_fit}\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix}.\n\\end{equation}\nIf the least squares solution is $\\widehat{c_1}, \\widehat{c_2}$, $\\widehat{c_3}$, then the best-fit circle is\n\\[\n(x-\\widehat{c_1})^2 + (y-\\widehat{c_2})^2 = \\widehat{c_3}+\\widehat{c_1}^2+\\widehat{c_2}^2.\n\\]\n\n\nLet us use least squares to find the circle that best fits the following nine points:\n%TODO: get data points that are not so close to an actual circle\n\\begin{table}\n\\begin{tabular}{c||c|c|c|c|c|c|c|c|c}\n$x$& 134  &104 &34  &-36  &-66  &-36  &34 &104 &  134  \\\\ \\hline\n$y$& 76&  146&  176&  146 &  76&  5& -24 & 5 & 76\\\\\n\\end{tabular}\n\\end{table}\n\n\nWe enter them into Python as a $9\\times 2$ array.\n\\begin{lstlisting}\n>>> P = np.array([[134,76],[104,146],[34,176],[-36,146],\n                  [-66,76],[-36,5],[34,-24],[104,5],[134,76]])\n\\end{lstlisting}\n\nWe compute $A$ and $b$ according to Equation \\ref{equ:circle_fit}.\n\\begin{lstlisting}\n>>> A = np.hstack((2*P, np.ones((9,1))))\n>>> b = (P**2).sum(axis=1)\n\\end{lstlisting}\n\nThen we use SciPy to find the least squares solution.\n\\begin{lstlisting}\n>>> c1, c2, c3 = la.lstsq(A, b)[0]\n\\end{lstlisting}\n\nWe can solve for $r$ using the relation $r^2 = c_3+c_1^2+c_2^2$.\n\\begin{lstlisting}\n>>> r = sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\n\nA good way to plot a circle is to use polar coordinates. \nUsing the same variables as before, the equation for a general circle is $x=r\\cos(\\theta)+c_1$ and $y=r\\sin(\\theta)+c_2$. \nWith the following code we plot the data points and our best-fit circle using polar coordinates. \nThe resulting image is Figure \\ref{fig:circle}.\n\\begin{lstlisting}\n# In the polar equations for a circle, theta goes from 0 to 2*pi.\n>>> theta = np.linspace(0,2*np.pi,200)\n>>> plt.plot(r*np.cos(theta)+c1,r*np.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{circle.pdf}\n\\caption{The graph of the some data and its best-fit circle.}\n\\label{fig:circle}\n\\end{figure}\n\n\\begin{comment}\n\\begin{problem}\nWrite a function \\li{fitCircle} that does the following.\nLoad the \\texttt{circlepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given\ndata set.  Use least squares to find the center and radius of the circle that best\nfits the data.  Then plot the data points and the circle on the same graph.\nThe function should return nothing.\n\\end{problem}\n\\end{comment}\n\n%TODO: figure out how to plot this problem\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Load the \\texttt{ellipsepts} array from \\texttt{data.npz}. This array has two columns corresponding to the $x$ and $y$ coordinates of some data points.\n\\item Use least squares to fit an ellipse to the data. \nThe general equation for an ellipse is\n\\[\nax^2 + bx + cxy + dy + ey^2 = 1.\n\\]\nYou should get  $0.087$, $-0.141$,  $0.159$, $-0.316$, $0.366$ for $a, b, c, d,$ and $e$ respectively.\n%\\item Plot the data and your line on the same graph.\n\\end{enumerate}\n\\end{problem}\n\n%TODO: keep this?\n\\begin{comment}\nIn these Least Squares problems, we have found best fit lines and ellipses relative to the 2-norm.\nIt is possible to generalize the idea of best fit curves relative to other norms.\nSee Figure \\ref{Fig:ellipse} for an illustration of this.\n\n\\begin{figure}[h]\n\\label{ellipsefit}\n\\centering\n\\includegraphics[width=\\textwidth]{ellipsefit.pdf}\n\\caption{Fitting an ellipse using different norms.}\n\\label{Fig:ellipse}\n\\end{figure} \n\\end{comment}\n\n\\begin{comment}\n\\section*{Loading Data from .npz Files}\nFor Least Squares problems as well as in many other contexts, loading data is often a necessary step before\nproceeding with further analysis. Here we briefly review another data format in Python and the commands used\nto load the data.\n\nA \\li{.npz} file is a compressed binary file that contains an archive of NumPy data structures.\nA given file may therefore contain several arrays, each array associated with a unique string that identifies it.\nWhen you load a \\li{.npz} file in Python, a dictionary-like object is returned, and you can access the data by\nproviding the appropriate key. Note that when you load a \\li{.npz} file, you must also be sure to close it when\nyou are finished. This is taken care of automatically if you use the \\li{with ... as} keywords.\n\nAs an example, suppose that we have a file named \\li{grades.npz} that contains several arrays, each giving the\nhomework scores of a particular student in a particular class. Assuming that one of the arrays is associated with\nthe key \\li{'Abe'}, we can load this array in the following way:\n\n\\begin{lstlisting}\n>>> with np.load('grades.npz') as grades:\n>>>     abe_grades = grades['Abe']\n>>> abe_grades\narray([ 10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.])\n\\end{lstlisting}\n\nYou will need to apply this technique in the next problem.\n\n\\end{comment}\n\n\\section*{Computing eigenvalues}\nThe eigenvalues of a matrix are the roots of its characteristic polynomial. \nThus, to find the eigenvalues of an $n \\times n$ matrix, we must compute the roots of a degree-$n$ polynomial. \nThis is easy for small $n$. \nFor example, if $n=2$ the quadratic equation can be used to find the eigenvalues. \nHowever, Abel's Impossibility Theorem says that no such formula exists for the roots of a polynomial of degree 5 or larger.\n\n\\begin{theorem}[Abel's Impossibility Theorem]\nThere is no general algebraic solution for solving a polynomial equation of degree $n\\geq5$.\n\\label{thm:Abel}\n\\end{theorem}\n\nThus, it is impossible to write an algorithm that will exactly find the eigenvalues of an arbitrary matrix. \n(If we could write such an algorithm, we could also use it to find the roots of polynomials, contradicting Abel's theorem.) \nThis is a significant result. \nIt means that we must find eigenvalues with \\emph{iterative methods}, methods that generate sequences of approximate values converging to the true value.\n\n\\subsection*{The power method}\nThere are many iterative methods for finding eigenvalues. \nThe power method finds an eigenvector corresponding to the \\emph{dominant} eigenvalue of a matrix, if such an eigenvalue exists.\nThe dominant eigenvalue of a matrix is the unique eigenvalue of greatest magnitude.\n\nTo use the power method on a matrix $A$, begin by choosing a vector $\\x_0$ such that $\\|\\x_0\\|=1$. Then recursively define\n\\[\nx_{k+1}=\\frac{Ax_k}{\\norm{Ax_k}}.\n\\]\nIf \n\\begin{itemize}\n\\item $A$ has a dominant eigenvalue $\\lambda$, and\n\\item the projection of $\\x_0$ into the subspace spanned by the eigenvectors corresponding to $\\lambda$ is nonzero,\n\\end{itemize}\nthen the vectors $\\x_0, \\x_1, \\x_2, \\ldots$ will converge to an eigenvector of $A$ corresponding to $\\lambda$. \n(See [TODO: ref textbook] for a proof when $A$ is semisimple, or [TODO: ref something else] for a proof in the general case.)\n\nIf all entries of $A$ are positive, then $A$ will always have a dominant eigenvalue (see [TODO: ref something!] for a proof). \nThere is no way to guarantee that the second condition is met, but if we choose $\\x_0$ randomly, it will almost always satisfy this condition.\n\nOnce you know that $\\x$ is an eigenvector of $A$, the corresponding eigenvalue is equal to the \\emph{Raleigh quotient}\n\\[\n\\lambda = \\frac{\\langle Ax, x \\rangle}{\\|\\x\\|^2}.\n\\]\n\n\n\n\\begin{problem}\nWrite a function that implements the power method to compute an eigenvector. Your function should\n\\begin{enumerate}\n\\item Accept a matrix and a tolerance \\li{tol}.\n\\item Start with a random vector.\n\\item Use the 2-norm wherever a norm is needed (use \\li{la.norm()}).\n\\item Repeat the power method until the vector changes by less than the tolerance. In mathematical notation, you are defining $x_0, x_1, \\ldots x_k$, and your function should stop when $\\|x_{k+1}-x_k\\| < \\text{tol}$.\n\\item Return the found eigenvector and the corresponding eigenvalue (use \\li{np.inner()}).\n\\end{enumerate} \nTest your function on positive matrices.\n\\end{problem}\n\n\\begin{comment}\nAn overview of the proof of the method is that you can write a matrix in Jordan Conical form $A=VJV^{-1}$ where $V$ is the matrix of the generalized eigenspaces. \nBut the first column is is the eigenvector corresponding to largest eigenvalue and $J$ is a upper trianglar matrix of eigenvalues and ones.\nNote that $A^k=VJ^kV^{-1}$. The limit as $k \\rightarrow \\infty$ of $(\\frac{1}{\\lambda_1}J)^k$ is a matrix of all zeros except for a one in the upper right hand corner. \nSo $(\\frac{A}{\\norm{A}})^k \\approx VJ^kV^{-1}$ So the largest eigenvalue dominates.\n\\end{comment}\n\n\\subsection*{The QR algorithm}\nThe disadvantage of the power method is that it only finds the largest eigenvector and a corresponding eigenvalue. \nTo use the QR algorithm, let $A_0=A$. Then let $Q_kR_k$ be the QR decomposition of $A_k$, and recursively define \n\\[\nA_{k+1}=R_kQ_k.\n\\] \nThen $A_0, A_1, A_2, \\ldots $ will converge to a matrix of the form\n\\begin{equation*}\n\\label{eq:Schur form}\nS =\n     \\begin{pmatrix}\n          S_1 &* & \\cdots & * \\\\\n           0     &S_2  &  \\ddots & \\vdots \\\\\n           \\vdots  & \\ddots & \\ddots & *  \\\\\n           0 & \\cdots & 0 & S_m\n    \\end{pmatrix}\n\\end{equation*}\nwhere $S_i$ is a $1\\times1$ or $2\\times2$ matrix.\\footnote{If $S$ is upper triangular (i.e., all $S_i$ are $1\\times1$ matrices), then $S$ is the \\emph{Schur form} of $A$. \nIf some $S_i$ are $2\\times2$ matrices, then $S$ is the \\emph{real Schur form} of $A$.} \nThe eigenvalues of $A$ are the eigenvalues of the $S_i$.\n\nThis algorithm works for three reasons. First, \n\\[\nQ_k^{-1}A_kQ_k = Q_k^{-1}(Q_kR_k)Q_k = (Q_k^{-1}Q_k)(R_kQ_k) = A_{k+1},\n\\]\nso $A_k$ is similar to $A_{k+1}$. \nBecause similar matrices have the same eigenvalues, $A_k$ has the same eigenvalues as $A$. \nSecond, each iteration of the algorithm transfers some of the ``mass'' from the lower to the upper triangle. \nThis is what makes $A_0, A_1, A_2, \\ldots$ converge to a matrix $S$ which has the described form. \nFinally, since $S$ is block upper triangular, its eigenvalues are just the eigenvalues of its diagonal blocks (the $S_i$).\n\nA $2 \\times 2$ block will occur in $S$ when $A$ is real but has complex eigenvalues. \nIn this case, the complex eigenvalues occur in conjugate pairs, each pair corresponding to a $2 \\times 2$ block on the diagonal of $S$.\n\n\n\\subsubsection*{Hessenberg preconditioning}\nOften, we ``precondition'' a matrix by putting it in upper Hessenberg form before passing it to the QR algorithm. \nThis is always possible because every matrix is similar to an upper Hessenberg matrix (see Lab \\ref{}). \nHessenberg preconditioning is done for two reasons.\n\nFirst, the QR algorithm converges much faster on upper Hessenberg matrices because they are already close to triangular matrices. \n\nSecond, an iteration of the QR algorithm can be computed in $\\mathcal{O}(n^2)$ time on an upper Hessenberg matrix, as opposed to $\\mathcal{O}(n^3)$ time on a regular matrix. \nThis is because so many entries of an upper Hessenberg matrix are 0.\nIf we apply the QR algorithm to an upper Hessenberg matrix $H$, then this speed-up happens in each iteration of the algorithm, since if $H = QR$ is the QR decomposition of $H$ then $RQ$ is also upper Hessenberg.\n\n\n\\begin{problem}\nWrite a function that implements the QR algorithm with Hessenberg preconditioning as described above. \nDo this as follows.\n\\begin{enumerate}\n\\item Accept a matrix \\li{A}, a number of iterations \\li{niter}, and a tolerance \\li{tol}\n\\item Put \\li{A} in Hessenberg form using \\li{la.hessenberg()}.\n\\item Compute the matrix $S$ by performing the QR algorithm \\li{niter} times. \nUse the function \\li{la.qr()} to compute the QR decomposition.\n\\item Iterate through the diagonal of $S$ from top to bottom to compute its eigenvalues. \nFor each diagonal entry,\n\\begin{enumerate}\n\\item If this is the last diagonal entry, then it is an eigenvalue.\n\\item If the entry below this one has absolute value less than \\li{tol}, assume this is a $1\\times 1$ block. \nThen the current entry is an eigenvalue.\n\\item Otherwise, the current entry is at the top left corner of a $2 \\times 2$ block. \nCalculate the eigenvalues of this block. \nUse the \\li{sqrt} function from the scimath library to find the square root of a negative number. \nYou can import this library with the line \\li{from numpy.lib import scimath}.\n\\end{enumerate}\n\\item Return the (approximate) eigenvalues of \\li{A}.\n\\end{enumerate}\nYou can check your function on the matrix\n\\[\n\\begin{pmatrix}\n 4 &  12 & 17 &  -2 \\\\\n-5.5& -30.5 & -45.5 &  9.5\\\\\n 3. &  20. & 30. &  -6. \\\\\n1.5 &  1.5&   1.5&   1.5\n       \\end{pmatrix},\n\\]\nwhich has eigenvalues $1+2i, 1-2i, 3$, and 0. You can also check your function on random matrices against \\li{la.eig()}.\n\\label{prob:qr_solver}\n\\end{problem}\n\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:QR_eig_hessenberg}\nWrite a version of the QR algorithm that performs the QR algorithm by computing the Hessenberg form of a matrix, then computing various QR decompositions of the Hessenberg form of the matrix.\nUse your solutions to \\ref{prob:hessenberg} (where you computed the Hessenberg form of a matrix) and Problem \\ref{prob:givens_hessenberg_modified} to do the necessary computations (where you computed the QR decomposition of a Hessenberg matrix and wrote code for multiplication by $Q$ that works in $\\mathcal{O} \\left( n^2 \\right)$ time).\nThe solution to Problem \\ref{prob:givens_hessenberg_modified} is especially important because it allows the compution of each QR decomposition and each $R Q = \\left( Q^T R^T \\right)$ in $\\mathcal{O} \\left( n^2 \\right)$ time.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nIf $A$ is normal, its Schur form is diagonal.\nFor normal $A$, have your function additionally output the eigenvector corresponding to each eigenvalue.\nHint 1: Test your function on Hermitian and real symmetric matrices; they are both normal.\nHint 2: Your work in Problem \\ref{problem:similarity proof} will help.\nYou have already made all the necessary calculations, you just need to store the information correctly.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nTest your implementation with random matrices.\nTry real-valued and symmetric matrices.\nCompare your output to the output from the eigenvalue solver.\nHow many iterations are necessary?\nHow large can $A$ be?\n\\end{problem}\n\\end{comment}\n\nThe QR algorithm as described in this lab is not often used. \nInstead, modern computer packages use the implicit QR algorithm, which is an improved version of the QR algorithm.\n\nLastly, iterative methods besides the power method and QR method are often used to find eigenvalues.\nArnoldi iteration is similar to the QR algorithm but exploits sparsity.\nOther methods include the Jacobi method and the Rayleigh quotient method.\n", "meta": {"hexsha": "fbc76771ee365061695a1c3053d0a6a675ee1a56", "size": 23581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/LeastSquaresEigs/LstsqEigs.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/LeastSquaresEigs/LstsqEigs.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/LeastSquaresEigs/LstsqEigs.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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9526411658, "max_line_length": 338, "alphanum_fraction": 0.7206649421, "num_tokens": 7210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.8824278680004707, "lm_q1q2_score": 0.781505887948054}}
{"text": "\\chapter{Differentiation}\n\nWe have done some differentiation, but you haven't been given the real\ndefinition because it is based on limits.\n\nThe idea is that we can find the slope between two points on the graph\n$a$ and $b$ like this:\n\n$$m = \\frac{f(b) - f(a)}{b - a}$$\n\n\\begin{tikzpicture} [scale=2]\n\\draw[->,thick,sdkblue] (0,0) -- (4,0) node[right] {$x$};\n\\draw[->,thick,sdkblue] (0,0) -- (0, 3.45) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black, domain=0:3.7,samples=300,variable=\\x]  plot (\\x,{\\x * \\x * 0.25});\n\\draw [sdkblue] (1, 0.25) -- (3, 2.251);\n\\draw [dashed] (1,0.25) -- (1, 0) node[below]{$a$};\n\\draw [dashed] (3, 2.251) -- (3, 0) node[below]{$b$};\n\\draw [dashed] (1,0.25) -- (3, 0.25) node[right] {$f(a)$};\n\\draw (3,2.251) node[right] {$f(b)$};\n\\draw (1,0.25) circle (0.05);\n\\draw (3, 2.251) circle (0.05);\n\\draw (2, 0.25) node[above]{$b - a$};\n\\draw (3, 1.25) node[right] {$f(b) - f(a)$};\n\\end{tikzpicture}\n\nIf we want to find the slope at $a$ we take the limit of this as the $b$ goes to $a$:\n\n$$f'(a) = \\lim_{b \\rightarrow b}\\frac{f(b) - f(a)}{b - a}$$\n\nThis idea is usually expressed using $\\Delta x$ as the difference between $b$ and $a$:\n\n\\begin{tikzpicture} [scale=2]\n\\draw[->,thick,sdkblue] (0,0) -- (4,0) node[right] {$x$};\n\\draw[->,thick,sdkblue] (0,0) -- (0, 3.45) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black, domain=0:3.7,samples=300,variable=\\x]  plot (\\x,{\\x * \\x * 0.25});\n\\draw [sdkblue] (1, 0.25) -- (3, 2.251);\n\\draw [dashed] (1,0.25) -- (1, 0) node[below]{$a$};\n\\draw [dashed] (3, 2.251) -- (3, 0) node[below]{$a + \\Delta x$};\n\\draw [dashed] (1,0.25) -- (3, 0.25) node[right] {$f(a)$};\n\\draw (3,2.251) node[right] {$f(a + \\Delta x)$};\n\\draw (1,0.25) circle (0.05);\n\\draw (3, 2.251) circle (0.05);\n\\draw (2, 0.25) node[above]{$\\Delta x$};\n\\draw (3, 1.25) node[right] {$f(a + \\Delta x) - f(a)$};\n\\end{tikzpicture}\n\nThen the formula becomes:\n\n$$f'(a) = \\lim_{\\Delta x \\rightarrow 0}\\frac{f(a + \\Delta x) - f(a)}{\\Delta x}$$\n\nNow, at any point $a$ we can compute the slope of the line tangent to the function at $a$:\n\n\\begin{tikzpicture} [scale=2]\n\\draw[->,thick,sdkblue] (0,0) -- (4,0) node[right] {$x$};\n\\draw[->,thick,sdkblue] (0,0) -- (0, 3.45) node[above] {$y$};\n% curve\n\\draw[<->,thick,draw=black, domain=0:3.7,samples=300,variable=\\x]  plot (\\x,{\\x * \\x * 0.25});\n\\draw [sdkblue] (0, -0.25) -- (3, 1.25) node[midway, right]{slope = $f'(a)$};;\n\\draw [dashed] (1,0.25) -- (1, 0) node[below]{$a$};\n\\draw (1,0.25) circle (0.05);\n\\end{tikzpicture}\n\n\\section{Differentiability}\n\nWarning: Not every function is differentiable everywhere.  For\nexample, if $f(x) = |x|$, you get a corner at zero.\n\n\\begin{tikzpicture} [scale=1]\n\\draw[->,thick,sdkblue] (-4,0) -- (4,0) node[right] {$x$};\n\\draw[->,thick,sdkblue] (0,0) -- (0, 3.45) node[above] {$y$};\n% curve\n\\draw[->,thick,draw=black, domain=0:3.7,samples=300,variable=\\x]  plot (\\x,\\x);\n\\draw[<-,thick,draw=black, domain=-3.7:0,samples=300,variable=\\x]  plot (\\x,{-1 * \\x});\n\\end{tikzpicture}\n\nTo the left of zero, the slope is -1. To the right of zero, the slope\nis 1.  At zero?  The derivative is not defined.\n\nIf a function has a derivative everywhere, it is said to be\n\\newterm{differentiable}. Generally, you can think of differentiable\nfunctions as smooth -- their graphs have no corners.\n\n\\section{Using the definition of derivative}\n\nLet's say that you want to know the slope of $f(x) = -3x^2$ at $x = 2$.\nUsing the definition of the derivative, that would be:\n\n$$f'(2) = \\lim_{\\Delta x \\rightarrow 0}\\frac{f(2 + \\Delta x) - f(2)}{\\Delta x} = \\lim_{\\Delta x \\rightarrow 0}\\frac{-3(2 + \\Delta x)^2- \\left(-3(2)^2\\right)}{\\Delta x} = \\lim_{\\Delta x \\rightarrow 0}\\frac{-12 - 12\\Delta x + -3(\\Delta x)^2 + 12}{\\Delta x} = -12$$ \n\n\n", "meta": {"hexsha": "7faab7047599505660821fbe3caa35b8372db7da", "size": 3732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Limits/differentiation-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/differentiation-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/differentiation-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": 40.1290322581, "max_line_length": 263, "alphanum_fraction": 0.6071811361, "num_tokens": 1547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809304, "lm_q2_score": 0.8824278602705731, "lm_q1q2_score": 0.7815058811022134}}
{"text": "\\section{Mathematical Prerequists}\nLet $R$ be a unital commutative ring (in literature one finds also unitary with the same meaning, i.e. a ring with one). Let us recall some important definitions from commutative and non-commutative algebra. For simplicity, let $\\trm{Hom}$, $\\otimes$ denote $\\trm{Hom}_R$, $\\otimes_R$, resp.\n\\index{Index}{ring!unital}\n\\index{Index}{ring!unitary}\n\\index{Index}{ring!with one}\n\\subsection{\\texorpdfstring{Basics in commutative and\\\\non-commutative algebra}{Basics in commutative and non-commutative algebra}}\n\\begin{defi}\\label{defi01}\nAn \\tb{$R$-algebra} $A$ is an $R$-module, with an $R$-linear map $\\mu : A \\otimes A \\longrightarrow A$. \\bn\n\\item If $\\mu$ is associative, i.e.\n$$\\xymatrix{\nA \\otimes A \\otimes A \\ar[rr]^{id_A \\otimes \\mu} \\ar[d]_{\\mu \\otimes id_A} & & A \\otimes A \\ar[d]^{\\mu}\\\\\nA \\otimes A \\ar[rr]_{\\mu} &&A\\\\\n}$$\ncommutes we call $A$ associative.\n\\index{Index}{algebra!associative}\n\\item\\label{alg_unital} %If there is an element $1_A \\in A$, with left- and right action as identity (i.e. $\\mu(1_A \\otimes\\_)= [x \\longmapsto 1_A \\cdot x] = id_A = \\mu(\\_ \\otimes 1_A) = [x \\longmapsto x \\cdot 1_A]$) $A$ is said to be \\tb{unital}. Alternatively, \nIf there is an $R$-linear map $\\eta : R \\longrightarrow A$ called the unit such that\n$$\\xymatrix{\nR \\otimes A  \\ar[rr]^{\\eta \\otimes id_A} \\ar[rrd]_\\sim& & A \\otimes A\\ar[d]_\\mu& & A \\otimes R\\ar[ll]_{id_A \\otimes \\eta} \\ar[lld]^\\sim\\\\\n&&A&&\\\\\n}$$\ncommutes, we call $A$ unital.\n\\index{Index}{algebra!unital}\n\\item If $\\mu(x \\otimes y) = \\mu(y \\otimes x)$ holds for all $x, y \\in A$ then $A$ is commutative.\n\\index{Index}{algebra!commutative}\n\\item An $R$-submodule $B \\subset A$ is an $R$-subalgebra, if $\\trm{im} \\mu\\mid_{B\\otimes B} \\subset B$.\n\\item An $R$-subalgebra $I \\subset A$ is an left-, right- or two-sided ideal if $\\mu(A \\otimes I) \\subset I$, $\\mu(I \\otimes A) \\subset I$ or both, respectively.\n\\index{Index}{algebra!ideal}\n\\item $A$ is (left-, right-,two-sided-) noetherian, if for every chain of ascending (left-, right-, two-sided-) ideals $\\ldots \\subset I_{n} \\subset I_{n+1} \\subset \\ldots$ in $A$ there is some $m \\in \\nz$ such that $I_m = I_{m+1}$.\n\\item $A$ is called artinian if for every chain of descending (left-, right-, two-sided) ideals $\\ldots \\supset I_n \\supset I_{n+1} \\supset \\ldots$ in $A$ there is some $m \\in \\nz$ sucht that $I_{m} = I_{m+1}$.\n\\index{Index}{algebra!noetherian}\n\\index{Index}{algebra!artinian}\n\\index{Symbol}{$\\mu$}\n\\index{Symbol}{$\\eta$}\n\\en\n\\end{defi}\n\\bmk \\label{alg_general} Some alternative remarks:\\\\\n\\bn\n\\item The reader may find an alternative definition of multiplication in the literature, as an $R$-bilinear map $A \\times A \\longrightarrow A$. However, due to the universal properaty of the tensor product we will use them interchangeably. Furthermore, being a unital algebra is equivalent in demanding a unique element $1_A \\in A$ such that its left action $\\mu(1_A \\otimes \\_) = [a \\longmapsto \\mu(1_A \\otimes a)]$ is identity on $A$.%We may define an algebra $A$ as follows: $A$ is an $R$-module with an $R$-bilinear map $\\cdot : A \\times A \\longrightarrow A$. However, due to the universal property of the $R$-tensor product, we get the following commuting diagram:\n%$$\\xymatrix{A \\times A \\ar[rd]_\\cdot\\ar[r]^\\otimes & A \\otimes A \\ar[d]^\\mu\\\\&A\\\\}$$\n%meaning, we may either start with an $R$-bilinear map $\\cdot : A \\times A \\longrightarrow A$ and define $\\mu(a \\otimes b) := \\cdot(a,b)$ or start with an $R$-linear map $\\mu$ and the tensor product and may define $\\cdot(a,b) := \\mu(\\otimes(a,b))$. Hence, both definition are equivalent. Therefore, we call both maps multiplication and use them interchangeably.\\\\\n\\item Commutativity can be rephrase as a commutative diagram wrt. to the flip isomorphism:\n$$\\tau : A \\otimes A \\longrightarrow A\\otimes A,\\ a \\otimes b \\longmapsto b \\otimes a:$$\n$A$ is commutative if and only if\n$$\\xymatrix{\nA \\otimes A \\ar[r]^\\tau \\ar[rd]_{\\mu} & A \\otimes A \\ar[d]^\\mu\\\\\n&A\\\\\n}$$\ncommutes.\n\\index{Index}{isomorphis!flip}\n\\index{Symbol}{$\\tau$}\n%\\item \\label{alg_unital} For any unital $R$-algebra $A$ we define an additional $R$-linear map:\n%$$\\eta : R \\longrightarrow A,\\ 1_R \\longmapsto 1_A,$$\n%with commuting diagram:\n%$$\\xymatrix{\n%R \\otimes A \\ar[r]^{\\eta \\otimes id_A}\\ar[rd]_\\sim & A \\otimes A\\ar[d]^\\mu & A \\otimes R\\ar[l]_{\\id_A \\otimes \\eta}\\ar[ld]^\\sim\\\\\n%&A.&\\\\\n%}$$\n%\\en\n\\item The triplet $(A,\\mu,\\eta)$ characterizes uniquely any unital, associative algebra over $R$.\n\\en\nFrom our definitions we get immediately\n\\begin{prop}\\label{prop01}\nLet $(A,\\mu,\\eta)$ be an unital associative $R$-algebra and $T A$ denote the tensor algebra over $A$. There is a unique two-sided ideal $I A \\subset T A$ wrt. $\\mu$, s.t. $T A /I A \\simeq A$.% up to isomorphism.\n\\end{prop}\n%\\commt{\n\\bws We offer two alternative proofs.\n\\bn\n\\item Note, that $T A = \\sum_{n \\geq 0} A^{\\otimes n}$ - in particular, we have $A^{\\otimes 0} = R \\simeq R.1_A$, $A^{\\otimes 1} = A$. Thus, $T A = \\bigoplus_{n \\geq 1} A^{\\otimes n}$. Then, put $J A := \\left<a \\otimes b - a b : a, b \\in A\\right>$. Now, it is enough to show that $J A = I A$. First, let us define $\\varphi : T A \\longrightarrow T A/I A$ and the degree map\n$$\\deg : \\bigcup_{i \\geq 0} A^{\\otimes i} \\longrightarrow \\zz \\cup \\{-\\infty\\},\\ x \\in A^{\\otimes i} \\longmapsto \\begin{cases}\ni & x \\neq 0\\\\\n-\\infty & \\trm{else}\\\\\n\\end{cases},$$ extended on $T A\\bsl\\{0\\}$ by $x = \\sum_i x_i \\longmapsto \\max\\{\\deg x_i : x_i \\in A^{\\otimes i}\\bsl\\{0\\}\\}$,\n being sub additive (additive in the case $A$ is a domain). Then by definition, all elements in our quotient algebra $B: = T A/J A$ are represented by elements of at most degree 1, i.e. $\\ov{x} = x + J A \\in B \\RA \\deg x \\leq 1$. Take the inclusion $f : J A \\longrightarrow T A$ and the projection $\\pi : T A \\longrightarrow B$ defining a short exact sequence of (ass) $R$-algebras:\n$$0 \\longrightarrow J A \\stackrel{f}{\\longrightarrow} T A \\stackrel{\\pi}{\\longrightarrow} B \\longrightarrow 0.$$\nFor the inclusion map $\\iota : A \\longrightarrow T A$ we clearly have $\\pi \\circ \\iota \\equiv id_A$ which shows the claim.\\\\\n\\item We recall the universal property of the $R$-tensor product: i.e.\n$$\\xymatrix{\nA \\times A \\ar[rd]_{\\cdot}\\ar[r]^{\\otimes} & A \\otimes_R A\\ar[d]^{\\mu}\\\\\n& A\\\\\n}$$\ncommutes. Hence, we may define:\n$$A \\otimes_A A := A \\otimes_R A/\\sim,\\ \\trm{where}\\ \\sim := \\left\\{(a \\gamma \\otimes b, a \\otimes \\gamma b) \\in \\left(A^{\\otimes_R 2}\\right)^2 : \\gamma \\in A\\right\\}$$\nand by universal prop.: $A \\simeq A\\otimes_A A$ and therefore\n$$\\xymatrix{\nA \\times A \\ar[r]\\ar[d] & A \\otimes_R A \\ar[d]\\ar[ld]_{\\mu}\\\\\nA & A \\otimes_A A.\\ar[l]_{\\sim}\\\\\n}$$\nHence, the two-sided $A$-submodule $I A := \\sum_{a \\otimes b \\in A \\otimes A}T A.(a \\otimes b - a b). T A$ is also a two-sided $T A$-submodule and has the required property:\n$$T A/I A \\simeq A,\\ a \\otimes 1_A \\equiv 1_A \\otimes a \\equiv a, a \\otimes b \\equiv ab \\mod I A,\\ \\forall a, b \\in A.$$\nSummarizing, we get the following commuting diagram:\n$$\\xymatrix{\nA \\ar@{^{(}->}[r]^\\iota \\ar[rd]_\\sim& T A\\ar[d]^\\pi\\\\\n& T A/I A\\\\\n}$$\n%It suffice to show that $I A$ is stable under $A$-automorphisms, i.e. a $G := \\trm{Aut}_{R-\\trm{alg}}(A)$-equivariant space/module.\n%\\indent By definition, $I A$ is stable under conjugation, i.e. $G' = \\left\\{\\varphi_h \\in G : \\varphi = \\left[g \\longmapsto h^{-1} g h\\right], h \\in A^\\times\\right\\}$, since:\n%$$a \\otimes b - a b \\equiv 0 \\mod I A\\LRA \\gamma^{-1} a \\gamma \\otimes \\gamma^{-1} b \\gamma - \\gamma^{-1} a b \\gamma \\equiv 0 \\mod I A.$$\n%Now we assume there is a $\\varphi \\in \\trm{Out}(A)$, where $\\trm{Out}(A) := G/G'$ s.t. $\\varphi(a) \\otimes \\varphi(b) - \\varphi(a) \\varphi(b) \\nequiv 0 \\mod I A$. First, we extend $G$ on $T A$ by simply defining\n%$$\\bao{crrcl}\n%\\hat{\\varphi} = \\sum_{n \\geq 1} \\hat{\\varphi}_n,&\\hat{\\varphi}_n : &T^n A &\\longrightarrow& T^n A\\\\\n%&&&&\\\\\n%&&a_{i_1} \\otimes \\ldots \\otimes a_{i_n} &\\longmapsto& \\varphi(a_{i_1}) \\otimes \\ldots \\otimes \\varphi(a_{i_n}),\\\\\n%&&&&\\\\\n%&&\\hat{\\varphi}_n\\mid_{T A \\bsl T^n A} &=& 0 \\in \\trm{End}(T A)\\\\\n%\\ea$$\n%The quotient $I A/G' := \\sum T A.(a \\otimes b - a b). T A/G' = \\{[c a c' \\otimes d b d' - c a c' d b d'] : c, c', d, d' \\in T A, \\varphi_h(c a c') \\otimes \\varphi_h(d b d') - \\varphi_h(c a c') \\varphi_h(d b d') \\in [c a c'\\otimes d b d' - c a c' d b d'],\\ \\forall \\varphi_h \\in G'\\}$.\n\\en\n\\begin{defi}\\label{defi04}\nLet $A$ be an algebra.\n\\bn\n\\item $A$ is called graded if there exist submodules $A_n$, such that\n$$A = \\bigoplus_{n\\geq 0} A_n\\ \\trm{and}\\ \\mu_A(A_n \\otimes A_m) \\subset A_{n+m}.$$\n\\item $A$ is called filtered if there exist submodules $A^{\\leq n}$, such that\n$$A = \\bigcup_{n \\geq 0} A^{\\leq n}\\ \\trm{and}\\ \\mu_A(A^{\\leq n} \\otimes A^{\\leq m}) \\subset A^{\\leq n + m}.$$\n\\item For a filtered algebra $\\mathcal{A} = \\bigcup \\mathcal{A}^{\\leq n}$ we call\n$$\\trm{gr} \\ \\mathcal{A} := \\bigoplus_{n \\geq 1} A^n,\\ \\trm{where}\\ A^n := \\mathcal{A}^{\\leq n}/\\mathcal{A}^{\\leq n - 1}$$\nthe associated graded algebra. Multiplication $\\mu_{\\trm{gr} \\mathcal{A}}$ is defined by $[x y] \\in A^{n + m}$ for all $x \\in \\mathcal{A}^{\\leq n}, y \\in \\mathcal{A}^{\\leq m}$.\n\\item An algebra $A$ is called a deformation of a filtered algebra $\\mathcal{A}$ if $\\trm{gr} \\mathcal{A} \\simeq A$.\n\\en\n\\index{Index}{algebra!graded}\n\\index{Index}{algebra!filtered}\n\\index{Index}{algebra!associated graded}\n\\end{defi}\n\\bmk Deformation theory is fundamental in the study of singularity theory. For instance, deformation theory of Kleinian singularities $\\cz^2/\\Gamma$ leads to the classification scheme also found in simple Lie algebras (the ADE-system), where $\\Gamma$ is a finite subgroup of $\\trm{Sl}_2(\\cz)$.\\\\\n\\indent The submodules $A_n$ for a given grading are sometimes called the homogeneous submodules and its elements homogeneous.\n\\subsubsection{Algebras and their modules}\nLet $(A,\\mu,\\eta)$ be an $R$-algebra and $M$ an $R$-module. $A$ is assumed to be associative and unital.\n\\begin{defi}\n$M$ is called a left A-module, if there is a homomorphism $\\rho : A \\longrightarrow \\trm{End}_R(M)$ of $R$-algebras - i.e. the following diagrams commute:\n$$\\bao{cc}\n\\xymatrix{\nA \\otimes A \\otimes M \\ar[rr]^{\\id_A \\otimes \\Psi}\\ar[d]_{\\mu_A \\otimes id_M} && A \\otimes M \\ar[d]^\\Psi\\\\\nA \\otimes M\\ar[rr]_\\Psi && M\\\\\n} & \n\\xymatrix{\nR \\otimes M \\simeq M \\ar[rrd]_\\sim \\ar[rr]^{\\eta \\otimes id_M} && A \\otimes M \\ar[d]^\\Psi \\\\\n&&M\\\\\n}\n\\ea$$\nwhere $\\Psi : A \\otimes M \\longrightarrow M, a \\otimes m \\longmapsto \\rho(a)(m)$.\n\\end{defi}\n\\bmk A right $A$-module is constructed similarly (just reversing sides). The pair $(M,\\rho)$ is called an $A$-representation. The associativity is not needed for its definition, hence modules over non-associative algebras are permitted.\n\\subsection{Ore Extensions}\nUnless mentioned otherwise, $A$ is always an unital associative algebra over $R$. Let $X$ be a non-empty set. The $R$-algebra $T X$ is defined as the tensor algebra\n$$T X := \\bigoplus_{n \\geq 0} M(X)^{\\otimes n},\\ \\trm{where}\\ M(X) := \\bigoplus_{x \\in X} R.x \\ \\trm{and}\\ M(X)^{\\otimes 0} := R.$$\n\\begin{defi}\\label{defi02}\nLet $A[X]$ be the left $A$-module $A \\otimes T X$ with left $A$ action $a \\cdot 1_A \\otimes x = a \\otimes x$, for all $x \\in T X$, $a \\in A$.\n\\bn\n\\item For an injective algebra homomorphism $\\alpha : A \\longrightarrow A$ an $\\alpha$-derivation $\\delta : A \\longrightarrow A$ is an $R$-linear map such that\n$$\\delta(a b) = \\alpha(a) \\delta(b) + \\delta(a) b\\ \\forall a, b \\in A.$$\n\\item If in addition, $\\alpha$ is surjective, the triple $A[X, \\alpha, \\delta]$ is called the Ore extension of $A$ with\n$$x a = \\alpha(a) x + \\delta(a), \\forall x \\in X, a \\in A.$$\nIn other words, $A[X]$ has a unique right $A$-module structure, as well, defining an $A$-algebra.% with structure maps:\n%$$\\bao{rrclcl}\n%\\eta :& A & \\longrightarrow&A[X]\\\\\n%& 1_A&\\longmapsto&1_A x^0 =: 1_{A[X]}\\\\\n%&&&\\\\\n%\\mu_{A[X]} :&A[X] \\otimes A[X] & \\longrightarrow& A[X]\\\\\n%& a x \\otimes b y &\\longmapsto& a \\alpha(b) x y + a \\delta(b) y,\\ \\forall x, y \\in X,\\ a, b \\in A\\\\\n%&a x \\otimes b y &\\longmapsto& %a x_1 \\ldots x_n b y\\\\\n%%& &=& a x_1 \\ldots x_{n-1} (\\alpha(b) x_{n} + \\delta(b)) y\\\\\n %%&&=& \n%a \\alpha^n(b) x_1 \\ldots x_n y + a \\delta(\\alpha^{n-1}(b)) x_2 \\ldots x_n y +\\ldots\\\\\n%&&&a \\alpha^{n-1}(\\delta(b)) x_1 \\ldots x_{n-1} y + a \\delta^2 (\\alpha^{n-2}(b) x_3 \\ldots x_n y + \\\\\n%&&&a \\delta(\\alpha(\\delta(\\alpha^{n-3}(b)))) x_2 x_4 \\ldots x_n\n%\\ea$$\n\\en\n\\index{Index}{extension!Ore}\n\\index{Symbol}{$A[X,\\alpha,\\delta]$}\n\\end{defi}\nClearly, the definition of an Ore extension is analogous to the situation of adjoining a transcendental element to a field/ring as in polynomial rings. However, as $A$ or the action of $\\alpha$ does not need to be commutative there are obstacles with regard to right and left-sidedness. The aim is to define a right $A$-module structure on $A[X]$. Firstly, we identify $A \\otimes X$ with $A \\otimes M(X)$ and set $B^n := (A \\otimes X)^{\\otimes n} \\otimes A$ for all $n \\geq 1$ and $B^0 = A$.\n%\\begin{lemm}\n%The two-sided $A$-module $B$, where $B := \\bigoplus_{i \\geq 0} B^i$, has a natural $A$ algebra structure given by the $A$ linear maps:\n%\\scriptsize{\n%$$\\mu^{i,j} : B^i \\otimes B^j \\longrightarrow B^{i+j},\\ (a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1} \\otimes \\ldots \\otimes a_{i_{n-1}} \\otimes x_{i_n} \\otimes a_{i_n} $$\n%}\n%\\end{lemm}\n\\begin{prop}\\label{prop02}\nLet $B$ be the two sided $A$-module, as above:%generated by $A$ and $X$, i.e. $B^n = (A \\otimes X)^{\\otimes n} \\otimes A$ and\n$$B = \\bigoplus_{n \\geq 0} B^n.$$\nThen $B$ has a graded $A$-algebra structure via multiplication\n$$\\bao{rrcl}\n\\mu^{n,m} :& B^n \\otimes B^m &\\longrightarrow& B^{n+m}\\\\\n&&&\\\\\n&a_{i_0} \\otimes x_{i_1} \\otimes \\ldots \\otimes  x_{i_n} \\otimes a_{i_{n}} & & a_{i_0} \\otimes x_{i_1} \\otimes \\ldots \\otimes  x_{i_n} \\otimes a_{i_{n}}\\\\\n&\\otimes &\\longmapsto&\\\\\n& b_{j_0} \\otimes x_{j_1} \\otimes \\ldots \\otimes  x_{j_m} \\otimes b_{j_{m}} & &  b_{j_0} \\otimes x_{j_1} \\otimes \\ldots \\otimes  x_{j_m} \\otimes b_{j_{m}}\\\\\n\\ea$$\nfor all $a_{i_k}, b_{j_l} \\in A$, $x_{i_k}, x_{j_l} \\in X$ and $1 \\leq k \\leq n, 1 \\leq l \\leq m$.\n\\end{prop}\n\\bws The proof is straightforward if we put $\\mu^{n,m}\\mid_{B \\otimes B \\bsl B^n \\otimes B^m} = 0$ and $\\mu = \\sum_{n,m \\in \\nz_0} \\mu^{n,m}$.\n\\begin{prop}\\label{prop03}\nLet $B$ be the algebra as above. The Ore extension $A[X,\\alpha,\\delta]$ is isomorphic to\n$B/I(\\alpha,\\delta)$ where\n$$I(\\alpha,\\delta) := \\left<1_A \\otimes x \\otimes a - \\alpha(a) \\otimes x \\otimes 1_A - \\delta(a): x \\in X, a \\in A\\right>$$\nis a two-sided ideal in $B$. Moreover, if $A$ is zero divisor free then so is $A[X,\\alpha,\\delta]$.\n\\end{prop}\n\\bws Comes in several steps:\n\\bn\n\\item First, let us compute $\\delta(1_A) = \\delta(1_A \\cdot 1_A) = \\alpha(1_A) \\delta(1_A) + \\delta(1_A) 1_A$. Equivalently, $0 = \\alpha(1_A) \\delta(1_A)$. But being a monomorphism $\\alpha(1_A) = 1_A$, hence $\\delta(1_A) = 0$.\n\\item Put $\\iota_l : A[X] \\longrightarrow B$, $a \\otimes x_i := a \\otimes x_{i_1} \\ldots x_{i_n}  \\longmapsto a \\otimes (x_{i_1} \\otimes 1_A) \\otimes \\ldots \\otimes (x_{i_n} \\otimes 1_A)$. This clearly defines a left $A$-module homomorphism. Similarly, we get $\\iota_r : [X]A \\longrightarrow B$, $x_i \\otimes a = x_{i_1} \\ldots x_{i_n} \\otimes a \\longmapsto (1_A \\otimes x_{i_1}) \\otimes \\ldots \\otimes (1_A \\otimes x_{i_n}) \\otimes a$ a right $A$-module homomorphism. Both morphisms are injective as we readily see by our definition. Thus, we see that\n$$A[X], [X]A \\subset B/I(\\alpha,\\delta).$$\nMoreover, $A[X]$ is a $T X$-right module and $[X]A$ is a $T X$-left module.\n\\item Set $C := B/I(\\alpha,\\delta)$ and $\\varphi : B \\longrightarrow C$.\n\\bd\n\\item[Claim:] $\\varphi$ is an $A$-algebra morphism. We are going to proof this claim sequentially.\n\\bn\n\\item $\\varphi$ is a two-sided $A$-module homomorphism and in particular, we have $\\varphi\\mid_{A[X]} \\circ \\iota_l \\equiv id_{A[X]}$. As we just proved both single sided $A$-modules, $A[X], [X]A$, have isomorphic images in $B$ and its quotient algebra. By our definition, $\\varphi$ respects the left $A$-module structure. So let us proof the right $A$-module morphism. As we just saw there is a right $A$ submodule $\\iota_r(X \\otimes A) = 1_A \\otimes X \\otimes A$. Its image under $\\varphi$ is the subset $\\varphi(X \\otimes A)$. But, no matter if we first apply the right action of $A$ on our monomials $x_i \\in X$ or apply the action on $\\varphi(x_i \\otimes a)$ we still get the same value:\n$$\\alpha(a) x_i + \\delta(a) = \\mu_C(\\varphi(x_i) \\otimes \\varphi(a)) = \\varphi(x_i \\otimes a) \\in C.$$\nIn particular we have\n$$\\varphi(X \\otimes A) \\simeq \\varphi(1_A \\otimes X \\otimes A) \\subset \\left\\{\\alpha(a) \\otimes x \\otimes 1_A + \\delta(a) : a \\in A,\\ x \\in X\\right\\} \\subset C^{\\leq 1}.$$\nThis extends to all elements in $[X]A$ as follows: pick $x_{i_1} \\ldots x_{i_n} a \\in X^{\\otimes n} \\otimes A$ and identify with $1_A \\otimes x_{i_1} \\otimes 1_A \\otimes \\ldots \\otimes 1_A \\otimes x_{i_n} \\otimes a \\in B^n$. Then, iteratively apply the following rule - if $I = \\{i_j : 1 \\leq j \\leq n\\}$ is the index set of our monomial $x_i \\in T X$ and $M := \\trm{map}(I,\\{0,1\\}) = \\{0,1\\}^I$, then:\n$$x_{i_1} \\ldots x_{i_n} a = \\sum_{\\substack{m \\in M}} w_{m}(a) x_{i_1}^{m(i_1)} \\ldots x_{i_n}^{m(i_n)} \\in C,\\ \\trm{where}$$\n$$w_{m} := w_{m(i_1)} w_{m(i_2)} \\ldots w_{m(i_n)},\\ w_{m(i_j)} = \\delta^{1-m(i_j)} \\alpha^{m(i_j)},$$\nwhere multiplication simply means composition. \n%and $w_{k \\in \\nz^0} = \\delta^n$ or, equivalently, having deleted all monomials from $x_1 \\ldots x_n$.\nEasily proved by induction: assuming we have the above formular in case $X^{\\otimes n} \\otimes A$, then for $x_{i_0} x_{i_1} \\ldots x_{i_n} a \\in X^{\\otimes n + 1} \\otimes A$ we get:\n\\begin{align*}\nx_{i_0} x_{i_1} \\ldots x_{i_n} a &= x_{i_0} \\sum_{m \\in M} w_k (a) x_{i_1}^{m(i_1)} \\ldots x_{i_n}^{m(i_n)}\\\\\n &= \\sum_m \\alpha( w_m(a) ) x_{i_0}^1 x_{i_1}^{m(i_1)} \\ldots x_{i_n}^{m(i_n)}\\\\ & + \\sum_m \\delta(w_m(a)) x_{i_0}^0 x_{i_1}^{m(i_1)} \\ldots x_{i_n}^{m(i_n)}&&\\\\\n\\end{align*}\nDefining two functions $\\wt{m}_{0,1} : I \\cup \\{i_0\\} \\longrightarrow \\{0,1\\}$, with $\\wt{m}_{0,1}\\mid_I = m$ and $\\wt{m}_0(i_0) = 0, \\wt{m}_1(i_0) = 1$ we get two extensions for each $m \\in M$ on $I \\cup \\{i_0\\}$:\n\\begin{align} \nx_{i_0} \\ldots x_{i_n} a &= \\sum_{\\wt{m} \\in \\wt{M}} w_{\\wt{m}} (a) x_{i_0}^{\\wt{m}(i_0)} \\ldots x_{i_n}^{\\wt{m}(i_n)},\\\\\n\\end{align}\nwhere $\\wt{M} = \\{0,1\\}^{I \\cup \\{i_0\\}}$.\n\\item By definition $B$ is a graded $A$-algebra with a filtration induced by the grading. This filtration is obviously kept under $\\varphi$ ($\\trm{im} \\mu\\mid_{B^{\\leq n}} \\subset C^{\\leq n}$). Thus, we will show that the following diagram commutes:\n$$\\xymatrix{\nB \\otimes B \\ar[d]_{\\mu_B}\\ar[r]^{\\varphi \\otimes \\varphi} & C \\otimes C\\ar[d]^{\\mu_C} \\\\\nB \\ar[r]_{\\varphi} & C.\\\\\n}$$\n\\newcommand{\\mmap}{\\mathfrak{m}}\n\\newcommand{\\nmap}{\\mathfrak{n}}\nOmitting the tensor symbol and ones, the image of any element $x_i a \\otimes x_j b := x_{i_1} \\ldots x_{i_m} a \\otimes x_{j_1} \\ldots x_{j_n} b \\in B^m \\otimes B^n$ is:\n$$\\bao{rrcl}\n&\\varphi \\otimes \\varphi(x_i a \\otimes x_j b) &=& \\sum_{\\mmap \\in M, \\nmap \\in N} w_\\mmap(a) x_{i_1}^{\\mmap(i_1)} \\ldots x_{i_m}^{\\mmap(i_n)}\\\\\n&&& \\otimes w_\\nmap(b) x_{j_1}^{\\nmap(j_1)} \\ldots x_{j_n}^{\\nmap(j_n)}\\\\\n&&&\\\\\n\\RA&\\mu_C(\\varphi \\otimes \\varphi)(x_i a \\otimes x_j b) &=& \\sum_{\\mmap, \\mmap' \\in M, \\nmap\\in N} w_\\mmap(a) w_{\\mmap'}(w_\\nmap(b)) x_{i_1}^{\\mmap(i_1) \\cdot \\mmap'(i_1)} \\ldots x_{i_m}^{\\mmap(i_m) \\cdot\\mmap'(i_m)}\\\\\n&&&\\cdot x_{j_1}^{\\nmap(j_1)} \\ldots x_{j_n}^{\\nmap(j_n)},\\\\\n\\ea$$\nwhere $M = \\{0,1\\}^{\\{i_1,\\ldots,i_m\\}}, N = \\{0,1\\}^{\\{j_1,\\ldots,j_n\\}}$ and $w_q$ as above. The lower part of the diagram yields:\n$$\\bao{rrcl}\n&\\mu_B(x_i a \\otimes x_j b) &=& x_i a x_j b\\\\\n&&&\\\\\n\\RA&\\varphi(x_i a \\otimes x_j b) &=& \\sum_{\\nmap \\in N} w_\\mmap(a) x_i^{\\mmap(i)} w_\\nmap(b) x_j^{\\nmap(j)}\\\\\n&&&\\\\\n&&=& \\sum_{\\mmap, \\mmap' \\in M, \\nmap \\in N} w_\\mmap(a) w_{\\mmap'}(w_\\nmap(b)) x_i^{\\mmap(i) \\cdot \\mmap'(i)} x_j^{\\nmap(j)},\\\\\n\\ea$$\nwhere $x_i^{\\mmap(i)} = x_{i_1}^{\\mmap(i_1)} \\ldots x_{i_m}^{\\mmap(i_m)}$, etc. Obviously, the commutativity holds for all algebra generators. Hence, $\\varphi$ is an $A$-algebra homomorphism.\n%$$\\bao{rcl}\n%\\varphi \\otimes \\varphi(a\\otimes b) &=& \\sum_{n_k \\in X_k,m_l \\in Y_l} a_{i_0} w_{n_1}(a_{i_1}) \\ldots w_{n_n}(a_{i_n}) x_{i_1}^{\\prod_k n_k(i_1)} \\ldots x_{i_n}^{\\prod_k n_k(i_n)}\\\\\n%&&\\\\\n%&& \\otimes b_{j_0} w_{m_1}(b_{j_1}) \\ldots w_{m_m}(b_{j_m}) x_{j_1}^{\\prod_l m_l(j_1)} \\ldots x_{j_m}^{\\prod_l m_l(j_m)},\n%\\ea$$\n%where $X_k = \\{0,1\\}^{\\{i_1,\\ldots,i_k\\}}, Y_l = \\{0,1\\}^{\\{j_1,\\ldots,j_l\\}}$ and each $w_q$ is defined as above. The product is\n%$$\\bao{rcl}\n%\\mu_C(\\varphi \\otimes \\varphi(a\\otimes b)) &=&  \\sum_{n_k, n'_k \\in X_k,m_l \\in Y_l} a_{i_0} w_{n_1}(a_{i_1}) \\ldots w_{n_n}(a_{i_n}) w_{n'_0}(b_{j_0})\\\\&&\\\\\n%&& w_{n'_1}(w_{m_1}(b_{j_1})) \\ldots w_{n'_n}(w_{m_m}(b_{j_m})) \\\\\n%&&\\\\\n%&& x_{i_1}^{\\prod_k n_k(i_1) \\cdot n'_k(i_1)} \\ldots x_{i_n}^{\\prod_k n_k(i_n)\\cdot n'_k(i_1)} x_{j_1}^{\\prod_l m_l(j_1)} \\ldots x_{j_m}^{\\prod_l m_l(j_m)}.\n%\\ea$$\n%Commuting the lower part of the diagram:\n%$$\\mu_B (a \\otimes b) = a_{i_0} x_{i_1} \\ldots x_{i_n} a_{i_n} b_{j_0} x_{j_1} \\ldots x_{j_m} b_{j_m}.$$\n%The image is then:\n%$$\\varphi(\\mu_B(a \\otimes b)) = \n%We have $\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes 1_A) \\varphi(a_{i_1} \\otimes x_{i_2} \\otimes a_{i_2}) = \\varphi(a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1}) \\varphi(1_A \\otimes x_{i_2} \\otimes a_{i_2})$ for all $a_{i_k} \\in A, x_{i_k} \\in X$. First we observe that $\\varphi\\mid_{B^0} = id_{B^0}$ and $\\varphi(B^1) \\subset A \\otimes X \\otimes 1_A \\oplus A$. Also note that the equivalence equals the statement $\\varphi = \\mu_C(\\varphi \\otimes \\varphi) = \\varphi \\mu$. Then we compute\n%$$\\bao{rcl}\n%\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1} \\otimes x_{i_2} \\otimes a_{i_2}) &=& a_{i_0} \\alpha(a_{i_1}) \\alpha^2(a_{i_2}) x_{i_1} x_{i_2} + \\alpha(a_{i_1}) \\alpha \\delta(a_{i_2}) x_{i_1}\\\\\n%&&\\\\\n%&& + \\delta(a_{i_1} \\alpha(a_{i_2})) x_{i_2} + \\delta(a_{i_1} \\delta(a_{i_2}))\\\\\n%&&\\\\\n%\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes 1_A) \\varphi(a_{i_1} \\otimes x_{i_2} \\otimes a_{i_2}) &=& a_{i_0} x_{i_1} a_{i_1} (\\alpha(a_{i_2}) x_{i_2} + \\delta(a_{i_2}))\\\\\n%&&\\\\\n%&=& a_{i_0} x_{i_1} a_{i_1} \\alpha(a_{i_2}) x_{i_2} + a_{i_0} x_{i_1} a_{i_1} \\delta(a_{i_2})\\\\\n%&&\\\\\n%&=& a_{i_0} \\left[\\alpha(a_{i_1} \\alpha(a_{i_2})) x_{i_1} + \\delta(a_{i_1} \\alpha(a_{i_2})) \\right] x_{i_2}\\\\\n%&&\\\\\n%&& + a_{i_0} \\left[\\alpha(a_{i_1} \\delta(a_{i_2}))x_{i_1} + \\delta(a_{i_1} \\delta(a_{i_2}))\\right]\\\\\n%&&\\\\\n%\\ea$$\n%$$\\bao{rcl}\n%\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1}) \\varphi(1 \\otimes x_{i_2} \\otimes a_{i_2}) &=& a_{i_0} (\\alpha(a_{i_1}) x_{i_1} + \\delta(a_{i_1})) (\\alpha(a_{i_2}) x_{i_2} + \\delta(a_{i_2}))\\\\\n%&&\\\\\n%&=& a_{i_0} \\left(\\alpha(a_{i_1}) x_{i_1} \\alpha(a_{i_2}) x_{i_2} + \\alpha(a_{i_1}) x_{i_1} \\delta(a_{i_2})\\right)\\\\\n%&&\\\\\n%&& + a_{i_0} \\left(\\delta(a_{i_1}) \\alpha(a_{i_2}) x_{i_2} + \\delta(a_{i_1}) \\delta(a_{i_2})\\right)\\\\\n%&&\\\\\n%&=& a_{i_0} \\alpha(a_{i_1}) [\\alpha^2(a_{i_2}) x_{i_1} + \\delta(\\alpha(a_{i_2}))] x_{i_2}\\\\ &&\\\\\n%&& + a_{i_0} \\alpha(a_{i_1}) [\\alpha(\\delta(a_{i_2})) x_{i_1} + \\delta(\\delta(a_{i_2}))]\\\\\n%&&\\\\\n%&& + a_{i_0} \\left(\\delta(a_{i_1}) \\alpha(a_{i_2}) x_{i_2} + \\delta(a_{i_1}) \\delta(a_{i_2})\\right)\\\\\n%&&\\\\\n%&=& a_{i_0} \\left(\\alpha(a_{i_1} \\alpha(a_{i_2})) x_{i_1} x_{i_2} + \\alpha(a_{i_1} \\delta(a_{i_2})) x_{i_1}\\right)\\\\\n%&&\\\\\n%&& + a_{i_0} \\underbrace{\\left[\\alpha(a_{i_1}) \\delta(\\alpha(a_{i_2})) + \\delta(a_{i_1}) \\alpha(a_{i_2})\\right]}_{\\delta(a_{i_1} \\alpha(a_{i_2}))} x_{i_2}\\\\\n%&&\\\\\n%&& + a_{i_0} \\underbrace{\\left[\\alpha(a_{i_1}) \\delta(\\delta(a_{i_2})) + \\delta(a_{i_1}) \\delta(a_{i_2})\\right]}_{\\delta(a_{i_1} \\delta(a_{i_2}))}\\\\&&\\\\\n%\\ea$$\n%$$\\bao{rcl}\n%\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1}) \\varphi(1 \\otimes x_{i_2} \\otimes a_{i_2}) &=& \\varphi(a_{i_0} \\otimes x_{i_1} \\otimes 1_A) \\varphi(a_{i_1} \\otimes x_{i_2} \\otimes a_{i_2})\\\\\n%\\ea$$\n%In addition, $\\varphi(\\varphi(a_{i_0} \\otimes x_{i_1} \\otimes a_{i_1}) \\otimes x_{i_2} \\otimes a_{i_2}) = \\varphi(a_{i_0} \\otimes x_{i_1} \\otimes \\varphi(a_{i_1} \\otimes x_{i_2} \\otimes a_{i_2}))$. Hence, our claim above is just shown for $B^{\\leq 2}$. The claim can thus be iteratively extended to all $A$ submodules $B^i$ showing that $\\varphi$ is indeed an algebra homomorphism. Moreover, the two-sided $A$ submodule $I(\\alpha,\\delta)$ is a two-sided ideal in $B$.\n%\\item The ideal $\\ker \\varphi \\subset B$ equals $I(\\alpha,\\delta)$. Set $m(a,x) = 1_A \\otimes x \\otimes a - \\alpha(a) \\otimes x \\otimes 1_A - \\delta(a)$. By definition all elements $f \\in I(\\alpha,\\delta)$ are of the form $f = \\sum_{i \\in \\nz_0} f_i m(x,a) g_i$. Multiplicativity we have $\\varphi(f) = \\sum \\varphi(f_i) \\varphi(m(x,a)) \\varphi(g_i) = \\sum \\varphi(f_i) (\\varphi(1_A \\otimes x \\otimes a) - \\alpha(a) \\otimes x \\otimes 1_A - \\delta(a)) \\varphi(g_i) = \\sum \\varphi(f_i) \\cdot 0 \\cdot \\varphi(g_i) = 0$. Therefore, $f \\in \\ker \\varphi$. Conversely, let $f \\in \\ker \\varphi \\bsl I(\\alpha,\\delta)$\n\\en\n\\ed\n\\item By our proposition \\ref{prop01} that every algebra $A$ has an ideal $IA$ in its tensor algebra $TA$, such that $TA/IA \\simeq A$ it is enough to show that the following diagram commutes:\n$$\\xymatrix{\nB \\ar[d]\\ar[r]_\\varphi & C\\ar[ld]^{\\stackrel{?}{\\sim}}\\ar[d]^\\iota\\\\\nA[X,\\alpha,\\delta]& T C \\ar[l]^\\pi.\\\\\n}$$\nBut clearly, the ideal $I C = \\left<a \\otimes b - a b : a, b \\in C\\right>$ being the kernel of $\\pi : TC \\longrightarrow C$, is equally represented as\n$$I C = \\left<\\underbrace{a \\otimes x - a x}_{A-\\trm{left}\\ \\trm{module}}, \\underbrace{x \\otimes a - \\alpha(a) x - \\delta(a)}_{A-\\trm{right}\\ \\trm{module}} : a \\in A, x \\in X\\right>,$$\nwhere we explicitly give the relations on the tensor elements in $T C$.\n%$B \\simeq T B^1$, for\n%$$IA := \\left<1 \\otimes x \\otimes a - \\alpha(a) \\otimes x \\otimes 1 - \\delta(a) : a \\in A, x \\in X\\right>.$$\n%On the other hand, $I C := \\left<a \\otimes b - a b : a, b \\in C\\right>$.\n\\item If $\\trm{Ann}_R(A) = \\{0\\}$ then: $a b = 0$ if and only if $a = 0$ or $b = 0$, i.e. $A$ is a domain. Then by definition we have for $f, g \\in A[X,\\alpha,\\delta]$ $lt(f g) \\in C^{\\deg f + \\deg g}$, where $lt(f)$ is the leading term of $f$ - i.e. the monomial of highest degree. If $f g = 0$ then $\\deg (f g) = \\max \\underbrace{\\{i \\in \\nz_0 : \\sum_{|k| = i} f_j \\wt{g}_{i-j} \\neq 0\\}}_{= \\emptyset} = -\\infty$ implies either $f_{i_1} = 0$ or $g_{i_2} = 0$ for all $0 \\leq i_1 \\leq \\deg f, 0 \\leq i_2 \\leq \\deg g$ concluding our proof.\n%we conclude the $I(\\alpha,\\delta) = IA[X,\\alpha,\\delta]$.\n%First, let us reassure that $A[X] \\subset B$. Consider the element $a \\otimes (x \\otimes 1_A)^{\\otimes n}$. Then by iteratively applying the definition we have \n%$$a \\otimes (x \\otimes 1_A)^{\\otimes n - 2} \\otimes x \\otimes (1_A\\cdot(\\alpha(1_A) + \\delta(1_A)) \\otimes x \\otimes 1_A = \\ldots = a \\sum_{\\gamma_{i_j} \\in \\{\\alpha,\\delta\\}} \\prod_{j=1}^n \\gamma_{i_j}(1_A) \\otimes (x \\otimes 1_A)^{\\otimes n}$$\n%Obviously, we have $1_A = \\alpha(1_A) + \\delta(1_A)$. Being an algebra monomorphism $\\alpha(1_A) = 1_A$ thus $\\delta(1_A) = 0_A$. Therefore, we may identify $a \\otimes(x\\otimes 1_A)^{\\otimes n}$ with $a \\otimes x^n$.\n%a \\otimes (x \\otimes 1_A)^{\\otimes n - 3} \\otimes x \\otimes (\\alpha(\\alpha(1_A) + \\delta(1_A)) + \\delta(\\alpha(1_A) + \\delta(1_A))) \\otimes x \\otimes 1_A \\otimes x \\otimes 1_A$\n\\en\n\\bsp We want to show two prominent examples for some field $R$ - the polynomial ring $R[X_1,\\ldots,X_n]$ and the tensor algebra $T(R^n)$. In both cases, $\\alpha = id_R$ and $\\delta = 0_R$. Thus, the verification both being Ore extensions of $R$ is straightforward.\\\\\n\\indent A more complicated situation we find in the so called quantum algebras: let $q \\in R^\\times \\bsl\\{1\\}$ and $A = R[X]$. Then the Ore extension $A[Y, \\alpha, \\delta]$, with\n$$\\alpha = [X^i \\longmapsto q^i X^i] \\in \\trm{Aut}_{R-\\trm{alg}}(A)\\ \\forall i \\geq 0,\\ \\delta \\equiv 0,$$\ndefines a non-commutative algebra - as $Y X = q X Y$ implies.\n\\begin{prop}\\label{prop04}\nIf $A$ is noetherian and $|X| < \\infty$ then $A[X,\\alpha,\\delta]$ is noetherian.\n\\end{prop}\n\\bws If $|X| < \\infty$ the module $M(X)$ is noetherian over $R$. In particular, it is an $R$-module free of rank $|X|$. Thus, it suffices to show that $A \\otimes X$ is noetherian as a left $A$-module. If $A$ is noetherian, then each $a \\in A$ is a finite $R$-linear combination of only finitely many generators $B_A := \\{a_i\\} \\subset A$. Hence if $\\left<a_i : i \\in I\\right> = A$, $|I| < \\infty$, then\n$$A \\otimes X = \\bigoplus_{\\substack{i \\in I\\\\x \\in X}} A.a_i.A \\otimes x$$\nis also finitely generated. In particular for $\\rank A < \\infty$, we have $\\rank A \\otimes X = \\rank A \\cdot |X|$, since $M(X)$ was a free $R$-module of rank $|X|$. Therefore, we get that each finite $A$ linear combination of elements in $B$ is also finitely generated over $R$. But being noetherian is kept under epimorphisms, hence we get our claim.\n\\subsection{Derivations and Lie Algebras}\nFor the sake of clarity, we repeat:\n\\begin{defi}\\label{defi05}\nFor an algebra $A$ an $R$-derivation is a map $D$ with\n\\bn\n\\item $D \\in \\trm{End}_R(A)$,\n\\item $D(x y) = D(x) y + x D(y)$ (Leibniz rule).\n\\en\nFurthermore, we have\n\\bn\n\\item the set of $R$-derivations is denoted by $\\trm{Der}_R(A)$,\n\\item $A$ is called a (non-trivial) differential algebra over $R$ if $\\trm{Der}_R(A) \\neq \\{0\\}$,\n\\en\n\\index{Index}{derivation}\n\\index{Index}{algebra!differential}\n\\index{Symbol}{$\\trm{Der}_R(A)$}\n%\\index{Symbol}{$\\trm{Der}_R(A)$}\n\\end{defi}\nAny ring $R$ defines a trivial differential algebra over itself, taking the zero-homomorphism as $R$-derivation.\n%\\bmk Note, an $R$-derivation is an $id_A$ derivation in the sense of Ore extensions. That to say, is equivalent to saying $A$ is an $R[X,id_A,D]$ algebra over $R$, where\n%$$X = \\{x \\in A : \\exists D \\in \\trm{Der}_R(A),\\ D(x) \\neq 0\\}$$\n%and $D$ are generators of $\\trm{Der}_R(A)$.\n\\begin{defi}\\label{defi06}\nAn Lie algebra $\\mathfrak{g}$ is an $R$-algebra with the $R$-linear map $\\mu : \\mathfrak{g} \\otimes \\mathfrak{g} \\longmapsto \\mathfrak{g}$, s.t.\n\\bn\n\\item $\\mu(x \\otimes y) = -\\mu(y \\otimes x)$ (anti symmetric) and\n\\item for any $x_i \\in \\mathfrak{g}$, $i = 1, 2, 3$, we have\n$$\\mu \\circ(\\mu \\otimes id_\\mathfrak{g})(x_1 \\otimes x_2 \\otimes x_3 + x_2 \\otimes x_3 \\otimes x_1 + x_3 \\otimes x_1 \\otimes x_2) = 0,$$ \nthe Jacobian identity.\n\\item \\label{LieAlgFromAlg} For any algebra $A$ the $R$-module $\\mathfrak{g}(A)$ with $\\mu = [x \\otimes y \\longmapsto x y - y x]$ is the Lie algebra associated with $A$, coinciding with $A$ as a set. The $R$-bilinear map (multiplication) is denoted by $[.,.] : \\mathfrak{g} \\times \\mathfrak{g}\\longrightarrow \\mathfrak{g}$, the so called commutator of $A$.\n\\en\n\\index{Index}{Lie algebra}\n\\index{Index}{commutator}\n\\index{Symbol}{$\\mathfrak{g}$}\n\\end{defi}\n\\begin{koro}\\label{koro02}\nThe set of derivations $\\trm{Der}_R(A)$ is a Lie algebra via the above defined commutator on $\\trm{End}_R(A)$.\n\\end{koro}\n\\bmk All definitions of morphisms, sub Lie algebras, modules and ideals translate from algebras (although, ideals in Lie algebras are always two-sided). We repeat, if $(A, \\mu, \\eta)$ is some $R$-algebra its Lie algebra $\\mathfrak{g}(A)$ is the same set, only with a different multiplication map.\n\\bsp Some prominent examples:\n\\bn\n\\item for any $R$-module $M$, the endomorphism algebra $\\trm{End}_R(M)$ is a Lie algebra with the commutator inducing multiplication $\\mu$, denoted by\n$$\\mathfrak{gl}_R(M).$$\nIf $M \\simeq R^n$, then $\\mathfrak{gl}_R(M)$ is also denoted by $\\mathfrak{gl}_n(R)$,\n%\\item for any associative $R$-algebra $A$, the algebra $(A, \\mu_{\\trm{Lie}})$, where $\\mu_{\\trm{Lie}} := [.,.]$, is an $R$-Lie algebra - denoted by\n%$$\\mathfrak{g}(A),$$\n\\item the set of upper triangular matrices, $\\mathfrak{b} \\subset \\mathfrak{gl}_n(R)$, and strictly upper triangular matrices $\\mathfrak{n} \\subset \\mathfrak{b}$ are Lie algebras,\n\\item the set of all square matrices with trace zero is a sub Lie algebra of $\\mathfrak{gl}_n(R)$, denoted by $\\mathfrak{sl}_n(R)$, called the special Lie algebra.\n\\en\n\\begin{defi}\\label{PartialDiff}\nA differential algebra $(A,\\mu,D)$ is called a partial differential algebra, if the Lie algebra $\\trm{Der}_R(A) = \\left<D\\right>_{\\trm{Lie}}$ is commutative:\n$$[\\partial,\\delta] = 0,\\ \\forall \\partial, \\delta \\in \\trm{Der}_R(A).$$\n\\index{Index}{algebra!partial differential}\n\\end{defi}\nFirstly, we remark that $A$ itself may be an Lie algebra (hence, we omit the unit map). This definition is due to Ritt (\\cite{Ritt}, pg. 163), who, however, simply demanded commutativity of the derivations.\n\\bsp \\label{partial_diff_alg_examp}We give an example and a counter-example.\n\\bn\n\\item\\label{partial_diff_exp01} For all $n \\geq 1$ is $(k[x_1,\\ldots,x_n], \\Delta = \\{\\partial_1,\\ldots,\\partial_n\\})$ a partial differential algebra:\n$$\\bao{rclcl}\n\\partial_i &=& [x_{j}^{k} &\\longmapsto& \\sum_{k} \\delta_{ij} x_j^{k-1} = \\delta_{ij} k x_j^{k-1}]\\\\\n&&&&\\\\\n\\partial_i \\partial_j &=& [x^k := x_1^{k_1} \\ldots x_n^{k_n} &\\longmapsto & k_i k_j x_1^{k_1}\\ldots x_i^{k_i - 1} \\ldots x_j^{k_j-1} \\ldots x_n^{k_n}],\\ \\forall 1 \\leq i < j \\leq n\\\\\n&&&&\\\\\n\\partial_j \\partial_i &=& [x^k := x_1^{k_1} \\ldots x_n^{k_n} &\\longmapsto & k_i k_j x_1^{k_1}\\ldots x_i^{k_i - 1} \\ldots x_j^{k_j-1} \\ldots x_n^{k_n}],\\ \\forall 1 \\leq i < j \\leq n,\\\\\n\\ea$$\nwhere $\\delta_{ij}$ is the Kronecker-Delta. The special case $n = 1$ is simply the differential algebra over a polynomial ring in one indeterminate over $k$.\n\\item\\label{partial_diff_exp02} Let $k$ be a field with $\\trm{char} k \\neq 2$ and $k[x,x^{-1}]$ denote the localization of $k[x]$, i.e. the ring of Laurent polynomials with $n = 1$ in our last example. The differential ring $(k[x,x^{-1}], \\Delta = \\{\\partial_1, \\partial_{-1}\\})$, with:\n$$\\bao{rcl}\n\\partial_1 &=& \\left[\n\\bao{rcl}\nx^i &\\longmapsto& i x^{i-1}\\\\\nx^{-i}&\\longmapsto& -i x^{-i-1}\\\\\n\\ea\\right]\\\\\n&&\\\\\n\\partial_{-1} &=& \\left[\n\\bao{rcl}\nx^i &\\longmapsto& -i x^{i+1}\\\\\nx^{-i} &\\longmapsto& i x^{-i+1},\\\\\n\\ea\\right]\\\\\n\\ea$$\nis not a partial differential algebra over $k$, as\n$$\\bao{rcl}\n\\partial_{-1} \\partial_1 &=& \\left[\n\\bao{rcl}\nx^i &\\longmapsto& -i (i + 1) x^i\\\\\nx^{-i}&\\longmapsto& -i (i - 1) x^{-i}\\\\\n\\ea\\right]\\\\\n&&\\\\\n\\partial_1 \\partial_{-1} &=& \\left[\n\\bao{rcl}\nx^i &\\longmapsto& -i (i - 1) x^i\\\\\nx^{-i}&\\longmapsto& -i (i + 1) x^{-i}\\\\\n\\ea\\right]\\\\\n\\ea$$\ndo not agree and therefore its commutator is:\n$$\\bao{rcl}\n[\\partial_1,\\partial_{-1}] &=& \\left[\\bao{rcl}\nx^i &\\longmapsto& 2 i x^i\\\\\nx^{-i} &\\longmapsto& -2 i x^{-i}.\\\\\n\\ea\\right]\\\\\\ea$$\nWe claim that our derivation Lie algebra $\\mathfrak{g}$, generated by $\\Delta$, is isomorphic to $\\mathfrak{sl}_2(k)$. In particular, $k[x,x^{-1}]$ is an $\\mathfrak{sl}_2(k)$-module. Identifying $H = [\\partial_1,\\partial_{-1}]$, $X = \\partial_1$ and $Y = \\partial_{-1}$, we get an isomorphism of $k$-vector spaces (using $\\mathfrak{sl}_2(k) = k.X \\oplus k.Y \\oplus k.H$). Now, it is enough to show this is also an isomorphism of Lie algebras. But by our computation above, we see already: $[X,H] = 2 X, [Y,H] = -2 Y$ and, by definition, $[X,Y] = H$, completing the proof.\n\\en\n\\subsubsection{The Universal Enveloping Algebra}\nA consequence of the universal property of algebras we have the following definition:\n\\begin{defi}\\label{defi07}\nFor every Lie algebra $\\mathfrak{g}$ there exists a unique associative algebra $U(\\mathfrak{g})$ and a homomorphism of Lie algebras $\\iota : \\mathfrak{g} \\longrightarrow U(\\mathfrak{g})$, universal in the following sense. For each associative algebra $A$ and a homomorphism of Lie algebras $f : \\mathfrak{g} \\longrightarrow \\mathfrak{g}(A)$, there exists an unique morphisms of algebras $g : U(\\mathfrak{g}) \\longrightarrow A$ such that\n$$\\xymatrix{\n\\mathfrak{g} \\ar[r]^{\\iota}\\ar[dr]_f & U(\\mathfrak{g})\\ar[d]^g\\\\\n&A\\\\\n}$$\ncommutes.\n\\index{Index}{algebra!univeral enveloping}\n\\index{Symbol}{$U(\\mathfrak{g})$}\n\\end{defi}\nWe recall that $\\mathfrak{g}(A)$ and $A$ coincide as sets (see def. \\ref{defi06}\\ref{LieAlgFromAlg}) and the Lie algebra structure on $U(\\mathfrak{g})$ is given by the commutator. The above definition gives us the so called universal property, hence the name. In later examples we will see the application of both concepts.\n\\begin{prop}\\label{prop05}\nLet $T\\mathfrak{g}$ be the tensor algebra of $\\mathfrak{g}$, then\n$$T \\mathfrak{g}/\\left<x \\otimes y - y \\otimes x - [x,y]: x, y \\in \\mathfrak{g}\\right> \\simeq U(\\mathfrak{g}).$$\n\\end{prop}\n\\bws We recall proposition \\ref{prop01} that $U(\\mathfrak{g}) \\simeq T U(\\mathfrak{g})/I U(\\mathfrak{g})$ for some two-sided ideal $IU(\\mathfrak{g})$ in the universal enveloping algebra. The ideal is generated by all elements of the form $a \\otimes b - a b \\in \\mathfrak{g}^{\\otimes 2} \\oplus \\mathfrak{g}$. Clearly, $b \\otimes a - ba$ is also a generator. Therefore, the element $a \\otimes b - a b - b \\otimes a + b a$ is indeed another generator. Recalling the definition of the commutator $[a,b] = ab - ba$ we get that\nthe generators\n$$a \\otimes b - b \\otimes a - \\underbrace{a b - b a}_{[a,b]} = a \\otimes b - b \\otimes a - [a,b]$$\nuniquely define an associative algebra containing $\\mathfrak{g}$ as Lie algebra.\\\\\n\\bmk The universal enveloping algebra of a one-dimensional $\\qz$ Lie algebra will be the centerpiece of the examples discussed in this paper.\n\\subsection{Coalgebras}\nThe concept of a coalgebra is dual to that of an (associative unital) algebras. To recall, each associative unital algebra $A$ is described by the two $R$-linear maps $\\mu : A \\otimes A \\longrightarrow A$ and $\\eta : R \\longrightarrow A$, i.e. the triple $(A,\\mu,\\eta)$ contains already all information of $A$ given the commutative diagrams in definition \\ref{defi01}, \\ref{alg_unital} and its subsequent remark.\n\\begin{defi}\\label{defi08}\nA coalgebra is an $R$-module $C$ with two $R$-linear maps $\\Delta : C \\longrightarrow C \\otimes C$, $\\eps : C \\longrightarrow R$, called the comultiplication or coproduct and counit, and the following properties:\n\\bn\n\\item $(id_C \\otimes \\Delta) \\circ \\Delta = (\\Delta \\otimes id_C) \\circ \\Delta$ (coassociativity) and\n\\item $(id_C \\otimes \\eps) \\circ \\Delta = (\\eps \\otimes id_C) \\circ \\Delta = id_C$ (counitarity).\n\\en\nIn addition, if $\\tau : C \\otimes C \\longrightarrow C\\otimes C$, $c \\otimes c' \\longmapsto c' \\otimes c$ is the flip isomorphism, we call $(C, \\Delta, \\eps)$ cocommutative, if $\\tau \\Delta = \\Delta$.\n\\index{Index}{coalgebra}\n\\index{Index}{coassociativity}\n\\index{Index}{counitality}\n\\index{Index}{cocommutative}\n\\index{Symbol}{$\\Delta$}\n\\index{Symbol}{$\\eps$}\n%\\index{Symbol}{counitality}\n%\\index{Symbol}{cocommutative}\n\\end{defi}\n\\bmk The properties of coalgebras can be reformulated in terms of commuting diagrams:\n$$\\bao{cc}\n\\xymatrix{\nC \\otimes C \\otimes C && C \\otimes C\\ar[ll]_{id \\otimes \\Delta}\\\\\nC\\otimes C \\ar[u]^{\\Delta \\otimes id}&& C\\ar[ll]^{\\Delta}\\ar[u]_{\\Delta}\\\\\n} & \\xymatrix{R \\otimes C & \\ar[l]_{\\eps \\otimes id_C} C \\otimes C \\ar[r]^{id_C \\otimes \\eps}& C \\otimes R\\\\\n&C \\ar[lu]^\\simeq \\ar[u]_\\Delta \\ar[ru]_\\simeq&\\\\\n}\\ea$$\nwhere we identify $R \\otimes C \\simeq C \\simeq C \\otimes R$ and $C \\otimes (C \\otimes C) \\simeq C^{\\otimes 3} \\simeq (C \\otimes C) \\otimes C$. The left and right hand diagrams represent the coassociativity and the counitality, respectively. Lastly, cocommutativity can expressed as\n$$\\xymatrix{\nC \\otimes C & C \\otimes C\\ar[l]_\\tau\\\\\n&C \\ar[lu]^\\Delta\\ar[u]_\\Delta.\\\\\n}$$\n%One important theorem in the theory of coalgebras, which we are not going to prove, reads as\n%\\begin{satz}\n%Any element in a coalgebra is contained in a finitely generated sub-coalgebra.\n%\\end{satz}\nClearly, reversion of arrows in the commutative diagrams defining algebras (commutative, associative, unital) results in the above diagrams (cocommutative, coassociative and counital, resp.).\n\\subsubsection{Duals of coalgebras}\n\\begin{prop}\\label{prop06}\nIf $C$ is a coalgebra, then $C^* = \\trm{Hom}(C,R)$ is an associative unital algebra. The multiplication is called convolution.\\index{Index}{convolution}\n\\end{prop}\n\\bws First, let us define the multiplication and unit via the duals of the comultiplication and counit:\n$$\\bao{rrcl}\n\\eta_{C^*} := \\eps^* :& R \\simeq R^* &\\longrightarrow& C^*\\\\\n&&&\\\\\n&r &\\longmapsto& r \\eps = [x \\mapsto r \\eps(x)]\\\\\n&&&\\\\\n\\mu_{C^*} := \\Delta^* :& (C \\otimes C)^* \\simeq C^* \\otimes C^* &\\longrightarrow & C^*\\\\\n&&&\\\\\n&\\alpha \\otimes \\beta &\\longmapsto& \\mu_R \\circ (\\alpha \\otimes \\beta) \\circ \\Delta\\\\\n\\ea$$\nNow, it is easy to check that the above defined diagrams commute. For simplicity we omit the subscripts. Let $\\alpha, \\beta, \\gamma \\in C^*$, first we compute:\n$$\\mu_{C^*} = \\mu_R \\circ (ev \\otimes ev) \\circ (id_{C^*} \\otimes \\tau_{C^*\\otimes C} \\otimes id_C) \\circ (id_{C^{* \\otimes 2}} \\otimes \\Delta),$$\nwhere $ev : C^* \\otimes C \\longrightarrow R, \\alpha \\otimes c \\longmapsto \\alpha(c)$. Now we see that\n$$\\bao{rcl}\n\\mu_{C^*} \\circ (id_{C^*} \\otimes \\mu_{C^*})(\\alpha \\otimes \\beta \\otimes \\gamma) &=& \\mu_R(\\alpha \\otimes \\mu_R(\\beta \\otimes \\gamma)(id_C \\otimes \\Delta)) \\circ \\Delta\\\\\n&&\\\\\n\\mu_{C^*}(\\mu_{C^*} \\otimes id_{C^*})(\\alpha\\otimes\\beta\\otimes\\gamma) &=& \\mu_R \\circ (\\mu_R \\circ (\\alpha \\otimes \\beta) \\circ \\Delta \\otimes \\gamma)\\circ \\Delta.\\\\\n\\ea$$\nSo for any given $x \\in C$ we have by linearity and coassociativity ($(\\Delta \\otimes id)\\Delta(x) = (id \\otimes \\Delta)\\Delta(x)$):\n$$\\bao{rcl}\n\\mu_R(\\alpha \\otimes \\mu_R(\\beta \\otimes \\gamma)(id_C \\otimes \\Delta)) \\circ \\Delta(x) &=& \\sum_{(x)} \\mu_R(\\alpha(x_{(1)}) \\otimes \\mu_R(\\beta \\otimes \\gamma)\\Delta(x_{(2)}))\\\\\n&&\\\\\n &=& \\sum_{(x),(x_2)} \\mu_R(\\alpha(x_{(1)}) \\otimes \\beta(x_{(21)}) \\gamma(x_{(22)}))\\\\\n&&\\\\\n &=& \\sum_{(x),(x_2)} \\alpha(x_{(1)}) \\beta(x_{(2)}) \\gamma(x_{(3)})\\\\\n&&\\\\\n\\mu_R \\circ (\\mu_R \\circ (\\alpha \\otimes \\beta) \\circ \\Delta \\otimes \\gamma)\\circ \\Delta(x) &=& \\sum_{(x)} \\mu_R(\\mu_R(\\alpha \\otimes \\beta)\\Delta(x_{(1)}) \\otimes \\gamma(x_{(2)}))\\\\\n&&\\\\\n &=& \\sum_{(x_1),(x)} \\mu_R(\\alpha(x_{(11)}) \\beta(x_{(12)}) \\otimes \\gamma(x_{(2)}))\\\\\n &&\\\\\n &=& \\sum_{(x_1),(x)} \\alpha(x_{(1)}) \\beta(x_{(2)}) \\gamma(x_{(3)})\\\\\n\\ea$$\nHence, we have an associative linear map $\\mu$. On the other hand - identifying $R \\otimes C^* \\simeq C^* \\simeq C^* \\otimes R$, we get from counitality:\n$$\\bao{rclcl}\n((id \\otimes \\eta)\\alpha\\otimes r)\\Delta(x) &=& \\sum_{(1),(2)} r \\alpha(x_{(1)}) \\otimes \\eps(x_{(2)}) &=& r \\sum_{(1),(2)} \\alpha(x_{(1)}) \\otimes \\eps(x_{(2)})\\\\\n&&&&\\\\\n&=& \\alpha\\underbrace{\\left(\\sum_{(1),(2)} x_{(1)} \\eps(x_{(2)})\\right)}_{x} \\otimes r &=& r \\alpha(x)\\\\\n&&&&\\\\\n((\\eta \\otimes id) r\\otimes \\alpha)\\Delta(x) &=& \\sum_{(1),(2)} r \\eps(x_{(1)}) \\otimes \\alpha(x_{(2)}) &=& \\sum_{(1),(2)} r \\eps(x_{(1)}) \\otimes \\alpha(x_{(2)})\\\\\n&&&&\\\\\n&=& r \\otimes \\alpha(\\underbrace{\\sum_{(1),(2)} \\eps(x_{(1)}) x_{(2)}}_{x}) &=& r \\alpha(x)\\\\\n\\ea$$\nwhich defines our two structure maps in the triple $(C^*, \\mu, \\eta)$.\\\\\n\\indent Note however, in general the converse does not hold.\n\\begin{defi}\\label{defi09} Let $R$ be a ring.\n \\bn\n \\item An $R$-module $M$ is called projective if there is a lifting property:\n Let $N, P$ be two $R$-modules and $\\varphi : N \\rightarrow P$ an $R$-epimorphism, for every $f \\in \\trm{Hom}(M,N)$ there is at least one $g \\in \\trm{Hom}(M,P)$ such that $f \\circ \\varphi = g$.\n \\item An $R$-module is of finite type if every proper $R$-submodule $M'$ is noetherian.\n \\en\n\\index{Index}{module!finite type}\n\\index{Index}{module!projective}\n\\end{defi}\nNote, the first definition does not provide a universal condition. We may have more than one such map. However, we get\n\\begin{prop}\\label{prop07}\nIf the algebra $A$ is a projective $R$-module of finite type then, $A^*$ is a coalgebra.\n\\end{prop}\nWe omit the proof and refer the reader to \\cite{OmSho}. An important consequence is that, for $R$ a field, all finite-dimensional $R$-algebras have coalgebras as duals. An other immediate consequence of \\ref{prop06} we get\n\\begin{koro}\\label{koro03}\nLet $C$ be a (coass, counital) coalgebra and $A$ an associative, unital algebra, both over $R$. The set $\\mathcal{A}_C := \\trm{Hom}(C^*,A)$ is an associative unital algebra, with multiplication\n$$\\mu_* : \\mathcal{A}_C \\otimes \\mathcal{A}_C \\longrightarrow \\mathcal{A}_C,\\ f \\otimes g \\longmapsto \\mu_A \\circ(f\\otimes g) \\circ \\Delta_C$$\ncalled the convolution (denoted by $*$) and unit $\\eta_A \\circ \\eps_C$.\n\\end{koro}\n\\subsubsection{Comodules, coideals and homomorphisms of coalgebras}\n\\begin{defi}\\label{defi10}\nFor each coalgebra $C$ we define a left $C$-comodule $M$ as a module over $R$ with structure map $\\rho_M = \\rho : M \\longrightarrow C \\otimes M$ such that\n\\bn\n\\item $(\\Delta \\otimes id_M) \\rho = (id_C \\otimes \\rho)\\rho$,\n\\item $(\\eps \\otimes id_M) \\rho = id_M$.\n\\en\nAdditionally, we define a sub-comodule $N \\subset M$ via restriction of $\\rho\\mid_N$. A sub coalgebra is a sub-comodule $C' \\subset C$ with structure map $\\Delta_{C'} = \\Delta\\mid_{C'}$. A coideal $I \\subset C$ is a two-sided sub $C$-comodule of $\\ker \\eps$ such that\n$$I \\subset \\ker \\eps \\ \\wedge \\ \\Delta(I) \\subset I \\otimes C + C \\otimes I.$$\nFor two left $C$-comodules $M, N$, a morphism of left $C$-comodules is a module homomorphism $f : M \\longrightarrow N$ such that\n$$\\rho_N f = (id_C \\otimes f) \\rho_M.$$\nMoreover, if $C$, $C'$ are coalgebras, then a homomorphism of coalgebras is morphism $f \\in \\trm{Hom}(C, C')$, such that:\n$$\\Delta_{C'} f = (f \\otimes f) \\circ \\Delta_C.$$\n\\index{Index}{comodule}\n\\index{Index}{coideal}\n\\index{Index}{coalgebra!homomorphisms of}\n\\index{Symbol}{$\\rho_M$}\n\\end{defi}\nThe definitions can be readily extended for right and two-sided $C$ comodules and homomorphism.\n\\bsp \\label{coalg_example} We give two examples via the duals of finite-dimensional/free of finite rank $R$-algebras:\n\\bn\n\\item \\label{coalg01} Let $R$ be a unique factorization domain and $A := R[x]/\\left<x^2\\right>$ the ring of dual numbers over $R$. Its dual is\n$$C := A^* = R.\\delta_{\\ov{1}} \\oplus R.\\delta_{\\ov{x}},\\ \\trm{where}\\ \\delta_y(z) = \\begin{cases}\n1 & y = z\\\\\n0 &\\trm{else}\\\\\n\\end{cases},\\ \\forall y, z \\in \\{\\ov{1},\\ov{x}\\}.$$\nThe comultiplication is the dual map of the multiplication on $A$:\n$$\\Delta := \\mu^* = \\left[\\alpha \\longmapsto \\alpha \\circ \\mu\\right].$$\nHence, we get:\n$$\\bao{rcl}\n\\delta_{\\ov{1}} &\\longmapsto& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}}\\\\\n\\delta_{\\ov{x}} &\\longmapsto& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\\\\n\\ea$$\nas images for the comultiplication. The images of the counit are consequently:\n$$\\bao{rcl}\n\\delta_{\\ov{1}} &\\longmapsto& 1\\\\\n\\delta_{\\ov{x}} &\\longmapsto& 0.\\\\\n\\ea$$\nThe coassociativity is easily checked for both generators. Moreover, cocommutativity is evident.\n\\item \\label{coalg02} Let $R$ be a field such that $x^2 + 1$ is irreducible over $R$ and $A := R[x]/\\left<x^2 + 1\\right>$. Following our last example, we get for $C := A^*$:\n$$\\bao{rrcl}\n\\Delta:& C &\\longrightarrow& C \\otimes C\\\\\n& \\delta_{\\ov{1}} &\\longmapsto & \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\\\\n& \\delta_{\\ov{x}} &\\longmapsto & \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\\\\n\\ea$$\nand a counit similar to the one in our last example. As in the last example, $C$ is cocommutative. However, coassociativity is not that easily seen:\n$$\\bao{rcl}\n(\\Delta \\otimes id_C)\\Delta(\\delta_{\\ov{1}}) &=& \\Delta \\otimes id_C\\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right)\\\\\n&=& \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right) \\otimes \\delta_{\\ov{1}} - \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right) \\otimes \\delta_{\\ov{x}}\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\n\\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}}\\\\\n&&\\\\\n(id_C \\otimes \\Delta)\\Delta(\\delta_{\\ov{1}}) &=& id_C \\otimes \\Delta\\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right)\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right) - \\delta_{\\ov{x}} \\otimes \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right)\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\n\\otimes \\delta_{\\ov{1}}\\\\\n\\ea$$\n$$\\bao{rcl}\n(\\Delta \\otimes id_C)\\Delta(\\delta_{\\ov{x}}) &=& \\Delta \\otimes id_C\\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right)\\\\\n&=& \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right) \\otimes \\delta_{\\ov{x}} + \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right) \\otimes \\delta_{\\ov{1}}\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\n\\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}}\\\\\n&&\\\\\n(id_C \\otimes \\Delta)\\Delta(\\delta_{\\ov{x}}) &=& id_C \\otimes \\Delta\\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right)\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}}\\right) + \\delta_{\\ov{x}} \\otimes \\left(\\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}\\right)\\\\\n&=& \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} + \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} + \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{1}} \\otimes \\delta_{\\ov{1}} - \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}} \\otimes \\delta_{\\ov{x}}.\\\\\n\\ea$$\n\\en\nBoth examples are cocommutative, coassociative and counital coalgebras. However, they are not isomorphic over the same field/ring. This is clear if we recall that the dual of a coalgebra is an algebra. If both would be isomorphic, so would be their respective duals. Nevertheless, the first example $(A_1 = R[x]/\\left<x^2\\right>$, see \\ref{coalg01}) contained a nilpotent element, the second example $(A_2 = R[x]/\\left<x^2 + 1\\right>$, see \\ref{coalg02}) is either reduced (trivial nilradical) or is an integral ring extension (if $x^2 + 1$ has no roots in $R$, as we demanded). On the other hand, both coalgebras contain a coideal generated by the element $\\delta_{\\ov{x}}$. Hence, we get a coalgebra homomorphism\n$$A_i^* \\longrightarrow R,\\ a_1 \\delta_{\\ov{1}} + a_x \\delta_{\\ov{x}} \\longmapsto a_1,\\ \\trm{for}\\ i = 1,2$$\n\\begin{defi}\\label{coalg_type}\nLet $C$ be a non-trivial coalgebra over some field $k$.\n\\bn\n\\item\\label{coalg_irred} We call $C$ irreducible if any two subcoalgebras $C', C'' \\subset C$ have non-zero intersection.\n\\item\\label{coalg_simp} We call $C$ simple if $C$ has no non-trivial proper subcoalgebra $C' \\subsetneq C$.\n\\item\\label{coalg_point} We call $C$ pointed if all its simple subcoalgebras are of dimension one.\n\\item \\label{coalg_group}We call an element $c \\in C$ group-like if $\\Delta(c) = c \\otimes c$.\n\\item\\label{coalg_skew}We call $c \\in C$ $(g,h)$-skew primitive if $\\Delta(c) = g \\otimes c + c \\otimes h$ for some group-like elements $g, h \\in C$.\n\\en\n\\index{Index}{coalgebra!irreducible}\n\\index{Index}{coalgebra!simple}\n\\index{Index}{coalgebra!pointed}\n\\index{Index}{element!group-like}\n\\index{Index}{element!skew-primitive}\n\\end{defi}\n\\bmk Clearly, all group-like elements of a coalgebra generate simple subcoalgebras. The first of examples \\ref{coalg_example} has only one proper subcoalgebra generated by $\\delta_{\\ov{1}}$ which is simple. Therefore, it is reducible and pointed. The latter example is irreducible as $\\Delta(\\delta_{\\ov{z}})$ is in $C^{\\otimes 2}$ for $\\ov{z} = \\ov{1}, \\ov{x}$, but not simple.\n\\begin{defi}\nLet $(C, \\Delta_C, \\eps_C)$ and $(D, \\Delta_D, \\eps_D)$ be two coalgebras over $R$. The tensor product $C \\otimes D$ has a coalgebra structure via\n$$\\Delta_\\otimes = (id_C \\otimes \\tau \\otimes id_D) (\\Delta_C \\otimes \\Delta_D),\\ \\eps_\\otimes = \\eps_C \\otimes \\eps_D.$$\n\\end{defi}\n\\begin{lemm}\nIf $(C, \\Delta, \\eps)$ is a coalgebra over $R$ and $A \\in \\trm{CAlg}_R$ then\n$$\\iota : C \\longrightarrow A \\otimes C, c \\longmapsto 1_A \\otimes c$$\nhas a $A$-coalgebra structure via\n$$\\Delta_A := (id_{A \\otimes C} \\otimes \\iota) (id_A \\otimes \\Delta),\\ \\eps_A = id_A \\otimes \\eps$$\n\\end{lemm}\n\\bws Let $c \\in C$, $C' = A \\otimes C$ and $C$ being coassociative then\n$$\\bao{rclcl}\n\\Delta_A(1_A \\otimes c) &=& (id_{C'} \\otimes \\iota)(1_A \\otimes \\Delta(c)) &=& (id_{C'} \\otimes \\iota)\\left(1_A \\otimes \\left(\\sum_{(c)} c_{(1)} \\otimes c_{(2)}\\right)\\right)\\\\\n&&&&\\\\\n&=& \\sum_{(c)} 1_A \\otimes c_{(1)} \\otimes \\iota(c_{(2)}) &=& \\sum_{(c)} 1_A \\otimes c_{(1)} \\otimes 1_A \\otimes c_{(2)}.\\\\\n\\ea$$\nCoassociativity follows already from the coassociativity of $C$ via equality\n$$\\sum_{(c),(c_{(1)})} 1_A \\otimes c_{(11)} \\otimes 1_A \\otimes c_{(12)} \\otimes 1_A \\otimes c_{(2)} = \\sum_{(c),(c_{(2)})} 1_A \\otimes c_{(1)} \\otimes 1_A \\otimes c_{(21)} \\otimes 1_A \\otimes c_{(22)}.$$\nCounitality follows as\n$$(\\eps_A \\otimes id_{C'})(1_A \\otimes c) = \\sum_{(c)} \\eps_A(1_A \\otimes c_{(1)}) \\otimes 1_A \\otimes c_{(2)} = \\sum_{(c)} 1_A \\otimes\\underbrace{ \\eps(c_{(1)}) c_{(2)}}_{c} = 1_A \\otimes c\\ \\trm{and}$$\n$$(id_{C'} \\otimes \\eps_A)(1_A \\otimes c) = \\sum_{(c)} 1_A \\otimes c_{(1)} \\otimes \\eps_A(1_A \\otimes c_{(2)}) = \\sum_{(c)} 1_A \\otimes\\underbrace{c_{(1)} \\eps(c_{(2)})}_{c} = 1_A \\otimes c$$\nimplies $(\\Delta_A \\otimes id) \\Delta_A = id_{C'} = (id \\otimes \\Delta_A)\\Delta_A$.\n\\subsubsection{Cofree and cofree cocommutative coalgebras}\nReturning to algebras and coalgebra, the question of the coalgebra structure for a general algebra $A$ hasn't been fully answered. This section is taken from \\cite{Sweed}. Although, \\cite{barr} gives a definition of cofree coalgebras for general rings we are following \\cite{Sweed}: let $R$ be a field. Firstly, we need\n\\begin{defi}\nLet $R$ be as above and $A$ an $R$-algebra. We define the sub $A^0$ to be\n$$A^0 = \\left<g \\in A^\\ast : \\exists I \\subseteq \\ker g, A/I \\simeq \\bigcup_{i\\leq n} B_i,\\ B_i \\simeq R^{n_i}, n_i \\in \\nz\\right>.$$\n\\index{Symbol}{$A^o$}\n\\end{defi}\nIn words, $A^0$ is a subspace generated by all dual elements containing a cofinite ideal in $A$.\n\\begin{lemm}\nLet $A, B$ be $R$-algebras and $f \\in \\mathrm{Hom}_{R-\\mathrm{alg}}(A,B) =: \\mathrm{Alg}_R(A,B)$ - we have:\n\\bn\n\\item $f^\\ast: B^\\ast \\longrightarrow  A^\\ast$ with $f^\\ast = [\\beta \\longmapsto \\beta \\circ f]$ has $f^\\ast(B^\\ast) \\subset A^\\ast$,\n\\item Regarding $A^\\ast \\otimes B^\\ast \\subset (A \\otimes B)^\\ast$, we have $A^o \\otimes B^o = (A \\otimes B)^o$,\n\\item $\\mu^\\ast : A^\\ast \\longrightarrow (A \\otimes A)^\\ast$ has $\\mathrm{im} \\mu^\\ast\\mid_{A^o} \\subset A^o \\otimes A^o$.\n\\en\n\\end{lemm}\n\\bws See \\cite{Sweed}, pg. 110 - 113.\n\\begin{prop}\nFor $A$ as above, $(A^o, \\Delta, \\varepsilon)$ is a $R$-coalgebra for \n$$\\varepsilon : A^o \\longrightarrow R,\\ \\alpha \\longmapsto \\alpha(1_A)\\ \\mathrm{and}\\ \\Delta := \\mu^\\ast\\mid_{A^o}.$$\n\\end{prop}\n\\bws See \\cite{Sweed}, pg. 113 - 114.\n\n\\bmk This vector space has some interesting properties which are\n\\bn\n\\item If $A$ and $B$ are $R$-algebras and $g \\in \\mathrm{Alg}_R(A,B)$ then last prop shows that $g^\\ast \\mid_{B^o} =: g^o$ is an coalgebra homomorphism.\n\\item $A^o$ is the maximal coalgebra in $A^\\ast$ being induced by $\\mu^{-1}(A^\\ast \\otimes A^\\ast)$.\n\\item It may happen that $A^o = \\{0\\}$ for example for infinite degree field extension.\n\\item $A^\\ast$ has a left $A$-module structure defined via:\n$$\\rho_l : A \\otimes A^\\ast \\longrightarrow A^\\ast,\\ a \\otimes \\alpha \\longmapsto \\alpha \\_ \\cdot a := [b \\longmapsto \\alpha(b a)].$$\nFurthermore, via\n$$\\rho_r : A^\\ast \\otimes A \\longrightarrow A^\\ast,\\ \\alpha \\otimes a \\longmapsto \\alpha a \\cdot \\_ := [b \\longmapsto \\alpha(a b)],$$\nmaking $A^\\ast$ into an two-sided $A$-module.\n\\item for a coalgebra $C$ its bidual $C^{\\ast \\ast}$ has its image in $C^{\\ast o}$.\n\\en\n\\begin{satz}\nThe functors $^o : \\mathrm{Alg}_R \\longrightarrow \\mathrm{CoAlg}_R$ and $^* : \\mathrm{CoAlg}_R \\longrightarrow \\mathrm{Alg}_R$ are adjoint to one another. There is a one-to-one correspondence between the sets\n$$\\mathrm{Alg}_R(A,C^\\ast) \\ \\mathrm{and}\\ \\mathrm{CoAlg}_R(C, A^o)$$\n\\end{satz}\nGiven two spaces $V$ and $W$ and $\\iota : V^\\ast \\otimes W^\\ast \\longrightarrow (V \\otimes W)^\\ast$ as identification. Then $V^\\ast \\otimes W^\\ast$ is dense in $(V \\otimes W)^\\ast$ if $u_1 \\in V \\otimes W\\backslash\\{0\\}$ there is an $u_2 \\in V^\\ast \\otimes W^\\ast$ such that\n$$u_2(u_1) \\neq 0.$$\n\\begin{defi}\nAn algebra $A$ is called proper if and only if $A^0$ is dense in $A^\\ast$.\n\\end{defi}\n\\begin{lemm}\n$A^o$ dense if and only if for each non-zero $a \\in A$ there is a cofinite ideal excluding $a$.\n\\end{lemm}\n\\begin{satz}\nIf $A$ is a commutative finitely generated algebra then $A^o$ is dense in $A^\\ast$.\n\\end{satz}\n\\bsp We consider $A = R[x]$ and denote with $ev_a : A \\longrightarrow R, x^i \\longmapsto a^i$, for all $a \\in R$ then\n$$A^o = \\left<\\chi_i : \\chi_i(x^j) = \\delta_{i,j}\\right> + \\left<ev_a : a \\in R \\right>$$\nas each $I_i = \\left<x^{i+1}\\right> \\subset \\ker\\chi_i$ has a quotient algebra free of rank $i + 1$ and by definition, $\\ker ev_a \\supseteq \\left<x - a\\right>$. We get that $\\chi_i(1_A) = \\delta_{0,i}$ and $ev_a(1_A) = 1_R$ and for $p = \\sum p_i x^i, q = \\sum q_i x^i$:\n$$\\bao{rclcl}\n\\Delta(\\chi_i) &=& \\chi_i \\circ \\mu_A &=& [p \\otimes q \\longmapsto \\sum_{k+l=i} p_k q_l]\\\\\n&=& \\sum_{k+l=i} \\chi_k \\otimes \\chi_l&&\\\\\n&&&&\\\\\n\\Delta(ev_a) &=& ev_a \\circ \\mu_A &=& \\left[p \\otimes q \\longmapsto ev_a(p q)\\right]\\\\\n&=& ev_a \\otimes ev_a\\\\\n\\ea$$\nThus, $\\chi_0$ and $ev_a$ are group-like and $\\chi_1$ is primitive.\n%Clearly, for any arbitrary bialgebra $H$, its dual $H^\\ast$ is usually not an bialgebra. However, $H^o$ is indeed.\n\\begin{defi}[Cofree]\nIf $V$ is a vector space, a pair $(C, \\pi)$ with $C$ a coalgebra and $\\pi \\in \\mathrm{Hom}(C,V)$ is called cofree coalgebra on $V$ if for any coalgebra $D$ and $f \\in \\mathrm{Hom}(D,V)$ there is a unique $F \\in \\mathrm{CoAlg}(D,C)$, such that \n$$\\xymatrix{\nD \\ar[dr]_f\\ar[r]^F & C \\ar[d]^\\pi\\\\\n& V\\\\\n}$$\n\\index{Index}{coalgebra!cofree}\n\\end{defi}\n\\begin{satz}\nFor any vector space $V$ the cofree coalgebra always exists.\n\\end{satz}\n\\bmk $T(V^\\ast)^o$ is the cofree coalgebra for $V^{\\ast\\ast}$ for any vector space $V$.\n\\begin{lemm}\nLet $(C,\\pi)$ be a cofree coalgebra on some space $X$ and $Y \\subset X$ be a subspace. Let $D = \\sum E$ with\n$E$ subcoalgebras of $C$ such that $\\pi(E) \\subset Y$. Then $\\rho := \\pi\\mid_D$ maps $D$ to $Y$ and $(D, \\rho)$ is the cofree coalgebra on $Y$.\n\\end{lemm}\nNow, we see that the cofree coalgebra for any vectors space $V$ can be recovered from the cofree coalgebra $(T(V^\\ast)^o, \\pi)$ on $V^{\\ast\\ast}$ where $\\pi$ is defined via the composition map:\n$$\\pi : T(V^\\ast)^o \\longrightarrow T(V^\\ast)^\\ast \\longrightarrow V^{\\ast\\ast}.$$\nThe first arrow is simply the inclusion whereas the second is the dual of the embedding of $V^\\ast$ in $T(V^ \\ast)$.\n\\begin{defi}[Cofree cocommutative coalgebra]\nLet $V$ be a vector space and $C$ a cocommutative coalgebra. For $\\pi \\in \\trm{Hom}(C,V)$ we call $(C, \\pi)$ a cofree cocommutative algebra if for all cocommutative coalgebras $D$ and $f \\in \\trm{Hom}(D,V)$ there is a \tunique $F \\in \\trm{CoAlg}(C,D)$ such that\n$$\\xymatrix{\nC \\ar[r]^F \\ar[rd]_\\pi & D\\ar[d]^f\\\\\n&V\\\\\n}$$\ncommutes.\n\\index{Symbol}{$T(V^\\ast)^o$}\n\\index{Index}{coalgebra!cofree!cocommutative}\n\\end{defi}\n\\subsection{Bialgebras}\nBoth, the definition of algebras and coalgebras, with certain compatibility conditions, define a bialgebra.\n\\begin{defi}\\label{defi11}\nA bialgebra is a module $B$, with the structure of an algebra $(B,\\mu,\\eta)$ and of a coalgebra $(B,\\Delta,\\eps)$ with the following compatibility conditions expressed in commuting diagrams:\n$$\\bao{cc}\n\\xymatrix{\n B \\otimes B \\ar[r]^\\mu \\ar[d]_{\\Delta \\otimes \\Delta} & B \\ar[r]^\\Delta & B \\otimes B\\\\\n B \\otimes B \\otimes B \\otimes B \\ar[rr]_{id_B \\otimes \\tau \\otimes id_B}&& B \\otimes B \\otimes B \\otimes B \\ar[u]_{\\mu \\otimes \\mu}\\\\\n }\n %\\item for multiplication $\\nabla$ and counit $\\eps$\n &\\xymatrix{\n B \\otimes B \\ar[rd]_{\\eps \\otimes \\eps} \\ar[rr]^\\mu & & B\\ar[ld]^\\eps\\\\\n &R&\n }\\\\\n \\trm{co/multiplication} & \\trm{multiplication~and~counit}\\\\\n &\\\\\n %\\item for comultiplication $\\Delta$ and unit $\\eta$:\n \\xymatrix{\n &R \\ar[ld]_\\eta \\ar[rd]^{\\eta \\otimes \\eta}&\\\\\n  B \\ar[rr]_\\Delta&&B \\otimes B \\\\ \n }\n %\\item and for co-/unit:\n &\\xymatrix{\n R \\ar[rr]^{id}\\ar[rd]^\\eta && R \\\\\n &B\\ar[ru]^\\eps&\n }\\\\\n \\trm{comultiplication~and~unit} & \\trm{co/unit}\\\\\n \\ea$$\n where $\\tau : B \\otimes B \\rightarrow B \\otimes B$, $x \\otimes y \\mapsto y\\otimes x$ is the flip map.\n\\index{Index}{bialgebra}\n\\end{defi}\n\\bmk The commuting diagrams can be rephrased as\n\\bn\n\\item $\\eps$ and $\\Delta$ are homomorphisms of algebras,\n\\item $\\eta$ and $\\mu$ are homomorphisms of coalgebras.\n\\en\n\\begin{defi}\\label{defi12}\nLet $B$ be a bialgebra. Group-like and $(g,h)$-skew primitive elements are defined via their coproducts as in def. \\ref{coalg_type}, pt. \\ref{coalg_skew} or \\ref{coalg_group}. If $B$ has a unit $1_B$ we call an element primitive if it is a $(1_B,1_B)$-skew primitive element, i.e. \n$$\\Delta(x) = x \\otimes 1_B + 1_B \\otimes x.$$\n\\index{Index}{element!primitive}\n\\end{defi}\n\\bmk Primitive elements and Lie algebras are intimitely connected what we are going to show in a short instance.\n%\\bmk Firstly, we remark that the definition only depends on the coalgebra structure. In deed, \\cite{Sweed} only uses the skew-primitive and group-like definition in the context of coalgebras.\\\\\n%\\indent Secondly, the different types of primitive elements are interconnected. A primitive element is simply a $(1_B,1_B)$-primitive and $h$-skew primitives are $(1_B,h)$ skew-primitive. Recalling our definition of Ore-extensions $A[X,\\alpha,\\delta]$, we see that an $\\alpha$-derivation $\\delta$ is simply an $(id,\\alpha)$-skew primitive element in $\\trm{End}_R(A)$. To be precise, $\\delta$ and $\\alpha$ generate a bialgebra with $\\alpha$ group-like and $\\delta$ $(id,\\alpha)$ skew-primitive.\n\\bsp As before we introduce two famous examples.\n\\bn\n\\item Coming back to our tensor algebra over some module free of rank $n$, $T R^n$, it has the the structure of a primitive bialgebra given by $x \\in R^n$ being primitive and $\\eps(x) = 0$ for all $x \\in T R^n\\bsl R$ and $1_{TR^n} \\longmapsto 1_R$. This gives us a coalgebra, with algebra structure maps $\\eta : R \\longrightarrow TR^n$, $1_R \\longmapsto 1_{TR^n}$ and the given multiplication.\n\\item The second example is the group algebra $R.G = R[G]$, for some group $G$. We have a comultiplication $\\Delta(g) = g \\otimes g$ and a counit $\\eps(g) = 1$ for all $g \\in G$. The multiplication is obvious and the unit is $1_R \\longmapsto 1_{R.G}$.\n\\en\n%\\subsubsection{Primitives form a Lie algebra}\n\\begin{prop}\\label{prop08}\nLet $(B,\\mu,\\eta,\\Delta,\\eps)$ be a coassociative bialgebra. The module of all primitive elements of $B$ defines a Lie algebra, denoted $\\mathcal{P}(B)$. The module of all group-like elements generates a sub bialgebra of $B$, denoted $\\mathcal{G}(B)$.\n\\end{prop}\n\\bws Firstly, recall $\\Delta$ is an algebra homomorphism\n$$\\bao{rcl}\n[x,y] &=& x y - y x\\\\\n &\\RA&\\\\\n \\Delta([x,y]) &=& \\Delta(x y) - \\Delta(y x)\\\\ &=& \\Delta(x) \\Delta(y) - \\Delta(y) \\Delta(x)\\\\\n&=&(1 \\otimes x + x \\otimes 1)(1 \\otimes y + y \\otimes 1) \\\\\n&& - (1 \\otimes y + y \\otimes 1)(1 \\otimes x + x \\otimes 1)\\\\\n &=& 1 \\otimes x y + y \\otimes x + x \\otimes y + x y \\otimes 1\\\\\n&& - 1 \\otimes y x - x \\otimes y - y \\otimes x - y x \\otimes 1\\\\\n&=& 1 \\otimes [x,y] + [x,y] \\otimes 1\\\\\n\\ea$$\nSecondly, clearly:\n$$\\sum_i \\lambda_i g_i \\in \\mathcal{G}(B)\\ \\stackrel{\\Delta}{\\longmapsto} \\ \\sum_i \\lambda_i \\underbrace{g_i \\otimes g_i}_{\\in \\Delta(\\mathcal{G}(B))},\\ \\forall \\lambda_i \\in R,$$\ni.e. the coproducts of linear combination of group-likes are simply its linear combination of its coproducts. Hence, we only need to show that the product of group-like elements is again group-like. But this is clear from coassociativity and the fact that both coproduct and counit are algebra homomorphisms.\n\\begin{defi}\nA bialgebra $B$ is called pointed irreducible, if its coalgebra $(B, \\Delta, \\eps)$ is pointed and irreducible. A cocommutative pointed irreducible bialgebra $B$ is called of Birkhoff-Witt type if it its coalgebra $(B,\\Delta_B\\eps_B)$ is isomorphic to a cocommutative cofree pointed irreducible coalgebra.\n\\index{Index}{bialgebra!pointed irreducible}\n\\index{Index}{bialgebra!of Birkhoff-Witt type}\n\\end{defi}\n\\bmk In \\cite{Take} it is said that any irreducible cocommutative bialgebra over a field of characteristic zero is Birkhoff-Witt. In positive characteristic $p$, there is a canonical $R^{1/p}$-linear map:\n$$\\mathcal{Y} : B \\longrightarrow R^{1/p} \\otimes_R B,$$\nthen $B$ is BW if and only if $\\mathcal{Y}$ is surjective. This is the case if $C$ is spanned by divided by power sequences or alternatively, if for\n$$T(C_+) = \\bigoplus_{n \\geq 0} C_+^{\\otimes n},\\ C_+ = \\ker \\eps$$\n$\\trm{Hom}(T(C_+), A)$ is a divided power algebra for all algebras $A$. We define:\n\\begin{defi}\nLet $A$ be an algebra and $I$ a (two-sided) ideal in $A$ with a family of maps $\\gamma_i : I \\longrightarrow A$ indexed by $\\nz_0$ such that\n\\bn\n\\item $\\gamma_1(x) = x$ and $\\gamma_0(x) = 1$ for all $x \\in I$,\n\\item $\\gamma_n(x) \\gamma_m(x) = \\left(\\begin{array}{c}m + n\\\\m\\\\\\end{array}\\right) \\gamma_{m + n} (x)$ for all $x \\in I$ and $m, n \\geq 0$,\n\\item $\\gamma_n(a x) = a^n \\gamma_n(x)$ for all $x \\in I$ and $a \\in A$,\n\\item $\\gamma_n(x + y) = \\sum_{i = 0}^n \\gamma_i(x) \\gamma_{n - i}(y)$ for all $x, y \\in I$ and $n \\geq 0$,\n\\item $\\gamma_n(\\gamma_m)) = \\frac{(m n)!}{n! (m!)^n} \\gamma_{n m}(x)$ for all $x \\in I$ and $n, m \\geq 0$,\n\\en\nthen we call the triple $(A, I, \\gamma)$ a divided power algebra. Here, $\\gamma = (\\gamma_i)_{i \\in \\nz_0}$.\n\\index{Index}{algebra!pointed power sequences, of}\n\\end{defi}\n\\bsp \\label{exp_bialg} To illustrate our last definitions, we give some examples.\n\\bn\n\\item \\label{exp_bialg01} Let $\\mathfrak{g}$ be a Lie algebra and $U(\\mathfrak{g})$ be its universal enveloping algebra. Since the only group-like elements are all in $R.1$ we have that the universal enveloping algebra is our first example of a pointed irreducible bialgebra (with multiplication and unit as given and\n$$\\Delta = [x \\longmapsto 1 \\otimes x + x \\otimes 1],\\ \\eps(x) = 0\\ \\forall x \\in \\mathfrak{g}).$$\nIn conjunction with prop. \\ref{prop08}, we have a complete picture concerning Lie algebras or more precisely their universal envelopping algebras and primitive elements: if $A$ is a unital associative algebra and $A \\simeq_{R-\\trm{algs}} U(\\mathfrak{g})$ for some Lie algebra $\\mathfrak{g}$ then $A$ has a coalgebra structure via primitive generators $x \\in \\mathfrak{g}$. On the other hand, if $B$ is some bialgebra then its bialgebra of primitive elements is isomorphic to some universal envelopping algebra for a Lie algebra.\n%In \\cite{Heid13} bialgebras of this type, are refered to as pointed irreducible of Birkhoff-Witt type.\n\\item \\label{exp_bialg02} On the other hand, for some group $G$, the group algebra $R.G$ with its (co-) multiplication and (co-) unit is a group-like bialgebra.\\\\\n\\item \\label{exp_bialg03} Examples of skew-primitive bialgebras are for example $U_q(\\mathfrak{sl}_2(\\cz))$ for $q \\in \\cz^\\times \\bsl \\{1\\}$, where some of the relations among its generators can be described as actions of skew-primitive elements of $\\trm{End}_\\cz(U(\\mathfrak{sl}_2(\\cz)))$.\\\\\n%\\indent Two examples, where we have that the dual of an $R$-algebra are $R$-coalgebras:\n\\en\n\\subsubsection{Morphisms of bialgebras and bialgebra ideals}\n\\begin{defi}\nLet $(B,\\mu,\\eta,\\Delta,\\eps)$ be a $R$-bialgebra.\n\\bn\n\\item An $R$-bimodule is an $R$-module $M$ which is a $(B,\\mu,\\eta)$-module and a $(B,\\Delta,\\eps)$-comodule.\n\\item A sub- bialgebra $B'$ is an $R$-submodule such that the restrictions of the structure maps yields a bialgebra.\n\\item A bialgebra ideal is an ideal of the associative algebra $(B,\\mu,\\eta)$ and a coideal of the coassociative coalgebra $(B,\\Delta,\\eps)$.\n\\en\n\\index{Index}{bimodule}\n\\index{Index}{bialgebra!sub-bialgebra}\n\\index{Index}{bialgebra!ideal of}\n\\end{defi}\n\\bmk Let $g, h \\in B$ be group-like. First, we want to show that a $(g,h)$ skew-primitive element $x \\in B$ is in a proper coideal. We define $S := \\{x \\in B : \\exists! (g, h) \\in B^2, \\Delta(x) = g \\otimes x + x \\otimes h\\}$ and let\n$$I := B.S.B,$$\ni.e. the two-sided ideal generated by $S$. We recall that $(\\eps\\otimes id)\\Delta = id_B = (id\\otimes \\eps)\\Delta$ and $\\eps(g) = 1 = \\eps(h)$. Therefore,\n$$(id\\otimes \\eps)\\Delta(x) = g \\otimes \\eps(x) + x \\otimes \\eps(h) = x = \\eps(g) \\otimes x + \\eps(x) \\otimes h = (\\eps \\otimes id) \\circ \\Delta(x) \\LRA x \\in \\ker \\eps\\ \\forall x \\in S.$$\nThus, $S \\subset \\ker \\eps$. Furthermore, for any product $a x b$, with $a, b \\in B$, $x \\in S$ we get:\n$$\\Delta(a x b) = \\Delta(a) (g \\otimes x + x \\otimes h) \\Delta(b) = \\sum_{(a),(b)} (\\underbrace{a_{(1)} g b_{(1)} \\otimes a_{(2)} x b_{(2)}}_{\\in B \\otimes I} + \\underbrace{a_{(1)} x b_{(1)} \\otimes a_{(2)} h b_{(2)}}_{\\in I \\otimes B})$$\n%if $x_{i_1} \\ldots x_{i_n} \\in B, x_{i_j} \\in \\mathcal{P}(B)$ then\n%$$\\Delta (x_{i_1} \\ldots x_{i_n}) = \\Delta(x_{i_1}) \\ldots \\Delta(x_{i_n}) = (1 \\otimes x_{i_1} + x_{i_1} + x_{i_1} \\otimes 1) \\ldots (1 \\otimes x_{i_n} + x_{i_n} \\otimes 1)$$\n%and \n%$$\\bao{rcl}\n% \\Delta(x_{i_1}) \\ldots \\Delta(x_{i_n}) &=& \\Delta(x_{i_1} \\ldots x_{i_{n-1}}) (1 \\otimes x_{i_n}) + (x_{i_n} \\otimes 1) \\Delta(x_{i_1} \\ldots x_{i_{n-1}})\\\\\n%\\ea$$\nIn addition, $\\eps(x y) = \\eps(x) \\eps(y)$ which shows $I$ is a coideal and, by definition, an ideal in $B$. Therefore, the canonical projection\n$$\\pi : B \\longrightarrow B/I,\\ x \\longmapsto x + I$$\nis a bialgebra morphism.\\\\\n\\indent Subsequently, all primitive elements, i.e. $(1,1)$ skew-primitives, also define a bialgebra ideal in $B$.\n\\begin{lemm}\nLet $(B,\\mu,\\eta,\\Delta,\\eps)$ be an $R$-bialgebra und $I \\subset B$ be an $R$-submodule. The following statements are equivalent:\n\\bn\n\\item\\label{biideal} $I$ is a two-sided bialgebra ideal.\n\\item\\label{bimodule} $I$ is two-sided $B$-sub bimodule of $\\ker \\eps$.\n\\en\n\\end{lemm}\n\\bws If $I$ is a two-sided biideal, then $I$ is a two-sided $(B,\\mu,\\eta)$-submodule of $B$. On the other hand, $I \\subset \\ker \\eps$ and a two-sided $(B,\\Delta,\\eps)$-sub-comodule of $B$. Thus, we have \\ref{biideal} $\\RA$ \\ref{bimodule}. The converse implication follows immediately.\n\\begin{lemm}\\label{GroupLikeHopfIdeal}\nLet $2 \\nmid \\trm{char}(R)$ as well as $\\frac{1}{2} \\in R$ and $B$ an $R$-bialgebra. For two group-like elements $g,h \\in \\mathcal{G}(B)$ the difference $g - h$ generates a biideal, the set $I := B.(g - h).B$.\n\\end{lemm}\n\\bws Simple computation shows:\n$$\\bao{rcl}\n\\Delta(g - h) &=& \\underbrace{\\frac{1}{2}(g + h) \\otimes (g - h) + \\frac{1}{2}(g - h) \\otimes (g + h)}_{B \\otimes I + I \\otimes B}\\\\\n&&\\\\\n\\eps(g - h) &=& 0\\\\\n\\ea$$\nThe biideal property is a consequence of the fact that $\\eps$ and $\\Delta$ are algebra homomorphisms, as well as $\\mu$ and $\\eta$ being coalgebra homomorphisms. Furthermore, image of the canonical projection $\\pi : B \\longrightarrow B/I$ is a pointed-irreducible bialgebra (note, all group-likes are equivalent to $1_{B/I}$).\n\\paragraph{Morphisms}\nLet $(B,\\mu_B,\\eta_B,\\Delta_B,\\eps_B)$, $(C,\\mu_C,\\eta_C,\\Delta_C,\\eps_C)$ be to two $R$-bialgebras.\n\\begin{defi}\nA morphism of $R$-modules $f: B \\longrightarrow C$ is a bialgebra morphism if and only if it is morphism of $R$-algebras and $R$-coalgebras.\n\\index{Index}{bialgebra!morphism of}\n\\end{defi}\nEquivalently, we could have demanded the any $R$-module morphism commuting with the structure maps defining each bialgebra would also yield the above definition.\n\\subsubsection{Module algebras}\nThe definition of an Ore extension can be easily extended as follows. Let $(A,\\mu_A,\\eta_A)$ be an $R$-algebra and $(B,\\mu_B,\\eta_B,\\Delta_B,\\eps_B)$ be an $R$-bialgebra and in addition let $A$ be a left $B$-module (equivalently, there is an algebra homomorphism $\\rho : B \\longrightarrow \\trm{End}(A)$, i.e. a $B$-representation on $A$)\n\\begin{defi}\\label{defi09a}\nWe call $A$ a $B$-module algebra, if there is a $\\Psi \\in \\trm{Hom}(B \\otimes A, A)$ with\n$$\\Psi : B \\otimes A \\longrightarrow A,\\ b \\otimes a \\longmapsto \\rho(b)(a)$$\nsuch that\n\\bn\n\\item $\\Psi(b \\otimes a a') = \\sum_{(b)} \\mu_A\\left(\\rho(b_{(1)})(a) \\otimes \\rho(b_{(2)})(a')\\right)$, for all $a, a' \\in A$ and $b \\in B$,\nwhere $\\Delta_B(b) = \\sum_{(b)} b_{(1)} \\otimes b_{(2)}$,\n\\item $\\Psi(b \\otimes 1_A) = \\eps_B(b) 1_A$ for all $b \\in B$.\n\\en\n\\index{Index}{module algebra}\n\\end{defi}\n\\bmk Firstly, in Heiderich 2010 and Heiderich 2011 a module algebra is defined for some coalgebra $(C,\\Delta,\\eps)$. Indeed, the module algebra structure solely depends on the coalgebra structure maps. But, most of the examples we will encounter are bialgebras. Secondly, the above definition can be rephrased in the context of commuting diagrams, the first is\n$$\\xymatrix{\nB \\otimes A \\otimes A \\ar[d]_{\\Delta_B\\otimes id_{A\\otimes A}}\\ar[rrr]^{id_B\\otimes \\mu_A}&&& B\\otimes A\\ar[dd]^{\\Psi_A}\\\\\nB \\otimes B \\otimes A \\otimes A \\ar[d]_{id_B \\otimes \\tau_{B\\otimes A} \\otimes id_A}&&&\\\\\nB\\otimes A \\otimes B \\otimes A\\ar[rr]_{\\Psi_A\\otimes \\Psi_A}&&A \\otimes A\\ar[r]_{\\mu_A}&A,\\\\\n}$$\nwhere $\\tau_{B\\otimes A} : B \\otimes A \\longrightarrow A \\otimes B$ is the flip isomorphism. The second is simply\n$$\\xymatrix{\nB \\simeq B \\otimes R \\ar[rr]^{id_B \\otimes \\eta_A}\\ar[d]_{id_B\\otimes \\eta_A}&&B \\otimes A\\ar[d]^{\\eps_B \\otimes id_A}\\\\\nB \\otimes A \\ar[rr]_{\\Psi_A}&& A \\simeq R \\otimes A\\\\\n}$$\n\\bsp Recalling example \\ref{partial_diff_exp02} on pg. \\pageref{partial_diff_alg_examp}, $k[x,x^{-1}]$ and $\\mathfrak{sl}_2(k)$ as derivation Lie algebra. We define $B = U(\\mathfrak{sl}_2(k))$ with multiplication and unit as given, and comultiplication and counit given via the primitive generators $x \\in \\mathfrak{sl}_2(k)$ (see also example \\ref{exp_bialg}. \\ref{exp_bialg01} on pg. \\pageref{exp_bialg01}). This makes $A := k[x,x^{-1}]$ into a $U(\\mathfrak{sl}_2(k))$-module algebra, if we choose\n$$\\bao{rrcl}\n\\Psi : & U(\\mathfrak{sl}_2(k)) \\otimes_k k[x,x^{-1}] &\\longrightarrow& k[x,x^{-1}]\\\\\n&&&\\\\\n& \\partial_{i_1} \\ldots \\partial_{i_n} \\otimes x^j & \\longmapsto & \\partial_{i_1} \\circ \\ldots \\circ \\partial_{i_n}(x^j)\\\\\n\\ea$$\nas structure map, where $\\partial_{i_j} \\in \\{\\partial_{\\pm 1}, [\\partial_1,\\partial_{-1}]\\}$. Clearly, $\\Psi(b \\otimes 1) = \\eps(b)\\cdot 1 = \\begin{cases}0 & \\deg b \\geq 1\\\\b_0.1 & \\trm{else}\\\\\\end{cases}$ for $b = b_0 + b_1 \\partial_1 + b_{-1} \\partial_{-1} + b_{1,-1} [\\partial_1,\\partial_{-1}] + \\ldots$, as demanded. Moreover, a product $y z \\in k[x,x^{-1}]$ gets mapped to:\n$$\\partial_{i} \\otimes y z \\longmapsto \\mu \\circ (id_A \\otimes \\partial_i + \\partial_i \\otimes id_A)(y \\otimes z) = \\mu(\\Psi \\otimes \\Psi)(id_B \\otimes \\tau_{B \\otimes A} \\otimes id_A)(\\Delta \\otimes id_{A^{\\otimes 2}})(\\partial_i \\otimes y \\otimes z),$$\nwith $\\partial_i$ as above. Recalling that $\\Delta$ is an $k$-algebra homomorphism, we see that this applies to all weight spaces $k.\\partial_{i_1} \\ldots \\partial_{i_n}$ of degree $n$.\n\\begin{defi}\nLet $(A,\\Psi_A)$ be a $B$-module algebra. \n\\bn\n\\item The subset\n$$A^\\Psi := \\{a \\in A : \\Psi_A(b \\otimes a) = \\eps_B(b) a,\\ \\forall b \\in B\\}$$\nis called the constant $B$-module (sub)algebra.\n\\item if $A' \\subset A$ is a subalgebra, and $\\trm{im}\\Psi\\mid_{B\\otimes A'} \\subset A'$, then $(A', \\Psi_{A'} := \\Psi\\mid_{B\\otimes A'})$ is also a $B$-module algebra.\n\\item An ideal $I \\subset A$ is called $B$-stable, if $\\Psi_A(b \\otimes a) \\in I$ for all $a \\in I$ and $b \\in B$.\n\\item Let $(A',\\Psi_{A'})$ be an other $B$-module algebra. A morphism of algebras $\\varphi : A \\longrightarrow A'$ is called a morphism of $B$-module algebras if\n$$\\xymatrix{\nB \\otimes A \\ar[r]^{id_B\\otimes \\varphi}\\ar[d]_{\\Psi_A} & B \\otimes A'\\ar[d]^{\\Psi_{A'}}\\\\\nA \\ar[r]_{\\varphi} & A'\\\\\n}$$\ncommutes.\n\\en\n\\index{Index}{module algebra!constant}\n\\index{Index}{module algebra!subalgebra}\n\\index{Index}{module algebra!$B$-stable ideals}\n\\index{Index}{module algebra!homomorphisms of}\n\\end{defi}\nRecall that for two unital algebras $(A,\\mu_A,\\eta_A)$, $(B,\\mu_B,\\eta_B)$ the tensor product $A \\otimes B$ has an unital algebra structure via:\n$$\\mu_{A\\otimes B} := (\\mu_A \\otimes \\mu_{B}) \\circ (id_A \\otimes \\tau_{B \\otimes A} id_B),\\ \\eta_{A \\otimes B} = \\eta_A \\otimes \\eta_B.$$\n\\begin{lemm}\\label{d_mod_tens_prod}\nLet $D$ be a cocommutative bialgebra, $(A,\\Psi_A)$ and $(B,\\Psi_B)$ be two $D$-module algebras. Then the algebra $A \\otimes B$ has a $D$-module algebra structure via:\n$$\\Psi_{A\\otimes B} := \\left(\\Psi_A \\otimes \\Psi_B\\right) \\circ (id_D \\otimes \\tau_{D \\otimes A} \\otimes id_B) \\circ (\\Delta_D \\otimes id_{A \\otimes B}).$$\n\\end{lemm}\n\\bws Let $d \\in D$ and $a \\otimes b, a'\\otimes b' \\in A\\otimes B$. We need to show that the two commutative diagrams in the last remark hold.\n\\bn\n\\item Firstly, let $f$ denote the morphism of the lower path of the first diagram and let $(\\Delta \\otimes \\Delta) \\circ \\Delta(d) := \\sum_{(d)} \\Delta(d_{(1)}) \\otimes \\Delta(d_{(2)}) = \\sum_{(d_{(1)}),(d_{(2)})} d_{(11)} \\otimes d_{(12)} \\otimes d_{(21)} \\otimes d_{(22)}$, then\n{\\scriptsize\n$$\\bao{rcl}\n\\Psi_{A\\otimes B}(d \\otimes (a a' \\otimes b b')) &=& \\sum_{(d)} \\Psi_A(d_{(1)} \\otimes a a') \\otimes \\Psi_B(d_{(2)} \\otimes b b')\\\\\n&&\\\\\n&=& \\sum_{(d_{(1)}),(d_{(2)})} (\\Psi_A(d_{(11)} \\otimes a)\\Psi_A(d_{(12)}\\otimes a')) \\otimes (\\Psi_AB(d_{(21)} \\otimes b)\\Psi_B(d_{(22)} \\otimes b'))\\\\\n&&\\\\\nf(d \\otimes (a \\otimes b) \\otimes (a'\\otimes b')) &=& \\sum_{(d)}\\mu_{A\\otimes B} \\circ (\\Psi_{A\\otimes B} \\otimes \\Psi_{A\\otimes B})(d_{(1)} \\otimes (a \\otimes b) \\otimes d_{(2)} \\otimes (a' \\otimes b'))\\\\\n&&\\\\\n&=& \\sum_{(d)} \\mu_{A\\otimes B} (\\Psi_{A\\otimes B}(d_{(1)} \\otimes (a \\otimes b)) \\otimes \\Psi_{A\\otimes B}(d_{(2)} \\otimes (a' \\otimes b')))\\\\\n&&\\\\\n&=& \\sum_{(d_{(1)}),(d_{(2)})} \\mu_{A\\otimes B}\\left(\\Psi_A(d_{(11)} \\otimes a) \\otimes \\Psi_B(d_{(12)} \\otimes b) \\otimes \\Psi_A(d_{(21)} \\otimes a') \\otimes \\Psi_B(d_{(22)} \\otimes b')\\right)\\\\\n&&\\\\\n&=& \\sum_{(d_{(1)}),(d_{(2)})} (\\Psi_A(d_{(11)} \\otimes a)\\Psi_A(d_{(21)}\\otimes a')) \\otimes (\\Psi_A(d_{(12)} \\otimes b)\\Psi_B(d_{(22)} \\otimes b'))\\\\\n\\ea$$}\nRecall from our definition of coassociative cocommutative (counital) coalgebras:\n$$\n\\bao{cc}\n\\xymatrix{\nD \\ar[r]^{\\Delta}\\ar[d]_{\\Delta}&D^{\\otimes2}\\ar[d]_{id\\otimes \\Delta}\\\\\nD^{\\otimes2} \\ar[r]_{\\Delta\\otimes id}&D^{\\otimes3}\\\\\n} &\n%\\xymatrix{\n%D \\ar[r]^{\\Delta} \\ar[d]_{\\Delta}&D^{\\otimes2}\\ar[d]^{\\eps \\otimes id}\\\\\n%D^{\\otimes2} \\ar[r]_{id \\otimes \\eps} & D\\\\ \n%} &\n\\xymatrix{\nD \\ar[r]^\\Delta\\ar[rd]_{\\Delta}&D^{\\otimes2}\\ar[d]_\\tau\\\\\n&D^{\\otimes2}\\\\}\n\\ea$$\nas well as each tensor module $D^{\\otimes n}$ has a natural (right) comodule structure via $\\rho_n := id^{\\otimes n - 1} \\otimes \\Delta : D^{\\otimes n} \\longrightarrow D^{\\otimes n} \\otimes D$ and similarily a (left) comodule structure $\\wt{\\rho}_n := \\Delta \\otimes id^{\\otimes n - 1} : D^{\\otimes n} \\longrightarrow D \\otimes D^{\\otimes n}$. In particular, we have $\\wt{\\rho}_3 \\rho_2 \\Delta = \\rho_3 \\wt{\\rho}_2 \\Delta = (\\Delta \\otimes \\Delta)\\Delta$ and we may always apply cocommutativity where ever $\\Delta$ appears. Hence, $(id_D \\otimes \\tau \\otimes id) \\circ (\\Delta \\otimes \\Delta) \\circ \\Delta = (\\Delta \\otimes \\Delta) \\circ \\Delta$ (a proper proof in Heiderich 2010, Lem 2.15). Note, cocommutativity is essential in this step (i.e. in general the tensor product of $D$-module algebras is not a $D$-module algebra).\n\\item Computing $\\Psi_{A\\otimes B}(d \\otimes (1_A\\otimes 1_B)) = \\sum_{(d)}\\Psi_A(d_{(1)} \\otimes 1_A) \\otimes \\Psi_B(d_{(2)} \\otimes 1_B) = \\sum_{(d)}\\eps(d_{(1)}) 1_A \\otimes \\eps(d_{(2)}) 1_B = \\eps(d) (1_A \\otimes 1_B)$.\n\\en\n\\subsubsection{Smashed product}\n\\begin{defi}\\label{defi03}\nLet $A$ be an algebra, $G$ some group and $R.G$ the group algebra over $R$. Let $\\rho : G \\longrightarrow \\trm{Aut} A$ define a representation, then\n$$\\bao{rrcl}\nA \\# G := A \\otimes R.G,\\ \\mu_{A\\#G} :& A\\#G \\otimes A\\#G &\\longrightarrow& A\\#G\\\\\n& (m_1 \\otimes g_1) \\otimes (m_2 \\otimes g_2) &\\longmapsto& m_1 \\rho(g_1)(m_2) \\otimes g_1 g_2\\\\\n\\ea$$\ndefines an associative unital algebra, the so called smashed product.\n\\index{Index}{smashed product}\n\\end{defi}\nNote, that $A\\#G$ can be interpreted as the semi-direct product $A \\rtimes_\\rho R.G$ of the two monoids $A$ and $R.G$. We also note, that $A$ has the structure of $R.G$-module algebra, via:\n$$\\Psi : R.G \\otimes A \\longrightarrow A,\\ r g \\otimes a \\longmapsto r g(a),$$\nextending to the $R.G$-module algebra $A\\#G$:\n$$\\Psi' : R.G \\otimes A\\#G \\longrightarrow A\\#G,\\ r g \\otimes a \\otimes 1_G \\longmapsto r g(a) \\otimes g,$$\nsumarized in the following\n\\begin{koro}\\label{koro01}\nLet $A\\#G$ be the smashed product for some algebra $A$ and some group $G$ with $G$-representation $\\rho : G \\longrightarrow \\trm{Aut}_R(A)$.\n\\bn\n\\item $A\\#G$ is isomorphic to \n$$T(A\\otimes R.G \\otimes A)/\\left<1_A \\otimes g \\otimes a - \\rho(g)(a) \\otimes g \\otimes 1_A: a \\in A, g \\in G\\right>,$$\nwhere $T(A \\otimes R.G \\otimes A)$ is the tensor algebra generated by the two-sided $A$-module $A \\otimes R.G \\otimes A$.\n\\item $A\\# G$ is a $R.G$-module algebra given by\n$$\\bao{rrcl}\n\\Psi_{A\\#G} : &R.G \\otimes A\\# G &\\longrightarrow& A\\#G\\\\\n&&&\\\\\n&(r g, a\\# h) &\\longmapsto&r \\rho(g)(a)\\# g h.\\\\\n\\ea$$\n\\en\n\\end{koro}\n\\bws The first statement is an immediate consequence of Prop. \\ref{prop01} - the second statement is an immediate consequence of our definition of module algebras. %More general, we get an extended Ore extension $A[B]$ for any pair of algebras with semi-direct monoidal product $A \\rtimes_\\rho B$, where $\\rho : B \\longrightarrow \\trm{Aut}A$ defines some representation.\n\\bmk The smashed product and its quotient algebras play an important role in deformation of singularities of algebraic varieties, a subfield of algebraic geometry. In addition, we will encounter smashed products in the context of general differential Galois theory.\n\\subsubsection{The internal module algebra}\nGiven a $B$-module algebra $(A,\\Psi)$ we define for $\\trm{Hom}_R(B,A)$ the $B$-module algebra structure\nas follows\n\\begin{lemm}\nThe map $\\Psi_{\\trm{int}} : B \\otimes \\trm{Hom}_R(B,A) \\longrightarrow \\trm{Hom}_R(B,A)$ given\nby\n$$\\Psi_{\\trm{int}} = \\left[b \\otimes f\\longmapsto f \\circ \\mu_B(b \\otimes\\_) := [b' \\longmapsto f \\circ \\mu_B(b \\otimes b')]\\right]$$\nis the proposed structure map.\n\\end{lemm}\n\\bws Again, we want to show that the two commuting diagrams following def. \\ref{defi09a} hold.\n\\bn\n\\item let $b \\in B$ and $f, g \\in \\trm{Hom}_R(B,A)$, then we have for $\\Delta_B(b) = \\sum_{(b)} b_{(1)} \\otimes b_{(2)}$:\n$$\\bao{rcl}\n\\Psi_{\\trm{int}}(b \\otimes \\mu_{\\trm{Hom}_R(B,A)}(f \\otimes g)) &=& \\sum_{(b)} \\mu_A\\circ\\left(f \\circ \\mu_B(b_{(1)} \\otimes\\_) \\otimes g \\circ \\mu_B(b_{(2)} \\otimes\\_)\\right)\\circ\\Delta\\\\\n&&\\\\\n&=& \\left[b' \\longmapsto \\sum_{(b),(b')} f(b_{(1)} b'_{(1)}) g(b_{(2)} b'_{(2)})\\right]\\\\\n&&\\\\\n\\phi(b \\otimes f \\otimes g) &=& \\sum_{(b)}\\mu_{_C\\mathcal{M}(B,A)} \\circ (\\Psi_{\\trm{int}}(b_{(1)} \\otimes f) \\otimes \\Psi_{\\trm{int}}(b_{(2)} \\otimes g))\\\\\n&&\\\\\n&=& \\left[b' \\longmapsto \\sum_{(b),(b')} f(b_{(1)} b'_{(1)}) g(b_{(2)} b'_{(2)})\\right]\\\\\n\\ea$$\nAs multiplication $\\mu_{\\trm{Hom}_R(B,A)}$ is given via convolution $\\mu_A (f \\otimes g) \\Delta$ we showed the first diagram. Here, we use $\\phi = \\mu_A \\circ (\\Psi_{\\trm{int}} \\otimes \\Psi_{\\trm{int}}) \\circ (id_B \\otimes \\tau_{B \\otimes \\trm{Hom}_R(B,A)} \\otimes id_{\\trm{Hom}_R(B,A)}) \\circ (\\Delta \\otimes id_{\\trm{Hom}_R(B,A)^{\\otimes2}})$.\n\\item $1_{\\trm{Hom}_R(B,A)} = \\eta_A \\eps_B$ then for all $b \\in B$:\n$$\\bao{rcl}\n\\Psi_{\\trm{int}}(b \\otimes 1_{\\trm{Hom}_R(B,A)}) &=& \\eta_A\\eps_B(\\mu_B(b \\otimes\\_))\\\\\n&&\\\\\n&=& \\left[b' \\longmapsto \\eta_A(\\eps_B(b b')) = \\eps_B(b b') \\eta_A(1_R) = \\eps_B(b) \\eta_A(\\eps_B(b'))\\right]\\\\\n&&\\\\\n&=& \\eps_B(b) \\eta_A \\eps_B\\\\ \n\\ea$$\nshowing the second diagram.\n\\en\n%\\bmk We previously claimed that the two examples \\ref{coalg_example} on pg. \\pageref{coalg_example} are not isomorphic over the same ring/field.\n\\subsection{Hopf Algebras}\nThe concept of bialgebras has another specialization in the so called Hopf algebras, with one additional condition. For its definition we need to expand some concepts.\n\\begin{defi}\\label{defi13}\nLet $(B,\\mu,\\eta,\\Delta,\\eps)$ be a bialgebra.\n\\bn\n\\item For each algebra $(B,\\mu,\\eta)$, its opposite algebra $B^{\\trm{op}}$ is defined as $(B,\\mu^{\\trm{op}},\\eta^{\\trm{op}})$, where $\\mu^{\\trm{op}} := \\mu \\tau_{B\\otimes B}$, $\\eta^{\\trm{op}} = \\eta$.\n\\item For each coalgebra $(B,\\Delta,\\eps)$, its opposite coalgebra $B^{\\trm{cop}}$ is $(B,\\Delta^{\\trm{op}},\\eps^{\\trm{op}})$, where $\\Delta^{\\trm{op}} := \\tau_{B \\otimes B} \\Delta$ and $\\eps^{\\trm{op}} = \\eps$.\n\\item The opposite bialgebra $B^{\\trm{copop}}$ is simply $(B,\\mu^{\\trm{op}},\\eta,\\Delta^{\\trm{op}},\\eps)$.\n\\item An antipode $S : B \\longrightarrow B^{\\trm{op}}$ is a homomorphism of algebras such that $$S * id_B := [x \\longmapsto \\sum_{(x)} S(x_{(1)}) x_{(2)}] = [x \\longmapsto \\sum_{(x)} x_{(1)} S(x_{(2)})] =: id * S = \\eta \\eps$$\n(i.e. $S$ the two-sided inverse of identity with respect to convolution on $\\trm{Hom}((B, \\Delta, \\eps),(B, \\mu, \\eta))$).\n\\item\\label{defi131} An Hopf algebra $B$ is a bialgebra with antipode $S \\in \\trm{Hom}(B,B)$.\n\\en\n\\index{Index}{Hopf algebra}\n\\index{Index}{antipode}\n\\index{Index}{algebra!opposite}\n\\index{Index}{coalgebra!opposite}\n\\index{Index}{bialgebra!opposite}\n\\index{Symbol}{$\\Delta^{\\trm{op}}$}\n\\index{Symbol}{$\\mu^{\\trm{op}}$}\n\\index{Symbol}{$B^{\\trm{op}}$}\n\\index{Symbol}{$B^{\\trm{cop}}$}\n\\index{Symbol}{$B^{\\trm{copop}}$}\n\\index{Symbol}{$S$}\n\\end{defi}\nThe concept of opposite algebra can be extended to objects in the category of groups: let $G$ be an object in $\\trm{Grp}$, its opposite group $G^{\\trm{op}}$ is the same set $G$, with the same unit map $e : \\ast \\longrightarrow G$, but with multiplication:\n$$m : G \\times G \\longrightarrow G, (g,h) \\longmapsto h g.$$\nThe notation used here is introduced in the appendix, in the category theory section. An anti-homomorphism in the category of groups is a group homomorphism $i : G \\longrightarrow G^{\\trm{op}}$. Thus, we can characterize the antipode as a bialgebra homomorphism:\n$$S : B \\longrightarrow B^{\\trm{copop}},$$\ni.e. an antihomomorphism (in the category of bialgebras). The following composed commutative diagram describes definition \\ref{defi13}.\\ref{defi131}:\n$$\\xymatrix{\nB \\ar[d]_\\Delta\\ar[r]^\\eps & R\\ar[r]^\\eta & B\\\\\nB\\otimes B\\ar[rr]^{id_B \\otimes S}_{S \\otimes id_B} &&B\\otimes B\\ar[u]_\\mu\\\\\n}$$\n%\\begin{defi}\n%Let $(B,\\mu,\\eta,\\Delta,\\eps,S)$ be a Hopf algebra.\n%\\bn\n%\\item \n%\\en\n%\\end{defi}\n\\subsubsection{Skew symmetric polynomials}\nFrom now on, we assume $R$ to be some algebraically closed field. Let $q \\in R^\\times$ then the polynomial ring $A := R[X]$ has a Hopf-algebra structure as mentioned before. Revisiting the notion of Ore-extionsions, let $\\alpha := [X^i \\longmapsto (q X)^i]$ be an $R$-algebra homomorphism on $A$. Clearly, the zero-homomorphism is an $\\alpha$-derivation.\n\\begin{defi}[Skew symmetric polynomials]\nLet $\\delta = 0_A$. The $A$-algebra $B := A[Y,\\alpha,\\delta]$ is called the ring of skew-symmetric polynomials.\n\\end{defi}\n\\bmk This can be constructed via the tensor algebra over some free $R$-module free of rank 2:\n$$B \\simeq R\\left<X,Y\\right>/\\left<Y X - q X Y\\right>.$$\nThis can be extended in the following sense: let $\\mathfrak{g}$ denote an $R$-Lie algebra and $U(\\mathfrak{g})$ denoted its universal enveloping algebra. If $\\left<x_i : x_i \\in \\mathfrak{g}\\right> = \\mathfrak{g}$ we construct the quantized universal enveloping algebra $U_{\\trm{quant}}(\\mathfrak{g})$ via Ore-extensions as follows:\n$A_1 := R[x_1]$ and $A_i := A_{i-1}[x_i,\\alpha_i,\\delta_i]$, with $\\alpha_i \\in \\trm{Aut}_{\\trm{alg}}(A_{i-1})$ and $\\delta_i \\in \\trm{Der}_{\\alpha_i}(A_{i-1})$.\n \\bsp The best understood examples are the $q$-quantized universal enveloping algebras of finite dimensionals simple Lie algebras as $\\mathfrak{sl}_n(R)$ (where $R$ is a field and $q \\in R^\\times\\bsl\\{1\\}$). See for instance Klimyk \\cite{Klim}, for $U_q(\\mathfrak{so}_n)$ or Saito  \\cite{Sait} for the general case.\n\\bmk Lastly, we like to note that Saito and Umemura gave a brief introduction to quantized Galois theory over $\\qz$ \\cite{SaitoUmemura,SaitoUmemura01}. There, the differential Galois group is a quantum group. However, this beyond the scope of this essay.", "meta": {"hexsha": "b174cd4f8d557f792f5360f7782494f6c556ec38", "size": 89038, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Script_Diff_Gal07/prereqs.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Script_Diff_Gal07/prereqs.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Script_Diff_Gal07/prereqs.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.4272970562, "max_line_length": 828, "alphanum_fraction": 0.6565623666, "num_tokens": 34465, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7814985687569463}}
{"text": "\\section{Derivation of Euler's formula}\\label{eulers-formula-derivation}\n\nEuler's formula is a basic tool that is widely used in the field of complex\nanalysis. It can directly tell that multiplication of complex numbers indicates\nrotations.\n\nIn this section, Euler's formula will be proved using the \\textbf{Maclaurin\nexpansion} of the following three function.\n\n\\begin{equation}\n\te^x=\\sum_{n=0}^\\infty{x^n\\over n!}\n\t=1+x+{x^2\\over2!}+{x^3\\over3!}+\\dots\n\t\\label{taylor-exp}\n\\end{equation}\n\\begin{equation}\n\t\\sin(x)=\\sum_{n=0}^\\infty{(-1)^n\\over(2n+1)!}x^{2n+1}\n\t=x-{x^3\\over3!}+{x^5\\over5!}-{x^7\\over7!}+\\dots\n\t\\label{taylor-sin}\n\\end{equation}\n\\begin{equation}\n\t\\cos(x)=\\sum_{n=0}^\\infty{(-1)^n\\over(2n)!}x^{2n}\n\t=1-{x^2\\over2!}+{x^4\\over4!}-{x^6\\over6!}+\\dots\n\t\\label{taylor-cos}\n\\end{equation}\n\nFirst, if we substitute $x$ with $i\\theta$ in the exponential function.\nTherefore, the corresponding Maclaurin series can be written like this:\n\n$$\n\\begin{aligned}\n\te^{i\\theta}\n\t&=1+i\\theta+{i^2\\theta^2\\over2!}+{i^3\\theta^3\\over3!}+\\dots \\\\\n\t&=1+i\\theta-{\\theta^2\\over2!}-{i\\theta^3\\over3!}+{\\theta^4\\over4!}\n\t+\\dots \\\\\n\t&=1-{\\theta^2\\over2!}+{\\theta^4\\over4!}-{\\theta^6\\over6!}+\\dots\n\t+i\\left(\\theta-{\\theta^3\\over3!}+{\\theta^5\\over5!}-{\\theta^7\\over7!}\n\t+\\dots\\right)\n\\end{aligned}\n$$\n\nBy mathematical induction, one can easily see that the real component of this\nexpression matches the pattern of equation (\\ref{taylor-cos}) and the imaginary\npart matches (\\ref{taylor-sin}). Eventually, we inducted Euler's formula.\n\n$$e^{i\\theta}=\\cos\\theta+i\\sin\\theta$$\n\nWhen substituting $\\theta$ with $\\pi$, the formula becomes \\textbf{Euler's\nidentity}, which puts two transcendental numbers, two units of complex numbers,\nand zero in a single equation.\n\n$$e^{i\\pi}+1=0$$\n", "meta": {"hexsha": "53e935e65dd85c49e313a610c71dca2536ab191c", "size": 1763, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "eulers-formula.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "eulers-formula.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "eulers-formula.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 33.9038461538, "max_line_length": 79, "alphanum_fraction": 0.6965399887, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8519528019683105, "lm_q1q2_score": 0.7814985653088572}}
{"text": "\\section{Scalar multiplication}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Multiply a matrix by a scalar, and take linear combinations of matrices.\n  \\item Identify when these operations are not defined.\n  \\item Apply the algebraic properties of matrix addition and scalar\n    multiplication to manipulate an algebraic expression involving\n    matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nThe multiplication of a scalar by a matrix is called the\n\\textbf{scalar multiplication} of matrices. The new matrix is obtained\nby multiplying every entry of the original matrix by the given scalar,\nas in the following example.\n\\begin{equation*}\n  3~\\begin{mymatrix}{rrrr}\n    1 & 2 & 3 & 4 \\\\\n    5 & 2 & 8 & 7 \\\\\n    6 & -9 & 1 & 2\n  \\end{mymatrix} = \\begin{mymatrix}{rrrr}\n    3 & 6 & 9 & 12 \\\\\n    15 & 6 & 24 & 21 \\\\\n    18 & -27 & 3 & 6\n  \\end{mymatrix}.\n\\end{equation*}\nThe formal definition of scalar multiplication is as follows.\n\n\\begin{definition}{Scalar multiplication of a matrix}{scalar-multiplication-of-matrices}\n  If $k$ is a scalar and $A=\\mat{a_{ij}}$ is a matrix, then\n  $kA=\\mat{ka_{ij}}$%\n  \\index{matrix!scalar multiplication}%\n  \\index{scalar multiplication!of a matrix}.\n\\end{definition}\n\n\\begin{example}{Linear combination of matrices}{matrix-linear-combination}\n  Find $2A-3B$, where%\n  \\index{linear combination!of matrices}\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    B = \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  \\begin{equation*}\n    2A-3B =\n    2 \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      1 & 0 & 4\n    \\end{mymatrix}\n    - 3 \\begin{mymatrix}{rrr}\n      5 & 2 & 3 \\\\\n      -6 & 2 & 1\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      2 & 4 & 6 \\\\\n      2 & 0 & 8\n    \\end{mymatrix}\n    - \\begin{mymatrix}{rrr}\n      15 & 6 & 9 \\\\\n      -18 & 6 & 3\n    \\end{mymatrix}\n    =\n    \\begin{mymatrix}{rrr}\n      -13 & -2 & -3 \\\\\n      20 & -6 & 5\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nScalar multiplication of matrices obeys the same properties as scalar\nmultiplication of vectors.\n\n\\begin{proposition}{Properties of scalar multiplication}{properties-scalar-multiplication}\n  Let $A$ and $B$ be matrices of the same size, and let $k,\\ell$ be\n  scalars. Then the following properties%\n  \\index{matrix!properties of scalar multiplication}%\n  \\index{matrix!scalar multiplication!properties}%\n  \\index{properties of scalar multiplication!matrix} hold.\n  \\begin{itemize}\n  \\item The distributive law over matrix addition\n    \\begin{equation*}\n      k (A+B) = kA + kB.\n    \\end{equation*}\n  \\item The distributive law over scalar addition\n    \\begin{equation*}\n      (k + \\ell) A = k A + \\ell A.\n    \\end{equation*}\n  \\item The associative law for scalar multiplication\n    \\begin{equation*}\n      k (\\ell A) = (k \\ell) A.\n    \\end{equation*}\n  \\item The rule for multiplication by $1$\n    \\begin{equation*}\n      1A=A.\n    \\end{equation*}\n  \\end{itemize}\n\\end{proposition}\n", "meta": {"hexsha": "559096f191b6b19811b82aa09704e56ac08d7b07", "size": 3086, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-ScalarMultiplication.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-ScalarMultiplication.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-ScalarMultiplication.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.3119266055, "max_line_length": 90, "alphanum_fraction": 0.6419313027, "num_tokens": 1028, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8791467595934563, "lm_q1q2_score": 0.7813494211301804}}
{"text": "\n\\subsection{Stratified sampling}\nStratified sampling refers to a type of sampling method . With stratified sampling, the population is divided into separate groups, called strata. Then, a probability sample (often a simple random sample) is drawn from each group.\n\nConsider the political polling, it's impractical to poll an entire population. So pollsters select a sample of individuals that represents the whole population. Understanding how respondents come to be selected to be in a poll is a big step toward determining how well their views and opinions mirror those of the voting population. A simple example is that choose $n$ individuals randomly,\n$$\n\\mathbb{E}_p({\\# Republicans \\over n})=p, \\quad Var({\\# Republicans \\over n})=p(1-p).\n$$\nThe accuracy of the sampling is approximate to $\\sqrt{p(1-p)\\over n}$. If the size of the sample is 100 and $p\\approx 0.5$, then $\\sqrt{p(1-p)\\over n}\\approx 5\\%$. This implies that the size of the sample should be large enough to get a good estimate.\n\nAnother way to select a sample is to break the population into several groups, say A and B. Suppose the percentage of individuals belong to group A is $p_A=70\\%$, and the percentage for group B is $p_B=30\\%$. And $p_{A, R}=80\\%$ individuals in group A will vote for Republicans and only $p_{B, R}=10\\%$ in group B will vote for Republicans. Instead of calling $n=100$ individuals randomly, we call $np_A=70$ people in group A and $np_B=30$ people in group B. Then the variance becomes\n\\begin{equation*}\n\\begin{split}\n\\mathbb{V}(0.7{\\# Republicans \\over 70} + 0.3{\\# Republicans \\over 30})&=0.7^2{p_{A, R}(1-p_{A, R})\\over 70} + 0.3^2{p_{B, R}(1-p_{B, R})\\over 30}\\\\\n&=100(0.7*0.8*0.2 + 0.3*0.1*0.9).\n\\end{split}\n\\end{equation*}\n\nThis is an application of the stratified sampling. The population is divided into separate groups. There are two stratified sampling strategies: One is proportionate allocation, which  uses a sampling fraction in each of the strata that is proportional to that of the total population. The above example belongs to this case. The other strategy is \noptimum allocation, where the sampling fraction of each stratum is proportionate to both the proportion (as above) and the standard deviation of the distribution of the variable. \n\n\nStratified sampling has several advantages over simple random sampling. For example, using stratified sampling, it may improve the precision of the sample by reducing sampling error. It can produce a weighted mean that has less variability than the arithmetic mean of a simple random sample of the population.\n\nLet $\\theta$ be a random variable representing the groups mentioned above and $P(\\theta)$ be the distribution. Define\n$$\nf(x)=\\mathbb{E}_{P} (f_{\\theta}(x))=\\mathbb{E}_{\\theta} (q(x, \\theta))=\\int_G q(x,\\theta) dP(\\theta).\n$$ \nA sample from the distribution $P(\\theta)$ gives us $\\theta_1, \\theta_2, \\cdots , \\theta_n$. Let\n\\begin{equation}\nf_n(x)={1\\over n}\\sum_{k=1}^n f_{ \\theta_k}(x)={1\\over n}\\sum_{k=1}^n q(x, \\theta_k)\n\\end{equation}\nThen, the variance is \n\\begin{equation}\n\\mathbb{V}(f_n(x))={1\\over n}\\mathbb{V}(f)\n\\end{equation}\nwith error ${1\\over \\sqrt{n}}$.\n\nStratified sampling is to break $G$ into groups $G_1, G_2, \\cdots, G_M$ so that the variation of $q(x,\\theta)$ is small on each $G_i$. Instead of sampling uniformly from $G$ and taking the average, we sample from each $G_i$ and get $\\theta_{i,1}$, $\\theta_{i,2}, \\cdots, \\theta_{i,n_i}$ where $n_i=\\lceil nP(G_i)\\rceil$ is the size of samples in $G_i$. Then there exists the estimate\n\\begin{equation}\n\\sum_{i=1}^M P(G_i)[{1\\over n_i}\\sum_{j=1}^{n_i} q(x,\\theta_{ij})]\n\\end{equation}\nwhere ${1\\over n_i}\\sum_{j=1}^{n_i} q(x,\\theta_{ij})$ is an estimate of the conditional expectation $\\mathbb{E}_p(q(x,\\theta|\\theta\\in G_i))$. Note that $n_i\\leq np_i$ with $p_i=P(G_i)=\\int_{G_i} dP(\\theta)$. The variance of the estimate is \n\\begin{equation}\n\\sum_{i=1}^M p_i^2{\\mathbb{V}[q(x,\\theta)|\\theta\\in G_i)]\\over n_i}\n\\leq \\sum_{i=1}^M {p_i^2\\over np_i}\\mathbb{V}[q(x,\\theta)|\\theta\\in G_i]\n= {1\\over n}\\sum_{i=1}^M p_i\\mathbb{V}[q(x,\\theta)|\\theta\\in G_i].\n\\end{equation} \nThis implies that we need to choose $G_i$ so that $\\mathbb{V}[q(x,\\theta)|\\theta\\in G_i]$ is small. \n\nIf $G$ is bounded in $\\mathbb{R}^d$ and $q(x,\\theta)$ is smooth with respect to $\\theta$,\n$$\n|\\nabla_\\theta q|\\leq C.\n$$\nWe can consider a particular partition of $G$ into  $M$ sets $G_1, G_2, \\cdots, G_M$ with diameter $\\mathcal{O}(n^{-1/d})$. We choose one element from each set. For each $G_i$, sample $n_i=\\lceil nP(G_i)\\rceil$ samples in $G_i$.  Let\n\\begin{equation}\nf_n(x)=\\sum_{k=1}^n p_i[{1\\over n_i}\\sum_{j=1}^{n_i}q(x,\\theta_{ij})]\\in NN_{2n}.\n\\end{equation}\nThe variance is \n\\begin{equation}\nVar(f_n)= {1\\over n}\\sum_{i=1}^M p_i\\mathbb{V}[q(x,\\theta)|\\theta\\in G_i]\\leq (n^{-1/d}C)^2\n\\end{equation}\nAccording to , there exists the following modified estimate \n\\begin{equation}\nVar(f_n)\\leq n^{-1-2/d} \n\\end{equation}\nThus, for any $f$, there exist $\\theta_{ij}, 1\\leq i\\leq n, 1\\leq j\\leq n_i$ such that\n\\begin{equation}\n|f_n-f|\\leq  n^{-1/2-1/d}.\n\\end{equation}\n\n ", "meta": {"hexsha": "a498a70b07fe37af1b9163489061458793fb2860", "size": 5089, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/StratifiedSamplingIntro.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/StratifiedSamplingIntro.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/StratifiedSamplingIntro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.6805555556, "max_line_length": 484, "alphanum_fraction": 0.714089212, "num_tokens": 1678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8887587986487518, "lm_q1q2_score": 0.7813494192993192}}
{"text": "\\documentclass{amsart}\n\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\\title{PDE: Assignment 3}\n\\author{Mark Ditsworth}\n\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section{Problem 1}\n\tConsider a three-component vector field $\\mathbf{u(x)}$ on some finite volume domain $\\Omega \\in \\mathbb{R}^3$. Define the inner product of two vectors $\\mathbf{u}$ and $\\mathbf{v}$ by the volume integral: $\\langle\\mathbf{u},\\mathbf{v}\\rangle = \\int_{\\Omega} \\overline{\\mathbf{u}} \\cdot \\mathbf{v}$. Consider the curl operator $\\triangledown \\times$.\n\t\\\\\n\t\\subsection{Part 1}\n\tDerive the identity: $\\triangledown \\cdot (\\mathbf{u} \\times \\mathbf{v}) = (\\triangledown \\times \\mathbf{u}) \\cdot \\mathbf{v} - \\mathbf{u} \\cdot (\\triangledown \\times \\mathbf{v})$\n\t\\\\\\\\\n\t\\[ \\triangledown \\cdot (\\mathbf{u} \\times \\mathbf{v})=\n\t   \\triangledown \\cdot\n\t   \\begin{bmatrix}\n\t\t   u_2v_3 - u_3v_2\\\\\n\t\t   u_3v_1 - u_1v_3\\\\\n\t\t   u_1v_2 - u_2v_1\n\t   \\end{bmatrix}=\n\t   \\frac{\\partial}{\\partial x}(u_2v_3 - u_3v_2) + \\frac{\\partial}{\\partial y}(u_3v_1 - u_1v_3) + \n\t   \\frac{\\partial}{\\partial z}(u_1v_2 - u_2v_1)\n\t\\]\\\\\n\t\n\t\\[ (\\triangledown \\times \\mathbf{u}) \\cdot \\mathbf{v} - \\mathbf{u} \\cdot (\\triangledown \\times \\mathbf{v}) = \n\t\\begin{bmatrix}\n\t\t\\frac{\\partial u_3}{\\partial y} - \\frac{\\partial u_2}{\\partial z} &\n\t\t\\frac{\\partial u_1}{\\partial z} - \\frac{\\partial u_3}{\\partial x} &\n\t\t\\frac{\\partial u_2}{\\partial x} - \\frac{\\partial u_1}{\\partial y}\n\t\\end{bmatrix} \\cdot \\mathbf{v} - \\mathbf{u} \\cdot\n\t\\begin{bmatrix}\n\t\t\\frac{\\partial v_3}{\\partial y} - \\frac{\\partial v_2}{\\partial z} \\\\\n\t\t\\frac{\\partial v_1}{\\partial z} - \\frac{\\partial v_3}{\\partial x} \\\\\n\t\t\\frac{\\partial v_2}{\\partial x} - \\frac{\\partial v_1}{\\partial y}\n\t\\end{bmatrix}\n\t\\]\\\\\n\t\n\t\\[ = \\frac{\\partial u_3}{\\partial y}v_1 - \\frac{\\partial u_2}{\\partial z}v_1 +\n\t\\frac{\\partial u_1}{\\partial z}v_2 - \\frac{\\partial u_3}{\\partial x}v_2 +\n\t\\frac{\\partial u_2}{\\partial x}v_3 - \\frac{\\partial u_1}{\\partial y}v_3 - \n\t\\frac{\\partial v_3}{\\partial y}u_1 + \\frac{\\partial v_2}{\\partial z}u_1 -\n\t\\frac{\\partial v_1}{\\partial z}u_2 + \\frac{\\partial v_3}{\\partial x}u_2 -\n\t\\frac{\\partial v_2}{\\partial x}u_3 + \\frac{\\partial v_1}{\\partial y}u_3\n\t\\]\n\t\\\\\n\t\n\t\\[ = \\frac{\\partial u_2}{\\partial x}v_3 + \\frac{\\partial v_3}{\\partial x}u_2 - \\left( \\frac{\\partial u_3}{\\partial x}v_2 +  \\frac{\\partial v_2}{\\partial x}u_3\\right) + \\frac{\\partial u_3}{\\partial y}v_1 + \\frac{\\partial v_1}{\\partial y}u_3 - \\left( \\frac{\\partial u_1}{\\partial y}v_3 + \\frac{\\partial v_3}{\\partial y}u_1 \\right) + \\frac{\\partial u_1}{\\partial z}v_2 + \\frac{\\partial v_2}{\\partial z}u_1 \\]\\\\\\[+ \\left( \\frac{\\partial u_2}{\\partial z}v_1 + \\frac{\\partial v_1}{\\partial z}u_2\\right)\n\t\\]\\\\\n\tby the chain rule,\\\\\n\t\\[ =\\frac{\\partial}{\\partial x}(u_2v_3 - u_3v_2) + \\frac{\\partial}{\\partial y}(u_3v_1 - u_1v_3) + \n\t\\frac{\\partial}{\\partial z}(u_1v_2 - u_2v_1)\n\t\\]\\\\\n\t\n\t\\[ \\therefore \\triangledown \\cdot (\\mathbf{u} \\times \\mathbf{v}) = (\\triangledown \\times \\mathbf{u}) \\cdot \\mathbf{v} - \\mathbf{u} \\cdot (\\triangledown \\times \\mathbf{v})\n\t\\]\n\t\\\\\\\\\n\t\\subsection{Part 2}\n\tShow that $\\langle\\mathbf{u},\\triangledown \\times \\mathbf{v}\\rangle = \\langle\\triangledown \\times \\mathbf{u},\\mathbf{v}\\rangle + \\iint_{\\partial \\Omega} \n\t\\mathbf{w} \\cdot dS$ for some $\\mathbf{w}$.\n\t\\\\\\\\\n\tFrom Part 1, $\\overline{\\mathbf{u}} \\cdot (\\triangledown \\times \\mathbf{v}) = (\\triangledown \\times \\overline{\\mathbf{u}}) \\cdot \\mathbf{v} - \\triangledown \\cdot (\\overline{\\mathbf{u}} \\times \\mathbf{v})$\n\t\\\\\\\\\n\t\\[ \\int_{\\Omega}\\overline{\\mathbf{u}} \\cdot (\\triangledown \\times \\mathbf{v}) = \\int_{\\Omega}(\\triangledown \\times \\overline{\\mathbf{u}}) \\cdot \\mathbf{v} - \\int_{\\Omega} \\triangledown \\cdot (\\overline{\\mathbf{u}} \\times \\mathbf{v})\n\t\\]\\\\\n\tFrom the definition of the inner product,\n\t\\\\\n\t\\[\\langle\\mathbf{u},\\triangledown \\times \\mathbf{v}\\rangle = \\langle\\triangledown \\times \\mathbf{u},\\mathbf{v}\\rangle - \\int_{\\Omega} \\triangledown \\cdot (\\overline{\\mathbf{u}} \\times \\mathbf{v})\n\t\\]\\\\\n\tUsing the divergence theorem,\n\t\\\\\n\t\\[\\langle\\mathbf{u},\\triangledown \\times \\mathbf{v}\\rangle = \\langle\\triangledown \\times \\mathbf{u},\\mathbf{v}\\rangle + \\iint_{\\partial \\Omega} (\\overline{\\mathbf{u}} \\times \\mathbf{v}) \\cdot dS.\n\t\\]\n\t\\\\\n\tThus, $\\mathbf{w} = \\overline{\\mathbf{u}} \\times \\mathbf{v}$, and we are done.\n\t\\\\\n\t\\subsection{Part 3}\n\tGive a possible boundary condition on the vector space such that $\\triangledown\\times$ is self-adjoint with this inner product.\n\t\\\\\\\\\n\tIf $\\langle \\mathbf{u} ,\\triangledown\\times \\mathbf{v} \\rangle = \\langle \\triangledown\\times \\mathbf{u}, \\mathbf{v} \\rangle$ then $\\triangledown\\times$ is self-adjoint. For this to be true,\\\\ $\\iint_{\\partial\\Omega} (\\overline{\\mathbf{u}}\\times \\mathbf{v})\\cdot dS = 0$.\n\t\\\\\n\t\n\t\\noindent\n\tThus, with the boundary condition $\\overline{\\mathbf{u}} \\times \\mathbf{v} = 0$, the above equality will be true and $\\triangledown\\times$ will be self-adjoint.\n\t\\\\\n\t\\subsection{Part 4}\n\tShow that $\\triangledown\\times\\triangledown\\times$ is self-adjoint for this inner product under \\textit{either} some boundary condition on $\\mathbf{u}$ or some boundary condition on the \\textit{derivatives} of $\\mathbf{u}$. Is it positive or negative definite or semi-definite?\n\t\\\\\\\\\n\tIf $\\langle \\mathbf{u},\\triangledown\\times\\triangledown\\times\\mathbf{v}\\rangle = \\langle \\triangledown\\times\\triangledown\\times\\mathbf{u},\\mathbf{v}\\rangle$ then $\\triangledown\\times\\triangledown\\times$ is self-adjoint.\n\t\\\\\n\t\\[\n\t\\langle \\mathbf{u},\\triangledown\\times\\triangledown\\times \\mathbf{v}\\rangle = \\langle \\triangledown\\times\\mathbf{u},\\triangledown\\times\\mathbf{v}\\rangle + \\iint_{\\partial\\Omega} (\\overline{\\mathbf{u}} \\times \\triangledown\\times \\mathbf{v}) \\cdot dS\n\t\\]\n\t\\[\n\t\\langle\\mathbf{u},\\triangledown\\times\\triangledown\\times \\mathbf{v}\\rangle = \\langle \\triangledown\\times\\triangledown\\times\\mathbf{u}, \\mathbf{v}\\rangle + \\iint_{\\partial\\Omega}(\\triangledown\\times\\overline{\\mathbf{u}}\\times\\mathbf{v})\\cdot dS + \\iint_{\\partial\\Omega} (\\overline{\\mathbf{u}} \\times \\triangledown\\times \\mathbf{v}) \\cdot dS\n\t\\]\\\\\n\tIf $\\mathbf{u}\\times \\mathbf{n}|_{\\partial\\Omega} = 0$ or $\\triangledown\\times\\mathbf{u}\\times\\mathbf{n}|_{\\partial\\Omega}=0$, then $\\triangledown\\times\\triangledown\\times$ is self-adjoint.\n\t\\\\\\\\\n\t$\\langle\\mathbf{u},\\triangledown\\times\\triangledown\\times\\mathbf{u}\\rangle = \\langle\\triangledown\\times\\mathbf{\\overline{u}},\\triangledown\\times\\mathbf{u}\\rangle = \\int_{\\Omega}|\\triangledown\\times\\mathbf{u}|^2 \\geq 0$, thus it is positive semi-definite.\n\t\\subsection{Part 5}\n\tTwo of Maxwell's equations are $\\triangledown\\times \\mathbf{E} = -\\frac{\\partial\\mathbf{B}}{\\partial t}$ and $\\triangledown\\times\\mathbf{B} = \\frac{1}{c^2}\\frac{\\partial\\mathbf{E}}{\\partial t}$. Take the curl of both sides of the first equation to obtain a PDE in $\\mathbf{E}$ alone. Suppose that $\\Omega$ is the interior of a hollow metal container, where the boundary conditions are that $\\mathbf{E}$ is perpendicular to the metal at the surface. Combining these facts with the previous parts, explain why one would expect \\textit{oscillating} solutions to Maxwell's equations.\n\t\\\\\\\\\n\t\\[\n\t\\triangledown\\times\\triangledown\\times\\mathbf{E} = \\triangledown\\times -\\frac{\\partial \\mathbf{B}}{\\partial t} = -\\frac{1}{c^2}\\frac{\\partial^2 \\mathbf{E}}{\\partial t^2}\n\t\\]\n\t\\[\n\t\\frac{\\partial^2\\mathbf{E}}{\\partial t^2} =  \\hat{A}\\mathbf{E}\n\t\\]\n\t\\noindent\n\twhere $\\hat{A}=-c^2 \\triangledown\\times\\triangledown\\times$. Since $\\mathbf{E}$ is normal to the surface, Part 4 gives that $\\hat{A}$ is self-adjoint and negative semi-definite. Thus, the PDE is a Hyperbolic equation with eigenvalues $\\lambda\\leq0$, and thus, oscillating solutions.\n\t\\\\\\\\\\\\\n\t\\section{Problem 2}\n\tSolve for the 2-D eigenfunctions of $\\triangledown^2$ in an annular region $\\Omega$ that \\textit{does not contain the origin}, so that you will need both $J_m$ and $Y_m$ solutions to Bessel's equation. The separation of variables $u(r,\\Theta) = \\rho(r)\\tau(\\Theta)$ leads to functions $\\tau(\\Theta)$ spanned by $\\sin(m\\Theta)$ and $\\cos(m\\Theta)$ and functions $\\rho(r)$ that satisfy Bessel's equation. That is, the eigenfunctions are of the form:\n\t\\[ u(r,\\Theta) = [\\alpha J_m(kr) + \\beta Y_m(kr)] \\times [A\\cos(m\\Theta) + B\\sin(m\\Theta) \\]\n\tfor arbitrary constants $A$ and $B$, integers $m = 1,2,\\dots$, and constants $\\alpha$, $\\beta$ and $k$, which must be determined.\n\t\n\t\\noindent\n\tThe boundary conditions are Neumann boundary condition $\\frac{\\partial u}{\\partial r} = 0$ at R1 and R2.\n\t\\\\\n\t\\subsection{Part 1}\n\tUsing the boundary conditions, write two equations for $\\alpha$, $\\beta$, and $k$, of the form $E\\left(\n\t\\begin{matrix}\n\t\t\\alpha \\\\ \\beta\n\t\\end{matrix}\n\t\\right) = 0$ for some $2\\times 2$ matrix $E$. This only has a solution when the determinant is 0. Use this fact to obtain a single equation for $k$ of the form $f_m(k) =0$ for some function $f_m$ that depends on $m$. In terms of $k$, write down a possible expression for $\\alpha$, $\\beta$.\n\t\\\\\\\\\n\t\\[\n\t\t\\frac{\\partial u}{\\partial r} = \\alpha J_m'(kr) + \\beta Y_m'(kr) = 0|_{r=R_1,R_2}\n\t\\]\n\t\\\\\n\t\\[\n\tE\\left[\n\t\\begin{matrix}\n\t\\alpha \\\\ \\beta\n\t\\end{matrix}\n\t\\right] = \n\t\\left[\\begin{matrix}\n\t\tJ_m'(kR_1) & Y_m'(kR_1)\\\\\n\t\tJ_m'(kR_2) & Y_m'(kR_2)\n\t\\end{matrix}\\right]\n\t\\left[\n\t\\begin{matrix}\n\t\t\\alpha \\\\ \\beta\n\t\\end{matrix}\\right] = \\mathbf{0}\n\t\\]\n\t\\\\\n\t\\[\n\tf_m(k) = \\det E = J_m'(kR_1)Y_m'(kR_2) - J_m'(kR_2)Y_m'(kR_1) = 0\n\t\\]\n\t\\\\\n\t\\[\n\t\\frac{\\partial u}{\\partial r}|_{r=R_1} = \\frac{\\partial u}{\\partial r}|_{r=R_2} = 0\n\t\\]\n\t\\\\\n\t\\[\n\t\\alpha J_m'(kR_1)+\\beta Y_m'(kR_1) = \\alpha J_m'(kR_2)+\\beta Y_m'(kR_2) = 0\n\t\\]\n\t\\\\\n\t\\[\n\t\\beta = \\alpha \\frac{J_m'(kR_1)}{Y_m'(kR_1)} = \\alpha \\frac{J_m'(kR_2)}{Y_m'(kR_2)}\n\t\\]\n\t\\\\\n\t\\subsection{Part 2}\n\tAssuming $R1 = 1, R2=2$, plot $f_m(k)$ vs $k \\in [0,20]$ for $m=0,1,2$.\n\t\\\\\n\t\\textit{see notebook.}\n\t\\\\\n\t\\subsection{Part 3}\n\tFor $m=0$, find the first three (smallest $k>0$)  solutions to $f_0(k) = 0$.\n\t\\\\\n\t\\textit{see notebook.}\n\t\\\\\n\t\\subsection{Part 4}\n\tSince $\\triangledown^2$ is self-adjoint, the eigenfunctions must be orthogonal. Check that the solutions from Part 3 are orthogonal.\n\t\\\\\n\t\\textit{see notebook.}\n\t\\\\\n\t\\subsection{Part 5}\n\tLet the operator $\\hat{A}$ now be $c(r)\\triangledown^2$ with $c(r)=2$ for $r<R_1$ and $c(r)=1$ for $r\\geq R_1$. Impose Dirichlet boundary conditions $u(R_2)=0$. What is the form of the eigenfunctions? If we solve for eigenfunctions $\\hat{A}u = \\lambda u$, with $u$ finite everywhere, what conditions must $u$ satisfy at $r=R_1$ for $\\hat{A}u$ to be well-defined and finite? Write down a condition $f_m(k)=0$ that must be satisfied in order for the above equation to have a solution. The roots of this function give the eigenvalues.\n\t\\\\\\\\\n\tThe eigenfunctions are of the form:\n\t\\[\n\tu(r,\\theta) = [A\\cos(m\\theta) + B\\sin(m\\theta)] \\times \\left\\lbrace\n\t\\begin{matrix}\n\t\t\\alpha J_m(k_1r) & r<R_1\\\\\n\t\t\\beta J_m(k_2r) + \\gamma Y_m(k_2r) & r>R_1\n\t\\end{matrix}\\right.\n\t\\]\n\twith $k_1 = k_2/\\sqrt{2}$.\\\\\n\t\n\tIf $\\hat{A}$ is to be well defined and finite, then\n\t\\[\n\t\\alpha J_m(kR_1/\\sqrt{2}) = \\beta J_m(kR_1)+\\gamma Y_m(kR_1)\n\t\\]\n\tand\n\t\\[\n\t\\alpha J_m'(kR_1/\\sqrt{2}) = \\beta J_m'(kR_1) + \\gamma Y_m'(kR_1)\n\t\\]\n\tpaired with the Dirichlet boundary conditions, this gives the system,\n\t\\[\n\t\\left[\n\t\\begin{matrix}\n\t\t-J_m(kR_1/\\sqrt{2}) & J_m(kR_1) & Y_m(kR_1)\\\\\n\t\t-J_m'(kR_1/\\sqrt{2}) & J_m'(kR_1) & Y_m(kR_1)\\\\\n\t\t0 & J_m(kR_2) & Y_m(kR_2)\n\t\\end{matrix}\\right]\n\t\\left[\n\t\\begin{matrix}\n\t\t\\alpha \\\\ \\beta \\\\ \\gamma\n\t\\end{matrix}\n\t\\right]= E_m(k)\n\t\\left[\n\t\\begin{matrix}\n\t\t\\alpha \\\\ \\beta \\\\ \\gamma]\n\t\\end{matrix}\n\t\\right] = \\mathbf{0}\n\t\\]\n\t$f_m(k)$ is thus $\\det E_m(k)$.\n\t\n\t\\section{Problem 3}\n\tThe Bessel functions $u(x) = J_m(kx)$, solve the eigenproblem:\n\t\\[\n\t\\hat{A}u = u'' + \\frac{u'}{r} - \\frac{m^2}{r^2}u = -k^2 = \\lambda u\n\t\\]\n\ton $[0,R]$ where $u(R)=0$ and $u(0)=0$ for $m>0$.\n\t\\\\\n\t\\subsection{Part 1}\n\tShow that $\\hat{A}$ is of the form of a Sturm-Louville operator and is therefor self-adjoint for a particular inner product.\n\t\\\\\n\t\\subsection{Part 2}\n\tShow that $\\hat{A}$ is negative definite.\n\t\\\\\n\t\\subsection{Part 3}\n\tWrite a center-difference discretization of the operator $\\hat{A}$ for $u_n = u(n\\Delta x)$ with $m=1,\\dots,R \\Delta x = \\frac{R}{N+1}$.\n\t\\\\\n\t\\subsection{Part 4}\n\tIn Julia, for the matrix approximation $A$ of $\\hat{A}$ for $m=1$ (with $N=100$, $R=1$). Compare its smallest-magnitude eigenfunction to $J_1(k_{1,1}r/R)$ where $k_{1,1}$ is the first root of $J_1$. \n\t\n\\end{document}", "meta": {"hexsha": "10a71297f9c43bb94902408db4f61e698de53b23", "size": 12416, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Assignments/A3/assn3.tex", "max_stars_repo_name": "markditsworth/linearPDE", "max_stars_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_stars_repo_licenses": ["MIT"], "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/A3/assn3.tex", "max_issues_repo_name": "markditsworth/linearPDE", "max_issues_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_issues_repo_licenses": ["MIT"], "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/A3/assn3.tex", "max_forks_repo_name": "markditsworth/linearPDE", "max_forks_repo_head_hexsha": "8f2717d5f55341fa6218836d5e4cab58db03f371", "max_forks_repo_licenses": ["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.305785124, "max_line_length": 580, "alphanum_fraction": 0.665753866, "num_tokens": 4808, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8791467722591729, "lm_q1q2_score": 0.7813494142543868}}
{"text": "\\section{Directional Derivatives}\r\n\\noindent\r\nWe already saw partial derivatives in the $x$, $y$, and $z$ directions.\r\nHowever, we can take the derivative coming from other directions.\r\nThese are called directional derivatives, $D_{\\hat{u}}{f}$, where $\\hat{u}$ is the direction.\r\n\\begin{equation*}\r\n\tD_{\\hat{u}}{f} = \\lim_{h \\to 0}{\\frac{f(\\vec{p_0} + h\\hat{u})}{h}}\r\n\\end{equation*}\r\n\\noindent\r\nIf $\\hat{u} = \\langle a, b \\rangle$, \r\n\\begin{equation*}\r\n\tD_{\\hat{u}}{f} = \\lim_{h \\to 0}{\\frac{f(x+ah, y+bh) - f(x,y)}{h}}.\r\n\\end{equation*}\r\nNote that\r\n\\begin{equation*}\r\n\tD_{\\hat{i}}{f} = \\lim_{h \\to 0}{\\frac{f(x+h, y) - f(x, y)}{h}} = f_x \\text{ and } D_{\\hat{j}}{f} = f_y.\r\n\\end{equation*}\r\nLet's look at $D_{\\hat{u}}{f}$.\r\n\\begin{align*}\r\n\tD_{\\hat{u}}{f} &= \\lim_{h \\to 0}{\\frac{f(x+ah, y+bh) - f(x+ah, y) + f(x+ah, y) - f(x, y)}{h}} \\\\\r\n\t&= b\\lim_{h \\to 0}{\\frac{f(x+ah, y+bh)-f(x+ah, y)}{bh}} + a\\lim_{h \\to 0}{\\frac{f(x+ah, y) - f(x, y)}{ah}} \\\\\r\n\t&= b\\frac{\\partial f}{\\partial y} + a\\frac{\\partial f}{\\partial x} \\\\\r\n\t&= af_x + bf_y.\r\n\\end{align*}\r\nSo, \r\n\\begin{equation*}\r\n\tD_{\\hat{u}}{f} =\\nabla f \\cdot \\hat{u}.\r\n\\end{equation*}\r\n", "meta": {"hexsha": "142b9efaa341539b4481d48037fa5f7bfa2dd3f2", "size": 1142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/directionalDerivatives.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/directionalDerivatives.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/directionalDerivatives.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 39.3793103448, "max_line_length": 111, "alphanum_fraction": 0.5665499124, "num_tokens": 510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067276593032, "lm_q2_score": 0.8289388146603364, "lm_q1q2_score": 0.7812804096352952}}
{"text": "\\lab{B-Splines}{B-Splines}\nThough B\\'{e}zier curves are good for a variety of things, they have certain limitations.\n\\begin{itemize}\n\\item As the number of control points increases it becomes very expensive to compute the points on the curve.\n\\item Changes in the placement of a single control point affect the shape of the entire curve.\n\\item Since a change in any control point affects the entire curve, it is necessary to recompute the entire curve to account for a change in a single control point.\n\\item As the number of points increases, individual points have progressively less affect on the portions of the curve that lie nearest to them.\n\\end{itemize}\n\nB-Splines are an ideal way to answer these limitations.\nA B-Spline is somewhat similar to a piecewise B\\'{e}zier curve.\n\n\\section*{B-Spline Basis Functions}\n\nIn the previous lab we introduced a way to represent B\\'{e}zier curves as a linear combination of Bernstein Polynomials.\nWe discussed the convenient property that the coefficient of each Bernstein polynomial for the B\\'{e}zier curve formed from a given control point is simply the control point itself.\nThis is a useful property.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{bernstein_basis}\n\\caption{5th degree Bernstein basis functions}\n\\end{figure}\n\nB-splines are a generalization of B\\'{e}zier curves which allow us to use piecewise basis functions.\nWe usually choose basis functions that are zero on most of the domain so that, at any given parameter value, we only have to consider a few of the basis functions to compute the value of a spline\nChoosing basis functions that are zero on significant portions of the domain makes it so that we do not have to recompute the entire curve when we change only one control point.\nIt also makes it so that the curve is easier to manipulate, since local changes in control points only change a portion of the spline curve.\n\nWe would like to be able to do this without loosing the useful properties of B\\'{e}zier curves.\nUsing basis functions of any sort guarantees that each point of the curve will be a linear combination of the control points.\nIt would be best if we could make it so that this curve has the convex hull property (i.e. that it lies within the area bounded by the outermost control points).\nB\\'{e}zier curves also allow easy computation of their derivatives, so we would hope that B-Splines would allow this as well.\nOne of the largest constraints we need is that the curve we are forming be continuous with a given number of continuous derivatives.\nThe construction of the B-Spline Basis functions takes all of these factors into account.\n\nThere are a number of ways the B-Spline basis functions can be defined.\nA common approach is to use recursion.\nLet $t = \\lbrace t_0, t_1, ... , t_l \\rbrace$ be a nondecreasing sequence of real numbers.\n$t$ is called the knot vector.\nThe $t_i$ are called the knots.\nNote that each $t_i$ is not necessarily distinct.\n$N_{i,k}(x)$, the $i$'th B-Spline basis function of degree $k$ is defined as:\n\n\\begin{equation*}\nN_{i,0}(x) =\n\\begin{cases}\n1 & \\text{if } t_i \\leq x < t_{i+1} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation*}\n\n\\begin{equation*}\nN_{i,k}(x) = \\frac{x - t_i}{t_{i+k} - t_i} N_{i,k-1}(x) + \\frac{t_{i + k + 1} - x}{t_{i + k + 1} - t_{i + 1}} N_{i+1,k-1}(x)\n\\end{equation*}\n\nThis is known as the Cox-De Boor recursion formula.\nThis algorithm is the De Boor algorithm.\nWhen implemented properly, this algorithm is both fast and numerically stable.\nSome simple basis functions are shown in Figure \\ref{fig:bspline_basis}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{bspline_basis.pdf}\n\\caption{B-spline basis functions that are only nonzero on a portion of the given interval.}\n\\label{fig:bspline_basis}\n\\end{figure}\n\nFinding the point of a spline at a given parameter value $x$ is done in the same way it was using the Bernstein basis for B-splines.\nWhere, $P_i$ are the control points, $N_{i,k}$ are the basis functions of degree $k$, and there are $n$ control points , we have that the spline $B$ of degree $k$ can be written\n\\[B\\left(x\\right) = \\sum_{i=0}^n P_i N_{i,k}\\left(x\\right)\\]\n\nNotice that we defined $t$ to be nondecreasing, which means some $t_i$ may be repeated.\nWhen programming this algorithm as it is currently written, be careful to avoid division by zero.\nWhenever we get the indeterminate form $\\frac{0}{0}$ or any other sort of division by $0$, we must replace it with zero.\n\nAlso note that $N_{i,0}$ is a step function which is zero except on $[t_i, t_{i+1})$.\nThe other basis functions are piecewise polynomials of degree $k$ that are only nonzero on $[t_{i-k}, t_{i+1+k})$.\nThis is nice because computation of a set of basis functions requires only a knot vector $t$ and a degree $k$, so we can predefine basis functions before we know the actual positions of the control points.\n\n\\begin{warn}\nWhen performing the computation of each of the terms in the De Boor Algorithm, you should very careful about division by $0$.\nWhenever division by $0$ occurs in either term, you should replace the value for \\emph{that specific term} by $0$.\nThis should be done for each term independently so that, if you are using NumPy's float types, a value of \\li{inf} or \\li{nan} does not propagate through the recursion in the algorithm.\nYou can test to see if a floating point number has a value of \\li{nan} or \\li{inf} using the functions \\li{math.isnan} and \\li{math.isinf} or \\li{numpy.isnan} and \\li{numpy.isinf}.\nThis can also be done by checking to see if the denominator is $0$ before performing division.\n\\end{warn}\n\n\\begin{problem}\nUse the De Boor algorithm to write a recursive python function to evaluate a b-spline basis function for some $x$ between the maximum and minimum of a given knot vector $t$.\n\\end{problem}\n\nUpon considering the computation involved in the previous problem, we see that this recursion, particularly for higher order splines, involves a massive amount of repetitive calculation.\nMany of the performance costs can be avoided by rewriting the algorithm using explicit loops and avoiding unnecessary computations.\n\n\\begin{comment}\n% These comments and this problem could be one way to expand this lab later on.\n% Depending on how long the lab is, we will probably want to give them pseudocode for this version of the algorithm.\n\nFirst, notice that for splines of order $2$ and higher, we actually compute the values of some splines multiple times.\nA simple way to avoid this is to figure out which of the 0-order splines we will actually use in our computation, compute them all, then compute all the needed splines of order 1, 2, etc.\n\nThere is also some redundant computation in the computation of the coefficients used at each stage of the recursion.\nThis can be eliminated by using good control structure and a temporary variable.\n\nWe will label the left and right coefficients in the formula $L$ and $R$ respectively, so we have $L(i, k, x) = \\frac{x - t_i}{t_{i + k} - t_i}$ and $R(i, p, u) = \\frac{t_{i + k + 1} - x}{t_{i + k + 1} - t_{i + 1}}$.\nNotice that $L(i + 1, k, x) = 1 - R(i, k, x)$.\nWe can eliminate much of the duplicate computation by computing the new left hand side coefficient the iteration before we actually need it.\nThis avoids nearly all the repeated computation.\n\n\\begin{problem}\nWrite a function that uses loops instead of recursion to compute the values for all the b-spline basis functions of a given power $k$ for a given array of $t$ values.\nReturn the answer as a two dimensional array with the results for each polynomial stored in each of the rows of the array.\n\\end{problem}\n\nIt is worth noting that you can remove further excess computation when evaluating a single function and even further when evaluating a single function at a single point.\nThis can be done by figuring out in advance which of the $N_{i,k}$ will be nonzero and only iterating over those terms.\nThis approach may or may not be faster depending on the form of the problem.\n\n\\end{comment}\n\nScipy has some built in functions and a built in class for B-splines.\nThey are all part of the scipy.interpolate package.\n\nAs of SciPy 14, \\li{scipy.interpolate} also includes the \\li{BPoly} class that allows for easy computation of the basis functions for a B-spline.\n\nSeveral of the functions built in to SciPy are wrappers around the Fortran package FITPACK.\nOne such example is the function \\li{scipy.interpolate.splev}.\nThis function is used to evaluate a spline with knot vector $t$, basis function coefficients $c$, and degree $k$ at a set of points $x$.\nThe calling convention for this function is \\li{splev(x, (t, c, k))}.\nIf $c$ is a multi-dimensional array, the function is applied to each row of $c$.\nThis is equivalent to using each column of $c$ as a control point in a higher dimension.\n\nThe package \\li{scipy.interpolate} also includes several routines designed for easy interpolation with b-splines.\nIt also has routines designed for integration and differentiation of B-splines.\n\n\\begin{problem}\nUse \\li{scipy.interpolate.splev} to generate a plot of a b-spline with control points in $\\mathbb{R}^2$ at equally spaced points along the edge of a circle.\nMake your control points start and end at the point $\\left(1, 0\\right)$.\nGenerate the same plot with your own implementation of the De Boor's algorithm.\n\nUse the following knot vector (where $m$ some positive integer and $k$ is the degree of the desired spline):\n\\begin{lstlisting}\nt = np.array([0]*(k) + range(m) + [m]*(k+1))\n\\end{lstlisting}\nThis knot vector will give you $k + m$ different nonzero basis functions on the interval $\\left[0, m\\right]$.\nYou will have to include an extra column at the end of your array of control points since this knot vector gives an extra basis function that is equal to $0$.\n\\end{problem}\n", "meta": {"hexsha": "1785b5b4e59a79a003ec3a7a9df6fd0b0710040f", "size": 9787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/BSplines/bsplines.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/BSplines/bsplines.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/BSplines/bsplines.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": 66.5782312925, "max_line_length": 216, "alphanum_fraction": 0.7636660877, "num_tokens": 2436, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.7812455863535194}}
{"text": "\n\\subsection{Residual blocks}\n\nIn a node we have:\n\n\\(a_{ij}=\\sigma_{ij}(W_{ij}a_{i-1})\\)\n\nThat is, the value of a node, is the activation on the sum of the weights of the previous layer.\n\nResidual block however look further back that one layer. They include the full data from an older layer (without weights)\n\n\\(a_{ij}=\\sigma_{ij}(W_{ij}a_{i-1}+a_k)\\)\n\n", "meta": {"hexsha": "82d35b6d6024dbe8e904ca69b9e2d3616c8dbbc2", "size": 354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksRegularising/01-09-residual.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/neuralNetworksRegularising/01-09-residual.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/neuralNetworksRegularising/01-09-residual.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.2857142857, "max_line_length": 121, "alphanum_fraction": 0.7146892655, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947086083138, "lm_q2_score": 0.8267118026095992, "lm_q1q2_score": 0.781238279010112}}
{"text": "\n\\subsection{Vector spaces}\n\nA vector space is a group with additional structure.\n\nThe operation for each element is shown as addition. So we can say:\n\n\\(\\forall u,v \\in V [u+v \\in V]\\)\n\nTo this we add scalars, from a field \\(F\\). We write this as multiplication.\n\n\\(\\forall f \\in F \\forall v \\in V [fv \\in V]\\)\n\n\\subsubsection{Subspace}\n\nA subspace is a subset of \\(V\\) which still acts as a vector space. In practice, this means fewer dimensions.\n\n", "meta": {"hexsha": "bd1b002ab30a5424aa9d2e1b23a0b0cfe2051cd7", "size": 450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/linearAlgebra/01-01-vectorSpace.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/linearAlgebra/01-01-vectorSpace.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/linearAlgebra/01-01-vectorSpace.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 109, "alphanum_fraction": 0.7088888889, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591979, "lm_q2_score": 0.8267117983401364, "lm_q1q2_score": 0.7812382736948199}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nProve that the keys in any subtree form a contiguous sequence.\n\n\\subsection*{Solution}\n\nSuppose tree $T'$ with root $r'$ is a subtree of the tree $T$ with root $r$ such that $r'$ is a child of $r$.\nWe claim that the keys in the subtree $T'$ construct a contiguous sequence.\nIn other words, sorted sequence of all keys of subtree $T'$ is itself a subsequence of sorted sequence of keys of tree $T$.\n\nProof is given by contradiction.\nAssume that our initial claim is false.\nThis means there is an element $e$ in tree $T$ such that $n_1.key < e.key < n_2.key$ where $n_1$ and $n_2$ are two keys of subtree $T'$ and such that $e \\notin T'$.\n\nFollowing the assumption that $r'$ is a child of $r$, $r'$ is either the left child or the right child.\nWe now show that existence of the node $e$ in tree $T$ violates basic definition of the binary search tree.\n\n\\begin{itemize}[itemsep=1mm] \\parskip=0pt \\parsep=0pt\n\\item If $r'$ is the left child of $r$, $T'$ is a left subtree of $r$.\nTherefore, definition of the binary search tree enforces that keys of all nodes in $T'$ are less than key of $r$.\nSince $e \\notin T'$, $e$ is either $r$ or in the right subtree of $r$.\n\\begin{itemize}[itemsep=1mm] \\parskip=0pt \\parsep=0pt\n  \\item[] If $e = r$, then there is a node $n_2$ such that $r.key < n_2.key$.\n  \\item[] If $e$ is in the right subtree, this means $e.key > r.key$.\nIn this case, $e.key < n_2.key$ leads to $r.key < n_2.key$.\n\\end{itemize}\nAnd both cases violate the definition stating key of every node in left subtree $T'$ is less than $r.key$.\n\\item If $r'$ is the right child of $r$, $T'$ is a right subtree of $r$.\nTherefore, definition of the binary search tree enforces that keys of all nodes in $T'$ are bigger than key of $r$.\nSince $e \\notin T'$, $e$ is either $r$ or in the left subtree of $r$.\n\\begin{itemize}[itemsep=1mm] \\parskip=0pt \\parsep=0pt\n  \\item[] If $e = r$, then there is a node $n_1$ such that $n_1.key < r.key$.\n  \\item[] If $e$ is in the left subtree, this means $e.key < r.key$.\nIn this case, $n_1.key < e.key$ leads to $n_1 < r.key$.\n\\end{itemize}\nAnd both cases violate the definition stating keys of nodes in right subtree $T'$ are bigger than $r.key$.\n\\end{itemize}\nThrefore, our initial assumption is false and the claim holds for all cases.\n", "meta": {"hexsha": "51e68897f959e3699a916aad918e003aabbadc57", "size": 2650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw04/hw04q03.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/hw04q03.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/hw04q03.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.6086956522, "max_line_length": 164, "alphanum_fraction": 0.6701886792, "num_tokens": 790, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767970940974, "lm_q2_score": 0.8902942355821459, "lm_q1q2_score": 0.7812125343099593}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\n\\usepackage{amsmath}\n\\usepackage{booktabs}\n\n\\begin{document}\n\n\\title{NAIVE BAYES CLASSIFIER}\n\\date{}\n\\maketitle\n\nSupervised learning algorithm based on the application of Bayes\\textsc{\\char13} theorem with the\n``naive'' assumption of independence between every pair of features.\n\n\\section{Bayes' Theorem}\n\n\\begin{align*}\n\t\\mathbf{P}(A\\cap B) = \\mathbf{P}(A|B) \\times \\mathbf{P}(B)                   \\\\\n\t= \\mathbf{P}(B|A) \\times \\mathbf{P}(A)                                       \\\\\n\t                                                                             \\\\\n\t\\mathbf{P}(A|B) = \\frac{\\mathbf{P}(B|A) \\times \\mathbf{P}(A)}{\\mathbf{P}(B)}\n\\end{align*}\n\n\\section{Derivation}\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=y_k\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) = \\frac{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p|\\mathbf{Y}=y_k) \\times \\mathbf{P}(\\mathbf{Y}=y_k)}{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p)} \\\\\n\\end{align*}\n\nChoose $y_k$ which maximizes $\\mathbf{P}(\\mathbf{Y}=y_k | x_1,\\ x_2,\\ ...\\ x_p)$.\n\n\\begin{align*}\n\t\\mathbf{Y} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t\\frac{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p | \\mathbf{Y}=y_k) \\times \\mathbf{P}(\\mathbf{Y=y_k)}}{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p)} \\\\\n\t\\end{array}\n\t\\right.                                                                                                                      \\\\\n\\end{align*}\n\nSince $\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p)$ is constant for all $y_k$, the above can be written as follows:\n\n\\begin{align*}\n\t\\mathbf{Y} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p | \\mathbf{Y}=y_k) \\times \\mathbf{P}(\\mathbf{Y=y_k)} \\\\\n\t\\end{array}\n\t\\right.                                                                             \\\\\n\\end{align*}\n\nThe ``naive'' assumption that all $\\mathbf{X_1},\\ \\mathbf{X_2},\\ ...\\ \\mathbf{X_p}$ are independent allows for the following simplification.\n\n\\begin{align*}\n\t\\mathbf{Y} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t\\prod_{i} \\mathbf{P}(x_i|\\mathbf{Y}=y_k) \\times \\mathbf{P}(\\mathbf{Y=y_k)} \\\\\n\t\\end{array}\n\t\\right.                                                                    \\\\\n\\end{align*}\n\nAll the terms on the right are easy to calculate.\n\n\\section{Example}\n\n\\begin{table}[h!]\n\t\\centering\n\t\\caption{Training data}\n\t\\label{tab:table1}\n\t\\begin{tabular}{c|cccc|c}\n\t\t\\toprule\n\t\t\\textbf{Sr.} & \\textbf{Outlook} & \\textbf{Temperature} & \\textbf{Humidity} & \\textbf{Windy} & \\textbf{PlayGolf} \\\\\n\t\t\\midrule\n\t\t1            & Rainy            & Hot                  & High              & False          & No                \\\\\n\t\t2            & Rainy            & Hot                  & High              & True           & No                \\\\\n\t\t3            & Overcast         & Hot                  & High              & False          & Yes               \\\\\n\t\t4            & Sunny            & Mild                 & High              & False          & Yes               \\\\\n\t\t5            & Sunny            & Cool                 & Normal            & False          & Yes               \\\\\n\t\t6            & Sunny            & Cool                 & Normal            & True           & No                \\\\\n\t\t7            & Overcast         & Cool                 & Normal            & True           & Yes               \\\\\n\t\t8            & Rainy            & Mild                 & High              & False          & No                \\\\\n\t\t9            & Rainy            & Cool                 & Normal            & False          & Yes               \\\\\n\t\t10           & Sunny            & Mild                 & Normal            & False          & Yes               \\\\\n\t\t11           & Rainy            & Mild                 & Normal            & True           & Yes               \\\\\n\t\t12           & Overcast         & Mild                 & High              & True           & Yes               \\\\\n\t\t13           & Overcast         & Hot                  & Normal            & False          & Yes               \\\\\n\t\t14           & Sunny            & Mild                 & High              & True           & No                \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\\end{table}\n\n\\noindent The following tables are calculated.\n\n\\begin{table}[h!]\n\t\\centering\n\t\\label{tab:table2}\n\t\\begin{tabular}{c|cc}\n\t\t\\toprule\n\t\t\\textbf{Outlook} & \\textbf{Yes} & \\textbf{No} \\\\\n\t\t\\midrule\n\t\tRainy            & 2            & 3           \\\\\n\t\tOvercast         & 4            & 0           \\\\\n\t\tSunny            & 3            & 2           \\\\\n\t\\end{tabular}\n\t\\hspace{2em}\n\t\\vspace{2em}\n\t\\label{tab:table3}\n\t\\begin{tabular}{c|cc}\n\t\t\\toprule\n\t\t\\textbf{Temperature} & \\textbf{Yes} & \\textbf{No} \\\\\n\t\t\\midrule\n\t\tHot                  & 2            & 2           \\\\\n\t\tMild                 & 4            & 2           \\\\\n\t\tCool                 & 3            & 1           \\\\\n\t\\end{tabular}\n\t\\label{tab:table4}\n\t\\begin{tabular}{c|cc}\n\t\t\\toprule\n\t\t\\textbf{Humidity} & \\textbf{Yes} & \\textbf{No} \\\\\n\t\t\\midrule\n\t\tHigh              & 3            & 4           \\\\\n\t\tNormal            & 6            & 1           \\\\\n\t\\end{tabular}\n\t\\hspace{2em}\n\t\\label{tab:table5}\n\t\\begin{tabular}{c|cc}\n\t\t\\toprule\n\t\t\\textbf{Windy} & \\textbf{Yes} & \\textbf{No} \\\\\n\t\t\\midrule\n\t\tFalse          & 6            & 2           \\\\\n\t\tTrue           & 3            & 3           \\\\\n\t\\end{tabular}\n\\end{table}\n\nIf $X = (Sunny, Hot, Normal, False)$, then\n\n\\begin{align*}\n\t\\mathbf{PlayGolf} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t\\mathbf{P}(\\textbf{Outlook}=Sunny|\\textbf{PlayGolf}=Yes)         \\\\\n\t\\times\\mathbf{P}(\\textbf{Temprature}=Hot|\\textbf{PlayGolf}=Yes)  \\\\\n\t\\times\\mathbf{P}(\\textbf{Humidity}=Normal|\\textbf{PlayGolf}=Yes) \\\\\n\t\\times\\mathbf{P}(\\textbf{Windy}=False|\\textbf{PlayGolf}=Yes)     \\\\\n\t\\times\\mathbf{P}(\\textbf{PlayGolf}=Yes)                          \\\\\n\t                                                                 \\\\\n\t\\mathbf{P}(\\textbf{Outlook}=Sunny|\\textbf{PlayGolf}=No)          \\\\\n\t\\times\\mathbf{P}(\\textbf{Temprature}=Hot|\\textbf{PlayGolf}=No)   \\\\\n\t\\times\\mathbf{P}(\\textbf{Humidity}=Normal|\\textbf{PlayGolf}=No)  \\\\\n\t\\times\\mathbf{P}(\\textbf{Windy}=False|\\textbf{PlayGolf}=No)      \\\\\n\t\\times\\mathbf{P}(\\textbf{PlayGolf}=No)                           \\\\\n\t\\end{array}\n\t\\right.\n\\end{align*}\n\n\\begin{align*}\n\t\\mathbf{PlayGolf} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t3/9                                                     \\\\\n\t\\times2/9                                               \\\\\n\t\\times6/9                                               \\\\\n\t\\times6/9                                               \\\\\n\t\\times9/14                                              \\\\\n\t                                                        \\\\\n\t2/5                                                     \\\\\n\t\\times2/5                                               \\\\\n\t\\times1/5                                               \\\\\n\t\\times2/5                                               \\\\\n\t\\times5/14                                              \\\\\n\t\\end{array}\n\t\\right.\n\\end{align*}\n\n\\begin{align*}\n\t\\mathbf{PlayGolf} = \\operatorname*{argmax}_{y_k}\\left\\{\n\t\\begin{array}{ll}\n\t0.0212\n\t                                                        \\\\\n\t0.0046                                                  \\\\\n\t\\end{array}\n\t\\right.\n\\end{align*}\n\nTherefore, $\\textbf{PlayGolf}=Yes$ because $0.0212 > 0.0046$.\n\n\\section{Extensions}\n\n\\begin{itemize}\n\t\\item For a continuous input feature, assumption regarding the distribution needs to be made. Examples: \\textbf{Gaussian}, \\textbf{Multinomial} and \\textbf{Bernoulli}.\n\t\\item Smoothing may be required to prevent the multiplication from being zero when one probability term is zero.\n\\end{itemize}\n\n\\section{Comments}\n\\begin{itemize}\n\t\\item Due to independence assumption, naive Bayes' classifiers often perform good even with less training data.\n\t\\item Main applications include \\textbf{spam filtering} and \\textbf{document classification}.\n\t\\item Extremely fast in both training and prediction.\n\t\\item Often fail to produce a good estimate of the correct class probabilities but make the correct classification if the correct class is more probable than any other class.\n\\end{itemize}\n\\end{document}\n", "meta": {"hexsha": "53ef334153746ea3736797d61c49da0c261976c1", "size": 8230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Naive Bayes/Naive Bayes.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": "Naive Bayes/Naive Bayes.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": "Naive Bayes/Naive Bayes.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": 41.3567839196, "max_line_length": 180, "alphanum_fraction": 0.4465370595, "num_tokens": 2378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767746654974, "lm_q2_score": 0.8902942188450159, "lm_q1q2_score": 0.7812124996554631}}
{"text": "\\paragraph{\\underline{Hypothesis tests for goodness-of-fit}} \\hspace{0pt}\n\n\\vspace{10pt} \\noindent \\textbf{\\em Pearson chi-square test}\n$X$ i.i.d. $F=?$, $F_0$ is dist. of interest, $H_0: F=F_0$\n\n$d_i= \\frac{N_i - np_i}{\\sqrt{np_i}}$,\n$p_i = P_{F_0}(X \\in S_i) > 0$\n\n\\[ T = \\Sigma_{i=1}^r d_i^2 \\rightarrow_{n \\rightarrow \\infty} \\chi^2_{r-1-t} \\]\n\n\\vspace{10pt} \\noindent \\textbf{\\em Kolmogorov test} assumes that the sample comes from a continuous distribution.\n\n\\[ T = \\sup_{x \\in \\mathbb{R}}{ \\left| \\hat{F}_n(x) - F_0(x) \\right| } \\]\n\n\\[ T^+ = \\max_{i}{ \\left( \\frac{i}{n} - \\hat{F}_0(x_{i:n}) \\right) } \\]\n\n\\[ T^- = \\max_{i}{ \\left( \\hat{F}_0(x_{i:n}) - \\frac{i-1}{n} \\right) } \\]\n\nwhere $i \\in \\mathbb{N}$, $i \\in [1,n]$ and $x_{i:n}$ is the $i$th sample element taken from sorted sample\n\n\\[ T = \\max{ \\left\\{ T^+, T^- \\right\\} } \\]\n\n\\paragraph{\\underline{Hypothesis tests for normality}} \\hspace{0pt}\n\n\\vspace{10pt} \\noindent \\textbf{\\em Shapiro-Wilk test}\n\\begin{gather*}\nW = \\frac{ \\left( \\sum_{i=1}^{n} a_i x_{i:n} \\right)^2 }{ \\sum_{i=1}^{n} \\left( x_i - \\bar{x} \\right)^2 } \\\\\na_i = \\frac{m^T V^{-1}}{ \\sqrt{ m^T V^{-1} V^{-1} m } }\n\\end{gather*}\n\nwhere $m$ is a vector of expected values of sorted sample from $\\distnormal(0,1)$, and $V$ is a covariance matrix of $m$.\n\nNull hypothesis is rejected when $W$ is too small. This test is designed for small sample sizes, $n < 50$. \n\n\\paragraph{\\underline{Hypothesis tests for independence}} \\hspace{0pt}\n\n\\vspace{10pt} \\noindent \\textbf{\\em Wilcoxon signed-rank test}\n\\begin{gather*}\nW = \\frac{1}{2}\\Sigma_{i=1}^n \\bar{r}(Z_i)+\\frac{n(n + 1)}{4}\n\\end{gather*}\n", "meta": {"hexsha": "9edeffbabde82e93674c9ca094e0da2b7b074834", "size": 1620, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_7d_tests_nonparam_example.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_7d_tests_nonparam_example.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_7d_tests_nonparam_example.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.512195122, "max_line_length": 121, "alphanum_fraction": 0.6216049383, "num_tokens": 648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7812024381690791}}
{"text": "\\iffalse\nNoether's theorem says that continuous symmetries of physical systems gives rise to conservation laws. In this class we'll see some examples of low dimensional Lie groups and how they give rise to various phenomenon in physics like time dilation and length contraction in special relativity, spin states of electrons.\n\nKeywords: bilinear forms, signature, SO(2), SO(3), Spin, SO(1,3), Minkowski space and relativity, Noether's theorem, Lie groups.\n\nPrereqs: Linear algebra, Group theory\nHomework: Recommended\n\\fi\n\n\n\\input{../preamble}\n\n\\DeclareMathOperator{\\aut}{Aut}\n\n\\begin{document}\n\\title{Linear Groups}\n\\author{Apurva Nakade}\n\\thispagestyle{fancy}\n\\maketitle\n\n\n\nAny mathematical object naturally defines a group $\\aut(X)$, the group of \\textbf{automorphisms} or symmetries of $X$ which are maps $X \\rightarrow X$ preserving {some structure} on $X$. Our main examples for $X$ will be vector spaces over $\\R$ or $\\C$ (with  additional structures) in which case the automorphisms groups are called \\textbf{linear groups}. We'll make the structures successively more rigid thereby specializing to smaller and smaller linear groups.\n\n\n\n\n\n\n\\section*{Symmetries of $\\R^1$}\nSymmetries of $\\R^1$ are transformations $f: \\R^1 \\rightarrow \\R^1$ which preserve some structure. The simplest structure $\\R^1$ has is that of a set. The symmetries of $\\R^1$ thought of as a set are bijective maps $f: \\R^1 \\rightarrow \\R^1$. This group is too big and lacks any interesting structure. $\\R^1$ is also a topological space. Symmetries of the topological space $\\R^1$ are continuous maps $f:\\R^1 \\rightarrow \\R^1$ which are isomorphisms.\n\nFrom an algebraic point of view $\\R^1$ is a vector space over $\\R$. Symmetries of the vector space $\\R^1$ are linear transformations $f:\\R^1 \\rightarrow \\R^1$ which are isomorphisms. A linear transformation $f$ is simply multiplication by a scalar $c \\in \\R$ and such a transformation is an isomorphism if $c \\neq 0$. So the set of symmetries of the vector space $\\R^1$ is isomorphic to the group of non-zero reals $\\R^{\\times}$. This group is usually denoted by $GL_1(\\R)$.\n\nInside $\\R^{\\times}$ is the subgroup of positive reals $\\R _ {> 0}$. These are the orientation preserving transformations of $\\R^1$ (see Section \\ref{sec:orientation}). Another structure that $\\R^1$ has is that of distance. Multiplication by a scalar $c$ preserves distances iff $c = \\pm 1$, and the set $\\{ -1, +1 \\}$ is isomorphic to $\\Z/2$. Finally only the identity map preserves both the orientation and the inner product and so the corresponding automorphism group is trivial.\n\n\\begin{center}\n\t\\begin{tabular}{ll}\n\t\tStructures on $\\R^1$ & Automorphism Groups   \\\\\\hline\n\t\tSet                  & Bijections            \\\\\n\t\tTopological space    & Continuous bijections \\\\\n\t\tVector space         & $\\R^{\\times}$         \\\\\n\t\tOrientation          & $\\R_{>0}$             \\\\\n\t\tMetric               & $\\Z/2$                \\\\\n\t\tOrientation + Metric & trivial group\n\t\\end{tabular}\n\\end{center}\n\n\n\n\n\\section{General linear groups}\n\nDenote the set of $n \\times n$ matrices with entries in $\\R$ (resp. $\\C$) by $M_{n \\times n}(\\R)$ (resp. $M_{n \\times n}(\\C)$).\n\nFor the vector space $\\R^n$ the automorphism group is called the \\textbf{general linear group} $GL_n(\\R)$ i.e. $GL_n(\\R)$ is the group of invertible $n \\times n$ matrices with real entries. Consider an $n \\times n$ matrix $A \\in GL_n(\\R)$ and let $e_1, e_2, \\ldots , e_n$ be the columns of $A$. Because $M$ is invertible $e_1, e_2, \\ldots , e_n$ form a basis for $\\R^n$. Conversely any basis $e_1, e_2, \\ldots , e_n$ gives an $n \\times n$ invertible matrix.\n\\begin{align}\n\tGL_n(\\R)\n\t  & = \\{ n \\times n \\mbox{ invertible matrices with entries in } \\R \\}             \\\\\n\t  & = \\{ A \\in M_{n \\times n}(\\R) : \\det A \\neq 0\\}                                \\\\\n\t  & = \\{ (e_1 , e_2 , \\cdots , e_n) : (e_i)_{i=1}^n \\mbox{ is a basis for } \\R^n\\}\n\\end{align}\n\n\n\n\n\n\n\n\\section{Orientation}\n\\label{sec:orientation}\nThe determinant of an invertible matrix is non-zero. Further the determinant satisfies the property that for two $n\\times n$ matrices $A$, $B$ we have $\\det (AB) = \\det A \\cdot \\det B$. Hence we have a group homomorphism\n\\begin{align}\n\t\\det : GL_n(\\R) \\rightarrow \\R^{\\times}\n\\end{align}\nThe preimage of positive reals $\\R_{>0}$ under this map is denoted by $GL_n^+(\\R) := \\det^{-1}(\\R_{>0})$. It is easy to see that this is a subgroup of $GL_n(\\R)$. We can decompose $GL_n(\\R)$ into cosets\n\\begin{align}\n\tGL_n(\\R) = {\\det} ^{-1}(\\R_{>0}) \\sqcup {\\det} ^{-1}(\\R_{<0})\n\\end{align}\nThis breaks up the set of all bases of $\\R^n$ into two. These are called the \\textbf{orientation classes} of bases of $\\R^n$. The bases in the orientation class containing the standard basis are said to have the \\textbf{standard orientation} and the bases which are not in this orientation class are said to have the \\textbf{reverse orientation}.\n\nThe matrices in $GL_n^+(\\R)$ are called \\textbf{orientation preserving} matrices. In the language of automorphisms $GL_n^+(\\R)$ is the automorphism group of $\\R^n$ with a chosen orientation class.\n\n\n\n\n\n\n\n\\section{Special linear groups}\n\nSitting inside $GL_n(\\R)$ is the subgroup of $n\\times n$ matrices with determinant 1 denoted by $SL_n(\\R)$, called the \\textbf{special linear group}.\n\\begin{align}\n\tSL_n(\\R) = \\{ A \\in M_{n \\times n}(\\R) : \\det A = 1 \\}\n\\end{align}\nWe can realize $SL_n(\\R)$ as volume preserving automorphisms of $\\R^n$ i.e. if $A \\in SL_n(\\R)$ and $X$ is a subset of $\\R^n$ then the volume of $X$ is the same as the volume of $AX$. This is because if $X$ is a `parallelogram' in $\\R^n$ then the volume of $X$ is exactly the absolute value of the determinant of $X$, and any other shape can be approximated by `parallelograms'.\n\nThe converse is almost true. A volume preserving automorphism of $\\R^n$ should have determinant $\\pm 1$, hence $SL_n(\\R)$ is the group of automorphism of $\\R^n$ which preserve both {volume} and {orientation}.\n\n\n\n\n\n\n\n\n\\section{Orthogonal groups}\nOn $\\R^n$ we have the natural notion of distance and we can look at linear autmorphisms of $\\R^n$ which preserve distances. We know from Euclidean geometry that any transformation that preserves distances also preserves angles. Angles and lengths in $\\R^n$ can be measured using the dot product, this turns out to be the structure that is easiest to manipulate.\n\nDenote by $(\\cdot)$ the standard dot product between vectors in $\\R^n$ defined as: for $ x = [x_1, x_2, \\cdots, x_n]^T$ and $ y = [y_1, y_2, \\cdots, y_n]^T$ the dot product is\n\\begin{align}\n\tx \\cdot  y := \\sum \\limits _{i=1}^n x_i y_i =  x ^ T  y\n\\end{align}\nRecall that the length of the vectors is given by $\\norm{ x}^2 = { x.  x}$ and we can \\emph{define} the angle between the vectors $ x$ and $ y$ by $\\theta := \\cos^{-1}\\dfrac{ x \\cdot  y}{\\norm { x} \\norm{ y}}$. The group of linear transformations of $\\R^n$ which preserve the standard dot product is called the \\textbf{orthogonal group} denoted $O(n)$.\n\\begin{align}\n\tO(n) := \\{ A : \\R^n \\rightarrow \\R^n : \\innerp{A  x}{A  y} = \\innerp{ x}{ y} \\mbox{ for all }  x,  y \\in \\R^n\\}\n\\end{align}\n\nWe can simplify the condition $\\innerp{M  x}{A  y} = \\innerp{ x}{ y}$ as follows:\n\\begin{alignat}{4}\n\t  &   & \\innerp{M  x}{M  y}\n\t& = \\innerp{ x}{ y}   \\qquad \\qquad\\\\\n\t\\Longleftrightarrow \\qquad\n\t  &   &\n\t(A  x)^T (A  y)\n\t& =  x ^ T  y         \\qquad \\qquad\\\\\n\t\\Longleftrightarrow  \\qquad\n\t  &   &\n\tx ^ T A^T A y\n\t& =  x ^ T  y         \\qquad \\qquad\\\\\n\t\\Longleftrightarrow \\qquad\n\t  &   &\n\tx ^ T (A^T A- I_{n}) y\n\t& = 0 \\qquad \\qquad\n\\end{alignat}\nwhere $I _ {n}$ denotes the identity matrix of size $n \\times n$. For an orthogonal matrix $A$ we want this to be true for all $ x,  y \\in \\R^n$. This is equivalent to requiring $A^T A - I_{n} = 0$ (Exercise \\ref{thm:linAlgProb}) which gives an alternate definition of $O(n)$.\n\nFor an orthogonal matrix $A \\in O(n)$ if $e_1, e_2, \\cdots, e_n$ are the columns of $A$ then $e_i \\cdot e_j = 0$ if $i \\neq j$ and $e_i \\cdot e_i = 1$, such a basis is called an \\textbf{orthonormal basis} of $\\R^n$.\n\n\\begin{align}\n\tO(n)\n\t  & = \\{ A \\in M_{n \\times n}(\\R) : \\mbox{ for all } x, y \\in \\R^n \\mbox{ we have }\\innerp{x}{y} = \\innerp{Ax}{Ay}\t\\} \\\\\n\t  & = \\{ A \\in M_{n \\times n}(\\R) : A^T A = I_{n}\\}                                                                   \\\\\n\t  & = \\{ (e_1 , e_2 , \\cdots , e_n) : (e_i)_{i=1}^n \\mbox{ is an orthonormal basis for } \\R^n\\}\n\\end{align}\n\n\\subsection{Special orthogonal groups}\nThe intersection $O(n) \\cap GL_n^+(\\R)$ is called the \\textbf{special orthogonal group} denoted $SO(n)$, these are the matrices which preserve the standard inner product and orientation. As we'll see later for small positive integers $n$ the groups $SO(n)$ have nice descriptions.\n\n\n\n\n\n\n\n\\section{Complex matrix groups}\nEverything that we did above can be generalized for vector spaces over complex numbers. We have natural generalizations of the vector spaces $GL_n(\\C)$ and $SL_n(\\C)$.\n\nThe generalization of $O(n)$ on the other hand needs a little tweaking. On complex vector spaces instead of a regular inner product $(.)$ we have a \\textbf{hermitian inner product} defined by\n\\begin{align}\n\t\\innerp{ x}{ y} & = \\conj{x_1}{y_1} + \\conj{x_2}{y_2} + \\cdots + \\conj{x_n}{y_n}\n\\end{align}\nMatrices which preserve this structure are called \\textbf{unitary matrices} and the columns of these form an orthonormal basis under the hermitian inner product.\n\\begin{align}\n\tU(n)\n\t  & = \\{ A \\in M_{n \\times n}(\\C) : \\mbox{ for all } x, y \\in \\C^n \\mbox{ we have }\\innerp{x}{y} = \\innerp{Ax}{Ay}\t\\} \\\\\n\t  & = \\{ A \\in M_{n \\times n}(\\C) : A^* A = I_{n}\\}                                                                   \\\\\n\t  & = \\{ (e_1 , e_2 , \\cdots , e_n) : (e_i)_{i=1}^n \\mbox{ is an orthonormal basis for } \\C^n\\}\n\\end{align}\nwhere $A^*$ is the complex conjugate of transpose of $A$. There is also the \\textbf{special unitary group} $SU(n)$ defined to be the group of unitary matrices with determinant 1 (see \\ref{thm:detProb}).\n\nWe have a natural inclusion $\\R^n \\rightarrow \\C^n$ induced by $\\R \\subseteq \\C$. This induces a group homomorphism $\\Phi: GL_n(\\R) \\hookrightarrow GL_n(\\C)$. Furthermore the restriction of the standard hermitian bilinear on $\\C^n$ to $\\R^n$ is the standard inner product which implies that $\\Phi^{-1}(U(n)) \\cong O(n)$ and $\\Phi^{-1}(SU(n)) \\cong SO(n)$. There are also maps going in the other direction, see Exercise \\\\\n\n\n\n\nTo summarize we have the following hierarchy of matrices\n\\begin{align*}\n\t\\xymatrix{\n\tSO(n) \\ar@{^{(}->}[r] \\ar@{^{(}->}[dr] & SL(n) \\ar@{^{(}->}[r] & GL_n^+(\\R) \\ar@{^{(}->}[r] & GL_n(\\R) \\\\\n\t& O(n) \\ar@{^{(}->}[urr]\n\t}\n\t&&\n\t\\xymatrix{\n\tSU(n) \\ar@{^{(}->}[r] & U(n) \\ar@{^{(}->}[r] & GL_n(\\C)\n\t}\n\\end{align*}\n\n\n\n\n\n\n\n\n\n\n\n\\section{Exercises}\n\n\\begin{exercise}\n\t\\label{thm:linAlgProb}\n\tFor $A \\in M_{n \\times n}(\\R)$ show that if $ x^T A  y = 0$ for all vectors $ x,  y \\in \\R^n$ then $A = 0$.\n\\end{exercise}\n\n\\begin{exercise}\n\t\\label{thm:detProb}\n\tFind the images of $O(n)$, $SO(n)$, $GL_n(\\C)$, $U(n)$ under the determinant map.\n\\end{exercise}\n\n\\begin{exercise}\n\tDoes it make sense to define $GL_n^+(\\C)$?\n\\end{exercise}\n\n\\begin{exercise}\n\tIdentify the following quotients:\n\t\\begin{enumerate}\n\t\t\\item $GL_n(\\R)/GL_n^+(\\R)$\n\t\t\\item $GL_n(\\R)/SL_n(\\R)$\n\t\t\\item $GL^+_n(\\R)/SL_n(\\R)$\n\t\t\\item $O(n)/SO(n)$\n\t\t\\item $U(n)/SU(n)$\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tFind the possible eigenvalues for matrices in $O(n)$ and $U(n)$.\n\\end{exercise}\n\n\\begin{exercise}$\\:$\n\t\\begin{enumerate}\n\t\t\\item Because $\\C^n$ can be thought of as a vector space over $\\R$ of dimension $2n$ and every $\\C$ linear transformation is also $\\R$ linear, we can define a map $\\Psi:GL_{n}(\\C) \\rightarrow GL_{2n}(\\R)$. Explicitly describe the map $\\Psi$.\n\t\t\\item Is $\\Psi$ a group homomorphism?\n\t\t\\item Describe the map $\\Psi \\circ \\Phi$.\n\t\\end{enumerate}\n\n\\end{exercise}\n\n\\begin{exercise}\n\tIs $O(n)$ a normal subgroup of $GL_n(\\R)$? Read about the \\textbf{QR-decomposition} of matrices and identify the set $GL_n(\\R)/O(n)$. What structure(s) does this set have?\n\\end{exercise}\n\n\\begin{exercise}\n\t$M_{n \\times n}(\\R)$ is naturally isomorphic to $\\R^{(n^2)}$, similarly for $\\C$, so we can talk about connectedness of its subsets.\n\t\\begin{enumerate}\n\t\t\\item Show that $GL_n(\\R)$ and $O(n)$ are not connected.\n\t\t\\item Can you think of a way of showing that $GL_n^+(\\R)$, $SO(n)$ and $GL_n(\\C)$ are connected?\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\end{document}\n\n\n\n\\iffalse\n$SO(n)$ is precisely the kernel of the determinant map $\\det : O(n) \\rightarrow \\{ -1, +1\\}$ and so we have an isomorphism\n\\begin{align}\n\tO(n) / SO(n) \\cong \\Z/2\n\\end{align}\n\n\\raisebox{10pt}{\\dbend} We think of elements of $SO(n)$ as rotations of $\\R^n$ and the elements of the coset $O(n) \\setminus SO(n)$ as reflections of $\\R^n$. When $n>3$ these words do not agree with our standard notion of rotation as there are multiple axes around which rotations can occur independently.\n\\fi\n\n\n\n\\iffalse\nAs $\\det A^T = \\det A$ for orthogonal matrices $A \\in O(n)$ we get\n\\begin{align}\n\t(\\det A )^2 = \\det(A^2) & = \\det(A^T A) = \\det (I_n) = 1 \\\\\n\t\\implies \\qquad \\det A  & = \\pm 1\n\\end{align}\nThis is a very useful property and we will exploit this to understand elements of $O(n)$ later.\n\\fi\n", "meta": {"hexsha": "8cf692788b978ce79308ff043af2a00cf7031990", "size": 13258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "03 Symmetries of Spaces/01 Linear Groups.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": "03 Symmetries of Spaces/01 Linear Groups.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": "03 Symmetries of Spaces/01 Linear Groups.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": 48.2109090909, "max_line_length": 482, "alphanum_fraction": 0.6591491929, "num_tokens": 4256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.868826771143471, "lm_q1q2_score": 0.7811807160338496}}
{"text": "\\section{Stochastic Collocation with Gamma Distribution}\nAssociated external model: \\texttt{poly\\_scgpc\\_gamma.py}\n\nRecall that the \\textit{Gamma} distribution has the probability density function\n\\begin{align}\n  f(x) = \\frac{x^{\\alpha-1}e^{-x/\\beta}}{\\beta^\\alpha\\Gamma\\left(\\alpha\\right)}, \\alpha > 0, \\beta > 0\n\\end{align}\n\nThe following two polynomials are used to compute the analytic statistical moments:\n\\textit{Gamma} distribution:\n\\begin{align}\n  u_1(x, y) = x + y \\\\\n  u_2(x, y) = x^2 + y^2\n\\end{align}\nwhere $x$ and $y$ are two mutually independent \\textit{Gamma} variates, i.e.\n\\begin{align}\n  x \\thicksim \\Gamma\\left(\\alpha_{1},\\beta_{1}\\right) \\notag \\\\\n  y \\thicksim \\Gamma\\left(\\alpha_{2},\\beta_{2}\\right) \\notag\n\\end{align}\n\n\\subsection{Mean and Variance}\nThe first two statistical moments of $u_1(x,y)$ and $u_2{x,y}$ are:\n\\begin{align}\n  \\expv{u_1(x,y)} &= \\int_{0}^\\infty dxdyP\\left(x,y\\right)u_1\\left(x,y\\right), \\notag \\\\\n  &= \\int_{0}^\\infty dxdy \\Gamma\\left(\\alpha_{1},\\beta_{1}\\right) \\Gamma\\left(\\alpha_{2},\\beta_{2}\\right) u_1\\left(x,y\\right), \\notag \\\\\n  &= \\frac{\\alpha_{1}}{\\beta_{1}} + \\frac{\\alpha_{2}}{\\beta_{2}}\n\\end{align}\n\\begin{align}\n  \\expv{u_2(x,y)} &= \\int_{0}^\\infty dxdyP\\left(x,y\\right)u_2\\left(x,y\\right), \\notag \\\\\n  &= \\int_{0}^\\infty dxdy \\Gamma\\left(\\alpha_{1},\\beta_{1}\\right) \\Gamma\\left(\\alpha_{2},\\beta_{2}\\right) u_2\\left(x,y\\right), \\notag \\\\\n  &= \\frac{\\left(\\alpha_{1} + 1\\right)\\alpha_1}{\\beta_{1}^2} + \\frac{\\left(\\alpha_{2}+1\\right)\\alpha_2}{\\beta_{2}^2}\n\\end{align}\n\n\\begin{align}\n  \\text{var}[u_1(x,y)] &= \\int_{0}^\\infty dxdyP\\left(x,y\\right)\\left[u_1\\left(x,y\\right) - \\expv{u_1(x,y)}\\right]^2, \\notag \\\\\n  &= \\frac{\\alpha_{1}}{\\beta_{1}^2} + \\frac{\\alpha_{2}}{\\beta_{2}^2}\n\\end{align}\n\\begin{align}\n  \\text{var}[u_2(x,y)] &= \\int_{0}^\\infty dxdyP\\left(x,y\\right)\\left[u_2\\left(x,y\\right) - \\expv{u_2(x,y)}\\right]^2, \\notag \\\\\n  &= \\frac{\\left(4\\alpha_{1} + 6.0\\right)\\left(\\alpha_{1} + 1\\right)\\alpha_1}{\\beta_{1}^4} + \\frac{\\left(4\\alpha_{2} + 6.0\\right)\\left(\\alpha_{2}+1\\right)\\alpha_2}{\\beta_{2}^4}\n\\end{align}\n\n\\subsection{numeric values}\nSome numeric values for the mean and variance are listed below for given distributions:\n\\begin{align}\n  x \\thicksim \\Gamma\\left(11, 5\\right) \\notag \\\\\n  y \\thicksim \\Gamma\\left(2, 0.8\\right) \\notag\n\\end{align}\n\\begin{table}[h!]\n  \\centering\n  \\begin{tabular}{c|c|c}\n    $Function$ & mean & variance \\\\ \\hline\n    $u_1$ & 4.7    & 3.565 \\\\\n    $u_2$ & 14.655 & 215.638125 \\\\\n  \\end{tabular}\n\\end{table}\n\n\n", "meta": {"hexsha": "803d47d3d9a3017aa56986a599db15775829718f", "size": 2513, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/gamma_scgpc.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/gamma_scgpc.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/gamma_scgpc.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.593220339, "max_line_length": 176, "alphanum_fraction": 0.6486271389, "num_tokens": 1021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7810676902128886}}
{"text": "\\section{The Second Variation}\r\n\\subsection{The Legendre Condition}\r\nBy the Euler-Lagrange equation we can only find the stationary point(s) of a functional, but we do not know about whether they are a minimum, maximum or a saddle point.\r\nWhen we are in $\\mathbb R^n$, a (partial) solution to this problem is to look at the second (or higher) derivative, which inspires us to consider higher order variations.\\\\\r\nConsider the functional\r\n$$F[y]=\\int_\\alpha^\\beta f(x,y,y^\\prime)\\,\\mathrm dx$$\r\nWe now want to expand further to the second order term of $\\epsilon$, that is, for $\\eta$ such that $\\eta(\\alpha)=\\eta(\\beta)=0$ and $y$ a stationary point of $F$,\r\n$$F[y+\\epsilon\\eta]-F[y]=\\frac{\\epsilon^2}{2}\\int_\\alpha^\\beta\\left( \\eta^2\\frac{\\partial^2f}{\\partial y^2}+(\\eta^\\prime)^2\\frac{\\partial^2f}{\\partial(y^\\prime)^2}+2\\eta\\eta^\\prime\\frac{\\partial^2f}{\\partial y\\partial y^\\prime} \\right)\\,\\mathrm dx+O(\\epsilon^3)$$\r\nThe integrand (as a functional on $\\eta$) is called the second variation:\r\n$$\\delta^2 F[y](\\eta)=\\frac{1}{2}\\int_\\alpha^\\beta\\left( \\eta^2\\frac{\\partial^2f}{\\partial y^2}+(\\eta^\\prime)^2\\frac{\\partial^2f}{\\partial(y^\\prime)^2}+2\\eta\\eta^\\prime\\frac{\\partial^2f}{\\partial y\\partial y^\\prime} \\right)\\,\\mathrm dx$$\r\nBy a simple integration by part argument on the last term and using the boundary condition on $\\eta$, we can further simplify the expression to get\r\n$$\\delta^2F[y](\\eta)=\\frac{1}{2}\\int_\\alpha^\\beta(Q\\eta^2+P(\\eta^\\prime)^2)\\,\\mathrm dx,Q=\\frac{\\partial^2f}{\\partial y^2}-\\frac{\\mathrm d}{\\mathrm dx}\\left( \\frac{\\partial^2 f}{\\partial y\\partial y^\\prime}\\right),P=\\frac{\\partial^2f}{\\partial (y^\\prime)^2}$$\r\nThe way we got the expression of $\\delta^2F[y]$ then hinted that $y$ being a minimiser relates greatly to $\\delta^2F[y]$ being positive.\r\n\\begin{proposition}\r\n    If $y$ is a solution to the Euler-Lagrange equation of $F$ and $Q\\eta^2+P(\\eta^\\prime)^2>0$ for any nonzero (sufficiently smooth) function $\\eta$ that vanishes at $\\alpha,\\beta$, then $y$ is a local minimiser of $F$.\r\n\\end{proposition}\r\n\\begin{example}\r\n    For the geodesics on the plane, we already know that the solutions to the Euler-Lagrange equation are striaght line segments.\r\n    We have $f=\\sqrt{1+(y^\\prime)^2}$, so\r\n    $$P=\\frac{\\partial}{\\partial y^\\prime}\\left( \\frac{y^\\prime}{\\sqrt{1+(y^\\prime)^2}} \\right)=\\frac{1}{(1+(y^\\prime)^2)^{3/2}},Q=0$$\r\n    But then $P$ is always positive and $\\eta^\\prime$ is nonzero since $\\eta$ is nonconstant (if it is constant then it is zero by the boundary condition), so by the preceding proposition any stationary point of it is a local minimiser.\r\n\\end{example}\r\nAn analogous computation proves a similar result for geodesics on the sphere.\r\n\\begin{proposition}\r\n    If $y_0(x)$ is a local minimum, then\r\n    $$P=\\left.\\frac{\\partial^2 f}{\\partial (y^\\prime)^2}\\right|_{y_0}=0$$\r\n\\end{proposition}\r\nThis is known as the Legendre condition.\r\nWe will sketch a proof of it.\r\n\\begin{proof}[Sketch of proof]\r\n    Assume there is some $x_0$ such that $P(x_0,y_0,y_0^\\prime)<0$.\r\n    We can easily constuct a function $\\eta$ such that $|\\eta|<\\epsilon$ for some small $\\epsilon>0$ but $\\eta$ fluctuates so rapid around $x_0$ such that $|\\eta^\\prime|$ is big around $x_0$, then the $Q\\eta^2$ term would contribute very little to the integral but $P(\\eta^\\prime)^2$ contributes a more significant and positive value, which shall yield a contradiction.\r\n\\end{proof}\r\nNote that the Legendre condition is only necessary but not sufficient.\r\nAn obvious sufficient condition is $P>0,Q\\ge 0$ at $y_0$.\r\n\\begin{example}[The Brachistochrone Problem]\r\n    We have\r\n    $$f=\\sqrt{\\frac{1+(y^\\prime)^2}{-y}}$$\r\n    Which we already know has the cycloid as a stationary point.\r\n    To see it is actually a minimiser, we compute\r\n    $$P=\\frac{1}{(1+(y^\\prime)^2)^{3/2}\\sqrt{-y}}>0,Q=\\frac{1}{2\\sqrt{1+(y^\\prime)^2}y^2\\sqrt{-y}}>0$$\r\n    so the cycloid is indeed a local minimiser.\r\n\\end{example}\r\n\\subsection{Associated Eigenvalue Problem}\r\nRewrite the integrand of the second variation in the form\r\n$$Q\\eta^2+P(\\eta^\\prime)^2=Q\\eta^2+\\frac{\\mathrm d}{\\mathrm dx}(P\\eta\\eta^\\prime)-\\eta\\frac{\\mathrm d}{\\mathrm dx}(P\\eta^\\prime)$$\r\nIntegrating by part again yields another formula for the second variation.\r\n$$\\delta^2F[y](\\eta)=\\frac{1}{2}\\int_\\alpha^\\beta\\eta\\left( -\\frac{\\mathrm d}{\\mathrm dx}(P\\eta^\\prime)+ Q\\eta\\right)\\,\\mathrm dx$$\r\nBut the thing in the bracket is precisely the Sturm-Liouville operator $\\mathcal L$ in Example \\ref{sturm-liouville} with $\\rho=P$ and $\\sigma=Q$ applied to $\\eta$.\r\nSo if $\\mathcal L(\\eta)=-\\omega^2\\eta$ for some $\\eta$ satisfying the boundary conditions and $\\omega\\in\\mathbb R$, then $\\delta^2F[y_0]<0$ if $\\eta$ is not constantly zero, therefore $y_0$ is not a minimiser.\r\nObserve here that $\\mathcal L$ can have nonpositive eigenvalues (as shown in the example below) even if $P>0$, so this would mean that the Legendre condition is not sufficient.\r\n\\begin{example}\r\n    Consider the functional\r\n    $$F[y]=\\int_0^\\beta((y^\\prime)^2-y^2)\\,\\mathrm dx$$\r\n    subject to the initial conditions $y(0)=y(\\beta)=0$ and $\\beta$ is not an integer multiple of $\\pi$.\r\n    The Euler-Lagrange equation transforms to $y^{\\prime\\prime}+y=0$, which solves to $y\\equiv 0$ due to our initial condition.\r\n    Now\r\n    $$\\delta^2F[0](\\eta)=\\frac{1}{2}\\int_0^\\beta((\\eta^\\prime)^2-\\eta^2)\\,\\mathrm dx$$\r\n    So $P=1>0$, so the Legendre condition is satisfied but the corresponding Sturm-Liouville operator is $\\mathcal L(\\eta)=-\\eta^{\\prime\\prime}-\\eta$.\r\n    But if $\\beta>\\pi$, then there is a solution $\\omega$ satisfying the condition $(\\pi/\\beta)^2=1-\\omega^2$, which makes the function $\\eta(x)=\\sin(\\pi x/\\beta)$ satisfy $\\mathcal L(\\eta)=-\\omega^2\\eta$, hence $0$ is not a local minimiser even if it satisfies the Legendre condition.\r\n\\end{example}\r\nThe example shows that $P>0$ alone may not guarantee local minimisation when the interval $[\\alpha,\\beta]$ is ``too large''.\r\nWe will make it precise in a moment.\r\n\\subsection{The Jacobi Condition}\r\nLegendre tried and failed to prove that $P>0$ is also a sufficient condition for a local minimiser -- which is because it is not, as seen in the last example.\r\nJacobi, on the other hand, improved upon Legendre's idea.\r\nAssuming that the Legendre condition holds, then let $\\phi=\\phi(x)$ be any differentiable function on $[\\alpha,\\beta]$, then\r\n$$0=\\int_\\alpha^\\beta (\\phi\\eta^2)^\\prime\\,\\mathrm dx=\\int_\\alpha^\\beta(\\phi^\\prime\\eta^2+2\\eta\\eta^\\prime\\phi)\\,\\mathrm dx$$\r\nSo we can modify the expression of the second variation by\r\n$$\\delta^2F[y](\\eta)=\\frac{1}{2}\\int_\\alpha^\\beta(P(\\eta^\\prime)^2+2\\phi\\eta\\eta^\\prime+(Q+\\phi^\\prime)\\eta^2)\\,\\mathrm dx$$\r\nCompleting the square,\r\n$$\\delta^2F[y](\\eta)=\\frac{1}{2}\\int_\\alpha^\\beta \\left( P\\left( \\eta^\\prime+\\frac{\\phi}{P}\\eta \\right)^2 +\\left( Q+\\phi^\\prime-\\frac{\\phi^2}{P} \\right)\\eta^2\\right)\\,\\mathrm dx$$\r\nHence, if we can find a solution $\\phi$ to the differential equation $\\phi^2=P(Q+\\phi^\\prime)$, then the positivity of the integrand is proved, hence we have a local minimum.\r\nThis ODE is called the Ricatti equation.\\\\\r\nWe can transform the Ricatti equation into a linear second-order ODE by setting $\\phi=-Pu^\\prime/u$ for some $u$ nonzero anywhere on $[\\alpha,\\beta]$, so\r\n$$-(Pu^\\prime)^\\prime+Qu=0$$\r\nthis is called the Jacobi accessory equation.\r\nBut this is exactly the kernel problem of $\\mathcal L$ with the restriction that the solution vanishes nowhere on $[\\alpha,\\beta]$.", "meta": {"hexsha": "806afd508410039c8459191515301befe7b54195", "size": 7474, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/second.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "7/second.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "7/second.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.8205128205, "max_line_length": 370, "alphanum_fraction": 0.6978860048, "num_tokens": 2311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8918110540642805, "lm_q1q2_score": 0.7810365288311478}}
{"text": "\\documentclass[notitlepage]{simple}\n\n\\usepackage{float}\n\n\\author{Matt McCarthy}\n\\title{Euler's Formula and the Complex Unit Circle}\n\\date{March 2016}\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\nWe want to show the following.\n\n\\begin{thm*}\n\tLet $x\\in\\RR$ and $i$ be the positive root of $x^2+1$.\n\tThen $e^{ix} = \\cos x + i \\sin x$.\n\\end{thm*}\n\n\\begin{thm*}\n\tThe set $U = \\set{z\\in\\CC | |z|=1}$ forms a group under complex multiplication.\n\\end{thm*}\n\n\\section{Complex Numbers}\n\nWe begin by defining the complex numbers.\n\n\\begin{definition}\n\tThe set of \\textit{complex numbers} is the set $\\CC=\\set{a+bi|a,b\\in\\RR}$ where $i^2=-1$.\n\tComplex addition is defined component wise, that is $(a+bi)+(c+di)=(a+c)+(b+d)i$ and complex multiplication is defined as\n\t\\[\n\t\t(a+bi)(c+di) = (ac -bd) + (ad + bc)i.\n\t\\]\n\\end{definition}\n\nSuppose $z\\in\\CC$, then there exist $a,b\\in\\RR$ such that $z=a+bi$.\nWe can plot this on a plane as follows.\n\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\\end{figure}\n\nWhen we plot it, we get a triangle with vertices $0,a,z$.\nIf we consider the line $az$, we see that it is parallel to the $iy$ axis, which is in turn perpendicular to the $x$ axis.\nThus, $\\triangle 0az$ is right and $r=\\sqrt{a^2+b^2}$ by Pythagorean theorem.\nWe also define $|z|=\\sqrt{a^2+b^2}$, or the Euclidean distance between $z$ and $0$.\n\nFurthermore, consider the angle $\\theta$.\nIf we use the change of variables $a=r\\cos\\theta$ and $b=r\\sin\\theta$, we get that $\\theta = \\arctan(b/a)$.\nThus, we can write $z=a+bi$ as $r(\\cos\\theta+i\\sin\\theta)$, which gives us a polar representation of $z$.\nMoreover, we call $r$ the \\textit{modulus} of $z$ and $\\theta$ the \\textit{argument} of $z$; note that both the modulus and argument are real numbers.\n\n\\section{Euler's Formula}\n\nIn the 1740's Leonhard Euler noted that\n\\[\n\te^{ix}=\\cos x + i\\sin x.\n\\]\nWe provide a proof of that.\n\\begin{thm}\n\tLet $x\\in\\RR$ and $i$ be the positive root of $x^2+1$.\n\tThen $e^{ix} = \\cos x + i \\sin x$.\n\\end{thm}\n\\begin{proof}\n\tWe know $e^{ix}$ is a complex number thus, $e^{ix}=r\\cdot(\\cos \\theta+ i\\sin \\theta)$, where $r=r(x)$ and $\\theta = \\theta(x)$.\n\tTherefore\n\t\\[\n\t\t\\frac{d}{dx} e^{ix} = \\frac{d}{dx}\\paren{r\\cdot\\paren{\\cos \\theta+ i\\sin \\theta}}\n\t\\]\n\tand\n\t\\[\n\t\t-r\\sin\\theta + ir\\cos\\theta =\n\t\tie^{ix} =\n\t\t\\paren{\\cos \\theta+ i\\sin \\theta}\\frac{dr}{dx} + r\\cdot\\paren{-\\sin \\theta+ i\\cos \\theta}\\frac{d\\theta}{dx}.\n\t\\]\n\tThus, when we match real and imaginary parts, we get the following linear system of equations.\n\t\\begin{align*}\n\t\t\\cos \\theta\\frac{dr}{dx} - r\\sin\\theta\\frac{d\\theta}{dx} &= -r\\sin\\theta\\\\\n\t\t\\sin \\theta\\frac{dr}{dx} + r\\cos\\theta\\frac{d\\theta}{dx} &=  r\\cos\\theta\n\t\\end{align*}\n\tSolving the system yields the differential equations $dr/dx = 0$ and $d\\theta/dx = 1$.\n\n\tConsider $e^{i0}$.\n\t\\[\n\t\tr(0)(\\cos(\\theta(0))+ i\\sin(\\theta(0)))=e^{i0}=1=1(\\cos 0 + i\\sin 0)\n\t\\]\n\tMatching terms gives us, $r(0)=1$ and $\\theta(0)=0$.\n\tWhen combined with our differential equations, this yields the following initial value problems.\n\t\\[\n\t\t\\begin{cases}\n\t\t\t\\frac{dr}{dx}=0\\\\\n\t\t\tr(0)=1\n\t\t\\end{cases}\n\t\t\\hspace{4em}\n\t\t\\begin{cases}\n\t\t\t\\frac{d\\theta}{dx}=1\\\\\n\t\t\t\\theta(0)=0\n\t\t\\end{cases}\n\t\\]\n\tThe solutions to these initial value problems are $r(x)=1$ and $\\theta(x)=x$ respectively.\n\tThus,\n\t\\[\n\t\te^{ix}=\\cos x + i\\sin x.\n\t\\]\n\\end{proof}\n\nWe can quickly extend this result to any complex number.\n\n\\begin{corollary}\n\tFor any $z\\in\\CC$, $z=re^{i\\theta}$ where $\\theta=\\arg z$ and $r=|z|$.\n\\end{corollary}\n\\begin{proof}\n\tSince $z\\in\\CC$, $z=r(\\cos \\theta + i\\sin \\theta)$ where $\\theta = \\arg z$ and $r=|z|$.\n\tThus by Euler's formula,\n\t\\[\n\t\tz=r(\\cos \\theta + i\\sin \\theta) = re^{i\\theta}.\n\t\\]\n\\end{proof}\n\n\\section{The Unit Circle}\n\nConsider $e^{i\\theta}$ where $\\theta$ is real.\nWe know that $\\abs{e^{i\\theta}}=1$ by the corollary to Euler's formula.\nThus $e^{i\\theta}$ lies on the unit circle of the complex plane.\n\\begin{definition}\n\tThe unit circle of the complex plane is the subset of $\\CC$ whose elements all have a modulus of one.\n\t\\[\n\t\tU = \\set{z\\in\\CC | |z|=1}.\n\t\\]\n\\end{definition}\nConversely, all points on the unit circle also have the form $e^{i\\theta}$ for some $\\theta\\in[0,2\\pi)$.\n\nOur goal is to show that $U$ is a group under complex multiplication, but before we do so, let us consider $\\CC$.\nMost notably, $\\CC$ is a field, which implies that $\\CC\\setminus\\set{0}$ is an abelian group under complex multiplication.\nThus, in order to show that $(U,\\cdot)$ forms a group, it is sufficient to show that $U$ is a \\textit{subgroup} of $\\CC\\setminus\\set{0}$.\nIn short, a subset of a group is a subgroup if it is also a group under the group operation in its own right.\nAdditionally, we have a quick test to determine whether or not a subset is a subgroup.\n\n\\begin{proposition}[One step test]\n\tLet $(G,*)$ be a group and $H$ a non empty subset of $G$.\n\tThen $H$ is a subgroup of $G$ if for all $a,b\\in H$,\n\t\\[\n\t\ta*b^{-1}\\in H.\n\t\\]\n\\end{proposition}\n\nWith the Euler's formula and the one step subgroup test in our toolbox, we are now ready to show that $U$ is a group.\n\n\\begin{thm}\n\tThe set $U = \\set{z\\in\\CC | |z|=1}$ forms a group under complex multiplication.\n\\end{thm}\n\\begin{proof}\n\tWe know that $|1|=1$, therefore $1\\in U$ and $U$ is nonempty.\n\tFurthermore, $U\\subset\\CC\\setminus\\set{0}$ by definition of $U$.\n\n\tProceed via one step subgroup test.\n\tLet $z,w\\in U$.\n\tTherefore $|z|=|w|=1$ and $z=e^{i\\theta}$ and $w=e^{i\\phi}$ where $\\theta,\\phi\\in\\RR$ by corollary to Euler's formula.\n\n\tConsider $zw^{-1}$.\n\t\\[\n\t\tzw^{-1} = e^{i\\theta}e^{-i\\phi} = e^{i\\theta - i\\phi} = e^{i(\\theta -\\phi)}\n\t\\]\n\tWe know that for any $x\\in\\RR$, $|e^{ix}|=1$ therefore $|zw^{-1}|=|e^{i(\\theta - \\phi)}|=1$ and $zw^{-1}\\in U$.\n\tThus, $U$ is a subgroup of $\\CC\\setminus\\set{0}$ under multiplication by the one step subgroup test.\n\tTherefore $(U,\\cdot)$ is a group.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "4e0425da4c40f1ce24abf00a3716300885351c5e", "size": 7708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-spring/eulers-formula-unit-circle/eulers-formula-unit-circle.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/eulers-formula-unit-circle/eulers-formula-unit-circle.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/eulers-formula-unit-circle/eulers-formula-unit-circle.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": 37.0576923077, "max_line_length": 166, "alphanum_fraction": 0.651141671, "num_tokens": 2960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379298, "lm_q2_score": 0.8757870046160257, "lm_q1q2_score": 0.7810365241675709}}
{"text": "\\subsection{Translation}\r\n\\noindent\r\nLet $a$ be a constant.\r\n\\begin{equation*}\r\n\t\\Laplace{e^{at}f(t)} = \\int_{0}^{\\infty}{e^{at}f(t)e^{-st} \\mathrm{d}t} = \\int_{0}^{\\infty}{f(t)e^{-(s-a)t} \\mathrm{d}t} = \\mathcal{L}\\left\\{f(t)\\right\\}\\left(s-a\\right)\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{e^{at}f(t)} = \\mathcal{L}\\left\\{f(t)\\right\\}\\left(s-a\\right)\r\n\\end{equation*}\r\nThis illustrates how multiplying by $e^{at}$ in the $t$ domain corresponds to a translation by $a$ in the $s$ domain.", "meta": {"hexsha": "9418061336ce704a2b6e70b7893ac910734e119e", "size": 499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/translation.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/laplaceTransforms/derivations/translation.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/laplaceTransforms/derivations/translation.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.3636363636, "max_line_length": 171, "alphanum_fraction": 0.629258517, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7807970278632347}}
{"text": "\\lab{Algorithms}{Optimization}{Optimization Package 2}\n\\label{lab:Optimization 2}\n\\objective{Introduce some of the basic optimization functions available in the cvxopt package}\n\n\nYou can learn about more about cvxopt at  \n\n\\url{http://abel.ee.ucla.edu/cvxopt/documentation/}.\n\n\n\n\\section*{Linear Programs}\n\nCvxopt has linear program solver and can implement integer programming through the Gnu Linear Programming Kit, glpk.\n\n\n\n\nConsider the following transportation problem:\nA piano company needs to transport thirteen pianos from their three  supply centers (1,2, and 3) to two demand centers (4 and 5). Transporting a piano from a supply center to a demand center incurs a cost, listed in the table below. The company want to minimize shipping costs for the pianos. How many pianos should each supply center send each demand center?\n\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\\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\\end{table}\n\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\\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\n\\begin{align}\np +& q  &    &    &    &   &=& 7\\\\\n   &    & r +& s  &    &   &=& 2\\\\\n   &    &    &    & t +& u &=& 4\\\\\np +&    & r +&    & t  &   &=& 5\\\\\n   & q +&    & s +&    & u &=& 8\\\\\n\\end{align}\n\nThe objective function is the number of pianos shipped from each location multiplied by the cost.\n\n\\begin{center}\n$4p + 7q + 6r + 8s + 8t + 9u$\n\\end{center}\n\nWe can solve this program using cvxopt, which uses the notation\n\n\\begin{lstlisting}[mathescape]\nmin $c^Tx$\nsubject to $Gx +s = h$\n\t   $Ax    = b$\n\t   $s     \\geq 0$\n\\end{lstlisting}\n\nCvxopt also solves the dual problem\n\n\\begin{lstlisting}[mathescape]\nmin $-h^Tz - b^Ty$\nsubject to $G^Tz +A^Ty + c = 0$\n\t   $z     \\geq 0$\n\\end{lstlisting}\n\nAll entries must be floats, and each array must be converted to a matrix type, unique to cvxopt. Numpy arrays can be converted to matrix by\n\n\\begin{lstlisting}\n>>> a = numpy.array([[11,2],[2,5]])\n>>> A = matrix(a)\n\\end{lstlisting}\n\nThere a several ways to solve the linear program. \n\n\n\n\\section*{Example}\nHere, $G$ and $h$ constrain the variables to be non-negative. The entries are negative because cvxopt uses the format $Gx \\leq h$. $A$ and $b$ represent the supply and demand constraints. Cvxopt.solvers returns a dictionary with a lot of information, including slack, iterations, dual and primal information. All we really care about right now are the values of $x$ and the objective value.\n\n\\begin{lstlisting}\n: from cvxopt import matrix, solvers\n: c = matrix([4., 7., 6., 8., 8., 9])\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: 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: print sol['x']\n: print sol['primal objective']\n\\end{lstlisting}\n\n\\textbf{Problem 1}\n\nRun the example. What happens?\n\n\nWe can fix the problem by including the supply demand constraints in the $G$ matrix.\n\n\\section*{Example}\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. Cvxopt is configured to work with  Gnu, which does have an integer linear program. It will work with either of the methods above. \n\n\\textbf{Example}\n\nglpk.ilp returns a tuple. The 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\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\n\\textbf{Problem 3}\nCreate the dual problem for the linear program and solve. \nCompare your answer to the dual value cvxopt returned. \n\n\\section*{Programmming}\n\nThe quadratic programming setup is similar to the linear programming. However, it does not have to be constrained. $G, h, A$, and $b$ are optional\n\n\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\n\n\\section*{Example}\nFind the minimum of \n\\begin{equation}\nf(x,y) = 2x^2 +2xy + y^2 +x -y\n\\end{equation}\n\\begin{lstlisting}\n: Q = matrix([ [4., 2.], [2., 2.] ])\n: p = matrix([1., -1.])\n: G = matrix([[1., 0.], [0., -1.]])\n: h = matrix([0.,0.])\n: sol=solvers.qp(Q, p, G, h)\n: print(sol['x'])\n: print sol['primal objective']\n\\end{lstlisting}\n\n\n\n\\textbf{Problem 4}\nFind the minimizer and minimum of \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 & 0 & 1\\\\\n0 & 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", "meta": {"hexsha": "844b7ce7a41f2edec38f2f959e8d9bf8c910dc47", "size": 7519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/OptimizationPackage2/Optimize2.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/OptimizationPackage2/Optimize2.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/OptimizationPackage2/Optimize2.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": 28.3735849057, "max_line_length": 390, "alphanum_fraction": 0.5510041229, "num_tokens": 2872, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.9184802507195636, "lm_q1q2_score": 0.7806817489941412}}
{"text": "\\section{The natural numbers}\n\nThe archetypal example of an inductive type is the type $\\N$ of \\emph{natural numbers}.\nThe type of \\define{natural numbers}\\index{natural numbers|see N@{$\\N$}} is defined to be a closed type $\\nat$\\index{N@{$\\N$}} equipped with closed terms for a \\define{zero term}\\index{zero term} $\\zeroN:\\N$ and a \\define{successor function}\\index{successor function!of N@{of $\\N$}}\\index{function!successor on N@{successor on $\\N$}} $\\succN:\\N\\to\\N$.\n\nThe rules we postulate for the type of natural numbers again come in four sets:\n\\begin{enumerate}\n\\item The formation rule, which asserts that the type $\\N$ can be formed.\n\\item The introduction rules, which provide the zero element and the successor function.\n\\item The elimination rule. This rule is the type theoretic analogue of the induction principle for $\\N$.\n\\item The computation rules, which assert that any application of the elimination rule behaves as expected on the constructors $\\zeroN$ and $\\succN$ of $\\N$.\n\\end{enumerate}\n\\begin{rmk}\n  We annotate the terms $\\zeroN$ and $\\succN$ of type $\\N$ with their type in the subscript, as a reminder that $\\zeroN$ and $\\succN$ are declared to be terms of type $\\N$, and not of any other type. In the next chapter we will introduce the type $\\Z$ of the integers, on which we can also define a zero term $\\zeroZ$, and a successor function $\\succZ$. These should be distinguished from the terms $\\zeroN$ and $\\succN$. In general, we will make sure that every term is given a unique name. In libraries of mathematics formalized in a computer proof assistant it is also the case that every type must be given a unique name.\n\\end{rmk}\n\n\\subsection{The formal specification of the type of natural numbers}\n\\subsubsection{The formation rule of $\\N$}\nThe type $\\N$ is formed by the $\\N$-formation rule\n\\begin{prooftree}\n  \\AxiomC{}\n  \\RightLabel{$\\N$-form}\n  \\UnaryInfC{$\\vdash \\N~\\mathrm{type}$.}\n\\end{prooftree}\n\n\\subsubsection{The introduction rules of $\\N$}\nThe introduction rules for $\\N$ introduce the zero term and the successor function\n\n\\bigskip\n\\begin{minipage}{.45\\textwidth}\n  \\begin{prooftree}\n    \\AxiomC{}\n    \\UnaryInfC{$\\vdash \\zeroN:\\N$}\n  \\end{prooftree}\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n  \\begin{prooftree}\n    \\AxiomC{}\n    \\UnaryInfC{$\\vdash \\succN:\\N\\to\\N$}\n  \\end{prooftree}\n\\end{minipage}\n\n\\subsubsection{The elimination rule of $\\N$}\nTo prove properties about the natural numbers, we postulate an \\emph{induction principle}\\index{induction principle!of N@{of $\\N$}} for $\\N$. In dependent type theory, however, the induction principle for the natural numbers provides a way to construct \\emph{dependent functions} of types depending on the natural numbers.\n\nThe induction principle for $\\N$ states what one has to do in order to construct a dependent function of type $\\prd{n:\\N}P(n)$, for any given type family $P$ over $\\N$. Just like for the usual induction principle of the natural numbers, there are two things to be constructed: first one has to construct $p_0:P(\\zeroN)$, and the second task is to construct a function of type $P(n)\\to P(\\succN(n))$ for all $n:\\N$. \n\nTherefore the induction principle for $\\N$ is as follows:\n\\begin{prooftree}\n  \\def\\fCenter{\\Gamma}\n  \\Axiom$\\fCenter, n:\\N\\vdash P(n)~\\mathrm{type}$\n  \\noLine\n  \\UnaryInf$\\fCenter\\ \\vdash p_0:P(\\zeroN)$\n  \\noLine\n  \\UnaryInf$\\fCenter\\ \\vdash p_S:\\prd{n:\\N}P(n)\\to P(\\succN(n))$\n  \\RightLabel{$\\N{-}\\mathrm{Ind}$}\n  \\UnaryInf$\\fCenter\\ \\vdash \\ind{\\N}(p_0,p_S):\\prd{n:\\N} P(n)$\n\\end{prooftree}\n\n\\begin{rmk}\n  The induction principle of $\\N$ might also be formulated as an inference rule\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma,n:\\N\\vdash P(n)~\\mathrm{type}$}\n    \\UnaryInfC{$\\Gamma\\vdash \\mathsf{ind}_{\\N} : P(\\zeroN)\\to \\Big(\\Big(\\prd{n:\\N}P(n)\\to P(\\succN(n))\\Big)\\to \\prd{n:\\N}P(n)\\Big)$}\n  \\end{prooftree}\n  To see that indeed we get such a function from the induction principle, we note that the induction principle is stated to hold in an \\emph{arbitrary} context $\\Gamma$. In particular, by weakening and the variable rule we have the following well-formed terms:\n  \\begin{align*}\n    \\Gamma,~p_0:P(\\zeroN),~p_S:\\prd{n:\\N}P(n)\\to P(\\succN(n)) & \\vdash p_0 : P(\\zeroN) \\\\\n    \\Gamma,~p_0:P(\\zeroN),~p_S:\\prd{n:\\N}P(n)\\to P(\\succN(n)) & \\vdash p_S : \\prd{n:\\N}P(n)\\to P(\\succN(n)).\n  \\end{align*}\n  Therefore, the induction principle of $\\N$ provides us with a term\n  \\begin{equation*}\n    \\Gamma,~p_0:P(\\zeroN),~p_S:\\prd{n:\\N}P(n)\\to P(\\succN(n)) \\vdash \\mathsf{ind}_\\N(p_0,p_S) : \\prd{n:\\N}P(n).\n  \\end{equation*}\n  By $\\lambda$-abstraction we now obtain a function\n  \\begin{equation*}\n    \\mathsf{ind}_\\N : P(\\zeroN)\\to \\Big(\\Big(\\prd{n:\\N}P(n)\\to P(\\succN(n))\\Big) \\to \\prd{n:\\N}P(n)\\Big)\n  \\end{equation*}\n  in context $\\Gamma$. Therefore we see that it does not really matter whether we present the induction principle of $\\N$ in a more verbose way as an inference rule with the base case and the inductive step as hypotheses, or as a function taking variables for the base case and the inductive step as arguments.\n\\end{rmk}\n\n\\subsubsection{The computation rules of $\\N$}\nFurthermore we require that the dependent function $\\ind{\\N}(P,p_0,p_S)$ behaves as expected when it is applied to $\\zeroN$ or a successor, i.e., with the same hypotheses as for the induction principle we postulate the \\define{computation rules}\\index{computation rules!of N@{of $\\N$}} for $\\N$\n\\begin{prooftree}\n    \\def\\fCenter{\\Gamma}\n  \\Axiom$\\fCenter, n:\\N\\vdash P(n)~\\mathrm{type}$\n  \\noLine\n  \\UnaryInf$\\fCenter\\ \\vdash p_0:P(\\zeroN)$\n  \\noLine\n  \\UnaryInf$\\fCenter\\ \\vdash p_S:\\prd{n:\\N}P(n)\\to P(\\succN(n))$\n  \\RightLabel{$\\N{-}\\mathrm{Ind}$}\n  \\UnaryInf$\\fCenter\\ \\vdash \\ind{\\N}(p_0,p_S,\\zeroN)\\jdeq p_0 : P(\\zeroN)$\n\\end{prooftree}\nand similarly, with the same hypotheses as for the computation rule for the base case,\n\\begin{prooftree}\n\\AxiomC{$\\cdots$}\n%\\RightLabel{$\\N{-}\\mathrm{Comp}(\\succN)$}\n\\UnaryInfC{$\\Gamma, n:\\N \\vdash  \\ind{\\N}(p_0,p_S,\\succN(n))\\jdeq p_S(n,\\ind{\\N}(p_0,p_S,n)) : P(\\succN(n))$}\n\\end{prooftree}\nThis completes the formal specification of $\\N$.\n\n\\subsection{Addition on the natural numbers}\nUsing the induction principle of $\\N$ we can perform many familiar constructions. \nFor instance, we can define the \\define{addition operation}\\index{addition!on N@{on $\\N$}}\\index{function!addition on N@{addition on $\\N$}} by induction on $\\N$.\n\n\\begin{defn}\n  We define a function\n  \\begin{equation*}\n    \\addN:\\N\\to (\\N\\to\\N)\n  \\end{equation*}\n  satisfying $\\addN(\\zeroN,n)\\jdeq n$ and $\\addN(\\succN(m),n)\\jdeq\\succN(\\addN(m,n))$. Usually we will write $n+m$ for $\\addN(n,m)$.\n\\end{defn}\n\n\\begin{proof}[Informal construction]\nInformally, the definition of addition is as follows. By induction it suffices to construct a function $\\mathsf{add\\usc{}}\\zeroN : \\N\\to\\N$, and a function\n\\begin{align*}\n\\mathsf{add\\usc{}}\\succN(n,f):\\N\\to\\N,\n\\end{align*}\nfor every $n:\\N$ and every $f:\\N\\to\\N$.\n\nThe function $\\mathsf{add\\usc{}}\\zeroN:\\N\\to\\N$ is of course taken to be $\\idfunc[\\N]$, since the result of adding $0$ to $n$ should be $n$.\n\nGiven $n:\\N$ and a function $f:\\N\\to\\N$ we define $\\mathsf{add\\usc{}}\\succN(n,f)\\defeq \\succN\\circ f$. The idea is that if $f$ represents adding $m$, then $\\mathsf{add\\usc{}}\\succN(n,f)$ should be adding one more than $f$ did.\n\\end{proof}\n\n\\begin{proof}[Formal derivation]\nThe derivation for the construction of $\\mathsf{add\\usc{}}\\succN$ looks as follows:\n\\begin{prooftree}\n  \\AxiomC{}\n  \\UnaryInfC{$\\succN:\\N^\\N$}\n  \\AxiomC{}\n  \\UnaryInfC{$\\vdash\\N~\\mathrm{type}$}\n  \\AxiomC{}\n  \\UnaryInfC{$\\vdash\\N~\\mathrm{type}$}\n  \\AxiomC{}\n  \\UnaryInfC{$\\vdash\\N~\\mathrm{type}$}\n  \\TrinaryInfC{$\\vdash \\mathsf{comp}:\\N^\\N\\to (\\N^\\N\\to \\N^\\N)$}\n  \\UnaryInfC{$g:\\N\\to\\N\\vdash \\mathsf{comp}(g):\\N^\\N\\to\\N^\\N$}\n  \\BinaryInfC{$\\vdash \\mathsf{comp}(\\succN):\\N^\\N\\to\\N^\\N$}\n  \\UnaryInfC{$n:\\N\\vdash \\mathsf{comp}(\\succN):\\N^\\N\\to\\N^\\N$}\n  \\UnaryInfC{$\\vdash \\mathsf{add\\usc{}}\\succN\\defeq \\lam{n}\\mathsf{comp}(\\succN):\\N\\to (\\N^\\N \\to \\N^\\N)$}\n%\\BinaryInfC{$\\vdash\\addN:\\ind{\\N}(add_0,add_S):\\N\\to \\N^\\N$}\n\\end{prooftree}\nWe combine this derivation with the induction principle of $\\N$ to complete the construction of addition:\n\\begin{prooftree}\n  \\AxiomC{$\\vdots$}\n  \\UnaryInfC{$n:\\N\\vdash \\N^\\N~\\mathrm{type}$}\n  \\AxiomC{$\\vdots$}\n  \\UnaryInfC{$\\vdash \\mathsf{add\\usc{}}\\zeroN\\defeq \\idfunc[\\N]:\\N^\\N$}\n  \\AxiomC{$\\vdots$}\n  \\UnaryInfC{$\\vdash \\mathsf{add\\usc{}}\\succN:\\N\\to (\\N^\\N \\to \\N^\\N)$}\n  \\TrinaryInfC{$\\vdash\\addN\\jdeq\\ind{\\N}(\\mathsf{add\\usc{}}\\zeroN,\\mathsf{add\\usc{}}\\succN):\\N\\to \\N^\\N$}\n\\end{prooftree}\nThe asserted judgmental equalities then hold by the computation rules for $\\N$.\n\\end{proof}\n\n\\begin{rmk}\n  When we define a function $f:\\prd{n:\\N} P(n)$, we will often do so just by indicating its definition on $\\zeroN$ and its definition on $\\succN(n)$, by writing\n  \\begin{align*}\n    f(\\zeroN) & \\defeq p_0 \\\\\n    f(\\succN(n)) & \\defeq p_S(n,f(n)).\n  \\end{align*}\n  For example, the definition of addition on the natural numbers could be given as\n  \\begin{align*}\n    \\addN(\\zeroN,n) & \\defeq n \\\\\n    \\addN(\\succN(m),n) & \\defeq \\succN(\\addN(m,n)).\n  \\end{align*}\n  This way of defining a function is called \\emph{pattern matching}. A more formal inductive argument can be obtained from a definition by pattern matching if it is possible to obtain from the expression $p_S(n,f(n))$ a general dependent function\n  \\begin{equation*}\n    p_S : \\prd{n:\\N} P(n)\\to P(\\succN(n)).\n  \\end{equation*}\n  In practice this is usually the case. Computer proof assistants such as Agda have sofisticated algorithms to allow for definitions by pattern matching.\n\\end{rmk}\n\n\\begin{rmk}\nThe rules that we provided so far are not sufficient to also conclude that $n+\\zeroN\\jdeq n$ and $n+ \\succN(m)\\jdeq \\succN(n+m)$. However, once we have introduced the \\emph{identity type} in \\cref{chap:identity} we will nevertheless be able to \\emph{identify} $n+\\zeroN$ with $n$, and $n+ \\succN(m)$ with $\\succN(n+m)$. See \\cref{ex:semi-ring-laws-N}. \n\\end{rmk}\n\n\\begin{exercises}\n  \\item Define the binary \\define{min} and \\define{max} functions $\\min_\\N,\\max_\\N:\\N\\to(\\N\\to\\N)$.\\index{minimum function}\\index{maximum function}\\index{function!min}\\index{function!max}\n  \\item Define the \\define{multiplication}\\index{multiplication!on N@{on $\\N$}}\\index{function!multiplication on N@{multiplication on $\\N$}} operation $\\mathsf{mul}_\\N :\\N\\to(\\N\\to\\N)$.\n  \\item Define the \\define{power}\\index{power function on N@{power function on $\\N$}}\\index{function!power function on N@{power function on $\\N$}} operation $n,m\\mapsto m^n$ of type $\\N\\to (\\N\\to \\N)$.\n  \\item Define the \\define{factorial}\\index{factorial function}\\index{function!factorial function} function $n\\mapsto n!$.\n  \\item Define the \\define{binomial coefficient}\\index{binomial coefficients} $\\binom{n}{k}$ for any $n,k:\\N$, making sure that $\\binom{n}{k}\\jdeq 0$ when $n<k$.\n  \\item Define the \\define{Fibonacci sequence}\\index{Fibonacci sequence} $0,1,1,2,3,5,8,13,\\ldots$ as a function $F:\\N\\to\\N$.\n\\end{exercises}\n", "meta": {"hexsha": "cacdd55ddd9d98b62cb838e109b0b3af9fc95d47", "size": 11046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/nat.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/nat.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/nat.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": 59.0695187166, "max_line_length": 625, "alphanum_fraction": 0.6964512041, "num_tokens": 3751, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7806817402676667}}
{"text": "\\section{Complex networks}\n\nGraph theory is a well established area of mathematics. More recently, other areas from physics to economics, sociology to ecology have found that the structures and properties of graphs give a powerful and practical method of representing systems of interest to them. This new focus on what might have been called applied graph theory is what is now mostly know as network science. One of the interesting aspects of network science is that it deals with structures that are non-regular (not lattice-like) but also not purely random. These heterogeneous patterns of connections have implications for the study of complex systems (systems of entities with non-trivial sets of typically non-linear interactions) and hence networks often get referred to as complex networks. The Complex part of the name is really a bit redundant, but it sounds good and is commonly used, so we'll stick with it.\n\n\\subsection{An introduction to graph theory \\& networks}\n\nA network or \\emph{graph} is a collection of \\emph{vertices} (nodes) $V=\\{v_i\\}$ and \\emph{edges} (links) $E=\\{e_{ij}\\}$ which we denote $G= G(V,E)$.\n\nIf we consider the edge $e_{ij}$, between vertices $v_i$ and $v_j$ to be distinct from $e_{ji}$ then we say that the edge is \\emph{directed}. A graph is directed if all its edges are directed. A \\emph{simple graph} is a network (possibly directed) where there is a unique (directed) edge between connected pairs of nodes. A \\emph{multigraph} allows for the possibility of multiple edges edges between the same nodes. We will mostly only consider simple graphs, though much of what we'll present also holds for multigraphs, with a slight adjustment. \n\nThe \\emph{density} of a graph is the number of edges present in the graph divided by the number of possible edges. For an undirected simple graph with $|V|=n$ nodes, the density is given by\n$$\n\t\\rho = \\frac{|E|}{\\frac12 n(n-1)},\n$$\nwhere $|E|$ is the number of edges and where the factor of $\\frac12$ comes from the fact that the edges are undirected so $e_{ij}=e_{ji}$. \n\nThe \\emph{degree} of a node in a network, often denoted $k$ or $k_i$ for the degree of node $i$ is the number of edges that connect to that node. In the case of a directed network we have both \\emph{in-degree} and \\emph{out-degree}, the number of incoming and outgoing links, respectively.\n\nThe \\emph{component} of a graph to which a vertex belongs is the set of vertices that can be reached from it by paths running along the edges of the graph. A node in a directed graph has both an \\emph{in-component} and an \\emph{out-component} corresponding to the nodes that it can be reached from and the nodes that can be reached from it. A graph need not consist of only a single component, though some properties are ambiguously defined when it does not.\n\nThe \\emph{geodesic path} between a pair of nodes is the shortest path through the network that connects them. The shortest path need not be unique and for a directed network the shortest path can differ depending on direction.\nIt is sometimes interesting to look at the \\emph{average shortest path} for a graph. That is the average over all possible shortest paths in the graph, computed for each pair of nodes. \n\nThe notation $e_{ij}$ for the edges of a network suggests that we can represent a network as a matrix. If we let the rows and columns of the matrix represent the vertices of the network, then the non-zero entries of the matrix represent edges between pairs of vertices. We call such a network the \\emph{adjacency matrix} of the graph. The values of the non-zero entries can be used to denote \\emph{edge weights} of a \\emph{weighted graph}.\n\nMany real-world networks consist of nodes of different types, with connection only between nodes of certain types. The simplest example of this is a \\emph{bipartite network} (also known as a \\emph{two-mode network}): a network of two types of vertices $V=\\{v_i\\}$ and $U=\\{u_j\\}$ where the edges only connect nodes of type $v$ to nodes of type $u$. For example, a publication network where $V$ represents authors and $U$ their publications.  (More generally, the two node types are often referred to as agents and artifacts.) Edges link authors to their publications but not publications to publications, nor authors to authors. In order to obtain a co-authorship network from this publication network it would be necessary to calculate the \\emph{unipartite} or \\emph{one-mode projection} of the bipartite network.\n\n\n\\subsection{Real-world networks: some examples}\n\n{\\bf Social networks:} \n\nA social network is a set of people or groups with some pattern of contacts or interactions between them. They include such diverse examples as friendship networks of dolphins and interactions between characters in works of fiction, through to more traditional networks such as friendships between individuals, either in real life, or on Facebook, employment networks, and business relationships between companies.\n\nSome of these networks, like the business relationships are best viewed as undirected networks, while others, like real-life friendship networks are directed. Friendship networks lend their name to an interesting feature of networks: the so called \\emph{friendship paradox} which states that your friends will typically have more friends than you do. This arises from the fact that like many other real-world networks, friendship networks have a heavy-tailed degree distribution so picking a random node and following an edge from it is likely to lead you to a node with higher degree than the starting node.\n\n\\emph{Contact networks} are one important example of social networks. These are networks of when people are in close enough proximity to allow for a disease to spread between them. (Close enough obviously depends on the type of disease.) Contact networks play an important role in modeling of disease contagion --- for example the recent Ebola outbreak in West Africa was successfully modeled using contact networks and this played an important role in managing the epidemic.\n\n\n\n{\\bf Information networks:}\n\nThese could equally be called knowledge networks. Examples include the publication networks mentioned earlier (bipartite, undirected), citation networks (directed) whether as citations of publications or of patents, and the World Wide Web (directed). (Note --- the WWW should not be confused with the internet; one is a collection of electronic documents that can link to one another, the other is a collection of computers and switches connected by cables.) Preference networks are another example of information networks that are often used in real-world applications. Examples include networks of people linked to their Netflix viewings, or their Amazon purchases. Identifying patterns in such networks and predicting likely new links is a highly active area of both academic and commercial interest.\n\n\n{\\bf Technological \\& infrastructure networks:} \n\nThese are networks with physical links between nodes. Examples include the internet (undirected); electricity grids (partly directed) perhaps also including the computers that control the grid; road, rail, shipping, or air transport networks; and electronic circuits. \n\n\n{\\bf Biological networks:} \n\nThese networks span multiple scales, from networks of interactions between proteins and their metabolites, or genes and proteins (both directed) that are used amongst other things, in the study of disease through to networks of interactions between species. The latter includes food webs (directed) and mutualistic networks like pollination networks (bipartite, directed). Neural networks are another example that is an active area of study; the complete neural network (282 neurons) is known for the nematode C. Elegans. Studying bigger brains, however, requires bigger brains. Though not entirely biological, I'll include in this class a couple of examples of physical networks. These are networks linking free energy minima of glasses via the saddle points on the energy surface that they sit on and networks linking confirmations of polymers when they can transition between a pair of structures. \n\n\n\\subsection{Properties of networks}\n\n{\\bf Small world effect:}\n\nOne of the best know network properties is the \\emph{small world effect}. This gets it name from a famous experiment in the 1960s by the sociologist Stanley Milgram. In the experiment, letters were passed from person to person until they reached a designated target person. Milgram found that it took on average only about six hops for the letters to reach their destination leading to the so called \\emph{six degrees of separation} phenomenon. This small world effect is an example of how particular network structures can provide short paths through the network connecting most pairs of nodes. \n\nThe mean geodesic path length for an undirected network is given by\n$$\n\tL =\\frac{1}{\\frac12 n(n-1)}\\sum_{i\\geq j} d_{ij}\n$$\nwhere $d_{ij}$ is the geodesic distance between $v_i$ and $v_j$. In the case of disconnected networks, one must make a choice about how to count the contribution of pairs of nodes that are not connected. The Facebook friendship network is one of the best examples of a small world network. Despite having around 1 billion nodes and 100 billion links (i.e. a mean degree of 100) the mean geodesic distance for the Facebook network is only around four.\n\n{\\bf Transitivity/clustering:}\n\nIn mathematics, a set with a relationship $\\sim$ is transitive if $a \\sim b,~b\\sim c \\implies a \\sim c$. In the context of networks the relationship means \"is connected to\". If a network is entirely transitive, then it would consist of totally connected components. More interesting is to measure how close a network is to being transitive by looking at how much clustering it has.\n\nThe \\emph{global clustering coefficient} for a network is defined as\n$$\n\tC=\\frac{3\\times\\text{\\# of triangles}}{\\text{\\# number of connected triples}}\n$$\nwhere a connected triple is a vertex with connections to two other vertices.\n\nIt is sometime interesting to look at how the clustery-ness of a network varies over the network, perhaps to study how clustering depends on some node property. To look at this, we use the \\emph{local clustering coefficient} for a vertex $v_i$:\n$$\n\tC_i = \\frac{\\text{\\# triangle connected to }v_i}{\\text{\\# triples centered on }v_i}.\n$$\nClearly, $C = \\frac{1}{N}\\sum_{i=1}^NC_i$.\n\nNow that we've defined the clustering coefficient, we can look a little closer at the small world property.\nIf we start with a completely regular network (figure \\ref{fig1}a) where each node has the same degree $k$ and is connected to its $k$ nearest neighbours we will have a high clustering coefficient, but a relatively long mena geodesic path. If we start to introduce random re-wirings of the network, with probability $p$, by either switching an end of an existing edge (figure \\ref{fig1}b) or by introducing new random links (figure \\ref{fig1}c), then we find that the mean geodesic path length drops quickly, while the mean clustering coefficient remains close to its original value as the re-wiring probability $p$ increases --- see figure \\ref{fig2}. This means that while the long-range connections rapidly reduce the \\emph{global} mean path geodesic length, any change to the \\emph{local} structure is barely perceptible.\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width = 12cm]{regularNW.png}\n\t\\end{center}\n\t\\caption{}\n\t\\label{fig1}\n\\end{figure}\n\n\\begin{figure}\n\t\\begin{center}\n\t\t\\includegraphics[width = 8cm]{smallWorld.png}\n\t\\end{center}\n\t\\caption{Mean geodesic path length (solid line) and mean clustering coefficient (dashed line) as a function of the rewiring probability $p$, and measured relative to their maximum value, i.e. with no re-wiring.}\n\t\\label{fig2}\n\\end{figure}\n\n\n{\\bf Degree distribution:}\n\nThe degree $k$ of a vertex is the number of edges that connect to that vertex. We write $p_k$ for the fraction of nodes in a network that have degree $k$, this is also the probability that a randomly selected node has degree $k$. One of the interesting properties of real-world networks is the degree distribution --- the histogram of $p_k$ as a function of $k$. For a network with uniformly random connections between nodes, the degree distribution is Poisson. This is not the case for most real-world networks --- these tend to have degree distributions that are highly right-skewed. In particular, many real-world networks tend to have a \\emph{heavy-tail} --- a probability distribution that has a non-negligible probability of getting values much greater than the mean. In fact, the mean (and higher order moments like the variance) may not even be well defined for all heavy-tailed distributions.  Of particular interest is the case where the degree distribution is a \\emph{power-law} or \\emph{scale-free}. That is\n$$\n p_k \\sim k^{-\\gamma}.\n$$\n\nSuch degree distributions show up surprisingly often in real world networks: the WWW, the internet, metabolic networks, telephone call networks, and sexual contact networks. Power law degree distributions also arise from one of the most popular models for generating networks --- we'll see more on this later.\n\nAn alternative (i.e. non-power-law) distribution that is still heavy-tailed is the \\emph{exponential distribution}\n$$\n\tp_k\\sim\\exp(-k/\\kappa).\n$$\n\nPower-law and exponential distributions are easily identified in data: they give a straight line on log-log and semi-log axes, respectively.\n\nThe probability generating functions that we introduced at the start of the course give a useful way of calculating network properties from their degree distributions. For example, if $G_0(x) = \\sum_{k=0}^\\infty p_kx^k$ is the PGF for the degree distribution of a network, then the first moment of the PGF gives the average degree, $\\langle k \\rangle$, of the network, according to\n$$\n\tG_{0}'(x) = \\sum_{k}kp_{k}x^{k-1},\n$$\nand\n$$\n\tG_{0}'(1) = \\sum_{k}kp_{k} = \\langle k \\rangle.\n$$\t\n\nAnother important property is the degree distribution of first neighbours. The reasoning is as follows: by selecting a link at random, and following it until reaching a node, we will find that the node has, let's say, degree $k$. The probability with which we will reach such a node is proportional to its degree ($\\propto kp_{k}$). The normalized distribution is given by\n$$\n\t\\dfrac{\\sum kp_{k}x^{k}}{\\sum_{k}kp_{k}} = x \\dfrac{\\sum kp_{k}x^{k-1}}{\\langle k \\rangle} = \\dfrac{x}{\\langle k \\rangle}G_{0}'(x).\n$$\n\nThen, by following each one of the $k$ edges of a randomly chosen node of degree $k$, we have the distribution of the remaining outgoing edges of the $k$ first neighbours of that node generated by the function \n$$\n\tG_{1}(x) = \\dfrac{\\sum_{k}kp_{k}(k)x^{k-1}}{\\langle k \\rangle} = \\dfrac{1}{\\langle k \\rangle}G_{0}'(x)\n$$\nNote that because we are following the edges of a randomly chosen node, the distribution of the remaining edges of the first neighbours do not count the edge by which we arrived at that neighbour. That is why we get rid of one power of $x$ in the equation for $G_{1}(x)$.\n\nFrom that, it is not hard to find a new PGF for the number of second neighbours of nodes in a network. \n$$\\sum_k p_k (G_1(x))^k $$ \nwhere \n$$G_1(x) = \\frac{G_{0}'(x)}{G_{0}'(1)}$$ \nThis, in turn, is close to the PGF for the degree distribution of the projection of a bipartite network, since the second neighbours of a bipartite network are the neighbours of its projection.\n\n\\subsection{Network growth models}\nIt is one thing to be able to produce a network, fully formed, with a particular set of properties. It is quite another to prescribe a process that is able to grow, or generate, a network with those same properties.\n\nOne popular generative network model is the \\emph{preferential attachment plus growth model} (PAGP model), also known as the Barabasi and Albert or BA model.\n\nAs the name suggests, at each time step, the PAPG model adds a node with degree $m$. Each of the edges of the new node attaches itself to a node in the existing network with a probability that is proportionate to the degree of the existing nodes. The edges in this model are undirected and once and edge is attached to a node, there is no re-wiring. It isn't too hard to prove that the PAPG model generates graphs with a power law degree distribution with $p_k \\sim k^{-3}$. The fact that the power law exponent is fixed is unfortunate, though generalisation of the PAPG model allow for different exponents. It is also not hard to see that the PAPG model only produces connected graphs. This limits its applicability to some real world networks. Even though the PAPG model manages to grow networks that reproduce some real-world features (the power-law degree distribution), it does so in a way that may not match up with the growth processes of those real-world networks. For example the highest degree nodes of the PAPG model are the oldest nodes --- this is not the case with networks such as the WWW to which the PAPG model might be applied.\n\n\n\\subsection{Exponential random graph models}\nGiven a particular empirical network one often wants to create models of networks with similar observable properties. These observables might be any of the properties mention so far (or many others) such as mean clustering or a particular degree distribution. One approach is to consider the empirical network as one example of a network from an ensemble of networks that have been generated by the same underlying model. Exponential random graph models (ERGMs) provide a way to study the properties of such models by employing methods that come directly from the statistical mechanics that we have seen so far.\n\nConsider a set $\\mathcal{G}$ of graphs and a collection of observables $\\{X_i\\},~~i=1,2,\\ldots,r$ for which we have measured expected values $\\langle X_i\\rangle$. It will often turn out that we only have a single measurement of these values. (Here we'll assume that the graphs in $\\mathcal{G}$ are simple graphs, but the same approach works for many other possibilities.) Given a specific graph $G\\in\\mathcal{G}$ we want $P(G)$ the probability of finding that graph to be commensurate with the expected values of each of the graph observables $\\{X_i\\}$. Just like for statistical  mechanics, this is an under-determined problem: the number of degrees of freedom for the definition of $P(G)$ is much smaller than the number of constraints from the observables. However, as we know from statistical mechanics, the best approach is to pick the solution that maximises the Gibbs entropy\n$$\n\tS= -\\sum_{G\\in\\mathcal{G}}P(G)\\ln P(G),\n$$\nsubject to the constraints\n$$\n\t\\sum_G P(G)X_i(G) = \\langle X_i\\rangle\n$$\nand the normalization condition\n$$\n\t\\sum_G P(G) =1.\n$$\n\nTo do this, we introduce the Lagrange multipliers $\\alpha$ and $\\theta_i$ and solve\n$$\n\t\\frac{\\partial}{\\partial P(G)}\\left[S + \\alpha \\left(1-\\sum_G P(G)\\right) + \\sum_i \\theta_i \\left(\\langle X_i \\rangle - \\sum_G P(G)X_i(G)\\right) \\right] = 0\n$$\nfor all graphs $G$.\n\nThis gives\n$$\n\t\\ln P(G) +1 +\\alpha +\\sum_i\\theta_iX_i(G) = 0.\n$$\n\nWe can rearrange this to get\n$$\n\tP(G) = \\frac{\\exp(-H(G))}{Z},\n$$\nwhere $H(G) = \\sum_i\\theta_iX_i(G)$ is known as the graph Hamiltonian and $Z = \\exp(\\alpha+1)$ is the partition function. The requirement that $Z$ be a normalising factor requires that $\\exp(\\alpha+1) = \\exp(-H(G))$.\n\n\n\\subsection{Recommended reading}\nThere are several good books on complex networks, including \\emph{Lectures on Complex Networks} by S.N. Dorogovtsev and \\emph{The Structure of Complex Networks} by E. Estrada, but some of the best content is in the form of journal survey articles. My picks are the two by M.E.J. Newman: \\emph{The Structure and Function of Complex Networks} and, joint with J. Park \\emph{Statistical Mechanics of Networks}. I used both of these extensively in writing this section. Also good is \\emph{Statistical Mechanics of Complex Networks} by R. Albert and A.-L. Barabasi. For a good survey of generative models for power law distributions, see the survey article by Mitzenmacher.\n\n", "meta": {"hexsha": "ac67c94143de09bc474907fff9738fb77b27f251", "size": 20059, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "09-complexNetworks.tex", "max_stars_repo_name": "dvasques83/708Notes2018", "max_stars_repo_head_hexsha": "98db7cf5060553a9f2ba1d92d3e9fe79e9e902b1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "09-complexNetworks.tex", "max_issues_repo_name": "dvasques83/708Notes2018", "max_issues_repo_head_hexsha": "98db7cf5060553a9f2ba1d92d3e9fe79e9e902b1", "max_issues_repo_licenses": ["MIT"], "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-complexNetworks.tex", "max_forks_repo_name": "dvasques83/708Notes2018", "max_forks_repo_head_hexsha": "98db7cf5060553a9f2ba1d92d3e9fe79e9e902b1", "max_forks_repo_licenses": ["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.0209424084, "max_line_length": 1145, "alphanum_fraction": 0.7743656214, "num_tokens": 4720, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.7806817312384836}}
{"text": "\\lesson{3}{Sep 14 2021 Tue (16:54:18)}{Solving Radical Equations}{Unit 1}\n\n\\begin{definition}[Radical Equations]\n    Here is what a \\textbf{Radical Equation} looks like:\n\n    \\[ T = 2\\pi\\sqrt{\\frac{L}{32}} .\\]\n\\end{definition}\n\n\\begin{example}[Radical Equations 1]\n    Let's solve $\\sqrt{(5x + 4)} = 7$:\n  \n    \\begin{align}\n        \\sqrt{(5x + 4)} &= 7 \\\\\n                        &= (\\sqrt{5x + 4})^2 = (7)^2 \\\\\n                        &= 5x + 4 = 49 \\\\\n                        &= 5x = 45 \\\\\n                        &= \\frac{5x}{5} = \\frac{45}{5} \\\\\n                        &= x = 9\n    \\end{align}\n    \n    Now, let's check our work:\n\n    \\begin{align}\n        \\sqrt{5x + 4} &= 7 \\\\\n                      &= \\sqrt{5(9) + 4} = 7 \\\\\n                      &= \\sqrt{45 + 4} = 7 \\\\\n                      &= \\sqrt{49} = 7 \\\\\n                      &= 7 = 7\n    \\end{align}\n\\end{example}\n\nLet's try another one:\n\n\\begin{example}[Radical Equations 2]\n    Let's solve $\\sqrt{x - 3} + 4 = 1$:\n\n    \\begin{align}\n        \\sqrt{x - 3} + 4 &= 1 \\\\\n                         &= \\sqrt{x - 3} = -3 \\\\\n                         &= (\\sqrt{x - 3})^2 = (-3)^2 \\\\\n                         &= x - 3 = 9 \\\\\n                         &= x = 12\n    \\end{align}\n\n    Now, let's check our work:\n\n    \\begin{align}\n        \\sqrt{x - 3} + 4 &= 1 \\\\\n                         &= \\sqrt{12 - 3} + 4 = 1 \\\\\n                         &= \\sqrt{9} + 4 = 1 \\\\\n                         &= 3 + 4 = 1 \\\\\n                         &= 7 \\neq 1\n    \\end{align}\n\n    We call this situation extraneous solution.\n\\end{example}\n\n\\subsubsection*{Quick Review of Factoring}\n\nLet's look at factoring by group.\n\nFirst, you want the split the middle term into factors of $15$ that combine to equal $2$.\n\nThen, just factor by $GCF$.\n\n\\begin{align}\n    x^2 + 2x - 15 &= x^2 - 3x + 5x - 15 \\\\\n                  &= (x^2 - 3x) + (5x - 15) \\\\\n                  &= x(x - 3) + 5(x - 3) \\\\\n                  &= (x + 5)(x - 3)\n\\end{align}\n\n\\newpage\n", "meta": {"hexsha": "305ff95cdf60d547e9a9afc9dd42a8555d0ce69b", "size": 1982, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-1/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-1/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-1/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": 26.7837837838, "max_line_length": 89, "alphanum_fraction": 0.3890010091, "num_tokens": 653, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7805448464630499}}
{"text": "\\section{Projective Geometry}\n\\subsection{Coordinates}\n\\subsubsection{Crossproduct}\n$$ \\bm{\\tilde{x}_1} \\times \\bm{\\tilde{x}_2} = [\\bm{\\tilde{x}_1}]_\\times \\bm{\\tilde{x}_2} =\n\\begin{bmatrix}\n0&z&-y\\\\\n-z&0&x\\\\\ny&-x&0\\\\\n\\end{bmatrix} \\bm{\\tilde{x}_2} $$\n\\subsubsection{2D, 3D points}\n\\textit{For 2D a small letter is used, a capital letter for 3D, a bold letter stands for a vector, while a normal one is a single entry from a vector}\\\\\n\n\\textbf{Inhomogeneous coordinates} (marked with plain letter):\n$$ \\bm{x} = (x,y)^\\top \\qquad \\bm{X} = (x,y,z)^\\top$$\n\n\\textbf{Homogeneous coordinates} (with a tilde on top):\n$$ \\tilde{\\bm{x}} = (x,y,w)^\\top \\qquad \\tilde{\\bm{X}} = (x,y,z,w)^\\top$$\n\nalso called \" augmented coordinates $\\bar{x}$ \" when $w = 1$.\\\\\n\nScale is not important for incidence relation.\\\\\n\n\\textbf{Ideal point / point at infinity}:\n$$\\tilde{\\bm{x}} = (x,y,0)^\\top \\qquad \\tilde{\\bm{X}} = (x,y,z,0)^\\top$$\n\n\\textbf{Intersection of two lines}:\n$$ \\tilde{\\bm{x}} = \\bm{\\tilde{l}_1} \\times \\bm{\\tilde{l}_2} $$\n\n3D Point form three planes:\n$$ \\begin{bmatrix}\n\\pi^{(1)\\top}\\\\\n\\pi^{(2)\\top}\\\\\n\\pi^{(3)\\top}\\\\\n\\end{bmatrix} \\tilde{\\bm{X}} = 0 $$\n\n\\subsubsection{2D lines}\n\n$$ \\bm{l} = (a,b,c) $$\n\nThe point x lies on the line l if and only if\n$$ \\bm{l}^\\top\\tilde{\\bm{x}} = ax+by+c=0$$\n\nLine at infinity:\n$$\\bm{l}_\\infty = (0,0,1)^\\top$$\n\nHorizontal and vertical lines:\n\n\\includegraphics[width=0.8\\columnwidth]{pictures/verticalhorizontal}\n\n\\textbf{Line joining two points}:\n$$ \\bm{l} = \\bm{\\tilde{x}_1} \\times \\bm{\\tilde{x}_2} $$\n\n\\subsubsection{3D Planes}\n\n$$ \\pi = (\\pi_1,\\pi_2,\\pi_3,\\pi_4)^\\top $$\n\nThe point $\\bm{\\tilde{X}}$ lies on the plane $\\pi$ if and only if\n$$ \\pi^T\\bm{\\tilde{X}} = \\pi_1x+\\pi_2y+\\pi_3z+\\pi_4w = 0 $$\n\nPlanes from points\n$$ \\begin{bmatrix}\n\t\\tilde{\\bm{X}}^{(1)\\top}\\\\\n\t\\tilde{\\bm{X}}^{(2)\\top}\\\\\n\t\\tilde{\\bm{X}}^{(3)\\top}\\\\\n\\end{bmatrix} \\pi = 0 $$\n\n\n\\subsubsection{Conic}\nInhomogenious:\n$$ ax^2 + bxy + cy^2 + dx + ey + f = 0$$\n\n5 Degrees of freedom\n\n\\subsection{Transformation}\n\\subsubsection{2D Transformation}\n\\begin{itemize}\n\t\\item Rotation+translation/Euclidean\n\t\\item Scaled Rotation/Similarity/Metric - This transformation preserves angles between lines and planes( Orthogonal views of the planar at all times)\n\t\\item Affine - Parallel lines and planes remain parallel under affine transformations (general camera motion relative to the planar shape, but always keeping sufficient distance from the planar shape)\n\t\\item Projectivity/Collineation/Projective transformation/Homography (all cameras motions are allowed, also when moving close to the planar shape)\n\\end{itemize}\n\n$$\\begin{pmatrix}\nx'\\\\\ny'\\\\\nw'\\\\\n\\end{pmatrix} = \\begin{bmatrix}\nh_{11}&h_{12}&h_{13}\\\\\nh_{21}&h_{22}&h_{23}\\\\\nh_{31}&h_{32}&h_{33}\\\\\n\\end{bmatrix} \\begin{pmatrix}\nx\\\\\ny\\\\\nw\\\\\n\\end{pmatrix} $$\n\nPoint transformation: $\\bm{\\tilde{x}'} = H \\bm{\\tilde{x}}$\\\\\nLine transformation: $\\bm{l'} = H^{-\\top} \\bm{l}$\\\\\n\n\\includegraphics[width=\\columnwidth]{pictures/2Dtransformations}\n\n\\subsubsection{3D Transformationen}\n\n$$\\begin{pmatrix}\nx'\\\\\ny'\\\\\nz'\\\\\nw'\\\\\n\\end{pmatrix} = \\begin{bmatrix}\nh_{11}&h_{12}&h_{13}&h_{14}\\\\\nh_{21}&h_{22}&h_{23}&h_{24}\\\\\nh_{31}&h_{32}&h_{33}&h_{34}\\\\\nh_{41}&h_{42}&h_{43}&h_{44}\\\\\n\\end{bmatrix} \\begin{pmatrix}\nx\\\\\ny\\\\\nz\\\\\nw\\\\\n\\end{pmatrix} $$\n\nPoint transformation: $\\bm{\\tilde{X}'} = H \\bm{\\tilde{X}}$\\\\\nPlane transformation: $\\bm{\\pi'} = H^{-\\top} \\bm{\\pi}$\\\\\n\n\\includegraphics[width=\\columnwidth]{pictures/3Dtransformation}\n\n\n", "meta": {"hexsha": "447135b378c3d883d26c4d067ed635c7733d9935", "size": 3464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/1_Projective_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/1_Projective_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/1_Projective_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": 27.2755905512, "max_line_length": 201, "alphanum_fraction": 0.6561778291, "num_tokens": 1296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7804892075151175}}
{"text": "\\section{Mixed Models and Splines}\n\nMixed models are defined by \n\\[\n\\by = \\bX \\bb + \\bZ \\bu + \\beps\n\\]\nwhere $\\by$ is a vector of $n$ observable random variables, $\\bb$\nis vector of $p$ unknown parameters having fixed values (fixed\neffects), $\\bX$ and $\\bZ$ are known matrices and $\\bu$ and\n$\\beps$ are vector, of length $q$ and $n$, of unobservable variables\n(random \neffects) such that $\\E(\\bu)=0$ and $\\E(\\beps)=0$ and \n\\[\n\\var\\left[ \\begin{array}{c} \\bu \\\\ \\beps \\end{array} \\right] \n= \n\\left[ \\begin{array}{cc} G&0\\\\ 0&R \\end{array} \\right] \\sigma^2\n\\].\nHere $R$ and $G$ are known positive definite matrices and $\\sigma^2$\nis a positive constant.\n\nRandom effects are especially useful to introduce correlation to the\nrandom part of the model.\n\nRobinson (1991) describes how the best linear unbiased predictor of\n$\\by$ is a ``good thing''. Speed (1991) notes that after defining an\nappropriate $\\bX$, $\\bZ$, and $G$ we have that natural smoothing are\nBLUPs.\n\nThe smoothing parameter is included in the $G$ and one can view it a\n``nuisance'' parameter. Robinson (1991) suggests REML estimation\nas a way of ``estimating'' the smoothness parameter. Speed notes that\nthis is equivalent to Wahba's Generalized Maximum Likelihood estimate\nof the smoothing parameter. \n\nFurthermore, this idea permits us to model nested curves in a natural\nway. See Brumback and Rice (1998).\n\n", "meta": {"hexsha": "9622f96a20e3d32ca95bdea959be8c4ad0851096", "size": 1373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-06.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-06-06.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-06-06.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": 36.1315789474, "max_line_length": 69, "alphanum_fraction": 0.719592134, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7804821444023903}}
{"text": "\\subsection{Draw}\n\n$draw(f,x)$ draws a graph of function $f$ of $x$.\n(The default second argument is $x$.)\n\n{\\color{blue}\n\\begin{verbatim}\ndraw(x^2)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{parabola1.png}\n\\end{center}\n\n\\noindent\nThe vectors $xrange$ and $yrange$ control the scale of the graph.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (-1,1)\nyrange = (0,2)\ndraw(x^2)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{parabola2.png}\n\\end{center}\n\n\\noindent\nParametric drawing occurs when a function returns a vector.\nThe vector $trange$ controls the parametric range.\nThe default is $trange=(-\\pi,\\pi)$.\nIn the following example, $draw$ varies $theta$\nover the default range $-\\pi$ to $+\\pi$.\n\n{\\color{blue}\n\\begin{verbatim}\nxrange = (-10,10)\nyrange = (-10,10)\nf = 5 (cos(theta),sin(theta))\ndraw(f,theta)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{circle1.png}\n\\end{center}\n\n\\noindent\nIn the following example, $trange$ is reduced\nto draw a quarter circle instead of a full circle.\n\n{\\color{blue}\n\\begin{verbatim}\ntrange = (0,pi/2)\nf = 5 (cos(theta),sin(theta))\ndraw(f,theta)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{circle2.png}\n\\end{center}\n\n\\noindent\nLemniscate.\n\n{\\color{blue}\n\\begin{verbatim}\ntrange = (-pi,pi)\nX = cos(t) / (1 + sin(t)^2)\nY = sin(t) cos(t) / (1 + sin(t)^2)\nf = 5 (X,Y)\ndraw(f,t)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{lemniscate.png}\n\\end{center}\n\n\\noindent\nCardioid.\n\n{\\color{blue}\n\\begin{verbatim}\nr = (1 + cos(t)) / 2\nu = (cos(t),sin(t))\nf = r u\nxrange = (-1,1)\nyrange = (-1,1)\ntrange = (0,2pi)\ndraw(f,t)\n\\end{verbatim}\n}\n\n\\begin{center}\n\\includegraphics[scale=0.5]{cardioid.png}\n\\end{center}\n", "meta": {"hexsha": "4d88a8f3cb2474af881cf71d95050dc9093e37b4", "size": 1709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draw.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/draw.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/draw.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": 16.7549019608, "max_line_length": 65, "alphanum_fraction": 0.678174371, "num_tokens": 601, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7804821426805879}}
{"text": "\\subsection*{c)}\n\nFor some datasets it is of interest to only calculate the upper/lower bound of the estimate. As for our case, one is not particularly interested in a significant wave-lengths lower bound, but rather the upper bound. Here we will provide a one-sided parametric bootstrapped 95\\% confidence interval for the 100-year return value of the significant wave-height data provided. \\\\\n\nIf we want to get the return value of the 100-year return value, we use the relation derived in the introduction above. To recall it is denoted by\n\\[ F^{-1}(1-1/T;\\mu,\\beta), \\quad T=3\\cdot14\\cdot100.\\] \\\\\n\nIf we want to get the return value of the 100-year return value, we use the relation derived in the introduction above. To recall it is denoted by\n\\[ F^{-1}(1-1/T;\\mu,\\beta), \\quad T=3\\cdot14\\cdot100.\\]\nTo get the return value we therefore use the relation for the inverse again in assignment \\textbf{a)} by inserting $u=1-1/T$ and our estimated $\\mu$ and $\\beta$. Giving the return value as\n\\[  \\mu-\\beta \\ln \\left \\{\\ln\\left ( \\frac{1}{u}\\right ) \\right \\}=x,\\quad x=16.5436\\]\n\nThis is however, only the maximum-value using our estimates and if we use the same arguments as before. Meaning, we calculate the maximum-value using the relation, but we here use the upper bounds for our estimate. This returns the value $x=17.3984$. As a result, our one-sided 95\\% confidence bound of the 100-year return value for the wave-height is \n\\[ x_b=(16.5436,17.3984)\\quad m \\]\n", "meta": {"hexsha": "5b5db416eb854ffa8ecb6c2ffcae94d2e67a9515", "size": 1471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2/Report/task2c.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/task2c.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/task2c.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": 98.0666666667, "max_line_length": 376, "alphanum_fraction": 0.7416723317, "num_tokens": 396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7802739906425558}}
{"text": "\\section{Segments}\nIn this section we will discuss how to compute intersections and distances involving line segments.\n\n\\subsection{Point on segment}\\label{onsegment}\nAs an introduction, let's first see how to check if a point $P$ lies on segment $[AB]$.\n\nFor this we will first define a useful subroutine \\lstinline|inDisk()| that checks if a point $P$ lies on the disk of diameter $[AB]$. We know that the points on a disk are those which form angles $\\geq 90\\degree$ with the endpoints of a diameter. This can easily be checked by using dot product: $\\widehat{APB} \\geq 90\\degree$ is equivalent $\\dotv{PA}{PB} \\leq 0$ (with the exception of $P=A,B$ in which case angle $\\widehat{APB}$ is undefined).\n\n\\centerFig{segment0}\n\n\\begin{lstlisting}\nbool inDisk(pt a, pt b, pt p) {\n    return dot(a-p, b-p) <= 0;\n}\n\\end{lstlisting}\n\n\\begin{mathy}\nIn fact, we can notice that $\\dotv{PA}{PB}$ is equal to the power of point $P$ with respect to the circle of diameter $[AB]$: if $O$ is the center of that circle and $r$ its radius, then $\\dotv{PA}{PB} = |OP|^2 - r^2$. This makes it perfect for our purpose.\n\\end{mathy}\n\nWith this subroutine in hand, it is easy to check whether $P$ is on segment $[AB]$: this is the case if and only if $P$ is on line $AB$ and also on the disk whose diameter is $AB$ (and thus is in the part the line between $A$ and $B$).\n\n\\begin{center}\n\\includeFig{segment1}\n\nintersection of line and disk $=$ segment\n\\end{center}\n\n\\begin{lstlisting}\nbool onSegment(pt a, pt b, pt p) {\n    return orient(a,b,p) == 0 && inDisk(a,b,p);\n}\n\\end{lstlisting}\n\n\\subsection{Segment-segment intersection}\\label{ss:seg-seg-inter}\nFinding the precise intersection between two segments $[AB]$ and $[CD]$ is quite tricky: many configurations are possible and the intersection itself might be empty, a single point or a whole segment.\n\nTo simplify things, we will separate the problem in two distinct cases:\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. This is easy to test with \\lstinline|orient()|.\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\nLet's deal with the first case: there is a single proper intersection point $I$. To test this, it suffices to test that $A$ and $B$ are on either side of line $CD$, and that $C$ and $D$ are on either side of line $AB$. If the test is positive, we find $I$ as a weighted average of $A$ and $B$.\\footnote{We can understand the formula as the center of gravity of point $A$ with weight $|o_B|$ and point $B$ with weight $|o_A|$, which gives us a point $I$ on $[AB]$ such that $|IA|/|IB| = o_A/o_B$.}\n\n\\begin{center}\n\\includeFig{segment2}\n\nproper intersection\n\\end{center}\n\\begin{lstlisting}\nbool properInter(pt a, pt b, pt c, pt d, pt &out) {\n    double oa = orient(c,d,a),\n           ob = orient(c,d,b),\n           oc = orient(a,b,c),\n           od = orient(a,b,d);\n    // Proper intersection exists iff opposite signs\n    if (oa*ob < 0 && oc*od < 0) {\n        out = (a*ob - b*oa) / (ob-oa);\n        return true;\n    }\n    return false;\n}\n\\end{lstlisting}\n\nThen to deal with the second case, we will 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$. Clearly, an endpoint cannot be in the middle of the intersection segment, so $S$ will always contain 0, 1 or 2 distinct points, describing an empty intersection, a single intersection point or an intersection segment.\n\n\\centerFig{segment3}\n\n\\begin{lstlisting}\n// To create sets of points we need a comparison function\nstruct cmpX {\n    bool operator()(pt a, pt b) {\n        return make_pair(a.x, a.y) < make_pair(b.x, b.y);\n    }\n};\n\nset<pt,cmpX> inters(pt a, pt b, pt c, pt d) {\n    pt out;\n    if (properInter(a,b,c,d,out)) return {out};\n    set<pt,cmpX> s;\n    if (onSegment(c,d,a)) s.insert(a);\n    if (onSegment(c,d,b)) s.insert(b);\n    if (onSegment(a,b,c)) s.insert(c);\n    if (onSegment(a,b,d)) s.insert(d);\n    return s;\n}\n\\end{lstlisting}\n\n\\subsection{Segment-point distance}\nTo find the distance between segment $[AB]$ and point $P$, there are two cases: either the closest point to $P$ on $[AB]$ is strictly between $A$ and $B$, or it is one of the endpoints ($A$ or $B$). The first case happens when the orthogonal projection of $P$ onto $AB$ is between $A$ and $B$.\n\n\\centerFig{segment4}\n\nTo check this, we can use the \\lstinline|cmpProj()| method in \\lstinline|line|.%\\footnote{If desired, we can also eliminate the need for \\lstinline|line| by using the direction vector \\lstinline|v = b-a| to perform the computations directly.}\n\\begin{lstlisting}\ndouble segPoint(pt a, pt b, pt p) {\n    if (a != b) {\n        line l(a,b);\n        if (l.cmpProj(a,p) && l.cmpProj(p,b)) // if closest to projection\n            return l.dist(p);                 // output distance to line\n    }\n    return min(abs(p-a), abs(p-b)); // otherwise distance to A or B\n}\n\\end{lstlisting}\n\n\\subsection{Segment-segment distance}\nWe can find the distance between two segments $[AB]$ and $[CD]$ based on the segment-point distance if we separate into the same two cases as for segment-segment intersection:\n\\begin{enumerate}\n\\item Segments $[AB]$ and $[CD]$ intersect properly, in which case the distance is of course 0.\n\\item In all other cases, the shortest distance between the segments is attained in at least one of the endpoints, so we only need to test the four endpoints and report the minimum.\n\\end{enumerate}\n\nThis can be readily implemented with the functions at our disposal.\n\\begin{lstlisting}\ndouble segSeg(pt a, pt b, pt c, pt d) {\n    pt dummy;\n    if (properInter(a,b,c,d,dummy))\n        return 0;\n    return min({segPoint(a,b,c), segPoint(a,b,d),\n                segPoint(c,d,a), segPoint(c,d,b)});\n}\n\\end{lstlisting}\n\nSome possible cases are illustrated below.\n\\centerFig{segment5}\n", "meta": {"hexsha": "af797d46a684bde1fb13a49f0c5b6a814ac626e3", "size": 6064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/basics/segment.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/segment.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/segment.tex", "max_forks_repo_name": "cbarnson/UVa", "max_forks_repo_head_hexsha": "0dd73fae656613e28b5aaf5880c5dad529316270", "max_forks_repo_licenses": ["Unlicense", "MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.7480314961, "max_line_length": 496, "alphanum_fraction": 0.690798153, "num_tokens": 1703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850039701653, "lm_q2_score": 0.8333246015211009, "lm_q1q2_score": 0.7802293278436204}}
{"text": "\\section{Formal analysis}\nThe problem we must solve is to tell whether:\n\\begin{equation}\n  E_{th} \\le \\frac{1}{N} \\sum_{n=1}^N x^2[n]\n\\end{equation}\nSince $ x[n] \\in [-1, 1) $ and it is represented on 16 bits, it can be\nwritten as\n\\begin{equation}\n  x[n] = z[n]\\cdot LSB\n\\end{equation}\nwhere $z[n] \\in [-2^{15}, 2^{15} - 1]$ and $LSB = \\frac{1}{2^{15}}$. Therefore we\ncan equivalently check that:\n\\begin{equation}\n  \\sum_{n=1}^N |z[n]|^2 \\ge \\frac{N \\cdot E_{th}}{LSB^2} = E_{th}'\n\\end{equation}\nSince the sampling rate is $f_s$ and the frame duration is $T_{frame}$,\nwe can easily compute the number of samples per frame:\n$N = \\frac{T_{frame}}{1/f_s} = 16\\si{\\milli\\second} \\cdot 16\\si{\\kilo\\hertz} = 256$\nand hence $E_{th}' = 13743895347$.\n\n% TODO: move to optimization section\n% \\paragraph{Absolute value} of $z > 0$ is $Z$, which is also the representation\n% of $z$ if it is represented using the 2 complement on 16 bits. We note that\n% $Z(15) = 0$ because $z > 0$.\n\n% If $z < 0$, $|z|$ is represented by $\\bar{Z} + 1$, with $Z\\in[2^{15}, 2^{16}-1]$.\n% So $\\bar{Z} + 1 \\in [1, 2^{15}]$, which requires 16 bits to be represented.\n% We could approximate the representation of $|z|$ with $\\bar{Z}$ for negative $z$,\n% so the representation would require only 15 bits, as in the case of $z > 0$.\n\n% We could hence use only 15 bits to represent $|z|$ for all cases.\n\nFinally, note that, since data comes in serially, the component just needs to \nkeep a partial sum of the squares of the samples.\n\n\\begin{equation}\n  \\begin{cases}\n    S[n] = |z[n]|^2 + S[n - 1] \\\\\n    S[0] = 0\n  \\end{cases}\n\\end{equation}\n", "meta": {"hexsha": "b5b95cc8fa0c6b4bfbf6471e8caadfe5ab5226a7", "size": 1605, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/10_formal_analysis.tex", "max_stars_repo_name": "moriglia/VAD", "max_stars_repo_head_hexsha": "2e65173e329101df7b31478106066532a2e6929b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-03-26T14:19:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-11T23:14:53.000Z", "max_issues_repo_path": "report/10_formal_analysis.tex", "max_issues_repo_name": "moriglia/VAD", "max_issues_repo_head_hexsha": "2e65173e329101df7b31478106066532a2e6929b", "max_issues_repo_licenses": ["MIT"], "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/10_formal_analysis.tex", "max_forks_repo_name": "moriglia/VAD", "max_forks_repo_head_hexsha": "2e65173e329101df7b31478106066532a2e6929b", "max_forks_repo_licenses": ["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.2142857143, "max_line_length": 83, "alphanum_fraction": 0.6492211838, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7802293269310606}}
{"text": "\n\\subsection{Intervals}\n\nFor a totally ordered set we can define a subset as being all elements with a relationship to a number. For example:\n\n\\([a,b]=\\{x:a\\le x \\land x\\le b\\}\\)\n\nThis denotes a closed interval. Using the definition above we can also define an open interval:\n\n\\((a,b)=\\{x:a< x \\land x< b\\}\\)\n\n\n", "meta": {"hexsha": "d7cee136fc88afa4e940671462b218639332ab23", "size": 311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/orderingInfinite/01-02-intervals.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/orderingInfinite/01-02-intervals.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/orderingInfinite/01-02-intervals.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.9230769231, "max_line_length": 116, "alphanum_fraction": 0.6945337621, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.936285002192296, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7802293186107899}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the distance between the points $P=(0,1,3)$ and\n  $Q=(2,-1,0)$ in $\\R^3$.\n  \\begin{sol}\n    $\\sqrt{17}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the distance between the points $P=(1,3,-1,0)$ and\n  $Q=(2,2,3,3)$ in $\\R^4$.\n  \\begin{sol}\n    $\\sqrt{27}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Describe the points in $\\R^3$ that are equally distant from the two\n  points $Q=(1,1,1)$ and $R=(-1,-1,-1)$.\n  \\begin{sol}\n    The form the plane $x+y+z=0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Describe the points in $\\R^3$ that have distance $1$ from the origin.\n  \\begin{sol}\n    They form a sphere of radius $1$, given by the equation\n    $x^2+y^2+z^2=1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the length of each of the following vectors.\n  \\begin{equation*}\n    \\vect{u}=\\begin{mymatrix}{c}-3\\\\2\\end{mymatrix}, \\quad\n    \\vect{v}=\\begin{mymatrix}{c}1\\\\-2\\\\5\\end{mymatrix}, \\quad\n    \\vect{w}=\\begin{mymatrix}{c}1\\\\4\\\\-2\\\\1\\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $\\norm{\\vect{u}} = \\sqrt{13}$, $\\norm{\\vect{v}} = \\sqrt{30}$,\n    $\\norm{\\vect{w}} = \\sqrt{22}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Prove the properties of Proposition~\\ref{prop:properties-length}.\n\\end{ex}\n\n\\begin{ex}\n  Prove that for all vectors $\\vect{u}\\in\\R^n$, we have\n  $\\norm{-\\vect{u}} = \\norm{\\vect{u}}$.\n  \\begin{sol}\n    This follows from the last property of\n    Proposition~\\ref{prop:properties-length}: $\\norm{-\\vect{u}} =\n    \\norm{(-1)\\vect{u}} = \\abs{-1}\\norm{\\vect{u}} = \\norm{\\vect{u}}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following are unit vectors?\n  \\begin{equation*}\n    \\vect{u}=\\frac{1}{2}\\begin{mymatrix}{c}1\\\\1\\\\1\\end{mymatrix}, \\quad\n    \\vect{v}=\\frac{1}{3}\\begin{mymatrix}{c}1\\\\1\\\\1\\end{mymatrix}, \\quad\n    \\vect{w}=\\frac{1}{2}\\begin{mymatrix}{c}1\\\\1\\\\1\\\\1\\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    Only $\\vect{w}$ is a unit vector.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Normalize the following vectors.\n  \\begin{equation*}\n    \\vect{u}=\\begin{mymatrix}{r}1\\\\2\\end{mymatrix}, \\quad\n    \\vect{v}=\\begin{mymatrix}{r}-2\\\\3\\\\2\\end{mymatrix}, \\quad\n    \\vect{w}=\\begin{mymatrix}{r}5\\\\-3\\\\1\\\\-1\\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\frac{1}{\\norm{\\vect{u}}}\\vect{u} = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{r}1\\\\2\\end{mymatrix},\\quad\n      \\frac{1}{\\norm{\\vect{v}}}\\vect{v} = \\frac{1}{\\sqrt{17}}\\begin{mymatrix}{r}-2\\\\3\\\\2\\end{mymatrix},\\quad\n      \\frac{1}{\\norm{\\vect{w}}}\\vect{w} = \\frac{1}{6}\\begin{mymatrix}{r}5\\\\-3\\\\1\\\\-1\\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "0988bb008b7478cd4449c5e04f948ee992d2c8c8", "size": 2570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Vectors-Length.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-Length.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-Length.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.8764044944, "max_line_length": 108, "alphanum_fraction": 0.5937743191, "num_tokens": 1085, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7802000273868643}}
{"text": "\n\\subsection{Integrals}\n\n\\subsubsection{Cosine and sine}\n\n\\(\\arccos (\\theta)\\), \\(\\arcsin (\\theta )\\) and difficulty of inversing\n\nIn order to determine \\(\\tau \\) we need inverse functions for \\(\\cos (\\theta )\\) or \\(\\sin (\\theta )\\).\n\nThese are the \\(\\arccos (\\theta )\\) and \\(\\arcsin (\\theta )\\) functions respectively.\n\nHowever this is not easily calculated. Instead we look for another function.\n\n\\subsubsection{Calculating \\(\\arctan (\\theta )\\)}\n\nSo we want a function to inverse this. This is the \\(\\arctan (\\theta )\\) function.\n\nIf \\(y=\\tan (\\theta )\\), then:\n\n\\(\\theta =\\arctan (y)\\)\n\nWe know the derivative for \\(\\tan (\\theta )\\) is:\n\n\\(\\dfrac{\\delta }{\\delta \\theta }\\tan (\\theta )=1+\\tan^2(\\theta )\\)\n\n\\(\\dfrac{\\delta y}{\\delta \\theta }=1+y^2\\)\n\nSo\n\n\\(\\dfrac{\\delta \\theta }{\\delta y}=\\dfrac{1}{1+y^2}\\)\n\n\\(\\dfrac{\\delta }{\\delta y}\\arctan (y)=\\dfrac{1}{1+y^2}\\)\n\nSo the value for \\(\\arctan (k)\\) is:\n\n\\(\\arctan (k)=\\arctan (a)+\\int_a^k\\dfrac{\\delta }{\\delta y}\\arctan (y) \\delta y\\)\n\n\\(\\arctan (k)=\\arctan (a)+\\int_a^k\\dfrac{1}{1+y^2} \\delta y\\)\n\nWhat do we know about this function? We know it can map to multiple values of \\(\\theta \\) because the underlying \\(\\sin (\\theta )\\) and \\(\\cos (\\theta )\\) functions also loop.\n\nWe know that one of the results for \\(\\arctan (0)\\) is \\(0\\).\n\n", "meta": {"hexsha": "1221679b459a126aaf27c1a5cbf9cd349700aafc", "size": 1299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/trigonometryPi/01-03-trigIntegrals.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-03-trigIntegrals.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-03-trigIntegrals.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.5227272727, "max_line_length": 175, "alphanum_fraction": 0.6304849885, "num_tokens": 446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172572644806, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7801894526203763}}
{"text": "\\chapter{Graphs}\n\nA \\emph{graph} is an ordered pair $G=(V,E)$ where $V$ is a set of\n\\emph{vertices} and $E$ is a set of \\emph{edges}.  An edge is a pair\nof vertices which are said to be \\emph{adjacent}.  An edge is said to\nbe \\emph{incident} on its component vertices.  Usually we consider\nedges to be unordered, in which case the graph is undirected and an\nedge $\\{A,B\\}$ connects $A$ to $B$ and $B$ to $A$.  For example:\n\n\\begin{align*} \nV &= \\{ A, B, C \\} \\\\ E &= \\{ (A, B), (B, C) \\} \n\\end{align*}\n\nWhich can be represented more visually:\n\n{\n  \\includegraphics[scale=0.2]{SimpleGraph}\n  %\\caption{Demonstrates a simple graph}\n  \\label{fig:SimpleGraph}\n}\n\nNote that the vertices are represented by labeled circles and the\nedges are represented by lines connecting vertices to one another.\n\nThe number of edges connecting a vertex $v$ is called the degree of\n$v$ or $deg(v)$.  In the above example:\n\n\\begin{align*}\ndeg(A) = deg(C) &= 1 \\\\\ndeg(B) &= 2\n\\end{align*}\n\nSometimes an edge is directional, meaning the pair of vertices in an\nedge is ordered.  In other words, the edge $(A, B)$ connects $A$ to\n$B$, but not $B$ to $A$.  We say such an edge is incoming on $B$ and\noutgoing on $A$.  A graph whose edges are ordered pairs is called a\n$directed graph$ or $digraph$.\n\nThis is represented visually by an edge with an arrow at one end,\nindicating the direction:\n\n{\n  \\includegraphics[scale=0.2]{DiGraph}\n  %\\caption{Demonstrates a directed graph}\n  \\label{fig:DiGraph}\n}\n\nIn a digraph, the number of incoming edges of $v$ is the in-degree or\n$deg^-(v)$.  Similarly, the number of outgoing edges is the\nout-degree or $deg^+(v)$.\n\nIn the above example:\n%\n\\begin{align*}\ndeg^+(A) = deg^+(B) &= 1 \\\\\ndeg^-(B) = deg^-(C) &= 1 \\\\\ndeg^+(C) = deg^-(A) &= 0\n\\end{align*}\n\nA \\emph{simple graph} is a graph which contains no edges from any\nvertex $v$ to itself $ (v,v) $, called loops.  A simple graph also\ncontains no multi-edges which connect more than two vertices.\n\nA \\emph{path} is a sequence of edges from vertex $u$ to vertex $v$.\n\nTwo vertices are said to be \\emph{connected} if there exists a path\nbetween them.  \n\nA graph is said to be connected if for any two vertices, there exists\na path between them. An adjacent vertex is called a \\emph{neighbour}.\n\nA \\emph{complete} graph is one in which every vertex is adjacent to\nevery other vertex.\n\nA \\emph{subgraph} is a graph consisting of a subset of the vertices\nand edges in another graph.\n\nA \\emph{connected component} is a connected subgraph which does\nnot disconnect any adjacent vertices.  It should be easy to see that a\nconnected graph has exactly one connected component.\n\nA \\emph{cycle} in a graph is when there exists a path from a vertex\nback to itself without crossing any edge more than once.\n\nA graph is said to be \\emph{acyclic} when it does not contain cycles.\n\n\\section{Representation}\n\n\\subsection{Adjacency List}\n\nOne way to represent a graph is for every vertex, store a list of\nneighbours.  For example:\n\n{\n  \\includegraphics[scale=0.2]{SimpleGraph}\n  %\\caption{Demonstrates a simple graph}\n  \\label{fig:SimpleGraph}\n}\n\ncan be represented:\n\n{\n  \\includegraphics[scale=0.7]{AdjacencyList}\n  %\\caption{Demonstrates an adjacency list for a simple graph}\n  \\label{fig:AdjacencyList}\n}\n\nAnd\n\n{\n  \\includegraphics[scale=0.2]{DiGraph}\n  %\\caption{Demonstrates a directed graph}\n  \\label{fig:DiGraph}\n}\n\ncan be represented:\n\n{\n  \\includegraphics[scale=1.0]{AdjacencyListDigraph}\n  %\\caption{Demonstrates an adjacency list for a directed graph}\n  \\label{fig:AdjacencyListDigraph}\n}\n\n\\subsection{Adjacency Matrix}\n\nAnother representation of a graph is as a square matrix with $n$ rows\nand columns where the element at row $i$ and column $j$ is 1 if there\nis an edge between $v_i$ and $v_j$ and 0 otherwise.  For example:\n\n{\n  \\includegraphics[scale=0.2]{SimpleGraph}\n  %\\caption{Demonstrates a simple graph}\n  \\label{fig:SimpleGraph}\n}\n\ncan be represented\n\n\\[\n\\left[\n\\begin{array}{cccc}\n  & a & b & c \\\\\na & 0 & 1 & 0 \\\\\nb & 1 & 0 & 1 \\\\\nc & 0 & 1 & 0\n\\end{array}\n\\right]\n\\]\n\nAs for directed graphs, row $i$ column $j$ is 1 if there exists an\nedge $(v_i,v_j)$.  For example:\n\n{\n  \\includegraphics[scale=0.2]{DiGraph}\n  %\\caption{Demonstrates a directed graph}\n  \\label{fig:DiGraph}\n}\n\ncan be represented\n\n\\[\n\\left[\n\\begin{array}{cccc}\n  & a & b & c \\\\\na & 0 & 1 & 0 \\\\\nb & 0 & 0 & 1 \\\\\nc & 0 & 0 & 0\n\\end{array}\n\\right]\n\\]\n", "meta": {"hexsha": "fa96b3ecc4ce6e68e3d954332cfa8f82f5e8ba59", "size": 4385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "graphs.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": "graphs.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": "graphs.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": 25.7941176471, "max_line_length": 70, "alphanum_fraction": 0.7012542759, "num_tokens": 1354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554445, "lm_q2_score": 0.8807970889295664, "lm_q1q2_score": 0.7800616293210595}}
{"text": "\\subsection{FTC for Line Integrals}\r\n\\noindent\r\nWe saw earlier that $\\mathrm{d}z = \\nabla f \\cdot \\langle \\mathrm{d}x, \\mathrm{d}y \\rangle$. This can be written as $\\mathrm{d}z = \\nabla f \\cdot \\mathrm{d}\\vec{r}$ where $\\vec{r}(t)$ parameterizes a simple curve $C$ and $a \\leq t \\leq b$.\r\n\\begin{equation*}\r\n\t\\int\\limits_{C}{\\nabla f \\cdot \\mathrm{d}\\vec{r}} = \\int_{a}^{b}{(\\nabla f\\circ\\vec{r}) \\cdot \\vec{r^\\prime}\\mathrm{d}t} = f\\circ\\vec{r}\\rvert_{a}^{b} = f(\\vec{r}(b))-f(\\vec{r}(a))\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\int\\limits_{C}{\\nabla f\\cdot\\mathrm{d}\\vec{r}}=f(\\vec{r}(b))-f(\\vec{r}(a))\r\n\\end{equation*}\r\nthe fundamental theorem of calculus for line integrals.\\\\\r\n\r\n\\noindent\r\nLet's test by computing a line integral directly and using the FTC for line integrals. Let the path be the top-half semicircle connecting $(1,0)$ to $(-1,0)$ and let $f(x,y) = 12 - 3x - y$.\r\n\\begin{center}\r\n\t$\\vec{r}(t)=\\langle\\cos{t},\\sin{t}\\rangle$, $0\\leq t\\leq\\pi$\r\n\t\\begin{tabular}{c|c}\r\n\t\tDirectly & FTC \\\\ \\hline\r\n\t\t$\\vec{r^\\prime}(t) = \\langle-\\sin{t}, \\cos{t}\\rangle$ & $\\vec{r}(0) = \\langle 1, 0 \\rangle$, $\\vec{r}(\\pi) = \\langle -1, 0 \\rangle$ \\\\\r\n\t\t$\\nabla f = \\langle -3, -1 \\rangle$ & $f(\\vec{r}(0)) = 9$, $f(\\vec{r}(\\pi)) = 15$ \\\\\r\n\t\t$\\int_{0}^{\\pi}{3\\sin{t} - \\cos{t}\\mathrm{d}t} = 3 - \\cos{t} - \\sin{t}\\rvert_{0}^{\\pi} = 6$ & $15 - 9 = 6$ \\\\\r\n\t\\end{tabular}\r\n\\end{center}\r\n\r\n\\input{./lineSurfaceIntegrals/potentialFunctions}", "meta": {"hexsha": "8b6452e6ecbfd257facddf91deb747dfff4f20a0", "size": 1435, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/ftcLineIntegrals.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/ftcLineIntegrals.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/ftcLineIntegrals.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 59.7916666667, "max_line_length": 240, "alphanum_fraction": 0.6027874564, "num_tokens": 615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181875, "lm_q2_score": 0.8807970904940926, "lm_q1q2_score": 0.7800616253890548}}
{"text": "\\lab{Applications}{Image Compression (SVD)}{SVD}\n\n\\objective{Explore the SVD as a method of image compression}\n\nIn this lab, we are going to explore how the SVD can be used to compress image data.  \nRecall that the SVD is a decomposition of an $m \\times n$ matrix $A$ of rank $r$ into the product $A = U \\Sigma V^H$, where $U$ and $V$ are unitary matrices having dimensions $m \\times m$ and $n \\times n$, respectively, and $\\Sigma$ is an $m \\times n$ diagonal matrix.\n\\begin{equation*}\n\\Sigma = \\mbox{diag}(\\sigma_1,\\sigma_2,\\ldots,\\sigma_r,0,\\ldots,0)\n\\end{equation*}\nwhere $\\sigma_1 \\geq \\sigma_2 \\geq \\ldots \\geq \\sigma_r > 0$ are the singular values of $A$.\nUpon closer inspection, we see that we can write\n\\begin{equation*}\nU = \\begin{pmatrix}U_1 & U_2\\end{pmatrix}, \\quad \\Sigma =\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}, \\quad V =\n\\begin{pmatrix}V_1 & V_2\\end{pmatrix},\n\\end{equation*}\nwhere $U_1$ and $V_1$ have dimensions $m\\times r$ and $n\\times r$ respectively and $\\Sigma_r$ is the $r\\times r$ diagonal matrix of (nonzero) singular values.\nMultiplying this out yields the reduced form of the SVD\n\\begin{equation*}\nA =\n\\begin{pmatrix}U_1 & U_2\\end{pmatrix}\n\\begin{pmatrix}\\Sigma_r & 0\\\\0 & 0\\end{pmatrix}\n\\begin{pmatrix}V^H_1 \\\\ V^H_2\\end{pmatrix} =\nU_1 \\Sigma_r V_1^H\n\\end{equation*}\n\n\\subsection*{Low rank data storage}\nIf the rank of a given matrix is significantly smaller than its dimensions, the reduced form of the SVD offers a way to store $A$ with less memory.\nWithout the SVD, an $m\\times n$ matrix requires storing $m*n$ values.\nBy decomposing the original matrix into the SVD reduced form, $U_1$, $\\Sigma_r$ and $V_1$ together require $(m*r)+r+(n*r)$ values.\nThus if $r$ is much smaller than both $m$ and $n$, we can obtain considerable efficiency.\nFor example, suppose $m=100$, $n=200$ and $r=20$. \nThen the original matrix would require storing $20,000$ values whereas the reduces form of the SVD only requires storing $6020$ values.\n\n\\subsection*{Low rank approximation}\nThe reduced form of the SVD also provides a way to approximate a\nmatrix 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_{\\widehat A} = \\sigma_1, \\sigma_2, \\ldots, \\sigma_s,\\sigma_{s+1}=0,\\ldots,\\sigma_r=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 the singular values.\nWe have plotted the singular values to the image below.\nMatrix rank is on the x-axis and the eigenvalues are the y-axis.\nNote that SVD orders the singular values from greatest to least.\nThe greatest eigenvalues contribute most to the image while the smallest eigenvalues hardly contribute anything to the final approximation.\nBy looking at the graph we can have a rough idea of how many singular values we need to preserve to have a good approximation of $A$.\nThe matrix rank of the image below is $670$.\nHowever, as the plot shows, we could easily approximate the image using only the first half of the singular values.\n\n%\\begin{figure}\n%\\includegraphics[]{hubble_red.png}\n%\\includegraphics[scale=.4]{hubble_svals.pdf}\n%\\end{figure}\n\n\\begin{figure}\n\\begin{minipage}[b]{.4\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{hubble_red}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.5\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{hubble_svals}\n\\end{minipage}\n\\caption{An image and its SVD.}\n\\end{figure}\n\n\\begin{lstlisting}\n: import numpy as np\n: from scipy.linalg import svd, norm\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,Vt = svd(A)\n: S = np.diag(s)\n: Ahat = U[:,0:3].dot(S[0:3,0:3]).dot(Vt[0:3,:])\n: 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\\subsection*{Application to Imaging}\nEnter the following into IPython (note that any image you might have will work):\n\\begin{lstlisting}\n: import matplotlib.pyplot as plt\n: X = plt.imread('fingerprint.png')[:,:,0].astype(float)\n: X.nbytes      #number of bytes needed to store X\n: plt.imshow(X)\n: plt.show()\n\\end{lstlisting}\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)\n: S = sp.diag(s)\n\\end{lstlisting}\nIn the next code block, $n$ represents the desired rank of the output.\n\\begin{lstlisting}\n: n = 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\n\\begin{problem}\nSometimes there is not enough available bandwidth to transmit a full resolution photograph.\nYou aim to reduce the amount of data that needs to be transmitted from a remote location such that loss of image detail is minimal, but the amount of data that needs to be sent has reduced as much as possible.\nIn other words, find the minimum rank needed to accurately represent a variety of images.\nRecord your results and comment on them.\n\\end{problem}\n", "meta": {"hexsha": "5981677024fda946ed35361dda6c15ac6eb61efb", "size": 5625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/SVD/SVD.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/SVD/SVD.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/SVD/SVD.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": 48.9130434783, "max_line_length": 268, "alphanum_fraction": 0.7352888889, "num_tokens": 1674, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.880797085800514, "lm_q1q2_score": 0.7800616159146752}}
{"text": "\\section{Sequences}\\label{sec:sequences}\nWhile the idea of a sequence of numbers, $a_1,a_2,a_3,\\ldots$ is\nstraightforward, it is useful to think of a sequence as a function. We\nhave dealt with functions whose domains are the real\nnumbers, or a subset of the real numbers, like $f(x)=\\sin x$. A\nsequence can be regarded as a function with domain as the natural numbers\n$\\mathbb{N}=\\{1,2,3,\\ldots\\}$ or the non-negative integers,\n$\\ds \\mathbb{Z}^{\\geq 0}=\\{0,1,2,3,\\ldots\\}$. The range of the function is still\nallowed to be the set of all real numbers; we say that a sequence is\na function $f\\colon \\mathbb{N}\\to\\mathbb{R}$. Sequences are commonly denoted in several different, but equally acceptable ways:\n$$a_1,a_2,a_3,\\ldots $$\n$$\\left\\{a_n\\right\\}_{n=1}^\\infty $$\n$$\\left\\{f(n)\\right\\}_{n=1}^\\infty $$\n\nAs with functions of the real numbers,\nwe will most often encounter sequences that can be expressed by a\nformula. We have already seen the sequence $\\ds a_i=f(i)=1-1/2^i$.\nSome other simple examples are:\n\\begin{align*}\nf(i)&={i\\over i+1}\t\\\\\nf(n)&={1\\over2^n}\t\\\\\nf(n)&=\\sin(n\\pi/6)\t\\\\\nf(i)&={(i-1)(i+2)\\over2^i}\t\\\\\n\\end{align*}\nFrequently these formulas will make sense if thought of either as\nfunctions with domain $\\mathbb{R}$ or $\\mathbb{N}$, though occasionally one will make\nsense for integer values only. \n\nThe main question of interest when dealing with sequences is what happens to the terms as we go further and further down the list. In particular, as $i$ becomes extremely large, does $a_i$ get closer to one specific value? This is reminiscent of a question we asked in Chapter~\\ref{chap:Limits}, when looking at limits of functions. In fact, the problems are closely related and we define the limit of a sequence in a way similar to Definition~\\ref{def:LimitAtInfinity}.\n\n\\begin{definition}{Limit of a Sequence}{LimitofaSequence}\nSuppose that $\\ds\\left\\{a_n\\right\\}_{n=1}^\\infty$ is a sequence.\nWe say that $\\ds \\lim_{n\\to \\infty}a_n=L$ if for every $\\epsilon>0$\nthere is an $N > 0$ so that whenever $n>N$, $|a_n-L|<\\epsilon$. If\n$\\ds \\lim_{n\\to\\infty}a_n=L$ we say that the sequence \\dfont{converges} to $L$, otherwise it \\dfont{diverges}.  \n\\end{definition}\n\nIntuitively, $\\lim_{n\\to\\infty}a_2=L$ means that the further we go in the sequence, the closer the terms get to $L$.\n\n\\begin{example}{Exponential Sequence}{ExpSequenceEx}\nShow that $\\{2^{1/n}\\}_{n=1}^{\\infty}$ converges to 1.\n\\end{example}\n\\begin{solution}\nSuppose $\\epsilon>0$. Then let $N=\\frac{1}{\\log_2(1+\\epsilon)}$. Note that $N>0$. Now if $n>N$, then\n\\begin{align*}\n\\ds n&>\\frac{1}{\\log_2(1+\\epsilon)}\t\\\\\n\\log_2(1+\\epsilon)&>\\frac{1}{n}\\\\\n1+\\epsilon&>2^{1/n}\t\\\\\n\\epsilon&>2^{1/n}-1\t\\\\\n\\epsilon&>\\left|2^{1/n}-1\\right|\n\\end{align*}\n\\end{solution}\n\nNote that, as in Chapter~\\ref{chap:Limits}, we generally need to work ``backwards'' from the last line of the proof to determine how to choose $N$. Having done so, we write the actual proof as we have done here to show that this value of $N$ `works'.\n\nIf a sequence is defined by a formula $\\{f(i)\\}_{i=1}^{\\infty}$, we can often expand the domain of the function $f$ to the set of all (or almost all) real numbers. For example, $f(i)=\\frac{1}{i}$ is defined for all non-zero real numbers.\n\nWhen this happens, we can sometimes find the limit of the sequence $\\{f(i)\\}_{i=1}^{\\infty}$ more easily by finding the limit of the function $f(x)$, $x\\in\\mathbb{R}$, as $x$ approaches infinity.\n\n\\begin{theorem}{Limit of a Sequence}{LimSeqTheorem}\nIf $\\lim_{x\\to\\infty}f(x)=L$, where $f:\\mathbb{R}\\to\\mathbb{R}$, then $\\{f(i)\\}_{i=1}^{\\infty}$ converges to $L$.\n\\end{theorem}\n\\begin{proof}\nThis follows immediately from Definitions~\\ref{def:LimitAtInfinity} and \\ref{def:LimitofaSequence}.\n\\end{proof}\n\nHereafter we will use the convention that $x$ refers to a real-valued variable and $i$ and $n$ are integer-valued.\n\n\\begin{example}{Sequence of $1/n$}{SequenceOneOverN}\nShow that $\\{\\frac{1}{n}\\}_{n=0}^{\\infty}$ converges to 0.\n\\end{example}\n\\begin{solution}\nSince $\\lim_{x\\to\\infty}\\frac{1}{x}=0$, $\\lim_{n\\to\\infty}\\frac{1}{n}=0$.\n\\end{solution}\n\nNote that the converse of Theorem~\\ref{thm:LimSeqTheorem} is not true.\n\nLet $f(n)=\\sin(n\\pi)$. This is the sequence\n\\[\n  \\sin(0\\pi), \\sin(1\\pi),\\sin(2\\pi),\\sin(3\\pi),\\ldots=0,0,0,0,\\ldots\n\\]\nsince $\\sin(n\\pi)=0$ when $n$ is an integer. Thus\n$\\ds \\lim_{n\\to\\infty}f(n)=0$. But $\\ds \\lim_{x\\to\\infty}f(x)$, when $x$ is\nreal, does not exist: as $x$ gets bigger and bigger, the values\n$\\sin(x\\pi)$ do not get closer and closer to a single value, but take\non all values between $-1$ and $1$ over and over. In general, whenever\nyou want to know $\\ds \\lim_{n\\to\\infty}f(n)$ you should first attempt to\ncompute $\\ds \\lim_{x\\to\\infty}f(x)$, since if the latter exists it is also\nequal to the first limit. But if for some reason\n$\\ds \\lim_{x\\to\\infty}f(x)$ does not exist, it may still be true that \n$\\ds \\lim_{n\\to\\infty}f(n)$ exists, but you'll have to figure out\nanother way to compute it.\n\nIt is occasionally useful to think of the graph of a sequence. Since\nthe function is defined only for integer values, the graph is just a\nsequence of points. In Figure~\\ref{fig:GraphsOfSequences} we see the\ngraphs of two sequences and the graphs of the corresponding real\nfunctions.\n\n\\begin{figure}[H]\n\\centerline{\n%\\texonly\n\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <0.5truecm,0.5truecm> point at -14 0\n\\setplotarea x from 0 to 10, y from 0 to 5\n\\axis left ticks length <2pt> numbered from 0 to 5 by 1 /\n\\axis bottom  ticks length <2pt> numbered from 0 to 10 by 5 /\n\\setquadratic\n\\plot 0.200 5.000 0.445 2.247 0.690 1.449 0.935 1.070 1.180 0.847 \n1.425 0.702 1.670 0.599 1.915 0.522 2.160 0.463 2.405 0.416 \n2.650 0.377 2.895 0.345 3.140 0.318 3.385 0.295 3.630 0.275 \n3.875 0.258 4.120 0.243 4.365 0.229 4.610 0.217 4.855 0.206 \n5.100 0.196 5.345 0.187 5.590 0.179 5.835 0.171 6.080 0.164 \n6.325 0.158 6.570 0.152 6.815 0.147 7.060 0.142 7.305 0.137 \n7.550 0.132 7.795 0.128 8.040 0.124 8.285 0.121 8.530 0.117 \n8.775 0.114 9.020 0.111 9.265 0.108 9.510 0.105 9.755 0.103 \n10.000 0.100 /\n\\put {$f(x)=1/x$} at 5 2.5\n\\setcoordinatesystem units <0.5truecm,0.5truecm> point at 0 0\n\\setplotarea x from 0 to 10, y from 0 to 5\n\\axis left ticks length <2pt> numbered from 0 to 5 by 1 /\n\\axis bottom  ticks length <2pt> numbered from 0 to 10 by 5 /\n\\multiput {$\\bullet$} at 1 1 2 0.5 3 0.3333 4 0.25 5 0.2\n6 0.1667 7 0.1429 8 0.125 9 0.1111 10 0.1 /\n\\put {$f(n)=1/n$} at 5 2.5\n\\setcoordinatesystem units <0.63truecm,1truecm> point at -11.1 3\n\\setplotarea x from 0 to 8, y from -1 to 1\n\\axis left ticks length <2pt> numbered from -1 to 1 by 1 /\n\\axis bottom shiftedto y=0 /\n\\setquadratic\n\\plot 0.000 0.000 0.080 0.249 0.160 0.482 0.240 0.685 0.320 0.844 \n0.400 0.951 0.480 0.998 0.560 0.982 0.640 0.905 0.720 0.771 \n0.800 0.588 0.880 0.368 0.960 0.125 1.040 -0.125 1.120 -0.368 \n1.200 -0.588 1.280 -0.771 1.360 -0.905 1.440 -0.982 1.520 -0.998 \n1.600 -0.951 1.680 -0.844 1.760 -0.685 1.840 -0.482 1.920 -0.249 \n2.000 0.000 2.080 0.249 2.160 0.482 2.240 0.685 2.320 0.844 \n2.400 0.951 2.480 0.998 2.560 0.982 2.640 0.905 2.720 0.771 \n2.800 0.588 2.880 0.368 2.960 0.125 3.040 -0.125 3.120 -0.368 \n3.200 -0.588 3.280 -0.771 3.360 -0.905 3.440 -0.982 3.520 -0.998 \n3.600 -0.951 3.680 -0.844 3.760 -0.685 3.840 -0.482 3.920 -0.249 \n4.000 0.000 4.080 0.249 4.160 0.482 4.240 0.685 4.320 0.844 \n4.400 0.951 4.480 0.998 4.560 0.982 4.640 0.905 4.720 0.771 \n4.800 0.588 4.880 0.368 4.960 0.125 5.040 -0.125 5.120 -0.368 \n5.200 -0.588 5.280 -0.771 5.360 -0.905 5.440 -0.982 5.520 -0.998 \n5.600 -0.951 5.680 -0.844 5.760 -0.685 5.840 -0.482 5.920 -0.249 \n6.000 0.000 6.080 0.249 6.160 0.482 6.240 0.685 6.320 0.844 \n6.400 0.951 6.480 0.998 6.560 0.982 6.640 0.905 6.720 0.771 \n6.800 0.588 6.880 0.368 6.960 0.125 7.040 -0.125 7.120 -0.368 \n7.200 -0.588 7.280 -0.771 7.360 -0.905 7.440 -0.982 7.520 -0.998 \n7.600 -0.951 7.680 -0.844 7.760 -0.685 7.840 -0.482 7.920 -0.249 \n8.000 0.000 /\n\\put {$f(x)=\\sin(x\\pi)$} at 4 1.3\n\\setcoordinatesystem units <0.63truecm,1truecm> point at 0 3\n\\setplotarea x from 0 to 8, y from -1 to 1\n\\axis left ticks length <2pt> numbered from -1 to 1 by 1 /\n\\axis bottom shiftedto y=0 ticks length <2pt> numbered from 1 to 8 by 1 /\n\\multiput {$\\bullet$} at 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 /\n\\put {$f(n)=\\sin(n\\pi)$} at 4 0.5\n\\endpicture}}\n%\\endtexonly\n\\caption{Graphs of sequences and their corresponding real functions.}\n\\label{fig:GraphsOfSequences}\n\\end{figure}\n\nNot surprisingly, the properties of limits of real functions translate\ninto properties of sequences quite easily. \nTheorem~\\ref{thm:PropertiesLimits} about limits becomes:\n\n\\begin{theorem}{Properties of Sequences}{SequenceProperties}\nSuppose that $\\ds\\lim_{n\\to\\infty}a_n=L$ and \n$\\ds\\lim_{n\\to\\infty}b_n=M$ and\n$k$ is some constant. Then\n\\begin{align*}\n&\\lim_{n\\to\\infty} ka_n = k\\lim_{n\\to\\infty}a_n=kL\t\\\\\n&\\lim_{n\\to\\infty} (a_n+b_n) = \\lim_{n\\to\\infty}a_n+\\lim_{n\\to\\infty}b_n=L+M\t\\\\\n&\\lim_{n\\to\\infty} (a_n-b_n) = \\lim_{n\\to\\infty}a_n-\\lim_{n\\to\\infty}b_n=L-M\t\\\\\n&\\lim_{n\\to\\infty} (a_nb_n) = \\lim_{n\\to\\infty}a_n\\cdot\\lim_{n\\to\\infty}b_n=LM\t\\\\\n&\\lim_{n\\to\\infty} {a_n\\over b_n} = {\\lim_{n\\to\\infty}a_n\\over\n  \\lim_{n\\to\\infty}b_n}={L\\over M},\\hbox{ if $M$ is not 0}\t\\\\\n\\end{align*}\n\\end{theorem}\n\nLikewise the Squeeze Theorem (\\ref{thm:SqueezeTheorem}) becomes:\n\n\\begin{theorem}{Squeeze Theorem for Sequences}{SequenceSqueezeTheorem}\nSuppose that $\\ds a_n \\leq b_n \\leq c_n$ for all $n>N$, for some $N$.\nIf $\\ds\\lim_{n\\to\\infty}a_n=\\ds\\lim_{n\\to\\infty}c_n=L$, \nthen $\\ds\\lim_{n\\to\\infty}b_n=L$.\n\\end{theorem}\n\nAnd a final useful fact:\n\n\\begin{theorem}{Absolute Value Sequence}{AbsValueSequence}\n$\\ds\\lim_{n\\to\\infty}|a_n|=0$ if and only if\n$\\ds\\lim_{n\\to\\infty}a_n=0$.\n\\end{theorem}\n\nThis says simply that the size of $\\ds |a_n|$ gets close to zero if and\nonly if $\\ds a_n$ gets close to zero.\n\n\\begin{example}{Convergence of a Rational Fraction}{ConvRationalFraction}\nDetermine whether $\\ds\\left\\{{n\\over n+1}\\right\\}_{n=0}^\\infty$ converges or\ndiverges. If it converges, compute the limit.\n\\end{example}\n\\begin{solution}\nDefining $f(x)=\\frac{x}{x+1}$ we obtain\n$$\n\\lim_{x\\to\\infty}{x\\over x+1}=\\lim_{x\\to\\infty}1-{1\\over x+1}=1-0=1.\n$$\nThus the sequence converges to 1.\n\\end{solution}\n\n\\begin{example}{Convergence of Ratio with Natural Logarithm}{ConvNatLog}\nDetermine whether $\\ds\\bigg\\{{\\ln n\\over n}\\bigg\\}_{n=1}^\\infty$ converges or\ndiverges. If it converges, compute the limit.\n\\end{example}\n\\begin{solution}\nWe compute\n$$\\lim_{x\\to\\infty}{\\ln x\\over x}=\\lim_{x\\to\\infty}{1/x\\over 1}=\n0,$$\nusing L'H\\^opital's Rule. Thus the sequence converges to 0.\n\\end{solution}\n\n\\begin{example}{Alternating Ones}{AltOnes}\nDetermine whether $\\ds\\{(-1)^n\\}_{n=0}^\\infty$ converges or\ndiverges. If it converges, compute the limit.\n\\end{example}\n\\begin{solution}\n$f(x)=(-1)^x$ is undefined for irrational values of $x$ so $\\lim_{x\\to\\infty}(-1)^x$ does not exist. However, the sequence has a very simple pattern:\n$$1,-1,1,-1,1\\ldots$$\nand clearly diverges.\n\\end{solution}\n\n\\begin{example}{Convergence of Exponential}{ConvExp}\nDetermine whether $\\ds\\{(-1/2)^n\\}_{n=0}^\\infty$ converges or\ndiverges. If it converges, compute the limit.\n\\end{example}\n\\begin{solution}\nWe consider the sequence \n$\\ds\\{|(-1/2)^n|\\}_{n=0}^\\infty=\\{(1/2)^n\\}_{n=0}^\\infty$.\nThen\n$$\n  \\lim_{x\\to\\infty}\\left({1\\over2}\\right)^x=\\lim_{x\\to\\infty}{1\\over2^x}=0,\n$$\nso by Theorem~\\ref{thm:AbsValueSequence} the sequence converges to 0.\n\\end{solution}\n\n\\begin{example}{Using the Squeeze Theorem for Sequences}{UsingSqThmSeq}\nDetermine whether $\\ds\\{(\\sin n)/\\sqrt{n}\\}_{n=1}^\\infty$ converges or\ndiverges. If it converges, compute the limit.\n\\end{example}\n\\begin{solution}\nSince $|\\sin n|\\le 1$, $\\ds 0\\le|\\sin n/\\sqrt{n}|\\le\n1/\\sqrt{n}$ and we can use Theorem~\\ref{thm:SequenceSqueezeTheorem}\nwith $\\ds a_n=0$ and $\\ds c_n=1/\\sqrt{n}$. Since\n$\\ds\\lim_{n\\to\\infty} a_n=\\ds\\lim_{n\\to\\infty} c_n=0$, \n$\\ds\\lim_{n\\to\\infty}\\sin n/\\sqrt{n}=0$ and the sequence converges to 0.\n\\end{solution}\n\n\\begin{example}{Geometric Sequence}{GeometricSequenceEx}\nLet $r$ be a fixed real number. Determine when $\\{r^n\\}_{n=0}^{\\infty}$ coverges.\n\\end{example}\n\\begin{solution}\nA particularly common and useful sequence is $\\ds \\{r^n\\}_{n=0}^\\infty$,\nfor various values of $r$. Some are quite easy to understand: If $r=1$\nthe sequence converges to 1 since every term is 1, and likewise if\n$r=0$ the sequence converges to 0. If $r=-1$ this is\nthe sequence of Example~\\ref{exa:AltOnes} and\ndiverges. If $r>1$ or $r<-1$ the terms $\\ds r^n$ get large without limit,\nso the sequence diverges. If $0<r<1$ then the sequence converges to\n0. If $-1<r<0$ then $\\ds |r^n|=|r|^n$ and $0<|r|<1$, so the sequence\n$\\ds \\{|r|^n\\}_{n=0}^\\infty$ converges to 0, so also \n$\\ds\\{r^n\\}_{n=0}^\\infty$ converges to 0.\nconverges. In summary, $\\ds \\{r^n\\}$ converges precisely when\n$-1<r\\le1$ in which case\n\\[\n\\lim_{n\\to\\infty} r^n=\\left\\{\n\\begin{array}{l l}\n0 & \\quad \\text{if $-1<r<1$}\\\\\n1 & \\quad \\text{if $r=1$}\n\\end{array}\\right.\n\\]\n\\end{solution}\n\nSequences of this form, or the more general form $\\{kr^n\\}_{n=0}^{\\infty}$, are called \\dfont{geometric sequences} or \\dfont{geometric progressions}. They are encountered in a large variety of mathematical and real-world applications.\n\nSometimes we will not be able to determine the limit of a sequence,\nbut we still would like to know whether it converges. In some cases we\ncan determine this even without being able to compute the limit.\n\nA sequence is called \\dfont{increasing}\nor sometimes \\dfont{strictly increasing} if $\\ds a_i<a_{i+1}$ for all\n$i$. It is called \\dfont{non-decreasing} or sometimes\n(unfortunately) \\dfont{increasing} if $\\ds a_i\\le a_{i+1}$ for all\n$i$. Similarly a sequence is \\dfont{decreasing} if $\\ds a_i>a_{i+1}$ for all $i$\nand \\dfont{non-increasing} if\n$\\ds a_i\\ge a_{i+1}$ for all $i$. If a sequence has any of these\nproperties it is called \\dfont{monotonic}.\n\n\\begin{example}{}{}\nThe sequence\n$$\n  \\left\\{{2^i-1\\over2^i}\\right\\}_{i=1}^\\infty=\n  {1\\over2},{3\\over4},{7\\over8},{15\\over16},\\ldots,\n$$\nis increasing, and\n$$ \n  \\left\\{{n+1\\over n}\\right\\}_{i=1}^\\infty=\n  {2\\over1},{3\\over2},{4\\over3},{5\\over4},\\ldots\n$$\nis decreasing.\n\\end{example}\n\nA sequence is \\dfont{bounded above}\nif there is some number $N$ such that $\\ds a_n\\le N$ for every $n$,\nand \\dfont{bounded below} if there is\nsome number $N$ such that $\\ds a_n\\ge N$ for every $n$. If a sequence\nis bounded above and bounded below it is \\dfont{bounded}. If a sequence $\\ds\n\\{a_n\\}_{n=0}^\\infty$ is increasing or non-decreasing it is bounded\nbelow (by $\\ds a_0$), and if it is decreasing or non-increasing it is\nbounded above (by $\\ds a_0$).  Finally, with all this new terminology\nwe can state an important theorem.\n\n\\begin{theorem}{Bounded Monotonic Sequence}{BoundedMonotonicSequence}\nIf a sequence is bounded and monotonic then it converges.\n\\end{theorem}\n\nWe will not prove this, but the proof appears in many calculus books. It\nis not hard to believe: suppose that a sequence is increasing and\nbounded, so each term is larger than the one before, yet never larger\nthan some fixed value $N$. The terms must then get closer and closer\nto some value between $\\ds a_0$ and $N$. It need not be $N$, since $N$ may\nbe a ``too-generous'' upper bound; the limit will be the\nsmallest number that is above all of the terms $\\ds a_i$.\n\n\\begin{example}{}{}\nDetermine whether $\\ds\\left\\{\\frac{2^i-1}{2^i}\\right\\}_{i=1}^{\\infty}$ converges.\n\\end{example}\n\\begin{solution}\nFor every $i\\geq 1$ we have $0<(2^i-1)/2^i<1$, so the sequence is bounded, and we have already observed that it is necessary. Therefore, the sequence converges.\n\\end{solution}\n\nWe don't actually need to know that a sequence is monotonic to apply\nthis theorem---it is enough to know that the sequence is\n``eventually'' monotonic, that is, that at some point it becomes\nincreasing or decreasing. For example, the sequence $10$, $9$, $8$,\n$15$, $3$, $21$, $4$, $3/4$, $7/8$, $15/16$, $31/32,\\ldots$ is not\nincreasing, because among the first few terms it is not. But starting\nwith the term $3/4$ it is increasing, so the theorem tells us that the\nsequence $3/4, 7/8, 15/16, 31/32,\\ldots$ converges.  Since convergence\ndepends only on what happens as $n$ gets large, adding a few\nterms at the beginning can't turn a convergent sequence into a\ndivergent one.\n\n\\begin{example}{}{}\nShow that $\\ds\\{n^{1/n}\\}$ converges.\n\\end{example}\n\\begin{solution}\nWe first show that \nthis sequence is decreasing, that is, that $\\ds n^{1/n}>\n(n+1)^{1/(n+1)}$. Consider the real function $\\ds f(x)=x^{1/x}$ when\n$x\\ge1$. We can compute the derivative, $\\ds f'(x)=x^{1/x}(1-\\ln x)/x^2$,\nand note that when $x\\ge 3$ this is negative. Since the function has\nnegative slope, $\\ds n^{1/n}>\n(n+1)^{1/(n+1)}$ when $n\\ge 3$. Since all terms of the sequence are\npositive, the sequence is decreasing and bounded when $n\\ge3$, and so\nthe sequence converges. (As it happens, we can compute the limit in\nthis case, but we know it converges even without knowing the limit; see\nExercise~\\ref{ex:ExpLimit}.)\n\\end{solution}\n\n\\begin{example}{}{}\nShow that $\\ds\\{n!/n^n\\}$ converges.\n\\end{example}\n\\begin{solution}\nIf we look at the ratio of successive terms we see that:\n$$ \n  {a_{n+1}\\over a_n} = {(n+1)!\\over (n+1)^{n+1}}{n^n\\over n!}=\n  {(n+1)!\\over n!}{n^n\\over (n+1)^{n+1}}=\n  {n+1\\over n+1}\\left({n\\over n+1}\\right)^n=\n  \\left({n\\over n+1}\\right)^n < 1.\n$$\nTherefore $a_{n+1}<a_n$, and so the sequence is decreasing. Since all terms are positive, it is also bounded, and so it must converge.\n(Again it is possible to compute the limit; see\nExercise~\\ref{ex:FactorialLimit}.)\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:sequences}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\\label{ex:ExpLimit}\nCompute $\\ds\\lim_{x\\to\\infty} x^{1/x}$.\n\\begin{sol}\n$1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:FactorialLimit}\nUse the squeeze theorem to show that \n$\\ds\\lim_{n\\to\\infty} {n!\\over n^n}=0$.\n\\end{ex}\n\n\\begin{ex}\nDetermine whether $\\ds\\{\\sqrt{n+47}-\\sqrt{n}\\}_{n=0}^\\infty$ \nconverges or diverges. If it converges, compute the limit.\n\\begin{sol}\n$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether \n$\\ds\\left\\{{n^2+1\\over (n+1)^2}\\right\\}_{n=0}^\\infty$ \nconverges or diverges. If it converges, compute the limit.\n\\begin{sol}\n$1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether \n$\\ds\\left\\{{n+47\\over\\sqrt{n^2+3n}}\\right\\}_{n=1}^\\infty$ \nconverges or diverges. If it converges, compute the limit.\n\\begin{sol}\n$1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nDetermine whether \n$\\ds\\left\\{{2^n\\over n!}\\right\\}_{n=0}^\\infty$ \nconverges or diverges. \n\\begin{sol}\n$0$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "22203f0391a53dd43e2ee21773b8e79136956ca0", "size": 18739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "9-sequences-and-series/9-1-sequences.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-1-sequences.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-1-sequences.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.204954955, "max_line_length": 470, "alphanum_fraction": 0.6930465873, "num_tokens": 7175, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.9073122301325987, "lm_q1q2_score": 0.7799834476879488}}
{"text": "\\section{Application: Error correcting codes}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine the block length, message length, Hamming distance,\n    and rate of a code.\n  \\item Determine whether a code is $m$-error detecting and $m$-error\n    correcting.\n  \\item Find generator and check matrices for a linear code.\n  \\item Use the syndrome method to correct errors in code blocks.\n  \\item Construct and use Hamming codes.\n  \\end{enumerate}\n\\end{outcome}\n\n% ----------------------------------------------------------------------\n\\subsection*{Binary codes}\n\nWhen transmitting or storing information on digital media, the\ninformation is usually encoded as a sequence of bits, i.e., 0s and 1s.\nFor example, in the ASCII code, each symbol is encoded as a sequence\nof 8 bits. The letter ``A'' is encoded as $01000001$, the letter ``B''\nis encoded as $01000010$, and so on. We can think of a sequence of $n$\nbits as an $n$-dimensional column vector over the field $\\Z_2$, i.e.,\nas an element of $\\Z_2^n$. For our purposes, it is convenient to\ncontinue writing bit sequences horizontally, but we will consider this\nto be merely an alternate notation for a column vector.\n\nOne issue with digital data is that the data can sometimes be\ncorrupted. DVDs may be scratched, magnetic storage may depolarize, and\ndata sent by radio transmission may be subject to interference. This\ncan result in errors in the data, such as some 0s being changed to 1s\nor vice versa. One of the ways to deal with such errors is to\nintroduce \\textbf{redundancy}%\n\\index{error correcting code!redundancy}%\n\\index{redundancy} in the way the data is encoded.\n\nA very simple example of redundant encoding is the so-called\n\\textbf{3-repetition code}%\n\\index{error correcting code!repetition code}%\n\\index{repetition code}. This simply means to repeat each bit 3\ntimes. Thus, the bit $0$ is encoded as $000$ and the bit $1$ as\n$111$. For example, the bit string $100101$ is encoded as\n$111000000111000111$. With this encoding, single bit errors are easy\nto detect and correct. Assuming that at most one error occurs within\neach 3-bit block, the blocks can be decoded by ``majority\ndecision''. Namely, if the bits in a block are not the same, we assume\nthat the error occurred in the bit that is in the minority. The\nfollowing table shows the decoding scheme:\n\\begin{center}\n  \\begin{tabular}{|c|c|c|c|}\n    \\hline\n    Received & Likely error & Corrected & Decoded \\\\\\hline\n    $000$    & none         & $000$     & $0$     \\\\\n    $100$    & bit 1        & $000$     & $0$     \\\\\n    $010$    & bit 2        & $000$     & $0$     \\\\\n    $001$    & bit 3        & $000$     & $0$     \\\\\n    $011$    & bit 1        & $111$     & $1$     \\\\\n    $101$    & bit 2        & $111$     & $1$     \\\\\n    $110$    & bit 3        & $111$     & $1$     \\\\\n    $111$    & none         & $111$     & $1$     \\\\\\hline\n  \\end{tabular}\n\\end{center}\n\n\\begin{example}{Decoding the 3-repetition code}{decode-repetition}\n  A message was encoded with the 3-repetition code. The receiver\n  receives the following data: $001011000100111110$. What was the\n  likely message?\n\\end{example}\n\n\\begin{solution}\n  We start by dividing the received data into blocks of 3 bits:\n  \\begin{equation*}\n    001~011~000~100~111~110.\n  \\end{equation*}\n  We then decode each block separately, using the majority rule.\n  The first block $001$ has a majority of zeros, so the likely error is\n  in the third bit and the likely decoding is $0$. The second block $011$\n  has a majority of ones, so the likely error is in the first bit and\n  the likely decoding is $1$. Continuing this way, we find that the\n  likely original message was $01~00~11$.\n\\end{solution}\n\nSince the 3-repetition code can be used to correct some errors, it is\ncalled an \\textbf{error correcting code}%\n\\index{error correcting code}%\n\\index{code!error correcting|see{error correcting code}}. This\nparticular code only works if there are not too many errors; namely,\nit can correct at most one error per code block. The main drawback of\nthe 3-repetition code is that it increases the message length by a\nfactor of 3. In this section, we will use linear algebra over the\nfield $\\Z_2$ to construct better error correcting codes.\n\nMost error correcting codes do not work by encoding individual\nbits. Rather, the codes work by dividing the message into\n\\textit{message blocks} of length $k$, and encoding each such message\nblock by a \\textit{code block} of length $n$.  This leads us to the\nfollowing definition:\n\n\\begin{definition}{Code}{code}\n  Let $n$ and $k$ be positive integers with $k\\leq n$. A\n  \\textbf{code}%\n  \\index{code} with \\textbf{message length}%\n  \\index{message length}%\n  \\index{error correcting code!message length} $k$ and \\textbf{block\n    length}%\n  \\index{block!block length}%\n  \\index{error correcting code!block length} $n$ is a set $C$ of\n  $2^k$ different vectors in $\\Z_2^n$. We call the elements of $C$ the\n  \\textbf{code blocks}%\n  \\index{code block}%\n  \\index{error correcting code!code block}%\n  \\index{block!code block}. Since there are $2^k$ different code\n  blocks, they can be used to encode \\textbf{message blocks}%\n  \\index{message block}%\n  \\index{error correcting code!message block}%\n  \\index{block!message block} of length $k$. We say that the\n  \\textbf{rate}%\n  \\index{rate of a code}%\n  \\index{error correcting code!rate} of the code is $\\frac{k}{n}$,\n  because for every $n$ bits of encoded data transmitted, $k$\n  bits of decoded data are obtained.\n\\end{definition}\n\n\\begin{example}{A simple code}{code-simple}\n  Consider the following code with message length $k=2$ and block\n  length $n=5$:\n  \\begin{center}\n    \\begin{tabular}{|c|c|}\n      \\hline\n      Message block & Code block \\\\\\hline\n      $00$ & $00000$ \\\\\n      $01$ & $00111$ \\\\\n      $10$ & $11100$ \\\\\n      $11$ & $11011$ \\\\\\hline\n    \\end{tabular}\n  \\end{center}\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item Encode the message\\/ $011110$.\n    \\item Decode the message\\/ $111000011111011$.\n    \\item What is the rate of this code? Is it better or worse than\n      the rate of the 3-repetition code?\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{example}\n\n\\begin{solution}\n  (a) We divide the message into blocks of length $2$:\n  $01~11~10$. Then we encode each block separately:\n  $00111~11011~11100$. (b) We divide the message into blocks of length\n  $5$: $11100~00111~11011$. Then we decode each block separately:\n  $10~01~11$. (c) The rate is $\\frac{2}{5}=0.4$. It is slightly\n  higher, and therefore better, than the rate of the 3-repetition code,\n  which is $\\frac{1}{3}\\approx 0.33$.\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection*{Hamming distance and error correction}\n\nThe error correction capabilities of a code depend on a property\ncalled the \\textit{Hamming distance} of the code, which we now define.\n\n\\begin{definition}{Hamming weight and Hamming distance}{hamming-distance}\n  \\begin{itemize}\n  \\item Let $\\vect{v}$ be a vector in $\\Z_2^n$. The \\textbf{Hamming\n      weight}%\n    \\index{Hamming weight}%\n    \\index{error correcting code!Hamming weight} of\\/ $\\vect{v}$,\n    denoted $\\Hw(\\vect{v})$, is the number of components of\\/ $\\vect{v}$\n    that are equal to 1.\n  \\item Let $\\vect{v},\\vect{w}$ be two vectors in $\\Z_2^n$. The\n    \\textbf{Hamming distance}%\n    \\index{Hamming distance}%\n    \\index{error correcting code!Hamming distance} between $\\vect{v}$\n    and $\\vect{w}$, denoted $\\Hd(\\vect{v},\\vect{w})$, is the number of\n    components where $\\vect{v}$ and $\\vect{w}$ differ. We can also\n    express this as the Hamming weight of\\/ $\\vect{v}-\\vect{w}$, i.e.,\n    $\\Hd(\\vect{v},\\vect{w})=\\Hw(\\vect{v}-\\vect{w})$.\n  \\item Finally, we say that the \\textbf{Hamming distance of a code}\n    is equal to the smallest Hamming distance between any two code\n    blocks.\n  \\end{itemize}\n  A code with block length $n$, message length $k$, and Hamming\n  distance $d$ is also called an \\textbf{$(n,k,d)$-code}%\n  \\index{nkd-code@$(n,k,d)$-code}%\n  \\index{error correcting code!nkd-code@$(n,k,d)$-code}.\n\\end{definition}\n\n\\begin{example}{Hamming distance}{hamming-distance}\n  Calculate the Hamming distance between $00111$ and $11100$. What is\n  the Hamming distance of the 3-repetition code? What is the\n  Hamming distance of the code in Example~\\ref{exa:code-simple}?\n\\end{example}\n\n\\begin{solution}\n  The vectors $00111$ and $11100$ differ in 4 places, so their Hamming\n  distance is $\\Hd(00111,11100)=4$. This is also equal to the Hamming\n  weight of $00111-11100 = 11011$.\n\n  The 3-repetition code has only two code blocks: $000$ and\n  $111$. Since their Hamming distance is 3, the Hamming distance of\n  the code is also 3.\n\n  To calculate the Hamming distance of the code from\n  Example~\\ref{exa:code-simple}, we calculate the Hamming distance\n  between all pairs of code blocks:\n  \\begin{equation*}\n    \\begin{array}{rcl}\n      \\Hd(00000,00111) &=& 3, \\\\\n      \\Hd(00000,11100) &=& 3, \\\\\n      \\Hd(00000,11011) &=& 4, \\\\\n      \\Hd(00111,11100) &=& 4, \\\\\n      \\Hd(00111,11011) &=& 3, \\\\\n      \\Hd(11100,11011) &=& 3. \\\\\n    \\end{array}\n  \\end{equation*}\n  Since the smallest distance between any two code blocks is $3$, the\n  Hamming distance of the code is $3$.\n\\end{solution}\n\nThe significance of a code's Hamming distance is explained by the\nfollowing definition and proposition.\n\n\\begin{definition}{Error detection and error correction}{detection-correction}\n  \\begin{itemize}\n  \\item We say that a code $C$ is \\textbf{$m$-error detecting}%\n    \\index{error correcting code!m-error detecting@$m$-error\n      detecting} if for all valid code blocks $\\vect{v}$, whenever\\/\n    $\\vect{w}$ is obtained from $\\vect{v}$ by introducing up to $m$\n    bit errors, then $\\vect{w}$ is not a valid code block.\n  \\item We say that a code $C$ is \\textbf{$m$-error correcting}%\n    \\index{error correcting code!m-error correcting@$m$-error\n      correcting} if for all valid code blocks $\\vect{v}$, whenever\\/\n    $\\vect{w}$ is obtained from $\\vect{v}$ by introducing up to $m$\n    bit errors, then $\\vect{v}$ is the only valid code block within\n    Hamming distance $m$ of $\\vect{w}$.\n  \\end{itemize}\n\\end{definition}\n\n\\begin{proposition}{Error detection and error correction}{detection-correction}\n  Consider a code with Hamming distance $d$. Then the code is:\n  \\begin{itemize}\n  \\item $m$-error detecting if $m\\leq d-1$;\n  \\item $m$-error correcting if $2m\\leq d-1$.\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  Assume up to $m$ errors have happened. In other words, let\n  $\\vect{v}$ be a valid code block, and let $\\vect{w}$ be the code\n  block obtained from $\\vect{v}$ by introducing up to $m$ errors.  To\n  prove the first claim, assume $m\\leq d-1$.  Then\n  $\\Hd(\\vect{v},\\vect{w})\\leq m\\leq d-1$. Since $d$ is the minimum\n  distance between any two valid code blocks, $\\vect{w}$ cannot be a\n  valid code block. Hence, the errors can be detected.  To prove the\n  second claim, assume $2m\\leq d-1$. Then\n  $\\Hd(\\vect{v},\\vect{w})\\leq m$. Assume that there exists another\n  valid code block $\\vect{u}$ within Hamming distance $m$ of\n  $\\vect{w}$, i.e., assume $\\Hd(\\vect{w},\\vect{u})\\leq m$. Then\n  \\begin{equation*}\n    \\Hd(\\vect{v},\\vect{u}) \\leq \\Hd(\\vect{v},\\vect{w}) +\n    \\Hd(\\vect{w},\\vect{u}) \\leq m+m \\leq d-1.\n  \\end{equation*}\n  Therefore, the Hamming distance of $\\vect{v}$ and $\\vect{u}$ is at\n  most $d-1$, contradicting the assumption that the code has Hamming\n  distance $d$. Hence, there is no such code block $\\vect{u}$, and the\n  errors can be corrected.\n\\end{proof}\n\n\\begin{example}{Error detection and error correction}{detection-correction}\n  Consider a code with Hamming distance $3$. How many errors per code\n  block can the code detect? How many can it correct? Also answer this\n  question for Hamming distance $2$, $4$ and $5$.\n\\end{example}\n\n\\begin{solution}\n  By Proposition~\\ref{prop:detection-correction}, a code with Hamming\n  distance $3$ can detect up to $2$ errors and correct up to $1$\n  error. The answers for other Hamming distances are summarized in the\n  following table:\n  \\begin{equation*}\n    \\begin{array}{|c|c|c|}\n      \\hline\n      \\mbox{Hamming distance} & \\mbox{Errors detected} & \\mbox{Errors corrected} \\\\\\hline\n      2 & 1 & 0 \\\\\n      3 & 2 & 1 \\\\\n      4 & 3 & 1 \\\\\n      5 & 4 & 2 \\\\\n      \\hline\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Decoding}{simple-code-decoding}\n  The following message has been encoded using the code of\n  Example~\\ref{exa:code-simple}. It contains some errors, but no more\n  than 1 error per code block. Can you decode the message?\n  \\begin{equation*}\n    11101~01000~11011~11111~00011\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Since the code of Example~\\ref{exa:code-simple} has Hamming distance\n  $3$, it can correct up to 1 error per code block, so we are able to\n  decode the message uniquely. For each code block, we must find the\n  unique valid code block that is within Hamming distance $1$ or less.\n  \\begin{center}\n    \\begin{tabular}{|c|c|c|c|}\n      \\hline\n      Received & Error & Corrected & Decoded \\\\\\hline\n      $11101$  & bit 5 & $11100$   & $10$    \\\\\n      $01000$  & bit 2 & $00000$   & $00$    \\\\\n      $11011$  & none  & $11011$   & $11$    \\\\\n      $11111$  & bit 3 & $11011$   & $11$    \\\\\n      $00011$  & bit 3 & $00111$   & $01$    \\\\\n      \\hline\n    \\end{tabular}\n  \\end{center}\n  The decoded message is $10~00~11~11~01$.\n\\end{solution}\n\nWe can say that a ``good'' error correcting code is one that has a\nhigh rate (of message length divided by block length) and a large\nHamming distance.\n\n% ----------------------------------------------------------------------\n\\subsection*{Linear codes}\n\nTo construct a code of message length $n$, we need to specify a set of\n$2^n$ code blocks. If $n$ is large, it is not really feasible to write\ndown a list of all the code blocks, and to check all their Hamming\ndistances by hand. For example, a code of block length $n=10$ requires\n$2^{10}=1024$ code blocks, and we need to check more than half a\nmillion Hamming distances. Instead, we will focus on a particular\nclass of codes that is much easier to describe. These are the linear\ncodes.\n\n\\begin{definition}{Linear code}{linear-code}\n  A \\textbf{linear code}%\n  \\index{linear code}%\n  \\index{error correcting code!linear code} is a subspace of\n  $\\Z_2^n$. If the subspace is $k$-dimensional, then the code has\n  message length $k$ and block length $n$.\n\\end{definition}\n\nThe advantage of a linear code is that to specify the code blocks, we\nonly need to list $k$ basis elements, rather than all $2^k$ elements\nof the code.\n\n\\begin{example}{Linear code}{linear-code}\n  Show that the code from Example~\\ref{exa:code-simple} is\n  linear. What is a basis for the code?\n\\end{example}\n\n\\begin{solution}\n  Consider all linear combinations of $11100$ and $00111$ (with\n  scalars in $\\Z_2$):\n  \\begin{equation*}\n    \\begin{array}{rcl}\n      0(11100) + 0(00111) &=& 00000, \\\\\n      0(11100) + 1(00111) &=& 00111, \\\\\n      1(11100) + 0(00111) &=& 11100, \\\\\n      1(11100) + 1(00111) &=& 11011. \\\\\n    \\end{array}\n  \\end{equation*}\n  This shows that the code of Example~\\ref{exa:code-simple} is\n  $\\sspan\\set{11100, 00111}$, and hence a subspace of $\\Z_2^5$. A\n  basis for the code is $\\set{11100, 00111}$\n\\end{solution}\n\nFrom Section~\\ref{sec:null-space}, we know that every subspace of\n$\\Z_2^n$, and therefore every linear code, is the column space of some\nmatrix $G$, and also the null space of some matrix $H$. Such matrices\nare called a {\\em generator matrix} and a {\\em check matrix} for the\ncode, respectively.\n\n\\begin{definition}{Generator matrix and check matrix}{generator-check-matrix}\n  Consider a linear code $C$ with block length $n$ and message length\n  $k$, i.e., a $k$-dimensional subspace of $\\Z_2^n$.\n  \\begin{itemize}\n  \\item A \\textbf{generator matrix}%\n    \\index{generator matrix}%\n    \\index{linear code!generator matrix}%\n    \\index{error correcting code!generator matrix} for the code is an\n    $n\\times k$-matrix $G$ such that $C$ is the column space of $G$.\n  \\item A \\textbf{check matrix}%\n    \\index{check matrix}%\n    \\index{linear code!check matrix}%\n    \\index{error correcting code!check matrix} for the code is an\n    $(n-k)\\times n$-matrix $H$ such that $C$ is the null space of $H$.\n  \\end{itemize}\n\\end{definition}\n\n\\begin{example}{Generator matrix and check matrix}{generator-check-matrix}\n  Find a generator matrix and check matrix for the linear code from\n  Example~\\ref{exa:code-simple}.\n\\end{example}\n\n\\begin{solution}\n  We already found in Example~\\ref{exa:linear-code} that\n  $\\set{11100, 00111}$ is a basis for this code. We can obtain a\n  generator matrix by using the basis vectors as columns:\n  \\begin{equation*}\n    G = \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      1 & 0 \\\\\n      1 & 1 \\\\\n      0 & 1 \\\\\n      0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  To find a check matrix, assume that $\\mat{a,b,c,d,e}$ is a row of\n  the check matrix. Then for every code block $\\vect{v}\\in C$, we must\n  have $\\mat{a,b,c,d,e}\\vect{v}=0$. Since the code blocks are spanned\n  by $11100$ and $00111$, it suffices to consider the two equations\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc} a & b & c & d & e \\end{mymatrix}\n    \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = 1a+1b+1c+0d+0e = 0\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc} a & b & c & d & e \\end{mymatrix}\n    \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    = 0a+0b+1c+1d+1e = 0.\n  \\end{equation*}\n  Solving this system of equations, we find that the following is a\n  basis for the solution space:\n  \\begin{equation*}\n    \\set{\n      \\begin{mymatrix}{ccccc} 1 & 1 & 0 & 0 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{ccccc} 1 & 0 & 1 & 1 & 0 \\end{mymatrix},\n      \\begin{mymatrix}{ccccc} 1 & 0 & 1 & 0 & 1 \\end{mymatrix}\n    }\n  \\end{equation*}\n  We can use these basic solutions as the rows of the check matrix:\n  \\begin{equation*}\n    H = \\begin{mymatrix}{ccccc}\n      1 & 1 & 0 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 & 0 \\\\\n      1 & 0 & 1 & 0 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  \\vspace{-6ex}\\par\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection*{Encoding and the generator matrix}\n\nLet $C$ be a linear code with generator matrix $G$. Since $C$ is the\ncolumn space of the generator matrix, there is a simple encoding\nmethod: we can simply multiply the generator matrix $G$ by a message\nblock to obtain the corresponding code block. In other words, if\n$\\vect{u}\\in\\Z_2^k$ is a message block, we can use\n$\\vect{v}=G\\vect{u}\\in\\Z_2^n$ as the code block.\n\n\\begin{example}{Using the generator matrix for encoding}{generator-matrix-encoding}\n  Use the generator matrix\n  \\begin{equation*}\n    G = \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      1 & 0 \\\\\n      1 & 1 \\\\\n      0 & 1 \\\\\n      0 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  to encode the message\\/ $01~11~10$.\n\\end{example}\n\n\\begin{solution}\n  The message blocks are\n  $\\vect{u}_1 = \\begin{mysmallmatrix}{c} 0 \\\\ 1 \\end{mysmallmatrix}$,\n  $\\vect{u}_2 = \\begin{mysmallmatrix}{c} 1 \\\\ 1 \\end{mysmallmatrix}$,\n  and\n  $\\vect{u}_3 = \\begin{mysmallmatrix}{c} 1 \\\\ 0 \\end{mysmallmatrix}$.\n  We obtain the corresponding code blocks by multiplication with the\n  generator matrix:\n  \\begin{equation*}\n    \\vect{v}_1\n    = G\\vect{u}_1\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    \\quad\n    \\vect{v}_2\n    = G\\vect{u}_2\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    \\quad\n    \\vect{v}_3\n    = G\\vect{u}_3\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n  \\end{equation*}\n  Therefore the encoded message is $00111~11011~11100$. Note that\n  this is the same answer as in Example~\\ref{exa:code-simple}(a).\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection*{Decoding and the check matrix}\n\nLet $C$ be a linear code with check matrix $H$.  By definition, $C$ is\nthe null space of the check matrix. This means that a vector\n$\\vect{v}\\in\\Z_2^n$ is a valid code block (i.e., a code block without\nerrors) if and only if $H\\vect{v}=\\vect{0}$. So we can easily use the\ncheck matrix to determine whether a code block contains errors or not.\n\nHowever, something even better is true. The value of $H\\vect{v}$, when\nit is not zero, tell us not only {\\em that} an error has occurred, but\nalso {\\em which} error has occurred! To see why, consider a code block\n$\\vect{v}'$ possibly containing errors. Then\n$\\vect{v}' = \\vect{v} + \\vect{e}$, where $\\vect{v}$ is a valid code\nblock and $\\vect{e}$ is an \\textbf{error pattern}%\n\\index{error pattern}%\n\\index{error correcting code!error pattern}%\n\\index{linear code!error pattern}. The error pattern is the vector\n$\\vect{e}$ that has a $1$ in every component in which an error\noccurred, and a $0$ everywhere else.  Then we have\n\\begin{equation*}\n  H\\vect{v}' = H(\\vect{v} + \\vect{e}) = H\\vect{v} + H\\vect{e} =\n  \\vect{0} + H\\vect{e} = H\\vect{e}.\n\\end{equation*}\nTherefore, the value of $H\\vect{v}'$ only depends on the error\npattern, and not on $\\vect{v}$. The value\n$\\vect{s} = H\\vect{v'} = H\\vect{e}$ is called the \\textbf{syndrome}%\n\\index{syndrome}%\n\\index{error correcting code!syndrome}%\n\\index{linear code!syndrome} of the error. A code is error correcting,\nfor a class of error patterns, if and only if each such error pattern\nhas a different syndrome. In that case, we can simply make a table of\nall the syndromes and corresponding error patterns, as an efficient\nmethod for correcting errors. Such a table is called a\n\\textbf{syndrome table}%\n\\index{syndrome table}%\n\\index{error correcting code!syndrome table}%\n\\index{linear code!syndrome table} and the corresponding decoding\nmethod is called \\textbf{syndrome decoding}%\n\\index{syndrome decoding}%\n\\index{error correcting code!syndrome decoding}%\n\\index{linear code!syndrome decoding}.\n\n\\begin{example}{Syndrome decoding}{syndrome-decoding}\n  Consider the linear code of Example~\\ref{exa:code-simple} with check\n  matrix\n  \\begin{equation*}\n    H = \\begin{mymatrix}{ccccc}\n      1 & 1 & 0 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 & 0 \\\\\n      1 & 0 & 1 & 0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Make a syndrome table for all single-bit errors.  Then use your\n  syndrome table to decode the message\n  $11101~01000~11011~11111~00011$.\n\\end{example}\n\n\\begin{solution}\n  Since we are only interested in single-bit errors, there are six\n  error patterns to consider: $00000$ (no error), $10000$, $01000$,\n  $00100$, $00010$, and $00001$. For each of these error patterns\n  $\\vect{e}$, we compute the corresponding syndrome $H\\vect{e}$. For\n  example,\n  \\begin{equation*}\n    H \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    H \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    H \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\end{mymatrix},\n  \\end{equation*}\n  and so on. We put this information in a table (writing the vectors\n  horizontally as usual in this section). This is the syndrome table:\n  \\begin{equation*}\n    \\begin{array}{|c|c|}\n      \\hline\n      \\mbox{Error pattern $\\vect{e}$} & \\mbox{Syndrome $H\\vect{e}$} \\\\\\hline\n      00000 & 000 \\\\\n      10000 & 111 \\\\\n      01000 & 100 \\\\\n      00100 & 011 \\\\\n      00010 & 010 \\\\\n      00001 & 001 \\\\\n      \\hline\n    \\end{array}\n  \\end{equation*}\n  To decode the message $11101~01000~11011~11111~00011$, we first\n  calculate the syndrome of each code block by multiplying it by the\n  check matrix. The syndrome table then tells us the corresponding\n  error pattern, which we can use to correct the code block.\n\n  For example, consider the first code block $11101$. Multiplying by\n  $H$, we get the syndrome $001$:\n  \\begin{equation*}\n    H \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n  \\end{equation*}\n  The syndrome table then tells us that the corresponding error pattern\n  is $00001$. Therefore, the corrected code block is $11101 + 00001 =\n  11100$. The decoded block is $10$. We proceed in the same way for\n  all the code blocks:\n  \\begin{equation*}\n    \\begin{array}{|c|c|c|c|c|}\n      \\hline\n      \\mbox{Received code block $\\vect{v}'$} &\n      \\mbox{Syndrome $H\\vect{v}'$} &\n      \\mbox{Error pattern $\\vect{e}$} &\n      \\mbox{Corrected code block $\\vect{v}=\\vect{v}'+\\vect{e}$} &\n      \\mbox{Decoded} \\\\\n      \\hline\n      11101 & 001 & 00001 & 11100 & 10 \\\\\n      01000 & 100 & 01000 & 00000 & 00 \\\\\n      11011 & 000 & 00000 & 11011 & 11 \\\\\n      11111 & 011 & 00100 & 11011 & 11 \\\\\n      00011 & 011 & 00100 & 00111 & 01 \\\\\n      \\hline\n    \\end{array}\n  \\end{equation*}\n  Therefore, the decoded message is $10~00~11~11~01$. Note that this\n  is the same answer we got in Example~\\ref{exa:simple-code-decoding}.\n  But the syndrome table gives a more systematic method of finding the\n  error patterns, which we previously had to do by guessing, or by\n  comparing to all possible code blocks.\n\\end{solution}\n\n\\begin{example}{An invalid code block}{invalid-code-block}\n  Using the code of the previous example, suppose you have received\n  the code block $10010$. Can you decode it?\n\\end{example}\n\n\\begin{solution}\n  The syndrome of this code block is\n  \\begin{equation*}\n    H \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Since the syndrome $101$ is not in our syndrome table, it is not the\n  syndrome of any single-bit error. Therefore, the code block $10010$\n  must contain more than one error. Since our code is only 1-error\n  correcting, this error cannot be corrected. (In fact, there are two\n  valid code words within Hamming distance $2$, namely $00000$ and\n  $11011$).\n\\end{solution}\n\n% ----------------------------------------------------------------------\n\\subsection*{Hamming codes}\n\nThe syndrome decoding method immediately gives us the following\ntheorem:\n\n\\begin{theorem}{Check matrices of 1-error correcting codes}{1-error-check}\n  Consider a linear code with check matrix $H$. Then the code is\n  1-error correcting if and only if all columns of the check matrix\n  are non-zero and distinct.\n\\end{theorem}\n\n\\begin{proof}\n  The syndrome of the zero error pattern is always\n  $H\\vect{0}=\\vect{0}$. Let $\\vect{e}_i$ be the error pattern\n  containing a single bit error in the $i\\th$ component. Then its\n  syndrome is $H\\vect{e}_i$, which is the $i\\th$ column of $H$.\n\n  If $H$ has distinct, non-zero columns, then each possible single bit\n  error has a different syndrome. Therefore, the errors can be\n  corrected.\n\n  Conversely, if $H$ has a column that is zero, or two columns that\n  are equal, then the corresponding error patterns have the same\n  syndrome, and therefore cannot be corrected.\n\\end{proof}\n\nThis theorem was discovered by Richard Hamming%\n\\index{Richard Hamming}%\n\\index{Hamming, Richard} in 1950. Hamming then realized that the best\nsingle-error correcting binary codes can be constructed by letting the\ncheck matrix have {\\em all} possible non-zero columns. The resulting\ncodes are called Hamming codes.\n\n\\begin{definition}{Hamming code}{hamming-code}\n  Let $r\\geq 2$ The $r\\th$ \\textbf{Hamming code}%\n  \\index{Hamming code}%\n  \\index{error correcting code!Hamming code}%\n  \\index{linear code!Hamming code} is a linear code whose check matrix\n  $H$ is an $r\\times (2^r-1)$-matrix that has all possible non-zero\n  column vectors as its columns.\n\\end{definition}\n\nFrom the size of the check matrix, we know that the code length is\n$n=2^r-1$. Since the check matrix has rank $r$, its null space has\ndimension $k=n-r$. Thus, the $r\\th$ Hamming code is an $(n,k,3)$-code,\nwhere $n=2^r-1$ and $k=2^r-1-r$.\n\nIt is customary to order the columns of the check matrix so that the\nlast $r$ columns are the standard basis vectors. In other words, the\ncheck matrix is usually taken to be of the form\n\\begin{equation*}\n  H=\\begin{mymatrix}{c|c}A&I\\end{mymatrix}\n\\end{equation*}\nwhere $I$ is the $r\\times r$-identity matrix and $A$ is the\n$r\\times k$-matrix consisting of the remaining columns of $H$. In that\ncase, we can take the $n\\times k$-matrix\n\\begin{equation*}\n  G = \\begin{mymatrix}{c} I \\\\\\hline A \\end{mymatrix}\n\\end{equation*}\nas the generator matrix, where $I$ is the $k\\times k$-identity\nmatrix. Specifically, for this choice of $G$, we have $HG=0$, ensuring\nthat the column space of $G$ is contained in the null space of\n$H$. Moreover, since $\\rank G = k$, the column space of $G$ is\n$k$-dimensional, and therefore equal to the null space of $H$, so that\n$G$ is indeed a correct generator matrix for the code.\n\n\\begin{example}{Hamming code for $r=3$}{hamming-code-3}\n  Construct a check matrix and generator matrix for the Hamming code\n  with $r=3$. Then encode the message $0101~1110~0111$.\n\\end{example}\n\n\\begin{solution}\n  The check matrix must be a $3\\times 7$-matrix whose columns are all\n  the possible non-zero vectors of length 3. Moreover, we will follow\n  the convention of using the standard basis vectors as the last 3\n  columns. Such a matrix is\n  \\begin{equation*}\n    H = \\begin{mymatrix}{cccc|ccc}\n      1 & 1 & 0 & 1 & 1 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n      0 & 1 & 1 & 1 & 0 & 0 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The corresponding generator matrix $G$ is\n  \\begin{equation*}\n    G = \\begin{mymatrix}{cccc}\n      1 & 0 & 0 & 0 \\\\\n      0 & 1 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 1 \\\\\\hline\n      1 & 1 & 0 & 1 \\\\\n      1 & 0 & 1 & 1 \\\\\n      0 & 1 & 1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  To encode the message $0101~1110~0111$, we multiply the generator\n  matrix by each code block:\n  \\begin{equation*}\n    G \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\quad\n    G \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix},\n    \\quad\n    G \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the encoded message is $0101010~1110000~0111001$. Note that\n  the fact that the top part of the generator matrix $G$ is the\n  identity matrix has the pleasant effect that the $k$ first bits of\n  each code block are the corresponding message block. This makes\n  decoding especially convenient (after any errors have been corrected\n  first).\n\\end{solution}\n\n\\begin{example}{Decoding a Hamming code}{hamming-3-decoding}\n  Using the Hamming $(7,4,3)$-code of the previous example, correct\n  the errors in the message $1011101~1101001~0001101~1110000$ and\n  decode it.\n\\end{example}\n\n\\begin{solution}\n  We do not need to make a syndrome table, because the syndromes are\n  exactly the columns of the check matrix $H$. More precisely, the\n  $i\\th$ column of the check matrix is the syndrome of the error\n  pattern containing a single-bit error in the $i\\th$ bit.\n  We use the check matrix\n  \\begin{equation*}\n    H = \\begin{mymatrix}{cccc|ccc}\n      1 & 1 & 0 & 1 & 1 & 0 & 0 \\\\\n      1 & 0 & 1 & 1 & 0 & 1 & 0 \\\\\n      0 & 1 & 1 & 1 & 0 & 0 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  to calculate the syndrome of each code block:\n  \\begin{equation*}\n    H \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n    \\quad\n    H \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1 \\end{mymatrix},\n    \\quad\n    H \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\end{mymatrix},\n    \\quad\n    H \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  From these syndromes, we can read off the error locations and\n  correct the errors:\n  \\begin{equation*}\n    \\begin{array}{|c|c|c|c|c|c|}\n      \\hline\n      \\mbox{Received code block} &\n      \\mbox{Syndrome} &\n      \\mbox{Error position} &\n      \\mbox{Error pattern} &\n      \\mbox{Corrected code block} &\n      \\mbox{Decoded} \\\\\n      \\hline\n      1011101 & 111 & \\mbox{bit 4} & 0001000 & 1010101 & 1010 \\\\\n      1101001 & 101 & \\mbox{bit 2} & 0100000 & 1001001 & 1001 \\\\\n      0001101 & 010 & \\mbox{bit 6} & 0000010 & 0001111 & 0001 \\\\\n      1110000 & 000 & \\mbox{none}  & 0000000 & 1110000 & 1110 \\\\\n      \\hline\n    \\end{array}\n  \\end{equation*}\n  Thus, the decoded message is $1010~1001~0001~1110$.\n\\end{solution}\n\n\\begin{example}{Hamming code for $r=2$}{hamming-code-2}\n  What is the Hamming code for $r=2$? Have you seen this code before?\n\\end{example}\n\n\\begin{solution}\n  The check matrix and generator matrix for the Hamming code with\n  $r=2$ are\n  \\begin{equation*}\n    H = \\begin{mymatrix}{c|cc}\n      1 & 1 & 0 \\\\\n      1 & 0 & 1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    G = \\begin{mymatrix}{c} 1 \\\\\\hline 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  The code has block size $n=3$ and message length $k=1$. The encoding\n  function is\n  \\begin{equation*}\n    G\\begin{mymatrix}{c} 0 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\end{mymatrix},\\quad\n    G\\begin{mymatrix}{c} 1 \\end{mymatrix}\n    = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  This is exactly the 3-repetition code.\n\\end{solution}\n\nWe end this section by remarking that the Hamming codes are very\nefficient. The rate of the $r\\th$ Hamming code is\n\\begin{equation*}\n  \\frac{k}{n}\n  ~=~ \\frac{2^r-1-r}{2^r-1}\n  ~=~ 1 - \\frac{r}{2^r-1},\n\\end{equation*}\nwhich is very close to $1$ when $r$ is large. The following table\nlists the block sizes, message sizes, and rates of all Hamming codes\nup to $r=8$.\n\\begin{equation*}\n  \\begin{array}{|c|c|c|c|}\n    \\hline\n    r & \\mbox{Block size $n$} & \\mbox{Message size $k$} & \\mbox{Rate} \\\\\\hline\n    2  & 3    & 1    & 0.333 \\\\\n    3  & 7    & 4    & 0.571 \\\\\n    4  & 15   & 11   & 0.733 \\\\\n    5  & 31   & 26   & 0.839 \\\\\n    6  & 63   & 57   & 0.905 \\\\\n    7  & 127  & 120  & 0.945 \\\\\n    8  & 255  & 247  & 0.969 \\\\\n    \\hline\n  \\end{array}\n\\end{equation*}\nOf course, since the codes are only 1-error correcting, one cannot\nincrease the block size indefinitely, or else the probability of\nhaving two or more errors in a block becomes too large. There exist\nmore sophisticated error correcting codes with larger Hamming\ndistances, which can correct many errors per code block. You might\nlearn more about such codes in a course on applied modern algebra.\n", "meta": {"hexsha": "bbd0ddbf8ae5583df164daf08286aca7d99a26db", "size": 34743, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/VectorSpaces-ErrorCorrectingCodes.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/VectorSpaces-ErrorCorrectingCodes.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/VectorSpaces-ErrorCorrectingCodes.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 39.9804372842, "max_line_length": 89, "alphanum_fraction": 0.6561609533, "num_tokens": 11409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.9073122132152183, "lm_q1q2_score": 0.779983426620369}}
{"text": "\\subsection{Constant}\r\nLet $a$ be a constant.\\\\\r\nBy definitions of a Laplace transform and an improper integral,\r\n\\begin{equation*}\r\n\t\\Laplace{a} = \\lim\\limits_{n\\to\\infty}{\\int_{0}^{n}{ae^{-st}\\mathrm{d}t}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= \\frac{a}{s}\\lim\\limits_{n\\to\\infty}\\left[-e^{-st}\\right]_{0}^{n} \\text{, } s \\neq 0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= \\frac{a}{s}\\lim\\limits_{n\\to\\infty}{\\left(1-e^{-sn}\\right)} \\text{, } s \\neq 0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= \\frac{a}{s} \\text{, } s > 0 \r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{a} = \\frac{a}{s} \\text{, } s > 0\r\n\\end{equation*}", "meta": {"hexsha": "da92ebda7de2e2435c0bd8f6920839121fa8d39f", "size": 621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/constant.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/laplaceTransforms/derivations/constant.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/laplaceTransforms/derivations/constant.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.6842105263, "max_line_length": 87, "alphanum_fraction": 0.6086956522, "num_tokens": 270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942119105695, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7798966423138879}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Stieltjes integral} \\label{app:stieltjes}\n% Sources : wolfram world http://mathworld.wolfram.com/StieltjesIntegral.html\n% wikipedia : https://en.wikipedia.org/wiki/Riemann%E2%80%93Stieltjes_integral\nThe Riemann-Stieltjes integral is a generalization of the Riemann integral. Let $f$ and $g$ be real-valued functions defined on a closed interval $[a,\\,b]$. The Riemann-Stieltjes integral of $f$ with respect to $g$ is denoted \n\\begin{equation} \\label{eq:stieltjes}\n\t\\int_a^b f(t) \\rm dg(t).\n\\end{equation}\nConsider a partition of the interval\n\\begin{equation}\n\ta = t_0 < t_1 < \\dots < t_{n-1} < t_n = b,\n\\end{equation}\nand define \n\\begin{equation}\n\th_n \\triangleq \\max_{i \\in \\{1,2,\\dots,n\\}} (t_i - t_{i-1}).\n\\end{equation}\nNow take the Riemann sum\n\\begin{equation}\n\t\\sum_{i=1}^{n} f(\\tau_i)[g(t_i) - g(t_{i-1})],\n\\end{equation}\nwith $\\tau_i \\in [t_{i-1},\\,t_i]$. If the sum tends to a fixed number $I$ as $n \\rightarrow \\infty$ and $h_n \\rightarrow 0$, then\n\\begin{equation}\n\t\\int_a^b f(t) \\rm dg(t) = I.\n\\end{equation}\n% If the function $g'$ is such that \n% \\begin{equation}\n% \tg(t) = g(t_0) + \\int_{t_0}^t g'(t') \\rm dt',\n% \\end{equation}\n% where the integral is the Lebesgue integral (i.e. if $g$ is absolutely continuous), then\n% \\begin{equation}\n% \t\\int_a^b f(t) \\rm dg(t) = \\int_a^b f(t) g'(t) \\rm dt,\n% \\end{equation}\n% where the second integral is a classical Riemann integral.\n\n", "meta": {"hexsha": "07d516eb399d56e4b46e848ec28dfd4143d21c20", "size": 1455, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/appendix/stieltjes.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/stieltjes.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/stieltjes.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": 41.5714285714, "max_line_length": 226, "alphanum_fraction": 0.6872852234, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904956, "lm_q2_score": 0.8633916187614823, "lm_q1q2_score": 0.7798966383531031}}
{"text": "\\section{Orthogonality and the Gram Schmidt process}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine if a given set is orthogonal or orthonormal.\n  \\item Determine if a given matrix is orthogonal.\n  \\item Given a linearly independent set, use the Gram-Schmidt Process\n    to find corresponding orthogonal and orthonormal sets.\n  \\item Find the orthogonal projection of a vector onto a subspace.\n  \\item Find the least squares approximation for a collection of\n    points.\n  \\end{enumerate}\n\\end{outcome}\n", "meta": {"hexsha": "45fd340daa69f9e40bfb93c62815d203659bb7b5", "size": 511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsOrthogonality.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/RnVectorsOrthogonality.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/RnVectorsOrthogonality.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.5, "max_line_length": 70, "alphanum_fraction": 0.771037182, "num_tokens": 121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.779896636498213}}
{"text": "% !TEX root = Main.tex\n\\section{Neural Networks}\n$F^\\sigma:\\mathbb{R}^n \\rightarrow \\mathbb{R}^m, F_j^\\sigma(x) = \\sigma(w_j^\\top x)$ for $j=1,..,m$\\\\\n\\textbf{Activation fuctions}: logistic function $\\sigma(x)=\\frac{1}{1+e^{-x}}$, $\\sigma'(x)=\\sigma(x)(1-\\sigma(x))$, ReLu $\\phi(z)=max(0,z)$ \\\\\n\\textbf{Output layer}: linear regression: $\\hat{\\mathbf{y}} = \\mathbf{W}^L\\mathbf{x}^{L-1}$\\\\\nbinary classification (logistic):\\\\\n$\\hat{y_1} = \\text{P}[Y=1|\\mathbf{x}] = \\frac{1}{1 + \\exp[-\\langle \\mathbf{w}_1^L,\\mathbf{x}^{L-1}\\rangle]}$\\\\\nmulticlass (soft-max):\\\\\n$\\hat{y_k} = \\text{P}[Y=k|\\mathbf{x}]= \\frac{\\exp[\\langle \\mathbf{w}_k^L,\\mathbf{x}^{L-1}\\rangle]}{\\sum_{m=1}^{K}{\\exp[\\langle \\mathbf{w}_m^L, \\mathbf{x}^{L-1}\\rangle]}}$.\\\\\n\\textbf{Loss function} squared loss: $\\frac{1}{2}(y - \\hat{y})^2$\\\\\ncross-entropy loss: $-y \\log \\hat{y} - (1-y)\\log(1-\\hat{y})$.\\\\\n\\textbf{Regularization}: add $l_2$-regularizer to objective or add drop-out layers. \\\\\n\\textbf{Units and Layers}: layer-to-layer fwd. prop. notation: $\\mathbf{x}^{(l)} = \\sigma^{(l)}\\left(\\mathbb{W}^{\\left(l\\right)}\\mathbf{x}^{\\left(l-1\\right)}\\right)$ \nwhere $y = x^{(L)}$ is the output activation vector.\n\n\\subsection*{Backpropagation}\n\\textbullet Use SGD to optimize over weights: $\\theta \\leftarrow \\theta - \\eta \\nabla_\\theta l(y_t;y(x_t;\\theta))$ for $t=\\{1,..,T\\}$\n\\textbullet We want to know $\\partial l / \\partial w_{ij}^{(l')} $ i.e how does changing weights affect the loss.\n\\textbullet three steps: \n\\begin{inparaenum}[\\color{red} 1.] \n    \\item how does output $y$ affect loss \n    \\item how do activities of units affect each other resp. $y$. \n    \\item how do weights affect activities of units. \n\\end{inparaenum}\n\\textbullet \n\\begin{inparaenum}[\\color{red} 1.]\n\\item $\\nabla_yl=\\frac{\\partial}{\\partial y}l(y^*,y)=..$ \n\\item $\\frac{\\partial\\mathbf{x}^{(l)}}{\\partial\\mathbf{x}^{(l-n)}} = \\mathbf{J}^{(l)}\\cdot\\frac{\\partial\\mathbf{x}^{(l-1)}}{\\partial\\mathbf{x}^{(l-n)}}=\\mathbf{J}^{(l)}\\cdot\\mathbf{J}^{(l-1)}\\cdots\\mathbf{J}^{(l-n+1)}$ \nwhere $\\mathbf{x}$ = prev. layer activation, $\\mathbf{x^+}$ = next layer activation. Jacobian matrix $\\mathbf{J}$ = $J_{ij}$ of mapping $\\mathbf{x}\\rightarrow\\mathbf{x^+}$, $\\mathbf{x_i^+} = \\sigma(\\mathbf{w}_i^\\top\\mathbf{x})$, $J_{ij} = \\frac{\\partial \\mathbf{x_i^+}}{\\partial \\mathbf{x}_j} = w_{ij}\\cdot\\sigma'(\\mathbf{w}_i^\\top\\mathbf{x})$. \n\\item $\\frac{\\partial x_i^+}{\\partial w_{ij}} = \\sigma'(w_i^\\top x)x_j$ \n\\end{inparaenum}\n\n\\textbullet Perform forward pass to compute activities for all units. Compute gradient of objective wrt output layer activites. Propagate gradient info back from output to inputs. Compute local gradients of activities wrt weights.  \n\\subsection*{Convolutional Neural Networks}\n\\textbullet \\textbf{Convolution step}: primary purpose is to extract features from the input image. Parameter/weight sharing = a kernel is used on multiple locations of the image with the same weights. Sparse interactions = by making kernel smaller than input. Discrete convolution operator $s[i,j]=(I*K)[i,j] = \\sum_m \\sum_n I[m,n]K[i-m,j-n]$ where I is the image and K the kernel. Note that arguments are commutative. \\\\\n\\textbullet \\textbf{Pooling step}: reduce dim of each feature map e.g by max, sum, average over a predefined spatial neighborhood. Why? Scale invariant representation of image, less params/less overfitting. \n", "meta": {"hexsha": "9e965d6592b949afd8d25c73fdfbd073f558c99d", "size": 3367, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NN.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": "NN.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": "NN.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": 91.0, "max_line_length": 422, "alphanum_fraction": 0.6756756757, "num_tokens": 1174, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342006179156, "lm_q2_score": 0.8152324915965392, "lm_q1q2_score": 0.7798792829162069}}
{"text": "\\section{The Cayley-Hamilton Theorem}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item For a square matrix $A$, find a polynomial $p(x)$ such that $p(A)=0$.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we will consider the so-called\n\\textbf{Cayley-Hamilton theorem}%\n\\index{Cayley-Hamilton theorem}%\n\\index{characteristic polynomial!Cayley-Hamilton theorem}%\n\\index{matrix!Cayley-Hamilton theorem}. It states that every square\nmatrix is a root of its own characteristic polynomial. We use the\nfollowing notation. If\n\\begin{equation*}\n  p(\\eigenvar) = a_n\\eigenvar^n + a_{n-1}\\eigenvar^{n-1} + \\ldots +\n  a_1\\eigenvar + a_0\n\\end{equation*}\nis a polynomial, we denote by $p(A)$ the matrix defined by\n\\begin{equation*}\n  p(A) = a_nA^n + a_{n-1}A^{n-1} + \\ldots + a_1A + a_0I.\n\\end{equation*}\nThe explanation for the last term is that $A^0$ is interpreted as $I$,\nthe identity matrix.\n\n\\begin{theorem}{Cayley-Hamilton theorem}{cayley-hamilton}\n  Let $A$ be a square matrix and let $p(\\eigenvar)=\\det(A-\\eigenvar\n  I)$ be its characteristic polynomial. Then $p(A)=0$.\n\\end{theorem}\n\nBefore we prove this theorem, we consider an example.\n\n\\begin{example}{Cayley-Hamilton theorem}{cayley-hamilton}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      3 & 4 \\\\\n      -1 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the characteristic polynomial $p(\\eigenvar)$, and compute\n  $p(A)$.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    p(\\eigenvar)\n    ~=~ \\det(A-\\eigenvar I)\n    ~=~ \\begin{absmatrix}{cc}\n      3-\\eigenvar & 4 \\\\\n      -1 & 2-\\eigenvar \\\\\n    \\end{absmatrix}\n    ~=~ (3-\\eigenvar)(2-\\eigenvar) - (-1)4\n    ~=~ \\eigenvar^2 - 5\\eigenvar + 10.\n  \\end{equation*}\n  Applying the characteristic polynomial to $A$, we get\n  \\begin{eqnarray*}\n    p(A) ~=~ A^2 - 5A + 10I\n    &=& \\begin{mymatrix}{rr}\n      3 & 4 \\\\\n      -1 & 2 \\\\\n    \\end{mymatrix}^2\n    - 5 \\begin{mymatrix}{rr}\n      3 & 4 \\\\\n      -1 & 2 \\\\\n    \\end{mymatrix}\n    + \\begin{mymatrix}{rr}\n      10 & 0 \\\\\n      0 & 10 \\\\\n    \\end{mymatrix} \\\\\n    &=& \\begin{mymatrix}{rr}\n      5 & 20 \\\\\n      -5 & 0 \\\\\n    \\end{mymatrix}\n    - \\begin{mymatrix}{rr}\n      15 & 20 \\\\\n      -5 & 10 \\\\\n    \\end{mymatrix}\n    + \\begin{mymatrix}{rr}\n      10 & 0 \\\\\n      0 & 10 \\\\\n    \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{rr}\n      0 & 0 \\\\\n      0 & 0 \\\\\n    \\end{mymatrix},\n  \\end{eqnarray*}\n  just as predicted by the Cayley-Hamilton theorem.\n\\end{solution}\n\nThe remainder of this section is devoted to the proof of the\nCayley-Hamilton theorem. Readers who are not interested in the proof\ncan skip this material. We begin with a lemma:\n\n\\begin{lemma}{Polynomials with matrix coefficients}{polynomial-matrix-coefficient}\n  Let $A_0,\\ldots,A_m$ be $n\\times n$-matrices and assume that for all\n  scalars $\\eigenvar$,\n  \\begin{equation*}\n    A_0 + A_1\\eigenvar + \\ldots + A_m\\eigenvar^m = 0.\n  \\end{equation*}\n  Then each $A_i = 0$.\n\\end{lemma}\n\n\\begin{proof}\n  Multiply by $\\eigenvar^{-m}$ to obtain\n  \\begin{equation*}\n    A_0 \\eigenvar^{-m} + A_1 \\eigenvar^{-m+1} + \\ldots + A_{m-1}\\eigenvar^{-1} + A_m = 0.\n  \\end{equation*}\n  Now let $\\abs{\\eigenvar}\\rightarrow\\infty$ to obtain $A_m = 0$. With\n  this, multiply by $\\eigenvar$ to obtain\n  \\begin{equation*}\n    A_0 \\eigenvar^{-m+1} + A_1 \\eigenvar^{-m+2} + \\ldots + A_{m-1} = 0.\n  \\end{equation*}\n  Now let $\\abs{\\eigenvar}\\rightarrow\\infty$ to obtain $A_{m-1} =\n  0$. Continue multiplying by $\\eigenvar$ and letting\n  $\\eigenvar\\to\\infty$ to obtain $A_i=0$ for all $i$.\n\\end{proof}\n\nThe following is a simple consequence of the lemma.\n\n\\begin{corollary}{}{polynomial-matrix-coefficient}\n  Let $A_i$ and $B_i$ be $n\\times n$-matrices and suppose that\n  \\begin{equation*}\n    A_0 + A_1\\eigenvar + \\ldots + A_m\\eigenvar^m =\n    B_0 + B_1\\eigenvar + \\ldots + B_m\\eigenvar^m\n  \\end{equation*}\n  for all $\\eigenvar$. Then for any $n\\times n$-matrix $C$,\n  \\begin{equation*}\n    A_0 + A_1C + \\ldots + A_mC^m =\n    B_0 + B_1C + \\ldots + B_mC^m.\n  \\end{equation*}\n\\end{corollary}\n\n\\begin{proof}\n  Subtracting the right-hand side from the left-hand side and using\n  Lemma~\\ref{lem:polynomial-matrix-coefficient}, we get that $A_i=B_i$\n  for all $i$. But then the conclusion immediately follows.\n\\end{proof}\n\nWith this preparation, it is now relatively easy to prove the\nCayley-Hamilton theorem.\n\n\\begin{proofof}{of the Cayley-Hamilton Theorem} Let $A$ be an\n  $n\\times n$-matrix, and let $p(\\eigenvar)=\\det(A-\\eigenvar I)$ be\n  its characteristic polynomial.  Let $\\adj(A-\\eigenvar I)$ be the\n  adjugate of the matrix $A-\\eigenvar I$ (see\n  Section~\\ref{sec:adjugate} for the definition of the\n  adjugate). Since each of the entries of the adjugate is a cofactor\n  of $A-\\eigenvar I$, the entries are polynomials in $\\eigenvar$ of\n  degree at most $n-1$. Therefore, the adjugate can be written in the\n  form\n  \\begin{equation*}\n    \\adj(A-\\eigenvar I) = C_0 + C_1\\eigenvar + \\ldots + C_{n-1}\\eigenvar^{n-1}.\n  \\end{equation*}\n  By Theorem~\\ref{thm:inverse-and-determinant}, we have\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\\,I = (A-\\eigenvar I) \\, \\adj(A-\\eigenvar I),\n  \\end{equation*}\n  or equivalently,\n  \\begin{equation*}\n    p(\\eigenvar)\\,I =\n    (A-\\eigenvar I)\\,(C_0 + C_1\\eigenvar + \\ldots + C_{n-1}\\eigenvar^{n-1}).\n  \\end{equation*}\n  Since this equation holds for all $\\eigenvar$,\n  Corollary~\\ref{cor:polynomial-matrix-coefficient} may be\n  used. Therefore, if $\\eigenvar$ is replaced with $A$, the two sides\n  will be equal. Thus\n  \\begin{equation*}\n    p(A)\\,I = (A-A)\\,(C_0 + C_1A + \\ldots + C_{n-1}A^{n-1}) = 0.\n  \\end{equation*}\n  It follows that $p(A)=0$, concluding the proof of the\n  Cayley-Hamilton Theorem.\n\\end{proofof}\n", "meta": {"hexsha": "4e91d5aa0fb5a9045788c29ab589b383f9daac28", "size": 5700, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/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/content/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/content/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": 32.3863636364, "max_line_length": 89, "alphanum_fraction": 0.6480701754, "num_tokens": 2120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950907764118, "lm_q2_score": 0.9241418272911436, "lm_q1q2_score": 0.7798787512321387}}
{"text": "\\section{Principal Component Analysis}\nTo reduce the dimensionality and increase the variance, a Principal Component Analysis (PCA) is used. The PCA transforms the data into a new set of dimensions with a minimum amount of correlation. This new feature space contains the dimensions, which are responsible for most of the variance within the data. Hence the covariance is maximized. The covariance matrix of a vector $x$ of length $n$ is given as\n\\[\n    \\mathbf{S} = \\frac{1}{N} \\sum_{i=1}^{n}{(\\mathbf{x}_i - \\overline{\\mathbf{x}}) (\\mathbf{x}_i - \\overline{\\mathbf{x}})^\\mathsf{T}}\n\\]\nwith $\\overline{\\mathbf{x}}$ as mean value of the vector. A PCA resulting in one dimension would always result in the eigenvector $\\mathbf{u}_1$ with the largest eigenvalue $\\lambda_1$ of the covariance matrix\n\\[\n    \\mathbf{S} \\mathbf{u_1} = \\lambda_1 \\mathbf{u}_1.\n\\]\nThe eigenvector gives then the transformation of the PCA. More dimensions could be calculated by defining Iteratively the eigenvectors. For higher dimensions also more efficient algorithms are known. Details on the theory can be found in \\cite[p.~561]{bib:Bishop2006}. Using the PCA\\footnote{Using sklearn.decomposition.PCA from scikit-learn (http://scikit-learn.org/)}, we reduced our features to $d=5$ dimensions.\\\\\\\\\nTo get a data point for one sample, the PCA of all the features in the $n$ blocks can be seen as one long feature vector of length $d \\cdot n$. Consequently, the features of each sample can be considered as a point in a $d \\cdot n$ dimensional space.\\\\\nAll feature data and PCA-reduced feature data are saved as Pandas DataFrames. This reduces the whole data set from about 560~Mb of wave files to a 60~Mb HD5 database. Calculating this takes about 5 minutes on a modern computer\\footnote{The multiprocessing module in Python seemed to have a problem with Windows, thus forcing the Windows version to use only one core, which would quadruple the runtime.}.\n", "meta": {"hexsha": "914e971e5a1b852623745023a73c7f035a43252d", "size": 1934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Pca.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/Pca.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/Pca.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": 148.7692307692, "max_line_length": 419, "alphanum_fraction": 0.7662874871, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7798765719472448}}
{"text": "\\section{Projection Pursuit}\nOne solution is projection-pursuit. It assumes a model of the form\n\\[\nf(X_1,\\dots,X_n) = \\sum_{j=1}^p f_j\\{\\bg{\\alpha}_j'\\bX\\}\n\\]\nwhere $\\bg{\\alpha}_j ' \\bX$ denotes a one dimensional projection of the\nvector $(X_1,\\dots,X_p)'$ and $f_j$ is an arbitrary function of this\nprojection. \n\n\nThe model builds up the regression surface by estimating these\nunivariate regressions along carefully chosen projections defined by\nthe $\\bg{\\alpha}_k$. Thus for $K=1$ and $p=2$ the regression surface\nlooks like a corrugated sheet and is constant in the directions\northogonal to $\\bf{\\alpha}_k$.\n\nIf you don't see how this solves the problem of dimensionality, the\nnext section will help you understand.\n", "meta": {"hexsha": "fc12f809d22f9c65c827d58c9ddc9faba75e6aeb", "size": 719, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-07-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-07-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-07-01.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 37.8421052632, "max_line_length": 71, "alphanum_fraction": 0.7538247566, "num_tokens": 201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294984, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7798660699047619}}
{"text": "\\subsection{Diagonalization}\\label{subsec:diagonalization}\n\n\\begin{definition}\\label{def:diagonal_matrix}\n  We say that the square \\hyperref[def:array/matrix]{matrix} \\( \\{ a_{i,j} \\}_{i,j=1}^{n,n} \\) over a field \\( \\BbbK \\) is \\term{diagonal} if \\( a_{i,j} = 0 \\) whenever \\( i \\neq j \\), that is, only the main diagonal has nonzero elements:\n  \\begin{equation*}\n    \\begin{pmatrix}\n      a_{1,1} & 0       & \\cdots & 0       \\\\\n      0       & a_{2,2} & \\cdots & 0       \\\\\n      \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n      0       & 0       & \\cdots & a_{n,n}\n    \\end{pmatrix}.\n  \\end{equation*}\n\n  If all elements along the main diagonal are \\( 1 \\), we call the matrix the \\term{identity matrix} of order \\( n \\) and denote it by\n  \\begin{equation*}\n    E_n \\coloneqq\n    \\begin{pmatrix}\n      1      & 0      & \\cdots & 0      \\\\\n      0      & 1      & \\cdots & 0      \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      0      & 0      & \\cdots & 1\n    \\end{pmatrix}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:diagonalizable_matrix}\n  A matrix over a field is \\term{diagonalizable} if it is isomorphic to a diagonal matrix.\n\\end{definition}\n\n\\begin{theorem}[Spectral theorem for matrices]\\label{def:spectral_theorem_for_matrices}\\mcite[thm. 6.5]{Knapp2016BasicAlgebra}\n  If \\( R \\) is a ring and \\( 2 \\) is a unit in \\( R \\), every symmetric matrix over \\( R \\) is diagonalizable.\n\\end{theorem}\n", "meta": {"hexsha": "9a5e53ca7f2a8f4f99bec45b793ec717e44be4da", "size": 1430, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/diagonalization.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/diagonalization.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/diagonalization.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": 43.3333333333, "max_line_length": 238, "alphanum_fraction": 0.5951048951, "num_tokens": 494, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7798652241494377}}
{"text": "\\chapter{Compound Interest}\n\nWhen you loan money to someone, you typically charge them some sort of\ninterest. The most common loan of this sort is what the bank calls a\n``savings account''.  Any money you put in the account is loaned to\nthe bank. The bank then lends it to someone else, who pays interest to\nthe bank. And the bank gives some of that interest to you.\n\nHowever, what if you leave the interest in your account? And you start\nmaking \\textit{interest on the interest}? This is known as\n\\textit{compound interest}.\\index{compound interest}\n\n\\section{An example with annual interest payments}\n\nLets say that you put \\$1000 in a savings account that pays 6\\%\ninterest every year. How much money would you have after 12 years?\nLet's make a spreadsheet.\n\n\\includegraphics[width=0.4\\textwidth]{StartInterest.png}\n\nCreate a new spreadsheet and edit the cells to look like this.  All\nthe cells in row 1 - 4 are just values: just type in what you\nsee.\n\nThe fifth row is all formulas:\n\n\\begin{tabular}{c | c | c}\n  After year & Interest & Balance \\\\\n  \\hline \n  = A4 + 1 & = B\\$1 * C4 & = C4 + B5 \\\\\n\\end{tabular}\n\nThe interest rate field should be formatted as a percentage. One thing\nto know when dealing with percentages in the spreadsheet: if the field\nsays ``600\\%'', its value is 6. \n\nThe cells in the Interest and Balance column should be formatted as currency.\n\nYou are about to make a bunch of copies of the cells in the fifth row,\nso make sure they look right.\n\nClick on A5 and shift click on C5 to select all three cells. Drag the\nlower-right corner down to fill the rows 6 - 15.\n\n\\includegraphics[width=0.5\\textwidth]{CopiedCellsInterest.png}\n\nLook at the numbers.  The first interest payment is \\$60, but the last\nis \\$113.90. Your balance has more than doubled!\n\n\\section{Exponential Growth}\n\nWe figured this out numerically by repeatedly multiplying the balance\nby the interest rate.  What if you wanted to know what the balance\nwould be $n$ years after investing $P_0$ dollars with an annual interest\nrate of $r$? (Note that $r$ in our example would be 0.06, not 6.0.)\n\nEach year, the balance is multiplied by $1 + r$, so after one year,\n$P_0$ would become $P_0 \\times (1 + r)$.  The next year you would multiply\nthis number by $(1 + r)$ again: $P_0 \\times (1 + r) \\times (1 + r)$. The\nnext year? $P_0 \\times (1 + r) \\times (1 + r) \\times (1 + r)$ See the\npattern? If we define $P_n$ be this balance after $n$ years, then\n\n$$P_n = P_0 (1+r)^n$$\n\nBecause $n$ is an exponent, we call this \\textit{exponential growth}.\nAnd there are few things as terrifying to a scientist as\nthe phrase ``The population is undergoing exponential growth''.\\index{exponential growth}\n\n\\section{Sensitivity to interest rate}\n\nFor most people, the first surprising thing about compound interest is\nhow quickly your money grows after a few years.  The second thing that\nis surprising is how much difference a small change in the percentage\nrate makes.\n\nLets add another set of columns that shows what happens to your money\nif you convince the bank to pay you 8\\% instead of 6\\%.\n\nCopy everything from columns B and C:\n\n\\includegraphics[width=0.6\\textwidth]{CopyForSecondInterest.png}\n\nNow edit the second interest rate to be 8\\%:\n\n\\includegraphics[width=0.6\\textwidth]{AtBiggerInterestRate.png}\n\n", "meta": {"hexsha": "c74c22d90acba2c4d0b37f718d30c954d0276ba0", "size": 3290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Spreadsheets/compound_interest-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/compound_interest-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/compound_interest-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.816091954, "max_line_length": 89, "alphanum_fraction": 0.747112462, "num_tokens": 873, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.877476785879798, "lm_q1q2_score": 0.7798652121216135}}
{"text": "\\section{Sandwich Theorem}\r\nWe can use the Sandwich Theorem to indirectly find limits by \"sandwiching\" the function in question between two functions we do know the limit of.\r\nIf these two sandwiching functions go to the same value in the limit, then so to must the function in question.\r\n\\begin{theorem}[The Sandwich Theorem]\r\n\tIf $g(x) \\leq f(x) \\leq h(x)$ and $\\lim_{x \\to c}{g(x)} = \\lim_{x\\to c}{h(x)} = L$, then $\\lim_{x \\to c}{f(x)} = L$.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tEvaluate the following limit\r\n\t\\begin{equation*}\r\n\t\t\\lim_{\\theta \\to 0}{\\frac{\\sin{\\theta}}{\\theta}}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe'll need to use some geometric ideas to solve this limit.\r\n\tConsider the following on a unit circle.\r\n\t\r\n\t\\begin{figure}[H]\r\n\t\t\\label{sin_limit_proof}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width = 0.5\\textwidth]{./limits_continuity/sin_limit_proof.png}\r\n\t\t\\caption{\\hyperref{}{}{}{Triangle with internal angle $\\theta$ inside a unit circle.}}\r\n\t\\end{figure}\r\n\t\r\n\tWe can see that the area of the swept arc is between the two triangle with base of length 1 and heights of $\\sin{\\theta}$ and $\\tan{\\theta}$.\r\n\tSo, we can write the following inequality.\r\n\t\\begin{align*}\r\n\t\t\\frac{1}{2}\\sin{\\theta} &\\leq \\frac{1}{2}\\theta \\leq \\frac{1}{2}\\frac{\\sin{\\theta}}{\\cos{\\theta}} \\\\\r\n\t\t\\sin{\\theta} \\leq \\theta &\\leq \\frac{\\sin{\\theta}}{\\cos{\\theta}}\r\n\t\\end{align*}\r\n\t\r\n\tTaking the reciprocal of each part and multiplying by $\\sin{\\theta}$,\r\n\t\\begin{equation*}\r\n\t\t1 \\geq \\frac{\\sin{\\theta}}{\\theta} \\geq \\cos{\\theta}.\r\n\t\\end{equation*}\r\n\t\r\n\tTaking the limit of as $\\theta$ approaches 0 of each term,\r\n\t\\begin{align*}\r\n\t\t1 \\geq & \\lim_{\\theta \\to 0}{\\frac{\\sin{\\theta}}{\\theta}} \\geq \\lim_{\\theta\\to 0}{\\cos{\\theta}} \\\\\r\n\t\t1 \\geq & \\lim_{\\theta \\to 0}{\\frac{\\sin{\\theta}}{\\theta}} \\geq 1.\r\n\t\\end{align*}\r\n\t\r\n\tSo, by the Sandwich Theorem,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{\\theta \\to 0}{\\frac{\\sin{\\theta}}{\\theta}} = 1.\r\n\t\\end{equation*}\r\n\\end{answer}", "meta": {"hexsha": "bdebc14fc26c69cb6fa2503654be763c3ded69a2", "size": 1965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/sandwich_theorem.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/limits_continuity/sandwich_theorem.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/limits_continuity/sandwich_theorem.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.8085106383, "max_line_length": 147, "alphanum_fraction": 0.6575063613, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476793890012, "lm_q2_score": 0.8887587824432528, "lm_q1q2_score": 0.7798652069598961}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{parskip}\n\\usepackage{graphicx}\n\\usepackage{bm}\n\n\\DeclareMathOperator*{\\E}{\\mathbb{E}}\n\\newcommand{\\R}{\\mathbb{R}} \n\n\\begin{document}\n\\title{Stuff I Should Know for Bayesian Statistics}\n\\author{D. Aaron Hillegass \\\\hillegass@gatech.edu}\n\\maketitle\n\n\\section*{Normal Distribution}\n\nA normal distribution has two parameters: the mean ($\\theta$) and the variance ($\\sigma^2$). $x$ can go from $-\\infty$ to $\\infty$. Its density is given by\n\\begin{equation*}\np(x) = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{(x - \\theta)^2}{2\\sigma^2}}\n\\end{equation*}\n\n\nThe conjugate prior of the mean of a normal distribution is another normal distribution. Specifically, if $x_1, \\dots, x_n$, are identical and independent with a normal distribution $\\mathcal{N}(\\theta, \\sigma^2)$ and the prior is $\\theta \\sim  \\mathcal{N}(\\theta_0, \\sigma_0^2)$,\n\\begin{equation*}\n\\theta | x_1,\\ldots,x_n \\sim \\mathcal{N}\\left( \\frac{\\frac{\\sigma^2}{n}\\theta_0 + \\sigma_0^2\\bar{x}}{\\frac{\\sigma^2}{n}+\\sigma_0^2},\\left( \\frac{n}{\\sigma^2} + \\frac{1}{\\sigma_0^2} \\right)^{-1} \\right)\n\\end{equation*}\n\nThe conjugate prior of the variance of a normal distribution is an inverse gamma distribution.\n\n\\section*{Gamma Distribution}\n\nThe gamma distribution has two parameters: $\\alpha$ and $\\beta$. $x$ can go from $0$ to $\\infty$ Its density is given by\n\\begin{equation*}\np(x) =   \\frac{ \\beta^\\alpha}{\\Gamma(\\alpha)} x^{\\alpha-1} e^{-\\beta x} \\quad \\text{ for } x > 0 \\text{ and } \\alpha, \\beta > 0,\n\\end{equation*}\n\n\nThe mean of the distribution is\n\\begin{equation*}\nE[x] = \\frac{ \\alpha}{\\beta}\n\\end{equation*}\n\nIf $\\alpha \\geq 1$, the mode is \n\\begin{equation*}\n\\frac{ \\alpha - 1}{\\beta}\n\\end{equation*}\n\n\n\\section*{Inverse Gamma Distribution}\n\nAn inverse gamma distribution has two parameters: $\\alpha$ and $\\beta$. $x$ can go from $0$ to $\\infty$. Its density is given by\n\\begin{equation*}\np(x) =\n\\frac{\\beta^\\alpha}{\\Gamma(\\alpha)}(1/x)^{\\alpha + 1}e^{\\left(-\\frac{\\beta}{x}\\right)}\n\\end{equation*}\n\nIf $\\alpha > 1$, the mean of the distribution is\n\\begin{equation*}\nE[x] = \\frac{ \\beta}{\\alpha - 1} \n\\end{equation*}\n\nThe mode is \n\\begin{equation*}\n\\frac{ \\beta}{\\alpha + 1}\n\\end{equation*}\n\n\\section*{Binomial Distribution}\n\nThe binomial distribution is a discrete distribution that takes one parameter: $\\pi$ is the probability of one success in one try. The probability of getting exactly $k$ successes in $n$ trials is given by\n\\begin{equation*}\np(k) = \\binom{n}{k}\\pi^k(1-\\pi)^{n-k}\n\\end{equation*}\n\nThe mean is $n\\pi$.\n\nThe conjugate prior of $\\pi$ is the Beta distribution.\n\n\\section*{Beta Distribution}\n\nThe beta distribution takes two parameters: $\\alpha$ and $\\beta$. Its density is given by\n\\begin{equation*}\np(x) = \\frac{1}{Beta(\\alpha,\\beta)} x^{\\alpha-1}(1-x)^{\\beta-1}\n\\end{equation*}\n\nThe mode is\n\\begin{equation*}\n\\frac{\\alpha - 1} {\\alpha + \\beta - 2}\n\\end{equation*}\n\n\\section*{Negative Binomial Distribution}\n\nThe negative binomial distribution is a discrete probability distribution that takes two parameters: $r$ and $p$. For any $k \\in 0, 1,2,\\ldots$,\n\\begin{equation*}\np(k) = \\binom{k+r-1}{k} (1-p)^r p^k \n\\end{equation*}\n\nThe mean is\n\\begin{equation*}\n\\E \\left( p(k) \\right) = \\frac{pr}{1-p}\n\\end{equation*}\n\nIf $r \\leq 1$, the mode is 0. Otherwise it is $\\lfloor \\frac{p(r - 1)}{1 - p} \\rfloor$\n\nThe variance is\n\\begin{equation*}\n\\frac{pr}{(1-p)^2}\n\\end{equation*}\n\n\\section*{Exponential Distribution}\n\nThe exponential distribution takes one parameter $\\lambda$. Its probability density is\n\\begin{equation*}\np(x) = \\begin{cases}\n\\lambda e^{-\\lambda x} & x \\ge 0, \\\\\n0 & x < 0.\n\\end{cases}\n\\end{equation*}\nNote that this is a special case of the gamma distribution.\n\nIts cumulative distribution function is\n\\begin{equation*}\nF(x) = \\begin{cases}\n1-e^{-\\lambda x} & x \\ge 0, \\\\\n0 & x < 0.\n\\end{cases}\n\\end{equation*}\n\nIts mean is $\\frac{1}{\\lambda}$. Its median is $\\frac{\\log{2}}{\\lambda}$. Its mode is 0. Its variance is $\\frac{1}{\\lambda^2}$.\n\nThe conjugate prior for $\\lambda$ in the exponential distribution is a gamma distribution.\n\n\\section*{Poisson Distribution}\n\nThe Poisson Distribution is a discrete distribution that takes one parameter: $\\lambda$. Its distribution is given by\n\\begin{equation*}\np(x) = \\frac{\\lambda^x  e^{-\\lambda}}{x!} \\hspace{5mm}  x \\in \\lbrace 0, 1, \\ldots\\rbrace\n\\end{equation*}\n\n\n$\\lambda$ is both its mean and its variance.\n\nThe congugate prior for $\\lambda$ is the gamma distribution\n\n\\section*{Pareto Distribution}\n\nThe Type 1 Pareto Distribution has two parameters $\\alpha$ and $x_\\mathrm{m}$, where $x_\\mathrm{m}$ is the minimum possible value.  Both  $x_\\mathrm{m}$ and $\\alpha$ must be positive. Its density is\n\\begin{equation*}\np(x)= \\begin{cases} \\frac{\\alpha x_\\mathrm{m}^\\alpha}{x^{\\alpha+1}} & x \\ge x_\\mathrm{m}, \\\\ 0 & x < x_\\mathrm{m}. \\end{cases}\n\\end{equation*}\n\nThe mean of the distribution is\n\\begin{equation*}\n\\operatorname{E}(X)= \\begin{cases} \\infty & \\alpha\\le 1, \\\\\n\\frac{\\alpha x_\\mathrm{m}}{\\alpha-1} & \\alpha>1.\n\\end{cases}\n\\end{equation*}\n\nIts cumulative distribution function is\n\\begin{equation*}\nF(x) = \\begin{cases}\n1-\\left(\\frac{x_\\mathrm{m}}{x}\\right)^\\alpha & x \\ge x_\\mathrm{m}, \\\\\n0 & x < x_\\mathrm{m}.\\end{cases}\n\\end{equation*}\n\n\\section*{Gamma Function}\n\nThe gamma function is a generalization of factorial. That is, if $n$ is a positive integer\n\\begin{equation*}\n\\Gamma(n) = (n-1)!\n\\end{equation*}\nBut the gamma function is defined:\n\\begin{equation*}\n\\Gamma(z) = \\int_0^\\infty x^{z-1} e^{-x}\\,dx\n\\end{equation*}\n\n\\section*{Beta Function}\n\nThe beta function is \n\\begin{equation*}\nBeta(x,y) = \\int_0^1t^{x-1}(1-t)^{y-1}\\,dt = \\frac{\\Gamma(x)\\,\\Gamma(y)}{\\Gamma(x+y)}\n\\end{equation*}\n\n\\section*{Choose Function}\n\nThe choose function is:\n\\begin{equation*}\n\\binom{n}{k} = \\frac{n!}{k! (n-k)!}\n\\end{equation*}\n\n\n\\section*{Linear Regression}\n\nIf you are trying to use $p$ inputs ($x_1, \\ldots, x_p$) to predict an ouput $y$, you could create a vector of coefficients $(\\beta_0, \\ldots, \\beta_n)$ such that\n\\begin{equation*}\ny \\approx \\beta_0 + \\beta_1 x_1 + \\ldots + \\beta_p x_p\n\\end{equation*}\n\nSo how do you figure out what the $\\beta$ is? You use the $n$ data points you have: The column vector $\\boldsymbol{y} = (y_1, y_2, \\ldots, y_n)'$ is the outcomes. The matrix $\\boldsymbol{X}$ is the inputs.  Row $i$ of $\\boldsymbol{X}$ starts with 1 and has the inputs $(x_{i,1}, x_{i,2},\\ldots,x_{i, p})$ that correspond to $y_i$. Thus $X$ has $n$ rows and $p+1$ columns.\n\nGiven the data you have, the sum of the squares of the errors for a column vector $\\beta$ (of length $p + 1$) is given by \n\\begin{equation*}\n\\boldsymbol{y}^T \\boldsymbol{y} - 2 \\beta^T \\boldsymbol{X}^T \\boldsymbol{y} + \\beta^T \\boldsymbol{X}^T \\boldsymbol{X} \\beta\n\\end{equation*}\n\nTo minimize that, you set $\\beta$ to be:\n\\begin{equation*}\n\\beta = \\left( \\boldsymbol{X}^T \\boldsymbol{X} \\right)^{-1} \\boldsymbol{X}^T \\boldsymbol{y}\n\\end{equation*}\n\n\\section*{Logarithmic Identities}\n\n\\begin{equation*}\n\\log{\\left( e^x \\right)} = x \\hspace{10mm} e^{\\log{x}} = x\n\\end{equation*}\n\n\\begin{equation*}\n\\log{\\left(  ab \\right)} = \\log a + \\log b \\hspace{10mm}  \\log{\\left(\\frac{a}{b} \\right)} = \\log a - \\log b\n\\end{equation*}\n\n\\begin{equation*}\n\\log{\\left(  a^b \\right)} = b\\log a \\hspace{10mm}  \\log{\\left(\\sqrt[b]{a} \\right)} = \\frac{\\log{a}}{b}\n\\end{equation*}\n\n\\begin{equation*}\na^{\\log{b}} = b^{\\log{a}}  \\hspace{10mm}  x^{\\frac{\\log(a)}{\\log(x)}} = a\n\\end{equation*}\n\n\\begin{equation*}\n{d \\over dx} \\log x = {1 \\over x } \\hspace{10mm} \\log x = \\int_1^x \\frac {1}{t} dt\n\\end{equation*}\n\n\\section*{Stuff Bayesians Like To Calculate}\n\n\\begin{equation*}\np(\\theta | y) \n=  \\frac{p(y | \\theta) p(\\theta)}{p(y)} \n=  \\frac{p(y | \\theta) p(\\theta)}{\\int p(y | \\theta)p(\\theta)d\\theta} \n\\end{equation*}\n\n\\begin{equation*}\n\\E (\\theta | y) =  \\int \\theta\\ p(\\theta| y)d\\theta = \\frac{\\int \\theta\\ p(y|\\theta)p(\\theta)d\\theta}{\\int p(y|\\theta)p(\\theta)d\\theta}\n\\end{equation*}\n\n\\begin{equation*}\nvar (\\theta | y) = \\E (\\theta^2 | y) - \\left(\\E(\\theta | y)\\right)^2\n\\end{equation*}\n\n\\begin{equation*}\np(\\theta \\in A \\ | \\ y) = \\int_{A} p(\\theta | y)d\\theta\n\\end{equation*}\n\nThe posterior predictive distribution:\n\\begin{equation*}\np(y \\ | \\ data) = \\int p(y\\ |\\ \\theta) p(\\theta\\ |\\ data) d\\theta\n\\end{equation*}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "a892504dd6608ef067702820b5ee69af5872882f", "size": 8331, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes.tex", "max_stars_repo_name": "hillegass/bstats-notes", "max_stars_repo_head_hexsha": "109d10439984e22838f34acb107d5767a7149608", "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.tex", "max_issues_repo_name": "hillegass/bstats-notes", "max_issues_repo_head_hexsha": "109d10439984e22838f34acb107d5767a7149608", "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.tex", "max_forks_repo_name": "hillegass/bstats-notes", "max_forks_repo_head_hexsha": "109d10439984e22838f34acb107d5767a7149608", "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.7977099237, "max_line_length": 371, "alphanum_fraction": 0.6673868683, "num_tokens": 2983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8774767826757122, "lm_q1q2_score": 0.7798652066885089}}
{"text": "\\subsection{Linear Approximations}\r\n\\noindent\r\nSince $\\partial z = f_x\\partial x + f_y\\partial y$, we can approximate $\\Delta z$ (the change in any function) as $\\Delta z \\approx f_x\\Delta x + f_y\\Delta y$, since values of $f$ and the tangent plane are close. We an rewrite this approximation as a dot product: $\\Delta z \\approx \\langle f_x, f_y\\rangle \\cdot \\langle \\Delta x, \\Delta y \\rangle$.\\\\\r\n\r\nFor example, say a cylindrical can has a radius $r=1$ and a height $h=5$. If the radius is increased by .1 and the height is increased by 1, what is the approximate $\\Delta V$?\r\n\\begin{equation*}\r\n\tV(r,h) = \\pi r^2 h, V_r = 2\\pi rh \\text{, and } V_h = \\pi r^2\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\tV_{r}(1,5) = 10\\pi  \\text{ and } V_{h}(1,5) = \\pi\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\Delta V \\approx 10\\pi(.1) + \\pi(1) = 2\\pi\t\r\n\\end{equation*}\r\nComparing this to the actual answer of $2.26\\pi$, we see our approximation is decent.", "meta": {"hexsha": "ff99e9a18ba2904e9a587268619511da958f31db", "size": 934, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximations.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/linearApproximations.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/linearApproximations.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.2666666667, "max_line_length": 351, "alphanum_fraction": 0.6755888651, "num_tokens": 317, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797172476385, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7798341993994047}}
{"text": "\\section{M/M/m/m Queues}\n\\label{sec:M-M-m-m-Queues}\n\nA $M/M/m/m$ is a queue where \\footnote{also called $m$-server loss system}\n(i) the arrival process is Poissonian with rate $\\lambda$,\n(ii) the service process is Exponential with rate $\\mu$,\n(iii) there are $m$ servers,\n(iv) there is no buffer,\n(v) the scheduling policy is FCFS.\n\n%\\begin{figure}[tp]\n%\\label{fig:M-M-m-m-Queue}\n%\t\\centering\n%\t\\includegraphics{fig/M-M-m-m-Queue}\n%\t\\caption{An M/M/m/m queue and its corresponding CTMC.}\n%\\end{figure}\n  \nThe key question in these types of systems is determining the \\textit{Blocking Probability} $P_{block}$, that is the probability that a job is dropped.\n\n\\begin{theorem}[State Probability]\n\\label{thm:M-M-m-m-Probability-State}\n\n\tFor any $M/M/m/m$, the state probability is\n\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-m-Probability-State}\n\t\\pi_{i} = \\Big( \\frac{\\lambda}{\\mu} \\Big)^{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-m-m-Queue-Probability-State-Zero}\n\t\\pi_{0} = \\Big[ \\sum_{i=0}^{m} \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!} \\Big]^{-1}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} on page 256-257.\n\t\\end{proof}\n\\end{theorem}\n\n\\begin{theorem}[Blocking Probability]\n\\label{thm:M-M-m-m-Probability-Block}\t\n\tFor any $M/M/m/m$, the blocking probability is\n\t\n\t\\begin{equation}\n\t\\label{eqn:M-M-m-m-Probability-Block}\n\t\tP_{block} = \\pi_{m} = \\frac{\\Big(\\frac{\\lambda}{\\mu}\\Big)^{m} \\frac{1}{m!}}{\\sum_{i=0}^{m} \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!}}\n\t\\end{equation}\n\t\n\t\\begin{proof}\n\t\tFollows from the fact that $P_{block} = \\pi_{m}$. \n\t\\end{proof}\n\\end{theorem}\n\n\\Cref{thm:M-M-m-m-Probability-Block} is called \\textit{Erlang-B Formula}.\n\nThis formula exposes the \\textit{Insensitivity Property}, that is it is independent of arrivals and service distribution and depends only on the mean quantities of distributions. \nInsensitivity often occurs where there is no queue.\n\nAn easy way to remember \\Cref{eqn:M-M-m-m-Probability-Block} is as follows.\n\n\\begin{equation*}\n\\begin{split}\n\tP_{block} & = \\pi_{m} \\cdot \\frac{e^{-\\frac{\\lambda}{\\mu}}}{e^{-\\frac{\\lambda}{\\mu}}} \\\\ \n\t\t\t  & = \\frac{e^{-\\frac{\\lambda}{\\mu}} \\cdot \\Big(\\frac{\\lambda}{\\mu}\\Big)^{m} \\frac{1}{m!}}{\\sum_{i=0}^{m} e^{-\\frac{\\lambda}{\\mu}} \\cdot \\Big( \\frac{\\lambda}{\\mu} \\Big)^{i} \\frac{1}{i!}} \\\\\n\t\t\t  & = \\frac{\\probability{X = m}}{\\probability{X \\leq m}}\n\\end{split}\n\\end{equation*}\n\nwhere $X \\sim Poisson(\\frac{\\lambda}{\\mu})$.", "meta": {"hexsha": "70ae3576c24ccb959254d77046d249f41b657e77", "size": 2508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/m-m-m-m-queues.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/m-m-m-m-queues.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/m-m-m-m-queues.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 35.323943662, "max_line_length": 192, "alphanum_fraction": 0.6654704944, "num_tokens": 888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7798341970642743}}
{"text": "\\section{Recursion} % (fold)\n\\label{sec:recursion}\n\n\\begin{questions}\n\\titledquestion{Power} % (fold)\n\\label{sub:power}\n\nWrite a recursive function that computes $a^b$ for given $a$ and $b$, where\n$b$ is an integer. Do not use \\texttt{**}.\n\n% titledquestion power (end)\n\n\\titledquestion{Recursive map and filter} % (fold)\n\\label{sub:recursive_map}\n\nWrite a recursive functions \\texttt{myrecmap} and \\texttt{myrecfilter}\nthat implement the \\texttt{map} and \\texttt{filter} functions using recursion.\n\n% titledquestion Recursive map (end)\n\n\\titledquestion{Purify}\n\\label{sub:purify}\n\nWrite two functions, one that uses iteration (say a for loop), and the other using recursion, that achieve the following:\nThe input of the function is a list with integers. The functions return a (new) list with only the even integers in the list.\n\n\\titledquestion{Product}\n\\label{sub:product}\n\nWrite two functions, one that uses iteration, and the other using recursion, that achieve the following:\nThe input of the function is a list with numbers. The functions return the product of the numbers in the list.\n\n\n\\titledquestion{Factorial} % (fold)\n\\label{sub:factorial}\n\nWrite a recursive function to compute $n! = n \\times (n-1) \\times \\ldots \\times 1$.\nNote that $0!$ is defined to equal $1$.\n\n% titledquestion factorial (end)\n\n\\titledquestion{Recursive root finding} % (fold)\n\\label{sub:rec_root_finding}\n\nIn Exercise~\\ref{sec:functions}.\\ref{sub:root_finding} you wrote a function to find a root of a function $f$.\nNow write a recursive function that finds the root of a function.\n\n% titledquestion rec_root_finding (end)\n\n\\titledquestion{Collatz sequence} % (fold)\n\\label{sub:collatz_sequence}\n\nWrite a recursive implementation of a function that returns a list with\nthe Collatz sequence started at an arbitrary starting value.\n\nRecall:\nA Collatz sequence is formed as follows:\nWe start with some number $x_0$, and we find the next number in the sequence by\n\\[\n    x_{i+1} = \\begin{cases}\n        x_i / 2 & \\text{ if $x_i$ is even}\\\\\n        3x_i + 1 & \\text{ if $x_i$ is odd}\n    \\end{cases}\n\\]\nIf $x_i = 1$, we stop iterating and have found the full sequence.\n\n% titledquestion collatz_sequence (end)\n\n\\titledquestion{Fibonacci sequence} % (fold)\n\\label{sub:fibonacci_sequence}\n\nThe Fibonacci sequence $\\{F_i\\}_i=0^\\infty$ starts with $F_0=0, F_1=1$.\nEvery subsequent value in the sequence is the sum of the last elements in the\nsequence:\n\\[\n    F_{n} = F_{n-1} + F_{n-2}\n\\]\n\n\\begin{parts}\n    \\part Implement a non-recursive function that computes the $F_n$\n    \\part Implement a recursive function that computes $F_n$\n    \\part Compare the runtime for computing $F_{35}$ recursively versus\n    non-recursively, and explain the difference.\n    \\part This does not mean a recursion is not feasible for this problem, only\n    that the naive implementation isn't the best. We can get a better version\n    using either of the following\n    \\begin{parts}\n        \\part Store values already calculated, say in a dictionary, so you can look them up instead of redoing the calculation.\n        \\part Generalizing the Fibonacci sequence to an additive\n        sequence with arbitrary starting points $t_0$ and $t_1$, and finding\n        a recursive algorithm to find the $n$th term in such a sequence.\n        Note that finding the $n$th term in a sequence started from $t_0$ and $t_1$\n        is the same as finding the $n-1$th term in a sequence started from $t_1$ and $t_0 + t_1$.\n    \\end{parts}\n    Implement one of the above (or both).\n\n\\end{parts}\n\n% titledquestion fibonacci_sequence (end)\n\n\\titledquestion{Palindromes} % (fold)\n\\label{sub:palindromes}\n\nGiven a string \\texttt{t}, we are interested in finding the largest palindrome in \\texttt{t},\nwhere we are allowed to remove characters from \\texttt{t}.\nFor example, consider the string \\texttt{abcdba}, then the function should return \\texttt{abcba}. Before you start coding, figure out the recursion on paper first.\n\nExtra: you will notice that if you are not careful, this will take a very long time to compute for longer inputs. However, a simple modification can speed up your code so that it runs in $\\mathcal{O}(n^2)$, where $n$ is the length of the input string. Find and implement this modification.\\footnote{This exercise is inspired by an exercise in cs221.}\n\n% titledquestion palindromes (end)\n\n\\titledquestion{Quicksort} % (fold)\n\\label{sub:quicksort}\n\nThere are many sorting algorithms, see for example \\url{http://www.sorting-algorithms.com/}.\nQuicksort is a well known (and quick) sorting algorithm that works as follows:\n\n\\begin{parts}\n    \\part Test whether the list is sorted, if not:\n    \\part Select one part of the list as \\emph{pivot}, any element works.\n    \\part Create a new list, \\texttt{left} and \\texttt{right}, and put all\n        elements smaller than the pivot in the \\texttt{left} list, and all\n        elements larger than the pivot in the \\texttt{right} list.\n    \\part Recursively sort the left and right list, and return\n        \\texttt{sorted left + pivot + sorted right}.\n\\end{parts}\n\nImplement the quicksort algorithm. However, first think about the following caveats\nand how to get around them:\n\\begin{parts}\n    \\part Testing whether a list is sorted takes quite a bit of work, so we\n        do not want to do this. Instead, we want to perform a much simpler check:\n        what list is trivially sorted?\n    \\part What happens when the pivot element occurs multiple times in the list?\n        How can we get around this?\n\\end{parts}\n\n% titledquestion quicksort (end)\n\\end{questions}\n% section recursion (end)\n", "meta": {"hexsha": "40dc656fb361adb8683288fe7444fd02c57cc9e9", "size": 5595, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/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": "exercises/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": "exercises/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": 39.6808510638, "max_line_length": 350, "alphanum_fraction": 0.7352993744, "num_tokens": 1470, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7798341966750855}}
{"text": "\\chapter{Introduction to Neural Network}\n\n\\section{Biological Neural Networks}\n\n\\begin{description}\n\\item[Soma] cell body which processes incoming activations and converts input into output activation\n\\item[Dendrites] receptive zones that receive activation signals from other neurons\n\\item[Axon] transmission lines that send activation signals to other neurons\n\\item[Synapses] allow weighted signal transmission between the dendrites and axons\n\\end{description}\n\n\\section{Artificial Neuron}\nInput signal vector:\n$$\\mathbf{x}=(x_1x_2\\ldots x_p)^{T}$$\nThe weight vector:\n$$\\mathbf{w}=(w_1w_2\\ldots w_p)^{T}$$\nTotal synaptic input:\n\\begin{equation*}\n\\begin{split}\nu &= \\sum_{i=1}^{p} w_ix_i - \\theta \\\\\n\\mathbf{u} &= \\mathbf{w}^{T} \\mathbf{x} - \\pmb{\\theta}\n\\end{split}\n\\end{equation*}\nOutput Activation:\n$$\\mathbf{y} = \\Phi(\\mathbf{u})$$\n\\begin{center}where $\\Phi$ is activation function\\end{center}\n\n\\section{Typical ANN Activation Functions}\nThreshold Activation Function:\n$$\\Phi (u)=\n\\begin{cases} \n    1 & u>0 \\\\\n    0 & otherwise\n\\end{cases}\n$$\nLinear Activation Function:\n$$\\Phi (u) = u$$\nRamp Activation Function:\n$$\\Phi (u) = max\\{ 0, min\\{ 1, u + 0.5 \\} \\}$$\nUnipolar Sigmoid Activation Function:\n$$\\Phi (u) = \\frac{a}{1+exp(-bu)}$$\nBipolar Sigmoid Activation Function:\n\\begin{equation*}\n\\begin{split}\n\\Phi (u) &= a\\Bigg(\\frac{1-exp(-bu)}{1+exp(-bu)}\\Bigg) \\\\\n&= a\\Bigg(-1 + \\frac{2}{1+exp(-bu)}\\Bigg)\n\\end{split}\n\\end{equation*}\n\n\\section{ANN Architecture}\n\\begin{description}\n\\item[Two-Layer Feed-forward Network] input layer + output layer\n\\item[Multilayer Feed-forward Network] input layer + hidden layers + output layer\n\\item[Recurrent networks without hidden neurons] single layer of neurons with each neuron feeding its output signal back to the input layer\n\\end{description}\n\n\\section{Feed-forward ANN Analysis}\nWeight matrix to hidden layer:\n$$\\mathbf{W = [w_1w_2 \\ldots w_J]^{T}}$$\nSynaptic inputs to hidden layer:\n$$\\mathbf{u=Wx}$$\n\\clearpage\n\\noindent Output of hidden layer:\n$$\\mathbf{y}=f(\\mathbf{u})$$\n\\begin{center}where $f$ is activation function of hidden layer neurons \\end{center}\nWeight matrix to output layer:\n$$\\mathbf{V = [v_1v_2 \\ldots v_J]^{T}}$$\nSynaptic inputs to output layer:\n$$s=Vy$$\nOutput:\n$$\\mathbf{z} = g(\\mathbf{s})$$\n\\begin{center}where $g$ is activation function of output layer neurons \\end{center}\n\n\\section{ANN Learning}\n\\begin{description}\n\\item[Supervised Learning] For each training input pattern, the network is presented with the correct target answer by a teacher\n\\item[Unsupervised Learning] For each training inputs, the network adjusts weights without knowing the correct target\n\\end{description}\n\n\\section{Characteristics of ANN}\n\\begin{itemize}\n\\item Parallel and distributed processing\n\\item Adaptiveness\n\\item Generalization\n\\item Fault-tolerance\n\\item Ease of construction\n\\end{itemize}\n\n\\section{ANN Limitations}\n\\begin{itemize}\n\\item Operational problems, computational time increase\n\\item Intractable system, black boxes\n\\end{itemize}", "meta": {"hexsha": "258edef612b06e05a39b5a4008ee147830a04cf8", "size": 3000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter1.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": "chapter1.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": "chapter1.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": 32.2580645161, "max_line_length": 139, "alphanum_fraction": 0.7403333333, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.911179705187943, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7798341957783903}}
{"text": "\\documentclass[../algorithms.tex]{subfiles}\n\\begin{document}\n% \\chapter{Introduction}\nIn this chapter, I will mainly discuss some problems so that we can see how different approaches and algorithms can make difference on the time and space complexity.  \n\\section{Maximum Subarray}\nLeetCode 53. Maximum Subarray\n\nFind the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array $[-2,1,-3,4,-1,2,1,-5,4]$, the contiguous subarray $[4,-1,2,1]$ has the largest sum = 6.\n\\subsection{Brute Force}\nThe brute force solution of this problem is to use two for loops, one pointer at the start position of the subarray, the other point at the end position of the subarray. Then we get the maximum sum of these subarries. The time complexity is $O(n^3)$, where we spent $O(n)$ to the sum of each subarray. The code is writen as: \n\\begin{lstlisting}[language=Python]\nfor i in range(n):\n    for j in range(i+1,n):\n\\end{lstlisting}\nHowever, if we can get the sum of each subarray with $O(1)$. Then we can lower the complexity to $O(n^2)$. Here one solution is to trade space for efficiency. the sum of subarray from index $i$ to $j$ is $sum(i,j)=sum(0,j)-sum(0,i)$. We can pre compute the accumulated sum to each index and save it in an array of the same size, which gives us $O(n^2)$ time complexity and $O(n)$ space complexity. \n\\subsection{Divide and Conquer}\nTo further improve the efficiency, we use divide and conquer, where we divide one array into two halves: the maximum subarray might located on the left size, or the right side, or some in the left side and some in the right size, which crossed the bound. $T(n) = max(T(left),T(right), T(cross))$, max is for merging and the T(cross) is for the case that the potential subarray across the mid point. For the complexity, $T(n)=2T(n/2)+n$, if we use the master method, it would give us $O(nlgn)$. With this solution, we use $O(lgn)$ space for the recursive function stack space.\n\\begin{lstlisting}[language=Python]\ndef maxSubArray(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        def getCrossMax(low,mid,high):\n            left_sum,right_sum =0,0\n            left_max,  right_max = -maxint, -maxint\n            left_i,right_j=-1,-1\n            for i in xrange(mid,low-1,-1): #[)\n                left_sum+=nums[i]\n                if left_sum>left_max:\n                    left_max= left_sum\n                    left_i = i\n            for j in xrange(mid+1,high+1):\n                right_sum+=nums[j]\n                if right_sum>right_max:\n                    right_max= right_sum\n                    right_j = j\n            return (left_i,right_j,left_max+right_max)\n        \n        def maxSubarray(low,high):\n            if low==high:\n                return (low,high, nums[low])\n            mid = (low+high)//2\n            rslt=[]\n            #left_low, left_high, left_sum = maxSubarray(low,mid) #[low,mid]\n            rslt.append(maxSubarray(low,mid)) #[low,mid]\n            #right_low,right_high,right_sum = maxSubarray(mid+1,high)#[mid+1,high]\n            rslt.append(maxSubarray(mid+1,high))\n            #cross_low,cross_high,cross_sum = getCrossMax(low, mid, high)\n            rslt.append(getCrossMax(low, mid, high))\n            return max(rslt, key=lambda x: x[2])\n        return maxSubarray(0,len(nums)-1)[2]\n\\end{lstlisting}\n\\subsection{Dynamic Programming}\nUsing dynamic programming: the $f$ memorize the maximum subarray value till $j$, $f[ j ] = max f [ j- 1] + S [ j ] , S [ j ]$. This would gave us $O(n)$ time complexity and $O(n)$ space complexity.\n\\subsection{Greedy Algorithm}\nBecause $sum(i,j)=sum(0,j)-sum(0,i)$, to till index $j$, we use $f(j)$ represents the maximum subarray value. which gives us relation $f(j) = sum(0,j)-min(Sum(0,i))_{i in [0,j] }, j>=1$\n\\subsection{Prefix Sum}\nconvert this problem to best time to buy and sell stock problem. $[0, -2, -1, -4, 0, -1, 1, 2, -3, 1]$, which is to find the maximum benefit, => O(n), use prefix$\\_$sum, the difference is we set prefix$\\_$sum to 0 when it is smaller than 0, $O(n)$. Or we can try two pointers.\n\\begin{lstlisting}\nfrom   sys import maxint\nclass Solution(object):    \n    def maxSubArray(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        max_so_far = -maxint - 1\n        prefix_sum= 0\n        for i in range(0, len(nums)):\n            prefix_sum+= nums[i]\n            if (max_so_far < prefix_sum):\n                max_so_far = prefix_sum\n \n            if prefix_sum< 0:\n                prefix_sum= 0  \n        return max_so_far\n\\end{lstlisting}\nFrom this problem, we get a peek how using different methods can gradually improve the algorithms' performance.\n\n\\end{document}", "meta": {"hexsha": "8e90acec4230f77b8cac088f719f7c8547a680fc", "size": 4766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/part3_deprc/introduction.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/part3_deprc/introduction.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/part3_deprc/introduction.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": 58.8395061728, "max_line_length": 575, "alphanum_fraction": 0.6437263953, "num_tokens": 1293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425267730008, "lm_q2_score": 0.8479677506936878, "lm_q1q2_score": 0.779827204869961}}
{"text": "%!TEX root=report.tex\n\\subsection{OLS}\nOLS (Ordinary Least Squares) regression is used for finding the best linear unbiased estimator(BLUE) of $Y$ base on one or more exogenous variables $X$. \nThis is done by a matrix-vector product between a $\\beta$ vector and $X$.\nSince $X$ can be custom tailored for various purposes it is often referred to as the design matrix. The model is\n\\begin{align}\nY=X \\beta +\\epsilon && \\text{, where } \\mathrm{E}[\\epsilon] = 0 \\text{ and } \\mathrm{D}[\\epsilon] = \\mathrm{D}[Y] = \\sigma^2 I .\n\\end{align}\n\nIn the equation above the $\\beta$-vector is the unknown parameter which needs to be determined while  $\\epsilon$ is a vector containing the residuals which the model cannot account for.\nOften the purpose of OLS is to predict $Y$, but in this case we want to analyze the individual $\\beta_i$ elements.\n\n\\subsubsection{The solution to the OLS problem}\nAs the name sugest, the OLS method minimizes the sum of squared residuals ($\\epsilon^T \\epsilon$).\nIt is seen directly that $\\epsilon = Y - X \\beta$ and thus the following is obtained\n\\begin{equation}\n\\begin{split}\n\\epsilon^T\\epsilon&=(Y-X\\beta)^T (Y-X\\beta)\\\\\n&=(Y^T-\\beta^T X^T) (Y-X\\beta) \\\\\n&=Y^T Y-\\beta^T X^T Y-Y^T X \\beta + \\beta^T X^T X \\beta \\\\\n&=Y^T Y- 2\\beta^T X^T Y+ \\beta^T X^T X \\beta.\n\\end{split}\n\\end{equation}\n\nOne can now differentiate with respect to the $\\beta$ vector\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial \\epsilon^T\\epsilon}{\\partial \\beta}&=-2 X^T Y+2X^T X \\beta=2(-X^T Y+X^T X \\beta).\n\\end{split}\n\\end{equation}\n\nNow  $\\epsilon^T \\epsilon$'s minimum is given by solving for $\\frac{\\partial \\epsilon^T\\epsilon}{\\partial \\beta} = 0$\n\\begin{equation}\n\\begin{split}\n\\frac{\\partial \\epsilon^T\\epsilon}{\\partial \\beta} = 0 \\Rightarrow 2(-X^T Y+X^T X \\hat{\\beta}) &= 0 \\\\\nX^T X \\hat{\\beta}&=X^T Y \\\\\n\\hat{\\beta}&=(X^T X)^{-1} X^T Y.\n\\end{split}\n\\end{equation}\n\nThe solution above is formally correct \\cite[p.~12]{statistical-learning}, but if $X$ is badly conditioned $(X^T X)^{-1}$ might not be numerically stable (i.e., if the columns in $X$ are highly correlated leading to a near singular $X^T X$) \\cite[p.~8]{aasbjerg-ls}.\nTo avoid this problem $X$ should be factorised and the solution reformulated; in this report we will exclusively do this using SVD\n\\begin{equation}\n\\begin{split}\n\\left( U \\Sigma V^T\\right)^T \\left(U \\Sigma V^T\\right) \\hat{\\beta} &= \\left(U \\Sigma V^T\\right)^T Y \\\\\nV \\Sigma^2 V^T \\hat{\\beta} &= V \\Sigma U^T Y \\\\\n\\left(V \\Sigma^{-2} V^T\\right) V \\Sigma^2 V^T \\hat{\\beta} &= \\left(V \\Sigma^{-2} V^T\\right) V \\Sigma U^T Y \\\\\n\\hat{\\beta} &= V \\Sigma^{-1} U^T Y.\n\\end{split}\n\\end{equation}\n\nIt should be noted, that when multiple $\\hat{\\beta}$ vectors need to be calculated (one vector for each spatial location on the surface) optimization is possible, by arranging $Y$ as a matrix with each column corresponding to a location.\n$\\hat{\\beta}$ will then be a matrix containing all solutions instead of a vector containing only one solution.\n\n\\subsubsection{The ``Hat\" matrix}\nIn the special case of the GRACE data, the $X$ matrix is identical for every position. This can be exploited by constructing a hat matrix $H$ which only depends on $X$ and projects $Y$ onto $\\hat{Y}$ (puts the hat on $Y$).\n\\begin{equation}\n\\begin{split}\n\\hat{Y} &= X \\hat{\\beta} \\Rightarrow \\hat{Y} = X V \\Sigma^{-1} U^T Y \\\\\n\\hat{Y} &= H Y \\quad \\text{, where } H =X(X^{T}X)^{-1}X^{T}= X V \\Sigma^{-1} U^T.\n\\end{split}\n\\end{equation}\n\nAs earlier with $\\beta$, the hat matrix can be calculated for all $Y$ vectors by vertically stacking $Y$ to form a matrix.\n\nAn important property of the $H$ matrix is that it is idempotent ($H^2 = H$) and symmetrical ($H^T = H$).\nThis is because $H$ is a projection matrix which projects $Y$ onto $\\hat{Y}$.\nProjecting $Y$ onto $\\hat{Y}$ and then projecting again onto $\\hat{Y}$, will obviously not change anything, because one is already in the $\\hat{Y}$-plane, spanned by the columns of $X$.\n\n\\subsubsection{Root Mean Squared Error}\n\nThe ``Root Mean Squared Error'' (RMSE) is an indicator of how good an $Y$ estimate is.\nIt can be calculated as\n\\begin{equation}\n\\hat{\\sigma} = \\sqrt{\\frac{\\left(Y - \\hat{Y}\\right)^T \\left(Y - \\hat{Y}\\right)}{n-m}},\n\\end{equation}\n\nwhere $m$ is the number of parameters (elements in $\\beta$) and $n$ is the number of observations (elements in $Y$).\nRMSE is an estimate for the standard deviation of $Y$ \\cite[theorem~3.4]{time-series-analysis} thus the symbol $\\hat{\\sigma}$.\n\n\n\\subsubsection{The variance of $\\hat{Y}$}\n\nThe dispersion (variance-covariance) of $\\hat{Y}$ can be calculated as\n\\begin{equation}\n\\mathrm{D}[\\hat{Y}] = \\mathrm{D}[H Y] = H \\mathrm{D}[Y] H^T = \\sigma^2 H^2 = \\sigma^2 H.\n\\end{equation}\n\nThe variance of $\\hat{Y_i}$ is given by the diagonal elements in $\\mathrm{D}[\\hat{Y}]$\n\\begin{equation}\n\\mathrm{Var}[\\hat{Y_i}] = \\sigma^2 H_{ii}.\n\\end{equation}\n\nBecause $\\sigma^2$ is a scalar, the diagonal in $H$ is important to examine, since it can reveal potential elements (in our case points of time) with high variance in the predictions.\n\n\\subsubsection{The dispersion of $\\hat{\\boldsymbol\\beta}$}\n\nThe dispersion of $\\hat{\\beta}$ is calculated as \\cite[theorem~3.2]{time-series-analysis}:\n\\begin{equation}\n\\mathrm{D}[\\hat{\\beta}] = \\sigma^2 (X^T X)^{-1} = \\sigma^2 V \\Sigma^{-2} V^T\n\\end{equation}\n\nSince $\\sigma^2$ is a scalar and dependent of $Y$, a similar spatial independent expression can be made, by removing the scalar $\\sigma^2$  factor, thus looking exclusively at $V \\Sigma^{-2} V^T$.\n\n\\subsubsection{p-values for $\\hat{\\boldsymbol\\beta}$}\n\nAssuming the residuals are normally distributed, the p-values for OLS parameters can be calculated using the student's t-distribution, with the t-score \\cite[p.~172]{time-series-analysis}\n\\begin{align}\n\\mathrm{t} = \\frac{\\hat{\\beta_i}}{\\mathrm{SD}[\\hat{\\beta_i}]} && \\text{where: } \\mathrm{SD}[\\hat{\\beta_i}] = \\sqrt{\\mathrm{Cov}[\\hat{\\beta}]_{ii}} = \\hat{\\sigma} \\sqrt{ (V \\Sigma^{-2} V^T)_{ii} }.\n\\end{align}\n\nNow by plugging the t-score into the Student's Cumulative distribution function ($\\Phi_t$) with $N - p$ degrees of freedom, we get\n\\begin{equation}\np = 2 \\cdot \\Phi_t\\left(\\mathrm{abs}(t), N-p\\right)\n\\end{equation}\n\nThe null-hypothesis is that $\\beta_i = 0$ and the alternative hypothesis is $\\beta_i \\not = 0$.\n", "meta": {"hexsha": "ae6a5136d796a72a43bbb546d6bb2db44db07ea1", "size": 6281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Rapport/theory-ols.tex", "max_stars_repo_name": "AndreasMadsen/grace", "max_stars_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-05-17T22:52:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-17T22:52:19.000Z", "max_issues_repo_path": "Rapport/theory-ols.tex", "max_issues_repo_name": "AndreasMadsen/grace", "max_issues_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Rapport/theory-ols.tex", "max_forks_repo_name": "AndreasMadsen/grace", "max_forks_repo_head_hexsha": "bf472d30a2fac76145d3f68e819c92da4a1970ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.2288135593, "max_line_length": 266, "alphanum_fraction": 0.6939977711, "num_tokens": 2004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942144788077, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7797081018821969}}
{"text": "\\documentclass{article}\r\n\\title{Dual Derivations of ALO for Elastic Net}\r\n\\author{Yuze Zhou}\r\n\\usepackage{amsmath}\r\n\\usepackage{amsfonts}\r\n\\usepackage{graphicx}\r\n\\usepackage{algorithm}\r\n\\usepackage{subfigure}\r\n\\begin{document}\r\n\\maketitle\r\n\\section{Dual Problem of Elastic Net}\r\n\\paragraph{}The original problem for elastic net is to solve for $\\hat{\\beta}$ such that:\r\n\\begin{center}\r\n$\\hat{\\beta} = \\arg \\min\\limits_{\\beta} \\frac{1}{2}||y-X\\beta||_{2}^{2} + \\lambda_{1}||\\beta||_{1}+\\lambda_{2}||\\beta||_{2}^{2}$\r\n\\end{center}\r\n\\paragraph{}By adding the Lagrangian, we get the formulation of $L$:\r\n\\begin{center}\r\n$L = \\frac{1}{2}||y-z||_{2}^{2} + \\lambda_{1}||\\beta||_{1}+\\lambda_{2}||\\beta||_{2}^{2}+u^{\\tau}(z-X\\beta)$\r\n\\end{center}\r\n\\paragraph{}The original problem is solving the primal of the Lagrangian such that $p^{*} = \\min\\limits_{\\beta,z}\\max\\limits_{u}L$ and the dual formulation $d^{*} = \\max\\limits_{u}\\min\\limits_{\\beta,z}L$, to minimize over $z$:\r\n\\begin{center}\r\n$\\frac{\\partial L}{\\partial z} = z -y +u = 0$\\\\\r\n$y = u + z$\\\\\r\n\\end{center}\r\n\\paragraph{}Since $\\beta$ is penalized element-wisely, we can minimize over $\\beta$ by minimizing over each $\\beta_{i}$, that is, we have to minimize $\\lambda_{1}|\\beta_{i}| + \\lambda_{2}\\beta_{i}^{2} - u^{\\tau}X_{i}\\beta$ for each dimension of $\\beta$, where $X_{i}$ denotes the $i$th column of $X$, therefore:\r\n\\begin{center}\r\n$\\min\\limits_{\\beta}\\lambda_{1}|\\beta_{i}| + \\lambda_{2}\\beta_{i}^{2} - u^{\\tau}X_{i}\\beta = $\\\\\r\n$ $\\\\\r\n$= \\left\\{\r\n\\begin{aligned}\r\n0 \\quad if \\quad |u^{\\tau}X_{i}| \\leq \\lambda_{1}\\\\\r\n-\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}} \\quad if \\quad |u^{\\tau}X_{i}| > \\lambda_{1}\\\\\r\n\\end{aligned}\r\n\\right.\r\n$\r\n\\end{center}\r\n\\paragraph{}By taking all the above to the Lagrangian, we could obtain the dual problem $d^{*}$ as:\r\n\\begin{center}\r\n$d^{*} = \\min\\limits_{u} \\frac{1}{2}||y-u||_{2}^{2} + \\sum\\limits_{j: |X_{j}^{\\tau}u| > \\lambda_{1}}\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}}$\r\n\\end{center}\r\n\\paragraph{}The minimizer $\\hat{u}$ could also be obtained from the dual problem through a proximal approach:\r\n\\begin{center}\r\n$\\hat{u} = \\textbf{prox}_{R}(y) \\quad where \\quad R(u) = \\sum\\limits_{j: |X_{j}^{\\tau}u| > \\lambda_{1}}\\frac{(\\lambda_{1}-|u^{\\tau}X_{i}|)^{2}}{4\\lambda_{2}}$\r\n\\end{center}\r\n\\section{ALO Estimation for Elastic Net}\r\n\\paragraph{}By replacing the full data problem $y$ with $y_{\\alpha} = y + (y_{i}^{/i}-y_{i})e_{i}$, where $y_{i}^{/i}$ is the true loo estimator and $e_{i}$ is the $i$th standard vector, and let $u^{/i} = \\textbf{prox}_{R}(y_{\\alpha})$, therefore:\r\n\\begin{align*}\r\n0 &= e_{i}^{\\tau}u^{/i}\\\\\r\n& = e_{i}^{\\tau}\\textbf{prox}_{R}(y_{\\alpha})\\\\\r\n& \\approx e_{i}^{\\tau}(\\textbf{prox}_{R}(y)+J_{R}(y)(y_{\\alpha}-y))\\\\\r\n& \\approx \\hat{u}_{i} + J_{ii}(y_{i}^{/i}-y_{i})\r\n\\end{align*}\r\n\\paragraph{}Here $J_{R}(y)$ denotes the Jacobian matric of the proximal operator at $y$, thus the alo estimator $\\tilde{y}_{i}$ is obtained as \r\n\\begin{center}\r\n$\\tilde{y}_{i} = y_{i} - \\frac{\\hat{u}_{i}}{J_{ii}}$\r\n\\end{center}\r\n\\paragraph{}The Jacobian could locally be obtained as:\r\n\\begin{align*}\r\nJ_{R}(y) &= (I+\\nabla^{2}R(\\textbf{prox}_{R}(y)))^{-1}\\\\\r\n&= (I + \\nabla^{2}R(\\hat{u}))^{-1}\\\\\r\n&= (I + \\frac{1}{2\\lambda_{2}}X_{E}X_{E}^{\\tau})^{-1}\\\\\r\n\\end{align*}\r\n\\paragraph{}Here $E = \\{j:|X_{j}^{\\tau}u|>\\lambda_{1}\\}$.\r\n\\end{document}", "meta": {"hexsha": "12d9d6628f7f57998c62d9c449ddebabb29dd018", "size": 3370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "elasticnetdual.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": "elasticnetdual.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": "elasticnetdual.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": 52.65625, "max_line_length": 312, "alphanum_fraction": 0.6172106825, "num_tokens": 1315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059267, "lm_q2_score": 0.8902942188450159, "lm_q1q2_score": 0.7797080927174835}}
{"text": "\\chapter{Introduction}\n\n\\section{Metric space}\n\nA metric $d$ on a set $X$, also called a distance function, is a function\nthat defines a distance between each pair of elements of the set. A\nset with a metric is called a \\textbf{metric space}.\\\\\n\nFormally, $d : X \\times X \\rightarrow R$ is a metric if it is a function satisfying the following properties $\\forall x, y, z \\epsilon X$:\n\\begin{enumerate}\n\\item{Non-negativity : $d(x, y) \\geq 0$}\n\\item{Indiscernability : $d(x, y) = 0$ iff $x = y$}\n\\item{Symmetry : $d(x, y) = d(y, x)$}\n\\item{Subadditivity : $d(x, y) + d(y, z) \\geq d(x, z)$}\n\\end{enumerate}\n\\section{The Christofides' algorithm}\nThe Christofides' algorithm is an approximation algorithm for Metric TSP with an approximation ratio of $1.5$. Let G be a graph with $n$ points in the euclidean metric space. Below is a description of the steps involved in the Christofides' algorithm.\n\\vspace{0.7in}\n\\subsection{Pseudo code}\n\\textbf{Algorithm}\n\\begin{enumerate}\n    \\item{\n        Find an MST of $G$, say $T$.        \n    }\n    \\item {Compute a minimum cost perfect matching, $M$, on the set of odd-degree vertices of $T$.}\n    \\item {\n        Add $M$ to $T$ and obtain an Eulerian multi-graph $H$.\n    }\n    \\item {Find an Euler tour, $E$ of this graph.\n    }\n    \\item {Output the tour that visits vertices of $G$ in order of their first appearance in $E$.}\n\\end{enumerate}\n\\begin{figure}[h]\n    \\centering\n    \\caption{MST $T$ of $G$}\n    \\includegraphics[scale=0.3]{1.jpg}\n\\end{figure}        \n\\begin{figure}[h]\n    \\centering\n    \\caption{Multi-graph $H$ of $G$}\n    \\includegraphics[scale=0.3]{2.jpg}\n\\end{figure}\n\\begin{figure}[h]\n    \\centering\n    \\caption{Euler tour $E$ of $H$}\n    \\includegraphics[scale=0.3]{3.jpg}\n\\end{figure}\n\\subsection{Time complexity}\n\\begin{enumerate}\n    \\item {Creating MST $T$ of $G$ : $O(nlogn)$}\n    \\item {Finding the minimum cost perfect matching $M$ : $O(n^3)$}\n    \\item {Creating multi-graph H : $O(n)$}\n    \\item {Finding Euler tour $E$ in $H$ : $O(n)$}\n\\end{enumerate}\n% some text\\cite{citation-1-name-here}, some more texts\n% even more text\\footnote{<footnote here>}, and even more.\n% \\section{Motivation}\n", "meta": {"hexsha": "55177664530ed44114bf91b3756100cdad28c9bf", "size": 2166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "introduction.tex", "max_stars_repo_name": "jaiteshp/CS6100-Christofides-ShortCutting-Heurisitcs-Project-Report", "max_stars_repo_head_hexsha": "5819512e75e1a145faa47d4a0168a03d2e9c5c33", "max_stars_repo_licenses": ["MIT"], "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": "jaiteshp/CS6100-Christofides-ShortCutting-Heurisitcs-Project-Report", "max_issues_repo_head_hexsha": "5819512e75e1a145faa47d4a0168a03d2e9c5c33", "max_issues_repo_licenses": ["MIT"], "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": "jaiteshp/CS6100-Christofides-ShortCutting-Heurisitcs-Project-Report", "max_forks_repo_head_hexsha": "5819512e75e1a145faa47d4a0168a03d2e9c5c33", "max_forks_repo_licenses": ["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.3448275862, "max_line_length": 251, "alphanum_fraction": 0.6643582641, "num_tokens": 687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942173896131, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.7797080899996848}}
{"text": "\n\\subsection{Gibb's sampling}\n\n\\subsubsection{Introduction}\n\nAs with Metropolis-Hastings, we want to generate samples for \\(P(X)\\) and use this to approximate its form.\n\nWe do this by using the conditional distribution. If \\(X\\) is a vector then we also have:\n\n\\(P(x_j|x_0,...,x_{j-1},x_{j+1},...,x_n)\\)\n\nWe use our knowledge of this distribution.\n\nStart with vector \\(x_0\\).\n\nThis has components \\(x_{0,j}\\)\n\nTo form the next vector \\(x_1\\) we loop through each component.\n\n\\(P(x_{1,0}|x_{0,0},x_{0,1},...,x_{0,n})\\)\n\nWe use this to form \\(x_{1,0}\\)\n\nHowever after th the first component we update this so it uses the updated variables.\n\n\\(P(x_{1,k}|x_{1,0},...,x_{1,k-1},x_{0,k},...,x_{0,n}\\)\n\nThis means we only need to know the conditional distributions.\n\n", "meta": {"hexsha": "d781e5e3e24a487a361bdf62adcd81e63329aa50", "size": 760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/samplingMCMC/03-01-gibbs.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/samplingMCMC/03-01-gibbs.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/samplingMCMC/03-01-gibbs.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.3333333333, "max_line_length": 107, "alphanum_fraction": 0.6802631579, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554476, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7796164075740916}}
{"text": "\\documentclass{article}\n\n\n\\include{stddefs}\n\\include{imodefs}\n\n\\newcommand{\\vect}[2]{\\begin{pmatrix} #1 \\\\ #2 \\end{pmatrix}}\n\\newcommand{\\vects}[3]{\\begin{pmatrix} #1 \\\\ #2 \\\\ #3\\end{pmatrix}}\n\\newcommand{\\hphm}{\\hphantom{-}}\n\n\n\\chapterno{5}\n\n\\begin{document}\n\n\n\n\\chapter{Euclidean vector spaces}\n\nBig data are made up of many numbers in data sets. Such data sets can\nbe represented as vectors in a high dimensional euclidean vector\nspace. A vector is nothing but a list of numbers, but we need to talk\nmathematically about the size of a vector and perform operations on\nvectors. The term euclidean refers to vectors with a dot product as\nknown from the plane $\\RR^2$.\n\nThe purpose of this chapter is to set the stage for this,\nespecially by introducing the dot product (or inner product) for\ngeneral vectors. Having a dot product is immensely useful and we give several\napplications like linear regression and the perceptron learning algorithm\n\nIn the last part of the chapter rudimentary basics of analysis\nare introduced like sequences, continuous functions, open, closed\nand compact subsets. Some results will in this context only\nbe quoted and not proved.\n\n\n\n\n\\section{Vectors in the plane}\n\nThe dot product (or inner product) between two vectors $u, v\\in \\RR^2$ is\ngiven by\n\\begin{equation}\\label{smhack}\nu\\cdot v = x_1 x_2 + y_1 y_2,\n\\end{equation}\nwhere\n\\begin{equation}\nu = \\begin{pmatrix} x_1 \\\\ y_1 \\end{pmatrix}\\qquad\\text{and}\\qquad\nv = \\begin{pmatrix} x_2 \\\\ y_2 \\end{pmatrix}.\n\\end{equation}\nWe may also interpret\n$u$ and $v$  as $2\\times 1$ matrices (or column vectors).\nThen the dot product in\n\\eqref{smhack} may be realized as the matrix product:\n$$\nu\\cdot v = u^T v.\n$$\nThe length or \\emph{norm} of the vector $u\\in \\RR^2$ is given by\n$$\n\\abs{u} = \\sqrt{u\\cdot u} = \\sqrt{u^T u} = \\sqrt{x_1^2 + y_1^2}.\n$$\nThis follows from the \\url{Pythagorean theorem}{https://en.wikipedia.org/wiki/Pythagorean_theorem}:\n\n\\includegraphics{Pythagoras.svg}\n\n\nAlso, the cosine of the angle $\\theta$ between $u$ and $v$ is given by\n$$\n\\cos(\\theta) = \\frac{u\\cdot v}{\\abs{u}\\abs{v}}\\qquad\\text{or}\\qquad u \\cdot v = \\abs{u} \\abs{v} \\cos(\\theta).\n$$\nWe will not go into this formula. It is a byproduct of considering the projection of a vector on\nanother vector (see Exercise \\ref{dim2vec}).\n\n\\section{Higher dimensions}\n\nThe notions of dot product, norm and the formula for cosine of the\nangle generalize immediately to vectors in dimensions\nhigher than two.\n\nWe denote the set of column vectors with $d$ rows\nby $\\RR^d$ and call it the euclidean vector space of\ndimension $d$. An element $v\\in \\RR^d$ is called a vector and it has\nthe form (column vector with $d$ entries)\n$$\nv =\n\\begin{pmatrix}\n  x_1 \\\\\n  x_2 \\\\\n  \\vdots\n  \\\\\n  x_d\n\\end{pmatrix}.\n$$\n\nA vector in $\\RR^d$ is a model for a data set in real life. A collection\nof $d$ numbers, which could signify $d$ measurements. You will see\nan example of this below, where a vector represents a data set\ncounting words in a string.\n\nBeing column vectors, vectors in $\\RR^d$ can be added and multiplied by\nnumbers:\n$$\n\\begin{pmatrix}\n  x_1 \\\\\n  x_2 \\\\\n  \\vdots\n  \\\\\n  x_d\n\\end{pmatrix} + \n\\begin{pmatrix}\n  y_1 \\\\\n  y_2 \\\\\n  \\vdots\n  \\\\\n  y_d\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n  x_1 + y_1 \\\\\n  x_2 + y_2\\\\\n  \\vdots\n  \\\\\n  x_d + y_d\n\\end{pmatrix}\\qquad\\qquad\n\\lambda\n\\begin{pmatrix}\n  x_1 \\\\\n  x_2 \\\\\n  \\vdots\n  \\\\\n  x_d\n\\end{pmatrix} =\n\\begin{pmatrix}\n  \\lambda x_1 \\\\\n  \\lambda x_2 \\\\\n  \\vdots\n  \\\\\n  \\lambda x_d\n\\end{pmatrix}.\n$$\n\nThe dot product generalizes as follows to higher dimensions.\n\n\\subsection{Dot product and norm}\n\n\\begin{definition}[emph]\nThe dot product of\n$$\nu =\n\\begin{pmatrix}\n  x_1 \\\\\n  x_2 \\\\\n  \\vdots\n  \\\\\n  x_d\n\\end{pmatrix}\\qquad\n\\text{and}\n\\qquad\nv =\n\\begin{pmatrix}\n  y_1 \\\\\n  y_2 \\\\\n  \\vdots\n  \\\\\n  y_d\n\\end{pmatrix}\n$$\nis defined by\n\\begin{equation}\\label{dotpr}\nu\\cdot v = u^T v = x_1 y_1 + x_2 y_2 + \\cdots + x_d y_d.\n\\end{equation}\n\n\nThe norm of $u\\in \\RR^d$ is defined by\n\\begin{equation}\\label{vecnorm}\n\\abs{u} = \\sqrt{u\\cdot u} = \\sqrt{x_1^2 + x_2^2 + \\cdots + x_d^2}.\n\\end{equation}\n\n\nA vector $e\\in \\RR^d$ with $\\abs{e}=1$ is called a \\emph{unit vector}.\n\nTwo vectors $u, v\\in \\RR^d$ are called \\emph{orthogonal} if $u\\cdot v = 0$. We write\nthis as $u \\perp v$.\n\n\\end{definition}\n\n\\beginshex\nShow that\n$$\nu \\perp u \\iff u = 0,\n$$\nwhere $u\\in \\RR^d$.\n\\endshex\n\n\n\\beginshex\\label{normrules}\nUse the definition in \\eqref{dotpr} to show that\n\\begin{align*}\n  u\\cdot (v + w) &= u\\cdot v + u\\cdot w\\\\\n  (\\lambda u)\\cdot v &= u\\cdot (\\lambda v) = \\lambda (u\\cdot v)\n\\end{align*}\nfor $u, v, w\\in \\RR^d$ and $\\lambda\\in\\RR$.\n\\endshex\n\n\n\\beginshex\nLet $u\\in \\RR^d$ be a nonzero vector and $\\lambda\\in \\RR$. Use the definition\nin \\eqref{vecnorm} to show that\n$|\\lambda u| = |\\lambda| \\, |u|$ and that\n$$\n\\frac{1}{|u|} u\n$$\nis a unit vector.\n\n\\begin{hideinbutton}{Hint}\n  You could perhaps use Exercise \\ref{normrules} to do this. Notice also that\n  $|\\lambda|$ is the absolute value for $\\lambda$ if $\\lambda\\in \\RR$. \n\\end{hideinbutton}\n\\endshex\n\n\\beginshex\\label{dim2vec}\nGiven two vectors $u, v\\in \\RR^d$ with $v\\neq 0$, find $\\lambda\\in \\RR$, such\nthat $u - \\lambda v$ and $v$ are orthogonal, i.e.\n$$\n(u - \\lambda v) \\cdot v = 0.\n$$\n\n\\begin{hideinbutton}{Hint}\n  $$\n  (u - \\lambda v) \\cdot v = 0 \\iff (u\\cdot v) - \\lambda (v\\cdot v) = 0.\n  $$\n  This is an equation, where $\\lambda$ is unknown!\n\\end{hideinbutton}\n\nFor $d=2$, it is sketched below\nthat if $u - \\lambda v$ and $v$ are orthogonal, then\n$u, \\lambda v$ and $u-\\lambda v$ are the sides in a right triangle.\n\n\\includegraphics{opggymkap5.png}\n\n\nIn this case, if $\\theta$ is the angle between $u$ and $v$, show that\n$$\n\\abs{u} \\cos(\\theta) = \\abs{v} \\lambda.\n$$\nUse this to show that\n$$\nu\\cdot v = \\abs{u} \\abs{v} \\cos(\\theta).\n$$\nFinally show that\n$$\n\\cos(A - B) = \\cos(A) \\cos(B) + \\sin(A) \\sin(B),\n$$\nwhere $A$ and $B$ are two angles.\n\n\\begin{hint}[showhide]\nIn the last question, you could use that the vectors\n$$\n\\begin{pmatrix}\n  \\cos(A)\\\\ \\sin(A)\n\\end{pmatrix}\\qquad\\text{and}\\qquad\n\\begin{pmatrix}\n  \\cos(B)\\\\ \\sin(B)\n\\end{pmatrix}\n$$\nare unit vectors.\n\\end{hint}\n\\endshex\n\n\n\\beginshex\nGiven two vectors $u, v\\in \\RR^d$, solve the minimization problem\n\\begin{align*}\n  &\\text{Minimize} &\\abs{u - \\lambda v}&\\\\\n  &\\text{with constraint}\\\\\n  &&\\lambda\\in\\RR.\n\\end{align*}\n\n\\begin{hint}[showhide]\n  First convince yourself that $\\lambda$ minimizes $\\abs{u - \\lambda v}$\n  if and only if it minimizes\n  $$\n  (u - \\lambda v)\\cdot (u - \\lambda v) = \\abs{v}^2 \\lambda^2 - 2 (u\\cdot v)\\lambda + \\abs{u}^2,\n  $$\n  which happens to be a quadratic polynomial in $\\lambda$.\n\\end{hint}\n\\endshex\n\n\\begin{quizexercise}[showhide]\n\\begin{quiz}\n\\question\nLet $d$ denote the distance from $(1, 1)$ to the line through $(0, 0)$ and $(2, 1)$. What is true about $d$?\n\\answer{F}\n$$\nd = \\frac{1}{2}.\n$$\n\\answer{F}\n$$\nd = 0.447214.\n$$\n\\answer{T}\n$$\nd = \\frac{\\sqrt{5}}{5}.\n$$\n\\answer{F}\n$$\nd = \\frac{2}{\\sqrt{5}}.\n$$\n\\end{quiz}\n\\end{quizexercise}\n\n\n\n\\begin{hideinbutton}{The dist formula from high school}\n  The infamous \\url{dist formula}{https://www.webmatematik.dk/lektioner/matematik-b/geometri/distanceformlen} from high school says that the distance from the point $(x_1, y_1)$ to the line\n  given by $y = a x + b$ is\n  \\begin{equation}\\label{distform}\n  \\frac{\\abs{a x_1 + b - y_1}}{\\sqrt{a^2 + 1}}.\n  \\end{equation}\n  Where does this magical formula come from? Consider a general line $L$ in parametrized form\n  $$\n  L = \\{ u + t v\\mid t\\in \\RR\\} \\subseteq \\RR^d.\n  $$\n  If $w\\in \\RR^d$, then the distance from $w$ to $L$ is given by the solution $t_0$ to the\n  optimization problem\n  \\begin{align}\\label{distopt}\n  &\\text{min}\\, (w - (u + t v))\\cdot (w - (u + t v))\\\\\n  &t\\in \\RR.\n\\end{align}\nThis looks scary, but simply boils down to finding the top point of a parabola. The solution is\n$$\nt_0 = \\frac{v\\cdot w - u\\cdot v}{v\\cdot v}\n$$\nand the point on $L$ closest to $w$ is $u + t_0 v$.\n\nNow we put\n$$\nu = \\begin{pmatrix} 0 \\\\ b \\end{pmatrix}, \\quad v = \\begin{pmatrix} 1 \\\\ a \\end{pmatrix}\\quad\\text{and}\\quad w = \\begin{pmatrix} x_1 \\\\ y_1 \\end{pmatrix}\n$$\nin order to derive \\eqref{distform}. The solution to \\eqref{distopt} becomes\n$$\nt_0 = \\frac{x_1 + a y_1 - a b}{1 + a^2}.\n$$\nWe must compute the distance $D$ from $w$ to $u + t_0 v$ in this case. The distance\nsquared is\n\\begin{align*}\nD^2 &= |w - (u + t_0 v)|^2 = (w - (u + t_0 v))\\cdot (w - (u + t_0 v)) \\\\ \n    &=(x_1 - t_0)^2 + (y_1 - b - t_0 a)^2.\n\\end{align*}\nThis is a mouthful and I have to admit that I used symbolic software (see below) to verify that\n$$\nD^2 = \\frac{a^2 x_1^2 + 2 a b x_1 - 2 a x_1 y_1 + b^2 - 2 b y_1 + y_1^2}{1 + a^2} =\n\\frac{(a x_1 + b - y_1)^2}{1+a^2}.\n$$\n\\begin{sage}\nvar('x1 y1 a b')\nt0 = (x1 + a*y1 - a*b)/(1 + a^2)\nD2 = (x1 - t0)^2 + (y1 - b - t0*a)^2\nprint(factor(D2))\n\\end{sage}\n\\end{hideinbutton}\n\n\\subsection{The perceptron algorithm}\\label{sectperceptron}\n\nAlready at this point we have the necessary definitions for explaining the\nperceptron algorithm. This is one of the early algorithms of machine learning.\nIt aims at finding a high dimensional line (hyperplane) that separates data\norganized in two clusters.\n\nIn terms of the dot product, the core of the algorithm is described in\nthe example below.\n\n\\begin{example}\\label{exampleperceptronsimple}\n\n\n\n\n  Given finitely many vectors $v_1, \\dots, v_n\\in \\RR^d$, can we find\n  $\\alpha\\in \\RR^d$, such that\n  $$\n  \\alpha\\cdot v_i > 0\n  $$\n  for every $i = 1, \\dots, n$?\n\n\n  \n\\beginshex\nCome up with a simple example, where this problem is unsolvable i.e., come\nup with vectors $v_1, \\dots, v_n\\in \\RR^d$, where such an $\\alpha$ does not\nexist.\n\n\\begin{hideinbutton}{Hint}\n  Try out some simple examples for $d=1$ and $d=2$.\n\\end{hideinbutton}  \n\\endshex\n\n\\beginshex\nSuppose that there exists $\\alpha\\in \\RR^d$, such that\n$\\alpha\\cdot v_i > 0$ for every $i = 1, \\dots, n$. Show then that\nthere exists $\\alpha^*\\in \\RR^d$, such that\n$$\n\\alpha^* \\cdot v_i \\geq 1\n$$\nfor every $i = 1, \\dots, n$.\n\n\\begin{hideinbutton}{Hint}\n  Let $\\mu = \\min(\\alpha\\cdot v_1, \\dots, \\alpha\\cdot v_n)$. Show that\n  $\\alpha^* = \\frac{1}{\\mu} \\alpha$ works.\n\\end{hideinbutton}\n\\endshex\n\nIn case $\\alpha$ exists, the following\nridiculously simple algorithm \\footnote{works}{If you are interested in why the algorithm stops, click on the button after the example to read more about the perceptron algorithm} for finding $\\alpha$:\n\n  \\begin{enumerate}[(i)]\n  \\item Begin by putting $\\alpha = 0$.\n  \\item If there exists $v_i\\in \\{v_1, \\dots, v_n\\}$ with $\\alpha\\cdot v_i \\leq 0$, then replace\n    $\\alpha$ by $\\alpha + v_i$ and repeat this step. Otherwise $\\alpha$ is the desired output vector.\n  \\end{enumerate}\n    \nLet us try out the algorithm on the simple example of just\ntwo points in $\\RR^2$ given by\n$$\nv_1 = \\vect{-1}{\\hphm 1}\\qquad\\text{and}\\qquad v_2 =\n\\vect{1}{0}.\n$$\n\nIn this case the algorithm proceeds as pictured below.\n\n\n\n$$\n\\alpha = \\vect{0}{0}\\xrightarrow{+v_1} \\vect{-1}{\\hphm 1} \\xrightarrow{+v_2} \\vect{0}{1} \\xrightarrow{+v_2}\\vect{1}{1} \\xrightarrow{+v_1}\\vect{0}{2} \\xrightarrow{+v_2} \\vect{1}{2}.\n$$\n\nIt patiently crawls its way ending with the vector $\\alpha = \\vect{1}{2}$, which\nsatisfies $\\alpha\\cdot v_1 > 0$ and $\\alpha\\cdot v_2 > 0$.\n\n\\includegraphics{perceptronsimple.png}\n\n\\end{example}\n\n\n\\begin{hideinbutton}{The perceptron algorithm}\nThe perceptron algorithm is a fancy name for a surprisingly simple\nalgorithm for computing a hyperplane that divides binary labeled\npoints.\n\nWe will assume that $x_1, \\dots, x_n$ are\npoints in $\\RR^d$ each of which is labeled by\na number $l_i\\in \\{-1, 1\\}$.\n\nAssuming that you can find a (separating) hyperplane $\\alpha^T v = \\beta$,\nsuch that\n$$\n\\alpha^T x_i > \\beta\\qquad\\text{if}\\qquad l_i = 1\n$$\nand\n$$\n\\alpha^T x_i < \\beta\\qquad\\text{if}\\qquad l_i = -1.\n$$\n\n\n\\includegraphics{perceptronsephyp.png}\n\n\nWe are interested in given the points and their labels in\ncomputing $\\alpha\\in \\RR^d$ and $\\beta\\in \\RR$. In machine learning\nthe term \\emph{training the algorithm} is used pointing\ntowards using the hyperplane for future points not in\nthe initial data set.\n\n\nAn extremely useful trick is to add one more dimension\nand study the problem in $\\RR^{d+1}.$ We replace\neach point\n\n$$\nx_i\\in \\RR^d\\qquad\\text{ by }\\qquad \\hat{x_i} = (l_i x_i, l_i)\\in \\RR^{d+1}.\n$$\n\nThe original problem is now equivalent to finding $\\hat{\\alpha}\\in \\RR^{d+1}\\setminus\\{0\\}$,\nsuch that\n\\begin{equation}\\label{liftproblem}\n\\hat{\\alpha}^T \\hat{x_i} > 0\n\\end{equation}\nfor every $i = 1, \\dots, n$. If such an $\\hat{\\alpha} = (\\alpha_1, \\dots, \\alpha_d, t)^T$ can\nbe found, then we may take $\\alpha = (\\alpha_1, \\dots, \\alpha_d)^T$ and $\\beta = -t$ as\na solution to our original problem.\nOn the other hand, if $\\alpha$ and $\\beta$ solve our original problem, then\n$\\hat{\\alpha} = (\\alpha, -\\beta)$ solves \\eqref{liftproblem}.\n\n\nWe have reduced our original problem to a simpler problem in\none more dimension. We will focus on this problem (now $d+1$ is\nreplaced by $d$):\n\nSuppose that we are given points $x_1, \\dots, x_n\\in \\RR^d$ and\nthere exists $\\alpha\\in \\RR^d\\setminus \\{0\\}$, such that\n$\\alpha^T x_i > 0$ for every $i = 1, \\dots, n$. Geometrically\nthis means that all the points are on one side of the\nhyperplane $\\alpha^T v = 0$.\n\n\\includegraphics{perceptronsephpplusone.png}\n\n\nWe are interested in computing such an $\\alpha$. This is exactly\nwhat is done by the simple\nalgorithm presented in Example \\ref{exampleperceptronsimple}.\n\n\\begin{example}\\label{Examplepercep}\nConsider the points\n$$\nv_1 = \\vect{0}{0},\\qquad v_2=\\vect{1}{1}\\qquad\\text{and}\\qquad v_3=\\vect{\\hphm 1}{-1}\n$$\nin $\\RR^2$, where $v_1$ and $v_2$ are labeled by $+1$ and $v_3$ is labeled by $-1$. Then\n$$\n\\hat{v}_1 = \\vects{0}{0}{1},\\qquad \\hat{v}_2 = \\vects{1}{1}{1}\\qquad\n\\text{and}\\qquad \\hat{v}_3 = \\vects{-1}{\\hphm 1}{-1}.\n$$\nNow we run the simple algorithm from Example \\ref{exampleperceptronsimple}:\n$$\n\\hat{\\alpha} = \\vects{0}{0}{0}\\xrightarrow{+\\hat{v}_1} \\vects{0}{0}{1} \\xrightarrow{+\\hat{v}_3} \\vects{-1}{\\hphm 1}{\\hphm 0} \\xrightarrow{+\\hat{v}_1} \\vects{-1}{\\hphm 1}{\\hphm 1}.\n$$\n\nFrom the last vector we see that $\\alpha = \\vect{-1}{\\hphm 1}$ and $\\beta = -1$ determine\na separating hyperplane (line) of the labeled points.\n\n\\includegraphics{perceptronplane.png}\n\n\\end{example}\n\n\n\\beginshex\nConsider the points\n$$\n\\begin{pmatrix}\n0 \\\\ 0\n\\end{pmatrix},\\qquad\n\\begin{pmatrix}\n0 \\\\ 1\n\\end{pmatrix},\\qquad\n\n\\begin{pmatrix}\n1 \\\\ 1\n\\end{pmatrix},\\qquad\\text{and}\\qquad\n\\begin{pmatrix}\n1 \\\\ 0\n\\end{pmatrix}\n$$\nin $\\RR^2$, where the first point is labeled with $-1$ and the rest by $1$.\nUse the perceptron algorithm to compute a separating hyperplane.\n\nWhat happens when you run the perceptron algorithm on the above\npoints, but where the label of\n$$\n\\begin{pmatrix}\n  1 \\\\ 1\n\\end{pmatrix}\n$$\nis changed from $1$ to $-1$?\n\\endshex\n\n\n\\begin{hideinbutton}{Why does the simple algorithm work?}\n  We will assume that there exists $\\alpha\\in \\RR^d$, such that\n  $$\n  \\alpha^T x_i > 0\n  $$\n  for every $i = 1, \\dots, n$. This is equivalent to the existence of $\\alpha^*\\in \\RR^d$, such that\n  $$\n  (\\alpha^*)^T x_i \\geq 1\n  $$\n  for every $i = 1, \\dots, n$. Let $r = \\max\\{\\abs{x_1}, \\dots, \\abs{x_n}\\}$. The basic insight\n  is the following\n  \\begin{proposition}\\label{proprepl}\n    After $m$ replacements of $\\alpha$ in the algorithm, we have\n    \\begin{align*}\n      \\alpha^T \\alpha^* &\\geq m \\\\\n      m r^2 &\\geq \\abs{\\alpha}^2.\n    \\end{align*}\n  \\end{proposition}\n  \\begin{proof}[showhide]\n    These statements follow from the inequalities\n    $$\n    (\\alpha + x_i)^T \\alpha^* = \\alpha^T \\alpha^* + x_i^T \\alpha^* \\geq \\alpha^T \\alpha^* + 1\n    $$\n    and\n    $$\n    (\\alpha + x_i)^T (\\alpha + x_i) = \\abs{\\alpha}^2 + 2 x_i^T \\alpha + \\abs{x_i}^2 \\leq \\abs{\\alpha}^2 +\n    \\abs{x_i}^2 \\leq \\abs{\\alpha}^2 + r^2.\n    $$\n  \\end{proof}\n\n  Proposition \\ref{proprepl} implies that\n$$\nm \\leq \\abs{\\alpha} \\abs{\\alpha^*} \\leq \\sqrt{m} r \\abs{\\alpha^*}.\n$$\nTherefore we get $m\\leq r^2 \\abs{\\alpha^*}^2$ and there is an upper bound on the number of\niterations used in the second step. At a certain iteration within this bound\nwe must have $\\alpha^T x_i > 0$ for every $i=1, \\dots, n$.\n\\end{hideinbutton}\n\nBelow is an implementation of the perceptron (learning) algorithm\nin python with input from Example \\ref{Examplepercep}.\n\n\\begin{sage}\nimport numpy as np\n\nvectors = [[0,0], [1,1], [1,-1]]\nlabels = [1, 1, -1]\n\ndef liftvectors(vectors, labels):\n    return [list(map(lambda t: x[1]*t, x[0]))+[x[1]] for x in zip(vectors, labels)]\n\ndef perceptron(inputvectors):\n    alpha = np.array(len(inputvectors[0])*[0])\n    vectors = list(map(np.array, inputvectors))\n    done = False\n    while not done:\n        done = True\n        for v in vectors:\n            if np.dot(alpha, v) <= 0:\n               alpha = np.add(alpha, v)  \n               done = False\n               break\n    return alpha\n\nprint(\"The (normal) vector alpha in dimension one more is:\")\n    \nperceptron(liftvectors(vectors, labels))    \n\\end{sage}\n\n\\beginshex\nFor python aficionados: why does the above code stop working when\n\\begin{quote}\n  \\texttt{vectors = list(map(np.array, inputvectors))}\n\\end{quote}\nis replaced by\n\\begin{quote}\n  \\texttt{vectors = map(np.array, inputvectors)}\n\\end{quote}\n?\n\\endshex\n\n\\end{hideinbutton}\n\n\\subsection{Bounded subsets}\n\nA subset $S \\subseteq \\RR^d$ is called bounded if there exists $M\\in \\RR$, such that\n$$\nu\\cdot u\\leq M\n$$\nfor every $u\\in S$ i.e.,\n\\begin{frameit}\n  $$\n  u\\in S \\implies u\\cdot u\\leq M.\n  $$\n\\end{frameit}\n\nThis condition is true if and only if there exists $N\\in \\RR$, such\nthat\n$$\n|u|\\leq N\n$$\nfor every $u\\in S$ i.e., that the norms of the vectors in $S$ are bounded by some\nnumber.\n\n\\beginshex\nDescribe geometrically what it means for a subset $S$ of $\\RR$ resp. $\\RR^2$\nto be bounded by using intervals resp. circles (disks).\n\\endshex\n\n\\beginshex\nShow precisely that the subset $\\NN$ of $\\RR$ is not bounded, whereas the subset\n$\\{1, \\frac{1}{2}, \\frac{1}{3}, \\dots\\}$ is.\n\\endshex\n\n\\beginshex\nSketch why\n$$\nS = \\{(x, y) \\mid x\\geq 0, y\\geq 0, x + y\\leq 1\\}\\subseteq \\RR^2\n$$\nis bounded. Now use Fourier-Motzkin elimination to show the same\nwithout sketching.\n\\endshex\n\n\\subsection{Pythagoras and the least squares method}\n\nThe result below is a generalization of the theorem of Pythagoras about right\ntriangles to higher dimensions.\n\n\\begin{proposition}\\label{proppythagoras}\n  If $u, v\\in \\RR^d$ and $u\\perp v$, then\n  $$\n  \\abs{u + v}^2 = \\abs{u}^2 + \\abs{v}^2.\n  $$\n\\end{proposition}\n\n  \\begin{proof}[showhide]\n    This follows from\n    $$\n    (u + v)\\cdot(u+v) = u\\cdot u + u\\cdot v + v\\cdot u + v\\cdot v = u\\cdot u + v\\cdot v = \\abs{u}^2 + \\abs{v}^2,\n    $$\n    since $u \\cdot v = v\\cdot u = 0$.\n  \\end{proof}\n\n\n\n\nThe dot product and the norm have a vast number of applications. One of them is the\nmethod of least squares: suppose that you are presented with a system\n\\begin{equation}\\label{lineqslsq}\nA x = b\n\\end{equation}\nof linear equations, where $A$ is an $m\\times n$ matrix.\n\nYou may not be able to solve \\eqref{lineqslsq}. There could be for example\n$17$ equations and only $2$ unknowns making it impossible for all the equations to hold.\nAs an example, the system\n\n\\newcommand{\\mph}{\\phantom{-}}\n\n\\begin{equation}\\label{nosols}\n\\begin{pmatrix}\n\\mph 1 & \\mph 1\\\\\n\\mph 1 & -1\\\\\n-1 & \\mph 1\n\\end{pmatrix} \\begin{pmatrix} x \\\\ y\\end{pmatrix} = \\begin{pmatrix} 3 \\\\ 1 \\\\ 1 \\end{pmatrix}\n\\end{equation}\nof three linear equations and two unknowns does not have any solutions.\n\n\nThe method of (linear) least squares seeks the best approximate solution $x_0$ to \\eqref{lineqslsq} as a\nsolution to the minimization problem\n\n\n\n\\begin{align}\\label{optlsq}\n  &\\text{Minimize} &\\abs{b - A x}^2&\\\\\n  &\\text{with constraint}\\\\\n  &&x\\in\\RR^n.\n\\end{align}\n\nThere is a surprising way of finding optimal solutions to \\eqref{optlsq}:\n\n\n\n\\begin{theorem}[emph]\\label{lsqthm}\n  If $x_0\\in\\RR^n$ is a solution to the system\n  $$\n  (A^T A) x = A^T b\n  $$\n  of $n$ linear equations with $n$ unknowns,\n  then $x_0$ is an optimal solution to \\eqref{optlsq}.\n\\end{theorem}\n\n  \\begin{proof}[showhide]\n    Suppose we know that $b - A x_0$ is orthogonal to $A v$ for every $v\\in \\RR^n$. Then\n    $$\n    \\abs{b - A x}^2 = \\abs{b - A x_0 + A(x_0 - x)}^2 = \\abs{b - A x_0}^2 + \\abs{A(x-x_0)}^2\n    $$\n    for every $x\\in \\RR^n$\n    by Proposition \\ref{proppythagoras}. So, in the case that\n    $b - A x_0 \\perp A v$ for every $v\\in \\RR^n$ we have\n    $$\n    \\abs{b - A x}^2 \\geq \\abs{b - A x_0}^2\n    $$\n    for every $x\\in \\RR^n$ proving that $x_0$ is an optimal solution to\n    \\eqref{optlsq}.\n\n\n    Now we wish to show that $b - A x_0$ is orthogonal to $A v$ for every $v\\in \\RR^n$ if and\n    only if $A^T A x_0 = A^T b$. This is a computation involving the matrix arithmetic\n    introduced in Chapter \\ref{Chapter:Matrices}:\n    \\begin{align*}\n      &(b - A x_0)\\cdot A v = \\\\\n      &(b - A x_0)^T A v  =\\\\\n      &b^T A v - x_0^T A^T A v = \\\\\n      &(b^T A - x_0 A^T A) v = 0\n    \\end{align*}\n    for every $v\\in \\RR^n$ if and only if $b^T A - x_0 A^T A = 0$. But\n    $$\n    (b^T A - x_0 A^T A)^T = A^T b - A^T A x_0. \n    $$\n  \\end{proof}\n\nIn a future course on linear algebra you will see that the system of linear equations in\nTheorem \\ref{lsqthm} is always solvable i.e., an optimal solution to \\eqref{optlsq} can\nalways be found in this way.\n\n\n\n\\beginshex\nShow that \\eqref{nosols} has no solutions. Compute the best approximate solution to \\eqref{nosols} \nusing Theorem \\ref{lsqthm}.\n\\endshex\n\n\\begin{example}\n  The classical application of the least squares method is to find\nthe best line $y = \\alpha x + \\beta$ through a given set of points\n$$\n(x_1, y_1), \\quad (x_2, y_2), \\quad \\dots \\quad, (x_n, y_n)\n$$\nin the plane $\\RR^2$.\n\nUsually we cannot find a line matching the points precisely. This corresponds to the fact that\nthe system of equations\n$$\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\n\\alpha \\\\ \\beta\n\\end{pmatrix}\n= \n\\begin{pmatrix}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{pmatrix}\n$$\nhas no solutions.\n\nWorking with the least squares solution, we try to compute the best\nline $y = \\alpha x + \\beta$ in the sense that\n$$\n(y_1 -\\alpha x_1 -\\beta)^2 + (y_2 -\\alpha x_2 -\\beta)^2 + \\cdots +\n(y_n -\\alpha x_n -\\beta)^2 \n$$\nis minimized.\n\n\\begin{figure}\n\\includegraphics{linreg.png}\n\\caption{Best fit of line to random points from \\url{Wikipedia}{https://en.wikipedia.org/wiki/Least_squares}.}\n\\end{figure}\n\nWe might as well have asked for the best quadratic polynomial \n$$\ny = \\alpha x^2 + \\beta x + \\gamma \n$$\npassing through the points\n$$\n(x_1, y_1), \\quad (x_2, y_2), \\quad \\dots \\quad, (x_n, y_n)\n$$\nin $\\RR^2$.\n\nThe same method gives us the system\n$$\n\\begin{pmatrix}\nx_1^2 & x_1 & 1\\\\\nx_2 ^2 & x_2 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n^2 & x_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\n\\alpha \\\\ \\beta \\\\ \\gamma\n\\end{pmatrix}\n= \n\\begin{pmatrix}\ny_1 \\\\\ny_2 \\\\\n\\vdots \\\\\ny_n\n\\end{pmatrix}\n$$\nof linear equations.\n\n\n\\begin{figure}\n\\includegraphics{parabelfit.png}\n\\caption{Best fit of quadratic polynomial to random points from  \\url{Wikipedia}{https://en.wikipedia.org/wiki/Least_squares}.}\n\\end{figure}\n\n\n\nThe method generalizes naturally to finding the best polynomial of degree $m$\n$$\ny = a_m x^m + a_{m-1} x^{m-1} + \\cdots + a_1 x + a_0 \n$$\nthrough a given set of points.\n\\end{example}\n\n\\beginshex\nFind the best line $y = \\alpha x + \\beta$ through the points\n$(1, 2), (2,1)$ and $(4,3)$ and the best quadratic polynomial\n$ y = a x^2 + b x + c$ through the points\n$(-2, 2), (-1, 1), (0,0), (1,1)$ and $(2,2)$.\n\nIt is important here, that you write down the relevant system\nof linear equations according to Theorem \\ref{lsqthm}.\nIt is however ok to solve the equations\non a computer (or check your best fit on \\url{WolframAlpha}{https://www.wolframalpha.com/}).\n\nAlso, you can get a graphical illustration of your result in the sage window below.\n\n\\begin{sage}\npts = [(-2, 2), (-1, 1), (0, 0), (1, 1), (2, 2)]\na = 1\nb = 1\nc = 1\nshow(points(pts, pointsize=30) + plot(a*x^2 + b*x + c, (x, -2.5, 2.5)))\n\\end{sage}\n\\endshex\n\n\n\\beginshex\nA circle with center $(a, b)$ and radius $r$ is given by the equation\n\n\\begin{equation}\\label{eq:circle}\n(x - a)^2 + (y - b)^2 = r^2.\n\\end{equation}\n\n\\begin{enumerate}\n\\item\n  Explain how \\eqref{eq:circle} can be rewritten to the equation\n\\begin{equation}\\label{eq:circfit}\n2 a x + 2 b y + c = x^2 + y^2,\n\\end{equation}\nwhere $c = r^2 - a^2 - b^2$.\n\n\\item\n  Explain how fitting a circle to the points $(x_1, y_1), \\dots, (x_n, y_n)$\n  in the least squares context using \\eqref{eq:circfit} leads to the system\n$$\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots &\\vdots &\\vdots\\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\na \\\\\nb \\\\\nc\n\\end{pmatrix}\n=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots \\\\\nx_n^2 + y_n^2\n\\end{pmatrix},\n$$\nof linear equations.\n\n\\item\n\n  Compute the best circle through the points\n$$\n(0, 2),\\quad (0, 3),\\quad  (2,0)\\quad\\text{and}\\quad (3, 1)\n$$ \nby giving the center coordinates and radius with two decimals.\n\n\\includegraphics{circlefit.png}\n\n\\end{enumerate}\n\n\\begin{sage}\npts = [(0, 2), (0, 3), (2, 0), (3, 1)]\n\nx = 2\ny = 2\nr = 2\n\nshow(points(pts, pointsize=30) + circle((x, y), r))\n\\end{sage}\n\n\\endshex\n\n\\subsection{The Cauchy-Schwarz inequality}\n\nEven though the generalizations of the dot product and norm to higher\ndimensions amount to just adding some coordinates, they entail\na rather stunning result called the \\url{Cauchy-Schwarz inequality}{https://en.wikipedia.org/wiki/Cauchy\\%E2\\%80\\%93Schwarz_inequality}. The\nproof is not long, but revolves around a rather beautiful trick.\n\n\n\\begin{theorem}\\label{cs}\n  For two vectors $u, v\\in \\RR^d$,\n  $$\n  \\abs{u\\cdot v} \\leq \\abs{u} \\abs{v}.\n  $$\n\\end{theorem}\n  \\begin{proof}[showhide]\n    We consider the function $q:\\RR\\rightarrow \\RR$ given by\n    $$\n    q(x) = (x u + v)\\cdot (x u + v) = \\abs{u}^2 x^2 + 2 (u\\cdot v) x + \\abs{v}^2\n    $$\n    Then $q(x)$ is a quadratic polynomial with $q(x)\\geq 0$. Therefore\n    its discriminant must be $\\leq 0$ i.e.,\n    $$\n    4 (u\\cdot v)^2 - 4 \\abs{u}^2 \\abs{v}^2 \\leq 0,\n    $$  \n    which gives the result.\n  \\end{proof}\n\n\nThe Cauchy-Schwarz inequality\nimplies that \n$$\n-1 \\leq \\frac{u\\cdot v}{|u|\\, |v|} \\leq 1\n$$\nfor two vectors $u, v\\in \\RR^d$ and it makes sense to define the angle\n$\\theta$ between these vectors\\index{angle between vectors} by\n\\begin{equation}\\label{cossim}\n\\cos(\\theta) = \n\\frac{u \\cdot v}{|u|\\, |v|}.\n\\end{equation}\n\n\\beginshex\nFor arbitrary two numbers $x, y\\in \\RR$, \n$$\n2 (x^2 + y^2) \\geq (x + y)^2,\n$$\nsince\n$$\n2(x^2 + y^2) - (x + y)^2 = x^2 + y^2 - 2 x y = (x - y)^2\\geq 0.\n$$\n\nWhy is\n$$\nn (x_1^2 + \\cdots + x_n^2) \\geq (x_1 + \\cdots + x_n)^2\n$$\nfor arbitary $n$ numbers $x_1, \\dots, x_n\\in \\RR$?\n\\endshex\n\n\\begin{example}\n\n  When vectors are interpreted as data sets,\n  the number in \\eqref{cossim} is known as the \\emph{cosine similarity}\nand measures the correlation between the two data sets\n$u$ and $v$.\n\nAn application could be the similarity between two strings.\nConsider the two strings \n\"\\emph{Mathematics is fun and matrices are useful}\"\nand\n\"\\emph{Mathematics is fun and matrices are applicable}\".\n\nFrom the words in the two strings we form the following vectors in $\\RR^8$.\n\n$$\n\\begin{array}{lll}\n  \\text{Mathematics} & 1 & 1\\\\[0.5em]\n  \\text{is} & 1& 1\\\\[0.5em]\n  \\text{fun} & 1 & 1\\\\[0.5em]\n  \\text{and} & 1 & 1\\\\[0.5em]\n  \\text{matrices} & 1 & 1\\\\[0.5em]\n  \\text{applicable} & 0 & 1\\\\[0.5em]\n  \\text{useful} & 1 & 0\\\\[0.5em]\n  \\text{are} & 1 & 1\n\\end{array}\n$$\n\nwhere every word in the two strings has an entry counting the number of\noccurences in the string. A measure for the equality between\nthe two strings is the cosine of the angle between the two vectors.\n\nThe closer the cosine gets to $1$ (corresponding to an angle of $0$\ndegrees), the more similar we consider the strings.\n\nIn the above case the cosine similarity is approximately $0.86$.\n\nBelow is a snippet of python code (using \\texttt{numpy}) for computing the cosine similarity of two strings, where\nwords are separated by blanks. It can be extended in many ways.\n\n\n\\begin{sage}\nimport numpy as np\nfrom numpy.linalg import norm\n\ndef cosinesim(str1, str2):\n  words1 = str1.split()\n  words2 = str2.split()\n  words12 = list(set().union(words1, words2))\n  v1 = np.array([words1.count(w) for w in words12])\n  v2 = np.array([words2.count(w) for w in words12])\n  return (np.dot(v1, v2)/(norm(v1)*norm(v2)))\n\nstr1 = \"Mathematics is fun and matrices are useful\"\nstr2 = \"Mathematics is fun and matrices are applicable\"\n\nprint(\"The cosine similarity between\")\nprint(str1)\nprint(\"and\")\nprint(str2)\nprint(\"is\")\nprint(cosinesim(str1, str2))\n\\end{sage}\n\n\nThis application is based on rather basic mathematics, but we do get a quantitative measure for\nhow close two strings are. This is a crude tool applicable for flagging potential plagiarism.\n\nThe cosine similarity is implemented in the python machine\nlearning library \\url{\\texttt{sci-kit-learn}}{https://scikit-learn.org/stable/}.\n\n\\end{example}\n\n\n\n\\subsection{Distance of vectors and the triangle inequality}\n\nWe know how to measure the size of a vector $u\\in \\RR^d$ by its norm $\\abs{u}$. We need\nto measure how close two vectors $u, v\\in \\RR^d$ are i.e., we\nneed to measure their \\emph{distance}. A perfectly good\nmeasure for the distance from $u$ to $v$ is the norm\n$$\n\\abs{u-v}.\n$$\nYou can see from \\eqref{vecnorm} that $|u-v|$ is small implies that\nthe coordinates of $u$ and $v$ are close. Also we want $u = v$ if\ntheir distance is zero. This is satisfied. Similarly we want\nthe distance from $u$ to $v$ to equal the distance from $v$ to $u$. This is true,\nsince $\\abs{x} = \\abs{-x}$ for any vector $x\\in \\RR^d$.\n\n\\beginshex\nShow the above, that $\\abs{x} = \\abs{-x}$ for any vector $x\\in \\RR^d$. Explain why\nthis implies $\\abs{u - v} = \\abs{v - u}$ for every $u, v\\in \\RR^d$.\n\\endshex\n\nOne other, not so obvious property, is the \\url{triangle inequality}{https://en.wikipedia.org/wiki/Triangle_inequality}.\n\n\\begin{theorem}\\label{thmtrineq}\n  For two vectors $u, v\\in \\RR^d$,\n  $$\n  \\abs{u + v} \\leq \\abs{u} + \\abs{v}.\n  $$\n  \\end{theorem}\n    \\begin{proof}[showhide]\n      From the Cauchy-Schwarz inequality (Theorem \\ref{cs}) it follows that \n      $$\n      \\abs{u+v}^2 = (u+v)\\cdot (u+v) = \\abs{u}^2 + 2 u\\cdot v + \\abs{v}^2 \\leq \\abs{u}^2 + 2 \\abs{u}\\abs{v} + \\abs{v}^2.\n      $$\n      Since the right hand side of this inequality is $(\\abs{u} + \\abs{v})^2$, the result follows.\n    \\end{proof}\n\n  Why is this result called the triangle inequality? A consequence is that\n  $$\n  \\abs{u - v}  = \\abs{(u - w) + (w - v)} \\leq \\abs{u - w} + \\abs{w - v},\n  $$\n  i.e., that the distance from $u$ to $v$ is always less than or equal to\n  the distance from $u$ to $w$ plus the distance from $w$ to $v$, where\n  $w$ is a third vector.\n\n  In boiled down terms: the length of any one side in a triangle is\n  less than or equal to the sum of the lengths of the two other sides.\n\n\n\\includegraphics{triangleineq.svg}\n\n\\beginshex\nFind two typos in the figure above. Correct them!\n\\endshex\n\nThe triangle inequality implies that\n\\begin{align}\\label{trineqopp}\n  \\abs{\\abs{x}-\\abs{y}} &\\leq \\abs{x - y}\\\\\n  \\abs{\\abs{x}-\\abs{y}} &\\leq \\abs{x + y}\n\\end{align}\nfor every $x, y\\in \\RR^d$.\n\n\\beginshex\n  Show how \\eqref{trineqopp} follows from Theorem \\ref{thmtrineq}. \n\\endshex\n\n\n\n\n\\section{An important remark about the real numbers}\n\nIn the beginning of this course, we postulated the existence of the real\nnumbers $\\RR$ as an extension of the rational numbers $\\QQ$ with their ordering $\\leq$.\n\nThe rational numbers had the glaring defect that the graph of the function $f:\\QQ\\rightarrow \\QQ$ given by\n$$\nf(x) = x^2 - 2\n$$\ndoes not intersect the $x$-axis between $1$ and $2$ in spite of the\nfact that $f(1) = -1$ and $f(2) = 2$.\n\n\nIt seems from the sage plot below, that the graph intersects the\n$x$-axis around $x_0\\approx 1.4$, but it really does not happen!\nYour computer and its screen only\nhandles rational numbers.\n\n\\begin{sage}\n  plot(x**2 -2, (x, 1, 2))\n\\end{sage}\n\nSurely the most natural property for a well behaved function\n(like $f(x) = x^2 - 2$) is that it must intersect the $x$-axis\nin a point $x_0$ with $a < x_0 < b$ if $f(a) < 0$ and $f(b) > 0$.\n\nI will not be completely precise about how to repair this defect about the\nrational numbers $\\QQ$, but\njust state one exceedingly important property about the real numbers $\\RR$ in\nthe button below.\n\nIn fact this\none property guarantees that $\\RR$ does not have any holes\nas in the graph above.\n\n\n\\begin{hideinbutton}{Supremum and infimum}\n\\subsection{Supremum}\n\nA subset $S$ of $\\RR$ is called \\emph{bounded from above} if there exists\n$M\\in \\RR$, such that $x\\leq M$ for every $x\\in S$. Here $M$ is\ncalled an \\emph{upper bound} for $S$.\n\n\\beginshex\nGive an example of a subset of the real numbers, which is not bounded from\nabove and one that is.\n\\endshex\n\n\nThe set of real numbers satisfies that for every subset $S\\subseteq \\RR$ bounded from above,\n there exists a smallest upper bound denoted $\\sup(S)$ called\nthe \\emph{supremum} of $S$. In precise terms,\n\\begin{enumerate}[(i)]\n\\item\n  $\\sup(S)\\geq x$ for every $x\\in S$ \n\\item\n  If we move a little to the left of $\\sup(S)$ we encounter\n  elements from $S$: for every $\\epsilon > 0$, there exists $x\\in S$,\n  such that\n  $$\n  \\sup(S)-\\epsilon < x \\leq \\sup(S).\n  $$\n\\end{enumerate}\n\n\\includegraphics{supremum.png}\n\nNotice that we may have $\\sup(S)\\not\\in S$.\n\n\\subsection{Infimum}\n\nIn the same way a subset $S$ of $\\RR$ is called \\emph{bounded from below}, if\nthere exists $m\\in \\RR$, such that $m \\leq x$ for\nevery $x\\in S$. Every subset $S$ bounded from below has\na largest lower bound denoted $\\inf(S)$ called the \\emph{infimum} of $S$.\nIn precise terms,\n\\begin{enumerate}[(i)]\n\\item\n  $\\inf(S)\\leq x$ for every $x\\in S$ \n\\item\n  If we move a little to the right of $\\inf(S)$ we encounter\n  elements from $S$: for every $\\epsilon > 0$, there exists $x\\in S$,\n  such that\n  $$\n  \\inf(S) \\leq x < \\inf(S) + \\epsilon.\n  $$\n\\end{enumerate}\n\n\n\\beginshex\nGive a simple example of a subset $S\\subseteq \\RR$ bounded from above, where\n$\\sup(S)\\not\\in S$.\n\nShow that the subset $S = \\{x\\in \\QQ \\mid x^2 < 2\\}$ of $\\RR$ is bounded from above and below and\n  that $\\sup(S)\\not\\in \\QQ$ and $\\inf(S)\\not\\in \\QQ$.\n\\endshex\n\n\\beginshex\nShow that $S$ is infinite if $\\sup(S)\\not\\in S$.\n\\endshex\n\n\\end{hideinbutton}\n\n\n\n  \\section{Sequences and limits in $\\RR^d$}\n\n  For the first time in the notes we are now moving towards infinite\n  processes. We will introduce limits\n  of vectors organized in an infinite sequence.\n\n\\begin{definition}[emph]  \nA sequence\nin  $\\RR^d$ is an \\emph{infinite} list of vectors\n$$\nv_1, v_2, v_3, \\dots\n$$\nin $\\RR^d$, where repetitions are allowed. Such a sequence is denoted $(v_n)$.\n\\end{definition}\n\nIn order to define a sequence we just need to tell what its $n$-th element is. So\nin abstract terms a sequence in $\\RR^d$ is nothing but a function $\\NN\\rightarrow \\RR^d$.\n\n\\begin{example}\nBelow we give two examples of sequences in $\\RR$.\n\\begin{align*}\n&(x_n): 1, 2, 3, 4, \\dots\\\\\n&(y_n): 1, \\tfrac{1}{2}, \\tfrac{1}{3}, \\tfrac{1}{4}, \\dots\n\\end{align*}\nThe first sequence is given by $x_n = n$ and the second $y_n = \\frac{1}{n}$ for $n\\in \\NN$. The first sequence\nexplodes to infinity, whereas the second sequence gets closer and closer to $0$. In the latter case we\nwrite\n$$\n\\lim_{n\\to\\infty} y_n = 0.\n$$\n\\end{example}\n\nWhat does it mean that a sequence $(v_n)$ of vectors in $\\RR^d$  has limit $v\\in \\RR^d$? Intuitively,\nwe can get $v_n$ as close to $v$ as we want by choosing\n$n\\in \\NN$ sufficiently big. Here is the precise way of saying this:\n\n\n\\begin{equation}[emph]\\label{convdef}\n\\forall \\epsilon > 0\\, \\exists N\\in \\NN: n\\geq N\\implies \\abs{v_n - v} < \\epsilon.\n\\end{equation}\n\n\nIf a sequence $(v_n)$ has a limit $v$, then we write\n$$\n\\lim_{n\\to\\infty} v_n = v.\n$$\n\nA sequence is called convergent if it has a limit. Let us see\nhow our new technology works on two intuitively\nobvious examples.\n\n\n\n\n\n\\begin{example}\\label{Example:basicconv}\n  Let us use \\eqref{convdef} to give a precise proof of\n  $$\n  \\lim_{n\\to\\infty} x_n = 0,\n  $$\n  where $x_n = 1/n$. So given any $\\epsilon >0$ we must find $N\\in \\NN$, such that\n  $$\n  \\abs{x_n - 0} = \\abs{x_n} = \\frac{1}{n} < \\epsilon\n  $$\n  for $n > N$. But\n  $$\n  \\frac{1}{n} < \\epsilon \\iff \\frac{1}{\\epsilon} < n.\n  $$\n  So we simply choose $N$ to be the smallest natural number bigger than $\\frac{1}{\\epsilon}$.\n\n  An even simpler example is a constant sequence like\n  $$\n  17, 17, 17, 17, \\dots\n  $$\n  i.e., $x_n = 17$ for all $n\\in \\NN$. Here we want the limit to be $17$ and\n  \\eqref{convdef} agrees. We can put $N= 1$:\n  $$\n  \\forall \\epsilon > 0 : n\\geq 1\\implies \\abs{x_n - 17} = \\abs{17 - 17} = 0 < \\epsilon.\n  $$\n\n\\end{example}\n\n\nIf a sequence is convergent, then it can have\nonly one limit. You can not have a convergent sequence with two different limits!\nIn particular, the constant sequence\n$$\n  17, 17, 17, 17, \\dots\n  $$\n  cannot converge to $18$.\n\n\\beginshex\nGive a precise proof of the fact that a convergent sequence $(x_n)$ can only have\none limit using proof by contradiction i.e., start by assuming that\nit has two different limits $x\\neq y$. Then show that \n$$\n\\forall \\epsilon > 0\\, \\exists N\\in \\NN: n\\geq N\\implies \\abs{x_n - y} < \\epsilon.\n$$\ncannot be true by showing that\n$$\n\\exists \\epsilon > 0\\, \\forall N\\in \\NN: \\exists n\\geq N\\implies \\abs{x_n - y} \\geq \\epsilon.\n$$\n\\begin{hint}\n  Try $\\epsilon = \\abs{x-y}/2$ in the definition of $x$ being a limit and apply \\eqref{trineqopp} to\n  $$\n  \\abs{x_n - y} = \\abs{x_n - x + x - y}.\n  $$\n\\end{hint}\n\\endshex\n\nNow, that we have the definition of a convergent sequence, we go on to use it in a rather\ntypical proof of a rather typical result. In this (typical) proof we first handle the\ninfinite and then the finite.\n\n\n\n\n\\begin{proposition}\\label{propconvbounded}\n  A convergent sequence $(x_n)$ is bounded i.e., there exists $M\\in \\RR$, such that\n  $|x_n| \\leq M$ for every $n\\in \\NN$.\n\\end{proposition}\n  \\begin{proof}[showhide]\n    Let $x$ denote the limit of $(x_n)$. Then for $\\epsilon = 1$, we may find\n    $N\\in \\NN$, such that $\\abs{x - x_n} < 1$ for $n\\geq N$. Therefore\n    $\\abs{x_n} < \\abs{x} + 1$ for $n\\geq N$ by \\eqref{trineqopp}. Let\n    $M_1 = \\max\\{\\abs{x_0}, \\dots, \\abs{x_N}\\}$ and then letting\n    $M = \\max\\{M_1, \\abs{x} + 1\\}$, we see that $\\abs{x_n} \\leq M$\n    for every $n\\in \\NN$.\n  \\end{proof}\n\n\n  \\begin{example}\n    Proposition \\ref{propconvbounded} shows that the sequence\n    $$\n    1, 2, 3, 4, \\dots\n    $$\n    cannot be convergent. Why?\n  \\end{example}\n\n\n  \n\n\n\\newcommand{\\phmi}{\\phantom{-}}\n\\begin{quizexercise}[showhide]\n\\begin{quiz}\n  \\question\n  What is the limit of the sequence\n  $$\n  \\phmi 1, -1, \\phmi 1, -1, \\phmi 1, -1, \\dots ?\n  $$\n  \\answer{F}\n  $$1$$\n  \\answer{F}\n  $$-1$$\n  \\answer{T}\n  It does not have a limit.\n  \\answer{F}\n  $$0$$\n\\end{quiz}\n\\end{quizexercise}\n\nSage may be helpful in computing limits (see below).\n\n\\begin{sage}\nn = var('n')\nassume(n>0)\nsequence = n/(n+1)\nlimit(sequence, n=infinity)\n\\end{sage}\n\n\nFor convergent sequences we have the following result.\n\n\\begin{frameit}\n\\begin{proposition}\\label{propconvarithm}\nLet $(x_n)$ and $(y_n)$ be convergent sequences in $\\RR^d$ with limits\n$x$ and $y$ respectively. Then\n\\begin{enumerate}[(i)]\n\\item\\label{itemsum}\nthe sequence $(x_n + y_n)$ is convergent with limit $x + y$.\n\\item\\label{itemproduct}\nthe sequence $(x_n y_n)$ is convergent with limit $x y$ (if $d=1$)\n\\item\nthe sequence $(x_n/y_n)$ is convergent with limit $x/y$ provided\nthat $y\\neq 0$ and $y_n \\neq 0$ for every $n\\in\\NN$ (if $d=1$).\n\\end{enumerate}\n\\end{proposition}\n\\end{frameit}\n  \\begin{proof}[showhide]\n    I will give the proof of \\ref{itemproduct}. By definition (see\n    \\eqref{convdef}) we are given $\\epsilon > 0$ and we must find\n    $N\\in \\NN$, such that\n    $$\n    \\abs{x y - x_n y_n} < \\epsilon\n    $$\n    for $n\\geq N$. An old trick shows that\n    $$\n    \\abs{x y - x_n y_n} = \\abs{(x-x_n) y + (y - y_n) x_n}.\n    $$\n    Therefore we may find $M > 0$ so that \n    $$\n    \\abs{x y - x_n y_n} \\leq \\abs{x-x_n}\\abs{y} + \\abs{y - y_n}\\abs{ x_n} \\leq \\abs{x-x_n} M + \\abs{y-y_n} M,\n    $$\n    where $y \\leq M$ and $\\abs{x_n}\\leq M$ for every $n\\in \\NN$ (see Proposition \\ref{propconvbounded}).\n    We are assuming the $(x_n)$ and $(y_n)$ are convergent sequences. Therefore we may find\n    $N_1$ and $N_2$ in $\\NN$, so that\n    \\begin{align*}\n      \\abs{x - x_n} &< \\frac{\\epsilon}{2 M}\\qquad\\text{for}\\qquad n \\geq N_1\\\\\n      \\abs{y - y_n} &< \\frac{\\epsilon}{2 M}\\qquad\\text{for}\\qquad n \\geq N_2.\n    \\end{align*}\n    Choosing $N = \\max\\{N_1, N_2\\}$, we get\n    $$\n    \\abs{x y - x_n y_n} \\leq \\abs{x-x_n} M + \\abs{y-y_n} M \\leq \\frac{\\epsilon}{2 M} M + \\frac{\\epsilon}{2 M} M = \\epsilon,\n    $$\n    for $n\\geq N$.\n  \\end{proof}\n\n\\beginshex\nThe proof of \\ref{itemsum} in Proposition \\ref{propconvarithm} is much less involved\nthan the given proof of \\ref{itemproduct} in the same result. In the proof of\n\\ref{itemproduct} we used a trick using $\\frac{\\epsilon}{2M}$. Use the same\ntrick with $\\frac{\\epsilon}{2}$ and the triangle inequality to prove\n\\ref{itemsum}.\n\\begin{hint}\n  $$\n  \\abs{x + y - (x_n + y_n)} = \\abs{(x - x_n) + (y - y_n)} \\leq \\abs{x - x_n} + \\abs{y - y_n}. \n  $$\n\\end{hint}\n\\endshex\n\n\\begin{quizexercise}[showhide]\n  \\begin{quiz}\n    \\question\n    What is the limit of the sequence $(x_n)$ given by\n    $$\n    x_n = \\frac{3 n^2 + 17 n + 5}{2 n^2 + 3 n + 2}?\n    $$\n    \\answer{F}\n    $$0$$\n    \\answer{F}\n    It does not have a limit\n    \\answer{T}\n    $$1.5$$\n    \\answer{F}\n    $$\\frac{17}{5}$$\n  \\end{quiz}\n\\end{quizexercise}\n\n\n\\beginshex\nConsider the sequence $(x_n)$ given by\n$$\nx_n = \\left(1 + \\frac{1}{n}\\right)^n.\n$$\nCarry out a computer experiment in Sage below to find the limit\nof $(x_n)$. Can you prove what you observe in\nthe experiment?\n\n\\begin{sage}\ndef exp(n):\n  print(\"(1 + 1/n)^n is =\")\n  print((1 + 1/float(n))**n)\n  print(\"for n = \", n)\n\nexp(100)  \n\\end{sage}\n\n\\begin{hint}\n  $$\n  n \\ln\\left(1 + \\frac{1}{n}\\right) =\n  \\frac{\\ln\\left(1 + \\frac{1}{n}\\right) - \\ln(1)}{\\frac{1}{n}}\n$$\n\\end{hint}\n\\endshex\n\n\\beginshex\nAssume that $(x_n)$ is a convergent sequence in $\\RR^d$. Show that\n$(\\abs{x_n})$ is a convergent sequence in $\\RR$.\n\\endshex\n\n\\beginshex\nLet $(x_n)$ be a sequence bounded below with the property that\n$$\nx_1 \\geq x_2 \\geq x_3 \\geq \\cdots\n$$\nShow that $\\inf\\{x_n \\mid n\\in \\NN\\}$ is the limit of $(x_n)$.\n\nSimilarly let $(z_n)$ be a sequence bounded above with the property that\n$$\nz_1 \\leq z_2 \\leq z_3 \\leq \\cdots\n$$\nShow that $\\sup\\{z_n \\mid n\\in \\NN\\}$ is the limit of $(z_n)$.\n\\endshex\n\n\\beginshex\n\\begin{enumerate}[(i)]\n\\item Show that\n  $$\n  \\sqrt{a b} \\leq \\frac{a+b}{2},\n  $$\n  for $0 \\leq a \\leq b$.\n\\item\n  Prove that $a < \\sqrt{a b}$ and $(a+b)/2 < b$ for $0\\leq a < b$.\n\\item\n  Start with two numbers $a$ and $b$ with $0\\leq a\\leq b$ and define\n  \\begin{align*}\n    a_{n+1} &= \\sqrt{a_n b_n}\\\\\n    b_ {n+1} &= (a_n + b_n)/2,\n  \\end{align*}\n  where $a_0 = a$ and $b_0 = b$. Carry out computer experiments in the sage (python) window below\n  to analyze the sequences $a_0, a_1, \\dots$ and $b_0, b_1, \\dots$\n  for different values of $a_0$ and $b_0$.\n\n\n\\begin{sage}\nimport math\n\na0 = 1\nb0 = 2\nprint(\"Input a=\", a0, \" and b=\", b0)\nprint(\"Iterating towards ag mean:\")\n  \nfor i in range(10):\n  print(a0, b0)\n  a1 = math.sqrt(a0*b0)\n  b1 = (a0 + b0)/float(2)\n  a0 = a1\n  b0 = b1\n\\end{sage}\n\\item\n  Prove for $n\\geq 1$ that\n  $$\n  b_n - a_n < \\left(\\frac{1}{2}\\right)^n (b-a)\n  $$\n  if $0< a < b$.\n\\item\n  Let $s = \\lim_{n\\to \\infty} a_n$ and $t=\\lim_{n\\to \\infty} b_n$.\n  Show that the limits exist and that $s = t$.\n\\end{enumerate}\nThe common limit $M(a, b)$ of the sequences $(a_n)$ and\n$(b_n)$ is called the \\url{arithmetic-geometric mean}{https://en.wikipedia.org/wiki/Arithmetic\\%E2\\%80\\%93geometric_mean} of $a$ and $b$.\nJust for the fun of it, here is a cool way of computing $\\pi$\ninvolving this quantity:\n$$\n\\pi = \\frac{4 M(1, \\frac{1}{\\sqrt{2}})^2}{1 - \\sum_{n=1}^\\infty 2^ {n+1}(b_n^2 - a_n^2)}.\n$$\n\\endshex\n\n\\subsection{Closed and open subsets}\n\nWe have defined what it means for a subset of a euclidean space to be bounded. Now\nwe come to an exceedingly important definition about subsets being closed meaning\nthat they should (in a mathematically precise way) contain their boundary points. For example, we want the interval $[0, 1]$ to be closed, whereas the\ninterval $[0, 1)$ should not be closed, because it is missing its\nboundary point $1$.\n\n\\begin{definition}[emph]\nA subset $F\\subseteq \\RR^d$ is called closed if it contains all its limit vectors. This\nmeans that if $(v_n)$ is a convergent sequence contained in $F$, then its limit must\nbe contained in $F$.\n\\end{definition}\n\n\n\n\nWe can immediately come up with a non-closed subset using the definition. Consider the subset\n$$\nS = \\{x\\in \\RR \\mid x > 0\\}\\subset \\RR.\n$$\nHere $\\left(\\frac{1}{n}\\right)$ is a convergent sequence, whose elements all are\ncontained in $S$, but its limit $0$ is outside $S$ (see Example\n\\ref{Example:basicconv}).\nWe have, however, the following important result relating to this example.\n\n\\begin{proposition}[emph]\\label{closedinR}\n  The following subsets\n  \\begin{align*}\n    [a, b] &= \\{x\\in \\RR \\mid a \\leq x \\leq b\\} \\\\\n    [a, \\infty) &= \\{x\\in \\RR \\mid a \\leq x\\}\\\\\n    (-\\infty, a] &= \\{x\\in \\RR \\mid x \\leq a\\}\n  \\end{align*}\n  are closed subsets of $\\RR$ for every $a, b\\in \\RR$.\n\\end{proposition}\n\nClosed subsets are preserved by finite unions and intersections.\n\n\\begin{proposition}[emph]\n  Let $F_1, F_2, \\dots, F_n$ be finitely many closed subsets of $\\RR^d$. Then \n  $$\n  F_1 \\cap F_2 \\cap \\cdots \\cap F_n \\qquad\\text{and}\\qquad\n  F_1 \\cup F_2 \\cup \\cdots \\cup F_n \n  $$\n  are closed subsets of $\\RR^d$.\n\\end{proposition}\n\nThe complementary notion of a closed subset is an open subset.\n\n\n\\begin{definition}[emph]\n  A subset $U\\subseteq \\RR^d$ is called \\emph{open} if $\\RR^d\\setminus U$ is closed.\n\\end{definition}\n\n\\beginshex\nProve that \n  $$\n  U_1 \\cap U_2 \\cap \\cdots \\cap U_n \\qquad\\text{and}\\qquad\n  U_1 \\cup U_2 \\cup \\cdots \\cup U_n \n  $$\nif $U_1, \\dots, U_n$ are open subsets.\n\\endshex\n\n  \\beginshex\n  Let $(a, b) =\\{x \\in \\RR \\mid a < x < b\\}$ for $a, b\\in \\RR$, where $a < b$.\n  Show that $(a, b)$ is an open subset of $\\RR$.\n  \\endshex\n\n  \\begin{remark}\n    In fact, an arbitrary (also infinite) intersection of closed subsets is closed and an arbitrary (also infinite) union of open subsets is open. However, for a\n    first course introducing intersections and unions over arbitrary families is pushing the\n    envelope.\n  \\end{remark}\n  \n\n\\begin{hideinbutton}{Infinite series}\n\\subsection{Infinite series}\n\nGiven a sequence $(x_m)$ in $\\RR^d$ we may form the new sequence given by the sums\n\\begin{align*}\n  s_1 &= x_1\\\\\n  s_2 &= x_1 + x_2\\\\\n      &\\vdots\\\\\n  s_n &= x_1 + x_2 + \\cdots + x_n\\\\\n  &\\vdots       \n\\end{align*}\nSuch a sequence is called an infinite series. It is denoted\n$$\n\\sum_{n=1}^\\infty x_n\n$$\nand is defined to converge if the sequence $(s_n)$ converges.\n\nInfinite series give rise to very \\url{beautiful identities}{https://en.wikipedia.org/wiki/Basel_problem} like\n$$\n\\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6}.\n$$\n\nWe will not go deeper into the rich theory of infinite series, but\nsettle at defining a widely used infinite series called the\n\\emph{geometric series}.  Let $q\\in \\RR$ with $\\abs{q} < 1$. We saw in\nthe first chapter that\n$$\n1 + q + \\cdots + q^n = \\frac{1 - q^{n+1}}{1-q}\n$$\nfor any number $q\\neq 1$. If $\\abs{q} < 1$, then $\\lim_{n\\to\\infty} q^n = 0$.\n\n\\beginshex\nShow that $\\lim_{n\\to\\infty} q^n = 0$ if $\\abs{q} < 1$.\n\\endshex\n\nTherefore\n\\begin{equation}\\label{geomseries}\n  \\sum_{n=0}^\\infty q^n = \\frac{1}{1-q}.\n\\end{equation}\nThe series in \\eqref{geomseries} is called the geometric series.\n\n\\beginshex\nCompute the (infinite) sums\n\\begin{enumerate}[(i)]\n\\item\n  $$\n  \\frac{1}{2} + \\frac{1}{4} + \\frac{1}{8} + \\cdots\n  $$\n\\item\n  $$\n  1 - \\frac{1}{2} + \\frac{1}{4} - \\frac{1}{8} + \\cdots\n  $$\n\\end{enumerate}\n\\endshex\n\n\\beginshex\nThe series given by $x_n = \\frac{1}{n}$ i.e.,\n$$\ns_n = 1 + \\frac{1}{2} + \\frac{1}{3} + \\cdots + \\frac{1}{n}\n$$\nis called the \\emph{harmonic series}. Explore the growth of the harmonic series as a function of $n$\nusing the sage window below.\n\n\\begin{sage}\nn = 100\nprint(\"The sum of the first \", n , \" terms in the harmonic series is \", sum(1/float(i) for i in range(1, n+1)))\n\\end{sage}\n\nWhat does this \\url{video}{https://twitter.com/TamasGorbe/status/1174406602998341632/video/1}\non twitter have to do with the harmonic series?\n\nSuppose that the inequality\n\\begin{align}\\label{lbharm}\n\\ln(n) = \\int_1^n \\frac{1}{x} d x \\leq 1 + \\frac{1}{2} + \\cdots + \\frac{1}{n}\n\\end{align}\nholds. What does \\eqref{lbharm} imply for the harmonic series? Is \\eqref{lbharm} true? Compare\nwith the graphs in the sage window below.\n\n\\begin{sage}\nn = 1000\n  \nprint(\"Graphs of the sum of the harmonic series and the (natural) logarithm (red) up to n=\", n)\nx = var('x')\ng = Graphics()\ng += plot(harmonic_number(x), (x, 1, n))\ng += plot(log(x), (x, 1, n), color='red')\ng.show()\n\\end{sage}\n\nUse the sage window below to investigate if the sequence $e_n$ given by\n$$\ne(n) = 1 + \\frac{1}{2} + \\cdots + \\frac{1}{n} - \\ln(n)\n$$\nconverges. In particular, make a clever statement about the convergence by studying a finite table\nof\n$$\ne(1), e(2), e(3), \\dots\n$$\nobserving $e(n) - e(n+1)$ for $n = 1, 2, 3, \\dots$.\n\n\\begin{sage}\ndef euler(n):\n  return harmonic_number(float(n)) - log(float(n))\n\nn = 100\nprint(\"e(n) is \", euler(n), \" for n=\", n )\n\\end{sage}\n\\endshex\n\n\n\\end{hideinbutton}\n\n\n\\section{Continuous functions}\n\n\\begin{definition}[emph]\\label{defcontfunc}\nA function $f: S\\rightarrow T$, where $S \\subseteq \\RR^d$ and $T\\subseteq \\RR^e$ is\ncalled \\emph{continuous at $v\\in S$} if for every\nconvergent sequence $(v_n)$ in $S$ with limit $v\\in S$, $(f(v_n))$ is a\nconvergent sequence with limit $f(v)$ in $T$. The function $f: S\\rightarrow T$ is called continuous\nif it is continuous at every $v\\in S$.\n\\end{definition}\n\n\nThe above is the formal definition of a continuous function. It is short and sweet. To\nget an understanding, you should study the mother of all examples of \nnon-continuous functions given below:\n\\begin{equation}\\label{bracketfct}\nf(x) =\n\\begin{cases}\n  0 &\\text{if } x > 0\\\\\n  1 &\\text{if } x \\leq 0\n\\end{cases}.\n\\end{equation}\n\nThis is a function from $\\RR$ to $\\RR$. It is impossible to plot it\nwithout lifting the pencil or defining such a beast without using a\nbracket as in \\eqref{bracketfct}.\n\n\\includegraphics{noncont.png}\n\nLet me sketch how the formal Definition \\ref{defcontfunc} kills any hope of\n\\eqref{bracketfct} being continuous. It is enough to come up with just\none sequence $(x_n)$ converging to $x$, such that the sequence\n$(f(x_n))$ does not converge to $f(x)$.  We pick\nthe sequence $x_n= 1/n$, which converges to $x = 0$.\nBut $(f(x_n))$\nis the constant sequence\n$$\n0, 0, 0, \\dots\n$$\nbecause $f(1/n) = 0$ for $n = 1, 2, \\dots$. Therefore $(f(x_n))$ has to converge\nto $0$, which is different from $f(0) = 1$ and $f$ fails to be continuous according\nto Definition \\ref{defcontfunc}.\n\nAlmost all functions we encounter will be continuous. The function $f$ above is an\nanomaly.\n\nLet us stop briefly once more and see Definition \\ref{defcontfunc} in action.\n\n\\begin{example}\\label{contbasic}\n  Let $S = T = \\RR$ in Definition \\ref{defcontfunc}. We consider the two functions\n  \\begin{align*}\n    f(x) &= x\\\\\n    g(x) &= c,\n  \\end{align*}\n  where $c\\in \\RR$ i.e., $f$ is the identity function and $g$ is a\n  constant function given by the real number $c$. Both of these\n  functions are continuous. Let us see why.\n\n  A sequence $(x_n)$ is convergent with limit $x$ if\n  \\begin{equation}\\label{contexeq}\n  \\forall \\epsilon > 0 \\exists N\\in \\NN: n\\geq N \\implies \\abs{x - x_n}<\\epsilon\n  \\end{equation}\n  according to \\eqref{convdef}. To verify Definition \\ref{defcontfunc}, we must prove that \n  $$\n  \\forall \\epsilon > 0 \\exists N\\in \\NN: n\\geq N \\implies \\abs{f(x) - f(x_n)}<\\epsilon.\n  $$\n  But $\\abs{f(x) - f(x_n)} = \\abs{x - x_n}$, so that the above claim is true\n  by \\eqref{contexeq} with the same $N$.\n  Similarly $\\abs{g(x_n) - g(x)} = \\abs{c - c} = 0$. Here we may pick $N=1$, since\n  $0 < \\epsilon$ to begin with.\n\\end{example}\n\nWe give now three important results, which can be used\nin concrete situations to verify that a given function is continuous. They can\nbe proved without too much hassle. The first result below basically follows from the\ndefinition of the norm of a vector (see \\eqref{vecnorm}).\n\n\\begin{lemma}[emph]\\label{Lemma:proj}\n  The functions $\\pi_i:\\RR^d\\rightarrow \\RR$ given by\n  $$\n  \\pi_i(x_1, \\dots, x_i, \\dots, x_d) = x_i\n  $$\n  for $i = 1, ,\\dots, d$ are continuous. In general a function\n  $f:S\\rightarrow T$ is continuous if and only if $\\pi_j\\circ f: S\\rightarrow \\RR$\n  is continuous for every $j = 1, \\dots, e$, where $S\\subseteq \\RR^d$ and\n  $T\\subseteq \\RR^e$.\n\\end{lemma}\n\n\nDefinition \\ref{defcontfunc} also behaves nicely when continuous functions\nare composed. This is the content of the following\n\n\\begin{proposition}[emph]\n  Suppose that $g: S\\rightarrow T$ and $f: T\\rightarrow R$ are continuous\n  functions, where $S\\subseteq \\RR^d, T\\subseteq \\RR^e$ and $R\\subseteq \\RR^f$. Then\n  the composition\n  $$\n  (f\\circ g): S\\rightarrow R\n  $$\n  is continuous.\n\\end{proposition}\n\n\nTo get continuous functions from functions already known to be continuous using\narithmetic operations, the result below is useful.\n\n\\begin{proposition}[emph]\\label{contfunccomp}\nLet $f, g: U\\rightarrow \\RR$ be functions defined on a subset $U\\subset \\RR^d$. If\n$f$ and $g$ are continuous, then the functions\n\\begin{align*}\n(f + g): U\\rightarrow \\RR\\qquad\\text{given by}\\quad &(f + g)(x) = f(x) + g(x)\\\\\n(f g): U\\rightarrow \\RR\\qquad\\text{given by}\\quad &(f g)(x) = f(x) g(x)\\\\\n(f/g): V\\rightarrow \\RR\\qquad\\text{given by}\\quad &(f/g)(x) = f(x)/g(x)\n\\end{align*}\nare continuous functions, where $V = \\{x\\in U\\mid g(x)\\neq 0\\}$ (the last function is\ndefined only if $g(x)\\neq 0$).\n\\end{proposition}\n\n\\begin{proof}[showhide]\nThis result is a consequence of the definition of continuity and Proposition \\ref{propconvarithm}.\n\\end{proof}\n\n\\beginshex\nShow in detail that the function $f: \\RR^2\\rightarrow \\RR$ given by\n$$\nf(x, y) = x^2 + y^2\n$$\nis continuous by using Proposition \\ref{contfunccomp} combined with \nLemma \\ref{Lemma:proj}.\n\\endshex\n\n\\begin{frameit}\n\\begin{remark}\\label{combcont}\n  By combining Example \\ref{contbasic} with Proposition \\ref{contfunccomp}, one finds that\n  every polynomial is a continuous function and that\n  $$\n  h(x) = \\frac{f(x)}{g(x)}\n  $$\n  is continuous for $g(x)\\neq 0$, where $f, g\\in \\RR[x]$.\n\\end{remark}\n\\end{frameit}\n\n\\beginshex\nVerify the claim in Remark \\ref{combcont}.\n\\endshex\n\nMore advanced (transcendental) functions like $\\sin(x)$ and $e^x$ also turn out to be continuous.\n\n\nWe are now in position to prove a famous result from 1817 due to \\url{Bolzano}{https://en.wikipedia.org/wiki/Bernard_Bolzano}. \n\n\\begin{theorem}[emph]\\label{Bolzano}\n  Let $f: [a, b]\\rightarrow \\RR$ be a continuous function, where $a < b$. If\n  $f(a) < 0$ and $f(b) > 0$, then there exists $x_0$ with $a < x_0 < b$, such\n  that $f(x_0) = 0$.\n\\end{theorem}\n\n  \\begin{proof}[showhide]\n    This is proved using the supremum property of the real numbers. The subset\n    $$\n    S = \\{x\\in [a, b]\\mid f(x) \\leq 0\\}\n    $$\n    is non-empty (since $a\\in S$) and bounded from above. We let $c = \\sup(S)$.\n\n    We will need the following observation about the continuous function $f$:\n    If $f(z) < 0$ for $a \\leq z < b$, then there exists a small\n    $\\delta > 0$, such that\n    $$\n    f(x) < 0\n    $$\n    for every $x\\in [z, z+\\delta]$.\n\n    Similarly if $f(z) > 0$ for $a <  z \\leq b$, then there exists a small\n    $\\delta > 0$, such that\n    $$\n    f(x) > 0\n    $$\n    for every $x\\in [z - \\delta, z]$.\n\n    These observations imply that $a < c < b$ by the definition\n    of supremum. Similarly we cannot according to these\n    observations have $f(c) < 0$ or $f(c) > 0$.\n    In this case $c\\not\\in S$ and by definition of supremum we have $S\\cap [c-\\varepsilon, c] \\neq \\emptyset$ for every $\\varepsilon > 0$. But for some $\\varepsilon>0$ there must exist $x\\in [c-\\varepsilon, c]\\cap S$, such that $f(x) > 0$.This is impossible.\n\n    The only possibility remaining is $f(c) = 0$.\n  \\end{proof}\n\nAgain, by Proposition \\ref{contfunccomp}, polynomials are continuous functions.\nNow, as promised previously, we state and prove the following result.\n\n\\begin{proposition}[emph]\nLet\n$$\nf(x) = a_n x^n + \\cdots + a_1 x + a_0\n$$\nbe a polynomial of odd degree, i.e. $n$ is odd. Then $f$ has a root,\ni.e. there exists $x_0\\in\\RR$, such that $f(x_0) = 0$.\n\\end{proposition}\n\\begin{proof}[showhide]\nWe will assume that $a_n > 0$ (if not, just multiply $f$ by $-1$). Consider $f(x)$ written as\n$$\nf(x) = x^n \\left(a_n + \\frac{a_{n-1}}{x} + \\cdots + \\frac{a_1}{x^{n-1}} + \\frac{a_0}{x^n}\\right).\n$$\nBy choosing $c$ negative with $\\abs{c}$ extremely big, we have $f(c) < 0$, \nsince $c^n$ is negative and \n$$\na_n + \\frac{a_{n-1}}{c} + \\cdots + \\frac{a_1}{c^{n-1}} + \\frac{a_0}{c^n} > 0\n$$\nas $a_n$ is positive. Notice here that the terms\n$$\n\\frac{a_{n-1}}{c} + \\cdots + \\frac{a_1}{c^{n-1}} + \\frac{a_0}{c^n} \n$$\nare extremely small, when $\\abs{c}$ is extremely big.\n\nSimilarly by choosing\n$d$ positive and tremendously big, we have $f(d) > 0$.\nBy Theorem \\ref{Bolzano}, there exists $x_0$ with $c < x_0 < d$ with\n$f(x_0) = 0$.\n\\end{proof}\n\n\nBefore defining (and more importantly giving examples of) closed subsets, we will\ndefine abstractly the preimage of a subset of a function.\n\n\\begin{definition}[emph]\nConsider a\nfunction\n$$\nf: A \\rightarrow B,\n$$\nwhere $A$ and $B$ are sets. If $C\\subseteq B$, then the\npreimage of $C$ under $f$ is defined by\n\\begin{equation*}\nf^{-1}(C) = \\{x\\in A \\mid f(x)\\in C\\}.\n\\end{equation*}\n\\end{definition}\n\n\\begin{quizexercise}[showhide]\n  \\begin{quiz}\n    \\question\n    Consider the function $f:\\{1, 2, 3, 4, 5\\}\\rightarrow \\RR$ given by\n    $$\n\\def\\arraystretch{1.5}\n\\begin{array}{c|ccccccc}\nx & 1 & 2 & 3 & 4 & 5\\\\ \\hline\nf(x) & 1 & 2 & 4 & -1 & \\pi\n\\end{array}\n$$\nand let $C = [3, \\infty)$. What is true about $f^{-1}(C)$?\n\\answer{F}\n$$\n1\\in f^{-1}(C)\n$$\n\\answer{T}\n$$\n\\{3, 5\\}\\subseteq f^{-1}(C)\n$$\n\\answer{F}\n$$\n\\{3, 4, 5\\}\\subseteq f^{-1}(C)\n$$\n\\answer{T}\n$$\nf^{-1}(\\RR\\setminus C) \\cup f^{-1}(C) = \\{1, 2, 3, 4, 5\\}.\n$$\n\\end{quiz}\n\\end{quizexercise}\n\nThe following result is often a very useful tool in showing that a\nsubset is closed.\n\n\\begin{proposition}[emph]\\label{preimagecontclosed}\n  If $F\\subseteq \\RR^e$ is a closed subset and $f: \\RR^d\\rightarrow \\RR^e$\n  a continuous function, then the preimage\n  $$\n  f^{-1}(F)\n  $$\n  is a closed subset of $\\RR^d$.\n\\end{proposition}\n\n\\begin{example}\n  The function $f:\\RR^2\\rightarrow \\RR$ given by $f(x, y) = x^2 + y^2$ is\n  continuous. Therefore the subset\n  \\begin{align*}\n    &\\{(x, y)\\in \\RR^2\\mid x^2 + y^2 \\geq 1\\} = \\\\\n    &\\{(x, y)\\in \\RR^2\\mid f(x, y) \\geq 1\\} = \\\\\n    &\\{(x, y)\\in \\RR^2\\mid f(x, y) \\in [1, \\infty)\\} = \\\\\n    &f^{-1}([1, \\infty))\n  \\end{align*}\n  of $\\RR^2$ is closed, since $[1, \\infty)$ is a closed subset\n  of $\\RR$ by Proposition \\ref{closedinR}.\n  \\end{example}\n\n\n\\beginshex\nShow that\n\n$$\ng(x) = \\dfrac{a(x)}{b(x)}\n$$\n\nis a continuous function $g: V\\rightarrow \\mathbb{R}$, where $a(x) = x^2 - 3 x + 2$ and $b(x) = x^2 - 4 x + 3$ and\n\n$$\nV = \\mathbb{R}\\setminus\\{1, 3\\}.\n$$\n\nUse Proposition \\ref{closedinR} and Proposition \\ref{preimagecontclosed} to show that\n\n$$\nF = \\{x\\in \\mathbb{R} \\mid a(x) \\leq 17\\}\n$$\n\nis a closed subset of $\\mathbb{R}$.\n\n\n\nExperiment a bit and compute $g(x)$, when $x$ is close to $1$. Is $g(x)$ close to a special value $y_0$ when $x$ is close to $1$? What happens when $x$ is close to $1$? How do you explain this in terms of $a(x)$ and $b(x)$?\n\\endshex\n\n\n  \n  We end the section on continuous functions by introducing \\emph{compact} subsets\n  and a crucial optimization result.\n\n\\begin{definition}[emph]\nA subset of euclidean space is called compact if it is bounded and closed.\n\\end{definition}\n\n\n\\begin{theorem}[emph]\\label{thmcontcomp}\n  Let $C$ be a compact subset of $\\RR^d$ and $f: C\\rightarrow \\RR$\n  a continuous function. Then there exists $u, v\\in C$, such that\n  $$\n  f(u) \\leq f(x)\\qquad\\text{and}\\qquad f(x)\\leq f(v)\n  $$\n  for every $x\\in C$.\n\\end{theorem}\n\nThis is a rather stunning result! You are guaranteed solutions to\noptimization problems of the type\n\n\\begin{align*}\n  &\\text{Minimize} &f(x)&\\\\\n  &\\text{with constraint}\\\\\n  &&x\\in C,\n\\end{align*}\n\nwhere $C$ is a compact subset and $f: C\\rightarrow \\RR$ a continuous function.\nFinding the optimal solutions in this setting is another story. It can be\nextremely hard. For the rest of these notes we will actually dive into\nmethods for computing optimal solutions of optimization problems such as\nthe one above.\n\n\n\n\\end{document}", "meta": {"hexsha": "876173f0a95cb2751901e070477e93db34a8c297", "size": 60968, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IMO21/euclidean.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/euclidean.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/euclidean.tex", "max_forks_repo_name": "FunByJohn/QaDiL", "max_forks_repo_head_hexsha": "9e22bb061c5a2c32473c7ab3aa9b9cce4e98c963", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-10T08:26:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-25T02:04:32.000Z", "avg_line_length": 28.0699815838, "max_line_length": 258, "alphanum_fraction": 0.6582141451, "num_tokens": 21813, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730775, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.779570398106811}}
{"text": "\\section{Integers as instructions or programs}\n\n\\subsection{Integer representation}\nWhen we deal with RAM program, as said in Section~\\ref{sec:RAM_intro}, we do not treat subtraction as if we were in $\\mathbb{Z}$ or other set of number including $\\mathbb{Z}$, we are supposed to be in the natural number world. \n\nIn a RAM program subtraction is represented by the $\\dotminus$ symbol giving us an expression of the type $A \\dotminus B = max(0, A - B)$ therefore the we created the \\textit{Int} class that extends the \\textit{int} class and overrides the \\textit{\\_\\_sub\\_\\_} function as shown in Listing \\ref{listing:int_class_sub} .\n\n\\begin{lstlisting}[\n    caption={The Int class}, \n    label={listing:int_class_sub},\n    language=Python,\n    backgroundcolor=\\color{gray!10},\n    frame=lines,\n    ]\nclass Int(int):\n    def __sub__(self, x: int):\n        return Int(max(int(self) - x, 0))\n    ...\n\\end{lstlisting}\n\n\n\\subsection{Gödelisation function}\nAs seen in course every instruction can be represented as an integer, thanks to Gödel bijective function (look at listing~\\ref{god_enc}).\n\n\\begin{lstlisting}[\n    caption={Gödel encoding function}, \n    label={god_enc},\n    mathescape, \n    frame=lines,\n    backgroundcolor=\\color{gray!10}, breaklines=true\n    ]\n    $Rk =  Rk + 1 \\rightsquigarrow 3 \\times  k$ \n    $Rk =  Rk - 1 \\rightsquigarrow 3 \\times  k + 1$\n    $IF\\;Rk \\neq  0\\;THEN\\;GOTOB\\;n\\;\\rightsquigarrow 3 \\times  [k, [1, [n, 0]]] + 2$ \n    $IF\\;Rk \\neq  0\\;THEN\\;GOTOF\\;n \\rightsquigarrow 3 \\times  [k, [0, [n, 0]]] + 2$\n Where : \n    - k is the register number\n    - is the number of jump to do inside a if\n\\end{lstlisting}\n\n\\newpage\n\\subsection{Gödel inverse function}\nWhen we are given an integer and we know that it is an instruction, we can easily decode it with modulo operations (look at listing~\\ref{god_dec}).\n\\begin{lstlisting}[\n    caption={Gödel decoding function}, \n    label={god_dec},\n    mathescape, \n    frame=lines,\n    backgroundcolor=\\color{gray!10},\n    ]\nif $X \\equiv 0 \\mod 3 \\rightsquigarrow$ we have a $Rk = Rk + 1$ instruction\nif $X \\equiv 1 \\mod 3 \\rightsquigarrow$ we have a $Rk = Rk - 1$ instruction\n  in both cases, k is equal to $\\lfloor X/3 \\rfloor$\nif $X \\equiv 2 \\mod 3 \\rightsquigarrow$ we have a jump instruction\n  where $X' =  \\lfloor X/3 \\rfloor$ and we can decode $X$ in $[k, [j, [n, 0]]]$ \n  with Cantor inverse function (see next paragraph)\n\\end{lstlisting}\nDecoding an instruction like can be done by the \\textit{decode\\_int\\_instr} in \\textit{decode\\_int.py} file.\n\n\\subsection{Cantor pairing function}\n\\label{sec:cant_pair_func}\nNow, we know how to code an instruction, we can so code a program, that is a list of instruction, thanks to Cantor function (look at listing~\\ref{cant_enc})\n\n\\begin{lstlisting}[\n    caption={Cantor encoding function}, \n    label={cant_enc},\n    mathescape, \n    frame=lines,\n    backgroundcolor=\\color{gray!10},\n    ]\n    $[x, y] = \\frac{(x + y) \\times (x+y+1)}{2} + y + 1 = n$\n    if b is a couple, we encode it at first,\n    and that recursively until the last tuple\n\\end{lstlisting}\n\nThe encoding of two integer to a Cantor's int is made by the \\textit{cantor} method of the \\textit{Int} class.\n\n\\subsection{Cantor inverse function}\nThe Cantor inverse function is not as simple as computing the Gödel inverse one. The Cantor Pairing function is a \\textit{Diophantine equation} (voir definition at ...) and finding back the two variables $x$ and $y$ from $n$ ask to iterate from 0 the n to find an intermediate $n'$.  \n\nSince $n$ may be very big, (it is the case if we encode multiple instructions) this task may become very slow, therefore, to speed it, we make a \\textit{binary search} to have an answer in a logarithmic time instead of a linear one. \n\nThe decoding function of a Cantor's int to a couple of the form $(x_1, (x_2, (..., (x_n, 0))))$ is made by the \\textit{Int} class with the \\textit{int\\_to\\_couple} method.\n\\newpage\n\\begin{lstlisting}[\n    caption={Cantor decoding function}, \n    label={cant_dec},\n    frame=lines,\n    backgroundcolor=\\color{gray!10},\n    language=Python\n    ]\nclass Int(int):\n    ...\n    def cantor_inv(self):\n        tmp = self.aux()\n        r = self - ((tmp - 1) * tmp / 2 + 1)\n        l = tmp - r - 1\n        return l, r\n    \n    def int_to_couple(s):\n        res = Int(s).cantor_inv()\n        return res if res[1] == 0 \n               else (res[0], Int(res[1]).int_to_couple())\n    ...\n\\end{lstlisting}", "meta": {"hexsha": "92514041c25f6518c34ba737d65fb3d77404de86", "size": 4436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "rep/Calculability/sections/integers_as_instructions_or_programs.tex", "max_stars_repo_name": "margauxschmied/RAM_language_interpreter", "max_stars_repo_head_hexsha": "608d42f76d3a2bb28906cb7664b9f852f9aee805", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2022-01-26T21:19:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T23:55:54.000Z", "max_issues_repo_path": "rep/Calculability/sections/integers_as_instructions_or_programs.tex", "max_issues_repo_name": "margauxschmied/RAM_language_interpreter", "max_issues_repo_head_hexsha": "608d42f76d3a2bb28906cb7664b9f852f9aee805", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "rep/Calculability/sections/integers_as_instructions_or_programs.tex", "max_forks_repo_name": "margauxschmied/RAM_language_interpreter", "max_forks_repo_head_hexsha": "608d42f76d3a2bb28906cb7664b9f852f9aee805", "max_forks_repo_licenses": ["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.2476190476, "max_line_length": 319, "alphanum_fraction": 0.6780883679, "num_tokens": 1362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8670357494949105, "lm_q1q2_score": 0.7795703772281416}}
{"text": "%\n% 429\n%\n\\chapter{Elliptic Functions. General Theorems and the\nWeierstrassian Functions}\n\n\\Section{20}{1}{Doubly-periodic functions.}\n\nA most important property of the circular functions sin, cos, tan,\n... is that, if/( ) denote any one of them,\n\nf z + 2 )=f z),\n\nand hfmce f z- '2mr)=f z), for all integer values of n. It is on\naccount of this property that the circular functions are frequently\ndescribed as periodic functions with period 27r. To distinguish them\nfrom the functions which will be discussed in this and the two\nfollowing chapters, they are called singly-periodic functions.\n\nLet Q)i, 0)2 be any two numbers (real or complex) whose ratio* is not\npurely real. A function which satisfies the equations\n\nf(z + 2a,0 =f z), f(z + 2a,,) =f(z),\n\nfor all values of z for which $f(z)$ exists, is called a doubly-periodic\nfunction of z, with periods 2\\&)i, 2co2. A doubly-periodic function\nwhich is analytic (except at poles), and which has no singularities\nother than poles in the finite part of the plane, is called an\nelliptic function.\n\n[Note. What is now known as an elliptic integral occurs in the\nresearches of Jakob Bernoulli on the Elastica. Maclaurin, Fagnano,\nLegendre, and others considered such integrals in connexion with the\nproblem of rectifying an arc of an ellipse; the idea of 'inverting'\nan elliptic integral (§ 21 '7) to obtain an elliptic function is due\nto Abel, Jacobi and Gauss.]\n\nThe periods 2( i, 2\\&,o play much the same part in the theory of\nelliptic functions as is played by the single period in the case of\nthe circular functions.\n\nBefore actually constructing any elliptic functions, and, indeed,\nbefore establishing the existence of such functions, it is convenient\nto prove some general theorems (\\hardsubsectionref{20}{1}{1}-20'14) concerning properties\ncommon to all elliptic functions; this procedure, though not strictly\nlogical, is convenient\n\n* If w.,/wj is real, the parallelograms defined in \\hardsubsectionref{20}{1}{1} collapse,\nand the function reduces to a singly-periodic function when Wg/wj is\nrational; and when w /wj is irrational, it has been shewn by Jacobi,\nJournal fiir Math. xiii. (183.5), pp. 55-56 [Ges. Werke, 11. (1882),\npp. 25-26] that the function reduces to a constant.\n\nt A brief discussion of elliptic integrals will be found in §§\n22-7-22*741.\n\n%\n% 430\n%\n\nbecause a large number of the properties of particular elliptic\nfunctions can be obtained at once by an appeal to these theorems.\n\nExample. The diflferential coefficient of an elliptic function is\nitself an elliptic function.\n\n2011. Pei-iod-parallelograms.\n\nThe study of elliptic functions is much facilitated by the geometrical\nrepresentation afforded by the Argaud diagi-am.\n\nSuppose that in the plane of the variable z we mark the points 0,\n2(Wi, 2(02, 2a)i + 2\\&)2, and, generally, all the points whose complex\ncoordinates are of the form 2mo)i + 2h\\&j.,, where m and n are\nintegers.\n\nJoin in succession consecutive points of the set 0, 2(Oi, 2(Oi + 2o\n.2, 2ei).,, 0, and we obtain a parallelogram. If there is no point a\ninside or on the boundary of this parallelogram (the vertices\nexcepted) such that\n\nf z + <o)=f z)\n\nfor all values of z, this parallelogram is called \\& fundamental\nperiod-parallelo- gram for an elliptic function with periods 2a)i, 2(0\n.\n\nIt is clear that the -plane may be covered with a network of\nparallelo- grams equal to the fundamental period-parallelogram and\nsimilarly situated, each of the points 2?/ia)i + 2na), being a vertex\nof four parallelograms.\n\nThese parallelograms are called peHod-parallelograms, or meshes; for\nall values of z, the points z, z- 2w, ... z +2m(o +2nw. ...\nmanifestly occupy corresponding positions in the meshes; any pair of\nsuch points are said to be congruent to one another. The congruence of\ntwo points z, z is expressed by the notation / = (mod. 2\\&)i, 2w.2).\n\nFrom the fundamental property of elliptic functions, it follows that\nan elliptic function assumes the same value at every one of a set of\ncongruent points; and so its values in any mesh are a mere repetition\nof its values in any other mesh.\n\nFor purposes of integration it is not convenient to deal with the\nactual meshes if they have singularities of the integrand on their\nboundaries; on account of the periodic properties of elliptic\nfunctions nothing is lost by taking as a contour, not an actual mesh,\nbut a parallelogram obtained by translating a mesh (without rotation)\nin such a way that none of the poles of the integrands considered are\non the sides of the parallelogi-am. Such a parallelogram is called a\ncell. Obviously the values assumed by an elliptic function in a cell\nare a mere repetition of its values in any mesh.\n\nA set of poles (or zeros) of an elliptic function in any given cell is\ncalled an irreducible set; all other poles (or zeros) of the function\nare congruent to one or other of them.\n\n%\n% 431\n%\n\n\\Subsection{20}{1}{2}{Simple properties of elliptic functions.}\n\n(I) The number of poles of an elliptic function in any cell is finite.\n\nFor, if not, the poles would have a limit point, by the\ntwo-dimensional analogue of \\hardsubsectionref{2}{2}{1}. This point is \\hardsubsectionref{5}{6}{1}) an\nessential singularity of the function; and so, by definition, the\nfunction is not an elliptic function.\n\n(II) The number of zeros of an elliptic function in any cell is\nfinite.\n\nFor, if not, the reciprocal of the function would have an infinite\nnumber of poles in the cell, and would therefore have an essential\nsingularity; and this point would be an essential singularity of the\noriginal function, which would therefore not be an elliptic function,\n[This argument presupposes that the function is not identically zero.]\n\n(III) The sum of the residues of an elliptic function, f z), at its\npoles in any cell is zero.\n\nLet C be the contour formed by the edges of the cell, and let the\ncorners of the cell be, + 2\\&ji, t + 2(yi + 2\\&).,, t + 2\\&)2.\n\n[Note. In future, the periods of an elliptic function will not be\ncalled 2ci)i, 2(B2 indifferently; but that one will be called 2wi\nwhich makes the ratio o),/©! have a positive imaginary part; and\nthen, if C be described in the sense indicated by the order of the\ncorners given above, the description of C is counter-clockioise.\n\nThroughout the chapter, we shall denote by the symbol C the contour\nformed by the edges of a cell.]\n\nThe sum of the residues oif z) at its poles inside C is\n\n .\\ f z)dz=-~\\ \\ . + + + \\ f z)dz.\n\nIn the second and third integrals write z+2a)i, z + 2(Oo respectively\nfor 2, and the right-hand side becomes\n\n . /( ) -/ + 2a>.)) dz - - f(z) -f z + 20,01 dz,\n\nand each of these integrals vanishes in virtue of the periodic\nproperties of f z); and so I f(z) dz = 0, and the theorem is\nestablished.\n\n(IV) Liouvilles theorem*. An elliptic function, f z), luith no poles\nin a cell is merely a constant.\n\nFor if f(z) has no poles inside the cell, it is analytic (and\nconsequently bounded) inside and on the boundary of the cell \\hardsubsectionref{3}{6}{1}\ncorollary ii); that is to say, there is a number K such that f(z), <\nK when z is inside or on the boundary of the cell. From the periodic\nproperties oi f(z) it follows that\n\n* This modification of the theorem of \\hardsubsectionref{5}{6}{3} is the result on which\nLiouville based his lectures on elliptic functions.\n\n%\n% 432\n%\n\nf z) is analytic and \\ f(z) \\ < K for all values of z; and so, by §\n5-63, $f(z)$ is a constant.\n\nIt will be seen later that a very large number of theorems concerning\nelliptic functions can be proved by the aid of this result.\n\n\\Subsection{20}{1}{3}{The order of an elliptic function.}\n\nIt will now be shewn that, \\ \\ f(z) be an elliptic function and c be\nany constant, the number of roots of the equation\n\nf( ) = c\n\nwhich lie in any cell depends only on f z), and not on c; this number\nis called the order of the elliptic function, and is equal to the\nnumber of poles off(z) in the cell.\n\nBy \\hardsubsectionref{6}{3}{1}, the difference between the number of zeros and the number\nof poles o f(z) - c which lie in the cell G is\n\n1 ' /'< > d..\n\n27ri J r f(z) - c\n\nSince /' z + 2\\&)i) =/' z + 2(Wo) = /\" z), by dividing the contour\ninto four parts, precisely as in \\hardsubsectionref{20}{1}{2}(III), we find that this\nintegral is zero.\n\nTherefore the number of zeros of /'( )- c is equal to the number of\npoles of $f(z)$ - c\\ but any pole oif z) - c is obviously a pole of f(z)\nand conversely; hence the number of zeros of f(z)- c is equal to the\nnumber of poles of $f(z)$, which is independent of $c$; the required\nresult is therefore established.\n\n[Note. In determining the order of an elliptic function by counting\nthe number of its irreducible poles, it is obvious, from \\hardsubsectionref{6}{3}{1}, that\neach pole has to be reckoned according to its multiplicity.]\n\nThe order of an elliptic function is never less than 2; for an\nelliptic function of order 1 would have a single irreducible pole;\nand if this point actually were a pole (and not an ordinary point) the\nresidue there would not be zero, which is contrary to the result of §\n201 2 (III).\n\nSo far as singularities are concerned, the simplest elliptic functions\nare those of order 2. Such functions may be divided into two classes,\n(i) those which have a single irreducible double pole, at which the\nresidue is zero in accordance with \\hardsubsectionref{20}{1}{2} (III); (ii) those which\nhave two simple poles at which, by § 20\"! 2 (III), the residues are\nnumerically equal but opposite in sign.\n\nFunctions belonging to these respective classes will be discussed in\nthis chapter and in Chapter xxii under the names of Weierstrassian and\nJacobian elliptic functions respectively; and it will be shewn that\nany elliptic function is expressible in terms of functions of either\nof these types.\n\n%\n% 433\n%\n\n\\Subsection{20}{1}{4}{Relation hetiueen the zeros and poles of an elliptic function.}\n\nWe shall now shew that the sum of the affixes of a set of irreducible\nzeros of an elliptic function is congruent to the sum of the affixes\nof a set of irreducible poles.\n\nFor, with the notation previously employed, it follows, from \\hardsubsectionref{6}{3}{1},\nthat the difference between the sums in question is\n\n27ri J C f 2) TTl [J t J +2<o, J f+2a,,+2a,2 J t+2ojJ J 2:)\n\n  j rt+2. j ) \\ z+2oy,)f'(z + 2co. ] ~27ri]t \\ f ) f z + 2ay,) \\ '\n\n27rij, \\ f(z) f z+2c.,) r\n\n27ri [ Jt f (z) J t f z)\n\nJ.j-2.,[log/(.)\n\nt+iu\n\n+ 2(0,\n\nlog/( )\n\nt\n\non making use of the substitutions used in § 2012 (III) and of the\nperiodic properties off z) and f' z).\n\nNow $f(z)$ has the same values at the points t + 2(Oi, t 4-20), as at t,\nso the values of \\ ogf(z) at these points can only differ from the\nvalue of $f(z)$ at $t$ by integer multiples of 27ri, say - 2n7ri,\n2///'7rt; then we have\n\n2'mJc fiz)\n\nand so the sum of the affixes of the zeros minus the suin of the\naffixes of the poles is a period; and this is the result which had to\nbe established.\n\n\\Section{20}{2}{The construction of an elliptic function. Definition of z).}\n\nIt was seen in | 20'1 that elliptic functions may be expected to have\nsome properties analogous to those of the circular functions. It is\ntherefore natural to introduce elliptic functions into analysis by\nsome definition analogous to one of the definitions which may be made\nthe foundation of the theory of circular functions.\n\nOne mode of developing the theory of the circular functions is to\nstart\n\nfrom the series S z-m7r)~-; calling this series (sin ')~-, it is\npossible\n\nJW= - CO\n\nto deduce all the known properties of sin z; the method of doing so\nis briefly indicated in \\hardsubsubsectionref{20}{2}{2}{2}.\n\nW. M. A. 28\n\n%\n% 434\n%\n\nThe analogous method of founding- the theory of elliptic functions is\nto define the function (,.> ( ) by the equation*\n\n \" m.n \\ \\ {2; - 2vio)i - '2n(02y (2? \\&)i+2?ieu2)-j ' Avhere (o, Wo\nsatisfy the conditions laid down in §§ 0*1, 20\"12(III); the summation\nextends over all integer values (positive, negative and zero) of m and\nn, simultaneous zero values of ni and n excepted.\n\nFor brevity, we write Qm,n in place of 'Iinw + 'Inwo, so that\n\nm, n\n\nWhen m and n are such that \\ \\ m,n\\ is large, the general terra of the\nseries defining ip (z) is 0(\\ flm,n\\~% and so \\hardsectionref{3}{4}) the series\nconverges absolutely and uniformly (with regard to z) except near its\npoles, namely the points Clm,n-\n\nTherefore \\hardsectionref{5}{3}), J (z) is analytic throughout the whole 2 -plane\nexcept at the points n,\\, where it has double poles.\n\nThe introduction of this function p z) is due to Weierstrassf; we now\nproceed to discuss properties of (z), and in the course of the\ninvestigation it will appear that j z) is an elliptic function with\npenods 2\\&)i, 2a)2.\n\nFor purposes of numerical computation the series for p (z) is useless\non account of the slowness of its convergence. Elliptic functions free\nfrom this defect will be obtained in Chapter xxi.\n\nExample. Prove that\n\nP(2)=U- I - + 2 cosec2 =7r - 2 cosec- - \"tt .\n\n\\Subsection{20}{2}{1}{Periodicity and other properties of z).}\n\nSince the series for z) is a uniformly convergent series of analytic\nfunctions, term-by-terra differentiation is legitimate \\hardsectionref{5}{3}), and so\n\nij' z) =,j z)=-2 t\n\n  m, n \\ \\ - '>, n)\n\nThe function ' z) is an odd functio7i of z\\ for, from the definition\nof y( ), we at once get\n\n '(- ) = 2 ( 4-n,, )- .\n\nm, n * Throughout the chapter 2 will be written to denote a summation\nover all integer values of m and n, a prime being inserted (2') when\nthe term for which j =:n = has to be omitted\n\nm, n\n\nfrom the summation. It is also customary to write ' z) for the\nderivate of 4> z). The use of the prime in two senses will not cause\nconfusion.\n\nt Werke, ii. (1895), pp. 245-2.55. The subject-matter of the greater\npart of this chapter is due to Weierstrass, and is contained in his\nlectures, of which an account has been published by Schwarz, Formeln\nund Lehrsatze zum Gebrauche der elUptischen Fiinktionen, Xach\nVorle.tnngen und Aufzeichnungen des Herrn Prof. K. Weierstrass\n(Berlin, 1893). See also Cayley, Journal de Math. X. (1845), pp.\n385-420 [Math. Papers, i. pp. 156-182], and Eisenstein, Journal fUr\nMath. XXXV. (1847), pp. 137-184, 18-5-274.\n\n%\n% 435\n%\n\nBut the set of points - D, (\\ is the same as the set Qm, n and so the\nterms of ' (- z) are just the same as those of - ' (z), but in a\ndifferent order. But, the series for j' (z) being absolutely\nconvergent \\hardsectionref{3}{4}), the derangement of the terms does not affect its\nsum, and therefore\n\n y -z) = - y (z).\n\nIn like manner, the terms of the absolutely convergent series\n\nni,n\n\nare the terms of the series\n\ny Hz - n - n~ i\n\nm, n\n\nin a different order, and hence\n\ni (- z) = i U); that is to say, (z) is an even functipn\\ oj[j.\n\nFurther, j' z + 2co,) = - 2 1 ( - D, + 2a,r;\n\nm, n\n\nbut the set of points n, - 2\\&ji is the same as the set Q,,, so the\nseries for y (z + 'Zcoi) is a derangement of the series for ' (z). The\nseries being absolutely convergent, we have\n\n y (z + 2ft)i) = y (z);\n\nthat is to say, '/ (z) has the period 2fOi; in like manner it has the\nperiod 2ft)o.\n\nSince y' (z) is analytic except at its poles, it follows from this\nresult that y (z) is an elliptic function.\n\nIf now we integrate the equation ' z + '2(o ) = < ' z), we get\n\n<p z + 2oy,) = < i z) + A,\n\nwhere A is constant. Putting z = - w and using the fact that < z) is\nan even function, we get = 0, so that\n\niO z + 2ft)i) = J (z); in like manner j z + 'Icoo) = (jp (z).\n\nSince p (z) has no singularities but poles, it follows from these two\nresults that J(2) is an elliptic function.\n\nThere are other methods of introducing both the circular and elliptic\nfunctions into analysis; for the circular functions the following may\nbe noticed :\n\n(1) The geometrical definition in which sin z is the ratio of the side\nopposite the angle 2 to the hypotenuse in a right-angled triangle of\nwhich one angle is z. This is the definition given in elementary\ntext-books on Trigonometry; from our point of view it has various\ndisadvantages, some of which are stated in the Appendix.\n\n(2) The definition by the power series\n\nZ 2\n\nsm2 = 2--, + -\n\n28-2\n\n%\n% 436\n%\n\n(3) The definition by the product\n\n(4) The definition by 'inversion' of an integral\n\nfBim J\n\nThe periodicity properties may be obtained easily from (4) by taking\nsuitable paths of integration (of. Forsyth, Theory of Functions,\n(1918), 104), but it is extremely difficult to prove that sin z\ndefined in this way is an analytic function.\n\nThe reader will 'see later (§§ 22-82, 22-1, 20-42, 20-22 and \\hardsubsectionref{20}{5}{3}\nexample 4) that elliptic functions may be defined by definitions\nanalogous to each of these, with corre- sponding disadvantages in the\ncases of the first and fourth.\n\nExample. Deduce the periodicity of .> (z) directly from its definition\nas a double series. [It is not difficult to justify the necessary\nderangement.]\n\n\\Subsection{20}{2}{2}{The differential equation satisfied by j z).}\n\nWe shall now obtain an equation satisfied by < z), which will prove to\nbe of great importance in the theory of the function.\n\nThe function j (2) -,2\" which is equal to S' (2 - n,,,i)~2 - H, is\n\nm, n\n\nanalytic in a region of which the origin is an internal point, and it\nis an even function of s. Consequently, by Taylor's theorem, we have\nan expansion of the form\n\nvalid for sufficiently small values of | |. It is easy to see that\n\nm, n ni, n\n\nThus (z) = Z-' + 20 g z' + 28 3 + ( ') '\n\ndifferentiating this result, we have\n\n y (z) = - 2z-' + g,z 1 g,z + (z ). Cubing and squaring these\nrespectively, we get\n\nf z) = z-' + .l~ g,z- + l g..+ 0(z ),\n\nHence ' (z) - 4 =* (z) = - g.z\" -gs + z'),\n\nand so '- z) - 4f (z) + g (z) + gs=0 (z').\n\nThat is to say, the function z) - 4 (z) + g (z) + g-s, which is\nobviously an elliptic function, is analytic at the origin, and\nconsequently it is also analytic at all congruent points. But such\npoints are the only possible singularities of the function, and, so it\nis an elliptic function luith no singularities; it is therefore a\nconstant \\hardsubsectionref{20}{1}{2}, lY).\n\nOn making z- 0, we see that this constant is zero.\n\n%\n% 437\n%\n\nThus, finally, the function ( z) satisfies the differential equation\n\nwhere 2 and g (called the invariants) are given by the equations\n\ng, = m T n f, 5r3 = i4o 1' n-.\n\n), n m, n\n\nConversely, given the equation if numbers \\&)i, (o can he determined*\nsuch that\n\nm, n i, n\n\nthen the general solution of the differential equation is\n\ny = iO ±z + a), where a is the constant of integration. This may be\nseen by taking a new dependent variable u defined by the equationf y =\n< (u), when the differential\n\nequation reduces to [ \\ =1.\n\nSince g? z) is an even function of z, we have y = 0 z ± a), and so the\nsolution of the equation can be written in the form\n\ny = j z + a) without loss of generality.\n\nExample. Deduce from the differential equation that, if\n\n)i = l\n\nthen C2=5r2/22 . 5, Ci=g l . 7, CQ=g ij2i.' . 52,\n\n ~2*.5.7.11' \"~25..3.5M.3\" 2*.72.13' '' 2 . 3 . 52 . 7 . 11 \"\n\n\\Subsubsection{20}{2}{2}{1}{The integral formula for < z).}\n Consider the equation\n\nz=\\ (U'-g,t-g,)- dt,\n\n  i\n\ndetermining z in terms of if; the path of integration may be any\ncurve which does not pass through a zero of M - g. t - g . On\ndifferentiation, we get\n\n(i/ = 4?'-< f-...\n\nand so =Sf> ( + oc),\n\nwhere a is a constant.\n\n* The difficult problem of establishing the existence of such numbers\nw and Wj when g and g are given is solved in \\hardsubsectionref{21}{7}{3}.\n\nt This equation in it always has solutions, by \\hardsubsectionref{20}{1}{3}.\n\n%\n% 438\n%\n\nMake - > x; then - >0, since the integral converges, and so a is a\npole of the function; i.e., a is of the form n,,i, and so = j(2 + n,\nn) = (z).\n\nThe result that the equation z=l 4:t' - gd - (/ i)~-dt is equivalent\nto\n\nu\n\nthe equation = z) is sometimes written in the form\n\n= f,\n\n\\Subsubsection{20}{2}{2}{2}{An illustration from the theory of the circular functions.}\n\nThe theorems obtained in §>; 20'2-20'221 may be illustrated by the\ncorresponding results in the theory of the circular functions. Thus we\nmay deduce the properties\n\nof the function cosec- z from the series 2 z- mTT)~ in the following\nmanner :\n\nm=-a)\n\nDenote the series by/ (2); the series converges absolutely and\nuniformly* (with regard to z) except near the points mn at which it\nobviously has double poles. Except at these points, /(j) is analytic.\nThe effect of adding any multiple of tt to is to give a series whose\nterms are the same as tho.se occurring in the original series; since\nthe series converges absolutely, the sum of the series is unaffected,\nand 80/(2) is a periodic function of z icith period n.\n\nNow consider the behaviour oi $f(z)$ in the .strip for which -\\ 7r R z)\n\\ n. From the periodicity of f z), the value off z) at any point in\nthe plane is equal to its value at the corresponding point of the\nstrip. In the strip/ (2) has one .singularity, namely 2 =; and /(2)\nis bounded as 2-*-oc in the strip, becau.se the terms of the series\nfor/ (2 are\n\nac\n\nsmall compared with the corresponding terms of the comparison series\n2' m~ .\n\nm= - 00\n\nIn a domain including the point z=0, f z)-z~ is analytic, and is an\neven function; and consequently there is a Maclaurin expansion\n\n/(2)-2-2= 2 a, z valid when ' z' <n. It is easily seen that\n\na2 = 27r-- (2 + l) 2 jn-'\"~-,\n\nm = l\n\nand so o= a2 = 67r~* 2 in'* .\n\nm=l\n\nHence, for small values of | 2 |,\n\nf z) = z- + + \\ z + 0(z*). Differentiating this result twice, and also\nsquaring it, we have\n\nf\"(z)=ez- + +0 z%\n\n Hz)=z-*+p- +n+o z ).\n\nIt follows that /\" (2) -e/'-i (2) + 4/(2)= (z ).\n\nThat is to say, the function /\" (2) - 6/ (2) + 4/\" (2) is analytic at\nthe origin and it is obviously periodic. Since its only possible\nsingularities are at the points mn, it follows from the periodic\nproperty of the function that it is an integral function.\n\n* By comparison with the series 2' m~' .\n\nm = - 30\n\n%\n% 439\n%\n\nFurthei*, it is bounded as z-s-qc in the strip - ir R z) 7r, since f\nz) is bounded and so is* f\" (z). Hence/\" (2) - 6/ (3) + 4/(2) is\nbounded in the strip, and therefore from its periodicity it is bounded\neverywhere. By Liouville's theorem \\hardsubsectionref{5}{6}{3}) it is therefore a\nconstant. By making z ~0, we see that the constant is zero. Hence the\nfunction cosec z satisfies the equation\n\nf\"(z) = 6fHz)-4f z).\n\nMultiplying by 2/' (s) and integrating, we get\n\nf z) = 4P z) f(z)-l +c,\n\nwhere c is a constant, which is easily seen to be zero on making use\nof the power series\n\nfor/' (2) and/ (2).\n\nWe thence deduce that 2s = I f' t-l)~i dt,\n\nJ fiz)\n\nwhen an appropriate path of integration is chosen.\n\nExample 1. If j/ = (2) and primes denote difierentiations with regard\nto 2, shew that\n\n4 -|j3=tV (y- i)-H0/-.'.2)-H(3/-.3)- -|y(3/- i)-'(y- 2)-V.y- 3)--\\\n\nwhere ej, e, e are the roots of the equation Afi - got - gz = - [AVe\nhave y\" = 4f-go,y-g\n\nDifferentiating logarithmically and dividing by y\\ we have\n\nr=\\\n\nDifferentiating again, we have\n\n2y\"' 4?/\"2 3,,\n\ny y r=i '\n\nAdding this equation multiplied by j to the square of the preceding\nequation, multiplied by, we readily obtain the desired result.\n\nIt should be noted that the left-hand side of the equation is half the\nSchwarziaii derivative t of z with respect to y; and so z is the\nquotient of two solutions of the equation\n\nc + Ire,.!, (//-O -gy n (.-..) j .=0.]\n\nExample 2. Obtain the 'properties of homogeneity ' of the function\n(2); namely that\n\n H>''')= '' f 'l'\"')'; ~'92, X-V3) = X-'\\&?(--; <72,5'3), \\ 1 A 2/ \\\ni CO2/\n\nwhere (s M denotes the function formed with periods 2q)i, 2a)2 and (2;\ng, g )\n\ndenotes the function formed with invariants g-n g -\n\n[The former is a direct consequence of the definition of z) by a\ndouble series; the latter may then be derived from the double series\ndefining the g invariants.]\n\n* The series for /\" (s) may be compared with 2' t~'*.\n\nm= -\n\nt Cayley, Gamh. Phil. Tram. xiii. (1883), p. 5 [Math. Papers, xi. p.\n148].\n\n%\n% 440\n%\n\n\\Section{20}{3}{The addition-theorem for the function TODO.}\n\nThe function z) possesses what is known as an addition-theorem; that\nis to say, there exists a formula expressing J z + y) as an algebraic\nfunction oi z) and (y) for general values* <) z and ?/.\n\nConsider the equations\n\ni ' z) = Af z) + B, <,j' y) Af j) + B,\n\nwhich determine A and B in terms of and y unless z) = < y), i.e.\nunlessf z = ±y (mod. 2wi, 2\\&)2),\n\nNow consider \\&>' (0 - iP (t) - >\n\n i/a function of f. It has a triple pole at = and consequently it has\nthree, and only three, irreducible zeros, by \\hardsubsectionref{20}{1}{3}; the sum of these\nis a period, by \\hardsubsectionref{20}{1}{4}, and as =z, =y are two zeros, the third\nirreducible zero must be congruent to - - y. Hence - z - y h a. zero\nof ' ( ) - Af ( ) - B,\n\nand so\n\n o' -z-y)=A< -z-y) + B.\n\nEliminating A and B from this equation and the equations by which A\nand B were defined, we have\n\n  z) f' z) 1 =0.\n\ni iz y) - ' z + y) 1\n\nSince the derived functions occurring in this result can be expressed\nalgebraically in terms of z), i> y), <fP (z + y) respectively (§\n20\"22), this result really expresses .> z + y) algebraically in terms\nof i z) and < (y). It is therefore an addition-theorem.\n\nOther methods of obtaining the addition-theorem are indicated in §\n20-311 examples 1 and 2, and \\hardsubsubsectionref{20}{3}{1}{2}.\n\nA symmetrical form of the addition-theorem may be noticed, namely\nthat, if u + V -I- w = 0, then\n\n! ij(u) i iu) 1 =0.\n\n\\&(v) '(v) 1 (lu) ' (lu) 1\n\n\\Subsection{20}{3}{1}{Another form of the addition-theorem.}\n\nRetaining the notation of \\hardsectionref{20}{3}, we see that the values of, which\nmake ' ( ) - A ( ) - B vanish, are congruent to one of the points z,\ny,-z - y.\n\n* It is, of course, unnecessary to consider the special cases when y,\nor z, or ij +z is n period.\n\nt The function z)- (y), qua function of z, has double poles at points\ncongruent to 2 = 0, and no other singularities; it therefore (§\n20-13) has only two irreducible zeros; and the points congruent to z=\ny therefore give all the zeros of (z) - J (y).\n\n%\n% 441\n%\n\nHence ' (0- l- fr (O + B]- vanishes when t is congruent to any of the\npoints z, y, - z - y. And so\n\n4j.nr) - AY K) - AB + g. f 0 - (B-' + 9s)\n\nvanishes when j ( ) is equal to any one of (z), y), j (z + y).\n\nFor general values of z and y, j (z), o (y) and z + y) are unequal and\nso they are all the roots of the equation\n\n4>Z - A-Z-- - -lAB + g )Z- (B- +g,) = 0.\n\nConsequently, by the ordinary formula for the sum of the roots of a\ncubic equation,\n\n ( ) + iHy) + i (2 + y) = lA%\n\nand so i. + y)=li - -,). o(y),\n\non solving the equations by which A and B were defined.\n\nThis result expresses j (z + y) explicitly in terms of functions of z\nand of 2/.\n\n\\Subsubsection{20}{3}{1}{1}{The duplication formula for < z).}\n\nThe forms of the addition-theorem which have been obtained are both\nnugatory when y = z. But the result of \\hardsubsectionref{20}{3}{1} is true, in the case of\nany given value of z, for general values of y. Taking the limiting\nform of the result when y approaches z, we have\n\nFrom this equation, we see that, if 22- is not a period, we have\n\n/ox Ir W (z) - i ' + h) o / X g (2z) = -J hm V- -x - -7 ~-y - 2p (z)\n\n= -. 11m\n\non applying Taylor's theorem to J z + h), j' z + h)\\ and so\n\n < >=i |<f- ( >'\n\nunless 2z is a period. This result is called the duplicatioih formula.\nExample 1. Prove that\n\nqua function of j, has no singularities at points congruent with 2 =\n0, ±i/; and, by making use of Liouville's theorem, deduce the\naddition-theorem.\n\n%\n% 442\n%\n\nExample 2. Apply the process indicated in example 1 to the function\n\nI (2/) ¥iy) 1 I,\n\nand deduce the addition-theorem. Example 3. Shew that\n\n  z .y) + z-y) = W z)-<p :y) -'-[ 2 z)ip y)-\\ g ] <§> z)- y) -g,\\ [By\nthe addition-theorem we have\n\nReplacing ' z) and p (y) by 4 ( )\\ (2)\\ 3 and <\\& y) - g y) - 9\nrespec- tively, and reducing, we obtain the required result.] Example\n4. Shew, by Liouville's theorem, that\n\nj W z-a) z-h)] = <p a-h) <p' z-a) + ' ' z-h) -iy a-b) z-a)- z-h)].\n\n\\addexamplecitation{Trinity, 1905.} 20\"312. Abel's* method of proving the\naddition-theorem for p z).\n\nThe following outline of a method of establishing the addition-theorem\nfor p (z) is instructive, though a completely rigorous proof would be\nlong and tedious.\n\nLet the invariants of p z) be go, g ', take rectangular axes OX, OY in\na plane, and consider the intersections of the cubic curve\n\ny - = Ax -g.2X-g with a variable line y = mx- n.\n\nIf any point ( i, y ) be taken on the cubic, the equation in z\n\nP z)-x, = Q has two solutions +2i, - i \\hardsubsectionref{20}{1}{3}) and all other\nsolutions are congruent to these two.\n\nSince P' z) = ip z)-g2P z)-gz, we have P\"- z)=yi; choose z- to be the\nsolution for which p' (2i)= -Hyi, not -y .\n\nA number Zi thus chosen will be called the parameter of ( i, j/i) on\nthe cubic.\n\nNow the abscissae i, x.2, x. of the intersections of the cubic with\nthe variable line are the roots of\n\n< ix) ~ 4x gi -gz- (\" - +nY= 0,\n\nand so ( x)=.A x- x ) (x - x, (x - x ).\n\nThe variation bx in one of these abscissae due to the variation in\nposition of the line consequent on small changes hn, 8n in the\ncoefficients m, n is given by the equation\n\n(b' (Xr) S*v+ - 8m + ? 8?t = 0, Cm en\n\nand so * (f)' (Xr) 8 r = 2 (mx + n) x tm - 8n),\n\nTODO\n\nwhence 2 - =2 2\n\n=1 mjCr + n r=l 0' (- r) '\n\nprovided that Xi, x, x are unequal, so that < ' Xr)+0.\n\n* Journal fiir Math. ii. (1827), pp. 101-181; iii. (1828), pp. 160-190\n[Oeuvres, i. (Christiania, 1839), pp. 141-2.52].\n\n%\n% 443\n%\n\nNow, if we put X (x 8)n + 8n)/4> (s), qua function of .r, into partial\nfractions, the result is\n\n3 r=\\\n\nwhere,.= lim .r ( Sm + Sw) -p\n\n= x x . 8m + 8n) lim (x - av)/ ( )\n\nby Taylor's theoi-em.\n\n:=.c, x,8m + 8n)l(f)' x \\\n\n3 3\n\nPutting x=0, we get 2 S.r,./j . = 0, i.e. 2 62,. = 0.\n\nr=l r=l\n\nThat is to say, the sum of the parameters of the points of\nintersection is a constant independent of the position of the line.\n\nVary the line so that all the points of intersection move off to\ninfinity (no two points coinciding during this process), and it is\nevident that 21 + 22 + 23 is equal to the sum of the parameters when\nthe line is the line at infinity; but when the line is at infinity,\neach parameter is a period of p (2) and therefore 21 + 22 + 23 is a\nperiod of (2).\n\nHence the sum of the parameters of three collinear points on the cubic\nis congruent to zero. This result having been obtained, the\ndeterminantal form of the addition-theorem follows as in \\hardsectionref{20}{3}.\n\n2032. The constants e-, 62, 63.\n\nIt will now be shewn that J (coi), j((Oo), i ifOs), (where 0)3= - co -\ncoo), are all unequal; and, if their values be e, e, e, then e-,\ne.2, e-, are the roots of the equation 4 * - g t - g O.\n\nFirst consider < ' (\\&)i). Since ' z) is an odd periodic function, w e\nhave \\&>' i i) = ~ i ' (- i) = - i ' (2<yi - i) = - < ' (ft)i), and so\nfr''(\\&>i) = 0.\n\nSimilarly < ' w. = ( ' (0)3) = 0.\n\nSince < ' z) is an elliptic function whose only singularities are\ntriple poles at points congruent to the origin, < ' z) has three, and\nonly three \\hardsubsectionref{20}{1}{3}), irreducible zeros. Therefore the only zeros of\nf' z) are points congruent to\n\nCOj, \\&),, 6)3.\n\nNext consider i z) - ei. This vanishes at (o and, since < ' wy) = 0,\nit has a double zero at (o . Since i z) has only two irreducible\npoles, it follows from \\hardsubsectionref{20}{1}{3} that the only zeros of ( z) - ei are\ncongruent to coj. In like manner, the only. zeros of z)- e-., J(z) -\nes are double zeros at points con- gruent to (1)2, ois respectively.\n\nHence i 62 = s- For if gj = e, then (z) - e has a zero at w., which\nis a point not congruent to Wj.\n\nAlso, since ' (z) = 4 (z) - gz (z) - g and since '' (z) vanishes at\ncoj, to,, 6)3, it follows that 4 =* (z) - g2 (z) - g vanishes when p\n(z) = e, 62 or e .\n\nThat is to say, e, 62, e are the roots of the equation\n\n4>f-g2t-gs = 0.\n\n%\n% 444\n%\n\nFrom the well-known formulae connecting roots of equations with their\n\ncoefficients, it follows that\n\ne, + e. + 3 = 0,\n\nExample 1. When g and rg are real and the discriminant g.? - %1g- is\npositive, shew that ex, e2 s are all real; choosing them so that e-\n>eo> 63, shew that\n\n. 00 0,1=1 t -g t-g- ~ dt,\n\nand 0)3 = - 1 / ' g:i+g.it - 4fi) ~ dt,\n\nso that 0)1 is real and 003 a pure imaginary.\n\nExample 2. Shew that, in the circumstances of example 1, p z) is real\non the peri- meter of the rectangle whose corners are 0, 0)3, wi +\ncos, coi.\n\n\\Subsection{20}{3}{3}{The addition of a half-period to the argument of p (z). }\nFrom the form of the addition-theorem given in \\hardsubsectionref{20}{3}{1}, we have\n\n,(,)., +,K)=H|-l;!- r.\n\n3\n\nand so, since J'-(z) = 4 n P z) - er,\n\nr=l\n\nwe have (-'+o,.) = ' <\";!l' i''\"'\" - W- .\n\n J Z) - Bi\n\n3 on using the result 2 6 =0;\n\nr=l\n\nthis formula expresses (s + coi) in terms of (2).\n\nExample 1.' Shew that\n\n  (|6,i)=ei± (61-62) (61-63) -\n\nExample 2. From the formula for z + at. combined with the result of\nexample 1, shew that\n\n  ( CO, + Q).,) = 61 + (61 - 62) (61 - 63) .\n\n\\addexamplecitation{Math. Trip. 1913.}\n\nExample 3. Shew that the value of '(2) '(z-t-wi) ' (s-l-wo) (2 + W3)\nis equal to the discriminant of the equation 4t - got - g3=0.\n\n[Differentiating the result of \\hardsectionref{20}{3}3, we have\n\nr (2 -f l) = - (61 - 62) (61 - 63) ' (2) if> (2) - 6, -2;\n\nfrom this and analogous results, we have\n\nf (2) ' (2 + Wi) g)' (2 + CO2) p' (2 -I- CO3)\n\n= (61 -62)2 (62 -63)- (63-61)2 (2) n p(2)-6, -2\n\nr=l = 16(6l-62)M 2- 3)M 3-e,)\n\nwhich is the discriminant g - Tig- in question.]\n\n%\n% 445\n%\n\nExample 4. Shew that, with appropriate interpretations of the\nradicals,\n\n ' (icoi)= -2 e,-e.,) e,-e )]i l ei-e ) + e -e )h .\n\n\\addexamplecitation{Math. Trip. 1913.}\n\nExample 5. Shew that, with appropriate interpretations of the\nradicals, p 2z) - e p 2z) - 63 * + W (22) - 3 * P (22) - e\n\n+ iP m~e, i ip 2z)-e.2 = p z)-p 2z).-\n\n\\Section{20}{4}{Quasi-periodic functions. The function* TODO.}\n\nWe shall next introduce the function (z) defined by the equation\n\ndz - ' ' coupled with the condition lim [ z) - z~ ]=0.\n\nSince the series for p z) - z~' converges uniformly throughout any\ndomain from which the neighbourhoods of the points f 'm,n are\nexcluded, we may integrate term-by-term \\hardsectionref{4}{7}) and get\n\nl;iz)-z- = -n z)-z-,dz J\n\n= -S' r z-n,,nr'- 7n%]dz, 711, n J\n\nandso ( )= +N !\\ \\ + +\n\nThe reader will easily see that the general term of this series is\n\n0( n i,;-= ) as in,,,, - co;\n\nand hence (cf \\hardsectionref{20}{2}), z) is an analytic function of z over the Avhole\nsr-plane except at simple poles (the residue at each pole being -H 1)\nat all the points of the set i m, ti- lt is evident that\n\nZ m.n \\ Z -T i-m,n iii,n I2, j,j)\n\nand, since this series consists of the terms of the series for (z),\nderanged in the same way as in the corresponding series of \\hardsubsectionref{20}{2}{1}, we\nhave, by \\hardsubsectionref{2}{5}{2},\n\n  -z) = - (z),\n\nthat is to say, z) is an odd function of z.\n\n* This function should not, of course, be confused with the\nZeta-funetion of Eieraann, discussed in Chapter xni.\n\nt The symbol il', is used to denote all the points fl,,,i with the\nexception of the origin (cf.\\hardsectionref{20}{2}).\n\n%\n% 446\n%\n\nFollowing up the analogy of J 20-222, we may compare z) with the\nfunction cot 2 defined by the series 2~'+ 2' (2- i7r)~' + (m7r)~i,\nthe equation -7; cot 2 = - cosec 2\n\ncori-e ponding to f (2) = - (2).\n\n\\Subsection{20}{4}{1}{The quasi-periodicity of the function i z).}\n\nThe heading of \\hardsectionref{20}{4} was an anticipation of the result, which will\nnow be proved, that i z) is not a doubly-periodic function .of z; and\nthe effect on z) of increasing z by 2( i or by 2w.. will bo\nconsidered. It is evident from \\hardsubsectionref{20}{1}{2} (III) that z) cannot be an\nelliptic function, in view of the fact that the residue of z) at every\npole is + 1.\n\nIf now we integrate the equation\n\nip z- 2\\&)i) = (j) z\\\n\nweget ( +2a,,)=r(~0 + 277i,\n\nwhere 27 1 is the constant introduced by integration; putting z= - ai\n, and taking account of the fact that z) is an odd function, we have\n\nIn like manner, z + 2\\&)o)= z)- 2??2,\n\nwhere 1-1 = K ( 2)-\n\nExample 1. Prove by Liouville's theorem that, if A--i-?/-|-2 = 0, then\n\n(Frobenius u. Stiekelberger, Journal fur Math, lxxxviii.)\n\n[This result is a pseudo-addition theorem. It is not a true\naddition-theorem since\n\nC i- ), C y\\ C (2) ai'e not algebraic functions of ( (x), f (.?/), C\n(2)-]\n\nExample 2. Prove by Liouville's theorem that\n\n2 I 1 X) p (x)\n\n' 1 PLy) PHy)\n\n1 (2) (2)\n\n1 p x) p' x)\\ \\ = ax+y + z)-i x)-( jj)-C .z).\n\n1 (y) F(i )\n\n1 (2) F'(2) I Obtain a generalisation of this theorem involving n\nvariables.\n\n\\addexamplecitation{Math. Trip. 1894.}\n\n\\Subsubsection{20}{4}{1}{1}{Tlie relation hetiueen ij and rj.,.}\n\nWe shall now shew that\n\n1 .\n\nTo obtain this result consider i z)dz taken round the boundary of a\ncell. There is one pole of i z) inside the cell, the residue there\nbeing -I- 1.\n\nHence 1: (z) dz = 27ri.\n\nJ r\n\n%\n% 447\n%\n\nModifying the contour integral in the manner of \\hardsubsectionref{20}{1}{2}, we get\n\n -Ki = K z) - r( + 2a),)i dz - ( ) - ( + 2 o (\n\n= - 27?2 rf + 27/1 fZt\n\nand so 27rt = - iVi i + ' Vi -z,\n\nwhich is the required result.\n\n\\Subsection{20}{4}{2}{The function a z).}\n\nWe shall next introduce the function o z), defined by the equation\n\nj- \\ og(7 z)=l; z)\n\ncoupled with the condition lim [a z)!z] = 1.\n\nOn account of the uniformity of convergence of the series for t, z),\nexcept near the poles of z), we may integrate the series term-by-term.\nDoing so, and taking the exponential of each side of the resulting\nequation, we get\n\na(z) zn'\\ [ l- ' ' ( z z\n\n( ) = n' l- -)exp\n\n+\n\n--m.n 2S2T.\n\nthe constant of integration has been adjusted in accordance with the\ncondition stated.\n\nBy the methods employed in §§ 202, 20-21, 20-4, the reader will easily\nobtain the following results :\n\n(I) The product for a (z) converges absolutely and uniformly in any\nbounded domain of values of z.\n\n(II) The function a(z) is an odd integral function of with simple\nzeros at all the points flm,n'\n\nThe function a (z) may be compared with the function sin z defined by\nthe product\n\nthe relation -j- log sin z = cot z corresponding to -i- log o- (z) =\n(z).\n\n\\Subsubsection{20}{4}{2}{1}{The quasi-periodicity of the function cr z).}\n\nIf we integrate the equation\n\n  z + 2(o,) = !: z +2v we get a (z + 2(Wi) = ce- ' -a (z),\n\nwhere c is the constant of integration; to determine c, we put z = -\ncoi, and\n\nthen\n\na (coi) = - ce~-''''\">o- (coi).\n\nz\n\nJ = - CO (\\\n\n%\n% 448\n%\n\nConsequently c = - e-'''\"',\n\nand o- (z + 2\\&)j) = - e2''i( +'-i) a z).\n\nIn like manner (t(z + 2<i)o) = - g i 'z-i-'xj) a (z).\n\nThese results exhibit the behaviour of (t z) when z is increased by a\nperiod of (z).\n\nIf, as in \\hardsubsectionref{20}{3}{2}, we wTite ais = - co - ay.,, then three other\nSigma-functions are defined by the equations\n\na, z) = e-'i'-'o- (z + \\&),.) V (wr) (? = !, 2, 3).\n\nThe four Siguia-functions are analogous to the four Theta-functions\ndis- cussed in Chapter XXI (see \\hardsectionref{21}{9}).\n\nExample 1 . Shew that, if m and n are any integers,\n\n<r z + 277i(Oi + 2na>2) = ( - )\"' + \" a- (z) exp 27nrii + 2nr).>) z +\n2m-r) <3>i + 4? ?i;j,a)2 + 2n' r\\ < ia>, and deduce that r]xi>ii-\nr]-i<Ji\\ is an integer multiple of \\ ni.\n\nExample 2. Shew that, if 5' = exp iriu)-!! o>i)i so that y < 1, and if\n\nthen / (2) is an integi-al function with the same zeros as (t z) and\nalso F z)la- z) is a doubly-periodic function of 2 with periods 2a)i,\n2a).2-\n\nExample 3. Deduce from example 2, by using Liouville's theorem, that\n\nExample 4. Obtain the result of example 3 by expressing each factor on\nthe right as a singty infinite product.\n\n\\Section{20}{5}{Formulae expressing any elliptic function in terms of Weie7'strassian functions ivith the same periods.TODO}\n\nThere are various formulae analogous to the expression of any rational\nfraction as (I) a quotient of two sets of products of linear factors,\n(II) a sum of partial fractions; of the first type there are two\nformulae involving Sigma- functions and Weierstrassian elliptic\nfunctions respectively; of the second type there is a formula\ninvolving derivates of Zeta-functions. These formulae will now be\nobtained.\n\n\\Subsection{20}{5}{1}{The expression of any elliptic function in terms of z) and ( >'z).}\n\nLet $f(z)$ be any elliptic function, and let i z) be the Weierstrassian\nelliptic function formed with the same periods 2\\&)i, 2\\&)o.\n\nWe first ite\n\nfiz) = I Uiz) +/(- z)] + \\ [ f(z) -f - z)\\ Wizfr] ' z).\n\n%\n% 449\n%\n\nThe functions\n\nf z) +/(- z\\ [f z) -/(- )] Wi )]-' are both even functions, and they\nare obviously elliptic functions when/( ) is an elliptic function.\n\nThe solution of the problem before us is therefore effected if we can\nexpi ess any even elliptic function < (2), say, in terms of i ) (z).\n\nLet a be a zero of (f> (z) in any cell; then the point in the cell\ncongruent to - a will also be a zero. The irreducible zeros of (z) may\ntherefore be arranged in two sets, say a, a, ...an and certain\npoints congruent to - a-,\n\n 2 >    - Cln\n\nIn like manner, the irreducible poles may be arranged in two sets, say\nhi, b.., ... bn, and certain points congruent to -61, - 60, ... - 6 .\nConsider now the function*\n\n1 fi H')( )-iP(\"r)\n\nd> z)-, = i iiO Z) - ) br)\n\nIt is an elliptic function of z, and clearly it has no poles; for the\nzeros of (b (z) are zeros f of the numerator of the product, and the\nzeros of the denominator oi\" the product are polesf of 4>(z).\nConsequently by Liouville's theorem it is a constant, A, say.\n\nTherefore < (.) = A H | ? 1,\n\nthat is to say, <f) (z) has been expressed as a rational function of J\n(z).\n\nCarrying out this process with each of the functions\n\nf z) +fi-z), f(z) -f -z) ip\\ z) -\\\n\nwe obtain the theorem that any elliptic function f (z) can be\nexpressed in terms, of the Weierstrassian elliptic functions (z) and\np' z) luith the same periods., the expression being rational in z) and\nlinear in < ' z).\n\n\\Subsection{20}{5}{2}{The expression of any elliptic function as a\n  linear combination of Zeta functions and their derivatives.}\n\nLet $f(z)$ be any elliptic function with periods 2coi, 2(iJo: Let a set\nof irreducible poles of $f(z)$ be i, c/o, ... a, and let the principal\npart \\hardsubsectionref{5}{6}{1}) off z) near the pole a be\n\n k,i . Ck,2 Ck, rje\n\nz-ajc (z- a f '\" z- ttkY '\n\n* If any one of the points a,, or h is congruent to the origin, we\nomit the corresponding factor ii> (2) - .' (rt,.) or J ( ) - (\\&,.).\nThe zero (or pole) of the product and the zero (or pole) of (j) [z) at\nthe origin are then of the same order of multiplicit.y. In this\nproduct, and in that of \\hardsectionref{20}{5}o, factors corresponding to multiple\nzeros and poles have to be repeated the appropriate number of times.\n\nf Of the same order of multiplifity.\n\nW. M. A, 29\n\n%\n% 450\n%\n\nThen we can shew that\n\nf z) = .4, + i \\ c,,, 2 - ( ) -Ct,,r ( - \"X\") + . c - l (.\n\nk:\n\nwhere A., is a constant, and (z) denotes -r- z).\n\nDenoting the summation on the right by F z), we see that F z +\n-2co,)-F z)= I 27J,Ck,,\n\nk = l\n\nby \\hardsubsectionref{20}{4}{1}, since all the derivates of the Zeta-functions are\nperiodic.\n\nn\n\nBut S C/c i is the sum of the residues of y'(2 ) at all of its poles\nin a cell,\n\nk = l\n\nand is consequently \\hardsubsectionref{20}{1}{2}) zero.\n\nTherefore F(z) has period 2\\&)i, and similarly it has period 2coo; and\nso f(z) - F (z) is an elliptic function.\n\nMoreover $F(z)$ has been so constructed that $f(z) - F(z)$ has no poles at\nthe points nj, o, ... a; and hence it has no poles in a certain cell.\nIt is consequently a constant, A.,, by Liouville's theorem.\n\nThus the function $f(z)$ can be expanded in the form\nA=is=i(s - i; !\nThis result is of importance in the problem of\nintegrating an elliptic function $f(z)$ when the principal part of its\nexpansion at each of its poles is known; for we obviously have\n\nf(z)dz = A.z+ 2 k=i\n\nCk,i\\ og a (z - ak)\n\nwhere C is a constant of integration.\n\nExample. Shew by the method of this article that\n\nand deduce that\n\nwhere C is a constant of integration.\n\n\\Subsection{20}{5}{3}{The expression of any elliptic function as a\n  quotient of Sigma-functions.}\n\nLet $f(z)$ be any elliptic function, with periods 2\\&)i and 2a)2, and\nlet a set of irreducible zeros of /( ) be a,, a, ... an. Then\n\\hardsubsectionref{20}{1}{4}) we can choose a\n\n%\n% 451\n%\n\nset of poles bi,bo, ... hn such that all poles 0 /(2) are congruent to\none or other of them andf\n\na + a2+ ... + an = bi + b.2 + ... +bn.\n\nConsider now the function\n\n  (r(z- ar)\n\nThis product obviously has the same poles and zeros as f z); also the\neffect of increasing z by 2(0j is to multiply the function by\n\n  exp [2771 z - g,.),.=1 exp 277i ( - br)] The function therefore has\nperiod 2\\&)i (and in like manner it has period 2\\&)2), and so the\nquotient\n\nis an elliptic function with no zeros or poles. By Liouville's\ntheorem, it must be a constant, A- say.\n\nThus the function/' (2 ) can be expressed in the form\n\nr=l(T Z-b,)\n\nAn elliptic function is consequently determinate (save for a\nmultiplicative constant) when its periods and a set of irreducible\nzeros and poles are known. Example 1. Shew that\n\nExample 2. Deduce by difFerentiation, from example 1, that\n\nand by further differentiation obtain the addition-theorem for (z).\n\nII\n\n2 b,., shew that\n\n=1\n\nI (r ar-bi)(r(ar-b. ...(T ar-bJ \\,.=1 o- (a,. - ai) o- (a,. - a J . .\n. . . . o- (a - a ) ' the * denoting that the vanishing factor o- (a -\na ) is to be omitted. Example 4. Shew that\n\n  z)-e,. = a/ z)la' z) (r=l,2, 3).\n\n[It is customary to define g? z) - e to mean o-,. (2)/(r (2), not -\no-,. (s)/'o- (2).] Example 5. Establish, by example I, the '\nthree-term equation,' namely,\n\nd z + a) a- z - a) a- b + c) a- b - c) + <T z + b) a- z - b) a- c + a)\na c - a)\n\n+ 0- z + c)(t z-c) (r a + b)a a-b) = 0.\n\nt Multiple zeros or poles are, of course, to be reckoned according to\ntheir degree of multi- plicity; to determine b, h-i, ...b, we\nchoose 6i, bo,, ... b, \\ i, 6,/ to be the set of poles in the cell\nin which ai, a-i, ...a lie, and then choose \\&, congruent to 6, in\nsuch a way that the required equation is satisfied.\n\n29-2\n\nExample 3. If 2 a,.= 2 6,., shew that\n\nr-. r=]\n\n%\n% 452\n%\n\n[This result is due to Weierstrass; see p. 47 of the edition of his\nlectures by Schwarz.] The equation is characteristic of the\nSigma-function; it has been proved by Halphen, Fonctions ElUptiques,\nI. (Paris, 1886), p. 187, that no function essentially diflferent from\nthe Sigma-function satisfies an equation of this type. See p. 461,\nexample 38.\n\n\\Subsection{20}{5}{4}{The connexion between ani/ hvo elliptic functions with the same periods.}\n\nWe shall now prove the important result that an algebraic relation\nexists bettveen any ttuo elliptic functions, f(z) and <f)(z), with the\nsame periods.\n\nFor, by \\hardsubsectionref{20}{5}{1}, we can express $f(z)$ and (z) as\nrational functions of\nthe Weierstrassian functions (z) and ' (z) with the same periods, so\nthat\n\nf(z) = R, [p (z), io' (z)], < (z) = R, (z), ' (z)], where Ri and jB,\ndenote rational functions of two variables.\n\nEliminating (z) and ' (z) algebraically from these two equations and\n'Uz) = 4>f' z)-go\\ \\& z)-g\n\nwe obtain an algebraic relation connecting f(z) and (f> (z); and the\ntheorem is proved.\n\nA particular case of the proposition is that every elliptic function\nis con- nected with its derivate by an algebraic relation.\n\nIf now we take the orders of the elliptic functions $f(z)$ and 4> z) to\nbe $m$ and $n$ respectively, then, corresponding to any given value of/( )\nthere is (§ 2018) a set of m iiTeducible values of z, and consequently\nthere are m values (in general distinct) of cf) (z). So, corresponding\nto each value off, there are ni values of cf) and, similarly, to each\nvalue of (f) correspond n values of /.\n\nThe relation between f(z) and cf) (z) is therefore (in general) of\ndegree m in (f) and n in f\n\nThe relation may be of lower degree. Thus, iff(z) = p (z), of order 2,\nand (j) (2) = 2 of order 4, the relation is/- = cf).\n\nAs an illustration of the general result take f(z) = o z), of order 2,\nand (j> (z) = y (z), of order 8. The relation should be of degree 2 in\n(/> and of degree 3 in f; this is, in f;ict, the case, for the\nrelation is < - = 4/'-' - .2/- 3.\n\nExample. If u, v, ic are three elliptic functions of their argument of\nthe second order with the same periods, shew that, in general, there\nexist two distinct relations which are linear in each of l, v, w,\nnamely\n\nA uvtv+Bvw + Cicu + Btiv + E u + F r + G iv+ H =0, A'uvw + B'vw +\nC'lvti + D'u v + E'u + F'v + G'w + H' = 0, where 1, B, . . ., IT'\nare constants.\n\n\\Section{20}{6}{On the integration of TODO.}\n\nIt will now be shewn that certain problems of integration, which are\ninsoluble by means of elementary functions only, can be solved by the\nintro- duction of the function < z).\n\n%\n% 453\n%\n\nLet ttoX + a af + Qa. x- + a x + a =f(x) be any quartic polynomial\nwhich has no repeated factors; and let its invariants* be\n\ng = ciocti - 4aia3 + 3a.\n\ngs = a aoCti + 2aia2a3 - ai - a a - a-ca .\n\n/'* -1\n\nLet z = /(t)] 'dt, where a-'o is any root of the equation/(a;) =;\nthen,\n\nif the function z) be construe tedf with the invariants g and g, it\nis possible to express x as a rational function of <,p z; go, g ).\n\n[Note. The reason for assuming tbat/(.r) has no repeated factors is\nthat, when/(.r) has a repeated factor, the integration can be eftected\nwith the aid of circular or logarithmic functions only. For the same\nreason, the case in which aQ = ai = need not be considered.]\n\nBy Taylor's theorem, we have\n\nf t) = 4 3 t - X,) + QA. (t - x,y + 4>A, (t - x,y + 0 ( - 'oY,\n\n(since / (xq) = 0), where\n\nA 2 = UoXq + 2aiXQ + a.,, As = o V'' + ' UiXq- + a.2Xo + ttj. On\nwriting (t - Xa)~ = t, (x - Xq)~'- =, we have\n\n2 = 1 4.43T= + QA,T + 4A,T + Ao] ~ irfr.\n\n' s\n\nTo remove the second term in the cubic involved, write\n\nr = Ar(cr-h . =A,- (s-iA,), and we get\n\nr z ['ia'- SA. - A,A,)a- 2A,A.,A,-A, -AoAs')]~ -d(T.\n\n. s\n\nThe reader will verify, without difficulty, that\n\n3i4.;- - 4 1 3 and iA- A. A - A - A A\n\nare respectively equal to g. and g-, the invariants of the original\nquartic, and so\n\ns=io z;go,g.;).\n\nNow X = Xq + Az \\ s - A. ~',\n\nand hence x = Xo + \\ f' ( o) z ', 92, Qi) - -hf\" ( 'o) ~S\n\nso that X has been expressed as a rational function of ( (z; g.,, g .\n\n* Burnside and Pauton, Tlieonj of Equations, ii. p. 113. + See \\hardsubsectionref{21}{7}{3}.\n\nJ This substitution is legitimate since A3 + O; for the equation -13 =\ninvolves /(x) = having x - Xq as a repeated root.\n\n%\n% 454\n%\n\nThis formula for cc is to be regarded as the integral equivalent of\nthe relation\n\nz\n\nExample 1. With the notation of this article, shew that Example 2.\nShew that, if\n\nI a\n\nwhere a is ani/ constant, not necessarily a zero of f x), and / (x) is\na quartic polynomial with no repeated factors, then\n\n,,, /( ) F( )+i/'W ( -)- V/\"( ) +A/( )/'\"( )\n\nthe function p (z) being formed with the invariants of the quartic\n/(:c).\n\n\\addexamplecitation{Weierstrass.}\n\n[This result was first published in 1865, in an Inaugural-dissertation\nat Berlin by Biermann, who ascribed it to Weierstrass. An alternative\nresult, due to Mordell, Messengery XLIV. (1915), pp. 138-141 is that,\nif\n\n\\ C' v y dx - X dy\n\nwhere /(:f, y) is a homogeneous quartic whose Hessian is h x, y), then\nwe may take\n\nx=ap' z) ff+ip z)f,+ h\n\ny-hp- z) lf-\\ p z)f,-Ua, where /and h stand for /(a, 6) and A (a, 6),\nand suffixes denote partial dMferentiations.] Example 3. Shew that,\nwith the notation of example 2,\n\n(. M /w/( ) +/( ) I /'( ),rw\n\n 'x-af 4(.r-a) 24 '\n\nand F( )= - 1, 3 - rr l /( ) - j/- 3 +/ U /(-) *\n\n* ' x-af A x-a)-y-' ' x-af A x-ay] ' '\n\n\\Section{20}{7}{The uniformisation* of curves of genus unity.}\nThe theorem of §\n20*6 may be stated somewhat differently thus : If the variables x and\ny are connected by an equation of tlie form y\"- = a id + a-i a? + a x\n+ a x + a,\n\nthen they can be expressed as one-valued functions of a variable z by\nthe\n\nequations, .,,, . .\n\n  x=x,+\\ r x,)\\ p z) - j-j\" x,yr\n\ny = -U' o)p' z) p z)-i-J\" xo)]\n\nwhere f(x) = a x + 4aia + Qa.,x + 'ia x -t- a, Xq is any zero of f\nx), and the function < z) is formed with the invariants of the quartic\n; and z is such that\n\nz=r [f t)]- dt.\n\n* This term employs the word uniform in the sense one-valued. To\nprevent coufusion with the idea of uniformity as explained in Chapter\nin, tliioughout the present work we have used the phrase 'one-valued\nfunction' as being preferable to 'uniform function.'\n\n!07]\n\n%\n% 455\n%\n\nIt is obvious that y is a two-valued function of x and a; is a\nfour-valued function of y; and the fact, that x and y can be\nexpi'essed as one-valued functions of the variable z, makes this\nvariable z of considerable importance in the theory of algebraic\nequations of the type considered; z is called the uniformising vm\niahle of the equation\n\ny\" = a x* -f- 4ai.'C -f a. x\" a x + a .\n\nThe reader who is acquainted with the theory of algebraic plane curves\nwill be aware that they are classified according to their deficiency/\nor genus*, a number whose geometrical significance is that it is the\ndifterence between the number of double points possessed by the curve\nand the maximum number of double points which can be possessed by a\ncurve of the same degree as the given curve.\n\nCurves whose deficiency is zero are called tmicursal curves. If/ (x,\ny) = is the equation of a unicursal curve, it is well known t that x\nand ?/ can be expressed as rational functions of a 'parameter. Since\nrational functions are one-valued, this parameter is a uniformising\nvariable for the curve in question.\n\nNext consider curves of genus unity; let /(.r, ?/) = be such a curve;\nthen it has been shewn by CIebsch| that x and y can be expressed as\nrational functions of and ?; where ry' is a polynomial in | of degree\nthree or four. Hence, by \\hardsectionref{20}{6}, and r\\ can be expressed as rational\nfunctions of (2) and ' z\\ (these functions being formed with suitable\ninvariants), and so x and y can be expressed as one-valued (elliptic)\nfunctions of z which is therefore a uniformising variable for the\nequation under consideration.\n\nWhen the genus of the algebraic curve /(.r, 3/) = is greater than\nunity, the uniformi- sation can be effected by means of what are known\nas automorphic functions. Two classes of such functions of genus\ngreater than unity have been constructed, the first by Weber,\nOottinger Nach. (1886), pp. 359-370, the other by Whittaker, Phil.\nTrans, cxcii. (1898), pp. 1-32. The analogue of the\nperiod-parallelogram is known as the 'fundamental polygon.' In the\ncase of Weber's functions this polygon is ' mviltiply-connected,' i.e.\nit consists of a. region containing islands which have to be regarded\nas not belonging to it; whereas in the case of the second class of\nfunctions, the polygon is ' simply-connected,' i.e. it contains no\nsuch islands. The latter class of functions may therefore be regarded\nas a more immediate generalisation of elliptic functions. Cf. Ford,\nIntroduction to theory of Auto- morphic Functions., Edinburgh Math.\nTracts, No. 6 (1915).\n\nREFERENCES.\n\nK. Weierstrass, Werke, i. (1894), pp. 1-49, 11. (1895), pp. 245-255,\n257-309.\n\nC. Briot et J. C. Bouquet, Theorie des fonctions elliptiques. (Paris,\n1875.)\n\nH. A. ScHWARZ, Formeln und Lehrsdtze zuni Gehrauche der elliptischen\nFunktionen. Nach\n\nVorlesungen und Aufzeichnungen des Herrn Prof. K. Weierstrass.\n(Berlin, 1893.) A. L. Daniels, 'Notes on Weierstrass' methods,'\nAmerican Journal of Math. vi. (1884),\n\npp. 177-182, 253-269; vn. (1885), pp. 82-99. J. LiouviLLE (Lectures\npublished by C. W. Borchardt), Journal fiir Math. Lxxxviii.\n\n(1880), pp. 277-310. A. Enneper, ElliptiS'-he Funktionen. (Zweite\nAuflage, von F. Miiller, Halle, 1890.) J. Tannery et J. Molk,\nFonctions Elliptiques. (Paris, 1893-1902.)\n\n* French genre, German Geschlecht.\n\nt See Salmon, Higher Plane Curves (Dublin, 1873), Ch. 11.\n\nX Journal f fir Math. lxiv. (1865), pp. 210-270. A proof of the result\nof Clebsch is given by Forsyth, Theory of Functions (1918), § 248. See\nalso Cayley, Proc. London Math. Sac. iv. (1873), pp. 347-352 [Math.\nPapers, vni. pp. 181-187].\n\n%\n% 456\n%\n\nMiscellaneous Examples.\n\n1. Shew that\n\n9 'ry)- z-y)=-\\&' z) ' y) ip z)- y)]-\\\n\n2. Prove that\n\nwhere, on the right-hand side, the subject of diflferentiation is\nsymmetrical in 2, y, and w.\n\n\\addexamplecitation{Math. Trip. 1897.} ti. Shew that\n\nn -y) r\\ y- ' r'o - )\n\n\\ 1\n\n55 2\n\nr\"(2-y) r\"(3/-\"') r'( '-2)\n\n  (-- y) (y- O (w'- ) 1 1 1\n\n\\addexamplecitation{Trinity, 1898.}, dy\n\n4. If y= (2)-ei, .y'=\n\nshew that y is one of the vahies of\n\nif \\ d' \\ i 1 i\n\n|/(y-4 2logyj +(ei-e2)(ei-e3)|\n\n\\addexamplecitation{Math. Trip. 1897.}\n\n5. Prove that\n\n2 W (2) - (P (y) - P ( ') ' IP (y + ) - 4* (P (y - ' ) - )* = O'\n\nwhere the sign of summation refers to the three arguments 2, y, v.;\nand e is any one of the\n\nroots Ci, Co, So.\n\n\\addexamplecitation{Math. Trip. 1896.}\n\n6. Shew that\n\nP' z + <oi)\\ (P (i i)-£( i)r\n\nP'( ) ........\n\n\\addexamplecitation{Math. Trip. 1894.}\n\n7. Prove that\n\nP (22) - p (a,,) = IP' (2) -2 [ (2) - (|a ) 2 (2) - (a>2 +*o,i) .\n\n\\addexamplecitation{Math. Trip. 1894.}\n\n8. Shew that\n\np u + v)iO(u-v) =\n\niP (u) p (v) + ig l+giilMllMl\n\n p u)-p v)\n\n,,.V2\n\n\\addexamplecitation{Trinity, 1908.}\n\n9. If p(u) have primitive periods 2a)i, 2( 2 and f(u) = p u) - p co- '\n, while g:)i (?0 And/i (m) are similarly constructed with periods\n2a)i/yi and 2a)2, prove that\n\nPi ii) = P ti)+\"'2 p u + '2ma>iln) -p 2mcoi/7i),\n\nm=l\n\nn-1 n f u + 2ma)iin)\n\n and /i (w) = \" i\n\nn f 2mailn)\n\nm=r\n\n(Math. Trip. 1914; the first of the formulae is due to Kiepert,\nJournal fur Math. Lxxvi. (1873), p. 39.)\n\n%\n% 457\n%\n\n10. If .r = p u + a), y = <p u-a),\n\nwhere a is constant, shew that the curve on which (.r, y) lies is\n\n xy + ex + cy + g. f = 4 ( +y + c) [cxy - lg \\ where c = p(2a).\n\n\\addexamplecitation{Burnside, Messenger xxi.}\n\n11. Shew that\n\n2 \"3 (.0 - Zg.£\" u) +gi = 21 ' u)+g,Y.\n\n12. If z=r xi + 6cx + e -)-idx,\n\nverify that x=,\n\nthe elliptic function being formed with the roots -c, c + e), (c - e).\n\n\\addexamplecitation{Trinity, 1909.}\n\n\\addexamplecitation{Trinity, 1905.}\n\nF(i/)i z)-<P y) \" '' (2)- (y)\n\n13. If m be any constant, prove that\n\n1 / e' (2)-S'(2')fp(3)(;2, e MS'(2)-S'(y) y\n\n-I? IT\n\n P( )- r P(y)-er '\n\nwhere the summation refers to the values 1, 2, 3 of;; and the\nintegrals are indefinite.\n\n\\addexamplecitation{Math. Trip. 1897.}\n\n1 4. Let R x) = Ax + Bx\" + Cx\"- + Dx + ',\n\nand let |= (.r) be the function defined by the equation\n\n. '=| ( ) - /, where the lower limit of the integral is arbitrary.\nShew that\n\n20' ( ) \\ <j>' a- y) + ' ia ) 0' (a-y)+< '(a) \\ < '(a+y)-< '( )\n\n( (A'+2/)-0(a) < (o+ )-0(a) (i> a-y)-<f> a) (]i a+y)-(j) x)\n\n0'( -y)-0'(- ')\n\nc ) a-y)-cl) x) '\n\n[Hermite, Proc. J/ / Congress (Chicago, 1896), p. 105. This formula is\nan addition-formula which is satisfied by every elliptic function of\norder 2.]\n\n15. Shew that, when the change of variables\n\nis applied to the equations\n\nr + .(l+i> ) + l = 0, a.- - = 0, they transform into the similar\nequations\n\nShew that the result of performing this change of variables three\ntimes in succession is a retiirn to the original variables, r; and\nhence prove that, if and r) be denoted as functions of by -Ei u) and F\nu) respectively, then\n\nwhere A is one-third of a period of the functions E u) and F u). Shew\nthat E (u) = -P it; g2, g ),\n\nwhere 92 = '2p + - p\\ 93= -'i-- qP - P -\n\n(De Brun, Ofversigt af K. Vet. Akad., Stockholm, Liv.)\n\n%\n% 458\n%\n\n16. Shew that\n\n[chap. XX\n\naud\n\n\\&' =\n\nF ( )=\n\n2o- (2 + Wj) (T (2 + <t>2) <T (Z- <i>i - 0)9) O- (s) C (ft)i) (T (0)2)\nO\" (©i +0)2)\n\n60- (z + a) a z-a)(r z + c) a z - c)\n\n(r*(2)<r2(a)o-2(c)\n\nwhere\n\n17. Prove that\n\n+ \\&'(a-h) C z-a)-a'-b) + C <')-ah)] IS. Shew that\n\n\\addexamplecitation{Math. Trip. 1913.}\n\n\\addexamplecitation{Math. Trip. 1895.}\n\n2l (M)- (t ) gJ(i;)- (M')J ' ''\n\n\\addexamplecitation{Math. Trip. 1910.}\n\n19. Shew that\n\nC( i) + C,W2) + C(\"3)-r(W] + *2 + 3)\n\n2 (? i) - g> (M2) ( 2) - 9 n )] P ( 3) - P ( <l)\n\nF ( l) W ( 2) - (Ws) + ' ( -2) P ( 3) - ( l) + i;-'' (%) ( l) - ( 2)\n\n\\addexamplecitation{Math. Trip. 1912.}\n\n20. Shew that\n\na x+y+z) o- x-y) <r 1/ - z) a z - x) 1 I 1 P (-0 ' i- )\na3(.r)cr3(y)cr3(2) 2,\n\n1 p z) p' z) Obtain the addition-theorem for the function p z) from\nthis result.\n\n21. Shew by induction, or otherwise, that\n\n1 ( i) '( i)... <\"- )(2i)\n\n\\ /\\ xiM(n-l)j I 2 ! ... ?i :\n\n, O- (20 + 2 i + . . . + 2n) no- (2; - Z )\n\n'<T z )...a\"*' z )\n\n' 1 PizJ P'(2 )...p-1)(2 )\n\nwhere the product is taken for pairs of all integral values of X and\n/i from to 71, such\n\nthat X < /I.\n\n(Frobenius u. Stickelberger*, Journal fiir Math, lxxxiii. (1877), p.\n179.)\n\n22. Express\n\n1 p x) P( ) p' x) I\n\n1 Piy) F(y) r(3') I 1 (2) P(2) F( ) I 1 p u) p( ) f (w);\n\nas a fraction whose numerator and denominator are products of\nSigma-functions.\n\n* See also Kiepert, Journal filr Math. L.xs.yi. (1873), pp. 21-33;\nHermite, Journal fiir Math. Lxxxn. (1877), p. 346.\n\n%\n% 459\n%\n\nDeducethat if a = p(.r), 8 = p y), y=p z), 8 = p (ii), where x +\n9/+z+u = 0, then ( 2 - 63) (a - ei) (/3 - ei) (y - e ) 8 - ej) + (es -\nei) (a - e ) (/3 - e,) (7 - e ) (S - 63) *\n\n+ ( 1 - ea) (a - 63) (/3 - e ) (y - 63) (8 - 63) * = e - 63) ( 3 - ei)\n(ej - eg)-\n\n\\addexamplecitation{Math. Trip. 1911.}\n23. Shew that\n\n2C(2 )-4aiO = |J' ''\n\n3t(32i)-9C(20 =\n\n\\addexamplecitation{Math. Trip. 1905.}\n\n24. Shew that\n\nand prove that a- nu)j cr ( ) \"' is a doubly-periodic function of ?6.\n\n\\addexamplecitation{Math. Trip. 1912.}\n\n25. Prove that\n\na- (z-2a + b) a- (z -2b + a)\n\n  z-a)-( z-b)-C(a-b) + C 2a-2h)-\n\na- (26 - 2a) o- (2 - a) o- ( - 6) '\n\n\\addexamplecitation{Math. Trip. 1895.}\n\n26. Shew that, if Sj + S2 + 3 + i = 0, then\n\n 2C (2,.) = 3 2t (2,.) SP (,.) + 2 ' (.-.), the summations being\ntaken for r = l, 2, 3, 4. \\addexamplecitation{Math. Trip. 1897.}\n\n27. Shew that every elliptic function of order n can be expressed as\nthe quotient of two ex2)ressions of the form\n\naiPiz + b) + a,p' z + b) + ...+a,,p( -')(z + b),\n\nwhere b, rtj, 02, ... a are constants. (Painleve, Bulletin de la Soc.\nMath, xxvii.)\n\n28. Taking e >e2>e;, p a>) = ei, p(co') = es, consider the values\nassumed by\n\nC( )-Mf ( ')/ '\n\nas u passes along the perimeter of the rectangle whose corners are -\nco,, w + w', -a> + w\n\n\\addexamplecitation{Math. Trip. 1914.}\n\n29. Obtain an integral of the equation\n\n1 d w,, ., - -Ty = 6 (2) + 36\n\nin the form\n\ndzla z)a c) ' \\ b-2p c) ' fj'\n\nwhere c is defined by the equation\n\n(62- 39 2) (0) = 3 (63 + 3).\n\nAlso, obtain another integral in the form\n\n f j exp -sf(ai)-2aa2),\n\nwhere ( i) + P ( 2) = \\&, F ( i) + P ( 2) = 0,\n\nand neither ai + a2 nor ai-a-i is congruent to a period.\n\\addexamplecitation{Math. Trip. 1912.}\n\n%\n% 460\n%\n\n30. Prove tliat\n\n, .\\ a z + Zi) (r z + Z 2) a- z + Z3) a- (z + Zj)\n\n  '~ ' r 22 + i(2i + 22 + £3 + 24)\n\nis a doubly-periodic function of z, such that\n\n  (2) +5r (2 + coj) + (/ (2+ o).,) + <7 (2+ 0)1 + C02)\n\n= - 20- | (20 + 23 - 2i - 24) or \\ (23 + 2i - Zo - 24) (T J (21 + 22 -\n23 - 24) .\n\n\\addexamplecitation{Math. Trip. 1893.}\n\n31. If $f(z)$ be a doubly-periodic function of the third order, with\npoles at 2 = Cj, 2 = 02, 2=C3, and if (2). be a doubly-periodic\nfunction of the second order with the same periods and poles at 2 = 0,\n: = 3, its value in the neighbourhood of 2 = being\n\n( z) = + \\ \\ z-a) + <o z-af - ...,\n\nz - a\n\nprove that\n\niX-' /\" (a) -/\" (3) - \\ /' ( ) +/' m 2</) ( 1) + / (a) -fm sXXi + 2ct>\nc,) cj> (C3)| = 0.\n\n\\addexamplecitation{Math. Trip. 1894.}\n\n32. If X (2) be an elliptic function with two poles aj, a, and if z,\nz-j,, ... 22n be 2n constants subject only to the condition\n\nZl + Z2 + ...+Z. = 7l ai + Cto),\n\nshew that the determinant whose ith row is\n\n1, \\ \\ {Zi), X2(2,.), ... \\ \\ Zi), X,(2,), X(2i)X,(2i), X2 (2,) Xi\n(2,), . .. X -M t) l (2f)\n\n[where Xj (zi) denotes the result of writing 2 for 2 in the derivate\nof X (2)], vanishes identically. \\addexamplecitation{Math. Trip. 1893.}\n\n33. Deduce from example 21 by a limiting process, or otherwise prove,\nthat\n\n\\ F(z) P\" z) ...p-')(2) =(-)\"-Ml! 2!... ( -l)! 2cr(;m)/ a-(?0 ' .\n\np\" z) r'(2) -P' H ) :\n\n\\ 2(01 \"'1/ <\"! ©i\n\nP-1)(2) p)(2)...F\"\"'K2) I\n\n\\addexamplecitation{Kiepert, Journal fur Math, lxxvi.}\n\n34. Shew that, provided certain conditions of inequality are\nsatisfied,\n\n  z)(T y) ' 2coi\n\nwhere the summation applies to all positive integer values of m and n,\nand j = exp (7ria)2/< i)\n\n\\addexamplecitation{Math. Trip. 1895.}\n\n35. Assuming the formula\n\n>)i s? 1 - 2o- cos - + q*\" 2a), 2<x)i . nz ° tO] a-(2) = e ' . - sm\nr- n 7 :r-r,,\n\nprove that\n\n(P (2)= - - + U- cosec2 2 - 2, o cos\n\nwhen 2 satisfies the inequalities\n\n-2li( )<R( )<2R(?A, \\ la>l/ \\ i(Oi/ V(Oi/\n\n\\addexamplecitation{Math. Trip. 1896.}\n\n%\n% 461\n%\n\n36. Shew that if 2 is- be any expression of the form 2ma)i + 2n(02 and\nif\n\nthen X is a root of the sextic\n\n,r - 55'2a;*-405'3A-3 - 5g. x - Sg.2gzX-bg = 0, and obtain all the\nroots of the sextic. \\addexamplecitation{Trinity, 1898.}\n\n37. Shew that\n\nwhere\n\n/ . - )(. -.)ri..=-iiog:-|-;-f; i.og:jj >,\n\n(Dolbnia, Darhoux' Bulletin (2), xix.) 38. Prove that every analytic\nfunction (3) which satisfies the three-term equation\n\n2 /(2 + a)/(2-a)/(6+c)/(6-c) = 0,\n\nfor general values of, 6, c and, is expressible as a finite\ncombination of elementary functions, together with a Sigma-function\n(including a circular function or an algebraic\n\nfunction as degenerate cases).\n\n(Hermite, Fonctions elliptiqnes, i. p. 187.)\n\n[Put 0=a = 6 = c=O, and then/(0) = 0; put 6 = c, and then /( -\n6)+/(6-(x) = 0, so that/ (2) is an odd function.\n\nIf F [z) is the logarithmic derivate of /'(2), the result of\ndifferentiating the relation with respect to 6, and then putting 6 =\nc, is\n\nDifferentiate with respect to 6, and put 6 = 0; then /(. + a)/( -a) /'\n(0)F \\\n\n /( )/(a)F \" -\n\nIf/' (0) \"were zei'o, / ' z) would be a constant and, by integration,/\n(2) would be of the form A exp (Bz+Cz ), and this is an odd function\nonly in the trivial case when it is zero.\n\nIf /' (0) 0, and we write F' (s)= - 4> (z), it is found that the\ncoefficient of a* in the expansion of\n\nl2f z+a)f z-a)/ fiz)Y\n\nis 6 \\$ (z) - \" (j), and the coefficient of a* in 12 /( ) * (a) - *\n(2) is a linear function of * (2). Hence 4>\" (2) is a quadratic\nfunction of \\$(2); and when we multiply this function by \\$' (2) and\nintegrate we find that\n\n <!>' (2) 2 = 4 * (2) 3+ 12J * (2)j-'+ 12 \\$ (2)4-46',\n\nwhere A, B, C are constants. If the cubic on the right has no\nre2:)eated factors, then, by \\hardsectionref{20}{6}, <I> z) = z + a) + A, where a is\nconstant, and on integration\n\nf z) = (r z + a) exp - Az'-Kz-L),\n\nwhere K and L are constants; since/ (2) is an odd function a = K=0,\nand\n\n/(2) = (r(2)exp -iJ22-Z .\n\nIf the cubic has a repeated factor, the Sigma-function is to be\nreplaced (cf.\\hardsubsubsectionref{20}{2}{2}{2}) by the sine of a multiple of z, and if the\ncubic is a perfect cube the Sigma-function is to be replaced by a\nmultiple of 2.]\n", "meta": {"hexsha": "206c7a9bd922ea882e1f38f585942a0906d345dc", "size": 66812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/tex/wandw-ch20.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-ch20.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-ch20.tex", "max_forks_repo_name": "CdLbB/Whittaker-and-Watson", "max_forks_repo_head_hexsha": "5fefdd2c36b4e48cc078a88afc77df289e680a73", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.9856832972, "max_line_length": 124, "alphanum_fraction": 0.6712716279, "num_tokens": 22326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.7795117282711227}}
{"text": "\\subsection{Boundary Points, Open \\& Closed Sets}\r\n\\noindent\r\nGiven some set $\\Omega \\subset \\mathbb{R}^n$, $x$ is an interior point to $\\Omega$ if there exists some $\\delta$ such that $N(x, \\delta) \\subset \\Omega$.\r\nThat is, $x$ is an interior point to $\\Omega$ if you can draw a circle of non-zero radius around $x$ such that the entire circle is inside of $\\Omega$.\r\nAll points that are not interior points are boundary points.\r\nFormally, $x$ is a boundary point of $\\Omega$ if for all $\\delta$,  $N(x,\\delta) \\not\\subset \\Omega$.\r\nUsing our definitions of interior and boundary points, we can define and open set as one that doesn't contain any of its boundary points and a closed set as one that contains all of its boundary point. Note that a set that contains some of its boundary points is neither open nor closed.", "meta": {"hexsha": "cf94f6ed14585b0c29544f521f7be075fc7baf5e", "size": 822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/boundaryPointsOpenClosedSets.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/boundaryPointsOpenClosedSets.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/boundaryPointsOpenClosedSets.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": 117.4285714286, "max_line_length": 287, "alphanum_fraction": 0.7384428224, "num_tokens": 208, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465152482724, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7794472621034167}}
{"text": "\\section{The Limit}\\label{sec:LimitsWorkingDefn}\r\nThe value a function $f$ approaches as its input $x$ approaches some value is said to be the limit of $f$. Limits are essential to the study of calculus and, as we will see, are used in defining continuity, derivatives, and integrals.\r\n\r\nConsider the function\r\n$$f(x)=\\frac{x^2-1}{x-1}.$$\r\n\r\nNotice that $x=1$ does not belong to the domain of $f(x)$.\r\nRegardless, we would like to know how $f(x)$ behaves close to the point $x=1$.\r\nWe start with a table of values:\r\n$$\\begin{array}{ccc}\r\n\\underline{x}&\\qquad&\\underline{f(x)}\\\\\r\n0.5&\\qquad&1.5\\\\\r\n0.9&\\qquad&1.9\\\\\r\n0.99&\\qquad&1.99\\\\\r\n1.01&\\qquad&2.01\\\\\r\n1.1&\\qquad&2.1\\\\\r\n1.5&\\qquad&2.5\\\\\r\n\\end{array}$$\r\n\r\nIt appears that for values of $x$ close to $1$ we have that $f(x)$ is close to $2$.\r\nIn fact, we can make the values of $f(x)$ as close to $2$ as we like by taking $x$ sufficiently close to $1$.\r\nWe express this by saying \\ifont{the limit of the function $f(x)$ as $x$ approaches $1$ is equal to $2$} and use the notation:\r\n$$\\lim_{x\\to 1}f(x)=2.$$\r\n\\begin{definition}{Limit (Useable Definition)}{Limit}\r\nIn general, we will write\r\n$$\\lim_{x\\to a}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ 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\nWe read the expression $\\lim_{x\\to a}f(x)=L$ as ``\\ifont{the limit of $f(x)$ as $x$ approaches $a$ is equal to $L$}\".\r\nWhen evaluating a limit, you are essentially answering the following question: \r\nWhat number does the function \\ifont{approach} while $x$ gets closer and closer to $a$ (but \\ifont{not equal} to $a$)?\r\nThe phrase \\ifont{but not equal to $a$} in the definition of a limit means \r\nthat when finding the limit of $f(x)$ as $x$ approaches $a$ we never actually consider $x=a$.\r\nIn fact, as we just saw in the example above, $a$ may not even belong to the domain of $f$.\r\nAll that matters for limits is what happens to $f$ close to $a$, not necessarily what happens to $f$ at $a$.\r\n\r\n\\subsection*{One-sided limits}\r\nConsider the following piecewise defined function:\r\n%$$f(x)=\r\n%\\left\\{\\begin{array}{ccc}\r\n%x,&\\quad&\\mbox{if $x\\leq 1$,}\\\\\r\n%x+1,&\\quad&\\mbox{if $x>1$,}\\\\\r\n%\\end{array}\\right.$$\r\n%which has the following visual representation:\r\n$$\\includegraphics[width=4.0in]{images/limits-1}$$ Observe from the\r\ngraph that as $x$ gets closer and closer to $1$ from the \\ifont{left},\r\nthen $f(x)$ approaches $+1$.  Similarly, as $x$ gets closer and closer\r\n$1$ from the \\ifont{right}, then $f(x)$ approaches $+2$.  We use the\r\nfollowing notation to indicate this: $$\\lim_{x\\to\r\n1^-}f(x)=1\\qquad\\mbox{and}\\qquad\\lim_{x\\to 1^+}f(x)=2.$$ The symbol\r\n$x\\to 1^-$ means that we only consider values of $x$ sufficiently\r\nclose to $1$ which are less than $1$.  Similarly, the symbol $x\\to\r\n1^+$ means that we only consider values of $x$ sufficiently close to\r\n$1$ which are greater than $1$.\r\n\r\n\\begin{definition}{Left and Right-Hand Limit (Useable Definition)}{LeftRightHandLimit}\r\nIn general, we will write\r\n$$\\lim_{x\\to a^-}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ by taking $x$ to be sufficiently close to $a$ and $x$ less than $a$.\r\nThis is called the \\dfont{left-hand limit} of $f(x)$ as $x$ approaches $a$.\r\nSimilarly, we write\r\n$$\\lim_{x\\to a^+}f(x)=L,$$\r\nif we can make the values of $f(x)$ arbitrarily close to $L$ by taking $x$ to be sufficiently close to $a$ and $x$ greater than $a$.\r\nThis is called the \\dfont{right-hand limit} of $f(x)$ as $x$ approaches $a$.\r\n\\end{definition}\r\n\r\nWe note the following fact:\r\n\\begin{center}\r\n$\\ds{\\lim_{x\\to a}f(x)=L\\qquad\\mbox{if and only if}\\qquad\\lim_{x\\to a^-}f(x)=L\\qquad\\mbox{and}\\qquad\\lim_{x\\to a^+}f(x)=L}.$\r\n\\end{center}\r\nOr more concisely:\r\n\\[\\lim_{x\\to a^-}f(x)=\\lim_{x\\to a^+}f(x)=L\\].\r\nA consequence of this fact is that if the one-sided limits are \\ifont{different}, then the two-sided limit $\\ds{\\lim_{x\\to a}f(x)}$ does not exist, often denoted as: (DNE).\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:LimitsWorkingDefn}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 0}\r\n\\frac{\\sin x}{x}$, where $x$ is in radians.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 0}\r\n\\frac{\\tan(3x)}{\\tan(5x)}$, where $x$ is in radians.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse a calculator to estimate $\\ds\\lim_{x\\to 1^{+}}\\frac{|x-1|}{1-x^2}$ and $\\ds\\lim_{x\\to 1^{-}}\\frac{|x-1|}{1-x^2}$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "809aeb3a8e8dbaca52ee40d5db87b5bf14c8a09a", "size": 4625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-1-limits-working-definition.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": "3-limits/3-1-limits-working-definition.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": "3-limits/3-1-limits-working-definition.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": 46.7171717172, "max_line_length": 235, "alphanum_fraction": 0.6598918919, "num_tokens": 1559, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382058759129, "lm_q2_score": 0.9046505402422645, "lm_q1q2_score": 0.7793910033849959}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Bead on a spinning circular wire}\n\\begin{center}\n\\includegraphics[scale=1]{Lecture-5/W5-img1.png}\n\\end{center}\nA bead of mass $m$ is threaded on a frictionless circular wire hoop of radius $R$. The hoop lies in a vertical plane, which is forced to rotate about the hoop's vertical diameter with constant angular velocity $\\dot{\\phi} = \\omega$. The bead's position on the hoop is specified by the angle $\\theta$.\n\n\\begin{p}\nWrite an expression for the potential energy of the system.\n\\end{p}\n\\begin{s}\nThe height of the bead is determined (via trigonometry) to be $h = 1 - \\cos\\theta$, so the gravitational potential energy is given by:\n\\[U = mgh = mg(1-\\cos\\theta)\\]\n\\end{s}\n\n\\begin{p}\nWrite an expression for the kinetic energy of the system. Thus you can now write out the Lagrangian $\\LL$.\n\\end{p}\n\\begin{s}\n\\[T = \\frac{1}{2}\\frac{m}{v}\\dot{\\v{r}}^2 = \\frac{m}{2}\\left(R\\omega\\sin\\theta + R\\dot{\\theta}\\right)^2 = \\frac{m}{2}\\left(R^2\\omega^2\\sin^2\\theta + R^2\\dot{\\theta}^2\\right) \\]\nWhere the first term is the normal velocity (out of the page in the diagram) and the second term is the tangential velocity (velocity in the frame of the page in the diagram). Hence the Lagrangian is:\n\\[\\LL = T - U = \\frac{m}{2}\\left(R^2\\omega^2\\sin^2\\theta + R^2\\dot{\\theta}^2\\right) +mg(\\cos\\theta-1)\\] \n\\end{s}\n\n\\begin{p}\nFrom the Lagrangian, what is the torque acting on the angle $\\theta$ of the bead? What is the equation of motion for the bead?\n\\end{p}\n\\begin{s}\nTo get the torque, we look at the generalized force for $\\theta$:\n\\[\\dpd{\\LL}{\\theta} = -mgR\\sin\\theta + mR^2\\omega^2\\sin\\theta\\cos\\theta\\]\nBy the EL equation, we obtian the equation of motion for $\\theta$:\n\\[ -mgR\\sin\\theta + mR^2\\omega^2\\sin\\theta\\cos\\theta = \\dod{}{t}\\dpd{\\LL}{\\dot{\\theta}} = mR^2\\ddot{\\theta}\\]\n\\end{s}\n\n\\begin{p}\nSketch your best estimate for where the equilibrium point(s) of the bead are, i.e. sketch the equilibrium value(s) of $\\theta_0$ versus $\\omega$.\n\\end{p}\n\\begin{s}\nThere is an equilibrium point at the bottom of the ring (somewhat intuitively), and when the ring spins fast enough, there are additional equilibrium points symmetrically across the axis:\n\\begin{center}\n    \\includegraphics[scale=0.4]{Lecture-5/W5-img2.png}\n\\end{center}\nThe derivation of this graph and other equilibrium points mathematically is given in the next problem. We can see that as $\\omega \\rightarrow \\infty$ that the bead will be perfectly horizontal (which lines up with our intuition somewhat).\n\\end{s}\n\n\\begin{p}\nConvince yourself that an equilibrium point has $\\dot{\\theta} = \\ddot{\\theta} = 0$. Find all equilibrium points of the bead. Where is the equilibrium point when $0 < \\omega^2 < g/R$?\n\\end{p}\n\\begin{s}\nIf we want equilibrium, we require the condition of $\\ddot{\\theta} = 0$ (as the bead should not feel any net torque and start with no angular velocity if it is to remain at rest), which results in \\[\\left(\\omega^2\\cos\\theta_0 - \\frac{g}{R}\\right)\\sin\\theta_0 = 0\\]\nThis has solutions of $\\theta_0 = 0$ or $\\theta_0 = \\pi$ (the sine term is zero) or $\\cos\\theta_0 = \\frac{g}{\\omega^2R}$ or $\\theta_0 = \\pm \\arccos(\\frac{g}{\\omega^2R})$. Since $\\cos$ only varies between $1$ and $-1$ this arccos solution only has a solution for $\\omega^2 \\geq \\frac{g}{R}$.\n\\end{s}\n\n\\begin{p}\nShow that at the equilibrium points defined by $\\omega^2\\cos\\theta - g/R = 0$, the tangential components of the gravitational and centrifugal forces (in the non-inertial frame of the hoop) cancel. Show that for any points with $\\theta > \\pi/2$ including near the top, the above two forces are in the same direction.\n\\end{p}\n\\begin{s}\nConsider the balance of forces at these equilibrium points. There is the centrifugal force that throws the particle outwards, and the gravitational force that pulls the particle downwards. The centrifugal force is given by $\\abs{\\v{F}_{cent}} = m\\omega^2r = m\\omega^2R\\sin\\theta$ that throws the particle outwards and the gravitational force $\\abs{\\v{F}_g}= -mg$ downwards. We decompose these forces into the radial and tangential components.\n\\begin{center}\n    \\includegraphics[scale=0.4]{Lecture-5/W5-img3.png}\n\\end{center}\nFor the angle to remain constant, we require that the tangential components (pictured in red above) must cancel. This is given by:\n\\[F_{tan} = -mg\\sin\\theta + m\\omega^2R\\sin\\theta\\cos\\theta = \\sin\\theta\\left(\\omega^2 R\\cos\\theta - g\\sin\\theta\\right)\\]\nWhich we see is $0$ whenever $\\omega^2\\cos\\theta - g/R = 0$ and hence we get the same answer in two different ways. \nIf $\\theta > \\frac{\\pi}{2}$, then we have that $\\sin\\theta > 0$ and $\\cos\\theta < 0$ and hence we can see from the above expression of the tangential force above that the gravitational tangent force and the centrifugal force point in the same direction; there is no hope of having an equilibrium point on the upper half of the metal loop!\n\\end{s}\n\n\\begin{p}\nShow that the equilibrium point at $\\theta_0 = 0$ is stable, so long as $\\omega < \\sqrt{g/R}$. What is the oscillation frequency about the equilibrium point?\n\\end{p}\n\\begin{s}\nWhen $\\theta$ is small, we can do a small angle approximation and so $\\cos\\theta \\sim 1$ and $\\sin\\theta \\sim \\theta$. Going back to our equation of motion, we see that:\n\\[mR\\ddot{\\theta} = -mgR\\theta + mR^2\\omega^2\\theta\\]\nand therefore:\n\\[\\ddot{\\theta} = \\left(\\omega^2 - \\frac{g}{R}\\right)\\theta\\]\nWhich is a nice equation we can solve analytically. We see that the RHS is negative when $\\omega < \\sqrt{\\frac{g}{R}}$ and positive when $\\omega > \\sqrt{\\frac{g}{R}}$. In the first case, the solutions to the differential equations are sines/cosines; i.e. simple harmonic oscillation with frequency $\\Omega = \\sqrt{\\frac{g}{R} - \\omega^2}$:\n\\[\\ddot{\\theta} = -\\Omega^2\\theta\\]\n\\[\\theta(t) = A\\cos(\\Omega t) + B\\sin(\\Omega t)\\]\nWhich is a stable equilibrium; it oscillates about the $\\theta = 0$ point when perturbed from it.\n\\end{s}\n\n\\begin{p}\nFind the oscillation frequencies about the equilibrium points $\\theta_0$ when $\\omega > \\sqrt{g/R}$. What is the stability condition for these oscillations? What is the oscillation frequency? Now sketch the equilibrium values of $\\theta_0$, as a function of $\\omega$, over the full range $\\omega > 0$.\n\\end{p}\n\\begin{s}\nConversely, when $\\omega > \\sqrt{g/R}$, consider a small perturbation $\\theta_0 + \\e$ from the equilibrium. For a small $\\e$, we have:\n\\[\\cos(\\theta_0 + \\e) \\approx \\cos\\theta_0 - \\e\\sin\\theta_0\\]\n\\[\\sin(\\theta_0 +\\e) \\approx \\sin\\theta_0 +\\e\\sin\\theta_0\\]\nThe equation of motion then becomes:\n\\[\\ddot{\\theta} = \\left[\\omega^2\\cos(\\theta_0 + \\e) - \\frac{g}{R}\\right]\\sin(\\theta_0 + \\e)\\]\n\\[\\ddot{\\theta} \\approx \\left[\\omega^2\\cos\\theta_0 - \\e\\omega^2\\sin\\theta_0 - \\frac{g}{R}\\right]\\left[\\sin\\theta_0 + \\e\\cos\\theta_0\\right]\\]\nNow the $\\omega^2\\cos\\theta_0$ and $-g/R$ terms cancel, and neglecting terms in $\\e^2$, we have:\n\\[\\ddot{\\theta} = \\ddot{\\e} = -\\e\\omega^2\\sin^2\\theta_0 = -\\Omega'\\e\\]\nSo we can see that if we perturb around $\\theta_0$ that we have oscillation around $\\theta_0$ which corresponds to a stable equilibrium. \n\\end{s}\nIn conclusion, we see that this is quite a rich problem with respect to different equilibrium points and their behavior. There is also a discontinuous jump between certain equilibria $\\omega = \\sqrt{g/R}$, which is known as \\textbf{bifurcation}, which can lead to chaotic motion.\n\\end{document}", "meta": {"hexsha": "8ef17f158d1e3578814c1c558c3b7599a3e1e300", "size": 7415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-5/Worksheet-5.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-5/Worksheet-5.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-5/Worksheet-5.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": 74.898989899, "max_line_length": 442, "alphanum_fraction": 0.7165205664, "num_tokens": 2273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681122619883, "lm_q2_score": 0.9086179031191509, "lm_q1q2_score": 0.7793834635259603}}
{"text": "\\section{Definitions, Families of Curves}\n\n\\subsection{Definitions}\n\n\\begin{definition}[Order]\n    Order of a DE is the highest-ordered derivative appearing in it.\n    So\n    \\begin{equation}\n        \\frac{d^2y}{dx^2}+2b(\\frac{dy}{dx})^3+y=0\n    \\end{equation}\n    is a 2nd order DE. In general,\n    \\begin{equation}\n        F(x,y,y',y'',\\ldots,y^{(n)})=0.\n    \\end{equation}\n    is an $n$-th order DE.\n    Under restrictions on $F$, can find a solution in terms of the other $n+1$ variables\n    \\begin{equation}\n        y^{(n)}=f(x,y,y',\\ldots,y^{(n-1)}).\\label{DESoln}\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Solution]\n    A function $\\phi$ on interval $x\\in (a,b)$ is a solution to the DE (\\ref{DESoln})\n    if the $n$ derivatives exist on $x\\in(a,b)$ and $\\phi^{(n)}(x)=f(x,\\phi(x),\\ldots,\\phi^{(n-1)}(x))$.\n\\end{definition}\n\n\\begin{definition}[First order DE]\n    A first order DE is of the form\n    \\begin{equation}\n        \\frac{dy}{dx}=f(x,y)\n    \\end{equation}\n    with solution of the form $y=f(x)$.\n    Can be rewritten for convenience in the form\n    \\begin{equation}\n        M(x,y)dx+N(x,y)dy=0\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Linear ODE]\n    An ODE of order $n$ is linear if it can be written in the form\n    \\begin{equation}\n        b_0(x)\\frac{d^ny}{dx^n}+b_1(x)\\frac{d^{n-1}y}{dx^{n-1}}+\\cdots+b_{n-1}(x)\\frac{dy}{dx}+b_{n}(x)y=R(x)\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Partial DE]\n    Is of the form, for example\n    \\begin{equation}\n        b_0(x,y)\\frac{\\pr w}{\\pr x}+b_x(x,y)\\frac{\\pr w}{\\pr y}=R(x,y)\n    \\end{equation}\n\\end{definition}\n\n\\subsection{Families of Solutions}\n\nSolutions to the DE\n\\begin{equation}\n    \\frac{dy}{dx}=f(x,y)\\Leftrightarrow y=\\int f(x)dx+c\n\\end{equation}\n\nexist as one-parameter families with parameter $c$.\n\n\\subsection{Isoclines}\n\nLet there be the DE\n\n\\begin{equation}\n    \\frac{dy}{dx}=y\n\\end{equation}\n\nIsoclines are lines $f(x,y)=y=c$. Example:\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[scale=0.75]{figures/Screen Shot 2021-09-27 at 3.25.57 PM.png}\n    \\caption{Isoclines of $\\frac{dy}{dx}=y$}\n\\end{figure}\n\n\\subsection{Existence Theorem}\n\nConsider equation\n\n\\begin{equation}\n    \\frac{dy}{dx}=f(x,y)\n\\end{equation}\n\nFurther, let $T$ denote the rectangle defined by\n\\begin{eqnarray}\n    |x-x_0|\\leq a\\\\\n    |y-y_0|\\leq b\n\\end{eqnarray}\nwith the point $(x_0,y_0)$ as the center.\nAlso let $f,\\frac{\\pr f}{\\pr y}$ be continuous functions of $x,y$ in $T$.\n\nWith these conditions an interval exists for $x_0$ where $|x-x_0|\\leq h$, and function $y(x)$\nwhich has properties\n\\begin{enumerate}\n    \\item $y=y(x)$ is a sol'n of the DE on interval $|x-x_0|\\leq h$\n    \\item On this interval, $|y(x)-y_0|\\leq b$\n    \\item $y=y(x_0)=y_0$ at $x=x_0$\n    \\item $y(x)$ is unique on interval $|x-x_0|\\leq h$ where it is the only function with above 3 properties\n\\end{enumerate}", "meta": {"hexsha": "3182a009152181a5e794461eea97c08aefc7d6ba", "size": 2887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "differential-equations/tex/unit-1.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "differential-equations/tex/unit-1.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "differential-equations/tex/unit-1.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.5841584158, "max_line_length": 109, "alphanum_fraction": 0.640457222, "num_tokens": 1035, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094032139576, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.7792761185983236}}
{"text": "\\section{The Complex Numbers}\r\nSome polynomials have no solution in $\\mathbb R$, e.g. $x^2+1=0$.\r\nSo we want so enlarge the reals to seek a solution.\r\n\\begin{definition}\r\n    The complex numbers, written as $\\mathbb C$, consists of $\\mathbb R^2$ (ordered pairs of real numbers) with operations $+,\\cdot$ defined by\r\n    $$(a,b)+(c,d)=(a+c,b+d)$$\r\n    $$(a,b)\\cdot(c,d)=(ac-bd,ad+bc)$$\r\n\\end{definition}\r\nThe collection $\\{(a,0):a\\in\\mathbb R\\}$ can be identified as the reals.\r\nOne can verify straight away that the sum and product reduced to the case that we are familiar with.\r\nWe can write $i=(0,1)$, and we have $i^2=)=(-1,0)$, also every complex numbers are in the form $a+bi$ for $a,bin\\mathbb R$.\r\nIndeed, $(a,b)=(a,0)+(b,0)\\cdot (0,1)=a+bi$.\r\n\\begin{remark}\r\n    We can check that the complex numbers satisfy the usual laws of arithmetic.\r\n    In particular, for each $z=a+bi\\neq 0$, we know that $zw=1$ where $w=\\bar z/(z\\bar z)$ where $\\bar z=a-bi$.\r\n    The complex number $\\bar z$ is called the conjugate of $z$.\r\n    Such a structure is called a field.\r\n\\end{remark}\r\nExamples of fields includes $\\mathbb C,\\mathbb R,\\mathbb Q,\\mathbb Z_p$ where $p$ is prime.\r\nBut $\\mathbb Z$ is not due to the lack of multiplicative inverses.\r\n\\begin{theorem}[Fundamental Theorem of Algebra]\r\n    Every nonconstant polynomial with complex coefficient has a root in $\\mathbb C$.\r\n\\end{theorem}\r\nWe will obviously not prove it here.", "meta": {"hexsha": "a4580de1f1957f3b8d98672807f05b8efd504f89", "size": 1428, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/complex.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": "5/complex.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": "5/complex.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": 59.5, "max_line_length": 144, "alphanum_fraction": 0.6820728291, "num_tokens": 437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.779140886906814}}
{"text": "\n\\subsection{Incompleteness of the rational numbers}\n\n\\subsubsection{The square root of \\(2\\) is not a rational number}\n\nLet's prove there are numbers which are not rational. Consider \\(\\sqrt 2\\) and let's show that it being rational leads to a contradiction.\n\n\\(\\sqrt 2=\\dfrac{x}{y}\\)\n\n\\(2=\\dfrac{x^2}{y^2}\\)\n\n\\(2y^2=x^2\\)\n\nSo we know that \\(x^2\\) is even, and can be shown as \\(x=2n\\).\n\n\\(2y^2=(2n)^2\\)\n\n\\(y^2=2n^2\\)\n\nSo \\(y\\) is even. But if both \\(x\\) and \\(y\\) are even, then the fraction was not reduced.\n\nThis presents a contraction so the original statement must have been false.\n\nSo we know there isn't a rational solution to \\(\\sqrt 2\\).\n\n", "meta": {"hexsha": "0d400002cc14763fac6181ff418be0f7c3aa18b2", "size": 649, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/reals/01-02-realReals.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/reals/01-02-realReals.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/reals/01-02-realReals.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.9615384615, "max_line_length": 138, "alphanum_fraction": 0.6748844376, "num_tokens": 202, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147439, "lm_q2_score": 0.8539127603871312, "lm_q1q2_score": 0.7791408764033992}}
{"text": "\\section{Method}\n\n\\begin{wrapfigure}{r}{0.33\\linewidth}\n  \\centering\n  \\tikz \\graph { 1 -- { 2,3 } -- 4 };\n  \\caption{The diagram of graph \\(G=\\p{V, E}\\) where \\(G=\\Set{1,2,3,4}\\) and \\(E=\\Set{\\p{1,2},\\p{1,3}, \\p{2,4}, \\p{3,4}}\\)\\label{fig:generic_graph}}\n\\end{wrapfigure}\n\nThe main mathematical object used in this project is a graph state, so we provide a detailed definition. We start with the definition of a \\emph{graph}. A graph \\(G=\\p{V, E}\\) is the pair of a finite set \\(V = \\Set{1, 2, \\dots, N}\\) and a set \\(E \\subset V\\times V\\) \\cite{clrs}. The set \\(V\\) is composed of elements that are called the \\emph{vertices} of the graph. The elements of the set of paired vertices\\(E\\) are called the \\emph{edges} of the graph. Graphs are usually represented visually using diagrams. One such example is given in Figure \\ref{fig:generic_graph}. \n\nAfter establishing the definition of a graph, we define what a \\emph{graph state} is. Let the unitary operator \\(U_{ab}\\) be a controlled \\(\\sigma_z\\) operation applied between qubits \\(a\\) and \\(b\\).\n\\begin{equation}\n  U_{ab} = \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{equation}\nThe effect of \\(U_{ab}\\) applied on a qubit can be described as the following equation.\n\\begin{equation}\n  U_{ab}\\ket{+^{\\spaceScript{a}}}\\ket{+^{\\spaceScript{b}}} = \\frac{1}{\\sqrt{2}}\\p{\\ket{0^{\\spaceScript{a}}}\\ket{+^{\\spaceScript{b}}} + \\ket{1^{\\spaceScript{a}}}\\ket{-^{\\spaceScript{b}}}}\n\\end{equation}\nSo \\(U_{ab}\\) creates a maximally entangled Bell pair\\cite{hein2006}. We use this constuct to create edges in a graph state. Let \\(G=\\p{G, E}\\) be a graph. The graph state \\(\\ket{G}\\) which corresponds to the graph \\(G\\) is the pure state with following wave function, where \\(\\ket+^V\\) is the product state of \\(\\ket+\\) for all vertices in the graph.\n\\begin{equation}\n  \\ket{G} = \\prod_{\\p{a, b}\\in E} U_{ab} \\: \\ket{+}^V\n\\end{equation} \nSo the preparation procedure for a graph state reads:\n\\begin{enumerate}\n  \\item Set the qubits at each vertex to \\(\\ket+\\), the positive eigenstate of \\(\\sigma_z\\).\n  \\item Apply \\(U_{ab}\\)\\/ to each adjacent vertex in the graph.\n\\end{enumerate} \nAn example graph state and its diagrammatic representation is given in Figure \\ref{fig:graph_state}.\n\n\\begin{figure}[tb]\n  \\centering\n  \\begin{subfigure}[b]{0.4\\linewidth}\n    \\begin{align*}\n      \\ket{G} \n        &= U_{23}U_{12}\\ket{+}^{\\otimes 3} \\\\\n        & =\\begin{aligned}[t]\n          &\\frac{1}{2} \\ket{0^{\\spaceScript{1}}} \\ket{0^{\\spaceScript{2}}} \\ket{+^{\\spaceScript{3}}} \\\\\n          &+ \\frac{1}{2} \\ket{0^{\\spaceScript{1}}} \\ket{1^{\\spaceScript{2}}} \\ket{-^{\\spaceScript{3}}} \\\\\n          &+ \\frac{1}{2} \\ket{1^{\\spaceScript{1}}} \\ket{0^{\\spaceScript{2}}} \\ket{+^{\\spaceScript{3}}}\\\\\n          &- \\frac{1}{2} \\ket{1^{\\spaceScript{1}}} \\ket{1^{\\spaceScript{2}}} \\ket{-^{\\spaceScript{3}}}\n        \\end{aligned}\n    \\end{align*}\n    \\caption{Wave Funciton Representation\\label{fig:graph_state:wfn}}\n  \\end{subfigure}\n  \\hspace{5pt}\n  \\begin{subfigure}[b]{0.4\\linewidth}\n    \\centering\n    \\input{fig/graph_simple}\n    \\caption{Diagrammatic Representation}\n  \\end{subfigure}\n  \\caption{Two different representations of the same graph state for the graph \\(G=\\p{\\Set{1,2,3},\\Set{(1,2),(2,3)}}\\) \\label{fig:graph_state}}\n\\end{figure}\n\nThe wave function representation of a graph state is not always the best for succinctly representing a graph. Figure \\ref{fig:graph_state:wfn} shows this clearly. It also hides the entanglement patterns present in the graph state. To solve this issue, \\emph{stabilizer} of this graph state is used to represent it textually. A stabilizer \\(\\symcal{S}\\) is defined as a commutative subgroup of the Pauli group \\(\\symcal{P}^V\\) that does not contain \\(-\\symbb{1}_V\\) or \\(\\pm i\\symbb{1}_V\\). Any graph state \\(\\ket{G}\\) for a given graph \\(G = \\p{G, E}\\) satisfies the set of eigenvalue equations \n\\begin{equation}\n  K_a\\ket{G} = +1 \\ket{G}\n\\end{equation}\nwhere\n\\begin{equation}\n  K_a \\coloneq  \\sigma_x^a \\prod_{b\\in N_a} \\sigma_z^b.\n\\end{equation} The symbol \\(N_a\\) denotes the set of adjacent vertices of the vertex \\(a\\), called its \\emph{neighbourhood}. The commutative subgroup of \\(\\symcal{P}^V\\) generated by the set of operators \n\\begin{equation}\n  \\symcal{S} = \\Set*{\\;K_a \\in \\symcal{P}^V \\given a \\in V \\; }\n\\end{equation}\nis called the stabilizer of the graph state. Graph states are uniquely represented by their stabilizers. Note that graph state stabilizers expose the correlation patterns as they impose the following set of constraints to the measurement outcomes of their generators.\n\\begin{equation}\n  \\forall a\\in V \\; : \\; m_x^a \\prod_{b\\in N_a} m_z^b = +1 \n\\end{equation} \n\nNow that we have provided a detailed account of what graph states are, we introduce a \\emph{cluster state}. A cluster \\(C\\) is a \\(d\\)-dimensional array of qubits where each qubit is entangled with its neighbours. A simple graph can represent any cluster, so a cluster's quantum state \\(\\ket{C}\\) is a graph state. This cluster construct will be used as a universal medium for quantum computation by applying measurements to its particles in a particular order and on a certain basis\\cite{russendorf2001}.\n\nThis way of computation is called measurement-based quantum computing. This project will investigate how to construct algorithms using this formalism and the existing implementations of quantum algorithms for measurement-based quantum computers.", "meta": {"hexsha": "5b3989c7d22001fc6190f5f84f9cfa4d5a6040e1", "size": 5501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/proposal/content/method.tex", "max_stars_repo_name": "kurabirko/phys400", "max_stars_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "documents/proposal/content/method.tex", "max_issues_repo_name": "kurabirko/phys400", "max_issues_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documents/proposal/content/method.tex", "max_forks_repo_name": "kurabirko/phys400", "max_forks_repo_head_hexsha": "1e7608322457c090e4db8c52ff1c7c8c55a612c3", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.5256410256, "max_line_length": 595, "alphanum_fraction": 0.6866024359, "num_tokens": 1755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.8539127455162773, "lm_q1q2_score": 0.779140864867945}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the following augmented matrix in which $\\ast$ denotes an\n  arbitrary number and $\\blacksquare$ denotes a non-zero number. Determine\n  whether the given augmented matrix is consistent. If consistent, is the\n  solution unique?\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc|c}\n      \\blacksquare & \\ast & \\ast & \\ast & \\ast & \\ast \\\\\n      0 & \\blacksquare & \\ast & \\ast & 0 & \\ast \\\\\n      0 & 0 & \\blacksquare & \\ast & \\ast & \\ast \\\\\n      0 & 0 & 0 & 0 & \\blacksquare & \\ast\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    The solution exists but is not unique.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following augmented matrix in which $\\ast$ denotes an arbitrary\n  number and $\\blacksquare$ denotes a non-zero number. Determine whether the\n  given augmented matrix is consistent. If consistent, is the solution unique?\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc|c}\n      \\blacksquare & \\ast & \\ast & \\ast \\\\\n      0 & \\blacksquare & \\ast & \\ast \\\\\n      0 & 0 & \\blacksquare & \\ast\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    A solution exists and is unique.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following augmented matrix in which $\\ast$ denotes an arbitrary\n  number and $\\blacksquare$ denotes a non-zero number. Determine whether the\n  given augmented matrix is consistent. If consistent, is the solution unique?\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc|c}\n      \\blacksquare & \\ast & \\ast & \\ast & \\ast & \\ast \\\\\n      0 & \\blacksquare & 0 & \\ast & 0 & \\ast \\\\\n      0 & 0 & 0 & \\blacksquare & \\ast & \\ast \\\\\n      0 & 0 & 0 & 0 & \\blacksquare & \\ast\n    \\end{mymatrix}\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following augmented matrix in which $\\ast$ denotes an arbitrary\n  number and $\\blacksquare$ denotes a non-zero number. Determine whether the\n  given augmented matrix is consistent. If consistent, is the solution unique?\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc|c}\n      \\blacksquare & \\ast & \\ast & \\ast & \\ast & \\ast \\\\\n      0 & \\blacksquare & \\ast & \\ast & 0 & \\ast \\\\\n      0 & 0 & 0 & 0 & \\blacksquare & 0 \\\\\n      0 & 0 & 0 & 0 & \\ast & \\blacksquare\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    There might be a solution. If so, there are infinitely many.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose a system of equations has fewer equations than\n  variables. Will such a system necessarily be consistent? If so,\n  explain why and if not, give an example which is not consistent.\n  \\begin{sol}\n    No. Consider $x+y+z=2$ and $x+y+z=1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  If a system of equations has more equations than variables, can it\n  have a solution? If so, give an example and if not, explain why not.\n  \\begin{sol}\n    These can have a solution. For example, $x+y=1$, $2x+2y=2$,\n    $3x+3y=3$ even has an infinite set of solutions.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find $h$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      2 & h & 4 \\\\\n      3 & 6 & 7\n    \\end{mymatrix}\n  \\end{equation*}\n  is the augmented matrix of an \\textit{inconsistent} system.\n  \\begin{sol}\n    $h=4$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find $h$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & h & 3 \\\\\n      2 & 4 & 6\n    \\end{mymatrix}\n  \\end{equation*}\n  is the augmented matrix of a \\textit{consistent} system.\n  \\begin{sol}\n    Any $h$ will work.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find $h$ such that\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & 1 & 4 \\\\\n      3 & h & 12\n    \\end{mymatrix}\n  \\end{equation*}\n  is the augmented matrix of a \\textit{consistent} system.\n  \\begin{sol}\n    Any $h$ will work.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Choose $h$ and $k$ such that the augmented matrix shown has each of the following:\n  \\begin{enumerate}\n  \\item one solution\n  \\item no solution\n  \\item infinitely many solutions\n  \\end{enumerate}\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & h & 2 \\\\\n      2 & 4 & k\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    If $h\\neq 2$ there will be a unique solution for any $k$. If $h=2$ and\n    $k\\neq 4$, there are no solutions. If $h=2$ and $k=4$, then there are\n    infinitely many solutions.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Choose $h$ and $k$ such that the augmented matrix shown has each of the following:\n  \\begin{enumerate}\n  \\item one solution\n  \\item no solution\n  \\item infinitely many solutions\n  \\end{enumerate}\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      1 & 2 & 2 \\\\\n      2 & h & k\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    If $h\\neq 4$, then there is exactly one solution. If $h=4$ and $k\\neq 4$,\n    then there are no solutions. If $h=4$ and $k=4$, then there are infinitely\n    many solutions.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine if the system is consistent. If so, is the solution unique?\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+2y+z-w=2 \\\\\n      x-y+z+w=1 \\\\\n      2x+y-z=1 \\\\\n      4x+2y+z=5\n    \\end{array}\n  \\end{equation*}\n  \\begin{sol}\n    There is no solution. The system is inconsistent. You can see this from the\n    augmented matrix. $\\begin{mymatrix}{rrrr|r}\n      1 & 2 & 1 & -1 & 2 \\\\\n      1 & -1 & 1 & 1 & 1 \\\\\n      2 & 1 & -1 & 0 & 1 \\\\\n      4 & 2 & 1 & 0 & 5\n    \\end{mymatrix}$, {\\ef}: $\\begin{mymatrix}{rrrr|r}\n      1 & 2 & 1 & -1 & 2 \\\\\n      0 & -3 & 0 & 2 & -1 \\\\\n      0 & 0 & -3 & 0 & -2 \\\\\n      0 & 0 & 0 & 0 & 1\n    \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine if the system is consistent. If so, is the solution unique?\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+2y+z-w=2 \\\\\n      x-y+z+w=0 \\\\\n      2x+y-z=1 \\\\\n      4x+2y+z=3\n    \\end{array}\n  \\end{equation*}\n  \\begin{sol}\n    Solution is: $w=\\frac{3}{2}y-1$, $x=\\frac{2}{3}-\\frac{1}{2}y$,\n    $z=\\frac{1}{3}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine which matrices are in {\\ef}.\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrrr}\n      1 & 1 & 2 & 0 \\\\\n      0 & 0 & 3 & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 0 \\\\\n      2 & 1 & 7\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrrrrr}\n      0 & 1 & 0 & 0 & 5 \\\\\n      0 & 0 & 1 & 0 & 4 \\\\\n      0 & 0 & 0 & 1 & 3\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    (a) Yes. (b) No. (c) Yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:rr-ef}\n  Row reduce each of the following matrices to {\\ef}.\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrrr}\n      2 & -1 & 3 & -1 \\\\\n      1 & 0 & 2 & 1 \\\\\n      1 & -1 & 1 & -2\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrrr}\n      0 & 0 & -1 & -1 \\\\\n      1 & 1 & 1 & 0 \\\\\n      1 & 1 & 0 & -1\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrrr}\n      3 & -6 & -7 & -8 \\\\\n      1 & -2 & -2 & -2 \\\\\n      1 & -2 & -3 & -4\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    (d)~\n    \\begin{mymatrix}{rrrr}\n      2 & 4 & 5 & 15 \\\\\n      1 & 2 & 3 & 9 \\\\\n      1 & 2 & 2 & 6\n    \\end{mymatrix}\n    \\quad\n    (e)~\n    \\begin{mymatrix}{rrrr}\n      4 & -1 & 7 & 10 \\\\\n      1 & 0 & 3 & 3 \\\\\n      1 & -1 & -2 & 1\n    \\end{mymatrix}\n    \\quad\n    (f)~\n    \\begin{mymatrix}{rrrr}\n      3 & 5 & -4 & 2 \\\\\n      1 & 2 & -1 & 1 \\\\\n      1 & 1 & -2 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    (g)~\n    \\begin{mymatrix}{rrrr}\n      -2 & 3 & -8 & 7 \\\\\n      1 & -2 & 5 & -5 \\\\\n      1 & -3 & 7 & -8\n    \\end{mymatrix}\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the general solution of the system whose augmented matrix is\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & 0 & 2 \\\\\n      1 & 3 & 4 & 2 \\\\\n      1 & 0 & 2 & 1\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & 0 & 2 \\\\\n      2 & 0 & 1 & 1 \\\\\n      3 & 2 & 1 & 3\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrr|r}\n      1 & 1 & 0 & 1 \\\\\n      1 & 0 & 4 & 2\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    (d)~\n    \\begin{mymatrix}{rrrrr|r}\n      1 & 0 & 2 & 1 & 1 & 2 \\\\\n      0 & 1 & 0 & 1 & 2 & 1 \\\\\n      1 & 2 & 0 & 0 & 1 & 3 \\\\\n      1 & 0 & 1 & 0 & 2 & 2\n    \\end{mymatrix}\n    \\quad\n    (e)~\n    \\begin{mymatrix}{rrrrr|r}\n      1 & 0 & 2 & 1 & 1 & 2 \\\\\n      0 & 1 & 0 & 1 & 2 & 1 \\\\\n      0 & 2 & 0 & 0 & 1 & 3 \\\\\n      1 & -1 & 2 & 2 & 2 & 0\n    \\end{mymatrix}\n  \\end{equation*}\n\n  \\begin{sol}\n    (b) The {\\ef} is\n    $\\def\\arraystretch{1.3}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & \\frac{1}{2} & \\frac{1}{2} \\\\\n      0 & 1 & -\\frac{1}{4} & \\frac{3}{4} \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}$. Therefore, the solution is of the form $z=t$,\n    $y=\\frac{3}{4}+t\\paren{\\frac{1}{4}}$, $x=\\frac{1}{2}-\\frac{1}{2}t$,\n    where $t\\in \\R$.\n\n    (c) The {\\ef} is $\\begin{mymatrix}{rrr|r}\n      1 & 0 & 4 & 2 \\\\\n      0 & 1 & -4 & -1\n    \\end{mymatrix}$ and so the solution is $z=t$, $y=-1+4t$, $x=2-4t$.\n\n    (d) The {\\ef} is $\\begin{mymatrix}{rrrrr|r}\n      1 & 0 & 0 & 0 & 9 & 3 \\\\\n      0 & 1 & 0 & 0 & -4 & 0 \\\\\n      0 & 0 & 1 & 0 & -7 & -1 \\\\\n      0 & 0 & 0 & 1 & 6 & 1\n    \\end{mymatrix}$ and so $x_5=t$, $x_4=1-6t$, $x_3=-1+7t$,\n    $x_2=4t$, $x_1=3-9t$.\n\n    (e) The {\\ef} is\n    $\\def\\arraystretch{1.3}\n    \\begin{mymatrix}{rrrrr|r}\n      1 & 0 & 2 & 0 & -\\frac{1}{2} & \\frac{5}{2} \\\\\n      0 & 1 & 0 & 0 & \\frac{1}{2} & \\frac{3}{2} \\\\\n      0 & 0 & 0 & 1 & \\frac{3}{2} & -\\frac{1}{2} \\\\\n      0 & 0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}$. Therefore, let $x_5=t$, $x_3=s$. Then the other\n    variables are given by $x_4=-\\frac{1}{2}-\\frac{3}{2}t$,\n    $x_2=\\frac{3}{2}-t\\frac{1}{2}$, $x_1=\\frac{5}{2}+\\frac{1}{2}t-2s$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the system of equations $7x+14y+15z=22$, $2x+4y+3z=5$, and $3x+6y+10z=13$.\n  \\begin{sol}\n    Solution is: $\\mat{x=1-2t,z=1,y=t}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the system of equations $3x-y+4z=6$,\n  $y+8z=0$, and $-2x+y=-4$.\n  \\begin{sol}\n    Solution is: $\\mat{x=2-4t,y=-8t,z=t}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the system of equations $9x-2y+4z=-17$, $13x-3y+6z=-25$, and\n  $-2x-z=3$.\n  \\begin{sol}\n    Solution is: $\\mat{x=-1,y=2,z=-1}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the system of equations\n  $65x+84y+16z=546$, $81x+105y+20z=682$, and $84x+110y+21z=713$.\n  \\begin{sol}\n    Solution is:\n    $\\mat{x=2,y=4,z=5}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the system of equations\n  $8x+2y+3z=-3$, $8x+3y+3z=-1$, and $4x+y+3z=-9$.\n  \\begin{sol}\n    Solution is: $\\mat{x=1,y=2,z=-5}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose a system of equations has fewer equations than variables and\n  you have found a solution to this system of equations. Is it possible that\n  your solution is the only one?\\ Explain.\n  \\begin{sol}\n    No. Consider $x+y+z=2$ and $x+y+z=1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose a system of linear equations has an augmented\n  matrix with 2 rows and 4 columns and the last column is a pivot\n  column. Could the system of linear equations be consistent? Explain.\n  \\begin{sol}\n    No. This would lead to $0=1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose the coefficient matrix of a system of $n$ equations with $n$\n  variables has the property that every column is a pivot column. Does it\n  follow that the system of equations must have a solution? If so, must the\n  solution be unique? Explain.\n  \\begin{sol}\n    Yes. It has a unique solution.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose there is a unique solution to a system of linear equations.\n  What must be true of the pivot columns in the augmented matrix?\n  \\begin{sol}\n    The last column must not be a pivot column. The remaining columns must each be pivot\n    columns.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  The steady state temperature, $u$, of a plate solves Laplace's\n  equation, $\\Delta u=0$. One way to approximate the solution is to\n  divide the plate into a square mesh and require the temperature at\n  each node to equal the average of the temperature at the four\n  adjacent nodes. In the following picture, the numbers represent the\n  observed temperature at the indicated nodes. Find the temperature at\n  the interior nodes, indicated by $x$, $y$, $z$, and $w$. One of the\n  equations is $z=\\frac{1}{4}(10+0+w+x)$.\n\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.8]\n      \\draw (1,0) -- (1,3);\n      \\draw (2,0) -- (2,3);\n      \\draw (0,1) -- (3,1);\n      \\draw (0,2) -- (3,2);\n      \\fill (0,1) circle (3pt) node[left]{$10$};\n      \\fill (0,2) circle (3pt) node[left]{$10$};\n      \\fill (1,0) circle (3pt) node[below]{$0$};\n      \\fill (1,1) circle (3pt) node[above right]{$z$};\n      \\fill (1,2) circle (3pt) node[above right]{$x$};\n      \\fill (1,3) circle (3pt) node[above]{$20$};\n      \\fill (2,0) circle (3pt) node[below]{$0$};\n      \\fill (2,1) circle (3pt) node[above right]{$w$};\n      \\fill (2,2) circle (3pt) node[above right]{$y$};\n      \\fill (2,3) circle (3pt) node[above]{$20$};\n      \\fill (3,1) circle (3pt) node[right]{$30$};\n      \\fill (3,2) circle (3pt) node[right]{$30$};\n    \\end{tikzpicture}\n  \\end{center}\n  \\begin{sol}\n    You need $\\def\\arraystretch{1.2}\n    \\begin{array}{r}\n      \\frac{1}{4}(20+30+w+x) -y=0 \\\\\n      \\frac{1}{4}(y+30+0+z) -w=0 \\\\\n      \\frac{1}{4}(20+y+z+10) -x=0 \\\\\n      \\frac{1}{4}(x+w+0+10) -z=0\n    \\end{array}$.\n    Solution is: $\\mat{x=15,y=20,z=10,w=15}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the rank of the following matrices.\n  \\begin{equation*}\n    (a)~\n    \\begin{mymatrix}{rrrr}\n      4 & -16 & -1 & -5 \\\\\n      1 & -4 & 0 & -1 \\\\\n      1 & -4 & -1 & -2\n    \\end{mymatrix}\n    \\quad\n    (b)~\n    \\begin{mymatrix}{rrrr}\n      3 & 6 & 5 & 12 \\\\\n      1 & 2 & 2 & 5 \\\\\n      1 & 2 & 1 & 2\n    \\end{mymatrix}\n    \\quad\n    (c)~\n    \\begin{mymatrix}{rrrrr}\n      0 & 0 & -1 & 0 & 3 \\\\\n      1 & 4 & 1 & 0 & -8 \\\\\n      1 & 4 & 0 & 1 & 2 \\\\\n      -1 & -4 & 0 & -1 & -2\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{equation*}\n    (d)~\n    \\begin{mymatrix}{rrrrr}\n      1 & -2 & 0 & 3 & 11 \\\\\n      1 & -2 & 0 & 4 & 15 \\\\\n      1 & -2 & 0 & 3 & 11 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}\n    \\quad\n    (e)~\n    \\begin{mymatrix}{rrr}\n      -2 & -3 & -2 \\\\\n      1 & 1 & 1 \\\\\n      1 & 0 & 1 \\\\\n      -3 & 0 & -3\n    \\end{mymatrix}\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is an $m\\times n$-matrix. Explain why the rank of $A$ is\n  always no larger than $\\min (m,n)$.\n  \\begin{sol}\n    The rank is the number of pivot entries in the {\\ef}. There is at\n    most one pivot entry in each row and column. Therefore, the rank\n    cannot be larger than the number of rows or the number of columns;\n    in other words, the rank is at most $\\min(m,n)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  State whether each of the following sets of data is\n  possible for a system of equations. If possible, describe the\n  solution set.  That is, indicate whether there exists a unique\n  solution, no solution or infinitely many solutions. Here, $A$ is\n  the coefficient matrix, and $\\mat{A\\mid B}$ denotes the\n  augmented matrix of the system.\n\n  \\begin{enumerate}\n  \\item $A$ is a $5\\times 6$-matrix, $\\rank(A) =4$ and\n    $\\rank\\mat{A\\mid B} =4$.\n\n  \\item $A$ is a $3\\times 4$-matrix, $\\rank(A) =3$ and\n    $\\rank\\mat{A\\mid B} =2$.\n\n  \\item $A$ is a $4\\times 2$-matrix, $\\rank(A) =4$ and\n    $\\rank\\mat{A\\mid B} =4$.\n\n  \\item $A$ is a $5\\times 5$-matrix, $\\rank(A) =4$ and\n    $\\rank\\mat{A\\mid B} =5$.\n\n  \\item $A$ is a $4\\times 2$-matrix, $\\rank(A) =2$ and\n    $\\rank\\mat{A\\mid B} =2$.\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item The {\\ef} has 4 non-zero rows and 6 columns, so there are 2\n      free variables, and the system has infinitely many solutions.\n    \\item Such a system of equations of equations does not exist. If\n      you add in another column, the rank does not get smaller.\n    \\item Such a system of equations does not exist,\n      because the rank cannot equal 4 if there are only two columns.\n    \\item The {\\ef} has 4 non-zero rows on the left-hand side, but 5\n      non-zero rows if we also include the right-hand side. Therefore\n      the system is inconsistent, i.e., it has no solutions.\n    \\item The {\\ef} has 2 non-zero rows, so there are 2\n      pivot variables and no free variables. Therefore, the system has\n      a unique solution.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the system $-5x+2y-z=0$ and $-5x-2y-z=0$. Both equations\n  equal zero and so $-5x+2y-z=-5x-2y-z$ which is equivalent to $y=0$. Does it follow that $x$\n  and $z$ can equal anything?  Notice that when $x=1$, $z=-4$, and $y=0$ are plugged in\n  to the equations, the equations do not equal $0$. Why?\n  \\begin{sol}\n    These are not legitimate row\n    operations. They do not preserve the solution set of the system.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "3c54e024ccea60102f8555bbab63db3edacd1399", "size": 16800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-GaussianElimination.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-GaussianElimination.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-GaussianElimination.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.7685950413, "max_line_length": 93, "alphanum_fraction": 0.5588690476, "num_tokens": 6614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.9124361527383704, "lm_q1q2_score": 0.7791408602931312}}
{"text": "\\subsubsection{Incremental Numerical Solutions of Maxwell's Equations}\n\nThe following calculations are done in one dimension only for simplicity but can be easily expanded to more dimensions (ref.~\\cite{numel} for detailed calculations in multiple dimensions).\n\nGiven a function $f$ we can calculate its value at a point $x_0\\pm\\frac{\\delta}{2}$ as a Tailor expansion at $x_0$ with\n\n\\begin{align}\n  f\\left(x_0+\\frac{\\delta}{2}\\right)&=f(x_0)+\\frac{\\delta}{2}f'(x_0)+\\frac{1}{2!}\\left(\\frac{\\delta}{2}\\right)^2f''(x_0)+\\frac{1}{3!}\\left(\\frac{\\delta}{2}\\right)^3f'''(x_0)+\\dots,\\\\\n  f\\left(x_0-\\frac{\\delta}{2}\\right)&=f(x_0)-\\frac{\\delta}{2}f'(x_0)+\\frac{1}{2!}\\left(\\frac{\\delta}{2}\\right)^2f''(x_0)-\\frac{1}{3!}\\left(\\frac{\\delta}{2}\\right)^3f'''(x_0)+\\dots.\n\\end{align}\n\nSubstracting these equations leads to\n\n\\begin{equation}\n  f\\left(x_0+\\frac{\\delta}{2}\\right)-f\\left(x_0-\\frac{\\delta}{2}\\right)=\\delta f'(x_0)+\\frac{2}{3!}\\left(\\frac{\\delta}{2}\\right)^3f'''(x_0)+\\dots.\n\\end{equation}\n\nDividing by $\\delta$ and rearranging gives\n\n\\begin{equation}\n  \\left.\\frac{df(x)}{dx}\\right|_{x=x_0} = \\frac{f(x_0+\\frac{\\delta}{2})-f(x_0-\\frac{\\delta}{2})}{\\delta} + O(\\delta^2),\n\\end{equation}\n\nwhere $O(\\delta^2)$ stands for higher order $\\delta$ terms which can be neglected for small $\\delta$. Assuming the electric field only has a $z$-component, Maxwell's equations give\n\n\\begin{align}\n  -\\mu\\frac{\\partial\\mathbf{H}}{\\partial t}&=\\nabla\\times\\mathbf{E} \\quad\\Rightarrow\\quad \\mu\\frac{\\partial H_y}{\\partial t} = \\frac{\\partial E_z}{\\partial x},\\\\ \\label{eq:maxwell}\n  \\epsilon\\frac{\\partial\\mathbf{E}}{\\partial t}&=\\nabla\\times\\mathbf{H} \\quad\\Rightarrow\\quad \\epsilon\\frac{\\partial E_z}{\\partial t} = \\frac{\\partial H_y}{\\partial x},\n\\end{align}\n\nwith the electric field $\\mathbf{E}$, the magnetic field $\\mathbf{H}$, permittivity $\\epsilon$ and permeability $\\mu$.\n", "meta": {"hexsha": "f256d85fe467111f126607222f8b0e647d488a02", "size": 1868, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/1_theoretical_basis/17_incremental_solutions.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/17_incremental_solutions.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/17_incremental_solutions.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": 58.375, "max_line_length": 188, "alphanum_fraction": 0.6879014989, "num_tokens": 668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374444, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7790493902387301}}
{"text": "After data structures, which are a complex part of programming knowledge, we can move on to an even more ambitious goal. We will now try and build a full-blown programming language with our logic language. We will begin with simple arithmetic expressions, which we will augment with memory and flow-control statements.\n\n\\subsection{Evaluating simple arithmetic expressions}\nSimple arithmetic expressions are defined as trees\\footnote{These are, surprisingly, commonly referred to as \\textit{expression trees}.}. Each node of the tree is either a \\texttt{+} or a \\texttt{*}, and the two children of the nodes are the sub expressions that must be, respectively, added or multiplied together. The recursion ends when we find a leaf (\\texttt{\\$}), which contains a single integer value. Examples of expressions that we can represent are \\texttt{3 + 5}, \\texttt{5 + 2 * 3}, etc.\n\nThe reason why such expressions can be represented with a tree can be visualized graphically quite intuitively. Consider expression \\texttt{5 + 2 * 3}; we can render it into a tree as:\n\n\\begin{lstlisting}\n  +\n / \\\n5  *\n  / \\\n 2   3\n\\end{lstlisting}\n\nThe above definition of expressions can be summed up into three new data declarations:\n\n\\begin{lstlisting}\nData [Expr] \"+\" [Expr] Priority 10 Type Expr\nData [Expr] \"*\" [Expr] Priority 20 Type Expr\nData [] \"$\" [<<int>>] Priority 10000 Type Value\n\\end{lstlisting}\n\nOf course a \\texttt{Value} sometimes needs to be used where an \\texttt{Expr} is expected, therefore we add\\footnote{At this point we might even say ``the usual''.}:\n\n\\begin{lstlisting}\nValue is Expr\n\\end{lstlisting}\n\nEvaluating an expression is done with the \\texttt{eval} function, which takes an \\texttt{Expr} as input and then returns an \\texttt{<<int>>}:\n\n\\begin{lstlisting}\nFunc \"eval\" [Expr] Priority 1 Type Expr => <<int>>\n\\end{lstlisting}\n\nWhen the expression to evaluate is an integer constant (the \\texttt{\\$} operator is just a wrapper to make an \\texttt{<<int>>} appear as an \\texttt{Expr}), then the result of the evaluation is just the integer constant itself:\n\n\\begin{lstlisting}\n---------------\neval ($i) => i\n\\end{lstlisting}\n\nWhen the expression to evaluate is a compound expression of sub-expressions \\texttt{a} and \\texttt{b}, then: \\begin{inparaenum}[\\itshape i\\upshape)]\n\\item we evaluate the sub-expressions into \\texttt{x} and \\texttt{y} respectively;\n\\item we combine \\texttt{x} and \\texttt{y} into the final result \\texttt{res} by invoking native operations such as machine integer addition between \\texttt{<<} and \\texttt{>>} brackets.\n\\end{inparaenum}\n\n\\begin{lstlisting}\neval a => x\neval b => y\n<<x+y>> => res\n------------------\neval (a+b) => res\n\neval a => x\neval b => y\n<<x*y>> => res\n------------------\neval (a*b) => res\n\\end{lstlisting}\n\nIt is trivial to extend the above to yet more arithmetic operations such as subtraction, division, etc.\n\nConsider now the evaluation of the expression seen before: \\texttt{\\$5 + (\\$2 * \\$3)}:\n\n\\begin{lstlisting}\n-----------------------\neval ($5+($2*$3)) => ?\n\\end{lstlisting}\n\nThe first rule that is instanced is the rule for addition:\n\n\\begin{lstlisting}\neval $5 => x\neval ($2*$3) => y\n<<x+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nThe premise above (\\texttt{\\$5}) is very easily solved by applying the rule for constants:\n\n\\begin{lstlisting}\nx := 5\n--------------\neval $5 => x\neval ($2*$3) => y\n<<x+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nAt this point we cannot proceed before unwinding the stack by one step, thus we obtain:\n\n\\begin{lstlisting}\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nWe now have to resolve the second premise, thus we apply the rule for multiplication and we obtain:\n\n\\begin{lstlisting}\neval $2 => x'\neval $3 => y'\n<<x'*y'>> => res'\ny := res'\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nWe can now use a rule to solve the evaluation of the first constant:\n\n\\begin{lstlisting}\nx' := 2\n--------------\neval $2 => x'\neval $3 => y'\n<<x'+y'>> => res'\ny := res'\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nWe unwind the stack by one step:\n\n\\begin{lstlisting}\neval $3 => y'\n<<2*y'>> => res'\ny := res'\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nAgain we apply the rule for constants:\n\n\\begin{lstlisting}\ny' := 3\n--------------\neval $3 => y'\n<<2+y'>> => res'\ny := res'\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nWe unwind the stack yet again:\n\n\\begin{lstlisting}\n<<2*3>> => res'\ny := res'\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nAt this point we can just unwind the stack multiple times, from:\n\n\\begin{lstlisting}\ny := 6\n------------------\neval ($2*$3) => y\n<<5+y>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nto:\n\n\\begin{lstlisting}\n<<5+6>> => res\n-------------------------\neval ($5+($2*$3)) => res\n\\end{lstlisting}\n\nAnd finally we obtain the desired result of:\n\n\\begin{lstlisting}\n------------------------\neval ($5+($2*$3)) => 11\n\\end{lstlisting}\n\n\\subsection{Evaluating expressions with memory}\n\nSuppose that we now want to be able to define expressions with symbols such as \\texttt{``x''} or \\texttt{``y''} in the middle, for example: \\texttt{5 + 2 * x}.\n\nThe immediate result is that to represent such an expression we need a new data term for variables\\footnote{This term, much like \\texttt{\\$} for integer constants, is essentially just a wrapper around \\texttt{<<string>>} that allows us to treat a string as an \\texttt{Expr}.}\n\n\\begin{lstlisting}\nData [] \"!\" [<<string>>] Priority 10000 Type Variable\n\\end{lstlisting}\n\nOf course since we want variables to be useable where expressions are expected, we add:\n\n\\begin{lstlisting}\nVariable is Expr\n\\end{lstlisting}\n\nEvaluation of an expression cannot be done directly, because we encounter variables we do not know what value to assign them. For this reason we shall extend the \\texttt{eval} function so that it also takes as input parameter a \\texttt{Memory}:\n\n\\begin{lstlisting}\nFunc [] \"eval\" [Expr Memory] Priority 1 Type Expr => <<int>>\n\\end{lstlisting}\n\nIn the following we assume that \\texttt{Memory} is any container of data. The concrete implementation of \\texttt{Memory} is actually not that important for the purpose of our scneario: it could be a list of \\texttt{<<string>>}, \\texttt{<<int>>} pairs, a binary search tree, a balanced binary search tree, or some other data structure such as those defined in Chapter \\ref{chap:dataStructures}. The only requirement that we impose is that we have an operator to \\texttt{lookup} the value of a variable given its name:\n\n\\begin{lstlisting}\nFunc [Memory] \"lookup\" [<<string>>] Priority 10 Type Expr => <<int>>\n\\end{lstlisting}\n\nThe rules that we have seen so far are substantially unchanged, that is they do not use the memory but rather just pass it around:\n\n\\begin{lstlisting}\n-----------------\neval ($i) m => i\n\neval a m => x\neval b m => y\n<<x+y>> => res\n------------------\neval (a+b) m => res\n\n...\n\\end{lstlisting}\n\nWhen we encounter a variable, which is prefixed by \\texttt{!}, we simply look up its value from memory and return it:\n\n\\begin{lstlisting}\nm lookup v => res\n------------------\neval !v m => res\n\\end{lstlisting}\n\nConsider now a very simple evaluation: expression \\texttt{!v + \\$3}, where memory is \\texttt{[v -> 10]}. We start at:\n\n\\begin{lstlisting}\n------------------------------\neval (!v + $3) [v -> 10] => ?\n\\end{lstlisting}\n\nWe begin by applying the rule for addition, which yields:\n\n\\begin{lstlisting}\neval !v [v -> 10] => x\neval $3 [v -> 10] => y\n<<x + y>> => res\n--------------------------------\neval (!v + $3) [v -> 10] => res\n\\end{lstlisting}\n\nWe now use the rule for variable lookup, which results in:\n\n\\begin{lstlisting}\n[v -> 10] lookup v => res'\nx := res'\n--------------------------\neval !v [v -> 10] => x\neval $3 [v -> 10] => y\n<<x + y>> => res\n--------------------------------\neval (!v + $3) [v -> 10] => res\n\\end{lstlisting}\n\nThe result of looking up is that of obtaining the appropriate value from memory, therefore leading to:\n\n\\begin{lstlisting}\nx := 10\n--------------------------\neval !v [v -> 10] => x\neval $3 [v -> 10] => y\n<<x + y>> => res\n--------------------------------\neval (!v + $3) [v -> 10] => res\n\\end{lstlisting}\n\nWe must now unwind the stack once for \\texttt{x}:\n\n\\begin{lstlisting}\neval $3 [v -> 10] => y\n<<10 + y>> => res\n--------------------------------\neval (!v + $3) [v -> 10] => res\n\\end{lstlisting}\n\nWe have to evaluate constant \\texttt{\\$3}, which immediately yields \\texttt{3} itself as the result:\n\n\\begin{lstlisting}\n<<10 + 3>> => res\n--------------------------------\neval (!v + $3) [v -> 10] => res\n\\end{lstlisting}\n\nThe final unwinding step gives us the expected result of:\n\n\\begin{lstlisting}\n-------------------------------\neval (!v + $3) [v -> 10] => 13\n\\end{lstlisting}\n\n\\subsection{Evaluating statements}\n\nLet us now consider yet another extension: we want to be able to assign variables. This means that we have a new possible expression data term, which we will use for assigning values to variables:\n\n\\begin{lstlisting}\nData [Variable] \":=\" [Expr] Priority 1 Type Expr\n\\end{lstlisting}\n\nEvaluation of expressions such as assignment can be considered to return nothing, and just affect memory. We therefore define the \\texttt{nothing} value:\n\n\\begin{lstlisting}\nData [] \"nothing\" [] Priority 1 Type Value\n\\end{lstlisting}\n\nA natural extension of expression that comes from assignment is the fact that expressions can also be sequenced together, much like lists:\n\n\\begin{lstlisting}\nData [] \"nil\" [] Priority 1 Type Expr\nData [Expr] \";\" [Expr] Priority 1 Type Expr\n\\end{lstlisting}\n\nAfter evaluating an expression, we do not just get the resulting value; this happens because if one expression contains an assignment then evaluation will return the resulting value, but also the changed memory after the assignment. We therefore define a new data type that contains both a value and memory, and extend the return type of \\texttt{eval} so that it now returns such a pair:\n\n\\begin{lstlisting}\nData [Value] \",\" [Memory] Priority 1 Type ValueMemory\nFunc [] \"eval\" [Expr Memory] Priority 1 Type Expr => ValueMemory\n\\end{lstlisting}\n\nEvaluating a null expression is quite simple: we just return nothing and pass the memory through:\n\n\\begin{lstlisting}\n------------------------\neval nil m => nothing,m\n\\end{lstlisting}\n\nWhen evaluating a sequence of expressions, we:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item evaluate the first sub-expression with the input memory \\texttt{m}, therefore obtaining the new memory \\texttt{m1};\n\\item evaluate the second sub-expression with the new memory \\texttt{m1}, therefore obtaining a result \\texttt{res} and new memory \\texttt{m2};\n\\item return \\texttt{res} and \\texttt{m2} as the final result of the whole expression:\n\\end{inparaenum}\n\n\\begin{lstlisting}\neval a m0 => nothing,m1\neval b m1 => res,m2\n------------------------\neval (a;b) m0 => res,m2\n\\end{lstlisting}\n\nIt is important to realize that the \\texttt{;} operator role is simply that of letting the changes done to memory ``fall through'' from one expression to the next.\n\nAssume now that we have some implementation of a function that adds (or updates) a key-value parir into memory:\n\n\\begin{lstlisting}\nFunc [Memory] \"add\" [<<string>> <<int>>] Priority 1 Type Expr => Memory\n\\end{lstlisting}\n\nWe can use this function to define how the assignment operator works:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item we evaluate the right-hand side of the assignment, obtaining a result \\texttt{res} and a potentially changed memory \\texttt{m1};\n\\item we bind \\texttt{res} to \\texttt{v}, therefore obtaining a new memory \\texttt{m2};\n\\item we return \\texttt{nothing} and the final memory \\texttt{m2} as the final result.\n\\end{inparaenum}\n\n\\begin{lstlisting}\neval e m => res,m1\nm1 add v res => m2\n-------------------------------\neval (!v := e) m => nothing,m2\n\\end{lstlisting}\n\nThis actually gives us a complete memory model which can be extended to operators of all kinds. As strange as it may sound to think of memory as just another value that we freely pass around, consider the possibilities that this manner of reasoning offers us:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item we might decide to build a system where memory can be split so that one thread gets some variables and another thread gets some other variables, so that no risky interaction is possible;\n\\item we might define an operator that saves memory in order roll-back the program state to an earlier safe state in case of error;\n\\item we might define a transactional operator that creates a new copy of memory which is only committed after some kind of confirmation;\n\\item etc.\n\\end{inparaenum}\n\nThe possibilities of such a model are endless, and it is important not to be fooled by the fact that we are limiting ourselves \\textit{on purpose} to implement only well-known models of computation. \\footnote{Indeed, new models of computation could just as easily be built, even though they would be quite poor examples for illustration!}\n\n\\subsection{Evaluating control flow statements}\n\nMost of the work has been done so far, but we can now add some finishing touches to turn our tiny language into something more complete, albeit still quite primitive. The final extensions to our language will therefore be a series of control flow operators such as \\texttt{if}, \\texttt{while}, etc., plus a few ``decorative'' symbols such as \\texttt{then}, \\texttt{else}, and \\texttt{do} which, although not strictly necessary, make code much more readable:\n\n\\begin{lstlisting}\nData [Expr] \"gt\" [Expr] Priority 10 Type Expr\nData [] \"if\" [Expr Then Expr Else Expr] Priority 5 Type Expr\nData [] \"then\" [] Priority 10000 Type Then\nData [] \"else\" [] Priority 10000 Type Else\nData [] \"while\" [Expr Do Expr] Priority 5 Type Expr\nData [] \"do\" [] Priority 10000 Type Do\n\\end{lstlisting}\n\nSince we will now also need to manipulate boolean expressions, we will create a new data type to wrap boolean values:\n\n\\begin{lstlisting}\nKeyword [] \"?\" [<<bool>>] Priority 10000 Type Value\n\\end{lstlisting}\n\nSince evaluation may now return values as well, we update the definition of \\texttt{eval} so that its return type is now \\texttt{Value} instead of just \\texttt{<<int>>}. Evaluating a \\texttt{gt} (greater than) comparison now looks very much like the evaluation of a sum or a product:\n\n\\begin{lstlisting}\neval a m0 => $x,m1\neval b m1 => $y,m2\nx > y\n-----------------------------\neval (a gt b) m0 => ?true,m2\n\neval a m0 => $x,m1\neval b m1 => $y,m2\nx <= y\n------------------------------\neval (a gt b) m0 => ?false,m2\n\\end{lstlisting}\n\nWhen evaluating a conditional statement, then we first evaluate the condition. If the condition evaluates to a value of \\texttt{true}, then we evaluate the \\texttt{then} branch and return the result of its evaluation:\n\n\\begin{lstlisting}\neval c m0 => ?true, m1\neval a m1 => res,m2\n---------------------------------------\neval (if c then a else b) m0 => res,m2\n\\end{lstlisting}\n\nIf the condition evaluates to a value of \\texttt{false}, then we evaluate the \\texttt{else} branch and return the result of its evaluation:\n\n\\begin{lstlisting}\neval c m0 => ?false, m1\neval b m1 => res,m2\n---------------------------------------\neval (if c then a else b) m0 => res,m2\n\\end{lstlisting}\n\nThe evaluation of a \\texttt{while} loop is just as simple. We evaluate the condition of the \\texttt{while} loop, and if we obtain a result of \\texttt{false} then we are done and we can return a result of \\texttt{nothing}:\n\n\\begin{lstlisting}\neval c m0 => ?false,m1\n-------------------------------------\neval (while c do b) m0 => nothing,m1\n\\end{lstlisting}\n\nIf the condition of the loop evaluates to \\texttt{true}, then we evaluate the body of the loop once, obtaining a new memory \\texttt{m2}. This new memory will be used to re-evaluate the \\texttt{while} loop:\n\n\\begin{lstlisting}\neval c m0 => ?true, m1\neval b m1 => nothing,m2\neval (while c do b) m2 => nothing,m3\n-------------------------------------\neval (while c do b) m0 => nothing,m3\n\\end{lstlisting}\n\nIn this case we will skip a practical example as it would be quite long, and it does not really add much to the examples seen previously in the chapter.\n\n\\paragraph{Conclusions}\nIt is quite possible to further extend our tiny language to all sorts of additional niceness. For example, we could define functions, we could distinguish between \\textit{heap} and \\textit{stack} memory, we could define data structures, etc. Of course this would quite complicate our definitions, but surprisingly less than one would expect. For example, a much richer implementation that also contains declaration and even scoping of variables (the fundamental construct that makes function definition possible) requires as little as 360 lines of code. The implementation of a real-time oriented programming language for game development (Casanova) took less than 600 lines of code. Compared with the equivalent definition of a compiler written by hand, we are talking about a significant difference; the Casanova compiler written in F\\# is almost two orders of magnitude larger than the new implementation, at a whopping 10,000 lines of code.\n\nMoreover, primitive or not, our tiny language now supports integer variables and some looping constructs. This means that the sample language we have defined in this chapter enjoys a very important property known as \\textit{Turing completeness}, which guarantees that it is powerful enough to compute anything that is computable. This important property and its consequences will be further elaborated in Chapter \\ref{chap:closingRemarks}.\n", "meta": {"hexsha": "a7faea0c864660734b2f5d53d112ad041fa50c0f", "size": 17984, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/evaluating_expressions.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/evaluating_expressions.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/evaluating_expressions.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": 38.021141649, "max_line_length": 944, "alphanum_fraction": 0.6783251779, "num_tokens": 4725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062238, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7790493798044512}}
{"text": "\\section{Integral of $\\frac{1}{x^4+1}$}\nWhen we first see function $\\frac{1}{x^4+1}$, it always reminds us of the\nderivative of arc tangent (which is $\\frac{1}{x^2+1}$). Therefore we can solve\nthis using some intuitions of arc tangent. First step, we try to make it into\nmultiplication of polynomials in order to facilitate the integration:\n\n$$\n\\begin{aligned}\n\tx^4+1\n\t&=(x^4+2x^2+1)-2x^2 \\\\\n\t&=(x^2+1)^2-(\\sqrt2x)^2 \\\\\n\t&=(x^2-\\sqrt2x+1)(x^2+\\sqrt{2x}+1) \\\\\n\\end{aligned}\n$$\n\nIt seems that we are now able to deal with it using partial fractions:\n\n$$\\frac{1}{x^4+1}=\\frac{Ax+B}{x^2-\\sqrt2x+1}+\\frac{Cx+D}{x^2+\\sqrt2x+1}$$\n\nSince we know the numerator of the fraction in the left part is one, we can\nmake the addition of numerator equal to $1$:\n\n$$\n\\begin{aligned}\n\t1=&(Ax+B)(x^2+\\sqrt2x+1)+(Cx+D)(x^2-\\sqrt2x+1) \\\\\n\t1=&(Ax^3+A\\sqrt2x^2+Ax)+(Bx^2+B\\sqrt2x+B)+ \\\\\n\t&(Cx^3-C\\sqrt2x^2+Cx)+(Dx^2-D\\sqrt2x+D) \\\\\n\t1=&(A+C)x^3+[\\sqrt2(A-C)+B+D]x^2+[A+C+\\sqrt2(B-D)]x+B+D\n\\end{aligned}\n$$\n\nWe can turn this nasty polynomial equation into linear equations:\n\n$$\n\\begin{aligned}\n\t\\begin{cases}\n\t\tA+C=0 \\\\\n\t\t\\sqrt2(A-C)+B+D=0 \\\\\n\t\tA+C+\\sqrt2(B-D)=0 \\\\\n\t\tB+D=1 \\label{e_d}\n\t\\end{cases} \\\\\n\t\\because B+D=1 \\\\\n\t\\therefore \\sqrt2(A-C)+1=0 \\\\\n\t\\therefore A-C=-\\frac{1}{\\sqrt2} \\\\\n\t\\because A+C=0 \\\\\n\t\\therefore 2A=-\\frac{1}{\\sqrt2} \\\\\n\t\\therefore A=-\\frac{1}{2\\sqrt2} \\\\\n\t\\therefore C=\\frac{1}{2\\sqrt2} \\\\\n\t\\because B+D=1,B-D=0 \\\\\n\t\\therefore B=D=\\frac{1}2 \\\\\n\t\\begin{cases}\n\t\tA=-\\frac{1}{\\sqrt2} \\\\\n\t\tB=\\frac{1}2 \\\\\n\t\tC=\\frac{1}{\\sqrt2} \\\\\n\t\tD=\\frac{1}2 \\\\\n\t\\end{cases} \\\\\n\t\\therefore \\frac{1}{x^4+1}=\\frac{-\\frac{1}{2\\sqrt2}x+\n\t\\frac{1}2}{x^2-\\sqrt2x+1}+\\frac{\\frac{1}{2\\sqrt2}x+\n\t\\frac{1}2}{x^2+\\sqrt2x+1}\n\\end{aligned}\n$$\n\nSince we split the one fraction into two fractions in which each denominator is\nmade of a second-power trinomial, so we can complete squares for integrating\nfor arc tangent.\n\n\\begin{eqnarray}\n\t\\begin{aligned}\n\t\tx^2-\\sqrt2x+1\n\t\t&=(x^2-\\sqrt2x+\\frac{1}2)+\\frac{1}2 \\\\\n\t\t&=(x-\\frac{1}{\\sqrt2})^2+\\frac{1}2\n\t\\end{aligned} \\label{eqn1}\\\\\n\tx^2+\\sqrt2x+1=(x+\\frac{1}{\\sqrt2})^2+\\frac{1}2 \\label{eqn2}\n\\end{eqnarray}\n\nNow we can integrate since everything is ready. The integration starts with\npartial fractions and then plugging in \\ref{eqn1} and \\ref{eqn2}\n\n$$\n\\begin{aligned}\n\t\\int\\frac{dx}{x^4+1}&=\\int\\frac{-\\frac{1}{2\\sqrt2}x+\n\t\\frac{1}2}{x^2-\\sqrt2x+1}dx+\\int\\frac{\\frac{1}{2\\sqrt2}x+\n\t\\frac{1}2}{x^2+\\sqrt2x+1}dx \\\\\n\t&=\\frac{1}{4\\sqrt2}\\left(\\int\\frac{-2x+2\\sqrt2}{(x-\\frac{1}{\\sqrt2})^2\n\t+\\frac{1}2}dx+\\int\\frac{2x+2\\sqrt2}{(x+\\frac{1}{\\sqrt2})^2+\\frac{1}2}dx\n\t\\right)\n\\end{aligned}\n$$\n\nNow we start dealing with them with the first part:\n\n$$\n\\begin{aligned}\n\t\\int\\frac{-2x+2\\sqrt2}{(x-\\frac{1}{\\sqrt2})^2+\\frac{1}2}dx\n\t&=-\\int\\frac{2x}{(x-\\sqrt2)^2+\\frac{1}2}dx+\n\t\\int\\frac{2\\sqrt2}{(x-\\sqrt2)^2+\\frac{1}2}dx\n\\end{aligned}\n$$\n\nIt seems like a \\textbf{$u$-substitution} is applicable in the first integral,\nso we let $u=(x-\\sqrt2)^2+\\frac{1}2$, so $du=2xdx$. Then the whole thing is\ntransformed into this:\n\n$$\n\\begin{aligned}\n\t-\\int\\frac{2x}{(x-\\sqrt2)^2+\\frac{1}2}dx+\n\t\\int\\frac{2\\sqrt2}{(x-\\sqrt2)^2+\\frac{1}2}dx\n\t&=-\\int\\frac{du}u+\n\t\\int\\frac{2\\sqrt2}{(x-\\sqrt2)^2+\\frac{1}2}dx \\\\\n\t&=-\\ln(u)+\n\t\\int\\frac{2\\sqrt2}{(x-\\sqrt2)^2+\\frac{1}2}dx \\\\\n\t&=-\\ln(x^2-\\sqrt2x+1)+\n\t\\int\\frac{2\\sqrt2}{(x-\\sqrt2)^2+\\frac{1}2}dx \\\\\n\t&=-\\ln(x^2-\\sqrt2x+1)+\n\t\\int\\frac{2\\sqrt2}{(x-\\frac{1}{\\sqrt2})^2\n\t+(\\frac{1}{\\sqrt2})^2}dx \\\\\n\t&=-\\ln(x^2-\\sqrt2x+1)+\\sqrt2\\arctan(\\sqrt2x-1)\n\\end{aligned}\n$$\n\nThe integration of the second integral is very similar, at last the indefinite\nintegral of $\\frac1{x^4+1}$ is:\n\n$$\n\\frac1{4\\sqrt2}\\left(\\ln({x^2+\\sqrt2x+1\\over x^2-\\sqrt2x+1})+\n2\\arctan(\\sqrt2x+1)+2\\arctan(\\sqrt2x-1)\\right)+C\n$$\n", "meta": {"hexsha": "8a2a282f8db1ccea183194b1c2fadb6456719165", "size": 3720, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integrate-1overx4plus1.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "integrate-1overx4plus1.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "integrate-1overx4plus1.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 29.0625, "max_line_length": 79, "alphanum_fraction": 0.6260752688, "num_tokens": 1676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8947894703109853, "lm_q1q2_score": 0.7790012656490881}}
{"text": "\\section{Differentiation}\n\n\\subsection{Basic Definitions}\n\n\\subsubsection{Exercise 1}\nLet the derivative of $f$ at $a$ be the linear operator $\\lambda$. Then, by problem $1-10$, we have that\n$\\abs{\\lambda(h)} \\leq M \\abs{h}$ for some $M \\in \\mathbb{R}$. Thus,\n\\begin{align*}\n        \\abs{(f(a + h) - f(a)} &= \\frac{\\abs{f(a + h) - f(a)}}{\\abs{h}} * \\abs{h} \\\\\n                               &\\leq \\frac{\\abs{f(a + h) - f(a) - \\lambda(h)} + \\abs{\\lambda(h)}}{\\abs{h}} * \\abs{h} \\\\\n        \\implies \\lim_{h \\to 0} \\abs{f(a + h) - f(a)} &\\leq \\lim_{h \\to 0} \\frac{\\abs{f(a + h) - f(a) - \\lambda(h)} + \\abs{\\lambda(h)}}{\\abs{h}} \\lim_{h \\to 0} \\abs{h} \\\\\n                                                      &\\leq M * 0 = 0\n\\end{align*}\n\n\\subsubsection{Exercise 2}\nIf $f$ is independent, we can define $g = f(x, y_0)$ for some arbitrary $y_0$. If there exists $g$ such that\n$f(x, y) = g(x)$ for all $x, y$, then we have $f(x, y_1) = g(x) = f(x, y_2)$ so $f$ is independent of the\nsecond variable. In this case, $f'(a, b) = g'(a)$.\n\n\\subsubsection{Exercise 3}\nA function that is independent of both variables must, by construction, be constant.\n\n\\subsubsection{Exercise 4}\n(a) When $t < 0$, we have\n\\begin{align*}\n        h(t) = -t\\abs{x} g\\bigg(\\frac{tx}{-t \\abs{x}}\\bigg) = t\\abs{x}g\\bigg(\\frac{x}{\\abs{x}}\\bigg)\n\\end{align*}\nwhich is the same as $h(t)$ when $t > 0$, so $h(t)$ is differentiable with derivative $f(x)$.\n\n(b) Since $g(0, 1) = g(1, 0) = 0$, we have that $f(h, 0) = f(0, k) = 0$. Letting $\\lambda = Df(0, 0)$, we have\nthat\n\\begin{align*}\n        \\lim_{(h, 0) \\to 0} \\frac{\\abs{\\lambda(h, 0)}}{\\abs{h}} &= \\lim_{(h, 0) \\to 0} \\frac{\\abs{h} \\lambda(1, 0)}{\\abs{h}} \\\\\n                                                                &= \\lambda(1, 0) = 0\n\\end{align*}\nif $\\lambda$ exists. Similarly, considering $(0, k) \\to 0$ gives $\\lambda(0, 1) = 0$, so $\\lambda = 0$. \nAs a result, we have that $f$ is differentiable at $(0, 0)$ only if\n\\begin{align*}\n        \\lim_{(h, k) \\to (0, 0)} \\frac{\\abs{f(h, k)}}{\\abs{(h, k)}} = \\lim_{(h, k) \\to (0, 0)} \\abs{g\\bigg(\\frac{(h, k)}{\\abs{(h, k)}}\\bigg)} = 0\n\\end{align*}\nwhich implies that $g = 0$ (we can consider $t(x, y)$ as $t \\to 0$ for every $(x, y)$ on the unit circle). \n\n\\subsubsection{Exercise 5}\nApply the previous exercise with $g(x, y) = x\\abs{y}$.\n\n\\subsubsection{Exercise 8}\nIf $f$ is differentiable, then\n\\begin{align*}\n        \\lim_{h \\to 0} \\frac{\\abs{f(a + h) - f(a) - \\lambda(h)}}{\\abs{h}} &= 0 \\\\\n                                                                          &= \\lim_{h \\to 0} \\frac{\\abs{(f_1(a + h) - f_1(a) - \\lambda_1(h), f_2(a + h) - f_2(a) - \\lambda_2(h))}}{\\abs{h}} \\\\\n                                                                          &\\geq \\lim_{h \\to 0} \\frac{\\abs{f_1(a + h) - f_1(a) - \\lambda_1(h)}}{\\abs{h}}\n\\end{align*}\nso $f_1$ and $f_2$ are both differentiable. The reverse direction is a straightforward application of the triangle\ninequality.\n\n\\subsubsection{Exercise 9}\n(a) If $f$ is differentiable at $a$, then we can let $g(x) = f(a) + f'(a) (x - a)$. For the other direction,\n\\begin{align*}\n        \\lim_{h \\to 0} \\frac{f(a + h) - a_0 - a_1h}{h} &= 0 \\\\\n        \\implies \\lim_{h \\to 0} \\frac{f(a + h) - a_0}{h} &= a_1 \\\\\n        \\implies a_0 = f(a)\n\\end{align*}\nso $f$ is differentiable at $a$.\n\n(b) We can break up the $n^{\\text{th}}$ order limit into\n\\begin{align*}\n        \\lim_{x \\to  a} \\frac{f(x) - g(x)}{(x - a)^n} &=\n        \\lim_{x \\to a} \\frac{f(x) - \\sum_{i = 0}^{n - 1} \\frac{f^{(i)}(a)}{i!} (x - a)^i}{(x - a)^n} +\n        \\frac{f^{(n)}(a)}{n!} \\\\\n                                                      &= \\frac{f^{(n)}(a)}{n!} - \\frac{f^{(n)}(a)}{n!} = 0\n\\end{align*}\nwhere the last step follows from repeated application of L'Hopital's.\n\n\\subsection{Basic Theorems}\n\n\\subsubsection{Exercise 11}\n(a) Let $G$ be a function such that $G' = g$. Then\n\\begin{align*}\n        f'(x, y) &= g(x + y) (\\pi_1'(x, y) + \\pi_2'(x, y)) \\\\\n                 &= g(x + y) ((1, 0) + (0, 1)) = (g(x + y), g(x + y))\n\\end{align*}\n\n(b) Following the setup of (a), we have\n\\begin{align*}\n        f'(x, y) &= g(xy) (y \\pi_1'(x, y) + x \\pi_2'(x, y)) \\\\\n                 &= g(xy) (y, x)\n\\end{align*}\n\n\\subsubsection{Exercise 12}\n(a) Since $f(h, k) = hk f(1, 1)$, the desired result follows immediately from $\\lim_{(h, k) \\to 0} \\frac{\\abs{hk}}{\\abs{(h, k)}} = 0$.\n\n(b) We have that $f(a + h, b + k) - f(a, b) = f(a, k) + f(h, b) + f(h, k)$ from bilinearity, so $Df(a, b)(x, y) = f(a, y) + f(x, b)$ as\ndesired.\n\n(c) The function $p: \\mathbb{R} \\times \\mathbb{R} \\to \\mathbb{R}$ from Theorem 2-3 is bilinear, so it is just a special case\nof (b).\n\n\\subsubsection{Exercise 14}\n(a) We can bound the multilinear case with the bilinear case:\n\\begin{align*}\n        \\lim_{h \\to 0} \\frac{\\abs{f(a_1, ..., h_i, ..., h_j, ..., a_k)}}{\\abs{h}} &\\leq\n        \\lim_{h \\to 0} \\frac{\\abs{f(a_1, ..., h_i, ..., h_j, ..., a_k)}}{\\abs{(h_i, h_j)}} \\\\ &\\leq\n        \\lim_{(h_i, h_j) \\to 0} \\frac{\\abs{f(a_1, ..., h_i, ..., h_j, ..., a_k)}}{\\abs{(h_i, h_j)}} \\\\\n                                                                                             &= 0\n\\end{align*}\n\n(b) Expanding $f(a_1 + h_1, ..., a_n + h_n) - f(a_1, ..., a_n) - Df(a_1, ..., a_n)(h_1, ..., h_n)$\nleaves only terms that are at least bilinear, so by part (a) we are done.\n\n\\subsubsection{Exercise 16}\nUsing the fact that $Dx = x$ (from Theorem 2-3), we have that\n\\begin{align*}\n        f'(f^{-1}) \\circ f^{-1\\prime} (x) &= x \\\\\n        \\implies f^{-1\\prime} (x) &= [f'(f^{-1} (x))]^{-1} \n\\end{align*}\n\n\\subsection{Partial Derivatives}\n\n\\subsubsection{Exercise 19}\nSince $f(1, y) = 1$, $D_2 f(1, y) = 0$.\n\n\\subsubsection{Exercise 21}\n(a) The first term of $f$ is independent of $y$, so we need not consider it. Letting $G_2$ be the antiderivative of\n$g_2$, we have that the second term is equivalent to $G_2(x, y) - G_2(x, 0)$. Differentiating this with respect to $y$\nyields $g_2(x, y)$ as desired.\n\n(b) Replacing the first integrand with $g_1(t, y)$ and the second integrand with $g_2(0, t)$ will give\n$D_2 f(x, y) = g_1(x, y)$.\n\n(c) The functions $f(x, y) = \\frac{x^2}{2} + \\frac{y^2}{2}$ and $f(x, y) = xy$ will work (obtained by integrating the\ndesired partial derivatives with respect to $x$ and $y$).\n\n\\subsubsection{Exercise 22}\nApplying the mean value theorem to each variable gives the desired results.\n\n\\subsubsection{Exercise 23}\n(a) Consider $(x_1, y_1)$ and $(x_2, y_2)$. Since $D_1 f = D_2 f = 0$, we have that $f$ is constant along the lines from\n$(x_1, y_1)$ to $(-\\epsilon, y_1)$, $(-\\epsilon, y_1)$ to $(-\\epsilon, y_2)$, and $(-\\epsilon, y_2)$ to $(x_2, y_2)$ by\nthe logic of the previous exercise (where $\\epsilon > 0$). Thus, $f(x_1, y_1) = f(x_2, y_2)$ for all $(x_1, y_1)$ and\n$(x_2, y_2)$.\n\n(b) Take the following function:\n\\begin{align*}\n        f(x, y) = \n        \\begin{cases}\n                0 & x < 0 \\\\\n                1 & x \\geq 0, y > 0 \\\\\n                -1 & x \\geq 0, y < 0 \\\\\n        \\end{cases}\n\\end{align*}\nThis function is not independent of $y$, since $f(0, 1) \\neq f(0, -1)$. However,\n$D_2 f = 0$ (due to $x \\geq 0, y = 0$ not being in $A$).\n\n\\subsubsection{Exercise 25}\nSince $\\exp(-x^{-2})$ is $C^\\infty$ for all $x \\neq 0$, $f$ is also $C^\\infty$ for all such $x$. For\n$x = 0$, we can proceed via L'Hopital's as suggested:\n\\begin{align*}\n        f'(0) &= \\lim_{h \\to 0} \\frac{f(h) - f(0)}{h} \\\\\n              &= \\lim_{h \\to 0} \\frac{\\exp(-h^{-2})}{h} \\\\\n              &= \\lim_{h \\to 0} \\frac{\\frac{1}{h}}{\\exp(h^{-2})} \\\\\n              &= \\lim_{h \\to 0} \\frac{h}{2\\exp(h^{-2})} \\\\\n              &= 0\n\\end{align*}\nRepeating this procedure indefinitely shows that $f^{(i)}(0) = 0$ and that $f$ is $C^\\infty$.\n\n\\subsubsection{Exercise 26}\n(a) The strategy from the previous exercise should work.\n\n(b) Consider the following function:\n\\begin{align*}\n        f(x) =\n        \\begin{cases}\n                \\exp(-x^{-2}) \\exp(-(x - \\epsilon)^{-2}) & x \\in (0, \\epsilon) \\\\\n                0 & x \\notin (0, \\epsilon)\n        \\end{cases}\n\\end{align*}\nNow we can define $g(x) = \\int_{0}^{x} f / \\int_{0}^{\\epsilon} f$ as suggested. Since\n$f(x) = 0$ for all $x \\geq \\epsilon$, we have that $\\int_{0}^{x} f = \\int_{0}^{\\epsilon} f$.\nSimilarly, $\\int_{0}^{x} f = 0$ for $x \\leq 0$.\n\n(c) The fact that $g$ is $C^\\infty$ follows from $f$ being $C^\\infty$. Similarly,\nplugging $\\frac{x_i - a_i}{\\epsilon}$ into $f$ gives\n$\\exp(-\\big(\\frac{x_i - (a_i + \\epsilon)}{\\epsilon}\\big)^{-2}) \\exp(-\\big(\\frac{x_i - (a_i - \\epsilon)}{\\epsilon}\\big)^{-2})$, from\nwhich it can be seen that $f$ is positive only on \n$(a_1 - \\epsilon, a_1 + \\epsilon) \\times ... \\times (a_n - \\epsilon, a_n + \\epsilon)$\nand 0 everywhere else.\n\n(d) Since $C$ is compact and in $\\mathbb{R}^n$, we can choose finitely many\nclosed rectangles around points in $C$ such that these rectangles are contained\nin $A$ and their union covers $C$. For each such rectangle, we can then mimic\nthe style of the function $g$ in part (c) to produce a $C^\\infty$ function that is \nnon-zero only in that rectangle. Finally, we can take the sum of these functions\nto get a function that is $C^\\infty$ and positive on $C$ while being 0 outside of a\nclosed set contained in $A$.\n\n(e) The function described in (d) satisfies $f(x) \\geq \\epsilon$ (for some $\\epsilon > 0$)\nfor all $x \\in C$ since $C$ is compact. Thus, we can consider $g \\circ f$ with\nthe aforementioned $\\epsilon$ ($g$ is described in (b)) to get the desired \nfunction.\n", "meta": {"hexsha": "e5ff15f7860b2ee18cdea7439eebe823540de821", "size": 9462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus_on_Manifolds_Spivak/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": "Calculus_on_Manifolds_Spivak/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": "Calculus_on_Manifolds_Spivak/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.31, "max_line_length": 189, "alphanum_fraction": 0.5447051363, "num_tokens": 3566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.7789350643079531}}
{"text": "\n\\subsection{Linear first-order Ordinary Differential Equations}\n\n\\subsubsection{Linear ODEs}\n\nFor some we can write:\n\n\\(\\dfrac{dy}{dt}=f(t,y)\\)\n\n\\(\\dfrac{dy}{dt}=q(t)-p(t)y\\)\n\nThis can be solved by multiplying by an unknown function \\(\\mu (t)\\):\n\n\\(\\dfrac{dy}{dt}+p(t)y=q(t)\\)\n\n\\(\\mu (t)[\\dfrac{dy}{dt}+p(t)y]=\\mu (t)q(t)\\)\n\nWe can then set \\(\\mu(t)=e^{\\int p(t)dt}\\). This means that \\(\\dfrac{d\\mu }{dt}=p(t)u(t)\\)\n\n\\(\\dfrac{d}{dt}[\\mu(t)y]=\\mu (t)q(t)\\)\n\n\\(\\mu(t)y=\\int \\mu (t)q(t)dt + C\\)\n\nIn some cases, this can then be solved.\n\n\\subsubsection{Example}\n\n\\(\\dfrac{\\delta y}{\\delta x}=cy\\)\n\n\\(y=Ae^{c(y+a)}\\)\n\n\n\\(\\dfrac{\\delta^2 y}{\\delta x^2}=cy\\)\n\n\\(y=Ae^{\\sqrt c (y+a)}\\)\n\n", "meta": {"hexsha": "c3345e3077aa82188f3e525fcc8f72590ad55dd4", "size": 680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/ODE/02-02-linearFirstODE.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/ODE/02-02-linearFirstODE.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/ODE/02-02-linearFirstODE.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.3783783784, "max_line_length": 90, "alphanum_fraction": 0.5779411765, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235895, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7789263993991575}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Cayley-Dickson Constructs}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe Cayley-Dickson construction is a method to generate a larger algebra $\\mathcal{C}(\\mathcal{A})$ given an initial algebra $\\mathcal{A}$. Here ``algebra'' is used very loosely.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Pairs}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nLet $a$ and $b$ be members of $\\mathcal{A}$. A member $z$ of the Cayley Dickson construct $\\mathcal{C}(\\mathcal{A})$ is an \\textbf{ordered-pair}\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nA Cayley-Dickson construct is not quite a tensor product of $\\mathcal{A}$ with itself. The operations involving members of $\\mathcal{C}(\\mathcal{A})$ can be defined in terms of the analogous operations involving members of $\\mathcal{A}$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Addition}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{addition} operation works as expected: the sum of two pairs $z_{1}$ and $z_{2}$ is just the pair of additions. That is, if\n\\begin{align*}\n    z_{1} &= \\begin{pmatrix}\n        a_{1} & b_{1}\n    \\end{pmatrix} &\n    z_{2} &= \\begin{pmatrix}\n        a_{2} & b_{2}\n    \\end{pmatrix}\n\\end{align*}\nthen\n\\begin{equation}\n    z_{1} + z_{2} = \\begin{pmatrix}\n        a_{1} + a_{2} & b_{1} + b_{2}\n    \\end{pmatrix}\n\\end{equation}\nNote that addition is a symmetric operation.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Scalar Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{scalar multiplication} operation is also as expected: scaling $z$ by a scalar $c$ is just the pair of scalings. That is, if\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen\n\\begin{equation}\n    cz = \\begin{pmatrix}\n        ca & cb\n    \\end{pmatrix}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Negation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{negation} operation is a special case of scalar multiplication. If\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen\n\\begin{equation}\n    {-z} = \\begin{pmatrix}\n        -a & -b\n    \\end{pmatrix}\n\\end{equation}\nNote that negation is an involutive operation.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Subtraction}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou can always define the \\textbf{subtraction} operation in terms of addition and negation. That is, if\n\\begin{align*}\n    z_{1} &= \\begin{pmatrix}\n        a_{1} & b_{1}\n    \\end{pmatrix} &\n    z_{2} &= \\begin{pmatrix}\n        a_{2} & b_{2}\n    \\end{pmatrix}\n\\end{align*}\nthen\n\\begin{equation}\n    z_{1} - z_{2} = \\begin{pmatrix}\n        a_{1} - a_{2} & b_{1} - b_{2}\n    \\end{pmatrix}\n\\end{equation}\nNote that addition is an anti-symmetric operation.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Asterisk Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{asterisk conjugate} operation on a member of the Cayley-Dickson construct on $\\mathcal{A}$ can be stated in terms of negation and asterisk conjugate operations on members of $\\mathcal{A}$. Given\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen\n\\begin{equation}\n    {\\ast z} = \\begin{pmatrix}\n        {\\ast a} & -b\n    \\end{pmatrix}\n\\end{equation}\nNote that asterisk conjugation is an involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Parabolic Construct}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA parabolic Cayley-Dickson construct will introduce elements that square to zero. This will lead to zero-divisors.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven two members\n\\begin{align*}\n    z_{1} &= \\begin{pmatrix}\n        a_{1} & b_{1}\n    \\end{pmatrix} &\n    z_{2} &= \\begin{pmatrix}\n        a_{2} & b_{2}\n    \\end{pmatrix}\n\\end{align*}\nthen the \\textbf{parabolic multiplication} operation is\n\\begin{equation}\n    z_{1} \\wedge z_{2} = \\begin{pmatrix}\n        a_{1} \\wedge a_{2} & b_{2} \\wedge a_{1} + a_{2} \\wedge {\\ast b_{1}}\n    \\end{pmatrix}\n\\end{equation}\nNote that the order here is very important. In some cases, this product will be commutative and/or associative, but not always.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen the \\textbf{parabolic quadrance} of $z$ is\n\\begin{equation}\n    \\Vert z \\Vert^{2} \\equiv \\Vert a \\Vert^{2} = z \\wedge {\\ast z} = {\\ast z} \\wedge z\n\\end{equation}\nThat is, the quadrance of $z$ is the same as the quadrance of the first element of $z$. In this way it is clear that if $a$ has zero quadrance, then $z$ will have zero quadrance and no inverse.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Cloak and Dagger Conjugation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{cloak and dagger conjugate} operations on a member of the parabolic Cayley-Dickson construct on $\\mathcal{A}$ can be stated in terms of cloak and dagger conjugate operations on members of $\\mathcal{A}$. Given\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen\n\\begin{align}\n    {\\diamond z} &= \\begin{pmatrix}\n        {\\diamond a} & {\\dagger b}\n    \\end{pmatrix} &\n    {\\dagger z} &= \\begin{pmatrix}\n        {\\dagger a} & {\\diamond b}\n    \\end{pmatrix}\n\\end{align}\nThe cloak and dagger conjugates are involutions. \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Hodge Star}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe \\textbf{Hodge star} operation on a member of the parabolic Cayley-Dickson construct on $\\mathcal{A}$ can be stated in terms of dagger conjugate and Hodge star operations on members of $\\mathcal{A}$. Given\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen\n\\begin{equation}\n     {\\star z} = \\begin{pmatrix}\n         {\\dagger {\\star b}} &  {\\star a}\n    \\end{pmatrix}\n\\end{equation}\nThe Hodge star operation is not always an involution.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Elliptic Construct}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nAn elliptic Cayley-Dickson construct will introduce elements that square to minus one. This might lead to zero-divisors, eventually.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven two members\n\\begin{align*}\n    z_{1} &= \\begin{pmatrix}\n        a_{1} & b_{1}\n    \\end{pmatrix} &\n    z_{2} &= \\begin{pmatrix}\n        a_{2} & b_{2}\n    \\end{pmatrix}\n\\end{align*}\nthen the \\textbf{elliptic multiplication} operation is\n\\begin{equation}\n    z_{1} \\wedge z_{2} = \\begin{pmatrix}\n        a_{1} \\wedge a_{2} - {\\ast b_{2}} \\wedge b_{1} & b_{2} \\wedge a_{1} + a_{2} \\wedge {\\ast b_{1}}\n    \\end{pmatrix}\n\\end{equation}\nNote that the order here is very important. In some cases, this product will be commutative and/or associative, but not always.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen the \\textbf{elliptic quadrance} of $z$ is\n\\begin{equation}\n    \\Vert z \\Vert^{2} \\equiv \\Vert a \\Vert^{2} + \\Vert b \\Vert^{2} = z \\wedge {\\ast z} = {\\ast z} \\wedge z\n\\end{equation}\nThat is, the quadrance of $z$ is the sum of the quadrance of the elements of $z$.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Hyperbolic Construct}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA hyperbolic Cayley-Dickson construct will introduce elements that square to one. This will lead to zero-divisors.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Multiplication}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven two members\n\\begin{align*}\n    z_{1} &= \\begin{pmatrix}\n        a_{1} & b_{1}\n    \\end{pmatrix} &\n    z_{2} &= \\begin{pmatrix}\n        a_{2} & b_{2}\n    \\end{pmatrix}\n\\end{align*}\nthen the \\textbf{hyperbolic multiplication} operation is\n\\begin{equation}\n    z_{1} \\wedge z_{2} = \\begin{pmatrix}\n        a_{1} \\wedge a_{2} + {\\ast b_{2}} \\wedge b_{1} & b_{2} \\wedge a_{1} + a_{2} \\wedge {\\ast b_{1}}\n    \\end{pmatrix}\n\\end{equation}\nNote that the order here is very important. In some cases, this product will be commutative and/or associative, but not always.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Quadrance}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nGiven\n\\begin{equation}\n    z = \\begin{pmatrix}\n        a & b\n    \\end{pmatrix}\n\\end{equation}\nthen the parabolic quadrance of $z$ is\n\\begin{equation}\n    \\Vert z \\Vert^{2} \\equiv \\Vert a \\Vert^{2} - \\Vert b \\Vert^{2} = z \\wedge {\\ast z} = {\\ast z} \\wedge z\n\\end{equation}\nThat is, the quadrance of $z$ is the difference of the quadrance of the elements of $z$.", "meta": {"hexsha": "cabe04883080e60fe5264c6db77030b04d121681", "size": 10298, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/B.tex", "max_stars_repo_name": "meirizarrygelpi/cdc", "max_stars_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter/B.tex", "max_issues_repo_name": "meirizarrygelpi/cdc", "max_issues_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter/B.tex", "max_forks_repo_name": "meirizarrygelpi/cdc", "max_forks_repo_head_hexsha": "f9c9f027888aa8c05fd58d2fef0b21ee78002b9c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.0326530612, "max_line_length": 237, "alphanum_fraction": 0.4852398524, "num_tokens": 2567, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771662, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7788823145281564}}
{"text": "\\section{Application: The matrix exponential}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute $e^A$, $\\sin A$, and $\\cos A$, for a square matrix $A$.\n  \\item Apply any analytic function to a square matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nFrom calculus, recall that a function is called \\textbf{analytic}%\n\\index{analytic function} if it can be defined by a power series. For example:\n\\begin{eqnarray*}\n  e^{x} &=& 1 + x + \\frac{1}{2}x^2 + \\frac{1}{3!}x^3 + \\frac{1}{4!}x^4 + \\ldots \\\\\n  \\sin x &=& x - \\frac{1}{3!}x^3 + \\frac{1}{5!}x^5 - \\frac{1}{7!}x^7 \\pm \\ldots \\\\\n  \\cos x &=& 1 - \\frac{1}{2}x^2 + \\frac{1}{4!}x^4 - \\frac{1}{6!}x^6 \\pm \\ldots\n\\end{eqnarray*}\nWe know from calculus that the above power series converge for all\nreal numbers $x$. Since it makes sense to compute the $n\\th$ power of\na square matrix, in principle it also makes sense to plug a matrix\ninto a power series. For a square matrix $A$, we can define\n\\begin{eqnarray*}\n  e^{A} &=& I + A + \\frac{1}{2}A^2 + \\frac{1}{3!}A^3 + \\frac{1}{4!}A^4 + \\ldots \\\\\n  \\sin A &=& A - \\frac{1}{3!}A^3 + \\frac{1}{5!}A^5 - \\frac{1}{7!}A^7 \\pm \\ldots \\\\\n  \\cos A &=& I - \\frac{1}{2}A^2 + \\frac{1}{4!}A^4 - \\frac{1}{6!}A^6 \\pm \\ldots\n\\end{eqnarray*}\nThe goal of this section is to investigate whether these power series\nconverge, and if yes, how to compute the sum of the series. We begin\nwith the case of a diagonal matrix.\n\n\\begin{example}{Exponential of a diagonal matrix}{exponential-diagonal}\n  Compute $e^{D}$, where\n  \\begin{equation*}\n    D = \\begin{mymatrix}{rr}\n      x & 0 \\\\\n      0 & y \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By definition,\n  \\begin{eqnarray*}\n    e^{D}\n    &=& I + D + \\frac{1}{2}D^2 + \\frac{1}{3!}D^3 + \\ldots \\\\\n    &=& \\begin{mymatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mymatrix}\n        + \\begin{mymatrix}{cc} x & 0 \\\\ 0 & y \\end{mymatrix}\n        + \\frac{1}{2}\\begin{mymatrix}{cc} x^2 & 0 \\\\ 0 & y^2 \\end{mymatrix}\n        + \\frac{1}{3!}\\begin{mymatrix}{cc} x^3 & 0 \\\\ 0 & y^3 \\end{mymatrix}\n        + \\ldots \\\\\n    &=& \\begin{mymatrix}{cc}\n      1 + x + \\frac{1}{2}x^2 + \\frac{1}{3!}x^3 + \\ldots & 0 \\\\\n      0 & 1 + y + \\frac{1}{2}y^2 + \\frac{1}{3!}y^3 + \\ldots \\\\\n    \\end{mymatrix} \\\\\n    &=& \\begin{mymatrix}{cc}\n      e^{x} & 0 \\\\\n      0 & e^{y} \\\\\n    \\end{mymatrix}.\n  \\end{eqnarray*}\n  Therefore, the exponential of a diagonal matrix is computed by\n  taking the exponential of each diagonal entry. Note that this\n  proves, in particular, that the sum converges.\n\\end{solution}\n\nThe same argument also works for applying other analytic functions to\ndiagonal matrices, for example:\n\\begin{eqnarray*}\n  \\sin\\begin{mymatrix}{cc} x & 0 \\\\ 0 & y \\end{mymatrix}\n  &=& \\begin{mymatrix}{cc} \\sin x & 0 \\\\ 0 & \\sin y \\end{mymatrix}, \\\\\n  \\cos\\begin{mymatrix}{cc} x & 0 \\\\ 0 & y \\end{mymatrix}\n  &=& \\begin{mymatrix}{cc} \\cos x & 0 \\\\ 0 & \\cos y \\end{mymatrix}.\n\\end{eqnarray*}\nBut how can we compute the matrix exponential of a non-diagonal\nmatrix?  This can be done by diagonalization. The following theorem\nshows how:\n\n\\begin{theorem}{Matrix functions by diagonalization}{matrix-exponential}\n  Suppose $A$ is a diagonalizable square matrix, with\n  $A=PDP^{-1}$. Then%\n  \\index{matrix!exponential of}%\n  \\index{matrix!sine and cosine of}%\n  \\index{exponential function!of a matrix}%\n  \\index{sine!of a matrix}%\n  \\index{cosine!of a matrix}\n  \\begin{eqnarray*}\n    e^{A} &=& Pe^{D}P^{-1}, \\\\\n    \\sin A &=& P(\\sin D)P^{-1}, \\\\\n    \\cos A &=& P(\\cos D)P^{-1}.\n  \\end{eqnarray*}\n\\end{theorem}\n\n\\begin{proof}\n  We have\n  \\begin{eqnarray*}\n    e^{A}\n    &=& I + A + \\frac{1}{2}A^2 + \\frac{1}{3!}A^3 + \\ldots \\\\\n    &=& I + PDP^{-1} + \\frac{1}{2}(PDP^{-1})^2 + \\frac{1}{3!}(PDP^{-1})^3 + \\ldots \\\\\n    &=& PIP^{-1} + PDP^{-1} + \\frac{1}{2}PD^2P^{-1} + \\frac{1}{3!}PD^3P^{-1} + \\ldots \\\\\n    &=& P(I + D + \\frac{1}{2}D^2 + \\frac{1}{3!}D^3 + \\ldots)P^{-1} \\\\\n    &=& Pe^{D}P^{-1}.\n  \\end{eqnarray*}\n  The proof for $\\sin$ and $\\cos$ is similar. Indeed, the same method\n  works for any analytic function.\n\\end{proof}\n\n\\begin{example}{A matrix exponential}{matrix-exponential}\n  Compute $e^{A}$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      -8 & 10 \\\\\n      -5 & 7 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We first diagonalize $A$. Following the usual method, we find that\n  the eigenvalues are $\\eigenvar=-3$ and $\\eigenvar=2$, with\n  corresponding eigenvectors\n  \\begin{equation*}\n    \\begin{mymatrix}{r} 2 \\\\ 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, we can diagonalize $A$ as $A=PDP^{-1}$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{rr} 2 & 1 \\\\ 1 & 1 \\end{mymatrix},\n    \\quad\n    D = \\begin{mymatrix}{rr} -3 & 0 \\\\ 0 & 2 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    P^{-1} = \\begin{mymatrix}{rr} 1 & -1 \\\\ -1 & 2 \\end{mymatrix}.\n  \\end{equation*}\n  By Theorem~\\ref{thm:matrix-exponential}, we have\n  \\begin{equation*}\n    e^{A}\n    = Pe^{D}P^{-1}\n    = \\begin{mymatrix}{rr} 2 & 1 \\\\ 1 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{cc} e^{-3} & 0 \\\\ 0 & e^2 \\end{mymatrix}\n    \\begin{mymatrix}{rr} 1 & -1 \\\\ -1 & 2 \\end{mymatrix}\n    = \\begin{mymatrix}{cc}\n      2e^{-3}-e^2 & -2e^{-3}+2e^2 \\\\\n      e^{-3}-e^2  & -e^{-3}+2e^2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "e5f36cc7dfcfd9cdb2c43cbfb103d5ea3d5618c8", "size": 5332, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Application-Exponential.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Application-Exponential.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Application-Exponential.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.7724137931, "max_line_length": 88, "alphanum_fraction": 0.5890847712, "num_tokens": 2148, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099167, "lm_q2_score": 0.9059898184796792, "lm_q1q2_score": 0.7788466052780396}}
{"text": "\\section{Factor Modeling}\n\nAt least in the context of mathematical finance, factor modeling is a technique to model a covariance-stationary multivariate timeseries $\\{\\mathbf{x_t} | \\mathbf{x_t} \\in \\mathbb{R}^m, t \\in 0,1,...,\\tau\\}$ in terms of a lower dimensional vector of  time-varying common factors $\\mathbf{f} \\in \\mathbb{R}^k$, and noise $\\epsilon \\in \\mathbb{R}^m$. A linear factor model takes the familiar form of a cross-sectional regression:\n\n\\begin{equation}\n\\mathbf{x_t} = \\mathbf{\\alpha} + \\mathbf{Bf_t}+ \\mathbf{\\epsilon_t}\n\\end{equation}\n\nWhere $\\mathbf{\\alpha} \\in \\mathbb{R}^{m \\times 1}$, $\\mathbf{B} \\in \\mathbb{R}^{m \\times k}$ and $\\mathbf{\\epsilon_t} \\in \\mathbb{R}^{m x\\times 1}$. So long as $\\mathbf{x}_t$ is covariance stationary, $\\mathbf{\\alpha}$ and $\\mathbf{B}$ can stay the same for all $t$, and the $k$-variate factors $\\mathbf{f_t}$ are also covariance stationary, with an, in general, non-diagonal covariance matrix. \n\nThe residuals $\\epsilon_t$ are $m$-variate white noise, which has zero mean and is uncorrelated across time and asset classes.\n\n\\begin{equation}\n\\begin{array}{l}\n\\mathbf{\\Omega_f} = \\mathrm{Cov}\\left[ \\mathbf{f_t} \\right]\\\\\n\\mathbf{\\Psi} = \\mathrm{Cov} \\left[ \\mathbf{\\epsilon_t} \\right] = \\mathrm{diag} \\left( \\sigma_1, ..., \\sigma_m \\right)\n\\end{array}\n\\end{equation}\n\nInstead of fitting the factor model cross-sectionally, i.e. across $m$ timeseries, it may also be fit as a time series regression, in which case the covariances are across different time steps of a single time series. The time series regressions for time series can also be grouped in a fashion that results in a factor model that includes both time delays and cross-asset correlations. The simplest canonical factor model is due to Sharpe (1970), which has a single factor, the \"market\". \n\n\\subsection{Comparison to Principal Components Regression}", "meta": {"hexsha": "01b6cf1142705efd4a1f2bce13d7aabdbf3f5ec6", "size": 1875, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/sup_factormodeling.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/sup_factormodeling.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/sup_factormodeling.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": 85.2272727273, "max_line_length": 489, "alphanum_fraction": 0.7338666667, "num_tokens": 553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7787449639512365}}
{"text": "\n\\subsection{Pooling layers}\n\nThe input is a matrix. We place a number of windows on the input matrix. The max of each window is an input to the next layer.\n\nMeans fewer parameters, easier to compute, less chance of overfitting\n\nParameters: height, width of window, stride (amount shifts by each window)\n\nWe can also add padding to the edge of the image so we don't lose data.\n\nSame padding (use 0), valid padding (no padding)\n\nPooling layer compresses, takes 2x2. Max pooling returns highest activiation\n\n", "meta": {"hexsha": "82506183bab4e48cf0bf9671a7c1a1f9aa365954", "size": 506, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworksConvolution/02-01-pooling.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/02-01-pooling.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/02-01-pooling.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.625, "max_line_length": 126, "alphanum_fraction": 0.7747035573, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.7787449455511802}}
{"text": "\\subsection{Bonus: Mobius Band and Stokes'}\r\nWe all know what a Mobius Band (or Mobius Strip) is.\r\nIn particular, it is not orientable since it only have one side.\r\nConsider $\\underline{F}=(-y,x,0)^\\top/(x^2+y^2)$, so $\\nabla\\times\\underline{F}=\\underline{0}$ whenever $x^2+y^2>0$.\r\nIf we are given the parameterization\r\n$$S=\\left\\{\\underline{x}(u,v)=\\begin{pmatrix}\r\n    (1+\\frac{v}{2}\\cos\\frac{u}{2})\\cos u\\\\\r\n    (1+\\frac{v}{2}\\cos\\frac{u}{2})\\sin u\\\\\r\n    \\frac{v}{2}\\sin\\frac{u}{2}\r\n\\end{pmatrix}:u\\in[0,2\\pi],v\\in[-1,1]\\right\\}$$\r\nThen if we apply Stokes' Theorem (which we should not), then\r\n$$0=\\int_S\\nabla\\times\\underline{F}\\cdot\\mathrm d\\underline{S}=\\oint_{\\partial S}\\underline{F}\\cdot\\mathrm d\\underline{x}$$\r\nBut the boundary, which is parameterized as\r\n$$[0,4\\pi]\\ni t\\mapsto \\begin{pmatrix}\r\n    (1+\\frac{1}{2}\\cos\\frac{t}{2})\\cos t\\\\\r\n    (1+\\frac{1}{2}\\cos\\frac{t}{2})\\sin t\\\\\r\n    \\frac{1}{2}\\sin\\frac{t}{2}\r\n\\end{pmatrix}$$\r\nThen we have\r\n$$\\oint_{\\partial S}\\underline{F}\\cdot\\mathrm d\\underline{x}=4\\pi\\neq 0$$\r\nContradiction.", "meta": {"hexsha": "98e52734b900bc77c1fe8ba0f8de5ac5df7bd222", "size": 1049, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/mobius.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/mobius.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/mobius.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": 49.9523809524, "max_line_length": 124, "alphanum_fraction": 0.6444232602, "num_tokens": 415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8397339716830605, "lm_q1q2_score": 0.7787384617607407}}
{"text": "\\newcommand{\\quotes}[1]{``#1''}\n\\section{Recommender Systems}\n\n\\subsection{K nearest neighbors}\n\nThe  $K$-Nearest Neighbor method makes use of ratings by  $K$  other \\quotes{similar} users when predicting  $Y_{ai}$ .\n\nLet  $KNN(a)$  be the set of  K  users \\quotes{similar} to user  $a$ , and let $sim(a,b)$ be a similarity measure between users  $a$  and  $b \\in KNN(a)$. The  K -Nearest Neighbor method predicts a ranking  $Y_{ai}$  to be :\n\n\\begin{align*}\n\\widehat{Y}_{ai} = \\displaystyle \\frac{\\displaystyle \\sum _{b \\in \\text {KNN}(a)} \\text {sim}(a,b) Y_{bi}}{\\displaystyle \\sum _{b \\in \\text {KNN}(a)} \\text {sim}(a,b)}.\n\\end{align*}\n\n \nThe similarity measure  $sim(a,b)$  could be any distance function between the feature vectors  $xa$ and  $x_b$  of users  $a$  and  $b$ , e.g. the euclidean distance  $\\left\\|  x_ a-x_ b \\right\\|$  and the cosine similarity  $c\\displaystyle \\cos \\theta = \\frac{x_ a\\cdot x_ b}{\\left\\|  x_ a \\right\\| \\left\\|  x_ b \\right\\| }$ . \n\n\n\\subsection{Collaborative Filtering}\n\nMatrix $Y$ with $n$ rows (users) and $m$ columns (Movies) is sparse (entries missing), $(a,i)$th  entry  $Y_{ai}$  is the rating by user  $a$  of movie  $i$ if this rating has already been given, and blank if not. Goal is to predict matrix $X$ with no missing entries.\n\nLet $D$  be the set of all $(a,i)$ 's for which a user rating  $Y_{ai}$  exists, i.e. $(a,i) \\in D$ if and only if the rating of user  $a$  to movie  $i$  exists.\n\n\n\\begin{align*}\n\\begin{split}\n\\displaystyle J &= \\sum _{(a,i) \\in D} \\frac{(Y_{ai} - \\big [UV^ T\\big ]_{ai})^2}{2} + \\\\\n& \\frac{\\lambda }{2} \\left(\\sum _{a,k} U_{ak}^2 + \\sum _{i,k} V_{ik}^2\\right)\n\\end{split} \\\\\nu&=\n\\begin{bmatrix}\nu_1\\\\\nu_2\n\\end{bmatrix};  \nv=\n\\begin{bmatrix}\nv_1\\\\\nv_2\\\\\nv_3\n\\end{bmatrix}\\\\\n\\textbf{Example:}\\\\\nv&=\n\\begin{bmatrix}\n2\\\\\n7\\\\\n8\n\\end{bmatrix}\\\\\nuv^T& = \\begin{bmatrix}\n2u_1 & 7u_1 & 8u_1\\\\\n2u_2 & 7u_2 & 8u_2\n\\end{bmatrix}\\\\\n\\end{align*}\n\nTake derivative of Objective function $J$ with respect to every user, set it to zero and find respective $u_i$ value:\n\n\\begin{align*}\n\\frac{d}{du_1}(J)=\\frac{d}{du_1}( \\frac{(7-8u_1)^2}{2} + \\frac{\\lambda}{2} u_1^2) = 0\\\\\n\\frac{d}{du_2}(J) = 0\\\\\nu_1 = \\frac{66}{\\lambda + 68};\nu_2 = \\frac{16}{\\lambda +53}\n\\end{align*}\n\nUse resulting values for $u$ to compute $uv^T$ compare resulting matrix $X$ with matrix $Y$ and start again. Continue until convergence.", "meta": {"hexsha": "912532f4d87c5a074a714c531be51fad41c677c4", "size": 2375, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/recommender.tex", "max_stars_repo_name": "sharov-am/MITx_capstone_2", "max_stars_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_stars_repo_licenses": ["MIT"], "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/recommender.tex", "max_issues_repo_name": "sharov-am/MITx_capstone_2", "max_issues_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_issues_repo_licenses": ["MIT"], "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/recommender.tex", "max_forks_repo_name": "sharov-am/MITx_capstone_2", "max_forks_repo_head_hexsha": "dfb1242b5984b29f0951ba9e14d96db9bf475d54", "max_forks_repo_licenses": ["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.6984126984, "max_line_length": 329, "alphanum_fraction": 0.6429473684, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317102, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.7787384582152282}}
{"text": "\n\\subsection{Bayesian optimisation}\n\n\\subsubsection{Introduction}\n\nIf we have sampled from the hyperparameter space we know something about the shape.\n\nCan we use this to inform where we should next look?\n\nThe shape of the function is \\(y=f(\\mathbf x)\\)\n\nWe have observations \\(\\mathbf X\\) and \\(\\mathbf y\\).\n\nSo what's our posterior, \\(P(y|\\mathbf X, \\mathbf y)\\)?\n\n\\subsubsection{Exploration and exploitation}\n\nThe can be a tradeoff between:\n\n\\begin{itemize}\n\\item Exploring - which gives us a better shape for \\(y=f(x)\\); and\n\\item Exploiting - which gives us a better estimate for the global optimum.\n\\end{itemize}\n\n\\subsubsection{The surrogate function}\n\nWe do not know \\(y=f(x)\\), but we model it as:\n\n\\(z(x)=y(x)+\\epsilon\\)\n\nWe can then maximise \\(z\\)\n\n\\subsubsection{Proposing new candidates}\n\nWe want an algorithm which maps from our history of observations to a new candidate.\n\nThere are different approaches:\n\n\\begin{itemize}\n\\item Probability of improvement - Choosing one with the highest chance of a more optimal value\n\\item Expected improvement - Choosing one with the biggest expected increase in the optimal value\n\\item Entropy search - choosing one which reduces uncertainty about the global maximum.\n\\end{itemize}\n\n", "meta": {"hexsha": "e389be7aa53733a8ac2fa0fdf5c1158f8ebe5832", "size": 1234, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/optimisation/02-01-bayesian.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/02-01-bayesian.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/02-01-bayesian.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.4222222222, "max_line_length": 97, "alphanum_fraction": 0.755267423, "num_tokens": 298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632976542184, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7787384558335558}}
{"text": "\\subsection{Trig Functions \\& The Unit Circle}\r\n\\noindent\r\nImagine aa circle of radius 1 centered at the origin that we'll call the unit circle. The x and y coordinates of a point on the unit circle are completely determined by the angle $\\theta$ in radians between the x-axis and a line from the origin to the point.\\\\\r\n\r\n\\noindent\r\nThe function $\\cos{\\theta}$ tells us x-coordinate of the point, while $\\sin{\\theta}$ tells us the y-coordinate of the point. The function $\\tan{\\theta} = \\frac{\\sin{\\theta}}{\\cos{\\theta}}$ tells us the slope of the line from the origin to the point. Most of the trig functions have geometric interpretations as shown below. The most used ones are $\\sin$, $\\cos$, $\\tan=\\frac{\\sin}{\\cos}$, $\\cot = \\frac{\\cos}{\\sin}$, $\\csc=\\frac{1}{\\sin}$, and $\\sec=\\frac{1}{\\cos}$.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{unitCircle}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.75\\textwidth]{./backgroundReview/algebraPreCalc/unitCircle2.png}\r\n\t\\caption{\\hyperref{https://en.wikipedia.org/wiki/Unit_circle}{}{}{Wikipedia - Unit circle}}\r\n\\end{figure}\r\n\r\n\\noindent\r\nWe can also think about the inverses of these trig functions. These are either notated with a -1 exponent on the function, or the prefix arc in front of the function name. Many of these functions are only defined on a part of the domain $\\left[0, 2\\pi\\right]$. Below is a table of the inverse trig functions and their domains.\r\n\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{l|l}\r\n\t\tFunction  & Domain                                                 \\\\ \\hline\r\n\t\t$\\arcsin$ & $\\left[-1, 1\\right]$           \t\t\t\t\t\t   \\\\\r\n\t\t$\\arccos$ & $\\left[-1, 1\\right]$                                   \\\\\r\n\t\t$\\arctan$ & $\\left(-\\infty, \\infty\\right)$                         \\\\\r\n\t\t$\\arccot$ & $\\left(-\\infty, \\infty\\right)$                         \\\\\r\n\t\t$\\arccsc$ & $\\left(-\\infty, -1\\right] \\cup \\left[1, \\infty\\right)$ \\\\\r\n\t\t$\\arcsec$ & $\\left(-\\infty, -1\\right] \\cup \\left[1, \\infty\\right)$\r\n\t\\end{tabular}\r\n\\end{table}\r\n", "meta": {"hexsha": "75e5e995a9a2f152dd2db28cfc8506365fbec31a", "size": 1985, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/algebraPreCalc/trigFunctionsUnitCircle.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/trigFunctionsUnitCircle.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/trigFunctionsUnitCircle.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": 66.1666666667, "max_line_length": 467, "alphanum_fraction": 0.6312342569, "num_tokens": 578, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206870747657, "lm_q2_score": 0.8633916047011594, "lm_q1q2_score": 0.7787107493266542}}
{"text": "\\section{Missing lemmas, $\\mathbf{RP}^n$ again, and even CW-complexes}\n\\begin{lemma}\nWe want to show that $ H_\\ast(X_n,X_{n-1})\\cong H_\\ast(X_n/X_{n-1},\\ast)$. We have the characteristic map $\\left(\\coprod_\\alpha D^n,\\coprod_\\alpha S^{n-1}\\right)\\to (X_n,X_{n-1})$, where the map $\\coprod_\\alpha S^{n-1}\\to X_{n-1}$ is the attaching map.\n\\begin{equation*}\n\\xymatrix{ H_\\ast(X_n,X_{n-1})\\ar[d]^\\cong & H_\\ast\\left(\\coprod_\\alpha D^n,\\coprod_\\alpha S^{n-1}\\right)\\ar[l]\\ar[d]^{\\cong,homework}\\\\\n H_\\ast(X_n/X_{n-1},\\ast) & H_\\ast\\left(\\bigvee_{\\alpha}S^n_\\alpha,\\ast\\right)\\ar[l]^\\cong}\n\\end{equation*}\n\\end{lemma}\nFor preparation, we will talk about ``strong deformation retracts''. For example, $S^{n-1}\\hookrightarrow D^n-\\{0\\}$. You just deform everything back radially.\n\\begin{definition}\nA subspace of a space $A$ inside $X$ is a \\emph{strong deformation retract} if there is a homotopy $h:X\\times I\\to X$ such that $h(x,0)=x$, $h(x,1)\\in A$, and $h(a,t)=a$ if $a\\in A$.\n\\end{definition}\n\\begin{example}\nFor example, for the map $S^{n-1}\\hookrightarrow D^n-\\{0\\}$ can be defined as $h(x,t)=(1-t)x+t\\frac{x}{||x||}$.\n\\end{example}\nA strong deformation retract is a homotopy equivalence, because we can just define the homotopy inverse to be $h(-,1)$. Then $A\\hookrightarrow X\\xrightarrow{h(-,1)}A$ is the identity, and $X\\xrightarrow{h(-,1)}A\\hookrightarrow X$ is homotopic to the identity.\n\\begin{example}\nThe map $\\coprod_\\alpha S^{n-1}_\\alpha\\xrightarrow\\coprod(D^{n-1}_\\alpha-\\{0\\})$.\n\\end{example}\nTerminology: if $X$ is a CW-complex with filtration $X_0\\subseteq X_1\\subseteq\\cdots\\subseteq X$. A choice of characteristic maps is a ``cell structure'' for $X$. Note that this isn't specified in the CW-structure.\n\n\\begin{proof}[Proof of the lemma]\nLet $X$ be a CW-complex, with a choice of a cell structure, say with characteristic maps $g_\\alpha:D^n_\\alpha\\to X_n$. Let $C_n=\\{g_\\alpha(0)|\\alpha\\in A_n\\}$. We know that $X_{n-1}\\hookrightarrow X_n-C_n$. We claim that this is a strong deformation retract. This follows from our observation that $\\coprod_\\alpha S^{n-1}_\\alpha\\xrightarrow\\coprod(D^{n-1}_\\alpha-\\{0\\})$ is a strong deformation retract. In particular, $X_{n-1}\\hookrightarrow X_n-C_n$ is a homotopy equivalence.\n\nFor example, consider the torus. If you look at the fundamental polygon, and remove a hole, you can retract everything back to the boundary.\n\nNow, we have:\n\\begin{equation*}\n\\xymatrix{ H_\\ast\\left(\\coprod_\\alpha D^n_\\alpha,\\coprod_\\alpha S^{n-1}_\\alpha\\right)\\ar[r]\\ar[d] & H_\\ast(X_n,X_{n-1})\\ar[d]\\\\\n H_\\ast\\left(\\coprod_\\alpha D^n_\\alpha,\\coprod_\\alpha (D^n_\\alpha-\\{0\\})\\right) & H_\\ast(X_n,X_n-C_n)}\n\\end{equation*}\nThe downwards arrows are isomorphisms because of strong deformation retractions, homotopy invariance, lexseq, and the 5-lemma. Recall that if $U\\subseteq A\\subseteq X$, then $ H_\\ast(X-U)\\cong H_\\ast(X,A)$ if $\\overline{U}\\subseteq \\mathrm{int}(A)$. Suppose we consider $X_{n-1}\\subseteq X_n-C_n\\subseteq X_n$. This is an excision because $X_{n-1}$ is already closed, and $X_n-C_n$ is already open. Then excision tells us that $ H_\\ast(X_n-X_{n-1},X_n-X_{n-1}-C_n)$. This means we can extend the diagram as follows.\n\\begin{equation*}\n\\xymatrix{ H_\\ast\\left(\\coprod_\\alpha D^n_\\alpha,\\coprod_\\alpha S^{n-1}_\\alpha\\right)\\ar[r]\\ar[d] & H_\\ast(X_n,X_{n-1})\\ar[d]\\\\\n H_\\ast\\left(\\coprod_\\alpha D^n_\\alpha,\\coprod_\\alpha (D^n_\\alpha-\\{0\\})\\right) & H_\\ast(X_n,X_n-C_n)\\\\\n H_\\ast(\\coprod_\\alpha(D^n_\\alpha-S^{n-1}_\\alpha),\\coprod_\\alpha(D^n_\\alpha-S^{n-1}_\\alpha-\\{0\\}))\\ar[r]\\ar[u]^\\cong & H_\\ast(X_n-X_{n-1},X_n-X_{n-1}-C_n)\\ar[u]^\\cong}\n\\end{equation*}\nThe left arrow on the second row is the excision from $\\coprod_\\alpha S^{n-1}_\\alpha\\subseteq \\coprod_\\alpha D^n_\\alpha-\\{0\\}\\subseteq \\coprod_\\alpha D^n_\\alpha$. The bottom right arrow is an isomorphism because $\\coprod_\\alpha(D^n_\\alpha-S^{n-1}_\\alpha),\\coprod_\\alpha(D^n_\\alpha-S^{n-1}_\\alpha-\\{0\\})\\to (X_n-X_{n-1},X_n-X_{n-1}-C_n)$ is a homeomorphism, and hence an isomorphism. This concludes the proof of the lemma.\n\\end{proof}\nNow for the second lemma\n\\begin{lemma}\nWe have:\n\\begin{equation*}\n\\xymatrix{\\ar[r]\\cdots & H_q(X_{q-1})\\ar[r]\\ar@{=}[d] & H_q(X_q)\\ar@{->>}[r]\\ar[d]^\\cong\\ar[drr] & H_q(X_{q+1})\\ar[r]^\\cong\\ar[dr] & H_q(X_{q+2})\\ar[d]\\ar[r]^\\cong & \\cdots\\ar[dl]\\\\\n& 0 & H_n(C_\\ast(X_n))\\ar@{=}[d] & & H_n(X) \\\\\n& & \\ker(C_n(X)\\xrightarrow{d}C_{n-1}(X))\\ar@{^(->}[d] & &\\\\\n& & C_n(X_n) & &}\n\\end{equation*}\nSo $ H_q(X_q)$ is free abelian. The lemma is that $ H_n(X_{n+1})\\to H_n(X)$ is an isomorphism.\n\\end{lemma}\nFor preparation, we'll talk about subcomplexes.\n\\begin{definition}\nLet $X$ be a CW-complex with a cell structure $\\{g_\\alpha:D^n_\\alpha\\to X_n|\\alpha\\in A_n\\}$. A subcomplex is a subspace $Y\\subseteq X$ such that for all $n$, there are $B_n\\subseteq A_n$ such that $Y_n=Y\\cap X_n$ is a CW-filtration for $Y$ with characteristic maps $\\{g_\\beta|\\beta\\in B_n\\}$.\n\\end{definition}\n\\begin{example}\n$X_n\\subseteq X$ is a subcomplex.\n\\end{example}\n\\begin{prop}[Bredon, p. 196]\nLet $X$ be a CW-complex with a chosen cell structure. Let $K\\subseteq X$ be compact. Then $K$ sits inside some finite subcomplex. \n\\end{prop}\n\\begin{remark}\nFor fixed cell structures, unions and intersections of subcomplexes are subcomplexes.\n\\end{remark}\n\\begin{proof}[Proof of lemma 2]\nLet's do surjectivity. Pick $c\\in Z_n(C_\\bullet)(X)$. Well, $c=\\sum c_i\\sigma_i$ where $\\sigma_i:\\Delta^n\\to X$. Since $\\Delta^n$ is compact, $\\sigma_i(\\Delta^n)$ is compact, and thus $\\bigcup\\sigma_i(\\Delta^n)$ is compact, and hence it lies in a finite subcomplex. Hence it sits in some $X_N$ for some $N$, possibly very large. Thus $c\\in S_n(X_N)\\subseteq S_n(X)$. It's still a cycle because it was a cycle before. (This is a stronger result, we've proved that cycles come from cycles). This is more than enough.\n\nLet's do injectivity. Let $c\\in Z_n(C_\\bullet)(X_{n+1})$. If $i_\\ast$ denotes the maps $ H_n(X_q)\\to H_n(X)$, then $i_\\ast c\\in Z_n(C_\\bullet)(X)$. Suppose there was $b$ such that $db=i_\\ast(c)$, so that $i_\\ast(c)=0$ in $ H_n(X)$. Well, $b=\\sum b_i \\tau_i$ where $\\tau_i:\\Delta^{n+1}\\to X$. Then $\\bigcup \\tau_i(\\Delta^{n+1})$ is compact, and thus sits inside $X_M$. So $b\\in S_{n+1}(X_M)$, so the equation $db=i_\\ast(c)$ is still true in $X_M$. So $[c]=0$ in $ H_n(X_M)$. It's not quite what I wanted.\n\nThis is good enough, because the maps $ H_n(X_{n+1})\\to H_n(X_{n+2})\\to \\cdots$ are all isomorphisms.\n\\end{proof}\nWe'll talk about real projective space next week.\n\\begin{remark}\nSuppose $X$ has only even cells. For example, $\\mathbf{CP}^n$, namely complex lines in $\\mathbf{C}^{n+1}$ through the origin, or $S^{2n+1}/v\\sim \\zeta z$ for any $\\zeta\\in \\CC$ such that $|\\zeta|=1$. I have a map $S^{2n-1}\\to \\mathbf{CP}^{n-1}$. We have:\n\\begin{equation*}\n\\xymatrix{S^{2n-1}\\ar@{^(->}[r]\\ar[d] & D^{2n}\\ar[d]\\\\\n\\mathbf{CP}^{n-1}\\ar@{^(->}[r] & \\mathbf{CP}^n}\n\\end{equation*}\nThe same argument that we had before for $\\mathbf{RP}^n$ show that the CW structure on $\\mathbf{CP}^n$ is $\\CP^0\\subseteq\\CP^1\\subseteq\\cdots\\subseteq\\CP^n$. So $\\CP^n=D^0\\cup D^2\\cup\\cdots\\cup D^{2n}$.\n\nAnyway, if you had $X$ only with even cells, then $C_{\\text{odd}}(X)=0$, so $ H_n(X)=\\begin{cases}C_n(X) & n=2k \\\\ 0 & n=2k+1\\end{cases}$. We've shown that:\n\\begin{equation*}\n H_k(\\mathbf{CP}^n)=\\begin{cases}\n\\Z & k=2n\\\\\n0 & k=2n+1\n\\end{cases}\n\\end{equation*}\n\\end{remark}\n", "meta": {"hexsha": "fa7bb35fd3675442222513df10aa54860353b70b", "size": 7366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-17-RPn.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-17-RPn.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-17-RPn.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": 83.7045454545, "max_line_length": 515, "alphanum_fraction": 0.6849036112, "num_tokens": 2727, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.7786872054155203}}
{"text": "\\lab{Filtering and Convolution}{Filtering and Convolution}\n\\objective{The Fourier transform reveals things about an audio signal that are not immediately apparent from the soundwave. In this lab we learn to filter noise out of a signal using the discrete Fourier transform, and explore the effect of convolution on sound files.}\n\n% TODO:\n%       - Address stereo vs. mono signals, especially for the convolution.\n\n\\section*{Cleaning up a Noisy Signal}\n\nListen to \\texttt{Noisysignal1.wav}.\nThis is a mono recording of a (probably familiar) voice with some annoying noise over it.\nThe plot of the soundwave isn't very descriptive; in fact, it looks like static.\nSee Figure \\ref{fig:noisysignal}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/noisy}\n\\caption{The plot of \\texttt{Noisysignal1.wav}.}\n\\label{fig:noisysignal}\n\\end{figure}\n\nHowever, if we take the Fourier transform of the signal, we see that the static in Figure \\ref{fig:noisysignal} is the result of some concentrated high frequency noise.\n(In this case, artificially added).\nSee Figure \\ref{fig:noisyspec}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/noisyspec}\n\\caption{Spectrum of \\li{Noisysignal1.wav}}\n\\label{fig:noisyspec}\n\\end{figure}\n\nThe noise can be removed by setting the coefficients of the high frequencies to zero.\nSince the discrete Fourier transform is symmetric, if we set coeffecient $j$ to $0$, then we must set coefficient $N - j$ to $0$ as well, where $N$ is the number of coefficients.\nThen we calculate the inverse Fourier transform to get a new, clean signal.\n\n\\begin{lstlisting}\n>>> rate,data = wavfile.read('Noisysignal1.wav')\n\n# Calculate the Fourier transform\n>>> fsig = sp.fft(data, axis = 0)\n\n# Coefficients 10000 to 20000 were chosen by inspecting the\n# plot of the Fourier transform.\n>>> for j in xrange(10000, 20000):\n...     # Set the chosen coefficients to 0\n...     fsig[j] = 0\n...     fsig[-j] = 0\n\n# Calculate the inverse Fourier transform, cast it as real,\n# and scale it to be compatible with the wavfile format.\n>>> newsig = sp.ifft(fsig)\n>>> newsig = sp.real(newsig)\n>>> newsig = sp.int16(newsig / sp.absolute(newsig).max() * 32767)\n\\end{lstlisting}\n\nNow we can save the resulting cleaned-up signal \\texttt{newsig} to a \\li{.wav} file.\nThe plot of the wave now reveals individual syllables as they are spoken.\nSee Figure \\ref{fig:cleansignal}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{figures/Cleanedsignal}\n\\caption{The plot of \\texttt{Noisysignal1.wav} after being cleaned.}\n\\label{fig:cleansignal}\n\\end{figure}\n\n% Problem 1: Clean up a noisy signal (The only thing we have to fear...)\n\\begin{problem}\nListen to \\texttt{Noisysignal2.wav}.\nYou will probably just hear noise.\nInspect the discrete Fourier transform to see where there is noise.\nRemove the noise using the technique described above in order to make the cleaned-up signal audible.\nWhat does the voice say?\nWho is the speaker?\n(If you don't know the answer to this last question, try a quick Google search.)\n\\end{problem}\n\nThe DFT is commonly used in sound filtering, though identifying the particular frequencies to zero out can be difficult.\n\n\\section*{Filtering and Convolution}\n\nThe DFT is useful for more than filtering noise out of a signal.\nSuppose we have a recording of musical piece played in a small carpeted room with essentially no acoustics (little or no echo), and suppose we would like to apply an effect to make it sound as if the piece were played in a large concert hall or some other room.\nThe DFT makes this possible when used together with the idea of \\emph{convolution}.\n\nWhen a balloon is popped in large room, although the sound of the actual pop only lasts a few milliseconds, the sound echoes about the room for up to several seconds.\nThis echoing sound is called an \\emph{impulse response} of the room, and is a way of approximating the acoustics of a room.\n\nSo first, we need a recording of how the room responds to a short pulse of sound.\nEffective ways of producing a loud sound approximating a pulse include firing a (blank) gunshot, popping a balloon, or, if neither of those are available, clapping the hands one time.\n\nRecall that we model sound with discrete samples of a soundwave in rapid succession.\nWhen these sounds are played back, the ear percieves them as a continuous soundwave.\nIn other words, sound playback is a series of pulses of varying intensities, similar to the pulse in an impulse response.\nIf we ``mix'' the individual sounds of an instrument in a carpeted room with the impulse response from a concert hall, then the new soundwave will sound as if the instrument is being played in the concert hall.\n\nSince audio needs to be samples frequently (44100 samples per second is standard) to create smooth playback, a recording of a song can be millions of samples.\nEach of these samples needs to be combined with the impulse response, which may be several seconds long.\nThis may be starting to seem computationally infeasible or at least very difficult.\nThe key is to recognize that this process can be described as a convolution: namely, the final sound is simply the convolution of the our original sound with the impulse response.\nWe can calculate convolutions quickly using the convolution theorem:\n\n\\[\\mathcal{F}(f \\ast g) = \\mathcal{F}(f)\\cdot\\mathcal{F}(g)\\]\n\nwhere $\\mathcal{F}$ is the Fourier Transform, $\\ast$ is convolution, and $\\cdot$ is component-wise multiplication.\nThus we calculate the convolution of two arrays by simply taking the Fourier transform of each, multiplying them pointwise, and then taking the inverse transform.\n\n% Problem 2 (Optional): Get a good ballon pop to convolve stuff with.\n\\begin{problem}\n(Optional)\\footnote{If the instructor does not require this problem then students may use the provided \\texttt{balloon.wav} file which contains the sound of a balloon pop in a large room.} Find a large room or area with good acoustics, and record (an approximation to) its impulse response using a balloon pop.\nTo record the sound, you will want to use at least a decent microphone.\nYou may want to record it using the program Audacity\\footnote{Audacity is free sound manipulation software and may be downloaded at http://audacity.sourceforge.net} and a laptop.\nIf you use a unidirectional microphone, be sure the microphone is pointing at the balloon when you pop it, so that the direct sound from the pop is picked up.\n(If you don't, the result will still be okay.\nHowever, after the convolution it will probably sound somewhat distant, as if we were standing somewhere where we couldn't hear the music directly.)\nIf you've chosen a good room, the response should be audible for at least a full second.\n\nInclude a plot of both the waveform and spectrum of the impulse response you recorded.\n\\end{problem}\n\n% Problem 3: Convolve the balloon pop with Chopin.\n\\begin{problem}\\label{convolution_problem}\nDownload and listen to the file \\texttt{chopin.wav}.\nYou will hear a piano being played in a dead room with little or no acoustics.\nUsing the Convolution Theorem, take the convolution of this signal with the impulse response recorded in the previous problem.\nThe convolution given in the theorem is \\emph{circular}, meaning that sounds at the end of the signal will tend to mix with sounds at the beginning of the signal.\nTo avoid this effect, add several seconds of silence to the end of \\li{chopin.wav} by appending zeroes to the end of the signal.\nAlso, keep in mind that the Convolution Theorem requires both signals to have the same length; therefore you will need to pad the smaller of your two signals (namely, the impulse response signal) with zeros in order to make it the same size as the other signal.\nThese zeros should be added to the middles of signals, as we need to maintain its symmetric structure.\nDescribe the resulting sound.\n\nTo summarize:\n\\begin{enumerate}\n\n\\item Read in \\texttt{chopin.wav} and the impulse response with \\li{wavfile},\n\\item Add several seconds of silence to the signal from \\texttt{chopin.wav},\n\\item Insert zeros into the middle of the impulse response transform so that it is the same length as,\n\\item Calculate the convolution of the signals,\n\\item And finally, calculate the inverse Fourier transform.\n\\end{enumerate}\n\n\\end{problem}\n\nIn some instances, a circular convolution is actually desirable.\nFor instance, an interesting effect is achieved by taking the circular convolution of a long segment of white noise with some other (shorter) sound.\nWe can create white noise using SciPy's \\li{random} module:\n\\begin{lstlisting}\n# Create 10 seconds of mono white noise.\nsamplerate = 22050\nnoise = sp.int16(sp.random.randint(-32767, 32767, samplerate * 10))\n\\end{lstlisting}\n\n% Problem 4: White noise.\n\\begin{problem}\nCreate white noise and listen to the resulting sound (\\textbf{CAUTION:} Turn your volume way down. It may be very very loud).\nThis kind of noise is called ``white\" because it contains all frequencies with the same strength, or rather, with the same expected strength (since the amplitude of a specific frequency is a matter of chance).\nIn order to see this, plot the spectrum of the noise.\n\\end{problem}\n\nNow can take the circular convolution of this noise with some other sound.\nFor instance, let's use \\texttt{tada.wav}.\nThe result is in \\texttt{tada-conv.wav}.\nWe notice that the original short sound has been sustained to an indefinite length.\nThe result is not a set of static tones, but rather a rich sound which preserves not only the tones, but the texture, of the original sound; you can hear different tones fluctuating randomly in amplitude over time.\nIf you were to play this \\texttt{tada-conv.wav} on repeat, you would find that, because we used a circular convolution, the sound loops seamlessly from the end back to the beginning; however, most sound players are not capable of doing this properly, so you will probably hear a break in the sound. To demonstrate the ``seamlessness\", we can paste together three copies of the sound consecutively:\n\n\\begin{lstlisting}\nrate, sig = wavfile.read('tada-conv.wav')\nsig = sp.append(sig, sig)\nsig = sp.append(sig, sig)\n\\end{lstlisting}\n\nListen to the resulting sound, and notice that we are not able to identify where the sound loops back to the beginning, because there is no break or click.\n\n% Useless old problem.\n\\begin{comment}\n\\begin{problem}\nRecord yourself singing a few notes (or, feel free to produce some other sound another way).\nTake the circular convolution of white noise with this recording.\nNow do it again using stereo white noise.\nThis is just like the mono white noise problem, but make the SciPy array in two dimensions.\nIt's no problem that your original recording will probably be mono; just make the left and right channels duplicate in the recording (but: be sure to use different left and right channels for the white noise).\nCan you hear any difference between the mono and stereo versions of the result?\n\\end{problem}\n\nFeel free to play around with this. The file \\texttt{guitar-conv.mp3} is a collage of sounds created using this technique (mostly using guitar samples). You could probably think of other lots of other things you can do with this.\n\\end{comment}\n\n", "meta": {"hexsha": "9319460ed706878864d29ae1bf978d977d4e05eb", "size": 11233, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2A/Fourier2-Convolution/Fourier2.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/Fourier2-Convolution/Fourier2.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/Fourier2-Convolution/Fourier2.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.4338624339, "max_line_length": 397, "alphanum_fraction": 0.7803792397, "num_tokens": 2626, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278757303677, "lm_q2_score": 0.8824278680004707, "lm_q1q2_score": 0.7786789490449327}}
{"text": "\\section*{Probability Modeling}\nAssumption: Data set is generated iid\\\\\nFind $h:X\\rightarrow Y$ that minimizes pred. error $R(h) = \\mathbb{E}_{x,y}[l(y;h(x))]$ \n$h^*(x) = \\mathbb{E}[Y|X=x]$ for $R(h) = \\mathbb{E}_{x,y}[(y-h(x))^2]$\nPred: $\\hat{y} = \\hat{\\mathbb{E}}[Y|X=x]$\n\n\\subsection*{Maximum Likelihood Estimation (MLE)}\nChoose a particular parametric form $\\hat{P}(Y|X,\\theta)$, then optimize the parameters using MLE.\n\n$\\theta^* = \\underset{\\theta}{\\operatorname{argmax}} \\hat{P}(y_1,...,y_n|x_1,...,x_n,\\theta) $\\\\\n$= \\underset{\\theta}{\\operatorname{argmax}} \\prod_{i=1}^n \\hat{P}(y_i|x_i, \\theta) \\text{\\quad (iid)}$\\\\\n$= \\underset{\\theta}{\\operatorname{argmin}} - \\sum_{i=1}^n log \\hat{P}(y_i|x_i,\\theta)$\\\\\n\n\\subsection*{Example: MLE for Linear Gaussian}\n$y_i \\sim \\mathcal{N} (w^T x_i, \\sigma^2):$\\\\\n$y_i = w^T x_i + \\epsilon_i, \\epsilon_i \\sim \\mathcal{N}(0, \\sigma^2)$\\\\\nMaximizing the log likelihood:\\\\\n$\\underset{w}{\\operatorname{argmax}} P(y_1,...,y_n|x_1,...,x_n,w)$\\\\\n%$= \\underset{w}{\\operatorname{argmax}} \\prod \\limits_i \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{1}{2} \\frac{(y_i-w^T x_i)^2}{\\sigma^2}}$\\\\\n$= \\underset{w}{\\operatorname{argmin}}  \\sum_i^n (y_i-w^Tx_i)^2$\n\n\\subsection*{Bias/Variance/Noise}\nPrediction Error = $Bias^2 + Variance + Noise$\n\n\\subsection*{Maximum a posteriori estimate (MAP)}\nIntroduce bias by expressing assumption through a Bayesian prior $w_i \\in \\mathcal{N}(0, \\beta^2)$\\\\\nBayes rule: $P(w|x,y) = \\frac{P(w|x) P(y|x,w)}{P(y|x)}$\\\\\n$ = \\frac{P(w) P(y|x,w)}{P(y|x)}$, we assume w is indep. of x.\n$ \\underset{w}{\\operatorname{argmax}} P(w|x,y)$\\\\ \n$= \\underset{w}{\\operatorname{argmin}} - log P(w) - log P(y|x,w) + const.$ \\\\\n$= \\underset{w}{\\operatorname{argmin}} \\frac{1}{2\\beta^2} ||w||_2^2 + \\frac{1}{2\\sigma^2} \\sum_{i=1}^n (y_i - w^Tx_i)^2$ \\\\\n$= \\underset{w}{\\operatorname{argmin}} \\lambda ||w||_2^2 + \\sum_{i=1}^n (y_i - w^Tx_i)^2$ , $\\lambda = \\frac{\\sigma^2}{\\beta^2}$\\\\\n($=\\underset{w}{\\operatorname{argmax}} P(w) \\prod_i P(y_i|x_i,w)$, assuming noise $P(y|x,w)$ iid Gaussian, prior $P(w)$ Gaussian)\n\n\\subsection*{Logistic Regression}\nLink function: $\\sigma(w^Tx) = \\frac{1}{1+exp(-w^Tx)}$ (Sigmoid)\\\\\nLogistic regression replaces the assumption of Gaussian noise by iid Bernoulli noise. Can naturally output probabilities.\\\\\n$P(y|x,w) = Ber(y; \\sigma(w^Tx)) = \\frac{1}{1+exp(-y w^T x)}$\\\\\n%$=\\begin{cases}\n%1/(1+exp(-w^Tx)) = \\sigma(w^T x)\\\\\n%\t\t1 - 1/(1+exp(-w^Tx)) = \\sigma (-w^T x)\\\\\n%\\end{cases}$\n%Learning: $w = \\underset{w}{\\operatorname{argmax}} P(w|x,y)$\\\\\n%Classification: Use $P(y|x,w) = \\frac{1}{1+exp(-yw^Tx)}$ and predict most likely class label.\n\n\\subsection*{Example: MLE for logistic regression}\n$\\underset{w}{\\operatorname{argmax}} P(y_{1:n}|w,x_{1:n})\\\\\n= \\underset{w}{\\operatorname{argmin}} - \\sum_{i=1}^n log P(y_i|w,x_i)\\\\\n= \\underset{w}{\\operatorname{argmin}} \\sum_{i=1}^n log(1+exp(-y_i w^T x_i))\\\\\n\\hat{R}(w) = \\sum_{i=1}^n log(1+exp(-y_i w^T x_i))$ (neg log l. f.)\n%negative log likelihood function\n\n%\\subsection*{Gradient for logistic regression}\n%Loss function $l(w) = log(1+exp(-yw^Tx))$\\\\\n%$\\nabla_w l(w) = \\frac{1}{1+exp(-yw^Tx)} exp(-yw^Tx) (-yx)$\\\\\n%$=\\frac{1}{1+exp(yw^Tx)} (-yx)$\\\\\n%$=P(Y = -y|w, x) (-yx)$\n\n\\subsection*{SGD for logistic regression}\n1. Initialize w; 2. For t=1,2,...\\\\\nPick data point $(x,y) \\in_{u.a.r} D$\\\\\nCompute probability of misclassification $\\hat{P}(Y = -y|w,x) = \\frac{1}{1+exp(yw^Tx)}$\\\\\nUpdate $w \\leftarrow w + \\eta_t y x \\hat{P}(Y = -y|w,x)$\n\n\\subsection*{Logistic regression and regularization}\n$s = ||w||_2^2$ L2 (Gaussian prior)/$|w||_1$ L1 (Laplace)\\\\\n$\\underset{w}{\\operatorname{min}} \\sum_{i=1}^n log(1+exp(-y_i w^T x_i)) + \\lambda s$\n\n\\subsection*{SGD for L2-regularized logistic regression}\nUpdate $w \\leftarrow w (1-2\\lambda \\eta_t) + \\eta_t y x \\hat{P}(Y = -y|w,x)$", "meta": {"hexsha": "80593099fc602b2e8c81f2393499a8d45411cfb0", "size": 3799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/ProbabilityModeling.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/ProbabilityModeling.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/ProbabilityModeling.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": 54.2714285714, "max_line_length": 138, "alphanum_fraction": 0.6285864701, "num_tokens": 1560, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096181702031, "lm_q2_score": 0.8499711718571775, "lm_q1q2_score": 0.778666765705759}}
{"text": "\\section{Cauchy-Schwarz Inequality}\n\n\t\\subsection{Theorem}\n\t\t\\begin{align}\n\t\t\t\\forall u, v \\in \\mathbb{R}^n |u \\cdot v| \\leq \\|u\\| \\cdot \\|v\\|\n\t\t\\end{align}\n  \n\t\\subsection{Proof}\n\t\n\t\tLet $tu + v$ be a family of vectors where t is in $\\mathbb{R}$.\n\t\n\t\t\\begin{align}\n\t\t\t\\forall w \\in \\mathbb{R}^n 0 \\leq w \\cdot w \\\\\n\t\t\t0 \\leq (tu + v) \\cdot (tu + v) \\\\\n\t\t\t0 \\leq tu \\cdot v  + 2u \\cdot v + v \\cdot tu + v \\cdot v \\\\\n\t\t\t\\forall a = u \\cdot u, b = 2u \\cdot v: 0 \\leq t^2\n\t\t\\end{align}\n\t\t\n\t//TODO CJB REREAD THE FIRST PAGE (having trouble in low light)\n\t\t\n\\section{Triangle Inequality}\n\n\t\\subsection{Definition}\n\t\n\t\t\\begin{align}\n\t\t\t\\|u+v\\| \\leq \\|u\\| + \\|v\\|\n\t\t\\end{align}\n\t\t\n\t\\subsection{Proof}\n\t\n\t\tWe show that $\\|u+v\\|^2 \\leq (\\|u\\| + \\|v\\|)^2$.\n\t\t\n\t\t\\begin{align}\n\t\t\t\\|u+v\\|^2 &= (u+v) \\cdot (u+v) = u \\cdot u + 2u \\cdot v + v \\dot v \\\\\n\t\t\t\t&= \\|u\\|^2 + 2u \\cdot v + \\|v\\|^2 \\\\\n\t\t\t\t&\\leq \\|u\\|^2 + 2\\|u \\cdot v \\| + \\|v\\|^2  \\\\\n\t\t\t\t&\\leq \\|u\\|^2 + 2\\|u|\\ \\|v\\| + \\|v\\|^2 & \\textrm{by Cauchy} \\\\\n\t\t\t\t&\\leq (\\|u\\| + \\|v\\|)^2\n\t\t\\end{align}\n\t\t\n\\section{Complex Numbers}\n\n\t\\subsection{Introduction}\n\t\n\t\tComplex numbers introduce a unit $i$ such that $i^2 = -1$ and generate a set of numbers called $\\mathbb{C}$.\n\t\tUsually complex numbers are represented as some combination $a + ib$ where $a, b \\in \\mathbb{R}$.\n\t\t\n\t\tIn complex space you can solve any polynomial equation and the number of solution is the degree \\footnote{No matter what people told me I found it hard to understand the importance of complex numbers, but it turns out they become really important in numerical analysis.  In stuff like predator-prey models, oscillations in population dynamics are results of complex eigenvalues.  You can determine whether or not the oscillations of such a population are stable by checking if the imaginary part of the complex values are positive or negative.  In black holes, everything spirals into the black hole along a circle, which can only mathematically be described using complex numbers.  It's surprisingly cool... gets a lot more cool with the stability of orbits for satellites.  You want a satellite to have a slightly unstable orbit so that it doesn't take much energy to shift the position of the satellite. -CJB}.\n\t\tIn complex space //TODO return to 1/0 section.\n\t\t\n\t\tA complex number is a pair of real numbers with operations \"+\" and \"*.\"\n\t\tThe following demonstrate how complex numbers operate.\n\t\t\\begin{align}\n\t\t\t(a,b) + (c,d) = (a+c, b+d) \\\\\n\t\t\t(a,b) * (c,d) = (ac - bd, ad + bc) \\\\\n\t\t\t(0,1) * (0,1) = (-1,0) = -(1,0) \\implies i^2 = 1 \\\\\n\t\t\ta(1,0) + b(0,1) = (a,b) = a + ib \\\\\n\t\t\\end{align}\n\t\t\n\t\t\n\t\tThe following demonstrates the logic of complex numbers.\n\t\t\\begin{align}\n\t\t\t(a+ib)(c+id) &=ac + aid + ibc + (ib)(id) \\\\\n\t\t\t\t\t&= ac + i(ad + bc) + i^2bd \\\\\n\t\t\t\t\t&= (ac - bd) + i(ad+bc)\n\t\t\\end{align}\n\t\t\n\t\\subsection{Definition}\n\t\n\t\tFormally:\n\t\t\\begin{align}\n\t\t\t\\forall a,b \\in \\mathbb{R}: z = a+ib \\\\\n\t\t\ta = realpart[z] = [Re(z)]\\\\\n\t\t\tb = imaginarypart[z] = [Im(z)]\n\t\t\\end{align}\n\t\t\n\\section{Complex Conjugation}\n\n\tThe complex conjugate of some complex number z is given by $\\overline{z} = a - ib$.\n\t\n\t\\subsection{Definitions}\n\t\n\t\t\\begin{itemize}\n\t\t\t\\item $z = a + ib, \\overline{z} = (a - ib)$\n\t\t\t\\item $z*\\overline{z} = (a+ib)(a-ib) = a^2 + b^2$\n\t\t\t\\item $|z| = \\sqrt{a^2 + b^2} = sqrt{z*\\overline{z}}$\n\t\t\\end{itemize}\n\t\t\n\t\\subsection{Theorems}\n\t\n\t\t\\begin{itemize}\n\t\t\t\\item $\\forall z*\\overline{z}: z*\\overline{z} \\in R$\n\t\t\t\\item $\\forall z*\\overline{z}: z*\\overline{z} \\geq 0$\n\t\t\t\\item $\\forall z \\in \\mathbb{C}, z \\neq 0: \\exists w \\in \\mathbb{C} \\mid zw =1$ \\\\\n\t\t\t\t\tProof:\n\t\t\t\t\t\\begin{align}\n\t\t\t\t\t\t&& z = a + ib, w = \\dfrac{a-ib}{a^2 + b^2} \\\\\n\t\t\t\t\t\tzw &= (a + ib)\\dfrac{a-ib}{a^2 + b^2} = \\dfrac{a^2 - aib + aib - iib^2}{a^2 + b^2} \\\\\n\t\t\t\t\t\t\t&= \\dfrac{a^2 + b^2}{a^2 + b^2} = 1\n\t\t\t\t\t\\end{align}\n\t\t\t\\item $|z_1z_2| = |z_1||z_2|$\\\\\n\t\t\t\t\tProof:\n\t\t\t\t\t$|z_1z_2| = (z_1z_2)(\\overline{z_1z_2}) = z_1z_2\\overline{z_1}\\overline{z_2} = z_1\\overline{z_1}z_2\\overline{z_2} = |z_1||z_2|$\n\t\t\\end{itemize}\n\t\n\t\n\t\\subsection{Visualisation}\n\t\t\n\t\tIn the complex plane, complex conjugate is a reflection in the x-axis.\n\t\t//TODO generate figures for description of complex conjugate as a reflection of the complex number\n\t\t\n\\section{Complex Spaces}\n\n\t$\\mathbb{C}^n$ is the complex n space that consists of n tuples of complex numbers.\n\tNumbers in $\\mathbb{C}^n$ can be added, scaled, and otherwise manipulated much like $\\mathbb{R}^n$.\n\t\n\t\\subsection{Definitions}\n\t \n\t \t\\subsubsection{Dot Product in $\\mathbb{C}^n$}\n\t \t\n\t\t\\begin{align}\n\t\t\t(z_1, \\ldots, z_2) \\cdot (w_1, \\ldots, w_n) = z_1\\overline{w_1} + \\ldots + z_n\\overline{w_n}\n\t\t\\end{align}\n\t\t\n\t\tThis agrees with the dot product on $\\mathbb{R}^n$, as $\\mathbb{R}^n$ is a subset of $\\mathbb{C}^n$.  For $\\mathbb{R}$, $a + 0i = a - 0i$, so the conjugate makes no difference.\n\t\t\n\t\\subsection{Theorems}\n\t\n\t\t\\subsubsection{$v \\cdot v$ is in $\\mathbb{R}^n$, and nonnegative; $v \\cdot v = 0 \\iff v = 0$}\n\t\tIf $v$ is $\\mathbb{C}^n$ then $v \\cdot v$ is in $\\mathbb{R}^n$, and nonnegative; $v \\cdot v = 0 \\iff v = 0$\n\t\t\t\t\\begin{align}\n\t\t\t\t\tv = (z_1, \\ldots, z_2) \\\\\n\t\t\t\t\tv \\cdot v = z_1\\overline{z_1} + \\ldots + z_n\\overline{z_n} \\\\\n\t\t\t\t\tz_k = a_k + ib_k \\\\\n\t\t\t\t\tz_k\\overline{z_k} = a_k^2 + b_k^2 \\\\\n\t\t\t\t\tv \\cdot v = a_1^2 + b_1^2 + \\ldots + a_n^2 + b_n^2\n\t\t\t\t\\end{align}\n\t\t\t\t\n\t\tThis implies $v \\cdot v$ is a non-negative i and 0 only if it equals 0 and it equals 0 only if $a_k = 0$ and $b_k = 0$ for all k between 1 and n.\n\t\tIn this case, v is 0.\n\t\t\n\\section{Matrices as Arrays}\n\n\tWe can look at matrices as arrays, where a matrix is an array with n rows each with m elements.\n\t\n\tThe shape of a matrix is defined by n and m.\n\tIf two matrices have the same shape they can be added, where each element of the matrices are added to the corresponding elements of the other matrix.\n\t\n\tScaling a matrix consists of multiplying each element by some scalar.\n\t\n\tMultiplying a matrix consists of multiplying each row by a corresponding column in the other matrix.\n\tIt's a little more complicated but presumably people are familiar with this from maths 133.\n\t\n\tThe transposed matrix consists of a matrix where each row and column index has been switched.\n\t\n\tThe matrix power is a matrix multiplied by itself some $n$ times.\n\t\n\t\\subsection{Matrix Multiplication}\n\t\n\t\t\\begin{align}\n\t\t\t(AB)C = A(BC) & \\textrm{associative} \\\\\n\t\t\tA(B+C) = AB + AC & \\textrm{distributive} \\\\\n\t\t\t(B+C)A = BA + CA \\\\\n\t\t\tAB \\neq BA\n\t\t\\end{align}\n\t\t\n\t\\subsection{Definitions}\n\t\n\t\t\t\\begin{description}\n\t\t\t\t\\item[square matrix] An n by n matrix.\n\t\t\t\t\\item[trace] The trace of a square matrix $A = [a_{ij}]$ is given by $tr(A) = \\sum_{i=1}^{n} a_{ii}$.\n\t\t\t\t\\item[identity matrix] The n by m identity matrix is the $I_n = [a_{ij}]$ where $\\forall i = j, a_{ij} = 1 \\wedge \\forall i \\neq j, a_{ij} = 0$\n\t\t\t\t\\item[Matrix Power] \n\t\t\t\t\t$\\forall square_matrix[A]\\ \\ A^0 = I \\\\\n\t\t\t\t\t\\forall invertible[A]\\ \\ A^{-1} = inverse[A]$\n\t\t\t\t\\item[Block Matrix] A matrix partitioned in submatrices.\n\t\t\t\t\\item[Linear Equation]  A linear equation with unknowns is an expression of the form $a_1x_1 + \\ldots + a_nx_n = b$ where some vector $a_n$ and the value $b$ are in some number system.\n\t\t\t\tA solution vector $x_n$ exists that satisfies this equation.\n\t\t\t\\end{description}\n\t\t\t\n\t\\subsection{Theorems}\n\t\t\n\t\t\\subsubsection{$A_{mn}I_n = A,\\ \\ I_nB_{nm} = B$}\n\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\sum_{k=1}^{n} a_{ik}I_{ik} = a_{ij}\n\t\t\t\\end{align}\n\t\t\t\n\t\t\\subsubsection{$A_{ik}B_{kj}$}\n\t\t\t\n\t\t\t\\begin{align}\n\t\t\t\t\\forall A_{ik}B_{kj} \\\\\n\t\t\t\tAB = [C_{ij}] \\\\\n\t\t\t\tC_{ij} = \\sum_{k = i}^{n} A_{ik}B_{kj}\n\t\t\t\\end{align}\n\t\t\n\t\t\t\n\t\\subsection{Note on Excluded Material}\n\t\n\t\tI have not included some theorems on addition and multiplication and the like.\n\t\tI also have not typeset notes on how to do proofs.\n\t\tThe assignments seem to do an excellent job of covering this material.\n\t\tShould I find the time (probably will), these will be typeset after the midterm to complete the notes properly.", "meta": {"hexsha": "0981c5dd512f60fa17d6d3d88e039cc54707f4f2", "size": 7956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/lecture_1.tex", "max_stars_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_stars_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-03T23:09:18.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-03T23:09:18.000Z", "max_issues_repo_path": "parts/lecture_1.tex", "max_issues_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_issues_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "parts/lecture_1.tex", "max_forks_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_forks_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.1921182266, "max_line_length": 915, "alphanum_fraction": 0.631850176, "num_tokens": 2882, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.7786000363452744}}
{"text": "\n\\subsection{Probability mass functions}\n\n\\(P(X=x)=P({\\omega |X(\\omega)=x})\\)\n\nFor discrete probability, this is a helpful number. For example for rolling a die.\n\nThis is not helpful for continuous probability, where the chance of any specific outcome is \\(0\\).\n\n", "meta": {"hexsha": "6b7e587a0a8cd6ee6b2bea141c1fb62c429f48e0", "size": 263, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityVariables/01-02-mass.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/probabilityVariables/01-02-mass.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/probabilityVariables/01-02-mass.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.3, "max_line_length": 98, "alphanum_fraction": 0.7338403042, "num_tokens": 63, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9294404018582427, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7785178315574958}}
{"text": "\\subsection{Lagrange polynomials}\\label{subsec:lagrange_polynomials}\n\n\\begin{definition}\\label{def:omega_polynomial}\n  Given distinct elements \\( x_0, \\ldots, x_n \\) of the field \\( \\BbbK \\), we form the polynomial\n  \\begin{equation*}\n    \\omega(X) \\coloneqq \\prod_{k=0}^n (X - x_j).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:omega_polynomial_derivative}\n  For the polynomial \\( \\omega \\) from \\fullref{def:omega_polynomial}, for \\( k = 0, \\ldots, n \\) we have\n  \\begin{equation*}\n    \\omega'(x_j) = \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (x_j - x_k),\n  \\end{equation*}\n  where \\( \\omega' \\) is the \\hyperref[def:algebraic_derivative]{algebraic derivative} of \\( \\omega \\).\n\\end{proposition}\n\\begin{proof}\n  Fix \\( k \\in \\{ 0, \\ldots, n \\} \\) and denote\n  \\begin{equation*}\n    q(X) \\coloneqq \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (X - x_j).\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    \\omega(X) = (X - x_k) q(X)\n  \\end{equation*}\n  so\n  \\begin{equation*}\n    \\omega'(X) = [q(X) + X q'(X)] - x_k q'(X) = q(X) + (X - x_k) q'(X).\n  \\end{equation*}\n\n  So for \\( x_k \\) we have\n  \\begin{equation*}\n    \\omega'(x_k) = q(x_k) = \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (x_k - x_j).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[Lagrange interpolation]\\label{thm:lagrange_interpolation}\n  Let \\( x_0, x_1, \\ldots, x_n \\) be pairwise distinct elements of \\( \\BbbK \\) and let \\( y_0, y_1, \\ldots, y_n \\) be arbitrary elements of \\( \\BbbK \\). Then there exists a unique \\hyperref[def:polynomial_algebra]{polynomial} \\( L(X) \\) of degree at most \\( n \\) such that \\( L(x_k) = y_k \\) for \\( k = 1, \\ldots, n \\).\n\\end{theorem}\n\\begin{proof}\n  \\SubProof{Proof of uniqueness} Suppose that \\( p, q \\) are polynomials of degree at most \\( n \\) that both satisfy \\( L(x_k) = y_k \\) for \\( k = 1, \\ldots, n \\). Their difference \\( p - q \\) is a polynomial of degree at most \\( n \\) that has \\( n + 1 \\) roots. By \\fullref{thm:def:integral_domain/root_limit}, \\( p - q = 0 \\).\n\n  \\SubProof{Proof of existence} We will construct the polynomial explicitly. Define the Lagrange basis polynomial\n  \\begin{equation*}\n    L(X) = \\sum_{m=0}^n y_m \\prod_{\\substack{j = 0 \\\\ j \\neq m}}^n \\frac {(X - x_j)} {(x_m - x_j)}.\n  \\end{equation*}\n\n  For \\( k = 0, 1, \\ldots, n \\) we have\n  \\begin{equation*}\n    L(x_k) = y_k \\underbrace{\\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n \\frac {(x_k - x_j)} {(x_k - x_j)}}_{1} + \\sum_{\\substack{m = 0 \\\\ m \\neq k}}^n y_m \\overbrace{\\frac{(x_k - x_m)}{(x_k - x_m)}}^{0} \\prod_{\\substack{j = 0 \\\\ j \\neq k \\\\ j \\neq m}}^n \\frac {(x_k - x_j)} {(x_m - x_j)} = y_k.\n  \\end{equation*}\n\n  Therefore, \\( L \\) is the desired polynomial.\n\\end{proof}\n\n\\begin{theorem}[Finite field Lagrange interpolation]\\label{thm:finite_field_lagrange_interpolation}\\mcite{MathOF:functions_over_finite_fields}\n  For a multivariate function \\( f: \\BbbF_q^n \\to \\BbbF_q \\) over the \\hyperref[thm:finite_fields]{finite field} \\( \\BbbF_q \\), there exists a unique multivariate polynomial \\( L(X_1, \\ldots, X_n) \\) such that\n  \\begin{itemize}\n    \\item For any sequence of values \\( x_1, \\ldots, x_n \\),\n    \\begin{equation*}\n      f(x_1, \\ldots, x_n) = L(x_1, \\ldots, x_n).\n    \\end{equation*}\n\n    \\item For every monomial \\( X_1^{\\gamma_n} \\cdots X_n^{\\gamma_n} \\) of \\( L \\), \\( \\gamma_i < q \\) for \\( i = 1, \\ldots, n \\).\n  \\end{itemize}\n\\end{theorem}\n\\begin{proof}\n  For any point \\( (x_1, \\ldots, x_n) \\in \\BbbZ_q^n \\), the characteristic polynomial\n  \\begin{equation*}\n    c(X_1, \\ldots, X_n) \\coloneqq \\prod_{i=0}^n \\parens*{ \\prod_{\\substack{m=0 \\\\ m \\neq x_i}}^{q - 1} \\frac {X_i - m} {x_i - m} }\n  \\end{equation*}\n  satisfies\n  \\begin{equation*}\n    c(y_1, \\ldots, y_n) = \\begin{cases}\n      1, &x_i = y_i \\T{for all} i = 1, \\ldots, n \\\\\n      0, &\\T{otherwise.}\n    \\end{cases}\n  \\end{equation*}\n\n  As in \\fullref{thm:lagrange_interpolation}, give us the desired polynomial, a linear combination of these basis polynomials with coefficients corresponding to the values of \\( f \\) give us the desired polynomial.\n\\end{proof}\n", "meta": {"hexsha": "1189be246f33aa459f5c38b6bc824d0442fa27d0", "size": 4037, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lagrange_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/lagrange_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/lagrange_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": 48.6385542169, "max_line_length": 328, "alphanum_fraction": 0.6274461234, "num_tokens": 1531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.7785014216635215}}
{"text": "\n\\subsection{Sesquilinear forms}\n\n\\subsubsection{Bilinear form recap}\n\nA bilinear form takes two vectors and produces a scalar from the underyling field.\n\nThe function is linear in addition in both arguments.\n\n\\(\\phi (au+x, bv+y)=\\phi (au,bv)+\\phi (au,y)+\\phi (x,bv)+\\phi (x,y)\\)\n\nThe function is also linear in multiplication in both arguments.\n\n\\(\\phi (au+x, bv+y)=ab\\phi (u,v)+a\\phi (u,y)+b\\phi (x,v)+\\phi (x,y)\\)\n\nThey can be represented as:\n\n\\(\\phi (u,v)=v^TMu\\)\n\n\\subsubsection{Sesquilinear forms}\n\nLike bilinear forms, sesquilinear are linear in addition:\n\n\\(\\phi (au+x, bv+y)=\\phi (au,bv)+\\phi (au,y)+\\phi (x,bv)+\\phi (x,y)\\)\n\nSesqulinear forms however are only multiplictively linear in the second argument.\n\n\\(\\phi (au+x, bv+y)=b\\phi (au,v)+\\phi (au,y)+b\\phi (x,v)+\\phi (x,y)\\)\n\nIn the first argument they are \"twisted\"\n\n\\(\\phi (au+x, bv+y)=\\bar ab\\phi (u,v)+\\bar a\\phi (u,y)+b\\phi (x,v)+\\phi (x,y)\\)\n\n\\subsubsection{The real field}\n\nFor the real field, \\(\\bar b = b\\) and so the sesqulinear form is the same as the bilinear form.\n\n\\subsubsection{Representing sesquilinear forms}\n\nWe can show the sesquilinear form as \\(v^*Mu\\)\n\n\\subsubsection{Stuff}\n\n\\(f(M)=f([v_1,v_2])\\)\n\nWe introduce \\(e_i\\), the element vector. This is \\(0\\) for all entries except for \\(i\\) where it is \\(1\\). Any vector can be shown as a sum of these vectors multiplied by a scalar.\n\n\\(f(M)=f([\\sum^m_{i=1}a_{1i}e_i,\\sum^m_{i=1}a_{2i}e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^mf([a_{1k}e_k,\\sum^m_{i=1}a_{2i}e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}f([a_{1k}e_k,a_{2i}e_i])\\)\n\nBecause this in linear in scalars:\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}^*a_{2i}f([e_k,e_i])\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}^*a_{2i}e_k^*Me_i\\)\n\n\\subsubsection{Orthonormal basis and \\(M=I\\)}\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}^*a_{2i}e_k^*Me_i\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}^*a_{2i}e_k^*e_i\\)\n\n\\(f(M)=\\sum_{k=1}^m\\sum^m_{i=1}a_{1k}^*a_{2i}\\delta_i^k\\)\n\n\\(f(M)=\\sum^m_{i=1}a_{1i}^*a_{2i}\\)\n\n", "meta": {"hexsha": "aab175dde27ad5e578363dacc2cf022fd3f2268b", "size": 1958, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/03-01-sesquilinearForms.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/03-01-sesquilinearForms.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/03-01-sesquilinearForms.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.9714285714, "max_line_length": 181, "alphanum_fraction": 0.6414708887, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768604361741, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7784378691230378}}
{"text": "\\section{Deterministic Annealing\n\\hfill\\normalfont\\sffamily (\\textit{\\rmfamily Z} is tractable)}\n\n\\emph{Lemma:}\\enspace\nfunc's $\\times$ domain $\\to$ domain $\\times$ co-dom.\\\\\n\\quad $\\textcolor{gray}{\\mathcal O(K^N) \\rightarrow\\,}\n\\highlight*{\\sum_c \\prod_i \\epsilon_{i, \\color{red} c(i)} = \\prod_i \\sum_k \\epsilon_{ik}}\n\\textcolor{gray}{\\,\\leftarrow \\mathcal O(NK)}$\n\n$p(c\\mid \\theta, X) = \\prod_{i\\leq N} p_i(c(i) \\mid \\theta,X)$\\\\\n\\quad where\\enskip $p_i(k\\mid \\theta, X) \\propto \\exp(-\\frac1T \\norm{x_i - \\theta_k}^2)$\n% $\\phantom{p(c\\mid \\theta, X)} = \\prod_{i\\leq N} \\frac{\\exp(-\\frac1T \\norm{\\bm x_i - \\theta_{c(i)}}^2)}{\\sum_{j\\leq K} \\exp(-\\frac1T \\norm{\\bm x_i - \\theta_j}^2)}$\n% $\\substack{~\\\\[10pt]\\textcolor{gray}{\\leftarrow Z(X)}}$\n\nMax. entr.\n$\\implies \\pderiv{\\log Z}{\\theta_k} = 0\n\\implies \\highlight*{\\theta_k^\\ast = \\frac{ \\sum_i p_i(k\\mid \\theta^\\ast, X) \\:\\cdot\\: \\bm x_i }{ \\sum_i p_i(k\\mid \\theta^\\ast, X) }}$\n\n\\begin{highlightbox}\n\\begin{itemize}\n    \\item[] do\n    \\begin{itemize}\n        \\item[]\n            \\vspace{-5pt}\n            \\textbf{E-step:\\;} $p_i(k\\vert \\theta\\ap{old}, X) = \\frac{\\exp\\paren*{ -\\frac1T \\norm{\\bm x_i - \\theta_k}^2 }}{\\sum_{j\\leq K} \\exp\\paren*{ -\\frac1T \\norm{\\bm x_i - \\theta_j }^2}}$\n            \\vspace{-5pt}\n        \\item[] \\textbf{M-step:} $\\theta_k \\leftarrow \\ldots$\n        \\item[] $\\theta\\ap{old} \\leftarrow \\theta$\n    \\end{itemize}\n    \\item[] until convergence of $\\theta$\n    \\item[] $\\theta_k \\leftarrow \\theta_k + \\epsilon$\n        {\\small\\enspace\\color{gray} (noise s.t. centroids can separate)}\n\\end{itemize}\n\\end{highlightbox}\n\n\\emph{Phase transitions:}\\enspace\nFor $T {\\to} \\infty$ :\\enspace $\\theta_k^\\ast = \\overline{\\bm X} \\enspace \\forall k\\leq K$\\\\\nOnce $T=2\\lambda\\ped{max}$, more centroids appear, where $\\lambda\\ped{max} = \\textrm{max. eigenvalue}$ of $\\frac1N \\bm X^\\top \\bm X$.\n\\enspace($\\bm x_i$'s row-wise)", "meta": {"hexsha": "5b64388eb6fdec70c802597f1600a5239152030a", "size": 1890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/SLT21/sections/05_deterministic_annealing.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/05_deterministic_annealing.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/05_deterministic_annealing.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.4615384615, "max_line_length": 191, "alphanum_fraction": 0.6185185185, "num_tokens": 736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148513, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7784092799373548}}
{"text": "\\subsection{Slant Asymptotes}\\label{subsec:SlantAsymptotes}\nSome functions may have slant (or {\\it oblique}) asymptotes, which are neither vertical nor horizontal. If\n\\[\\ds\\lim_{x\\to\\infty}\\left[f(x)-(mx+b)\\right]=0\\]\nthen the straight line $y=mx+b$ is a \\dfont{slant asymptote} to $f(x)$. Visually, the vertical distance between $f(x)$ and $y=mx+b$ is decreasing towards 0 and the curves do not intersect or cross at any point as $x$ approaches infinity. Similarly when $x\\to-\\infty$.\n\n\\begin{example}{Slant Asymptote in a Rational Function}{SlantAsymptRationalFunction}\nFind the slant asymptotes of $\\ds f(x)=\\frac{-3x^2+4}{x-1}$.\n\\end{example}\n\\begin{solution}\nNote that this function has no horizontal asymptotes since $f(x)\\to-\\infty$ as $x\\to\\infty$ and $f(x)\\to\\infty$ as $x\\to-\\infty$.\n\nIn rational functions, slant asymptotes occur when the degree in the numerator is one greater than in the denominator. We use long division to rearrange the function:\n\\[\\ds\\frac{-3x^2+4}{x-1}=-3x-3+\\frac{1}{x-1}.\\]\nThe part we're interested in is the resulting polynomial $-3x-3$. This is the line $y=mx+b$ we were seeking, where $m=-3$ and $b=-3$. Notice that\n\\[\\ds\\lim_{x\\to\\infty}\\frac{-3x^2+4}{x-1}-(-3x-3)=\\lim_{x\\to\\infty}\\frac{1}{x-1}=0\\]\nand\n\\[\\ds\\lim_{x\\to-\\infty}\\frac{-3x^2+4}{x-1}-(-3x-3)=\\lim_{x\\to-\\infty}\\frac{1}{x-1}=0.\\]\nThus, $y=-3x-3$ is a slant asymptote of $f(x)$.\n\\end{solution}\n\nAlthough rational functions are the most common type of function we encounter with slant asymptotes, there are other types of functions we can consider that present an interesting challenge.\n\n\\begin{example}{Slant Asymptote}{SlantOtherFunction}\nShow that $y=2x+4$ is a slant asymptote of $f(x)=2x-3^x+4$.\n\\end{example}\n\\begin{solution}\nThis is because  \n\\[\\lim_{x\\to -\\infty}[f(x)-(2x+4)]=\\lim_{x\\to -\\infty}(-3^x)=0.\\]\n\\end{solution}\n\nWe note that $\\lim_{x\\to \\infty}[f(x)-(2x+4)]=\\lim_{x\\to \\infty}(-3^x)=-\\infty$.\nSo, the vertical distance between $%\ny=f(x)$ and the line $y=2x+4$ decreases toward 0 only when $%\nx\\to -\\infty $ and not when $x\\to \\infty$. The graph of $f$\napproaches the slant asymptote $y=2x+4$ only at the far left and not at the\nfar right. One might ask if $y=f(x)$ approaches a slant\nasymptote when $x\\to \\infty$. The answer turns out to be no, but we\nwill need to know something about the relative growth rates of the\nexponential functions and linear functions in order to prove this.\nSpecifically, one can prove that when the base is greater than 1 the\nexponential functions grows faster than any power function as $x\\to\n\\infty$. This can be phrased like this: For any $a>1$ and any $n>0$,%\n\\begin{equation*}\n\\lim_{x\\to \\infty}\\frac{a^x}{x^n}=\\infty \\text{ and }%\n\\lim_{x\\to \\infty}\\frac{x^n}{a^x}=0.\n\\end{equation*}%\nThese facts are most easily proved with the aim of something called the L'H\\^{o}pital's Rule.", "meta": {"hexsha": "f0f126d0970f0c4b45a6e3bb22eb03855363504d", "size": 2834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3-limits/3-5-3-slant-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-3-slant-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-3-slant-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": 60.2978723404, "max_line_length": 267, "alphanum_fraction": 0.7124206069, "num_tokens": 985, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.77836340067619}}
{"text": "\n\\subsection{Independence and conditional independence}\n\n\\subsubsection{Independence}\n\n\\(x\\) is independent of \\(y\\) if:\n\n\\(\\forall x_i \\in x,\\forall y_j \\in y (P(x_i|y_j)=P(x_i)\\)\n\nIf \\(P(x_i|y_j)=P(x_i)\\) then:\n\n\\(P(x_i\\land y_j)=P(x_i).P(y_j)\\)\n\nThis logic extends beyond just two events. If the events are independent then:\n\n\\(P(x_i\\land y_j \\land z_j)=P(x_i).P(y_j \\land z_k)=P(x_i).P(y_j).P(z_k)\\)\n\nNote that because:\n\n\\(P(x_i|y_j)=\\dfrac{P(x_i\\land y_j)}{P(y_j)}\\)\n\nIf two variables are independent\n\n\\(P(x_i|y_j)=\\dfrac{P(x_i)P(y_j)}{P(y_j)}\\)\n\n\\(P(x_i|y_j)=P(x_i)\\)\n\n\\subsubsection{Conditional independence}\n\n\\(P(A\\land B|X)=P(A|X)P(B|X)\\)\n\nThis is the same as:\n\n\\(P(A|B\\land X)=P(A|X)\\)\n\n", "meta": {"hexsha": "96b4a44f97a9b645ebaee92126828a322257d705", "size": 697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityVariables/02-02-independence.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/probabilityVariables/02-02-independence.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/probabilityVariables/02-02-independence.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.3611111111, "max_line_length": 78, "alphanum_fraction": 0.649928264, "num_tokens": 268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9632305349799242, "lm_q2_score": 0.8080672181749421, "lm_q1q2_score": 0.7783550188623886}}
{"text": "\\documentclass[a4paper]{article}\n\n\\usepackage[english]{babel}\n\\usepackage[utf8x]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage[colorinlistoftodos]{todonotes}\n\n\\title{MATH 542 Homework 3}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\\section*{Problem 1}\n\nGiven: $A_{n\\times n}$ is idempotent $\\implies AA=A$; $P$ is non-singular and $C_{n\\times n}$ is orthogonal $\\implies CC^T=C^TC=I$\n\n\\subsection*{1.a}\n\\begin{align*}\n(I-A)(I-A) = I-A-A+AA\\\\\n&= I-2A+A\\ \\text{ using } AA=A\\\\\n&=I-A\n\\end{align*}\n\nHence $I-A$ is idempotent\n\n\\subsection*{1.b}\n\\begin{align*}\nA(I-A) &= A-AA\\\\\n&= A-A\\ \\text{ using } AA=A\\\\\n&=0\n\\end{align*}\n\nSimilarly,\n\\begin{align*}\n(I-A)A &= A-AA\\\\\n&= A-A\\ \\text{ using } AA=A\\\\\n&=0\n\\end{align*}\n\n\\subsection*{1.c}\n\\begin{align*}\n(P^{-1}AP)(P^{-1}AP)  &=P^{-1}APP^{-1}AP\\\\ \n&= P^{-1}AAP \\ \\text{since }PP^{-1}=I\\\\\n&= P^{-1}AP\\ \\text{ using } AA=A\\\\\n\\end{align*}\nHence $P^{-1}AP$ is idempotent\n\n\\subsection*{1.d}\n\\begin{align*}\n(C'AC)(C'AC) &=C'ACC'AC\\\\\n&= C'AAC \\text{ since } CC'=C'C=I\\\\\n&= C'AC \\ \\text{ using } AA=A\\\\\n\\end{align*}\n\n\\subsection*{1.e}\n$A$ is a projection matrix and $C'C=C'C=I$\nFor $C'AC$ to be a projection matrix $C'ACz=z\\ \\forall z \\in S$ for some vector space $S$\n\nFor some $z \\in S$:\n\\begin{align*}\nC'ACz &= C'Ay \\text{ where } y=Az\\\\\n&= C'Ay\\\\\n&= C'y\\text{ since $A$ is projection matrix }  \\\\\n&= C'Cz\\\\\n&= z\\ \\text{ since } C'C=I\n\\end{align*}\n\nThus, $C'ACz \\in S$ and $C'ACz=z$ and hence $C'AC$ is a projection matrix\n\n\\section*{Problem 2}\n\\subsection*{2.a}\n\n\\begin{align*}\nQ(x_1,x_2,x_3) &= 12x_1^2+3x_2^2+3x_3^2+2x_1x_2-10x_1x_3+4x_2x_3\\\\\n&= 3(2x_1+x_2+x_3)^2-(12x_1x_2+6x_2x_3+12x_1x_3)+2x_1x_2-10x_1x_3+4x_2x_3\\\\\n&= 3(2x_1+x_2+x_3)^2-10x_1x_2-2x_2x_3-22x_1x_3\\\\\n&= (x_1+x_2)^2+ 2(x_2+x_3)^2+(5x_1-x_3)^2-14x_1^2\\\\\n&=(x_1+x_2)^2+2(x_2+x_3)^2+x_3^2+11x_1^2-10x_1x_3\\\\\n&= (x_1+x_2)^2+2(x_2+x_3)^2+25(x_1-x_3/5)^2-14x_1^2\n\\end{align*}\n\nand hence $Q(x_1,x_2,x_3)$ is positive defnite, (the coefficient of the negative term(-$x_1^2$) is less than the positive coefficient of $x_1^2$\n\\subsection*{2.b}\n\\begin{align*}\nx'Ax=\\begin{pmatrix}x_1 & x_2 &x_3\\end{pmatrix}\\begin{pmatrix}\n2 & 1 & 2\\\\\n1 & 2 & 1\\\\\n2 & 1 & 4\\\\\n\\end{pmatrix}\\begin{pmatrix} x_1\\\\x_2\\\\x_3\n\\end{pmatrix}\\\\\n&= (2x_1+x_2+x_3)x_1+(x_1+2x_2+x_3)x_2+(2x_1+x_2+4x_3)x_3\\\\\n&= 2x_1^2+2x_2^2+4x_3^2+2x_1x_2+3x_1x_3+2x_2x_3\\\\\n&= (x_1+x_2)^2+(x_2+x_3)^2+(x_1+\\frac{3}{2}x_2)^2+\\frac{3}{4}x_2^2\\\\\n> 0\n\\end{align*}\n\n$A$ is positive definite\n\n\\subsection*{2.c}\n\n\\begin{align*}\nx'Ax=\\begin{pmatrix}x_1 & x_2 &x_3\\end{pmatrix}\\begin{pmatrix}\n1 & 2 & 3\\\\\n2 & 1 & 1\\\\\n3 & 1 & -2\\\\\n\\end{pmatrix}\\begin{pmatrix} x_1\\\\x_2\\\\x_3\n\\end{pmatrix}\\\\\n&= (x_1+2x_2+3x_3)x_1+(2x_1+x_2+x_3)x_2+(3x_1+x_2-2x_3)x_3\\\\\n&= x_1^2+x_2^2-2x_3^2+4x_1x_2+6x_1x_3+2x_2x_3\\\\\n&= (x_2+x_3)^2+3(x_1+x_3)^2+2(x_1+x_2)^2-6x_1^2-6x_3^2-4x_1^2-2x_2^2-6x_3^2\\\\\n\\end{align*}\n\n$A$ is neither positive definite nor positive semidefinite.\n\n\\section*{Problem 3}\n\n\\begin{align*}\n\\begin{pmatrix}\na & b\\\\\nc & d\\\\\n\\end{pmatrix}\\times \\begin{pmatrix}\na & b\\\\\nc & d\\\\\n\\end{pmatrix} &= \\begin{pmatrix}\n2 & -1\\\\\n-1 & 2\n\\end{pmatrix}\\\\\n\\begin{pmatrix}\na^2+b^2 & ac+bd\\\\\nac+bd & c^2+d^2\n\\end{pmatrix}&=\\begin{pmatrix}\n2 & -1\\\\\n-1 & 2\n\\end{pmatrix}\\\\\n\\end{align*}\n\n\\begin{align*}\na^2+b^2 &=2\\\\\nac+bd&=-1\\\\\nc^2+d^2&=2\n\\end{align*}\n\nLet $a=1,b=1$ $\\implies \\ c+d=1 $ \n\n\\begin{align*}\nc^2+d^2 &=2\\\\\nc^2+(-1-c)^2 & =2\\\\\n2c^2+2c-1 &=0\\\\\nc &= \\frac{-2\\pm\\sqrt{4+8}}{4}\\\\\nc &= \\frac{-1\\pm\\sqrt{3}}{2}\\\\\nd &= \\frac{-1\\pm\\sqrt{3}}{2}\n\\end{align*}\n\nand hence one possible $B$ is:\n\\begin{align*}\nB &=\\begin{pmatrix}\n1 & 1\\\\\n\\frac{-1-\\sqrt{3}}{2} & \\frac{-1+\\sqrt{3}}{2}\\\\\n\\end{pmatrix}\n\\end{align*}\n\n\\section*{Problem 4}\n$G=(X'X)^-$\n\nLet $Y=(X'X)$  to prove $GYG$ is symmetric we need to show $(GYG)^T=GYG$\n\nNOTE: $Y^T=(X^TX)^T=X^TX=Y$\n\nUsing $YGY=Y$, we get:\n\\begin{align*}\nYGY &= Y\\\\\nYGYG &= YG\\\\\n\\implies GYG=G\n\\end{align*}\n\nNow, again consider $YGY$ and take transpose on both sides:\n\n\\begin{align*}\n(YGY)^T &= Y^T\\\\\nY^TG^TY^T &= Y^T\\\\\nYG^TY &= Y \\text{ using } Y^T=Y\\\\\n\\implies G&=G^T \\ \\text{ since }YG^TY=YGY=Y \\text{Also see NOTE below}\n\\end{align*}\n\nNow consider $GYG$\n\n\\begin{align*}\n(GYG)^T &= G^TY^TG^T\\\\\n&= GYG \\ \\text{ using } G=G^T and Y=Y^T\n\\end{align*}\nNOTE: \n\\begin{enumerate}\n\\item \n\\end{enumerate}\nHowever, this case is only true for the case when $G=G^T$ i.e. the generalized inverse in unique. I could not prove it for the general case\n\nTo show $GYG$ is a generalized inverse of $Y$ we need to show $YGYGY = Y$\n\n\\begin{align*}\nY(GYG)Y &= YG(YGY)\\\\\n&= YGY\\ \\text{ using } YGY=Y, \\text{ G is generalised inverse of Y}\\\\\n&= Y\\ \\text{ using definition of generalised inverse for } G\n\\end{align*}\n$\\implies$ GYG is generalised inverse of $Y=X^TX$\n\n\\section*{Problem 5}\n\n\nGiven: $E[X]=1$ and $Var(X)=E[X^2]-E[X]^2 = 5$\nUsing $E[X]=1$ we get, $E[X^2]=5+E[X]^2=6$\n\n\\subsection*{5.a}\n\n\\begin{align*}\nE[(1+2X)^2] &= E[1+4X+4X^2]\\\\\n&= E[1]+E[4X]+E[4X^2]\\\\\n&= 1+4E[X]+4E[X^2]\\\\\n&= 1+4+4(6)\\\\\n&= 30\n\\end{align*}\n\n\\subsection*{5.b}\n\\begin{align*}\nvar(3+4X) &= Var(3) + Var(4X) + 2Cov(3,4X)\\\\\n&= 0 + 16Var(X) + 2(0)\\\\\n&= 80\n\\end{align*}\n\n\\end{document}", "meta": {"hexsha": "dd697334516b86170e2ce22cb129a1d4462edf4d", "size": 5133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW03/hw03.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/HW03/hw03.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/HW03/hw03.tex", "max_forks_repo_name": "saketkc/hatex", "max_forks_repo_head_hexsha": "c5cfa2410d47c7e43a476a8c8a9795182fe8f836", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2015-09-25T19:06:45.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T03:21:09.000Z", "avg_line_length": 22.3173913043, "max_line_length": 144, "alphanum_fraction": 0.6111435808, "num_tokens": 2583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976953003183444, "lm_q2_score": 0.8670357546485407, "lm_q1q2_score": 0.7783339221559641}}
{"text": "\n\\subsection{Perceptron (step function)}\n\n\\subsubsection{The function}\n\nIf the sum is above \\(0\\), \\(a(z)=1\\). Otherwise, \\(a(z)=0\\).\n\n\\subsubsection{The derivative}\n\nThis has a differential of \\(0\\) at all point except \\(0\\), where it is undefined.\n\n\\subsubsection{Notes}\n\nThis function is not smooth.\n\nThese is the activation function used in the perceptron.\n\nPerceptron data needs to be linearly separable to train.\n\nEven if linearly separable, doesn't necessarily get the best outcome?\n\n\\subsection{Perceptron}\n\nPerceptron: one node neural network. is one or zero depednign if weightd inputs enough. therefore is classiication\n\nIf error, update weights\n\nOnly works if linearly separable. ie can draw linear line completely separting all inputs\n\nNeural network has more layers\n\nWorks if data is linear\n\nHow to treat node inputs: raw, sigmoid, {0,1}\n\nFor all of these want the cost function have only one solution, like least squares doe. not guaranteed for all\n\nFor logistic, want to make it convex. loss = -log(f(x)) or -log(1-f(x)) depending on correct y. this is convex\n\nHow to create node inputs: sigmoid, binary cutoff\n", "meta": {"hexsha": "cdeea36188164ecfda79e289061df91c6f1fce92", "size": 1127, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glm/03-02-perceptron.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glm/03-02-perceptron.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glm/03-02-perceptron.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.487804878, "max_line_length": 114, "alphanum_fraction": 0.759538598, "num_tokens": 280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8670357460591569, "lm_q1q2_score": 0.7783339049530101}}
{"text": "\\section{Matrix Multiplication}\n\nGiven two matrices $\\mathbf{A}\\in\\mathbb{R}^{m \\times p }$ and $\\mathbf{B}\\in\\mathbb{R}^{p \\times n}$ with entries $a_{i,j}$ and $b_{i,j}$ in their $i$th row and $j$th column, the product $\\mathbf{C} \\in \\mathbf{AB}\\in\\mathbb{R}^{m \\times n}$ and with elements $c_{i,j} = \\sum_{k = 1}^{p} a_{i,k}b_{k,j}$.\n\nThere are two ways to interpret how the rows or columns of $\\mathbf{C}$ come about through this operation. The first is that a row or column vector in $\\mathbf{C}$ is formed by one of the matrices acting on an individual vector from the other matrix. The second is that a row of a column vector in $\\mathbf{C}$ is formed as the linear superposition of the vectors within one of the matrices, where the coefficients of the superposition are given by a row or a column within the other matrix.\n\nLet: \n\n\\begin{equation}\n\\mathbf{A} = \\left[\n\\begin{array}{ccc}\n\\vert & \\vert & \\vert \\\\\na^{(c)}_1 & a^{(c)}_2 & a^{(c)}_3\\\\\n\\vert & \\vert & \\vert \\\\\n\\end{array}\n\\right] =\n\\left[\n\\begin{array}{ccc}\n- & a^{(r)}_1 & - \\\\\n- & a^{(r)}_2 & - \\\\\n- & a^{(r)}_3 & - \\\\\n\\end{array}\n\\right] \n\\end{equation}\n\n\\begin{equation}\n\\mathbf{B} = \\left[\n\\begin{array}{ccc}\n\\vert & \\vert & \\vert \\\\\nb^{(c)}_1 & b^{(c)}_2 & b^{(c)}_3\\\\\n\\vert & \\vert & \\vert \\\\\n\\end{array}\n\\right] =\n\\left[\n\\begin{array}{ccc}\n- & b^{(r)}_1 & - \\\\\n- & b^{(r)}_2 & - \\\\\n- & b^{(r)}_3 & - \\\\\n\\end{array}\n\\right] \n\\end{equation}\n\n\\begin{equation}\n\\mathbf{C} = \\left[\n\\begin{array}{ccc}\n\\vert & \\vert & \\vert \\\\\nc^{(c)}_1 & c^{(c)}_2 & c^{(c)}_3\\\\\n\\vert & \\vert & \\vert \\\\\n\\end{array}\n\\right] =\\left[\n\\begin{array}{ccc}\n- & c^{(r)}_1 & - \\\\\n- & c^{(r)}_2 & - \\\\\n- & c^{(r)}_3 & - \\\\\n\\end{array}\n\\right] \n\\end{equation}\n\nbe the notation in terms of row and column vectors.\n\n\\subsubsection{Elementwise}\n$[\\mathbf{C}]_{i,j}$ is the dot product of the $i$th row vector of $\\mathbf{A}$ and the $j$ column vector of $\\mathbf{B}$.\n\n\\begin{equation}\nc_{i,j} = \\left[\\begin{array}{c} \\vert \\\\ a_i^{(r)}\\\\ \\vert \\end{array}\\right] \\cdot \\left[\\begin{array}{ccc} - &b_j^{(c)}& - \\end{array}\\right]\n\\end{equation}\n\n\\subsubsection{Columns of $\\mathbf{C}$}\n\nThe $j$th column of $\\mathbf{C}$ involves all of $\\mathbf{A}$ and only the $j$th column of $\\mathbf{B}$.\n\nThe $j$th column of $\\mathbf{C}$ is the matrix product of $\\mathbf{A}$ with the first column of $\\mathbf{B}$.\n\n\\begin{equation}\n\\left[\n\\begin{array}{c}\n\\vert\\\\\nc^{(c)}_j\\\\\n\\vert\n\\end{array}\n\\right]=\n\\left[\n\\begin{array}{ccc}\n- & a^{(r)}_1 & - \\\\\n- & a^{(r)}_2 & - \\\\\n- & a^{(r)}_3 & - \\\\\n\\end{array}\n\\right] \n\\left[ \\begin{array}{c} \\vert \\\\ b^{(c)}_j  \\\\ \\vert \\end{array}\\right]\n\\end{equation}\n\n\nThe $j$th column of the product $\\mathbf{C}$ is a linear superposition of the columns of $\\mathbf{A}$, with the coefficients given by the $j$th column of $\\mathbf{B}$.\n\n\n\\begin{equation}\n\\left[\n\\begin{array}{c}\t\n\\vert\\\\\nc^{(c)}_j\\\\\n\\vert\n\\end{array}\n\\right]=\n\\begin{array}{ccc}\n\\left[\\begin{array}{c} \\vert\\\\ a^{(c)}_1 \\\\ \\vert \\end{array}\\right]b^{(c)}_{1,j} \n+ \\left[\\begin{array}{c} \\vert\\\\ a^{(c)}_2 \\\\ \\vert \\end{array}\\right]b^{(c)}_{2,j} \n+ \\left[\\begin{array}{c} \\vert\\\\ a^{(c)}_3 \\\\ \\vert \\end{array}\\right]b^{(c)}_{3,j} \n\\end{array}\n\\end{equation}\n\n\n\n\\subsubsection{Rows of $\\mathbf{C}$}\nThe $i$th row of $\\mathbf{C}$ involves all of $\\mathbf{B}$ and only the $i$th row of $\\mathbf{A}$.\n\nThe $i$th row of $\\mathbf{C}$ is the matrix product of $\\mathbf{B}$ acting backwards on the $i$th row of $\\mathbf{A}$.\n\n\n\\begin{equation}\n\\left[\\begin{array}{ccc} - & c^{(r)}_i & - \\end{array}\\right] = \n\\left[\\begin{array}{ccc} - & a^{(r)}_i & - \\end{array}\\right] \n\\left[\n\\begin{array}{ccc}\n\\vert & \\vert & \\vert \\\\\nb^{(c)}_1 & b^{(c)}_2 & b^{(c)}_3\\\\\n\\vert & \\vert & \\vert \\\\\n\\end{array}\n\\right]\n\\end{equation}\n\nThe $i$th row of $\\mathbf{C}$ is a linear superposition of the rows of $\\mathbf{B}$, with the coefficients given by the $i$th row of $\\mathbf{A}$.\n\n\\begin{equation}\n\\begin{array}{rl}\n\\left[\\begin{array}{ccc} - & c^{(r)}_i & - \\end{array}\\right] = & a^{(r)}_{i,1} \\left[\\begin{array}{ccc} - & b^{(r)}_1 & - \\end{array}\\right]\\\\\n&+ a^{(r)}_{i,2} \\left[\\begin{array}{ccc} - & b^{(r)}_2 & - \\end{array}\\right]\\\\\n&+ a^{(r)}_{i,3} \\left[\\begin{array}{ccc} - & b^{(r)}_3 & - \\end{array}\\right]\n\\end{array}\n\\end{equation}\n\n\n\n\n", "meta": {"hexsha": "6ee6596b7def70dcd79080579ab938cbf43c3d42", "size": 4267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_matrixmultiplication.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/linalg_matrixmultiplication.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/linalg_matrixmultiplication.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.6319444444, "max_line_length": 491, "alphanum_fraction": 0.5985469885, "num_tokens": 1687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952811593496, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7783339040023007}}
{"text": "\\chapter{Hopfield Network}\nHopfield networks are recurrent neural networks with symmetric feedback connections. There are no self-feedback connections\n\n\\section{Energy minimizing Networks}\nOutput activation vector:\n$$\\mathbf{v} = (v_1 v_2 \\ldots v_n)^{T}$$\nThe network energy is critical and network output is optimum or reaches a stable condition when:\n$$Energy\\ gradient, \\nabla E(v) = 0$$\nHessian matrix is defined as:\n$$H = \\nabla^{2} E(\\mathbf{v})$$\nIf $H$ is \\emph{positive-definite}, then the energy is a \\emph{minimum}.\n\n\\section{Analysis of Hopfield Model}\n\\begin{figure}[!h]\n\\centering\n\\includegraphics{chapter6_1}\n\\end{figure}\nThe total synaptic input:\n\\begin{equation}\n\\begin{split}\nu_i &= \\sum_{j=1,j\\ne i}^{n} w_{ij} v_j + x_i -t_i \\\\\n&= \\mathbf{w^{T} v} + x_i - t_i\n\\end{split}\n\\label{hopfield_input}\n\\end{equation}\nRewritten in matrix notations:\n$$\\mathbf{u = W v + x - t}$$\nWhere matrix $\\mathbf{W}$ is called the connectivity matrix:\n$$ \\mathbf{W}\n\\begin{bmatrix}\n0 & w_{12} & \\cdots & w_{1n} \\\\\nw_{21} & 0 & \\cdots & w_{2n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nw_{n1} & w_{n2} & \\cdots & 0\n\\end{bmatrix}\n$$\n\\begin{center}where $w_{ij} = w_{ji}$ and $w_{ii} = 0$ \\end{center}\nThe unipolar Hopfield processing unit:\n$$v_{i} =\n\\begin{cases} \n    0 & u_i \\le 0 \\\\\n    1 & u_i > 0\n\\end{cases}\n$$\nThe bipolar Hopfield processing unit:\n$$v_{i} =\n\\begin{cases} \n    -1 & u_i \\le 0 \\\\\n    1 & u_i > 0\n\\end{cases}\n$$\n\n\\section{Updating Activation of Neurons}\nActivity of each neuron of the Hopfield network is usually updated in an asynchronous manner. \\\\\nThe energy of node $i$ is defined as:\n\\begin{equation*}\n\\begin{split}\nE_i &= -v_i u_i \\\\\n&= - v_i \\Big(\\sum_{j} w_{ij} v_j + x_i - t_i \\Big) \\\\\nE &= -\\frac{1}{2} \\sum_{i=1}^{n} \\sum_{j=1, i\\ne j}^{n} w_{ji} v_{i} v_{j} - \\sum_{i=1}^{n} x_i v_i + \\sum_{i=1}^{n} t_i v_i \\\\\n&= -\\frac{1}{2} \\mathbf{v^{T} W v - v^{T} x + v^{T}t} \\\\\n\\nabla E(\\mathbf{v}) &= \\frac{\\partial E(\\mathbf{v})}{\\partial \\mathbf{v}} \\\\\n&= \\mathbf{- Wv - x + t} \\\\\n\\Delta^{2} E(\\mathbf{v}) &= - W\n\\end{split}\n\\end{equation*}\n\n\\section{Convergence Analysis}\nIf there is no change in its state, then:\n$$\\Delta E_i = 0$$\nIf there is a change in its state, then\n\\begin{equation}\n\\begin{split}\n\\Delta E_i &= E_i^{new} - E_i^{old} \\\\\n&= - (v_i^{new} - v_i^{old}) u_i \\\\\n&= - \\Delta v_i u_i \n\\end{split}\n\\label{change_of_energy}\n\\end{equation}\nIf $v_i$ change from 0 to 1, then:\n$$\\Delta v_i = +1\\ and\\ u_i > 0$$\nSubstituting to \\ref{change_of_energy} yields $\\Delta E_i < 0$ \\\\ \\\\\nIf $v_i$ change from 1 to 0, then:\n$$\\Delta v_i = -1\\ and\\ u_i \\le 0$$\nSubstituting to \\ref{change_of_energy} yields $\\Delta E_i < 0$\n\n\\section{Hopfield Model Design}\n\n\\subsection{Solution by calculation}\nBy using \\ref{hopfield_input} and unipolar Hopfield processing unit, you will get several inequalities. From these inequalities, select one possible solutions. \\\\\n\\textit{Note: One of the problems in designing Hopfield network is false energy wells}\n\n\\subsection{Solution by learning}\nLet the set of $P$ training patterns be:\n$${\\mathbf{s}(1), \\mathbf{s}(2), \\ldots, \\mathbf{s}(P)}$$\n$$\\mathbf{s}(i) = s_1(p), s_2(p), \\ldots , s_n(p)$$\nTraining is done using \\emph{Hebbian learning rule}:\n$$w_{ij} = \\sum_{p=1}^{P} (2s_i(p) - 1)(2s_j(p) - 1)$$\n\\begin{center}for unipolar patterns \\end{center}\n\n$$w_{ij} = \\sum_{p=1}^{P} s_i(p) s_j(p)$$\n\\begin{center}for bipolar patterns \\end{center}\n\n\\noindent \\textit{Note: you still need to use inequalities to find the threshold $t$}", "meta": {"hexsha": "2e84ef4673881bab815eb20b884244a77fd8d3f9", "size": 3488, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter6.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": "chapter6.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": "chapter6.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.5384615385, "max_line_length": 162, "alphanum_fraction": 0.6605504587, "num_tokens": 1290, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7782634755028496}}
{"text": "%!TEX root = uber-driver-strategy.tex\n\\section{Problem Setup}\nConsider a finite horizon Markov decision process with finite decision horizon $T = \\{0,1,2, ..., N-1\\}$. At each stage, the driver occupies a state $i \\in \\mathcal{X}$, where $n = |\\mathcal{X}|$ is finite, and a driver is allowed to choose an action $a$ from finite set of allowable actions $\\mathcal{A} = \\{a_1, a_2, ..., a_m\\}$. The system starts in a given initial state $i_0$. The states make Markov transitions according to a collection of time-dependent transition matrices $\\tau := (P^{a}_t)_{a \\in \\mathcal{A}, t \\in \\mathcal{T}}$, the $n \\times n$ transition matrix $P^{a}_t$ contains the probabilities of transitioning under action $a$ at stage $t$. Let $\\pi = (\\textbf{a}_0, ..., \\textbf{a}_{N-1})$ denote a policy, where $\\textbf{a}_t(i)$ denotes the action of the driver while at state $i$ at time $t$. Define by $r_t(i,a)$, the reward corresponding to state $i$ and action $a$ at time $t$, and by $r_N$ the reward at the final stage (end of time). We assume that $r_t(i,a)$ is non-negative and finite (negative cost of take empty ride action can be accounted for by considering all the rewards relative to the highest negative cost of empty ride i.e., moving the zero to the left.)\n\nFor a given set of transition matrices $\\tau$, if $R_N(\\pi, \\tau)$ denotes the \\textit{expected total rewards} under the policy $\\pi$ and transition matrices $\\tau$, then,\n\\begin{eqnarray*}\nR_N(\\pi, \\tau) &:=& \\textbf{E}\\bigg(\\sum_{t=0}^{N-1} r_t(i_t,\\textbf{a}_t(i)) + r_N(i_N)\\bigg)\n\\end{eqnarray*}\nWhen the set of transition matrices $\\tau$ is known,  $R_N(\\pi, \\tau)$ maximising policy $\\pi$ can be found via dynamic programming algorithm, with a complexity of $O(mnN)$. The \\textit{nominal} problem giving the corresponding maximum expected total reward is,\n\\begin{eqnarray*}\n\\phi_N(\\Pi, \\tau) &:=& \\max_{\\pi \\in \\Pi} R_N(\\pi, \\tau),\n\\end{eqnarray*}\nwhere $\\Pi = \\mathcal{A}^{nN}$ is the entire policy space.\n\nIn our case, the transition matrix under each action $a$ and time $t$ is known to lie in some given subset $\\mathcal{P}^{a}_t$, where $\\mathcal{P}^{a}_t$ can be thought of as \\textit{sets of confidence} for the transition matrices. Given this uncertainty in the transition matrices, we are interested in maximising the lower bound on the expected total rewards for the driver. This leads to a game between the driver and \\textit{nature}, where the driver seeks to maximise the minimum expected reward, with nature being the minimizing player. Formally, \\textit{policy of nature} refers to specific collection of time-dependent transition matrices $\\tau = (P^{a}_t)_{a \\in \\mathcal{A}, t \\in \\mathcal{T}}$ chosen by nature, and the set of admissible policies of nature is $\\mathcal{T} := (\\otimes_{a \\in \\mathcal{A}} \\mathcal{P}^{a}_t)^N$. The maximum lower bound can be given by,\n\\begin{eqnarray}\n\\phi_N(\\Pi, \\mathcal{T}) &:=& \\max_{\\pi \\in \\Pi} \\min_{\\tau \\in \\mathcal{T}} R_N(\\pi, \\tau)\n\\end{eqnarray}\n\n\\section{Robust Finite Horizon Dynamic programming} \\label{section:robust-dynamic-programming}\n\nFor a given state $i \\in \\mathcal{X}$, action $a \\in \\mathcal{A}$ and $P^{a}_t \\in \\mathcal{P}^{a}_t$, we denote by $p^{a}_{i,t}$ the next-state distribution drawn from $P^{a}_t$ corresponding to state $i \\in \\mathcal{X}$, the $i$-th row of the matrix. Furthermore, we define $\\mathcal{P}^{a}_{i,t}$ as the projection of the set $\\mathcal{P}^{a}_{t}$ onto the set of $p^{a}_{i,t}$ variables. Using the robust dynamic programming theorem from \\cite{nilim2003robustness}, we can show that perfect duality holds, i.e.,\n\\begin{eqnarray}\n\\phi_N(\\Pi, \\mathcal{T}) = \\max_{\\pi \\in \\Pi} \\min_{\\tau \\in \\mathcal{T}} R_N(\\pi, \\tau) = \\min_{\\tau \\in \\mathcal{T}} \\max_{\\pi \\in \\Pi} R_N(\\pi, \\tau) = \\psi_N(\\Pi, \\mathcal{T})\n\\end{eqnarray}\nThe problem can be solved via recursion. The worst case optimal value function in state $i$ at time $t$, $v_t(i)$ is given by, \n\\begin{eqnarray}\nv_t(i) &=& \\max_{a \\in \\mathcal{A}} \\bigg(r_t(i,a) + \\sigma_{\\mathcal{P}^{a}_{i,t}}(v_{t+1})\\bigg), i \\in \\mathcal{X}, t \\in T\n\\end{eqnarray}\nwhere, $\\sigma_{\\mathcal{P}(v)} = \\inf\\{p^Tv : p \\in \\mathcal{P}\\}$. It should be noted in that solving $\\sigma_{\\mathcal{P}(v)} = \\inf\\{p^Tv : p \\in \\mathcal{P}\\}$ is the inner problem in every step of the above recursion. A corresponding optimal driver policy $\\pi^* = (\\textbf{a}^*_0, ..., \\textbf{a}^*_{N-1})$ is obtained by,\n\\begin{eqnarray}\n\\textbf{a}^*_t(i) &=& \\arg \\max_{a \\in \\mathcal{A}} \\bigg\\{r_t(i,a) + \\sigma_{\\mathcal{P}^{a}_{i,t}}(v_{t+1})\\bigg\\}, i \\in \\mathcal{X}\n\\end{eqnarray}\nFurthermore, the effect of uncertainty on some other policy $\\pi = (\\textbf{a}_0, ..., \\textbf{a}_{N-1})$ can be evaluated as follows,\n\\begin{eqnarray}\nv^{\\pi}_t(i) &=& r_t(i,\\textbf{a}_t(i)) + \\sigma_{\\mathcal{P}^{\\textbf{a}_t(i)}_{i,t}}(v^{\\pi}_{t+1}), i \\in \\mathcal{X}\n\\end{eqnarray}\n\n\\section{Likelihood Model} \\label{section:likelihood}\nWe use a likelihood constraint to describe the uncertainty in the transition matrix for the action $a$ (when driver takes a passenger ride). Let $F^{a}_t$ denote the matrix of observed frequencies of transitions in our data (in time slice centered around time $t$), and let $f^{a}_{i,t}$ be its $i$-th row. We have $F^{a}_t \\geq 0$ and $F^{a}_t\\textbf{1} = \\textbf{1}$, where \\textbf{1} denotes the vector of ones. For simplicity, let us assume that $F^{a}_t > 0$, which is same as assuming $f^{a}_{i,t} > 0$, $f^{a}_{i,t} \\in \\textbf{R}^n_+$ and $(f^{a}_{i,t})^T\\textbf{1} = 1$. To simplify the notation in this section, we shall drop the subscript $t$ denoting the time slice as we estimate the likelihood models independently for each time slice. Furthermore, we shall also drop the superscript $a$ denoting action, because there is uncertainty associated with only one of the actions in our model i.e, driver taking a passenger ride. \\hc{The other category of actions is `taking empty ride to some other state'. There is no uncertainty involved in the transition matrix coresponding to this action, as exactly one value in every row is exactly 1. Another type of action in flexible work schedule involves driver going offline in the system. Again, there is either no transition in this action, or taking a definite transition to home node of the driver.}Plug-in estimates for the transition matrix $P$ with uncertainty level $\\beta$ is given by,\n\\begin{eqnarray*}\n\\bigg\\{P \\in \\textbf{R}^{n \\times n}: P \\geq 0, P\\textbf{1} = \\textbf{1}, \\sum_{i,j}F(i,j)\\log P(i,j) \\geq \\beta \\bigg\\}\n\\end{eqnarray*}\nwhere $\\beta < \\beta_{max} = \\sum_{i,j}F(i,j)\\log F(i,j)$. From \\cite{lehmann2006testing}, for a $(1-U_L)$ level of confidence, $\\beta$ is solution of the equation,\n\\begin{eqnarray*}\n(1 - U_L) &=& F_{\\mathcal{X}^{2}_{n(n-1)}}(2(\\beta_{max} - \\beta))\n\\end{eqnarray*}\nwhere $F_{\\mathcal{X}^{2}_{d}}$ is the cumulative density function of the $\\mathcal{X}^2$-distribution with $d$ degrees of freedom. In the inner problem, we only need to work with uncertainty on each row $p_{i}$. Due to separable nature of the log-likelihood function, the projection of the above set onto the $p_{i}$ variables of the matrix $P$ can be given as,\n\\begin{eqnarray*}\n\\mathcal{P}_{i}(\\beta_i) &=& \\bigg\\{p \\in \\Delta^n: \\sum_{j}f_{i}(j)\\log p_{i}(j) \\geq \\beta_i \\bigg\\}\n\\end{eqnarray*}\nwhere,\n\\begin{eqnarray*}\n\\beta_i &=& \\beta - \\sum_{k \\neq i} \\sum_{j} F(k,j) \\log F(k,j). \\\\\n\\Delta^n &=& \\{p \\in \\textbf{R}^n_+ : p^T\\textbf{1} = 1\\}\n\\end{eqnarray*}\nIn the following section, as we deal with each row of the matrix separately, we drop the subscript $i$ in the observed frequencies $f_i$ and in the lower bound $\\beta_i$. Hence $\\beta_{max} = \\sum_{j} f(j)\\log f(j)$. We assume that $\\beta < \\beta_{max}$ along with $f > 0$. \\hc{Unsure what happens if we relax this constraint to $f \\geq 0$, which would be more appropriate in our cases, as during some time slices there no transitions to/from airport zone of the city.} Without loss of generality, we can also assume that $v \\in \\textbf{R}^n_+$.\n", "meta": {"hexsha": "8e7eb3f5fa8dd1b5899dad044f985bb4be8aa4e4", "size": 8016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/formulation/problem.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/problem.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/problem.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": 138.2068965517, "max_line_length": 1449, "alphanum_fraction": 0.6977295409, "num_tokens": 2615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7782224673416628}}
{"text": "\\section{Prob 4. b)}\n\nThe linear growth factor can be calculated indirectly from\n\\begin{equation}\\label{eq:1}\n    \\dot D(t) = \\frac{dD}{da} \\dot a, \n\\end{equation}\nwhere $\\dot a(z) = H(z)a(z)$. Plug in $\\dot a(z)$ and rewrite the equation with the chain rule, \\cref{eq:1} then becomes\n\\begin{equation}\\label{eq:2}\n    \\dot D(z) = \\frac{dD}{da} H(z) a(z) = \\frac{dD}{da} \\frac{H(z)}{1+z} = \\frac{dD}{dz} \\frac{dz}{da} \\frac{H(z)}{1+z},\n\\end{equation}\nwhere $a(z) = \\frac{1}{1+z}$. Take the derivative of $a$ with respect of $z$, we have\n\\begin{equation}\n    \\frac{da}{dz} = - \\frac{1}{(1+z)^2} \\quad\n    \\Rightarrow \\quad \\frac{dz}{da} = - (1+z)^2\n\\end{equation}\nThus, we can simplify \\cref{eq:2} to \n\\begin{equation}\\label{eq:4}\n    \\dot D(z) = - \\frac{dD}{dz} (1+z) H(z).\n\\end{equation}\nFrom part a) we get the linear growth factor and the Hubble parameter as a function, \n\\begin{gather}\n    D(z) = \\frac{5 \\Omega_m {H_0}^2 }{2} H(z) \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz' \\\\\n    H(z) = (\\Omega_m (1+z)^3 + \\Omega_{\\Lambda})^{1/2}.\n\\end{gather}\nTheir derivatives with respect to $z$ are then,\n\\begin{gather}\n    \\label{eq:7}\n    \\frac{dD}{dz} = \\frac{5 \\Omega_m {H_0}^2 }{2} [\\frac{dH(z)}{dz} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz' + H(z) \\frac{d}{dz} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz'] \\\\ \n    \\label{eq:8}\n    \\frac{dH}{dz} = \\frac{3 \\Omega_m (1+z)^2}{2[\\Omega_m (1+z)^3 + \\Omega_\\Lambda]^{1/2}}.\n\\end{gather}\nSubstitute \\cref{eq:7} and \\cref{eq:8} into \\cref{eq:4} and simplify, we get \n\\begin{equation}\\label{eq:9}\n\\begin{split}\n    \\dot D(z) &= - \\frac{5 \\Omega_m {H_0}^2 }{2} [\\frac{dH(z)}{dz} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz' + H(z) \\frac{d}{dz} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz'] (1+z) H(z) \\\\\n    &= - \\frac{5 \\Omega_m {H_0}^2 }{2}  (\\frac{3 \\Omega_m (1+z)^2}{2[\\Omega_m (1+z)^3 + \\Omega_\\Lambda]^{1/2}} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz' + \\\\\n    &\\qquad \\qquad \\qquad \\frac{(1+z)^2}{[\\Omega_m (1+z)^3 + \\Omega_\\Lambda]^{1/2}}) \\cdot (1+z) [\\Omega_m (1+z)^3 + \\Omega_\\Lambda]^{1/2} \\\\\n    &= - \\frac{5 \\Omega_m {H_0}^2 }{2} (\\frac{3 \\Omega_m (1+z)^3}{2} \\int_{z}^{\\infty} \\frac{1+z'}{H^3(z')} dz' + \\frac{(1+z)^2}{[\\Omega_m (1+z)^3 + \\Omega_\\Lambda]^{1/2}}).\n\\end{split}\n\\end{equation}\n\\cref{eq:9} is then what we need for the time derivative of the linear growth factor $D$ as a function of the redshift $z$. ", "meta": {"hexsha": "11391071e663e35377cd08fb66c9827128e17df3", "size": 2365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Hand_in_exercise_2/handin2_p4b.tex", "max_stars_repo_name": "rywjhzd/Numerical-Recipes-In-Astrophysics", "max_stars_repo_head_hexsha": "1f4bf40c504cd5f0117a9986c2756dcfd5bfc5c5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Hand_in_exercise_2/handin2_p4b.tex", "max_issues_repo_name": "rywjhzd/Numerical-Recipes-In-Astrophysics", "max_issues_repo_head_hexsha": "1f4bf40c504cd5f0117a9986c2756dcfd5bfc5c5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Hand_in_exercise_2/handin2_p4b.tex", "max_forks_repo_name": "rywjhzd/Numerical-Recipes-In-Astrophysics", "max_forks_repo_head_hexsha": "1f4bf40c504cd5f0117a9986c2756dcfd5bfc5c5", "max_forks_repo_licenses": ["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.6829268293, "max_line_length": 187, "alphanum_fraction": 0.5754756871, "num_tokens": 1046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7782215845956911}}
{"text": "\\section{Biogeochemical models \\label{sec:bio-intro}}\n\n\nIn this module, biogeochemical models are implemented,\nin a two-way coupled mode.\n\n\\subsection{Mathematical formulation}\\label{sec:bio-math}\n\nThe general structure of a biogeochemical model with\n$I$ state variables expressed as ensemble averaged\nconcentrations is given by the\nfollowing set of equations:\n\\begin{equation}\\label{FullSystem}\n  \\partial_t c_i + \\partial_z\n\\left(m_i c_i - K_V \\partial_z c_i\\right)\n=   P_i(\\vec{c}) -D_i(\\vec{c}), \\;\\; i = 1,\\ldots,I, \\quad j,k = 1,\\ldots,3,\n\\end{equation}\nwith $c_i$ denoting the concentrations of state variables.\nFurthermore, $m_i$ represents the autonomous motion of the ecosystem\ncomponent $c_i$ (e.g. sinking or active swimming),\nand $K_V$ represents the eddy diffusivity.\nThe source and sink terms of the ecosystem component\n$c_i$ are summarised in $P_i(\\vec{c})$ and $D_i(\\vec{c})$, respectively.\nFor three-dimensional models, advection with the flow field\nand horizontal advection would have to be accounted for additionally.\nIn many biogeochemical models, some of the state variables have positive\nlower limits. In order to account for this,\nwe defined all state variables as the difference between\nthe actual value and their lower limit, such that\n(for non-negative state variables only)\nthe model value $c_i$ represents a concentration of\n$c_i+c_i^{\\min}$ where $c_i^{\\min}$ is the lower limit of $c_i$.\n\nThe gradient term on the left hand side of (\\ref{FullSystem})\nis the total transport,\nfor which typically surface and bottom boundary conditions\n\\begin{equation}\nK_V\\partial_z c_i\\big|_{z=\\eta} = F^s_i,\\qquad\nK_V\\partial_z c_i\\big|_{z=-H} = -F^b_i,\n\\end{equation}\nwith surface and bottom fluxes, $F^s_i$ and $F^b_i$, respectively,\nare applied.\nThe right hand side denotes the reaction terms,\nwhich are composed of contributions\n$d_{i,j}(\\vec{c})$, which represent reactive fluxes from\n$c_i$ to $c_j$, and in turn, $p_{i,j}(\\vec{c})$ are reactive fluxes from\n$c_j$ received by $c_i$:\n\\begin{equation}\\label{eq:am:a}\nP_i(\\vec{c}) = \\sum^I_{j=1} p_{i,j}(\\vec{c}), \\;\\;\\;\\;\nD_i(\\vec{c}) = \\sum^I_{j=1} d_{i,j}(\\vec{c}),\n\\end{equation}\nwith $d_{i,j}\\geq 0$ for all $i,j$ and $p_{i,j}\\geq 0$\nfor all $i\\not= j$.\n\nWe basically consider two types of ecosystem models.\nIn the simple NPZ (nutrient-phytoplankton-zooplankton) type models\nall state variables are based on the same measurable unit\nsuch as [mmol N m$^{-3}$] for nitrogen-based models.\nIn such NPZ models the reactive terms do only exchange mass\nbetween state variables with\n\\begin{equation}\\label{eq:am:symmetry}\np_{i,j}(\\vec{c}) = d_{j,i}(\\vec{c}), \\quad \\mbox{ for } i \\not= j\n\\quad\\mbox{ and }\\quad\np_{i,i}(\\vec{c}) = d_{i,i}(\\vec{c})=0, \\quad \\mbox{ for } i = j.\n\\end{equation}\nNeglecting for a moment all transport terms, it is easily seen that this\nsimple type of\nmodel is conserving mass:\n\\begin{equation}\n\\begin{array}{l}\n\\displaystyle\nd_t\\left(\\sum_{i=1}^I c_i    \\right) =\n\\sum_{i=1}^I\\left( P_i(\\vec{c})- D_i(\\vec{c})\\right) =\n\\displaystyle\n\\sum_{i=1}^I\\sum_{j=1}^I\\left(p_{i,j}(\\vec{c}) - d_{i,j}(\\vec{c})\\right)\n= \\sum_{i=1}^I\\left(p_{i,i}(\\vec{c}) - d_{i,i}(\\vec{c})\\right)=0.\n\\end{array}\n\\end{equation}\nThe NPZD model (see section \\ref{sec:bio-npzd}) and the\n\\cite{Fashametal1990} model discussed in section \\ref{sec:bio-fasham}\nare such fully conservative models.\n\nIn many biogeochemical models most state variables are known to be positive\nor at least non-negative quantities. For non-negative initial conditions\n$c_i(0) \\geq 0$ one can easily show by a simple\ncontradiction argument that the condition\n\\begin{equation}\\label{eq:am:d1}\nd_{i,j}(\\vec{c}) \\longrightarrow 0 \\;\\; \\mbox{for} \\;\\; c_i \\longrightarrow 0\n\\end{equation}\nguarantees that the quantities\n$c_i(t) \\geq 0$, remain non-negative for all $t$.\nA typical example is $d_{i,j}(\\vec{c}) = f(\\vec{c}) c_i$ with a non-negative,\nbounded\nfunction $f$ which might depend on all $c_i$.\n\nHowever, for many applications such simple models are\ntoo restrictive. Often different spatial references\nare involved for the state variables, such as the\ndetritus concentration in the water column, measured in [mmol N m$^{-3}$]\nand the fluff layer concentration at the bed, measured in [mmol N m$^{-2}$].\nMany biogeochemical processes\ninvolve more than two substances such as the photosynthesis\nwhere different nutrients (e.g.\\ nitrate and phosphorus) are taken\nup by phytoplankta and oxygen is produced. The ratios between these\nsubstances dissipated or produced are usually fixed, in the example\nof photosynthesis uptake of 16 mmol m$^{-3}$ nitrate is\nconnected to an uptake of 1 mmol m$^{-3}$ phosphorus\nand a production of 8.125 mmol m$^{-3}$ oxygen.\n\nFor state variables which may\nbe negative (such as oxygen concentration\nwhich also includes oxygen demand units,\nall sink and source\nterms are added up in the production terms\n$p_{i,j}$, with a negative sign for the sink terms.\nFor the \\cite{Neumannetal2002} model discussed in sections\n\\ref{sec:bio-iow},\nfurther deviations from the conservation formulation are introduced since\nbiogeochemical reactions include substances which are not budgeted by the\nmodel (mostly because they are assumed to be not limiting).\nOne typical example is nitrogen fixated by blue-green algae which\nbuilds up biomass by using atmospheric nitrogen which is later recycled to\nnitrate. Such non-conservative terms are lumped into the diagonal terms\n$p_{i,i}$ and $d_{i,i}$.\n\n\\subsection{Numerical aspects}\\label{sec:bio-num}\n\nTwo basic aspects which are included in the mathematical formulation for\nthe biogeochemical equations discussed in section \\ref{sec:bio-math}\nare to be reproduced by the numerical methods applied: conservation and\npositivity. Another constraint for the choice\nof numerical methods is that they should be sufficiently stable and accurate.\nIn order to facilitate this, a split method is applied\nseparating the numerical solution of the transport part\n(advection, diffusion) and the reaction part.\nBy doing so, we take splitting errors into account which should however\nbe not significant as long as the typical reaction time scales are\nmuch longer than the constant model time step $\\Delta t$.\n\nIn the transport step\nin which the right hand side is set to zero,\nfinite volume discretisations\nare used such that conservation of mass is guaranteed.\nThe spatial discretisation is carried out by separating the water column\ninto $N$ not necessarily equidistant intervals of height $h_k$.\nThe state variables, represented by layer-averaged values,\nare located in the centres of these intervals, the advective and diffusive\nfluxes are located at the interfaces in between.\nThe transport step itself is subject to operator splitting.\nThe autonomous motion of the state variables (including sinking or\nrising due to negative or positive buoyancy, respectively)\nis discretised by means of\nTVD (Total Variation\nDiminishing) advection schemes, for which several choices are\navailable, see \\cite{Pietrzak98}.\nThese TVD schemes are positivity conserving due to their TVD\nproperty.\nThe most accurate among those\nschemes is the so-called\nPDM-limited P$_2$ scheme which has been described in detail\nby \\cite{Leonhard91}.\n\nFor the diffusion, a\ncentral in space scheme is used which is slightly biased towards\na backward in time scheme in order to avoid asymptotic instability\n(see \\cite{Samarskij84}). By doing so, positivity is obtained and the schemes\nare practically second order in time and space.\n\nWith the discretisations of the transport terms given above,\naccuracy, positivity and conservation of the state variables are\nguaranteed by means of standard schemes. For the reaction terms,\n\\cite{Burchardetal2003b} recently developed schemes which also fulfil these\nrequirements.\nDue to the operator split between transport and reaction terms,\nonly ordinary differential equations (ODEs)\nhave to be treated numerically for the latter terms.\nFor the case of conservative biogeochemical models with\n$p_{i,i}=d_{i,i}=0$, these schemes are identical to those given\nby \\cite{Burchardetal2003b}.\nFor $p_{i,i}\\not= 0$, some modifications are necessary.\nThree classes of schemes are considered:\nExplicit schemes such as the Euler-forward scheme and second- and\nfourth-order Runge-Kutta schemes (see section \\ref{sec:ode-solver}).\nThese schemes are known to be conservative, but for\nsufficiently large time steps they may compute negative values\nof state variables also for non-negative state variables.\nThis may be avoided by small time stepping, which however usually\nleads to an enormous increase of the computational effort such that\nthese schemes lose their practical relevance in this context.\nIn order to solve this problem,\n\\cite{Patankar80} had suggested the first-order in time\npositive definite scheme\n(\\ref{eq:am:patankar}), and \\cite{Burchardetal2003b} have extended this\nto second order, see (\\ref{eq:am:PRK}).\nHowever, these schemes are not conservative, since\nsource and sink terms are numerically treated in a different way.\nFully conservative and non-negative schemes in first- and second-oder\nin time have thus been suggested and tested for\nordinary differential equations by \\cite{Burchardetal2003b},\nwith $p_{i,i}=d_{i,i}=0$ in equations.\\ (\\ref{eq:am:MP}) and (\\ref{eq:am:MPRK})\nin section \\ref{sec:ode-solver}.\nThis equal numerical treatment of sources and sinks\nresults in implicit linear systems of equations.\nSince only ordinary differential equations are to be solved in each\ngrid point, these systems have small dimensions, for example $I=7$ for\nthe \\cite{Fashametal1990} model (see section \\ref{sec:bio-fasham}) and\n$I=10$ for the \\cite{Neumannetal2002} model \n(see section \\ref{sec:bio-iow}).\nThus, these linear systems may be directly solved\nby Gaussian elimination schemes.\nNevertheless, one can also employ iterative methods.\nEspecially for the linear system arising in the context of the present\ntype of equations it is proven in \\cite{Burchardetal2003b}\nthat the involved matrix is always non-singular and the\nstandard Jacobi-type method converge to the unique solution of the system.\nLater, \\cite{Bruggemanetal2005} found that the Modified Patankar\nschemes as described in equations (\\ref{eq:am:MP}) and (\\ref{eq:am:MPRK})\nare only conservative for systems with one model currency\n(e.g.\\ nitrogen in the model of \\cite{Fashametal1990}),\nbut do not conserve stoichiometric ratios, when several\nlimiting nutrients are present. To solve that problem,\n\\cite{Bruggemanetal2005} developed first- and second-order\nExtended Modified Patankar (EMP) schemes, which are\nstoiciometrically conservative and explicit, such that they do\nnot need to solve implicit systems of linear equations. \n\n\n\\subsection{Computational aspects}\\label{sec:bio-comp}\n\nThe computational structure of the coupled physical-biogeochemical\nmodel system implemented here\nhas been designed under consideration of various objectives. \nIn this section  \na description of the various design related decisions is given.\nThe major objectives are:\n\\begin{itemize}\n  \\item to provide a well-defined interface between the one-dimensional\n   physical model and a sufficiently generic biogeochemical model,\n  \\item to allow for easy extensions of the system with new \n     biogeochemical models without changing \n  the over-all structure, such as the \\cite{Fashametal1990} model\n  (see section \\ref{sec:bio-fasham}) and the \\cite{Neumannetal2002} model, \n  see section \\ref{sec:bio-iow}),\n  \\item to provide a number of solution methods for the 'process part' of the\n  biogeochemical model, i.e.\\ solvers for ordinary differential equations\n  as discussed in section \\ref{sec:bio-num} and section \\ref{sec:ode-solver},\n  \\item to obtain fast and efficient execution of the coupled model,\n  \\item to design the system in such a way that three-dimensional \n   models can easily be interfaced with it.\n\\end{itemize}\nFor the biogeochemical model,\nwe have adopted the same design strategy as has been used for the turbulence \nmodule of GOTM. The interface between an application using the turbulence\nmodule consists of two subroutine calls only: \\emph{init\\_turbulence()} and\n\\emph{do\\_turbulence()}. The subroutine \\emph{init\\_turbulence()} is\nresponsible for initialising the parameters of the turbulence module and  \ncalled as part of the \ninitialisation of the entire model. For the turbulence module the \ninitialisation includes reading \\emph{namelists} with the model configuration, \nallocating memory for all necessary variables and initialising \nthese variables with sensible values. \\emph{init\\_turbulence()} should only be\ncalled once during program execution and after this call all public and private\nvariables of the turbulence module should be in a \nconsistently initialised state.\nDuring the time integration of the model, \\emph{do\\_turbulence()} has to be\ncalled at each time step. It is called with a number\nof parameters to transfer information e.g.\\ from the mean-flow module \nto the turbulence module but also to receive the variables updated\nby the turbulence module.\n\nUsing the same strategy for the biogeochemical module \nhas some problematic implications which are described here.\nIn analogy to the turbulence\nmodule, the interface is given via the two subroutines \\emph{init\\_bio()} and \n\\emph{do\\_bio()}.\nThe major difference between the turbulence module and the \nbiogeochemical module\nin terms of implementation\nis that in the former the number of variables are known at compilation time\nand the dimensions are specified at run time where as in the latter both \nthe number of state variables and their dimension are known only at run time.\nThe general interface has to be able to handle not only the different \nbiogeochemical models implemented at present but also to provide a framework\nfor developing future models. There are two major\nitems to address: 1.\\ how to initialise the biogeochemical model and 2.\\ how to \nselect the right biogeochemical model during the time integration and use the \nselected ordinary differential equation (ODE) solver.\n\nTo solve the initialisation problem we have chosen a two-level initialisation\napproach.  At the first level variables not specific to any of the \nbiogeochemical \nmodels are initialised. The single most important variable during this \nphase is \\emph{bio\\_model}, which contains the identification number for all\nimplemented biogeochemical models. \nDepending on the value of \\emph{bio\\_model}, the second level\nof initialisation is started. At this level all model specific variables\n(such as process rates) are initialised.\nThe most important variable at the second\nlevel is $I$ (number of state variables). \nAfter this step, the system returns to the first level, and\nnow all information is available for allocating memory and initialising \nall variables. The most important data structure provided to the individual \nbiogeochemical models will briefly be mentioned here. $c_{i,k}$ \nwith $1\\leq i\\leq I$ and $1\\leq k\\leq N$ (number of vertical layers)\nis a two-dimensional array containing the concentrations of each \nvariable at each depth. $I$ is  \nsupplied by the individual biogeochemical model and $N$\nis transferred in the call to \\emph{init\\_bio()} from the physical model. \n\nAfter the initialisation, all variables are initialised in a common\ndata structure where the only link to the specific model is via \n\\emph{bio\\_model} and $I$. The next step is to design the actual\ntime integration in such a way that selected biogeochemical model \noperates on the \ncommon data structure using the selected ODE solver in a transparent way.\n\n\\begin{figure}\n\\begin{center}\n\\scalebox{0.5}{\\includegraphics{figures/structure_gotmbio.eps}}\n\\caption{\nThe structure of the \\emph{do\\_bio()} subroutine. This subroutine is responsible\nfor updating all variables in the biogeochemical model in question at each time-step.\n\\emph{do\\_bio()} essentially works as a wrapper around all biogeochemical models\nimplemented.\nThe hatched arrows from \\emph{process model} to \\emph{ODE solvers}\nindicate that between one and four calls \nof  \\emph{process model}\nper time step are performed, depending on the order of the chosen ODE solver.  \n}\\label{fig_bio_code}\n\\end{center}\n\\end{figure}\n\nFigure \\ref{fig_bio_code} shows a sketch of how this is organised in the\nmodel source code. \nThe sketch should be be read from left to right. At the left side we have \nthe interface \\emph{do\\_bio()}, which is the only connection to the\ncalling program. The next level shows a sequence of steps necessary to do the\ntime integration. It should be noted that not all biogeochemical \nmodels necessarily\nhave to execute all the steps, some models do e.g.\\\nnot need any surface fluxes or short-wave radiation.\nFor the diffusion/advection part a general subroutine is called\nwhich is also used by \nthe physical model. \nAfter having calculated $I_{PAR}$ and $B$ (see eqs.\\ (\\ref{Iz}) and\n(\\ref{B}),\nthe next step is the step at which the production and destruction terms\n($p_{i,j,k}$ and $d_{i,j,k}$)\nof the biogeochemical models are calculated. This is done via a call to \n\\emph{ode\\_solver()}. After the call to \\emph{ode\\_solver()}, $c_{i,k}$\nhas been updated with the new values of all variables in the\nbiogeochemical model. Which ODE solver to use is determined during the \ninitialisation phase (\\emph{ode\\_method}).\nIt should be noted\nthat for some of the solution methods the biogeochemical processes have to \nbe evaluated more than once. Instead of having \\emph{ode\\_solver()} being \nresponsible for calling the chosen biogeochemical model,\nan additional subroutine\nhas been introduced: \\emph{process\\_model}, is a simple\nwrapper routine calling the selected biogeochemical model.\n\nThe implementation of this biogeochemical module into three-dimensional models\nis straight-forward. The 3D model has to take care of storing all\nthree-dimensional state variables and calculate their advection with the\nmean flow and the horizontal diffusion.\nSettling, migration, vertical diffusion and the production/destruction\nprocesses are calculated by the biogeochemical module which has to be\ncalled by means of a loop over all horizontal grid boxes of the 3D\nmodel.\n\n\n\nThis text has been adapted from \\cite{Burchardetal05}.\n\n", "meta": {"hexsha": "57c0799f00b758ff32dc669b261b456e11f358b2", "size": 18217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/GOTM4.0/doc/bioIntro.tex", "max_stars_repo_name": "huyquangtranaus/schism", "max_stars_repo_head_hexsha": "077d2e71d5a5e4ed02a9dd4712eabc48f88b7477", "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/GOTM4.0/doc/bioIntro.tex", "max_issues_repo_name": "huyquangtranaus/schism", "max_issues_repo_head_hexsha": "077d2e71d5a5e4ed02a9dd4712eabc48f88b7477", "max_issues_repo_licenses": ["Apache-2.0"], "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/GOTM4.0/doc/bioIntro.tex", "max_forks_repo_name": "huyquangtranaus/schism", "max_forks_repo_head_hexsha": "077d2e71d5a5e4ed02a9dd4712eabc48f88b7477", "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.5786666667, "max_line_length": 85, "alphanum_fraction": 0.7834989296, "num_tokens": 4627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632343454895, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.778219085228001}}
{"text": "\n\\subsection{Positive-definite matrices}\n\nThe matrix \\(M\\) is positive definite if for all non-zero vectors the scalar is positive.\n\n\\(v^TMv\\)\n\nWe know that the outcome is a scalar, so:\n\n\\(v^TMv=(v^TMv)^T\\)\n\n\\(v^TMv=v^TM^Tv\\)\n\n\\(v^T(M-M^T)v=0\\)\n\n", "meta": {"hexsha": "fd8e48537242449fe375c975e4bdd8dc558af9cd", "size": 246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/04-04-positiveDefinite.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/04-04-positiveDefinite.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/04-04-positiveDefinite.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.375, "max_line_length": 89, "alphanum_fraction": 0.662601626, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9518632234212402, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7782190762966137}}
{"text": "\\section{Central Limit Theorem}%\n\\label{sec:central_limit_theorem}\n\n\\begin{thm}\n    If $X_1 \\ldots X_n$ iid, $\\E X_i = \\xi$, $\\Var X_i = \\sigma^2 < \\infty$, then\n    \\begin{equation*}\n        \\sqrt{n} (\\bar{X} - \\xi) \\convl N(0, \\sigma^2).\n    \\end{equation*}\n\\end{thm}\n\n\\begin{thm}[Berry-Esseen]\n    If $X_1 \\ldots X_n$ iid $\\sim F$ with finite 3rd moment, then $\\exists C$\n    that is independent of $F$ such that for all $x$,\n    \\begin{equation*}\n        |G_n(x) - \\Phi| \\le \\frac{C}{\\sqrt{n}} \\frac{\\E |X_i - \\xi|^3}{\\sigma^3}\n    \\end{equation*}\n    where $G_n(x)$ is the CDF of $\\sqrt{n} (\\bar{X} - \\xi) / \\sigma$.\n\\end{thm}\n\n\\begin{corollary}\n    Under the assumptions of Berry-Esseen's theorem,\n    \\begin{equation*}\n        G_n(x) \\to \\Phi(x) \\text{ as } n \\to \\infty\n    \\end{equation*}\n    for any sequence $F_n$ with mean $\\xi_n$ and $\\sigma_n^2$ for which\n    \\begin{equation*}\n        \\frac{E_n |X_1 - \\xi_n|^3}{\\sigma_n^3} = o(\\sqrt{n})\n    \\end{equation*}\n    and in particular if it is bounded.\n\\end{corollary}\n", "meta": {"hexsha": "492b1c0423309e0563b6c8b77772555330507ea0", "size": 1029, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "statistics/inference/src/03-central-limit-theorem.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/03-central-limit-theorem.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/03-central-limit-theorem.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": 33.1935483871, "max_line_length": 81, "alphanum_fraction": 0.5908649174, "num_tokens": 401, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595115, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7781867772940716}}
{"text": "\\section{Stochastic Boolean satisfiability}\n\\label{sect:background-ssat}\n\nAn SSAT formula $\\Qf$ over variables $\\{x_1,\\ldots,x_n\\}$ has the form:\n$Q_1x_1,\\ldots,Q_nx_n.\\pf$,\nwhere each $Q_i\\in\\{\\exists,\\random{p}\\}$ and $\\pf$ is quantifier-free.\nSymbol $\\exists$ denotes an existential quantifier with its conventional semantics.\nSymbol $\\random{p}$ denotes a randomized quantifier~\\cite{Papadimitriou1985}, which requires\nthe quantified variable to evaluate to $\\top$ with probability $p\\in[0,1]$.\nGiven an SSAT formula $\\Qf$, the quantification structure $Q_1 x_1, \\ldots, Q_n x_n$ is called the \\emph{prefix},\nand the quantifier-free Boolean formula $\\phi$ is called the \\emph{matrix}.\n\nLet $x$ be the outermost variable in the prefix of an SSAT formula $\\Qf$.\nThe satisfying probability of $\\Qf$, denoted by $\\spb{\\Qf}$, is defined by the following four rules:\n\\begin{enumerate}\n    \\item[a)] $\\spb{\\top}=1$,\n    \\item[b)] $\\spb{\\bot}=0$,\n    \\item[c)] $\\spb{\\Qf}=\\max\\{\\spb{\\ncf{\\Qf}{x}},\\spb{\\pcf{\\Qf}{x}}\\}$, if $x$ is existentially quantified,\n    \\item[d)] $\\spb{\\Qf}=(1-p)\\spb{\\ncf{\\Qf}{x}}+p\\spb{\\pcf{\\Qf}{x}}$, if $x$ is randomly quantified by $\\random{p}$,\n\\end{enumerate}\nwhere $\\ncf{\\Qf}{x}$ and $\\pcf{\\Qf}{x}$ denote the SSAT formulas obtained by eliminating the outermost quantifier of $x$ via substituting the value of $x$ in the matrix with $\\bot$ and $\\top$, respectively.\n\nThe \\textit{decision version} of SSAT is stated as follows.\nGiven an SSAT formula $\\Qf$ and a threshold $\\theta\\in[0,1]$, decide whether $\\spb{\\Qf}\\geq\\theta$.\nOn the other hand, the \\textit{optimization version} asks to compute the exact value of $\\spb{\\Qf}$.\nThe decision version of SSAT is PSPACE-complete~\\cite{Papadimitriou1985}.\n\nAn SSAT formula can also be interpreted from a game-theoretical viewpoint.\nThe randomized quantifiers represent the nondeterministic factors in a stochastic game.\nThe existential quantifiers model the moves of an agent who plays under such uncertainty.\nThe satisfying probability of the SSAT formula corresponds to the maximum winning probability of the agent.\nA \\textit{Skolem function} for an existentially quantified variable is the agent's strategy to assign this variable.\nNote that the Skolem function for a variable can only depend on its preceding variables in the prefix.\nA set of optimal Skolem functions achieves the maximum winning probability.\n\n\\begin{example}\n    Consider an SSAT formula $\\Qf$:\n    \\begin{align*}\n        \\random{0.5}x_1,\\exists y_1,\\random{0.5}x_2,\\exists y_2.\n        (x_1\\lor\\lnot y_1)(\\lnot x_1\\lor y_1)\n        (\\lnot x_1\\lor\\lnot x_2\\lor y_2)(x_1\\lor\\lnot y_2)(x_2\\lor\\lnot y_2).\n    \\end{align*}\n    According to the computational rules for the satisfying probability of SSAT, we have $\\spb{\\Qf}=1$.\n    The maximum winning probability can be achieved by assigning $y_1$ to $f_1(x_1)=x_1$ and $y_2$ to $f_2(x_1,x_2)=x_1\\land x_2$.\n    The set of functions $\\{f_1,f_2\\}$ is a set of optimal Skolem functions for $\\Qf$.\n\\end{example}", "meta": {"hexsha": "69479bf3631289df4a0644e492d623c60b1cbeef", "size": 3000, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background/ssat.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/ssat.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/ssat.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": 65.2173913043, "max_line_length": 206, "alphanum_fraction": 0.7246666667, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7781867767406561}}
{"text": "\\chapter{Stochastic Differential Equations and Training Algorithms}\n\\input{6DL/Bayesian}\n\\section{Simulated Annealing}\nGiven a function $\\phi(x)$, we want to find the global minimum of this funcion, that is, we need to find $x^*=argmin(\\phi(x))$\n\\subsection{Theorem}\nFor stochastic process $X^T_t$ which satisfies a stochastic differential equation \n$$dX_t^T=-\\frac{1}{\\gamma}\\nabla\\phi(X_t^T)dt+\\frac{\\sigma}{\\gamma} dW_t$$\nwhere $T=\\frac{\\sigma^2}{2\\gamma}$ and $\\sigma$, $\\gamma$ are constant.\n~\\\\We have \n$$\\mathop{lim}\\limits_{t\\rightarrow\\infty, T\\rightarrow 0}E(X^T_t)=x^*$$\nwhere $x^*=argmin (\\phi(x))$\n\\subsection{Proof}For a stochastic differential equation\n$$dX_t=A(X_t,t)dt+\\sigma(X_t,t)dW_t \\eqno{(1)}$$\nBy Kolmogorov forward equation, we have the transition probability $P(x,t;x',0)$ satisfies \n$$\\frac{\\partial}{\\partial t}P(x,t;x',0)=L_t^{+}P(x,t;x',0) \\eqno{(2)}$$\nwhere $L_t=A(X_t,t)\\frac{\\partial}{\\partial x}+\\frac{1}{2}\\sigma^2(X_t,t)\\frac{\\partial^2}{\\partial x^2}$ and $L_t^+$ is the adjoint of $L_t$.\n~\\\\By the definition of probability density function w.r.t. transition probability:\n$$f(x,t)=\\int P(x,t;x',0)P(x')dx' \\eqno{(3)}$$\nwhere $P(x')$ is the density function at $t=0$.\n~\\\\Combine equation (3) and (2), by simple computation, we get Fokker-Planck equation:\n$$\\frac{\\partial}{\\partial t}f(x,t)=L_t^{+}f(x,t) \\eqno{(4)}$$\nNow we set $A(x,t)=-\\frac{1}{\\gamma}\\nabla\\phi(x)$ and $\\sigma(x,t)=\\frac{\\sigma}{\\gamma}$ (constant)\n~\\\\Then the Fokker-Planck equation [or equation (4)] becomes:\n$$\\frac{\\partial f}{\\partial t}=\\frac{\\partial}{\\partial x}[\\frac{1}{\\gamma}\\nabla\\phi(x)\\cdot f]+\\frac{1}{2}\\frac{\\partial^2}{\\partial x^2}(\\frac{\\sigma^2}{\\gamma^2} f) \\eqno(5)$$\nWhen it comes to a steady state, that is, the density function would not change according to time:\n$$\\frac{\\partial f}{\\partial t}=0 \\eqno(6)$$\n(In physics, we often set $t\\rightarrow \\infty$ to represent the steady state)\n~\\\\Combine equation (5) and (6), we get \n$$\\frac{\\partial}{\\partial x}[\\frac{1}{\\gamma}\\nabla\\phi(x)\\cdot f]+\\frac{1}{2}\\frac{\\partial^2}{\\partial x^2}(\\frac{\\sigma^2}{\\gamma^2} f)=0 \\eqno(7)$$\nSolve this ODE, we have:\n$$f=\\frac{e^{-\\frac{2\\gamma\\phi(x)}{\\sigma^2}}}{\\int e^{-\\frac{2\\gamma\\phi(x)}{\\sigma^2}}dx} \\eqno(8)$$\nWe define $T=\\frac{\\sigma^2}{2\\gamma}$ as the temperature. We call this steady state distribution equilibrium distribution at temperature T. So just by changing variables, we rewrite equation (8):\n$$f^T_{eq}=\\frac{e^{-\\frac{\\phi(x)}{T}}}{\\int e^{-\\frac{\\phi(x)}{T}}dx} \\eqno(9)$$\nWe denote $X_t^T$ as the stochastic process which satisfies\n$$dX_t^T=-\\frac{1}{\\gamma}\\nabla\\phi(X_t^T)dt+\\frac{\\sigma}{\\gamma} dW_t \\eqno(10)$$\nwhere $T=\\frac{\\sigma^2}{2\\gamma}$ [Because we have set $A(x,t)=-\\frac{1}{\\gamma}\\nabla\\phi(x)$ and $\\sigma(x,t)=\\frac{\\sigma}{\\gamma}$ (constant)]\n~\\\\By previous argument, the density function of random variable $X_{\\infty}^T$ is $f^T_{eq}$\n~\\\\By Laplace Method, which says that:\n~\\\\For  $\\forall g\\in C^{\\infty}(\\mathbb{R})$, we have \n$$\\int g\\cdot f^T_{eq}\\rightarrow \\int g\\cdot \\delta(x-x^*)=g(x^*)~\\ as ~\\ T\\rightarrow 0 \\eqno(11)$$\nwhere $x^*=argmin (\\phi(x))$\n~\\\\Because $g(x)=x\\in C^{\\infty}(\\mathbb{R})$, we immediately get:\n$$E(X^T_\\infty)=\\int x\\cdot f^T_{eq}\\rightarrow\\int x\\cdot \\delta(x-x^*)=x^* ~\\ as ~\\ T\\rightarrow 0 \\eqno(12)$$\nSo we get:\n$$\\mathop{lim}\\limits_{t\\rightarrow\\infty, T\\rightarrow 0}E(X^T_t)=x^* \\eqno(13)$$\nSo the basic idea of simulated annealing is to approximate $\\mathop{lim}\\limits_{t\\rightarrow\\infty, T\\rightarrow 0}E(X^T_t)$\n\\subsection{Algorithm of simulated annealing}\nFix T=1, we fix a point $x_0$ and evolve the stochastic differential equation $dX_t^T=-\\frac{1}{\\gamma}\\nabla\\phi(X_t^T)dt+\\frac{\\sigma}{\\gamma} dW_t$ [equation(10)]. When it comes to the steady state $(t>>1)$, we start sampling $\\{x_1, x_2, x_3, ..., x_n\\}$\nwhen n is large enough, we get $E(X^1_\\infty)\\approx\\frac{1}{n}\\sum\\limits^n_{i=1}x_i$\n~\\\\Fix T=0.1, we set $x_0=\\frac{1}{n}\\sum\\limits^n_{i=1}x_i$ and evolve the stochastic differential equation $dX_t^T=-\\frac{1}{\\gamma}\\nabla\\phi(X_t^T)dt+\\frac{\\sigma}{\\gamma} dW_t$ [equation(10)]. When it comes to the steady state $(t>>1)$, we start sampling $\\{x_1, x_2, x_3, ..., x_n\\}$\nwhen n is large enough, we get $E(X^{0.1}_\\infty)\\approx\\frac{1}{n}\\sum\\limits^n_{i=1}x_i$.\n~\\\\We keep lowering the temperature.\n~\\\\Finally, we get $T=\\epsilon$ ($\\epsilon<<1$). After doing sampling $\\{x_1, x_2, x_3, ..., x_n\\}$, we have $\\frac{1}{n}\\sum\\limits^n_{i=1}x_i\\approx E(X^{\\epsilon}_\\infty)\\approx x^*$\n\n\n\\subsection{From SGD (minibatch) to SA}\nWe first consider the following lost function \n$$ \nF(x) = \\frac{1}{N} \\sum_{i=1}^N f_i(x),\n$$ \nwhere $N$ is the number of data point. The Minibatch SGD is written\nas \n\\begin{equation} \\label{equ:minibatch}\nx^{n+1} = x^n - \\Delta t_{n} \\nabla F_{B_n}(x^n),\n\\end{equation}\nwhere \n$$ \nF_{B_n}(x) = \\frac{1}{|B_n|} \\sum_{j \\in B_n} f_j(x).\n$$ \nNow, we rewrite \\eqref{equ:minibatch} as \n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - \\Delta t_{n} \\nabla F(X^n) + \\Delta {t}_n\n\\underbrace{[\\nabla F(X^n) - \\nabla F_{B_n}(X^n)]}_{Y^n}. \n\\end{equation}\n\n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - a_{n} \\nabla F(X^n) + a_n\n[\\nabla F(X^n) - \\nabla F_{B_n}(X^n)-\\frac{b_n}{a_n}] + b_nW_n \n\\end{equation}\n\\begin{equation} \\label{equ:minibach-SA}\nX^{n+1} = X^n - a_{n} [\\nabla F(X^n) + \\xi_n] + b_nW_n \n\\end{equation}\nwhere\n$$\na_n=\\Delta t_n, \\xi_n=\\nabla F(X^n) - \\nabla F_{B_n}(X^n)-\\frac{b_n}{a_n}W_n.\n$$\n\nLet $p_i$ is the probability of choosing the $i$-th component to\nthe minibatch. We note here that each component may be in the\nminibatch for more than once. Then, we have \n$$ \n\\begin{aligned}\n\\mathbb{E}(Y^n) &= \\nabla F(X^n) - \\mathbb{E} [\\nabla F_{B_n}(X^n)] \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\frac{1}{|B_n|}\n\\mathbb{E}[\\sum_{j\\in B_n} \\nabla f_j(X^n)] \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\mathbb{E}[\\nabla\nf(X^n)] \\qquad (\\text{independence}) \\\\\n&= \\frac{1}{N} \\sum_{i=1}^N \\nabla f_i(X^n) - \\sum_{i=1}^N p_i \\nabla\nf_i(X^n).\n\\end{aligned}\n$$ \nTherefore, we have the following condition\n\\begin{equation} \\label{equ:mean-condition}\n\\frac{1}{N}\\sum_{i=1}^N \\nabla f_i(x^n) = \\mathbb{E}[\\nabla f(X^n)].\n\\end{equation}\nFrom the above condition, a simple choice is $p_i = \\frac{1}{N}$,\nnamely uniform distribution. Condition \\eqref{equ:mean-condition}\ncan also be written as $\\mathbb{E}(Y^n) = 0$.\n\nNote that ${\\rm Var}(Y^n) = \\mathbb{E}[Y^n (Y^n)^T] - \\mathbb{E}(Y^n)\n\\mathbb{E}(Y^n)^T = \\mathbb{E}[Y^n (Y^n)^T]$. For simplicity,\nwe remove the dependence of $X^n$ in the following. Then, \n$$ \n\\begin{aligned}\n{\\rm Var}(Y^n) &= \\mathbb{E}[ (\\nabla F - \\nabla F_{B_n})\n(\\nabla F - \\nabla F_{B_n})^T ]\n\\\\\n&= \\mathbb{E}[\\nabla F_{B_n} (\\nabla F_{B_n})^T ] - \\nabla F (\\nabla\nF)^T \\\\\n&= \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_1} \\cdots\n\\mathbb{E}_{i_{|B_n|}}[ (\\sum_{j=1}^{|B_n|} \\nabla f_{i_j})\n(\\sum_{j=1}^{|B_n|} \\nabla f_{i_j})^T ] - \\nabla F (\\nabla F)^T \\\\\n&= \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_2} \\cdots\n\\mathbb{E}_{i_{|B_n|}}[ \\sum_{j,r=1 , i\\neq j}^{|B_n|} \\nabla f_{i_j}\n(\\nabla f_{i_r})^T] \\\\ \n& ~~ + \\frac{1}{|B_n|^2} \\mathbb{E}_{i_1} \\mathbb{E}_{i_2} \\cdots\n\\mathbb{E}_{i_{|B_n|}} [\\sum_{j=1}^{|B_n|} \\nabla\nf_{i_j} (\\nabla f_{i_j})^T]- \\nabla F (\\nabla F)^T \\\\ \n& = (1 - \\frac{1}{|B_n|}) \\mathbb{E}(\\nabla f) [\\mathbb{E}(\\nabla\nf)]^T + \\frac{1}{|B_n|} \\mathbb{E}[ (\\nabla f) (\\nabla f)^T] -\n\\nabla F (\\nabla F)^T \\\\\n&= \\frac{1}{|B_n|} \\left( \\mathbb{E}[(\\nabla f) (\\nabla f)^T] -\n\\mathbb{E}(\\nabla f) [\\mathbb{E}(\\nabla f)^T] \n\\right) \\\\\n&= \\frac{1}{|B_n|} {\\rm Var}(\\nabla f).\n\\end{aligned}\n$$ \n\n\\begin{remark}\n\tSince the index here can be repeated, there is NO need that ${\\rm\n\t\tVar}(Y^n) = 0$ when $|B_n| = N$.\n\\end{remark}\n\nIn summary, we have \n\\begin{equation} \\label{equ:summary}\n\\mathbb{E}(Y^n) = 0, \\qquad {\\rm Var}(Y^n) = \\frac{1}{|B_n|} {\\rm\n\tVar}(\\nabla f).\n\\end{equation}\nIt is conceivable that the result can be extended to the expectation\nversion of the lost function, namely, \n$$ \nF(x) = \\mathbb{E}_{\\xi} f(x, \\xi).\n$$ \n\n\n\\subsection{Convergence result}\nIn the SA scheme, \n\\begin{equation} \\label{equ:SA}\nX^{n+1} = X^n - \\Delta t_n \\nabla F(X^n) + \\sigma_n W_{\\Delta t_n},\n\\end{equation}\nthe convergence is proven under the following condition: \n$$ \n\\Delta t_n = \\mathcal{O}(n), \\qquad \\sigma_n^2 =\n\\mathcal{O}(\\frac{1}{n \\log\\log n})\n$$ \nCompare the variance of $\\sigma_n W_{\\Delta t_n}$ and $\\Delta t_n\nY^n$, we have \n$$ \n\\sigma_n^2 \\Delta t_n \\approx \\Delta t_n^2 {\\rm Var}(Y^n),\n$$ \nwhich implies that \n$$ \n\\frac{1}{|B_n|} {\\rm Var}(\\nabla f) =\n\\mathcal{O}(\\frac{\\sigma_n^2}{\\Delta t_n}) =\n\\mathcal{O}(\\frac{1}{\\log\\log n}).\n$$ \nWe conclude that, if the SGD is stagnated, namely ${\\rm Var}(\\nabla\nf)$ stays the almost the same, we need to slowly increase the size of\nminibatch in the way that \n\\begin{equation} \\label{equ:batch-size}\n|B_n| = \\mathcal{O}(\\log\\log n).\n\\end{equation}\n\n\n\\begin{remark}\n\tThe above argument requires that $\\nabla f(x, \\xi)$ is Gaussian on\n\t$\\xi$ for any $x$. This assumption holds for linear Gaussian\n\tregression. \n\\end{remark}\n", "meta": {"hexsha": "d7babf0372e3b0fb5807b5086a75ffae8fe436fc", "size": 9132, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/SA.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/SA.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/SA.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.0631578947, "max_line_length": 289, "alphanum_fraction": 0.6418090232, "num_tokens": 3736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797051879431, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7780679738782639}}
{"text": "\\subsection{lead compensation}\n$$\nG_c(s) = K_c\\dfrac{s + \\dfrac{1}{T}}{s+\\dfrac{1}{\\alpha T}}, \\quad 0 < \\alpha < 1\n$$\n$$\nG_c(s) = K_c \\alpha \\dfrac{Ts + 1}{\\alpha T s + 1}\n$$\nDefine:\n$$K_c\\alpha = K$$\nthen:\n$$\nG_c(s) = K \\dfrac{Ts + 1}{\\alpha T s + 1}\n$$\nThe open-loop transfer function of the compensated system is:\n$$\nG_c(s)G(s) = G_c(s) = K \\dfrac{Ts + 1}{\\alpha T s + 1} G(s)\n= G_c(s) = \\dfrac{Ts + 1}{\\alpha T s + 1}KG(s) = G_c(s) = \\dfrac{Ts + 1}{\\alpha T s + 1}G_1(s)\n$$\nWhere:\n$$\nKG(s)= G_1(s)\n$$\nSteady state error must be less than $0.05\\%$\n$$\ne_{ss} = \\lim_{s\\to 0} = \\dfrac{1}{1+G_1(0)} = 0.05 \\to 0.05 + 0.05G_1(0) = 1 \\to 0.95 = 0.05G_1(0) \\to G_1(0) = 19\n$$\n$$\n\\lim_{s\\to 0} G(s) = \\lim_{s\\to 0} \\dfrac{50(s+0.5)}{(s+1)(s+1.5)^{3}(s+2)} = \\dfrac{50\\times0.5}{1\\times1.5^3\\times2} = 3.7037 \\xrightarrow[G_1 = KG]{G_1(0) = 19} K = 5.1300\n$$\n\n\n\n\nThe amplitude ratio:\n$$\n\\left\\vert G_1(j\\omega) \\right\\vert = \\left\\vert KG(j\\omega) \\right\\vert = 5.1300\\dfrac{50\\sqrt{\\omega^2+0.5^2}}{\\sqrt{\\omega^2+1^2}\\times(\\sqrt{\\omega^2 + 1.5^2})^3\\times\\sqrt{\\omega^2 + 2^2}}\n$$\nGain Crossover frequency:\n$$\n\\left\\vert G_1(j\\omega_g) \\right\\vert = 1\n$$\n\\newline\n$$\n5.1300\\dfrac{50\\sqrt{\\omega_g^2+0.5^2}}{\\sqrt{\\omega_g^2+1^2}\\times(\\sqrt{\\omega_g^2 + 1.5^2})^3\\times\\sqrt{\\omega_g^2 + 2^2}} = 1\n$$\n$$\n{26.3169\\times2500({\\omega_g^2+0.25}}) = \n{({\\omega_g^2+1})({\\omega_g^2 + 2.25})^3({\\omega_g^2 + 4}})\n$$\nThis equation solved with MATLAB and code has attacked (Q1\\_a.m).\n$$\n\\omega_g = 3.6233\n$$\n\nThe phase angle:\n\n$$\n\\angle G(j\\omega) = 0^{\\circ} + \\tan^{-1}\\dfrac{\\omega}{0.5} - \\tan^{-1}\\dfrac{\\omega}{1} - 3\\tan^{-1}\\dfrac{\\omega}{1.5} - \\tan^{-1}\\dfrac{\\omega}{2}\n$$\n\n$$\n\\angle G(j\\omega_g) = \\tan^{-1}\\dfrac{3.6233}{0.5} - \\tan^{-1}\\dfrac{3.6233}{1} - 3\\tan^{-1}\\dfrac{3.6233}{1.5} - \\tan^{-1}\\dfrac{3.6233}{2} = -4.46917_{rad} = -256.064^{\\circ}\n$$\nPhase margin:\n$$\n\\gamma = 180 + \\angle G(j\\omega_g) = 180 - 256.064 = -76.064\n$$\nNow we check above calculation with MATLAB margin function.\n\\begin{figure}[H]\n\t\\caption{System Bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/margin.png}\n\\end{figure}\nNyquist plot for system.\n\\begin{figure}[H]\n\t\\caption{System Nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/system_nyquist.png}\n\\end{figure}\nMATLAB bode diagram and our calculation are exactly the same.\n$$\n\\bar{\\gamma} = 45 + 5 = 50^{\\circ},\\quad \\phi_m = \\bar{\\gamma} - \\gamma = 126.0646^{\\circ}.\n$$\n$$\n\\phi_m = 85^{\\circ}\n$$\nThis is too much!\nbest we can do is about $90^{\\circ}$ in lead compensation so we add $85^{\\circ}$.\n$$\n\\sin(\\phi_m) = \\dfrac{1-\\alpha}{1+\\alpha} \\to\n\\alpha = \\dfrac{1-\\sin(\\phi_m) }{1+\\sin(\\phi_m) } = 0.0019\n$$\n$\\alpha$ is very low.\n$$\nK_c = \\dfrac{K}{\\alpha} = \\dfrac{5.1300}{0.0019} = 2691.1\n$$\n$$\n\\left\\vert G_1(j\\omega_m) \\right\\vert = \\sqrt{\\alpha} = \\left\\vert KG(j\\omega_m) \\right\\vert = 5.13 \\dfrac{50\\sqrt{\\omega_m^2+0.5^2}}{\\sqrt{\\omega_m^2+1^2}\\times(\\sqrt{\\omega_m^2 + 1.5^2})^3\\times\\sqrt{\\omega_m^2 + 2^2}} = \\sqrt{0.0019}\n$$\nThis equation solved with MATLAB and code has attacked (Q1\\_a.m).\n$$\n\\omega_m = 8.58898\n$$\n$$\n\\omega_m = \\dfrac{1}{T\\sqrt{\\alpha}} \\to\nT = \\dfrac{1}{\\omega_m\\sqrt{\\alpha}} = \\dfrac{1}{8.58898\\sqrt{0.0019}} = 2.6666\n$$\n$$\nG_c(s) = K_c \\dfrac{s + \\dfrac{1}{T}}{s + \\dfrac{1}{\\alpha T}} = 2691.1\\dfrac{s + 0.3750}{s + 196.720}\n$$\nBode diagram for lead compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{lead compensation Bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/controller_bode.png}\n\\end{figure}\nNyquist plot for lead compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{lead compensation nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/controller_nyquist.png}\n\\end{figure}\nNow add lead compensation to system.\n$$\nG_c(s)G(s) = 2691.1\\dfrac{s + 0.3750}{s + 196.720} \\dfrac{50(s+0.5)}{(s+1)(s+1.5)^{3}(s+2)}\n$$\nBode diagram for system with adding lead compensation.\n\\begin{figure}[H]\n\t\\caption{Bode diagram for system with lead compensation using MATLAB}\n\t\\centering\n\t\\label{margin with one lead}\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/new_margin.png}\n\\end{figure}\nNyquist plot for system with adding lead compensation.\n\\begin{figure}[H]\n\t\\caption{Nyquist plot for system with lead compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/new_nyquist.png}\n\\end{figure}\nThat was the best we can do with lead compensation!\nAll bode diagram in one figure:\n\\begin{figure}[H]\n\t\\caption{all bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/all_in_one.png}\n\\end{figure}\nWe didn't get requirement so we add new lead compensation.\nwe skip previous calculation and use MATLAB margin function in figure \\ref{margin with one lead}.\n$$\n\\bar{\\gamma} = 45 + 5 = 50^{\\circ},\\quad \\phi_m = \\bar{\\gamma} - \\gamma = 98.9000^{\\circ}.\n$$\n$$\n\\phi_m = 85^{\\circ}\n$$\nThis is too much!\nbest we can do is about $90^{\\circ}$ in lead compensation so we add $85^{\\circ}$.\n$$\n\\sin(\\phi_m) = \\dfrac{1-\\alpha}{1+\\alpha} \\to\n\\alpha = \\dfrac{1-\\sin(\\phi_m) }{1+\\sin(\\phi_m) } = 0.0019\n$$\n$\\alpha$ is very low.\nWith before lead compensation we currect steady state error so we assume $K = 1$.\n$$\nK_c = \\dfrac{K}{\\alpha} = \\dfrac{1}{0.0019} = 524.5825\n$$\nFrom previous calculation and MATLAB calculation figure \\ref{margin with one lead} $\\omega_m = 8.58898$\n$$\n\\omega_m = \\dfrac{1}{T\\sqrt{\\alpha}} \\to\nT = \\dfrac{1}{\\omega_m\\sqrt{\\alpha}} = \\dfrac{1}{8.58898\\sqrt{0.0019}} = 2.6666\n$$\n$$\nG_c(s) = K_c \\dfrac{s + \\dfrac{1}{T}}{s + \\dfrac{1}{\\alpha T}} = 524.5825\\dfrac{s + 0.3750}{s + 196.720}\n$$\nBode diagram for second lead compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{second lead compensation Bode diagram using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/new_controller_bode.png}\n\\end{figure}\nNyquist plot for second lead compensation using MATLAB.\n\\begin{figure}[H]\n\t\\caption{second lead compensation nyquist plot using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/new_controller_nyquist.png}\n\\end{figure}\nNow add second lead compensation to system and lag compensation.\n$$\nC_{c_1}(s)G_c(s)G(s) = 524.5825\\dfrac{s + 0.3750}{s + 196.720}\n2691.1\\dfrac{s + 0.3750}{s + 196.720}\n \\dfrac{50(s+0.5)}{(s+1)(s+1.5)^{3}(s+2)}\n$$\nBode diagram for system with adding lead compensation.\n\\begin{figure}[H]\n\t\\caption{Bode diagram for system with lead compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/two_lead_new_margin.png}\n\\end{figure}\nNyquist plot for system with adding lead compensation.\n\\begin{figure}[H]\n\t\\caption{Nyquist plot for system with lead compensation using MATLAB}\n\t\\centering\n\t\\includegraphics[width=12cm]{../Figure/Q1/a/two_lead_new_nyquist.png}\n\\end{figure}\nWe didn't get requirement so we add new lead compensation.\nwe skip previous calculation and use MATLAB margin function in figure \\ref{margin with one lead}.\n$$\n\\bar{\\gamma} = 45 + 10 = 55^{\\circ},\\quad \\phi_m = \\bar{\\gamma} - \\gamma = 98.9000^{\\circ}.\n$$\n\n", "meta": {"hexsha": "d9ecb61d7015a076c72b3a94e2289a9c84a6d805", "size": 7069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW/HW II/Report/Q1/a/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 II/Report/Q1/a/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 II/Report/Q1/a/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": 33.6619047619, "max_line_length": 236, "alphanum_fraction": 0.6640260291, "num_tokens": 2770, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.778067970856592}}
{"text": "% Project for Integration Workshop. Dept. Mathematics. UArizona\n% Write a first-order ODE solver for a system of ODEs\n\n\\section{First-order ODE Integrators}\nConsider the differential equation\n\\begin{equation}\n\\label{eq:ode_system}\n\\begin{cases} \\dot{x}(t) = -y, & \\quad x(0) = 1\\\\ \\dot{y}(t) = \\phantom{-}x, & \\quad y(0) = 0 \\end{cases}\n\\end{equation}\n% which we can also write in matrix notation as\n% \\begin{equation}\n% \\label{eq:ode_matrix}\n% \\dot{\\bm{x}}(t) = \\begin{bmatrix*}[r] 0 & -1 \\\\ 1 & 0 \\end{bmatrix*} \\bm{x}, \\quad \\bm{x}(0) = \\begin{pmatrix} 1\\\\0 \\end{pmatrix}\n% \\end{equation}\nUse pencil-and-paper to solve the ODE. Make a quiver plot. Sketch solutions.\\\\\n\nIn this project, you will build a numerical solver for differential equations like this one. You will test your solver on this ODE, and then use it to solve a more interesting ODE.\nFor this problem, discretize the time interval $0 \\leq t \\leq T$ into $n+1$ points. That is, set $\\Delta t = T/n$ and $t_k = k \\, \\Delta t$, so $ t = \\{t_0, t_1, \\dots, t_n\\}$. \\\\\n\\textit{Forward Differences:}\n\\begin{enumerate}[(a)]\n    \\item Use what's called a \\textit{first-order forward difference} approximation to the derivatives $\\dot{x}$ and $\\dot{y}$ at each $t$ as follows:\n    \\begin{equation} \n    \\label{eq:forward_difference}\n    \\dot{x}(t) \\approx \\frac{x(t + \\Delta t) - x(t)}{\\Delta t} \\qquad \\text{and} \\qquad \\dot{y}(t) \\approx \\frac{y(t + \\Delta t) - y(t)}{\\Delta t}.\n    \\end{equation}\n     Substitute equation (\\ref{eq:forward_difference}) into equation (\\ref{eq:ode_system}) and show that we can approximate the differential equation by the discrete time-stepping process:\n    \\begin{equation}\n    \\label{eq:forward_euler}\n    \\begin{cases} x_{k+1} = x_k - (\\Delta t) y_k, & \\quad x_0 = 1\\\\  y_{k+1} = y_k + (\\Delta t) x_k, & \\quad y_0 = 0\\\\  \\end{cases}\n    \\end{equation}\n    \\item Implement equation \\ref{eq:forward_euler} for $0 \\leq t \\leq 1$ and plot the trajectory given by the solution.\n    \\item Is your approximation qualitatively correct? Will it remain qualitatively correct on $0 \\leq t \\leq T$ as $T$ gets very large? Explain.\\\\\n    \\textit{Hint:} It may be useful to rewrite the system of difference equations in matrix form,\n    \\begin{equation*}\n    \\bm{x}_{k+1} \n    % = \\bm{x}_n + (\\Delta t) \\begin{bmatrix*}[r] 0 & -1 \\\\ 1 & 0 \\end{bmatrix*} \\bm{x}_n \n    = \\begin{bmatrix} 1 & -\\Delta t \\\\  \\Delta t & 1\\end{bmatrix} \\bm{x}_k, \\quad \\bm{x}_0 = \\begin{pmatrix} 1\\\\0 \\end{pmatrix}\n    \\end{equation*}\n    and to analyze the eigenvalues of the matrix.\n\\end{enumerate}\n\\textit{Backward Differences:}\n\\begin{enumerate}[(a),resume]\n    \\item We could have solved this problem by a different approach. We could also have used what's called a \\textit{first-order backward difference}:\n    \\begin{equation} \n    \\label{eq:backward_difference}\n    \\dot{x}(t) \\approx \\frac{x(t) - x(t - \\Delta t)}{\\Delta t} \\qquad \\text{and} \\qquad \\dot{y}(t) \\approx \\frac{y(t) - y(t  \\Delta t)}{\\Delta t}.\n    \\end{equation}\n    Show that the backward difference gives the approximation\n    \\begin{equation}\n    \\label{eq:backward_euler}\n     \\begin{cases} x_{k} = x_{k-1} - (\\Delta t) y_k, & \\quad x_0 = 1\\\\  y_{k} = y_{k-1} + (\\Delta t) x_k, & \\quad y_0 = 0\\\\  \\end{cases}\n    \\end{equation}\n    which can be rewritten as\n   \\begin{equation*} \n    \\bm{x}_{k} \n    % = \\bm{x}_n + (\\Delta t) \\begin{bmatrix*}[r] 0 & -1 \\\\ 1 & 0 \\end{bmatrix*} \\bm{x}_n \n    = \\left(\\begin{bmatrix} 1 & \\Delta t \\\\  -\\Delta t & 1\\end{bmatrix}\\right)^{-1} \\bm{x}_{k-1}, \\quad \\bm{x}_0 = \\begin{pmatrix} 1\\\\0 \\end{pmatrix}\n    \\end{equation*}\n    \\item Implement equation (\\ref{eq:backward_euler}) for $0 \\leq t \\leq 1$ and plot the trajectory given by the solution. \n    \\item Is your approximation qualitatively correct? Will it remain qualitatively correct on $0 \\leq t \\leq T$ as $T$ gets very large? Explain.\n\\end{enumerate}\n\\textit{Bonus:}\n\\begin{enumerate}[(a),resume]\n    \\item (The really fun stuff) Use your ODE solver to solve $\\dot{x} = -y$, $\\dot{y} = \\sin x$. \n\\end{enumerate}\n\\newpage\n\n", "meta": {"hexsha": "9d6f340f144a57bc0245b808a931fcbdb7f15156", "size": 4053, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ode-solver-first-order.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": "ode-solver-first-order.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": "ode-solver-first-order.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": 59.6029411765, "max_line_length": 188, "alphanum_fraction": 0.6555637799, "num_tokens": 1409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951143326727, "lm_q2_score": 0.9219218332461268, "lm_q1q2_score": 0.7780053308730274}}
{"text": "\\subsection{Stochastic process}\n\nWhen describing how a quantity evolves over time with a non-deterministic\ntrajectory we often use what is commonly known as stochastic processes. For\nexample imagine we are keeping track of a random variable $X$ that changes over\ntime. This stochastic variable $X$ could describe things such as count of a\nspecific chemical species, average price of an asset over a period of time,\nfrequency of a particular allele on a population, etc. To describe how this\nvariable $X$ changes over time we could in principle list an infinite number of\nfunctions\n\\begin{equation}\n  X(t) = f(X, t).\n\\end{equation}\nThis is what we call a stochastic process, i.e. the time evolution of a random\nvariable $X$. What we are doing here is considered notation abuse by the more\nscrupulous mathematicians. Usually people prefer to define a random process as\n$Y_X(t) \\equiv f(X, t)$ to specify that we are studying how a random variable\n$X$ evolves over time $t$ without compromising the use of $X$ as the sole\nrandom variable, but I personally find that notation too strict. Most of our\nefforts in these notes will go into describing the probability distribution of\nsuch processes $P(x, t)$, i.e. the probability of our particular random process\ntaking the specific value $X(t) = x(t)$. More on that later.\n\nLet's clarify all these subtle but important notation differences: The random\nvariable $X$ is a mapping from a random event to the real line; in other words,\nfor a particular quantity that we want to describe we assign a number to\nrepresent the event that happened. A useful example is to think about it as\ngetting to observe a specific face once we roll a die, and assigning a number\nfrom 1 to 6 to represent the face we observed. The stochastic process $X(t)$\ndescribes the values that our random variable $X$ can take over time. Following\nup with the die example this could be rolling a die every so often and keeping\ntrack of the numbers that we obtain. This process $X(t)$ represents the\n\\textbf{ensemble} of possible realizations $x(t)$. In other words, as shown\nschematically in \\fref{fig_ensemble_realization} $X(t)$ describes all possible\nvalues that the quantity $X$ can take over time, and $x(t)$ describes a\nspecific trajectory that happened to occur for a specific realization of the\nprocess.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[width=0.5\\textwidth]\n  {../../fig/drift_langevin/02_02_01_ensemble_realization.jpeg}\n\t\\caption{\\textbf{Schematic description of a stochastic process}. The shaded\n\tregion describes the stochastic process $X(t)$, i.e. all the possible values\n\tthat the random variable $X$ can take over time. The particular realization\n\t$x(t)$ describes a specific trajectory that the random variable $X$ took in\n\tone particular case.}\n  \\label{fig_ensemble_realization}\n\\end{figure}\n\nFrom the intuition presented in \\fref{fig_ensemble_realization} we understand\nthat all possible trajectories that our stochastic process can take are\ncontained in the function $X(t)$. But some particular paths $x(t)$ are more\nlikely to happen than others. This is what the language of probability theory\nallows us to compute! In principle we are interested in writing how likely it\nis for our process to take a specific value $x(t)$. This is described by the\nprobability function $P(x, t)$ which will be at the center of our endeavors for\nthese notes. Once we define our stochastic process we might want to compute a\nmoment of the distribution. Recall that for a continuous random variable $X$\nwith probability density function $P_X(x)$, a moment is defined as\n\\begin{equation}\n  \\ee{X^m} \\equiv \\int dx \\; x^m P_X(x),\n\\end{equation}\nwhere the integral is taken over all the values that $X$ can take. Notice that\nour notation for the distribution $P_X(x)$ highlights that we are only\nconsidering values that $X$ can take, no time involved so far. For our case\nin which the random variable can change over time what we have to do is settle\nfor a specific time point $t^*$ and compute the average at that time point\n\\begin{equation}\n  \\ee{X(t^*)^m} \\equiv \\int dx \\; x^m P(x, t^*).\n  \\label{eq_process_moment}\n\\end{equation}\nNotice that this is still not making a statement about the time evolution of\nour variable $X$, but rather committing to a specific time point $t^*$ and then\ncomputing the $m\\tth$ moment at that time point. An intuitive way to think\nabout this is to take a frequentist approach for probability. We imagine that\nwe get to observe many many individual trajectories $\\{x_1(t), \\ldots\nx_n(t)\\}$, as schematically shown in \\fref{fig_average_langevin} then what\n\\eref{eq_process_moment} is doing is computing the moment at a specific time\npoint $t^*$ highlighted also in \\fref{fig_average_langevin}.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[width=0.5\\textwidth]\n  {../../fig/drift_langevin/02_02_02_average_langevin.jpeg}\n\t\\caption{\\textbf{Computing a moment of a distribution $\\ee{X(t)}$}. Multiple\n  realizations of the stochastic process $\\{x_1(t), \\ldots x_n(t)\\}$ are\n  highlighted. In the limit where we have many many of these trajectories we\n  can then compute a moment of the distribution $P(x, t^*)$ for a specific time\n  point $t^*$. \\mrm{need better caption}}\n  \\label{fig_average_langevin}\n\\end{figure}\n\nThere is no reason why we have to limit ourselves to a single time point $t^*$.\nIn particular there are interesting quantities such as the autocorrelation\nfunction $\\kappa(t_1, t_2)$ that analyze how two different time points $t_1$\nand $t_2$ covary with each other. This quantity is defined as\n\\begin{equation}\n  \\kappa(t_1, t_2) = \\ee{\\left(X(t_1) - \\ee{X(t_1)}\\right)\n                         \\left(X(t_2) - \\ee{X(t_2)}\\right)}.\n\\end{equation}\n\\mrm{Not sure if I will need to include this if we don't ge to compute moments\nthat refer to multiple time points.}\n\nHaving understood conceptually what stochastic process are and what they allow\nus to do we are ready to see their practical implementation. The stochastic\nprocess literature is rich and very formal, but it can be daunting to grasp the\nbasics of it. For our purposes we will take a more pragmatic approach rather\nthan diving into the intricacies of the formalism. Our fundamental equation to\nmodel stochastic processes will be the Langevin equation.\n\n\\subsection{The Langevin equation}\\label{sec_langevin_intro}\n\nSince Robert Brown systematically described the jiggling of particles of\norganic and inorganic origin under the microscope, physicists of the caliber of\nEinstein and Smoluchowski tried to describe the phenomena. The first success\ncame from Einstein himself who in 1905 published a microscopic description of\nBrownian motion at the time where the atomic structure of matter was still up\nin the air. In 1908 only three years later, motivated by this theoretical\npredictions, Jean Baptiste Perrin experimentally confirmed Einstein's theory to\nunambiguously settle the controversy behind the existence of atoms. That same\nyear Paul Langevin published a seminal paper in which he proposed an\n``infinitely simpler'' formulation of Brownian dynamics according to himself.\nIn doing so Langevin made use of what we know nowadays as a stochastic\ndifferential equation. Ever since, the study of microscopic particles jiggling\nunder thermal forces has had enormous consequences in our understanding of the\nstructure of matter, and has motivated the development of the mathematical\nformalism of stochastic calculus with great impact in physics, economics, and\nas we are concerned here biological evolution.\n\nThe mathematical object that Langevin proposed that now carries his name is\ndifferent form the standard ordinary differential equations in the sense that\nit includes a stochastic term. More specifically for a 1D system the Langevin\nequation that describes the dynamics of $x(t)$ is of the form\n\\begin{equation}\n  \\dt{x} = A(x, t) + B(x, t) \\xi(t),\n  \\label{eq_langevin}\n\\end{equation}\nwhere $A(x, t)$ is the directional deterministic field that could depend on the\nvariable $x$ itself as well as time, $B(x, t)$ is the scale associated with the\nstochasticity of the process and $\\xi(t)$ is the random variable associated\nwith the dynamics of $x(t)$. Without the second term on the right-hand side we\nhave a regular differential equation for which there is most likely a method to\nsolve it given that $A(x, t)$ is a well behaved function. The solution of \n\\eref{eq_langevin} without this second term would be of the form\n\\begin{equation}\n  x(t) = x_o + \\int_{t_o}^t dt\\; A(x, t),\n\\end{equation}\nwhere $x_o$ is the initial condition, i.e. $x(t = t_o) = x_o$. This solution\nwould be a smooth deterministic trajectory for $x(t)$. The extra element that\nmakes \\eref{eq_langevin} special is the stochastic term $B(x, t) \\xi(t)$. \n$B(x, t)$ is simply a coefficient that determines the amplitude of the noise,\ni.e. it sets the scale for how noisy the stochastic process $x(t)$ must be. But\nthe true innovative feature of \\eref{eq_langevin} is $\\xi(t)$, sometimes called\nwhite noise. This term is itself a random variable, meaning that it is defined\nby a probability distribution $P(\\xi, t)$. The reason this term is called white\nnoise is because the noise is assumed to have mean zero, i.e. fluctuations that\nrandomly increase the value of $x(t)$ cancel with fluctuations that tend to\ndecrease $x(t)$ on average. This is mathematically expressed as\n\\begin{equation}\n  \\ee{\\xi(t)} = 0.\n\\end{equation}\nThe second reason this term is called white noise is because the noise at time\n$t$ is independent of the noise at any other point in time $t'$. This is\nsometimes referred as delta-correlated noise because the way we express this\nlack of time correlation between time points is through a $\\delta$-function as\n\\begin{equation}\n  \\ee{\\xi(t) \\xi(t')} = 2D \\delta(t - t'),\n  \\label{eq_noise_delta}\n\\end{equation}\nwhere the prefactor $2D$ is put to resemble the origins of this equation where\n$D$ represented the diffusion coefficient of the Brownian particle. What \n\\eref{eq_noise_delta} is saying is that only when $t = t'$ the noise\nautocorrelation function takes the magnitude $2D$ - that's what the \n$\\delta$-function role is. In other words, independently of what the noise\nmagnitude was at time $t'$, the noise at time $t$ is sampled from a\ndistribution with mean $\\ee{\\xi(t)} = 0$ and variance $\\ee{\\xi(t)^2} = 2D$.\n\nSince we are characterizing the noise via only its first two moments, i.e. the\nnoise and the variance, we take the distribution of $\\xi(t)$ to be Gaussian.\nThis assumption is justified because of the central limit theorem that tells us\nthat the distribution of the sum of many independent random variables tends to\na Gaussian distribution. That means the the probability density function of\n$\\xi(t)$ is of the form\n\\begin{equation}\n  P(\\xi(t)) = {1 \\over \\sqrt{4 \\pi D}} \n  \\E^{- {\\xi(t)^2 \\over 4D}}.\n\\end{equation}\nTo get a better feeling for how this equation works let's work through a very\nsimple example.\n\n\\subsubsection{Biased random walk}\n\\mrm{For now I took a ``synthetic'' example not directly connected to what we\nwill do in population genetics. The nice thing about this example is that can\nbe analitically solved very easily, so it illustrates how one works with\nLangevin equations. But I might consider using a more relevant example in\nfurther iterations if this feels too out of place.}\n\nIn order to see what we can do with this type of mathematical object let's\ndefine the a very simple Langevin equation that includes both a directional\nterm and the stochastic term. For this we will imagine a small particle\nperforming a random walk in 1D. We will follow the particle's position $x(t)$\nas it is subject to a restoration force and a constant noise term. What this\nmeans is that the dynamics of $x(t)$ are given by\n\\begin{equation}\n  \\dt{x} = -\\gamma x(t) + \\xi(t),\n  \\label{eq_random_walk_langevin}\n\\end{equation}\nwhere we set $A(x, t) = -\\gamma x(t)$ and $B(x, t) = 1$. If $\\xi(t)$ was a\nregular function \\eref{eq_random_walk_langevin} would be a non-homogeneous\nlinear differential equation. To solve this equation we could use for example\nthe integrating factor method. For this we would rewrite\n\\eref{eq_random_walk_langevin} as\n\\begin{equation}\n  \\dt{x} + \\gamma x(t) = \\xi(t).\n\\end{equation}\nThe integrating factor $M(t) $is then given by\n\\begin{equation}\n  M(t) = \\E^{\\int \\gamma \\; dt}.\n\\end{equation}\nThe integral in the exponent of the integrating factor is a kind of integral\nknown as an integral function. The reason being that it gives the primitive\nargument itself (in this case $t$) without an integration constant. In other\nwords, the integral should be thought as\n\\begin{equation}\n  \\int \\gamma \\; dt = \\int_0^t \\gamma ds,\n\\end{equation}\nwhere the fundamental theorem of calculus tells us that this gives\n\\begin{equation}\n  \\int_0^t \\gamma ds = \\gamma t,\n\\end{equation}\nregardless of the integration lower limit. Multiplying both sides of the\nequation by $M(t)$ then gives\n\\begin{equation}\n  \\E^{\\gamma t} \\left[ \\dt{x} + \\gamma x(t) \\right] =\n  \\E^{\\gamma t} \\xi(t).\n\\end{equation}\nThe integration factor allows us to rewrite the left-hand side as\n\\begin{equation}\n  \\dt{}\\left[ x(t) \\E^{\\gamma t} \\right] = \n  \\E^{\\gamma t} \\xi(t).\n\\end{equation}\nWe can now integrate both sides of the equation from 0 to $t$ to obtain\n\\begin{equation}\n  \\int_0^t ds\\; {d \\over ds}\\left[ x(s) \\E^{\\gamma s} \\right] =\n  \\int_0^t ds \\; \\E^{\\gamma s} \\xi(s).\n\\end{equation}\nFor the left-hand side we can use the fundamental theorem of calculus to cancel\nthe integral with the derivative, obtaining\n\\begin{equation}\n  \\left. x(s)\\E^{\\gamma s} \\right\\vert_{0}^{t} =\n  \\int_0^t ds \\; \\E^{\\gamma s} \\xi(s).\n\\end{equation}\nSubstituting the integration limits and solving for $x(t)$ results in\n\\begin{equation}\n  x(t) = x_o \\E^{-\\gamma t} + \n  \\int_0^t ds \\; \\E^{-\\gamma (t - s)} \\xi(s).\n  \\label{eq_random_walk_sol}\n\\end{equation}\nFor the second term on the right-hand side we cannot give a close-form\nanalytical solution given the probabilistic nature of $\\xi(t)$. But what we can\ndo is describe the statistical properties of the trajectories. For example\nlet's compute the average position of the random walker $\\ee{x(t)}$\n\\begin{equation}\n  \\ee{x(t)} = \\ee{x_o \\E^{-\\gamma t} + \n  \\int_0^t ds \\; \\E^{-\\gamma (t - s)} \\xi(s)}.\n\\end{equation}\nUsing the linearity of expected values this gives\n\\begin{equation}\n  \\ee{x(t)} = x_o \\E^{-\\gamma t} +\n  \\int_0^t ds \\; \\E^{-\\gamma (t - s)} \\ee{\\xi(s)}.\n\\end{equation}\nSince we defined the mean noise $\\ee{\\xi(t)} = 0$ this results in\n\\begin{equation}\n  \\ee{x(t)} = x_o \\E^{-\\gamma t}.\n  \\label{eq_walker_mean}\n\\end{equation}\nFrom this result we can see that the memory of the initial position decays\nexponentially with a typical time-scale of $\\tau = {1 \\over \\gamma}$.\n\nTo compute the second moment $\\ee{x(t)^2}$ we need to square \n\\eref{eq_random_walk_sol}. This results in\n\\begin{equation}\n  x(t)^2 =\n  \\left( x_o \\E^{-\\gamma t} + \n  \\int_0^t ds \\; \\E^{-\\gamma (t - s)} \\xi(s) \\right)^2.\n\\end{equation}\nExpanding the binomial on the right-hand side gives\n\\begin{equation}\n   x(t)^2 = x_o^2 \\E^{-2\\gamma t} +\n   2 x_o \\E^{-\\gamma t} \n   \\left( \\int_0^t ds\\; \\E^{-\\gamma (t - s)} \\xi(s) \\right) +\n   \\left( \\int_0^t ds \\; \\E^{-\\gamma(t - s)} \\xi(s) \\right)^2.\n\\end{equation}\nWe can rewrite the squared integral term as a double integral of the form\n\\begin{equation}\n   \\left( \\int_0^t ds \\; \\E^{-\\gamma(t - s)} \\xi(s) \\right)^2 =\n   \\int_0^t ds \\; \\int_0^t dz\\; \\E^{-\\gamma (t - s)} \\E^{-\\gamma (t - z)}\n   \\xi(s) \\xi(z).\n\\end{equation}\nUsing this result and taking the expected value results in\n\\begin{equation}\n  \\ee{x(t)^2} = \\ee{\n   x_o^2 \\E^{-2\\gamma t} +\n   2 x_o \\E^{-\\gamma t} \n   \\left( \\int_0^t ds\\; \\E^{-\\gamma (t - s)} \\xi(s) \\right) +\n   \\int_0^t ds \\; \\int_0^t dz\\; \\E^{-\\gamma (t - s)} \\E^{-\\gamma (t - z)}\n   \\xi(s) \\xi(z)\n  }.\n\\end{equation}\nWe can again use the linearity of expected value. The first term on the\nright-hand side involves no random variable $\\xi(t)$, so it comes out of the\nexpected value operator. The second term involves a term $\\ee{\\xi(s)}$ which we\ndefined to be zero, so this term will cancel. For the last term we have a term\nof the form $\\ee{\\xi(s)\\xi(z)}$ - we defined this to be $2D \\delta (s - z)$.\nLet's substitute these results\n\\begin{equation}\n  \\ee{x(t)^2} = \n   x_o^2 \\E^{-2\\gamma t} +\n   \\int_0^t ds\\; \\int_0^t dz\\; \\E^{-\\gamma (t-s)} \\E^{-\\gamma (t-z)}\n   (2D \\delta(s - t)).\n\\end{equation}\nNow that we have this $\\delta$-function in place we can evaluate the integral\nover the values of $z$. The $\\delta$-function means that only when $z = s$ this\nterm contributes; in practice this means that the result from the integral over\n$z$ is to substitute all values of $z$ for $s$. This looks like\n\\begin{equation}\n  \\ee{x(t)^2} = \n   x_o^2 \\E^{-2\\gamma t} +\n   2D \\int_0^t ds \\; \\E^{-\\gamma (t-s)} \\E^{-\\gamma (t-s)}.\n\\end{equation}\nFactorizing the terms with exponent $t$ and taking them out of the integral\nresults in\n\\begin{equation}\n   \\ee{x(t)^2} = \n   x_o^2 \\E^{-2\\gamma t} +\n   2D \\E^{-2 \\gamma t} \\int_0^t ds\\; \\E^{2 \\gamma s}.\n\\end{equation}\nEvaluating the integral results in\n\\begin{equation}\n   \\ee{x(t)^2} = \n   x_o^2 \\E^{-2\\gamma t} +\n   {2D \\E^{-2\\gamma t} \\over 2 \\gamma}\\left( \\E^{2 \\gamma t} - 1 \\right).\n\\end{equation}\nThis can be simplified to\n\\begin{equation}\n   \\ee{x(t)^2} = \n   x_o^2 \\E^{-2\\gamma t} +\n   {D \\over \\gamma} \\left( 1 - \\E^{-2 \\gamma t} \\right).\n\\end{equation}\n\nNow that we have the first and the second moment we can compute the variance of\nour random walk. Recall that the variance is given by\n\\begin{equation}\n  \\sigma^2(x(t)) = \\ee{x(t)^2} - \\ee{x(t)}^2.\n  \\label{eq_walker_var}\n\\end{equation}\nUsing the results we derived results in\n\\begin{equation}\n  \\sigma^2(x(t)) = x_o^2 \\E^{-2\\gamma t} +\n   {D \\over \\gamma} \\left( 1 - \\E^{-2 \\gamma t} \\right) -\n   x_o^2 \\E^{-2\\gamma t} = \n   {D \\over \\gamma} \\left( 1 - \\E^{-2 \\gamma t} \\right).\n\\end{equation}\nIn the limit where $t \\rightarrow \\infty$ we the find that the variance\nconverges to $\\sigma^2(x) = {D \\over \\gamma}$. Let's now test these results\nwith numerical integration of the Langevin equation.\n\n\\subsubsection{Numerical integration of Langevin equations}\n\nIn order to test the validity of our analytical results we can generate several\nrealizations of the trajectories, i.e. a list of $\\{x_1(t), x_2(t), \\ldots \\}$\nthat follow the dynamics defined by \\eref{eq_random_walk_langevin} to then\ncompute from such realizations the mean and variance. The simplest method to\nnumerically integrate the Langevin equation is to write it as a discrete\ndifference equation. This means we rewrite \\eref{eq_random_walk_langevin} as\n\\begin{equation}\n  {x(t + \\Dt) + x(t) \\over \\Dt} = -\\gamma x(t) + \\xi(t).\n\\end{equation}\nThen if we solve for $x(t + \\Dt)$ we find our recipe to numerically integrate\nthe equation. This is\n\\begin{equation}\n  x(t + \\Dt) = x(t) - \\gamma x(t) \\Dt + \\xi(t) \\Dt.\n  \\label{eq_discrete_walker}\n\\end{equation}\nSo for a given small time interval $\\Dt$ that is significantly smaller compared\nto the relevant time scale set by $\\gamma$ and $D$ we can use Euler's method to\nintegrate the dynamics. The difference is that at each time step we can\ngenerate a pseudo-random number that follows the statistical properties that we\ndefined for $\\xi(t)$.\n\n\\fref{fig_langevin_euler} shows the result of this numerical procedure. The\nlight gray lines show different realizations of the dynamics generated with\n\\eref{eq_discrete_walker}, the black lines are the resulting mean $\\pm$\nstandard deviation of the trajectories, while the shaded blue are shows the\nsame mean $\\pm$ standard deviation as computed from our analytical results in\n\\eref{eq_walker_mean} and \\eref{eq_walker_var}. The agreement is strikingly\ngood, and the more realizations of the dynamics we were to include in our\ncomputation, the better the agreement would be.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[width=0.5\\textwidth]\n  {../../fig/drift_langevin/02_02_03_langevin_euler.png}\n\t\\caption{\\textbf{Numerical integration of the Langevin equation}. Comparison of simulation-based results with analytical results. Random trajectories that evolve according to \\eref{eq_random_walk_langevin} were generated. From these the mean and standard deviation of the trajectories were computed (black lines). Analytical results for the mean $\\pm$ standard deviation are shown as shaded blue area. For these simulations $x_o= 2$, $\\gamma = 1$, $D = 1.5$, and $\\Dt = 0.001$}\n  \\label{fig_langevin_euler}\n\\end{figure}\n\nHaving introduced the concept of random processes and the simple but yet\npowerful Langevin equation our goal will now be to work out the mathematical\ndescription of the full time evolution of the probability distribution of\npossible realizations of the random process $P(x, t)$. Our goal will be to\nderive the famous partial differential equation known as the Fokker-Plank\nequation that exactly describes this time evolution.", "meta": {"hexsha": "251ef3ce9be9e858cf584d2247dd45a49075ab83", "size": 20967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/book_draft/chapters/drift_langevin/02_intro_langevin.tex", "max_stars_repo_name": "mrazomej/stat_gen", "max_stars_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/book_draft/chapters/drift_langevin/02_intro_langevin.tex", "max_issues_repo_name": "mrazomej/stat_gen", "max_issues_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-03-05T00:17:26.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-05T00:17:26.000Z", "max_forks_repo_path": "doc/book_draft/chapters/drift_langevin/02_intro_langevin.tex", "max_forks_repo_name": "mrazomej/pop_gen", "max_forks_repo_head_hexsha": "abafd9ecc63ae8a804c8df5b9658e47cabf951fa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.0145985401, "max_line_length": 478, "alphanum_fraction": 0.7364906758, "num_tokens": 5906, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.7779690250993483}}
{"text": "\n\\subsection{Elementary row operations}\n\nSome operations to a matrix can be reversed to arrive at the original matrix. Trivially, multiplying by the identity matrix is reversible.\n\nSimilarly, some operations are not reversible. Such as multiplying by the empty matrix.\n\nAll matrix operations which can be reversed are combinations of \\(3\\) elementary row operations. These are:\nSwapping rows\n\n\\(T_{12}=\\begin{bmatrix}0& 1&...&0\\\\1 & 0&...&0\\\\...&...&...&...\\\\0&0&...&1\\end{bmatrix}\\)\n\nMultiplying rows by a vector\n\n\\(D_2(m)=\\begin{bmatrix}1& 0&...&0\\\\0 & m&...&0\\\\...&...&...&...\\\\0&0&...&1\\end{bmatrix}\\)\n\nAdding rows to other rows\n\n\\(L_{12}(m)=\\begin{bmatrix}1& 0&...&0\\\\m & 1&...&0\\\\...&...&...&...\\\\0&0&...&1\\end{bmatrix}\\)\n", "meta": {"hexsha": "d30e395ea46748dd8b6fad6d86aa779edf868168", "size": 728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/03-03-linearDependence.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/linearSystems/03-03-linearDependence.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/linearSystems/03-03-linearDependence.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.4, "max_line_length": 138, "alphanum_fraction": 0.6428571429, "num_tokens": 244, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418241572635, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.777966285606129}}
{"text": "\\section{Sets}\n\n\\begin{frame}{Set: collection of objects}\n  \\begin{itemize}\n    \\setlength\\itemsep{4mm}\n    \\item Denoted by capital letters: $A,B,X$\n    \\item Objects in a set are called elements.\n    \\item Elements are denoted by lower case letters: $a,b,x$\n    \\item Curly braces around elements: $A = \\{a_0,a_1,a_2\\}$\n  \\end{itemize}\n  \\vspace{3mm}\n  \\begin{exampleblock}{Examples}\n      \\begin{flalign*}\n      A &= \\{ 1, 2, 3 \\} \\\\\n      B &= \\{ p \\mid p \\ \\textrm{is a prime number} \\}\n      \\end{flalign*}\n  \\end{exampleblock}\n\\end{frame} \n \n\n\\begin{frame}{No order and no count}\n  \\begin{alertblock}{A set doesn’t maintain an order of its elements:}\n      \\begin{flalign*}\n        & \\{1,2,3\\} \\  = \\  \\{1,3,2\\} \\  = \\  \\{2,1,3\\} \\  = \\   \\{2,3,1\\}\\\\\n        & = \\  \\{3,1,2\\} \\  = \\  \\{3,2,1\\}\n      \\end{flalign*}\n    \\end{alertblock}\n    \\vspace{3mm}\n    \\begin{alertblock}{An object is either in the set or not:}\n      \\begin{flalign*}\n        & \\{1,2,2,3\\} \\  = \\   \\{1,2,3\\}\n      \\end{flalign*}\n  \\end{alertblock}\n\\end{frame}\n\n\\begin{frame}[fragile]{Question: is $1.0$ an element of $\\mathbb{Z}$?}\n\n  To a programmer, the answer is likely no, since $1.0$ is a floating-point number and not an integer.\n  Compilers will sometimes give errors if you give $1.0$ where an integer is expected.\n\n  \\begin{minted}[frame=lines]{python}\nIPython 6.1.0 -- An enhanced Interactive Python.\nType '?' for help.\nIn [1]: i = 1.0\nIn [2]: a = [1,4,9,16]\nIn [3]: a[i]\nTypeError: list indices must be integers or slices,\nnot float\nIn [4]: a[int(i)]\nOut[4]: 4\n  \\end{minted}\n\\end{frame}\n\n\\begin{frame}[fragile]{Question: is $1.0$ an element of $\\mathbb{Z}$?}\n  Most mathematicians, on the other hand, will likely say $1.0$ is an integer.\n  To them, $1$ and $1.0$ are just different representations of the same point on a number line.\n  They think of $\\mathbb{Z}$ as a subset of the real numbers $\\mathbb{R}$.\n  Every number on the usual number line is a real number, including $\\pi$, $1.5$ and $10$.\n\n  \\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{img/numberline.png} \n  \\end{center}\n\n  There's not a lot we can do, other than to provide some context when we consider such sets.\n  The discussion can get philosophical, especially in discussions about symbols and semantics.\n  Again, this is an important concept in the theory of computation.\n\\end{frame}\n\n\n\n\\begin{frame}{Sets containing sets}\n  \\begin{alertblock}{Subsets}\n    \\setlength\\itemsep{0mm}\n    \\belowdisplayskip=0pt\n    $A$ is a subset of $B$ if all the elements of $A$ are in $B$.\n    \\begin{flalign*}\n      A=\\{1,2,3,4\\} \\qquad   B=\\{2,3\\} \\qquad B \\subset A\n    \\end{flalign*}\n  \\end{alertblock}\n\n  \\begin{alertblock}{Powersets}\n    Some sets contain other sets as elements.\n    The powerset of a set is the set containing all subsets of it:\n    \\begin{flalign*}\n      A &= \\{1,2,3\\} \\\\\n      \\mathcal{P}(A) &= \\{\\{\\},\\{1\\},\\{2\\},\\{3\\},\\{1,2\\},\\{1,3\\},\\{2,3\\},\\{1,2,3\\}\\}\n    \\end{flalign*}\n    Note $A$ contains 3 elements and $\\mathcal{P}(A)$ contains $2^3=8$.\n  \\end{alertblock}\n\\end{frame}\n\n\n\\begin{frame}[fragile]{Famous sets}\n  \\begin{description}[123]\n    \\setlength\\itemsep{5mm}\n    \\item[$\\mathbb{N}$] -- the natural numbers $\\{ 1, 2, 3, \\ldots \\}$.\n    \\item[$\\mathbb{N}_0$] -- the natural numbers with zero $\\{ 0, 1, 2, 3, \\ldots \\}$.\n    \\item[$\\mathbb{Z}$] -- the integers $\\{ \\ldots, -2, -1, 0, 1, 2, \\ldots \\}$.\n    \\item[$\\mathbb{Q}$] -- the rational numbers $\\{ \\frac{m}{n} \\mid m, n \\in \\mathbb{Z} \\}$.\n    \\item[$\\mathbb{R}$] -- the \\href{https://en.wikipedia.org/wiki/Real\\_number\\#Definition}{real numbers}.\n    \\item[$\\mathbb{C}$] -- the complex numbers $\\{ a + bi \\mid a, b \\in \\mathbb{R}, i^2 = -1 \\}$.\n  \\end{description}\n\\end{frame}\n\n\n\\begin{frame}[fragile]{Sizes of sets}\n  \n  \\redmath{A = \\{a,b,c\\} \\  \\Rightarrow \\  \\vert A \\vert = 3}\n\n  \\begin{itemize}\n    \\setlength\\itemsep{4mm}\n    \\item Number of elements is denoted with vertical lines.\n    \\item The set of all prime numbers is an \\emph{infinite} set.\n    \\item Infinite sets can still have a notion of size.\n    \\item $\\mathbb{R}$ \\href{https://en.wikipedia.org/wiki/Cantor\\%27s\\_diagonal\\_argument}{is bigger than} $\\mathbb{N}$ even though they're both infinite -- important consequences for computation.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}{Operations on sets}\n  \\redmath{A = \\{1,2,3\\} \\qquad  B = \\{2,3,4\\}}\n  \\vspace{4mm}\n  \\begin{description}[Intersection:]\n    \\setlength\\itemsep{6mm}\n    \\item[Union:] $A \\cup B = \\{1,2,3,4\\}$, in $A$ \\textbf{or} $B$.\n    \\item[Intersection:] $A \\cap B = \\{2,3\\}$, in $A$ \\textbf{and} $B$.\n    \\item[Difference:] $A \\setminus B = \\{1\\}$, in $A$ \\textbf{not} $B$.\n  \\end{description}\n\\end{frame}\n\n\n\n\n\n\n\\section{Tuples}\n\n\\begin{frame}{Tuples: finite list of elements taken from sets}\n  \\redmath{t = (2,1,1) \\qquad t \\in \\mathbb{N} \\times \\mathbb{N} \\times \\mathbb{N} \\qquad |t| = 3}\n  \\begin{itemize}\n    \\setlength\\itemsep{2mm}\n    \\item Round brackets denote tuples, and $t$ is a $3$-tuple or a triple.\n    \\item Tuples have order, and can repeat elements.\n    \\item Sometimes we omit the brackets and commas: $t = 211$.\n    \\item $\\mathbb{N} \\times \\mathbb{N} \\times \\mathbb{N}$ is sometimes shortened to $\\mathbb{N}^3$.\n    \\item The first $\\mathbb{N}$ means the first element comes from $\\mathbb{N}$.\n    \\item The second $\\mathbb{N}$ means the second element comes from $\\mathbb{N}$, etc.\n    \\item Note that there is a single empty tuple: $()$.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}[fragile]{Cartesian products of sets}\n  \\redmath{A = \\{1,2,3\\} \\qquad B = \\{x,y\\}}\n  \\redmath{A \\times B = \\{(1,x),(2,x),(3,x),(1,y),(2,y),(3,y)\\}}\n  \n  \\begin{itemize}\n    \\item $A \\times B$ is called the cartesian product of $A$ and $B$ -- the set of tuples with first element from $A$ and second from $B$.\n    \\item $\\mathbb{R} \\times \\mathbb{R} = \\mathbb{R}^2$ is the usual 2D plane where we draw plots.\n    \\item Can extend to any length of tuple: $\\mathbb{R}^3$ is the 3D plane.\n  \\end{itemize}\n\n  \\begin{center}\n    \\resizebox{20mm}{20mm}{%\n      \\begin{tikzpicture}\n        \\begin{axis}\n          \\addplot[color=red]{exp(x)};\n        \\end{axis}\n      \\end{tikzpicture}\n    }\n    \\hspace{5mm}\n    \\resizebox{20mm}{20mm}{%\n      \\begin{tikzpicture}\n        \\begin{axis}[grid=both]\n          \\addplot3[surf,shader=faceted] {x*y};\n        \\end{axis}\n      \\end{tikzpicture}\n    }\n  \\end{center}\n\\end{frame}\n\n\\begin{frame}[fragile]{Multisets}\n  \\redmath{A = \\{a,b,x \\}}\n  \\redmath{M = \\{(a, 2), (b, 10), (x,5) \\}}\n  \\begin{itemize}\n    \\setlength\\itemsep{3mm}\n    \\item We can use sets and tuples to define other data structures.\n    \\item A multiset over a set $A$ is a subset of $A \\times \\mathbb{N}$ such that every element of $A$ appears exactly once as the first element in a tuple.\n  \\end{itemize}\n\\end{frame}", "meta": {"hexsha": "2abf533e3570c68161864722e08b8db4e5b9ef8f", "size": 6812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content.tex", "max_stars_repo_name": "ianmcloughlin/slides-sets-tuples", "max_stars_repo_head_hexsha": "673adf4e8547103c8b4e7f860deb821cc4206f2a", "max_stars_repo_licenses": ["MIT"], "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-sets-tuples", "max_issues_repo_head_hexsha": "673adf4e8547103c8b4e7f860deb821cc4206f2a", "max_issues_repo_licenses": ["MIT"], "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-sets-tuples", "max_forks_repo_head_hexsha": "673adf4e8547103c8b4e7f860deb821cc4206f2a", "max_forks_repo_licenses": ["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.0423280423, "max_line_length": 197, "alphanum_fraction": 0.6194950088, "num_tokens": 2457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240721511739, "lm_q2_score": 0.899121375242593, "lm_q1q2_score": 0.77794145764556}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 21, 2022}\n\\subsection{Elliptic Curve Elgamal}\nAs usual, we have some public knowledge, private key, and public key. The idea  is to replace multiplication in $\\FF_p^\\times$ with addition on $E$.\n\\begin{mdframed}\n    \\ul{Public Knowledge}: \\\\\n    $p$ --- prime. \\\\\n    $E$ --- elliptic curve over $\\FF_p$. \\\\\n    $P \\in E(\\FF_p)$ --- point.\n\n    \\ul{Private Key}: \\\\\n    $n$ --- private key.\n\n    \\ul{Public Key}: \\\\\n    $Q = n\\cdot P$ --- public key.\n\n    \\ul{Encrpytion}: \\\\\n    Bob has a message $M\\in E(\\FF_p)$.\n    \\begin{enumerate}\n        \\item Choose random $k$.\n        \\item Compute\n              \\begin{align*}\n                  C_1 & = k\\cdot P     \\\\\n                  C_2 & = M + k\\cdot Q\n              \\end{align*}\n              Send $(C_1, C_2)$ to Alice.\n    \\end{enumerate}\n\n    \\ul{Decryption}: \\\\\n    Alice will compute\n    \\[C_2 - n\\cdot C_1 = M + k\\cdot Q - nk\\cdot P = M\\]\n\\end{mdframed}\n\nWe now implement this:\n\n\\begin{lstlisting}\nfrom ec import ext_gcd, add, minus, multiply\n\n# Private key for Alice\nn = randrange(q)\n\n# Public key for Alice\nQ = multiply(P, n, a, p)\n\ndef e(Q, M):\n    \"\"\"Encryption Function\"\"\"\n    k = randrange(q)\n    c1 = multiply(P, k, a, p)\n    c2 = add(M, multiply(Q, k, a, p), a, p)\n    return (c1, c2)\n\ndef d(n, C):\n    \"\"\"Decryption Function\"\"\"\n    c1, c2 = C\n    return add(c2, minus(multiply(c1, n, a, p), p), a, p)\n\\end{lstlisting}\n\nThe expansion factor is $2$. Even if we think of putting our message into only the $x$ coordinate, the $y$ coordinate is determined by the $x$ coordinate so the factor is still $2$.\n\n\\subsection{Elliptic Curve DSA}\nSince we have Elgamal, we can also have DSA with Elliptic Curves.\n\\begin{mdframed}\n    \\ul{Public Knowledge \\& Public Key}: \\\\\n    \\emph{Same as Elgamal} \\\\\n    $p$ --- prime. \\\\\n    $E$ --- elliptic curve over $\\FF_p$. \\\\\n    $Q = n\\cdot P$ --- public key.\n\n    \\ul{Private Key}: \\\\\n    $n$ --- private key.\n\n    \\ul{Signing}: \\\\\n    Alice has document $d\\in \\ZZ/q\\ZZ$.\n    \\begin{enumerate}\n        \\item Choose random $k$.\n        \\item Compute $(x, y) = k\\cdot P$.\n              \\begin{align*}\n                  s_1 & = x                               \\\\\n                  s_2 & = (d + ns_1)\\cdot k^{-1} \\pmod{q}\n              \\end{align*}\n    \\end{enumerate}\n\n    \\ul{Verification}: \\\\\n    We can verify the signature as follows:\n    \\begin{align*}\n        v_1 & = d\\cdot s_2^{-1} \\pmod{q} \\\\\n        v_2 & = s_1s_2^{-1} \\pmod{q}\n    \\end{align*}\n    \\begin{align*}\n        v_1\\cdot P + v_2\\cdot Q & = ds_2^{-1}\\cdot P + s_1s_2^{-1} k\\cdot P \\\\\n                                & = (d + s_1 n)s_2^{-1} P                   \\\\\n                                & = k P\n    \\end{align*}\n    $(\\text{$x$-coord of }v_1P + v_2Q) = s_1$ check to verify signature.\n\\end{mdframed}\n\nAgain, we can implement this: \n\\begin{lstlisting}\nfrom ec import *\n\ndef sign(n, d):\n    \"\"\"Signing document d with private key n\"\"\"\n    k = randrange(q)\n    x, _ = multiply(P, k, a, p)\n    s1 = x\n    s2 = ((d + n * s1) * ext_gcd(k, q)[0]) % q\n    return (s1, s2)\n\ndef verify(Q, d, s):\n    \"\"\"Verifies document d's signature s with public key Q\"\"\"\n    s1, s2 = s\n    v1 = (d * ext_gcd(s2, q)[0]) % q\n    v2 = (s1 * ext_gcd(s2, q)[0]) % q\n    return add(multiply(P, v1, a, p), multiply(Q, v2, a, p), a, p)[0] == s1\n\\end{lstlisting}\n\n\\begin{remark}\n    The specific numbers used in lecture is the elliptic curve used in the Bitcoin blockchain. Being able to forge signatures in this elliptic curve is to topple the Bitcoin market. \n\\end{remark}", "meta": {"hexsha": "cc7d952e3a049b6f101aa89c83e3549a4ffce606", "size": 3556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-21.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-03-21.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-03-21.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": 29.8823529412, "max_line_length": 182, "alphanum_fraction": 0.5430258718, "num_tokens": 1177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9597620585273153, "lm_q2_score": 0.8104789086703224, "lm_q1q2_score": 0.7778669057784006}}
{"text": "\\section*{Exercise 26.2-2}\n\\subsubsection*{What is the flow and cut}\nLet the cut be given as in the exercise, then the flow across the cut (and all other cuts) in figure~26.1(b) is \n\\begin{align*}\nf(S,T) &= f(\\{s, v_2, v_4\\},\\{v_1, v_3,t\\}) = \\sum_{u \\in S}\\sum_{v \\in T} f(u,v) - \\sum_{u \\in S}\\sum_{v \\in T} f(v,u) \\\\\n       &= 11 + 1 + 7 + 4 - 4 = 19\n\\end{align*}\nThe capacity is\n$$\nC(S,T) = \\sum_{u \\in S}\\sum_{v \\in T} c(u,v) = 16 + 4 + 7 + 4 =31\n$$", "meta": {"hexsha": "7352531fc57546638cb19a038d3775065ecbc575", "size": 454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge1/Ex.26.2.2.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge1/Ex.26.2.2.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge1/Ex.26.2.2.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.2727272727, "max_line_length": 122, "alphanum_fraction": 0.5682819383, "num_tokens": 206, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789547, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.777761978172852}}
{"text": "%!TEX root = da2020-02.tex\n\n\\Chapter{2}{Graph-Theoretic Foundations}\n\n\\noindent\nThe study of distributed algorithms is closely related to graphs: we will interpret a computer network as a graph, and we will study computational problems related to this graph. In this section we will give a summary of the graph-theoretic concepts that we will use.\n\n\\section{Terminology}\n\nA \\emph{simple undirected graph} is a pair $G = (V,E)$, where $V$ is the set of \\emph{nodes} (\\emph{vertices}) and $E$ is the set of \\emph{edges}. Each edge $e \\in E$ is a 2-subset of nodes, that is, $e = \\{u,v\\}$ where $u \\in V$, $v \\in V$, and $u \\ne v$. Unless otherwise mentioned, we assume that $V$ is a non-empty finite set; it follows that $E$ is a finite set. Usually, we will draw graphs using circles and lines\\mydash each circle represents a node, and a line that connects two nodes represents an edge.\n\n\n\\subsection{Adjacency}\n\nIf $e = \\{u,v\\} \\in E$, we say that node $u$ is \\emph{adjacent} to $v$, nodes $u$ and $v$ are \\emph{neighbors}, node $u$ is \\emph{incident} to $e$, and edge $e$ is also \\emph{incident} to $u$. If $e_1, e_2 \\in E$, $e_1 \\ne e_2$, and $e_1 \\cap e_2 \\ne \\emptyset$ (i.e., $e_1$ and $e_2$ are distinct edges that share an endpoint), we say that $e_1$ is \\emph{adjacent} to $e_2$.\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PGraph]{figs.pdf}\n    \\caption{Node $u$ is adjacent to node $v$. Nodes $u$ and $v$ are incident to edge $e$. Edge $e_1$ is adjacent to edge $e_2$.}\\label{fig:graph}\n\\end{figure}\n\nThe \\emph{degree} of a node $v \\in V$ in graph $G$ is \\[\n    \\deg_G(v) = \\bigl|\\bigSet{ u \\in V : \\{u,v\\} \\in E }\\bigr|.\n\\]\nThat is, $v$ has $\\deg_G(v)$ neighbors; it is adjacent to $\\deg_G(v)$ nodes and incident to $\\deg_G(v)$ edges. A node $v \\in V$ is \\emph{isolated} if $\\deg_G(v) = 0$. Graph $G$ is \\emph{\\Reg{k}} if $\\deg_G(v) = k$ for each $v \\in V$.\n\n\n\\subsection{Subgraphs}\n\nLet $G = (V,E)$ and $H = (V_2,E_2)$ be two graphs. If $V_2 \\subseteq V$ and $E_2 \\subseteq E$, we say that $H$ is a \\emph{subgraph} of $G$. If $V_2 = V$, we say that $H$ is a \\emph{spanning subgraph} of $G$.\n\nIf $V_2 \\subseteq V$ and $E_2 = \\Set{ \\{u,v\\} \\in E : u \\in V_2,\\ v \\in V_2 }$, we say that $H = (V_2,E_2)$ is an \\emph{induced subgraph}; more specifically, $H$ is the subgraph of $G$ induced by the set of nodes $V_2$.\n\nIf $E_2 \\subseteq E$ and $V_2 = \\bigcup E_2$, we say that $H$ is an \\emph{edge-induced subgraph}; more specifically, $H$ is the subgraph of $G$ induced by the set of edges $E_2$.\n\n\n\\subsection{Walks}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PWalk]{figs.pdf}\n    \\caption{\n        (a)~A walk of length~5 from $s$ to $t$.\n        (b)~A non-backtracking walk.\n        (c)~A path of length~4.\n        (d)~A path of length~2; this is a shortest path and hence $\\dist_G(s,t) = 2$.\n    }\\label{fig:walk}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PCycle]{figs.pdf}\n    \\caption{\n        (a)~A cycle of length~6.\n        (b)~A cycle of length~3; this is a shortest cycle and hence the girth of the graph is~$3$.\n    }\\label{fig:cycle}\n\\end{figure}\n\nA \\emph{walk} of length $\\ell$ from node $v_0$ to node $v_\\ell$ is an alternating sequence \\[w = (v_0, e_1, v_1, e_2, v_2, \\dotsc, e_\\ell, v_\\ell)\\] where $v_i \\in V$, $e_i \\in E$, and $e_i = \\{ v_{i-1}, v_i \\}$ for all $i$; see Figure~\\ref{fig:walk}. The walk is \\emph{empty} if $\\ell = 0$. We say that walk~$w$ \\emph{visits} the nodes $v_0, v_1, \\dotsc, v_\\ell$, and it \\emph{traverses} the edges $e_1, e_2, \\dotsc, e_\\ell$. In general, a walk may visit the same node more than once and it may traverse the same edge more than once. A \\emph{non-backtracking walk} does not traverse the same edge twice consecutively, that is, $e_{i-1} \\ne e_i$ for all $i$. A \\emph{path} is a walk that visits each node at most once, that is, $v_i \\ne v_j$ for all $0 \\le i < j \\le \\ell$. A walk is \\emph{closed} if $v_0 = v_\\ell$. A \\emph{cycle} is a non-empty closed walk with $v_i \\ne v_j$ and $e_i \\ne e_j$ for all $1 \\le i < j \\le \\ell$; see Figure~\\ref{fig:cycle}. Note that the length of a cycle is at least~$3$.\n\n\n\\subsection{Connectivity and Distances}\\label{ssec:graphs-conn}\n\nFor each graph $G = (V,E)$, we can define a relation $\\leadsto$ on $V$ as follows: $u \\leadsto v$ if there is a walk from $u$ to $v$. Clearly $\\leadsto$ is an equivalence relation. Let $C \\subseteq V$ be an equivalence class; the subgraph induced by $C$ is called a \\emph{connected component} of $G$.\n\nIf $u$ and $v$ are in the same connected component, there is at least one \\emph{shortest path} from $u$ to $v$, that is, a path from $u$ to $v$ of the smallest possible length. Let $\\ell$ be the length of a shortest path from $u$ to $v$; we define that the \\emph{distance} between $u$ and $v$ in $G$ is $\\dist_G(u,v) = \\ell$. If $u$ and $v$ are not in the same connected component, we define $\\dist_G(u,v) = \\infty$. Note that $\\dist_G(u,u) = 0$ for any node $u$.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PNeighbourhood]{figs.pdf}\n    \\caption{Neighborhoods.}\\label{fig:neighborhood}\n\\end{figure}\nFor each node $v$ and for a non-negative integer $r$, we define the \\emph{radius-$r$ neighborhood} of $v$ as follows (see Figure~\\ref{fig:neighborhood}):\n\\[\n    \\ball_G(v, r) = \\Set{ u \\in V : \\dist_G(u,v) \\le r }.\n\\]\n\nA graph is \\emph{connected} if it consists of one connected component. The \\emph{diameter} of graph $G$, in notation $\\diam(G)$, is the length of a longest shortest path, that is, the maximum of $\\dist_G(u,v)$ over all $u, v \\in V$; we have $\\diam(G) = \\infty$ if the graph is not connected.\n\nThe \\emph{girth} of graph $G$ is the length of a shortest cycle in $G$. If the graph does not have any cycles, we define that the girth is $\\infty$; in that case we say that $G$ is \\emph{acyclic}.\n\nA \\emph{tree} is a connected, acyclic graph. If $T = (V,E)$ is a tree and $u,v \\in V$, then there exists precisely one path from $u$ to $v$. An acyclic graph is also known as a \\emph{forest}\\mydash in a forest each connected component is a tree. A \\emph{pseudotree} has at most one cycle, and in a \\emph{pseudoforest} each connected component is a pseudotree.\n\nA \\emph{path graph} is a graph that consists of one path, and a \\emph{cycle graph} is a graph that consists of one cycle. Put otherwise, a path graph is a tree in which all nodes have degree at most $2$, and a cycle graph is a \\Reg{2} pseudotree. Note that any graph of maximum degree $2$ consists of disjoint paths and cycles, and any \\Reg{2} graph consists of disjoint cycles.\n\n\n\\subsection{Isomorphism}\n\nAn \\emph{isomorphism} from graph $G_1 = (V_1,E_1)$ to graph $G_2 = (V_2,E_2)$ is a bijection $f\\colon V_1 \\to V_2$ that preserves adjacency: $\\{u,v\\} \\in E_1$ if and only if $\\{f(u),f(v)\\} \\in E_2$. If an isomorphism from $G_1$ to $G_2$ exists, we say that $G_1$ and $G_2$ are isomorphic.\n\nIf $G_1$ and $G_2$ are isomorphic, they have the same structure; informally, $G_2$ can be constructed by renaming the nodes of $G_1$ and vice versa.\n\n\n\\section{Packing and Covering}\\label{sec:packingcovering}\n\nA subset of nodes $X \\subseteq V$ is\n\\begin{enumerate}\n    \\item an \\emph{independent set} if each edge has at most one endpoint in $X$, that is, $|e \\cap X| \\le 1$ for all $e \\in E$,\n    \\item a \\emph{vertex cover} if each edge has at least one endpoint in $X$, that is, $e \\cap X \\ne \\emptyset$ for all $e \\in E$,\n    \\item a \\emph{dominating set} if each node $v \\notin X$ has at least one neighbor in $X$, that is, $\\ball_G(v,1) \\cap X \\ne \\emptyset$ for all $v \\in V$.\n\\end{enumerate}\nA subset of edges $X \\subseteq E$ is\n\\begin{enumerate}[resume]\n    \\item a \\emph{matching} if each node has at most one incident edge in $X$, that is, $\\{t,u\\} \\in X$ and $\\{t,v\\} \\in X$ implies $u = v$,\n    \\item an \\emph{edge cover} if each node has at least one incident edge in $X$, that is, $\\bigcup X = V$,\n    \\item an \\emph{edge dominating set} if each edge $e \\notin X$ has at least one neighbor in $X$, that is, $e \\cap \\bigl(\\bigcup X\\bigr) \\ne \\emptyset$ for all $e \\in E$.\n\\end{enumerate}\nSee Figure~\\ref{fig:packingcovering} for illustrations.\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PPackingCovering]{figs.pdf}\n    \\caption{Packing and covering problems; see Section~\\ref{sec:packingcovering}.}\\label{fig:packingcovering}\n\\end{figure}\n\nIndependent sets and matchings are examples of \\emph{packing problems}\\mydash intuitively, we have to ``pack'' elements into set $X$ while avoiding conflicts. Packing problems are \\emph{maximization problems}. Typically, it is trivial to find a feasible solution (for example, an empty set), but it is more challenging to find a large solution.\n\nVertex covers, edge covers, dominating sets, and edge dominating sets are examples of \\emph{covering problems}\\mydash intuitively, we have to find a set $X$ that ``covers'' the relevant parts of the graph. Covering problems are \\emph{minimization problems}. Typically, it is trivial to find a feasible solution if it exists (for example, the set of all nodes or all edges), but it is more challenging to find a small solution.\n\nThe following terms are commonly used in the context of maximization problems; it is important not to confuse them:\n\\begin{enumerate}\n    \\item \\textbf{\\emph{maximal}}: a maximal solution is not a proper subset of another feasible solution,\n    \\item \\textbf{\\emph{maximum}}: a maximum solution is a solution of the largest possible cardinality.\n\\end{enumerate}\nSimilarly, in the context of minimization problems, analogous terms are used:\n\\begin{enumerate}\n    \\item \\textbf{\\emph{minimal}}: a minimal solution is not a proper superset of another feasible solution,\n    \\item \\textbf{\\emph{minimum}}: a minimum solution is a solution of the smallest possible cardinality.\n\\end{enumerate}\nUsing this convention, we can define the terms \\emph{maximal independent set}, \\emph{maximum independent set}, \\emph{maximal matching}, \\emph{maximum matching}, \\emph{minimal vertex cover}, \\emph{minimum vertex cover}, etc.\n\nFor example, Figure~\\ref{fig:packingcovering}a shows a maximal independent set: it is not possible to greedily extend the set by adding another element. However, it is not a maximum independent set: there exists an independent set of size $3$. Figure~\\ref{fig:packingcovering}d shows a matching, but it is not a maximal matching, and therefore it is not a maximum matching either.\n\nTypically, maximal and minimal solutions are easy to find\\mydash you can apply a greedy algorithm. However, maximum and minimum solutions can be very difficult to find\\mydash many of these problems are NP-hard optimization problems.\n\nA \\emph{minimum maximal matching} is precisely what the name suggests: it is a maximal matching of the smallest possible cardinality. We can define a \\emph{minimum maximal independent set}, etc., in an analogous manner.\n\n\n\\section{Labelings and Partitions}\\label{sec:partitions}\n\nWe will often encounter functions of the form \\[f\\colon V \\to \\{1,2,\\dotsc,k\\}.\\] There are two interpretations that are often helpful:\n\\begin{enumerate}[label=(\\roman*)]\n    \\item Function $f$ assigns a \\emph{label} $f(v)$ to each node $v \\in V$. Depending on the context, the labels can be interpreted as colors, time slots, etc.\n    \\item Function $f$ is a \\emph{partition} of $V$. More specifically, $f$ defines a partition $V = V_1 \\cup V_2 \\cup \\dotsb \\cup V_k$ where $V_i = f^{-1}(i) = \\Set{ v \\in V : f(v) = i }$.\n\\end{enumerate}\nSimilarly, we can study a function of the form \\[f\\colon E \\to \\{1,2,\\dotsc,k\\}\\] and interpret it either as a labeling of edges or as a partition of~$E$.\n\nMany graph problems are related to such functions. We say that a function $f\\colon V \\to \\{1,2,\\dotsc,k\\}$ is\n\\begin{enumerate}\n    \\item a \\emph{proper vertex coloring} if $f^{-1}(i)$ is an independent set for each~$i$,\n    \\item a \\emph{weak coloring} if each non-isolated node $u$ has a neighbor $v$ with $f(u) \\ne f(v)$,\n    \\item a \\emph{domatic partition} if $f^{-1}(i)$ is a dominating set for each~$i$.\n\\end{enumerate}\nA function $f\\colon E \\to \\{1,2,\\dotsc,k\\}$ is\n\\begin{enumerate}[resume]\n    \\item a \\emph{proper edge coloring} if $f^{-1}(i)$ is a matching for each~$i$,\n    \\item an \\emph{edge domatic partition} if $f^{-1}(i)$ is an edge dominating set for each~$i$.\n\\end{enumerate}\nSee Figure~\\ref{fig:partitions} for illustrations.\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PPartitions]{figs.pdf}\n    \\caption{Partition problems; see Section~\\ref{sec:partitions}.}\\label{fig:partitions}\n\\end{figure}\n\nUsually, the term \\emph{coloring} refers to a proper vertex coloring, and the term \\emph{edge coloring} refers to a proper edge coloring. The value of $k$ is the \\emph{size} of the coloring or the \\emph{number of colors}. We will use the term \\emph{$k$-coloring} to refer to a proper vertex coloring with $k$ colors; the term \\emph{$k$-edge coloring} is defined in an analogous manner.\n\nA graph that admits a $2$-coloring is a \\emph{bipartite graph}. Equivalently, a bipartite graph is a graph that does not have an odd cycle.\n\nGraph coloring is typically interpreted as a minimization problem. It is easy to find a proper vertex coloring or a proper edge coloring if we can use arbitrarily many colors; however, it is difficult to find an \\emph{optimal} coloring that uses the smallest possible number of colors.\n\nOn the other hand, domatic partitions are a maximization problem. It is trivial to find a domatic partition of size $1$; however, it is difficult to find an \\emph{optimal} domatic partition with the largest possible number of disjoint dominating sets.\n\n\n\\section{Factors and Factorizations}\n\nLet $G = (V,E)$ be a graph, let $X \\subseteq E$ be a set of edges, and let $H = (U,X)$ be the subgraph of $G$ induced by $X$. We say that $X$ is a \\emph{$d$-factor} of $G$ if $U = V$ and $\\deg_H(v) = d$ for each $v \\in V$.\n\nEquivalently, $X$ is a $d$-factor if $X$ induces a spanning \\Reg{d} subgraph of $G$. Put otherwise, $X$ is a $d$-factor if each node $v \\in V$ is incident to exactly $d$ edges of $X$.\n\nA function $f\\colon E \\to \\{1,2,\\dotsc,k\\}$ is a \\emph{\\Fact{d}} of $G$ if $f^{-1}(i)$ is a $d$-factor for each $i$. See Figure~\\ref{fig:factorization} for examples.\n\\begin{figure}\n    \\centering\n    \\includegraphics[page=\\PFactorisation]{figs.pdf}\n    \\caption{\n        (a)~A \\Fact{1} of a \\Reg{3} graph.\n        (b)~A \\Fact{2} of a \\Reg{4} graph.\n    }\\label{fig:factorization}\n\\end{figure}\n\nWe make the following observations:\n\\begin{enumerate}\n    \\item A $1$-factor is a maximum matching. If a $1$-factor exists, a maximum matching is a $1$-factor.\n    \\item A \\Fact{1} is an edge coloring.\n    \\item The subgraph induced by a $2$-factor consists of disjoint cycles.\n\\end{enumerate}\nA $1$-factor is also known as a \\emph{perfect matching}.\n\n\n\\section{Approximations}\n\nSo far we have encountered a number of maximization problems and minimization problems. More formally, the definition of a maximization problem consists of two parts: a set of \\emph{feasible solutions} $\\calS$ and an \\emph{objective function} $g\\colon \\calS \\to \\RR$. In a maximization problem, the goal is to find a feasible solution $X \\in \\calS$ that maximizes $g(X)$. A minimization problem is analogous: the goal is to find a feasible solution $X \\in \\calS$ that minimizes $g(X)$.\n\nFor example, the problem of finding a maximum matching for a graph $G$ is of this form. The set of feasible solutions $\\calS$ consists of all matchings in $G$, and we simply define $g(M) = |M|$ for each matching $M \\in \\calS$.\n\nAs another example, the problem of finding an optimal coloring is a minimization problem. The set of feasible solutions $\\calS$ consists of all proper vertex colorings, and $g(f)$ is the number of colors in $f \\in \\calS$.\n\nOften, it is infeasible or impossible to find an optimal solution; hence we resort to approximations. Given a maximization problem $(\\calS,g)$, we say that a solution $X$ is an \\emph{\\Apx{\\alpha}} if $X \\in \\calS$, and we have $\\alpha g(X) \\ge g(Y)$ for all $Y \\in \\calS$. That is, $X$ is a feasible solution, and the size of $X$ is within factor $\\alpha$ of the optimum.\n\nSimilarly, if $(\\calS,g)$ is a minimization problem, we say that a solution $X$ is an \\Apx{\\alpha} if $X \\in \\calS$, and we have $g(X) \\le \\alpha g(Y)$ for all $Y \\in \\calS$. That is, $X$ is a feasible solution, and the size of $X$ is within factor $\\alpha$ of the optimum.\n\nNote that we follow the convention that the approximation ratio $\\alpha$ is always at least $1$, both in the case of minimization problems and maximization problems. Other conventions are also used in the literature.\n\n\n\\section{Directed Graphs and Orientations}\n\nUnless otherwise mentioned, all graphs that we encounter are undirected. However, we will occasionally need to refer to so-called orientations, and hence we need to introduce some terminology related to directed graphs.\n\nA \\emph{directed graph} is a pair $G = (V,E)$, where $V$ is the set of nodes and $E$ is the set of \\emph{directed edges}. Each edge $e \\in E$ is a pair of nodes, that is, $e = (u,v)$ where $u, v \\in V$. Put otherwise, $E \\subseteq V \\times V$.\n\nIntuitively, an edge $(u,v)$ is an ``arrow'' that points from node $u$ to node $v$; it is an \\emph{outgoing edge} for $u$ and an \\emph{incoming edge} for $v$. The \\emph{outdegree} of a node $v \\in V$, in notation $\\outdegree_G(v)$, is the number of outgoing edges, and the \\emph{indegree} of the node, $\\indegree_G(v)$, is the number of incoming edges.\n\nNow let $G = (V,E)$ be a graph and let $H = (V,E')$ be a directed graph with the same set of nodes. We say that $H$ is an \\emph{orientation} of $G$ if the following holds:\n\\begin{enumerate}\n    \\item For each $\\{u,v\\} \\in E$ we have either $(u,v) \\in E'$ or $(v,u) \\in E'$, but not both.\n    \\item For each $(u,v) \\in E'$ we have $\\{u,v\\} \\in E$.\n\\end{enumerate}\nPut otherwise, in an orientation of $G$ we have simply chosen an arbitrary direction for each undirected edge of $G$. It follows that \\[\\indegree_H(v) + \\outdegree_H(v) = \\deg_G(v)\\] for all $v \\in V$.\n\n\\section{Quiz}\n\nConstruct a simple undirected graph $G = (V,E)$ with the following property: If you take any set $X$ that is a maximal independent set of $G$, then $X$ is not a minimum dominating set of $G$.\n\nPresent the graph in the set formalism by listing the sets of nodes and edges. For example, a cycle on three nodes can be encoded as $V = \\{1,2,3\\}$ and $E = \\{ \\{1,2\\}, \\{2,3\\}, \\{3,1\\} \\}$.\n\n\\section{Exercises}\n\n\\begin{ex}[independence and vertex covers]\n    Let $I \\subseteq V$ and define $C = V \\setminus I$. Show that\n    \\begin{subex}\n        \\item if $I$ is an independent set then $C$ is a vertex cover and vice versa,\n        \\item if $I$ is a maximal independent set then $C$ is a minimal vertex cover and vice versa,\n        \\item if $I$ is a maximum independent set then $C$ is a minimum vertex cover and vice versa,\n        \\item it is possible that $C$ is a \\Apx{2} of minimum vertex cover but $I$ is not a \\Apx{2} of maximum independent set,\n        \\item it is possible that $I$ is a \\Apx{2} of maximum independent set but $C$ is not a \\Apx{2} of minimum vertex cover.\n    \\end{subex}\n\\end{ex}\n\n\\begin{ex}[matchings]\n    Show that\n    \\begin{subex}\n        \\item any maximal matching is a \\Apx{2} of a maximum matching,\n        \\item any maximal matching is a \\Apx{2} of a minimum maximal matching,\n        \\item a maximal independent set is not necessarily a \\Apx{2} of maximum independent set,\n        \\item a maximal independent set is not necessarily a \\Apx{2} of minimum maximal independent set.\n    \\end{subex}\n\\end{ex}\n\n\\begin{ex}[matchings and vertex covers]\\label{ex:mmvc}\n    Let $M$ be a maximal matching, and let $C = \\bigcup M$, i.e., $C$ consists of all endpoints of matched edges. Show that\n    \\begin{subex}\n        \\item $C$ is a \\Apx{2} of a minimum vertex cover,\n        \\item $C$ is not necessarily a \\Apx{1.999} of a minimum vertex cover.\n    \\end{subex}\n    Would you be able to improve the approximation ratio if $M$ was a minimum maximal matching?\n\\end{ex}\n\n\\begin{ex}[independence and domination]\n    Show that\n    \\begin{subex}\n        \\item a maximal independent set is a minimal dominating set,\n        \\item a minimal dominating set is not necessarily a maximal independent set,\n        \\item a minimum maximal independent set is not necessarily a minimum dominating set.\n    \\end{subex}\n\\end{ex}\n\n\\begin{ex}[graph colorings and partitions]\n    Show that\n    \\begin{subex}\n        \\item a weak $2$-coloring always exists,\n        \\item a domatic partition of size $2$ does not necessarily exist,\n        \\item if a domatic partition of size $2$ exists, then a weak $2$-coloring is a domatic partition of size $2$,\n        \\item a weak $2$-coloring is not necessarily a domatic partition of size $2$.\n    \\end{subex}\n    Show that there are \\Reg{2} graphs with the following properties:\n    \\begin{subex}[resume]\n        \\item any $3$-coloring is a domatic partition of size $3$,\n        \\item no $3$-coloring is a domatic partition of size $3$.\n    \\end{subex}\n    Assume that $G$ is a graph of maximum degree $\\Delta$; show that\n    \\begin{subex}[resume]\n        \\item there exists a \\Dpocol,\n        \\item a $\\Delta$-coloring does not necessarily exist.\n    \\end{subex}\n\\end{ex}\n\n\\begin{ex}[isomorphism]\n    Construct non-empty \\Reg{3} connected graphs $G$ and $H$ such that $G$ and $H$ have the same number of nodes and $G$ and $H$ are \\emph{not} isomorphic. Just giving a construction is not sufficient\\mydash you have to \\emph{prove} that $G$ and $H$ are not isomorphic.\n\\end{ex}\n\n\\begin{exs}[matchings and edge domination]\\label{ex:mmeds}\n    Show that\n    \\begin{subex}\n        \\item a maximal matching is a minimal edge dominating set,\n        \\item a minimal edge dominating set is not necessarily a maximal matching,\n        \\item a minimum maximal matching is a minimum edge dominating set,\n        \\item any maximal matching is a \\Apx{2} of a minimum edge dominating set.\n    \\end{subex}\n    \\hint{Assume that $D$ is an edge dominating set; show that you can construct a maximal matching $M$ with $|M| \\le |D|$.}\n\\end{exs}\n\n\\begin{exs}[Petersen 1891]\\label{ex:2fact}\n    Show that any \\Reg{2d} graph $G = (V,E)$ has an orientation $H = (V,E')$ such that \\[\\indegree_H(v) = \\outdegree_H(v) = d\\] for all $v \\in V$. Show that any \\Reg{2d} graph has a \\Fact{2}.\n\\end{exs}\n\n\n\\section{Bibliographic Notes}\n\nThe connection between maximal matchings and approximations of vertex covers (Exercise~\\ref{ex:mmvc}) is commonly attributed to Gavril and Yannakakis\\mydash see, e.g., Papadimitriou and Steiglitz \\cite{papadimitriou98combinatorial}. The connection between minimum maximal matchings and minimum edge dominating sets (Exercise~\\ref{ex:mmeds}) is due to Allan and Laskar~\\cite{allan78domination} and Yannakakis and Gavril~\\cite{yannakakis80edge}. Exercise~\\ref{ex:2fact} is a 120-year-old result due to Petersen~\\cite{petersen1891dietheorie}. The definition of a weak coloring is from Naor and Stockmeyer~\\cite{naor95what}.\n\nDiestel's book~\\cite{diestel05graph} is a good source for graph-theoretic background, and Vazirani's book~\\cite{vazirani01approximation} provides further information on approximation algorithms.\n", "meta": {"hexsha": "dab634a138a32b09bda212efe831aeb254e18a31", "size": 23267, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "book/ch02.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/ch02.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/ch02.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": 72.4828660436, "max_line_length": 1004, "alphanum_fraction": 0.7003051532, "num_tokens": 7151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8933094145755219, "lm_q1q2_score": 0.7777127391721721}}
{"text": "\n\n\\vspace{-7mm}\nThis chapter gives routines for computing rotation matrices that operate on the expansion coefficients of spherical harmonics and spherical wave functions in order to rotate fields or view fields from a rotated frame.  The rotation matrices work the same for any of the wave functions in Chapter \\ref{chap:wavefunctions}.\n\n\\section{Euler Rotation}\n3D rotation of a Cartesian reference frame can be accomplished with three Euler angles $(\\alpha,\\beta,\\gamma)$, where the sequence rotates the frame successively about one of its axes. The angles can take any value of radians. The most common rotation sequence is denoted Z-X'-Z'', sometimes just called ZXZ. This consists of a right-handed rotation of $\\alpha$ about the $z$ axis, followed by a right-handed rotation of $\\beta$ about the $x$ axis of the rotated frame (X'), followed by a right-handed rotation of $\\gamma$ about the $z$ axis of the rotated frame (Z''). This is represented in a rotation matrix as:\n\\ea{\n\\bb{R}_{ZX'Z''}(\\alpha,\\beta,\\gamma) &=& \\bb{R}_{Z}(\\alpha)\\bb{R}_{X}(\\beta)\\bb{R}_{Z}(\\gamma) \\\\\n\\ &= &\n \\thbth{\\cos(\\alpha)}{-\\sin(\\alpha)}{0} {\\sin(\\alpha)}{ \\cos(\\alpha)}{ 0} {0}{ 0}{ 1}\\thbth{1}{ 0}{ 0}{0 }{\\cos(\\beta)}{ -\\sin(\\beta)}{0}{ \\sin(\\beta) }{\\cos(\\beta)}\\thbth{\\cos(\\gamma)}{ -\\sin(\\gamma)}{ 0} {\\sin(\\gamma)}{ \\cos(\\gamma) }{0}  {0 }{0 }{1} \\label{rot}\n}\nEach matrix is a right-handed rotation about the axes of the unrotated, or fixed, global frame. The reason the matrices are applied in what seems like reverse order, and applied about the axes of the fixed frame, is because each new matrix stacks the rotations in front of it. This creates the effect that each rotation was applied about the axes of the rotated frame in the order $(\\alpha,\\beta,\\gamma)$.\n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=6.5in]{Rotation/Figures/ZXZ} \n   \\caption{ZX'Z'' rotation sequence $(\\alpha,\\beta,\\gamma) = (\\pi/6, \\pi/5, \\pi/4)$.  First pane shows the rotation of $\\alpha$ about the $z$ axis from the original Cartesian frame (black dotted) to the new frame (red/blue/green). Second pane shows the second rotation of $\\beta$ about the $x$ axis of the previously rotated frame. Third pane shows the final rotation of $\\gamma$ about the $z$ axis of the previously rotated frame.}\n   \\label{fig1}\n\\end{figure}\n\n\nA point $\\bb{x} = [x, y, z]^t$ that in the global frame is rotated to the point $\\bb{x}' = [x',y',z']^t$ as\n\\begin{equation}\n\\bb{x}' = \\bb{R}\\bb{x}\n\\end{equation}\n\n\\noindent In other words, the point is rotated through the global frame as though you are standing in the global frame. We call this a forward rotation. $\\bb{R}$ is unitary, so the inverse is equal to the transpose, and \n\\begin{equation}\n\\bb{x} = \\bb{R}^t\\bb{x}'\n\\end{equation}\n\nThe inverse rotation brings the point back, and applies the Euler angles in the reverse order and reverse direction. Given a forward set of angles $(\\alpha,\\beta,\\gamma)$, applying the inverse is equivalent to fixing a point in the global frame and seeing it as you ride along with the rotating frame. We call this the inverse rotation.\n\nDetermining the ZXZ Euler angles from a rotation matrix is done with \n\\begin{eqnarray}\n\\alpha & =& \\arctan \\dfrac{R_{13}}{-R_{23}} \\\\\n\\beta & =& \\arctan \\dfrac{\\sqrt{R_{13}^2 + R_{23}^2} }{R_{33}}\\\\\n\\gamma &=& \\arctan \\dfrac{R_{31}}{R_{32}} \n\\end{eqnarray}\n\n\\noindent where $R_{ij}$ are the matrix entries of $\\bb{R}$. \n\nThe rotation matrix and Euler angle conversions are given in the routines \\texttt{euler2rot} and \\texttt{rot2euler}. A plotting function,  \\texttt{plotrot}, not copied here, will plot the axes of the rotated frame given $\\bb{R}$. \n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/euler2rot.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/rot2euler.m}\n}\n\n%{\\footnotesize\n%\\VerbatimInput{\\code/Rotation/plotrot.m}\n%}\n\n\n\n\\clearpage\n\\section{Rotation Addition Theorem}\n\nThe rotation addition theorem for spherical harmonics is given by  \n\\begin{equation}\nY_{lm}(\\theta,\\phi) = \\sum_{p=-l}^{l} D_{lmp}(\\alpha,\\beta,\\gamma) Y_{lp}(\\theta',\\phi')\n\\end{equation}\n\n\\noindent where $(\\alpha,\\beta,\\gamma)$ are the three Euler angles describing a ZXZ rotation from unprimed to primed coordinate systems. $D_{lmp}$ is the rotation matrix for spherical harmonics. Because the coordinate $r$ and the gradient are invariant under rotation, the rotation addition theorem for scalar and vector wave functions have identical forms \\cite{edmonds1996angular,hansen1988spherical,stein1961addition,dufva2008unified},\n\\begin{equation}\n\\psi_{lm}(r,\\theta,\\phi) = \\sum_{p=-l}^{l} D_{lmp}(\\alpha,\\beta,\\gamma) \\psi_{lp}(r',\\theta',\\phi')\n\\end{equation}\n\\begin{equation}\n\\bb{M}_{lm}(r,\\theta,\\phi) = \\sum_{p=-l}^{l} D_{lmp}(\\alpha,\\beta,\\gamma)\\bb{M}_{lp}'(r',\\theta',\\phi')\n\\end{equation}\n\nThis means that the same $D_{lmp}$ can be used to rotate any of following: spherical harmonics, scalar spherical wave functions, vector spherical harmonics, or vector spherical wave functions. $D_{lmp}$ is a square block diagonal matrix with blocks that span $m$ and $p$ for a given $l$, zero otherwise.  Specifically,\n\\begin{equation}\nD_{lmp}(\\alpha,\\beta,\\gamma) = e^{im\\alpha}d_{lmp}(\\beta)e^{ip\\gamma} \\label{dlmpsep}\n\\end{equation}\n\nThe rotation matrix is inherently separable in $(\\alpha,\\beta,\\gamma)$, where $\\alpha$, and $\\gamma$ are diagonal. The matrix $d_{lmp}(\\beta)$, called \"little-d\", is block diagonal and can be computed itself. This is advantageous when precomputing rotation matrices over many combinations of Euler angles. The matrix $d_{lmp}(\\beta)$ is given by \n\\begin{eqnarray}\nd_{lmp}(\\beta) &=&  i^{m-p}\\sqrt{\\dfrac{(l+p)!(l-p)!}{(l+m)!(l-m)!}} \\sum_s (-1)^{s}  {l+m \\choose l+p-s} {l-m \\choose s}  \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s}  \\label{dlmpdirect}\n\\end{eqnarray}\n\n\nThe sum is over all $s$ for positive arguments of the binomial coefficients. There is a version used in quantum mechanics, \\cite{wigner2012group}, based on a ZYZ rotation that yields a real-valued $d_{lmp}(\\beta)$ matrix. This forms the basis of a recursion algorithm in Section \\ref{littled}. The mapping from complex ZXZ  $d_{lmp}(\\beta)$ to the purely real ZYZ is, \\cite{littledconversion},\n\\eq{ d_{lmp}^{ZYZ}(\\beta)   =  (-i)^{p-m} d_{lmp}^{ZXZ}(\\beta)   \\label{zyzzxzconv} }\n%\\eq{ d_{lmp}^{ZYZ}(\\beta)   = i^{p-m} (-1)^{p-m} d_{lmp}^{ZXZ}(\\beta)   \\label{zyzzxzconv} }\n\n\n\n%\n%\\begin{eqnarray}\n%d_{lmp}(\\beta) &=&  \\sqrt{\\frac{(l+p)!(l-p)!}{(l+m)!(l-m)!}}\\sum_u {l+m \\choose l-p-u}{l-m \\choose u} \\nonumber \\\\\n%\\ & \\ & \\cdot (-1)^{l-p-u}\\left(\\cos\\frac{\\beta}{2}\\right)^{m+p+2u}\\left(\\sin\\frac{\\beta}{2}\\right)^{2l-m-p-2u} \n%\\end{eqnarray}\n%\n%The sum is over all $u$ for positive arguments of the binomial coefficients.  \n\n\n%From Wikipedia (\"Wigner-D Matrix\"), the rotation matrix is given as\n%\\eq{D_{lmp}(\\alpha\\beta\\gamma) = e^{-im\\alpha}d_{lmp}(\\beta)e^{-ip\\gamma}}\n%\n%with \n%\\begin{eqnarray}\n%d_{lmp}(\\beta) &=&  \\sqrt{(l+m)!(l-m)!(l+p)!(l-p)!} \\sum_s  \\dfrac{(-1)^{m-p+s}}{(l+p-s)!s!(m-p+s)!(l-m-s)!} \\nonumber \\\\\n%\\ & \\ & \\cdot  \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s} \n%\\end{eqnarray}\n\n%\\begin{eqnarray}\n%d_{m'm}^j(\\beta) &=&  \\sqrt{(j+m')!(j-m')!(j+m)!(j-m)!} \\sum_s  \\dfrac{(-1)^{m'-m+s}}{(j+m-s)!s!(m'-m+s)!(j-m'-s)!} \\nonumber \\\\\n%\\ & \\ & \\cdot  \\left(\\cos\\frac{\\beta}{2}\\right)^{2j+m-m'-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m'-m+2s} \n%\\end{eqnarray}\n%\n%This is for a ZYZ rotation, which results in the purely real $d_{lmp}$.  For ZXZ Euler rotations, the $(-1)^{m-p+s}$ is replaced with $(-1)^s i^{p-m}$ and $s$ runs from $[0,l+p]$ while for valid factorials.  However, I found that $(-1)^s i^{m-p}$ and multiplying the diagonal matrices in reverse (conjugate transpose) as $e^{im\\gamma}d_{lmp}(\\beta)e^{ip\\alpha}$ matched the values given by the recursion algorithm above. Therefore, the transform between the purely real and complex  $d_{lmp}(\\beta)$ is \n%\\eq{ d_{lmp}(\\beta) \\leftarrow i^{m-p} (-1)^{m-p} d_{lmp}(\\beta)}\n%\n\n\n%\\begin{eqnarray}\n%d_{lmp}(\\beta) &=&  \\sqrt{(l+m)!(l-m)!(j+p)!(j-p)!} \\sum_s  \\dfrac{(-1)^{m-p+s}}{(l+p-s)!s!(m-p+s)!(l-m-s)!} \\nonumber \\\\\n%\\ & \\ & \\cdot  \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s}  \\\\\n%\\ &=&  \\sqrt{\\dfrac{(l+p)!(l-p)!}{(l+m)!(l-m)!}} \\sum_s  \\dfrac{(-1)^{m-p+s} (l+m)!(l-m)! }{(l+p-s)!s!(m-p+s)!(l-m-s)!}   \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s}  \\\\\n%\\ &=&  \\sqrt{\\dfrac{(l+p)!(l-p)!}{(l+m)!(l-m)!}} \\sum_s (-1)^{m-p+s}  {l+m \\choose l+p-s} {l-m \\choose s}  \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s} \n%\\end{eqnarray}\n\n\n\n\n\\subsection{Field Rotations} \n\nGiven a field expansion in an unprimed system, \n\\begin{equation}\n\\bb{E}(\\bb{r}) = \\sum_{lm}a_{lm}\\bb{M}_{lm}(k,\\br)+b_{lm}\\bb{N}_{lm}(k,\\br)\n\\end{equation}\n\nthe expansion coefficients in the primed system are found by substituting the addition theorem \n\n\\begin{equation}\n\\bb{E}'(\\bb{r}') = \\sum_{lp}a_{lp}'\\bb{M}_{lp}'(k,\\br')+b_{lp}'\\bb{N}_{lp}'(k,\\br')\n\\end{equation}\n\n\\noindent where \n\n\\begin{equation}\na_{lp}' = \\sum_m a_{lm}D_{lmp}, \\quad \\quad\nb_{lp}' = \\sum_m b_{lm}D_{lmp}\n\\end{equation}\n\nIn matrix form, if $\\bb{a}$ are the outgoing wave coefficients in the $i$ frame, and $\\bb{a}'$ are those in the rotated $i'$ frame, then \n\\begin{equation}\n\\bb{a}' = \\bb{D}_i\\bb{a}\n\\end{equation}\n\n\\noindent where $\\bb{D}_i$ is the rotation matrix, and $(\\alpha,\\beta,\\gamma)$ describe the rotation from $i$ to $i'$.  In other words, the application of $\\bb{D}_i$ is an inverse rotation on the field (the coefficients $\\bb{a}'$ describe the same field but viewed from the rotated frame). $\\bb{D}_i$ is unitary, so the inverse is the conjugate transpose: $\\bb{D}_i^{-1} = \\bb{D}^*_i$.  This is the forward rotation, where the field itself rotates, to follow the Euler angles, as seen from the originating frame. \n\n%, and the inverse relation is \n%\n%\\begin{equation}\n%\\bb{a} = \\bb{D}^*_i\\bb{a}'\n%\\end{equation}\n\n\n\\subsection{Properties} \n\nHere we give several properties of the rotation matrix. The transpose satisfies the following relation\n\\eq{D_{lmp}(\\alpha,\\beta,\\gamma) = D_{lpm}^*(-\\gamma+\\pi,\\beta,-\\alpha+\\pi) }\nThe following relation exists for conjugated matrix elements\n\\eq{D_{l,-m,-p} = (-1)^{m+p}D_{lmp}^*}\n\nThe following identity exists between the $d_{lmp}(\\beta)$ and the Legendre polynomials\n\\ea{d_{l00}(\\beta) &=& P_l(\\cos\\beta) }\n\nThe rotation matrix is orthogonal over the three Euler angles as\n\\eq{\\int_{0}^{2\\pi} \\int_{0}^{\\pi} \\int_{0}^{2\\pi} D_{l'm'p'}^*(\\alpha,\\beta,\\gamma) D_{lmp}(\\alpha,\\beta,\\gamma) d\\alpha \\sin\\beta d\\beta d\\gamma\n= \\dfrac{8 \\pi^2}{2 l + 1} \\delta_{l'l}\\delta_{m'm}\\delta_{p'p}}\n\nwhere \n\\eq{\\int_{0}^{2\\pi}  d\\alpha \\int_{0}^{\\pi} \\sin\\beta d\\beta  \\int_{0}^{2\\pi} d\\gamma\n= 8 \\pi^2}\n\nThe same integral computed over a matrix element is \n\\ea{I_{lmp} &=& \\int_{0}^{2\\pi} \\int_{0}^{\\pi} \\int_{0}^{2\\pi} D_{lmp}(\\alpha,\\beta,\\gamma) d\\alpha \\sin\\beta d\\beta d\\gamma \\\\\n\\ &=& 4\\pi^2 \\delta_{m,0}  \\delta_{p,0} \\int_{0}^{\\pi}d_{lmp}(\\beta) \\sin\\beta d\\beta  \\\\\n\\ &=& 4\\pi^2 \\delta_{m,0}  \\delta_{p,0}\\int_{0}^{\\pi}P_l(\\cos\\beta) \\sin\\beta d\\beta  \\\\ \n\\ &=& 8 \\pi^2 \\delta_{l,0}\\delta_{m,0}  \\delta_{p,0} }\n\nFor $\\alpha = 0$, $\\gamma = 0$, the sum over the diagonal elements of the blocks satisfy\n\\eq{\\sum_{m=-l}^l D_{lmm}(\\beta) = \\sum_{m=-l}^l d_{lmm}(\\beta) = \\dfrac{\\sin\\left(\\dfrac{(2 l+1)}{2}\\beta\\right)}{\\sin\\left(\\dfrac{\\beta}{2}\\right)}}\n\nwhich is the normalized Dirichlet kernel.  \n\n\n\n\\clearpage\n\\newpage\n\n\\section{Computation of $D_{lmp}$}\n\nDirect computation of the rotation matrix using \\eqref{dlmpsep} and \\eqref{dlmpdirect} is not advised because of the need to compute the binomial coefficients. Instead, a fast recursion algorithm for computing the full $D_{lmp}$ is given in \\cite{choi1999rapid}. This begins with a rotation matrix defined\n\\begin{equation}\n(\\hat{x},\\hat{y},\\hat{z}) = (x,y,z)\\thbth{R_{xx}}{R_{xy}}{R_{xz}}{R_{yx}}{R_{yy}}{R_{yz}}{R_{zx}}{R_{zy}}{R_{zz}} = (x,y,z)\\bb{R}\n\\end{equation}\n\nwhich is opposite to the rotation matrix in \\eqref{rot}. Next, \\cite{choi1999rapid} defines the following matrices \n\\begin{equation}\n\\bb{D} = \\bb{F} + i\\bb{G}\n\\end{equation}\n\\begin{equation}\n\\bb{F} = \\thbth{(R_{yy}+R_{xx})/2}{R_{xz}/\\sqrt{2}}{(R_{yy}-R_{xx})/2}{R_{zx}/\\sqrt{2}}{R_{zz}}{-R_{zx}/\\sqrt{2}}{(R_{yy}-R_{xx})/2}{-R_{xz}/\\sqrt{2}}{(R_{yy}+R_{xx})/2}\n\\end{equation}\n\\begin{equation}\n\\bb{G} = \\thbth{(R_{yx}-R_{xy})/2}{R_{yz}/\\sqrt{2}}{-(R_{yx}+R_{xy})/2}{-R_{zy}/\\sqrt{2}}{0}{-R_{zy}/\\sqrt{2}}{(R_{yx}+R_{xy})/2}{R_{yz}/\\sqrt{2}}{(R_{xy}-R_{yx})/2}\n\\end{equation}\n\n\\noindent which serves as the initial condition\n\\eq{D_{1mp} = \\bb{D}}\n%\\begin{eqnarray}\n%D_{lmp} &=& F_{lmp} + iG_{lmp} \\\\\n%\\bb{D}_{1mp} &=& \\bb{D}\n%\\end{eqnarray}\n\nThe recursion equations are given as follows: \n\\begin{enumerate}\n\\item For $(-l+1) \\leq p \\leq (l-1)$:\n\\begin{equation}\nD_{lmp} = a_{lmp}D_{100}D_{l-1,mp}+b_{lmp}D_{110}D_{l-1,m-1,p}+b_{l,-m,p}D_{1,-10}D_{l-1,m+1,p}\n\\end{equation}\n\\begin{eqnarray}\na_{lmp} &=& \\sqrt{\\frac{(l+m)(l-m)}{(l+p)(l-p)}} \\\\\nb_{lmp} &=& \\sqrt{\\frac{(l+m)(l+m-1)}{2(l+p)(l-p)}} \n\\end{eqnarray}\n$p = \\pm l$ is not covered, $a_{lmp} = 0$ for $m=\\pm l$, and $b_{lmp} = 0$ for both $m=-l$ and $m=-l+1$.\n\n\\item For $-l \\leq p \\leq (l-2)$:\n\\begin{eqnarray}\nD_{lmp} &=& c_{lm,-p}D_{10,-1}D_{l-1,m,p+1}+d_{lm,-p}D_{11,-1}D_{l-1,m-1,p+1} \\nonumber \\\\\n\\ & \\ & +d_{l,-m,-p}D_{1,-1,-1}D_{l-1,m+1,p+1}\n\\end{eqnarray}\n\\begin{eqnarray}\nc_{lmp} &=& \\sqrt{\\frac{2(l+m)(l-m)}{(l+p)(l+p-1)}} \\\\\nd_{lmp} &=& \\sqrt{\\frac{(l+m)(l+m-1)}{(l+p)(l+p-1)}} \n\\end{eqnarray}\n$p = \\pm l$ and $p=(l-1)$ are not covered, $c_{lmp} = 0$ for $m=\\pm l$, and $d_{lmp} = 0$ for both $m=-l$ and $m=-l+1$.\n\n\\item For $(-l+1) \\leq p \\leq l$:\n\\begin{eqnarray}\nD_{lmp} &= &c_{lm,p}D_{101}D_{l-1,m,p-1}+d_{lm,p}D_{111}D_{l-1,m-1,p-1} \\nonumber \\\\\n\\ & \\ & +d_{l,-m,p}D_{1,-1,1}D_{l-1,m+1,p-1}\n\\end{eqnarray}\n$p = -l$ and $p = -l+1$ are not covered, and $c_{lmp}$ and $d_{lmp}$ are the same as above.\n\\end{enumerate}\n\nThis algorithm is the basis for two routines that follow. The first routine computes \\texttt{Dlmp} on a full square matrix, which has mostly zero elements. The second routine is specialized to compute this on a sparse 1D array to same memory.  \n\n\\subsection{Full $D_{lmp}$ Matrix}\n\nThe routine \\texttt{Dlmp} returns the rotation matrix in full, including zeros, starting with $l=1$. As mentioned, this describes an inverse rotation. Use the string switch \\texttt{'mono'} to include the monopole term. The algorithm above uses a rotation matrix that is transposed from our convention, so we transpose it on input to keep the routine consistent. There are helper functions to compute the coefficients: \\texttt{a\\_lmp}, \\texttt{b\\_lmp}, \\texttt{c\\_lmp}, \\texttt{d\\_lmp}.  Figure \\ref{fig1} shows the magnitude of $D_{lmp}$ for different $\\beta$ ($\\alpha$, $\\gamma$ do not affect the magnitude).  \n\n\\begin{figure}[H] \n   \\centering\n   \\includegraphics[width=4in]{Rotation/Figures/Dlmp} \n   \\caption{$D_{lmp}$ magnitude (color scale [0, 1]) for varying $\\beta$, $\\alpha = \\gamma = 0$.}\n   \\label{fig1}\n\\end{figure}\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/Dlmp.m}\n}\n\n\n\\newpage\n\n\\subsection{Sparse $D_{lmp}$ Matrix}\n\nThe rotation matrix that is the output of \\texttt{Dlmp} should not be used directly for matrix-vector multiplication because it contains unnecessary zeros. The quick fix is to immediately transform it to a sparse matrix:\n\n\\begin{verbatim}\n      D = sparse(Dlmp(L,alpha,beta,gamma));\n\\end{verbatim}\n\nIf several different rotation matrices are needed, they will likely have different numbers of non-zero elements, which can lead to problems with preallocation. Furthermore, the routine \\texttt{Dlmp} works on a large, mostly zero, 2D matrix. Therefore, we have a modified version of the routine \\texttt{Dlmp}, which recurses on a sparse matrix stored as a 1D array. The modifications follow.\n\nBecause the rotation matrix is square block diagonal, the maximum number of non-zero elements (excluding the monopole) is found by counting the elements in blocks that are sized $2l+1$ on a side up to a maximum degree harmonic $L$: \n\\begin{eqnarray}\nN_L &=& \\sum_{l=1}^L (2l + 1)^2  \\\\\n\\ &=& 4 \\sum_{l=1}^L l^2 + 4 \\sum_{l=1}^L l + \\sum_{l=1}^L 1 \\\\\n%\\ &=& 4 \\left(\\dfrac{L^3}{3} + \\dfrac{L^2}{2} + \\dfrac{L}{6}\\right) + 4\\left(\\dfrac{L^2 + L}{2}\\right) + L \\\\\n\\ &=& \\dfrac{4}{3} L^3 + 4L^2 + \\dfrac{11}{3}L \n\\end{eqnarray}\n\nAdd 1 for the monopole.  Next, we map the 2D row/column linear indices to a 1D index of the sparse matrix. Let the row linear index for the $(l,m)$ harmonic in the full matrix be $l^2 + l + m$ and let the column linear index of the $(l,p)$ harmonic in the full matrix be $l^2 + l + p$.  Counting column-major (top-down, left-right), the linear index for the $(l,m,p)$ element in the sparse array is\n\\begin{equation}\nI(l,m,p) = N_{l-1} + (2l+1)(l+p) + (l+m+1)\n\\end{equation}\n\n\\noindent The term $N_{l-1}$ counts the number of elements for all full blocks less than $l$, the second term counts the number of elements in full columns of the current block less than $p$, the last term counts the rows up to $m$ in the current column.  Again, add 1 for the monopole.  \n\nThe routine \\texttt{DlmpSparse} returns the three column arrays containing the row index, column index, and matrix entries of $D_{lmp}$. It is the same as \\texttt{Dlmp} except computed on a 1D array.  Use the string switch \\texttt{'mono'} for the monopole.  The two helper functions \\texttt{NDlmpSparse} and \\texttt{indDlmpSparse} return the number of elements and index for the sparse rotation matrix. A further refinement could use conjugate symmetry to only store half of the matrix plus the main diagonal, but that then requires specialized routines for matrix-vector multiplication. Finally, the helper functions as written create a bottleneck, so a faster version, \\texttt{DlmpSparseFast}, is included but not copied here. This uses inline indexing and is about five times faster for moderate values of $L$. \n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/DlmpSparse.m}\n}\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/NDlmpSparse.m}\n}\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/indDlmpSparse.m}\n}\n\n\n\\newpage\n\n\\section{Computation of $d_{lmp}(\\beta)$}\n\\label{littled}\nThis section contains routines for the computation of \"little-d\", $d_{lmp}(\\beta)$. This rotation matrix should be used with \\eqref{dlmpsep} to precompute and loop over combinations of Euler angles.  Four routines are provided. The first is a direct computation for cross-checking, but should not be used in practice because computing the factorials in the binomial coefficients is not accurate. The second is based on a fast recursion of the purely real ZYZ $d_{lmp}(\\beta)$, computed on the full matrix, then converted to complex ZXZ $d_{lmp}(\\beta)$.  The third routine is the same as the second but faster. The last routine is the same as the second but computed on the sparse matrix using the sparse indexing tools developed before. \n\n\n\\subsection{Direct Computation}\n\nThe routine \\texttt{dlmpBetaDirect} computes the ZXZ complex $d_{lmp}(\\beta)$ directly from \\eqref{dlmpdirect}. This is good to maybe $L = 20$ due to direct computation of the factorials. This is used to validate the recursive algorithms.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/dlmpBetaDirect.m}\n}\n\n\\subsection{Recursion Algorithm}\n\nA fast computation of $d_{lmp}(\\beta)$ is based on the recursive algorithm in \\cite{gimbutas2009fast}, which gives an algorithm for the purely real ZYZ matrix. The recursion equations for real $d_{lmp}(\\beta)$ are \n\\ea{d_{lmp} &=& \\cos^2 (x) A_{lmp} d_{l-1,m-1,p-1} - 2 \\sin (x)\\cos (x) B_{lmp} d_{l-1,m-1,p} + \\sin^2 (x) C_{lmp} d_{l-1,m-1,p+1} \\label{dlmprec1} \\\\\n d_{lmp} &=& \\sin^2 (x)  D_{lmp} d_{l-1,m+1,p-1}+2 \\sin (x) \\cos (x)  E_{lmp} d_{l-1,m+1,p} + \\cos^2 (x)  F_{lmp} d_{l-1,m+1,p+1} \\label{dlmprec2} \\\\\n d_{lmp} &=& \\sin (x) \\cos (x)  G_{lmp} d_{l-1,m,p-1}+(\\cos^2 (x)  - \\sin^2 (x) ) H_{lmp} d_{l-1,m,p} -\\sin (x)\\cos (x)  I_{lmp} d_{l-1,m,p+1} \\nonumber \\label{dlmprec3} \\\\}\n \n\\noindent where $x = \\beta/2$. The coefficients can be written as an outer product \n\\eq{\\thbth{A_{lmp}^2}{B_{lmp}^2}{C_{lmp}^2}{D_{lmp}^2}{E_{lmp}^2}{F_{lmp}^2}{G_{lmp}^2}{H_{lmp}^2}{I_{lmp}^2} =  \\thrcol{\\dfrac{1}{(l+m)(l+m-1)} }{\\dfrac{1}{(l-m)(l-m-1)} }{\\dfrac{1}{(l-m) (l+m)} } \\thrrow{(l+p)(l+p-1)}{(l+p)(l-p)}{(l-p)(l-p-1) } }\n\n%A_{lmp} &=& \\sqrt{\\dfrac{(l+p)(l+p-1) }{(l+m)(l+m-1) } } \\\\\n%B_{lmp} &=& \\sqrt{\\dfrac{(l+p)(l-p) }{(l+m)(l+m-1) } } \\\\\n%C_{lmp} &=& \\sqrt{\\dfrac{(l-p)(l-p-1) }{(l+m)(l+m-1) } } \\\\\n%D_{lmp} &=& \\sqrt{\\dfrac{(l+p)(l+p-1) }{(l-m)(l-m-1) } }  \\\\\n%E_{lmp} &=& \\sqrt{\\dfrac{(l+p)(l-p) }{(l-m)(l-m-1) } }  \\\\\n%F_{lmp} &=& \\sqrt{\\dfrac{(l-p)(l-p-1) }{(l-m)(l-m-1) } }  \\\\\n%G_{lmp} &=& \\sqrt{\\dfrac{(l+p)(l+p-1) }{(l-m) (l+m)} }  \\\\\n%H_{lmp} &=&\\sqrt{\\dfrac{(l+p)(l-p) }{(l-m)(l+m) } }   \\\\\n%I_{lmp} &=&  \\sqrt{\\dfrac{(l-p)(l-p-1) }{(l-m)(l+m) } }  }\n\n\n\n%\n%\\ea{d_{n}^{m',m} &=& \\cos^2 (x) A d_{n-1}^{m'-1,m-1} - 2 \\sin (x)\\cos (x) B d_{n-1}^{m'-1,m} + \\sin^2 (x) C d_{n-1}^{m'-1,m+1} \\label{dlmprec1} \\\\\n% d_{n}^{m',m} &=& \\sin^2 (x)  D d_{n-1}^{m'+1,m-1}+2 \\sin (x) \\cos (x)  E d_{n-1}^{m'+1,m} + \\cos^2 (x)  F d_{n-1}^{m'+1,m+1} \\label{dlmprec2} \\\\\n% d_{n}^{m',m} &=& \\sin (x) \\cos (x)  G d_{n-1}^{m',m-1}+(\\cos^2 (x)  - \\sin^2 (x) ) H d_{n-1}^{m',m} -\\sin (x)\\cos (x)  I d_{n-1}^{m',m+1} \\nonumber \\label{dlmprec3} \\\\}\n%\\ea{x &=& \\beta/2\\\\\n%A_{nm'm} &=& \\sqrt{\\dfrac{(n+m)(n+m-1) }{(n+m')(n+m'-1) } } \\\\\n%B_{nm'm} &=& \\sqrt{\\dfrac{(n+m)(n-m) }{(n+m')(n+m'-1) } } \\\\\n%C_{nm'm} &=& \\sqrt{\\dfrac{(n-m)(n-m-1) }{(n+m')(n+m'-1) } } \\\\\n%D_{nm'm} &=& \\sqrt{\\dfrac{(n+m)(n+m-1) }{(n-m')(n-m'-1) } }  \\\\\n%E_{nm'm} &=& \\sqrt{\\dfrac{(n+m)(n-m) }{(n-m')(n-m'-1) } }  \\\\\n%F_{nm'm} &=& \\sqrt{\\dfrac{(n-m)(n-m-1) }{(n-m')(n-m'-1) } }  \\\\\n%G_{nm'm} &=& \\sqrt{\\dfrac{(n+m)(n+m-1) }{(n-m') (n+m')} }  \\\\\n%H_{nm'm} &=&\\sqrt{\\dfrac{(n+m)(n-m) }{(n-m')(n+m') } }   \\\\\n%I_{nm'm} &=&  \\sqrt{\\dfrac{(n-m)(n-m-1) }{(n-m')(n+m') } }  }\n%\n%In the paper, the numerator for $I$ is $(n-m+1)$, which is incorrect. I found $(n-m-1)$ to be correct, which also preserves the symmetry, so that these can be written as an outer product as \n%\\eq{\\thbth{A^2}{B^2}{C^2}{D^2}{E^2}{F^2}{G^2}{H^2}{I^2} =  \\thrcol{\\dfrac{1}{(n+m')(n+m'-1)} }{\\dfrac{1}{(n-m')(n-m'-1)} }{\\dfrac{1}{(n-m') (n+m')} } \\thrrow{(n+m)(n+m-1)}{(n+m)(n-m)}{(n-m)(n-m-1) } }\n\nThe recursion algorithm first computes \\eqref{dlmprec1} for $m=l$ and all $\\pm p$, then \\eqref{dlmprec2} for $m=-l$ all $p$, and finally \\eqref{dlmprec3} for $m=(-l+1),...,(l-1)$ all $p$.  When a coefficient is zero, the corresponding term at $l-1$ does not exist and can be ignored.  With the conversion to complex using \\eqref{zyzzxzconv}, this recursion matches the direct compuation and matches the full \\texttt{Dlmp} for $(\\alpha,\\beta,\\gamma) = (0,\\beta,0)$.  Note, in \\cite{gimbutas2009fast}, the numerator of $I_{lmp}$ has $(l-p+1)$, which is incorrect. It should be $(l-p-1)$, so that it preserves the symmetry of the coefficients. \n\nThe routine \\texttt{dlmpBeta} is a straight implementation of \\eqref{dlmprec1}, \\eqref{dlmprec2}, \\eqref{dlmprec3} on the full matrix (with zeros) with conversion to complex.  Use \\texttt{'mono'} to include the monopole. A second version of this routine, \\texttt{dlmpBetaFast}, which is not copied here but included in the library, is a faster implementation that uses inline indexing, inline coefficient computation, and vectorized real to complex conversion. Still on the full matrix, it runs about six times faster.\n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/dlmpBeta.m}\n}\n\n\\subsection{Sparse Recursive}\nLike the full $D_{lmp}$, $d_{lmp}(\\beta)$ can be computed as a sparse matrix on a 1D array with proper bookkeeping to avoid having to create and index a large matrix of zeros.  We previously solved the problem of indexing the sparse rotation matrix.  \\texttt{dlmpBetaSparse} is a version of \\texttt{dlmpBeta} that returns the row, column and matrix entries for sparse complex ZXZ $d_{lmp}(\\beta)$.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/Rotation/dlmpBetaSparse.m}\n}\n\n\n%\n%\\subsubsection{Log-recurrence for $d_{lmp}(\\beta)$} \n%We'll derive a recurrence based on the log-transform to compute each matrix element directly. This means including the factorials out front so that they cancel with the factorials in the sum.\n%\n%\\begin{eqnarray}\n%d_{lmp}(\\beta) &=&  \\sum_s (-1)^s i^{m-p}  \\dfrac{\\sqrt{(l+p)!(l-p)!(l+m)!(l-m)! }}{(l+p-s)!(m-p+s)! s! (l-m-s)!}  \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s} \n%\\end{eqnarray}\n%\n%or \n%\\begin{eqnarray}\n%d_{lmp}(\\beta) &=& i^{m-p}  \\sum_s (-1)^s  e^{\\ln a_s} \n%\\end{eqnarray}\n%where\n%\\eq{a_s = c d_{s}  C_{s} S_{s}  }\n%\n%\\ea{c &=& \\sqrt{(l+p)!(l-p)!(l+m)!(l-m)! } \\\\\n%d_{s} &=& \\dfrac{1}{(l+p-s)!(m-p+s)! s! (l-m-s)!} \\\\\n%C_{s} &=& \\left(\\cos\\frac{\\beta}{2}\\right)^{2l+p-m-2s}\\\\\n%S_{s} &=& \\left(\\sin\\frac{\\beta}{2}\\right)^{m-p+2s} }\n%\n%Taking the natural log\n%\\eq{\\ln a_s = \\ln c + \\ln d_{s} + \\ln C_{s} + \\ln S_{s}  }\n\n", "meta": {"hexsha": "40a84f46248abe330c515902f0d48b73342ad9ab", "size": 25137, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Rotation/Rotation.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/Rotation/Rotation.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/Rotation/Rotation.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": 61.0121359223, "max_line_length": 814, "alphanum_fraction": 0.656721168, "num_tokens": 9297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.8705972684083609, "lm_q1q2_score": 0.7777127337000848}}
{"text": "\\chapter{Transformations}\n\n\\section{How transforming a vector transforms its coordinates}\n\nWe can imagine rotating a vector by 30 degrees,\nbut how do the coordinates change?\n\nLet \\(f : V \\to V\\) be a vector transformation.\n\nLet \\(T : V \\to V\\) be a linear function.\n\nLet \\(U : \\Real^n \\to \\Real^n\\) be a linear function.\n\nLet \\(v:V\\) be a vector.\n\nLet \\(e:\\Real^n \\to V\\) be a basis.\n\nIf \\(v\\) changes to \\(T(v)\\), then the \\(e\\)-coordinates change from \\(x\\) to \\(U(x)\\).\n\nLet \\(x = (x_1,\\ldots,x_n)\\).\n\nWe can explode \\(U : \\Real^n \\to \\Real^n\\) into \\(n\\) functions\n\\(U_1,\\ldots,U_n\\), each of type \\(\\Real^n \\to \\Real\\),\nso that we can write \\(U\\) out as\n\\Formula{\n    U(x) = (U_1(x), \\ldots, U_n(x))\n}\n\n\\(T\\) is a vector transformation.\n\\(U\\) is the coordinate transformation that corresponds to \\(T\\).\n\nLet \\(E\\) be the basis.\n\nRemember that we can write a vector as \\(v = E(x)\\).\n\nSuppose that we transform a vector from \\(v\\) to \\(T(v)\\).\n\nThus \\(T(v) = T(E(x)) = E(U(x))\\).\n\nThus \\(T \\circ E = E \\circ U\\).\n\n\\section{Rotation in two-dimensional orthonormal basis}\n\nThe vector \\(a\\) rotated by \\(t\\) radians counterclockwise is the vector \\(b\\) having the same length\nbut such that the angle from \\(a\\) to \\(b\\) is \\(t\\).\n\nLet \\(\\{i,j\\}\\) be an orthonormal basis.\n\nIt can be geometrically shown that\nthe result of rotating the vector \\(xi+yj\\) by \\(a\\) radians\nis the vector \\(x'i+y'j\\) where\n\\begin{align}\n    x' &= \\cos(a) \\cdot x - \\sin(a) \\cdot y\n    \\\\ y' &= \\sin(a) \\cdot x + \\cos(a) \\cdot y\n\\end{align}\nwhich we can write as the matrix equation\n\\Formula{\n    \\Matrix{x' \\\\ y'}\n    = \\Matrix{\n        \\cos(a) & -\\sin(a)\n        \\\\ \\sin(a) & \\cos(a)\n    }\n    \\Matrix{x \\\\ y}\n}\nfor which we can also write \\( \\text{rotate}(a, xi + yj) = x'i + y'j \\).\nWe can also write \\( \\text{rotate}(e, a, (x,y)) = (x',y')\\).\nWe can also write \\( \\text{rotate}(e, a, X) = R(a) \\cdot X\\).\n\nIf the basis is orthonormal, then we can define the rotation matrix\n\\Formula{\n    R(a) = \\Matrix{\n        \\cos a & -\\sin a\n        \\\\ \\sin a & \\cos a\n    }\n}\nso that we can write the rotation as matrix multiplication\n\\( X' = R(a) \\cdot X \\).\n\nThus changing the vector \\(v\\) to \\(\\text{rotate}(a,v)\\)\nchanges the \\(e\\)-coordinate tuple \\(x\\) to \\(R(a) \\cdot x\\).\n\nSee also Wikipedia%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Rotation_(mathematics)\\#Two_dimensions}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Rotation_matrix\\#In_two_dimensions}}%\n.\n\n\\section{Transforming the basis}\n\nWe have just rotated a vector.\nWhat if we rotate the basis (the coordinate axes) instead?\n\nSee also Wikipedia%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Active_and_passive_transformation}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Change_of_basis}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Rotation_of_axes}}%\n.\n\n\\section{Change of basis}\n\nLet \\( e : \\Real^n \\to V \\) be a basis.\n\nFor example, if \\(e(x,y) = xi + yj\\).\n\nLet \\(t\\) be rotation of 90 degrees counterclockwise.\n\nWe can think of a change of basis as an invertible function \\( t : \\Real^n \\to \\Real^n \\).\nThen, we can change the basis from \\(e\\) to \\(e \\circ t\\).\n\nWe have a vector \\(v : V\\).\nIts coordinate tuple under basis \\(e\\) is \\(x\\).\nIts coordinate tuple under basis \\(e \\circ t\\) is \\(x'\\).\n\\begin{align*}\n    v &= v\n    \\\\ e(x) &= (e \\circ t)(x')\n    \\\\ e(x) &= e(t(x'))\n    \\\\ x &= t(x')\n    \\\\ t^{-1}(x) &= x'\n\\end{align*}\n\nThus a vector is contravariant.\n\n\\section{Coordinateless and coordinateful description of scalar fields}\n\nLet \\(f : V \\to \\Real\\) be a scalar field.\nWe call \\(f\\) coordinateless because \\(f\\) does not use any coordinates.\n\nA coordinateful description of \\(f\\) under basis \\(e : \\Real^n \\to V\\) is\nanother function \\(g : \\Real^n \\to \\Real\\)\nsuch that \\(g = f \\circ e\\).\n\nHow do we describe derivatives coordinatelessly?\n\n\\section{Keeping a function while changing basis: contravariance and covariance}\n\nLet there be two functions \\( p : \\Real \\to V \\) and \\( \\phi : V \\to \\Real \\).\nObserve how their types mirror each other.\nWe will explain how \\( p \\) is contravariant and \\( \\phi \\) is covariant.\n\nAn example of \\(p\\) is a parametric curve.\n\nAn example of \\( \\phi \\) is a scalar field such as a temperature field,\nwhich maps each point in space to the temperature at that point.\nAnother example is a height map,\nwhich maps each point in space to the height of the terrain at that point.\n\nLet \\( p_e, p_f : \\Real \\to \\Real^n \\) be coordinateful descriptions of \\( p \\).\nLet \\(\\phi_e : \\Real^n \\to \\Real \\) describe \\(\\phi\\) using the basis \\(e\\).\nLet \\(\\phi_f : \\Real^n \\to \\Real \\) describe \\(\\phi\\) using the basis \\(f\\).\nThe subscript denotes the basis.\n\\begin{align*}\n    e(p_e(t)) &= p(t)\n    \\\\ f(p_f(t)) &= p(t)\n    \\\\ \\phi(v) &= \\phi_e(e^{-1}(v))\n    \\\\ \\phi(v) &= \\phi_f(f^{-1}(v))\n\\end{align*}\n\nEven though \\(p_e\\) and \\(p_f\\) are different functions,\nthey describe the same coordinateless function \\(p\\), only with different bases.\nWe want to change the basis from \\(e\\) to \\(f\\), but we want \\(p_f\\) to describe \\(p\\).\n\nWe write \\(f \\equiv g\\) to mean that \\(f\\) gives the same result as \\(g\\) for all parameters.\nWe have discussed this in \\SectionRef{sec:function-equivalence}.\nThus, we can tidy up the equations as\n\\begin{align*}\n    e \\circ p_e &\\equiv p\n    \\\\ f \\circ p_f &\\equiv p\n    \\\\ \\phi &\\equiv \\phi_e \\circ e^{-1}\n    \\\\ \\phi &\\equiv \\phi_f \\circ f^{-1}\n\\end{align*}\nObserve the inverses.\n\nLet \\( m : \\Real^n \\to \\Real^n \\) be the function that changes the basis from \\( e \\) to \\( f \\).\nThis means \\( f \\equiv e \\circ m \\).\n(The other possibility \\(m \\circ e\\) does not make sense because the types conflict.)\n\nThen, observe how we have to change the coordinates to keep \\(p\\) and \\(\\phi\\) the same:\n\\begin{align*}\n    p &\\equiv p\n    &\n    \\phi &\\equiv \\phi\n    \\\\\n    e \\circ p_e &\\equiv f \\circ p_f\n    &\n    \\phi_e \\circ e^{-1} &\\equiv \\phi_f \\circ f^{-1}\n    \\\\\n    e \\circ p_e &\\equiv (e \\circ m) \\circ p_{e \\circ m}\n    &\n    \\phi_e \\circ e^{-1} &\\equiv \\phi_{e \\circ m} \\circ (e \\circ m)^{-1}\n    \\\\\n    e \\circ p_e &\\equiv e \\circ m \\circ p_{e \\circ m}\n    &\n    \\phi_e \\circ e^{-1} &\\equiv \\phi_{e \\circ m} \\circ m^{-1} \\circ e^{-1}\n    \\\\\n    p_e &\\equiv m \\circ p_{e \\circ m}\n    &\n    \\phi_e &\\equiv \\phi_{e \\circ m} \\circ m^{-1}\n    \\\\\n    m^{-1} \\circ p_e &\\equiv p_{e \\circ m}\n    &\n    \\phi_e \\circ m &\\equiv \\phi_{e \\circ m}\n\\end{align*}\n\nTherefore, summarizing, we get\n\\begin{align}\n    m^{-1} \\circ p_e &\\equiv p_{e \\circ m}\n    \\\\ \\phi_e \\circ m &\\equiv \\phi_{e \\circ m}\n\\end{align}\n\nWe say that \\(p\\) is contravariant because of the \\(m^{-1}\\).\n\nWe say that \\(\\phi\\) is covariant because of the \\(m\\).\n\nA vector is contravariant.\n\nFunctions of type \\( \\Real \\to V \\) are contravariant.\n\nFunctions of type \\( V \\to \\Real \\) are covariant.\n\n\\section{Einstein notation?}\n\n\\paragraph{Subscripts and superscripts for coordinate tuple components?}\n\nA vector is \\(v = e(x^1,\\ldots,x^n)\\).\n\nA parametric curve is \\(p(t) = e((p_e(t))^1, \\ldots, (p_e(t))^n)\\).\nWe lift it to \\(p = E(q^1, \\ldots, q^n)\\).\n\nA covector is \\(\\phi(v) = \\phi_e(x_1,\\ldots,x_n)\\).\n\nWe overload the superscript, which unfortunately has been used to mean raising a number to a power.\nDon't confuse contravariant tuple component notation \\(x^3\\)\nwith power notation \\(2^3 = 2 \\times 2 \\times 2\\).\n", "meta": {"hexsha": "8dfdc1bf7bc297961899f727d9b18c50d48ce4b2", "size": 7295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/transform.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/transform.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/transform.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.3090128755, "max_line_length": 101, "alphanum_fraction": 0.6261823167, "num_tokens": 2299, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422645, "lm_q2_score": 0.8596637505099167, "lm_q1q2_score": 0.7776952763254875}}
{"text": "\\section{Math II - Combinatorics}\r\n  \\subsection{Lucas Theorem}\r\n    Compute $\\binom{n}{k} \\bmod{p}$ in $O(p + \\log_p n)$ time, where $p$ is a prime.\r\n    \\code{math/combs/lucas.cpp}\r\n  \\subsection{Granville's Theorem}\r\n    Compute $\\binom{n}{k} \\bmod{m}$ (for any $m$) in $O(m^2 \\log^2 n)$ time.\r\n    \\code{math/combs/granville.py}\r\n  \\subsection{Derangements}\r\n    Compute the number of permutations with $n$ elements such that no element is at their original position:\r\n    \\[\r\n    D(n) = (n-1) \\left( D(n-1) + D(n-2) \\right) =  n D(n-1) + (-1)^n\r\n    \\]\r\n    % \\subsection{Next Permutation}\r\n    % \\subsection{Next Combination}\r\n    % \\subsection{Next Arrangement}\r\n    % \\subsection{Next Partition}\r\n    \\subsection{Factoradics}\r\n    Convert a permutation of $n$ items to factoradics and vice versa in $O(n \\log n)$.\r\n    \\code{math/combs/factoradics.cpp}\r\n  \\subsection{$k$th Permutation}\r\n    Get the next $k$th permutation of $n$ items, if exists, using factoradics. All values should be from $0$ to $n-1$. Use factoradics methods as discussed above.\r\n    \\code{math/combs/kth-permutation.cpp}\r\n  \\subsection{Catalan Numbers}\r\n    \\[\r\n        C_n = \\frac{1}{n+1}\\binom{2n}{n} =  \\binom{2n}{n}-\\binom{2n}{n+1}\r\n    \\]\r\n    \\begin{enumerate}\r\n      \\item The number of non-crossing partitions of an $n$-element set\r\n      \\item The number of expressions with $n$ pairs of parentheses\r\n      \\item The number of ways $n+1$ factors can be parenthesized\r\n      \\item The number of full binary trees with $n+1$ leaves\r\n      \\item The number of monotonic lattice paths of an $n \\times n$ grid (5-SAT problem)\r\n      \\item The number of triangulations of a convex polygon with $n+2$ sides (non-rotational)\r\n      \\item The number of permutations $\\{1, \\ldots, n\\}$ without a 3-term increasing subsequence\r\n      \\item The number of ways to form a mountain range with $n$ ups and $n$ downs\r\n    \\end{enumerate}\r\n  \\subsection{Stirling Numbers}\r\n    $s_1$: Count the number of permutations of $n$ elements with $k$ disjoint cycles\r\n\r\n    $s_2$: Count the ways to partition a set of $n$ elements into $k$ nonempty subsets\r\n    \\[\r\n    s_1(n,k) = \\begin{cases}\r\n        1 & n = k = 0 \\\\\r\n        s_1(n-1,k-1) - (n-1) s_1(n-1,k) & n,k>0 \\\\\r\n        0 & \\text{elsewhere}\r\n    \\end{cases}\r\n    \\]\r\n    \\[\r\n    s_2(n,k) = \\begin{cases}\r\n        1 & n = k = 0 \\\\\r\n        s_2(n-1,k-1) + k s_2(n-1,k) & n,k>0 \\\\\r\n        0 & \\text{elsewhere}\r\n    \\end{cases}\r\n    \\]\r\n  \\subsection{Partition Function}\r\n    Pregenerate the number of partitions of positive integer $n$ with $n$ positive addends.\r\n    \\[\r\n    p(n,k) = \\begin{cases}\r\n        1 & n = k = 0 \\\\\r\n        0 & n < k \\\\\r\n        p(n-1,k-1) + p(n-k,k) & n \\ge k\r\n    \\end{cases}\r\n    \\]\r\n", "meta": {"hexsha": "9375f56eea7a4b1fe8fc7dac5c774e5b30828d87", "size": 2737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/combinatorics.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/combinatorics.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/combinatorics.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.765625, "max_line_length": 163, "alphanum_fraction": 0.6021191085, "num_tokens": 898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088005554475, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7776537454795569}}
{"text": "\\chapter{Analysis Techniques}\\label{ch:analysis}\nThis chapter provides some useful techniques to analyse FD schemes. Techniques to analyse PDEs also exist, but the focus here is of a practical nature and will especially revolve around the discrete schemes. This chapter can be seen as a `tutorial' on how to use these techniques. \nStarting off with some necessary theory on matrices in a FDTD context and other mathematical tools, this chapter continues to introduce \n\\begin{itemize}\n    \\item \\textit{Frequency domain analysis}, which can be used to determine stability conditions of (linear and time-invariant) FD schemes,\n    \\item \\textit{Energy analysis}, which can both be used to debug implementations of FD schemes, as well as determine stability conditions in a more general fashion, and\n    \\item \\textit{Modal analysis} which can be used to determine the modal frequencies (and damping per mode) that a FD scheme exhibits.\n\\end{itemize}\n\n\\section{Matrices in a FDTD context}\\label{sec:matricesFDTD}\nFor several purposes, such as implementation in \\texttt{MATLAB} and several analysis techniques described shortly, it is useful to write a FD scheme in \\textit{matrix form}.\\footnote{Appendix \\ref{app:matrices} provides some basic knowledge on matrices and linear algebra for those unfamiliar with this.} Matrix multiplication when working with FDTD methods usually involves multiplying a square matrix (with equal rows and columns) onto a column vector. Consider a $(N+1)\\times (N+1)$ square matrix $\\A$ and a $(N+1) \\times 1$ column vector $\\u$. Multiplying these results in a $(N+1) \\times 1$ column vector $\\w$:\n\\begin{equation}\n    \\A\\u = \\w.\n\\end{equation}\nExpanding this operation results in\n\\begin{equation}\n    \\underbrace{\\begin{bmatrix}\n        a_{00} & a_{01} & \\hdots & a_{0N}\\\\\n        a_{10} & a_{11} & \\hdots & a_{2N}\\\\\n        \\vdots & \\vdots & &\\vdots\\\\\n        a_{N0} & a_{N1} & \\hdots & a_{NN}\n    \\end{bmatrix}}_{\\A}\n    \\underbrace{\\begin{bmatrix}\n        u_0\\\\\n        u_1\\\\\n        \\vdots\\\\\n        u_N\n    \\end{bmatrix}}_{\\u} = \n    \\underbrace{\\begin{bmatrix}\n        a_{00}u_0 + a_{01}u_1 + \\hdots + a_{0N}u_N\\\\\n        a_{10}u_0 + a_{11}u_1 + \\hdots + a_{1N}u_N\\\\\n        \\vdots\\\\\n        a_{N0}u_0 + a_{N1}u_1 + \\hdots + a_{NN}u_N\n    \\end{bmatrix}}_{\\w}\n\\end{equation}\nwhere the indexing of the matrix elements starts at $0$ rather than $1$ here, as it relates better to operations used in a FDTD context.\n\n\\subsection{FD operators in matrix form}\nFD operators approximating spatial derivatives and averages introduced in Section \\ref{sec:FDoperators} can be written in matrix form and applied to a column vector $\\u^n$ containing the state of the system at time index $n$. These matrices are square and their sizes depend on the number of grid points the system is described for and on the boundary conditions. Not assuming a specific size for now, the FD operators in \\eqref{eq:discFirstSpace} can be written in matrix form according to\n% \\setstackgap{L}{1.1\\baselineskip}\n% \\fixTABwidth{T}\n\\setstackgap{L}{14pt}\n\\setstacktabbedgap{4pt}\n\\def\\lrgap{\\kern3pt}\n\\fixTABwidth{T}\n\n\\def\\xbracketMatrixstack#1{\\left[\\lrgap\\tabbedCenterstack{#1}\\lrgap\\right]}\n\n\\begin{equation*}\n    \\mathbf{D}_{x+} = \\frac{1}{h}\\xbracketMatrixstack{\n        \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n         & -1 & 1 & & & \\\\\n        & & -1 & 1 & & \\\\\n        & & & -1 & 1 & \\\\\n        & & & & -1 & \\ddots\\\\\n        &\\mathbf{0} & & & & \\ddots\n    }\\qquad \\mathbf{D}_{x-} = \\frac{1}{h}\\xbracketMatrixstack{\n        \\ddots & & & & \\mathbf{0}&\\\\\n        \\ddots & 1 & & & & \\\\\n        & -1 & 1 & & & \\\\\n        & & -1 & 1 & & \\\\\n        & & & -1 & 1 & \\\\\n        &\\mathbf{0} & & & \\ddots & \\ddots\n    }\n\\end{equation*}\n\n\\begin{equation*}\n    \\mathbf{D}_{x\\cdot} = \\frac{1}{2h}\\xbracketMatrixstack{\n        \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n        \\ddots & 0 & 1 & & & \\\\\n        & -1 & 0 & 1 & & \\\\\n        & & -1 & 0 & 1 & \\\\\n        & & & -1 & 0 & \\ddots \\\\\n        &\\mathbf{0} & & & \\ddots & \\ddots\n    }\n\\end{equation*}\n% \\begin{gather*}\n%     \\mathbf{D}_{x+} = \\frac{1}{h}\n%     \\begin{bmatrix}\n%         \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n%          & -1 & 1 & & & \\\\\n%         & & -1 & 1 & & \\\\\n%         & & & -1 & 1 & \\\\\n%         & & & & -1 & \\ddots\\\\\n%         &\\mathbf{0} & & & & \\ddots \\\\\n%     \\end{bmatrix}\n%     \\quad\n%     \\mathbf{D}_{x-} = \\frac{1}{h}\\begin{bmatrix}\n%         \\ddots & & & & \\mathbf{0}&\\\\\n%         \\ddots & 1 & & & & \\\\\n%         & -1 & 1 & & & \\\\\n%         & & -1 & 1 & & \\\\\n%         & & & -1 & 1 & \\\\\n%         &\\mathbf{0} & & & \\ddots & \\ddots \\\\\n%     \\end{bmatrix}\\\\\n%     \\\\\n%     \\mathbf{D}_{x\\cdot} = \\frac{1}{2h}\\begin{bmatrix}\n%         \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n%         \\ddots & 0 & 1 & & & \\\\\n%         & -1 & 0 & 1 & & \\\\\n%         & & -1 & 0 & 1 & \\\\\n%         & & & -1 & 0 & \\ddots \\\\\n%         &\\mathbf{0} & & & \\ddots & \\ddots \\\\\n%     \\end{bmatrix}\\\\\n% \\end{gather*}\n%\nwhere the diagonal dots denote that the values on the respective diagonals continue until the top-left and bottom-right corners of the matrix.\\todo{is this how you explain it?} A $\\boldsymbol{0}$ indicates that the rest of the values in the matrix are zeros.\n\nAveraging operators $\\mxp$, $\\mxm$ and $\\mxd$ are defined in a similar way:\n\n\\begin{equation*}\n    \\mathbf{M}_{x+} = \\frac{1}{2}\\xbracketMatrixstack{\n        \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n         & 1 & 1 & & & \\\\\n        & & 1 & 1 & & \\\\\n        & & & 1 & 1 & \\\\\n        & & & & 1 & \\ddots\\\\\n        &\\mathbf{0} & & & & \\ddots\n    }\n    \\qquad\n    \\mathbf{M}_{x-} = \\frac{1}{2}\\xbracketMatrixstack{\n        \\ddots & & & & \\mathbf{0}&\\\\\n        \\ddots & 1 & & & & \\\\\n        & 1 & 1 & & & \\\\\n        & & 1 & 1 & & \\\\\n        & & & 1 & 1 & \\\\\n        &\\mathbf{0} & & & \\ddots & \\ddots\n    }\n\\end{equation*}\n\n\\begin{equation*}    \n    \\mathbf{M}_{x\\cdot} = \\frac{1}{2}\\xbracketMatrixstack{\n        \\ddots &\\ddots & & & \\mathbf{0}&\\\\\n        \\ddots & 0 & 1 & & & \\\\\n        & 1 & 0 & 1 & & \\\\\n        & & 1 & 0 & 1 & \\\\\n        & & & 1 & 0 & \\ddots \\\\\n        &\\mathbf{0} & & & \\ddots & \\ddots\n    }\n\\end{equation*}\n\nIt is important to notice that only spatial operators are written in this matrix form and then applied to state vectors at different time steps ($\\u^{n+1}$, $\\u^n$ and $\\u^{n-1}$). \n\nFinally, the identity matrix is a matrix with only $1$s on the diagonal and $0$s elsewhere:\n\\begin{equation*}\n    \\I = \\xbracketMatrixstack{\n        \\ddots & & & & \\mathbf{0}&\\\\\n         & 1 & & & & \\\\\n        & & 1 & & & \\\\\n        & & & 1 & & \\\\\n        & & & & 1 & \\\\\n        &\\mathbf{0} & & &  & \\ddots\n    },\n\\end{equation*}\nand has the following special property\n\\begin{equation*}\n    \\I\\A = \\A\\I = \\A.\n\\end{equation*}\n\n\\subsection{Schemes and update equations in matrix form}\\label{sec:matrixForm}\nWith the spatial operators in matrix form presented above, the FD scheme of the 1D wave equation in Eq. \\eqref{eq:1DwaveFDS} can be written in matrix form.\n\nIf the Dirichlet boundary conditions in \\eqref{eq:discreteDirichlet} are used, the end points of the system do not have to be included in the calculation. The values of the grid function $\\uln$ for $l\\in \\{1, \\hdots, N-1\\}$ can then be stored in a column vector according to $\\u^n = [u_1^n, \\hdots, u_{N-1}^n]^T$. Furthermore, $(N-1) \\times (N-1)$ matrix $\\Dxx$ is defined as\n\\begin{equation}\\label{eq:DxxDef}\n    \\Dxx = \\frac{1}{h^2}\\xbracketMatrixstack{\n        -2 & 1 & & &\\mathbf{0}\\\\\n        1 & -2 & 1 & & \\\\\n        & \\ddots & \\ddots & \\ddots & \\\\\n        & & 1 & -2 & 1 \\\\\n        \\mathbf{0}& & & 1 & -2 \n    }.\n\\end{equation}\nIf instead, Neumann boundary conditions in Eq. \\eqref{eq:discreteDirichlet} are used, the values of $\\uln$ for the full range $l\\in \\{0, \\hdots, N\\}$ need to be stored as $\\u^n=[u_0^n, \\hdots, u_N^n]^T$ and the $(N+1) \\times (N+1)$ matrix $\\Dxx$ will be \n\\begin{equation}\\label{eq:DxxDefNeumann}\n    \\Dxx = \\frac{1}{h^2}\n    \\xbracketMatrixstack{\n        -2 & 2 & & &\\mathbf{0}\\\\\n        1 & -2 & 1 & & \\\\\n        & \\ddots & \\ddots & \\ddots & \\\\\n        & & 1 & -2 & 1 \\\\\n        \\mathbf{0}& & & 2 & -2 \n    },\n\\end{equation}\nwhere the $2$s in the top and bottom row correspond to the multiplication by $2$ with $u_1^n$ and $u_{N-1}^n$ in update equations \\eqref{eq:1DWaveLeftBound} and \\eqref{eq:1DWaveRightBound} respectively.\n\nRegardless of the boundary conditions, the FD scheme in \\eqref{eq:1DwaveFDS} can be written in matrix form as\n\\begin{equation}\\label{eq:1DwaveMatrix}\n    \\frac{1}{k^2}\\left(\\u^{n+1} - 2 \\u + \\u^{n-1}\\right) = c^2 \\Dxx \\u^n,\n\\end{equation}\nand rewritten to a matrix form of the update equation analogous to Eq. \\eqref{eq:1DwaveUpdate}\n\\begin{equation}\n    \\u^{n+1} = (2\\I + c^2k^2 \\Dxx )\\u^n - \\u^{n-1}.\n\\end{equation}\nThe identity matrix is necessary here for correct matrix addition.\n\n\\section{Mathematical tools and product identities}\nSome useful mathematical tools used for the energy analysis techniques presented in Section \\ref{sec:energyAnalysis} will be shown here. The tools shown here can be applied to 1D systems. These will be extended to 2D systems in Chapter \\ref{ch:2Dsyst}. Unless denoted otherwise, the notation and theory will follow \\cite{theBible}.\n\n\\subsection{Inner product}\\label{sec:innerProduct}\nFor two functions $f = f(x,t)$ and $g = g(x,t)$ defined for $x\\in\\D$ where $\\mathcal{D} = [0,L]$, their $l_2$ inner product and $l_2$ norm are defined as\n\\begin{equation}\\label{eq:contInnerProd}\n    \\langle f, g\\rangle_\\D = \\int_\\D fg dx \\quad \\text{and} \\quad \\lVert f \\rVert_\\D = \\sqrt{\\langle f, f \\rangle_\\D}.\n\\end{equation}\nThese functions do not have to be time-dependent (i.e., they can also simply be $f(x)$ and $g(x)$), but as all functions used in this work are in fact time-dependent, this is left for coherence. It is also important to note that these functions do not have to be `isolated' state variables per se (such as $u(x,t)$ used in the previous chapter), but could also be state variables with a derivative applied to it (such as $\\pt u(x,t)$). \n\nThe discrete inner product of any two (1D) functions $f_l^n$ and $g_l^n$ defined for $l \\in d$, with discrete domain $d = \\{0,\\hdots,N\\}$, is\n\\begin{equation}\\label{eq:discInnerProd}\n    \\langle f_l^n, g_l^n \\rangle_d = \\sum_{l = 0}^N h f_l^n g_l^n,\n\\end{equation}\nwhere the multiplication by $h$ is the discrete counterpart of $dx$ in the continuous definition in \\eqref{eq:contInnerProd}. \nAlso useful are the primed inner product\n\\begin{equation}\\label{eq:primedInnerProd}\n    \\langle f_l^n, g_l^n \\rangle_d' = \\sum_{l=1}^{N-1} h f_l^n g_l^n + \\frac{h}{2}f_0^ng_0^n + \\frac{h}{2}f_N^ng_N^n,\n\\end{equation}\nand the more general weighted inner product\n\\begin{equation}\\label{eq:weightedInnerProd}\n    \\langle f_l^n, g_l^n \\rangle_d^{\\el, \\er} = \\sum_{l=1}^{N-1} h f_l^n g_l^n + \\frac{\\el}{2}hf_0^ng_0^n + \\frac{\\er}{2}hf_N^ng_N^n,\n\\end{equation}\nwhere free parameters $0 < \\el, \\er \\leq 2$\\todo{check with Stefan} scale the boundary points of the regular inner product. Naturally, if $\\el = \\er = 1$, Eq. \\eqref{eq:weightedInnerProd} reduces to Eq. \\eqref{eq:primedInnerProd}, and if $\\el = \\er = 2$, \\eqref{eq:weightedInnerProd} reduces to \\eqref{eq:discInnerProd}.\n\n\\subsection{Summation by parts}\\label{sec:summationByParts}\nExtremely useful when performing energy analysis on distributed systems is \\textit{summation by parts}, which is the discrete counterpart of integration by parts. Although its application will only be apparent when actually performing an energy analysis (see fx. Sections \\ref{sec:1DWaveEnergyAnalysis} and \\ref{sec:energyAnalysisString}), some definitions will be presented here for future reference.\n\nHere, the same functions as in the previous section, $f(x,t)$ and $g(x,t)$ and domain $\\D$, will be used. Applying a spatial derivative to $g$, and using Eq. \\eqref{eq:contInnerProd}, integration by parts is defined as\n\\begin{equation}\\label{eq:integrationByParts}\n    \\langle f, \\px g \\rangle_\\D = -\\langle \\px f, g\\rangle_\\D + fg|_0^L\n\\end{equation}\nwhere $fg|_0^L$ describes the boundary terms that appeared in the process. One can observe that the spatial derivative switched functions, and is now applied to $f$ rather than $g$.\n\nIn discrete time, using the same two (1D) functions as before: $f_l^n$ and $g_l$ and are defined for $l\\in d$ with discrete domain $d=\\{0, \\hdots, N\\}$. Then, using the discrete inner product in Eq. \\eqref{eq:discInnerProd}, two variants of summation by parts are defined as\n\\begin{subequations}\\label{eq:summationByParts}\n    \\begin{align}\n        \\langle f_l^n, \\dxm g_l^n \\rangle_d  &= -\\langle \\dxp f_l^n, g_l^n\\rangle_d + f_{N+1}^ng_N^n - f_0^ng_{-1}^n,\\label{eq:summationByPartsMinus}\\\\\n        \\langle f_l^n, \\dxp g_l^n \\rangle_d \n        &= -\\langle \\dxm f_l^n, g_l^n\\rangle_d + f_N^ng_{N+1}^n - f_{-1}^ng_0^n.\\label{eq:summationByPartsPlus}\n    \\end{align}\n\\end{subequations}\nA derivation of Eq. \\eqref{eq:summationByPartsMinus} is given below. As in the case of integration by parts in Eq. \\eqref{eq:integrationByParts}, the process of summation by parts causes the derivative to be applied to the other function and the sign of the resulting inner product changes. Important to note, is that the sign (forward / backward) of the derivative operator has also changed. Lastly, discrete boundary terms have appeared and it can be seen that values outside of the defined domain are needed, i.e., $g_{N+1}^n$ and $f_{-1}^n$. These can be accounted for by the boundary conditions imposed on the system (see Section \\ref{sec:1DWaveDisc} as an example). \n\nOne could also choose to work with reduced domains after summation by parts. Domains that have one fewer point at the boundaries are defined as $\\underline{d} = \\{0, \\hdots, N-1\\}$, \n$\\overline{d} = \\{1, \\hdots, N\\}$ and $\\underline{\\overline{d}} = \\{1, \\hdots, N-1\\}$. The following identities can be shown to hold\n\\begin{subequations}\\label{eq:summationByParts}\n    \\begin{align}\n        \\langle f_l^n, \\dxm g_l^n \\rangle_d  &= -\\langle \\dxp f_l^n, g_l^n\\rangle_{\\underline{d}} + f_N^ng_N^n - f_0^ng_{-1}^n,\\label{eq:summationByPartsMinusBar}\\\\\n        \\langle f_l^n, \\dxp g_l^n \\rangle_d \n        &= -\\langle \\dxm f_l^n, g_l^n\\rangle_{\\overline{d}} + f_N^ng_{N+1}^n - f_0^ng_0^n,\\label{eq:summationByPartsPlusBar}\n    \\end{align}\n\\end{subequations}\nand, using the primed inner product in Eq. \\eqref{eq:primedInnerProd},\n\\begin{subequations}\n    \\begin{align}\n        \\langle f_l^n, \\dxm g_l^n \\rangle_d'  = -\\langle \\dxp f_l^n, g_l^n \\rangle_{\\underline{d}}+f_N^n\\mxm g_N^n-f_0^n\\mxm g_0^n,\\label{eq:primedIdentityMinus}\\\\\n        \\langle f_l^n, \\dxp g_l^n \\rangle_d'  = -\\langle \\dxm f_l^n, g_l^n \\rangle_{\\overline{d}}+f_N^n\\mxp g_N^n-f_0^n\\mxp g_0^n,\\label{eq:primedIdentityPlus}\n    \\end{align}\n\\end{subequations}\n%\nor the more general weighted inner product in Eq. \\eqref{eq:weightedInnerProd}\n\\begin{subequations}\n    \\begin{align}\n       &\\begin{aligned}\n        \\langle f_l^n, \\dxm g_l^n \\rangle_d^{\\el,\\er}  = -&\\langle \\dxp f_l^n, g_l^n \\rangle_{\\underline{d}}+ f_N^ng_{N-1}^n - f_0^ng_0^n \\\\\n        &+ \\frac{\\epsilon_\\text{r}}{2}f_N^n(g_N^n-g_{N-1}^n)+ \\frac{\\epsilon_\\text{l}}{2}f_0^n(g_0^n - g_{-1}^n),\n        \\end{aligned}\\label{eq:weightedIdentityMinus}\\\\\n        &\\begin{aligned}\n            \\langle f_l^n, \\dxp g_l^n \\rangle_d^{\\el,\\er}  = -&\\langle \\dxm f_l^n, g_l^n \\rangle_{\\overline{d}}+ f_N^ng_N^n - f_0^ng_1^n  \\\\\n            &+ \\frac{\\epsilon_\\text{r}}{2}f_N^n(g_{N+1}^n-g_N^n)+ \\frac{\\epsilon_\\text{l}}{2}f_0^n(g_1^n - g_0^n),\n        \\end{aligned}\\label{eq:weightedIdentityPlus}\n    \\end{align}\n\\end{subequations}\nall of which will prove useful in energy analysis techniques later on.\\todo{will it though?} A derivation of \\eqref{eq:summationByPartsMinusBar} is given below. \n\nFinally, recalling that $\\dxx = \\dxp\\dxm$, one can apply summation by parts twice to get the following identities\n\\begin{subequations}\n    \\begin{align}\n        \\langle f, \\dxx g\\rangle_d &= \\langle \\delta_{xx}f, g \\rangle_d+f_N\\delta_{x+}g_N-g_N\\delta_{x+}f_N -f_0\\delta_{x-}g_0+g_0\\delta_{x-}f_0,\\label{eq:summationsummationByPartsTwice}\\\\\n        \\langle f, \\dxx g\\rangle_d &= \\langle \\delta_{xx}f, g \\rangle_{\\underline{\\overline{d}}}+f_N\\dxp g_N-g_N\\dxm f_N -f_0\\dxm g_0+g_0\\dxp f_0,\\label{eq:summationByPartsTwiceReduced}\\\\\n        \\langle f, \\dxx g\\rangle_d' &= \\langle \\dxx f, g\\rangle_d' + f_N\\dxd g_N - g_N \\dxd f_N - f_0 \\dxd g_0 + g_0 \\dxd f_0.\\label{eq:summationByPartsTwicePrimed}\n    \\end{align}\n\\end{subequations}\n\n\\subsubsection{Derivations}\nTo see why the above identities hold true, it is useful to briefly go through a derivation. As an example, Eqs. \\eqref{eq:summationByPartsMinus} and \\eqref{eq:summationByPartsMinusBar} are derived as they have the same inner product as a starting point, but yield different results. In the following, $d=\\{0, \\hdots, N\\}$ and $N = 2$ are used. \n\nStarting with Eq. \\eqref{eq:summationByPartsMinus}, suppressing the $n$ superscript for brevity, and using the definition for the discrete inner product in Eq. \\eqref{eq:discInnerProd}, yields\n\\begin{align*}\n    \\langle f_l, \\dxm g_l \\rangle_d &= \\sum_{l = 0}^2 h f_l\\frac{1}{h}\\left(g_l - g_{l-1}\\right),\\\\\n    &= f_0g_0 - f_0g_{-1} + f_1g_1 - f_1g_0 + f_2g_2-f_2g_1,\\\\\n    &= g_0(f_0-f_1) - f_0g_{-1} + g_1(f_1-f_2) + g_2(f_2-f_3) + f_3g_2,\\\\\n    &= -g_0(f_1-f_0)- g_1(f_2-f_1) - g_2(f_3-f_2) + f_3g_2 - f_0g_{-1},\\\\\n    &= -\\sum_{l=0}^2 h g_l\\frac{1}{h}\\left(f_{l+1} - f_l\\right) + f_3g_2 - f_0g_{-1},\\\\\n    &= -\\langle \\dxp f_l, g_l\\rangle_d + f_3g_2 - f_0g_{-1}.\n\\end{align*}\nAs $N=2$, the result is identical to Eq. \\eqref{eq:summationByPartsMinus}. \n\nSimilarly, identity \\eqref{eq:summationByPartsMinusBar} can be proven to hold:\n\\begin{align*}\n    \\langle f_l, \\dxm g_l \\rangle_d &= \\sum_{l = 0}^2 h f_l\\frac{1}{h}\\left(g_l - g_{l-1}\\right),\\\\\n    &= f_0g_0 - f_0g_{-1} + f_1g_1 - f_1g_0 + f_2g_2-f_2g_1,\\\\\n    &= -f_0g_{-1} + g_0(f_0-f_1) + g_1(f_1-f_2) + f_2g_2,\\\\\n    &= - g_0(f_1 - f_0) - g_1(f_2-f_1) + f_2g_2 - f_0g_{-1},\\\\\n    &=\\sum_{l=0}^1hg_l\\frac{1}{h}(f_{l+1}-f_l) + f_2g_2 - f_0g_{-1},\\\\\n    &= -\\langle \\dxp f_l, g_l\\rangle_{\\underline{d}} + f_2g_2 - f_0g_{-1},\n\\end{align*}\nwhere the resulting inner product has a reduced domain of $\\underline{d} = \\{0, \\hdots, N-1\\}$.\nSimilar processes can be used to prove the other identities presented in this section.\n\n% Notes on primed plus:\n% \\begin{equation*}\n%     \\begin{aligned}\n%         \\langle f_l, \\dxp g_l\\rangle_d' &= \\sum_{l=1}^{N-1} hf_l\\dxp g_l + \\frac{h}{2}f_0\\dxp g_0 + \\frac{h}{2}f_3\\dxp g_3\\\\\n%         &= \\frac{h}{2}f_0\\frac{1}{h}(g_1-g_0)+hf_1\\frac{1}{h}(g_2-g_1)+ hf_2\\frac{1}{h}(g_3-g_2)+ \\frac{h}{2}f_3\\frac{1}{h}(g_4-g_3)\\\\\n%         &= \\frac{1}{2}f_0g_1-\\frac{1}{2}f_0g_0+f_1g_2-f_1g_1+f_2g_3-f_2g_2+\\frac{1}{2}f_3g_4-\\frac{1}{2}f_3g_3\\\\\n%         &= -\\frac{1}{2}f_0g_0 - g_1(f_1-f_0) - \\frac{1}{2}f_0g_1-g_2(f_2-f_1)-g_3(f_3-f_2) + \\frac{1}{2}f_3g_3 + \\frac{1}{2}f_3g_4 \\\\\n%         &= -\\sum_{l=1}^N hg_l\\dxm f_l - \\frac{1}{2}f_0g_0-\\frac{1}{2}f_0g_1+\\frac{1}{2}f_3g_3+\\frac{1}{2}f_3g_4\\\\\n%         &= - \\langle \\dxm f_l, g_l \\rangle_{\\underline{d}} + f_3(\\mxp g_3) - f_0(\\mxp g_0)\n%     \\end{aligned}\n% \\end{equation*}\n\n% Alternative domains the following:\n% \\begin{align*}\n%     \\langle f, \\dxp g \\rangle_d &= \\sum_{l = 0}^2 h f_l\\frac{1}{h}\\left(g_{l+1} - g_l\\right),\\\\\n%     &= f_0g_1 - f_0g_0 + f_1g_2 - f_1g_1 + f_2g_3-f_2g_2,\\\\\n%     &= -f_0g_0 + g_1(f_0-f_1) + g_2(f_1-f_2) + f_2g_3,\\\\\n%     &= - g_1(f_1 - f_0) - g_2(f_2-f_1) + f_2g_3 - f_0g_0,\\\\\n%     &= -\\langle \\dxm f, g\\rangle_{\\overline{d}} + f_2g_3 - f_0g_0\n% \\end{align*} \n\n\\subsection{Product identities}\\label{sec:prodIdentities}\nSome useful identities used in this work are\n\\begin{subequations}\n    \\begin{align}\n        (\\dtd \\uln)(\\dtt \\uln) &= \\dtp \\left(\\frac{1}{2}(\\dtm \\uln)^2\\right),\\label{eq:prodIdentity1}\\\\\n        (\\dtd \\uln)\\uln &= \\dtp \\left(\\frac{1}{2}\\uln e_{t-}\\uln\\right),\\label{eq:prodIdentity2}\\\\\n        (\\dtp \\uln)(\\mtp \\uln) &= \\dtp \\left(\\frac{1}{2}(\\uln)^2\\right),\\label{eq:prodIdentity3}\\\\\n        (\\dtd \\uln)(\\mu_{t\\cdot}\\uln) &= \\dtp\\left(\\frac{1}{2} \\mtm(\\uln)^2\\right),\\label{eq:prodIdentity4}\\\\\n        (\\dtd \\uln)(\\mtt \\uln) &= \\dtp\\left(\\frac{1}{8}(\\uln + e_{t-}\\uln)^2\\right)\\label{eq:prodIdentity5}\\\\\n        \\uln e_{t-}\\uln &=  (\\mtm \\uln)^2 - \\frac{k^2}{4}(\\dtm \\uln)^2\\label{eq:prodIdentityEnergyStab}\n    \\end{align}\n\\end{subequations}\nThese identities can be used for spatial derivatives as well by substituting the `$t$' subscripts for `$x$'.\n\nWhen an operator is applied to a product of two grid functions, the discrete counterpart of the product rule needs to be used according to\n\\begin{equation}\\label{eq:productRule}\n    \\dtp (\\uln\\wln) = (\\dtp \\uln)(\\mtp\\wln) + (\\mtp \\uln)(\\dtp \\wln).\n\\end{equation}\nThe same rule applies when the backward operator $\\dtm(\\uln\\wln)$ or centred operator $\\dtd(\\uln\\wln)$ is used. In that case, the forward operators $\\dtp$ and $\\mtp$ in Eq. \\eqref{eq:productRule} need to be substituted for the backward or centred versions of the operators respectively. \n\n\\section{Frequency domain analysis}\\label{sec:stabilityAnalysis}\nFrequency domain analysis, also called Fourier analysis, is a way to determine various properties of a FD scheme, including conditions for stability. The process is similar to finding stability for digital filters. In essence, a FD scheme can be seen as a complex filter of which its coefficients are defined by physical parameters.\nThis section will explain how to obtain a frequency domain representation of a scheme and will mainly follow \\cite{theBible}, albeit in a slightly more practical manner.\n\n\\subsubsection{Frequency domain representation and ansatz}\nFrequency domain analysis of FD schemes starts by performing a \\textit{z-transform} on the scheme. The z-transform converts a discrete signal into a frequency domain representation, and is extensively used in the field of digital signal processing (DSP) to analyse the behaviour and especially stability of digital filters. To not go too much into detail here, the interested reader is referred to the very comprehensive explanation on the z-transform given in \\cite[Ch. 5]{Park2010}. \n\nIf a system is distributed in space, one can perform a spatial Fourier transform on a grid function. Frequency domain analysis in the distributed case is called \\textit{von Neumann analysis} which first appeared in \\cite{vonNeumann} co-authored by John von Neumann. Later, this technique got a more general treatment in \\cite{Strikwerda1989} and is heavily used in \\cite{theBible}. The discrete-time z-transform and discrete spatial Fourier transform performed on a 1D grid function are defined as \\cite{theBible}\n\\begin{equation}\n    \\hat u  = \\sum_{n=-\\infty}^\\infty \\uln z^{-n}\\qaq \\tilde u = \\sum_{l=-\\infty}^\\infty \\uln e^{-jl\\beta h}\n\\end{equation}\nwith complex number $z = e^{sk}$, complex frequency $s=j\\omega + \\sigma$ (more elaborated on in \\ref{sec:modalAnalysis}) and real wavenumber $\\beta$. Frequency domain analysis in 2D will be elaborated on in Section \\ref{sec:stability2Dwave}.\n\nA shortcut to performing a full frequency domain analysis is to use a test solution, or \\textit{ansatz}, and replace the grid functions by their transforms. The grid function for a 1D system can be replaced by an ansatz of the form (1D) \\cite{Strikwerda1989}\\todo{check reference}\n\\begin{equation}\\label{eq:ansatz}\n    u_l^n \\ansatz z^n e^{jl\\beta h}\n\\end{equation} \nwhere ``$\\overset{\\mathcal{A}}{\\Longrightarrow}$'' indicates to replace the grid function with the ansatz (the shortcut to taking the full z-transform and spatial Fourier transform). \n\nLike in the DSP realm, the power of $z$ indicates a temporal shift, i.e., $z^{-1}$ is a one-sample delay. In a FDTD context, this corresponds to a time shift as seen in Section \\ref{sec:FDoperators}. For spatially distributed systems, a shift in $l$ can be interpreted as a phase shift of a frequency with wavenumber $\\beta$. \\todo{check} See Table \\ref{tab:zIdentities} for the frequency domain representation of grid functions with their temporal and spatial indices shifted in different ways. \n\n\n{\\renewcommand{\\arraystretch}{1.2}\n\n\\begin{table}[h]\n    \\begin{center}\n    \\begin{tabular}{|c|c|c|}\n        \\hline\n        Grid function & Ansatz & Result\\\\ \\hline\n        $u_l^n$ & $z^0 e^{j0\\beta h}$ & $1$\\\\\n        $u_l^{n+1}$ & $z^1 e^{j0\\beta h}$ & $z$\\\\\n        $u_l^{n-1}$ & $z^{-1} e^{j0\\beta h}$ & $z^{-1}$\\\\\n        $u_{l+1}^n$ & $z^0 e^{j1\\beta h}$ & $e^{j\\beta h}$\\\\\n        $u_{l-1}^n$ & $z^0 e^{j(-1)\\beta h}$ & $e^{-j\\beta h}$\\\\\n        $u_{l+2}^n$ & $z^0 e^{j2\\beta h}$ & $e^{j2\\beta h}$\\\\\n        $u_{l-2}^n$ & $z^0 e^{j(-2)\\beta h}$ & $e^{-j2\\beta h}$\\\\\n        $u_{l+1}^{n-1}$ & $z^{-1} e^{j1\\beta h}$ & $z^{-1}e^{j\\beta h}$\\\\\n        $u_{l-1}^{n-1}$ & $z^{-1} e^{j(-1)\\beta h}$ & $z^{-1}e^{-j\\beta h}$\\\\\\hline\n    \\end{tabular}\n    \\caption{Frequency domain representation of a grid function using ansatz \\eqref{eq:ansatz} with frequently appearing temporal and spatial shifts.\\label{tab:zIdentities}}\n    \\end{center}\n\\end{table}\n{\\renewcommand{\\arraystretch}{1}\n\n%In the same way, using ``$\\overset{\\mathcal{Z}}{\\Longrightarrow}$'' and ``$\\overset{\\mathcal{F}}{\\Longrightarrow}$'' to denote a discrete z-transform and Fourier transform respectively,\nUsing these definitions, the effect of various operators on a grid function can be written in their frequency domain representation. For systems distributed in space, the following trigonometric identities are extremely useful when performing the analyses \\cite[p. 71]{Abramowitz1972}:\n\\begin{subequations}\\label{eq:trigIdentities}\n    \\begin{gather}\n        \\sin(x) = \\frac{e^{jx} - e^{-jx}}{2j}\\ \\ \\Rightarrow \\ \\ \\sin^2(x) %= \\frac{e^{j2x} - 2e^{jx-jx}+ e^{-j2x}}{-4} \n        = \\frac{e^{j2x} + e^{-j2x}}{-4} + \\frac{1}{2},\\label{eq:sinIdentity}\\\\\n        \\cos(x) = \\frac{e^{jx} + e^{-jx}}{2}\\ \\ \\Rightarrow \\ \\ \\cos^2(x) %= \\frac{e^{j2x} + 2e^{jx-jx}+ e^{-j2x}}{4} \n        = \\frac{e^{j2x} + e^{-j2x}}{4} + \\frac{1}{2}.\\label{eq:cosIdentity}\n    \\end{gather}\n\\end{subequations}\nTake for example\n\\begin{equation*}\n    \\dxx \\uln = \\frac{1}{h^2}\\left(u_{l+1}^n - 2 \\uln + u_{l-1}^n\\right)\\ansatz \\frac{1}{h^2}\\left(e^{j\\beta h} - 2 + e^{-j\\beta h}\\right).\n\\end{equation*}\nThen, using $x = \\beta h / 2$, identity \\eqref{eq:sinIdentity} can be rewritten to \n\\begin{equation*}\n    e^{j\\beta h} - 2 + e^{-j\\beta h} = -4 \\sin^2(\\beta h / 2),\n\\end{equation*}\nand substituted into the above to get\n\\begin{equation*}\n    \\dxx \\uln \\ansatz -\\frac{4}{h^2}\\sin^2(\\beta h /2).\n\\end{equation*}\nExamples of various temporal FD operators applied to grid functions in their frequency domain representation are\n\\begin{equation}\\label{eq:temporalAnsatz}\n    \\begin{aligned}\n    \\dtp \\uln &\\ansatz \\frac{1}{k} \\left(z - 1\\right),& \\dtm \\uln &\\ansatz \\frac{1}{k} \\left(1 - z^{-1}\\right),\\\\\n    \\dtd \\uln&\\ansatz \\dfrac{1}{2k} \\left(z - z^{-1}\\right), &\\quad \\dtt \\uln&\\ansatz\\frac{1}{k^2} \\left(z - 2 + z^{-1}\\right)\n    \\end{aligned}\n\\end{equation}\nand for spatial operators identity \\eqref{eq:sinIdentity} can be used to obtain\n\\begin{subequations}\n\\begin{align}\n    \\dxx\\uln&\\ansatz -\\frac{4}{h^2} \\sin^2(\\beta h / 2), \\quad \\label{eq:dxxAnsatz}\\\\\n    \\dxxxx \\uln&\\ansatz\\frac{16}{h^4} \\sin^4(\\beta h / 2).\\label{eq:dxxxxAnsatz}\n\\end{align}\n\\end{subequations}\n\n\\subsubsection{Proving stability}\nSimilar to digital filters, the system is stable when the roots of the characteristic polynomial in $z$ are bounded by $1$ (unity)\\todo{only the denominator of the transfer function}\n\\begin{equation}\\label{eq:boundByUnity}\n    |z| \\leq 1.\n\\end{equation} \nIn the FDTD context, the frequency domain representation of a FD scheme results in a \\textit{characteristic equation} -- which is usually a second-order polynomial -- in $z$ and needs to satisfy condition \\eqref{eq:boundByUnity} for all wave numbers $\\beta$.\nIt can be shown that for a polynomial of the form \n\\begin{equation}\\label{eq:polynomialForm}\n    z^2 + a^{(1)}z + a^{(2)}\n\\end{equation} \nits roots satisfy condition \\eqref{eq:boundByUnity} when it abides the following condition \\cite{theBible}\n\\begin{equation}\\label{eq:condition214}\n    |a^{(1)}| - 1 \\leq a^{(2)} \\leq 1.\n\\end{equation}\nIf $a^{(2)} = 1$, the simpler condition\n\\begin{equation}\\label{eq:simplerCondition215}\n    |a^{(1)}|\\leq 2,\n\\end{equation}\nsuffices. \n\n\\subsection{Mass-spring system}\\label{sec:massSpringStability}\nRecalling the FD scheme of the mass-spring system in Eq. \\eqref{eq:massSpringUpdate}\n\\begin{equation*}\n    M \\dtt \\un = -K \\un\n\\end{equation*} \na frequency domain representation can be obtained using the ansatz in \\eqref{eq:ansatz} with $l = 0$. Using Table \\ref{tab:zIdentities} and Eqs. \\eqref{eq:temporalAnsatz} as a reference and substituting the definitions yields\n\\begin{equation*}\n    \\frac{M}{k^2}\\left(z -2 +z^{-1}\\right) = -K.\n\\end{equation*}\nGathering the terms and moving all to the left-hand side, the characteristic equation for the mass-spring system can be obtained:\n\\begin{equation}\\label{eq:massSpringCharacteristic}\n    z - \\left(2-\\frac{Kk^2}{M} \\right) + z^{-1} = 0. \n\\end{equation}\nTo begin to prove stability, this equation needs to be written in the form found in \\eqref{eq:polynomialForm}. Multiplying all the terms by $z$, and noticing that $a^{(2)} = 1$, one could continue with condition \\eqref{eq:simplerCondition215}. However, the scheme used here is a special case where the roots of the characteristic equation can not be identical \\cite{theBible}. When this happens, the output of the system will grow linearly and is called ``marginally unstable''. This means that $|a^{(1)}|\\neq 1$ and the condition in \\eqref{eq:simplerCondition215} becomes $|a^{(1)}|<2$. Continuing with this conditions yields\n\\begin{align*}\n    \\left|-2+\\frac{Kk^2}{M}\\right| &< 2,\\\\\n    -2 < -2+\\frac{Kk^2}{M} &< 2,\\\\\n    0 < \\frac{Kk^2}{M} &< 4.\n\\end{align*}\nIf only non-zero values are chosen for $K$, $k$ and $M$ they are positive (as they are already defined as being non-negative) and the first condition is always satisfied. The second condition is then easily solved for $k$ by\n\\begin{equation}\\label{eq:stabilityMK}\n    k < 2\\sqrt{\\frac{M}{K}}.\n\\end{equation}\nRecalling that $\\omega_0 = \\sqrt{K/M}$, Eq \\eqref{eq:stabilityMK} can be more compactly written as \n\\begin{equation}\n    k <\\frac{2}{\\omega_0}.\n\\end{equation}\n\n\\subsection{1D wave equation}\\label{sec:vonNeumann1DWave}\nThis section will derive the stability condition for the 1D wave equation presented in Section \\ref{sec:1DWave} using von Neumann analysis.\n\nRecalling the FD scheme in \\eqref{eq:1DwaveFDS}:\n\\begin{equation*}\n    \\dtt \\uln = c^2 \\dxx \\uln,\n\\end{equation*}\nits frequency domain representation can be obtained using the definitions in Eqs. \\eqref{eq:temporalAnsatz} and \\eqref{eq:dxxAnsatz}:\n\\begin{equation}\n    \\frac{1}{k^2}\\left(z - 2 + z^{-1}\\right) = -\\frac{4c^2}{h^2}\\sin^2\\left(\\beta h / 2\\right).\n\\end{equation}\nAlso recalling that\n\\begin{equation*}\n    \\lambda = \\frac{ck}{h},\n\\end{equation*}\nthe characteristic equation of the 1D wave equation is\n\\begin{equation}\\label{eq:1dWaveCharacteristic}\n    z + \\left(4\\lambda^2\\sin^2(\\beta h / 2) -2\\right) + z^{-1} = 0.\n\\end{equation}\n% one can now perform von Neumann analysis. Moving all terms to the left-hand side and performing a z-transform and spatial Fourier transform one get:\n% \\begin{equation}\\label{eq:zFDS}\n%     z - 2(1-\\lambda^2)1 - \\lambda^2(e^{j\\beta h}+e^{-j\\beta h}) + z^{-1} = 0.\n% \\end{equation}\n% Using the identity found in Eq. \\eqref{eq:sinIdentity} with $\\beta h = 2x \\Rightarrow x = \\beta h / 2$ one can rewrite \\eqref{eq:zFDS} to:\n% \\begin{equation}\n%      z - 2 + 2\\lambda^2 +4\\lambda^2(\\sin^2({\\beta h / 2}) - 1/2) - z^{-1} = 0,\n% \\end{equation}\n% and rewriting this yields the characteristic equation shown in Eq. (6.38):\n% \\begin{equation}\\label{eq:characteristic1D}\n%      z + 2(2\\lambda^2\\sin^2(\\beta h/2) - 1) + z^{-1} = 0.\n% \\end{equation}\n% The roots are then given by (using $X = \\lambda^2\\sin^2(\\beta h/2)$ for brevity):\n% \\begin{equation}\n% \\begin{aligned}\\nonumber\n%     z_\\pm &= \\frac{-2(2X-1) \\pm \\sqrt{4(2X-1)^2 - 4 \\cdot 1 \\cdot 1}}{2}\\\\\n%     &= 1-2X \\pm 1/2 \\cdot \\sqrt{4(2X-1)^2 - 4}\\\\\n%     &= 1-2X \\pm 1/2 \\cdot \\sqrt{4(4X^2-4X + 1) - 4}\\\\\n%     &= 1-2X \\pm 1/2 \\cdot \\sqrt{(4(4X^2 - 4X) + 4 - 4}\\\\\n%     &= 1-2X \\pm 1/2 \\cdot \\sqrt{4(4X^2 - 4X)}\\\\\n%     &= 1-2X \\pm 1/2 \\cdot 2 \\cdot \\sqrt{4X^2 - 4X}\\\\\n%     &= 1-2X \\pm \\sqrt{(1 - 2X)^2 - 1}\\\\\n% \\end{aligned}\n% \\end{equation}\n% which results in the equation for the roots (right below (6.38) in section 6.2.2):\n% \\begin{equation}\n%     z_\\pm = 1-2\\lambda^2\\sin^2(\\beta h/2) \\pm \\sqrt{(1 - 2\\lambda^2\\sin^2(\\beta h/2))^2 - 1}.\n% \\end{equation}\nThe scheme is then stable if the roots satisfy condition \\eqref{eq:boundByUnity}. As the characteristic equation is of the form in \\eqref{eq:polynomialForm} (after multiplication with $z$) with $a^{(2)} = 1$, stability is shown by abiding condition \n\\eqref{eq:simplerCondition215} for all $\\beta$ and when applied to the characteristic equation \\eqref{eq:1dWaveCharacteristic}, it can be seen that\n\\begin{equation}\\nonumber\n    \\begin{aligned}\n        |4\\lambda^2\\sin^2(\\beta h/2) - 2| &\\leq 2,\\\\\n        |2\\lambda^2\\sin^2(\\beta h/2) - 1| &\\leq 1,\\\\\n        -1 \\leq 2\\lambda^2\\sin^2(\\beta h/2) - 1 &\\leq 1,\\\\\n        0 \\leq 2\\lambda^2\\sin^2(\\beta h/2)&\\leq 2,\\\\\n        0\\leq \\lambda^2\\sin^2(\\beta h/2) &\\leq 1.\n    \\end{aligned}\n\\end{equation}\nObserving that all terms in $\\lambda^2\\sin^2(\\beta h/2)$ are squared, this term will always be non-negative and therefore always satisfy the first condition. Continuing with the second condition, and knowing that the $\\sin^2(\\beta h / 2)$-term is bounded by $1$ for all $\\beta$, yields the following stability condition:\n\\begin{equation*}\n    \\lambda \\leq 1.\n\\end{equation*}\nThis is the CFL condition given in Eq. \\eqref{eq:CFL}. To obtain the stability condition in terms of the grid spacing, the definition for $\\lambda$ is substituted and written in terms of the grid spacing\n\\begin{equation}\n    h \\geq ck,\n\\end{equation}\nwhich is the stability condition given in Eq. \\eqref{eq:1DWaveStabilityCond}.\n\n\\subsection{Discussion}\nAlthough frequency domain analysis is very useful, it can only be applied to linear and time-invariant (LTI) systems and linear and shift-invariant (LSI) systems. These, respectively, describe systems whose properties do not change over time (LTI) and space (LSI).\\footnote{Acoustic tubes with a spatially-varying cross-section presented in Chapter \\ref{ch:brass} are examples of non-LSI systems.} Furthermore, the analysis assumes systems with infinite domains, so boundary conditions are not included. Energy analysis techniques, on the other hand, allow these types of systems, even nonlinear systems, to be analysed, as well as being able to handle boundary conditions. This will be presented below.\n\n\\section{Energy analysis}\\label{sec:energyAnalysis}\nOf all analysis techniques described in this chapter, energy analysis is without a doubt the most important when working with FDTD methods. \nFirst of all, from a practical point of view, it is essential for debugging implementations of FD schemes. Especially when trying to model more complex systems, programming errors are unavoidable, and energy analysis can be extremely helpful in pinpointing where the error lies. \nSecondly, energy analysis techniques can be used to obtain stability conditions in a much more general sense than the frequency domain analysis techniques presented in Section \\ref{sec:stabilityAnalysis}. Where frequency domain analysis is restricted to LTI and LSI systems with infinite domains (for distributed systems), energy analysis can be applied to nonlinear systems and include boundary conditions \\cite{theBible}. \n\nGustafsson et al. in (the first edition of) \\cite{Gustafsson2013} worked with energy to find stability conditions for FD schemes. This, they referred to as `the energy method' and it effectively circumvented the need of a frequency domain representation to find stability conditions (as presented in Section \\ref{sec:stabilityAnalysis}). Later, energy, or more specifically `energy as a conserved quantity', was used to determine stability and passivity of systems. Bilbao gives an extensive overview in \\cite{theBible} where this has been extensively used to show stability of the FD schemes used. \n\nOne of the main goals when performing energy analysis is to find an expression for the total energy present in the system. This is referred to as the \\textit{Hamiltonian} and denoted by $\\mathfrak{H}$ in continuous time and $\\h$ in discrete time. In this work, the focus of the energy analysis will be in discrete time. %Although it is useful to perform the analysis in continuous time to have some sort of\n\nIn this section, four steps are presented and can be followed to perform a full energy analysis of a FD scheme and implement it afterwards. Then, the analysis will be performed on the mass-spring system and the 1D wave equation presented in Chapter \\ref{ch:FDTD}. Finally, it will be shown how to obtain stability conditions through the techniques presented in this section. \n\n\\subsection{Energy analysis: A 4-step tutorial}\n\n%% 4 steps for copy-pasting:\n\n% \\subsubsection{Step 1: Obtain $\\dtp \\h$}\n% \\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\n% \\subsubsection{Step 3: Check units}\n% \\subsubsection{Step 4: Implementation}\n\n\\subsubsection{Step 1: Obtain the rate of change of the total energy $\\dtp \\h$}\nThe first step to energy analysis is to take the appropriate \\textit{norm} of the scheme (see Eq. \\eqref{eq:contInnerProd}), which yields an expression for the rate of change of the energy of the system: $\\dtp\\h$. Usually, this means to take the inner product of the scheme with $(\\dtd \\uln)$ over a discrete domain $d$. See Section \\ref{sec:innerProduct} for more details on the inner product. Note that the forward time difference $\\dtp$ is used (and not the backwards or centred) because of convention and preference.\\footnote{[Bilbao, verbally]}\n\nFor the units of the resulting energy balance to add up (also see Step 3), it is useful to perform the analysis on a scheme with all physical parameters written out (so the discretised version of Eq. \\eqref{eq:massSpringPDE} rather than Eq. \\eqref{eq:massSpringCompact}).\n\n\\subsubsection{Step 2: Identify different types of energy and obtain the total energy $\\h$ by isolating $\\dtp$}\nThe energy of a FD scheme can generally be divided into three different types: the total energy contained within the system, or Hamiltonian $\\h$, energy losses through damping $\\mathfrak{q}$ and energy input through external forces or excitations $\\mathfrak{p}$. For distributed systems, an additional boundary term $\\mathfrak{b}$ appears, but vanishes under `regular' (lossless and not energy-storing) boundary conditions. Nearly any energy balance is thus of the form \n\\begin{equation}\\label{eq:energyForm}\n    \\dtp \\h = \\mathfrak{b}-\\mathfrak{q} - \\mathfrak{p}.\n\\end{equation}\nThis equation essentially says that the total energy present in the system changes due to losses and inputs. For a lossless system without externally supplied energy over the course of the simulation (so initial conditions excluded), the energy should remain unchanged over the course of the simulation, \n\\begin{equation}\\label{eq:unchangedEnergy}\n    \\dtp \\h = 0 \\quad \\Longrightarrow \\quad \\h^n = \\h^0.\n\\end{equation}\n\nAs the eventual interest lies in the total energy of the system $\\h$ and not its rate of change, $\\dtp$ must be isolated in the definition of $\\dtp \\h$. In this step, the identities in Section \\ref{sec:prodIdentities} will come in handy, as well as summation by parts described in Section \\ref{sec:summationByParts} for distributed systems.\n \nThe Hamiltonian itself can usually be further subdivided into kinetic energy and potential energy, denoted by the symbols $\\t$ and $\\v$ respectively:\n\\begin{equation}\n    \\h = \\t + \\v\n\\end{equation}\nAs a rule of thumb, the definition for kinetic energy contains `velocity squared' (as in the classical-mechanics definition $E_\\text{kin}=\\tfrac{1}{2}M\\dot u$) and the potential energy includes the restoring forces of the system. \n\n\\subsubsection{Step 3: Check the units in the expression for $\\h$}\nTo know that the previous steps have been carried out correctly, it is good to check whether the units of the resulting expression for $\\h$ is indeed in Joules, or kg $\\cdot$ m$^2 \\cdot $ s$^{-2}$. The other quantities such as energy losses $\\mathfrak{q}$ and inputs $\\mathfrak{p}$, should be in Joules per second or in SI units: kg $\\cdot$ m$^2 \\cdot $ s$^{-3}$. As mentioned in Step 1, it is therefore useful to have all physical parameters written out so that the units will be correct in this step. Some information about operators and grid functions and how they `add' units are given in Table \\ref{tab:units}. It is important to note that the time shift operator ($e_{t-}$) does not influence the units. Finally, the appearance of a grid function $\\uln$ `adds' whatever it describes. Usually, as $\\uln$ describes a displacement in m, it will `add' this to the equation. If it describes anything else, it will `add' that.\n\n{\\renewcommand{\\arraystretch}{1.2}\n\n\\begin{table}[h]\n    \\begin{center}\n    \\begin{tabular}{|l|c|c|}\n        \\hline\n        Name & Operator & Unit\\\\ \\hline\n        Inner product (1D) & $\\langle \\cdot, \\cdot\\rangle_d$ & m\\\\\n        Norm (1D) & $\\lVert \\cdot, \\cdot\\rVert_d^2$ & m\\\\\n        First order ops. in time & $\\dtp, \\dtm, \\dtd$ & s$^{-1}$\\\\\n        Second order op. in time & $\\dtt$ & s$^{-2}$\\\\\n        First order ops. in space & $\\dxp, \\dxm, \\dxd$ & m$^{-1}$\\\\\n        Second order op. in space & $\\dxx$ & m$^{-2}$\\\\\n        Shift operators & $e_{t-}, e_{x+}, \\hdots$ & -\\\\\n        Averaging operators & $\\mtp, \\mtt, \\mxd, \\hdots$ & -\\\\\\hline\n    \\end{tabular}\n    \\caption{Units of operators.\\label{tab:units}}\n    \\end{center}\n\\end{table}\n{\\renewcommand{\\arraystretch}{1}\n\n% An (1D) inner product (or norm) will `add' one `m' unit due to the $h$ in its definition in \\eqref{eq:contInnerProd}. A first-order temporal difference operator will `add' one `s$^{-1}$'-unit (because of the $1/k$) and a first-order spatial difference operator will `add' one `m$^{-1}$'-unit ($1/h$). Along these lines, a second-order time or difference operator will `add' a `s$^{-2}$' ($1/k^2$) or `m$^{-2}$'-unit ($1/h^2$) respectively.\n\n\\subsubsection{Step 4: Implement the definitions for energy and debug the FD scheme}\nIn the end, the definition for the energy can be implemented and used as a check for whether the FD scheme has been implemented correctly. Usually, the energy of the system is calculated for every iteration in the for loop and plotted after the simulation.\nFor a system without losses or energy inputs, the energy should be unchanged according to Eq. \\eqref{eq:unchangedEnergy} and can be plotted according to\n% \n\\begin{equation}\\label{eq:normalisedEnergy}\n    \\h_{\\text{e}}^n = \\frac{\\h^n - \\h^0}{\\h^0}\\ ,\\quad \\text{if}\\  \\h^0\\neq 0,\n\\end{equation}\n% \nwhere $\\h^n_\\text{e}$ can be seen as the normalised energy and shows the error variation. \nAlthough this equation should always return $0$ (as $\\h^n = \\h^0$), in a finite precision simulation, minute fluctuations of the energy should be visible due to rounding errors. Plotting the Hamiltonian should show fluctuations within \\textit{machine precision}, which is usually in the range of $10^{-15}$. Over time, the fluctuations can add up, and possibly end up out of this range, but generally, any fluctuations less than in the $10^{-10}$ range indicate that there is no programming error. See fx. Figures \\ref{fig:energyMassSpring} and \\ref{fig:energy1DWave}.\n\nFor a system with losses or energy inputs, a discrete integration, or summed form can be used (as done in fx. \\cite{Harrison2018}):\n\\begin{equation}\\label{eq:normalisedEnergyDamping}\n    \\h_{\\text{e}}^n = \\frac{\\h^n-\\h^0 + k\\sum_{m = 0}^{n-1} \\left(\\mathfrak{q}^m + \\mathfrak{p}^m\\right)}{\\h^0}\\ ,\\quad \\text{if}\\ \\h^0\\neq 0.\n\\end{equation}\\todo{check if the sum should indeed go until $n-1$ and why}\n\n\\subsection{Mass-spring system}\nRecalling the FD scheme for the simple mass-spring system in Eq. \\eqref{eq:massSpringFDS}\n\\begin{equation*}\n    M\\dtt \\un = -K\\un\n\\end{equation*}\nan energy analysis can be performed using the four steps described above. \n\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nThe energy balance of the simple mass-spring system presented in Section \\ref{sec:massSpringSystem} can be obtained by first taking the product of scheme \\eqref{eq:massSpringFDS} with $(\\dtd \\un)$:\n\\begin{equation}\\label{eq:rOCmassSpring}\n    \\dtp \\h = M(\\dtd\\un)(\\dtt \\un) + K(\\dtd\\un)(\\un) = 0.\n\\end{equation}\nNote that the inner product is not necessary as the system is not distributed.\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nAs there are no losses or externally supplied energy present in the system, all terms are part of the Hamiltonian $\\h$. To isolate $\\dtp$ from \\eqref{eq:rOCmassSpring}, one can use identities \\eqref{eq:prodIdentity1} and \\eqref{eq:prodIdentity2} to get the following:\n\\begin{equation}\n    \\dtp \\h = \\dtp\\left(\\frac{M}{2}(\\dtm\\un)^2 + \\frac{K}{2}\\un e_{t-}\\un\\right) = 0,\n\\end{equation}\nand the following definition for $\\h$ can be obtained\n\\begin{equation}\n    \\h = \\frac{M}{2}(\\dtm\\un)^2 + \\frac{K}{2}\\un e_{t-}\\un = 0.\n\\end{equation}\nThis can be rewritten in terms of the kinetic energy $\\t$ and potential energy $\\v$ according to\n\\begin{equation}\\label{eq:energyBalanceMassSpring}\n    \\h = \\t + \\v, \\qwiq\n    \\t = \\frac{M}{2}(\\dtm\\un)^2, \\qaq \\v = \\frac{K}{2}\\un e_{t-}\\un.\n\\end{equation} \n\n\\subsubsection{Step 3: Check units}\nAs mentioned above, the energy $\\h$ needs to be in Joules, or kg $\\cdot$ m$^2 \\cdot$ s$^{-2}$. Taking the terms in Eq. \\eqref{eq:energyBalanceMassSpring} one-by-one and writing them in their units results in \n\\begin{align*}\n    \\t = \\frac{M}{2}(\\dtm\\un)^2 &\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}} \\quad\\text{kg}\\cdot(\\text{s}^{-1}\\cdot \\text{m})^{2}= \\text{kg}\\cdot\\text{m}^2\\cdot\\text{s}^{-2},\\\\\n    \\v = \\frac{K}{2}\\un e_{t-}\\un&\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}} \\quad \\text{N} \\cdot \\text{m}^{-1} \\cdot \\text{m}\\cdot \\text{m} = \\text{kg}\\cdot\\text{m}^2\\cdot\\text{s}^{-2},\n\\end{align*}\nand indeed have the correct units. \n\n\\subsubsection{Step 4: Implementation}\nEquation \\eqref{eq:energyBalance1DWave} can then be implemented in the same for-loop recursion where the update is calculated.  \n\\setlstMAT\n\\begin{lstlisting}\n%% Calculate the energy using Eq. %*\\eqrefMatlab[eq:energyBalanceMassSpring]*) \n\n% Kinetic energy\nkinEnergy(n) = M / 2 * (1/k * (u - uPrev))^2;\n\n% Potential energy\npotEnergy(n) = K / 2 * u * uPrev;\n\n% Total energy (Hamiltonian)\ntotEnergy(n) = kinEnergy(n) + potEnergy(n);\n\\end{lstlisting}\nFigure \\ref{fig:energyMassSpring} shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) of the mass-spring system and shows that the deviation is indeed 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/analysis/massSpringEnergy2.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 mass-spring system are plotted in the left panel. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}). Notice that the scaling of the y-axis is $10^{-14}$ and the energy is thus within machine precision. \\label{fig:energyMassSpring}}\n\\end{figure}\n\n\\subsection{1D wave equation}\\label{sec:1DWaveEnergyAnalysis}\nEnergy analysis could be directly performed on the FD scheme in \\eqref{eq:1DwaveFDS}. However, in order for the units of the scheme to add up to energy in Joules, it is useful to write out all physical parameters. Taking the definition for the wave speed for the ideal string $c = \\sqrt{T/\\rho A}$ and multiplying both sides of Eq. \\eqref{eq:1DwaveFDS} by $\\rho A$ yields\n\\begin{equation}\\label{eq:1DWavePhysical}\n    \\rho A \\dtt \\uln = T \\dxx \\uln,\n\\end{equation}\nwhere $l\\in d$ with discrete domain $d\\in\\{0, \\hdots, N\\}$ and number of grid points $N+1$. Furthermore, Dirichlet boundary conditions as given in Eq. \\eqref{eq:discreteDirichlet} are used. A note on using Neumann boundary conditions is given at the end of this section.\n\n\\subsubsection{Step 1: Obtain $\\dtp \\h$}\nTaking an inner product using Eq. \\eqref{eq:1DWavePhysical} with $\\left( \\dtd \\uln \\right)$ and moving all terms to the left-hand side yields the definition for the rate of change of the Hamiltonian:\n\\begin{equation}\\label{eq:rOC1DWave}\n    \\dtp \\h = \\rho A \\langle \\dtd \\uln, \\dtt \\uln \\rangle_d - T \\langle \\dtd\\uln, \\dxx \\uln\\rangle_d = 0.\n\\end{equation}\n\n\n\\subsubsection{Step 2: Identify energy types and isolate $\\dtp$}\nAs in the case of the mass-spring system in the previous section, there are no losses or externally supplied energy present in the system, and all terms are part of the Hamiltonian $\\h$.\n\nTo isolate $\\dtp$ in Eq. \\eqref{eq:rOC1DWave}, the terms have to be rewritten in a way that it fits the product identities in Section \\ref{sec:prodIdentities}.\nSummation by parts as described in Section \\ref{sec:summationByParts}  can be used. Using identity \\eqref{eq:summationByPartsMinusBar}  with $f_l^n \\triangleq \\dtd \\uln$ and $g_l^n \\triangleq \\dxp \\uln$, the second term can be rewritten to \n%\n\\begin{equation*}\n    - T \\langle \\dtd\\uln, \\dxx \\uln\\rangle_d  = T\\langle \\dxp(\\dtd\\uln), \\dxp\\uln\\rangle_{\\underline{d}} - \\mathfrak{b},\n\\end{equation*}\nwhere the boundary term\n\\begin{equation*}\n    \\mathfrak{b} = T(\\dtd u_N^n)(\\dxp u_N^n) - T(\\dtd u_0^n) \\underbrace{(\\dxp u_{-1}^n)}_{\\dxm u_0^n},\n\\end{equation*}\nand reduced domain $\\underline{d} = \\{0, \\hdots, N-1\\}$. As Dirichlet boundary conditions are used, the boundary term vanishes as \n\\begin{equation*}\n    u_0^n = u_N^n = 0 \\quad \\Longrightarrow \\quad \\dtd u_0^n = \\dtd u_N^n = 0.\n\\end{equation*}\nIn other words, if the states of the system at the boundaries are zero, their velocity will also be zero. \nThen, using the discrete inner product in Eq. \\eqref{eq:discInnerProd}, Eq. \\eqref{eq:rOC1DWave} can be expanded to\n\\begin{equation}\n    \\dtp \\h = \\rho A \\sum_{l = 0}^N h(\\dtd \\uln)(\\dtt \\uln) + T \\sum_{l = 0}^N h(\\dtd \\dxp \\uln)(\\dxp \\uln)\n\\end{equation}\nThen, using identities \\eqref{eq:prodIdentity1} and \\eqref{eq:prodIdentity2}, $\\dtp$ can be isolated \n\\begin{equation}\n    \\dtp \\h = \\dtp \\left(\\frac{\\rho A}{2}\\lVert\\dtm \\uln\\rVert^2_d + \\frac{T}{2}\\langle\\dxp\\uln, e_{t-}\\dxp\\uln\\rangle_{\\underline{d}}\\right),\n\\end{equation}\nand the definition for the Hamiltonian and the kinetic and potential energy can be found:\n\\begin{equation}\\label{eq:energyBalance1DWave}\n    \\begin{gathered}\n        \\h = \\t + \\v,\\\\\n        \\text{with}\\quad \\t = \\frac{\\rho A}{2}\\lVert\\dtm \\uln\\rVert^2_d, \\qaq \\v = \\frac{T}{2}\\langle\\dxp\\uln, e_{t-}\\dxp\\uln\\rangle_{\\underline{d}}.\n    \\end{gathered}\n\\end{equation}\n\n\\subsubsection{Step 3: Check units}\nWriting out the definitions for kinetic and potential energy in Eq. \\eqref{eq:energyBalance1DWave} respectively, yields\n\\begin{align*}\n    \\t = \\frac{\\rho A}{2}\\lVert\\dtm \\uln\\rVert^2_d \\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}& \\quad \\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}^{-2},\\\\\n    \\v = \\frac{T}{2}\\langle\\dxp\\uln, e_{t-}\\dxp\\uln\\rangle_{\\underline{d}}\\ \\overset{\\text{in units}}{\\xrightarrow{\\hspace*{1cm}}}& \\quad \\text{N} \\cdot \\text{m}\\cdot (\\text{m}^{-1}\\cdot\\text{m}\\cdot \\text{m}^{-1}\\cdot\\text{m}^{-1}\\text{m}) \\\\\n    & = \\text{kg} \\cdot \\text{m}^2 \\cdot \\text{s}^{-2},\n\\end{align*}\nand are indeed in Joules. Notice that an extra `m' unit appears due to the norm and inner product.\n\n\\subsubsection{Step 4: Implementation}\nThe energy balance in Eq. \\eqref{eq:energyBalance1DWave} can be implemented with the following code in the for-loop recursion:\n\n\\setlstMAT\n\\begin{lstlisting}\n%% Calculate the energy using Eq. %*\\eqrefMatlab[eq:energyBalance1DWave]*) \n\n% Kinetic energy\nkinEnergy(n) = rho * A / 2 * h * sum((1/k * (u-uPrev)).^2);\n\n% Potential energy\npotEnergy(n) = T/(2*h) * sum(([u; 0] - [0; u]) ...\n            .* ([uPrev; 0] - [0; uPrev]));\n\n% Total energy (Hamiltonian)\ntotEnergy(n) = kinEnergy(n) + potEnergy(n);\n\\end{lstlisting}\nHere, \\texttt{u} is the vector $\\u = [u_1^n, \\hdots, u_{N-1}^n]^T$ (as Dirichlet boundary conditions are used) and need to be concatenated with $0$ in the calculation of the potential energy as the boundaries needs to be included in the calculation, despite them being 0.\\footnote{As can be seen from the definition of $\\v$ in Eq. \\eqref{eq:energyBalance1DWave}, the domain used for the inner product is $\\underline{d} = \\{0,\\hdots, N-1\\}$ and $\\v$ contains a forward difference in its definition requiring $u_N^n$ as well.}\nFigure \\ref{fig:energy1DWave} shows the plot of the normalised energy according to Eq. \\eqref{eq:normalisedEnergy} and shows that the deviation of $\\h^n$ is within machine precision.\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/analysis/1dWaveEnergy.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 1D wave equation are plotted in the left panel. The right panel shows the normalised energy (according to Eq. \\eqref{eq:normalisedEnergy}) and shows that the deviation of the energy is within machine precision. \\label{fig:energy1DWave}}\n\\end{figure}\n\n\\subsubsection{Neumann boundary conditions}\nIf Neumann boundary conditions -- as per Eq. \\eqref{eq:discreteNeumann} -- are used instead, the primed inner product in Eq. \\eqref{eq:primedInnerProd} needs to be used in Step 1. Using the identity in \\eqref{eq:primedIdentityMinus}, summation by parts of the second term results in\n\\begin{equation*}\n    - T \\langle \\dtd\\uln, \\dxx \\uln\\rangle_d'  = T\\langle \\dxp(\\dtd\\uln), \\dxp\\uln\\rangle_{\\underline{d}} - \\mathfrak{b},\n\\end{equation*}\nwhere the boundary term\n\\begin{align*}\n    \\mathfrak{b} &= T(\\dtd u_N^n)(\\mxm\\dxp u_N^n) - T(\\dtd u_0^n) (\\mxm \\dxp u_0^n),\\\\[-1em]\n    \\xLeftrightarrow{\\mystrut\\ \\text{Eq. \\eqref{eq:identity2}}\\ } \\quad &= T(\\dtd u_N^n)(\\dxd u_N^n) - T(\\dtd u_0^n) (\\dxd u_0^n).\n\\end{align*}\nAs the Neumann boundary condition states that\n\\begin{equation*}\n    \\dxd u_0^n = \\dxd u_N^n = 0\n\\end{equation*}\nthe boundary term vanishes and the energy balance results in\n%\n\\begin{equation}\\label{eq:energyBalance1DWaveNeumann}\n    \\begin{gathered}\n        \\h = \\t + \\v,\\\\\n        \\text{with}\\quad \\t = \\frac{\\rho A}{2}\\Big(\\lVert \\dtm \\uln \\rVert'_d\\Big)^2, \\qaq \\frac{T}{2}\\langle\\dxp\\uln, e_{t-}\\dxp\\uln\\rangle_{\\underline{d}}.\n    \\end{gathered}\n\\end{equation}\nUsing \\texttt{u} for the vector $\\u = [u_0^n, \\hdots, u_N^n]^T$, this is then implemented as\n\n\\setlstMAT\n\\begin{lstlisting}\n%% Calculate the energy using Eq. %*\\eqrefMatlab[eq:energyBalance1DWaveNeumann]*) \n\n% Scaling of the boundaries through weighted inner product\nscaling = [0.5; ones(N-1, 1); 0.5];\n\n% Kinetic energy\nkinEnergy(n) = rho * A / 2 * h * sum(scaling .* (1/k * (u-uPrev)).^2);\n\n% Potential energy\npotEnergy(n) = T/(2*h) * sum(u(2:end) - u(1:end-1) ...\n            .* (uPrev(2:end) - uPrev(1:end-1)));\n\n% Total energy (Hamiltonian)\ntotEnergy(n) = kinEnergy(n) + potEnergy(n);\n\\end{lstlisting}\n\n\n\\subsection{Stability using energy analysis techniques}\\label{sec:stabilityAnalysisEnergy}\nSection \\ref{sec:stabilityAnalysis} showed how to obtain a stability condition of a FD scheme using a frequency domain representation. Although not operating in the frequency domain, the energy analysis techniques presented here may also be used to obtain stability conditions of FD schemes and might even be considered more powerful than the frequency domain approach, as it can also be used to analyse spatially varying and nonlinear systems!\\todo{long sentence}\n\nTo arrive at a stability condition, the energy must be \\textit{non-negative} ($\\h \\geq 0$) or, in some cases \\textit{positive definite} ($\\h > 0$). Below, the mass-spring system and the 1D wave equation will be used as a test case.\n\n\\subsubsection{Mass-spring system}\nSection \\ref{sec:massSpringStability} mentions that the mass-spring system is a special case in that the roots of its characteristic equation can not be identical. When proving stability using energy analysis, this means that the energy of the system needs to be positive definite. It can be shown that an equation of the form \n\\begin{equation}\\label{eq:quadraticForm}\n    x^2 + y^2  + 2axy\n\\end{equation} \nis positive definite if $|a| < 1$.% If $|a| = 1$, the function is non-negative, but not positive definite.\n\nEquation \\eqref{eq:quadraticForm} can be used to prove stability for the mass spring system using the energy balance in Eq. \\eqref{eq:energyBalanceMassSpring}. One can easily conclude that $\\t$ is non-negative due to the fact that  $M > 0$ and $(\\dtm \\un)$ is squared. The potential energy $\\v$, however, is of indefinite sign. Expanding the operators in Eq. \\eqref{eq:energyBalanceMassSpring} yields\n\\begin{align*}\n    \\h &= \\frac{M}{2k^2}\\Big((\\un)^2 - 2\\un u^{n-1} + (u^{n-1})^2\\Big)+ \\frac{K}{2}\\un u^{n-1},\\\\\n    &= \\frac{M}{2k^2}\\Big((\\un)^2+ (u^{n-1})^2\\Big)+ \\left(\\frac{K}{2}-\\frac{M}{k^2}\\right)\\un u^{n-1}.\n\\end{align*}\nDividing all terms by $M/2k^2$ this equation is of the form in Eq. \\eqref{eq:quadraticForm}:\n\\begin{equation*}\n    \\h = (\\un)^2+ (u^{n-1})^2+ \\left(\\frac{Kk^2}{M} - 2\\right)\\un u^{n-1}.\n\\end{equation*}\nFor $\\h$ to be positive definite, the following condition must hold\n\\begin{equation*}\n    \\left|\\frac{Kk^2}{2M} - 1\\right| < 1.\n\\end{equation*}\nThis can then be written as\n\\begin{align*}\n    -1&<\\frac{Kk^2}{2M} - 1<1\\\\\n    0 &< \\frac{Kk^2}{2M} < 2\n\\end{align*}\nwhere, as long as $K$ and $k$ are non-zero, the first inequality is always satisfied. Then the condition solved for $k$ can easily be shown to be\n\\begin{equation}\n    k < 2\\sqrt{\\frac{M}{K}}\n\\end{equation}\nwhich is identical to the definition in Eq. \\eqref{eq:stabilityMK}.\n\n\\subsubsection{1D wave equation}\nFor the 1D wave equation, the energy must be proven to be non-negative. One can take the energy balance in Eq. \\eqref{eq:energyBalance1DWave} and conclude that $\\t$ is non-negative due to the non-negativity of the parameters and $(\\dtm \\uln)$ being squared. The potential energy, however, is of indefinite sign. One can rewrite $\\v$ using identity \\eqref{eq:prodIdentityEnergyStab} as\n\\begin{align*}\n    \\v &= \\frac{T}{2} \\langle \\dxp \\uln, e_{t-}\\dxp \\uln\\rangle_{\\underline{d}},\\\\\n    &= \\frac{T}{2} \\sum_{l=0}^{N-1} h(\\dxp \\uln)(e_{t-}\\dxp\\uln),\\\\\n    &= \\frac{T}{2} \\sum_{l=0}^{N-1} h\\left((\\mtm \\dxp \\uln)^2 - \\frac{k^2}{4}(\\dtm\\dxp \\uln)^2\\right),\\\\\n    &= \\frac{T}{2}\\left(\\lVert\\mtm\\dxp\\uln\\rVert_{\\underline{d}}^2-\\frac{k^2}{4}\\lVert\\dtm\\dxp \\uln\\rVert_{\\underline{d}}^2\\right).\n\\end{align*}\nOne can then use the following bound for spatial differences \\cite{theBible}\n\\begin{equation}\\label{eq:spatialBound}\n    \\lVert \\dxp \\uln \\rVert_{\\underline{d}} \\leq \\frac{2}{h}\\lVert \\uln \\rVert_d' \\leq \\frac{2}{h}\\lVert \\uln \\rVert_d,\n\\end{equation}\nto put a condition on $\\v$\n\\begin{align*}\n    \\v &\\geq \\frac{T}{2}\\left(\\lVert\\mtm\\dxp\\uln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{4}\\left(\\frac{2}{h}\\lVert\\dtm\\uln\\rVert_{d}\\right)^2\\right),\\\\\n    &\\geq \\frac{T}{2}\\left(\\lVert\\mtm\\dxp\\uln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{h^2}\\lVert\\dtm\\uln\\rVert_{d}^2\\right),\n\\end{align*}\nSubstituting this condition into the energy balance in Eq. \\eqref{eq:energyBalance1DWave} yields\n\\begin{align*}\n    \\h = \\t + \\v &\\geq \\frac{\\rho A}{2}\\lVert\\dtm \\uln\\rVert^2_d + \\frac{T}{2}\\left(\\lVert\\mtm\\dxp\\uln\\rVert_{\\underline{d}}^2 - \\frac{k^2}{h^2}\\lVert\\dtm\\uln\\rVert_{d}^2\\right),\\\\\n    &\\geq \\left(\\frac{\\rho A}{2} - \\frac{Tk^2}{2h^2}\\right)\\lVert \\dtm \\uln\\rVert_d^2 + \\frac{T}{2}\n    \\lVert\\mtm\\dxp \\uln\\rVert_{\\underline{d}}^2.\n\\end{align*}\nRecalling that $c = \\sqrt{T /\\rho A}$ and $\\lambda = ck/h$, all terms can be divided by $\\rho A$ which yields\n\\begin{equation}\n    \\h = \\t + \\v \\geq \\frac{1}{2}\\left(1 - \\lambda^2\\right)\\lVert \\dtm \\uln\\rVert_d^2 + \\frac{c^2}{2}\n    \\lVert\\mtm\\dxp \\uln\\rVert_{\\underline{d}}^2,\n\\end{equation}\nand is non-negative for\n\\begin{align*}\n    1-\\lambda^2 &\\geq 0,\\\\\n    \\lambda &\\leq 1.\n\\end{align*}\nThis is the same (CFL) condition obtained through von Neumann analysis in Section \\ref{sec:vonNeumann1DWave}.\n\n\\section{Modal analysis}\n\\label{sec:modalAnalysis}\nModes are the resonant frequencies of a system. The number of modes that a discrete system contains depends on the number of moving points. A mass-spring system thus has one resonating mode, but -- as briefly touched upon in Section \\ref{sec:output1DWave} -- a FD scheme of the 1D wave equation with $N = 30$ and Dirichlet boundary conditions will have $29$ modes. Modal analysis \\todo{some citation here} can be used to obtain objective data on what modes a FD scheme should contain. This can then be used to determine whether this matches one's expectations or whether the output of the system matches what the analysis predicted. Although this method is only fully accurate for LTI systems, it can still provide valuable information about systems with slow (sub-audio rate) parameter changes.\\footnote{The modal analysis techniques presented here have indeed been used extensively in paper \\citeP[G] (described in Chapter \\ref{ch:dynamicGrid}), exactly for this reason.} This section will show how to numerically obtain the modal frequencies of a FD scheme using the 1D wave equation as a test case.\n\nRecall the matrix form of the 1D wave equation from Eq. \\eqref{eq:1DwaveMatrix}\n\\begin{equation*}\n    \\frac{1}{k^2}\\left(\\u^{n+1}-2\\u^n+\\u^{n-1}\\right) = c^2 \\Dxx\\u^n.\n\\end{equation*}\nFollowing \\cite{theBible}, a test solution of the form $\\u^n = z^n\\boldPhi$ can be assumed \\todo{more explanation, perhaps refer to von neumann analysis in \\ref{sec:stabilityAnalysis}}. Substituting this into the above equation yields the characteristic equation\n\\begin{equation}\n    (z - 2 + z^{-1})\\boldPhi = c^2k^2\\Dxx \\boldPhi.\n\\end{equation}\nThis is an eigenvalue problem (see Section \\ref{sec:eigenValueProblems}) where the $p$\\th solution $\\boldPhi_p$ may be interpreted as the modal shape of mode $p$. The corresponding modal frequencies (or eigenfrequencies) are the solutions to the following equations:\n\\begin{gather}\\label{eq:1DWaveModalIntermediate}\n    z_p-2+z_p^{-1} = c^2k^2\\text{eig}_p(\\Dxx),\\nonumber\\\\\n    z_p+\\Big(-2-c^2k^2\\text{eig}_p(\\Dxx)\\Big)+z_p^{-1}=0.\n\\end{gather}\n%\\SWcomment[If the CFL condition for the scheme is satisfied, the roots will lie on the unit circle.] \nFurthermore, one can substitute a test solution $z_p = e^{s_pk}$ with complex frequency $s_p = j\\omega_p + \\sigma_p$ which contains the (angular) frequency $\\omega_p$ and damping $\\sigma_p \\leq 0$ \\todo{check with Stefan} of the $p$\\th mode.\\footnote{Notice that regardless of the possible damping coefficient per mode, the eventual amplitude of each will mostly be determined by the locations of the excitation and output as discussed in Section \\ref{sec:output1DWave}.} As there is no damping present in the system, the test solution reduces to $z_p = e^{j\\omega_p k}$ which can be substituted into Eq \\eqref{eq:1DWaveModalIntermediate} to get\n\\begin{align*}\n    e^{j\\omega_pk}+e^{-j\\omega_pk}-2-c^2k^2\\text{eig}_p(\\Dxx)&=0,\\\\\n    \\frac{e^{j\\omega_pk}+e^{-j\\omega_pk}}{-4}+\\frac{1}{2}+\\frac{c^2k^2}{4}\\text{eig}_p(\\Dxx)&=0.\n\\end{align*}\nFinally, using the trigonometric identity in Eq. \\eqref{eq:sinIdentity} yields\n\\begin{align}\n    \\sin^2(\\omega_pk/2)&+\\frac{c^2k^2}{4}\\text{eig}_p(\\Dxx)=0,\\nonumber\\\\\n    \\sin(\\omega_pk/2)&=\\frac{ck}{2}\\sqrt{-\\text{eig}_p(\\Dxx)},\\nonumber\\\\\n    \\omega_p &= \\frac{2}{k}\\sin^{-1}\\left(\\frac{ck}{2}\\sqrt{-\\text{eig}_p(\\Dxx)}\\right),\\label{eq:1DWaveModesAngular}\n\\end{align}\nand can be rewritten to \n\\begin{equation}\n    f_p = \\frac{1}{\\pi k}\\sin^{-1}\\left(\\frac{ck}{2}\\sqrt{-\\text{eig}_p(\\Dxx)}\\right)\\label{eq:1DWaveModes}\n\\end{equation}\nto get the modal frequency of the $p$\\th mode in Hz. \n\nSee Figure \\ref{fig:modalFreqs1Dwave} for a plot of the modal frequencies of an implementation of the 1D wave equation with the parameters given in Table \\ref{tab:1DWaveParams}.\nThe figure shows one great advantage of performing modal analysis on a FD scheme, over only obtaining the spectrum of its output. Although the values from the analysis do correspond to the partials shown in the frequency domain output of the 1D wave equation in Figure \\ref{fig:1DWaveOutput}, the latter does not show all modes present in the system. This is due to the input and output locations of the system as discussed in Section \\ref{sec:output1DWave}. The modal analysis does obtain the frequency data regardless of the aforementioned input and output locations. \n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width = 0.6\\textwidth]{figures/analysis/1dmodes.eps}\n    \\caption{Modal frequencies of the 1D wave equation with the parameters given in Table \\ref{tab:1DWaveParams}. \\label{fig:modalFreqs1Dwave}}\n\\end{figure}\n\n\\subsection{One-step form}\\label{sec:oneStepForm}\nFor more complicated systems, specifically those containing damping terms, it is useful to rewrite the update in \\textit{one-step form} (also referred to as a state-space representation). The damping terms cause the coefficients of $z$ and $z^{-1}$ in the characteristic equation to not be identical and the trigonometric identities in \\eqref{eq:trigIdentities} can not be used directly. Although the eigenvalue calculation needs to be done on a larger matrix, it allows for a more general and direct way to calculate the modal frequencies and damping coefficients per mode. \n\nIf matrix $\\A$ has an inverse, any scheme of the form\n\\begin{equation}\\label{eq:modalForm}\n    \\A\\u^{n+1}=\\B\\u^n + \\C\\u^{n-1},\n\\end{equation}\ncan be rewritten to\n\\begin{equation}\\label{eq:oneStepForm}\n    \\underbrace{\\begin{bmatrix}\n        \\u^{n+1}\\\\\n        \\u^n\n    \\end{bmatrix}}_{\\w^{n+1}} = \n    \\underbrace{\\begin{bmatrix}\n        \\A^{-1}\\B & \\A^{-1}\\C\\\\\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}\nwhich relates the unknown state of the system to the known state through matrix $\\Q$ which encompasses the scheme. The sizes of the identity matrix $\\I$ and zero matrix $\\mathbf{0}$ are the same size as $\\A, \\B$ and $\\C$.\n\nAgain, solutions of the form $\\w^n = z^n\\boldPhi$ can be assumed (where $\\boldPhi$ is now less-trivially connected to the modal shapes)\n\\begin{equation}\n    z\\boldPhi = \\Q\\boldPhi ,\n\\end{equation}\nwhich can be solved for the $p$th eigenvalue as\n\\begin{equation}\n    z_p = \\text{eig}_p(\\Q).\n\\end{equation}\nAs the scheme could exhibit damping, the test solution $z_p = e^{s_pk}$ is used. Substituting this yields\n\\begin{align}\n    e^{s_pk} &= \\text{eig}_p(\\Q),\\nonumber\\\\\n    s_p &= \\frac{1}{k}\\ln \\left(\\text{eig}_p(\\Q)\\right).\\label{eq:sp}\n\\end{align}\nSolutions for the frequency and damping for the $p$th eigenvalue can then be obtained through\n\\begin{equation}\n    \\omega_p = \\mathfrak{I}(s_p) \\quad \\text{and} \\quad \\sigma_p = \\mathfrak{R}(s_p),\n\\end{equation}\nwhere $\\mathfrak{I}(\\cdot)$ and $\\mathfrak{R}(\\cdot)$ denote the ``imaginary part of'' and ``real part of'' respectively. \n\nAs the elements of $\\Q$ are real-valued, the solutions $s_p$ in Eq. \\eqref{eq:sp} come in complex conjugates (pairs of numbers of which the imaginary part has an opposite sign). For analysis, only the $\\mathfrak{I}(s_p)\\geq 0$ should be considered as these correspond to non-negative frequencies. \n\n\\section{Conclusion}\nThis chapter presented three different analysis techniques in discrete time, that are of extreme utility when working with FD schemes. Frequency domain analysis, or von Neumann analysis in the distributed case, can be used to obtain stability conditions for LTI and LSI systems. Energy analysis techniques can also be used to prove stability and passivity, but for a larger range of systems including LTI, LSI, and nonlinear systems. Furthermore, energy analysis can be used in a practical manner to debug implementations of FD schemes and ensure that no programming errors have been made. Finally, modal analysis can be used to analyse the behaviour of a scheme in terms of its modal frequencies and modal shapes. This can be used to determine whether the auditory output matches the precidictions of the analysis. Although analogous techniques in continuous time also exist, a more practical angle has been chosen for this work and only the discrete time methods have been presented. For more information about the techniques in continuous time, see \\cite{theBible}.\n\nAll three analysis techniques will be extensively used in the rest of this document to analyse the FD schemes used in this project.", "meta": {"hexsha": "0cc4b24cbd2f38c599f155c430eae7707ed6be03", "size": 69865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/introduction/analysis.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/introduction/analysis.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/introduction/analysis.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": 69.4483101392, "max_line_length": 1102, "alphanum_fraction": 0.6875402562, "num_tokens": 23156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564154, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7776416822798771}}
{"text": "\\lab{Application}{K-Nearest Neighbors}{K-Nearest Neighbors}\n\\label{Ch:KNN}\n\n\\objective{Implement a K-Nearest Neighbors classification algorithm using the Nearest Neighbor search from the previous section}\n\n\\section*{Classification}\n\nA common problem is correctly classifying data.  Suppose that you have a ten marbles.  Suppose further that five of your marbles are blue with a green stripe and the other five are red with a purple stripe.  If your friend gave you an eleventh marble that was blue with a brown stripe, which group would you put it in?  Probably you would include it with the other blue marbles.  What if the marble that your friend gave you was blue with a purple stripe?  This marble shares characteristics with both groups.  Where you end up grouping it will depend on which characteristics are most important to you.\n\nThis is the intuitive classfication problem.  If we have data that is grouped into some sets for us, what set do we put new data into?  Classification has myriad and sundry applications.  In this lab we will use it in an optical character recognition application.\n\n\\section*{Nearest Neighbor Classification}\n\nWe now more formally describe the classification problem and explain the nearest neighbor classification algorithm.  Suppose that we have a collection of vectors $\\{x_1, ..., x_m\\}$ in $\\R^n$ with corresponding labels $\\{l_1, ..., l_k\\}$ describing to which group each datum belongs.  This collection of vectors and labels is called our training set.  Each entry of a vector is called a feature, and $n$ is the size of our feature set.  For example, consider the following vectors in $\\R^3$\n\n\\begin{center}\n\\begin{tabular}{cc}\n$(2,0,0)$ & $1$ \\\\\n$(3,0,0)$ & $1$ \\\\\n$(0,3,0)$ & $2$ \\\\\n$(0,2,0)$ & $2$ \\\\\n$(\\frac{1}{10},2,0)$ & $2$ \\\\\n$(0,0,4)$ & $3$ \\\\\n$(0,0,7)$ & $3$ \\\\\n\\end{tabular}\n\\end{center}\n\nIf we also have a metric on our space, we may determine the distance between all of these points.  If we are given a new datum and we wish to decide which of the three groups to include it in, one option is to choose the group to which it's closest neighbor belongs.  Let us use the euclidean metric to classify $(0,0,5)$ against our training set.  We see that the distance from $(0,0,5)$ and $(0,0,4)$ is only $1$, while the distance to the remaining points is at least $2$.  The label of $(0,0,4)$ is $3$, and so we assign $(0,0,5)$ the same label.\n\nNow, what if we wished to classify $(\\frac{5}{2},\\frac{5}{2},0)$?  This presents a problem since this point is equidistant from the points in label $1$ and label $2$.  In such a case it is up to the programmer to decide how to break the tie.\n\nOne case we need to consider is when the data that we are using in our search are on different scales. For example, suppose we wished to classify people applying for a loan at a bank as `risky' or `safe.'  Further suppose that we know their age, education level, current debt, and how many credit cards they have.  We could encode their education level as integers between $0$ and $4$.\n\nSuppose that Bob is 30 years old, well educated, has a debt of \\$5000, and 3 credit cards.  Let's say that James is 18 years old, barely out of high school, \\$5000 dollars in debt, and own 4 credit cards.  If we were to use the Euclidean metric $d$ to measure how close Bob is to James, we would get a distance of\n\\[\nd((30,4,5000,3),(18,0,5000,4)) = 12^2 + 4^2 + 1^2 = 161.\n\\]\n\nHowever, if Alice is well 29 years old, well educated, has a debt of \\$4900, and 3 credit cards, then her distance from Bob is\n\\[\nd((30,4,5000,3),(29,4,4900,3)) = 1^2 + 100^2 = 100001.\n\\]\n\nIs James closer to Bob than Alice?  Most Banks would say no.  In order to classify these individuals better, we need to measure distance differently. There are two different ways to handle this. The first is we could scale the data before inputting it into our algorithm. In our previous example we could divide age by 100, education by 4, debt by 1000 and credit cards by 10 and then preform a nearest neighbor search on Bob. Then the distance from Bob to James is \n\\[\nd((\\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10}),(\\frac{18}{100},\\frac{0}{4},\\frac{5000}{1000},\\frac{4}{10})) = .12^2 + 1^2 + .1^2 = 1.0244.\n\\]\nwhile the distace from Alice to Bob is\n\\[\nd((\\frac{30}{100},\\frac{4}{4},\\frac{5000}{1000},\\frac{3}{10}),(\\frac{29}{100},\\frac{4}{4},\\frac{4900}{1000},\\frac{3}{10})) = .1^2 + .01^2 = 0.0101.\n\\]\nSo now Bob is closer to Alice.\n\n\\begin{problem}\n\nWrite a function that takes in data points and the a vector that is used to be the scale. The function outputs the scaled data points. So if we were using it for our baking example it would take in the array representing the data Alice, Bob and James (where each person is a row) and the vector $[100,4,1000,10]$ and output the scaled data of Alice, Bob and James.\n\n\\end{problem}\n\nAnother alternative is changing the metric we used to measure distance with. In both the examples above we used our algorithm to measure distance used the Euclidean metric. Suppose one piece of data we had was color where 1 was red, 2 was violet, 3 was blue, 4 was green, 5 was yellow, 6 was orange. If we use Euclidean distance green is closer to red than orange is where is reality we want orange to be the same distance from red as violet is. The best solution would be to write your metric function that took this into account. \n\n\n\\section*{K-Nearest Neighbor Classification}\n\nOften we can improve the accuracy of a classifier by looking other points beside the nearest neighbor.  Instead, we may choose an arbitrary number $k$ and give the point to be classified the majority label in from it's $k$ nearest neighbors. \n\nThere are pitfalls to this approach.  Consider a point that's closest neighbor has the label $0$.  If we only considered the nearest neighbor, then we would be finished.  However, what if the next $10$ nearest neighbors all had the label $1$?  Do you think that we should still classify the point as $0$?  What if the nearest point has a distance of $0.1$ and the next $10$ points have a distance of at least $100$?  The answer to these questions depend on the kind of data we are working with and the metric that we choose.  One should ensure to consider how to treat situations like this when working on classification algorithms.\n\n\nThe sklearn library has neighbors module that has a KNeighborsClassifier\n\\begin{lstlisting}\nfrom sklearn import neighbors\nnbrs = neighbors.KNeighborsClassifier(n_neighbors=8 ,weights = 'distance' ,p=2)\n\\end{lstlisting}\n\nThe \\li{neighbors.KNeighborsClassifier} sets up your knearestnieghbor algorithm. \\li{n_neighbors} how many neighbors you would like to find  and \\li{weights} is how you would like to weight the neighbors you have to make the classification. weights can be \\li{'uniform'}, the majority of the k classifications is what the new value will be classified as, or \\li{'distance'}, where it weights the classifications nearer to the point heavier than those far away. The argument \\li{p} correpsods to the distance metric. For this lab we will use \\li{p=2} which is the Euclidean distance.  \n\n\\begin{lstlisting}\nnbrs.fit(points, labels)\n\\end{lstlisting}\nPoints and labels are your training data. The \\li{fit} function makes the \\li{nrbs} make a data structure containing those points and labels that is ready to be queried. \n\n\\begin{lstlisting}\nnbrs.predict(testpoints)\n\\end{lstlisting}\n\nTheses are the points you want to classify. The output is the labels that the points correspond to. More information about this package can be found at http://scikit-learn.org/stable/modules/neighbors.html.\n\\begin{problem}\n\nGet the post office handwritten digit data set. Load with\n\\begin{lstlisting}\nlabels,points,testlabels,testpoints=np.load('PostalData.npz').items()\n\\end{lstlisting}\nThis contains a training set and a test set. When you load the first entry is a name. So \\li{points[1]} and \\li{labels[1]} are the actual points and labels you want to use. Each point is a  image that is $28 \\times 28$ matrix of pixels that has been flattened. The corresponding label indicates which number was written.  Try classifying the testpoints with \\li{n_neighbors} being 4 and then 10 and \\li{weights} being \\li{'uniform'}, and then \\li{'distance'}. Then do the classfication with \\li{n_neighbors} being 1. For each one return a report indicating how your classifier performs in terms of misclassifications as a percentange (testlabels are the labels that correspond to the testpoints). Which one does the best?\n\nA similar classification process is used by the United States Postal Service to automatically determine the zip code to send a letter to.\n\n\\end{problem}\n\n\\begin{figure}[h]\n\\includegraphics[scale = 4]{Example.png}\n\\caption{An example of the number 6 taken from the data set}\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\n\n\n\n\n\n\n\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": "87b20e84bf8b888aa3248011fa86684e286f812e", "size": 8856, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/KNeighbor/KNearestNeighbor.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/KNeighbor/KNearestNeighbor.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/KNeighbor/KNearestNeighbor.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": 56.7692307692, "max_line_length": 721, "alphanum_fraction": 0.7461607949, "num_tokens": 2307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8558511543206819, "lm_q1q2_score": 0.7776416759263918}}
{"text": "\\subsection{Cross Products}\r\n\\noindent\r\nA cross product is a way of multiplying two vectors so that the result is a vector. Although the cross product technically only works for 3D vectors, we will first look a a \"fake\" 2D version to build an intuition.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = a_1b_1-a_2b_2\r\n\\end{equation*}\r\nThis \"fake\" 2D cross product gives the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\norm{\\vec{a}}\\norm{\\vec{b}}\\sin{\\theta}\t\r\n\\end{equation*}\r\nwhere $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$.\\\\\r\nAnother way to think of the magnitude of the cross product, both in 2D and 3D, is as a measure of how perpendicular two vectors are.\r\n\r\n\\begin{figure}[h]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.33]{Images/backgroundReview/CrossProduct}\r\n\\end{figure}\r\n\r\n\\noindent\r\nIn 3D, $\\vec{a}\\times\\vec{b}$ is a vector, and similar to the 2D case, the magnitude of $\\vec{a}\\times\\vec{b}$ is equal to the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\langle a_2b_3-b_2a_3,a_3b_1-b_3a_1,a_1b_2-b_1a_2 \\rangle\r\n\\end{equation*}\r\nand\r\n\\begin{equation*}\r\n\t\\norm{\\vec{a}\\times\\vec{b}}=\\norm{\\vec{a}}\\norm{\\vec{b}}\\sin{\\theta}\r\n\\end{equation*}\r\nwhere $\\theta$ is the angle between $\\vec{a}$ and $\\vec{b}$.\\\\\r\nEach component of $\\vec{a}\\times\\vec{b}$ gives the area of the parallelogram spanned by $\\vec{a}$ and $\\vec{b}$ in some plane: The x-component of $\\vec{a}\\times\\vec{b}$ gives the area in the yz-plane (x=0 plane).\\\\\r\n$\\vec{a}\\times\\vec{b}$ is perpendicular, also called \"normal,\" to the plane containing $\\vec{a}$ and $\\vec{b}$. It's direction, is determined by the right hand rule.\\\\\r\n\r\n\\noindent\r\nThe cross product table of the standard basis vectors is useful for providing some insight into the properties of the cross product.\r\n\\begin{table}[h]\r\n\t\\centering\r\n\t\\renewcommand{\\arraystretch}{1.5}\r\n\t\\begin{tabular}{|l|l|l|l|}\r\n\t\t\\hline\r\n\t\t$\\overrightarrow{\\text{row}}\\times\\overrightarrow{\\text{col}}$ & $\\hat{i}$  & $\\hat{j}$  & $\\hat{k}$  \\\\ \\hline\r\n\t\t$\\hat{i}$                                & $0$        & $\\hat{k}$  & $-\\hat{j}$ \\\\ \\hline\r\n\t\t$\\hat{j}$                                & $-\\hat{k}$ & $0$        & $\\hat{i}$  \\\\ \\hline\r\n\t\t$\\hat{k}$                                & $\\hat{j}$  & $-\\hat{i}$ & $0$        \\\\ \\hline\r\n\t\\end{tabular}\r\n\\end{table}\r\n\r\n\\begin{itemize}\r\n\t\\item \\textbf{NOT} Commutative, but is antisymmetric\r\n\t\\begin{equation*}\r\n\t\t\\vec{a}\\times\\vec{b} = -\\left(\\vec{b}\\times\\vec{a}\\right)\r\n\t\\end{equation*}\r\n\t\\item Scalar Associative\r\n\t\\begin{equation*}\r\n\t\t\\left(c\\cdot\\vec{a}\\right)\\times\\vec{b}=\\vec{a}\\times\\left(c\\cdot\\vec{b}\\right)\r\n\t\\end{equation*}\r\n\t\\item Distributive\r\n\t\\begin{equation*}\r\n\t\t\\vec{a}\\times\\left(\\vec{b}\\times\\vec{c}\\right) = \\vec{a}\\times\\vec{b} + \\vec{a}\\times\\vec{c}\r\n\t\\end{equation*}\r\n\\end{itemize}\r\n\r\n\\noindent\r\nOne can also think of the cross product as the determinant of a matrix.\r\n\\begin{equation*}\r\n\t\\vec{a}\\times\\vec{b} = \\det\\begin{bmatrix}\r\n\t\t\\hat{i}& \\hat{j} & \\hat{k} \\\\\r\n\t\ta_1 & a_2 & a_2\\\\\r\n\t\tb_1 & b_2 & b_3 \r\n\t\\end{bmatrix}\r\n\\end{equation*}", "meta": {"hexsha": "676ef0163b527e143a144995d52119d9b84eb689", "size": 3155, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/backgroundReview/crossProducts.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/backgroundReview/crossProducts.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/backgroundReview/crossProducts.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.7246376812, "max_line_length": 215, "alphanum_fraction": 0.6339144216, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837706, "lm_q2_score": 0.8558511506439708, "lm_q1q2_score": 0.7776416683500093}}
{"text": "\\subsection*{Brief Recap\\ldots}\nWorking with a real system\n\\begin{equation}\n    (A + \\delta A)x = b + \\delta b \n\\end{equation}\n\nThe numerical solution has some error $\\delta x$, with bounds given\nby\n\n\\begin{equation}\n    \\frac{\\norm{\\delta x}}{\\norm{x}} \\le \\ldots\n\\end{equation}  \n\nThe larger the condition number, the closer it is to being a singular\nmatrice and inversion is numerically unstable. Geometrically, solving\n$Ax = b$ is finding the intersection of planes. If the planes are\nnearly parallel to each other, then even small deviations in the\nplanes will lead to large deviations in the intersection point.\n\n\\section*{Finite Precision Arithmetic}\nEven if we know any quantity with infinite precision, we can only\nstore a representation of the quantity up to some finite precision.\n\nThe computers that use store finite precision binary representations,\nand computations of non-discrete systems are typically done using\nfloating point numbers. A typical floating point representation\nis something that looks like this\n\\begin{equation}\n    \\label{float-rep}\n    x_1\\vdot x_2x_3x_4x_5 \\times 10^{y_1y_2}\n\\end{equation}\n\nWhere $x_i$ are the digits in some base. Computers use binary, i.e.\nbase 2. In general, there can be multiple representations that\nwe can work with in computers. There was a need for standardization.\nSo, most machines follow the IEEE standard.\n\n\\subsection*{IEEE 754}\nIn (\\ref{float-rep}), the $x$ part is called the mantissa, and the\n $y$ part is called the exponent. Typically there is also a sign bit.\nPer IEEE 754, single precision, typically implemented as a 32 bit\nword representation.\n\\begin{itemize}\n    \\item 24 significand bits, including sign bit\n    \\item 8 exponent bits, with a bias of 127\n\\end{itemize}\n\nIn general, any floating point number (other than 0.0) can be\nrepresented as $1.x_1x_2x_3\\ldots \\times 10\\text{e}y_1y_2\\ldots$\nIn the IEEE representation, the $1.$ is implicit and only the\ndigits after the decimal are stored. This results in a somewhat\nquirky represenation of 0.0.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{figures/ieee754_1.png}\n    \\caption{An example taken from Wikipedia}\n    \\label{fig:figures-ieee754_1-png}\n\\end{figure}\n\nSo, essentially your real line has been discretized.\n\n\\subsection*{Quantization Error}\nGiven any $x \\in  \\R$ the computer takes it as $\\hat{x}:=fl(x)$,\ni.e. converts it to a floating point representation in its word\nlength.\n\n\\begin{equation}\n    \\hat{x} = \\text{fl}(x) = x(1+\\epsilon)\n\\end{equation}\n\n$\\epsilon$ is called the per-unit error.\n\nWhat is the maximum possible error introduced when\nconverting a real quantity from $\\R$ to IEEE 754? It's the\nmachine epsilon. Assume that the mantissa has $s$ bits. The\nmachine epsilon is given by\n\\begin{equation}\n    u \\approx \\frac{1}{2}10^{1-s}\n\\end{equation}\n\n\\subsection*{Operations on Floating Point Numbers}\nIf you have a binary operator that works with two numbers\nfrom $\\R$, you want to be able to simulate it.\n\nLet the `real' operation be $O(x,y)$, where  $x, y \\in  \\R$.\nWhat the machine sees and does is $F(O(\\hat{x},\\hat{y}))$,\ni.e. some errors will be introduced.\n\\begin{equation}\n    \\label{fpop}\n    \\begin{split}\n        R &= F(O(x(1 + \\epsilon_1), y(1 + \\epsilon_2)))\\\\\n          &= O(x,y)(1 + \\epsilon)\n    \\end{split}\n\\end{equation}\n\nLet's start with looking at what happens to our basic\narithmetic operations.\n\n\\subsubsection*{Multiplication}\n\\begin{equation}\n    \\begin{split}\n        F(x_1x_2) &= (x_1(1+\\epsilon_1)x_2(1 + \\epsilon_2))(1 + \\epsilon_3)\\\\\n                  &= x_1x_2(1 + \\epsilon_1)(1+\\epsilon_2)(1+\\epsilon_3)\\\\\n                  &= x_1x_2(1 + \\epsilon_1 + \\epsilon_2\n                  + \\epsilon_3 + \\mathcal{O}(u^3))\n    \\end{split}\n\\end{equation}\nSo, for multiplication the significant error goes as $3u\\approx \\mathcal{O(u)}$\n\n\\subsubsection*{Division}\n\\begin{equation}\nF(\\frac{x_1}{x_2}) \\approx (\\frac{x}{y})(1 + \\varepsilon + \\mathcal{O}(u^2))\n\\end{equation}\n\n\\subsubsection*{Addition}\nThis is troublesome\n\\begin{equation}\n    \\begin{split}\n    F(x_1 + x_2) &= x_1(1 + \\epsilon_1) + x_2(1 + \\epsilon_2)\\\\\n                 &= (x_1+x_2)(1 + \\frac{x_1\\epsilon_1}{x_1 + x_2} + \\frac{x_2\\epsilon_2}{x_1 + x_2})\n    \\end{split}\n\\end{equation}\nThe relative error depends on the operands. So, the error\nwill blow up if $x + y$ is small. This would happen if\n$x$ and $y$ have similar magnitudes, different signs.\n\nE.g. if $x = 1.24456$ and  $y = 1.23421$, so that\n $\\hat{x} = 1.2346$ and $\\hat{y} = 1.2342$. We have\n$\\hat{x} - \\hat{y} = 0.0004$, while $x - y = 0.00035$.\nThis is like approximating 35 as 40. 14\\% error.\nMeanwhile, the truncation errors were some 0.001\\%.\nAbsolutely mad.\n\nThis is called catastrophic cancellation.\nThis error can reach as high as 30\\%. Imagine how much\nerror is introduced in Gaussian elimination. Computer\nscientists were aware of the catastrophic cancellation\nerrors.\n\nThe only way around this is to use different numerical\nalgorithms, i.e. something that uses addition instead of\nsubtraction, and figure out the upper bounds for errors\nin any numerical algorithm before we even start doing\nthe computation.\n", "meta": {"hexsha": "7f1346c198108603fb2c697477eed9dddc689631", "size": 5149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matcomp/lec/lec09.tex", "max_stars_repo_name": "loonatick-src/sem-8", "max_stars_repo_head_hexsha": "956d4bfcaed74f1b4751d83303e1769f699814f8", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "matcomp/lec/lec09.tex", "max_issues_repo_name": "loonatick-src/sem-8", "max_issues_repo_head_hexsha": "956d4bfcaed74f1b4751d83303e1769f699814f8", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "matcomp/lec/lec09.tex", "max_forks_repo_name": "loonatick-src/sem-8", "max_forks_repo_head_hexsha": "956d4bfcaed74f1b4751d83303e1769f699814f8", "max_forks_repo_licenses": ["CC0-1.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.2671232877, "max_line_length": 100, "alphanum_fraction": 0.7141192465, "num_tokens": 1549, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.9005297941266013, "lm_q1q2_score": 0.7775098687803235}}
{"text": "\\input{header.tex}\n\n\\graphicspath{\n{images/png/}{images/}{images/plots/}\n}\n\n\n\\begin{document}\n\n\\setcounter{tocdepth}{2}\n\\tableofcontents\n\\newpage\n\n\\section{Laplace equation}\n\\label{chap:laplace}\n\nFor a computational domain $\\Omega\\subset \\R^d$ the Laplace equation is given by\n\\begin{equation}\\label{eq:laplace}\n  \\begin{array}{ll}\n    Δu = 0 \\quad \\text{on }\\Omega.\n  \\end{array}\n\\end{equation}\nA classical solution $u: \\Omega \\to \\R$ fulfills \\eqref{eq:laplace}. For a unique solution also boundary conditions have to be specified, e.g.\n\\begin{equation}\n  \\begin{array}{rcll}\n    ∇u(\\bfx) \\cdot \\bfn &=& 0 \\quad &\\text{on } \\Gamma_N,\\\\[4mm]\n    u(\\bfx) &=& u_0(\\bfx) \\quad &\\text{on } \\Gamma_D,\n  \\end{array}\n\\end{equation}\nwhere the homogeneous Neumann-type boundary conditions for $\\bfx \\in \\Gamma_N$ set the flux over the boundary in normal direction $\\bfn$ to zero and the Dirichlet-type boundary conditions on $\\Gamma_D$ prescribe a value for $u$ on the boundary.\n\n\\subsection{Analytical solution}\n%\nThe solution for a 1D case on $\\Omega = [0,l]$ with $u_0(0)=a$, $u_0(l)=b$, simply is\n\\begin{equation*}\n  \\begin{array}{lll}\n    u(x) = a + (b-a)\\,x/l.\n  \\end{array}\n\\end{equation*}\nFor the 2D case on $\\Omega = [0,1]^2$ with Dirichlet boundary conditions\n\\begin{equation*}\n  \\begin{array}{lll}\n    u_0(x_1,1) = \\sin(k\\,\\pi\\,x_1), \\quad k \\in \\N  \\qquad &\\text{\\say{top}},\\\\[4mm]\n    u_0(x_1,0) = u_0(0,x_2) = u_0(1,x_2) = 0  \\quad &\\text{\\say{left, right and bottom}},\\\\[4mm]\n  \\end{array}\n\\end{equation*}\nwe have the solution\n\\begin{equation*}\n  \\begin{array}{lll}\n    u(x_1,x_2) = c_1\\,\\sin(k\\,\\pi\\,x_1)\\,e^{k\\,\\pi\\,x_2} + c_2\\,\\sin(k\\,\\pi\\,x_1)\\,e^{-k\\,\\pi\\,x_2}, \\qquad \\text{where}\\\\[4mm]\n    c_1 = 1/\\big(2\\,\\sinh(k\\,\\pi)\\big), \\quad c_2=-1/\\big(2\\,\\sinh(k\\,\\pi)\\big).\n  \\end{array}\n\\end{equation*}\nAlso see exercise in \\say{Grundlagen des Wissenschaftlichen Rechnens} (2013 3.2d).\n\n\\subsection{Finite Element formulation}\n\nBy multiplication of a testfunction $\\phi\\in H^1_0(\\Omega)$ and integration follows the weak formulation of \\eqref{eq:laplace}:\n\\begin{equation}\n  \\begin{array}{ll}\n    \\ds\\int_{\\Omega}Δu\\,\\phi\\,\\d \\bfx = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega)\n  \\end{array}\n\\end{equation}\nFor a definition of $H^1_0$ see section \\ref{sec:hilbert}.\n\nThe Laplace operator can be written as $Δu=∇\\cdot(∇u)$. Applying divergence theorem in form of \\eqref{eq:gauss1} with $f=\\phi$ and $\\bfF=∇u$ yields\n\\begin{equation}\n  \\begin{array}{ll}\n    -\\ds\\int_{\\Omega}∇u \\cdot ∇\\phi \\,\\d \\bfx + \\ds\\int_{\\p \\Omega} (\\phi\\,∇u)\\cdot\\bfn\\,\\d \\bfx  = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega)\n  \\end{array}\n\\end{equation}\nBecause $\\phi$ is zero on the boundary, the second term vanishes:\n\\begin{equation}\n  \\begin{array}{ll}\n    -\\ds\\int_{\\Omega}∇u \\cdot ∇\\phi \\,\\d \\bfx = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega)\n  \\end{array}\n\\end{equation}\n\nNow we have to specify a finite-dimensional ansatz space to choose the solution function from. We do this by specifying a basis and take the span of it: $V:=\\spn\\{\\phi_1, \\dots \\phi_n\\}$.\n\nThe numerical solution is given by\n\\begin{equation}\n  \\begin{array}{ll}\n    u_h(\\bfx) = \\s{i=1}{N} u_i\\,\\phi_i(\\bfx).\n  \\end{array}\n\\end{equation}\nWe also take $V$ as the space of testfunctions.\nPlugging this into \\eqref{eq:laplace_weak} yields\n\\begin{equation}\\label{eq:laplace_discretized}\n  \\begin{array}{ll}\n    -\\s{i=1}{N} u_i \\ds\\int_{\\Omega}∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx = 0 \\quad \\text{for }j=1,\\dots,N.\n  \\end{array}\n\\end{equation}\nThe minus sign is kept for similarity with later mentioned problem equations that also have a right-hand side.\n\nA reasonable choice of ansatz functions are functions that have limited support. We discretize the domain $\\Omega$ by Finite Elements $\\Omega_e$,\n\\begin{equation}\n  \\begin{array}{ll}\n    \\Omega = \\overset{M}{\\underset{e=1}{\\bigcup}} \\,\\Omega_e = \\Omega_1 \\dot{\\cup} \\cdots \\dot{\\cup} \\Omega_M,\n  \\end{array}\n\\end{equation} and define nodes with global indices $N(e)$ on each element $e$. Interpolating ansatz functions are now chosen such that they have the value 1 at only one node and the value 0 at all other nodes. The support is contained just within the elements that are adjacent to the node where the function is 1.\n\n\\subsection{Ansatz functions}\nA simple choice that fulfills the requirements are first-order Lagrange functions $L_{i,p},p=1$ which are defined a follows for $d=1$ and depicted in \\cref{fig:lagrange}.\n\\begin{equation}\n  \\begin{array}{ll}\n    \\varphi_i: [0,1] \\to \\R,\\quad\n    \\varphi_1(x) = L_{1,1}(x) := 1-x, \\qquad \\varphi_2(x) = L_{2,1}(x) := x\n  \\end{array}\n\\end{equation}\nFor higher dimensions they are composed by a tensor product ansatz.\n\\begin{equation}\n  \\begin{array}{ll}\n    \\varphi_i(\\bfx) = \\bfL_{i}(\\bfx) := \\prod\\limits_{k=1}^{d} L_{j,1}(x_k)\n  \\end{array}\n\\end{equation}\nThe local numbering of the ansatz functions of an element proceeds fastest in the first dimension then in the second and so on as shown in \\cref{fig:element1}\n\n\\begin{figure}\n  \\centering\n  \\subfig{element1}{4cm}{Numbering and element coordinate system for a 2D first-order Lagrange element}\\,\n  \\subfig{element2}{4.5cm}{Arbitrarily shaped element}\n  \\,\n  \\subfigpdf{lagrange}{6cm}{first order Lagrange ansatz functions}\n  \\caption{2D first-order Lagrange element}\n  \\label{fig:2d-lagrange}\n\\end{figure}\n\n\\subsection{Transformation of integration domain}\nThe definition of the ansatz functions was in parameter space, i.e. on the unit interval $[0,1]^d$. The corresponding coordinate system is $\\bfxi = \\{\\xi_1, \\dots \\xi_d\\}$. However, integration over the elements $\\Omega_e$ of the computational domain is required. The node coordinates which define the elements are given in the global coordinate system $\\bfx = \\{x_1, \\dots x_d\\}$. A mapping from $\\bfxi$ to $\\bfx$ can be performed using multi-linear interpolation between the nodal coordinates $\\bfx^i$:\n\\begin{equation}\\label{eq:multilagrange}\n  \\begin{array}{ll}\n    \\bfx(\\bfxi) = \\Phi(\\bfxi) := \\ds\\sum\\limits_{i} \\bfL_i(\\bfxi)\\,\\bfx^i.\n  \\end{array}\n\\end{equation}\nNote that again Lagrange functions of first order appear, but this is part of the parameter space to global space mapping and independent of the choosen ansatz functions. For 1D and 2D problems Eq.~\\eqref{eq:multilagrange} can be written out as:\n\\begin{equation}\\label{eq:fe_phi}\n  \\begin{array}{ll}\n    \\text{1D:}\\quad\n    \\Phi(\\xi_1) =& (1-\\xi_1)\\,\\bfx^1 + \\xi_1\\,\\bfx^2\\\\[4mm]\n    \\text{2D:}\\quad\n    \\Phi(\\bfxi) =& (1-\\xi_1)\\,(1-\\xi_2)\\,\\bfx^1 + \\xi_1\\,(1-\\xi_2)\\,\\bfx^2 + (1-\\xi_1)\\,\\xi_2\\,\\bfx^3 + \\xi_1\\,\\xi_2\\,\\bfx^4.\\\\[4mm]\n    \\text{3D:}\\quad\n    \\Phi(\\bfxi) =& \n      (1-\\xi_1)\\,(1-\\xi_2)\\,(1-\\xi_3)\\,\\bfx^1 + \\xi_1\\,(1-\\xi_2)\\,(1-\\xi_3)\\,\\bfx^2 + (1-\\xi_1)\\,\\xi_2\\,(1-\\xi_3)\\,\\bfx^3 + \\xi_1\\,\\xi_2\\,(1-\\xi_3)\\,\\bfx^4\\\\[4mm]\n      &+ (1-\\xi_1)\\,(1-\\xi_2)\\,\\xi_3\\,\\bfx^5 + \\xi_1\\,(1-\\xi_2)\\,\\xi_3\\,\\bfx^6 + (1-\\xi_1)\\,\\xi_2\\,\\xi_3\\,\\bfx^7 + \\xi_1\\,\\xi_2\\,\\xi_3\\,\\bfx^8\n    \n  \\end{array}\n\\end{equation}\nThe node numbering and coordinate frames are defined by \\cref{fig:element2}.\nThe Jacobians of $\\Phi$, ${J_\\Phi = \\d \\bfx/\\d \\bfxi}$ for the 1D and 2D case are given by:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\text{1D:}\\quad &J_\\Phi(\\xi_1) = \\Phi'(\\xi_1) = \\bfx^2-\\bfx^1\\\\[4mm]\n    \\text{2D:}\\quad &J_\\Phi(\\bfxi) = \\mat{(1-\\xi_2)\\,(\n    \\bfx^2-\\bfx^1)+\\xi_2\\,(\\bfx^4-\\bfx^3) & (1-\\xi_1)\n    \\,(\\bfx^3-\\bfx^1) +\\xi_1\\,(\\bfx^4-\\bfx^2)}\\\\[4mm]\n    \\text{3D:}\\quad &J_\\Phi(\\bfxi) = \\mat{J_{\\Phi,1}(\\bfxi) & J_{\\Phi,2}(\\bfxi) & J_{\\Phi,3}(\\bfxi)}\\\\[4mm]\n    & J_{\\Phi,1}(\\bfxi) =\n     (1-\\xi_2)\\,(1-\\xi_3)\\,(\\bfx^2-\\bfx^1)\n     +\\xi_2\\,(1-\\xi_3)\\,(\\bfx^4-\\bfx^3)\n     +(1-\\xi_2)\\,\\xi_3\\,(\\bfx^6-\\bfx^5)\n     +\\xi_2\\,\\xi_3\\,(\\bfx^8-\\bfx^7) \\\\[4mm]\n    & J_{\\Phi,2}(\\bfxi) =\n     (1-\\xi_1)\\,(1-\\xi_3)\\,(\\bfx^3 -\\bfx^1)\n     + \\xi_1\\,(1-\\xi_3)\\,(\\bfx^4-\\bfx^2)\n     + (1-\\xi_1)\\,\\xi_3\\,(\\bfx^7-\\bfx^5)\n     + \\xi_1\\,\\xi_3\\,(\\bfx^8-\\bfx^6) \\\\[4mm]\n    & J_{\\Phi,3}(\\bfxi) =\n     (1-\\xi_1)\\,(1-\\xi_2)\\,(\\bfx^5 -\\bfx^1)\n     + \\xi_1\\,(1-\\xi_2)\\,(\\bfx^6-\\bfx^2)\n     + (1-\\xi_1)\\,\\xi_2\\,(\\bfx^7-\\bfx^3)\n     + \\xi_1\\,\\xi_2\\,(\\bfx^8-\\bfx^4)\n    \n  \\end{array}\n\\end{equation*}\nIn order to invert the mappings $\\Phi$ from parameter to world space, we proceed:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\text{1D:}\\quad &\\bfx^p_i = \\bfx_i^1 + \\xi_1\\,(\\bfx^2_i - \\bfx^1_i), \\quad \\forall i \\in \\{1,2,3\\}\\\\[4mm]\n    & \\Rightarrow \\quad \\xi_1 = (\\bfx^p_i - \\bfx^1_1) / (\\bfx^2_i - \\bfx^1_i) \\quad \\forall i \\in \\{1,2,3\\}\\\\[4mm]\n    \\text{2D:}\\quad & \n  \\end{array}\n\\end{equation*}\n\nThe point in world space, $\\bfx^{p}$ is computed by the sum over shape functions, $\\phi^{L}$ and control points of the element, $\\bfx^{L}$.\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfx^{p}_i(\\bfxi) = \\Phi_i(\\bfxi) = \\ds\\sum\\limits_{L} \\phi^{L}_i(\\bfxi)\\,\\bfx^{L} \\\\[4mm]\n    \\bfx^{p} = \\bfM(\\bfxi)\\,\\bfx,\n  \\end{array}\n\\end{equation*}\nwhere $\\bfM(\\bfxi)$ is a $n \\times d$ matrix with $n$ nodes and dimension $d$ and the entries \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfM_{iL}(\\bfxi) =  \\phi^{L}_i(\\bfxi)\n  \\end{array}\n\\end{equation*}\n\n\nStarting from \\eqref{eq:laplace_discretized} we now plug in the Lagrange ansatz functions for $\\phi$. Then the respective functions only have to be integrated over the elements where they are defined.\nWe get\n\\begin{equation}\\label{eq:laplace_discretized0}\n  \\begin{array}{ll}\n     -\\s{e=1}{M} \\sum_{i\\in N(e)} u_i \\ds\\int_{\\Omega_e} ∇\\phi_i(\\bfx)\\cdot ∇\\phi_j(\\bfx)\\,\\d\\bfx = 0 \\quad \\text{for }j=1,\\dots,N,\n  \\end{array}\n\\end{equation}\nwhere the sum over $i\\in N(e)$ is over the nodes of element $e$. The expression $∇\\phi(\\bfx)$ means, that the gradient is with respect to $\\bfx$, despite the function $\\phi$ being defined in parameter space, i.e. ${∇\\phi(\\bfx) = ∇_\\bfx \\phi(\\Phi^{-1}(\\bfx)) = ∇_\\bfx\\phi(\\bfxi)}$.\n\nThe integration domain, $\\Omega_e$, is described by the mapping from parameter space, $\\Omega_e = \\Phi([0,1]^d)$.\nAt every point $\\bfp = \\Phi(\\bfxi)$ the gradients are with respect to orthogonal coordinates in the tangent space of the point.\nThe tangent space coordinates for a particular point given by $\\bfxi$ are introduced as $\\bfzeta(\\bfxi)=(\\zeta_1(\\bfxi), \\dots, \\zeta_d(\\bfxi))$. The scaling is like in world space, i.e. the following holds:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\left|\\p{\\zeta_i}{\\xi_i}\\right| = \\left|\\p{\\Phi}{\\xi_i}\\right|.\n  \\end{array}\n\\end{equation*}\nThe integral in \\eqref{eq:laplace_discretized0} is then\n\\begin{equation}\\label{eq:m_int}\n  \\begin{array}{ll}\n     \\ds\\int_{\\Omega_e} ∇\\phi_i(\\bfx)\\cdot ∇\\phi_j(\\bfx)\\,\\d\\bfx = \n     \\ds\\int_{\\Phi([0,1]^d)} ∇_{\\bfzeta(\\bfxi(\\bfx))}\\phi_i(\\bfx)\\cdot ∇_{\\bfzeta(\\bfxi(\\bfx))}\\phi_j(\\bfx)\\,\\d\\bfx.\n  \\end{array}\n\\end{equation}\nDepending on dimension this is resolved differently.\n\n\\textbf{1D case.} With one dimension, we can choose $\\zeta_1 = \\xi_1 \\cdot s$, where $s$ is the scaling factor between the different length scales in world space ($\\zeta$) and parameter space ($\\xi$). Then with $\\d\\phi/\\d\\zeta = \\d\\phi/\\d\\xi\\cdot \\d\\xi/\\d\\zeta$ and $\\d\\xi/\\d\\zeta = s^{-1}$ we get\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\ds\\int_{\\Omega_e} ∇\\phi_i(\\bfx)\\cdot ∇\\phi_j(\\bfx)\\,\\d\\bfx = \n     \\ds\\int_{\\Phi([0,1])} \\d{\\phi_i(\\bfx)}{\\xi} \\d{\\phi_j(\\bfx)}{\\xi}\\Big(\\ub{\\d{\\xi}{\\zeta}}{=:s^{-1}}\\Big)^2 \\,\\d\\bfx.\n  \\end{array}\n\\end{equation*}\nThe scaling factor can be computed by \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\p{\\Phi}{\\xi} = \\p{\\zeta}{\\xi} = s \\quad \\Rightarrow \\quad s = \\Phi'(\\xi_1) = \\Vert \\bfx^2 - \\bfx^1 \\Vert_2.\n  \\end{array}\n\\end{equation*}\nAfter transformation of the integration domain to parameter space this yields the following formula for the stiffness matrix:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\ds\\int_{\\Omega_e} ∇\\phi_i(\\bfx)\\cdot ∇\\phi_j(\\bfx)\\,\\d\\bfx = \\ds\\int_{[0,1]} \\d{\\phi_i(\\xi)}{\\xi} \\d{\\phi_j(\\xi)}{\\xi} s^{-2}\\mathcal{J}_1(\\xi)\\,\\d\\xi\n  \\end{array}\n\\end{equation*}\n\n\\textbf{3D case.}\nIn 3D we use the world coordinate system as $\\bfzeta$-frame, i.e. $\\bfzeta_1 = \\bfe_1, \\bfzeta_2 = \\bfe_2, \\bfzeta_3 = \\bfe_3$.\n%\nWe transform the integration domain from global to local coordinate frame using  \\eqref{eq:integration_transformation_dd} and get:\n\\begin{equation}\\label{eq:fe_integral}\n  \\begin{array}{ll}\n     -\\s{e=1}{M} \\sum_{i\\in N(e)} u_i \\ds\\int_{[0,1]^d} ∇_{\\bfzeta(\\bfxi)}\\phi_i(\\bfxi)\\cdot ∇_{\\bfzeta(\\bfxi)}\\phi_j(\\bfxi)\\,\\mathcal{J}_d(\\bfxi)\\,\\d\\bfxi = 0 \\quad \\text{for }j=1,\\dots,N.\n  \\end{array}\n\\end{equation}\nFor a transformation of the gradients to parameter space we need the Jacobian $J_{\\Phi}$ of the coordinate mapping, $\\bfx =\\Phi(\\bfxi)$, which consists of the entries\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\big(J_{\\Phi}\\big)_{i,j} = \\d{x_i}{\\xi_j}.\n  \\end{array}\n\\end{equation*}\nNote that the Jacobian of $\\Phi: \\R^d \\to \\R^3$ might not be quadratic in general, but a $3 \\times d$ matrix with $d \\leq 3$. Only in the special 3D-case it is quadratic and can therefore be inverted.\n\nAssuming that $\\Phi$ is invertible on $\\Omega$ the inverse function theorem states\n\\begin{equation*}\n  \\begin{array}{lll}\n    J_{\\Phi^{-1}} = J_\\Phi^{-1}.\n  \\end{array}\n\\end{equation*}\n%\nExecuting the chain rule on a derivative in world space, $\\d \\phi / \\d x_k$, yields:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\d{\\phi(\\bfxi)}{x_k} = \\s{\\ell=1}{d}\\d{\\phi(\\bfxi)}{\\xi_\\ell} \\d{\\xi_\\ell(\\bfxi)}{x_k}\n  \\end{array}\n\\end{equation*}\nand for the whole gradient vector:\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇_\\bfx\\phi(\\bfxi) = J^{-\\top}_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi(\\bfxi),\n  \\end{array}\n\\end{equation*}\nwhere $J^{-\\top}_\\Phi = (J^{-1}_\\Phi)^\\top$.\n\nNow the expression $∇_\\bfx\\phi_i\\cdot ∇_\\bfx\\phi_j$ can be computed:\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇_\\bfx\\phi_i(\\bfx)\\cdot ∇_\\bfx\\phi_j(\\bfx) \n    &= \\s{k=1}{d} \\d{\\phi_i(\\bfxi)}{x_k}\\d{\\phi_j(\\bfxi)}{x_k} \n    = \\s{k=1}{d} \\Big(\\s{\\ell=1}{d}\\d{\\phi_i(\\bfxi)}{\\xi_\\ell} \\d{\\xi_\\ell(\\bfxi)}{x_k} \\s{\\ell=1}{d}\\d{\\phi_j(\\bfxi)}{\\xi_\\ell} \\d{\\xi_\\ell(\\bfxi)}{x_k} \\Big)\\\\[8mm]\n    &= J^{-\\top}_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_i(\\bfxi) \\cdot \n    J^{-\\top}_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_j(\\bfxi)\\\\[4mm]\n    &= \\big(J^{-\\top}_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_i(\\bfxi)\\big)^\\top \n    J^{-\\top}_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_j(\\bfxi)\\\\[4mm]\n    &= ∇_{\\bfxi} \\phi_i(\\bfxi)^\\top \\ub{J^{-1}_\\Phi(\\bfxi) \n    J^{-\\top}_\\Phi(\\bfxi)}{=:T_\\Phi(\\bfxi)} ∇_{\\bfxi} \\phi_j(\\bfxi).\n  \\end{array}\n\\end{equation*}\nWith the definition of the finite element Laplace operator  transformation matrix $T_\\Phi(\\bfxi) := J^{-1}_\\Phi(\\bfxi) \n    J^{-\\top}_\\Phi(\\bfxi)$ the transformation becomes:\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇_\\bfx\\phi_i(\\bfx)\\cdot ∇_\\bfx\\phi_j(\\bfx) = ∇_{\\bfxi} \\phi_i(\\bfxi) \\cdot T_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_j(\\bfxi).\n  \\end{array}\n\\end{equation*}\nThe inverse transpose $M_\\Phi(\\bfxi) := T_\\Phi(\\bfxi)^{-\\top} = J_\\Phi(\\bfxi)^{\\top}J_\\Phi(\\bfxi)$ is called the metric tensor of the mapping $\\Phi$.\n\n\\textbf{2D case.}\nIn two dimensions we consider the 2D manifold embedded in $\\R^3$ with the mapping $\\Phi: [0,1]^2 \\to \\Omega \\subset \\R^3$. At a fixed point $\\bfp \\in \\Omega$ with $\\Phi(\\bfxi_p) = \\bfp$ we first determine the tangent vectors $\\bfzeta_1(\\bfxi_p), \\bfzeta_2(\\bfxi_z)$. The first tangent vector is defined to lie on the $\\xi_1$ coordinate direction, the second vector is then constructed to be orthogonal to the first. To define the tangent vector $\\bfzeta_1$ we use a curve in parameter space:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\gamma(t) = \\mat{\\gamma_1(t) \\\\ \\gamma_2(t)} = \\mat{\\xi_{p1}+t \\\\ \\xi_{p2} }.\n  \\end{array}\n\\end{equation*}\nThen we define\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfzeta_1 &= (\\Phi \\circ \\gamma_1)'(0) \n    = \\p{t}\\Phi\\big(\\gamma(t)\\big)|_{t=0} \\\\[4mm]\n    &= \\p{\\Phi(\\gamma(0))}{\\xi_1}\\ub{\\gamma_1'(t)}{=1} + \\p{\\Phi(\\gamma(0))}{\\xi_2}\\ub{\\gamma_2'(t)}{=0}\\\\[4mm]\n    &= \\p{\\Phi(\\xi_p)}{\\xi_1}.\n  \\end{array}\n\\end{equation*}\nSimilar we define the helper tangent vector $\\bfzeta_h$ along the $\\xi_2$ coordinate, which is then\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfzeta_h = \\p{\\Phi(\\xi_p)}{\\xi_2}.\n  \\end{array}\n\\end{equation*}\n$\\bfzeta_1$ and $\\bfzeta_h$ are not orthogonal in general. Therefore a third tangent vector $\\bfzeta_2 = \\bfzeta_1\\times \\bfzeta_h \\times \\bfzeta_1$ will be defined.\n\nIt is the tangent vector of a curve \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\delta(t) = \\mat{\\delta_1(t) \\\\ \\delta_2(t)} = \\mat{\\xi_{p1}+\\cos(α)t \\\\ \\xi_{p2}+\\sin(α)t }.\n  \\end{array}\n\\end{equation*}\nThe angle $\\beta$ between $\\bfzeta_1$ and $\\bfzeta_h$ is given by\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\cos(\\beta) |\\bfzeta_1| |\\bfzeta_h| = \\bfzeta_1 \\cdot \\bfzeta_h\n    \\quad \\Rightarrow \\quad \\beta = \\arccos\\left(\\dfrac{\\bfzeta_1 \\cdot \\bfzeta_h}{|\\bfzeta_1| |\\bfzeta_h|}\\right)\n  \\end{array}\n\\end{equation*}\nThen by relating angles we get\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\dfrac{\\pi/2}{\\beta} = \\dfrac{α}{\\pi/2} \\quad \\Rightarrow \\quad \\alpha = \\dfrac{\\pi^2}{4\\,\\beta}.\n  \\end{array}\n\\end{equation*}\nSo the tangent vector becomes\n\\begin{equation}\\label{eq:tangent_vector}\n  \\begin{array}{lll}\n    \\bfzeta_2 = (\\Phi \\circ \\delta)'(0) = \\p{\\Phi(\\bfxi_p)}{\\xi_1}\\cos(α) + \\p{\\Phi(\\bfxi_p)}{\\xi_2}\\sin(α) = \\bfzeta_1\\,\\cos(α) + \\bfzeta_h\\,\\sin(α).\n  \\end{array}\n\\end{equation}\nAnother approach is to use the formula \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfzeta_2 = \\bfzeta_1\\times \\bfzeta_h \\times \\bfzeta_1,\n  \\end{array}\n\\end{equation*}\nwhich leads to the expression\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfzeta_2 = \\mat{\n    -\\p{\\Phi_2}{\\xi_1}(\\p{\\Phi_1}{\\xi_1}\\p{\\Phi_2}{\\xi_2} - \\p{\\Phi_1}{\\xi_2}\\p{\\Phi_2}{\\xi_1}) - \\p{\\Phi_3}{\\xi_1}(\\p{\\Phi_1}{\\xi_1}\\p{\\Phi_3}{\\xi_2} - \\p{\\Phi_1}{\\xi_2}\\p{\\Phi_3}{\\xi_1}) \\\\[4mm]\n \\p{\\Phi_1}{\\xi_1}(\\p{\\Phi_1}{\\xi_1}\\p{\\Phi_2}{\\xi_2} - \\p{\\Phi_1}{\\xi_2}\\p{\\Phi_2}{\\xi_1}) - \\p{\\Phi_3}{\\xi_1}(\\p{\\Phi_2}{\\xi_1}\\p{\\Phi_3}{\\xi_2} - \\p{\\Phi_2}{\\xi_2}\\p{\\Phi_3}{\\xi_1})\\\\[4mm]\n \\p{\\Phi_1}{\\xi_1}(\\p{\\Phi_1}{\\xi_1}\\p{\\Phi_3}{\\xi_2} - \\p{\\Phi_1}{\\xi_2}\\p{\\Phi_3}{\\xi_1}) + \\p{\\Phi_2}{\\xi_1}(\\p{\\Phi_2}{\\xi_1}\\p{\\Phi_3}{\\xi_2} - \\p{\\Phi_2}{\\xi_2}\\p{\\Phi_3}{\\xi_1})\n    }.\n  \\end{array}\n\\end{equation*}\nThe mapping between parameter space and tangent space is given by $\\Psi_\\bfp$:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\Psi_\\bfp : [0,1]^2 \\to T_\\bfp\\Omega,\\\\[4mm]\n    \\Psi_\\bfp(\\bfxi) = \\bfp + c_1(\\bfxi)\\,\\hat{\\bfzeta}_1 + c_2(\\bfxi)\\,\\hat{\\bfzeta}_2.\\\\[4mm]\n  \\end{array}\n\\end{equation*}\nThe basis vectors $\\hat{\\bfzeta}_i$ are the normalized tangent vectors, $\\hat{\\bfzeta}_i = \\bfzeta_i / |\\bfzeta_i|$. And the coefficients are:\n\\begin{equation*}\n  \\begin{array}{lll}\n    c_1(\\bfxi) = \\big(\\xi_1-\\xi_{p1}-(\\xi_2-\\xi_{p2})\\cos(α)/\\sin(α)\\big)\\,l_1\\\\[4mm]\n    c_2(\\bfxi) = (\\xi_2-\\xi_{p2})/\\sin(α)\\,l_2,\n  \\end{array}\n\\end{equation*}\nwith the lengths $l_1 = |\\bfzeta_1|, l_2 = |\\bfzeta_2|$.\n\nThe Jacobian of $\\Psi$ and its inverse are as follows:\n\\begin{equation*}\n  \\begin{array}{lll}\n    J_\\Psi = \\mat{l_1 & -l_1\\,\\cos(α)/\\sin(α) \\\\ 0 & l_2/\\sin(α)},\\qquad\n    J_\\Psi^{-1} = J_{\\Psi^-1} = \\mat{1/l_1 & \\cos(α)/l_2 \\\\ 0 & \\sin(α)/l_2}.\n  \\end{array}\n\\end{equation*}\nThe inverse contains the entries\n\\begin{equation*}\n  \\begin{array}{lll}\n    (J^{-1}_{\\Psi})_{i,j} = \\d{\\xi_i}{\\zeta_j}.\n  \\end{array}\n\\end{equation*}\n\nTo compute the gradients of a function with respect to $\\zeta$, we use the chain rule:\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\d{\\phi(\\bfxi)}{\\zeta_k} = \\s{\\ell=1}{d}\\d{\\phi(\\bfxi)}{\\xi_\\ell}\\d{\\xi_\\ell(\\bfxi)}{\\zeta_k},\n  \\end{array}\n\\end{equation*}\nso the gradient becomes\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇_{\\bfzeta} \\phi(\\bfxi) = J_{\\Psi}^{-\\top}∇_{\\bfxi}\\phi(\\bfxi),\n  \\end{array}\n\\end{equation*}\nwhere $J^{-\\top}_{\\Psi} = (J_\\Psi^{-1})^\\top$.\n\nAnalogous to the 3D case we define \n\\begin{equation*}\n  \\begin{array}{lll}\n    T_\\Psi(\\bfxi) := J_{\\Psi}^{-1}(\\bfxi)J_\\Psi^{-\\top}(\\bfxi) = \\mat{\\cos(α)^2/l_2^2 + 1/l_1^2 & \\sin(α)\\,\\cos(α)/l_2^2 \\\\ \\sin(α)\\,\\cos(α)/l_2^2 & \\sin(α)^2/l_2^2}\n  \\end{array}\n\\end{equation*}\nand get:\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇_{\\bfzeta}\\phi_i(\\bfx)\\cdot ∇_{\\bfzeta}\\phi_j(\\bfx) = ∇_{\\bfxi} \\phi_i(\\bfxi) \\cdot T_\\Phi(\\bfxi) ∇_{\\bfxi} \\phi_j(\\bfxi).\n  \\end{array}\n\\end{equation*}\n%Note that the computational domain $\\Omega\\subset \\R^3$ is always considered to be embedded in $\\R^3$. The 1D and 2D cases where the mesh is fully contained within a 1D or 2D subspace are then a specialization of the general case. Think of the lower dimensional meshes as a curve ($d=1$) or a bended surface ($d=2$) embedded in $\\R^3$.\n\n\\subsection{Evaluation of the integral term}\\label{chap:integral1}\nThe integral in \\eqref{eq:fe_integral} defines for $i$ and $j$ the entries $m_{ij}$ of the \\emph{stiffness matrix} $M$.\nThe equation can be written in matrix form as\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    M\\,\\bfu = \\bfzero,\n  \\end{array}\n\\end{equation*}\nwhere $M$ contains the entries\n\\begin{equation*}\n  \\begin{array}{lll}\n    m_{ij} = -\\ds\\int_{\\Omega}∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx = -\\s{e=1}{M} \\sum_{i\\in N(e)} \\ds\\int_{[0,1]^d} ∇\\phi_i(\\bfxi)\\cdot T_\\Phi(\\bfxi)∇\\phi_j(\\bfxi)\\,\\mathcal{J}_d(\\bfxi)\\,\\d\\bfxi\n  \\end{array}\n\\end{equation*}\nand $\\bfu = (u_1, \\dots, u_N)^\\top$ is the solution vector. Given $M$ the solution $\\bfu$ is computed by an appropriate linear system solver.\n\nThe integral for $m_{i,j}$ depends via $\\mathcal{J}_d$ on the shape of the elements. In general, it has to be evaluated numerically. However, for special simple cases it can be computed analytically.\nThis includes scenarios in $d=1,2,3$ dimensions where the elements are on a rectilinear cartesian grid.\n\nIf the grid is arbitrary, analytical computation for 1D is still simple. For $d=2,3$ it is still possible, but involves more lengthy derivations that are usually performed using a computer algebra system such as \\verb|sympy|. In this section the 1D and 2D cases are derived, the python \\verb|sympy| code for 2D and 3D is contained in the \\verb|doc| directory for further reference.\n\nFor all 1D meshes that are embedded in a 3D domain as well as rectangular cartesian 2D and 3D meshes the terms $T_\\Phi(\\bfxi)$ and $\\mathcal{J}_d(\\bfxi)$ are constant within each element, i.e. do not depend on $\\bfxi$. In that case we can take $\\mathcal{J}_d$ out of the integral.\n\n\\textbf{1D case.}\nWe now compute $m_{ij}$ for $d=1$. The transformation term $\\mathcal{J}_1(\\xi)$\nis defined as\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_1(\\xi) = \\Vert \\Phi'(\\xi)\\Vert_2.\n  \\end{array}\n\\end{equation*}\nUsing the parametric representation of $\\Phi$ given in \\eqref{eq:fe_phi}, we derive\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_1(\\xi) = \\Vert \\Phi'(\\xi)\\Vert_2 = \\Vert \\bfx^2 - \\bfx^1 \\Vert_2,\n  \\end{array}\n\\end{equation*}\nwhich is the length of the element $e$ with nodes $\\bfx^1$ and $\\bfx^2$. We define it to be $l_e := \\Vert\\bfx^2-\\bfx^1\\Vert_2$, and thus have $\\mathcal{J}_1(\\xi) = l_e$. The scaling factor is then $s = l_e$ and the total prefactor of the integral becomes\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_1\\,s^{-2} = 1/l_e.\n  \\end{array}\n\\end{equation*}\n\n\n\n%We use the derivatives of the Lagrange functions,\n%\\begin{equation}\n%  \\begin{array}{ll}\n%    L_{1,1}'(\\xi) = -1, \\quad L_{2,1}'(\\xi) = 1.\\\\[4mm]\n%  \\end{array}\n%\\end{equation}\n\n\\textbf{2D case.}\nFor 2D we assume a rectangular element that lies in a $z=\\text{constant}$ plane with side lengths $l_{1,e}$ and $l_{2,e}$ in $\\xi_1$ and $\\xi_2$ directions.\nThe mapping from $\\bfxi=(\\xi_1,\\xi_2)$ to $\\bfx$ coordinate frame is given by\n\\begin{equation}\n  \\begin{array}{ll}\n    \\Phi(\\bfxi) = \\bfx^1 + \\mat{\\xi_1\\,l_{1,e} \\\\[2mm] \\xi_2\\,l_{2,e}}.\n  \\end{array}\n\\end{equation}\nThen we derive\n\\begin{equation*}\n  \\begin{array}{lll}\n    J_{\\Phi}(\\bfxi) = \\mat{l_{1,e}  & 0 \\\\[2mm] 0 & l_{2,e}}\n  \\end{array}\n\\end{equation*}\nand\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_2 = \\sqrt{\\det \\big(J_{\\Phi}(\\bfxi)^\\top J_{\\Phi}(\\bfxi)\\big)} = |l_{1,e}\\,l_{2,e}|.\n  \\end{array}\n\\end{equation*}\nThe tangent vectors $\\bfzeta_1$ and $\\bfzeta_h$ are computed to be\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfzeta_1 = \\p{\\Phi(\\bfxi_p)}{\\xi_1} = (l_{1,e},0)^\\top,\\quad\n    \\bfzeta_h = \\p{\\Phi(\\bfxi_p)}{\\xi_2} = (0, l_{2,e})^\\top,\n     \\quad l_1 = |\\bfzeta_1| = l_{1,e}.\n  \\end{array}\n\\end{equation*}\nThe angle in between is\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\beta = \\arccos\\left(\\dfrac{\\bfzeta_1\\cdot \\bfzeta_h}{|\\bfzeta_1||\\bfzeta_h|}\\right) = \\dfrac{\\pi}{2}.\n  \\end{array}\n\\end{equation*}\nThe angle in parameter space is then also $\\alpha = \\pi^2 / (4\\beta) = \\pi/2$.\nUsing \\eqref{eq:tangent_vector} the orthogonal tangent vector $\\bfzeta_2$ becomes $\\bfzeta_2 = \\bfzeta_h$. Then $l_2 = |\\bfzeta_h| = l_{2,e}$.\n\nThis leads to a transformation matrix\n\\begin{equation*}\n  \\begin{array}{lll}\n    T_\\Psi(\\bfxi) = \\mat{\\cos(α)^2/l_2^2 + 1/l_1^2 & \\sin(α)\\,\\cos(α)/l_2^2 \\\\[2mm] \\sin(α)\\,\\cos(α)/l_2^2 & \\sin(α)^2/l_2^2} = \\mat{1/l_{1,e}^2 & 0 \\\\[2mm] 0 & 1/l_{2,e}^2}.\n  \\end{array}\n\\end{equation*}\nWhen the mesh resolution is uniform, i.e. $l_{1,e} = l_{2,e} = l_e$, the transformation matrix becomes a scaled identity matrix, $T_{\\Psi}(\\bfxi) = l_e^{-2}\\,\\bfI$ and the transformation can be moved out of the integral. The prefactor is then\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_2\\,l_e^{-2} = 1.\n  \\end{array}\n\\end{equation*}\n\n\n\\textbf{3D case.}\nSimilar to the 2D case when a rectangular 3D grid with grid widths $l_{1,e}, l_{2,e},l_{3,e}$ is assumed, the transformation factor becomes\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_3 = |l_{1,e}\\,l_{2,e}\\,l_{3,e}|.\n  \\end{array}\n\\end{equation*}\nWith the world mapping $\\Phi(\\bfxi)$ and its Jacobian $J_{\\Phi}(\\bfxi)$ given by\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\Phi(\\bfxi) = \\bfx^1 + \\mat{\\xi_1\\,l_{1,e}\\\\[2mm]\n    \\xi_2\\,l_{2,e}\\\\[2mm]\n    \\xi_3\\,l_{3,e}}\n  \\end{array}, \\quad \n  J_{\\Phi}(\\bfxi) = \\mat{l_{1,e}&0&0 \\\\[2mm] 0 & l_{2,e} & 0 \\\\[2mm] 0 & 0 & l_{3,e}},\n\\end{equation*}\nthe transformation matrix becomes\n\\begin{equation*}\n  \\begin{array}{lll}\n    T_\\Phi(\\bfxi) := J^{-1}_\\Phi(\\bfxi) \n    J^{-\\top}_\\Phi(\\bfxi) = \\mat{l_{1,e}^{-2}&0&0 \\\\[2mm] 0 & l_{2,e}^{-2} & 0 \\\\[2mm] 0 & 0 & l_{3,e}^{-2}}.\n  \\end{array}\n\\end{equation*}\nWith uniform grid lengths, $l_{1,e}=l_{2,e}=l_{3,e}=l_e$, we get $T_\\Phi(\\bfxi) = l_e^{-2}\\,\\bfI$. The prefactor of the integral yields\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mathcal{J}_3\\,l_e^{-2} = l_e.\n  \\end{array}\n\\end{equation*}\n\nIn the presented special cases with uniform grid resolution $\\mathcal{J}_d$ did not depend on the integration domain, which allows to compute the factor separately:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\ds\\int_{\\Omega} ∇\\phi_i \\cdot T ∇\\phi_j\\,\\mathcal{J}_d\\,\\d\\bfxi = \\mathcal{J}_d\\,l_e^{-2}\\ds\\int_{\\Omega} ∇\\phi_i \\cdot ∇\\phi_j\\,\\d\\bfxi.\n  \\end{array}\n\\end{equation*}\n\nNow the term $-\\int ∇\\phi_i\\cdot ∇\\phi_j \\,\\d\\xi$, remains to be computed. We compute values at the nodes and visualize them using \\emph{stencil notation}. For a fixed node $i$ we compute the respective values for adjacent nodes $j$. The result for $i=j$ is underlined in the stencil, the values for adjacent nodes are placed left, right, top and bottom, in the position of the respective nodes.\n\nWe first compute element-wise stencils that state the contribution of a single element. If all elements have the same length properties, the element contributions can be summed up to get the total value at the nodes which is shown in the nodal stencils. From these stencils we can easily set up the stiffness matrix for a non-varying, equidistant mesh.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|l|l|l}\n    dim & element contribution & node stencil\\\\\n    \\hline\n    1D: &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n     \\left[\\begin{array}{ccc}\n        \\underline{-1} & 1\\\\\n    \\end{array}\\right] \\quad \n  \\end{equation*}\n\\end{minipage} \n    &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\left[\\begin{array}{ccc}\n        1 & \\underline{-2} & 1\\\\\n    \\end{array}\\right]\n  \\end{equation*}\n\\end{minipage} \n     \\\\[4mm]\n     \\hline\n    2D:&\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\left[\n      \\begin{array}{ccc}\n        1/6 & 1/3 \\\\\n        \\underline{-2/3} & 1/6\n      \\end{array}\n    \\right]\n  \\end{equation*}\n\\end{minipage}  &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n      \\dfrac13\\left[\n        \\begin{array}{ccc}\n          1 & 1 & 1\\\\\n          1 & \\underline{-8} & 1 \\\\\n          1 & 1 & 1\n        \\end{array}\n      \\right]\n  \\end{equation*}\n\\end{minipage}  \\\\[4mm]\n    \\hline\n    3D: &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\text{center:} &\n      \\left[\\begin{array}{ccc}\n          0 & 1/12\\\\\n          \\underline{-1/3} & 0\\\\\n      \\end{array}\\right] \\\\[4mm]\n      \\text{top:}& \n      \\left[\\begin{array}{ccc}\n          1/12 & 1/12\\\\\n             0 & 1/12\\\\\n      \\end{array}\\right]\n    \\end{array}\n  \\end{equation*}\n\\end{minipage} &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\text{bottom:} &\n      \\dfrac1{12}\n      \\left[\\begin{array}{ccc}\n          1 & 2 & 1\\\\\n          2 & 0 & 2\\\\\n          1 & 2 & 1\n      \\end{array}\\right] \\\\[4mm]\n      \\text{center:} &\n      \\dfrac1{12}\n      \\left[\\begin{array}{ccc}\n          2 & 0 & 2\\\\\n          0 & \\underline{-32} & 0\\\\\n          2 & 0 & 2\n      \\end{array}\\right] \\\\[4mm]\n      \\text{top:}& \n      \\dfrac1{12}\n      \\left[\\begin{array}{ccc}\n          1 & 2 & 1\\\\\n          2 & 0 & 2\\\\\n          1 & 2 & 1 \n      \\end{array}\\right]\n    \\end{array}  \n  \\end{equation*}\n\\end{minipage}\n\\end{tabular}\n\\caption{Stencils of the Finite Element stiffness matrix of $-Δu$ for an equidistant mesh with uniform resolution. Note, that for 1D, 2D and 3D elements of mesh width $h$, the prefactors of the integral over the element domain are $1/h$, 1 and $h$.}\n\\end{table}\n\n\\subsection{Triangle ansatz functions in 2D}\n\nIn the following, the FEM formulation for quadratic triangles in 2D are derived.\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}{0.4\\textwidth}\n    \\def\\svgwidth{5cm}\n    \\input{images/triangle_ansatz_linear.pdf_tex}\n    \\caption{Nodes of a triangle for linear ansatz functions}\n  \\end{subfigure}\n  \\quad\n  \\begin{subfigure}{0.4\\textwidth}\n    \\def\\svgwidth{5cm}\n    \\input{images/triangle_ansatz.pdf_tex}\n    \\caption{Nodes of a triangle for quadratic ansatz functions}\n  \\end{subfigure}\n  \\label{fig:triangle_ansatz}\n\\end{figure}\n%\n\\Cref{fig:triangle_ansatz} shows a triangle for quadratic ansatz functions. The mapping from the parameter space with $\\xi_1, \\xi_2$ to the actual space is given by the following definition of $\\bfx = \\Phi(\\bfxi)$:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\Phi(\\bfxi) = \\sum\\limits_{i\\in\\{0,1,2,3,6,8\\}} \\phi_i(\\bfx)\\,\\bfx^i\\\\[4mm]\n    \\phi_0(\\bfx) = (\\xi_1 + \\xi_2 - 1)\\,(2\\xi_1 + 2\\xi_2 - 1)   \\\\[4mm]  %  1.0*(1.0*xi1 + 1.0*xi2 - 1.0)*(2.0*xi1 + 2.0*xi2 - 1.0)\n    \\phi_1(\\bfx) = 4\\,\\xi_1\\,(1 - \\xi_1 - \\xi_2)                \\\\[4mm]  % -4.0*xi1*(xi1 + xi2 - 1)\n    \\phi_2(\\bfx) = \\xi_1\\,(2\\xi_1 - 1)                          \\\\[4mm]  % 1.0*xi1*(2.0*xi1 - 1.0)\n    \\phi_3(\\bfx) = 4\\,\\xi_2\\,(1 - \\xi_1 - \\xi_2)                \\\\[4mm]  % -4.0*xi2*(xi1 + xi2 - 1)\n    \\phi_6(\\bfx) = \\xi_2\\,(2\\xi_2 - 1)                          \\\\[4mm]  % 1.0*xi2*(2.0*xi2 - 1.0)\n    \\phi_8(\\bfx) = 4\\,\\xi_1\\,\\xi_2                              \\\\[4mm]  % 4.0*xi1*xi2\n  \\end{array}\n\\end{equation*}\nThe Jacobian of this mapping is computed as:\n\\begin{equation*}\n  \\begin{array}{lll}\n    J_\\Phi(\\bfxi) = \\mat{J_{1} & J_{2}}\\quad \\text{with}\\\\[4mm]\n    J_{1} = (4\\,\\xi_1 + 4\\,\\xi_2 - 3)\\,\\bfx^0 - (8\\,\\xi_1 + 4\\,\\xi_2 - 4)\\,\\bfx^1 + (4\\,\\xi_1 - 1)\\,\\bfx^2 - 4\\,\\xi_2\\,\\bfx^3 + 4\\,\\xi_2\\,\\bfx^5,\\\\[4mm]\n    J_{2} = (4\\,\\xi_1 + 4\\,\\xi_2 - 3)\\,\\bfx^0 - 4\\,\\xi_1\\,\\bfx^1 - (4\\,\\xi_1 + 8\\,\\xi_2 - 4)\\,\\bfx^3 + (4\\,\\xi_2 - 1)\\,\\bfx^4 + 4\\,\\xi_1\\,\\bfx^5.\n  \\end{array}\n\\end{equation*}\nIntegration of the element stiffness and mass matrices according to \\eqref{eq:m_int}:\n\\begin{equation*}\n  \\begin{array}{lll}\n    k_{ij}^\\text{el} = \\ds\\int_{\\Omega_e} ∇\\phi_i(\\bfx)\\cdot ∇\\phi_j(\\bfx)\\,\\d\\bfx = \n     \\ds\\int\\limits_{\\xi_2=0}^1 \\int\\limits_{\\xi_1=0}^{1-\\xi_2} ∇_\\bfx \\phi_i(\\bfxi)\\cdot ∇_\\bfx \\phi_j(\\bfxi)\\,\\mathcal{J}_d\\,\\d\\xi_1\\,\\d\\xi_2, \\quad \\text{with}\\\\[4mm]\n    ∇_\\bfx \\phi(\\bfxi) = J_\\Phi^{-\\top}(\\bfxi)\\,∇_{\\bfxi}\\, \\phi_i(\\bfxi)\\\\[4mm]\n    m_{ij}^\\text{el} = \\ds\\int_{\\Omega_e} \\phi_i(\\bfx)\\, \\phi_j(\\bfx)\\,\\d\\bfx = \n    \\ds\\int\\limits_{\\xi_2=0}^1 \\int\\limits_{\\xi_1=0}^{1-\\xi_2} \\phi_i(\\bfxi)\\,\\phi_j(\\bfxi)\\,\\mathcal{J}_d\\,\\d\\xi_1\\,\\d\\xi_2\n  \\end{array}\n\\end{equation*}\nFor the quadrature see \\cite{zienkiewicz2005finite}.\n\nAnalogous for linear ansatz functions:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\Phi(\\bfxi) = \\sum\\limits_{i\\in\\{0,1,2\\}} \\phi_i(\\bfx)\\,\\bfx^i\\\\[4mm]\n    \\phi_0(\\bfx) = (1-\\xi_1-\\xi_2)   \\\\[4mm]\n    \\phi_1(\\bfx) = \\xi_1 \\\\[4mm]\n    \\phi_2(\\bfx) = \\xi_2\n  \\end{array}\n\\end{equation*}\nThe Jacobian is given by\n\\begin{equation*}\n  \\begin{array}{lll}\n    J_\\Phi(\\bfxi) = \\mat{J_{1} & J_{2}}\\quad \\text{with}\\\\[4mm]\n    J_{1} = -\\bfx^0 + \\bfx^1,\\\\[4mm]\n    J_{2} = -\\bfx^0 + \\bfx^2\n  \\end{array}\n\\end{equation*}\n\n\\begin{figure}\n  \\centering\n  \\begin{subfigure}{0.45\\textwidth}\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/triangle_ansatz_linear4.pdf_tex}\n    \\caption{Nodes of a triangle for linear ansatz functions}\n  \\end{subfigure}\n  \\quad\n  \\begin{subfigure}{0.45\\textwidth}\n    \\def\\svgwidth{\\textwidth}\n    \\input{images/triangle_ansatz4.pdf_tex}\n    \\caption{Nodes of a triangle for quadratic ansatz functions}\n  \\end{subfigure}\n  \\label{fig:triangle_ansatz}\n  \\caption{The red circle is the origin of the coordinate frame for every triangle.}\n\\end{figure}\n%\n\\subsection{Boundary Conditions}\n\\label{sec:bc}\nThe Neumann-type boundary condition\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇u(\\bfx)\\cdot \\bfn = 0 \\qquad \\text{on }\\Gamma_N\n  \\end{array}\n\\end{equation*}\n%\nis satisfied automatically by the Galerkin finite element formulation. Starting from the left hand side of \\eqref{eq:laplace_weak} and using Divergence theorem we get:\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    -\\i{\\Omega}{} ∇u\\cdot ∇\\phi \\,\\d \\bfx = -\\i{∂\\Omega}{} \\phi\\,\\big(∇u\\cdot \\bfn\\big) \\,\\d \\bfx + \\i{\\Omega}{} Δu\\,\\phi  \\,\\d \\bfx = 0 \\qquad ∀ \\phi \\in H^1_0(\\Omega)\n  \\end{array}\n\\end{equation*}\n%\nBecause $Δu = 0$ on $\\Omega$ we get $∇u\\cdot \\bfn=0$ on the boundary.\n\n\\subsubsection{Dirichlet boundary conditions in strong form}\nDirichlet boundary conditions can be easily considered at the discretized system. For each condition $u_i = u_{0,i}$ that enforces the degree of freedom $i\\in I_\\text{BC}$ to have the value $u_{0,i}$ we modify the linear system of equations. In the  right hand side vector we subtract from the value $f_{j}$ the product of $a_{ji}$ and the given value $u_{0,i}$ for every $j\\neq i$, i.e. the new value is $\\hat{f_j} = f_j - a_{ji}\\,u_{0,i}$. We set $f_i = u_{0,i}$. In the matrix we zero the row and column that contain the entry $a_{ii}$, i.e. $a_{ij} = a_{ji} = 0, ∀j\\neq i$ and set $a_{ii}=1$. As an example, consider the system\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mat{m_{11} & m_{12} & m_{13} \\\\ m_{21} & m_{22} & m_{23} \\\\ m_{31} & m_{32} & m_{33}}\n    \\mat{u_1 \\\\ u_2 \\\\ u_3} = \\mat{0 \\\\ 0 \\\\ 0}\n  \\end{array}\n\\end{equation*}\nwith the Dirichlet boundary condition $u_3 = u_{0,3}$. The modified system is then given by\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\mat{m_{11} & m_{12} & 0 \\\\ m_{21} & m_{22} & 0 \\\\ 0 & 0 & 1}\n    \\mat{u_1 \\\\ u_2 \\\\ u_3} = \\mat{-m_{13}\\,u_{0,3} \\\\ -m_{23}\\,u_{0,3} \\\\ u_{0,3}}.\n  \\end{array}\n\\end{equation*}\n%\n\\subsubsection{Dirichlet boundary conditions in weak form}\n%\nWe modify the system \\eqref{eq:laplace_discretized} and add the weak form of the Dirichlet boundary conditions:\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    -\\s{i=1}{N} u_i \\ds\\int_{\\Omega}∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx = -\\s{i\\in I_\\text{BC}}{}u_{0,i}\\ds\\int_{\\Omega}∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx \\quad \\text{for }j=1,\\dots,N.\n  \\end{array}\n\\end{equation*}\n\n\n\\subsection{Function spaces}\n\\label{sec:hilbert}\n%\nFor the weak solutions $u$ of the problems we do not need to request $\\CC^2(\\Omega)$, since only the first derivatives are needed and only in a weak sense. Therefore $u\\in H^1_0(\\Omega)$ suffices.\n\nThe Hilbert space $H^1(\\Omega)$ is the Sobolev space $\\W^{1,2}(\\Omega)$ which is defined using weak derivatives. The concept of weak derivatives generalizes the classical derivatives.\n\nLet $u,v\\in \\Lloc(\\Omega)$ and $\\alpha \\in \\N^d_0$ a multi-index. Then $v$ is called \\emph{weak derivative} of $u$ of order $\\alpha$ if\n\\begin{equation}\n  \\begin{array}{ll}\n    \\i{\\Omega}{}u(\\bfx) \\D^\\alpha \\phi(\\bfx) \\,\\d \\bfx = (-1)^{|\\alpha|} \\i{\\Omega}{} v(\\bfx)\\,\\phi(\\bfx)\\,\\d \\bfx\n  \\end{array}\n\\end{equation}\nfor all $\\phi \\in \\CC^\\infty_0(\\Omega)$. We then write $\\D^\\alpha u = v$. The derivative with the multi-index, $\\D^\\alpha$ is given by\n\\begin{equation}\n  \\begin{array}{ll}\n    \\D^\\alpha = \\dfrac{\\p^{|\\alpha|}}{\\p^{\\alpha_1}_{x_1} \\cdots \\p^{\\alpha_d}_{x_d}}\n  \\end{array}\n\\end{equation}\n\nIf $u$ is differentable in a classical sense, the classical derivatives are also the weak derivatives. \n\nNow we define the \\emph{Sobolev} space $\\W^{1,2}(\\Omega)$ (1=first order weak derivatives, 2=derivatives in $\\L^2(\\Omega)$)) as follows:\n\\begin{equation}\n  \\begin{array}{ll}\n    \\W^{1,2}(\\Omega) := \\{ u \\in \\Lloc(\\Omega) \\mid |\\alpha| \\in \\N^d_0, |\\alpha| \\leq 1, \\D^\\alpha u \\text{ exists}, \\D^\\alpha u \\in \\L^2(\\Omega)\\}.\n  \\end{array}\n\\end{equation}\nWith an appropriate Sobolev norm, $\\W^{1,2}$ is a Banach space, i.e. complete (Cauchy series converge in it).\n\nTogether with the scalar product\n\\begin{equation}\n  \\begin{array}{ll}\n    (u,v)_{H^1} := \\sum\\limits_{|\\alpha|\\leq 1} \\i{\\Omega}{}{\\D^\\alpha u(\\bfx) \\,\\D^\\alpha v(\\bfx) \\,\\d\\bfx}\n  \\end{array}\n\\end{equation}\nwe get the Hilbert space $H^1(\\Omega) := \\W^{1,2}(\\Omega)$.\n\nWith $H^1_0(\\Omega) := \\{u \\in H^1(\\Omega) \\mid u(\\bfx) = 0 \\text{ for } \\bfx \\in \\p \\Omega\\}$ we denote the subspace of functions that are 0 on the boundary.\n\n%-------------------------------------------------------------------------------------------------\n\n\\section{Poisson Equation}\nThe Poisson equation is a generalization of the Laplace equation and is given by\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    Δu = f\\qquad \\text{on }\\Omega.\n  \\end{array}\n\\end{equation*}\n%\nIt can be subject to the same boundary conditions as Laplace equation, i.e. Neumann-type boundary conditions\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇u(\\bfx) \\cdot \\bfn = 0 \\qquad \\text{on }\\Gamma_N,\n  \\end{array}\n\\end{equation*}\n%\nas well as Dirichlet-type boundary conditions\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    u(\\bfx) = u_0(\\bfx) \\qquad \\text{on }\\Gamma_D.\n  \\end{array}\n\\end{equation*}\nThe finite element formulation proceeds similar to Chap.~\\ref{chap:laplace}, multiplication of a testfunction $\\phi \\in H^{1}_0(\\Omega)$ and integration yields\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\ds\\int_{\\Omega}Δu\\,\\phi\\,\\d \\bfx = \\int_{\\Omega} f\\,\\phi\\,\\d \\bfx, \\quad \\forall \\phi \\in H^1_0(\\Omega).\n  \\end{array}\n\\end{equation*}\nApplying divergence theorem we get\n\\begin{equation}\\label{eq:poisson_divergence}\n  \\begin{array}{lll}\n    -\\ds\\int_{\\Omega} ∇u\\cdot ∇\\phi \\,\\d \\bfx = \\int_{\\Omega} f\\,\\phi\\,\\d \\bfx \\quad \\forall \\phi \\in H^{1}_0(\\Omega).\n  \\end{array}\n\\end{equation}\nLike the solution $u(\\bfx)$ also the right hand side $f(\\bfx)$ has to be spatially discretized by a linear combination of coefficients and basis functions:\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    u_h(\\bfx) = \\s{i=1}{N}u_i\\,\\phi_i(\\bfx),\\\\[4mm]\n    f_h(\\bfx) = \\s{i=1}{N}f_i\\,\\phi_i(\\bfx).\n  \\end{array}\n\\end{equation*}\nBy again choosing the space of testfunctions to be the same as the span of basis functions, ${V=\\spn\\{\\phi_1, \\dots, \\phi_n\\}}$ we get the Galerkin formulation as\n\\begin{equation*}\n  \\begin{array}{lll}\n    -\\s{i=1}{N} u_i \\int_\\Omega ∇\\phi_i\\cdot ∇\\phi_j \\,\\d\\bfx = \\s{i=1}{N}f_i \\int_\\Omega \\phi_i\\cdot \\phi_j \\,\\d\\bfx \\quad \\text{for }j = 1, \\dots, N.\n  \\end{array}\n\\end{equation*}\nThe domain $\\Omega$ is again decomposed into disjoint elements $\\Omega_e, e=1,\\dots, M$ and integration has only be performed over the elements where none of the basis function vanish.\n\nThe first integral term, $\\int_{\\Omega} ∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx$, has to be computed as described in Section \\ref{chap:integral1}. How to compute the second integral term, $\\int_{\\Omega} \\phi_i\\cdot \\phi_j\\,\\d\\bfx$ is shown in the following.\n\nSimilar as before, the integration domain is transferred from element space to parameter space. For this a transformation factor $\\mathcal{J}_d$ has to be considered, which is constant for some special cases as discussed in \\cref{chap:integral1}.\n\nFor the remaining integral, $\\int_{\\Omega} \\phi_i\\cdot \\phi_j\\,\\d\\bfxi$ node stencils are provided in the following table.\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{l|l|l|l}\n    dim & element contribution & node stencil\\\\\n    \\hline\n    1D: &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n     \\dfrac16\\left[\\begin{array}{ccc}\n        \\underline{2} & 1\\\\\n    \\end{array}\\right] \\quad \n  \\end{equation*}\n\\end{minipage} \n    &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\dfrac16\\left[\\begin{array}{ccc}\n        1 & \\underline{4} & 1\\\\\n    \\end{array}\\right]\n  \\end{equation*}\n\\end{minipage} \n     \\\\[4mm]\n     \\hline\n    2D:&\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\dfrac1{36}\\left[\\begin{array}{ccc}\n        2 & 1 \\\\\n        \\underline{4} & 2\n      \\end{array}\n    \\right]\n  \\end{equation*}\n\\end{minipage}  &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n      \\dfrac1{36}\\left[\n        \\begin{array}{ccc}\n          1 & 4 & 1\\\\\n          4 & \\underline{16} & 4 \\\\\n          1 & 4 & 1\n        \\end{array}\n      \\right]\n  \\end{equation*}\n\\end{minipage}  \\\\[4mm]\n    \\hline\n    3D: &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\text{center:} &\n      \\dfrac1{216}\\left[\\begin{array}{ccc}\n          4 & 2\\\\\n          \\underline{8} & 4\\\\\n      \\end{array}\\right] \\\\[4mm]\n      \\text{top:}& \n      \\dfrac1{216}\\left[\\begin{array}{ccc}\n          2 & 1\\\\\n          4 & 2\\\\\n      \\end{array}\\right]\n    \\end{array}\n  \\end{equation*}\n\\end{minipage} &\n\\begin{minipage}{6cm}\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\text{bottom:} &\n      \\dfrac1{216}\\left[\\begin{array}{ccc}\n          1 & 4 & 1\\\\\n          4 & 16 & 4\\\\\n          1 & 4 & 1\n      \\end{array}\\right] \\\\[4mm]\n      \\text{center:} &\n      \\dfrac1{216}\n      \\left[\\begin{array}{ccc}\n          4 & 16 & 4\\\\\n          16 & \\underline{64} & 16\\\\\n          4 & 16 & 4\n      \\end{array}\\right] \\\\[4mm]\n      \\text{top:}& \n      \\dfrac1{216}\n      \\left[\\begin{array}{ccc}\n          1 & 4 & 1\\\\\n          4 & 16 & 4\\\\\n          1 & 4 & 1 \n      \\end{array}\\right]\n    \\end{array}  \n  \\end{equation*}\n\\end{minipage}\n\\end{tabular}\n\\caption{Stencils of the Finite Element right hand side for an equidistant mesh with uniform resolution. Note, that for 1D, 2D and 3D elements of mesh width $h$, the prefactors of the integral over the element domain are $h$, $h^2$ and $h^3$.}\n\\end{table}\n\n\n\\section{Generalized Laplace operator}\n%\nThe Laplace equation $Δu=0$ describes steady-state matter-/heat-/current flow where the computed quantity $u$ designates the potential that induces the flow $\\bfF$, which can be modelled as being directed against the potential gradient, $\\bfF = -∇u$. In terms of heat transfer this is \\emph{Fick's law}. By considering the conservation law of the flowing quantity we assume $∇\\cdot \\bfF = 0$ which leads directly to the Laplace equation. \n\nIf the medium in which the flow occurs is non-isotropic this can be modelled by adjusting the relationship between the negative potential gradient, $-∇u$, and the induced flow direction, $F$. By applying a linear map $A$ onto the negative gradient vector which can be thought of being the sum of contributions in coordinate directions, each contribution vector of a coordinate direction gets scaled and projected to a new direction. The flow is then $\\bfF = -A∇u$ and the resulting equation is called generalized Laplace equation, reading\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇\\cdot (A ∇u) = 0.\n  \\end{array}\n\\end{equation*}\nThe parantheses can also be neglected. $∇\\cdot A∇$ is referred to as generalized Laplace operator.\n\nThe derivation of the Finite Element formulation proceeds analoguos to \\cref{chap:laplace}.\nMultiplication with a testfunction $\\phi$ yields:\n\\begin{equation}\n  \\begin{array}{ll}\n    \\ds\\int_{\\Omega}∇\\cdot A ∇u\\,\\phi\\,\\d \\bfx = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega)\n  \\end{array}\n\\end{equation}\nApplying divergence theorem \\eqref{eq:gauss1} with $f=\\phi$ and $\\bfF=A ∇u$ yields\n\\begin{equation}\n  \\begin{array}{ll}\n    -\\ds\\int_{\\Omega}A ∇u \\cdot ∇\\phi \\,\\d \\bfx + \\ds\\int_{\\p \\Omega} (\\phi\\,A∇u)\\cdot\\bfn\\,\\d \\bfx  = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega).\n  \\end{array}\n\\end{equation}\nBecause $\\phi$ is zero on the boundary, the boundary integral vanishes:\n\\begin{equation}\\label{eq:laplace_weak}\n  \\begin{array}{ll}\n    -\\ds\\int_{\\Omega}A ∇u \\cdot ∇\\phi \\,\\d \\bfx = 0 \\quad \\forall \\phi\\in H^1_0(\\Omega).\n  \\end{array}\n\\end{equation}\nThe discretization remains the same and leads to an integral term of\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    m_{ji} = -\\ds\\int_{Ω}A∇\\phi_i\\cdot ∇\\phi_j\\,\\d\\bfx.\n  \\end{array}\n\\end{equation*}\nfor the stiffness matrix $M$. For these term the stencil notation cannot be applied in general. The stiffness matrix has to be computed using e.g. numerical quadrature.\n\n%-------------------------------------------------------------------------------------------------\n\n\\section{Diffusion Equation}\n\nThe diffusion equation is given by\n\\begin{equation}\\label{eq:diffusion}\n  \\begin{array}{lll}\n    u_t = c\\,Δu, \\qquad c \\in \\R\n  \\end{array}\n\\end{equation}\nFor the finite element formulation it can be seen as a Poisson equation with right hand side $u_t$, neglecting the constant $c$ for now. \nWe get from \\eqref{eq:poisson_divergence}:\n\\begin{equation}\\label{eq:diffusion_derivation1}\n  \\begin{array}{ll}\n    -\\ds\\int_{\\Omega} ∇u\\cdot ∇\\phi \\,\\d \\bfx = \\int_{\\Omega} u_t\\,\\phi\\,\\d \\bfx \\quad \\forall \\phi \\in H^{1}_0(\\Omega).\n  \\end{array}\n\\end{equation}\nThe derivative in time, $u_t$ can be discretized by a differential quotient as follows:\n\\begin{equation*}\n  \\begin{array}{lll}\n    u_t = \\dfrac{u^{(t+1)} - u^{(t)}}{dt},\n  \\end{array}\n\\end{equation*}\nwhere $dt$ is the time step width. In space we formulate the quantity again with a discrete basis:\n\\begin{equation*}\n  \\begin{array}{lll}\n    u_h^{(t)}(\\bfx) = \\s{i=1}{N} u_i^{(t)}\\,\\phi_i(\\bfx).\n  \\end{array}\n\\end{equation*}\nSubstituting into \\eqref{eq:diffusion_derivation1} yields:\n\\begin{equation*}\n  \\begin{array}{lll}\n    & -\\ds\\int_{\\Omega} ∇u^{(t)}\\cdot ∇\\phi \\,\\d \\bfx = \\dfrac{1}{dt}\\int_{\\Omega} \\Big(u^{(t+1)} - u^{(t)}\\Big))\\,\\phi\\,\\d \\bfx \\quad \\forall \\phi \\in H^{1}_0(\\Omega)\\\\[4mm]\n    \\Leftrightarrow\\quad & -\\s{i=1}{N} u^{(t)}_i \\ds\\int_Ω ∇\\phi_i \\cdot ∇\\phi_j\\,\\d\\bfx = \\dfrac{1}{dt}\\s{i=1}{N}(u_i^{(t+1)} - u_i^{(t)})\\ds\\int_Ω \\phi_i \\cdot \\phi_j\\,\\d\\bfx\\qquad \\text{for }j = 1,\\dots, N.\n  \\end{array}\n\\end{equation*}\nWe use the matrix notation with the stiffness matrix, $\\bfK$, and the mass matrix, $\\bfM$. For the explicit Euler scheme $u^{(t+1)} = u^{(t)} + dt\\,f(t,u^{(t)})$, we get \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfK\\bfu^{(t)} &= \\dfrac1{dt} \\bfM\\Big(\\bfu^{(t+1)} - \\bfu^{(t)}\\Big)\\\\[4mm]\n    \\bfu^{(t+1)} &= \\bfu^{(t)} + dt \\,\\bfM^{-1}\\bfK\\bfu^{(t)}\\\\[4mm]\n                 &= \\Big(\\bfI + dt \\,\\bfM^{-1}\\bfK\\Big)\\bfu^{(t)}\n                .\n  \\end{array}\n\\end{equation*}\nFor an implicit Euler scheme $u^{(t+1)} = u^{(t)} + dt\\,f(t+1,u^{(t+1)})$, we get \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfK\\bfu^{(t+1)} &= \\dfrac1{dt} \\bfM\\Big(\\bfu^{(t+1)} - \\bfu^{(t)}\\Big)\\\\[4mm]\n     (I - dt\\,\\bfM^{-1}\\bfK)\\,\\bfu^{(t+1)}&= \\,\\bfu^{(t)}\\\\[1em] \\textrm{or}\\\\[1em]\n     \\displaystyle(\\bfK-\\frac{\\bfM}{dt})\\bfu^{(t+1)}&=\\,\\displaystyle -\\frac{\\bfM}{dt}\\bfu^{(t)}\n  \\end{array}\n\\end{equation*}\nThe second form may be beneficial in case of variable time step.\\\\[1em]\nFor the Crank-Nicolson scheme $u^{(t+1)} = u^{(t)} + dt\\,(f(t+1,u^{(t+1)})+f(t,u^{(t)}))/2$, we get\n\\begin{equation*}\n\t\\begin{array}{lll}\n\t\t\\dfrac{\\bfK(\\bfu^{(t+1)}+\\bfu^{(t)})}{2} &= \\dfrac1{dt} \\bfM\\Big(\\bfu^{(t+1)} - \\bfu^{(t)}\\Big)\\\\[4mm]\n\t\t(I - \\dfrac{dt}{2}\\,\\bfM^{-1}\\bfK)\\,\\bfu^{(t+1)}&= \\,\\bfu^{(t)}(I + \\dfrac{dt}{2}\\,\\bfM^{-1}\\bfK)\n\t\\end{array}\n\\end{equation*} \nor\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\big(\\dfrac1{2}\\bfK-\\dfrac{1}{dt}\\bfM\\big) \\bfu^{(t+1)} = \\big(-\\dfrac12{\\bfK} - \\dfrac{1}{dt}\\bfM\\big) \\bfu^{(t)}\n  \\end{array}\n\\end{equation*}\n\\subsection{Lumped Mass Matrix}\nFor linear or bilinear basis functions\n\\begin{equation*}\n\\left\\{\n  \\begin{array}{ll}\n    m'_{i,j}=0 &i\\ne j\\\\\n    m'_{i,i}=S(i) &i=1,...,n\n  \\end{array},\n\\right.\n\\end{equation*}\nwhere $S(i)=\\sum_{j=1}^{n}m_{i,j}$ for $i=1,...,n$.\\\\[0.5em]\nFor orders of basis greater than two suggested from Hinton et al. \\cite{hinton_rock_zienkiewicz_1976}:\n\\begin{equation}\n\\left\\{\n  \\begin{array}{ll}\n\tm'_{i,j}=0 &i\\ne j\\\\\n\tm'_{i,i}=\\frac{S}{D} m_{i,i} & i=1,...,n\n  \\end{array}\n\\right.\n\\end{equation}\nwhere $S=\\sum_{i=1}^{n}\\sum_{j=1}^{n} m_{i,j}$ and $D=\\sum_{i=1}^{n}m_{i,i}$.\n\n\n\n%------------------------------------------------------------------------------------------------\n\\subsection{Derivation with boundary conditions}\n\\subsubsection{Diffusion problem}\nIn general, the weak form of a diffusion problem discretized with Crank-Nicolson,\n\\begin{equation}\\label{eq:weak_form0}\n  \\begin{array}{lll}\n    ∇\\cdot (\\bfsigma ∇u) = u_t, \\qquad \\p{u}{\\bfn} = f \\quad \\text{on }\\Gamma_f, \\qquad \\p{u}{\\bfn} = 0 \\quad \\text{on } ∂Ω\\backslash \\Gamma_f \\\\[4mm]\n    \\Rightarrow\\quad \\ds\\int_Ω \\big(\\theta\\,∇\\cdot (\\bfsigma ∇u^{(i+1)}) + (1-\\theta)\\,∇\\cdot (\\bfsigma ∇u^{(i)})\\big)\\,\\phi \\,\\d\\bfx = \\dfrac{1}{dt} \\ds\\int_Ω(u^{(i+1)} - u^{(i)})\\,\\phi\\,\\d\\bfx, \\quad \\forall \\phi \\in V_h\\\\[4mm]\n  \\end{array}\n\\end{equation}\nDiscretize in space with $u = \\sum_j u_j\\,\\varphi_j, V_h = \\spn\\{\\varphi_j | j = 1\\dots N\\}$ and using Divergence theorem\n\\begin{equation}\\label{eq:weak_form1}\n  \\begin{array}{lll}\n    \\ds\\sum\\limits_{j=1}^{N} \\big(\\theta\\,u_j^{(i+1)} + (1-\\theta)\\,u_j^{(i)}\\big)  \\left(-\\ds\\int_Ω (\\bfsigma∇\\varphi_j)\\cdot ∇\\phi_k \\,\\d\\bfx + \\ds\\int_{∂Ω} (\\bfsigma\\,∇\\varphi_j\\cdot \\bfn)\\phi_k \\,\\d\\bfx  \\right) \\\\[4mm]\n    \\quad = \\dfrac{1}{dt} \\sum\\limits_{j=1}^{N} \\big(u_j^{(i+1)} - u_j^{(i)}\\big) \\ds\\int_Ω \\varphi_j\\,\\phi_k\\,\\d\\bfx, \\quad \\forall k = 1\\dots N.\\\\[4mm]\n  \\end{array}\n\\end{equation}\nThe ansatz functions for discretization and the test functions are chosen to be equal, $\\phi_j=\\varphi_j$.\n\nThe formulation can be written in matrix notation as\n\\begin{equation}\\label{eq:diffusion_weak_form_matrix}\n  \\begin{array}{lll}\n    \\bfA\\,\\bfu^{(i+1)} = \\bfb(\\bfu^{(i)}),\n  \\end{array}\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:diffusion_weak_form_matrix2}\n  \\begin{array}{lll}\n    \\bfA = \\theta\\,(\\bfK + \\bfB) -\\dfrac{1}{dt}\\bfM, \\\\[4mm]\n    \\bfb = \\big((\\theta-1)\\,(\\bfK + \\bfB) - \\dfrac{1}{dt} \\bfM \\big)\\,\\bfu^{(i)},\n  \\end{array}\n\\end{equation} \nwith \n\\begin{equation*}\n  \\begin{array}{lll}\n     \\bfK_{kj} = -\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx \\qquad \\text{(note, the minus sign is correct for $+Δ$)},\\\\[4mm]\n     \\bfB_{kj} = \\ds\\int_{\\Gamma_f} (\\bfsigma\\,∇\\varphi_j\\cdot \\bfn)\\varphi_k \\,\\d\\bfx,\\\\[4mm]\n     \\bfM_{kj} = \\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx,\n  \\end{array}\n\\end{equation*}\nor written in component form:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfA_{kj} = \\theta\\,\\left(-\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx + \\ds\\int_{∂Ω} (\\bfsigma\\,∇\\varphi_j\\cdot \\bfn)\\varphi_k \\,\\d\\bfx \\right) - \\dfrac{1}{dt}\\,\\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx,\\\\[4mm]\n    \\bfb_k = \\ds\\sum\\limits_{j=1}^{N} -(1-\\theta)\\,u_j^{(i)}\\,\\left(-\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx + \\ds\\int_{∂Ω} (\\bfsigma\\,∇\\varphi_j\\cdot \\bfn)\\varphi_k \\,\\d\\bfx \\right)\n     + \\dfrac{1}{dt} \\ds\\sum\\limits_{j=1}^{N} (-u_j^{(i)}) \\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx.\n  \\end{array}\n\\end{equation*}\nSo far we did not plug in the boundary conditions. For $f=0$ we get $\\bfB = \\bfzero$. The case $f \\neq 0$ is handled in the next subsection.\n\n\\subsubsection{Boundary conditions}\nThe boundary condition $\\bfsigma\\,∇u\\cdot\\bfn = f$ can be written as\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfsigma\\,∇u\\cdot\\bfn = \\s{j=1}{N}u_j\\,(\\bfsigma\\,∇\\varphi_j\\cdot \\bfn) = f,\n  \\end{array}\n\\end{equation*}\nWe discretize the flow over the boundary, $f$, by different ansatz functions, $\\psi_j$, with coefficients $f_j$:\n\\begin{equation*}\n  \\begin{array}{lll}\n    f = \\s{j=1}{N}f_j\\,\\psi_j\n  \\end{array}\n\\end{equation*}\nWe get from \\eqref{eq:weak_form1} \n\\begin{equation*}\n  \\begin{array}{lll}\n    \\ds\\sum\\limits_{j=1}^{N} \\big(\\theta\\,u_j^{(i+1)} + (1-\\theta)\\,u_j^{(i)}\\big) \n     \\left(-\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx \\right)\n      + \\ds\\int_{\\Gamma_f} \\big(\\theta\\,f^{(i+1)} + (1-\\theta)\\,f^{(i)}\\big)\\,\\varphi_k \\,\\d\\bfx \\\\[4mm]\n    \\quad = \\dfrac{1}{dt} \\sum\\limits_{j=1}^{N} \\big(u_j^{(i+1)} - u_j^{(i)}\\big) \\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx, \\quad \\forall k = 1\\dots N,\\\\[4mm]\n    \\Leftrightarrow \\quad \n    \\ds\\sum\\limits_{j=1}^{N} \\big(\\theta\\,u_j^{(i+1)} + (1-\\theta)\\,u_j^{(i)}\\big) \n     \\left(-\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx \\right)\n      + \\ds\\sum\\limits_{j=1}^{N} \\big(\\theta\\,f_j^{(i+1)} + (1-\\theta)\\,f_j^{(i)}\\big) \n      \\ds\\int_{\\Gamma_f} \\psi_j\\,\\varphi_k \\,\\d\\bfx \\\\[4mm]\n    \\quad = \\dfrac{1}{dt} \\sum\\limits_{j=1}^{N} \\big(u_j^{(i+1)} - u_j^{(i)}\\big) \\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx, \\quad \\forall k = 1\\dots N,\\\\[4mm]\n  \\end{array}\n\\end{equation*}\nIn matrix notation,\n\\begin{equation}\\label{eq:diffusion_weak_form_matrix}\n  \\begin{array}{lll}\n    \\bfA\\,\\bfu^{(i+1)} = \\bfb(\\bfu^{(i)}),\n  \\end{array}\n\\end{equation}\nwe have\n\\begin{equation}\\label{eq:diffusion_weak_form_matrix2}\n  \\begin{array}{lll}\n    \\bfA = \\theta\\,\\bfK -\\dfrac{1}{dt}\\bfM, \\\\[4mm]\n    \\bfb = \\big((\\theta-1)\\,\\bfK - \\dfrac{1}{dt} \\bfM \\big)\\,\\bfu^{(i)} - \\bfB_{\\Gamma_f}\\,\\big(\\theta\\,\\bff^{(i+1)} + (1-\\theta)\\,\\bff^{(i)}\\big),\n  \\end{array}\n\\end{equation} \nwith \n\\begin{equation*}\n  \\begin{array}{lll}\n     \\bfK_{kj} = -\\ds\\int_Ω \\bfsigma\\,∇\\varphi_j\\cdot ∇\\varphi_k \\,\\d\\bfx \\qquad \\text{(note, the minus sign is correct for $+Δ$)},\\\\[4mm]\n     \\bfM_{kj} = \\ds\\int_Ω \\varphi_j\\,\\varphi_k\\,\\d\\bfx,\\\\[4mm]\n     \\bfB_{\\Gamma_f,kj} = \\ds\\int_{\\Gamma_f} \\psi_j\\,\\varphi_k \\,\\d\\bfx,\n  \\end{array}\n\\end{equation*}\n\n\\subsubsection{Laplace problem}\nWe consider $∇\\cdot (\\bfsigma ∇\\bfu) = 0$ with Neumann boundary condition, $ \\partial (\\bfsigma\\,\\bfu)/\\partial \\bfn = \\bff$.\nThis leads to \n\\begin{equation*}\n  \\begin{array}{lll}\n    (\\bfK + \\bfB)\\,\\bfu = \\bfzero \\qquad \\text{or} \\qquad \\bfK\\,\\bfu + \\bfB_{\\Gamma_f}\\,\\bff = 0.\n  \\end{array}\n\\end{equation*}\n\n\\subsubsection{Two coupled Laplace problems}\nWe have the domain as in \\cref{fig:two-domains} and the following equations:\n\\bild{two-domains}{5cm}{Two domains}\n\\begin{equation*}\n  \\begin{array}{lll}\n    ∇\\cdot (\\bfsigma_1 ∇u_1) = \\bff_1, \\quad \\text{on } \\Omega_1 \\qquad \\partial u_1/\\partial \\bfn = g_1 \\quad \\text{on } Γ_{f1}\\\\[4mm]\n    ∇\\cdot (\\bfsigma_2 ∇u_2) = \\bff_2, \\quad \\text{on } \\Omega_2 \\qquad \\partial u_2/\\partial \\bfn = g_2 \\quad \\text{on } Γ_{f2}\\\\[4mm]\n    u_1 = u_2, \\quad q := (\\bfsigma_1 ∇u_1)\\cdot\\bfn = (\\bfsigma_1 ∇u_2)\\cdot\\bfn \\quad \\text{on }Γ_{12}\n  \\end{array}\n\\end{equation*}\nThe flux over $Γ_{12}$ is\n\\begin{equation*}\n  \\begin{array}{lll}\n    q(\\bfx) := (\\bfsigma_1∇u_1(\\bfx))\\cdot \\bfn = \\ds\\s{i=1}{N}u_i\\, (\\bfsigma_1 ∇\\varphi_i(\\bfx))\\cdot \\bfn \\quad \\text{for } \\bfx \\in Γ_{12}.\n  \\end{array}\n\\end{equation*}\nThis is only defined for quadratic ansatz functions. The flux condition is therefore forced in a weak form.\n\n\n\n\nThe Finite Element formulation leads to\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\bfK_{\\bfsigma_1}\\,\\bfu_1 = \\bff_1 - \\bfB_{\\Gamma_{f1}}\\,\\bfg_1 - \\bfB_{\\Gamma_{12}}\\,\\bfq_1,\\\\[4mm]\n    \\bfK_{\\bfsigma_2}\\,\\bfu_2 = \\bff_2 - \\bfB_{\\Gamma_{f2}}\\,\\bfg_2 - \\bfB_{\\Gamma_{12}}\\,\\bfq_2,\\\\[4mm]\n    \\bfB_{\\Gamma_{12}}\\,\\bfq_1 = -\\bfB_{\\Gamma_{12}}\\,\\bfq_2\n  \\end{array}\n\\end{equation*}\nwhere \n\\begin{equation*}\n  \\begin{array}{lll}\n     \\bfK_{\\bfsigma,kj} = -\\ds\\int_Ω (\\bfsigma ∇\\varphi_j)\\cdot ∇\\varphi_k \\,\\d\\bfx \\qquad \\text{(note, the minus sign is correct for $+Δ$)},\\\\[4mm]\n     \\bfB_{\\Gamma_f,kj} = \\ds\\int_{\\Gamma_f} \\psi_j\\,\\varphi_k \\,\\d\\bfx.\n  \\end{array}\n\\end{equation*}\n\nCombining the two equations we get the system\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\left[\\begin{array}{@{}cc@{}}\n     \\bfK_{\\bfsigma_{1}}&\\\\[2mm]\n     &\\bfK_{\\bfsigma_{2}}\n    \\end{array}\\right]\n    \\left[\\begin{array}{@{}c@{}}\n      \\bfu_{1}\\\\[2mm]\n      \\bfu_{2}\n    \\end{array}\\right]\n    = \n    \\left[\\begin{array}{@{}c@{}}\n     \\bff_{1} - \\bfB_{Γ_{f1}}\\,\\bfg_{1} - \\bfB_{\\Gamma_{12}}\\,\\bfq_1\\\\[2mm]\n     \\bff_{2} - \\bfB_{Γ_{f2}}\\,\\bfg_{2} - \\bfB_{\\Gamma_{12}}\\,\\bfq_2\n    \\end{array}\\right]\n  \\end{array}\n\\end{equation*}\n%\nHere, $\\bfu_1$  and $\\bfu_2$ are the degrees of freedom in $Ω_{1} ∪ Γ_{12}$ and $Ω_2 ∪ Γ_{12}$. The degrees of freedom on $Γ_{12}$ appear in $\\bfu_1$ as well as in $\\bfu_2$.\n$\\bfK_{\\bfsigma_{1}}$ and $\\bfK_{\\bfsigma_{2}}$ are computed by integrating only over the domains $Ω_{1}$ and $Ω_{2}$, respectively.\nof freedom in $Ω_1\\backslash Γ_{12}$ and $Ω_2\\backslash Γ_{12}$, $\\bfK_{\\sigma_{12}} = \\bfK_{\\sigma_1} + \\bfK_{\\sigma_2}$ \\text{ on } $Γ_{12}$.\n%\nStatic condensation of $q_1 = -q_2$:\n\n\\begin{equation*}\n  \\begin{array}{lll}\n   \\bfB_{\\Gamma_{12}}\\,\\bfq_2 = \\bff_{2} - \\bfB_{Γ_{f2}}\\,\\bfg_{2} - \\bfK_{\\bfsigma_{2}}\\,\\bfu_{2}\\\\[4mm]\n    \\Rightarrow\\quad \\bfK_{\\bfsigma_{1}}\\,\\bfu_{1} = \\bff_{1} - \\bfB_{Γ_{f1}}\\,\\bfg_{1} + \\bff_{2} - \\bfB_{Γ_{f2}}\\,\\bfg_{2} - \\bfK_{\\bfsigma_{2}}\\,\\bfu_{2}\\\\[4mm]\n    \\Rightarrow\\quad \\bfK_{\\bfsigma_{1}}\\,\\bfu_{1} + \\bfK_{\\bfsigma_{2}}\\,\\bfu_{2} = \\bff_{1} - \\bfB_{Γ_{f1}}\\,\\bfg_{1} + \\bff_{2} - \\bfB_{Γ_{f2}}\\,\\bfg_{2}\\\\[4mm]\n    \n  \\end{array}\n\\end{equation*}\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\left[\\begin{array}{@{}cc@{}}\n     \\bfK_{\\bfsigma_{1}}& \\bfK_{\\bfsigma_{2}}\n    \\end{array}\\right]\n    \\left[\\begin{array}{@{}c@{}}\n      \\bfu_{1}\\\\[2mm]\n      \\bfu_{2}\n    \\end{array}\\right]\n    = \n    \\left[\\begin{array}{@{}c@{}}\n     \\bff_{1} + \\bff_{2} - \\bfB_{Γ_{f1}}\\,\\bfg_{1} - \\bfB_{Γ_{f2}}\\,\\bfg_{2}\n    \\end{array}\\right]\n  \\end{array}\n\\end{equation*}\nThis means the systems is solved normally as if there was no separation in $\\Omega_1, \\Omega_2$.\n%------------------------------------------------------------------------------------------------\n\n\\section{Models of Electrophysiology}\nIn the following the Bidomain and Monodomain models are derived.\n\\subsection{The Bidomain Model}\n\nThe Bidomain model considers two computational domains of intra-cellular and extra-cellular space. In a homogenised view it is assumed that these domains share space such that at each spatial point there coexist both domains at the same time. Both domains have their own conductivity tensors $\\bfsigma_i, \\bfsigma_e$ and electric potential $\\phi_i, \\phi_e$, as depicted in \\cref{fig:bidomain}. An electric current $I_m$ between the computational domains is possible and has to pass the cell membrane. For specifying boundary conditions of the Bidomain equations, a third domain, the surrounding body, is assumed, that receives a current from the extracellular domain, but not from the intracellular space. For Monodomain equation this current is later set to 0.\n\n\\bild{bidomain}{10cm}{Setting of the Bidomain model}\n\nStarting point of the derivation is a form of Ohm's Law by which the current density $J$ is a result of an electric field $E$ that exists in a medium with electric conductivity $\\bfsigma$:\n\\beq\n  \\ba{ll}\n    J = \\bfsigma\\,E.\n  \\ea\n\\eeq\nAssuming quasi static conditions, the field strength $E$ is given by the negative gradient of a potential field:\n\\beq\n  \\ba{ll}\n    E = -∇\\phi.\n  \\ea\n\\eeq\nFor the current densities $J_i$ and $J_e$ in the two domains we then have:\n\\beq\n  \\ba{ll}\n    J_i = -\\bfsigma_i\\,∇\\phi_i,\\qquad J_e = -\\bfsigma_e\\,∇\\phi_e.\n  \\ea\n\\eeq\nBecause of the spatial coexistence of the two domains the divergence of the current density in one domain has to be the negative of the divergence at the same point in the other domain,\n\\beqno\\label{eq:pre2}\n  \\ba{ll}\n    ∇\\cdot J_i = -∇\\cdot J_e \\quad \\Leftrightarrow \\quad -∇\\cdot(\\bfsigma_i\\,∇\\phi_i) = ∇\\cdot (\\bfsigma_e\\,∇\\phi_e).\n  \\ea\n\\eeqno\nThe current enabling this relationship is the membrane current $I_m$ such that:\n\\beqno\\label{eq:AmIm}\n  \\ba{ll}\n    ∇\\cdot(\\bfsigma_i\\,∇\\phi_i) = A_m\\,I_m.\n  \\ea\n\\eeqno\nThe factor $A_m$ characterizes the membrane area to domain volume relationship of the cell membrane. Then $I_m$ is a quantity per area. It is the external current in the Hodgkin-Huxley model, \\cref{eq:V_m}, such that \\cref{eq:AmIm} becomes:\n\\beq\n  \\ba{ll}\n    ∇\\cdot(\\bfsigma_i\\,∇\\phi_i) = A_m\\,\\big(C_m\\,\\p{V_m}{t} + I_{ion}(V_m)\\big).\n  \\ea\n\\eeq\n\nUsing $V_m = \\phi_i - \\phi_e$, the intracellular potential $\\phi_i$ can be eliminated yielding\n\\beqno\\label{eq:bidomain1}\n  \\ba{ll}\n    ∇\\cdot(\\bfsigma_i\\,∇V_m) + ∇\\cdot (\\bfsigma_i\\,∇\\phi_e) = A_m\\,\\big(C_m\\p{V_m}{t} + I_{ion}(V_m)\\big).\n  \\ea\n\\eeqno\nThe second equation comes from \\cref{eq:pre2} which is also formulated with $V_m$ instead of $\\phi_i$:\n\\beqno\\label{eq:bidomain2}\n  \\ba{ll}\n    &∇\\cdot\\big(\\bfsigma_i\\,∇(V_m + \\phi_e)\\big) = -∇\\cdot(\\bfsigma_e\\,∇\\phi_e)\\\\[4mm]\n    \\Leftrightarrow \\quad & ∇\\cdot\\big((\\bfsigma_i + \\bfsigma_e)\\,∇\\phi_e) + ∇\\cdot (\\bfsigma_i\\,∇V_m) = 0,\n  \\ea\n\\eeqno\n\\Cref{eq:bidomain1,eq:bidomain2} form the Bidomain Equations.\n\n\\subsection{The Monodomain Model}\n\nUnder assumption that the anisotropy of the tissue at a point inside and outside the muscle cell is equal, the two Bidomain Equations can be reduced to the single Monodomain Equation. The assumption can be expressed as\n\\beq\n  \\ba{ll}\n    \\bfsigma_i = k\\cdot \\bfsigma_e\n  \\ea\n\\eeq\nfor a real factor $k$. Plugging $\\bfsigma_e = \\bfsigma_i/k$ into the second Bidomain Eq. \\eqref{eq:bidomain2} yields\n\\beqno\\label{eq:int1}\n  \\ba{ll}\n    &∇\\cdot\\big((1+\\dfrac{1}{k})\\,\\bfsigma_i\\,∇\\phi_e\\big) + ∇\\cdot (\\bfsigma_i\\,∇V_m) = 0\\\\[4mm]\n    \\Leftrightarrow \\quad & ∇\\cdot(\\bfsigma_i\\,∇\\phi_e) = -\\dfrac{k}{k+1}\\,∇\\cdot(\\bfsigma_i\\,∇V_m).\n  \\ea\n\\eeqno\nNow \\cref{eq:int1} can be combined with the first Bidomain Eq. \\eqref{eq:bidomain1} to get:\n\\beq\n  \\ba{ll}\n    ∇\\cdot(\\bfsigma_i\\,∇V_m) - \\dfrac{k}{k+1}\\,∇\\cdot(\\bfsigma_i\\,∇V_m) = A_m\\,\\big(C_m\\p{V_m}{t} + I_{ion}(V_m)\\big)\\\\[4mm]\n    \\dfrac{1}{k+1}\\,∇\\cdot(\\bfsigma_i\\,∇V_m) = A_m\\,\\big(C_m\\p{V_m}{t} + I_{ion}(V_m)\\big)\n  \\ea\n\\eeq\nFor the 1D case where the muscle fibre is modeled as a single line this can be simplified to:\n\\beq\n  \\ba{ll}\n    ∇\\cdot\\Big(\\ub{\\dfrac{\\bfsigma_i}{\\bfsigma_i/\\bfsigma_e+1}}{=\\dfrac{\\bfsigma_e\\,\\bfsigma_i}{\\bfsigma_e+\\bfsigma_i}}∇V_m\\Big) = A_m\\,\\big(C_m\\p{V_m}{t} + I_{ion}(V_m)\\big)\n  \\ea\n\\eeq\nBy defining the effective conductivity ${\\bfsigma_{\\text{eff}} := (\\bfsigma_e\\,\\bfsigma_i)/(\\bfsigma_e+\\bfsigma_i)}$ the 1D Monodomain Equation can be written as:\n\\beqno\\label{eq:monodomain_1D}\n  \\ba{ll}\n    ∇\\cdot(\\bfsigma_{\\text{eff}}\\,∇V_m) = A_m\\,\\big(C_m\\p{V_m}{t} + I_{ion}(V_m)\\big).\n  \\ea\n\\eeqno\nThis is a 1D PDE in the variable $V_m$ and is usually solved with the boundary condition\n\\beq\n  \\ba{ll}\n    (\\bfsigma_{\\text{eff}}∇V_m)\\cdot \\bfn^M = 0 \\quad \\text{on }\\Gamma^M.\n  \\ea\n\\eeq\nwhich inhibits current to the outer domain. $\\bfn^M$ is the outward normal vector on the border $\\Gamma^M$ of the muscle fibre surface.\nThe spatial discretization of the diffusion term on the left-hand side of \\cref{eq:monodomain_1D} can be achieved by using 1D finite elements.\n  \n%------------------------------------------------------------------------------------------------\n\\subsection{The 1D Monodomain Equation}\n\nWe consider 2 domains: intra- and extracellular space. The setting is homogenised such that the domains occupy the same space.\nThe domains have electric potentials $\\phi_i, \\phi_e$ and conductivities $\\sigma_i, \\sigma_e$, the membrane voltage is defined as $V_m = \\phi_i-\\phi_e$.\n%  \n\\begin{figure}\n  \\def\\svgwidth{6cm}\n  \\input{images/bidomain_setting1.pdf_tex}\\quad\n\\end{figure}\nThe current density can be described by a potential:\n% \n\\begin{equation*}\n\\begin{array}{lll}\nj_e = -\\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x},\\quad j_i = -\\sigma_i\\,\\dfrac{\\partial\\phi_i}{\\partial x}\n\\end{array}\n\\end{equation*}\n\n\\begin{figure}\n  \\def\\svgwidth{6cm}\n  \\input{images/bidomain_setting2.pdf_tex}\\quad\n\\end{figure}\nConservation of charges holds, changes in current density affect the other domain.\n%\n\\begin{equation}\\label{eq:bidom1}\n  \\begin{array}{lll}\n    &\\dfrac{\\partial}{\\partial x} j_i = -\\dfrac{\\partial}{\\partial x} j_e\\\\[4mm]\n    \\quad\\Leftrightarrow\\quad & \\dfrac{\\partial}{\\partial x} \\Big(\\sigma_i\\,\\dfrac{\\partial\\phi_i}{\\partial x}\\Big) \n      = -\\dfrac{\\partial}{\\partial x} \\Big(\\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x}\\Big)\n  \\end{array}\n\\end{equation}\nThe current through the domain is given by\n\\begin{equation}\\label{eq:bidom2}\n  \\begin{array}{lll}\n      \\dfrac{\\partial}{\\partial x} \\Big(\\sigma_i\\,\\dfrac{\\partial\\phi_i}{\\partial x}\\Big)  &= I_m\\\\[4mm]\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\n  \\end{array}\n\\end{equation}\n\nWe assume $\\sigma_i = k\\cdot \\sigma_e$ and substitute $V_m = \\phi_i - \\phi_e$ to eliminate $\\phi_i$:\n\\begin{equation}\\label{eq:subsbidom}\n  \\begin{array}{lll}\n    \\dfrac{\\partial}{\\partial x} \\Big(\\sigma_i\\,\\dfrac{\\partial\\phi_i}{\\partial x}\\Big) = \n    \\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial(V_m + \\phi_e)}{\\partial x}\\Big)\n  \\end{array}\n\\end{equation}\n\nPlugging this into \\eqref{eq:bidom1} yields\n\\begin{equation}\\label{eq:subs2bidom}\n  \\begin{array}{lll}\n    &\\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial(V_m + \\phi_e)}{\\partial x}\\Big)\n      = -\\dfrac{\\partial}{\\partial x} \\Big(\\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x}\\Big)    \\\\[4mm]\n    \\quad\\Leftrightarrow\\quad & \n    \\dfrac{\\partial}{\\partial x} \\Big((k+1)\\cdot \\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x}\\Big) = -\\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial V_m}{\\partial x}\\Big) \\\\[4mm]\n    \\quad\\Leftrightarrow\\quad & \n    \\dfrac{\\partial}{\\partial x} \\Big(\\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x}\\Big) = -\\dfrac{\\partial}{\\partial x} \\Big(\\dfrac{k}{k+1}\\cdot \\sigma_e\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\\\\[4mm]\n  \\quad\\Leftrightarrow\\quad & \n    \\dfrac{\\partial}{\\partial x} \\Big(k\\,\\sigma_e\\,\\dfrac{\\partial\\phi_e}{\\partial x}\\Big) = -\\dfrac{\\partial}{\\partial x} \\Big(\\dfrac{k}{k+1}\\cdot k\\, \\sigma_e\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n  \\end{array}\n\\end{equation}\n\nUsing the substitution \\eqref{eq:subsbidom} in \\eqref{eq:bidom2} yields\n\\begin{equation*}\n  \\begin{array}{lll}\n      \\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial(V_m + \\phi_e)}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\n  \\end{array}\n\\end{equation*}\nStarting from \\eqref{eq:bidom1} with \\eqref{eq:subs2bidom} we get\n\\begin{equation*}\n  \\begin{array}{lll}\n      &\\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial(V_m + \\phi_e)}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n      \\quad\\Leftrightarrow\\quad &\n       \\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n      + \\dfrac{\\partial}{\\partial x} \\Big(k\\cdot \\sigma_e\\,\\dfrac{\\partial \\phi_e}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n      \\quad\\Leftrightarrow\\quad &\n       \\dfrac{\\partial}{\\partial x} \\Big(\\big(1 - \\dfrac{k}{k+1}\\big)\\cdot k\\, \\sigma_e\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n      \\quad\\Leftrightarrow\\quad &\n       \\dfrac{\\partial}{\\partial x} \\Big(\\dfrac{1}{k+1}\\cdot \\sigma_i\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n    \\quad\\Leftrightarrow\\quad &\n       \\dfrac{\\partial}{\\partial x} \\Big(\\dfrac{1}{\\sigma_i/\\sigma_e+1}\\cdot \\sigma_i\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n    \\quad\\Leftrightarrow\\quad &\n       \\dfrac{\\partial}{\\partial x} \\Big(\\dfrac{\\sigma_i\\,\\sigma_e}{\\sigma_i+\\sigma_e}\\,\\dfrac{\\partial V_m}{\\partial x}\\Big)\n      &= A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big)\\\\[4mm]\n  \\end{array}\n\\end{equation*}\n\nThis leads to the Monodomain equation:\n\\begin{equation*}\n  \\begin{array}{lll}\n  \\dfrac{\\partial}{\\partial x} \\Big(\\sigma_\\text{eff}\\,\\dfrac{\\partial V_m}{\\partial x}\\Big) = A_m\\Big(C_m \\dfrac{\\partial V_m}{\\partial t} + I_\\text{ion}(V_m)\\Big),\\qquad\n  \\text{with }\\sigma_\\text{eff}:= \\sigma_i || \\sigma_e = \\dfrac{\\sigma_i\\,\\sigma_e}{\\sigma_i+\\sigma_e}\n  \\end{array}\n\\end{equation*}\n\\subsection{Numerical treatment}\nEquation solved for $\\dfrac{\\partial V_m}{\\partial t}$:\n\\begin{equation*}\n  \\begin{array}{lll}\n  \\dfrac{\\partial V_m}{\\partial t} = -\\dfrac{1}{C_m}I_\\text{ion}(V_m) + \\dfrac{1}{A_m\\,C_m} \\dfrac{\\partial}{\\partial x}\\Big(\\sigma_\\text{eff}\\,\\dfrac{\\partial}{\\partial x}V_m\\Big)\n  \\end{array}\n\\end{equation*}\nEmploy finite differences in $t$ and Godunov operator splitting:\n\\begin{equation*}\n  \\begin{array}{lll}\n  \\dfrac{V_m^\\ast - V_m^{(k)}}{\\Delta t} &= -\\dfrac{1}{C_m}\\,I_\\text{ion}(V_m^{(k)}),\\\\[4mm]\n  \\dfrac{V_m^{(k+1)} - V_m^{*}}{\\Delta t} &= \\dfrac{1}{A_m\\,C_m}\\dfrac{\\partial}{\\partial x}\\Big(\\sigma_\\text{eff}\\,\\dfrac{\\partial}{\\partial x}V_m^{(k+1)}\\Big),\\\\[4mm]\n  \\end{array}\n\\end{equation*}\n\n\\begin{equation*}\n  \\begin{array}{lll}\n  V_m^{(k+1)} = V_m^{*} + \\Delta t \\cdot \\dfrac{1}{A_m\\,C_m}\\dfrac{\\partial}{\\partial x}\\Big(\\sigma_\\text{eff}\\,\\dfrac{\\partial}{\\partial x}V_m^{(k+1)}\\Big),\n  \\end{array}\n\\end{equation*}\nThe CellML model gives the right hand side $f(V_m^{(k)}) = -\\dfrac{1}{C_m}\\,I_\\text{ion}(V_m^{(k)})$. When solving the diffusion equation the value of $C_m$ should match.\n%------------------------------------------------------------------------------------------------\n\n    \nThe bidomain equation can be used for computation of EMG ($\\phi_e$), after the Heidlauf model, when only $V_m$ is known.\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\div\\big((\\bfsigma_i + \\bfsigma_e)\\,\\grad \\phi_e\\big) = - \\div(\\bfsigma_i\\,\\grad V_m)\n  \\end{array}\n\\end{equation*}\n\n%------------------------------------------------------------------------------------------------\n\\section{Solid Mechanics Model of Muscle Contraction}\\label{sec:model_muscle_contraction}\n\nMuscle contraction is described on the organ level by a description of solid mechanics. Because of possibly large strains, a nonlinear hyperelastic formulation is used. 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% assumptions\nWe 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 placement function $\\bfx = \\bfvarphi_t(\\bfX)$. In 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%\n\\begin{align*}\n  \\bfx(\\bfX) = \\bfX + \\bfu(\\bfX).\n\\end{align*}\nThe current velocity $\\bfv$ is the time derivative of the displacements, $\\bfv := \\dot{\\bfu}$.\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*}\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 current configuration. 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}\n%\nThe second order Cauchy stress tensor $\\bfsigma$ has units of force per area and is defined by the relation $\\bft = \\bfsigma \\bfn$ between a traction force $\\bft$ in a virtual cut out of the body at $\\bfx$ and the normal vector $\\bfn$ of the cut area.\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\nThe mathematical description has to be closed by defining a constitutive relation between stresses and strains. The usual approach for hyperelastic materials is to define a strain energy function $\\Psi$. This scalar function is formulated in terms of the right Cauchy-Green tensor $\\bfC$, which is related to the strain of the deformed body. Then, the stresses are given by%\n\\begin{align*}\n  \\bfS = 2\\p{\\Psi(\\bfC)}{\\bfC},\n\\end{align*}\nwhere $\\bfS$ is the second Piola-Kirchhoff stress tensor, which in the incompressible case is the pull-back of the Cauchy stress $\\bfsigma$ used in the balance of momentum in \\cref{eq:assumption_2_local}.\n%which is related to the Cauchy stress $\\bfsigma$ used in the balance of momentum in \\cref{eq:assumption_2_local}.\n\n%It is usually formulated in terms of the five principle strain invariants $I_1$ to $I_5$. A derivative of $\\Psi$ is used to derive a term for the stress. More details follow in \\cref{sec:discretization_mechanics}.\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*}\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 remain intact. Similarly, other material models can be defined using the framework of the strain energy function.\n\nIn short summary, the following system of equations describes the continuum mechanics model of muscle contraction:\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}\\\\[4mm]\n    \\bfS &= 2\\p{\\Psi(\\bfC)}{\\bfC}, && \\text{(constitutive equation)}\\label{eq:contraction_4}\n  \\end{align}\n\\end{subequations}\nwith a material model that defines the strain energy function $\\Psi$.\n\nDirichlet boundary conditions for the displacements $\\bfu$ and velocities $\\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%\nInitial conditions for $\\bfu$ and $\\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%\nAdditionally, Neumann boundary conditions can be used to prescribe traction forces on the surface.\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$.\nHowever, our implementation extends the model to the fully dynamic formulation given in \\cref{eq:contraction_1,eq:contraction_2,eq:contraction_3,eq:contraction_4}. \n\nMore details on the mechanics equations, their discretization and the resulting numerical scheme to obtain the solution functions $\\bfu$ and $\\bfv$ are given in \\cref{sec:discretization_mechanics}.\n\n\\subsection{Discretization and Solution Approach for the Solid Mechanics Model }\\label{sec:discretization_mechanics}\n\nThe following sections provides a more profound introduction of solid mechanics to complement the overview given before. We also describe the Finite Element discretization of the solid mechanics model and the algorithms used to obtain a numeric solution. \n\nDynamic \\emph{finite elasticity} methods considering large strains and generic hyperelastic materials, both compressible and incompressible, are less frequently used than \\emph{linear elasticity} descriptions with linearizations at various levels. Nonetheless, corresponding formulations exist in literature with sometimes varying conventions and symbols.\n\nThe 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. The derivation largely follows the book of Holzapfel \\cite{holzapfel2000nonlinear} and the discretization follows the work of Zienkiewicz, Taylor et al. \\cite{zienkiewicz1977finite,zienkiewicz2005finite}.\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 later used to describe the physics.\nAs introduced in \\cref{sec:model_muscle_contraction}, the function $\\bfvarphi_t:\\Omega_0\\to \\Omega_t$ maps points $\\bfX$ in the reference configuration $\\Omega_0$ to points $\\bfx = \\bfX + \\bfU$ in the current configuration $\\Omega_t$ using the displacement field $\\bfU(\\bfX)$. The displacement field formulated in terms of points $\\bfx$ in the current configuration is denoted by $\\bfu(\\bfx)=\\bfU(\\bfX(\\bfx))$.\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/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\n% stress measures\nTo employ the physical balance principles described in \\cref{sec:model_muscle_contraction}, we need to define stress measures. The Cauchy stress tensor $\\bfsigma$ has been introduced in \\cref{sec:model_muscle_contraction} using Euler's cut principle where the mechanical action on an arbitrary cut out of the domain is represented by a traction vector $\\bft$ as contact force per surface area. The 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$. The stress tensor $\\bfsigma$ is defined by Cauchy's theorem:\n\\begin{align*}\n  \\bft = \\bfsigma \\cdot \\bfn.\n\\end{align*}\nThus, the Cauchy stress describes the \\say{true stress} of contact forces per deformed area. Both slots of the second order tensor are associated with the current configuration. More specifically, $\\sigma$ 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$. While 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(\\bfg) = \\bfF^\\top\\bfg\\,\\bfF$ and push-forward operations $\\varphi_\\ast(\\bfG) = \\bfF^{-\\top}\\bfG\\,\\bfF^{-1}$, which bring tensors from Eulerian to Lagrangian description and vice-versa.\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 focus on descriptions of the stress.\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*}\nIt 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/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. \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. \nTo 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$. \nDifferent pairs of strain and stress tensors can be used. \nThe Lagrangian setting defines the right Cauchy-Green tensor $\\bfC$ and the dual second Piola-Kirchhoff stress $\\bfS$.\nWe consider these quantities in the further derivations, because the Lagrangian formulation is naturally used to derive the discretization schemes.\n\n\\subsection{A Linearized Model as an Exemplary Description of Solid Mechanics}\\label{sec:linearized_mechanics_model}\n\nThe quantities introduced in \\cref{sec:geometric_description} are linked together by various relations, which are summarized in a digram 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.\n\nIn this section, we present a simplified, static model where all of the assumed relations are linear. \nThis model serves as a prototype for the subsequent derivation of the fully nonlinear model. Besides the nonlinear model, our software OpenDiHu also implements the linearized description. The linear model exhibits better numerical properties and can be solved faster than the generic model. Thus, it can serve as a toy problem and for mechanical systems, where the linearization assumption is valid.\n\n% Tonti diagram\n\\begin{figure}\n  \\centering%\n  \\def\\svgwidth{\\textwidth}\n  \\input{images/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\nUsing variational calculus, the system response of external forces and infinitesimal, compatible, virtual displacements $δ\\bfu$ is studied. \nWe start with the \\emph{principle of virtual work}, which states that in equilibrium the virtual work $δW$ performed by external forces along virtual displacements $δ\\bfu$ is zero. Equivalently, the external virtual work $δW_\\text{ext}$ is equal to the internal virtual work $δW_\\text{int}$. \n\nThe external virtual work $δW_\\text{ext}$ is given by external forces $\\bft$ and the virtual displacements $δ\\bfu$ at the same location. The internal virtual work $δW_\\text{int}$ is the body's response in terms of stresses $\\bfsigma$ and virtual strains $\\bfeps$.\nIn summary, the equilibrium equation is given by:\n\\begin{align}\n  δW_\\text{int}(\\bfu,δ\\bfu) &= δW_\\text{ext}(δ\\bfu) \\qquad && \\forall δ\\bfu \\in H^1_0(\\Omega)\\label{eq:linearized_helper1}\\\\[4mm]\n  \\quad \\Leftrightarrow \\quad \\ds\\int_\\Omega \\bfsigma(\\bfu) : δ\\bfeps\\,\\d\\bfx &= \\ds\\int_{∂\\Omega} \\bft : δ\\bfu\\,\\d \\bfx &&\\forall δ\\bfu \\in H^1_0(\\Omega).\\label{eq:linearized_helper1b}\n\\end{align}\nHere, the vectors contain the degrees of freedom of a Finite Element discretization. The operator \\say{:} denotes the component-wise product. \n\nOften, it is easier to write the equations in component form. Indices $a,b,c,\\dots$ are used to specify a dimension index in $\\{1,\\dots,d\\}$. The letters $L,M \\in \\{1,\\dots,N\\}$ designate indices over degrees of freedom in a mesh with $N$ nodes. The Einstein sum convention is used where repeated indices implicitly indicate summation, except when the indices are in parantheses.\nThus, the right hand side of \\cref{eq:linearized_helper1b} with ansatz functions $\\phi^L$ and the degrees of freedom $δu_a^L$ of $δ\\bfu$ can be written as:\n\\begin{align*}\n  \\bff_a = \\ds\\int_{∂\\Omega} t_{(a)}\\,δu_{(a)}^L\\,\\phi^L \\,\\d \\bfx.\n\\end{align*}\n\nThe linear material model is 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\nThe third relation according to \\cref{fig:tonti_diagram} is the kinematics relation between displacements $\\bfu$ and strains $\\bfeps$. \nThe strain expression given in \\cref{eq:green_lagrange_u} is linearized by neglecting products of the derivatives and using the spatial displacements $\\bfu$ instead of $\\bfU$:\n\\begin{align}\\label{eq:linearized_helper3}\n  \\bfeps = \\dfrac12\\big((∇\\bfu)^\\top + ∇\\bfu\\big).\n\\end{align}\nBecause of small displacements, we do not distinguish between reference and current configuration, and \\cref{eq:linearized_helper1} combines the strain measure $\\bfeps$, which is derived from the Lagrangian Green-Lagrange strain with the Eulerian Cauchy stress $\\bfsigma$.\n\nBy combining \\cref{eq:linearized_helper1,eq:linearized_helper2,eq:linearized_helper3} and discretizing displacements and virtual displacements, we get the linear matrix equation\n\\begin{align}\\label{eq:linearized_helper4}\n  \\bfK\\,\\bfu = \\bff.\n\\end{align}\nThe stiffness matrix $\\bfK$ has rows and columns for every combination of degree of freedom $L,M \\in \\{1,\\dots,N\\}$ and dimension indices $a,b \\in \\{1,2,3\\}$. The entries are given by:\n\\begin{align*}\n  \\bfK_{LaMb} = \\ds\\int_{\\Omega} \\mathbb{C}_{adbc}\\p{\\phi^L(\\bfx)}{x_{d}}\\p{\\phi^M(\\bfx)}{x_{c}}\\,\\d \\bfx.\n\\end{align*}\n%\n\nThe resulting model in \\cref{eq:linearized_helper4} describes the passive behavior of a body under the linearization assumptions. For muscle tissue, we also need to incorporate active stresses that are generated at the sarcomeres in the muscle. We add an active stress term $\\bfsigma^\\text{active}$ to the external virtual work in \\cref{eq:linearized_helper1}, yielding the model:\n%\n\\begin{align}\\label{eq:linearized_helper5}\n  δW_\\text{int}(\\bfu,δ\\bfu) &= \\bff + \\ds\\int_\\Omega \\bfsigma^\\text{active} : δ\\bfeps_{-}\\,\\d\\bfx &&\\forall δ\\bfu \\in H^1_0(\\Omega).\n\\end{align}\n%\nThe active stress is associated with compression, i.e., negative virtual strains $δ\\bfeps < 0$. Therefore, we use $δ\\bfeps_{-}$ which is defined equal to $δ\\bfeps$ for $δ\\bfeps < 0$ and zero otherwise.\nFrom \\cref{eq:linearized_helper5}, we get the same discretized linear system as in \\cref{eq:linearized_helper4}, but with an additional term $\\bff^\\text{ active}$ at the right hand side that contains the discretized prescribed active stress field $\\bfsigma^\\text{active}_{ab}(\\bfx)$:\n\\begin{align*}\n  \\bff^\\text{ active}_{La} = \\ds\\int_{Ω}\\bfsigma^\\text{active}_{ab}(\\bfx)\\,\\p{\\phi^L(\\bfx)}{x_{b}} \\,\\d\\bfx.\n\\end{align*}\n%\n\n\\subsection{Nonlinear Material Modeling}\\label{sec:material_modeling}\n%\nNext, we present the derivation of a nonlinear model that forgoes all linearization assumptions of small strains. We begin with the description of the material law, which links strains and stresses.\n\nAs noted in \\cref{sec:discretization_mechanics}, the strain energy function $\\Psi$ is used to define the material model and it is linked to the second Piola-Kirchhoff stress $\\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*}\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*}\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 behaviour 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*}\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\\subsection{Derivation of the Stress Tensor and the Elasticity Tensor}\\label{sec:stress_and_elasticity}\nFollowing \\cref{eq:material_model_helper1}, the second Piola-Kirchhoff stress $\\bfS$ is given by a the derivative of the strain energy function $\\Psi$ with respect to $\\bfC$.\nFor the representation using the invariants, the chain rule has to be used:%\n\\begin{align*}\n   \\bfS &= 2\\,\\p{\\Psi(\\bfC)}{\\bfC} = \\p{\\Psi}{I_a}\\p{I_a}{\\bfC}.\n\\end{align*}\nUsing the decoupled form, the resulting stresses are also decoupled as $\\bfS = \\bfS_\\text{vol}+\\bfS_\\text{iso}$. The volumetric stress $\\bfS_\\text{vol}$ describes the elastic response to compression, the isochoric stress $\\bfS_\\text{iso}$ describes the response to the deviatoric deformation. In the following, all steps to compute these stresses are listed. The rationale is to give a condensed reference of the implemented algorithm in OpenDiHu to facilitate further development.\nFor the derivation of all intermediate steps, we refer to the literature \\cite{holzapfel2000nonlinear}.\n\nAt first, the reduced stress tensor $\\bar{\\bfS}$ that neglects the volumetric change is formulated as:%\n%\n\\begin{align*}\n  \\bar{\\bfS} = 2\\p{\\Psi_\\text{iso}(\\bar{I}_1,\\bar{I}_2,\\bar{I}_4,\\bar{I}_5)}{\\bar{\\bfC}} &= \\bar{\\gamma}_1\\,\\bfI + \\bar{\\gamma}_2\\,\\bar{\\bfC}\n  + \\bar{\\gamma}_4\\, \\bfa_0 \\otimes \\bfa_0 + \\bar{\\gamma}_5\\,(\\bfa_0 \\otimes \\bar{\\bfC}\\,\\bfa_0 + \\bfa_0\\bar{\\bfC}\\otimes \\bfa_0).\n\\end{align*}\nIn case of an isotropic material, the terms involving $\\bfa_0$ are not needed. The prefactors are given by derivatives of the strain energy function with respect to the reduced invariants:\n%\n\\begin{align*}\n  \\bar{\\gamma}_1 &= 2\\left(\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_1} + \\bar{I}_1\\,\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_2}\\right),\n  &\\bar{\\gamma}_2 &= -2\\p{\\Psi_\\text{iso}(\\bar{I}_1, \\bar{I}_2)}{\\bar{I}_2},\n  &\\bar{\\gamma}_4 &= 2\\p{\\Psi_\\text{iso}}{\\bar{I}_4}\\\\[4mm]\n  \\bar{\\gamma}_5 &= 2\\p{\\Psi_\\text{iso}}{\\bar{I}_5}\n\\end{align*}\n%\nUsing the fourth order identity tensor $\\mathbb{I}$ and the projection tensor $\\mathbb{P}$,%\n\\begin{align*}\n  (\\mathbb{I})_{abcd} &= \\delta_{ac}\\,\\delta_{bd}, &\n  \\mathbb{P} &= \\mathbb{I} - \\dfrac13 \\bfC^{-1} \\otimes \\bfC,\n\\end{align*}\nthe stress tensors can finally be computed as\n\\begin{align*}\n  \\bfS_\\text{iso} &= J^{-2/3}\\mathbb{P}:\\bar{\\bfS}, &\n  \\bfS_\\text{vol} &= J\\,p\\,\\bfC^{-1}, &\n  \\bfS &= \\bfS_\\text{iso} + \\bfS_\\text{vol}.\n\\end{align*}\nIn the compressible case including the penalty method, the value of $p$, that is needed for $\\bfS_\\text{vol}$, is given by the constitutive model as $p = \\d \\Psi_\\text{vol}(J)/\\d J$. In the incompressible case, $p$ is the unknown Lagrange multiplier that gets computed as part of the numerical solution. In that case, $p$ has the physical meaning of the hydrostatic pressure.\n\nAnother important quantity for the numerical solution is the fourth order elasticity tensor $\\C$, which is defined as\n\\begin{align*}\n  \\C = 2\\p{\\bfS(\\bfC)}{\\bfC} = 4\\dfrac{\\partial^2 \\Psi(\\bfC)}{\\partial\\bfC\\partial\\bfC}.\n\\end{align*}\nIt is the derivative of the stress tensor and is required in the Jacobian matrix of an iteration of the nonlinear Newton solver. Like the material tensor in \\cref{eq:symmetries}, it shows major and minor symmetries and has 21 independent entries.\n\nLike the stress tensor, the elasticity tensor is also additively composed into a volumetric term $\\C_\\text{vol}$ and an isochoric term $\\C_\\text{iso}$. The volumetric term can be computed by:%\n\\begin{align*}\n  \\mathbb{C}_\\text{vol} &= J\\,\\tilde{p}\\,\\bfC^{-1} \\otimes \\bfC^{-1} - 2\\,J\\,p\\,\\bfC^{-1} \\odot \\bfC^{-1}, &\n  \\big(\\bfC^{-1} \\odot \\bfC^{-1}\\big)_{abcd} &= \\dfrac12\\big(C^{-1}_{ac}\\,C^{-1}_{bd} + C^{-1}_{ad}\\,C^{-1}_{bc}\\big).\n\\end{align*}\nThe term includes two pressure variables $\\tilde{p}$ and $p$. In the incompressible formulation, both variables equals the Lagrange multiplier $p$. For the compressible formulation, $\\tilde{p}$ is derived as $\\tilde{p} = p + J\\,\\d p/\\d J$ and $p$ is computed from the volumetric strain energy function as stated above.\n\n\\clearpage\nThe isochoric term $\\mathbb{C}_\\text{iso}$ of the elasticity tensor follows from the following list of quantities to compute:%\n\\begin{align*}\n  &\\bar{\\delta}_1 = 4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_1} + 2\\,\\bar{I}_1\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_2} +\\dfrac{∂\\Psi_\\text{iso}}{∂\\bar{I}_2} + \\bar{I}_1^2\\,\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}\\right), \\,\n  \\bar{\\delta}_2 = -4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_2} + \\bar{I}_1\\,\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}\\right),\\\\[4mm]\n  &\\bar{\\delta}_3 = 4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_2}, \\quad\n  \\bar{\\delta}_4 = -4\\dfrac{∂\\Psi_\\text{iso}}{∂\\bar{I}_2}, \\quad\n  \\bar{\\delta}_5 = 4\\left(\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_1\\,∂\\bar{I}_4} +\\bar I_1 \\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_4}\\right),\\\\[4mm]\n  &\\bar{\\delta}_6 = -4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_2\\,∂\\bar{I}_4}, \\,\\,\\,\\,\n  \\bar{\\delta}_7 = 4\\dfrac{∂^2\\Psi_\\text{iso}}{∂\\bar{I}_4\\,∂\\bar{I}_4}, \\,\\,\\,\\,\n  \\mathbb{I}_{abcd} = δ_{ac}\\,δ_{bd}, \\,\\,\\,\\,\n  \\bar{\\mathbb{I}}_{abcd} = δ_{ad}\\,δ_{bc}, \\,\\,\\,\\,\n  \\mathbb{S} = (\\mathbb{I} + \\bar{\\mathbb{I}}) / 2, \\\\[4mm]\n  &\\p{\\bar I_5}{\\bar\\bfC} = \\bfa_0 \\otimes \\bar\\bfC\\,\\bfa_0 + \\bfa_0\\,\\bar\\bfC \\otimes \\bfa_0, \\quad\n  \\dfrac{∂^2\\bar{I}_5}{∂\\bar{\\bfC}∂\\bar{\\bfC}} = \\p{\\bar{\\bfC}}(\\bfa_0 \\otimes \\bar\\bfC\\,\\bfa_0 + \\bfa_0\\,\\bar\\bfC \\otimes \\bfa_0),\\\\[4mm]\n  &\\bar{\\mathbb{C}} = J^{-4/3}\\bigg(\\bar{\\delta}_1\\,\\bfI \\otimes \\bfI + \\bar{\\delta}_2\\,\\big(\\bfI \\otimes \\bar{\\bfC} + \\bar{\\bfC} \\otimes \\bfI\\big) + \\bar{\\delta}_3\\bar{\\bfC} \\otimes \\bar{\\bfC} + \\bar{\\delta}_4\\,\\mathbb{S}\n  +\\bar{δ}_5\\,(\\bfI \\otimes \\bfa_0 \\otimes \\bfa_0 + \\bfa_0 \\otimes \\bfa_0 \\otimes \\bfI)\\\\[4mm]\n  &\\hspace*{1cm} +\\bar{δ}_6\\,(\\bar{\\bfC} \\otimes \\bfa_0 \\otimes \\bfa_0 + \\bfa_0 \\otimes \\bfa_0 \\otimes \\bar{\\bfC})\n  +\\bar{δ}_7\\,(\\bfa_0 \\otimes \\bfa_0 \\otimes \\bfa_0 \\otimes \\bfa_0) \\\\[4mm]\n  &\\hspace*{1cm} + \\bar{δ}_8\\,\\Big(\\bfI \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bfI \\Big)\n  + \\bar{δ}_9\\,\\Big(\\bar{\\bfC} \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bar{\\bfC} \\Big) + \\bar{δ}_{10}\\Big(\\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}}\\Big) \\\\[4mm]\n  &\\hspace*{1cm}+ \\bar{δ}_{11} \\Big(\\bfa_0 \\otimes \\bfa_0 \\otimes \\p{\\bar{I}_5}{\\bar{\\bfC}} + \\p{\\bar{I}_5}{\\bar{\\bfC}} \\otimes \\bfa_0 \\otimes \\bfa_0 \\Big) + \\bar{δ}_{12} \\dfrac{∂^2\\bar{I}_5}{∂\\bar{\\bfC}∂\\bar{\\bfC}}\\bigg)\\\\[4mm]\n  &\\tilde{\\mathbb{P}} = \\bfC^{-1} \\odot \\bfC^{-1} - \\dfrac13 \\bfC^{-1} \\otimes \\bfC^{-1} \\\\[4mm]\n  &\\mathbb{C}_\\text{iso} = \\mathbb{P} : \\bar{\\mathbb{C}} : \\mathbb{P}^\\top + \\dfrac23 J^{-2/3} \\bar{\\bfS} : \\bfC\\,\\tilde{\\mathbb{P}} - \\dfrac23\\big(\\bfC^{-1}\\otimes \\bfS_\\text{iso} + \\bfS_\\text{iso}\\otimes \\bfC^{-1}\\big)\n\\end{align*}\nThen, $\\C = \\C_\\text{vol} + \\C_\\text{iso}$ can be calculated.\n%\n%\n\n% invariants: I1-I5\n% transversely isotropic\n% reduced invariants, reduced quantities for compressible materials\n% strain energy function, derivative\n% elasticity tensor\n% -> computation of S and C\n\n\\subsection{Derivation of the Static Hyperelastic Finite Element Model}\\label{sec:static_hyperelastic_fe_model}\n\nIn \\cref{sec:linearized_mechanics_model}, the ingredients of a solid mechanics model derivation consisting of equilibrium, material and kinematic equations were outlined and used to derive a linearized description. For the nonlinear model, the material equations were discussed in \\cref{sec:material_modeling} and the stress and elasticity tensors were derived in \\cref{sec:stress_and_elasticity}. This section uses these building blocks and presents the full derivation for the generic hyperelastic Finite Element model.\n\nFirst, we assume a static, incompressible problem. The equilibrium equation can 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$.\nThe functional is additively composed of internal and external potential energy:\n\\begin{align*}\n  \\Pi_L(\\bfu,p) = \\Pi_\\text{int}(\\bfu,p) + \\Pi_\\text{ext}(\\bfu).\n\\end{align*}\nThe external energy functional is formulated by\n\\begin{align*}\n  \\Pi_\\text{ext}(\\bfu) = -\\ds\\int_{\\Omega_0} \\bfB\\, \\bfu\\,\\d V - \\ds\\int_{∂\\Omega_0^t}\\bar{\\bfT}\\,\\bfu\\,\\d S,\n\\end{align*}\nwith body force $\\bfB$ in reference configuration and prescribed surface traction $\\bar{\\bfT}$ on the traction boundary $∂\\Omega_0^t$.\nThe internal energy functional is given by:\n%\n%\n\\begin{align}\\label{eq:mechanics_helper1}\n  \\Pi_\\text{int}(\\bfu,p) = \\ds\\int_{\\Omega_0} \\Psi_\\text{iso}\\big(\\bar\\bfC(\\bfu)\\big)\\,\\d V\n    + \\ds\\int_{\\Omega_0} p\\,\\big(J(\\bfu) - 1\\big)\\,\\d V.\n\\end{align}\n%\nHere, $\\Psi_\\text{iso}$ is the isochoric strain-energy density function in terms of the reduced right Cauchy-Green tensor $\\bar{\\bfC}$.\nThe first term in \\cref{eq:mechanics_helper1} describes the isochoric elastic response of the material, the second term adds the incompressibility constraint $J=1$ with the Lagrange multiplier $p$. The value of $p$ is computed as part of the model and can be identified as the hydrostatic pressure. Therefore, the second term is interpreted as the elastic response to compression and is included in the internal energy functional $\\Pi_\\text{int}$.\n\nAccording to the \\emph{principle of stationary potential energy}, the system is in equilibrium, if the potential energy functional is stationary.\nThis is the case, if the first variation $δ\\Pi_L$ is zero.\nUsing the additive structure of $\\Pi_L$, we can express the principle of stationarity as\n\\begin{subequations}\n  \\begin{align}\n    D_{δ\\bfu}\\Pi_L(\\bfu, p) &= D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p) + D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) \\overset{!}{=} 0, & \\forall δ\\bfu  \\label{eq:variations_functional_zero_a}\\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu, p) &= D_{δp}\\Pi_\\text{int}(\\bfu,p) \\overset{!}{=} 0 & \\forall δp. \\label{eq:variations_functional_zero_b}\n  \\end{align}\n\\end{subequations}\nThe variations of the internal and external energy functionals are defined as\n\\begin{align}\\label{eq:def_variation}\n  D_{δ\\bfu}\\Pi(\\bfu) &= \\d{\\eps} \\Pi(\\bfu + \\epsδ\\bfu)\\big|_{\\eps=0}, & \n  D_{δp}\\Pi(p) &= \\d{\\eps} \\Pi(p + \\epsδp)\\big|_{\\eps=0}.\n\\end{align}\nThey can be identified as the internal and external virtual work,\n\\begin{align*}\n  D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p) &= δW_\\text{int}, & D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) &= -δW_\\text{ext}.\n\\end{align*}\nThus, \\cref{eq:variations_functional_zero_a} can be expressed as \n\\begin{align*}\n  δW_\\text{int} - δW_\\text{ext} &= 0,\n\\end{align*}\nwhich is the form of the equilibrium equation that was used in \\cref{eq:linearized_helper1} in the derivation of the linearized model in \\cref{sec:linearized_mechanics_model} . The Euler-Lagrange equations corresponding to the variational problem are the local incompressibility constraint and the partial differential equation of balance of momentum presented in \\cref{eq:contraction_1,eq:contraction_2}.\n\nExecuting the derivative in the definitions of the variations in \\cref{eq:def_variation} yields the following terms:\n\\begin{align*}\n  &D_{δ\\bfu}\\Pi_\\text{int}(\\bfu,p)  = \\ds\\int_{\\Omega_0} \\bfS(\\bfu,p): δ\\bfE(δ\\bfu)\\,\\d V,\n  \\qquad D_{δp}\\Pi_\\text{int}(\\bfu,p) =\\ds\\int_{\\Omega_0} \\big(J(\\bfu) - 1\\big)δp\\,\\d V, \\\\[4mm]\n  &D_{δ\\bfu}\\Pi_\\text{ext}(\\bfu) = -\\ds\\int_{\\Omega_0} \\bfB\\cdot δ\\bfu\\,\\d V - \\ds\\int\\limits_{∂\\Omega^t_0} \\bar{\\bfT}\\cdot δ\\bfu\\,\\d S,\n\\end{align*}\nwhere the variational variables $δp,δ\\bfu$ and $δ\\bfE$ are the virtual pressure, virtual displacements, and virtual strains.\n\n% discretization\nWe discretize the solutions of the functional for the displacements $\\bfu(\\bfx)$ and pressure $p(\\bfx)$ and their variations using different ansatz functions $\\phi^L$, $L=1,\\dots,N_u$ and $\\psi^L$, $L=1,\\dots,N_p$:\n\\begin{align*}\n   u_a &= \\hat{u}_a^L \\phi_{(a)}^L, & δu_a &= δ\\hat{u}_a^L \\phi_{(a)}^L,   & p &= \\hat{p}^L \\psi^L, & δp &= δ\\hat{p}^L \\psi^L.\n\\end{align*}\nThe displacements function is vector-valued and given by $\\bfu(\\bfx) = (u_1(\\bfx), u_2(\\bfx), u_3(\\bfx))^\\top$. The vectors containing the degrees of freedom are denoted by $\\hat{\\bfu} = (\\hat{u}^L)_{L=1,\\dots,N_u}$ and $\\hat{\\bfp} = (\\hat{p}^L)_{L=1,\\dots,N_p}$.\n\nThe kinematics equation to compute virtual strains from virtual displacements follows from \\cref{eq:green_lagrange_u} in Lagrangian description and is given by $δ\\bfE = \\sym(\\bfF^\\top ∇\\bfu)$ or in discretized form, where the subscript comma $\\square_{,A}$  indicates the derivative with respect to the indexed coordinate $\\bfX_A$:\n\\begin{align*}\n  δE_{AB} &= \\dfrac12\\left(F_{aB}\\, \\phi_{(a),A}^M + F_{aA}\\, \\phi_{(a),B}^M\\right)δ\\hat{u}_{a}^M.\n\\end{align*}\n%\n% summarize equations\nIn summary, the discretized nonlinear equations are given by \n\\begin{align*}\n  δW_\\text{int}(\\bfu,p) - δW_\\text{ext} &= 0 \\qquad &\\forall\\,δ\\bfu, \\\\[4mm]\n  D_{δp}\\Pi_L(\\bfu) &= 0 \\qquad &\\forall\\,δp,\n\\end{align*}\nwith the discretized terms\n\\begin{subequations}\\label{eq:mechanics_static_system}\n  \\begin{align}\n    δW_\\text{int}({\\bfu},{p})  = \\ds\\int_{\\Omega}\\dfrac12  S_{AB}(\\bfu,p)\\, \\left(F_{aB}\\, \\phi_{(a),A}^M + F_{aA}\\, \\phi_{(a),B}^M\\right)δ\\hat{u}_{a}^M \\,\\d V,\\\\[4mm]\n    δW_\\text{ext}  = \\ds\\int_{\\Omega} B_a \\phi_{(a)}^M\\,δ\\hat{u}^M_a \\,\\d V +\\ds\\int_{∂\\Omega}  \\bar{T}^L_a\\,\\phi_{(a)}^L\\, \\phi_{(a)}^M\\,δ\\hat{u}^M_a\\,\\d S, \\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu) = \\ds\\int_\\Omega \\big(J(\\bfu) - 1)\\,δp\\,\\d V .\n  \\end{align}\n\\end{subequations}\n\n\\subsection{Nonlinear Solver for the Solid Mechanics Model}\\label{sec:solver_static_hyperelastic_fe_model}\n\n% Newton solver\nThe governing nonlinear system of equations is solved by a Newton scheme. We define the vector of the unknown degrees of freedom as $(\\hat{\\bfu},\\hat{p}) =: \\bfz$. Then, the nonlinear equation takes the general form $\\bfW(\\bfz) = 0$. By linearization around a value $\\bfz$, we get%\n\\begin{align*}\n  \\bfW(\\bfz+Δ\\bfz) = \\bfW(\\bfz) + \\bfJ\\,Δ\\bfz + o(\\bfz + Δ\\bfz),\n\\end{align*}\nwith the increment $Δ\\bfz = (Δ\\hat\\bfu, Δ\\hat{p})$ and the Jacobian matrix $\\bfJ = \\partial {\\bfW}/\\partial {\\bfz}$.\nNeglecting the sublinear error term $o(z + Δz)$, we can start from an initial guess $\\bfz^{(0)}$ and proceed to find the root of $\\bfW$ using the the following iterative Newton scheme:%\n\\begin{subequations}\\label{eq:newton_scheme}\n  \\begin{align}\n    \\bfJ\\,Δ\\bfz^{(n)} = -\\bfW(\\bfz^{(n)}),\\label{eq:mechanics_linear_system}\\\\[4mm]\n    \\bfz^{(n+1)} = \\bfz^{(n)} + Δ\\bfz^{(n)}.\n  \\end{align}\n\\end{subequations}\n\\Cref{eq:mechanics_linear_system} is a linear system of equations with the system matrix given by $\\bfJ$, which has to be solved in every iteration step $n$. The linear system of equations can be expressed as follows:\n\\begin{align}\\label{eq:static_newton_iteration}\n  \\matt{\\bfk_{δ\\bfu,Δ\\bfu} & \\bfk_{δp,Δ\\bfu}^\\top \\\\[2mm]\n  \\bfk_{δp,Δ\\bfu} & \\bfzero} \\, \\matt{Δ\\hat{\\bfu} \\\\[2mm] Δ\\hat{p}} \n  =\n  \\matt{-\\bfR_{δ\\bfu} \\\\[2mm] -\\bfR_{δp}}.\n\\end{align}\nThe definition of the right hand sides $\\bfR_{δ\\bfu} = δW_\\text{int} - δW_\\text{ext}$ and $\\bfR_{δp}=D_{δp}\\Pi_L$ is given in \\cref{eq:mechanics_static_system}. The system matrix is composed as follows. The upper left part consists of 3 times 3 blocks of submatrices, each with size $N_u \\times N_u$ and the entries given by:\n\\begin{align*}\n  \\bfk_{δ\\bfu,Δ\\bfu,(L,a),(M,b)} &= \\ds\\int_\\Omega \\phi_{(a),B}^L\\tilde{k}_{abBD}\\phi_{(b),D}^M\\,\\d V &\\text{with}\\quad \n  \\tilde{k}_{abBD} &= δ_{ab}\\,S_{BD} + F_{aA}\\,F_{bC}\\,\\mathbb{C}_{ABCD}.\n\\end{align*}\nHere, $S_{BD}$ and $\\mathbb{C}_{ABCD}$ are entries of the second Piola-Kirchhoff stress tensor $\\bfS$ and the elasticity tensor $\\mathbb{C}$. The computation of these terms uses the description in \\cref{sec:stress_and_elasticity}.\n\nThe lower left part of the system matrix in \\cref{eq:static_newton_iteration} is given by 1 times 3 blocks of submatrices, each with size $N_p \\times N_u$ and entries given by:\n\\begin{align*}\n  \\bfk_{δp,Δ\\bfu,L,(M,a)} = \\ds\\int_\\Omega J\\,\\psi^L\\,(F^{-1})_{Ba}\\,\\phi_{(a),B}^M \\,\\d V.\n\\end{align*}\nThe upper right part equals the transposed lower left block such that the system matrix is symmetric. Solving the system in \\cref{eq:static_newton_iteration} in every iteration of the Newton scheme in \\cref{eq:newton_scheme} converges to the solution of the static solid mechanics problem.\n\n\\subsection{Derivation and Solution of the Dynamic Hyperelastic Finite Element Model}\\label{sec:solver_dynamic_hyperelasticity_fe_model}\n% dynamic hyperelasticity (6.9.2)\nBased on the static formulation that was described in \\cref{sec:static_hyperelastic_fe_model,sec:solver_static_hyperelastic_fe_model}, we now formulate a dynamic model that takes into account the inertia of the contracting muscle.\n\nWe add an unknown velocity function $\\bfv: \\Omega_t \\to \\R^3$ to the formulation. The additional equation $\\dot{\\bfu} = \\bfv$ relates the displacements and the velocity. Moreover, a new inertial body force $\\bfB_\\text{a} = \\rho_0\\,\\dot{\\bfv}$ is added. \n\nThe time derivatives are discretized to timesteps $t=i\\cdot \\dt$ with an implicit Euler scheme:\n\\begin{align*}\n  \\dot{\\bfu} &\\leadsto \\dfrac1{\\dt}(\\bfu^{(i+1)} - \\bfu^{(i)}), & \\dot{\\bfv} &\\leadsto \\dfrac1{\\dt}(\\bfv^{(i+1)} - \\bfv^{(i)}).\n\\end{align*}\n%\n\nBecause of the added inertial body force, the external virtual work now depends on the vector of unknowns.\nIn consequence, we split the external virtual work $δW_\\text{ext}$ into a dead part $δW_\\text{ext,dead}$ that solely depends on external forces and an inertial part:%\n\\begin{align*}\n  δW_\\text{ext} = δW_\\text{ext,dead} + \\ds\\int_{\\Omega} \\rho_0\\,\\dfrac{v^{(i+1),L}_{(a)} - v^{(i),L}_{(a)}}{dt}\\,\\phi_{(a)}^L\\, \\phi_{(a)}^M\\,δ\\hat{u}^M_a \\,\\d V = 0.\n\\end{align*}\nIn summary, the system of equations to proceed from timestep $i$ to $(i+1)$ is given as:\n\\begin{subequations}\\label{eq:mechanics_dynamic}\n  \\begin{align}\n    δW_\\text{int}({\\bfu^{(i+1)}},p^{(i+1)}) - δW_\\text{ext}(\\bfv^{(i)},\\bfv^{(i+1)}) &= 0 \\qquad &&\\forall\\,δ\\bfu,\\label{eq:mechanics_dynamic1}\\\\[4mm]\n    \\dfrac1{\\dt}(\\bfu^{(i+1)} - \\bfu^{(i)}) - \\bfv^{(i+1)} &= 0,\\label{eq:mechanics_dynamic2}\\\\[4mm]\n    D_{δp}\\Pi_L(\\bfu^{(i+1)}) &= 0 \\qquad &&\\forall\\,δp.\\label{eq:mechanics_dynamic3}\n  \\end{align}\n\\end{subequations}\nHere, \\cref{eq:mechanics_dynamic1} is the principle of virtual work, \\cref{eq:mechanics_dynamic2} relates displacements $\\bfu$ and velocities $\\bfv$ and \\cref{eq:mechanics_dynamic3} is the incompressibility constraint.\n\nThe system is again solved using the Newton scheme presented in \\cref{sec:solver_static_hyperelastic_fe_model}.\nThe linear system for each Newton iteration takes the following form:\n\\begin{align*}\n  \\matt{\n    \\bfk_{δ\\bfu,Δ\\bfu} & \\bfl_{δ\\bfu,Δ\\bfv} & \\bfk_{δp,Δ\\bfu}^\\top \\\\[2mm]\n    \\bfl_{δ\\bfv,Δ\\bfu} & \\bfl_{δ\\bfv,Δ\\bfv} & \\bfzero \\\\[2mm]\n    \\bfk_{δp,Δ\\bfu} & \\bfzero & \\bfzero\n  } \\, \n  \\matt{Δ\\hat{\\bfu} \\\\[2mm] Δ\\hat{\\bfv} \\\\[2mm] Δ\\hat{p}} \n  =\n  \\matt{-\\bfR_{δ\\bfu} \\\\[2mm] -\\bfR_{δ\\bfv} \\\\[2mm] -\\bfR_{δp}}.\n\\end{align*}\nThe entries $\\bfk_{δ\\bfu,Δ\\bfu}$ and $\\bfk_{δp,Δ\\bfu}$ are the same as in the static case in \\cref{eq:static_newton_iteration}.\nThe other non-zero entries are given by \n\\begin{align*}\n  \\bfl_{δ\\bfu,Δ\\bfv,(L,a),(M,b)} &= \\dfrac1{\\dt}\\delta_{ab} \\ds\\int_{\\Omega} \\rho_0\\,\\,\\phi_{(b)}^M \\,\\phi_{(a)}^L \\,\\d V, & \n  \\bfl_{δ\\bfv,Δ\\bfu,(L,a),(M,b)} &= \\dfrac{1}{\\dt}\\delta_{ab}\\,\\delta^{LM},\\\\[4mm]\n  \\bfl_{δ\\bfv,Δ\\bfv,(L,a),(M,b)} &= -\\delta_{ab}\\,\\delta^{LM}.\n\\end{align*}\n\nNote that in the dynamic problem, the system matrix is unsymmetric. It would be symmetric if the entries $\\bfl_{δ\\bfu,Δ\\bfv}$ and $\\bfl_{δ\\bfv,Δ\\bfu}^\\top$ were be the same. This would be the case for a density of one, $\\rho_0 = 1$, and if the term $\\int_{\\Omega} \\phi_{b}^M \\phi_{a}^L \\,\\d V$ would be replaced by $\\delta_{ab}\\delta^{LM}$. The second condition means that a lumped mass matrix would be used where the diagonal entries are set to the row sums of the original matrix.\n\nWe discretize the Finite Element solution in space by \\emph{Taylor-Hood} elements. This type of element uses quadratic ansatz functions $\\phi$ for the displacements and velocities and linear ansatz functions $\\psi$ for the Lagrange multiplier or hydrostatic pressure $p$ on a 3D hexahedral mesh. This choice was proven to exhibit no locking \\cite{zienkiewicz2005finite}. Locking is a phenomenon of degraded convergence of the Finite Element method for solid mechanics problems and occurs for improper discretization schemes.\n\nFor a compressible material, the incompressibility constraint which is the last equation in the systems \\cref{eq:mechanics_static_system} or \\cref{eq:mechanics_dynamic} is removed. Instead of solving for the pressure $p$ as a Lagrange multiplier, the value is given by the constitutive model as described in \\cref{sec:material_modeling}. In consequence, the system matrix of the linear system of equations that is solved in the Newton iterations has a smaller size for compressible materials.\n\nMoreover, the size varies depending on whether the static or the dynamic problem given in \\cref{sec:solver_static_hyperelastic_fe_model,sec:solver_dynamic_hyperelasticity_fe_model} is solved. Assuming a linear mesh with $N_p$ degrees of freedom and a quadratic mesh with $N_u$ degrees of freedom, the square system matrix has $3\\,N_u$ rows and columns for a static compressible formulation, $3\\,N_u + N_p$ for a static incompressible formulation, $6\\,N_u$ for a dynamic compressible model, and $6\\,N_u+N_p$ for a dynamic incompressible model.\n\n% static compressible:    3*N_u\n% static incompressible:  3*N_u + N_p\n% dynamic compressible:   3*N_u + 3*N_u\n% dynamic incompressible: 3*N_u + 3*N_u + N_p\n\n\nIn any case, the mechanics model can be linked to the subcellular model by defining the active stress as given in \\cref{eq:active_stress_term}. Since the active stress does not depend directly on the passive behavior, the active stress term can be added as a constant to the passive stress term. This constant also has no influence on the jacobian matrix $\\bfJ$. As the subcellular model depends on the fiber stretch $\\lambda_f = \\sqrt{I_4}$, there is a feedback loop between the subcellular and the solid mechanics model.\n\nDetails on the connection to the subcellular model as well as details on the numeric solution schemes for the nonlinear Newton solver and the linear solvers in every Newton iteration, including the solver schemes, how initial values are chosen and measures to speed up convergence such as load stepping are discussed in the implementation and result sections.\n\n%To speed up the computation, the initial guess of the vector of unknowns in every timestep is linearly extrapolated from the two previous timesteps.\n\n\n\n\\section{Model Order Reduction}\nConsidering the total reduction, we get the system to be solved for the fully reduced state $\\tilde{\\mathbf{z}}$: \n\\begin{equation*}\n  \\begin{array}{l}\n\t\\tilde{\\mathbf{z}}^{*} =\n\t\\tilde{\\mathbf{z}}^{(t)}+\n\t\\mathbf{V}_k^{\\text{T}} \\textbf{FG}(\\mathbf{v}_\\mathrm{m}^{(t)}, \\mathbf{y}^{(t)})\n\t\\label{e:POD_full_a},\\\\[0.5em]\n\t\\tilde{\\mathbf{z}}^{(t+1)} = \\tilde{\\mathbf{z}}^{*}+\\mathbf{V}_k^{\\text{T}}\n\t\\textbf{A}_\\mathrm{enh} \\mathbf{V}_k  \\tilde{\\mathbf{z}}^{(t+1)},\n  \\end{array}\n\\end{equation*}\nwhere $\\textbf{FG}(\\mathbf{v}_\\mathrm{m}, \\mathbf{y})$ and $ \\textbf{A}_\\mathrm{enh}$\nas well as the full state recovery are defined by\n\\begin{equation*}\n  \\textbf{FG}(\\mathbf{v}_\\mathrm{m}, \\mathbf{y}) := \\!  \\,\\left[\\begin{array}{c}\n  \t\\textbf{F}_1(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\\\\\n  \t\\textbf{F}_2(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\\\\\n  \t\\vdots \\\\\n  \t\\textbf{F}_n(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\\\\\n  \t\\textbf{G}_1(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\\\\  \t\n  \t\\textbf{G}_2(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\\\\\n  \t\\vdots \\\\  \t\n  \t\\textbf{G}_n(\\mathbf{v}_\\mathrm{m},\\mathbf{y})\n  \\end{array}\\right],\\, \n  \\textbf{A}_\\mathrm{enh} := \\left[ \\begin{array}{c}\n  \t\\textbf{A}_1\\\\\n  \t\\textbf{A}_2\\\\\n  \t\\textbf{A}_n\\\\\n  \t0 \\\\\n  \t\\vdots \\\\ \t\n  \t0 \n  \\end{array} \\right], \\,\n  \\mathbf{V}_k  \\tilde{\\mathbf{z}}=\\left[ \\begin{array}{c}\n  \t\\mathbf{v}_{\\mathrm{m},1} \\\\\n  \t\\mathbf{v}_{\\mathrm{m},2} \\\\ \n  \t\\vdots \\\\ \n  \t\\mathbf{v}_{\\mathrm{m},n} \\\\\t\n  \t\\mathbf{y}_1 \\\\ \n  \t\\mathbf{y}_2 \\\\ \n  \t\\vdots \\\\ \n    \\mathbf{y}_n \\\\\\end{array} \\right].\n\\end{equation*}\n%------------------------------------------------------------------------------------------------\n\\section{Quadrature}\n\nThe aim is to compute a good approximation for the integral\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    I := \\i{0}{1}f(\\xi)\\,\\d \\xi\n  \\end{array}\n\\end{equation*}\nwith a low number of function evaluations $f(\\xi)$. \n\\subsection{Gaussian quadrature}\nThe Gaussian quadrature rule approximates the integral by\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    I \\approx \\s{i=1}{n}f(\\xi_i)\\,w_i\n  \\end{array}\n\\end{equation*}\nwith appropriate \\emph{Gauss points} $\\xi_i$ and weights $w_i, i=1,\\dots,n$. The sampling points and weights are chosen such that the rule approximates polynomials of degree $p_\\text{exact}=2\\,n-1$ exactly. Some values are listed below. \n\n\\begin{table}[ht]\n\\centering\n\\begin{tabular}{c|c|c|c}\n    $n$& $\\xi_i$& $w_i$ & $p_\\text{exact}$\\\\[4mm]\n    \\hline&&\\\\[-4mm]\n    $1$& $\\dfrac12$ & $1$ & $1$\\\\[4mm]\n    \\hline\n    $2$& $\\pm \\dfrac{1+\\sqrt{3}}{2\\sqrt{3}}$ & $\\dfrac12$ & $3$\\\\[4mm]\n    \\hline\n    $3$& $\\dfrac12$ & $\\dfrac49$ & $5$ \\\\[4mm]\n     & $\\pm \\dfrac{\\sqrt{3}+\\sqrt{5}}{2\\sqrt{5}}$ & $\\dfrac{5}{18}$ &\n\\end{tabular}\n\\caption{Gauss points and weights}\n\\end{table}\n\nNote: Literature on Gauss quadrature often describes the case of an integral $\\int_{-1}^{1} f(x) \\,\\d x$. The transformation is given by:\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\i{0}{1} f(\\xi) \\,\\d \\xi = \\dfrac12 \\i{-1}{1} f\\big(1/2+x/2\\big) \\,\\d x.\n  \\end{array}\n\\end{equation*}\n\n\\subsection{Clenshaw-Curtis quadrature}\nClenshaw-Curtis quadrature approximates the function by a number of Chebyshev polynomials for which the exact integral is known.\nThe function $f$ is evaluated at the $n+1$ roots of the Chebyshev polynomial $T_{n+1}$, which are:\n\\begin{equation*}\n  \\begin{array}{lll}\n    \\xi_i = \\cos(i\\pi/n), \\quad i = 0,\\dots,n, \\,n \\text{ even}.\n  \\end{array}\n\\end{equation*}\nThe function can be written as Chebyshev series\n%    \n\\begin{equation*}\n  \\begin{array}{lll}\n    f(\\xi) = \\dfrac{a_0}{2} T_0(\\xi) + \\s{i=1}{∞} a_i\\,T_i(x)\n  \\end{array}\n\\end{equation*}\nwhere the coefficients result from discrete cosine transform. The approximated integral is computed by\n\\begin{equation*}\n  \\begin{array}{lll}\n    I \\approx a_0 + \\s{i=1}{n/2-1} \\dfrac{2\\,a_{2\\,i}}{1-(2\\,i)^2} + \\dfrac{a_n}{1-n^2}.\n  \\end{array}\n\\end{equation*}\nThe coefficients are\n%\n\\begin{equation*}\n  \\begin{array}{lll}\n    a_{2\\,i} = \\dfrac{2}{n}\\Bigg(\\dfrac{f(1)+f(-1)}{2} + f(0)\\,(-1)^i + \\s{i=1}{n/2-1}\\big(f(\\xi_i) + f(-\\xi_i)\\big)\\cos(k/2\\,\\xi_i)\\Bigg)\n  \\end{array}\n\\end{equation*}\n\nThis quadrature rule approximates polynomials with degree $p_\\text{exact} = m-1$ exactly when using $m$ sampling points. However for some non-polynomial functions its accuracy may be better than the respective Gauss quadrature.\n\n%------------------------------------------------------------------------------------------------\n\\section{Propositions}\nIn this section some propositions are collected such that they can be referenced when needed.\n\n\\subsection{Divergence theorem}\n\\textit{Also called Gauss's theorem.}\nLet $U \\subset \\R^d$ be a compact set with a piecewise smooth boundary $\\p U$, $\\bfF: U \\to \\R^d$ a continuously differentiable vector field. Then:\n\\begin{equation}\\label{eq:gauss}\n  \\begin{array}{ll}\n    \\ds\\int_U ∇\\cdot\\bfF(\\bfx) \\,\\d \\bfx = \\ds\\int_{\\p U} \\bfF(\\bfx)\\cdot \\bfn\\,\\d \\bfx.\n  \\end{array}\n\\end{equation}\nFor $d=2$ one gets \\emph{Stoke's theorem}.\n\n\\subsubsection{Corollary}\nReplacing $\\bfF$ of \\eqref{eq:gauss} by ${f\\,\\bfF}$ yields the following proposition:\n\nFor a differentable function $f: U \\to \\R$ and a vector field $\\bfF: U \\to \\R^d$ the following holds:\n\\begin{equation}\\label{eq:gauss1}\n  \\begin{array}{ll}\n     \\ds\\int_U f(∇\\cdot\\bfF) \\,\\d \\bfx = \\ds\\int_{\\p U} (f\\,\\bfF)\\cdot\\bfn\\,\\d \\bfx -\\ds\\int_U \\bfF \\cdot ∇f \\,\\d \\bfx\n  \\end{array}\n\\end{equation}\nNow set $\\bfF\\equiv (1,0,\\dots), (0,1,\\dots), \\dots$ to get the following vector-valued identity:\n\nFor a differentable function $f: U \\to \\R$ the following holds:\n\\begin{equation}\n  \\begin{array}{ll}\n    \\ds\\int_U ∇f(\\bfx) \\,\\d \\bfx = \\ds\\int_{\\p U} f(\\bfx)\\,\\bfn\\,\\d \\bfx\n  \\end{array}\n\\end{equation}\n\n\\subsection{Classical Stoke's theorem}\nLet $U\\subset \\R^3$ be an open set, $V$ a 2-manifold in $U$ with boundary $\\p V$ and $\\bfF: U \\to \\R^3$ a continuously differentiable vector field. Then:\n\\begin{equation}\n  \\begin{array}{ll}\n    \\ds\\varointctrclockwise_{\\p V} \\bfF\\cdot\\d s = \\ds\\int_{V} \\big(∇\\times \\bfF\\big) \\cdot \\bfn \\,\\d\\bfx,\n  \\end{array}\n\\end{equation}\nwhere $\\bfn$ is the normal on the surface $V$.\n\n\\subsection{Integration on manifolds}\nIn the following it is outlined how to integrate on 1D and 2D domains that are embedded in $\\R^d$. The formalism of manifolds is omitted for simplicity.\n\n\\subsubsection{1D curve integrals}\nLet $U\\subset \\R$ be an open set (the parameter space) and $\\Phi:U \\to \\R^d$ a smooth mapping that defines a curve $\\Omega=\\Phi(U)$ embedded in $\\R^d$. An integrable function $g:\\Omega \\to \\R$ can then be integrated as follows:\n%\n\\begin{equation}\\label{eq:integration_transformation_1d}\n  \\begin{array}{ll}\n    \\ds\\int_{\\Phi(U)} g(\\bfx) \\,\\d\\bfx = \\int_{U} g\\big(\\Phi(\\xi)\\big)\\,\\Vert \\Phi'(\\xi)\\Vert_2 \\, \\d \\xi\n  \\end{array}\n\\end{equation}\n\n\n\\subsubsection{2D surface integrals}\nLet $U \\subset \\R^2$ be an open set (parameter space), $\\Phi:U \\to \\Phi(U)=:\\Omega \\subset\\R^3$ a diffeomorphism, $\\Phi$ maps parameters $\\bfxi=(\\xi_1,\\xi_2) \\in U$ to points in world space $\\bfx \\in \\Omega$. The inverse map $\\Phi^{-1} : \\Omega \\subset \\R^3 \\to \\R^2$ assigns coordinates $(\\xi_1,\\xi_2)$ to each point $\\bfx\\in\\Omega$. We name $\\Phi^{-1}(\\bfx) = (x(\\bfx),y(\\bfx))$ in the following formula. The integration of a 2-dimensional function $g:\\Omega \\to \\R$ is performed as follows.\n%\n\\begin{equation}\\label{eq:integration_transformation_2d}\n  \\begin{array}{ll}\n    \\ds\\int_{\\Phi(U)} g(\\bfx) \\,\\d\\bfx  \n    &  = \\ds\\int_{U} g\\big(\\Phi(\\bfxi)\\big) \n    \\sqrt{\\det \\big(J_{\\Phi}(\\bfxi)^\\top J_{\\Phi}(\\bfxi)\\big)}\\,\\d\\bfxi\\\\[4mm]\n    \n    & = \\ds\\int_{U} g\\big(\\Phi(\\bfxi)\\big) \n    \\sqrt{\\det\\mat{\\d{\\Phi}{\\xi_1} \\cdot \\d{\\Phi}{\\xi_1} & \\d{\\Phi}{\\xi_1} \\cdot \\d{\\Phi}{\\xi_2}  \\\\[4mm]\n    \\d{\\Phi}{\\xi_1} \\cdot \\d{\\Phi}{\\xi_2} & \\d{\\Phi}{\\xi_2} \\cdot \\d{\\Phi}{\\xi_2}}}\\,\\d\\bfxi\\\\[4mm]\n    \n     & = \\ds\\int_{U} g\\big(\\Phi(\\bfxi)\\big) \n    \\sqrt{\\Big\\Vert \\d{\\Phi}{\\xi_1}\\Big\\Vert_2^2\\,\\Big\\Vert \\d{\\Phi}{\\xi_2}\\Big\\Vert_2^2 - \\Big(\\d{\\Phi}{\\xi_1} \\cdot \\d{\\Phi}{\\xi_2}\\Big)^2 }\\,\\d\\bfxi\\\\[4mm]\n    \n    \n  \\end{array}\n\\end{equation}\n\n\\subsubsection{Substitution on domains with same dimensionality}\n\\emph{Integration by substitution}, \\textit{German \\say{Transformationssatz}}, also \\emph{change of variables rule}.\nLet $U \\subset \\R^d$ be an open set, $\\Phi:U \\to \\Phi(U) \\subset\\R^d$ a diffeomorphism ($\\Phi$ bijective and continuously differentiable, inverse map $\\Phi^{-1}$ also continuously differentiable).\n\nThen $g:\\Phi(U) \\to \\R$ is integrable on $\\Phi(U)$ if and only if the function $\\bfxi \\mapsto g(\\Phi(\\bfxi))\\,|\\det(J_{\\Phi}(\\bfxi))|$ is integrable on $U$. The following holds:\n\\begin{equation}\\label{eq:integration_transformation_3d}\n  \\begin{array}{ll}\n    \\ds\\int_{\\Phi(U)} g(\\bfx)\\,\\d \\bfx = \\ds\\int_U g(\\Phi(\\bfxi))\\,|\\det(J_{\\Phi}(\\bfxi))|\\,\\d \\bfxi,\n  \\end{array}\n\\end{equation}\nwhere $J_{\\Phi}$ is the Jacobian of $\\Phi$.\n\n\\subsubsection{Summary}\nThe transformation rules \\cref{eq:integration_transformation_1d,eq:integration_transformation_2d,eq:integration_transformation_3d} can be summarized in a unified form as follows.\n\nLet $U \\subset \\R^d, d\\in\\{1,2,3\\}$ be an open set (parameter space), $\\Phi:U \\to \\Phi(U)=:\\Omega \\subset\\R^d$ a diffeomorphism that maps parameters $\\bfxi \\in U$ to points in world space $\\bfx \\in \\Omega$. A function defined in parameter space, $f:U\\to \\R$, can then be integrated as follows in world space.\n%\n\\begin{equation}\\label{eq:integration_transformation_dd}\n  \\begin{array}{lll}\n    \\ds\\int_{\\Phi(U)} f\\big(\\Phi^{-1}(\\bfx)\\big)\\,\\d \\bfx = \\ds\\int_U f(\\bfxi)\\,\\mathcal{J}_d(\\bfxi)\\,\\d \\bfxi,\n  \\end{array}\n\\end{equation}\nwhere the definition of $\\mathcal{J}_d(\\bfxi)$  depends on the dimension $d$ as follows:\n%\n\\begin{equation*}\n  \\begin{array}{rll}\n    \\mathcal{J}_1(\\xi) &= \\Vert \\Phi'(\\xi) \\Vert_2 &\\quad \\text{for }d=1, \\bfxi=\\xi \\in U \\subset \\R,\\\\[4mm]\n    \\mathcal{J}_2(\\bfxi) &= \\sqrt{\\det \\big(J_{\\Phi}(\\bfxi)^\\top J_{\\Phi}(\\bfxi)\\big)} &\\quad \\text{for }d=2, \\bfxi\\in U \\subset \\R^2, \\phi^{-1}(\\bfx) =: \\big(x(\\bfx), y(\\bfx)\\big),\\\\[4mm]\n    \\mathcal{J}_3(\\bfxi) &= |\\det (J_{\\Phi}\\big(\\bfxi)\\big)| &\\quad \\text{for }d=3, \\bfxi\\in U \\subset \\R^3.\n  \\end{array}\n\\end{equation*}\n\n% -------------- Literaturseite --------------------\n\\newpage\n\\nocite{*}\n\\bibliography{literatur}{}\n\\bibliographystyle{abbrv}\n\n% -------------- Anhang ------------\n%\\appendix\n%\\input{8_anhang.tex}\n\n\\end{document}\n", "meta": {"hexsha": "0f7649d9eb71c7c0658c8c459f05927e5143a5f9", "size": 137631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/derivations/doc.tex", "max_stars_repo_name": "maierbn/opendihu", "max_stars_repo_head_hexsha": "577650e2f6b36a7306766b0f4176f8124458cbf0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 17, "max_stars_repo_stars_event_min_datetime": "2018-11-25T19:29:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-20T04:46:22.000Z", "max_issues_repo_path": "doc/derivations/doc.tex", "max_issues_repo_name": "maierbn/opendihu", "max_issues_repo_head_hexsha": "577650e2f6b36a7306766b0f4176f8124458cbf0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-11-12T15:15:58.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-29T15:29:24.000Z", "max_forks_repo_path": "doc/derivations/doc.tex", "max_forks_repo_name": "maierbn/opendihu", "max_forks_repo_head_hexsha": "577650e2f6b36a7306766b0f4176f8124458cbf0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-10-17T12:18:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-28T13:24:20.000Z", "avg_line_length": 56.290797546, "max_line_length": 761, "alphanum_fraction": 0.6726754874, "num_tokens": 50071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297834483234, "lm_q2_score": 0.8633916099737806, "lm_q1q2_score": 0.7775098595607879}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Main maths packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage{mathtools}\n\n\\begin{document}\n\n\\section*{Piecewise functions}\n\n\\subsection*{The environment \\emph{cases}}\n\nThe best practices to define piecewise functions is to the environment \\emph{cases}.\n\n\\[\n\t\\operatorname{abs}(x)=\n\t\\begin{cases}\n\t\t-x\t& \\text{if } x < 0 \\\\\n\t\tx\t& \\text{if } x \\ge 0\n\t\\end{cases}\n\\]\n\n\\subsection*{The manual way using \\emph{aligned}}\n\nPiecewise functions can also be done using a brace and the environment \\emph{aligned}.\n\n\\[\n\t\\operatorname{abs}(x)=\n\t\\left\\{\n\t\\begin{aligned}\n\t\t-x\t& : x < 0 \\\\\n\t\tx\t& : x \\ge 0\n\t\\end{aligned}\n\t\\right.\n\\]\n\nWithin cases, \\emph{text} style math is used with results such as:\n\n\\[\n\tf(x)=\n\t\\begin{cases}\n\t\t\\int_{0}^{10} x\\, dx & \\text{if } x \\ge 0 \\\\\n\t\t\\frac{1}{x} & \\text{if } x < 0\n\t\\end{cases}\n\\]\n\n\\emph{Display} style may be used instead, by using the environment \\emph{dcases} with the package \\emph{mathtools}:\n\n\\[\n\tf(x)=\n\t\\begin{dcases}\n\t\t\\int_{0}^{10} x\\, dx & \\text{if } x \\ge 0 \\\\\n\t\t\\frac{1}{x} & \\text{if } x < 0\n\t\\end{dcases}\n\\]\n\nOften the second column consists mostly of normal text. To set it in the normal font of the document, the \\emph{dcases*} environment may be used:\n\n\\[\n\tf(x)=\n\t\\begin{dcases*}\n\t\t\\int_{0}^{10} x\\, dx & when $x$ is even \\\\\n\t\t\\frac{1}{x} & when $x$ is odd\n\t\\end{dcases*}\n\\]\n\n\\subsection*{The manual way using \\emph{array}}\n\nPiecewise functions can also be done using a brace and the environment \\emph{array}. This enables to control the alignment of the elements.\n\n\\[\n\t\\operatorname{abs}(x)=\n\t\\left\\{\n\t\\begin{array}{lr}\n\t\t-x\t& : x < 0 \\\\\n\t\tx\t& : x \\ge 0\n\t\\end{array}\n\t\\right.\n\\]\n\n\\end{document}", "meta": {"hexsha": "7f345b2549fb6cb16fdd458be657836788aa732d", "size": 1754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/piecewise-functions.tex", "max_stars_repo_name": "ZenLulz/LatexCompendium", "max_stars_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-30T21:43:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T20:16:19.000Z", "max_issues_repo_path": "compendium/mathematics/piecewise-functions.tex", "max_issues_repo_name": "ZenLulz/LatexCompendium", "max_issues_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compendium/mathematics/piecewise-functions.tex", "max_forks_repo_name": "ZenLulz/LatexCompendium", "max_forks_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.3953488372, "max_line_length": 145, "alphanum_fraction": 0.6516533637, "num_tokens": 644, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267898240861, "lm_q2_score": 0.8947894668039496, "lm_q1q2_score": 0.7774170600116812}}
{"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 4}\n\nLet $\\mathcal{C}_\\infty$, $\\mathcal{C}_\\epsilon$ be two collections of sets.\nDefine  $\\mathcal{C}_\\infty \\wedge \\mathcal{C}_\\epsilon = \\{ \\mathcal{C}_\\infty \\cap \\mathcal{C}_\\epsilon | \\mathcal{C}_\\infty \\in \\mathcal{C}_\\infty, \\mathcal{C}_\\epsilon \\in \\mathcal{C}_\\epsilon \\}$.\nShow that $\\prod_\\mathcal{C}(m) \\leq \\prod_{\\mathcal{C}_\\infty}(m) \\prod_{\\mathcal{C}_\\epsilon}(m)$.\n\n\\subsection*{Solution}\n\nWe assume an arbitrary set $X$ of size $m$.\nLet $Y_1, ..., Y_k$ be the set of intersections of concepts of $C_1$ with $X$.\nBy definition of $\\prod_{C_1}(X)$,\n$k \\leq \\prod_{C_1}(X) \\leq \\prod_{C_1}(m)$.\nSimilarly, from definition of $\\prod_{C_2}(Y_i)$, the intersections of the concepts from $C_2$ with $Y_i$ are at most $\\prod_{C_2}(Y_i) \\leq \\prod_{C_2}(m)$.\n\nTherefore, the number of sets intersections of concepts of $C$ with $X$ is at most\n$k \\prod_{C_2} (Y_i) \\leq \\prod_{C_1}(m) \\prod_{C_2}(m)$.\nSince we already showed $\\prod_{C_1}(X)$,\n$k \\leq \\prod_{C_1}(X)$, therefore, the proof is complete and $\\prod_\\mathcal{C}(m) \\leq \\prod_{\\mathcal{C}_\\infty}(m) \\prod_{\\mathcal{C}_\\epsilon}(m)$.\n", "meta": {"hexsha": "9cf0acbc4dbe8cf52a7e0d8bbd0d3f32aa492435", "size": 1475, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/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-cs671-2015s/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-cs671-2015s/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": 56.7307692308, "max_line_length": 201, "alphanum_fraction": 0.6298305085, "num_tokens": 515, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.777417046929243}}
{"text": "\\section{The transpose}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Calculate the transpose of a matrix.\n  \\item Determine whether a matrix is symmetric, antisymmetric, or neither.\n  \\item Manipulate algebraic expressions involving the transpose of matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nAnother important operation on matrices is that of taking the\n\\textbf{transpose}. The transpose of a matrix is obtained by turning\nthe rows into columns and vice versa.\n\n\\begin{definition}{The transpose of a matrix}{matrix-transpose}\n  Let $A$ be an $m\\times n$-matrix.  Then the \\textbf{transpose}%\n  \\index{matrix!transpose}%\n  \\index{transpose of a matrix} of $A$, denoted $A^T$, is the\n  $n\\times m$-matrix whose $(i,j)$-entry is the $(j,i)$-entry of $A$.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      a_{11} & \\cdots & a_{1n} \\\\\n      a_{21} & \\cdots & a_{2n} \\\\\n      \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix},\n    \\quad\n    A^T = \\begin{mymatrix}{cccc}\n      a_{11} & a_{21} & \\cdots & a_{m1} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{1n} & a_{2n} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{example}{The transpose of a matrix}{transpose-matrix}\n  Find the transpose of the following matrix:\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 6 \\\\\n      3 & 5 & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The transpose is\n  \\begin{equation*}\n    A^T =\n    \\begin{mymatrix}{rr}\n      1 & 3 \\\\\n      2 & 5 \\\\\n      6 & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  Notice that $A$ is a $2\\times 3$-matrix, while $A^T$ is a\n  $3\\times 2$-matrix.\n\\end{solution}\n\nWe have already used a special case of the transpose since\nChapter~\\ref{cha:vectors-rn}, when we wrote\n$\\begin{mymatrix}{rrr}1&2&3\\end{mymatrix}^T$ as a space-saving\nnotation for the column vector\n\\begin{equation*}\n  \\begin{mymatrix}{c}\n    1 \\\\\n    2 \\\\\n    3 \\\\\n  \\end{mymatrix}.\n\\end{equation*}\n\nThe transpose of a matrix satisfies the following\nproperties%\n\\index{transpose of a matrix!properties}%\n\\index{matrix!transpose!properties}%\n\\index{matrix!properties of transpose}:\n\n\\begin{proposition}{Properties of the transpose}{transpose-properties}\n  Let $A$ and $B$ be matrices of appropriate sizes, and $r$ a\n  scalar. Then the following hold.\n  \\begin{enumerate}\n  \\item $(A^T)^T = A$.\n  \\item $(A+B)^T=A^T+B^T$.\\label{matrix-transpose-2}\n  \\item $(rA)^T=rA^T$.\\label{matrix-transpose-3}\n  \\item $(AB)^T=B^TA^T$.\\label{matrix-transpose-4}\n  \\item $0^T = 0$.\n  \\item $I^T = I$.\n  \\item $(A^{-1})^T = (A^T)^{-1}$, if $A$ is invertible.\n  \\end{enumerate}\n\\end{proposition}\n\nRecall that a column vector is the same thing as a $n\\times\n1$-matrix. Using the transpose, we can make precise the connection\nbetween the dot product and the matrix product%\n\\index{dot product!from matrix product}%\n\\index{vector!dot product!from matrix product}. Namely, let\n\\begin{equation*}\n  \\vect{v}=\\begin{mymatrix}{c}v_1\\\\\\vdots\\\\v_n\\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{w}=\\begin{mymatrix}{c}w_1\\\\\\vdots\\\\w_n\\end{mymatrix}\n\\end{equation*}\nby column vectors. Then\n\\begin{equation*}\n  \\vect{v}\\dotprod\\vect{w}\n  ~=~\n  v_1w_1 + \\ldots + v_nw_n\n  ~=~\n  \\begin{mymatrix}{ccc} v_1 & \\cdots & v_n \\end{mymatrix}\n  \\begin{mymatrix}{c} w_1 \\\\ \\vdots \\\\ w_n \\end{mymatrix}\n  ~=~\n  \\vect{v}^T\\vect{w}.\n\\end{equation*}\nIn other words, the dot product of column vectors $\\vect{v}$ and\n$\\vect{w}$ is the same thing as the matrix product\n$\\vect{v}^T\\vect{w}$.\n\nWe can also use the notion of transpose to define what it means for a\nmatrix to be \\textbf{symmetric} and \\textbf{antisymmetric}.\n\n\\begin{definition}{Symmetric and antisymmetric matrices}{symmetric-and-antisymmetric}\n  An $n\\times n$-matrix $A$ is said to be \\textbf{symmetric}%\n  \\index{matrix!symmetric}%\n  \\index{symmetric matrix} if $A^T=A$. It is said to be\n  \\textbf{antisymmetric}%\n  \\index{matrix!antisymmetric}%\n  \\index{antisymmetric matrix} (sometimes also called \\textbf{skew\n    symmetric}%\n  \\index{matrix!skew symmetric}%\n  \\index{skew symmetric matrix}) if $A^T=-A$.\n\\end{definition}\n\n\\begin{example}{Symmetric and antisymmetric matrices}{symmetric-matrix}\n  Let\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      2 & 1 & 3 \\\\\n      1 & 5 & -3 \\\\\n      3 & -3 & 7\n    \\end{mymatrix},\n    \\quad\n    B=\\begin{mymatrix}{rrr}\n      0 & 1 & 3 \\\\\n      -1 & 0 & 2 \\\\\n      -3 & -2 & 0\n    \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    C=\\begin{mymatrix}{rrr}\n      0 & 1 &  3 \\\\\n      1 & 5 & -3 \\\\\n      1 & 3 &  0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Then $A$ is symmetric because $A^T=A$, $B$ is antisymmetric\n  because $B^T=-B$, and $C$ is neither symmetric nor antisymmetric\n  because $C^T$ is equal to neither $C$ nor $-C$.\n\\end{example}\n\n", "meta": {"hexsha": "d77b2fcef7d5fc4b7a896e8713b58febc45df229", "size": 4800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Transpose.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-Transpose.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-Transpose.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.3797468354, "max_line_length": 85, "alphanum_fraction": 0.6475, "num_tokens": 1716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381843, "lm_q2_score": 0.8947894654011352, "lm_q1q2_score": 0.7774170466363567}}
{"text": "\\section{Sparse Coding}\n\n\\subsection*{Orthogonal Basis}\nPros: fast inverse; preserves energy. \nFor $\\mathbf{x}$ and orthog. mat. $\\mathbf{U}$ compute $\\mathbf{z} = \\mathbf{U}^\\top \\mathbf{x} $. Approx $ \\mathbf{\\hat{x}} = \\mathbf{U\\hat{z}}$, $\\hat{z}_i = z_i$ if $ \\lvert z_i \\rvert > \\epsilon$ else 0.\nReconstruction Error $\\|\\mathbf{x}-\\mathbf{\\hat{x}}\\|^2 = \\sum_{d\\notin\\sigma}\\langle\\mathbf{x},\\mathbf{u}_d\\rangle ^2$.\nChoice of base depends on signal. Fourier for global, wavelet for local support. PCA basis optimal for given $\\Sigma$. Stripes \\& check patterns: hi-freq in Fourier.\n\n\\subsection*{Haar Wavelets (form orthogonal basis)}\nscaling fcn $\\phi(x)=[1,1,1,1]$, mother $W(x)=[1,1,-1,-1]$, dilated $W(2x)=[1,-1,0,0]$, translated $W(2x-1)=[0,0,1,-1]$\n\n\\subsection*{Overcomplete Basis}\n$\\mathbf{U} \\in \\mathbb{R}^{D \\times  L}$ for \\# atoms $ = L > D = \\mathsf{dim}\\text{(data)}$. Decoding involved $\\rightarrow$ add constraint $\\mathbf{z}^\\star \\in \\argmin_\\mathbf{z} \\lVert \\mathbf{z} \\rVert_0$ s.t. $\\mathbf{x} = \\mathbf{Uz}$. NP-hard $\\rightarrow$ approximate with 1-norm (convex) or with MP.\n\n\\textbf{Coherence}\n\\begin{inparaitem}[\\color{red}\\textbullet]\n\t\\item $m(\\mathbf{U}) = \\max_{i,j:\\, i \\neq j} | \\mathbf{u}_i^\\top \\mathbf{u}_j |$\n\t\\item $m(\\mathbf{B}) = 0$ if $\\mathbf{B}$ orthogonal matrix\n\t\\item $m([\\mathbf{B}, \\mathbf{u}]) \\geq \\frac{1}{\\sqrt{D}}$ if atom $\\mathbf{u}$ is added to orthogonal basis $\\mathbf{B}$ (o.n.b. = orthonormal base)\n\\end{inparaitem}\n\n\\textbf{Matching Pursuit (MP)}\napproximation of $\\mathbf{x}$ onto $\\mathbf{U}$, using $K$ entries.\nObjective: $\\mathbf{z}^\\star \\in \\argmin_{\\mathbf{z}} \\|\\mathbf{x} - \\mathbf{Uz} \\|_2$, s.t. $\\|\\mathbf{z}\\|_0 \\leq K$\n\\begin{inparaenum}[\\color{red}1.]\n\t\\item init: $z \\leftarrow 0, r \\leftarrow x$\n\t\\item while $\\|\\mathbf{z}\\|_0 < K$ do\n\t\\item select atom with smallest angle $i^\\star = \\argmax_i |\\langle \\mathbf{u}_i, \\mathbf{r} \\rangle|$\n\t\\item update coefficients: $z_{i^\\star} \\leftarrow z_{i^\\star} + \\langle \\mathbf{u}_{i^\\star}, \\mathbf{r} \\rangle$\n\t\\item update residual: $\\mathbf{r} \\leftarrow \\mathbf{r} - \\langle \\mathbf{u}_{i^\\star}, \\mathbf{r} \\rangle \\mathbf{u}_{i^\\star}$.\n\\end{inparaenum}\n\\\\\\textbf{Exact recovery} when: $K<1/2( 1+1/m(\\mathbf{U}))$\n\n\\textbf{Compressive Sensing}: Compress data while gathering:\n\\begin{inparaitem}[\\color{red}\\textbullet]\n  \\item $\\mathbf{x} \\in \\mathbb{R}^D$, $K$-sparse in o.n.b. $\\mathbf{U}$. $\\mathbf{y} \\in \\mathbb{R}^M$ with $y_i = \\langle \\mathbf{w}_i, \\mathbf{x}\\rangle $: $M$ lin. combinations of signal; $\\mathbf{y} = \\mathbf{Wx} = \\mathbf{WUz} = \\mathbf{\\Theta z}$, $\\Theta \\in \\mathbb{R}^{M \\times D}$\n  \\item Reconstruct $\\mathbf{x} \\in \\mathbb{R}^D$ from $\\mathbf{y}$; find $\\mathbf{z}^\\star \\in \\argmin_{\\mathbf{z}}\\|\\mathbf{z}\\|_0$, s.t. $\\mathbf{y} = \\mathbf{\\Theta z}$ (e.g. with MP, or convex it with 1-norm: canbe eq!). Given $\\mathbf{z}$, reconstruct $\\mathbf{x} = \\mathbf{Uz}$\n\\end{inparaitem}\n\\\\Any orthogonal $\\mathbf{U}$ sufficient if:\n\\begin{inparaitem}[\\color{red}\\textbullet]\n  \\item $\\mathbf{W} = $ Gaussian random projection, i.e. $w_{ij}\\sim\\mathcal{N}(0, \\frac{1}{D})$\n  \\item M $\\geq cK log(\\frac{D}{K})$, where $c$ is some constant\n\\end{inparaitem}\n", "meta": {"hexsha": "c7c8ea468ece0a0aad81a540736945ade6f4b221", "size": 3217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SparseCoding.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": "SparseCoding.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": "SparseCoding.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": 73.1136363636, "max_line_length": 310, "alphanum_fraction": 0.6502953062, "num_tokens": 1273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894661025423, "lm_q2_score": 0.8688267677469951, "lm_q1q2_score": 0.7774170396479312}}
{"text": "%\n% Chapter 2.6\n%\n\n\\section*{2.6 Implicit Differentiation}\n\nImplicit differentiation is a way of solving a derivative by differentiating both sides of an equation with respect to \\(x\\) and the solving the resulting equation for \\(y'\\).\n\n\\subsubsection*{Example}\n\nFind \\(\\frac{dy}{dx} \\) of \\( x^2+y^2=25 \\).\n\n\\subsubsection*{Solution}\n\nDifferentiate both side of the equation.\n$$ \\frac{d}{dx}(x^2+y^2) = \\frac{d}{dx}(25) $$\n$$ \\frac{d}{dx}(x^2)+\\frac{d}{dx}(y^2)=0$$\n\\(y\\) is a function of \\(x\\) so we use the chain rule.\n$$ \\frac{d}{dx}(y^2) = \\frac{d}{dy} (y^2) \\frac{dy}{dx} = 2y\\frac{dy}{dx}$$\n$$ 2x + 2y \\frac{dy}{dx} = 0 $$\nSolve for \\(\\frac{dy}{dx}\\).\n$$ \\frac{dy}{dx}=-\\frac{x}{y} $$\n", "meta": {"hexsha": "cbdb18d884601615ccfd380441212cd66429b6b7", "size": 692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-6.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-6.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-6.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": 30.0869565217, "max_line_length": 175, "alphanum_fraction": 0.6156069364, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458251637412, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7773825531108475}}
{"text": "\\section{Gradient Descent}\n\\frame{\\tableofcontents[currentsection, hideothersubsections]}\n\n\\begin{frame}\n\\frametitle{Gradient Descent: Intro}\n\nRecall:\\\\\n\\begin{itemize}\n    \\item hypotheses as vectors $\\mathbf{w}$ that \\\\\n         come from a convex hypothesis class, $\\mathcal{H}$\n    \\item goal of learning:\\\\\n          to minimize the risk function $L_D(\\mathbf{w})$;\\\\\n          \\textbf{not} the empirical risk $L_S (h)$\n    \\item gradient def:\n        \\begin{figure}\n            \\centering\n            \\includegraphics[scale=0.30]{grad_def_p185}\n        \\end{figure}\n\\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Gradient Descent: Intro}\nGradient descent:\n\\begin{itemize}\n\\item an iterative optimization procedure\n\\item at each step: \\\\\n    improve the solution by\n    taking a step along the negative of the gradient of the function to be minimized at the current point\n\n    \\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.30]{eq_14_1}\n    \\end{figure}\n\\item after $T$ iterations, output either\n    \\begin{itemize}\n        \\item averaged vector\n            \\footnote{taking the average turns out to be rather useful, especially\n            when we generalize gradient descent to nondifferentiable functions and to the stochastic case}, \\textbf{or}\n        \\item last vector, \\textbf{or}\n        \\item the best performing vector\n    \\end{itemize}\n\\end{itemize}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Gradient Descent: Analysis of GD for Convex-Lipschitz Fn}\n\nLET:\n\\begin{itemize}\n\\item $\\mathbf{w^*}$ be any vector and\n\\item $B$ be an upper bound on $\\parallel \\mathbf{w^*} \\parallel$\n\\end{itemize}\n\\vspace{5mm}\n\nGOAL:\\\\\nto obtain an upper bound on  $f(\\bar{\\mathbf{w}}) - f(\\mathbf{w^*})$,\nwhere $\\bar{\\mathbf{w}} = \\frac{1}{T} \\sum_{1}^{T} \\mathbf{w}^{(t)}$\n\\vspace{5mm}\n\nRESULT:\\\\\nFrom the definition of $\\bar{\\mathbf{w}}$, and using Jensen's inequality, we obtain:\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{eq_14_3b}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Gradient Descent: Analysis of GD for Convex-Lipschitz Fn}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.25]{lemma_14_1}\n\\end{figure}\n\n\\end{frame}\n\n\\begin{frame}\n\\frametitle{Gradient Descent: Analysis of GD for Convex-Lipschitz Fn}\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.2]{corollary_14_2}\n\\end{figure}\n\n\\end{frame}\n", "meta": {"hexsha": "47d0f5279cc2d8563b31cfe68081ce4e7fa394d8", "size": 2370, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "talk/tor/cvx-sgd-20180316/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/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/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": 26.043956044, "max_line_length": 119, "alphanum_fraction": 0.6848101266, "num_tokens": 725, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8807970811069351, "lm_q1q2_score": 0.7772398836137592}}
{"text": "\\section*{Ex.34.5-7}\n\\subsection*{Longest--simple--cycle problem (LSC)}\n\nThe decision problem: Is there a cycle of simple path of size $k$\n\nTo show NP:\n\\\\\nGet the vertices $v_1,\\ldots, v_n$ in sorted order, and verify that edges $(v_i, v_{i+1})$ exists in $G$ for $i\\in\\{1,\\ldots,n\\}$ and let $v_{n+1} = v_1$. This can be done in polynomial time. Hence LSC is NP.\n\nTo show NP completeness we want to show that HAM--CYCLE $\\leq_P$ LSC:\n\\\\\nIf you solve LSC with  $k=\\abs*{V}$ then you get 1 if there is a HAM--CYCLE and 0 else. Hence there exists a polynomial function which transform HAM--CYCLE to LSC. So LSC is NP complete.\t", "meta": {"hexsha": "6d2aa67a98ffe6ed3e754191726db92375b84df9", "size": 625, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.5-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": "Uge4/Ex.34.5-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": "Uge4/Ex.34.5-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": 52.0833333333, "max_line_length": 208, "alphanum_fraction": 0.7008, "num_tokens": 212, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8791467754256017, "lm_q1q2_score": 0.777200289268441}}
{"text": "% jam 2004-09-05\n\n\\section{Barycentric coordinates}\n\\label{sec:barycentric-coordinates}\n\nIn this section, I describe how to compute\nthe barycentric coordinates of a point $\\q$\nwith respect to a $n$-simplex in\na finite dimensional inner product space $\\Vspace$\n(with $\\dimension (\\Vspace ) = m \\ge n$) ---\nand the derivatives with respect to the vertex positions.\n\nLet $S$ be the geometric $n$-simplex\nwith vertex positions $\\{\\p_0  \\ldots  \\p_n\\}$;\nin $\\Vspace$.\n\nThe {\\it span} of $S$, $\\affine_span ( S )$,\nis the affine span of its vertex positions\n$\\affine_span \\{\\p_0  \\ldots  \\p_n\\}$,\nthat is, the set of points $\\q$ such that\n$\\q = \\sum_{j=n}^{m} b_j \\p_j $ where $1 = \\sum_{j=0}^{n} b_j $.\n$b_j$ are {\\it barycentric coordinates} of $\\q$ with respect to $S$.\nBarycentric coordinates of an arbitrary point $\\q \\in \\Vspace$,\nare barycentric coordinates of the closest point in $\\affine_span(S)$.\nIf $S$ is non-degenerate (the dimension of its span is $m$),\nthen the barycentric coordinates of any point are unique.\n\nAssume in what follows that $S$ is non-degenerate.\nWhen faced with for a degenerate simplex, there are several options.\nOne can use the minimum norm $\\b$.\nIt is often possible to use the barycentric coordinates\nwith respect to the 'largest' non-degenerate face instead.\nWe may also want to choose $\\b$ to be as close to convex,\n$0 \\le \\b_j \\le 1$, as possible. {\\it (How?)}\n\nLet $\\{ \\v_0 \\ldots \\v_{n-1} \\} = \\{ (\\p_0 - \\p_n) \\ldots (\\p_{n-1} - \\p_n)\\},$\nand let $\\Vmap = \\sum_{j=0}^{n-1} ( \\v_j \\otimes \\e_j^{\\Reals^n} )$,\nthe linear map from $\\Reals^n \\mapsto \\Vspace$,\nwhose 'columns' are the $\\v_j$.\nLet $\\b = \\left( \\b_0 \\ldots \\b_{n-1} \\right) \\in \\Reals^n$\nbe the unconstrained vector of the first $n$ barycentric coordinates.\nFor $\\q \\in \\affine_span ( S )$, $\\q = \\Vmap \\b + \\p_m$\nand $\\b = \\Vmap^{-1} \\left ( \\q - \\p_m \\right)$.\nFor arbitrary $\\q \\in \\Vspace$,\n$\\b = \\Vmap^{-} (\\q - \\p_m)$\n(see \\autoref{sec:Inverses-and-pseudo-inverses}).\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "75baf9f018a8ed13291034d44fc25f4feb33ee77", "size": 1985, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/barycentric-coordinates.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/barycentric-coordinates.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/barycentric-coordinates.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": 33.0833333333, "max_line_length": 79, "alphanum_fraction": 0.6695214106, "num_tokens": 683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8840392878563336, "lm_q1q2_score": 0.7772002738725785}}
{"text": "\\section{Fundamentals of Hypothesis Testing}\\label{S:HypTest}\n%This section is under Jazz-\\work\\\\{\\scriptsize [and will evolve from face-to-face interactions with students of mathematics at Uppsala University]}.\n\nThe subset of {\\bf all posable hypotheses} that remain {\\bf falsifiable} is the space of {\\bf scientific hypotheses}.  Roughly, a falsifiable hypothesis is one for which a statistical experiment can be designed to produce data that an experimenter can use to falsify or reject it.  In the statistical decision problem of hypothesis testing, we are interested in empirically falsifying a scientific hypothesis, i.e.~we attempt to reject an hypothesis on the basis of empirical observations or data.  Thus, hypothesis testing has its roots in the philosophy of science and is based on Karl Popper's falsifiability criterion for demarcating scientific hypotheses from the set of all posable hypotheses.\n\n\\subsection{Introduction}\\label{S:HypTestIntro}\nUsually, the hypothesis we attempt to reject or falsify is called the {\\bf null hypothesis} or $H_0$ and its complement is called the {\\bf alternative hypothesis} or $H_1$.  For example, consider the following two hypotheses:\n\n$H_0$:  The average waiting time at an Orbiter bus stop is less than or equal to $10$ minutes.\\\\\n$H_1$:  The average waiting time at an Orbiter bus stop is more than $10$ minutes.\n\nIf the sample mean $\\overline{x}_n$ is much larger than $10$ minutes then we may be inclined to reject the null hypothesis that the average waiting time is less than or equal to $10$ minutes.  We will learn to formally test hypotheses in the sequel.\n\nSuppose we are interested in the following hypothesis test for the bus-stop  problem:\n\n$H_0$:  The average waiting time at an Orbiter bus stop is equal to $10$ minutes.\\\\\n$H_1$:  The average waiting time at an Orbiter bus stop is not $10$ minutes.\n\nOnce again we can use the sample mean as the test statistic.  Our procedure for rejecting this null hypothesis is different and is often called the Wald test.\n\n%\\section{Parametric Hypothesis Testing}\n\nMore generally, suppose $X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} F(x_1;\\theta^*)$, with an unknown and fixed $\\theta^* \\in \\BB{\\Theta}$.  Let us partition the parameter space $\\BB{\\Theta}$ into $\\BB{\\Theta}_0$, the null parameter space, and $\\BB{\\Theta}_1$, the alternative parameter space, ie,\n$$\\BB{\\Theta}_0 \\cup \\BB{\\Theta}_1 = \\BB{\\Theta}, \\qquad \\text{and} \\qquad \\BB{\\Theta}_0 \\cap \\BB{\\Theta}_1 = \\emptyset \\ .$$\nThen, we can formalise testing the null hypothesis versus the alternative as follows:\n\\[\nH_0 : \\theta^* \\in \\BB{\\Theta}_0 \\qquad \\text{versus} \\qquad H_1 :  \\theta^* \\subset \\BB{\\Theta}_1 \\ .\n\\]\nThe basic idea involves finding an appropriate rejection region $\\Xz_R$ within the data space $\\Xz$ and rejecting $H_0$ if the observed data $x:=(x_1,x_2,\\ldots,x_n)$ falls inside the rejection region $\\Xz_R$,\n\\[\n\\text{If $x:=(x_1,x_2,\\ldots,x_n) \\in \\Xz_R \\subset \\Xz$, then reject $H_0$, else do not reject $H_0$.} \n\\]\nTypically, the rejection region $\\Xz_R$ is of the form:\n\\[\n\\Xz_R := \\{ x:=(x_1,x_2,\\ldots,x_n)  : T(x) > c \\}\n\\]\nwhere, $T$ is the {\\bf test statistic} and $c$ is the {\\bf critical value}.  Thus, the problem of finding $\\Xz_R$ boils down to that of finding $T$ and $c$ that are appropriate.  Once the rejection region is defined, the possible outcomes of a hypothesis test are summarised in the following table.\n\\begin{table}[htbp]\n\\begin{center}\n\\caption{Outcomes of an hypothesis test.}\n\\begin{tabular}{c|c|c}\\hline\n& Do not Reject $H_0$ & Reject $H_0$ \\\\ \\hline\n$H_0$ is True & OK & Type I Error \\\\ \\hline\n$H_1$ is True & Type II Error & OK \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\begin{definition}[Power, Size and Level of a Test]\nThe {\\bf power function} of a test with rejection region $\\Xz_R$ is\n\\begin{equation}\\label{E:power}\n\\beta(\\theta) := \\P_{\\theta}(x \\in \\Xz_R) \\ .\n\\end{equation}\nSo $\\beta(\\theta)$ is the power of the test at the parameter value $\\theta$, i.e.~the probability that the observed data $x$, sampled from the distribution specified by $\\theta$, falls in $\\Xz_R$ and thereby leads to a rejection of the null hypothesis.\n\nThe $\\mathsf{size}$ of a test with rejection region $\\Xz_R$ is the supreme power under the null hypothesis, i.e.~the supreme probability of rejecting the null hypothesis when the null hypothesis is true:\n\\begin{equation}\\label{E:size}\n\\mathsf{size} := \\sup_{\\theta \\in \\BB{\\Theta}_0} \\beta(\\theta) := \\sup_{\\theta \\in \\BB{\\Theta}_0} \\P_{\\theta}(x \\in \\Xz_R) \\ .\n\\end{equation}\nThe $\\mathsf{size}$ of a test is often denoted by $\\alpha$.  A test is said to have $\\mathsf{level}$ $\\alpha$ if its $\\mathsf{size}$ is less than or equal to $\\alpha$.\n\\end{definition}\nLet us familiarize ourselves with some terminology in hypothesis testing next.\n\\begin{table}[htbp]\n\\begin{center}\n\\caption{Some terminology in hypothesis testing.}\n\\begin{tabular}{c|c|c}\\hline\n$\\BB{\\Theta}$ & Test: $H_0$ versus $H_1$ & Nomenclature \\\\ \\hline\n$\\BB{\\Theta} \\subset \\Rz^m, m \\geq 1$ & $H_0: \\theta^* = \\theta_0$ versus $H_1: \\theta^* \\neq \\theta_1$ & Simple Hypothesis Test \\\\ \\hline\n$\\BB{\\Theta} \\subset \\Rz^m, m \\geq 1$ & $H_0: \\theta^* \\in \\BB{\\Theta}_0$ versus $H_1: \\theta^* \\in \\BB{\\Theta}_1 $ & Composite Hypothesis Test \\\\ \\hline\n$\\BB{\\Theta} \\subset \\Rz^1$ & $H_0: \\theta^* = \\theta_0$ versus $H_1: \\theta^* \\neq \\theta_0$ & Two-sided Hypothesis Test \\\\ \\hline\n$\\BB{\\Theta} \\subset \\Rz^1$ & $H_0: \\theta^* \\geq \\theta_0$ versus $H_1: \\theta^* < \\theta_0$ & One-sided Hypothesis Test \\\\ \\hline\n$\\BB{\\Theta} \\subset \\Rz^1$ & $H_0: \\theta^* \\leq \\theta_0$ versus $H_1: \\theta^* > \\theta_0$ & One-sided Hypothesis Test \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\nWe introduce some widely used tests next.\n\n\\subsection{The Wald Test}\\label{S:WaldTest}\nThe Wald test is based on a direct relationship between the $1-\\alpha$ confidence interval and a $\\mathsf{size}$ $\\alpha$ test.  It can be used for testing simple hypotheses involving a scalar parameter.\n\\begin{definition}[The Wald Test]\nLet $\\widehat{\\Theta}_n$ be an asymptotically normal estimator of the fixed and possibly unknown parameter $\\theta^* \\in \\BB{\\Theta} \\subset \\Rz$ in the parametric IID experiment:\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} F(x_1;\\theta^*) \\enspace .\n\\] \nConsider testing:\n\\[\nH_0: \\theta^* = \\theta_0 \\qquad \\text{versus} \\qquad H_1: \\theta^* \\neq \\theta_0 \\enspace .\n\\]\nSuppose that the null hypothesis is true and the estimator $\\widehat{\\Theta}_n$ of $\\theta^*=\\theta_0$ is asymptotically normal:\n\\[\n\\theta^*=\\theta_0, \\qquad \\frac{\\widehat{\\Theta}_n - \\theta_0}{\\widehat{\\mathsf{se}}_n} \\rightsquigarrow \\normal(0,1) \\enspace .\n\\]\nThen, the Wald test based on the test statistic $W$ is:\n\\[\n\\boxed{\n\\text{Reject $H_0$ when $|W|>z_{\\alpha/2}$, where $W:=W((X_1,\\ldots,X_n))=\\frac{\\widehat{\\Theta}_n ((X_1,\\ldots,X_n)) - \\theta_0}{\\widehat{\\mathsf{se}}_n}$.\n}\n}\n\\]\nThe rejection region for the Wald test is:\n\\[\n\\boxed{\n\\Xz_R = \\{ x:=(x_1,\\ldots,x_n) : |W (x_1,\\ldots,x_n) | > z_{\\alpha/2} \\} \\enspace .\n}\n\\]\n\\end{definition}\n\\begin{prop}[Asymptotic $\\mathsf{size}$ of a Wald test]\nAs the sample size $n$ approaches infinity, the $\\mathsf{size}$ of the Wald test approaches $\\alpha$ :\n\\[\n\\boxed{\n\\mathsf{size} = \\P_{\\theta_0} \\left( |W| > z_{\\alpha/2} \\right) \\to \\alpha \\enspace .}\n\\]\n\\end{prop}\n\\begin{proof}\nLet $Z \\sim \\normal(0,1)$.  The $\\mathsf{size}$ of the Wald test, i.e.~the supreme power under $H_0$ is:\n\\begin{flalign*}\n\\mathsf{size} \n& := \\sup_{\\theta \\in \\BB{\\Theta}_0} \\beta(\\theta) := \\sup_{\\theta \\in \\{\\theta_0\\}} \\P_{\\theta}(x \\in \\Xz_R) = \\P_{\\theta_0}(x \\in \\Xz_R) \\\\\n& = \\P_{\\theta_0} \\left( |W| > z_{\\alpha/2} \\right)  = \\P_{\\theta_0} \\left( \\frac{|\\widehat{\\theta}_n - \\theta_0|}{\\widehat{\\mathsf{se}}_n} > z_{\\alpha/2} \\right) \\\\\n& \\to \\P \\left( |Z| > z_{\\alpha/2} \\right)\\\\\n& = \\alpha \\enspace .\n\\end{flalign*}\n\\end{proof}\nNext, let us look at the power of the Wald test when the null hypothesis is false.\n\\begin{prop}[Asymptotic power of a Wald test]\nSuppose $\\theta^* \\neq \\theta_0$.  The power $\\beta(\\theta^*)$, which is the probability of correctly rejecting the null hypothesis, is approximately equal to:\n\\[\n\\boxed{\n\\Phi \\left( \\frac{\\theta_0-\\theta^*}{\\widehat{\\mathsf{se}}_n} - z_{\\alpha/2} \\right) +\n\\left( 1- \\Phi \\left( \\frac{\\theta_0-\\theta^*}{\\widehat{\\mathsf{se}}_n} + z_{\\alpha/2} \\right) \\right) \\enspace ,\n}\n\\]\nwhere, $\\Phi$ is the DF of $\\normal(0,1)$ RV.  Since ${\\widehat{\\mathsf{se}}_n} \\to 0$ as $n \\to 0$ the power increase with sample $\\mathsf{size}$ $n$.  Also, the power increases when $|\\theta_0-\\theta^*|$ is large. \n\\end{prop}\nNow, let us make the connection between the $\\mathsf{size}$ $\\alpha$ Wald test and the $1-\\alpha$ confidence interval explicit.\n\\begin{prop}[The $\\mathsf{size}$ Wald test]\nThe $\\mathsf{size}$ $\\alpha$ Wald test rejects:\n\\[\n\\boxed{\n\\text{ $H_0: \\theta^*=\\theta_0$ versus $H_1: \\theta^* \\neq \\theta_0$ if and only if $\\theta_0 \\notin C_n := (\\widehat{\\theta}_n-{\\widehat{\\mathsf{se}}_n} z_{\\alpha/2}, \\widehat{\\theta}_n+{\\widehat{\\mathsf{se}}_n} z_{\\alpha/2})$.\n}}\n\\]\nTherefore, testing the hypothesis is equivalent to verifying whether the null value $\\theta_0$ is in the confidence interval.\n\\end{prop}\n\\begin{example}[Wald test for the mean waiting times at our Orbiter bus-stop]\nLet us use the Wald test to attempt to reject the null hypothesis that the mean waiting time at our Orbiter bus-stop is $10$ minutes under an IID $\\exponential(\\lambda^*)$ model.  Let $\\alpha=0.05$ for this test.  We can formulate this test as follows:\n\\[\nH_0: \\lambda^* = \\lambda_0= \\frac{1}{10} \\quad \\text{versus} \\quad H_1: \\lambda^* \\neq \\frac{1}{10}, \\quad \\text{where, } \\quad X_1\\ldots,X_{132} \\overset{IID}{\\sim} \\exponential(\\lambda^*) \\enspace .\n\\]\nBased on \\hyperref[EX:ExponentialFisherInfo]{Example~\\ref*{EX:ExponentialFisherInfo}} and \\hyperref[LW:ExponentialMLECIOrbiter]{Labwork~\\ref*{LW:ExponentialMLECIOrbiter}} we obtained the $95\\%$ confidence interval to be $[0.0914, 0.1290]$. Since our null value $\\lambda_0=0.1$ belongs to this confidence interval, we fail to reject the null hypothesis from a $\\mathsf{size}$ $\\alpha=0.05$ Wald test.\n\\end{example}\n\nWe can use bootstrap-based confidence interval $C_n$ in conjunction with Wald test as shown by the next example.\n\n\\begin{example}[Wald test of the bootstrapped correlation coefficient]\nRecall the problem of estimating the confidence interval for the correlation coefficient between the LSAT scores ($Y_1,\\ldots,Y_{15}$) and the GPA ($Z_1,\\ldots,Z_{15}$) in \\hyperref[LW:LSATGPACorrBoot]{Labwork~\\ref*{LW:LSATGPACorrBoot}}.  We assumed that the bivariate data $(Y_i,Z_i) \\overset{IID}{\\sim} F^*$, such that $F^* \\in \\{ \\text{all bivariate DFs} \\}$. Suppose we are interested in testing the null hypothesis that the true correlation coefficient $\\theta^*$ is $0$:\n\\[\nH_0: \\theta^* = \\theta_0 = 0 \\quad \\text{versus} \\quad H_1: \\theta^* \\neq 0, \\quad \\text{where} \\quad  \\theta^* = \\frac{\\int \\int (y-\\E(Y))(z-\\E(Z))dF(y,z)}{\\sqrt{\\int (y-\\E(Y))^2 dF(y) \\int (z-\\E(Z))^2 dF(z)}} \\enspace .\n\\]\nSince the percentile-based $95\\%$ bootstrap confidence interval for the plug-in estimate of the correlation coefficient from \\hyperref[LW:LSATGPACorrBoot]{Labwork~\\ref*{LW:LSATGPACorrBoot}} was $[0.2346, 0.9296]$ and this interval does not contain $0$, we can reject the null hypothesis that the correlation coefficient is $0$ using a $\\mathsf{size}$ $\\alpha=0.05$ Wald test.\n\\end{example}\n\n\\subsection{A Composite Hypothesis Test}\nOften, we are interested in a testing a composite hypothesis, i.e.~one in which  the null hypothesis is not a singleton set.  We revisit the Orbiter waiting time problem from this perspective next.\n\\begin{figure}[htpb]\n\\caption{Plot of power function $\\beta(\\lambda)$ for different values of the critical value $c$ and the $\\mathsf{size}$ $\\alpha$ as function of the critical values.\n\\label{F:ExponentialTestOrbiter}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/ExponentialTestOrbiter}}\n\\end{figure}\n\n\\begin{example}[Testing the Mean Waiting Time at an Orbiter Bus-stop]\nLet us test the following null hypothesis $H_0$.\n\n$H_0$:  The average waiting time at an Orbiter bus stop is less than or equal to $10$ minutes.\\\\\n$H_1$:  The average waiting time at an Orbiter bus stop is more than $10$ minutes.\n\nWe have observations of $n=132$ waiting times $x_1,x_2,\\ldots,x_{132}$ at the Orbter bus-stop with $\\overline{x}_{132}=9.0758$.  Let us assume a parametric model, say,\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\exponential(\\lambda^*)\n\\]\nwith an unknown and fixed $\\lambda^* \\in \\BB{\\Lambda}=(0,\\infty)$.  Since the parameter $\\lambda$ of an $\\exponential(\\lambda)$ RV is the reciprocal of the mean waiting time, we can formalise the above hypothesis testing problem of $H_0$ versus $H_1$ as follows:\n\\[\nH_0 : \\lambda^* \\in \\BB{\\Lambda}_0 = [1/10,\\infty) \\qquad \\text{versus} \\qquad H_1 :  \\lambda^* \\in \\BB{\\Lambda}_1 = (0,1/10) \n\\]\nConsider the test:\n\\[\n\\text{Reject $H_0$ if $T>c$.}\n\\] \nwhere the test statistic $T=\\overline{X}_n$ and the rejection region is:\n\\[\n\\Xz_R = \\{ (x_1,x_2,\\ldots,x_n) : T(x_1,x_2,\\ldots,x_n) > c \\} \\enspace .\n\\]\nSince the sum of $n$ IID $\\exponential(\\lambda)$ RVs is $\\gammA(\\lambda,n)$ distributed, the power function is:\n\\begin{flalign*}\n\\beta(\\lambda) &= \\P_{\\lambda} \\left(\\overline{X}_n > c \\right) = \\P_{\\lambda}\\left(\\sum_{i=1}^n{X_i} > nc \\right) = 1- \\P_{\\lambda}\\left(\\sum_{i=1}^n{X_i} \\leq nc \\right)\\\\\n&= 1 - F\\left( nc; \\lambda, n \\right) \n= 1- \\frac{1}{\\Gamma(n)}\\int_0^{\\lambda n c} y^{n-1} \\exp(-y) dy \\\\\n&= 1- {\\tt gammainc}(\\lambda n c, n)\n\\end{flalign*}\nClearly, $\\beta(\\lambda)$ is a decreasing function of $\\lambda$ as shown in \\hyperref[F:ExponentialMLECIOrbiter]{Figure~\\ref*{F:ExponentialTestOrbiter}}.  Hence the $\\mathsf{size}$ of the test as a function of the critical region specified by the critical value $c$ is:\n\\begin{flalign*}\n\\mathsf{size} \n&= \\sup_{\\lambda \\in \\BB{\\Lambda}_0} \\beta(\\lambda)\n= \\sup_{\\lambda \\geq 1/10} \\beta(\\lambda)=\\beta(1/10)=1- {\\tt gammainc}(132 c/10, 132)\n\\end{flalign*}\nFor a $\\mathsf{size}$ $\\alpha=0.05$ test we numerically solve for the critical value $c$ that satisfies: $$0.05=1- {\\tt gammainc}(132 c/10, 132)$$ by trial and error as follows:\n\\begin{VrbM}\n>> lambda0=1/10\nlambda0 =    0.1000\n>> S=@(C)(1-gammainc(lambda0*n*C,n)); % size as a function of c\n>> Cs=[10 11 11.474 12 13] % some critical values c\nCs =   10.0000   11.0000   11.4740   12.0000   13.0000\n>> Size=arrayfun(S,Cs) % corresponding size\nSize =    0.4884    0.1268    0.0499    0.0143    0.0007\n\\end{VrbM}  \nThus, we reject $H_0$ when $\\overline{X}_n>11.4740$ for a level $\\alpha=0.05$ test.  Since our observed test statistic $\\overline{x}_{132}=9.0758 < 11.4740$ we fail to reject the null hypothesis that the mean waiting time is less than or equal to $10$ minutes.  Therefore, there is no evidence that the Orbiter bus company is violating its promise of an average waiting time of no more than $10$ minutes.\n\\end{example}\n\n\n\n\\subsection{p-values}\\label{S:p-values}\nIt is desirable to have a more informative decision than simply reporting \"reject $H_0$'' or ``fail to reject $H_0$.''  For instance, we could ask whether the test rejects $H_0$ for each $\\mathsf{size}=\\alpha$.  Typically, if the test rejects at $\\mathsf{size}$ $\\alpha$ it will also reject at a larger $\\mathsf{size}$ $\\alpha' > \\alpha$.  Therefore, there is a smallest $\\mathsf{size}$ $\\alpha$ at which the test rejects $H_0$ and we call this $\\alpha$ the $\\pvalue$ of the test.\n\n\\begin{figure}[h]\n\\caption{The smallest $\\alpha$ at which a $\\mathsf{size}$ $\\alpha$ test rejects the null hypothesis $H_0$ is the $\\pvalue$.}\\label{F:pvalue}\n\\begin{center}\n\\fbox{\n\\setlength{\\unitlength}{1mm}\n\\begin{picture}(130,50)(0,-2)\n\\thicklines\n\\put(10,30){\\fbox{Reject $H_0$?~}}\n\\put(30,10){{No~}}\n\\put(30,40){{Yes~}}\n\n\\put(40,5){\\vector(0,1){40}}\n\\put(40,5){\\vector(1,0){70}}\n\\put(59,4){$\\bullet$}\n\\put(70,15){\\vector(-1,-1){10}}\n\\put(70,15){$\\pvalue$}\n\n\\put(40,1){$0$}\n\\put(90,1){$1$}\n\\put(65,-1){$\\mathsf{size}$}\n\n\\put(40,10){\\line(1,0){20}}\n\\put(60,10){\\line(0,1){30}}\n\\put(60,40){\\line(1,0){30}}\n\n\\end{picture}\n}\n\\end{center}\n\\end{figure}\n\n\\begin{definition}[p-value]\nSuppose that for every $\\alpha \\in (0,1)$ we have a $\\mathsf{size}$ $\\alpha$ test with rejection region $\\Xz_{R,\\alpha}$ and test statistic $T$.  Then,\n\\[\n\\pvalue := \\inf \\{ \\alpha: T(X) \\in \\Xz_{R,\\alpha} \\} \\enspace .\n\\]\nThat is, the $\\pvalue$ is the smallest $\\alpha$ at which a $\\mathsf{size}$ $\\alpha$ test rejects the null hypothesis.\n\\end{definition}\n\nIf the evidence against $H_0$ is strong then the $\\pvalue$ will be small.  However, a large $\\pvalue$ is not strong evidence in favour of $H_0$.  This is because a large $\\pvalue$ can occur for two reasons:\n\\begin{enumerate}\n\\item $H_0$ is true.\n\\item $H_0$ is false but the test has low power.\n\\end{enumerate}\nFinally, it is important to realise that $\\pvalue$ is not the probability that the null hypothesis is true, i.e.~$\\pvalue \\neq \\P(H_0|x)$, where $x$ is the data.  The following tabulation of evidence scale is useful.\n\\begin{table}\n\\caption{Evidence scale against the null hypothesis in terms of the range of $\\pvalue$.}\\label{T:pvalueEvidenceScale}\n\\begin{center}\n\\begin{tabular}{|c|c|}\n\\hline\n$\\pvalue$ range & Evidence \\\\ \\hline\n$(0, 0.01]$ & very strong evidence against $H_0$\\\\\n$(0.01, 0.05]$ & strong evidence against $H_0$\\\\\n$(0.05, 0.1]$ & weak evidence against $H_0$\\\\\n$(0.1,1)$ & little or no evidence against $H_0$\\\\\n\\hline\n\\end{tabular}\n\\end{center} \n\\end{table}\nThe next proposition gives a convenient expression for the $\\pvalue$ for certain tests.\n\\begin{prop}[The $\\pvalue$ of a hypothesis test]\nSuppose that the $\\mathsf{size}$ $\\alpha$ test based on the test statistic $T$ and critical value $c_{\\alpha}$ is of the form:\n\\[\n\\text{Reject $H_0$ if and only if $T:=T((X_1,\\ldots,X_n))> c_{\\alpha}$,}\n\\]\nthen\n\\[\n\\pvalue = \\sup_{\\theta \\in \\BB{\\Theta}_0} \\P_{\\theta}(T((X_1,\\ldots,X_n)) \\geq t:=T((x_1,\\ldots,x_n))) \\enspace ,\n\\]\nwhere, $(x_1,\\ldots,x_n)$ is the observed data and $t$ is the observed value of the test statistic $T$.  In words, the $\\pvalue$ is the supreme probability under $H_0$ of observing a value of the test statistic the same as or more extreme than what was actually observed.\n\\end{prop}\nLet us revisit the Orbiter waiting times example from the $\\pvalue$ perspective.\n\\begin{example}[$\\pvalue$ for the parametric Orbiter experiment]\nLet the waiting times at our bus-stop be $X_1,X_2,\\ldots,X_{132} \\overset{IID}{\\sim} \\exponential(\\lambda^*)$.  Consider the following testing problem:\n\\[\nH_0: \\lambda^*=\\lambda_0=\\frac{1}{10} \\quad \\text{versus} \\quad H_1: \\lambda^* \\neq \\lambda_0 \\enspace .\n\\]\nWe already saw that the Wald test statistic is:\n\\[\nW:=W(X_1,\\ldots,X_n)= \\frac{\\widehat{\\Lambda}_n-\\lambda_0}{\\widehat{\\mathsf{se}}_n(\\widehat{\\Lambda}_n)} = \\frac{\\frac{1}{\\overline{X}_n}-\\lambda_0}{\\frac{1}{\\sqrt{n}\\overline{X}_n}} \\enspace .\n\\]\nThe observed test statistic is:\n\\[\nw=W(x_1,\\ldots,x_{132})=\n\\frac{\\frac{1}{\\overline{X}_{132}}-\\lambda_0}{\\frac{1}{\\sqrt{132}\\overline{X}_{132}}}\n= \\frac{\\frac{1}{9.0758}-\\frac{1}{10}}{\\frac{1}{\\sqrt{132} \\times 9.0758}} = 1.0618 \\enspace .\n\\]\nSince, $W \\rightsquigarrow Z \\sim \\normal(0,1)$, the $\\pvalue$ for this Wald test is:\n\\begin{flalign*}\n\\pvalue \n&= \\sup_{\\lambda \\in \\BB{\\Lambda}_0} \\P_{\\lambda} (|W|>|w|)= \\sup_{\\lambda \\in \\{\\lambda_0\\}} \\P_{\\lambda} (|W|>|w|) =  \\P_{\\lambda_0} (|W|>|w|) \\\\\n& \\to \\P (|Z|>|w|)=2 \\Phi(-|w|)=2 \\Phi(-|1.0618|)=2 \\times 0.1442=0.2884 \\enspace .\n\\end{flalign*}\nTherefore, there is little or no evidence against $H_0$ that the mean waiting time under an IID $\\exponential$ model of inter-arrival times is exactly ten minutes.\n\\end{example}\n%\\section{Parametric Bootstrap-based Test}\n\n\\subsection{Permutation Test for the equality of any two DFs}\\label{S:PermTest}\n\nPermutation test is a non-parametric exact method for testing whether two distributions are the same.  It is non-parametric because we do not impose any restrictions on the class of DFs that the unknown DF should belong to.  It is exact because we do not have any asymptotic approximations involving sample size approaching infinity.  So this test works for any sample size.\n\nFormally, we suppose that:\n\\[\nX_1,X_2,\\ldots,X_m \\overset{IID}{\\sim} F^* \\quad \\text{and} \\quad X_{m+1}, X_{m+2},\\ldots,X_{m+n} \\overset{IID}{\\sim} G^* \\enspace ,\n\\]\nare two sets of independent samples.  The possibly unknown DFs $F^*,G^* \\in \\{ \\text{all DFs} \\}$.  Now, consider the following hypothesis test:\n\\[\nH_0: F^*=G^* \\quad \\text{versus} \\quad H_1: F^* \\neq G^* \\enspace .\n\\]\nLet our test statistic $T(X_1,\\ldots,X_m,X_{m+1},\\ldots,X_{m+n})$ be some sensible one -- $T$ is large when $F^*$ is too different from $G^*$, say:\n\\[\nT:=T(X_1,\\ldots,X_m,X_{m+1},\\ldots,X_{m+n})= \\abs \\left( \\frac{1}{m} \\sum_{i=1}^m X_i -  \\frac{1}{n} \\sum_{i=m+1}^n X_i  \\right) \\enspace .\n\\]\nThen the idea of a permutation test is as follows:\n\\begin{enumerate}\n\\item Let $N:=m+n$ be the pooled sample size and consider all $N!$ permutations of the observed data $x_{\\mathsf{obs}}:=(x_1,x_2,\\ldots,x_m,x_{m+1},x_{m+2},\\ldots,x_{m+n})$.\n\\item For each permutation of the data compute the statistic $T(\\text{permuted data $x$})$ and denote these $N!$ values of $T$ by $t_1,t_2,\\ldots,t_{N!}$.\n\\item Under $H_0: X_1,\\ldots,X_m,X_{m+1},\\ldots,X_{m+n} \\overset{IID}{\\sim}F^*=G^*$, each of the permutations of $x= (x_1,x_2,\\ldots,x_m,x_{m+1},x_{m+2},\\ldots,x_{m+n})$ has the same joint probability $\\prod_{i=1}^{m+n} f(x_i)$, where $f(x_i)=dF(x_i)=dG(x_i)$.  Therefore, the transformation of the data by our statistic $T$ also has the same probability over the values of $T$, namely $\\{t_1,t_2,\\ldots,t_{N!}\\}$.  Let $\\P_0$ be this permutation distribution that is dicrete and uniform over  $\\{t_1,t_2,\\ldots,t_{N!}\\}$.\n\\item Let $t_{\\mathsf{obs}} := T(x_{\\mathsf{obs}})$ be the observed value of the statistic.\n\\item Assuming we reject $H_0$ when $T$ is large, the $\\pvalue$ is:\n\\[\n\\pvalue = \\P_0 \\left( T \\geq t_{\\mathsf{obs}} \\right) = \\frac{1}{N!} \\left( \\sum_{j=1}^{N!} \\BB{1} (t_j  \\geq t_{\\mathsf{obs}}) \\right), \\qquad  \\BB{1} (t_j \\geq t_{\\mathsf{obs}}) =\n\\begin{cases}\n1 & \\text{if } \\quad t_j \\geq t_{\\mathsf{obs}} \\\\\n0 & \\text{otherwise} \n\\end{cases}\n\\]\n\\end{enumerate}\n\nLet us look at a small example involving the diameters of coarse venus shells ({\\em Dosinia anus}) that Guo Yaozong and Chen Shun found on the left and right sides of the New Brighton prier in Spring 2007.  We are interested in testing the hypothesis that the distribution of shell diameters for this bivalve species is the same on both sides of the pier.  \n\\begin{example}[Guo-Chen Experiment with Venus Shell Diameters]\nLet us look at the first two samples $x_1$ and $x_2$ from the left of pier and the first sample from the right side of pier, namely $x_3$.  Since the permutation test is exact, we can use this small data set with merely three samples to conduct the following hypothesis test:\n\\[\nH_0: X_1,X_2,X_3 \\overset{IID}{\\sim} F^*=G^*, \\qquad H_1: X_1,X_2 \\overset{IID}{\\sim} F^*, X_3 \\overset{IID}{\\sim} G^*, \\quad F^* \\neq G^* \\enspace .\n\\] \nLet us use the test statistic:\n\\[\nT(X_1,X_2,X_3)=\\abs \\left( \\frac{1}{2} \\sum_{i=1}^2 X_i -  \\frac{1}{1} \\sum_{i=2+1}^3 X_i  \\right)=\\abs \\left( \\frac{X_1+x_2}{2} -  \\frac{X_3}{1} \\right) \\enspace .\n\\]\nThe data giving the shell diameters in millimetres and $t_{\\mathsf{obs}}$ are:\n\\[\n(x_1,x_2,x_3) = (52,54,58) \\quad \\text{and} \\quad t_{\\mathsf{obs}}=\\abs \\left( \\frac{52+54}{2} - \\frac{58}{1} \\right) = \\abs (53-58) = \\abs(-5)=5 \\enspace .\n\\]\nLet us tabulate the $(2+1)!=3!=3\\times2\\times1=6$ permutations of the data $(x_1,x_2,x_3) = (52,54,58)$, the corresponding values of $T$ and their probabilities under the null hypothesis, i.e., the permutation distribution $\\P_0(T)$.\n\\begin{center}\n\\begin{tabular}{c c c}\n\\hline\nPermutation & $t$ & $\\P_0(T=t)$ \\\\ \\hline\n$(52,54,58)$ & $5$ & $\\frac{1}{6}$ \\\\\n$(54,52,58)$ & $5$ & $\\frac{1}{6}$  \\\\\n$(52,58,54)$ & $1$ & $\\frac{1}{6}$  \\\\\n$(58,52,54)$ & $1$ &$\\frac{1}{6}$  \\\\\n$(58,54,52)$ & $4$ & $\\frac{1}{6}$  \\\\\n$(54,58,52)$ & $4$ & $\\frac{1}{6}$  \\\\ \\hline\n\\end{tabular}\n\\end{center}\nFrom the table, we get:\n\\[\n\\pvalue = \\P_0 \\left( T \\geq t_{\\mathsf{obs}}\\right) =  \\P_0 \\left( T \\geq 5 \\right) = \\frac{1}{6}+ \\frac{1}{6}= \\frac{2}{6}= \\frac{1}{3} \\approxeq 0.333 \\enspace . \n\\]\nTherefore, there is little to no evidence against $H_0$.\n\\end{example}\n\nWhen the pooled sample size $N=m+n$ gets large, $N!$ would be too numerous to tabulate exhaustively.  In this situation, we can use a Monte Carlo approximation of the $\\pvalue$ by generating a large number of random permutations of the data according to the following Steps:\n\n\\begin{enumerate}\n\\item[\\sf{Step 1}:] Compute the observed statistic $t_{\\mathsf{obs}} := T(x_{\\mathsf{obs}})$ of data $x_{\\mathsf{obs}}:=(x_1,\\ldots,x_m,x_{m+1},\\ldots,x_{m+n})$.\n\\item[\\sf{Step 2}:] Randomly permute the data and compute the statistic again from the permuted data.\n\\item[\\sf{Step 3}:] Repeat {\\sf Step 2} $B$ times and let $t_1,\\ldots,t_B$ denote the resulting values ($B$ is large, say $1000$).\n\\item[\\sf{Step 4}:] The (Monte Carlo) approximate $\\pvalue$ is:\n\\[\n\\frac{1}{B} \\sum_{j=1}^B \\BB{1}(t_j \\geq t_{\\mathsf{obs}} ) \\enspace .\n\\]\n\\end{enumerate}\nNext we implement the above algorithm on the full data set of Guo and Chen obtained from coarse venus shells sampled from the two sides of the New Brighton pier. \n\\begin{labwork}[Approximate $\\pvalue$ of a permutation test of shell diameters]\\label{LW:Shells}\nTest the null hypothesis that the distribution of the diameters of coarse venus shells are the same on both sides of the New Brighton pier. \n\\VrbMf[label=Shells.m]{scripts/Shells.m}\nWhen we execute the script to perform a permutation test and approximate the $\\pvalue$, we obtain:\n\\begin{VrbM}\n>> Shells\nApproxPValue =    0.8576\n\\end{VrbM}\nTherefore, there is little or no evidence against the null hypothesis.\n\\end{labwork}\n\n\\subsection{Pearson's Chi-Square Test for Multinomial Trials}\\label{S:Chi2}\n\nWe derive the $\\chisquare$ distribution introduced by Karl Pearson in 1900 [{\\em Philosophical Magazine}, Series 5, {\\bf 50}, 157-175].  This historical work laid the foundations of modern statistics by showing why an experimenter cannot simply plot experimental data and just assert the correctness of his or her hypothesis.  This derivation is adapted from Donald E.~Knuth's treatment [{\\em Art of Computer Programming, Vol.~II, Seminumerical Algorithms}, 3rd Ed., 1997, pp.~55-56].  We show how $\\demoivre$, $\\multinomial$, $\\poisson$ and the $\\normal$ random vectors conspire to creare the $\\chisquare$ random variable.\n\n{\\em Part 1: \\demoivre~trials}\\\\\nConsider $n$ independent and identically distributed $\\demoivre (\\theta_1,\\ldots,\\theta_k)$ random vectors (\\rv s):\n\\[\nX_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\demoivre (\\theta_1,\\ldots,\\theta_k) \\enspace .\n\\]\nRecall from \\hyperref[M:deMoivreRVec]{Model~\\ref*{M:deMoivreRVec}} that $X_1 \\sim \\demoivre (\\theta_1,\\ldots,\\theta_k)$ means $\\P(X_1=e_i)=\\theta_i$ for $i\\in\\{1,\\ldots,k\\}$, where $e_1,\\ldots,e_k$ are ortho-normal basis vectors in $\\Rz^k$. \nThus, for each $i \\in \\{1,2,\\ldots,n\\}$, the corresponding  $X_i$ has $k$ components, i.e.~$X_i:=(X_{i,1},X_{i,2},\\ldots,X_{i,k})$.\n\n{\\em Part 2: \\multinomial~trial}\\\\\nSuppose we are only interested in the experiment induced by their sum:\n\\[\nY := (Y_1,\\ldots,Y_k) := \\sum_{i=1}^n X_i :=  \\sum_{i=1}^n (X_{i,1},X_{i,2},\\ldots,X_{i,k}) = \\left( \\sum_{i=1}^n X_{i,1}, \\sum_{i=1}^n X_{i,2},\\ldots, \\sum_{i=1}^n X_{i,k} \\right) \\enspace .\n\\]\nThe \\rv~$Y$, being the sum of $n$ IID $\\demoivre(\\theta_1,\\ldots,\\theta_k)$ \\rv s, is the $\\multinomial(n,\\theta_1,\\ldots,\\theta_k)$ \\rv~of  \\hyperref[M:Multinomial]{Model~\\ref*{M:Multinomial}} and the probability that $Y:=(Y_1,\\ldots,Y_k) = y := (y_1,\\ldots,y_k)$ is:\n\\[\n \\frac{n!}{y_1! y_2! \\cdots y_k!} \\prod_{i=1}^k \\theta_i^{y_i} \\enspace .\n\\]\nThe support of the \\rv~$Y$, i.e.~the set of possible realisations of $y:= (y_1,\\ldots,y_k)$ is:\n\\[\n\\Yz := \\{ (y_1,\\ldots,y_k) \\in \\Zz_+^k : \\sum_{i=1}^k y_i = n \\} \\enspace .\n\\]\n{\\em Part 3: Conditional sum of \\poisson~trials}\\\\\nHere we consider an alternative formulation of the $\\multinomial(n,\\theta_1,\\ldots,\\theta_k)$ \\rv~$Y$.  Suppose,\n\\[\nY_1 \\sim \\poisson(n \\theta_1), Y_2 \\sim \\poisson(n \\theta_2), \\ldots, Y_k \\sim \\poisson(n \\theta_k) \\enspace ,\n\\]\nand that $Y_1,\\ldots,Y_k$ are independent.  Recall from \\hyperref[M:Poisson]{Model~\\ref*{M:Poisson}} that $Y_i \\sim \\poisson(n\\theta_i)$ means $\\P(Y_i=y_i)=e^{-n\\theta_i} (n\\theta_i)^{y_i}/y_i!$ for $y_i \\in \\{0,1,\\ldots\\}$.  Then, the joint probability probability of the \\rv~$(Y_1,\\ldots,Y_k)$ is the product of the independent $\\poisson$ probabilities:\n\\begin{flalign*}\n\\P\\left( (Y_1,\\ldots,Y_k) = (y_1,\\ldots,y_k) \\right) \n&:= \\P \\left( Y_1=y_1,\\ldots,Y_k=y_k \\right) \n= \\prod_{i=1}^k \\P(Y_i=y_i) = \\prod_{i=1}^k{ \\frac{e^{-n\\theta_i} (n\\theta_i)^{y_i}}{y_i!} } \\\\\n& \n= \\frac{ \\prod_{i=1}^k e^{-n\\theta_i} n^{y_i} \\theta_i^{y_i}}{ \\prod_{i=1}^k{ y_i!} }\n=\\left(e^{-n \\sum_{i=1}^k \\theta_i} n^{\\sum_{i=1}^k y_i} \\prod_{i=1}^k \\theta_i^{y_i}\\right) \\frac{1}{ \\prod_{i=1}^k{ y_i!} } \\\\\n& =  \\frac{  e^{-n} n^{n} \\prod_{i=1}^k \\theta_i^{y_i}}{ \\prod_{i=1}^k{ y_i!} }\n\\enspace .\n\\end{flalign*}\nNow, the probability that sum $Y_1+\\cdots+Y_k$ will equal $n$ is obtained by summing over the probabilities of all $(y_1,\\ldots,y_k) \\in \\Yz$:\n\\begin{flalign*}\n\\P\\left(\\sum_{i=1}^k Y_i = n \\right)\n& = \\sum_{\\substack{(y_1,\\ldots,y_k)\\\\ \\in\\Yz}}  \\P\\left( (Y_1,\\ldots,Y_k) = (y_1,\\ldots,y_k) \\right) =  \\sum_{\\substack{(y_1,\\ldots,y_k)\\\\ \\in\\Yz}}  \\frac{  e^{-n} n^{n} \\prod_{i=1}^k \\theta_i^{y_i}}{ \\prod_{i=1}^k{ y_i!} } \\\\\n& = e^{-n} n^{n} \\frac{1}{n!} \n\\underset {=\\P(\\Yz)=1}{\\underbrace{\\left( \\sum_{\\substack{(y_1,\\ldots,y_k)\\\\ \\in\\Yz}}   \\frac{n!}{ \\prod_{i=1}^k{ y_i!} } \\prod_{i=1}^k \\theta_i^{y_i} \\right)}} = \\frac{e^{-n} n^{n}}{n!}\n\\enspace .\n\\end{flalign*}\nFinally, the conditional probability that $(Y_1,\\ldots,Y_k)=(y_1,\\ldots,y_k)$ given $\\sum_{i=1}^k Y_i = n$ is:\n\\begin{multline*}\n\\P \\left( (Y_1,\\ldots,Y_k)=(y_1,\\ldots,y_k) \\vert \\sum_{i=1}^k Y_i = n \\right) = \n\\frac{\\P \\left( (Y_1,\\ldots,Y_k)=(y_1,\\ldots,y_k) , \\sum_{i=1}^k Y_i = n \\right)}{\\P \\left( \\sum_{i=1}^k Y_i = n \\right) } \\\\\n= \\frac{\\P \\left( (Y_1,\\ldots,Y_k)=(y_1,\\ldots,y_k) \\right)}{\\P \\left( \\sum_{i=1}^k Y_i = n \\right) } \n= \\frac{  e^{-n} n^{n} \\prod_{i=1}^k \\theta_i^{y_i}}{ \\prod_{i=1}^k{ y_i!} } \\frac{n!} {e^{-n} n^{n}} =  \\frac{n!}{y_1! y_2! \\cdots y_k!} \\prod_{i=1}^k \\theta_i^{y_i} \\enspace .\n\\end{multline*}\nTherefore, we may also think of the random vector $Y:=(Y_1,\\ldots,Y_k) \\sim \\multinomial(n,\\theta_1,\\ldots,\\theta_k)$ as $k$ independent $\\poisson$ random variables, $Y_1 \\sim \\poisson(n \\theta_1), \\ldots, Y_k \\sim \\poisson(n \\theta_k)$, that have been conditioned on their sum $\\sum_{i=1}^nY_i$ being $n$.\n\n{\\em Part 4: The $\\normal$ approximation of the centred and scaled $\\poisson$}\\\\\nRecall from \\hyperref[M:Poisson]{Model~\\ref*{M:Poisson}} that the expectation and variance of a RV $Y_i \\sim \\poisson(n\\theta_i)$ are $\\E(Y_i)=\\V(Y_i)=n\\theta_i$.  Let $Z_i$ be $\\E(Y_i)$-centred and $\\sqrt{\\V(Y_i)}$-scaled $Y_i$ and \\[\nZ_i :=  \\frac{Y_i - \\E(Y_i)}{\\sqrt{\\V(Y_i)}} = \\frac{Y_i - n \\theta_i}{\\sqrt{n \\theta_i}} \\enspace .\n\\]\nThe condition that $Y_1+\\cdots+Y_k=n$ is equivalent to requiring that $\\sqrt{\\theta_1} Z_1 +\\cdots+\\sqrt{\\theta_k} Z_k = 0$, since:\n\\begin{multline*}\n\\sum_{i=1}^k {Y_i} =n \n\\iff \\sum_{i=1}^k {Y_i} -n = 0\n\\iff \\sum_{i=1}^k {Y_i} - n \\sum_{i=1}^k {\\theta_i} = 0\n\\iff \\sum_{i=1}^k {Y_i - n \\theta_i} = 0 \\\\\n\\iff \\sum_{i=1}^k  \\frac{Y_i - n \\theta_i}{\\sqrt{n }} = 0\n\\iff \\sum_{i=1}^k \\sqrt{\\theta_i} \\frac{Y_i - n \\theta_i}{\\sqrt{n \\theta_i}} = 0\n\\iff \\sum_{i=1}^k \\sqrt{\\theta_i} Z_i = 0 \\enspace .\n\\end{multline*}\nNow consider the support of the \\rv~$Z:=(Z_1,\\ldots,Z_k)$ conditioned on $\\sum_{i=1}^k \\sqrt{\\theta_i} Z_i = 0$, i.e.~the hyper-plane of $(k-1)$-dimensional vectors:\n\\[\n\\Hz := \\{ (z_1,\\ldots,z_k) : \\sqrt{\\theta_1} z_1 +\\cdots+\\sqrt{\\theta_k} z_k = 0 \\} \n\\]\nEach $Z_i \\rightsquigarrow \\normal(0,1)$ by the central limit theorem.  Therefore, for large values of $n$, each $Z_i$ is approximately distributed as the $\\normal(0,1)$ RV with PDF $f(z_i;0,1)=(2\\pi)^{-1/2}\\exp(-z_i^2/2)$.  Since the $Z_i$s are independent except for the condition that they lie in $\\Hz$, the point in a differential volume $dz_2\\ldots dz_k$ of $\\Hz$ occur with probability approximately proportional to:\n \\[\n \\exp(-z_1^2/2) \\times \\cdots \\times \\exp(-z_k^2/2)  = \\exp(-(z_1^2+\\cdots+z_k^2)/2)\n \\]\n\n{\\em Part 5: $\\chisquare$ distribution as the sum of squared $\\normal$s}\\\\\nWe are interested in the sum of the area of squares with side-lengths $Z_1,\\ldots,Z_k$.  Let $V$ be the desired sum of squares:\n\\[\n\\qquad V := \\sum_{i=1}^k Z_i^2 =  \\sum_{i=1}^k \\frac{\\left(Y_i - n \\theta_i \\right)^2}{{n \\theta_i}}  , \\quad \\text{such that} \\quad Z_i \\rightsquigarrow \\normal(0,1), \\quad \\sum_{i=1}^k \\sqrt{\\theta_i} Z_i = 0 \\enspace .\n\\]\nThe probability that $V \\leq v$ as $n \\to \\infty$ is:\n\\[\n\\frac{\\int_{\\substack{(z_1,\\ldots,z_k) \\in \\Hz \\ \\text{and} \\ \\sum_{i=1}^k{z_i^2} \\leq v}} \\exp(-(z_1^2+\\cdots+z_k^2)/2) \\ dz_2\\ldots dz_k} {\\int_{\\substack{(z_1,\\ldots,z_k) \\in \\Hz}} \\exp(-(z_1^2+\\cdots+z_k^2)/2) \\ dz_2\\ldots dz_k}\n\\]\nSince the $(k-1)$-dimensional hyper-plane $\\Hz$ passes through the origin of  $\\Rz^k$, the domain of integration in the numerator above is the interior of a $(k-1)$-dimensional hyper-sphere of radius $\\sqrt{v}$ that is centred at the origin.  Using a transformation of the above ratio of integrals into generalised polar co-ordinates with radius $\\chi$  and angles $\\alpha_1,\\ldots,\\alpha_{k-2}$, we get:\n\\[\n\\frac{\\int_{\\chi^2\\leq v} \\exp(-\\chi^2/2) \\chi^{k-2} g(\\alpha_1,\\ldots,\\alpha_{k-2}) d \\chi d \\alpha_1\\cdots d \\alpha_{k-2}} {\\int \\exp(-\\chi^2/2) \\chi^{k-2} g(\\alpha_1,\\ldots,\\alpha_{k-2}) d \\chi d \\alpha_1\\cdots d \\alpha_{k-2}} \\enspace ,\n\\]\nfor some function $g$ of the angles [See Problem 15 in {\\em Art of Computer Programming, Vol.~II, Seminumerical Algorithms}, 3rd Ed., 1997, pp.~59].   The integration over the $(k-2)$ angles results in the same factor that cancels between the numerator and the denominator.  This yields the formula for the probability that $V \\leq v$ as $n \\rightarrow \\infty$:\n\\[\n\\lim_{n \\to \\infty} \\P(V \\leq v) =  \\frac{\\int_0^{\\sqrt{v}}\\exp(-\\chi^2/2) \\chi^{k-2} d \\chi} {\\int_0^{\\infty}\\exp(-\\chi^2/2) \\chi^{k-2} \\ d \\chi} \\enspace .\n\\]  \nBy substituting $t=\\chi^2/2$, we can express the integrals in terms of the incomplete Gamma function defined as $\\gamma(a,x) :=  \\int_0^{a} \\exp(-t) t^{a-1} \\ dt$ as follows:\n\\[\n\\P(V \\leq v) = \\gamma \\left( \\frac{k-1}{2},\\frac{v}{2} \\right) / \\Gamma \\left(\\frac{k-1}{2} \\right) \\enspace .\n\\]\nThis is the DF of the $\\chisquare$ distribution with $k-1$ degrees of freedom.\n\n\\begin{model}[$\\chisquare(k)$ RV]  Given a parameter $k \\in \\Nz$ called degrees of freedom, we say that $V$ is a $\\chisquare(k)$ RV if its PDF is:\n\\[\nf(v; k) :=  \\frac{v^{(k/2)-1}e^{-v/2}}{2^{k/2}\\Gamma(k/2)} \\BB{1}_{\\{v \\in \\Rz: v>0\\}}(v)\n\\]\nAlso, $\\E(V)=k$ and $\\V(V) = 2k$.\n\\end{model}\n\nWe can use the {\\bf Pearson's Chi-Square test statistic}: \n\\begin{equation}\\label{PearsonsChiSquaredTestStat}\nT:= T(Y_1,\\ldots,Y_k) = \\frac{\\left(Y_1 - n \\theta^*_1 \\right)^2}{n \\theta^*_1}+\\cdots+\\frac{\\left(Y_k - n \\theta^*_k \\right)^2}{n \\theta^*_k}\n\\end{equation}\nto test the null hypothesis $H_0$ that may be formalised in three equivalent ways:\n\\begin{flalign*}\n& H_0: X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} \\demoivre(\\theta_1^*,\\ldots,\\theta_k^*)~\\rv \\\\\n\\iff \n& H_0:\nY:= (Y_1,\\ldots,Y_k) = \\sum_{i=1}^n X_i \\sim \\multinomial(n,\\theta_1^*,\\ldots,\\theta_k^*)~\\rv \\\\\n\\iff \n& H_0:\nY_1 \\overset{IND}{\\sim} \\poisson(n\\theta_1)~\\mbox{RV},\\ldots,Y_k \\overset{IND}{\\sim} \\poisson(n\\theta_k)~\\mbox{RV} \\ \\text{given that} \\ \\sum_{i=1}^k Y_i = n\n\\end{flalign*}\n\nWe have seen that under $H_0$, the test statistic $T \\rightsquigarrow V \\sim \\chisquare(k-1)$.  Let $t_{\\mathsf{obs}}$ be the observed value of the test statistic and let the upper alpha quantile be $\\chi^2_{k-1,\\alpha} := F^{[-1]}(1-\\alpha)$, where $F$ is the CDF of $V \\sim \\chisquare(k-1)$.  Hence the test:\n\\[\n\\boxed{\n\\text{Reject $H_0$ if $T > \\chi^2_{k-1,\\alpha}$ is an asymptotically $\\mathsf{size}$ $\\alpha$ test and the $\\pvalue = \\P(V > t_{obs})$.}\n}\n\\]\n\nNow, let us look at a concrete example of Perason's Chi-Square test.\n\nGregor Johann Mendel (1822--1884) was a scientist and an abbot. \nMendel gained posthumous recognition as the founder of the modern science of genetics. \nThough it has been known for millennia that crossbreeding of plants and animals could favour specific desirable traits, Mendel's pea plant experiments conducted between 1856 and 1863 was the first to empirically establish many of the rules of heredity. \nThese rules are now known as the {\\em laws of Mendelian inheritance}. Let's look at an experiment performed by Medel to test a null hypothesis on the rules of inheritance.\n\n\\begin{example}[Medel's Peas]\nMendel bred two varieties of peas. The first variety had round yellow seeds and the second one had wrinkled green seeds. \nThe progeny of this breeding experiment were of four types: round yellow, wrinkled yellow, round green, and wrinkled green. \nLet us assume that the number of each type of progeny is a $\\multinomial(n,\\theta)$ RV $X$ with probability $\\theta = (\\theta_1,\\theta_2,\\theta_3,\\theta_4) \\in \\Delta^3$.  \nMendel's theory of inheritance predicts that $\\theta = \\theta_0$,\n\\[\n\\theta_0 = (\\theta_{0,1}, \\theta_{0,2}, \\theta_{0,3}, \\theta_{0,4}) = \\left( \\frac{9}{16}, \\frac{3}{16}, \\frac{3}{16}, \\frac{1}{16} \\right)\n\\]\nHe obtained $n=556$ progeny out of which he observed $X = (315,101,108,32)$. \n\nHere, we will test the null hypothesis $H_0: \\theta = \\theta_0$ versus $H_1: \\theta \\neq \\theta_0$ using Pearson's Chi-Square test statistic \\eqref{PearsonsChiSquaredTestStat}.\n\nSince $n \\theta_{0,1} = 556 \\frac{9}{16} = 312.75$, $n \\theta_{0,2} = n \\theta_{0,3} = 556 \\frac{3}{16} = 104.25$, and $n \\theta_{0,4} = 556 \\frac{1}{16} = 34.75$, the test statistic is:\n\\[\nT = \\sum_{j=1}^4 \\frac{(X_j - n \\theta_{0,j})^2}{n \\theta_{0,j}} = \n\\frac{(315-312.75)^2}{312.75} + \\frac{(101-104.25)^2}{104.25} + \\frac{(108-104.25)^2}{104.25} + \\frac{(32-34.75)^2}{34.75} = 0.47\n\\]\nFor $\\alpha=0.05$, the $\\chi^2_{3,\\alpha}$ value is $7.815$ --- this can be ontained numerically or from a table of $\\chisquare$ distribution with $3$ degrees of freedom. \nSince the observed test statistic $0.47$ is not larger than $\\chi^2_{3,\\alpha}=7.815$, we do not reject the null hypothesis. \nWith $T \\sim \\chisquare(3)$ under the null hypothesis, the $\\pvalue$ is\n\\[\n\\pvalue = \\P ( T > 0.47) = 0.93\n\\]\nwhich is little to no evidence against the null hypothesis. \nTherefore, the data do not contradict Medel's theory of inheritance.\n\\end{example}\n\n\\newpage\n\n%\\section{Kolmogorov-Smirnov Test for continuous DF $F$}\n\n", "meta": {"hexsha": "625427b415c173e5a955845f99a45e492b69c43d", "size": 39015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/HypothesisTesting.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/HypothesisTesting.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/HypothesisTesting.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.1514629948, "max_line_length": 699, "alphanum_fraction": 0.6803024478, "num_tokens": 14119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7772002701269964}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section{Algorithms}\n\nEuclid's algorithm (Algorithm E)\n\nGiven two positive integers $n$ and $m$, find their GCD.\n\n\\begin{enumerate}\n  \\item If $m < n$, switch $m \\longleftrightarrow n$.\n  \\item Divide $m$ by $n$ and let $r$ be the remainder.\n  \\item If $r = 0$ then the algorithm terminates and $n$ from Step 2 is the answer.\n  \\item If $r \\neq 0$, set $m \\leftarrow n$ and $n \\leftarrow r$, then go to Step 2.\n\\end{enumerate}\n\nA sketch of a formal definition of an algorithm:\n\nA \\emph{computational method} is a quadruple $(Q,I,\\Omega,f)$, where\n\\begin{itemize}\n  \\item $I\\subset Q$ is the \\emph{input}\n  \\item $\\Omega \\subset Q$ is the \\emph{output}\n  \\item $f : Q \\rightarrow Q$ is the \\emph{computational rule}, which satisfies $f(\\omega) = \\omega\\ \\forall \\omega \\in \\Omega$.\n\\end{itemize}\n\nEach $x\\in I$ defines a \\emph{computational sequence} $x_0,x_1,\\dots,$, where $x_0=x$ and $x_{k+1} = f(x_k)$. The sequence \\emph{terminates} in $k$ steps if $k$ is the smallest integer such that $x_k \\in \\Omega$. An \\emph{algorithm} is a computational method that terminates in some finite number of steps for all $x$ in $I$.\n\nAs an example, we present Euclid's algorithm in this formalization: let $Q$ be the set of all singletons $\\{n\\}$, all ordered pairs $(m,n)$, and all ordered quadruples $(m,n,r,1),(m,n,r,2),(m,n,p,3)$ where $m,n,p$ are positive integers and $r$ is a nonnegative integer. Let $I$ be the ordered pairs $(m,n)$ and $\\Omega$ the set of singletons $\\{n\\}$. Define $f$ by\n\n\\begin{align*}\n  f((m,n)) = (m,n,0,1);\\ f((n)) = (n); \\\\\n  f((m,n,r,1)) = (m,n, m\\ \\% \\ n, 2); \\\\\n  f((m,n,r,2)) = (n)\\ \\mathrm{if}\\ r=0,\\ (m,n,r,3)\\ \\mathrm{otherwise}; \\\\\n  f((m,n,p,3)) = (n,p,p,1)\n\\end{align*}\n \n\nNote that this definition of an algorithm doensn't include any notions of effectiveness - i.e., the ability for the algorithm to be performed with constituent elementary operations (compass-and-straightedge, MIX instructions, etc). We introduce a ``programming'' notion of effectiveness as follows: let $A$ be a finite set of letters, and let $A^*$ be the set of all strings on $A$. Let $N$ be a nonnegative integer and $Q$ be the set of all $(\\sigma,j)$ with $\\sigma \\in A^*$ and $j$ is an integer such that $0\\leq j \\leq N$. Let $I \\subset J$ be the subset of $J$ where $j=0$ and $\\Omega$ be the subset of $J$ where $j=N$. If $\\theta,\\sigma \\in A^*$, we say that $\\theta$ occurs in $\\sigma$ if there exists $\\alpha,\\omega\\in A^* $ such that $\\sigma = \\alpha\\theta\\omega$ (under string concatenation). Finally, let $f$ be a function defined by the strings $\\theta_j$ and $\\phi_j$, and the integers $a_j$ and $b_j$, for each $0\\leq j \\leq N$:\n\n\\begin{flalign*}\n  f((\\sigma,j)) = (\\sigma,a_j) && \\text{if}\\ \\sigma_j\\ \\text{does not occur in}\\ \\theta \\\\\n  f((\\sigma,j)) = (\\alpha\\phi_j\\omega,b_j) && \\text{if}\\ \\alpha\\ \\text{is the shortest possible string such that}\\ \\sigma=\\alpha\\theta_j\\omega \\\\\n  f((\\sigma,N)) = (\\sigma,N)\n\\end{flalign*}\n\n\\section{Algorithms - solutions to exercises}\n\\\n\\indent \\textbf{1.1.1} $t \\leftarrow a$, $a \\leftarrow b$, $b \\leftarrow c$, $c \\leftarrow d$, $d\\leftarrow t$.\n\n\\\n\n\\textbf{1.1.2} We have $m \\leftarrow n$ and $n \\leftarrow r$. Since $r < n$, after assignment $n < m$.\n\n\\\n\n\\textbf{1.1.3} \\textbf{Algorithm F}. Given two positive integers $m$ and $n$, find the greatest common divisor.\n\n\\ \\textbf{F1} Divide $m$ by $n$.\n\n\\ \\textbf{F2} Set $m$ equal to the remainder.\n\n\\ \\textbf{F3} If $m=0$ then the answer is $n$.\n \n\\ \\textbf{F4} Otherwise divide $n$ by $m$.\n\n\\ \\textbf{F5} Set $n$ equal to the remainder.\n\n\\ \\textbf{F6} If $n=0$ then the answer is $m$.\n\n\\ \\textbf{F7} Go to \\textbf{F1}.\n\n\\\n\\textbf{1.1.4} $6099 \\% 2166 = 1767 \\Rightarrow 2166 \\% 1767 = 399$\n\n$\\Rightarrow 1767 \\%  399 = 171 \\Rightarrow 399 \\$ 171 = 57 \\Rightarrow 171 \\% 57 = 0$.\n\nSo the GCD is 57.\n\\  \n\n\\textbf{1.1.5} Not finite, not definite, not effective.\n\n\\textbf{1.1.6}\n$n=1$: $1 \\% 5 = 1 \\Rightarrow 5 \\% 1 = 0$, 2 steps \n\n$n=2$: $2 \\% 5 = 2 \\Rightarrow 5 \\% 2 = 1 \\Rightarrow 2 \\% 1 = 0$, 3 steps\n\n$n=3$: $3 \\% 5 = 3 \\Rightarrow 5 \\% 3 = 2 \\Rightarrow 3 \\% 2 = 1 \\Rightarrow 2 \\%1 = 0$, 4 steps\n\n$n=4$: $4 \\% 5 = 4 \\Rightarrow 5 \\% 4 = 4 \\Rightarrow 4 \\% 4 = 0$, 3 steps \n\n$n=5$: $5 \\% 5 = 0$, 1 step\n\nSo $T_5 = 2.6$.\n\n\\\n\\textbf{1.1.7} $U_m$ is well-defined: if $n > m$, the first step of the Euclidean algorithm simply swaps $n$ and $m$ (since $m\\ \\%\\ n = m$) and $U_m = T_m + 1$. If $n < m$ then there are only finitely many cases.\n\n\\textbf{1.1.8} \\textbf{Note: I was a bit confused by this presentation and checked the answers.} Find the GCD of $n$ and $m$, given an alphabet containing $a$ and $b$ and an input $a^m b^n$.\n\nOur intent is to translate Euclid's algorithm, using the hint provided:\n\\begin{enumerate}\n  \\item Set $r \\leftarrow |m - n|$ and $n \\leftarrow \\mathrm{min}(m,n)$\n  \\item If $r = 0$ then $m = n$ and $n$ is the GCD of $m$ and $n$, so the algorithm terminates.\n  \\item Otherwise set $m \\leftarrow n$ and $n \\leftarrow r$ and go to Step 1.\n\\end{enumerate}\n\nWe first prove that this is in fact the GCD. If $g$ is the GCD of $m$ and $n$, then either $g = n$ or $g < n$. The first case is correct handled by Step 2. Otherwise, in step 3, $g$ is clearly the GCD of $\\min(m,n)$ and by hypothesis $m\\neq n$. Suppose $m>n$; then $m - n = ag - bg = g(a - b)$ for some $0 < b < a$ where $g$ does not share any factors with $a$ or $b$ and $g > a,b$. Therefore $g$ is the GCD of $r$ as well. \n\nTo translate this algorithm into the formalism, we will need an alphabet character, $c$, to represent the remainder. Phrasing the algorithm as words:\n\\begin{enumerate}\n  \\item Start with $a^m b^n$.\n  \\item Remove $n$ $b$s from the right and $n$ $a$s from the left, then append $n$ $c$s to the left.\n  \\item There are $|m-n|$ $a$s left over (aka $r$ from above) and $n$ $c$s to the left of the $a$s.\n  \\item If $m=n$ then there are no $a$s and the number of $c$s (aka $m$ and $n$ is the GCD.\n  \\item Otherwise swap the $a$s with $b$s and the $c$s with $a$s, then repeat.\n\\end{enumerate}\n\nThis faithfully reproduces the algorithm above. Therefore, in the formalism,\n\n\\textbf{1.1.9}\n\n\\section{Mathematical Preliminaries - Induction}\nAlgorithmic proof procedure:\n\n\\textbf{Algorithm I - Construct a proof} Given a positive integer $n$ and proposition $P(n)$, this algorithm will output a proof that $P(n)$ is true (if it succeeds).\n\n\\textbf{I1} [Prove $P(1)$] Set $k \\leftarrow 1$ and use another algorithm to output a proof of $P(1)$.\n\n\\textbf{I2} [$k=n$?] If $k=n$, terminate - the required proof was found in the previous step.\n\n\\textbf{I3} [$k<n$] Otherwise $k<n$. Use another algorithm to output a proof of the following statement: ``If $P(1)$, $P(2)$,$\\dots$,$P(k)$ is true, then $P(k+1)$ is true.'' Then output the statement ``We have already proved $P(1),\\dots,P(k)$, hence $P(k+1)$ is true.'' Combine these statements.\n\n\\textbf{I4} Set $k \\leftarrow k + 1$. Go to step \\textbf{I2}.\n\nHere is an inductive proof of a fact about the Fibonacci sequence. Let $F_0 = 0,F_1=1$ and $F_n = F_{n-1} + F_{n-2}$ for $n\\geq 2$. Define $\\phi = (1 + \\sqrt{5})/2$. Then $F_n \\leq \\phi^{n-1}$ for all positive $n$.\n\nWe proceed according to the algorithm above. This is clearly true for $n=0$ and $n=1$,l so we have obtained a proof of $P(1)$. For $P(2)$, $F_2 = 1$ and $\\phi > 1.6$, so we have a (computational) proof of $P(2)$. Now assume our target is $k+1$ with $k>1$ and we have $k$ proofs $P(1),\\dots,P(k)$. Since $F_{k+1} = F_k + F_{k-1}$, and by hypothesis $F_k \\leq \\phi^{k-1}$ and $F_{k-1} \\leq \\phi^{k-2}$,\n\n\\begin{equation}\n  F_{k+1} \\leq \\phi^{k-1} + \\phi^{k-2} = \\phi^{k-2}(1+\\phi).\n\\end{equation}\n\n$\\phi$ is actually the positive solution to $1 + \\phi = \\phi^2$. So plugging this in gives $F_{k+1} \\leq \\phi^k$, as desired.\n\nNote that our proof would have failed if we didn't have direct proofs of $P(1)$ and $P(2)$: $P(1)$ would fail at the inductive step since the theorem is not true for $n=0$, and for $P(2)$ we couldn't have applied the method at the $F_{k-1} \\leq \\phi^{k-2}$ step (since $k=1$).\n\n\\section{Mathematical Induction - Exercises}\n\n\\indent \\textbf{1.2.1} The base case $n=0$, then prove $P(0),P(1),dots,P(n)$ implies $P(n+1)$.\n\n\\textbf{1.2.2} The proof uses this formula:\n\n\\begin{equation*}\n  a^{(n+1)-1} = \\frac{(a^{n-1})(a^{n-1})}{(a^{(n-2)/(n-1)})^{n-1}}\n\\end{equation*}\n\nbut this formula is not valid for $n=1$. So the proof used in the base case can't be used with this formula in the inductive step.\n   \n\\textbf{1.2.3} Since there are $n-1$ terms in the expansion, the formula is not valid at $n=1$ and ``clearly $3/2 - 1/n = 1/2$'' is not actually a valid reading of the formula.\n\n\\textbf{1.2.4} \n\n\\end{document}\n", "meta": {"hexsha": "18dfb5e48a31d8eb7bf19a30c52906ce07c2742f", "size": 8731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TAoCP/Volume1/BasicConcepts.tex", "max_stars_repo_name": "nicklecompte/CSLearning", "max_stars_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "TAoCP/Volume1/BasicConcepts.tex", "max_issues_repo_name": "nicklecompte/CSLearning", "max_issues_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TAoCP/Volume1/BasicConcepts.tex", "max_forks_repo_name": "nicklecompte/CSLearning", "max_forks_repo_head_hexsha": "34fadc2d36068016cab66a4cc0e57c933f21c300", "max_forks_repo_licenses": ["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.2814371257, "max_line_length": 942, "alphanum_fraction": 0.6482648036, "num_tokens": 3122, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898178450964, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7771291626050637}}
{"text": "%TODOs for this lab\n%1. May merge with ImgSegMST\n\n\\lab{Algorithm}{Image Segmentation with Minimal Spanning Trees}{Image Segmentation with Minimal Spanning Trees}\n\\label{Ch:MSTImgSeg}\n\n\\objective{This section teaches about how to use minimum spanning trees to segment an image.}\n\n\\section*{Image Segmentation}\n\n%Lab \\ref{MSTImgSeg}\n\nOne application of Minimal Spanning Trees (MSTs) is image segmentation.\nKruskal's algorithm is especially good at this.\nYou can convert an image into graph. Each pixel is a vertex and you define weights between the nodes. You then build the minimal spanning tree. If you take away the edge with the greatest weight you will get two forests (removing an edge from any graph with no cycles will create two forests). Then you can continue doing this to each forest to split up those forests. Each forest corresponds to a segment of the image.\nLet $k$ be the number of divisions that is wanted and $n$ be the number of nodes.\nKruskal's algorithm is performed until $n-(k+1)$ edges are added which is the same as taking out the $k$ edges with greatest weights.\n\nThere are many different ways to turn an image into a graph and weight the edges.\nA simple, yet effective, version is to make every pixel a node and the edges are the difference in intensities in the four cardinal directions. \n\n\nThis means that there are less than $4n$ edges.\nOther image segmentation algorithms have to use $n^2$ space.\nThis gives the MST algorithm a critical advantage over other image segmentation algorithms. \n\n\\begin{problem}\nWrite a function that takes a black and white image as input and outputs a list of the edges and a list of nodes.\nStore the edges using the form \\li{(node,node,weight)}.\n\\end{problem}\n\nThe provided Kruskal's algorithm takes as inputs the list of nodes, the list of edges and the number of divisions desired.\nThe number of divisions often has to be higher than the actual number that is needed because sometimes one or two pixels form a division because the difference between them and the pixels around them is so great.\nYou will have to adjust the number of divisions until the desired result is found.  See Figure 9.1.\n\n\\begin{problem}\nPerform the image segmentation algorithm on the image, then graph the original image and the three largest divisions.\n(Use the Counter class from collections to find the number of pixels in each division.) \n\\end{problem}\n\n\\begin{problem}\nMake a division of the image a different color.\n\\end{problem}\n\nThis algorithm can also be extended to 3D images.\nOne way to do this is to make each pixel a node and have the edges run in the eight cardinal directions, i.e. the pixel directly above it, the pixel below it, etc.\n\nThis algorithm can also be used to segment other data such as connections on Facebook. \n\n\\vfill\n\\begin{figure}[ht]\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg1.jpg}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg2.jpg}\n\\end{minipage}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg3.jpg}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.47\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{MSTseg4.jpg}\n\\end{minipage}\n\\caption{The original image is in the top left hand corner. The three larges segments are shown in the other corners. The original image was 498x498 and 50000 divisions were used.}\n\\end{figure}\n\\vfill\n", "meta": {"hexsha": "181923f34993e54b408b204cb1f52e0176e9771d", "size": 3477, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/ImageSegMST/ImgSegMST.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/ImageSegMST/ImgSegMST.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/ImageSegMST/ImgSegMST.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.6301369863, "max_line_length": 419, "alphanum_fraction": 0.7840092033, "num_tokens": 862, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774768002981829, "lm_q2_score": 0.8856314858927012, "lm_q1q2_score": 0.7771210824844528}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\n\\title{Sum of Finite Geometric Series}\n\\author{Steven Xia}\n\n\n\\begin{document}\n\\maketitle\n\n\\section{Statement}\n$$\\sum_{k=0}^n b^k = \\frac{b^{n+1} - 1}{b - 1}$$\n\n\\section{Proof}\n\n\\subsection{Verification by Intuition}\nWritten in base $b$, $b^k$ is represented as a one followed by $k$ zeroes.\nAs such, the sum in the statement above is represented as $n+1$ ones in base $b$.\n\nContinuing, $b^{n+1}$ is represented as a one followed by $n+2$ zeroes.\nThis means that $b^{n+1} - 1$ is represented as $n+1$ characters representing the value of $b - 1$ (in the case of base ten, this character would be nine).\nFinally, dividing the number by $b-1$ results in $n+1$ ones, which is equal to the value of the sum as shown initially.\n\n\\subsection{Proof by Induction}\n\nThe base case, $n=0$, is trivial; both sides evaluate to 1.\n\n\\subsubsection{Inductive step: $n\\geq1$}\n\\begin{align}\n    \\frac{b^{n+1} - 1}{b - 1} &= \\frac{b^n - 1}{b - 1} + b^n \\\\\n                              &= \\frac{b^n - 1 + (b - 1)b^n}{b - 1} \\\\\n                              &= \\frac{(1 + (b - 1))b^n - 1}{b - 1} \\\\\n                              &= \\frac{(b)b^n - 1}{b - 1} \\\\\n                              &= \\frac{b^{n+1} - 1}{b - 1}\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "97cd0184cb99b3e19ce3968f38d163a9338620b6", "size": 1273, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics/FiniteSum.tex", "max_stars_repo_name": "xtevenx/archive", "max_stars_repo_head_hexsha": "69dc0d50b568f1a752b49cdb2df34d2ff5c41b3c", "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": "Mathematics/FiniteSum.tex", "max_issues_repo_name": "xtevenx/archive", "max_issues_repo_head_hexsha": "69dc0d50b568f1a752b49cdb2df34d2ff5c41b3c", "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": "Mathematics/FiniteSum.tex", "max_forks_repo_name": "xtevenx/archive", "max_forks_repo_head_hexsha": "69dc0d50b568f1a752b49cdb2df34d2ff5c41b3c", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.641025641, "max_line_length": 155, "alphanum_fraction": 0.5805184603, "num_tokens": 427, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8774767986961403, "lm_q1q2_score": 0.7771210731193042}}
{"text": "\\lab{Algorithms}{Eigenvalue Solvers And Markov Chains}{Eigenvalue Solvers And Markov Chains}\n\\objective{Implement the QR algorithm for finding eigenvalues and learn Markov chains.}\n\\label{lab:EigSolve}\n\n\\section*{Eigenvalues are hard to find}\nFinding the eigenvalues of $n \\times n$ matrix $A$ means solving the following equation, where $x$ is a nonzero vector and $\\lambda$ is a scalar.\n\\begin{align}\nA x &= \\lambda x \\notag \\\\\nA x - \\lambda x &= 0 \\notag \\\\\n(A - \\lambda I)x  &= 0 \\label{eq:singularity}\n\\end{align}\nSince $x$ is nonzero, \\eqref{eq:singularity} means $A-\\lambda I$ must be singular.\nThus $\\det(A - \\lambda I) = 0$.  This determinant is often notated $\\det(A - \\lambda I) = p(\\lambda)$ and is called the \\emph{characteristic polynomial} of $A$.\nThe roots of the characteristic polynomial are the eigenvalues of $A$.\n\nIf $A$ is $n \\times n$, the degree of $p(\\lambda)$ is  $n$.\nFinding the roots is easy for small $n$, but it becomes difficult or impossible as $n$ increases.\nAbel's Theorem  outlines the problem.\n\n\\begin{theorem}[Abel's Impossibility Theorem]\nThere is no general algebraic solution for solving a polynomial equation of degree $n>4$.\n\\label{thm:Abel}\n\\end{theorem}\n\nTherefore, there is no method that will exactly find the eigenvalues of an arbitrary matrix.\nThis is a significant result. \nIn practice it means that we often rely on iterative methods, which converge to the eigenvalues.\n\n\\section*{The Power Method}\nThere are many such iterative methods for finding eigenvalues. \nThe Power Method is a simple fast way to find the largest eigenvalue and eigenvector. \nYou begin with a vector $x_0$, that has norm 1, and do the iteration.\n\\[\nx_{k+1}=\\frac{Ax_k}{\\norm{Ax_k}}\n\\]\nit works when\n\\begin{itemize}\n\\item The matrix $A$ has a eigenvalue that is strictly greater in magnitude than its other eigenvectors.\n\\item your starting vector $x_0$ has a nonzero component in the direction of the eigenvector of the dominant eigenvalue.\n\\end{itemize}\n\nThis often converges slowly (geometric with the ration given by $\\norm{\\lambda_2/\\lambda_1}$ but is especially useful when your matrix has all positive values because you are guaranteed to have a dominant eigenvalue and the modulus of dominant eigenvalue is often much greater than the rest of the eigenvalues so the convergence is much faster.\nWhenever you have an eigenvector you can compute its corresponding eigenvalue using the Rayleigh quotient\n\\[\n\\lambda = \\frac{Ax\\cdot x}{x\\cdot x}\n\\]\nThe down side is that it only finds the largest eigenvector and eigenvalue. The next algorithm finds more eigenvalues.\n\\begin{problem}\nWrite a method that takes a in matrix and a tolerance and computes its largest eigenvalue and the eigenvector. \nHave your starting vector be random. \nUse the two-norm and have the iteration stop when the maximun change of the vector is less than the tolerance. \nTest your function on positive matrices.\n\\end{problem}\n\n\\begin{comment}\nAn overview of the proof of the method is that you can write a matrix in Jordan Conical form $A=VJV^{-1}$ where $V$ is the matrix of the generalized eigenspaces. \nBut the first column is is the eigenvector corresponding to largest eigenvalue and $J$ is a upper trianglar matrix of eigenvalues and ones.\nNote that $A^k=VJ^kV^{-1}$. The limit as $k \\rightarrow \\infty$ of $(\\frac{1}{\\lambda_1}J)^k$ is a matrix of all zeros except for a one in the upper right hand corner. \nSo $(\\frac{A}{\\norm{A}})^k \\approx VJ^kV^{-1}$ So the largest eigenvalue dominates.\n\\end{comment}\n\n\\section*{The QR algorithm}\nWe will explore one of the simplest: the $QR$ algorithm.\nThe following recurrence describes the $QR$ Algorithm in its most basic form:\n\\begin{equation*}\nA_0 = A, \\quad A_k = Q_k R_k, \\quad A_{k+1} = R_k Q_k\n\\end{equation*}\nwhere $Q_k, R_k$ is the $QR$ decomposition of $A_k$.\nYes, it's as easy as it looks.\nAll this algorithm does at each step is find the $QR$ decomposition of $A_k$ and multiply $Q_k$ and $R_k$ together again but in the opposite order.\nHow does this simple algorithm find the eigenvalues of $A$?\n\nObserve that $A_{k+1} \\sim A_k$ (where $\\sim$ denotes matrix similarity).\nThen $A_n \\sim A$ for all $n$.\nThis statement shows that $A_n$ has the same eigenvalues as $A$.\nPreservation of eigenvalues is the first important feature that makes the algorithm work.\nThe other important feature is that each iteration of the algorithm effectively transfers some of the ``mass'' from the lower to the upper triangle.\nUnder very general conditions, $A_n$ will converge to a matrix of the form\n\n\\begin{equation*}\n\\label{eq:Schur form}\nS =\n     \\begin{pmatrix}\n          S_1 &* & \\cdots & * \\\\\n           0     &S_2  &  \\ddots & \\vdots \\\\\n           \\vdots  & \\ddots & \\ddots & *  \\\\\n           0 & \\cdots & 0 & S_m\n    \\end{pmatrix}\n\\end{equation*}\nwhere $S_i$ is either a $1 \\times 1$ or a $2 \\times 2$ matrix.\nFor most matrices $A$, all the $S_i$ will be $1 \\times 1$, so $S$ will be an upper triangular matrix.\nIn this case, $S$ is called the \\emph{Schur form} of $A$.\nThe eigenvalues of $A$ are on the main diagonal of $S$.\n\nThe only case where $S$ is not upper triangular is when $A$ is a real but not symmetric matrix.\nIn this case, though $A$ is real, it may have complex eigenvalues.\nThese eigenvalues occur in complex conjugate pairs.\nEach of these pairs corresponds to a $2 \\times 2$ block in $S$, where the eigenvalues of the $2 \\times 2$ block are the complex conjugate pair of eigenvalues of $A$.\nIn this case, $S$ is called the \\emph{real Schur form} of $A$.\n\n\\subsection*{Hessenberg preconditioning}\nRecall that an upper Hessenberg matrix looks like\n\\[\n\\begin{pmatrix}\n* & * & * & \\cdots & * \\\\\n* & * & * & \\cdots & * \\\\\n0 & * & * & \\cdots&* \\\\\n\\vdots & & \\ddots & \\ddots & \\vdots \\\\\n0 & \\cdots & 0 & * & *\\\\\n\\end{pmatrix}\n\\]\nand that every matrix is similar to an upper Hessenberg matrix.\nHessenberg reduction also preserves eigenvalues.\nIt is a good idea to reduce to Hessenberg form before continuing with the $QR$ algorithm.\nYou'll converge to the Schur form faster this way, since Hessenberg matrices are already close to upper triangular.\n\n\\begin{problem}\nWrite a function \\li{qrSolver} that implements the QR algorithm as described above. Use the QR decomposition built into \\li{scipy.linalg}.\nHave your function accept a real-valued $n \\times n$ matrix $A$, a number of iterations, and a tolerance number,\nand return the corresponding estimate for all the eigenvalues of $A$.\nNote that you will need to find the eigenvalues of the $2 \\times 2$ $S_i$ directly, whenever there are any.\n\\label{prob:qr_solver}\n\\end{problem}\n\nReducing the matrix to Schur form also has the added benefit that each iteration for an $n \\times n$ array can be computed in $\\mathcal{O} \\left( n^2 \\right)$ time instead of $\\mathcal{O} \\left( n^3 \\right)$.\nOne algorithm for computing the QR decomposition of an upper Hessenberg matrix was discussed in Lab \\ref{lab:givens}.\nThis works since $Q$ in the QR factorization of an upper Hessenberg matrix is also upper Hessenberg, the product $R Q$ also turns out to be upper Hessenberg.\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:QR_eig_hessenberg}\nWrite a version of the QR algorithm that performs the QR algorithm by computing the Hessenberg form of a matrix, then computing various QR decompositions of the Hessenberg form of the matrix.\nUse your solutions to \\ref{prob:hessenberg} (where you computed the Hessenberg form of a matrix) and Problem \\ref{prob:givens_hessenberg_modified} to do the necessary computations (where you computed the QR decomposition of a Hessenberg matrix and wrote code for multiplication by $Q$ that works in $\\mathcal{O} \\left( n^2 \\right)$ time).\nThe solution to Problem \\ref{prob:givens_hessenberg_modified} is especially important because it allows the compution of each QR decomposition and each $R Q = \\left( Q^T R^T \\right)$ in $\\mathcal{O} \\left( n^2 \\right)$ time.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nIf $A$ is normal, its Schur form is diagonal.\nFor normal $A$, have your function additionally output the eigenvector corresponding to each eigenvalue.\nHint 1: Test your function on Hermitian and real symmetric matrices; they are both normal.\nHint 2: Your work in Problem \\ref{problem:similarity proof} will help.\nYou have already made all the necessary calculations, you just need to store the information correctly.\n\\end{problem}\n\\end{comment}\n\n\\begin{problem}\nTest your implementation with random matrices.\nTry real-valued and symmetric matrices.\nCompare your output to the output from the eigenvalue solver.\nHow many iterations are necessary?\nHow large can $A$ be?\n\\end{problem}\n\nBe aware that the algorithm we coded today is a very un-optimized approach.\nIn practice, the QR algorithm as we have described it here is not generally used.\nThere is an improved version called the Implicit QR algorithm that iterates much more efficiently.\n\nFurther, the QR algorithm is not the only iterative method used to find eigenvalues.\nArnoldi iteration is similar to the QR algorithm but exploits sparsity.\nOther methods include the Jacobi method and the Rayleigh quotient method.\n\nAs a final note, it is important to remember that eigenvalue solvers can be wrong, particularly for matrices that are ill-conditioned. \nConvergence is not unconditionally guaranteed. \n\n\\section*{Markov Chains}\nA Markov Chain describes a particular type of random process that\nundergoes a sequence of transitions among various states. It is\ncharacterized by the fact that all relevant information is related to its current state.\nWe can easily model this process using matrices.\nWe will start with a simple example of a frog jumping from one lily pad to another.\n\nSuppose Fredo the frog jumps around between the three lily pads 1, 2, and 3.\nThese three pads are taken as the possible \\emph{states} of the system, and the\nlily pad on which Fredo is presently sitting is the \\emph{current state}.\nIf Fredo is on lily pad 1 and jumps, there is a 25\\% chance that it will land back on lily pad 1, a 25\\% chance that it will land on lily pad 2, and a 50\\% chance that it will land on lily pad 3.\nWe can find similar probabilities if he starts on lily pad 2 or 3.\nSuch probabilities are known as the \\emph{transition probabilities}.\nIn figure \\ref{fig:markov1} we have a transition diagram that reflects the various probabilities of jumping from one lily pad to another.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{markov1}\n\\caption{Transition diagram for Fredo the Frog}\n\\label{fig:markov1}\n\\end{figure}\n\nWe can convert our transition diagram into a transition matrix, where the $(i,j)$-entry of the matrix corresponds to the probability that Fredo jumps from the $j^{th}$ lily pad to the $i^{th}$ lily pad (where $1$ is the first lily pad, $2$ is the second, and so on).\nThe transition matrix is\n\\[\nA = \\begin{pmatrix}\n1/4 & 1/2 & 1/2\\\\\n1/4 & 1/6 & 1/2\\\\\n1/2 & 1/3 & 0\n\\end{pmatrix}\n\\]\nNote that all of the columns add up to one.\nThis is important.\n\nIf Fredo is on lily pad 1, where will it be after two jumps?\nBy multiplying the matrix $A$ by itself, we have (approximately)\n\n\\[\nA^2 = \\begin{pmatrix}\n0.4375 & 0.3750 & 0.3750\\\\\n0.3542 & 0.3194 & 0.2083\\\\\n0.2083 & 0.3056 & 0.4167\n\\end{pmatrix}\n\\]\nFrom this, we infer that there is a 43.75\\% chance the frog will still be on lily pad 1 after two jumps.\nNote that it might have jumped from 1 to 1 to 1, denoted $1 \\rightarrow 1 \\rightarrow 1$, or it could have jumped to one of the other lily pads and then back again, that is, either $1 \\rightarrow 2 \\rightarrow 1$ or $1 \\rightarrow 3 \\rightarrow 1$.\nIn addition, there is a 35.42\\% chance it will be on lily pad 2 and a 20.83\\% chance that it will be on lily pad 3.\nUsing Python, we can type in our transition matrix and see where Fredo will be after 5, 10, 20 or 100 jumps.\n\n\\begin{lstlisting}\n#Remember, the 1.'s in the numerator force floating point division\n>>> A = np.array([[1./4,1./2,1./2],[1./4,1./6,1./2],[1./2,1./3,0]])\n>>> np.linalg.matrix_power(A,5)\n>>> np.linalg.matrix_power(A,10)\n>>> np.linalg.matrix_power(A,20)\n>>> np.linalg.matrix_power(A,100)\n\\end{lstlisting}\n\nNote that as we take higher powers it appears that the limit goes to\n\\[\nA^\\infty = \\begin{pmatrix}\n0.4 & 0.4 & 0.4\\\\\n0.3 & 0.3 & 0.3\\\\\n0.3 & 0.3 & 0.3\n\\end{pmatrix},\n\\]\nand this can, in fact, be proven carefully.\nThis means that after several jumps, the probability that we will find Fredo on a given lily pad will have nothing to do with where he started initially.\n\nWe can generalize this notion beyond that of frogs and lily pads.\nLet the state distribution of our system be represented by a probability vector\n\\[\n\\x = \\begin{bmatrix}\nx_1\\\\\nx_2\\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\n\\]\nwhere each entry represents the probability of being in that state.\nNote that each entry is non-negative and the sum of all the entries adds up to one.\nFor example, in the frog example, if we know initially that it is on lily pad 1, then we have the probability vector\n\\[\n\\x_0 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}\n\\]\nbecause we know for certainty (100\\%) that Fredo is in the first state.\nAfter one jump, we have\n\\[\n\\x_1 = A \\x_0 = \\begin{bmatrix}\n0.25\\\\\n0.25\\\\\n0.50\n\\end{bmatrix}\n\\]\nAfter two jumps, we have\n\\[\n\\x_2 = A \\x_1 = A^2 \\x_0 = \\begin{bmatrix}\n0.4375\\\\\n0.3542\\\\\n0.2083\n\\end{bmatrix}\n\\]\nAfter a large number of jumps $(n>>1)$, we have\n\\[\n\\x_n = A \\x_{n-1} = \\dots = A^n \\x_0 \\approx \\begin{bmatrix}\n0.4\\\\\n0.3\\\\\n0.3\n\\end{bmatrix}\n\\]\nSince all of the columns are the same for $A^\\infty$, it follows that for any initial probability vector $\\x_0$, we get the same limiting output, or in other words, all initial vectors converge to the same point, call it $\\x_\\infty$.\nMoreover, we have that\n\\[\n\\x_\\infty = A \\x_\\infty\n\\]\nThis is called a \\emph{stable fixed point}.\nHow can we check that a stable fixed point exists?\n\nNotice this is just the power method iteration without dividing by the norm. Since the all of the columns of $A$ sum to one and $x_0$ sums to one the one norm of $Ax_k=1$ for all $k$. So this goes to a stable fixed point and that fixed point turns out to be the eigenvector corresponding to the largest eigenvalue. Note that all the columns sum up to one and that a matrix and its transpose have the same eigenvalues. It can be shown that if all the rows of a positive matrix sum to the same number that number is the largest eigenvalue and the corresponding eigenvector is the one vector. So the $A.T$ has the eigenvalue $\\lambda=1$ so $A$. So for any Markov chain the largest eigenvalue will be $\\lambda=1$.\n\n\\begin{example}\nConsider the Markov chain given by\n\\[\nA = \\begin{pmatrix}\n0.5 & 0.3 & 0.4\\\\\n0.2 & 0.2 & 0.3\\\\\n0.3 & 0.5 & 0.3\n\\end{pmatrix}.\n\\]\n\nWe do this via Python:\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n>>> A = np.array([[.5,.3,.4],[.2,.2,.3],[.3,.5,.3]])\n>>> V = la.eig(A)[1]\n\\end{lstlisting}\nNote that the entries in the $\\lambda=1$ eigenvector do not generally add up to one.\nIndeed, any multiple of an eigenvector is an eigenvector.\nSo we need to multiply it by the appropriate constant so that all of the entries add up to one.\n\\begin{lstlisting}\n>>> x = V[:,0]\n>>> x = x/np.sum(x);x\narray([ 0.41836735,  0.23469388,  0.34693878])\n\\end{lstlisting}\nWe can check this answer by taking $A$ to a high exponent, say $A^{100}$.\n\\end{example}\n\n\\begin{problem}\nSuppose a basketball player's success at shooting free throws can be described with the following Markov chain\n\\[\nA = \\begin{pmatrix}.75&.50\\\\.25&.50\\end{pmatrix}\n\\]\nwhere the first state corresponds to success and the second state to failure.\n\\begin{enumerate}\n\\item If the player makes his first free throw, what is the probability that he also makes his third one?\n\\item What is the player's average free throw percentage?\n\\end{enumerate}\n\\label{prob:markov_freethrow}\n\\end{problem}\n\n\\begin{problem}\nConsider the Markov process given by the transition diagram in Figure \\ref{fig:markov2}.\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{markov2}\n\\caption{Transition diagram}\n\\label{fig:markov2}\n\\end{figure}\n\n\\begin{enumerate}\n\\item Find the transition matrix.\n\\item If the Markov process is in state 1 initially, find the probability that it is in state 2 after two transitions.\n\\item Find the stable fixed point if it exists.\n\\end{enumerate}\n\\label{prob:markov_stablept}\n\\end{problem}", "meta": {"hexsha": "dc327ae7e6c5da5e296cf8795f098f814f9e1c90", "size": 16309, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/EigSolver/Eig.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/EigSolver/Eig.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/EigSolver/Eig.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.4098837209, "max_line_length": 709, "alphanum_fraction": 0.7410019008, "num_tokens": 4621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912913, "lm_q2_score": 0.8670357701094304, "lm_q1q2_score": 0.7770819947111455}}
{"text": "\\subsection{Introduction}\r\n\r\nLinear regression is a statistical approach for modelling relationship between a dependent variable with a given set of independent variables.\r\n\r\nIn order to provide a basic understanding of linear regression, we start with the most basic version of linear regression, i.e. Simple linear regression.\r\n\r\n\\subsubsection{Simple Linear Regression}\r\nSimple linear regression is an approach for predicting a \\textbf{response} using a \\textbf{single feature}.\r\n\r\nIt is assumed that the two variables are linearly related. Hence, we try to find a linear function that predicts the response value(y) as accurately as possible as a function of the feature or independent variable(x).\r\n\r\nNow, the task is to find a line which fits best in above scatter plot so that we can predict the response for any new feature values. (i.e a value of x not present in dataset)\r\n\r\nThis line is called \\textbf{Regression line}. This equation of regression line is represented as:\r\n\r\n\\begin{equation}\r\nh(x_{i}) = \\beta_{0} + \\beta_{1}x_{i};\r\n\\end{equation}\r\n\r\nHere, $\\bullet$ represents the predicted response value for i-th observation.\r\n\r\n$\\bullet$ b\\_0 and b\\_1 are regression coefficients and represent y-intercept and slope of regression line respectively.\r\n\r\nTo create our model, we must \\q{learn} or estimate the values of regression coefficients b\\_0 and b\\_1. And once we've estimated these coefficients, we can use the model to predict responses!\r\nFor this we use Least Squared Technique.\r\n\r\n\\subsubsection{Least Square Technique}.\r\n\\begin{equation}\r\ny_{i}=\\beta_{0} + \\beta_{1} \\times x_{i} + \\epsilon_{i} = h(x_{i+}) + \\epsilon_{i}\r\n\\implies \\epsilon_{i} = y_{i} - h(x_{i});\r\n\\end{equation}\r\n\r\nHere, e\\_i is residual error in ith observation.  We try to  minimize the total residual error. We define the squared error or cost function, J as:\r\n\\begin{equation}\r\nJ(\\beta_{0},\\beta_{1}) = \\frac{1}{2n} \\sum_{i=1}^{n} \\epsilon_{i}^2;\r\n\\end{equation}\r\n\r\nand our task is to find the value of b\\_0 and b\\_1 for which J(b\\_0, b\\_1) is minimum! Without going into the mathematical details, we present the result here:\r\n\r\n\\begin{equation}\r\n\\beta_{1} = \\frac{SS_{xy}}{SS_{xx}};\r\n\\end{equation}\r\n\r\n\\begin{equation}\r\n\\beta_{0} =  \\bar{y} - \\beta_{1}\\bar{x};\r\n\\end{equation}\r\n\r\nwhere SS\\_xy is the sum of cross-deviations of y and x:\r\n\r\n\\begin{equation}\r\nSS_{xy} = \\sum_{i=1}^{n} (x-\\bar{x})(y-\\bar{y})= \\sum_{i=1}^{n} y_{i}x_{i} -n\\bar{x}\\bar{y};\r\n\\end{equation}\r\n\r\nand SS\\_xx is the sum of squared deviations of x:\r\n\r\n\\begin{equation}\r\nSS_{xx} = \\sum_{i=0}^{n}(x_{i}-\\bar{x})^2= \\sum_{i=0}^{n} x_{i}^2 - n(\\bar{x})^2;\r\n\\end{equation}\r\n\r\n\\subsubsection{Multiple Linaer Regression}\r\nMultiple linear regression attempts to model the relationship between two or more features and a response by fitting a linear equation to observed data. Clearly, it is nothing but an extension of Simple linear regression. Consider a dataset with p features(or independent variables) and one response(or dependent variable). Also, the dataset contains n rows/observations. \r\n\r\nX(features matrix) = a matrix of size nXp where x\\_{i} denotes the values of jth feautres for ith observation.\r\n \r\nSo,\r\n$$\r\n\\begin{pmatrix}\r\nx_{1,1} & x_{1,2} & \\cdots & x_{1,n} \\\\\r\nx_{2,1} & x_{2,2} & \\cdots & x_{2,n} \\\\\r\n\\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\r\nx_{m,1} & x_{m,2} & \\cdots & x_{m,n} \r\n\\end{pmatrix}\r\n$$\r\n\r\nand\r\n\r\ny = $\r\n\\begin{pmatrix}\r\ny_{1} \\\\ y_{2} \\\\ y_{3} \\\\\r\n\\vdots y_{n}\r\n\\end{pmatrix}\r\n$\r\n\r\nThe regression line for p is represented as:\r\n\r\n\\begin{equation}\r\nh(x_{i}) = \\beta_{0} + \\beta_{1}x_{i1}+\\beta_{2}x_{i2}+ ... +\\beta_{p}x_{ip};\r\n\\end{equation}\r\n\r\n\r\nwhere h(x\\_i) is predicted response value for ith observation and b\\_0,b\\_1, ...,b\\_p are the regression coefficients. \r\nAlso, we can write:\r\n\r\n\\begin{equation}\r\ny_{i} = \\beta_{0} + \\beta_{1}x_{i1} + \\beta_{2}x_{i2} + ... +\\beta_{p}x_{ip} + \\epsilon_{i};\r\n\\end{equation}\r\n\r\nor\r\n\r\n\\begin{equation}\r\ny_{i} = h(x_{i}) + \\epsilon_{i} \\implies \\epsilon_{i} = y_{i} - h(x_{i});\r\n\\end{equation}\r\n\r\n\r\nWe can generalize our linear model a little bit more by representing feature matrix X as:\r\n\r\n$\\begin{pmatrix}\r\n1 & x_{1,1} & x_{1,2} & \\cdots & x_{1,p} \\\\\r\n1 & x_{2,1} & x_{2,2} & \\cdots & x_{2,p} \\\\\r\n\\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\r\n1 & x_{n,1} & x_{n,2} & \\cdots x a_{n,p} \r\n\\end{pmatrix}$\r\n\r\n\r\nSo now, the linear model can be expressed in terms of matrices as:\r\n \r\n$$\r\ny = X\\beta + \\epsilon\r\n$$\r\n\r\nwhere,\\newline\r\n\r\n$$\\beta = \r\n\\begin{bmatrix} \r\n\\beta_0\\\\  \\beta_1\\\\  .\\\\  .\\\\  \\beta_p \r\n\\end{bmatrix}$$ \r\n\r\nand\r\n\r\n$$\\epsilon = \r\n\\begin{bmatrix} \r\n\\varepsilon_1\\\\  \\varepsilon_2\\\\  .\\\\  .\\\\  \\varepsilon_n \r\n\\end{bmatrix}\r\n$$ \r\n\r\nNow, we determine estimate of b, i.e. b' using Least Squares method.\r\n\r\nAs already explained, Least Squares method tends to determine b for which total residual error is minimized.\r\n\r\nWe present the result directly here:\r\n$$\\hat{\\beta} = (XX')^{-1} {X}'y $$\r\n\r\nwhere 'represents the transpose of the matrix while -1 represents the matrix inverse.\r\n\r\nKnowing the least square estimates, b', the multiple linear regression model can now be estimated as:\r\n$$\\hat{y} = X\\hat{\\beta}$$\r\n\r\nwhere $\\hat{y}$ is estimated response vector.\r\n\r\n\\subsubsection{Assumptions}\r\nthe basic assumptions that a linear regression model makes regarding a dataset on which it is applied:\r\n\r\n\\paragraph{Linear relationship:}\r\nRelationship between response and feature variables should be linear. The linearity assumption can be tested using scatter plots. As shown below, 1st figure represents linearly related variables where as variables in 2nd and 3rd figure are most likely non-linear. So, 1st figure will give better predictions using linear regression.\r\n\r\n\\paragraph{Little or no multi-collinearity:}\r\nIt is assumed that there is little or no multicollinearity in the data. Multicollinearity occurs when the features (or independent variables) are not independent from each other.\r\n\r\n\\paragraph{Little or no auto-correlation:}\r\nAnother assumption is that there is little or no autocorrelation in the data. Autocorrelation occurs when the residual errors are not independent from each other. You can refer here for more insight into this topic.\r\n\r\n\\paragraph{Homoscedasticity:}\r\nHomoscedasticity describes a situation in which the error term (that is, the \\q{noise} or random disturbance in the relationship between the independent variables and the dependent variable) is the same across all values of the independent variables. As shown below, figure 1 has homoscedasticity while figure 2 has heteroscedasticity.\r\n\r\n\\subsection{Application}\r\nSome of the application of linear regression model are :\r\n\r\n\\begin{enumerate}\r\n\\item Trend lines: A trend line represents the variation in some quantitative data with passage of time (like GDP, oil prices, etc.). These trends usually follow a linear relationship. Hence, linear regression can be applied to predict future values. However, this method suffers from a lack of scientific validity in cases where other potential changes can affect the data.\r\n\\item Economics: Linear regression is the predominant empirical tool in economics. For example, it is used to predict consumption spending, fixed investment spending, inventory investment, purchases of a country's exports, spending on imports, the demand to hold liquid assets, labor demand, and labor supply.\r\n\\item Finance: Capital price asset model uses linear regression to analyze and quantify the systematic risks of an investment.\r\n\\item Biology: Linear regression is used to model causal relationships between parameters in biological systems.\r\n\\end{enumerate}\r\n\r\n\\subsection{Citing}\r\nA well known implementation is given in \\href{https://www.geeksforgeeks.org/linear-regression-python-implementation/}{Geeks-for-Geeks} and a well discussion is done at \\href{https://en.wikipedia.org/wiki/Linear_regression}{Linear regression Wiki}.\r\n\r\nFor our project we will use simple linear regression (with features the difference in the number of bits).\r\n", "meta": {"hexsha": "8e92d943de9e36de055c37f9659a03ac10c704f1", "size": 8006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/thesis/doc_src/lr.tex", "max_stars_repo_name": "TheScienceUniverse/BlockChain", "max_stars_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/thesis/doc_src/lr.tex", "max_issues_repo_name": "TheScienceUniverse/BlockChain", "max_issues_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/thesis/doc_src/lr.tex", "max_forks_repo_name": "TheScienceUniverse/BlockChain", "max_forks_repo_head_hexsha": "03c33fabfa702fad7f6e3a9de5757a2ccda2d909", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.7262569832, "max_line_length": 375, "alphanum_fraction": 0.7239570322, "num_tokens": 2172, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896802383028, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7770499070584573}}
{"text": "%             %\n%%           %%\n%%% CHAPTER %%%\n%%           %%\n%             %\n\n\n\\chapter{Mathematics -- Basics}\n\n\t\\label{cha::maths:basics}\n\n\nMathematics writing is one of the most advantage of \\LaTeX{} compared to common text editors.\nOn a first approach, it looks like a programming language but it is in fact quite intuitive.\n\n\n\n\\section{Packages for mathematics}\n\n\n\tThe first package which was extremely useful in mathematics writing was \\emph{amsmath}.\n\tSince then, it has been upgraded by the \\emph{mathtools} package that I recommend to use.\n\tHence the following line in the preamble of the document:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\usepackage{mathtools}\n\\end{lstlisting}\n\n\n\tOther interesting packages are:\n\t\\begin{itemize}\n\t\t\\item \\emph{cases} which provides the \\texttt{numcases} command to number all lines of a system of equations,\n\t\t\\item \\emph{systeme} which provides command to format a system of equations for better readility, and\n\t\t\\item \\emph{physics} which provides many commands to facilitate the writing of \\enquote{complex} equations including derivatives and partial derivatives.\n\t\\end{itemize}\n\tHowever, \\emph{systeme} is quite new at the time this document is being written and so it could lack of maturity.\n\n\n\n\\section{Writing equations}\n\n\n\tUsually, when a writer wants to put mathematics in a document, it takes the form of an equation.\n\tWriting an equation is simply done thanks to the \\texttt{equation} environment.\n\tMaxwell's equations will be used as examples: so, the \n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation}\n\t\\vec{\\nabla}\\cdot\\vec{B}=0.\n\t\\label{eq::Maxwell:no_magnetic_monopole}\n\\end{equation}\n\\end{lstlisting}\n\t\\LaTeX{} code generates\n\t\\begin{equation}\n\t\t\\vec{\\nabla}\\cdot\\vec{B}=0.\n\t\t\\label{eq::Maxwell:no_magnetic_monopole}\n\t\\end{equation}\n\t\n\t\n\tHere is the power of \\LaTeX{}: automatic numbering of equations.\n\tIn \\emph{book}-like documents, equations are numbered within chapters by default, i.e., (1.x) in chapter~1, (2.x) in chapter~2 and so on.\n\tMoreover, equations numbers (a.k.a. tags) are placed on the right side.\n\tOf course, this layout can be modified.\n\t\n\t\n\t\n\t\\subsection{Unnumbered equations}\n\t\n\t\n\t\tAutomatic numbering can be avoided by using the starred version of the previous environment: \\texttt{equation*}.\n\t\tFor instance,\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\vec{\\nabla}\\times\\vec{E}\n\t\t=-\\frac{\\partial\\vec{B}}{\\partial t}.\n\\end{equation*}\n\\end{lstlisting}\t\n\t\tproduces\n\t\t\\begin{equation*}\n\t\t\t\\vec{\\nabla}\\times\\vec{E}\n\t\t\t\t=-\\frac{\\partial\\vec{B}}{\\partial t}.\n\t\t\\end{equation*}\n\t\tNevertheless, it is generally recommended to number all equations in scientific documents for easier reference.\n\t\t\n\t\t\n\t\tShorter forms of the unnumbered version are offered by the package: the \\textbackslash{}[ \\ldots \\textbackslash{}] wrapper or the double \\$\\$ symbol.\n\t\tPlease note that the latter is plain \\TeX{}, which means that it should not be used with \\LaTeX{} because it is not robust.\n\t\tThough, the reason for which \\$\\$ is presented in this document is that it is overly used on the Internet \\footnote{And, as we all know, if it is on the Internet, it must be true\\ldots}.\n\t\t\n\t\tHere follow the corresponding examples:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n$$\\iint_{\\Sigma_f} \\vec{B} \\cdot \\mathrm{d}\\vec{S},$$\n\\end{lstlisting}\n\t\tis the code corresponding to\n\t\t$$ \\iint_{\\Sigma_f} \\vec{B} \\cdot \\mathrm{d}\\vec{S}, $$\n\t\twhile\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\[ \\oint_{C} \\vec{E} \\cdot \\mathrm{d}\\vec{l}\n\t= - \\iint_{S} \\frac{\\partial\\vec{B}}{\\partial t}\n\t  \\cdot \\mathrm{d}\\vec{S}. \\]\n\\end{lstlisting}\n\t\tcreates\n\t\t\\[ \\oint_{C} \\vec{E} \\cdot \\mathrm{d}\\vec{l}\n\t\t\t= - \\iint_{S} \\frac{\\partial\\vec{B}}{\\partial t}\n\t\t\t  \\cdot \\mathrm{d}\\vec{S}. \\]\n\t\t\t  \n\t\tHowever, I do not recommend to use short forms. \n\t\tOn the one hand, the \\texttt{equation*} environment highlights the mathematics when looking in the \\LaTeX{} code.\n\t\tOn the other hand, if the author changes his mind and wants to number the equation, he must simply remove the \\texttt{*} character.\n\t\n\t\n\t\n\t\\subsection{Inline equations}\n\t\n\t\n\t\tInline equations are equations written in the text.\n\t\tIt can be useful in some circumstances, such as the description of a variable.\n\t\tFor instance, I could specify that $\\vec{B}$ in \\cref{eq::Maxwell:no_magnetic_monopole} is the magnetic field.\n\t\tTo do so, the equation is surrounded by single \\$ signs:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n$\\vec{B}$\n\\end{lstlisting}\n\n\n\n\t\\subsection{Text-mode VS math-mode}\n\t\n\t\tInline equations underlines a fundamental behaviour of \\LaTeX{}: the difference between \\emph{math-mode} and \\emph{text-mode}.\n\t\tAs the names explain, text-mode is the regular mode of \\LaTeX{} as the main part of the document is usually text, while math-mode is set in specific environments intended for mathematics.\n\t\t\n\t\tCompare\n\t\t\\begin{center}\n\t\t\tregular behaviour (text-mode),\n\t\t\t$text in mathematical environment (math-mode)$.\n\t\t\\end{center}\n\t\tthat is produced by\n\\begin{lstlisting}[language={[LaTeX]TeX}]\nregular behaviour (text-mode),\n$text in mathematical environment (math-mode)$.\n\\end{lstlisting}\n\t\n\t\n\t\tMath-mode has several effects:\n\t\t\\begin{itemize}\n\t\t\t\\item a math font is used instead of the text font,\n\t\t\t\\item the default font family is slanted while it is normal roman font in text,\n\t\t\t\\item it manages white spaces in a different way than the ongoing typographical rules\n\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\\item any white space is automatically removed,\n\t\t\t\t\t\\item white space is added around mathematical operators,\n\t\t\t\t\\end{itemize}\n\t\t\t\\item commands available in math-mode only will not generate errors.\n\t\t\\end{itemize}\n\t\n\t\n\t\n\t\\subsection{Consequences of text- and math-mode: display style}\n\t\n\t\t\n\t\tSometimes, inline equations may introduce unpleasant distortion in the text, especially with \\enquote{big} symbols.\n\t\tAs an example, let us use express the acceleration as the derivative of the speed:\n\t\t$a=\\frac{\\mathrm{d}v}{\\mathrm{d}t}$.\n\t\tIt can be seen that the fraction symbol has been compacted to fit with the line space.\n\t\tIt happens when math-mode is used inside a block text-mode, like it is the case with inline equations.\n\t\t\n\t\t\n\t\tIt is possible to prevent the fraction from being reshaped by forcing the \\emph{displayed math-mode}.\n\t\tTo do so, the writer must use the \\texttt{displaystyle} command, which exists in shorter forms for common mathematical symbols such as fractions.\n\t\tExpressing again the acceleration:\n\t\t$a=\\dfrac{\\mathrm{d}v}{\\mathrm{d}t}$, or, equivalently,\n\t\t$\\displaystyle a=\\frac{\\mathrm{d}v}{\\mathrm{d}t}$.\n\t\tIt can be seen that the space line is increased above and below the line including the equation, creating a somewhat uncomfortable text arrangement.\n\t\t\n\t\t\n\t\tThe problem presented here above is related to the following \\LaTeX{} codes:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n$a=\\frac{\\mathrm{d}v}{\\mathrm{d}t}$\n$a=\\dfrac{\\mathrm{d}v}{\\mathrm{d}t}$\n$\\displaystyle a=\\frac{\\mathrm{d}v}{\\mathrm{d}t}$\n\\end{lstlisting}\n\t\tIt will appear every time a \\enquote{big} symbol (fraction, integral, sum, etc.) is used.\n\t\tHowever, it never occurs within mathematical environments such as \\texttt{equation} because in that case the maths are \\emph{displayed}, i.e., horizontally centred and wrapped with additional vertical space in order to be highlighted and readable.\n\t\n\t\n\t\\subsection{General recommendations for equations}\n\t\t\n\t\tRecommendations:\n\t\t\\begin{itemize}\n\t\t\t\\item use numbered equation only (with the \\texttt{equation} environment),\n\t\t\t\\item try to avoid inline equations except\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item to describe variables or operators,\n\t\t\t\t\\item for very small, less important and/or very well-known formulae which do not contain \\enquote{big} symbols (e.g., integral, fraction).\n\t\t\t\\end{itemize}\n\t\t\\end{itemize}\n\t\n\t\n\t\n\\section{Writing groups of equations}\n\n\n\tSeveral commands and environments allow to group equations.\n\tThe most-used are presented here after.\n\tFor a complete presentation, please refer to the \\emph{amsmath} and \\emph{mathtools} packages documentation.\n\t\n\t\n\t\n\t\\subsection{Group of equations}\n\t\n\t\n\t\tThe first tool which allow to group equations is the \\texttt{gather} environment.\n\t\tInside the environment, a double backslash (\\textbackslash\\textbackslash) indicates the end of an equation and the beginning of a new one.\n\t\tConsequently, a new line is produced and another equation can be written.\n\t\tPay attention: no double backslash must be put after the last equation.\n\t\tOtherwise, an additional space is added at the end of the group.\n\t\t\n\t\t\n\t\tUnless the starred version (\\texttt{gather*}) is used, all equations are numbered.\n\t\tTo prevent one line from being numbered, the \\texttt{\\textbackslash{}notag} or the \\texttt{\\textbackslash{}nonumber} command can be used.\n\t\t\n\t\t\n\t\tIt is also possible to write text between equations while still being in the \\texttt{gather} environment.\n\t\tThis is done with the \\texttt{intertext} command, or \\texttt{shortintertext} which removes extra vertical space.\n\t\tIt is specifically useful for a mathematical development.\n\t\tWithin these commands, \\LaTeX{} is in text-mode, while it is in math-mode within the rest of the \\texttt{gather} environment.\n\t\t\n\t\t\n\t\tAs an example, the\t\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{gather}\n\t\\vec{\\nabla} \\times \\vec{B}\n\t\t= \\mu_0 \\vec{\\jmath}\n\t\t+ \\varepsilon_0 \\mu_0 \\frac{\\partial \\vec{E}}{\\partial t},\n\t\t\\\\\n\t\\intertext{which can be written in the integral form by \n\t\tapplying the Green theorem}\n\t\\oint_{C} \\vec{B} \\cdot \\mathrm{d} \\vec{l}\n\t\t= \\mu_0 \\iint_S \\vec{\\jmath} \\cdot \\mathrm{d} \\vec{S}\n\t\t+ \\varepsilon_0 \\mu_0 \\iint_S \\frac{\\partial \\vec{E}}{\n\t\t\t\\partial t}\t\\cdot \\mathrm{d} \\vec{S}\n\\end{gather}\n\\end{lstlisting}\t\n\t\tcode will generate\n\t\t\\begin{gather}\n\t\t\t\\vec{\\nabla} \\times \\vec{B}\n\t\t\t\t= \\mu_0 \\vec{\\jmath}\n\t\t\t\t+ \\varepsilon_0 \\mu_0 \\frac{\\partial \\vec{E}}{\\partial t},\n\t\t\t\t\\\\\n\t\t\t\\intertext{which can be written in the integral form by applying the Green theorem}\n\t\t\t\\oint_{C} \\vec{B} \\cdot \\mathrm{d} \\vec{l}\n\t\t\t\t= \\mu_0 \\iint_S \\vec{\\jmath} \\cdot \\mathrm{d} \\vec{S}\n\t\t\t\t+ \\varepsilon_0 \\mu_0 \\iint_S \\frac{\\partial \\vec{E}}{\\partial t} \\cdot \\mathrm{d} \\vec{S}\n\t\t\\end{gather}\n\t\t(see the use of \\texttt{\\textbackslash{}intertext}).\n\t\n\t\n\t\n\t\\subsection{Group of aligned equations}\n\t\n\t\n\t\tThe second tool allowing to group equations is the \\texttt{align} environment.\n\t\tIt does the same as the \\texttt{gather} environment but also allows to align the equations.\n\t\tThe alignment is performed thanks to the ampersand (\\&) symbol.\n\t\tAll other commands and symbols performs the same as in the \\texttt{gather} environment.\n\t\t\n\t\t\n\t\tFor instance,\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{align}\n\t\\vec{B} &= \\vec{\\nabla} \\times \\vec{A} \\\\\n\t\\vec{E} &= -\\vec{\\nabla} V - \\frac{\\partial \\vec{A}}{\\partial t}.\n\\end{align}\n\\end{lstlisting}\n\t\tcreates\n\t\t\\begin{align}\n\t\t\t\\vec{B} &= \\vec{\\nabla} \\times \\vec{A} \\\\\n\t\t\t\\vec{E} &= -\\vec{\\nabla} V - \\frac{\\partial \\vec{A}}{\\partial t}.\n\t\t\\end{align}\n\t\n\t\n\t\n\t\\subsection{General recommendations for groups of equations}\n\t\n\t\tRecommendations:\n\t\t\\begin{itemize}\n\t\t\t\\item use numbered equations only (unstarred versions) with possible exceptions for\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item numerical computations,\n\t\t\t\t\\item proofs (theorems, formulae, etc.),\n\t\t\t\\end{itemize}\n\t\t\t\\item do not abuse of intertext because it makes the \\LaTeX{} code less readable.\n\t\t\\end{itemize}\n\n\n\n\\section{Common symbols for mathematics}\n\n\tMathematics would not be mathematics without any symbols.\n\tCommon ones are:\n\t\\begin{itemize}\n\t\t\\item arithmetic operators such as $+$ and $-$,\n\t\t\\item comparison operators like $>$ and $<$.\n\t\\end{itemize}\n\n\tLess intuitive but still useful symbols are:\n\t\\begin{itemize}\n\t\t\\item the multiplication operator $\\cdot$ generated by the \\texttt{cdot} command,\n\t\t\\item the fraction symbol $\\frac{n}{d}$ created by the \\texttt{frac} command,\n\t\t\\item the integral $\\int$ which is produced by the \\texttt{int} command, and\n\t\t\\item any text symbol that is usually generated by a command having the same name (e.g., $\\sin$ with the \\texttt{sin} command or $\\exp$ with \\texttt{exp}).\n\t\\end{itemize}\n\t\n\tThere are many other symbols and being exhaustive is not the purpose of this mini-guide.\n\tIf the reader is looking for specific symbols, he may refer to:\n\t\\begin{itemize}\n\t\t\\item his \\LaTeX{} editor, which generally provides a list of shortcuts and buttons to generate the correct commands,\n\t\t\\item a \\href{https://fr.sharelatex.com/learn/List_of_Greek_letters_and_math_symbols}{quick review} of symbols from ShareLaTeX,\n\t\t\\item a \\href{http://www.rpi.edu/dept/arc/training/latex/LaTeX_symbols.pdf}{big list} of symbols native from \\TeX{} and coming from different packages.\n\t\\end{itemize}\n\n\n% *** End of chapter ***", "meta": {"hexsha": "bac11f1a8f1c893c735cad16b158150e5f975632", "size": 12739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tutorials/B100__Mathematics_Basics/Mini_guide__maths_basics.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/B100__Mathematics_Basics/Mini_guide__maths_basics.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/B100__Mathematics_Basics/Mini_guide__maths_basics.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": 39.809375, "max_line_length": 249, "alphanum_fraction": 0.7227411885, "num_tokens": 3630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.9207896834987981, "lm_q1q2_score": 0.7770498971572622}}
{"text": "\\chapter{Contraction and Index Gymnastics}\n\\emph{Index gymnastics} is the process by which we try and keep track of indices of tensors when written without their basis.\nSuppose we had a tensor $A \\in \\tps{T}^3_2(V)$.\nFormally, we would write this $(3,2)$ tensor as\n\\[ \\tensor{A}{^{\\alpha\\beta\\gamma}_{\\mu\\nu}} \\vec{e}_\\alpha \\otimes \\vec{e}_\\beta \\otimes \\vec{e}_\\gamma \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu : V^* \\times V^* \\times V^* \\times V \\times V \\to \\mathbb{F}, \\]\nwhich is kind of ridiculous to carry around\\footnote{Remember, what's written here is the \\emph{shortened} version using Einstein summation. The truly complete version would also have 5 summation signs at the beginning.}, especially when the component $\\tensor{A}{^{\\alpha\\beta\\gamma}_{\\mu\\nu}}$ contains all the information we need.\n\nAs we've written it, $A$ is a mapping from $\\tps{T}^3_2$ to the scalar field $\\mathbb{F}$; however, we've just shown that we can also `trick' this tensor into producing other objects if we give it a different number of arguments than it is expecting.\nFor example, if we were to give $A$ a single covector $\\Lambda$ as an argument, we've suddenly created a map which takes two covectors and two vectors to $\\mathbb{F}$, so \n\\[ A(\\Lambda,\\cdot,\\cdot\\mid\\cdot,\\cdot) \\in \\tps{T}^2_2, \\]\nwhere $\\mid$ is just a divider to visually separate the covector arguments from the vector arguments.\nNotice that this isn't the only way we can make $A$ a $\\tps{T}^2_2$ tensor; we can use $\\Lambda$ as any of the covector arguments expected, and create an entirely new rank $(2,2)$ tensor, like\n\\[ A(\\cdot,\\Lambda,\\cdot\\mid\\cdot,\\cdot) \\in \\tps{T}^2_2. \\]\n\n\\section{The Universal Property}\nSuppose we have a multilinear map $Z$ defined as\n\\[ B : \\underbrace{V \\times V \\times \\cdots}_{\\text{$p$ times}}\\underbrace{V^* \\times V^* \\times \\cdots}_{\\text{$q$ times}} \\to U, \\]\nwhere $U$ is some vector space.\nThe \\emph{Universal Property} says that if such a map exists, then we are guaranteed to have a multilinear map\n\\[ \\beta : \\underbrace{V \\otimes V \\otimes \\cdots}_{\\text{$p$ times}}\\underbrace{V^* \\otimes V^* \\otimes \\cdots}_{\\text{$q$ times}} \\to U, \\]\nand that these will be the same map, meaning that their results will always be the same.\nGraphically, the universal property can be written as\n\\begin{center}\n\\begin{tikzcd}\nV \\times V^* \\arrow[rr] \\arrow[rrdd, \"B\"'] &  & V \\otimes V^* \\arrow[dd, \"\\beta\", dashed] \\\\\n &  &  \\\\\n &  & U\n\\end{tikzcd}\n\\end{center}\nfor a simplified example with only a single vector-dual space product.\n\n\\begin{proof}[Proof of the Universal Property]\nWe will prove it holds for a simple case, and by linearity it will hold for all more general cases.\nSuppose we have a vector space $V$ over a scalar field $\\mathbb{F}$.\nLet $\\{\\vec{e}_\\mu\\}$ be the basis for $V$ and $\\{\\vec{e}^\\nu\\}$ be a basis for its dual space, $V^*$.\nLet $B$ be a map defined as \n\\[ B : V \\times V^* \\to U, \\]\nwhere $U$ is some vector space.\nIt must be the case that $B(\\vec{e}_\\mu, \\vec{e}^\\nu) \\in U$.\nLet $\\beta$ then be the map\n\\[ \\beta : \\tps{T}^1_1 \\to U \\]\ndefined in such a way that $\\beta(\\vec{e}_\\mu \\otimes \\vec{e}^\\nu) = B(\\vec{e}_\\mu, \\vec{e}^\\nu)$.\nSince we've defined how $\\beta$ operates on the basis $\\vec{e}_\\mu \\otimes \\vec{e}^\\nu$, we can represent any member of $V \\otimes V^*$ as a linear combination of that basis, and since $B$ and $\\beta$ are linear, we can write the result of any argument for $\\beta$ in this way.\n\\end{proof}\n\n\\section{Contraction of Bases}\nTo see why we care at all about the Universal Property, consider the notion of a map we defined at the very beginning of this lesson,\n\\begin{align*}\n    \\langle \\cdot, \\cdot \\rangle : V \\times V^* \\to \\mathbb{F}.\n\\end{align*}\nWe know this map exists because the creation of $V$ \\emph{automatically} implies the creation of the dual space $V^*$, so we must have the concept of multilinear mapping for any vector space.\nBy the Universal Property, we know that there must automatically be a function $\\beta$ such that\n\\begin{align*}\n    \\beta &: \\tps{T}^1_1 (V) \\to \\mathbb{F} \\\\\n      &: V \\otimes V^* \\to \\mathbb{F}.\n\\end{align*}\nWhile this example might seem trivial, we can use $\\langle \\cdot, \\cdot \\rangle$ to build more complicated mappings.\nSuppose we have some mapping\n\\begin{align*}\n    B &: V^p \\times V^{*q} \\to \\tps{T}^{p-1}_{q-1} \\\\\n      &: \\underbrace{V \\times V \\times \\cdots}_{\\text{$p$ times}}\\underbrace{V^* \\times V^* \\times \\cdots}_{\\text{$q$ times}} \\to \\tps{T}^{p-1}_{q-1}.\n\\end{align*}\nBy the Universal Property, we must be able to find some equivalent function $\\beta$ such that\n\\[ \\beta : \\tps{T}^p_q \\to \\tps{T}^{p-1}_{q-1}. \\]\nThis is what is known as a \\emph{contraction}; we can jump between tensor product spaces by lowering both indices by 1.\nObviously for this to occur, both $p$ and $q$ must be greater than 0.\nOne way we can do this is by taking a vector-covector pair from $\\tps{T}^p_q$ and applying the linear map to them; that is,\n\\[ B^i_j : \\vec{e}_1 \\times \\cdots \\vec{e}_i \\times \\cdots \\vec{e}_p \\times \\vec{e}^1 \\times \\cdots \\vec{e}^j \\times \\cdots \\vec{e}^q \\mapsto \\langle \\vec{e}^j, \\vec{e}_i \\rangle \\vec{e}_{\\alpha \\not= i} \\otimes \\vec{e}^{\\gamma \\not= j}. \\]\nThis map $B^i_j$ rips out the $i$\\textsuperscript{th} basis vector and $j$\\textsuperscript{th} basis covector from $\\tps{T}^p_q$, applies them to one another, and multiplies the result by the tensor product of all remaining basis vectors.\nSince we defined this map $B$ to act on the Cartesian product of the vector spaces and dual spaces, we must be able to find our equivalent function $\\beta^i_j$ which does the same thing, but maps from the tensor product space, so\n\\[ \\beta^i_j : \\tps{T}^p_q \\to \\tps{T}^{p-1}_{q-1} : \\vec{e}_1 \\otimes \\cdots \\vec{e}_p \\otimes \\vec{e}^1 \\otimes \\cdots \\vec{e}^q \\mapsto \\langle \\vec{e}^j, \\vec{e}_i \\rangle \\vec{e}_{\\alpha \\not=1}\\otimes \\vec{e}^{\\gamma \\not= j}. \\]\nNote that because we can vary $1 \\leq i \\leq p$ and $1 \\leq j \\leq q$, this isn't the only possible mapping we could have created using this method.\nIn fact, there will always be $pq$ possible mappings.\nWe refer to the specific contraction as $\\beta^i_j$ or the $(i,j)$ contraction.\nIf we want to contract more than once, we can simply apply this mapping more than once, so a jump from $\\tps{T}^p_q$ to $\\tps{T}^{p-\\alpha}_{q-\\alpha}$ can be achieved by some mapping\n\\[ \\gamma = \\underbrace{\\beta^{k}_{l} \\circ \\cdots \\circ \\beta^i_j}_{\\text{$\\alpha$ times}} \\]\napplied to the original tensor product space.\n\n\\section{Contraction of Generalized Tensors}\nLet's consider an arbitrary tensor \n\\[\nT = \\tensor{T}{^{i_1\\cdots i_\\alpha \\cdots i_p}_{j_1 \\cdots j_\\beta \\cdots j_q}} \\vec{e}_{i_1} \\otimes \\cdots \\vec{e}_{i_\\alpha} \\cdots \\otimes \\vec{e}_{i_p} \\otimes \\vec{e}^{j_1} \\otimes \\cdots \\vec{e}^{j_\\beta} \\cdots \\otimes \\vec{e}^{j_q}.\n\\]\nWe want to find the map \n\\begin{align*}\nC^{i_\\alpha}_{j_\\beta} &: \\tps{T}^p_q \\to \\tps{T}^{p-1}_{q-1} \\\\ \n                       &: T \\mapsto \\tensor{T}{^{i_1 \\cdots i_p}_{j_1 \\cdots j_q}} \\langle \\vec{e}^{j_\\beta}, \\vec{e}_{i_\\alpha} \\rangle \\vec{e}_{i \\not= \\alpha } \\otimes \\vec{e}^{j \\not= \\beta} \\\\\n                       &: T \\mapsto \\tensor{T}{^{i_1\\cdots i_\\alpha \\cdots i_p}_{j_1\\cdots i_\\alpha \\cdots j_q}} \\vec{e}_{i \\not= \\alpha } \\otimes \\vec{e}^{j \\not= \\beta}.\n\\end{align*}\nNotice that we end up with an $i_\\alpha$ in both the superscript and subscript indices of $T$.\nRecall this happens because $\\langle \\vec{e}^{j_\\beta}, \\vec{e}_{i_\\alpha} \\rangle = \\delta^{j_\\beta}_{i_\\alpha}$.\nAs we will see, this causes that index to be dropped in the resultant tensor component.\n\n\\section{Symmetric and Antisymmetric Tensors}\nA tensor is \\emph{symmetric} if we can rearrange the vector arguments, and rearrange the covector arguments (but not switch the two).\nFor example, a tensor $T$ is symmetric if\n\\[ \\tensor{T}{^{\\alpha\\beta}_{\\gamma\\delta}} = \\tensor{T}{^{\\beta\\alpha}_{\\delta\\gamma}}. \\]\nA tensor is \\emph{antisymmetric} if switching any pair of arguments switches the sign of the tensor, so \n\\[ T_{\\alpha\\beta\\gamma} = -T_{\\beta\\alpha\\gamma} = T_{\\beta\\gamma\\alpha}. \\]\nIf we refer to any pair of arguments $\\alpha\\beta$ of a tensor $T$, we can find its \\emph{symmetric part} and \\emph{antisymmetric part} by the following:\n\\begin{align*}\n    T_{(\\alpha\\beta)\\gamma} &= \\frac{1}{2}\\qty(T_{\\alpha\\beta\\gamma} + T_{\\beta\\alpha\\gamma}) \\tag{Symmetric part} \\\\\n    T_{[\\alpha\\beta]\\gamma} &= \\frac{1}{2}\\qty(T_{\\alpha\\beta\\gamma} - T_{\\beta\\alpha\\gamma}). \\tag{Antisymmetric part}\n\\end{align*}\nThis means that a tensor is the sum of its symmetric and antisymmetric parts, so $T_{\\alpha\\beta\\gamma} = T_{(\\alpha\\beta)\\gamma} + T_{[\\alpha\\beta]\\gamma}$.\n\n\\section{Index Gymnastics}\nAs you can see, it is very cumbersome to carry around the basis vectors in each calculation.\nInstead of writing everything out, we can keep track of all the necessary information by just shuffling the indices of the tensor component.\nThe simplest form of index gymnastics is raising or lowering a single index of a tensor.\nFor example, if we have a contravariant tensor $A^\\mu$ (written fully $A^\\mu \\vec{e}_\\mu \\in V$), we can create an associated covariant tensor $A_\\nu$ by lowering the index.\nIn fact, we've already done this with the metric tensor; consider Equation~\\eqref{eqn:metric-index-lowering}, where we saw that\n\\[ g_{\\mu\\nu} \\vec{e}^\\mu \\otimes \\vec{e}^\\nu \\qty(A^\\alpha \\vec{e}_\\alpha) \\mapsto A^\\mu g_{\\mu\\nu} \\vec{e}^\\nu \\in V^*. \\]\nIf we drop the basis vectors from this equation and look only at what is happening to the components, we get the equivalent \n\\[ g_{\\mu\\nu}\\qty(A^\\alpha \\vec{e}_\\alpha) \\mapsto A^\\mu g_{\\mu\\nu}, \\]\nwhich we often simply abbreviate as $A_\\nu$; this means that the metric tensor can be used to lower the index of a tensor via $g_{\\mu\\nu}A^\\mu \\mapsto A^\\nu$.\nThis is an example of how contraction reduces the indices when they are the same: because this tensor component as $\\mu$ as both an upper and lower index, it gets summed over, and we are left with a component with only $\\nu$ as a lower index.\nNote that it may be more proper to write this as $g_{\\nu\\mu}A^\\mu$, so that the summed-over indices are adjacent; we are allowed to do this because the metric tensor (in most derivations) is symmetric.\n\n\\section{Removing Bases}\nWe've already been doing a bit of index gymnastics when we refer to a tensor with multiple vector spaces in its tensor product space by only a single component with multiple indices.\nConsider this simple example of a $\\tps{T}^2_0$ tensor,\n\\[ T^{\\mu\\nu} = A^\\mu \\vec{e}_\\mu \\otimes B^\\nu \\vec{e}_\\nu. \\]\nPerhpas more properly, we should write this tensor as $A^\\mu B^\\nu$, but because these are both simply field elements, we can simplify them into a single component $T^{\\mu\\nu}$.\nNotice, however, that when we keep the basis vectors around, we can change the order of the components without changing the tensor, because of the commutativity of scalar multiplication.\n\\[ A^\\mu B^\\nu \\vec{e}_\\mu \\otimes \\vec{e}_\\nu = B^\\nu A^\\mu \\vec{e}^\\mu \\otimes \\vec{e}^\\nu. \\]\nWhile we swap the components, we keep the basis vectors in place, because $\\vec{e}^\\mu \\otimes \\vec{e}^\\nu \\not= \\vec{e}^\\nu \\otimes \\vec{e}^\\mu$.\nThis means that when we drop the basis vectors, we have to remember that the order of the indices is now important, because although $A^\\mu B^\\nu = B^\\nu A^\\mu$, $T^{\\mu\\nu} \\not= T^{\\nu\\mu}$, as the latter implies a different ordering of the basis vectors.\nConsider another example, from a tensor with a single vector and covector basis.\nSay we had a tensor\n\\[ A^\\mu B_\\nu \\vec{e}_\\mu \\otimes \\vec{e}^\\nu. \\]\nIf we combine the components in the appropriate way, we get a $\\tps{T}^1_1$ tensor $\\tensor{T}{^\\mu_\\nu}$, but if we combine them in the wrong order, we get $\\tensor{T}{_\\nu^\\mu}$, which isn't technically even a tensor.\n\n\\section{Contraction \\& Index Gymnastics}\nRecall that when we learned how to contract tensors, we saw that we ended up with a scenario where an upper and lower index were equal, causing that index to be removed and dropping the tensor from a $(p,q)$ tensor to a $(p-1,q-1)$ tensor.\nWithout worrying about the basis vectors, we can write this much more succinctly as\n\\[ \\tensor{T}{^{\\alpha\\beta\\gamma}_{\\lambda\\mu\\nu}} \\mapsto \\tensor{T}{^{\\alpha\\beta\\gamma}_{\\alpha\\mu\\nu}} \\mapsto \\tensor{M}{^{\\beta\\gamma}_{\\mu\\nu}}. \\]\n\n\\section{The Metric Tensor as a Metric}\nWe we learn about the inner product, its often in conjunction with the idea of the magnitude of a vector; in linear algebra, we learn that $\\vec{a}\\cdot\\vec{a} = \\norm{a}^2$.\nEven the name \\emph{metric tensor} implies that we can use it to get a notion of measure.\nTo show how this works in tensor form, lets consider the metric tensor $g_{\\mu\\nu}$ acting on two copies of an arbitrary vector:\n\\begin{align*}\n    g_{\\mu\\nu}\\qty(A^\\alpha \\vec{e}_\\alpha, A^\\alpha \\vec{e}_\\alpha) &= A^\\alpha A^\\alpha g_{\\mu\\nu} \\langle \\vec{e}^\\mu, \\vec{e}_\\alpha \\rangle \\langle \\vec{e}^\\nu, \\vec{e}_\\alpha \\rangle \\\\\n    &= A^\\alpha A^\\alpha g_{\\alpha\\alpha} \\\\\n    &= A^\\alpha A_\\alpha. \\tag{via Index Contraction}\n\\end{align*}\nThis is where we get the notion that $\\vec{a}\\cdot\\vec{a} = \\norm{a}^2$ in the world of tensors.\n", "meta": {"hexsha": "dc9674777b4a69a67db614bad9dc1a5dbdc9f6bb", "size": 13224, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/contraction_and_index_gymnastics.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/contraction_and_index_gymnastics.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/contraction_and_index_gymnastics.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": 88.7516778523, "max_line_length": 333, "alphanum_fraction": 0.6993345433, "num_tokens": 4209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7770391253741475}}
{"text": "\\section{Rates of Change \\& Tangent Lines}\r\nYou might already be familiar from physics with the idea of an average rate of change over some interval (often a time interval in physics).\r\nIt is simply the amount of change that occurred in the interval, divided by the length of the interval.\r\nThis is exactly the same idea as the slope of a line being \"rise over run\"\r\n\\begin{equation*}\r\n\t\\overline{\\Delta f_{a,b}} = \\frac{f(b)-f(a)}{b-a}.\r\n\\end{equation*}\r\nThis is also known as the ``secant slope'', which gets its name from secant lines on circles.\r\n\r\n\\begin{example}\r\n\tFind the average rate of change of $x^2-1$ over the interval $[1,4]$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tApplying the formula,\r\n\t\\begin{equation*}\r\n\t\t\\overline{\\Delta f_{1,4}} = \\frac{f(4)-f(1)}{4-1} = \\frac{15-0}{3} = 5.\r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\nAs we decrease the size of the interval, the secant line becomes closer and closer to a tangent line.\r\nIn the limit, as the size of the interval approaches 0, we get a tangent line, representing an instantaneous rate of change.\r\n\\begin{equation*}\r\n\t\\Delta f_a = \\lim_{h \\to 0}{\\frac{f(a+h)-f(a)}{h}}.\\footnote{You may recognize this from pre-calculus as the ``difference quotient''.}\r\n\\end{equation*}\r\n\r\n\\begin{figure}[H]\r\n\t\\label{sectant_tangent_line}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.5\\textwidth]{./derivatives/secant_tangent_line.png}\r\n\t\\caption{\\hyperref{}{}{}{Secant and Tangent Line}}\r\n\\end{figure}\r\n\r\n\\begin{example}\r\n\tFind the equation of the tangent line to $f(x)=x^2-4x$ at $x=1$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tFirst, we need to find the instantaneous rate of change of $f$ at $x=1$.\r\n\tWe do this by evaluating the limit.\r\n\t\\begin{align*}\r\n\t\t\\Delta f_{1} &= \\lim_{h \\to 0}{\\frac{f(1+h)-f(1)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{(1+h)^2-3(1+h) - (1)^2 + 3(1)}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{h^2 + 2h + 1 - 3 - 3h - 1 + 3}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{\\frac{h^2 - h}{h}} \\\\\r\n\t\t&= \\lim_{h \\to 0}{h - 1} \\\\\r\n\t\t&= -1.\r\n\t\\end{align*}\r\n\t\r\n\tNow that we have the slope of the tangent line, we can write the equation of the line in point-slope form.\r\n\tWe can also rearrange to standard for is needed.\r\n\t\\begin{align*}\r\n\t\ty - f(1) &= -1(x - 1) \\\\\r\n\t\ty + 2 &= -x + 1 \\\\\r\n\t\ty &= -x - 1.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "a5eaebf59bfce99abd31cd04b4072b90355cce6e", "size": 2250, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/rates_of_change.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/derivatives/rates_of_change.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/derivatives/rates_of_change.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.9090909091, "max_line_length": 141, "alphanum_fraction": 0.6484444444, "num_tokens": 789, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.90192066862062, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7770391178922514}}
{"text": "\\subsection{Rotations}\n\nAny matrix of the form $\\begin{bmatrix}a&-b\\\\b&a\\end{bmatrix}$ where $a^2+b^2=1$. \nThus, $\\theta=\\tan^{-1}(\\frac{b}{a})$, or by any other trigonometric relation.\n\n\\subsection{Scaling and dilation}\n\nHorizontal scaling affects the $x$-component:\n\n\\[\n    T \\begin{bmatrix}x\\\\ y\\end{bmatrix}\n    =\n    \\begin{bmatrix}kx\\\\ y\\end{bmatrix}\n    \\implies\n    A=\n    \\begin{bmatrix}k&0\\\\ 0&1\\end{bmatrix}\n\\]\n\nVertical scaling affects the $y$-component:\n\n\\[\n    T \\begin{bmatrix}x\\\\ y\\end{bmatrix}\n    =\n    \\begin{bmatrix}x\\\\ ky\\end{bmatrix}\n    \\implies\n    A=\n    \\begin{bmatrix}1&0\\\\ 0&k\\end{bmatrix}  \n\\]\n\nDilation is scaling by $k$ for both $x$ and $y$:\n\n\\[\n    T \\begin{bmatrix}x\\\\ y\\end{bmatrix}\n    =\n    \\begin{bmatrix}kx\\\\ ky\\end{bmatrix}\n    \\implies\n    A=\n    \\begin{bmatrix}k&0\\\\ 0&k\\end{bmatrix}  \n\\]\n\n\\subsection{Normalizing a vector}\n\nCan make any vector into a unit vector parallel to the original:\n\n\\[\\boxed{\\tb{u}=\\frac{\\tb{v}}{||\\tb{v}||}}\\]\n\nThe magnitude of a unit vector is always 1 ($||\\tb{u}||=1$).\n\n\\subsection{Projections}\n\n$x$-axis:\n\n\\[\n      T \\begin{bmatrix}x\\\\ y\\end{bmatrix}=\n      \\begin{bmatrix}x\\\\ 0\\end{bmatrix}\n\\]\n\n$y$-axis:\n\n\\[\n  T \\begin{bmatrix}x\\\\ y\\end{bmatrix}\n  = \\begin{bmatrix}0\\\\ y\\end{bmatrix}\n\\]\n\nMathematically:\n\n\\[||\\mathrm{proj}_l(\\tb{v})||=||\\tb{v}||\\cos\\theta\\]\n\nThe dot product:\n\n\\[\\boxed{\\tb{a}\\cdot \\tb{b}=||\\tb{a}||\\tb{b}||\\cos\\theta}\\]\n\nUnit vector $\\tb{u}$ given by the following because the line $l$ can be represented by $\\begin{bmatrix}\n    1\\\\m\n\\end{bmatrix}$:\n\n\\[\\tb{u}=\\frac{1}{\\sqrt{1+m^2}}\\begin{bmatrix}\n    1\\\\m\n\\end{bmatrix}\\]\n\nThe projection matrix, onto a line of slope $m$:\n\n\\[\n    \\mathrm{proj}_l(\\tb{v})=(\\tb{u}\\cdot \\tb{v})\\tb{u} = \n    \\begin{bmatrix}\\frac{v_1+v_2m}{1+m^2}\\\\\\frac{v_1m+v_2m^2}{1+m^2} \\end{bmatrix}  \n\\]\n\nThus,\n\n\\[A=\n    \\begin{bmatrix}\\frac{1}{1+m^2}&\\frac{m}{1+m^2}\\\\\\frac{m}{1+m^2}&\\frac{m^2}{1+m^2}\\end{bmatrix}\n\\]\n\nGeneral projection matrix given $a^2+b^2=1$:\n\n\\[\\boxed{\n    A= \\begin{bmatrix}a^2&ab\\\\ ab&b^2\\end{bmatrix}\n}\\]\n\n\\subsection{Reflections}\n\nGiven by:\n\n\\[\\mathrm{refl}_l(\\tb{v})=2\\mathrm{proj}_l(\\tb{v})-\\tb{v}\\]\n\nHas the matrix $A$:\n\n\\[A= \\begin{bmatrix}\\frac{1-m^2}{1+m^2}&\\frac{2m}{1+m^2}\\\\\\frac{2m}{1+m^2}&\\frac{m^2-1}{1+m^2}\\end{bmatrix}\\]\n\nIf $a^2+b^2=1$:\n\n\\[\\boxed{\n    A= \\begin{bmatrix}a&b\\\\ b&-a\\end{bmatrix}\n}\\]\n\n\\subsection{Shear}\n\nHorizontal:\n\n\\[A= \\begin{bmatrix}1&k\\\\ 0&1\\end{bmatrix}\\]\n\nVertical:\n\n\\[A= \\begin{bmatrix}1&0\\\\ k&1\\end{bmatrix}\\]\n", "meta": {"hexsha": "f63644f1204c83c934f48e01140616ab6c621762", "size": 2484, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/7_transformations-geometry.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/7_transformations-geometry.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/7_transformations-geometry.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": 19.872, "max_line_length": 109, "alphanum_fraction": 0.6006441224, "num_tokens": 1043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533107374443, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7770362758877455}}
{"text": "\\section{Recap}\n\\begin{align}\n    \\rho &= \\frac{e^{-\\beta H}}{Z}\n\\end{align}\nwhere\n\\begin{align}\n    Z &= \\Tr e^{-\\beta H}\n\\end{align}\nand for any operator $\\mathcal{O}$,\n\\begin{align}\n    \\bar{\\mathcal{O}} &= \\Tr(\\rho\\mathcal{O})\n\\end{align}\nand if it's a continuous system,\n\\begin{align}\n    \\rho(q, p) &=\n    \\frac{e^{-\\beta H(q, p)}}{Z}\n\\end{align}\nand the partition function is\n\\begin{align}\n    Z &=\n    \\frac{\\int d^Nq d^Np e^{-\\beta H(q, p)}}{h^N n!}\n\\end{align}\n\n\\begin{example}[Harmonic oscillator]\n    The partition function is\n    \\begin{align}\n        Z &=\n        \\sum_{n=0}^{\\infty} \\bra{n} e^{-\\beta H} \\ket{n}\\\\\n        &=\n        \\sum_{n=0}^{\\infty} e^{-\\beta\\hbar\\omega\\left( n + \\frac{1}{2}\n        \\right)}\\\\\n        &=\n        e^{-\\beta \\hbar\\omega/2}\n        \\sum_{n=0}^{\\infty} \\left( e^{-\\beta \\hbar \\omega} \\right)^n\\\\\n        &=\n        \\frac{1}{e^{\\beta \\hbar\\omega/2} + e^{-\\beta\\hbar\\omega/2}}\\\\\n        &=\n        \\frac{1}{2}\n        \\frac{1}{\\sinh\\left(\\beta\\hbar\\omega/2 \\right)}\n    \\end{align}\n    So then the average energy is\n    \\begin{align}\n        \\bar{E} &= \\Tr(\\rho H)\\\\\n        &= \\frac{1}{Z} \\sum_{n=0}^{\\infty}\n        \\bra{n} e^{-\\beta H} H \\ket{n}\\\\\n        &=\n        \\frac{1}{Z} \\sum_{n=0}^{\\infty}\n        E_n e^{-\\beta E_n}\\\\\n        &= \\frac{1}{Z}\\left( -\\frac{\\partial}{\\partial\\beta} \\right) Z\\\\\n        &=\n        -\\frac{\\partial}{\\partial\\beta}\\ln Z\\\\\n        &=\n        \\frac{\\partial}{\\partial\\beta}\n        \\ln\\left( \n            Z \\sinh(\\beta\\hbar\\omega/2)\n        \\right)\\\\\n        &=\n        \\frac{\\cosh(\\beta\\hbar\\omega/2)}{\\sinh(\\beta\\hbar\\omega/2)}\n        \\frac{\\hbar\\omega}{2}\n    \\end{align}\n\\end{example}\n\nIn the high temperature limit $k_B T \\ge \\hbar\\omega$,\nthis expression approaches\n\\begin{align}\n    \\bar{E} \\to k_B T\n\\end{align}\nAt high energy,\nit doesn't matter what the energy is,\nthe energy is just going to be given by the thermal energy.\nYou might know this result from somewhere right?\nIt's closely related to the equipartition theorem.\n\nIn the low-temperature limit,\n\\begin{align}\n    \\bar{E} &=\n    \\hbar\\omega\n    \\frac{1 + e^{-\\beta\\hbar\\omega}}{1 + e^{-\\beta\\hbar\\omega}}\\\\\n    &\\approx\n    \\frac{\\hbar\\omega}{2}\\left(\n        1 + 2e^{-\\beta\\hbar\\omega} + \\cdots\n    \\right)\n\\end{align}\nso no matter how low temperature you get,\nyou can't get lower than $\\hbar\\omega/2$,\nwhich is the \\emph{zero point energy}.\nThe excitations are exponentially small.\n\nThis is how quantum mechanics was invented by the way.\nIf you have a cavity,\neach mode behaves like a harmonic oscillator.\nThe only thing with different wave lengths is that the frequency changes.\nEvery mode of the EM rays inside the black body is going to contribute some\nenergy $k_B T$,\nbut there's an infinite number of modes,\nbecause I can make them smaller,\nso this $\\bar{E} = k_B T$ must be wrong.\n\nThe correct QM calculation is that no matter how high $T$ is,\nwhen $\\omega$ is large enough,\nit stays very close to the ground state,\nexponentially so.\nNo matter what the temperature is,\nfor the high energy modes,\nthey stay in the ground state,\nand they shut off,\nand that's how QM saves it.\n\nThere's so much physics to talk about.\nIn a certain way,\nwe're going to derive this result over and over again,\nand get all amazing results.\n\nFor example,\nget a metal piece reasonably cold.\nBy metal,\nI mean a non-conducting crystal,\nso a salt,\na rock.\nThe goal of this class is that you can run this calculation in your head\nimmediately.\nWe're going to derive this result,\nhand it to your previous self and tell me how are you going to derive it.\nHere we're still understanding the formalism.\n\nHow let's go back to the classical harmonic oscillator\nand the classical calculator..\n\n\\begin{example}[Classical harmonic oscillator]\n    Let's say we have a simple harmonic oscillator\n    \\begin{align}\n        H(x, p) &=\n        \\frac{p^2}{2m} + \\frac{m\\omega^2}{2}x^2\n    \\end{align}\n    and the partition function should be an integral\n    \\begin{align}\n        Z &=\n        \\int_{-\\infty}^{\\infty}\\frac{dx\\,dp}{h}\n        e^{-\\beta\\left(\n            \\frac{p^2}{2m} + \\frac{m\\omega^2}{2}x^2\n        \\right)}\n    \\end{align}\n    which is a Gaussian integral.\n\\end{example}\nMy intent for today was to give you homework was to show you how to do a\nGaussian integral,\nbut you have a midterm,\nso it's next week.\nMy opinion is that every integral should be done by computer,\nbut this one is worth known.\n\nSuppose you are stuck on an island.\nThe only way out is to build a steam engine out of coconuts and bananas.\nTo build a steam engine,\nyou need to know thermodynamics,\nand so you need to calculate partition functions,\nso you need to know how to calculate Gaussian integrals.\n\nRemember this one\n\\begin{align}\n    Z = \\frac{1}{h}\n    \\int_{-\\infty}^{\\infty} dx\\,\n    e^{\\frac{-\\beta m\\omega^2}{2} x^2}\n    \\int_{-\\infty}^{\\infty} dp\\,\n    e^{\\frac{-\\beta p^2}{2}}\n\\end{align}\nLook at the first integral. By dimension analysis,\nthere's only one thing it could depend on,\nbecause $x$ is of units lengths,\nand the argument of the exponential is dimensionless,\nso $1/\\sqrt{\\beta m \\omega^2}$ has units of length.\n\\begin{align}\n    \\int_{-\\infty}^{\\infty} dx\\,\n    e^{\\frac{-\\beta\\hbar\\omega^2}{2} x^2}\n    \\propto\n    \\frac{1}{\\sqrt{\\beta m \\omega}}\n\\end{align}\nup to some dimensionless constant, and it happens to be\n\\begin{align}\n    \\int_{-\\infty}^{\\infty} dx\\,\n    e^{\\frac{-\\beta\\hbar\\omega^2}{2} x^2}\n    &=\n    \\sqrt{\\frac{2\\pi k_B T}{\\omega^2}}\n\\end{align}\nand\n\\begin{align}\n    \\int_{-\\infty}^{\\infty} dp\\,\n    e^{\\frac{-\\beta p^2}{2}}\n    &=\n    \\sqrt{2\\pi m k_B T}\n\\end{align}\nso\n\\begin{align}\n    Z &= \\frac{k_B T}{\\hbar \\omega}.\n\\end{align}\nRelax about the $\\hbar$, it's just a constant that cancels out when\nyou calculate expectations!\n\nSo if you're stuck on an island and your life depends it,\nyou'll know.\n\nOne thing you'll learn in this course is how to take derivatives with logs.\n\\begin{align}\n    \\bar{E} &=\n    \\frac{1}{Z} \\int dx\\,dp\\,\n    e^{-\\beta H} H\\\\\n    &=\n    \\frac{1}{Z}\\left( \\frac{-\\partial}{\\partial\\beta} \\right)Z\\\\\n    &=\n    -\\frac{\\partial}{\\partial \\beta}Z\\\\\n    &= -\\frac{\\partial}{\\partial\\beta}\\ln Z\\\\\n    &=\n    \\frac{\\partial}{\\partial\\beta} \\ln(\\beta\\hbar\\omega)\\\\\n    &=\n    \\frac{1}{\\beta}\\\\\n    &= k_B T\n\\end{align}\nwhich is not surprising as you did the quantum calculation\nand showed this is the high energy limit.\n\nThat's why there's a delivery of liquid nitrogen and once in a blue moon liquid\nhelium,\nbecause people want to do experiments at low energy.\n\n\nIn the old days, the notation $\\langle E\\rangle$ was common,\nand Dirac decided to break it up into $\\bra{\\psi}E\\ket{\\psi}$.\n\nRecall how to compute the variance.\n\\begin{align}\n    \\overline{(E - \\overline{E})^2}\n    &=\n    \\overline{E^2} - \\overline{E}^2\\\\\n    &=\n    \\frac{1}{Z} \\int dx\\,dp\\,\n    e^{-\\beta H} H^2\n    -\\left( \n        \\int dx\\, dp\n        \\frac{e^{-\\beta H}}{Z} H\n    \\right)^2\\\\\n    &= \\frac{\\partial^2}{\\partial\\beta^2} \\ln Z\\\\\n    &= \\left( k_B T \\right)^2\n\\end{align}\nNow if you recall,\n\\begin{align}\n    \\frac{\\partial}{\\partial\\beta} \\ln Z\n    &=\n    \\frac{1}{Z} \\frac{\\partial}{\\partial\\beta} Z\\\\\n    \\frac{\\partial^2}{\\partial\\beta^2} \\ln Z &=\n    - \\frac{1}{Z^2}\\left( \\frac{\\partial^2 Z}{\\partial \\beta^2} \\right)\n\\end{align}\nStudent: Stop!\nYou want me to copy how to do second derivatives of a log?\n\nAnyway,\nso I'm going to consider the spread of energy,\nthe noise to signal ratio,\n\\begin{align}\n    \\frac{\\sqrt{\\overline{(E - \\overbar{E})^2}}}{\\bar{E}} = 1\n\\end{align}\nwhich is not good,\nbecause there's so much fluctuation.\nBut it's no good doing statistical mechanics on just one single harmonic\noscillator,\nwe need many more.\n\nLet me do $N$ harmonic oscillators.\nInstead of having just 1 $x$ and one $p$,\nI'm going to have $N$ $x$s and $N$ $p$s.\nSo Hamiltonian is\n\\begin{align}\n    H(x, p) &=\n    \\frac{p_1^2}{2m}\n    + \\frac{m\\omega^2}{2} x_1^2\n    \\frac{p_2^2}{2m}\n    + \\frac{m\\omega^2}{2} x_2^2\n    + \\cdots\n\\end{align}\nand so we get a product\n\\begin{align}\n    Z &=\n    \\prod_{i=1}^{N}\\int_{-\\infty}^{\\infty}\\frac{dx_i\\,dp_i}{h}\n    e^{-\\beta\\left(\n        \\frac{p_i^2}{2m} + \\frac{m\\omega^2}{2}x_i^2\n    \\right)}\n\\end{align}\nAnd if you follow the steps,\nyou get\n\\begin{align}\n    \\overline{(E - \\overline{E})^2} = N(k_B T)^2\n\\end{align}\nand the noise to signal ratio drops to\n\\begin{align}\n    \\frac{\\sqrt{\\overline{(E - \\overbar{E})^2}}}{\\bar{E}} = \n    \\frac{\\sqrt{N} k_B T}{N k_B T}\\\\\n    = \\frac{1}{\\sqrt{N}}\n\\end{align}\nso if you have $10^{23}$ particles,\nthe fluctuation in total energy is very very small,\nand that's why statistical mechanics works.\n", "meta": {"hexsha": "8be45f19ebe3cc753a11a1718b43b310ad81933e", "size": 8631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys612/lecture14.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/lecture14.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/lecture14.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.6744186047, "max_line_length": 79, "alphanum_fraction": 0.6284323949, "num_tokens": 2902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533051062237, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7770362750548941}}
{"text": "\n\\subsection{Hidden layers}\n\nIn the perceptron we have input vector \\(x\\), and output:\n\n\\(a=a(wx)\\)\n\nWe can augment the perceptron by adding a hidden layer.\n\nNow the output on the activation function is an input to a second layer. By using different weights, we can create a second vector of inputs to the second layer.\n\n\\subsubsection{The parameters of a feed forward model}\n\n\\(\\Theta^{j}\\) is a matrix of weights for mapping layer \\(j\\) to \\(j+1\\). So we have \\(\\Theta^1\\) and \\(\\Theta^2\\).\n\nIf we have \\(s\\) units in the hidden layer, \\(n\\) features and \\(k\\) classes:\n\n\\begin{itemize}\n\\item The dimension of \\(\\Theta^1\\) is \\((n+1) \\times s\\)\n\\item The dimension of \\(\\Theta^2\\) is \\((s+1) \\times k\\)\n\\end{itemize}\n\nThese include the offsets for each layer.\n\n\\subsubsection{The activation function of a multi-layer perceptron}\n\nFor a perceptron we had \\(a=f(wx)\\). Now we have:\n\n\\(a_i^j=f(a_{j-1}\\Theta_{j-1})\\)\n\nWe refer to the value of a node as \\(a_i^{j}\\), the activation of unit \\(i\\) in layer \\(j\\).\n\n\\subsubsection{Initialising parameters}\n\nWe start by randomly initialisng the value of each \\(\\theta \\).\n\nWe do this to prevent each neuron from moving in sync.\n\n", "meta": {"hexsha": "5aee290ae4042ea297b91b899a4b2c790e25da14", "size": 1173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/neuralNetworks/01-01-hiddenLayers.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/neuralNetworks/01-01-hiddenLayers.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/neuralNetworks/01-01-hiddenLayers.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.0769230769, "max_line_length": 161, "alphanum_fraction": 0.6965046888, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109784205502, "lm_q2_score": 0.8175744739711883, "lm_q1q2_score": 0.7770317557386237}}
{"text": "\\subsection{Fubini's Theorem \\& Domain Regions}\r\n\\begin{theorem}[Fubini's Theorem]\r\n\tThe order of integration on a domain where the variables of integration $\\left(x, y, \\text{etc.}\\right)$ vary independently doesn't matter.\r\n\\end{theorem}\r\n\r\n\\noindent\r\nFor example, let's find the volume under $f(x,y) = 9-x^2-y^2$, $(x,y) \\in [0,1] \\times [1,2]$.\\\\\r\nWe will do so in two ways to show that they are equivalent: one with $x$ first and then $y$ and another with $y$ first and then $x$.\\\\\r\n\\begin{center}\r\n\t\\begin{tabular}{c|c}\r\n\t\t$V = \\int_{0}^{1}{\\int_{1}^{2}{9 - x^2 - y^2\\mathrm{d}y}\\mathrm{d}x}$ & $V =\\int_{2}^{1}{\\int_{0}^{1}{9 - x^2 - y^2\\mathrm{d}x}\\mathrm{d}y}$ \\\\\r\n\t\t$= \\int_{0}^{1}{\\left[9y - x^2y - \\frac{y^2}{3}\\right]_{1}^{2}\\mathrm{d}x}$ & $= \\int_{1}^{2}{\\left[9x - \\frac{x^3}{3} - xy^2\\right]_{0}^{1}\\mathrm{d}y}$ \\\\\r\n\t\t$= \\int_{0}^{1}{\\frac{20}{3} - x^2\\mathrm{d}x}$ & $= \\int_{1}^{2}{\\frac{26}{3} - y^2\\mathrm{d}y}$ \\\\\r\n\t\t$= \\left[\\frac{20}{3}x - \\frac{x^3}{3}\\right]_{0}^{1}$ & $= \\left[\\frac{26}{3}y - \\frac{y^3}{3}\\right]_{1}^{2}$ \\\\\r\n\t\t$= \\frac{19}{3}$ & $= \\frac{19}{3}$ \\\\\r\n\t\\end{tabular}\r\n\\end{center}\r\n\r\n\\noindent\r\nLet's look at a case where $x$ and $y$ are not independent. specifically, where the bounds on $y$ are a function of $x$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis is called a Type I Region. Formally, a Type I Region is a domain $D = \\left\\{ (x,y) \\mid a \\leq x \\leq b, g(x) \\leq y \\leq h(x) \\right\\}$.\\\\\r\n\r\n\\begin{theorem}[Fubini's Theorem for Type I Regions]\r\n\tLet $D$ be a Type I Region in $\\mathbb{R}^2$.\\\\\r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{D}{f(x,y)\\mathrm{d}A} = \\int_{a}^{b}{\\int_{g(x)}^{h(x)}{f(x,y)\\mathrm{d}y}\\mathrm{d}x}\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\noindent\r\nIt's also possible for y to have constant bounds and the bound for $x$ to be a function of $y$. this is a Type II Region. Formally, a Type II Region is a domain $D = \\left\\{(x,y) \\mid g(y) \\leq x \\leq h(y), a \\leq y \\leq b\\right\\}$.\r\n\r\n\\begin{theorem}[Fubini's Theorem for Type II Regions]\r\n\tLet $D$ be a Type II Region in $\\mathbb{R}^2$.\r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{D}{f(x,y)\\mathrm{d}A} = \\int_{a}^{b}{\\int_{g(y)}^{h(y)}{f(x,y)\\mathrm{d}x}\\mathrm{d}y}\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\noindent\r\nSometimes, a region can be describes as both Type I and Type II. You should pick whichever description is most convenient.\\\\\r\n\r\n\\noindent\r\nThe previous two theorems can be summarized as dependent variables need to be integrated before the variables that they depend on. This core idea extends into higher dimensions where classifying regions becomes tedious and not very helpful.\\\\\r\n\r\n\\noindent\r\nOne can split larger, harder to describe domains into smaller domains. Let $D_1 \\cup D_2 = D$.\r\n\r\n[INSERT IMAGE]\r\n\r\n\\begin{equation*}\r\n\t\\iint\\limits_{D}{f(x,y)\\mathrm{d}A} = \\iint\\limits_{D_1}{f(x,y)\\mathrm{d}A} + \\iint\\limits_{D_2}{f(x,y)\\mathrm{d}A} - \\iint\\limits_{D_1 \\cap D_2}{f(x,y)\\mathrm{d}A}\r\n\\end{equation*}", "meta": {"hexsha": "4012051c9639cf109d7e19a9ae4a6ad4c255944a", "size": 2940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/domainRegionsFubinisTheorem.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/multipleIntegrals/domainRegionsFubinisTheorem.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/multipleIntegrals/domainRegionsFubinisTheorem.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.5789473684, "max_line_length": 243, "alphanum_fraction": 0.631292517, "num_tokens": 1143, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870046160257, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.7770022614489136}}
{"text": "\\section{Definition and equality}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Identify the dimension and entries of a matrix.\n  \\item Check equality of matrices.\n  \\end{enumerate}\n\\end{outcome}\n\nWe have solved systems of equations by writing them in terms of an\naugmented matrix and then doing row operations. It turns out that\nmatrices are important not only for systems of equations but also for\nmany other purposes.\n\n\\begin{definition}{Matrix}{matrix}\n  A \\textbf{matrix}%\n  \\index{matrix} is a rectangular array of numbers\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cccc}\n      a_{11} & a_{12} & \\cdots & a_{1n} \\\\\n      a_{21} & a_{22} & \\cdots & a_{2n} \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      a_{m1} & a_{m2} & \\cdots & a_{mn} \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  where the $a_{ij}$ are scalars, called the \\textbf{entries}%\n  \\index{matrix!entry of}%\n  \\index{entry of a matrix} or \\textbf{components}%\n  \\index{matrix!component of}%\n  \\index{component!of a matrix} of $A$.  The \\textbf{size}%\n  \\index{matrix!size of}%\n  \\index{size of a matrix} or \\textbf{dimension}%\n  \\index{matrix!dimension of}%\n  \\index{dimension!of a matrix} of a matrix is defined as $m\\times n$,\n  where $m$ is the number of rows and $n$ is the number of columns.\n\\end{definition}\n\nFor example, here is a $3\\times 4$-matrix (pronounced ``three-by-four\nmatrix''):\n\\begin{equation*}\n  \\begin{mymatrix}{rrrr}\n    1 & 2 & 3 & 4 \\\\\n    5 & 2 & 8 & 7 \\\\\n    6 & -9 & 1 & 2\n  \\end{mymatrix}.\n\\end{equation*}\nThis is a $3\\times 4$-matrix because there are three rows and four\ncolumns. When specifying the size of a matrix, we always list the\nnumber of rows before the number of columns.\n\nEntries of the matrix are identified according to their position. The\n\\textbf{$(i,j)$-entry}%\n\\index{matrix!ij-entry@$(i,j)$-entry}%\n\\index{ij-entry of a matrix@$(i,j)$-entry of a matrix} of a matrix is\nthe entry in the $i\\th$ row and $j\\th$ column, and is often denoted\n$a_{ij}$. For example, in the above matrix, the $(2,3)$-entry is the\nentry in the second row and the third column, and is equal to $8$. We\nsometimes use $A=\\mat{a_{ij}}$ as a short-hand notation for the entire\n$m\\times n$-matrix whose $(i,j)$-entry is equal to $a_{ij}$ for all\n$i=1,\\ldots m$ and $j=1,\\ldots,n$.\n\nThere are various operations which are done on matrices of appropriate\nsizes. Matrices can be added and subtracted, multiplied by a scalar,\nand multiplied by other matrices. We will never divide a matrix by\nanother matrix, but we will see later how matrix inverses play a\nsimilar role.\n\n\\begin{definition}{Equality of matrices}{matrix-equality}\n  Two matrices are \\textbf{equal}%\n  \\index{matrix!equality}%\n  \\index{equality!of matrices} if they have the same size and the same\n  corresponding entries. More precisely, if $A=\\mat{a_{ij}}$ and\n  $B=\\mat{b_{ij}}$ are two $m\\times n$-matrices, then $A=B$ means that\n  $a_{ij}=b_{ij}$ for all $i=1,\\ldots m$ and $j=1,\\ldots,n$.\n\\end{definition}\n\nFor example,\n\\begin{equation*}\n  \\begin{mymatrix}{rr}\n    0 & 0 \\\\\n    0 & 0 \\\\\n    0 & 0\n  \\end{mymatrix} \\neq \\begin{mymatrix}{rr}\n    0 & 0 \\\\\n    0 & 0\n  \\end{mymatrix}\n\\end{equation*}\nbecause they are different sizes.\nAlso,\n\\begin{equation*}\n  \\begin{mymatrix}{rr}\n    0 & 1 \\\\\n    3 & 2\n  \\end{mymatrix} \\neq \\begin{mymatrix}{rr}\n    1 & 0 \\\\\n    2 & 3\n  \\end{mymatrix}\n\\end{equation*}\nbecause, although they are the same size, their corresponding entries are not identical.\n\nThere are special names for matrices of certain dimensions: some\nmatrices are called square matrices, columns vectors, or row vectors.\n\n\\begin{definition}{Square matrix}{square-matrix}\n  A matrix of size $n\\times n$ is called a \\textbf{square matrix}%\n  \\index{matrix!square}%\n  \\index{square matrix}.  In other words, $A$ is a square matrix if it\n  has the same number of rows and columns.\n\\end{definition}\n\n\\begin{definition}{Column vectors and row vectors}{row-and-column-vectors}\n  A matrix of size $n\\times 1$ is called a \\textbf{column vector}%\n  \\index{vector!column vector}%\n  \\index{column vector}. A matrix of size $1\\times n$ is called a\n  \\textbf{row vector}%\n  \\index{vector!row vector}%\n  \\index{row vector}.  Here is an example of a column vector $X$ and a\n  row vector $Y$:\n  \\begin{equation*}\n    X=\\begin{mymatrix}{c}\n      x_1 \\\\\n      \\vdots \\\\\n      x_n\n    \\end{mymatrix},\n    \\quad\n    Y = \\begin{mymatrix}{ccc}\n      y_1 & \\cdots & y_n\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{definition}\n\nWe have already encountered column vectors in\nChapter~\\ref{cha:vectors-rn}.  When we use the term \\textbf{vector}\nwithout further qualification, we always mean a column vector. Also\nrecall from Definition~\\ref{def:column-vector} that the set of\n$n$-dimensional column vectors is called $\\R^n$.\n", "meta": {"hexsha": "bf99c95178c57e73be32fd454e8646e4fa5f6dbe", "size": 4754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Matrices-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Matrices-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Matrices-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.700729927, "max_line_length": 88, "alphanum_fraction": 0.6874211191, "num_tokens": 1532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869884059266, "lm_q2_score": 0.8872045892435129, "lm_q1q2_score": 0.7770022353134933}}
{"text": "\\section{Count Regressions}\n\nCount data is common, and often incorrectly analyzed using ordinary least squares. In general, least squares is only applicable when the error on the data, or a transformation of the data, has normal distribution with uniform variance. Count data tends to defy that expectation, especially for low counts. Count data also tends to be heteroskedastic: higher counts tend to fluctuate more widely.\n\n\\begin{itemize}\n\\item The data is strictly positive. OLS models can predict negative values.\n\\item Especially for low counts, the distribution is highly skewed\n\\item The data is discrete, not continuous.\n\\item The fluctuation on the mean is not constant. The data is heteroskedastic. \n\\end{itemize}\n\nThe definite resource for modeling count data is \\citeasnoun{hilbe2014modeling}.\n\n\n\\subsection{Poisson Regression Models}\nPoisson models tend to be the first pass at modeling count data, perhaps analogous to how ordinary least squares (OLS) regression is the first pass at modeling continuous data. Poisson models distinguish themselves, in general, by assuming that the fluctuation of the data about the mean has Poisson distribution.\n\n\n\\subsubsection{``Ordinary\" Poisson Regression}\nThe term Poisson regression tends to be used interchangeably with a specific type of model, which is a generalized linear model with Poisson noise and log link. A concise reference for those models is chapter 4 in \\citeasnoun{rodriguez2007generalized}.\n\nSpecifically, the likelihood of observing a value $y$ is assumed to follow a Poisson distribution:\n\n\\begin{equation}\np(y|\\mu) = \\frac{e^{-\\mu} \\mu^{y}}{y!}\n\\end{equation}\n\nWhere the only parameter, $\\mu$, is both the mean and the variance of the Poisson distribution. The model acquires additional structure when $\\mu$ is assumed to be a function of some explanatory variables, $x$, i.e. $\\mu = f(x)$. The canonical Poisson regression uses a log-linear relationship between the coefficients and the mean, i.e. $\\mu = e^{\\mathbf{\\beta \\cdot x}}$. The result is a generalized linear model with Poisson error and link log.\n\nThe assumptions of this \"ordinary Poisson regression\" (my idea to call it that) are: \n\\begin{itemize}\n\\item The error has Poisson distribution.\n\\item The data is strictly positive.\n\\item The data has discrete distribution (though the generalization to continuous numbers is pretty trivial)\n\\item The data is i.i.d., meaning that the observed count events are results of independent trials. (Example: the number of kids in a family is unaffected by the number of kids the neighbors have)\n\\end{itemize}\n\nAnd, very importantly:\n\\begin{itemize}\n\\item It is a log-linear model! The relationship between the dependent variable ($Y$) and the independent variables is log linear. I.e. $ln(Y)$ is a linear function of the coefficients.\n\\item The distribution of the data is heteroskedastic so that the mean equals the variance. The Poisson distribution only has one parameter and (i.e. $\\mu = \\sigma$)!\n\\end{itemize}\n\nIn the model, the likelihood of observing a value $y$ is assumed to follow a Poisson distribution:\n\n\\begin{equation}\np(y|\\mu) = \\frac{e^{-\\mu} \\mu^{y}}{y!}\n\\end{equation}\n\nWhere the only parameter, $\\mu$, is both the mean and the variance of the Poisson distribution. The model acquires additional structure when $\\mu$ is assumed to be a function of some explanatory variables, $x$, i.e. $\\mu = f(x)$. The canonical Poisson regression uses a log-linear relationship between the coefficients and the mean, i.e. $\\mu = e^{\\mathbf{\\beta \\cdot x}}$. The result is a generalized linear model with Poisson error and link log.\n\n\\begin{equation}\np(y|\\mathbf{x};\\mathbf{\\beta}) = \\frac{e^{-\\exp(\\mathbf{\\beta\\cdot x})} (\\exp(\\mathbf{\\beta\\cdot x}))^{y}}{y!}\n\\end{equation}\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{poissonmodels02.png}\n    \\caption{Left: Ordinary Poisson Regression on data that satisfies the assumptions of the model. For small rates, the model is approximately linear, but beyond that it shows exponential growth because of the log-link. Right: Residuals showing heteroskedasticity with variance increasing with the mean. Dividing the residuals by the mean yields constant variance.}\n    \\label{fig:ordinarypoisson}\n\\end{figure}\n\n\n\\subsubsection{Poisson Noise \\& Central Limit Theorem}\n\nFor small count rates, the Poisson distribution is highly skewed and strictly positive. For large count rates, the Poisson distribution is essentially normal, except that variance and mean are locked.\n\nIf you are dealing with large counts, then the Poisson model still has the feature of being heteroskedastic.\n\n\\subparagraph{Advantages of using Poisson Noise}\n\n\\begin{itemize}\n\\item The Poisson Distribution is highly skewed for small rates, and strictly positive. For high enough count rates, this advantage disappears.\n\\item The Poisson Distribution is heteroskedastic\n\\end{itemize}\n\n\\subparagraph{Drawbacks of using Poisson Noise}\n\n\\begin{itemize}\n\\item The Poisson distribution only has a single parameter. The assumption that the mean and the variance are the same is very restrictive.\n\\end{itemize}\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{poissonmodels01.png}\n    \\caption{Left: The Poisson Distribution for small rates is highly skewed. Right: The Poisson Distribution for intermediate rates looks very similar to a normal distribution. In both cases, the variance and the mean are the same value.}\n    \\label{fig:poissonandcentrallimit}\n\\end{figure}\n\n\n\\subsubsection{Poisson Noise Analogy to Least Squares Regression}\nTo anchor intuition in familiar territory, consider least squares regression with a log-linear relationship between endogenous and exogenous variables (that is, the model assumes a relationship of $log(y)=a + \\mathbf{bx}$ that is beset with Gaussian noise). The familiar form for the model is:\n\n\\begin{equation}\n\\begin{array}{rl}\ny &= a\\exp{\\mathbf{b \\cdot x}} + \\epsilon \\\\\n&= \\exp\\mathbf{\\beta \\cdot x} + \\epsilon\n\\end{array}\n\\end{equation}\n\nWhere the constant $a$ was absorbed into the coefficient vector $\\mathbf{\\beta}$ in the second line, and $\\mathbf{x} \\rightarrow [1,\\mathbf{x}]$. $\\epsilon$ is an error term that is assumed to have normal distribution with zero mean, i.e. $\\epsilon \\sim \\mathscr{N}(0,\\sigma)$. It's a bit unnatural, but this can be rewritten, absorbing the parameters into the random term:\n\n\\begin{equation}\ny = 0 + \\epsilon'\n\\end{equation}\n\nWith $\\epsilon' \\sim \\mathscr{N}(\\mu = \\exp{\\mathbf{\\beta \\cdot x}},\\sigma)$. Now what if the fluctuations aren't normally distributed about the mean, but they are Poisson distributed about the mean? In that case, $\\epsilon' \\sim \\mathrm{Poisson}(\\mu = \\exp{\\mathbf{\\beta \\cdot x}})$. \n\n\n\n\\subsubsection{Multivariate Poisson Model}\nFor least squared regression, it's totally common to look at multivariate models with interesting codependence structure captured by a covariance matrix. In analogy to that, there is multivariate Poisson Regression. The math looks quite different. \n\n\\url{http://www2.stat-athens.aueb.gr/~karlis/multivariate%20Poisson%20models.pdf}\n\n\\subsubsection{Goodness of Fit}\nThe Poisson deviance is given by:\n\n\\begin{equation}\nD = 2\\sum\\left\\{ y_i \\log\\left( \\frac{y_i}{\\hat{\\mu}_i} \\right) - \\left( y_i - \\hat{\\mu}_i \\right) \\right\\}\n\\end{equation}\n\nHere, $\\hat{\\mu}_i = e^{\\mathbf{x}^T_i \\hat{\\mathbf{\\beta}}}$ is the fitted mean of the $i$th data point, and $y_i$ is the observed count of the $i$th datapoint. \n\nFor large sample sizes, the deviance will be distributed approximately chi-squared with $n-p$ degrees of freedom, where $n$ is the number of data points and $p$ is the number of features. An alternative to the deviance is Pearson's chi-squared statistic. \n\n\\subsubsection{General $\\mu = f(\\mathbf{x})$}\nThe Poisson-ness only has to do with how the data fluctuates about the mean. How the mean is expected to depend on the explanatory variables is another question. In so far, general other functions, including highly-nonlinear machine learning models, can be fit under the assumption of Poisson noise.\n\nXGBoost supports poisson loss. Empirically, it seems that Poisson loss performs worse in the regime where the model is underfitting, and slightly better in the regime where the model is overfitting. The difference is especially pronounced in the Poisson deviance and for sparse data.\n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{poissonmodels03.png}\n    \\caption{Left: Ordinary Poisson Regression on data that satisfies the assumptions of the model. For small rates, the model is approximately linear, but beyond that it shows exponential growth because of the log-link. Right: Residuals showing heteroskedasticity with variance increasing with the mean. Dividing the residuals by the mean yields constant variance.}\n    \\label{fig:ordinarypoisson}\n\\end{figure}", "meta": {"hexsha": "a47e23722900ba2fdfb90290e525a1f679c61c14", "size": 8865, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/reg_countregressions.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/reg_countregressions.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/reg_countregressions.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": 63.3214285714, "max_line_length": 447, "alphanum_fraction": 0.7721376199, "num_tokens": 2185, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.7770022324371582}}
{"text": "\\section{Low Power Design}\n\\begin{itemize}\n\t\\item $\\alpha$ switching activity\n\t\\item $C_L$ load capacity\n\t\\item $f$ clock frequency\n\t\\item $V_{dd}$ supply voltage\n\t\\item $V_T$ threshold voltage ($V_T \\ll V_{dd}$)\n\\end{itemize}\n\\begin{align*}\n\tP &\\sim \\alpha C_L V_{dd}^2 f \\\\\n\t\\tau &\\sim C_L \\frac{V_{dd}}{\\left(V_{dd} - V_{T}\\right)^2} \\\\\n\tf_{max} &\\sim V_{dd} \\\\\n\tE &\\sim \\alpha C_L V_{dd}^2 \\underbrace{\\left(\\text{\\#cycles}\\right)}_{f \\cdot t}\n\\end{align*}\n\n\\subsection{YDS Algorithm}\nThe YDS algorithm can be use to schadule tasks with dynamic voltage scaling such\nthat the engergy consuption is minimal.\n\nWe define\n\\begin{align*}\n\tV'([z, z']) &= \\set{v_i \\in V: z \\leq a_i < d_i \\leq z'} \\\\\n\tG([z, z']) &= \\sum_{v_i in V'([z,z'])} \\frac{C_i}{z' - z}\n\\end{align*}\n\nAlgorithm:\n\\begin{enumerate}\n\t\\item Calculate intensities\n\t\\item Schedule jobs in highest intensity interval using EDF, intensity as\n\t\tfrequency\n\t\\item Adjust arrival times and deadlines by excluding the interval, restart\n\\end{enumerate}\n\nThe online version continuously updates best schedule for all available tasks.\nIt has at most 27 times higher energy consumption.\n\n\\subsection{DPM}\nWith dpm, make sleep periods as long as possible, reduce the amount of on/off\ntransitions. Use YDS and round frequencies up.\n", "meta": {"hexsha": "25b9282eaf22812a14d89378da3d4a7dcc8c966f", "size": 1282, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "embedded systems/sections/low_power_design.tex", "max_stars_repo_name": "ntruessel/eth-summaries", "max_stars_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "embedded systems/sections/low_power_design.tex", "max_issues_repo_name": "ntruessel/eth-summaries", "max_issues_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "embedded systems/sections/low_power_design.tex", "max_forks_repo_name": "ntruessel/eth-summaries", "max_forks_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.05, "max_line_length": 82, "alphanum_fraction": 0.7059282371, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.7769811968507853}}
{"text": "\n\\subsection{Fourier transforms}\n\n\n\\subsubsection{Fourier transform}\n\n\\(\\hat f(\\Xi )=\\int_{-\\infty}^{\\infty }f(x)e^{-2\\pi ix\\Xi }dx\\) \n\n\\subsubsection{Inverse Fourier transform}\n\n\\(f(x)=\\int_{-\\infty}^{\\infty }\\hat f(\\Xi )e^{2\\pi ix\\Xi }d\\Xi \\)\n\n\\subsubsection{Fourier inversion theorem}\n\n\n", "meta": {"hexsha": "e180071e6f914eb81876f15672bbd6bb98b2dd9b", "size": 290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/03-04-trigFourier.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/03-04-trigFourier.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/03-04-trigFourier.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.125, "max_line_length": 65, "alphanum_fraction": 0.6655172414, "num_tokens": 101, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9643214491222695, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7768883976878436}}
{"text": "\\documentclass[11pt]{amsart}\n\\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}\n\n\\makeatletter\n\\def\\subsection{\\@startsection{subsection}{3}%\n  \\z@{.5\\linespacing\\@plus.7\\linespacing}{.1\\linespacing}%\n  {\\normalfont\\itshape}}\n\\makeatother\n\n\\title{Coordinate Systems}\n\n\\author{Joe Bentley}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\newpage\n\n\\section{Orthogonal Coordinate Systems}\n\nWhen we are looking to construct a new coordinate system, we want to be able to translate between unit vectors and coordinates of both coordinate systems. In this section we can explore how we can construct orthogonal coordinate systems, which is, coordinate systems where the basis are always orthogonal.\n\nFirst, suppose that the Cartesian coordinates $(x, y, z)$ of any point $P$ in space can be expressed as functions of three variables $(u_1, u_2, u_3)$ such that,\n\n\\begin{align*}\n  \\mathbf{r} =\n  \\begin{pmatrix}\n    x \\\\\n    y \\\\\n    z \\\\\n  \\end{pmatrix} =\n  \\begin{pmatrix}\n    x(u_1, u_2, u_3) \\\\\n    y(u_1, u_2, u_3) \\\\\n    z(u_1, u_2, u_3)\n  \\end{pmatrix}\n\\end{align*}\n\nIf each point $P$ corresponds to a \\textit{unique} set of new coordinates $(u_1, u_2, u_3)$ then these are called curvilinear coordinates of $P$. That is, for the coordinates $(u_1, u_2, u_3)$ to be curvilinear, they must be the \\textit{only} set of new coordinates that corresponds to point $P$.\n\nWe know from directional derivatives that $\\frac{\\partial\\mathbf{r}}{\\partial u_1}$, $\\frac{\\partial\\mathbf{r}}{\\partial u_2}$, $\\frac{\\partial\\mathbf{r}}{\\partial u_3}$ are vectors in the directions of increasing $u_1$, $u_2$, and $u_3$ respectively. These may not necessarily be unit vectors, as they might not have a length of unity, so we may write,\n\n\\begin{align*}\n   \\frac{\\partial\\mathbf{r}}{\\partial u_1} = h_1 \\mathbf{e_1} \\qquad \\frac{\\partial\\mathbf{r}}{\\partial u_2} = h_2 \\mathbf{e_2} \\qquad \\frac{\\partial\\mathbf{r}}{\\partial u_3} = h_3 \\mathbf{e_3}\n\\end{align*}\n\nwhere $\\mathbf{e_1}$, $\\mathbf{e_2}$, $\\mathbf{e_3}$ are unit vectors in the directions of increasing $u_1$, $u_2$, and $u_3$ respectively. The quantities $h_1$, $h_2$, and $h_3$ are \\textit{scale factors} which scale the derivative down to unity, such that,\n\n\\begin{align*}\n  \\frac{1}{h_i} \\left|\\frac{\\partial\\mathbf{r}}{\\partial u_i}\\right| = 1\n\\end{align*}\n\nand therefore we can calculate the scale factor $h_i$ by,\n\n\\begin{align*}\n  \\left|\\frac{\\partial\\mathbf{r}}{\\partial u_i}\\right| = h_i\n\\end{align*}\n\n\n\n\nIf our unit vectors $\\mathbf{e_1}$, $\\mathbf{e_2}$, $\\mathbf{e_3}$ are mutually orthogonal, then we have an orthogonal coordinate system.\n\nOne final point is the order the coordinates are written in. This is mathematically arbitrary, but we want to choose coordinates such that,\n\n\\begin{align*}\n  \\hat{\\imath}\\times\\hat{\\jmath}&=\\hat{k}\n\\end{align*}\n\nor in terms of our more general unit vectors,\n\n\\begin{align*}\n  \\mathbf{e_1}\\times\\mathbf{e_2}&=\\mathbf{e_3}\n\\end{align*}\n\nIf the coordinates are our of order, such that for example $\\mathbf{e_1}$ and $\\mathbf{e_2}$ are switched so that the coordinates are written $(u_2, u_1, u_3)$, then the result of the cross product of the first two unit basis vectors will be negative instead of positive. We would prefer them to be positive as this feels more physically intuitive and natural.\n\nIn the next few examples, we will find the unit vectors of various coordinate systems, as well as proving their orthogonality.\n\n\\section{Cylindrical Polar Coordinates}\n\nWe have enough experience in cylindrical polar coordinates to know how to write the Cartesian coordinates $(x, y, z)$ in terms of the cylindrical coordinates $(\\rho, \\phi, z)$,\n\n\\begin{align*}\n  \\mathbf{r} =\n  \\begin{pmatrix}\n    x \\\\\n    y \\\\\n    z\n  \\end{pmatrix} =\n  \\begin{pmatrix}\n    \\rho\\cos\\phi \\\\\n    \\rho\\sin\\phi \\\\\n    z\n  \\end{pmatrix}\n\\end{align*}\n\nHow do we know to order the coordinates $(\\rho, \\phi, z)$? We don't, and we will check their order once finding the unit vectors.\n\nFirst, we want to find the unit basis $\\mathbf{e_{\\rho}}$. We can do this by taking the derivative of the position vector with respect to the coordinate $\\rho$. This will give us a possibly non-unit vector in the direction of changing $\\rho$, which we then need to divide by the scale factor $h_{\\rho}$ to give us the unit basis vector $\\mathbf{e_{\\rho}}$.\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial\\rho} =\n  \\begin{pmatrix}\n    \\cos\\phi \\\\\n    \\sin\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nWe can see here that the result is already a unit vector, as $\\sin^2\\phi + \\cos^2\\phi = 1$. This means that our scale factor $h_{\\rho} = 1$, and our unit basis vector is given by,\n\n\\begin{align*}\n  \\mathbf{e_{\\rho}} =\n  \\begin{pmatrix}\n    \\cos\\phi \\\\\n    \\sin\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nSimilarly, for the $\\phi$ and $z$ coordinates,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial\\phi} = \\rho\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nThis time we see that the result is not a unit vector, but by factoring out $\\rho$, we get the scale factor multiplied by a unit basis vector, therefore we have,\n\n\\begin{align*}\n  h_{\\phi} = \\rho\n\\end{align*}\n\nand\n\n\\begin{align*}\n  \\mathbf{e_{\\phi}} =\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nFinally we have the $z$ coordinate,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial z} =\n  \\begin{pmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{pmatrix} \\to\n  \\mathbf{e_z} =\n  \\begin{pmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{pmatrix}\n\\end{align*}\n\nHere the scale factor again is just $h_z = 1$.\n\nNext we need to check whether these unit basis form an orthogonal coordinate system,\n\n\\begin{alignat*}{2}\n  \\mathbf{e_{\\rho}}\\cdot\\mathbf{e_{\\phi}}&=\n  \\begin{pmatrix}\n    \\cos\\phi \\\\\n    \\sin\\phi \\\\\n    0\n  \\end{pmatrix}\\cdot\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix} &&= 0 \\\\\n  \\mathbf{e_{\\rho}}\\cdot\\mathbf{e_z}&=\n  \\begin{pmatrix}\n    \\cos\\phi \\\\\n    \\sin\\phi \\\\\n    0\n  \\end{pmatrix}\\cdot\n  \\begin{pmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{pmatrix} &&= 0 \\\\\n  \\mathbf{e_{\\phi}}\\cdot\\mathbf{e_z}&=\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix}\\cdot\n  \\begin{pmatrix}\n    0 \\\\\n    0 \\\\\n    1\n  \\end{pmatrix} &&= 0\n\\end{alignat*}\n\nTherefore we have that all the unit basis vectors are mutually orthogonal. Also to check that the order of the coordinates $(\\rho, \\phi, z)$ we calculate the cross product and see that $\\mathbf{e_{\\rho}}\\times\\mathbf{e_{\\phi}}=\\mathbf{e_z}$ although this will not be shown explicitly here as it is simply the cross product of two vectors.\n\n\\section{Spherical Polar Coordinates}\n\nAgain we will take the same approach as last time. This time we know we can write $(x, y, z)$ as $(r, \\theta, \\phi)$ by the relations,\n\n\\begin{align*}\n  \\mathbf{r} =\n  \\begin{pmatrix}\n    r\\sin\\theta\\cos\\phi \\\\\n    r\\sin\\theta\\sin\\phi \\\\\n    r\\cos\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nSo we first take the derivative of the position vector with respect to each coordinate to find the vectors in the direction of each increasing coordinate,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial r} =\n  \\begin{pmatrix}\n    \\sin\\theta\\cos\\phi \\\\\n    \\sin\\theta\\sin\\phi \\\\\n    \\cos\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nBy $\\sin^2\\phi + \\cos^2\\phi = 1$ this again is already a unit vector, so $h_r = 1$ and,\n\n\\begin{align*}\n  \\mathbf{e_r} =\n  \\begin{pmatrix}\n    \\sin\\theta\\cos\\phi \\\\\n    \\sin\\theta\\sin\\phi \\\\\n    \\cos\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nand for the $\\theta$ and $\\phi$ coordinates,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial\\theta} = r\n  \\begin{pmatrix}\n    \\cos\\theta\\cos\\phi \\\\\n    \\cos\\theta\\sin\\phi \\\\\n    -\\sin\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nThe scale factor is $h_{\\theta} = r$ and,\n\n\\begin{align*}\n  \\mathbf{e_{\\theta}} =\n  \\begin{pmatrix}\n    \\cos\\theta\\cos\\phi \\\\\n    \\cos\\theta\\sin\\phi \\\\\n    -\\sin\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nFor the last coordinate $\\phi$,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial\\phi} = r\\sin\\theta\n  \\begin{pmatrix}\n    \\cos\\theta\\cos\\phi \\\\\n    \\cos\\theta\\sin\\phi \\\\\n    -\\sin\\theta\n  \\end{pmatrix}\n\\end{align*}\n\nTherefore this time we have a scale factor of $h_{\\phi} = r\\sin\\theta$ and,\n\n\\begin{align*}\n  \\mathbf{e_{\\phi}} =\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nAgain we check for orthogonality,\n\n\\begin{align*}\n  \\mathbf{e_r}\\cdot\\mathbf{e_{\\theta}} &= 0 \\\\\n  \\mathbf{e_r}\\cdot\\mathbf{e_{\\phi}} &= 0 \\\\\n  \\mathbf{e_{\\phi}}\\cdot\\mathbf{e_{\\theta}} &= 0\n\\end{align*}\n\nAnd finally we check that $(r, \\theta, \\phi)$ is the correct order of the coordinates,\n\n\\begin{align*}\n  \\mathbf{e_r}\\times\\mathbf{e_{\\theta}}=\\mathbf{e_{\\phi}}\n\\end{align*}\n\n\\section{Paraboidal Coordinates}\n\nThe paraboidal coordinate $(u, v, \\phi)$ are related to the cartesian coordinates such that,\n\n\\begin{align*}\n  \\mathbf{r}=\n  \\begin{pmatrix}\n    uv\\cos\\phi \\\\\n    uv\\sin\\phi \\\\\n    \\frac{1}{2}\\left(u_2 - v^2\\right)\n  \\end{pmatrix}\n\\end{align*}\n\nAgain we take the derivatives,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial u} =\n  \\begin{pmatrix}\n    v\\cos\\phi \\\\\n    v\\sin\\phi \\\\\n    u\n  \\end{pmatrix}\n\\end{align*}\n\nThis time, unlike before, finding the scale factor and thus the unit basis vector is not as easy as a simple factorisation to construct the unit vector. This time we must find the modulus of the derivative to give us the scale factor,\n\n\\begin{align*}\n  h_u = \\left|\\frac{\\partial\\mathbf{r}}{\\partial u}\\right| = \\sqrt{u_2 + v_2}\n\\end{align*}\n\nso our unit vector is given by,\n\n\\begin{align*}\n  \\mathbf{e_u} = \\frac{1}{\\sqrt{u^2 + v^2}}\n  \\begin{pmatrix}\n    v\\cos\\phi \\\\\n    v\\sin\\phi \\\\\n    u\n  \\end{pmatrix}\n\\end{align*}\n\nand for coordinate $v$ we find,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial v} =\n  \\begin{pmatrix}\n    u\\cos\\phi \\\\\n    u\\sin\\phi \\\\\n    -v\n  \\end{pmatrix}\n\\end{align*}\n\nso just as before $h_v = \\sqrt{u^2 + v^2}$ and,\n\n\\begin{align*}\n  \\mathbf{e_v} =\n  \\begin{pmatrix}\n    u\\cos\\phi \\\\\n    u\\sin\\phi \\\\\n    -v\n  \\end{pmatrix}\n\\end{align*}\n\nand for coordinate $\\phi$,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial\\rho} =\n  \\begin{pmatrix}\n    -uv\\sin\\phi \\\\\n    uv\\cos\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nThis time we can factorize so that $h_{\\phi} = uv$ and,\n\n\\begin{align*}\n  \\mathbf{e_{\\phi}} =\n  \\begin{pmatrix}\n    -\\sin\\phi \\\\\n    \\cos\\phi \\\\\n    0\n  \\end{pmatrix}\n\\end{align*}\n\nThis time, to check for orthogonality, we will take the dot product of the derivatives of the unit vectors instead of the unit vectors themselves. We do this as a convenience to make the calculation easier. It is possible to do this because the derivative $\\partial \\mathbf{r} / \\partial u_1$ is just the unit vector $\\mathbf{e_1}$ multiplied by a constant, the scale factor. By computing the dot products we see that,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial u}\\cdot\\frac{\\partial\\mathbf{r}}{\\partial v} &= 0 \\\\\n  \\frac{\\partial\\mathbf{r}}{\\partial u}\\cdot\\frac{\\partial\\mathbf{r}}{\\partial \\phi} &= 0 \\\\\n  \\frac{\\partial\\mathbf{r}}{\\partial v}\\cdot\\frac{\\partial\\mathbf{r}}{\\partial \\phi} &= 0\n\\end{align*}\n\nand therefore,\n\n\\begin{align*}\n  \\mathbf{e_u}\\cdot\\mathbf{e_v} &= 0 \\\\\n  \\mathbf{e_u}\\cdot\\mathbf{e_{\\phi}} &= 0 \\\\\n  \\mathbf{e_v}\\cdot\\mathbf{e_{\\phi}} &= 0\n\\end{align*}\n\nTherefore we have an orthogonal basis. The order of the coordinates is checked just as before and we find that $(u, v, \\phi)$ is indeed the correct order, such that,\n\n\\begin{align*}\n  \\mathbf{e_u}\\times\\mathbf{e_v}=\\mathbf{e_{\\phi}}\n\\end{align*}\n\n\\section{The Gradient}\n\nIn this section we will discover how to take the gradient of a scalar function in an orthogonal coordinate system. First we note that the gradient will be a vector function acting on a scalar field $\\Psi$ such that,\n\n\\begin{align*}\n  \\nabla\\Psi = A_1 \\mathbf{e_1} + A_2 \\mathbf{e_2} + A_3 \\mathbf{e_3}\n\\end{align*}\n\nThe difficulty arises since in an orthogonal coordinate system $\\mathbf{e_1}$, $\\mathbf{e_2}$, and $\\mathbf{e_3}$ can vary in space, unlike the Cartesian coordinate system where $\\hat{\\imath}$, $\\hat{\\jmath}$, and $\\hat{k}$ are constant.\n\nThe coefficients, $A_i$ can be extracted by using the orthogonality of the vectors $\\mathbf{e_i}$. This allows us to use the dot product to extract each component of the gradient,\n\n\\begin{align*}\n  A_i = \\mathbf{e_i} \\cdot \\nabla\\Psi = \\frac{1}{h_i} \\frac{\\partial\\mathbf{r}}{\\partial u_i} \\cdot \\nabla\\Psi\n\\end{align*}\n\nHere we have used the discovery from the last section that the derivative in some direction $\\partial\\mathbf{r}/\\partial u_i$ is just the unit vector $\\mathbf{e_i}$ multiplied by some scale factor $h_i$. Expanding out this scalar product gives,\n\n\\begin{align*}\n  \\frac{\\partial\\mathbf{r}}{\\partial u_i} &= \\left(\\frac{\\partial x}{\\partial u_i}, \\frac{\\partial y}{\\partial u_i}, \\frac{\\partial z}{\\partial u_i}\\right) \\cdot \\left(\\frac{\\partial\\Psi}{\\partial x}, \\frac{\\partial\\Psi}{\\partial y}, \\frac{\\partial\\Psi}{\\partial z}\\right) \\\\\n                                          &= \\frac{\\partial\\Psi}{\\partial x} \\frac{\\partial x}{\\partial u_i} + \\frac{\\partial\\Psi}{\\partial y} \\frac{\\partial y}{\\partial u_i} + \\frac{\\partial\\Psi}{\\partial z} \\frac{\\partial z}{\\partial u_i} \\\\\n                                          &= \\frac{\\partial\\Psi}{\\partial u_i}\n\\end{align*}\n\nIn the last step we have just applied the chain rule in reverse, that is, that the derivative of $\\Psi$ with respect to $u_i$ can be expressed as the derivatives of each Cartesian component. If you apply the chain rule to the final line it can be seen that this is what results. We now have an expression for an arbitrary coefficient $A_i$ of the gradient,\n\n\\begin{align*}\n  A_i = \\frac{1}{h_i} \\frac{\\partial\\Psi}{\\partial u_i}\n\\end{align*}\n\nTherefore, by substituting these coefficients into our equation for the gradient,\n\n\\begin{align*}\n  \\nabla\\Psi = \\frac{1}{h_1}\\frac{\\partial\\Psi}{\\partial u_1} \\mathbf{e_1} + \\frac{1}{h_2}\\frac{\\partial\\Psi}{\\partial u_2} \\mathbf{e_2} + \\frac{1}{h_3}\\frac{\\partial\\Psi}{\\partial u_3} \\mathbf{e_3}\n\\end{align*}\n\nFor example, in spherical polar coordinates this would be,\n\n\\begin{align*}\n  \\nabla\\Psi = \\frac{\\partial\\Psi}{\\partial r} \\mathbf{e_r} + \\frac{1}{r}\\frac{\\partial\\Psi}{\\partial\\theta}\\mathbf{e_{\\theta}} + \\frac{1}{r\\sin\\theta}\\frac{\\partial\\Psi}{\\partial\\Phi}\\mathbf{e_{\\Phi}}\n\\end{align*}\n\nWe now have an expression for the differential operator $\\nabla$ in any orthogonal coordinate system,\n\n\\begin{align*}\n  \\nabla = \\frac{\\mathbf{e_1}}{h_1}\\frac{\\partial}{\\partial u_1} + \\frac{\\mathbf{e_2}}{h_2}\\frac{\\partial}{\\partial u_2} + \\frac{\\mathbf{e_3}}{h_3}\\frac{\\partial}{\\partial u_3}\n\\end{align*}\n\nWhen we evaluate $\\nabla\\cdot\\mathbf{A}$ or $\\nabla\\times\\mathbf{A}$, the derivative operators also apply to the unit vectors $\\mathbf{e_i}$. This was fine in Cartesian coordinates because the unit vectors did not change in space, but now we have unit vectors which vary in the $x$, $y$, and $z$ directions. Therefore if we want to calculate the divergence or the curl we have to take a lot of derivatives, but this isn't necessary and it turns out that it is easier to apply Gauss' theorem and Stoke's theorem instead.\n\n\\section{Divergence in Orthogonal Coordinates: Integral Approach}\n\nConsider an infinitesimal cuboid situated at $(u_1, u_2, u_3)$ with sides of length $h_1 du_1$, $h_2 du_2$, and $h3 du_3$. We want to calculate the surface integral over the surface of the cuboid,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A}\\cdot d\\mathbf{S}\n\\end{align*}\n\nOur vector field $\\mathbf{A}$ will be of the form,\n\n\\begin{align*}\n  \\mathbf{A} = A_1 \\mathbf{e_1} + A_2 \\mathbf{e_2} + A_3 \\mathbf{e_3}\n\\end{align*}\n\nFirst we will consider the flux through the surfaces parallel to $\\mathbf{e_1}$,\n\n\\begin{align*}\n  \\int_{S_1} \\mathbf{A}\\cdot d\\mathbf{S_1} &= \\mathbf{A}\\cdot d\\mathbf{S_1} = \\mathbf{A}\\cdot h_2 du_2 h_2 du_3 \\mathbf{e_1} = h_2 h_3 A_1 du_2 du_3 \\\\\n  \\int_{S_2} \\mathbf{A}\\cdot d\\mathbf{S_2} &= \\mathbf{A}\\cdot d\\mathbf{S_2} = -\\mathbf{A}\\cdot h_2 du_2 h_2 du_3 \\mathbf{e_1} = -h_2 h_3 A_1 du_2 du_3\n\\end{align*}\n\nThe minus sign appears because $\\mathbf{S_2}$ is in the opposite direction to $\\mathbf{S_1}$. It may seem almost like when we sum them, they will disappear, but we have to remember that these coefficients will vary in different places in space; the $A_1$ in the first integral is evaluated at $(u_1 + du_1, u_2, u_3)$ whereas the $A_1$ in the second integral is evaluated at $(u_1, u_2, u_3)$. Now by summing these integrals,\n\n\\begin{align*}\n  \\int_{S_1 + S_2} \\mathbf{A}\\cdot d\\mathbf{S} &= \\left[h_2 h_3 A_1(u_1 + du_1) - h_2 h_3 A_1(u_1)\\right] du_2 du_3 \\\\\n                                               &= \\left[\\frac{\\partial}{\\partial u_1} (h_2 h_3 A_1) du_1\\right] du_2 du_3\n\\end{align*}\n\nIn this last line we have used the definition of the derivative to see that the term in square brackets in the first line is just the derivative $\\partial \\dots / \\partial u1$ multiplied by $du_1$.\n\nWhen we sum all of the other pairs of surfaces we get similar results,\n\n\\begin{align*}\n  \\oint_S \\mathbf{A}\\cdot d\\mathbf{S} = \\left[\\frac{\\partial}{\\partial u_1}(h_2h_3A_1) + \\frac{\\partial}{\\partial u_2}(h_3h_1A_2) + \\frac{\\partial}{\\partial u_3}(h_1h_2A_3)\\right] du_1 du_2 du_3\n\\end{align*}\n\nGauss' theorem tells us that the divergence is just the flux per unit volume, so we define the volume of the cuboid as,\n\n\\begin{align*}\n  \\Delta V = h_1h_2h_3du_1du_2du_3\n\\end{align*}\n\nand then by using that divergence is the flux divided by volume,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{A} = \\frac{\\oint_S \\mathbf{A}\\cdot d\\mathbf{S}}{\\Delta V} = \\frac{1}{h_1h_2h_3} \\left[\\frac{\\partial}{\\partial u_1}(h_2h_3A_1) + \\frac{\\partial}{\\partial u_2}(h_3h_1A_2) + \\frac{\\partial}{\\partial u_3}(h_1h_2A_3)\\right]\n\\end{align*}\n\nSimilarly this allows us to find an expression for the Laplacian of a scalar field, $\\nabla^2 \\Psi = \\nabla \\cdot (\\nabla \\Psi)$,\n\n\\begin{align*}\n  \\nabla\\Psi = \\frac{1}{h_1}\\frac{\\partial\\Psi}{\\partial u_1} \\mathbf{e_1} + \\frac{1}{h_2}\\frac{\\partial\\Psi}{\\partial u_2} \\mathbf{e_2} + \\frac{1}{h_3}\\frac{\\partial\\Psi}{\\partial u_3} \\mathbf{e_3}\n\\end{align*}\n\nand then substituting this into the divergence,\n\n\\begin{align*}\n  \\nabla^2\\Psi = \\frac{1}{h_1h_2h_3}\\left[\\frac{\\partial}{\\partial u_1}\\left(\\frac{h_2h_3}{h_1}\\frac{\\partial\\Psi}{\\partial u_1}\\right) + \\frac{\\partial}{\\partial u_2}\\left(\\frac{h_3h_1}{h_2}\\frac{\\partial\\Psi}{\\partial u_2}\\right) + \\frac{\\partial}{\\partial u_3}\\left(\\frac{h_1h_2}{h_3}\\frac{\\partial\\Psi}{\\partial u_3}\\right)\\right]\n\\end{align*}\n\n\\section{Using the Laplacian in Orthogonal Coordinate Systems}\n\n\\subsection*{Cylindrical Polar Coordinates}\n\nIn cylindrical polar coordinates, the coordinates $(u_1, u_2, u_3)$ are given by $(\\rho, \\phi, z)$. From earlier we have shown that the scale factors are given by $(h_1, h_2, h_3) = (1, \\rho, 1)$. We can therefore calculate the Laplacian,\n\n\\begin{align*}\n  \\nabla^2\\Psi&=\\frac{1}{\\rho}\\left[\\frac{\\partial}{\\partial\\rho}\\left(\\rho\\frac{\\partial\\Psi}{\\partial\\rho}\\right) + \\frac{\\partial}{\\partial\\phi}\\left(\\frac{1}{\\rho}\\frac{\\partial\\Psi}{\\partial\\phi}\\right) + \\frac{\\partial}{\\partial z}\\left(\\rho\\frac{\\partial\\Psi}{\\partial z}\\right)\\right] \\\\\n              &=\\frac{1}{\\rho}\\frac{\\partial}{\\partial\\rho}\\left(\\rho\\frac{\\partial\\Psi}{\\partial\\rho}\\right) + \\frac{1}{\\rho^2}\\frac{\\partial^2\\Psi}{\\partial\\phi^2} + \\frac{\\partial^2\\Psi}{\\partial z^2} \\\\\n              &=\\frac{1}{\\rho}\\frac{\\partial\\Psi}{\\partial\\rho}+\\frac{\\partial^2\\Psi}{\\partial\\rho^2}+\\frac{1}{\\rho^2}\\frac{\\partial^2\\Psi}{\\partial\\phi^2} + \\frac{\\partial^2\\Psi}{\\partial z^2}\n\\end{align*}\n\nIn the last line we have expanded the $\\partial/\\partial\\rho$ operator using the product rule, although we will not bother to expand in later examples as it is not needed.\n\n\\subsection*{Spherical Polar Coordinates}\n\nIn spherical polar coordinates, $(u_1, u_2, u_3) = (r, \\theta, \\phi)$, and the scale factors $(h_1, h_2, h_3) = (1, r, r\\sin\\theta)$. We will not write the working from now on, only the result, as the method is identical to the cylindrical polar case. The Laplacian is thus given by,\n\n\\begin{align*}\n  \\nabla^2\\Psi=\\frac{1}{r^2}\\frac{\\partial}{\\partial r}\\left(r^2\\frac{\\partial\\Psi}{\\partial r}\\right)+\\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\left(\\sin\\theta\\frac{\\partial\\Psi}{\\partial\\theta}\\right)+\\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2\\Psi}{\\partial\\phi^2}\n\\end{align*}\n\n\\subsection*{Paraboloidal Coordinates}\n\nIn paraboloidal coordinates, the coordinates are given by $(u_1, u_2, u_3) = (u, v, \\phi)$, and the scale factors given by $(h_1, h_2, h_3) = (\\sqrt{u^2 + v^2}, \\sqrt{u^2 + v^2}, uv)$. We can see that in this case $h_1 = h_2$. The Laplacian is given by,\n\n\\begin{align*}\n  \\nabla^2\\Psi=\\frac{1}{(u^2+v^2)}\\frac{1}{u}\\frac{\\partial}{\\partial u}\\left(u\\frac{\\partial\\Psi}{\\partial u}\\right)+\\frac{1}{(u^2+v^2)}\\frac{1}{v}\\frac{\\partial}{\\partial v}\\left(v \\frac{\\partial\\Psi}{\\partial v}\\right)+\\frac{1}{(u^2 + v^2)}\\frac{\\partial^2\\Psi}{\\partial\\phi^2}\n\\end{align*}\n\n\\section{Curl in Orthogonal Coordinate Systems: Integral Approach}\n\nIn this section we will find expression for the curl of a vector field in an orthogonal coordinate system. First we consider an infinitesimal rectangle in the $u_1u_2$ plane situated at $(u_1, u_2)$ such that this is the lower left corner or the rectangle. The rectangle has sides length $h_1du_1$ and $h_2du_2$. The corners are thus given such that the lower left is $(u_1, u_2)$, the lower right is $(u_1 + du_1, u_2)$, the upper left is $(u_1, u_2 + du_2)$, the upper right is $(u_1 + du_2, u_2 + du_2)$. We label the bottom side $1$, the right side $2$, the top side $3$, and the left side $4$.\n\nThe circulation of a vector field $\\mathbf{A}$ around this loop is given by,\n\n\\begin{align*}\n  \\oint_C \\mathbf{A}\\cdot d\\mathbf{r}=\\mathbf{A}\\cdot d\\mathbf{r_1} + d\\mathbf{r}=\\mathbf{A}\\cdot d\\mathbf{r_2} + d\\mathbf{r}=\\mathbf{A}\\cdot d\\mathbf{r_3} + d\\mathbf{r}=\\mathbf{A}\\cdot d\\mathbf{r_4}\n\\end{align*}\n\nThe vectors, $d\\mathbf{r_i}$ are given by,\n\n\\begin{alignat*}{2}\n  d\\mathbf{r_1}&=h_1du_1\\mathbf{e_1}\\qquad d\\mathbf{r_2}&&=h_2du_2\\mathbf{e_2} \\\\\n  d\\mathbf{r_1}&=-h_1du_1\\mathbf{e_1}\\qquad d\\mathbf{r_4}&&=-h_2du_2\\mathbf{e_2}\n\\end{alignat*}\n\nTherefore the circulation over the entire loop is,\n\n\\begin{align*}\n  \\oint_C\\mathbf{A}\\cdot d\\mathbf{r}&=h_1A_1du_1(u_1, u_2) + h_2A_2du_2(u_1+du_1, u_2)\\\\\n                                    &- h_1A_1du_1(u_1, u_2+du_2) - h_2A_2du_2(u_1, u_2) \\\\\n                                    &=\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2)du_1\\right]du_2 - \\left[\\frac{\\partial}{\\partial u_2}(h_1A_1)du_2\\right]du_1 \\\\\n                                    &=\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2) - \\frac{\\partial}{\\partial u_2}(h_1A_1)\\right]du_1 du_2\n\\end{align*}\n\nAgain here we have used the definition of the derivative. Stokes' theorem tells us that the $u_3$ component of the curl is thus given by,\n\n\\begin{align*}\n  {\\left[\\nabla\\times\\mathbf{A}\\right]}_3 &= \\frac{\\oint_C\\mathbf{A}\\cdot d\\mathbf{r}}{\\text{Area}} = \\frac{\\oint_C\\mathbf{A}\\cdot d\\mathbf{r}}{h_1h_2du_1du_2} \\\\\n&=\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2)du_1\\right]du_2 - \\left[\\frac{\\partial}{\\partial u_2}(h_1A_1)du_2\\right]du_1 \\\\\n&=\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2) - \\frac{\\partial}{\\partial u_2}(h_1A_1)\\right]du_1 du_3\n\\end{align*}\n\nThe curl of the vector field is therefore,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{A} &= \\frac{1}{h_2h_3}\\left[\\frac{\\partial}{\\partial u_2}(h_3A_3)-\\frac{\\partial}{\\partial u_3}(h_2A_2)\\right]\\mathbf{e_1} \\\\\n&+ \\frac{1}{h_3h_1}\\left[\\frac{\\partial}{\\partial u_3}(h_1A_1)-\\frac{\\partial}{\\partial u_1}(h_3A_3)\\right]\\mathbf{e_2} \\\\\n&+ \\frac{1}{h_1h_2}\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2)-\\frac{\\partial}{\\partial u_2}(h_1A_1)\\right]\\mathbf{e_2}\n\\end{align*}\n\nBy rearranging we can write this as a determinant,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{A} = \\frac{1}{h_1h_2h_3}\n  \\begin{vmatrix}\n    h_1\\mathbf{e_1} & h_2\\mathbf{e_2} & h_3\\mathbf{e_3} \\\\[6pt]\n    \\frac{\\partial}{\\partial u_1} & \\frac{\\partial}{\\partial u_2} & \\frac{\\partial}{\\partial u_3} \\\\[6pt]\n    h_1A_1 & h_2A_2 & h_3A_3\n  \\end{vmatrix}\n\\end{align*}\n\n\n\\section{Divergence in Orthogonal Coordinate Systems: Differential Approach}\n\nIn earlier sections we explored how we can apply the divergence and curl in orthogonal coordinate systems by taking integrals over surfaces and lines and then applying Gauss' and Stokes' theorems to find the divergence and curl. In this section we will find the same result by using differentiation only, as well as some vector calculus identities. To see the vector calculus identities, as well as proofs for a few of them, see the separate vector calculus notes.\n\nThe trick to finding the divergence and curl in orthogonal coordinate systems is to find combinations of the scale factors $h_i$ and the unit vectors $\\mathbf{e_i}$ that have either zero divergence or curl. First we do this by finding the gradient of $u_1$,\n\n\\begin{align*}\n  \\nabla u_1 &= \\frac{\\mathbf{e_1}}{h_1}\\frac{\\partial}{\\partial u_1}\\left(u_1\\right) + \\frac{\\mathbf{e_2}}{h_2}\\frac{\\partial}{\\partial u_2}\\left(u_1\\right) + \\frac{\\mathbf{e_3}}{h_3}\\frac{\\partial}{\\partial u_3}\\left(u_1\\right) \\\\\n             &= \\frac{\\mathbf{e_1}}{h_1}\n\\end{align*}\n\nSince $\\nabla\\times\\nabla\\Psi = \\mathbf{0}$ it follows that,\n\n\\begin{align*}\n  \\nabla\\times\\left(\\frac{\\mathbf{e_1}}{h_1}\\right) = \\mathbf{0}\n\\end{align*}\n\nWe can apply similar reasoning for $u_2$ and $u_3$ to give,\n\n\\begin{align*}\n  \\nabla\\times\\left(\\frac{\\mathbf{e_1}}{h_1}\\right) = \\nabla\\times\\left(\\frac{\\mathbf{e_2}}{h_2}\\right) = \\nabla\\times\\left(\\frac{\\mathbf{e_3}}{h_3}\\right) = \\mathbf{0}\n\\end{align*}\n\nUsing our vector calculus identity $\\nabla\\cdot(\\mathbf{A}\\times\\mathbf{B}) = \\mathbf{B}\\cdot(\\nabla\\times\\mathbf{A}) - \\mathbf{A}\\cdot(\\nabla\\times\\mathbf{B})$ we obtain a combination that leads to zero divergence,\n\n\\begin{align*}\n  \\nabla\\cdot\\left(\\frac{\\mathbf{e_1}}{h_2h_3}\\right) &= \\nabla\\cdot\\left(\\frac{\\mathbf{e_2}}{h_2}\\times\\frac{\\mathbf{e_3}}{h_3}\\right) \\\\\n                                                      &= \\frac{\\mathbf{e_3}}{h_3}\\cdot\\nabla\\times\\left(\\frac{\\mathbf{e_2}}{h_2}\\right) - \\frac{\\mathbf{e_2}}{h_2}\\cdot\\nabla\\times\\left(\\frac{\\mathbf{e_3}}{h_3}\\right) \\\\\n                                                      &= 0\n\\end{align*}\n\nSimilar reasoning leads us to,\n\n\\begin{align*}\n  \\nabla\\cdot\\left(\\frac{\\mathbf{e_1}}{h_2h_3}\\right)=\\nabla\\cdot\\left(\\frac{\\mathbf{e_2}}{h_3h_1}\\right)=\\nabla\\cdot\\left(\\frac{\\mathbf{e_3}}{h_1h_2}\\right)=0\n\\end{align*}\n\nTo calculate the divergence then, we take the divergence of a given vector field $\\mathbf{A}$ in the orthogonal coordinate system,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{A}=\\nabla\\cdot(A_1\\mathbf{e_1}+A_2\\mathbf{e_2}+A_3\\mathbf{e_3})\n\\end{align*}\n\nWe can write the $\\mathbf{e_1}$ term as,\n\n\\begin{align*}\n  \\nabla\\cdot(A_1\\mathbf{e_1})=\\nabla(h_2h_3A_1\\frac{\\mathbf{e_1}}{h_2h_3})\n\\end{align*}\n\nNow we use identity five, which is that $\\nabla\\cdot(\\Psi\\mathbf{F})=\\nabla\\Psi\\cdot\\mathbf{F}+\\Psi\\nabla\\cdot\\mathbf{F}$. This gives us,\n\n\\begin{align*}\n  \\nabla\\cdot\\left(h_2h_3A_1\\frac{\\mathbf{e_1}}{h_2h_3}\\right)&=\\nabla(h_2h_3A_1)\\cdot\\frac{\\mathbf{e_1}}{h_2h_3}+h_2h_3A_1\\nabla\\cdot\\left(\\frac{\\mathbf{e_1}}{h_2h_3}\\right) \\\\\n                                                              &=\\left[\\frac{1}{h_1}\\frac{\\partial}{\\partial u_1}(h_2h_3A_1)\\mathbf{e_1}\\right]\\cdot\\frac{\\mathbf{e_1}}{h_2h_3} + 0 \\\\\n                                                              &=\\frac{1}{h_1h_2h_3}\\frac{\\partial}{\\partial u_1}(h_2h_3A_1)\n\\end{align*}\n\nThe last term in the first line can be seen to be zero as we have shown earlier, as $\\nabla\\cdot\\left(\\frac{\\mathbf{e_1}}{h_2h_3}\\right) = 0$. We can get the other two terms of the divergence using cyclic interchange and we see that we get the same result as before,\n\n\\begin{align*}\n  \\nabla\\cdot\\mathbf{A}=\\frac{1}{h_1h_2h_3}\\left[\\frac{\\partial}{\\partial u_1}(h_2h_3A_1)+\\frac{\\partial}{\\partial u_2}(h_3h_1A_2)+\\frac{\\partial}{\\partial u_3}(h_1h_2A_3)\\right]\n\\end{align*}\n\n\n\\section{Curl in Orthogonal Coordinate Systems: Differential Approach}\n\nSimilarly we can apply the same reasoning to find the curl in an orthogonal coordinate system. First we state the curl of a vector field $\\mathbf{A}$ in orthogonal coordinates,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{A}=\\nabla\\times(A_1\\mathbf{e_1}+A_2\\mathbf{e_2}+A_3\\mathbf{e_3})\n\\end{align*}\n\nWe can see that the first term can be written as,\n\n\\begin{align*}\n  \\nabla\\times(A_1\\mathbf{e_1})=\\nabla\\times(h_1A_1\\frac{\\mathbf{e_1}}{h_1})\n\\end{align*}\n\nNext we use identity six which is that $\\nabla\\times(\\Psi\\mathbf{F}) = \\nabla\\Psi\\times\\mathbf{F} + \\Psi\\nabla\\times\\mathbf{F}$. Using this leads us to,\n\n\\begin{align*}\n  \\nabla\\times(A_1\\mathbf{e_1}) &= \\nabla\\times\\left((h_1A_1\\frac{\\mathbf{e_1}}{h_1}\\right) = \\nabla(h_1A_1)\\times\\frac{\\mathbf{e_1}}{h_1}+h_1A_1\\nabla\\times\\frac{\\mathbf{e_1}}{h_1} \\\\\n                                &= \\left[\\frac{1}{h_2}\\frac{\\partial}{\\partial u_2}(h_1A_1)\\mathbf{e_2}+\\frac{1}{h_3}\\frac{\\partial}{\\partial u_3}(h_1A_1)\\mathbf{e_3}\\right]\\times\\frac{\\mathbf{e_1}}{h_1} + \\mathbf{0} \\\\\n                                &= \\frac{1}{h_3h_1}\\frac{\\partial}{\\partial u_3}(h_1A_1)\\mathbf{e_2} - \\frac{1}{h_1h_2}\\frac{\\partial}{\\partial u_2}(h_1A_1)\\mathbf{e_3} \\\\\n\\end{align*}\n\nWe see that the last term of the first line goes to zero as we have shown earlier in the last section. We can get the other terms by cyclic interchange,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{A}&=\\frac{1}{h_2h_3}\\left[\\frac{\\partial}{\\partial u_2}(h_3A_3)-\\frac{\\partial}{\\partial u_3}(h_2A_2)\\right]\\mathbf{e_1} \\\\\n                        &+\\frac{1}{h_3h_1}\\left[\\frac{\\partial}{\\partial u_3}(h_1A_1)-\\frac{\\partial}{\\partial u_1}(h_3A_3)\\right]\\mathbf{e_2} \\\\\n                        &+\\frac{1}{h_1h_2}\\left[\\frac{\\partial}{\\partial u_1}(h_2A_2)-\\frac{\\partial}{\\partial u_2}(h_1A_1)\\right]\\mathbf{e_3}\n\\end{align*}\n\nThis can also be written in determinant form,\n\n\\begin{align*}\n  \\nabla\\times\\mathbf{A}=\\frac{1}{h_1h_2h_3}\n  \\begin{vmatrix}\n    h1\\mathbf{e_1} & h2\\mathbf{e_2} & h3\\mathbf{e_3} \\\\\n    \\frac{\\partial}{\\partial u_1} & \\frac{\\partial}{\\partial u_2} & \\frac{\\partial}{\\partial u_3} \\\\\n    h_1A_1 & h_2A_2 & h_3A_3\n  \\end{vmatrix}\n\\end{align*}\n\n\\section{Converting Spherical Polars to Cartesian}\n\nWe can write the Cartesian coordinates $(x, y, z)$ in terms of the spherical polar coordinates $(r, \\theta, \\phi)$,\n\n\\begin{align*}\n  x &= r\\sin\\theta\\cos\\phi \\\\\n  y &= r\\sin\\theta\\sin\\phi \\\\\n  z &= r\\cos\\theta\n\\end{align*}\n\nFrom this we can write $(r, \\theta, \\phi)$ in terms of $(x, y, z)$,\n\n\\begin{align*}\n  r&=\\sqrt{x^2+y^2+z^2} \\\\\n  \\theta&=\\arctan{\\left(\\frac{\\sqrt{x^2 + y^2}}{z}\\right)} \\\\\n  \\phi&=\\arctan{\\left(\\frac{y}{x}\\right)} \\\\\n\\end{align*}\n\nBut if we need to take the cosine or sin of either $\\theta$ or $\\phi$ in terms of $(x, y, z)$ we need to do a difficult calculation (the sine of an arctangent) so it is better if we define the cosine and sine of $\\theta$ and $\\phi$ without an arctangent,\n\n\\begin{alignat*}{2}\n  \\cos\\theta&=\\frac{r\\cos\\theta}{\\cos\\theta}&&=\\frac{z}{r}=\\frac{z}{\\sqrt{x^2 + y^2 + z^2}}\\\\\n  \\sin\\theta&=\\frac{r\\sin\\theta}{\\sin\\theta}&&=\\frac{\\sqrt{x^2+y^2}}{\\sqrt{x^2+y^2+z^2}}\\\\\n  \\cos\\phi&=\\frac{r\\sin\\theta\\cos\\phi}{r\\sin\\theta}&&=\\frac{x}{\\sqrt{x^2+y^2}}\\\\\n  \\sin\\phi&=\\frac{r\\sin\\theta\\sin\\phi}{r\\sin\\theta}&&=\\frac{y}{\\sqrt{x^2+y^2}}\n\\end{alignat*}\n\n\\end{document}\n", "meta": {"hexsha": "5a90731f5dab1e5f0979f3c8c011d7624cc9182d", "size": 31576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maths/coordsystems/coordsystems.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/coordsystems/coordsystems.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/coordsystems/coordsystems.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": 42.7280108254, "max_line_length": 598, "alphanum_fraction": 0.6739612364, "num_tokens": 11467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8740772269642948, "lm_q1q2_score": 0.7768438242314477}}
{"text": "\\lab{Data Structures II}{Data Structures II}\n\\label{lab:Python_DataStructures2}\n\n\\objective{Implement tree data structures and understand their relative strengths and weaknesses.}\n\n\\section*{Recursion}\n\nRecursion is an important problem solving technique in computer programming.\nA recursive function is one that calls itself.\nWhen the function is executed, it continues calling itself until it reaches a specified base case.\nThen the function exits without calling itself again, and each previous function call is resolved.\nAs a simple example, suppose we want to recursively sum all positive integers from $1$ to some integer $n$.\n\n\\begin{lstlisting}\ndef recursive_sum(n):\n\t\"\"\"Calculate the sum of all positive integers in [1, n] recursively.\"\"\"\n\n\t# Typically the base case comes first. There are no positive integers less\n\t# than 1, so if 'n' is 1 we stop the recursion and return 1 (since the sum of\n\t# all 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\t# itself on the next smallest integer and adding 'n'.\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), we need to calculate recursive_sum(4).\n# But to find recursive_sum(4), we need to 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\nNow that we've reached a base case, we can unwind the recursion.\nReading from bottom to top, we substitute the values that result from each function call.\n\n\\begin{lstlisting}\nrecursive_sum(5)\t\t# 5 + 10 = 15\n\trecursive_sum(4)\t\t# 4 + 6 = 10\n\t\trecursive_sum(3)\t\t# 3 + 3 = 6\n\t\t\trecursive_sum(2)\t\t# 2 + 1 = 3\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$).\nMany problems that can be solved by iterative methods can also be solved (often more efficiently) with a recursive approach.\nCompare, for example, the following two methods for calculating the $n^{th}$ Fibonacci number.\n\n\\begin{lstlisting}\ndef iterative_fib(n):\n\t\"\"\"Calculate the nth Fibonacci number iteratively.\"\"\"\n\tfibonacci = list()\t\t# 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 we haven't reached a base case, the function recurses by calling\n\t# itself on 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 until a base case is reached.\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% Problem 1: simple recursion for linked lists traversal\n\\begin{problem}\nRewrite the following iterative function for finding data in a linked list using recursion.\nUse a \\li{LinkedList} object from the previous lab to test the function.\n\\begin{lstlisting}\n# solutions.py\n\ndef iterative_search(linkedlist, data):\n\tcurrent = linkedlist.head\n\twhile current is not None:\n\t\tif current.data == 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\\end{problem}\n\n\\begin{warn}\nIt is not always 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 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 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.\nThis continues until the end of the list, with the last node as the only leaf node.\n\nOther kinds of trees may be more complicated.\nSee Figure \\ref{fig:tree}.\n\n\\begin{figure}\n\\caption{Examples of trees, some of which are binary search trees.}\n\\label{fig:trees}\n\\end{figure}\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, 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.\nConceptually, each level of a BST partitions the dataset into two halves.\nFor any given node, each node in the left subtree contains data that is less than the data in the top node, and each node in the right subtree contains data that is greater than the original node's data.\n\n% TODO: make sure this statement is consistent with the figure\nThe far right tree in Figure \\ref{fig:trees} is an example of a binary search tree.\nIn practice, binary search tree nodes have attributes that keep track of their data, children, and (in doubly-linked trees) their parent.\n\n% self.prev instead of self.parent for consistency\n\\begin{lstlisting}\n# BST.py\n\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.data = data\n        self.prev = None        # A reference to this node's parent node.\n        self.left = None        # This node's data will be less than self.data\n        self.right = None       # This node's data will be greater than self.data\n        \n    def __str__(self):\n        \"\"\"String representation: the data contained in the node.\"\"\"\n        return str(self.data)\n\\end{lstlisting}\n\nThe actual binary search tree class has an attribute pointing to its root.\n\n\\begin{lstlisting}\n# BST.py\n\nclass BST(object):\n    \"\"\"Binary Search Tree data structure class.\n    The first node is referenced to by 'root'.\n    \"\"\"\n    def __init__(self):\n        \"\"\"Initialize the root attribute.\"\"\"\n        self.root = None\n\\end{lstlisting}\n\n\\subsection*{Finding in a Binary Search Tree}\n\nMany tree algorithms are best understood and implemented using recursion.\nFor instance, finding a node in a binary search tree can be done recursively.\nStarting at the root, we check if the data we are looking for matches the current node.\nIf it does not, then if the data is less than the current node's data we search again on the left child.\nIf the data is greater, we search on the right child.\nThis process continues until the data is found or, if the data is not in the tree, an empty child is searched.\nSee Figure \\ref{fig:BST.find} for an example.\nCarefully read the following code; similar techniques will be used for subsequent methods.\n\n\\begin{lstlisting}\n# BST.py\n\ndef find(self, data):\n    \"\"\"Return the node containing 'data'. If there is no such node in the\n    tree, raise a ValueError with error message \"<data> is not in the tree.\"\n    \"\"\"\n    # First, check to see if the tree is empty.\n    if self.root is None:\n        raise ValueError(str(data) + \" is not in the tree.\")\n    \n    # Define a recursive function to traverse the tree.\n    def _step(current, item):\n        \"\"\"Recursively step through the tree until the node containing\n        'item' 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 item == current.data:                # Base case 2: the data matches.\n            return current\n        if item < current.data:                 # Step to the left\n            return _step(current.left,item)\n        else:                                   # Step to the right\n            return _step(current.right,item)\n    \n    # Start the recursion on the root of the tree.\n    return _step(self.root, data)\n\\end{lstlisting}\n\n\\begin{figure}\n% I want a picture of how descending through a tree partitions a number line.\n% This will help when they get to K-D trees in the next lab.\n\\caption{Examples of finding in a BST, including the conceptual partitioning of the number line.}\n\\label{fig:BST.find}\n\\end{figure}\n\n\\subsection*{Inserting to a Binary Search Tree}\n\nTo insert new data into a binary search tree, a leaf node is added at the correct location.\nFirst, we find the node that should be the parent of the new node.\nWe find the parent recursively, using a similar approach to the \\li{find} method.\nOnce the correct parent is found, the new node is added as the left or right child of the parent.\nSee Figure \\ref{fig:BST.insertion} for an example.\n\n\\begin{figure}\n\\caption{Examples of inserting to a BST.}\n\\label{fig:BST.insertion}\n\\end{figure}\n\n% Some pseudocode to help with insertion, if deemed necessary.\n\\begin{comment}\n\\begin{lstlisting}\n\"\"\"Pseudocode for finding the correct parent of a new node\n\nfind the parent of node, data\n\tif data < node.data:\n\t\tif node.left is not None \n\t\t\tfind the parent of node.left, data\n\t\telse:\n\t\t\treturn node\n\tif data > node.right:\n\t\tif data > node.data:\n\t\t\tif node.right is not None:\n\t\t\t\tfind the parent of node.right, data\n\t\t\telse:\n\t\t\t\treturn node\n\"\"\"\n\\end{lstlisting}\n\\end{comment}\n\n% Problem 2: BST.insert\n\\begin{problem}\nImplement the \\li{insert} method in the \\li{BST} class.\nTo accomplish this, write a recursive \\li{_find_parent} method within \\li{insert}.\nFind the correct parent, then determine whether the new node will be its left or right child.\nThen double-link the parent and the new child.\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\nDo not allow for duplicates in the tree: if the user executes \\li{insert(x)} and there is already a node in the tree containing \\li{x}, raise a ValueError.\n\\end{problem}\n\n\\subsection*{Removing from a Binary Search Tree}\n\nDeleting nodes from a binary search tree is more difficult than searching and 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. See Figure \\ref{fig:BST.remove_leaf}.\n\n\\begin{figure}\n\\caption{Examples of removing a leaf node.}\n\\label{fig:BST.remove_leaf}\n\\end{figure}\n\n\\begin{comment}\n\\begin{lstlisting}\n\"\"\"Pseudocode for removing a leaf node\nif the target node does not have children:\n\tif the target's data is smaller than its parent's data:\n\t\tset the parent's left child to None\n\telse:\n\t\tset the parent's right child to None\n\"\"\"\n\\end{lstlisting}\n\\end{comment}\n\n\\subsubsection*{Removing a node with one child}\n\nIf the target node has one or more children, we must 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, we 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, the target has no references pointing to it, so it is deleted.\nThe target's successor, however, is pointed to by the target's parent, and so it remains in the tree.\nSee Figure \\ref{fig:BST.remove_oneChild}.\n\n\\begin{figure}\n\\caption{Examples of removing a leaf node with one child. Include a bad example (losing a subtree) and a good example (proper deletion).}\n\\label{fig:BST.remove_oneChild}\n\\end{figure}\n\n\\begin{comment}\n\\begin{lstlisting}\n\"\"\"Pseudocode for removing a node with one child\nif the target node has one child:\n\tif target.parent.right is the target:\n\t\tset parent's right child to the target's child.\n\tif target.parent.left is the target:\n\t\tset parent's left child to the target's child.\n\"\"\"\n\\end{lstlisting}\n\\end{comment}\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 we find it's immediate in-order predecessor.\nThe predecessor is the node with the largest data that is smaller than the target's data.\nIt may be found by moving to the left child of the target (so that it's value is less than the target's value), and then to the right for as long as possible (so that it has the largest such value).\nNote that because of how the predecessor is chosen, any predecessor can only have at most one child.\n\nOnce the predecessor is found, the target and its predecessor must switch places in the graph, and then the target must be removed.\nThis can be done by simply switching the data values for the target and its predecessor.\nThen the node with the target data has at most one child, and may be deleted accordingly.\nIf the predecessor 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 predecessor has at most one child, we may recursivley remove the predecessor node by calling \\li{remove} on the predecessor's data.\nThen set the data stored in the target node as the predecessor's data.\nSee Figure \\ref{fig:BST.remove_twoChild}.\n\n\\begin{figure}\n\\caption{Examples of removing a leaf node with two children.}\n\\label{fig:BST.remove_twoChild}\n\\end{figure}\n\n\\begin{comment}\n\\begin{lstlisting}\n\"\"\"Pseudocode for removing a node with two children.\n\nfind the predecessor:\n\tset the current node to be target.left\n\tset current to be current.right until there is no right child\n\treturn current.\n\nRemove the node that has the predecessor's data (it will only have one child).\nChange the target's data to the predecessor's data.\n\"\"\"\n\\end{lstlisting}\n\\end{comment}\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% Problem 3: BST.remove()\n\\begin{problem}\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}.\n\nMake sure to cover 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}\nTest your solution thoroughly with each case.\n\n(Hint: use \\li{find} 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 we essentially end up with a linked list.\n\n\\begin{lstlisting}\n# Adding ordered integers sequentially destroys the efficiency of a BST.\n>>> unbalanced_tree = BST()\n>>> for i in xrange(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 AVL tree is a tree that prevents any one branch from getting longer than the others.\nIt accomplishes this by periodically ``balancing'' the branches as nodes are added.\nSee Figure \\ref{fig:avl_balance}\nThe AVL's balancing algorithm is beyond the scope of this text, but details and exercises on the algorithm can be found in Chapter 2 of the Volume II text.\n\n\\begin{lstlisting}\n>>> balanced_tree = AVL()\n>>> for i in xrange(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{figure}\n\\caption{Example of an AVL rebalancing.}\n\\label{fig:avl_balance}\n\\end{figure}\n\n% Problem 4: compare build and search speeds\n\\begin{problem}\nCompare the speed of building and searching the different data structures we have implemented so far.\nVisualize the results by creating a plot with two subplots: one for build times, and one for search times.\nRepeat the following for $n$ varying from 500 to 5000 at intervals of 500:\n\nUse the \\li{create_word_list} function in the provided \\li{WordList} module to generate a list of $n$ randomized words from the file \\li{English.txt}.\nTime (separately) how long it takes to load a \\li{LinkedList}, a \\li{BST}, and an \\li{AVL} with the data set.\nUse \\li{add} to load the \\li{LinkedList} and \\li{insert} to load the trees.\nThen choose 5 random words from the data set, and time how long it takes to find each word in each object.\nUse the \\li{iterative_search} function from problem 1 to search the \\li{LinkedList} and \\li{find} to search the trees.\nCalculate the average search time for each object.\n\nIn the first subplot, plot the number of words in each data set against the time it took to build each object.\nIn the second subplot, plot the number of words in each data set against the average time it took to search each object.\nYour plot should look similar to Figure \\ref{fig:times}.\n\n\\begin{comment}\n\n% TODO: merge in this picture (as a pdf? png? jpeg?)\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{times.pdf}\n\\caption{Note that the \\li{BST} has the fastest build times, but the \\li{AVL} has the fastest search times. How would the graph change if the data were sorted to begin with?}\n\\label{fig:times}\n\\end{figure}\n\n\\end{comment}\n\n\\end{problem}\n\n\n\\begin{comment}\n\n% Nixed\n\\begin{problem}\nThe \\li{lab5_data} module has a method called \\li{load_data}.\nThis method returns two objects: a linked list and a binary search tree of a random permutation of the numbers from 1 to 100000.\nEach object has a \\li{find} method that returns the node that contains the data that the \\li{find} method receives as an argument.\nWrite a method that generates 50 random numbers between 1 and 100000, finds them in the given data structures, and returns the average search time for each.\n\\end{problem}\n\n\\begin{problem}\nThe \\li{Lab5_data} module has a method called \\li{load_words} that returns a list of several thousand english words.\nThe \\li{Lab5_spec} module has an implementation of an AVL tree that inherits from a working \\li{BST} class.\nInsert each word into an instances of the \\li{BST} and \\li{AVL} classes.\nWrite a method called \\li{test_words} that searches for 50 random words in each object and returns their average search times.\n\\end{problem}\n\n\\end{comment}\n\n", "meta": {"hexsha": "a615872ef4cec1d6692f9c3b0c11112be5185541", "size": 22268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Python/DataStructures2/BSTrees.tex", "max_stars_repo_name": "jessicaleete/numerical_computing", "max_stars_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Python/DataStructures2/BSTrees.tex", "max_issues_repo_name": "jessicaleete/numerical_computing", "max_issues_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Python/DataStructures2/BSTrees.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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.6224299065, "max_line_length": 203, "alphanum_fraction": 0.7425453566, "num_tokens": 5569, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8740772236840656, "lm_q1q2_score": 0.7768438187406866}}
{"text": "\\subsubsection{Power methods}\n\nWhile the $QR$ algorithm can be used to compute eigenvalues, there is a useful and fairly elementary technique for\nfinding the eigenvector and associated eigenvalue nearest to a given complex number which\nis called the {\\em shifted inverse power method}. It tends to work extremely well provided you\nstart with something which is fairly close to an eigenvalue.\n\nPower methods are based the consideration of powers of a given matrix. Let $\n\\set{\n\\vect{x}_{1},\\ldots,\\vect{x}_{n}} $ be a basis of eigenvectors for $\n\\C^{n}$ such that $A\\vect{x}_{n}=\\lambda _{n}\\vect{x}_{n}$. Now let $\n\\vect{u}_{1}$ be some non-zero vector. Since $\\set{\\vect{x}_{1},\\ldots,\\vect{x}_{n}} $ is a basis, there exists unique scalars, $c_{i}$ such that\n\\begin{equation*}\n\\vect{u}_{1}=\\sum_{k=1}^{n}c_{k}\\vect{x}_{k}\n\\end{equation*}\nAssume you have not been so unlucky as to pick $\\vect{u}_{1}$ in such a way\nthat $c_{n}=0$. Then let $A\\vect{u}_{k}=\\vect{u}_{k+1}$ so that\n\\begin{equation}\n\\vect{u}_{m}=A^{m}\\vect{u}_{1}=\\sum_{k=1}^{n-1}c_{k}\\lambda _{k}^{m}\\vect{x}\n_{k}+\\lambda _{n}^{m}c_{n}\\vect{x}_{n}.  \\label{20-may-e1}\n\\end{equation}\nFor large $m$ the last term, $\\lambda _{n}^{m}c_{n}\\vect{x}_{n}$, determines\nquite well the direction of the vector on the right. This is because $\n\\abs{\\lambda _{n}}$ is larger than $\\abs{\\lambda\n_{k}}$ for $k<n$ and so for a large $m$, the sum, $\\sum_{k=1}^{n-1}c_{k}\\lambda _{k}^{m}\\vect{x}_{k}$, on the right is fairly\ninsignificant. Therefore, for large $m$, $\\vect{u}_{m}$ is essentially a\nmultiple of the eigenvector $\\vect{x}_{n}$, the one which goes with $\\lambda\n_{n}$. The only problem is that there is no control of the size of the\nvectors $\\vect{u}_{m}$. You can fix this by scaling. Let $S_{2}$ denote the\nentry of $A\\vect{u}_{1}$ which is largest in absolute value. We call this a\n\\index{scaling factor} \\textbf{scaling factor}. Then $\\vect{u}_{2}$ will not be just $A\\vect{u}_{1}$ but $A\\vect{u}_{1}/S_{2}$. Next\nlet $S_{3}$ denote the entry of $A\\vect{u}_{2}$ which has largest absolute\nvalue and define $\\vect{u}_{3}\\equiv A\\vect{u}_{2}/S_{3}$. Continue this way.\nThe scaling just described does not destroy the relative insignificance of\nthe term involving a sum in {\\eqref{20-may-e1}}. Indeed it amounts to nothing more\nthan changing the units of length. Also note that from this scaling\nprocedure, the absolute value of the largest element of $\\vect{u}_{k}$ is\nalways equal to 1. Therefore, for large $m$,\n\\begin{equation*}\n\\vect{u}_{m}=\\vspace{0.05in}\\frac{\\lambda _{n}^{m}c_{n}\\vect{x}_{n}}{S_{2}S_{3}\\cdots S_{m}}+(\\text{relatively insignificant term}) .\n\\end{equation*}\nTherefore, the entry of $A\\vect{u}_{m}$ which has the largest absolute value\nis essentially equal to the entry having largest absolute value of\n\\begin{equation*}\nA\\paren{\\vspace{0.05in}\\frac{\\lambda _{n}^{m}c_{n}\\vect{x}_{n}}{S_{2}S_{3}\\cdots S_{m}}} =\\vspace{0.05in}\\frac{\\lambda _{n}^{m+1}c_{n}\n\\vect{x}_{n}}{S_{2}S_{3}\\cdots S_{m}}\\approx \\lambda _{n}\\vect{u}_{m}\n\\end{equation*}%\nand so for large $m$, it must be the case that $\\lambda _{n}\\approx S_{m+1}$.\nThis suggests the following procedure.\n\n\\begin{procedure}{Finding the largest eigenvalue with its eigenvector}{}\n\\begin{enumerate}\n\\item Start with a vector $\\vect{u}_{1}$ which you hope has a component in\nthe direction of $\\vect{x}_{n}$. The vector $(1,\\ldots,1) ^{T}$\nis usually a pretty good choice.\n\n\\item If $\\vect{u}_{k}$ is known,\n\\begin{equation*}\n\\vect{u}_{k+1}=\\frac{A\\vect{u}_{k}}{S_{k+1}}\n\\end{equation*}\nwhere $S_{k+1}$ is the entry of $A\\vect{u}_{k}$ which has largest absolute\nvalue.\n\n\\item When the scaling factors, $S_{k}$ are not changing much, $S_{k+1}$\nwill be close to the eigenvalue and $\\vect{u}_{k+1}$ will be close to an\neigenvector.\n\n\\item Check your answer to see if it worked well.\n\\end{enumerate}\n\\end{procedure}\n\nThe shifted inverse power method involves finding the eigenvalue closest to\na given complex number along with the associated eigenvalue. If $\\mu $ is a\ncomplex number and you want to find $\\lambda $ which is closest to $\\mu$,\nyou could consider the eigenvalues and eigenvectors of $(A-\\mu\nI) ^{-1}$. Then $A\\vect{x}=\\lambda \\vect{x}$ if and only if\n\\begin{equation*}\n(A-\\mu I) \\vect{x}=(\\lambda -\\mu) \\vect{x}\n\\end{equation*}\nIf and only if\n\\begin{equation*}\n\\frac{1}{\\lambda -\\mu }\\vect{x}=(A-\\mu I) ^{-1}\\vect{x}\n\\end{equation*}\nThus, if $\\lambda $ is the closest eigenvalue of $A$ to $\\mu $ then out of\nall eigenvalues of $(A-\\mu I) ^{-1}$, you would have $\\frac{1}{\n\\lambda -\\mu }$ would be the largest. Thus all you have to do is apply the\npower method to $(A-\\mu I) ^{-1}$ and the eigenvector you get\nwill be the eigenvector which corresponds to $\\lambda $ where $\\lambda $ is\nthe closest to $\\mu $ of all eigenvalues of $A$. You could use the\neigenvector to determine this directly.\n\n\\begin{example}{Finding eigenvalue and eigenvector}{}\nFind the eigenvalue and eigenvector for\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n3 & 2 & 1 \\\\\n-2 & 0 & -1 \\\\\n-2 & -2 & 0\n\\end{mymatrix}\n\\end{equation*}\nwhich is closest to $0.9+0.9i$.\n\\end{example}\n\n\\begin{solution}\nForm\n\\begin{eqnarray*}\n&&(\\begin{mymatrix}{rrr}\n3 & 2 & 1 \\\\\n-2 & 0 & -1 \\\\\n-2 & -2 & 0\n\\end{mymatrix} -(0.9+0.9i) \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}) ^{-1} \\\\\n&=&\\begin{mymatrix}{ccc}\n-0.619\\,19-10.\\,\\allowbreak 545i & -5.\\,\\allowbreak 524\\,9-4.\\,\\allowbreak\n972\\,4i & -0.370\\,57-5.\\,\\allowbreak 821\\,3i \\\\\n5.\\,\\allowbreak 524\\,9+4.\\,\\allowbreak 972\\,4i & 5.\\,\\allowbreak\n276\\,2+0.248\\,62i & 2.\\,\\allowbreak 762\\,4+2.\\,\\allowbreak 486\\,2i \\\\\n0.741\\,14+11.\\,\\allowbreak 643i & 5.\\,\\allowbreak 524\\,9+4.\\,\\allowbreak\n972\\,4i & 0.492\\,52+6.\\,\\allowbreak 918\\,9i%\n\\end{array}%\n}\n\\end{eqnarray*}\nThen pick an initial guess an multiply by this matrix raised to a large\npower.\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\n-0.619\\,19-10.\\,\\allowbreak 545i & -5.\\,\\allowbreak 524\\,9-4.\\,\\allowbreak\n972\\,4i & -0.370\\,57-5.\\,\\allowbreak 821\\,3i \\\\\n5.\\,\\allowbreak 524\\,9+4.\\,\\allowbreak 972\\,4i & 5.\\,\\allowbreak\n276\\,2+0.248\\,62i & 2.\\,\\allowbreak 762\\,4+2.\\,\\allowbreak 486\\,2i \\\\\n0.741\\,14+11.\\,\\allowbreak 643i & 5.\\,\\allowbreak 524\\,9+4.\\,\\allowbreak\n972\\,4i & 0.492\\,52+6.\\,\\allowbreak 918\\,9i%\n\\end{mymatrix} ^{15}\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nThis equals\n\\begin{equation*}\n\\begin{mymatrix}{c}\n1.\\,\\allowbreak 562\\,9\\times 10^{13}-3.\\,\\allowbreak 899\\,3\\times 10^{12}i\n\\\\\n-5.\\,\\allowbreak 864\\,5\\times 10^{12}+9.\\,\\allowbreak 764\\,2\\times 10^{12}i\n\\\\\n-1.\\,\\allowbreak 562\\,9\\times 10^{13}+3.\\,\\allowbreak 899\\,9\\times 10^{12}i\n\\end{mymatrix}\n\\end{equation*}\nNow divide by an entry to make the vector have reasonable size. This yields\n\\begin{equation*}\n\\begin{mymatrix}{c}\n-0.999\\,99-3.\\,\\allowbreak 614\\,0\\times 10^{-5}i \\\\\n0.499\\,99-0.499\\,99i \\\\\n1.0\n\\end{mymatrix}\n\\end{equation*}\nwhich is close to\n\\begin{equation*}\n\\begin{mymatrix}{c}\n-1 \\\\\n0.5-0.5i \\\\\n1.0\n\\end{mymatrix}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n3 & 2 & 1 \\\\\n-2 & 0 & -1 \\\\\n-2 & -2 & 0\n\\end{mymatrix} \\begin{mymatrix}{c}\n-1 \\\\\n0.5-0.5i \\\\\n1.0\n\\end{mymatrix} =\\begin{mymatrix}{c}\n-1.0-1.0i \\\\\n1.0 \\\\\n1.0+1.0i\n\\end{mymatrix}\n\\end{equation*}\nNow to determine the eigenvalue, you could just take the ratio of\ncorresponding entries. Pick the two corresponding entries which have the\nlargest absolute values. In this case, you would get the eigenvalue is $1+i$\nwhich happens to be the exact eigenvalue. Thus an eigenvector and eigenvalue\nare\n\\begin{equation*}\n\\begin{mymatrix}{c}\n-1 \\\\\n0.5-0.5i \\\\\n1.0\n\\end{mymatrix}, 1+i\n\\end{equation*}\n\\end{solution}\n\nUsually it won't work out so well but you can still find what is desired.\nThus, once you have obtained approximate eigenvalues using the $QR$\nalgorithm, you can find the eigenvalue more exactly along with an\neigenvector associated with it by using the shifted inverse power method.\n", "meta": {"hexsha": "dc910d35459a1a64104b80ed655c3109c5e02b72", "size": 7893, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityQRFactorizationPowerMethods.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/spectraltheoryOrthogonalityQRFactorizationPowerMethods.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/spectraltheoryOrthogonalityQRFactorizationPowerMethods.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.0742574257, "max_line_length": 145, "alphanum_fraction": 0.6840238186, "num_tokens": 2893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.9161096072908429, "lm_q1q2_score": 0.7768314030832938}}
{"text": "\\section{Finite State Automata}\n\n\\subsection{Alphabets \\& Strings}\n\n\\begin{itemize}\n\t\n\t\\item Let $ A $ be a set; then $ A^n $ is the set of all finite sequences $ a_1 \\dots a_n $ with $ a_i \\in A $, $ 1 \\le i \\le m $\n\t\n\t\\begin{itemize}\n\t\t\\item Elements of $ A $ are \\textit{letters} or \\textit{symbols}\n\t\t\n\t\t\\item Elements of $ A^n $ are \\textit{words} or \\textit{strings} over $ A $ of length $ m $\n\t\\end{itemize}\n\n\t\\item $ \\varepsilon $ is the special \\textit{empty string}, the only string of length $ 0 $\n\n\t\\item $ A^+ = \\bigcup_{m \\ge 1} A^m $ -- the set of non-empty strings over $ A $ of any length\n\t\n\t\\item $ A^* = A^+ \\cup \\varepsilon = \\bigcup_{m \\ge 0} A^m$ -- the set of (possibly empty) strings over $ A $ of any length\n\t\n\t\\item If $ \\alpha = a_1 \\dots a_m $, $ \\beta = b_1 \\dots b_m \\in A^* $, then define $ \\alpha \\beta $ to be $ a_1 \\dots a_m b_1 \\dots b_m \\in A^{m + n} $. This gives binary `product' or \\textit{concatenation} on $ A^* $\n\t\n\t\\item For $ \\alpha \\in A^+ $, define $ \\alpha^n, n \\in \\Nat $ by $ \\alpha^0 = \\varepsilon $, and $ \\alpha^{n+1} = \\alpha^n \\alpha $\n\t\n\t\\item A \\textit{language} with alphabet $ A $ is a subset of $ A^* $\n\t\n\\end{itemize}\n\n\\clearpage\n\n\\subsection{Definition of an FSA}\n\n\\begin{itemize}\n\t\n\t\\item A Finite State Automaton (FSA) is a tuple $ M = (Q, F, A, \\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 the alphabet\n\t\t\n\t\t\\item $ \\tau \\subseteq Q \\times A \\times Q $ is the set of transitions\n\t\t\n\t\t\\item $ q_0 \\in Q $ is the initial state\n\t\t\n\t\\end{itemize}\n\n\t\\item The transition diagram of an FSA is a directed graph with:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Vertex set $ Q $\n\t\t\n\t\t\\item An edge for each transition; $ (q, a, q') \\in \\tau $ corresponds to an edge from $ q $ to $ q' $ with label $ a $\n\t\t\n\t\t\\item Initial state $ q_0 $ labelled with $ - $\n\t\t\n\t\t\\item Final states labelled with $ + $\n\t\t\n\t\t\\item Example: a \\textit{non-deterministic} `haha machine', with $ A = \\set{h, a} $\n\t\t\n\t\t\\begin{tikzpicture}\n\t\t\\node[circle,thick,draw] (q0) at (0, 0) {$ - $};\n\t\t\\node[circle,thick,draw] (q1) at (2, 0) {$ \\; $};\n\t\t\\node[circle,thick,draw] (q2) at (4, 0) {$ + $};\n\t\t\n\t\t\\draw[edge] (q0) to[bend left] node[above] {h} (q1);\n\t\t\\draw[edge] (q1) to[bend left] node[above] {a} (q2);\n\t\t\\draw[edge] (q1) to[bend left] node[below] {a} (q0);\n\t\t\\end{tikzpicture}\n\t\t\n\t\\end{itemize}\n\n\t\\item A \\textit{computation} of $ M $ is a sequence $ q_0, a_1, q_1, a_2, \\dots, a_n, q_n $ with $ n \\ge 0 $ where $ (q_i, a_{i+1}, q_{i+1}) \\in \\tau $ for $ 0 \\le i \\le n - 1 $\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item The \\textit{label} on the computation is $ a_1 \\dots a_m $\n\t\t\n\t\t\\item The computation is \\textit{successful} if $ q_n \\in F $\n\t\t\n\t\t\\item A string $ a_1 \\dots a_n $ is \\textit{accepted} by $ M $ if there is a successful computation with label $ a_1 \\dots a_n $, and it is \\textit{rejected} otherwise\n\t\t\n\t\\end{itemize}\n\n\t\\item The language recognised by $ M $ is $ \\Lang(M) = \\setcomp{w \\in A^*}{w \\text{ is accepted by } M} $\n\t\n\t\\item There is a one-to-one correspondence between computations of $ M $ and paths in the graph from $ q_0 $\t\n\t\n\t\\item Example: $ A = \\set{a, b} $ of an FSA accepting only words with an odd number of 'a's\n\t\n\t\\begin{tikzpicture}\n\t\\node[circle,thick,draw] (q0) at (0, 0) {$ - $};\n\t\\node[circle,thick,draw] (q1) at (4, 0) {$ + $};\n\t\n\t\\draw[edge] (q0) to[bend left] node[above] {a} (q1);\n\t\\draw[edge] (q0) to[loop left] node[left] {b} (q0);\n\t\n\t\\draw[edge] (q1) to[bend left] node[above] {a} (q0);\n\t\\draw[edge] (q1) to[loop right] node[right] {b} (q1);\n\t\\end{tikzpicture}\n\t\n\t\\item An FSA is deterministic (a DFA) if for all $ q \\in Q, a \\in A $ there is exactly one $ q' \\in Q $ such that $ (q, a, q') \\in \\tau $\n\t\n\t\\item Example: DFA for the `haha machine'\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) {$ \\; $};\n\t\\node[circle,thick,draw] (q2) at (4, 0) {$ + $};\n\t\n\t\\draw[edge] (q0) to[bend left] node[above] {h} (q1);\n\t\\draw[edge] (q1) to[bend left] node[above] {a} (q2);\n\t\\draw[edge] (q2) to[bend left] node[below] {h} (q1);\n\t\\end{tikzpicture}\n\t\n\t\\item Note this machine lacks a transition for $ a $ when in the initial state -- though technically required for a DFA, it is easily fixed by adding an `error state' to catch what would otherwise be missing transitions\n\t\n\\end{itemize}\n\n\\clearpage\n\n\\subsection{Deterministic FSAs}\n\n\\begin{itemize}\n\t\n\t\\item For a DFA $ M $, define the transition function $ \\delta: Q \\times A \\to Q $ by $ q' = \\delta(q, a) $, where $ q' $ is the unique element such that $ (q, a, q') \\in \\tau $\n\t\n\t\\item If $ \\Lang $ is a language with alphabet $ A $, then the following are equivalent:\n\t\n\t\\begin{enumerate}\n\t\t\\item $ \\Lang $ is recognised by an FSA\n\t\t\n\t\t\\item $ \\Lang $ is recognised by a DFA\n\t\\end{enumerate}\n\t\n\t\\item Given a non-deterministic FSA $ M = (Q, F, A, \\tau, q_0) $, an equivalent DFA $ M' = (Q', F', A, \\tau', q_0') $ may be generated by the \\textit{powerset method}:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item $ Q' = \\powerset{Q} \\setminus \\emptyset $ (i.e. the set of all subsets of $ Q $ that aren't empty)\n\t\t\n\t\t\\item $ F' = \\setcomp{X \\in Q'}{q \\in X \\text{ for some } q \\in F} $\n\t\t\n\t\t\\item For $ X \\in Q', a \\in A $, define $ \\delta(X, a) := \\setcomp{q \\in Q}{(x, a, q) \\in \\tau \\text{ for some } x \\in X} $\n\t\t\n\t\t\\item $ \\tau' = \\setcomp{(X, a, \\delta(X, a))}{X \\in Q', a \\in A} $\n\t\t\n\t\t\\item $ q_0' = \\set{q_0} $\n\t\t\n\t\\end{itemize}\n\n\t\\item Proof: show that $ \\Lang(M) = \\Lang(M') $\n\t\n\t\\begin{itemize}\n\t\t\\item $ \\Lang(M) \\subseteq Lang(M') $:\n\t\t\n\t\t\\begin{itemize}\n\t\t\t\\item Given $ w \\in \\Lang(M) $, $  q_0 a_1 \\dots a_n q_n $ is a successful computation of $ M $\n\t\t\t\n\t\t\t\\item Then define $ q_i' = \\delta(q_{i-1}', a_i) $ for $ 1 \\le i \\le n $\n\t\t\t\n\t\t\t\\item $ q_0', a_1, q_1' \\dots a_n, q_n' $ will be a successful computation of $ M' $\n\t\t\t\n\t\t\t\\item Therefore $ w \\in \\Lang(M') $\n\t\t\\end{itemize}\n\t\n\t\\item $ \\Lang(M') \\subseteq Lang(M) $:\n\t\n\t\\begin{itemize}\n\t\t\\item Let $ w = a_1 \\dots a_n \\in L(M') $, and $  q_0', a_1, q_1' \\dots a_n, q_n' $ be a successful computation of $ M $\n\t\t\n\t\t\\item Each $ q_i' $ cannot be the empty set\n\t\t\n\t\t\\item By definition of $ \\tau' $, $ \\exists q_1 \\in q_1' $ s.t. $ (q_0, a_1, q_1) \\in \\tau $\n\t\t\n\t\t\\item Then we can find $ q_i \\in q_i' $ s.t. $ (q_{i-1}, a_i, q_i) \\in \\tau $ for $ 1 \\le i \\le n $\n\t\t\n\t\t\\item For $ q_n $ we further require $ q_n \\in F $\n\t\t\n\t\t\\item Therefore, $ q_0, a_1, q_1, a_2, \\dots a_n, q_n $ is a successful computation\n\t\t\n\t\t\\item Therefore $ w \\in \\Lang(M) $\n\t\\end{itemize}\n\t\n\t\\end{itemize}\n\t\n\\end{itemize}\n\n\\clearpage\n\n\\subsection{The Pumping Lemma}\n\n\\begin{itemize}\n\t\n\t\\item The Pumping Lemma says that for any $ \\Lang $ recognised by an FSA $ M $, there is a certain word length beyond which all words can be split into sections as $ xyz$, where $ x y^n z $ is also in the language\n\t\n\t\\item Formally there is an integer $ p > 0 $ s.t. any word $ w \\in L $ with $ \\abs{w} \\ge p $ is of the form $ w = xyz $, where $ \\abs{y} > 0 $, $ \\abs{xy} \\le p $ and $ x y^i z \\in \\Lang $ for $ i \\ge 0 $\n\t\n\t\\item Proof:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Let $ p $ be the number of states in $ M $, and suppose $ w = a_1 \\dots a_n \\in \\Lang $, where $ n \\ge p $\n\t\t\n\t\t\\item A successful computation $ q_0, a_1, \\dots, q_n $ has to pass through a certain state at least twice (by the pigeonhole principle)\n\t\t\n\t\t\\item Therefore, $ \\exists r < s $ s.t. $ q_r = q_s $; choose minimal such $ s $\n\t\t\n\t\t\\item Now put $ x = a_1 \\dots a_r $, $ y = a_{r+1} \\dots a_s $ (note $ \\abs{y} > 0$), and $ z = a_{s+1} \\dots a_n $\n\t\t\n\t\t\\item By minimality of $ s $, $ q_0, \\dots q_{s-1} $ are distinct, and $ \\abs{xy} = s \\le p $\n\t\t\n\t\t\\item Then, note that $ q_r, a_{r+1}, \\dots, q_{s} $ is a loop, which may be validly repeated $ i \\ge 0 $ times\n\t\t\n\t\t\\item Therefore, $ x y^i z \\in \\Lang $\n\t\t\n\t\\end{itemize}\n\n\t\\item Corollary: there exist languages which are not computable by an FSA\n\t\n\t\\item Example: there is no FSA which can recognise $ \\Lang = \\setcomp{a^n b^n}{n \\in \\Nat} $\n\t\n\t\\item Proof:\n\t\n\t\\begin{itemize}\n\t\t\n\t\t\\item Assume for a contradiction there exists an FSA $ M $ which can recognise $ \\Lang $\n\t\t\n\t\t\\item Let $ p $ be the number from the pumping lemma, and choose $ n \\ge p $ and consider $ w = a^n b^n $\n\n\t\t\\item By the pumping lemma, $ \\exists x, y, z $ s.t. $ a^n b^n = xyz $, with $ \\abs{y} \\ge 1 $ and $ \\abs{xy} \\le p \\le n $\n\t\t\n\t\t\\item Then $ y $ is written entirely in terms of the letter a, and $ \\abs{y} \\ge 1 $\n\t\t\n\t\t\\item By the pumping lemma, $ x y^i z \\in \\Lang $ for all $ i $\n\t\t\n\t\t\\item So choose $ i = 0 $, then some $ w = a^k b^n \\in \\Lang $ s.t. $ k < n $, which is a contradiction \n\t\t\n\t\\end{itemize}\n\t\n\\end{itemize}\n", "meta": {"hexsha": "ffe82436e46a7a05ab2a5e28468b819b11df21f5", "size": 8734, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MATH3306/computability/c_fsa.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_fsa.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_fsa.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": 35.5040650407, "max_line_length": 220, "alphanum_fraction": 0.5994962217, "num_tokens": 3347, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443461, "lm_q2_score": 0.8652240877899775, "lm_q1q2_score": 0.7767075925950542}}
{"text": "\\section{Linear equations}\n\\subsection{Linear and affine functions}\nSuperposition condition:$f(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)$\\\\\nSuch an f is called Linear\\\\\nMatrix vector product function: A is mXn matrix such that $f(x)=Ax$ and f is linear $f(\\alpha x + \\beta y)=A(\\alpha x + \\beta y)=\\alpha f(x) + \\beta f(y)$\\\\\nConverse is true: If $f:R^{n} \\mapsto R^{m}$ is linear, then $f(x)=f(x_{1}e_{1}+x_{2}e_{2}+...x_{n}e_{n})$\n\\newline $=x_{1}f(e_{1})+x_{2}f(e_{2})+...x_{n}f(e_{n})$\n\\newline$=Ax$ with $A = [f(e_{1})+f(e_{2})+...f(e_{n})]$\n\\newline Affine Functions:$f:R^{n} \\mapsto R^{m}$ is affine if it is a linear function plus a constant i.e $f(x)=Ax+b$ same as $f(\\alpha x + \\beta y)=\\alpha f(x)+\\beta f(y)$ holds for all x, y and $\\alpha,\\beta$ such that $\\alpha+\\beta=1$ \n\\newline A and B can be calculated as \\\\\n$A=[f(e_{1})-f(0)\\thickspace f(e_{2})-f(0) ... f(e_{n})-f(0)]] ; b= f(0)$\\\\\nAffine functions sometimes incorrectly called linear functions\n\\subsection{Linear function models}\nPrice elasticity of demand\n$\\delta_i^{price}=(p_i^{new}-p_{i})/p_{i}$: fractional changes in prices\n$\\delta_i^{dem}=(d_i^{new}-d_{i})/d_{i}$: fractional change in demand\nPrice demand elasticity model: $\\delta^{dem}=E\\delta^{price}$\\\\\nTaylor series approximation\nRegression model\n\\subsection{Systems of linear equations}", "meta": {"hexsha": "bd8cc492698e5b5fc59352c3b07248c2c5e705c9", "size": 1327, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_stars_repo_name": "ksb25395/COT5615", "max_stars_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_issues_repo_name": "ksb25395/COT5615", "max_issues_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter8.tex", "max_forks_repo_name": "ksb25395/COT5615", "max_forks_repo_head_hexsha": "d3f9d9375597ea2b15404ae5f46d21d9073b8697", "max_forks_repo_licenses": ["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.35, "max_line_length": 239, "alphanum_fraction": 0.6616428033, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140232, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7766160476421964}}
{"text": "%!TEX root = ../TTK18-Summary.tex\n\\section{Linear matrix inequalities}\nMany problems in systems and control can be reduced to optimization problems involving LMIs, for which there exist efficient numerical solvers.\n\nAn LMI has the form\n%\n\\begin{equation}\n  F(p) = F_0 + \\sum_{i=1}^m p_i F_i > 0\n\\end{equation}\n%\nwhere $p$ is the variable vector, and $F_i = F_i^T$. Multiple LMIs can be rewritten as a single LMI by stacking each matrix on the diagonal:\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    F^{(1)}(p) &&\\\\\n    & \\ddots &\\\\\n    && F^{(n)}(p)\n  \\end{bmatrix} > 0\n\\end{equation}\n\n\\subsection{Some LMI problems}\n\\paragraph{Feasibility problem} Is $\\dot{x} = Ax$ stable? Yes, given\n%\n\\begin{equation}\\label{eq:linear-auto-stability}\n  A\\tp P + PA < 0,\\quad P > 0\n\\end{equation}\n%\nfor the Lyapunov function $V(x) = x\\tp P x$. (This is equivalent to the requirement that all real parts of the eigenvalues of $A$ are negative.) Equation \\eqref{eq:linear-auto-stability} can be written as a single LMI by stacking the two inequalities in one matrix:\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    A\\tp P + PA & 0 \\\\\n    0 & -P\n  \\end{bmatrix}\n  < 0\n\\end{equation}\n\n\\paragraph{Convex function minimization} For the system\n%\n\\begin{equation}\n  \\begin{split}\n    \\dot{x} &= Ax + Bw \\\\\n    z &= Cx + Dw\n  \\end{split}\n\\end{equation}\n%\nthe $H_\\infty$-norm of the transfer function from $w$ to $z$ can be found by\n%\n\\begin{gather}\n% \\begin{equation}\n% \\begin{split}\n  \\min \\gamma \\\\\n  \\mbox{s.t. }\n  \\begin{bmatrix}\n    A\\tp P + PA & PB & C\\tp \\\\\n    B\\tp P & -\\gamma I & D\\tp \\\\\n    C & D & -\\gamma I\n  \\end{bmatrix}\n   < 0\n% \\end{split}\n% \\end{equation}\n\\end{gather}\n\n\\subsection{LMI tricks}\n\\subsubsection{Preliminaries}\nIf $W$ is full rank, then pre-multiplication with $W\\tp$ and post-multiplication with $W$ does not change sign-definiteness:\n%\n\\begin{equation}\\label{eq:pre-post-multiply}\n  Q > 0 \\Leftrightarrow W\\tp Q W > 0 \\quad (\\mbox{for full rank } W)\n\\end{equation}\n\n\\subsubsection{Change of variables}\\label{sssec:change-of-variables}\nSometimes changing the variables can linearize the problem.\n\\paragraph{Example} State feedback: Find $u = Kx$ to stabilize the system. Must find $P > 0$ and $K$ such that\n%\n\\begin{equation}\n  (A + BK)\\tp P + P(A + BK) < 0.\n\\end{equation}\n%\nIf this is fullfilled, we have shown Lyapunov stability, but this is not linear in $P$ and $K$. Like in \\eqref{eq:pre-post-multiply}, we can pre- and postmultiply by $Q = P^{-1}$ to get\n%\n\\begin{equation}\n  QA\\tp + AQ + QK\\tp B\\tp + BKQ < 0\n\\end{equation}\n%\nand define $L = KQ$ to get (remember $Q = P^{-1}$ so $Q = Q\\tp$)\n%\n\\begin{equation}\n  QA\\tp + AQ + L\\tp B\\tp + BL < 0.\n\\end{equation}\n%\nThis is an LMI in $Q > 0$ and $L$!\n\n\\subsubsection{Congruence transform}\nWith e.g.\n%\n\\begin{equation}\n  Q =\n  \\begin{bmatrix}\n    A\\tp P + PA & PBK + C\\tp V \\\\\n    * & -2V\n  \\end{bmatrix}\n  < 0\n\\end{equation}\n%\nin variables $P>0$, $V>0$, and $K$. Choosing the full-rank $W$\n%\n\\begin{equation}\n  W =\n  \\begin{bmatrix}\n    P^{-1} & 0 \\\\\n    0 & V^{-1}\n  \\end{bmatrix}\n\\end{equation}\n%\ngives\n%\n\\begin{equation}\n  W\\tp Q W =\n  \\begin{bmatrix}\n    XA\\tp + AX & BL + XC\\tp \\\\\n    * & -2U\n  \\end{bmatrix}\n\\end{equation}\n%\nwhich is an LMI in $X = P^{-1}$, $U = V^{-1}$, $L = KV^{-1}$.\n\n\\subsubsection{Schur complement}\nThese are equivalent:\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    \\Phi_{11} & \\Phi_{12} \\\\\n    \\Phi_{12}\\tp & \\Phi_{22}\n  \\end{bmatrix}\n  < 0\n  \\quad \\Leftrightarrow \\quad\n  \\begin{cases}\n    \\Phi_{22} < 0 \\\\\n    \\Phi_{11} - \\Phi_{12} \\Phi_{22}^{-1} \\Phi_{12}\\tp < 0\n  \\end{cases}\n\\end{equation}\n\n\\paragraph{Example} Given $Q \\geq 0$, $R > 0$, find $P > 0$ such that the Ricatti inequality\n%\n\\begin{equation}\n  A\\tp P + PA + PBR^{-1}B\\tp P + Q < 0.\n\\end{equation}\n%\nWe can rearrange to reveal a similarity\n%\n\\begin{equation}\n  \\underbrace{A\\tp P + PA + Q}_{\\Phi_{11}}\n  -\n  \\underbrace{PB}_{\\Phi_{12}}\n  \\underbrace{(-R^{-1})}_{\\Phi_{22}^{-1}}\n  \\underbrace{B\\tp P}_{\\Phi_{12}\\tp}\n  < 0.\n\\end{equation}\n%\nFrom the Schur complement and that $-R < 0$, this is equivalent to\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    A\\tp P + PA + Q & PB \\\\\n    * & -R\n  \\end{bmatrix}\n  < 0.\n\\end{equation}\n\n\\subsubsection{S-procedure}\nUsed when we need a criterion fulfilled locally, such as $F_0(x) \\leq 0$ only when $F_i(x) > 0$, that is, the S-procedure gives a criterion for when one inequality is implied by another.\n\nWe want $F_0(x) \\leq 0$ when $F_i(x) > 0$. This is true given\n%\n\\begin{equation}\n  F\\sub{aug}(x) = F_0(x) + \\sum_{i=1}^q \\tau_i F_i(x) \\leq 0, \\quad \\tau_i \\geq 0\n\\end{equation}\n\n\\paragraph{Example} Find $P>0$ such that\n%\n\\begin{equation}\n  \\bmat{x \\\\ z}\\tp\n  \\underbrace{\\bmat{A\\tp P & PB \\\\ * & 0}}_{F_0}\n  \\bmat{x \\\\ z}\n  < 0\n\\end{equation}\n%\nwhen\n%\n\\begin{equation}\n  z\\tp z \\leq x\\tp C\\tp C x\n  \\quad \\Leftrightarrow \\quad\n  \\bmat{x \\\\ z}\\tp\n  \\underbrace{\\bmat{C\\tp C & 0 \\\\ * & -I}}_{F_1}\n  \\bmat{x \\\\ z}\n  \\geq 0.\n\\end{equation}\n\nThis can be transformed into an LMI by the S-procedure:\n%\n\\begin{equation}\n  \\bmat{x \\\\ z}\\tp\n  \\underbrace\n    {\n      \\begin{bmatrix}\n        A\\tp P + PA + \\tau C\\tp C & PB \\\\\n        * & -\\tau I\n      \\end{bmatrix}\n    }_{F\\sub{aug}}\n  \\bmat{x \\\\ z}\n  < 0.\n\\end{equation}\n%\nThis is an LMI in $P>0$ and $\\tau \\geq 0$.\n\n\\subsubsection{Projection lemma}\nSometimes we get equations like\n%\n\\begin{equation}\\label{eq:finsler-projection-formulation}\n  \\Psi(X) + G(X)\\Lambda\\tp H(X) + H(X)\\Lambda\\tp G\\tp(X) < 0\n\\end{equation}\n%\nin matrix variables $X$ and $\\Lambda$. $\\Psi$, $G$, and $H$ are affine functions of $X$. Equation \\eqref{eq:finsler-projection-formulation} is equivalent to\n%\n\\begin{equation}\n  \\begin{split}\n    W_{G(X)}\\tp \\Psi(X) W_{G(X)} &< 0 \\\\\n    W_{H(X)}\\tp \\Psi(X) W_{H(X)} &< 0\n  \\end{split}\n\\end{equation}\n%\nwhere $W_{G(X)}$ and $W_{H(X)}$ are orthogonal complements to $G$ and $H$:\n\\begin{gather}\n  W_{G(X)} G(X) = 0,\\quad W_{H(X)} H(X) = 0 \\\\\n  \\rank W_{G(X)} + \\rank G = n,\\quad \\rank W_{H(X)} + \\rank H = n.\n\\end{gather}\n%\nThis is useful as it may linearize the formulation, and it may reduce the number of variables in the computation.\n\n\\paragraph{Example} State feedback:\n%\n\\begin{equation}\n  (A + BK)\\tp P + P(A + BK) < 0,\\quad P > 0\n\\end{equation}\n%\ncan be rewritten by a change of variables (Section \\ref{sssec:change-of-variables}) as\n%\n\\begin{equation}\n  QA\\tp + AQ + L\\tp B\\tp + BL < 0,\\quad Q > 0.\n\\end{equation}\n%\nUsing the projection lemma this can be written without $L$:\n%\n\\begin{equation}\n  \\begin{rcases}\n    W_B\\tp(AQ+QA\\tp)W_B < 0 \\\\\n    W_I\\tp(AQ+QA\\tp)W_I < 0\n  \\end{rcases} Q > 0\n\\end{equation}\n%\nIn this case the second inequality is unnecessary, because $I$ is full rank. First inequality can be interpreted as ``the system is stable if it is stable in the null space of the inputs.''\n\n\\subsubsection{Finsler's lemma}\nFinsler's lemma is another way of writing \\eqref{eq:finsler-projection-formulation} more compactly:\n%\n\\begin{equation}\n  \\begin{split}\n    \\Psi(X) - \\sigma G(X) G(X)\\tp &< 0 \\\\\n    \\Psi(X) - \\sigma H(X) H(X)\\tp &< 0\n  \\end{split}\n\\end{equation}\n%\nfor some real $\\sigma$.\n\n\\paragraph{Example} State feedback:\n%\n\\begin{equation}\n  (A + BK)\\tp P + P(A + BK) < 0,\\quad P > 0\n\\end{equation}\n%\ncan be rewritten\n%\n\\begin{equation}\n  QA\\tp + AQ + L\\tp B\\tp + BL < 0,\\quad Q > 0.\n\\end{equation}\n%\nUsing Finsler's lemma this can be written without $L$\n%\n\\begin{equation}\n  \\begin{rcases}\n    &AQ + QA\\tp - \\sigma BB\\tp < 0 \\\\\n    &AQ + QA\\tp - \\sigma I < 0\n  \\end{rcases} Q > 0.\n\\end{equation}\n%\nAs long as $Q$ and $\\sigma$ fulfilling the first inequality are found, it is always possible to find $\\sigma$ to fulfill the second.\n\n\\subsection{Applications}\n\n\\subsubsection{Discrete-time state feedback stabilization}\nDiscrete systems use Lyapunov differences. For the LF\n%\n\\begin{equation}\n  V(x_k) = x_k\\tp P x_k,\\quad P>0\n\\end{equation}\n%\nthe system is stable if\n%\n\\begin{equation}\n  V(x_k) - V(x_{k+1}) = x_k\\tp P x_k - x_{k+1}\\tp P x_{k+1} > 0,\n\\end{equation}\n%\nwhich is equivalent to\n%\n\\begin{equation}\n  P - (A + BK)\\tp P (A+BK) > 0.\n\\end{equation}\n%\nThe Schur complement is\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    P & (A + BK)\\tp P \\\\\n    P(A + BK) & P\n  \\end{bmatrix}\n  > 0,\n\\end{equation}\n%\nand congruence transform with $W = \\bmat{P\\inv & 0 \\\\ 0 & P\\inv}$ gives\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    P\\inv & P\\inv (A + BK)\\tp \\\\\n    (A + BK) P\\inv & P\\inv\n  \\end{bmatrix}\n  > 0.\n\\end{equation}\n%\nA change of variables $Q = P\\inv$, $L = KP\\inv$ gives\n%\n\\begin{equation}\n  \\begin{bmatrix}\n    Q & QA\\tp + L\\tp B\\tp \\\\\n    AQ + BL & Q\n  \\end{bmatrix}\n  > 0\n\\end{equation}\n%\nwhich is an LMI in $Q > 0$ and $L$.\n\n\\subsubsection{Robust feedback stabilization}\nPlant not exactly known, but known to be in a set\n%\n\\begin{equation}\n  \\bmat{A \\\\ B} \\in \\co \\bmat{A_1 \\dots A_q \\\\ B_1 \\dots B_q}\n\\end{equation}\n%\nwhere $\\co$ denotes convex combination. Equivalent:\n%\n\\begin{equation}\n    A = \\sum_{i=1}^q a_i A_i,\\quad B = \\sum_{i=1}^q a_i B_i \\\\\n\\end{equation}\n%\nwith\n%\n\\begin{equation}\n  \\sum_{i=1}^q a_i = 1, a_i \\geq 0.\n\\end{equation}\n%\nA controller that solves the LMIs for all $q$ extreme plants with the same $Q$ and $L$ is stable for all $A$ and $B$.\n\n\\subsubsection{Parameter dependent LFs}\nWith a model\n%\n\\begin{equation}\n  A(\\delta) = A_0 + \\sum_{i=1}^q \\delta_i A_i\n\\end{equation}\n%\nwith bounds and rate limits\n%\n\\begin{equation}\n  \\delta_i \\in [\\underline\\delta_i, \\overline\\delta_i], \\quad \\dot\\delta_i \\in [\\underline\\lambda_i, \\overline\\lambda_i ]\n\\end{equation}\n%\n$\\Delta$ is the set of all $\\delta$ that are within the bounds, and $\\Lambda$ is the set of all $\\dot\\delta$ within the rate limits. $\\Delta_0$ and $\\Lambda_0$ are their respective vertex sets.\n\nSome LFs have the form\n%\n\\begin{equation}\n  V(\\delta,x) = x\\tp P(\\delta)x,\\quad P(\\delta) = P_0 + \\sum_{i=1}^q \\delta_i P_i.\n\\end{equation}\n%\nwhich gives\n%\n\\begin{equation}\n  \\od{P(\\delta)}{t} = \\dot\\delta_1 P_1 + \\dots + \\dot\\delta_q P_q = P(\\dot\\delta) - P_0\n\\end{equation}\n%\nleading to\n%\n\\begin{equation}\n  \\dot{V}(\\delta,x) = x\\tp \\left(A\\tp(\\delta) P(\\delta) + P(\\delta) A(\\delta) + P(\\dot{\\delta}) - P_0 \\right)x.\n\\end{equation}\n%\nWhich is stable if there exists matrices $P_0 \\dots P_q$ such that\n%\n\\begin{equation}\n  \\begin{split}\n    A\\tp(\\delta)P(\\delta) + P(\\delta)A(\\delta) + P(\\dot\\delta) &< P_0, \\quad \\forall \\delta \\in \\Delta_0, \\forall \\dot\\delta \\in \\Lambda_0 \\\\\n    P(\\delta) &> I, \\quad \\forall \\delta \\in \\Delta_0 \\\\\n    A_i\\tp + P_iA_i &\\leq 0,\\quad i = 1,\\dots,q.\n  \\end{split}\n\\end{equation}\n%\nThis means that we only have to find valid LFs for the ``extreme points'', i.e. when $\\delta$ or $\\dot\\delta$ is at saturation.\n", "meta": {"hexsha": "4b521999e9347a862193391f0b3e759d04891687", "size": 10591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-lmis.tex", "max_stars_repo_name": "jakoblover/ntnu-course-summaries", "max_stars_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-05-30T09:19:22.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-11T02:42:40.000Z", "max_issues_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-lmis.tex", "max_issues_repo_name": "jakoblover/ntnu-course-summaries", "max_issues_repo_head_hexsha": "8ba859de2349b93c5079ca10a4cf2ec49c1f5dc0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "TTK18 Optimaliseringsbasert reguleringsdesign og analyse/tex/sec-lmis.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": 25.3980815348, "max_line_length": 265, "alphanum_fraction": 0.6355396091, "num_tokens": 3986, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951607140233, "lm_q2_score": 0.8311430415844385, "lm_q1q2_score": 0.7766160359176336}}
{"text": "\\subsection{Trigonometric polynomials}\\label{subsec:trigonometric_polynomials}\n\n\\begin{definition}\\label{def:trigonometric_polynomial}\n  We define the \\term{trigonometric polynomials} over \\( \\BbbC \\) as the \\hyperref[def:laurent_polynomial/polynomial]{Laurent polynomials} \\( \\BbbC[e^{iz}] \\). A trigonometric polynomial \\( p \\in \\BbbC[e^{iz}] \\) can be written as\n  \\begin{equation}\\label{def:trigonometric_polynomial/exponential}\n    p(z) = \\sum_{k \\in \\BbbZ} c_k e^{ikz}\n  \\end{equation}\n  or, using \\hyperref[thm:exponential_trigonometric_identities/eulers_formula]{Euler's formula}, rewritten in the more conventional notation (see \\cite[1]{Боянов2008} or \\cite[88]{Rudin1987RealAndComplex}):\n  \\begin{equation}\\label{def:trigonometric_polynomial/trigonometric}\n    p(z) = a_0 + \\sum_{k=1}^\\infty [ a_k \\cos(kz) + b_k \\sin(kz) ],\n  \\end{equation}\n  where we denote \\( a_k \\coloneqq c_k \\) and \\( b_k \\coloneqq ic_k \\).\n\n  In particular, when using \\fullref{def:trigonometric_polynomial/trigonometric}, we may regard the coefficients \\( \\{ a_k \\}_{k=0}^\\infty \\) and \\( \\{ b_k \\}_{k=1}^\\infty \\) as either real or complex, which is a downside of \\fullref{def:trigonometric_polynomial/exponential}.\n\n  Denote by \\( \\tau_n(\\BbbK) \\) the vector space of all trigonometric polynomials of degree at most \\( n \\) with coefficients in \\( \\BbbK \\). We also introduce the subspaces \\( \\tau_n^\\alpha{\\BbbK} \\) of those polynomials which \\( a_0 = 0 \\).\n\\end{definition}\n", "meta": {"hexsha": "6f412fa293ef6da3a12d14bd295b47da4f9e485c", "size": 1464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/trigonometric_polynomials.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/trigonometric_polynomials.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/trigonometric_polynomials.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": 81.3333333333, "max_line_length": 276, "alphanum_fraction": 0.7260928962, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765210631688, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.7765987137234521}}
{"text": "\\subsubsection{Supervised Learning}\n\\label{learning}\n\nA conceptual difference between classical and ML methods is the format\n    for the model inputs.\nIn ML models, a time series $Y$ is interpreted as labeled data.\nLabels are collected into a vector $\\vec{y}$ while the corresponding\n    predictors are aligned in an $(T - n) \\times n$ matrix $\\mat{X}$:\n$$\n\\vec{y}\n=\n\\begin{pmatrix}\n    y_T \\\\\n    y_{T-1} \\\\\n    \\dots \\\\\n    y_{n+1}\n\\end{pmatrix}\n~~~~~~~~~~\n\\mat{X}\n=\n\\begin{bmatrix}\n    y_{T-1} & y_{T-2} & \\dots & y_{T-n} \\\\\n    y_{T-2} & y_{T-3} & \\dots & y_{T-(n+1)} \\\\\n    \\dots   & \\dots   & \\dots & \\dots \\\\\n    y_n     & y_{n-1} & \\dots & y_1\n\\end{bmatrix}\n$$\nThe $m = T - n$ rows are referred to as samples and the $n$ columns as\n    features.\nEach row in $\\mat{X}$ is \"labeled\" by the corresponding entry in $\\vec{y}$,\n    and ML models are trained to fit the rows to their labels.\nConceptually, we model a functional relationship $f$ between $\\mat{X}$ and\n    $\\vec{y}$ such that the difference between the predicted\n    $\\vec{\\hat{y}} = f(\\mat{X})$ and the true $\\vec{y}$ are minimized\n    according to some error measure $L(\\vec{\\hat{y}}, \\vec{y})$, where $L$\n    summarizes the goodness of the fit into a scalar value (e.g., the\n    well-known mean squared error [MSE]; cf., Section \\ref{mase}).\n$\\mat{X}$ and $\\vec{y}$ show the ordinal character of time series data:\n    Not only overlap the entries of $\\mat{X}$ and $\\vec{y}$, but the rows of\n    $\\mat{X}$ are shifted versions of each other.\nThat does not hold for ML applications in general (e.g., the classical\n    example of predicting spam vs. no spam emails, where the features model\n    properties of individual emails), and most of the common error measures\n    presented in introductory texts on ML, are only applicable in cases\n    without such a structure in $\\mat{X}$ and $\\vec{y}$.\n$n$, the number of past time steps required to predict a $y_t$, is an\n    exogenous model parameter.\nFor prediction, the forecaster supplies the trained ML model an input\n    vector in the same format as a row $\\vec{x}_i$ in $\\mat{X}$.\nFor example, to predict $y_{T+1}$, the model takes the vector\n    $(y_T, y_{T-1}, ..., y_{T-n+1})$ as input.\nThat is in contrast to the classical methods, where we only supply the number\n    of time steps to be predicted as a scalar integer.\n", "meta": {"hexsha": "5e7c2bc17ce0fb04aa54227ec549c38fd82aa2ed", "size": 2340, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2_lit/3_ml/2_learning.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/2_learning.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/2_learning.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": 43.3333333333, "max_line_length": 77, "alphanum_fraction": 0.6653846154, "num_tokens": 686, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.963779946215714, "lm_q2_score": 0.8056321983146848, "lm_q1q2_score": 0.7764521567613744}}
{"text": "\n\\subsection{Covariant and contravariant bases}\n\nIn element form we write a vector as:\n\n\\(v=e_iv^i\\)\n\nThe indices are raised and lowered to reflect whether the value is covariant or contravariant.\n\n\\(v^i\\) is contravariant. If the basis moves one way, it moves the other.\n\n\\(e_i\\) is covariant. If the basis moves, it moves with it.\n\n", "meta": {"hexsha": "3988bc2674b90184a680f06814d92c601fa3039e", "size": 334, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/tensors/01-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/tensors/01-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/tensors/01-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": 23.8571428571, "max_line_length": 94, "alphanum_fraction": 0.745508982, "num_tokens": 89, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9496693659780477, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7764254365572498}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Choose Your Method}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises choosing a method for computing volume.\n\\end{abstract}\n\\maketitle\n\n\\begin{exercise}%%%%%[2016.29]\nThe region in the plane bounded by $y = e^{-x/2}$ and the $x$-axis for $0 \\leq x \\leq \\ln 2$ is rotated about the $x$-axis. The volume of the resulting solid of revolution is\n\\[ V = \\answer{ \\frac{\\pi}{2}}. \\]\n(Hints won't be revealed until after you choose a response.)\n\\begin{feedback}\nIf $x$ is used as the slicing variable, then slices are vertical and consequently perpendicular to the axis of rotation. \\begin{hint}\nFurthermore one side of the region lies along the axis, so the disk method is appropriate in this case. \n\\begin{hint}\nThe distance from the axis to the upper edge of the region is $e^{-x/2}$, so\n\\[ \\begin{aligned} V & = \\int_0^{\\ln 2} \\pi \\left( e^{-x/2} \\right)^2 dx = \\pi \\int_0^{\\ln 2} e^{-x} dx \\\\ & =  \\left. - \\pi e^{-x} \\right|_{x=0}^{\\ln 2} = \\pi (-e^{-\\ln 2} + e^0) = \\pi \\left( - \\frac{1}{2} + 1 \\right) = \\frac{\\pi}{2}. \\end{aligned}\\]\n\\end{hint}\n\\end{hint}\n\\end{feedback}\n\\end{exercise}\n\n\\begin{exercise}\n The region in the plane bounded on the right by the curve $x = 2 - y^2$, on the left by the curve $x = y^2$, and on the bottom by $y = 0$ is revolved around the $y$-axis. Compute the volume of the resulting solid.\n \\[ V = \\answer{\\frac{8 \\pi}{3}}. \\]\n \\end{exercise}\n \n \n \\begin{exercise}%%%%%Based on [2018.S.1]; mirrored axes\nCompute the volume of the solid of revolution obtained by rotating the region between $x=0$, $y=0$, and $x=\\sqrt{2+3y^2 - 5y^4}$ around the $y$-axis.\n\\[ V = \\answer{2 \\pi}. \\]\n\\end{exercise}\n\n\n\\begin{exercise}%%%%%[2015C.14]\n\nThe region between the graph of \\(y = 1-x^2\\) and the \\(x\\)-axis is rotated around the line \\(y=1\\). What is the volume of the resulting solid?\n\\[ V= \\answer{ \\frac{8 \\pi}{5}}. \\]\n%\\begin{multiplechoice}\n%\\choice{\\(\\displaystyle \\frac{2 \\pi}{5}\\)}\n%\\choice{\\(\\displaystyle \\frac{4 \\pi}{5}\\)}\n%\\choice{\\(\\displaystyle \\frac{6 \\pi}{5}\\)}\n%\\choice[correct]{\\(\\displaystyle \\frac{8 \\pi}{5}\\)}\n%\\choice{\\(2 \\pi\\)}\n%\\choice{\\(\\displaystyle \\frac{12 \\pi}{5}\\)}\n%\\end{multiplechoice}\n\\end{exercise}\n\n\\begin{exercise}% Inspired by Fall 2011 final exam question 3.\nFind the volume obtained by rotating the region between the graph $x = \\frac{1}{2} \\sin (y^2)$ and the $y$-axis for $0 \\leq y \\leq \\sqrt{\\pi}$ about the $x$-axis.\n\\[ V = \\answer{\\pi}. \\]\n\\end{exercise}\n\n\n\\section*{Sample Exam Questions}\n\n\n\n\\begin{question}%%%%%[2015C.15]\n\nCalculate the volume of the solid obtained by rotating the area between the graphs of \\(\\displaystyle y = \\frac{1}{\\sqrt{x^2-1}}\\) and the \\(x\\)-axis for \\(1 < x < \\sqrt{5}\\) around the \\(y\\)-axis.\n\\begin{multiplechoice}\n\\choice{\\(\\pi\\)}\n\\choice[correct]{\\(4 \\pi\\)}\n\\choice{\\(6 \\pi\\)}\n\\choice{\\(8 \\pi\\)}\n\\choice{\\(3 \\pi\\)}\n\\choice{\\(2 \\pi\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2016C.14]\n\nLet \\(f(x)\\) be a continuous function that satisfies \\(f(0) = 0\\) and \\(f(x) > 0\\) for \\(x > 0\\). For every \\(b > 0\\), when the region between the graph of \\(y = f(x)\\), the \\(x\\)-axis, and the line \\(x=b\\) is rotated around the \\(x\\)-axis, the volume of the resulting solid is \\(18 \\pi b^2\\). What is \\(f(x)\\)?\n(Hints will not be revealed until after you choose a response.)\n\\begin{multiplechoice}\n\\choice{\\(\\displaystyle 9x\\)}\n\\choice{\\(\\displaystyle 3x^2\\)}\n\\choice[correct]{\\(\\displaystyle 6 \\sqrt{x}\\)}\n\\choice{\\(\\displaystyle 27 x^{3/2}\\)}\n\\choice{\\(\\displaystyle 9 x^2\\)}\n\\choice{\\(\\displaystyle \\sqrt{3x}\\)}\n\\end{multiplechoice}\n\\begin{feedback}\nBy the disk method, we have that\n\\[ \\int_0^b \\pi (f(x))^2 dx = 18 \\pi b^2 \\]\nfor each $b > 0$. Solve this equation for $b$.\n\\begin{hint}\nDifferentiate both sides with respect to $b$; use the Fundamental Theorem of Calculus to differentiate the left-hand side.\n\\end{hint}\n\\end{feedback}\n\\end{question}\n\n\\begin{question}%%%%%[2017C.02]\n\nFind the volume of the solid generated by revolving the region bounded above by \\(y = \\sec x\\) and bounded below by \\(y=0\\) for \\(0 \\leq x \\leq \\pi/3\\) about the \\(x\\)-axis.\n\\begin{multiplechoice}\n\\choice{\\(\\pi\\)}\n\\choice{\\(2 \\pi\\)}\n\\choice[correct]{\\(\\pi \\sqrt{3}\\)}\n\\choice{\\(3 \\pi\\)}\n\\choice{\\(4 \\pi\\)}\n\\choice{none of these}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\n\n\\end{document}\n", "meta": {"hexsha": "9241c212ee71942e74fbd99a7b6c8018903ad697", "size": 4366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "volumes/04choosepractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "volumes/04choosepractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "volumes/04choosepractice.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": 37.3162393162, "max_line_length": 311, "alphanum_fraction": 0.6525423729, "num_tokens": 1481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110425624792, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7764082635797467}}
{"text": "% !Tex program = pdflatex\n% Chapter 2 - Introduction to quantum mechanics\n\\ifx\\allfiles\\undefined\n\\documentclass[en]{sol-man}\n\\begin{document}\n\\fi\n\\chapter{Introduction to quantum mechanics}\n\n\\section{Linear algebra}\n\n\\begin{exe}[Linear dependence: example]\n    Show that $(1,-1)$, $(1,2)$ and $(2,1)$ are Linearly dependent.\n\\end{exe}\n\\begin{pf}\n    Since\n    \\begin{align}\n        (1,-1)+(1,2)-(2,1)=0,\n    \\end{align}\n    these three vectors are linearly dependent.\n\\end{pf}\n\n\\begin{exe}[Matrix representations: example]\n    Suppose $V$ is a vector space with basis vectors $\\lvert 0\\rangle$ and $\\lvert 1\\rangle$, and $A$ is a linear operator from $V$ to $V$ such that $A\\lvert 0\\rangle=\\lvert 1\\rangle$ and $A\\lvert 1\\rangle=\\lvert 0\\rangle$. Give a matrix representation for $A$, with respect to the input basis $\\lvert 0\\rangle$, $\\lvert 1\\rangle$, and the output basis $\\lvert 0\\rangle$ and $\\lvert 1\\rangle$. Find input and output bases which give rise to a different matrix representation of $A$.\n\\end{exe}\n\\begin{sol}\n    The matrix representation for $A$ with respect to the input basis $\\lvert 0\\rangle$, $\\lvert 1\\rangle$ and the output basis $\\lvert 0\\rangle$ and $\\lvert 1\\rangle$ is\n    \\begin{align}\n        \\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}.\n    \\end{align}\n\n    Keep $\\lvert 0\\rangle$ and $\\lvert 1\\rangle$ as the input basis and choose $\\lvert+\\rangle=(\\lvert 0\\rangle+\\lvert 1\\rangle)/\\sqrt{2}$ and $\\lvert-\\rangle=(\\lvert 0\\rangle-\\lvert 1\\rangle)/\\sqrt{2}$ as the output basis, then $A$ can be regarded as a linear operator from $V$ to $V$ such that $A\\lvert 0\\rangle=(\\lvert+\\rangle-\\lvert-\\rangle)/\\sqrt{2}$ and $A\\lvert 1\\rangle=(\\lvert 0\\rangle+\\lvert 1\\rangle)/\\sqrt{2}$. In this way, the matrix representation for $A$ is\n    \\begin{align}\n        \\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&-1\\\\\n            1&1\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}[Matrix representation for operator products]\n    Suppose $A$ is a linear operator from vector space $V$ to vector space $W$, and $B$ is a linear operator from vector spaces $W$ to vector space $X$. Let $\\lvert v_i\\rangle$, $\\lvert w_j\\rangle$, and $\\lvert x_k\\rangle$ be bases for the vector spaces $V$, $W$, and $X$, respectively. Show that the matrix representation for the linear transformation $BA$ is the matrix product of the matrix representations for $B$ and $A$, with respect to the appropriate bases.\n\\end{exe}\n\\begin{pf}\n    Suppose the dimension of vector spaces $V$, $W$, and $W$ are $l$, $m$, $n$, respectively. Since $A$ is a linear operator from vector space $V$ to vector space $W$, for each $i$ in the range $1,\\cdots,l$, there exist complex numbers $A_{1i}$ through $A_{mi}$ such that\n    \\begin{align}\n        A\\lvert v_i\\rangle=\\sum_jA_{ji}\\lvert w_j\\rangle,\n    \\end{align}\n    where $A_{ji}$ is the entries of the matrix representation of the operator $A$.\n    Since $B$ is a linear operator from vector space $W$ to vector space $X$, for each $j$ in the range $1,\\cdots,m$, there exist complex numbers $A_{1j}$ through $A_{nj}$ such that\n    \\begin{align}\n        B\\lvert w_j\\rangle=\\sum_kB_{kj}\\lvert x_k\\rangle,\n    \\end{align}\n    where $B_{kj}$ is the entries of the matrix representation of the operator $B$.\n    Putting the above two equations together, we have\n    \\begin{align}\n        BA\\lvert v_i\\rangle=B\\sum_jA_{ji}\\lvert w_j\\rangle=\\sum_jA_{ji}\\sum_kB_{kj}\\lvert x_k\\rangle=\\sum_k\\left(\\sum_jB_{kj}A_{ji}\\right)\\lvert x_k\\rangle=\\sum_k(BA)_{ki}\\lvert x_k\\rangle.\n    \\end{align}\n    where $(AB)_{ki}$ is the entries of the matrix representation of the operator $BA$. Therefore, the matrix representation for the linear transformation $BA$ is the matrix product of the matrix representations for $B$ and $A$, with respect to the appropriate bases.\n\\end{pf}\n\n\\begin{exe}[Matrix representation for identity]\n    Show that the identity operator on a vector space $V$ has a matrix representation which is one along the diagonal and zero everywhere else, if the matrix representation is taken with respect to the same input and output bases. The matrix is known as the \\emph{identity matrix}.\n\\end{exe}\n\\begin{pf}\n    Suppose $I$ is the identity operator on the vector space $V$ and choose $\\lvert v_1\\rangle,\\cdots,\\lvert v_m\\rangle$ as both the input basis and the output basis for $V$. Then for each $j$ in the range $1,\\cdots,m$, there exist complex numbers $I_{1j}$ through $I_{mj}$ such that\n    \\begin{gather}\n        I\\lvert v_j\\rangle=\\sum_iA_{ij}\\lvert v_i\\rangle=\\lvert v_j\\rangle,\\\\\n        \\Longrightarrow(A_{jj}-1)\\lvert v_j\\rangle+\\sum_{i\\neq j}A_{ij}\\lvert v_i\\rangle=0,\n    \\end{gather}\n    where $A_{ij}$ is the entries of the matrix representation of the operator $I$. Due to linear independence of the basis, there must be\n    \\begin{align}\n        v_{ij}=\\left\\{\\begin{array}{ll}\n            1,&i=j;\\\\\n            0,&i\\neq j,\n        \\end{array}\\right.=\\delta_{ij},\\quad\\forall i,j=1,\\cdots,m.\n    \\end{align}\n    i.e., the identity operator on the vector space $V$ has a matrix representation which is one along the diagonal and zero everywhere else.\n\\end{pf}\n\n\\begin{exe}\n    Verify that $(\\cdot,\\cdot)$ just defined is an inner product on $\\mathbb{C}^n$.\n\\end{exe}\n\\begin{pf}\n    $(\\cdot,\\cdot)$ just defined satisfies the requirements that:\n    \\begin{itemize}\n        \\item[(1)] $(\\cdot,\\cdot)$ is linear in the second argument,\n        \\begin{align}\n            \\notag\\left((y_1,\\cdots,y_n),\\sum_j\\lambda_j(z_1^{(j)},\\cdots,z_n^{(j)})\\right)=&\\left((y_1,\\cdots,y_n),(\\sum_j\\lambda_jz_1^{(j)},\\cdots,\\sum_j\\lambda_jz_n^{(j)})\\right)=\\sum_iy_i^*\\sum_j\\lambda_jz_i^{(j)}\\\\\n            =&\\sum_j\\lambda_j\\sum_iy_i^*z_i^{(j)}=\\sum_j\\lambda_j((y_1,\\cdots,y_n),(z_1^{(j)},\\cdots,z_n^{(j)})).\n        \\end{align}\n        \\item[(2)] \n        \\begin{align}\n            ((y_1,\\cdots,y_n),(z_1,\\cdots,z_n))=\\sum_iy_i^*z_i=\\left(\\sum_iz_i^*y_i\\right)^*=((z_1,\\cdots,z_n),(y_1,\\cdots,y_n))^*.\n        \\end{align}\n        \\item[(3)] \n        \\begin{align}\n            ((y_1,\\cdots,y_n),(y_1,\\cdots,y_n))=\\sum_iy_i^*y_i=\\sum_i\\abs{y_i}^2\\geq 0,\n        \\end{align}\n        with equality if and only if $(y_1,\\cdots,y_n)=0$.\n    \\end{itemize}\n    Therefore, $(\\cdot,\\cdot)$ is an inner product on $\\mathbb{C}^n$.\n\\end{pf}\n\n\\begin{exe}\n    Show that any inner product $(\\cdot,\\cdot)$ is conjugate-linear in the first argument,\n    \\begin{align}\n        \\left(\\sum_i\\lambda_i\\lvert w_i\\rangle,\\lvert v\\rangle\\right)=\\sum_i\\lambda_i^*(\\lvert w_i\\rangle,\\lvert v\\rangle).\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\left(\\sum_i\\lambda_i\\lvert w_i\\rangle,\\lvert v\\rangle\\right)=\\left(\\lvert v\\rangle,\\sum_i\\lambda_i\\lvert w_i\\rangle\\right)^*=\\left(\\sum_i\\lambda_i(\\lvert v\\rangle,\\lvert w_i\\rangle)\\right)^*=\\sum_i\\lambda_i^*(\\lvert w_i\\rangle,\\lvert v\\rangle).\n    \\end{align}\n    Therefore, any inner product $(\\cdot,\\cdot)$ is conjugate-linear in the first argument.\n\\end{pf}\n\n\\begin{exe}\n    Verify that $\\lvert w\\rangle\\equiv(1,1)$ and $\\lvert v\\rangle\\equiv(1,-1)$ are orthogonal. What are the normalized forms of these vectors?\n\\end{exe}\n\\begin{sol}\n    Since\n    \\begin{align}\n        (\\lvert w\\rangle,\\lvert v\\rangle)=1\\times 1+1\\times(-1)=0,\n    \\end{align}\n    these two vectors are orthogonal. The normalized form of $\\lvert w\\rangle$ and $\\lvert v\\rangle$ are\n    \\begin{align}\n        \\frac{\\lvert w\\rangle}{\\norm{\\lvert w\\rangle}}=\\frac{1}{\\sqrt{2}}(1,1),\n    \\end{align}\n    and\n    \\begin{align}\n        \\frac{\\lvert v\\rangle}{\\norm{\\lvert v\\rangle}}=\\frac{1}{\\sqrt{2}}(1,-1),\n    \\end{align}\n    respectively.\n\\end{sol}\n\n\\begin{exe}\n    Prove that the Gram-Schmidt procedure produces an orthonormal basis for $V$.\n\\end{exe}\n\\begin{pf}\n    Obviously, $\\lvert v_1\\rangle,\\cdots,\\lvert v_n\\rangle$ are normalized, so we first prove that $\\lvert v_1\\rangle,\\cdots,\\lvert v_d\\rangle$ are orthogonal with induction.\n    For $k=1$,\n    \\begin{align}\n        (\\lvert v_1\\rangle,\\lvert v_{k+1}\\rangle)=&(\\lvert v_1,\\lvert v_2\\rangle\\rangle)=\\left(\\lvert v_1\\rangle,\\frac{\\lvert w_2\\rangle-\\langle v_1\\vert w_2\\rangle\\lvert v_1\\rangle}{\\norm{\\lvert v_1\\rangle-\\langle v_1\\vert w_2\\rangle\\lvert v_1\\rangle}}\\right)=\\frac{\\langle v_1\\vert w_2\\rangle-\\langle v_1\\vert w_2\\rangle\\langle v_1\\vert v_1\\rangle}{\\norm{\\lvert v_1\\rangle-\\langle v_1\\vert w_2\\rangle\\lvert v_1\\rangle}}=\\frac{\\langle v_1\\vert w_2\\rangle-\\langle v_1\\vert w_2\\rangle}{\\norm{\\lvert v_1\\rangle-\\langle v_1\\vert w_2\\rangle\\lvert v_1\\rangle}}=0,\\\\\n    \\end{align}\n    so $\\lvert v_1\\rangle,\\cdots,\\lvert v_{k+1}\\rangle$ are orthogonal for $k=1$.\n    For $k\\geq 2$, if $\\lvert v_1\\rangle,\\cdots,\\lvert v_k\\rangle$ are orthogonal, then\n    \\begin{align}\n        \\notag(\\lvert v_j\\rangle,\\lvert v_{k+1}\\rangle)=&\\left(\\lvert v_j\\rangle,\\frac{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}{\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}}\\right)=\\frac{\\langle v_j\\vert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\langle v_j\\vert v_i\\rangle}{\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}}\\\\\n        =&\\frac{\\langle v_j\\vert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\delta_{ji}}{\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}}=\\frac{\\langle v_j\\vert w_{k+1}\\rangle-\\langle v_j\\vert w_{k+1}\\rangle}{\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}}=0,\\quad\\forall j=1,\\cdots,k,\n    \\end{align}\n    so $\\lvert v_1\\rangle,\\cdots,\\lvert v_{k+1}\\rangle$ are orthogonal for $k\\geq 2$, such as $k=d-1$.\n    Till now, we proved that $\\lvert v_1\\rangle,\\cdots,\\lvert v_d\\rangle$ are orthonormal.\n\n    We then prove that $\\lvert v_1\\rangle,\\cdots,\\lvert v_n\\rangle$ are a basis for $V$.\n    As proved above, $\\lvert v_1\\rangle,\\cdots,\\lvert v_d\\rangle$ are orthonormal, and thus linear independent. Since $\\lvert w_1\\rangle,\\cdots,\\lvert w_d\\rangle$ are a basis for $V$. Any vector $\\lvert v\\rangle$ in $V$ can be written as a linear combination of $\\lvert w_1\\rangle,\\cdots,\\lvert w_d\\rangle$:\n    \\begin{align}\n        \\lvert v\\rangle=\\sum_{i=1}^da_i\\lvert w_i\\rangle.\n    \\end{align}\n    Using\n    \\begin{align}\n        \\lvert v_1\\rangle=\\frac{\\lvert w_1\\rangle}{\\norm{\\lvert w_1\\rangle}}\\Longrightarrow \\lvert w_1\\rangle=\\norm{\\lvert w_1\\rangle}\\lvert v_1\\rangle,\\\\\n    \\end{align}\n    and\n    \\begin{align}\n        \\notag\\lvert v_{k+1}\\rangle=&\\frac{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}{\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}}\\\\\n        \\Longrightarrow&\\lvert w_{k+1}\\rangle=\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}\\lvert v_{k+1}\\rangle+\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle,\\quad\\forall k=1,\\cdots,d-1\n    \\end{align}\n    we can rewrite $\\lvert v\\rangle$ as a linear combination of $\\lvert v_1\\rangle,\\cdots,\\lvert v_d\\rangle$:\n    \\begin{align}\n        \\lvert v\\rangle=a_1\\norm{\\lvert w_1\\rangle}\\lvert v_1\\rangle+\\sum_{k=1}^{d-1}a_{k+1}\\left(\\norm{\\lvert w_{k+1}\\rangle-\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle}\\lvert v_{k+1}\\rangle+\\sum_{i=1}^k\\langle v_i\\vert w_{k+1}\\rangle\\lvert v_i\\rangle\\right),\n    \\end{align}\n    so $\\lvert v_1\\rangle,\\cdots,\\lvert v_d\\rangle$ span and form a basis for $V$.\n\n    Therefore, the Gram-Schmidt procedure produces an orthonormal basis for $V$.\n\\end{pf}\n\n\\begin{exe}[Pauli operators and the outer product]\n    The Pauli matrices (Figure 2.2 on page 65) can be considered as operators with respect to an orthonormal basis $\\lvert 0\\rangle$, $\\lvert 1\\rangle$ for a two-dimensional Hilbert space. Express each of the Pauli operators in the outer product notion.\n\\end{exe}\n\\begin{sol}\n    The Pauli operators in the outer product notion:\n    \\begin{align}\n        \\sigma_0=&\\sum_{m,n=1}^2\\langle m\\rvert\\sigma_0\\lvert n\\rangle\\lvert m\\rangle\\langle n\\rvert=\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert,\\\\\n        \\sigma_1=&\\sum_{m,n=1}^2\\langle m\\rvert\\sigma_1\\lvert n\\rangle\\lvert m\\rangle\\langle n\\rvert=\\lvert 0\\rangle\\langle 1\\rvert+\\lvert 1\\rangle\\langle 0\\rvert,\\\\\n        \\sigma_2=&\\sum_{m,n=1}^2\\langle m\\rvert\\sigma_2\\lvert n\\rangle\\lvert m\\rangle\\langle n\\rvert=-i\\lvert 0\\rangle\\langle 1\\rvert+i\\lvert 1\\rangle\\langle 0\\rvert,\\\\\n        \\sigma_3=&\\sum_{m,n=1}^2\\langle m\\rvert\\sigma_3\\lvert n\\rangle\\lvert m\\rangle\\langle n\\rvert=\\lvert 0\\rangle\\langle 0\\rvert-\\lvert 1\\rangle\\langle 1\\rvert.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Suppose $\\lvert v_i\\rangle$ is an orthonormal basis for and inner product space $V$. What is the matrix representation for the operator $\\lvert v_j\\rangle\\langle v_k\\rvert$, with respect to the $\\lvert v_i\\rangle$ basis?\n\\end{exe}\n\\begin{sol}\n    The matrix representation for the operator $\\lvert v_j\\rangle\\langle v_k\\rvert$ with respect to the $\\lvert v_i\\rangle$ basis:\n    \\begin{align}\n        \\lvert v_j\\rangle\\langle v_k\\rvert=\\begin{array}{cc}\n            \\begin{array}{ccccccc}\n                \\multicolumn{7}{c}{k\\text{th column}} \\\\\n                 &  &  & \\downarrow &  &  & \n                \\end{array} & \\begin{array}{c}\n                    \\\\\n                    \\\\\n                   \\end{array} \\\\\n            \\left[\\begin{array}{ccccccc}\n                0 &  &  &  & \\multicolumn{3}{c}{\\multirow{3}{*}{\\Huge0}} \\\\\n                 & \\ddots &  &  & \\multicolumn{3}{c}{} \\\\\n                 &  & 0 &  & \\multicolumn{3}{c}{} \\\\\n                 &  &  & 1 &  &  &  \\\\\n                \\multicolumn{3}{c}{\\multirow{3}{*}{\\Huge0}} &  & 0 &  &  \\\\\n                \\multicolumn{3}{c}{} &  &  & \\ddots &  \\\\\n                \\multicolumn{3}{c}{} &  &  &  & 0\n                \\end{array}\\right] & \\begin{array}{c}\n                    \\\\\n                    \\\\\n                    \\\\\n                   \\leftarrow\\,j\\text{th row} \\\\\n                    \\\\\n                    \\\\\n                    \\\\\n                   \\end{array}\n        \\end{array}\n    \\end{align}\n    (a matrix with all zeros expect a one at the $j$th row and $k$th column).\n\\end{sol}\n\n\\begin{exe}[Eigendecomposition of the Pauli matrices]\n    Find the eigenvectors, eigenvalues, and diagonal representations of the Pauli matrices $X$, $Y$, and $Z$.\n\\end{exe}\n\\begin{sol}\n    The characteristic equation of $X$\n    \\begin{align}\n        \\det\\abs{X-\\lambda I}=\\abs{\\begin{matrix}\n            -\\lambda&1\\\\\n            1&-\\lambda\n        \\end{matrix}}=\\lambda^2-1=0,\n    \\end{align}\n    gives the eigenvalues\n    \\begin{align}\n        \\lambda_1=1,\\quad\\lambda_2=-1.\n    \\end{align}\n    The eigenequations of $X$\n    \\begin{align}\n        X\\lvert v_1\\rangle=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            b_1\\\\\n            a_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\quad X\\lvert v_2\\rangle=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\begin{bmatrix}\n            b_2\\\\\n            a_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\begin{bmatrix}\n            -a_2\\\\\n            -b_2\n        \\end{bmatrix},\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle),\\quad\\lvert v_2\\rangle=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            -1\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle-\\lvert 1\\rangle).\n    \\end{align}\n    The diagonal representation of $X$ is\n    \\begin{align}\n        X=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)\\frac{1}{\\sqrt{2}}(\\langle 0\\rvert+\\langle 1\\rvert)-\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle-\\lvert 1\\rangle)\\frac{1}{\\sqrt{2}}(\\langle 0\\rvert-\\langle 1\\rvert).\n    \\end{align}\n    The characteristic equation of $Y$\n    \\begin{align}\n        \\det\\abs{Y-\\lambda I}=\\abs{\\begin{matrix}\n            -\\lambda&-i\\\\\n            i&-\\lambda\n        \\end{matrix}}=\\lambda^2-1=0,\n    \\end{align}\n    gives the eigenvalues\n    \\begin{align}\n        \\lambda_1=1,\\quad\\lambda_2=-1.\n    \\end{align}\n    The eigenequations of $Y$\n    \\begin{align}\n        Y\\lvert v_1\\rangle=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            -ib_1\\\\\n            ia_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\quad Y\\lvert v_2\\rangle=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\begin{bmatrix}\n            -ib_2\\\\\n            ia_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\begin{bmatrix}\n            -a_2\\\\\n            -b_2\n        \\end{bmatrix},\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            i\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+i\\lvert 1\\rangle),\\quad\\lvert v_2\\rangle=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            -i\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle-i\\lvert 1\\rangle).\n    \\end{align}\n    The diagonal representation of $Y$ is\n    \\begin{align}\n        Y=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+i\\lvert 1\\rangle)\\frac{1}{\\sqrt{2}}(\\langle 0\\rvert+i\\langle 1\\rvert)-\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle-i\\lvert 1\\rangle)\\frac{1}{\\sqrt{2}}(\\langle 0\\rvert-i\\langle 1\\rvert).\n    \\end{align}\n    The characteristic equation of $Z$\n    \\begin{align}\n        \\det\\abs{Z-\\lambda I}=\\abs{\\begin{matrix}\n            1-\\lambda&0\\\\\n            0&-1-\\lambda\n        \\end{matrix}}=\\lambda^2-1=0,\n    \\end{align}\n    gives the eigenvalues\n    \\begin{align}\n        \\lambda_1=1,\\quad\\lambda_2=-1.\n    \\end{align}\n    The eigenequations of $Z$\n    \\begin{align}\n        Z\\lvert v_1\\rangle=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            a_1\\\\\n            -b_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\quad Z\\lvert v_2\\rangle=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            -b_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\begin{bmatrix}\n            -a_2\\\\\n            -b_2\n        \\end{bmatrix},\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\begin{bmatrix}\n            1\\\\\n            0\n        \\end{bmatrix}=\\lvert 0\\rangle,\\quad\\lvert v_2\\rangle=\\begin{bmatrix}\n            0\\\\\n            1\n        \\end{bmatrix}.\n    \\end{align}\n    The diagonal representation of $Z$ is\n    \\begin{align}\n        Z=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\lvert 0\\rangle\\langle 0\\rvert-\\lvert 1\\rangle\\langle 1\\rvert.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Prove that the matrix\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\n    \\end{align}\n    is not diagonalizable.\n\\end{exe}\n\\begin{pf}\n    The matrix is not normal,\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}=\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&1\\\\\n            0&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix}\\neq\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&1\\\\\n            0&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix},\n    \\end{align}\n    so it is not diagonalizable.\n\\end{pf}\n\n\\begin{exe}\n    If $\\lvert w\\rangle$ and $\\lvert v\\rangle$ are any two vectors, show that $(\\lvert w\\rangle\\langle v\\rvert)^{\\dagger}=\\lvert v\\rangle\\langle w\\rvert$.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        (\\lvert w\\rangle\\langle v\\rvert)^{\\dagger}=\\langle v\\rvert^{\\dagger}\\lvert w\\rangle^{\\dagger}=\\lvert v\\rangle\\langle w\\rvert.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}[Anti-linearity of the adjoint]\n    Show tha the adjoint operation is anti-linear,\n    \\begin{align}\n        \\left(\\sum_ia_iA_i\\right)^{\\dagger}=\\sum_ia_i^*A_i^{\\dagger}.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    For two arbitrary vectors $\\lvert v\\rangle$ and $\\lvert w\\rangle$,\n    \\begin{align}\n        \\left(\\left(\\sum_ia_iA_i\\right)^{\\dagger}\\lvert v\\rangle,\\lvert w\\rangle\\right)=\\left(\\lvert v\\rangle,\\sum_ia_iA_i\\lvert w\\rangle\\right)=\\sum_ia_i(\\lvert v\\rangle,A_i\\lvert w\\rangle)=\\sum_ia_i(A_i^{\\dagger}\\lvert v\\rangle,\\lvert w\\rangle)=\\left(\\sum_ia_i^*A_i^{\\dagger}\\lvert v\\rangle,\\lvert w\\rangle\\right).\n    \\end{align}\n    Due to the arbitrariness of $\\lvert v\\rangle$ and $\\lvert w\\rangle$,\n    \\begin{align}\n        \\left(\\sum_ia_iA_i\\right)^{\\dagger}=\\sum_ia_i^*A_i^{\\dagger}.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Show that $(A^{\\dagger})^{\\dagger}=A$.\n\\end{exe}\n\\begin{pf}\n    For two arbitrary vectors $\\lvert v\\rangle$ and $\\lvert w\\rangle$,\n    \\begin{align}\n        ((A^{\\dagger})^{\\dagger}\\lvert v\\rangle,\\lvert w\\rangle)=(\\lvert v\\rangle,A^{\\dagger}\\lvert w\\rangle)=(A^{\\dagger}\\lvert w\\rangle,\\lvert v\\rangle)^*=(\\lvert w\\rangle,A\\lvert v\\rangle)^*=[(A\\lvert v\\rangle,\\lvert w\\rangle)^*]^*=(A\\lvert v\\rangle,\\lvert w\\rangle).\n    \\end{align}\n    Due to the arbitrariness of $\\lvert v\\rangle$ and $\\lvert w\\rangle$,\n    \\begin{align}\n        (A^{\\dagger})^{\\dagger}=A.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Show that any projector $P$ satisfies the equation $P^2=P$.\n\\end{exe}\n\\begin{pf}\n    For any orthonormal basis $\\lvert 1\\rangle,\\cdots,\\lvert k\\rangle$ for $W$,\n    \\begin{align}\n        P=\\sum_{i=1}^k\\lvert i\\rangle\\langle i\\rvert,\n    \\end{align}\n    and then\n    \\begin{align}\n        P^2=\\sum_{i=1}^k\\lvert i\\rangle\\langle i\\rvert\\sum_{j=1}^k\\lvert j\\rangle\\langle j\\rvert=\\sum_{i=1}^k\\sum_{j=1}^k\\lvert i\\rangle\\langle i\\vert j\\rangle\\langle j\\rvert=\\sum_{i=1}^k\\sum_{j=1}^k\\lvert i\\rangle\\delta_{ij}\\langle j\\rvert=\\sum_{i=1}^k\\lvert i\\rangle\\langle i\\rvert=P.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Show that a normal matrix is Hermitian if and only if it has real eigenvalues.\n\\end{exe}\n\\begin{pf}\n    \\emph{Sufficiency}: If normal matrix $A$ has real eigenvalues $\\lambda_1,\\cdots,\\lambda_n$ with corresponding eigenvectors $\\lvert 1\\rangle,\\cdots,\\lvert n\\rangle$. It can be written as\n    \\begin{align}\n        A=\\sum_{i=1}^n\\lambda_i\\lvert i\\rangle\\langle i\\rvert.\n    \\end{align}\n    Since $\\lambda_1,\\cdots,\\lambda_n$ are real,\n    \\begin{align}\n        A^{\\dagger}=\\sum_{i=1}^n\\lambda_i^{\\dagger}\\lvert i\\rangle\\langle i\\rvert=\\sum_{i=1}^n\\lambda_i\\lvert i\\rangle\\langle i\\rvert=A.\n    \\end{align}\n    Therefore, $A$ is Hermitian.\n\n    \\emph{Necessity}: Suppose normal and Hermitian matrix $A$ has eigenvalues $\\lambda_1,\\cdots,\\lambda_n$ with corresponding eigenvectors $\\lvert 1\\rangle,\\cdots,\\lvert n\\rangle$. For any $i=1,\\cdots,n$,\n    \\begin{align}\n        \\notag\\lambda_i=\\lambda_i(\\lvert i\\rangle,\\lvert i\\rangle)=(\\lvert i\\rangle,\\lambda_i\\lvert i\\rangle)=&(\\lvert i\\rangle,A\\lvert i\\rangle)\\\\\n        =&(A^{\\dagger}\\lvert i\\rangle,\\lvert i\\rangle)=(\\lvert i\\rangle,A^{\\dagger}\\lvert i\\rangle)^*=((A^{\\dagger})^{\\dagger}\\lvert i\\rangle,\\lvert i\\rangle)=(A\\lvert i\\rangle,\\lvert i\\rangle)=(\\lambda_i\\lvert i\\rangle,\\lvert i\\rangle)=\\lambda_i^*(\\lvert i\\rangle,\\lvert i\\rangle)=\\lambda_i^*.\n    \\end{align}\n    Therefore, all the eigenvalues $\\lambda_1,\\cdots,\\lambda_n$ are real.\n\\end{pf}\n\n\\begin{exe}\n    Show that all eigenvalues of a unitary matrix has modulus $1$, that is can be written in the form $e^{i\\theta}$ for some real $\\theta$.\n\\end{exe}\n\\begin{pf}\n    Suppose unitary matrix $A$ has eigenvalues $\\lambda_1,\\cdots,\\lambda_n$ with corresponding eigenvectors $\\lvert 1\\rangle,\\cdots,\\lvert n\\rangle$. The eigenequations of $A$ are\n    \\begin{align}\n        A\\lvert i\\rangle=\\lambda_i\\lvert i\\rangle,\\quad\\forall i=1,\\cdots,n.\n    \\end{align}\n    Taking Hermitian conjugate of the above equations,\n    \\begin{align}\n        \\langle i\\rvert A^{\\dagger}=(A\\lvert i\\rangle)^{\\dagger}=\\lambda_i^*\\langle i\\rvert,\\quad\\forall i=1,\\cdots,n.\n    \\end{align}\n    Since $A$ is unitary, for any $i=1,\\cdots,n$,\n    \\begin{gather}\n        1=\\langle i\\vert i\\rangle=\\langle i\\rvert I\\lvert i\\rangle=\\langle i\\rvert A^{\\dagger}A\\lvert i\\rangle=\\abs{\\lambda_i}^2\\langle i\\vert i\\rangle=\\abs{\\lambda_i}^2,\\\\\n        \\Longrightarrow\\abs{\\lambda_i}=1.\n    \\end{gather}\n    Therefore, all eigenvalues of a unitary matrix has modulus $1$.\n\\end{pf}\n\n\\begin{exe}[Pauli matrices: Hermitian and unitary]\n    Show that the Pauli matrices are Hermitian and unitary.\n\\end{exe}\n\\begin{pf}\n    Since\n    \\begin{align}\n        \\sigma_0^{\\dagger}=I^{\\dagger}=I=\\sigma_0,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sigma_0^{\\dagger}\\sigma_0=I^{\\dagger}I=II=I,\n    \\end{align}\n    $\\sigma_0$ is Hermitian and unitary.\n    Since\n    \\begin{align}\n        \\sigma_1^{\\dagger}=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\sigma_1,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sigma_1^{\\dagger}\\sigma_1=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\n    \\end{align}\n    $\\sigma_1$ is Hermitian and unitary.\n    Since\n    \\begin{align}\n        \\sigma_2^{\\dagger}=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\sigma_2,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sigma_2^{\\dagger}\\sigma_2=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\n    \\end{align}\n    $\\sigma_2$ is Hermitian and unitary.\n    Since\n    \\begin{align}\n        \\sigma_3^{\\dagger}=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\sigma_3,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sigma_3^{\\dagger}\\sigma_3=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\n    \\end{align}\n    $\\sigma_3$ is Hermitian and unitary.\n\\end{pf}\n\n\\begin{exe}[Basis changes]\n    Suppose $A'$ and $A''$ are matrix representations of an operator $A$ on a vector space $V$ with respect to two different orthonormal bases, $\\lvert v_i\\rangle$ and $\\lvert w_i\\rangle$. Then the elements of $A'$ and $A''$ are $A_{ij}'=\\langle v_i\\rvert A\\lvert v_j\\rangle$ and $A_{ij}''=\\langle w_i\\rvert A\\lvert w_j\\rangle$. characterize the relationship between $A'$ and $A''$.\n\\end{exe}\n\\begin{sol}\n    Define $U=\\sum_i\\lvert w_i\\rangle\\langle v_i\\rvert$ so that $\\lvert w_i\\rangle=U\\lvert v_i\\rangle$ and $\\langle w_i\\rvert=\\langle v_i\\rvert U^{\\dagger}$ $\\forall i$. Since $\\lvert v_i\\rangle$ and $\\lvert w_i\\rangle$ are two bases for $V$ and\n    \\begin{align}\n        A_{ij}''=\\langle w_i\\rvert A''\\lvert w_j\\rangle=\\langle v_i\\rvert U^{\\dagger}A'U\\lvert v_j\\rangle,\n    \\end{align}\n    the relationship between $A'$ and $A''$ is\n    \\begin{align}\n        A''=U^{\\dagger}A'U.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Repeat the proof of the spectral decomposition in Box 2.2 for the case when $M$ is Hermitian, simplifying the proof wherever possible.\n\\end{exe}\n\\begin{pf}\n    \\emph{Forward}: Suppose vector space $V$ is $d$-dimensional.\n    The case $d=1$ is trivial.\n    For the case $d\\geq 2$, let $\\lambda$ be an eigenvalue of $M$, $P$ the projector onto the $\\lambda$ eigenspace, and $Q$ the projector onto the orthogonal component. The $M=IMI=(P+Q)M(P+Q)=PMP+PMQ+QMP+QMQ=PMP+QMQ$, where $PMP=\\lambda P$, i.e., $PMP$ is diagonal, and $QMQQM^{\\dagger}Q=QM^{\\dagger}QQMQ$, i.e., $QMQ$ is normal. By induction, $QMQ$ is diagonal with respect to some orthonormal basis for the subspace $Q$. It follows that $M=PMP+QMQ$ is diagonal with respect to some orthonormal basis for the total vector space.\n\n    \\emph{Converse}: holds only if all the eigenvalues of $M$ are real. Suppose $M$ is diagonalizable with respect to an orthonormal basis $\\lvert i\\rangle$ for $V$, i.e.,\n    \\begin{align}\n        M=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert,\n    \\end{align}\n    where $\\lambda_i$ are the eigenvalues of $M$.\n    Since $M$ is Hermitian, all $\\lambda_i$ are real,\n    \\begin{align}\n        M^{\\dagger}=\\left(\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert\\right)^{\\dagger}=\\sum_i\\lambda_i^*\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert,\n    \\end{align}\n    so $M$ is Hermitian.\n\\end{pf}\n\n\\begin{exe}\n    Prove that two eigenvectors of a Hermitian operators with different eigenvalues are necessarily orthogonal.\n\\end{exe}\n\\begin{pf}\n    Suppose Hermitian operator $A$ has two eigenvectors $\\lvert v_1\\rangle$ and $\\lvert v_2\\rangle$ corresponding to two different eigenvalues $\\lambda_1$ and $\\lambda_2$, i.e.,\n    \\begin{align}\n        A\\lvert v_1\\rangle=\\lambda_1\\lvert v_1\\rangle,\\\\\n        A\\lvert v_2\\rangle=\\lambda_2\\lvert v_2\\rangle.\n    \\end{align}\n    Then,\n    \\begin{align}\n        \\langle v_1\\rvert A\\lvert v_2\\rangle=\\lambda_1\\langle v_1\\vert v_2\\rangle=\\lambda_2\\langle v_1\\vert v_2\\rangle.\n    \\end{align}\n    Since $\\lambda_1\\neq\\lambda_2$, the above equation holds only if\n    \\begin{align}\n        \\langle v_1\\vert v_2\\rangle=0,\n    \\end{align}\n    i.e., $\\lvert v_1\\rangle$ and $\\lvert v_2\\rangle$ are orthogonal.\n\\end{pf}\n\n\\begin{exe}\n    Show that the eigenvalues of a projector $P$ are all either $0$ or $1$.\n\\end{exe}\n\\begin{pf}\n    Suppose $\\lvert 1\\rangle,\\cdots,\\lvert k\\rangle$ is an orthonormal basis for the subspace $P$ and $\\lvert 1\\rangle,\\cdots,\\lvert n\\rangle$ is an orthonormal basis for the total vector space, where $k\\leq n$. It is easy to see that $\\lvert 1\\rangle,\\cdots,\\lvert n\\rangle$ are eigenvectors of projector $P=\\sum_{i=1}^k\\lvert i\\rangle\\langle i\\rvert$:\n    \\begin{align}\n        P\\lvert j\\rangle=\\sum_{i=1}^k\\lvert i\\rangle\\langle i\\vert j\\rangle=\\sum_{i=1}^k\\lvert i\\rangle\\delta_{ij}=\\left\\{\\begin{array}{ll}\n            \\lvert j\\rangle,&\\text{if }j=1,\\cdots,k;\\\\\n            0,&\\text{if }j=k+1,\\cdots,n.\n        \\end{array}\\right.\n    \\end{align}\n    Therefore, the eigenvalues of a projector $P$ are all either $0$ or $1$.\n\\end{pf}\n\n\\begin{exe}[Hermiticity of positive operators]\n    Show that a positive operator is necessarily Hermitian. (\\emph{Hint}: Show that an arbitrary operator $A$ can be written $A=B+iC$ where $B$ and $C$ are Hermitian.)\n\\end{exe}\n\\begin{pf}\n    An arbitrary positive operator $A$ can be written $A=B+iC$ where all the entries of $B=\\frac{A+A^{\\dagger}}{2}$ and $C=\\frac{A-A^{\\dagger}}{2i}$ are Hermitian. Since $A$ is a positive operator, for any vector $\\lvert v\\rangle$,\n    \\begin{align}\n        \\langle v\\rvert A\\lvert v\\rangle=\\langle v\\rvert(B+iC)\\lvert v\\rangle=\\langle v\\rvert B\\lvert v\\rangle+i\\langle v\\rvert C\\lvert v\\rangle\\geq 0,\n    \\end{align}\n    and is real. In this way, $\\langle v\\rvert C\\lvert v\\rangle$ can only be either purely imaginary or zero. Since $C$ is Hermitian, it is diagonalizable and has a diagonal representation\n    \\begin{align}\n        C=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert,\n    \\end{align}\n    where $\\lambda_i$ are the eigenvalues of $C$ and real, and $\\lvert i\\rangle$ is an orthonormal basis. Any vector $\\lvert v\\rangle$ can be written as a linear combination of $\\lvert i\\rangle$,\n    \\begin{align}\n        \\lvert v\\rangle=\\sum_ia_i\\lvert i\\rangle.\n    \\end{align}\n    Hence\n    \\begin{align}\n        \\langle v\\rvert C\\lvert v\\rangle=\\sum_ia_i^*\\langle i\\rvert \\sum_j\\lambda_j\\lvert j\\rangle\\langle j\\rvert\\sum_ka_k\\lvert k\\rangle=\\sum_{i,j,k}\\lambda_ja_i^*a_k\\langle i\\vert j\\rangle\\langle j\\vert k\\rangle=\\sum_{ijk}\\lambda_ja_i^*a_k\\delta_{ij}\\delta_{jk}=\\sum_i\\lambda_i\\abs{a_i}^2\n    \\end{align}\n    can not be purely imaginary and only be zero. Therefore, $A=B$ and is Hermitian.\n\\end{pf}\n\n\\begin{exe}\n    Show that for any operator $A$, $A^{\\dagger}A$ is positive.\n\\end{exe}\n\\begin{pf}\n    For any vector $\\lvert v\\rangle$,\n    \\begin{align}\n        (\\lvert v\\rangle,A^{\\dagger}A\\lvert v\\rangle)=((A^{\\dagger}A)^{\\dagger}\\lvert v\\rangle,\\lvert v\\rangle)=(A^{\\dagger}A\\lvert v\\rangle,\\lvert v\\rangle)=(\\lvert v\\rangle,A^{\\dagger}A\\lvert v\\rangle)^*,\n    \\end{align}\n    so $(\\lvert v\\rangle,A^{\\dagger}A\\lvert v\\rangle)$ is real. Besides,\n    \\begin{align}\n        (\\lvert v\\rangle,A^{\\dagger}A\\lvert v\\rangle)=((A^{\\dagger})^{\\dagger}\\lvert v\\rangle,A\\lvert v\\rangle)=(A\\lvert v\\rangle,A\\lvert v\\rangle)\\geq 0.\n    \\end{align}\n    Therefore, for any operator $A$, $A^{\\dagger}A$ is positive.\n\\end{pf}\n\n\\begin{exe}\n    Let $\\lvert\\psi\\rangle=(\\lvert 0\\rangle+\\lvert 1\\rangle)/\\sqrt{2}$. Write out $\\lvert\\psi\\rangle^{\\otimes 2}$ and $\\lvert\\psi\\rangle^{\\otimes 3}$ explicitly, both in terms of tensor products like $\\lvert 0\\rangle\\lvert 1\\rangle$, and using the Kronecker product.\n\\end{exe}\n\\begin{sol}\n    \\begin{align}\n        \\lvert\\psi\\rangle^{\\otimes 2}=&\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)\\otimes\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)=\\frac{1}{2}(\\lvert 0\\rangle\\lvert 0\\rangle+\\lvert 0\\rangle\\lvert 1\\rangle+\\lvert 1\\rangle\\lvert 0\\rangle+\\lvert 1\\rangle\\lvert 1\\rangle)\\\\\n        =&\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}\\otimes\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}=\\frac{1}{2}\\begin{bmatrix}\n            1\\\\\n            1\\\\\n            1\\\\\n            1\n        \\end{bmatrix},\\\\\n        \\notag\\lvert\\psi\\rangle^{\\otimes 3}=&\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)\\otimes\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)\\otimes\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)=\\frac{1}{2\\sqrt{2}}(\\lvert 0\\rangle\\lvert 0\\rangle\\lvert 0\\rangle+\\lvert 0\\rangle\\lvert 0\\rangle\\lvert 1\\rangle+\\lvert 0\\rangle\\lvert 1\\rangle\\lvert 0\\rangle+\\lvert 0\\rangle\\lvert 1\\rangle\\lvert 1\\rangle\\\\\n        &+\\lvert 1\\rangle\\lvert 0\\rangle\\lvert 0\\rangle+\\lvert 1\\rangle\\lvert 0\\rangle\\lvert 1\\rangle+\\lvert 1\\rangle\\lvert 1\\rangle\\lvert 0\\rangle+\\lvert 1\\rangle\\lvert 1\\rangle\\lvert 1\\rangle)\\\\\n        =&\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}\\otimes\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}\\otimes\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\n        \\end{bmatrix}=\\frac{1}{2\\sqrt{2}}\\begin{bmatrix}\n            1\\\\\n            1\\\\\n            1\\\\\n            1\\\\\n            1\\\\\n            1\\\\\n            1\\\\\n            1\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Calculate the matrix representation of the tensor products of the Pauli operators (a) $X$ and $Z$; (b) $I$ and $X$; (c) $X$ and $I$. Is the tensor product commutative?\n\\end{exe}\n\\begin{sol}\n    \\begin{itemize}\n        \\item[(a)] The matrix representation of the tensor product of $X$ and $Z$:\n        \\begin{align}\n            X\\otimes Z=\\begin{bmatrix}\n                0&1\\\\\n                1&0\n            \\end{bmatrix}\\otimes\\begin{bmatrix}\n                1&0\\\\\n                0&-1\n            \\end{bmatrix}=\\begin{bmatrix}\n                0&0&1&0\\\\\n                0&0&0&-1\\\\\n                1&0&0&0\\\\\n                0&-1&0&0\n            \\end{bmatrix}.\n        \\end{align}\n        The matrix representation of the tensor product of $Z$ and $X$:\n        \\begin{align}\n            Z\\otimes X=\\begin{bmatrix}\n                1&0\\\\\n                0&-1\n            \\end{bmatrix}\\otimes\\begin{bmatrix}\n                0&1\\\\\n                1&0\n            \\end{bmatrix}=\\begin{bmatrix}\n                0&1&0&0\\\\\n                1&0&0&0\\\\\n                0&0&0&-1\\\\\n                0&0&-1&0\n            \\end{bmatrix}.\n        \\end{align}\n        Therefore, the tensor product $X\\otimes Z$ and $Z\\otimes X$ are not commutative.\n        \\item[(b)] The matrix representation of the tensor product of $I$ and $X$:\n        \\begin{align}\n            I\\otimes X=\\begin{bmatrix}\n                1&0\\\\\n                0&1\n            \\end{bmatrix}\\otimes\\begin{bmatrix}\n                0&1\\\\\n                1&0\n            \\end{bmatrix}=\\begin{bmatrix}\n                0&1&0&0\\\\\n                1&0&0&0\\\\\n                0&0&0&1\\\\\n                0&0&1&0\n            \\end{bmatrix}.\n        \\end{align}\n        \\item[(c)] The matrix representation of the tensor product of $X$ and $I$:\n        \\begin{align}\n            X\\otimes I=\\begin{bmatrix}\n                0&1\\\\\n                1&0\n            \\end{bmatrix}\\otimes\\begin{bmatrix}\n                1&0\\\\\n                0&1\n            \\end{bmatrix}=\\begin{bmatrix}\n                0&0&1&0\\\\\n                0&0&0&1\\\\\n                1&0&0&0\\\\\n                0&1&0&0\n            \\end{bmatrix}.\n        \\end{align}\n        Therefore, the tensor product $I\\otimes X$ and $X\\otimes I$ are not commutative.\n    \\end{itemize}\n\\end{sol}\n\n\\begin{exe}\n    Show that the transpose, complex conjugate, and joint operation distribute over the tensor product,\n    \\begin{align}\n        (A\\otimes B)^*=A^*\\otimes B^*;\\quad(A\\otimes B)^T=A^T\\otimes B^T;\\quad(A\\otimes B)^{\\dagger}=A^{\\dagger}\\otimes B^{\\dagger}.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    Suppose $A$ is a $m$ by $n$ matrix, and $B$ is a $p$ by $q$ matrix.\n    \\begin{itemize}\n        \\item[(a)] \n        \\begin{align}\n            (A\\otimes B)^*=\\begin{bmatrix}\n                A_{11}B&A_{12}B&\\cdots&A_{1n}B\\\\\n                A_{21}B&A_{22}B&\\cdots&A_{2n}B\\\\\n                \\vdots&\\vdots&\\vdots&\\vdots\\\\\n                A_{m1}B&A_{m2}B&\\cdots&A_{mn}B\n            \\end{bmatrix}^*=\\begin{bmatrix}\n                A_{11}^*B^*&A_{12}^*B^*&\\cdots&A_{1n}^*B^*\\\\\n                A_{21}^*B^*&A_{22}^*B^*&\\cdots&A_{2n}^*B^*\\\\\n                \\vdots&\\vdots&\\vdots&\\vdots\\\\\n                A_{m1}^*B^*&A_{m2}^*B^*&\\cdots&A_{mn}^*B^*\n            \\end{bmatrix}=A^*\\otimes B^*.\n        \\end{align}\n        \\item[(b)] \n        \\begin{align}\n            (A\\otimes B)^T=\\begin{bmatrix}\n                A_{11}B&A_{12}B&\\cdots&A_{1n}B\\\\\n                A_{21}B&A_{22}B&\\cdots&A_{2n}B\\\\\n                \\vdots&\\vdots&\\vdots&\\vdots\\\\\n                A_{m1}B&A_{m2}B&\\cdots&A_{mn}B\n            \\end{bmatrix}^T=\\begin{bmatrix}\n                A_{11}B^T&A_{21}B^T&\\cdots&A_{m1}B^T\\\\\n                A_{12}B^T&A_{22}B^T&\\cdots&A_{m2}B^T\\\\\n                \\vdots&\\vdots&\\vdots&\\vdots\\\\\n                A_{1n}B^T&A_{2n}B^T&\\cdots&A_{mn}B^T\n            \\end{bmatrix}=A^T\\otimes B^T.\n        \\end{align}\n        \\item[(c)] \n        \\begin{align}\n            (A\\otimes B)^{\\dagger}=[(A\\otimes B)^*]^T=(A^*\\otimes B^*)^T=(A^*)^T\\otimes(B^*)^T=A^{\\dagger}\\otimes B^{\\dagger}.\n        \\end{align}\n    \\end{itemize}\n\\end{pf}\n\n\\begin{exe}\n    Show that the tensor product of two unitary operators is unitary.\n\\end{exe}\n\\begin{pf}\n    Suppose $A$ and $B$ are two unitary operators,\n    \\begin{align}\n        A^{\\dagger}A=&I,\\\\\n        B^{\\dagger}B=&I.\n    \\end{align}\n    Using the conclusion obtained in the previous exercise,\n    \\begin{align}\n        (A\\otimes B)^{\\dagger}(A\\otimes B)=(A^{\\dagger}\\otimes B^{\\dagger})(A\\otimes B)=(A^{\\dagger}A)\\otimes(B^{\\dagger}B)=I\\otimes I=I,\n    \\end{align}\n    so the tensor product of two unitary operators is unitary.\n\\end{pf}\n\n\\begin{exe}\n    Show that the tensor product of two Hermitian operators is Hermitian.\n\\end{exe}\n\\begin{pf}\n    Suppose $A$ and $B$ are two Hermitian operators,\n    \\begin{align}\n        A^{\\dagger}=&A,\\\\\n        B^{\\dagger}=&B.\n    \\end{align}\n    Using the conclusion obtained in Exercise 2.28,\n    \\begin{align}\n        (A\\otimes B)^{\\dagger}=A^{\\dagger}\\otimes B^{\\dagger}=A\\otimes B,\n    \\end{align}\n    so the tensor product of two Hermitian operators is Hermitian.\n\\end{pf}\n\n\\begin{exe}\n    Show that the tensor product of two positive operators is positive.\n\\end{exe}\n\\begin{pf}\n    Suppose $A$ and $B$ are positive operators on vector spaces $V$ and $W$ respectively. For any vector $\\lvert v\\rangle\\in V$ and $\\lvert w\\rangle\\in W$,\n    \\begin{align}\n        (\\lvert v\\rangle,A\\lvert v\\rangle)\\geq&0,\\\\\n        (\\lvert w\\rangle,B\\lvert w\\rangle)\\geq&0,\n    \\end{align}\n    so $A\\otimes B$ is a positive operator,\n    \\begin{align}\n        (\\lvert v\\rangle\\otimes\\lvert w\\rangle,(A\\otimes B)(\\lvert v\\rangle\\otimes\\lvert w\\rangle))=(\\lvert v\\rangle\\otimes\\lvert w\\rangle,(A\\lvert v\\rangle)\\otimes(B\\lvert w\\rangle))=(\\lvert v\\rangle,A\\lvert v\\rangle)(\\lvert w\\rangle,B\\lvert w\\rangle)\\geq 0.\n    \\end{align}\n    Therefore, the tensor product of two positive operators is positive.\n\\end{pf}\n\n\\begin{exe}\n    Show that the tensor product of two projectors is a projector.\n\\end{exe}\n\\begin{pf}\n    Suppose $\\lvert i\\rangle_V$ is an orthonormal basis for vector space $V$, and $\\lvert j\\rangle_W$ is an orthonormal basis for vector space $W$. The projector onto $V$ is\n    \\begin{align}\n        P_V=\\sum_i\\lvert i\\rangle_V\\langle i\\lvert_V,\n    \\end{align}\n    and the projector onto $W$ is\n    \\begin{align}\n        P_W=\\sum_j\\lvert j\\rangle_W\\langle j\\lvert_W.\n    \\end{align}\n    Their tensor product is\n    \\begin{align}\n        P_V\\otimes P_W=\\left(\\sum_i\\lvert i\\rangle_V\\langle i\\lvert_V\\right)\\otimes\\left(\\sum_j\\lvert j\\rangle_W\\langle j\\lvert_W\\right)=\\sum_{i,j}(\\lvert i\\rangle_V\\otimes\\lvert j\\rangle_W)(\\langle i\\rvert_V\\otimes\\langle j\\rvert_W).\n    \\end{align}\n    Since both $\\lvert i\\rangle_V$ and $\\lvert j\\rangle_W$ are independent, $\\lvert i\\rangle\\otimes\\lvert j\\rangle$ are independent. Since both $\\lvert i\\rangle_V$ and $\\lvert j\\rangle_W$ are orthonormal, $\\lvert i\\rangle\\otimes\\lvert j\\rangle$ are orthonormal,\n    \\begin{align}\n        (\\vert i\\rangle_V\\otimes\\lvert j\\rangle_W,\\lvert k\\rangle_V\\otimes\\lvert l\\rangle_W)=(\\lvert i\\rangle_V,\\lvert k\\rangle_V)(\\lvert j\\rangle_W,\\lvert l\\rangle_W)=\\delta_{ik}\\delta_{jl}.\n    \\end{align}\n    Since any vector $\\lvert v\\rangle\\in V$ can be written as a linear combination of $\\lvert i\\rangle_V$,\n    \\begin{align}\n        \\lvert v\\rangle=\\sum_ia_i\\lvert i\\rangle_V,\n    \\end{align}\n    and any vector $\\lvert w\\rangle\\in W$ can be written as a linear combination of $\\lvert j\\rangle_W$,\n    \\begin{align}\n        \\lvert w\\rangle=\\sum_jb_j\\lvert j\\rangle_W,\n    \\end{align}\n    the tensor product $\\lvert v\\otimes\\lvert w\\rangle\\in V\\otimes W$ can be written as a linear combination of $\\lvert i\\rangle_V\\otimes\\lvert j\\rangle_W$,\n    \\begin{align}\n        \\lvert v\\rangle\\otimes\\lvert w\\rangle=\\left(\\sum_ia_i\\lvert i\\rangle_V\\right)\\otimes\\left(\\sum_jb_j\\lvert j\\rangle_W\\right)=\\sum_{i,j}a_ib_j\\lvert i\\rangle_V\\otimes\\lvert j\\rangle_W.\n    \\end{align}\n    Hence $\\lvert i\\rangle_V\\otimes\\lvert j\\rangle_W$ is an orthonormal basis for $V\\otimes W$ and $P_V\\otimes P_W$ is a projector onto $V\\otimes W$. Therefore, the tensor product of two projectors is a projector.\n\\end{pf}\n\n\\begin{exe}\n    The Hadamard operator on one qubit may be written as\n    \\begin{align}\n        H=\\frac{1}{\\sqrt{2}}\\left[(\\lvert 0\\rangle+\\lvert 1\\rangle)\\langle 0\\rvert+(\\lvert 0\\rangle-\\lvert 1\\rangle)\\langle 1\\rvert\\right].\n    \\end{align}\n    Show explicitly that the Hadamard transform on $n$ qubits, $H^{\\otimes n}$, may be written as\n    \\begin{align}\n        H^{\\otimes n}=\\frac{1}{\\sqrt{2^n}}\\sum_{x,y}(-1)^{x\\cdot y}\\lvert x\\rangle\\langle y\\rvert.\n    \\end{align}\n    Write out an explicit matrix representation for $H^{\\otimes 2}$.\n\\end{exe}\n\\begin{sol}\n    Hadamard transform on one qubit may be written as\n    \\begin{align}\n        H\\lvert 0\\rangle=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 0\\rvert+\\lvert 0\\rangle\\langle 1\\rvert-\\lvert 1\\rangle\\langle 1\\rvert)=\\frac{1}{\\sqrt{2}}\\sum_{x,y=0}^1\\lvert x\\rangle\\langle y\\rvert.\n    \\end{align}\n    Thus Hadamard transform on $n$ qubits may be written as\n    \\begin{align}\n        \\notag H^{\\otimes n}=&\\left(\\frac{1}{\\sqrt{2}}\\sum_{x_1,y_1=0}^1\\lvert x_1\\rangle\\langle y_1\\rvert\\right)\\otimes\\cdots\\otimes\\left(\\frac{1}{\\sqrt{2}}\\sum_{x_n,y_n=0}^1\\lvert x_n\\rangle\\langle y_n\\rvert\\right)=\\frac{1}{\\sqrt{2^n}}\\sum_{\\substack{x_1,\\cdots,x_n\\\\y_1,\\cdots,y_n}=0}^1\\lvert x_1,\\cdots,x_n\\rangle\\langle y_1,\\cdots,y_n\\rvert\\\\\n        =&\\frac{1}{\\sqrt{2^n}}\\sum_{x,y}(-1)^{x\\cdot y}\\lvert x\\rangle\\langle y\\rvert.\n    \\end{align}\n    The matrix representation for $H^{\\otimes 2}$ is\n    \\begin{align}\n        H^{\\otimes 2}=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}\\otimes\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}=\\frac{1}{2}\\begin{bmatrix}\n            1&1&1&1\\\\\n            1&-1&1&-1\\\\\n            1&1&-1&-1\\\\\n            1&-1&-1&1\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Find the square root and logarithm of the matrix\n    \\begin{align}\n        \\begin{bmatrix}\n            4&3\\\\\n            3&4\n        \\end{bmatrix}.\n    \\end{align}\n\\end{exe}\n\\begin{sol}\n    The square root of the matrix is\n    \\begin{align}\n        \\begin{bmatrix}\n            2&\\sqrt{3}\\\\\n            \\sqrt{3}&2\n        \\end{bmatrix}.\n    \\end{align}\n    The logarithm of the matrix is\n    \\begin{align}\n        \\begin{bmatrix}\n            \\ln 4&\\ln 3\\\\\n            \\ln 3&\\ln 4\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}[Exponential of the Pauli matrices]\n    Let $\\vec{v}$ be any real, three dimensional unit vector and $\\theta$ a real number. Prove that\n    \\begin{align}\n        \\label{E2.35}\n        \\exp(i\\theta\\vec{v}\\cdot\\vec{\\sigma})=\\cos(\\theta)I+i\\sin(\\theta)\\vec{v}\\cdot\\vec{\\sigma},\n    \\end{align}\n    where $\\vec{v}\\cdot\\vec{\\sigma}=\\sum_{i=1}^3v_i\\sigma_i$. This exercise is generalized in Problem 2.1 on page 117.\n\\end{exe}\n\\begin{pf}\n    The left side of Equation \\eqref{E2.35} is\n    \\begin{align}\n        \\exp(i\\theta\\vec{v}\\cdot\\vec{\\sigma})=\\sum_{n=0}^{\\infty}\\frac{1}{n!}(i\\theta\\vec{v}\\cdot\\vec{\\sigma})^n=\\sum_{n=0}^{\\infty}\\frac{(-1)^n}{(2n)!}(\\theta\\vec{v}\\cdot\\vec{\\sigma})^{2n}+\\sum_{n=0}^{\\infty}\\frac{i(-1)^n}{(2n+1)!}(\\theta\\vec{v}\\cdot\\vec{\\sigma})^{2n+1}.\n    \\end{align}\n    Note that\n    \\begin{align}\n        (\\vec{v}\\cdot\\vec{\\sigma})^2=\\left(\\sum_{i=1}^3v_i\\sigma_i\\right)^2=\\sum_{i,j=1}^3v_iv_j\\sigma_i\\sigma_j.\n    \\end{align}\n    Due to the anti-commutation relation between the Pauli matrices,\n    \\begin{align}\n        \\{\\sigma_i,\\sigma_j\\}=\\sigma_i\\sigma_j+\\sigma_j\\sigma_i=2\\delta_{ij}I=\\left\\{\\begin{array}{ll}\n            2I,&i=j;\\\\\n            0,&i\\neq j,\n        \\end{array}\\right.\n    \\end{align}\n    we have\n    \\begin{align}\n        (\\vec{v}\\cdot\\vec{\\sigma})^2=\\sum_{i=1}^3v_i^2I=I.\n    \\end{align}\n    Hence the left side of Equation \\eqref{E2.35} can be written as\n    \\begin{align}\n        \\exp(i\\theta\\vec{v}\\cdot\\vec{\\sigma})=\\sum_{n=0}^{\\infty}\\frac{(-1)^n}{(2n)!}\\theta^{2n}+\\sum_{n=0}^{\\infty}\\frac{i(-1)^n}{(2n+1)!}\\theta^{2n+1}\\vec{v}\\cdot\\vec{\\sigma}=\\cos(\\theta)I+i\\sin(\\theta)\\vec{v}\\cdot\\vec{\\sigma},\n    \\end{align}\n    which equals the right side of Equation \\eqref{E2.35}. Therefore, Equation \\eqref{E2.35} holds.\n\\end{pf}\n\n\\begin{exe}\n    Show that the Pauli matrices except for $I$ have trace zero.\n\\end{exe}\n\\begin{pf}\n    The trace of $I$ is\n    \\begin{align}\n        \\tr(I)=1+1=2.\n    \\end{align}\n    The trace of $X$ is\n    \\begin{align}\n        \\tr(X)=0+0=0.\n    \\end{align}\n    The trace of $Y$ is\n    \\begin{align}\n        \\tr(Y)=0+0=0.\n    \\end{align}\n    The trace of $Z$ is\n    \\begin{align}\n        \\tr(Z)=1+(-1)=0.\n    \\end{align}\n    Therefore, the Pauli matrices except for $I$ have trace zero.\n\\end{pf}\n\n\\begin{exe}[Cyclic property of the trace]\n    If $A$ and $B$ are two linear operators show that\n    \\begin{align}\n        \\tr(AB)=\\tr(BA).\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\tr(AB)=\\sum_i(AB)_{ii}=\\sum_i\\left(\\sum_jA_{ij}B_{ji}\\right)=\\sum_j\\left(\\sum_iB_{ji}A_{ij}\\right)=\\sum_j(BA)_{jj}=\\tr(BA).\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}[Linearity of the trace]\n    If $A$ and $B$ are two linear operators. show that\n    \\begin{align}\n        \\tr(A+B)=\\tr(A)+\\tr(B)\n    \\end{align}\n    and if $z$ is an arbitrary complex number show that\n    \\begin{align}\n        \\tr(zA)=z\\tr(A).\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\tr(A+B)=&\\sum_i(A+B)_{ii}=\\sum_iA_{ii}+\\sum_iB_{ii}=\\tr(A)+\\tr(B).\\\\\n        \\tr(zA)=&\\sum_i(zA)_{ii}=z\\sum_iA_{ii}=z\\tr(A).\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}[The Hilbert-Schmidt inner product on operators]\n    The set $L_V$ of linear operators on a Hilbert space $V$ is obviously a vector space -- the sum of two linear operators is a Linear operator, $zA$ is a linear operator if $A$ is a linear operator and $z$ is a complex number, and there is a zero element $0$. An important additional result is that the vector space $L_V$ can be given a natural inner product structure, turning it into a Hilbert space.\n    \\begin{itemize}\n        \\item[(1)] Show that the function $(\\cdot,\\cdot)$ on $L_V\\times L_V$ defined by\n        \\begin{align}\n            (A,B)\\equiv\\tr(A^{\\dagger}B)\n        \\end{align}\n        is an inner product function. This inner product is known as the \\emph{Hilbert-Schmidt} or \\emph{trace} inner product.\n        \\item[(2)] If $V$ has $d$ dimensions show that $L_V$ has dimension $d^2$.\n        \\item[(3)] Find an orthonormal basis of Hermitian matrices for the Hilbert space $L_V$.\n    \\end{itemize}\n\\end{exe}\n\\begin{sol}\n    \\begin{itemize}\n        \\item[(1)] The function $(\\cdot,\\cdot)$ on $L_V\\times L_V$ satisfies the requirements that:\n        \\begin{itemize}\n            \\item[(a)] $(\\cdot,\\cdot)$ is linear in the second argument,\n            \\begin{align}\n                \\left(A,\\sum_j\\lambda_jB^{(j)}\\right)=\\tr\\left(A^{\\dagger}\\sum_j\\lambda_jB^{(j)}\\right)=\\tr\\left(\\sum_j\\lambda_jA^{\\dagger}B^{(j)}\\right)=\\sum_j\\lambda_j\\tr(A^{\\dagger}B^{(j)})=\\sum_j\\lambda(A,B^{\\dagger}).\n            \\end{align}\n            \\item[(b)] \n            \\begin{align}\n                \\notag(A,B)=&\\tr(A^{\\dagger}B)=\\sum_i(A^{\\dagger}B)_{ii}=\\sum_i\\left[\\sum_j(A^{\\dagger})_{ij}B_{ji}\\right]=\\sum_i\\left(\\sum_jA_{ji}^*B_{ji}\\right)=\\left[\\sum_i\\left(\\sum_jA_{ji}B_{ji}^*\\right)\\right]^*\\\\\n                =&\\left\\{\\sum_i\\left[\\sum_j(B^{\\dagger})_{ij}A_{ji}\\right]\\right\\}^*=\\left[\\sum_i(B^{\\dagger}A)_{ii}\\right]^*=[\\tr(B^{\\dagger}A)]^*=(B,A)^*.\n            \\end{align}\n            \\item[(c)] \n            \\begin{align}\n                (A,A)=\\tr(A^{\\dagger}A)=\\sum_i(A^{\\dagger}A)_{ii}=\\sum_i\\left[\\sum_j(A^{\\dagger})_{ij}A_{ji}\\right]=\\sum_i\\left(\\sum_jA_{ji}^*A_{ji}\\right)=\\sum_{i,j}\\abs{A_{ji}}^2\\geq 0,\n            \\end{align}\n            with equality if and only if $A=0$.\n        \\end{itemize}\n        Therefore, the function $(\\cdot,\\cdot)$ defined on $L_V\\times L_V$ is an inner product function.\n        \\item[(2)] Suppose $\\lvert 1\\rangle,\\cdots,\\lvert d\\rangle$ form an orthonormal basis for $V$. Since\n        \\begin{itemize}\n            \\item[(a)] any operator $A$ in $V$ can be written as\n            \\begin{align}\n                A=\\sum_{i,j}A_{ij}\\lvert i\\rangle\\langle j\\rvert,\n            \\end{align}\n            and\n            \\item[(b)] $\\lvert i\\rangle\\langle j\\rvert$ are orthonormal,\n            \\begin{align}\n                (\\lvert i\\rangle\\langle j\\rvert,\\lvert m\\rangle\\langle n\\rvert)=\\tr[(\\lvert i\\rangle\\langle j\\rvert)^{\\dagger}\\lvert m\\rangle\\langle n\\rvert]=\\tr(\\lvert j\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert)=\\sum_k\\langle k\\rvert j\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle=\\sum_k\\delta_{kj}\\delta_{im}\\delta_{nk}=\\delta_{im}\\delta_{jn},\n            \\end{align}\n            and thus linearly independent, $\\lvert i\\rangle\\langle j\\rvert$ is an orthonormal basis for $L_V$. Since this basis has $d^2$ elements, $L_V$ has dimension $d^2$.\n        \\end{itemize}\n        \\item[(3)] $\\left\\{\\lvert i\\rangle\\langle i\\rvert,\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}},\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}};\\forall 1\\leq i<j\\leq d\\right\\}$ is an orthonormal basis of Hermitian matrices for the Hilbert space $L_V$. Here is the reason:\n        \\begin{itemize}\n            \\item[(a)] For any Hermitian matrices $A$, since\n            \\begin{align}\n                A^{\\dagger}=A\\Longrightarrow A_{ji}^*=A_{ji},\\quad\\forall i,j=1,\\cdots,d,\n            \\end{align}\n            and $A_{ii}$ is real $\\forall i$, $A$ can be written as\n            \\begin{align}\n                \\notag A=&\\sum_{i,j}A_{ij}\\lvert i\\rangle\\langle j\\rvert=\\sum_iA_{ii}\\lvert i\\rangle\\langle i\\rvert+\\sum_{i=2}^d\\sum_{j=1}^{i-1}A_{ij}\\lvert i\\rangle\\langle j\\rvert+\\sum_{j=2}^d\\sum_i^{j-1}A_{ij}\\lvert i\\rangle\\langle j\\rvert\\\\\n                \\notag=&\\sum_iA_{ii}\\lvert i\\rangle\\langle i\\rvert+\\sum_{i=2}^d\\sum_{j=1}^{i-1}A_{ji}^*\\lvert i\\rangle\\langle j\\rvert+\\sum_{j=2}^d\\sum_i^{j-1}A_{ij}\\lvert i\\rangle\\langle j\\rvert\\\\\n                \\notag=&\\sum_iA_{ii}\\lvert i\\rangle\\langle i\\rvert+\\sum_{j=2}^d\\sum_{i=1}^{j-1}A_{ij}^*\\lvert j\\rangle\\langle i\\rvert+\\sum_{j=2}^d\\sum_i^{j-1}A_{ij}\\lvert i\\rangle\\langle j\\rvert\\\\\n                \\notag=&\\sum_iA_{ii}\\lvert i\\rangle\\langle i\\rvert+\\sum_{j=2}^d\\sum_{i=1}^{j-1}\\frac{A_{ij}+A_{ij}^*}{\\sqrt{2}}\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}}+\\sum_{j=2}^d\\sum_i^{j-1}\\frac{A_{ij}-A_{ij}^*}{-i\\sqrt{2}}\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}}.\n            \\end{align}\n            \\item[(b)] Elements in $\\left\\{\\lvert i\\rangle\\langle i\\rvert,\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}},\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}};\\forall 1\\leq i<j\\leq d\\right\\}$ are orthonormal and thus linearly independent,\n            \\begin{align}\n                \\notag\\left(\\lvert i\\rangle\\langle i\\rvert,\\frac{\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert}{\\sqrt{2}}\\right)=&\\tr\\left[(\\lvert i\\rangle\\langle i\\rvert)^{\\dagger}\\left(\\frac{\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert}{\\sqrt{2}}\\right)\\right]=\\frac{1}{\\sqrt{2}}\\tr\\left[\\lvert i\\rangle\\langle i\\rvert(\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert)\\right]\\\\\n                \\notag=&\\frac{1}{\\sqrt{2}}\\tr(\\lvert i\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert+\\lvert i\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert)\\\\\n                \\notag=&\\frac{1}{\\sqrt{2}}\\sum_k(\\langle k\\vert i\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle+\\langle k\\vert i\\rangle\\langle i\\vert n\\rangle\\langle m\\vert k\\rangle)\\\\\n                \\notag=&\\frac{1}{\\sqrt{2}}\\sum_k(\\delta_{ki}\\delta_{im}\\delta_{nk}+\\delta_{ki}\\delta_{in}\\delta_{mk})\\\\\n                =&\\sqrt{2}\\delta_{im}\\delta_{in}=0,\\quad\\forall i=1,\\cdots,d,1\\leq m<n\\leq d,\\\\\n                \\notag\\left(\\lvert i\\rangle\\langle i\\rvert,\\frac{\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right)=&\\tr\\left[(\\lvert i\\rangle\\langle i\\rvert)^{\\dagger}\\left(\\frac{\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right)\\right]=\\frac{1}{i\\sqrt{2}}\\tr\\left[\\lvert i\\rangle\\langle i\\rvert(\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert)\\right]\\\\\n                \\notag=&\\frac{1}{i\\sqrt{2}}\\tr(\\lvert i\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert-\\lvert i\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert)\\\\\n                \\notag=&\\frac{1}{i\\sqrt{2}}\\sum_k(\\langle k\\vert i\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle-\\langle k\\vert i\\rangle\\langle i\\vert n\\rangle\\langle m\\vert k\\rangle)\\\\\n                \\notag=&\\frac{1}{i\\sqrt{2}}\\sum_k(\\delta_{ki}\\delta_{im}\\delta_{nk}-\\delta_{ki}\\delta_{in}\\delta_{mk})\\\\\n                =&0,\\quad\\forall i=1,\\cdots,d,1\\leq m<n\\leq d,\\\\\n                \\notag\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}},\\frac{\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right)=&\\tr\\left[\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}}\\right)^{\\dagger}\\left(\\frac{\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right)\\right]\\\\\n                \\notag=&\\frac{1}{2i}\\tr\\left[(\\lvert j\\rangle\\langle i\\rvert+\\lvert i\\rangle\\langle j\\rvert)(\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert)\\right]\\\\\n                \\notag=&\\frac{1}{2i}\\tr(\\lvert j\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert-\\lvert j\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert+\\lvert i\\rangle\\langle j\\vert m\\rangle\\langle n\\rvert-\\lvert i\\rangle\\langle j\\vert n\\rangle\\langle m\\rvert)\\\\\n                \\notag=&\\frac{1}{2i}\\sum_k(\\langle k\\vert j\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle-\\langle k\\vert j\\rangle\\langle i\\vert n\\rangle\\langle m\\vert k\\rangle\\\\\n                \\notag&+\\langle k\\vert i\\rangle\\langle j\\vert m\\rangle\\langle n\\vert k\\rangle-\\langle k\\vert i\\rangle\\langle j\\vert n\\rangle\\langle m\\vert k\\rangle)\\\\\n                \\notag=&\\frac{1}{2i}\\sum_k(\\delta_{kj}\\delta_{im}\\delta_{nk}-\\delta_{kj}\\delta_{in}\\delta_{mk}+\\delta_{ki}\\delta_{jm}\\delta_{nk}-\\delta_{ki}\\delta_{jn}\\delta_{mk})\\\\\n                =&0,\\quad\\forall 1\\leq i<j\\leq d,\\cdots,d,1\\leq m<n\\leq d,\\\\\n                \\notag(\\lvert i\\rangle\\langle i\\rvert,\\lvert j\\rangle\\langle j\\rvert)=&\\tr[(\\lvert i\\rangle\\langle i\\rvert)^{\\dagger}\\lvert j\\rangle\\langle j\\rvert]=\\tr(\\lvert i\\rangle\\langle i\\vert j\\rangle\\langle j\\rvert)=\\sum_k\\langle k\\vert i\\rangle\\langle i\\vert j\\rangle\\langle j\\vert k\\rangle=\\sum_k\\delta_{ki}\\delta_{ij}\\delta_{jk}\\\\\n                =&\\delta_{ij},\\quad\\forall i,j=1,\\cdots,d,\\\\\n                \\notag\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert i\\rangle\\langle j\\rvert}{\\sqrt{2}},\\frac{\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert}{\\sqrt{2}}\\right)=&\\tr\\left[\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}}\\right)^{\\dagger}\\frac{\\lvert m\\rangle\\langle n\\rvert+\\lvert n\\rangle\\langle m\\rvert}{\\sqrt{2}}\\right]\\\\\n                \\notag=&\\frac{1}{2}\\tr[(\\lvert j\\rangle\\langle i\\rvert+\\lvert i\\rangle\\langle j\\rvert)(\\lvert m\\rangle\\langle m\\rvert+\\lvert n\\rangle\\langle m\\rvert)]\\\\\n                \\notag=&\\frac{1}{2}\\tr(\\lvert j\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert+\\lvert j\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert+\\lvert i\\rangle\\langle j\\vert m\\rangle\\langle n\\rvert+\\lvert i\\rangle\\langle j\\vert n\\rangle\\langle m\\rvert)\\\\\n                \\notag=&\\frac{1}{2}\\sum_k(\\langle k\\vert j\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle+\\langle k\\vert j\\rangle\\langle i\\vert n\\rangle\\langle m\\vert k\\rangle\\\\\n                \\notag&+\\langle k\\vert i\\rangle\\langle j\\vert m\\rangle\\langle n\\vert k\\rangle+\\langle k\\vert i\\rangle\\langle j\\vert n\\rangle\\langle m\\vert k\\rangle)\\\\\n                \\notag=&\\frac{1}{2}\\sum_k(\\delta_{kj}\\delta_{im}\\delta_{nk}+\\delta_{kj}\\delta_{in}\\delta_{mk}+\\delta_{ki}\\delta_{jm}\\delta_{nk}+\\delta_{ki}\\delta_{jn}\\delta_{mk})\\\\\n                =&\\delta_{im}\\delta_{jn}+\\delta_{in}\\delta_{jm},\\quad\\forall 1\\leq i<j\\leq d,1\\leq m<n\\leq d,\\\\\n                \\notag\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}},\\frac{\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right)=&\\tr\\left[\\left(\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}}\\right)^{\\dagger}\\frac{\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert}{i\\sqrt{2}}\\right]\\\\\n                \\notag=&\\frac{1}{2}\\tr\\left[(\\lvert j\\rangle\\langle i\\rvert-\\lvert i\\rangle\\langle j\\rvert)(\\lvert m\\rangle\\langle n\\rvert-\\lvert n\\rangle\\langle m\\rvert)\\right]\\\\\n                \\notag=&\\frac{1}{2}\\tr(\\lvert j\\rangle\\langle i\\vert m\\rangle\\langle n\\rvert-\\lvert j\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert-\\lvert i\\rangle\\langle j\\vert m\\rangle\\langle n\\rvert+\\lvert j\\rangle\\langle i\\vert n\\rangle\\langle m\\rvert)\\\\\n                \\notag=&\\frac{1}{2}\\sum_k(\\langle k\\vert j\\rangle\\langle i\\vert m\\rangle\\langle n\\vert k\\rangle-\\langle k\\vert j\\rangle\\langle i\\vert n\\rangle\\langle m\\vert k\\rangle\\\\\n                \\notag&-\\langle k\\vert i\\rangle\\langle j\\vert m\\rangle\\langle n\\vert k\\rangle+\\langle k\\vert i\\rangle\\langle j\\vert n\\rangle\\langle m\\vert k\\rangle)\\\\\n                \\notag=&\\frac{1}{2}\\sum_k(\\delta_{kj}\\delta_{im}\\delta_{nk}-\\delta_{kj}\\delta_{in}\\delta_{mk}-\\delta_{ki}\\delta_{jm}\\delta_{nk}+\\delta_{ki}\\delta_{jn}\\delta_{mk})\\\\\n                =&\\delta_{im}\\delta_{jn}-\\delta_{in}\\delta_{jm}=\\delta_{im}\\delta_{jn},\\quad\\forall 1\\leq i<j\\leq d,1\\leq m<n\\leq d.\n            \\end{align}\n            and thus linearly independent.\n        \\end{itemize}\n        Therefore, $\\left\\{\\lvert i\\rangle\\langle i\\rvert,\\frac{\\lvert i\\rangle\\langle j\\rvert+\\lvert j\\rangle\\langle i\\rvert}{\\sqrt{2}},\\frac{\\lvert i\\rangle\\langle j\\rvert-\\lvert j\\rangle\\langle i\\rvert}{i\\sqrt{2}};\\forall 1\\leq i<j\\leq d\\right\\}$ is an orthonormal basis of Hermitian matrices for the Hilbert space $L_V$.\n    \\end{itemize}\n\\end{sol}\n\n\\begin{exe}[commutation relation for the Pauli matrices]\n    Verify the commutation relations\n    \\begin{align}\n        [X,Y]=2iZ;\\quad[Y,Z]=2iX;\\quad[Z,X]=2iY.\n    \\end{align}\n    There is an elegant way of writing this using $\\epsilon_{jkl}$, the alternative antisymmetric tensor on three indices for which $\\epsilon_{jkl}=0$ except for $\\epsilon_{123}=\\epsilon_{231}=\\epsilon_{312}=1$, and $\\epsilon_{321}=\\epsilon_{213}=\\epsilon_{132}=-1$:\n    \\begin{align}\n        [\\sigma_j,\\sigma_k]=2i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    The commutation relations for the Pauli matrices are\n    \\begin{align}\n        [X,Y]=&XY-YX=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}-\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            i&0\\\\\n            0&-i\n        \\end{bmatrix}-\\begin{bmatrix}\n            -i&0\\\\\n            0&i\n        \\end{bmatrix}=2i\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=2iZ,\\\\\n        [Y,Z]=&YZ-ZY=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}-\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            0&i\\\\\n            i&0\n        \\end{bmatrix}-\\begin{bmatrix}\n            0&-i\\\\\n            -i&0\n        \\end{bmatrix}=2i\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=2iX,\\\\\n        [Z,X]=&ZX-XZ=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}-\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            0&1\\\\\n            -1&0\n        \\end{bmatrix}-\\begin{bmatrix}\n            0&-1\\\\\n            1&0\n        \\end{bmatrix}=2i\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=2iY,\n    \\end{align}\n    and\n    \\begin{align}\n        [\\sigma_j,\\sigma_j]=&\\sigma_l\\sigma_l-\\sigma_l\\sigma_l=0,\\quad\\forall j=1,2,3,\\\\\n        [\\sigma_j,\\sigma_k]=&\\sigma_j\\sigma_k-\\sigma_k\\sigma_j=-[\\sigma_k,\\sigma_j],\\quad\\forall j,k=1,2,3.\n    \\end{align}\n    Therefore, in general,\n    \\begin{align}\n        [\\sigma_j,\\sigma_k]=2i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}[Anti-commutation relation for the Pauli matrices]\n    Verify the anti-commutation relations\n    \\begin{align}\n        \\{\\sigma_i,\\sigma_j\\}=0\n    \\end{align}\n    where $i\\neq j$ are both chosen from the set $1,2,3$. Also verify that ($i=0,1,2,3$)\n    \\begin{align}\n        \\sigma_i^2=I.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\{\\sigma_1,\\sigma_2\\}=&\\sigma_1\\sigma_2+\\sigma_2\\sigma_1=\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}+\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            i&0\\\\\n            0&-i\n        \\end{bmatrix}+\\begin{bmatrix}\n            -i&0\\\\\n            0&i\n        \\end{bmatrix}=0,\\\\\n        \\{\\sigma_2,\\sigma_3\\}=&\\sigma_2\\sigma_3+\\sigma_3\\sigma_2=\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}+\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            0&i\\\\\n            i&0\n        \\end{bmatrix}+\\begin{bmatrix}\n            0&-i\\\\\n            -i&0\n        \\end{bmatrix}=0,\\\\\n        \\{\\sigma_3,\\sigma_1\\}=&\\sigma_3\\sigma_1+\\sigma_1\\sigma_3=\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}+\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            0&1\\\\\n            -1&0\n        \\end{bmatrix}+\\begin{bmatrix}\n            0&-1\\\\\n            1&0\n        \\end{bmatrix}=0,\\\\\n        \\sigma_0^2=&I^2=I,\\\\\n        \\sigma_1^2=&\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\\\\\n        \\sigma_2^2=&\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\\\\\n        \\sigma_3^2=&\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I.\n    \\end{align}\n    Therefore, in general,\n    \\begin{align}\n        \\{\\sigma_i,\\sigma_j\\}=0,\\quad\\forall i,j=1,2,3,\\text{ and }i\\neq j,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sigma_i^2=I,\\quad\\forall i=0,1,2,3.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Verify that\n    \\begin{align}\n        AB=\\frac{[A,B]+\\{A,B\\}}{2}.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\frac{[A,B]+\\{A,B\\}}{2}=\\frac{AB-BA+AB+BA}{2}=AB.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Show that for $j,k=1,2,3$,\n    \\begin{align}\n        \\sigma_j\\sigma_k=\\delta_{jk}I+i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    As obtained in Exercises 2.40, 2.41 and 2.42,\n    \\begin{align}\n        [\\sigma_j,\\sigma_k]=&2i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l,\\quad\\forall j,k=1,2,3,\\\\\n        \\{\\sigma_j,\\sigma_k\\}=&2\\delta_{jk}I,\\quad\\forall j,k=1,2,3,\\\\\n        AB=&\\frac{[A,B]+\\{A,B\\}}{2},\n    \\end{align}\n    so\n    \\begin{align}\n        \\sigma_j\\sigma_k=\\frac{[\\sigma_j,\\sigma_k]+\\{\\sigma_j,\\sigma_k\\}}{2}=\\frac{2i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l+2\\delta_{jk}I}{2}=\\delta_{jk}I+i\\sum_{l=1}^3\\epsilon_{jkl}\\sigma_l,\\quad\\forall j,k=1,2,3.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose $[A,B]=0$, $\\{A,B\\}=0$, and $A$ is invertible. Show that $B$ must be 0.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        AB=\\frac{[A,B]+\\{A,B\\}}{2}=0.\n    \\end{align}\n    $A$ is invertible and thus can not be $0$, so $B$ must be $0$.\n\\end{pf}\n\n\\begin{exe}\n    Show that $[A,B]^{\\dagger}=[B^{\\dagger},A^{\\dagger}]$.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        [A,B]^{\\dagger}=(AB-BA)^{\\dagger}=B^{\\dagger}A^{\\dagger}-A^{\\dagger}B^{\\dagger}=[B^{\\dagger},A^{\\dagger}].\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Show that $[A,B]=-[B,A]$.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        [A,B]=AB-BA=-(BA-AB)=-[B,A].\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose $A$ and $B$ are Hermitian. Show that $i[A,B]$ is Hermitian.\n\\end{exe}\n\\begin{pf}\n    Since $A$ and $B$ are Hermitian,\n    \\begin{align}\n        A^{\\dagger}=&A,\\\\\n        B^{\\dagger}=&B.\n    \\end{align}\n    Since\n    \\begin{align}\n        (i[A,B])^{\\dagger}=[i(AB-BA)]^{\\dagger}=-i(B^{\\dagger}A^{\\dagger}-A^{\\dagger}B^{\\dagger})=i(AB-BA)=i[A,B],\n    \\end{align}\n    $i[A,B]$ is Hermitian.\n\\end{pf}\n\n\\begin{exe}\n    What is the polar decomposition of a positive matrix $P$? Of a unitary matrix $U$? Of a Hermitian matrix, $H$?\n\\end{exe}\n\\begin{sol}\n    \\emph{Polar decomposition of positive matrix $P$}: There exists unitary $U$ and positive operators $J$ and $K$ such that\n    \\begin{align}\n        P=UJ=KU,\n    \\end{align}\n    where the unique positive operators $J=\\sqrt{P^{\\dagger}P}$ and $K=\\sqrt{PP^{\\dagger}}$. Since $P$ is positive, it can be given a spectral decomposition, $P=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert$, where $\\lambda_i$ are real and $\\lambda_i\\geq 0$ $\\forall i$. In this way,\n    \\begin{align}\n        J=&\\sqrt{P^{\\dagger}P}=\\sum_i\\sqrt{\\lambda_i^*\\lambda_i}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\abs{\\lambda_i}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert=P,\\\\\n        K=&\\sqrt{PP^{\\dagger}}=\\sum_i\\sqrt{\\lambda_i\\lambda_i^*}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\abs{\\lambda_i}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert=P.\n    \\end{align}\n    If $P$ is invertible, i.e., $P$ is positive definite, then so is $J$, so $U=PJ^{-1}=I$ is unique.\\\\\n    \\emph{Polar decomposition of unitary matrix $U$}: There exists unitary $A$ and positive operators $J$ and $K$ such that\n    \\begin{align}\n        U=AJ=KA,\n    \\end{align}\n    where the unique positive operators $J=\\sqrt{U^{\\dagger}U}=I$ and $K=\\sqrt{KK^{\\dagger}}=I$. Hence $A=UJ^{-1}=U$ is unique.\\\\\n    \\emph{Polar decomposition of Hermitian matrix $H$}: There exists unitary $U$ and positive operators $J$ and $K$ such that\n    \\begin{align}\n        H=UJ=KU,\n    \\end{align}\n    where the unique positive operators $J=\\sqrt{H^{\\dagger}H}$ and $K=\\sqrt{HH^{\\dagger}}$. Since $H$ is Hermitian, it is normal. According to spectral decomposition theorem, $H$ is diagonal with respect to some orthonormal basis, i.e.,\n    \\begin{align}\n        H=A\\Lambda A^{\\dagger},\n    \\end{align}\n    where $\\Lambda$ is the matrix of eigenvalues of $H$ and $A$ is unitary. In this way,\n    \\begin{align}\n        J=&\\sqrt{H^{\\dagger}H}=\\sqrt{HH}=A\\sqrt{\\Lambda^2}A^{\\dagger},\\\\\n        K=&\\sqrt{HH^{\\dagger}}=\\sqrt{HH}=A\\sqrt{\\Lambda^2}A^{\\dagger}.\n    \\end{align}\n    If $H$ is invertible, then $U=HJ^{-1}$ is unique.\n\\end{sol}\n\n\\begin{exe}\n    Express the polar decomposition of a normal matrix in the outer product representation.\n\\end{exe}\n\\begin{sol}\n    \\emph{Polar decomposition of normal matrix in the outer products representation}: For a normal matrix $M$, there exists unitary $U$ and positive operators $J$ and $K$ such that\n    \\begin{align}\n        M=UJ=KU,\n    \\end{align}\n    where the unique operators $J=\\sqrt{M^{\\dagger}M}$ and $K=\\sqrt{MM^{\\dagger}}$. In the outer product representation,\n    \\begin{align}\n        M=\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert,\n    \\end{align}\n    so\n    \\begin{align}\n        J=&\\sum_i\\sqrt{\\lambda_i^*\\lambda_i}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\abs{\\lambda_i}\\lvert i\\rangle\\langle i\\rvert,\\\\\n        K=&\\sum_i\\sqrt{\\lambda_i\\lambda_i^*}\\lvert i\\rangle\\langle i\\rvert=\\sum_i\\abs{\\lambda_i}\\lvert i\\rangle\\langle i\\rvert.\n    \\end{align}\n    If $M$ is invertible, then\n    \\begin{align}\n        U=MJ^{-1}=\\left(\\sum_i\\lambda_i\\lvert i\\rangle\\langle i\\rvert\\right)\\left(\\sum_j\\abs{\\lambda_j}^{-1}\\lvert j\\rangle\\langle j\\rvert\\right)=\\sum_i\\frac{\\lambda_i}{\\abs{\\lambda_i}}\\lvert i\\rangle\\langle i\\rvert\n    \\end{align}\n    is also unique.\n\\end{sol}\n\n\\begin{exe}\n    Find the left and right polar decomposition of the matrix\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}.\n    \\end{align}\n\\end{exe}\n\\begin{sol}\n    Left polar decomposition:\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=UJ,\n    \\end{align}\n    where\n    \\begin{align}\n        J=\\sqrt{\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}}.\n    \\end{align}\n    Since\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&1\\\\\n            0&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix},\n    \\end{align}\n    whose characteristic equation\n    \\begin{align}\n        \\left\\lvert\\begin{matrix}\n            2-\\lambda&1\\\\\n            1&1-\\lambda\n        \\end{matrix}\\right\\rvert=\\lambda^2-3\\lambda+1=0\n    \\end{align}\n    gives eigenvalues\n    \\begin{align}\n        \\lambda_{1,2}=\\frac{3\\pm\\sqrt{5}}{2},\n    \\end{align}\n    and eigenequations\n    \\begin{align}\n        \\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix}\\lvert v_1\\rangle=&\\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            2a_1+b_1\\\\\n            a_1+b_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\frac{3+\\sqrt{5}}{2}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\\\\n        \\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix}\\lvert v_2\\rangle=&\\begin{bmatrix}\n            2&1\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\begin{bmatrix}\n            2a_2+b_2\\\\\n            a_2+b_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\frac{3-\\sqrt{5}}{2}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}\\\\\n            \\sqrt{\\frac{5-\\sqrt{5}}{10}}\n        \\end{bmatrix},\\quad\\lvert v_2\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{5-\\sqrt{5}}{10}}\\\\\n            -\\sqrt{\\frac{5+\\sqrt{5}}{10}}\n        \\end{bmatrix},\n    \\end{align}\n    we have\n    \\begin{align}\n        J=\\sqrt{\\frac{3+\\sqrt{5}}{2}}\\lvert v_1\\rangle\\langle v_1\\rvert+\\sqrt{\\frac{3-\\sqrt{5}}{2}}\\lvert v_2\\rangle\\langle v_2\\rvert\\approx\\begin{bmatrix}\n            1.3416&0.4472\\\\\n            0.4472&0.8944\n        \\end{bmatrix},\n    \\end{align}\n    and\n    \\begin{align}\n        U=\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}J^{-1}\\approx\\begin{bmatrix}\n            0.8944&-0.4472\\\\\n            0.4472&0.8944\n        \\end{bmatrix}.\n    \\end{align}\n    Right polar decomposition:\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}=KU,\n    \\end{align}\n    where\n    \\begin{align}\n        K=\\sqrt{\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}}.\n    \\end{align}\n    Since\n    \\begin{align}\n        \\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}^{\\dagger}=\\begin{bmatrix}\n            1&0\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            1&1\\\\\n            0&1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix},\n    \\end{align}\n    whose characteristic equation\n    \\begin{align}\n        \\left\\lvert\\begin{matrix}\n            1-\\lambda&1\\\\\n            1&2-\\lambda\n        \\end{matrix}\\right\\rvert=\\lambda^2-3\\lambda+1=0\n    \\end{align}\n    gives eigenvalues\n    \\begin{align}\n        \\lambda_{1,2}=\\frac{3\\pm\\sqrt{5}}{2},\n    \\end{align}\n    and eigenequations\n    \\begin{align}\n        \\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix}\\lvert v_1\\rangle=&\\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            a_1+b_1\\\\\n            a_1+2b_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\frac{3+\\sqrt{5}}{2}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\\\\n        \\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix}\\lvert v_2\\rangle=&\\begin{bmatrix}\n            1&1\\\\\n            1&2\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\begin{bmatrix}\n            a_2+b_2\\\\\n            a_2+2b_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\frac{3-\\sqrt{5}}{2}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix},\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{5-\\sqrt{5}}{10}}\\\\\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}\n        \\end{bmatrix},\\quad\\lvert v_2\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}\\\\\n            -\\sqrt{\\frac{5-\\sqrt{5}}{10}}\n        \\end{bmatrix},\n    \\end{align}\n    we have\n    \\begin{align}\n        K=\\sqrt{\\frac{3+\\sqrt{5}}{2}}\\lvert v_1\\rangle\\langle v_1\\rvert+\\sqrt{\\frac{3-\\sqrt{5}}{2}}\\lvert v_2\\rangle\\langle v_2\\rvert\\approx\\begin{bmatrix}\n            0.8944&0.4472\\\\\n            0.4472&1.3416\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\section{The postulates of quantum mechanics}\n\n\\begin{exe}\n    Verify that the Hadamard gate $H$ is unitary.\n\\end{exe}\n\\begin{pf}\n    Since\n    \\begin{align}\n        H^{\\dagger}H=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}^{\\dagger}\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I,\n    \\end{align}\n    the Hadamard gate $H$ is unitary.\n\\end{pf}\n\n\\begin{exe}\n    Verify that $H^2=I$.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        H^2=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    What are the eigenvalues and eigenvectors of $H$?\n\\end{exe}\n\\begin{sol}\n    The characteristic equation of $H$\n    \\begin{align}\n        \\left\\lvert\\begin{matrix}\n            \\frac{1}{\\sqrt{2}}-\\lambda&\\frac{1}{\\sqrt{2}}\\\\\n            \\frac{1}{\\sqrt{2}}&-\\frac{1}{\\sqrt{2}}-\\lambda\n        \\end{matrix}\\right\\rvert=\\lambda^2-1=0\n    \\end{align}\n    gives the eigenvalues\n    \\begin{align}\n        \\lambda_{1,2}=\\pm 1.\n    \\end{align}\n    The eigenequations of $H$\n    \\begin{align}\n        H\\lvert v_1\\rangle=&\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            a_1+b_1\\\\\n            a_1-b_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\\\\n        H\\lvert v_2\\rangle=&\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            1&1\\\\\n            1&-1\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            a_2+b_2\\\\\n            a_2-b_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\begin{bmatrix}\n            -a_2\\\\\n            -b_2\n        \\end{bmatrix},\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{2+\\sqrt{2}}{2}}\\\\\n            \\sqrt{\\frac{2-\\sqrt{2}}{2}}\n        \\end{bmatrix},\\quad\\lvert v_2\\rangle=\\begin{bmatrix}\n            \\sqrt{\\frac{2-\\sqrt{2}}{4}}\\\\\n            -\\sqrt{\\frac{2+\\sqrt{2}}{4}}\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Suppose $A$ and $B$ are commuting Hermitian operators. Prove that $\\exp(A)\\exp(B)=\\exp(A+B)$. (\\emph{Hint}: Use the results of Section 2.1.9.)\n\\end{exe}\n\\begin{pf}\n    Since $A$ and $B$ commute,\n    \\begin{align}\n        [A,B]=AB-BA=0\\Longrightarrow AB=BA.\n    \\end{align}\n    Hence\n    \\begin{align}\n        \\notag\\exp(A+B)=&\\sum_{n=0}^{\\infty}\\frac{(X+Y)^n}{n!}=\\sum_{n=0}^{\\infty}\\sum_{m=0}^n\\left(\\begin{matrix}\n            n\\\\\n            m\n        \\end{matrix}\\right)\\frac{A^mB^{n-m}}{n!}=\\sum_{n=0}^{\\infty}\\sum_{m=0}^n\\frac{A^mB^{n-m}}{m!(n-m)!}=\\sum_{j=0}^{\\infty}\\sum_{k=0}^{\\infty}\\frac{A^jB^k}{j!k!}\\\\\n        =&\\left(\\sum_{j=0}^{\\infty}\\frac{A^j}{j!}\\right)\\left(\\sum_{k=0}^{\\infty}\\frac{B^k}{k!}\\right)=\\exp(A)\\exp(B).\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Prove that $U(t_1,t_2)$ defined in Equation (2.91)\\footnote{$U(t_1,t_2)\\equiv\\exp\\left[\\frac{-iH(t_2-t_1)}{\\hbar}\\right]$.} is unitary.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        U(t_1,t_2)=&\\exp\\left[\\frac{-iH(t_2-t_1)}{\\hbar}\\right]=\\sum_{n=0}^{\\infty}\\frac{1}{n!}\\left[\\frac{-iH(t_2-t_1)}{\\hbar}\\right]^n,\\\\\n        \\notag[U(t_1,t_2)]^{\\dagger}=&\\sum_{n=0}^{\\infty}\\frac{1}{n!}\\left[\\frac{iH^{\\dagger}(t_2-t_1)}{\\hbar}\\right]^n=\\sum_{n=0}^{\\infty}\\frac{1}{n!}\\left[\\frac{iH(t_2-t_1)}{\\hbar}\\right]^n=\\exp\\left[\\frac{iH(t_2-t_1)}{\\hbar}\\right]=\\left\\{\\exp\\left[\\frac{-iH(t_2-t_1)}{\\hbar}\\right]\\right\\}^{-1}\\\\\n        =&[U(t_1,t_2)]^{-1}.\n    \\end{align}\n    Therefore, $U(t_1,t_2)$ is unitary.\n\\end{pf}\n\n\\begin{exe}\n    Use the spectral decomposition to show that $K=-i\\log(U)$ is Hermitian for any unitary $U$, and thus $U=\\exp(iK)$ for some Hermitian $K$.\n\\end{exe}\n\\begin{pf}\n    The spectral decomposition of $U$ in terms of outer product representation is\n    \\begin{align}\n        U=\\sum_n\\lambda_n\\lvert n\\rangle\\langle n\\rvert.\n    \\end{align}\n    Since $U$ is unitary,\n    \\begin{align}\n        U^{\\dagger}=\\sum_n\\lambda_n^*\\lvert n\\rangle\\langle n\\rvert=\\sum_n\\lambda_n^{-1}\\lvert n\\rangle\\langle n\\rvert=U^{-1},\n    \\end{align}\n    we have\n    \\begin{align}\n        \\lambda_n^*=\\lambda_n^{-1},\\quad\\forall n.\n    \\end{align}\n    The spectral decomposition of $K$ is\n    \\begin{align}\n        K=-i\\log U=\\sum_n-i\\log\\lambda_i\\lvert n\\rangle\\langle n\\rvert.\n    \\end{align}\n    Since\n    \\begin{align}\n        K^{\\dagger}=\\sum_n(-i\\log\\lambda_n)^*\\lvert n\\rangle\\langle n\\rvert=\\sum_ni\\log(\\lambda_n^*)\\lvert n\\rangle\\langle n\\rvert=\\sum_ni\\log(\\lambda_n^{-1})\\lvert n\\rangle\\langle n\\rvert=\\sum_n-i\\log\\lambda_n\\lvert n\\rangle\\langle n\\rvert=K,\n    \\end{align}\n    $K$ is Hermitian. Hence $U=\\exp(iK)$ for some Hermitian $K$.\n\\end{pf}\n\n\\begin{exe}[Cascaded measurements are single measurements]\n    Suppose $\\{L_l\\}$ and $\\{M_m\\}$ are two sets of measurement operators. Show that a measurement defined by the measurement operators $\\{L_l\\}$ followed by a measurement defined by the measurement operators $\\{M_m\\}$ is physically equivalent to a single measurement defined by measurement operators $\\{N_{lm}\\}$ with the representation $N_{ml}=M_mL_l$.\n\\end{exe}\n\\begin{pf}\n    Suppose the state of the quantum state is $\\lvert\\psi\\rangle$ immediately before the measurement. Then the probability that the result $m$ occurs in the first measurement is\n    \\begin{align}\n        p(l)=\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle,\n    \\end{align}\n    and the state of the system after the measurement is\n    \\begin{align}\n        \\frac{L_l\\lvert\\psi\\rangle}{\\sqrt{\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle}}.\n    \\end{align}\n    The probability that the result $l$ occurs in the second measurement conditional on that the result $m$ occurs in the first measurement is\n    \\begin{align}\n        p(m\\vert l)=\\frac{\\langle\\psi\\rvert L_l^{\\dagger}}{\\sqrt{\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle}}M_m^{\\dagger}M_m\\frac{L_l\\lvert\\psi\\rangle}{\\sqrt{\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle}}=\\frac{\\langle\\psi\\rvert L_l^{\\dagger}M_m^{\\dagger}M_mL_l\\lvert\\psi\\rangle}{\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle},\n    \\end{align}\n    and the state of the system after the two measurements is\n    \\begin{align}\n        \\frac{M_mL_l\\lvert\\psi\\rangle}{\\sqrt{\\frac{\\langle\\psi\\rvert L_l^{\\dagger}M_m^{\\dagger}M_mL_l\\lvert\\psi\\rangle}{\\langle\\psi\\rvert L_l^{\\dagger}L_l\\lvert\\psi\\rangle}}}\n    \\end{align}\n    Hence the probability that the result $m$ occurs in the first measurement and the result $l$ occurs in the second measurement is\n    \\begin{align}\n        p(l,m)=p(l)p(m\\vert l)=\\langle\\psi\\rvert L_l^{\\dagger}M_m^{\\dagger}M_mL_l\\lvert\\psi\\rangle.\n    \\end{align}\n    Therefore, a measurement defined by the measurement operators $\\{L_l\\}$ followed by a measurement defined by the measurement $\\{M_m\\}$ is physically equivalent to a single measurement defined by measurement operators $\\{N_{lm}\\}$ with the representation $N_{ml}=M_mL_l$.\n\\end{pf}\n\n\\begin{exe}\n    Suppose we prepare a quantum system in an eigenstate $\\lvert\\psi\\rangle$ of some observable $M$, with corresponding eigenvalue $m$. What is the average observed value of $M$, and the standard deviation?\n\\end{exe}\n\\begin{sol}\n    The average observed value of $M$ is\n    \\begin{align}\n        \\langle M\\rangle=\\langle\\psi\\rvert M\\lvert\\psi\\rangle=\\langle\\psi\\rvert m\\lvert\\rangle=m.\n    \\end{align}\n    The average observed value of $M^2$ is\n    \\begin{align}\n        \\langle M^2\\rangle=\\langle\\psi\\rvert M^2\\lvert\\psi\\rangle=\\langle\\psi\\rvert m^2\\lvert\\psi\\rangle=m^2.\n    \\end{align}\n    The standard deviation of $M$ is\n    \\begin{align}\n        [\\Delta(M)]^2=\\langle M^2\\rangle-\\langle M\\rangle^2=0.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Suppose we have qubit in the state $\\lvert 0\\rangle$, and we measure the observable $X$. What is the average value of $X$? What is the standard deviation of $X$?\n\\end{exe}\n\\begin{sol}\n    The average value of $X$ is\n    \\begin{align}\n        \\langle 0\\rvert X\\lvert 0\\rangle=\\begin{bmatrix}\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            1\\\\\n            0\n        \\end{bmatrix}=0.\n    \\end{align}\n    The average value of $X^2$ is\n    \\begin{align}\n        \\langle 0\\rvert X^2\\lvert 0\\rangle=\\begin{bmatrix}\n            1&0\n        \\end{bmatrix}\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}^2\\begin{bmatrix}\n            1\\\\\n            0\n        \\end{bmatrix}=1.\n    \\end{align}\n    The standard deviation of $X$ is\n    \\begin{align}\n        [\\Delta(X)]^2=\\langle X^2\\rangle-\\langle X\\rangle^2=1.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Show that $\\vec{v}\\cdot\\vec{\\sigma}$ has eigenvalues $\\pm 1$, and that the projectors onto the corresponding eigenspaces are given by $P_{\\pm}=(I\\pm\\vec{v}\\cdot\\vec{\\sigma})/2$.\n\\end{exe}\n\\begin{pf}\n    \\begin{align}\n        \\vec{v}\\cdot\\vec{\\sigma}=v_1\\sigma_1+v_2\\sigma_2+v_3\\sigma_3=v_1\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}+v_2\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}+v_3\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            v_3&v_1-iv_2\\\\\n            v_1+iv_2&-v_3\n        \\end{bmatrix}.\n    \\end{align}\n    The characteristic equation of $\\vec{v}\\cdot\\vec{\\sigma}$\n    \\begin{align}\n        \\lvert\\vec{v}\\cdot\\vec{\\sigma}-\\lambda I\\rvert=\\left\\lvert\\begin{matrix}\n            v_3-\\lambda&v_1-iv_2\\\\\n            v_1+iv_2&-v_3-\\lambda\n        \\end{matrix}\\right\\rvert=\\lambda^2-v_1^2-v_2^2-v_3^2=\\lambda^2-1=0\n    \\end{align}\n    gives the eigenvalues\n    \\begin{align}\n        \\lambda_{1,2}=\\pm 1.\n    \\end{align}\n    The eigenequations\n    \\begin{align}\n        (\\vec{v}\\cdot\\vec{\\sigma})\\lvert v_1\\rangle=&\\begin{bmatrix}\n            v_3&v_1-iv_2\\\\\n            v_1+iv_2&-v_3\n        \\end{bmatrix}\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix}=\\begin{bmatrix}\n            v_3a_1+(v_1-iv_2)b_1\\\\\n            (v_1+iv_2)a_1-v_3b_1\n        \\end{bmatrix}=\\lambda_1\\lvert v_1\\rangle=\\begin{bmatrix}\n            a_1\\\\\n            b_1\n        \\end{bmatrix},\\\\\n        (\\vec{v}\\cdot\\vec{\\sigma})\\lvert v_2\\rangle=&\\begin{bmatrix}\n            v_3&v_1-iv_2\\\\\n            v_1+iv_2&-v_3\n        \\end{bmatrix}\\begin{bmatrix}\n            a_2\\\\\n            b_2\n        \\end{bmatrix}=\\begin{bmatrix}\n            v_3a_2+(v_1-iv_2)b_2\\\\\n            (v_1+iv_2)a_2-v_3b_2\n        \\end{bmatrix}=\\lambda_2\\lvert v_2\\rangle=\\begin{bmatrix}\n            -a_2\\\\\n            -b_2\n        \\end{bmatrix}\n    \\end{align}\n    give the corresponding eigenvectors\n    \\begin{align}\n        \\lvert v_1\\rangle=\\frac{1}{\\sqrt{2(1+v_3)}}\\begin{bmatrix}\n            1+v_3\\\\\n            v_1+iv_2\n        \\end{bmatrix},\\quad\\lvert v_2\\rangle=\\frac{1}{\\sqrt{2(1-v_3)}}\\begin{bmatrix}\n            v_3-1\\\\\n            v_1+iv_2\n        \\end{bmatrix}.\n    \\end{align}\n    The projectors onto the corresponding eigensapces are\n    \\begin{align}\n        \\notag P_+=&\\lvert v_1\\rangle\\langle v_1\\rvert=\\frac{1}{\\sqrt{2(1+v_3)}}\\begin{bmatrix}\n            1+v_3\\\\\n            v_1+iv_2\n        \\end{bmatrix}\\frac{1}{\\sqrt{2(1+v_3)}}\\begin{bmatrix}\n            1+v_3&v_1-iv_2\n        \\end{bmatrix}\\\\\n        \\notag=&\\frac{1}{2(1+v_3)}\\begin{bmatrix}\n            (1+v_3)^2&(1+v_3)(v_1-iv_2)\\\\\n            (v_1+iv_2)(1+v_3)&(v_1+iv_2)(v_1-iv_2)\n        \\end{bmatrix}=\\frac{1}{2(1+v_3)}\\begin{bmatrix}\n            (1+v_3)^2&(1+v_3)(v_1-iv_2)\\\\\n            (v_1+iv_2)(1+v_3)&(1+v_3)(1-v_3)\n        \\end{bmatrix}\\\\\n        =&\\frac{1}{2}\\begin{bmatrix}\n            1+v_3&v_1-iv_2\\\\\n            v_1+iv_2&1-v_3\n        \\end{bmatrix}=(I+\\vec{v}\\cdot\\vec{\\sigma})/2,\\\\\n        \\notag P_-=&\\lvert v_2\\rangle\\langle v_2\\rvert=\\frac{1}{\\sqrt{2(1-v_3)}}\\begin{bmatrix}\n            v_3-1\\\\\n            v_1+iv_2\n        \\end{bmatrix}\\frac{1}{\\sqrt{2(1-v_3)}}\\begin{bmatrix}\n            v_3-1&v_1-iv_2\n        \\end{bmatrix}\\\\\n        \\notag=&\\frac{1}{2(1-v_3)}\\begin{bmatrix}\n            (v_3-1)^2&(v_3-1)(v_1-iv_2)\\\\\n            (v_1+iv_2)(v_3-1)&(v_1+iv_2)(v_1-iv_2)\n        \\end{bmatrix}=\\frac{1}{2(1-v_3)}\\begin{bmatrix}\n            (1-v_3)^2&-(1-v_3)(v_1-iv_2)\\\\\n            -(v_1+iv_2)(1-v_3)&(1+v_3)(1-v_3)\n        \\end{bmatrix}\\\\\n        =&\\frac{1}{2}\\begin{bmatrix}\n            1-v_3&-(v_1-iv_2)\\\\\n            v_1+iv_2&1+v_3\n        \\end{bmatrix}=(I-\\vec{v}\\cdot\\vec{\\sigma})/2.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Calculate the probability of obtaining the result $+1$ for a measurement of $\\vec{v}\\cdot\\vec{\\sigma}$, given that the state priori to measurement is $\\lvert 0\\rangle$. What is the state of the system after the measurement if $+1$ is obtained?\n\\end{exe}\n\\begin{sol}\n    The probability of obtaining $+1$ for a measurement of $\\vec{v}\\cdot\\vec{\\sigma}$ is\n    \\begin{align}\n        p(1)=\\langle 0\\rvert P_+\\lvert 0\\rangle=\\begin{bmatrix}\n            1&0\n        \\end{bmatrix}\\frac{1}{2}\\begin{bmatrix}\n            1-v_3&-(v_1-iv_2)\\\\\n            v_1+iv_2&1+v_3\n        \\end{bmatrix}\\begin{bmatrix}\n            1\\\\\n            0\n        \\end{bmatrix}=\\frac{1-v_3}{2}.\n    \\end{align}\n    The state of the system after the measurement if $+1$ is obtained is\n    \\begin{align}\n        \\lvert v_1\\rangle=\\frac{1}{\\sqrt{2(1+v_3)}}\\begin{bmatrix}\n            1+v_3\\\\\n            v_1+iv_2\n        \\end{bmatrix}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Show that any measurement where the measurement operators and the POVM elements coincide is a projective measurement.\n\\end{exe}\n\\begin{pf}\n    Consider a measurement whose measurement operators $\\{M_m\\}$ coincide with POVM elements $\\{E_m=M_m^{\\dagger}M_m\\}$,\n    \\begin{align}\n        E_m=M_m^{\\dagger}M_m=M_m.\n    \\end{align}\n    Since\n    \\begin{align}\n        M_m=E_m^{\\dagger}=M_m^{\\dagger}M_m=E_m=M_m,\n    \\end{align}\n    $\\{M_m\\}$ are Hermitian. Hence\n    \\begin{align}\n        M_m^{\\dagger}M_m=M_m^2=M_m,\n    \\end{align}\n    $\\{M_m\\}$ are projectors and this measurement is a projective measurement.\n\\end{pf}\n\n\\begin{exe}\n    Suppose a measurement is described by measurement operators $M_m$. Show that there exists unitary operators $U_m$ such that $M_m=U_m\\sqrt{E_m}$, where $E_m$ is the POVM associated to the measurement.\n\\end{exe}\n\\begin{pf}\n    Since $U_m$ is unitary and the POVM measurement operators $E_m$ is Hermitian,\n    \\begin{align}\n        M_m^{\\dagger}M_m=\\sqrt{E_m^{\\dagger}}U_m^{\\dagger}U_m\\sqrt{E_m}=\\sqrt{E_m}U_m^{-1}U_m\\sqrt{E_m}=E_m.\n    \\end{align}\n    Therefore, there exists unitary operators $U_m$ such that $M_m=U_m\\sqrt{E_m}$, where $E_m$ is the POVM associated to the measurement.\n\\end{pf}\n\n\\begin{exe}\n    Suppose Bob is given a quantum state chosen from a set $\\lvert\\psi_1\\rangle,\\cdots,\\lvert\\psi_m\\rangle$ of linearly independent states. Construct a POVM $\\{E_1,E_2,\\cdots,E_{m+1}\\}$ such that if outcome $E_i$ occurs, $1\\leq i\\leq m$, then Bob knows with certainty that he was given the state $\\lvert\\psi_i\\rangle$. (The POVM must be such that $\\langle\\psi_i\\rvert E_i\\lvert\\psi_i\\rangle>0$ for each $i$.)\n\\end{exe}\n\\begin{sol}\n    For each $1\\leq i\\leq m$, using Gram-Schmidt procedure to produce the orthonormal basis set $\\lvert\\phi_1^{(i)}\\rangle,\\lvert\\phi_2^{(i)}\\rangle,\\cdots,\\lvert\\phi_{i-1}^{(i)}\\rangle,\\lvert\\phi_{i+1}^{(i)}\\rangle,\\cdots,\\lvert\\phi_m\\rangle$ from $\\lvert\\psi_1\\rangle,\\lvert\\psi_2\\rangle,\\cdots,\\lvert\\psi_{i-1}\\rangle,\\lvert\\psi_{i+1}\\rangle,\\cdots,\\lvert\\psi_m\\rangle$, and then\n    \\begin{align}\n        E_m=\\frac{\\left(\\lvert\\psi_i\\rangle-\\sum_{j\\neq i}\\langle\\psi_i\\vert\\phi_j^{(i)}\\rangle\\lvert\\phi_j^{(i)}\\rangle\\right)\\left(\\langle\\psi_i\\rvert-\\sum_{j\\neq i}\\langle\\phi_j^{(i)}\\vert\\psi_i\\rangle\\langle\\phi_j^{(i)}\\rvert\\right)}{\\abs{\\lvert\\psi_i\\rangle-\\sum_{j\\neq i}\\langle\\psi_i\\vert\\phi_j^{(i)}\\rangle\\lvert\\phi_j^{(i)}\\rangle}^2}.\n    \\end{align}\n    For $i=m+1$,\n    \\begin{align}\n        E_{m+1}=I-\\sum_{i=1}^mE_m.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Express the states $(\\lvert 0\\rangle+\\lvert 1\\rangle)/\\sqrt{2}$ and $(\\lvert 0\\rangle-\\lvert 1\\rangle)/\\sqrt{2}$ in a basis in which they are not the same up to a relative phase shift.\n\\end{exe}\n\\begin{sol}\n    In the basis $\\{\\lvert 0\\rangle,\\lvert 1\\rangle\\}$,\n    \\begin{align}\n        \\frac{\\lvert 0\\rangle+\\lvert 1\\rangle}{\\sqrt{2}}=&\\frac{1}{\\sqrt{2}}\\lvert 0\\rangle+\\frac{1}{\\sqrt{2}}\\lvert 1\\rangle,\\\\\n        \\frac{\\lvert 0\\rangle-\\lvert 1\\rangle}{\\sqrt{2}}=&\\frac{1}{\\sqrt{2}}\\lvert 0\\rangle+\\frac{1}{\\sqrt{2}}e^{i\\pi}\\lvert 1\\rangle,\n    \\end{align}\n    which are not the same up to a relative phase shift.\n\\end{sol}\n\n\\begin{exe}\n    Show that the average value of the observable $X_1Z_2$ for a two qubit system measured in the state $(\\lvert 00\\rangle+\\lvert 11\\rangle)/\\sqrt{2}$ is zero.\n\\end{exe}\n\\begin{pf}\n    The average value of the observable $X_1Z_2$ for a two qubit system measured in the state $(\\lvert 00\\rangle+\\lvert 11\\rangle)/\\sqrt{2}$ is\n    \\begin{align}\n        \\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}X_1Z_2\\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}=\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}X_1\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}=\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 10\\rangle-\\lvert 01\\rangle}{\\sqrt{2}}=0.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose $V$ is Hilbert space with a subspace $W$. Suppose $U:W\\rightarrow V$ is linear operator which preserves inner products, that is, for any $\\lvert w_1\\rangle$ and $\\lvert w_2\\rangle$ in $W$,\n    \\begin{align}\n        \\langle w_1\\rvert U^{\\dagger}U\\lvert w_2\\rangle=\\langle w_1\\vert w_2\\rangle.\n    \\end{align}\n    Prove that there exists a unitary operator $U':V\\rightarrow V$ which extends $U$. That is, $U'\\lvert w\\rangle=U\\lvert w\\rangle$ for all $\\lvert w\\rangle$ in $W$, but $U'$ is defined on the entire space $V$. Usually we omit the prime symbol $'$ and just write $U$ to decode the extension.\n\\end{exe}\n\\begin{pf}\n    Define\n    \\begin{align}\n        U'\\equiv U\\otimes A,\n    \\end{align}\n    where the unitary operator $A:U-W\\rightarrow\\im(U)^{\\perp}$.\n    Since both $U$ and $A$ are unitary, $U'$ is unitary.\n    For all $\\lvert w\\rangle$ in $V$, we can express it as\n    \\begin{align}\n        \\lvert w\\rangle=\\lvert w_1\\rangle\\otimes\\lvert w_2\\rangle,\n    \\end{align}\n    where $\\lvert w_1\\rangle$ and $\\lvert w_2\\rangle$ are in the image of $U$, $\\im(U)$, and the complement of the image of U, $\\im(U)^{\\perp}=W-\\im(U)$, respectively, and then\n    \\begin{align}\n        U'\\lvert w\\rangle=(U\\otimes A)(\\lvert w_1\\rangle\\otimes\\lvert w_2\\rangle)=(U\\lvert w_1\\rangle)\\otimes(A\\lvert w_2\\rangle).\n    \\end{align}\n    Specially, for all $\\lvert w\\rangle$ in $W$, we can extend it as\n    \\begin{align}\n        \\lvert w'\\rangle=\\lvert w\\rangle\\otimes\\lvert 0\\rangle\\in V\n    \\end{align}\n    where $\\im(U)^{\\perp}$ is the zero vector in $V-W$,\n    and then\n    \\begin{align}\n        U'\\lvert w'\\rangle=(U\\otimes A)(\\lvert w\\rangle\\otimes\\lvert 0\\rangle)=U\\lvert w\\rangle\\otimes\\lvert 0\\rangle\n    \\end{align}\n    Therefore, there exists a unitary $U':V\\rightarrow V$ which extends $U$.\n\\end{pf}\n\n\\begin{exe}\n    Prove that $\\lvert\\psi\\rangle\\neq\\lvert a\\rangle\\lvert b\\rangle$ for all single qubit states $\\lvert a\\rangle$ and $\\lvert b\\rangle$.\n\\end{exe}\n\\begin{pf}\n    Suppose\n    \\begin{align}\n        \\lvert a\\rangle=&a_0\\lvert 0\\rangle+a_1\\lvert 1\\rangle,\\\\\n        \\lvert b\\rangle=&b_0\\lvert 0\\rangle+b_1\\lvert 1\\rangle,\n    \\end{align}\n    where the normalization condition requires that\n    \\begin{align}\n        \\abs{a_0}^2+\\abs{a_1}^2=&1,\\\\\n        \\abs{b_0}^2+\\abs{b_1}^2=&1.\n    \\end{align}\n    If\n    \\begin{align}\n        \\label{E2.68}\n        \\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}=\\lvert\\psi\\rangle=\\lvert a\\rangle\\lvert b\\rangle=a_0b_0\\lvert 00\\rangle+a_0b_1\\lvert 01\\rangle+a_1b_0\\lvert 10\\rangle+a_1b_1\\lvert 11\\rangle,\n    \\end{align}\n    then\n    \\begin{align}\n        \\label{E2.68-1}a_0b_0=&\\frac{1}{\\sqrt{2}},\\\\\n        \\label{E2.68-2}a_0b_1=&0,\\\\\n        \\label{E2.68-3}a_1b_0=&0,\\\\\n        \\label{E2.68-4}a_1b_1=&\\frac{1}{\\sqrt{2}}.\n    \\end{align}\n    Equation \\eqref{E2.68-1} and \\eqref{E2.68-4} means that none of $a_0$, $a_1$, $b_0$ and $b_1$ equals $0$, which conflicts with Equations \\eqref{E2.68-2} and \\eqref{E2.68-3}.\n    Therefore, Equation \\eqref{E2.68} is impossible and $\\lvert\\psi\\rangle\\neq\\lvert a\\rangle\\lvert b\\rangle$ for all single qubit states $\\lvert a\\rangle$ and $\\lvert b\\rangle$.\n\\end{pf}\n\n\\section{Application: superdense coding}\n\n\\begin{exe}\n    Verify that the Bell basis forms an orthonormal basis for the two qubit state space.\n\\end{exe}\n\\begin{pf}\n    The Bell basis satisfies that:\n    \\begin{itemize}\n        \\item[(a)] The Bell basis is normalized,\n        \\begin{align}\n            \\abs{\\lvert\\beta_{00}\\rangle}=&\\sqrt{\\langle\\beta_{00}\\vert\\beta_{00}\\rangle}=\\sqrt{\\frac{\\langle 00\\rvert+\\langle 00\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}}=1,\\\\\n            \\abs{\\lvert\\beta_{01}\\rangle}=&\\sqrt{\\langle\\beta_{01}\\vert\\beta_{01}\\rangle}=\\sqrt{\\frac{\\langle 01\\rvert+\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{2}}}=1,\\\\\n            \\abs{\\lvert\\beta_{10}\\rangle}=&\\sqrt{\\langle\\beta_{10}\\vert\\beta_{10}\\rangle}=\\sqrt{\\frac{\\langle 00\\rvert-\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}}=1,\\\\\n            \\abs{\\lvert\\beta_{11}\\rangle}=&\\sqrt{\\langle\\beta_{11}\\vert\\beta_{11}\\rangle}=\\sqrt{\\frac{\\langle 01\\rvert-\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}}=1.\n        \\end{align}\n        \\item[(b)] The Bell basis is orthogonal,\n        \\begin{align}\n            \\langle\\beta_{00}\\vert\\beta_{01}\\rangle=&\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{2}}=0,\\\\\n            \\langle\\beta_{00}\\vert\\beta_{10}\\rangle=&\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}=0,\\\\\n            \\langle\\beta_{00}\\vert\\beta_{11}\\rangle=&\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}=0,\\\\\n            \\langle\\beta_{01}\\vert\\beta_{10}\\rangle=&\\frac{\\langle 01\\rvert+\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}=0,\\\\\n            \\langle\\beta_{01}\\vert\\beta_{11}\\rangle=&\\frac{\\langle 01\\rvert+\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}=0,\\\\\n            \\langle\\beta_{10}\\vert\\beta_{11}\\rangle=&\\frac{\\langle 00\\rvert-\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}=0,\n        \\end{align}\n        and thus also linearly independent.\n        \\item[(c)] The dimension of the two qubit state space is $2\\times 2=4$, the Bell basis also has $4$ independent elements, so the Bell basis can span the two qubit space.\n    \\end{itemize}\n    Therefore, the Bell basis forms an orthonormal basis for the two qubit state space.\n\\end{pf}\n\n\\begin{exe}\n    Suppose $E$ is any positive operator acting on Alice's qubit. Show that $\\langle\\psi\\rvert E\\otimes I\\lvert\\psi\\rangle$ \\emph{takes the same value} when $\\lvert\\psi\\rangle$ is any of the four Bell states. Suppose some malevolent third party (`Eve') intercepts Alice's qubit on the way to Bob in the superdense coding protocol. Can Eve infer anything about which of the four possible bit strings $00$, $01$, $10$, $11$ Alice is trying to send? If so, how, or if not, why not?\n\\end{exe}\n\\begin{pf}\n    $\\langle\\psi\\rvert E\\otimes I\\lvert\\psi\\rangle$ takes the same value when $\\lvert\\psi\\rangle$ is any of the four Bell states,\n    \\begin{align}\n        \\notag\\langle\\beta_{00}\\rvert E\\otimes I\\lvert\\beta_{00}\\rangle=&\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}=\\frac{1}{2}(\\langle 00\\rvert E\\otimes I\\lvert 00\\rangle+\\langle 00\\rvert E\\otimes I\\lvert 11\\rangle+\\langle 11\\rvert E\\otimes I\\lvert 00\\rangle+\\langle 11\\rvert E\\otimes I\\lvert 11\\rangle)\\\\\n        =&\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle\\langle 0\\rvert I\\lvert 0\\rangle+\\langle 0\\rvert E\\lvert 1\\rangle\\langle 0\\rvert I\\lvert 1\\rangle+\\langle 1\\rvert E\\lvert 0\\rangle\\langle 1\\rvert I\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle\\langle 1\\rvert I\\lvert 1\\rangle)=\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle),\\\\\n        \\notag\\langle\\beta_{01}\\rvert E\\otimes I\\lvert\\beta_{01}\\rangle=&\\frac{\\langle 01\\rvert+\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{2}}=\\frac{1}{2}(\\langle 01\\rvert E\\otimes I\\lvert 01\\rangle+\\langle 01\\rvert E\\otimes I\\lvert 10\\rangle+\\langle 10\\rvert E\\otimes I\\lvert 01\\rangle+\\langle 10\\rvert E\\otimes I\\lvert 10\\rangle)\\\\\n        =&\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle\\langle 1\\rvert I\\lvert 1\\rangle+\\langle 0\\rvert E\\lvert 1\\rangle\\langle 1\\rvert I\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 0\\rangle\\langle 0\\rvert I\\lvert 1\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle\\langle 0\\rvert I\\lvert 0\\rangle)=\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle),\\\\\n        \\notag\\langle\\beta_{10}\\rvert E\\otimes I\\lvert\\beta_{10}\\rangle=&\\frac{\\langle 00\\rvert-\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}=\\frac{1}{2}(\\langle 00\\rvert E\\otimes I\\lvert 00\\rangle-\\langle 00\\rvert E\\otimes I\\lvert 11\\rangle-\\langle 11\\rvert E\\otimes I\\lvert 00\\rangle+\\langle 11\\rvert E\\otimes I\\lvert 11\\rangle)\\\\\n        =&\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle\\langle 0\\rvert I\\lvert 0\\rangle-\\langle 0\\rvert E\\lvert 1\\rangle\\langle 0\\rvert I\\lvert 1\\rangle-\\langle 1\\rvert E\\lvert 0\\rangle\\langle 1\\rvert I\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle\\langle 1\\rvert I\\lvert 1\\rangle)=\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle),\\\\\n        \\notag\\langle\\beta_{11}\\rvert E\\otimes I\\lvert\\beta_{11}\\rangle=&\\frac{\\langle 01\\rvert-\\langle 10\\rvert}{\\sqrt{2}}\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}=\\frac{1}{2}(\\langle 01\\rvert E\\otimes I\\lvert 01\\rangle-\\langle 01\\rvert E\\otimes I\\lvert 10\\rangle-\\langle 10\\rvert E\\otimes I\\lvert 01\\rangle+\\langle 10\\rvert E\\otimes I\\lvert 10\\rangle)\\\\\n        =&\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle\\langle 1\\rvert I\\lvert 1\\rangle-\\langle 0\\rvert E\\lvert 1\\rangle\\langle 1\\rvert I\\lvert 0\\rangle-\\langle 1\\rvert E\\lvert 0\\rangle\\langle 0\\rvert I\\lvert 1\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle\\langle 0\\rvert I\\lvert 0\\rangle)=\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle).\n    \\end{align}\n    Eve can not infer anything about which of the four possible bit string Alice is trying to send. Here is the reason:\n    Suppose Eve intercepts Alice's qubit and try to do some measurement on it. Whichever of the four possible bit string $00$, $01$, $10$, $11$ Alice is trying to send, Eve will get result $m$ with the same possibility\n    \\begin{align}\n        p(m)=\\frac{1}{2}(\\langle 0\\rvert E\\lvert 0\\rangle+\\langle 1\\rvert E\\lvert 1\\rangle).\n    \\end{align}\n    In this way, Eve can not obtain any knowledge about the bit string Alice is trying to send from the measurement result.\n\\end{pf}\n\n\\section{The density operator}\n\n\\begin{exe}[Criterion of decide if a state is mixed or pure]\n    Let $\\rho$ be a density operator. Show that $\\tr(\\rho^2)\\leq 1$, with equality if and only if $\\rho$ is a pure state.\n\\end{exe}\n\\begin{pf}\n    The density operator is\n    \\begin{align}\n        \\rho=\\sum_ip_i\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert,\n    \\end{align}\n    so\n    \\begin{align}\n        \\notag\\tr(\\rho^2)=&\\tr\\left[\\left(\\sum_ip_i\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert\\right)\\left(\\sum_jp_j\\lvert\\psi_j\\rangle\\langle\\psi_j\\rvert\\right)\\right]=\\sum_ip_i\\left[\\sum_jp_j\\tr(\\lvert\\psi_i\\rangle\\langle\\psi_i\\vert\\psi_j\\rangle\\langle\\psi_j\\rvert)\\right]\\\\\n        \\notag=&\\sum_ip_i\\left[\\sum_jp_j\\tr(\\langle\\psi_i\\vert\\psi_j\\rangle\\langle\\psi_j\\vert\\psi_i\\rangle)\\right]=\\sum_ip_i\\left[\\sum_jp_j\\tr(\\abs{\\langle\\psi_i\\vert\\psi_j\\rangle}^2)\\right]=\\sum_ip_i\\left[\\sum_jp_j\\abs{\\langle\\psi_i\\vert\\psi_j\\rangle}^2\\right]\\\\\n        \\leq&\\sum_ip_i\\left(\\sum_jp_j\\right)=\\sum_ip_i=1.\n    \\end{align}\n    If $\\rho$ is a pure state,\n    \\begin{align}\n        \\rho=\\lvert\\psi\\rangle\\langle\\psi\\rvert,\n    \\end{align}\n    then\n    \\begin{align}\n        \\tr(\\rho^2)=\\tr(\\lvert\\psi\\rangle\\langle\\psi\\vert\\psi\\rangle\\langle\\psi\\rvert)=\\tr(\\lvert\\psi\\rangle\\langle\\psi\\rvert)=1.\n    \\end{align}\n    If $\\tr(\\rho^2)=1$, then\n    \\begin{gather}\n        \\sum_ip_i\\left[\\sum_jp_j\\abs{\\langle\\psi_i\\vert\\psi_j\\rangle}^2\\right]=\\sum_ip_i\\left(\\sum_jp_j\\right),\\\\\n        \\Longrightarrow\\abs{\\langle\\psi_i\\vert\\psi_j\\rangle}^2=\\abs{\\langle\\psi_i\\vert\\psi_i\\rangle}^2=1,\n    \\end{gather}\n    which means that, for all $i$ and $j$, $\\lvert\\psi_i\\rangle$ and $\\lvert\\psi_j\\rangle$ is the same up to a phase difference\n    \\begin{align}\n        \\lvert\\psi_j\\rangle=e^{i\\theta_{ij}}\\lvert\\psi_i\\rangle,\\quad\\forall i,j,\n    \\end{align}\n    i.e., $\\rho$ must be a pure state\n    \\begin{align}\n        \\rho=\\lvert\\psi_1\\rangle\\langle\\psi_1\\rvert.\n    \\end{align}\n    Therefore, $\\tr(\\rho^2)\\leq 1$, with equality if and only if $\\rho$ is a pure state.\n\\end{pf}\n\n\\begin{exe}[Bloch sphere for mixed states]\n    The Bloch sphere picture for pure states of a single qubit was introduced in Section 1.2. This description has an important generalization to mixed states as follows.\n    \\begin{itemize}\n        \\item[(1)] Show that an arbitrary density matrix for a mixed state qubit may be written as\n        \\begin{align}\n            \\rho=\\frac{I+\\vec{r}\\cdot\\vec{\\sigma}}{2},\n        \\end{align}\n        where $\\vec{r}$ is a real three-dimensional vector such that $\\norm{\\vec{r}}\\leq 1$. This vector is known as the \\emph{Bloch vector} for the state $\\rho$.\n        \\item[(2)] What is the Bloch vector representation for the state $\\rho=I/2$?\n        \\item[(3)] Show that a state $\\rho$ is pure if and only if $\\norm{\\vec{r}}=1$.\n        \\item[(4)] Show that for pure states the description of the Bloch vector we have given coincide with that in Section 1.2.\n    \\end{itemize}\n\\end{exe}\n\\begin{sol}\n    \\item[(1)] An arbitrary $2\\times 2$ matrix $\\rho$ can be expressed as a linear combination of $I$, $\\sigma_1$, $\\sigma_2$, $\\sigma_3$,\n    \\begin{align}\n        \\notag\\rho=&\\begin{bmatrix}\n            \\rho_{11}&\\rho_{12}\\\\\n            \\rho_{21}&\\rho_{22}\n        \\end{bmatrix}=\\begin{bmatrix}\n            \\frac{1}{2}(\\rho_{11}+\\rho_{22})+\\frac{1}{2}(\\rho_{11}-\\rho_{22})&\\frac{1}{2}(\\rho_{12}+\\rho_{21})+i(-i)\\frac{1}{2}(\\rho_{12}-\\rho_{21})\\\\\n            \\frac{1}{2}(\\rho_{12}+\\rho_{21})+i\\cdot i(\\rho_{12}-\\rho_{21})&\\frac{1}{2}(\\rho_{11}+\\rho_{22})-\\frac{1}{2}(\\rho_{11}-\\rho_{22})\n        \\end{bmatrix}\\\\\n        \\notag=&\\frac{1}{2}(\\rho_{11}+\\rho_{22})\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}+\\frac{1}{2}(\\rho_{12}+\\rho_{21})\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}+\\frac{i}{2}(\\rho_{12}-\\rho_{21})\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}+\\frac{1}{2}(\\rho_{11}-\\rho_{22})\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}\\\\\n        =&\\frac{1}{2}(\\rho_{11}+\\rho_{22})I+\\frac{1}{2}(\\rho_{12}+\\rho_{21})\\sigma_1+\\frac{i}{2}(\\rho_{12}-\\rho_{21})\\sigma_2+\\frac{1}{2}(\\rho_{11}-\\rho_{22})\\sigma_3\n    \\end{align}\n    If $\\rho$ is an arbitrary density matrix, then it has trace of $1$,\n    \\begin{align}\n        \\tr(\\rho)=\\rho_{11}+\\rho_{22}=1,\n    \\end{align}\n    so\n    \\begin{align}\n        \\rho=\\frac{1}{2}I+\\frac{1}{2}(\\rho_{12}+\\rho_{21})\\sigma_1+\\frac{i}{2}(\\rho_{12}-\\rho_{21})\\sigma_2+\\frac{1}{2}(\\rho_{11}-\\rho_{22})\\sigma_3=\\frac{I+\\vec{r}\\cdot\\vec{\\sigma}}{2},\n    \\end{align}\n    where\n    \\begin{align}\n        \\vec{r}=(r_1,r_2,r_3)=(\\rho_{12}+\\rho_{21},i(\\rho_{12}-\\rho_{21}),\\rho_{11}-\\rho_{22}).\n    \\end{align}\n    \\item[(2)] For the state\n    \\begin{align}\n        \\rho=\\frac{I}{2}=\\frac{I+\\vec{r}\\cdot\\vec{\\sigma}}{2},\n    \\end{align}\n    the Bloch vector representation is\n    \\begin{align}\n        \\vec{r}=(0,0,0)=\\vec{0}.\n    \\end{align}\n    \\item[(3)] \\emph{Necessity}: If $\\norm{\\vec{r}}=1$, then\n    \\begin{align}\n        \\label{E2.72-1}\n        \\norm{\\vec{r}}^2=r_1r_1^*+r_2r_2^*+r_3r_3^*=(\\rho_{12}+\\rho_{21})(\\rho_{12}+\\rho_{21})^*+(\\rho_{12}-\\rho_{21})(\\rho_{12}-\\rho_{21})^*+(\\rho_{11}-\\rho_{22})(\\rho_{11}-\\rho_{22})^*=1.\n    \\end{align}\n    Since the density matrix $\\rho$ is positive, it is necessarily Hermitian, i.e., $\\rho_{11}$ and $\\rho_{22}$ are real and $\\rho_{12}$ and $\\rho_{21}$ are complex conjugate,\n    \\begin{align}\n        \\rho_{12}=\\rho_{21}^*.\n    \\end{align}\n    Hence we can rewrite Equation \\eqref{E2.72-1} as\n    \\begin{align}\n        \\label{E2.72-2}\n        (\\rho_{12}+\\rho_{21})(\\rho_{21}+\\rho_{12})+(\\rho_{12}-\\rho_{21})(\\rho_{21}-\\rho_{12})+(\\rho_{11}-\\rho_{22})(\\rho_{11}-\\rho_{22})^*=4\\rho_{12}\\rho_{21}+\\rho_{11}^2+\\rho_{22}^2-2\\rho_{11}\\rho_{22}=1.\n    \\end{align}\n    Since the trace of the density matrix $\\rho$ is $1$,\n    \\begin{align}\n        \\tr(\\rho)=\\rho_{11}+\\rho_{22}=1,\n    \\end{align}\n    we can rewrite Equation \\eqref{E2.72-2} as\n    \\begin{gather}\n        4\\rho_{12}\\rho_{21}+2(\\rho_{11}^2+\\rho_{22}^2)-(\\rho_{11}^2+\\rho_{22}^2+2\\rho_{11}\\rho_{22})=4\\rho_{12}\\rho_{21}+2(\\rho_{11}^2+\\rho_{22}^2)-(\\rho_{11}+\\rho_{22})^2=4\\rho_{12}\\rho_{21}+2(\\rho_{11}^2+\\rho_{22}^2)-1=1,\\\\\n        \\Longrightarrow 2\\rho_{12}\\rho_{21}+\\rho_{11}^2+\\rho_{22}^2=1.\n    \\end{gather}\n    In this way, the trace of the square of the density matrix equals $1$,\n    \\begin{align}\n        \\tr(\\rho^2)=\\tr\\left(\\begin{bmatrix}\n            \\rho_{11}&\\rho_{12}\\\\\n            \\rho_{21}&\\rho_{22}\n        \\end{bmatrix}\\begin{bmatrix}\n            \\rho_{11}&\\rho_{12}\\\\\n            \\rho_{21}&\\rho_{22}\n        \\end{bmatrix}\\right)=\\tr\\begin{bmatrix}\n            \\rho_{11}^2+\\rho_{12}\\rho_{21}&\\rho_{11}\\rho_{12}+\\rho_{12}\\rho_{22}\\\\\n            \\rho_{21}\\rho_{11}+\\rho_{22}\\rho_{21}&\\rho_{21}\\rho_{12}+\\rho_{22}^2\n        \\end{bmatrix}=\\rho_{11}^2+\\rho_{22}^2+2\\rho_{12}\\rho_{21}=1.\n    \\end{align}\n    Therefore, the state $\\rho$ is pure.\\\\\n    \\emph{Sufficiency}: If the state $\\rho$ is pure, the trace of its square is $1$,\n    \\begin{align}\n        \\tr(\\rho^2)=\\rho_{11}^2+\\rho_{22}^2+2\\rho_{12}\\rho_{21}=1.\n    \\end{align}\n    Then\n    \\begin{align}\n        \\norm{\\vec{r}}=\\sqrt{4\\rho_{12}\\rho_{21}+2(\\rho_{11}^2+\\rho_{22}^2)-1}=1.\n    \\end{align}\n    Therefore, a state $\\rho$ is pure if and only if $\\norm{\\vec{r}}=1$.\n    \\item[(4)] According to Section 1.2, we write the state of the pure state as\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\cos\\frac{\\theta}{2}\\lvert 0\\rangle+e^{i\\varphi}\\sin\\frac{\\theta}{2}\\lvert 1\\rangle,\n    \\end{align}\n    and the Bloch vector is\n    \\begin{align}\n        \\vec{r}=(\\sin\\theta\\cos\\varphi,\\sin\\theta\\sin\\varphi,\\cos\\theta).\n    \\end{align}\n    The density matrix of the pure state is\n    \\begin{align}\n        \\notag\\rho=&\\left(\\cos\\frac{\\theta}{2}\\lvert 0\\rangle+e^{i\\varphi}\\sin\\frac{\\theta}{2}\\lvert 1\\rangle\\right)\\left(\\cos\\frac{\\theta}{2}\\langle 0\\rvert+e^{-i\\varphi}\\sin\\frac{\\theta}{2}\\langle 1\\rvert\\right)=\\begin{bmatrix}\n            \\cos\\frac{\\theta}{2}\\\\\n            e^{i\\varphi}\\sin\\frac{\\theta}{2}\n        \\end{bmatrix}\\begin{bmatrix}\n            \\cos\\frac{\\theta}{2}&e^{-i\\varphi}\\sin\\frac{\\theta}{2}\n        \\end{bmatrix}\\\\\n        =&\\begin{bmatrix}\n            \\cos^2\\frac{\\theta}{2}&e^{-i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2}\\\\\n            e^{i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2}&\\sin^2\\frac{\\theta}{2}\n        \\end{bmatrix}.\n    \\end{align}\n    According to the description we have given, the Bloch vector is\n    \\begin{align}\n        \\notag\\vec{r}=&(\\rho_{12}+\\rho_{21},i(\\rho_{12}-\\rho_{21}),\\rho_{11}-\\rho_{22})\\\\\n        \\notag=&\\left(e^{-i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2}+e^{i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2},i\\left(e^{-i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2}-e^{i\\varphi}\\sin\\frac{\\theta}{2}\\cos\\frac{\\theta}{2}\\right),\\cos^2\\frac{\\theta}{2}-\\sin^2\\frac{\\theta}{2}\\right)\\\\\n        =&(\\sin\\theta\\cos\\varphi,\\sin\\theta\\sin\\sin\\varphi,\\cos\\theta).\n    \\end{align}\n    Therefore, for pure states, the description of the Bloch vector we have given coincide with that in Section 1.2.\n\\end{sol}\n\n\\begin{exe}\n    Let $\\rho$ be a density operator. A \\emph{minimal ensemble} for $\\rho$ is an ensemble $\\{p_i,\\lvert\\psi_i\\rangle\\}$ containing a number of elements equal to the rank of $\\rho$. Let $\\lvert\\psi_i\\rangle$ be any state in the support of $\\rho$. (The \\emph{support} of a Hermitian operator $A$ is vector space spanned by the eigenvectors of $A$ with non-zero eigenvalues.) Show that there is a minimal ensemble for $\\rho$ that contains $\\lvert\\psi\\rangle$, and moreover that in any such ensemble $\\lvert\\psi_i\\rangle$ must appear with probability\n    \\begin{align}\n        p_i=\\frac{1}{\\langle\\psi_i\\rvert\\rho^{-1}\\lvert\\psi_i\\rangle},\n    \\end{align}\n    where $\\rho^{-1}$ is defined to be the inverse of $\\rho$, where $\\rho$ is considered as an operator acting only on the support of $\\rho$. (This definition removes the problem that $\\rho$ may not have an inverse.)\n\\end{exe}\n\\begin{pf}\n    Suppose the spectral decomposition of the density matrix $\\rho$ is\n    \\begin{align}\n        \\rho=\\sum_{k=1}^Nq_k\\lvert k\\rangle\\langle k\\rvert=\\sum_{k=1}^N\\lvert\\tilde{k}\\rangle\\langle\\tilde{k}\\rvert.\n    \\end{align}\n    where $q_k$ are the non-zero eigenvalues and $\\lvert k\\rangle$ are the eigenvectors of $\\rho$, $N=\\text{rank}(\\rho)$ and\n    \\begin{align}\n        \\lvert\\tilde{k}\\rangle=\\sqrt{q_k}\\lvert k\\rangle.\n    \\end{align}\n    Since $\\lvert\\psi_i\\rangle$ is a state in the support of $\\rho$, it can be written as a linear combination of the eigenvectors\n    \\begin{align}\n        \\lvert\\psi_i\\rangle=\\sum_k\\langle k\\vert\\psi_i\\rangle\\lvert k\\rangle=\\sum_kc_{ik}\\lvert k\\rangle,\n    \\end{align}\n    where\n    \\begin{align}\n        c_{ik}=\\langle k\\vert\\psi_i\\rangle,\n    \\end{align}\n    and\n    \\begin{align}\n        \\sum_{k=1}^N\\abs{c_{ik}}^2=1.\n    \\end{align}\n    Define\n    \\begin{align}\n        p_i=\\frac{1}{\\sum_{k=1}^N\\frac{\\abs{c_{ik}}^2}{p_k}}\n    \\end{align}\n    and\n    \\begin{align}\n        u_{ik}=\\frac{\\sqrt{p_i}c_{ik}}{\\sqrt{q_k}}.\n    \\end{align}\n    Since\n    \\begin{align}\n        \\sum_{k=1}^N\\abs{u_{ik}}^2=\\sum_{k=1}^N\\frac{p_i\\abs{c_{ik}}^2}{q_k}=p_i\\sum_{k=1}^N\\frac{\\abs{c_{ik}}^2}{q_k}=1,\n    \\end{align}\n    $u_{ik}$ is a unitary matrix.\n    According to Theorem 2.6, the set\n    \\begin{align}\n        \\lvert\\tilde{\\psi}_i\\rangle=\\sum_{k=1}^Nu_{ik}\\lvert\\tilde{k}\\rangle=\\sum_{k=1}^N\\frac{\\sqrt{p_i}c_{ik}}{\\sqrt{q_k}}\\lvert\\tilde{k}\\rangle=\\sqrt{p_i}\\sum_{k=1}^Nc_{ik}\\lvert k\\rangle=\\sqrt{p_i}\\lvert\\psi_i\\rangle,\\quad i=1,\\cdots,N,\n    \\end{align}\n    generate the same density matrix $\\rho$,\n    \\begin{align}\n        \\rho=\\sum_{i=1}^N\\lvert\\tilde{\\psi}_i\\rangle\\langle\\tilde{\\psi}_i\\rvert=\\sum_{i=1}^Np_i\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert.\n    \\end{align}\n    Moreover,\n    \\begin{align}\n        \\frac{1}{\\langle\\psi_i\\rvert\\rho^{-1}\\lvert\\psi_i\\rangle}=\\frac{1}{\\langle\\psi_i\\rvert\\sum_{k=1}^Nq_k^{-1}\\lvert k\\rangle\\langle k\\rvert\\lvert\\psi_i\\rangle}=\\frac{1}{\\sum_{k=1}^Nq_k^{-1}\\abs{\\langle k\\vert\\psi_i\\rangle}^2}=\\frac{1}{\\sum_{k=1}^N\\frac{\\abs{c_{ik}}^2}{q_k}}=p_i.\n    \\end{align}\n    Therefore, there is a minimal ensemble for $\\rho$ that contains $\\lvert\\psi_i\\rangle$, and moreover that in any such ensemble $\\lvert\\psi_i\\rangle$ must appear with probability\n    \\begin{align}\n        p_i=\\frac{1}{\\langle\\psi_i\\rvert\\rho^{-1}\\lvert\\psi_i\\rangle}.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose a composite of system $A$ and $B$ is in the state $\\lvert a\\rangle\\lvert b\\rangle$, where $\\lvert a\\rangle$ is a pure state of system $A$, and $\\lvert b\\rangle$ is a pure state of system $B$. Show that the reduced density operator of system $A$ alone is a pure state.\n\\end{exe}\n\\begin{pf}\n    The density operator of the composite system is\n    \\begin{align}\n        \\rho^{AB}=\\lvert a\\rangle\\langle a\\rvert\\otimes\\lvert b\\rangle\\langle b\\rvert.\n    \\end{align}\n    The reduced density operator of system $A$ is\n    \\begin{align}\n        \\rho^A=\\tr_B(\\rho^{AB})=\\lvert a\\rangle\\langle a\\rvert\\tr_B(\\lvert b\\rangle\\langle b\\rvert)=\\lvert a\\rangle\\langle a\\rvert.\n    \\end{align}\n    Since\n    \\begin{align}\n        \\tr[(\\rho^A)^2]=\\tr[(\\lvert a\\rangle\\langle a\\rvert)(\\lvert a\\rangle\\langle a\\rvert)]=\\tr(\\lvert a\\rangle\\langle a\\rvert)=1,\n    \\end{align}\n    the reduced density operator of system $A$ alone is a pure state.\n\\end{pf}\n\n\\begin{exe}\n    For each of the four Bell states, find the reduced density operator for each qubit.\n\\end{exe}\n\\begin{sol}\n    Suppose the first one of the two qubits described by the Bell states is $A$, and the other $B$.\n    For the Bell state\n    \\begin{align}\n        \\lvert\\beta_{00}\\rangle=\\frac{\\lvert 00\\rangle\\langle 11\\rvert}{\\sqrt{2}},\n    \\end{align}\n    its density operator is\n    \\begin{align}\n        \\rho_{00}^{AB}=\\lvert\\beta_{00}\\rangle\\langle\\beta_{00}\\rvert=\\frac{\\lvert 00\\rangle\\langle 11\\rvert}{\\sqrt{2}}\\frac{\\langle 00\\rvert+\\langle 11\\rvert}{\\sqrt{2}}=\\frac{1}{2}(\\lvert 00\\rangle\\langle 00\\rvert+\\lvert 00\\rangle\\langle 11\\rvert+\\lvert 11\\rangle\\langle 00\\rvert+\\lvert 11\\rangle\\langle 11\\rvert),\n    \\end{align}\n    the reduced density operator of qubit $A$ is\n    \\begin{align}\n        \\notag\\rho_{00}^A=&\\tr_B(\\rho_{00}^{AB})=\\frac{1}{2}[\\tr_B(\\lvert 00\\rangle\\langle 00\\rvert)+\\tr_B(\\lvert 00\\rangle\\langle 11\\rvert)+\\tr_B(\\lvert 11\\rangle\\langle 00\\rvert)+\\tr_B(\\lvert 11\\rangle\\langle 11\\rvert)]\\\\\n        \\notag=&\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert\\langle 0\\vert 0\\rangle+\\lvert 0\\rangle\\langle 1\\rvert\\langle 0\\vert 1\\rangle+\\lvert 1\\rangle\\langle 0\\rvert\\langle 1\\vert 0\\rangle+\\lvert 1\\rangle\\langle 1\\rvert\\langle 1\\vert 1\\rangle)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert),\n    \\end{align}\n    and the reduced density operator of qubit $B$ is\n    \\begin{align}\n        \\notag\\rho_{00}^B=&\\tr_A(\\rho_{00}^{AB})=\\frac{1}{2}[\\tr_A(\\lvert 00\\rangle\\langle 00\\rvert)+\\tr_A(\\lvert 00\\rangle\\langle 11\\rvert)+\\tr_A(\\lvert 11\\rangle\\langle 00\\rvert)+\\tr_A(\\lvert 11\\rangle\\langle 11\\rvert)]\\\\\n        =&\\frac{1}{2}(\\langle 0\\vert 0\\rangle\\lvert 0\\rangle\\langle 0\\rvert+\\langle 0\\vert 1\\rangle\\lvert 0\\rangle\\langle 1\\rvert+\\langle 1\\vert 0\\rangle\\lvert 1\\rangle\\langle 0\\rvert+\\langle 1\\vert 1\\rangle\\lvert 1\\rangle\\langle 1\\rvert)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert),\n    \\end{align}\n    For the Bell state\n    \\begin{align}\n        \\lvert\\beta_{01}\\rangle=\\frac{\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{2}},\n    \\end{align}\n    its density operator is\n    \\begin{align}\n        \\rho_{01}^{AB}=\\lvert\\beta_{01}\\rangle\\langle\\beta_{01}\\rvert=\\frac{\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{2}}\\frac{\\langle 01\\rvert+\\langle 10\\rvert}{\\sqrt{2}}=\\frac{1}{2}(\\lvert 01\\rangle\\langle 01\\rvert+\\lvert 01\\rangle\\langle 10\\rvert+\\lvert 10\\rangle\\langle 01\\rvert+\\lvert 10\\rangle\\langle 10\\rvert),\n    \\end{align}\n    the reduced density operator of qubit $A$ is\n    \\begin{align}\n        \\notag\\rho_{01}^A=&\\tr_B(\\rho_{01}^{AB})=\\frac{1}{2}[\\tr_B(\\lvert 01\\rangle\\langle 01\\rvert)+\\tr_B(\\lvert 01\\rangle\\langle 10\\rvert)+\\tr_B(\\lvert 10\\rangle\\langle 01\\rvert)+\\tr_B(\\lvert 10\\rangle\\langle 10\\rvert)]\\\\\n        =&\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert\\langle 1\\vert 1\\rangle+\\lvert 0\\rangle\\langle 1\\rvert\\langle 1\\vert 0\\rangle+\\lvert 1\\rangle\\langle 0\\rvert\\langle 0\\vert 1\\rangle+\\lvert 1\\rangle\\langle 1\\rvert\\langle 0\\vert 0\\rangle)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert),\n    \\end{align}\n    and the reduced density operator of qubit $B$ is\n    \\begin{align}\n        \\notag\\rho_{01}^B=&\\tr_A(\\rho_{01}^{AB})=\\frac{1}{2}[\\tr_A(\\lvert 01\\rangle\\langle 01\\rvert)+\\tr_A(\\lvert 01\\rangle\\langle 10\\rvert)+\\tr_A(\\lvert 10\\rangle\\langle 01\\rvert)+\\tr_A(\\lvert 10\\rangle\\langle 10\\rvert)]\\\\\n        =&\\frac{1}{2}(\\langle 0\\vert 0\\rangle\\lvert 1\\rangle\\langle 1\\rvert+\\langle 0\\vert 1\\rangle\\lvert 1\\rangle\\langle 0\\rvert+\\langle 1\\vert 0\\rangle\\lvert 0\\rangle\\langle 1\\rvert+\\langle 1\\vert 1\\rangle\\lvert 0\\rangle\\langle 0\\rvert)=\\frac{1}{2}(\\lvert 1\\rangle\\langle 1\\rvert+\\lvert 0\\rangle\\langle 0\\rvert).\n    \\end{align}\n    For the Bell state\n    \\begin{align}\n        \\lvert\\beta_{10}^{AB}\\rangle=\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}},\n    \\end{align}\n    \\begin{align}\n        \\rho_{10}^{AB}=\\lvert\\beta_{10}^{AB}\\rangle\\langle\\beta_{10}^{AB}\\rvert=\\frac{\\lvert 00\\rangle-\\lvert 11\\rangle}{\\sqrt{2}}\\frac{\\langle 00\\rvert-\\langle 11\\rvert}{\\sqrt{2}}=\\frac{1}{2}(\\lvert 00\\rangle\\langle 00\\rvert-\\lvert 00\\rangle\\langle 11\\rvert-\\lvert 11\\rangle\\langle 00\\rvert+\\lvert 11\\rangle\\langle 11\\rvert),\n    \\end{align}\n    the reduced density operator of qubit $A$ is\n    \\begin{align}\n        \\notag\\rho_{10}^A=&\\tr_B(\\rho_{10}^{AB})=\\frac{1}{2}[\\tr_B(\\lvert 00\\rangle\\langle 00\\rvert)-\\tr_B(\\lvert 00\\rangle\\langle 11\\rvert)-\\tr_B(\\lvert 11\\rangle\\langle 00\\rvert)+\\tr_B(\\lvert 11\\rangle\\langle 11\\rvert)]\\\\\n        =&\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert\\langle 0\\vert 0\\rangle-\\lvert 0\\rangle\\langle 1\\rvert\\langle 0\\vert 1\\rangle-\\lvert 1\\rangle\\langle 0\\rvert\\langle 1\\vert 0\\rangle+\\lvert 1\\rangle\\langle 1\\rvert\\langle 1\\vert 1\\rangle)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert),\n    \\end{align}\n    and the reduced density operator of qubit $B$ is\n    \\begin{align}\n        \\notag\\rho_{10}^B=&\\tr_A(\\rho_{10}^{AB})=\\frac{1}{2}[\\tr_A(\\lvert 00\\rangle\\langle 00\\rvert)-\\tr_A(\\lvert 00\\rangle\\langle 11\\rvert)-\\tr_A(\\lvert 11\\rangle\\langle 00\\rvert)+\\tr_A(\\lvert 11\\rangle\\langle 11\\rvert)]\\\\\n        =&\\frac{1}{2}(\\langle 0\\vert 0\\rangle\\lvert 0\\rangle\\langle 0\\rvert-\\langle 0\\vert 1\\rangle\\lvert 0\\rangle\\langle 1\\rvert-\\langle 1\\vert 0\\rangle\\lvert 1\\rangle\\langle 0\\rvert+\\langle 1\\vert 1\\rangle\\lvert 1\\rangle\\langle 1\\rvert)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert).\n    \\end{align}\n    For the Bell state\n    \\begin{align}\n        \\lvert\\beta_{11}^{AB}\\rangle=\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}},\n    \\end{align}\n    its density operator is\n    \\begin{align}\n        \\rho_{11}^{AB}=\\lvert\\beta_{11}^{AB}\\rangle\\langle\\beta_{11}^{AB}\\rvert=\\frac{\\lvert 01\\rangle-\\lvert 10\\rangle}{\\sqrt{2}}\\frac{\\langle 01\\rvert-\\langle 10\\rvert}{\\sqrt{2}}=\\frac{1}{2}(\\lvert 01\\rangle\\langle 01\\rvert-\\lvert 01\\rangle\\langle 10\\rvert-\\lvert 10\\rangle\\langle 01\\rvert+\\lvert 10\\rangle\\langle 10\\rvert),\n    \\end{align}\n    the reduced density operator of qubit $A$ is\n    \\begin{align}\n        \\notag\\rho_{11}^A=&\\tr_B(\\rho_{11}^{AB})=\\frac{1}{2}[\\tr_B(\\lvert 01\\rangle\\langle 01\\rvert)-\\tr_B(\\lvert 01\\rangle\\langle 10\\rvert)-\\tr_B(\\lvert 10\\rangle\\langle 01\\rvert)+\\tr_B(\\lvert 10\\rangle\\langle 10\\rvert)]\\\\\n        =&\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert\\langle 1\\vert 1\\rangle-\\lvert 0\\rangle\\langle 1\\rvert\\langle 1\\vert 0\\rangle-\\lvert 1\\rangle\\langle 0\\rvert\\langle 0\\vert 1\\rangle+\\lvert 1\\rangle\\langle 1\\rvert\\langle 0\\vert 0\\rangle)=\\frac{1}{2}(\\lvert 0\\rangle\\langle 0\\rvert+\\lvert 1\\rangle\\langle 1\\rvert),\n    \\end{align}\n    and the reduced density operator of qubit $B$ is\n    \\begin{align}\n        \\notag\\rho_{11}^B=&\\tr_A(\\rho_{11}^{AB})=\\frac{1}{2}[\\tr_A(\\lvert 01\\rangle\\langle 01\\rvert)-\\tr_A(\\lvert 01\\rangle\\langle 10\\rvert)-\\tr_A(\\lvert 10\\rangle\\langle 01\\rvert)+\\tr_A(\\lvert 10\\rangle\\langle 10\\rvert)]\\\\\n        =&\\frac{1}{2}(\\langle 1\\vert 1\\rangle\\lvert 0\\rangle\\langle 0\\rvert-\\langle 1\\vert 0\\rangle\\lvert 0\\rangle\\langle 1\\rvert-\\langle 0\\vert 1\\rangle\\lvert 1\\rangle\\langle 0\\rvert+\\langle 0\\vert 0\\rangle\\lvert 1\\rangle\\langle 1\\rvert)=\\frac{1}{2}(\\lvert 1\\rangle\\langle 1\\rvert+\\lvert 0\\rangle\\langle 0\\rvert).\n    \\end{align}\n\\end{sol}\n\n\\section{The Schmidt decomposition and purification}\n\n\\begin{exe}\n    Extend the proof the Schmidt decomposition to the case where $A$ and $B$ may have the state spaces of different dimensionality.\n\\end{exe}\n\\begin{pf}\n    Suppose the dimension of the state space for systems $A$ and $B$ are $n$ and $m$, respectively, and let $\\lvert j\\rangle$ and $\\lvert k\\rangle$ be any fixed orthonormal bases for systems $A$ and $B$, respectively.\n    Then $\\lvert\\psi\\rangle$ can be written as\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_{j=1}^n\\sum_{k=1}^ma_{jk}\\lvert j\\rangle\\lvert k\\rangle,\n    \\end{align}\n    for some matrix $a$ of complex numbers $a_{jk}$.\n    Without loss of generality, set $n>m$. By the singular value decomposition,\n    \\begin{align}\n        a=u\\begin{bmatrix}\n            d\\\\\n            0\n        \\end{bmatrix}v,\n    \\end{align}\n    where $u$ is an $n\\times n$ unitary matrix, $v$ is an $m\\times m$ unitary matrix, $d$ is an $m\\times m$ diagonal matrix with non-negative real elements, and $\\left[\\begin{smallmatrix}\n        d\\\\\n        0\n    \\end{smallmatrix}\\right]$ is a $n\\times m$ matrix whose $(m+1)$th to $n$th row are all zero.\n    Thus\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_{j=1}^n\\sum_{i=1}^m\\sum_{k=1}^mu_{ji}d_{ii}v_{ik}\\lvert j\\rangle\\lvert k\\rangle.\n    \\end{align}\n    Define\n    \\begin{align}\n        \\lvert i_A\\rangle\\equiv&\\sum_{j=1}^nu_{ji}\\lvert j\\rangle,\\\\\n        \\lvert i_B\\rangle\\equiv&\\sum_{k=1}^mu_{ik}\\lvert k\\rangle,\n    \\end{align}\n    and\n    \\begin{align}\n        \\lambda_i\\equiv d_{ii}.\n    \\end{align}\n    We see that this gives\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_{i=1}^m\\lambda_i\\lvert i_A\\rangle\\lvert i_B\\rangle.\n    \\end{align}\n    Due to the unitarity of $u$ and $v$ and the orthonormality of $\\lvert j\\rangle$ and $\\lvert k\\rangle$,\n    \\begin{align}\n        \\langle i_A\\vert l_A\\rangle=&\\left(\\sum_{j=1}^nu_{ji}\\lvert j\\rangle\\right)^{\\dagger}\\left(\\sum_{j'=1}^nu_{j'l}\\lvert j'\\rangle\\right)=\\sum_{j=1}^n\\sum_{j'=1}^nu_{ij}^*u_{j'l}\\langle j\\vert j'\\rangle=\\sum_{j=1}^n\\sum_{j'=1}^nu_{ij}^*u_{j'i}\\delta_{jj'}=\\sum_{j=1}^nu_{ij}^*u_{jl}=\\delta_{il},\\\\\n        \\langle i_B\\vert l_B\\rangle=&\\left(\\sum_{k=1}^mv_{ik}\\lvert k\\rangle\\right)^{\\dagger}\\left(\\sum_{k'=1}^mv_{lk'}\\lvert k'\\rangle\\right)=\\sum_{k=1}^m\\sum_{k'=1}^mv_{ki}^*v_{lk'}\\langle k\\vert k'\\rangle=\\sum_{k=1}^m\\sum_{k'=1}^mv_{ki}^*v_{lk'}\\delta_{kk'}=\\sum_{k=1}^mv_{ki}^*u_{lk}=\\delta_{il},\n    \\end{align}\n    $\\lvert i_A\\rangle$ and $\\lvert i_B\\rangle$ form two orthonormal sets, respectively.\n    Moreover, since $\\lvert\\psi\\rangle$ is a normalized pure state,\n    \\begin{align}\n        \\langle\\psi\\vert\\psi\\rangle=\\left(\\sum_{i=1}^m\\lambda_i\\lvert i_A\\rangle\\lvert i_B\\rangle\\right)^{\\dagger}\\left(\\sum_{l=1}^m\\lambda_l\\lvert l_A\\rangle\\lvert l_B\\rangle\\right)=\\sum_{i=1}^m\\sum_{l=1}^m\\lambda_i^2\\langle i_A\\vert l_A\\rangle\\langle i_B\\vert l_B\\rangle=\\sum_{i=1}^m\\sum_{l=1}^m\\lambda_i\\lambda_l\\delta_{il}=\\sum_{i=1}^m\\lambda_i^2=1.\n    \\end{align}\n    Therefore, there exists orthonormal states $\\lvert i_A\\rangle$ for system $A$, and orthonormal states $\\lvert i_B\\rangle$ of system $B$ such that\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_i\\lambda_i\\lvert i_A\\rangle\\lvert i_B\\rangle,\n    \\end{align}\n    where $\\lambda_i$ are non-negative real number satisfying $\\sum_i\\lambda_i^2=1$.\n\\end{pf}\n\n\\begin{exe}\n    Suppose $ABC$ is a three component quantum system. Show by example that there are quantum state $\\lvert\\psi\\rangle$ of such systems which can not be written in the form\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_i\\lambda_i\\lvert i_A\\rangle\\lvert i_B\\rangle\\lvert i_C\\rangle,\n    \\end{align}\n    where $\\lambda_i$ are real numbers, and $\\lvert i_A\\rangle$, $\\lvert i_B\\rangle$, $\\lvert i_C\\rangle$ are orthonormal bases of the respective systems.\n\\end{exe}\n\\begin{sol}\n    Prove this according to \\cite{peres1995higher}. Suppose the dimension of the vector spaces of the three component systems are all $d$. Taking the normalization condition and the common phase factor taken into consideration, $2d^3-2$ real parameters are needed to determine the state of the composite system\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_{j,k,l=1}^dA_{jkl}\\lvert j\\rangle\\lvert k\\rangle\\lvert l\\rangle,\n    \\end{align}\n    where $\\lvert j\\rangle$, $\\lvert k\\rangle$ and $\\lvert l\\rangle$ are any fixed orthonormal bases for systems $A$, $B$ and $C$, respectively.\n    To rewrite the state into the form\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_{i=1}^d\\lvert i_A\\rangle\\lvert i_B\\rangle\\lvert i_C\\rangle,\n    \\end{align}\n    where $\\lambda_i$ are real numbers, and $\\lvert i_A\\rangle$, $\\lvert i_B\\rangle$, $\\lvert i_C\\rangle$ are orthonormal bases of the respective systems, we need take unitary transforms,\n    \\begin{align}\n        \\lvert i_A\\rangle=&\\sum_{j=1}^dU_{ij}\\lvert j\\rangle,\\\\\n        \\lvert i_B\\rangle=&\\sum_{k=1}^dV_{ik}\\lvert k\\rangle,\\\\\n        \\lvert i_C\\rangle=&\\sum_{l=1}^dW_{il}\\lvert l\\rangle.\n    \\end{align}\n    Each $d\\times d$ unitary matrix has $d(d-1)$ real parameters, so we only have $3d(d-1)+2d-2=3d^2-d-2$ real parameters in the rewriting process, which are not enough to solve the problem in general.\n\n    Therefore, there must be quantum state $\\lvert\\psi\\rangle$ of such systems which can not be written in the form\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\sum_i\\lambda_i\\lvert i_A\\rangle\\lvert i_B\\rangle\\lvert i_C\\rangle.\n    \\end{align}\n\n    One of the examples is a quantum system consists of three qubits, $A$, $B$, and $C$, whose state is\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\frac{\\lvert 001\\rangle+\\lvert 010\\rangle+\\lvert 100\\rangle}{\\sqrt{3}}.\n    \\end{align}\n\\end{sol}\n\n\\begin{exe}\n    Prove that a state $\\lvert\\psi\\rangle$ of a composite system $AB$ is a product state if and only if it has Schmidt number $1$. Prove that $\\lvert\\psi\\rangle$ is a product state if and only if $\\rho^A$ (and thus $\\rho^B$) are pure states.\n\\end{exe}\n\\begin{pf}\n    \\emph{Sufficiency}: If the state $\\lvert\\psi\\rangle$ has Schmidt number $1$, it can be written as\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\lambda_1\\lvert 1_A\\rangle\\lvert 1_B\\rangle,\n    \\end{align}\n    where the normalization condition requires that $\\abs{\\lambda_1}=1$ and we can actually absorb the phase factor of $\\lambda_1$ into $\\lvert 1_A\\rangle$ or $\\lvert 1_B\\rangle$, so the phase $\\lvert\\psi\\rangle$ is a product state.\\\\\n    \\emph{Necessity}: If the state $\\lvert\\psi\\rangle$ is a product state, it can be written as the product of the state of $A$ and the state of $B$,\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\lvert 1_A\\rangle\\lvert 1_B\\rangle,\n    \\end{align}\n    so its Schmidt number is $1$.\n\n    \\emph{Sufficiency}: If $\\rho^A$ (and thus $\\rho^B$) are pure states, they can be written as\n    \\begin{align}\n        \\rho^A=&\\lvert 1_A\\rangle\\langle 1_A\\rvert,\\\\\n        \\rho^B=&\\lvert 1_B\\rangle\\langle 1_B\\rvert,\\\\\n        \\Longrightarrow\\rho=&\\rho^A\\otimes\\rho^B=\\lvert 1_A\\rangle\\lvert 1_B\\rangle\\langle 1_A\\rvert\\langle 1_B\\rvert=\\lvert\\psi\\rangle\\langle\\psi\\rvert,\n    \\end{align}\n    so $\\lvert\\psi\\rangle=\\lvert 1_A\\rangle\\lvert 1_B\\rangle$ is a product state.\\\\\n    \\emph{Necessity}: If $\\lvert\\psi\\rangle$ is a product state, it can be written as\n    \\begin{align}\n        \\lvert\\psi\\rangle=\\lvert 1_A\\rangle\\lvert 1_B\\rangle,\n    \\end{align}\n    and its density matrix is\n    \\begin{align}\n        \\rho=\\lvert\\psi\\rangle\\langle\\psi\\rvert=\\lvert 1_A\\rangle\\lvert 1_B\\rangle\\langle 1_A\\rvert\\langle 1_B\\rvert,\n    \\end{align}\n    so\n    \\begin{align}\n        \\rho^A=&\\tr_B(\\rho)=\\lvert 1_A\\rangle\\langle 1_A\\rvert,\\\\\n        \\rho^B=&\\tr_A(\\rho)=\\lvert 1_B\\rangle\\langle 1_B\\rvert,\n    \\end{align}\n    are pure states.\n\\end{pf}\n\n\\begin{exe}\n    Consider a composite system consisting of two qubits. Find the Schmidt decomposition of the states\n    \\begin{align}\n        \\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}};\\quad\\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle+\\lvert 11\\rangle}{2};\\quad\\text{and}\\quad\\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{3}}.\n    \\end{align}\n\\end{exe}\n\\begin{pf}\n    State $\\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}$ is already in the form of Schmidt decomposition,\n    \\begin{align}\n        \\frac{\\lvert 00\\rangle+\\lvert 11\\rangle}{\\sqrt{2}}=\\frac{1}{\\sqrt{2}}\\lvert 0\\rangle\\lvert 0\\rangle+\\frac{1}{\\sqrt{2}}\\lvert 1\\rangle\\lvert 1\\rangle.\n    \\end{align}\n    For state $\\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle+\\lvert 11\\rangle}{2}$, by singular decomposition, we have\n    \\begin{align}\n        a=\\frac{1}{2}\\begin{bmatrix}\n            1&1\\\\\n            1&1\n        \\end{bmatrix}=\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            -1&1\\\\\n            1&1\n        \\end{bmatrix}\\begin{bmatrix}\n            0&0\\\\\n            0&1\n        \\end{bmatrix}\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            -1&1\\\\\n            1&1\n        \\end{bmatrix}=udv,\n    \\end{align}\n    where\n    \\begin{align}\n        u=v=&\\frac{1}{\\sqrt{2}}\\begin{bmatrix}\n            -1&1\\\\\n            1&1\n        \\end{bmatrix},\\\\\n        d=&\\begin{bmatrix}\n            0&0\\\\\n            0&1\n        \\end{bmatrix}.\n    \\end{align}\n    Hence we define\n    \\begin{align}\n        \\lvert 1_A\\rangle=&u_{11}\\lvert 0\\rangle+u_{12}\\lvert 1\\rangle=\\frac{1}{\\sqrt{2}}(-\\lvert 0\\rangle+\\lvert 1\\rangle),\\\\\n        \\lvert 2_A\\rangle=&u_{21}\\lvert 1\\rangle+u_{22}\\lvert 1\\rangle=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle),\\\\\n        \\lvert 1_B\\rangle=&v_{11}\\lvert 0\\rangle+v_{12}\\lvert 1\\rangle=\\frac{1}{\\sqrt{2}}(-\\lvert 0\\rangle+\\lvert 1\\rangle),\\\\\n        \\lvert 2_B\\rangle=&v_{21}\\lvert 1\\rangle+v_{22}\\lvert 1\\rangle=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle),\n    \\end{align}\n    and have Schmidt decomposition\n    \\begin{align}\n        \\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle+\\lvert 11\\rangle}{2}=\\sum_{i=1}^2d_{ii}\\lvert i_A\\rangle\\lvert i_B\\rangle=\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle)\\otimes\\frac{1}{\\sqrt{2}}(\\lvert 0\\rangle+\\lvert 1\\rangle).\n    \\end{align}\n    For state $\\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{3}}$, by singular decomposition,\n    \\begin{align}\n        a=\\frac{1}{\\sqrt{3}}\\begin{bmatrix}\n            1&1\\\\\n            1&0\n        \\end{bmatrix}=\\begin{bmatrix}\n            -\\sqrt{\\frac{5-\\sqrt{5}}{10}}&\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\\\\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}&\\sqrt{\\frac{5-\\sqrt{5}}{10}}\n        \\end{bmatrix}\\begin{bmatrix}\n            \\frac{1-\\sqrt{5}}{2\\sqrt{3}}&0\\\\\n            0&\\frac{1+\\sqrt{5}}{2\\sqrt{3}}\n        \\end{bmatrix}\\begin{bmatrix}\n            -\\sqrt{\\frac{5-\\sqrt{5}}{10}}&\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\\\\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}&\\sqrt{\\frac{5-\\sqrt{5}}{10}}\n        \\end{bmatrix}=udv,\n    \\end{align}\n    where\n    \\begin{align}\n        u=v=&\\begin{bmatrix}\n            -\\sqrt{\\frac{5-\\sqrt{5}}{10}}&\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\\\\n            \\sqrt{\\frac{5+\\sqrt{5}}{10}}&\\sqrt{\\frac{5-\\sqrt{5}}{10}}\n        \\end{bmatrix},\\\\\n        d=&\\begin{bmatrix}\n            \\frac{1-\\sqrt{5}}{2\\sqrt{3}}&0\\\\\n            0&\\frac{1+\\sqrt{5}}{2\\sqrt{3}}\n        \\end{bmatrix}.\n    \\end{align}\n    Hence we define\n    \\begin{align}\n        \\lvert 1_A\\rangle=&u_{11}\\lvert 0\\rangle+u_{12}\\lvert 1\\rangle=-\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 1\\rangle,\\\\\n        \\lvert 2_A\\rangle=&u_{21}\\lvert 0\\rangle+u_{22}\\lvert 1\\rangle=\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 1\\rangle,\\\\\n        \\lvert 1_B\\rangle=&v_{11}\\lvert 0\\rangle+v_{12}\\lvert 1\\rangle=-\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 1\\rangle,\\\\\n        \\lvert 2_B\\rangle=&v_{21}\\lvert 0\\rangle+v_{22}\\lvert 1\\rangle=\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 1\\rangle,\n    \\end{align}\n    and have Schmidt decomposition\n    \\begin{align}\n        \\notag\\frac{\\lvert 00\\rangle+\\lvert 01\\rangle+\\lvert 10\\rangle}{\\sqrt{3}}=&\\frac{1-\\sqrt{5}}{2\\sqrt{3}}\\left(-\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 1\\rangle\\right)\\otimes\\left(-\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 1\\rangle\\right)\\\\\n        &+\\frac{1+\\sqrt{5}}{2\\sqrt{3}}\\left(\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 1\\rangle\\right)\\otimes\\left(\\sqrt{\\frac{5+\\sqrt{5}}{10}}\\lvert 0\\rangle+\\sqrt{\\frac{5-\\sqrt{5}}{10}}\\lvert 1\\rangle\\right).\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose $\\lvert\\psi\\rangle$ and $\\lvert\\varphi\\rangle$ are two pure states of a composite quantum system with components $A$ and $B$, with identical Schmidt coefficients. Show that there are unitary transformations $U$ on system $A$ and $V$ on system $B$ such that $\\lvert\\psi\\rangle=(U\\otimes V)\\lvert\\varphi\\rangle$.\n\\end{exe}\n\\begin{pf}\n    Suppose the two pure states are respectively\n    \\begin{align}\n        \\lvert\\psi\\rangle=&\\sum_i\\lambda_i\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^B\\rangle,\\\\\n        \\lvert\\varphi\\rangle=&\\sum_i\\lambda_i\\lvert\\varphi_i^A\\rangle\\lvert\\varphi_i^B\\rangle.\n    \\end{align}\n    Define the two unitary matrices as\n    \\begin{align}\n        U=&\\sum_i\\lvert\\psi_i^A\\rangle\\langle\\varphi_i^A\\rvert,\\\\\n        V=&\\sum_i\\lvert\\psi_i^B\\rangle\\langle\\varphi_i^B\\rvert.\n    \\end{align}\n    Then\n    \\begin{align}\n        \\notag(U\\otimes V)\\lvert\\varphi\\rangle=&\\sum_j\\lvert\\psi_j^A\\rangle\\langle\\varphi_j^A\\rvert\\sum_k\\lvert\\psi_k^B\\rangle\\langle\\varphi_k^B\\rvert\\sum_i\\lambda_i\\lvert\\varphi_i^A\\rangle\\lvert\\varphi_i^B\\rangle=\\sum_{i,j,k}\\lambda_i\\lvert\\psi_j^A\\rangle\\langle\\varphi_j^A\\vert\\varphi_i^A\\rangle\\lvert\\psi_k^B\\rangle\\langle\\varphi_k^A\\vert\\varphi_i^B\\rangle\\\\\n        =&\\sum_{i,j,k}\\delta_{ij}\\delta_{ik}\\lambda_i\\lvert\\psi_j^A\\rangle\\lvert\\psi_k^B\\rangle=\\sum_i\\lambda_i\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^B\\rangle=\\lvert\\psi\\rangle.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}[Freedom in purifications]\n    Let $\\lvert AR_1\\rangle$ and $\\lvert AR_2\\rangle$ be two purifications of a state $\\rho^A$ to a composite system $AR$. Prove that there exists a unitary transformation $U_R$ acting on system $R$ such that $\\lvert AR_1\\rangle=(I_A\\otimes U_R)\\lvert AR_2\\rangle$.\n\\end{exe}\n\\begin{pf}\n    Let the Schmidt decomposition of $\\lvert AR_1\\rangle$ and $\\lvert AR_2\\rangle$ be respectively\n    \\begin{align}\n        \\lvert AR_1\\rangle=&\\sum_i\\sqrt{p_i}\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^R\\rangle,\\\\\n        \\lvert AR_2\\rangle=&\\sum_i\\sqrt{q_i}\\lvert\\varphi_i^A\\rangle\\lvert\\varphi_i^R\\rangle.\n    \\end{align}\n    Since $\\lvert AR_1\\rangle$ and $\\lvert AR_2\\rangle$ are two purifications of state $\\rho^A$,\n    \\begin{gather}\n        \\rho^A=\\tr_R(\\lvert AR_1\\rangle\\langle AR_1\\rvert)=\\tr_R(\\lvert AR_2\\rangle\\langle AR_2\\rvert),\\\\\n        \\Longrightarrow\\sum_ip_i\\lvert\\psi_i^A\\rangle\\langle\\psi_i^A\\rvert=\\sum_iq_i\\lvert\\varphi_i^A\\rangle\\langle\\varphi_i^A\\rvert.\n    \\end{gather}\n    Since both $\\lvert\\psi_i^A\\rangle$ and $\\lvert\\varphi_i^A\\rangle$ are orthogonal bases of system $A$ and eigenvectors of $\\rho^A$, without loss of generality, we can set\n    \\begin{gather}\n        \\sqrt{p_i}=\\sqrt{q_i}\\equiv\\lambda_i,\\\\\n        \\lvert\\psi_i^A\\rangle=\\lvert\\varphi_i^A\\rangle\\equiv\\lvert i^A\\rangle.\n    \\end{gather}\n    In this way,\n    \\begin{align}\n        \\lvert AR_1\\rangle=&\\sum_i\\lambda_i\\lvert i^A\\rangle\\lvert\\psi_i^R\\rangle,\\\\\n        \\lvert AR_2\\rangle=&\\sum_i\\lambda_i\\lvert i^A\\rangle\\lvert\\varphi_i^R\\rangle\n    \\end{align}\n    Define the unitary transformation as\n    \\begin{align}\n        U_R=\\sum_i\\lvert\\psi_i^R\\rangle\\langle\\varphi_i^R\\rvert.\n    \\end{align}\n    Then\n    \\begin{align}\n        \\notag(I_A\\otimes U_R)\\lvert AR_2\\rangle=&\\left(I_A\\otimes\\sum_j\\lvert\\psi_i^R\\rangle\\langle\\varphi_i^R\\rvert\\right)\\sum_i\\lambda_i\\lvert i^A\\rangle\\lvert\\varphi_i^R\\rangle=\\sum_{i,j}\\lambda_i\\lvert i^A\\rangle\\lvert\\psi_j^R\\rangle\\langle\\varphi_j^R\\vert\\varphi_i^R\\rangle=\\sum_{i,j}\\delta_{ij}\\lambda_i\\lvert i^A\\rangle\\lvert\\psi_i^R\\rangle=\\sum_i\\lambda_i\\lvert i^A\\rangle\\lvert\\psi_i^R\\rangle\\\\\n        =&\\lvert AR_2\\rangle.\n    \\end{align}\n\\end{pf}\n\n\\begin{exe}\n    Suppose $\\{p_i,\\lvert\\psi_i\\rangle\\}$ is an ensemble of states generating a density matrix $\\rho=\\sum_ip_i\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert$ for a quantum system $A$. Introduce a system $R$ with orthonormal basis $\\lvert i\\rangle$.\n    \\begin{itemize}\n        \\item[(1)] Show that $\\sum_i\\sqrt{p_i}\\lvert\\psi_i\\rangle\\lvert i\\rangle$ is a purification of $\\rho$.\n        \\item[(2)] Suppose we measure $R$ in the basis $\\lvert i\\rangle$, obtaining outcome $i$. With what probability do we obtain the result $i$, and what is the corresponding state of system $A$.\n        \\item[(3)] Let $\\lvert AR\\rangle$ be any purification of $\\rho$ to the system $AR$. Show that there exists an orthonormal basis $\\lvert i\\rangle$ in which $R$ can be measured such that the corresponding post-measurement state for system $A$ is $\\lvert\\psi_i\\rangle$ with probability $p_i$.\n    \\end{itemize}\n\\end{exe}\n\\begin{sol}\n    \\begin{itemize}\n        \\item[(1)] Since\n        \\begin{align}\n            \\tr_R\\left[\\left(\\sum_i\\sqrt{p_i}\\lvert\\psi_i\\rangle\\lvert i\\rangle\\right)\\left(\\sum_j\\sqrt{p_j^*}\\langle\\psi_j\\rvert\\langle j\\rvert\\right)\\right]=\\sum_ip_i\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert=\\rho,\n        \\end{align}\n        $\\sum_i\\sqrt{p_i}\\lvert\\psi_i\\rangle\\lvert i\\rangle$ is a purification of $\\rho$.\n        \\item[(2)] The probability of obtaining $i$ is\n        \\begin{align}\n            \\notag p(i)=&\\tr\\left[(I^A\\otimes M_i^R)^\\dagger(I_A\\otimes M_i^R)\\left(\\sum_j\\sqrt{p_j}\\lvert\\psi_j\\rangle\\lvert j\\rangle\\right)\\left(\\sum_k\\sqrt{p_k^*}\\langle\\psi_k\\rvert\\langle k\\rvert\\right)\\right]\\\\\n            \\notag=&\\tr\\left[\\sum_{j,k}\\sqrt{p_jp_k^*}\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle i\\vert i\\rangle\\langle i\\vert j\\rangle\\langle k\\rvert\\right]=\\tr\\left[\\sum_{j,k}\\delta_{ij}\\sqrt{p_jp_k^*}\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle k\\rvert\\right]\\\\\n            =&\\tr\\left[\\sum_k\\sqrt{p_ip_k^*}\\lvert\\psi_i\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle k\\rvert\\right]=\\abs{p_i}.\n        \\end{align}\n        The state of the joint system after measurement is\n        \\begin{align}\n            \\notag\\frac{(I^A\\otimes M_i^R)^{\\dagger}\\left(\\sum_j\\sqrt{p_j}\\lvert\\psi_j\\rangle\\lvert j\\rangle\\right)\\left(\\sum_k\\sqrt{p_k^*}\\langle\\psi_k\\rvert\\langle k\\rvert\\right)(I_A\\otimes M_i^R)}{p(i)}=&\\frac{\\sum_{j,k}\\sqrt{p_jp_k^*}\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\lvert i\\rangle\\langle i\\vert j\\rangle\\langle k\\vert i\\rangle\\langle i\\rvert}{\\abs{p_i}}\\\\\n            \\notag=&\\frac{\\sum_{j,k}\\delta_{ij}\\delta_{ik}\\sqrt{p_jp_k^*}\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle i\\rvert}{\\abs{p_i}}\\\\\n            =&\\frac{\\abs{p_i}\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert\\otimes\\lvert i\\rangle\\langle i\\rvert}{\\abs{p_i}}=\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle i\\rvert.\n        \\end{align}\n        The corresponding state of system $A$ is\n        \\begin{align}\n            \\tr_R(\\lvert\\psi_j\\rangle\\langle\\psi_k\\rvert\\otimes\\lvert i\\rangle\\langle i\\rvert)=\\lvert\\psi_i\\rangle\\langle\\psi_i\\rvert,\n        \\end{align}\n        i.e. $\\lvert\\psi_i\\rangle$.\n        \\item[(3)] Suppose the Schmidt decomposition of the purification $\\lvert AR\\rangle$ is\n        \\begin{align}\n            \\lvert AR\\rangle=\\sum_i\\sqrt{q_i}\\lvert\\varphi_i^A\\rangle\\lvert\\varphi_i^R\\rangle.\n        \\end{align}\n        According to Theorem 2.6, there exists a unitary matrix $u_{ij}$ such that\n        \\begin{align}\n            \\sqrt{q_i}\\lvert\\varphi_i^A\\rangle=\\sum_{j}u_{ij}\\sqrt{p_j}\\lvert\\psi_i\\rangle.\n        \\end{align}\n        In this way,\n        \\begin{align}\n            \\lvert AR\\rangle=\\sum_i\\left(\\sum_{j}u_{ij}\\sqrt{p_j}\\lvert\\psi_i\\rangle\\right)\\lvert\\varphi_i^R\\rangle=\\sum_j\\sqrt{p_j}\\lvert\\psi_j\\rangle\\left(\\sum_iu_{ij}\\lvert\\varphi_i^R\\rangle\\right)=\\sum_j\\sqrt{p_j}\\lvert\\psi_j\\rangle\\lvert j\\rangle=\\sum_i\\sqrt{p_i}\\lvert\\psi_i\\rangle\\lvert i\\rangle,\n        \\end{align}\n        where\n        \\begin{align}\n            \\lvert i\\rangle=\\sum_ju_{ji}\\lvert\\varphi_j^R\\rangle.\n        \\end{align}\n        Therefore, there exists an orthonormal basis $\\lvert i\\rangle$ in which $R$ can be measured such that the corresponding post-measurement state for system $A$ is $\\lvert\\psi_i\\rangle$ with probability $p_i$.\n    \\end{itemize}\n\\end{sol}\n\n\\section{EPR and the Bell inequality}\n\n\\begin{prob}[Functions of the Pauli matrices]\n    Let $f(\\cdot)$ be any function from complex numbers to complex numbers. Let $\\vec{n}$ be a normalized vector in three dimensions, and let $\\theta$ be real. Show that\n    \\begin{align}\n        \\label{P2.1}\n        f(\\theta\\vec{n}\\cdot\\vec{\\sigma})=\\frac{f(\\theta)+f(-\\theta)}{2}I+\\frac{f(\\theta)-f(-\\theta)}{2}\\vec{n}\\cdot\\vec{\\sigma}.\n    \\end{align}\n\\end{prob}\n\\begin{pf}\n    Similar to Exercise 2.35, the left side of Equation \\eqref{P2.1} is\n    \\begin{align}\n        \\notag f(\\theta\\vec{n}\\cdot\\vec{\\sigma})=\\sum_{k=0}^{\\infty}\\frac{1}{k!}f^{(k)}(0)(\\theta\\vec{n}\\cdot\\vec{\\sigma})^k=\\sum_{k=0}^{\\infty}\\frac{1}{(2k)!}(\\theta\\vec{n}\\cdot\\vec{\\sigma})^{2k}+\\sum_{k=0}^{\\infty}\\frac{1}{(2k+1)!}(\\theta\\vec{n}\\cdot\\vec{\\sigma})^{2k+1}.\n    \\end{align}\n    Note that\n    \\begin{align}\n        (\\vec{n}\\cdot\\vec{\\sigma})^2=\\left(\\sum_{i=1}^3n_i\\sigma_i\\right)^2=\\sum_{i,j=1}^3v_iv_j\\sigma_i\\sigma_j.\n    \\end{align}\n    Using the anti commutation relation between the Pauli matrices,\n    \\begin{align}\n        \\{\\sigma_i,\\sigma_j\\}=\\sigma_i\\sigma_j+\\sigma_j\\sigma_i=2\\delta_{ij}I=\\left\\{\\begin{array}{ll}\n            2I,&i=j;\\\\\n            0,&i\\neq j,\n        \\end{array}\\right.\n    \\end{align}\n    we have\n    \\begin{align}\n        (\\vec{n}\\cdot\\vec{\\sigma})^2=\\sum_in_i^2I=I.\n    \\end{align}\n    Hence the left side of Equation \\eqref{P2.1} can be written as\n    \\begin{align}\n        f(\\theta\\vec{n}\\cdot\\vec{\\sigma})=\\sum_{k=0}^{\\infty}\\frac{1}{(2k)!}f^{(2k)}(0)\\theta^{2k}+\\sum_{k=0}^{\\infty}\\frac{1}{(2k+1)!}f^{(2k+1)}(0)\\theta^{2k+1}\\vec{n}\\cdot\\vec{\\sigma}.\n    \\end{align}\n    Since\n    \\begin{align}\n        f(\\theta)+f(-\\theta)=&\\sum_{k=0}^{\\infty}\\frac{1}{k!}f^{(k)}(0)\\theta^k+\\sum_{k=0}^{\\infty}\\frac{1}{k!}f^{(k)}(0)(-\\theta)^k=\\sum_{k=0}^{\\infty}\\frac{1}{(2k)!}f^{(2k)}(0)\\theta^{2k},\\\\\n        f(\\theta)-f(-\\theta)=&\\sum_{k=0}^{\\infty}\\frac{1}{k!}f^{(k)}(0)\\theta^k-\\sum_{k=0}^{\\infty}\\frac{1}{k!}f^{(k)}(0)(-\\theta)^k=\\sum_{k=0}^{\\infty}\\frac{1}{(2k+1)!}f^{(2k+1)}(0)\\theta^{2k+1},\n    \\end{align}\n    the left side of Equation \\eqref{P2.1} equals its right side,\n    \\begin{align}\n        f(\\theta\\vec{n}\\cdot\\vec{\\sigma})=\\frac{f(\\theta)-f(-\\theta)}{2}I+\\frac{f(\\theta)-f(-\\theta)}{2}\\vec{n}\\cdot\\vec{\\sigma}.\n    \\end{align}\n    Therefore, Equation \\eqref{P2.1} holds.\n\\end{pf}\n\n\\begin{prob}[Properties of the Schmidt number]\n    Suppose $\\lvert\\psi\\rangle$ is a pure state of a composite system with components $A$ and $B$.\n    \\begin{itemize}\n        \\item[(1)] Prove that the Schmidt number of $\\lvert\\psi\\rangle$ is equal to the rank of the reduced density matrix $\\rho_A\\equiv\\tr_B(\\lvert\\psi\\rangle\\langle\\psi\\rvert)$. (Note that the rank of a Hermitian operator is equal to the dimension of its support.)\n        \\item[(2)] Suppose $\\lvert\\psi\\rangle=\\sum_j\\lvert\\alpha_j\\rangle\\lvert\\beta_j\\rangle$ is a representation for $\\lvert\\psi\\rangle$, where $\\lvert\\alpha_i\\rangle$ and $\\lvert\\beta_j\\rangle$ are (un-normalized) states for system $A$ and $B$, respectively. Prove that the number of terms in such a decomposition is greater than or equal to the Schmidt number of $\\lvert\\psi\\rangle$, $\\text{Sch}(\\psi)$.\n        \\item[(3)] Suppose $\\lvert\\psi\\rangle=\\alpha\\lvert\\varphi\\rangle+\\beta\\lvert\\gamma\\rangle$. Prove that\n        \\begin{align}\n            \\text{Sch}(\\psi)\\geq\\abs{\\text{Sch}(\\varphi)-\\text{Sch}(\\gamma)}.\n        \\end{align}\n    \\end{itemize}\n\\end{prob}\n\\begin{pf}\n    \\begin{itemize}\n        \\item[(1)] Suppose the Schmidt decomposition of $\\lvert\\psi\\rangle$ is\n        \\begin{align}\n            \\lvert\\psi\\rangle=\\sum_{i=1}^{\\text{Sch}(\\psi)}\\lambda_i\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^B\\rangle.\n        \\end{align}\n        The reduced density matrix is\n        \\begin{align}\n            \\notag\\rho_A=&\\tr_B(\\lvert\\psi\\rangle\\langle\\psi\\rvert)=\\tr_B\\left[\\left(\\sum_{i=1}^{\\text{Sch}(\\psi)}\\lambda_i\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^B\\rangle\\right)\\left(\\sum_{j=1}^{\\text{Sch}(\\psi)}\\lambda_j^*\\langle\\psi_j^A\\rvert\\langle\\psi_j^B\\rvert\\right)\\right]\\\\\n            =&\\tr_B\\left(\\sum_{i,j=1}^{\\text{Sch}(\\psi)}\\lambda_i\\lambda_j^*\\lvert\\psi_i^A\\rangle\\langle\\psi_j^A\\rvert\\otimes\\lvert\\psi_i^B\\rangle\\langle\\psi_j^B\\rvert\\right)=\\sum_{i=1}^{\\text{Sch}(\\psi)}\\abs{\\lambda_i}^2\\lvert\\psi_i^A\\rangle\\langle\\psi_i^A\\rvert,\n        \\end{align}\n        whose rank is equal to the Schmidt number $\\text{Sch}(\\psi)$.\n        \\item[(2)] Suppose the number of terms in the decomposition, $\\lvert\\psi\\rangle=\\sum_j\\lvert\\alpha_j\\rangle\\lvert\\beta_j\\rangle$, $J$ is less than $\\text{Sch}(\\psi)$.\n        The reduced density matrix is\n        \\begin{align}\n            \\notag\\rho_A=&\\tr_B(\\lvert\\psi\\rangle\\langle\\psi\\rvert)=\\tr_B\\left[\\left(\\sum_{j=1}^J\\lvert\\alpha_j\\rangle\\lvert\\beta_j\\rangle\\right)\\left(\\sum_{k=1}^J\\langle\\alpha_k\\rvert\\langle\\beta_k\\rvert\\right)\\right]=\\tr_B\\left(\\sum_{j,k=1}^J\\lvert\\alpha_j\\rangle\\lvert\\beta_j\\rangle\\langle\\alpha_k\\rvert\\langle\\beta_k\\rvert\\right)\\\\\n            =&\\sum_{i=1}^{\\text{Sch}(\\psi)}\\sum_{j,k=1}^J\\lvert\\alpha_j\\rangle\\langle\\alpha_k\\rvert\\langle\\psi_i^B\\vert\\beta_j\\rangle\\langle\\beta_k\\vert\\psi_i^B\\rangle=\\sum_{j,k=1}^J\\left(\\sum_{i=1}^{\\text{Sch}(\\psi)}\\langle\\psi_i^B\\vert\\beta_j\\rangle\\langle\\beta_k\\vert\\psi_i^B\\rangle\\right)\\lvert\\alpha_j\\rangle\\langle\\alpha_k\\rvert\n        \\end{align}\n        Even if $\\lvert\\alpha_j\\rangle$ are all independent, the rank of the reduced density matrix $\\rho^A$ is only $J$, which is less than $\\text{Sch}(\\psi)$, and thus less than the rank of $\\rho^A$.\n        Therefore, the supposition is incorrect and the number of terms in such a decomposition is greater than or equal to the Schmidt number of $\\lvert\\psi\\rangle$, $\\text{Sch}(\\psi)$.\n        \\item[(3)] Suppose the Schmidt decompositions of $\\lvert\\varphi\\rangle$ and $\\lvert\\gamma\\rangle$ are respectively\n        \\begin{align}\n            \\lvert\\varphi\\rangle=&\\sum_{i=1}^{\\text{Sch}(\\varphi)}\\lvert\\varphi_i^A\\rangle\\lvert\\varphi_i^B\\rangle,\\\\\n            \\lvert\\gamma\\rangle=&\\sum_{i=1}^{\\text{Sch}(\\gamma)}\\lvert\\gamma_i^A\\rangle\\lvert\\gamma_i^B\\rangle.\n        \\end{align}\n        Without loss of generality, we assume $\\text{Sch}(\\varphi)\\geq\\text{Sch}(\\gamma)$ and thus the original problem is converted to proving that $\\text{Sch}(\\varphi)+\\text{Sch}(\\gamma)\\geq\\text{Sch}(\\psi)$. From\n        \\begin{align}\n            \\lvert\\psi\\rangle=\\alpha\\lvert\\varphi\\rangle+\\beta\\lvert\\gamma\\rangle,\n        \\end{align}\n        we have\n        \\begin{align}\n            \\lvert\\varphi\\rangle=\\frac{\\beta}{\\alpha}\\lvert\\gamma\\rangle-\\frac{1}{\\alpha}\\lvert\\psi\\rangle=\\frac{\\beta}{\\alpha}\\sum_{i=1}^{\\text{Sch}(\\gamma)}\\lvert\\gamma_i^A\\rangle\\lvert\\gamma_i^B\\rangle-\\frac{1}{\\alpha}\\sum_{i=1}^{\\text{Sch}(\\psi)}\\lvert\\psi_i^A\\rangle\\lvert\\psi_i^B\\rangle=\\sum_{i=1}^{\\text{Sch}(\\gamma)+\\text{Sch}(\\psi)}\\delta_i\\lvert a_i\\rangle\\lvert b_i\\rangle,\n        \\end{align}\n        where\n        \\begin{align}\n            \\delta_i=&\\left\\{\\begin{array}{ll}\n                \\frac{\\beta}{\\alpha},&1\\leq i\\leq\\text{Sch}(\\gamma);\\\\\n                -\\frac{1}{\\alpha},&\\text{Sch}(\\gamma)<i\\leq\\text{Sch}(\\gamma)+\\text{Sch}(\\psi),\n            \\end{array}\\right.\\\\\n            a_i=&\\left\\{\\begin{array}{ll}\n                \\gamma_i^A,&1\\leq i\\leq\\text{Sch}(\\gamma);\\\\\n                \\psi_i^A,&\\text{Sch}(\\gamma)<i\\leq\\text{Sch}(\\gamma)+\\text{Sch}(\\psi),\n            \\end{array}\\right.\\\\\n            b_i=&\\left\\{\\begin{array}{ll}\n                \\gamma_i^B,&1\\leq i\\leq\\text{Sch}(\\gamma);\\\\\n                \\psi_i^B,&\\text{Sch}(\\gamma)<i\\leq\\text{Sch}(\\gamma)+\\text{Sch}(\\psi).\n            \\end{array}\\right.\n        \\end{align}\n        Using the conclusion obtained in (2), we have\n        \\begin{align}\n            \\text{Sch}(\\gamma)+\\text{Sch}(\\psi)\\geq\\text{Sch}(\\varphi).\n        \\end{align}\n        Therefore,\n        \\begin{align}\n            \\text{Sch}(\\psi)\\geq\\abs{\\text{Sch}(\\varphi)-\\text{Sch}(\\gamma)}.\n        \\end{align}\n    \\end{itemize}\n\\end{pf}\n\n\\begin{prob}[Tsirelson's inequality]\n    Suppose $Q=\\vec{q}\\cdot\\vec{\\sigma}$, $R=\\vec{r}\\cdot\\vec{\\sigma}$, $S=\\vec{s}\\cdot\\vec{\\sigma}$, $T=\\vec{t}\\cdot\\vec{\\sigma}$, where $\\vec{q}$, $\\vec{r}$, $\\vec{s}$ and $\\vec{t}$ are real unit vectors in three dimensions. Show that\n    \\begin{align}\n        (Q\\otimes S+R\\otimes S+R\\otimes T-Q\\otimes T)^2=4I+[Q,R]\\otimes[S,T].\n    \\end{align}\n    Use this result to prove that\n    \\begin{align}\n        \\langle Q\\otimes S\\rangle+\\langle R\\otimes S\\rangle+\\langle R\\otimes T\\rangle-\\langle Q\\otimes T\\rangle\\leq 2\\sqrt{2},\n    \\end{align}\n    so the violation of the Bell inequality found in Equation (2.230)\\footnote{$\\langle QS\\rangle+\\langle RS\\rangle+\\langle RT\\rangle-\\langle QT\\rangle=2\\sqrt{2}$.} is the maximum possible in quantum mechanics.\n\\end{prob}\n\\begin{pf}\n    \\begin{gather}\n        Q=\\vec{q}\\cdot\\vec{\\sigma}=q_1\\sigma_1+q_2\\sigma_2+q_3\\sigma_3=q_1\\begin{bmatrix}\n            0&1\\\\\n            1&0\n        \\end{bmatrix}+q_2\\begin{bmatrix}\n            0&-i\\\\\n            i&0\n        \\end{bmatrix}+q_3\\begin{bmatrix}\n            1&0\\\\\n            0&-1\n        \\end{bmatrix}=\\begin{bmatrix}\n            q_3&q_1-iq_2\\\\\n            q_1+iq_2&-q_3\n        \\end{bmatrix},\\\\\n        \\Longrightarrow Q^2=\\begin{bmatrix}\n            q_3&q_1-iq_2\\\\\n            q_1+iq_2&-q_3\n        \\end{bmatrix}\\begin{bmatrix}\n            q_3&q_1-iq_2\\\\\n            q_1+iq_2&-q_3\n        \\end{bmatrix}=\\begin{bmatrix}\n            q_1^2+q_2^2+q_3^2&0\\\\\n            0&q_1^2+q_2^2+q_3^2\n        \\end{bmatrix}=\\begin{bmatrix}\n            1&0\\\\\n            0&1\n        \\end{bmatrix}=I.\n    \\end{gather}\n    Similarly,\n    \\begin{align}\n        R^2=S^2=T^2=I.\n    \\end{align}\n    Hence\n    \\begin{align}\n        \\notag(Q\\otimes S+R\\otimes S+R\\otimes T-Q\\otimes T)^2=&QQ\\otimes SS+QR\\otimes SS+QR\\otimes ST-QQ\\otimes ST\\\\\n        \\notag&+RQ\\otimes SS+RR\\otimes SS+RR\\otimes ST-RQ\\otimes ST\\\\\n        \\notag&+RQ\\otimes TS+RR\\otimes TS+RR\\otimes TT-RQ\\otimes TT\\\\\n        \\notag&-QQ\\otimes TS-QR\\otimes TS-QR\\otimes TT+QQ\\otimes TT\\\\\n        \\notag=&I\\otimes I+QR\\otimes I+QR\\otimes ST-I\\otimes ST\\\\\n        \\notag&+RQ\\otimes I+I\\otimes I+I\\otimes ST-RQ\\otimes ST\\\\\n        \\notag&+RQ\\otimes TS+I\\otimes TS+I\\otimes I-RQ\\otimes I\\\\\n        \\notag&-I\\otimes TS-QR\\otimes TS-QR\\otimes I+I\\otimes I\\\\\n        \\notag=&4I+QR\\otimes ST-RQ\\otimes ST+RQ\\otimes TS-QR\\otimes TS\\\\\n        =&4I+(QR-RQ)\\otimes(ST-TS)=4I+[Q,R]\\otimes[S,T].\n    \\end{align}\n    The average of the above equation is\n    \\begin{align}\n        \\langle(Q\\otimes S+R\\otimes S+R\\otimes T-Q\\otimes T)^2\\rangle=\\langle 4I+[Q,R]\\otimes[S,T]\\rangle=4\\langle I\\rangle+\\langle[Q,S]\\rangle\\otimes\\langle[S,T]\\rangle=4+\\langle[Q,R]\\rangle\\otimes\\langle[S,T]\\rangle,\n    \\end{align}\n    where\n    \\begin{align}\n        \\langle[Q,R]\\rangle=\\langle\\psi\\rvert[Q,R]\\lvert\\psi\\rangle=\\langle\\psi\\rvert QR-RQ\\lvert\\psi\\rangle=\\langle\\psi\\rvert QR\\lvert\\rangle-\\langle\\psi\\rvert RQ\\lvert\\psi\\rangle=2i\\re[\\langle\\psi\\rvert QR\\lvert\\psi\\rangle]=2i\\re[\\langle QR\\rangle].\n    \\end{align}\n    Note that both $Q$ and $R$ are unitarity, so $QR$ is unitary. Since unitary operators preserve the inner products and thus lengths of vectors, $QR\\lvert\\psi\\rangle$ is still a normalized vector and $\\abs{\\langle[Q,R]\\rangle}\\leq 1\\Longrightarrow-1\\leq\\re[\\langle QR\\rangle]\\leq 1$.\n    Similarly,\n    \\begin{align}\n        \\langle[S,T]\\rangle=2i\\re[\\langle ST\\rangle].\n    \\end{align}\n    and $-1\\leq\\re[\\langle ST\\rangle]\\leq 1$.\n    Therefore,\n    \\begin{align}\n        \\notag\\langle Q\\otimes S\\rangle+\\langle R\\otimes S\\rangle+\\langle R\\otimes T\\rangle-\\langle Q\\otimes T\\rangle\\leq&\\sqrt{\\langle(Q\\otimes S+R\\otimes S+R\\otimes T-Q\\otimes T)^2\\rangle}=\\sqrt{4+\\langle[Q,R]\\rangle\\otimes\\langle[S,T]\\rangle}\\\\\n        =&\\sqrt{4-4\\re[\\langle QR\\rangle]\\re[\\langle ST\\rangle]}\\leq 2\\sqrt{2}.\n    \\end{align}\n\\end{pf}\n\n\\ifx\\allfiles\\undefined\n\\bibliographystyle{plain}\n\\bibliography{References}\n\\end{document}\n\\fi", "meta": {"hexsha": "d68aa4dbfab314cb4623c3d09313822f13459ed1", "size": 160072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chap-2.tex", "max_stars_repo_name": "Chen-Jialin/Solutions-to-Exercises-in-Quantum-Computation-and-Quantum-Information", "max_stars_repo_head_hexsha": "a3e0da2f02074433f9663c7406dce441520b541b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2022-03-07T08:22:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T13:45:20.000Z", "max_issues_repo_path": "Chap-2.tex", "max_issues_repo_name": "Chen-Jialin/Solutions-to-Exercises-in-Quantum-Computation-and-Quantum-Information", "max_issues_repo_head_hexsha": "a3e0da2f02074433f9663c7406dce441520b541b", "max_issues_repo_licenses": ["MIT"], "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-2.tex", "max_forks_repo_name": "Chen-Jialin/Solutions-to-Exercises-in-Quantum-Computation-and-Quantum-Information", "max_forks_repo_head_hexsha": "a3e0da2f02074433f9663c7406dce441520b541b", "max_forks_repo_licenses": ["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.2738693467, "max_line_length": 560, "alphanum_fraction": 0.6132740267, "num_tokens": 59293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972717658209, "lm_q2_score": 0.8918110404058914, "lm_q1q2_score": 0.7764082587080073}}
{"text": "\\chapter{Minimum Search on Rotated Array}\nThe objective of this challenge is to find the smallest element in an array\nthat was rotated at a random index after being sorted. Duplicate elements are\nnot allowed for this challenge.\n\n\\section{Solution}\n\\imb[3][11]{\\alg/rotatedarray.cpp}\n\\imb[34][39]{\\alg/rotatedarray.cpp}\n\\imb[42][43]{\\alg/rotatedarray.cpp}\n\nBy using a binary-search method with three nodes, the code above is successful\nin finding and returning the smallest element. This algorithm uses recursive\nfunctions, and shows the time complexity of the following:\n\\[ T(n)=2T\\left(\\frac{n}{2}\\right)+\\alpha=4T\\left(\\frac{n}{4}\\right)+3\\alpha=\n\\cdots=2^kT\\left(\\frac{n}{2^k}\\right)+\\frac{k(k+1)}{2}\\alpha,~\\therefore T(n)=\nO(\\log n) \\]\n\n\\iffalse\n\\section{With Duplicate Elements}\nWith duplicate elements, the time complexity cannot be kept at $\\log n$. Follow-\nup explanations for rotated arrays with duplicates will soon be committed.\n\\fi\n", "meta": {"hexsha": "db35b8d4f7e085821184bbe3020051a936127350", "size": 945, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/04_rotatedarray.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/04_rotatedarray.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/04_rotatedarray.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": 41.0869565217, "max_line_length": 80, "alphanum_fraction": 0.7555555556, "num_tokens": 261, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8705972616934408, "lm_q1q2_score": 0.7764082541062263}}
{"text": "\\problem{Induction 1}\n\nLet $n \\in \\mathcal{N}$. Conjecture a formula for:\n\n$$a_n = \\frac{1}{(1)(2)} + \\frac{1}{(2)(3)} + ... + \\frac{1}{(n)(n + 1)}$$\n\n\\solution\n\n\\part \n\n\\begin{theorem}\nThe formula $a_n = \\frac{n}{n + 1}$ describes the summation.\n\\end{theorem}\n\\begin{proof}\nProceeding by induction, it is first established that the formula works for $a_1$, because $a_1 = \\frac{1}{(1) * (2)} = \\frac{1}{2}$.\nThen, suppose the formula is true for an arbitrary $n \\geq 1$, i.e. that $a_n = \\frac{n}{n + 1}$.\nFrom this, $a_{n + 1} = \\frac{n}{n + 1} + \\frac{1}{(n + 1)(n + 2)} = \\frac{n^2 + 2n + 1}{(n + 1)(n + 2)} = \\frac{(n + 1)(n + 1)}{(n + 1)(n + 2)} = \\frac{n + 1}{n + 2}$.\nBy induction, this formula describes the summation $a_n$.\n\n\\end{proof}\n\n\\subsection{Scratch work}\n\n$a_1 = (1/2)$ \\\\\n$a_2 = (1/2) + (1/6) = 4/6 = 2/3$ \\\\\n$a_3 = (1/2) + (1/6) + (1/12) = 9/12 = 3/4$ \\\\\n\nA likely formula is $a_n = (n/n+1)$\n\n\n", "meta": {"hexsha": "ee726bd41b0e6d83f66184c0bbc6daeab7f88175", "size": 915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-12/problems/3.2.3.tex", "max_stars_repo_name": "LSaldyt/proofs", "max_stars_repo_head_hexsha": "13e92e5824cfc90fa4f440269167c7a59d8e11bc", "max_stars_repo_licenses": ["MIT"], "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-12/problems/3.2.3.tex", "max_issues_repo_name": "LSaldyt/proofs", "max_issues_repo_head_hexsha": "13e92e5824cfc90fa4f440269167c7a59d8e11bc", "max_issues_repo_licenses": ["MIT"], "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-12/problems/3.2.3.tex", "max_forks_repo_name": "LSaldyt/proofs", "max_forks_repo_head_hexsha": "13e92e5824cfc90fa4f440269167c7a59d8e11bc", "max_forks_repo_licenses": ["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.5161290323, "max_line_length": 168, "alphanum_fraction": 0.5486338798, "num_tokens": 407, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761565, "lm_q2_score": 0.8244619177503205, "lm_q1q2_score": 0.7763579900569686}}
{"text": "\\section{Math Extra}\r\n\\subsection{Combinatorial formulas}\r\n\r\n $\\sum_{k=0}^{n}k^{2}=n(n+1)(2n+1)/6$\\\\\r\n $\\sum_{k=0}^{n}k^{3}=n^{2}(n+1)^{2}/4$\\\\\r\n $\\sum_{k=0}^{n}k^{4}=(6n^{5}+15n^{4}+10n^{3}-n)/30$\\\\\r\n $\\sum_{k=0}^{n}k^{5}=(2n^{6}+6n^{5}+5n^{4}-n^{2})/12$\\\\\r\n $\\sum_{k=0}^{n}x^{k}=(x^{n+1}-1)/(x-1)$\\\\\r\n $\\sum_{k=0}^{n}kx^{k}=(x-(n+1)x^{n+1}+nx^{n+2})/(x-1)^{2}$\\\\\r\n ${n \\choose k}=\\frac{n!}{(n-k)!k!}$\\\\\r\n ${n \\choose k}={n-1 \\choose k}+{n-1 \\choose k-1}$\\\\\r\n ${n \\choose k}=\\frac{n}{n-k}{n-1 \\choose k}$\\\\\r\n ${n \\choose k}=\\frac{n-k+1}{k}{n \\choose k-1}$\\\\\r\n ${n+1 \\choose k}=\\frac{n+1}{n-k+1}{n \\choose k}$\\\\\r\n ${n \\choose k+1}=\\frac{n-k}{k+1}{n \\choose k}$\\\\\r\n $\\sum_{k=1}^{n}k\\tbinom{n}{k}=n2^{n-1}$\\\\\r\n $\\sum_{k=1}^{n}k^{2}\\tbinom{n}{k}=(n+n^{2})2^{n-2}$\\\\\r\n ${m+n \\choose r}=\\sum_{k=0}^{r}{m \\choose k}{n \\choose r-k}$\\\\\r\n ${n \\choose k}=\\prod_{i=1}^{k}\\frac{n-k+i}{i}$\\\\\r\n\r\n\\subsection{Number theory identities}\r\n\\textbf{Lucas' Theorem:} For non-negative integers $m$ and $n$ and a prime $p$,\r\n\r\n$$\\binom{m}{n}\\equiv\\prod_{i=0}^k\\binom{m_i}{n_i}\\pmod p,$$\r\nwhere\r\n$$m=m_kp^k+m_{k-1}p^{k-1}+\\cdots +m_1p+m_0$$\r\nis the base $p$ representation of $m$, and similarly for $n$.\r\n\r\n\\subsection{Stirling Numbers of the second kind}\r\nNumber of ways to partition a set of $n$ numbers into $k$ non-empty subsets.\r\n\r\n$${n \\brace k}=\\frac{1}{k!}\\sum_{j=0}^{k}(-1)^{(k-j)}{k \\choose j}j^n$$\r\n\r\nRecurrence relation:\r\n\r\n  $${0 \\brace 0}=1$$\r\n  $${n \\brace 0}={0 \\brace n}=1$$\r\n  $${n+1 \\brace k}=k{n \\brace k}+{n \\brace k-1}$$\r\n\r\n\r\n\\subsection{Burnside's Lemma}\r\nLet $G$ be a finite group that acts on a set $X$. For each $g$ in $G$ let $X^g$ denote the set of elements in $X$ that are fixed by $g$, which means $X^g=\\{x\\in X| g(x)=x\\}$. Burnside's lemma assers the following formula for the number of orbits, denoted $|X/G|$:\r\n\\begin{align*}\r\n|X/G|=\\frac{1}{|G|} \\sum_{g\\in G} |X^g|\r\n\\end{align*}\r\n\r\n\\subsection{Numerical integration}\r\nRK4: to integrate $\\dot{y} = f(t, y)$ with $y_0 = y(t_0)$, compute\r\n\\begin{align*}\r\n  k_1 &= f(t_n, y_n) \\\\\r\n  k_2 &= f(t_n + \\frac h 2, y_n + \\frac h 2 k_1) \\\\\r\n  k_3 &= f(t_n + \\frac h 2, y_n + \\frac h 2 k_2) \\\\\r\n  k_4 &= f(t_n + h, y_n + h k_3) \\\\\r\n  y_{n+1} &= y_n + \\frac h 6 (k_1 + 2k_2 + 2k_3 + k_4) \r\n\\end{align*}\r\n", "meta": {"hexsha": "2cc362cf2dbf84cf88dfb5d80c5c3c9002ec5115", "size": 2252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook-generator/mathextra.tex", "max_stars_repo_name": "hsnavarro/icpc-notebook", "max_stars_repo_head_hexsha": "5e501ecdd56a2a719d2a3a5e99e09d926d7231a3", "max_stars_repo_licenses": ["MIT"], "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-generator/mathextra.tex", "max_issues_repo_name": "hsnavarro/icpc-notebook", "max_issues_repo_head_hexsha": "5e501ecdd56a2a719d2a3a5e99e09d926d7231a3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebook-generator/mathextra.tex", "max_forks_repo_name": "hsnavarro/icpc-notebook", "max_forks_repo_head_hexsha": "5e501ecdd56a2a719d2a3a5e99e09d926d7231a3", "max_forks_repo_licenses": ["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.2142857143, "max_line_length": 264, "alphanum_fraction": 0.541740675, "num_tokens": 1054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8333245932423308, "lm_q1q2_score": 0.7762106147395985}}
{"text": "% !TEX root = report.tex\n\\section{Introduction}\n\n\n\\subsection{Basic definition of database system}\n\nIn database systems, a \\textbf{database} is a collection of tables, and each \\textbf{table} stores one coherent dataset. Each row of a table represents a single data point and each column represents an attribute of the data. Theoretically speaking, a table is merely a mathematical \\textbf{relation} over one or more sets of scalar values (numbers, strings, etc.) and each row of the table is a \\textbf{tuple} (or an element) in such relation.\n\nFor the sake of keeping our explanation simple, the relationship of data across different tables can be expressed by declaring \\textbf{keys} (usually referred as IDs) as explicit columns in the table. Each row of a table may have a \\textbf{primary key} declared as an anchor point to which other tables can refer to with \\textbf{foreign keys}. In practice, since integers can be used as keys, it is sufficient to portray keys no different than other scalar values. Therefore, we omit the keys from our discussion for the rest of this project.\n\n\\smallskip\n\\marginhead{First example of database}\nFor example, let us say that we would like to construct a database to store information of four students: Alice, Bob, Carol, and David. The database must contain their personal data (e.g. year of birth) as well as a network graph representing their friendship relation. One possibility is that we create two tables, described below.\n\n\\newrobustcmd\\nameA{\\field{Name\\hrsp{}A}}\n\\newrobustcmd\\nameB{\\field{Name\\hrsp{}B}}\n\\newrobustcmd\\personaldata{\\rel{PersonalData}(\\field{Name},\\field{BirthYear})}\n\\newrobustcmd\\friendship{\\rel{Friendship}(\\nameA,\\nameB)}\n\n\\begin{itemize}[topsep=0.5pc,itemsep=0.25pc]\n    \\item  $\\personaldata$: a two-column table containing each student's name and year of birth;\n    \\item  $\\friendship$: a (possibly non-symmetric) two-column table where each row contains names and only names of two students who are friends of each other.\n\\end{itemize}\nAn example of an instance of such database are shown in \\autoref{tab:age} and \\autoref{tab:friend}, and the visualization is shown in \\autoref{fig:alicebob}.\n\n\\smallskip\n\\begin{table}[!h]\n    \\small\\centering\n    \\begin{minipage}{0.45\\linewidth}\n        \\centering\n        \\begin{tabular}{ll}\n            \\toprule\n            \\field{Name} & \\field{BirthYear} \\\\\n            \\midrule\n            \\str{Alice} & \\val{1994} \\\\\n            \\str{Bob} & \\val{1995} \\\\\n            \\str{Carol} & \\val{1994} \\\\\n            \\str{David} & \\val{1993} \\\\\n            \\bottomrule\n        \\end{tabular}\n        \\caption{Table \\rel{PersonalData} with four students: Alice, Bob, Carol, and David, and their corresponding year of birth.}\n        \\label{tab:age}\n    \\end{minipage}\n    \\begin{minipage}{0.45\\linewidth}\n        \\centering\n        \\begin{tabular}{ll}\n            \\toprule\n            \\nameA & \\nameB \\\\\n            \\midrule\n            \\str{Alice} & \\str{Bob} \\\\\n            \\str{Bob} & \\str{Carol} \\\\\n            \\str{Alice} & \\str{Carol} \\\\\n            \\str{Carol} & \\str{David} \\\\\n            \\bottomrule\n        \\end{tabular}\n        \\caption{Table \\rel{Friendship} showing that Alice, Bob, and Carol know each other, but David knows only Carol.}\n        \\label{tab:friend}\n    \\end{minipage}\n\\end{table}\n\\begin{figure}[!h]\n    \\small\\centering\n    \\begin{minipage}[b]{0.35\\linewidth}\n        \\caption{The visualization of data in the table \\rel{PersonalData} and \\rel{Friendship}.}\n        \\label{fig:alicebob}\n    \\end{minipage}\n    \\begin{minipage}[b]{0.55\\linewidth}\n        \\includegraphics[width=0.8\\linewidth]{figures/alicebob.eps}\n    \\end{minipage}\n\\end{figure}\n\n\\newpage\n\\subsection{Database query model}\n\nOne of the most basic database function is the \\textbf{query} function, i.e., the process of fetching the stored data from the database. SQL model is an example of one of the most practical query model adopted in industry. Nonetheless, it is also useful to discuss theoretical query models (such as \\textbf{relational calculus} and \\textbf{relational algebra}) in order to gain a better understanding of database query models.\n\n\\marginhead{Definition of Domain Relational Calculus}In this report, we mainly discuss one particular variant of relational calculus query model, namely the \\textbf{domain relational calculus} (\\textsc{drc}). In this model,\n\\begin{itemize}[topsep=0.5pc,itemsep=0.25pc]\n    \\item  We use set comprehension notation (i.e., set defined by a predicate) to construct a query result. Such predicate must be in first-order logic.\n    \\item  Each identifier in the set comprehension must represent a scalar value in the database (as opposed to representing a tuple in tuple relational calculus).\n\\end{itemize}\n\n\\phantomsection\n\\label{psec:table-name-pred}\n\\marginhead{Table names as predicates}\nAs part of the predicate in set comprehension, the following notation regarding the existence of a tuple in a database table is allowed.\n\n\\begin{notation}\n    Suppose that $R$ is a database table with $m$ columns. Let $\\boldsymbol{x} = \\langle x_1, x_2, \\ldots, x_m \\rangle$ be an $m$-tuple, where each $x_i$ represents a scalar value. Then $R(\\boldsymbol{x})$ denotes a predicate whose value is true \\emph{if and only if} the table $R$ contains the tuple $\\boldsymbol{x}$. Sometimes we also write $R(x_1, x_2, \\ldots, x_m)$ directly instead.\n\\end{notation}\n\nFor example, based on the data from \\autoref{tab:age}, we could say that $\\rel{PersonalData}(\\str{Alice}, \\val{1994})$ is true whereas $\\rel{PersonalData}(\\str{Bob}, \\val{1993})$ is false.\n\n\\marginhead{Examples of \\textnormal{\\textsc{drc}} queries}\nHere are some examples of \\textsc{drc} queries.\n\n\\smallskip\n\\begin{example}\n    Suppose that we want to obtain all students and their year of birth who were born \\emph{strictly} before \\val{1995} (using the database table $\\personaldata$ as described in \\autoref{tab:age}). We use the following \\textsc{drc} query.\n    \\[\n        Q_\\text{\\,before\\,\\val{1995}} = \\{\\var{name}, \\var{year} \\mid\n            \\rel{PersonalData}(\\var{name}, \\var{year}) \\wedge (\\var{year} < \\val{1995})\\}\n    \\]\n    This query returns a set of three tuples: $\\{(\\str{Alice},\\val{1994}),(\\str{Carol},\\val{1994}),(\\str{David},\\val{1993})\\}$.\n\\end{example}\n\n\\begin{example}\n    Suppose that we want to obtain all friends of Bob (based on the database table $\\friendship$ from \\autoref{tab:friend}). We use the following \\textsc{drc} query.\n    \\[\n        Q_\\text{\\,Bob's\\,friend} = \\{\\var{name} \\mid\n            \\rel{Friendship}(\\var{name}, \\str{Bob}) \\vee\n            \\rel{Friendship}(\\str{Bob}, \\var{name})\\}\n    \\]\n    This query returns a set of two elements: $\\{\\str{Alice},\\str{Carol}\\}$. \\emph{Note that we sometimes omit the tuple notation when it contains only a single column.}\n\\end{example}\n\n\\newpage\n\\begin{example}\n    Suppose that we want to obtain all pairs of students who share a common friend using the same data as above. We use the following query.\n    \\begin{align*}\n        Q_\\text{\\,friend\\,of\\,friend} = \\{ x, y \\mid (x < y) \\wedge \\exists z[\n                &(\\rel{Friendship}(x, z) \\vee \\rel{Friendship}(z, x)) \\\\\n                &\\quad\\wedge (\\rel{Friendship}(y, z) \\vee \\rel{Friendship}(z, y))\n            ]\\}\n    \\end{align*}\n    This query would return $\\{(\\str{Alice},\\str{Bob}),(\\str{Alice},\\str{Carol}),(\\str{Bob},\\str{Carol}),(\\str{Alice},\\str{David}),$ $(\\str{Bob},\\str{David})\\}$. \\emph{This query utilizes the existential quantification in first-order logic to represent a friend in common between two students. Also assume that $<$ does a lexicographical comparison of two strings.}\n\\end{example}\n\n\\medskip\n\\phantomsection\n\\label{psec:explicit-domain}\nNotice how the domain for variables (such as \\var{name} and \\var{year}) are not explicit in the query. This is okay because predicates \\rel{PersonalData} and \\rel{Friendship} provides the \\emph{finite bound} of what could be in the result of the query. We discuss this in more depth in the next subsection.\n\n\n\\subsection{Safety in \\textsc{drc} queries}\n\n\\marginhead{Motivated example of unsafe queries}\n\\noindent\nLet us consider the query $Q_\\text{\\,before\\,\\val{1995}}$ from above once again. You may have noticed that, at least in the paradigm of database systems, it would \\emph{not} make practical sense to make such query but \\emph{without} the predicate $\\rel{PersonalData}(\\var{name}, \\var{year})$. If it was the case, then the result of the query would also have included tuples that are \\emph{not} from the table \\rel{PersonalData} in order to be consistent with the mathematical definition of set notation.\n\nMore concretely, the result of\n\\[\n    Q^*_\\text{\\,before\\,\\val{1995}} = \\{\\var{name}, \\var{year} \\mid\n        \\var{year} < \\val{1995}\\}\n\\]\nwould change depending on what is defined as the scope or the domain of the scalar values. For example, if all nonempty strings are allowed for student names, and all integers are allowed for year of birth, then $(\\str{Eve}, \\val{-80})$ would be part of the query result. However, if the domain only allows positive integers for year of birth, then the same tuple would \\emph{not} appear in the result.\n\n\\marginhead{Definition of safe vs. unsafe query}\nWe call queries like $Q^*_\\text{\\,before\\,\\val{1995}}$ \\textbf{unsafe} as their result changes when the domain changes (i.e., results are \\textbf{domain-dependent}). On the other hand, queries such as $Q_\\text{\\,before\\,\\val{1995}}$ and $Q_\\text{\\,Bob's\\,friend}$ are examples of \\textbf{safe} queries because the result of the query is always the same no matter what the scope of the domain is. In other words, their results rely only on data in the database. See Chapter 5 of \\emph{Foundations of Databases} \\cite[p.~75]{Abiteboul:1995:FDL:551350} for more information.\n\nThe concept of domain-dependency was summarized by Fagin in his paper \\cite{Fagin:1982:HCD:322344.322347} and it was historically different from the \\emph{original} meaning of safety of query formulae as introduced by Ullman \\cite{Ullman:1983:PDS:538906}. For this project, we adopt a certain assumption \\cite{Abiteboul:1988:inria-00075707} so we refer to a query as \\textbf{safe} \\emph{interchangeably} with the term \\textbf{domain-independent}.\n\n\\newpage\n\\marginhead{More examples of unsafe queries}\nNow let us consider a few more examples of unsafe queries. Assume that we have a database table $\\rel{Follows}(\\field{fan}, \\field{idol})$ representing the fact that \\field{fan} is following \\field{idol} on a social network. Consider the following queries in \\textsc{drc}.\n\n\\smallskip\n\\begin{example}\n    \\label{ex:not-follow}\n    \\[\n        Q_\\text{\\,not\\,following\\,Alice} =\n            \\{ x \\mid \\neg\\,\\rel{Follows}(x, \\str{Alice}) \\}\n    \\]\n    The first query, $Q_\\text{\\,not\\,following\\,Alice}$, returns a set of all people who did not follow Alice. It is unsafe because, for some database instance (such as when no one follows Alice), the result of the query will be every person within the domain. Hence, the result would be domain-dependent.\n\\end{example}\n\n\\begin{example}\n    \\[\n        Q_\\text{\\,weird\\,pairing} =\n            \\{ x, y \\mid \\rel{Follows}(x, \\str{Alice}) \\vee \\rel{Follows}(y, \\str{Bob}) \\}\n    \\]\n    The second query, $Q_\\text{\\,weird\\,pairing}$, returns a set of pairs of people such that the first person follows Alice, or that the second person follows Bob. This query is also not safe. One counterexample is that no one follows Alice but Alice is the only person who follows Bob. Then $(x, \\str{Alice})$ will appear in result for every $x$ in the domain of people, and thus is domain-dependent.\n\\end{example}\n\n\\begin{example}\n    \\label{ex:follow-all}\n    \\[\n        Q_\\text{\\,follows\\,all} =\n            \\{ x \\mid \\forall y[\\rel{Follows}(x, y)] \\}\n    \\]\n    The third query $Q_\\text{\\,follows\\,all}$ returns a set of people who follows everyone in the domain. Notice how the result for this query is guaranteed to be bounded even if the domain was infinite. However, suppose that Alice follows everyone in the domain $D_1$. If the domain $D_2$ is defined as $D_2 = D_1 \\cup \\{\\str{Bob}\\}$ where $\\str{Bob} \\not\\in D_1$, then Alice would appear in the result when the domain $D_1$ is used, but would \\emph{not} if $D_2$ is used. Therefore, query $Q_\\text{\\,follows\\,all}$ is domain-dependent.\n\\end{example}\n\n\n\\subsection{Project goal and previous work}\n\\label{sub:goal}\n\nThe goal for this project is to study and analyze the safety of a query in \\textsc{drc} model for a specified database schema using Alloy Analyzer (introduced in the next section). Specifically,\n\n\\begin{quote}\n    \\makebox[0pt][r]{``}Given a database schema $S$ and a query $Q$, does there exist a database instance under two \\emph{distinct} domains $D_1$ and $D_2$ such that the respective results $R_1$ and $R_2$ differ. If so, then the query $Q$ is considered unsafe; otherwise it is safe.''\n\\end{quote}\n\nThe verification of data models using Alloy Analyzer has been investigated in prior work, including the data models whose specifications are in relational database schemata \\cite{Cunha:2009:MAS:1685167.1685438} and other specification language such as \\textsc{ora-ss} \\cite{Wang:2006:VOD:1129030.1129454}.\nThe verification of data models in the context of web applications has also been studied \\cite{Nijjar:2011:BVR:2001420.2001429,Nijjar:2015:DMP:2820114.2699691}. However, none of them involved the modeling of database relational queries.\nAlso note that we traditionally use Codd's Theorem \\cite{codd1972relational} to verify whether a \\textsc{drc} query is safe by providing an equivalent relational algebra query statement, which is outside the scope of this project.\n\nAlthough relational calculus is not a practical way to make a query to the database, this project should provide an insight into the fundamental concepts of database theory as well as provide us a framework to help us on determining whether a \\textsc{drc} query is safe, a task usually tediously done by humans due to its complexity.\n", "meta": {"hexsha": "58b735d55140b49f3b61e0ef3d3746c5b053f583", "size": 14020, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "master-project/report/ch01_intro.tex", "max_stars_repo_name": "abhabongse/relationalcalculus-alloy", "max_stars_repo_head_hexsha": "1be5a4d76e8c7c6f61ac18a5c987cc2fe1d7216d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-03-08T16:30:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-08T16:30:55.000Z", "max_issues_repo_path": "master-project/report/ch01_intro.tex", "max_issues_repo_name": "abhabongse/relationalcalculus-alloy", "max_issues_repo_head_hexsha": "1be5a4d76e8c7c6f61ac18a5c987cc2fe1d7216d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-03-11T18:47:49.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-23T20:37:09.000Z", "max_forks_repo_path": "master-project/report/ch01_intro.tex", "max_forks_repo_name": "abhabongse/relationalcalculus-alloy", "max_forks_repo_head_hexsha": "1be5a4d76e8c7c6f61ac18a5c987cc2fe1d7216d", "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.8080808081, "max_line_length": 571, "alphanum_fraction": 0.717189729, "num_tokens": 3871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625050654263, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7762106073706058}}
{"text": "\\chapter{Logistic Regression}\n\\label{ch:logistic_regression}\n\nLogistic regression is one of the best-known classifiers. The model returns the probability of a class variable, based on input features. First, it computes probabilities with a one-versus-all approach, meaning that for a multiclass problem, it will take one target value and treat all the rest as \"other\", effectively transforming the problem to binary classification.\n\nSecond, it tries to find an optimal plane that separates instances with the target value from the rest. Then it uses logistic function to transform the distance to the plane into probabilities. The further away from the plane an instance will be, the higher the probability it belongs to the class on that side of the plane. The closer it is to the decision boundary (the plane), the more uncertain the prediction becomes (i.e. it gets close to 0.5).\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{logistic-regression.png}%\n    \\caption{Can you guess what would the probability for belonging to the blue class be for A, B, and C?}\n    \\label{fig:logreg}\n  \\end{marginfigure}\n\nLogistic regression tries to find such a plane that all points from one class are as far away from the boundary (in the correct direction) as possible.\n\n\\begin{marginfigure}\n    \\includegraphics[width=\\textwidth]{workflow.png}%\n    \\label{fig:workflow}\n  \\end{marginfigure}\n\nA great thing about \\widget{Logistic Regression} is that we can interpret it with a \\widget{Nomogram}. Nomogram shows the importance of variables for the model. The higher the variable is in the list, the greater its importance. Also, the longer the line, the greater the importance. The line corresponds to the coefficient of the variable, which is then mapped to the probability. You can drag the blue point on the line left or right, decreasing or increasing the probability of the target class. This will show you how different values affect the outcome of the model.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.4]{nomogram.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nAnother characteristic of logistic regression is that it observes all variables at once and takes the correlation into account. If some variables are correlated, their importance will be spread among them.\n\nA not so great thing about logistic regression is that it operates with planes, meaning that the model won't work when the data cannot be separated in such a way. Can you think of such a data set?\n", "meta": {"hexsha": "39c89e8656301c92bb7950bc21e8e1ca094f7863", "size": 2487, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/023-logistic-regression/logistic-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/023-logistic-regression/logistic-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/023-logistic-regression/logistic-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": 77.71875, "max_line_length": 571, "alphanum_fraction": 0.7844792923, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094088947399, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7761311354303067}}
{"text": "\\section*{Appendix}\n\nIn this part, several interesting constructions are listed, \nwhile others are left in \\mintinline{bash}|./libs/Init/Prelude.v|.\n\n\\subsection*{Boolean}\n\\begin{center}\n\\begin{minted}{coq}\nInductive True : Type :=\n| I : True.\n\nInductive False : Type :=.\n\nInductive and (A : Type) (B : Type) : Type :=\n| conj : A -> B -> and A B.\n\nInductive or (A : Type) (B : Type) : Type :=\n| or_introl : A -> or A B\n| or_intror : B -> or A B.\n\\end{minted}\n\\end{center}\n\n\\subsection*{Logic}\n\\begin{center}\n\\begin{minted}{coq}\nDefinition If_then_else (P : Type) (Q : Type) (R : Type) : Type :=\n    or (and P Q) (and (not P) Q).\n\nDefinition not (A : Type) : Type :=\n    A -> False.\n\nDefinition iff (A : Type) (B : Type) : Type :=\n    and (A -> B) (B -> A).\n\nInductive ex (A : Type) (P : A -> Type) : Type :=\n| ex_intro : forall (x : A), P x -> ex A P.\n\nInductive eq (A : Type) (x : A) : A -> Type :=\n| eq_refl : eq A x x.\n\\end{minted}\n\\end{center}\n\n\\subsection*{Natural Number}\n\\begin{center}\n\\begin{minted}{coq}\nInductive nat : Type :=\n| O : nat\n| S : nat -> nat.\n\nFixpoint plus (n : nat) (m : nat) : nat :=\n    match n as n0 in nat return nat with\n    | O => m\n    | S n1 => S (plus n1 m)\n    end.\n\nFixpoint multiply (n : nat) (m : nat) : nat :=\n    match n as n0 in nat return nat with\n    | O => O\n    | S n1 => plus m (multiply n1 m)\n    end.\n\nFixpoint power (n : nat) (m : nat) : nat :=\n    match m as m0 in nat return nat with\n    | O => S O\n    | S m1 => multiply n (power n m1)\n    end.\n\\end{minted}\n\\end{center}\n\n\\subsection*{List}\n\\begin{center}\n\\begin{minted}{coq}\nInductive list (T : Type) : Type :=\n| nil : list T\n| cons : T -> list T -> list T.\n\nInductive iliist (T : Type) : nat -> Type :=\n| inil : ilist T O\n| icons : forall (n : nat), T -> ilist T n -> ilist T (S n).\n\\end{minted}\n\\end{center}\n", "meta": {"hexsha": "25553ca390f394490d818f407d9c64c4a3ffb789", "size": 1812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/appendix.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/appendix.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/appendix.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": 22.0975609756, "max_line_length": 66, "alphanum_fraction": 0.5805739514, "num_tokens": 632, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.936285009303773, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7761229838181661}}
{"text": "\\section*{Binary Classification}\nA set of $N_{\\text{act}}$ data instances undergo binary classification\nprediction. \n\n\\subsection*{Count}\n\n\\begin{itemize}\n\\item [true (positive, negative):] $N_{\\text{tp}}, N_{\\text{tn}}$\n%\\item [true negative:] $N_{\\text{tn}}$\n\\item [false (positive, negative):] $N_{\\text{fp}}, N_{\\text{fn}}$\n%\\item [false negative:] $N_{\\text{fn}}$\n\\item [actual positive:] $N_{\\text{act-p}} = N_{\\text{tp}} + N_{\\text{fn}}$\n\\item [actual negative:] $N_{\\text{act-n}} = N_{\\text{tn}} + N_{\\text{fp}}$\n\\item [predicted positive:] $N_{\\text{prd-p}} = N_{\\text{tp}} + N_{\\text{fp}}$\n\\item [predicted negative:] $N_{\\text{prd-n}} = N_{\\text{tn}} + N_{\\text{fn}}$\n\\item [predicted true:] $N_{\\text{prd-t}} = N_{\\text{tp}} + N_{\\text{tn}}$\n\\item [predicted false:] $N_{\\text{prd-f}} = N_{\\text{fp}} + N_{\\text{fn}}$\n\\item [predicted:] $N_{\\text{prd}} = N_{\\text{prd-p}} + N_{\\text{prd-n}} =\n  N_{\\text{prd-t}} + N_{\\text{prd-f}}$\n\\item [actual:] $N_{\\text{act}} = N_{\\text{prd}}$\n\\end{itemize}\n\n\\subsection*{Classify}\n\\begin{itemize}\n\\item [true positive rate:] $R_{\\text{tp}} = N_{\\text{tp}} / N_{\\text{act-p}}$\n\\item [true negative rate:] $R_{\\text{tn}} = N_{\\text{tn}} /\n  N_{\\text{act-n}}$\n\\item [accuracy:] $R_{\\text{accur}} = N_{\\text{prd-t}} / N_{\\text{act}}$\n\\item [error:] $R_{\\text{error}} = N_{\\text{prd-f}} / N_{\\text{act}} = 1 - R_{\\text{accur}}$\n\\item [precision:] $R_{\\text{precis}} = N_{\\text{tp}} / N_{\\text{prd-p}}$\n\\item [recall:] $R_{\\text{recall}} = N_{\\text{tp}} / N_{\\text{act-p}} = R_{\\text{tp}}$\n\\item [sensitivity:] $R_{\\text{sensit}} = N_{\\text{tp}} / N_{\\text{act-p}}\n  = R_{\\text{tp}} = R_{\\text{recall}}$\n\\item [specificity:] $R_{\\text{specif}} = N_{\\text{tn}} / N_{\\text{act-n}}\n  = R_{\\text{tn}}$\n\\item [positive likelihood:] $R_{\\text{lkl-pos}} = R_{\\text{sensit}} / (1 - R_{\\text{specif}})$\n\\item [negative likelihood:] $R_{\\text{lkl-neg}} = (1 -\n  R_{\\text{sensit}}) / R_{\\text{specif}}$\n\\item [normalized likelihood:] \\mbox{}\\\\%\n  $R_{\\text{lkl-norm}} = (\\sqrt{3}/\\pi)\n  [\\log(R_{\\text{lkl-pos}}) + \\log(R_{\\text{lkl-neg}})]$\n\\item [Youden's index:] $R_{\\text{Youden}} = R_{\\text{sensit}} - (1 -\n  R_{\\text{specif}})$\n\\end{itemize}\n\n\\subsection*{Combine}\n\\begin{itemize}\n\\item [balanced classification:] $R_{\\text{bcr}} = (R_{\\text{tp}} +\n  R_{\\text{tn}})/2 = (R_{\\text{sensit}} + R_{\\text{specif}}) / 2$\n\\item [balanced error:] $R_{\\text{ber}} = 1 - R_{\\text{bcr}}$\n\\item [$F_1$-measure:] $F_1 = 2(R_{\\text{precis}} R_{\\text{recall}}) / (R_{\\text{precis}} + R_{\\text{recall}})$\n\\item [$F_{\\beta}$-measure:] \\mbox{}\\\\ $F_{\\beta} = (1+\\beta^2) (R_{\\text{precis}}\n  R_{\\text{recall}}) / (\\beta^2R_{\\text{precis}} + R_{\\text{recall}})$\n\\item [Matthew's correlation coefficient:] \\mbox{}\\\\ $C_{\\text{Matthews}} =\n  (N_{\\text{tp}}N_{\\text{tn}} - N_{\\text{fp}}N_{\\text{fn}}) / %\n  \\sqrt{N_{\\text{act-p}} N_{\\text{prd-p}} N_{\\text{act-n}} N_{\\text{prd-n}}}$\n\\end{itemize}\n", "meta": {"hexsha": "081fc7dd720d40e5ec875a1bd9d35d9f6503891e", "size": 2915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Mathematics/units/unit_BinaryClassification.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_BinaryClassification.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_BinaryClassification.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": 50.2586206897, "max_line_length": 111, "alphanum_fraction": 0.5945111492, "num_tokens": 1214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850004144266, "lm_q2_score": 0.8289388146603365, "lm_q1q2_score": 0.7761229784277874}}
{"text": "\\lab{Nearest Neighbor Search}{Nearest Neighbor Search}\n\n\\objective{The nearest neighbor problem is an optimization problem that arises in applications such as computer vision, internet marketing, and data compression.\nThe problem can be solved efficiently with a $k$-d tree, a generalization of the binary search tree.\nIn this lab we implement a $k$-d tree, use it to solve the nearest neighbor problem, then use that solution as the basis of an elementary machine learning algorithm.}\n\n\\section*{The Nearest Neighbor Problem} % =====================================\n\nLet $X \\subset \\mathbb{R}^k$ be a collection of data, called the \\emph{training set}, and let $\\z \\in \\mathbb{R}^k$, called the \\emph{target}.\nThe \\emph{nearest neighbor search problem} is determining the point $\\x^* \\in X$ that is ``closest'' to $\\z$.\n\nFor example, suppose you move into a new city with several post offices.\nSince your time is valuable, you wish to know which post office is closest to your home.\nThe set $X$ could be addresses or latitude and longitude data for each post office in the city; $\\z$ would be the data that represents your new home.\nThe task is to find the closest post office in $\\x \\in X$ to your home $\\z$.\n\n\\subsection*{Metrics and Distance} % ------------------------------------------\n\nSolving the nearest neighbor problem requires a definition for distance between $\\z$ and elements of $X$.\nIn $\\mathbb{R}^k$, distance is typically defined by the \\emph{Euclidean metric}.\n\\begin{align}\n\\label{eq:nearest-neighbor-euclidean-metric}\nd(\\x,\\z) = \\|\\x - \\z\\| = \\sqrt{\\sum_{i=1}^k(x_i-z_i)^2}\n\\end{align}\nHere $\\|\\cdot\\|$ is the standard \\emph{Euclidean norm}, which computes vector length.\nIn other words, $d(\\x,\\z)$ is the length of the straight line from $\\x$ to $\\z$.\nWith this notation, the nearest neighbor search problem can be written as follows.\n\\begin{align}\n\\label{eq:nearest-neighbor-def}\n\\x^* = \\underset{\\x\\in X}{\\text{argmin}}\\:d(\\x,\\z)\n\\qquad\\qquad\nd^* = \\min_{\\x\\in X}d(\\x,\\z)\n\\end{align}\n\nNumPy and SciPy implement the Euclidean norm (and other norms) in \\li{linalg.norm()}.\nThis function accepts vectors or matrices.\nUse the \\li{axis} argument to compute the norm along the rows or columns of a matrix: \\li{axis=0} computes the norm of each column, and \\li{axis=1} computes the norm of each row (see the NumPy Visual Guide).\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n>>> x0 = np.array([1, 2, 3])\n>>> x1 = np.array([6, 5, 4])\n\n# Calculate the length of the vectors x0 and x1 using the Euclidean norm.\n>>> la.norm(x0)\n3.7416573867739413\n>>> la.norm(x1)\n8.7749643873921226\n\n# Calculate the distance between x0 and x1 using the Euclidean metric.\n>>> la.norm(x0 - x1)\n5.9160797830996161\n\n>>> A = np.array([[1, 2, 3],        # or A = np.vstack((x0,x1)).\n...               [6, 5, 4]])\n>>> la.norm(A, axis=0)              # Calculate the norm of each column of A.\narray([ 6.08276253,  5.38516481,  5.        ])\n>>> la.norm(A, axis=1)              # Calculate the norm of each row of A.\narray([ 3.74165739,  8.77496439])   # This is ||x0|| and ||x1||.\n\\end{lstlisting}\n\n\\subsection*{Exhaustive Search} % ---------------------------------------------\n\nConsider again the post office example.\nOne way to find out which post office is closest is to drive from home to each post office, measuring the distance travelled in each trip.\nThat is, we solve \\eqref{eq:nearest-neighbor-def} by computing $\\|\\x - \\z\\|$ for every point $\\x\\in X$.\nThis strategy is called a \\emph{brute force} or \\emph{exhaustive search}.\n\n\\begin{problem} % Exhaustive search method.\nWrite a function that accepts a $m\\times k$ NumPy array $X$ (the training set) and a 1-dimensional NumPy array $\\z$ with $k$ entries (the target).\nEach of the $m$ rows of $X$ represents a point in $\\mathbb{R}^k$ that is an element of the training set.\n\nSolve \\eqref{eq:nearest-neighbor-def} with an exhaustive search.\nReturn the nearest neighbor $\\x^*$ and its distance $d^*$ from the target $\\z$.\n\\\\(Hint: use array broadcasting and the \\li{axis} argument to avoid using a loop.)\n\\label{prob:nearest-neighbor-exhaustive-search}\n\\end{problem}\n\nThe complexity of an exhaustive search for $X\\subset\\mathbb{R}^k$ with $m$ points is $O(km)$, since \\eqref{eq:nearest-neighbor-euclidean-metric} is $O(k)$ and there are $m$ norms to compute.\nThis method works, but it is only feasible for relatively small training sets.\nSolving the problem with greater efficiency requires the use of a specialized data structure.\n\n\\section*{K-D Trees} % ========================================================\n\n% \\footnote{This lab is a sequel to the Data Structures II lab, and should not be attempted until the reader has successfully implemented a binary search tree in Python.}\nA \\href{https://en.wikipedia.org/wiki/K-d_tree}{\\emph{$k$-d tree}} is a generalized binary search tree where each node in the tree contains $k$-dimensional data.\nJust as a BST makes searching easy in $\\mathbb{R}$, a $k$-d tree provides a way to efficiently search $\\mathbb{R}^k$.\n\nA BST creates a partition of $\\mathbb{R}$: if a node contains the value $x$, all of the nodes in its left subtree contain values that are less than $x$, and the nodes of its right subtree have values that are greater than $x$.\nSimilarly, a $k$-d tree partitions $\\mathbb{R}^k$.\nEach node is assigned a \\emph{pivot} value $i \\in \\{0,1,\\ldots,k-1\\}$ corresponding to the depth of the node: the root has $i=0$, its children have $i=1$, their children have $i=2$, and so on.\nIf a node has $i=k-1$, its children have $i=0$, their children have $i=1$, and so on.\n% In general, if a node has \\li{pivot} $i$, its children have an \\li{pivot} of $(i + 1) \\mod k$.\nThe tree is constructed such that for a node containing $\\x = [x_0,x_1,\\ldots,x_{k-1}]\\trp \\in\\mathbb{R}^k$, if a node in the left subtree contains $\\y$, then $y_i < x_i$.\nConversely, if a node in the right subtree contains $\\z$, then $x_i \\le z_i$.\nSee Figure \\ref{fig:nearest-neighbor-pivot-tree} for an example where $k = 3$.\n\n% The case where $k=1$ results in a usual BST, since each value in the tree is a member of $\\mathbb{R}$.\n\n\\begin{figure}[H] % 3-d tree with pivot entries marked.\n\\begin{tikzpicture}[\n    level 1/.style={sibling distance=7cm},\n    level 2/.style={sibling distance=4cm},\n    level 3/.style={sibling distance=3cm},\n    level 4/.style={sibling distance=3cm},\n    edge from parent/.style={draw, ->,thick, >=stealth'}]\n\n    % Place the nodes and labels\n    \\node [thick,circle,draw] (a) {$[\\textcolor{red}{3},1,4]$}\n        child {node[thick,circle,draw] (b) {$[1,\\textcolor{red}{2},7]$}\n            child {node[thick,circle,draw] (c) {$[2,0,\\textcolor{red}{3}]$}}\n            child {node[thick,circle,draw] (d) {$[2,4,\\textcolor{red}{5}]$}\n                child {node[thick,circle,draw] (e) {$[\\textcolor{red}{1},4,3]$}}\n                child {node[thick,circle,draw] (f) {$[\\textcolor{red}{0},5,7]$}}}}\n        child {node[thick,circle,draw] (g) {$[4,\\textcolor{red}{3},5]$}\n            child {node[thick,circle,draw] (h) {$[6,1,\\textcolor{red}{4}]$}\n                child {node[draw = none] (invisble) {} edge from parent[draw=none]}\n                child {node[thick,circle,draw] (i) {$[\\textcolor{red}{5},2,5]$}}}\n            child {node[draw = none] (invisble1) {} edge from parent[draw=none]}};\n\n    % pivot labels\n    \\node [draw=none,red,node distance=5.7cm]  (1) [right of=a] {\\li{pivot=0}};\n    \\node [draw=none,red,node distance=2.18cm] (2) [right of=g] {\\li{pivot=1}};\n    \\node [draw=none,red,node distance=4.19cm] (3) [right of=h] {\\li{pivot=2}};\n    \\node [draw=none,red,node distance=2.69cm] (4) [right of=i] {\\li{pivot=0}};\n\\end{tikzpicture}\n\n\\caption{A $k$-d tree with $k = 3$.\nThe root $[\\textcolor{red}{3},1,4]$ has an \\li{pivot} of $0$, so $[1,2,7]$ is to the left of the root because $1<\\textcolor{red}{3}$, and $[4,3,5]$ is to the right since $\\textcolor{red}{3} \\le 4$.\nSimilarly, the node $[2,4,\\textcolor{red}{5}]$ has an \\li{pivot} of $2$, so $[1,4,3]$ is to its left since $4<\\textcolor{red}{5}$ and $[0,5,7]$ is to its right because $\\textcolor{red}{5}\\le 7$.\nThe nodes that are furthest from the root have an \\li{pivot} of $0$ because their parents have an \\li{pivot} of $2 = k - 1$.}\n\\label{fig:nearest-neighbor-pivot-tree}\n\\end{figure}\n\n\\begin{problem} % Write a KDTNode class from scratch.\nWrite a \\li{KDTNode} class whose constructor accepts a single parameter $\\x \\in \\mathbb{R}^k$.\nIf $\\x$ is not a NumPy array (of type \\li{np.ndarray}), raise a \\li{TypeError}.\nSave $\\x$ as an attribute called \\li{value}, and initialize attributes \\li{left}, \\li{right}, and \\li{pivot} as \\li{None}.\nThe \\li{pivot} will be assigned when the node is inserted into the tree, and \\li{left} and \\li{right} will refer to child nodes.\n\\end{problem}\n\n% Now we construct the $k$-d tree class.\n% For an optimal $k$-d tree, the data needs to be inserted in a very particular order.\n% However, inserting at random still usually produces a good tree.\n% Here we simply insert the data in the order that it is given.\n% TODO: put this elsewhere (in the problem statement?).\n\n\\subsection*{Constructing the Tree} % -----------------------------------------\n\n\\subsubsection*{Locating Nodes} % - - - - - - - - - - - - - - - - - - - - - - -\n\nThe \\li{find()} methods for $k$-d trees and binary search trees are very similar.\nBoth recursively compare the values of a target and nodes in the tree, but in a $k$-d tree, these values must be compared according to their \\li{pivot} attribute.\n% Solving the nearest neighbor problem does not require a \\li{find()} method, the $k$-d tree version of \\li{find()} is provided as an instructive example.\nEvery comparison in the recursive \\li{_step()} function, implemented below, compares the data of \\li{target} and \\li{current} based on the \\li{pivot} attribute of \\li{current}.\nSee Figure \\ref{fig:nearest-neighbor-kdfind}.\n\n\\begin{lstlisting}\nclass KDT:\n    \"\"\"A k-dimensional tree for solving the nearest neighbor problem.\n\n    Attributes:\n        root (KDTNode): the root node of the tree. Like all other nodes in\n            the tree, the root has a NumPy array of shape (k,) as its value.\n        k (int): the dimension of the data in the tree.\n    \"\"\"\n    def __init__(self):\n        \"\"\"Initialize the root and k attributes.\"\"\"\n        self.root = None\n        self.k = None\n\n    def find(self, data):\n        \"\"\"Return the node containing the data. If there is no such node in\n        the tree, or if the tree is empty, raise a ValueError.\n        \"\"\"\n        def _step(current):\n            \"\"\"Recursively step through the tree until finding the node\n            containing the data. If there is no such node, raise a ValueError.\n            \"\"\"\n            if current is None:                     # Base case 1: dead end.\n                raise ValueError(str(data) + \" is not in the tree\")\n            elif np.allclose(data, current.value):\n                return current                      # Base case 2: data found!\n            elif data[current.pivot] < current.value[current.pivot]:\n                return _step(current.left)          # Recursively search left.\n            else:\n                return _step(current.right)         # Recursively search right.\n\n        # Start the recursive search at the root of the tree.\n        return _step(self.root)\n\\end{lstlisting}\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[\n    level 1/.style={sibling distance=7cm},\n    level 2/.style={sibling distance=4cm},\n    level 3/.style={sibling distance=3cm},\n    level 4/.style={sibling distance=3cm},\n    edge from parent/.style={draw, ->,thick, >=stealth'}]\n\n    % Place the nodes and labels\n    \\node [draw=blue, circle,fill=blue!10!,thick] (a) {$[\\textcolor{red}{3},1,4]$}\n        child {node[draw=blue, circle, fill=blue!10!,thick] (b) {$[1,\\textcolor{red}{2},7]$}\n            child {node[thick,circle,draw] (c) {$[2,0,\\textcolor{red}{3}]$}}\n            child {node[draw=blue, circle,thick,fill=blue!10!] (d) {$[2,4,\\textcolor{red}{5}]$}\n                child {node[draw=blue, circle,thick,fill=blue!10!] (e) {$[\\textcolor{red}{1},4,3]$}}\n                child {node[thick,circle,draw] (f) {$[\\textcolor{red}{0},5,7]$}}}}\n        child {node[thick,circle,draw] (g) {$[4,\\textcolor{red}{3},5]$}\n            child {node[thick,circle,draw] (h) {$[6,1,\\textcolor{red}{4}]$}\n                child {node[draw = none] (invisble) {} edge from parent[draw=none]}\n                child {node[thick,circle,draw] (i) {$[\\textcolor{red}{5},2,5]$}}}\n            child {node[draw = none] (invisble1) {} edge from parent[draw=none]}};\n    \\draw [blue!100!,->,thick,>=stealth'] (a)--(b);\n    \\draw [blue!100!,->,thick,>=stealth'] (b)--(d);\n    \\draw [blue!100!,->,thick,>=stealth'] (d)--(e);\n\n    % pivot labels\n    \\node [draw=none,red,node distance=5.7cm]  (1) [right of=a] {\\li{pivot=0}};\n    \\node [draw=none,red,node distance=2.18cm] (2) [right of=g] {\\li{pivot=1}};\n    \\node [draw=none,red,node distance=4.19cm] (3) [right of=h] {\\li{pivot=2}};\n    \\node [draw=none,red,node distance=2.69cm] (4) [right of=i] {\\li{pivot=0}};\n\\end{tikzpicture}\n\\caption{To locate the node containing $[1,4,3]$, start by comparing $[1,4,3]$ to the root $[\\textcolor{red}{3},1,4]$.\nThe root has an \\li{pivot} of $0$, so compare the first component of the data to the first component of the root: since $1<\\textcolor{red}{3}$, step left.\nNext, $[1,4,3]$ must be to the right of $[1,\\textcolor{red}{2},7]$ because $\\textcolor{red}{2}\\le 4$.\nSimilarly, $[1,4,3]$ must be to the left of $[2,4,\\textcolor{red}{5}]$ as $3<\\textcolor{red}{5}$.} %, where the node containing $[1,4,3]$ is found.}\n\\label{fig:nearest-neighbor-kdfind}\n\\end{figure}\n\n\\begin{figure}[H] % KDT.insert()\n\\captionsetup[subfigure]{justification=justified}\n\\begin{center}\n\\begin{subfigure}{\\textwidth}\n    \\centering\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1cm},\n        edge from parent/.style={draw, ->, thick, >=stealth'}]\n        \\node [thick,circle,draw] (a) {$[\\textcolor{red}{5},5]$}\n          child {node[draw=none] (b) {\\textcolor{gray}{$A$}} edge from parent[draw=gray]\n            child {node[draw=none] (d) {} edge from parent[draw=none]}\n            child {node[draw=none] (e) {} edge from parent[draw=none]\n                child {node[draw=none] (i) {} edge from parent[draw=none]}\n                child {node[draw=none] (j) {} edge from parent[draw=none]}}}\n          child {node[draw=none] (b) {\\textcolor{gray}{$B$}} edge from parent[draw=gray]\n            child {node[draw=none] (f) {} edge from parent[draw=none]}\n            child {node[draw=none] (g) {} edge from parent[draw=none]}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\\textcolor{white}{[]}\n    \\includegraphics[width=.4\\textwidth]{figures/partition1.pdf}\n    \\end{tabular}\n    \\caption{Insert $[5,5]$ as the root.\n    The root always has an \\li{pivot} of $0$, so nodes to the left of the root contain points from $A = \\{(x,y)\\in\\mathbb{R}^2 : x < \\textcolor{red}{5}\\}$, and nodes on the right branch have points in $B = \\{(x,y)\\in\\mathbb{R}^2 : \\textcolor{red}{5}\\le x\\}$.}\n\\end{subfigure}\n\\begin{subfigure}{\\textwidth}\n    \\centering\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1cm},\n        edge from parent/.style={draw, ->, thick, >=stealth'}]\n        \\node [thick,circle,draw] (a) {$[\\textcolor{red}{5},5]$}\n          child {node[thick,circle,draw] (b) {$[3,\\textcolor{blue}{2}]$}\n            child {node[draw=none] (d) {\\textcolor{gray}{$A$}} edge from parent[draw=gray]}\n            child {node[draw=none] (e) {\\textcolor{gray}{$B$}} edge from parent[draw=gray]\n                child {node[draw=none] (i) {} edge from parent[draw=none]}\n                child {node[draw=none] (j) {} edge from parent[draw=none]}}}\n          child {node[thick,circle,draw] (b) {$[8,\\textcolor{blue}{4}]$}\n            child {node[draw=none] (f) {\\textcolor{gray}{$C$}} edge from parent[draw=gray]}\n            child {node[draw=none] (g) {\\textcolor{gray}{$D$}} edge from parent[draw=gray]}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\n    \\includegraphics[width=.4\\textwidth]{figures/partition2.pdf}\n    \\end{tabular}\n    \\caption{Insert $[3,2]$, then $[8,4]$.\n    Since $3 < \\textcolor{red}{5}$, $[3,2]$ becomes the left child of $[\\textcolor{red}{5},5]$.\n    Likewise, as $\\textcolor{red}{5}\\le 8$, $[8,4]$ becomes the right child of $[\\textcolor{red}{5},5]$.\n    These new nodes have an \\li{pivot} of $1$, so they partition the space vertically:\n    nodes to the right of $[3,\\textcolor{blue}{2}]$ contain points from $B = \\{(x,y)\\in\\mathbb{R}^2 : x < \\textcolor{red}{5},\\ \\textcolor{blue}{2} \\le y\\}$;\n    nodes to the left of $[8,\\textcolor{blue}{4}]$ hold points from $C = \\{(x,y)\\in\\mathbb{R}^2 : \\textcolor{red}{5} \\le x,\\ y < \\textcolor{blue}{8}\\}$.}\n\\end{subfigure}\n\\begin{subfigure}{\\textwidth}\n    \\centering\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1cm},\n        edge from parent/.style={draw, ->, thick, >=stealth'}]\n        \\node [thick,circle,draw] (a) {$[\\textcolor{red}{5},5]$}\n            child {node[thick,circle,draw] (b) {$[3,\\textcolor{blue}{2}]$}\n                child {node[draw=none] (d) {\\textcolor{gray}{$A$}} edge from parent[draw=gray]}\n                child {node[thick,circle,draw] (e) {$[\\textcolor{red}{2},6]$}\n                  child {node[draw=none] (i) {\\textcolor{gray}{$B$}} edge from parent[draw=gray]}\n                  child {node[draw=none] (j) {\\textcolor{gray}{$C$}} edge from parent[draw=gray]}}}\n            child {node[thick,circle,draw] (c) {$[8,\\textcolor{blue}{4}]$}\n                child {node[draw=none] (f) {\\textcolor{gray}{$D$}} edge from parent[draw=gray]}\n                child {node[draw=none] (g) {\\textcolor{gray}{$E$}} edge from parent[draw=gray]}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\n    \\includegraphics[width=.4\\textwidth]{figures/partition3.pdf}\n    \\end{tabular}\n    \\caption{Insert $[2,6]$.\n    The \\li{pivot} cycles back to $0$ since $k = 2$, so nodes to the left of $[\\textcolor{red}{2},6]$ have points that lie in $B = \\{(x,y)\\in\\mathbb{R}^2 : x < \\textcolor{red}{2},\\ \\textcolor{blue}{2} \\le y\\}$\n    and nodes to the right store points in $C = \\{(x,y)\\in\\mathbb{R}^2 : \\textcolor{red}{2} \\le x < \\textcolor{red}{5},\\ \\textcolor{blue}{2} \\le y\\}$.}\n\\end{subfigure}\n\\end{center}\n\\caption{As a $k$-d tree is constructed (left), it creates a partition of $\\mathbb{R}^k$ (right) by defining separating hyperplanes that pass through the points.\nThe more points, the finer the partition.}\n\\label{fig:nearest-neighbor-KDT_insert}\n\\end{figure}\n\n\\subsubsection*{Inserting Nodes} % - - - - - - - - - - - - - - - - - - - - - -\n\n% New nodes in a $k$-d tree are always added as leaf nodes.\nTo add a new node to a $k$-d tree, determine which existing node should be the parent of the new node by recursively stepping down the tree as in the \\li{find()} method.\nNext, assign the new node as the \\li{left} or \\li{right} child of the parent, and set its \\li{pivot} based on its parent's \\li{pivot}: if the parent's \\li{pivot} is $i$, the new node's \\li{pivot} should be $i+1$, or $0$ if $i = k-1$.\n\nConsider again the $k$-d tree in Figure \\ref{fig:nearest-neighbor-kdfind}.\nTo insert $[2,3,4]$, search the tree for $[2,3,4]$ until hitting an empty slot.\nIn this case, the search steps from the root down to $[\\textcolor{red}{1},4,3]$, which has an \\li{pivot} of $0$.\nThen since $\\textcolor{red}{1} \\le 2$, the new node should be to the right of $[1,4,3]$.\nHowever, $[\\textcolor{red}{1},4,3]$ has no right child, so it becomes the parent of $[2,3,4]$.\nThe \\li{pivot} of the new node should therefore be $1$.\nSee Figure \\ref{fig:nearest-neighbor-KDT_insert} for another example.\n% This method partitions $\\mathbb{R}^k$ into smaller subsections, allowing for efficient searching.\n\n\\begin{problem} % KDT.insert()\n\\label{prob:kdt-insert}\nWrite an \\li{insert()} method for the \\li{KDT} class that accepts a point $\\x\\in\\mathbb{R}^k$.\n\\begin{enumerate}\n\\item If the tree is empty, create a new \\li{KDTNode} containing $\\x$ and set its \\li{pivot} to $0$.\nAssign the \\li{root} attribute to the new node and set the \\li{k} attribute as the length of $\\x$.\nThereafter, raise a \\li{ValueError} if data to be inserted is not in $\\mathbb{R}^k$.\n\\item If the tree is nonempty, create a new \\li{KDTNode} containing $\\x$ and find the existing node that should become its parent.\nDetermine whether the new node will be the parent's \\li{left} or \\li{right} child, then link the parent to the new node accordingly.\nSet the \\li{pivot} of the new node based on its parent's \\li{pivot}.\n\\\\(Hint: write a recursive function like \\li{_step()} to find and link the parent.)\n\\item Do not allow duplicates in the tree: if there is already a node in the tree containing $\\x$, raise a \\li{ValueError}.\n% Be careful to check the entire array, not just the \\li{pivot} entry.\n\\end{enumerate}\nTo test your method, use the \\li{__str__()} method provided in the Additional Materials section.\nTry constructing the trees in Figures \\ref{fig:nearest-neighbor-pivot-tree} and \\ref{fig:nearest-neighbor-KDT_insert}.\nAlso check that the provided \\li{find()} method works as expected.\n\\end{problem}\n\n\\subsection*{Nearest Neighbor Search with K-D Trees} % ------------------------\n\nGiven a target $\\z\\in\\mathbb{R}^k$ and a $k$-d tree containing a set $X\\subset\\mathbb{R}^k$ of $m$ points, the nearest neighbor problem can be solved by traversing the tree in a manner that is similar to the \\li{find()} or \\li{insert()} methods from the previous section.\nThe advantage of this strategy over an exhaustive search is that not every $\\x\\in X$ has to be compared to $\\z$ via \\eqref{eq:nearest-neighbor-euclidean-metric}; the tree structure makes it possible to rule out some elements of $X$ without actually computing their distances to $\\z$.\nThe complexity is $O(k\\log(m))$, a significant improvement over the $O(km)$ complexity of an exhaustive search.\n\nTo begin, set $\\x^*$ as the value of the root and compute $d^* = d(\\x^*,\\z)$.\nStarting at the root, step down through the tree as if searching for the target $\\z$.\nAt each step, determine if the value $\\x$ of the current node is closer to $\\z$ than $\\x^*$.\nIf it is, assign $\\x^* = \\x$ and recompute $d^* = d(\\x^*, \\z)$.\nContinue this process until reaching a leaf node.\n\nNext, backtrack along the search path and determine if the non-explored branch needs to be searched.\nTo do this, check that the sphere of radius $d^*$ centered at $\\z$ does not intersect with the separating hyperplane defined by the current node.\nThat is, if the separating hyperplane is further than $d^*$ from $\\z$, then no points on the other side of the hyperplane can possibly be the nearest neighbor. %, so the branch that hasn't been searched can be safely ignored.\nSee Figure \\ref{fig:nearest-neighbor-query} for an example and Algorithm \\ref{alg:nearest-neighbor-search} for the details of the procedure.\n\n\\begin{figure}[H] % KDT.query()\n\\captionsetup[subfigure]{justification=justified}\n\\begin{center}\n\\begin{subfigure}{\\textwidth}\n    \\centering\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1.5cm},\n        edge from parent/.style={draw, ->,thick, >=stealth'}]\n        \\node [draw=purple,thick,circle,fill=green!20!] (a) {$[\\textcolor{red}{5},5]$}\n          child {node[thick,circle,draw] (b) {$[3,\\textcolor{blue}{2}]$}\n            child {node[draw = none] (invisble) {} edge from parent[draw=none]}\n            child {node[thick,circle,draw] (c) {$[\\textcolor{red}{2},6]$}\n              child {node[draw=none] (i) {} edge from parent[draw=none]}}}\n          child {node[thick,circle,draw] (g) {$[8,\\textcolor{blue}{4}]$}\n            child {node[draw = none] (invisible1) {} edge from parent[draw=none]}\n            child {node[draw,circle] (e) {$[\\textcolor{red}{7},7]$}}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\n    \\includegraphics[width=.4\\textwidth]{figures/kdtnn_search1.pdf}\n    \\end{tabular}\n    \\caption{Start at the root, setting $\\x^* = [\\textcolor{red}{5},5]$.\n    The sphere of radius $d^* = d(\\x^*,\\z)$ centered at $\\z$ intersects the hyperplane $x = 5$, so (at this point) it is possible that a nearer neighbor lies to the right of the root.}\n\\end{subfigure}\n\\begin{subfigure}{\\textwidth}\n    \\centering\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1.5cm},\n        edge from parent/.style={draw, ->,thick, >=stealth'}]\n        \\node [thick,circle,draw] (a) {$[\\textcolor{red}{5},5]$}\n          child {node[draw=purple,thick,circle,fill=green!20!] (b) {$[3,\\textcolor{blue}{2}]$} edge from parent[draw=red]\n            child {node[draw = none] (invisble) {} edge from parent[draw=none]}\n            child {node[thick,circle,draw=black] (c) {$[\\textcolor{red}{2},6]$} edge from parent[draw=black]\n              child {node[draw=none] (i) {} edge from parent[draw=none]}}}\n          child {node[thick,circle,draw] (g) {$[8,\\textcolor{blue}{4}]$}\n            child {node[draw = none] (invisible1) {} edge from parent[draw=none]}\n            child {node[draw,circle] (e) {$[\\textcolor{red}{7},7]$}}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\n    \\includegraphics[width=.4\\textwidth]{figures/kdtnn_search2.pdf}\n    \\end{tabular}\n    \\caption{If the target $\\z = [3,2.75]$ were in the tree, it would be to the left of the root, so step left and examine $\\x = [3,\\textcolor{blue}{2}]$.\n    Since $d(\\x,\\z) < d(\\x^*,\\z)$, reassign $\\x^* = \\x$ and recompute $d^*$.\n    Now the sphere of radius $d^*$ centered at $\\z$ no longer intersects the root's hyperplane, so the nearest neighbor cannot be in the root's right subtree.}\n\\end{subfigure}\n\\begin{subfigure}{\\textwidth}\n    \\begin{tabular}{lcr}\n    \\begin{tikzpicture}[\n        baseline=(current bounding box.south),\n        level 1/.style={sibling distance=4cm, level distance=1cm},\n        level 2/.style={sibling distance=2.5cm, level distance=1cm},\n        level 3/.style={sibling distance=1.5cm, level distance=1.5cm},\n        edge from parent/.style={draw, ->,thick, >=stealth'}]\n        \\node [thick,circle,draw] (a) {$[\\textcolor{red}{5},5]$}\n          child {node[thick,circle,draw=purple] (b) {$[3,\\textcolor{blue}{2}]$}\n            child {node[draw=none] (invisble) {} edge from parent[draw=none]}\n            child {node[draw,thick,circle,fill=green!20!] (c) {$[\\textcolor{red}{2},6]$} edge from parent[draw=blue]\n              child {node[draw=none] (i) {} edge from parent[draw=none]}}}\n          child {node[thick,circle,draw] (g) {$[8,\\textcolor{blue}{4}]$}\n            child {node[draw=none] (invisible1) {} edge from parent[draw=none]}\n            child {node[draw,circle] (e) {$[\\textcolor{red}{7},7]$}}};\n    \\end{tikzpicture}\n    &\\textcolor{white}{----------}&\n    \\includegraphics[width=.4\\textwidth]{figures/kdtnn_search3.pdf}\n    \\end{tabular}\n    \\caption{Continuing the search, step right to check the point $\\x = [\\textcolor{red}{2},6]$.\n    In this case $d(\\x,\\z) > d(\\x^*,\\z)$, meaning $\\x$ is \\textbf{not} nearer to $\\z$ than $\\x^*$.\n    Since $[\\textcolor{red}{2},6]$ is a leaf node, retrace the search steps up the tree to check the non-searched branches.\n    However, the sphere around $\\z$ does not intersect any splitting hyperplanes defined by the tree, so $\\x^*$ is guaranteed to be the nearest neighbor.}\n\\end{subfigure}\n\\end{center}\n\\caption{Nearest neighbor search of a $k$-d tree with $k= 2$.\nThe target is $\\z = [3,2.75]$ and the nearest neighbor is $\\x^* = [3,\\textcolor{blue}{2}]$ with minimal distance $d^* = 0.75$.\nThe tree structure allows the algorithm to eliminate $[8,\\textcolor{blue}{4}]$ and $[\\textcolor{red}{7},7]$ from consideration without computing their distance from $\\z$.}\n\\label{fig:nearest-neighbor-query}\n\\end{figure}\n\n\\begin{algorithm}[h] % K-d search algorithm.\n\\begin{algorithmic}[1]\n% \\State Let $\\z \\in \\mathbb{R}^k$ be a search target, $d(\\cdot,\\cdot)$ be a metric, and \\texttt{root} be the top of a $k$-d tree. %; \\texttt{current} and \\texttt{nearest} are \\li{KDTNode}s.\n\\Procedure{Nearest Neighbor Search}{$\\z$, \\texttt{root}}\n\\Procedure{KDSearch}{\\texttt{current}, \\texttt{nearest}, $d^*$}\n\\If {\\texttt{current} \\textcolor{blue}{\\texttt{is None}}}\n    \\Comment{Base case: dead end.}\n    \\State \\pseudoli{return} \\texttt{nearest}, $d^*$\n\\EndIf\n\\State $\\x \\gets$ \\texttt{current.value}\n\\State $i \\gets$ \\texttt{current.pivot}\n\\If {$d(\\x,\\z) < d^*$}\n    \\Comment{Check if \\texttt{current} is closer to $\\z$ than \\li{nearest}.}\n    \\State \\texttt{nearest} $\\gets$ \\texttt{current}\n    \\State $d^* \\gets d(\\x,\\z)$\n\\EndIf\n\\If {$z_i < x_i$}\n    \\Comment{Search to the left.}\n    \\State \\texttt{nearest}, $d^* \\gets$ \\texttt{KDSearch}(\\texttt{current.left}, \\texttt{nearest}, $d^*$)\n    \\If {$z_i + d^* \\ge x_i$}\n    \\Comment{Search to the right if needed.}\n        \\State \\texttt{nearest}, $d^* \\gets$ \\texttt{KDSearch}(\\texttt{current.right}, \\texttt{nearest}, $d^*$)\n    \\EndIf\n\\Else\n    \\Comment{Search to the right.}\n    \\State \\texttt{nearest}, $d^* \\gets$ \\texttt{KDSearch}(\\texttt{current.right}, \\texttt{nearest}, $d^*$)\n\n    \\If {$z_i - d^* \\le x_i$}\n    \\Comment{Search to the left if needed.}\n        \\State \\texttt{nearest}, $d^* \\gets$ \\texttt{KDSearch}(\\texttt{current.left}, \\texttt{nearest}, $d^*$)\n    \\EndIf\n\\EndIf\n\\State \\pseudoli{return} \\texttt{nearest}, $d^*$\n\\EndProcedure\n\\State \\texttt{node}, $d^* \\gets \\texttt{KDSearch}(\\texttt{root}, \\texttt{root}, d(\\texttt{root.value},\\z))$\n\\State \\pseudoli{return} \\texttt{node.value}, $d^*$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{$k$-d tree nearest neighbor search}\n\\label{alg:nearest-neighbor-search}\n\\end{algorithm}\n\n\\begin{problem} % K-d nearest neighbor search algorithm.\n\\label{prob:kdtree-nearest-neighbor-search}\nWrite a method for the \\li{KDT} class that accepts a target point $\\z\\in\\mathbb{R}^k$.\nUse Algorithm \\ref{alg:nearest-neighbor-search} to solve \\eqref{eq:nearest-neighbor-def}.\nReturn the nearest neighbor $\\x^*$ (the actual NumPy array, not the \\li{KDTNode}) and its distance $d^*$ from $\\z$.\n\nCompare your method to the exhaustive search in Problem \\ref{prob:nearest-neighbor-exhaustive-search} and to SciPy's built-in \\li{KDTree} class.\nThis structure is essentially a heavily optimized version of the \\li{KDT} class.\nTo solve the nearest neighbor problem, initialize the tree with data, then ``query'' the tree with the target point.\nThe \\li{query()} method returns a tuple of the minimum distance and the index of the nearest neighbor in the data.\n\n\\begin{lstlisting}\n>>> from scipy.spatial import KDTree\n\n# Initialize the tree with data (in this example, use random data).\n>>> data = np.random.random((100,5))    # 100 5-dimensional points.\n>>> target = np.random.random(5)\n>>> tree = KDTree(data)\n\n# Query the tree for the nearest neighbor and its distance from 'target'.\n>>> min_distance, index = tree.query(target)\n>>> print(min_distance)\n0.24929868807\n>>> tree.data[index]                    # Get the actual nearest neighbor.\narray([ 0.26927057,  0.03160271,  0.46830759,  0.26766863,  0.63073275])\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{warn}\nThere are a few caveats to using a $k$-d tree for the nearest neighbor search problem.\n\\begin{itemize}\n\\item Constructing the tree takes time.\nFor small enough data sets, an exhaustive search may be faster than the combined time of constructing and searching a tree.\nOn the other hand, once the tree is constructed, it can be used for multiple nearest-neighbor queries.\n\\item In the worst case---when the tree is completely unbalanced---the search complexity is $O(km)$ instead of $O(k\\log(m))$.\nFortunately, there are algorithms for constructing the tree intelligently so that it is mostly balanced, and a random insertion order usually results in a somewhat balanced tree.\n\\end{itemize}\n% In general, $k$-d trees may be unnecessary or even a hinderance if $X$ is small, but it certainly pays to have a well-constructed $k$-d tree if $X$ is large.\n\\end{warn}\n\n\\section*{K-Nearest Neighbors} % ==============================================\n\nThe nearest neighbor algorithm provides one way to solve a common machine learning problem.\nIn \\emph{supervised learning},\n% \\footnote{In \\emph{unsupervised learning} there are no labels provided in the first place.}\na \\emph{training set} $X\\subset D$ has a corresponding set of \\emph{labels} $Y$ that specifies a category for each element of $X$.\nFor instance, $X$ could contain financial data on $m$ individuals, and $Y$ could be a set of $m$ booleans indicating which individuals have filed for bankruptcy.\nSupervised learning algorithms use the training data to construct a function $f:D\\rightarrow Y$ that maps points to their corresponding label.\nIn other words, the algorithm ``learns'' enough about the relationship between $X$ and $Y$ to intelligently label arbitrary elements of $D$.\nIn the bankruptcy example, a person could then use their own financial data to learn whether or not they look more like someone who files for bankruptcy or someone who does not.\n\nA \\emph{$k$-nearest neighbors} classifier uses a simple strategy to label an arbitrary $\\z\\in D$: find the $k$ elements of $X$ that are nearest to $\\z$ (usually in terms of the Euclidean metric) and choose the most common label from those $k$ elements as the label of $\\z$.\nThat is, the points in the $k$ labeled points that are most like $\\z$ are allowed to ``vote'' on how $\\z$ should be labeled.\nSee Figure \\ref{fig:k-nearest-neighbors}.\n\n\\begin{figure}[H]\n\\begin{tabular}{ccccc}\n\\begin{tikzpicture}[circ/.style={circle,align=center,minimum size=.5cm}]\n    \\node[circ,draw=black,thick] (R) {};\n    \\node[cyan!70,fill=cyan!70,circ,above left=.3cm and .3cm of R] (B1) {};\n    \\node[cyan!70,fill=cyan!70,circ,below left=-.3cm and .6cm of R] (B3) {};\n    \\node[yellow!70,fill=yellow!70,circ,below left=.5cm and .6cm of R] (Y1){};\n    \\node[yellow!60,fill=yellow!60,circ,above right=.3cm and .3cm of R](Y2){};\n    \\node[yellow!60,fill=yellow!60,circ,below right=0cm and 1cm of R] (Y3) {};\n\\end{tikzpicture}\n%\n\\quad\\qquad\\qquad&\\qquad\\qquad&\n%\n\\begin{tikzpicture}[circ/.style={circle,align=center,minimum size=.5cm}]\n    \\node[circ,cyan!70,fill=cyan!70,draw=black,thick] (R) {};\n    \\node[cyan!70,fill=cyan!70,circ,above left=.3cm and .3cm of R] (B1) {};\n    \\node[cyan!70,fill=cyan!70,circ,below left=-.3cm and .6cm of R] (B3) {};\n    \\node[yellow!70,fill=yellow!70,circ,below left=.5cm and .6cm of R] (Y1) {};\n    \\node[yellow!60,fill=yellow!60,circ,above right=.3cm and .3cm of R] (Y2){};\n    \\node[yellow!60,fill=yellow!60,circ,below right=0cm and 1cm of R] (Y3) {};\n    \\foreach \\a/\\b in {R/B1,R/B3,R/Y2} \\draw[line width=.05cm] (\\a) -- (\\b);\n\\end{tikzpicture}\n%\n&\\qquad\\qquad&\\qquad\\qquad\\quad\n%\n\\begin{tikzpicture}[circ/.style={circle,align=center,minimum size=.5cm}]\n    \\node[circ,yellow!60,fill=yellow!60,draw=black,thick] (R) {};\n    \\node[cyan!70,fill=cyan!70,circ,above left=.3cm and .3cm of R] (B1) {};\n    \\node[cyan!70,fill=cyan!70,circ,below left=-.3cm and .6cm of R] (B3) {};\n    \\node[yellow!70,fill=yellow!70,circ,below left=.5cm and .6cm of R] (Y1) {};\n    \\node[yellow!60,fill=yellow!60,circ,above right=.3cm and .3cm of R] (Y2){};\n    \\node[yellow!60,fill=yellow!60,circ,below right=0cm and 1cm of R] (Y3) {};\n    \\foreach \\a/\\b in {R/B1,R/B3,R/Y2,R/Y3,R/Y1} \\draw[line width=.05cm] (\\a) -- (\\b);\n\\end{tikzpicture}\n\\end{tabular}\n\\caption{To classify the center node, determine its $k$-nearest neighbors and pick the most common label of the neighbors.\nIf $k=3$, the $k$ nearest points are two blues and a yellow, so the center node is labeled blue.\nFor $k=5$, the $k$ nearest points consists of two blues and three yellows, so the center node is labeled yellow.}\n\\label{fig:k-nearest-neighbors}\n\\end{figure}\n\n\\begin{warn}\nThe $k$ in $k$-d tree refers to the \\textbf{dimension} of the data housed in the tree, but the $k$ in $k$-nearest neighbors refers to the \\textbf{number of neighbors} to use in the voting scheme.\nUnfortunately, both names are standard.\n% The $k$ in the \\emph{$k$-means algorithm} refers to the number of clusters to separate the data into.\n\\end{warn}\n\n\\begin{problem} % Write a KNeighborsClassifier class.\n\\label{prob:kneighbors-classifier}\nWrite a \\li{KNeighborsClassifier} class with the following methods.\n\\begin{enumerate}\n\\item The constructor should accept an integer \\li{n_neighbors}, the number of neighbors to include in the vote (the $k$ in $k$-nearest neighbors).\nSave this value as an attribute.\n\n\\item \\li{fit()}: accept an $m\\times k$ NumPy array $X$ (the training set) and a 1-dimensional NumPy array $\\y$ with $m$ entries (the training labels).\nAs in Problems \\ref{prob:nearest-neighbor-exhaustive-search} and \\ref{prob:kdtree-nearest-neighbor-search}, each of the $m$ rows of $X$ represents a point in $\\mathbb{R}^k$.\nHere $y_i$ is the label corresponding to row $i$ of $X$.\n\nLoad a SciPy \\li{KDTree} with the data in $X$.\nSave the tree and the labels as attributes.\n\n\\item \\li{predict()}: accept a 1-dimensional NumPy array $\\z$ with $k$ entries.\nQuery the \\li{KDTree} for the \\li{n_neighbors} elements of $X$ that are nearest to $\\z$ and return the most common label of those neighbors.\nIf there is a tie for the most common label (such as if $k=2$ in Figure \\ref{fig:k-nearest-neighbors}), choose the alphanumerically smallest label.\n\\\\(Hint: use \\li{scipy.stats.mode()}. The default behavior splits ties correctly.)\n\nTo get several nearest neighbors from the tree, specify \\li{k} in \\li{KDTree.query()}.\n\\begin{lstlisting}\n>>> data = np.random.random((100,5))    # 100 5-dimensional points.\n>>> target = np.random.random(5)\n>>> tree = KDTree(data)\n\n# Query the tree for the 3 nearest neighbors.\n>>> distances, indices = tree.query(target, k=3)\n>>> print(indices)\n[26 30 32]\n\\end{lstlisting}\n\\end{enumerate}\n\\end{problem}\n\n\\begin{info}\nThe format of the \\li{KNeighborsClassifier} in Problem \\ref{prob:kneighbors-classifier} conforms to the style of \\emph{scikit-learn} (\\li{sklearn}), a large machine learning library in Python.\nIn fact, scikit-learn has a class called \\li{sklearn.neighbors.KNeighborsClassifier} that is a more robust version of the class from Problem \\ref{prob:kneighbors-classifier}.\nSee \\url{http://scikit-learn.org/stable/modules/neighbors.html} for more tools from scikit-learn for solving the nearest neighbor problem in the context of machine learning.\n\\end{info}\n\n\\begin{comment}\nTo determine the accuracy of a machine learning model, first divide the set of labeled data into a \\emph{training set} and a \\emph{test set}.\nThe training set is used to find potentially predictive relationships between the \\emph{features}, or individual properties, of a data point.\nIn the bankruptcy example above, the incomes and debt levels were features of the data.\nRelationships between features are discovered in the \\emph{training phase} of machine learning.\nIn the nearest neighbor algorithm, the training phase consists of simply storing the training set.\nThe test set is a small subset (usually around 20\\%) of the original data set.\nDuring the \\emph{test phase}, the accuracy of the model is calculated using the test set.\nThe test set is treated as a set of novel data, and is run through the model.\nThe model's classifications of the test data are compared to the actual labels of the test data.\nThe ratio of correct classifications to total number of instances in the test set is the accuracy of the model.\n\n\\subsection*{Breaking Ties}\nConsider the illustration in Figure \\ref{fig:k-nearest-neighbors}.\nSuppose that the three neighbors of a new data point were found, but all of these neighbors had different classifications: one neighbor was of class A, one was B, and one was C.\nHow would the new instance be classified?\nA common approach to dealing with ties is to remove the farthest neighbor's vote until a majority vote is found.\nIn some cases, this results in only the closest neighbor determining the output of a new instance.\n\\end{comment}\n\n\\subsection*{Handwriting Recognition} % ---------------------------------------\n\n\\emph{Computer vision} is a challenging area of artificial intelligence that focuses on autonomously interpreting images.\nPerhaps the simplest computer vision problem is that of translating images into text.\nRoughly speaking, computers store grayscale images as $M \\times N$ arrays of pixel brightness values: 0 corresponds to black, and 255 to white.\nFlattening out such an array yields a vector in $\\mathbb{R}^{MN}$.\nGiven some images of characters with labels (assigned by humans), a $k$-nearest neighbor classifier can intelligently decide what character the image represents.\n\n\\begin{problem}\nThe file \\texttt{mnist\\_subset.npz} contains part of the MNIST dataset,\\footnote{See \\url{http://yann.lecun.com/exdb/mnist/}.} a collection of $28\\times 28$ images of handwritten digits and their labels.\nThe data is split into four parts.\n\\begin{itemize}\n\\item \\li{X_train}: A $3000\\times 728$ matrix, the training set.\nEach of the $3000$ rows is a flattened $28\\times 28$ image to be used in training the classifier.\n\n\\item \\li{y_train}: A 1-dimensional NumPy array with $3000$ entries.\nThe entries are integers from 0 to 9, the labels corresponding to the images in \\li{X_train}.\n\n\\item \\li{X_test}: A $500\\times 728$ matrix of $500$ images to classify.\n\n\\item \\li{y_test}: A 1-dimensional NumPy array with $500$ entries.\nThese are the labels corresponding to \\li{X_test}, the ``right answers'' that the classifier will try to guess.\n\\end{itemize}\nThe following code uses \\li{np.load()} to extract the data.\n% Use \\li{np.load()} to extract the data.\n% An \\texttt{npz} file holds several arrays, which can be accessed like the values of a dictionary.\n\\begin{lstlisting}\n>>> data = np.load(\"mnist_subset.npz\")\n>>> X_train = data[\"X_train\"].astype(np.<<float>>)          # Training data\n>>> y_train = data[\"y_train\"]                           # Training labels\n>>> X_test = data[\"X_test\"].astype(np.<<float>>)            # Test data\n>>> y_test = data[\"y_test\"]                             # Test labels\n\\end{lstlisting}\nTo visualize one of the images, reshape it as a $28\\times 28$ array and use \\li{plt.imshow()}.\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> plt.imshow(X_test[0].reshape((28,28)), cmap=\"gray\")\n>>> plt.show()\n\\end{lstlisting}\n\\begin{center}\n\\includegraphics[width=.15\\textwidth]{figures/digit.pdf}\n\\end{center}\n\n% \\begin{figure}[H]\n% \\centering\n% \\includegraphics[width=.4\\textwidth]{figures/digit.pdf}\n% \\caption{The number 6 taken from the data set.}\n% \\label{fig:digit}\n% \\end{figure}\n\nWrite a function than accepts an integer \\li{n_neighbors}.\nLoad a classifier from Problem \\ref{prob:kneighbors-classifier} %or a \\li{sklearn.neighbors.KNeighborsClassifier}\nwith the data \\li{X_train} and the corresponding labels \\li{y_train}.\nUse the classifier to predict the labels of each image in \\li{X_test}.\nReturn the classification accuracy, the percentage of predictions that match \\li{y_test}.\nThe accuracy should be at least $90\\%$ using $4$ nearest neighbors.\n\\end{problem}\n\n\\begin{info}\nThe $k$-nearest neighbors algorithm is \\textbf{not} the best machine learning algorithm for this problem, but it is a good starting point because of its simplicity.\nIn fact, $k$-nearest neighbors is often used as a baseline to compare against more complicated machine learning techniques.\n\\end{info}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Ball Trees} % ----------------------------------------------------\n\nThe nearest neighbor problem can also be solved efficiently with a \\emph{ball tree}, another space-partitioning data structure.\nInstead of separating $\\mathbb{R}^k$ by hyperplanes, a ball tree uses nested hyperspheres to split up the space.\nSince the partitioning scheme is different, a nearest neighbor search through a ball tree is more efficient than the $k$-d tree search for some data sets.\nSee \\url{https://en.wikipedia.org/wiki/Ball_tree} for more details.\n\n\\subsection*{The Curse of Dimensionality} % -----------------------------------\n\nThe \\emph{curse of dimensionality} refers to a phenomena that occurs when dealing with high-dimensional data: the computational cost of an algorithm increases much more rapidly as the dimension increases than it does when the number of points increases.\nThis problem occurs in many other areas involving multi-dimensional data, but it is quite apparent in a nearest neighbor search.\n\n\\begin{figure}[H] % Curse of Dimensionality\n\\captionsetup[subfigure]{justification=centering}\n\\centering\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/curse_m.pdf}\n    \\caption{Fixing $k$ and increasing $m$ leads to consistent growth in execution time.}\n\\end{subfigure}\n%\n\\begin{subfigure}{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/curse_k.pdf}\n    \\caption{For fixed $m$, the times takes a sharp upturn around $k = 2^9$ relative to previous growth rates.}\n\\end{subfigure}\n\\caption{Construction and nearest neighbor search times for a $k$-d tree with a $m\\times k$ training set.}\n\\end{figure}\n\nSee \\url{https://en.wikipedia.org/wiki/Curse_of_dimensionality} for more examples.\nOne way to avoid the curse of dimensionality is via \\emph{dimension reduction}, a process usually based on the singular value decomposition (SVD) that projects data into a lower-dimensional space.\n\n\\subsection*{Tiebreaker Strategies} % -----------------------------------------\n\nAs mentioned in Problem \\ref{prob:kneighbors-classifier}, the majority voting scheme in the $k$-nearest neighbor algorithm can often result in a tie.\nBreaking the tie intelligently is a science unto itself, but here are a few common strategies.\n\\begin{enumerate}\n\\item For binary classification (meaning there are only two labels), choose an odd $k$ to avoid a tie in the first place.\n\\item Redo the search with $k-1$ neighbors, repeating as needed until $k=1$.\n\\item Choose the label that appears more frequently in the test set.\n\\item Choose randomly among the labels that are tied for most common.\n\\end{enumerate}\n\n\\subsection*{Additional Code} % -----------------------------------------------\n\nThe following code creates a string representation for the \\li{KDT} class.\nUse this to test Problem \\ref{prob:kdt-insert}.\n\n\\begin{lstlisting}\nclass KDT:\n    # ...\n    def __str__(self):\n        \"\"\"String representation: a hierarchical list of nodes and their axes.\n\n        Example:                           'KDT(k=2)\n                    [5,5]                   [5 5]   pivot = 0\n                    /   \\                   [3 2]   pivot = 1\n                [3,2]   [8,4]               [8 4]   pivot = 1\n                    \\       \\               [2 6]   pivot = 0\n                    [2,6]   [7,5]           [7 5]   pivot = 0'\n        \"\"\"\n        if self.root is None:\n            return \"Empty KDT\"\n        nodes, strs = [self.root], []\n        while nodes:\n            current = nodes.pop(0)\n            strs.append(\"{}\\tpivot = {}\".<<format>>(current.value, current.pivot))\n            for child in [current.left, current.right]:\n                if child:\n                    nodes.append(child)\n        return \"KDT(k={})\\n\".<<format>>(self.k) + \"\\n\".join(strs)\n\\end{lstlisting}\n", "meta": {"hexsha": "eb0a258e06e9ea5065f001821f96c0a78d934f06", "size": 48414, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume2/NearestNeighbor/NearestNeighbor.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/NearestNeighbor/NearestNeighbor.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/NearestNeighbor/NearestNeighbor.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": 60.6691729323, "max_line_length": 283, "alphanum_fraction": 0.6705291858, "num_tokens": 14366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8418256631249077, "lm_q2_score": 0.9219218428996602, "lm_q1q2_score": 0.7760974667483433}}
{"text": "\\subsection{Convolution with stride by introducing stride operator}\nAs discussed above, the restriction mapping is consistent with the \nco-called convolution with stride $s=2$, which is defined as:\n\\begin{equation}\\label{stride_2}\n[K \\ast_2 f]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} f_{2i + p, 2j + q},  \n\\quad i = 1: \\frac{m+1}{2} , j = 1: \\frac{n+1}{2}.\n\\end{equation}\n\n\n\\begin{remark}\nMore generally in CNN, given an integer $s\\ge1$, a convolution with stride $s$ for $f \\in \\mathbb{R}^{(m)\\times\n\t\t(2^n+1)}$ can also be defined as:\n\t\\begin{equation}\\label{stride}\n\t[K \\ast_s f]_{i,j} = \\sum_{p,q=-k}^k K_{p,q} f_{si + p, sj + q},  \n\t\\quad i = 1: \\lceil  \\frac{m}{s}\\rceil , j = 1: \\lceil  \\frac{n}{s}\\rceil.\n\t\\end{equation}\n\t\n\tHere $ \\lceil  \\frac{m}{s}\\rceil$ denotes the smallest integer that greater than $\\frac{m}{s}$.\n\\end{remark}\n\nAs general in CNN and multigrid method, convolution with stride $s=2$ is the most important case.\nTo make this operator more clear, now we are going to introduce the stride operator $\\mathcal S$ as:\n\\begin{equation}\\label{eq:strideopdim}\n\\mathcal S: \\mathbb{R}^{m \\times n} \\mapsto \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{n+1}{2}},\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:strideop}\n[\\mathcal S(f)]_{i,j} = f_{2i, 2j}, \\quad i  = 1:\\frac{m+1}{2}, j = 1:\\frac{n+1}{2}.\n\\end{equation}\n\nThen we have the rewrite form of convolution with stride $2$ as:\n\\begin{equation}\\label{eq:convstride_2_1}\nK \\ast_2 f = \\mathcal S( K\\ast f).\n\\end{equation}\n\n\nThen the deconvolution in defined by the transposed of convolution \nwith stride with respect to the F-inner product defined as:\n$$\n(u, v)_F := \\sum_{i,j} u_{i,j}v_{i,j}.\n$$\nThen we have the definition of deconvolution as\n\\begin{equation}\\label{eq:def_deconv}\n(K \\ast_2 u, v)_F = (u, K \\ast_2^\\top v),\n\\end{equation}\nwith\n\\begin{equation}\nu \\in \\mathbb{R}^{m \\times n} \\quad \\text{and} \\quad v \\in \\mathbb{R}^{\\frac{m+1}{2} \\times \\frac{m+1}{2}}.\n\\end{equation}\n\nFor a more comprehensive notation, let us also define \n$K\\ast$ as an operator from $\\mathbb{R}^{m\\times n} \\quad \\text{and}$\nto $\\mathbb{R}^{m\\times n}$ as $\\mathcal C_K$.\nThen we have the ``transpose'' of convolution without stride as:\n\\begin{equation}\\label{eq:def_tran_conv}\n(K \\ast u, v)_F = (\\mathcal C_K (u), v) =  (u,  \\mathcal C_K^\\top v).\n\\end{equation}\n\n\\begin{lemma}\\label{lemm:tilde-K}\nFor the transposed convolution without stride, we have the next result\n\\begin{equation}\\label{eq:}\n\\mathcal C_K^\\top = \\mathcal C_{\\tilde K},\n\\end{equation}\nwhere $\\tilde K$ is defined as\n\\begin{equation}\\label{eq:def_tildeK}\n\\tilde K_{p,q} = K_{-p, -q}, \\quad p,q = -k:k.\n\\end{equation}\nIntuitively, if we take $K_{0,0}$ as the center for the convolutional kernel $K$, \nthen $\\tilde K$ is the central symmetry of $K$. \nIn 2D case, it can also be understood as the rotation of $\\pi$ with respect to\nthe center $K_{0,0}$.\n\\end{lemma}\n\nThen recall the definition of deconvolution in \\eqref{eq:def_deconv} we have\n\\begin{equation}\\label{eq:op_deconv}\n\\begin{aligned}\n(u,  K \\ast_2^\\top v) &= (K \\ast_2 u, v)_F = (\\mathcal S \\mathcal C_K u, v) \\\\\n&= (u,  \\mathcal C^\\top_K \\mathcal S^\\top v),\n\\end{aligned}\n\\end{equation}\nwith definition\n\\begin{equation}\\label{eq:de_stride_dim}\n\\mathcal S^\\top:   \\mathbb{R}^{\\frac{m+1}{2} \\times\\frac{n+1}{2}} \\mapsto \\mathbb{R}^{m\\times n},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:de_stride}\n[\\mathcal S^\\top (f)]_{i,j} = \n\\begin{cases}\n0 \\quad &\\text{if i or j is even}, \\\\\nf_{i/2, j/2}, \\quad &\\text{else}.\n\\end{cases}\n\\end{equation}\n\nThus to say, we have the simple version of the deconvolution for $K \\ast $ as\n\\begin{equation}\\label{eq:simple_deconv}\nK \\ast_2^\\top v = \\mathcal C_K\\top \\circ \\mathcal S^\\top (v) = \\mathcal C_{\\tilde K} \\circ \\mathcal S^\\top (v) = \\tilde K \\ast \\mathcal S^\\top (v),\n\\end{equation}\nthus to say\n\\begin{equation}\\label{eq:final}\nK \\ast_2^\\top  = \\tilde K \\ast \\mathcal S^\\top.\n\\end{equation}\n\nIn short, we have the next decomposition\n\\begin{itemize}\n\t\\item convolution with stride = stride $ \\circ$ convolution,\n\t\\item deconvolution with stride  = transposed convolution $\\circ$ transposed stride = convolution with the central symmetry of original kernel $\\circ$ transposed stride.\n\\end{itemize}\n\n\\begin{theorem}\\label{thm:deconv_op}\nHere let us show a simple example about some details for computing deconvolution. \nLet us consider \n\\begin{equation}\nK_{p,q} \\quad p,q = -1, 0, 1.\n\\end{equation}\nThen we have \n$$\nK \\ast_2^\\top v = \\tilde K \\ast \\mathcal S^\\top (v).\n$$\nAs in \\eqref{eq:de_stride} and the Lemma \\ref{lemm:tilde-K}, we have the \nfinal version is \n\\begin{equation}\n\\label{eq:7}\n[K \\ast_2^\\top v ]_{2i,2j}=  K_{0,0}v_{i,j},\n\\end{equation}\nwith \n\\begin{equation}\n\\label{eq:9}\n[K \\ast_2^\\top v ]_{2i-1, 2j} = K_{0,1}v_{i-1,j} + K_{0,-1}v_{i,j}, \\quad \n[K \\ast_2^\\top v ]_{2i, 2j-1} = K_{1,0}v_{i,j} + K_{-1,0}v_{i,j-1},\n\\end{equation}\nand\n\\begin{equation}\n%\\begin{tiny}\n%{\\scriptsize \n[K \\ast_2^\\top v ]_{2i-1, 2j-1}  =  \nK_{1,1}v_{i,j} + K_{-1,1}v_{i-1,j} + K_{1,-1}v_{i,j-1} + K_{-1,-1}v_{i-1,j-1}.\n%\\end{tiny}\n%}\n\\end{equation}\n\n\n\\end{theorem}", "meta": {"hexsha": "0ec21e81dafb68d4989cf084324309af4611bda3", "size": 5071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_ConvStride.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_ConvStride.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_ConvStride.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.7112676056, "max_line_length": 170, "alphanum_fraction": 0.6720567935, "num_tokens": 1947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921841290738, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7760974507599331}}
{"text": "\\section{Hypothesis testing}\nIs the effect you see in a sample likely to appear in a larger population? \nThere are several ways we could formulate this question, including Fisher null hypothesis testing, Neyman-Pearson decision theory, and Bayesian inference.\nThe logic of this process is similar to a proof by contradiction.\n\nSteps:\n\\begin{enumerate}\n\t\\item choose a test statistic, e.g. the difference between means of two groups. \n\t\\item define a null hypothesis\n\t\\item compute a p-value, which is the probability of seeing the apparent effect if the null hypothesis is true. \n\t\\item interpret the result. If the p-value is low, the effect is said to be statistically significant, \n\t\twhich means that it is unlikely to have occurred by chance. \n\t\tIn that case we infer that the effect is more likely to appear in the larger population.\n\\end{enumerate}\n\nInterpret p-values according to their order of magnitude.  If the p-value is\n\\begin{itemize}\n\t\\item  $<$ 1\\%, the effect is unlikely to be due to chance; \n\t\\item $>$ 10\\%, the effect can plausibly be explained by chance. \n\t\\item P-values between 1\\% and 10\\% should be considered borderline.\n\\end{itemize}\n\nIn general the p-value for a one-sided test is about half the p-value for a two-sided test, depending on the shape of the distribution.\n\n\\subsubsection{testing a correlation}\nIf x and y appear correlated, mix up the x, y pairs and look at the correlation of this permuted data. \nRepeat 100x, and look at the distribution of correlations seen; \n\tthis gives perspective on whether the correlation is real. \n\t\n\\subsubsection{testing proportions}\nE.g. testing whether a die is fair. \nDefine a test statistic to be the $\\sum$ abs((actual counts) - (expected counts)).\nSimulate what this test statistic ends up being for a fair die.\nThe p-value is the fraction of the time this statistic is at your threshold or higher. \n\nIf instead you use the square, $\\sum$ ((actual counts) - (expected counts))$^2$, large outliers are weighted more strongly, and the probability appears more extreme. \nYou are now in the realm of Chi-squared tests.\n\n\\subsubsection{Chi-squared tests}\n$\\displaystyle \\chi^2 = \\sum_i \\frac{(O_i - E_i)^2}{E_i}$\n$O_i$ are observed frequencies, $E_i$ are expected frequencies. \n", "meta": {"hexsha": "746cf61cb76eba1b95ad7f0dd7145051b53378cd", "size": 2251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/hypothesis_testing.tex", "max_stars_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_stars_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/hypothesis_testing.tex", "max_issues_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_issues_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/hypothesis_testing.tex", "max_forks_repo_name": "JanetMatsen/Statistics_for_Data_Science", "max_forks_repo_head_hexsha": "b1f626226dfdd444b508203d21c0f66a343c7097", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.5952380952, "max_line_length": 166, "alphanum_fraction": 0.7645490893, "num_tokens": 544, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.776081840958689}}
{"text": "\\chapter{{\\tt SemiImplMtx}: Semi-Implicit Factorization}\n\\label{chapter:SemiImplMtx}\n\\par\nThe {\\tt SemiImplMtx} object contains a semi-implicit\nrepresentation of a sparse matrix factorization.\nAssume that the matrix $A$ has been factored as\n$PAQ = LDU$, where $L$ is unit lower triangular\nand $U$ is unit upper triangular.\nNow consider $PAQ$ (and so $L$, $D$ and $U$) partitioned as\nfollows.\n$$\n{\\widehat A} = PAQ =\n\\begin{bmatrix}\n{\\widehat A}_{1,1} & {\\widehat A}_{1,2} \\\\\n{\\widehat A}_{2,1} & {\\widehat A}_{2,2}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\nL_{1,1} &   0     \\\\\nL_{2,1} & L_{2,2}\n\\end{bmatrix}\n\\begin{bmatrix}\nD_{1,1} &    0    \\\\\n   0    & D_{2,2}\n\\end{bmatrix}\n\\begin{bmatrix}\nU_{1,1} & U_{1,2} \\\\\n   0    & U_{2,2}\n\\end{bmatrix}\n$$\nAfter some algebra we can arrive at the following identities.\n$$\nL_{2,1} = {\\widehat A}_{2,1} D_{1,1}^{-1}\n\\text{\\qquad and \\qquad}\nU_{1,2} = D_{1,1}^{-1} {\\widehat A}_{1,2} \n$$\nThe straightforward solution of $AX = B$ can be done as follows,\nas we solve the permuted linear system\n${\\widehat A} {\\widehat X} = {\\widehat B}$,\nwhere ${\\widehat X} = Q^T X$ and ${\\widehat B} = P B$.\n\\begin{itemize}\n\\item solve $L_{1,1} Y_1 = {\\widehat B}_1$.\n\\item solve $L_{2,2} Y_2 = {\\widehat B}_2 - L_{2,1} Y_1$.\n\\item solve $D_{1,1} Z_1 = Y_1$.\n\\item solve $D_{2,2} Z_2 = Y_2$.\n\\item solve $U_{2,2} {\\widehat X}_2 = Z_2$.\n\\item solve $U_{1,1} {\\widehat X}_1 = Z_1 - U_{1,2} Z_2$.\n\\end{itemize}\nAn equivalent process does not requires $L_{2,1}$ and $U_{1,2}$,\nbut instead uses the ${\\widehat A}_{1,2}$ and ${\\widehat A}_{2,1}$\nmatrices.\n\\begin{itemize}\n\\item \nsolve $L_{1,1} D_{1,1} U_{1,1} T_1 = {\\widehat B}_1$.\n\\item \nsolve $L_{2,2} D_{2,2} U_{2,2} {\\widehat X}_2 = {\\widehat B}_2 - A_{2,1} T_1$.\n\\item \nsolve $L_{1,1} D_{1,1} U_{1,1} {\\widehat X}_1 \n       = {\\widehat B}_1 - A_{1,2} {\\widehat X}_2$.\n\\end{itemize}\nIn effect, we have traded multiplies with $L_{2,1}$ and $U_{1,2}$\nfor multiplies with $A_{1,2}$ and $A_{2,1}$ and\ntwo extra solves with $D_{1,1}$.\nIn some cases this {\\it semi-implicit} procedure\n(so named because $L_{2,1}$ and $U_{1,2}$ are stored in a\nsemi-implicit form) can pay off ---\nstorage can be saved when the number of entries in\n$L_{2,1}$ and $U_{1,2}$ are larger than the number of entries in\n$A_{2,1}$ and $A_{1,2}$.\nThe number of solve operations is reduced by \n$|L_{2,1}| + |U_{1,2}| - 2|D_{1,1}| -|A_{2,1}| - |A_{1,2}|$,\nwhere $|\\cdot|$ denotes the number of nonzeroes in a matrix.\n", "meta": {"hexsha": "591c8d78d1500e4a17b296c2db56b2f330afdf68", "size": 2445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ccx_prool/SPOOLES.2.2/SemiImplMtx/doc/intro.tex", "max_stars_repo_name": "alleindrach/calculix-desktop", "max_stars_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ccx_prool/SPOOLES.2.2/SemiImplMtx/doc/intro.tex", "max_issues_repo_name": "alleindrach/calculix-desktop", "max_issues_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2017-09-21T17:03:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-25T16:08:31.000Z", "max_forks_repo_path": "ccx_prool/SPOOLES.2.2/SemiImplMtx/doc/intro.tex", "max_forks_repo_name": "alleindrach/calculix-desktop", "max_forks_repo_head_hexsha": "2cb2c434b536eb668ff88bdf82538d22f4f0f711", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-08-29T18:41:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-29T18:41:28.000Z", "avg_line_length": 33.4931506849, "max_line_length": 78, "alphanum_fraction": 0.6323108384, "num_tokens": 1013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425223682085, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7760818189221593}}
{"text": "\n\\subsection{Absolute risk aversion}\n\nGiven a utility function we can calculate the risk aversion.\n\n\\(A(x)=-\\dfrac{u''(x)}{u'(x)}\\)\n\nConstant Absolute Risk Aversion (CARA) is:\n\n\\(A(x)=c\\)\n\n\\(u(x)=1-e^{\\alpha x}\\)\n\nHyperbolic Absolute Risk Aversion (HARA) is:\n\n\\(A(x)=\\dfrac{1}{ax+b}\\)\n\nIncreasing and Decreasing Absolute Risk Aversion (IARA and DARA):\n\nRisk aversion increase or decreases in \\(x\\).\n\n", "meta": {"hexsha": "cfc94e93447e99f4cc33761498836e1364dcf61e", "size": 400, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/uncertainty/02-01-absolute.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/uncertainty/02-01-absolute.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/uncertainty/02-01-absolute.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.1818181818, "max_line_length": 65, "alphanum_fraction": 0.6825, "num_tokens": 125, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7759898329448942}}
{"text": "\\chapter{Stream}\n\\section{Sliding Window}\n\\runinhead{Sliding Window Maximum.} Given an array $nums$, Find the list of maximum in the sliding window of size $k$ which is moving from the very left of the array to the very right. $\\rightarrow$ double-ended queue.\n\nInvariant: the queue is storing the non-decreasing-ordered elements of current window.\n\n\\runinhead{Sliding Window Median.} Find the list of median in the sliding window. $\\rightarrow$ Dual heap with lazy deletion - section \\ref{dh_lazy_del}.\n", "meta": {"hexsha": "3edb478681e3382bf1ae1db085169a69a0ade4b6", "size": 504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterStream.tex", "max_stars_repo_name": "li77leprince/Algo-Quicksheet", "max_stars_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "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": "chapterStream.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": "chapterStream.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": 63.0, "max_line_length": 218, "alphanum_fraction": 0.7797619048, "num_tokens": 120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8459424431344437, "lm_q1q2_score": 0.7759852548561392}}
{"text": "% Time-stamp: <2004/04/06, 16:46:43 (EST), maverick, test.tex>\n\\subsection{Strict diagonal-dominance}\nSuppose we are given a matrix $A=L+D$, where $L$ is a Laplacian and\n$D$ is a nonnegative diagonal matrix, for which we seek to construct a\npreconditioner.\n \nWe may construct a Support Tree Preconditioner, $B =\n\\begin{pmatrix} T & U\\\\U\\TT & W\\end{pmatrix}$ for $L$ and to use $B'\n=\\begin{pmatrix} T & U \\\\U\\TT & W+D\\end{pmatrix}$ as a preconditioner\nfor $A$.  If we let $Q = W - U\\TT T\\IV U$, by Lemma~\\ref{lem:stcg} it\nsuffices to bound $\\sigma(A/Q+D)$ and $\\sigma(Q+D/A)$.\n\n\\begin{proposition}\\label{prop:XZ-YZ}\nIf $X$, $Y$, and $Z$ are spsd matrices of the same size then \n$\\sigma(X+Z/Y+Z) \\leq \\max\\{\\sigma(X/Y),\\, 1\\}$.\n\\end{proposition}\n\n\\Proof We have $\\sigma(X+Z/Y+Z) = \n\\min\\{\\tau \\mid \\forall\\vv{x},\\, \\tau\\cdot \\vv{x}\\TT (Y+Z)\\vv{x} \\geq\n       \\vv{x}\\TT(X+Z)\\vv{x}\\} = \n\\min\\{\\tau \\mid \\forall\\vv{x},\\, (\\tau-1)\\cdot \\vv{x}\\TT Z\\vv{x} + \n      \\tau \\cdot\\vv{x}\\TT Y\\vv{x} \\geq \\vv{x}\\TT X\\vv{x}\\} \\leq \n\\max\\{1,\\,\\sigma(X/Y)\\}$.\\QED\n\n", "meta": {"hexsha": "37a19e8368cc7ac94b1f8fce70b5f78326149648", "size": 1047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "utils/tests/tex.tex", "max_stars_repo_name": "luoqingzhou/solarized", "max_stars_repo_head_hexsha": "2a33be435a7d924f3180cbd3a1094071457cef42", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10743, "max_stars_repo_stars_event_min_datetime": "2015-01-01T04:29:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:51:20.000Z", "max_issues_repo_path": "utils/tests/tex.tex", "max_issues_repo_name": "RangeChiong/solarized", "max_issues_repo_head_hexsha": "e40cd4130e2a82f9b03ada1ca378b7701b1a9110", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 124, "max_issues_repo_issues_event_min_datetime": "2015-01-06T06:54:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-19T22:17:09.000Z", "max_forks_repo_path": "utils/tests/tex.tex", "max_forks_repo_name": "RangeChiong/solarized", "max_forks_repo_head_hexsha": "e40cd4130e2a82f9b03ada1ca378b7701b1a9110", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3561, "max_forks_repo_forks_event_min_datetime": "2015-01-01T01:50:33.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-27T23:21:22.000Z", "avg_line_length": 41.88, "max_line_length": 70, "alphanum_fraction": 0.6170009551, "num_tokens": 429, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026482819238, "lm_q2_score": 0.8459424295406087, "lm_q1q2_score": 0.7759852309116451}}
{"text": "\\section{Bayesian linear regression}\n\n\\subsection{Linear regression revisited}\n\\begin{itemize}\n\\item Suppose that we have data $D=\\{(\\xx_1, t_1), \\ldots, (\\xx_N, t_N) \\}$\n\\item We assume that the data can be modelled by some function $t_n \\approx y(x, \\omega)+ \\epsilon$, where $\\epsilon$ models additive noise.\n\\item  We assume that noise is independent, identically distributed and Gaussian: \n\\begin{align}\n\t\\epsilon &\\sim \\mathcal{N}(0,\\beta^{-1})\\\\\n\tt|\\xx, \\omega, \\beta &\\sim \\mathcal{N}(y(\\xx,\\omega), \\beta^{-1})\n\\end{align}\n\\end{itemize}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.5\\textwidth]{./lecture5/Figure128.pdf}\n\t\\caption{Linear regression. Bishop PRML Figure 1.28}\n\\end{figure}\n\n\n\\subsection{Maximum likelihood estimation for linear regression}\n\\begin{itemize}\n\\item We consider a linear model $y(\\xx,\\omega)= \\omega^\\top \\xx$\n\\item ~[On board: Likelihood, Maximum Likelihood Solution, Predictive distribution from MLE]\\\\\n\\item  For a Bayesian treatment, we need priors.\n\\end{itemize}\n\n\\begin{bbbox}{Maximum likelihood estimation for linear regression}\n\t\\begin{align*}\n\t\t\tL(t | x,\\omega) &= \\log \\left( \\prod_{n=1}^N p(t_n |  x_n, \\omega ) \\right) \\\\\n\t\t\t        &= \\sum_{n=1}^N \\log \\left( \\frac{1}{\\sqrt(2\\pi)} \\exp \\left( - \\frac{\\beta}{2} \\left( t_n - \t\\omega^{\\top} x_n \\right)^2 \\right) \\right) \\\\\n\t\t\t        &= const. + \\sum_{n=1}^N - \\frac{\\beta}{2} \\left( t_n - \\omega^{\\top} x_n \\right)^2 \\\\\n\t\t\t        &= const - \\underbrace{\\frac{\\beta}{2} \\sum_{n=1}^N \\left( t_n - \\omega^{\\top} x_n \\right)^2}_{AMSE - average mean squared error} \\\\\n\t   \\hat{\\omega} &= \\left( \\sum_{n=1}^N x_n x_n^{\\top} \\right)^{-1} \\left( \\sum_{n=1} x_n t_n \\right) \\\\\t\t\t \t    \\end{align*}\n\tPredictive distribution \\\\\n\t$P(t^{*} | x^{*},0) = P(t^{*} | x^{*},\\hat{\\omega}) = \\mathcal{N}(\\omega^{\\top} x^{*}, \\frac{1}{\\beta})$ \n\\end{bbbox}\n\n\\subsection{Maximum a posteriori estimation for the linear regression.}\n\\begin{align}\n\\omega_i &\\sim \\mathcal{N}(0,\\alpha^{-1})\\\\\np(\\omega| \\alpha) &= \\prod_{i=1}^M  \\sqrt{\\frac{\\alpha}{{2\\pi}}}\\exp\\left( -\\frac{\\alpha}{2}  {\\omega_i^2}\\right)\\\\\n&%\n =\\left(\\frac{\\alpha}{2\\pi}\\right)^{M/2} \\exp \\left(-\\frac{\\alpha}{2} \\omega^\\top \\omega  \\right) \\\\\n \\text{where } \\forall i,j: \\alpha_i &= \\alpha_j\n\\end{align}\n\n\\begin{bbbox}{Finding the maximum-a-posteriori of $\\omega$}\n\t\\begin{align*}\n\t\tL_{post}(t | x,\\omega) &= \\log \\left( \\prod_{n=1}^N p(t_n |  x_n, \\omega ) p(\\omega|\\alpha)\\right) \\\\\n\t\t &= \\sum_{n=1}^N \\log \\left( \\frac{1}{\\sqrt(2\\pi)} \\exp \\left( - \\frac{\\beta}{2} \\left( t_n - \t\\omega^{\\top} x_n \\right)^2 \\right) \\frac{\\alpha}{2\\pi}^{\\frac{M}{2}} \\exp \\left( -\\frac{\\alpha}{2} \\omega^{\\top}\\omega \\right) \\right) \\\\\n\t\t &= const. - \\frac{\\beta}{2} \\sum_{n=1}^N \\left( t_n - \\omega^{\\top} x_n \\right)^2 -\\frac{\\alpha}{2} \\omega^{\\top}\\omega \\\\\n\t\\hat{\\omega} &= \\left( \\sum_{n=1}^N x_n x_n^{\\top} + \\frac{\\alpha}{\\beta} \\mathbf{I}_M \\right)^{-1} \\left( \\sum_{n=1} x_n t_n \\right) \\\\\t\t\t \n\t\\end{align*}\n\\end{bbbox}\n\n\n\\subsection{Basis functions in linear regression}\n\\textbf{If you are smart about choosing good basis functions ('features'), linear regression can get you pretty far.}\n\\begin{itemize}\n\\item If we use nonlinear basis functions $\\phi(x)$, can model nonlinear relationships with $y(\\omega, \\xx)= \\omega^\\top \\phi(x)$.\n\\item Polynomial regression: $\\phi(x)=(1,x,x^2,x^3)$ ; (cubic feature space) \n\\item 'Gaussian bumps': $\\phi_i(x)= \\exp\\left((x-s_i)^2/\\sigma_i^2 \\right)$\n\\item Sigmoids $\\phi_i(x)=1/(1+\\exp(-x-s_i))$\n\\item  'Kernel methods' are essentially linear algorithms which take one basis function per data-point.\n\\item Predictive Mean [on board]\n\\end{itemize}\n\n\\begin{figure}\n\\centering\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{./lecture5/Figure31a.pdf}\n                \\caption{Polynomial basis.}\n    \\end{subfigure}%\n\t~\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{./lecture5/Figure31b.pdf}\n                \\caption{Gaussian bumps.}\n    \\end{subfigure}%\n\t~\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n                \\centering\n                \\includegraphics[width=\\textwidth]{./lecture5/Figure31c.pdf}\n                \\caption{Logistic sigmoids.}\n    \\end{subfigure}%\n    \\caption{Non-linear basis functions, taken from Bishop PRML}\n\\end{figure}\n\n\n\\subsection{Bayesian linear regression}\n\n\n\\textbf{Bayesian linear regression takes into account our uncertainty about parameters.}\n\n\\begin{itemize}\n\\item Posterior distribution is Gaussian $\\rightarrow$ Posterior mean and MAP coincide!\n\\item  However, neither the MLE nor the MAP solution take into account that we have (posterior) uncertainty about the parameters\n\\end{itemize}\n\n\n\\begin{figure}\n\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\centering\t\n\t\t\\includegraphics[width=\\textwidth]{./lecture5/LinReg.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{./lecture5/LinRegBayes.pdf}\n\t\\end{subfigure}\n\\end{figure}\n\n\n\\subsection{Gaussian processes}\n\\textbf{Illustration: Climate prediction [by Carl Rasmussen, University of Cambridge, using Gaussian Processes]}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{./lecture5/Rasmussen2}\n\t\\caption{Gaussian process regression.}\n\\end{figure}\n\n\n\\subsection{Sequential update of the posterior distribution}\n\\textbf{Bayesian regression illustrated: The more data we observe, the more constrained the parameters are.}\n\n\\begin{figure}\n\t\\includegraphics[width=\\textwidth]{./lecture5/Figure37.pdf}\n\t\\caption{Sequential update of the Gaussian posterior, figures taken from Bishop PRML}\n\\end{figure}\n\n\n\n\\textbf{Calculating the predictive mean and variance for Bayesian regression}\n\nAssume $\\alpha$ and $\\beta$ as given.\\\\ Posterior distribution: [derivation on board]\n\n\\begin{bbbox}{Bayesian linear regression: calculating posterior mean and variance}\n\tRecall the quadratic form for the Gaussian: \\\\\n\t\\begin{align*}\n\t\t&\\frac{1}{Z} \\exp \\left( -\\frac{1}{2} \\left( x-\\mu \\right)^{\\top} \\Sigma^{-1} \\left( x-\\mu \\right) \\right) \\\\\n\t\t           &= \\frac{1}{Z} \\exp \\left( -\\frac{1}{2} \\left( x^{\\top}\\Sigma^{-1}x + \\mu^{\\top}\\Sigma^{-1}\\mu \n\t\t             - \\mu^{\\top}\\Sigma^{-1}x - x^{\\top}\\Sigma^{-1}\\mu \\right) \\right)\\\\\n\t\t           &= \\frac{1}{Z} \\exp \\left( -\\frac{1}{2} x^{\\top}\\Sigma^{-1}x + x^{\\top}\\Sigma^{-1}\\mu + const. \\right) \\\\\n\t\\end{align*}\n\tHere again we can easily read out the posterior mean and covariance from the two terms. \\\\\n\tWe say that $\\omega | D \\sim \\mathcal{N}\\left( \\mu_{post}, \\Sigma_{post}\\right)$. \\\\\n\tSince the mode and mean of a Gaussian are the same thing we already know from our MAP estimation that:\n\t$ \\mu_{post} = \\left( \\sum_{n=1}^N x_n x_n^{\\top} + \\frac{\\alpha}{\\beta} \\mathbf{I}_M \\right)^{-1} \\left( \\sum_{n=1} x_n t_n \\right)$ \\\\\n\tThe next thing we have to do is to bring the posterior  distribution into the quadratic form from above and to read out the posterior covariance. Note that all terms that are independents from $\\omega$ will sucked into the constant term: \\\\\n\t\\begin{align*}\n\t\tP(\\omega|D) &= \\frac{1}{Z_1} \\prod_{n=1}^N P(t_n|x_n,\\omega) P(\\omega) \\\\\n\t\t&= \\frac{1}{Z_2} \\exp \\left( \\sum_{n=1}^N -\\frac{\\beta}{2} \\left( \\omega^{\\top} x_n - t_n \\right) ^2 - \\frac{\\alpha}{2} \\omega^{\\top} \\omega \\right) \\\\\n\t\t&= \\frac{1}{Z_2} \\exp \\left( -\\frac{\\beta}{2} \\sum_{n=1}^N \\left( \\omega^{\\top} x_n - t_n \\right) \\left( \\omega^{\\top} x_n - t_n \\right)^{\\top} - \\frac{\\alpha}{2} \\omega^{\\top} \\omega \\right) \\\\\n\t\t&= \\frac{1}{Z_3} \\exp \\left( -\\frac{1}{2} \\left( \\beta \\sum_{n=1}^N \\omega^{\\top} x_n x_n^{\\top} \\omega + \\alpha \\omega^{\\top} \\omega \\right) \\right) \\\\\n\t\t&= \\frac{1}{Z_3} \\exp \\left( -\\frac{1}{2} \\left( \\omega^{\\top} \\left( \\beta \\sum_{n=1}^N x_n x_n^{\\top} + \\alpha \\mathbf{I}_M \\right) \\omega \\right) \\right) \\\\\n\t\t\\Sigma_{post}^{-1}&=\\alpha \\mathbf{I}_M + \\beta \\sum_{n=1}^N x_n x_n^\\top\\\\\n\t\\end{align*}\n\\end{bbbox}\n\n\\begin{align}\n\\Sigma_{post}^{-1}&=\\alpha \\mathbf{I}+\\beta \\sum_i x_i x_i^\\top\\\\\n\\mu_{post}&=\\Sigma_{post} \\beta \\sum_i x_i t_i\n\\end{align}\n\nPredictive distribution: [derivation on board]\n\n\\begin{bbbox}{Predictive distribution}\n\tWe note that in the case of a regression the predictive error arises from our uncertainty about the parameters as well as the variance which is inherent to our predicted variable. We want to calculate the predictive distribution starting from the observation that making a prediction is basically a concatenation of two random variables.\n\t\\begin{align*}\n\t\tt^* &| D, x_*: \\;\n\t\tt^* = \\underbrace{\\omega^{\\top}x_*}_{y^*} + \\epsilon \\\\\t\t\n%\t\t\\mu &\\sim \\mathcal{N}(\\mu_0, \\frac{1}{\\tau}); \\;\n%\t\tx|\\mu \\sim \\mathcal{N}(\\mu,\\frac{1}{\\beta}); \\;\n%\t\t\\rightarrow x \\sim \\mathcal{N}(\\mu_0, \\frac{1}{\\tau} + \\frac{1}{\\beta}) \\\\\n\t\ty^* &\\sim \\mathcal{N} (\\mu_*,\\frac{1}{\\tau_{*}}); \\;\n\t\tt^*|y^* \\sim \\mathcal{N}(y^*,\\frac{1}{\\beta}); \\;\n\t\t\\rightarrow \\underbrace{t^* \\sim \\mathcal{N}(\\mu_*,\\frac{1}{\\tau_{*}} + \\frac{1}{\\beta})}_{\\text{Predictive distribution}} \\\\\n\t\\end{align*}\n\t\nWe see that the variance of our predictive distribution is calculated from the variance in our parameter estimate and from the variance in $t$. We can further express the posterior distribution based on:\n\t\\begin{align*}\n\t\t\\mu_* &= E(y^* | D) = E(\\omega^{\\top} x_* | D) \\\\\n\t\t      &= E(\\omega^{\\top} | D) x_* = E(\\omega | D)^{\\top} x_* \\\\\n\t\t      &= \\mu_{post}^{\\top} x_* \\\\\n\t\t\\frac{1}{\\tau_{*}} &= \\mbox{Var}(y^* | D) \\\\\n\t\t     &= \\mbox{Var}(\\omega^{\\top} x_* | D) = x_*^{\\top} \\mbox{Var}(\\omega^{\\top} | D) x_* \\\\\n   \t\t     &= x_*^{\\top} \\Sigma_{post} x_* \\\\\n\t\\end{align*}\n\\end{bbbox}\n\n\\begin{align}\nE(t^*|D,x^*)&= \\mu_{post}^\\top x^* \\\\\n\\mbox{Var}(t^*|D,x^*)&=  1/\\beta+ x^{*\\top} \\Sigma_{post} x^*\n\\end{align}\nWhat if there are basis functions? [on board]\n\n\n\n\\subsection{Fully Bayesian linear regression}\n\n\n\\textbf{But, where do we get $\\alpha$ and $\\beta$ from?}\n\n\\begin{itemize}\n\\item Bad news: Getting these makes things more complicated.\n\\item  Good news: This will not be on the exam (unless I take that back explicitly...). \n\\item  'Full' Bayesian inference: Integrate out $\\alpha$, $\\beta$. No closed form solution. Use (e.g.) variational inference.\n\\item  Practical solution: optimize $\\alpha$ and $\\beta$ by \\emph{maximizing the evidence}, also known as \\emph{marginal likelihood} or \\emph{likelihood type 2}\n\\begin{align}\nE&=\\log P(\\alpha, \\beta|D)\\\\\n&= \\log \\int_\\omega p(D|\\omega,\\beta) p(\\omega|\\alpha) p(\\alpha,\\beta)    d \\omega\\\\\n&= \\frac{M}{2}\\log(\\alpha)+\\frac{N}{2}\\log \\beta-\\mbox{M}(\\mu_{post})+\\frac{1}{2}|\\Sigma_{post}|-\\frac{N}{2} \\log(2\\pi) \n\\end{align}\n\\item $\\mu_{post}$ and $\\Sigma_{post}$ are the posterior mean and covariance, and $\\mbox{M}(\\mu_{post})=\\frac{\\beta}{2}\\sum_n (t_n-y(\\mu_{post},\\xx_n))^2+\\frac{\\alpha}{2} \\mu_{post}\\mu_{post}^\\top$ is the quadratic cost function evalulated at the posterior mean (see Bishop 3.5 for details).\n\\end{itemize}\n\n\n\\textbf{Optimization of the marginal likelihood is a Bayesian alternative to parameter-setting by cross-validation.}\n\n\\textbf{What we have not had time to cover:}\n\\begin{itemize}\n\\item \\emph{Non-Gaussian priors:} The most important non-Gaussian prior is the `Laplace prior' ('L1 regularization'), which leads to sparse MAP-solutions.\n\\item \\emph{Non-Gaussian noise models:} If you know that your noise is not Gaussian but, say, Poisson, use 'generalized linear regression'. Some choices of noise models are more robust to outliers than the Gaussian. We will do one specific example of generalized linear regression in the last lecture.\n\\item \\emph{Nonlinear regression models:} The most important Bayesian nonlinear regression technique is \\emph{Gaussian process regression}. In a nutshell, GP regression is like linear regressions but the algorithm puts ne basis function at each data-point. To understand GP regression, you need to understand Gaussians.\n\\end{itemize}\n\n\n", "meta": {"hexsha": "ead22338e6eb99c5826de0cecb0b9c010a290c70", "size": 11926, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture5/lecture5.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/lecture5/lecture5.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/lecture5/lecture5.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": 51.4051724138, "max_line_length": 338, "alphanum_fraction": 0.660405836, "num_tokens": 4008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302033, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7759803779006065}}
{"text": "\\section{Tutorial 2: Delilah and Complex Math Formulae}\nDelilah is working on a part of a material about linear algebra. As her work proceeds, she will obtain the ability to deal with complex mathematical formulae in \\LaTeX{}, especially those methods provided by the ams packages loaded in xjtlumath.\n\n\\subsection{Multiple Lined Formulae}\nA system of linear equations is a fundamental part of linear algebra. When Delilah tries to type a group of equations, she encounters a problem. In the predefined \\verb=\\[\\]= and environment equation, she finds no option to start a new line. Even the line-break options of \\LaTeX{} like \\verb=\\\\= and \\verb=\\newline= do not work there. Of course the equations should not be put in one line, so what should she do now? Later she learns that the environment \\emph{aligned} is designed to allow a system of equations to be aligned in multiple lines:\n\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\[\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\nHere, the ampersand sign \\verb=&= is used before the symbols according to which the equations are to be aligned. The line break sign \\verb=\\\\= starts a new line of equation. Note that other line-break operations cannot be used here.\n\nDelilah likes the result, but she feels that the equations are too lonely. She thinks that adding a large curly bracket for them will comfort them. \\LaTeX{} supports a syntax to put things before and after a group of things.\n\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\[\n\\left\\{\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\right.\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\left\\{\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\right.\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\nThe \\verb=\\left= command defines what is to be put on the left, and the \\verb=\\right= command defines what is to be put on the right. Delilah does not want to put anything on the right, so she writes \\verb=.= for nothing.\n\nFor a group of equations that requires no alignment, or for a single equation that is too long to fit in one line, the environment \\emph{gathered} that does no alignment is a better choice:\n\n\\begin{miniexammar}{.45\\textandmarginlen}{\n\\[\n\\begin{gathered}\n\\cos {z} = 1 - \\frac{z^2}{2!} + \\frac{z^4}{4!} - \\frac{z^6}{6!} + \\cdots \\\\\n= \\sum_{n=0}^\\infty {\\frac{(-1)^n z^{2n}}{(2n!)}}\n\\end{gathered}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\begin{gathered}\n\\cos {z} = 1 - \\frac{z^2}{2!} + \\frac{z^4}{4!} - \\cdots \\\\\n= \\sum_{n=0}^\\infty {\\frac{(-1)^n z^{2n}}{(2n!)}}\n\\end{gathered}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\n\nAfter writing several groups of equations, Delilah wants to reference one of them. She uses the equation environment instead of \\verb=\\[\\]=, but finds out that the equations are numbered as a whole.\n\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\begin{equation}\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\end{equation}\n}\n\\begin{lstlisting}\n\\begin{equation}\n\\begin{aligned}\nx+y &= 1\\\\\nx-y &= 2\n\\end{aligned}\n\\end{equation}\n\\end{lstlisting}\n\\end{miniexammar}\nSo it is difficult for her to reference a single equation in a group. amsmath provides the environment align for this purpose:\n\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\begin{align}\nx+y &= 1\\\\\nx-y &= 2\n\\end{align}\n}\n\\begin{lstlisting}\n\\begin{align}\nx+y &= 1\\\\\nx-y &= 2\n\\end{align}\n\\end{lstlisting}\n\\end{miniexammar}\n\nIf she doesn't want to number a single equation, she needs to append \\verb=\\nonumber= at the end of that line.\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\begin{align}\nx+y &= 1\\\\\nz&=10 \\nonumber\\\\\nx-y &= 2\n\\end{align}\n}\n\\begin{lstlisting}\n\\begin{align}\nx+y &= 1\\\\\nz &= 10 \\nonumber\\\\\nx-y &= 2\n\\end{align}\n\\end{lstlisting}\n\\end{miniexammar}\n\nWithout the ``ed'' suffix, \\emph{gather} is also a standalone environment that does what gathered do. But there is a major difference between the normal version and ``ed''ed version. Delilah finds it impossible to put the bracket again before a align or gather, because they don't need to be surrounded by mathematical environments. Also, their width are fixed to be the width of texts, while their ``ed''ed versions can be of any width.\n\nAs the same as the equation environment, their starred versions give no number by default.\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\begin{align*}\nx+y &= 1\\\\\nx-y &= 2\n\\end{align*}\n}\n\\begin{lstlisting}\n\\begin{align*}\nx+y &= 1\\\\\nx-y &= 2\n\\end{align*}\n\\end{lstlisting}\n\\end{miniexammar}\n\nDelilah is able to put multiple groups of equations in one align, just by adding ampersands between the groups.\n\\begin{miniexammar}{.4\\textandmarginlen}{\n\\begin{align*}\nx+y &= 1  & a+b &= 3\\\\\nx-y &= 2  & a-b &= 4\n\\end{align*}\n}\n\\begin{lstlisting}\n\\begin{align*}\nx+y &= 1  & a+b &= 3\\\\\nx-y &= 2  & a-b &= 4\n\\end{align*}\n\\end{lstlisting}\n\\end{miniexammar}\nThe space between the groups is adjusted automatically by align.\n\n\\subsection{Matrices}\nMatrices are vital to linear algebra, as they represent linear mappings from a vector space to another in specific bases. Also, the coefficient matrix and the augmented matrix are convenient in operating linear equations.\n\namsmath provides several environments for typing matrices.\n\\begin{miniexammar}{.5\\textandmarginlen}{\n\\[\n\\begin{bmatrix}\n1&2&3&4\\\\\n5&6&7&8\\\\\n9&10&11&12\\\\\n13&14&15&16\n\\end{bmatrix}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\begin{bmatrix}\n1&2&3&4\\\\\n5&6&7&8\\\\\n9&10&11&12\\\\\n13&14&15&16\n\\end{bmatrix}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\nThe environments pmatrix, Bmatrix, vmatrix, and Vmatrix produce delimiters of \\verb=()=, \\verb={}=, \\verb=||=, and \\verb=|| ||=, respectively.\n\nTo use matrices in inline mode, Delilah uses the environment smallmatrix, which has no p,b,B,v,V versions in amsmath, as it is the author's responsibility to decide the delimiters.\n\\begin{miniexammar}{.4\\textandmarginlen}{\nThe matrix $\\left(\\begin{smallmatrix} a&b\\\\c&d \\end{smallmatrix}\\right)$ is so small and cute!\n}\n\\begin{lstlisting}\nThe matrix $\\left(\\begin{smallmatrix} a&b\\\\c&d \\end{smallmatrix}\\right)$ is so small and cute!\n\\end{lstlisting}\n\\end{miniexammar}\n\nWhen Delilah tries to put fractions inside a matrix, she finds something annoying.\n\\begin{miniexammar}{.3\\textandmarginlen}{\n\\[\n\\begin{bmatrix}\n1&\\frac{1}{2}&\\frac{1}{3}\\\\\n1&\\frac{1}{4}&\\frac{1}{5}\\\\\n\\end{bmatrix}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\begin{bmatrix}\n1&\\frac{1}{2}&\\frac{1}{3}\\\\\n1&\\frac{1}{4}&\\frac{1}{5}\\\\\n\\end{bmatrix}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\nThe fractions above and below are so close that they touch each other! This is not what Delilah wants and she is surprised that \\LaTeX{} doesn't detect this and do something. Fortunately, in amsmath environments, an optional argument is allowed to be passed to \\verb=\\\\= to define the actual vertical space between lines. For fractions, 2ex is a good option. Also, the fractions are in inline mode. The \\verb=\\dfrac= command gives displayed fractions.\n\\begin{miniexammar}{.3\\textandmarginlen}{\n\\[\n\\begin{bmatrix}\n1&\\dfrac{1}{2}&\\dfrac{1}{3}\\\\[2ex]\n1&\\dfrac{1}{4}&\\dfrac{1}{5}\n\\end{bmatrix}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\begin{bmatrix}\n1&\\dfrac{1}{2}&\\dfrac{1}{3}\\\\[2ex]\n1&\\dfrac{1}{4}&\\dfrac{1}{5}\n\\end{bmatrix}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\n\nSometimes a matrix is too large to be displayed fully. At these times, the use of ellipses (plural of ellipsis, not ellipse) is important. When Delilah writes the inverse of a matrix, she uses ellipses.\n\\begin{miniexammar}{.5\\textandmarginlen}{\n\\[\nA^{-1} = \\frac{1}{\\det A}\n\\begin{bmatrix}\nC_{11} & C_{21} & \\cdots & C_{n1} \\\\\nC_{12} & C_{22} & \\cdots & C_{n2} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\nC_{n2} & C_{n2} & \\cdots & C_{nn} \\\\\n\\end{bmatrix}\n\\]\n}\n\\begin{lstlisting}\n\\[\nA^{-1} = \\frac{1}{\\det A}\n\\begin{bmatrix}\nC_{11} & C_{21} & \\cdots & C_{n1} \\\\\nC_{12} & C_{22} & \\cdots & C_{n2} \\\\\n\\vdots & C\\vdots & \\ddots & \\vdots \\\\\nC_{n2} & C_{n2} & \\cdots & C_{nn} \\\\\n\\end{bmatrix}\n\\]\n\\end{lstlisting}\n\\end{miniexammar}\n\n\\subsection{Texts and Operator Names}\nTo put text inside math environments, Delilah uses the \\verb=\\text= command provided by amsmath.\n\\begin{miniexammar}{.57\\textandmarginlen}{\n\\begin{definition}[Null Space]\nThe null space of an $m \\times n$ matrix $A$, written as $\\Nul A$, is the set of all solutions\nof the homogeneous equation $A\\vec{x} = \\vec{0}$. In set notation,\n\\[\n\\Nul A = \\{\\vec{x}:\\vec{x} \\text{ is in } \\mathbb{R}^n \\text{ and } A\\vec{x} = \\vec{0} \\}\n\\]\n\\end{definition}\n}\n\\begin{lstlisting}\n\\begin{definition}[Null Space]\nThe null space of an $m \\times n$ matrix $A$, written as $\\Nul A$, is the set of all solutions\nof the homogeneous equation $A\\vec{x} = \\vec{0}$. In set notation,\n\\[\n\\Nul A = \\{\\vec{x}:\\vec{x} \\text{ is in } \\mathbb{R}^n \\text{ and } A\\vec{x} = \\vec{0} \\}\n\\]\n\\end{definition}\n\\end{lstlisting}\n\\end{miniexammar}\n\nThe commands like \\verb=\\Nul=, \\verb=\\sin=, ... are math operators. Part of predefined math operators in \\LaTeX{} are shown in Table \\ref{tab:predefmathop}.\n\\begin{table}[hbpt]\n\\begin{center}\n\\small\n\\begin{tabular}{cl|cl|cl}\nResult & Command & Result & Command & Result & Command \\\\\n\\hline\narccos & \\verb=\\arccos= & arcsin & \\verb=\\arcsin= & arctan & \\verb=\\arctan= \\\\\ncos & \\verb=\\cos= & sin & \\verb=\\sin= & tan & \\verb=\\tan= \\\\\ncot & \\verb=\\cot= & sec & \\verb=\\sec= & csc & \\verb=\\csc= \\\\\ncosh & \\verb=\\cosh= & sinh & \\verb=\\sinh= & tanh & \\verb=\\tanh= \\\\\nlim & \\verb=\\lim= & lim inf & \\verb=\\liminf= & lim sup & \\verb=\\limsup= \\\\\nln & \\verb=\\ln= & log & \\verb=\\log= & lg & \\verb=\\lg= \\\\\nmax & \\verb=\\max= & min & \\verb=\\min= & sup & \\verb=\\sup= \\\\\ninf & \\verb=\\inf= &  &  &  &  \\\\\nker & \\verb=\\ker= & det & \\verb=\\det= & exp & \\verb=\\exp= \n\\end{tabular}\n\\end{center}\n\\caption{Some Predefined Math Operators}\n\\label{tab:predefmathop}\n\\end{table}\n\nIn fact, operator \\verb=\\Nul= and \\verb=\\Span= are defined by xjtlumath as in the forms in the year 1 linear algebra textbook of XJTLU. Also, xjtlumath changes the default \\verb=\\vec= command in \\LaTeX{} so that vectors appear in bold form rather than with a arrow above them.\n\nSome operators, like \\verb=\\lim=, are designed to support taking limits. That is, in displayed mode, when one tries to give one of such operators a subscript using \\verb=_=, the subscript will appear at the bottom of the operator.\n\\begin{parexammar}{.4\\textandmarginlen}{\n\\[\n\\lim_{x\\to 0} f(x)\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\lim_{x\\to 0} f(x)\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\nDelilah is able to explicitly control the limit style by using \\verb=\\limits= and \\verb=\\nolimits=. Note that these two commands can only be used after a operation that supports taking limits.\n\\begin{parexammar}{.4\\textandmarginlen}{\n$\\lim\\limits_{x \\to 0}f(x)$\n\\[\n\\lim\\nolimits_{x\\to 0} f(x)\n\\]\n}\n\\begin{lstlisting}\n$\\lim\\limits_{x \\to 0}f(x)$\n\\[\n\\lim\\nolimits_{x\\to 0} f(x)\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\n\\subsection{Delimiters}\nDelilah already knows how to type basic delimiters. For parentheses and square brackets, plain text will do; and since the curly brackets are reserved by \\LaTeX{}, Delilah needs to add a backslash before each of them.\n\\begin{parexammar}{.45\\textandmarginlen}{\nThe range of a function may be expressed explicitly by its domain and itself: the range of $f: X \\to Y$ is $f(X)$.\n\nIn some context the arguments of a function are enclosed by square brackets: $f[x]$.\n\nCurly brackets are often used to show a set: $S := \\{2,4,\\cdots\\}$.\n}\n\\begin{lstlisting}\nThe range of a function may be expressed explicitly by its domain and itself: the range of $f: X \\to Y$ is $f(X)$.\n\nIn some context the arguments of a function are enclosed by square brackets: $f[x]$.\n\nCurly brackets are often used to show a set: $S := \\{2,4,\\cdots\\}$.\n\\end{lstlisting}\n\\end{parexammar}\n\nYet in some conditions where the expression being enclosed has a different height, the result becomes unsatisfactory. \\LaTeX{} provides a mechanism to enable the user to automatically or manually adjust the size of delimiters.\n\nAdding \\verb=\\left= and \\verb=\\right= around a pair of delimiters automatically adjust their size to match the expression being enclosed. However, sometimes we want the delimiters to be a bit bigger or smaller, and that's when we need to manually adjust the size.\n\\begin{parexammar}{.5\\textandmarginlen}{\n\\[\n\\left( \\frac{1}{2} \\right) \n\\Bigg( \\bigg( \\Big( \\big( x\\big) \\Big) \\bigg) \\Bigg)\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\left(\\frac{1}{2}\\right) \\Bigg( \\bigg( \\Big( \\big( x\\big) \\Big) \\bigg) \\Bigg)\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\nDelilah once mismatched a pair of delimiters, but she found that the height of the two symbols are still the same. She learns in addition that the dot `.' can be used to inform \\LaTeX{} to insert nothing.\n\\begin{parexammar}{.5\\textandmarginlen}{\nA fraction enclosed left by a parenthesis, and right by a curly bracket.\n\\[\n\\left(\\frac{a}{b}\\right\\}\n\\]\nA system of equations\n\\[\n\\left\\{\n\\begin{aligned}\nx+y&=1\\\\\nx-y&=2\n\\end{aligned}\n\\right.\n\\]\n}\n\\begin{lstlisting}\nA fraction enclosed left by a parenthesis, and right by a curly bracket.\n\\[\n\\left(\\frac{a}{b}\\right\\}\n\\]\nA system of equations\n\\[\n\\left\\{\n\\begin{aligned}\nx+y&=1\\\\\nx-y&=2\n\\end{aligned}\n\\right.\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\nNow Delilah knows how to properly handle delimiters, but the repetitive \\verb=\\left= and \\verb=\\right= really makes her sick. xjtlumath simplifies the work by providing these predefined groups of delimiters. The following examples show the delimiter groups defined by xjtlumath, as well as the explicit control of the size.\n\\begin{parexammar}{.5\\textandmarginlen}{\nThese delimiters are defined by xjtlumath.\n\\[\n\\rbra{x},\\ \\sbra{x},\\ \\cbra{x},\\ \\abs{x},\\ \\floor{x},\\ \\ceiling{x}\n\\]\nOne can also change the delimiter resizer.\n\\[\n\\abs[\\bigg]{x}\n\\]\n}\n\\begin{lstlisting}\nThese delimiters are defined by xjtlumath.\n\\[\n\\rbra{x},\\ \\sbra{x},\\ \\cbra{x},\\ \\abs{x},\\ \\floor{x},\\ \\ceiling{x}\n\\]\nOne can also change the delimiter resizer.\n\\[\n\\abs[\\bigg]{x}\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\n\\subsection{Symbols}\nThe standard \\LaTeX{} font in math environments is neat and clean. Yet in some special occasions Delilah would like to change the font of certain symbols. For example, to represent some conventional sets, she uses the blackboard font.\n\\begin{parexammar}{.4\\textandmarginlen}{\n\\[\n\\mathbb{R}\\quad \\mathbb{N}\\quad \\mathbb{Q}\\quad \\mathbb{Z}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\mathbb{R}\\quad \\mathbb{N}\\quad \\mathbb{Q}\\quad \\mathbb{Z}\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\nWriting \\verb=\\mathbb= every time is somehow irritating. For this purpose, xjtlumath defines shorthands for them.\n\\begin{parexammar}{.45\\textandmarginlen}{\n\\[\n\\setr \\quad \\setq \\quad \\setz \\quad \\setn \\quad \\setnp\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\setr \\quad \\setq \\quad \\setz \\quad \\setn \\quad \\setnp\n\\]\n\\end{lstlisting}\n\\end{parexammar}\n\nOther font controlling methods are like what we have talked about in subsection \\ref{subsec:fonts}. For example, \\verb=\\mathrm= gives font in \\textrm{Roman} family, and \\verb=\\mathbf= gives font in \\textbf{bold} series.\n\\begin{parexammar}{.45\\textandmarginlen}{\n\\[\n\\mathrm{Like normal text} \\quad \\mathbf{bold}\n\\]\n}\n\\begin{lstlisting}\n\\[\n\\mathrm{Like normal text} \\quad \\mathbf{bold}\n\\]\n\\end{lstlisting}\n\\end{parexammar}", "meta": {"hexsha": "a222e2137b188a92fd0f6455247a5482448b9b6a", "size": 15122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Bin/Documentation/LaTeX Documentation/Tutorial 2.tex", "max_stars_repo_name": "Little-He-Guan/A-XJTLU-Math-Club-LaTeX-Template", "max_stars_repo_head_hexsha": "b008538f693d67932746a5c6dfa799b902b783f5", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-25T03:20:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-25T03:20:04.000Z", "max_issues_repo_path": "Bin/Documentation/LaTeX Documentation/Tutorial 2.tex", "max_issues_repo_name": "Little-He-Guan/A-XJTLU-Math-Club-LaTeX-Template", "max_issues_repo_head_hexsha": "b008538f693d67932746a5c6dfa799b902b783f5", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Bin/Documentation/LaTeX Documentation/Tutorial 2.tex", "max_forks_repo_name": "Little-He-Guan/A-XJTLU-Math-Club-LaTeX-Template", "max_forks_repo_head_hexsha": "b008538f693d67932746a5c6dfa799b902b783f5", "max_forks_repo_licenses": ["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.1622807018, "max_line_length": 546, "alphanum_fraction": 0.7044041793, "num_tokens": 4961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541611, "lm_q2_score": 0.9046505318875316, "lm_q1q2_score": 0.7759803691262}}
{"text": "\\section{Using custom cost function}\n\n\\subsection{Implementation}\nA cost function that satisfies the specified conditions is shown equation \\ref{eq:custom_cost_function}\n\n\\begin{equation}\n\\label{eq:custom_cost_function}\ncost(h_{\\theta}(x_i), y_i) = 100(1-y_i)h_{\\theta}(x_i) + 100y_i(1-h_{\\theta}(x_i))\n\\end{equation}\n\nwhere,\n\n\\begin{equation}\n\\label{eq:logistic_regression}\nh_{\\theta}(X) = \\frac{1}{e^{-\\theta_0 - \\theta_1 * X}}\n\\end{equation}\n\nThe minimization function J($\\theta$) is given by equation \\ref{eq:custom_minimization_function}\n\n\\begin{equation}\n\\label{eq:custom_minimization_function}\nJ(\\theta) = \\frac{100}{m} \\sum_{i=1}^{m}(1-y_i)h_{\\theta}(x_i) + y_i(1-h_{\\theta}(x_i))\n\\end{equation}\n\nThe update rules for $\\theta$s for the above minimization function are as follows.\n\n\\begin{equation}\n\\label{eq:theta_0_update}\n\\theta_0 = \\theta_0 + \\frac{100\\alpha}{m}\\sum_{i=1}^{m}h_\\theta(x_i)(1-h_\\theta(x_i))(1-2y)\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:theta_1_update}\n\\theta_1 = \\theta_1 + \\frac{100\\alpha}{m}\\sum_{i=1}^{m}h_\\theta(x_i)(1-h_\\theta(x_i))(1-2y)x_{i1}\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 = -13.915013230977546\n\\end{equation}\n\n% Theta 1 final value\n\\begin{equation}\n\\theta_1 = 4.276707007556025\n\\end{equation}\n\nThe plot of decision curve for above $\\theta$s is shown in figure \\ref{fig:custom_cost_function}\n\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{custom_cost_function_0_01.png}\n  \\caption{Sigmoid graph for custom cost function}\n  \\label{fig:custom_cost_function}\n\\end{figure}\n\nIf we overlap the curve obtained from logistic regression shown in figure \\ref{fig:logistic_regression} and curve in figure \\ref{fig:custom_cost_function}\nthe resulting figure is shown in figure in \\ref{fig:compare_log_vs_custom}.\n\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{compare_log_vs_custom.png}\n  \\caption{Comparison of logistic regression and custom cost function}\n  \\label{fig:compare_log_vs_custom}\n\\end{figure}\n\n\\begin{figure}[!ht]\n  \\includegraphics[width=\\textwidth,height=0.4\\textheight,keepaspectratio]{custom_cost_function_0_0001.png}\n  \\caption{Improved curve for custom cost function}\n  \\label{fig:custom_cost_function_0_0001}\n\\end{figure}\n\n\\subsection{Conclusion}\nAs shown by figure \\ref{fig:compare_log_vs_custom}, after running for the same numbers of iterations the boundary line obtained\nfrom custom cost function does not clearly divides the data into two seperate regions as some of the data points lie in the boundary line.\nThe equations \\ref{eq:theta_0_update} and \\ref{eq:theta_1_update} shows that the learning rate is multiplied by a scalar factor of 100. Due which the\nlearning rate for $\\theta$s becomes high. We can overcome this by further decreasing the learning rate to about 0.0001 as shown in figure \\ref{fig:custom_cost_function_0_0001}\n\n\\subsection{Source Code}\n\\lstinputlisting[language=python]{task_4.py}\n", "meta": {"hexsha": "5067c50ac0940dc49a70f3e4472f159e48c3757e", "size": 3071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/custom_cost.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/custom_cost.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/custom_cost.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": 37.9135802469, "max_line_length": 175, "alphanum_fraction": 0.7723868447, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037221561136, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7758904954200458}}
{"text": "\\section{Background}\n\\label{SEC:background}\n\nWe briefly review the relevant properties of cryptographic $(k, n)$-threshold\nschemes.  Although the specific $(k,n)$-threshold scheme that is used \nis not fundamental to our\nwork, we describe Shamir Secret Sharing \\cite{shamir1979share}, which we use to develop\nexplicit examples within the text. \n\n\\emph{The $(k, n)$-threshold scheme}\n\nThreshold schemes protect secret information (usually a key) by deriving $n$\ndifferent shares from this information.  A threshold scheme describes how any $k$\nshares (from a set of n total shares) can be used to recover an original\nsecret.  The number of needed shares, $k$, is called the threshold.  If fewer than\n$k$ shares are known, no information about the secret is provided.\n\nShamir Secret Sharing is an algorithm that describes how a secret is divided\ninto a set of $n$ shares.  If a threshold $k$ of shares are input (specified when the \nsecret is divided), the original secret can be reconstructed. To hide\na secret, Shamir Secret Sharing computes $k - 1$ random coefficients for a $k - 1$\ndegree polynomial $f(x)$ in a finite field (commonly GF-256 or GF-65536). The $k$th\nterm (commonly the constant term) contains the secret. To compute a share, a\nvalue between 1 and the order of the field is chosen. The polynomial is\nevaluated with $x$ equal to the share value, where the terms $x$ and $f(x)$ are used\nas the share. To reconstruct the secret from at least $k$ shares, a party can\ninterpolate the values in the finite field to find the constant term (i.e., the\nsecret). In practice, interpolation is often computationally optimized so that\nonly the constant term is recovered.\n\nSuppose that a secret, 235, is to be hidden so that it can only be\nreconstructed if three shares are provided. Because the threshold is three, two\nrandom terms are first generated (24 and 182) to build a GF-256 polynomial,\nsuch as $f(x) = 24x^2 + 182x + 235$. Shares can then be generated by computing $x$\nand $f(x)$, such as: (1, 92), (2, 148), (3, 37), (4, 69), etc. A party that has\nat least three shares can interpolate to reconstruct the full polynomial of\n$f(x)$ and thus, the secret (235). \n\nIt is possible to generate additional shares after recovering the secret, (e.g.,\nif Lagrange interpolation is performed during reconstruction). This makes share\nrecovery slightly more computationally complex but also makes it possible (and\nefficient) to generate additional shares simply by evaluating f(x) for the\nspecified share.  This means that all shares do not need to be created\ninitially --- they may instead be added (or recovered) after the secret has\nbeen reconstructed.\n\nIn many cases, the secret will be larger than the size of the finite field.  A\nlarge secret can be stored by breaking it into segments that are the size of\nthe finite field (often one or two bytes) and applying the above technique\nseparately to each segment.  The same share number, $x$, is typically used for\neach share $f_i(x)$.  This simplifies --- and effectively hides --- the fact that a\nsecret has only a limited size.  An integrity check can be added to detect whether\nan incorrect share has been provided.  As was previously described, when given a set\nof any k distinct shares, whether valid or invalid, Shamir Secret Sharing will\nproduce a polynomial of the appropriate length. This means that if any share is\ninvalid, its resulting polynomial will be incorrect. To avoid this problem,\nimplementations of Shamir Secret Sharing typically store an integrity check by\nappending the hash of the secret to the secret; this check detects if an\nincorrect share has been provided.  When the shares are reconstructed, the\nadditional integrity check provides verification that the correct shares were\ngiven.\n\n", "meta": {"hexsha": "6d45857de66cec5b32877eede6dfdf13c1368bf4", "size": 3768, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "academic-writeup/background.tex", "max_stars_repo_name": "PolyPasswordHasher/PolyPasswordHasher", "max_stars_repo_head_hexsha": "7953d182b90e04b5b10945e169afa6e593f84428", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 286, "max_stars_repo_stars_event_min_datetime": "2015-01-13T14:18:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-23T02:07:03.000Z", "max_issues_repo_path": "academic-writeup/background.tex", "max_issues_repo_name": "PolyPasswordHasher/PolyPasswordHasher", "max_issues_repo_head_hexsha": "7953d182b90e04b5b10945e169afa6e593f84428", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2015-05-25T04:01:35.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-27T21:41:20.000Z", "max_forks_repo_path": "academic-writeup/background.tex", "max_forks_repo_name": "PolyPasswordHasher/PolyPasswordHasher", "max_forks_repo_head_hexsha": "7953d182b90e04b5b10945e169afa6e593f84428", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 25, "max_forks_repo_forks_event_min_datetime": "2015-01-01T08:38:10.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-19T11:56:44.000Z", "avg_line_length": 59.8095238095, "max_line_length": 87, "alphanum_fraction": 0.7746815287, "num_tokens": 893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7758408265735}}
{"text": "\\section{Number Representation}\n\nBy default the standard binary system can only represent unsigned integers.\nWith other number representation systems you can also represent signed numbers and floats.\nThis chapter describes different number systems.\n\n\\subsection{Sign \\& Magnitude}\n{\\bf Sign \\& Magnitude} is the (for humans) the simplest method of representing numbers.\nYou add one bit at the most significant bit (the `sign' bit).\nThis bit defines if the rest of the bitstring is positive or negative.\nA \\(0\\) indicates a positive number, a \\(1\\) a negative one.\nApplying direct operations to these numbers does not work, for example \\(5 + -5\\).\nWhen you do this with Sign \\& Magnitude you'll end up with \\(2\\).\nThis is obviously not correct.\nAlso you end up with two zero's, \\(0000\\) and \\(1000\\).\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c | c | c}\n\t\tDecimal & Binary    & S \\& M    \\\\\n\t\t\\hline\n\t\t72      & 0100 1000 & 0100 1000 \\\\\n\t\t-57     & --        & 1011 1001 \\\\\n\t\t8       & 0000 1000 & 0000 1000 \\\\\n\t\t-8      & --        & 1000 1000 \\\\\n\t\t-43.75  & --        & --        \\\\\n\t\\end{tabular}\n\t\\caption{Sign \\& Magnitude}\n\\end{table}\n\n\\subsection{One's Complement}\n{\\bf One's complement} is the same as Sign \\& Magnitude,\nbut when the sign is positive you need to take the complement of the number.\nIt's a lot better for computer to work with, but you still cannot directly do operations to it.\nIf you do attempt to do calculations to it, you will get an offset of \\(1\\).\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c | c | c}\n\t\tDecimal & Binary    & One's Complement \\\\\n\t\t\\hline\n\t\t72      & 0100 1000 & 0100 1000        \\\\\n\t\t-57     & --        & 1100 0110        \\\\\n\t\t8       & 0000 1000 & 0000 1000        \\\\\n\t\t-8      & --        & 1111 0111        \\\\\n\t\t-43.75  & --        & --               \\\\\n\t\\end{tabular}\n\t\\caption{One's Complement}\n\\end{table}\n\n\\subsection{Two's Complement}\n{\\bf Two's complement} is the same as one's complement.\nThe difference is that you'll add 1 to the result when the number is negative.\nThis also makes sure there is only one zero.\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c | c | c}\n\t\tDecimal & Binary    & Two's Complement \\\\\n\t\t\\hline\n\t\t72      & 0100 1000 & 0100 1000        \\\\\n\t\t-57     & --        & 1100 0111        \\\\\n\t\t8       & 0000 1000 & 0000 1000        \\\\\n\t\t-8      & --        & 1111 1000        \\\\\n\t\t-43.75  & --        & --               \\\\\n\t\\end{tabular}\n\t\\caption{Two's Complement}\n\\end{table}\n\n\\subsection{Excess-N}\n{\\bf Excess-N} is great for really large positive or negative numbers.\nThe \\(N\\) in Excess-N stands for the offset used.\nFor example, if you want to represent \\(5\\) you can do \\(5 + N\\).\nThis gives \\(5 + 3 = 8\\) in Excess-3.\nTo get the \\(5\\) back you can just substract the \\(N\\) to the number.\nFor example \\(8 - 3 = 5\\).\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c | c | c | c}\n\t\tDecimal & Binary    & Excess-128 & Excess-57 \\\\\n\t\t\\hline\n\t\t72      & 0100 1000 & 1100 1000  & 1000 0001 \\\\\n\t\t-57     & --        & 0100 0111  & 0000 0000 \\\\\n\t\t8       & 0000 1000 & 1000 1000  & 0100 0001 \\\\\n\t\t-8      & --        & 0111 1000  & 0011 0001 \\\\\n\t\t-43.75  & --        & --         & --        \\\\\n\t\\end{tabular}\n\t\\caption{Excess-N}\n\\end{table}\n\n\\subsection{IEEE-754}\n{\\bf IEEE-754} is an way of representing floats.\nIt has the following parts:\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{l | c | c| l}\n\t\tName     & Bits (32-bit) & Bits (64-bit) & Description                    \\\\\n\t\t\\hline\n\t\tSign     & 1             & 1             & 0 for positive, 1 for negative \\\\\n\t\tExponent & 8             & 11            & Exponent for the Mantissa      \\\\\n\t\tMantissa & 23            & 52            & The actual number, encodeds    \\\\\n\t\\end{tabular}\n\t\\caption{Parts of IEEE-754}\n\\end{table}\n\nTo convert a number to IEEE-754 you first have to convert the number to binary.\nLet's take the number \\(-43.75\\).\nWe can already see that the sign bit should be 1, as the number is negative.\nLet's first convert the interger first part, this gives \\(0010 1011\\).\nThen convert the decimal part seperately and add it.\nThis gives \\(0010 1011 . 1100\\).\nNow move the point to the first \\(1\\) and remember the places you've moved.\nThis gives \\(001.0 1011 1100\\), with 5 places moved.\nThe 5 is your exponent, but it needs a bias to deal with negative numbers.\nWith 32-bit the bias is \\(127\\), in 64-bit \\(1023\\).\nWe are using 32-bit, so apply a bias of \\(127\\).\nThis gives an exponent of \\(exp = 5 + 127 = 132\\) or \\(1000 0100\\).\nFor the mantissa part you copy all digits after the dot and right-pad with 0's till 23 bits.\nThis gives you \\(010 1111 0000 0000 0000 0000\\).\nThe complete format IEEE-754 gives \\(1100 0010 0010 1111 0000 0000 0000 0000\\)\n\n\\begin{table}[h]\n\t\\centering\n\t\\begin{tabular}{c | c | c | c | c}\n\t\tDecimal & Binary    & Sign & Exponent  & Mantissa                     \\\\\n\t\t\\hline\n\t\t72      & 0100 1000 & 0    & 1000 0101 & 001 0000 0000 0000 0000 0000 \\\\\n\t\t-57     & --        & 1    & 1000 0100 & 110 0100 0000 0000 0000 0000 \\\\\n\t\t8       & 0000 1000 & 0    & 1000 0010 & 000 0000 0000 0000 0000 0000 \\\\\n\t\t-8      & --        & 1    & 1000 0010 & 000 0000 0000 0000 0000 0000 \\\\\n\t\t-43.75  & --        & 1    & 1000 0100 & 010 1111 0000 0000 0000 0000 \\\\\n\t\\end{tabular}\n\t\\caption{IEEE-754}\n\\end{table}\n", "meta": {"hexsha": "0f6b86ecc76905122eacd697566e8749471e50ce", "size": 5287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Computer Organisation/chapters/number-representation.tex", "max_stars_repo_name": "dsluijk/TUD-CSE-summaries", "max_stars_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Computer Organisation/chapters/number-representation.tex", "max_issues_repo_name": "dsluijk/TUD-CSE-summaries", "max_issues_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Computer Organisation/chapters/number-representation.tex", "max_forks_repo_name": "dsluijk/TUD-CSE-summaries", "max_forks_repo_head_hexsha": "9157650c7a6af2e1c3072f6e66a6fd1e001460ce", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.5912408759, "max_line_length": 95, "alphanum_fraction": 0.6031776054, "num_tokens": 1787, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7758408226728168}}
{"text": "\\lab{QR Decomposition using Householder reflectors}{QR Decomposition using Householder reflectors}\n\\objective{Use orthonormal transformations to perform QR decomposition.}\n\\label{lab:Canonical_Transformations}\n\n\\section*{Orthonormal transformations}\nRecall that a matrix $Q$ is \\emph{unitary} if $Q^\\mathsf{H} Q = I$ or for real matrices,\n$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.\nThe number $\\kappa(A) = \\norm{A} \\norm{A^{-1}}$ is called the \\emph{condition number} of $A$.\nWe'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.\nFor the induced 2-norm, it holds that $\\norm{Q}=1$ when $Q$ is unitary.\nThe Cauchy-Schwarz inequality $\\norm{AB} \\leq \\norm{A} \\norm{B}$ also holds for this norm, and\nso it follows that $\\kappa(A) = \\norm{A} \\norm{A^{-1}} \\geq \\norm{A A^{-1}} = \\norm{I} = 1$.\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$.\nThis 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.\nLet's explore these two types of unitary transformations and some of their applications.\nWe 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\\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.\nWe applied the changes we needed to each portion of the array that needed to be changed.\nDoing 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\n$v_k \\left( v_k^\\mathsf{H} A[k:,k:] \\right)$, not an inner product.\nMake sure that you account for this when you write the code to run this algorithm.\nYou 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 place.\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 in Python.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from numpy.random import rand\n>>> from scipy import linalg as la\n>>> Q, X = la.qr(rand(500,500)) # create a random orthonormal matrix:\n>>> R = np.triu(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>>> 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}\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 generally very high, and this was the case here.\nThis has, in turn, made the condition number of $A$ extremely large as well.\nTry the following to compute the condition numbers of $A$.\nIn this case the condition numbers 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$; thus 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 try 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 chose $Q_1$ so that it does not fix the first row.\nWhen 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 it over and over again, the subdiagonal entries will often converge to zero.\nThat'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 computation of 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", "meta": {"hexsha": "d591fd37a269a06497ec0c12059bb26e1f717400", "size": 19460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/HouseholderReflections/CanonTransform.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/HouseholderReflections/CanonTransform.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/HouseholderReflections/CanonTransform.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.9396551724, "max_line_length": 222, "alphanum_fraction": 0.6860226105, "num_tokens": 6273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.867035752930664, "lm_q2_score": 0.8947894534772125, "lm_q1q2_score": 0.7758144475100324}}
{"text": "\\section{Gaussians}\n\\smallskip \\hrule height 2pt \\smallskip\n\nProperties of Gaussians: \n\\begin{itemize} \n\t\\item Affine transformation (multiplying by a scalar and adding a constant) are Gaussian.\n\t\tIf X $\\sim$ N($\\mu$,$\\sigma^2$) and Y = aX + b, then Y $\\sim$ N($a\\mu+b, a^2\\sigma^2$) \n  \t\\item Sum of Gaussians is Gaussian.  \n\t\t\tIf X $\\sim$ N($\\mu_X, \\sigma^2_X$), \n\t\t\tY $\\sim$ N($\\mu_Y, \\sigma^2_Y$), \n\t\t\tand Z = X+Y, then \n\t\t\tZ $\\sim$ N($\\mu_X+\\mu_Y, \\sigma_X^2 +\\sigma_Y^2$)\n\t\\item  Easy to differentiate.\n\\end{itemize}\n\nLearn a Gaussian: $P(x | \\mu, \\sigma) = \\frac{1}{\\sigma \\sqrt{2 \\pi}}e^\\frac{-(x-\\mu)^2}{2\\sigma^2}$. \\hfill \\\\\nMLE for Gaussian: Prob of i.i.d. samples D = $\\{x_1, \\dots, x_N\\}$:  \\hfill \\\\\n$\\displaystyle  P(D|\\mu, \\sigma) = ( \\frac{1}{\\sigma \\sqrt{2 \\pi}})^N \\prod_{i=1}^N e^\\frac{-(x_i-\\mu)^2}{2\\sigma^2}$.   \\hfill \\\\\nNote: it is \\underline{not} $P(\\mu, \\sigma | D)$, like I thought in class.  \\hfill \\\\\nFind $\\mu_{MLE}$, $\\sigma_{MLE} = \\argmax_{\\mu, \\sigma} P(D | \\mu, \\sigma)$.  \\hfill \\\\\n\nLog-likelihood:  $ \\displaystyle \\ln P(D | \\mu, \\sigma) = \\ln[\\mbox{thing above}] = -N \\ln \\sigma \\sqrt{2\\pi} - \\sum_{i=1}^N \\frac{(x_i - \\mu)^2}{2\\sigma^2}$.  \\hfill \\\\\nDifferentiate w.r.t. $\\mu$ and set = 0.  End up with $ \\displaystyle \\widehat{\\mu} = \\frac{1}{N} \\sum_{i=1}^N x_i$.  \\hfill \\\\\nDifferentiate w.r.t. $\\sigma$ and set = 0.  End up with $ \\displaystyle \\widehat{\\sigma}^2_{MLE} = \\frac{1}{N} \\sum_{i=1}^N (x_i-\\widehat{\\mu})^2$.  \\hfill \\\\\nBut actually, that leads to a biased estimate, so people actually use  $ \\displaystyle \\widehat{\\sigma}^2_{unbiased} = \\frac{1}{N-1} \\sum_{i=1}^N (x_i-\\widehat{\\mu})^2$  \\hfill \\\\\n\nThe conjugate priors: mean: use Gaussian prior:  $ \\displaystyle  P(\\mu | \\nu, \\lambda) = \\frac{1}{\\lambda \\sqrt{2 \\pi}}e^\\frac{-(\\mu - \\nu)^2}{2\\sigma^2} $.  (Instead of $\\sigma$, use $\\lambda$ and replace the $(x-\\mu)^2$ with $(\\mu - \\nu)^2$).  \\hfill \\\\\nFor variance: use Wishard Distribution:  ", "meta": {"hexsha": "bdfbc566fac9ba50f1715a1399dea78c87398527", "size": 1956, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/gaussians.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/gaussians.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/gaussians.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": 69.8571428571, "max_line_length": 256, "alphanum_fraction": 0.6053169734, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8479677602988602, "lm_q1q2_score": 0.7758065156682463}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  For each of the following subspaces of $\\R^4$, find a basis and\n  determine the dimension.\n  \\begin{enumerate}\n  \\item $V_1 = \\sspan\\set{\n      \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ -1 \\\\ -1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 5 \\\\ 2 \\\\ 3 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ -2 \\\\ -2 \\end{mymatrix}\n    }$.\n  \\item $V_2 = \\sspan\\set{\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ -2 \\\\ 2 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 5 \\\\ -5 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 2 \\\\ -2 \\end{mymatrix}\n    }$.\n  \\item $V_3 = \\sspan\\set{\n      \\begin{mymatrix}{r} -2 \\\\ 1 \\\\ 1 \\\\ -3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -9 \\\\ 4 \\\\ 3 \\\\ -9 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -33 \\\\ 15 \\\\ 12 \\\\ -36 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -22 \\\\ 10 \\\\ 8 \\\\ -24 \\end{mymatrix}\n    }$.\n  \\item $V_4 = \\sspan\\set{\n      \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ -1 \\\\ -2 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -4 \\\\ 3 \\\\ -2 \\\\ -4 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -3 \\\\ 2 \\\\ -1 \\\\ -2 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ -2 \\\\ -4 \\end{mymatrix},~\n      \\begin{mymatrix}{r} -7 \\\\ 5 \\\\ -3 \\\\ -6 \\end{mymatrix}\n    }$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Find a basis and the dimension of each of the following subspaces of\n  $\\R^n$.\n  \\begin{enumerate}\n  \\item $S_1 =\n    \\set{\\left.\\begin{mymatrix}{c}\n          4u+v-5w \\\\\n          12u+6v-6w \\\\\n          4u+4v+4w\n        \\end{mymatrix} ~\\right\\vert~u,v,w\\in \\R}.$\n  \\item $S_2 =\n    \\set{\\left.\\begin{mymatrix}{c}\n          2u+6v+7w \\\\\n          -3u-9v-12w \\\\\n          2u+6v+6w \\\\\n          u+3v+3w\n        \\end{mymatrix} ~\\right\\vert~u,v,w\\in \\R}.$\n  \\item $S_3 =\n    \\set{\\left.\\begin{mymatrix}{c}\n          2u+v \\\\\n          6v-3u+3w \\\\\n          3v-6u+3w\n        \\end{mymatrix} ~\\right\\vert~u,v,w\\in \\R}.$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find a basis and the dimension of each of the following subspaces of\n  $\\R^n$.\n  \\begin{enumerate}\n  \\item $W_1 =\n    \\set{\\left.\\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      \\mbox{$u+v=0$ and $u-2w=0$}}.$\n  \\item $W_2 =\n    \\set{\\left.\\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      \\mbox{$u+v+w=0$}}.$\n  \\item $S =\n    \\set{\\left.\\begin{mymatrix}{c} u \\\\ v \\\\ w \\\\ x \\end{mymatrix}\n        ~\\right\\vert~\n      \\mbox{$u+v=w+x$ and $u+w=v+x$}}.$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the vector $\\vect{v}$ that has coordinates\n  \\begin{equation*}\n    \\coord{\\vect{v}}_B = \\begin{mymatrix}{r} 2 \\\\ 1 \\\\ -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} 2 \\\\ 4 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 0 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} -1 \\\\ 0 \\\\ 3\\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Find the coordinates of each of $\\vect{v}$, $\\vect{w}$ with respect\n  to the basis $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$, where\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} 4 \\\\ 3 \\\\ 8 \\end{mymatrix},\\quad\n    \\vect{w} = \\begin{mymatrix}{r} -1 \\\\ -1 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Extend $\\set{\\vect{u}_1,\\vect{u}_2}$ to a basis of $\\R^3$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 3 \\\\ 3 \\\\ -6 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    V ~=~ \\set{\\left.\n        \\begin{mymatrix}{c} x \\\\ y \\\\ z \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      x+y+z+2w = 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 \\\\ 0 \\\\ -1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{c} -2 \\\\ -2 \\\\ -2 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Is $\\set{\\vect{u}_1,\\vect{u}_2}$ a basis of $V$? If not, extend it\n  to a basis of $V$ by adding additional basis vectors.\n\\end{ex}\n\n\\begin{ex}\n  Shrink $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3,\\vect{u}_4}$ to a\n  basis of $\\R^4$ by removing redundant vectors, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 2 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 2 \\end{mymatrix}.\n    \\vect{u}_3 = \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 8 \\end{mymatrix},\\quad\n    \\vect{u}_4 = \\begin{mymatrix}{r} -7 \\\\ 2 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Use one of the basis tests of\n  Proposition~\\ref{prop:basis-test-k-vectors} to determine whether the\n  vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 4 \\\\ -2 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -2 \\\\ 4 \\\\ 1 \\end{mymatrix},\\quad\n    \\mbox{and}\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 1 \\\\ -2 \\\\ 4 \\end{mymatrix}\n  \\end{equation*}\n  form a basis of\\/ $\\R^3$.\n\\end{ex}\n\n\\begin{ex}\n  Use one of the basis tests of\n  Proposition~\\ref{prop:basis-test-k-vectors} to determine whether the\n  vectors\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ -1 \\\\ -1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} -1 \\\\ 2 \\\\ -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{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_5$ of integers\n  modulo $5$ instead of real numbers (see Section~\\ref{sec:fields},\n  ``Fields'').  Find a basis and the dimension of each of the\n  following subspaces of $(\\Z_5)^n$.\n  \\begin{enumerate}\n  \\item $V_1 = \\sspan\\set{\n      \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 1 \\\\ 4 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 4 \\\\ 3 \\\\ 2 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 4 \\\\ 1 \\\\ 2 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    }$.\n  \\item $V_2 =\n    \\set{\\left.\\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      \\mbox{$2u+v=0$ and $u+4w=0$}}.$\n  \\item $V_3 =\n    \\set{\\left.\\begin{mymatrix}{c} u \\\\ v \\\\ w \\end{mymatrix}\n        ~\\right\\vert~\n      \\mbox{$u+2v+3w=0$}}.$\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Basis $\\set{\\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 1 \\\\ 4 \\end{mymatrix},\n      \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ 1 \\\\ 0 \\end{mymatrix}}$, dimension 2.\n    \\item Basis $\\set{\\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 1 \\end{mymatrix}}$,\n      dimension 1.\n    \\item Basis $\\set{\\begin{mymatrix}{r} 2 \\\\ 0 \\\\ 1 \\end{mymatrix},\n      \\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 0 \\end{mymatrix}}$,\n      dimension 2.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_7$ of integers\n  modulo $7$ instead of real numbers.\n  Find the coordinates of $\\vect{v}$ with respect\n  to the basis $B=\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ in $(\\Z_7)^3$, where\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} 3 \\\\ 1 \\\\ 4 \\end{mymatrix},\\quad\n    \\vect{u}_1 = \\begin{mymatrix}{r} 2 \\\\ 4 \\\\ 2 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 1 \\\\ 3 \\\\ 3 \\end{mymatrix},\\quad\n    \\vect{u}_3 = \\begin{mymatrix}{r} 4 \\\\ 1 \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  In this exercise, we use scalars from the field $\\Z_2$ of integers\n  modulo $2$ instead of real numbers.\n  Extend $\\set{\\vect{u}_1,\\vect{u}_2}$ to a basis of $(\\Z_2)^4$, where\n  \\begin{equation*}\n    \\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\\\ 1 \\\\ 1 \\end{mymatrix},\\quad\n    \\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\\\ 1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  True or false? Explain.\n  \\begin{enumerate}\n  \\item Every set of $5$ vectors in $\\R^5$ is linearly independent.\n  \\item Every set of $4$ vectors in $\\R^5$ is linearly independent.\n  \\item Every set of $6$ vectors in $\\R^5$ is linearly dependent.\n  \\item No set of $4$ vectors spans $\\R^5$.\n  \\item Every linearly independent set of $5$ vectors in $\\R^5$ is a\n    basis of $\\R^5$.\n  \\item Every linearly independent set of $4$ vectors in $\\R^5$ is a\n    basis of $\\R^5$.\n  \\item Some linearly independent set of $4$ vectors in $\\R^5$ is a\n    basis of $\\R^5$.\n  \\item Every spanning set of $6$ vectors in $\\R^5$ is a basis of\n    $\\R^5$.\n  \\item Every linearly independent set of $4$ vectors in $\\R^5$ spans\n    a $4$-dimensional subspace of $\\R^5$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item No. For example, the vectors\n      $\\set{\\vect{0},\\vect{0},\\vect{0},\\vect{0},\\vect{0}}$ are\n      linearly dependent.\n    \\item No. For example, the vectors\n      $\\set{\\vect{0},\\vect{0},\\vect{0},\\vect{0}}$ are linearly\n      dependent.\n    \\item Yes, by Proposition~\\ref{prop:size-linearly-independent-or-spanning}.\n    \\item Correct, by Proposition~\\ref{prop:size-linearly-independent-or-spanning}.\n    \\item Yes, by Proposition~\\ref{prop:basis-test-k-vectors}.\n    \\item No, in fact no such set is a basis of $\\R^5$, since every\n      basis of $\\R^5$ consists of $5$ vectors by\n      Theorem~\\ref{thm:bases-same-size}.\n    \\item No, as noted in the previous answer.\n    \\item No, no basis of $\\R^5$ can have $6$ elements.\n    \\item Yes, because a linearly independent set of vectors is a\n      basis of the subspace it spans.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  If you have $6$ vectors in $\\R^5$, is it possible they are\n  linearly independent? Explain.\n  \\begin{sol}\n    No. As a $5$-dimensional space, $\\R^5$ is spanned by $5$\n    vectors. By the Exchange Lemma, any linearly independent set can\n    have size at most $5$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $V$ and $W$ both have dimension equal to $7$ and they are\n  subspaces of $\\R^{10}$. What are the possibilities for the dimension\n  of $V\\cap W$? \\textbf{Hint:} Remember that a linear independent set can be\n  extended to form a basis.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\void{\n  %% Something is wrong with this problem. Whoever wrote the solution\n  %% did not prove that the $p+q-k$ vectors are in fact linearly\n  %% independent. This is required to conclude $p+q-k \\neq n$.\n  \\begin{ex}\n    Suppose $V$ has dimension $p$ and $W$ has dimension $q$ and they\n    are each contained in a subspace, $U$ which has dimension equal to $n$ where\n    $n>\\max (p,q)$. What are the possibilities for the dimension of\n    $V\\cap W$? \\textbf{Hint:} Remember that a linearly independent set can be\n    extended to form a basis.\n    \\begin{sol}\n      Let $\\set{x_1,\\ldots,x_k}$ be a\n      basis for $V\\cap W$. Then there are bases for $V$ and $W$ which are\n      respectively\n      \\begin{equation*}\n        \\set{x_1,\\ldots,x_k,y_{k+1},\\ldots,y_p},\\ \\set{\n          x_1,\\ldots,x_k,z_{k+1},\\ldots,z_q}.\n      \\end{equation*}\n      None of the $y_i$ are in $W$ (or else they would be in\n      $V\\cap W$, and therefore a linear combination of\n      $x_1,\\ldots,x_k$). Similarly, none of the $z_j$ are in\n      $V$. It follows that $k+p-k+q-k\\leq n$, and so\n      \\begin{equation*}\n        p+q-n\\leq k\n      \\end{equation*}\n    \\end{sol}\n  \\end{ex}\n}\n", "meta": {"hexsha": "34246256f75d1c2aab2d23832e37bfe25d05791c", "size": 11511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/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/exercises/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/exercises/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": 36.1981132075, "max_line_length": 83, "alphanum_fraction": 0.5798801147, "num_tokens": 4638, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900950352329, "lm_q2_score": 0.8479677660619634, "lm_q1q2_score": 0.7758065150382317}}
{"text": "\\section{Phase space, Hamiltonian dynamics, and the fundamental postulate of statistical mechanics}\n\n\n\\subsection{Phase space}\n\nAt a microscopic level, a thermodynamic system is comprised of $N$ particles, each with some mass $m_i$, which can interact with each other and with the boundaries of the system. (Although we are going to motivate this discussion with a thermodynamic system, everything the follows is also true for other systems where the total energy of the system is conserved --- i.e. anywhere that a Hamiltonian could show up.) If we know the positions and momenta  for each of the particles then we can completely describe the state of the system. In three dimensions, this means we must know the values for each of the $6N$ degrees of freedom (3 for position and 3 for momentum); more generally, we have $2d$ d.o.f. where $d$ is the number of d.o.f. for the positions. That is the state of the system is described by a point in a $6N$ (or $2d$) dimensional phase space.\nOnce a point in the microscopic phase space is know, the evolution of the system is completely governed by the equations of motion for the system. These in turn are prescribed by the Hamiltonian of the system\n\n$$H = T+U = H({\\bf r}, {\\bf v}) = H({\\bf q}, {\\bf p}),$$\n$T=$ kinetic energy, $U=$ potential energy. In general, $H$, $T$, and $U$ may all depend on both the positions and the momenta of the particles, however, for many systems we find that, conveniently, $T = \\sum_{i=1}^{N} T_i$, where $T_i=\\frac{{\\bf p}_i^2}{2m_i}$, and the potential $U$ depends only on the positions: $U = U({\\bf q}).$\n\nIf the Hamiltonian is known for a system, then the equations of motion for that system are given by the \\textit{Hamiltonian equations of motion}:\n\\begin{eqnarray*}\n\t\\frac{d{\\bf q}_i}{dt} &=& ~~\\frac{\\partial H}{\\partial {\\bf p_i}}, \\\\\n\t\\frac{d{\\bf p}_i}{dt} &=& -\\frac{\\partial H}{\\partial {\\bf q_i}}.\n\\end{eqnarray*}\n\nIf we write ${\\bf x} = [{\\bf q}^\\top,{\\bf p}^\\top]^\\top$, then we can compactly express the equations of motion as\n\n\\begin{equation}\n\t\\frac{d{\\bf x}}{dt} = f({\\bf x}) = J^{-1}\\nabla H({\\bf x}),\n\\end{equation}\nwhere\n$$\n\tJ = \n\t\\begin{bmatrix}\n\t\t0 & -Id\\\\\n\t\tId & 0\n\t\\end{bmatrix}.\n$$\n($Id$ is the identity matrix of dimension $d$.)\n\nGiven a Hamiltonian, H, and a suitable set of initial conditions ${\\bf x}_0$, the evolution of the solution ${\\bf x}(t)$ can be quite complicated (Hamiltonian systems are one of the archetypal systems for studying chaotic dynamics). However, the fact that the system is Hamiltonian provides us with some additional information that can help us characterise the state of the system. For example, it is not hard to prove that a solution ${\\bf x}(t)$ that satisfies $\\dot{\\bf x} = f({\\bf x}) = J^{-1}\\nabla H({\\bf x}),$ ${\\bf x}_0 = {\\bf x}(0)$ has $H({\\bf x}(t)) = H({\\bf x}_0)= const.$ That is, Hamiltonian systems conserve energy along their solutions. We identify the Hamiltonian $H$ with the internal energy of the system.\n\nKnowing that $\\frac{dH}{dt}=0$, we can reduce the size of the phase space where ${\\bf x}(t)$ can lie, from $2d$ d.o.f. down to $2d-1$. If we know other quantities that remain invariant over time (e.g. the total momentum of the system) then we can further reduce the size of the phase space. Strictly speaking, there are $2d-1$ invariants (AKA first integrals or constants of motion) for a Hamiltonian system. This defines a curve in the remaining 1 d.o.f. along which the solution must lie (that is, a line in the phase space). This can be seen as a consequence of the uniqueness theorem for differential equations (think back to the 2nd year maths course on D.E.s). In reality, we typically can't find a closed form expression for most of these conserved quantities and have no idea what they might be.\n\nIt is possible that a (vanishingly) small change in the positions of the particles in phase space can lead to a large change in the state of the system and in the subsequent trajectories of the particles.\nThis is similar to saying that the dynamics of a Hamiltonian system can switch abruptly from regular to chaotic motion, as some parameter of the system is varied. \nSuch quantities are not helpful in characterising the thermodynamics of the system.\nIn statistical mechanics, we are interested in the invariant quantities that only change by a little when there is a small change in the microscopic variables of the system. \nE.g. ${\\bf x}\\rightarrow {\\bf x}+\\delta {\\bf x} \\implies H\\rightarrow H+\\delta H$.\n\nOne way to phrase this is to say that we want to consider systems where the region in phase space where the system is evolving can be (almost) completely identified, for thermodynamic purposes, by the values of a (not too large) number of observable invariant quantities.\n\n\\subsection{Observables}\nIn statistical mechanics, we say that an observable is a function defined on the phase space of the system that varies smoothly with changes in the representative point of the system. This definition is different to the definition in quantum mechanics.\n\nThe kinetic energy $\\sum_i \\frac{p_i}{2m_i}$ is an observable, while the function $\\Theta = \\prod_i \\theta(r_0^2-r_i^2)$, where $\\theta(x)$ is the Heaviside function, is not, since an arbitrarily small change in a position $r_i$ can lead to a finite change in $\\Theta$. This behaviour is not smooth which means $\\Theta$ is not an observable. This non-smoothness results from the presence of the Heaviside function (also known as the unit step function), which is equal to zero when its argument is negative and one when it is positive; this function has a jump when the argument is zero and is thus obviously not smooth.\n\nOther examples of (thermodynamic) observables include the internal energy $E$ (i.e. the Hamiltonian) and the number of particles in the system ($N = \\int d{\\bf r}\\sum\\delta({\\bf r}-{\\bf r}_i)$).\nIt turns out that the entropy $S=S(X_0=E=H,X_1,\\ldots,X_r)$ is also an observable. However, we don't yet have a way to express the entropy --- the extensive variable of a thermodynamic system --- as a function of the microscopic state of the system and its equations of motion. To do so, we are going to invoke the fundamental postulate of statistical mechanics.\n\n\\subsection{The fundamental postulate of statistical mechanics}\nThe fundamental postulate expresses the entropy $S$ as a function of the accessible volume of the phase space of a dynamical system. I.e. that part of the phase space where the observables have values that are compatible with a specific thermodynamic state.\n\nAssume that the thermodynamic state of a system is determined by the extensive variables $X_1,\\ldots,X_r$ and that each of the $X_i$ can be expressed as a function over the microscopic phase space; I.e. $X_i = X_i({\\bf x})$.\nThe region of phase space that is accessible is defined by the value of $X = (X_1,\\ldots,X_r)$. Well, almost; we actually also allow for small discrepancies $\\epsilon_i,~~i=1,\\ldots,r$ to account for the effect of any non-extensive terms.\n\nWe denote the region of phase space in which the observable $X_i$ have the specific values that match the thermodynamic state as $\\Gamma$ and we denote the corresponding phase space volume $\\text{vol}(\\Gamma)=\\Omega$. Then the fundamental postulate of thermodynamics states that\n\\begin{equation}\n\tS = k_B\\ln(\\Omega),\n\t\\label{eqS}\n\\end{equation}\nwhere $S$ is the thermodynamic entropy, $k_B$ is Boltzmann's constant ($k_B = 1.384\\times10^{-23}$J/K) and the equality should be interpreted as meaning ``is equal, up to terms of size $\\epsilon_i$''. The accessible phase space volume $\\Omega$ measures the amount of the phase space available to the microscopic system while it is in this macroscopic state. If the system had only discrete micro-states, then we could simply count the number of micro-states that correspond to the same macro-state. \n\n\n\\subsection{Symplectic transformations and phase space area preservation}\nWhy is phase space so important in the formulation of entropy? To understand this we are going to look closer at some of the properties that being Hamiltonian impose on a system, including the choice of coordinate system.\n\nWe saw earlier that the equations of motion for a time-independent Hamiltonian system can be written as$ \\frac{d{\\bf x}}{dt} = f({\\bf x}) = J^{-1}\\nabla H({\\bf x})$. This Hamiltonian form is not preserved by arbitrary coordinate transformations; it \\emph{is} preserved by \\emph{symplectic} transformations.\n\n{\\bf Definition:} A linear transformation $A: \\mathbb{R}^{2d}\\rightarrow\\mathbb{R}^{2d}$ is said to be symplectic if it satisfies\n$$ A^\\top J A = J.$$\nFor a non-linear transformation $\\mathcal{A}$, we replace $A$ above with its jacobian $D\\mathcal{A}$.\n\nAn alternative, but equivalent, definition of a symplectic transformation --- and one that will turn out to be useful in a bit --- borrows some tools from differential geometry. (No prior experience with differential geometry is assumed.)\n\n{\\bf Definitions:} A symplectic transformation is a diffeomorphism (a smooth, invertible mapping between manifolds) $f:\\mathbb{R}^{2d}\\rightarrow\\mathbb{R}^{2d}$, with coordinates $q$ and $p$, which preserves the symplectic two-form $\\omega$ (an anti-symmetric, bilinear form) that acts on pairs of vectors and gives the sum of the oriented areas that they define. In two dimensions, this is the area of the parallelogram spanned by the two vectors.\n\nMore explicitly,\n\\begin{equation*}\n\t\\omega(u,v) = u^\\top Jv = \\sum_{i=1}^d u_{p_i} v_{q_i} - u_{q_i} v_{p_i}.\n\\end{equation*}\n\nAt this point it is necessary to introduce a (potentially) new concept --- the flow map of a vector field. The flow $\\varphi_{t,f}({\\bf x})$ of a Hamiltonian system is a function that maps a point ${\\bf x}^*$ in the phase space of the system with equations of motion $\\dot{\\bf x} = f({\\bf x}) =J^{-1}\\nabla H({\\bf x})$ forward by time $t$. I.e. for any $f({\\bf x})$ and ${\\bf x}_0$, $\\varphi_{t,f}({\\bf x}_0)$ gives the solution to $\\dot{\\bf x}=f({\\bf x})$ at time $t$. That is, it shows the time evolution of {\\bf x} and {\\bf p} on the phase space.\n\n{\\bf Theorem:} If the Hamiltonian $H({\\bf x})$ is a twice differentiable function on some neighbourhood of $\\mathbb{R}^{2d}$, then the time-$t$ flow map $\\varphi_{t,f}({\\bf x}_0)$ of the Hamiltonian vector field is a symplectic map for all $t$.\n{\\bf Proof:} We will show that $\\omega(u,v)=u^\\top J v$ is constant along solutions of $\\dot{\\bf x} = J^{-1}\\nabla H({\\bf x})$.\n\nThe tangent vector $u(t) = \\frac{\\partial \\varphi_t}{\\partial {\\bf x}_0}({\\bf x}_0)u(0)$ satisfies $\\frac{du}{dt} = J^{-1}\\nabla^2H({\\bf x}(t))u(t)$ and the tangent vector $v(t)$ satisfies a similar expression. Now we can calculate the time derivative of $\\omega(u,v)$.\n\\begin{eqnarray*}\n\t\\frac{d}{dt}\\omega(u,v) &=& \\dot{u}^{\\top}Jv+u^\\top J\\dot{v}\\\\\n\t\t&=& (J^{-1}\\nabla^2Hu)^\\top Jv + u^\\top JJ^{-1}\\nabla^2Hv\\\\\n\t\t&=& 0\n\\end{eqnarray*}\nsince $J^{-\\top}=(J^{-1})^\\top$, $J^{-\\top}J=-I$ and $JJ^{-1} = I$.\n\nI.e. as the system evolves according to its equations of motion, it always preserves the area for $d=1$, or the sum of the oriented areas for $d \\geq2$.\n\n\n\\subsection{Liouville's theorem and preservation of phase space volume}\nWe are now in a position to prove that the flow of a Hamiltonian system preserves phase space volume. That is, for every bounded, open set $A\\subset\\mathcal{R}^{2d}$ and every $t$ for which $\\varphi_{t,f}({\\bf x})$ exists\n$$\\text{Vol}(\\varphi_{t,f}(\\Gamma))=\\text{Vol}(\\Gamma)$$\nwhere $f=J^{-1}\\nabla H$ and $\\text{Vol}(\\Gamma) = \\int_{\\Gamma}d{\\bf x}$.\n\nTo prove this, we will actually prove a slightly more general case: the flow of a differential equation $\\dot{\\bf x}=f({\\bf x})$ in $\\mathbb{R}^n$ is volume preserving if and only if it is divergence-free; i.e. $\\nabla\\cdot f=0$.\n\nBut first, why do we care about preservation of phase space volume? The fundamental postulate of statistical mechanics, $S=k_B\\ln(\\Omega)$ related the entropy of a system to the volume of the part of the phase space accessible to that system when it is in that particular thermodynamic state. We would like to be sure that this quantity doesn't vary too much over time as the microscopic system evolves, according to the Hamiltonian equations of motion. Although the microscopic system might be in continuous motion, the trajectories of the particles it is comprised of are such that the extensive variables which characterise the macroscopic state of the system are (almost) constant. I.e. there is no change in entropy, no heat flow, no work done while the system is at equilibrium. This is reassuring --- it says that disorder doesn't increase unless something happens.\n\n{\\bf Proof: volume preservation:}\nThe Jacobian of the flow map $\\varphi_{t,f}({\\bf x}_0)$ defines the matrix function $X(t)=D\\varphi_{t,f}({\\bf x}_0)$. The volume of the shape spanned by the columns of $X$ is given by $\\det(X)$, and $X(t)$ is a solution of the equation\n$$\n\\dot{X}=A(t)X(t),\\qquad X(0)=I,\n$$\nwhere $A(t):=Df({\\bf x}(t))$ denotes the Jacobian of $f({\\bf x}(t))$ evaluated at ${\\bf x}(t)=\\varphi_{t,f}({\\bf x}_0)$. To show that the volume defined by $X$ is constant we use the Abel-Liouville-Jacobi-Ostrogradskii identity to find the time derivative of $\\det X$:\n$$\n\\frac{d}{dt}\\det X(t)=\\text{trace} A(t)\\cdot\\det X(t).\n$$\nSince $A(t)=Df({\\bf x}(t))$ we have $\\text{trace} A(t)=\\sum_i\\frac{\\partial f_i}{\\partial {\\bf x}_i}({\\bf x}(t))=\\nabla\\cdot f({\\bf x}(t))$ and therefore $\\det X(t)=\\det X(0)=1$ if and only if $\\nabla\\cdot f({\\bf x})=0.$\n\n\\subsection{Recommended reading}\nThis section has mostly followed the first half of chapter 3 of \\emph{Statistical Mechanics in a Nutshell}. However, some of the significance of Hamiltonian systems is lost in SMiaN, so I've supplemented it with more substantive (mathematically oriented) details from \\emph{Geometric Numerical Integration} by E. Hairer, Ch. Lubich and G. Wanner (Springer, 2006) --- one of the best books on (the numerics of) Hamiltonian dynamical systems and a personal favourite.\n", "meta": {"hexsha": "fa24dc9aef065176cc5addca76a42f1ef21e02c2", "size": 14005, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05-hamiltonianPhaseSpace.tex", "max_stars_repo_name": "wvan478/708Notes2018", "max_stars_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2018-02-28T20:47:25.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-10T19:05:54.000Z", "max_issues_repo_path": "05-hamiltonianPhaseSpace.tex", "max_issues_repo_name": "wvan478/708Notes2018", "max_issues_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2018-03-07T20:07:07.000Z", "max_issues_repo_issues_event_max_datetime": "2018-04-18T20:53:19.000Z", "max_forks_repo_path": "05-hamiltonianPhaseSpace.tex", "max_forks_repo_name": "wvan478/708Notes2018", "max_forks_repo_head_hexsha": "0a4ef44e261f2892b0e927aeadf7f06adda1b80b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2018-02-26T21:38:05.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-15T22:54:11.000Z", "avg_line_length": 113.8617886179, "max_line_length": 872, "alphanum_fraction": 0.7335237415, "num_tokens": 3846, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009573133051, "lm_q2_score": 0.8479677545357569, "lm_q1q2_score": 0.7758065103955777}}
{"text": "\\subsection{Least Squares Fit}\n\nGiven a discrete set of data points which represent a measured step  response of\nan  unknown system, the input parameters  of  the  function  $G_n(s,r)$  can  be\ntweaked such that the squared error between its step response and the input data\nis minimised. The squared error is computed using:\n\n\\begin{equation}\n    S = \\sum_{i} \\left(g(t_i)-y_i\\right)^2\n\\end{equation}\n\nwhere $g(t)$ is the inverse Laplace transform  of $\\frac{G_n(s,r)}{s}$ (the time\ndomain step response) and ($t_i$,$y_i$) are  data  points  of  the measured step\nresponse.\n\nBy fitting a system $G_n(s,r)$ to  the  input  data,  it  is possible to further\nrefine the results  obtained by the two methods mentioned thus far, or otherwise\nfind  optimal  values  for  $T$  and  $r$ when dealing with  noisy  input  data.\n\nThe possibility of finding local minima exists. It is therefore advised to first\nuse one of the four previous methods to find optimal initial values for $T$, $r$\nand $n$ before performing the fit.\n\nIt will be shown that the  least  squares  fit  approach  will  yield  the  most\naccurate results by orders of magnitude. The downside to this method, of course,\nis the large amount of computation time required.\n", "meta": {"hexsha": "29f6d452d47f437927168980bdd6428b0ec426db", "size": 1230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/mlab/sections/theory/least_squares.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/mlab/sections/theory/least_squares.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/mlab/sections/theory/least_squares.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.5555555556, "max_line_length": 80, "alphanum_fraction": 0.7447154472, "num_tokens": 330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.914900957313305, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7758065103955776}}
{"text": "\n\\subsection{Simultaneous games}\n\n\\subsubsection{One round simultaneous games}\n\nEconomic agents face options from some set. This could be consumption choices, numbers of hours to work, or how much capital to invest in at a factory.\n\nConsider the prisoner’s dilemma game:\n\ttable.table.table-bordered\n\t\tthead\n\t\t\ttr\n\t\t\t\tth \n\t\t\t\tth Silent\n\t\t\t\tth Tell\n\t\ttbody\n\t\t\ttr\n\t\t\t\ttd Silent\n\t\t\t\ttd (5,5)\n\t\t\t\ttd (10,0)\n\t\t\ttr\n\t\t\t\ttd Tell\n\t\t\t\ttd (0,10)\n\t\t\t\ttd (8,8)\n\nIn this game we have two agents who simultaneously choose \n\nLet’s compare the decision to “tell” to the decision to be “silent”. \n\nNo matter what the other agent does, you are always better off choosing “tell”. As a result we say the strategy “tell” strictly dominates “silent”.\n\nIf under some circumstances the agent is indifferent to the strategy and another, then the strategy only weakly dominates.\n\nSo one way to solve a game is to choose dominating strategies. However an agent may not have strictly dominating strategies. Another method it to rule out strategies. If one strategy is strictly dominated for an agent, we can rule out them choosing it. This may reveal strategies which are dominant one actions of another agent can be ruled out.\n\nIf after iterations of this process we are left with only one strategy for each agent, we say this is a Von Neumann solution, an analytic solution. \n\nBut what if there are still multiple options? Consider\n\n\ttable.table.table-bordered\n\t\tthead\n\t\t\ttr\n\t\t\t\tth \n\t\t\t\tth Opera\n\t\t\t\tth Tell\n\t\ttbody\n\t\t\ttr\n\t\t\t\ttd Opera\n\t\t\t\ttd (10,5)\n\t\t\t\ttd (0,0)\n\t\t\ttr\n\t\t\t\ttd Football\n\t\t\t\ttd (0,0)\n\t\t\t\ttd (5,10)\n\nAnd\n\n\ttable.table.table-bordered\n\t\tthead\n\t\t\ttr\n\t\t\t\tth \n\t\t\t\tth Rock\n\t\t\t\tth Paper\n\t\t\t\tth Scissors\n\t\ttbody\n\t\t\ttr\n\t\t\t\ttd Rock\n\t\t\t\ttd (0,0)\n\t\t\t\ttd (-1,1)\n\t\t\t\ttd (1,-1)\n\t\t\ttr\n\t\t\t\ttd Paper\n\t\t\t\ttd (1,-1)\n\t\t\t\ttd (0,0)\n\t\t\t\ttd (-1,1)\n\t\t\ttr\n\t\t\t\ttd Scissors\n\t\t\t\ttd (-1,1)\n\t\t\t\ttd (1,-1)\n\t\t\t\ttd (0,0)\n\nIn both of these there is no strategy which is always better to follow, even weakly. But these games are very different. In the former, if agents agree to both got to football, or both to opera, neither would be better off by defecting. In the second example there is no such “Nash equilibrium”.\n\nThis is relevant for considering how to expand the game. In the former example a couple can talk to each other and coordinate actions.  For example one agent could commit to going to the football, and the other agent would rationally join.\n\nIn the latter no such coordination is beneficial.\n\nIn the context of the game, the player can instead of choosing a pure strategy such as “rock”, which may not always be appropriate, choose a mixed strategy.\n\nFor example a player could choose each of the \\(3\\) moves \\(\\dfrac{1}{3}\\) of the time.\n\n\n\\subsubsection{Nash equilibrium}\n\n\n\\subsubsection{Minimax strategy}\n\n\\subsubsection{Pure/mixed strategy}\n\n", "meta": {"hexsha": "9d96c82de6f685490bba9ef6802eb89e5ab827b9", "size": 2814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/gameTheory/03-01-gameSimultaneous.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/ai/gameTheory/03-01-gameSimultaneous.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/ai/gameTheory/03-01-gameSimultaneous.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.4242424242, "max_line_length": 345, "alphanum_fraction": 0.7153518124, "num_tokens": 714, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8807970748488297, "lm_q1q2_score": 0.7758034843061944}}
{"text": "\\documentclass[../../question_3_array_question.tex]{subfiles}\n\\begin{document}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%% Subset\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Subset(Combination and Permutation)}\n\\label{part4_array_subset}\nThe Subset B of a set A is defined as a set within all elements of this subset are from set A. In other words, the subset B is contained inside the set A, $B \\in A$. There are two kinds of subsets: if the order of the subset doesnt matter, it is a combination problem, otherwise, it is a permutation problem. To solve the problems in this section, we need to refer to the backtracking in Sec~\\ref{sec_combination}. When the subset has a fixed constant length, then hashmap can be used to lower the complexity by one power of n.\n\n\\textbf{Subset VS Subsequence}. In the subsequence, the elements keep the original order from the original sequence. While, in the set concept, there is no ordering, only a set of elements. \n\nIn this type of questions, we are asked to return subsets of a list. For this type of questions, backtracking~\\ref{sec:backtrack} can be applied. \n\\subsection{Combination}\n\\label{part4_array_combine}\nThe solution of this section is heavily correlated to Section~\\ref{sec_combination}. \n78. Subsets\n\\begin{lstlisting}\nGiven a set of distinct integers, nums, return all possible subsets (the power set).\n\nNote: The solution set must not contain duplicate subsets.\n\nExample:\n\nInput: nums = [1,2,3]\nOutput:\n[\n  [3],\n  [1],\n  [2],\n  [1,2,3],\n  [1,3],\n  [2,3],\n  [1,2],\n  []\n]\n\\end{lstlisting}\n\\textbf{Backtracking}. This is a combination problem, which we have explained in backtrack section. We just directly gave the code here. \n\\begin{lstlisting}[language = Python]\ndef subsets(self, nums):\n    res, n = [], len(nums)\n    res = self.combine(nums, n, n)\n    return res\n\ndef combine(self, nums, n, k):\n    \"\"\"\n    :type n: int\n    :type k: int\n    :rtype: List[List[int]]\n    \"\"\"\n    def C_n_k(d, k, s, curr, ans): #d controls the degree (depth), k is controls the return level, curr saves the current result, ans is all the result\n        ans.append(curr)\n        if d == k: #the length is satisfied\n\n            return\n        for i in range(s, n):\n            curr.append(nums[i])\n            C_n_k(d+1, k, i+1, curr[:], ans) # i+1 because no repeat, make sure use deep copy curr[:]\n            curr.pop()\n\n    ans = []    \n    C_n_k(0, k, 0, [], ans) \n    return ans\n\\end{lstlisting}\n\\textbf{Incremental}. Backtracking is not the only way for the above problem. There is another way to do it iterative, observe the following process. We can just keep append elements to the end of of previous results. \n\\begin{lstlisting}\n[1, 2, 3, 4]\nl = 0, []\nl = 1, for 1, []+[1], -> [1],  get powerset of [1]\nl = 2, for 2, []+[2], [1]+[2], -> [2], [1, 2], get powerset of [1, 2]\nl = 3, for 3, []+[3], [1]+[3], [2]+[3], [1, 2]+[3], -> [3], [1, 3], [2, 3], [1, 2, 3], get powerset of [1, 2, 3]\nl = 4, for 4, []+ [4]; [1]+[4]; [2]+[4], [1, 2] +[4]; [3]+[4], [1,3]+[4],[2,3]+[4], [1,2,3]+[4], get powerset of [1, 2, 3, 4]\n\\end{lstlisting}\n\\begin{lstlisting}[language=Python]\ndef subsets(self, nums):\n    result = [[]] #use two dimensional, which already have [] one element\n    for num in nums:\n        new_results = []\n        for r in result:\n            new_results.append(r + [num])\n        result += new_results\n        \n    return result\n\\end{lstlisting}\n90. Subsets II\n\\begin{lstlisting}\nGiven a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).\n\nNote: The solution set must not contain duplicate subsets.\n\nExample:\n\nInput: [1,2,2]\nOutput:\n[\n  [2],\n  [1],\n  [1,2,2],\n  [2,2],\n  [1,2],\n  []\n]\n\\end{lstlisting}\nAnalysis: Because of the duplicates, the previous superset algorithm would give repetitive subset. For the above example, we would have [1, 2] twice, and [2] twice.  If we try to modify on the previous code. We first need to sort the nums, which makes the way we check repeat easiler. Then the code goes like this:\n\\begin{lstlisting}[language = Python]\n    def subsetsWithDup(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: List[List[int]]\n        \"\"\"\n        nums.sort()\n        result = [[]] #use two dimensional, which already have [] one element\n        for num in nums:\n            new_results = []\n            for r in result:\n                print(r)\n                new_results.append(r + [num])\n            for rst in new_results:\n                if rst not in result: # check the repetitive\n                    result.append(rst)\n            \n        return result\n\\end{lstlisting}\nHowever, the above code is extremely inefficient because of the checking process. A better way to do this:\n\\begin{lstlisting}\n[1, 2, 2]\nl = 0, []\nl = 1, for 1, []+[1]\nl = 2, for 2, []+[2], [1]+[2]; []+[2, 2], [1]+[2, 2]\n\\end{lstlisting}\nSo it would be more efficient if we first save all the numbers in the array in a dictionary. For the above case, the dic = {1:1, 2:2}. Each time we try to generate the result, we use 2 up to 2 times. Same way, we can use dictionary on the backtracking too. \n\\begin{lstlisting}[language=Python]\nclass Solution(object):\n    def subsetsWithDup(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: List[List[int]]\n        \"\"\"\n        if not nums:\n            return [[]]\n        res = [[]]\n        dic = collections.Counter(nums)\n        for key, val in dic.items():\n            tmp = []\n            for lst in res:\n                for i in range(1, val+1):\n                    tmp.append(lst+[key]*i)\n            res += tmp\n        return res\n\\end{lstlisting}\n\n77. Combinations\n\\begin{lstlisting}\nGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.\n\nExample:\n\nInput: n = 4, k = 2\nOutput:\n[\n  [2,4],\n  [3,4],\n  [2,3],\n  [1,2],\n  [1,3],\n  [1,4],\n]\n\\end{lstlisting}\nAnalysis: In this problem, it is difficult for us to generate the results iteratively, the only way we can use the second solution is by filtering and get only the results with the length we want. However, the backtrack can solve the problem easily as we mentioned in Section~\\ref{sec_combination}.\n\\begin{lstlisting}[language=Python]\ndef combine(self, n, k):\n    \"\"\"\n    :type n: int\n    :type k: int\n    :rtype: List[List[int]]\n    \"\"\"\n    ans = []\n    def C_n_k(d,k,s,curr):\n        if d==k:\n            ans.append(curr)\n            return\n        for i in range(s, n):\n            #curr.append(i+1)\n            #C_n_k(d+1, k, i+1, curr[:])\n            #curr.pop()\n            C_n_k(d+1, k, i+1, curr+[i+1])\n    C_n_k(0,k,0,[]) \n\n    return ans\n\\end{lstlisting}\n%%%%%%%%%%%%%%%%%%%combination sum%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Combination Sum}\n39. Combination Sum\n\nGiven a set of candidate numbers (candidates) \\textbf{(without duplicates)} and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.\n\nThe same repeated number may be chosen from candidates \\textbf{unlimited number} of times.\n\\begin{lstlisting}\nNote:\n\n    All numbers (including target) will be positive integers.\n    The solution set must not contain duplicate combinations.\n\nExample 1:\n\nInput: candidates = [2,3,6,7], target = 7,\nA solution set is:\n[\n  [7],\n  [2,2,3]\n]\n\nExample 2:\n\nInput: candidates = [2,3,5], target = 8,\nA solution set is:\n[\n  [2,2,2,2],\n  [2,3,3],\n  [3,5]\n]\n\\end{lstlisting}\n\\textbf{DFS Backtracking}. Analysis: This is still a typical combination problem, the only thing is the return level is when the sum of the path we gained is larger than the target, and we only collect the answer when it is equal. And Because a number can be used unlimited times, so that each time after we used one number, we do not increase the next start position. \n\\begin{lstlisting}[language=Python]\ndef combinationSum(self, candidates, target):\n    \"\"\"\n    :type candidates: List[int]\n    :type target: int\n    :rtype: List[List[int]]\n    \"\"\"\n    ans = []\n    candidates.sort()\n    self.combine(candidates, target, 0, [], ans)\n    return ans\n\ndef combine(self, nums, target, s, curr, ans):\n    if target < 0:\n        return  # backtracking\n    if target == 0:\n        ans.append(curr)\n        return \n    for i in range(s, len(nums)):\n        # if nums[i] > target:\n        #     return\n        self.combine(nums, target-nums[i], i, curr+[nums[i]], ans) # use i, instead of i+1 because we can reuse\n\\end{lstlisting}\n40. Combination Sum II\n\nGiven a collection of candidate numbers \\textbf{(candidates with duplicates)} and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.\n\nEach number in candidates may only \\textbf{be used once} in the combination.\n\\begin{lstlisting}\nNote:\n\n    All numbers (including target) will be positive integers.\n    The solution set must not contain duplicate combinations.\n\nExample 1:\n\nInput: candidates = [10,1,2,7,6,1,5], target = 8,\nA solution set is:\n[\n  [1, 7],\n  [1, 2, 5],\n  [2, 6],\n  [1, 1, 6]\n]\n\nExample 2:\n\nInput: candidates = [2,5,2,1,2], target = 5,\nA solution set is:\n[\n  [1,2,2],\n  [5]\n]\n\\end{lstlisting}\n\\textbf{Backtracking+Counter}. Because for the first example, if we reuse the code from the previous problem, we will get extra combinations: [7, 1], [2, 1, 5]. To avoid this, we need a dictionary to save all the unique candidates with its corresponding appearing times. For a certain number, it will be used at most its counter times. \n\\begin{lstlisting}[language=Python]\ndef combinationSum2(self, candidates, target):\n    \"\"\"\n    :type candidates: List[int]\n    :type target: int\n    :rtype: List[List[int]]\n    \"\"\"\n        \n    candidates = collections.Counter(candidates)\n    ans = []\n    self.combine(list(candidates.items()), target, 0, [], ans) # convert the Counter to a list of (key, item) tuple\n    return ans\n    \ndef combine(self, nums, target, s, curr, ans):\n    if target < 0:\n        return \n    if target == 0:\n        ans.append(curr)\n        return\n    for idx in range(s, len(nums)):           \n        num, count = nums[idx]\n        for c in range(count):\n            self.combine(nums, target-num*(c+1), idx+1, curr+[num]*(c+1), ans )\n\\end{lstlisting}\n377. Combination Sum IV (medium)\n\\begin{lstlisting}\n Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.\n\nExample:\n\nnums = [1, 2, 3]\ntarget = 4\n\nThe possible combination ways are:\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\n\nNote that different sequences are counted as different combinations.\n\nTherefore the output is 7.\n\nFollow up:\nWhat if negative numbers are allowed in the given array?\nHow does it change the problem?\nWhat limitation we need to add to the question to allow negative numbers? \n\\end{lstlisting}\n\\textbf{DFS + MEMO}. This problem is similar to 39. Combination Sum. For [2, 3, 5], target = 8,  comparison:\n\\begin{lstlisting}\n[2, 3, 5], target = 8\n39. Combination Sum. # there is ordering (each time the start index is same or larger than before)\n[\n  [2,2,2,2],\n  [2,3,3],\n  [3,5]\n]\n377. Combination Sum IV, here we have no ordering( each time the start index is the same as before). Try all element.\n[\n  [2,2,2,2],\n  [2,3,3],\n* [3,3,2]\n* [3,2,3]\n  [3,5],\n* [5,3]\n]\n\\end{lstlisting}\n\\begin{lstlisting}[language=Python]\ndef combinationSum4(self, nums, target):\n    \"\"\"\n    :type nums: List[int]\n    :type target: int\n    :rtype: int\n    \"\"\"\n    nums.sort()\n    n = len(nums)\n    def DFS(idx, memo, t):\n        if t < 0:\n            return 0\n        if t == 0:\n            return 1\n        count = 0\n        if t not in memo:\n            for i in range(idx, n):\n                count += DFS(idx, memo, t-nums[i])\n            memo[t] = count\n        return memo[t]\n    return(DFS(0, {}, target))\n\\end{lstlisting}\nBecause, here we does not need to numerate all the possible solutions, we can use dynamic programming, which will be shown in Section~\\ref{}. \n\n\\subsection{K Sum}\nIn this subsection, we still trying to get subset that sum up to a target. But the length here is fixed. We would have 2, 3, 4 sums normally. Because it is still a combination problem, we can use the \\textbf{backtracking} to do. Second, because the fixed length, we can use \\textbf{multiple pointers} to build up the potential same lengthed subset.  But in some cases, because the length is fixed, we can use \\textbf{hashmap} to simplify the complexity. \n\n1. Two Sum\nGiven an array of integers, return \\textbf{indices} of the two numbers such that they add up to a specific target.\n\nYou may assume that each input would have \\textbf{exactly} one solution, and you may not use the same element twice.\n\\begin{lstlisting}\nExample:\n\nGiven nums = [2, 7, 11, 15], target = 9,\n\nBecause nums[0] + nums[1] = 2 + 7 = 9,\nreturn [0, 1].\n\\end{lstlisting}\n\\textbf{Hashmap}. Using backtracking or brute force will get us $O(n^2)$ time complexity. We can use hashmap to save the nums in a dictionary. Then we just check target-num in the dictionary. We would get $O(n)$ time complexity. We have two-pass hashmap and one-pass hashmap.\n\\begin{lstlisting}[language=Python]\n# two-pass hashmap\ndef twoSum(self, nums, target):\n    \"\"\"\n    :type nums: List[int]\n    :type target: int\n    :rtype: List[int]\n    \"\"\"\n    dict = collections.defaultdict(int)\n    for i, t in enumerate(nums):\n        dict[t] = i\n    for i, t in enumerate(nums):\n        if target - t in dict and i != dict[target-t]:\n            return [i, dict[target-t]]\n# one-pass hashmap\ndef twoSum(self, nums, target):\n    \"\"\"\n    :type nums: List[int]\n    :type target: int\n    :rtype: List[int]\n    \"\"\"\n    dict = collections.defaultdict(int)\n    for i, t in enumerate(nums):\n        if target - t in dict:\n            return [dict[target-t], i]\n        dict[t] = i\n\\end{lstlisting}\n\n15. 3Sum\n\nGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.\n\nNote: The solution set must not contain duplicate triplets.\n\nFor example, given array S = [-1, 0, 1, 2, -1, -4],\n\\begin{lstlisting}\nA solution set is:\n[\n  [-1, 0, 1],\n  [-1, -1, 2]\n]\n\\end{lstlisting}\n\nSolution: Should use three pointers, no extra space. i is the start point from [0,len-2], l,r is the other two pointers. l=i+1, r=len-1 at the beignning. The saving of time complexity is totally from the sorting algorithm.\n\\begin{lstlisting}\n[-4,-1,-1,0,1,2]\ni, l-> ``````<-r\n\\end{lstlisting}\nHow to delete repeat?\n\\begin{lstlisting}[language = Python]\ndef threeSum(self, nums):\n    res = []\n    nums.sort()\n    for i in xrange(len(nums)-2):\n        if i > 0 and nums[i] == nums[i-1]: #make sure pointer not repeat\n            continue\n        l, r = i+1, len(nums)-1\n        while l < r:\n            s = nums[i] + nums[l] + nums[r]\n            if s < 0:\n                l +=1 \n            elif s > 0:\n                r -= 1\n            else:\n                res.append((nums[i], nums[l], nums[r]))\n                l+=1\n                r-=1\n\n                #after the first run, then check duplicate example.\n                while l < r and nums[l] == nums[l-1]:\n                    l += 1\n                while l < r and nums[r] == nums[r+1]:\n                    r -= 1\n    return res\n\\end{lstlisting}\nUse hashmap:\n\\begin{lstlisting}[language = Python]\ndef threeSum(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: List[List[int]]\n        \"\"\"\n        res =[]\n        nums=sorted(nums)\n        if not nums:\n            return []\n        if nums[-1]<0 or nums[0]>0:\n            return []\n        end_position = len(nums)-2\n        dic_nums={}\n        for i in xrange(1,len(nums)):\n            dic_nums[nums[i]]=i# same result save the last index\n        \n        for i in xrange(end_position):\n            target = 0-nums[i]\n            if i>0 and nums[i] == nums[i-1]: #this is to avoid repeat \n                continue\n            if target<nums[i]: #if the target is smaller than this, we can not find them on the right side\n                break\n            for j in range(i+1,len(nums)): #this is to avoid repeat \n                if j>i+1 and nums[j]==nums[j-1]:\n                    continue\n                complement =target - nums[j]\n                if complement<nums[j]: #if the left numbers are bigger than the complement, no need to keep searching\n                    break\n                if complement in dic_nums and dic_nums[complement]>j: #need to make sure the complement is bigger than nums[j]\n                    res.append([nums[i],nums[j],complement])\n        return res\n\\end{lstlisting}\nThe following code uses more time\n\\begin{lstlisting}[language = Python]\nfor i in xrange(len(nums)-2):\n            if i > 0 and nums[i] == nums[i-1]:\n                continue\n            l, r = i+1, len(nums)-1\n            while l < r:\n                if l-1>=i+1 and nums[l] == nums[l-1]: #check the front\n                    l += 1\n                    continue\n                if r+1<len(nums) and nums[r] == nums[r+1]:\n                    r -= 1\n                    continue\n                s = nums[i] + nums[l] + nums[r]\n                if s < 0:\n                    l +=1 \n                elif s > 0:\n                    r -= 1\n                else:\n                    res.append((nums[i], nums[l], nums[r]))\n                    l += 1; r -= 1\n        return res\n\\end{lstlisting}\n18. 4Sum\n\\begin{lstlisting}[language = Python]\ndef fourSum(self, nums, target):\n        def findNsum(nums, target, N, result, results):\n            if len(nums) < N or N < 2 or target < nums[0]*N or target > nums[-1]*N:  # early termination\n                return\n            if N == 2: # two pointers solve sorted 2-sum problem\n                l,r = 0,len(nums)-1\n                while l < r:\n                    s = nums[l] + nums[r]\n                    if s == target:\n                        results.append(result + [nums[l], nums[r]])\n                        l += 1\n                        r-=1\n                        while l < r and nums[l] == nums[l-1]:\n                            l += 1\n                        while l < r and nums[r] == nums[r+1]:\n                            r -= 1\n                    elif s < target:\n                        l += 1\n                    else:\n                        r -= 1\n            else: # recursively reduce N\n                for i in range(len(nums)-N+1):\n                    if i == 0 or (i > 0 and nums[i-1] != nums[i]):\n                        findNsum(nums[i+1:], target-nums[i], N-1, result+[nums[i]], results) #reduce nums size, reduce target, save result\n\nresults = []\n        findNsum(sorted(nums), target, 4, [], results)\n        return results\n\\end{lstlisting}\n\n454. 4Sum II\n\nGiven four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.\n\nTo make problem a bit easier, all A, B, C, D have same length of N where $0 \\leq N \\leq 500$. All integers are in the range of -228 to 228–1 and the result is guaranteed to be at most 231–1.\n\nExample:\n\\begin{lstlisting}\nInput:\nA = [ 1, 2]\nB = [-2,-1]\nC = [-1, 2]\nD = [ 0, 2]\n\nOutput:\n2\n\\end{lstlisting}\n\nExplanation:\n\n\\begin{lstlisting}\nThe two tuples are:\n1. (0, 0, 0, 1) -> A[0] + B[0] + C[0] + D[1] = 1 + (-2) + (-1) + 2 = 0\n2. (1, 1, 0, 0) -> A[1] + B[1] + C[0] + D[0] = 2 + (-1) + (-1) + 0 = 0\n\\end{lstlisting}\nSolution: if we use brute force, use 4 for loop, then it is $O(N^4)$. If we use divide and conquer, sum the first half, and save a dictionary (counter), time complexity is $O(2N^2)$. What if we have 6 sum, we can reduce it to $O(2N^3)$, what if 8 sum.\n\n\\begin{lstlisting}[language = Python]\ndef fourSumCount(self, A, B, C, D):\n    AB = collections.Counter(a+b for a in A for b in B)\n    return sum(AB[-c-d] for c in C for d in D)\n\\end{lstlisting}\n\n\n\\subsubsection{Summary}\nAs we have seen from the shown examples in this section, to solve the combination problem, backtrack shown in Section~\\ref{sec_combination} offers a universal solution. Also, there is another iterative solution which suits the power set purpose. And I would include its code here again:\n\\begin{lstlisting}[language = Python]\ndef subsets(self, nums):\n    result = [[]] #use two dimensional, which already have [] one element\n    for num in nums:\n        new_results = []\n        for r in result:\n            new_results.append(r + [num])\n        result += new_results\n        \n    return result\n\\end{lstlisting}\nIf we have duplicates, how to handle in the backtrack?? In the iterative solution, we can replace the array with a dictionary saves the counts. \n\n\\subsection{Permutation}\n46. Permutations\n\\begin{lstlisting}\nGiven a collection of distinct numbers, return all possible permutations.\n\nFor example,\n [1,2,3] have the following permutations:\n\n[\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]\n\\end{lstlisting}\n\n47. Permutations II\n\nGiven a collection of numbers that might contain duplicates, return all possible unique permutations.\n\nFor example,\n\\begin{lstlisting}\n [1,1,2] have the following unique permutations:\n\n[\n  [1,1,2],\n  [1,2,1],\n  [2,1,1]\n]\n\\end{lstlisting}\n\n301. Remove Invalid Parentheses\n\nRemove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results.\n\nNote: The input string may contain letters other than the parentheses ( and ).\n\nExamples:\n\\begin{lstlisting}\n\"()())()\" -> [\"()()()\", \"(())()\"]\n\"(a)())()\" -> [\"(a)()()\", \"(a())()\"]\n\")(\" -> [\"\"]\n\\end{lstlisting}\n\\end{document}", "meta": {"hexsha": "b8edbb499f1cfb96b96fd0968ff25d21f8084b0e", "size": 21647, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/mastering/array/subset.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/mastering/array/subset.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/mastering/array/subset.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": 33.5092879257, "max_line_length": 527, "alphanum_fraction": 0.5998059777, "num_tokens": 6050, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467643431002, "lm_q2_score": 0.8824278649085118, "lm_q1q2_score": 0.7757836022005085}}
{"text": "\\documentclass[10pt,oneside,landscape]{article}\n\\usepackage{latexsym}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{graphicx}\n\\usepackage{amsthm}\n\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem*{problem}{Problem}\n\n\\begin{document}\n\n\\title{Approximating $\\pi$ with an Infinite Series}\n\\author{Dave Neary}\n\n\\maketitle\n\n\\section{Introduction}\n\nWe can sum the infinite series:\n\\[f(t) = 1-t^2+t^4-t^6+\\cdots = \\frac{1}{1+t^2} \\]\n\nIntegrating across from 0 to $x$:\n\n\\[\\int_{t=0}^x f(t) dt = \\tan^{-1}(x) = x-\\frac{x^3}{3}+\\frac{x^5}{5} - \\cdots\\]\n\nAnd setting $x=1$ (which converges in the integral, but not in the original function):\n$\\tan^{-1}(1) = \\frac{\\pi}{4} = 1-\\frac{1}{3}+\\frac{1}{5}-\\frac{1}{7} - \\cdots$\n\n\\bigskip\n\nThis is a nice formula for $\\pi$, but is slow to converge. You can use the tan sum formula to\nfind faster converging solutions:\n\\[\\tan(A+B) = \\frac{\\tan A + \\tan B}{1-\\tan A \\tan B}\\]\n\nLet $A=\\tan^{-1} \\frac{1}{2}, B=\\tan^{-1} \\frac{1}{3}$ Then apply the tangent sum forula, and take\ninverse tangents on both side:\n\n\\begin{align*}\n\\tan(A+B) &= \\frac{\\frac{1}{2}+\\frac{1}{3}}{1-\\frac{1}{2}\\cdot\\frac{1}{3}} = 1 \\\\\n\\tan^{-1}(1) & = \\frac{\\pi}{4} = \\tan^{-1}\\frac{1}{2} + \\tan^{-1}\\frac{1}{3}\n\\end{align*}\n\n\\bigskip\n\nThen:\n\\[\\displaystyle \\frac{\\pi}{4} = \\sum_{i=1}^{\\infty} \\frac{(-1)^{i+1}}{2i-1} \\left( \\frac{1}{2^{2i-1}} + \\frac{1}{3^{2i-1}}\\right)\\]\n\nwhich converges many times faster. You can do this for any other numbers you can find for\n$A+B=1-AB$ which gives $(A+1)(B+1) = 2$ such as $\\frac{1}{4}$ and $\\frac{3}{5}$.\nAnother example, more complicated to find, is:\n\n\\[\\frac{\\pi}{4} = 4\\tan^{-1}\\left(\\frac{1}{5}\\right) - \\tan^{-1}\\left(\\frac{1}{239}\\right)\\]\n\nwhich converges to 10 digits of $\\pi$ when you take the first 4 terms of the expansion of\n$\\tan^{-1} \\frac{1}{5}$ and the first two terms of $\\tan^{-1} \\frac{1}{239}$.\n\n\\end{document}\n\n", "meta": {"hexsha": "5ccc0f7250ac972e71ef0efcc983be74d6aca361", "size": 1883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "approximations_of_pi.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": "approximations_of_pi.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": "approximations_of_pi.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": 31.3833333333, "max_line_length": 131, "alphanum_fraction": 0.6325013277, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427872638409, "lm_q2_score": 0.8791467548438124, "lm_q1q2_score": 0.7757836006137864}}
{"text": "% Copyright 2017 Paul Mitchener, licensed under GNU FDL v1.3\n% main author: \n%   Paul Mitchener\n%\n\\section{Measure Spaces}\\label{sec:measure-spaces}\n\n\\begin{definition}\nLet $\\Omega$ be a measurable space, equipped with a $\\sigma$-algebra $\\mathscr A$.  \nA \\emph{measure} on $\\Omega$ is a function $\\mu \\colon {\\mathscr A}\\rightarrow [0,\\infty ]$ such that:\n\\begin{axiomlist}[M]\n\\item The function $\\mu$ is \\emph{$\\sigma$-additive}, i.e.\n\\[  \\mu \\left( \\bigcup_{n=1}^\\infty A_n \\right) = \\sum_{n=1}^\\infty \\mu (A_n ) \\ , \\] \nwhenever $(A_n)_{n\\in \\N}$ is a sequence of disjoint mesaurable sets.  \n\\item There is a measurable set $A$ such that $\\mu (A)<\\infty$.\n\\end{axiomlist}\nThe number $\\mu (A)$ is called the \\emph{measure} of a set $A$.  A measurable space equipped with some measure is called a \n\\emph{measure space}.\n\\end{definition}\n\nFor the above definition to make sense, we need to make a convention concerning our `number' $\\infty$, namely that $a + \\infty = \\infty$ whenever $a\\in [0,\\infty ]$.  \n\n\\begin{example}\nLet $\\Omega$ be a measurable space.  For any measurable set $E\\subseteq \\Omega$, let us define\n$\\mu (E) = |E|$, where $|E|$ denotes the number of elements of $E$.  Then $\\mu$ is a measure on $\\Omega$, called the {\\em counting measure}.\n\\end{example}\n\n\\begin{example}\nLet $\\Omega$ be a measurable space, and let $x_0 \\in \\Omega$.  For any measurable set $E\\subseteq \\Omega$, let us define\n$$\\mu (E) = \\left\\{ \\begin{array}{ll}\n1 & x_0 \\in E \\\\\n0 & x_0 \\not\\in E \\\\\n\\end{array} \\right.$$\n\nThen $\\mu$ is a measure on $\\Omega$, called the {\\em Dirac measure}.\n\\end{example}\n\n\\begin{proposition}\nLet $\\Omega$ be a measure space, with measure $\\mu$.  Then $\\mu (\\emptyset ) =0$.\n\\end{proposition}\n\n\\begin{proof}\nChoose a measurable set $A$ such that $\\mu (A)<\\infty$.  Then\n$$\\mu (A) =  \\mu (A) + \\mu (\\emptyset ) + \\mu (\\emptyset ) +\\cdots$$\nHence $\\mu (\\emptyset ) =0$.\n\\end{proof}\n\n\\begin{corollary}\nLet $A_1 , \\ldots , A_n$ be disjoint measurable sets.  Then\n$$\\mu (A_1 \\cup \\cdots \\cup A_n ) = \\mu (A_1 ) + \\cdots + \\mu (A_n)$$\n\\textbf{proof to be filled in!}\n\\end{corollary}\n\n\\begin{corollary}\nLet $A$ and $B$ be measurable set where $A\\subseteq B$.  Then $\\mu (A) \\leq \\mu (B)$.\n\\end{corollary}\n\n\\begin{proof}\nThe set $B\\backslash A = B\\cap (\\Omega \\backslash A )$ is measurable, the sets $A$ and $B\\backslash A$ are disjoint, and $B = A\\cup B\\backslash A$.  By the above corollary\n$$\\mu (B) = \\mu (A) + \\mu (B\\backslash A)$$\n\nThe inequality $\\mu (A)\\leq \\mu (B)$ follows since $\\mu (B\\backslash A)\\geq 0$.\n\\end{proof}\n\n\\begin{proposition} \\label{limsub}\nLet $(A_n )$ be a sequence of measurable sets such that $A_n \\subseteq A_{n+1}$ for all $n$.  Let $A = \\bigcup_{n=1}^\\infty A_n$.  Then $\\lim_{n\\rightarrow \\infty} \\mu (A_n ) = \\mu (A)$.\n\\end{proposition}\n\n\\begin{proof}\nLet $B_1 =A_1$, and $B_n = A_n \\backslash A_{n-1}$ when $n\\geq 2$.  Then the sets $B_n$ are measurable and disjoint.  Further\n$$A_n = B_1 \\cup \\cdots \\cup A_n \\qquad A= \\bigcup_{n=1}^\\infty B_n$$\n\nHence\n$$\\mu (A) = \\sum_{n=1}^\\infty \\mu (B_n) = \\lim_{N\\rightarrow} \\sum_{n=1}^N \\mu (B_n) = \\lim_{N\\rightarrow \\infty}\\mu (A_N)$$\n\\end{proof}\n\n\\begin{corollary}\nLet $(A_n)$ be a sequence of measurable sets such that $\\mu (A_1)<\\infty$ and $A_{n+1}\\subseteq A_n$ for all $n$.    Let $A = \\bigcap_{n=1}^\\infty A_n$.  Then $\\lim_{n\\rightarrow \\infty} \\mu (A_n ) = \\mu (A)$.\n\\end{corollary}\n\n\\begin{proof}\nLet $C_n =A_1\\backslash A_n$.  Then the set $C_n$ is measurable, $C_n\\subseteq C_{n+1}$ for all $n$, and $\\bigcup_{n=1}^\\infty C_n = A_1 \\backslash A$.  Hence, by the above proposition\n$$\\lim_{n\\rightarrow \\infty}\\mu (C_n) = \\mu (A_1 \\backslash A)$$\n\nWe know that the measure $\\mu (A_1)$ is finite, and that we have disjoint unions$$A_1 = A_n \\cup C_n \\qquad A_1 = A_1\\backslash A \\cup A$$\nHence\n$$\\mu (A_1 )- \\lim_{n\\rightarrow \\infty} \\mu (A_n) = \\mu (A_1 ) - \\mu (A)$$\nand\n$$\\lim_{n\\rightarrow \\infty} \\mu (A_n ) = \\mu (A)$$\n\\end{proof}\n\nThe above corollary is false if we omit the assumption that $\\mu (A_1)<\\infty$.\n", "meta": {"hexsha": "57470d3932d27cda3acc2815ca5f269c3812b067", "size": 4022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Example/sections/measure-spaces.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/measure-spaces.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/measure-spaces.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": 43.7173913043, "max_line_length": 209, "alphanum_fraction": 0.6514172054, "num_tokens": 1507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467548438124, "lm_q2_score": 0.88242786954645, "lm_q1q2_score": 0.7757835978955006}}
{"text": "\\chapter{Counting Principles}\n\\label{chapter:principles}\n\\marginurl{%\n  Counting Principles:\\\\\\noindent\n  Introduction to Combinatorics \\#2\n}{youtu.be/dAoperLCjb8}\n\\section{The Additive Principle}\nThe first principle is called \\emph{additive} principle and it states that if\nyou have two disjoint sets, then their union have size equal to the sum of their\nsizes.\n\nA simple illustration of this statement is the following. Assume you have three\npencils and two pens; how many ways to choose a writing accessory. According to\nthis principle the answer is $2 + 3 = 5$.\n\\begin{theorem}[The Additive Principle]\n\\label{theorem:additive-principle}\n  Let $X$ and $Y$ be finite sets. If $X \\cap Y = \\emptyset$, then\n  $\\cardinality{X \\cup Y} = \\cardinality{X} + \\cardinality{Y}$.\n\\end{theorem}\n\n\n\\begin{corollary}\n\\label{corollary:additive-principle}\n  Let $X_1, \\dots, X_n$ be some pairwise disjoint sets. Then\n  $\\cardinality{\\bigcup_{i = 1}^n X_i} = \\sum_{i = 1}^n \\cardinality{X_i}$.\n\\end{corollary}\n\n\\begin{exercise}\n  Prove Corollary~\\ref{corollary:additive-principle}.\n\\end{exercise}\n\n\n\\section{The Multiplicative Principle}\nThe next principle is called the \\emph{multiplicative} principle and it can be\nillustrated as follows: imagine that you are given two postal stamps and\nthree envelopes, how many ways are there to pack the letters? The answer is obviously\n$2 \\cdot 3 = 6$.\n\\begin{theorem}[The Multiplicative Principle]\n\\label{theorem:multiplicative-principle}\n  Let $X$ and $Y$ be finite sets. Then $\\cardinality{X \\times Y} =\n  \\cardinality{X} \\times \\cardinality{Y}$.\n\\end{theorem}\n\n\\begin{exercise}\n  Assume you have $5$ types of envelopes and $6$ types of postal stamps.\n  \\begin{enumerate}\n    \\item How many ways to put one stamp on one envelope?\n    \\item How many ways to put two stamps on one envelope?\n  \\end{enumerate}\n\\end{exercise}\n\nBy analogy with unions and intersections of many sets we can define the cross\nproduct of many sets.\nLet $X_1$, \\dots, $X_n$ be some sets. Then $\\bigtimes_{i = 1}^1 X_i = A_1$ and\n$\\bigtimes_{i = 1}^{k + 1} X_i =\n  \\left(\\bigtimes_{i = 1}^k X_i\\right) \\times X_{k + 1}$\\footnote{%\n    Note that cross product is not associative and different definitions of the\n    product of several sets are not equivalent. However, the bijection\n    constructed in the previous section allow us to think about these\n    definitions as if they are equivalent.\n}.\n\n\\begin{corollary}\n\\label{corollary:multiplicative-principle}\n  Let $X_1, \\dots, X_n$ be some finite sets. Then\n  $\\cardinality{\\bigtimes_{i = 1}^n X_i} = \\prod_{i = 1}^n \\cardinality{X_i}$.\n\\end{corollary}\n\n\\begin{exercise}\n  Prove Corollary~\\ref{corollary:multiplicative-principle}.\n\\end{exercise}\n\n\\begin{theorem}\n\\label{theorem:cardinality-of-power-set}\n  For any set $X$, $\\cardinality{\\subsets{X}} = 2^{\\cardinality{X}}$.\n\\end{theorem}\n\\begin{proof}\n  By Corollary~\\ref{corollary:power-set-and-set-of-binary-strings},\n  $\\cardinality{\\subsets{X}} =\n  \\cardinality{\\functions{\\cardinality{X}}{\\set{0, 1}}}$, so it is enough to\n  prove that $\\cardinality{\\set{0, 1}^{\\cardinality{X}}} = \\subsets{\\cardinality{X}}$. \n  This statement is true by \\Cref{corollary:multiplicative-principle} since \n  $\\cardinality{\\set{0, 1}^{\\cardinality{X}}} =\n  \\prod_{i = 1}^{\\cardinality{X}} \\cardinality{\\set{0, 1}} = \n    2^{\\cardinality{X}}$.\n\\end{proof}\n\nUsing this result and \\Cref{theorem:injections-surjections-inequalities} we may\nfinally prove \\Cref{lemma:turning-turtles-number-P}.\n\\begin{proof}[Proof of \\Cref{lemma:turning-turtles-number-P}]\n  First note that any state in turning turtles can be described by a set \n  $\\set{a_1, \\dots, a_\\ell} \\subseteq \\range{m}$ of positions of heads; moreover\n  the position is a P-position iff \n  $a_1 \\bitwisexor a_2 \\bitwisexor \\dots \\bitwisexor a_\\ell = 0$.\n\n  We may also note that for any $n \\in  \\range{2^r}$ there is a set $C(n) =\n  \\set{c_1, \\dots, c_k} \\subseteq \\set{2^0, 2^1, 2^2, \\dots, 2^{r - 1}}$ such\n  that \n  $n \\bitwisexor c_1 \\bitwisexor a_2 \\bitwisexor \\dots \\bitwisexor c_k = 0$.\n  Let $I = \\range{m} \\setminus \\set{2^0, 2^1, 2^2, \\dots, 2^{r - 1}}$.\n  It is clear that for any $J \\subseteq I$ there is \n  $C'(J) = \\set{c_1, \\dots, c_k} \\subseteq \n    \\set{2^0, 2^1, 2^2, \\dots, 2^{r - 1}}$ such that $J \\cup C'(J)$ describes a\n  P-position in turning turtles.\n\n  Let $I = \\set{i_1, \\dots, i_{m - r}}$. We can define an injection \n  $f : \\set{0, 1}^{\\cardinality{I}} \\to 2^{\\range{m}}$ such that $f(x)$ is a \n  P-position in turning turtles. Indeed, the function $f$ such that\n  $f(x_1, \\dots, x_{m - r}) = \\set[x_j = 1]{i_j} \\cup C'(\\set[x_j = 1]{i_j})$\n  is an injection and $f(x_1, \\dots, x_{m - r})$ is a P-position in turning\n  turtles.\n\n  Therefore $2^{m - r} = \\cardinality{\\set{0, 1}^{\\cardinality{I}}}$ is greater\n  or equal to the number of P-positions in turning turtles.\n\\end{proof}\n\nWe can also use these principles to show that Hamming code is optimal.\n\\begin{theorem}\n  Let $n = 2^{2^r - r - 1}$ and let $C : \\range{n} \\to \\set{0, 1}^m$ be an\n  error-correcting code correcting $1$ error. Then $m \\ge 2^r - 1$.\n\\end{theorem}\n\\begin{proof}\n  Let $B(i) = \\set[{\\hammingDist{C(i)}{x} \\le 1}]{x \\in \\set{0, 1}^m}$.\n  By the definition of erorr-correcting codes, $B(i)$ and $B(j)$ are disjoint \n  for $i \\neq j$. Note that $\\cardinality{B(i)} = 1 + m$ since if\n  $\\hammingDist{C(i)}{x} \\le 1$, then either $x = C(i)$ or they are different in\n  one out of $m$ coordinates. Therefore $\\cardinality{\\bigcup_{i = 1}^n B(i)}\n  = (1 + m) n \\le 2^m$ since $\\cardinality{\\set{0, 1}^m} = 2^m$. \n\n  Note that for a fixed $r$, $(1 + m) n$ and $2^m$ as functions of $m$ intersect\n  only in one point and the inequality is false for $m = 0$. Moreover, the\n  inequality became equality for $m = 2^r - 1$. Therefore in order for the\n  equality to be true we need $m \\ge 2^r - 1$.\n\\end{proof}\n\n\\section{The Inclusion-exclusion Principle}\n\nThe last principle we are going to discuss in this chapter is the\ninclusion-exclusion principle which helps us to find the size of the union\nof sets when they are not disjoint.\n\\begin{theorem}[The Inclusion-exclusion Principle]\n\\label{theorem:inclusion-exclusion-principle}\n  Let $X$ and $Y$ be finite sets. Then $\\cardinality{X \\cup Y} = \\cardinality{X}\n  + \\cardinality{Y} - \\cardinality{X \\cap Y}$.\n\\end{theorem}\n\\begin{proof}\n  Note that $X \\cup Y = (X \\setminus Y) \\cup (Y \\setminus X) \\cup (X \\cap Y)$.\n  Hence, $\\cardinality{X \\cup Y} = \\cardinality{X \\setminus Y} + \n  \\cardinality{Y \\setminus X} + \\cardinality{X \\cap Y}$. But it\n  is possible to note that $\\cardinality{Y \\setminus X} + \\cardinality{X \\cap Y}\n  = \\cardinality{Y}$ and $\\cardinality{X \\setminus Y} + \\cardinality{X \\cap Y} =\n  \\cardinality{X}$.\n\\end{proof}\n\n\\begin{corollary}\n\\label{corollary:inclusion-exclusion-principle}\n  Let $X_1, \\dots, X_n$ be some finite sets. Then\n  \\[\n    \\cardinality{\\bigcup_{i = 1}^n X_i} =\n    \\sum_{S \\subseteq \\range{n} ~:~ S \\neq \\emptyset} \n      (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\]\n\\end{corollary}\n\\begin{proof}\n  As always, we prove this statement using induction by $n$. The base case for\n  $n = 2$ is true by Theorem~\\ref{theorem:inclusion-exclusion-principle}.\n\n  By the induction hypothesis,\n  \\[\n    \\cardinality{\\bigcup_{i = 1}^k X_i} =\n    \\sum_{S \\subseteq \\range{k} ~:~ S \\neq \\emptyset} \n      (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\]\n  In addition, by Theorem~\\ref{theorem:inclusion-exclusion-principle},\n  \\[\n    \\cardinality{\\bigcup_{i = 1}^{k + 1} X_i} =\n    \\cardinality{\\bigcup_{i = 1}^k X_i} + \\cardinality{X_{k + 1}} -\n      \\cardinality{\\left(\\bigcup_{i = 1}^k X_i\\right) \\cap X_{k + 1}}.\n  \\]\n  We need to simplify two elements of the sum on the right of the equality.\n  By the induction hypothesis,\n  \\[\n    \\cardinality{\\bigcup_{i = 1}^k X_i} =\n    \\sum_{S \\subseteq \\range{k} ~:~ S \\neq \\emptyset}\n        (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\]\n  In addition, it is easy to note that\n  \\[\n    \\cardinality{\\left(\\bigcup_{i = 1}^k X_i\\right) \\cap X_{k + 1}} =\n    \\cardinality{\\bigcup_{i = 1}^k \\left(X_i \\cap X_{k + 1}\\right)}.\n  \\]\n  Thus using the induction hypothesis,\n  \\begin{multline*}\n    \\cardinality{\\left(\\bigcup_{i = 1}^k X_i\\right) \\cap X_{k + 1}} = \\\\\n    \\sum_{S \\subseteq \\range{k} ~:~ S \\neq \\emptyset}\n      (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} (X_i \\cap X_{k + 1})} = \\\\\n    \\sum_{S \\subseteq \\range{k + 1} ~:~ (k + 1) \\in S \\text{ and } S \\neq \\set{k + 1}}\n          (-1)^{\\cardinality{S}} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\end{multline*}\n  As a result,\n  \\[\n    \\cardinality{X_{k + 1}} -\n      \\cardinality{\\left(\\bigcup_{i = 1}^k X_i\\right) \\cap X_{k + 1}} =\n    \\sum_{S \\subseteq \\range{k + 1} ~:~ (k + 1) \\in S}\n          (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\]\n  Which implies that\n  \\begin{multline*}\n    \\cardinality{\\bigcup_{i = 1}^{k + 1} X_i} =\n    \\sum_{S \\subseteq \\range{k} ~:~ S \\neq \\emptyset}\n      (-1)^{\\cardinality{S} + 1}\\cardinality{\\bigcap_{i \\in S} X_i} + \\\\\n    \\sum_{S \\subseteq \\range{k + 1} ~:~ (k + 1) \\in S}\n          (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i} = \\\\\n    \\sum_{S \\subseteq \\range{k + 1} ~:~ S \\neq \\emptyset}\n      (-1)^{\\cardinality{S} + 1} \\cardinality{\\bigcap_{i \\in S} X_i}.\n  \\end{multline*}\n\\end{proof}\n\n\n\n\\begin{chapterendexercises}\n  \\exercise\n    Find the cardinality of the set\n    \\[\n      \\set[{x, y \\in \\range{9} \\text{ and } x \\neq y}]{(x, y)}.\n    \\]\n  \\exercise[recommended] Find the number of ordered pairs $(A, B)$ of subsets of\n    $\\range{n}$ such that $A \\cap B = \\emptyset$ (the answer is not supposed to\n    contain the summation sign).\n  \\exercise How many functions from $\\set{0, 1}^n$ to $\\set{0, 1}$?\n  \\exercise[recommended] How many numbers from $\\range{999}$ are not divisible\n    neither by $3$, nor by $5$, nor by $7$.\n    \\begin{solution}\n      Let $D_n = \\set[i \\text{is divisible by n}]{i \\in \\range{999}}$.\n      Note that $D_3 \\cap D_5 = D_{15}$, $D_3 \\cap D_7 = D_{21}$, $D_5 \\cap D_7\n      = D_{35}$, and finally, $D_3 \\cap D_5 \\cap D_7 = D_{105}$. Additionally,\n      $\\cardinality{D_3} = 999 / 3 = 333$,\n      $\\cardinality{D_5} = \\floor{999 / 5} = 199$,\n      $\\cardinality{D_7} = \\floor{999 / 7} = 142$,\n      $\\cardinality{D_{15}} = \\floor{999 / 15} = 66$,\n      $\\cardinality{D_{21}} = \\floor{999 / 21} = 47$,\n      $\\cardinality{D_{35}} = \\floor{999 / 35} = 28$, and\n      $\\cardinality{D_{105}} = \\floor{999 / 105} = 9$.\n      As a result, by the inclusion-exclusion principle, the answer is\n      $999 - 333 - 199 - 142 + 66 + 47 + 28 - 9 = 457$.\n    \\end{solution}\n  \\exercise How many numbers from $1$ to $1000$ are neither square numbers nor\n    cubic numbers?\n    \\begin{solution}\n      Let us define \n      $\n        A_i =  \\set[{\\sqrt[i]{x} \\in \\Z}]{x \\in \\range{1000}}.\n      $\n      We need to find the value of $1000 - |A_2 \\cup A_3|$. Note that \n      $\\cardinality{A_i} = \\floor{\\sqrt[i]{1000}}$. Hence,\n      \\begin{multline*}\n        \\cardinality{A_2 \\cup A_3} = \\cardinality{A_2} + \\cardinality{A_3} -\n        \\cardinality{A_2 \\cap A_3} = \\cardinality{A_2} + \\cardinality{A_3} -\n        \\cardinality{A_6} = \\\\\n        \\floor{\\sqrt{1000}} + \\floor{\\sqrt[3]{1000}} - \\floor{\\sqrt[6]{1000}} =\n        31 + 10 - 3 = 38.\n      \\end{multline*}\n      Therefore the answer is equal to $1000 - 38 = 962$.\n    \\end{solution}\n  \\exercise How many $6$-digit numbers are there that have the same reminder\n    modulo $2$ of all the digits?\n    \\begin{solution}\n      We will give two solutions depending on one's interpretation of $6$-digit\n      numbers (i.e whether or not the leading coefficient can be $0$).\n\n      First, in the case where the leading coefficient may be $0$, there are\n      $10$ choices for the first digit. Upon picking the first digit, we now\n      must picks digits that have the same parity (i.e even or odd) as the first\n      digit. Thus, there are $5$ choices for digits two through six, and we get\n      \\[\n        10\\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5\\cdot 5 = 31250 \\text{ total digits. }\n      \\]\n\n      However, if you interpreted the problem as the leading coefficient cannot\n      be $0$, then there would be $9$ options for the first digit and then $5$\n      for each of the remaining. We would then get\n      \\[\n        9 \\cdot 5 \\cdot 5 \\cdot 5 \\cdot 5\\cdot 5 = 28125 \\text{ total digits. }\n      \\]\n    \\end{solution}\n  \\exercise How many numbers $x$ from $1$ to $999$ such that at least one\n    of the digits of $x$ is $7$?\n    \\begin{solution}\n      First note that any number from $0$ to $999$ may be expressed using $3$\n      digits (we allow to use leading $0$s to express the numbers like $1$).\n      Thus we need to find the size of the set\n      \\[\n        \\set[{ \n          7 \\in \\{a_1, a_2, a_3\\}\n        }]{(a_1, a_2, a_3) \\in \\set{0, \\dots, 9}^3}.\n      \\]\n\n      Let $S \\subseteq [3]$, it is easy to see that \n      \\[\n        \\bigcap_{i \\in S}\n          \\set[{ \n            7 \\in \\{a_1, a_2, a_3\\}\n          }]{(a_1, a_2, a_3) \\in \\set{0, \\dots, 9}^3}\n      \\]\n      has $10^{\\cardinality{S}}$ elements. As a result, the answer is \n      $1000 - 3 \\cdot 10^2 + 3 \\cdot 10 - 1$.\n    \\end{solution}\n  \\exercise How many numbers $x$ from $1$ to $999$ such that exactly one\n    of the digits of $x$ is $7$?\n    \\begin{solution}\n      Note that any number from $0$ to $999$ can be described by three digits.\n      It is easy to see that there are $9^2$ number with one digit equal to $7$\n      and all others being not equal to $7$. Hence, the answer is $3 \\cdot\n      9^2$.\n    \\end{solution}\n  \\exercise Let $A$, $B$ be some finite sets such that $A \\subseteq B$.\n    Show that $\\cardinality{B \\setminus A} = \\cardinality{B} - \\cardinality{A}$.\n  \\exercise King Arthur invited $n$ knights for a feast. Each knight has an enemy\n    (being an enemy is a mutual relation; i.e., if $A$ is an enemy of $B$, then\n    $B$ is an enemy of $A$). How many ways for knights to seat around the Round\n    Table so that enemies are not sitting together?\n  \\exercise[recommended] Let $n$ be some positive integer.\n    Find the cardinality of the set\n    \\[\n      \\set[{A, B \\subseteq \\range{n} \\text{ and } A \\cap B \\neq \\emptyset}]{(A, B)}?\n    \\]\n  \\exercise Let $X$ and $Y$ be some finite sets, and $f : X \\to Y$ be a function\n    such that $\\cardinality{f^{-1}(y)} = k$ for all $y \\in Y$. Prove that\n    $\\cardinality{X} = k\\cardinality{Y}$.\n  \\exercise[recommended] Show that if $U$ and $X_1, \\dots, X_n \\subseteq U$ are\n    some finite sets, then\n    \\[\n      \\cardinality{\\bigcap_{i = 1}^n X_i} =\n      \\sum_{S \\subseteq \\range{n}} (-1)^{\\cardinality{S}}\n        \\cardinality{\\bigcap_{i \\in S} \\overline{X}_i},\n    \\]\n    where $\\overline{X}_i = U \\setminus X_i$ and\n    $\\bigcap_{i \\in \\emptyset} \\overline{X}_i = U$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "56a492e8e0866a70970d863d0f2b06a74e58f531", "size": 14886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_4/chapter_18_principles.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_18_principles.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_18_principles.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.7823529412, "max_line_length": 90, "alphanum_fraction": 0.6347574903, "num_tokens": 5271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392878563336, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.7757239472345656}}
{"text": "\\subsection{B-spline as activation functions}\\label{sec:Bsplines}\nIn this section, we consider the power of ReLU as activation functions\n\\begin{equation}\n  \\label{relup}\n{\\rm ReLU}^k(x)=[x_+]^k. \n\\end{equation} \n\n\nWe consider the following neuron network function class \nwith one hidden layer:\n\\begin{equation}\n\\label{VkN}\nV_N^k=\\left\\{\\sum_{i=1}^Na_i(w_i\\cdot x+b_i)_+^k, a_i, b_i\\in\\mathbb R^1, w_i\\in \\mathbb R^{1\\times d}\\right\\}.\n\\end{equation}\nWe note that $V_N^k$ is not a linear vector space.  The definition of\nneural network function class such as \\eqref{VkN} can be traced back\nin \\cite{mcculloch1943logical} and its early mathematical analysis can be found in \\cite{hornik1989multilayer,cybenko1989approximation,funahashi1989approximate}.\n\nThe functions in $V^k_N$ as defined in \\eqref{VkN} will be known as finite neuron functions in this paper.\n\\begin{lemma}\n  For any $k\\ge 1$, $V_N^k$ consists of functions that are piecewise\n  polynomials of degree $k$ with respect to a grid whose boundaries are\n  given by intersection of the following hyperplanes\n$$\nw_ix + b_i=0,\\quad 1\\le i\\le N.\n$$\nsee Fig \\ref{fig:1} and Fig \\ref{fig:3}. Furthermore, if $k\\ge m$,\n$$\nV_N^k(\\Omega)\\subset H^k(\\Omega)\\subset H^m(\\Omega),\n$$\nwhere $\\Omega$ is a bounded domain in $\\mathbb{R}^d$.\n\\end{lemma}\n\\begin{figure}[!ht]\n\\begin{center}\n%$(10, 10)$ $(20, 20)$ $ (40,40)$ \n\\includegraphics[width=.3\\textwidth]{6dl/figures/dnn1-50.jpg}    \n\\end{center}\n\\caption{Hyperplanes with $\\ell=1$, where $\\ell$ is the depth of the neural network in \\eqref{NNL}.}\n\\label{fig:1}\n\\end{figure} \t\t\n \n\nThe main goal of this section is to prove that the \nfollowing type of error estimate holds, for some $\\delta\\ge 0$,\n\\begin{equation}\\label{VNerror}\n\\inf_{v_N\\in V_N^k}\\|u- v_N \\|_{H^m(\\Omega)} \\lesssim \nN^{-{1\\over 2}-\\delta}.\n\\end{equation} \nWe will use two different approaches to establish \\eqref{VNerror}.\nThe first approach, presented in \\S\\ref{sec:Bsplines}, mainly follows\n\\cite{hornik1994degree} and \\cite{siegel2020approximations} that gives\nerror estimates for a general class of activation functions.  The\nsecond approach follows\n\\cite{klusowski2016uniform} that gives error estimates specifically\nfor ReLU activation function.\n\nWe assume that $\\Omega\\subset\\mathbb R^d$ is a given bounded domain.\nThus,\n\\begin{equation}\n  \\label{T}\nT=\\max_{x\\in \\bar{\\Omega}} \\|x\\|<\\infty.  \n\\end{equation}\nThe activation function ${\\rm [ ReLU]}^k$ \\eqref{relup} is related to\ncardinal B-Splines.  A cardinal B-Spline of degree $k\\ge 0$\ndenoted by $b^k$, is defined by convolution as\n\\begin{equation}\n\tb^k(x)=(b^{k-1}*b^0)(x)=\\int_\\mathbb{R}b^{k-1}(x-t)b^0(t)dt,\n\\end{equation}\nwhere \n\\begin{equation}\nb^0(x)=\\left\\{\n\t\t     \\begin{array}{lr}\n\t\t    1 & x\\in[0,1),\\\\\n\t\t    0 & \\hbox{otherwise}.\n\t\t     \\end{array}\n\t\\right.\n\\end{equation}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{6DL/figures/B-spline.png}   \n\\caption{Plots of some B-spline basis}\n\\label{bk}\n\\end{center}\n\\end{figure}\nMore explicitly, see \\cite{de1971subroutine}, for any\n$x\\in[0,k+1]$ and $k\\geq 1$, we have \n\t\\begin{equation}\n\tb^k(x)=\\frac{x}{k}b^{k-1}(x)+\\frac{k+1-x}{k}b^{k-1}(x-1),\n\t\\end{equation}\nor\n\t\\begin{equation}\\label{splinetorelu}\n\tb^k(x)=(k+1)\\sum_{i=0}^{k+1} w_i(i-x)_+^k \\hbox{~and~} w_i={\\displaystyle\\prod_{j=0,j\\neq i}^{k+1}} \\frac{1}{i-j}.\n\t\\end{equation}\nWe note that all $b^k$ are locally supported and see Fig.~\\ref{bk} for their plots. \n\nFor an uniform grid with mesh size $h=\\frac{1}{n+1}$, we define\n\t\\begin{equation}\n\tb^k_{j,h}(x)=b^{k}(\\frac{x}{h}-j).\n\t\\end{equation}\nThen the cardinal B-Spline series of degree $k$ on the uniform grid is \n\\begin{equation}\\label{Skn}\nS_N^k=\\Big\\{v(x)=\\sum_{j=-k}^{N}\tc_jb^k_{j,h}(x)\\Big\\}.\n\\end{equation}\n\\begin{lemma} For $V_N^k$ and $S_N^k$ defined by \\eqref{VkN} and\n  \\eqref{Skn}, we have\n\\begin{equation}\n    \\label{SV}\nS_N^k\\subset V_{N+k+1}^k.    \n  \\end{equation}\nAs a result, for any bounded domain $\\Omega\\subset \\mathbb R^1$, we have\n\\begin{equation}\n  \\label{SVerror}\n\\inf_{v\\in V_{N}^k}\\|u-v\\|_{m,\\Omega} \n\\le \\inf_{v\\in S_{N-k-1}^k}\\|u-v\\|_{m,\\Omega} \\lesssim N^{m-(k+1)} \\|u\\|_{k+1,\\Omega}.\n\\end{equation}\n\\end{lemma}\n\n\\iffalse\nGiven an activation function $\\sigma\\in L^1(\\mathbb R)$, consider its Fourier transformation:\n\\begin{equation}\n  \\label{Fsigma}\n\\hat \\sigma(a) = \\frac{1}{2\\pi}\\int_{\\mathbb{R}} \\sigma(t)e^{-iat}dt. \n\\end{equation}\nFor any $a\\neq 0$ with $\\hat \\sigma(a)\\neq 0$, by making a change of variables \n$t = a^{-1}\\omega\\cdot x + b$ and $dt = db$, we have\n \\begin{equation}\n \\begin{aligned}\n\\hat{\\sigma}(a)&=\\frac{1}{2\\pi}\\int_{\\mathbb{R}}\\sigma(a^{-1}\\omega\\cdot x+b)e^{-ia( a^{-1}\\omega\\cdot x+b)}db = e^{-i\\omega \\cdot x}\\frac{1}{2\\pi}\\int_{\\mathbb{R}}\\sigma(a^{-1} \\omega\\cdot x+b)e^{-iab}db.\n \\end{aligned}\n \\end{equation}\nThis implies that\n\\begin{equation}\\label{FourierExp}\n e^{i\\omega \\cdot x} = \\frac{1}{2\\pi\\hat{\\sigma}(a)}\\int_{\\mathbb{R}}\\sigma(a^{-1}\\omega\\cdot x+b)e^{-iab}db.\n\\end{equation}\nWe write $ \\hat{u}(\\omega) = e^{-i\\theta(\\omega)} | \\hat{u}(\\omega)|$\nand then obtain the following integral represntation:\n\\begin{equation}\\label{integral_representation01}\nu(x) = \\int_{\\mathbb{R}^d} e^{i\\omega\\cdot x}\\hat{u}(\\omega)d\\omega = \n\\int_{\\mathbb{R}^d}\\int_\\mathbb{R}\\frac{1}{2\\pi\\hat{\\sigma}(a)}\n\\sigma\\left(a^{-1} \\omega\\cdot x+b\\right)|\\hat{u}(\\omega)|e^{-i(ab+\\theta(\\omega))}dbd\\omega\n\\end{equation}\nNow we consider activation function $\\sigma(x)=b^k(x)$ and $\\hat \\sigma$ be the\nFourier transform of $\\sigma(x)$. Note that, by \\eqref{bk}, \n\\begin{align}\\label{splineFourier}\n\\hat{\\sigma}(a)=\\left({1-e^{-ia}\\over ia}\\right)^{k+1}=\\left({2\\over a}\\sin {a\\over 2}\\right)^{k+1}e^{-{ia(k+1)\\over 2}}.\n\\end{align}\n\nWe first take $a=\\pi$ in \\eqref{splineFourier}. Thus,\n\\begin{equation}\n  \\label{pi1}\n\\hat\\sigma(\\pi)=\n\\left({2\\over \\pi}\\right)^{k+1}e^{-{i\\pi (k+1)\\over 2}}.\n\\end{equation}\nCombining \\eqref{integral_representation01} and \\eqref{pi1}, we obtain\nthat\n\\begin{equation}\n  \\label{splinerep0}\nu(x) = \n\\frac{1}{4}\\left({\\pi\\over 2}\\right)^{k}\\int_{\\mathbb{R}^d}\\int_\\mathbb{R}\n\\sigma\\left(\\pi^{-1}\\omega\\cdot x+b\\right)|\\hat{u}(\\omega)|e^{-i(\\pi b + {\\pi (k+1)\\over 2}+\\theta(\\omega))}dbd\\omega\n\\end{equation}\nAn application of the Monte Carlo method in Lemma \\ref{MC} to the integral representation \\eqref{splinerep0} leads to the following estimate.\n\\begin{theorem}\\label{splinestratify}\nFor any $0\\le m\\le k$, if $u\\in {B}^{m+1}(\\Omega)$, there exist $\\omega_i\\in \\mathbb{R}^d$, $b_i\\in \\mathbb{R}$ such that\n\\begin{equation}\n\\left \\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}\\lesssim  N^{-{1\\over 2}} \\|u\\|_{{B}^{m+1}(\\Omega)}\n\\end{equation}\nwith\n\\begin{equation}\nu_{N}(x)=\\sum_{i=1}^{N} \\beta_i b^k\\left(\\pi^{-1} \\omega_i\\cdot x+b_i\\right).\n\\end{equation} \n\\end{theorem}\n\nBased on the integral representation \\eqref{splinerep0}, a stratified analysis similar to the one in \\cite{siegel2020approximations} leads to the following result.\n\\begin{theorem}\nFor any $0\\le m\\le k$ and positive $\\epsilon$,  if $u\\in {B}^{m+1+\\epsilon}(\\Omega)$, , there exist $\\omega_i\\in \\mathbb{R}^d$, $b_i\\in \\mathbb{R}$ such that\n\\begin{equation}\\label{straunbdd}\n\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}\\le  N^{-{1\\over 2}-{\\epsilon \\over (d+1)(2+\\epsilon)}} \\|u\\|_{{B}^{m+1+\\epsilon}(\\Omega)}\n\\end{equation}\nwith\n\\begin{equation}\nu_{N}(x)=\\sum_{i=1}^{N} \\beta_i b^k\\left(\\bar \\omega_i\\cdot x+b_i\\right) .\n\\end{equation} \n\\end{theorem}\nNext, we try to improve the estimate \\eqref{straunbdd}. Again, we will use \\eqref{integral_representation01}. Let $\\displaystyle a_\\omega=4\\pi\\lceil {\\|\\omega\\|\\over 4\\pi}\\rceil + \\pi$ in \\eqref{splineFourier} and $\\displaystyle \\bar\\omega ={\\omega\\over a_\\omega}$. We have\n \\begin{equation}\n\\hat{\\sigma}(a_\\omega)=\\left({2\\over a_\\omega}\\right)^{k+1}, \\quad \\|\\omega\\| + \\pi\\le a_\\omega\\le \\|\\omega\\|+5\\pi,\\quad \\|\\bar\\omega\\|\\le 1,\n \\end{equation}\nwhich, together with \\eqref{integral_representation01}, indicates that\n \\begin{equation}\\label{integral_representation}\n \\begin{split}\n  u(x) =  \\int_{\\mathbb{R}^d}\\int_\\mathbb{R}\\frac{1}{2\\pi}\n  \\sigma\\left(\\bar \\omega\\cdot x+b\\right)\\left({a_\\omega\\over 2}\\right)^{k+1}\\hat{u}(\\omega)e^{-ia_\\omega(b+{k+1\\over 2})}dbd\\omega.\n\\end{split}\n \\end{equation}\n\n\n\\begin{theorem}\nIf $u\\in {B}^{k+1}(\\Omega)$, there exist $\\|\\bar \\omega_i\\|\\le 1$, $|b_i|\\le T + k+1$ such that\n\\begin{equation}\\label{d+1}\n\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}\\lesssim  N^{-{1\\over 2}-{1\\over d+1}} \\|u\\|_{{B}^{k+1}(\\Omega)}\n\\end{equation}\nwith\n\\begin{equation}\nu_{N}(x)=\\sum_{i=1}^{N} \\beta_i b^k\\left(\\bar \\omega_i\\cdot x+b_i\\right) .\n\\end{equation} \n\\end{theorem}\n\\begin{proof}\nWe write \\eqref{integral_representation} as follows\n$$\n\\displaystyle u(x)= \\int_{\\mathbb{R}^d}\\int_\\mathbb{R}\ng(x, b, \\omega)\\rho(b,\\omega) dbd\\omega\n$$\nwith \n$$ \n\\hat{u}(\\omega) = e^{-i\\theta(\\omega)} | \\hat{u}(\\omega)|,\\quad \\tilde \\theta(\\omega)=\\theta(\\omega) + a_\\omega(b+{k+1\\over 2})\n$$ and \n\\begin{equation}\\label{eq:g}\ng(x, b, \\omega) = \\sigma\\left({\\bar \\omega}\\cdot x+b\\right)sgn(\\cos \\tilde\\theta(\\omega)),\n\\end{equation}\n\\begin{equation}\\label{eq:rho}\n\\rho(b,\\omega) = \\frac{1}{(2\\pi)^d}\\left({a_\\omega\\over 2}\\right)^{k+1}| \\hat{u}(\\omega)||\\cos \\tilde\\theta(\\omega)|.\n\\end{equation} \nNote that\n\\begin{equation}\n\\|\\bar\\omega\\|\\le 1, \\quad |b|\\le T+k+1.\n\\end{equation} \nLet \n$$\nG=\\{(\\omega, b): \\omega\\in \\mathbb{R}^d,\\ |b|\\le T+k+1\\}, \\ \\tilde G=\\{(\\bar \\omega, b): \\|\\bar \\omega\\| \\le 1,\\ |b|\\le T+k+1\\}.\n$$\nFor any positive integer $n$, divide $\\tilde  G$ into $\\tilde  M(\\tilde  M\\le {n\\over 2})$   nonoverlapping subdomains, say \n$\\tilde  G=\\tilde  G_1\\cup \\tilde  G_2\\cup \\cdots \\cup\\tilde  G_{\\tilde M}$, such that\n\\begin{equation}\n|b-b'|\\lesssim n^{-{1\\over d+1}},\\quad |\\bar\\omega - \\bar\\omega'|\\lesssim  n^{-{1\\over d+1}}, \\quad (\\bar\\omega, b),\\ (\\bar\\omega', b')\\in \\tilde G_i,\\ 1\\le i\\le \\tilde M.\n\\end{equation} \nDefine $M=2\\tilde  M$ and for $1\\le i\\le \\tilde M$,\n$$\nG_i = \\{(\\omega, b): (\\bar \\omega, b)\\in \\tilde  G_i, \\ \\cos \\tilde\\theta(\\omega)\\ge 0\\},\\ \nG_{\\tilde  M+i} = \\{(\\omega, b): (\\bar \\omega, b)\\in \\tilde  G_i, \\ \\cos \\tilde\\theta(\\omega)\\le 0\\}.\n$$\nThus, $G=G_1\\cup G_2\\cup \\cdots \\cup G_M$ with $\\tilde  G_i\\cap \\tilde G_j=\\varnothing$ if $i\\neq j$, and \n\\begin{equation}\n|b-b'|\\lesssim n^{-{1\\over d+1}},\\quad |\\bar\\omega - \\bar\\omega'|\\lesssim  n^{-{1\\over d+1}}, \\quad sgn(\\cos \\tilde\\theta(\\omega))=sgn(\\cos\\tilde \\theta(\\omega')).\n\\end{equation} \nLet $n_i=\\lceil \\lambda(G_i)n\\rceil$, $N=\\displaystyle \\sum_{i=1}^M n_i$ and\n\\begin{equation}\nu_{N}(x)=\\|\\rho\\|_{L^1(G)}\\sum_{i=1}^{M} \\frac{\\lambda(G_{i})}{n_{i}} \\sum_{j=1}^{n_{i}}g(x,\\theta_{i,j}).\n\\end{equation}\nIt holds that\n\\begin{equation}\\label{eq:sum}\n\\begin{split}\n\\mathbb{E}\\left(\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}^{2}\\right)\\le&\n\\|\\rho\\|_{L^1(G)}\\sum_{i=1}^{M}  \\frac{\\lambda^2(G_i)}{n_{i}}  \\sup_{\\theta_{i},\\theta_{i}'\\in G_i} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)}\n \\end{split}\n\\end{equation}\nwith $\\theta=(b, \\omega)$. \nFor any $(b, \\omega)\\in G_i$, $1\\le i\\le M$, if $k\\ge m+1$,\n\\begin{equation}\n|g(x,\\theta) - g(x,\\theta')| \\lesssim |b-b'| + |\\omega - \\omega'| \\lesssim   n^{-{1\\over d+1}}\n\\end{equation}\nThus,\n\\begin{equation}\n \\sum_{i=1}^{M}  \\frac{\\lambda^2(G_i)}{n_{i}}  \\sup_{\\theta_{i},\\theta_{i}'\\in G_i} \\| g(x,\\theta_i) - g(x,\\theta_i')\\|^2_{H^m(\\Omega)}  \n \\lesssim  n^{-{2\\over d+1}} |\\Omega|.\n\\end{equation}\nThus,\n\\begin{equation}\\label{eq:}\n\\begin{split}\n\\mathbb{E}\\left(\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}^{2}\\right)\\lesssim&   n^{-1-{2\\over d+1}} |\\Omega|\\|\\rho\\|_{L^1(G)}.\n \\end{split}\n\\end{equation}\nSince $a\\le \\|\\omega\\|+5\\pi$, \n$$\n\\|\\rho\\|_{L^1(G)}\\lesssim \\int_G (\\|\\omega\\| + 1)^{k+1}|\\hat u(\\omega)|d\\omega db \\lesssim \\|u\\|_{B^{k+1}(\\Omega)}.\n$$\nNote that $n\\le N\\le 2n$. Thus, there exist $\\omega_i\\in \\mathbb{R}^d$, $\\beta_i$, $b_i\\in \\mathbb{R}$ such that\n\\begin{equation}\n\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}\\lesssim  N^{-{1\\over 2}-{1\\over d+1}} \\|u\\|_{B^{k+1}(\\Omega)},\n\\end{equation}\nwhich completes the proof.\n\\end{proof}\n\nThe above analysis can also be applied to more general activation functions with compact support. \n\\begin{theorem}\nSuppose that $\\sigma\\in W^{m+1,\\infty}(\\mathbb{R})$ that has a compact\nsupport. If for any $a>0$, there exists $\\tilde a>0$ such that\n\\begin{equation}\n\\tilde a\\gtrsim a,\\quad  |\\hat\\sigma(\\tilde a)|\\gtrsim a^{-\\ell},\n\\end{equation}\nand  $u\\in {B}^{\\ell}(\\Omega)$, then, there exist $\\omega_i\\in \\mathbb{R}^d$ and $b_i\\in \\mathbb{R}$ such that\n\\begin{equation}\n\\left\\|u - u_{N}\\right\\|_{H^{m}(\\Omega)}\\lesssim  N^{-{1\\over 2}-{1\\over d+1}} \\|u\\|_{B^{\\ell}(\\Omega)},\n\\end{equation}\nwhere\n\\begin{equation}\nu_{N}(x)=\\sum_{i=1}^{N} \\beta_i \\sigma\\left(\\bar \\omega_i\\cdot x+b_i\\right) .\n\\end{equation} \n\\end{theorem}\n\n\\fi\n", "meta": {"hexsha": "58427f6894bbd0b34709edb75e6857155b20bbf8", "size": 12739, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/BsplineApprox.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/BsplineApprox.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/BsplineApprox.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.1821192053, "max_line_length": 273, "alphanum_fraction": 0.6518565037, "num_tokens": 5197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8757869916479466, "lm_q1q2_score": 0.7756245135892648}}
{"text": "\\section{The determinant of a triangular matrix}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Calculate the determinant of an upper or lower triangular\n    matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nThere is a certain type of matrix for which finding the determinant is\na very simple procedure: a triangular matrix.\n\n\\begin{definition}{Triangular matrices}{triangular-matrices}\n  An square matrix $A$ is \\textbf{upper triangular}%\n  \\index{matrix!upper triangular}%\n  \\index{matrix!triangular}%\n  \\index{upper triangular matrix}%\n  \\index{triangular matrix} if $a_{ij}=0$ whenever $i>j$. In other\n  words, a matrix is upper triangular if the entries below the main\n  diagonal are $0$. Thus, an upper triangular matrix looks as follows,\n  where $\\ast$ refers to any non-zero number:\n  \\begin{equation*}\n    \\begin{mymatrix}{ccccc}\n      \\ast & \\ast & \\cdots & \\ast & \\ast \\\\\n      0 & \\ast & \\cdots & \\ast & \\ast \\\\\n      \\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n      0 & 0 & \\cdots & \\ast & \\ast \\\\\n      0 & 0 & \\cdots & 0 & \\ast \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Similarly, a square matrix is \\textbf{lower triangular}%\n  \\index{matrix!lower triangular}%\n  \\index{lower triangular matrix} if all entries above the main\n  diagonal%\n  \\index{diagonal of a matrix}%\n  \\index{matrix!diagonal of} are $0$.\n\\end{definition}\n\nThe following theorem provides a useful way to calculate the\ndeterminant of a triangular matrix.\n\n\\begin{theorem}{Determinant of a triangular matrix}{determinant-of-triangular-matrix}\n  Let $A$ be an upper or lower triangular matrix. Then $\\det(A)$ is\n  equal to the product of the entries on the main diagonal. Written as\n  a formula, we have\n  \\begin{equation*}\n    \\det(A) = a_{11}\\,a_{22}\\,\\cdots\\,a_{nn}.\n  \\end{equation*}\n\\end{theorem}\n\n\\begin{example}{Determinant of a triangular matrix}{determinant-of-triangular-matrix}\n  Compute $\\det(A)$, where\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrrr}\n      1 & 2 & 3 & 16 \\\\\n      0 & 2 & 6 & -7 \\\\\n      0 & 0 & 3 & 33 \\\\\n      0 & 0 & 0 & -1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  By Theorem~\\ref{thm:determinant-of-triangular-matrix}, it suffices\n  to take the product of the elements on the main diagonal. Thus\n  \\begin{equation*}\n    \\det (A) ~=~ 1\\cdot 2\\cdot 3\\cdot (-1) ~=~ -6.\n  \\end{equation*}\n\\end{solution}\n\nFor comparison, let us compute the determinant without\nTheorem~\\ref{thm:determinant-of-triangular-matrix}, i.e., by using\ncofactor expansion. If we expand the determinant along the first\ncolumn, we get:\n\\begin{equation*}\n  \\det (A)\n  ~=~\n  1 \\begin{absmatrix}{rrr}\n      2 & 6 & -7 \\\\\n      0 & 3 & 33 \\\\\n      0 & 0 & -1\n    \\end{absmatrix}\n  - 0 \\begin{absmatrix}{rrr}\n      2 & 3 & 16 \\\\\n      0 & 3 & 33 \\\\\n      0 & 0 & -1\n    \\end{absmatrix}\n  + 0 \\begin{absmatrix}{rrr}\n      2 & 3 & 16 \\\\\n      2 & 6 & -7 \\\\\n      0 & 0 & -1\n    \\end{absmatrix}\n  - 0 \\begin{absmatrix}{rrr}\n      2 & 3 & 16 \\\\\n      2 & 6 & -7 \\\\\n      0 & 3 & 33 \\\\\n    \\end{absmatrix}.\n\\end{equation*}\nThe only non-zero term in the expansion is\n\\begin{equation*}\n  1\\begin{absmatrix}{rrr}\n    2 & 6 & -7 \\\\\n    0 & 3 & 33 \\\\\n    0 & 0 & -1\n  \\end{absmatrix}.\n\\end{equation*}\nWe can in turns expand this $3\\times 3$ determinant by the cofactor\nmethod along the first column:\n\\begin{equation*}\n  \\begin{absmatrix}{rrr}\n    2 & 6 & -7 \\\\\n    0 & 3 & 33 \\\\\n    0 & 0 & -1\n  \\end{absmatrix}\n  ~=~ 2 \\begin{absmatrix}{rr}\n    3 & 33 \\\\\n    0 & -1\n  \\end{absmatrix}\n  - 0 \\begin{absmatrix}{rr}\n    6 & -7 \\\\\n    0 & -1\n  \\end{absmatrix}\n  + 0 \\begin{absmatrix}{rr}\n    6 & -7 \\\\\n    3 & 33 \\\\\n  \\end{absmatrix}.\n\\end{equation*}\nAgain, the only non-zero term is the first term. In summary,\n\\begin{equation*}\n  \\det (A)\n  ~=~\n  \\begin{absmatrix}{rrrr}\n    1 & 2 & 3 & 16 \\\\\n    0 & 2 & 6 & -7 \\\\\n    0 & 0 & 3 & 33 \\\\\n    0 & 0 & 0 & -1\n  \\end{absmatrix}\n  ~=~ 1 \\begin{absmatrix}{rrr}\n    2 & 6 & -7 \\\\\n    0 & 3 & 33 \\\\\n    0 & 0 & -1\n  \\end{absmatrix}\n  ~=~ 1\\cdot 2\n  \\begin{absmatrix}{rr}\n    3 & 33 \\\\\n    0 & -1\n  \\end{absmatrix}\n  ~=~ 1\\cdot 2\\cdot 3\\cdot (-1)\n  ~=~ -6.\n\\end{equation*}\nOf course this is just the same as the product of the diagonal entries\nof $A$, which is the point of\nTheorem~\\ref{thm:determinant-of-triangular-matrix}.\n", "meta": {"hexsha": "cb993ec0de8f60fccbd026de93d709328c5d0a96", "size": 4258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-Triangular.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-Triangular.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-Triangular.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.6493506494, "max_line_length": 85, "alphanum_fraction": 0.6110850164, "num_tokens": 1540, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.9124361640485893, "lm_q1q2_score": 0.7755444460041073}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let $\\Poly_3$ be the vector space of polynomials of degree at most\n  3. Determine which of the following are bases for this vector space.\n\n  \\begin{enumerate}\n  \\item $\\set{x^3+1,~x^2+x,~2x^3+x^2,~2x^3-x^2-3x+1}$.\n  \\item $\\set{x+1,~x^3+x^2+2x,~x^2+x,~x^3+x^2+x}$.\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item\n      Yes. Suppose\n      \\begin{equation*}\n        c_1(x^3+1) + c_2(x^2+x) + c_3(2x^3+x^2) +\n        c_4(2x^3-x^2-3x+1) = 0.\n      \\end{equation*}\n      Then collect equal powers of $x$:\n      \\begin{equation*}\n        (c_1+2c_3+2c_4)x^3 + (c_2+c_3-c_4)x^2 +\n        (c_2-3c_4)x + (c_1+c_4) = 0.\n      \\end{equation*}\n      Does the system\n      \\begin{equation*}\n        \\begin{array}{c}\n          c_1 + 2c_3 + 2c_4 = 0 \\\\\n          c_2 + c_3 - c_4 = 0 \\\\\n          c_2 - 3c_4 = 0 \\\\\n          c_1 + c_4 = 0\n        \\end{array}\n      \\end{equation*}\n      have a non-trivial solution? The only solution is\n      \\begin{equation*}\n        c_1 = 0,\\quad\n        c_2 = 0,\\quad\n        c_3 = 0,\\quad\n        c_4 = 0,\n      \\end{equation*}\n      and therefore, the polynomials are linearly independent. Since\n      there are $4$ linearly independent polynomials in a\n      $4$-dimensional space, they form a basis.\n    \\item Yes.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine whether the following is a basis for $\\Poly_2$, the\n  vector space of polynomials of degree at most $2$.\n  \\begin{equation*}\n    \\set{x^2+x+1,~2x^2+2x+1,~x+1}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Find a basis for the following subspace of $\\Poly_2$:\n  \\begin{equation*}\n    W=\\sspan\\set{1+x+x^2,~1+2x,~1+5x-3x^2}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Find a basis for the following subspace of $\\Poly_3$:\n  \\begin{equation*}\n    W = \\sspan\\set{\n      1+x-x^2+x^3,~1+2x+3x^3,~-1+3x+5x^2+7x^3,~1+6x+4x^2+11x^3}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Extend the following linearly independent set of polynomials to a\n  basis of $\\Poly_3$:\n  \\begin{equation*}\n    \\set{x^3+x^2-x-1,~3x^3+2x^2+2x-1}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Let $V$ be a $5$-dimensional vector space.\n  If you have $5$ linearly independent vectors in $V$, can you\n  conclude that the vectors span $V$?\n  \\begin{sol}\n    Yes, because the set of $5$ linearly independent vectors can be\n    extended to a basis $B$ of $V$. But since $V$ is $5$-dimensional,\n    $B$ has only $5$ elements, which must be the original $5$ vectors.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $V$ be a $5$-dimensional vector space.  If you have $6$ vectors\n  in $V$, is it possible that they are linearly independent? Explain.\n  \\begin{sol}\n    No. Since $V$ has a spanning set of size $5$, the $6$ vectors\n    cannot be linearly independent by the Exchange Lemma.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find a basis for the vector space of symmetric $3\\times 3$-matrices%\n  \\index{matrix!symmetric}%\n  \\index{symmetric matrix}, i.e., matrices satisfying $A=A^T$.\n  What is the dimension of this space?\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subspace of $\\Poly_3$ (over the field $\\R$)\n  consisting of all polynomials $p(x)$ that satisfy $p(3)=0$.\n  Find a basis for $W$. What is the dimension of $W$?\n\\end{ex}\n\n\\begin{ex}\n  Find a basis for\n  $U=\\set{A\\in\\Mat_{2,2} ~\\left\\vert~ A\\begin{mysmallmatrix}{rr} 1 &\n        0 \\\\ 1 & -1 \\end{mysmallmatrix} = \\begin{mysmallmatrix}{rr} 1\n        & 1 \\\\ 0 & -1 \\end{mysmallmatrix} A \\right.}$.  What is the\n  dimension of $U$?\n\\end{ex}\n\n\\begin{ex}\n  \\begin{enumerate}\n  \\item Let $k$ be a positive integer, let $W_k\\subseteq\\Seq_K$ be the\n    subspace consisting of all sequences that are periodic%\n    \\index{periodic sequence}%\n    \\index{sequence!periodic} with period $k$ (see\n    Exercise~\\ref{ex:periodic}). Find a basis for $W_k$. What is its\n    dimension?\n  \\item More difficult: find a basis for the infinite-dimensional\n    vector space consisting of all periodic sequences of all periods.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item In case $k=3$, the following sequences form a basis for\n      $W_3$:\n      \\begin{equation*}\n        \\begin{array}{l}\n          (1,0,0,1,0,0,1,0,0,1,\\ldots), \\\\\n          (0,1,0,0,1,0,0,1,0,0,\\ldots), \\\\\n          (0,0,1,0,0,1,0,0,1,0,\\ldots). \\\\\n        \\end{array}\n      \\end{equation*}\n      Therefore, $W_3$ is a 3-dimensional space. For general $k$,\n      the situation is analogous and the dimension of $W_k$ is $k$.\n    \\item Let $U$ be the set of all periodic sequences of all\n      periods. We can find an (infinite) spanning set for $U$ by\n      taking all the basis vectors for all of the spaces $W_k$:\n      \\begin{equation*}\n        \\begin{array}{ll}\n          (1,1,1,1,1,1,1,1,1,1,\\ldots) & \\mbox{(period $1$)},\\\\[1ex]\n          (1,0,1,0,1,0,1,0,1,0,\\ldots) & \\mbox{(period $2$)}, \\\\\n          (0,1,0,1,0,1,0,1,0,1,\\ldots) & \\mbox{(period $2$)},\\\\[1ex]\n          (1,0,0,1,0,0,1,0,0,1,\\ldots) & \\mbox{(period $3$)}, \\\\\n          (0,1,0,0,1,0,0,1,0,0,\\ldots) & \\mbox{(period $3$)}, \\\\\n          (0,0,1,0,0,1,0,0,1,0,\\ldots) & \\mbox{(period $3$)},\\\\[1ex]\n          (1,0,0,0,1,0,0,0,1,0,\\ldots) & \\mbox{(period $4$)}, \\\\\n          (0,1,0,0,0,1,0,0,0,1,\\ldots) & \\mbox{(period $4$)}, \\\\\n          (0,0,1,0,0,0,1,0,0,0,\\ldots) & \\mbox{(period $4$)}, \\\\\n          (0,0,0,1,0,0,0,1,0,0,\\ldots) & \\mbox{(period $4$)}, \\\\\n        \\end{array}\n      \\end{equation*}\n      and so on. However, these sequences are not linearly\n      independent. For example, we can obtain the sequence\n      $(1,0,1,0,1,0,1,0,\\ldots)$ of period $2$ as a linear combination\n      of two sequences of period $4$, namely\n      $(1,0,0,0,1,0,0,0,\\ldots)$ and $(0,0,1,0,0,0,1,0,\\ldots)$. By\n      Proposition~\\ref{prop:basis-from-spanning}, we know that it is\n      possible to shrink the above spanning set to a basis by removing\n      certain sequences. How exactly to do this is an interesting\n      question. One way to construct a basis is to keep exactly those\n      sequences of period $k$ that start with $\\ell$ zeros, where\n      $\\gcd(\\ell,k)=1$. Proving that this really works is an\n      interesting project.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $K=\\Q$, the field of rational numbers. Consider vectors of the\n  form $a+b\\sqrt{2}$ where $a,b$ are rational numbers. Show that this\n  collection of vectors is a vector space over $\\Q$ and give a basis\n  for this vector space. What is its dimension?\n  \\begin{sol}\n    When we add two number of the form $a+b\\sqrt{2}$, we get another\n    number of the same form. When we multiply a number of the form\n    $a+b\\sqrt{2}$ by a (rational) scalar, we get another number of the\n    same form. Also, $0=0+0\\sqrt{2}$ is of the required form. The 8\n    axioms of a vector space are satisfied because all of them are\n    laws of the arithmetic of real numbers. A basis is\n    $\\set{1,\\sqrt{2}}$. By definition, the span of these gives the\n    collection of vectors. To prove that they are linearly\n    independent, assume $a+b\\sqrt{2}=0$, where $a,b$ are rational\n    numbers. If $b\\neq 0$, then $\\sqrt{2}=-\\frac{a}{b}$, which cannot\n    happen because $\\sqrt{2}$ is irrational. If $a\\neq 0$, then\n    $\\frac{1}{\\sqrt{2}}=-\\frac{b}{a}$, which again cannot happen since\n    $\\frac{1}{\\sqrt{2}}$ is irrational. Hence both $a,b=0$. Therefore,\n    $1$ and $\\sqrt{2}$ are linearly independent over the rational\n    numbers, and form a basis. The dimension of the space is $2$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "d869b11830fa0b3ab15ee5296479aed7f2cc3314", "size": 7460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/VectorSpaces-Basis.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/VectorSpaces-Basis.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/VectorSpaces-Basis.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 37.1144278607, "max_line_length": 70, "alphanum_fraction": 0.6095174263, "num_tokens": 2760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818987, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.7754853522462098}}
{"text": "\\section{Column space, row space, and null space of a matrix}\n\\label{sec:null-space}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find a basis for the column space, row space, and null space\n    of a matrix.\n  \\item Find the rank and nullity of a matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nThere are three important spaces we can associate to a matrix. They\nare called the column space, row space, and null space, and are\ndefined as follows.\n\n\\begin{definition}{Column space, row space, null space}{row-column-space}\n  Let $A$ be an $m\\times n$-matrix.  The \\textbf{column space}%\n  \\index{column space}%\n  \\index{matrix!column space} of $A$, written $\\col(A)$, is the span\n  of the columns. The \\textbf{row space}%\n  \\index{row space}%\n  \\index{matrix!row space} of $A$, written $\\row(A)$, is the span of\n  the rows.  The \\textbf{null space}%\n  \\index{null space}%\n  \\index{matrix!null space} of $A$, written $\\nullspace(A)$, is the\n  set\n  \\begin{equation*}\n    \\nullspace(A) =\\set{\\vect{x} \\mid A \\vect{x} =\\vect{0}}.\n  \\end{equation*}\n\\end{definition}\n\nNote that the column space is a subspace of $\\R^m$ and the null space\nis a subspace of $\\R^n$. The row space, on the other hand, is a set of\nrow vectors. It can be regarded as a subspace of $\\R^n$, but only if\nwe regard $\\R^n$ as the set of $n$-dimensional row vectors (and not\ncolumn vectors, as usual).\n\nBefore we give an example, recall that two matrices are called\n\\textbf{row equivalent}%\n\\index{matrix!row equivalence}%\n\\index{row equivalence} if one can be obtained from the other by\nperforming a sequence of elementary row operations. The point of\nelementary row operations is that they do not affect the row space or\nthe null space of the matrix. (They do, however, affect the column\nspace). The following proposition makes this more precise.\n\n\\begin{proposition}{Effect of row operations}{row-operations-row-space}\n  Let $A$ and $B$ be row equivalent matrices. Then $\\row(A)=\\row(B)$\n  and $\\nullspace(A)=\\nullspace(B)$.\n\\end{proposition}\n\n\\begin{proof}\n  The fact that elementary row operations do not change the null space\n  is a special case of\n  Theorem~\\ref{thm:elementary-operations-and-solutions}, applied to a\n  homogeneous system. To prove that they do not change the row space\n  is also easy; we just need to look at each kind of elementary row\n  operation. For example, adding a multiple of one row to another\n  clearly does not change the span of the rows.\n\\end{proof}\n\n\\begin{example}{Basis of column space, row space, and null space}{basis-column-row-null}\n  Find a basis for the column space, row space, and null space of the\n  matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{rrrrr}\n      1 & 2 & 1 & 3 & 2 \\\\\n      1 & 3 & 6 & 0 & 2 \\\\\n      3 & 7 & 8 & 6 & 6 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The column space of $A$ is the span of the columns of $A$, i.e.,\n  \\begin{equation*}\n    \\col(A) = \\sspan\\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 7 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 1 \\\\ 6 \\\\ 8 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 3 \\\\ 0 \\\\ 6 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ 6 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  To find a basis for the column space, we use the casting-out\n  algorithm.  The {\\rref} of $A$ is\n  \\begin{equation}\\label{eqn:basis-column-row-null-1}\n    \\begin{mymatrix}{rrrrr}\n      \\circled{1} & 0 & -9 & 9 & 2 \\\\\n      0 & \\circled{1} & 5 & -3 & 0 \\\\\n      0 & 0 & 0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation}\n  Note that the first two columns of the {\\rref} are pivot\n  columns. Therefore, by the casting-out algorithm, the first two\n  columns of $A$ form a basis for the column space. Thus, the\n  following is a basis for the column space:\n  \\begin{equation*}\n    \\mbox{Basis of $\\col(A)$:} \\quad\n    \\set{\n      \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{r} 2 \\\\ 3 \\\\ 7 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  The rows space of $A$ is the span of the rows of $A$, i.e.,\n  \\begin{equation*}\n    \\row(A) =\n    \\sspan \\set{\n      \\begin{mymatrix}{rrrrr}\n        1 & 2 & 1 & 3 & 2 \\\\\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rrrrr}\n      1 & 3 & 6 & 0 & 2 \\\\\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rrrrr}\n      3 & 7 & 8 & 6 & 6\n      \\end{mymatrix}\n    }\n  \\end{equation*}\n  We could find a basis of the row space by writing all three rows as\n  column vectors and using the casting-out algorithm. However, there\n  is an easier way. By\n  Proposition~\\ref{prop:row-operations-row-space}, the row space of\n  $A$ is equal to the row space of the {\\rref}\n  {\\eqref{eqn:basis-column-row-null-1}}. Moreover, the non-zero rows\n  of the {\\rref} are clearly linearly independent (no non-zero row can\n  be a linear combination of other rows below it, because each\n  non-zero row has a pivot entry). Therefore, the non-zero rows of the\n  {\\rref} form a basis of the row space.\n  \\begin{equation*}\n    \\mbox{Basis of $\\row(A)$:} \\quad\n    \\set{\n      \\begin{mymatrix}{rrrrr}\n        1 & 0 & -9 & 9 & 2 \\\\\n      \\end{mymatrix},~\n      \\begin{mymatrix}{rrrrr}\n        0 & 1 & 5 & -3 & 0 \\\\\n      \\end{mymatrix}\n    }.\n  \\end{equation*}\n  Finally, the null space of $A$ is just the solution space of the\n  homogeneous system $A\\vect{x}=\\vect{0}$. Thus, finding a basis of\n  the null space is the same as finding a set of basic solutions. From\n  the {\\rref}, we can easily find the general solution of\n  $A\\vect{x}=\\vect{0}$, using three parameters $r$, $s$, $t$\n  corresponding to the three non-pivot columns of\n  {\\eqref{eqn:basis-column-row-null-1}}. The general solution is:\n  \\begin{equation*}\n    \\vect{x} =\n    r \\begin{mymatrix}{r} 9 \\\\ -5 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix}\n    + s \\begin{mymatrix}{r} -9 \\\\ 3 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n    + t \\begin{mymatrix}{r} -2 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, the following is a basis of the null space:\n  \\begin{equation*}\n    \\mbox{Basis of $\\nullspace(A)$:} \\quad\n    \\set{\n    \\begin{mymatrix}{r} 9 \\\\ -5 \\\\ 1 \\\\ 0 \\\\ 0 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -9 \\\\ 3 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix},~\n    \\begin{mymatrix}{r} -2 \\\\ 0 \\\\ 0 \\\\ 0 \\\\ 1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n\\end{solution}\n\nAs the example shows, all three bases, for the column space, the row\nspace, and the null space of $A$, can be easily determined from the\n{\\rref}. In the next proposition, we use this information to determine\nthe dimensions of these three spaces. Recall from\nDefinition~\\ref{def:rank} that the \\textbf{rank}%\n\\index{rank}%\n\\index{matrix!rank} of a matrix is equal to the number of pivot\nentries of its {\\rref}.\n\n\\begin{proposition}{Dimension of column space, row space, and null space}{dimension-column-row-null}\n  Let $A$ be an $m\\times n$-matrix. Then the dimensions of the column\n  space, row space, and null space of $A$ are as follows:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      \\dim(\\col(A)) &=& \\rank(A), \\\\\n      \\dim(\\row(A)) &=& \\rank(A), \\\\\n      \\dim(\\nullspace(A)) &=& n-\\rank(A). \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{proposition}\n\n\\begin{proof}\n  Let $r=\\rank(A)$.  Following the same method as in\n  Example~\\ref{exa:basis-column-row-null}, we can use the casting-out\n  algorithm to find a basis for the column space. Since the {\\rref} of\n  $A$ has $r$ pivot columns, the basis has $r$ elements, and therefore\n  $\\dim(\\col(A))=r$. Also, the {\\rref} has $r$ non-zero rows (since\n  each non-zero row contains exactly one pivot entry). These form a\n  basis of the row space, and therefore $\\dim(\\row(A))=r$. Finally,\n  the dimension of the null space is equal to the number of parameters\n  in the general solution of the system of equations\n  $A\\vect{x}=\\vect{0}$. There is one parameter for each non-pivot\n  column, and since $A$ has $n$ columns and $r$ pivot columns, it\n  follows that $\\dim(\\nullspace(A)) = n-r$.\n\\end{proof}\n\nAmong other things, the proposition states that the ``row rank'' of a\nmatrix (the dimension of its row space) is always equal to the\n``column rank'' (the dimension of the column space). This fact is not\nat all obvious when one first considers the definition of a matrix. It\nis often called the \\textbf{rank theorem}%\n\\index{rank theorem}%\n\\index{matrix!rank theorem} and is one of the deep and mysterious\nfacts of linear algebra. It means, for example, that if we do\nelementary column operations instead of elementary row operations, we\nend up with exactly the same number of pivots. Since the ``row rank''\nand ``column rank'' are always equal, we are justified in simply\ncalling this quantity the ``rank'' of the matrix.\n\nThere is also a name for the dimension of the null space. It is called\nthe \\textbf{nullity}%\n\\index{nullity}%\n\\index{matrix!nullity} of the matrix, and is written $\\nullity(A)$.\nThe last part of Proposition~\\ref{prop:dimension-column-row-null} is\nalso called the \\textbf{rank-nullity theorem}%\n\\index{rank-nullity theorem}%\n\\index{matrix!rank-nullity theorem}, and is often written in the form\n\\begin{equation*}\n  \\rank(A) + \\nullity(A) = n.\n\\end{equation*}\n\n\\begin{example}{Rank and nullity}{rank-nullity}\n  Find the rank and nullity of the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrrrrr}\n      1 & 2 & 1 & 3 & 2 \\\\\n      1 & 3 & 6 & 0 & 2 \\\\\n      1 & 2 & 1 & 3 & 2 \\\\\n      1 & 3 & 2 & 4 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The {\\rref} of $A$ is\n  \\begin{equation*}\n    \\def\\arraystretch{1.4}\n    \\begin{mymatrix}{rrrrrr}\n      1 & 0 & 0 & 0 & \\frac{13}{2} \\\\\n      0 & 1 & 0 & 2 & -\\frac{5}{2} \\\\\n      0 & 0 & 1 & -1 & \\frac{1}{2} \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix},\n  \\end{equation*}\n  and so $\\rank(A)=3$ and $\\nullity(A) = 5-3 = 2$.\n\\end{solution}\n\nWe conclude this section with two useful theorems about matrices.\n\n\\begin{theorem}{}{equivalent-rank1}\n  The following are equivalent for an $m\\times n$-matrix $A$.\n  \\begin{enumerate}\n  \\item $\\rank(A)=n$.\n  \\item $\\row(A)=\\R^n$, i.e., the rows of $A$ span $\\R^n$.\n  \\item The columns of $A$ are linearly independent in $\\R^m$.\n  \\item The $n\\times n$-matrix $A^TA$ is invertible.\n  \\item $A$ is left invertible, i.e., there exists an\n    $n\\times m$-matrix $B$ such that $BA=I$.\n  \\item The system $A\\vect{x}=\\vect{0}$ has only the trivial solution.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{theorem}{}{equivalent-rank2}\n  The following are equivalent for an $m\\times n$-matrix $A$.\n  \\begin{enumerate}\n  \\item $\\rank(A)=m$.\n  \\item $\\col(A)=\\R^m$, i.e., the columns of $A$ span $\\R^m$.\n  \\item The rows of $A$ are linearly independent in $\\R^n$.\n  \\item The $m\\times m$-matrix $AA^T$ is invertible.\n  \\item $A$ is right invertible, i.e., there exists an\n    $n\\times m$-matrix $B$ such that $AB=I$.\n  \\item The system $A\\vect{x}=\\vect{b}$ is consistent for\n    every $\\vect{b}\\in\\R^m$.\n  \\end{enumerate}\n\\end{theorem}\n", "meta": {"hexsha": "8d6b1027723e9a55860a0c2268f81e9d10bd809e", "size": 10881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SpanIndependenceBasis-ColumnRowNullSpace.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-ColumnRowNullSpace.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-ColumnRowNullSpace.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.7224199288, "max_line_length": 100, "alphanum_fraction": 0.6526054591, "num_tokens": 3652, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8962513821399044, "lm_q1q2_score": 0.7754582860998719}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 4}\n\nShow that there is an algorithm that produces the $k$ smallest elements of an unsorted set of $n$ elements in time $\\mathcal{O}(n + k \\log n)$.\n\nYou have to state the algorithm carefully and prove that it does what it is supposed to do.\nYou need also to prove that the algorithm runs in time $\\mathcal{O}(n + k \\log n)$.\n\n\\subsection*{Solution}\n\nThe desired algorithm \\textsc{Sort-k-Min} which sorts $k$ smallest elements of array $A$ has been proposed below.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Sort-k-Min}}\n\\begin{algorithmic}[1]\n\\State \\textsc{Build-Heap}($A$)\n\\For {$i \\leftarrow 1$ : $k$}\n\\State $F[i] \\leftarrow A[1]$\n\\State \\textsc{Heap-Delete}($A$, $1$)\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\nAs is shown, the objective is achieved by taking advantage of the heap data structure.\nFirst, a min-heap is constructed once from all elements of the array.\nThis would cost a $\\mathcal{O}(n)$ runtime.\nTo get the smallest element, each time the root element will be produced as smallest and then it is removed from the heap using a call to \\textsc{Heap-Delete}($A$, 1).\nRuntime of each iteration of the loop is thus $\\mathcal{O}(\\log n)$.\nTo get the first $k$ elements, the loop should be used $k$ times which results in a total runtime of $\\mathcal{O}(n + k\\log n)$.\n", "meta": {"hexsha": "e6878bfb81c1aef3dbdf232b185c9f8bebf48a04", "size": 1653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/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-cs624-2015s/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-cs624-2015s/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": 45.9166666667, "max_line_length": 167, "alphanum_fraction": 0.6733212341, "num_tokens": 448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8652240791017536, "lm_q1q2_score": 0.775458273758575}}
{"text": "\t\\begin{multicols}{2}\n\n\\subsection{Z-transform}\n\\begin{tabular}{p{7.75cm} p{4.75cm}}\n$\\mathcal{Z} \\left\\{ f_1(t) \\pm f_2(t) \\right\\}=F_1(z)+F_2(z)$ & Addition\\\\\n$\\mathcal{Z} \\left\\{ af(t) \\right\\}= aF(z)$ & Multiplication by a Constant \\\\\n$\\mathcal{Z} \\left\\{ f(t-nT) \\right\\}=z^{-n}F(z)$ & Shifting \\\\\n$\\mathcal{Z} \\left\\{ f(t+kT) \\right\\}=z^{k}F(z)-z^{k}f(0)- \\cdots - z f(kT-T)$ & Shifting (cont'd)\\\\\n$\\mathcal{Z} \\left\\{ e^{\\mp at} f(t) \\right\\}=F(ze^{\\pm at})$ & Complex Translation \\\\\n$\\lim_{k \\rightarrow \\infty} f(kT)= \\lim_{z \\rightarrow 0}F(z)$ & Initial Value Theorem \\\\ \\hline\nIf $(1-z^{-1})F(z)$ has all singularities inside unit disk $|z|=1$, then & Final Value Theorem \\\\\n$\\lim_{k \\rightarrow \\infty} f(kT) = \\lim_{z \\rightarrow 1} (1-z^{-1})F(z)$ & \\\\\n$\\mathcal{Z} \\left\\{ \\frac{\\partial}{\\partial a} f(t,a) \\right\\} = \\frac{\\partial}{\\partial a} F(z,a)$& Partial differentiation\n\\end{tabular}\n\n\\subsection{Sampling Theory}\n\\vspace*{-0.25cm}\n\\begin{align*}\n& \\mathcal{Z} \\left\\{G_1(s)G_2(s)\\right\\}=G_1G_2(z)= G_2G_1(z) \\quad \\text{In General} \\quad G_1(z)G_2(z) \\neq G_1G_2(z)\n\\end{align*}\n\\vspace*{-0.175cm}\n\\begin{minipage}[t]{1\\linewidth}\n\\includegraphics[width=1\\linewidth]{samplerTesting-cropped.pdf}\n\\end{minipage}\n\\begin{align*}\n& G(z) = \\mathcal{Z} \\left\\{\\left(\\frac{1-e^{-s}}{s}\\right) \\left[ \\frac{1}{s+1}\\right] \\left[\\frac{1}{s}\\right] \\right\\} \\rightarrow G_1(z) = (1-z^{-1})\\mathcal{Z} \\left\\{ G_{rest}(s) \\right\\}\n\\end{align*}\n\\begin{minipage}[h]{0.65\\linewidth}\n%\\medbreak\\noindent\\minipage{\\columnwidth}\n\\includegraphics[width=1.05\\linewidth]{sampleEND-cropped.pdf}%\\endminipage\\medbreak\n\\end{minipage}\n\\begin{minipage}[h]{0.35\\linewidth}\n\\[\nG(z) = \\frac{ze^{-1}+(1-ze^{-1})}{(z-1)(z-e^{-1})} \n\\]\n\\end{minipage}\n$$ \\text{ZOH(zero-hold-system)} \\quad \nf^\\ast(t) = \\sum_{k=-\\infty}^\\infty f(kT)\\delta(t-kT)  \\quad \nG_{h}(s)= \\frac{1-e^{-Ts}}{s}\n$$\n\\subsection{Stability Test for Digital Systems}\n\\vspace*{-0.45cm}\n\\begin{align*}\n& P(z) = a_0z^n+a_1z^{n-1} + \\cdots + a_{n-1}z+a_n \\quad G(z)= \\frac{A(z)}{P(z)} \\\\\n& \\text{Stability Condition:} \\quad P(z) \\neq 0 \\quad |z| \\geq 1 \\quad (\\text{Draw Unit Circle to test stability})\\\\\n& \\text{Routh-Stability in Digital Domain: } s = \\frac{z+1}{z-1} \\quad z=\\frac{s+1}{s-1}\n\\end{align*}\n%\\begin{table}\n%\\captionof{Table}{Jury-Marden Table}\n\\textbf{Jury-Marden Table Uses function P of z} \\newline\n%\\vspace*{-0.25cm}\n\\begin{minipage}[t]{1\\linewidth}\n\\begin{minipage}[h]{0.25\\linewidth}\n\\begin{align*}\n& b_k = \\det \\begin{bmatrix}\na_n & a_{n-1-k} \\\\\na_0 & a_{k+1}\n\\end{bmatrix} \\\\\n& k = 0,1,  \\cdots n-1 \\\\\n& c_k = \\det \\begin{bmatrix}\nb_{n-1} & b_{n-2-k} \\\\\nb_0 & b_{k+1}\n\\end{bmatrix} \\\\\n& k = 0,1,  \\cdots n-1 \\\\\n& q_k = \\det \\begin{bmatrix}\np_{3} & p_{2-k} \\\\\np_0 & p_{k+1}\n\\end{bmatrix} \\\\\n& k =0,1,2\n\\end{align*}\n\\end{minipage}\n\\begin{minipage}[h]{0.75\\linewidth}\n\\begin{tabular}{llllllll}\n%\\cline{1-5}\nRow & $z^0$     & $z^1$     & $z^2$     &          & $z^{n-2}$ & $z^{n-1}$ & $z^n$ \\\\ %\\cline{1-5}\n1   & $a_n$     & $a_{n-1}$ & $a_{n-2}$ & $\\cdots$ & $a_2$     & $a_1$     & $a_0$ \\\\\n2   & $a_0$     & $a_1$     & $a_2$     & $\\cdots$ & $a_{n-2}$ & $a_{n-1}$ & $a_n$ \\\\\n3   & $b_{n-1}$ & $b_{n-2}$ & $b_{n-3}$ & $\\cdots$ & $b_1$     & $b_0$     &       \\\\ %\\cline{1-5}\n4   & $b_0$     & $b_1$     & $b_2$     & $\\cdots$ & $b_{n-2}$ & $b_{n-1}$ &       \\\\\n5   & $c_{n-2}$ & $c_{n-3}$ & $c_{n-4}$ & $\\cdots$ & $c_0$     &           &       \\\\\n6   & $c_0$     & $c_1$     & $c_2$     & $\\cdots$ & $c_{n-2}$ &           &      \\\\\n2n-5& $p_3$ & $p_2$ & $p_1$ & $p_0$ & & \\\\\n2n-4& $p_0$ & $p_1$ & $p_2$ & $p_3$ & & \\\\\n2n-3& $q_2$ & $q_1$ & $q_0$ & & & \n\\end{tabular}\n\\end{minipage}\n\\end{minipage}\n\n\\textbf{Necessary and Sufficient Condition for Stability} \\newline\n\\begin{minipage}[h]{0.55\\linewidth}\n\\begin{enumerate}\n\\item $|a_n| < |a_0|$ \n\\item $P(1) > 0$\n\\item \\begin{align*}\nP(-1) & > 0 \\ \\text{for n even } \\\\\n& < 0 \\ \\text{for n odd}\n\\end{align*}\n\\item $b_{n-1}> |b_0|, |c_{n-2}|>|c_0|, \\cdots |q_2| > |q_0|$\n\\end{enumerate}\n\\end{minipage}\n\\begin{minipage}[h]{0.5\\linewidth}\n\\textbf{Special Case n =2} \\newline \n$P(z) =a_0z^2+a_1z+a_2$ \\newline \n\\begin{tabular}{c c c}\n$z^0$ & $z^1$& $z^2$ \\\\\n$a_2$ & $a_1$ & $a_0$\n\\end{tabular} \\newline\n$P(z) \\neq 0$ for $|z| \\geq 1$ if and only if \n\\begin{enumerate}\n\\item $|a_2| < |a_0|$\n\\item $P(1) > 0$\n\\item $P(-1) > 0 \\quad (n=2)$\n\\end{enumerate}\n\\end{minipage}\n\n\\textbf{Root Locus} presents the poles of the closed loop system when the gain K changes from zero to infinity.\n\n\\textbf{Construction of the Root Locus}\n\nOpen loop transfer function\n$ \\displaystyle \\text{KH}\\left( s \\right)G\\left( s \\right) = K\\frac{B(s)}{A(s)}$\n\nm: the order of the \\textbf{open-loop} numerator polynomial.\n\nn: the order of the \\textbf{open-loop} denominator polynomial. $q=n-m$\n\n\\textbf{Rule 1:} number of branches equals the number of poles of the\n open-loop transfer function\n\n\\textbf{Rule 2:} If the total number of poles and zeros of the open-loop\n system to the right of the s-point on the real axis is odd, then this\n point lies on the locus.\n\n\\textbf{Rule 3:} The locus starting point (K=0) are at the open-loop\npoles and the locus ending points (K=$\\infty$) are at the open loop zeros and\nn-m branches terminate at infinity.\n\n\\textbf{Rule 4 and 5:} Slope of asymptotes of root locus as `s' approaches infinity. \\newline Abscissa of the intersection between asymptotes of root locus and real-axis.\n\\[\\sigma  = {\\frac{\\sum\\limits_{i = 1}^n {{p_i}}  - \\sum\\limits_{i = 1}^m {{z_i}} }{q}} \\quad \\theta = \\pm r{\\frac{180}{q}} \\quad \\text{where r=1, 3, 5} \\]\n\n%\\textbf{Rule 5:} \n\n\\textbf{Rule 6:} Break-away and break-in points. From the characteristic\nequation\n\n\\[f\\left( s \\right) = A\\left( s \\right) + KB\\left( s \\right) = 0\\ \\ \\ \\ and\\ \\ \\ \\ K = - \\frac{A\\left( s \\right)}{B\\left( s \\right)}\\]\n\nThe break-away and break-in points can be found from\n\n\\[\\frac{\\text{dK}}{\\text{ds}} = - \\frac{A^{'}\\left( s \\right)B\\left( s \\right) - A\\left( s \\right)B^{'}\\left( s \\right)}{B^{2}\\left( s \\right)} = 0\n\\]\n\n\\textbf{Rule 7:} Angle of departure from complex poles or zeros.\nSubtract from $180^o$ the sum of all angles from all other zeros and poles\nof the open-loop system to the complex pole (or zero) with appropriate signs. \n\n\\[ \\text{Z-transform: Definition} \\quad F(z)=Z[f(t)]-Z[f(kT)]=\\sum_{k=0}^{\\infty}f(kT)z^{-k}\\]\n\\end{multicols}\n\\newpage\n\\begin{multicols}{3}\n\\begin{align*}\n& e^\\ast(\\infty)=\\lim_{z \\rightarrow 1} (1-z^{-1})E(z) \\\\\n& K_p=\\lim_{z \\rightarrow 1} G(z), \\quad e^\\ast (\\infty) = \\frac{1}{1+K_p} \\\\\n& e^\\ast(\\infty) = \\frac{1}{K_v}, \\quad K_v = \\frac{1}{T} \\lim_{z \\rightarrow 1}(z-1) G(z)  \\\\\n& e^\\ast(\\infty) = \\frac{1}{K_a}, \\quad K_a = \\frac{1}{T^2} \\lim_{z \\rightarrow 1}(z-1)^2 G(z)\n\\end{align*}\n\n{\\bf Linear Factor Rule.}  \nFor each factor of $Q$ of the form $(ax+b)^m$, \nthe partial fraction decomposition contains \nthe following sum of $m$ partial fractions:  \n\\[\n\\frac{A_1}{ax+b} + \\frac{A_2}{(ax+b)^2} + \\cdots + \\frac{A_m}{(ax+b)^m},\n\\]\nwhere the $A_i$ are constants to be determined.  \n\n\\medskip\n\\noindent\n{\\bf Quadratic Factor Rule.}  \nFor each factor of $Q$ of the form $(ax^2+bx+c)^m$, \nwhere $ax^2+bx+c$ is an irreducible quadratic, \nthe partial fraction decomposition contains \nthe following sum of $m$ partial fractions:  \n\\[\n\\frac{A_1x+B_1}{ax^2+bx+c} + \\frac{A_2x+B_2}{(ax^2+bx+c)^2} + \\cdots \n  + \\frac{A_mx+B_m}{(ax^2+bx+c)^m},\n\\]\nwhere the $A_i$ and $B_i$ are constants to be determined. \n\\begin{align*}\n& x(k+2)-\\frac{3}{2}x(k+1)+\\frac{1}{2}x(k)=u(k), \\text(x(0)=1,x(1)=5/2) \\\\\n& [z^2X(z)-z^2x(0)-zx(1)]-\\frac{3}{2}(zX(z)-zx(0)]+\\frac{1}{2}X(z)=\\frac{z}{z-1} \\\\\n& [z^2-1.5z+0.5z]X(z)= \\frac{z}{z-1}+z^2+(2.5-1.5)z \\\\\n& X(z) = \\frac{z[1+(z+1)(z-1]}{(z-1)(z-1)(z-0.5)}=\\frac{z^3}{(z-1)^2(z-0.5)} \\\\\n& \\frac{X(z)}{z}=\\frac{z^2}{(z-1)^2(z-0.5)}=\\frac{A_{11}}{(z-1)^2}+\\frac{A_{12}}{z-1}+\\frac{A_{13}}{z-0.5}\n\\end{align*}\nGeometric Sum $\\sum\\limits_{k = -N}^{N} {ar^{k - 1} = a\\frac{1-r^{N}}{{1 - r}}} \\sum_{i=0}^\\infty a^i=\\frac{1}{1-a}$\n\\textbf{Example Partial Fractions}\n\\begin{align*}\n& \\frac{20}{\\left(s+3\\right)\\,\\left(s^2+6\\,s+25\\right)} \\rightarrow \n\\frac{5}{4\\,\\left(s+3\\right)}-\\frac{\\frac{5\\,s}{4}+\\frac{15}{4}}{s^2+6\\,s+25} \\\\\n& \\frac{5\\,z}{4\\,\\left(z-{\\mathrm{e}}^{-3}\\right)}+\\frac{5\\,z\\,{\\mathrm{e}}^3\\,\\left(\\cos\\left(4\\right)-z\\,{\\mathrm{e}}^3\\right)}{4\\,\\left({\\mathrm{e}}^6\\,z^2-2\\,\\cos\\left(4\\right)\\,{\\mathrm{e}}^3\\,z+1\\right)} \\ \\text{Z-table} = \\text{17}\n\\end{align*}\n\\includegraphics[width=1\\linewidth]{NICEPictureRotate.png}\n$\\text{Ch.eqn} =\\Delta P(z)=z^2+(K-4)z+0.8=0$ \\newline\nInputting $z=1 \\text{ and } z=-1$, $K=-0.8-1+4=2.2$, $K=(1)^2+4+0.8=5.8$, for stability $-1<K<1$.\n\\includegraphics[width=1\\linewidth]{OgataTable.png}\n% \\begin{align*}\n% & G_p(s)=\\frac{K}{s(s+3)} \\rightarrow \\frac{1}{s(s+3)}\n% \\end{align*}\n%https://www.wolframalpha.com/input/?i=Plot++(t-2)*heaviside(t-2)-+(t-5)*heaviside(t-5)\n\\includegraphics[width=1\\linewidth]{heavsidePlot.png}\n\\begin{align*}\n& \\frac{1}{3}((t-2)u(t-2)- (t-5)u(t-5)) \\rightarrow \\frac{z^2 + z + 1}{3 (z - 1) z^4} \\\\\n& =\n\\frac{1(z^{-3}+z^{-4}+z^{-5})}{3(1-z^{-1})} \\quad \\frac{1}{3}z^{-3}+\\frac{2}{3}z^{-4}+z^{-5}+z^{-6}+ \\cdots \n\\end{align*}\n\\end{multicols}\n\n\\newpage\n\\begin{sidewaysfigure}\n\\includegraphics[width=0.75\\linewidth]{Table_z_Transforms.pdf}\n\\end{sidewaysfigure}\n%\\end{table}", "meta": {"hexsha": "b1258b1c6e69177870587e8cdabad96bb8c758be", "size": 9311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/ELEC460/elec460Formulas.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/ELEC460/elec460Formulas.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/ELEC460/elec460Formulas.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": 41.7533632287, "max_line_length": 238, "alphanum_fraction": 0.5962839652, "num_tokens": 4118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8962513738264114, "lm_q1q2_score": 0.7754582726773714}}
{"text": "\\subsection{Test 2}\r\n\\begin{enumerate}\r\n\t\\item Consider the function $f(x,y) = x^2 - 2x + y^2 - 4y + 7$.\\\\\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item Find equations for an plot (if possible) the C-level curves of $f$ for $C = 3$ and $C = 1$.\\\\\r\n\t\tWe will try to find the level curve for any $C$ and then plug in 1 and 3.\r\n\t\t\\begin{align*}\r\n\t\t\tx^2 - 2x + y^2 - 4y + 7 &= C\r\n\t\t\tx^2 - 2x + 1 + y^2 - 4y + 4 &= C-2\r\n\t\t\t(x-1)^2 + (y-2)^2 &= C-2\t\t.\r\n\t\t\\end{align*}\r\n\t\tA circle of radius $\\sqrt{C-2}$ centered at $(1,2)$.\r\n\t\tFor $C = 1$, the level curve does not exist because the circle would have a radius of $\\sqrt{2-1} = \\sqrt{-1}$.\r\n\t\tFor $C = 3$, the level curve is \r\n\t\t\\begin{equation*}\r\n\t\t\t(x-1)^2 + (y-2)^2 = 1\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\begin{figure}[H]\r\n\t\t\t\\centering\r\n\t\t\t\\includegraphics[scale=.25]{./additionalMaterials/test2_circle.png}\r\n\t\t\\end{figure}\r\n\t\t\r\n\t\t\\item Compute $\\nabla f$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\nabla f = \\langle f_x, f_y\\rangle = \\langle 2x-2, 2y-4 \\rangle\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item Find the equation of the plane tangent to the surface $z = f(x,y)$ at the point $(x_0, y_0, z_0) = (2,4,7)$.\r\n\t\t\\begin{equation*}\r\n\t\t\t\\vec{n} = \\langle f_x, f_y, -1\\rangle = \\langle 2x-2, 2y-4, -1 \\rangle.\r\n\t\t\\end{equation*}\r\n\t\tAt $(2,4,7)$, $\\vec{n} = \\langle 2, 7, -1 \\rangle$. So, the plane equation is \r\n\t\t\\begin{equation*}\r\n\t\t\t\\langle 2, 7, -1 \\rangle \\cdot \\langle x-2, y-4, z-7 \\rangle = 0\r\n\t\t\\end{equation*}\r\n\t\t\r\n\t\t\\item Perform one iteration of gradient descent on $f(x,y)$ with a learning rate $delta = 1/4$ starting from the point $(x_0,y_0) = (2,4)$.\\\\\r\n\t\t\\begin{align*}\r\n\t\t\t(x_n, y_n) &= (x_{n-1},y_{n-1}) - \\delta\\nabla f \\\\\r\n\t\t\t(x_0, y_0) &= (2,4), \\delta = 1/4 \\text{, and } \\nabla f = \\langle \t2x-2, 2y-4 \\rangle \\\\\r\n\t\t\t(x_1, y_1) &= (2,4) - \\frac{1}{4} \\langle 2(2)-2, 2(4)-4 \\rangle \\\\\r\n\t\t\t&= (3/2, 3)\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\r\n\t\\item Recall that for a differentiable function $f(x,y)$ and the unit vector $\\hat{u} = \\langle a, b \\rangle$, we proved that $D_{\\hat{u}}f = \\nabla f \\cdot \\hat{u}$.\r\n\t\\begin{enumerate}[label=\\alph*.]\r\n\t\t\\item Prove the statement ``The gradient is the direction of steepest ascent'' by showing that the directional derivative $D_{\\hat{u}}f$ is maximized when $\\hat{u}\\parallel\\nabla f$.\r\n\t\t\\begin{equation*}\r\n\t\t\tD_{\\hat{u}}f = \\nabla f \\cdot \\hat{u}=\\norm{\\nabla f}\\norm{\\hat{u}}\\cos{\\theta} = \\norm{\\nabla f}\\cos{\\theta}.\r\n\t\t\\end{equation*}\r\n\t\tThis value is maximized when $\\theta$ is a multiple of $2\\pi$, meaning that the angle between $\\nabla f$ and $\\hat{u}$ is 0. This means that the maximum value of the directional derivative, the direction of steepest ascent, is in the same direction as $\\nabla f$.\\\\\r\n\t\t\t\r\n\t\t\\item State the limit definition of the directional derivative $D_{\\hat{u}}f$. Starting from that definition, prove that $D_{\\hat{u}}f = \\nabla f\\cdot\\hat{u}$.\\\\\r\n\t\t\\begin{align*}\r\n\t\t\tD_{\\hat{u}}f &= \\lim_{h \\to 0}{\\frac{f(x+ah, y+bh)}{h}} \\text{ and} \\hat{u}=\\langle a, b \\rangle \\\\\r\n\t\t\t&= \\lim_{h \\to 0}{\\frac{f(x+ah, y+bh) - f(x+ah, y)}{h} + \\frac{f(x+ah, y) - f(x,y)}{h}} \\\\\r\n\t\t\t&= b\\lim_{h \\to 0}{\\frac{f(x, y+bh) - f(x,y)}{bh}} + a\\lim_{h \\to 0}{\\frac{f(x+ah, y) - f(x,y)}{ah}} \\\\\r\n\t\t\t&= bf_y + af_x = \\langle f_x, f_y \\rangle \\cdot \\langle a, b \\rangle = \\nabla f \\cdot \\hat{u}\r\n\t\t\\end{align*}\r\n\t\\end{enumerate}\r\n\t\r\n\t\\item Use the method of Lagrange Multipliers to find the maximum of the product of two numbers $x$ and $y$ given that $(x,y)$ is a coordinate pair in the 1st quadrant located on the unit circle centered at the origin. Begin by stating the objective function $f(x,y)$ and the constraint equation $g(x,y) = k$.\\\\\r\n\t\\begin{itemize}\r\n\t\t\\item Objective Function: $f(x,y) = xy$\r\n\t\t\\item Constraint Equation: $g(x,y) = x^2 + y^2 = 1$, $x \\geq 0$ and $y \\geq 0$\r\n\t\\end{itemize}\r\n\t\\begin{equation*}\r\n\t\tF(x,y,\\lambda) = xy + \\lambda(1-x^2-y^2)\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\partial F}{\\partial x} = y-2\\lambda x, \\frac{\\partial F}{\\partial y} = x-2\\lambda y \\text{ and } \\frac{\\partial F}{\\partial\\lambda} = 1-x^2-y^2\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\langle y-2\\lambda x, x-2 \\lambda y, 1-x^2-y^2 \\rangle = \\vec{0}\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\ty = 2\\lambda x \\\\\r\n\t\t\tx = 2\\lambda y \\\\\r\n\t\t\tx^2 + y^2 = 1\r\n\t\t\\end{cases} \\implies \\begin{cases}\r\n\t\t\t\\lambda = 1/2 \\\\\r\n\t\t\tx = 1/\\sqrt{2} \\\\\r\n\t\t\ty = 1/\\sqrt{2}\r\n\t\t\\end{cases}.\r\n\t\\end{equation*}\r\n\tSo, the maximum product is $\\frac{1}{\\sqrt{2}} \\cdot \\frac{1}{\\sqrt{2}} = \\frac{1}{2}$ at $\\left(\\frac{1}{\\sqrt{2}}, \\frac{1}{\\sqrt{2}}\\right)$\\\\\r\n\t\r\n\t\\item The function $p(x,y) = \\frac{1}{\\pi}\\exp{\\left(-(x-a)^2 - (y-b)^2\\right)}$ is the probability density function of a bivariate normal distribution with mean $(a,b)$ and standard deviation $\\frac{1}{\\sqrt{2}}$. Show that the global maximum of $p(x,y)$ occurs at $(a,b)$.\r\n\t\\begin{align*}\r\n\t\tp_x &= \\frac{1}{\\pi}(-2(x-a))\\exp{(-((x-a)^2 + (y-b)^2))} \\\\\r\n\t\tp_y &= \\frac{1}{\\pi}(-2(y-b))\\exp{(-((x-a)^2 + (y-b)^2))}\r\n\t\\end{align*}\r\n\t$p_x = 0$ when $x=a$ and $p_y = 0$ when $y=b$\r\n\t$\\implies (a,b)$ is a critical point.\r\n\t\\begin{align*}\r\n\t\tp_{xx} &= \\frac{1}{\\pi}(-2(y-b))\\exp{(-((x-a)^2 + (y-b)^2))} - 2\\exp{(-((x-a)^2 + (y-b)^2))} \\\\\r\n\t\t&= \\frac{1}{\\pi}(4(x-a)^2 - 2)\\exp{(-((x-a)^2 + (y-b)^2))} \\\\\r\n\t\tp_{yy} &= \\frac{1}{\\pi}(4(y-b)^2 - 2)\\exp{(-((x-a)^2 + (y-b)^2))} \\\\\r\n\t\tp_{xy} &= p_{yx} = \\frac{4}{\\pi}(x-a)(y-b)\\exp{(-((x-a)^2 + (y-b)^2))} \\\\\r\n\t\tp_{xx}(a,b) &= \\frac{-2}{\\pi}, p_{yy}(a,b) = \\frac{-2}{\\pi} \\text{ and } p_{xy}(a,b) = p_{yx}(a,b) = 0\r\n\t\\end{align*}\r\n\t\\begin{equation*}\r\n\t\tH(a,b) = \\begin{bmatrix}\r\n\t\t\\frac{-2}{\\pi} & 0 \\\\\r\n\t\t0 & \\frac{-2}{\\pi}\r\n\t\t\\end{bmatrix}\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\det{(H(a,b))} = \\frac{4}{\\pi^2}\r\n\t\\end{equation*}\r\n\t$(a,b)$ is an extrema because $\\det{(H(a,b))} > 0$.\r\n\tSince $f_{xx}(a,b) < 0$ and $f_{yy}(a,b) < 0$, $(a,b)$ is a maximum.\r\n\t$(a,b)$ is a global maximum because $p(x,y)$ is strictly decreasing as you move away from $(a,b)$.\\\\\r\n\t\r\n\t\\item Let the C-level curve of the function $f(x,y)$ be parameterized by the VVF $\\vec{r}(t) = \\langle x(t), y(t) \\rangle$. Use the chain rule to show that $\\nabla f(\\vec{r}(t))\\perp\\vec{r^\\prime}(t)$ for all $t$.\\\\\r\n\tSince $\\vec{r}(t)$ parameterizes a C-level curve of $f$,\r\n\t\\begin{equation*}\r\n\t\tf\\circ\\vec{r}(t) = C.\r\n\t\\end{equation*}\r\n\tWhere $C$ is a constant.\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\mathrm{d}}{\\mathrm{d}t}(f\\circ\\vec{r}(t)) = \\frac{\\mathrm{d}}{\\mathrm{d}t}C\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\frac{\\partial f}{\\partial x}\\frac{\\mathrm{d}x}{\\mathrm{d}t} + \\frac{\\partial f}{\\partial y}\\frac{\\mathrm{d}y}{\\mathrm{d}t} = 0\r\n\t\\end{equation*}\r\n\t\\begin{equation*}\r\n\t\t\\left<\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y}\\right> \\cdot \\left<\\frac{\\mathrm{d}x}{\\mathrm{d}t}, \\frac{\\mathrm{d}y}{\\mathrm{d}t}\\right> = 0\r\n\t\\end{equation*}\r\n\t\\begin{align*}\r\n\t\t\\nabla f(\\vec{r}(t)) &\\cdot \\vec{r^\\prime}(t) = 0 \\\\\r\n\t\t&\\implies \\nabla f(\\vec{r}(t))\\perp\\vec{r^\\prime}(t)\r\n\t\\end{align*}\r\n\\end{enumerate}", "meta": {"hexsha": "eea1e11b1ae62da2f30d8f72f39a3f0f52347f26", "size": 6983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/additionalMaterials/test2.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/additionalMaterials/test2.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/additionalMaterials/test2.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.9708029197, "max_line_length": 312, "alphanum_fraction": 0.5753973937, "num_tokens": 2956, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7754582689632187}}
{"text": "\\chapter{Vector and Tensor Fields}\nSo far, we've created a model of spacetime where each point as an associated set of cordinates $x^\\mu$, and is given its own four-dimensional, real vector space $V$ with basis $\\{\\bm{\\partial}_\\mu\\}$, where $\\bm{\\partial}_\\mu$ is the partial differential operator with respect to the coordinate $x^\\mu$.\nIf we take two points, $P$ and $Q$, and examine arbitrary vectors in their respective vector space, we get vectors $A^\\mu \\bm{\\partial}_\\mu \\in V_P$ and $B^\\mu \\bm{\\partial}_\\mu \\in V_Q$.\nAlthough these vector spaces are nearly identical, they aren't the same vector space, so we have to way of comparing the two vectors we've just created.\nWhat distinguishes them are the basis vectors; $\\{\\bm{\\partial}_\\mu\\}$ represents the differential operators of functions taken at a certain point, so a more complete notation might be $A^\\mu \\bm{\\partial}_\\mu \\mid_P$ and $B^\\mu \\bm{\\partial}_\\mu \\mid_Q$.\nBecause we can no longer be confined to a single vector space, we need a way of talking about what happens in the uncountably infinite number of vector spaces which exist in our spacetime.\n\n\\section{Vector Fields}\nThe solution to this problem is to define what is known as a \\emph{vector field}.\nSince we've defined a coordinate system $(x^\\mu)$ for our spacetime, we can imagine functions of those coordinates such that they are defined for every possible point.\nWe can then imagine taking the partial derivatives of these functions with respect to each of these coordinates.\n\\[ \\bm{\\partial}_\\mu f(x^\\mu) \\tag{defined for every $x^\\mu$} \\]\nWe will use these differential operators $\\partial_\\mu$ as basis vectors in our vector field.\nA \\emph{vector field} is a collection of vector spaces $V_P$ defined at every point $P$ in a \\emph{manifold} (like our spacetime), all of which share a common basis, and some function $f$ defined at those points.\nIt can be kind of hard to understand the distinction between a vector space and a vector field, so consider this example.\n\\begin{itemize}\n    \\item A vector field is like the velocity of wind at every point in a room.\n    At each point, we can assign a vector which represents the speed and direction of the wind.\n    While these vectors are all broadly measuring the same thing (the velocity of wind), it doesn't really make sense to add these vectors together, since they don't really live in the same space (what does it mean to add the wind at one location to the wind in another?).\n    \\item A vector space is where each of of those vectors live.\n    This is like asking ``at a point $P$, what is every possible direction the wind could be blowing in?''.\n    The vector space at point $P$ is separate from the vector space at point $Q$, since the wind at point $P$ isn't necessarily the same as the wind at point $Q$.\n\\end{itemize}\nMathematically, a vector field is a function\n\\begin{align*}\n    f &: \\mathcal{S} \\to V_\\mathcal{S} \\\\\n      &: P \\in \\mathcal{S} \\mapsto \\vec{v} \\in V_P\n\\end{align*}\nwhere $S = \\{p\\}$ is a subset of our spacetime and $V_\\mathcal{S}$ is the vector spaces defined for all point $P$ in $S$.\nWhen we say that $\\{\\bm{\\partial}_\\mu\\}$ is the basis for the vectors in our vector field, that means that $\\bm{\\partial}_\\mu$ will be the derivative with respect to $x^\\mu$ of our vector field (function) $f$ at the point $P$ with coordinates $(x^\\mu)$.\nIn practice, we often leave the function $f$ ambiguous, and treat $\\{\\bm{\\partial}_\\mu\\}$ as operators for an arbitrary vector field; this is kind of like how we know what the directions in spacetime might be $(t,x,y,z)$ but we don't know exactly \\emph{what} we'll be measuring --- maybe it's wind velocity, maybe it's mass flux, maybe it's whatever vector-valued function we want --- but we know we'll be measuring it's rate of change in the directions of $(t,x,y,z)$.\nIn principle, this means that we can think of an arbitrary vector $A^\\mu \\bm{\\partial}_\\mu \\in V_P$ in our spacetime as an operator $\\mathcal{L}$.\nIf a function $f$ comes along, $\\mathcal{L}$ can operate on it so that we evaluate the partial derivatives of $f$ at a point $P$, so\n\\[ \\mathcal{L}f = A^\\mu \\bm{\\partial}_\\mu f \\mid_P \\;\\in \\mathbb{R}. \\]\nThis choice of basis $\\{\\bm{\\partial}_\\mu\\}$ is known as the \\emph{coordinate basis}.\n\n\\section{Tensors Fields}\nWe have established that the basis of the vector space $V_P$ at a point $P$ is $\\{\\bm{\\partial}_\\mu\\}$;\nIf we want to find the basis of the dual space $V^*_P$ at $P$, we need to find a map which takes a differential operator $\\bm{\\partial}_\\mu$ and gives us a real number.\nWe call this basis $\\{\\vec{d}x^\\nu\\}$, so\n\\[ \\langle \\vec{d}x^\\nu, \\bm{\\partial}_\\mu \\rangle = \\delta^\\nu_\\mu. \\]\nElements of $\\{\\vec{d}x^\\nu\\}$ are known as \\emph{1-forms}. Just as all of the vectors with basis $\\{\\bm{\\partial}_\\mu\\}$ in $V_\\mathcal{S}$ formed a vector field, all of the covectors with basis $\\{\\vec{d}x^\\mu\\}$ in $V^*_\\mathcal{S}$ form a covector field.\nNow that we've defined a basis for the dual space, we can consider tensor product spaces which exist at points in our spacetime.\nFor example, a $(2,1)$ tensor $T$ would be an element of $V_P \\otimes V_P \\otimes V^*_P$, and so would have a basis $\\bm{\\partial}_\\lambda \\otimes \\bm{\\partial}_\\mu \\otimes \\vec{d}x^\\nu$.\nNote that we don't really write which point we're evaluating this basis at; in practice this is contextual, not explicit, and remember that we often won't even write the basis in the first place, and  would just refer to the component $\\tensor{T}{^{\\lambda\\mu}_\\nu}$.\nOne way this is even useful is that we often care about the tensor evaluated at every point in spacetime, not just a particular point, so the ambiguity of the notation can help remind us of that.\nBecause we're describing tensors at different points in spacetime, we've now created a \\emph{tensor field}; just as a vector field assigned vectors to each point in spacetime, a tensor field does the same with tensors.\n\n\\section{Vectors and the Coordinate Basis}\nAs a point of clarification, its helpful to go over exactly what each part of a vector $A^\\mu \\bm{\\partial}_\\mu$ in the coordinate basis actually is.\nWe said that the basis $\\{\\bm{\\partial}_\\mu\\}$ is differential operators with respect to $x^\\mu$ acting on some function $f$, but what about the components?\nWell, since $A^\\mu$ actually varies with $x^\\mu$, we can think of $A^\\mu$ as a function on the coordinates $(x^\\mu)$.\nExplicitly, this would make a vector\n\\[ A^\\nu(x^\\mu)\\,\\bm{\\partial}_\\nu. \\]\nNote that here, $(x^\\mu)$ represents a point, whereas $\\nu$ represents the coordinate directions, so $A^\\nu$ contracts with $\\partial_\\nu$, not with $(x^\\mu)$.\nWe could even replace $(x^\\mu)$ with a point $(P)$ to get\n\\[ A^\\nu (P)\\, \\bm{\\partial}_\\nu. \\]\nBecause of this, we now have the most explicit form of a tensor yet; for a $(2,2)$ tensor $\\Gamma$, we can write it as\n\\[ \\tensor{\\Gamma}{^{\\alpha\\beta}_{\\lambda\\mu}} = \\tensor{\\Gamma}{^{\\alpha\\beta}_{\\lambda\\mu}} (x^\\nu) \\,\\bm{\\partial}_\\alpha \\otimes \\bm{\\partial}_\\beta \\otimes \\vec{d}x^\\lambda \\otimes \\vec{d}x^\\mu. \\]\nIn practice, we only write out $\\tensor{\\Gamma}{^{\\alpha\\beta}_{\\lambda\\mu}}$, and we have to infer the rest.\nThanks, Index Gymnastics\\footnote{If you haven't read any David Sedaris, I \\emph{highly} recommend it.}!\n", "meta": {"hexsha": "9876c8b655c071a649b09447bd5fc7225a604a1a", "size": 7282, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/vector_tensor_fields.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/vector_tensor_fields.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/vector_tensor_fields.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": 117.4516129032, "max_line_length": 469, "alphanum_fraction": 0.7239769294, "num_tokens": 2006, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422186079557, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7754020450081758}}
{"text": "\\chapter{Algebra}\n\n\\section{Polynomial}\nShoeriert multiplication formulas:\n$$(x + y)^2 = x^2 + 2xy + y^2$$\n$$(x - y)^2 = x^2 - 2xy + y^2$$ \n$$(x + y + z)^2 = x^2 + y^2 + z^2 + 2xy + 2yz + 2zx$$ \n$$(x - y + z)^2 = x^2 + y^2 + z^2 - 2xy - 2yz + 2zx$$ \n\nConsequences of the above formulas:\n$$(-x + y)^2 = (y - x)^2 = y^2 - 2xy + x^2$$\n$$(-x - y)^2 = (-(x + y))^2 = (x + y)^2 = x2 + 2xy + y2$$\n\nFormulas for 3rd degree:\n$$(x + y)^3 = x^3 + y^3 + 3xy(x + y) = x^3 + 3x^2y + 3xy^2 + y^3$$\n$$(x - y)^3 = x^3 - y^3 - 3xy(x - y) = x^3 - 3x^2y + 3xy^2 - y^3$$\n\nFactor Rules:\n$$x^2 - y^2 = (x - y)(x + y)$$\n$$x^2 + y^2 = (x + y)^2 - 2xy = (x - y)^2 + 2xy$$\n$$x^3 - y^3 = (x - y)(x^2 + xy + y^2)$$\n$$x^3 + y^3 = (x + y)(x^2 - xy + y^2)$$\n\nMore Algebraic Formulas:\n$$2(x^2 + y^2) = (x + y)^2 + (x - y)^2$$\n$$(x - y)^2 = (x + y)^2 - 4xy$$\n$$x^4 + y^4 = (x + y)(x - y)[(x + y)^2 - 2xy]$$\n\nFactoring trinomials:\n$$ ax^{2n} + bx^n + c = (ax^n + r)(x^n + \\frac{s}{a}) ~~ \\text{with} ~ \\begin{cases} \n                                                                  r + s = b \\\\\n                                                                  r \\times s = ac\n                                                                 \\end{cases}\n$$\n\nPolynomial remainder theorem (the remainder of the division of a polynomial $f(x)$ by a linear polynomial ${(x-a)}$ is equal to $f(a)$:\n$$ f(x) = (x-a)q(x) + r(x) \\implies f(a) = r(x) $$\n\nNewton's binomial formula:\n\\[ (x+y)^n = \\sum_{k=0}^{n}\\binom{n}{k}x^ky^{n-k} \\]\n\n\\section{Equations}\nQuadratic equation solution:\n$$ ax^2 + bx + c = 0 \\rightarrow (x - x1)(x - x2) = 0 ~\\text{with}~ x_{1,2}=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}$$\n\nRational root theorem (or rational root test, rational zero theorem, rational zero test or p/q theorem): \n$$\n\\text{given } a_nx+^n+...+a_0=0 \\rightarrow \\text{ solutions are in the form } x=\\frac{p}{q} \\text{ with } \\begin{cases}\np \\text{ a factor of } a_0 \\\\\nq \\text{ a factor of } a_n\n\\end{cases}\n$$\n\n\n\\section{Inequities TODO}", "meta": {"hexsha": "33385b8c2ab52ab86b3bcda6315da53a6143c697", "size": 1981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics_Formulary/sections/algebra.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/algebra.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/algebra.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": 36.0181818182, "max_line_length": 135, "alphanum_fraction": 0.4634023221, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9683812322750955, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7753751076624936}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\\label{ex:orthogonal-basis-r3}\n  In $\\R^3$ with the usual dot product, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 3 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 2 \\\\ 6 \\\\ 0 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  \\begin{sol}\n    $\\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 3 \\end{mymatrix}$,\n    $\\vect{u}_2 = \\begin{mymatrix}{c} 1 \\\\ 4 \\\\ -3 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In $\\R^4$ with the usual dot product, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\\\  0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 3 \\\\ 0 \\\\ 2 \\\\ -1 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  \\begin{sol}\n    $\\vect{u}_1 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix}$,\n    $\\vect{u}_2 = \\begin{mymatrix}{c} 3 \\\\ -1 \\\\ 1 \\\\ -1 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  In $\\R^4$ with the usual dot product, find an orthogonal basis for\n  \\begin{equation*}\n    \\sspan\\set{\n      \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1 \\\\  0 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 1 \\\\ 3 \\\\ 1 \\\\ -1 \\end{mymatrix},~\n      \\begin{mymatrix}{c} 2 \\\\ 4 \\\\ 2 \\\\  2 \\end{mymatrix}\n    }.\n  \\end{equation*}\n  \\begin{sol}\n    $\\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 1 \\\\ 0 \\end{mymatrix}$,\n    $\\vect{u}_2 = \\begin{mymatrix}{c} 0 \\\\ 3 \\\\ 0 \\\\ -1 \\end{mymatrix}$,\n    $\\vect{u}_3 = \\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\\\ 3 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      3 & -1 & 0 \\\\\n      -1 & 5 & 2 \\\\\n      0 & 2 & 3 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  and consider the vector space $\\R^3$ with the inner product given by\n  $\\iprod{\\vect{v},\\vect{w}} = \\vect{v}^T A\\vect{w}$.\n  Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 2 \\end{mymatrix},\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} -1 \\\\ 1 \\\\ -5 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 2 \\\\ 2 \\\\ 3 \\end{mymatrix}.\n  \\end{equation*}\n  Apply the Gram-Schmidt procedure to\n  $\\vect{v}_1,\\vect{v}_2,\\vect{v}_3$ to find an orthogonal basis\n  $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ for $\\R^3$ with respect to\n  the above inner product.\n  \\begin{sol}\n    $\\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ 0 \\\\ 2 \\end{mymatrix}$,\n    $\\vect{u}_2 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ -1 \\end{mymatrix}$,\n    $\\vect{u}_3 = \\begin{mymatrix}{c} -1 \\\\ 1 \\\\ 0 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cccc}\n      3 & 2 & 0 & 0 \\\\\n      2 & 5 & 1 & 0 \\\\\n      0 & 1 & 3 & 1 \\\\\n      0 & 0 & 1 & 3 \\\\\n    \\end{mymatrix},\n  \\end{equation*}\n  and consider the vector space $\\R^4$ with the inner product given by\n  $\\iprod{\\vect{v},\\vect{w}} = \\vect{v}^T A\\vect{w}$.\n  Let\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ 1 \\\\ 1 \\end{mymatrix},\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 0 \\\\ 2 \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{c} 2 \\\\ 0 \\\\ 2 \\\\ 3 \\end{mymatrix},\n  \\end{equation*}\n  and let $W=\\sspan\\set{\\vect{v}_1,\\vect{v}_2,\\vect{v}_3}$.  Apply the\n  Gram-Schmidt procedure to $\\vect{v}_1,\\vect{v}_2,\\vect{v}_3$ to find\n  an orthogonal basis $\\set{\\vect{u}_1,\\vect{u}_2,\\vect{u}_3}$ for $W$\n  with respect to the above inner product.\n  \\begin{sol}\n    $\\vect{u}_1 = \\begin{mymatrix}{c} 1 \\\\ -1 \\\\ 1 \\\\ 1 \\end{mymatrix}$,\n    $\\vect{u}_2 = \\begin{mymatrix}{c} 1 \\\\ 1 \\\\ -1 \\\\ 1 \\end{mymatrix}$,\n    $\\vect{u}_3 = \\begin{mymatrix}{c} -1 \\\\ 1 \\\\ 1 \\\\ 0 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the inner product space $C[0,2]$, with the inner product\n  given by\n  \\begin{equation*}\n    \\iprod{p,q} = \\int_{0}^{2} f(x)g(x)\\,dx.\n  \\end{equation*}\n  Use the Gram-Schmidt procedure to find an orthogonal basis for\n  $\\sspan\\set{1,x,x^2}$.\n  \\begin{sol}\n    $\\vect{u}_1 = 1$, $\\vect{u}_2 = x-1$, $x^2 - 2x + \\frac{2}{3}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find an orthonormal basis for the subspace of $\\R^3$ from Exercise~\\ref{ex:orthogonal-basis-r3}.\n  \\begin{sol}\n    The orthonormal basis is $\\displaystyle\\set{\n      \\frac{\\vect{u}_1}{\\norm{\\vect{u}_1}},\n      \\frac{\\vect{u}_2}{\\norm{\\vect{u}_2}}\n    } = \\set{\n      \\frac{1}{\\sqrt{14}} \\begin{mymatrix}{c} 1 \\\\ 2 \\\\ 3 \\end{mymatrix},\n      \\frac{1}{\\sqrt{26}} \\begin{mymatrix}{c} 1 \\\\ 4 \\\\\n        -3 \\end{mymatrix}\n    }$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "1ce605e513b9345a6db2945bb8e20c8d104b892c", "size": 4444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-GramSchmidt.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-GramSchmidt.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-GramSchmidt.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 33.1641791045, "max_line_length": 98, "alphanum_fraction": 0.5549054905, "num_tokens": 1952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587993853654, "lm_q2_score": 0.8723473779969194, "lm_q1q2_score": 0.7753064083155136}}
{"text": "%%%%%%%%%%%%%%%\n% Definitions %\n%%%%%%%%%%%%%%%\n\n\\section{Definitions}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Basic Notions and Notation %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Basic Notions and Notation}\n\n\\textit{In the following, $\\Omega$ is a set, $\\CalF$ a \\SigmaAlgebra\\ on $\\Omega$. If used, then $\\mu$ is a measure. Otherwise, the measure is the probability measure $P$.}\n\n\\begin{definition}{1.1}{}\n\n    Let $\\mathcal{F}$ be a family of subsets of set $\\Omega$. $\\mathcal{F}$ is called a \\emph{$\\sigma$-algebra} if:\n\n        \\begin{itemize}\n            \\setlength{\\parskip}{0em}\n            \\item \\emph{Closed Under Complement}: $A \\in \\mathcal{F} \\Rightarrow A^c \\in \\mathcal{F}$,\n            \\item \\emph{Closed Under Arbitrary Union}: $A_n \\in \\mathcal{F}$ for integer $n \\geq 1$ $\\Rightarrow \\bigcup_{n=1}^{\\infty}A_n \\in \\mathcal{F}$,\n            \\item \\emph{Contains Entire Set}: $\\Omega \\in \\mathcal{F}$\n        \\end{itemize}\n\n\\end{definition}\n\n\\begin{definition}{1.2}{}\n    Let $\\mathcal{C}$ be a family of subsets of $\\Omega$. There exists a $\\sigma$-algebra which contains $\\mathcal{C}$ \\emph{and} which is contained in every $\\sigma$-algebra that contains $\\mathcal{C}$ (take intersection of all $\\sigma$-algebras. Such $\\sigma$-algebra is \\emph{unique} and called \\emph{smallest $\\sigma$-algebra containing $\\mathcal{C}$} or \\emph{$\\sigma$-algebra generated by $\\mathcal{C}$}, denoted by $\\sigma(\\mathcal{C})$. Simplest example, let $A \\subseteq \\Omega$:\n\n        \\begin{align*}\n            \\sigma(A) = \\{\\emptyset, A, A^c, \\Omega\\}.\n        \\end{align*}\n\\end{definition}\n\n\\begin{definition}{}{Finite Measure Space}\n\n    Let $(\\Omega, \\CalF, \\mu)$ be a measure space. If $\\mu(\\Omega) < \\infty$, then we call the measure space \\emph{finite}.\n\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%\n% Random Variables %\n%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Random Variables}\n\n\\begin{definition}{2.1.1}{}\n\n    Let $A \\subseteq \\Omega$ and $\\Indicator{A}$ be defined as follows:\n\n        \\begin{align*}\n            \\Indicator{A}(\\omega) =\n            \\begin{cases}\n                1, & \\omega \\in A \\\\\n                0, & \\omega \\not\\in A\n            \\end{cases}.\n        \\end{align*}\n\n    Then $\\Indicator{A}$ is a R.V. and called the \\emph{indicator (function) of (events) A}.\n\n\\end{definition}\n\n\\begin{definition}{2.3}{Distribution Function}\n\n    Let $X$ be a random variable. Then the function\n\n        \\begin{align*}\n            F_X(x) &= P(X \\leq x) = \\\\ &= P(X \\in (-\\infty, x]) = Q_X((-\\infty, x]),\n        \\end{align*}\n\n    for $x \\in \\mathbb{R}$ is called the \\emph{distribution function} of $X$.\n\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%\n% Expectation Integrals %\n%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Expectation Integrals}\n\n\\begin{definition}{}{Indicator Integral}\n\n    Let $A \\subseteq \\Omega$, then:\n\n        \\begin{align*}\n            \\int_{\\Omega} \\Indicator{A} \\,d\\mu = \\mu(A).\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Simple Function}\n\n    Let $f: \\Omega \\to \\mathbb{R}$ be a \\emph{simple function}, then $f$ takes finitely many values. Formally, if $I$ is a finite index set, $(A_i)_{i \\in I}$ a famility of \\emph{disjoint} subsets of $\\Omega$ and $(c_i)_{i \\in I}$ a family of real numbers, then:\n\n        \\begin{align*}\n            f(\\omega) = \\sum_{i \\in I} c_i \\Indicator{A_i}(\\omega).\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Lebesgue Integral for Expectation}\n\n    Let $X$ be a random variable. Then we write:\n\n        \\begin{align*}\n            EX = \\int_{\\Omega} X \\,dP.\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Non-negative, Measurable Lebesgue Integral}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative}, measurable function and $(f_n)_{n=1}^{\\infty}$ a sequence of \\emph{non-negative, simple} functions sucht that $\\lim_{n \\to \\infty} f_n = f$. Then\n\n        \\begin{align*}\n            \\int_{\\Omega} f \\, d\\mu = \\lim_{n \\to \\infty} f_n \\, d\\mu.\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Lebesgue Integral}\n\n     Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a measurable function. The \\emph{Lebesgue Integral} of $f$ is defined as:\n\n        \\begin{align*}\n            \\int_{\\Omega} f \\,d\\mu = \\int_{\\Omega} f^+ \\,d\\mu - \\int_{\\Omega} f^- \\,d\\mu,\n        \\end{align*}\n\n    where $f^+ = \\max\\{f, 0\\}$ and $f^-=\\max\\{-f, 0\\}$, if at least one of the integrals on the right-hand side is finite. If both are infinite, then we say that the Lebesgue Integral of $f$ does not exist.\n\n\\end{definition}\n\n\\begin{definition}{}{Restricted Integration}\n\n    Let $A \\in \\CalF$ and $f: \\Omega \\to \\overline{\\mathbb{R}}$ is a measurable function, then we define:\n\n        \\begin{align*}\n            \\int_A f \\, d\\mu = \\int_{\\Omega} \\Indicator{A} f \\, d\\mu,\n        \\end{align*}\n\n    when the integral of $\\Indicator{A} f$ w.r.t $\\mu$ exists.\n\n\\end{definition}\n\n\\begin{definition}{3.7}{Absolute Continuity}\n\n    Let $\\mu$ and $\\nu$ be measures on \\SigmaAlgebra\\ $\\CalF$ such that for some $\\CalF$-measureable $g: \\Omega \\to \\mathbb{R}$:\n\n        \\begin{align*}\n            \\nu(A) = \\int_{\\Omega} \\Indicator{A} g \\, d\\mu = \\int_{A} g \\mu(dx),\n        \\end{align*}\n\n    for all $A \\in \\CalF$. Then $\\nu$ is called \\emph{absolutely continuous} with respect to $\\mu$ and $g$ is called the \\emph{density} or \\emph{Radon-Nikodym derivative} (Notation: $g = \\frac{d\\nu}{d\\mu}$).\n\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Convergence of Measurable Functions %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Convergence of Measurable Functions}\n\n\\begin{definition}{}{$\\mu$-Almost Everywhere Finite}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be $\\CalF$-measurable, then $f$ is said to be \\emph{$\\mu$-almost everywhere} ($\\mu$-a.e.) finite if $\\mu(|f| = \\infty) = 0$.\n\n\\end{definition}\n\n\\begin{definition}{}{Almost Surely Finite}\n\n    Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be $\\CalF$-measurable, then $f$ is said to be \\emph{almost surely} (a.s.) finite if $P(|f| = \\infty) = 0$ $\\Leftrightarrow P(|f| < \\infty) = 1$.\n\n\\end{definition}\n\n\\begin{definition}{5.1}{$\\mu$-Almost Everywhere Convergence}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be $\\CalF$-measurable functions. The $f_n$ are said to \\emph{converge $\\mu$-almost everywhere} to a \\emph{$\\mu$-a.e. finite} $f: \\Omega \\to \\overline{\\mathbb{R}}$ as $n \\to \\infty$ if there exists an $A \\in \\CalF$ s.t. $\\mu(A) = 0$ and\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} f_n(\\omega) = f(\\omega) \\in \\mathbb{R}, \\quad \\forall \\omega \\in A^C.\n        \\end{align*}\n\n    \\emph{Notation:} $\\lim_{n \\to \\infty} f_n = f$ ($\\mu$-a.e.) or $f_n \\to f$ ($\\mu$-a.e.).\n\n\\end{definition}\n\n\\begin{definition}{5.1}{Almost Sure Convergence}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be $\\CalF$-measurable functions. The $f_n$ are said to \\emph{converge almost surely} to a \\emph{a.s. finite} $f: \\Omega \\to \\overline{\\mathbb{R}}$ as $n \\to \\infty$ if there exists an $A \\in \\CalF$ s.t. $P(A) = 0$ and\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} f_n(\\omega) = f(\\omega) \\in \\mathbb{R}, \\quad \\forall \\omega \\in A^C.\n        \\end{align*}\n\n    \\emph{Notation:} $\\lim_{n \\to \\infty} f_n = f$ (a.s.) or $f_n \\to f$ (a.s.).\n\n\\end{definition}\n\n\\begin{definition}{5.2}{Convergence in Measure}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be $\\CalF$-measurable functions. The $f_n$ are said to \\emph{converge in measure $\\mu$} to a \\emph{$\\mu$-a.e. finite} $f: \\Omega \\to \\overline{\\mathbb{R}}$ as $n \\to \\infty$ if\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} \\mu(|f_n - f| \\geq \\varepsilon) = 0, \\quad \\forall \\varepsilon > 0.\n        \\end{align*}\n\n    \\emph{Notation:} $\\mu-\\lim_{n \\to \\infty} f_n = f$.\n\n\\end{definition}\n\n\\begin{definition}{5.2}{Convergence in Probability}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be $\\CalF$-measurable functions. The $f_n$ are said to \\emph{converge in probability} to a \\emph{a.s. finite} $f: \\Omega \\to \\overline{\\mathbb{R}}$ as $n \\to \\infty$ if\n\n        \\begin{align*}\n            \\lim_{n \\to \\infty} P(|f_n - f| \\geq \\varepsilon) = 0, \\quad \\forall \\varepsilon > 0.\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Bounded in Measure}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of measurable functions, then it is \\emph{bounded in measure $\\mu$} if\n\n        \\begin{align*}\n            \\lim_{K \\to \\infty} \\mu(|f_n| \\geq K) = 0,\n        \\end{align*}\n\n    for any $n \\geq 1$.\n\n\\end{definition}\n\n\\begin{definition}{}{Bounded Uniformly in Measure}\n\n    Let $(f_n)_{n=1}^{\\infty}$ be a sequence of measurable functions, then it is \\emph{bounded in measure $\\mu$, uniformly in $n$} if\n\n        \\begin{align*}\n            \\lim_{K \\to \\infty} \\sup_{n \\geq 1} \\mu(|f_n| \\geq K) = 0.\n        \\end{align*}\n\n\\end{definition}\n\n\\begin{definition}{}{Finite Second Moment}\n\n    Let $X$ be a random variable. Then $X$ has \\emph{finite second moment} if $EX^2 < \\infty$.\n\n\\end{definition}\n\n%%%%%%%%%%%%%%%%\n% Independence %\n%%%%%%%%%%%%%%%%\n\n\\subsection{Independence of Events and Random Variables}\n\n\\begin{definition}{6.5}{$\\lambda$-system}\n\n    Let $\\Lambda$ be a family o subsets of $\\Omega$. Then $\\Lambda$ is a $\\lambda$-system, if it satisfies all of the following properties:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item (Contains whole set) $\\Omega \\in \\Lambda$;\n            \\item (Closed under Subset Set Subtraction) if $A, B \\in \\Lambda$, such that $B \\subset A$, then $A \\setminus B \\in \\Lambda$;\n            \\item (Closed under Disjoint Union) if $(A_n)_{n=1}^{\\infty}$ is a \\emph{pairwise disjoint} sequence, i.e. $A_i \\cap A_j = \\emptyset$ for $i \\neq j$, of subsets, such that $A_i \\in \\Lambda$ for $i = 1,2,\\hdots$, then $\\bigcup_{n=1}^{\\infty} \\in \\Lambda$.\n        \\end{enumerate}\n\n\\end{definition}\n\n\\begin{definition}{}{$\\pi$-system}\n\n    Let $\\Pi$ be a family of subsets of $\\Omega$. Then $\\Pi$ is a $\\pi$-system, if it is closed under finite intersections, i.e. $A,B \\in \\Pi$ $\\Rightarrow$ $A \\cap B \\in \\Pi$.\n\n\\end{definition}\n\n\\begin{definition}{Ws 5, 1}{$\\sigma$-Finite Measure}\n\n    Let $\\mu$ be a measure, then $\\mu$ is called \\emph{$\\sigma$-finite} if there exists an increasing sequence $(\\Omega_n)_{n=1}^{\\infty}$ in $\\CalF$, such that $\\mu(\\Omega_n) < \\infty$ for all $n \\geq 1$ and $\\bigcap_{n=1}^{\\infty} \\Omega_n = \\Omega$.\n\n\\end{definition}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Conditional Expectation %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\subsection{Conditional Expectation}\n\n\\begin{definition}{8.1}{Sub-$\\sigma$-Algebra Measurable}\n\n    Let $Y$ be a random variable and $\\CalG \\subset \\CalF$ be a \\SigmaAlgebra. Then $Y$ is $\\CalG$-measurable if $Y^{-1}(F) \\in \\CalG$ for any $F \\in \\mathcal{B}(\\mathbb{R})$.\n\n\\end{definition}\n\n\\begin{definition}{8.2}{Conditional Expectation}\n\n    Let $X,Y$ be random variables such that $E|X| < \\infty$ and $\\CalG \\subset \\CalF$ be a \\SigmaAlgebra. Let $Y$ satisfy the following properties:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item $Y$ is $\\CalG$-measurable and\n            \\item for any $A \\in \\CalG$:\n\n                    \\begin{align*}\n                        \\int_{A} Y \\, dP = \\int_{A} X \\, dP\n                        \\iff E(\\Indicator{A}Y) = E(\\Indicator{A}X),\n                    \\end{align*}\n        \\end{enumerate}\n\n    then $Y$ is called the \\emph{conditional expectation} with respect of $\\CalG$ of $X$ and we write $Y = E(X|\\CalG)$.\n\n\\end{definition}\n", "meta": {"hexsha": "7df2ff648e00b9f7457778691a61794232870fa5", "size": 11407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/definitions.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/definitions.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/definitions.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": 36.6784565916, "max_line_length": 488, "alphanum_fraction": 0.5891996143, "num_tokens": 3823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066392, "lm_q2_score": 0.8723473763375644, "lm_q1q2_score": 0.7753063914187569}}
{"text": "\\documentclass{standalone}\n\\begin{document}\n\t\\chapter{The Remainder and Factor Theorems}\n\t\\section{The Remainder Theorem}\n\tConsider the polynomial $f(x)$. Suppose that this polynomial is to be divided by the linear expression $x-a$. This gives:\n\t\\begin{alignat*}{3}\n\t\t&&\\frac{f(x)}{x-a}A&\\equiv Q(x) + \\frac{R}{x-a}\\\\\n\t\t&\\implies&f(x) &\\equiv Q(x) \\cdot (x-a) + R\\\\\n\t\t\\text{Let $x-a=0$}&\\implies &x &= a\\\\\n\t\t& \\therefore & f(a) & = R;\\quad & \\text{Where R is the remainder of $\\frac{f(x)}{x-a}$} \\\\\n\t\t&            &      &           & \\text{and Q is the quotient of $\\frac{f(x)}{x-a}$}    \\\\\n\t\\end{alignat*} \\\\\n\t\\begin{example}\n\t\tFind the remainder when the cubic polynomial $f(x) = 2x^3-3x-5$ is divided by $x-2$\n\t\\end{example}\n\t\n\t\n\tIf $f(x)$ is to be divided by $x-2$, then $f(2)$ is equal to the remainder of $\\frac{2x^3-3x-5}{x-2}$\n\t\\begin{alignat*}{2}\n\t\t&        & 2x^3 -3x-5       \\\\\n\t\t& =\\quad & 2(2)^3 - 3(2) -5 \\\\\n\t\t&\\boxed{\\therefore\\quad R\\quad=\\quad5}\n\t\\end{alignat*}\n\t\\section{The Factor theorem}\n\t\n\tThe factor theorem states that:\n\t\\begin{itemize}\n\t\t\\item{If the polynomial $f(x)$ is divided by $x-a$, then $f(a) = 0$ (i.e $R=0$}), therefore it can also be concluded that $x-a$ is a factor of $f(x)$\n\t\\end{itemize}\n\t\\begin{example}\n\t\tDetermine whether $2x+3$ is a factor of $2x^3+x^2-5x+6$ \n\t\\end{example}\n\t\n\t\\begin{flalign*}\n\t\t&  & \\text{Let } f(x) &= 2x^3+x^2-5x+6& \\\\\n\t\t& \\rlap{If $2x+3$ is a factor of $f(x)\\colon$} &0 &=f\\left(\\frac{-3}{2}\\right)\\\\\n\t\t&\\rlap{However,} &0 &\\neq 2\\left(\\frac{-3}{2}\\right)^3 + \\left(\\frac{-3}{2}\\right)^2 -5\\left(\\frac{-3}{2}\\right) + 6 \\\\\n\t\t&&&\\neq -3\\\\\n\t\t&&&\\boxed{\\therefore \\quad \\text{$2x+3$ is \\textbf{not} a factor of $f(x)$}}\n\t\\end{flalign*}\n\t\\newpage\n\t\\end{document}", "meta": {"hexsha": "cf9ec36d39fe6214a8a8519c746f0228463a8158", "size": 1725, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Pure Mathematics/RemFact_Theroem.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/RemFact_Theroem.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/RemFact_Theroem.tex", "max_forks_repo_name": "Girogio/My-LaTeX", "max_forks_repo_head_hexsha": "706ec7cb4d62af1b5a9ad7547589889240c755bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 41.0714285714, "max_line_length": 151, "alphanum_fraction": 0.5860869565, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8397339756938819, "lm_q1q2_score": 0.7751073471621343}}
{"text": "\\section{On Spectral Clustering: Analysis and an algorithm}\n\\label{ch:ng01}\n\n\\textit{On Spectral Clustering: Analysis and an algorithm} by Andrew Ng, Michael I. Jordan, and Francis R. Bach. \\\\\nCited by 3787. \\textit{Advances in neural information processing systems 2 (2002)}.\n\\newline\n\n\\textbf{Main point} is that the author \\begin{inparaenum}[\\itshape a\\upshape)]\n\\item suggest the method nomalize the rows of the chosen eigenvector.\n\\end{inparaenum}\n\n\\subsection{Algorithm}\nForm a similarity matrix $S \\in R^{n \\times n}$ defined by $A_{ij} = exp(- \\| s_i - s_j \\|^2 / 2 \\sigma^2)$ if $i \\neq j$, and $S_{ii} = 0$.\n\\begin{figure}[ht]\n\\begin{mdframed}\n\\begin{enumerate}\n\\item[Input] : Similarity matrix $S \\in R^{n \\times n}$, number $k$ of clusters. \\\\\n\\item[Step 1] : Construct the normalized graph Laplacian $L_{sym} = I - D^{-\\frac{1}{2}} S D^{-\\frac{1}{2}}$. \\\\\n\\item[Step 2] : Find the $k$ eigenvectors $u_1, \\cdots, u_k$ corresponding to the largest $k$ eigenvalues of $L_{sym}$. \\\\\n\\item[Step 3] : Let $U = R^{n \\times k}$ be the matrix containing the eigenvectors $u_i$ as columns, and let $y_i \\in R^k$ be the $i$th row of $U$.\\\\\n\\item[Step 4] : Let $T$ be the row-normalized $U$ matrix where $t_{ij} = \\frac{u_{ij}}{(\\sum_k u_{ik}^2)^2}$ and let $y_i \\in R^k$ be the $i$th row of $T$.\\\\\n\\item[Step 5] : Cluster the points $(y_i)_{i=1,\\cdots,n}$ in $R^k$ into clusters $C_1,\\cdots,C_k$ via $k$-means clustering or any other algorithm that attempts to minimize distortion. \\\\\n\\item[Output] : clusters $A_1, \\cdots, A_k$ where $A_k - {v_j|y_j \\in C_i}$\n\\end{enumerate}\n\\end{mdframed}\n\\caption{Normalized spectral clustering according to Ng}\n\\end{figure}\n\nThen assign the original point $s_i$ to cluster $j$ if and only if row $i$ of the matrix $Y$ was assigned to cluster $j$. The scaling parameter $\\sigma^2$ controls how rapidly the affinity $S_{ij}$ falls off with the distance between $s_i$ and $s_j$.\n\n\n", "meta": {"hexsha": "7afddabce59811fab448d16b388001f5c609d5de", "size": 1918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/references/reference_research/ng01.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/ng01.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/ng01.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": 59.9375, "max_line_length": 250, "alphanum_fraction": 0.6903023983, "num_tokens": 656, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.8438951104066295, "lm_q1q2_score": 0.7751009944703855}}
{"text": "\\section{Quadratics and Polynomials}\n\n\\subsection{Basic factoring}\n\nGiven some $ax^2+bx+c$, try and find the factorization $(sx+u)(tx+v)$ by expanding this template expression.\n\n\\begin{remark}\n    If one root is 0, the product of roots is 0 so\n    the equation is of form $ax^2+bx=0$.\n\\end{remark}\n\n\\begin{remark}\n    Difference of squares are of the form $x^2-a^2=0\\implies (x-a)(x+a)=0$.\n\\end{remark}\n\n\\begin{remark}\n    A perfect square is of the form $(x+a)^2=x^2+2ax+a^2$. This is a case of a \"double root.\"\n\\end{remark}\n\n\\subsection{Quadratic Formula}\n\nBy manipulating $ax^2+bx+c=0$ by completing the square, the quadratic formula can be found.\n\n\\begin{equation}\n    x=\\frac{-b\\pm \\sqrt{b^2-4ac}}{2a}\n\\end{equation}\n\n\\subsection{Expansions}\n\n\\begin{eqnarray}\n    (a+b)^2=a^2+2ab+b^2\\\\\n    (a+b)^3 = a^3 + 3a^2b+3ab^2+b^3\n\\end{eqnarray}\n\n\\subsection{Factoring}\n\n\\begin{definition}[Difference of squares]\n    \\begin{equation}\n        a^2-b^2=(a+b)(a-b)\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Sum of squares]\n    \\begin{equation}\n        a^2+b^2=(a+b)^2-2ab\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Sum of cubes]\n    \\begin{equation}\n        a^3+b^3=(a+b)(a^2-ab+b^2)\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Difference of cubes]\n    \\begin{equation}\n        a^3-b^3=(a-b)(a^2+ab+b^2)\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Some cube identity]\n    \\begin{equation}\n        a^3+b^3+c^3-3abc=(a+b+c)(a^2+b^2+c^2-ab-ac-bc)\n    \\end{equation}\n\\end{definition}\n\n\\begin{definition}[Simon factoring trick]\n    Used to factor in a diophantine equation.\n    If $ab + ka + nb = c$, then $(a+n)(b+k)=c+nk$.\n\\end{definition}\n\n\\subsection{Vieta's Formulas}\n\n\\begin{eqnarray}\n    x^2+ax+b=(x-p)(x-q)\\\\\n    x^2+ax+b=x^2-(p+q)x+pq\n\\end{eqnarray}\n\nThus, $a=p+q$ and $b=pq$. Generally,\n\n\\begin{align*}\t \n    s_1&= & r_1+r_2+r_3&+\\cdots+r_n & &=-\\frac{a_{n-1}}{a_n} \\\\\t s_2&= & r_1r_2+r_1r_3+r_1r_4&+\\cdots+r_{n-2}r_{n-1} & &=\\phantom{-}\\frac{a_{n-2}}{a_n} \\\\\t s_3&= & r_1r_2r_3+r_1r_2r_4&+\\cdots+r_{n-2}r_{n-1}r_n & &=-\\frac{a_{n-3}}{a_n} \\\\\t & & &\\vdots & & \\\\\t s_n&= & r_1r_2r_3&\\cdots r_n & &=(-1)^n\\frac{a_0}{a_n}.\\\\\t \n\\end{align*}\n\n\\begin{definition}[AM-GM Inequality]\n    \\begin{equation}\n        \\frac{a_1+\\ldots+a_n}{n}\\geq \\sqrt[n]{a_1a_2\\ldots a_n}\n    \\end{equation}\n\\end{definition}", "meta": {"hexsha": "12ee50dd5e0fcd7d82857c6f7cd0a28105bcf7a5", "size": 2343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "competitive-math/tex/quad-factor.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/quad-factor.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/quad-factor.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": 26.3258426966, "max_line_length": 318, "alphanum_fraction": 0.6282543747, "num_tokens": 957, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480244025281, "lm_q2_score": 0.8438951104066293, "lm_q1q2_score": 0.7751009869380223}}
{"text": "\\section{Introduction}\n\n\\noindent\nConsider the following arithmetic from Vladimir Nabokov's autobiography ``Speak, Memory.''\n\n\\begin{quote}\nA foolish tutor had explained logarithms to me much too early, and I had\nread (in a British publication, the {\\it Boy's Own Paper}, I believe)\nabout a certain Hindu calculator who in exactly two seconds could find the\nseventeenth root of, say,\n352947114576027513 2301897342055866171392\n(I am not sure I have got this right; anyway the root was 212).\n\\end{quote}\n\n\\noindent\nLet us compute $212^{17}$ and check the result.\nIn the field shown below, enter\n\n{\\color{blue}\n\\begin{verbatim}\n212^17\n\\end{verbatim}\n}\n\n\\begin{center}\n\\begin{tikzpicture}\n\\node at (0,0) {\\includegraphics[scale=0.2]{1st.png}};\n\\draw[red,thick] (2.3,-1.95) ellipse (2.5cm and 0.5cm);\n\\end{tikzpicture}\n\\end{center}\n\n\\noindent\nAfter pressing the return key, Eigenmath displays the following result.\n\n\\bigskip\n\\noindent\n$3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nNow let us compute the seventeenth root of this number.\n\n{\\color{blue}\n\\begin{verbatim}\nN = 212^17\nN^(1/17)\n\\end{verbatim}\n}\n\n\\noindent\nEigenmath displays the following result.\n\n\\bigskip\n\\noindent\n$212$\n\n\\bigskip\n\\noindent\nWhen a symbol is assigned a value, such as $N$ above,\nno result is printed.\nTo see the value of a symbol, just evaluate it.\n\n{\\color{blue}\n\\begin{verbatim}\nN\n\\end{verbatim}\n}\n\n\\noindent\n$N=3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nThe previous example shows a convention that will be used throughout\nthis manual.\nThat is, the color blue indicates something that the user should type.\nThe computer response is shown in black.\n", "meta": {"hexsha": "1851b9dfd0bf8f8bd9184e679d5daf198f956118", "size": 1661, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/nabokov-macos.tex", "max_stars_repo_name": "wuyudi/eigenmath", "max_stars_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "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/nabokov-macos.tex", "max_issues_repo_name": "wuyudi/eigenmath", "max_issues_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "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/nabokov-macos.tex", "max_forks_repo_name": "wuyudi/eigenmath", "max_forks_repo_head_hexsha": "509c3a2b320b27ce85fbc3cc055d8fa30e3175a6", "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.2948717949, "max_line_length": 90, "alphanum_fraction": 0.7652016857, "num_tokens": 485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8902942203004186, "lm_q1q2_score": 0.7750877132841687}}
{"text": "\\subsection{Progressions}\\label{subsec:progressions}\n\nProgressions are an elementary concept that happens to be useful quite often. There is no definition of progression, but rather the term \\enquote{progression} refers to specific recursively defined \\hyperref[def:sequence]{sequences}.\n\n\\begin{definition}\\label{def:arithmetic_progression}\n  The \\term{arithmetic progression} with \\term{base} \\( a_0 \\) and \\term{difference} \\( d \\) is the sequence\n  \\begin{equation}\\label{eq:def:arithmetic_progression}\n    a_k \\coloneqq \\begin{cases}\n      a_0,         & k = 0, \\\\\n      a_{k-1} + d, & k > 0.\n    \\end{cases}\n  \\end{equation}\n\n  Clearly every index \\( k \\geq 0 \\) we have the closed form representation \\( a_k = a_0 + kd \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:arithmetic_progression_partial_sums}\n  The \\hyperref[def:convergent_series]{series} constructed from the arithmetic progression \\eqref{eq:def:arithmetic_progression} has partial sums\n  \\begin{equation}\\label{eq:thm:arithmetic_progression_partial_sums}\n    \\sum_{k=0}^n a_k = \\frac {(n + 1) (a_n - a_0)} 2.\n  \\end{equation}\n\n  In the special case where \\( a_0 = 0 \\) and \\( d = 1 \\), this reduces to\n  \\begin{equation}\\label{eq:thm:arithmetic_progression_partial_sums/integers}\n    \\sum_{k=0}^n k = \\sum_{k=1}^n k = \\frac {n (n + 1)} 2.\n  \\end{equation}\n\\end{proposition}\n\\begin{proof}\n  \\begin{balign*}\n    2 \\sum_{k=0}^n a_k\n     & =\n    2 \\sum_{k=0}^n (a_0 + kd)\n    =    \\\\ &=\n    \\sum_{k=0}^n (a_0 + kd) + \\sum_{k=0}^n (a_0 + (n-k)d)\n    =    \\\\ &=\n    \\sum_{k=0}^n (2 a_0 + nd)\n    =    \\\\ &=\n    (n + 1) (a_0 + a_n).\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:geometric_progression}\n  The \\term{geometric progression} with \\term{base} \\( a_0 \\) and \\term{denominator} \\( q \\) is the sequence\n  \\begin{equation}\\label{eq:def:geometric_progression}\n    a_k \\coloneqq \\begin{cases}\n      a_0,       & k = 0, \\\\\n      a_{k-1} q, & k > 0.\n    \\end{cases}\n  \\end{equation}\n\n  Clearly every index \\( k \\geq 0 \\) we have the closed form representation \\( a_k = a_0 q^k \\).\n\n  The \\hyperref[def:convergent_series]{series}\n  \\begin{equation}\\label{eq:def:geometric_progression/series}\n    \\sum_{k=0}^\\infty a_k = a_0 \\sum_{k=0}^\\infty q^k.\n  \\end{equation}\n  is called the \\term{geometric series} for \\( q \\). Without loss of generality, we will assume \\( a_0 = 1 \\) when speaking about geometric series.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:geometric_series_properties}\n  The geometric series \\eqref{eq:def:geometric_progression/series} has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:geometric_series_properties/finite_sum} For all \\( q \\in \\BbbC \\setminus \\{ 1 \\} \\), the geometric series \\eqref{eq:def:geometric_progression/series} has partial sums\n    \\begin{equation}\\label{thm:geometric_progression/partial_sum}\n      \\sum_{k=0}^n q^k = \\frac {1 - q^{n+1}} {1 - q}.\n    \\end{equation}\n\n    Compare this to \\fullref{thm:xn_minus_yn_factorization}.\n\n    \\thmitem{thm:geometric_series_properties/degenerate} In the degenerate case \\( q = 1 \\), the progression itself is constant, and its partial sums are instead\n    \\begin{equation}\\label{thm:geometric_progression/degenerate}\n      \\sum_{k=0}^n q^k = n + 1.\n    \\end{equation}\n\n    \\thmitem{thm:geometric_series_properties/series_sum_exterior} For \\( \\abs{q} \\geq 1 \\), the geometric series diverges.\n\n    \\thmitem{thm:geometric_series_properties/series_sum_interior} For \\( 0 < \\abs{q} < 1 \\), the geometric series converges absolutely with sum\n    \\begin{equation}\\label{thm:geometric_progression/series_sum}\n      \\sum_{k=0}^\\infty q^k = \\frac 1 {1 - q}.\n    \\end{equation}\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:geometric_series_properties/finite_sum} Follows from \\fullref{thm:xn_minus_yn_factorization}.\n  \\SubProofOf{thm:geometric_series_properties/degenerate} Obvious.\n\n  \\SubProofOf{thm:geometric_series_properties/series_sum_exterior} For \\( q = 1 \\), \\fullref{thm:geometric_series_properties/degenerate} implies that the series diverges because it grows indefinitely. If \\( \\abs{q} = 1 \\) and \\( q \\neq 1 \\), the integer powers \\( q^k \\) are rotations around the complex plane unit circle, which do not tend to a limit. Hence, the series diverges again.\n\n  When \\( \\abs{q} > 1 \\), \\( \\abs{q^n} \\) grows indefinitely with \\( n \\), and it follows that\n  \\begin{equation*}\\label{thm:geometric_progression/cauchy_partial_sum}\n    \\sum_{k=m}^n q^k\n    =\n    q^m \\sum_{k=0}^{n-m} q^k\n    =\n    q^m \\frac {1 - q^{n-m+1}} {1 - q}\n    =\n    \\frac {q^m - q^{n+1}} {1 - q}.\n  \\end{equation*}\n  can get arbitrarily large. Therefore, in this case the series also diverges.\n\n  \\SubProofOf{thm:geometric_series_properties/series_sum_interior} Fix \\( q \\in B(0, 1) \\). Since only \\( q^{n + 1} \\) depends on \\( n \\) in \\eqref{thm:geometric_progression/partial_sum}, we obtain \\eqref{thm:geometric_progression/series_sum} by simply noting that \\( q^n \\to 0 \\) when \\( n \\to \\infty \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:n_ary_decomposition}\n  A simple but important practical example of a \\hyperref[eq:def:geometric_progression/series]{geometric series} is\n  \\begin{equation}\\label{eq:ex:n_ary_decomposition/binary}\n    \\sum_{k=0}^\\infty \\frac 1 {2^k} = \\frac 1 {1 - \\sfrac 1 2} = 2.\n  \\end{equation}\n\n  Note that if the series starts at \\( k = 1 \\) instead of \\( k = 0 \\), it sums to \\( 1 \\). This is often applied in analysis indirectly via \\fullref{thm:continuous_function_series_powers_of_two}.\n\n  Another application of \\eqref{eq:ex:n_ary_decomposition/binary} is showing that \\( 0.\\overline{1} = 2 \\) in the binary number system. More generally, for the \\( n \\)-ary number system we have\n  \\begin{equation}\\label{eq:ex:n_ary_decomposition/general}\n    \\sum_{k=0}^\\infty \\parens*{ \\frac {n-1} n }^k = \\frac 1 {1 - \\ifrac {(n-1)} n} = n.\n  \\end{equation}\n\\end{example}\n\n\\begin{remark}\\label{rem:progressions_and_interest}\n  In this example we exploit the equivalence between the closed form representations in \\fullref{def:arithmetic_progression} and \\fullref{def:geometric_progression} and the corresponding inductive definitions. The equivalences are obvious from a mathematical standpoint, however outside of mathematics they have highly nontrivial consequences. Indeed, they highlight the difference between simple interest and compound interest.\n\n  As an example, a savings account with \\( 1000\\$ \\) with a simple monthly interest of \\( 2\\% \\) will earn \\( 240\\$ \\) over a year:\n  \\begin{equation*}\n    1000 (1 + 12 \\cdot \\sfrac 2 {100}) = 1240.\n  \\end{equation*}\n\n  The same account with a compound interest of \\( 2\\% \\) will earn a bit more - about \\( 268\\$ \\):\n  \\begin{equation*}\n    1000 (1 + \\sfrac 2 {100})^{12} \\approx 1268.24.\n  \\end{equation*}\n\n  Over the course of ten years, however, simple interest will earn a total of \\( 2400\\$ \\), while compound interest will earn \\( \\approx 9765\\$ \\).\n\n  The difference between linear and exponential growth appears staggering in a real world situation even though the difference may not be very noticeable short-term.\n\\end{remark}\n\n\\begin{definition}\\label{def:harmonic_progression}\n  The \\term{harmonic progression} with \\term{base} \\( a_0 \\) and \\term{difference} \\( d \\) is the sequence\n  \\begin{equation}\\label{eq:def:harmonic_progression}\n    a_k \\coloneqq \\frac 1 {a_0 + kd}.\n  \\end{equation}\n\n  That is, each term is the reciprocal of the corresponding term in an \\hyperref[def:arithmetic_progression]{arithmetic progression} with the same base and difference. In order for \\eqref{eq:def:harmonic_progression} to be well-defined, either\n  \\begin{itemize}\n    \\item \\( d = 0 \\) and \\( a_0 \\neq 0 \\), which turns \\eqref{eq:def:harmonic_progression} into the constant sequence \\( \\seq{ \\sfrac 1 {a_0} }_{k=0}^\\infty \\).\n    \\item \\( d \\neq 0 \\), in which case\n    \\begin{equation*}\n      a_k = \\frac d {\\sfrac {a_0} d + k}.\n    \\end{equation*}\n\n    Thus, if \\( d \\neq 0 \\), \\( \\ifrac {a_0} d \\) must not be a negative integer unless we are satisfied with only the first \\( -\\ifrac {a_0} d \\) terms of the progression existing.\n  \\end{itemize}\n\n  Furthermore, the series may only start at \\( k = 0 \\) if \\( a_0 \\neq 0 \\).\n\n  For series related to harmonic progressions, see \\fullref{ex:harmonic_series}\n\\end{definition}\n\n\\begin{remark}\\label{rem:harmonic_progression_recursive_form}\n  Unlike \\fullref{def:arithmetic_progression} and \\fullref{def:geometric_progression}, we have defined the harmonic progressions via closed-form expressions. Indeed, the equivalent inductive definition is more awkward to work with:\n  \\begin{equation*}\n    a_k \\coloneqq \\begin{cases}\n      \\ifrac 1 {a_0},                    & k = 0, \\text{ only defined if } a_0 \\neq 0, \\\\\n      \\ifrac 1 {(a_0 + d)},                & k = 1,                                      \\\\\n      \\ifrac 1 {(\\sfrac 1 {a_{k-1}} + d)}, & k > 0.\n    \\end{cases}\n  \\end{equation*}\n\\end{remark}\n", "meta": {"hexsha": "d7beb8429e93b3bac1856895fc8760b4f375b4d6", "size": 8914, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/progressions.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/progressions.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/progressions.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.0595238095, "max_line_length": 428, "alphanum_fraction": 0.6874579313, "num_tokens": 2901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952948443462, "lm_q2_score": 0.863391611731321, "lm_q1q2_score": 0.7750625874592835}}
{"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-06.json'\n   cdblib.create (checkpoint_file)\n   checkpoint = []\n\\end{cadabra}\n\\egroup\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 6-01 Evaluating components}\n\n\\begin{cadabra}\n   {\\theta, \\varphi}::Coordinate.\n   {a,b,c,d,e,f,g,h#}::Indices(values={\\theta, \\varphi}, position=independent).\n\n   \\partial{#}::PartialDerivative.\n\n   V  := { V_{\\theta} = \\varphi, V_{\\varphi} = \\sin(\\theta) }.   # cdb(ex-06.100,V)\n   dV := \\partial_{b}{V_{a}} - \\partial_{a}{V_{b}}.              # cdb(ex-06.101,dV)\n\n   evaluate (dV, V)   # cdb(ex-06.102,dV)\n\\end{cadabra}\n\n\\begin{align*}\n             V_{a} &= \\Cdb{ex-06.100}\\\\[10pt]\n   \\cdb{ex-06.101} &= \\Cdb{ex-06.102}\n\\end{align*}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 6-02 Riemann tensor of a 2-sphere}\n\n% LCB: the dimensionality of the space is inferred from the number of distinct coordinates\n%      so use just two symbols for the coordinates\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   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   gab := { g_{\\theta\\theta}   = r**2,\n            g_{\\varphi\\varphi} = r**2 \\sin(\\theta)**2 }.      # cdb(ex-06.201,gab)\n\n   iab := { g^{\\theta\\theta}   = 1/r**2,\n            g^{\\varphi\\varphi} = 1/(r**2 \\sin(\\theta)**2) }.  # cdb(ex-06.202,iab)\n\n   substitute (Rabcd, Gamma)                                  # cdb(ex-06.203,Gamma)\n\n   evaluate   (Gamma, gab+iab, rhsonly=True)                  # cdb(ex-06.204,Gamma)\n   evaluate   (Rabcd, gab+iab, rhsonly=True)                  # cdb(ex-06.205,Rabcd)\n\n   # convert from a rule to a simple expression\n   Riem := R^{a}_{b c d}.\n   substitute (Riem, Rabcd)                                   # cdb(ex-06.206,Riem)\n\n   from cdb.core.component import *\n\n   RiemCompt = get_component (Riem, $\\theta, \\varphi, \\theta, \\varphi$)   # cdb(ex-06.207,RiemCompt)\n\n\\end{cadabra}\n\n\\begin{align*}\n   &\\Cdb{ex-06.201}\\\\[10pt]\n   &\\Cdb{ex-06.202}\\\\[10pt]\n   &\\Cdb{ex-06.204}\\\\[10pt]\n   &\\Cdb{ex-06.205}\\\\[10pt]\n   &\\Cdb{ex-06.206}\n\\end{align*}\n\n\\begin{align*}\n   R^{\\theta}{}_{\\varphi\\varphi\\theta} &= \\Cdb{ex-06.207}\n\\end{align*}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 6-03 Using {\\tt complete} to compute the inverse metric}\n\nThis version uses \\verb|complete| to compute the inverse metric.\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   gab := { g_{\\theta\\theta}   = r**2,\n            g_{\\varphi\\varphi} = r**2 \\sin(\\theta)**2 }.      # cdb(ex-06.301,gab)\n\n   complete   (gab, $g^{a b}$)                                # cdb(ex-06.302,gab)\n\n   substitute (Rabcd, Gamma)\n\n   evaluate   (Gamma, gab, rhsonly=True)                      # cdb(ex-06.303,Gamma)\n   evaluate   (Rabcd, gab, rhsonly=True)                      # cdb(ex-06.304,Rabcd)\n\n\\end{cadabra}\n\n\\begin{align*}\n   &\\Cdb{ex-06.301}\\\\[10pt]\n   &\\Cdb{ex-06.302}\\\\[10pt]\n   &\\Cdb{ex-06.303}\\\\[10pt]\n   &\\Cdb{ex-06.304}\n\\end{align*}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 6-04 Components by scalar projection}\n\nThis example shows how one component of the Riemann tensor can be computed using a scalar\nprojection.\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   theta{#}::LaTeXForm{\"\\theta\"}.\n   varphi{#}::LaTeXForm{\"\\varphi\"}.\n\n   # usual definitions for the connection and Riemann tensor\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   gab := { g_{\\theta \\theta}   = r**2,\n            g_{\\varphi \\varphi} = r**2 \\sin(\\theta)**2 }.   # cdb(ex-06.400,gab)\n\n   iab := { g^{\\theta\\theta}   = 1/r**2,\n            g^{\\varphi\\varphi} = 1/(r**2 \\sin(\\theta)**2) }.\n\n   substitute (Rabcd, Gamma)\n   evaluate   (Rabcd, gab+iab, rhsonly=True)\n\n   # above code just to compute Rabcd\n   # following code is all that is needed for the scalar projection method\n\n   # define the basis for vectors and dual vectors\n\n   basis := {theta^{\\theta} = 1, varphi^{\\varphi} = 1}.\n   dual  := {theta_{\\theta} = 1, varphi_{\\varphi} = 1}.\n\n   # obtain components by contracting with basis\n\n   compt := R^{a}_{b c d} theta_{a} varphi^{b} theta^{c} varphi^{d}.   # cdb(ex-06.401,compt)\n   substitute (compt,Rabcd)\n\n   evaluate (compt,basis+dual)                                         # cdb(ex-06.402,compt)\n\n   compt_sympy = compt._sympy_()\n\n   # cdbBeg(print.ex-06.04)\n   print ('type compt   = ' + str(type(compt)))        # shows that compt is a Cadabra object\n   print ('type gphiphi = ' + str(type(compt_sympy)))  # shows that gphiphi is a Python object\n   print ('     compt   = ' + str(compt))              # will contain LaTeX markup\n   print ('     gphiphi = ' + str(compt_sympy))        # will be pure Python/SymPy\n   # cdbEnd(print.ex-06.04)\n\n   checkpoint.append (compt)\n\\end{cadabra}\n\n\\begin{align*}\n   R^{\\theta}{}_{\\varphi\\theta\\varphi} &= \\Cdb{ex-06.401}\\\\\n                                       &= \\Cdb{ex-06.402}\n\\end{align*}\n\n\\IfFileExists{example-06-04.cdbcopy}%\n{\\lstinputlisting[backgroundcolor=\\color{white}]{example-06-04.cdbcopy}}%\n{Where is {\\tt example-06-04.cdbcopy}?}\n\n\\clearpage\n\n% ============================================================================================\n\\section*{Example 6-05 Components by selection}\n\nThis example shows how one component of the metric tensor can be computed by indexing\nthe result of a call to \\verb|evaluate|.\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   theta{#}::LaTeXForm{\"\\theta\"}.\n   varphi{#}::LaTeXForm{\"\\varphi\"}.\n\n   gab := { g_{\\theta \\theta}   = r**2,\n            g_{\\varphi \\varphi} = r**2 \\sin(\\theta)**2 }.   # cdb(ex-06.500,gab)\n\n   metric := g_{a b}.\n\n   evaluate (metric,gab)\n\n   indcs = metric[2][1][0]                                  # cdb(ex-06.501,indcs)\n   compt = metric[2][1][1]                                  # cdb(ex-06.502,compt)\n\n   # cdbBeg(print.ex-06.05)\n   print ('metric = ' + str(metric.input_form())+'\\n')  # reveals Cadabra's internal structure for storing metric\n\n   print ('metric[0] = ' + str(metric[0]))\n   print ('metric[1] = ' + str(metric[1]))\n   print ('metric[2] = ' + str(metric[2])+'\\n')\n\n   print ('metric[2][1] = '+ str(metric[2][1]))\n   print ('metric[2][1][0] = '+ str(metric[2][1][0]))\n   print ('metric[2][1][1] = '+ str(metric[2][1][1]))\n   # cdbEnd(print.ex-06.05)\n\n   checkpoint.append (indcs)\n   checkpoint.append (compt)\n\\end{cadabra}\n\n\\begin{align*}\n   g_{\\varphi\\varphi} &= g_{\\Cdb{ex-06.501}}\\\\\n                      &= \\Cdb{ex-06.502}\n\\end{align*}\n\n\\IfFileExists{example-06-05.cdbcopy}%\n{\\lstinputlisting[backgroundcolor=\\color{white}]{example-06-05.cdbcopy}}%\n{Where is {\\tt example-06-05.cdbcopy}?}\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": "82adb75b431cbe86c96c47ded447d02dd8c3fc66", "size": 9192, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/cadabra/example-06.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-06.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-06.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.4254545455, "max_line_length": 113, "alphanum_fraction": 0.5063098346, "num_tokens": 2871, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7750020917421636}}
{"text": "\n\\subsection{Dual space}\n\nThe dual space \\(V^*\\) of vector space \\(V\\) is the set of all linear forms, \\(\\hom(V,F)\\).\n\n\\subsubsection{The dual space is itself a vector space}\n\n\n\\(v\\in V\\)\n\n\\(f\\in F\\)\n\n\\(av = f\\)\n\n\\(bv = g\\)\n\n\\((a\\oplus b)v=f+g\\)\n\n\\((a\\oplus b)v=av + bv\\)\n\nSo there is some operation we can do on two members of dual space\n\nLinear in addition. That is, if we have two dual \"things\", we can define the addition of functions as the operation which results int he outputs being added.\n\nwhat about linear in scalar? same approach.\n\nWell we define \n\n\\((c\\odot a)=cav\\)\n\n\\subsubsection{The dual space has the same dimension as the underlying vector space}\n\n", "meta": {"hexsha": "6c0ee63e3ea71caecd37eef080121757820c3229", "size": 667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/01-02-dualSpace.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/01-02-dualSpace.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/01-02-dualSpace.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.2121212121, "max_line_length": 157, "alphanum_fraction": 0.6866566717, "num_tokens": 192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7750020855016974}}
{"text": "\\chapter{Abstract algebra}\n\n\\section{Group}\n\n\\index{binary operation}%\nThe type of a \\emph{binary operation} is \\(a \\to b \\to c\\).\n\\index{binary operation!closed}%\n\\index{closed binary operation}%\nThe type of a \\emph{closed binary operation} is \\(a \\to a \\to a\\).\nA binary operation \\(\\cdot\\)\nis \\emph{associative} iff \\(x\\cdot(y\\cdot z) = (x\\cdot y)\\cdot z\\),\nis \\emph{commutative} iff \\(x \\cdot y = y \\cdot x\\).\n\n\\index{magma}%\nA \\emph{magma} is a set and a closed binary operation.\n\\index{semigroup}%\nA \\emph{semigroup} is an associative magma (a magma whose operation is associative).\n\\index{monoid}%\nA \\emph{monoid} is a semigroup with an identity element.\n\\index{group}%\nA \\emph{group} is a monoid where each element has an inverse.\n\\index{commutative!group}%\n\\index{group!abelian}%\n\\index{group!commutative}%\nAn \\emph{abelian group} or a \\emph{commutative group}\nis a group whose operation is commutative.\n\n\\(-x\\) is the additive inverse of \\(x\\).\n\n\\section{Ring}\n\nA\n\\index{ring}%\n\\emph{ring} is \\((S,+,\\cdot,-,0,1)\\) where\n\\((S,+,-,0)\\) is a commutative group,\n\\((S,\\cdot,1)\\) is a monoid,\nand multiplication distributes addition:\n\\begin{align*}\n    x \\cdot (y+z) &= (x \\cdot y) + (x \\cdot z)\n    \\\\\n    (x+y) \\cdot z &= (x \\cdot z) + (y \\cdot z).\n\\end{align*}\nA ring is\n\\index{commutative!ring}%\n\\index{ring!commutative}%\n\\emph{commutative} iff its multiplicative monoid is commutative.\n\nIf \\(R\\) is a ring and \\(A \\to R\\) is a function space,\nthen the \\emph{natural ring of the function space} is:\n\\begin{align*}\n    0_{A\\to R}(x) &= 0_R\n    \\\\ 1_{A\\to R}(x) &= 1_R\n    \\\\ (- f)(x) &= - f(x)\n    \\\\ (f + g)(x) &= f(x) + g(x)\n    \\\\ (f \\cdot g)(x) &= f(x) \\cdot g(x).\n\\end{align*}\n\n\\section{Field}\n\n\\(x^{-1}\\) is the multiplicative inverse of \\(x\\).\n\n\\index{field}%\n\\((F,+,\\cdot,-,{}^{-1},0,1)\\) is a \\emph{field} iff\n\\((F,+,-,0)\\) is a commutative group,\n\\((F-\\{0\\},\\cdot,{}^{-1},1)\\) is a commutative group,\nand \\(\\cdot\\) distributes \\(+\\) (that is \\(x \\cdot (y + z) = (x \\cdot y) + (x \\cdot z)\\)) \\cite{wpfield}.\nFor brevity, if \\(F\\) is a set, ``\\(F\\) is a field'' means that \\((F,+,\\cdot,-,{}^{-1},0,1)\\) is a field.\nThat is, for brevity, we blur the distinction between a field and its underlying set.\n", "meta": {"hexsha": "9929a1fda469d6406d6061f5cc66ce819c2a0b08", "size": 2217, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/algebra.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/algebra.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/algebra.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.1304347826, "max_line_length": 105, "alphanum_fraction": 0.6292286874, "num_tokens": 809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7749759998370238}}
{"text": "\\section{Intuition of Euler-Lagrange equation}\n\nEuler-Lagrange equation is a \\textbf{partial differential equation} fundamental\nto the study of the \\textbf{calculus of variations}, especially in the field of\noptimizing a \\textbf{functional}. There are many methods to derive this\nequation rigourously, but this section will give readers a basic understanding\nof where this equation comes from.\n\n\\subsection{Functional}\n\nAccording to calculus of variations, a typical functional is defined as:\n\n\\begin{equation}\n\ty\\mapsto J[y]=\\int_{x_0}^{x_1}F(x,y,\\dot{y})dx\n\t\\label{functional-def}\n\\end{equation}\n\nwhere $y$ is a function dependent on $x$. Arc length, for instance, is a\ntypical functional:\n\n$$\ny\\mapsto L[y]=\\int_{x_0}^{x_1}\\sqrt{1+\\dot{y}^2}dx\n$$\n\nin which $F$ is called the \\textbf{core} of the functional.\n\n\\subsection{Optimize functional}\n\nIn single-variable calculus, we know that a function reaches an extremum if its\nderivative becomes zero, and this is same for functionals. Since the solution\nof the optimization of a problem is a function instead of a real number, we\nassume $y$ is the optimal function and define $f$ as follows:\n\n\\begin{equation}\n\tf=y+\\varepsilon\\mu\n\t\\label{var-y}\n\\end{equation}\n\nIn equation (\\ref{var-y}), $\\mu$ is an arbitrary function satisfying\n$\\mu(x_0)=\\mu(x_1)=0$, and $\\varepsilon\\in\\mathbb{R}$. Since $y$ denotes the\nresult of optimization of $J[f]$, the function $N(\\varepsilon)=J[f]$ reaches\nits extremum at $\\varepsilon=0$. Therefore, we can deduce:\n\n\\begin{equation}\n\t\\left.dN\\over d\\varepsilon\\right|_{\\varepsilon=0}=0\n\t\\label{optimal-functional}\n\\end{equation}\n\nIn order to find out $y$, we first need to express the derivative in\n(\\ref{optimal-functional}). According to \\textbf{Leibniz's rule}, we can swap\nthe differential operator and integral if the limits of the integral are\nnot depending on $\\varepsilon$.\n\n$$\n\\begin{aligned}\n\t{dN\\over d\\varepsilon}\n\t&={d\\over d\\varepsilon}\\int_{x_0}^{x_1}F(x,f,\\dot{f})dx \\\\\n\t&=\\int_{x_0}^{x_1}{d\\over d\\varepsilon}F(x,f,\\dot{f})dx\n\\end{aligned}\n$$\n\nSince $F$ is a multivariable function, we take its total derivative with\nrespect to $\\varepsilon$. Since $x$ does not depend on $\\varepsilon$,\n$dx/d\\varepsilon$ is automatically set to zero.\n\n$$\n\\begin{aligned}\n\t{dN\\over d\\varepsilon}\n\t&=\\int_{x_0}^{x_1}{\\partial F\\over\\partial x}\n\t{dx\\over d\\varepsilon}+{\\partial F\\over\\partial f}\n\t{df\\over d\\varepsilon}+{\\partial F\\over\\partial\\dot{f}}\n\t{d\\dot{f}\\over d\\varepsilon}dx \\\\\n\t&=\\int_{x_0}^{x_1}{\\partial F\\over\\partial f}{df\\over d\\varepsilon}\n\t+{\\partial F\\over\\partial\\dot{f}}{d\\dot{f}\\over d\\varepsilon}dx\n\\end{aligned}\n$$\n\nAccording to the definition of $f$ in (\\ref{var-y}), $df/d\\varepsilon$ is\nsimply $\\mu$, and $d\\dot{f}/d\\varepsilon=\\dot{\\mu}$.\n\n$$\n{dN\\over d\\varepsilon}=\\int_{x_0}^{x_1}\\mu{\\partial F\\over\\partial f}\n+\\dot{mu}{\\partial F\\over\\partial\\dot{f}}dx\n$$\n\nUsing the technique of integration by parts, $\\mu$ became factored out. Because\n$\\mu(x_0)=\\mu(x_1)=0$, there is nothing left outside the integral.\n\n$$\n\\begin{aligned}\n\t{dN\\over d\\varepsilon}\n\t&=\\int_{x_0}^{x_1}\\mu{\\partial F\\over\\partial f}dx+\n\t\\left.\\mu{\\partial F\\over\\partial\\dot{f}}\\right|_{x_0}^{x_1}\n\t-\\int_{x_0}^{x_1}\\mu{d\\over dx}{\\partial F\\over\\partial\\dot{f}}dx \\\\\n\t&=\\int_{x_0}^{x_1}\\mu\\left({\\partial F\\over\\partial f}-\n\t{d\\over dx}{\\partial F\\over\\partial\\dot{f}}\\right)dx\n\\end{aligned}\n$$\n\nAccording to (\\ref{optimal-functional}) and \\ref{var-y}, we replace\n$dN/d\\varepsilon$, $f$, and $\\dot{f}$ with zero, $y$, and $\\dot{y}$\nrespectively.\n\n$$\n0=\\int_{x_0}^{x_1}\\mu\\left({\\partial F\\over\\partial y}-{d\\over dx}\n{\\partial F\\over\\partial\\dot{y}}\\right)dx\n$$\n\nAccording to the \\textbf{fundamental lemma of calculus of variations}, we know\nthat the coefficient of $\\mu$ must be zero if the integral is zero.\n\n$$\n{\\partial F\\over\\partial y}-{d\\over dx}{\\partial F\\over\\partial\\dot{y}}=0\n$$\n\nTherefore, we obtain the Euler-Lagrange equation:\n\n\\begin{equation}\n\t{\\partial F\\over\\partial y}={d\\over dx}{\\partial F\\over\\partial\\dot{y}}\n\t\\label{el-def}\n\\end{equation}\n\n\\subsection{Shortcut for specific functional}\n\nIf the core $F$ of a functional does not depend on $x$ ($F=F(y,\\dot{y})$), a\nsimpler approach is possible without taking the derivative of $\\partial\nF/\\partial\\dot{y}$, facilitating the whole optimization problem.\n\n\\begin{flushleft}\n\tStep 1: Eliminate the differential operator via integrating factor\n\\end{flushleft}\n\nIf we multiply (\\ref{el-def}) by $\\dot{y}$, we can formulate:\n\n$$\n{\\partial F\\over\\partial y}\\dot{y}=\n{d\\over dx}{\\partial F\\over\\partial\\dot{y}}\\dot{y}\n$$\n\nAccording to product rule of differential calculus, the right part of the\nequation is equivalent to:\n\n$$\n{d\\over dx}\\left({\\partial F\\over\\partial\\dot{y}}\\dot{y}\\right)\n-\\ddot{y}{\\partial F\\over\\partial\\dot{y}}\n$$\n\nAs a result, we can gather a dot product in the left side.\n\n$$\n\\left({\\partial F\\over\\partial y}\\hat{\\i}\n+{\\partial F\\over\\partial\\dot{y}}\\hat{\\j}\\right)^\\top\n\\left({dy\\over dx}\\hat{\\i}+{d\\dot{y}\\over dx}\\hat{\\j}\\right)\n={d\\over dx}\\left({\\partial F\\over\\partial\\dot{y}}\\dot{y}\\right)\n$$\n\nWe can discover that the left side is the total derivative of $F$ with respect\nto $x$, so we find the antiderivative of the both side in order to eliminate\ndifferential operator.\n\n$$\nF(y,\\dot{y})+C={\\partial F\\over\\partial\\dot{y}}\\dot{y}\n$$\n\nTherefore, when optimizing functionals with cores only depending on $y$ and\n$\\dot{y}$, we can use the following equation instead of the Euler-Lagrange\nequation:\n\n$$\nF(y,\\dot{y})-\\dot{y}{\\partial F\\over\\partial\\dot{y}}=C\n$$\n\nwhere $C$ is a constant. This corollary is known as \\textbf{Beltrami identity}.\n", "meta": {"hexsha": "f5f22c34dfcfd2e4e1d23c216fb31be31cad953a", "size": 5612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "euler-lagrange-equation.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "euler-lagrange-equation.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "euler-lagrange-equation.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 32.2528735632, "max_line_length": 79, "alphanum_fraction": 0.7129365645, "num_tokens": 1885, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424334245618, "lm_q2_score": 0.9161096153072137, "lm_q1q2_score": 0.7749759972566235}}
{"text": "%---------------------------Aspect Gamma-----------------------------\n\\section{Aspect Gamma}\n\nThis metric compares root-mean-square edge length to volume.\nThe root-mean-square edge length is\n\\[\nR = \\sqrt{\\frac{\\sum_{i=0}^{5}\\normvec{L_i}^2}{6}}\n\\]\nand so, normalizing the metric to a value of 1 for equilateral tetrahedra, we have\n\\[\nq = \\frac{R^3\\sqrt{2}}{12|V|}.\n\\]\n\nNote that if  $|V| < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\tetmetrictable{aspect $\\gamma$}%\n{$1$}%                  Dimension\n{$[1,3]$}%              Acceptable range\n{$[1,DBL\\_MAX]$}%       Normal range\n{$[1,DBL\\_MAX]$}%       Full range\n{$1$}%                  Equilateral tet\n{\\cite{par:93}}%        Citation\n{v\\_tet\\_aspect\\_gamma}%                            Verdict function name\n\n", "meta": {"hexsha": "c8f7d40b4f468833bad6c99bfd3a74e109bea46c", "size": 754, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetAspectGamma.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/TetAspectGamma.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/TetAspectGamma.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 30.16, "max_line_length": 82, "alphanum_fraction": 0.5371352785, "num_tokens": 228, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067179697694, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.774918787171525}}
{"text": "\n%\\section{Mathematical framework (for QM)}\n\t\n%\t\\begin{enumerate}\n%\t\\item Dirac's braket notation\n%\t\\item Inner/(Outer) product\n%\t\\item Linear operator\n%\t\\item Adjoints and Hermitian operators\n%\t\\item Pauli matrices\n%\t\\item Tensor Product and tensor space\n%\t\\end{enumerate}\n\t\n\tUnless stated otherwise, we consider each coefficient to be complex (as in elements of $\\mathbb{C}$). Vectors have complex components.\n\t\\section{Inner product spaces}\n\tIn standard vector notation we define the inner (scalar) product of complex vectors as\n\t\\begin{equation*}\n\t ( \\vec{v}, \\vec{w} ) =  \\begin{pmatrix} \\bar{v_1} & \\bar{v_2}\\end{pmatrix} \\begin{pmatrix} w_1 \\\\ w_2 \\end{pmatrix} = \\begin{pmatrix} \\bar{w_1} & \\bar{w_2}\\end{pmatrix} \\begin{pmatrix} v_1 \\\\ v_2 \\end{pmatrix} = ( \\vec{w}, \\vec{v} )^{\\dagger}\n\t\\end{equation*}\n\tWhere $\\dagger$ represents the conjugate transpose.\\\\\n%\tThis property is fundamental in the sense that it will allows us to go from a state space --- that can be many dimensional --- to a \\textit{measurement} space, which assumes real values.\\\\ %0 and 1 in our case??\n\t\n\tIt is important also to note that through the inner product of two vectors we also define the norm $\\|\\ket{v}\\|  =  \\sqrt{( \\vec{v}, \\vec{v} )} $.\\\\\n\t\n\t\\section{Tensor product spaces}\n\tThe tensor product $V\\otimes W$ is an operation between vector spaces that combines every element of the first vector space and every element of the second vector space in a bigger vector space. Tensor product is linear and from its properties emerges the famous phenomenon of quantum entanglement, which simply is that not all vectors in $\\H = V\\otimes W$ can be divided into $\\ket{v}\\otimes\\ket{w}$ with $\\ket{v}\\in V,\\; \\ket{w}\\in W$. This will later be explained in the next section.\n\tNotation and abbreviation for the tensor product is \n\t$$ \\ket{v}\\otimes\\ket{w} = \\ket{v}\\ket{w} = \\ket{v,w} = \\ket{vw}$$\n\tIt has the following properties:\n\t\\begin{align*}\n\t\t \\forall\\ket{v}\\in V ,\\; \\forall\\ket{w}\\in W, \\; \\forall z\\in \\mathbb{C}&\\\\\n\t\t\t\t\t&z(\\ket{v}\\otimes\\ket{w}) = (z\\ket{v})\\otimes\\ket{w} = \\ket{v}\\otimes(z\\ket{w} \\\\\n\t\t\\forall\\ket{v_1},\\ket{v_2}\\in V ,\\; \\forall\\ket{w}\\in W\t&\\\\\n\t\t\t\t\t &(\\ket{v_1} + \\ket{v_2})\\otimes\\ket{w} = \\ket{v_1w} + \\ket{v_2w} \\\\\n\t\t\\forall\\ket{v}\\in V ,\\; \\forall\\ket{w}\\in W, \\; A:V\\rightarrow V' \\; B:W\\rightarrow W'&\\\\\n\t\t\t\t\t&(A\\otimes B) \\left(\\sum_i a_i \\ket{v_i w_i} \\right) = \\sum_i a_i A\\ket{v_i}\\otimes B\\ket{w_i} \n\t\\end{align*}\n\tThe inner product on $V$ and $W$ can be used to define (linearly) an inner product on $V\\otimes W$.\t\n\t\n\t\n\n", "meta": {"hexsha": "5d4a444cb0178f1bc3bbc0ffcc22660e6b986c41", "size": 2545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writings/chapters/appendixA.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/appendixA.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/appendixA.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": 62.0731707317, "max_line_length": 488, "alphanum_fraction": 0.6813359528, "num_tokens": 886, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7749187795609892}}
{"text": "\\section{Policy Gradients}\nPolicy gradient algorithms directly optimize the policy $\\pi_\\theta(\\cdot \\mid  s)$. The goal is to maximize the expected return under $\\pi_\\theta$:\n\\[\n    \\max_\\theta J(\\theta) = \\E_{\\tau \\sim \\pi_\\theta} [R(\\tau)]\n\\]\nUsing the log-derivative trick ($\\nabla f = f \\nabla \\log f$) and the likelihood of a trajectory $\\tau$:\n\\[\n    \\pi_\\theta(\\tau) = \\rho_0(s_0) \\prod_{t=0}^T P(s_{t+1} \\mid  s_t, a_t) \\pi_\\theta(a_t \\mid  s_t)\n\\]\nthe \\emph{policy gradient} can be derived:\n\\begin{align}\n    \\nabla_\\theta J(\\theta) \n    &= \\E_{\\tau \\sim \\pi_\\theta} [\\nabla_\\theta \\log \\pi_\\theta(\\tau) R(\\tau)] \\nonumber \\\\\n    &= \\E_{\\tau \\sim \\pi_\\theta} \\left[\\sum_{t=0}^T R(\\tau) \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t) \\right]\n    \\label{eq:policy-gradient}\n\\end{align}\n\n\nLearning the optimal policy can be easier than learning all the action values $Q(s,a)$, and directly optimizing $\\pi_\\theta$ makes it possible to have smoother updates and more stable convergence than Q-learning. In addition, all policy gradient algorithms work with continuous/infinite action spaces, and can encourage exploration with additional rewards (entropy). However, they can be less adapted to tabular environments and are often less sample-efficient than value-based approaches, which typically use memory buffers.\n\n\\subsection{On-Policy}\n\\paragraph{REINFORCE}\nBased on eq. \\ref{eq:policy-gradient}, the REINFORCE algorithm simply uses a Monte-Carlo estimate of $\\nabla_\\theta J(\\theta)$ to optimize $\\pi_\\theta$, and increase the likelihood of trajectories with high rewards.\n\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n\\For{a number of epochs}{\n    \\While{not enough samples}{\n        collect trajectory $\\tau_i=(s_0^i, a_0^i, \\dots, s_{T_i}^i)$ by running active policy $\\pi_\\theta$\n    }\n    $\\hat{g} \\leftarrow \\sum_i \\sum_t R(\\tau^i) \\nabla_\\theta \\log \\pi_\\theta(a_t^i \\mid  s_t^i)$ \\tcp*{compute policy gradient estimate}\n    $\\theta \\leftarrow \\theta + \\alpha \\hat{g}$ \\;\n}\n\\caption{Vanilla REINFORCE}\n\\label{algo:reinforce}\n\\end{algorithm}\n\nIt is unbiased but typically has very high variance and is slow to converge. Variance can be reduced using alternatives expressions of the gradient (all three can be combined):\n\\begin{itemize}\n    \\item \\emph{Causality (don't let the past distract you)}\n    Intuitively, rewards obtained before taking an action do not bring any information, they are just noise. Indeed $R(\\tau)$ can be replaced by the \\emph{reward-to-go} $R_t(\\tau) = \\sum_{t'=t}^T r_t'$ without making the policy gradient expression biased \\demo.\n    \\item \\emph{Baseline}\n    For any function $b:\\mathcal{S} \\rightarrow \\mathbb{R}$, we have:\n    \\[\n        \\E_{\\tau \\sim \\pi_\\theta} \\left[\\sum_{t=0}^T b(s_t) \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t) \\right] = 0\n    \\]\n    Hence \\demo we can use $(R(\\tau) - b(s_t))$ instead of $R(\\tau)$, and the variance is minimal when choosing $b(s) = V^\\pi(s)$  (e.g. by fitting $b(s_t)$ to  $R_t(\\tau)$).\n    \\item \\emph{Discount}\n    Using a discounted return $R(\\tau) = \\sum_{t=0}^T \\gamma r_t$ can also reduce the variance but, unlike the 2 previous techniques, it makes the gradient biased. \n\\end{itemize}\n\nMore generally, the policy gradient can be expressed as:\n\\begin{equation}\n    \\nabla_\\theta J(\\theta) \n    = \\E_{\\tau \\sim \\pi_\\theta} \\left[\\sum_{t=0}^T \\Psi_t \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t) \\right]\n    \\label{eq:policy-gradient2}\n\\end{equation}\n\nWhere $\\Psi_t$ may be the reward $R(\\tau)$, the reward-to-go $R_t(\\tau)$, with or without a baseline (e.g. $R_t(\\tau) - b(s_t)$).\n\n\\paragraph{Actor-Critic}\nThe policy gradient (eq. \\ref{eq:policy-gradient2}) can also be expressed \\demo with:\n\\begin{itemize}\n    \\item $\\Psi_t = Q^\\pi(s_t,a_t)$: state-action value function\n    \\item $\\Psi_t = A^\\pi(s_t,a_t)$: advantage function\n    \\item $\\Psi_t = r_t + \\gamma V^\\pi(s_{t+1}) - V^\\pi(s_t) = \\delta_t$: TD error\n\\end{itemize}\nActor-critic methods combine the strengths of policy gradient and value-based methods by estimating a critic ($Q^\\pi$, $V^\\pi$ and/or $A^\\pi$) in order to better optimize the actor (policy $\\pi_\\theta$). Adding a critic reduces the variance, but estimation errors introduce a bias as soon as the critic is not perfect.\n\n\\paragraph{Actor-Critic with compatible functions}\nWe can try to approximate $A^\\pi$ with a function $f_\\phi: \\mathcal{S} \\times \\mathcal{A} \\rightarrow \\mathbb{R}$. According to the \\emph{Compatible Function Approximation Theorem} \\cite{sutton2000policy} \\demo, if $f_\\phi$ satisfies\n\\begin{equation}\n    \\forall s, a, \\nabla_\\phi f_\\phi(s,a) = \\nabla_\\theta \\log \\pi_\\theta(a\\mid s)\n    \\qquad \\text{(i.e. $f_\\phi$ is \\emph{compatible})}\n\\label{eq:compat-fct-1}\n\\end{equation}\n\\begin{equation}\n    \\E_{\\tau \\sim \\pi_\\theta} \\left[ \\sum_{t=0}^T \\gamma^t (Q^\\pi(s_t,a_t) - f_\\phi(s_t,a_t)) \\nabla_\\theta \\log \\pi_\\theta(a_t\\mid s_t)\\right] = 0\n\\label{eq:compat-fct-2}\n\\end{equation}\nthen the policy gradient is exact:\n\\[\n    \\nabla_\\theta J(\\theta) \n    = \\E_{\\tau \\sim \\pi_\\theta} \\left[\\sum_{t=0}^T \\gamma^t f_\\phi(s_t,a_t) \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t) \\right]\n\\]\nEq. \\ref{eq:compat-fct-1} can be satisfied with $f_\\phi(s,a) = \\nabla_\\theta \\log \\pi_\\theta(s,a)^T \\phi$, and eq. \\ref{eq:compat-fct-2} by solving:\n\\[\n    \\min_{\\phi, w} \\E_{s, a \\sim \\pi_\\theta}\\left[\n    \\left(Q^\\pi(s,a) - f_\\phi(s,a) - v_w(s)\\right)^2\n    \\right]\n\\]\nfor some function $v_w:\\mathcal{S} \\rightarrow \\mathbb{R}$ \\demo. In practice, TD is used to estimate $V^\\pi$ with $v_w$, and $Q^\\pi$ with $f_\\phi + v_w$, so that $f_\\phi(s,a) \\approx A^\\pi(s,a)$.\n\n\\paragraph{Actor-Critic with Generalized Advantage Estimation (GAE) \\cite{schulman2015high}}\nThis method only requires estimating $V^\\pi$ (easier to learn than $Q^\\pi(s,a) \\forall s,a$, especially in high dimension) to obtain an estimate of $A^\\pi$.\nSimilar to multi-steps learning, we can define the \\emph{n-steps advantage estimate}:\n\\begin{equation}\n    A_t^{(n)} = r_t + \\gamma r_{t+1} + \\dots + \\gamma^{n-1} r_{t+n-1} + \\gamma^n V^\\pi(s_{t+n}) - V^\\pi(s_t)\n\\label{eq:n-steps-advantage}\n\\end{equation}\nand control the bias-variance trade-off with $n$ ($n=1$: lower variance but higher bias when the estimate of $V^\\pi$ is wrong, $n\\rightarrow \\infty$: Monte-Carlo estimate, no bias but higher variance). Like TD($\\lambda$) learning, GAE averages the estimates and uses $\\lambda \\in [0,1]$ to control the trade-off:\n\\[\n    A_t^{GAE(\\gamma,\\lambda)} = (1-\\lambda) \\sum_{n=0}^\\infty \\lambda^n A_t^{(n)} = \\sum_{n=0}^\\infty (\\lambda \\gamma)^n \\delta_{t+n}\n\\]\nHere as well, eligibility traces are a way to implement GAE$(\\gamma,\\lambda)$. Indeed, we can re-write the sample estimate of the policy gradient:\n\\[\n    \\sum_{t=0}^\\infty A_t^{GAE(\\gamma,\\lambda)} \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t)\n    = \\sum_{t=0}^\\infty \\nabla_\\theta \\log \\pi_\\theta(a_t \\mid  s_t) \\sum_{n=0}^\\infty (\\gamma \\lambda)^n \\delta_{t+n}\n\\]\n\n\\begin{algorithm}[H]\n\\DontPrintSemicolon\n\\For{a number of episodes}{\n    initialize $s_0$ and set $e_0(s)=0, \\forall s$\\;\n     \\While{episode not done}{\n        take action $a_t \\sim \\pi(\\cdot \\mid s_t)$, observe $r_t$ and $s_{t+1}$ \\;\n        \\For{all $s$}{\n          $e_t(s) \\leftarrow \\lambda \\gamma e_{t-1}(s) + \\mathbbm{1}_{s_t=s}$ \\tcp*{this leads to $e_t(s) = \\sum_{k=0}^t(\\lambda \\gamma)^{t-k} \\mathbbm{1}_{s_k=s}$}\n          $V(s_t) \\leftarrow V(s_t) + \\alpha e_t(s) \\delta_t$ \\;\n        } \n    }\n}\n\\caption{Actor-critic with GAE, using eligibility traces}\n\\label{algo:gae-eligibility-traces}\n\\end{algorithm}\n\n% todo: add algos, e.g. learn $V^\\pi ?$\n\n\\paragraph{A2C / A3C}\n\\emph{Asynchronous Advantage Actor Critic} (A3C) \\cite{mnih2016asynchronous} and its synchronous version A2C are two widely used actor-critic methods. They both run $n$ environments in parallel to get better estimates of the returns (more samples = less variance).\n\\begin{itemize}\n    \\item Both a policy $\\pi_\\theta$ and a value function $V^{\\pi}_{\\theta_v}$ are learned. Most of the layers are shared (fig. \\ref{fig:actor-critic-architecture}).\n    \\item \\emph{Asynchronous}. The A3C updates are done asynchronously: each agent sends its gradient to the global network every $k$ steps and updates its local weights after that.\n    \\item \\emph{Advantage}. Use the $n$-steps return (forward view, eq. \\ref{eq:n-steps-advantage}) to learn $V^\\pi_{\\theta_v}$ and to estimate the advantage function $A^\\pi$.\n\\end{itemize}\nThe A2C algorithm works the same way but with synchronous, deterministic updates. It waits for all agents to be done with the $k$ steps, before performing a batch update and updating all weights at the same time.\n\n% todo: give actual formula (and algo) of A3C/A2C, cf https://arxiv.org/pdf/1611.01224.pdf\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.8\\linewidth]{figures/shared-actor-critic-network.png}\n    \\caption{Example of a shared network architecture for actor-critic methods.}\n    \\label{fig:actor-critic-architecture}\n\\end{figure}\n\n\\paragraph{Entropy}\nTo encourage exploration and avoid converging on a deterministic policy too fast, an entropy cost can be added to the policy gradient update: \n\\[\n    \\theta \\leftarrow \\theta + \\alpha (\\nabla_\\theta J(\\theta) + \\nabla_\\theta H_\\theta(s_t))\n\\]\nWith\n\\[\n    H_\\theta(s_t) = - \\sum_a \\pi_\\theta(a_t\\mid s_t) \\log \\pi_\\theta(a_t\\mid s_t)\n\\]\nthe entropy term to maximize.\n\n\\paragraph{Relative Policy Performance Bound}\nInstead of looking directly for $\\max_\\pi J(\\pi)$, we can optimize the \\emph{relative performance} between $\\pi$ and and arbitrary policy $\\pi_{old}$: $\\max_\\pi J(\\pi) - J(\\pi_{old})$. For any policies $\\pi = \\pi_\\theta$, $\\pi_{old} = \\pi_{\\theta_{old}}$, we have the \\emph{relative performance bound}:\n\\begin{align}\n    J(\\pi) - J(\\pi_{old}) \n    &= \\E_{\\tau \\sim \\pi} \\left[ \\sum_{t=0}^\\infty \\gamma^t A^{\\pi_{old}}(s_t,a_t) \\right] \\nonumber\\\\\n    &= \\frac{1}{1-\\gamma} \\E_{s\\sim d^\\pi(s), a \\sim \\pi_{old}(a\\mid s)} \\left[ \\frac{\\pi(a\\mid s)}{\\pi_{old}(a\\mid s)} A^{\\pi_{old}}(s,a)\\right] \\nonumber\\\\\n    &\\geq \\underbrace{\\frac{1}{1-\\gamma} \\E_{s\\sim d^{\\pi_{old}}(s), a \\sim \\pi_{old}(a\\mid s)} \\left[ \n        \\frac{\\pi(a\\mid s)}{\\pi_{old}(a\\mid s)} A^{\\pi_{old}}(s,a)\n    \\right]}_{=L_{\\theta_{old}}(\\theta)} - C D_{KL}^{max}(\\pi \\mid \\mid  \\pi_{old})\n    \\label{eq:performance-bound}\n\\end{align}\nwith\n\\begin{itemize}\n    \\item The \\emph{discounted state distribution} of policy $\\pi$\n    \\begin{equation}\n        d^\\pi(s) = (1-\\gamma) \\sum_{t=0}^\\infty \\gamma^t P(s_{t}=s\\mid \\pi)\n    \\label{eq:stationary-state-distribution}\n    \\end{equation}\n% According to Sylvain Lamprier, \n% FALSE:   According to \\href{https://eva.fing.edu.uy/pluginfile.php/343525/mod_resource/content/1/modern_methods.pdf}{this}, \\href{https://lilianweng.github.io/lil-log/2018/04/08/policy-gradient-algorithms.html#policy-gradient-theorem}{this}, \\href{https://www.alexirpan.com/rl-derivations/#state-visitation--occupency-measure}{this} and \\href{https://proceedings.neurips.cc//paper/2020/file/69bfa2aa2b7b139ff581a806abf0a886-Paper.pdf}{this} (to check?), \n    This is \\emph{not} the same as the \\emph{stationary distribution}:\n    \\[\n        d^\\pi(s) = \\lim_{t\\rightarrow \\infty} P(s_t = s \\mid \\pi)\n    \\]\n    \\item $D_{KL}^{max}(\\pi \\mid \\mid  \\pi_{old}) = \\max_s D_{KL}[\\pi(\\cdot\\mid s) \\mid \\mid  \\pi_{old}(\\cdot\\mid s)]$\n    \\item $C$ a factor that depends on $\\gamma$ and $\\pi_{old}$\n\\end{itemize}\nA number of algorithms (e.g. TRPO, PPO) maximize this lower bound of the relative performance, by keeping $\\pi$ (current policy) and $\\pi_{old}$ (old policy) close and maximizing objective $L_{\\theta_{old}}(\\theta)$. This has the advantages of:\n\\begin{enumerate}\n    \\item Re-using past samples, since $s,a$ are sampled from the old policy $\\pi_{old}$ in the training objective $L_{\\theta_{old}}(\\theta)$. This is more sample-efficient.\n    \\item Controlling the policy updates in the space of distributions instead of the space of parameters, thanks to the KL divergence term. This makes updates smoother and training more stable.\n\\end{enumerate}\n\n\\paragraph{Trust Region Policy Optimization (TRPO) \\cite{schulman2015trust}}\nTRPO considers an approximate objective to eq. \\ref{eq:performance-bound}. Since the penalty coefficient $C$ can be very large and lead to very small updates, it uses a hard constraint of the $D_{KL}$ (trust region), and since $D_{KL}^{max}$ is hard to optimize it uses $\\overline{D}_{KL}$ instead.\n\\begin{equation}\n    \\max_\\theta L_{\\theta_{old}}(\\theta) \n    \\quad \\text{subject to} \\quad\n    \\underbrace{\n        \\E_{s \\sim d^{\\pi_{old}}}[D_{KL}(\\pi(\\cdot\\mid s) \\mid \\mid  \\pi_{old}(\\cdot\\mid s)]\n    }_{=\\overline{D}_{KL}(\\pi\\mid \\mid \\pi_{old})}\n    \\leq \\delta    \n\\label{eq:trpo-exact}\n\\end{equation}\nfor some hyper-parameter $\\delta$.\nUsing Taylor approximation, this training objective (eq. \\ref{eq:trpo-exact}) is replaced by\n\\begin{equation}\n    \\max_\\theta g^T (\\theta - \\theta_{old})\n    \\quad \\text{s.t.} \\quad\n    \\frac{1}{2}(\\theta-\\theta_{old})^T F (\\theta-\\theta_{old}) \\leq \\delta\n\\label{eq:trpo-taylor-approx}\n\\end{equation}\nwith\n\\begin{align*}\ng \n    &= \\nabla_\\theta L_{\\theta_{old}}(\\theta)\\big|_{\\theta=\\theta_{old}} \\\\\n    &= \\nabla_\\theta J(\\theta)\\big|_{\\theta=\\theta_{old}} \n    \\qquad \\text{(only at $\\theta=\\theta_{old}$)} \\\\\n    &= \\frac{1}{1-\\gamma} \n    \\E_{s\\sim d^{\\pi_{old}}, a \\sim \\pi_{old}(\\cdot\\mid s)}\\left[\n        \\nabla_\\theta \\log \\pi_\\theta(a\\mid s)\\big|_{\\theta=\\theta_{old}} A^{\\pi_k}(s,a)\n    \\right]\n\\end{align*}\nand\n\\begin{align*}\nF \n    &= \\nabla^2_\\theta \\overline{D}_{KL}(\\pi\\mid \\mid \\pi_{old})\\big|_{\\theta=\\theta_{old}} \\\\\n    &= \\E_{s\\sim d^{\\pi_{old}}}\\left[\n        \\nabla^2_\\theta D_{KL}(\\pi(\\cdot\\mid s)\\mid \\mid \\pi_{old}(\\cdot\\mid s))\\big|_{\\theta=\\theta_{old}}\n    \\right]\n\\end{align*}\n\nAt each iteration, sample estimates of the gradient $g$ and Fisher matrix $F$ can be computed, and the constrained optimization objective of eq. \\ref{eq:trpo-taylor-approx} is solved approximately. The solution\n\\footnote{This update step does not take into account architectures using dropout or shared parameters between policy and value function.}\n(obtained by deriving KKT conditions) is:\n\\[\n    \\theta = \\theta_{old} + \\beta F^{-1} g\n    \\qquad \\text{with} \\qquad\n    \\beta = \\sqrt{\\frac{2\\delta}{g^T F^{-1} g}}\n\\]\nInstead of directly inverting $F$ (impossible with deep and large models), the conjugate gradient method solves $Fx=g$ (max $d$ steps with $\\theta \\in \\mathbb{R}^d$) and obtains an estimate of $x=F^{-1}g$, called the natural gradient\n\\footnote{The natural gradient is effectively a gradient in the space of the distributions (using distance $D_{KL}(\\pi_{\\theta}\\mid \\mid \\pi_{\\theta_{old}})$), rather than the space of parameters (with euclidean distance on parameters $\\theta$). More details \\href{https://julien-vitay.net/deeprl/NaturalGradient.html}{here}.}.\nThe update steps becomes:\n\\[\n    \\theta = \\theta_{old} + \\sqrt{\\frac{2\\delta}{x^T F x}} x\n\\]\nFinally, a \\emph{backtracking line search} adjusts the step size in order to make the largest update that effectively improves the objective $L_{\\theta_{old}}(\\theta)$ and respects the constraint $\\overline{D}_{KL}(\\pi\\mid \\mid \\pi_{old}) \\leq \\delta$ (which may be violated due to the approximations).\n\n\\paragraph{Natural Gradient with compatible functions}\nWhen using a compatible function for the advantage estimation (eq. \\ref{eq:compat-fct-1} and \\ref{eq:compat-fct-2}), it follows that $F \\phi = \\nabla_\\theta J(\\theta)$ \\demo, and $\\phi = F^{-1} \\nabla_\\theta J(\\theta)$ is actually the natural gradient (cf TRPO).\n\nAn incremental algorithm is suggested by \\cite{bhatnagar2007incremental}, using learning rate $\\alpha_i$ for the update of the critic (parameters $\\phi$ and $w$, cf \\emph{Actor-Critic with compatible functions}), and learning rate $\\beta_i$ for the policy: $\\theta \\leftarrow \\theta + \\beta_i \\phi$. This ensures that the critic converges faster than the actor. In practice however, the learning rates are hard to tune (approaches doing batch updates and adding an entropy cost have been suggested to make training more stable \\cite{pajarinen2019compatible}).\n\n\\paragraph{Proximal Policy Optimization (PPO) \\cite{schulman2017proximal}}\nSecond-order optimization methods like natural gradients perform well, but are computationally expensive and complex to implement. PPO mimics the reliable trust-region update of TRPO, but using a simpler first-order method. Two versions are proposed:\n\\begin{itemize}\n    \\item \\emph{Adaptive KL penalty}. Consider the following unconstrained objective to maximize:\n    \\begin{align*}\n        \\mathcal{L}^{KL}(\\theta) \n        &= L_{\\theta_{old}}(\\theta) - \n        \\beta_k \\overline{D}_{KL}(\\pi\\mid \\mid \\pi_{old}) \\\\\n        &= \\E_{s,a\\sim \\pi_{old}} \\left[\n            \\frac{\\pi(a\\mid s)}{\\pi_{old}(a\\mid s)} A^{\\pi_{old}}(s,a)\n            - \\beta_k D_{KL}[\\pi(\\cdot\\mid s)\\mid \\mid \\pi_{old}(\\cdot\\mid s)]\n        \\right]\n    \\end{align*}\n    With $\\beta_k$ an adaptive KL penalty term ensuring that $\\overline{D}_{KL}(\\pi\\mid \\mid \\pi_{old})$ stays close to $\\delta$ most of the time.\n    % todo: algo\n    \\item \\emph{Clipped objective}.\n    \\[\n        \\mathcal{L}^{CLIP}(\\theta) \n        = \\E_{s,a\\sim \\pi_{old}} \\left[\n            \\min(r_t(\\theta) A^{\\pi_{old}}_t, \\text{clip}(r_t(\\theta), 1-\\epsilon, 1+\\epsilon) A^{\\pi_{old}}_t)\n        \\right]\n    \\]\n    With $r_t(\\theta) = \\frac{\\pi_\\theta(a_t\\mid s_t)}{\\pi_{\\theta_{old}}(a_t,s_t)}$ and $A^{\\pi_{old}}_t = A^{\\pi_{old}}(s_t,a_t)$. As illustrated in figure \\ref{fig:ppo-clip}, this objective is a pessimistic lower bound of $\\frac{\\pi(a\\mid s)}{\\pi_{old}(a\\mid s)} A^{\\pi_{old}}(s,a)$, and effectively discourage too large improvements of policy $\\pi_\\theta$ by clipping the probability ratio. Updates in the wrong direction, i.e. that deteriorate $\\pi_\\theta$, remain fully penalized. \n\\end{itemize}\nCompared to TRPO, PPO makes it straightforward to share parameters between the policy and value functions. Also, re-using the sampled data $\\mathcal{D}_k$ for $K$ update steps makes it more data-efficient.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=0.5\\linewidth]{figures/ppo-clip.png}\n    \\caption{\\emph{PPO w/ clipped objective}. Plots showing $\\mathcal{L}^{CLIP}$ as a function of the probability ratio $r$, for positive advantages (left) and negative advantages (right). The red circle on each plot shows the starting point for the optimization, i.e., $r=1$. More detailed explanations \\href{https://stackoverflow.com/a/50663200}{here}. Figure taken from \\cite{schulman2017proximal}.}\n    \\label{fig:ppo-clip}\n\\end{figure}\n\n\\subsection{Off-Policy}\nAlthough actor-critic methods such as PPO or A2C/A3C are already re-using a couple recent samples, they are not as sample-efficient as off-policy value-based methods. \\emph{Off-policy policy gradient} methods improve this, and make it possible to define better exploration strategies.\n\nIn this section, samples are collected with a \\emph{behavior policy} $\\mu$, typically different from our learned policy $\\pi_\\theta$.\n\n\\paragraph{Off-policy policy gradient theorem}\nGiven a behavior policy $\\mu$ and its stationary distribution $d^\\mu(s) = \\lim_{t\\rightarrow \\infty} P(s_t = s \\mid \\mu)$ (see eq. \\ref{eq:stationary-state-distribution}), we can define an \\emph{off-policy performance objective} \\footnote{\nThis is slightly different from the on-policy reward that we have been considering so far: $J(\\theta) = \\E_{\\tau \\sim \\pi_\\theta}[R(\\tau)] = \\E_{s_0 \\sim \\rho_0}[V^{\\pi_\\theta}(s_0)]$.\n}:\n\n\\[\n    J_\\mu(\\theta) = \\E_{s_0 \\sim \\mu}[V^{\\pi_\\theta}(s_0)]\n\\]\nThe off-policy policy gradient can then be expressed as:\n\\begin{align}\n    \\nabla_\\theta J_\\mu(\\theta)\n    &= \\nabla_\\theta \\E_{s\\sim d^\\mu} \\left[ \\sum_a \\pi_\\theta(a\\mid s) Q^{\\pi_\\theta}(s,a) \\right] \\nonumber \\\\\n    &= \\E_{s\\sim d^\\mu} \\left[ \n        \\sum_a \\nabla_\\theta \\pi_\\theta(a\\mid s) Q^{\\pi_\\theta}(s,a) + \n        \\underbrace{\\pi_\\theta(a\\mid s) \\nabla_\\theta Q^{\\pi_\\theta}(s,a)}_{\\approx 0}\n    \\right] \\nonumber \\\\\n    &\\approx \\E_{s,a \\sim \\mu} \\left[\n        \\frac{\\pi_\\theta(a\\mid s)}{\\mu(a\\mid s)} Q^{\\pi_\\theta}(s,a) \\nabla_\\theta \\log \\pi_\\theta(a\\mid s)\n    \\right]\n    \\label{eq:off-policy-policy-gradient}\n\\end{align}\n\nThe approximation is necessary since $\\nabla_\\theta Q^{\\pi_\\theta}(s,a)$ is typically hard to compute. However, this biased gradient still improves the policy and allows converging to the right solution, at least in the tabular case (off-policy policy gradient theorem, \\cite{degris2012off}).\n\n\\emph{Note}. Eq. \\ref{eq:off-policy-policy-gradient} closely resembles the on-policy gradient (eq. \\ref{eq:policy-gradient}), but with an added weight $\\frac{\\pi_\\theta(a\\mid s)}{\\mu(a\\mid s)}$, and using the stationary distribution. \nThe \\emph{policy gradient theorem} \\footnote{Proof can be found \\href{https://lilianweng.github.io/lil-log/2018/04/08/policy-gradient-algorithms.html\\#policy-gradient-theorem}{here} or \\href{https://stanford.edu/~ashlearn/RLForFinanceBook/PolicyGradient.pdf}{here}} actually states that:\n\\begin{align}\n    \\nabla_\\theta J(\\theta)\n    &= \\E_{s\\sim d^{\\pi_\\theta}} \\left[ \\sum_a Q^{\\pi_\\theta}(s,a) \\nabla_\\theta \\pi_\\theta(a\\mid s) \\right]\n    \\nonumber \\\\\n    &= \\E_{s,a\\sim \\pi_\\theta} \\left[ Q^{\\pi_\\theta}(s,a) \\nabla_\\theta \\log \\pi_\\theta(a\\mid s) \\right]\n\\end{align}\n\n\\paragraph{Estimating $Q^\\pi$ in off-policy}\n\n\\emph{Tabular case (discrete action and state spaces)}.\nUsing a slightly different TD error $\\delta_t = r_t + \\gamma \\E_{a\\sim \\pi(\\dot \\mid s_{t+1}}[Q(s_{t+1})] - Q(s_t,a_t)$, we can estimate $Q^\\pi$ with TD-0 learning, even if our samples $(s_t, a_t, s_{t+1})$ are not collected with policy $\\pi$:\n\\[\nQ(s_t, a_t) \\leftarrow Q(s_t, a_t) + \\alpha \\delta_t\n\\]\n\nMulti-step learning is harder however, since the next actions $a_{t+k}$ are sampled from the behavior policy $\\mu$:\n\\[\nQ(s, a) \\leftarrow Q(s, a) + \\alpha \\E_{s_t,a_t,s_{t+1} \\sim \\mu, \\forall t} \\left[ \n    \\sum_{t=0}^k \\gamma^t \\left( \\prod_{i=0}^t c_i \\right) \\left( \n        r_t + \\gamma \\E_{a_{t+1}\\sim \\pi} [Q(s_{t+1}, a_{t+1})] - Q(s_t,a_t)\n    \\right) \\mid s_0 = s, a_0 = a\n\\right]\n\\]\nWith $c_i$ a coefficient that can be\n\\begin{itemize}\n    \\item $c_i = \\lambda$: regular $Q(\\lambda)$ algorithm, but biased since we are off-policy, and only converges if $\\mu$ and $\\pi$ are close\n    \\item $c_i = \\frac{\\pi(a_i\\mid s_i)}{\\mu(a_i\\mid s_i)}$: unbiased thanks to importance sampling, but not stable (high variance)\n    \\item $c_i = \\lambda \\pi(a_i\\mid s_i)$: \\emph{Tree Backup} \\cite{precup2000eligibility} works even when $\\mu$ and $\\pi$ are different, but not efficient due to premature “cuts” if $\\pi(a_i\\mid s_i)$ becomes small.\n    \\item $c_i = \\lambda \\min(1, \\frac{\\pi(a_i\\mid s_i)}{\\mu(a_i\\mid s_i)})$: \\emph{Retrace} \\cite{munos2016safe} combines the best of both worlds, with controlled variance $c_i \\leq \\lambda$), no premature “cuts”, and even has guarantees of convergence.\n\\end{itemize}\n\n\\emph{Approximate case (e.g. continuous state space)}.\nHere as well we can use the Retrace coefficient $c_i$, but learning $Q_\\theta(s,a)$ requires a target value $Q^{ret}$ in order to compute an error (e.g. least square) and a gradient. For each trajectory $\\tau$, the target can be defined recursively (starting from the final value $Q^{ret}(s_{T-1}, a_{T-1}) = r_{T-1}$):\n\\[\nQ^{ret}(s_t, a_t) = r_t + \\gamma c_{t+1} [Q^{ret}(s_{t+1}, a_{t+1}) - Q_\\theta(s_{t+1}, a_{t+1})] + \\gamma E_{a\\sim \\pi} Q_\\theta(s_{t+1}, a)\n\\]\n\n\\paragraph{Actor-Critic with Experience Replay (ACER)} \\cite{wang2016sample}\nSimilar to on-policy actor critic methods (e.g. A3C/A2C), learning an estimate of $Q^\\pi$ in eq. \\ref{eq:off-policy-policy-gradient} can reduce the variance. ACER decomposes $\\nabla_\\theta J_\\mu(\\theta)$ into\n\\begin{align*}\n\\nabla_\\theta J_\\mu(\\theta) = \\E_{s_t\\sim \\mu} \\biggl[\n    & \\E_{a_t\\sim \\mu}[\n        \\min(c, \\omega_t(a_t)) Q^\\pi(s_t, a_t) \\nabla_\\theta \\log \\pi_\\theta(a_t\\mid s_t)\n    ] \\\\\n    & + \\E_{a\\sim \\pi}\\left[\n        \\max\\left(0, \\frac{\\omega_t(a)-c}{\\omega_t(a)}\\right) Q^\\pi(s_t, a) \\nabla_\\theta \\log \\pi_\\theta(a\\mid s_t)\n    \\right]\n\\biggr]\n\\end{align*}\n\nWith $c$ a hyper-parameter and $\\omega_t(a) = \\frac{\\pi(a\\mid s_t)}{\\mu(a\\mid s_t)}$ the importance sampling ratio. The left term clips this ratio to bound the variance, the right term ensures that the estimate is unbiased. Using our estimates of $Q^\\pi$, and substracting our estimate $V_{\\theta_v}$ of $V^\\pi$ to further reduce the variance, the gradient estimate becomes:\n\\begin{align*}\n    g_t^\\text{acer} = \n    & \\min(c, \\omega_t(a_t)) (Q^{ret}(s_t, a_t) - V_{\\theta_v}(s_t)) \\nabla_\\theta \\log \\pi_\\theta(a_t\\mid s_t) \\\\\n    &+ \\E_{a\\sim \\pi}\\left[\n        \\max\\left(0, \\frac{\\omega_t(a)-c}{\\omega_t(a)}\\right) \n        (Q_{\\theta_v}(s_t, a) - V_{\\theta_v}(s_t)) \\nabla_\\theta \\log \\pi_\\theta(a\\mid s_t)\n    \\right]\n\\end{align*}\n\nIn addition to this, ACER does trust-region updates (like TRPO) but actually considers the gradient $g_{\\phi_\\theta(s_t)}$ w.r.t. the policy distribution parameters $\\phi_\\theta(s)$ (e.g. logits or probability vector of discrete actions) instead of the model parameters $\\theta$. With $\\pi_{\\theta_a}$ a smoothly updated average policy, the following optimisation problem is solved: \n\\[\n    \\min_z \\frac{1}{2} \\mid \\mid g_{\\phi_\\theta(s_t)} - z\\mid \\mid ^2 \\quad \\text{s.t.} \\quad\n    \\nabla_{\\phi_\\theta(s_t)} D_{KL}[\n        \\pi_{\\theta_a}(\\cdot \\mid s_t) \\mid \\mid \\pi_\\theta(\\cdot \\mid s_t)\n    ]^T z \\leq \\delta\n\\]\nWhich has a closed form solution $z^*$. Policy parameters $\\theta$ are updated using the gradient $g_\\theta = z^* \\nabla_\\theta \\phi_\\theta(s_t)$.\n\n\n\\subsection{Continuous Action Spaces}\nPrevious policy gradients methods can be used with either a discrete or continuous action space (e.g. $\\mathcal{A} \\in \\mathbb{R}^d, \\pi(a\\mid s) = \\mathcal{N}(a; \\mu_\\theta(s), \\Sigma_\\theta(s))$). But continuous action spaces actually allow taking the gradient w.r.t. actions $\\nabla_a Q_\\theta(s,a)$ and deriving specific algorithms.\n\n\\paragraph{Deterministic Policy Gradients (DPG/DDPG)} \\cite{silver2014deterministic} \\cite{lillicrap2015continuous}\nIn addition to a continuous action space, DPG considers a non-stochastic policy taking actions $a = \\mu_\\theta(s)$. The on-policy policy gradient becomes:\n\\begin{equation}\n    \\nabla_\\theta J(\\theta) = \\E_{s\\sim d^{\\pi_\\theta}} \\left[\n        \\nabla_a Q^{\\pi_\\theta}(s,a) \\Bigr|_{a=\\mu_\\theta(s)} \\nabla_\\theta \\mu_\\theta(s)\n    \\right]\n\\label{eq:ddpg-on-policy}\n\\end{equation}\nAnd critic $Q^{\\pi_\\theta}$ can be learned with SARSA updates.\n\nIn order to add exploration and to be more sample-efficient, an off-policy version is also proposed:\n\\begin{equation}\n    \\nabla_\\theta J_\\beta(\\theta) \\approx \\E_{s\\sim d^\\beta} \\left[\n        \\nabla_a Q^{\\pi_\\theta}(s,a) \\Bigr|_{a=\\mu_\\theta(s)} \\nabla_\\theta \\mu_\\theta(s)\n    \\right]\n\\label{eq:ddpg-off-policy}\n\\end{equation}\nDoing the same approximation as in \\ref{eq:off-policy-policy-gradient} (and this time we call $\\beta$ the behavior policy). Critic can be learned with Q-learning updates.\n\nDDPG simply implements the off-policy version of DPG with deep neural networks for $Q^\\pi$ and $\\mu_\\theta$, and adding noise to $\\mu_\\theta$ to construct the exploration policy. Stability is achieved by using tricks from DQN: replay buffer, target networks and soft updates. A couple extensions use additional tricks: 2 value networks $Q^\\pi$ like Double DQN (TD3 \\cite{fujimoto2018addressing}), Prioritized replay and a distributional critic (D4G \\cite{barth2018distributed}).\n\n\n\\paragraph{Policy gradient with an off-policy critic (Q-Prop)} \\cite{gu2016q}\nWhile off-policy methods like DDPG are more sample efficient than REINFORCE, the off-policy gradient (eq. \\ref{eq:ddpg-off-policy}) is biased and typically less stable (requiring fine hyper-parameter optimization). The Q-Prop algorithm uses an unbiased on-policy gradient (more stable) but reduces the variance (more sample efficient) thanks a control variate $\\eta(s_t)$ and an off-policy critic $Q_w$ learned like in DDPG.\n\n\\begin{align}\n    \\nabla_\\theta J(\\theta) = \n    & \\E_{s_t\\sim d^\\pi, a_t \\sim \\pi} \\underbrace{\n        \\left[\n            \\nabla_\\theta \\log \\pi_\\theta(a_t\\mid s_t) (\\hat{A}(s_t,a_t) - \\eta(s_t) \\overline{A_w}(s_t,a_t))\n        \\right]\n    }_{\n        \\text{REINFORCE correction term ($\\approx 0$ if $Q_w$ is good)}\n    }\n    \\nonumber \\\\\n    & + \\E_{s_t\\sim d^\\pi} \\underbrace{\n        \\left[\n            \\eta(s_t) \\nabla_a Q_w(s_t,a) \\Bigr|_{a=\\mu_\\theta(s_t)} \\nabla_\\theta \\mu_\\theta(s_t)\n        \\right]\n    }_{\n        \\text{On-policy policy gradient with control variate $\\eta(s_t)$}\n    }\n\\end{align}\n\nWith\n\\begin{itemize}\n    \\item $\\overline{Q}(s_t,a_t) = Q_w(s_t, \\mu_\\theta(s_t)) + \\nabla_a Q_w(s_t,a) \\Bigr|_{a=\\mu_\\theta(s_t)}(a_t-\\mu_\\theta(s_t))$ (1st order Taylor approximation)\n    \\item $\\overline{A}(s_t,a_t) = \\overline{Q}(s_t,a_t) - \\E_{a \\sim \\pi_\\theta}\\left[\\overline{Q}(s_t,a)\\right] = \\nabla_a Q_w(s_t, a) \\Bigr|_{a=\\mu_\\theta(s_t)} (a_t-\\mu_\\theta(s_t))$\n    \\item $\\hat{A}(s_t,a_t)$ estimated with GAE (using $V_w$ learned on-policy)\n    \\item $\\eta(s_t) = 1$ if $\\hat{A}(s_t,a_t) \\overline{A}(s_t,a_t) > 0$ (i.e. our estimate of $A^\\pi$ according to $Q_w$ at least has the same sign than the observed advantage $\\hat{A}$), and $\\eta(s_t) = 0$ otherwise.\n\\end{itemize}", "meta": {"hexsha": "90ee6718a83cbef2dd2ca5e51432cc2a511d5652", "size": 29373, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/5_policy_gradients.tex", "max_stars_repo_name": "alexandrethm/rl-cheatseet", "max_stars_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-06-18T23:54:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T11:54:02.000Z", "max_issues_repo_path": "sections/5_policy_gradients.tex", "max_issues_repo_name": "alexandrethm/rl-cheatsheet", "max_issues_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/5_policy_gradients.tex", "max_forks_repo_name": "alexandrethm/rl-cheatsheet", "max_forks_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.2151029748, "max_line_length": 559, "alphanum_fraction": 0.686140333, "num_tokens": 9555, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067211996142, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7749187775077734}}
{"text": "\\chapter{Real tuple spaces}\n\nEarlier, we defined \\enquote{space} as another word for \\enquote{set} because we want\nthat definition to include every real tuple space.\n\nThe set \\(\\Real^n\\) is the set of all real \\(n\\)-tuples.\n\nThe dimension of \\(\\Real^n\\) is \\(n\\).\n\nAn example element of \\(\\Real^3\\) is \\((1,2,3)\\).\n\n\\section{An example basis}\n\nImagine a flat sheet of paper.\n\nDraw a point \\(A\\).\n\nDraw a vector named \\(i\\), from \\(A\\), \\SI{1}{cm} long, pointing right.\n\nDraw another vector named \\(j\\), also from \\(A\\), \\SI{1}{cm} long, but pointing up.\n\nThus, the vectors \\(i\\) and \\(j\\) are orthogonal.\n\nThen, we declare the basis\n\\( e : \\Real^2 \\to E^2 \\) as \\( e(x,y) = xi + yj \\).%\n\n\\section{Cartesian coordinate system}\n\nLet \\(E^n\\) mean the \\(n\\)-dimensional Euclidean space.\n\nThe \\(n\\)-dimensional Cartesian coordinate system matches\na point in \\(E^n\\) and a point in \\(\\Real^n\\).\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Cartesian_coordinate_system}}\n\nFor example...\n\nWhat mapping is drawn in \\FigureRef{fig:a-2d-cartesian-coordinate-system}?\n\n\\begin{figure}[h]\n    \\centering\n    \\url{https://en.wikipedia.org/wiki/File:Cartesian-coordinate-system.svg}\n    \\caption{A two-dimensional Cartesian coordinate system}\n    \\label{fig:a-2d-cartesian-coordinate-system}\n\\end{figure}\n\n\\section{Example of geometry with numbers: describing a circle in \\(\\Real^2\\)}\n\nEvery variable is a real number unless specified otherwise.\n\nAssume a two-dimensional Cartesian coordinate system.\n\nConsider a circle \\(C\\) with center \\((0,0)\\) and radius 1.\nThat circle can be described in two ways:\nthe algebraic description \\eqref{eq:set-circle-algebraic},\nand the parametric description \\eqref{eq:set-circle-parametric}.\nBoth sets have the same members and describe the same circle.\n\\begin{align}\n    \\label{eq:set-circle-algebraic}\n    C_{\\text{algebraic}} &= \\{ (x,y) ~|~ x^2 + y^2 = 1 \\}\n    \\\\\n    \\label{eq:set-circle-parametric}\n    C_{\\text{parametric}} &= \\{ (r \\cos t, r \\sin t) ~|~ t \\in [0,2\\pi] \\}\n\\end{align}\n\nThe parametric description \\eqref{eq:set-circle-parametric}\ntells us that the dimension of \\(C\\) is one\nbecause the description uses one parameter \\(t\\).\n\n\\FIXME{Rename \\enquote{parametric description} to \\enquote{chart}?}\n\nThe derivative of the parametric function is the curve's velocity.\n\nA shape's dimension is the number of parameters in its parametric description.\n\nTo see that both sets does describe a circle (and the same circle),\nwe can plot the graph of both sets.\n\n\\section*{Describing a curve parametrically or algebraically}\n\n\\paragraph{Using parametric equations}\n\nWe can describe a curve with a function of type \\( \\Real \\to \\Real^n \\).\nFor example, we can write \\(x(t) = (r \\cos t, r \\sin t)\\) to describe a circle of radius \\(r\\).\nWe can also write the same equation as a set of parametric equations:\n\\(x(t) = r \\cos t\\) and \\(y(t) = r \\sin t\\).\n\n\\paragraph{Using algebraic equations}\n\nWe can describe a circle as \\( \\{ (x,y) ~|~ (x,y) \\in \\Real^2, ~ x^2 + y^2 = r^2 \\} \\).\nThe equation describes a circle because the set of all points satisfying the equation forms a circle.\n\n\\paragraph{Comparing the approaches}\n\nThe parametric equation of a circle simplifies computing the derivative.\n\nThe algebraic equation of a circle simplifies computing the distance.\n\n\\section*{Calculating the length of a parametric curve}\n\nLet the function \\(x : \\Real \\to \\Real^n\\) describe a curve.\n\nDefine \\(X(T) = \\{ x(t) ~|~ t \\in T \\}\\) as the \\emph{image of \\(T\\) under \\(x\\)}.\n\\footnote{\\url{https://en.wikipedia.org/wiki/Image_(mathematics)}}\n\nThe segment between \\(a\\) and \\(b\\) is \\( X([a,b]) = \\{ x(k) ~|~ a \\le k \\le b \\} \\).\nWhat is the length of this segment?\n\nDivide the curve into many segments.\nApproximate each segment as a straight line segment.\n\nThe \\emph{arc length}.\n\nThe length of the segment of \\(x\\) in \\(T\\) is\n\\begin{align*}\n    L(x,T) &= \\sum_k \\norm{x(t_{k+1}) - x(t_k)}\n    \\\\ &= \\sum_k \\frac{\\norm{x(t_k + h_k) - x(t_k)}}{h_k} \\cdot h_k\n    \\\\ &= \\int_T \\abs{x'(t)} \\dd{t}\n\\end{align*}\n\nWikipedia\\footnote{\\url{https://en.wikipedia.org/wiki/Arc_length\\#Definition_for_a_smooth_curve}}\nexplains how to derive that equation.\nThe key is to multiply by \\(h_k / h_k\\).\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Arc_length}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Curve\\#Length_of_a_curve}}%\n\\footnote{\\url{http://mathworld.wolfram.com/ArcLength.html}}\n\n\\section*{Describing a surface}\n\nAn example of a space is \\( \\{ (x,y,z) ~|~ x^2+y^2+z^2 = 1 \\} \\), the skin of the unit sphere in a 3-dimensional Euclidean space.\n\nA \\emph{smooth space} looks smooth (no discontinuities).\nIt has something to do with differentiability.\n\n\\section*{Describing spaces using vectors}\n\n\\section*{Describing a line, a plane, and a hyperplane}\n\nA line is a two-dimensional hyperplane.\nA plane is a three-dimensional hyperplane.\n\nThe \\emph{line} that connects point \\(A\\) and point \\(B\\) is the set\n\\( \\{ A + k \\cdot AB ~|~ k \\in \\Real \\} \\).\n\nTo define a hyperplane, we need a \\emph{normal vector} \\(n\\) and a point \\(C\\) on the plane.\nThe \\emph{hyperplane} is then the set of every point \\(P\\) such that \\(CP\\) is orthogonal to \\(n\\).\n\nTry convincing yourself that a line is a two-dimensional hyperplane.\nIn two-dimensional Euclidean space, fix a point \\(C\\),\nand draw a vector \\(n\\) whose origin is \\(C\\).\nPick a \\(P\\) such that \\(CP\\) and \\(n\\) form a right angle.\nPick another such \\(P\\).\nPick yet another such \\(P\\).\nPick as many such \\(P\\) as you need to see that those points form a line.\n\n\\section*{Defining lines as cotangent spaces and tangent spaces?}\n\nWe have just shown that there are two ways to define a line:\nby \\emph{cotangent space} and by \\emph{tangent space}?\n\n\\section*{Describing a circle, a sphere, and a hypersphere}\n\nA circle has a center and a radius.\nThe circumference of a circle is the set of all points\nwhose distance from the center is the radius.\n\nA circle with center \\(C\\) and radius \\(r\\)\nis described by the set \\( \\{ P : \\norm{CP} = r \\} \\).\nNote that this set only describes the circumference.\n\nWith coordinates: \\( \\{ (x,y) : \\norm{xi + yj} = r \\} \\).\n\nWith coordinates and orthonormal basis: \\( \\{ (x,y) : x^2 + y^2 = r^2 \\} \\).\n\nThe two-dimensional circle generalizes to the three-dimensional sphere,\nwhich generalizes to the higher-dimensional hypersphere.\n\n\\section*{Describing a shape}\n\n\\paragraph{As a set of points}\n\nA shape is a set of points.\n\n\\paragraph{With numbers}\n\nHere we get used to using numbers to describe shapes.\n\nLet's say we have a line that connects \\((0,0)\\) and \\((1,1)\\).\nSome other points on that line are \\((2,2)\\) and \\((3,3)\\).\nHowever, we want to describe \\emph{all} points on that line.\nThe way we do it is: ``For every \\((x,y)\\) in \\(\\Real^2\\), iff \\(x=y\\), then \\((x,y)\\) is on the line.''\nWe can write it in math notation as \\( \\{ (x,y) ~|~ (x,y) \\in \\Real^2, ~ x = y\\} \\).\n\nWe generalize.\nA line that passes \\((0,c/b)\\) and \\((c/a,0)\\)\nis described by the set \\(\\{ (x,y) ~|~ (x,y) \\in \\Real^2, ~ ax + by = c \\}\\).\nIf this is not obvious to you, try replacing \\(x\\) and \\(y\\) in the equation with some numbers\nwithout violating the equation.\n\nThe set \\(\\{ (x,y) ~|~ (x,y) \\in \\Real^2, ~ x^2 + y^2 = r^2 \\}\\) describes a circle.\n\nThe set \\(\\{ (x,y,z) ~|~ (x,y,z) \\in \\Real^3, ~ x^2 + y^2 + z^2 = r^2 \\}\\) describes a sphere.\n\n\\index{definitions!dimension of a shape}%\n\\index{dimension of a shape}%\nThe number of the tuple component is the \\emph{dimension} of the shape.\n\n\\paragraph{With functions}\n\nA function \\(\\Real \\to \\Real^3\\) describes a curve in a three-dimensional space.\n\n\\index{definitions!dimension of a shape}%\n\\index{dimension of a shape}%\nThe function's parameter count is the \\emph{dimension} of the shape.\n\nWe can use a function \\(\\Real^2 \\to \\Real^3\\) such as \\( (u,v) \\to (0,u,v^2) \\).\nThis describes a \\emph{surface} in a three-dimensional space.\n\nWe can use a vector equation such as \\( m \\cdot x + n = 0 \\).\n\nWe can use an equation such as \\( x^2 + y^2 + z^2 = 1 \\).\n\nThe distance of two points on the surface is the length of the shortest one-dimensional submanifold\nof that surface such that this submanifold connects those points.\n\nWhat is the length of a one-dimensional submanifold?\nThe curve is described by \\( x : \\Real \\to \\Real^n \\).\nThe length of a small segment around \\(t\\) is \\(\\norm{x(t+dt) - x(t)}\\).\n\n\\section{We haven't understood yet}\n\n\\subsection{Using charts and atlases}\n\nTODO\nMotivate differential geometry:\nHow do we make a map of the Earth?\nHow do we project the surface of a sphere to a paper?\nCurvilinear coordinates. Space curvature.\nHow do you describe a (curved) surface?\nWhat is curvature?\n\nManifold generalizes surface.\nA surface is a two-dimensional thing in a three-dimensional space.\nThere can be \\(m\\)-dimensional manifold in \\(n\\)-dimensional space, if \\(m \\le n\\).\n\nWe describe the surface of the unit sphere as \\( \\{ (x,y,z) ~|~ x^2 + y^2 + z^2 = 1, ~ (x,y,z) \\in \\Real^3 \\} \\).\nWe can also in cylindrical coordinates \\( \\{ (1,a,b) ~|~ 0 \\le a,b < 2\\pi \\} \\).\nThe \\emph{surface} of that sphere is a \\emph{two}-dimensional manifold.\n\nHow do we describe a line on the sphere?\nA great circle?\n\nA \\emph{chart} is a mapping (a function) between two manifolds?\n\nAn \\emph{atlas} is a set of charts?\n\n\\subsection{Describing a cotangent bundle}\n\nThe cotangent bundle of a space \\(S\\) is the vector bundle of all the cotangent spaces at every point in \\(S\\).\n\nThe cotangent bundle of a space \\(S\\) is the dual bundle of the tangent bundle of \\(S\\).\n\n\\subsection{Treating a phase space as a cotangent bundle}\n\nThis system of two equations describes a system that consists of one free particle: \\( x(t) = t \\) and \\( v(t) = 1 \\).\nThe phase space of that system is \\( \\{ (t,mv) ~|~ t \\in \\Real \\} \\).\nA set of \\emph{canonical coordinates} describes a point in the phase space.\nWhat physicists call \\emph{phase space},\nmathematicians call \\emph{cotangent bundle of a manifold} (\\enquote{Phase space}, Wikipedia).\n\n\\subsection{Understanding \\enquote{locally}}\n\n\\enquote{locally}\\footnote{\\url{https://en.wikipedia.org/wiki/Local_property}}\n\n\\subsection{Understanding parallel transports}\n\nTo understand Riemann curvature tensor.\n\\cite{arnold1989mathematical}\n\n\\subsection{Describing smooth deformation}\n\nA map from a sheet to a bent sheet.\n\n\\subsection{Describing strain using tensor}\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Infinitesimal_strain_theory}}\n\\footnote{\\url{https://en.wikipedia.org/wiki/Continuum_mechanics}}\n\n\\section{Generalizing two-dimensional shapes to higher dimensions}\n\n\\subsection{Generalizing line to plane and hyperplane}\n\n\\subsection{Generalizing circle to sphere and hypersphere}\n\n\\section{The word \\enquote{manifold}}\n\nYou can skip this section.\n\nRiemann defines manifold?\nPoincar\\'e's \\emph{Analysis situs} defines \\emph{manifold}%\n\\footnote{\\url{http://www.maths.ed.ac.uk/~aar/papers/poincare2009.pdf}}\n\nManifolds are confusing\nbecause the word \\enquote{manifold} means \\enquote{variety},\nwhich doesn't help students guess anything about locally flat spaces.\nHistory can explain this mess.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Manifold\\#History}}%\n\\footnote{\\url{https://en.wikipedia.org/wiki/History_of_manifolds_and_varieties}}\n\n\\section*{Replacing \\enquote{manifold} with \\enquote{space}}\n\nSometimes we can replace \\enquote{manifold} with \\enquote{space}.\nFor example, if we are discussing about spaces that are smooth and locally flat,\nthen we can write \\enquote{cotangent bundle of a space}\ninstead of \\enquote{cotangent bundle of a manifold}.\n\n\\section*{Redefining \\enquote{manifold} to mean \\enquote{locally flat spaces}}\n\nEvery time we meet the word \\enquote{manifold},\nwe should by reflex think \\enquote{locally flat space}.\n\nA manifold is a space that looks flat if we zoom close enough.\n\\enquote{Flat} means Euclidean, that is resembling an Euclidean space.\n\n\\ExerciseAnswer{Say to yourself until it becomes a reflex: \\enquote{A manifold is a locally flat space.}}{A manifold is a locally flat space.}\n\n\\ShowAnswers\n\nSome examples of one-dimensional manifolds are lines and circles.%\n\\footnote{\\url{https://en.wikipedia.org/wiki/Manifold}}\nSome examples of two-dimensional manifolds are flat sheets and bent seets.\n\n\\section{Raw thought}\n\nA line is a set of points.\nA sheet is a set of lines.\nA cube is a set of sheets.\nIs this thought useful?\n\nWe will study mappings of the form \\(\\Real^a \\to \\Real^b\\).\nFor example, \\( \\Real \\to \\Real^n \\) is the type of a curve,\nand \\( \\Real^n \\to \\Real \\) is the type of a scalar field.\nIs there a deeper connection between curves and scalar fields?\nCurves and embeddings?\nScalar fields and projections?\n\nWith the real tuple space and the Cartesian coordinate systems,\nwe can marry infinitesimal calculus and geometry into differential geometry.\n\nWith analytic geometry, we can describe shapes using real numbers.\n\n\\section{Embedding a space in another space}\n\nAn \\(n+1\\)-dimensional space is bigger than an \\(n\\)-dimensional space.\n\nAn \\(n+1\\)-dimensional space can contain an \\(n\\)-dimensional space.\n\nAn \\(n\\)-dimensional space can be embedded in an \\(n+1\\)-dimensional space.\n\n\\footnote{\\url{https://en.wikipedia.org/wiki/Embedding}}\n\n\\section*{Ambient spaces}\n\nAn \\(m\\)-dimensional object in an \\(n\\)-dimensional ambient space is a function \\(\\Real^m \\to \\Real^n\\).\nIt tells you how to embed the \\(m\\)-dimensional object into the \\(n\\)-dimensional ambient space.\n", "meta": {"hexsha": "fb297fe44db17a91079c0178d03040cdbebb9514", "size": 13404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/physics/real-tuple-space.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/physics/real-tuple-space.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/physics/real-tuple-space.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 36.5231607629, "max_line_length": 142, "alphanum_fraction": 0.7106087735, "num_tokens": 3798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.9032942171172603, "lm_q1q2_score": 0.7748169688651917}}
{"text": "\\section{\\texorpdfstring{Algebra and Number theory}{Algebra and Number theory}}\n\\vspace{5mm}\n\\large\n\n\\begin{theorem}[Invertibility of element]\n\t$a \\in \\Z_n$ is invertible $\\iff (a, n) = 1$.\n\\end{theorem}\n\\begin{proof}\n\tFor coprime $a, n$ we can use Extended Euclid algorithm and get the inverse using Bezout coefficients.\n\n\tOtherwise, no solution exists.\n\\end{proof}\n\n\\begin{definition}\n\t\\[ \\Z_N^{\\ast} := \\{ a \\in \\Z_N | (a, N) = 1 \\} \\]\n\tGroup of all invertible elements.\n\\end{definition}\n\n\\begin{theorem}[Lagrange]\n\tIf G is finite group, $H \\leq G \\Rightarrow |H|\\ |\\ |G|$.\n\\end{theorem}\n\n\\begin{theorem}[Fermat little]\n\tFor $p$ prime, $(x, p) = 1: x^{p-1} \\equiv 1\\mod p $.\n\\end{theorem}\n\n\\begin{theorem}[Euler]\n\tFor $N > 1$, $(x, N) = 1: x^{\\varphi(N)} \\equiv 1 \\mod N$.\n\\end{theorem}\n\\begin{proof}\n\tConsider\n\t\\[ 1 = x^0, x^1,..., x^k = 1 \\]\n\tAll of them distinct and form a subgroup of $\\Z_N^{\\ast}$.\n\n\tBy Lagrange $k = |H|$ is a divisor of order of the group $\\varphi(N)$.\n\t\\[ \\varphi(N) = k\\cdot l\\]\n\tSo:\n\t\\[ x^{\\varphi(N)} \\equiv x^{kl} = (x^k)^l \\equiv 1^l = 1\\]\n\n\\end{proof}\n\n\\begin{theorem}[Chinese Remainder Theorem (CRT)]\n\tFor $n_1,..., n_k$ pairwise coprime, $n := \\prod_i n_i$. Then\n\t\\[ \\Z_{n_1} \\times \\Z_{n_2} \\times ... \\times \\Z_{n_k} \\simeq \\Z_n \\]\n\\end{theorem}\n\\begin{proof}\n\tProof for $k = 2$, continue by induction.\n\n\t1) Consider\n\t\\[ f:\\Z_n \\to \\Z_{n_1} \\times \\Z_{n_2}, f(x) = (x \\mod n_1, x \\mod n_2) \\]\n\tFirstly $f$ is injective:\n\t\\[ f(x) = f(y) \\Rightarrow f(x - y) = (0,0) \\]\n\tAlso $(x - y)$ is divisible by both $n_1, n_2 \\Rightarrow (x - y)$ is divisible by $n_1 \\cdot n_2 = n \\Rightarrow y = x$.\n\n\tSecondly $f$ is bijective as both sets have the same cardinality.\n\n\t2) Constructive proof: given $(a,b)$, find $f(x) = (a,b)$.\\\\\n\tFirslty, find\n\t\\[ u,v: f(u) = (0, 1) \\land f(v) = (1, 0) \\Rightarrow f(au + bv) = af(u) + b f(v) = (a,0) + (0,b) = (a,b) \\]\n\n\t\\[ f(n_1) = (0, c_1) \\]\n\tIf $c_1 = 1, v = n_1$. Otherwise\n\t\\[ f(c_1^{-1} \\cdot n_1) = c_1^{-1} \\cdot (0, c_1) = (0, 1) \\]\n\tSimilarly obtain $f(n_2)$.\n\\end{proof}\nPrimality test (sketch)\n\\begin{enumerate}\n\t\\item Generate $a \\ne 0 \\in_R \\Z_n$\n\t\\item if $(a, n) \\ne 1$ (Euclid witness)\\\\\n\t\treturn NO\n\t\\item if $a^{n - 1} \\mod n \\neq 1$ (Fermat witness)\\\\\n\t\tretutn NO\n\t\\item YES.\n\\end{enumerate}\n\n\\begin{definition}\n\tCarmichael number: $n$ is composite and\n\t\\[ a \\in \\Z_n^{\\ast}: a^{n - 1} \\mod n = 1 \\]\n\tSmallest 561.\n\\end{definition}\n\n\\begin{theorem}[Prime probability]\n\tIf $n$ is composite, but not Carmichael $\\Rightarrow Pr_a[YES] \\leq 1/2$.\n\\end{theorem}\n\\begin{proof}\n\t\\[ H := \\{ a \\in \\Z_n^{\\ast} | a^{n - 1} \\mod n = 1 \\} \\]\n\tThen $H \\leq G$, as $H$ is not trivial subgroup. Therefore\n\t\\[ |H| \\leq 1/2 \\Z_n^{\\ast} \\]\n\\end{proof}\n", "meta": {"hexsha": "d27da85c17b5327d63a9e3125594c97d4905ede2", "size": 2721, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/prednasky/09_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/09_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/09_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": 30.2333333333, "max_line_length": 122, "alphanum_fraction": 0.6001470048, "num_tokens": 1128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971871, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7748169571089539}}
{"text": "\n\\subsection{T-test for variable significance}\n\n\\subsubsection{T-statistic}\n\nIn practice we don't know the population standard deviation and so must estimate it instead.\n\nWe use the standard deviation on the sample.\n\n\\(t=\\dfrac{\\bar x-x_0}{s_0 }\\)\n\n\\subsubsection{Student's t-distribution}\n\nAs we have used the sample standard deviation we have lost a degree of freedom, and can no longer model the variable as a normal distribution, as we did for the z-statistic.\n\nWe now have a distribution with an addition parameter, the number of degrees of freedom.\n\nThe number of degrees of freedom is \\(n-1\\).\n\nAs the sample size tends towards infinity, the distribution tends towards the normal distribution.\n\n\\subsubsection{Student's t-test}\n\n\\subsubsection{Confidence interval}\n\n\n", "meta": {"hexsha": "15b7eb087c8a236bef317b3d1d4c098013aa01e2", "size": 774, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/hypothesisZT/02-01-tStatistic.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/hypothesisZT/02-01-tStatistic.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/hypothesisZT/02-01-tStatistic.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 28.6666666667, "max_line_length": 173, "alphanum_fraction": 0.7803617571, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467157, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7747967645274146}}
{"text": "\\chapter{Methodology}\r\nThe methodology used in this research uses a modification of the classical Grey Wolf Optimization algorithm first introduced by Mirjalili, S., Mirjalili, S., and Lewis, A. in 2014 \\cite{Mirjalili2014}. As we will be discussing in this chapter, we have determined that using classical GWO as is does not result in usable solutions for the instance of facility layout problem we are solving. Hence, the necessity for the modification.\r\n\r\nIn this chapter, we will first discuss about the mathematical model of the problem being solved. Later, we will be delving into the inner workings of the solution representation, the algorithm (including the justification for the modification), and then the technologies that were used in implementing the approach.\r\n\r\n\\section{Mathematical Model}\r\nThe goal of any metaheuristic, like what is being proposed in this paper, is to optimize a certain objective function. As mentioned in the first chapter, in facility layout problems, we minimize the following function:\r\n\r\n$$\r\n\\text{min} F = \\sum_{i=1}^{n}\\sum_{j=1}^{n}c_{ij}f_{ij}d_{ij}\r\n$$\r\n\r\nFor the problem we are solving in this paper, we are optimizing the following equation that is not only a slight modification of the basic mathematical model for FLPs, but also adds penalties to solutions that are infeasible, no matter the degree of infeasiblity.\r\n\r\n\\begin{align*}\r\n\t\\text{min }F &= \\sum_{i=1}^{\\left | B \\right |}\\sum_{j=i + 1}^{\\left | B \\right |}c_{ij}d_{ij} \\\\\r\n\t& + \\sum_{i=1}^{\\left | B \\right |}\\sum_{j=i + 1}^{\\left | B \\right |} \\left ( P_{B}\\frac{A_{0}(i, j)}{\\text{min}(w_{i}h_{i}, w_{j}h_{j})} + P_{B} \\right ) \\cdot \\alpha_{0}(i, j) \\\\\r\n\t& + \\sum_{i=1}^{\\left | B \\right |}\\left( P_{R}\\frac{w_{i}h_{i} - A_{1}(i)}{w_{i}h_{i}} + P_{R} \\right) \\cdot \\alpha_{1}(i)\r\n\\end{align*}\r\n\r\nwhere:\r\n\r\n\\begin{table}[h!]\r\n\t\\centering\r\n\t\\begin{tabular}{| l | p{10cm} |}\r\n\t\\hline\r\n\t$x_{i}$  & top-left $x$ coordinate of building $i$ \\\\\r\n\t\\hline\r\n\t$y_{i}$  & top-left $y$ coordinate of building $i$ \\\\\r\n\t\\hline\r\n\t$w_{i}$  & width of building $i$ \\\\\r\n\t\\hline\r\n\t$h_{i}$  & height of building $i$ \\\\\r\n\t\\hline\r\n\t$R_{x}$  & top-left $x$ coordinate of the bounding region \\\\\r\n\t\\hline\r\n\t$R_{y}$  & top-left $y$ coordinate of the bounding region \\\\\r\n\t\\hline\r\n\t$R_{w}$  & width of the bounding region \\\\\r\n\t\\hline\r\n\t$R_{h}$  & height of the bounding region \\\\\r\n\t\\hline\r\n\t$c_{ij}$ & flow rate from building $i$ to building $j$ \\\\\r\n\t\\hline\r\n\t$d_{ij}$ & distance from the center of building $i$ to the\r\n\t           center of building $j$ \\\\\r\n\t\\hline\r\n\t$P_{B}$  & penalty value for building intersection \\\\\r\n\t\\hline\r\n\t$P_{T}$  & penalty value for any building going out of\r\n\t           bounds, even with a portion of a building \\\\\r\n\t\\hline\r\n\t\\end{tabular}\r\n\\end{table}\r\n\r\nWe elected to remove the flow rate from the basic formulation of the model that was discussed earlier in Equation \\ref{mm-equation-mhc}. \r\n\r\n\\begin{equation}\\label{mm-equation-mhc}\r\n\t\\sum_{i=1}^{\\left | B \\right |}\\sum_{j=i + 1}^{\\left | B \\right |}c_{ij}d_{ij}\r\n\\end{equation}\r\n\r\nThis is because we can consider flow rate as simply part of the cost. In the original formulation, we were considering it from a material handling cost perspective, which requires having both a cost and flow rate variable. However, in a general problem, we can consider cost to also include the frequency of movement from one facility to another, which is essentially the flow rate. As such, we can merge cost and flow rate into one variable.\r\n\r\nThe mathematical model allows for infeasible solutions to allow for better solutions in the long run. To follow this specification, the model includes expressions that penalizes solutions that meet any of the following conditions: (1) at least one building is intersecting with another building, and (2) a building, either in whole or in part, is outside the bounding area.\r\n\r\n\\begin{equation}\\label{mm-equation-intersection}\r\n\t\\sum_{i=1}^{\\left | B \\right |}\\sum_{j=i + 1}^{\\left | B \\right |} \\left ( P_{B}\\frac{A_{0}(i, j)}{\\text{min}(w_{i}h_{i}, w_{j}h_{j})} + P_{B} \\right ) \\cdot \\alpha_{0}(i, j)\r\n\\end{equation}\r\n\r\nEquation \\ref{mm-equation-intersection} is the expression that applies a penalty to solutions that meet the first condition. Notice that it has the functions $A_{0}(i, j)$ and $\\alpha_{0}(i, j)$. They are defined by the following:\r\n\r\n\\begin{align}\r\n\tA_{0}(i, j) &= I_{L}(x_{i}, x_{j}, w_{i}, w_{j})\r\n\t               \\cdot I_{L}(y_{i}, y_{j}, h_{i}, h_{j}) \\\\\r\n\tI_{L}(x_{1}, x_{2}, l_{1}, l_{2}) &= \\text{max}(0, \\text{min}(x_{1} + l_{1}, x_{2} + l_{2}) - \\text{max}(x_{1}, x_{2})) \\\\\r\n    \\alpha_{0}(i, j) &=\r\n    \\left\\{\\begin{matrix}\r\n    \t1 & \\text{if } A_{0}(i, j) > 0 \\\\ \r\n    \t0 & \\text{otherwise}\r\n    \\end{matrix}\\right.\r\n\\end{align}\r\n\r\n$A_{0}(i, j)$ simply gets the area of intersection of buildings $i$ and $j$. This is achieved by the use of $I_{L}(x_{1}, x_{2}, l_{1}, l_{2})$, which computes the length or width of an intersection of buildings.\r\n\r\nIn the equation, for every pair of buildings that intersect, we apply a penalty that is the percentage of the area of the smallest building by area that is intersecting with the other building multiplied by the penalty value for building intersection. This will allow for rewarding the algorithm for moving the buildings towards non-intersection. The same penalty value is also added to ensure that the algorithm prioritizes removing intersections over reducing the distance between the centers of the buildings. $\\alpha_{0}(i, j)$ ensures that the penalty is only applied to pairs of buildings that intersect with one another.\r\n\r\n\\begin{equation}\\label{mm-equation-oob}\r\n\t\\sum_{i=1}^{\\left | B \\right |}\\left( P_{R}\\frac{w_{i}h_{i} - A_{1}(i)}{w_{i}h_{i}} + P_{R} \\right) \\cdot \\alpha_{1}(i)\r\n\\end{equation}\r\n\r\nThe other part of the mathematical model, Equation \\ref{mm-equation-oob}, works in a similar principle as Equation \\ref{mm-equation-intersection}. This equation applies a penalty value when the second condition of infeasibility is met. Like in \\ref{mm-equation-intersection}, it has specific functions to help compute the penalty. They are defined as:\r\n\r\n\\begin{align}\r\n\tA_{1}(i) &= I_{L}(x_{i}, R_{x}, w_{i}, R_{w})\r\n\t\\cdot I_{L}(y_{i}, R_{y}, h_{i}, R_{h}) \\\\\r\n\t\\alpha_{1}(i) &=\r\n\t\\left\\{\r\n\t\\begin{matrix}\r\n\t\t0 & \\text{if} &\r\n\t\t\\begin{aligned}\r\n\t\t\tR_{x} &\\leq x_{i} &\\leq R_{x} + R_{w} \\\\\r\n\t\t\tR_{x} &\\leq x_{i} + w_{i} &\\leq R_{x} + R_{w} \\\\\r\n\t\t\tR_{y} &\\leq y_{i} &\\leq R_{y} + R_{h} \\\\\r\n\t\t\tR_{y} &\\leq y_{i} + h_{i} &\\leq R_{y} + R_{h} \\\\\r\n\t\t\\end{aligned} \\\\\t\t\r\n\t\t1 & \\text{otherwise}\r\n\t\\end{matrix}\\right.\r\n\\end{align}\r\n\r\n$A_{1}(i)$ simply computes the area of intersection of the building and the bounding area. Now, since this only computes the intersection, we must subtract the intersection with the area of the building to get the area of the building that is outside of the bounding area. This is expressed by the numerator of the fractional expression in Equation \\ref{mm-equation-oob}. Similar to Equation \\ref{mm-equation-intersection}, the equation applies a penalty value that is the percentage of the area of the total building area that is outside the bounding region multiplied and then added by the penalty value. The addition is also to ensure that the algorithm gives more priority to removing out-of-bounds buildings. $\\alpha_{1}(i)$ ensures that the penalty is only applied to buildings that are, in part or in whole, out of bounds.\r\n\r\n\\section{Solution Representation}\r\nThe solution is represented using a one-dimensional array of floating numbers. In the array, every group of three consecutive elements are considered to be the x and y positions, and angle, respectively, of one building. While the x and y positions are allowed to be of any value, the angle value is restricted to only $0^{\\circ}$ and $90^{\\circ}$. A visualization of the solution representation is shown by Figure \\ref{solution-repr-viz}.\r\n\r\n\\begin{figure}\r\n\t\\begin{center}\r\n\t\t\\begin{tabular}{| c | c | c | c | c | c | c |}\r\n\t\t\t\\hline\r\n\t\t\t$x_{0}$ & $y_{0}$ & $\\angle_{0}$ & $\\ddots$ & $x_{n - 1}$ & $y_{n - 1}$ & $\\angle_{n - 1}$ \\\\\r\n\t\t\t\\hline\r\n\t\t\\end{tabular}\r\n\t\\end{center}\r\n\t\\caption{Visualization of the solution representation.}\r\n\t\\label{solution-repr-viz}\r\n\\end{figure}\r\n\r\n\\section{The Algorithm}\r\nIn this paper, we are adapting the Grey Wolf Optimization algorithm into solving our instance of the facility layout problem. There have been no publicly available research that have previously used the metaheuristic in solving FLP, basing from our survey. This increases the significance of this paper. As mentioned earlier, the proposed algorithm requires modifications in order to produce feasible solutions. We will first be discussing the reasons why we require them, before proceeding to detailing the algorithm we are using for this research.\r\n\r\n\\subsection{The Problem with Classical GWO}\r\nIn classical GWO, the following equations are used:\r\n\r\n\\begin{align}\r\n\t\\vec{X_{1}^{'}} &= \\vec{X_{\\alpha}}(t) - \\vec{A_{\\alpha}} \\cdot \\vec{D_{\\alpha}} \\label{gwo-x1-eqn} \\\\\r\n\t\\vec{X_{2}^{'}} &= \\vec{X_{\\beta}}(t) - \\vec{A_{\\beta}} \\cdot \\vec{D_{\\beta}} \\\\\r\n\t\\vec{X_{3}^{'}} &= \\vec{X_{\\delta}}(t) - \\vec{A_{\\delta}} \\cdot \\vec{D_{\\delta}} \\label{gwo-x3-eqn} \\\\\r\n\t\\vec{X}(t + 1)  &= \\frac{\\vec{X_{1}^{'}} + \\vec{X_{2}^{'}} + \\vec{X_{3}^{'}}}{3} \\label{gwo-xt1-eqn}\r\n\\end{align}\r\n\r\nwhere $\\vec{X_{\\alpha}}$, $\\vec{X_{\\beta}}$, and $\\vec{X_{\\delta}}$ represent the $\\alpha$, $\\beta$, and $\\delta$ solutions \\cite{Gupta2018}. $\\vec{D}$ and $\\vec{A}$ are defined as:\r\n\r\n\\begin{align*}\r\n\t\\vec{D}        &= \\left | \\vec{C} \\cdot \\vec{X_{l}}(t)\r\n\t- \\vec{X}(t) \\right | \\\\\r\n\t\\vec{C}        &= 2 \\cdot \\vec{r_{2}} \\\\\r\n\t\\vec{A}        &= 2 \\cdot \\vec{a} \\cdot \\vec{r_{1}}\r\n\t\t\t\t\t  - \\vec{a}                \\\\\r\n\\end{align*}\r\n\r\nThe aforementioned equations may be usable as is for other problems. However, as we have discovered through our prior experiments, using these equations results in solutions that are infeasible and where the buildings tend to move to the axes of an origin and the origin itself. One example solution with these characteristics is shown in Figure \\ref{bad-solution-unmodified-gwo}, where we have set the origin of the buildings to the center of the bounding region.\r\n\r\n\\begin{figure}[h!]\r\n\t\\centering\r\n\t\\includegraphics{./images/chap05-methodology/bad-solution-unmodified-gwo.png}\r\n\t\\caption{Flowchart detailing the algorithm.}\r\n\t\\label{bad-solution-unmodified-gwo}\r\n\\end{figure}\r\n\r\nAs one may infer, using the equations above will require setting an origin point for the buildings. Not considering the affinity of building towards the axes, having the origin point at the center or in a certain location in the bounding region restricts the possible locations where the buildings can cluster around. This restriction prevents us from exploring the solution subspace where solutions are feasible but where the cluster point is not the origin. This lead us to solutions that are less ideal. Aside from requiring setting the origin point, buildings moving towards the axes also presents another problem. Basing from our experiments, it prevents us from producing feasible solutions.\r\n\r\nThis behaviour can be attributed primarily to the formula, $\\vec{D} = \\left | \\vec{C} \\cdot \\vec{X_{p}}(t) - \\vec{X}(t) \\right |$. To understand why the aforementioned formula contributes to the behaviour we have discussed earlier, we should understand what the formula means. It is helpful to simply consider that only building is being optimized in understanding the problems. Considering only the alpha solution may also provide better understanding as well.\r\n\r\nLet us start with $\\vec{C} \\cdot \\vec{X_{l}}(t)$ from $\\vec{D} = \\left | \\vec{C} \\cdot \\vec{X_{l}}(t) - \\vec{X}(t) \\right |$. To simplify our explanation, let $K = \\vec{C} \\cdot \\vec{X_{l}}(t)$. The range of each $i$th element in $K$ will be $[0, 2 \\cdot \\vec{C}_{l,i}]$. Note that the operation is a dot product, but it is actually pairwise multiplication. This means that $K$ simply scales the x and y positions, and angle of the buildings. Figure \\ref{gwo-c-effect} shows a visualization of this effect. Despite the figure only showing the effect with a building's position in the first quadrant, the same effect can be observed with other buildings located in other quadrants. Now, considering the entirety of $\\vec{D}$, $\\vec{D}$ would mean to be the distance between a building $i$ moved to a different point in the region $S$ (see Figure \\ref{gwo-c-effect}) in $\\vec{X_{l}}$ and a building $i$ in $\\vec{X}(t)$. A visualization for this is provided by Figure \\ref{gwo-d-effect}.\r\n\r\n\\begin{figure}[h!]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.45]{./images/chap05-methodology/gwo-c-effect.png}\r\n\t\\caption{In $K$, $C$ simply scales the x and y positions and angles of buildings. Assuming that the point $B$ represents the x and y positions of a building, the region $S$ is where $B$ may be repositioned based on the values of $C$.}\r\n\t\\label{gwo-c-effect}\r\n\\end{figure}\r\n\r\n\\begin{figure}[h!]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.45]{./images/chap05-methodology/gwo-d-effect.png}\r\n\t\\caption{A visualization of how $D$ is computed and its inherent meaning.}\r\n\t\\label{gwo-d-effect}\r\n\\end{figure}\r\n\r\nLet us also take note, $\\vec{A} \\cdot \\vec{D}$. First, we should take note that $\\vec{A} = 2 \\cdot \\vec{a} \\cdot \\vec{r_{1}} - \\vec{a}$. $a$, as mentioned before, linearly decreases over time. Since $a$ decreases linearly over time, $\\vec{A}$ will also decrease over time. This behaviour of $\\vec{A}$ would mean that in $\\vec{A} \\cdot \\vec{D}$, $\\vec{D}$ will eventually decrease as well. Considering equations \\ref{gwo-x1-eqn} to \\ref{gwo-x3-eqn}, $\\vec{A}$ influences the distance of a building from its counterpart in the leading wolves. This would mean that as the number of iterations increase in a run, buildings will eventually follow the placements of the leading wolves.\r\n\r\nLet us now return back to $\\vec{C} \\cdot \\vec{X_{l}}(t)$. Over the course of iterations, this equation will make it difficult for a building to change its position. Around 50\\% of the time (due to the fact that $\\vec{r_{2}}$ is a \\textit{uniform} random vector), the value of $\\vec{C}$ will be less than $1$. The position of the buildings will be moved towards the axes. Since $\\vec{C}$ is a scaling factor, it will be difficult for a building position to move away from an axis. This affects all solutions, and noting that the leading wolves guide the entire population, the movement towards an axis will be propagated towards the entire population, especially with the fact that the $\\vec{A}$ reduces the difference between the leading wolves/solutions and the rest of the solutions as the number of iterations increase in a run. Note that the penalty value for intersection prevents them from overlapping with one another. Buildings that are already on a certain axis will find it practically impossible to move in the direction of the perpendicular axis. Buildings that are on the origin itself will practically cease to move at all. Buildings will still be able to change their orientations, however. The reason for this behaviour of being stuck on an axis is due to the nature of axes themselves, where the value in one or both axes is zero, and to the scaling phenomenom caused by $\\vec{C}$. Since $K = \\vec{C} \\cdot \\vec{X_{l}}(t)$ and when a building is near or already on an axis, the x, y, or both x and y positions of a building will barely, if at all, move away from the axes it is currently stuck to, when multiplying with $\\vec{C}$. Hence, the behaviour we are noticing.\r\n\r\nThe aforementioned formula makes the classical GWO inadequate for our problem instance. We are unable to produce feasible nor satisfying results. In order for the grey wolf optimization algorithm to be successfully adapted into solving the facility layout problems, we must introduce a few changes into the algorithm. These changes will be discussed in the next subsection.\r\n\r\n\\subsection{Modified GWO}\r\n% Draft Note: We should maybe give a name to the modified GWO. Maybe call it \"Ballais-Romero GWO variant\". HAHAHA.\r\n\r\nMirjalili, S., Mirjalili, S., and Lewis, A. \\cite{Mirjalili2014} included a figure similar to Figure \\ref{gwo-positioning-update}. It visualizes how a wolf $\\omega$ will update its position based on the information provided by the leading wolves.\r\n\r\n\\begin{figure}[h!]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.3]{./images/chap05-methodology/gwo-position-updating.png}\r\n\t\\caption{Visualization of how wolves in GWO update their positions. An $\\omega$ wolf will move towards a random point inside the circle of the estimated prey position.}\r\n\t\\label{gwo-positioning-update}\r\n\\end{figure}\r\n\r\nBasing from the visualization, notice that the $\\vec{C}$ of the leading wolves specify the radius of the circle in which a $\\vec{C} \\cdot \\vec{X_{l}}$ will be located it. The circle does \\textbf{not} include an origin point. We have discussed before that performing a pairwise multiplication between $\\vec{C}$ and $\\vec{X_{l}}$ simply scales the elements $i$ in the vector $\\vec{X_{l}}$. This is different from the visualization. To achieve the same effect as the visualization, instead of performing pairwise multiplication, we must utilize vector addition between $\\vec{C}$ and $\\vec{X_{l}}$. See Figure \\ref{vector-addition-visualization} for a visualization of vector addition. This is the first modification we are introducing to classical GWO.\r\n\r\n\\begin{figure}[h!]\r\n\t\\centering\r\n\t\\includegraphics[scale=0.45]{./images/chap05-methodology/vector-addition-visualization.png}\r\n\t\\caption{Vector addition pushes the point represented by $\\vec{A}$ towards the direction of $\\vec{B}$ by the magnitude of the same vector.}\r\n\t\\label{vector-addition-visualization}\r\n\\end{figure}\r\n\r\nIn our modified GWO, $D$ is now defined as:\r\n\r\n\\begin{align}\r\n\tD &= \\left | (\\vec{C} + \\vec{X_{l}}) - \\vec{X}(t) \\right | \\label{modified-gwo-d}\r\n\\end{align}\r\n\r\nHowever, this alone is not enough to comply with the aforementioned visualization. Using this will only move the buildings to the right and/or top. In order for us to move the buildings, we must also modify $\\vec{C}$ as shown below:\r\n\r\n\\begin{align}\r\n\tC &= c \\cdot \\vec{r_{3}} \\label{modified-gwo-c}\r\n\\end{align}\r\n\r\nIn this equation, $c$ is a real-valued variable, and $r_{3}$ is a random vector in $[-1, 1]$. This modification will now allow us to move a building from any direction and at any magnitude. The magnitude in which the building will be moved is controlled by $c$.\r\n\r\nThese modifications remove the necessity to specify an origin point in the bounding region, and the behaviour of buildings to move towards the origin or axes. Unfortunately, this alone is not enough to produce feasible results. We have to add two more modifications before we are able to produce good results.\r\n\r\nThe first additional modification is the building clamping. Each building is restricted to the boundary. If a building is moved towards outside the boundary, it will be pulled back to within the boundary. Building clamping can be mathematically defined as the following. Given a building $B$ in a solution $X(t)$ at iteration $t$ after being updated by Equations \\ref{gwo-x1-eqn} to \\ref{gwo-xt1-eqn}, \\ref{modified-gwo-d}, and \\ref{modified-gwo-c}, clamping can be mathematically modeled as:\r\n\r\n\\begin{align}\r\n\tB_{x} &= \\text{max}\\left (R_{x} + \\frac{B_{w}}{2}, \\text{min}\\left(B_{x}, R_{x} + \\left(R_{w} - \\frac{B_{w}}{2}\\right)\\right)\\right ) \\label{bx-clamp-equation} \\\\\r\n\tB_{y} &= \\text{max}\\left (R_{y} + \\frac{B_{h}}{2}, \\text{min}\\left(B_{y}, R_{y} + \\left(R_{h} - \\frac{B_{h}}{2}\\right)\\right)\\right ) \\label{by-clamp-equation}\r\n\\end{align}\r\n\r\nwhere $B_{x}$ and $B_{y}$ are the $x$ and $y$ positions of the centroid of a building $B$, $B_{w}$ and $B_{h}$ are the width and height from the top left corner of a building $B$, $R_{x}$ and $R_{y}$ are the $x$ and $y$ positions of the top-left corner of the bounding region $R$, and $R_{w}$ and $R_{h}$ are the width and height of the bounding region $R$. Based on our prior experiments, without this clamping, buildings will freely move to points outside the boundary, and, at the end of the run, will produce a bad solution. \r\n\r\nThis clamping should \\textit{almost} solve the positioning of the buildings and allow us to produce results that are feasible. Since GWO is a continuous metaheuristic, building attributes that must only be one of two values will eventually be a value that is between the two aforementioned values. In our problem, this attribute that is affected is the building orientation. The building orientation may only be $0^{\\circ}$ or $90^{\\circ}$. It must never be a value between two. To solve this problem, we simply use the orientation of a building $B$ from the $\\alpha$, $\\beta$, or $\\delta$ solutions, which are randomly selected. This idea is based off from the nature of GWO, where the best three solutions lead the search for the local optima. The building orientation of a building $B$ is, therefore, obtained using:\r\n\r\n\\begin{align}\r\n\tB_{o} = \\left\\{\\begin{matrix}\r\n\t\t\\alpha_{B_{o}} & \\text{if } 0 \\leq r < \\frac{1}{3} \\\\ \r\n\t\t\\beta_{B_{o}}  & \\text{if } \\frac{1}{3} \\leq r < \\frac{2}{3}  \\\\ \r\n\t\t\\delta_{B_{o}} & \\text{otherwise}\r\n\t\\end{matrix}\\right.\r\n\t\\label{modified-gwo-bo}\r\n\\end{align}\r\n\r\nwhere $B_{o}$ is the current orientation of a building $B$, $\\alpha_{B_{o}}$, $\\beta_{B_{o}}$, and $\\delta_{B_{o}}$ are the orientations of building $B$ in the $\\alpha$, $\\beta$, and $\\delta$ solutions, respectively, and $r$ is a random variable in $[0, 1]$. In our approach, assigning the building orientations is performed before clamping the buildings.\r\n\r\nWith all these modifications already discussed, we now need to briefly discuss how population initialization performed. The population is initialized by providing each building $B$ a random x and y position values, and random orientation. The orientation is either $0$ or $90$. The x and y positions are clamped as well to ensure that the buildings are inside the bounding region. The positions are clamped using Equations \\ref{bx-clamp-equation} and \\ref{by-clamp-equation}, respectively. Algorithm \\ref{modified-gwo-algorithm-pop-initialization} shows the pseudocode for the population initialization.\r\n\r\n\\begin{algorithm}[h!]\r\n\\caption{Pseudocode for the population initialization.}\r\n\\label{modified-gwo-algorithm-pop-initialization}\r\n\\begin{algorithmic}[1]\r\n\\State Set $\\vec{X}$ to be the solution.\r\n\\State Set $R_{x}$ to be the x position of the top-left corner of the bounding region $R$.\r\n\\State Set $R_{y}$ to be the y position of the top-left corner of bounding region $R$.\r\n\\State Set $R_{w}$ to be the width of the bounding region $R$.\r\n\\State Set $R_{h}$ to be the height of the bounding region $R$.\r\n\\State Set $N$ to be the number of buildings in a population.\r\n\\For{i = 0 until $N$}\r\n\t\\State $\\vec{X}_{(i * 3)}$ = $U(R_{x}, R_{x} + R_{w})$\r\n\t\\State $\\vec{X}_{(i * 3) + 1}$ = $U(R_{y}, R_{y} + R_{h})$\r\n\t\\State $\\vec{X}_{(i * 3) + 2}$ = $U({0, 90})$\r\n\t\r\n\t\\State Apply Equation \\ref{bx-clamp-equation} to $\\vec{X}_{(i * 3)}$.\r\n\t\\State Apply Equation \\ref{by-clamp-equation} to $\\vec{X}_{(i * 3) + 1}$.\r\n\\EndFor\r\n\\end{algorithmic}\r\n\\end{algorithm}\r\n\r\nAll these modifications for the classical GWO have allowed us to successfully adapt GWO to the facility layout problem. Equations \\ref{summary-modified-gwo-a} to \\ref{summary-modified-gwo-xt1}, and Algorithm \\ref{modified-gwo-algorithm} summarises the entire modified GWO. Notice that these modifications are relatively simple, and do not significantly change the characteristics of classical GWO. The simplicity of GWO is still preserved. The next chapters will discuss how our modified version of GWO performs against configurations of unequal-area facility layout ptoblems.\r\n\r\n\\begin{align}\r\n\t\\vec{A} &= 2\\vec{a} \\cdot \\vec{r_{1}} - \\vec{a} \\label{summary-modified-gwo-a} \\\\\r\n\t\\vec{C} &= c \\cdot \\vec{r_{2}} \\\\\r\n\t\\vec{D}_{\\alpha} &= \\left | \\left ( \\vec{C}_{1} + \\vec{X_{\\alpha}(t)} \\right ) - \\vec{X(t)} \\right | \\label{summary-modified-gwo-DAlpha} \\\\\r\n\t\\vec{D}_{\\beta} &= \\left | \\left ( \\vec{C}_{2} + \\vec{X_{\\beta}(t)} \\right ) - \\vec{X(t)} \\right | \\\\\r\n\t\\vec{D}_{\\delta} &= \\left | \\left ( \\vec{C}_{3} + \\vec{X_{\\delta}(t)} \\right ) - \\vec{X(t)} \\right | \\\\\r\n\t\\vec{X}_{1} &= \\vec{X}_{\\alpha} - \\vec{A}_{1} \\cdot \\vec{D}_{\\alpha} \\\\\r\n\t\\vec{X}_{2} &= \\vec{X}_{\\beta} - \\vec{A}_{2} \\cdot \\vec{D}_{\\beta} \\\\\r\n\t\\vec{X}_{3} &= \\vec{X}_{\\delta} - \\vec{A}_{3} \\cdot \\vec{D}_{\\delta} \\\\\r\n\t\\vec{X}(t + 1) &= \\frac{\\vec{X}_{1} + \\vec{X}_{2} + \\vec{X}_{3}}{3} \\label{summary-modified-gwo-xt1}\r\n\\end{align}\r\n\r\n\\begin{algorithm}[h!]\r\n\\caption{Pseudocode for the proposed modified GWO.}\r\n\\label{modified-gwo-algorithm}\r\n\\begin{algorithmic}[1]\r\n\\State Set $T$ to be the maximum number of iterations.\r\n\\State Initialize the grey wolf population $\\vec{X}_{i} (i = 1, 2, \\ldots, n)$\r\n\\State Initialize $c$, and $a = 2$.\r\n\\State Calculate the fitness of each wolf.\r\n\\State Set $\\vec{X}_{\\alpha}$ to be the fittest wolf.\r\n\\State Set $\\vec{X}_{\\beta}$ to be the second fittest wolf.\r\n\\State Set $\\vec{X}_{\\delta}$ to be the third fittest wolf.\r\n\\While{t $<$ T}\r\n\t\\For{each wolf $\\vec{X}_{i}$}\r\n\t\t\\State Initialize $\\vec{A}_{1}$, $\\vec{A}_{2}$, $\\vec{A}_{3}$, $\\vec{C}_{1}$, $\\vec{C}_{2}$, and $\\vec{C}_{3}$.\r\n\t\t\\State Update the position of the current wolf $\\vec{X}_{i}$ using Equations \\ref{summary-modified-gwo-DAlpha} to \\ref{summary-modified-gwo-xt1}.\r\n\t\t\\State Set the orientation of each building using Equation \\ref{modified-gwo-bo}.\r\n\t\t\\State Clamp the buildings in $\\vec{X}_{i}$ using Equations \\ref{bx-clamp-equation} and \\ref{by-clamp-equation}.\r\n\t\\EndFor\r\n\t\\State Calculate the fitness of each wolf.\r\n\t\\State Update $\\vec{X}_{\\alpha}$, $\\vec{X}_{\\beta}$, and $\\vec{X}_{\\delta}$.\r\n\t\\State $a = 2 - \\frac{2t}{T}$\r\n\t\\State $t = t + 1$\r\n\\EndWhile \\\\\r\n\\Return $\\vec{X}_{\\alpha}$\r\n\\end{algorithmic}\r\n\\end{algorithm}\r\n\r\n\\section{Implementation Technologies}\r\nOur program was developed using C++17 compiled using the Clang 11 compiler in an elementaryOS Hera environment under release mode with the \\texttt{-03} optimized compilation flag turned on. Building was handled by CMake, and package management was handled by Conan. Our implementation is built on top of CoreX, a custom-developed 2D game engine. Using a game engine allowed us to visualize the results and configure experiments in a graphical manner. Using a custom engine over an over-the-shelf engine ensures that the implementation remains light and does not carry unnecessary features that are typically used in commercial game engines. The libraries EASTL, ImGUI, SDL 2, SDL 2 TTF. sdl-gpu, nlohmann JSON, and EnTT were used in developing the engine, with EnTT and ImGUI directly used by our implementation itself.", "meta": {"hexsha": "279fbf203bf5ca784e436f04e6330edd1999533b", "size": 26846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter5_methods.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": "chapter5_methods.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": "chapter5_methods.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": 86.8802588997, "max_line_length": 1686, "alphanum_fraction": 0.7102734113, "num_tokens": 7678, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9449947070591979, "lm_q2_score": 0.8198933293122506, "lm_q1q2_score": 0.7747948565532207}}
{"text": "\\lab{Conditioning and Stability}{Conditioning and Stability}\n\\objective{The condition number of a function measures how sensitive that function is to changes in the input.\nOn the other hand, the stability of an algorithm measures how accurately that algorithm computes the value of a function from exact input.\nBoth of these concepts are important for answering the crucial question, ``is my computer telling the truth?''\nIn this lab, we examine the conditioning of common linear algebra problems, including computing polynomial roots and matrix eigenvalues.\nWe also present an example to demonstrate how two different algorithms for the same problem may not have the same level of stability.}\n\n\\section*{Conditioning} % =====================================================\n\nThe \\emph{absolute condition number} of a function $f: \\mathbb{R}^m \\rightarrow \\mathbb{R}^n$ at a point $\\x\\in\\mathbb{R}^m$ is defined by\n\\begin{equation}\n\\hat{\\kappa} (\\x) = \\lim_{\\delta \\rightarrow 0^+} \\sup_{\\norm{\\mathbf{h}} < \\delta} { \\frac{\\norm{f(\\x + \\mathbf{h} ) - f(\\x)}}{\\norm{\\mathbf{h}}} }.\n\\label{eq:absolute-condition-number}\n\\end{equation}\n\nIn other words, the absolute condition number of $f$ is the limit of the change in output over the change of input.\nSimilarly, the \\emph{relative condition number} of $f$ is the limit of the relative change in output over the relative change in input,\n\\begin{equation}\n\\kappa(\\x)\n= \\lim_{\\delta \\rightarrow 0^+} \\sup_{\\norm{\\mathbf{h}} < \\delta} \\left({ \\frac{\\norm{f(\\x + \\mathbf{h} ) - f(\\x)}}{\\norm{f(\\x)}} } \\middle/ { \\frac{\\norm{\\mathbf{h}}}{\\norm{\\x}} }\\right)\n= \\frac{\\norm{\\x}}{\\norm{f(\\x)}} \\hat{\\kappa}(\\x).\n\\label{eq:relative-condition-number}\n\\end{equation}\n\nA function with a large condition number is called \\emph{ill-conditioned}.\nSmall changes to the input of an ill-conditioned function may produce large changes in output.\nIt is important to know if a function is ill-conditioned because floating point representation almost always introduces some input error, and therefore the outputs of ill-conditioned functions cannot be trusted.\n\nThe \\emph{condition number} of a matrix $A$, $\\kappa (A)=\\|A\\| \\|A^{-1}\\|$, is an upper bound on the condition number for many of the common problems associated with the matrix, such as solving the system $A\\x =\\b$.\nIf $A$ is square but not invertible, then $\\kappa(A) = \\infty$ by convention.\nTo compute $\\kappa(A)$, we often use the matrix 2-norm, which is the largest singular value $\\sigma_{\\max}$ of $A$.\nRecall that if $\\sigma$ is a singular value of $A$, $\\frac{1}{\\sigma}$ is a singular value of $A^{-1}$.\nThus, we have that\n\\begin{equation}\\label{eq:matrix_cond}\n\\kappa(A) = \\frac{\\sigma_{\\max}}{\\sigma_{\\min}},\n\\end{equation}\nwhich is also a valid equation for non-square matrices.\n\n\\begin{warn} % Ill-conditioned matrices.\nIll-conditioned matrices can wreak havoc in even simple applications.\n% Solving problems can become difficult or even impossible when working with matrices that have large condition numbers because small changes in input can quickly lead to inaccurate output.\nFor example, the matrix\n\\[\nA =\n\\left[\\begin{array}{cc}\n1 & 1 \\\\\n1 & 1.0000000001\n\\end{array}\\right]\n\\]\nis extremely ill-conditioned, with $\\kappa(A) \\approx 4\\times 10^{10}$.\nSolving the systems $A\\x = \\b_1$ and $A\\x = \\b_2$ can result in wildly different answers, even when $\\b_1$ and $\\b_2$ are extremely close.\n\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import linalg as la\n\n>>> A = np.array([[1, 1], [1, 1+1e-10]])\n>>> np.linalg.cond(A)\n39999991794.058899\n\n# Set up and solve a simple system of equations.\n>>> b1 = np.array([2, 2])\n>>> x1 = la.solve(A, b1)\n>>> print(x1)\n[ 2.  0.]\n\n# Solve a system with a very slightly different vector b.\n>>> b2 = np.array([2, 2+1e-5])\n>>> la.norm(b1 - b2)\n>>> x2 = la.solve(A, b2)\n>>> print(x2)\n[-99997.99172662  99999.99172662]   # This solution is hugely different!\n\\end{lstlisting}\n\nIf you find yourself working with matrices that have large condition numbers, check your math carefully or try to reformulate the problem entirely.\n\\end{warn}\n\n\\begin{info} % Orthonormal matrices are the best!\nAn \\emph{orthonormal matrix} $U$ has orthonormal columns and satisfies $U\\trp U = I$ and $\\|U\\|_2 = 1$.\nIf $U$ is square, then $U^{-1} = U\\trp$ and $U\\trp$ is also orthonormal.\nTherefore $\\kappa(U) = \\|U\\|_2\\|U^{-1}\\|_2 = 1$.\nEven if $U$ is not square, all of its singular values are equal to $1$, and again $\\kappa(U) = \\sigma_{\\max} / \\sigma_{\\min} = 1$.\n\nThe condition number of a matrix cannot be less than $1$ since $\\sigma_{\\max} \\ge \\sigma_{\\min}$ by definition.\nThus orthonormal matrices are, in a sense, the best kind of matrices for computations.\nThis is one of the main reasons why numerical algorithms based on the QR decomposition or the SVD are so important.\n\\end{info}\n\n\\begin{problem} % Compute matrix condition number.\nWrite a function that accepts a matrix $A$ and computes its condition number using (\\ref{eq:matrix_cond}).\nUse \\li{scipy.linalg.svd()}, or \\li{scipy.linalg.svdvals()} to compute the singular values of $A$.\nAvoid computing $A^{-1}$.\nIf the smallest singular value is $0$, return $\\infty$ (\\li{np.inf}).\n\nValidate your function by comparing it to \\li{np.linalg.cond()}.\nCheck that orthonormal matrices have a condition number of $1$ (use \\li{scipy.linalg.qr()} to generate an orthonormal matrix) and that singular matrices have a condition number of $\\infty$ according to your function.\n\\end{problem}\n\n% For large matrices where taking the SVD is difficult, the exact condition number of a matrix cannot always be computed and therefore must be estimated.\n% Although not covered here, there exist many algorithms that can efficiently and accurately estimate the condition number of a matrix.\n\n\\subsection*{The Wilkinson Polynomial} % --------------------------------------\n\nLet $f:\\mathbb{C}^{n+1} \\rightarrow \\mathbb{C}^n$ be the function that maps a collection of $n+1$ coefficients $(c_n, c_{n-1}, \\ldots, c_0)$ to the $n$ roots of the polynomial $c_nx^n+c_{n-1}x^{n-1}+\\ldots+c_2x^2+c_1x+c_0$.\nFinding polynomial roots is an extremely ill-conditioned problem in general, so the condition number of $f$ is likely very large.\nTo see this, consider the \\emph{Wilkinson polynomial}, made famous by James H. Wilkinson in 1963:\n\\[\nw(x) = \\prod_{r=1}^{20}(x-r) = x^{20} - 210x^{19} + 20615x^{18} - 1256850x^{17} + \\cdots.\n\\]\nLet $\\tilde{w}(x)$ be $w(x)$ where the coefficient on $x^{19}$ is very slightly perturbed from $-210$ to $-210.0000001$.\nThe following code computes and compares the roots of $\\tilde{w}(x)$ and $w(x)$ using NumPy and SymPy.\n\n\\begin{comment}\n\\begin{lstlisting}\n>>> w_coeffs = np.array([1, -210, 20615, -1256850, 53327946, -1672280820,\n                    40171771630, -756111184500, 11310276995381,\n                    -135585182899530, 1307535010540395,\n                    -10142299865511450, 63030812099294896,\n                    -311333643161390640, 1206647803780373360,\n                    -3599979517947607200, 8037811822645051776,\n                    -12870931245150988800, 13803759753640704000,\n                    -8752948036761600000, 2432902008176640000])\n>>> w_roots = np.arange(1, 21)\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{lstlisting}\n>>> import sympy as sy\n>>> from matplotlib import pyplot as plt\n\n# The roots of w are 1, 2, ..., 20.\n>>> w_roots = np.arange(1, 21)\n\n# Get the exact Wilkinson polynomial coefficients using SymPy.\n>>> x, i = sy.symbols('x i')\n>>> w = sy.poly_from_expr(sy.product(x-i, (i, 1, 20)))[0]\n>>> w_coeffs = np.array(w.all_coeffs())\n>>> print(w_coeffs[:6])\n[1 -210 20615 -1256850 53327946 -1672280820]\n\n# Perturb one of the coefficients very slightly.\n>>> h = np.zeros(21)\n>>> h[1]=1e-7\n>>> new_coeffs = w_coeffs - h\n>>> print(new_coeffs[:6])\n[1 -210.000000100000 20615 -1256850 53327946 -1672280820]\n\n# Use NumPy to compute the roots of the perturbed polynomial.\n>>> new_roots = np.roots(np.poly1d(new_coeffs))\n\\end{lstlisting}\n\nFigure \\ref{fig:wilkinson-perturbed-poly} plots $w(x)$ and $\\tilde{w}(x)$ together, and Figure \\ref{fig:wilkinon-perturbed-roots} and compares their roots in the complex plane.\n\n\\begin{figure}[H] % Original and pertubed Wilkinson polynomial + roots\n\\captionsetup[subfigure]{justification=justified}\n\\centering\n\\begin{subfigure}{.48\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/perturbed_poly.pdf}\n    \\caption{The original and perturbed Wilkinson polynomials.\n    They match for about half of the domain, then differ drastically.}\n    \\label{fig:wilkinson-perturbed-poly}\n\\end{subfigure}\n\\quad\n\\begin{subfigure}{.48\\textwidth}\n    \\centering\n    \\includegraphics[width=\\linewidth]{figures/perturbed_roots.pdf}\n    \\caption{Roots of the original and perturbed Wilkinson polynomials.\n    About half of the perturbed roots are complex.}\n    \\label{fig:wilkinon-perturbed-roots}\n\\end{subfigure}\n\\caption{}\n\\label{fig:wilkinson-polynomial}\n\\end{figure}\n\nFigure \\ref{fig:wilkinson-polynomial} clearly indicates that a very small change in just a single coefficient drastically changes the nature of the polynomial and its roots.\nTo quantify the difference, estimate the condition numbers (this example uses the $\\infty$ norm to compute $\\hat{\\kappa}$ and $\\kappa$).\n\n\\begin{lstlisting}\n# Sort the roots to ensure that they are in the same order.\n>>> w_roots = np.sort(w_roots)\n>>> new_roots = np.sort(new_roots)\n\n# Estimate the absolute condition number in the infinity norm.\n>>> k = la.norm(new_roots - w_roots, np.inf) / la.norm(h, np.inf)\n>>> print(k)\n28262391.3304\n\n# Estimate the relative condition number in the infinity norm.\n>>> k * la.norm(w_coeffs, np.inf) / la.norm(w_roots, np.inf)\n1.95063629993970+25                     # This is huge!!\n\\end{lstlisting}\n\nThere are some caveats to this example.\n\\begin{enumerate}\n\\item Computing the quotients in (\\ref{eq:absolute-condition-number}) and (\\ref{eq:relative-condition-number}) for a fixed perturbation $\\mathbf{h}$ only approximates the condition number.\nThe true condition number is the limit of such quotients.\nWe hope that when $\\|\\mathbf{h}\\|$ is small, a random quotient is at least the same order of magnitude as the limit, but there is no way to be sure.\n\n\\item This example assumes that NumPy's root-finding algorithm, \\li{np.roots()}, is \\emph{stable}, so that the difference between \\li{w_roots} and \\li{new_roots} is due to the difference in coefficients, and not to problems with \\li{np.roots()}.\nWe will return to this issue in the next section.\n\\end{enumerate}\nEven with these caveats, it is apparent that root finding is a difficult problem to solve correctly.\nAlways check your math carefully when dealing with polynomial roots.\n\n\\begin{problem}\nWrite a function that carries out the following experiment 100 times.\n\\begin{enumerate}\n\\item Randomly perturb the true coefficients of the Wilkinson polynomial by replacing each coefficient $c_i$ with $c_i*r_i$, where $r_i$ is drawn from a normal distribution centered at 1 with standard deviation $10^{-10}$ (use \\li{np.random.normal()}).\n\\item Plot the perturbed roots as small points in the complex plane.\nThat is, plot the real part of the coefficients on the $x$-axis and the imaginary part on the $y$-axis.\nPlot on the same figure in each experiment.\n\\\\(Hint: use a pixel marker, \\li{marker=','}, to avoid overcrowding the figure.)\n\\item Compute the absolute and relative condition numbers with the $\\infty$ norm.\n\\end{enumerate}\nPlot the roots of the unperturbed Wilkinson polynomial with the perturbed roots.\nYour final plot should resemble Figure \\ref{fig:wilkinsonpolynomial_many}.\nFinally, return the average computed absolute and relative condition numbers.\n\n\\begin{figure}[H]\n\\includegraphics[width=.7\\linewidth]{figures/wilkinson_prob_solution.pdf}\n\\caption{\nThis figure replicates Figure 12.1 on p. 93 of \\cite{Trefethen1997}.}\n\\label{fig:wilkinsonpolynomial_many}\n\\end{figure}\n\n\\label{prob:wilkinson-polynomial-roots}\n\\end{problem}\n\n\\subsection*{Calculating Eigenvalues} % ---------------------------------------\n\nLet $f:M_n(\\mathbb{C}) \\rightarrow \\mathbb{C}^n$ be the function that maps an $n \\times n$ matrix with complex entries to its $n$ eigenvalues.\nThis problem is well-conditioned for symmetric matrices, but it can be extremely ill-conditioned for non-symmetric matrices.\nLet $A$ be an $n\\times n$ matrix and let $\\boldsymbol{\\lambda}$ be the vector of the $n$ eigenvalues of $A$.\nIf $\\tilde{A} = A + H$ is a pertubation of $A$ and $\\tilde{\\boldsymbol{\\lambda}}$ are its eigenvalues, then the condition numbers of $f$ can be estimated by\n\\begin{equation}\n\\hat{\\kappa}(A) = \\frac{\\|\\boldsymbol{\\lambda} - \\tilde{\\boldsymbol{\\lambda}}\\|}{\\|H\\|},\n\\qquad\n\\kappa(A) = \\frac{\\|A\\|}{\\|\\boldsymbol{\\lambda}\\|}\\hat{\\kappa}(A).\n\\label{eq:eig-condition-numbers}\n\\end{equation}\n\n\\begin{problem}\\label{prob:eigenvalue} % Eigenvalue experiments\nWrite a function that accepts a matrix $A$ and estimates the condition number of the eigenvalue problem using (\\ref{eq:eig-condition-numbers}).\nFor the perturbation $H$, construct a matrix with complex entries where the real and imaginary parts are drawn from normal distributions centered at $0$ with standard deviation $\\sigma = 10^{-10}$.\n\\begin{lstlisting}\nreals = np.random.normal(0, 1e-10, A.shape)\nimags = np.random.normal(0, 1e-10, A.shape)\nH = reals + 1j*imags\n\\end{lstlisting}\nUse \\li{scipy.linalg.eig()} or \\li{scipy.linalg.eigvals()} to compute the eigenvalues of $A$ and $A+H$, and use the 2-norm for both the vector and matrix norms.\nReturn the absolute and relative condition numbers.\n\\label{prob:eig-condit}\n\\end{problem}\n\n\\begin{problem}\nWrite a function that accepts bounds $[x_{\\min},x_{\\max},y_{\\min},y_{\\max}]$ and an integer \\li{res}.\nUse your function from Problem \\ref{prob:eig-condit} to compute the relative condition number of the eigenvalue problem for the $2\\times 2$ matrix\n\\[\n\\left[\\begin{array}{cc}\n1 &  x\\\\\ny & 1\\end{array}\\right]\n\\]\nat every point of an evenly spaced \\li{res}$\\times$\\li{res} grid over the domain $[x_{\\min}, x_{\\max}]\\times [y_{\\min}, y_{\\max}]$.\nPlot these estimated relative condition numbers using \\li{plt.pcolormesh()} and the colormap \\li{cmap='gray_r'}.\nWith \\li{res=200}, your plot should look similar to the following figure.\n\n\\begin{figure}[H]\n    \\includegraphics[width=.7\\linewidth]{figures/eigenvalue_conditioning.png}\n\\end{figure}\n\n\\label{prob:eigenvalue-conditioning-plot}\n\\end{problem}\n\nProblem \\ref{prob:eigenvalue-conditioning-plot} shows that the conditioning of the eigenvalue problem depends heavily on the matrix, and that it is difficult to know a priori how bad the problem will be.\nLuckily, most real-world problems requiring eigenvalues are symmetric.\nIn their book on Numerical Linear Algebra, L. Trefethen and D. Bau III summed up the issue of conditioning and eigenvalues when they stated, ``\\emph{if the answer is highly sensitive to perturbations, you have probably asked the wrong question}.''\n\n\\section*{Stability} % ========================================================\n\nThe \\emph{stability} of an algorithm is measured by the error in its output.\nLet $f: \\mathbb{R}^m \\rightarrow \\mathbb{R}^n$ be a problem to be solved, as in the previous section, and let $\\tilde{f}$ be an actual algorithm for solving the problem.\nThe \\emph{forward error} of $f$ at $\\x$ is $||f(\\x)-\\tilde f(\\x)||$, and the \\emph{relative forward error} of $f$ at $\\x$ is\n\\[\n\\frac{||f(\\x)-\\tilde f(\\x)||}{||f(\\x)||}.\n\\]\nAn algorithm is called \\emph{stable} if its relative forward error is small.%\n\\footnote{See the Additional Material section for alternative (and more rigorous) definitions of algorithmic stability.}\n\nAs an example, consider again NumPy's root-finding algorithm that we used to investigate the Wilkinson polynomial.\nThe exact roots of $w(x)$ are clearly $1,2,\\ldots,20$.\nHad we not known this, we could have tried computing the roots from the coefficients using \\li{np.roots()} (without perturbing the coefficients at all).\n\n\\begin{lstlisting}\n# w_coeffs holds the coefficients and w_roots holds the true roots.\n>>> computed_roots = np.sort(np.roots(np.poly1d(w_coeffs)))\n>>> print(computed_roots[:6])       # The computed roots are close to integers.\n[ 1.          2.          3.          3.99999999  5.00000076  5.99998749]\n\n# Compute the forward error.\n>>> forward_error = la.norm(w_roots - computed_roots)\n>>> print(forward_error)\n0.020612653126379665\n\n# Compute the relative forward error.\n>>> forward_error / la.norm(w_roots)\n0.00038476268486104599              # The error is nice and small.\n\\end{lstlisting}\n\nThis analysis suggests that \\li{np.roots()} is a stable algorithm, so large condition numbers of Problem \\ref{prob:wilkinson-polynomial-roots} really are due to the poor conditioning of the problem, not the way in which the problem was solved.\n\n\\begin{info} % Conditioning versus Stability\nConditioning is a property of a \\textbf{problem} to be solved, such as finding the roots of a polynomial or calculating eigenvalues.\nStability is a property of an \\textbf{algorithm} to solve a problem, such as \\li{np.roots()} or \\li{scipy.linalg.eig()}.\nIf a problem is ill-conditioned, any algorithm used to solve that problem may result in suspicious solutions, even if that algorithm is stable.\n\\end{info}\n\n\n\\subsection*{Least Squares} % ----------------------------------------\n% An example of a problem with stable and unstable algorithms is the least squares problem.\n\nThe \\emph{ordinary least squares} (OLS) problem is to find the $\\x$ that minimizes $\\norm{A\\x -\\b}_2$ for fixed $A$ and $\\b$.\nIt can be shown that an equivalent problem is finding the solution of $A\\hrm A\\x =A\\hrm \\b$, called the \\emph{normal equations}.\n% This is repeated in the problem statement (as it should be).\n% \\begin{enumerate}\n% \\item Invert the matrix $A\\hrm A$ and then right multiply by $A\\hrm \\b$ to solve the normal equations.\n% Although this approach seems intuitive, it is actually highly unstable and can return an answer with a very large forward error.\n%\n% \\item\n% Use the QR-decomposition by factoring the $m\\times n$ matrix $A$ of rank $n\\geq m$ into $QR$, where $Q$ has orthonormal columns and $R$ is upper triangular.\n% It can also be shown that the solution of $R \\x = Q\\hrm\\b$ is equivalent to solving the least squares problem.\n% This algorithm has the advantage of being stable.\n% \\end{enumerate}\nA common application of least squares is polynomial approximation.\nGiven a set of $m$ data points $\\{(x_k, y_k)\\}_{k=1}^m$, the goal is to find the set of coefficients $\\{c_i\\}_{i=0}^n$ such that\n\\[\ny_k \\approx c_n x_k^n + c_{n-1} x_k^{n-1} + \\cdots + c_2 x_k^2 + c_1 x_k + c_0\n\\]\nfor all $k$, with the smallest possible error.\nThese $m$ linear equations yield the linear system\n\\begin{equation}\nA\\x =\n\\left[\\begin{array}{cccccc}\nx_1^n & x_1^{n-1} & \\cdots & x_1^2 & x_1 & 1 \\\\\nx_2^n & x_2^{n-1} & \\cdots & x_2^2 & x_2 & 1 \\\\\nx_3^n & x_3^{n-1} & \\cdots & x_3^2 & x_3 & 1 \\\\\n\\vdots & \\vdots & & \\vdots & \\vdots & \\vdots \\\\\nx_m^n & x_m^{n-1} & \\cdots & x_m^2 & x_m & 1 \\\\\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nc_n \\\\ c_{n-1} \\\\ \\vdots \\\\ c_2 \\\\ c_1 \\\\ c_0\n\\end{array}\\right]\n=\n\\left[\\begin{array}{c} y_1 \\\\ y_2 \\\\ y_3 \\\\ \\vdots \\\\ y_m \\end{array}\\right]\n= \\b.\n\\label{eq:condstab-poly-leastsq}\n\\end{equation}\n\n\\begin{comment} % Too much detail, they can work this part out.\n\\begin{lstlisting}\n# Use least squares to approximate sin(x) with a five-degree polynomial.\n>>> x = np.linspace(0, 6, 10)           # The x-values of the data.\n>>> b = np.sin(x) + .2*np.random.randn(10) # The y-values of the data (noisy).\n>>> A = np.vander(x, 6)                 # Set up the matrix of data values.\n>>> coeffs = la.lstsq(A, b)[0]          # Get the polynomial coefficients.\n\n>>> domain = np.linspace(0, 6, 100)     # Define a finer domain for plotting.\n>>> plt.plot(x, b, 'k*')\t\t\t\t# Plot the approximated points.\n>>> plt.plot(domain, np.sin(domain))\n\n# np.poly1d() converts an array of coefficients into a callable polynomial.\n>>> plt.plot(domain, np.poly1d(coeffs)(domain))\n\\end{lstlisting}\n\\end{comment}\n\n\\begin{problem}\nWrite a function that accepts an integer $n$.\nSolve for the coefficients of the polynomial of degree $n$ that best fits the data found in \\texttt{stability\\_data.npy}.\nUse two approaches to get the least squares solution:\n\n\\begin{enumerate}\n\\item Use \\li{la.inv()} to solve the normal equations: $\\x = (A\\trp A)^{-1}A\\trp \\b$.\nAlthough this approach seems intuitive, it is actually highly unstable and can return an answer with a very large forward error.\n\n\\item Use \\li{la.qr()} with \\li{mode='economic'} and \\li{la.solve_triangular()} to solve the system $R\\x = Q\\trp\\b$, which is equivalent to solving the normal equations.\nThis algorithm has the advantage of being stable.\n\\end{enumerate}\n\nLoad the data and set up the system (\\ref{eq:condstab-poly-leastsq}) with the following code.\n\n\\begin{lstlisting}\nxk, yk = np.load(\"stability_data.npy\").T\nA = np.vander(xk, n+1)\n\\end{lstlisting}\n\nPlot the resulting polynomials together with the raw data points.\nReturn the forward error $\\norm{A\\x-\\mathbf{b}}_2$ of both approximations.\n\\\\(Hint: The function \\li{np.polyval()} will be helpful for plotting the resulting polynomials.)\n\nTest your function using various values of $n$, taking special note of what happens for values of $n$ near $14$ (pictured below).\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{figures/lstsq_stability.pdf}\n\\end{figure}\n\\end{problem}\n\n\\subsection*{Catastrophic Cancellation} % -------------------------------------\n\nWhen a computer takes the difference of two very similar numbers, the result is often stored with a small number of significant digits and the tiniest bit of information is lost.\nHowever, these small errors can propagate into large errors later down the line.\nThis phenomenon is called \\emph{catastrophic cancellation}, and is a common cause for numerical instability.\n\nCatastrophic cancellation is a potential problem whenever floats or large integers that are very close to one another are subtracted.\nThis problem can be avoided by either rewriting the program to not use subtraction, or by increasing the number of significant digits that the computer tracks.\n\nFor example, consider the simple problem of computing $\\sqrt{a}-\\sqrt{b}$.\nThe computation can be done directly with subtraction, or by performing the equivalent division\n\\[\n\\sqrt{a}-\\sqrt{b} = (\\sqrt{a}-\\sqrt{b})\\frac{\\sqrt{a}+\\sqrt{b}}{\\sqrt{a}+\\sqrt{b}} = \\frac{a-b}{\\sqrt{a}+\\sqrt{b}}.\n\\]\n\n\\begin{lstlisting}\n>>> from math import sqrt           # np.sqrt() fails for very large numbers.\n\n>>> a = 10**20 + 1\n>>> b = 10**20\n>>> sqrt(a) - sqrt(b)               # Do the subtraction directly.\n0.0                                 # a != b, so information has been lost.\n\n>>> (a - b) / (sqrt(a) + sqrt(b))   # Use the alternative formulation.\n5e-11                               # Much better!\n\\end{lstlisting}\n\nIn this example, $a$ and $b$ are distinct enough that the computer can still tell that $a - b = 1$, but $\\sqrt{a}$ and $\\sqrt{b}$ are so close to each other that $\\sqrt{a} - \\sqrt{b}$ is computed as $0$.\n\n\\begin{problem}\nLet $I(n) = \\int_0^1 x^n e^{x - 1} dx$.\nIt can be shown that for a positive integer $n$,\n\\begin{equation}\nI(n) = (-1)^n(!n - \\frac{n!}{e}),\n\\label{eq:integral-subfactorial-formula}\n\\end{equation}\nwhere $!n=n!\\sum_{k=0}^{n} \\frac{(-1)^k}{k!}$ is the \\emph{subfactorial} of $n$.\nWrite a function to do the following.\n\\begin{enumerate}\n\\item Use SymPy's \\li{sy.integrate()} to evaluate the integral form of $I(n)$ for $n=5,10,\\ldots,50$.\nConvert the symbolic results of each integration to a float.\nSince this is done symbolically, these values can be accepted as the true values of $I(n)$.\n\\\\(Hint: be careful that the values of $n$ in the integrand are of type \\li{int}.)\n\n\\item Use (\\ref{eq:integral-subfactorial-formula}) to compute $I(n)$ for the same values of $n$.\nUse \\li{sy.subfactorial()} to compute $!n$ and \\li{sy.factorial()} to compute $n!$.\n\\\\(Hint: be careful to only pass Python integers to these functions.)\n\\label{step:subfactorial-cheat}\n\n\\item Plot the relative forward error of the results computed in step \\ref{step:subfactorial-cheat} at each of the given values of $n$.\nUse a log scale on the $y$-axis.\nIs (\\ref{eq:integral-subfactorial-formula}) a stable way to compute $I(n)$?\nWhy?\n\\end{enumerate}\n\\end{problem}\n\nThe examples presented in this lab are just a few of the ways that a mathematical problem can turn into a computational train wreck.\nAlways use stable algorithms when possible, and remember to check if problems are well conditioned or not.\n\n\\begin{comment}\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n$n$  & Actual value of $I(n)$ \\\\\n\\hline\n$1$  & $0.367879441171$ \\\\\n$5$  & $0.145532940573$ \\\\\n$10$ & $0.0838770701034$ \\\\\n$15$ & $0.0590175408793$ \\\\\n$20$ & $0.0455448840758$ \\\\\n$25$ & $0.0370862144237$ \\\\\n$30$ & $0.0312796739322$ \\\\\n$35$ & $0.0270462894091$ \\\\\n$40$ & $0.023822728669$ \\\\\n$45$ & $0.0212860390856$ \\\\\n$50$ & $0.0192377544343$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\end{comment}\n\n%\\begin{table}\n%\\centering\n%\\begin{tabular}{|l|l|l|}\n%\\hline\n%Integrand & Computed Value & Actual Value \\\\\n%\\hline\n%$x^{1}e^{x}$: & $0.367879441171$ & $0.367879441171$ \\\\\n%$x^{5}e^{x}$: & $0.145532940573$ & $0.145532940573$ \\\\\n%$x^{10}e^{x}$: & $0.0838770701084$ & $0.0838770701034$ \\\\\n%$x^{15}e^{x}$: & $0.0590209960938$ & $0.0590175408793$ \\\\\n%$x^{20}e^{x}$: & $0.0$ & $0.0455448840758$ \\\\\n%$x^{25}e^{x}$: & $1073741824.0$ & $0.0370862144237$ \\\\\n%$x^{30}e^{x}$: & $-1.80143985095 \\cdot 10^{16}$ & $0.0312796739322$ \\\\\n%$x^{35}e^{x}$: & $6.04462909807 \\cdot 10^{23}$ & $0.0270462894091$ \\\\\n%$x^{40}e^{x}$: & $0.0$ & $0.023822728669$ \\\\\n%$x^{45}e^{x}$: & $0.0$ & $0.0212860390856$ \\\\\n%$x^{50}e^{x}$: & $1.46150163733 \\cdot 10^{48}$ & $0.0192377544343$ \\\\\n%\\hline\n%\\end{tabular}\n%\\caption{Inaccuracy of values computed using an unstable algorithm.}\n%\\label{table:unstable_computation}\n%\\end{table}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Other Notions of Stability} % ------------------------------------\n\nThe definition of stability can be made more rigorous in the following way.\nLet $f$ be a problem to solve and $\\tilde{f}$ an algorithm to solve it.\nIf for every $\\x$ in the domain there exists a $\\tilde{\\x}$ such that\n\\[\n\\frac{\\|\\tilde{\\x} - \\x\\|}{\\|\\x\\|}\n\\qquad\\text{and}\\qquad\n\\frac{\\|\\tilde{f}(\\x) - f(\\tilde{\\x})\\|}{\\|f(\\tilde{\\x})\\|}\n\\]\nare small (close to $\\epsilon_{\\text{machine}} \\approx 10^{-16}$), then $\\tilde{f}$ is called stable.\nIn other words, ``A stable algorithm gives nearly the right answer to nearly the right question'' (Trefethen, Bao, 104).\nNote carefully that the quantity on the right is slightly different from the plain forward error introduced earlier.\n\nStability is desirable, but plain stability isn't the best possible condition.\nFor example, if for every input $\\x$ there exists a $\\tilde{\\x}$ such that\n$\\|\\tilde{\\x} - \\x\\| / \\|\\x\\|$ is small and $\\tilde{f}(\\x) = f(\\tilde{\\x})$ exactly, then $\\tilde{f}$ is called \\emph{backward stable}.\nThus ``A backward stable algorithm gives exactly the right answer to nearly the right question'' (Trefethen, Bao, 104).\nBackward stable algorithms are generally more trustworthy than stable algorithms, but they are also less common.\n\n\\begin{comment} % Unfinished garbage table.\n\\subsection*{Index of Conditioning and Stability of Algorithms} % -------------\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\\end{comment}\n\n\\subsection*{Stabilty of Linear System Solvers} % -----------------------------\n\nThe algorithms presented so far in this manual have different levels of stability.\nThe LU decomposition (with pivoting) is usually very good, but there are some pathological examples of matrices that can cause it to break down.\nEven so, \\li{scipy.linalg.solve()} uses the LU decomposition.\nThe QR decomposition (also with pivoting) is generally considered to be a better option than the LU decomposition and is more stable.\nHowever, solving a linear system using the SVD is even more stable than using the QR decomposition.\nFor this reason, \\li{scipy.linalg.lstsq()} uses the SVD.\n", "meta": {"hexsha": "0b936b53f3371af976b856f2f993bf298538fcba", "size": 29952, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume1/Conditioning_Stability/Conditioning_Stability.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/Conditioning_Stability/Conditioning_Stability.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/Conditioning_Stability/Conditioning_Stability.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": 50.5092748735, "max_line_length": 252, "alphanum_fraction": 0.6975827991, "num_tokens": 8683, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677506936879, "lm_q2_score": 0.9136765269395709, "lm_q1q2_score": 0.7747682294105687}}
{"text": "\\subsection{Positive definite matrices}\n\nPositive definite matrices are often encountered in applications such mechanics and statistics.\n\nWe begin with a definition.\n\n\\begin{definition}{Positive definite matrix}{positive-definite-matrix}\nLet $A$ be an $n \\times n$ symmetric matrix. Then $A$ is positive definite if all of its eigenvalues are positive.\n\\index{positive definite}\n\\end{definition}\n\nThe relationship between a negative definite matrix and positive definite matrix is as follows.\n\n\\begin{lemma}{Negative definite matrix}{negative-definite-matrix}\nAn $n\\times n$-matrix $A$ is negative definite if and only if $-A$ is\npositive definite.\n\\end{lemma}\n\n%%\\begin{proof}\n%%Suppose $A$ is negative definite. For all $\\vect{x}$,\n%%\\begin{equation*}\n%%\\vect{x}^{T}A\\vect{x}\\leq -\\delta \\norm{\\vect{x}} ^{2}\n%\\end{equation*}\n%%Then multiply both sides by $-1$ to find that $-A$ is positive definite.\n%%Next suppose for all $\\vect{x}$,\n%%\\begin{equation*}\n%%\\vect{x}^{T}(-A) \\vect{x}\\geq \\delta \\norm{\\vect{x}}\n%%^{2}.\n%%\\end{equation*}\n%%Then multiply by $-1$ to see that $A$ is negative definite.\n%%\\end{proof}\n%%\n%%\\medskip\n\n%%There is an equivalent characterization of a positive definite matrix in\n%%terms of eigenvalues.\n%%\n%%\\medskip\n%%\n%%\\begin{theorem}{Positive definite matrix and eigenvalues}{positive-definite-eigenvalues}  %%\\label{3-oct-3f}\n%%A symmetric matrix $A$ is positive definite if and only if all\n%%of its eigenvalues are positive. (Recall that all of the eigenvalues of a symmetric matrix are real.)\n%%\\index{positive definite!positive eigenvalues}\n%%\\end{theorem}\n%%\n%%\\medskip\n%%\n%%\\begin{proof}Suppose first that $A$ is positive definite. Let $\\lambda $\n%%is an eigenvalue with eigenvector $\n%%\\vect{u}$. Then, since $\\lambda $ is real,\n%%\\begin{equation*}\n%%\\vect{u}^{T}A\\vect{u}=\\lambda \\vect{u}^{T}\\vect{u}=\\lambda \\norm{\n%%u} ^{2}\\geq \\delta \\norm{\\vect{u}} ^{2}\n%%\\end{equation*}\n%%Hence $0<\\delta \\leq \\lambda$, this for any eigenvalue. Hence all\n%%eigenvalues are positive.\n%%\n%%Next suppose that all eigenvalues are positive. Then letting $\\delta $ be\n%%the smallest eigenvalue and $U$ a real orthogonal matrix such that $\n%%U^{T}AU=D$, a diagonal matrix having the eigenvalues of $A$ on the main\n%%diagonal,\n%%\\begin{equation*}\n%%\\vect{x}^{T}A\\vect{x}=\\vect{x}^{T}UDU^{T}\\vect{x}=(U^{T}\\vect{x})\n%%^{T}DU^{T}\\vect{x}=\\sum_{i=1}^{n}(U^{T}\\vect{x}) _{i}^{2}\\lambda\n%%_{i}\\geq \\delta \\sum_{i=1}^{n}(U^{T}\\vect{x}) _{i}^{2}=\\delta\n%%\\norm{U^{T}\\vect{x}} ^{2}\n%%\\end{equation*}\n%%Now $\\norm{U^{T}\\vect{x}} ^{2}=(U^{T}\\vect{x})\n%%^{T}U^{T}\\vect{x}=\\vect{x}^{T}UU^{T}\\vect{x}=\\vect{x}^{T}\\vect{x}=\\norm{\\vect{x}} ^{2}$ and so\n%%\\begin{equation*}\n%%\\vect{x}^{T}A\\vect{x}\\geq \\delta \\norm{\\vect{x}} ^{2}\n%%\\end{equation*}\n%%and so $A$ is positive definite.\n%%\\end{proof}\n%%\n%%\\medskip\n\nConsider the following lemma.\n\n\\index{positive definite!invertible}\n\\begin{lemma}{Positive definite matrix and invertibility}{pos-definite-invertible}\nIf $A$ is positive definite, then it is invertible.\n\\end{lemma}\n\n\\begin{proof}\nIf $A\\vect{v}=\\vect{0}$, then $0$ is an eigenvalue if $\\vect{v}$ is non-zero, which\ndoes not happen for a positive definite matrix. Hence $\\vect{v}=\\vect{0}$ and\nso $A$ is one to one. This is sufficient to conclude that it is invertible.\n\\end{proof}\n\nNotice that this lemma implies that if a matrix $A$ is positive definite, then $\\det(A) > 0$.\n\nThe following theorem provides another characterization of positive definite matrices. It gives a useful test for verifying if a matrix is positive definite.\n\n\\begin{theorem}{Positive definite matrix}{positive-definite}\nLet $A$ be a symmetric matrix. Then $A$ is positive definite if and\nonly if $\\vect{x}^T A \\vect{x} $ is positive for all non-zero $\\vect{x}\n\\in \\R^n$.\n\\end{theorem}\n\n\\begin{proof}\nSince $A$ is symmetric, there exists an orthogonal matrix $U$ so that\n\n\\[ U^{T}AU=\\func{diag}(\\lambda_1,\\lambda_2,\\ldots,\\lambda_n)=D,\\]\n\nwhere $\\lambda_1,\\lambda_2,\\ldots,\\lambda_n$ are the (not necessarily\ndistinct) eigenvalues of $A$.\nLet $\\vect{x}\\in\\R^n$, $\\vect{x}\\neq \\vect{0}$, and define\n$\\vect{y}=U^T\\vect{x}$.\nThen\n\\[ \\vect{x}^TA\\vect{x}=\\vect{x}^T(UDU^T)\\vect{x}\n= (\\vect{x}^TU)D(U^T\\vect{x})\n=\\vect{y}^TD\\vect{y}.\\]\n\nWriting $\\vect{y}^T=\\begin{mymatrix}{cccc}\ny_1 & y_2 & \\cdots & y_n\\end{mymatrix}$,\n\n\\begin{eqnarray*}\n\\vect{x}^TA\\vect{x} & = &\n\\begin{mymatrix}{cccc} y_1 & y_2 & \\cdots & y_n\\end{mymatrix}\n\\func{diag}(\\lambda_1,\\lambda_2,\\ldots,\\lambda_n)\n\\begin{mymatrix}{c} y_1 \\\\ y_2 \\\\ \\vdots \\\\ y_n\\end{mymatrix}\\\\\n& = & \\lambda_1 y_1^2 + \\lambda_2 y_2^2 + \\ldots + \\lambda_n y_n^2.\n\\end{eqnarray*}\n\n$(\\Rightarrow)$ First we will assume that $A$ is positive definite and prove that $\\vect{x}^T A \\vect{x} $ is positive.\n\nSuppose $A$ is positive definite, and $\\vect{x}\\in\\R^n$,\n$\\vect{x}\\neq\\vect{0}$.\nSince $U^T$ is invertible, $\\vect{y}=U^T\\vect{x}\\neq \\vect{0}$,\nand thus $y_j\\neq 0$ for some $j$, implying $y_j^2>0$\nfor some $j$.\nFurthermore, since all eigenvalues of $A$ are positive,\n$\\lambda_i y_i^2\\geq 0$ for all $i$ and $\\lambda_jy_j^2>0$.\nTherefore, $\\vect{x}^TA\\vect{x}>0$.\n\n$(\\Leftarrow)$ Now we will assume $\\vect{x}^T A \\vect{x} $ is positive and show that $A$ is positive definite.\n\nIf $\\vect{x}^TA\\vect{x}>0$ whenever $\\vect{x}\\neq \\vect{0}$,\nchoose $\\vect{x}=U\\vect{e}_j$, where $\\vect{e}_j$ is the $j\\th$\ncolumn of $I_n$.\nSince $U$ is invertible, $\\vect{x}\\neq\\vect{0}$,\nand thus\n\\[ \\vect{y}=U^T\\vect{x}=U^T(U\\vect{e}_j) =\\vect{e}_j.\\]\nThus $y_j=1$ and $y_i=0$ when $i\\neq j$, so\n\\[ \\lambda_1 y_1^2 + \\lambda_2 y_2^2 + \\ldots + \\lambda_n y_n^2\n=\\lambda_j,\\]\ni.e., $\\lambda_j=\\vect{x}^TA\\vect{x}>0$.\nTherefore, $A$ is positive definite.\n\\end{proof}\n\nThere are some other very interesting consequences which result from a\nmatrix being positive definite. First one can note that the property of\nbeing positive definite is transferred to each of the principal submatrices which we will now define.\n\n\\begin{definition}{The submatrix $A_k$}{submatrix-Ak}\nLet $A$ be an $n\\times n$-matrix. Denote by $A_{k}$ the $k\\times k$-matrix\nobtained by deleting the $k+1,\\ldots,n$ columns and the $k+1,\\ldots,n$\nrows from $A$. Thus $A_{n}=A$ and $A_{k}$ is the $k\\times k$ submatrix of $A$\nwhich occupies the upper left corner of $A$.\n\\index{principal submatrices}\n\\end{definition}\n\n\\begin{lemma}{Positive definite and submatrices}{positive-matrix-submatrix}\nLet $A$ be an $n\\times n$ positive definite matrix.  Then each submatrix $A_{k}$ is also positive definite.\n\\end{lemma}\n\n\\begin{proof}\nThis follows right away from the above definition. Let $\\vect{x}\\in \\R^{k}$ be non-zero. Then\n\\begin{equation*}\n\\vect{x}^{T}A_{k}\\vect{x}=\\begin{mymatrix}{cc}\n\\vect{x}^{T} & 0\n\\end{mymatrix} A\\begin{mymatrix}{c}\n\\vect{x} \\\\\n0\n\\end{mymatrix} >  0\n\\end{equation*}\nby the assumption that $A$ is positive definite.\n\\end{proof}\n\nThere is yet another way to recognize whether a matrix is positive definite\nwhich is described in terms of these submatrices. We state the result,  the proof\nof which can be found in more advanced texts.\n\n\\begin{theorem}{Positive matrix and determinant of $A_k$}{positive-matrix-determinant-Ak}\nLet $A$ be a symmetric matrix. Then $A$ is positive definite if\nand only if $\\det (A_{k})$ is greater than $0$ for every submatrix $A_{k}$,  $k=1,\\ldots,n$.\n\\index{principal submatrices!positive definite}\n\\index{positive definite!principal submatrices}\n\\end{theorem}\n\n\\begin{proof}\nWe prove this theorem by induction on $n$. It is clearly\ntrue if $n=1$. Suppose then that it is true for $n-1$ where $n\\geq 2$. Since\n$\\det (A) =\\det (A_{n}) >0$, it follows that all the\neigenvalues are non-zero. We need to show that they are all positive. Suppose\nnot. Then there is some even number of them which are negative, even because\nthe product of all the eigenvalues is known to be positive, equalling $\\det\n(A)$. Pick two, $\\lambda _{1}$ and $\\lambda _{2}$ and let $A\n\\vect{u}_{i}=\\lambda _{i}\\vect{u}_{i}$ where $\\vect{u}_{i}\\neq \\vect{0}$ for $\ni=1,2$ and $\\vect{u}_{1}\\dotprod \\vect{u}_{2}=0$. Now if $\\vect{y}\\equiv \\alpha\n_{1}\\vect{u}_{1}+\\alpha _{2}\\vect{u}_{2}$ is an element of $\\sspan\\set{\n\\vect{u}_{1},\\vect{u}_{2}}$, then since these are eigenvalues and $\\\n\\vect{u}_{1}\\dotprod \\vect{u}_{2}=0$, a short computation shows\n\\begin{equation*}\n(\\alpha _{1}\\vect{u}_{1}+\\alpha _{2}\\vect{u}_{2}) ^{T}A(\n\\alpha _{1}\\vect{u}_{1}+\\alpha _{2}\\vect{u}_{2})\n\\end{equation*}\n\\begin{equation*}\n=\\abs{\\alpha _{1}}^{2}\\lambda _{1}\\norm{\\vect{u}\n_{1}} ^{2}+\\abs{\\alpha _{2}}^{2}\\lambda\n_{2}\\norm{\\vect{u}_{2}} ^{2}<0.\n\\end{equation*}\nNow letting $\\vect{x}\\in \\R^{n-1}$, we can use the induction\nhypothesis to write\n\\begin{equation*}\n\\begin{mymatrix}{cc}\nx^{T} & 0\n\\end{mymatrix} A\\begin{mymatrix}{c}\n\\vect{x} \\\\\n0\n\\end{mymatrix} =\\vect{x}^{T}A_{n-1}\\vect{x}>0.\n\\end{equation*}\nNow the dimension of $\\set{\\vect{z}\\in \\R^{n}:z_{n}=0} $ is\n$n-1$ and the dimension of $\\sspan\\set{\\vect{u}_{1},\\vect{u}\n_{2}} =2$ and so there must be some non-zero $\\vect{x}\\in \\R\n^{n} $ which is in both of these subspaces of $\\R^{n}$. However, the\nfirst computation would require that $\\vect{x}^{T}A\\vect{x}<0$ while the\nsecond would require that $\\vect{x}^{T}A\\vect{x}>0$. This contradiction shows\nthat all the eigenvalues must be positive. This proves the if part of the\ntheorem. The converse can also be shown to be correct, but it is the\ndirection which was just shown which is of most interest.\n\\end{proof}\n\n\\begin{corollary}{Symmetric and negative definite matrix}{symmetric-definite-matrix} %\\label{pd3}\nLet $A$ be symmetric. Then $A$ is negative definite if and only\nif\n\\begin{equation*}\n(-1) ^{k} \\det (A_{k}) >0\n\\end{equation*}\nfor every $k=1,\\ldots,n$.\n\\end{corollary}\n\n\\begin{proof}This is immediate from the above theorem when we notice,\nthat $A$ is negative definite if and only if $-A$ is positive definite.\nTherefore, if $\\det (-A_{k}) >0$ for all $k=1,\\ldots,n$, it\nfollows that $A$ is negative definite. However, $\\det (-A_{k})\n=(-1) ^{k}\\det (A_{k})$.\n\\end{proof}\n", "meta": {"hexsha": "9bde7f3c51595a2b9afa6d747e21ad35e35aea07", "size": 9975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityPositiveDefinite.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/spectraltheoryOrthogonalityPositiveDefinite.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/spectraltheoryOrthogonalityPositiveDefinite.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.9, "max_line_length": 157, "alphanum_fraction": 0.6856140351, "num_tokens": 3425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.9136765157744067, "lm_q1q2_score": 0.7747682129220528}}
{"text": "\\lab{Single Pixel Camera}{Single Pixel Camera}\n\\label{lab:SPC}\n\n\\objective{You will build a single pixel camera that to take pictures of 2d and 3d tessellations.}\n\n\\section*{Single Pixel Camera}\nWhen you look at a picture on a computer screen it is divided into areas called pixels. \nEach pixel is a square that has a Red-Green-Blue (RGB) color value. \nWhen a  modern digital camera takes a picture it divides the picture in to pixels and stores the amount red, green, and blue light that comes in at each square.\n\nA single pixel camera treats the whole image as one pixel and thus only stores one RGB value that is the average color value of the whole image.  \n\n\\section*{2D Images}\nIn this lab we are going to represent the pictures as tessellated image.\nA tessellated image is a tiling with geometric shapes with no overlaps or gaps. \n\nIn this lab we assume that $\\mathcal{S}$ has a given tessellation $\\mathcal{T} = \\{F_i\\}$, where $F_i$ represents a particular face of our tessellation. \nWithout loss of generality, we will assume that each $F_i$ is a triangle. \nWe will represent the vertices of $F_i$ by $F^j_i$, where $F^j_i$ will be a column vector of length two representing the coordinates of $F_i$.\n\nRecall from multivariable calculus that the area of a triangle is half the magnitude of the cross product. \nFor $F_i$ this is given by\n\\begin{align}\nv_1 &= F_i^1 - F_i^0 \\\\\nv_2 &= F_i^2 - F_i^0 \\\\\nA_i &= \\frac{1}{2}\\abs{v_1[0] v_2[1] - v_1[1] v_2[0]}\n\\end{align}\n\n\nWe represent our signal, in this case our RBG color values, as a vector $s$, where the length of $s$ is the number of faces of our tessellation $\\mathcal{T}$. \nWe assume, naturally, that the value of our signal on the face $F_i$ is exactly the value $s[i]$.\nWe can then, using the areas previously calculated, express the single-pixel measurement of the signal of the camera as an inner product:\n\\begin{equation}\nA \\cdot s = b\n\\end{equation}\nIn addition, we assume that the total area of the image is equal to the sum of our tessellation. \nSo  \n\\begin{equation}\n\\hat{b} = \\frac{b}{\\sum_i A_i}\n\\end{equation}\nThen $\\hat{b}$ will be the RGB values of the singe pixel.\n\n\\begin{problem}\nWrite a function that takes in $S$, a 3-d array of the vertices of 2d tessellation faces, and $s$, the RBG values of the each tessellation. \nOutput the RGB value given by the single pixel camera. \nBelow is code to visualize the tessellation and $\\hat{b}$.  \nAlso included below is test code.\n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\nfrom matplotlib.collections import PolyCollection\n# This function plots a 2D tesselation, S, with the colors s \ndef visualize2d(S, s):\n    fig, ax = plt.subplots()\n    coll = PolyCollection(S, facecolors=s)\n    ax.add_collection(coll)\n    ax.autoscale_view()\n    plt.show()\n\\end{lstlisting}\n\\begin{lstlisting}\n#Let b be a 1d array of 3 values representing the RGB values. This plots the color\n>>> plt.imshow(np.array([[b]]))\n>>> plt.show()\n\\end{lstlisting}\n\\begin{lstlisting}\n#if your solution to problem 1 was called SPC2, your code should run similarly\n>>> test = np.array([[[.5,0],[0,1],[0,0]],[[.5,0],[0,-1],[0,0]],\n               [[-1,0],[0,1],[0,0]],[[-1,0],[0,-1],[0,0]]])\n>>> C = np.array([[0,0,1],[1,0,0],[0,1,0],[1,0,1]])\n>>> SPC2(test, C)\narray([ 0.5,  0.3333, 0.5])\n\\end{lstlisting}\n\\end{problem}\n\n\\section*{Projective Transforms}\nNow say that we have a tessellated 3d object and we would like to take a single pixel picture of it.\n\nWe begin by selecting a random camera location $c$. \nThe location is selected randomly on a sphere centered at the origin, with norm large enough that the entire surface lies inside the sphere. \nThe camera is assumed to point directly at the origin.\nIn order to keep the distance of the camera from the origin constant, this is best done by inputting the spherical coordinates and then changing to rectangular.\nRecall the that the formula to change polar coordinates to rectangular is \n\\[\nS(\\theta,\\phi,r)=(r*\\sin(\\phi)*\\cos(\\theta),r*\\sin(\\phi)*\\sin(\\theta),r*\\cos(\\phi))\n\\theta \\in [0,2\\pi),\\phi \\in [0,\\pi), r \\in [0,\\infty)\n\\]\n\\begin{problem}\nWrite a function that changes spherical coordinates to rectangular.\n\\end{problem}\n\nWe then utilize the projective transform to calculate how the camera ``sees'' the faces of the surface.\nHere we state the appropriate equations:\n\\begin{align}\nt &= \\text{acos}(\\frac{-c_2}{\\|c\\|}) \\\\\nw^* &= \\begin{bmatrix}\n\t\\frac{c_1}{\\|c\\|} \\\\\n\t\\frac{-c_0}{\\|c\\|} \\\\\n\t0\n\\end{bmatrix} \\\\\nw &= \\frac{w^*}{\\|w^*\\|} \\\\\n\\hat{w} &= \\begin{bmatrix}\n0 & 0 & w_1 \\\\\n0 & 0 & -w_0 \\\\\n-w_1 & w_0 & 0\n\\end{bmatrix} \\\\\nR &= e^{\\hat{w}t} = I + sin(t) \\hat{w} + (1-cos(t)) \\hat{w}^2 \\\\\nP &= \\begin{bmatrix}\nR^T & -R^T c \\\\\n0 & 1\n\\end{bmatrix}\n\\end{align}\n\nWe can then use the matrix $P$ to transform any point $x$ in homogenous world, in this case homogenous coordinates are created by simply appending 1 to the bottom of a given column vector, coordinates to homogenous camera coordinates $y$ by the equation:\n\\begin{equation*}\nPx = y\n\\end{equation*}\n\n\\begin{problem}\nWrite a function that takes in a camera location and outputs the transformation matrix.\n\\end{problem}\n\nWe can then find the projective transform (i.e. how the camera ``sees'' a point) by the equation:\n\\begin{equation}\nP_c(y) = \\begin{bmatrix}\n\\frac{y[0]}{f \\cdot y[2]} \\\\\n\\frac{y[1]}{f \\cdot y[2]}\n\\end{bmatrix}\n\\end{equation}\n\nHere $f$ represents the distance from the camera to the image plane, which is essentially an arbitrary constant.\nI recommend using $f=.5$.\n\n\\begin{problem}\nWrite a function that takes in a transformation matrix, a list of points in world coordinates, and a constant $f$ and outputs the projective transform of the points.\n\\end{problem}\n\nNow we essentially we have 2d points and we can calculate the areas as we did in the 2d case. Now we have the areas of each face of our tessellation with respect to our camera view. One thing that we need to worry about is the visibility of the face $F_j$. This constant, for convex surfaces, will either be zero or one. In this case the constant, if the center of the face denoted $Fc_j$ and $r$ is the radius of the tessellation. Then\n\\[\ne_j=||c-Fc_j||_2<\\sqrt{||c||_2^2+r^2}-\\epsilon\n\\] \nWhere $\\epsilon$ is small (I recommend .2 if the camera distance is 3).\nThen $e_j$ is a constant representing the  the visibility of of the face $F_j$.\n\n\\begin{problem}\nWrite a function that takes in an array of vertices of a tessellation, a camera position, the radius of the tessellation, and an $\\epsilon$ value and outputs an array of visibility constants.\n\\end{problem}\nThen:\n\n\\begin{equation}\nM(j) = A_j \\cdot e_j\n\\end{equation}\nThen\n\\begin{equation}\nM \\cdot s = b\n\\end{equation}\n\\begin{equation}\n\\frac{b}{\\sum_j M_j} = \\hat{b}\n\\end{equation}\nAnd $\\hat{b}$ is the RGB value of a picture taken by the single pixel camera at location $c$.\n\n\\begin{problem}\nUsing the previous problems, write a function that takes in an array of vertices of a tessellation, color values for the faces of the tessellation and a camera position in spherical coordinates and outputs single pixel RGB value. \nBelow is plotting script for 3d tessellations. \nIncluded is data from a satellite that makes a tessellation of the earth, Use it to test your function.\n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom mpl_toolkits.mplot3d.art3d import Poly3DCollection\nimport matplotlib.colors as colors\n\n# This function plots a 2D tesselation, F, with the colors C. \ndef visualize3d(F, C):\n    fig = plt.figure()\n    ax = Axes3D(fig)\n    l = len(F)\n    for n in xrange(l):\n        verts = [zip(F[n,0]*.5+.5, F[n,1]*.5+.5, F[n,2]*.5+.5)]\n        tri = Poly3DCollection(verts)\n        tri.set_color(colors.rgb2hex(C[n]))\n        tri.set_edgecolor('k')\n        ax.add_collection3d(tri)\n    plt.show()\n\\end{lstlisting}\n\\end{problem}\n\nYou can extend this for any tessellated object 2d or 3d.\nThe only thing that changes is how you calculate the area of the face (For example shoelace formula gives the area of any simple polygon).\nThe Projective Transform remains the same. \n\n\\section*{Application}\nThe single pixel camera is used in the field of compressed sensing (though the camera works a little differently than the one you made in this lab)\n", "meta": {"hexsha": "b90aebf0d7553c1840f5fd2a6d2afc05a75ab82b", "size": 8251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/SinglePixelCamera/SPC.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/SinglePixelCamera/SPC.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/SinglePixelCamera/SPC.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": 43.1989528796, "max_line_length": 436, "alphanum_fraction": 0.7211247122, "num_tokens": 2393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793452, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.77462743161736}}
{"text": "\\section{Homotopy invariance of homology}\nAs a side product, we'll construct something called the cross product. Here's the theorem.\n\t\\begin{theorem}\n\tIf $f_0,f_1:X\\to Y$ and $f_0\\sim f_1$, then $f_{0,\\ast}\\sim f_{1,\\ast}:S_\\ast(X)\\to S_\\ast(Y)$.\n\t\\end{theorem}\n\t\\begin{corollary}\n\tWith the same hypotheses, then $f_{0,\\ast}=f_{1,\\ast}: H_\\ast(X)\\to H_\\ast(Y)$, because chain homotopic maps induce the same map on homology.\n\t\\end{corollary}\nThe proof uses naturality (a lot). We'll produce a chain homotopy from the two inclusions $i_0,i_1:X\\to X\\times I$, and then homotope $f_0,f_1$ through a map $X\\times I\\to Y$. Namely, we'll construct a chain homotopy $h_X:S_n(X)\\to S_{n+1}(X\\times I)$ which gives a homotopy $i_{0,\\ast}\\sim i_{1,\\ast}$, and this'll be natural in $X$.\n\nThis gives the result we want. We can get a homotopy $h:=g\\circ h_\\ast:S_n(X)\\to S_{n+1}(X\\times I)\\to S_{n+1}(Y)$. Well:\n\t\t\\begin{multline*}\n\t\t\\partial h + h\\partial = \\partial(g_\\ast h_\\ast) + g_\\ast h_\\ast\\partial=g_\\ast\\partial h_\\ast + g_\\ast h_\\ast \\partial = g_\\ast(\\partial h_\\ast + h_\\ast\\partial)\\\\\n\t\t = g_\\ast(i_{1,\\ast} - i_{0,\\ast}) = g_\\ast i_{1,\\ast} - g_\\ast i_{0,\\ast} = (g\\circ i_1)_\\ast - (g\\circ i_0)_{\\ast} = f_{1,\\ast} - f_{0,\\ast}\n\t\t\\end{multline*}\n(The last equality is because $h_\\ast$ is a chain homotopy between $i_{1,\\ast}$ and $i_{0,\\ast}$.) So $h=g_\\ast\\circ h_\\ast$ is a chain homotopy. But how do we define $h_\\ast:S_n(X)\\to S_{n+1}(X\\times I)$? You want to take $\\sigma\\mapsto``\\sigma\\times I''$. More generally, we'll set up a cross product $\\times:S_p(X)\\times S_q(Y)\\to S_{p+q}(X\\times Y)$ that is natural, bilinear, satisfy the Leibniz rule, and are normalized.\n\nNaturality is exactly what you'd expect it to be. If $A,B,C$ are abelian groups, then $A\\times B\\to C$ is a bilinear map if $f(a+a^\\prime,b)=f(a,b)+f(a^\\prime,b)$ and similarly in the other variable (just substitute the $S_n(X)$ etc here). The Leibniz formula says:\n\t\t\\begin{equation*}\n\t\t\\partial(a\\times b) = (\\partial a)\\times b + (-1)^{|a|}a\\times\\partial b,\\quad\\text{where }|a|=p\\text{ means that }a\\in S_p(X).\n\t\t\\end{equation*}\nThe word normalized means that the following construction is correct. Suppose $q=0$; then this is a map $S_p(X)\\to S_0(Y)\\to S_p(X\\times Y)$, which (it suffices to define a map $\\Sin_p(X)\\times \\Sin_0(Y)\\to S_p(X\\times Y)$ because $\\left(\\sum_i a_i\\sigma_i,\\sum_j b_j\\tau_j\\right)\\mapsto \\sum_{i,j}a_ib_i(\\sigma_i\\times\\tau_j)$ by bilinearity) sending:\n\t\t\\begin{equation*}\n\t\t(\\sigma, c^0_y)\\mapsto \\left(\\begin{pmatrix}\\sigma \\\\ c^p_y\\end{pmatrix}:\\Delta^p\\to X\\times Y\\right)\n\t\t\\end{equation*}\nThis latter map is just the composition $\\Delta^p\\xrightarrow{\\sigma} X\\xrightarrow{\\text{inclusion at }y\\in Y}X\\times Y$. When $p=0$, we can send:\n\t\t\\begin{equation*}\n\t\t(c^0_x,\\tau)\\mapsto \\left(\\begin{pmatrix}c^p_0 \\\\ \\tau\\end{pmatrix}:\\Delta^p\\to X\\times Y\\right)\n\t\t\\end{equation*}\nThis latter map is just the composition $\\Delta^p\\xrightarrow{\\tau} Y\\xrightarrow{\\text{inclusion at }x\\in X}X\\times Y$. We have to check that this behaves correctly for the boundary map, namely, that Leibniz holds. We have:\n\t\t\\begin{equation*}\n\t\t\\partial(\\sigma\\times c^0_y) = \\partial\\sigma\\times c^0_y\n\t\t\\end{equation*}\nand similarly. We're going to use induction to define this for $p+q$; we've only done this for $p+q=0,1$. Let's assume it's done for $p+q-1$. First note that there's a universal example of a $p$-simplex, namely the map $\\iota_p:\\Delta^p\\to \\Delta^p$, because given any $p$-simplex $\\sigma:\\Delta^p\\to X$, you get $\\sigma=\\sigma_\\ast(\\iota_p)$ where $\\sigma_\\ast:\\Sin_p(\\Delta^p)\\to \\Sin_p(X)$. It suffices to define $\\iota_p\\times\\iota_q\\in S_{p+q}(\\Delta^p\\times\\Delta^q)$; you're supposed to think of the product of two simplices as a prism, which isn't a simplex itself - but you can triangulate it and look at it as the formal sum of two simplices. Then $\\sigma\\times \\tau = (\\sigma\\times\\tau)_\\ast(\\iota_p\\times\\iota_q)$ where $(\\sigma\\times\\tau)_\\ast:S_{p+q}(\\Delta^p\\times\\Delta^q)\\to S_{p+q}(X\\times Y)$. We need this to satisfy the Leibniz rule, so that:\n\t\t\\begin{equation*}\n\t\tS_{p+q-1}(\\Delta^p\\times\\Delta^q)\\ni \\partial(\\iota_p\\times\\iota_q) = (\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q\n\t\t\\end{equation*}\nA necessary condition for $\\iota_p\\times\\iota_q$ to exist is that $\\partial((\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q) =0$. Let's compute what this is.\n\t\t\\begin{equation*}\n\t\t\\partial((\\partial\\iota_p)\\times\\iota_q + (-1)^p\\iota_p\\times\\partial\\iota_q) = \\partial^2(\\iota_p)\\times\\iota_q + (-1)^{p-1}(\\partial \\iota_p)\\times(\\partial \\iota_q) + (-1)^p(\\partial\\iota_p)\\times(\\partial\\iota_q) + (-1)^q\\iota_p\\times\\partial^2\\iota_q = 0\n\t\t\\end{equation*}\nbecause $\\partial^2=0$. \n\nThe subspace $\\Delta^p\\times\\Delta^q\\subseteq\\mathbf{R}^{p+1}\\times\\mathbf{R}^{q+1}$ is convex, so by translation, it's homeomorphic to a star-shaped region. But we know that $ H_{p+q-1}(\\Delta^p\\times\\Delta^q)=0$ because $p+q>1$, which means that every cycle is a boundary. In other words, what we checked above is also sufficient! So, choose any element $\\iota_p\\times\\iota_q$ with the right boundary. This means we're done if we check that this choice satisfies naturality, bilinearity, and the Leibniz rule (left to reader). We'll now define $h_X:S_n(X)\\to S_{n+1}(X\\times I)$ via $h_Xc = c\\times\\iota$ where $\\iota:\\Delta^1\\to I$ is the obvious map. The cross product is in $S_{p+1}(X\\times I)$. Let's compute:\n\t\t\\begin{equation*}\n\t\t\\partial h_X = \\partial(c\\times \\iota) = \\partial c\\times\\iota + (-1)^{|c|}c\\times\\partial\\iota\n\t\t\\end{equation*}\nBut now, $\\partial\\iota = c_1^0 - c_0^0\\in S_0(I)$, which means that this becomes $\\partial c\\times\\iota + (-1)^{|c|}(\\iota_{1,\\ast} - \\iota_{0,\\ast})$. We'll do a little more next time.\n", "meta": {"hexsha": "f08ae51abf627ffb46b3a84bde55f667fada1cbb", "size": 5799, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-6-homotopy-invariance.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-6-homotopy-invariance.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-6-homotopy-invariance.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 118.3469387755, "max_line_length": 863, "alphanum_fraction": 0.6954647353, "num_tokens": 2146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213826762113, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7746274212972898}}
{"text": "\\documentclass{homework}\n\n\\course{Fluid Mechanics and Operations}{2}\n\n\\begin{document}\n\n\\section{MSH Problem 2.2}\n\n\\textit{\\underline{Solution:}}\n\n$dP + g\\rho dZ = 0$, \\quad $\\rho = \\displaystyle \\frac{PM}{RT}$, \\quad $T = 288-0.005Z$\n\\vspace{1.2ex}\n\n$\\Rightarrow dP + \\displaystyle \\frac{gPM}{R(288-0.005Z)} dZ = 0 \\Rightarrow\n\\int \\frac{1}{P} dP = \\int -\\frac{gM}{R(288-0.005Z)} dZ$\n\\vspace{1.2ex}\n\n$\\Rightarrow \\ln \\displaystyle \\frac{P_b}{P_a} = -\\frac{gM}{R} \\frac{-1}{0.005} \\ln\\left\\lvert\\frac{288-0.005Z}{288}\\right\\rvert$\n\\vspace{1.2ex}\n\n$\\Rightarrow \\ln \\displaystyle \\frac{1}{2} = \\frac{9.8 \\cdot 28.8 \\cdot 10^{-3}}{8.3145} \\frac{1}{0.005} \\ln\\left\\lvert\\frac{288-0.005Z}{288}\\right\\rvert$\n\\vspace{1.2ex}\n\n$\\Rightarrow Z = 5591$m\n\n\\section{MSH Problem 2.7}\n\n\\textit{\\underline{Solution:}}\n\n$r_2 = \\displaystyle \\frac{0.150}{2} = 0.075$m, \\quad $r_B = r_1 = 0.04$m\n\\vspace{1.2ex}\n\n$V_A = V_B \\Rightarrow \\pi(r_2^2 - r_i^2) = \\pi (r_i^2 - r_B^2)\\Rightarrow r_i = 0.060$m\n\\vspace{1.2ex}\n\n$\\rho_B(r_i^2-r_B^2) = \\rho_A(r_i^2-r_A^2) \\Rightarrow \\displaystyle \\frac{\\rho_B}{\\rho_A}(r_i^2 - r_B^2) = r_i^2 - r_A^2$\n\n\\begin{displaymath}\n\t\\Rightarrow r_A = \\sqrt{r_i^2 - \\frac{\\rho_B}{\\rho_A} (r_i^2 - r_B^2)} = \\sqrt{0.060^2 - \\frac{1020}{1109} (0.060^2 - 0.04^2)} = 0.042 m\n\\end{displaymath}\n\n\\section{}\n\n\\textit{\\underline{Solution:}}\n\n$P_g = -1.7psi + 62.42\\displaystyle \\frac{lb}{ft^3} \\cdot 1.6 \\cdot 1.5 ft \\frac{ft^2}{144in^2} = -0.66psi$\n\\vspace{1.2ex}\n\n$-0.66psi + 62.42 \\cdot SG_B \\cdot 1.25 \\cdot \\displaystyle\\frac{1}{144} = 0$\n\\vspace{1.2ex}\n\n$\\Rightarrow SG_B=1.22$\n\n\\end{document}", "meta": {"hexsha": "05a33c4a8367a11a3d2c1f132203e787cd36ab5d", "size": 1599, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Template/homework.tex", "max_stars_repo_name": "installbtien/LaTeX", "max_stars_repo_head_hexsha": "a107c25500c81e1830e5ed538e0f21723b97327c", "max_stars_repo_licenses": ["MIT"], "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/homework.tex", "max_issues_repo_name": "installbtien/LaTeX", "max_issues_repo_head_hexsha": "a107c25500c81e1830e5ed538e0f21723b97327c", "max_issues_repo_licenses": ["MIT"], "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/homework.tex", "max_forks_repo_name": "installbtien/LaTeX", "max_forks_repo_head_hexsha": "a107c25500c81e1830e5ed538e0f21723b97327c", "max_forks_repo_licenses": ["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.6111111111, "max_line_length": 154, "alphanum_fraction": 0.6404002502, "num_tokens": 723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213799730774, "lm_q2_score": 0.8615382040983515, "lm_q1q2_score": 0.7746274189684366}}
{"text": "\\section*{Ex.29.3-5}\n\\subsubsection*{Solve using Simplex}\n\nThe problem is\n\n\\begin{alignat*}{4}\n&\\max              \\quad && 18x_1 +    &&12.5x_2       &&         \\\\\n&\\text{subject to} \\quad && x_1   +    &&    x_2       && \\leq 20 \\\\\n&                        && x_1        &&              && \\leq 12 \\\\\n&                        &&            &&    x_2       && \\leq 16 \\\\\n&\\text{and} \\quad        && x_1 \\geq 0,&&    x_2 \\geq 0&&\n\\end{alignat*}\n\nWe introduce the slack variables and rewrite the problem such that the new slack variables are in the basis solution\n\n\\begin{alignat*}{4}\n&z     &&=  0  && +18x_1  &&+12.5x_2    \\\\\n&x_3   &&= 20  && -x_1    &&    -x_2       \\\\\n&x_4   &&= 12  && -x_1    &&               \\\\\n&x_5   &&= 16  &&         &&    -x_2 \n\\end{alignat*}\n\nBoth coefficients in the objective function are positive, hence increasing their value will increase the maximum. However, increasing them to much, will cause the current basic variables to become negative.\n\\\\\nFirst, we choose $x_1$ to enter as a basis variable. To determine which variable will leave the basis, we determine which of the current basis variables that will decrease to 0 first (making the constraint \\textit{tight}), when $x_1$ is increased. This turns out to be $x_4$. When we let $x_1$ enter the basis instead of $x_4$ we get\n\n\\begin{alignat*}{4}\n&z     &&=  216  && + 12.5 x_2 &&   -18x_4    \\\\\n&x_1   &&= 12    &&            &&     -x_4       \\\\\n&x_3   &&= 8     &&       -x_2 &&     +x_4       \\\\\n&x_5   &&= 16    &&       -x_2 &&    \n\\end{alignat*}\n\nThe objective function can potentially still be increased by inserting $x_2$ into the basis. In this case $x_3$ will leave the basis, by repeating the same procedure as above. The new problem maximization problem is then given by\n\n\\begin{alignat*}{4}\n&z     &&=  316  && - 12.5 x_3 &&   -5.5x_4    \\\\\n&x_1   &&= 12    &&            &&     -x_4       \\\\\n&x_2   &&= 8     &&       -x_3 &&     +x_4       \\\\\n&x_5   &&= 8    &&        +x_3 &&     -x_4\n\\end{alignat*}\n\nSo the optimal solution is when $x=(12,8,0,0,8)$ with optimal value $z=316$.", "meta": {"hexsha": "77c3523b6df949698ba7e1d0507c2ea2eb050bf8", "size": 2084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge2/Ex.29.3-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": "Uge2/Ex.29.3-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": "Uge2/Ex.29.3-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": 48.4651162791, "max_line_length": 333, "alphanum_fraction": 0.537428023, "num_tokens": 708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213664574069, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7746274137171437}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n\\usepackage{comment}\n\\usepackage{dirtytalk}\n\n\\usepackage{cleveref}\n\n\\bibliographystyle{ieeetr}\n\n\\begin{document}\n\n\\section{The Abstract Koopman Operator} \\label{sec:Abstract}\n\n    Koopman operators consist on a dimension lifting technique that allows us to model a Finite Dimensional Nonlinear Dynamical System through an Infinite Dimensional Linear Dynamical System.\n    \n    Koopman operators provide a convenient framework where traditional, more mature and optimized Linear System Identification and Control tools can be applied to a nonlinear system. In contrast with conventional linearization methods that depend on local derivatives, the Koopman operator provides an exact description (at least in theory) of the system's dynamics and, more importantly from the Applied Controls point of view, it is easily adaptable to a fully data-driven pipeline, provided we have some way of probing the internal states of the system (gray-box framework).\n\n    We start by stating the abstract problem, partially borrowing the definition from Mezić et Al.\\cite{Koopman_Basics}\\cite{Applied_Koopmanism}. Consider a continuous-time dynamical system such as the one given in \\cref{eq:CT_Dyn} on the state space $M$, where $\\mathbf{x}$ is a coordinate vector of the state, and $\\textbf{F}$ is (assumed to be) a non-linear vector-valued smooth function of the same dimension as its argument.\n\n    \\begin{equation} \\label{eq:CT_Dyn}\n        \\mathbf{\\dot{x}} = \\mathbf{F}\\left( \\mathbf{x} \\right) , \\mathbf{x} \\in M\n    \\end{equation}\n    \n    Let $S^t(\\mathbf{x}_0)$ denote the position the position at time $t$ of the trajectory of the system in \\cref{eq:CT_Dyn} that starts at $t=0$ from the state $\\mathbf{x}_0$, and let $g:M \\mapsto \\mathbb{C}$ an \\textit{arbitrary} (at least for now), complex-valued function. We call $g$ an observable of the system in \\cref{eq:CT_Dyn}, whose value observed over a trajectory starting from $\\mathbf{x}_0$ at $t=0$ changes with time according to the flow, as described in \\cref{eq:obs_traj}.\n\n    \\begin{equation} \\label{eq:obs_traj}\n        g\\left(t,\\mathbf{x}_0\\right) = g \\left(\\mathbf{S}^t\\left(\\mathbf{x}_0\\right)\\right)\n    \\end{equation}\n    \n    The space $\\mathcal{G}$ of all observables such as $g$ is a linear functional space, and thus we can define a family of linear operators $U^t:\\mathcal{G} \\mapsto \\mathcal{G}$ with $t \\in \\left[0,\\infty\\right)$ through \\cref{eq:Koopman_CT}.\n\n    \\begin{equation} \\label{eq:Koopman_CT}\n        U^t g\\left(\\mathbf{x}_0\\right) = g \\left(S^t \\left(\\mathbf{x}_0\\right)\\right)\n    \\end{equation}\n\n    Thus, for a fixed $t$, $U^t$ maps the vector-valued observable $g(\\mathbf{x}_0)$ into $g\\left(t,\\mathbf{x}_0\\right)$. We will call the family of all operators $U^t$, indexed by time $t$, the \\textbf{Koopman Semigroup} given by the generator $U$ of the continuous-time system in \\cref{eq:CT_Dyn}.\n\n    In Discrete Time, the definition is even simpler. Let \\cref{eq:DT_Dyn} describe a discrete-time dynamical system with $\\mathbf{z} \\in M$ and $\\mathbf{T}:M \\mapsto M$. Then, the associated Koopman operator $U$ is defined by \\cref{eq:Koopman_DT}.\n\n    \\begin{equation} \\label{eq:DT_Dyn}\n        \\mathbf{z}_{k+1} = \\mathbf{T}\\left(\\mathbf{z}\\right) , \\left\\{\\mathbf{z}_k,\\mathbf{z}_{k+1}\\right\\} \\subset M\n    \\end{equation}\n\n    \\begin{equation} \\label{eq:Koopman_DT}\n        U g\\left(\\mathbf{z}\\right) = g \\circ \\mathbf{T} \\left(\\mathbf{z}\\right)\n    \\end{equation}\n\n    At this point, it is worth noting that the discrete-time Koopman operator is also linear; i.e., $U\\left(c_1 \\mathbf{f}_1\\left(\\mathbf{z}\\right) + c_2 \\mathbf{f}_2\\left(\\mathbf{z}\\right)\\right) =\n    c_1 \\mathbf{f}_1\\left(\\mathbf{T}\\left(\\mathbf{z}\\right)\\right) + c_2 \\mathbf{f}_2\\left(\\mathbf{T}\\left(\\mathbf{z}\\right)\\right) =\n    c_1 U\\mathbf{f}_1\\left(\\mathbf{z}\\right) + c_2 U\\mathbf{f}_2\\left(\\mathbf{z}\\right)$. This linearity allows us to derive \\cref{eq:DT_Koopman_Concat}, which implies that the dynamics of the observables of a system over a trajectory $S^k\\left(\\mathbf{z}_0\\right)$ can be entirely described by the consecutive application of the discrete-time Koopman operator without having to \\say{observe} the system twice for a single trajectory.\n\n    \\begin{equation} \\label{eq:DT_Koopman_Concat}\n        g \\circ \\mathbf{T}\\left(\\mathbf{T}\\left(\\mathbf{z}_0\\right)\\right) = U g\\left(\\mathbf{T}\\left(\\mathbf{z}_0\\right)\\right) = U g \\circ \\mathbf{T} \\left(\\mathbf{z}_0\\right) = U^2 g\\left(\\mathbf{z}_0\\right) , \\mathbf{z}_0 \\in M\n    \\end{equation}\n    \n\\begin{comment}\n    By taking advantage of this linearity, we can now make use of eigenfunction decomposition in order to obtain further information from the defined operator. We call $\\phi : M \\mapsto \\mathbb{C}$ an eigenfunction of the Koopman operator $U$, associated to an eigenvalue $\\lambda \\in \\mathbb{C}$.\n\\end{comment}\n\n\\section{The Koopman Operator for Data-driven Real System Identification}\n\n    \\subsection{Applied problem definition}\n\n        After properly defining the abstract the Koopman operator, we now want to establish a practical framework in order to make use of its properties for System Identification and Control applications. We start by redefining $M$ as a real vector-space, and we follow the numerical scheme proposed by Mauroy-Goncalves\\cite{Goncalves} as a data-driven Identification method for dynamical systems.\n        \n        We consider the Real Dynamical System described in \\cref{eq:CT_Dyn_Real}, where $n$ is the dimension of the system. \n\n        \\begin{equation} \\label{eq:CT_Dyn_Real}\n            \\dot{\\mathbf{x}} = \\mathbf{F}\\left(\\mathbf{x}\\right), \\mathbf{x} \\in \\mathbb{R}^n\n        \\end{equation}\n\n        The vector field $\\mathbf{F}$ is w.l.o.g. of the form described in \\cref{eq:F_Decomp}, where the $k$ vectors $\\mathbf{w}_i = \\left( w_i^1 \\cdots w_i^n \\right)^T \\in \\mathbb{C}^n$ are unknown coefficients to be identified, whereas the $k$ library functions $h_i : \\mathbb{R}^n \\mapsto \\mathbb{C}$ are assumed to be known; note that some coefficients might be zero.\n\n        \\begin{equation} \\label{eq:F_Decomp}\n            \\mathbf{F}(\\mathbf{x}) = \\sum_{i = 1}^{N_F} \\mathbf{w}_i h_i \\left( \\mathbf{x} \\right)\n        \\end{equation}\n\n        Our first goal is to identify the vector field F (i.e., the $N_F$ coefficient vectors $\\mathbf{w}_i$) from snapshot measurements of the system trajectories. We consider $K$ snapshot pairs $\\left(\\mathbf{x}_k,\\mathbf{y}_k\\right)$ obtained from noisy measurements yielding \\cref{eq:x_noisy,eq:y_noisy}, where $\\epsilon$ is the state-dependent measurement noise, and \\cref{eq:snap}, which is associated to the dynamical system described in \\cref{eq:CT_Dyn}.\n\n        \\begin{align}\n            \\mathbf{x}_k &= \\bar{\\mathbf{x}}_k + \\epsilon\\left(\\mathbf{x}_k\\right) \\label{eq:x_noisy} \\\\\n            \\mathbf{y}_k &= \\bar{\\mathbf{y}}_k + \\epsilon\\left(\\mathbf{y}_k\\right) \\label{eq:y_noisy} \\\\\n            \\mathbf{y}_k &= \\mathbf{S}^{T_s}\\left(\\mathbf{x}_k\\right) \\label{eq:snap}\n        \\end{align}\n\n        We assume that the measurement noise is Gaussian and proportional to the state value; i.e., $\\epsilon\\left(\\mathbf{x}\\right) = \\mathbf{x} \\cdot \\mathbf{\\eta} , \\eta \\sim \\mathcal{N}\\left(0,\\sigma_\\text{meas}\\right)$. We also assume all snapshot pairs lie in a compact set $X \\subset \\mathbb{R}^n$ and are obtained with the same sampling time $T_s$, but we are not compelled to extracting all samples from the same trajectory (i.e., associated to the same starting point $\\mathbf{z}_0$).\n    \n    \\subsection{Applied Koopman operator}\n\n        As we stated in \\cref{sec:Abstract}, we can alternatively describe the behavior of the system  through a collection of \\textit{observables} $g : \\mathbb{R}^n \\mapsto \\mathbb{C}$ in a lifted space instead of using the original system states. Provided that the functions are continuously differentiable, their dynamics in the lifted space are given by \\cref{eq:obs_dyn}, where $\\dot{g}$ denotes $\\frac{\\partial \\left(f \\circ \\mathbf{S}^t\\right)}{\\partial t}$ and $\\nabla$ denotes the gradient.\n\n        \\begin{equation} \\label{eq:obs_dyn}\n            \\dot{g} = \\left(\\mathbf{F} \\cdot \\nabla\\right) g , g \\in \\mathcal{G}\n        \\end{equation}\n\n        In contrast to \\cref{eq:CT_Dyn_Real}, the dynamics in \\cref{eq:obs_dyn} are now infinite dimensional, but linear. Not only that, but we can also recover the semigroup-driven dynamics described in \\cref{eq:Koopman_CT}. That means that while the original state-space flow induced by \\cref{eq:CT_Dyn_Real} is given by the nonlinear flow map $S^t$, the flow induced by \\cref{eq:obs_dyn} in the lifted space $\\mathcal{G}$ is given by the linear semigroup of Koopman operators $U^t$ behaving just as in \\cref{eq:obs_traj}.\n        \n        Under appropriate conditions (see \\cite{Goncalves}), the semigroup of Koopman operators is strongly continuous and generated by the operator $L$ in \\ref{eq:infinitesimal_gen}, which we will call the infinitesimal generator of the Koopman operator; we denote its domain by $\\mathcal{D} \\left(L\\right)$.\n\n        \\begin{equation} \\label{eq:infinitesimal_gen}\n            L = \\mathbf{F} \\cdot \\nabla \\implies U^t = e^{Lt}\n        \\end{equation}\n\n        We will later exploit this continuity to manipulate the inherent sample time of the desired discrete Koopman operator, since this versatility turns out to be really helpful when controlling a real system.\n\n    \\subsection{Linear identification in the Lifted Space}\n\n        The semigroup of Koopman operators $U^t$ that describes the flow $S^t$ is unique for each system. It is by exploiting this equivalence relation that we can set ourselves to recover the system dynamics entirely from the Lifted Space. We divide the identification into three main steps:\n\n        \\begin{itemize}\n            \\item \\textit{Data lifting:} the snapshot pairs $\\left(\\mathbf{x}_k,\\mathbf{y}_k\\right)$ described in \\cref{eq:snap} are lifted to the space of observables by constructing new pairs of the form\\\\$\\left(\\mathbf{g}\\left(\\mathbf{x}_k\\right),\\mathbf{g}\\left(\\mathbf{y}_k\\right)\\right)$ for some $\\mathbf{g} = \\left\\{g_j\\right\\}_{j=1}^{N} \\subset \\mathcal{G}$; each \\textit{basis function} $g_j$ is assumed to be continuously differentiable. \\Cref{eq:Koopman_snap} follows from \\cref{eq:x_noisy,eq:y_noisy,eq:snap}.\n            \n            \\begin{align} \\label{eq:Koopman_snap}\n                \\mathbf{g} \\left(\\mathbf{y}_k\\right) &= \\mathbf{g} \\left(S^{T_s} \\left(\\mathbf{x}_k - \\epsilon\\left(\\mathbf{x}_k\\right)\\right) + \\epsilon\\left(\\mathbf{y}_k\\right)\\right)\n                \\\\\n                & \\approx U^{T_s} \\mathbf{g}\\left(\\mathbf{x}_k\\right) + \\mathcal{O} \\left(\\left|\\left|\\epsilon\\right|\\right|\\right)\n            \\end{align}\n\n            \\item \\textit{Identification of the Koopman operator:} A truncated finite-dimensional projection of the Koopman operator is obtained through a classical linear identification method, similar to a component of the Extended DMD algorithm\\cite{EDMD}, which in turn yields an approximation of the infinitesimal generator from \\ref{eq:infinitesimal_gen}.\n            \n            \\item \\textit{Identification of the vector field:} Using \\ref{eq:infinitesimal_gen}, we can recover the original system's vector field $F$.\n        \\end{itemize}\n\n        The specifics of each step will be discussed in \\cref{sec:algorithm}.\n\n\\section{Lifting Algorithm} \\label{sec:algorithm}\n\n    \\subsection{First Step: Data lifting}\n\n        At this point, a choice has to be made: so far, we have treated the library of observables as an infinite collection with all possible functions of the form $g:M \\mapsto \\mathbb{C}$; nevertheless, in practice such a collection is unfeasible, which is why we have to analyze the Koopman operator over a truncated realization of the theoretical functional space.\n\n        % Add proper references to real world applications and other benchmarks\n        The selection of the observable functions can be completely arbitrary (see \\dots) or even physically-informed (see \\dots). Nevertheless, for the sake of generality, we will present the algorithm using a sequence of monomials. These are not only congruent with the classical theory of Taylor expansion of arbitrary functions, but also facilitate scalability both in order and dimension while still providing a numerically trackable way of reaching a (theoretical) complete basis.\n\n        Let $\\mathcal{F}_N \\subset \\mathcal{F}$ be the linear subspace of observables generated by the basis $\\left\\{g_j\\right\\}_{j=1}^{N} = \\left\\{p_j\\right\\}_{j=1}^{N}$ of all polynomials of the form $p_j = x_1^{s_{j_1}} \\cdots x_n^{s_{j_n}}$ with total degree lesser or equal than $m$, so that $N = \\frac{(n+m)!}{n!m!}$.\n\n        For each snapshot pair $\\left(\\mathbf{x}_k,\\mathbf{y}_k\\right) \\in \\mathbb{R}^{n \\times 2} , k \\in \\left\\{1,\\dots,K\\right\\}$, we construct a new pair $\\left(\\mathbf{p}\\left(\\mathbf{x}_k\\right),\\mathbf{p}\\left(\\mathbf{y}_k\\right)\\right) \\in \\mathbb{R}^{N \\times 2}$, where $\\mathbf{p}\\left(\\mathbf{x}\\right) = \\left(p_1\\left(\\mathbf{x}\\right) , \\dots p_N\\left(\\mathbf{x}\\right)\\right)^T$ denotes the vector of basis monomials under the above constraints. From now on, we will also use the $\\mathbb{R}^{K \\times N}$ matrices in \\cref{eq:snap_matrix}.\n\n        \\begin{equation} \\label{eq:snap_matrix}\n            \\mathbf{P_x} =\n            \\begin{pmatrix}\n                \\mathbf{p}\\left(\\mathbf{x}_1\\right)^T \\\\\n                \\vdots \\\\\n                \\mathbf{p}\\left(\\mathbf{x}_K\\right)^T\n            \\end{pmatrix}\n            \\qquad\n            \\mathbf{P_y} =\n            \\begin{pmatrix}\n                \\mathbf{p}\\left(\\mathbf{y}_1\\right)^T \\\\\n                \\vdots \\\\\n                \\mathbf{p}\\left(\\mathbf{y}_K\\right)^T\n            \\end{pmatrix}\n        \\end{equation}\n\n    \\subsection{Second Step: Identification of the Koopman operator}\n\n        Now, we proceed with the identification of the Koopman operator $U^t , t = T_s$; specifically, we will identify the finite-rank truncation $U_N: \\mathcal{G}_N \\mapsto \\mathcal{G}_N$ of the form $U_N = P_N \\left.U^{T_s}\\right|_{\\mathcal{G}_N}$, where $P_N : L\\left(\\mathcal{G}\\right) \\mapsto L\\left(\\mathcal{G}_N\\right)$ is the projection operator onto the subspace $L\\left(\\mathcal{G}_N\\right)$ of Linear Functionals and where $\\left.U^{T_s}\\right|_{\\mathcal{G}_N} : \\mathcal{G}_N \\mapsto \\mathcal{G}$ is the restriction of the Infinite-Dimensional Koopman operator to the truncated subspace of observables $\\mathcal{G}_N$.\n        \n        Consider equation \\cref{eq:trunc_dyn}, where we exploit the linearity of the Koopman operator in the vector space to describe the dynamics of the polynomial observables through a pair of coefficient vectors $\\left(\\mathbf{a},\\mathbf{b}\\right) \\in \\mathbb{R}^{N \\times 2}$ (arbitrary as long as they comply with the aforementioned expression), we can define a matrix $\\overline{\\mathbf{U}}_N \\in \\mathbb{R}^{N \\times N}$ that satisfies \\cref{eq:UN_Matrix}.\n\n        \\begin{equation} \\label{eq:trunc_dyn}\n            g = \\mathbf{a}^T \\mathbf{p} , \\quad U_N g = \\mathbf{b}^T \\mathbf{p}\n        \\end{equation}\n\n        \\begin{equation} \\label{eq:UN_Matrix}\n            \\overline{\\mathbf{U}}_N \\mathbf{a} = \\mathbf{b}\n        \\end{equation}\n\n        The matrix $\\overline{\\mathbf{U}}_N$ is a representation of the projected Koopman operator $U_N$, providing an approximate finite-dimensional linear description of the nonlinear system in the truncated space of observables. As previously mentioned, this approximation does not depend on local linearization techniques, which makes it valid globally (granted sufficient trajectories covering all present dynamics were fed to the algorithm).\n\n        \\Cref{eq:Koopman_to_Matrix_1} follows from \\cref{eq:trunc_dyn,eq:UN_Matrix} and, since this holds for all coefficient vectors $\\mathbf{a}$, we get \\cref{eq:Koopman_to_Matrix_2}, where the operator $U_N$ acts on each component of the polynomial vector $\\mathbf{p}$. This implies that the $j$-th column of the resulting matrix is associated to the projection onto $\\mathcal{F}_N$ of the image of the basis function $p_j$ through the finite-rank Koopman operator $U_N^{T_s}$.\n\n        \\begin{equation} \\label{eq:Koopman_to_Matrix_1}\n            U_N g = U_N \\left(\\mathbf{a}^T \\mathbf{p}\\right) = \\left(\\overline{\\mathbf{U}}_N \\mathbf{a}\\right)^T \\mathbf{p} = \\mathbf{p}^T \\overline{\\mathbf{U}}_N \\mathbf{a}\n        \\end{equation}\n\n        \\begin{equation} \\label{eq:Koopman_to_Matrix_2}\n            U_N \\mathbf{p}^T = \\mathbf{p}^T \\overline{\\mathbf{U}}_N\n        \\end{equation}\n\n        We now get the least-squares fit for the orthogonal projection of an observable by solving the minimization problem in \\cref{eq:PN_Min_Prob}, which yields the expression presented in \\cref{eq:PN_Min_Sol} where $\\mathbf{P}^\\dagger$ denotes the Moore-Penrose pseudo-inverse of $\\mathbf{P}$.\n\n        \\begin{equation} \\label{eq:PN_Min_Prob}\n            P_N g = \\text{arg min}_{\\tilde{g} \\in \\text{span}\\left\\{p_1 , \\dots , p_N\\right\\}} \\sum_{k=1}^K \\left|\\tilde{g}\\left(\\mathbf{x}_k\\right) - g\\left(\\mathbf{x}_k\\right)\\right|^2\n        \\end{equation}\n\n        \\begin{equation} \\label{eq:PN_Min_Sol}\n            P_N g = \\mathbf{p}^T \\mathbf{P_x}^\\dagger\n                \\begin{pmatrix}\n                    g\\left(\\mathbf{x}_1\\right) \\\\\n                    \\vdots \\\\\n                    g\\left(\\mathbf{x}_K\\right)\n                \\end{pmatrix}\n        \\end{equation}\n\n        % Replace Goncalves cite with a more detailed demonstration of the measurement noise effect\n        The above means that we can get the least-squares coefficients associated to the projection of the $j$-th polynomial observable by setting $g=U^{T_s} p_j$ and using \\cref{eq:PN_Min_j}, under the assumption that the measurement noise $\\left|\\left|\\epsilon\\right|\\right|$ is small enough \\cite{Goncalves}.\n\n        \\begin{equation} \\label{eq:PN_Min_j}\n            P_N \\left(U^{T_s} p_j\\right) = \\mathbf{p}^T \\mathbf{P_x}^\\dagger\n                \\begin{pmatrix}\n                    U^{T_s} p_j\\left(\\mathbf{x}_1\\right) \\\\\n                    \\vdots \\\\\n                    U^{T_s} p_j\\left(\\mathbf{x}_K\\right)\n                \\end{pmatrix}\n            \\approx \\mathbf{p}^T \\mathbf{P_x}^\\dagger\n                \\begin{pmatrix}\n                    p_j\\left(\\mathbf{y}_1\\right) \\\\\n                    \\vdots \\\\\n                    p_j\\left(\\mathbf{y}_K\\right)\n                \\end{pmatrix}\n        \\end{equation}\n\n        By concatenating the above expression for all polynomial observables we get \\cref{eq:UN_Final}, which corresponds to the least-squares approximation of the matrix representation of the truncated Koopman operator indexed by the sampling time $T_s$.\n\n        \\begin{equation} \\label{eq:UN_Final}\n            \\overline{\\mathbf{U}}_N \\approx \\mathbf{P}_x^\\dagger \\mathbf{P}_y\n        \\end{equation}\n\n    \\bibliography{main.bib}\n\n\\end{document}", "meta": {"hexsha": "80377b479488d45ddde9ccdab37c3577d514b64f", "size": 18989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/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": "Thesis/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": "Thesis/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": 84.3955555556, "max_line_length": 631, "alphanum_fraction": 0.6918215809, "num_tokens": 5616, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.849971181358171, "lm_q1q2_score": 0.7744764965984221}}
{"text": "\\subsubsection{Quadratic Factors}\r\n\\noindent\r\nIf a quadratic doesn't have real roots, then we have a quadratic factor. Here, we'll assume that the quadratic factor isn't repeated. \r\nSo, $Q(x) = R(x)(ax^2+bx+c)$, $b^2-4ac < 0$, and $R(x)$ is not evenly divisible by $ax^2+bx+c$.\r\nIn this case, we say\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{R(x)(ax^2+bx+c)} = \\left(\\text{Decomposition of }R(x)\\right)+\\frac{A_1x+B_1}{ax^2+bx+c}.\r\n\\end{equation*}\r\nWe then solve for the constants in the numerator, possibly having to solve a system of equations or using previous results and less convenient values for $x$.\r\n\r\n\\begin{example}\r\n\tFind the partial fraction decomposition of the following expression:\r\n\t\\begin{equation*}\r\n\t\t\\frac{6x^2+21x+11}{x^3+5x^2+3x+15}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFactoring,\r\n\\begin{equation*}\r\n\tx^2+5x^2+3x+15 = (x+5)(x^2+3).\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{6x^2+21x+11}{x^3+5x^2+3x+15} = \\frac{A_1}{x+5}+\\frac{A_2x+B_2}{x^2+3}.\r\n\\end{equation*}\r\nMultiplying each side by the denominator,\r\n\\begin{equation*}\r\n\t6x^2+21x+11 = A_1(x^2+3)+(A_2x+B_2)(x+5).\r\n\\end{equation*}\r\nAt $x=-5$,\r\n\\begin{equation*}\r\n\t56 = 28A_1 \\implies A_1 = 2.\r\n\\end{equation*}\r\nNow we'll use the previous result and another value for $x$. We can use $x=0$ to not have to worry about the $A_2$ term.\r\nAt $x=0$,\r\n\\begin{equation*}\r\n\t11 = 2(3) + (B_2)(5) \\implies B_2 = 1.\r\n\\end{equation*}\r\nNow we'll use the previous 2 results to find $A_2$. $x=1$ is a good choice to keep the numbers small.\r\nAt $x=1$,\r\n\\begin{equation*}\r\n\t38 = 2(1+3)+(A_2+1)(6) \\implies A_2 = 4.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{6x^2+21x+11}{x^3+5x^2+3x+15} = \\frac{2}{x+5}+\\frac{4x+1}{x^2+3}.\r\n\\end{equation*}\r\n", "meta": {"hexsha": "48c9f4d19f86862148694ae171650da8274f1146", "size": 1713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/quadraticFactors.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/quadraticFactors.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/quadraticFactors.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.6875, "max_line_length": 159, "alphanum_fraction": 0.6544074723, "num_tokens": 707, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8791467675095292, "lm_q1q2_score": 0.7743499094378871}}
{"text": "\\lab{Algorithms}{Canonical Transformations and the QR Decomposition}{Canonical Transformations and the QR Decomposition}\n\\label{Ch:Canonical Transformations}\n\n\\objective{Use orthogonal transformations to perform QR decomposition.}\n\n\\section*{Orthogonal transformations}\nRecall that a matrix $Q$ is \\emph{unitary} if $Q^* Q = I$ or for real matrices, $Q^T Q = I$ (since the conjugate of a real number is itself). We like unitary transformations because they're very 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 Lab \\ref{Ch:Norms and Geometry}; for now, all you need to know is that if $\\kappa(A)$ is small, then problems involving $A$ are less susceptible to numerical errors. For induced matrix norms (which include most of the matrix norms we would ever care about),  it holds that $\\norm{Q}=1$ when $Q$ is unitary. The inequality $\\norm{AB} \\leq \\norm{A} \\norm{B}$ also holds for these norms. It follows that $\\kappa(A) = \\norm{A} \\norm{A^{-1}} \\geq \\norm{A A^{-1}} = \\norm{I} = 1$. Note that if $Q$ is unitary, $Q^{-1} = Q^*$ and $Q^*$ is also unitary, so $\\kappa(Q) = \\norm{Q} \\norm{Q^*} = 1$. This means that orthogonal matrices have the smallest possible condition number, which is great!\n\nAny unitary matrix $Q$ can be described as a reflection, a rotation, or some combination of the two. If $det(Q) = 1$, then $Q$ is a rotation; if $det(Q) = -1$, then $Q$  is the 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. See figure \\ref{fig:Householder reflector}. Recall that a hyperplane can be defined by a unit vector $v$ which is orthogonal to the hyperplane. As shown in the figure, $x - \\langle v,x \\rangle v$ is the projection of $x$ onto the hyperplane defined by $v$. (You should verify this geometrically.) However, to reflect \\emph{across} the hyperplane, we must move twice as far; that is, $Px = x - 2\\langle v,x \\rangle v$. This can be written $Px = x - 2v(v^\\ast x)$, so $P$ has matrix representation $P = I - 2vv^\\ast$. Note that $P^\\ast P = I$; thus $P$ is orthogonal.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width= \\textwidth]{fig1}\n\t\\caption{Householder reflector}\n\t\\label{fig:Householder reflector}\n\\end{figure}\n\n\\subsection*{Householder triangularization}\nConsider the problem of computing the $QR$ decomposition of a matrix $A$. You've already learned the Gram-Schmidt and the Modified Gram-Schmidt algorithms for this problem. The $QR$ decomposition can also be computed using Householder triangularization. Gram-Schmidt and Modified Gram-Schmidt \\emph{orthogonalize} $A$ by a series of \\emph{triangular} transformations. Conversely, the Householder method \\emph{triangularizes} $A$ by a series of \\emph{orthogonal} transformations.\n\nLet's demonstrate this method on a $4 \\times 3$ matrix $A$. First we find a orthogonal transformation $Q_1$ that maps the first column of A into the range of $e_1$.\n\n\\def\\mc#1{\\multicolumn{1}{c|}{#1}}\n\\begin{equation*}\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \n\\end{pmatrix}\n\\underrightarrow{Q_1}\n\\begin{pmatrix}\n\n\\ast & \\ast & \\ast & \\\\ \\cline{2-3}\n\\mc{0} & \\ast & \\mc{\\ast}& \\\\\n\\mc{0} & \\ast & \\mc{\\ast} & \\\\\n\\mc{0}& \\ast & \\mc{\\ast} & \\\\ \\cline{2-3}\n\\end{pmatrix}\n\\end{equation*}\nLet $A_2$ be the boxed submatrix of $A$. Now find an orthogonal transformation $Q_2$ that maps the first column of $A_2$ into the range of $e_2$. \n\n\\begin{equation*}\n\\begin{pmatrix}\n\\ast & \\ast \\\\\n\\ast & \\ast \\\\\n\\ast & \\ast \n\\end{pmatrix}\n\\underrightarrow{Q_2}\n\\begin{pmatrix}\n\\ast & \\ast \\\\\n0 & \\ast \\\\\n0 & \\ast \n\\end{pmatrix}\n\\end{equation*}\nSimilarly, $ \\begin{pmatrix} \\ast \\\\ \\ast \\end{pmatrix} \\underrightarrow{Q_3} \\begin{pmatrix} \\ast \\\\ 0 \\end{pmatrix} $. (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$. $Q_2$ leaves the first row alone, and $Q_3$ leaves the first two rows alone.) Then $Q_3 Q_2 Q_1 A =$ \n\n\\begin{equation*}\nQ_3 Q_2 Q_1\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\end{pmatrix}\n= Q_3 Q_2\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n\\end{pmatrix}\n= Q_3\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & 0 & \\ast \\\\\n0 & 0 & \\ast \\\\\n\\end{pmatrix}\n= \n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & 0 & \\ast \\\\\n0 & 0 & 0 \\\\\n\\end{pmatrix}\n\\end{equation*}\n\nWe've accomplished our goal, which was to triangularize $A$ using orthogonal transformations. But now, how do we find the $Q_i$ that do what we want? Using Householder reflections. (Surprise!)\n\nFor example, to find $Q_1$, we choose the right hyperplane to reflect $x$ into the range of $e_1$. It turns out there are two hyperplanes that will work, as shown in figure \\ref{fig:two reflectors}. (In the complex case, there are infinitely many such hyperplanes.) Between the two, the one that reflects $x$ further will be more numerically stable. This is the hyperplane perpendicular to \\textbf{$v = sign(x_1)\\norm{x}e_1 + x$}. The whole process is summarized in Algorithm \\ref{Alg:Householder triangularization}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width= \\textwidth]{fig2}\n\t\\caption{two reflectors}\n\t\\label{fig:two reflectors}\n\\end{figure}\n\n\\begin{pseudo}{Householder triangularization}{A}\n\\label{Alg:Householder triangularization}\nm,n \\GETS size(A)\\\\\n\\FOR k \\GETS 1 \\TO n-1 \\DO\n\\BEGIN\n   x = A_{k:m,k}\\\\\n   v_k = sign(x_1)\\norm{x}_2 e_1 + x\\\\\n   v_k = v_k / \\norm{v_k}_2\\\\\n   P_k = eye(m,m)\\\\\n   P_k[k:m,k:m] = P_k[k:m,k:m] - 2 v v^T\\\\\n   A = sp.dot(P_k,A);\n\\END\n\\end{pseudo}\n\nThis algorithm returns upper triangular $R$. You can find $Q$ s.t. $QR = A$ by multiplying the $P_k$ together appropriately.\n\n\\begin{problem}\n\\label{prob:HouseholderQR}\nWrite a script using Householder reflections to find the QR decomposition of a matrix A.\n\\end{problem}\n\n\\subsection*{Stability of the Householder QR algorithm}\n\nTry the following in Python.\n\n\\begin{lstlisting}\nIn [1]:  import scipy as sp\nIn [2]:  import numpy.linalg as la\nIn [3]:  import my_householder\nIn [4]:  Q,X = la.qr(sp.rand(50,50)) #create a random orthogonal matrix:\nIn [5]:  R = sp.triu(sp.rand(50,50)) # create a random upper triangular matrix\nIn [6]:   A = sp.dot(Q,R) #Q and R are the exact QR decomposition of A\n# use your Householder QR script to estimate Q and R:\nIn [7]:   Q1,R1 = my_householder.qr(A)\n#now check the relative errors of Q1 and R1\nIn [8]:  la.norm(Q1-Q)/la.norm(Q)\nOut [8]:  0.282842955725\nIn [9]:  la.norm(R1-R)/la.norm(R)\nOut[9]:  0.0428922016647\n\\end{lstlisting}\nThis is terrible! Python works in $16$ decimal points of precision. But $Q_1$ and $R_1$ are only accurate to $0$ and $1$ decimal points, respectively. We've lost $16$ decimal points of precision!\n\nDon't lose hope. Check how close the product $Q_1 R_1$ is to $A$.\n\\begin{lstlisting}\nIn [10]:  A1 = sp.dot(Q1,R1)\nIn [11]:  la.norm(A1-A)/la.norm(A)\nOut[11]:  9.73996046986e-16\n\\end{lstlisting}\nWe've now recovered $15$ digits of accuracy. The errors in $Q_1$ and $R_1$ were somehow ``correlated,\" so that they canceled out in the product. The errors in $Q_1$ and $R_1$ are called \\emph{forward errors}. The error in $A_1$ is the \\emph{backward error}. The Householder $QR$ algorithm is a backward stable algorithm.\n\nHouseholder QR factorization is more numerically stable than Gram-Schmidt or even Modified Gram-Schmidt (MGS). However, MGS is still useful for some types of iterative methods, because it finds the orthogonal basis one vector at a time instead of all at once (for example see Lab \\ref{Ch:EigSolve}).\n\n\\subsection*{Upper Hessenberg Form}\n\n%I'm not sure about this math. Is this true in the real case?\nAn upper Hessenberg matrix is a square matrix with zeros below the first subdiagonal. Every  $n \\times n$ matrix $A$ can be written $A = Q^THQ$ where $Q$ is orthogonal and $H$ is an upper Hessenberg matrix, called the Hessenberg form of $A$. Note the similarity of this decomposition to the Schur decomposition in Lab \\ref{Ch:Jordan}. \n\nThe Hessenberg decomposition can be computed using Householder reflections, in a process very similar to Householder triangularization. Let's demonstrate this process on a $5 \\times 5$ matrix $A$. Note that $A=Q^THQ$ is equivalent to $QAQ^T = H$; thus our strategy is to multiply $A$ on the right and left by a series of orthogonal matrices until it is in Hessenberg form. If we try 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$. However, since we now have to multiply $Q_1 A$ on the left by $Q_1^T$, all those zeros are destroyed, as demonstrated below. (Although this process may seem futile now, it actually does tend to decrease the size of the subdiagonal entries. If we repeat it over and over again, the subdiagonal entries will often converge to zero. That's the idea behind the $QR$ algorithm in Lab \\ref{Ch: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 range 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\n\\begin{problem}\nWrite a script that transfers an input matrix to upper Hessenberg form. (Hint: You only need to modify your code code from problem \\ref{prob:HouseholderQR} slightly.) We will use this technique in the eigenvalue lab later.\n\\end{problem}\n\n\\section*{Givens rotations}\n\nThe matrix $\\begin{pmatrix} cos(\\theta) & -sin(\\theta) \\\\ sin(\\theta) & cos(\\theta) \\end{pmatrix}$ rotates a vector counterclockwise by $\\theta$. Given a vector $x = \\begin{pmatrix} a \\\\ b \\end{pmatrix}$, we can rotate $x$ into the range of $e_1$ by choosing the correct $\\theta$. The problem is equivalent to solving for $c = cos(\\theta)$ and $s = sin(\\theta)$ in the system\n\\begin{equation}\n\\label{eq:Givens rotation system}\n\\begin{pmatrix} c & -s \\\\ s & c \\end{pmatrix} \\begin{pmatrix}a\\\\b\\end{pmatrix} \n= \\begin{pmatrix}r\\\\0\\end{pmatrix}\n\\end{equation}\n In fact, it's not necessary to compute $\\theta$; we solve for $c$ and $s$ directly. An obvious solution is $c = \\frac{a}{\\sqrt{a^2 + b^2}}$ and $s = \\frac{b}{\\sqrt{a^2+b^2}}$.\n\n\\subsection*{Givens triangularization}\n\nLike Householder, the Givens $QR$ algorithm, \\emph{triangularizes} a matrix $A$ using \\emph{orthogonal transformations}. The Householder $QR$ algorithm worked one column at a time; Givens works one element at a time. Each nonzero below the main diagonal can be zeroed out with a Givens rotation. If we solve for $c$ and $s$ as above, the matrix\n\\begin{equation*}\nG(i,j,c,s) = \n\\begin{pmatrix}\n1   & \\cdots & 0 & \\cdots & 0 & \\cdots & 0 \\\\\n \\vdots & \\ddots & \\vdots &  & \\vdots & & \\vdots \\\\\n0   & \\cdots &    c   & \\cdots &    -s   & \\cdots &    0   \\\\\n \\vdots &        & \\vdots & \\ddots & \\vdots &        & \\vdots \\\\\n 0   & \\cdots &   s   & \\cdots &    c   & \\cdots &    0   \\\\\n\\vdots &        & \\vdots &        & \\vdots & \\ddots & \\vdots \\\\\n0   & \\cdots &    0   & \\cdots &    0   & \\cdots &    1 \n\\end{pmatrix}\n\\end{equation*}\nwhere\n\\[ \\begin{array}{ll}\ng_{i\\, i} = c  & g_{j\\, i}= -s   \\\\\ng_{j\\, j} = c &  g_{i\\, j}= s  \\\\\n\\end{array}\\]\nrotates by $\\theta$ in the $i,j$ plane. Also, it's easy to check that $G(i,j,c,s)$ is orthogonal. Left-multiplying $A$ by $G(i,j,c,s)$ zeroes out $A_{i\\, j}$. For example, \n\n\\[\n\\begin{array}{ccccccc}\n\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n*&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n*&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(2,1)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(3,2)}\n&\\begin{pmatrix}\n*&*&*\\\\\n0&*&*\\\\\n0&0&*\n\\end{pmatrix}\n\\end{array}\n\\]\n\nThe Givens QR method is often slower than Householder, because it works one element at a time. But it is faster than Householder when $A$ is sparse, and it is very parallelizable.\n\n\\begin{problem}\nWrite a script that uses Givens rotations to do $QR$ decomposition. By performing successive Givens rotations, triangularize $A$ to find $R$. You can find $Q$ using the chain of rotations.\n\nTo find each rotation, you will have to solve \\eqref{eq:Givens rotation system} for $c$ and $s$. Let $b$ be the element you want to zero out, say $A_{i\\,j}$. Then $a$ is in the same \\emph{column} as $b$, and in the \\emph{row} you want to rotate into (it's like we're squishing the whole vector into $a$'s spot.) You can choose $a$ to be the diagonal element above $b$.\n\\end{problem}\n\n\\begin{problem} \nCompare the MGS, Householder, and Givens algorithms for $QR$ decomposition on various matrices. Try different sizes and different levels of sparsity. Which is the fastest? Which is the most stable?\n\\end{problem}\n\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", "meta": {"hexsha": "509799b03b02cda1beb629565cc6538674d5fa75", "size": 15014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/CanonTransform/CanonTransform.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/CanonTransform/CanonTransform.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/CanonTransform/CanonTransform.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": 46.91875, "max_line_length": 1032, "alphanum_fraction": 0.6681097642, "num_tokens": 5017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467611766711, "lm_q2_score": 0.8807970858005139, "lm_q1q2_score": 0.7743499052353723}}
{"text": "\\section{Simplifying expression for \\texorpdfstring{$w_p(\\phi)$}{}}\n\nThe sine function is a phase shift of the cosine function, so \n\\begin{equation}\n    \\sin(2k)=\\sin(2\\phi+\\pi/2)=\\cos(2\\phi).\n\\end{equation}\nIt is also given that\n\\begin{equation}\n    2\\sin^2(2k)=1-\\cos(2k).\n\\end{equation}\nBecause $\\cos(2k)=-\\sin(2\\phi)$ by a similar argument, \n\\begin{equation}\n    2\\sin^2(2k)=1+\\sin(2\\phi).\n\\end{equation}\nFinally\n\\begin{align}\n    w_p(\\phi)&=\\frac{1}{\\underbrace{\\sin(2\\phi+\\pi/2)}_{\\cos(2\\phi)}}[1\\underbrace{-\\frac{a_Tr_0^2}{\\mu}}_{-\\frac{4}{\\beta^2(3\\pi+8)}}(3\\phi+2)]+\\frac{2}{\\beta^2(3\\pi+8)}\\underbrace{(2\\sin^2(\\phi+\\pi/4)+3)}_{\\sin(2\\phi)+4}\\\\\n    &=\\frac{1}{\\cos(2\\phi)}\\left[1-\\frac{4}{\\beta^2(3\\pi+8)}(3\\phi+2)\\right]+\\frac{2}{\\beta^2(3\\pi+8)}(\\sin(2\\phi)+4)\n\\end{align}\n\n\\section{Numerical evaluation of \\texorpdfstring{$y(\\phi_0)=0$}{}}\n\n\\textbf{\\textit{Notation:} Let $\\phi_0$ satisfy $y(\\phi_0)=0,w_p(\\phi_0)=1$ and $\\phi_\\mathrm{min}$ minimize $w_p(\\phi)$.}\n\nTo evaluate $y_p(\\phi)=0$, we first define \\verb|phi = (1:1:1000)*pi/4/1000|. \nUsing this vector to formulate \\verb|y_p(Beta)|, where \\verb|Beta| is a variable constant, we have a vector of length 1000 representing $y_p(\\phi)$.\nNote that\n\n\\begin{equation}\n    y_p(\\phi)=\\frac{\\sqrt{\\varphi(\\phi)}}{\\beta^2(3\\pi+8)\\sin(2\\phi+pi/2)}\\sqrt{\\frac{\\mu}{r_0}}\\cot(\\phi+\\pi/4)\n\\end{equation}\n\n$\\varphi(\\phi)$ was defined in Eq. 18-20 of the presentation, and the above expression comes from Eq. 21 of the presentation. This implies that $\\sin(2\\phi+\\pi/2)\\neq 0$, and further that $y_p$ is only defined for $\\varphi(\\phi)\\geq 0$. Thus, the vector \\verb|y_p(Beta)| must be shortened to reflect this and exclude complex numbers.\nFrom calculations, we find that the real representation of $y_p$ is \\verb|y_p(Beta)(1:548)| using $a_T=0.2,r_0=1,\\mu=1$ with $\\beta\\approx 1.07$.\nTo find the section of this vector that is $\\in \\mathbb{R}$, we have called a function \\verb|realBreakpoint(vector)| in Figure \\ref{loop1}.\nSorting this vector and determining the corresponding $\\phi_0$ solves the problem, where we expect \\verb|y_minValue = 0| and \\verb|phi_0| to be the corresponding value of $\\phi$:\n\n\\begin{verbatim}\n    [y_values index_vector] = sort(y_p(Beta)(1:548));\n    y_minValue = y_values(1);\n    phi_0 = index_vector(1);\n\\end{verbatim}\n\nThis approach can be extended for a changing parameter $\\beta$. \nSince $\\delta=\\frac{1}{\\beta^2}\\in (0.001,1)$, $\\beta=\\sqrt{\\frac{1}{\\delta}}\\in (1,\\sqrt{1000})$.\nIn Octave/MATLAB, we can implement it as\n\n\\begin{verbatim}\n    delta = (1:1:1000)/1000;\n    Beta_vec = sqrt(1./delta);\n\\end{verbatim}\n\nMathematically, we say that \n\\begin{equation}\n\\vec\\beta=\\begin{bmatrix}\\beta_1\\\\\\vdots\\\\\\beta_n\\end{bmatrix}\\text{ and }\\vec{\\delta}=\\begin{bmatrix}1/\\beta_1^2\\\\\\vdots\\\\1/\\beta_n^2\\end{bmatrix}\n\\label{paravectors}\n\\end{equation}\nwhere we choose $n=1000$.\nThus, by iterating through the values of \\verb|Beta_vec|, we can generate a corresponding vector \\verb|phi_m1| to represent how $\\phi_0$ changes with respect to $\\delta$:\n\n\\begin{figure}[H]\n    \\begin{verbatim}\n        phi_m1 = zeros(1,n);\n        w_1 = zeros(1,n);\n        w_min = zeros(1,n);\n        y_0 = zeros(1,n);\n    \n        for i = 1:n\n            y_real = y_p(Beta_vec(i))(1:realBreakpoint(y_p(Beta_vec(i))));\n            [yvals idx] = sort(y_real);\n            if (length(idx) > 1)\n                w_1(i) = w_p(Beta_vec(i))(idx(2));\n                phi_m1(i) = phi(idx(2));\n                y_0(i) = yvals(2);\n            endif\n        end\n    \\end{verbatim}\n    \\caption{Numerically finding $\\vec\\phi_0$ over $\\vec{\\delta}$}\\label{loop1}\n\\end{figure}\n\nIn Figure \\ref{loop1} above, the vector \\verb|y_0| is updated with the value $y_p(\\phi_{0,i})$ in each iteration\nfor each value of $\\beta$, and is expected to be 0. The vector \\verb|w_1| is updated with $w_p(\\phi_{m,i})$, which is expected to be unity. As was done with \\verb|y_p(Beta)|, \nwe have defined a vector \\verb|w_p(Beta)| to represent $w_p(\\phi)$ where \\verb|Beta| is a constant that can be varied.\nThus, we should expect $w_p(\\vec\\phi_\\mathrm{min})=\\vec{1}$, $y_p(\\vec\\phi_0)=\\vec{0}\\in \\mathbb{R}^n$, and the existence of $\\vec\\phi_m=\\begin{bmatrix}\\phi_{m,1}\\\\\\vdots\\\\\\phi_{m,n}\\end{bmatrix}\\in \\mathbb{R}^n$ at the end of the loop.\nThe second index of \\verb|y_p(Beta_vec(i))| is accessed to find $\\phi_{0,i}$ within the loop because $\\phi=0$ always satisfies $y_p(\\phi)=0$, and we want to find the second such value.\nThe conditional check is to account for cases where the domain of $y_p(\\phi)\\in \\mathbb{R}$ is very small (i.e. \\verb|length(y_p(Beta_vec(i))| is 1), so we are only able to find $\\phi_{0,i}=0\\implies y(\\phi_0)=0$.\n\nThe results of $\\phi_0$ vs. $\\delta$ are expressed in Figure \\ref{yminplot} below. $y_p(\\phi_0)\\approx 0$ and $w_p(\\phi_\\mathrm{min})\\approx 1$ within numerical error, which verifies the validity of these results.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics{plots/phi_delta_y.pdf}\n    \\caption{A plot of these results}\\label{yminplot}\n\\end{figure}\n\n\\section{Numerical minimization of \\texorpdfstring{$w_p(\\phi)$}{}}\n\nWe use a similar approach as before to minimize $w_p(\\phi)$ numerically. \nIn Figure \\ref{loop1}, \\verb|w_1(i)| was updated\nto reflect the value of $w_p(\\phi_{\\mathrm{min},i})$ where $\\phi=\\phi_{\\mathrm{min},i}$ minimized $y_p(\\phi)$ for corresponding values of $\\beta_i,\\delta_i$\nfrom Eq. \\ref{paravectors}. The following code defines a vector \\verb|phi_m2| of length $n=1000$ and populates it with the value of $\\phi_{\\mathrm{min},i}$ that minimizes $w_p(\\phi)$ for $\\beta_i$.\nThe corresponding minimum values are stored in another vector \\verb|w_min|. Note that the first index of the sorted vector \\verb|w_vals| is accessed, since we are looking for the absolute minimum.\n\n\\begin{figure}[H]\n    \\begin{verbatim}\n        phi_m2 = zeros(1,n);\n        w_min = zeros(1,n);\n        for i = 1:n\n            [w_vals idx] = sort(w_p(Beta_vec(i)));\n            phi_m2(i) = phi(idx(1));\n            w_min(i) = w_vals(1);\n        end\n    \\end{verbatim}\n    \\caption{Iteratively finding $\\vec\\phi_\\mathrm{min}$ for various $\\beta$}\n\\end{figure}\n\n\\begin{figure}[H]\n    \\includegraphics{plots/phi_delta_min.pdf}\n    \\caption{Values of $\\phi_\\mathrm{min}$ that minimize $w_p(\\phi)$ for various $\\beta$}\\label{wminplot}\n\\end{figure}\n\nFigure \\ref{wminplot}, showing $\\phi_\\mathrm{min}$ (representing \\verb|phi_m2|) vs. $\\delta$, summarizes these results.", "meta": {"hexsha": "ecd8ac9fbfd7795008c231847a9876791478e008", "size": 6440, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/followup.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/followup.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/followup.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": 52.7868852459, "max_line_length": 333, "alphanum_fraction": 0.6683229814, "num_tokens": 2204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.880797076413356, "lm_q1q2_score": 0.7743498941937013}}
{"text": "\\section*{Matrix Reconstruction}\n\\subsection*{Alternating Least Squares}\nBeyond SVD: unobserved entries!\n$f(\\mathbf{U},v_i)=\\sum_{(i,j)\\in I} (a_{i,j} - \\langle \\mathbf{u}_j, \\mathbf{v}_i \\rangle)^2$,\nFix one, alternate other: \\\\\n$\\mathbf{U} \\gets \\argmin_\\mathbf{U} f(\\mathbf{U},\\mathbf{V})$, $\\mathbf{V} \\gets \\argmin_\\mathbf{V} f(\\mathbf{U},\\mathbf{V})$ \\\\\nCan decompose (solve independently) \\\\\n$f(\\mathbf{U},v_i)=\\sum_i \\left[ \\sum_{(i,j)\\in I} (a_{i,j} - \\langle \\mathbf{u}_j, \\mathbf{v}_i \\rangle)^2 \\right]$ \\\\\nCan add regularization $\\mu (||U||_F^2 + ||V||_F^2 )\\quad \\mu >0$ \\\\\nUpd: $u_i = \\left( \\sum_{(i,j)\\in \\mathcal{I}} v_jv_j^\\top + I_k\\lambda\\right)^{-1} \\left(\\sum_{(i,j)\\in \\mathcal{I}} a_{ij}v_j \\right)$\n\n\\subsection*{SVD Thresholding}\n$\\mathbf{B}^{*}=\\mathit{shrink}_\\tau(\\mathbf{A}):=\\argmin_{\\mathbf{B}}{\\{\\|\\mathbf{A-B}\\|^2_F + \\tau\\|\\mathbf{B}\\|_{*}\\}}$\\\\\nthen with SVD holds $\\mathbf{B^*=UD_\\tau V^T, D_\\tau} =$ \\\\\n$\\mathit{diag}(\\max\\{0,\\sigma_i - \\tau\\}),\\Pi(\\mathbf{X}) = x_{ij} \\text{ if } (i,j) \\in \\mathcal{I} \\text{ el. } 0$ \\\\\nIteration: $\\mathbf{B}_{t+1}=\\mathbf{B}_t + \\eta_t \\Pi(\\mathbf{A} - \\mathit{shrink}_\\tau(\\mathbf{B}_t))$\n", "meta": {"hexsha": "6dea08561d0a885c7a8f311ec7d12c4a33f086a6", "size": 1167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Reconstruction.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": "Reconstruction.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": "Reconstruction.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": 68.6470588235, "max_line_length": 136, "alphanum_fraction": 0.6126820908, "num_tokens": 516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741241296944, "lm_q2_score": 0.8128673133042217, "lm_q1q2_score": 0.7743163690044269}}
{"text": "\\section{More on Bilinear Forms}\r\nGuess what?\r\nWe are back to bilinear forms again!\r\nBut this time, we are interested in bilinear forms $\\phi:V\\times V\\to F$ for a finite dimensional vector space $V$ over $F$.\r\nFor a basis $B$ of $V$, we write $[\\phi]_B=[\\phi]_{B,B}$.\r\n\\begin{lemma}\r\n    Let $B,B'$ be bases of $V$ and $P=[\\operatorname{id}]_{B',B}$, then $[\\phi]_{B'}=P^\\top[\\phi]_BP$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Proposition \\ref{bilinear_change_of_basis}.\r\n\\end{proof}\r\n\\begin{definition}\r\n    Matrices $A,B\\in M_n(F)$ are congruent if there is invertible $P$ such that $A=P^\\top BP$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    Easily congruence is an equivalence relation.\r\n\\end{remark}\r\n\\begin{definition}\r\n    A bilineart form $\\phi$ in $V$ is symmetric if $\\phi(u,v)=\\phi(v,u)$ for any $u,v\\in V$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    $\\phi$ is symmetric iff $[\\phi]_B$ is symmetric in some basis $B$.\\\\\r\n    If we want to diagonalise $\\phi$, then it has to be symmetric by the preceding lemma.\r\n\\end{remark}\r\n\\begin{definition}\r\n    A map $Q:V\\to F$ is a quadratic form iff there exists a bilinear form $\\phi:V\\times V\\to F$ such that $Q(u)=\\phi(u,u)$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    If $B=\\{e_i\\}$ and $A=[\\phi]_B=(\\phi(e_i,e_j))_{i,j}$, then for $u=\\sum_ix_ie_i$ we have\r\n    $$Q(u)=\\phi\\left( \\sum_{i=1}^nx_ie_i,\\sum_{i=1}^nx_ie_i \\right)=\\sum_{i=1}^n\\sum_{j=1}^nx_ix_j\\phi(e_i,e_j)=x^\\top Ax$$\r\n    where $x=(x_1,\\ldots,x_n)^\\top$.\r\n    Also observe that $x^\\top Ax=x^\\top Sx$ where $S=(A+A^\\top)/2$ is symmetric.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    If $Q:V\\times V\\to F$ is a quadratic form, then there exists a unique symmetric bilinear form $\\phi:V\\times V\\to F$ such that $Q(u)=\\phi(u,u)$ for all $u\\in V$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We know that $Q(u)=\\psi(u,u)$ for some bilinear $\\psi$.\r\n    Take $\\phi=(\\psi+\\psi^\\top)/2$ where $\\psi^\\top(u,v)=\\psi(v,u)$ works.\r\n    To see it is unique, just observe that for a symmetric $\\phi$,\r\n    $$Q(u+v)=\\phi(u+v,u+v)=\\phi(u,u)+2\\phi(u,v)+\\phi(v,v)$$\r\n    which implies that necessarily $\\phi(u,v)=(Q(u+v)-Q(u)-Q(v))/2$ (known as the polarisation identity), so in particular $\\phi$ is uniquely determined.\r\n\\end{proof}\r\n\\begin{theorem}[Diagonalisation of Bilinear Forms]\\label{bilinear_diag}\r\n    Let $\\phi:V\\times V\\to F$ be a symmetric bilinear form and $\\dim V<\\infty$, then there exists a basis of $V$ such that $[\\phi]_B$ is diagonal.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We proceed by induction on $n=\\dim V$.\r\n    If $\\phi(u,u)=0$ for any $u\\in V$, then $\\phi$ is identically zero by the polarisation identity.\r\n    Otherwise, we can always find $u\\in V\\setminus\\{0\\}$ such that $\\phi(u,u)\\neq 0$.\r\n    Write $u=e_1$ and define\r\n    $$U=\\langle \\{e_i\\}\\rangle^\\perp=\\{v\\in V:\\phi(e_1,v)=0\\}=\\ker \\phi(e_1,\\cdot)$$\r\n    So $\\dim U=n-1$ and $U+e_1=U\\oplus e_1$.\r\n    Pick a basis $\\{e_2,\\ldots,e_n\\}$ of $U$ such that $\\phi|_U$ is diagonal in this basis, which is possible by induction hypothesis.\r\n    Then $\\phi$ is diagonal in $\\{e_1,\\ldots,e_n\\}$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $V=\\mathbb R^3$ and $Q(x)=x_1^2+x_2^2+2x_3^3+2x_1x_2+2x_1x_3-2x_2x_3$.\r\n    By inspection if we take\r\n    $$A=\\begin{pmatrix}\r\n        1&1&1\\\\\r\n        1&1&-1\\\\\r\n        1&-1&2\r\n    \\end{pmatrix}$$\r\n    then $Q(x)=x^\\top Ax$.\r\n    Of course, we can follow the algorithm illustrated in the proof.\r\n    We can alternatively complete the square to get\r\n    \\begin{align*}\r\n        Q(x)&=x_1^2+x_2^2+2x_3^3+2x_1x_2+2x_1x_3-2x_2x_3\\\\\r\n        &=(x_1+x_2+x_3)^2+(x_3-2x_2)^2-(2x)^2\r\n    \\end{align*}\r\n    then under the new basis $x_1+x_2+x_3,x_3-2x_2,2x_2$, $A$ has the matrix\r\n    $$A'=\\begin{pmatrix}\r\n        1&0&0\\\\\r\n        0&1&0\\\\\r\n        0&0&-1\r\n    \\end{pmatrix}$$\r\n    More concretely, we have $A'=P^\\top AP$ where\r\n    $$P=\\begin{pmatrix}\r\n        1&1&1\\\\\r\n        0&-2&1\\\\\r\n        0&-2&0\r\n    \\end{pmatrix}^{-1}$$\r\n\\end{example}", "meta": {"hexsha": "ada91722c3f54155139abd561f4fbda3c36aeb30", "size": 3919, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "18/bi.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": "18/bi.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": "18/bi.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": 46.6547619048, "max_line_length": 165, "alphanum_fraction": 0.6164837969, "num_tokens": 1472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767842777551, "lm_q2_score": 0.8824278757303677, "lm_q1q2_score": 0.7743099747529336}}
{"text": "\\subsection{Volume Between Surfaces}\r\n\\noindent\r\nSimilar to how we could find the area between two curves in single-variable calculus, we can find the volume between two surfaces.\r\n\\begin{equation*}\r\n\tV_{\\text{bwtn}} = \\iint\\limits_{D}{f\\mathrm{d}A} - \\iint\\limits_{D}{g\\mathrm{d}A} = \\iint\\limits_{D}{(f-g)\\mathrm{d}A}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nIf $g$ is below $f$ in $D_1 \\subset D$ but is above $f$ in $D_2 \\subset D$, where $D_1 \\cup D_2 = D \\text{ and } D_1 \\cap D_2 = \\emptyset$, we can still find the volume between the surfaces by splitting $D$ into $D_1$ and $D_2$.\r\n\\begin{equation*}\r\n\tV_{\\text{bwtn}} = \\iint\\limits_{D}{\\abs{f-g}\\mathrm{d}A} = \\iint\\limits_{D_1}{(f-g)\\mathrm{d}A} + \\iint\\limits_{D_2}{(g-f)\\mathrm{d}A}\r\n\\end{equation*}", "meta": {"hexsha": "02fd92c4dde5b0fc1bcbd534a386f95184d5c25c", "size": 752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/volumeBetweenSurfaces.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/multipleIntegrals/volumeBetweenSurfaces.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/multipleIntegrals/volumeBetweenSurfaces.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.6666666667, "max_line_length": 229, "alphanum_fraction": 0.6768617021, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8824278741843884, "lm_q1q2_score": 0.774309970568998}}
{"text": "\\lab{Inverse Problems}{Inverse Problems}\n\\label{lab:inverse_problems}\n\nAn important concept in mathematics is the idea of a well posed problem.\nThe concept initially came from Jacques Hadamard.\nA mathematical problem is \\textit{well posed} if \n\\begin{enumerate}\n\t\\item a solution exists, \n\t\\item that solution is unique, and \n\t\\item the solution is continuously dependent on the data in the problem.\n\\label{inverse_problems:continuous_dependence}\n\\end{enumerate}\nA problem that is not well posed is \\textit{ill posed}.\nNotice that a problem may be well posed, and yet still possess the property that small changes in the data result in larger changes in the solution; in this case the problem is said to be \\text{ill conditioned}, and has a large \\text{condition number}.\n\nNote that for a physical phenomena, a well posed mathematical model would seem to be a necessary requirement!\nHowever, there are important examples of mathematical problems that are ill posed.\nFor example, consider the process of differentiation.\nGiven a function $u$ together with its derivative $u'$, let $\\tilde{u}(t) = u(t) +  \\epsilon \\sin(\\epsilon^{-2}t)$ for some small $\\epsilon > 0$.\nThen note that \n\\begin{align*}\n\t\\|u-\\tilde{u}\\|_{\\infty} &= \\epsilon,\n\\end{align*}\nwhile\n\\begin{align*}\n\t\\|u'-\\tilde{u}'\\|_{\\infty} &= \\epsilon^{-1}.\n\\end{align*}\nSince a small change in the data leads to an arbitrarily large change in the output, differentiation is an ill posed problem.\nAnd we haven't even mentioned numerically approximating a derivative!\n\nFor an example of an ill posed problem from PDEs, consider the backwards heat equation with zero Dirichlet conditions: \n\\begin{align}\n\\begin{split}\n\t&{} u_t = -u_{xx}, \\quad (x,t) \\in (0,L)\\times (0,\\infty),\\\\\n\t&{} u(0,t) = u(L,t) = 0, \\quad t \\in (0,\\infty),\\\\\n\t&{} u(x,0) = f(x), \\quad x \\in (0,L).\n\\end{split}\n\\end{align}\nFor the initial data $f(x)$ the unique\\footnote{See \\textit{Partial Differential Equations} by Lawrence C. Evans, chapter 2.3, for a proof of uniqueness.} solution is $u(x,t) = 0.$ \nGiven the initial data $f(x) = \\frac{1}{n}\\sin ( \\frac{n \\pi x}{L})$, one can check that there is a unique solution $u(x,t) = \\frac{1}{n}\\sin ( \\frac{n \\pi x}{L})\\exp ( (\\frac{n \\pi }{L})^2 t)$. \nThus, on a finite interval $[0,T]$, as $n \\to \\infty$ we see that a small difference in the initial data results in an arbitrarily large difference in the solution.\n\n\\section*{Inverse Problems}\nAs implied by the name, inverse problems come in pairs.\nFor example, differentiation and integration are inverse problems.\nThe easier problem (in this case integration) is often called the direct problem.\nThe direct problem is usually studied first historically.\n\nGiven a physical system, together with initial data (the ``cause\"), the direct problem will usually predict the future state of the physical system (the ``effect\"); see Figure \\ref{fig:cause_and_effect}.\nInverse problems often turn this on its head - given the current state of a physical system at time $T$, what was the physical state at time $t = 0$?  \n\nAlternatively, suppose we measure the current state of the system, and we then measure the state at some future time.\nAn important inverse problem is to determine an appropriate mathematical model that can describe the evolution of the system.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{cause_and_effect.pdf}\n\\caption{Cause and effect within a given physical system.}\n\\label{fig:cause_and_effect}\n\\end{figure}\n\n\\section*{Another look at heat flow through a rod}\nConsider the following ordinary differential equation, together with natural boundary conditions at the ends of the interval\\footnote{This example of an ill-posed problem is given in \\textit{Inverse Problems in the Mathematical Sciences} by Charles W Groetsch.}:\n\\begin{align}\n\\begin{cases}\n\t-(au')' = f, & x \\in (0,1),\\\\\n\ta(0)u'(0) = c_0, & a(1)u'(1) = c_1.\n\\end{cases} \\label{inverse_problems:heat_flow}\n\\end{align}\nThis BVP can, for example, be used to describe the flow of heat through a rod.\nThe boundary conditions would correspond to specifying the heat flux through the ends of the rod.\nThe function $f(x)$ would then represent external heat sources along the rod, and $a(x)$ the density of the rod at each point. \n\nTypically, the density $a(x)$ would be specified, along with any heat sources $f(x)$, and the (direct) problem is to solve for the steady-state heat distribution $u(x)$.\nHere we shake things up a bit: suppose the heat sources $f$ are given, and we can measure the heat distribution $u(x)$.\nCan we find the density of the rod?\nThis is an example of a \\textit{parameter estimation problem}.\n\nLet us consider a numerical method for solving \\eqref{inverse_problems:heat_flow} for the density $a(x)$.\nSubdivide $[0,1]$ into $N$ equal subintervals, and let $x_j = jh$, $j = 0, \\ldots,N$, where $h = 1/N$.\nLet $\\phi_j(x)$ be the tent functions (used earlier in the finite element lab), given by \n\\begin{align*}\n\t\\phi_j(x) = \\begin{cases}\n(x - x_{j-1})/h  &  x \\in [x_{j-1},x_j],\\\\\n (x_{j+1} - x)/h  &  x \\in [x_{j},x_{j+1}],\\\\\n0 & \\text{ otherwise.}\n\\end{cases}\n\\end{align*}\nWe look for an approximation $a^h(x)$ of the form \n\\begin{align}\n\ta^h &= \\sum_{j=0}^N \\alpha_j \\phi_j, \\quad \\alpha_j=a(x_j).\n\\label{inverse_problems:approximate}\n\\end{align}\nIntegrating \\eqref{inverse_problems:heat_flow} from $0$ to $x$, we obtain\n\\begin{align}\n\\begin{split}\n&{} \\int_0^x -(au')'\\, ds = \\int_0^x f(s)\\, ds,\\\\\n&{} -[a(x)u'(x) - c_0] = \\int_0^x f(s)\\, ds,\\\\\n&{} u'(x) = \\frac{c_0 - \\int_0^x f(s)\\, ds}{a(x)}.\n\\end{split}\n\\end{align}\nThus for each $x_j$\n\\begin{align*}\n\tu'(x_j) &= \\frac{c_0 - \\int_0^{x_j} f(s)\\, ds}{a(x_j)},\\\\\n\t&= \\frac{c_0 - \\int_0^{x_j} f(s)\\, ds}{\\alpha_j}.\n\\end{align*}\nThe coefficients $\\alpha_j$ in \\eqref{inverse_problems:approximate} can now be approximated by minimizing \n\\begin{align*}\n\t\\sum_{j=0}^N \\left( \\frac{c_0 - \\int_0^{x_j} f(s)\\, ds}{\\alpha_j} - u'(x_j)  \\right)^2.\n\\end{align*}\n%For $c_0 = 3/8,$ $c_1 = 5/4$, $u(x) = x^2 + x/2 + 5/16$, and \n%\\begin{align*}\n%\tf &= \\begin{cases}\n%\t\t-6x^2 + 3x - 1 & x \\leq 1/2,\\\\\n%\t\t-1 & 1/2 < x \\leq 1,\n%\t\\end{cases}\n%\\end{align*}\n%we partially implement this method with the following code:\n%\n%\\begin{lstlisting}\n%import numpy as np\n%from scipy.optimize import minimize\n%import matplotlib.pyplot as plt\n%\n%def f(x):\n%\tout = -np.ones(x.shape)\n%\tm = np.where(x<.5)\n%\tout[m] = -6*x[m]**2. + 3.*x[m] - 1.\n%\treturn out\n%\n%def u(x):\n%\treturn (x+1./4)**2. + 1./4\n%\n%def integral_of_f(x):\n%\t# out =  \\int_0^x f(s) ds\n%\treturn out\n%\n%def derivative_of_u(x):\n%\t# out = u'(x)\n%\treturn out\n%\n%x = np.linspace(0,1,11)\n%F, u_p = integral_of_f(x), derivative_of_u(x)\n%\n%def sum_of_squares(alpha):\n%\tpass\n%\n%guess = (1./4)*(3-x)\n%sol = minimize(sum_of_squares,guess)\n%\n%plt.plot(x,sol.x,'-ob',linewidth=2)\n%plt.show()\n%\\end{lstlisting}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{density_a.pdf}\n\\caption{The solution $a(x)$ to Problem \\ref{prob:inverse}}\n\\label{fig:inverse_problems:num1}\n\\end{figure}\n\n\\begin{problem}\nSolve \\eqref{inverse_problems:heat_flow} for $a(x)$ using the following conditions:\n\n\\noindent $c_0 = 3/8,$ $c_1 = 5/4$, $u(x) = x^2 + x/2 + 5/16$, $x_j=.1j$ for $j=0,1,\\dots,10$, and \n\\begin{align*}\n\tf &= \\begin{cases}\n\t\t-6x^2 + 3x - 1 & x \\leq 1/2,\\\\\n\t\t-1 & 1/2 < x \\leq 1,\n\t\\end{cases}\n\\end{align*}\nProduce the plot shown in Figure \\ref{fig:inverse_problems:num1}.\n\nHint: use the \\li{minimize} function in \\li{scipy.optimize} and some initial guess to find the $a_j$.\n\\label{prob:inverse}\n\\end{problem}\n\n\\begin{problem}\n\tFind the density function $a(x)$ satisfying \n\t\\begin{align}\n\t\\begin{cases}\n\t\t-(au')' = -1, & x \\in (0,1),\\\\\n\t\ta(0)u'(0) = 1, & a(1)u'(1) = 2.\n\t\\end{cases} \\label{inverse_problems:ill_posed}\n\t\\end{align}\n\twhere $u(x) = x + 1 + \\epsilon \\sin(\\epsilon^{-2}x)$. \nUsing several values of $\\epsilon  > 0.66049142$, plot the corresponding density $a(x)$ for $x$ in \\li{np.linspace(0,1,11)} to demonstrate that the problem is ill-posed.\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{ill_posed_density_a.pdf}\n\\caption{The density function $a(x)$ satisfying \\eqref{inverse_problems:ill_posed} for $\\epsilon = .8$.}\n\\label{fig:inverse_problems:exercise1}\n\\end{figure}", "meta": {"hexsha": "e163aa21be6fb51c8f1374ef32af0191b5312760", "size": 8235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/InverseProblem/InverseProblem.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/InverseProblem/InverseProblem.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/InverseProblem/InverseProblem.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": 42.2307692308, "max_line_length": 262, "alphanum_fraction": 0.6973891925, "num_tokens": 2670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7743099641289493}}
{"text": "\\section{Statistical models}\n\\[E, \\{ P_\\theta \\} _{\\theta \\in \\Theta }\\]\n$E$ is a sample space for $X$ i.e. a set that contains all possible outcomes of $X$\\\\\n$\\displaystyle \\{ \\mathbb {P_\\theta }\\} _{\\theta \\in \\Theta }$ is a family of probability distributions on $E$.\\\\\n$\\Theta$ is a parameter set, i.e. a set consisting of some possible values of $\\Theta$.\\\\\n$\\theta$ is the true parameter and unknown. In a parametric model we assume that $\\Theta \\subset \\mathbb{R}^d,$ for some $d \\geq 1$.\n\\subsection{Identifiability}\n\\begin{align*}\n&\\theta \\neq \\theta' \\Rightarrow \\mathbb{P}_{\\theta} \\neq \\mathbb{P}_{\\theta'}\\\\\n&\\mathbb{P}_{\\theta} = \\mathbb{P}_{\\theta'} \\Rightarrow \\theta = \\theta'\n\\end{align*}\nA Model is well specified if:\n\\begin{align*}\n&\\exists \\theta \\ s.t.\\ \\mathbb{P} =\\mathbb{P}_{\\theta }\n\\end{align*}", "meta": {"hexsha": "84d8a1369e9c8ad90a63d4d0922618547b53518a", "size": 821, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Models.tex", "max_stars_repo_name": "r2cp/MITx_capstone_1", "max_stars_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "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/Models.tex", "max_issues_repo_name": "r2cp/MITx_capstone_1", "max_issues_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_issues_repo_licenses": ["MIT"], "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/Models.tex", "max_forks_repo_name": "r2cp/MITx_capstone_1", "max_forks_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "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": 54.7333333333, "max_line_length": 132, "alphanum_fraction": 0.6723507917, "num_tokens": 279, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9553191322715436, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7742660143150976}}
{"text": "\\section{Hitting and Absorption Probabilities}\r\n\\begin{definition}\r\n    Let $(X_n)$ be a Markov chain.\\\\\r\n    Then hitting time $H^A$ of a set $A\\subset I$ is the random variable $\\Omega\\to\\{0,1,\\ldots\\}\\cup\\{\\infty\\}$ given by $H^A(\\omega)=\\inf\\{n\\ge 0:X_n(\\omega)\\in A\\}$ where $\\inf\\varnothing=+\\infty$ by convention.\\\\\r\n    The hitting probability of $A$ is\r\n    $$h_i^A=\\mathbb P_i[H^A<\\infty]=\\mathbb P_i[\\text{hit $A$}]$$\r\n    If $A$ is a closed class, $h_i^A$ is called the absorption probability.\\\\\r\n    The mean hitting time is the expected time to reach $A$.\r\n    $$k_i^A=\\mathbb E_i[H^A]=\\mathbb E[\\text{time to hit $A$}]$$\r\n\\end{definition}\r\n\\begin{example}\r\n    Consider the Markov chain with transition matrix\r\n    $$\\begin{pmatrix}\r\n        1&&&\\\\\r\n        1/2&&1/2&\\\\\r\n        &1/2&&1/2\\\\\r\n        &&&1\r\n    \\end{pmatrix}$$\r\n    Observe that $\\{1\\},\\{4\\}$ are absorbing classes.\r\n    Starting from $2$, we want to know the probability of absorption in $\\{4\\}$ and the average time before the chain is absorbed in $\\{1\\}$ and $\\{4\\}$.\\\\\r\n    Let $h_i=h_i^{\\{4\\}}$ and $k_i=k_i^{\\{1,4\\}}$.\\\\\r\n    Obviously $h_1=0$ and $h_4=1$.\r\n    We have $h_2=h_1/2+h_3/2=h_3/2$ and $h_3=h_2/2+h_4/2=h_2/2+1/2$, solving which gives $h_2=1/3$.\\\\\r\n    For $k$'s, we have $k_1=k_4=0$ and $k_2=1+k_1/2+k_3/2=1+k_3/2$, $k_3=1+k_2/2+k_4/2=1+k_2/2$.\r\n    Solve for $k_2$ gives $k_2=2$.\r\n\\end{example}\r\nWe want to systematise our computation.\r\nThis inspires the following theorem:\r\n\\begin{theorem}\r\n    The vector $h^A$ of hitting probabilities is the minimal nonnegative solution to the system\r\n    $$\\begin{cases}\r\n        h_i^A=1\\text{, for $i\\in A$}\\\\\r\n        h_i^A=\\sum_{j\\in I}p_{ij}h_j^A\\text{, otherwise}\r\n    \\end{cases}$$\r\n    We need it to be minimal in the sense that if $x=(x_i)_{i\\in A}$ is another nonnegatve solution, then $x_i\\ge h_i^A$ for all $i\\in I$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $h^A$ is obviously a solution to the system.\r\n    Indeed, if $X_0=i\\in A$ it is obvious.\r\n    Otherwise $X_0=i\\notin A$, then by the Markov property,\r\n    $$\\mathbb P_i[H^A<\\infty|X_1=j]=\\mathbb P_j[H^A<\\infty]=h_j^A$$\r\n    So\r\n    \\begin{align*}\r\n        h_i^A&=\\mathbb P_i[H^A<\\infty]\\\\\r\n        &=\\sum_{j\\in I}\\mathbb P_i[H^A<\\infty|X_1=j]\\mathbb P_i[X_1=j]\\\\\r\n        &=\\sum_{j\\in I}h_j^Ap_{ij}\r\n    \\end{align*}\r\n    To see it is minimal, let $x$ be any nonnegative solution to the system.\r\n    If $i\\in A$ we clearly have $x_i=1\\ge 1=h_i^A$.\r\n    For $i\\notin A$, then\r\n    \\begin{align*}\r\n        x_i&=\\sum_{j\\in I}p_{ij}x_j=\\sum_{j\\in A}p_{ij}x_j+\\sum_{j\\notin A}p_{ij}x_j\\\\\r\n        &=\\sum_{j\\in A}p_{ij}+\\sum_{j\\notin A}p_{ij}\\left( \\sum_{k\\in A}p_{jk}+\\sum_{k\\notin A}p_{jk}x_k \\right)\\\\\r\n        &=\\mathbb P_i[X_1\\in A]+\\mathbb P_i[X_1\\notin A,X_2\\in A]+\\sum_{j\\notin A,k\\notin A}p_{ij}p_{jk}x_k\\\\\r\n        &=\\cdots\\\\\r\n        &=\\sum_{s=1}^n\\mathbb P[X_t\\notin A\\text{ for $t<s$},X_s\\in A]+\\sum_{j_1,\\ldots,j_n\\notin A}p_{ij_1}p_{j_1j_2}\\cdots p_{j_{n-1}}p_{j_n}x_{j_n}\\\\\r\n        &=\\mathbb P_i[H^A\\le n]+\\sum_{j_1,\\ldots,j_n\\notin A}p_{ij_1}p_{j_1j_2}\\cdots p_{j_{n-1}}p_{j_n}x_{j_n}\\\\\r\n        &\\ge\\mathbb P_i[H^A\\le n]\r\n    \\end{align*}\r\n    So $x_i\\ge \\mathbb P_i[H^A\\ge n]$ for all $n$, therefore\r\n    $$x_i\\ge\\lim_{n\\to\\infty}P_i[H^A\\le n]=\\mathbb P_i[H^A<\\infty]=h_i^A$$\r\n    Therefore $h^A$ is minimal.\\\\\r\n    To finish off the proof, observe that the system must has a solution since $h^A$ is one, and the solution obtained in this way must be $h^A$ since the minimality condition guaranteed uniqueness.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider our previous example with transition matrix\r\n    $$\\begin{pmatrix}\r\n        1&&&\\\\\r\n        1/2&&1/2&\\\\\r\n        &1/2&&1/2\\\\\r\n        &&&1\r\n    \\end{pmatrix}$$\r\n    Then the system in the above theorem is\r\n    $$\\begin{cases}\r\n        h_1=h_1\\\\\r\n        h_4=1\\\\\r\n        h_2=h_1/2+h_3/2\\\\\r\n        h_3=h_2/2+h_4/2\r\n    \\end{cases}$$\r\n    which is what we obtained eariler except that it does not determine $h_1$.\r\n    By the minimality condition we can then choose $h_1=0$ and get the results we got earlier.\r\n\\end{example}\r\n\\begin{example}[Gambler's Ruin]\r\n    Consider the Markov chain with $\\mathbb N\\cup\\{0\\}$ many states where for any $i$, $p_{i,i+1}=p$ and $p_{i+1,i}=q=1-p$ for some fixed $p\\in(0,1)$ and $p_{0,0}=1$.\r\n    We want to know the absorption probability $h_i=h_i^{\\{0\\}}$.\r\n    We can use this to model a casino, where a gambler with initial fortune $i$ wants to know the probability of him going broke.\r\n    By the theorem, the system we need is\r\n    $$\\begin{cases}\r\n        h_0=1\\\\\r\n        h_i=ph_{i+1}+qh_{i-1},i>0\r\n    \\end{cases}$$\r\n    Assuming $p\\neq q$, then one can easily get the general solution to be $h_i=A+B(q/p)^i$ for constants $A,B$.\r\n    For $p<q$ (which is the actual situation in most casino), then $0\\le h_i\\le 1$ gives $B=0$ and $A=1$ which means $h_i=1$ for all $i$.\r\n    If $p>q$, then $h_0=1$ gives $B=1-A$, so\r\n    $$h_i=\\left( \\frac{q}{p} \\right)^i+A\\left( 1-\\left( \\frac{q}{p} \\right)^i \\right)$$\r\n    As $h_i\\ge 0$ for all $i$, we have $A\\ge 0$.\r\n    The minimality condition then gives $A=0$, so $h_i=(q/p)^i$.\\\\\r\n    If $p=q=1/2$, then the general solution for the recursion is $h_i=A+Bi$ for constants $A,B$.\r\n    We can put in the initial conditions as usual and obtain $h_i=1$ for all $i$.\r\n\\end{example}\r\n\\begin{example}[Birth and Death Chain]\r\n    Again take the state space as the nonnegative integers.\r\n    For $i>0$, we set $p_{i,i+1}=p_1$ and $p_{i,i-1}=q_1=1-p_1$ where $p_i\\in (0,1)$ for all $i$.\r\n    Set $p_{0,0}=1$ as usual.\r\n    We again want to know the absorbing probability $h_i=h_i^{\\{0\\}}$ which can be interpreted as the extinction probability.\r\n    Now the theorem told us\r\n    $$\\begin{cases}\r\n        h_0=1\\\\\r\n        h_i=p_ih_{i+1}+q_ih_{i-1},i>0\r\n    \\end{cases}$$\r\n    Consider $u_i=h_{i-1}-h_i$, then for $i>0$,\r\n    $$p_iu_{i+1}-q_iu_i=p_ih_i-p_ih_{i+1}-q_ih_{i-1}+q_ih_i=(p_i+q_i-1)h_i=0$$\r\n    So we have\r\n    $$u_{i+1}=\\frac{q_i}{p_i}u_i=\\left( \\frac{q_iq_{i-1}\\cdots q_1}{p_ip_{i-1}\\cdots p_1} \\right)u_1=\\gamma_iu_1,\\gamma_i=\\frac{q_iq_{i-1}\\cdots q_1}{p_ip_{i-1}\\cdots p_1}$$\r\n    Hence we have\r\n    $$h_i=1-(h_0-h_i)=1-A(\\gamma_0+\\cdots +\\gamma_{i-1}),\\gamma_0=1,A=u_1$$\r\n    If $\\sum_i\\gamma_i=\\infty$, then $h_i\\in [0,1]$ gives $A=0$, so $h_i=1$ for all $i$.\r\n    Otherwise $\\gamma=\\sum_i\\gamma_i\\in\\mathbb R_+$, so by minimality $A=\\gamma^{-1}$.\r\n    Hence,\r\n    $$h_i=\\frac{\\sum_{j=i}^\\infty\\gamma_j}{\\sum_{j=0}^\\infty\\gamma_j}$$\r\n    In particular, for any $i$, we always have $h_i\\in (0,1)$, so the population survives or dies both with positive probability.\r\n\\end{example}\r\nWe've investigated a lot on hitting probability, but what about mean hitting time?\r\n\\begin{theorem}\r\n    The vector of mean hitting times $k^A=(k_i^A)_{i\\in I}$ is the minimal solution to\r\n    $$\\begin{cases}\r\n        k_i^A=0,i\\in A\\\\\r\n        k_i^A=1+\\sum_{j\\notin A}p_{ij}k_j^A,i\\notin A\r\n    \\end{cases}$$\r\n\\end{theorem}\r\nThe proof is quite analogous to the previous theorem on hitting time.\r\n\\begin{proof}\r\n    The same idea as in hitting time works to show that $k^A$ is indeed a solution.\r\n    If $X_0=i\\in A$ then obvously $k_i^A=0$.\r\n    Otherwise $X_0=i\\notin A$, so by the Markov property\r\n    $$\\mathbb E_i[H^A|X_1=j]=1+\\mathbb E_j[H^A]=1+k_j^A$$\r\n    Therefore\r\n    $$k_i^A=\\mathbb E_i[H^A]=\\sum_{j\\in I}\\mathbb E_i[H^A|X_1=j]\\mathbb P_i[X_1=j]=\\sum_{j\\in I}(1+k_j^A)p_{ij}=1+\\sum_{j\\in I}k_j^Ap_{ij}$$\r\n    To show this solution is minimal, assume $x$ is any other nonegative solution, then $x_i=0\\ge 0=k_i^A$ for any $i\\in A$.\r\n    For $i\\notin A$,\r\n    \\begin{align*}\r\n        x_i&=1+\\sum_{j\\notin A}p_{ij}x_j\\\\\r\n        &=1+\\sum_{j\\notin A}p_{ij}\\left( 1+\\sum_{k\\notin A}p_{jk}x_k \\right)\\\\\r\n        &=\\mathbb P_i[H^A\\ge 1]+\\mathbb P_i[H^A\\ge 2]+\\sum_{j\\notin A,k\\notin A}p_{ij}p_{jk}x_k\\\\\r\n        &=\\cdots\\\\\r\n        &=\\sum_{s=1}^n\\mathbb P_i[H^A\\ge s]+\\sum_{j_1,\\ldots,j_n\\notin A}p_{ij_1}\\cdots p_{j_{n-1}j_n}x_{j_n}\\\\\r\n        &\\ge\\sum_{s=1}^n\\mathbb P_i[H^A\\ge s]\\ge\\sum_{s=1}^\\infty\\mathbb P_i[H^A\\ge s]\\\\\r\n        &=\\mathbb E_i[H^A]=k_i^A\r\n    \\end{align*}\r\n    which shows the minimality.\r\n    The proof can be finished off in the same way as we did for the previous theorem.\r\n\\end{proof}", "meta": {"hexsha": "e6e7f5a5603f5afd138a21871f2315c2c6ae2d66", "size": 8252, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/hit.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": "3/hit.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": "3/hit.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": 54.2894736842, "max_line_length": 217, "alphanum_fraction": 0.6096703829, "num_tokens": 3320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.8757869786798663, "lm_q1q2_score": 0.7742301022973201}}
{"text": "\\subsection{Faraday's Law of Induction \\& Ampere's Law}\r\n\\noindent\r\nFaraday’s Law of Induction quantifies the idea that changing magnetic flux in a coil induces a current in the coil. More precisely, it induces a voltage, the potential function of electric field $\\left(\\vec{E} = \\nabla V\\right)$, and this field will oppose the magnetic field that induced it. More formally,\r\n\\begin{equation*}\r\n\t-\\frac{\\partial}{\\partial t}\\iint\\limits_{S}{\\vec{B} \\cdot \\mathrm{d}\\vec{s}} = \\oint\\limits_{C}{\\vec{E} \\cdot \\mathrm{d}\\vec{r}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t-\\iint\\limits_{S}{\\frac{\\partial}{\\partial t}\\vec{B} \\cdot \\mathrm{d}\\vec{s}} = \\iint\\limits_{S}{\\nabla \\times \\vec{E} \\cdot \\mathrm{d}\\vec{s}}\r\n\\end{equation*}\r\nby Stokes's Theorem.\\\\\r\nAs $S$ collapses to a point,\r\n\\begin{equation*}\r\n\t\\nabla \\times \\vec{E} = -\\frac{\\partial}{\\partial t}\\vec{B}.\r\n\\end{equation*} \r\nThis is Faraday's Law. It is the 3rd of Maxwell's Laws.\\\\\r\n\r\n\\noindent\r\nThe final of Maxwell's Equations is Ampere's Law (with Maxwell's correction). It says that \r\n\\begin{equation*}\r\n\t\\nabla \\times \\vec{B} = \\mu_0\\epsilon_0\\frac{\\partial\\vec{e}}{\\partial t} + \\mu_0J\r\n\\end{equation*}\r\nwhere $J$ is the current density and $\\mu_0$ is the permeability of free space. Using Maxwell's equations and some basic properties of waves, we can derive the speed of light as $c = \\frac{1}{\\sqrt{\\mu_0\\epsilon_0}}$.", "meta": {"hexsha": "9e3406f5223b817cbba2ae465aa04143b6479a66", "size": 1384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/faradaysLawInductionAmperesLaw.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/faradaysLawInductionAmperesLaw.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/faradaysLawInductionAmperesLaw.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.9090909091, "max_line_length": 308, "alphanum_fraction": 0.7001445087, "num_tokens": 460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541659378682, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7742178158421111}}
{"text": "\\section{Preprocessing of the Samples}\n\\label{sec:Preprocessing}\nIn order to make samples more comparable, all samples are preprocessed. First, the multi-channel samples are panned to mono. Since there are no spatial features used in the project, no stereo information is needed. To remove the stereo information the arithmetic mean in between the left and right channel is calculated. This is the mid signal of the stereo signal\n\\[\n    x_\\text{mid}[k] = \\frac{1}{2} \\left( x_\\text{left}[k] + x_\\text{right}[k] \\right).\n\\]\nSecond, silence at the beginning and end of each sample is cut off. All signal below a threshold level at -75~dBFS is detected as silence\n\\[\n    x_\\text{sil}[k] = \n    \\begin{cases}\n          0 & \\text{if} \\quad 20\\cdot \\lg(x_\\text{mid}[a]) < -75~\\forall~a \\leq k\\\\\n          0 & \\text{if} \\quad 20\\cdot \\lg(x_\\text{mid}[a]) < -75~\\forall~a \\geq k\\\\\n          x_\\text{mid}[k] & \\text{else}\n    \\end{cases}\n\\]\nLastly, all samples were amplified to have an root mean square (RMS) of 1 in order to normalize the energy of the samples\n\\[\n    x_\\text{pre}[k] = \\frac{x_\\text{sil}[k]}{\\sqrt{\\overline{x^2}}},\n\\]\n$\\overline{x^2}$ is the mean of the squared signal.", "meta": {"hexsha": "37c6bb1db2527b80d1b44bf596f4e7c23c15ccef", "size": 1180, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/Preprocessing.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/Preprocessing.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/Preprocessing.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": 59.0, "max_line_length": 364, "alphanum_fraction": 0.6847457627, "num_tokens": 361, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541544761566, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7742178043670578}}
{"text": "\\subsection{Isomorphisms}\n\nThe focus of this section is on linear transformations which are both one to one and onto. When this is the case, we call the transformation an isomorphism.\n\n\\begin{definition}{Isomorphism}{isomorphism}\nLet $V$ and $W$ be two vector spaces and let $T: V \\to W$ be a linear transformation.\nThen $T$ is called an \\textbf{isomorphism}\n\\index{isomorphism}if the following two conditions are satisfied.\n\n\\begin{itemize}\n\\item $T$ is one to one.\n\n\\item $T$ is onto.\n\\end{itemize}\n\\end{definition}\n\n\\begin{definition}{Isomorphic}{isomorphic}\nLet $V$ and $W$ be two vector spaces and let $T: V \\to W$ be a linear transformation.\nThen if $T$ is an isomorphism, we say that $V$ and $W$ are \\textbf{isomorphic.}\n\\index{isomorphic}\n\\end{definition}\n\nConsider the following example of an isomorphism.\n\n\\begin{example}{Isomorphism}{isomorphism}\nLet $T:\\Mat_{2,2}\\to\\R^4$ be defined by\n\\[\nT\\begin{mymatrix}{cc} a & b \\\\ c & d \\end{mymatrix}\n=\\begin{mymatrix}{c} a\\\\ b\\\\ c \\\\ d \\end{mymatrix}\n\\mbox{ for all }\n\\begin{mymatrix}{cc} a & b \\\\ c & d \\end{mymatrix}\n\\in\\Mat_{2,2}. \\]\nShow that $T$ is an isomorphism.\n\\end{example}\n\n\\begin{solution}\nNotice that if we can prove $T$ is an isomorphism, it will mean that $\\Mat_{2,2}$ and $\\R^4$ are isomorphic.\nIt remains to prove that\n\\begin{enumerate}\n\\item $T$ is a linear transformation;\n\\item $T$ is one-to-one;\n\\item $T$ is onto.\n\\end{enumerate}\n\n\\textbf{$T$ is linear:}\nLet $k,p$ be scalars.\n\\begin{eqnarray*}\nT \\paren{k \\begin{mymatrix}{cc} a_1 & b_1 \\\\ c_1 & d_1 \\end{mymatrix} +  p \\begin{mymatrix}{cc} a_2 & b_2 \\\\ c_2 & d_2 \\end{mymatrix}}\n&=& T \\paren{\\begin{mymatrix}{cc} k a_1 & k b_1 \\\\ k c_1 & k d_1 \\end{mymatrix} +  \\begin{mymatrix}{cc} p a_2 & p b_2 \\\\ p c_2 & p d_2 \\end{mymatrix}} \\\\\n&=& T \\paren{\\begin{mymatrix}{cc} k a_1 + p a_2 & k b_1 + p b_2 \\\\ k c_1 + p c_2& k d_1 + p d_2 \\end{mymatrix}} \\\\\n&=& \\begin{mymatrix}{c} k a_1 + p a_2 \\\\ k b_1 + p b_2 \\\\ k c_1 + p c_2 \\\\ k d_1 + p d_2 \\end{mymatrix}  \\\\\n&=& \\begin{mymatrix}{c} k a_1 \\\\ k b_1 \\\\ k c_1 \\\\ k d_1 \\end{mymatrix} + \\begin{mymatrix}{c} p a_2 \\\\ p b_2 \\\\ p c_2 \\\\ p d_2 \\end{mymatrix} \\\\\n&=& k \\begin{mymatrix}{c} a_1 \\\\  b_1 \\\\  c_1 \\\\  d_1 \\end{mymatrix} + p \\begin{mymatrix}{c}  a_2 \\\\  b_2 \\\\  c_2 \\\\  d_2 \\end{mymatrix} \\\\\n&=& k T \\paren{\\begin{mymatrix}{cc} a_1 & b_1 \\\\ c_1 & d_1 \\end{mymatrix}} +  p T \\paren{\\begin{mymatrix}{cc} a_2 & b_2 \\\\ c_2 & d_2 \\end{mymatrix}}\n\\end{eqnarray*}\n\nTherefore $T$ is linear.\n\n\\textbf{$T$ is one-to-one:}\nBy Lemma~\\ref{lem:one-to-one-abstract} we need to show that if $T(A) = 0$ then $A = 0$ for some matrix $A \\in \\Mat_{2,2}$.\n\\[\nT\\begin{mymatrix}{cc} a & b \\\\ c & d \\end{mymatrix}\n= \\begin{mymatrix}{c} a\\\\ b\\\\ c \\\\ d \\end{mymatrix}\n= \\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n\\]\n\nThis clearly only occurs when $a=b=c=d=0$ which means that\n\\[\nA = \\begin{mymatrix}{cc} a & b \\\\ c & d \\end{mymatrix} = \\begin{mymatrix}{cc} 0 & 0 \\\\ 0 & 0 \\end{mymatrix} = 0\n\\]\n\nHence $T$ is one-to-one.\n\n\\textbf{$T$ is onto:}\nLet\n\\[ \\vect{x}=\\begin{mymatrix}{c} x_1\\\\x_2\\\\x_3\\\\x_4 \\end{mymatrix}\\in\\R^4,\\]\nand\ndefine matrix $A\\in\\Mat_{2,2}$ as follows:\n\\[ A=\\begin{mymatrix}{cc} x_1 & x_2 \\\\ x_3 & x_4 \\end{mymatrix}.\\]\n\nThen $T(A)=\\vect{x}$, and therefore $T$ is onto.\n\nSince $T$ is a linear transformation which is one-to-one and onto, $T$ is an isomorphism. Hence $\\Mat_{2,2}$ and $\\R^4$ are isomorphic.\n\\end{solution}\n\nAn important property of isomorphisms is that the inverse of an isomorphism\nis itself an isomorphism and the composition of isomorphisms is an\nisomorphism. We first recall the definition of composition.\n\n\\begin{definition}{Composition of transformations}{composite-transformation}\nLet $V, W, Z$ be vector spaces and suppose $T: V \\to W$ and $S: W \\to Z$ are linear transformations. Then the composite of $S$ and $T$ is\n\\[\nS \\circ T: V \\to Z\n\\]\nand is defined by\n\\[\n(S \\circ T) (\\vect{v}) = S(T(\\vect{v})) \\mbox{ for all } \\vect{v} \\in V\n\\]\n\\end{definition}\n\nConsider now the following proposition.\n\n\\begin{proposition}{Composite and inverse isomorphism}{composite-inverse}\nLet $T:V\\rightarrow W$ be an isomorphism. Then $T^{-1}:W\\rightarrow V$ is\nalso an isomorphism. Also if $T:V\\rightarrow W$ is an isomorphism and if $\nS:W\\rightarrow Z$ is an isomorphism for the vector spaces $V,W,Z$, then $\nS\\circ T$ defined by $(S\\circ T) (v) = S(\nT(v)) $ is also an isomorphism.\n\\end{proposition}\n\n\\begin{proof}\nConsider the first claim. Since $T$ is onto, a typical\nvector in $W$ is of the form $T(\\vect{v})$ where $\\vect{v} \\in V$. Consider then for $a,b$\nscalars,\n\\begin{equation*}\nT^{-1}(aT(\\vect{v}_{1})+bT(\\vect{v}_{2}))\n\\end{equation*}\nwhere $\\vect{v}_{1}, \\vect{v}_2 \\in V$. Consider if this is equal to\n\\begin{equation*}\naT^{-1}(T(\\vect{v}_{1})) +bT^{-1}(T(\\vect{v}_{2})) =a\\vect{v}_{1}+b\\vect{v}_{2}?\n\\end{equation*}\nSince $T$ is one to one, this will be so if\n\\begin{equation*}\nT(a\\vect{v}_{1}+b\\vect{v}_{2}) =T(T^{-1}(aT(\\vect{v}_{1})+bT(\\vect{v}_{2}))\n) =aT(\\vect{v}_{1})+bT(\\vect{v}_{2})\n\\end{equation*}\nHowever, the above statement is just the condition that $T$ is a linear map.\nThus $T^{-1}$ is indeed a linear map. If $\\vect{v} \\in V$ is given, then $\n\\vect{v}=T^{-1}(T(\\vect{v})) $ and so $T^{-1}$ is onto. If $T^{-1}(\\vect{v})=\\vect{0}$, then\n\\begin{equation*}\n\\vect{v}=T(T^{-1}(\\vect{v})) =T(\\vect{0})=\\vect{0}\n\\end{equation*}\nand so  $T^{-1}$ is one to one.\n\nNext suppose $T$ and $S$ are as described. Why is $S\\circ T$ a linear map?\nLet for $a,b$ scalars,\n\\begin{eqnarray*}\nS\\circ T(a\\vect{v}_{1}+b\\vect{v}_{2}) &\\equiv &S(T(\na\\vect{v}_{1}+b\\vect{v}_{2})) =S(aT(\\vect{v}_{1})+bT(\\vect{v}_{2})) \\\\\n&=&aS(T(\\vect{v}_{1})) +bS(T(\\vect{v}_{2})) \\equiv a(S\\circ\nT) (\\vect{v}_{1}) +b(S\\circ T) (\\vect{v}_{2})\n\\end{eqnarray*}\nHence $S\\circ T$ is a linear map. If $(S\\circ T) (\\vect{v})\n=0$, then $S(T(\\vect{v})) =\\vect{0}$ and it follows that $T(\\vect{v})=\\vect{0}$ and hence by this lemma again, $\\vect{v}=\\vect{0}$. Thus $S\\circ\nT $ is one to one. It remains to verify that it is onto. Let $\\vect{z}\\in Z$. Then\nsince $S$ is onto, there exists $\\vect{w}\\in W$ such that $S(\\vect{w})=\\vect{z}$. Also, since $T$\nis onto, there exists $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$. It follows that $S(\nT(\\vect{v})) =\\vect{z}$ and so $S\\circ T$ is also onto.\n\\end{proof}\n\nSuppose we say that two vector spaces $V$ and $W$ are related if there exists an isomorphism of one to the other, written as $V\\iso W$.\nThen the above proposition suggests that $\\iso$ is an equivalence relation. That is: $\\iso$\nsatisfies the following conditions:\n\n\\begin{itemize}\n\\item $V\\iso V$\n\n\\item If $V\\iso W$, it follows that $W\\iso V$\n\n\\item If $V\\iso W$ and $W\\iso Z$, then $V\\iso Z$\n\\end{itemize}\n\nWe leave the proof of these to the reader.\n\nThe following fundamental lemma describes the relation between bases and\nisomorphisms.\n\n\\begin{lemma}{Bases and isomorphisms}{bases-isomorphism}\nLet $T:V\\rightarrow W$ be a\n\\index{isomorphism!invertible matrices}\n\\index{invertible matrices!isomorphism} linear map where $V,W$ are vector spaces.  Then a linear transformation $T$ which is one to one has the property that\nif $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is linearly\nindependent, then so is $\\set{T(\\vect{u}_{1}),\\ldots,T(\\vect{u}_{k})}$.\n More generally, $T$ is an\nisomorphism if and only if whenever $\\set{\n\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ is a basis for $V$, it follows\nthat $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ is a basis for $W$.\n\\end{lemma}\n\n\\begin{proof}\nFirst suppose that $T$ is a linear map and is one to one\nand $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{k}} $ is linearly\nindependent. It is required to show that $\\set{T(\\vect{u}_{1}),\\ldots,T(\\vect{u}_{k})} $ is also linearly independent. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{k}c_{i}T(\\vect{u}_{i})=\\vect{0}\n\\end{equation*}\nThen, since $T$ is linear,\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{u}_{i}} =\\vect{0}\n\\end{equation*}\nSince $T$ is one to one, it follows that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{u}_{i}=0\n\\end{equation*}\nNow the fact that $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{n}} $ is\nlinearly independent implies that each $c_{i}=0$. Hence $\\set{T(\\vect{u}\n_{1}),\\ldots,T(\\vect{u}_{n})} $ is linearly independent.\n\nNow suppose that $T$ is an isomorphism and $\\set{\\vect{v}_{1},\\ldots,\\vect{\nv}_{n}} $ is a basis for $V$. It was just shown that $\\set{T(\\vect{v}\n_{1}),\\ldots,T(\\vect{v}_{n})} $ is linearly independent. It remains to\nverify that the span of $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $\nis all of $W$. This is where $T$ is onto is used. If $\\vect{w}\\in W$, there\nexists $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{w}$. Since $\\set{\\vect{v}\n_{1},\\ldots,\\vect{v}_{n}} $ is a basis, it follows that there exists\nscalars $\\set{c_{i}} _{i=1}^{n}$ such that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{v}.\n\\end{equation*}\nHence,\n\\begin{equation*}\n\\vect{w}=T(\\vect{v})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}}\n=\\sum_{i=1}^{n}c_{i}T\\vect{v}_{i}\n\\end{equation*}\nwhich shows that the span of these vectors $\\set{T(\\vect{v}_{1}),\\ldots,T\n(\\vect{v}_{n})} $ is all of $W$ showing that this set of vectors is a\nbasis for $W$.\n\nNext suppose that $T$ is a linear map which takes a basis to a basis. Then\nfor $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ a basis for $V$, it\nfollows $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ is a basis for $\nW$. Then if $w\\in W$, there exist scalars $c_{i}$ such that $\nw=\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} $\nshowing that $T$ is onto. If $T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =0$\nthen $\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=\\vect{0}$ and since the vectors $\\set{T(\\vect{v}\n_{1}),\\ldots,T(\\vect{v}_{n})} $ are linearly independent, it follows\nthat each $c_{i}=0$. Since $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$ is a typical vector in\n$V$, this has shown that if $T(\\vect{v})=0$ then $\\vect{v}=\\vect{0}$ and so $T$ is also one to one.\nThus $T$ is an isomorphism.\n\\end{proof}\n\nThe following theorem illustrates a very useful idea for defining an\nisomorphism. Basically, if you know what it does to a basis, then you can\nconstruct the isomorphism.\n\n\\begin{theorem}{Isomorphic vector spaces}{isomorphic-vector-spaces}\nSuppose $V$ and $W$ are two vector spaces. Then the two vector spaces are isomorphic if and only\nif they have the same dimension. In the case that the two vector spaces have\nthe same dimension, then for\n\\index{isomorphism!equivalence} a linear transformation $T:V\\rightarrow W$, the\nfollowing are equivalent.\n\n\\begin{enumerate}\n\\item $T$ is one to one.\n\n\\item $T$ is onto.\n\n\\item $T$ is an isomorphism.\n\\end{enumerate}\n\\end{theorem}\n\n\\begin{proof}Suppose first these two vector spaces have the same\ndimension. Let a basis for $V$ be $\\set{\n\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ and let a basis for $W$ be $\n\\set{\\vect{w}_{1},\\ldots,\\vect{w}_{n}}$. Now define $T$ as\nfollows.\n\\begin{equation*}\nT(\\vect{v}_{i})=\\vect{w}_{i}\n\\end{equation*}\nfor $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$ an arbitrary vector of $V$,%\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} = \\sum_{i=1}^{n}c_{i}T\n(\\vect{v}_{i})=\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}.\n\\end{equation*}\nIt is necessary to verify that this is well-defined. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{v}_{i}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\sum_{i=1}^{n}(c_{i}-\\hat{c}_{i}) \\vect{v}_{i}=0\n\\end{equation*}\nand since $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $ is a basis, $\nc_{i}=\\hat{c}_{i}$ for each $i$. Hence\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}=\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{w}_{i}\n\\end{equation*}\nand so the mapping is well-defined. Also if $a,b$ are scalars,\n\\begin{eqnarray*}\nT\\paren{a\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}+b\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{v}\n_{i}} &=&T(\\sum_{i=1}^{n}(ac_{i}+b\\hat{c}_{i}) \\vect{v\n}_{i}) =\\sum_{i=1}^{n}(ac_{i}+b\\hat{c}_{i}) \\vect{w}_{i} \\\\\n&=&a\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}+b\\sum_{i=1}^{n}\\hat{c}_{i}\\vect{w}_{i} \\\\\n&=&aT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} +bT\\paren{\\sum_{i=1}^{n}\n\\hat{c}_{i}\\vect{v}_{i}}\n\\end{eqnarray*}\nThus $T$ is a linear map.\n\nNow if\n\\begin{equation*}\nT\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =\\sum_{i=1}^{n}c_{i}\\vect{w}\n_{i}=\\vect{0},\n\\end{equation*}\nthen since the $\\set{\\vect{w}_{1},\\ldots,\\vect{w}_{n}} $ are\nindependent, each $c_{i}=0$ and so $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{0}$\nalso. Hence $T$ is one to one. If $\\sum_{i=1}^{n}c_{i}\\vect{w}_{i}$ is a\nvector in $W$, then it equals\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T\\vect{v}_{i}=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}}\n\\end{equation*}\nshowing that $T$ is also onto. Hence $T$ is an isomorphism and so $V$ and $W$\nare isomorphic.\n\nNext suppose these two vector spaces are isomorphic. Let $T$ be the name of\nthe isomorphism. Then for $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $\na basis for $V$, it follows that a basis for $W$\nis $\\set{T\\vect{v}_{1},\\ldots,T\\vect{v}_{n}} $ showing that the two\nvector spaces have the same dimension.\n\nNow suppose the two vector spaces have the same dimension.\n\nFirst consider the claim that $1.)\\Rightarrow 2.)$. If $T$ is one to one,\nthen if $\\set{\\vect{v}_{1},\\ldots,\\vect{v}\n_{n}} $ is a basis for $V$, then $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v\n}_{n})} $ is linearly independent. If it is not a basis, then it must\nfail to span $W$. But then there would exist $\\vect{w}\\notin \\sspan\n\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $ and it follows that $\n\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n}),\\vect{w}} $ would be\nlinearly independent which is impossible because there exists a basis for $W$\nof $n$ vectors. Hence\n\\[\n\\sspan\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}\n_{n})} =W\n\\]\nand so $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{n})} $\nis a basis. Hence, if $\\vect{w}\\in W$, there exist scalars $c_{i}$ such that\n\\begin{equation*}\n\\vect{w}=\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=T\\paren{\\sum_{i=1}^{n}c_{i}\\vect{v}\n_{i}}\n\\end{equation*}\nshowing that $T$ is onto. This shows that $1.)\\Rightarrow 2.)$.\n\nNext consider the claim that $2.)\\Rightarrow 3.)$. Since $2.)$ holds, it\nfollows that $T$ is onto. It remains to verify that $T$ is one to one. Since\n$T$ is onto, there exists a basis of the form $\\set{T(\\vect{v}_{i}),\\ldots,T\n(\\vect{v}_{n})}$. If $\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $\nis linearly independent, then this set of vectors must also be a basis for $\nV $ because if not, there would exist $\\vect{u}\\notin \\sspan\\set{\\vect{\nv}_{1},\\ldots,\\vect{v}_{n}} $ so $\\set{\\vect{v}_{1},\\ldots,\\vect{v}\n_{n},\\vect{u}} $ would be a linearly independent set which is\nimpossible because by assumption, there exists a basis which has $n$\nvectors. So why is$\\set{\\vect{v}_{1},\\ldots,\\vect{v}_{n}} $\nlinearly independent? Suppose\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}=\\vect{0}\n\\end{equation*}\nThen\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T\\vect{v}_{i}=\\vect{0}\n\\end{equation*}\nHence each $c_{i}=0$ and so, as just discussed, $\\set{\\vect{v}_{1},\\ldots,\n\\vect{v}_{n}} $ is a basis for $V$. Now it follows that a typical\nvector in $V$ is of the form $\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}$. If $T\\paren{\n\\sum_{i=1}^{n}c_{i}\\vect{v}_{i}} =\\vect{0}$, it follows that\n\\begin{equation*}\n\\sum_{i=1}^{n}c_{i}T(\\vect{v}_{i})=\\vect{0}\n\\end{equation*}\nand so, since $\\set{T(\\vect{v}_{i}),\\ldots,T(\\vect{v}_{n})} $ is\nindependent, it follows each $c_{i}=0$ and hence $\\sum_{i=1}^{n}c_{i}\\vect{v}\n_{i}=\\vect{0}$. Thus $T$ is one to one as well as onto and so it is an\nisomorphism.\n\nIf $T$ is an isomorphism, it is both one to one and onto by definition so $\n3.)$ implies both $1.)$ and $2.)$.\n\\end{proof}\n\nNote the interesting way of defining a linear transformation in the first\npart of the argument by describing what it does to a basis and then\n``extending it linearly''.\n\nConsider the following example.\n\n\\begin{example}{}{}\nLet $V=\\R^{3}$ and let $W$ denote the polynomials of degree at most\n2. Show that these two vector spaces are isomorphic.\n\\end{example}\n\n\\begin{solution}\nFirst, observe that a basis for $W$ is $\\set{1,x,x^{2}} $ and a basis for $V$\nis $\\set{\\vect{e}_{1},\\vect{e}_{2},\\vect{e}_{3}}$. Since these two\nhave the same dimension, the two are\nisomorphic. An example of an isomorphism is this:\\\n\\begin{equation*}\nT(\\vect{e}_{1})=1,T(\\vect{e}_{2})=x,T(\\vect{e}_{3})=x^{2}\n\\end{equation*}\nand extend $T$ linearly as in the above proof. Thus\n\\begin{equation*}\nT(a,b,c) =a+bx+cx^{2}\n\\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "1216e1486eaadf953ef3088283c4bdb238a4ef04", "size": 16392, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/vectorspacesIsomorphismsIsomorphisms.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/vectorspacesIsomorphismsIsomorphisms.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/vectorspacesIsomorphismsIsomorphisms.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.9232736573, "max_line_length": 157, "alphanum_fraction": 0.6506222548, "num_tokens": 6391, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.9196425366837827, "lm_q1q2_score": 0.7741786809827987}}
{"text": "\\subsection{Boundary Points, Open \\& Closed Sets}\r\n\\noindent\r\nGiven some set $\\Omega \\subset \\mathbb{R}^n$, $x$ is an interior point to $\\Omega$ if $\\exists \\delta \\mid N(x, \\delta) \\subset \\Omega$. That is, $x$ is an interior point to $\\Omega$ if you can draw a circle of non-zero radius around $x$ such that the entire circle is inside of $\\Omega$.\\\\\r\nAll points that are not interior points are boundary points. Formally, $x$ is a boundary point of $\\Omega$ if $\\forall \\delta \\mid N(x,\\delta) \\not\\subset \\Omega$.\\\\\r\nUsing our definitions of interior and boundary points, we can define and open set as one that doesn't contain any of its boundary points and a closed set as one that contains all of its boundary point. Note that a set that contains some of its boundary points is neither open nor closed.", "meta": {"hexsha": "34a12b70444d2e0b28f3660b1d93d1637fa2f0dc", "size": 808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/boundaryPointsOpenClosedSets.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/boundaryPointsOpenClosedSets.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/boundaryPointsOpenClosedSets.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": 161.6, "max_line_length": 291, "alphanum_fraction": 0.7376237624, "num_tokens": 205, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7741786764649494}}
{"text": "\n\\subsection{Inequality constraints}\n\nlinear programming means of the form\nmax \\(c^Tx\\)\nst. \\(Ax<=b\\)\n\\(x>=0\\)\nthis is the canonical form\n\n\\subsubsection{Lagrangians with inequality constraints}\n\nWe can add constraints to an optimisation problem. These constraints can be equality constraints or inequality constraints. We can write constrained optimisation problem as:\n\nMinimise \\(f(x)\\) subject to \n\n\\(g_i(x)\\le 0\\) for \\(i=1,...,m\\)\n\n\\(h_i(x)=0\\) for \\(i=1,…,p\\)\n\nWe write the Lagrangian as:\n\n\\(\\mathcal{L}(x, \\lambda, \\nu )=f(x)+\\sum_{i=1}^m\\lambda_i g_i(x)+\\sum_{i=1}^p\\nu_ih_i(x)\\)\n\nIf we try and solve this like a standard Lagrangian, then all of the inequality constraints will instead by equality constraints.\n\n\\subsubsection{Affinity of the Lagrangian}\n\nThe Lagrangian function is affine with respect to \\(\\lambda \\) and \\(\\nu \\).\n\n\\(\\mathcal{L}(x, \\lambda, \\nu )=f(x)+\\sum_{i=1}^m\\lambda_i g_i(x)+\\sum_{i=1}^p\\nu_ih_i(x)\\)\n\n\\(\\mathcal{L}_{\\lambda_i}(x, \\lambda, \\nu )=g_i(x)\\)\n\n\\(\\mathcal{L}_{\\nu_i}(x, \\lambda, \\nu )=h_i(x)\\)\n\nAs the partial differential is constant, the partial differential is an affine function.\n\n", "meta": {"hexsha": "b5c5950b8366f92cc8c95337d9c53fb5feb222fe", "size": 1129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationMulti/03-01-inequality.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/optimisationMulti/03-01-inequality.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/optimisationMulti/03-01-inequality.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.7105263158, "max_line_length": 173, "alphanum_fraction": 0.6997342781, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7741786653993664}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: Cumulative}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to various topics we have studied.\n\\end{abstract}\n\\maketitle\n\n\n\\begin{exercise}\nThe series\n\\[ \\sum_{n=1}^\\infty \\left( e^{ \\frac{1}{n}} - 1 \\right) \\]\nis \\wordChoice{\\choice{convergent}\\choice[correct]{divergent}} by limit comparison to the $p$-series\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n^p} \\]\nwith $p = \\answer{1}$.  Likewise, the\nseries\n\\[ \\sum_{n=1}^\\infty \\left( e^{ \\frac{1}{n}} - 1 - \\frac{1}{n} \\right) \\]\nis \\wordChoice{\\choice[correct]{convergent}\\choice{divergent}} by limit comparison to the $p$-series\nwith $p = \\answer{2}$.\n\\begin{hint}\nUse a Maclaurin series to determine the dominant behavior of \n\\[ e^{\\frac{1}{n}} - 1 \\]\nas $n \\rightarrow \\infty$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nFill in the blank below with an appropriate constant to make the series absolutely convergent:\n\\[ \\sum_{n=1}^\\infty \\left[ \\ln \\left( 1 + \\frac{1}{n} \\right) - \\frac{\\answer{1}}{n} \\right] \\]\n\\begin{hint}\nUse the Maclaurin series for $\\ln (1 + x)$ and substitute $x = 1/n$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the series below converges absolutely, conditionally, or diverges.\n\\[ \\sum_{n=1}^\\infty n \\sin \\frac{1}{n} \\]\n\\begin{multipleChoice}\n\\choice{Absolute}\n\\choice{Conditional}\n\\choice[correct]{Diverge}\n\\end{multipleChoice}\n\\begin{hint}\nShow that the terms do not go to zero as $n \\rightarrow \\infty$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the series below converges absolutely, conditionally, or diverges.\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\sin \\frac{1}{n} \\]\n\\begin{multipleChoice}\n\\choice[correct]{Absolute}\n\\choice{Conditional}\n\\choice{Diverge}\n\\end{multipleChoice}\n\\begin{hint}\nUse the Maclaurin series for $\\sin x$ and evaluate at $x = 1/n$. Find the dominant term.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nDetermine whether the series below converges absolutely, conditionally, or diverges.\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\ln \\left(2 + \\frac{1}{n} \\right) \\]\n\\begin{multipleChoice}\n\\choice{Absolute}\n\\choice{Conditional}\n\\choice[correct]{Diverge}\n\\end{multipleChoice}\n\\begin{hint}\nTry limit comparison with the harmonic series.\n\\end{hint}\n\\end{exercise}\n\\begin{exercise}\nDetermine whether the series below converges absolutely, conditionally, or diverges.\n\\[ \\sum_{n=1}^\\infty \\frac{1}{n} \\ln \\left(1 + \\frac{1}{n} \\right) \\]\n\\begin{multipleChoice}\n\\choice[correct]{Absolute}\n\\choice{Conditional}\n\\choice{Diverge}\n\\end{multipleChoice}\n\\begin{hint}\nDo a Taylor expansion of $\\ln (1 + x)$ and evaluate at $x = 1/n$.\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the sum of the series below.\n\\[ \\sum_{n=0}^\\infty \\frac{(-1)^n}{2n+1} \\frac{1}{3^n} \\]\n\\begin{itemize}\n\\item We know the series\n\\[ \\sum_{n=0}^\\infty \\frac{(-1)^n x^{2n+1}}{2n+1} = \\answer{\\arctan x} \\]\nfor $-1 < x < 1$. \n\\item This means\n\\[ \\sum_{n=0}^\\infty \\frac{(-1)^n x^{2n}}{2n+1} = \\answer{\\frac{\\arctan x}{x}}. \\]\n\\item We conclude\n\\[  \\sum_{n=0}^\\infty \\frac{(-1)^n}{2n+1} \\frac{1}{3^n} = \\answer{\\frac{\\pi \\sqrt{3}}{6}}. \\]\n\\end{itemize}\n\\end{exercise}\n\n\n\n\\begin{exercise}\nCompute the sum of the series below.\n\\[ \\sum_{n=0}^\\infty n 3^{-n} = \\answer{\\frac{3}{4}}. \\]\n\\begin{hint}\n\\[ \\frac{1}{1-x} = \\sum_{n=0}^\\infty x^n \\ \\ \\text{ when } -1 < x < 1. \\]\n\\end{hint}\n\\begin{hint}\n\\[ \\frac{1}{(1-x)^2} = \\sum_{n=0}^\\infty n x^{n-1} \\ \\ \\text{ when } -1 < x < 1. \\]\n\\end{hint}\n\\end{exercise}\n\n\\begin{exercise}\nCompute the sum of the series below.\n\\[ \\sum_{n=1}^\\infty \\frac{3}{n(n+1)} = \\answer{3}. \\]\n\\begin{hint}\nYou don't need Taylor series for this one.\n\\end{hint}\n\\begin{hint}\nIt's a telescoping series\n\\end{hint}\n\\end{exercise}\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2015C.02]\n\nIf it converges, find the sum of the series \\(\\displaystyle \\sum_{n=0}^\\infty \\frac{(-1)^n \\pi^{2n}}{3^{2n} (2n)!}\\). \\offline{If the series diverges, explain why.}\n\\begin{multiplechoice}\n\\choice{\\(\\ln 2\\)}\n\\choice{\\(\\ln 3 - \\ln 2\\)}\n\\choice{\\(e^{-2}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle \\frac{2}{e}\\)}\n\\choice{diverges}\n\\end{multiplechoice}\n\\begin{feedback}\nWe recognize the Taylor series for cosine:\n\\[ \\cos x = \\sum_{n=0}^\\infty \\frac{(-1)^n \\pi^{2n}}{3^{2n}(2n)!} \\]\nThe series in question is exactly\n\\[ \\sum_{n=0}^\\infty \\frac{(-1)^n (\\pi/3)^{2n}}{(2n)!} = \\cos \\frac{\\pi}{3} = \\frac{1}{2}. \\]\n\\end{feedback}\n\n\\end{question}\n\n\\begin{question}%%%%%[2015C.05]\n\nWhat is the limit of the sequence \\(\\displaystyle \\left\\{ n^2 \\left( 1 - \\cos \\frac{1}{n} \\right) \\right\\}\\)?\n\\begin{multiplechoice}\n\\choice{\\(1\\)}\n\\choice{\\(-1\\)}\n\\choice{\\(\\displaystyle \\frac{\\sqrt{3}}{2}\\)}\n\\choice[correct]{\\(\\displaystyle \\frac{1}{2}\\)}\n\\choice{\\(\\displaystyle -\\frac{\\sqrt{3}}{2}\\)}\n\\choice{diverges}\n\\end{multiplechoice}\n\n\\end{question}\n\n\\begin{question}%%%%%[2017C.10]\n\nFind the limit of the sequence\n\\[ a_n = \\left\\{ n \\left[ \\ln (n+3) - \\ln n \\right] \\right\\}. \\]\n\\begin{multiplechoice}\n\\choice{\\(0\\)}\n\\choice{\\(1\\)}\n\\choice{\\(\\ln 3\\)}\n\\choice[correct]{\\(3\\)}\n\\choice{\\(\\infty\\)}\n\\choice{the limit does not exist}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "d8470290cae76e5d41f4f21c90316313120fb92b", "size": 5200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "powerseries/28finalpractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "powerseries/28finalpractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "powerseries/28finalpractice.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": 28.8888888889, "max_line_length": 164, "alphanum_fraction": 0.6575, "num_tokens": 1916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190939, "lm_q2_score": 0.9005297861178929, "lm_q1q2_score": 0.7741528069044509}}
{"text": "\\section{Analysis of Unconstrained Stochastic Gradient Descent.}\nFirst, let's examine the case with $P = 0$ and let's make no assumptions about strong convexity. Assume $\\|G(x, \\xi)\\| \\leq M$ for all $x$ and $\\xi$. Let $x_*$ denote any optimal solution of \\eqref{eq:origpro}. Then we have\n\\begin{eqnarray}\n\\mathbb{E}[\\|x_{k+1}-x_*\\|^2]&=&\\mathbb{E}[\\|x_{k}-\\gamma_k G(x_k,\\xi_k)-x_*\\|^2]  \\nonumber \\\\\n&=&\\mathbb{E}[\\|x_{k}-x_*\\|^2]- 2\\gamma_k\\mathbb{E}[\\langle G(x_k,\\xi_k), x_k-x_*\\rangle ]+ \\gamma_k^2 \\mathbb{E}[\\|\\gamma_k G(x_k,\\xi_k)\\|^2] \\nonumber \\\\\n&\\leq&\\mathbb{E}[\\|x_{k}-x_*\\|^2]- 2\\gamma_k\\mathbb{E}[\\langle G(x_k,\\xi_k), x_k-x_*\\rangle ]+ \\gamma_k^2 M^2 \\nonumber \\\\\n&=&\\mathbb{E}[\\|x_{k}-x_*\\|^2]- 2\\gamma_k\\mathbb{E}[\\langle \\nabla f(x_k), x_k-x_*\\rangle ]+ \\gamma_k^2 M^2 \\label{eq:eqnproof5} \\\\\n&\\leq& \\mathbb{E}[\\|x_{k}-x_*\\|^2]- 2\\gamma_k\\mathbb{E}[f(x_k)-f(x_*)]+ \\gamma_k^2 M^2 \\label{eq:eqnproof6}\n\\end{eqnarray}\n\\eqref{eq:eqnproof5} follows because\n\\begin{eqnarray}\n\\mathbb{E}[\\langle G(x_k,\\xi_k), x_k-x_*\\rangle ]&=&\\mathbb{E}_{\\xi_0,\\ldots,\\xi_{k-1}}[\\mathbb{E}_{\\xi_k}[\\langle G(x_k,\\xi_k), x_k-x_*\\rangle\\ |\\ \\xi_0,\\ldots,\\xi_{k-1} ]] \\nonumber\\\\\n&=&\\mathbb{E}_{\\xi_0,\\ldots,\\xi_{k-1}}[\\langle \\nabla f(x_k), x_k-x_*\\rangle\\ |\\ \\xi_0,\\ldots,\\xi_{k-1} ] \\\\\n&=&\\mathbb{E}[\\langle \\nabla f(x_k), x_k-x_*\\rangle]\n\\end{eqnarray}\nby the law of iterated expectation. \\eqref{eq:eqnproof6} is a consequence of the inequality\n\\begin{equation}\n\\langle \\nabla f(x_k), x_k-x_*\\rangle \\geq f(x_k)-f(x_*)\n\\end{equation}\nwhich holds because $f$ is convex.\n\nArranging the bound: by telescoping $k$ from $0$ to $n$,\n\\begin{equation}\n2\\gamma_k\\mathbb{E}[f(x_k)-f(x_*)] \\leq -\\mathbb{E}[\\|x_{k+1}-x_*\\|^2-\\|x_{k}-x_*\\|^2] + \\gamma_k^2 M^2,\n\\end{equation}\nwe have since $\\|x_{n+1}-x_*\\|^2\\geq 0$\n\\begin{equation}\n2\\sum_{k=0}^n \\gamma_k\\mathbb{E}[f(x_k)-f(x_*)] \\leq -\\mathbb{E}[\\|x_{n+1}-x_*\\|^2-\\|x_{0}-x_*\\|^2] + M^2 \\sum_{k=0}^{n} \\gamma_k^2\\leq D^2+M^2  \\sum_{k=0}^{n} \\gamma_k^2.\n\\end{equation}\nDividing by the sum of the $\\gamma_k$, we have for any $n$\n\\begin{equation}\n\\frac{1}{\\sum_{k=0}^n \\gamma_k}\\sum_{k=0}^n \\gamma_k\\mathbb{E}[f(x_k)-f(x_*)] \\leq \\frac{D^2+M^2  \\sum_{k=0}^{n} \\gamma_k^2}{2\\sum_{k=0}^n \\gamma_k}.\n\\end{equation}\nwhere $D=\\|x_0-x_*\\|$. Let $\\bar{x}:=(\\sum_{k=0}^n \\gamma_k)^{-1}\\sum_{k=0}^n \\gamma_k x_k$. Then, by convexity (Jensen's inequality), we have\n\\begin{equation}\n\\mathbb{E}[f(\\bar{x})-f(x_*)] \\leq \\frac{D^2+M^2  \\sum_{k=0}^{n} \\gamma_k^2}{2\\sum_{k=0}^n \\gamma_k}.\n\\end{equation}\nThis is precisely the bound rate of convergence for deterministic subgradient descent.", "meta": {"hexsha": "1f7829b890f305ffa86371f47bf43749a430e367", "size": 2612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Analysis_Prox_SGD.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/Analysis_Prox_SGD.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/Analysis_Prox_SGD.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.7368421053, "max_line_length": 223, "alphanum_fraction": 0.6374425727, "num_tokens": 1201, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857831, "lm_q2_score": 0.8856314798554445, "lm_q1q2_score": 0.774110326907313}}
{"text": "\\subsection{The Model}\n\nThe  model  used  by  both  Hudzovic\\cite{ref:hudzovic}  and Sani\\cite{ref:sani}\napproximate  the  step  response of a plant by using a series  of  PT1  elements\nmultiplied  together with varying time constants $T_k$ to form  a  PTn  element,\n$G(s)$. This is defined as:\n\n\\begin{equation}\n    G_n(s,r) = y_0 + K_s \\prod_{k=1}^{n} \\frac{1}{1+s \\cdot T_k(r)}\n    \\label{eq:ptn}\n\\end{equation}\n\nwhere the scale factor, $K_s$, is defined as:\n\n\\begin{equation}\n    K_s = \\frac{xa(\\infty)}{xeo}\n\\end{equation}\n\nThe  transfer function in equation \\ref{eq:ptn} serves as a basis to  model  the\nstep response of many systems.\n\nRather than individually having to find the time constants  $T_1\\ldots  T_n$  --\nthe effort of which would greatly increase with the order $n$ -- the two methods\nof  P.  Hudzovic  and  L.  Sani instead calculate these constants using a common\nfunction $T_k(r)$.\n\nThe  approach  proposed  by  P.  Hudzovic\\cite{ref:hudzovic}  for  $T_k(r)$  is:\n\n\\begin{equation}\n    T_k(r) = \\frac{T}{1 - (k-1)r}\n    \\label{eq:hudzovic}\n\\end{equation}\n\nwhere  the  constant  $r$  must  be   confined  to  the  interval  $0  \\le  r  <\n\\frac{1}{n-1}$.\n\nThe   approach   proposed   by   L.   Sani\\cite{ref:sani}   for   $T_k(r)$   is:\n\n\\begin{equation}\n    T_k(r) = T \\cdot r^{k-1}\n    \\label{eq:sani}\n\\end{equation}\n\nwhere  the  constant $r$ must be confined to  the  interval  $0  \\leq  r  <  1$.\n\nAs  can  be  seen,  in both cases, the  problem  has  been  reduced  to  finding\nappropriate values for  $n$,  $T$  and  $r$  such  that  the  step  response  of\n$G_n(s,r)$ approximates the data acquired from the plant as closely as possible.\n\n", "meta": {"hexsha": "c7863f86b4d9e805b32bafa00bbf75f505e36bc6", "size": 1666, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "versuche/mlab/sections/theory/model.tex", "max_stars_repo_name": "TheComet93/laborjournal", "max_stars_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_stars_repo_licenses": ["WTFPL"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "versuche/mlab/sections/theory/model.tex", "max_issues_repo_name": "TheComet93/laborjournal", "max_issues_repo_head_hexsha": "5b83c35ec2580a22106d755f466dc6371d7444ee", "max_issues_repo_licenses": ["WTFPL"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "versuche/mlab/sections/theory/model.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": 33.32, "max_line_length": 80, "alphanum_fraction": 0.668667467, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026573249612, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7741072254788577}}
{"text": "\\subsection{Convergence of Gradient Descent method}\nNow we are ready to study the rate of convergence of unconstrained minimization schemes. \nFor the optimization problem \\eqref{optmodel},\n\\begin{equation}\\label{key}\n\\min_{x\\in \\mathbb{R}^n} f(x).\n\\end{equation}\nWe assume that $f(x)$ is convex.\nThen we say that $x^*$ is a minimizer if \n$$\nf(x^*) = \\min_{x \\in \\mathbb{R}^n} f(x).\n$$\n%By Theorem \\ref{th:critical}, \nFor minimizer $x^*$, we have\n\\begin{equation}\\label{key}\n\\nabla f(x^*) = 0.\n\\end{equation}\nWe have the next two properties of the minimizer for convex functions:\n\\begin{enumerate}\n\t\\item If $f(x) \\ge c_0$, for some $c_0 \\in \\mathbb{R}$, then we have \n\t\\begin{equation}\\label{key}\n\t\\mathop{\\arg\\min} f \\neq \\emptyset.\n\t\\end{equation}\n\t\\item If $f(x)$ is $\\lambda$-strongly convex, then $f(x)$ has a unique minimizer, namely, there\n\texists a unique $x^*\\in \\mathbb{R}^n$ such that \n\t\\begin{equation}\\label{key}\n\tf(x^*) = \\min_{x\\in \\mathbb{R}^n }f(x).\n\t\\end{equation}\n\\end{enumerate}\n\n\nTo investigate the convergence of gradient descent method, let us recall the gradient\ndescent method:\n\\begin{algorithm}\n\t\\caption{ FGD} \n\t\\label{alg:FGD}\n\t{\\bf For}: $t = 1, 2, \\cdots$\n\t\\begin{equation}\\label{equ:fgd-iteration}\n\tx_{t+1} =  x_{t} - \\eta_t \\nabla f(x_t), \n\t\\end{equation}\n\twhere $\\eta_t$ is the stepsize / learning rate.\n\\end{algorithm}\n\n\n\n\nWe have the next theorem about the convergence of gradient descent method under the Assumption\n\\ref{ass:GD}.\n\n\\begin{theorem}\n\tFor Gradient Descent Algorithm \\ref{alg:FGD}, if $f(x)$ satisfies Assumption \\ref{ass:GD}, then \n\t\\begin{equation}\n\t\\|x_t - x^*\\|^2 \\le  \\alpha^t \\|x_0 - x^*\\|^2\n\t\\end{equation}\n\tif $0<\\eta_t <\\frac{2\\lambda}{L^2}$ and $\\alpha < 1$. \n\t\n\tParticularly, if $\\eta_t = \\frac{\\lambda}{L^2}$, then\n\t\\begin{equation}\n\t\\|x_t - x^*\\|^2 \\le  \\left(1 - \\frac{\\lambda^2}{L^2}\\right)^t \\|x_0 - x^*\\|^2.\n\t\\end{equation} \n\\end{theorem}\n\n\\begin{proof}\n\tNote that \n\t\\begin{equation}\n\tx_{t+1} - x =  x_{t} - \\eta_t \\nabla f(x_t)  - x.\n\t\\end{equation}\n\tBy taking $L^2$ norm for both sides, we get \n\t\\begin{equation}\n\t\\|x_{t+1} - x \\|^2 = \\|x_{t} - \\eta_t \\nabla f(x_t) - x \\|^2.\n\t\\end{equation}\n\tLet $x = x^*$. It holds that\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\|x_{t+1} - x^* \\|^2 &=  \\| x_{t} - \\eta_t \\nabla f(x_t) - x^* \\|^2 \\\\\n\t&= \\|x_t-x^*\\|^2 - 2\\eta_t \\nabla f(x_t)^\\top (x_t - x^*) + \\eta_t^2 \\|\\nabla f(x_t) - \\nabla f(x^*)\\|^2 \\qquad \\mbox{\\scriptsize (by $\\nabla f(x^*)=0$)}\\\\\n\t&\\le \\|x_t - x^*\\|^2 - 2\\eta_t \\lambda \\|x_t - x^*\\|^2 + \\eta_t ^2 L^2 \\|x_t - x^*\\|^2  \\quad \\mbox{\\scriptsize (by $\\lambda$- strongly convex \\eqref{strongConvIneq} and Lipschitz)}\\\\\n\t&\\le (1 - 2\\eta_t \\lambda + \\eta_t^2 L^2) \\|x_t - x^*\\|^2\n\t=\\alpha \\|x_t - x^*\\|^2,\n\t\\end{aligned}\n\t\\end{equation}\n\twhere\n\t$$\n\t\\alpha = \\left(L^2 (\\eta_t  -{\\lambda\\over L^2})^2 + 1-{\\lambda^2\\over L^2}\\right)<1\\  \\mbox{if } 0< \\eta_t<\\frac{2\\lambda}{L^2}.\n\t$$ \n\tParticularly, if $\\eta_t =\\frac{\\lambda}{L^2}$,\n\t$$\n\t\\alpha=1-{\\lambda^2\\over L^2},\n\t$$\n\twhich finishes the proof. \n\\end{proof}\nThis means that if the learning rate is chosen appropriatly, $\\{x_t\\}_{t=1}^\\infty$ from the gradient descent method will converge to the minimizer $x^*$ of the function.\n\nThere are some issues on Gradient Descent method:\n\\begin{itemize}\n\\item $\\nabla f(x_{t})$ is very expensive to compute.\n\\item Gradient Descent method does not yield generalization accuracy.\n\\end{itemize}\nThe stochastic gradient descent (SGD) method in the next section will focus on these two issues.\n", "meta": {"hexsha": "df38af65a392d4dcdf45d5734560242fb1b43301", "size": 3503, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/4 Training Algorithms/4.2-DL-GD-Convergence.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/4 Training Algorithms/4.2-DL-GD-Convergence.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/4 Training Algorithms/4.2-DL-GD-Convergence.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": 35.3838383838, "max_line_length": 184, "alphanum_fraction": 0.6451612903, "num_tokens": 1366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.9173026505426831, "lm_q1q2_score": 0.7741072215560113}}
{"text": "\\subsection{Unitary groups \\(U(n, F)\\)}\n\n\\subsubsection{Metric preserving transformations for sesquilinear forms}\n\nFor bilinear forms, the transformations which preserved metrics were:\n\n\\(P^T=P^{-1}\\)\n\nFor sesquilinear they are different:\n\n\\(u^*Mv\\)\n\n\\((Pu)^*M(Pv)\\)\n\n\\(u^*P^*MPv\\)\n\nSo we want the matrices where:\n\n\\(P^*MP=M\\)\n\n\\subsubsection{The unitary group}\n\nThe unitary group is where \\(M=I\\)\n\n\\(P^*P=I\\)\n\n\\(P^*=P^{-1}\\)\n\nWe refer to these using \\(U\\) instead of \\(P\\).\n\n\\(U^*=U^{-1}\\)\n\n\\subsubsection{Parameters of the unitary group}\n\nThe unitary group depends on the dimension of the vector space, and the underlying field. So we can have:\n\n\\begin{itemize}\n\\item \\(U(n, R)\\); and\n\\item \\(U(n, C)\\).\n\\end{itemize}\n\n\\subsubsection{We generally refer only to the complex}\n\nFor the \\(U(n, R)\\) we have:\n\n\\(U^*=U^{-1}\\)\n\n\\(U^T=U^{-1}\\)\n\nThis is the condition for the orthogonal group, and so we would instead write \\(O(n)\\).\n\nAs a result, \\(U(n)\\) refers to \\(U(n,C)\\).\n\\subsubsection{\\(U(1)\\): The circle group}\n\n", "meta": {"hexsha": "cf2b8a35f162bb776d8643da65854a0f8bb01095", "size": 1016, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/03-02-U.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/03-02-U.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/03-02-U.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.4727272727, "max_line_length": 105, "alphanum_fraction": 0.6515748031, "num_tokens": 321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179068309441, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7740995767663696}}
{"text": "\\chapter{projection equations}\n\n\nThe equation for a point object located at ($x_0$, $y_0$, $z_0$) in a circular scan trajectory is given by:\n\n\\begin{equation}\\label{eq:circularorbit}\n\\begin{split}\nx_{\\alpha}& = x_0 \\cos \\alpha \\pm y_0 \\sin \\alpha, \\\\\ny_{\\alpha}& = \\mp x_0 \\sin \\alpha + y_0 \\cos \\alpha, \\\\\nz& \\equiv z_0.\n\\end{split}\n\\end{equation}\n\nOn a perfectly well aligned detector the projection orbit of the point, $(u_{\\alpha}^{(id)}, v_{\\alpha}^{(id)})$, in the (x,y,z) coordinate is then given by its projections onto the detector plane, \n\\begin{equation}\\label{eq:idealUVpoints}\nu_{\\alpha}^{(id)} = \\frac{R x_{\\alpha}}{y_{\\alpha} + R_F}, \\hspace{0.4cm} v_{\\alpha}^{(id)} = \\frac{Rz_0}{y_{\\alpha}+R_F}, \n\\end{equation}\nwhere $R$ and $R_F$ are the distances from the focus to the detector and the axis of rotation, respectively.  For a misaligned detector the point (u,v) with (x', y', z') coordinates, the point locations on the detector is given by:\n\n\n\\begin{equation}\\label{eq:circularorbit}\n\\begin{split}\nx_{\\alpha}& = x_0 \\cos \\alpha \\pm y_0 \\sin \\alpha, \\\\\ny_{\\alpha}& = \\mp x_0 \\sin \\alpha + y_0 \\cos \\alpha, \\\\\nz& \\equiv z_0.\n\\end{split}\n\\end{equation}\n\nOn a perfectly well aligned detector the projection orbit of the point, $(u_{\\alpha}^{(id)}, v_{\\alpha}^{(id)})$, in the (x,y,z) coordinate is then given by its projections onto the detector plane, \n\\begin{equation}\\label{eq:idealUVpoints}\nu_{\\alpha}^{(id)} = \\frac{R x_{\\alpha}}{y_{\\alpha} + R_F}, \\hspace{0.4cm} v_{\\alpha}^{(id)} = \\frac{Rz_0}{y_{\\alpha}+R_F}, \n\\end{equation}\nwhere $R$ and $R_F$ are the distances from the focus to the detector and the axis of rotation, respectively.  For a misaligned detector the point (u,v) with (x', y', z') coordinates, the point locations on the detector is given by:\n\n\\begin{equation}\\label{eq:nonidealUVpoints}\n\\begin{split}\n\\begin{pmatrix}\nu \\\\ v \n\\end{pmatrix} = & \\frac{1}{\\det \\mathbf{Q}} \n\\begin{pmatrix}\no_{33}-o_{23}v^{(id)}/R & -(o_{13} - o_{23} u^{(id)}/R) \\\\\n-(o_{31} - o_{21} v^{(id)}/R) & o_{11}-o_{21} u^{(id)}/R \\\\\n\\end{pmatrix} \\\\\n\\times & \n\\begin{pmatrix}\nu^{(id)'} - d_x \\\\\nv^{(id)'} - d_z \n\\end{pmatrix},\n\\end{split}\n\\end{equation}\nwhere the primes denote a simple rescaling of the ideal orbit by\n\n\\begin{equation}\n\\begin{pmatrix}\nu^{(id)'} \\\\ v^{(id)'}\n\\end{pmatrix}\n= \\frac{R_y'}{R}\n\\begin{pmatrix}\nu^{(id)} \\\\ v^{(id)}\n\\end{pmatrix}.\n\\end{equation}\nwhere\n\\begin{equation}\n\\begin{split}\n\\det \\mathbf{Q} =& (o_{11} - o_{21} u^{(id)}/R)(o_{33}-o_{23}v^{(id)}/R) \\\\\n& -(o_{13}-o_{23}u^{(id)}/R)(o_{31}-o_{21} v^{(id)}/R).\n\\end{split}\n\\end{equation}\n\nand $\\mathbf{O}$ is the rotation matrix of the misaligned detector shown by \n\\begin{equation}\n\\mathbf{O} = \n\\begin{pmatrix}\n\\cos \\eta \\cos \\varphi - \\sin \\eta \\sin \\theta \\sin \\varphi & -\\cos \\theta \\sin \\varphi & -\\cos \\varphi \\sin \\eta - \\cos \\eta \\sin \\theta \\sin \\varphi \\\\\n\\cos \\varphi \\sin \\eta \\sin \\theta + \\cos \\eta \\sin \\varphi & \\cos \\theta \\cos \\varphi & \\cos \\eta \\cos \\varphi \\sin \\theta - \\sin \\eta \\sin \\varphi \\\\\n\\cos \\theta \\sin \\eta & -\\sin \\theta & \\cos \\eta \\cos \\theta\n\\end{pmatrix}\n\\end{equation}\n", "meta": {"hexsha": "d6f63c498f09fbb9aa91bec8d219b9bff996501d", "size": 3103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/projection_equations.tex", "max_stars_repo_name": "hfan36/dissertation", "max_stars_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Notes/projection_equations.tex", "max_issues_repo_name": "hfan36/dissertation", "max_issues_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Notes/projection_equations.tex", "max_forks_repo_name": "hfan36/dissertation", "max_forks_repo_head_hexsha": "5d755c96cf6cbece2c382789015e9db9ceb02da7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.2784810127, "max_line_length": 231, "alphanum_fraction": 0.6500161134, "num_tokens": 1166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9637799472560582, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7740828036309777}}
{"text": "%---------------------------Aspect Ratio-----------------------------\n\\section{Aspect Ratio\\label{s:tri-aspect-ratio}}\n\nThe aspect ratio of a triangle is: \n\\[\nq = \\frac{L_{\\max}}{2\\sqrt{3}r}.\n\\]\nUsing~\\eqref{eq:Arp}, one can thus write it alternatively as\n\\begin{equation*}\n\\label{eq:triangle_aspect_ratio}\nq = \\frac{L_{\\max}(L_0 + L_1 + L_2)}{4\\sqrt{3}A}.\n\\end{equation*}\n\nNote that in earlier versions of \\verd{}, triangle aspect ratio\nwas used to call out what is now called the triangle aspect.\n\n\\trimetrictable{aspect ratio}%\n{$1$}%                                                Dimension\n{$[1,1.3]$}%                                          Acceptable range\n{$[1,DBL\\_MAX]$}%                                     Normal range\n{$[1,DBL\\_MAX]$}%                                     Full range\n{$1$}%                                                Unit equilateral triangle value\n{\\cite{pebay:03}}%                                    Reference(s)                   \n{v\\_tri\\_aspect\\_ratio}%                            Verdict function name\n\n", "meta": {"hexsha": "b77e407566c3f843df2a093624b1b9341f06bc0b", "size": 1045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriAspectRatio.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/TriAspectRatio.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/TriAspectRatio.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.1923076923, "max_line_length": 85, "alphanum_fraction": 0.4708133971, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9362850093037732, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7740378578042824}}
{"text": "\\section{Solutions to Differential Equations}\r\n\\begin{definition}\r\n\tA solution to an ODE on an interval $I$ is a function $f$ that makes the differential equation true on $I$ when $f$ is substituted into the equation.\r\n\\end{definition}\r\n\\noindent\r\nAlthough this definition seems straightforward it gives us a formal way to check if a function is a solution to a differential equation.\r\n\r\n\\begin{example}\r\n\tCheck that $y = t^2\\ln{t}$ ($t > 0$) and $y = t^2$  are solutions to the differential equation\r\n\t\\begin{equation*}\r\n\t\tt^2y'' - 3ty' + 4y = 0.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nWe'll check $y= t^2\\ln{t}$ ($t > 0$) first.\r\n\\begin{align*}\r\n\tt^2\\left(t^2\\ln{t}\\right)'' - 3t\\left(t^2\\ln{t}\\right)' + 4\\left(t^2\\ln{t}\\right) &= 0 \\text{, } t > 0 \\\\\r\n\tt^2\\left(3 + 2\\ln{t}\\right) - 3t\\left(t + 2t\\ln{t}\\right) + 4\\left(t^2\\ln{t}\\right) &= 0 \\text{, } t > 0 \\\\\r\n\t3t^2 + 2t^2\\ln{t} - 3t^2 - 6t^2\\ln{t} + 4t^2\\ln{t} &= 0 \\text{, } t > 0 \\\\\r\n\t0 &= 0.\r\n\\end{align*}\r\nSo $y = t^2\\ln{t}$ ($t > 0$) is a solution.\r\nNow we'll check $y= t^2$.\r\n\\begin{align*}\r\n\tt^2\\left(t^2\\right)'' - 3t\\left(t^2\\right)' + 4\\left(t^2\\right) &= 0 \\\\\r\n\tt^2\\left(2\\right) - 3t\\left(2t\\right) + 4t^2 &= 0 \\\\\r\n\t2t^2 - 6t^2 + 4t^2 &= 0 \\\\\r\n\t0 &= 0.\r\n\\end{align*}\r\nSo $y = t^2$ is also a solution.", "meta": {"hexsha": "5254dd1ec361242eeb39daed7dfd935ff471d533", "size": 1275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/solutions/solutions.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/solutions/solutions.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/solutions/solutions.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.5, "max_line_length": 151, "alphanum_fraction": 0.5960784314, "num_tokens": 556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8723473846343393, "lm_q1q2_score": 0.7739506069646896}}
{"text": "\\section{Link analysis}\n\n\\subsection{Power method}\nComputing the pagerank index given a connection matrix \nconsists of finding \na probability distribution over websites in the web graph.\n\nWe can initialize a vector with $n$ components, each \nwith value $\\frac{1}{n}$, where $n$ is the number of websites \nand multiply it to the connection matrix many times. \nWe will converge to an eigenvector of the matrix, with eigenvalue 1, \nthat represent the final probability distribution over websites.\n\n\\paragraph{Result is an eigenvector}\nWe start with a matrix $A = [a_{i,j}]_{n \\times n}$, given an eigenpair $(\\lambda, \\vec{x})$, it holds that $A\\vec{x} = \\lambda \\vec{x}$.\n\nAlso, for $A$ dimensionality, we have $n$ eigenpairs, and we can \nsort them by non-increasing values of eigenvalue\n$$(\\lambda_1, \\vec{x}_1), \\dots, (\\lambda_n, \\vec{x}_n)$$\n\nEigenvalues are orthogonal and they constitute a basis for the space \nin which vectors such as $\\vec{x}$ lives.\nIf we now consider a starting vector $v_0$ as the starting probability distribution, we can rewrite it as follows.\n\\begin{equation}\n    \\begin{aligned}\n        \\vec{v}_0 &= \\alpha_1\\vec{x}_1 + \\dots + \\alpha_n\\vec{x}_n\n    \\end{aligned}\n\\end{equation}\nThus the matrix vector multiplication to find the final distribution becomes:\n\\begin{equation}\n    \\begin{aligned}\n         \\vec{v}_1 = A\\vec{v}_0 &= A(\\alpha_1\\vec{x}_1 + \\dots + \\alpha_n\\vec{x}_n) && \\text{For the above equation}\\\\\n         &= \\alpha_1A\\vec{x}_1 + \\dots + \\alpha_nA\\vec{x}_n && \\text{Distribute multiplication}\\\\\n         &= \\alpha_1\\lambda_1\\vec{x}_1 + \\dots + \\alpha_n\\lambda_n\\vec{x}_n && \\text{They are eigenvectors}\n    \\end{aligned}\n\\end{equation}\nComputing $\\vec{v}_2$ now becomes:\n\\begin{equation}\n    \\begin{aligned}\n         \\vec{v}_2 = A\\vec{v}_1 &= A(\\alpha_1\\lambda_1\\vec{x}_1 + \\dots + \\alpha_n\\lambda_n\\vec{x}_n) && \\text{Using the previous result}\\\\\n         &= \\alpha_1\\lambda_1^2\\vec{x}_1 + \\dots + \\alpha_n\\lambda_n^2\\vec{x}_n && \\text{We distribute A, as before}\\\\\n    \\end{aligned}\n\\end{equation}\nAt the generic $\\vec{v}_k$ we have:\n\\begin{equation}\n    \\begin{aligned}\n         \\vec{v}_k &= \\alpha_1\\lambda_1^k\\vec{x}_1 + \\dots + \\alpha_n\\lambda_n^k\\vec{x}_n\\\\\n         &= \\lambda_1^k\\bigg(\\alpha_1\\vec{x}_1 + \n         \\alpha_2\\bigg(\\frac{\\lambda_2}{\\lambda_1}\\bigg)^k\\vec{x}_2 \\dots\\bigg)\\\\\n         &\\approx \\lambda_1^k\\alpha_1\\vec{x}_1 &&\\text{As k grows, lambdas are sorted}\n    \\end{aligned}\n\\end{equation}\nWe have a practical problem, as if $\\lambda_1$ is smaller than 1 this method \ndiverges. \nIt holds that the maximum eigenvalue of a row-stochastic matrix\nis equals to 1.\n\\paragraph{Determinant of the transpose}\nTo prove it, we start to prove that $\\mathit{det}A^T = \\mathit{det}A$:\n\\begin{equation}\n    \\begin{aligned}\n        \\mathit{det}A &= \\sum_i a_{ij} c_{ij} = \\sum_j a_{ij} c_{ij}\\\\\n        \\mathit{det}A^T &= \\sum_i a_{ij}^T c_{ij}^T = \\sum_i a_{ji} c_{ji} = \\sum_j a_{ij} c_{ij} = \\mathit{det}A\\\\\n    \\end{aligned}\n\\end{equation}\nIt also holds that $A$ and $A^T$ have the same eigenvalues:\n\\begin{equation}\n    \\begin{aligned}\n        \\mathit{det}(A-\\lambda I) = 0 &\\longleftrightarrow \\mathit{det}(A-\\lambda I)^T = 0\\\\\n        &\\longleftrightarrow \\mathit{det}(A^T-\\lambda I) = 0\n    \\end{aligned}\n\\end{equation}\n\n\\paragraph{One as eigenvalue}\nWe can now show that 1 is always an eigenvalue of a row-stochastic matrix: \n\\begin{equation}\n    \\begin{aligned}\n        A\\cdot \\vec{1} = \\biggr[\\sum_j a_{ij}\\cdot1\\biggr]_n = \\vec{1} && \\text{As the components in $A$ row-wise are probabilities}\n    \\end{aligned}\n\\end{equation}\nWe can multiply the unit vector by one showing that it is a valid eigenvalue.\nSimilarly, this results holds even if $A$ is column-stochastic.\n\n\\paragraph{Power of stochastic matrix}\nWe now prove that if $A$ is row-stochastic, $A^k$ is as well.\n\\begin{equation}\n    \\begin{aligned}\n        k=1:&& \\text{trivial}\\\\\\\\\n        A^k\\;r.s. \\rightarrow A^{k+1}\\;r.s. : && a_{ij}^{k+1} &= \n        \\sum_s a_{is}^k \\cdot a_{sj}\\\\\n        && \\sum_j a_{ij}^{k+1} &= \\sum_j\n        \\sum_s a_{is}^k \\cdot a_{sj}\\\\\n        && &= \\sum_s a_{is}^k \\sum_j a_{sj}\\\\\n        && &= \\sum_s a_{is}^k \\cdot 1 = 1\n    \\end{aligned}\n\\end{equation}\n\n\\paragraph{One is highest eigenvalue}\nWe are left to show 1 is the highest eigenvalue of a column-wise stochastic matrix. Suppose it exists an eigenvalue greater than one.\n\\begin{equation}\n    \\begin{aligned}\n        A^T = \\lambda\\vec{v}\\\\\n        (A^T)^k = \\lambda^k\\vec{v} \\\\\n        \\sum_j((a^T)^k)_{ij}v_j = \\lambda^kv_i\n    \\end{aligned}\n\\end{equation}\nWe can overestimate the left end with $v_\\mathit{max}$, the maximum vector component, we underestimate tghe right end with $G$, a value of choice. \nIt exists a $k$ that makes the equation true as lambda is greater than one. We then divide by $v_\\mathit{max}$.\n\\begin{equation}\n    \\begin{aligned}\n        \\sum_j((a^T)^k)_{ij}v_\\mathit{max} &> G\\\\\n        1 = \\sum_j((a^T)^k)_{ij} &> \\frac{G}{v_\\mathit{max}}\\\\\n    \\end{aligned}\n\\end{equation}\n$A$ is column wise stochastic, the transpose is row stochastic, thus if we raise to the $k$ we get a sum of one. \nThis means it is absurd to assume we have an eigenvalue greater than one, as $G$ is arbitrary big.", "meta": {"hexsha": "a6e7cc7819f57d771c6900d21d1a376419f31fc2", "size": 5230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-courses/massive-datasets/chapters/link-analysis.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/massive-datasets/chapters/link-analysis.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/massive-datasets/chapters/link-analysis.tex", "max_forks_repo_name": "marcodb97/unimi-notes", "max_forks_repo_head_hexsha": "b0b9520a01568c4c64f4fdb69523dd05339ee8f6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-09T08:24:02.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T08:24:02.000Z", "avg_line_length": 45.4782608696, "max_line_length": 147, "alphanum_fraction": 0.6640535373, "num_tokens": 1752, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8633916134888613, "lm_q1q2_score": 0.7738159095710428}}
{"text": "\\subsection{Discrete Regularized Transport} \n\\label{sec:regsymme}\n\nSo far, we have introduced a transport problem where the mass conservation constraint is relaxed. The second step is to define its regularization. A classic way of imposing regularity on a mapping $V: \\RR^d \\rightarrow \\RR^d$ is by measuring the amplitude of its derivatives. Two examples for continuous functions are the quadratic Tikhonov regularizations such as the Sobolev semi-norm $\\|\\nabla V\\|^2$, and the anisotropic total variation semi-norm $\\|\\nabla V\\|_1$ regularization. But, the differential operator $\\nabla$  cannot be applied directly to our point clouds due to the lack of neighborhood definition. To extend the definition of the gradient operator, we need to impose a graph structure on each point cloud.\n\nIn our setting, we want to regularize the discrete map $T$ defined in~\\eqref{eqT}, which is only defined at the location of the points as $X_i \\mapsto \\tilde{V}_i=X_i - \\diag(\\Sig \\U)^{-1} (\\Sig Y)_i $.  To avoid the normalization $\\diag(\\Sig \\U)$ (which typically leads to non-convex optimization problems) we impose a regularity on the map $X_i \\mapsto V_i = \\diag(\\Sig \\U)X_i-(\\Sigma Y)_i$. This switch also has the advantage of imposing a stronger regularization in regions with large weights and to further regularize the variations of the weights $\\Sig \\U \\in \\RR^N$. We believe these are actually interesting features to reduce artifacts for imaging applications. \n\n\\paragraph{Gradient on Graphs}\n\nA natural way to define a gradient on a point cloud $X$ is by using  the gradient on a weighted graph $\\Gg_X = (X,E_X,W_X)$ where $E_X \\subset \\{1,\\ldots,N\\}^2$ is the set of edges and $W_X$ is the set of weights, $W_X = (w_{i,j})_{i,j=1}^N:  \\{1,\\ldots,N\\}^2 \\mapsto \\RR^+$, satisfying $w_{i,j}=0$ if $(i,j) \\notin E_X$. The edges of this graph are defined depending on the application. A typical example is the $n$-nearest neighbor graph, where every vertex $X_i$ is connected to $X_j$ if $X_j$ is one of the $n$-closest points to $X_i$ in $X$, creating the edge $(i,j) \\in E_X$, with a weight $w_{i,j}$. Because the edges are directed, the adjacency matrix is not symmetric. \n\nThe gradient operator on $\\Gg_X$ is defined as $G_X : \\RR^{N \\times d} \\rightarrow \\RR^{P \\times d}$, where $P=\\|E_X\\|$ is the number of edges and where, for each $V=(V_i)_{i=1}^N \\in \\RR^d$, \n\\eq{\n\tG_X V = \\pa{ w_{i,j}(V_i-V_j) }_{(i,j) \\in E_X} \\in \\RR^{P \\times d}.\n}\nA classic choice for the weights to ensure consistency with the directional derivative is $w_{i,j} = \\norm{X_i-X_j}^{-1}$, see for instance~\\cite{guilboa07}.\n\n\n%%%%%%%%%%%%%%%\n\\paragraph{Regularity Term}\n\nThe regularity of a transport map $V \\in \\RR^{N \\times d}$ is then measured according to some norm of $G_X V$, that we choose here for simplicity to be the following\n\\eq{\n\t\\regul{G_X  V} = \\sum_{(i,j) \\in E_x} \\left(\\norm{ w_{i,j} (V_i-V_j) }_q \\right)^p,\n}\nwhere $\\|.\\|_q$ is the $\\ell^q$ norm in $R^d$. \n\nThe case $(p,q)=(1,1)$ is the graph anisotropic total variation, $(p,q)=(2,2)$ is the graph Sobolev semi-norm, and $(p,q)=(1,2)$ is the graph isotropic total variation, see for instance~\\cite{elmoataz-graph} for applications of these functionals to imaging problems such as image segmentation and regularization. \n\n\\subsection{Symmetric Regular OT Formulation}\n\nGiven two point clouds X and Y, our goal is to compute a relaxed OT mapping between them which is regular with respect to both point clouds. To simplify notation, we conveniently re-write the displacement fields we aim to regularize as:\n\\eq{\n\t\\De_{X,Y}(\\Sig) = \\diag( \\Sigma \\U ) X - \\Sigma Y\n\t\\qandq\n\t\\De_{Y,X}(\\Sig^*) = \\diag( \\Sigma^* \\U ) Y -  \\Sigma^* X.\n}\n\nOur goal is to obtain a partial matching that is regular according to $X$ and $Y$, so we create two graphs $\\Gg_X$ and $\\Gg_Y$ as described in Section~\\ref{sec:regsymme} and we denote the corresponding gradient operators $G_X \\in \\RR^{P_X \\times N}$ and $G_Y \\in \\RR^{P_Y \\times N}$ where $P_X$ and $P_Y$ are the number of edges in the respective graphs. The symmetric regularized discrete OT energy is defined as: \n\\eql{\\label{eq-symm-reg-energy}\n\\umin{\\Sig \\in \\Matr_\\kappa} \\dotp{\\Sig}{\\Cost{X}{Y}} + \\la_X \\regul{G_X \\De_{X,Y}(\\Sig)} + \\la_Y \\regul{G_Y \\De_{Y,X}(\\Sig^*)},\n}\nwhere $(\\la_X,\\la_Y) \\in (\\RR^+)^2$ controls the desired amount of regularity.\nThe case $\\kappa=(1,1,1,1)$ and $(\\la_X,\\la_Y)=(0,0)$ corresponds to the usual OT defined in~\\eqref{eqMK}, and $(\\la_X,\\la_Y)=(0,0)$ corresponds to the un-regularized formulation~\\eqref{eq-relax-map}.\n\n%%%%%%%%%%%%%%%\n\\subsection{Algorithms} \n\\label{secalgosymm}\n\nSpecific values of the parameters $p$ and $q$ lead to different regularization terms, which in turn necessitate different optimization methods. In the following, for the sake of concreteness, we concentrate on the specific cases $(p,q)=(2,2)$ and $(p,q)=(1,1)$.\n\n%%%\n\\paragraph{Sobolev regularization}\n\nDefining $q=p=2$ fixes the regularization term as a graph-based Sobolev regularization. In this specific case, the minimization~\\eqref{eq-symm-reg-energy} becomes a quadratic programming problem \n\\begin{equation} \\label{eq-symm-S}\n\t\\umin{\\Sig \\in \\Matr_\\kappa}\n\tf(\\Sig) =  \\dotp{ \\Cost{X}{Y}}{\\Sig } + \\frac{\\la_X}{2} \\norm{ \\Gamma_{X,Y}(\\Sig)\\|^2 + \\frac{\\la_Y}{2} \\|\\Gamma_{Y,X}(\\Sig) }^2, \n\\end{equation} \nwhere $\\Gamma_{X,Y}(\\Sig) = G_X \\De_{X,Y}(\\Sig)$ and $\\Gamma_{Y,X}(\\Sig) = G_Y \\De_{Y,X}(\\Sig^*)$. The Frank-Wolfe algorithm is well tailored to solve such problems, as noticed for instance in~\\cite{Zaslavskiy09}, given that $f$ is convex and differentiable, and $\\Matr_\\kappa$ is a convex set. \nThe Frank-Wolfe method (also known as conditional gradient) iterates the following steps until convergence\n\\begin{equation}\n\\begin{aligned}\\label{eq-frankwolfe-update}\n\t\\tilde\\Sig^{(\\ell+1)} &\\in \\uargmin{\\tilde\\Sig \\in \\Matr_\\kappa} \\dotp{\\nabla f(\\Sig^{(\\ell)})}{ \\tilde\\Sig } \\\\\n\t\\Sig^{(\\ell+1)} &= \\Sig^{(\\ell+1)} + \\tau_\\ell ( \\tilde\\Sig^{(\\ell+1)}-\\Sig^{(\\ell+1)} ),\\\\\n\\end{aligned}\n\\end{equation}\nwhere $\\tau_\\ell$ is obtained by line-search. The first equation of~\\eqref{eq-frankwolfe-update} is a linear program which is efficiently solved using interior point methods~\\cite{Nesterov-Nemirovsky-Book}. \nThe function $f$ is quadratic, and to compute $\\nabla f(\\Sig)$, we note that $\\nabla \\frac{1}{2}\\norm{\\Ga_{X,Y}(\\Sig)}^2 = \\Ga_{X,Y}^*( \\Ga_{X,Y}(\\Sig) )$, where the adjoint $\\Ga_{X,Y}^*$ of $\\Ga_{X,Y}$ is\n\\eq{\n\t\\Ga_{X,Y}^* = \\De^*_{X,Y} \\circ G_X^*\n\t\\qwhereq \n\t\\choice{\n\t\t\\De^*_{X,Y}(U)= \\diag^*(U X^*)\\U^*-U Y^*, \\\\\n\t\t\\De^*_{Y,X}(U)= (\\diag^*(U Y^*)\\U^*)^*-X U^*,\n\t}\n}\nwhere $\\diag^*: \\RR^{N \\times N} \\mapsto \\RR^{N}$ is the adjoint of the $\\diag$ operator, and given $A \\in \\RR^{N \\times N}$, $\\diag^*(A)$ is a vector composed by the elements on the diagonal of $A$. \n\nThis leads to the following formula\n\\eq{\n\t\\nabla f(\\Sig) = \\Cost{X}{Y} + \\la_X  \\De^*_{X,Y}(G_X^*  \\Gamma_{X,Y}(\\Sig)) + \\la_Y \\De^*_{Y,X}(G_Y^* \\Gamma_{Y,X}(\\Sig)), \n} \n\nThe line search optimal step can be explicitly computed as\n\\eq{\n\t\\tau_{\\ell} = \n\t\\frac{ - \\dotp{ E^{(\\ell)} }{ \n\t\t\\Cost{X}{Y} } - \n\t\t\\dotp{  \\Gamma_{X,Y}(E^{(\\ell)}) }{  \\Gamma_{X,Y}(\\Sig^{(\\ell)}) } - \n\t\t\\dotp{  \\Gamma_{Y,X}( E^{(\\ell)} )  }{  \\Gamma_{Y,X} (\\Sig^{(\\ell)}) }\t\n\t}{ \n\t\t\\la_X \\norm{\\Gamma_{X,Y}(E^{(\\ell)})}^2 +   \\la_Y \\norm{\\Gamma_{Y,X}(E^{(\\ell)})}^2\n\t}\n} \nwhere $E^{(\\ell)} = \\Sig^{(\\ell+1)} - \\tilde\\Sig^{(\\ell+1)}$.\n\n%%%%\n\\paragraph{Anisotropic TV regularization}\n\nWe define an anisotropic total variation (TV) norm by setting the parameters $q=p=1$.\nProblem~\\eqref{eq-symm-reg-energy} can be re-written as a linear program by introducing the auxiliary variables $U_X \\in \\RR^{P_X \\times d}$ and $U_Y \\in \\RR^{P_Y \\times d}$\n\\eql{\n\\begin{aligned}\n& \\underset{\\Sig, U_X,U_Y}{\\text{min}}  & & \\dotp{ \\Cost{X}{Y}}{\\Sig}  + \\lambda_X \\dotp{U_X}{\\U}+ \\lambda_Y \\dotp{U_Y}{ \\U} \\\\\n& \\mbox{subject to} & &\n\\left\\{ \\begin{aligned}\n-U_X  & \\leq G_X ( \\Sig Y  - \\diag(\\Sig \\U) X)\\leq U_X, \\\\\n-U_Y & \\leq G_Y( \\Sig^* X - \\diag(\\Sig^* \\U) Y) \\leq U_Y, \\\\\n\\Sig & \\in \\Matr_\\kappa. \\\\\n\\end{aligned}\n\\right.\n\\end{aligned}\\label{eq-symm-TV}\n}\n\n%%%%\n\\paragraph{Numerical illustrations}\n\nIn Fig.~\\ref{exlk}, we can observe, on a synthetic example, the influence of the parameters $\\kappa$ and $(\\lambda_X, \\lambda_Y)$, from equation~\\eqref{eq-symm-reg-energy}. \n\n\\begin{figure*}\\label{figlambda}\n\\centering\n\\begin{tabular}{@{}|@{}c@{}|@{}c@{}|@{}}\n\\hline\n  \\includegraphics[width=.4\\linewidth]{../images/syntheticexamples/symmetricsyntheticmapping_l0_KX8_KY8_nn4} &  \n  \\includegraphics[width=.4\\linewidth]{../images/syntheticexamples/symmetricsyntheticmapping_l0001_KX8_KY8_nn4} \\\\\n\t {$\\la_X=\\la_Y=0$} & {$\\la_X =\\la_Y=0.001$}\\\\\\hline\n  \\includegraphics[width=.4\\linewidth]{../images/syntheticexamples/symmetricsyntheticmapping_l10_KX8_KY8_nn4} &\n  \\includegraphics[width=.4\\linewidth]{../images/graph} \\\\  \n  {$\\la_X =\\la_Y=10$} & Graphs \\\\\\hline \n\\end{tabular}\n\\caption{Given two sets of points $X$ (in blue) and $Y$ (in red), we show the points $Z=\\diag(\\Sigma \\U)^{-1} \\Sigma Y$ (in green), and the mappings $\\Sigma_{i,j}$ as line segments connecting $X_i$ and $Y_j$, which are dashed if $\\Sigma_{i,j} \\in ]0.1,1[$  and solid if $\\Sigma_{i,j}=1$. The results were obtained with the relaxed and regularized OT formulation, setting the parameters to $\\kappa=(0.1,8,0.1,8)$. Note the influence of a change in $\\la_X$ and $\\la_Y$ on the final result: with no regularization ($\\la_X=\\la_Y=0$) only few points in the data set are matched. The introduction of regularization ($\\la_X=\\la_Y=0.001$) spreads the connections among the clusters, while maintaining the cluster-to-cluster matching. For  a high value of $\\la_X=\\la_Y=10$, the regularization tends to match the clusters with similar shape with each other, where the shape is defined by the graph structure. The graphs $\\Gg_X$ and $\\Gg_Y$ are represented with the nodes on blue and red respectively, and the edges as solid lines.}\\label{exlk}\n\\end{figure*}\n\nFor $\\la_X=\\la_Y=0$ one obtains the relaxed symmetric OT solution, where the transport maps the points in $X$ to the closest point on $Y$, and vice versa. As we increase the values of $\\la_X$ and $\\la_Y$ to $0.001$, we can see how the regularization affects the mapping. Let us analyze $\\regul{G_X \\De_{X,Y}(\\Sig)} = \\|G_X \\diag(\\Sig \\U) X - G_X \\Sig Y\\|^2 $, for instance. The  term $G_X \\diag(\\Sig \\U) X$ is measuring the regularity of the weights $\\diag(\\Sig \\U)$ on $X$ and the consequence is that for $\\la_X=\\la_Y=0.001$ there are \nplenty of connections with low weight (there are few solid lines), while for $\\la_X=\\la_Y=0$ there are several mappings with $\\Sig_{i,j} = 1$ (solid lines). So, the regularization promotes a spreading of the matchings. \n\nThe minimum of $\\regul{G_X \\De_{X,Y}(\\Sig)}$ is reached when $G_X \\diag(\\Sig \\U) X = G_X \\Sig Y$, that is, when the graph structure of $X$ has the same shape as the graph structure of $\\Sig Y$, which both can be observed in the last column and row. For high values of $\\la_X=\\la_Y$ the matchings tend to link the clusters by their shape, that is, the big cluster on $X$ with the big cluster of $Y$, and similarly for the small clusters (note that the links with higher value are between the small clusters). \n\n\n", "meta": {"hexsha": "d274bbb21a738e8b6be76bc0002cb06b292c0f26", "size": 11255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/sections/sec-regularized.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-regularized.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-regularized.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": 79.8226950355, "max_line_length": 1033, "alphanum_fraction": 0.6880497557, "num_tokens": 3703, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8633915976709975, "lm_q1q2_score": 0.7738159001794613}}
{"text": "%\\documentclass[prc,preprint,superscriptaddress,showpacs,floatfix,widetables]{revtex4}\n\\documentclass[]{article}\n\\usepackage[dvips]{graphicx}\n\\usepackage{epsfig, color}\n\\usepackage{pst-plot}\n\\usepackage{bm}\n\\usepackage{hyperref,amssymb,amsmath,a4wide}\n\\usepackage{palatino}\n\\usepackage{dcolumn}% Align table columns on decimal point\n\\usepackage{graphicx}% Include figure files\n\\usepackage{listings}\n\\lstset{language=c++}\n\\lstset{alsolanguage=[90]Fortran}\n\\lstset{basicstyle=\\small}\n\\lstset{backgroundcolor=\\color{white}}\n\\lstset{frame=single}\n\\lstset{stringstyle=\\ttfamily}\n\\lstset{keywordstyle=\\color{red}\\bfseries}\n\\lstset{commentstyle=\\itshape\\color{blue}}\n\\lstset{showspaces=false}\n\\lstset{showstringspaces=false}\n\\lstset{showtabs=false}\n\\lstset{breaklines}\n\n\\fontfamily{phv}\n\\selectfont\n\n\\hypersetup{colorlinks=true, urlcolor=blue, linkcolor=black}\n\n\n\\begin{document}\n  \n  \\title{FYS 3150/4150: Possible solution of Project 1.}\n  \\author{Maxim Kartamyshev}\n  \\date{}\n\n  \n  \\maketitle\n  \n  Comments and critics are welcome and can be sent to \n  \\href{mailto::maximk@fys.uio.no}{maximk@fys.uio.no}.\n  \n  \n  \\section{Part a: Linear equation systems}\n  LU decomposition is one of the commonly used methods to solve systems of linear equation:\n  \\begin{equation}\n    \\left(\\begin{array}{ccccc}\n      a_{11}& a_{12}& a_{13} &\\dots &a_{1n}  \\\\\n      a_{21}& a_{22}& a_{23} &\\dots &a_{2n}  \\\\\n      \\dots &\\dots  &\\dots   &\\dots &\\dots   \\\\\n      a_{n1}& a_{n2}& a_{n3} &\\dots &a_{nn}  \\\\\n    \\end{array}\n    \\right)\\left(\\begin{array}{c}\n      x_1     \\\\\n      x_2     \\\\\n      \\dots   \\\\\n      x_n     \\\\\n    \\end{array} \\right)\n    =\n    \\left(\\begin{array}{c}\n      y_1     \\\\\n      y_2     \\\\\n      \\dots   \\\\\n      y_{n-1} \\\\\n    \\end{array} \\right)\\nonumber\n  \\end{equation}\n  which in compact form reads:\n  \\begin{equation}\n    {\\bf A}{\\vec x} = {\\vec y}  \\label{eq:lu_system}\n  \\end{equation}\n  The method consists of decomposing the original matrix {\\bf \\it A} into a product of lower-diagonal {\\bf \\it L}\n  and upper-diagonal {\\bf \\it U} matrices:\n  \\begin{equation}\n  A = LU \\nonumber\n  \\end{equation}\n  and then solving the linear system (\\ref{eq:lu_system}) in two steps:\n  \\begin{equation}\n    L{\\vec w} = {\\vec y} \\;\\;\\;\\;\\;\\;\\;\\;\\;\\;\\; U{\\vec x} = {\\vec w} \\label{eq:sys_diag}\n  \\end{equation} \n  Due to the form of {\\bf \\it L} and {\\bf \\it U} matrices, the two above equations can be easily solved via back substitution.\\\\\n  \\\\\n  In this project we use supplied library routines for LU-decomposition and back substitution to solve the following\n  linear system:\n  \\begin{equation}\n    \\left(\\begin{array}{ccc}\n     \\!\\!\\! -1 &  1& \\!\\!\\! -4 \\\\\n      2  &2 &0  \\\\\n      3  &3 &3  \\\\\n    \\end{array}\n    \\right)\\left(\\begin{array}{c}\n      x_1     \\\\\n      x_2     \\\\\n      x_3     \\\\\n    \\end{array} \\right)\n    =\n    \\left(\\begin{array}{c}\n      0     \\\\\n      1     \\\\\n      \\frac{1}{2} \\\\\n    \\end{array} \\right)\\nonumber\n  \\end{equation}\n  \\\\\n  which is satisfied with ${\\vec x} = [1.25, -0.75, -0.5]^T$. Numerical solution starts with first reading matrix {\\bf \\it A}\n  and vector ${\\vec y}$ from a file, LU-decomposition of the matrix with library routine {\\bf ludcmp}, and finally\n  obtaining the solution with help of routine {\\bf lubksb}. Routine {\\bf solve\\_part\\_a} in the attached program listing\n  contains implementation of this algorithm and is tested to produce the correct answer.\n\n\n\n  \\section{Part b: Tri-diagonal linear systems}\n  LU-decomposition is a general method and can be used for any non-singular matrix {\\bf \\it A}. \n  There also exist less general methods, applicable only to the matrices of a particular form, but\n  allowing for simple and fast computational algorithms.\\\\\n  \\\\\n  In this part of the project we have to solve a linear system governed by the so-called tri-diagonal\n  matrix:\n  \\\\\n  \\begin{equation}\n    \\left(\\begin{array}{ccccccc}\n      b_1   & c_1  & 0    &\\dots   &0       &0       &0       \\\\\n      a_2   & b_2  & c_2  &\\dots   &0       &0       &0       \\\\\n      \\dots &\\dots &\\dots &\\dots   &\\dots   &\\dots   &\\dots   \\\\\n      0     &0     &0     &\\dots   &a_{n-1} &b_{n-1} &c_{n-1} \\\\\n      0     &0     &0     &\\dots   &0       &a_n     &b_n     \\\\\n    \\end{array}\n    \\right)\\left(\\begin{array}{c}\n      x_1     \\\\\n      x_2     \\\\\n      \\dots   \\\\\n      x_{n-1} \\\\\n      x_n     \\\\\n    \\end{array} \\right)\n    =\n    \\left(\\begin{array}{c}\n      y_1     \\\\\n      y_2     \\\\\n      \\dots   \\\\\n      y_{n-1} \\\\\n      y_{n-1} \\\\\n    \\end{array} \\right) \\nonumber\n  \\end{equation}\\\\\n  \\\\\n  Instead of using LU-decomposition to solve this problem, a much easier method, accounting\n  for the specific form of matrix {\\bf \\it A}, can be employed:\n  \\\\\n  \\begin{lstlisting}\n    // solve tri-diagonal system\n    // forward substitution\n    btemp = b[0]; y[0] = f[0] / btemp;\n    for(i = 1; i < n; i++) {\n      temp[i] = c[i-1] / btemp;\n      btemp = b[i] - a[i] * temp[i];\n      y[i] = (f[i] - a[i] * y[i-1]) / btemp;\n    }\n    // back substitution\n    for(i = n-2; i >= 0; i--) {\n      y[i] = y[i] - temp[i+1] * y[i+1];\n    }\n  \\end{lstlisting}\n  \\ \\\\\n  The routine {\\bf solve\\_part\\_b} in the attached program listing contains implementation of the above algorithm.\n  Solution of the $100\\times 100$ tri-diagonal system with $a_i = c_i = - 0.01$, $b_i = 0.02$ and $f_i = 0.1*(i+1)$,\n  $i=\\overline{0,n-1}$, is displayed on Figure \\ref{fig:tridiag}. LU-decomposition method has been used to verify\n  the tri-diagonal solver.\\\\\n  \\begin{figure}[htbp]\n    \\centering\n    \\epsfig{file=tri.eps, width=\\textwidth}\n    \\caption{Solution of the 100x100 tri-diagonal system from the project text.}\n    \\label{fig:tridiag}\n  \\end{figure}\n  \\\\\n  Amount of operations required to solve the $n \\times n$ tri-diagonal systems goes as $O(n), n \\gg 1$. This stems\n  from the fact that implementation of both forward and back substitution in the algorithm require each only\n  one (non-nested) loop with index $i$ changing from 0 to $n-1$. Compared with $O(n^3)$ operations in LU-decomposition\n  and Gauss elimination, the algorithm for solving tri-diagonal system provides obvious computational advantage,\n  but its applicability is limited to the tri-diagonal matrices only.\\\\\n  \\\\\n  It is worth noticing that once one has performed the LU-decomposition of a general non-singular matrix, obtaining\n  solution of corresponding linear system requires only $O(n)$ operations (back-substitution). It means that we\n  can use the LU-decomposed form of the original matrix to solve the whole class of linear system having the same\n  matrix {\\bf \\it A} and different vectors ${\\vec y_i}$.\\\\\n  \\\\\n  Finally, let's compare times used by the tri-diagonal solver and LU-decomposition method. UNIX function 'time' is used\n  for precise measurements of time intervals. The Table {\\ref{tab:timing}} below summarizes the timing results obtained\n  while solving tri-diagonal systems of different dimensionalities $n$.\n  \\begin{table}[hbp]\n    \\center\n    \\caption{Time usage, s}\n    \\begin{tabular}{ccc}\n      \\hline\n      n & Tri-diagonal solver & LU-decomposition \\\\\n      \\hline\n      \\\\\n      1000 & $4^{-3}$  &  $32*10^{-3}$  \\\\\n      2000 & $4^{-3}$  &  $114*10^{-3}$ \\\\\n      4000 & $5^{-3}$  &  $442*10^{-3}$  \\\\\n      \\\\\n      \\hline\n    \\end{tabular}\n    \\label{tab:timing}\n  \\end{table}\n  \\\\\n  The timing results for the tri-diagonal solver show almost no dependence on the dimensionality of the problem.\n  This simply means that the time used by tri-diagonal solver is rather small compared to the time spent in other\n  parts of the program. One can easily see that the LU-decomposition method uses noticeably longer time to\n  solve exactly the same linear system.\n  \n\\end{document}\n", "meta": {"hexsha": "8a683ddf278c9def4471a7dd96e58cef060a4a23", "size": 7723, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/Projects/2015/Project1/FormerYears/report.tex", "max_stars_repo_name": "kimrojas/ComputationalPhysicsMSU", "max_stars_repo_head_hexsha": "a47cfc18b3ad6adb23045b3f49fab18c0333f556", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 220, "max_stars_repo_stars_event_min_datetime": "2016-08-25T09:18:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T14:09:16.000Z", "max_issues_repo_path": "doc/Projects/2015/Project1/FormerYears/report.tex", "max_issues_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_issues_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-04T12:55:10.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-04T12:55:10.000Z", "max_forks_repo_path": "doc/Projects/2015/Project1/FormerYears/report.tex", "max_forks_repo_name": "dnhdang94/ComputationalPhysicsMSU", "max_forks_repo_head_hexsha": "16990c74cf06eb5b933982137f0536d669567259", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 136, "max_forks_repo_forks_event_min_datetime": "2016-08-25T09:04:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T09:54:21.000Z", "avg_line_length": 36.95215311, "max_line_length": 128, "alphanum_fraction": 0.6351158876, "num_tokens": 2414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8887588038050467, "lm_q1q2_score": 0.7737509779146392}}
{"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\\section{Solving for $N$}\n\nSubstituting the values for $\\sigma$, $d$ and $E_{in}$, and putting the\nfollowing equation in terms of $N$:\n\n\n\\begin{align*}\nE_\\mathcal{D}[E_{in}(w_{lin})] &= 0.1^2 \\left(1 - \\frac{8+1}{N} \\right) \\\\\n0.008 &\\leq 0.01 \\left(1 - \\frac{9}{N} \\right) \\\\\n0.008 &\\leq 0.01 - \\frac{0.09}{N} \\\\\n-0.002 &\\leq - \\frac{0.09}{N} \\\\\nN &\\geq 45\n\\end{align*}\n\nSince we need to pick the least number of examples $N$ among the alternatives\nthat also satisfy this inequality, we'd have to choose $N=100$.\n\n\\end{document}\n", "meta": {"hexsha": "2958788d6e45a0ccf385b710444c012c2978efc6", "size": 706, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q01.tex", "max_stars_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_stars_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 98, "max_stars_repo_stars_event_min_datetime": "2015-04-27T06:55:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-05T06:09:19.000Z", "max_issues_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q01.tex", "max_issues_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_issues_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2016-05-14T19:33:33.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-12T13:07:41.000Z", "max_forks_repo_path": "Homework_5/Octave/by_danielfmt/week-05/math/q01.tex", "max_forks_repo_name": "freeernest/edX-Learning-From-Data-Solutions", "max_forks_repo_head_hexsha": "5cbcf0885b5fdb00c3658d230fc7bb7e20b5cf44", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 56, "max_forks_repo_forks_event_min_datetime": "2015-01-10T08:18:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-28T08:46:22.000Z", "avg_line_length": 22.7741935484, "max_line_length": 77, "alphanum_fraction": 0.671388102, "num_tokens": 263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587817066391, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7737509735956869}}
{"text": "\\chapter{Two Fibonaccis}\n\n$fib(n):$\n\\begin{algorithmic}\n\\IF { $ n=0 $ or $ n=1 $ }\n\\RETURN $n$\n\\ELSE\n\\RETURN $fib(n-1) + fib(n-2)$\n\\ENDIF\n\\end{algorithmic}\n\nWe can state a recurrence for this algorithm:\n\n\\begin{align*}\nT(n) \n&= T(n-1) + T(n-2) + O(1) \\\\\n&\\geq fib(n-1) + fib(n-2) \\\\\n&= fib(n)\n\\end{align*}\n\n$fib2(n):$\n\\begin{algorithmic}\n\\IF { $ n = 0 $ }\n\\RETURN 0\n\\ENDIF\n\\STATE create array $f[0 .. n]$\n\\STATE $f[0] \\leftarrow 0, f[1] \\leftarrow 1$\n\\FOR { $ i \\leftarrow 2$ to $n$ }\n\\STATE $f[i] \\leftarrow f[i-1] + f[i-2]$\n\\ENDFOR\n\\RETURN $f[n]$\n\\end{algorithmic}\n\nAddition of two numbers in the preceding algorithm takes constant time\nuntil the values exceed the maximum value that can be stored in a\nword.  After which, we need to consider how values of arbitrary length\nare added.\n", "meta": {"hexsha": "d8d989a28693b97a6cfecf66ccc154b5d88335e9", "size": 787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fibonacci.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": "fibonacci.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": "fibonacci.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": 20.7105263158, "max_line_length": 70, "alphanum_fraction": 0.6416772554, "num_tokens": 297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088064979619, "lm_q2_score": 0.8333246015211008, "lm_q1q2_score": 0.7736658987235948}}
{"text": "\\subsection{SVD as a function composition}\n\nThe first thing to remember, is that matrices are the operational\nrepresentation of an special type of function between vector\nspaces\\footnote{The reader is invited to review any Linear Algebra\n  textbook, to recall the definition of a vector space}\ncalled linear transformations (also called linear mappings or linear\n  functions). We say is an operational representation, in the \nsense that they provide an explicit recipe to apply the\nfunction. Furthermore, the functions they represent are\nspecial, as they have the nice property of preserve algebraic\nstructure across domain and codomains. Such \nproperty can be summarized as: \\\\\n\n\\[\nf(\\alpha x + \\beta y) = \\alpha f(x) + \\beta f(y)\n\\]\n\\hfill\n\nWhere the addition and products mentioned above, are the vector\naddition and multiplication by an scalar; defined for vector\nspaces. For the specific case of this work, where we restrict\nour attention to real matrices, we can tell that they do represent\nfunctions $f: \\R{n} \\fromto \\R{m}$. \\\\\n\nIn this context of linear functions, the matrix multiplication is the\noperational representation of the composition of the associated\nfunctions. A matrix factorization is in essence, a way to understand\nwhat the underlying function does; the whole product can be seen as\nserial algorithm, where each matrix represents on particular step or\ntransformation. Each of the four matrices that appear on the SVD\nfactorization, has its own function as follows:  \n\n\\begin{itemize}\n\\item $A$ is a function $\\func{F_A}: \\R{n} \\fromto \\R{m}$\n\\item $V$ is a function $\\func{F_V}: \\R{n} \\fromto \\R{n}$\n\\item Same goes for  \\trans{V}, which is $\\func{F_{\\trans{V}}}: \\R{n} \\fromto \\R{n}$\n\\item $\\Sigma$ is a function $\\func{F_\\Sigma}: \\R{n} \\fromto \\R{m}$\n\\item $U$ is a function $\\func{F_U}: \\R{m} \\fromto \\R{m}$\n\\end{itemize}\n\\hfill\n\nThus, in the context of function compositions, the SVD factorization\ncan be restated as: \\\\\n\n\\[\n\\func{F_A}(\\vec{x}) = \\func{F_U}(\\func{F_\\Sigma}(\\func{F_{\\trans{V}}}(\\vec{x})))\n\\]\n\\hfill\n", "meta": {"hexsha": "c962ff8cdf77a4b14572b41c824aed04498e516b", "size": 2045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "svd-intuit-fcomp.tex", "max_stars_repo_name": "rzavalet/svd-lsi-project-master", "max_stars_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "svd-intuit-fcomp.tex", "max_issues_repo_name": "rzavalet/svd-lsi-project-master", "max_issues_repo_head_hexsha": "3db2aed30f124e79d60dd7aa6c012ddd05bdce7f", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "svd-intuit-fcomp.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": 40.9, "max_line_length": 84, "alphanum_fraction": 0.7452322738, "num_tokens": 557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087985746093, "lm_q2_score": 0.8333246035907933, "lm_q1q2_score": 0.773665894042391}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Devil's chessboard}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Devil's chessboard}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Devil's chessboard}\n\n\\newthought{Hamming codes} are used to solve the problem\\footnote{\\bibentry{devils_chessboard}} in this note.\n\nYou, your friend, and the Devil play a game. You and the Devil are in the room with a chess board with $64$ tokens on it, one on each square. Meanwhile, your friend is outside of the room. The token can either be on an up position or a down position, and the difference in position is distinguishable to the eye. The Devil mixes up the positions (up or down) of the tokens on the board and chooses one of the  squares and calls it the magic square. Next, you may choose one token on a square and flip its position. Then, your friend comes in and must guess what the magic square was by looking on the squares on the board.\\footnote{\nDetails:\n\\\\\n\\begin{enumerate}\n\\item You \\textbf{may} flip a token. As in, you are not forced to flip a token; you may choose to not flip a token.\n\n\\item You can't just tell your friend what square it is. Or point to it. Or text him it. Or... you get the point.\n\n\\item Your friend knows the strategy as well (you tell him beforehand).\n\n\\item If you don't get it right, the Devil takes your soul. High stakes.\n\\end{enumerate}}\n\n\\vspace{10 mm}\n\\begin{problem}\nShow that there is a winning strategy such that your friend can always know what square the magic square is.\n\\end{problem}\n\n\\begin{marginfigure}[0.0in]\n\\includegraphics[scale=0.5]{Richard_Hamming.jpg}\n\\end{marginfigure}\n\nThere might be solutions that exploit the chessboard geometry with its black and white fields. We will ignore the chessboard angle though and use this problem as an excuse to dive into the topic of linear codes. We will solve the problem by treating the token information as a 64-bit word and we will devise a winning strategy that involves a Hamming\\footnote{Richard Hamming was one of the founders of modern coding theory. \\url{http://en.wikipedia.org/wiki/Richard_Hamming}} code (a type of perfect linear code).\n\nBut first lets introduce linear codes\\index{linear code}. We operate in the field $\\mathbb{F}_q$ of integers modulo a prime $q$. \n\n\\begin{defn}\\label{linearCodeDef}\nA \\textbf{linear code} $C$ of words of length $n$ is a subspace of the vector space $\\mathbb{F}^n_q$. Let $\\dim C = k$, then we say that $C$ is a $[n, k]_q$ linear code.\n\\end{defn}\n\nGiven a basis $\\{\\bm{c_1}, \\bm{c_2}, \\ldots, \\bm{c_k}\\}$ of $C$, we can build a matrix $G \\in \\mathbb{F}_q^{k \\times n}$ using the $\\bm{c_i}$ basis vectors as rows. Then $C$ is the row space of $G$ and $G$ is called a \\textbf{generator matrix}\\index{generator matrix} of $C$. We have\\footnote{We treat vectors as row vectors in this section. That means that $\\bm{x} \\in \\mathbb{F}_q^k$ is a matrix $\\mathbb{F}_q^{1 \\times k}$.}\n\n$$\nC = \\{\\bm{x} G: \\bm{x} \\in \\mathbb{F}_q^k\\},\n$$\n\n\\noindent so a code $C$ is made from all linear combinations of the row vectors of its generator matrix.\n\nLet $G'$ be the row reduced echelon form of $G$. By definition $G$ has full row rank, so $G'$ has only nonzero rows. If \n$\nG' = \\left[\\begin{smallmatrix}\nI_k & | & A_{k \\times (n - k)}\n\\end{smallmatrix}\\right]\n$ \nfor identity matrix $I_k$ and some matrix $A$ then the generator matrix $G'$ is in \\textbf{standard form}\\footnote{Not every generator matrix can be row reduced to the standard form. For example \n$$\n\\begin{bmatrix}\n1 & 1 & 0 & 0 \\\\\n0 & 0 & 1 & 1 \n\\end{bmatrix}\n$$\ncannot.}. Row operations preserve the row space, so $G'$ also generates $C$.\n\n\\begin{defn}\\label{parityCheckDef}\nGiven a $[n, k]_q$ linear code $C$, matrix $H \\in \\mathbb{F}_q^{(n-k) \\times n}$ is a \\textbf{parity check matrix}\\index{parity check matrix} for $C$, if $C = nullspace(H)=\\{\\bm{c} \\in \\mathbb{F}_q^n: H \\bm{c}^T = 0\\}$.\n\\end{defn}\n\n\\begin{thm}\\label{generatorParityCheckRel}\nGiven a $[n, k]_q$ linear code $C$ and a generator matrix $\nG = \\left[\\begin{smallmatrix}\nI_k & | & A_{k \\times (n - k)}\n\\end{smallmatrix}\\right]\n$ for $C$ in standard form, then $\nH = \\left[\\begin{smallmatrix}\n-A^T_{(n - k) \\times k} & | & I_{n - k}\n\\end{smallmatrix}\\right]\n$ is a parity check matrix\\footnote{With $G$ in standard form this theorem let's us construct a parity check matrix very easily. Also worth noting that in standard form we generate a code word from a message $\\bm{x} \\in \\mathbb{F}_q^k$ by appending $n - k$ parity check bits to the message with $\\bm{x} G$. We check if the transmitted and received word $\\bm{y} \\in \\mathbb{F}_q^n$ is a valid code word by verifying $H \\bm{y}^T = 0$. If true then the first k positions of $\\bm{y}$ are the original message $\\bm{x}$.} for $C$.\n\\end{thm}\n\n\\begin{proof}\n\nLet $\\bm{c} \\in C$ be a code word from $C$. Then there exists an $\\bm{x} \\in \\mathbb{F}_q^k$ such that $\\bm{c} = \\bm{x} G$.\nWe have\n\n\\begin{align*}\n H \\bm{c}^T &= H (\\bm{x} G)^T \\\\\n        &= \\left[ -A^T_{(n - k) \\times k} | I_{n - k} \\right] \\left(\\bm{x} \\left[ I_k | A_{k \\times (n - k)} \\right]\\right)^T \\\\\n        &=  \\left[ -A^T_{(n - k) \\times k} | I_{n - k} \\right] \\left[ \\begin{array}{c}\n                                                                           I_k \\\\ \\hline\n                                                                           A^T_{(n - k) \\times k}\n                                                                       \\end{array}  \\right] \\bm{x}^T \\\\\n        &= (-A^T + A^T) \\bm{x}^T \\\\\n        &= 0\n\\end{align*}\n\nThis means that $C \\subseteq nullspace(H)$. We have $\\dim C = k$ and \n$$\n\\dim nullspace(H) = n - rank(H) = n - n + k = k,\n$$\nso $C = nullspace(H)$ and $H$ is a parity check matrix for $C$.\n\n\\end{proof}\n\nWhat can we do if the generator matrix is not in standard form? Swapping columns in the generator matrix does not preserve the row space, so the linear code generated with the modified matrix is clearly not the same as the original code, but it is an equivalent code\\footnote{A $[n, k_1]_q$ linear code $C_1$ is equivalent to a $[n, k_2]_q$ linear code $C_2$ if there is a permutation $\\pi \\in S_n$ such that when $\\pi$ is applied to the coordinate indices of all the code words from $C_1$, it produces all the code words from $C_2$. Equivalent linear codes have the same dimension $k_1=k_2$.}. \n\n\\begin{defn}\\label{hammingDistDef}\nThe \\textbf{Hamming distance}\\index{Hamming distance} $d(\\bm{x}, \\bm{y})$ between two vectors $\\bm{x}, \\bm{y} \\in \\mathbb{F}_q^n$ is the number of positions in which the vectors differ. With $\\bm{x} = x_1 x_2 \\ldots x_n$ and $\\bm{y} = y_1 y_2 \\ldots y_n$ we have\n$$\nd(\\bm{x}, \\bm{y}) = |\\{i : 1 \\leq i \\leq n : x_i \\neq y_i\\}|\n$$\nThe \\textbf{Hamming weight}\\index{Hamming weight} $w(\\bm{x})$ is the number of positions that differ from zero:\n$$\nw(\\bm{x}) = |\\{i : 1 \\leq i \\leq n : x_i \\neq 0\\}| = d(\\bm{x}, \\bm{0})\n$$\n\\end{defn}\n\nWe will use the following properties of Hamming distances:\n\n\\marginnote{\\textit{Proof} of Lemma \\ref{hammingtriangle} \\\\\nThe first three properties are obvious from the definition of Hamming distance. For the last property let $i$ be an index where $\\bm{x}$ and $\\bm{y}$ differ, so $x_i \\neq y_i$. For vector $\\bm{z}$ we can have the following cases for position $i$:\n\\begin{align*}\n& z_i = x_i \\Rightarrow z_i \\neq y_i \\\\\n& z_i = y_i \\Rightarrow z_i \\neq x_i \\\\\n& z_i \\neq x_i \\land z_i \\neq y_i\n\\end{align*}\nIn each of these cases the contribution of $z_i$ to $d(\\bm{x}, \\bm{z}) + d(\\bm{z}, \\bm{y})$ is at least one, whereas on the left side position $i$ contributes one to $d(\\bm{x}, \\bm{y})$. A similar analysis holds for indices $i$ where $x_i=y_i$.\n\\qed}\n\n\\begin{lem}\\label{hammingtriangle}\n\\begin{align*}\n&\\forall \\bm{x}, \\bm{y} \\in \\mathbb{F}_q^n : d(\\bm{x}, \\bm{x}) \\geq 0 \\\\\n&\\forall \\bm{x}, \\bm{y} \\in \\mathbb{F}_q^n : d(\\bm{x}, \\bm{y}) = 0 \\Leftrightarrow x = y \\\\\n&\\forall \\bm{x}, \\bm{y} \\in \\mathbb{F}_q^n : d(\\bm{x}, \\bm{y}) = d(\\bm{y}, \\bm{x}) \\\\\n&\\forall \\bm{x}, \\bm{y}, \\bm{z} \\in \\mathbb{F}_q^n : d(\\bm{x}, \\bm{y}) \\leq d(\\bm{x}, \\bm{z}) + d(\\bm{z}, \\bm{y})\n\\end{align*}\n\\end{lem}\n\n\\begin{defn}\\label{hammingDistCodeDef}\nThe \\textbf{minimum distance} of $C$ is:\n$$\nd(C) = \\min \\{d(\\bm{x}, \\bm{x'}) : \\bm{x}, \\bm{x'} \\in C \\land \\bm{x} \\neq \\bm{x'} \\} = \\min \\{w(\\bm{x}) : \\bm{x} \\in C \\}\n$$\n\\end{defn}\n\nThe minimum distance\\index{minimum distance} is important enough that we add it to the characteristic notation of a linear code: $[n, k, d]_q$ is a linear  code over field $\\mathbb{F}_q$ with bit strings of length $n$, code dimension $k$ and minimum distance between code words $d$.\n\nThe next lemma establishes a connection between the minimum distance of a linear code and one of its parity check matrix.\n\n\\begin{lem}\\label{minCodeParityCheckRel}\nThe minimum distance of a code $C$ equals the minimum number of linearly dependent columns in one of its parity check matrices. \n\\end{lem}\n\n\\marginnote{\\textit{Proof} of Lemma \\ref{minCodeParityCheckRel} \\\\\nLet $H$ be a parity check matrix of $[n, k, d]_q$ linear code $C$. There must be a code word $\\bm{c}$ with $w(\\bm{c}) = d$.\n$\\bm{c}$ belongs to the nullspace of $H$, so\n\n$$\nH \\bm{c}^T = \\bm{0}\n$$\n\nBut $H \\bm{c}^T$ is a linear combination of column vectors of $H$, with $d$  nonzero coefficients, so the column vectors in this linear combination are linearly dependent. \n\\qed}\n\nSo far we have worked with fields $\\mathbb{F}_q$ of any prime $q$. Now we switch to the binary world $q=2$ and $\\mathbb{F}_2$. Our vectors are bit strings. We transmit these bit strings over a binary symmetric channel. \n\n\\begin{defn}\\label{symChanDef}\nIn a \\textbf{binary symmetric channel}\\index{binary symmetric channel} each bit sent has the same probability $p < \\frac{1}{2}$ of being received incorrectly.\n\\end{defn}\n\nWe send a code word $\\bm{x} \\in C$ from a $[n, k]_2$ linear code $C$ over a binary symmetric channel and receive a bit string $\\bm{y}$. If there were no transmission errors, then $y=x$. If there were errors, we want to find the most likely code word $\\bm{x}$ that was transmitted given the errors in $\\bm{y}$.\n\nOne decoding strategy\\footnote{Finding an appropriate code word for the transmitted bit string is called \\textit{decoding}. Finding the most likely code word is called \\textit{maximum likelihood decoding}.} would be to choose a code word $\\bm{x}$ with minimum Hamming distance over all code words from $C$ to received bit string $\\bm{y}$. This type of decoding is called \\textit{nearest neighbor decoding}. The chosen $\\bm{x}$ is not always unique.\n\n\\begin{thm}\\label{nnDmaximumLike}\nIn a binary symmetric channel with error probability $p < \\frac{1}{2}$ the nearest neighbor decoding is a maximum likelihood decoding.\n\\end{thm}\n\n\\begin{proof}\nGiven a bit string $\\bm{y} \\in \\mathbb{F}_2^n$ received through the channel, let $P_{\\bm{y}}(\\bm{x})$ be the probability that the code word $\\bm{x}$ was sent when $\\bm{y}$ was received. Because the channel is a binary symmetric channel, we have\n\n$$\nP_{\\bm{y}}(\\bm{x}) = p^{d(\\bm{x}, \\bm{y})} (1 - p)^{n - d(\\bm{x}, \\bm{y})}\n$$\n\nConsider two code words $\\bm{x}$ and $\\bm{x'}$ such that $d(\\bm{x}, \\bm{y}) \\leq d(\\bm{x'}, \\bm{y})$. Because $p < \\frac{1}{2}$, we then have $P_{\\bm{y}}(\\bm{x}) \\geq P_{\\bm{y}}(\\bm{x'})$. It follows that\n$$\n\\max_{\\bm{x} \\in C} P_{\\bm{y}}(\\bm{x}) = \\min_{\\bm{x} \\in C} d(\\bm{x}, \\bm{y})\n$$\nso the likeliest code word is the nearest neighbor to $\\bm{y}$.\n\\end{proof}\n\nFor the rest of this section we use nearest neighbor decoding. We want to know if we can detect and possibly correct a transmission with errors. Let's define clearly what we mean by that. A transmission is a pair $(\\bm{x}, \\bm{y}) \\in C \\times \\mathbb{F}_2^n$, where a code word $\\bm{x}$ was sent and a bit strings $\\bm{y}$ was received. It has $d(\\bm{x}, \\bm{y})$ transmission errors. The nearest neighbor decoding $nnd(\\bm{y})$ finds a code word (not necessarily unique) closest to $\\bm{y}$. The following holds by definition:\n\n$$\nd(\\bm{y}, nnd(\\bm{y})) = \\min_{\\bm{c} \\in C} d(\\bm{y}, \\bm{c})\n$$\n\nIf no errors occurred in the transmission, then $\\bm{x} = \\bm{y}$ and also $d(\\bm{x}, \\bm{y}) = 0$ and $nnd(\\bm{y}) = \\bm{x}$. If errors in the transmission occurred we want to:\n\n\\begin{enumerate}[label=\\textbf{E.\\arabic*}]\n\\item \\label{transmissionErrorRecogOne} detect that errors happened, i.e. establish that $\\bm{y} \\notin C$.\n\\item \\label{transmissionErrorRecogTwo} correct the errors, i.e. establish $nnd(\\bm{y}) = \\bm{x}$.\n\\end{enumerate}\n\nThe next theorem describes the conditions for \\ref{transmissionErrorRecogOne}.\n\n\\begin{thm}\\label{linearCodeDetectErrors}\nGiven a $[n, k, d]_2$ linear binary code $C$, we can detect that any transmission with up to $e$ errors was erroneous if and only if $d > e$.\n\\end{thm}\n\n\\begin{proof}\n\n\\noindent$(\\Rightarrow)$ Let $(\\bm{x}, \\bm{y})$ be a transmission with $d(\\bm{x}, \\bm{y}) \\leq e < d$ errors. Assume $\\bm{y} \\in C$. Then $d(\\bm{x}, \\bm{y}) \\leq e < d$ is a contradiction to $d$ being the minimal distance of $C$. It follows that $\\bm{y} \\notin C$.\n\n\\noindent$(\\Leftarrow)$ We can detect that any transmission with up to $e$ errors was erroneous. Assume $d \\leq e$. Then there exist two code words $\\bm{x} \\neq \\bm{x'}$ such that $d(\\bm{x}, \\bm{x'}) \\leq e$. Now consider transmission $(\\bm{x}, \\bm{x'})$. It's impossible to detect that it had errors because $\\bm{x'}$ is a code word. This is a contradiction with the fact that we can detect that any transmission with up to $e$ errors was erroneous. So $d > e$.\n\\end{proof}\n\n\\begin{marginfigure}[0.5in]\n\\includegraphics[scale=0.3]{hammingSpheres.pdf}\n\\caption{A Hamming sphere for code word $\\bm{c}$ with radius  $e$ is the set \\\\\n$\\{\\bm{x}: d(\\bm{x}, \\bm{c}) \\leq e\\}$. In this figure the spheres don't overlap, so vectors (blue dots) that fall within a sphere can be error-corrected to code words (red dots).}\n\\label{fig:hammingSpheres}\n\\end{marginfigure}\n\nFor \\ref{transmissionErrorRecogTwo} we have this theorem:\n\n\\begin{thm}\\label{linearCodeCorrectErrors}\nGiven a $[n, k, d]_2$ linear binary code $C$, we can correct any transmission with up to $e$ errors if $d > 2 e$.\n\\end{thm}\n\n\\begin{proof}\nLet $(\\bm{x}, \\bm{y})$ be a transmission with $d(\\bm{x}, \\bm{y}) \\leq e$ errors and $d > 2 e$. Assume $nnd(\\bm{y}) \\neq \\bm{x}$. Then $d(\\bm{y}, nnd(\\bm{y})) \\leq e$ (otherwise $\\bm{x}$ would be closer than $nnd(\\bm{y})$ to $\\bm{y}$). We have\n$$\nd(\\bm{x}, nnd(\\bm{y})) \\leq d(\\bm{x}, \\bm{y}) + d(\\bm{y}, nnd(\\bm{y})) \\leq e + e = 2 e\n$$\nwhich contradicts $d > 2 e$. So $nnd(\\bm{y}) = \\bm{x}$.\n\n\\end{proof}\n\nTheorems \\ref{linearCodeDetectErrors} and \\ref{linearCodeCorrectErrors} tell us that a large minimum distance $d(C)$ allows us to detect and correct more errors. But a large minimum distance between code words also limits the number of code words. The following theorem puts an upper bound on the number of code words given a minimum distance.\n\n\\begin{thm}\\label{hammingBound}\nGiven a $[n, k, 2 t + 1]_2$ linear binary code $C$, we have\n$$\n|C| \\leq \\frac{2^n}{\\sum_{i = 0}^t \\binom{n}{i}}\n$$\nThis upper bound is called \\textbf{Hamming bound}\\index{Hamming bound}.\n\\end{thm}\n\n\\begin{proof}\n\nGiven a bit string $\\bm{x}$ and an integer $i \\leq n$, there are $\\binom{n}{i}$ ways to choose the $i$ positions at which $\\bm{x}$ and and another bit string $\\bm{y}$ differ. So there are $\\binom{n}{i}$ bit strings $\\bm{y}$ with $d(\\bm{x}, \\bm{y}) = i$. This means there are \n$$\n\\sum_{i = 0}^t \\binom{n}{i}\n$$\nbit strings $\\bm{y}$ with $d(\\bm{x}, \\bm{y}) \\leq t$.\n\nOn the other hand, a bit string $\\bm{y}$ with $d(\\bm{y}, \\bm{x}) \\leq t$ to a code word $\\bm{x}$ cannot have the same  \n$d(\\bm{y}, \\bm{x'}) \\leq t$ to a different code word $\\bm{x'}$ because then\n\n$$\nd(\\bm{x}, \\bm{x'}) \\leq d(\\bm{x}, \\bm{y}) + d(\\bm{y}, \\bm{x'}) \\leq t + t \\leq 2 t\n$$\n\nwhich is a contradiction to $d(C) = 2 t + 1$.\n\nSo for each code word, we have at most $\\sum_{i = 0}^t \\binom{n}{i}$ bit strings with Hamming distance $\\leq t$ and we cannot have the same bit strings near two different code words. We have $2^n$ bit strings, so\n\n$$\n|C| \\sum_{i = 0}^t \\binom{n}{i} \\leq 2^n\n$$\n\n\\end{proof}\n\nA binary linear code that achieves equality in the Hamming bound \\ref{hammingBound} is called a \\textbf{perfect code}\\index{perfect code}.\n\nWe are now ready to define Hamming codes\\index{Hamming code}.\n\n\\begin{defn}\\label{hammingCode}\nA Hamming code $\\mathfrak{H}_r$ of order $r$ (where $r$ is a positive integer) is a binary linear code with the parity check matrix\nwith columns that are all the $2^r - 1$ nonzero bit strings of length $r$.\n\\end{defn}\n\nChanging the order of the columns in the parity check matrix produces equivalent codes with the same minimum distance. So for easier analysis we now consider Hamming codes with parity check matrix in standard form, ie the last $r$ columns form the identity matrix $I_r$, so $\nH = \\left[\\begin{smallmatrix}\nA_{r \\times (n - r)} & | & I_{r}\n\\end{smallmatrix}\\right]\n$, with $n = 2^r - 1$. From theorem \\ref{generatorParityCheckRel} we then know the generator matrix is $\nG = \\left[\\begin{smallmatrix}\nI_{n - r} & | & -A_{(n - r) \\times r}^T\n\\end{smallmatrix}\\right] = \\left[\\begin{smallmatrix}\nI_{n - r} & | & A_{(n - r) \\times r}^T\n\\end{smallmatrix}\\right]\n$, since we operate in $\\mathbb{F}_2$. We can see that $\\dim \\mathfrak{H}_r = n - r$. What is the minimum distance of $\\mathfrak{H}_r$? All columns are nonzero and distinct, so no two columns are linearly dependent\\footnote{Again, this is in $\\mathbb{F}_2$. The sum of two distinct columns is always nonzero, so a linear combination that is zero has to have coefficients zero, hence linearly independent.}. But consider the linear combination of the three columns \n$$\n[1, 1, 0, \\ldots, 0]^T + [1, 0, 0, \\ldots, 0]^T + [0, 1, 0, \\ldots, 0]^T = \\bm{0}^T\n$$\nThey are linearly dependent. From lemma \\ref{minCodeParityCheckRel} it follows that $d(\\mathfrak{H}_r) = 3$, so $\\mathfrak{H}_r$ is a $[2^r - 1, 2^r - 1 - r, 3]_2$ binary linear code. According to theorem \\ref{linearCodeCorrectErrors} it can correct transmissions with one error. \n\n\\begin{thm}\\label{hammingPerfect}\n$\\mathfrak{H}_r$ is a perfect code.\n\\end{thm}\n\n\\begin{proof}\n\nThe generator matrix has full row rank, so we need all linear combinations of the rows to get all the code words. This are binary words, so there are $2^{n - r}$ distinct linear combinations. It means $|\\mathfrak{H}_r| = 2^{n - r}$.\n\nInserting into formula of theorem \\ref{hammingBound}, we get\\footnote{With $t = 1$, because $d(\\mathfrak{H}_r) = 3$.}\n\n$$\n2^{n - r} \\sum_{i = 0}^1 \\binom{n}{i} = 2^{n - r} (1 + n) = 2^{n - r} (1 + 2^r - 1) = 2^{n - r} 2^r = 2^n\n$$\n\n\\end{proof}\n\nThis concludes our dive into linear codes and Hamming codes. Let's return to our problem and solve it using Hamming codes. The state of the chessboard is a binary word of length $64$. We use $r = 6$, so Hamming code $\\mathfrak{H}_6$. The word length is $2^6 - 1 = 63$. We agree that the devil choosing bit $64$ is a special case which we handle later. For now imagine the chessboard as a $63$-bit binary word and the devil only choosing a magic field between $1$ and $63$.\n\nThe winning strategy can be summarized as follows: the first player needs to modify the $63$-bit word (by flipping at most one bit) in such a way that the magic field is the one bit error of a code word in $\\mathfrak{H}_6$. Then the second player only has to come in, decode the modified chessboard and point to the corrected error which is the same magic field\\footnote{Decoding\\label{decodingSideNote} is done as follows: $\\bm{x}$ needs to be decoded. It is one bit away from a code word $\\bm{c}$ with error at bit $k$. Let $\\bm{e_k}$ be the unit vector with bit $k$ set. So $\\bm{x} = \\bm{c} + \\bm{e_k}$ and \n$$\nH \\bm{x} = H (\\bm{c} + \\bm{e_k}) = H \\bm{e_k}\n$$\nSince $\\bm{e_k}$ is be the unit vector with bit $k$ set, $H \\bm{e_k}$ is column $k$ from the parity check matrix $H$. To decode we calculate $H \\bm{x}$ and look to see which column in $H$ the result is. To save the lookup step we can be even more elegant. Instead of the parity check matrix in standard form, we choose a parity check matrix where column $k$ is the bit representation of $k$. Instead of lookup we just reverse the bit representation back to the integer $k$.\n}.\n\nIs this always possible? We know that Hamming codes are perfect codes, so any $63$-bit word is at most one bit away from a code word. We have the following cases for the initial state of the chessboard:\n\n\\begin{itemize}\n\\item  It happens to be a code word in $\\mathfrak{H}_6$. Then the first player flips the magic field bit, producing an error there.\n\n\\item It happens to be a $63$-bit word that is a one bit error at the magic field. The first player doesn't flip any bit in this case.\n\n\\item It happens to be a $63$-bit word with a one bit error different from the magic field.\n\\end{itemize}\n\nThe last case needs a little thinking. Assume $H$ is the parity check matrix for our $\\mathfrak{H}_6$ Hamming code and assume the state of the chessboard is $\\bm{x}$, which is one bit error from a code word $\\bm{c_1}$. Also let $1 \\leq m \\leq 63$ be the magic field bit and $\\bm{e_m}$ the unit vector with bit $m$ set. The one bit error is different from the magic field, so $\\bm{x} - \\bm{c_1} \\neq \\bm{e_m}$. Let $\\bm{y} = \\bm{x} - \\bm{e_m}$, which is also one bit away from a code word $\\bm{c_2}$, with error bit $k$. So \n$\\bm{y} = \\bm{c_2} + \\bm{e_k}$.\n\nNow consider $\\bm{x} - \\bm{e_k}$:\n$$\nH (\\bm{x} - \\bm{e_k}) = H (\\bm{y} + \\bm{e_m} - \\bm{e_k}) = H (\\bm{y} - \\bm{e_k}) + H \\bm{e_m} = H \\bm{c_2} + H \\bm{e_m} = H \\bm{e_m}\n$$\n\nSo $\\bm{x} - \\bm{e_k}$ has one bit error at the magic field, which is what we want. Flipping bit $k$ on the initial chessboard $\\bm{x}$ achieves that.\n\nIn all three cases the modified chessboard is one bit away from a code word with the error at the magic field and the chessboard was modified by flipping at most one bit. The players agree that if the chessboard is a code word instead, then the devil chose bit $64$ as the magic field, which handles the special case. Modifying the chessboard to get a code word can also be done by flipping at most one bit. This scales to any chessboard with size a power of two.\n\n\\begin{fullwidth}\n\nWhat follows is a Mathematica session illustrating the strategy. We use a parity check matrix with column $k$ the bit representation of integer $k$. This simplifies decoding as remarked in the side note \\ref{decodingSideNote} above.\n\nThe function \\textit{hamming} generates the parity check matrix for a Hamming code with a given $r$.\n\n\\begin{mmaCell}[morefunctionlocal={i},morepattern={r, r_Integer}]{Code}\n  hamming[r_Integer] := Transpose[Table[IntegerDigits[i, 2, r], {i, 1, 2^r - 1}]]\n\\end{mmaCell}\n\nFor example\n\n\\begin{mmaCell}[moredefined={hamming}]{Input}\n  hamming[4] // MatrixForm\n\\end{mmaCell}\n\n\\begin{mmaCell}{Output}\n\\\\\n\\end{mmaCell}\n$$\n\\left(\n\\begin{array}{ccccccccccccccc}\n 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\n 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\\\\n 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\\\\n 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\\\\n\\end{array}\n\\right)\n$$\n\n\nWe define $r$ and the corresponding Hamming code $h$ for our chessboard\n\n\\begin{mmaCell}{Input}\n  r = 6;\n\\end{mmaCell}\n\n\\begin{mmaCell}[moredefined={hamming}]{Input}\n  h = hamming[6];\n\\end{mmaCell}\n\nThe function \\textit{pos} returns the unit vector with the error bit set from decoding the specified word.\n\n\\begin{mmaCell}[morelocal={s},morepattern={w, w_}]{Input}\n  pos[w_] := With[\\{s = Mod[h.w, 2]\\}, UnitVector[2^Length[s] - 1, FromDigits[s, 2]]]\n\\end{mmaCell}\n\nFunction \\textit{friendOne} implements the strategy part for the first friend. Given the initial state of the chessboard \\textit{cb} and a magic field \\textit{mf}, it returns a modified chessboard.\n\n\\begin{mmaCell}[morepattern={cb, cb_List, mf, mf_Integer},morelocal={em, ey, y}]{Input}\n  friendOne[cb_List, mf_Integer] := Module[\\{em, y, ey\\},\n  em = UnitVector[2^r - 1, mf]; y = Mod[cb - em, 2]; ey = pos[y];\n  z = Mod[cb - ey, 2]\n  ]\n\\end{mmaCell}\n\nFunction \\textit{friendTwo} implements the strategy part for the second friend: decoding the specified chessboard and returning the index of the error bit which is also the magic field.\n\n\\begin{mmaCell}[morepattern={cb, cb_List}]{Input}\n  friendTwo[cb_List] := Position[pos[cb], 1][[1,1]]\n\\end{mmaCell}\n\nThis next function is returning random initial states for the chessboard.\n\n\\begin{mmaCell}{Input}\n  rw := RandomInteger[1, \\{2^r - 1\\}]\n\\end{mmaCell}\n\nWe can now simulate one game with the devil.\n\n\\textit{cb} is the initial (random) state of the chessboard.\n\n\\begin{mmaCell}{Input}\n  cb = rw;\n\\end{mmaCell}\n\nThe magic field is some integer, the devil chose $23$.\n\n\\begin{mmaCell}{Input}\n  mf = 23;\n\\end{mmaCell}\n\nThe first friend enters the room, modifies the chessboard according to \\textit{friendOne}. The returned value is the modified chessboard.\n\n\\begin{mmaCell}{Input}\n  cb2 = friendOne[cb, mf];\n\\end{mmaCell}\n\nLet's check that the Hamming distance between initial and modified chessboard is at most one.\n\\begin{mmaCell}{Input}\n  HammingDistance[cb, cb2]\n\\end{mmaCell}\n\n\\begin{mmaCell}{Output}\n  1\n\\end{mmaCell}\n\nThe second friend comes in and decodes with \\textit{friendTwo}, getting $23$.\n\n\\begin{mmaCell}{Input}\n  friendTwo[cb2]\n\\end{mmaCell}\n\n\\begin{mmaCell}{Output}\n  23\n\\end{mmaCell}\n\n\\end{fullwidth}\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n\n\n", "meta": {"hexsha": "67f566fd560550053342e7b79dae1b1e51d25c55", "size": 25492, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hammingcode/hammingcode.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": "hammingcode/hammingcode.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": "hammingcode/hammingcode.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": 54.8215053763, "max_line_length": 632, "alphanum_fraction": 0.6791150165, "num_tokens": 8271, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8539127585282745, "lm_q1q2_score": 0.7736362710571757}}
{"text": "\\chapter{Linear Regression}\n\n\n\\section{Introduction}\nLinear regression is the “work horse” of statistics and (supervised) machine learning. When augmented with kernels or other forms of basis function expansion, it can model also nonlinear relationships. And when the Gaussian output is replaced with a Bernoulli or multinoulli distribution, it can be used for classification, as we will see below. So it pays to study this model in detail.\n\n\n\\section{Representation}\n\n\\begin{equation}\np(y|\\vec{x},\\vec{\\theta})=\\mathcal{N}(y|\\vec{w}^T\\vec{x}, \\sigma^2)\n\\end{equation}\nwhere $\\vec{w}$ and $\\vec{x}$ are extended vectors, $\\vec{x}=(1,x)$, $\\vec{w}=(b,w)$.\n\nLinear regression can be made to model non-linear relationships by replacing $\\vec{x}$ with some non-linear function of the inputs, $\\phi(\\vec{x})$ \\begin{equation}\np(y|\\vec{x},\\vec{\\theta})=\\mathcal{N}(y|\\vec{w}^T\\phi(\\vec{x}), \\sigma^2)\n\\end{equation}\n\nThis is known as \\textbf{basis function expansion}. (Note that the model is still linear in the parameters $\\vec{w}$, so it is still called linear regression; the importance of this will become clear below.) A simple example are polynomial basis functions, where the model has the form\n\\begin{equation}\n\\phi(x)=(1, x, \\cdots, x^d)\n\\end{equation}\n\n\n\n\\section{MLE}\nInstead of maximizing the log-likelihood, we can equivalently minimize the \\textbf{negative log likelihood} or \\textbf{NLL}:\n\\begin{equation}\n\\text{NLL}(\\vec{\\theta}) \\triangleq -\\ell(\\vec{\\theta})=-\\log(\\mathcal{D}|\\vec{\\theta})\n\\end{equation}\n\nThe NLL formulation is sometimes more convenient, since many optimization software packages are designed to find the minima of functions, rather than maxima.\n\nNow let us apply the method of MLE to the linear regression setting. Inserting the definition of the Gaussian into the above, we find that the log likelihood is given by\n\\begin{align}\n\\ell(\\vec{\\theta})& =\\sum\\limits_{i=1}^N \\log\\left[\\dfrac{1}{\\sqrt{2\\pi}\\sigma}\\exp\\left(-\\dfrac{1}{2\\sigma^2}(y_i-\\vec{w}^T\\vec{x}_i)^2\\right)\\right] \\\\\n     & =-\\dfrac{1}{2\\sigma^2}\\text{RSS}(\\vec{w})-\\dfrac{N}{2}\\log(2\\pi\\sigma^2)\n\\end{align}\n\nRSS stands for \\textbf{residual sum of squares} and is defined by\n\\begin{equation}\n\\text{RSS}(\\vec{w}) \\triangleq \\sum\\limits_{i=1}^N (y_i-\\vec{w}^T\\vec{x}_i)^2\n\\end{equation}\n\nWe see that the MLE for $\\vec{w}$ is the one that minimizes the RSS, so this method is known as \\textbf{least squares}.\n\nLet's drop constants wrt $\\vec{w}$ and NLL can be written as\n\\begin{equation}\n\\text{NLL}(\\vec{w}) = \\dfrac{1}{2}\\sum\\limits_{i=1}^N (y_i-\\vec{w}^T\\vec{x}_i)^2\n\\end{equation}\n\nThere two ways to minimize NLL$(\\vec{w})$.\n\n\n\\subsection{OLS}\nDefine $\\vec{y}=(y_1,y_2,\\cdots,y_N)$, $\\vec{X}=\\left(\\begin{array}{c}\\vec{x}_1^T \\\\ \\vec{x}_2^T \\\\ \\vdots \\\\ \\vec{x}_N^T\\end{array}\\right)$, then NLL$(\\vec{w})$ can be written as\n\\begin{equation}\n\\text{NLL}(\\vec{w})=\\dfrac{1}{2}(\\vec{y}-\\vec{X}\\vec{w})^T(\\vec{y}-\\vec{X}\\vec{w})\n\\end{equation}\n\nWhen $\\mathcal{D}$ is small(for example, $N < 1000$), we can use the following equation to compute \\vec{w} directly\n\\begin{equation}\n\\hat{\\vec{w}}_{\\mathrm{OLS}}=(\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{y}\n\\end{equation}\n\nThe corresponding solution $\\hat{\\vec{w}}_{\\mathrm{OLS}}$ to this linear system of equations is called the \\textbf{ordinary least squares} or \\textbf{OLS} solution.\n\n\\begin{proof}\nWe now state without proof some facts of matrix derivatives (we won’t need all of these at this section).\n\\begin{eqnarray}\ntrA &\\triangleq& \\sum\\limits_{i=1}^n A_{ii} \\nonumber \\\\\n\\frac{\\partial}{\\partial A}AB &=& B^T \\\\\n\\frac{\\partial}{\\partial A^T}f(A) &=& \\left[\\frac{\\partial}{\\partial A}f(A)\\right]^T \\label{eqn:matrix-1} \\\\\n\\frac{\\partial}{\\partial A}ABA^TC &=& CAB+C^TAB^T \\label{eqn:matrix-2} \\\\\n\\frac{\\partial}{\\partial A}|A| &=& |A|(A^{-1})^T\n\\end{eqnarray}\n\nThen,\n\\begin{eqnarray*}\n\\text{NLL}(\\vec{w}) &=& \\frac{1}{2N}(\\vec{X}\\vec{w}-\\vec{y})^T(\\vec{X}\\vec{w}-\\vec{y}) \\\\\n\\frac{\\partial \\text{NLL}}{\\vec{w}} &=& \\frac{1}{2} \\frac{\\partial}{\\vec{w}} (\\vec{w}^T\\vec{X}^T\\vec{X}\\vec{w}-\\vec{w}^T\\vec{X}^T\\vec{y}-\\vec{y}^T\\vec{X}\\vec{w}+\\vec{y}^T\\vec{y}) \\\\\n                           &=& \\frac{1}{2} \\frac{\\partial}{\\vec{w}} (\\vec{w}^T\\vec{X}^T\\vec{X}\\vec{w}-\\vec{w}^T\\vec{X}^T\\vec{y}-\\vec{y}^T\\vec{X}\\vec{w}) \\\\\n\t\t\t\t\t\t   &=& \\frac{1}{2} \\frac{\\partial}{\\vec{w}} tr(\\vec{w}^T\\vec{X}^T\\vec{X}\\vec{w}-\\vec{w}^T\\vec{X}^T\\vec{y}-\\vec{y}^T\\vec{X}\\vec{w}) \\\\\n\t\t\t\t\t\t   &=& \\frac{1}{2} \\frac{\\partial}{\\vec{w}} (tr\\vec{w}^T\\vec{X}^T\\vec{X}\\vec{w}-2tr\\vec{y}^T\\vec{X}\\vec{w})\n\\end{eqnarray*}\n\nCombining Equations \\ref{eqn:matrix-1} and \\ref{eqn:matrix-2}, we find that \n\\begin{equation*}\n\\frac{\\partial}{\\partial A^T}ABA^TC = B^TA^TC^T+BA^TC\n\\end{equation*}\n\nLet $A^T=\\vec{w}, B=B^T=\\vec{X}^T\\vec{X}$, and $C=I$, Hence,\n\\begin{eqnarray}\n\\frac{\\partial \\text{NLL}}{\\vec{w}} &=& \\frac{1}{2} (\\vec{X}^T\\vec{X}\\vec{w}+\\vec{X}^T\\vec{X}\\vec{w} -2\\vec{X}^T\\vec{y}) \\nonumber \\\\\n\t\t\t\t\t\t   &=& \\frac{1}{2} (\\vec{X}^T\\vec{X}\\vec{w} - \\vec{X}^T\\vec{y}) \\nonumber \\\\\n\\frac{\\partial \\text{NLL}}{\\vec{w}} &=& 0 \\Rightarrow \\vec{X}^T\\vec{X}\\vec{w} - \\vec{X}^T\\vec{y} =0 \\nonumber \\\\\n\\vec{X}^T\\vec{X}\\vec{w} &=& \\vec{X}^T\\vec{y} \\label{eqn:normal-equation} \\\\\n\\hat{\\vec{w}}_{\\mathrm{OLS}} &=& (\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{y} \\nonumber\n\\end{eqnarray}\n\\end{proof}\n\nEquation \\ref{eqn:normal-equation} is known as the \\textbf{normal equation}.\n\n\n\\subsubsection{Geometric interpretation}\n\nSee Figure \\ref{fig:graphical-interpretation-of-OLS}.\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.50]{graphical-interpretation-of-OLS.png}\n\\caption{Graphical interpretation of least squares for $N=3$ examples and $D=2$ features. $\\tilde{\\vec{x}}_1$ and $\\tilde{\\vec{x}}_2$˜ are vectors in $\\mathbb{R}^3$; together they define a 2D plane. $\\vec{y}$ is also a vector in $\\mathbb{R}^3$ but does not lie on this 2D plane. The orthogonal projection of $\\vec{y}$ onto this plane is denoted $\\hat{\\vec{y}}$. The red line from $\\vec{y}$ to $\\hat{\\vec{y}}$ is the residual, whose norm we want to minimize. For visual clarity, all vectors have been converted to unit norm.}\n\\label{fig:graphical-interpretation-of-OLS} \n\\end{figure}\n\nTo minimize the norm of the residual, $\\vec{y}-\\hat{\\vec{y}}$, we want the residual vector to be orthogonal to every column of $\\vec{X}$,so˜ $\\tilde{\\vec{x}}_j(\\vec{y}-\\hat{\\vec{y}})=0$ for $j=1:D$. Hence\n\\begin{equation}\\begin{split}\n\\tilde{\\vec{x}}_j(\\vec{y}-\\hat{\\vec{y}})=0 & \\Rightarrow \\vec{X}^T(\\vec{y}-\\vec{X}\\vec{w})=0 \\\\\n                                           & \\Rightarrow \\vec{w}=(\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{y}\n\\end{split}\\end{equation}\n\n\n\\subsection{SGD}\nWhen $\\mathcal{D}$ is large, use stochastic gradient descent(SGD).\n\n\\begin{align}\n\\because \\dfrac{\\partial}{\\partial w_i}\\text{NLL}(\\vec{w})=& \\sum\\limits_{i=1}^N (\\vec{w}^T\\vec{x}_i-y_i)x_{ij} \\\\\n\\therefore w_j=& w_j - \\alpha\\dfrac{\\partial}{\\partial w_j}\\text{NLL}(\\vec{w}) \\nonumber \\\\\n                  =& w_j - \\sum\\limits_{i=1}^N \\alpha(\\vec{w}^T\\vec{x}_i-y_i)x_{ij} \\\\\n\\therefore \\vec{w}=& \\vec{w}-\\alpha(\\vec{w}^T\\vec{x}_i-y_i)\\vec{x}\n\\end{align}\n\n\n\\section{Ridge regression(MAP)}\nOne problem with ML estimation is that it can result in overfitting. In this section, we discuss a way to ameliorate this problem by using MAP estimation with a Gaussian prior.\n\n\n\\subsection{Basic idea}\nWe can encourage the parameters to be small, thus resulting in a smoother curve, by using a zero-mean Gaussian prior:\n\\begin{equation}\np(\\vec{w})=\\prod\\limits_j \\mathcal{N}(w_j|0,\\tau^2)\n\\end{equation}\nwhere $1/\\tau^2$ controls the strength of the prior. The corresponding MAP estimation problem becomes\n\\begin{equation}\n\\arg\\max_{\\vec{w}} \\sum\\limits_{i=1}^N \\log{\\mathcal{N}(y_i|w_0+\\vec{w}^T\\vec{x}_i,\\sigma^2)}+\\sum\\limits_{j=1}^D \\log{\\mathcal{N}(w_j|0,\\tau^2)}\n\\end{equation}\n\nIt is a simple exercise to show that this is equivalent to minimizing the following\n\\begin{equation}\\label{eqn:Ridge-regression-J}\nJ(\\vec{w})=\\dfrac{1}{N}\\sum\\limits_{i=1}^N (y_i-(w_0+\\vec{w}^T\\vec{x}_i))^2+\\lambda\\lVert\\vec{w}\\rVert^2 , \\lambda \\triangleq \\dfrac{\\sigma^2}{\\tau^2}\n\\end{equation}\n\nHere the first term is the MSE/ NLL as usual, and the second term, $\\lambda \\geq 0$, is a complexity penalty. The corresponding solution is given by\n\\begin{equation}\\label{eqn:Ridge-regression-solution}\n\\hat{\\vec{w}}_{\\mathrm{ridge}}=(\\lambda\\vec{I}_D+\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{y}\n\\end{equation}\n\nThis technique is known as \\textbf{ridge regression},or \\textbf{penalized least squares}. In general, adding a Gaussian prior to the parameters of a model to encourage them to be small is called $\\ell_2$ \\textbf{regularization} or \\textbf{weight decay}. Note that the offset term $w_0$ is not regularized, since this just affects the height of the function, not its complexity.\n\nWe will consider a variety of different priors in this book. Each of these corresponds to a different form of \\textbf{regularization}. This technique is very widely used to prevent overfitting.\n\n\n\\subsection{Numerically stable computation *}\n\n\\begin{equation}\\label{eqn:Ridge-regression-SVD}\n\\hat{\\vec{w}}_{\\mathrm{ridge}}=\\vec{V}(\\vec{Z}^T\\vec{Z}+\\lambda\\vec{I}_N)^{-1}\\vec{Z}^T\\vec{y}\n\\end{equation}\n\n\n\\subsection{Connection with PCA *}\n\n\n\\subsection{Regularization effects of big data}\nRegularization is the most common way to avoid overfitting. However, another effective approach — which is not always available — is to use lots of data. It should be intuitively obvious that the more training data we have, the better we will be able to learn.\n\nIn domains with lots of data, simple methods can work surprisingly well (Halevy et al. 2009). However, there are still reasons to study more sophisticated learning methods, because there will always be problems for which we have little data. For example, even in such a data-rich domain as web search, as soon as we want to start personalizing the results, the amount of data available for any given user starts to look small again (relative to the complexity of the problem).\n\n\n\\section{Bayesian linear regression}\nTODO\n\n", "meta": {"hexsha": "4820f01eb2e9081a441395e29bb87b1cee412c4b", "size": 10065, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterLinearRegression.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/chapterLinearRegression.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/chapterLinearRegression.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": 55.6077348066, "max_line_length": 524, "alphanum_fraction": 0.6852459016, "num_tokens": 3556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7736362551672922}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following are quadratic forms?\n  \\begin{enumerate}\n  \\item $f_1(x,y,z) = (x+y+z)^2$.\n  \\item $f_2(x,y,z) = x^2 + y^2 + z^2$.\n  \\item $f_3(x,y,z) = (x+y)^2 + (x+z)^2 + (y+z)^2$.\n  \\item $f_4(x,y,z) = x^2 - y^2$.\n  \\item $f_5(x,y,z) = x^2 + 2xyz + (y+z)^2$.\n  \\item $f_6(x,y,z) = x(y+z)$.\n  \\item $f_7(x,y,z) = x^2y^2z^2$.\n  \\end{enumerate}\n  \\begin{sol}\n    All of them except (e) and (g).\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the coefficients of the quadratic form\n  $f(x,y,z) = \\vect{v}^T A\\vect{v}$, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      0 &  1 &  2 \\\\\n      1 & -3 & -4 \\\\\n      2 & -4 &  5 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Write the quadratic form\n  \\begin{equation*}\n    f(x,y,z) = (x+y)^2 + 2(x-z)^2 + 3yz\n  \\end{equation*}\n  in matrix form.\n  \\begin{sol}\n    $f(x,y,z) = \\vect{v}^T A\\vect{v}$, where\n    \\begin{equation*}\n      A = \\begin{mymatrix}{ccc}\n        3  &  1  & -2  \\\\\n        1  &  1  & 1.5 \\\\\n        -2 & 1.5 &  2  \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Apply the change of variables $x = u+2w$, $y = v$, $z = w-v$ to the\n  quadratic form\n  \\begin{equation*}\n    x^2 + 7y^2 + 5z^2 - 4xy - 4xz + 11yz.\n  \\end{equation*}\n  \\begin{sol}\n    $3u^2 + v^2 + vw + w^2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Perform a change of variables so that the quadratic form\n  $f(x,y) = 3x^2 - 2xy + 3y^2$ becomes diagonal.\n  \\begin{sol}\n    $x=u+v$ and $y=u-v$ gives $f = 4u^2 + 8v^2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Diagonalize the quadratic form\n  \\begin{equation*}\n    f(x,y,z) = 3x^2 + 3y^2 + 4z^2 + 2xz - 2yz.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Find the principal axes of the following curves, and sketch them:\n  \\begin{enumerate}\n  \\item $x^2+\\frac{1}{2}y^2=1$,\n  \\item $2x^2 + 4xy + 5y^2 = 1$.\n  \\item $3x^2 + 2xy + 3y^2 = 1$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Eigenvalues: $\\eigenvar_1=1$, $\\eigenvar_2=\\frac{1}{2}$.\n      Principal axes:\n      $\\vect{u}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}$ and\n      $\\vect{u}_2 = \\begin{mymatrix}{r} 0 \\\\ 1 \\end{mymatrix}$.\n      $\\vect{u}_1$-intercept: $1$, $\\vect{u}_2$-intercept: $\\sqrt{2}$.\n    \\item Eigenvalues: $\\eigenvar_1=1$, $\\eigenvar_2=6$.\n      Principal axes:\n      $\\vect{u}_1 = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{r} 2 \\\\ -1 \\end{mymatrix}$ and\n      $\\vect{u}_2 = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix}$.\n      $\\vect{u}_1$-intercept: $1$, $\\vect{u}_2$-intercept: $\\frac{1}{\\sqrt{6}}$.\n    \\item Eigenvalues: $\\eigenvar_1=2$, $\\eigenvar_2=4$.\n      Principal axes:\n      $\\vect{u}_1 = \\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1 \\\\ -1 \\end{mymatrix}$ and\n      $\\vect{u}_2 = \\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}$.\n      $\\vect{u}_1$-intercept: $\\frac{1}{\\sqrt{2}}$, $\\vect{u}_2$-intercept: $\\frac{1}{2}$.\n    \\end{enumerate}\n    \\begin{equation*}\n      \\begin{tikzpicture}[scale=1.5]\n        \\begin{scope}[color=black]\n          \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n          \\draw[->] (0,-1.5) -- (0,1.5) node[below right] {$y$};\n          \\draw (-1,0) -- +(0,-.1) node[below] {$-1$};\n          \\draw (1,0) -- +(0,-.1) node[below] {$1$};\n          \\draw (0,-1) -- +(-.1,0) node[left] {$-1$};\n          \\draw (0,1) -- +(-.1,0) node[left] {$1$};\n        \\end{scope}\n        \\begin{scope}[color=blue,cm={(1,0,0,1,(0,0))}]\n          \\draw[thick,red] (0,0) circle [x radius={1}, y radius={sqrt(2)}];\n          \\draw[red] (1,0) +(0.15,0.2) node {$1$};\n          \\draw[red] (0,{sqrt(2)}) +(-0.4,0.15) node {$\\sqrt{2}$};\n          \\draw[thick,blue,->] (0,0) -- node[below] {$\\vect{u}_1$} (1,0);\n          \\draw[thick,blue,->] (0,0) -- node[left] {$\\vect{u}_2$} (0,1);\n        \\end{scope}\n      \\end{tikzpicture}\n      \\begin{tikzpicture}[scale=1.5]\n        \\begin{scope}[color=black]\n          \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n          \\draw[->] (0,-1.5) -- (0,1.5) node[below right] {$y$};\n          \\draw (-1,0) -- +(0,-.1) node[below] {$-1$};\n          \\draw (1,0) -- +(0,-.1) node[below] {$1$};\n          \\draw (0,-1) -- +(-.1,0) node[left] {$-1$};\n          \\draw (0,1) -- +(-.1,0) node[left] {$1$};\n        \\end{scope}\n        \\begin{scope}[color=blue,cm={(2/sqrt(5),-1/sqrt(5),1/sqrt(5),2/sqrt(5),(0,0))}]\n          \\draw[thick,red] (0,0) circle [x radius={1}, y radius={1/sqrt(6)}];\n          \\draw[red] (1,0) +(0.1,-0.2) node {$1$};\n          \\draw[red] (0,{1/sqrt(6)}) +(0.2,0.2) node {$\\frac{1}{\\sqrt{6}}$};\n          \\draw[thick,blue,->] (0,0) -- (1,0) node[right] {$\\vect{u}_1$};\n          \\draw[thick,blue,->] (0,0) -- (0,1) node[above] {$\\vect{u}_2$};\n        \\end{scope}\n      \\end{tikzpicture}\n      \\begin{tikzpicture}[scale=1.5]\n        \\begin{scope}[color=black]\n          \\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$};\n          \\draw[->] (0,-1.5) -- (0,1.5) node[below right] {$y$};\n          \\draw (-1,0) -- +(0,-.1) node[below] {$-1$};\n          \\draw (1,0) -- +(0,-.1) node[below] {$1$};\n          \\draw (0,-1) -- +(-.1,0) node[left] {$-1$};\n          \\draw (0,1) -- +(-.1,0) node[left] {$1$};\n        \\end{scope}\n        \\begin{scope}[color=blue,cm={(1/sqrt(2),-1/sqrt(2),1/sqrt(2),1/sqrt(2),(0,0))}]\n          \\draw[thick,red] (0,0) circle [x radius={1/sqrt(2)}, y radius={1/2}];\n          \\draw[red] ({1/sqrt(2)},0) +(0.2,-0.2) node {$\\frac{1}{\\sqrt{2}}$};\n          \\draw[red] (0,{1/2}) +(-0.2,0.2) node {$\\frac{1}{2}$};\n          \\draw[thick,blue,->] (0,0) -- (1,0) node[right] {$\\vect{u}_1$};\n          \\draw[thick,blue,->] (0,0) -- (0,1) node[above] {$\\vect{u}_2$};\n        \\end{scope}\n      \\end{tikzpicture}\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the principal axes of the ellipsoid\n  $2x^2 + 2y^2 + 3z^2 + 2xz - 2yz$.\n  \\begin{sol}\n    The principal axes are\n    $\\frac{1}{\\sqrt{3}}\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ -1 \\end{mymatrix}$,\n    $\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix}$,\n    $\\frac{1}{\\sqrt{6}}\\begin{mymatrix}{r} 1 \\\\ -1 \\\\ 2 \\end{mymatrix}$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "d7c3caaab3bace92507df37727589852837ac731", "size": 6078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/InnerProductSpaces-Application-QuadraticForms.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/InnerProductSpaces-Application-QuadraticForms.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/InnerProductSpaces-Application-QuadraticForms.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.3952095808, "max_line_length": 90, "alphanum_fraction": 0.4901283317, "num_tokens": 2723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267762381844, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.7735114547981149}}
{"text": "\\section{Linearization \\& Newton's Method}\r\n\r\n\\subsection{Linearization}\r\nAs we've seen, tangent lines intersect their function at most once: at the point of tangency.\r\nHowever, we know that differentiable functions are locally linear, so we'd expect the tangent line to be a decent approximation of the function near the point of tangency.\r\n\r\n\\begin{definition}\r\n\tIf $f$ is differentiable at $a$, then the approximating function\r\n\t\\begin{equation*}\r\n\t\tL(x) = f^\\prime(a)(x-a) + f(a)\r\n\t\\end{equation*}\r\n\tis the linearization of $f$ at $a$.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tFind the linearization of $f(x) = \\ln{(x+1)}$ at $x=0$.\r\n\tHow accurate is this approximation at $x=0.1$?\r\n\\end{example}\r\n\\begin{answer}\r\n\tFollowing the definition,\r\n\t\\begin{align*}\r\n\t\tf(0) = \\ln{(0+1)} = 0 \\\\\r\n\t\tf^\\prime(x) &= \\frac{1}{x+1} \\\\\r\n\t\tf^\\prime(0) &= \\frac{1}{0+1} = 1 \\\\\r\n\t\tL(x) &= 1(x-0) + 0 = x.\r\n\t\\end{align*}\r\n\t\r\n\tCalculating the error at $x=0.1$,\r\n\t\\begin{align*} \r\n\t\tL(0.1) &= 0.1 \\\\\r\n\t\tf(0.1) &\\approx .0953 \\\\\r\n\t\t\\text{\\% error} &= \\frac{\\abs{L(0.1)-f(0.1)}}{L(0.1)}100\\text{\\%} \\approx 4.7\\text{\\%}.\r\n\t\\end{align*}\r\n\t\r\n\tSo, we can see the linear approximation is pretty good.\r\n\\end{answer}\r\n\r\n\r\nWe call the difference in $x$ between the point of tangency and the point we're trying to approximate the differential.\r\n\\begin{definition}\r\n\tLet $y=f(x)$ be a differentiable function.\r\n\tThe differential $\\d{x}$ is an independent variable.\r\n\tThe differential $\\d{y}$ is $\\d{y} = f^\\prime(x)\\d{x}$.\r\n\\end{definition}\r\n\r\n$\\mathrm{d}y$ is the approximated change in $y$ expected by the linearization for some given change in $x$, $\\d{x}$.\r\n\r\n\\begin{example}\r\n\tFind $\\d{y}$ for $y=\\frac{2x}{1+x^2}$, $x=-2$, and $\\d{x} = 0.1$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\ty^\\prime &= \\frac{-4x^2}{\\left(1+x^2\\right)^2} + \\frac{2}{1+x^2} \\\\\r\n\t\ty^\\prime(-2) &= -6/25 \\\\\r\n\t\t\\d{y} &= (-6/25)(0.1) = -0.024.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsection{Newton's Method}\r\nWe can use the fact that the tangent line approximates the function to find the zeroes of functions.\r\nStarting with an initial guess $x_0$ for the $x$ value of the zero, we look at the the tangent line at $x_0$ and find where it intersects the $x$-axis.\r\n\\begin{align*}\r\n\tL_0(x) &= f^\\prime(x_0)(x - x_0) + f(x_0) \\\\\r\n\t0 &= f^\\prime(x_0)(x - x_0) + f(x_0) \\\\\r\n\t-f^\\prime(x_0)(x - x_0) &= f(x_0) \\\\\r\n\tx - x_0 &= -\\frac{f(x_0)}{f^\\prime(x_0)} \\\\\r\n\tx &= x_0 - \\frac{f(x_0)}{f^\\prime(x_0)}.\r\n\\end{align*}\r\nThis $x$ value serves as our next guess for the zero.\r\nWe repeat this process until we find the zero or are satisfied with our error, that is, successive approximations match up to a predetermined number of decimal places.\\footnote{For most well-behaved functions, Newton's Method can get within a small margin of error or a zero relatively quickly. There is also a generalized, sometimes faster version of Newton's Method that approximates the function with higher-order polynomials than just lines.}\r\nThis yields a recursive formula\r\n\\begin{equation*}\r\n\tx_{n+1} = x_n - \\frac{f(x_n)}{f^\\prime(x_n)}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind an approximation for the zero of $x^3-2x-5$ accurate to four decimal places.\r\n\\end{example}\r\n\\begin{answer}\r\n\tIn this particular case, we have\r\n\t\\begin{equation*}\r\n\t\tx_{n+1} = x_{n} - \\frac{x^3_n - 2x_n - 5}{3x^2_n - 2}.\r\n\t\\end{equation*}\r\n\t\r\n\tA quick sketch of the graph of this function suggests that $x_0=2$ is a reasonable initial guess.\r\n\t\\begin{align*}\r\n\t\tx_1 &= x_0 - \\frac{f(x_0)}{f^\\prime(x_0)} = 2 - \\frac{2^3 - 2(2) - 5}{3(2)^2 - 2} = 2.1 \\\\\r\n\t\tx_2 &= x_1 - \\frac{f(x_1)}{f^\\prime(x_1)} = 2.1 - \\frac{2.1^3 - 2(2.1) - 5}{3(2.1)^2 - 2} \\approx 2.0946 \\\\\r\n\t\tx_3 &= x_2 - \\frac{f(x_2)}{f^\\prime(x_2)} = 2.0946 - \\frac{2.0946^3 - 2(2.0946) - 5}{3(2.0946)^2 - 2} \\approx 2.0946.\r\n\t\\end{align*}\r\n\t\r\n\tSince we have obtained 2.0946 twice consecutively, it must be accurate to four decimal places.\r\n\\end{answer}", "meta": {"hexsha": "0b3377f895e8bb3f11b1c2a6be96737e144d30b6", "size": 3922, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_derivative/linearization_newtons_method.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_derivative/linearization_newtons_method.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_derivative/linearization_newtons_method.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.1720430108, "max_line_length": 447, "alphanum_fraction": 0.6430392657, "num_tokens": 1416, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8976953016868439, "lm_q1q2_score": 0.7733988092127706}}
{"text": "\n\\subsection{Poisson distribution}\n\n\\subsection{Definition}\n\nWe can use the Poisson distribution to model the number of indepedent events that occur in an a time period.\n\nFor a very short time period the chance of us observing an event is a Bernoulli trial.\n\n\\(P(1)=p\\)\n\n\\(P(0)=1-p\\)\n\n\\subsection{Chance of no observations}\n\nLet's consider the chance of repeatedly getting \\(0\\): \\(P(0;t)\\).\n\nWe can see that: \\(P(0;t+\\delta t)=P(0;t)(1-p)\\).\n\nAnd therefore:\n\n\\(P(0;t+\\delta t)-P(0;t)=-pP(0;t))\\)\n\nBy setting \\(p=\\lambda \\delta t\\):\n\n\\(\\dfrac{P(0;t+\\delta t)-P(0;t)}{\\delta t}=-\\lambda P(0;t))\\)\n\n\\(\\dfrac{\\delta P(0;t)}{\\delta t}=-\\lambda P(0;t)\\)\n\n\\(P(0;t)=Ce^{-\\lambda t}\\)\n\nIf \\(t=0\\) then \\(P(0;t)=0\\) and so \\(C=1\\).\n\n\\(P(0;t)=e^{-\\lambda t}\\)\n\n\\subsection{Deriving the Poisson distribution}\n\n\n", "meta": {"hexsha": "aa81479160f918f1040a475976c5d39a34dbdec7", "size": 800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsDiscreteRepeated/02-01-poisson.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/distributionsDiscreteRepeated/02-01-poisson.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/distributionsDiscreteRepeated/02-01-poisson.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.5128205128, "max_line_length": 108, "alphanum_fraction": 0.63375, "num_tokens": 277, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070158103778, "lm_q2_score": 0.8499711699569786, "lm_q1q2_score": 0.7733947307804099}}
{"text": "\n\\subsection{Endomorphisms form a vector space}\n\nAn endomorphism maps a vector space onto itself.\n\n\\( end (V)=\\hom (V, V)\\)\n\nNeed to show that endomorphism is a vector space\n\nEssentially\n\n\\(v\\in V\\)\n\n\\(f\\in F\\)\n\n\\(av = f\\)\n\n\\(bv = g\\)\n\n\n\\((a\\oplus b)v=f+g\\)\n\n\\((a\\oplus b)v=av + bv\\)\n\nso there is some operation we can do on two members of endo\n\nlinear in addition. That is, if we have two dual \"things\", we can define the addition of functions as the operation which results int he outputs being added.\n\nwhat about linear in scalar? same approach.\n\nWell we define \n\n\\(c\\odot a)=cav\\)\n\nThere is a unique endomorphism which results in two other endomorphisms being added together. define this as addition\n\\subsection{Dimension of endomorphisms}\n\n\\(\\dim (end(V))=(\\dim V )^2\\)\n\n\\subsection{Basis of endomorphisms}\n\n", "meta": {"hexsha": "eccab214c8d018f4820d93145511e98fda5256bb", "size": 813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/01-02-endomorphismsVectorSpace.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/endomorphisms/01-02-endomorphismsVectorSpace.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/endomorphisms/01-02-endomorphismsVectorSpace.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.3571428571, "max_line_length": 157, "alphanum_fraction": 0.7097170972, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465170505205, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7732619931951643}}
{"text": "%%lecture 7\n\n%% 20.9\n\\newpage\n\\section{Hilbert spaces} \n\\label{sec:hilbert_spaces}\n\\begin{beispiel}\n\tConsider $\\mathbb{C}^n = \\set[(x_1,x_2,\\dots,x_n)]{x_i \\in \\mathbb{C}}$ and $x,y \\in \\mathbb{C}^n$ with\n\t$x= (x_1,\\dots,x_n)$, $y = (y_1,\\dots,y_n)$. Define the inner product of $x,y$ (scalar product)\n\t\\[\n\t\t\\skal{x}{y} = \\sum^{n}_{i=1}x_i \\bar{y}_i \\in \\mathbb{C}.\n\t\\]\n\tWe have a map\n\t\\begin{align*}\n\t\t\\mathbb{C}^n \\times \\mathbb{C}^n &\\to \\mathbb{C} \\\\\n\t\t(x,y) &\\mapsto \\skal{x}{y}.\n\t\\end{align*}\n\tThis mapping has properties:\n\t\\begin{itemize}\n\t\t\\item $x \\neq 0$ folgt $\\skal{x}{x} = \\sum^{n}_{i=1}x_i \\bar{x}_i = \\sum^{n}_{i=1} \\abs{x_i}^2 >0$\n\t\t\\item $\\skal{\\lambda x}{y} = \\lambda \\skal{x}{y}$ for $x,y \\in \\mathbb{C}^n$, $\\lambda \\in \\mathbb{C}$.\n\t\t\\item $\\skal{x}{y} = \\sum^{n}_{i=1} x_i \\bar{y}_i = \\overline{\\sum^{n}_{i=1}y_i \\bar{x}_i}$ for $x,y \\in \\mathbb{C}^n$. \\\\\n\t\tIn particular $\\skal{x}{\\lambda y} = \\bar{\\lambda} \\skal{x}{y}$ for $\\lambda \\in \\mathbb{C}$.\n\t\t\\item $\\skal{x+y}{z} = \\skal{x}{z}+ \\skal{y}{z}$ for $x,y,z \\in \\mathbb{C}^n$. \n\t\\end{itemize}\n\\end{beispiel}\n\\begin{definition*}\n\tAn inner product space $V$ is a complex vector space with an inner product which is a map \n\t\\[\n\t\t\\skal{.}{.}: V \\times V \\to \\mathbb{C}.\n\t\\]\n\tSatisfying\n\t\\begin{itemize}\n\t\t\\item $\\skal{\\lambda x}{y} = \\lambda \\skal{x}{y}$ for any $x,y \\in V$, $\\lambda \\in \\mathbb{C}$.\n\t\t\\item $\\skal{x+y}{z} = \\skal{x}{z}+ \\skal{y}{z}$ for any $x,y,z \\in V$.\n\t\t\\item $\\skal{x}{y} = \\overline{\\skal{x}{y}}$ for any $x,y \\in V$.\n\t\t\\item $\\skal{x}{x}>0$ for any $x \\in V, x \\neq 0$.\n\t\\end{itemize}\n\\end{definition*}\nCan we generalize $\\mathbb{C}^n$? \\\\\n\\[\n\t\\mathbb{C}^{\\mathbb{N}} \\set[(x_1,x_2, \\dots)]{x_i \\in \\mathbb{C}}\n\\]\nwith\n\\[\n\t\\skal{x}{y} = \\sum^{\\infty}_{i=1} x_i \\bar{y}_i.\n\\]\nThis is not necessarily convergent.\n\\begin{beispiele}\n\t\\begin{enumerate}[(1)]\n\t\t\\item \t\\[\n\t\tl^2 = \\set[(x_1,x_2, \\dots)]{ \\sum^{\\infty}_{i=1} \\abs{x_i}^2 < \\infty}.\n\t\\]\n\tWe have with Cauchy Schwarz\n\t\\[\n\t\t\\sum^{n}_{i=1} \\abs{x_i \\bar{y}_i} \\leq \\left( \\sum^{n}_{i=1} \\abs{x_i}^2 \\right)^{\\frac{1}{2}} \\left( \\sum^{n}_{i=1} \\abs{y_i}^2 \\right)^{\\frac{1}{2}}\n\t\\]\n\tif $x \\in l^2$ and $y \\in l^2$ we get\n\t\\begin{align*}\n\t\t\\sum^{n}_{i=1}\\abs{x_i \\bar{y}_i} \\leq \\left( \\sum^{\\infty}_{i=1} \\abs{x_i}^2 \\right)^{\\frac{1}{2}} \\left( \\sum_{i=1}^{\\infty} \\abs{y_i}^2. \\right)^{\\frac{1}{2}} < \\infty.\n\t\\end{align*}\n\tIt follows that $\\sum_{i=1}^{\\infty} x_i \\bar{y}_i$ converges absolutely and hence it is convergent. The following \n\t\\[\n\t\t\\skal{x}{y} = \\sum^{\\infty}_{i=1} x_i \\bar{y}_i\n\t\\]\n\tis well-defined for vectors $x,y \\in l^2$. Like for $\\mathbb{C}^n$ one can easily check that $\\skal{.}{.}$ satisfies the axioms for inner products. \\\\\n\t$(l^2, \\skal{.}{.})$ is an inner product space.\n\t\\item Consider $C([0,1])$ with the inner product\n\t\\[\n\t\t\\skal{f}{g} = \\int_{0}^{1}f(t) \\overline{g(t)} \\,\\mathrm{d}t \\qquad \\forall\\, f,g \\in C([0,1]).\n\t\\]\n\t\\begin{itemize}\n\t\t\\item \t\\[\n\t\t\t\\skal{\\lambda f}{g} = \\int_{0}^{1}\\lambda f(t) \\overline{g(t)} \\,\\mathrm{d}t = \\lambda \\int_{0}^{1}f(t) \\overline{g(t)} \\,\\mathrm{d}t = \\lambda \\skal{f}{g}.\n\t\t\\]\n\t\t\\item \\[\n\t\t\t\\skal{f}{f} = \\int_{0}^{1}f(t) \\overline{f(t)} \\,\\mathrm{d}t = \\int_{0}^{1} \\abs{f(t)}^2 \\,\\mathrm{d}t >0.\n\t\t\\]\t\n\t\t\\item $\\dots$.\n\t\\end{itemize}\n\t\\end{enumerate}\n\\end{beispiele}\nIf we take $\\mathbb{R}^3$ with the Eukledian norm on $\\mathbb{R}^3$\n\\[\n\t\\norm{(x_1,x_2,x_3)} = \\sqrt{x_1^2 + x_2^2 + x_3^2} = \\left( \\sum_{i=1}^{3} \\abs{x_i}^2 \\right)^{\\frac{1}{2}} = \\skal{x}{x}^{\\frac{1}{2}}.\n\\]\nLet $V$ be an inner product space with $\\skal{.}{.}$ as the inner product. Let for $x \\in V$\n\\[\n\t\\norm{x} := \\skal{x}{x}^{\\frac{1}{2}}.\n\\]\n\\begin{satz}\n\tThe $x \\mapsto  \\norm{x}$ with $\\norm{.}$ defined above is a norm.\n\\end{satz}\nWe are going to prove the norm axioms but first we need another theorem.\n\t\\begin{theorem}[Cauchy-Schwarz inequalitiy]\n\t\tFor any $x,y \\in V$ (inner product space) \n\t\t\\[\n\t\t\t\\abs{\\skal{x}{y}} \\leq \\skal{x}{x}^{\\frac{1}{2}} \\skal{y}{y}^{\\frac{1}{2}}.\n\t\t\\]\n\t\tThe equality holds iff $x,y$ are linearly dependent.\n\t\\end{theorem}\n\t\\begin{beweis}\n\t\tAssume $x,y$ linearly dependent. We can assume that $x= \\lambda y$ for some $\\lambda \\in \\mathbb{C} $.\n\t\t\\[\n\t\t\t\\abs{\\skal{x}{y}} = \\abs{ \\skal{\\lambda y}{y}} = \\abs{\\lambda} \\skal{y}{y}\n\t\t\\]\n\t\tand\n\t\t\\begin{align*}\n\t\t\t\t\t\\skal{x}{x}^{\\frac{1}{2}} \\skal{y}{y}^{\\frac{1}{2}} &= \\skal{\\lambda y}{\\lambda y}^{\\frac{1}{2}} \\skal{y}{y}^{\\frac{1}{2}} \\\\\n\t\t\t\t\t&= \\abs{\\lambda} \\skal{y}{y}^{\\frac{1}{2}} \\skal{y}{y}^{\\frac{1}{2}} \\\\\n\t\t\t\t\t&= \\abs{\\lambda} \\skal{y}{y}.\n\t\t\\end{align*}\n\t\tHence \\[\n\t\t\t\\abs{\\skal{x}{y}} = \\skal{x}{x}^{\\frac{1}{2}} \\skal{y}{y}^{\\frac{1}{2}}.\n\t\t\\]\n\t\tAssume $x,y$ are linearly independent. Hence $x + \\lambda y \\neq 0$ for any $\\lambda \\in \\mathbb{C}$. By an axiom for inner product we get\n\t\t\\[\n\t\t\t0< \\skal{x+ \\lambda y}{x + \\lambda y} = \\skal{x}{x} + \\lambda \\skal{y}{x} + \\bar{\\lambda} \\skal{x}{y} + \\abs{\\lambda}^2 \\skal{y}{y}.\n\t\t\\]\n\t\tPick now\n\t\t\\[\n\t\t\t\\lambda = - \\frac{\\skal{x}{y}}{\\skal{y}{y}}.\n\t\t\\]\n\t\t(Note that $y \\neq 0$ as $x,y$ linearly independent.)\n\t\tWe have \\begin{align*}\n\t\t\t\t\t\t0 &< \\skal{x}{x} - \\frac{\\overset{= \\abs{\\skal{x}{y}}^2}{\\overbrace{\\skal{x}{y}\\skal{y}{x}}}}{\\skal{y}{y}} - \\frac{\\overset{= \\abs{\\skal{x}{y}}^2}{\\overbrace{\\overline{\\skal{x}{y}}\\skal{x}{y}}}}{\\skal{y}{y}}+ \\frac{\\abs{\\skal{x}{y}}^2}{\\skal{y}{y}^2} \\skal{y}{y} \\\\\n\t\t\t\t\t\t&= \\skal{x}{x} - \\frac{\\abs{\\skal{x}{y}}^2}{\\skal{y}{y}}.\n\t\t\\end{align*}\n\t\tThis gives\n\t\t\\[\n\t\t\t\\frac{\\abs{\\skal{x}{y}}^2}{\\skal{y}{y}} < \\skal{x}{x}\n\t\t\\]\n\t\tand it follows\n\t\t\\[\n\t\t\t\\abs{\\skal{x}{y}}^2 < \\skal{x}{x} \\skal{y}{y}.\n\t\t\\]\n\t\\end{beweis}\nNow we can use this inequality to proof the statement above:\n\\begin{beweis}\n\t\\begin{enumerate}[(i)]\n\t\t\\item $\\norm{x} >0$ for all $x \\neq 0$ in $V$ (Exercise).\n\t\t\\item $\\norm{\\lambda x} = \\abs{\\lambda} \\norm{x}$ for all $x \\in V$, $\\lambda \\in \\mathbb{C}$ (Exercise).\n\t\t\\item Let $x,y \\in V$. Then \n\t\t\\begin{align*}\n\t\t\t\\norm{x+y}^2 &= \\skal{x+y}{x+y} \\\\ &= \\skal{x}{x}+ \\skal{x}{y}+ \\skal{y}{x} + \\skal{y}{y} \\\\\n\t\t\t&= \\skal{x}{x} + 2 \\re( \\skal{x}{y}) + \\skal{y}{y} \\\\\n\t\t\t&\\leq  \\skal{x}{x}+ 2 \\abs{\\skal{x}{y}} + \\skal{y}{y} \\\\\n\t\t\t&\\leq  \\skal{x}{x} + 2 \\skal{x}{x}^{\\frac{1}{2}}\\skal{y}{y}^{\\frac{1}{2}} + \\skal{y}{y} \\\\\n\t\t\t&= \\left( \\skal{x}{x}^{\\frac{1}{2}} + \\skal{y}{y}^{\\frac{1}{2}} \\right)^2.\n\t\t\\end{align*} \n\t\tSo\n\t\t\\[\n\t\t\t\\norm{x+y}^2 \\leq \\left( \\norm{x} + \\norm{y} \\right)^2.\n\t\t\\]\n\t\\end{enumerate}\n\\end{beweis}\n\\begin{theorem}[The Parallelogram Law]\n\tLet $(V, \\skal{.}{.})$ be an inner product space. Let $\\norm{x} = \\skal{x}{x}^{\\frac{1}{2}}$. Then\n\t\\[\n\t\t\\norm{x+y}^2 + \\norm{x-y}^2 = 2 (\\norm{x}^2 + \\norm{y}^2) \\qquad \\forall\\, x,y \\in V.\n\t\\]\n\\end{theorem}\n\\begin{satz}\n\t$l^p$ has inner product $\\skal{.}{.}_{l^p}$ such that\n\t\\[\n\t\t\\norm{x}_p = \\sqrt{\\skal{x}{x}_{l^p}}\n\t\\]\n\tiff $p =2$.\n\\end{satz}\n\\begin{beweis}\n\tEnough to show that $\\norm{.}_p$-norm does not satisfy the parallelogram law for some $x,y \\in l^p$ if $p \\neq 2$. Take for example $x = (1,0,0, \\dots)$\n\tand $y= (0,1,0, \\dots)$. Note that $\\norm{x}_{l^p} = \\norm{y}_{l^p} = 1$\n\t\\begin{align*}\n\t\t\\norm{x+y}^2_{l^p} &= \\norm{(1,1,0, \\dots)}_{l^p} = 2^{\\frac{2}{p}} \\\\\n\t\t\\norm{x-y}^2_{l^p} &= \\norm{(1,-1,0,\\dots)}_{l^p} = 2^{\\frac{2}{p}} \\\\\n\t\t\\norm{x+y}^2_{l^p} + \\norm{x-y}_{l^p}^2 &= 2 \\cdot 2^{\\frac{2}{p}} = 2( \\norm{x}^2_{l^p}+ \\norm{y}^2_{l^p}) = 2 \\cdot 2.\n\t\\end{align*}\n\\end{beweis}\nAll $l^p$ with $p \\neq 2$ are not inner product spaces. \n\\minisec{Exercise:}Show that $(C([0,1]),\\norm{.}_{\\infty})$ is not an inner product space.\n\\begin{bemerkung}\n\tWhenever a norm satisfies the parallelogram law then there exists an inner product on $V$ such that\n\t\\[\n\t\t\\norm{x} = \\skal{x}{x}^{\\frac{1}{2}}.\n\t\\]\n\\end{bemerkung}\n\\begin{theorem}[The Polarization Identity]\n\tLet $(V,\\skal{.}{.})$ be an inner product space. Then \n\t\\[\n\t\t4 \\skal{x}{y}  = \\norm{x+y}^2- \\norm{x-y}^2 + i \\norm{x+ iy}^2 - i \\norm{x - iy}^2.\n\t\\]\n\\end{theorem}\n\\begin{definition}\n\tLet $(V, \\skal{.}{.})$ be an inner product space. We say that $x,y$ in $V$ are orthogonal if $\\skal{x}{y} = 0$ (We write $x \\perp y$). Let $M \\subseteq V$\n\tDefine the orthogonal complement\n\t\\[\n\t\tM^{\\perp} = \\set[x \\in V]{x \\perp y \\text{ for any }y \\in M}.\n\t\\]\n\\end{definition}\n\\begin{proposition}\n\tIf $M \\subseteq V$ then $M^{\\perp}$ is a subspace of $V$.\n\\end{proposition}\n\\begin{theorem}[Pythagorean formula]\n\t$x,y \\in V$ (inner product space). Then\n\t\\[\n\t\tx \\perp y \\qquad \\text{iff} \\qquad \\norm{x+y}^2 = \\norm{x}^2 + \\norm{y}^2.\n\t\\]\n\\end{theorem}\n\n\\subsection{Orthogonal Systems} \n\\label{sub:orthogonal_systems}\n\nLet $(V, \\skal{.}{.})$ be an inner product space $\\set{u_n} \\subseteq V$ is called orthogonal system (with $n$ finite or infinite) if $u_n \\perp u_m$ for all $n \\neq m$. It is an orthonormal system if in addition $\\norm{u_n}=1$. \n\n\\begin{beispiele}\n\t\\begin{enumerate}[1)]\n\t\t\\item $\\set{e_k}_{k=1}^{\\infty} \\subseteq l^2$ with \n\t\t\\[\n\t\t\t\\skal{x}{y} = \\sum^{\\infty}_{i=1} x_i \\bar{y}_i\n\t\t\\]\n\t\twith \n\t\t\\[\n\t\t\te_k = (0,\\dots,1,0,\\dots).\n\t\t\\]\n\t\t$\\Rightarrow$ $\\set{e_k}$ is an ON-system. \n\t\t\\item $C([-\\pi,\\pi])$ with\n\t\t\\[\n\t\t\t\\skal{f}{g} = \\int_{- \\pi}^{\\pi} f(t) \\overline{g(t)} \\,\\mathrm{d}t.\n\t\t\\]\n\t\t\\[\n\t\t\t\\set[\\frac{1}{\\sqrt{2 \\pi}} e^{-int}]{n \\in \\mathbb{Z}}\n\t\t\\]\n\t\tis an orthonormal system.\n\t\\end{enumerate}\n\\end{beispiele}\n\n\\begin{definition}\n\tLet $\\set[a_n]{n \\in \\mathbb{N}}$ be an orthonormal system in $V$. The formal series \n\t\\[\n\t\t\\sum_{n=1}^{\\infty} \\skal{x}{a_n}a_n\n\t\\]\n\tis called a fourier series of $x$ corresponding $\\set[a_n]{n \\in \\mathbb{N}}$ and $\\skal{x}{a_n}$ are called fourier coefficients of $x$ corresponding to $\\set[a_n]{n \\in \\mathbb{N}}$. \n\\end{definition}\n\n\\begin{theorem}[Bessel's Equality and Inequality]\n\tIf $\\set{a_n}$ orthonormal system in an inner product space $V$, then for all $x \\in V$\n\t\\[\n\t\t\\norm{x- \\sum_{k=1}^{n} \\skal{x}{a_k}a_k}^2 = \\norm{x}^2 - \\sum_{k=1}^{n} \\abs{\\skal{x}{a_k}}^2\n\t\\]\n\tand \n\t\\[\n\t\t\\sum_{k=1}^{\\infty} \\abs{\\skal{x}{a_k}}^2 \\leq \\norm{x}^2.\n\t\\]\n\\end{theorem}\n\\begin{beweis}\n\t\\begin{align*}\n\t\t\\norm{x- \\sum_{k=1}^{n} \\skal{x}{a_k}a_k}^2 &= \\skal{x- \\sum_{k=1}^{n} \\skal{x}{a_k}a_k }{x - \\sum_{k=1}^{n} \\skal{x}{a_k}a_k} \\\\\n\t\t&= \\skal{x}{x} - \\sum_{k=1}^{n} \\overline{\\skal{x}{a_k}} \\skal{x}{a_k} - \\sum_{k=1}^{n} \\skal{x}{a_k}\\skal{a_k}{x} \n\t\t\\\\ & \\qquad \\qquad + \\skal{\\sum_{k=1}^{n}\\skal{x}{a_k}a_k}{\\sum_{k=1}^{n}\\skal{x}{a_k}a_k} \\\\\n\t\t& = \\norm{x}^2 - \\sum_{k=1}^{n} \\abs{\\skal{x}{a_k}}^2 - \\sum_{k=1}^{n} \\abs{\\skal{x}{a_k}}^2 + \\sum_{k=1}^{n}\\abs{\\skal{x}{a_k}}^2  \\\\\n\t\t& = \\norm{x}^2 - \\sum_{k=1}^{n} \\abs{\\skal{x}{a_k}}^2.\n\t\\end{align*}\n\tThis gives also:\n\t\\[\n\t\t\\sum_{k=1}^{n}\\abs{\\skal{x}{a_k}}^2 = \\norm{x}^2 - \\norm{x - \\sum_{k=1}^{n} \\skal{x}{a_k}a_k} \\leq \\norm{x}^2 \n\t\\]\n\tfor all $n \\in \\mathbb{N}$. Hence\n\t\\[\n\t\t\\sum_{k=1}^{\\infty} \\abs{\\skal{x}{a_k}}^2 \\leq \\norm{x}^2.\n\t\\]\n\\end{beweis}\n\n\\begin{definition}[Hilbert space]\n\tA Hilbert space is an inner product space which is complete w.r.t. the norm is defined through the inner product.\n\\end{definition}\n\n\\begin{beispiele}\n\t\\begin{itemize}\n\t\t\\item $\\mathbb{C}^n$ is an inner product space and complete w.r.t the Eukledean norm. Hence $\\mathbb{C}^n$ is a Hilbert space.\n\t\t\\item $l^2$ is a Banach space w.r.t. \n\t\t\\[\n\t\t\t\\norm{x}_{l^2} = \\left( \\sum_{i=1}^{\\infty} \\abs{x_i}^2 \\right)^{\\frac{1}{2}}\n\t\t\\]\n\t\tand\n\t\t\\[\n\t\t\t\\norm{x}_{l^2} = \\skal{x}{x}^{\\frac{1}{2}},\n\t\t\\]\n\t\twhere\n\t\t\\[\n\t\t\t\\skal{x}{y} = \\sum_{i=1}^{\\infty} x_i \\bar{y}_i.\n\t\t\\]\n\t\t\\item $(C([0,1]), \\norm{.}_{\\infty})$ is a Banach space but not an inner product space. Hence it is no Hilbert space.\n\t\t\\item $(C([0,1]),\\skal{.}{.})$ is an inner product space $f,g \\in C([0,1])$ with\n\t\t\\[\n\t\t\t\\skal{f}{g} = \\int_{0}^{1} f(t) \\overline{g(t)} \\,\\mathrm{d}t\n\t\t\\]\n\t\tand the corresponding\n\t\t\\[\n\t\t\t\\norm{f}_2 = \\skal{f}{f} = \\int_{0}^{1} \\abs{f(t)}^2 \\,\\mathrm{d}t.\n\t\t\\]\n\t\\end{itemize}\n\\end{beispiele}\n\\begin{bemerkung}\n\tOther $l^p$ spaces are not Hilbert spaces!!!! They are not inner product spaces.\n\\end{bemerkung}\n\n\\begin{satz}\n\t$(C([0,1]), \\skal{.}{.})$ is not a Hilbert space since $(C([0,1]), \\norm{.}_2)$ is not complete.\n\\end{satz}\n\n\\begin{beweis}\n\tSketch: Show that $f_n(t)$, which is defined as a piecewise continuous function for example\n\t\\[\n\t\tf_n(x)= \\begin{cases}\n\t\t\t1, &\\text{ if }x \\in [0,\\frac{1}{2}]\\\\\n\t\t\t0, &\\text{ if }x \\in [\\frac{1}{2} + \\frac{1}{n}] \\\\\n\t\t\t\\text{continuous}, & \\text{elsewhere} \n\t\t\\end{cases}\n\t\\] is a Cauchy sequence w.r.t $\\norm{.}_2$ but has no limit in $C([0,1])$.\n\\end{beweis}\n\nConsider\n\\[\n\tC_F = \\set[(x_1,x_2,\\dots)]{\\text{only finite }x_i \\neq 0} \n\\]\nwith \\[\n\t\\skal{x}{y} = \\sum_{i=1}^{\\infty} x_i \\bar{y}_i.\n\\]\nShow that $(C_F, \\skal{.}{.})$ is not a Hilbert space.\n\n\\begin{definition}[strongly and weakly convergent]\n\tA sequence $\\set{x_n} \\subseteq H$, where $H$ is a Hilbert space, is called strongly convergent $(x_n \\to x \\in H)$ if \n\t\\[\n\t\t\\norm{x_n -x} \\to 0, \\qquad n \\to  \\infty.\n\t\\]\n\t(Norm induced by an inner product) \\\\ We say that $x_n$ is weakly convergent ($x_n \\rightharpoonup x$) if\n\t\\[\n\t\t\\skal{x_n}{y} \\to \\skal{x}{y}, \\qquad \\forall\\, y \\in H.\n\t\\]\n\\end{definition}\n\n\\begin{satz}\n\t$x_n \\to x$$ \\qquad \\Rightarrow \\qquad $ $x_n \\rightharpoonup x$.\n\\end{satz}\n\n\\begin{beweis}\n\tAssume strong convergence for $(x_n)_{n \\in \\mathbb{N}}$. Then\n\t\\begin{align*}\n\t\t\\abs{\\skal{x_n}{y}- \\skal{x}{y}} &= \\abs{\\skal{x_n-x}{y}} \\\\\n\t\t&\\leq \\underset{=\\norm{x_n-x}}{\\underbrace{\\skal{x_n-x}{x_n-x}^{\\frac{1}{2}}}} \\underset{= \\norm{y}}{\\underbrace{\\skal{y}{y}^{\\frac{1}{2}}}} \\\\\n\t\t&= \\underset{ \\to 0}{\\underbrace{x_n-x}} \\norm{y} \\to 0, \\qquad n \\to \\infty.\n\t\\end{align*}\n\tHence $\\skal{x_n}{y} \\to \\skal{x}{y}$.\n\\end{beweis}\n\n\\begin{bemerkung}\n\tThe converse is not true in general: \\\\\n\tTake $H=l^2$ and \n\t\\begin{align*}\n\t\tx_n &= e_n = (0, \\dots,1,0,\\dots) \\\\\n\t\ty &= (y_1,y_2,\\dots) \\in l^2.\n\t\\end{align*}\n\tWe have for all $y \\in H$\n\t\\[\n\t\t\\skal{e_n}{y} = y_n \\to 0, \\qquad n \\to \\infty\n\t\\]\n\tas\n\t\\[\n\t\t\\norm{e_n -0}_{l^2} = \\norm{e_n}_{l^2} =1.\n\t\\]\n\\end{bemerkung}\n\n\\begin{satz}\n\t$x_n \\to x$ and $y_n \\to y$ yields\n\t\\[\n\t\t\\skal{x_n}{y_n} \\to \\skal{x}{y}.\n\t\\]\n\tIn particular\n\t\\[\n\t\tx_n \\to x \\qquad \\Rightarrow \\qquad \\norm{x_n} \\to \\norm{x}.\n\t\\]\n\\end{satz}\n\\begin{beweis}\n\t\\begin{align*}\n\t\t\\abs{\\skal{x_n}{y_n}-\\skal{x}{y}} &= \\abs{\\skal{x_n}{y_n}-\\skal{x}{y_n} + \\skal{x}{y_n} - \\skal{x}{y}} \\\\\n\t\t&= \\abs{\\skal{x_n -x}{y_n} + \\skal{x}{y_n-y}} \\\\\n\t\t&\\leq \\abs{\\skal{x_n-x}{y_n}} + \\abs{\\skal{x}{y_n-y}} \\\\\n\t\t&\\leq \\underset{\\to 0}{\\underbrace{\\norm{x_n-x}}} \\underset{< \\infty}{\\underbrace{\\norm{y_n}}} + \\underset{< \\infty}{\\underbrace{\\norm{x}}} \\underset{\\to 0}{\\underbrace{\\norm{y_n-y}}} \\to 0, \\qquad  n \\to \\infty.\n\t\\end{align*}\n\tCheck $\\set{\\norm{y_n}}$ is bounded\n\t\\[\n\t\t\\norm{y_n} = \\norm{y_n -y +y} \\leq \\underset{\\to 0}{\\underbrace{\\norm{y_n -y}}}+ \\underset{< \\infty}{\\underbrace{\\norm{y}}} \\to 0, \\qquad n \\to \\infty.\n\t\\]\n\\end{beweis}\n\n\\begin{satz}\n\t$x_n \\rightharpoonup x$ and $\\norm{x_n} \\to \\norm{x}$ yields\n\t\\[\n\t\tx_n \\to x.\n\t\\]\n\\end{satz}\n\\begin{beweis}\n\t\\begin{align*}\n\t\t\\norm{x_n-x}^2 &= \\skal{x_n -x}{x_n-x} \\\\\n\t\t&= \\underset{= \\norm{x_n}^2}{\\underbrace{\\skal{x_n}{x_n}}} - \\skal{x}{x_n}- \\skal{x_n}{x} + \\skal{x}{x} \\\\\n\t\t&= \\norm{x_n}^2 - \\overline{\\skal{x_n}{x}} - \\skal{x_n}{x} + \\norm{x}^2 \\\\\n\t\t&\\to \\norm{x}^2 - \\norm{x}^2 - \\norm{x}^2 + \\norm{x}^2 = 0.\n\t\\end{align*}\n\\end{beweis}\n\nWe have proved \n\\[\n\tx_n \\to x \\qquad \\Rightarrow \\qquad \\set{\\norm{x_n}} \\text{ is bounded}.\n\\]\n\n\\begin{theorem}\n\t\\[\n\t\tx_n \\rightharpoonup x \\qquad \\Rightarrow \\qquad \\sup_{n \\in \\mathbb{N}}\\norm{x_n} < \\infty.\n\t\\]\n\\end{theorem}\n\\begin{beweis}\n\tLet $x_n \\rightharpoonup x$. Consider $f_n: H \\to \\mathbb{C}$ where\n\t\\[\n\t\tf_n(y) = \\skal{y}{x_n}, \\qquad y \\in H.\n\t\\]\n\t\\begin{itemize}\n\t\t\\item $f_n$ is a linear functional for every $n \\in \\mathbb{N}$.\n\t\t\\item $\\forall\\, n \\in \\mathbb{N}$ $f_n$ is a bounded ($\\Leftrightarrow$ continuous) linear functional as if \n\t\t\\[\n\t\t\ty_k \\stackrel{k \\to \\infty}{\\to }y \\qquad \\Rightarrow \\qquad f_n(y_k) = \\skal{y_k}{x_n} \\to \\skal{y}{x_n} = f_n(y), \\qquad k \\to \\infty.\n\t\t\\]\n\t\t\\item $f_n(y) \\to \\skal{y}{x}$. \\\\\n\t\t$\\set{f_n(y)}_n$ is a convergent sequence in $\\mathbb{C}$ and hence bounded for all $y \\in H$. \\\\\n\t\tHence it exists $M_y$ such that \n\t\t\\[\n\t\t\t\\abs{f_n(y)} \\leq M_y.\n\t\t\\]\n\t\tBy Banach-Steinhaus-Theorem it holds\n\t\t\\[\n\t\t\t\\norm{f_n} \\leq M \\text{ for some }M >0.\n\t\t\\]\n\t\tWe are done if we proof that $\\norm{f_n} = \\norm{x_n}$.\n\t\t\\[\n\t\t\t\\abs{f_n(y)}= \\abs{\\skal{y}{x_n}} \\leq \\norm{y} \\norm{x_n}, \\qquad \\forall\\, y \\in H.\n\t\t\\]\n\t\tHence \n\t\t\\[\n\t\t\t\\norm{f_n} \\leq \\norm{x_n} \\qquad \\qquad (1).\n\t\t\\]\n\t\tOn the other Hand we have\n\t\t\\[\n\t\t\tf_n(x_n) = \\skal{x_n}{x_n}= \\norm{x_n}^2\n\t\t\\]\n\t\tand thus\n\t\t\\[\n\t\t\t\\norm{f_n} = \\sup_{x \\in H} \\frac{\\abs{f_n(x)}}{\\norm{x}} \\geq \\frac{\\abs{f_n(x_n)}}{\\norm{x_n}} = \\norm{x_n} \\qquad \\qquad (2)\n\t\t\\]\n\t\tWith (1) and (2) we are finished.\n\t\\end{itemize}\n\\end{beweis}\n\n\\subsection{Orthogonal decomposition in Hilbert spaces} \n\\label{sub:orthogonal_decomposition_in_hilber_spaces}\n\nRemember Linear Algebra. Take $\\mathbb{R}^n$ and a subspace $M \\subseteq \\mathbb{R}^n$ \n\\[\n\t\\Rightarrow \\qquad \\forall\\, x \\in \\mathbb{R}^n \\qquad x = z + y, \\qquad \\text{where }z \\in M, y \\in M^{\\perp}.\n\\]\nThis can be done in a unique way\n\\begin{align*}\n\tM &= \\spn \\set{e_z} \\\\ \n\tM^{\\perp} &= \\spn\\set{e_y}\n\\end{align*}\nand\n\\[\n\tz = \\proj_{M^{\\perp}}x, \\qquad \\qquad \\norm{x - \\proj_Mx} = \\min_{y \\in M}\\norm{x-y}.\n\\]\n\n\\minisec{General Hilbert space case}\n\n\\begin{proposition}\n\t$M \\subseteq H$, then $M^{\\perp}$ is a closed subspace and\n\t\\[\n\t\t\\left( M^{\\perp} \\right)^{\\perp} = \\overline{\\spn M}.\n\t\\]\n\\end{proposition}\n\n\\begin{satz}\n\t$H$ Hilbert space and $M$-closed subspace of $H$ and $x \\in H$. Then there exists a unique $z \\in M$ such that\n\t\\[\n\t\t\\norm{x-z} = \\dist(x,M) := \\inf_{y \\in M} \\norm{x-y}.\n\t\\]\n\t($z$ analog of the $\\text{proj}_Mx$ in the other case).\n\\end{satz}\n\n\\begin{proposition}\n\tTaking $z \\in M$ from the previous proposition. We have $x - z \\in M^{\\perp}$, i.e.\n\t\\[\n\t\tx = \\underset{\\in M}{\\underbrace{z}} + \\underset{\\in M^{\\perp}}{\\underbrace{(x - z)}}.\n\t\\]\n\\end{proposition}", "meta": {"hexsha": "921a2ac98cdc65eb6bce228948a96ad8c10a8df3", "size": 18004, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "AF/splits/lecture7.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/lecture7.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/lecture7.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": 35.9361277445, "max_line_length": 271, "alphanum_fraction": 0.5725394357, "num_tokens": 8267, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8670357701094303, "lm_q1q2_score": 0.7732320815596081}}
{"text": "\n\\subsection{Dot product}\n\nGiven two vectors we can calculate:\n\n\\(\\dfrac{a.b}{||a|| ||b||}\\)\n\nIf the two vectors are identical, this is \\(1\\). If they are orthogonal this is \\(0\\). If they are opposite, this is \\(-1\\).\n\n", "meta": {"hexsha": "b8d2e806484753554ee2f03d4d4573a145e0348e", "size": 220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/distance/01-02-dotProduct.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/distance/01-02-dotProduct.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/distance/01-02-dotProduct.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.0, "max_line_length": 124, "alphanum_fraction": 0.6454545455, "num_tokens": 65, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.953966101527047, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7731693983236361}}
{"text": "In the previous chapter, the grey values were modelled using a compound Poisson distribution to reflect the science of x-rays. This model has a linear relationship between the variance and the expectation. As a result, it would be possible to predict the variance of the grey value, given the grey value. This opens up new ways to predict the uncertainty of each pixel in an x-ray projection.\n\nIn this chapter, generalised linear models \\citep{nelder1972generalized, nelder1972generalized_2, mccullagh1984generalized} with different link functions and polynomial features were selected using forward stepwise selection. These selected models were compared using cross-validation to find the best model and verified using residual analysis.\n\n\\section{Generalised Linear Models}\n\nThe sample variance-mean data were obtained from the replicate projections. Let $x_{i,j}$ be the grey value of the $i$th pixel, ignoring any spatial information, from the $j$th replicate projection for $i=1,2,3,\\ldots,N$ and $j=1,2,3,\\ldots,m$. The sample mean and sample variance grey value for the $i$th pixel are\n\\begin{equation}\n    x_{i}=\\frac{1}{m}\\sum_{j=1}^m x_{i,j}\n\\end{equation}\nand\n\\begin{equation}\n    y_{i} =\n    \\frac{1}{m-1}\n    \\sum_{j=1}^m\n        \\left(\n            x_{i,j} - {x}_{i}\n        \\right)^2\n\\end{equation}\nrespectively. The symbol $y$ should not be confused with the latent variable in the previous chapter. Only pixels in the region of interest (ROI) were considered here, that is, pixels which represent the test sample. The ROI was created by manually segmenting the test sample from the projection.\n\nThe aim is to model and predict the grey value variance of a pixel given its grey value by using a model fitted onto the sample variance-mean data. The variance-mean data is denoted as $(x_1,y_1),(x_2,y_2),\\ldots,(x_N,y_N)$ where $N$ is the area of the ROI or the size of the dataset. Let $Y(x)$ be a random variable and the sample variance given a grey value mean $x$. It was assumed that the standard error from estimating the mean was negligible so that the uncertainty is captured by the random variable $Y$. It was assumed that for a given pixel, the grey values are Normal and i.i.d. Let $\\sigma^2(x)$ be the variance given a grey value $x$, then it can be shown that\n\\begin{equation}\n\\dfrac{(m-1)Y(x)}{\\sigma^2(x)}\\sim\\chi^2_{m-1}\n\\end{equation}\nwhich results in\n\\begin{equation}\nY(x)\\sim\\gammaDist\\left(\\alpha,\\dfrac{\\alpha}{\\sigma^2(x)}\\right)\n\\end{equation}\nwhere $\\alpha=(m-1)/2$ is the shape parameter. The expectation and variance are\n\\begin{equation}\n\\expectation\\left[Y(x)\\right]=\\sigma^2(x)\n\\end{equation}\nand\n\\begin{equation}\n\\variance\\left[Y(x)\\right]=\\left(\\dfrac{\\sigma^2(x)}{\\alpha}\\right)^2\n\\end{equation}\nrespectively.\n\nThis framework allows the use of generalised linear models (GLM) \\citep{nelder1972generalized,nelder1972generalized_2, mccullagh1984generalized}. In the gamma distribution case, a GLM can be used to model\n\\begin{equation}\nY(x)\\sim\\gammaDist\\left(\\alpha,\\dfrac{\\alpha}{g^{-1}(\\eta(x))}\\right)\n\\end{equation}\nwhere $g(y)$ is the link function and $\\eta(x)$ is a linear function called the systematic component. It should be noted that\n\\begin{equation}\n  \\expectation\\left[Y(x)\\right]=g^{-1}(\\eta(x))\n\\end{equation}\nwhich shows how the link function and systematic component work together. Examples of link functions are the identity link\n\\begin{equation}\ng(y)=g^{-1}(y)=y\n\\end{equation}\nand, for the gamma distribution case, the canonical link\n\\begin{equation}\ng(y)=g^{-1}(y)=1/y \\ .\n\\end{equation}\n\nAn example of a systematic component are polynomial features $\\eta(x)=\\sum_{r=0}^{p}\\beta_r x^{r}$ so that when used with the identity link, for example, $\\expectation\\left[Y(x)\\right] = \\sum_{r=0}^{p}\\beta_r x^{r}$. Iterative reweighted least squares \\citep{friedman2001elements} can be used to estimate the parameters $\\beta_0, \\beta_1, \\ldots, \\beta_{p}$ given data for the model to fit onto.\n\nOnce the parameters have been estimated, prediction of the variance given a grey value $x$ is done by using $\\widehat{y}(x) = g^{-1}(\\widehat{\\eta}(x))$ where $\\widehat{\\eta}(x)$ is the systematic component using the estimated parameters.\n\n\\section{Model Selection}\n\nThis section describes how forward stepwise selection \\citep{efroymson1960multiple, friedman2001elements} was used to select which polynomial features to use in the systematic component.\n\nIn summary, forward stepwise selection fits a basic model to the data initially. A feature is added to make the model more complicated at each step to improve the fit onto the data. This is continued until the model cannot be improved subject to overfitting. The Akaike information criterion (AIC) \\citep{akaike1974new, friedman2001elements} and the Bayesian information criterion (BIC) \\citep{schwarz1978estimating, friedman2001elements} are criteria which can be used to assess the fit of the model at each step without overfitting to the data too much.\n\nThe AIC and BIC are given as\n\\begin{equation}\n\\AIC = 2k-2\\ln L\n\\end{equation}\nand\n\\begin{equation}\n\\BIC = k\\ln N - 2\\ln L\n\\end{equation}\nrespectively where $k$ is the number of parameters in the systematic component and $\\ln L$ is the log-likelihood of the GLM. The model with the lowest AIC or BIC is preferred. GLM aims to maximise the log-likelihood but the additional terms in the criteria penalise models with too many terms. The log-likelihood is given as\n\\begin{equation}\n  \\ln L = \\sum_{i=1}^N \\left[\n    \\alpha\\ln\\alpha\n    -\\ln\\Gamma(\\alpha)\n    -\\alpha\\ln \\widehat{y}_i\n    +(\\alpha-1)\\ln y_i\n    -\\frac{\\alpha y_i}{\\widehat{y}_i}\n  \\right]\n  \\ .\n\\end{equation}\nwhere $\\widehat{y}_i=\\widehat{y}(x_i)$. $\\alpha=(m-1)/2$ was assumed to be known so does not need to be estimated.\n\nThe procedure is as follows. A criterion and a link function were chosen beforehand. In the initial step, a GLM with systematic component $\\eta(x)=\\beta_0$ was fitted and the criterion was recorded. In the next step, a polynomial feature with one order higher was added to the systematic component $\\eta(x)=\\beta_0+\\beta_1 x$, fitted and the criterion recorded. Also, a polynomial feature with one order lower was added $\\beta(x)=\\beta_{-1}x^{-1}+\\beta_0$ and fitted separately with the criterion recorded. The model which decreased the criterion the most was accepted. Adding higher and lower order polynomials to the systematic component was repeated, for example, after accepting $\\eta(x)=\\beta_0+\\beta_1 x$, the following systematic components $\\eta(x)=\\beta_0+\\beta_1 x+\\beta_2x^2$ and $\\eta(x)=\\beta_{-1}x^{-1}+\\beta_0+\\beta_1 x$ were fitted and assessed. The fitted parameters may change when adding more terms. This is repeated until the criterion cannot be decreased and the procedure is left with the final model.\n\nForward stepwise selection was conducted on the datasets \\texttt{AbsNoFilter} and \\texttt{AbsFilter}. The procedure was repeated 10 times by using a random permutation, with replacement, of the replicate projections to obtain a different sample variance-mean data which introduced some variation to the data \\citep{efron1979bootstrap}. The procedure was also repeated using various shading corrections to investigate the effects of shading correction on the variance-mean relationship.\n\n\\begin{sidewaystable}\n\\centering\n\\begin{tabular}{ll|ccc}\n\\multicolumn{2}{c|}{Identity Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_identitycriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_identityvote.txt}       & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_identitycriterion.txt} \\\\\n\\\\\n\\multicolumn{2}{c|}{Canonical Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg30linear_reciprocalcriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg30linear_reciprocalcriterion.txt}\n\\end{tabular}\n\\caption{Forward stepwise selection was used to find suitable polynomial features when fitting a gamma GLM onto the sample variance-mean data from the projections in \\texttt{AbsNoFilter} at \\ang{30}. The columns of the table represent different shading corrections. Forward stepwise selection was repeated 10 times by bootstrapping the replicate projections. `Order' shows the most commonly selected polynomial orders and `votes' shows the number of times it was selected out of the 10 repeats. The error bars are the standard deviation from the 10 repeats.}\n\\label{table:meanVar_glmselect_absnofilterdeg30}\n\\end{sidewaystable}\n\n\\begin{sidewaystable}\n\\centering\n\\begin{tabular}{ll|ccc}\n\\multicolumn{2}{c|}{Identity Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_identitycriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_identityvote.txt}       & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_identitycriterion.txt} \\\\\n\\\\\n\\multicolumn{2}{c|}{Canonical Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsNoFilterDeg120linear_reciprocalcriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsNoFilterDeg120linear_reciprocalcriterion.txt}\n\\end{tabular}\n\\caption{Forward stepwise selection was used to find suitable polynomial features when fitting a gamma GLM onto the sample variance-mean data from the projections in \\texttt{AbsNoFilter} at \\ang{120}. The columns of the table represent different shading corrections. Forward stepwise selection was repeated 10 times by bootstrapping the replicate projections. `Order' shows the most commonly selected polynomial orders and `votes' shows the number of times it was selected out of the 10 repeats. The error bars are the standard deviation from the 10 repeats.}\n\\label{table:meanVar_glmselect_absnofilterdeg120}\n\\end{sidewaystable}\n\n\\begin{sidewaystable}\n\\centering\n\\begin{tabular}{ll|ccc}\n\\multicolumn{2}{c|}{Identity Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_identitycriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_identityvote.txt}       & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_identitycriterion.txt} \\\\\n\\\\\n\\multicolumn{2}{c|}{Canonical Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg30linear_reciprocalcriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg30linear_reciprocalcriterion.txt}\n\\end{tabular}\n\\caption{Forward stepwise selection was used to find suitable polynomial features when fitting a gamma GLM onto the sample variance-mean data from the projections in \\texttt{AbsFilter} at \\ang{30}. The columns of the table represent different shading corrections. Forward stepwise selection was repeated 10 times by bootstrapping the replicate projections. `Order' shows the most commonly selected polynomial orders and `votes' shows the number of times it was selected out of the 10 repeats. The error bars are the standard deviation from the 10 repeats.}\n\\label{table:meanVar_glmselect_absfilterdeg30}\n\\end{sidewaystable}\n\n\\begin{sidewaystable}\n\\centering\n\\begin{tabular}{ll|ccc}\n\\multicolumn{2}{c|}{Identity Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_identitycriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_identityorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_identityorder.txt}     \\\\\n                     & votes     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_identityvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_identityvote.txt}       & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_identityvote.txt}      \\\\\n                     & criterion & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_identitycriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_identitycriterion.txt} \\\\\n\\\\\n\\multicolumn{2}{c|}{Canonical Link}& null & bw & linear \\\\ \\hline\n\\multirow{3}{*}{AIC} & order      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectAicAbsFilterDeg120linear_reciprocalcriterion.txt} \\\\ \\hline\n\\multirow{3}{*}{BIC} & order      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_reciprocalorder.txt}     & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_reciprocalorder.txt}     \\\\\n                     & votes      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_reciprocalvote.txt}      & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_reciprocalvote.txt}      \\\\\n                     & criterion  & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120null_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120bw_reciprocalcriterion.txt} & \\inputNumber{../figures/varmean/GlmSelectBicAbsFilterDeg120linear_reciprocalcriterion.txt}\n\\end{tabular}\n\\caption{Forward stepwise selection was used to find suitable polynomial features when fitting a gamma GLM onto the sample variance-mean data from the projections in \\texttt{AbsFilter} at \\ang{120}. The columns of the table represent different shading corrections. Forward stepwise selection was repeated 10 times by bootstrapping the replicate projections. `Order' shows the most commonly selected polynomial orders and `votes' shows the number of times it was selected out of the 10 repeats. The error bars are the standard deviation from the 10 repeats.}\n\\label{table:meanVar_glmselect_absfilterdeg120}\n\\end{sidewaystable}\n\nThe results are shown in Tables \\ref{table:meanVar_glmselect_absnofilterdeg30} and \\ref{table:meanVar_glmselect_absnofilterdeg120} for \\texttt{AbsNoFilter} and Tables \\ref{table:meanVar_glmselect_absfilterdeg30} and \\ref{table:meanVar_glmselect_absfilterdeg120} for \\texttt{AbsFilter}. The models selected are quite simple and all have two features. Different shading corrections or different criteria had no effect on the selected model. The method was quite robust to the variation introduced to the dataset when repeating the experiment because all 10 repeats consistently selected the same model.\n\nThere was some variation to the selected models between datasets. For example, when using the identity link, \\texttt{AbsNoFilter} preferred $\\eta(x)=\\beta_0+\\beta_1 x$ whereas \\texttt{AbsFilter} preferred $\\eta(x)=\\beta_{-1}x^{-1}+\\beta_0$. Using the canonical link, both datasets selected $\\eta(x)=\\beta_{-1}x^{-1}+\\beta_0$ which correspond to $\\widehat{y}(x)=\\left(\\beta_{-1}x^{-1}+\\beta_0\\right)^{-1}$.\n\nFigures \\ref{fig:meanVar_varMeanExample_AbsNoFilter} and \\ref{fig:meanVar_varMeanExample_AbsFilter} shows the GLM fits for the datasets \\texttt{AbsNoFilter} and \\texttt{AbsFilter} respectively. The prediction intervals were obtained using the distribution $\\widehat{Y}(x)\\sim\\gammaDist\\left(\\alpha, \\dfrac{\\alpha}{g^{-1}\\left(\\widehat{\\eta}(x)\\right)}\\right)$. The fits all looked reasonable except for \\texttt{AbsNoFilter} at \\ang{120} where the fit did not capture the inflection. The forward stepwise selection may not picked this up because there were a lot of low grey values, causing a leverage towards these low grey values. As a result, the inflection did not stand out to the method.\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsNoFilterDeg30_identity000010.eps}\n        \\caption{${y}(x)=\\beta_0+\\beta_1 x$ at \\ang{30}}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsNoFilterDeg30_reciprocal000100.eps}\n        \\caption{${y}(x)=(\\beta_{-1}x^{-1}\\beta_0)^{-1}$ at \\ang{30}}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsNoFilterDeg120_identity000010.eps}\n        \\caption{${y}(x)=\\beta_0+\\beta_1 x$ at \\ang{120}}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsNoFilterDeg120_reciprocal000100.eps}\n        \\caption{${y}(x)=(\\beta_{-1}x^{-1}\\beta_0)^{-1}$ at \\ang{120}}\n    \\end{subfigure}\n    }\n    \\caption{Log frequency density histogram of the sample variance-mean data from \\texttt{AbsNoFilter} with linear shading correction. The solid red line shows the GLM fit along with the 68\\% prediction interval as dashed lines. The colour scales are in units of $\\log\\SI{}{\\adu^{-3}}$.}\n    \\label{fig:meanVar_varMeanExample_AbsNoFilter}\n\\end{figure}\n\n\\begin{figure}\n  \\centering\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsFilterDeg30_identity000100.eps}\n        \\caption{${y}(x)=\\beta_{-1}x^{-1}+\\beta_0$ at \\ang{30}}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsFilterDeg30_reciprocal000100.eps}\n        \\caption{${y}(x)=(\\beta_{-1}x^{-1}+\\beta_0)^{-1}$ at \\ang{30}}\n    \\end{subfigure}\n    }\n    \\centerline{\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsFilterDeg120_identity000100.eps}\n        \\caption{${y}(x)=\\beta_{-1}x^{-1}+\\beta_0$ at \\ang{120}}\n    \\end{subfigure}\n    \\begin{subfigure}[b]{\\subSize}\n        \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanExample_AbsFilterDeg120_reciprocal000100.eps}\n        \\caption{${y}(x)=(\\beta_{-1}x^{-1}+\\beta_0)^{-1}$ at \\ang{120}}\n    \\end{subfigure}\n    }\n    \\caption{Log frequency density histogram of the sample variance-mean data from \\texttt{AbsFilter} with linear shading correction. The solid red line shows the GLM fit along with the 68\\% prediction interval as dashed lines. The colour scales are in units of $\\log\\SI{}{\\adu^{-3}}$.}\n    \\label{fig:meanVar_varMeanExample_AbsFilter}\n\\end{figure}\n\n\\section{Cross-Validation}\n\nInstead of assessing the model fit using the AIC and BIC, the performance on predicting the variance given a grey value was assessed using cross-validation \\citep{allen1974relationship, stone1974cross, stone1977asymptotic, friedman2001elements}. Cross-validation assesses the model to make predictions on data it has not seen before. This was done by randomly splitting the $N$ data points into two disjoint sets, the training set and the test set $\\tau$. The model was fitted onto the training set. Afterwards, the fitted model predicts the variances given the grey values in the test set which were then compared to the actual variances.\n\nIt was chosen that the training and test set are of the same size, a 50:50 spilt. The sizes of the sets can be different, for example, a 75:25 spilt. A 50:50 spilt was chosen because a large training set is an overkill for a high data and low dimensional problem. Here, a model with a few parameters is fitted onto millions of pixels.\n\nThe mean scaled deviance was used to assess the performance of variance prediction of the test set. The deviance is defined to be\n\\begin{equation}\n  D = 2\\left(\n    \\ln L_\\mathrm{s} - \\ln L_\\tau\n  \\right)\n\\end{equation}\nwhere\n\\begin{equation}\n\\ln L_\\tau = \\sum_{i\\in\\tau} \\left[\n    \\alpha\\ln\\alpha\n    -\\ln\\Gamma(\\alpha)\n    -\\alpha\\ln \\widehat{y}_i\n    +(\\alpha-1)\\ln y_i\n    -\\frac{\\alpha y_i}{\\widehat{y}_i}\n  \\right]\n\\end{equation}\nis the log-likelihood of the test set given the fitted model and $\\ln L_\\mathrm{s}$ is the saturated log-likelihood. This is obtained by replacing all $\\widehat{y}_i$ with $y_i$ in $\\ln L_\\tau$ so that\n\\begin{equation}\n  \\ln L_\\mathrm{s} = \\sum_{i\\in\\tau}\\left[\n    \\alpha\\ln\\alpha\n    -\\ln\\Gamma(\\alpha)\n    -\\ln y_i\n    -\\alpha\n  \\right]\n  \\ .\n\\end{equation}\nFollowing from this, the deviance is\n\\begin{equation}\n  D = 2\\alpha\n  \\sum_{i\\in\\tau}\\left[\n      \\dfrac{\n          y_i-\\widehat{y}_i\n      }\n      {\n          \\widehat{y}_i\n      }\n      - \\ln\\left(\\dfrac{y_i}{\\widehat{y}_i}\\right)\n  \\right]\n  \\ .\n\\end{equation}\nThe mean scaled deviance is obtained by removing the factor of $\\alpha$ and dividing by $N_\\tau$ to get\n\\begin{equation}\n    D_\\mathrm{s} = \\dfrac{2}{N_\\tau}\n    \\sum_{i\\in\\tau}\\left[\n        \\dfrac{\n            y_i-\\widehat{y}_i\n        }\n        {\n            \\widehat{y}_i\n        }\n        - \\ln\\left(\\dfrac{y_i}{\\widehat{y}_i}\\right)\n    \\right]\n    \\ .\n\\end{equation}\n\n\\begin{figure}\n  \\centering\n  \\includegraphics[width=\\subSize]{../figures/varmean/devianceGraph.eps}\n  \\caption{The scaled deviance loss function}\n  \\label{fig:meanVar_deviance}\n\\end{figure}\n\nThe mean scaled deviance is a loss function which increases as $y_i/\\widehat{y}_i$ deviates from one, this is shown in Figure \\ref{fig:meanVar_deviance} and it should be noted that the $x$-axis is in log scale. Another way to show this is by letting $r_i = y_i/\\widehat{y}_i$ and $d_i = 2\\left[r_i-1-\\ln r_i\\right]$ be an element from the sum in the deviance. For $r_i\\approx 1$, $\\ln(r_i)\\approx(r_i-1)-(r_i-1)^2/2$ which implies that $d_i\\approx (r_i-1)^2$ with minimum at one. For $r_i$ deviate greatly from one, the loss function is asymmetric. For example a ratio of $r_i=10^1$ has a greater penalty than $r_i=10^{-1}$. This means that in extreme cases, overestimates are penalised less than underestimates relative to $y_i$.\n\nAssuming the model is correct, it is given that $D\\sim\\chi_{N_\\tau-k}^2$ which implies that for large $N_\\tau$,\n\\begin{equation}\n\\expectation\\left[D_\\mathrm{s}\\right] = \\dfrac{1}{\\alpha}\n\\end{equation}\nand\n\\begin{equation}\n\\variance\\left[D_\\mathrm{s}\\right] = \\dfrac{2}{\\alpha^2 N_\\tau} \\ .\n\\end{equation}\nBecause $\\alpha=(m-1)/2$, this shows that the number of replicated projections used to obtain the sample variance-mean data has an influence on the mean scaled deviance. This result can be used to estimate $\\alpha$ if it is unknown.\n\nCross validation was performed on the datasets \\texttt{AbsNoFilter} and \\texttt{AbsFilter} with various shading corrections. The models selected from forward stepwise selection in the previous section were assessed. They are ${y}(x)=\\beta_0+\\beta_1 x$ and ${y}(x)=\\beta_{-1}x^{-1}+\\beta_0$ using the identity link and ${y}(x)=(\\beta_{-1}x^{-1}+\\beta_0)^{-1}$ using the canonical link. The analysis was repeated 100 times by using a random permutation with replacement of the replicate projections to obtain a different sample variance-mean data which introduced some variation to the data \\citep{efron1979bootstrap}.\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/VarMeanCvAbsNoFilterDeg30_testmeanscaleddeviance.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/VarMeanCvAbsNoFilterDeg120_testmeanscaleddeviance.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n    \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/VarMeanCvAbsFilterDeg30_testmeanscaleddeviance.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/VarMeanCvAbsFilterDeg120_testmeanscaleddeviance.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n  \\caption{Test mean scaled deviance from predicting variances in a test set using a GLM fitted onto a training set. The different colours represent different shading corrections. The boxplots represent the 100 repeats of the analysis by bootstrapping the replicate projections.}\n  \\label{fig:meanVar_varMeanCv}\n\\end{figure}\n\nThe results from the cross-validation is shown in Figure \\ref{fig:meanVar_varMeanCv}. The performances of the three candidate models were very similar. One exception is the model ${y}(x)=\\beta_{-1}x^{-1}+\\beta_0$ fitted onto the \\texttt{AbsNoFilter} dataset because the mean scaled deviance was significantly larger. This is expected from a model not favoured in the forward stepwise selection in the previous section.\n\nShading correction did not have a significant effect on the analysis.\n\nFrom these results, it is recommended that the relationship ${y}(x)=\\beta_0+\\beta_1 x$ should be used for its simple form, similar performance to other candidate models and connections to the compound Poisson.\n\n\\section{Residual Analysis}\n\nResidual analysis was conducted to study for anything overlooked. The model ${y}(x)=\\beta_0+\\beta_1 x$ was fitted onto the entire sample variance-mean data. A residual plot plots $r_i=y_i-\\widehat{y}(x_i)$ for all $x_i$ in the dataset which was done using a 2D histogram. Due to the gamma GLM, higher grey values typically have bigger residuals in magnitude. A prediction residual interval is included in the histogram to aid judging the residuals. This interval was acquired by obtaining the prediction interval and subtracting it from the fit.\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsNoFilterDeg30_vsgreyvalue.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsNoFilterDeg120_vsgreyvalue.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsFilterDeg30_vsgreyvalue.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsFilterDeg120_vsgreyvalue.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n  \\caption{Log frequency density histogram of the residuals given the mean grey value. The residuals are from fitting a gamma GLM of the form ${y}(x)=\\beta_0+\\beta_1 x$ onto the sample variance-mean data obtained from the replicate projections. The dashed red line shows the 68\\% prediction residual interval. The colour scales are in units of $\\log\\SI{}{\\adu^{-3}}$.}\n  \\label{fig:meanVar_residualGreyvalue}\n\\end{figure}\n\nThe residual plots are shown in Figure \\ref{fig:meanVar_residualGreyvalue}. The residuals are all sensible and increased in magnitude with the grey value which is captured by the prediction residual interval. The inflection in \\texttt{AbsNoFilter} at \\ang{120}, as discussed previously, can be seen more clearly here.\n\n\\begin{figure}\n  \\centering\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsNoFilterDeg30_spatial.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsNoFilterDeg120_spatial.eps}\n      \\caption{\\texttt{AbsNoFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n  \\centerline{\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsFilterDeg30_spatial.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{30}}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{\\subSize}\n      \\includegraphics[width=\\textwidth]{../figures/varmean/varMeanResidualAbsFilterDeg120_spatial.eps}\n      \\caption{\\texttt{AbsFilter} at \\ang{120}}\n  \\end{subfigure}\n  }\n  \\caption{Absolute value residuals from fitting a gamma GLM of the form ${y}(x)=\\beta_0+\\beta_1 x$ onto the sample variance-mean data obtained from the replicate projections. Highlighted in a dashed red box is an example of an inflection. The colour scales are in units of \\SI{}{\\adu^2}.}\n  \\label{fig:meanVar_spatialResidual}\n\\end{figure}\n\nBecause no spatial information was used in modelling the variance, the residuals were plotted on top of the projections to look for any spatial structure, this is shown in Figure \\ref{fig:meanVar_spatialResidual}. Because of the geometry of the test sample, lower grey values, thus smaller residuals, were found in the middle of the projection. Similarly, higher grey values, thus bigger residuals, were found on the edges of the test sample. Considering that, the residuals do not show any striking spatial structure. Again, the inflection in \\texttt{AbsNoFilter} at \\ang{120} can be seen more clearly here.\n\n\\section{Conclusion}\n\nVarious parametric models were investigated. A gamma GLM with identity and canonical link functions were looked at with different polynomial features. In terms of cross-validation, most of the models looked at have similar prediction performance when predicting the variance given a grey value. Thus, the relationship $\\widehat{y}(x)=\\beta_0+\\beta_1 x$ using the identity link is attractive for its simplicity and links with the compound Poisson model.\n\nIt was found that shading correction had little effect on the variance-mean relationship.\n\nAs discussed in the compound Poisson chapter, a linear relationship can be derived by assuming no beam hardening, then it should be expected that a linear relationship is observed in the dataset \\texttt{AbsFilter}. In the forward stepwise selection, \\texttt{AbsNoFilter} consistently selected the linear model, given the identity link function. \\texttt{AbsFilter} did not select the linear model but in terms of cross-validation, the linear model was just as good as the other models.\n\nIt was unusual to see an inflection in the sample variance-mean data in \\texttt{AbsNoFilter} at \\ang{120} which was not captured by the GLM. A good explanation was not found but perhaps the absence of an x-ray filter may have contributed to this. As a result, the \\texttt{AbsNoFilter} dataset was discarded in favour of the \\texttt{AbsFilter} dataset from the next chapter.\n\nThere exist model selection methods such as lasso and elastic net \\citep{tibshirani1996regression, zou2005regularization, friedman2010regularization} but they are catered for high dimensional problems involving hundreds of parameters. In this problem, only a few parameters were needed to find a good model thus forward stepwise selection was sufficient. More flexible models such as non-parametric and machine learning methods may be used, however, they are slow and are unnecessary in a low dimensional problem with a large number of data points.\n\nWith the ability to predict the variance given a grey value of a pixel, the uncertainty can be quantified. In the next chapter, the projection is compared to a simulated projection in the face of that uncertainty.\n", "meta": {"hexsha": "3587c3956734bdcc4850fbeea53d1f958a1c1109", "size": 42580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/thesis/chapters/4_variancePrediction.tex", "max_stars_repo_name": "shermanlo77/oxwasp_phd", "max_stars_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "reports/thesis/chapters/4_variancePrediction.tex", "max_issues_repo_name": "shermanlo77/oxwasp_phd", "max_issues_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "reports/thesis/chapters/4_variancePrediction.tex", "max_forks_repo_name": "shermanlo77/oxwasp_phd", "max_forks_repo_head_hexsha": "2b2d337356d35aa3db77dca4ef2a9bd3b6a45c12", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 99.2540792541, "max_line_length": 1023, "alphanum_fraction": 0.7601925787, "num_tokens": 11612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.8376199694135333, "lm_q1q2_score": 0.7731560330251485}}
{"text": "\\section{Abstract}\n\nFinding real roots of polynomials is a fundamental problem in scientific\ncomputing. This project aims to implement a real-root isolation program based on\nBudan’s Theorem and Continued Fraction. Both methods are developed from\nDescartes’ rule of signs and work only on square-free polynomials. Therefore,\nsquare-free decomposition is the very first step to isolate the roots of\npolynomials. This project applies Yun’s algorithm to make the polynomials have\nno repeated roots. And in order to handle errors that come from floating point\ncomputation, interval arithmetic is introduced to replace exact numbers. Besides\nthat, many methods are used to optimize the program and running time of these\ntwo algorithms are compared. This report also discusses how errors propagated\nthrough computation and how it affects the success of the program.\n", "meta": {"hexsha": "4b864e2d6f7193f59897fc07149973c920032a78", "size": 859, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/010abstract.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/010abstract.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/010abstract.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": 61.3571428571, "max_line_length": 80, "alphanum_fraction": 0.8265424913, "num_tokens": 169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9161096044278532, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7731004031848153}}
{"text": "\\paragraph{Definition} A clique of a graph $G$ is a connected subgraph of $G$ which is\r\nisomorphic to a complete graph. For simplicity, we shall denote cliques by the\r\ncomplete graph $K_t$ to which the clique is isomorphic where $t$ is a positive integer.\r\n\\paragraph{Lemma} Assume a bipartite graph has a clique $K_t$. Then $t \\leq 2$.\r\n\\paragraph{Proof of Lemma} By contradiction: we prove that if a graph has a clique\r\n$K_3$ then it is not bipartite. Further, for $n \\geq 3$, $K_n$ has a clique $K_3$, which can\r\nbe seen by considering the subgraph generated by any three vertices in $K_t$ and\r\nrealising that this subgraph is indeed $K_3$.\r\n\\paragraph{} Let $G$ be bipartite and assume it has a clique $K_3$. Label the vertices in $K_3$\r\nas $u,v,w$. A bipartite graph is a graph which has two disjoint subsets $V_1$ and\r\n$V_2$ contained in $V\\left(G\\right)$ such that $V_1 \\cup V_2 = V\\left(G\\right)$ and $G\\left[V_1\\right]$ and $G\\left[V_2\\right]$ are\r\nboth discrete, or empty. Choose such $V_1$ and $V_2$ and w.l.o.g. let $u \\in V_1$. Then, since $u$ \r\ncannot be adjacent to any vertex in $V_1$, we have $v,w \\in V_2$, which in turn \r\nimplies that $G\\left[V_2\\right]$ has the edge $vw$ and so is not empty. This contradiction\r\ntells us that $G$ cannot have a $K_3$ clique, which proves the lemma.\r\n$\\square$\r\n\\paragraph{Answer}For a bipartite graph $G$ with order greater than 5, we have that at\r\nleast one of $V_1$, $V_2$ is of order greater than or equal to 3, which implies that $\\bar{G}$\r\nhas a $K_3$ clique as every pair of non-adjacent vertices in $G$ are adjacent in $\\bar{G}$ (and vice\r\nversa) i.e. $\\bar{G}\\left[V_1\\right] \\cong K_{n\\left(V_1\\right)}$ and $\\bar{G}\\left[V_2\\right] \\cong K_{n\\left(V_2\\right)}$.\r\n", "meta": {"hexsha": "bd5722c0cefe8ef7617fb5fcca613be1963dffc0", "size": 1727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tut2/3.3.tex", "max_stars_repo_name": "h4tguy/gt-hons", "max_stars_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tut2/3.3.tex", "max_issues_repo_name": "h4tguy/gt-hons", "max_issues_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tut2/3.3.tex", "max_forks_repo_name": "h4tguy/gt-hons", "max_forks_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_forks_repo_licenses": ["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.2380952381, "max_line_length": 132, "alphanum_fraction": 0.7116386798, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942093072239, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7730853867450473}}
{"text": "\\section{Splines}\nIn many situations, breakpoints in the regression function do not make sense.\nWould forcing the piecewise polynomials to be continuous suffice? What\nabout continuous first derivatives? \n\nWe start by consider the subspaces of the piecewise polynomial \nspace. We will denote it with ${\\cal\n  PP}_k(\\bt)$ with $\\bt = (t_1,\\dots,t_m)'$ the break-points or\ninterior knots. Different break points define different spaces.\n \nWe can put constrains on the behavior of the functions\n$g$ at the break points. (We can construct tests to see if these\nconstrains are suggested by the data but, will not go into this here)\n\nHere is  a trick for forcing the constrains and keeping the linear\nmodel set-up. We can write any function $g \\in {\\cal PP}_k(\\bt)$ in\n{\\it the truncated basis power}:\n\\begin{eqnarray*}\ng(x) &=& \\theta_{0,1} + \\theta_{0,2} x + \\dots + \\theta_{0,k} x^{k-1}\n+\\\\\n&\\,&  \\theta_{1,1}(x-t_1)^0_+ + \\theta_{1,2} (x-t_1)^1_+ + \\dots +\n\\theta_{1,k} (x-t_1)^{k-1}_+ +\\\\\n&& \\vdots\\\\\n&& \\theta_{m,1}(x-t_m)^0_+ + \\theta_{m,2} (x-t_m)^1_+ + \\dots +\n\\theta_{m,k} (x-t_m)^{k-1}_+\n\\end{eqnarray*}\nwhere $(\\cdot)_+ = \\max(\\cdot,0)$. Written in this way the\ncoefficients $\\theta_{1,1},\\dots,\\theta_{1,k}$ record the jumps in the\ndifferent derivative from the first piece to the second. \n\nNotice that the constrains reduce the number of parameters. This is in\nagreement with the fact that we are forcing more smoothness.\n\nNow we can force constrains, such as continuity, by putting constrains\nlike $\\theta_{1,1}=0$ etc... \n\nWe will concentrate on the cubic splines which are continuous\nand have continuous first and second derivatives. In this case we can\nwrite:\n\\begin{eqnarray*}\ng(x) &=& \\theta_{0,1} + \\theta_{0,2} x + \\dots + \\theta_{0,4} x^3\n+ \\theta_{1,k} (x-t_1)^{3}+ \\dots + \\theta_{m,k} (x-t_m)^{3}\n\\end{eqnarray*}\nHow many ``parameters'' in this space? \n\nNote: It is always possible to have less restrictions at knots where we\nbelieve the behavior is ``less smooth'', e.g for the Sr ratios, we\nmay have ``unsmoothness'' around KTB. \n\nWe can write this as a linear space. This setting is not\ncomputationally convenient. In S-Plus there is a function {\\tt bs()}\nthat makes a basis that is convenient for computations. \n\nThere is asymptotic theory that goes along with all this but we will\nnot go into the details. We will just notice that \n\\[\n\\E[ f(x) - g(x) ] = O(h_l^{2k} + 1/n_l)\n\\]\nwhere $h_l$ is the size of the interval where $x$ is in and $n_l$ is\nthe number of points in it. What does this say?\n\n\n\\subsection{Splines in terms of Spaces and sub-spaces}\nThe$p$-dimensional\nspaces described in Section 4.1 were defined through basis function\n$B_j(\\bx), j=1,\\dots,p$. So \nin general we defined for a given range $I \\subset {\\mathbb R}^k$\n\\[\n{\\cal G} =\\{ g: g(\\bx) = \\sum_{j=1}^p \\theta_j \\beta_j(\\bx), \\bx \\in I,\n(\\theta_1,\\dots,\\theta_p) \\in {\\mathbb R}^p \\}\n\\]\n\nIn the previous section we concentrated on $\\bx \\in \\mathbb R$. \n\nIn practice we have design points $x_1,\\dots,x_n$ and a vector of\nresponses $\\by = (y_1,\\dots,y_n)$. We can think of $\\by$ as an element\nin the $n$-dimensional vector space ${\\mathbb R}^n$. In fact we can go\na step further and define a Hilbert space with the usual inner product\ndefinition that gives us the norm\n\\[\n||\\by|| = \\sum_{i=1}^n y_i^2\n\\]\nNow we can think of least squares estimation as the projection of the\ndata $\\by$ to the sub-space $\\bG \\subset {\\mathbb R}^n$ defined by $\\cal\nG$ in the following way \n\\[\n\\bG = \\{ \\g \\in {\\mathbb R}^n: \\g = [g(x_1),\\dots,g(x_n)]', g \\in\n{\\cal G} \\}\n\\]\nBecause this space is spanned by the vectors \n$[B_1(x_1),\\dots,B_p(x_n) ]$ the projection of $\\by$ onto $\\bG$ is \n\\[\n\\bB(\\bB'\\bB)^{-}\\bB'\\by\n\\]\nas learned in 751. Here $[\\bB]_{ij} = B_j(x_i)$.\n\n", "meta": {"hexsha": "9a659946011d100758bba4f195b5f6c03c8e1080", "size": 3744, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-04-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-04-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-04-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.5979381443, "max_line_length": 77, "alphanum_fraction": 0.6909722222, "num_tokens": 1226, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.9032942008463507, "lm_q1q2_score": 0.7730853778432232}}
{"text": "\\subsection{Sample Variance} \\label{sample_variance}\nThe sample variance based on \\cite{chan1983algorithms}. Given is a time series\n$Q = (q_1, q_2, \\dots, q_i, \\dots, q_l)$ with length $l > 0$ over the domain set $\\mathbb{U}$ and a distance measure\nfunction $d$ with $d: \\mathbb{U} \\times \\mathbb{U} \\to \\mathbb{R}$. The variance of a time series $Q$ can be\ncalculated by the following formula.\n\\begin{equation}\n    VAR(Q) = \\frac{1}{l}\\sum \\limits_{i=1}^{l} d(q_i, \\bar{q})^2\n\\end{equation}\nwhere $\\bar{q}$ is the mean of the time series $Q$ as mentioned in \\ref{time_series_normalization}. The sample variance\nis also a promising candidate as time series measure for a measure based filter.\n", "meta": {"hexsha": "5f913971eeea993c6329d6f0ddde5382bd7ee42c", "size": 693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bachelor-thesis/background_and_notation/sample_variance.tex", "max_stars_repo_name": "GordonLesti/SlidingWindowFilter", "max_stars_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-06-22T09:37:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-14T11:43:53.000Z", "max_issues_repo_path": "bachelor-thesis/background_and_notation/sample_variance.tex", "max_issues_repo_name": "GordonLesti/SlidingWindowFilter", "max_issues_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "bachelor-thesis/background_and_notation/sample_variance.tex", "max_forks_repo_name": "GordonLesti/SlidingWindowFilter", "max_forks_repo_head_hexsha": "22c11f2912a5c523ae8ad85a849e2d0b123536ec", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-11T23:15:57.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-11T23:15:57.000Z", "avg_line_length": 63.0, "max_line_length": 119, "alphanum_fraction": 0.7215007215, "num_tokens": 223, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9566342024724487, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.7730247321703142}}
{"text": "\\subsection{Basic Facts}\n\n\\begin{itemize}\n    \\item If square matrix $A$ is invertible (or inverse exists), then $\\boxed{A^{-1}A=AA^{-1}=I}$.\n    \\item Can test invertibility of matrix using elimination, i.e. the $n\\times n$ matrix $A$ must have $n$ nonzero pivots.\n    \\item If $\\mathrm{det}(A)\\neq 0$, then $A$ is invertible.\n\\end{itemize}\n\n\\subsection{Computing inverses}\n\nCan compute inverses with Gauss-Jordan, eliminating $[A\\:I]$ to $[I\\:A^{-1}]$. \nIf a matrix is invertible, then solution to $A\\tb{x}=\\tb{b}$ is $\\tb{x}=A^{-1}\\tb{b}$.\\\\\n\nA $2\\times 2$ matrix is only invertible if $ad-bc\\neq 0$:\n\n\\[\\boxed{\n    A^{-1}=\n    \\frac{1}{ad-bc}\n    \\begin{bmatrix}\n        d&-b\\\\\n        -c&a\n    \\end{bmatrix}\n.}\\]\n\nMatrix inversion occurs in reverse order:\n\n\\[\\boxed{(ABC)^{-1}=C^{-1}B^{-1}A^{-1}}.\\]", "meta": {"hexsha": "e6f3a0c498521324ab0ff9218e3d7d20e2a81967", "size": 804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/5_inverses.tex", "max_stars_repo_name": "sidnb13/latex-notes", "max_stars_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "linear-algebra/tex/5_inverses.tex", "max_issues_repo_name": "sidnb13/latex-notes", "max_issues_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "linear-algebra/tex/5_inverses.tex", "max_forks_repo_name": "sidnb13/latex-notes", "max_forks_repo_head_hexsha": "bbd935b7ff9781169775c052625b1917a47d5dcc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.7777777778, "max_line_length": 123, "alphanum_fraction": 0.6119402985, "num_tokens": 287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7729467393300138}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.10| in the Command Window, and type \\verb|edit lab_10_script| in the Command Window to edit \\verb|lab_10_script.m|.\n%\n\\section{Define Meshgrid and Evaluate Function at Meshgrid}\n\\begin{enumerate}[(a)]\n    \\item Define an anonymous function \\verb|f| using the following formula:\n        $$\n        f(x, y) = \\pi^2 [\\sin(\\pi x) + 4 \\sin(2\\pi x) + \\sin(\\pi y) + 4 \\sin(2 \\pi y)].\n        $$\n    \\item Define both \\verb|x| and \\verb|y| starting from -1 to 1 with 30 points using \\verb|linspace|.\n    \\item Create meshgrid by \\verb|[X, Y] = meshgrid(x, y);|\n    \\item Evaluate $f(x, y)$ at the mesh grid by \\verb|Z = f(X, Y)|.\n\\end{enumerate}\n%---------------------------------------------\n\\section{Mesh Plots}\n%---------------------------------------------\n\n\\begin{enumerate}[(a)]\n    \\item Run the script \\verb|lab_10_script.m|.\n    \\item Mimick the first subplot to create subplot 2, use \\verb|meshc(Z)| instead of \\verb|mesh(Z)|, change the colormap to \\verb|winter| and also change the title to be \\verb|winter| as well.\n    \\item Repeat the above step to create subplot 3 with \\verb|mesh(x, y, Z)| and colormap to be \\verb|pink|.\n    \\item Repeat the above step to create subplot 4 with \\verb|mesh(Z)| and colormap to be \\verb|prism|. Add \\verb|hidden off| to the line below the last line.\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{Surf Plots}\n%---------------------------------------------\nRepeat Part 2 to create 4 subplots.\n\\begin{enumerate}[(a)]\n    \\item For subplot 1, change \\verb|mesh(Z)| to \\verb|surf(Z)|.\n    \\item For subplot 2, change \\verb|meshc(Z)| to \\verb|surfc(Z)|.\n    \\item For subplot 3, change \\verb|mesh(x, y, Z)| to \\verb|surf(x, y, Z)|.\n    \\item For subplot 4, change \\verb|mesh(Z)| to \\verb|surf(Z)|.\n\\end{enumerate}\n\nAt last, run the script \\verb|lab_10_script.m|, it might take some time to save the figures. You will upload the script file \\verb|lab_10_script.m|, and two figure files \\verb|lab_10_figure_1.pdf|, \\verb|lab_10_figure_2.pdf| to Overleaf, and in \\verb|body.tex| change the caption for each figuer. Recompile, and submit the generated .pdf file on WyoCourses.\n", "meta": {"hexsha": "3f3afea6adcbfaf3775dc52ff23db12636e29f54", "size": 2434, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.10/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.10/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.10/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.6111111111, "max_line_length": 414, "alphanum_fraction": 0.6433853739, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8991213826762113, "lm_q1q2_score": 0.77294205029696}}
{"text": "\\section{Maximum likelihood estimation}\n\nLet $\\left\\{ E,\\left(\\mathbf{P}_{\\theta }\\right)_{\\theta \\in \\Theta }\\right\\}$  be a statistical model associated with a sample of i.i.d. random variables $X_1, X_2, \\dots , X_ n$. Assume that there exists $\\theta ^* \\in \\Theta$ such that $X_ i \\sim \\mathbf{P}_{\\theta ^*}$.\n\nThe \\textbf{likelihood} of the model is the product of the $n$ samples of the pdf/pmf:\n\n\\begin{align*}\nL_n{(X_1, X_2, \\dots , X_ n, \\theta)} = \\\\\n{\\begin{cases}\n    \\displaystyle \\prod_{i=1}^np_\\theta(x_i) & \\text{if }E\\text{ is discrete} \\\\\n    \\displaystyle \\prod_{i=1}^nf_\\theta(x_i) & \\text{if }E\\text{ is continous}\n\\end{cases}}\n\\end{align*}\nThe maximum likelihood estimator is the (unique) $\\theta$ that minimizes $\\widehat{\\text {KL}}\\left(\\mathbf{P}_{\\theta ^*}, \\mathbf{P}_{\\theta }\\right)$ over the parameter space. (The minimizer of the KL divergence is unique due to it being strictly convex in the space of distributions once  is fixed.)\n\\begin{align*}\n\\widehat{\\theta }_ n^{MLE}& = \\displaystyle \\text {argmin}_{\\theta \\in \\Theta }\\widehat{\\text {KL}}_ n\\left(\\mathbf{P}_{\\theta ^*}, \\mathbf{P}_{\\theta }\\right)\\\\\n&= \\displaystyle \\text {argmax}_{\\theta \\in \\Theta } \\sum _{i=1}^{n} \\ln p_{\\theta }(X_ i)\\\\  \n&= \\displaystyle \\text {argmax}_{\\theta \\in \\Theta } \\ln \\left(\\prod _{i=1}^{n} p_{\\theta }(X_ i)\\right)\n\\end{align*}\n\nSince taking derivatives of products is hard but easy for sums and $exp()$ is very common in pdfs we usually take the log of the likelihood function before maximizing it.\n\\begin{align*}\n\\ell((X_1, X_2, \\dots , X_ n, \\theta)) &= ln(L_n{(X_1, X_2, \\dots , X_ n, \\theta)})\\\\\n &= \\sum_{i=1}^n  ln(L_i(X_i,\\theta)\n\\end{align*}\n\nCookbook: set up the likelihood function, take log of likelihood function. Take the partial derivative of the loglikelihood function wrt. the parameter(s). Set the partial derivative(s) to zero and solve for the parameter.\n\nIf an indicator function on the pdf/pmf does not depend on the parameter, it can be ignored. If it depends on the parameter it can't be ignored because there is an discontinuity in the loglikelihood function. The maximum/minimum of the $X_i$ is then the maximum likelihood estimator.\n\n\\subsection{Fisher Information}\n\nThe Fisher information is the covariance matrix of the gradient of the loglikelihood function. It is equal to the negative expectation of the Hessian of the loglikelihood function and captures the negative of the expected curvature of the loglikelihood function.\\\\\n\nLet $\\theta \\in \\Theta \\subset \\mathbb {R}^ d$ and let $\\left(E,\\left\\{ \\mathbf{P}_\\theta \\right\\} _{\\theta \\in \\Theta }\\right)$ be a statistical model. Let $f_{\\theta }(\\mathbf x)$ be the pdf of the distribution $\\mathbf{P}_\\theta$. Then, the Fisher information of the statistical model is.\\\\\n\n$\\mathcal{I}(\\theta) = Cov(\\nabla \\ell(\\theta)) = \\\\ = \\mathbb{E}[\\nabla \\ell(\\theta))\\nabla\\ell(\\theta)^T] -  \\mathbb{E}[\\nabla \\ell(\\theta)]\\mathbb{E}[\\nabla \\ell(\\theta)] =\\\\ = -\\mathbb{E}[\\mathbb{H}\\ell(\\theta)]$\\\\\n\nWhere $\\ell (\\theta ) = \\ln f_\\theta (\\mathbf X)$.If $\\nabla\\ell(\\theta) \\in \\mathbb{R}^d$ it is a $d \\times d$ matrix. The definition when the distribution has a pmf $p_\\theta (\\mathbf x)$ is also the same, with the expectation taken with respect to the pmf.\\\\\n\nLet $(\\mathbb {R}, \\{ \\mathbf{P}_\\theta \\} _{\\theta \\in \\mathbb {R}})$ denote a continuous statistical model. Let $f_\\theta (x)$ denote the pdf (probability density function) of the continuous distribution $\\mathbf{P}_\\theta$. Assume that $f_\\theta (x)$ is twice-differentiable as a function of the parameter $\\theta$.\\\\\n\nFormula for the calculation of Fisher Information of $X$:\\\\\n\n$\\mathcal{I}(\\theta )= \\int _{-\\infty }^\\infty \\frac{\\left(\\frac{\\partial f_\\theta (x)}{\\partial \\theta }\\right)^2}{f_\\theta (x)} \\,  dx$ \\\\\n\nModels with one parameter (ie. Bernulli):\\\\\n\n$\\mathcal{I}(\\theta ) = \\textsf{Var}(\\ell '(\\theta ))$\\\\\n\n$\\mathcal{I}(\\theta ) = - \\mathbf{E}(\\ell ''(\\theta ))$\\\\\n\nModels with multiple parameters (ie. Gaussians):\\\\\n\n$\\mathcal{I}(\\theta ) = -\\mathbb E\\left[\\mathbf{H}\\ell (\\theta )\\right]$\\\\\n\nCookbook:\\\\\n\nBetter to use 2nd derivative.\\\\\n\n\\begin{itemize}\n  \\item Find loglikelihood\n  \\item Take second derivative (=Hessian if multivariate)\n  \\item Massage second derivative or Hessian (isolate functions of $X_i$ to use with $- \\mathbf{E}(\\ell ''(\\theta ))$ or $-\\mathbb E\\left[\\mathbf{H}\\ell (\\theta )\\right]$.\n  \\item Find the expectation of the functions of $X_i$ and subsitute them back into the Hessian or the second derivative. Be extra careful to subsitute the right power back. $\\mathbb{E}[X_i] \\neq \\mathbb{E}[X_i^2]$.\n  \\item Don't forget the minus sign!\n\\end{itemize}\n\n\\subsection{Asymptotic normality of the maximum likelihood estimator}\n\nUnder certain conditions the MLE is asymptotically normal and consistent. This applies even if the MLE is not the sample average.\n\nLet the true parameter $\\theta^{*} \\in \\Theta$. Necessary assumptions:\n\n\\begin{itemize}\n\\item The parameter is identifiable\n\\item For all $\\theta \\in \\Theta$, the support $\\mathbb{P}_{\\theta}$ does not depend on $\\theta$ (e.g. like in $Unif(0,\\theta)$);\n\\item $\\theta^{*}$ is not on the boundary of $\\Theta$;\n\\item Fisher information $\\mathcal{I}(\\theta)$  is invertible in the neighborhood of $\\theta^{*}$\n\\item A few more technical conditions\n\\end{itemize}\n\nThe asymptotic variance of the MLE is the inverse of the fisher information.\n\n$\\sqrt(n)(\\widehat{\\theta }_ n^{\\text {MLE}} - \\theta^*) \\xrightarrow[n \\rightarrow \\infty]{(d)} N_d(0,\\mathcal{I}(\\theta^* )^{-1})$\\\\", "meta": {"hexsha": "ab0a3f9401a7ab3e348e80e83cffb54610508562", "size": 5544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Likelihood.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/Likelihood.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/Likelihood.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": 65.2235294118, "max_line_length": 320, "alphanum_fraction": 0.696969697, "num_tokens": 1728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.899121366457407, "lm_q2_score": 0.8596637469145054, "lm_q1q2_score": 0.7729420428196646}}
{"text": "\\lab{The Shooting Method for Boundary Value Problems}{The Shooting Method for Boundary Value Problems}\n\\label{lab:Shooting}\n\nConsider a boundary value problem of the form\n\\begin{align}\n\t\\label{shooting_bvp}\n\t\\begin{split}\ny'' &= f(x,y,y'), \\quad a \\leq x \\leq b, \\\\\ny(a) &= \\alpha, \\quad y(b) = \\beta.\n\\end{split}\n\\end{align}\nOne natural way to approach this problem is to study the initial value problem (IVP) associated with this differential equation:\n\\begin{align}\n\t\\label{shooting_ivp}\n\t\\begin{split}\ny'' &= f(x,y,y'), \\quad a \\leq x \\leq b, \\\\\ny(a) &= \\alpha, \\quad y'(a) = t.\n\t\\end{split}\n\\end{align}\n\n\\begin{warn}\nHere, do not mistake $t$ as an independent time variable.\nIt is a parameter for the boundary condition.\nThe prime $'$ notation represents the derivative with respect to $x$, which is an important distinction later in this section.\n\\end{warn}\nThe goal is to determine an  appropriate value $t$ for the initial slope, so that the solution of the IVP is also a solution of the boundary value problem.\n\nLet $y(x,t)$ be the solution of \\eqref{shooting_ivp}.\nWe can rewrite the initial value conditions as\n\\begin{align}\ny(a, t) = \\alpha, \\quad y'(a, t) = t\n\\end{align}\nWe wish to find a value of $t$ so that $y(b,t) - \\beta = 0$.\nApplying Newton's method to the function $h(t) = y(b,t) - \\beta$, we obtain the iterative method\n\\begin{align*}\n\tt_{n+1} &= t_n - \\frac{ h(t_n)}{h'(t_n) }, \\\\\n\t&= t_n - \\frac{ y(b,t_n) - \\beta}{\\frac{d}{dt} \\left.y(b,t)\\right|_{t_n} },\\quad n = 0,1,\\ldots .\n\\end{align*}\n\nWe recall that Newton's method requires a good initial guess $t_0$; a plausible initial guess would be the average rate of change of the solution across the entire interval, so that $t_0 =  (\\beta - \\alpha)/(b-a)$.\nIf this initial guess is not sufficient, the initial guess may be refined by looking at the solution $y(x,t_0)$ of the initial value problem.\n\nThis method requires us to evaluate or approximate the function $\\frac{d}{dt} \\left.y(b,t)\\right|_{t_n}$.\nThis term may be approximated with a finite difference, giving us the iterative method\n\\[t_{n+1} = t_n - \\frac{ (y(b,t_n) - \\beta)(t_n - t_{n-1})}{y(b,t_n) - y(b,t_{n-1}) }, \\,\\, n = 1, 2,\\hdots\\]\nThis variation of the shooting algorithm is called the secant method, and requires two initial values instead of one.\nNotice that finding $y(b,t_n)$ requires solving the initial value problem using RK4 or some other method.\n\nFor example, consider the boundary value problem\n\\begin{equation}\n\\begin{split}\n\\label{bvp1}\ny'' &= -4y -9\\sin(x), \\,\\, x \\in [0,3\\pi/4],\\\\\ny(0) &= 1, \\\\\ny(3 \\pi/4) &= -\\frac{1+3\\sqrt{2}}{2}.\n\\end{split}\n\\end{equation}\nThe following code implements the secant method to solve \\eqref{bvp1}.\nNotice that \\li{odeint} is the solver used for the initial value problems.\n\n\\lstinputlisting[style=FromFile]{secant_method.py}\n\n% The following code employs the secant method to find the initial slope $y'(0) = t$ of a solution of \\ref{bvp1}.\n% The numerical solution may then be computed and plotted using \\li{dopri5} and \\li{matplotlib}.\n% \\ref{bvp1} has an exact solution $y(x) = \\cos(2x) + (1/2)\\sin(2x) -3\\sin(x)$.\n\n% Recall that the necessary dependencies are \\li{numpy} and the \\li{ode} class from \\newline \\li{scipy.integrate}.\n% The first step to finding the initial slope $y'(0) = t$ is to define the ODE as a first order system of differential equations, and to define the necessary parameters:\n% \\begin{lstlisting}\n% def ode_f(x,y): return numpy.array([y[1] , -4.*y[0] - 9.*numpy.sin(x)])\n%\n% a, b = 0., 3*numpy.pi/4.\n% alpha, beta =  1., -(1.+3*numpy.sqrt(2))/2.\n%\n% \\end{lstlisting}\n% To calculate $y(b,t_0)$ we use the \\li{ode} class:\n% \\begin{lstlisting}\n% reltol, abstol = 1e-9,1e-8\n% example = ode(ode_f).set_integrator('dopri5',atol=abstol,rtol=reltol)\n% example.set_initial_value(np.array([alpha,t0]),a)\n% y0 = example.integrate(b)[0]\n% \\end{lstlisting}\n\n% \\begin{problem} Use the secant method to solve the bvp\n% \\begin{equation*}\n% \\begin{split}\n% y'' &= -4y -9\\sin(x), \\quad x \\in [0,3\\pi/4],\\\\\n% y(0) &= 1, \\\\\n% y(3\\pi/4) &=-\\frac{1+3\\sqrt{2}}{2}.\n% \\end{split}\n% \\end{equation*}\n% When you code the secant method, be sure to include a maximum number of iterations, as well as an appropriate stopping criteria.\n% For example, if $|y(b,t_n)-\\beta|<10^{-8},$ you have likely found a solution.\n% \\end{problem}\n\n\\begin{problem}\nAppropriately defined initial value problems will usually have a unique solution.\nBoundary value problems are not so straightforward; they may have no solution or they may have several.\nYou may have to determine which solution is physically interesting.\nThe following bvp has at least two solutions.\nUsing the secant method, find both numerical solutions and their initial slopes.\n(Their plots are given in Figure \\ref{prob:shooting1}.)\nWhat initial values $t_0, t_1$ did you use to find them?\n\\begin{equation*}\n\\begin{split}\ny'' &= -4y -9\\sin(x), \\,\\, x \\in [0,\\pi],\\\\\ny(0) &= 1, \\\\\ny(\\pi) &=1.\n\\end{split}\n\\end{equation*}\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{Fig1.pdf}\n\\caption{Two solutions of $y'' = -4y -9\\sin(x),$ both satisfying the boundary conditions $y(0) = y(\\pi) = 1.$}\n\\label{prob:shooting1}\n\\end{figure}\n\\end{problem}\n\nLet us consider how to solve for $\\frac{d}{dt} y(b,t)$.\nWe will assume that the function $y(x,t)$ can be differentiated with respect to $x$ and $t$ in any order, and let  $z(x,t) = \\frac{d}{dt} y(x,t).$\nUsing the chain rule, we obtain\n\\begin{eqnarray*}\nz'' = \\frac{d}{dt} y''(x,t) &=& \\frac{\\partial f}{\\partial y} (x,y(x,t),y'(x,t)) \\cdot \\frac{dy}{dt}(x,t) ,\\\\\n&+& \\frac{\\partial f}{\\partial y'} (x,y(x,t),y'(x,t)) \\cdot \\frac{dy'}{dt}(x,t),\n\\end{eqnarray*}\nUsing the initial conditions associated with $y(x,t)$ and noting that $z(x, t) = \\frac{d}{dt}y(x, t)$ and $z'(x, t) = \\frac{d}{dt}y'(x, t)$, we obtain the following initial value problem for $z(x,t)$:\n\\begin{eqnarray*}\nz'' &=& \\frac{\\partial f}{\\partial y} (x,y,y') z + \\frac{\\partial f}{\\partial y'} (x,y,y') z'\n,\\,\\,a \\leq x \\leq b, \\\\\n z(a, t) &=& 0,\\ z'(a, t) = 1.\n\\end{eqnarray*}\n\nTo use Newton's method, the (coupled) IVPs for $y$ and $z$ must be solved simultaneously.\nThe iterative method then becomes\n\\[t_{n+1} = t_n - \\frac{ y(b,t_n) - \\beta}{z(b,t_n)}, \\,\\, n = 0,1,\\hdots\\]\n\n\\begin{problem}\nUse Newton's method to solve the BVP\n\\begin{equation*}\n\\begin{split}\ny'' &= 3 + \\frac{2y}{x^2}, \\,\\, x \\in [1,e],\\\\\ny(1) &= 6, \\\\\ny(e) &= e^2 + 6/e.\n\\end{split}\n\\end{equation*}\nPlot your solution.\n(Compare with Figure \\ref{prob:shooting2}.)\nWhat is an appropriate initial guess?\n\nHint: Update the ode() function from the previous problem to solve for $y$, $y'$, $z$, $z'$ simultaneously.\nThis can be done by first rewriting the equations for $y\"$ and $z\"$ as a system of first order differential equations.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{Fig2.pdf}\n\\caption{The solution of  $y'' = 3 + 2y/x^2,$ satisfying the boundary conditions $y(1) = 6$, $ y(e) =  e^2 + 6/e$.}\n\\label{prob:shooting2}\n\\end{figure}\n\\end{problem}\n\n\\section*{The Cannon Problem}\n\nConsider the problem of aiming a projectile at a given target.\nHere we will construct a differential equation that describes the path of the projectile and takes into account air resistance.\nWe will then use the shooting method to determine the angle at which the projectile should be launched.\n\nLet the coordinates of the projectile be given by $\\vec{r}(t) = \\langle x(t), y(t) \\rangle$.\nIf $\\theta(t)$ represents the angle of the velocity vector from the positive $x$-axis and $v(t)$ represents the speed of the projectile ($ |\\vec{v}(t) |$), then we have\n\\begin{align*}\n\\dot{x} &= v\\cos{\\theta},\\\\\n\\dot{y} &= v\\sin{\\theta}.\n%x' &= v\\cos{\\theta},\\\\\n%y' &= v\\sin{\\theta}.\n\\end{align*} Note that each of $x,y,\\theta$, and $v$ are functions of $t$, so the dot %prime\ndenotes $\\dfrac{d}{dt}$.\nThe tangent vector to the path traced by the projectile is the unit vector in the direction of the projectile's velocity, so $\\vec{T}(t) = \\langle \\cos{\\theta}, \\sin{\\theta} \\rangle$.\nThe unit normal vector $\\vec{N} (t)$ is given by $\\vec{N} (t)= \\langle -\\sin{\\theta}, \\cos{\\theta} \\rangle$.\nThus the relationship between basis vectors $\\vec{i}, \\vec{j}$, and $\\vec{T(t)}, \\vec{N}(t)$ is given by\n\\[\\left[\\begin{array}{cc}\\cos{\\theta} & \\sin{\\theta} \\\\-\\sin{\\theta} & \\cos{\\theta}\\end{array}\\right] \\left[\\begin{array}{c}\\vec{i} \\\\\\vec{j}\\end{array}\\right] = \\left[\\begin{array}{c}\\vec{T(t)} \\\\\\vec{N(t)}\\end{array}\\right]\\]\nLet $F_g$ represent the force on the projectile due to gravity, and $F_d$ represent the force on the projectile due to air resistance. (We assume the air is still.)\nFrom Newton's law we have\n\\begin{align*}\nm \\dot{\\vec{v}} &= F_g + F_d.\n%m \\vec{v}\\ ' &= F_g + F_d.\n\\end{align*}\n\nThe drag equation from fluid dynamics says that the force on the projectile due to air resistance is $k v^2 = (1/2)\\rho c_D A v^2$, where $\\rho$ is the mass density of air (about $1.225$ $\\text{kg}/\\text{m}^3$), $v$ is the speed of the projectile, and $A$ is its cross-sectional area.\nThe drag coefficient $c_D$ is a dimensionless quantity that changes with respect to the shape of the object.\n(If we assume our projectile is spherical with a diameter of $.2$ m, then its drag coefficient $c_D \\approx 0.47$, its cross-sectional area is $\\pi/100$ $ \\text{m}^2$, and we obtain $k \\approx 0.009$.)\n\nThus the total force on the shell is\n\\begin{align}\nm \\dot{\\vec{v}} &= -mg \\vec{j} - kv^2 \\vec{T},\\nonumber \\\\\n%m \\vec{v}\\ ' &= -mg \\vec{j} - kv^2 \\vec{T},\\nonumber \\\\\n&= -mg( \\sin{\\theta} \\vec{T} + \\cos{\\theta} \\vec{N} ) - kv^2 \\vec{T},\\nonumber\\\\\n&= (-mg \\sin{\\theta} - k v^2 ) \\vec{T} - mg \\cos{\\theta} \\vec{N}.\\label{eqn:TForce1}\n\\end{align}\nFrom the identity\n$\\vec{v} = \\langle \\dot{x}, \\dot{y} \\rangle = \\langle v \\cos{\\theta}, v \\sin{\\theta} \\rangle$\n%$\\vec{v} = \\langle x', y' \\rangle = \\langle v \\cos{\\theta}, v \\sin{\\theta} \\rangle$\nwe have\n\\begin{align}\nm \\dot{\\vec{v}} = {} & m\\langle \\dot{v} \\cos{\\theta} - v\\sin{\\theta} \\cdot \\dot{\\theta} ,\\dot{v}\\sin{\\theta} + v\\cos{\\theta} \\cdot \\dot{\\theta} \\rangle \\nonumber \\\\\n= {} & m(\\dot{v}\\cos{\\theta} - v\\sin{\\theta} \\cdot \\dot{\\theta})(\\cos{\\theta} \\vec{T} - \\sin{\\theta}\\vec{N}) \\nonumber \\\\\n& + m(\\dot{v} \\sin{\\theta} + v\\cos{\\theta} \\cdot \\dot{\\theta})( \\sin{\\theta} \\vec{T} + \\cos{\\theta} \\vec{N}) ,  \\nonumber \\\\\n= {} & m(\\vec{T} \\cdot \\dot{v} + \\vec{N} \\cdot v \\cdot \\dot{\\theta}) .\\label{eqn:TForce2}\n%\n%m \\vec{v}' = {} & m\\langle v' \\cos{\\theta} - v\\sin{\\theta} \\cdot \\theta' ,v'\\sin{\\theta} + v\\cos{\\theta} \\cdot \\theta' \\rangle \\nonumber \\\\\n%= {} & m(v'\\cos{\\theta} - v\\sin{\\theta} \\cdot \\theta')(\\cos{\\theta} \\vec{T} - \\sin{\\theta}\\vec{N}) \\nonumber \\\\\n%& + m(v' \\sin{\\theta} + v\\cos{\\theta} \\cdot \\theta')( \\sin{\\theta} \\vec{T} + \\cos{\\theta} \\vec{N}) ,  \\nonumber \\\\\n%= {} & m(\\vec{T} \\cdot v' + \\vec{N} \\cdot v \\cdot \\theta') .\\label{eqn:TForce2}\n\\end{align}\nFrom equations \\eqref{eqn:TForce1} and \\eqref{eqn:TForce2} we have\n\\begin{align*}\n%m v' &= -mg\\sin{\\theta} - k v^2,\\\\\nm \\dot{v} &= -mg\\sin{\\theta} - k v^2,\\\\\nmv\\dot{\\theta} &= -mg \\cos{\\theta}.\n%mv\\theta' &= -mg \\cos{\\theta}.\n\\end{align*}\nThus we have the coupled system of differential equations\n\\begin{align}\n\\dot{x} &= v\\cos{\\theta}, \\nonumber \\\\\n\\dot{y} &= v\\sin{\\theta},\\nonumber \\\\\n\\dot{v} &= -g\\sin{\\theta} -  k v^2/m,\\nonumber \\\\\n\\dot{\\theta} &= -g \\cos{\\theta}/v. \\nonumber\n%x' &= v\\cos{\\theta}, \\nonumber \\\\\n%y' &= v\\sin{\\theta},\\nonumber \\\\\n%v' &= -g\\sin{\\theta} -  k v^2/m,\\nonumber \\\\\n%\\theta' &= -g \\cos{\\theta}/v. \\nonumber\n\\end{align}\n\nThe independent variable $t$ used above is unessential to our problem.\nIf we assume that $t$ is an smooth invertible function of $x$ ($t = t(x)$), then we obtain\n\\begin{align*}\n\\frac{dy}{dx} &= \\frac{dy}{dt}\\frac{dt}{dx} ,\\\\\n&= \\frac{dy}{dt} \\frac{1}{v\\cos{\\theta}}, \\\\\n&= \\frac{v \\sin{\\theta}}{v\\cos{\\theta}} = \\tan{\\theta}.\n\\end{align*}\nWe find $\\frac{dv}{dx}$ and $\\frac{d\\theta}{dx}$ in a similar manner.\nThus our system of differential equations becomes\n\\begin{align}\n\t\\begin{split}\n\\frac{dy}{dx} &= \\tan {\\theta} ,\\\\\n\\frac{dv}{dx} &= -\\frac{g \\sin{\\theta} + \\mu v^2}{v \\cos{\\theta}},\\\\\n\\frac{d\\theta}{dx} &= -\\frac{g}{v^2}, \\label{eqn:cannon_DEs}\n\t\\end{split}\n\\end{align}\nwhere $\\mu = k/m.$\nIn the next problem we will assume that the projectile has a mass of about $60$ kg, so that $\\mu \\approx .0003$.\n\n\\begin{problem}\nSuppose a projectile is fired from a cannon with velocity $45\\text{ m/s}^2$.\nAt what angle $\\theta(0)$ should it be fired to land at a distance of $195\\text{ m}$?\n\nThere should be two initial angles $\\theta(0)$ that produce a solution for this bvp.\nUse the secant method to numerically compute and then plot both trajectories.\n\\begin{align}\n\t\\label{eqn:cannon_shooting}\n\t\\begin{split}\n\\frac{dy}{dx} &= \\tan {\\theta} ,\\\\\n\\frac{dv}{dx} &= -\\frac{g \\sin{\\theta} + \\mu v^2}{v \\cos{\\theta}},\\\\\n\\frac{d\\theta}{dx} &= -\\frac{g}{v^2},\\\\\ny(0)&= y(195) = 0,\\\\\nv(0) &= 45 \\text{ m/s}^2\n\t\\end{split}\n\\end{align}\n($g = 9.8067\\text{ m/s}^2$.)\nFind both solutions for this boundary value problem when $\\mu = .0003$.\nCompare with the solutions when $\\mu = 0.$\nTheir graphs are given in Figure \\ref{fig:shooting_cannon_comparison2}.\n\nHint: This is a system of three first order differential equations, and so our secant method requires a slight modification.\nKeeping in mind that the unknown initial condition is $\\theta(0)$, not $y'(0)$, define an appropriate function $h(t)$.\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Cannon_with_AirResistance.pdf}\n\\caption{Two solutions of the system of equations \\eqref{eqn:cannon_DEs}, both with initial conditions  $y(0) = 0 \\text{ m}$, $ v(0) = 45 \\text{ m/s}$, and $\\theta(0)=\\pi/3$.\nThe black curve is the trajectory of a projectile immune to air resistance ($\\mu = 0$).\nThe red curve describes the trajectory of a more realistic projectile ($\\mu = .0003$).}\n\\label{fig:shooting_cannon_comparison1}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Cannon_Shooting.pdf}\n\\caption{Two solutions of the boundary value problem \\eqref{eqn:cannon_shooting} when the air resistance is described by the parameter $\\mu = .0003$.\nAlso both solutions when air resistance is not described in the model ($\\mu = 0$).}\n\\label{fig:shooting_cannon_comparison2}\n\\end{figure} ", "meta": {"hexsha": "7ec9e52e93ae466f8ac8dccfd1a627f32c4c5dfb", "size": 14245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "acme-material/Labs/Volume4/ShootingMethod/Shooting.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/ShootingMethod/Shooting.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/ShootingMethod/Shooting.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.4618055556, "max_line_length": 284, "alphanum_fraction": 0.665005265, "num_tokens": 4825, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.7728990388224538}}
{"text": "\\lab{Algorithms}{Complex Numbers}{Complex Numbers}\n\\label{Lab:complex_intro}\n\n\\objective{Learn to perform basic computation and visualization with complex numbers.}\n\n\\begin{comment}\n\\section*{Arithmetic with complex numbers}\nComputationally, complex numbers are really just a pair of floating point numbers.\nThe first is understood to represent the real part of the complex number.\nThe second is understood to represent the imaginary part.\nIn Python, a complex number $a + b i$ can be defined using either of the following methods\n\\begin{lstlisting}\ncomplex(a, b)\na + 1.0j * b\n\\end{lstlisting}\nPython lets us define purely imaginary numbers using the syntax shown there with \\li{j}.\nAs another example, $2 i$ would be \\li{2.0j}.\n\nPython also includes the built in \\li{cmath} library.\nThis library provides basic math functions for complex numbers.\nFor examle, the functions \\li{polar} and \\li{rect} can be used to convert to and from polar coordinates (discussed below).\nIt also includes basic functions like \\li{sin}, \\li{cos}, etc. with their domains extended to the complex numbers.\n\nThere are some computational advantages and disadvantages to using complex numbers.\nAddition or subtraction between two complex numbers now requires two floating point operations (one for each part of the number), so it takes longer.\nMultiplication and division are more costly.\nMutliplication is easily seen to take 4 floating point multiplies and two floating point adds instead of just a single floating point multiply.\nThe fact that there two numbers are stored also increases the amount of floating point error that can be created in each computation.\n\nMost of the basic functions in NumPy support complex numbers.\nFore example, \\li{numpy.absolute} will take the absolute value of a complex number without any trouble.\nYou can also acces the real and imaginary parts of a complex array via the \\li{real} and \\li{imag} attributes.\nFor example,\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nZ = rand(10) + 1.0j * rand(10)\n# print real part\nprint Z.real\n# print imaginary part\nprint Z.imag\n\\end{lstlisting}\n\nThe complex conjugate of a complex number or array can be obtained using the \\li{conjugate} method.\nFor example, if \\li{A} is a complex number or complex array, its conjugate (or elementwise conjugate) is obtained via\n\\begin{lstlisting}\nA.conjugate()\n\\end{lstlisting}\n\\end{comment}\n\n\\section*{Polar Representation of Complex Numbers}\n\nOne of the most important results in Complex Analysis is Euler's Formula.\nIt states that:\n\n\\[e^{i\\theta}=cos(\\theta)+i sin(\\theta)\\]\n\nOne way to derive this important result is to consider the taylor series expansion of each of the functions involved.\n\nFrom this formula, we can see that $e^x$ maps the imaginary axis onto the unit circle on the complex plane.\nFrom our knowledge of the sine and cosine functios, we can also know that this mapping has a period of $2\\pi$.\nFrom here, notice that we may represent any number on the complex plane in the form $r e^{i\\theta}$ for $r\\geq 0$ and $0 \\leq \\theta \\leq 2\\pi$.\nThis is what is known as the polar representation of a complex number.\nConceptually, it is \\emph{identical} to the polar representation of points in the standard cartesian plane.\nThe primary difference is that, here we define a map from $\\mathbb{C}$ to the polar coordinates instead of from $\\mathbb{R}^{2}$ to the polar coordinates.\nThe number $\\theta$ is known as the argument, or phase, of a complex number.\nThe number $r$ is known as the modulus, magnitude, or absolute value of a complex number.\nIn the complex plane we define $|z|$ as the modulus of $z$ and $arg(z)$ as the argument of $z$.\nTo get the argument and the modulus for an array of complex numbers you can use the functions \\li{np.angle} and \\li{np.absolute} respectively.\n\n\\section*{Visualization of Complex Functions}\nFunctions that map the complex plane to itself cannot be visualized  the same ways we usually visualize functions that map $\\mathbb{R}$ to itself.\nSince $\\mathbb{C}$ is isomorphic to $\\mathbb{R}^2$, visualizing a mapping from the complex numbers to themselves is the same as vizualizing a mapping from $\\mathbb{R}^2 \\to \\mathbb{R}^2$.\nThis gives a hint at how we can go about visualizing complex valued functions.\nA complex valued plot can be thought of as two separate maps from $\\mathbb{R}^2 \\to \\mathbb{R}$.\nThe $arg(z)$ maps the function to a color.  The $|z|$ maps the number to the hue. The picture is what the identity map maps to Figure \\ref{fig:identity} \n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Identity.png}\n\\caption{Color plot of the identity map.}\n\\label{fig:identity}\n\\end{figure}\n\nThe colorize function below takes in an array of complex values and outputs the RBG colors for each point.\n\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    zy=np.flipud(z)\n    r = np.abs(zy)\n    arg = np.angle(zy)\n\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    c = np.vectorize(hls_to_rgb) (h,l,s) # --> tuple\n    c = np.array(c)  # -->  array of (3,n,m) shape, but need (n,m,3)\n    c = c.swapaxes(0,2)\n    c = c.swapaxes(0,1)\n    return c\n\\end{lstlisting}\n\nThe following code uses the colorize function to plot  $\\frac{x^2 - 1}{x}$ see \\ref{fig:example} for what the output looks like.\n\n\\begin{lstlisting}\ndef f(z):\n\treturn (z**2-1)/z\nxbounds=(-.5, 1.5)\nybounds=(-1, 1)\nres=401\nx = np.linspace(xbounds[0],xbounds[1], res)\ny = np.linspace(ybounds[0],ybounds[1], res)\nX,Y = np.meshgrid(x,y)\nZ=f(X+Y*1j)\nZc=colorize(Z)\nplt.imshow(Zc,extent=(xbounds[0],xbounds[1],ybounds[0],ybounds[1]))\nplt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{example.png}\n\\caption{Colorplot of the  function $\\frac{x^2 - 1}{x}$.}\n\\label{fig:example}\n\\end{figure}\n\n\\begin{problem}\nWrite a function called \\li{plot_complex} following the code above. Have it take in a function, xbounds, ybounds and a resolution.\n\\end{problem}\n\n\nFrom these plots you can see the poles and zeros. The zeros are the black dots and the poles are the white dots on the plots. the order of the pole or zero can be read from the number of times the full set of colors show up around the pole or zero. As you can see from Figure \\ref{fig:funcplot} $x^2-1$ has two zeros of order one at $1$ and $-1$. $x^4-\\frac{1}{x^4}$ has eight zeros of order one and a pole of order four. \nFor essential singularities the colors circle outward like in \\ref{fig:e}, the plot of $e^\\frac{1}{z}$.\n\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{function.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{function2.png}\n\\end{subfigure}\n\\caption{Colorplot of the  function $x^2 - 1$ and $x^4-\\frac{1}{x^4}$.}\n\\label{fig:funcplot}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{function1.png}\n\\caption{Color plot of the $e^\\frac{1}{z}$.}\n\\label{fig:e}\n\\end{figure}\n\n\\begin{problem}\n\nPlot the following functions and look at the plots. Write a function that prints out an estimate of the roots and/or poles and their order.\n\\begin{itemize}\n\\item Plot $e^z$ from $x \\in [-8,8]$ and $y \\in [-8,8]$, \\item $z^2-2z^7+2z^6-4z^5+2z^4-2z^3-5z^2+4z-4$ from $x \\in [-2.5,2.5]$ and $y \\in [-2.5,2.5]$ \n\\item Plot $\\frac{16z^4+32z^3+32z^2+16z+4}{16z^4-16z^3+5z^2}$ from $x \\in [-1,1]$ and $y \\in [-1,1]$,\n\\item Plot $\\sin{\\frac{1}{z}}$ from $x \\in [-.8,.8]$ and $y \\in [-.8,.8]$,\n\\end{itemize}\n\n\\end{problem}\n\n\\section*{Multi-Valued Functions}\n\nAnother important topic in Complex Analysis is the study of multiple valued functions.\nThese functions arise as we consider the inverses of functions that are not strictly one to one on the complex plane.\nA classic example is $\\sqrt{x}$, which may take two values for every nonzero point of the complex plane.\n\nIn the Real numbers we worked with functions like this by simply restricting their output on a certain domain.\nWe can do a similar thing in the Complex plane.\nLoosely speaking, such a restriction is called a branch.\nComputationally we restrict the output to a single portion of the actual possible values of the multifunction.\nWe call inverse functions that have multiple values like this ``multi-valued functions\" or ``multifuctions.\"\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\n\\begin{figure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{possqrt.png}\n\\end{subfigure}\n\\begin{subfigure}{.49\\textwidth}\n\\includegraphics[width=\\textwidth]{negsqrt.png}\n\\end{subfigure}\n\\caption{The positive and negative cut respectiviely of the function $\\sqrt{z}$.}\n\\label{fig:sqrt}\n\\end{figure}\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\n\\begin{problem}\nPlot three cuts of $\\ln\\left(z\\right)$ and$\\arctan{x}$ on $x \\in [-2,2]$ and $y \\in [-2,2]$\n\\end{problem}\n\nAll three of these functions can be made analytic at almost any point, except at their singularities, but that depends on how we cut the domain to give it a single value.\nWhen Integrating such functions, be careful about integrating across such cuts in the domain.\n\n\\begin{comment}\n\\begin{problem}\nWrite two functions, both accepting accept 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\\section*{Contour Integrals in the Complex Plane}\n\nFrom multivariable calculus, you may recall that an integral may be taken along a path.\nThis is very similar to what we can be done in the complex plane.\nConsider the function $f(z)$ on the complex plane.\nLet $z=x+iy$.\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 paramaterization 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 continous 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", "meta": {"hexsha": "7fc2e6379bb1deafaf298bca4a23986e225daa2c", "size": 16119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/complexnumbers/complexnumbers.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/complexnumbers/complexnumbers.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/complexnumbers/complexnumbers.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": 55.7750865052, "max_line_length": 422, "alphanum_fraction": 0.7420435511, "num_tokens": 4476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8774767922879693, "lm_q1q2_score": 0.772878986403635}}
{"text": " \\chapter{Continuous Latent Variables}\n \\label{chap:Continuous Latent Variables}\n \\section{Principal Component Analysis}\n \\subsection{Introduction}\n Principal Component Analysis is widely used for applications such as dimensionality reduction,lossy data compression,feature extraction,and data visualization.Also known as the Karhunen-Loeve transform.There are two definitions giving rise to the same algorithm.PCA can be defined as the orthogonal projection of the data onto a lower dimensional linear space,known as the principal subspace,such that the variance of the projected data  is maximized.Equivalently,it can be defined as the linear projection the minimizes the average projection cost,\ndefined as  the linear projection that minimizes the average projection cost,defined as the mean squared distance between the data points and their projections.\n\\subsection{Maximum variance formulation}\nConsider a data set of observations $\\{x_n\\}$ where $n = 1,...,N$,and $x_n$ is a Euclidean variable with dimensionality D.\nOur goal is to project the data onto a space having dimensionality $M < D$ while maximizing the variance of the projected\ndata.We define the direction of this space using a D-dimensional unit vector $\\mathbf{u_1^T}\\mathbf{u_1} = 1$.Each \ndata point $\\mathbf{x_n}$ is then projected onto a scalar value $\\mathbf{u_1^T}\\mathbf{x_n}$.The mean of the projected \ndata is $\\mathbf{u_1^T}\\bar{\\mathbf{x}}$ where the $\\bar{\\mathbf{x}}$ is the sample set mean given by\n\\begin{align}\n\\bar{\\mathbf{x}} = \\frac{1}{N}\\sum_{n=1}^{N}{\\mathbf{x_n}}\n\\end{align}                                  \nand the variance of the projected data is given by\n\\begin{align}\n\\frac{1}{N}\\sum_{n=1}^{N}\\{\\mathbf{u_1^T}\\mathbf{x_n} - \\mathbf{u_1^T}\\bar{\\mathbf{x}}\\}^2 \n&= \\frac{1}{N}\\sum_{n=1}^{N}{\\{\\mathbf{u_1^T}(\\mathbf{x_n} - \\bar{\\mathbf{x}})\\}^2} \\\\\n&= \\frac{1}{N}\\sum_{n=1}^{N}{\\{\\mathbf{u_1^T(\\mathbf{x_n - \\bar{\\mathbf{x}}})(\\mathbf{x_n -\\bar{x}})^T\\mathbf{u_1^T} }  \\}} \\\\\n&= \\mathbf{u_1^T}\\mathbf{S}\\mathbf{u_1}\n\\end{align}\nwhere $\\mathbf{S}$ is the data covariance matrix defined by\n\\begin{align}\n\\mathbf{S} = \\frac{1}{N}\\sum_{n=1}^{N}(\\mathbf{x_n}-\\bar{\\mathbf{x}})(\\mathbf{x_n}-\\mathbf{\\bar{x}})^T\n\\end{align}\nWe now maximize the projected variance $\\mathbf{u_1^T}\\mathbf{S}\\mathbf{u_1}$ with respect to $\\mathbf{u_1}$,which is a\nconstrained maximization to prevent $\\parallel\\mathbf{u_1}\\parallel\\rightarrow \\infty$ .The appropriate constraint \ncomes from the normalization condition $\\mathbf{u_1^T}\\mathbf{u_1}=1$.To enforce this constraint,we introduce a \nLagrange multiplier that we shall denote by $\\lambda_1$,and then make an unconstrained maximization of\n\\begin{equation}\n\\mathbf{u_1^T}\\mathbf{S}\\mathbf{u_1} + \\lambda_1(1-\\mathbf{u_1^T}\\mathbf{u_1})\n\\end{equation}\nBy setting the derivative with respect to $\\mathbf{u_1}$ equal to zero,we see that this quantity will have a stationary\npoint when\n\\begin{equation}\n\\mathbf{S}\\mathbf{u_1} = \\lambda_1\\mathbf{u_1}\n\\end{equation}\nwhich says that $\\mathbf{u_1}$ must be an eigenvector of $\\mathbf{S}$.If we left-multiply by $\\mathbf{u_1^T}$ and make use\nof $\\mathbf{u_1^T}{u_1} = 1$,we see that the variance is given by\n\\begin{equation}\n\\mathbf{u_1^TSu_1} = \\lambda_1\n\\end{equation}\nand so the variance will be a maximum when we set $\\mathbf{u_1}$ equal to the eigenvector having the largest \neigenvalue $\\lambda_1$.This eigenvector is known as the first principal component.\n\n\\subsection{Minimum-error formulation}\n\n\n\\subsection{Applications of PCA}\n\\subsection{PCA for high-dimensional data}\n\n\\section{Probabilistic PCA}\n\n\\section{Kernel PCA}\n\n\\section{Nonlinear Latent Variable Models}", "meta": {"hexsha": "4000d31c51ffa1a480ec16eb369a6e1c1343f1fd", "size": 3646, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Continuous Latent Variables.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/Continuous Latent Variables.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/Continuous Latent Variables.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": 63.9649122807, "max_line_length": 550, "alphanum_fraction": 0.7416346681, "num_tokens": 1137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8774767826757123, "lm_q1q2_score": 0.7728789806828584}}
{"text": "\\section{Complex eigenvalues and eigenvectors}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the complex eigenvalues and eigenvectors of a matrix.\n  \\item Diagonalize a matrix over the complex numbers.\n  \\end{enumerate}\n\\end{outcome}\n\nAn $n\\times n$-matrix is diagonalizable if and only if it has $n$\nlinearly independent eigenvectors. But as we saw in\nExample~\\ref{exa:no-real-eigenvalue}, if we work over the real\nnumbers, it can sometimes happen that a matrix has no eigenvalues, and\ntherefore no eigenvectors, at all. For example, the matrix\n\\begin{equation*}\n  A=\\begin{mymatrix}{rr}\n      0 & -1 \\\\\n      1 &  0 \\\\\n    \\end{mymatrix}\n\\end{equation*}\nhas characteristic polynomial $\\eigenvar^2+1$. Since the equation\n$\\eigenvar^2+1$ does not have any roots in the real numbers, there are\nno real eigenvalues.\n\nOn the other hand, the fundamental theorem of algebra tell us that\nover the {\\em complex} numbers, every non-constant polynomial has a\nroot. In fact, every polynomial of degree $n$ factors into $n$ linear\nfactors. Therefore, every matrix has at least one eigenvalue over the\ncomplex numbers%\n\\index{eigenvalue!complex}%\n\\index{matrix!eigenvalue!complex}%\n\\index{eigenvector!complex}%\n\\index{matrix!eigenvector!complex}%\n\\index{vector!eigenvector!complex}. Some matrices are diagonalizable\nover the complex numbers but not over the real numbers. An\nintroduction to complex numbers and the fundamental theorem of algebra\ncan be found in Appendix~\\ref{app:complex}.\n\n\\begin{example}{Complex eigenvalues and eigenvectors}{complex-eigenvalue1}\n  Find the eigenvectors and eigenvalues of\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rr}\n      0 & -1 \\\\\n      1 &  0 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  over the complex numbers. Diagonalize $A$ if possible.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is $\\eigenvar^2+1$. This has no roots\n  in the real numbers, but it has two roots $\\eigenvar=i$ and\n  $\\eigenvar=-i$\\, in the complex numbers. To find the eigenvectors for\n  $\\eigenvar=i$, we solve $(A-iI)\\vect{v}=\\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      -i & -1 & 0 \\\\\n      1 & -i & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowswap R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{rr|r}\n      1 & -i & 0 \\\\\n      -i & -1 & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_2\\rowop R_2+iR_1}{\\roweq}\\quad\n    \\begin{mymatrix}{rr|r}\n      1 & -i & 0 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the basic eigenvector for $\\eigenvar=i$\\, is\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Similarly, to find the eigenvectors for $\\eigenvar=-i$, we solve\n  $(A+iI)\\vect{v}=\\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{cc|c}\n      i & -1 & 0 \\\\\n      1 &  i & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowswap R_2}{\\roweq}\\quad\n    \\begin{mymatrix}{cc|c}\n      1 &  i & 0 \\\\\n      i & -1 & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_2\\rowop R_2-iR_1}{\\roweq}\\quad\n    \\begin{mymatrix}{cc|c}\n      1 & i & 0 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Thus, the basic eigenvector for $\\eigenvar=-i$\\, is\n  \\begin{equation*}\n    \\vect{v}_2 = \\begin{mymatrix}{r} -i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Since we have found two linearly independent eigenvectors, the\n  matrix $A$ is diagonalizable. We have $A=PDP^{-1}$, where\n  \\begin{equation*}\n    P =\n    \\begin{mymatrix}{cr}\n      i & -i \\\\\n      1 &  1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D =\n    \\begin{mymatrix}{cr}\n      i &  0 \\\\\n      0 & -i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Complex eigenvalues and eigenvectors}{complex-eigenvalue2}\n  Find the eigenvectors and eigenvalues of\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rr}\n      1 & -1 \\\\\n      1 &  1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  over the complex numbers. Diagonalize $A$ if possible.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    = \\begin{absmatrix}{cc}\n      1-\\eigenvar & -1 \\\\\n      1 & 1-\\eigenvar \\\\\n    \\end{absmatrix}\n    = (1-\\eigenvar)^2 + 1\n    = \\eigenvar^2 - 2\\eigenvar + 2.\n  \\end{equation*}\n  To find the roots, we use the quadratic formula. The roots are given\n  by:\n  \\begin{equation*}\n    \\eigenvar\n    = \\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}\n    = \\frac{2\\pm\\sqrt{-4}}{2} = 1\\pm i.\n  \\end{equation*}\n  Note that since the discriminant $b^2-4ac$ is negative, there are no\n  real solutions. However, we find two complex solutions $\\eigenvar=1+i$\n  and $\\eigenvar=1-i$. To find the eigenvectors for $\\eigenvar=1+i$, we\n  solve the equation $(A-(1+i)I)\\vect{v}=\\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr|r}\n      -i & -1 & 0 \\\\\n      1 & -i & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\ldots\\roweq\\quad\n    \\begin{mymatrix}{rr|r}\n      1 & -i & 0 \\\\\n      0 & 0 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The basic eigenvector for $\\eigenvar=1+i$\\, is\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{c} i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Similarly, the basic eigenvector for $\\eigenvar=1-i$\\, is\n  \\begin{equation*}\n    \\vect{v}_2 = \\begin{mymatrix}{r} -i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  Since we have found two linearly independent eigenvectors, the\n  matrix $A$ is diagonalizable. We have $A=PDP^{-1}$, where\n  \\begin{equation*}\n    P =\n    \\begin{mymatrix}{cr}\n      i & -i \\\\\n      1 &  1 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D =\n    \\begin{mymatrix}{cc}\n      1+i &  0 \\\\\n      0 & 1-i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Diagonalize a matrix over the complex numbers}{complex-diagonalize}\n  Diagonalize the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      -3 & -2 & 4 \\\\\n      2  &  1 & 0 \\\\\n      -2 & -2 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    p(\\eigenvar)\n    = (-3-\\eigenvar)(1-\\eigenvar)(3-\\eigenvar) - 16 + 8(1-\\eigenvar) + 4(3-\\eigenvar)\n    = -\\eigenvar^3 + \\eigenvar^2 - 3\\eigenvar - 5.\n  \\end{equation*}\n  By trial and error, we find that $\\eigenvar=-1$ is one of the\n  roots. We factor out $(\\eigenvar + 1)$:\n  \\begin{equation*}\n    p(\\eigenvar) = (\\eigenvar+1)(-\\eigenvar^2 + 2\\eigenvar - 5).\n  \\end{equation*}\n  We then use the quadratic formula to find the other two eigenvalues,\n  i.e., the roots of $-\\eigenvar^2 + 2\\eigenvar - 5$. They are:\n  \\begin{equation*}\n    \\eigenvar = \\frac{-2\\pm\\sqrt{-16}}{-2} = 1\\pm 2i.\n  \\end{equation*}\n  Eigenvectors:\n  \\begin{itemize}\n  \\item For $\\eigenvar=-1$, we solve $(A-(-1)I)\\vect{v}=\\vect{0}$:\n    \\begin{equation*}\n      \\begin{mymatrix}{rrr|r}\n        -2 & -2 & 4 & 0 \\\\\n        2  &  2 & 0 & 0 \\\\\n        -2 & -2 & 4 & 0 \\\\\n      \\end{mymatrix}\n      \\quad\\roweq\\ldots\\roweq\\quad\n      \\begin{mymatrix}{rrr|r}\n        1 & 1 &  0 & 0 \\\\\n        0 & 0 &  1 & 0 \\\\\n        0 & 0 &  0 & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The basic eigenvector is\n    \\begin{equation*}\n      \\vect{v}_1 = \\begin{mymatrix}{r} -1 \\\\ 1 \\\\ 0 \\end{mymatrix}.\n    \\end{equation*}\n  \\item For $\\eigenvar=1+2i$, we solve $(A-(1+2i)I)\\vect{v}=\\vect{0}$:\n    \\begin{eqnarray*}\n      \\begin{mymatrix}{ccc|c}\n        -4-2i & -2  & 4    & 0 \\\\\n        2     & -2i & 0    & 0 \\\\\n        -2    & -2  & 2-2i & 0 \\\\\n      \\end{mymatrix}\n      & \\stackrel{R_1\\rowop-R_1/2}{\n        \\stackrel{R_2\\rowop R_2/2}{\n        \\stackrel{R_3\\rowop -R_3/2}{\\roweq}}} &\n      \\begin{mymatrix}{ccc|c}\n        2+i &  1 &  -2 & 0 \\\\\n        1   & -i &  0  & 0 \\\\\n        1   &  1 & i-1 & 0 \\\\\n      \\end{mymatrix}\n      \\\\\n      &\\stackrel{R_1\\rowswap R_2}{\\roweq} &\n      \\begin{mymatrix}{ccc|c}\n        1   & -i &  0  & 0 \\\\\n        2+i &  1 &  -2 & 0 \\\\\n        1   &  1 & i-1 & 0 \\\\\n      \\end{mymatrix}\n      \\\\\n      & \\stackrel{R_2\\rowop R_2-(2+i)R_1}{\n        \\stackrel{R_3\\rowop R_3-R_1}{\\roweq}} &\n      \\begin{mymatrix}{ccc|c}\n        1   & -i  &  0  & 0 \\\\\n        0   & 2i  & -2  & 0 \\\\\n        0   & 1+i & i-1 & 0 \\\\\n      \\end{mymatrix}\n      \\\\\n      & \\stackrel{R_2 \\rowop R_2/2i}{\n        \\stackrel{R_3 \\rowop R_3/(1+i)}{\\roweq}} &\n      \\begin{mymatrix}{ccc|c}\n        1   & -i  &  0  & 0 \\\\\n        0   & 1  &   i  & 0 \\\\\n        0   & 1   &  i  & 0 \\\\\n      \\end{mymatrix}\n      \\\\\n      & \\stackrel{R_1 \\rowop R_1+iR_2}{\n        \\stackrel{R_3 \\rowop R_3-R_2}{\\roweq}} &\n      \\begin{mymatrix}{ccc|c}\n        1     & 0   & -1  & 0 \\\\\n        0     & 1   & i   & 0 \\\\\n        0     & 0   & 0   & 0 \\\\\n      \\end{mymatrix}.\n    \\end{eqnarray*}\n    The basic eigenvector is\n    \\begin{equation*}\n      \\vect{v}_2 = \\begin{mymatrix}{r} 1 \\\\ -i \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n  \\item For $\\eigenvar=1-2i$, we solve $(A-(1-2i)I)\\vect{v}=\\vect{0}$:\n    \\begin{equation*}\n      \\begin{mymatrix}{ccc|c}\n        -4+2i & -2  & 4    & 0 \\\\\n        2     &  2i & 0    & 0 \\\\\n        -2    & -2  & 2+2i & 0 \\\\\n      \\end{mymatrix}\n      \\quad\\roweq\\ldots\\roweq\\quad\n      \\begin{mymatrix}{ccc|c}\n        1     & 0   & -1  & 0 \\\\\n        0     & 1   & -i  & 0 \\\\\n        0     & 0   & 0   & 0 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The basic eigenvector is\n    \\begin{equation*}\n      \\vect{v}_3 = \\begin{mymatrix}{c} 1 \\\\ i \\\\ 1 \\end{mymatrix}.\n    \\end{equation*}\n    Therefore, $A=PDP^{-1}$, where\n    \\begin{equation*}\n      P =\n      \\begin{mymatrix}{ccc}\n        -1 &  1 & 1 \\\\\n        1  & -i & i \\\\\n        0  &  1 & 1 \\\\\n      \\end{mymatrix}\n      \\quad\\mbox{and}\\quad\n      D =\n      \\begin{mymatrix}{ccc}\n        -1 &  0   & 0    \\\\\n        0  & 1+2i & 0    \\\\\n        0  &  0   & 1-2i \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{itemize}\n\\end{solution}\n\nIn Example~\\ref{exa:complex-eigenvalue1}, the complex eigenvalues were\n$i$ and $-i$. In Example~\\ref{exa:complex-eigenvalue2}, the complex\neigenvalues were $1+i$ and $1-i$. In\nExample~\\ref{exa:complex-diagonalize}, the complex eigenvalues were\n$1+2i$ and $1-2i$, and there was also a real eigenvalue of $-1$.  Is\nit a coincidence that the complex eigenvalues always come in conjugate\npairs? The following proposition states that this is always the case.\n\n\\begin{proposition}{Complex conjugate eigenvalues}{conjugate-eigenvalues}\n  Let $A$ be a square matrix whose entries are real numbers. If\n  $\\eigenvar$ is an eigenvalue of $A$, then so is $\\conjugate{\\eigenvar}$.\n\\end{proposition}\n\n\\begin{proof}\n  Assume $\\eigenvar$ is an eigenvalue of $A$ with corresponding\n  eigenvector $\\vect{v}$. Then $A\\vect{v} = \\eigenvar\\vect{v}$. Taking\n  complex conjugates of both sides of the equation, we have\n  $\\conjugate{A\\vect{v}} = \\conjugate{\\eigenvar\\vect{v}}$, and therefore\n  $\\conjugate{A}\\conjugate{\\vect{v}} =\n  \\conjugate{\\eigenvar}\\conjugate{\\vect{v}}$. Since $A$ is matrix with\n  real entries, we have $\\conjugate{A}=A$, and therefore\n  $A\\conjugate{\\vect{v}} = \\conjugate{\\eigenvar}\\conjugate{\\vect{v}}$.\n  It follows that $\\conjugate{\\eigenvar}$ is an eigenvalue of $A$ with\n  corresponding eigenvector $\\conjugate{\\vect{v}}$.\n\\end{proof}\n\nIt is important to note that even over the complex numbers, not all\nmatrices are diagonalizable. On the one hand, the characteristic\npolynomial of an $n\\times n$-matrix always factors into $n$ linear\nfactors over the complex numbers. Therefore, the sum of the algebraic\nmultiplicities%\n\\index{algebraic multiplicity!of an eigenvalue}%\n\\index{eigenvalue!algebraic multiplicity}%\n\\index{multiplicity!of eigenvalue!algebraic} of the eigenvalues is\nalways $n$. However, it can still happen that the geometric\nmultiplicity%\n\\index{geometric multiplicity!of an eigenvalue}%\n\\index{eigenvalue!geometric multiplicity}%\n\\index{multiplicity!of eigenvalue!geometric} of some eigenvalue is\nless than its algebraic multiplicity. In that case, the matrix is not\ndiagonalizable, even over the complex numbers. We have:\n\n\\begin{proposition}{Diagonalizability criterion}{complex-diagonalizability}\n  A square matrix $A$ is diagonalizable over the complex numbers if\n  and only if the geometric multiplicity of each eigenvalue is equal\n  to its algebraic multiplicity.\n\\end{proposition}\n\n\\begin{proof}\n  Let $A$ be an $n\\times n$-matrix. By the fundamental theorem of\n  algebra, the characteristic polynomial factors into $n$ linear\n  factors. Therefore, the sum of the algebraic multiplicities of all\n  the eigenvalues is $n$. We know by\n  Proposition~\\ref{prop:dimension-eigenspace} that the geometric\n  multiplicity of each eigenvalue less than or equal to its algebraic\n  multiplicity. If the geometric multiplicity of each eigenvalue is\n  equal to its algebraic multiplicity, then the sum of the geometric\n  multiplicities is $n$, and therefore $A$ is diagonalizable by\n  Proposition~\\ref{prop:multiplicity-and-diagonalization}. On the\n  other hand, if the geometric multiplicity of some eigenvalue is less\n  than its algebraic multiplicity, then the sum of the geometric\n  multiplicities is less than $n$, and $A$ is not diagonalizable.\n\\end{proof}\n\n\\begin{example}{Non-diagonalizable matrix}{complex-non-diagonalizable}\n  Show that the matrix $A =\n    \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      0 & 1\n    \\end{mymatrix}$ cannot be diagonalized, even over the complex numbers.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is $(1-\\eigenvar)^2$, and therefore\n  the only eigenvalue is $\\eigenvar=1$, with algebraic multiplicity\n  $2$. On the other hand, the eigenspace for $\\eigenvar=1$ is\n  $1$-dimensional:\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      0 & 0\n    \\end{mymatrix}\n    \\vect{v}\n    = \\begin{mymatrix}{r} 0 \\\\ 0 \\end{mymatrix}\n  \\end{equation*}\n  has a $1$-dimensional solution space. Therefore, we can find only one\n  basic eigenvector, and the matrix is not diagonalizable.\n\\end{solution}\n\nTo finish up this chapter, we will consider an application of complex\neigenvalues. We will solve a recurrence as in\nSection~\\ref{sec:recurrence}. But this time, although the recurrence\nrelation only uses real numbers, complex numbers will be required to\nsolve it.\n\n\\begin{example}{Solving a recurrence using complex eigenvalues}{recurrence-complex}\n  Consider the sequence of numbers defined by the recurrence\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      f_0 &=& 1, \\\\\n      f_1 &=& 3, \\\\\n      f_{n+2} &=& 2f_{n+1} - 2f_n, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n  Solve the recurrence, i.e., find a closed formula for $f_n$.\n\\end{example}\n\n\\begin{solution}\n  The first few members of the sequence are:\n  \\begin{equation*}\n    1, 3, 4, 2, -4, -12, -16, -8, 16, \\ldots\n  \\end{equation*}\n  To solve the recurrence, let\n  \\begin{equation*}\n    \\vect{v}_n = \\begin{mymatrix}{c} f_n \\\\ f_{n+1} \\end{mymatrix},\n  \\end{equation*}\n  so that for all $n\\geq 0$,\n  \\begin{equation*}\n    \\vect{v}_{n+1}\n    = \\begin{mymatrix}{c} f_{n+1} \\\\ f_{n+2} \\end{mymatrix}\n    = \\begin{mymatrix}{c} f_{n+1} \\\\ 2f_{n+1} - 2f_n \\end{mymatrix}\n    = \\begin{mymatrix}{rr}\n      0  & 1 \\\\\n      -2 & 2 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} f_n \\\\ f_{n+1} \\end{mymatrix}\n    = \\begin{mymatrix}{rr}\n      0  & 1 \\\\\n      -2 & 2 \\\\\n    \\end{mymatrix}\n    \\vect{v}_n.\n  \\end{equation*}\n  We then diagonalize the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      0  & 1 \\\\\n      -2 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The characteristic polynomial is\n  \\begin{equation*}\n    p(\\eigenvar) = \\eigenvar^2 - 2\\eigenvar + 2.\n  \\end{equation*}\n  The eigenvalues are the roots of the characteristic polynomial. We\n  compute them using the quadratic formula:\n  \\begin{equation*}\n    \\eigenvar_1,\\eigenvar_2\n    = \\frac{2\\pm\\sqrt{4-8}}{2}\n    = \\frac{2\\pm2i}{2}\n    = 1\\pm i.\n  \\end{equation*}\n  To find the eigenvectors for $\\eigenvar_1 = 1+i$, we solve the\n  equation $(A-(1+i)I)\\vect{v} = \\vect{0}$:\n  \\begin{equation*}\n    \\begin{mymatrix}{cc|r}\n      -1-i & 1 & 0 \\\\\n      -2 & 1-i & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\stackrel{R_1\\rowop (1-i)R_1}{\\roweq}\\quad\n    \\begin{mymatrix}{cc|r}\n      -2 & 1-i & 0 \\\\\n      -2 & 1-i & 0 \\\\\n    \\end{mymatrix}\n    \\quad\\roweq\\quad\n    \\begin{mymatrix}{cc|r}\n      -2 & 1-i & 0 \\\\\n      0  &  0  & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  A basic eigenvector for $\\eigenvar=1+i$\\, is\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{c} 1-i \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Similarly, a basic eigenvector for $\\eigenvar=1-i$\\, is\n  \\begin{equation*}\n    \\vect{u} = \\begin{mymatrix}{r} 1+i \\\\ 2 \\end{mymatrix}.\n  \\end{equation*}\n  Since we have found two linearly independent eigenvectors, the\n  matrix $A$ is diagonalizable. We have $A = PDP^{-1}$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{cc}\n      1-i & 1+i \\\\\n      2   & 2   \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{cc}\n      1+i & 0   \\\\\n      0   & 1-i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The inverse of $P$ is\n  \\begin{equation*}\n    P^{-1} =\n    \\frac{1}{4}\n    \\begin{mymatrix}{cc}\n      2i  & 1-i \\\\\n      -2i & 1+i \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Finally, we use this information to solve the recurrence:\n  \\begin{eqnarray*}\n    f_n\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}\n        \\begin{mymatrix}{c} f_n \\\\ f_{n+1} \\end{mymatrix} \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}\\vect{v}_n \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}A^n\\,\\vect{v}_0 \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}PD^nP^{-1}\\,\\vect{v}_0 \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}\n        \\begin{mymatrix}{cc} 1-i & 1+i \\\\ 2 & 2 \\end{mymatrix}\n        \\begin{mymatrix}{cc} (1+i)^n & 0 \\\\ 0 & (1-i)^n \\end{mymatrix}\n        \\frac{1}{4}\n        \\begin{mymatrix}{cc} 2i & 1-i \\\\ -2i & 1+i \\end{mymatrix}\n        \\begin{mymatrix}{c} 1 \\\\ 3 \\end{mymatrix} \\\\\n    &=& \\frac{1}{4}\n        \\begin{mymatrix}{cc} 1-i & 1+i \\end{mymatrix}\n        \\begin{mymatrix}{cc} (1+i)^n & 0 \\\\ 0 & (1-i)^n \\end{mymatrix}\n        \\begin{mymatrix}{c} 3-i \\\\ 3+i \\end{mymatrix} \\\\\n    &=& \\frac{1}{4}\\paren{(1-i)(1+i)^n(3-i) + (1+i)(1-i)^n(3+i)} \\\\\n    &=& \\frac{1}{4}\\paren{(2-4i)(1+i)^n + (2+4i)(1-i)^n} \\\\\n    &=& \\frac{1}{2}\\paren{(1-2i)(1+i)^n + (1+2i)(1-i)^n}.\n  \\end{eqnarray*}\n  We can use this, for example, to calculate the $8\\th$ element of the\n  sequence:\n  \\begin{equation*}\n    f_8\n    ~=~ \\frac{1}{2}\\paren{(1-2i)(1+i)^8 + (1+2i)(1-i)^8}\n    ~=~ \\frac{1}{2}\\paren{(1-2i)16 + (1+2i)16}\n    ~=~ \\frac{32}{2}\n    ~=~ 16.\n  \\end{equation*}\n\n\\end{solution}\n", "meta": {"hexsha": "0433a32a994789a5356a51e5c85a368cd9ae2896", "size": 18482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Complex.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-Complex.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-Complex.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.5426497278, "max_line_length": 85, "alphanum_fraction": 0.6023698734, "num_tokens": 6996, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8757869965109765, "lm_q1q2_score": 0.7728188453839728}}
{"text": "\\section{Algebra}\r\n\\subsection{General Algebra}\r\n{\\bf Solving low degree univariate polynomials:}\r\nFor \\emph{quadratic},  $x^2+px+q=0$, $(x_1-x_2)= {\\sqrt D}, D= p^2-4q, x_1+x_2=p$.\r\nFor \\emph{cubic}, $az^3 + bz^2 + cz + d= f(z)$, substitute $z= x - {\\frac {b} {3a}}$ and\r\ndivide by $a$ to get $x^3+ px+ q= 0$.  Put $x= (u+v)$, get $p=3uv$,\r\n$q= u^3 + v^3$.  Following Galois, note $S_3 \\supseteq A_3 \\supseteq 1$,\r\n$(x_1 -x_2)(x_1-x_3)(x_2-x_3)= {\\sqrt D}, D= -4p^3-27q^2$.  After adjoining\r\n${\\sqrt D}$, we are left with an irreducible cubic.  Put $\\rho=\r\n-{\\frac 1 2} + {\\frac 1 2} {\\sqrt {-3}}$ and \r\n$(1,x_1 )= x_1 +x_2 + x_3$, $(\\rho, x_1 )= x_1 + \\rho x_2 + \\rho^2 x_3$,\r\n$(\\rho^2, x_1 )= x_1 + \\rho^2 x_2 + \\rho x_3$, then\r\n$(\\rho, x_1 )^3= \\sum x_i^3  - {\\frac 3 2} \\sum x_i^2 x_j + 6 x_1 x_2 x_3$.\r\n$(\\rho, x_1 )^3= - {\\frac {27} {2}}q + {\\frac 3 2} {\\sqrt {-3}} {\\sqrt {D}}$ and\r\n$(\\rho^2, x_1 )^3= - {\\frac {27} {2}}q - {\\frac 3 2} {\\sqrt {-3}} {\\sqrt {D}}$.\r\nSolution is:\r\n$x= ({-{\\frac {p} {2}} +- {\\sqrt {{\\frac{q^2} {4}} + {\\frac {p^3} {27}}}}})^{\\frac {1} {3}}$.  \r\nFor \\emph{quartic}, $az^4 + bz^3 + cz^2 + dz+e= f(z)$, \r\nsubstitute $x= x - {\\frac {b} {4a}}$ and\r\ndivide by $a$ to get $x^4+ px^2 + qx + r$.  Again following Galois,\r\n$S_4 \\supseteq A_4 \\supseteq C_4 \\supseteq Z_2 \\supseteq 1$.  \r\n$\\Theta_1 = (x_1+x_2)(x_3+x_4)$ is fixed by $C_4$ but not $A_4$.\r\nThe $\\Theta_i$ are solutions of $\\Theta^3 -b_1 \\Theta^2 + b_2 \\Theta_3 -b_3$ with\r\n$b_1= 2p, b_2= p^2-4r, b_3= -q^2$ and\r\n$D=16 p^4r-4p^3q^2-128p^2r^2+144 p q^2r -27 q^4 +256 r^3$.\r\nLook at\r\n$(y^2 + p)^2 = py^2 -qy -r$ and pick $z$ to make right hand side\r\n$(y^2 + p + z)^2 = (p+2z)y^2 -qy + (p^2 -r +2pz + z^2 )$ a perfect square.\r\n\\\\\r\n\\\\\r\n{\\bf Fundamental Theorem of Algebra:}  If $f(z) \\in {\\mathbb C}[x]$ then $f(z)=0$\r\nhas a solution (\\emph{root}) in ${\\mathbb C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $f(z)= z^n+ a_{n-1} x^{n-1} + ... + a_0$ and \r\n$\\mu= \\textnormal{inf}(|f(z)|)$.   If \r\n$\\mu = 0$, we're done since the minimum must occur in bounded ball.  So assume\r\n$\\mu \\ne 0$.  Let the minimum occur at $z_{0}$ and put\r\n$f(z_{0})= w_{0}$,\r\n$w=f(z_{0}+ \\zeta)$.  ${\\frac {w} {w_{0}}}= 1+q \\zeta^{\\nu}(1+\\zeta \\xi)=\r\n1-h \\rho^{\\nu}(1+ \\zeta \\xi)$ where $\\zeta= \\rho (cos(\\theta) + i sin(\\theta))$ and\r\n$q= h(cos(\\lambda) + i sin(\\lambda))$.  So we can find a point with smaller modulus than\r\n$w_0$.  This contradicts the assumed minimality at $z_0$.\r\n\\end{quote}\r\n{\\bf Facts about roots of unity:}  \r\nConsider $f(x)= x^h -1$ over $F$ where \r\n$(char(F),h)=1$ or $char(F)=0$.\r\nThe roots of $f$ form an abelian group, $G$.  $x \\in G \\rightarrow |x| \\mid |G|$.  Since\r\n$(f, f')=1$ there are $h$ distinct roots, set $h= \\prod_{i=1}^m q_i^{v_i}$.  \r\n$\\{ x: x^{h/q_i} = 1 \\}$ is a group of order\r\n$h/q_i$ so $\\forall i, \\exists x_i \\in G: \r\nx^{h/q_i} \\ne 1$.  Setting $b_i= x_i^{h/{q_i}^{v_i}}$, then $\\chi = \\prod b_i$ has order\r\nexactly $h$ and is a primitive $h$th root of unity.  \r\nLet the number of such roots be $\\varphi(h)$; if $(r,s)=1, \\varphi(rs)= \\varphi(r) \\varphi(s)$\r\nso $\\varphi(\\prod_i {q_i}^{v_i})= \r\n\\prod_i \\varphi({q_i}^{v_i})= \r\n\\prod_i ({q_i}^{v_i}- {q_i}^{v_i-1})= h \\prod_i (1- {\\frac 1 {q_i}})$.  Set $n=\\varphi(h)$ and\r\n$\\Phi_n(x) = \\prod_i (x- \\psi_i)$ where $\\psi_i$ are the primitive roots.\r\n$x^h-1 = \\prod_{d \\mid h} \\Phi_d(x)$ and by Moebius inversion,\r\n$\\Phi_h(x)= \\prod_{d \\mid h} (x^d -1)^{\\mu({\\frac h d})}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $\\Phi_h(x)$ is irreducible of\r\ndegree $\\varphi(h)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $\\zeta \\in {\\mathbb C}$ be a primitive root of\r\n$\\Phi_h(x)$ with minimal polynomial $f(x)$ and $(p,h)=1$.  Let $g(x)$ be the minimal\r\npolynomial for $\\zeta^p$ so $g(\\zeta^p)=0$.  $x^h -1 = f(x) g(x) h(x)$ and\r\n$g(x^p)=f(x)k(x)$.  $g(x^p)=g(x)^p \\jmod{p}$.  If $\\phi(x) \\mid f(x)$ then\r\n$\\phi(x) \\mid g(x)^p \\jmod{p}$.  So $\\phi(x)^2 \\mid x^h-1$ but this contradicts the\r\nfact that $x^h -1$ does not have roots of multiplicity 2.  It follows that if $(p_i , h)=1$,\r\n$\\zeta^{p_1 p_2 \\ldots p_k}$ is a primitive root and the degree of $f(x)$ is $\\varphi(h)$.\r\n\\end{quote}\r\nNote this shows that $Aut({\\mathbb Q}[\\zeta]) \\cong {\\mathbb Z}_h^*$.\r\nSo if $h=q=p^n$ ,\r\nthe Galois group is cyclic and the subfields correspond to the\r\ncyclic subgroups of ${\\mathbb Z}_q^*$.  The $q$th roots of 1 are expressible as radicals\r\nif $char(F)=0$ or $char(F)>q$.\r\nIf $N_p (d)=$ number of irreducible monic polynomials of degree $d$ in\r\n$GF(p)[x]$ then $p^n = \\sum_{d \\mid n} d N_p (d)$ and $N_p (d)= {\\frac 1 n}\r\n\\sum_{d \\mid n} \\mu ( {\\frac {n} {d} }) p^d$.\r\n$x^{p^n} - x = \\prod_{f,\\small{irred, monic}, deg(f) \\mid n} f$.\r\n\\\\\r\n\\\\\r\n{\\bf Eisenstein's Criteria:} If $f(x)= \\sum_{i=0}^n a_n x^n$, $a_n \\ne 0 \\jmod{p}$,\r\n$a_i = 0 \\jmod{p}, i<n$ and $a_0 \\ne 0 \\jmod{p^2}$ then $f$ is irreducible.\r\n\\\\\r\n\\\\\r\n{\\bf Factoring in finite number of steps:} Let $g(x) \\in {\\mathbb Z}[x]$ if\r\n$f(x) \\mid g(x)$ then $f(n) \\mid g(n)$ for\r\nall $n$. $deg(f) = s \\le \\lfloor {\\frac {deg(g)} 2} \\rfloor$.  Pick $s$ integers $i_j$ and\r\nuse the integer factors of $g(i_j)$ to get possible $f(i_j)$; there are a finite\r\nnumber of ways to pick the factors.  For each possibility, we can solve for the $s$ \r\ncoefficients of $f$.\r\n\\subsection{Free groups, rings and modules}\r\n{\\bf Theorem:}\r\nEvery group is the homomorphic image of a free group.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $F$ be the elements of $G$ and $R$ be the relations $abc^{-1}=1$.\r\n$G$ is the free group on the symbols $F$ with relations $R$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $x_1, x_2, \\ldots , x_n$ is a basis for a free abelian group for a free abelian\r\ngroup and $y_i = \\sum_{j=1}^n a_{ij} x_j$ with $a_{ij} \\in {\\mathbb Z}$ then\r\n$\\langle y_i \\rangle$ is a basis iff $det(a_{ij}) = \\pm 1$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSince $\\langle y_i \\rangle$ is a basis, $x_i= \\sum_j b_{ij} y_j$ for some\r\n$b_{ij} \\in {\\mathbb Z}$.  Let $A= (a_{ij})$ and $B= (b_{ij})$ then\r\n$BA=I$ and $det(B)= det(A) \\in {\\mathbb Z}$, so $det(A)= \\pm 1$.\r\n$\\langle y_i \\rangle$ is a basis iff $det(a_{ij}) = \\pm 1$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery subgroup $H \\le G$ of a free abelian group $G$ of rank $n$ is free abelian group\r\nof rank $s \\le n$.  Moreover, $\\exists  u_1, \\ldots, u_s \\in G$ and \r\n$\\alpha_1, \\ldots, \\alpha_s \\in {\\mathbb Z}$ such that $\\alpha_1 u_1 , \\ldots, \\alpha_s u_s$\r\nis a basis of $H$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy induction on $n$.  True for $n=1$.  Pick a basis $w_1, \\ldots, w_n$ of $G$ and\r\nfor $h \\in H: h= h_1 w_1 + \\ldots + h_n w_n$.  Let $\\alpha_1 \\ne 0$ be the\r\nsmallest (in absolute value) coefficient in any such sum and assume WLOG it occurs as the coefficient of $w_1$ for\r\nsome $h$.\r\nLet $v_1= \\alpha_1 w_1 + \\beta_2 w_2 + \\ldots + \\beta_n w_n \\in H$. $\\exists q_i, r_i:\r\n\\beta_i = \\alpha_1 q_i + r_i$.  Put $u_1 = w_1 + q_2 w_2 + \\ldots + q_n w_n$ then\r\n$u_1, w_2 , \\ldots , w_n$ is another basis for $G$ and $v_1= \\alpha_1 u_1 \\in H$.\r\nNow put $H'= \\{ h= m_2 w_2 + \\ldots + m_n w_n: h \\in H \\}$.  $H' \\cap (v_1) = 0$\r\nand $H= H' \\oplus (v_1)$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $G$ is a free abelian group of rank $r$ and $H \\le G$ then $G/H$ is finite iff\r\n$H$ has rank $r$.  If $G$ has basis $x_1, \\ldots , x_s$ and $H$ has basis\r\n$y_1, \\ldots, y_s$ with $y_i= \\sum_{j=1}^s a_{ij} x_j$ then $|G/H|= det(a_{ij})$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nBy the structure theorem, viewing $G$ as a ${\\mathbb Z}$-module,\r\n$G \\approx {\\mathbb Z}^s/H$.  In the diagonal form, the order of the direct sums appears\r\non the diagonal and the product is $det(a_{ij})$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery finitely generated abelian group with $n$ generators is the direct product of a\r\nfree abelian group and a finite abelian group.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $G= \\langle x_i , \\ldots ,x_n \\rangle$ and $H= \\{ x \\in G: x^n=1, n \\in {\\mathbb Z} \\}$.\r\n$G/H$ is free and finitely generated.  Apply the theorem (just before the structure theorem)\r\nto $g \\rightarrow G/H$ to conclude the proof.\r\n\\end{quote}\r\n{\\bf Calculating with free groups:}\r\nLet $F_m$ be a free abelian group generated by $a_1 , a_2 , \\ldots , a_m$ and\r\ndefine $E_i= r_{i1} a_1 + r_{i2} a_2 + \\ldots + r_{im} a_m$ where\r\n$r_{ij} \\in {\\mathbb Z}$ and $1 \\le i \\le n$; further, put\r\n$b_i= E_i$ and let $K= \\langle b_i \\rangle$.  \r\nSuppose $G$ is the free abelian group generated\r\nby $a_i$ subject to $E_i = 0$.  Then $G \\cong F_m / K$.  Let $R$ represent the matrix\r\n$(r_{ij})$ then \r\n(1) if the matrix $S=(s_{ij})$ is obtained from $R$ by elementary row operations then\r\n$c_i= s_{i1} a_1 + \\ldots + s_{im} a_m \\in K$; and,\r\n(2) if the matrix $S=(s_{ij})$ is obtained from $R$ by elementary column operations then\r\n$\\exists a_i' \\in F_m: b_i= s_{i1} a_1' + \\ldots + s_{im} a_m'$ (so the $a_i'$ generate\r\n$K$).  By applying elementary row and column operations, we can transform $R$ into\r\nthe diagonal matrix $D= diag(d_1 , d_2 , \\ldots , d_r , 0, \\ldots , 0)$ where\r\n$d_i \\mid d_{i+1}$\r\nand $G \\cong {\\mathbb Z}/(d_1) \\times {\\mathbb Z}/(d_2) \\times \\ldots \r\n\\times {\\mathbb Z}/(d_r) \\times {\\mathbb Z} \\times \\ldots \\times {\\mathbb Z}$ where there\r\nare $m-r$ copies of ${\\mathbb Z}$ in the product.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} If $f(x)= \\sum_{i=0}^n a_i x^i$, $a_i \\in R$, a UFD, the \\emph{content} of\r\n$f$ is $cont(f)= gcd(a_0, a_1, \\ldots, a_n)$.  \r\n\\\\\r\n\\\\\r\n{\\bf Gauss' Lemma}: \r\nIf $D$ is a UFD and $f, g \\in D[x]$ then\r\n$cont(f(x)g(x))= cont(f(x)) cont(g(x))$.  If $f(x) \\in R[x], deg(f)>0$ and $f(x)$\r\nis irreducible in $R[x]$ then it is irreducible in $K[x]$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuffices to show that if $cont(f)=cont(g)=1$ then $cont(fg)=1$.  Let\r\n$f(x)= a_0 + a_1 x + \\ldots +a_n x^n$ and\r\n$g(x)= b_0 + b_1 x + \\ldots +b_m x^m$ with $a_i, b_i \\in R$.  Suppose, by way of\r\ncontradiction that $p \\mid cont(fg)$.  Let \r\n$i$ be maximal subject to $p \\nmid a_i$ and\r\n$j$ be maximal subject to $p \\nmid b_j$.  The coefficient of $x^{i+j}$ in $fg$ is\r\n$c_{i+j}= \\sum_{k=0}^{i+j} a_k b_{i+j-k}$.  \r\n$p \\mid a_k, k<i$ and\r\n$p \\mid b_{i+j-k}, k>i$ but $p \\nmid a_i b_j$ so $p \\nmid c_{i+j}$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $R$ is a UFD then\r\n$R[x]$ is a UFD. \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet the field of quotients of $R$ be $K$.  If $f(x) \\in R[x]$, $f(x)= cont(f) f'(x)$\r\nwith $cont(f')=1$.  By Gauss' lemma, it suffices to prove the result\r\nwhen $f$ is primitive.\r\n$f(x)= f_1(x) \\cdot f_2(x) \\ldots \\cdot f_n(x)$ over $K$ with each $f_i$ irreducible;\r\nfurther, this factorization is unique up to units in $K$.  So $\\exists c_i, d_i \\in R$ \r\nsuch that \r\n$d_i f_i(x)= c_i p_i(x)$ where $p_i \\in R[x]$ satisfies $cont(p_i)=1$.\r\nPut $c= \\prod_{i=1}^n c_i$ and\r\n$d= \\prod_{i=1}^n d_i$  then $d f(x)=\r\nc p_1(x) \\cdot p_2(x) \\ldots \\cdot p_n(x)$ so $c$ and $d$ are units of $R$ by Gauss.\r\nThis shows a factorization exists.\r\nIf $f(x)= d q_1(x) \\cdot q_2(x) \\ldots \\cdot q_m(x)$\r\nis another such factorization then $m=n$  \r\nand $p_i= u_i q_j$, $u_i \\in K$ by the factorization result in $K[x]$.  Thus\r\n$t_i p_i= r_i q_j$, $r_i, t_i \\in R$ with $(t_i, r_i)= 1$.  By Gauss, $t_i= u_i r_i$\r\nwhere $u_i$ is a unit in $R$.\r\nFinally, \r\n$d$ is a unit in $R$ again by Gauss's lemma and the proof is complete.\r\n\\end{quote}\r\n{\\bf Ring theoretic Chinese Remainder Theorem:} \r\nIf $I_j, j= 1,2, \\ldots, n$ are ideals of $R$ and\r\n$I_j + I_k = R$ for $j \\ne k$, then $\\forall x_1 , x_2, \\ldots , x_n \\in R, \\exists\r\nx \\in R$ such that $x= x_j \\jmod{I_j}$.\r\n\\\\\r\n\\\\\r\n{\\bf Corollaries:} Under the same assumptions as the theorem,\r\n$\\psi: R \\rightarrow R/I_1 \\times R/I_2 \\times \\ldots \\times R/I_n$ given by\r\n$x \\mapsto x \\jmod{I_1} \\times \\ldots \\times x \\jmod{I_n}$ is surjective and\r\n$R/(\\bigcap_{j=1}^n I_j) \\cong R/I_1 \\times R/I_2 \\times \\ldots \\times R/I_n$.\r\nIf $m= \\prod_{i=1}^n p_i^{r_i}$,\r\n${\\mathbb Z}/(m{\\mathbb Z}) \\cong \\prod_i {\\mathbb Z}/({p_i}^{r_i}{\\mathbb Z})$ and\r\n$\\psi(m)= \\prod_i \\psi({p_i}^{r_i})$.  If $R$ is cyclic of order $n$ then\r\n$End(R) \\cong {\\mathbb Z}/(n{\\mathbb Z})$ and\r\n$({\\mathbb Z}/(n{\\mathbb Z}))^* \\cong Aut(R)$.\r\n\\\\\r\n\\\\\r\n{\\bf Hilbert Basis Theorem: }\r\nIf $R$ is a ring with identity such that every ideal is finitely \r\ngenerated then $R[x]$ has the same property.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $I$ be an ideal of $R[x]$ and $I_j$ be the set of coefficients\r\nof the $x^j$ terms in $I$.  $I_j$ is an ideal of $R$ and $I_j \\subseteq I_{j+1}$.\r\nSince $R$ is finitely generated, $\\exists m: I_j \\subseteq I_m, \\forall i$.\r\nLet the generators of $I_j$ be \r\n$\\langle b^{(1)}_j, b^{(2)}_j,  \\ldots , b^{(i_j)}_j, \\rangle$.  So there are\r\npolynomials $f_j^{(i)}(x) \\in I_j$:\r\n$f_j^{(i)}(x)= b_j^{i} x^j + g_j^{(i)}(x), deg (g_j^{(i)}(x)< j)$.\r\nThe polynomials\r\n$$\\langle\r\nf_0^{(1)}(x),\r\nf_0^{(2)}(x), \\ldots,\r\nf_0^{(i_0)}(x), \r\nf_1^{(1)}(x),\r\nf_1^{(2)}(x), \\ldots,\r\nf_1^{(i_1)}(x), \r\n\\ldots,\r\nf_m^{(1)}(x),\r\nf_m^{(2)}(x), \\ldots,\r\nf_m^{(i_m)}(x)\r\n\\rangle$$\r\ngenerate $I$.\r\n\\end{quote}\r\n{\\bf Groups with operators} ($M$) and invariant subgroups:  Projection commutes with\r\nall inner automorphisms; such an endomorphism is called normal.  An $M-$group\r\n$G$ is decomposable \r\niff there are projections.  Any $M-$group satisfying DCC is a direct\r\nproduct of a finite number of indecomposable $M-$groups.  If $\\eta \\in  End(G)$\r\nthen ${\\sqrt \\eta}= \\{z \\in G: z \\eta^s=1 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Fitting Lemma:}  Let $G$ be an $M-$group that satisfies ACC and DCC and $\\eta$ is a\r\nnormal endomorphism of $G$ then $G= {\\sqrt \\eta} \\times H$ and $H \\eta = H$.\r\nIf $G$ is an indecomposable $M-$group satisfying ACC and DCC then any normal\r\n$M-$endomorphism of $G$ is either {\\bf nilpotent} or an automorphism.  Suppose\r\n$\\eta_1, \\eta_2$ are normal nilpotent $M-$endomorphisms, if $\\eta_1 + \\eta_2$\r\nis an endomorphism it is nilpotent.  {\\bf Krull-Schmidt} follows\r\nfrom this.  \r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $M$ is \\emph{unitary} if $RM=M$.  \r\n\\\\\r\n\\\\\r\n{\\bf Primary decomposition:}\r\nIf $A,B$ are ideals, we say $A \\mid B$ if $B \\subseteq A$. $Q$ is \\emph{primary} iff\r\n$ab= 0 \\jmod{I} \\rightarrow a = 0 \\jmod{Q}$ or $b \\in {\\sqrt I}$.  If\r\n$Q$ is primary then ${\\sqrt Q}$ is prime.  \r\nEvery irreducible ideal in a Noetherian ring is primary.\r\nEvery ideal in a Noetherian ring is the finite intersection of\r\nprimary ideals.  If $Q_1, Q_2$ are primary and\r\n${\\sqrt {Q_1}}= {\\sqrt {Q_2}}$ then $Q_1 \\cap Q_2$ is primary.\r\nIf $Q_1 \\cap Q_2 \\cap \\ldots \\cap Q_r = Q_1' \\cap Q_2' \\cap \\ldots \\cap Q_s'$\r\nare two irredundant representations into primary ideals whose associated primes\r\nare distinct, then $r=s$ and the set of associated primes is identical.\r\nIf $R^2=R$ is a commutative ring then every maximal ideal is prime.  Let\r\n$P$ be a prime ideal of $R$ ($1 \\in R$) then (1)\r\nThere is a 1-1 correspondence between the set of prime ideals of $R$ contained\r\nin $P$ and (2) the prime ideals of $R_P$ given by \r\n${\\mathbb Q} \\mapsto {\\mathbb Q}_P$.  A local ring is a commutative ring\r\nwith identity containing a unique maximal ideal.  If $R$ is a commutative ring\r\nwith identity, the following are equivalent: (1) $R$ is a local ring; (2)\r\nall non-units of $R$ are contained in an ideal \r\n$M \\ne R$; (3)  the non-units form an ideal.\r\nSubstitution from a the polynomial ring to the ring of coefficients is a homomorphism.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\nIf $R$ is Noetherian and $a \\in M$ is $R-$\\emph{integral} iff $\\exists$ a finitely\r\ngenerated submodule of $M$ that contains all powers of $a$.  The totality\r\n$G$ of elements of $M$ that are $R-$integral is a subring of $M$ containing\r\n$R$.  The ring $G$ or $R-$integral elements is integrally closed in $R$.\r\n\\begin{quote}\r\n\\emph{Proof:} $\\rightarrow$.  Suppose $a^n + r_{n-1} a^{n-1} + \\ldots + r_0 = 0$.\r\nPut $M= \\langle a^{n-1}, \\ldots, 1 \\rangle$.  $a^k \\in M, \\forall k$.\r\n$\\leftarrow$. Consider \r\n$\\langle 1 \\rangle \\subseteq \\langle 1, a \\rangle \\subseteq\r\n\\langle 1, a, a^2 \\rangle \\subseteq \\ldots$.  Since $R$ is noetherian, this series\r\nis finite.  Say $M = \\langle 1, a, a^2, \\ldots, a^m \\rangle$ is the terminal module\r\nin the series.  $a^k \\in M, \\forall k$.\r\n\\end{quote}\r\n{\\bf Projective and injective modules:}\r\nIf $A, B, C, A', B', C'$ are modules \r\nover a ring $R$ with identity and we have the diagrams\r\n$0 \\rightarrow A\r\n{\\buildrel\\rm f\\over \\rightarrow} \\; B {\\buildrel\\rm g\\over \\rightarrow} \\; \r\nC \\rightarrow 0$\r\nand\r\n$0 \\rightarrow A'\r\n{\\buildrel\\rm f'\\over \\rightarrow} \\; B' {\\buildrel\\rm g'\\over \\rightarrow} \\; \r\nC' \\rightarrow 0$ with \r\n$A\r\n{\\buildrel\\rm \\alpha\\over \\rightarrow} \\; \r\nA'$,\r\n$B\r\n{\\buildrel\\rm \\beta\\over \\rightarrow} \\; \r\nB'$, and\r\n$C\r\n{\\buildrel\\rm \\gamma\\over \\rightarrow} \\; \r\nC'$, then (1) $\\beta$ is a monomorphism if $\\alpha$ and $\\beta$ are and (2)\r\n$\\beta$ is a epimorphism if $\\alpha$ and $\\beta$ are.\r\n$P$ is projective if given $A, B, g, f$ and morphism diagrams:\r\n$A {\\buildrel\\rm g\\over \\rightarrow} \\; B \\rightarrow 0$ and\r\n$P {\\buildrel\\rm f\\over \\rightarrow} \\; B$, $\\exists h,\r\nP {\\buildrel\\rm h\\over \\rightarrow} \\; B$ which makes the diagram commute.\r\n$J$ is injective if given $A, B, g, f$ and morphism diagrams:\r\n$A {\\buildrel\\rm g\\over \\rightarrow} \\; B \\rightarrow 0$ and\r\n$A {\\buildrel\\rm f\\over \\rightarrow} \\; J$, $\\exists h,\r\nB {\\buildrel\\rm h\\over \\rightarrow} \\; J$ which makes the diagram commute.\r\nEvery free module $F$ over $R$ with identity is projective.  \r\nIf $R$ is a ring\r\nwith identity, TFAE: (1) $P$ is projective, (2) every short exact sequence\r\n$0 \\rightarrow A\r\n{\\buildrel\\rm f\\over \\rightarrow} \\; B {\\buildrel\\rm g\\over \\rightarrow} \\; \r\nP \\rightarrow 0$ splits so $B= P \\oplus A$ and (3) $\\exists F$, free such that\r\n$F=K \\oplus P$.\r\nIf $R$ is a ring\r\nwith identity, TFAE: (1) $J$ is injective, (2) every short exact sequence\r\n$0 \\rightarrow A\r\n{\\buildrel\\rm f\\over \\rightarrow} \\; B {\\buildrel\\rm g\\over \\rightarrow} \\; \r\nC \\rightarrow 0$ splits so $B= J \\oplus C$ and (3) $J$ is a direct summand.\r\n$0 \\rightarrow A\r\n{\\buildrel\\rm \\psi\\over \\rightarrow} \\; B {\\buildrel\\rm \\phi\\over \\rightarrow} \\; \r\nC$ is exact if:\r\n$0 \\rightarrow Hom(D, A)\r\n{\\buildrel\\rm \\psi\\over \\rightarrow} \\; Hom(D, B) {\\buildrel\\rm \\phi\\over \\rightarrow} \\; \r\nHom(D, C)$ is.\r\n$A\r\n{\\buildrel\\rm \\theta\\over \\rightarrow} \\; B {\\buildrel\\rm \\zeta\\over \\rightarrow} \\; \r\nC \\rightarrow 0$ \r\nis exact if:\r\n$0 \\rightarrow Hom(A, D)\r\n{\\buildrel\\rm \\psi\\over \\rightarrow} \\; Hom(B, D) {\\buildrel\\rm \\phi\\over \\rightarrow} \\; \r\nHom(C, D)$ is.  The full short exact sequence is split exact iff the corresponding\r\ndual (Hom) sequence is.\r\n\\\\\r\n\\\\\r\n{\\bf Integral closure of  UFD's:} \r\nIf $A$ us a unique factorization domain, $A$ is integrally closed.  \r\nThe integral closure in a number field\r\n$K$ is called the ring of algebraic integers.  Algebraic integers form a free\r\n${\\mathbb Z}$-module of rank $[K:{\\mathbb Q}]$.\r\n\\\\\r\n\\\\\r\n{\\bf Results on trace and norm:}\r\nLet $[E:F]=n$ and $[F(x):F]=d$ and $x_1 , x_2 , \\ldots , x_d$ be the\r\nroots of $min_F(x)$ then \r\n$N_{E/F}(x)= (\\prod_{i=1}^d x_i)^{\\frac n d}$ and\r\n$Tr_{E/F}(x)= {\\frac n d} (\\sum_{i=1}^d x_i)$.  \r\nIf $E/F$ is separable then\r\n$N_{E/F}(x)= \\prod_{i=1}^n \\sigma_i(x)$ and\r\n$Tr_{E/F}(x)= \\sum{i=1}^n \\sigma_i(x)$.  If $F \\subseteq E \\subseteq K$ then\r\n$N_{E/F}(N_{K/E}(x))= N_{K/F}(x)$ and $Tr_{E/F}(Tr_{K/E}(x))= Tr_{K/F}(x)$.  If\r\n$E/F$ is a finite separable extension, $\\exists x \\in E: Tr_{E/F}(x)= 0$ and\r\n$(x,y) \\rightarrow Tr_{E/F}(xy)$ is bilinear.\r\nFor this paragraph, $L$ be a separable extension of $K$, \r\n$A \\subseteq K$ be a ring of integers and\r\n$B \\subseteq L$ be a ring of algebraic integers.\r\n${\\vec x}$ is a basis for $L/K$ iff $\\Delta({\\vec x}) \\ne 0$.  If\r\n$L=K(x)$ and $f$ is a minimal polynomial of $x$ over $K$ then\r\n$\\Delta(1,x,x^2, \\ldots, x^{n-1})= disc(f)= \\prod_{i<j} (x_i-x_j)=\r\n(-1)^{n \\choose 2} N_{L/K}(f'(x))$.  There is a basis for $L/K$ consisting\r\nof elements of $B$.  If $A$ is a PID then $B$ is a free $A$-module of rank $[L:K]$.\r\nIf $a_i \\in A$ then $(x_1-a_1 , x_2 - a_2 , \\ldots , x_n-a_n)$ is a maximal ideal.\r\n\\\\\r\n\\\\\r\n{\\bf Theorems on chain conditions:}\r\nLet $M$ be an $R$ module.  \r\nThe following are equivalent\r\n(1) $M$ satisfies \\emph{ACC (Noetherian)}, \r\n(2) Any non empty collection of submodules of $M$\r\nhas a maximal element.\r\nThe following are equivalent\r\n(1) $M$ satisfies \\emph{DCC (Artinian)}, (2) Any non empty collection of submodules of $M$\r\nhas a minimal element.  \r\n$M$ is Noetherian iff every submodule is finitely generated.\r\n$M$ is Artinian iff every submodule is finitely co-generated.  \r\n\\\\\r\n\\\\\r\n{\\bf Example of Noetherian ring:}\r\nPIDs, $F[x]$.  $F[x_1 ,x_2, \\ldots ]$ is \\emph{neither} Noetherian nor Artinian.\r\nIf $N \\subseteq M$ then $M$ is Noetherian iff $N$ and $M/N$ are.  $M$ has a\r\ncomposition series iff $M$ is Noetherian and Artinian.\r\n$L$ be a separable extension of $K$, \r\n$A \\subseteq K$ be a ring of integers\r\n$B \\subseteq L$ be a ring of algebraic integers, if $A$ is integrally closed\r\nin $K$ and $A$ is Noetherian, so is $B$.\r\nLet $P$ be a prime ideal of $R$ and \r\n$P \\supseteq I_1 I_2 \\ldots I_n$ then\r\n$\\exists k: P \\supseteq I_k$.\r\nLet $I$ be a non-zero ideal of a noetherian integral domain $R$ then\r\n$I \\supseteq P_1 P_2 \\ldots P_n$ for $P_i$ prime.\r\nLet $R$ be a non-zero ideal of a noetherian integral domain and $K$ its\r\nfield of quotients, $I$ is a fractional ideal if $I$ is an $R$-module and\r\n$\\exists r \\in R: rI \\subseteq R$.  If $I$ is a finitely generated $R$\r\nsubmodule of $K$ then $I$ is a fractional ideal.  If $R$ is Noetherian and $I$\r\nis a fractional ideal of $R$ then $I$ is a finitely generated $R$ submodule of $K$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nA \\emph{Dedekind Domain (``DD'')} is an integral domain, $R$, such that \r\n(1) $R$ is Noetherian,\r\n(2) $R$ is integrally closed, and, (3) Every non-zero prime ideal of $R$ is maximal.\r\nPIDs are DDs.  Algebraic integers in a number field is a DD.  If $P$ is a non-zero\r\nprime ideal in a DD, $R$ and $J=\\{x \\in K: xI \\subseteq R \\}$ then\r\n(1) $R \\subseteq J$ and (2) $J$ is a fractional ideal and $PJ=R$.  If $I$\r\nis a fractional ideal in a DD, $R$ then $I= \\prod_{i=1}^N {P_i}^{n_i}$ \r\n($n_i \\in {\\mathbb Z}$ not just ${\\mathbb Z}^{\\ge 0}$), $n_P(I)=n_i$.  The\r\nfractional ideals form a group.  A non-zero fractional ideal is integral iff all\r\n$n_i$ in the forgoing representation are $\\ge 0$.  $I_1 \\supset I_2$ iff\r\n$\\forall P, n_P(I_1) \\le n_P(I_2)$.  If $I_1 , I_2$ are integral ideals then\r\n$I_1 \\mid I_2$ if $I_2= J I_1$.  $I_1 \\mid I_2$ iff $I_1 \\supseteq I_2$.\r\n$L$ be a separable extension of $K$, \r\n$A \\subseteq K$ be a ring of integers, if $A$ is a DD, $B$ is a DD.\r\nAn abelian group with a basis of $n$ elements is a \\emph{free abelian\r\ngroup} of rank $n$.\r\n\\\\\r\n\\\\\r\n{\\bf Kummer's idea:}  For a field, $K$ let\r\n${\\mathfrak D}_K$ denote the ring of integers in $K$.\r\nStart with $K$ and extend it to $L$ such that\r\n${\\mathfrak D}_K \\subseteq {\\mathfrak D}_L$.  For example, \r\n$K={\\mathbb Q}(\\sqrt {15}) \\subseteq {\\mathbb Q}({\\sqrt {3}}, {\\sqrt {5}})= L$.\r\n$10 = {\\sqrt{5}} {\\sqrt{5}} ({\\sqrt{5}} + {\\sqrt{3}}) ({\\sqrt{5}} - {\\sqrt{3}})$.\r\nLet $I= ({\\sqrt{5}} + {\\sqrt{3}}) \\cap {\\mathfrak D}_K$.  \r\n$({\\sqrt{15}} + 3) \\in I$,\r\n$({\\sqrt{15}} + 5) \\in I$ so $2 \\in I$ and $I$ is not principal.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A ${\\mathfrak D}$-submodule ${\\mathfrak a}$ of $K$ is a \r\n\\emph{fractional} ideal of ${\\mathfrak D}$ if $\\exists c \\in {\\mathfrak D}:\r\nc{\\mathfrak a} \\subseteq {\\mathfrak D}$ and $c {\\mathfrak a} = {\\mathfrak b}$ is an\r\nideal of ${\\mathfrak D}$.  An ideal ${\\mathfrak p}$ is prime if\r\n${\\mathfrak p} \\mid {\\mathfrak a} {\\mathfrak b}$ implies\r\n${\\mathfrak p} \\mid {\\mathfrak a}$ or ${\\mathfrak p} \\mid {\\mathfrak b}$.\r\n${\\mathfrak a}^{-1}= \\{ x \\in K: x {\\mathfrak a} \\subseteq {\\mathfrak D} \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If a domain is \\emph{noetherian} the elements factor into irreducibles.\r\nIf every irreducible in a domain, $D$, is prime then $D$ is a UFD.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n\\\\\r\n\\emph{Claim 1:}\r\nLet ${\\mathfrak a} \\ne 0$, $\\exists\r\n{\\mathfrak p}_1 , \r\n{\\mathfrak p}_2 , \\ldots ,\r\n{\\mathfrak p}_n $ \r\nsuch that\r\n$ {\\mathfrak p}_1 \\cdot {\\mathfrak p}_2 \\cdot \\ldots \\cdot{\\mathfrak p}_n  \\subseteq {\\mathfrak a}$.\r\n\\\\\r\n\\emph{Claim 2:}\r\n${\\mathfrak a}^{-1}$, exists.\r\n\\\\\r\n\\emph{Claim 3:}\r\nIf ${\\mathfrak a}$ is a proper ideal then\r\n${\\mathfrak a} \\nsupseteq {\\mathfrak D}$.\r\n\\\\\r\n\\emph{Claim 4:}\r\nIf \r\n${\\mathfrak a} S \\subseteq {\\mathfrak a}$ for\r\n$S \\subseteq K$ then\r\n$S \\subseteq {\\mathfrak D}$.\r\n\\\\\r\n\\emph{Claim 5:}\r\nIf ${\\mathfrak p}$ is a maximal ideal then\r\n${\\mathfrak a} {\\mathfrak a}^{-1} = {\\mathfrak D}$.\r\n\\\\\r\n\\emph{Claim 6:}\r\nIf\r\n${\\mathfrak a}$ is a fractional ideal, it has an inverse and\r\n${\\mathfrak a} {\\mathfrak a}^{-1} = {\\mathfrak D}$.\r\n\\\\\r\n\\emph{Claim 7:}\r\nEvery non-zero ideal ${\\mathfrak a}$ is a product of prime ideals.\r\n\\\\\r\n\\emph{Claim 8:}\r\nPrime factorization is unique.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe non-zero fractional ideals of ${\\mathfrak D}$ form a group and the identity is\r\n${\\mathfrak D}$.  Every non-zero ideal of ${\\mathfrak D}$ can be written as a product of prime\r\nideals uniquely up to the order of factors.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nTodo.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$N({\\mathfrak a})= {\\mathfrak D}/ {\\mathfrak a}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $G$ be an additive subgroup of\r\n${\\mathfrak D}$, a ring of algebraic integers, of rank $n$ equal to the degree of an\r\nalgebraic number field $K$ with ${\\mathbb Z}$-basis $\\{ \\alpha_1 , \\ldots , \\alpha_n \\}$\r\nthen $|{\\mathfrak D}/G|^2 \\mid \\Delta(\\alpha_1, \\ldots , \\alpha_n)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nTodo.\r\n\\end{quote}\r\n{\\bf Chain conditions and exact sequences:}\r\nIf $0 \\rightarrow A\r\n{\\buildrel\\rm f\\over \\rightarrow} \\; B {\\buildrel\\rm g\\over \\rightarrow} \\; \r\nP \\rightarrow 0$, $B$ satisfies ACC (resp DCC) iff $A$ and $C$ do.\r\n$A$ satisfies ACC on submodules iff each submodule is finitely generated (same for\r\nrings).  Jordan-Holder for modules (composition series have unique refinements).  $A$\r\nhas a composition series iff $A$ satisfies ACC and DCC.  If $D$ is a division ring\r\nthen $Mat_{n \\times n}(D)$ is both Noetherian and Artinian.  An ideal $P (\\ne R)$\r\nin a commutative ring $R$ is prime iff $R-P$ is a multiplicative set.  If\r\n$S$ is multiplicative and $S \\cap I \\ne \\emptyset$, $\\exists P$, prime that is maximal\r\nwith respect to the disjoint property.  $rad(I)= \\{ r \\in R: r^n \\in I \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nEvery transcendental extension has a \\emph{transcendence basis.}\r\nIf $\\langle x_1, x_2, \\ldots , x_n \\rangle$\r\nspans $E$ algebraically and $S \\subseteq E$ is algebraically independent then\r\n$|S| \\le n$. (Use Steinmetz replacement.) \r\n\\\\\r\n\\\\\r\n{\\bf Noetherian Normalization Lemma:}\r\nLet $R$ be an integral domain which is a finitely generated extension of $K$ and\r\nsuppose $r$ is the transcendence degree over $K$ of the quotient field of $R$, then\r\n$\\exists t_1, \\ldots, t_r$ algebraically independent elements such that\r\n$R$ is integral over $K[t_1, \\ldots, t_r]$.\r\n\\\\\r\n\\\\\r\n{\\bf Localization:} Let $S$ be a multiplicative subset of $R$ and $h: a \\mapsto a/1$ \r\nbe the natural map.  If $J$ is an ideal in $S^{-1}R$ then\r\n$S^{-1}J = I$ is an ideal of $R$ and\r\n$I \\subseteq h^{-1}(S^{-1}(I)$ with equality if $I \\cap S = \\emptyset$.\r\nIf $I$ is a prime ideal of $R$ and $I \\cap S= \\emptyset$ then $S^{-1}R$ is a\r\nprime ideal of $S^{-1}R$.  If $P$ is a prime ideal of $R$ and $S=R-P$ is a\r\nmultiplicative set, denote $S^{-1}R$ as $R_P$.  $R_P$ has a unique maximal ideal\r\nconsisting of non-units of $R_P$.  ${\\sqrt I}= P_1 \\cap P_2 \\cap \\ldots \\cap P_k$ for\r\nsome prime ideals $P_i$.\r\n\\subsection{Polynomials}\r\n{\\bf Basic Symmetric polynomials:} $\\sigma_1= \\sum x_i$, $\\sigma_2 = \\sum x_i x_j$,\r\netc.  \r\nEvery symmetric function $f(x_1, \\ldots , x_n)= (z-x_1) \\ldots (z-x_n)$\r\ncan be written as a polynomial\r\nwith coefficients in the basic symmetric polynomials.  \r\n\\begin{quote}\r\n\\emph{Proof 1:}\r\nLet $ a {x_1}^{a_1} {x_2}^{a_2} \\ldots {x_n}^{a_n}$\r\nbe the leading coefficient of a symmetric form in lexicographic order,\r\nsubtracting\r\n$a {\\sigma_1}^{a_1 - a_2} {\\sigma_2}^{a_2 - a_3} \\ldots {\\sigma_n}^{a_n}$\r\nleaves a symmetric form with leading coefficient smaller in lexicographic\r\norder.\r\n\\\\\r\n\\emph{Proof 2:}  By induction on the weight.  True for 1.  If \r\n$f(x_1 , \\ldots, x_n)$ is symmetric, so is\r\n${\\frac {f(x_1 , \\ldots, x_{n-1},0)} z}$. \r\nSo ${\\frac {f(x_1 , \\ldots, x_{n-1},0)} z}= \r\n\\phi((\\sigma_1)_0, \\ldots , (\\sigma_{n-1})_0)$\r\nSet  \r\n$f_1(x_1 , \\ldots, x_n)=\r\nf(x_1 , \\ldots, x_n)-\r\n\\phi((\\sigma_1)_0, \\ldots , (\\sigma_{n-1})_0)$.\r\n$f_1(x_1 , \\ldots, x_{n-1},0)=0$ so $x_n$ and hence $\\sigma_n$ divides\r\n$f_1$ thus $f_1 = \\sigma_n g$ and $g$ is writable as a polynomial in the basic\r\nsymmetric functions by induction so\r\n$f(x_1 , \\ldots, x_n)= \\sigma_n \\psi(\\sigma_1, \\ldots , \\sigma_n) \r\n+ \\phi (\\sigma_1 , \\ldots , \\sigma_{n-1})$.  Further, the representation is essentially\r\nunique which you can show by proving \r\n$\\phi(y_1 , \\ldots , y_n) \\ne 0 \\rightarrow \\phi(\\sigma_1 , \\ldots , \\sigma_n) \\ne 0 $\r\n(Prove).\r\n\\end{quote}\r\n{\\bf Theorem:} Let $\\sigma_1, \\ldots , \\sigma_n$ be the symmetric functions on $n$ variables.\r\n$\\varphi(\\sigma_1 , \\ldots , \\sigma_n )=0 $ iff\r\n$\\varphi(x_1 , \\ldots , x_n )=0 $.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nProof by induction on $n$.  Trivial for $n=1$.  \r\nLet $\\phi(y_1, \\ldots , y_n)=\r\n\\phi_k(y_1, \\ldots , y_{n-1}) y^m + \\ldots + \\phi_0(y_1 , \\ldots , y_{n-1})$ be a\r\ncounterexample of minimum degree in $y_n$.\r\nThen $\\phi(\\sigma_1, \\ldots , \\sigma_n)=\r\n\\phi_k(\\sigma_1, \\ldots , \\sigma_{n-1}) \\sigma^m + \\ldots + \\phi_0(\\sigma_1 , \\ldots , \\sigma_{n-1})= 0$.\r\nPut $x_n=0$.  Then  \r\n$\\phi_0(\\sigma_1 , \\ldots , \\sigma_{n-1})= 0$ but\r\n$\\phi_0(y_1 , \\ldots , y_{n-1}) \\neq 0$ which contradicts the induction hypothesis.\r\n\\end{quote}\r\n{\\bf Resultant:}\r\nIf $f_{v}(x)= v_{n}x^{n}+ \\ldots + v_{0}$ and\r\n$g_{w}(x)= w_{m}x^{m}+ \\ldots + w_{0}$,\r\n$\\exists \\phi_{v,w}(x), \\psi_{v,w} (x):$\r\n$\\phi_{v,w}(x) f_{v}(x) + \\psi_{v,w}(x) g_{u}(x) = R(v,w)\r\n= v_{m}^n w_{n}^m \\prod_{i<j} (t_{i}-u_{j})$, where $t_i , u_j$ are roots of\r\n$f, g$ respectively.  Resultant is 0 iff equations have common solution.  \r\nConsider the equations written in matrix notation:\r\n$$\r\n\\left(\r\n\\begin{array}{c}\r\nx^{m-1}f_{v} (x) \\\\\r\nx^{m-2}f_{v} (x) \\\\\r\n\\ldots \\\\\r\nf_{v} (x) \\\\\r\nx^{n-1}g_{w} (x) \\\\\r\nx^{n-2}g_{w} (x) \\\\\r\n\\ldots \\\\\r\ng_{w} (x)\r\n\\end{array}\r\n\\right) =\r\n\\left(\r\n\\begin{array}{cccccccc}\r\nv_n & v_{n-1} & \\ldots & v_0 & 0 & 0 & \\ldots & 0 \\\\\r\n0 & v_n & v_{n-1} & \\ldots & v_0 & 0 & \\ldots & 0 \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots\\\\\r\n0 & 0 & \\ldots & 0 & v_n & v_{n-1} & \\ldots & v_0 \\\\\r\nw_m & w_{m-1} & \\ldots & w_0 & 0 & 0 & \\ldots & 0 \\\\\r\n0 & w_m & w_{m-1} & \\ldots & w_0 & 0 & \\ldots & 0 \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots\\\\\r\n0 & 0 & \\ldots & 0 & w_m & w_{m-1} & \\ldots & w_0 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{c}\r\nx^{n+m-1}\\\\\r\nx^{n+m-2}\\\\\r\n\\ldots \\\\\r\n\\ldots \\\\\r\n\\ldots \\\\\r\n\\ldots \\\\\r\nx \\\\\r\n1\r\n\\end{array}\r\n\\right)\r\n$$\r\n\\begin{quote}\r\n\\emph{Proof:} Let the column vectors be $C_{m+n-1}$ \\ldots $C_{0}$.\r\n$C= (x^{m-1}f_v(x), \\ldots , g_w (x))^T$.\r\n$C= C_{m+n-1} \\cdot x_{m+n-1} + \\ldots + 1 \\cdot C_{0}$.\r\nNow solve for 1.  $1= {\\frac {det(C_{m+n-1}, \\ldots C_{1}, C)}\r\n{det(C_{m+n-1}, \\ldots C_{1}, C_{0})}}$.\r\nGet $\\phi_{v,w}(x)f_{v}(x) +\r\n\\psi_{v,w}(x)g_{w}(x)= R(v,w)$.\r\n\\end{quote}\r\n{\\bf Theorem}:\r\nLet $f_{1},\\ldots, f_{s}$ be polynomials of one variable with indeterminate\r\ncoefficients. $\\exists d_{1} , d_{2}, \\ldots, d_{h}$ of integral polynomials\r\nin the coefficients of $f_i$ such that if the coefficients are assigned values \r\n(\\emph{``specialized''})\r\nfrom $k$, $d_{i}=0$ iff either\r\nthe $f_{i}=0$ have a common solution or the leading coefficients vanish.\r\n\\begin{quote}\r\n\\emph{Proof:} Set $f_{u} = u_{1} f_{1} + \\ldots + u_{s} f_{s}$,\r\n$f_{v} = v_{1} f_{1} + \\ldots + v_{s} f_{s}$. $(f_{u}, f_{v})=1$ iff\r\n$(f_{1}, f_{2} \\ldots, f_{s}) = 1$.  $R(f_{u},f_{v}) = 0$ iff $f_u$ and\r\n$f_v$ have a non-trivial common factor.  But $R(f_u, f_v)$ is\r\na polynomial in $u_{i}, v_{j}$ with coefficients which are integral in the\r\ncoefficients of $f_{i}$.  Arrange these in the order of powers of $u_i v_j$.\r\nThese are the $d_i$.\r\nThe proof also shows that \r\n$d_{i}= 0 \\jmod{(f_{1}, f_{2}, \\ldots f_{r})}$ and\r\n$(d_{1}, d_{2} \\ldots d_{l})= 0 \\jmod{(f_{1}, f_{2}, \\ldots f_{r})}$.\r\n\\end{quote}\r\n{\\bf Theorem}: If\r\n$f_{1},\\ldots, f_{r} \\in F[x_1, \\ldots, x_n]$ has no common zeros, \r\n$\\exists A_{1},...A_{r}$ such that\r\n$\\sum_{i} A_{i}f_{i}=1$.\r\n\\begin{quote}\r\n\\emph{Proof:} By the induction on number of variables.  True for $n=1$\r\nby usual theory of polynomials over fields.\r\nAssume it's true for $n-1$.  Let ${\\overline f}_i(x)= f_i(x, x_2, \\ldots , x_n) =\r\n\\sum_{j-0}^{n_i} g_{ij}(x_2, \\ldots, x_n) x^j$.  \r\nThe ${\\overline f}_i$ have no common solution or the $f_i$ would; thus\r\nby the previous result, regarding the coefficients of $x^j$ as indeterminants,\r\n$\\exists d_{lk}$ which are not simultaneously $0$ [or again, the $f_i$ would have a common\r\nsolution], such that \r\n$\\sum_{lk} B_{lk} d_{lk} =1$.  After substitution,\r\n$\\sum_{ij} C_{ij} g_{ij} =1$.  Further, $g_{ij}= \\sum_j A_j f_j$, again by\r\nthe previous result.  After substituting again, we get\r\n$\\sum_j D_j f_j(x, x_2, \\ldots, x_n)$ which is what we want.\r\n\\end{quote}\r\n{\\bf Nullstellensatz}:  \r\nIf $f(x_1, \\ldots, x_n) \\in F$ vanishes at all the common zeros of\r\n$f_1(x_1, \\ldots, x_n), \\ldots , f_r(x_1, \\ldots, x_n)$\r\nin every extension of $F$, then\r\n$f^k(x_1, \\ldots, x_n) \\in (f_1(x_1, \\ldots, x_n), \\ldots,\r\nf_r(x_1, \\ldots, x_n))$ for some $k$.\r\n\\begin{quote}  \r\nTo prove this, look at\r\n$f_{1},\\ldots, f_{r}, 1-zf$,\r\nput $z= {\\frac {1} {f}}$ and clear denominators.\r\nNote that if $h_1 , \\ldots, h_m$ are zero\r\nfor all common zeros of the \r\n$f_i$, $(h_1, \\ldots , h_m)^{\\rho}= 0 (f_1 , f_2 , \\ldots , f_r)$.\r\n\\\\\r\n\\\\\r\nNote that an algebraic condition for solvability is not always\r\npossible:  Consider\r\n$a_1 x_1 +a_2 x_2 +a_3=0$,\r\n$b_1 x_1 +b_2 x_2 +b_3=0$; they have a solution in general if\r\n$a_1b_2-b_1a_2 \\ne 0$ and the $d_i$ (the resultant system)\r\nwould have to vanish for indeterminant $a, b$ and the\r\nequation would always have a solution but it doesn't.  However, this does work\r\nfor homogeneous equations (forms).\r\n\\end{quote}\r\nGeneral idea of \\emph{elimination} for forms relies on three lemmas:\r\n\\\\\r\n\\\\\r\n\\emph{Lemma 1:} We can assume $x_1$ appears with non-zero\r\nconstant coefficient.\r\n\\begin{quote}\r\n\\emph{Proof:} if not, substitute $x_1= u_1 x_1'$, \r\n$x_2= x_2'+u_2x_1'$, ..., $x_n= x_n'+u_nx_1'$. \r\n\\end{quote}\r\n\\emph{Lemma 2:}  If ${\\cal F}$ has a non-trivial common solution, the $d_i$ do too.\r\n\\begin{quote}\r\n\\emph{Proof:} If the\r\ncoefficients do not vanish, the $d_i$ give rise to a solution $(\\xi_2, \\ldots, \\xi_n)$\r\nin $(x_2, \\ldots, x_n)$ which can be extended to $x_1$; if not, the $d_i$ vanish identically\r\nand have a solution, say $(1,1,\\ldots,1)$ and the $f_i$ have a solution $(1,0,\\ldots,0)$\r\nwith the coefficients of the $x_1$ terms $0$.  \r\n\\end{quote}\r\n\\emph{Lemma 3:} The system ${\\cal F}$ has a\r\nresultant system of integral polynomials $b_j$ in the coefficients of the $f_i$ such that\r\nfor a specialization of the coefficients of the $f_i$, ${\\cal F}$ has a \r\nnon-trivial common solution iff the $b_j=0$; further, the $b_j$ are homogeneous in the\r\ncoefficients of the forms.\r\n\\\\\r\n\\\\\r\n{\\bf Elimination procedure:}  Successively eliminate $x_1 , x_2, \\ldots, x_n$.  At each step,\r\nthe $d_i$ obtained by eliminating previous $x_i$ are forms, \r\nwe can continue the elimination\r\nprocedure until only $x_n$ remains and the resultant system becomes:\r\n${x_n}^{s_1} b_1,\r\n{x_n}^{s_2} b_2, \\ldots,\r\n{x_n}^{s_k} b_k$ and by the above\r\n${x_n}^{s_j} b_j= 0 \\jmod{(f_1, \\ldots, f_n)}$.\r\nIf elimination results in a non-zero constant, there is no\r\ncommon solution and we get $1= 0 \\jmod{(f_1, f_2, \\ldots, f_r)}$.\r\n\\\\\r\n\\\\\r\nObserve that not all solutions can be obtained by specialization.  Consider\r\n$f_1= x_1^2 + x_1 x_2$, $f_2= x_1 x_2 + x_2^2 + x_1 +x_2$, $(x_1+x_2)$ is a common factor\r\nso the resultant vanishes.  $\\xi_1= -\\xi_2$ is a solution; however, if $\\xi_2= -1,\r\n\\xi_1=0$ is also solution which does not fit the specialization solution.\r\n\\\\\r\n\\\\\r\nFor the next few paragraphs, the system $\\cal F$ consists of\r\n$r$ forms, $f_1, ..., f_r$ in $n$ variables\r\nwith indeterminant coefficients.\r\nThe indeterminants in $f_1$ are $a_1, \\ldots , a_{\\omega}$,\r\nthe indeterminants in $f_2$ are $b_1, \\ldots , b_{\\omega}$\r\nand the indeterminants in $f_r$ are $e_1, \\ldots , e_{\\omega}$.  \r\nWhen $r=n$ the resultant system is generated by a single polynomial, $R$, called the\r\nresultant.\r\n\\\\\r\n\\\\\r\nLet ${\\cal F}$ be a system of forms as above with\r\n$deg(f_i)=l_1$ and $l_1=\\alpha, l_2= \\beta, \\ldots, l_r= \\epsilon$.  \r\nBy the above, $\\exists T \\in {\\mathbb Z}[a_1, \\ldots , e_{\\omega}]$ such\r\nthat ${x_i}^{\\tau} T = 0 \\jmod{(f_1, \\ldots, f_n)}$. $T$ is called an inertial form.\r\nSet $f_1= f_1^* + a_{\\omega}{x_n}^{\\alpha}$,\r\n$f_2= f_2^* + b_{\\omega}{x_n}^{\\beta}$, ... ,\r\n$f_n= f_n^* + e_{\\omega}{x_n}^{\\epsilon}$, substituting\r\n$a_{\\omega}= -{\\frac {f_1^*} {x_n^{\\alpha}}}$, ...,\r\n$e_{\\omega}= -{\\frac {f_r^*} {x_n^{\\alpha}}}$, we get\r\n$T(a_1 , \\ldots, -{\\frac {f_1^*} {x_n^{\\alpha}}}, \\ldots, \r\n-{\\frac {f_r^*} {x_n^{\\alpha}}}) =0$\r\n(Condition ``A'')\r\nand this actually holds for all $i$ if it holds for any $x_i$.  Conversely, if\r\nCondition ``A'' is satisfied, ${x_n}^{\\tau} T=0 \\jmod{(f_1, \\ldots, f_r)}$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe can use Condition A to rearrange $T$ in powers of\r\n$a_{\\omega}+{\\frac {f^*_1} {x_n^{\\alpha}}}, \r\n\\ldots, e_{\\omega}+{\\frac {f^*_r} {x_n^{\\epsilon}}}$ and the term independent of the\r\npowers vanishes so \r\n$T= 0\r\n\\jmod {(a_{\\omega}+{\\frac {f^*_1} {x_n^{\\alpha}}},\r\n\\ldots, e_{\\omega}+{\\frac {f^*_r} {x_n^{\\epsilon}}})}$; multiplying through by the largest\r\npower of $x_n$ in the denominators, we get \r\n$x_n^{\\tau}T= 0 \\jmod {(f_1, f_2 , \\ldots , f_r)}$.\r\nThe inertial forms form and ideal ${\\cal I}$ which is prime and a basis for ${\\cal I}$\r\nthus forms a resultant system.\r\n\\end{quote}\r\n{\\bf Theorem}:  If the number\r\nof forms, $f_i$, is less than the number of variables, $n$, then there is no inertial form\r\ndistinct from $0$; if $r=n$, there is no inertial form independent of $e_{\\omega}$ and\r\ndistinct from $0$.  \r\n\\begin{quote}\r\nThe proof uses the following \r\n\\emph{Lemma:}  When a sequence of polynomials\r\n$f_1, \\ldots, f_s$ in indeterminants $a_1 , a_2 , \\ldots, a_p, x_1, x_2, \\ldots, x_q$\r\nis algebraically dependent in $k[a_1, \\ldots, a_p]$, this dependence is valid for\r\nevery specialization $a_p=\\alpha$.  \r\n\\\\\r\n\\\\\r\n\\emph{Proof of Lemma:} Since\r\n$F(a_1, \\ldots, a_p, f_1, \\ldots , f_s)=0$ and\r\n$F(a_1, \\ldots, a_p, z_1, \\ldots , z_s) \\ne 0$, $F(a,z)$ is not divisible by \r\n$(a_p-\\alpha)$ or we could reduce the relations. So\r\n$F(a_1, \\ldots, a_{p-1}, \\alpha, f_1, \\ldots , f_s) \\ne 0$.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of theorem:}\r\nIf $r<n$, by Condition ``A'',\r\n$-{\\frac {f_1^*} {x_n^{\\alpha}}}, \\ldots,\r\n-{\\frac {f_r^*} {x_n^{\\alpha}}}$ would be algebraically dependent relative\r\nto $k[a_1, \\ldots, a_{\\omega -1}, e_1, \\ldots, e_{\\omega -1}]$ and this continues to be\r\ntrue if $x_n = 1$.  If $r=n$ and the hypothesis is false, \r\n$-{\\frac {f_1^*} {x_n^{\\alpha}}}, \\ldots,\r\n-{\\frac {f_{n-1}^*} {x_n^{\\delta}}}$ would be algebraically dependent relative and\r\nwe can set $x_n=1$.  In both cases, the lemma applies and we can specialize over any of the\r\nindeterminants without losing dependency.  Choose a specialization so\r\n$f_1, \\ldots, f_s^{\\delta} \\rightarrow x_1^{\\alpha}, \\ldots, x_s^{\\delta}$.  This is a\r\ncontradiction since these terms are algebraically independent.\r\n\\end{quote}\r\n{\\bf Theorem}:  If $r=n$, there is a non-vanishing\r\ninertial form $D_e$, homogeneous in the indeterminants and of degree\r\n$L_n= l_1 l_2 \\ldots l_{n-1}$ in the $e_j$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  Put \r\n$l= 1+ \\sum_i^n (l_i -1)$ and consider, ${\\cal P}$, the monomials of degree $l$ in the $x_i$.\r\n${\\cal P}$ is a disjoint union of the following sets: \r\nmonomials of degree $l$ containing ${x_1}^{l_1}$,\r\nmonomials of degree $l$ containing ${x_2}^{l_2}$ but not ${x_1}^{l_1}$, \\ldots,\r\nmonomials of degree $l$ containing ${x_n}^{l_n}$ but not \r\n${x_1}^{l_1}$,\r\n${x_2}^{l_2}$, etc.  Suppose $H^{(m)}_{l-l_1}$ are the complementary monomials of\r\nthe elements of the disjoint sets, i.e. - \r\n${x_1}^{l_1}H^{(m)}_{l-l_1}$ are in the disjoint sets.  $H^{(m)}_{l-l_n}$ has\r\n$l_1 l_2 \\ldots l_{n-1}$ power products ($x_1^k, 0 \\le k < l_1$, etc).  Now form\r\n$H^{(m)}_{l-l_i} f_i$.  Since there are as many of these as power products, the matrix is\r\nsquare.  Denote its determinant as $D_e$ which has the value $1$ under the specialization\r\n$f_i= {x_i}^{l_i}$.  Multiplying the equations $H^{(j)}_{l-l_i} f_i = \\sum a_{mk} H^{(k)}_l$\r\nby the subdeterminants of a column of $D_e$ and adding, the left hand side becomes\r\nlinear in the $f_i$ and the right hand side, $D_e H^{(k)}_l$.  Letting\r\n$H^{(k)}_l= x_i^l$, we get $D_rx_i^l = 0 \\jmod{(f_1, f_2, \\ldots, f_r)}$ and $D_e$\r\nis homogeneous in each form, $f_i$ and has degree $L_n$ in the coefficients of $f_n$.\r\n\\end{quote}\r\nNow, let $f_1, f_2, \\ldots, f_n$ be forms in $x_1, x_2, \\ldots, x_n$ with indeterminate\r\ncoefficients and ${\\cal I}$ the ideal generated by the inertial forms.  \r\n{\\bf Theorem:} If $R$ is a polynomial of minimal degree in $e_{\\omega}$, every element of \r\n${\\cal I}$ is divisible by $R$.  $R$ is the resultant.  \r\n\\begin{quote}\r\n\\emph{Proof:} Arrange $R$ in powers of\r\n$e_{\\omega}, R= S {e_{\\omega}}^{\\lambda} + \\ldots $.  If $T$ is in ${\\cal I}$, we can\r\nget a polynomial, $T'=S^jT-QR$ of lower degree which is also in ${\\cal I}$ but then $T'=0$ and\r\n$R \\mid T$.  Note if $R$ vanishes for a specialization, every element of ${\\cal I}$\r\ndoes also and the $f_i$ have a common 0; \r\nconversely, if the $f_i$ have a common zero, since\r\n${x_i}^{\\tau}R = A_1 f_1 + \\ldots + A_n f_n$, substitution makes the right side of\r\nthe equation $0$ but at least one $x_i \\ne 0$ so $R=0$.  We have:\r\n{\\bf Theorem}:\r\n$R(gh,f_2, \\ldots, f_n)= R(g,f_2, \\ldots, f_n) R(h,f_2, \\ldots, f_n)$, $R$ is\r\nhomogeneous of degree $L_1$ in the coefficients of $F_1$,\r\nhomogeneous of degree $L_2$ in the coefficients of $F_2$, ..., \r\nand homogeneous of degree $L_n$ in the coefficients of $F_n$,\r\n$R= (D_a, D_b, \\ldots, D_e)$ is a principal ideal\r\nand the resultant contains a principal term\r\n${a_1}^{L_1} \\ldots {e_{\\omega}}^{L_n}$.\r\n\\end{quote}\r\n{\\bf Bezout's theorem:}  If $n-1$ homogeneous equations have a finite number of solutions\r\nthen sum of the multiplicities equals \r\nthe product of the degrees of the equations.\r\n\\begin{quote}\r\n\\emph{Proof of Bezout}:  Suppose the system ${\\cal F}, r=n$ has a finite \r\nnumber of non-trivial\r\nsolutions $(\\xi_1^{(\\alpha)}, \\ldots, \\xi_n^{(\\alpha)})$, $\\alpha= 1,2, \\ldots, q$.\r\nAdd the form $l= u_1 x_1 + \\ldots + u_n x_n$ and form the resultant system $b_1(u),\r\nb_2(u), \\ldots, b_t(u)$.  The resultant system has a solution iff\r\n$l_{\\alpha}= u_1 {\\xi_1}^{(\\alpha)} + \\ldots + u_n {\\xi_n}^{(\\alpha)} =0$.  By\r\nthe Nullstellensatz: \r\n$(b_i(u))^{\\tau_i} = 0 \\jmod{ (\\prod_{\\alpha} l_{\\alpha})}$ and\r\n$(\\prod_{\\alpha} l_{\\alpha})^{\\tau}= 0 \\jmod{D(u)}$ where\r\n$D(u) = ( b_1(u), \\ldots, b_t(u))$.  So $D(u)= \\prod_{\\alpha} {l_{\\alpha}}^{\\rho_{\\alpha}}$\r\n(the $\\rho_{\\alpha}$'s are the multiplicities).\r\nIf we consider $n-1$ forms $f_i$ and add the form $l=u_1 x_1 + \\ldots + u_n x_n$, we get\r\nBezout's theorem.\r\n\\end{quote}\r\n{\\bf Berlekamp polynomial factorization over $F_q$:} $f(x)$ square free so\r\n$f(x)= p_1(x) \\ldots p_r(x)$. \r\nNote that $v(x)^p=v(x)$ and $(v(x)-0)(v(x)-1) \\ldots (v(x)-(p-1)) \\jmod{f(x)}$\r\nand $\\exists s_i \\in F_q: (f(x), v(x)-s_i)= p_i(x)$.\r\nCompute $x^{iq} \\jmod{f(x)}= \\sum q_{ij} x^j$.\r\nFind null space of $Q-I$ with basis $v_1 (x) , \\ldots , v_r (x)$.\r\nCompute $(f(x), v_k (x) - \\alpha ), \\alpha \\in F_q$.\r\n$f_{n}(x) = {\\frac {(x^{n} - 1)} {\\prod_{d \\mid n, d<n} f_{d}(x)}}$.\r\nFor \\emph{distinct factors}, note that if $q(x)$ is irreducible of degree $d$ then\r\n$q(x) \\mid x^{p^d} -x$ but $q(x) \\mid x^{p^c} -x, c<d$.  To use this, rull out square free\r\nagain, set $w(x)=x$, $d=0$ and repeatedly check $g_d(x)= w(x)-x, v(x)$ and replace\r\n$d$ by $d+1$,\r\n$w(x)$ by $w(x)^p$, and $v(x)$ by ${\\frac {v(x)} {g_d(x)}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Submodules of finitely generated free modules over a PID:}\r\nLet $D$ be a PID and $D^{(n)}$ be a free module of rank $n$ over $D$.  Then any\r\nsubmodule, $K$ of $D^{(n)}$ is free with base $m \\leq n$ elements.\r\n\\begin{quote}\r\n\\emph{Proof:}  By induction.  For $n=1$, $K$ is isomorphic to a principal ideal.\r\nSuppose the result is true for $n-1$.  Let\r\n$x_1, \\ldots, x_n$ be a free basis for $M$.  \r\nIf $K$ is contained in any module generated by all\r\nbut one of the $x_i$, were done by induction.  Let $\\pi_i$ be the projection on the\r\n$i$-th basis element.  \r\n$im((\\pi_i)_{|K})$ is a principal ideal generated by $p_i$.  WLOG let $p=p_1$ generate the\r\nmaximal ideal among these, so $p | p_i, \\forall i$. \r\n$\\exists k \\in K: k= p x_1 + p d_2 x_2 + \\ldots + p d_n x_n$.\r\nPut $y= x_1 + d_2 x_2 + \\ldots + d_n x_n$.  $M= Dy \\oplus D x_2 \\oplus \\ldots \\oplus D x_n$ \r\nand $py \\in K$.\r\nSet $K_1= (K \\cap \\langle x_2, \\ldots, x_n \\rangle)$.\r\n$K= (Dp) y + K_1$ and $Dp x_1 \\cap K_1= \\{0\\}$ so $K= Dp y \\oplus K_1$.\r\nSince $K_1 \\subseteq \\langle x_2 , x_3 , \\ldots , x_n \\rangle$, the result follows now \r\nby applying the induction hypothesis.\r\n\\end{quote}\r\n{\\bf Multivariate division algorithm:}\r\nFix a monomial order ($\\leq$) for terms in $x_1, x_2, \\ldots x_n$. Denote leading term of\r\n$f$ under this order as $in_{\\leq}(f)$.   The division algorithm for $f$\r\nwith respect to the monomial order produces\r\n$f(x)= a_1 (x) f_1 (x) + \\ldots + a_m (x) f_m (x) + r(x) $\r\nwhere $r=0$ or $r$ is a linear combination of monomials none of which are\r\ndivisible by $in_{\\leq}(f_i )$.  This is written as\r\n$r= {f^F}$.  \\emph{Procedure for multi-variable division algorithm:} Set\r\n$r \\leftarrow f(x), a_i(x) \\leftarrow 0$.\r\nPick ordering of $f_1(x), f_2(x), \\ldots , f_m(x)$.\r\nIf $in_{\\leq}(f_j) | in_{\\leq}(r)$ for any $j$, pick first such $j$, set\r\n$t \\leftarrow {\\frac {in_{\\leq}(r)} {in_{\\leq}(f_j)}}$,\r\n$s \\leftarrow s- t f_j(x)$,\r\n$a_j(x) \\leftarrow a_j(x) + t$; repeat this step until if condition fails.\r\n$r \\leftarrow s$.  In general, the result depends on the ordering of the\r\n$f_j(x)$.  \\\\\r\n\\\\\r\n{\\bf Grobner Basis}:  A finite subset\r\n$G= \\{ g_1 , g_2 , ..., g_s \\}$ is a Grobner basis for an ideal $I$\r\nwith respect to the monomial order $\\leq$ if\r\n$\\langle in_{\\leq}(g_1 ), in_{\\leq}(g_2 ), ... , in_{\\leq}(g_s )  \\rangle= \r\n\\langle in_{\\leq}(I) \\rangle$.\r\nEquivalently, if $f \\in I$, $in_{\\leq}(g_i ) | in_{\\leq}(f)$ for some $i$.\r\nIf $G$ is a Grobner basis $f^G$ is independent of the order of the $f_i(x)$.\r\nIf $G$ is a Grobner basis and $I= \\langle G \\rangle$, $f \\in I$ iff $f^G = 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Dickson's Lemma:}  If $S \\subseteq N^n$ then $\\exists v_1, v_2, \\ldots v_m$ such\r\nthat $S \\subseteq (v_1 + N^n) \\cup (v_2 + N^n) \\cup \\ldots \\cup (v_m + N^n)$.\r\n\\\\\r\nConsequence: Every ideal has a Grobner basis.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $S= \\{v: x^v = in_{\\leq}(f), f \\in I \\}$.  By Dickson,\r\n$S \\subseteq \\bigcup_i (v_i + N^n), i= 1,2, \\ldots m$. If\r\n$f(x) \\in I$,\r\n$ax^w = in_{\\leq} (f), w= v_i + v$ for some $i, v$ then\r\n$x^w= x^{v_i}x^v$ hence $in_{\\leq}(f_i) | in_{\\leq}(f)$.\r\n\\end{quote}\r\n{\\bf Buchberger reduction:}\r\n$f \\in R$ reduces to 0 with respect to  \r\n$f= \\langle f_1, f_2, \\ldots, f_m \\rangle \\subseteq R - \\{0\\}$\r\niff $\\exists a_1 , a_2 , \\ldots , a_m \\in R$:\r\n$f= a_1 f_1 + a_2 f_2 + \\ldots + a_m f_m$ and $in_{\\leq}(a_i f_i) \\leq in_{\\leq}(f)$\r\nif $a_i f_i \\ne 0$.  This is denoted by $f \\rightarrow_F 0$.\r\nLet $G= (g_1,g_2, \\ldots, g_m)$, $I= \\langle G \\rangle$.  \r\nIf $f \\rightarrow_G 0$ for all $f \\in I$\r\nthen $G$ is a Grobner basis.  If $G$ is a Grobner basis for $I$,\r\n$f^G=0$ iff $f \\rightarrow_G 0, \\forall f \\in I$.\r\n$S(f, g)= {\\frac {x^{\\gamma}} {in_{\\leq}(f)} } f - {\\frac {x^{\\gamma}} {in_{\\leq}(g)} } g$,\r\nwhere $x^{\\gamma}= LCM(in_{\\leq}(f),in_{\\leq}(g))$.\r\nIf $S(f_i, f_j) \\rightarrow_F 0, \\forall i,j$ then $f \\rightarrow_F 0, \\forall f \\in I$.\r\n$F$ is a Grobner basis iff $S(f_i,f_j) \\rightarrow_F 0, \\forall i,j$ iff\r\n$S(f_i, f_j)^F = 0, \\forall i,j$.\r\n\\\\\r\n\\\\\r\n{\\bf Buchberger Algorithm:}\r\nTest $S(f_i, f_j)^F \\ne 0$, $F= F \\cup \\{ S(f_i, f_j) \\}$.  Do this\r\nuntil all $S(f_i, f_j)^F=0$.  This procedure terminates.\r\n\\\\\r\n\\\\\r\n{\\bf Minimal Grobner:}\r\n$in_{\\leq}(f_i)$ does not divide\r\n$in_{\\leq}(f_j)$ and coefficients are 1.  \\emph{Reduced Grobner:} Minimal Grobner where\r\n$in_{\\leq}(f_i)$ does not divide any term of $in_{\\leq}(f_j)$.\r\n\\emph{Example:} $F=(x^2+y, x^2y+1)$.  $S(x^2+y, x^2y+1)= y^2-1$,\r\n$(x^2+y, x^2y+1, y^2-1)$ is a Grobner basis.\r\n\\emph{Elimination ideals:} $I_l = I \\cap k[ x_{l+1} , ..., x_{n} ]$.\r\n\\\\\r\n\\\\\r\n{\\bf More on Resultants.} Condition 1: \r\n$F_{0}(x_0 , x_1 , \\ldots , x_n) = F_{1}(x_0 , x_1 , \\ldots , x_n) =\r\n\\ldots = F_{n}(x_0 , x_1 , \\ldots , x_n)=0 $, \r\nwith each $F_i$ homogeneous of degree\r\n$d_i$ in the $x_i$.  Let $F_i (x_0 , x_1 , \\ldots , x_n)= \\sum_{|\\alpha|= d_i} \r\nu_{i, \\alpha} x^{\\alpha}$.\r\n{\\bf Theorem 1:} Fix $d_0 , d_1 , \\ldots , d_n$, there is a unique polynomial\r\n$Res \\in {\\mathbb Z} [ u_{i, \\alpha}]$ such that if $u_{i,\\alpha}$ are replaced by the \r\ncorresponding $c_{i,\\alpha} \\in {\\mathbb C}$\r\nand $F_i$ is homogeneous of degree $d_i$ then (a) the equations of condition 1 have a \r\nnon-trivial solution in ${\\mathbb C}$ iff $Res(F_0 , F_1 , \\ldots , F_n)=0$, (b)\r\n$Res( x_0^{d_0}, x_1^{d_1}, \\ldots , x_n^{d_n}) = 1$, (c) $Res$ is irreducible.  \r\nSometimes we write \r\n$Res_{d_0 , d_1 , \\ldots , d_n}$ to emphasize degrees.\r\nNote that $Res_{1,1, \\ldots , 1}$ is just the determinant.\r\n{\\bf Theorem 2:} For fixed $j, 0 \\le j \\le n$, $Res$ is homogeneous in $u_{j, \\alpha}$\r\nof degree $d_0 \\cdot d_1 \\cdot d_{j-1} \\cdot d_{j+1} \\cdot d_n$; further,\r\n$Res(F_0, \\ldots , F_{j-1} , \\lambda F_j , F_{j+1}, \\ldots, F_n)\r\n\\lambda^{ d_0 \\cdot d_1 \\cdot d_{j-1} \\cdot d_{j+1} \\cdot d_n}\r\nRes(F_0, F_1 , \\ldots , F_n)$ and the total degree of $Res$ is $\\sum_{j=0}^n\r\nd_0 \\cdot d_1 \\cdot d_{j-1} \\cdot d_{j+1} \\cdot d_n$.  $Res$ is alternating in the\r\n$F_i$ and \r\n$Res(gh , F_2, \\ldots, F_n) = Res(g , F_2, \\ldots, F_n) Res(h , F_2, \\ldots, F_n)$.\r\n\\emph{Example:}\r\n$Res_{2,2,2} (F_0 , F_1 , F_2)$ has $18$ variables of total degree \r\n$12$ and $21,894$ terms.  \r\nIf $f(x)= a_l x^l + \\ldots + a_0$ and\r\n$g(x)= b_m x^m + \\ldots + b_0$ then\r\n$Res(f,g,x)= a_l^m b_m^l \\prod_{i=1}^l \\prod_{j=1}^m (\\xi-\\eta_i)= \r\na_l^m \\prod_{i=1}^l g(\\xi_i)=\r\nb_m^l \\prod_{i=1}^m f(\\eta_i)$.  Put $A_f= k[x]/(f(x))$ and let $[h]_f$ be\r\nthe natural map from $k[x] \\rightarrow A_f$, further, let\r\n$m_g: [h]_f \\mapsto [gh]_f$ then $m_g$ is a linear map and $Res(f,g,x)= det(m_g)$.\r\n\\subsection{Linear Algebra}\r\n{\\bf Homomorphisms on modules:}\r\nLeft module $M$ over $R$ with $RM \\subset M$, $1 m = m, (r+s)m=rm+sm$, etc.\r\nNotation: $End_R(X)= Hom_R(X,X)$.\r\n$Hom_R(U,V)= \\{ f, f:U \\rightarrow V, \r\nf(r_1 u + r_2 v)= r_1 f(u) + r_2 f(v) \\}$ where $r_i \\in R$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} \r\nIf $V$ is a vector space (or module) then $V^*$, the set of linear functions over $V$, \r\nis the \\emph{dual space}.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $V$ is finite dimensional, $dim(V)= dim(V^*)$.  $V \\approx V^{**}$.  \r\nObserve that the solution space is the\r\nkernel of linear map, $L$. \r\n$colRank + dim(ker(L))=n$.  $rowRank + dim(ker(L))=n$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let\r\n$L = \r\n\\left(\r\n\\begin{array}{ccc}\r\na_{11} & \\ldots & a_{1n}\\\\\r\n\\ldots & \\ldots & \\ldots\\\\\r\na_{m1} & \\ldots & a_{mn}\\\\\r\n\\end{array}\r\n\\right)$.  $L: {\\mathbb R}^n \\rightarrow {\\mathbb R}^m$.  The image of $L$ is the column\r\nspace of $L$ and the kernel of $L$ is the solution space to $Lx = 0$.\r\n${\\mathbb R}^n / ker(L) \\cong im(L)$ so $n - dim(ker(L)) = colRank(L)$.\r\nNow, $ker(L)$ is the space of vectors in ${\\mathbb R}^n$ orthogonal to the\r\nrows of $L$ so $dim(ker(L)) + rowRank(L) = n$. So, $rowRank(L) = colRank(L)$.\r\n\\end{quote}\r\n{\\bf Theorem:}   Suppose $r_1, r_2 , \\ldots , r_m \\in {\\mathbb R}^n$ are linearly independent and\r\n$S= \\{ x \\in {\\mathbb R}^n: x \\cdot r_i=0 \\}$ then $dim(S)=n-m$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Put $W= \\{ r_1, r_2, \\ldots , r_m \\}$.\r\n$r_i \\notin S$ since $r_i \\cdot r_i \\ne 0$ so $dim(S) \\le n-m$.  Define $\\alpha: x \\mapsto\r\n(x \\cdot r_1, \\ldots , x \\cdot r_m)$.  Then $dim(ker(\\alpha)) = dim(S)$ and\r\n$dim(ker(\\alpha)) + dim(im(\\alpha)) =n$.  Since $dim(im(\\alpha)) \\le m$, $dim(S) + m \\ge n$ so\r\n$dim(S) \\ge n-m$.\r\n\\end{quote}\r\n{\\bf Theorem:} The row rank, $r$, equals column rank, $c$. \r\n\\begin{quote}\r\n\\emph{Proof:} Let $A= (a_{ij})$ be an $m \\times n$ matrix.  \r\nLet $\\langle S_1 , \\ldots , S_r \\rangle$ be a basis for the row space.\r\nPut $S_i= (s_{ij}), 1 \\leq j \\leq n, 1 \\leq i \\leq r$. \r\nLet row $i$, $R_i= (a_{i1}, a_{i2}, \\ldots, a_{in})$.\r\n$R_i = \\sum_{t=1}^r k_{it} S_t$.  \r\nSo $a_{ij}= \\sum_{t=1}^r k_{it} s_{tj}, 1 \\leq j \\leq n, 1 \\leq i \\leq m$ and\r\nthe column vectors $(k_{1i}, k_{2i} , \\ldots , k_{mi})^T, 1 \\le i \\le r$ \r\nspan the column space.  Thus $c \\leq r$.\r\nThe same holds for $A^T$ and so $r \\leq c$ and $r=c$.\r\n\\\\\r\n\\\\\r\n\\emph{Artin's proof:}\r\n\\\\\r\n\\emph{Lemma:} If $W \\subset V$ are vector spaces over $k$ and $W^{\\perp} \\subset V^*$ then\r\n$dim(W) + dim(W^{\\perp}) = dim(V)$.\r\n\\\\\r\n\\emph{Proof of result:} Let $T:k^n \\rightarrow k^m$ be the\r\nlinear transformation represented by the matrix $M$ with rows $r_1 , r_2 , \\ldots , r_m$\r\nand columns $c_1, \\ldots , c_n$ and let the row space of $M$ be $R$ and the column space,\r\n$C$; finally, let $r=dim(R)$, $c=dim(C)$ and $W= ker(T)$.  Since $dim(Im(T))+dim(W)=n=dim(V)$,\r\n$r=n-dim(W)$ and $dim(W) + dim(W^{\\perp})=n$, it suffices to show $dim(W^{\\perp})=r$.  \r\nNote that\r\n$r_i \\cdot w= 0$ for $w \\in W$ so, if $\\lambda_i$ is the usual dual basis of $V^*$ with\r\nrespect to \r\n$\\langle e_1 , e_2 , \\ldots , e_n \\rangle$ where\r\n$\\langle e_1 , e_2 , \\ldots , e_k \\rangle=W$.  \r\nLet $\\lambda_j$ be the natural dual basis and note that\r\n$R \\subseteq \\langle e_{k+1} , e_{k+2}, \\ldots , e_n \\rangle$ \r\nsince $r_i \\cdot \\lambda_j=0$ for $j \\le k$.\r\nNow let \r\n$b_{k+1} \\lambda_{k+1} + \\ldots + b_n \\lambda_n = \\lambda \\in W^{\\perp}$.\r\nConsider\r\n$\\varphi: \\lambda \\mapsto b_{k+1} e_{k+1} + \\ldots + b_n e_n$.  If \r\n$\\varphi(\\lambda)=0$, $\\lambda=0$ so $dim(R)=dim(W^{\\perp})$ and the result holds.\r\n\\end{quote}\r\nHere's still another proof.\\\\\r\n\\\\\r\n{\\bf Theorem:} If $A:V \\rightarrow W$ is a linear transformation (i.e, $A \\in Hom_{\\mathbb R}(V,W)$) between two \r\nfinite dimensional vector spaces over ${\\mathbb R}$, then $V = U \\oplus S$ where $U \\cong im(A)$ and $S=ker(A)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Let $\\langle u_1, u_2, \\ldots , u_k \\rangle$ be a basis for $im(A)$, so $k=dim(im(A))$.  Pick\r\n$v_1, \\ldots, v_k \\in V: A(v_i)= u_i, 1 \\leq i \\leq k$. First observe $\\langle v_1, \\ldots, v_k \\rangle$ are\r\nlinearly independent because $a_1 v_1 + \\ldots + a_k v_k = 0$ implies $a_1 A(v_1) + \\ldots + a_k A(v_k) = 0$ so\r\n$a_1 u_1 + \\ldots + a_k u_k = 0$ and all the $a_i$ are $0$ since $\\langle u_1, u_2, \\ldots , u_k \\rangle$ is\r\na basis; also note that $U= span(v_1, \\ldots, v_k) \\cong im(A)$.\r\nLet $S= ker(A)$.  $V= U + S$ so we need only show $U \\cap S = 0$.\r\nIf $v= a_1 v_1 + \\ldots + a_k v_k \\in S$ then $a_1 A(v_1) + \\ldots + a_k A(v_k) = 0$ but since $\\langle u_1, u_2, \\ldots , u_k \\rangle$\r\nis a basis, we must have $v=0$.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $V= {\\mathbb R}^n$ and $\\langle v_1, \\ldots, v_m \\rangle$ be a set of linearly independent vectors in $V$.\r\nPut $S= \\{v \\in V: (v_i, v)= 0, i = 1, \\ldots, m\\}$.  Finally, put $s= dim(S)$.  $s+m = n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nPut $W= span(v_1, \\ldots, v_m)$.\r\nFirst note that $S \\cap W = 0$ because $v \\in S \\rightarrow (v,w)=0, \\forall w \\in W$.  If $v \\in W$, this means $(v,v)=0$ so\r\n$v=0$.  Now, $dim(W+S) = dim(W) + dim(S) - dim(S \\cap W)= dim(W) + dim(S) \\leq n$  so $n - m \\geq s$.  \r\nDefine $\\alpha: V \\rightarrow {\\mathbb R}^m$ by $\\alpha(v) = ( (v_1, v), (v_2, v), \\ldots, (v_m, v) )$. \r\n$\\alpha \\in Hom_{\\mathbb R}({\\mathbb R}^n, {\\mathbb R}^m)$ so $im(\\alpha) + ker(\\alpha) = {\\mathbb R}^n$.\r\n$ker(\\alpha) = S$ and $dim(im(\\alpha)) \\leq m$ since $im(\\alpha) \\subseteq {\\mathbb R}^m$.  Thus\r\n$m + s \\geq n$ and $s \\geq n-m$, this, along with the previous inequality gives $n-m=s$.\r\n\\end{quote}\r\n{\\bf Theorem:}  Let $A=\r\n\\left(\r\n\\begin{array}{cccc}\r\na_{11} & a_{12} & ... & a_{1n} \\\\\r\n... & ... & ... & ... \\\\\r\na_{m1} &  a_{m2} & ... & \\ a_{mn}\\\r\n\\end{array}\r\n\\right)$.  $A: {\\mathbb R}^n \\rightarrow {\\mathbb R}^m$.  Let $r$ be the row rank of $A$ and $c$ be the column rank. Then\r\n$r=c$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nPut $a_i^{R} = (a_{i1},  a_{i2} ,  \\ldots a_{in}), 1 \\leq i \\leq m$ and \r\n$a_j^{C} = (a_{1j},  a_{2j} ,  \\ldots a_{mj})^T, 1 \\leq j \\leq n$.\r\nPut $S= \\{x \\in {\\mathbb R}^n: (a_i^{R}, x)=0, 1 \\leq i \\leq m \\}$ and $s= dim(S)$.  Note that $S=ker(A)$.  By the previous theorem,\r\n$n= s + r$. The column space of $A$ is $V_{CS}= span(a_1^{C}, \\ldots ,a_n^{C})$ which is just $im(A)$.  So\r\n$n = c +s$.  Thus $r=c$.\r\n\\end{quote}\r\n{\\bf Change of basis for matrix:}\r\nLet $[e]= \\{ e_1 , \\ldots , e_n \\}$ be a basis for $V_n$ and let $L$ be a\r\nlinear transformation on $V_n$.  Let \r\n$v_{[e]} = [c_1 , c_2 , ... , c_n]^T$ denote the\r\ncoordinates of $v$ with respect to $[e]$: $v_{[e]}= c_1 e_1 + ...+ c_n e_n$.\r\nLet $L_{[e]}$ denote the\r\nmatrix for $L$ with respect to $[e]$: $L_{[e]}: e_i \\mapsto \\sum_j a_{ji} e_j$. Then\r\n$L_{[e]} v_{[e]} = (Lv)_{[e]}$.  If $f_i= \\sum_j b_{ji} e_j$ is another basis,\r\n$P= (b_{ij})$ is called the transition matrix from $[f]$ to $[e]$\r\n(equivalently, $P[e_1, e_2, \\ldots , e_n] = \r\n[f_1, f_2, \\ldots , f_n]$) and $P^{-1}$ is\r\nthe transition matrix from $[e]$ to $[f]$ (note the sum over the first index).\r\n$Pv_{[f]}= v_{[e]}$ and\r\n$v_{[f]}= P^{-1}v_{[e]}$.  Finally, $L_{[f]}= P^{-1} L_{[e]}P$.  The same holds over free\r\nmodules.  Alternate notation: $L: V \\rightarrow W$, \r\n$V$ has basis ${\\cal B}$ and\r\n$W$ has basis ${\\cal B'}$ with $L(w_i)= \\sum_j a_{ij} v_j$ then\r\n$M^{\\cal B}_{\\cal B'}(F)= A^T$.  If ${\\cal B}$ and ${\\cal B'}$ are over\r\nthe same space, \r\n$M^{\\cal B'}_{\\cal B'}(F)= N^{-1}M^{\\cal B}_{\\cal B}(F)N$ where\r\n$N= M^{\\cal B'}_{\\cal B}(id)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe group of \\emph{affine transformations} is isomorphic\r\nto the subgroup of the matrices with last column $(0,0, \\ldots, 0,1)$.\r\nThe translations form a normal subgroup.\r\n\\\\\r\n\\\\\r\n{\\bf Cayley-Hamilton Theorem:}  \r\nAny matrix, $A$,\r\nacting on a vector space $V$ of dimension $n$, over a field, $F$, whose \r\ncharacteristic roots lie in $F$ (For example, if $F$ is\r\nalgebraically closed field) is similar to a \r\ntriangular one.  The minimum polynomial divides the characteristic polynomial.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe second statement follows from the first since the characteristic roots, $\\lambda_i$\r\nappear on the diagonal of the triangular matrix and the characterisitic polynomial is\r\nthus $f(x)= \\prod_{i=1}^n (x-\\lambda_i)$.  $f(A)=0$ so the minimal polynomial divides the\r\ncharacteristic polynomial.  The proof of the first statement is by induction on $n$.  It is\r\ntrue for $n=1$.  Suppose it's true for $n-1$.  $A$ has an eigenvalue, say, $\\lambda_1$ in\r\n$F$ with $Av= \\lambda_1 v_1, v_1 \\ne 0$.  Put $W= \\{ av_1, a \\in F \\}$. $A$ acts on\r\n$V/W$ which has dimension $<n$ so by induction, $\\exists v_2 , \\ldots , v_n$ and\r\n$a_{ij} \\in F$: \r\n$A {\\overline v}_2= a_{22} {\\overline v}_2$,\r\n$A {\\overline v}_3= \r\na_{32} {\\overline v}_2 +\r\na_{33} {\\overline v}_3$,\r\nand so on.  Let $v_i, i>1$ be corresponding elements of $V$.  $Av_2-a_{22}v_2 \\in W$ and\r\nso on.  Thus $A$ is triangular in the basis $\\{ v_1, \\ldots, v_n \\}$.\r\n\\end{quote}\r\n{\\bf Definitions:} Let $A^*$ denote the \\emph{adjoint} (conjugate transpose).  \r\n$(Ax,y)=(x,A^*y)$.\r\nA \\emph{hermitian matrix} is self adjoint over complex numbers.\r\nA \\emph{symmetric matrix} is self adjoint over reals.  \r\nA \\emph{unitary matrix} $AA^*=I$; equivalently: $A$ is length\r\npreserving: $(Ax,Ay)=(x,y)$.  \r\n$A$ is \\emph{nilpotent} if $\\exists q$: $A^q = 0$, smallest $q$ is degree of nilpotence.\r\n$A$ is \\emph{normal} if $A A^*= A^* A$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $T$ is any linear transform on $V_n$, $\\exists M_0 , M_1 , \\ldots , M_n$:\r\n(i) $AM_k \\subseteq M_k$, (ii) $dim (M_j )= j$, (iii)\r\n$\\{0\\} = M_0 \\subseteq M_1 \\subseteq \\ldots \\subseteq M_n= V_n$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A$ is a linear transform on $V_n$ with proper values\r\n$\\lambda_1 , \\lambda_2 ,  \\ldots , \\lambda_p$ having multiplicity\r\n$m_1 , m_2 ,  \\ldots , m_p$ then $V_n =  M_1 \\oplus \\ldots \\oplus M_p$ with\r\n$AM_j \\subseteq M_j$, $dim(M_j ) = m_j$ and $A- \\lambda_j I$\r\nis nilpotent on $M_j$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A$ is nilpotent of degree $q$, $\\exists x$: $A^{q-1}x \\ne 0$ and\r\n$x , Ax , A^2 x, \\ldots A^{q-1} x$ are linearly independent.  \r\nEvery linear transform is the direct sum of a nilpotent and an invertible transform.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nThe existence of $x$ is guarenteed by nilpotence.\r\nIf $a_0 x +  a_1 Ax + a_2 A^2 x  + \\ldots a_{q-1} A^{q-1} x = 0$, applying $A$\r\n$q-1$ times, we get  $a_0 A^{q-1}(x)= 0$ which is a contradiction. \r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A$ is symmetric and $X$ is orthogonal then $X A X^{-1}$ is symmetric.\r\n\\begin{quote}\r\n\\emph{Proof:}  Since $X$ is orthogonal, $X^{-1} = X^T$.\r\n$X A X^{-1} = (X A X^T)^T = X A^T X^T = X A X^T = (X A X^{-1})^T$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$T$ is orthogonal (unitary) iff it takes orthonormal basis into orthonormal basis\r\nwhich happens iff $TT^*=I$.  \r\n\\begin{quote}\r\n\\emph{Proof:} \r\nIf $T$ is unitary and $\\langle v_1, \\ldots , v_n \\rangle$ is an orthonormal basis,\r\n$(Tv_i, Tv_j)= (v_i, v_j)= \\delta_{ij}$ and $\\langle Tv_1 , \\ldots , Tv_n \\rangle$ is\r\nan orthonormal basis.\r\nIf $T v_i = w_i$ and \r\n$\\langle v_1 , \\ldots , v_n \\rangle$ and $\\langle w_1 , \\ldots , w_n \\rangle$ \r\nare both orthogonal basis extending linearly we get, $(Tx, Ty)= (x,y)$ and $T$ is unitary.\r\n\\end{quote}\r\n{\\bf Theorem:}  (a) If $S^*S(v)=0$, $S(v)= 0$.\r\nSuppose $N$ is \\emph{normal}. \r\n(b) $N(v)= 0 \\rightarrow N^*(v)= 0$.\r\n(c) If $N(v)= \\lambda v$, $N^*(v)= {\\overline {\\lambda}} v$. \r\n(d) If $N^k(v)=0$ then $N(v)=0$.\r\n(e) If $N(v)= \\lambda v, N(w)= \\mu w, \\lambda \\ne \\mu$ then $(v,w)= 0$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nFor (a), $(S^*S(v),v) = 0 = (S(v), S(v))$ and so $S(v)= 0$.\r\nFor (b), $(N^*(v), N^*(v))= (NN^*v,v)= (N^*Nv,v)=(Nv,Nv)=0$.\r\nFor (c), $(N-\\lambda) (N^*-{\\overline {\\lambda}}) $.  Since \r\n$(N-\\lambda)$ is normal and\r\n$(N-\\lambda)(v)= 0$, (b) gives\r\n$(N-\\lambda)^*(v)= 0$ and the result follows.\r\nFor (d), let $S=N^*N$ then $S^k v= (N^*)^k N^k v= 0$.  Since $S^*=S$, $S(v)= 0$ by\r\n(a) and again by (a) $N(v)= 0$.\r\nFor (e), $\\lambda (v,w)= (Nv,w)= (v, N^* w)= (v, {\\overline {\\mu}} w)= \\mu (v,w)$ and\r\nthe result follows.\r\n\\end{quote}\r\n{\\bf Spectral Theorem:}  If $T$ is \\emph{normal} ($TT^*=T^*T$), $\\exists E_{1}, \r\n\\ldots , E_{r}$ such that $T= \\sum_{i}^{r} \\lambda_{i} E_{i}$ with\r\n$T= \\sum_{i}^{r} E_{i}= I$, $E_{i}E_{j}= 0$ and transforming matrix, A,\r\nunitary $({\\overline A^{t}} = A^{-1})$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\lambda_1, \\ldots, \\lambda_k$ be the distinct characteristic roots of $T$.  By\r\nthe primary decomposition theorem, $V= V_1 \\oplus \\ldots \\oplus V_n$\r\nand each $V_i$ is annihilated by $(T-\\lambda_i)^{n_i}$.  Vectors\r\nin different $V_i$'s are orthogonal and each $V_i$ has an orthonormal basis by Gram-Schmidt.\r\n$T$ can be transformed into an upper triangular matrix with its eigenvalued on the diagonal,\r\nsinfe $T$ is normal, this matrix must be diagonal.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A$ is symmetric there is a $P$ such that $P^TAP$ is diagonal.  All the \r\neigenvalues are real.\r\n\\begin{quote}\r\n\\emph{Proof:} Diagonalizability follows from the Spectral theorem.  If\r\n$Av= \\lambda v$, $(AA^Tv, v)= (Av,Av)= \\lambda^2>0$ so the eigenvalues are real.\r\n\\end{quote}\r\n{\\bf Sylvester's Theorem:}\r\nEvery real quadratic form is equivalent to a diagonal one\r\nwith a signature of positive and negative coefficients.   \r\nTwo forms are\r\nequivalent iff they have the same rank and signature.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSince the matrix for the form is real and symmetric it can be brought into diagonal form\r\nby an orthogonal transformation and the eigenvalues are the diagonal elements of the\r\nmatrix.  The rank is invariant and so the number of nonzero elements is an invariant.\r\nBecause there are square roots, we can assume the elements are $\\pm 1$.  If \r\n$r$ is the number of $-1$'s and \r\n$s$ is the number of $1$'s we need only show these are invariants.  Since the subspace\r\nof vectors on which the form is positive is an invariant, we're done.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nExtreme point in {convex} set: $P$ with no $Q_1$, $Q_2$ such that $P= t Q_1 + (1-t) Q_2$,\r\n$t>0$.\r\n\\\\\r\n\\\\\r\n{\\bf Krien Millman Theorem:}  \r\nIf $S$ is a closed, bounded convex set, then $S$ is the convex closure\r\nof its extreme points.\r\n\\\\\r\n\\\\\r\n{\\bf Principal Axis Theorem:}\r\nAny real quadratic form is equivalent to one with $Q(\\eta)= \\lambda_1{x_1}^2 +\r\n\\ldots + \\lambda_n {x_n}^2$ with\r\n$\\lambda_1 \\geq \\lambda_2 \\geq \\ldots \\geq \\lambda_n$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nFind eigenvector $v$, $V= \\langle v \\rangle \\oplus \\langle v \\rangle^{\\perp}$.\r\n\\end{quote}\r\n{\\bf SVD:} $A= U \\Sigma V^T$, $\\Sigma$ diagonal and $U U^T=V V^T = 1$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nAn $n \\times n$ matrix is \\emph{diagonalizable} iff it has $n$ linearly independent\r\neigenvectors.  A matrix is diagonalizable iff its minimal polynomial is a \r\nproduct of different linear factors.\r\nTwo matrices are simultaneously diagonalizable iff\r\nthey are diagonalizable and commute.\r\n\\begin{quote}\r\n\\emph{Proof:} The first and second statements are easy.  The third statement is\r\nproved by induction on $n$.  It is clear for $n=1$.  Let \r\n$ \\lambda_1, \\lambda_2, \\ldots, \\lambda_k$ be the characteristic values\r\nof $T$ and $W_i$ be the null space of $T-\\lambda_i$.  Each $W_i$ is an invariant space\r\nand the $T_{|W_i}$ is diagonalizeable.  Since $dim(W_i)<dim(V)$ the commuting operators\r\nrestricted to these spaces can be simultaneously diagonalized.  Composing the diagonal\r\nbases of the restricted transformations yields a basis in which all the matricies are\r\ndiagonal.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $f: A \\rightarrow A'$ be surjective.  $A$, $A'$ abelian, $A'$ free.\r\n$\\exists C \\subseteq A$ such that $A= ker(f) \\oplus C$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\langle x_i' \\rangle$ be a basis of $A'$ and for each $i \\in I$, let $x_i \\in A$\r\nbe such that $f(x_i )= x_i'$.  Put $C= \\langle x_i \\rangle$ and $B=ker(f)$.  If we have\r\n$\\sum_{i \\in I} n_i x_i = 0$, applying $f$ yields\r\n$\\sum_{i \\in I} n_i x_i' = 0$ and $\\langle x_i \\rangle$ is a basis.\r\nSimilarly, if $z \\in C$ and $f(z)= 0$ then $z= 0$.  Hence $B \\cap C =0$.\r\nLet $x \\in A$.   Since $f(x) \\in A'$, $\\exists n_i, i \\in I:\r\nf(x)= \\sum_{i \\in I} n_i x_i'$.  Applying $f$ to $x - \\sum_{i \\in I} n_i x_i = b \\in B$.\r\n$x \\in B + C$ and so $A= B \\oplus C$.\r\n\\end{quote}\r\n{\\bf Submodules of free modules over PIDs:}  \r\nLet $D^{(n)}$ be a free $D$-module, $D$, a PID, with basis $X= [e_1 , e_2 , \\ldots , e_n]^T$.  \r\nIf $P$ is invertible, $Y= [e'_1, \\ldots , e'_n]^T= P X$ is another basis for $D^{(n)}$.\r\nLet $K$ be a submodule generated by\r\n$U=[u_1, \\ldots , u_m]^T = A X$.  $A$ is called a relations matrix.\r\nSuppose $Q$ is invertible so that\r\n$V= QU$ is another set of generators for $K$.\r\n$V= QU = QAX= QAP^{-1}Y$.  $B=QAP^{-1}$ is the new relations matrix for the basis $Y$.\r\n$A$ and $B$ are called \\emph{equivalent}.\r\nIn the foregoing, $M$ is finitely generated and we note that the map\r\n$f: e_i \\mapsto u_i$ extends to a homomorphism\r\nand $M \\cong D^{(n)} / K$ where $K= ker(f)$.  $K$ is\r\na submodule of $D^{(n)}$ and by a previous result, is free with a base of size $m \\le n$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If $A$ is an $m \\times n$ matrix with entries from a PID,\r\n$D$, then $A$ is equivalent to a matrix of the form\r\n$diag(d_1, d_2, \\ldots, d_r, 0, 0, \\ldots, 0)$ with $d_i \\ne 0$ and $d_i \\mid d_{i+1}$.\r\nThe proof simply requires applying elementary row and column operations to \r\n$A$ as is done below.\r\nThere, let $O_{ij}= (\\delta_{il} \\delta_{jk})_{1 \\leq l \\leq n, 1 \\leq k \\leq n}$\r\nand $E_{ij}(\\alpha)= I+ \\alpha O_{ij}$.\r\n$E_{ij} (\\alpha) A$ acts on $A$ by adding $\\alpha$ times row $j$ to row  $i$.\r\n$A E_{ij} (\\alpha) A$ acts on $A$ by adding $\\alpha$ times column $i$ to column $j$.\r\n\\\\\r\n\\\\\r\n\\emph{Example:} Suppose $D= {\\mathbb Z}$ and $F= {\\mathbb Z}^{(3)}$ \r\nis a free abelian group with basis $x_1, x_2, x_3$ and\r\n$K$ is the submodule generated by\r\n$u_1= 2 x_1 + 2x_2 + 8 x_3$ and $u_2= -2 x_1 + 2 x_2 + 4 x_3$ and\r\n$F/K= \r\n\\langle x_1 , x_2, x_3  | 2 x_1 + 2x_2 + 8 x_3 = 0$, $-2 x_1 + 2 x_2 + 4 x_3 = 0 \\rangle$.\r\nWe have $ \\left(\r\n\\begin{array}{ccc}\r\n2 & 2 & 8\\\\\r\n-2 & 2 & 4\\\\\r\n\\end{array}\r\n\\right) \r\n\\rightarrow\r\n\\left(\r\n\\begin{array}{ccc}\r\n2 & 0 & 0\\\\\r\n0 & 4 & 0\\\\\r\n\\end{array}\r\n\\right)$ \r\nand $F/K = {\\mathbb Z}_2 \\oplus {\\mathbb Z}_4 \\oplus {\\mathbb Z}$.\r\n\\\\\r\n\\\\\r\n{\\bf Structure theorem for finitely generated modules over principal ideal domains:} \r\nIf $M \\ne 0$ is a finitely generated module over a PID, $D$. Then $M= Dz_{1} \\oplus\r\nDz_{2} \\oplus \\ldots \\oplus Dz_{s}$ with\r\n$ann(z_{1}) \\supseteq ann(z_{2}) \\supseteq \\ldots \\supseteq ann(z_{s})$, \r\n$z_{k} \\ne 0$.  Note $D z_i \\cong D/ann(z_i)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nFirst, $Dx \\cong D/ann(x)$, always.\r\nLet the base of $D^{(n)}$ be $e_{1}, e_{2}, \\ldots , e_{n}$ and let\r\n$\\eta: D^{(n)} \\rightarrow M$ be the canonical map\r\n$\\sum_i a_i e_i \\mapsto \\sum_i a_i x_i$ where $\\langle x_i \\rangle$ are generators\r\nfor $M$.  $M \\cong D^{(n)}/K$. $K= ker(\\eta)$ is generated by \r\n$f_{i}= \\sum_j a_{ij} e_{j}, i= 1, 2, \\ldots , n$.  \r\nThe Smith reduced canonical relations matrix is\r\n$QAP^{-1}= diag(d_{1}, d_{2}, ..., d_{r}, 0, \\ldots, 0 )$ and $d_{i} \\mid d_{i+1}$,\r\n$P=(p_{ij}), Q= (q_{ij})$.\r\nSo $f'_{i}= d_{i} e'_{i}$ where $e_i'= \\sum_j p_{ij} e_j$ and \r\n$f_i'= \\sum_j q_{ij} f_j$. \r\n$y_i= \\sum_j p_{ij} x_j$ is another set of generators for $M$ (i.e.,\r\n$M= \\sum D y_i$).  If $\\sum_i b_i y_{i}=0$ then $\\sum_i b_i e_i' \\in K$ so\r\n$\\sum_i b_i e_i' = \\sum_i c_i f_i'= \\sum_i c_i d_i e_i'$ and so $b_i = c_i d_i$ and \r\n$b_i y_i=0, \\forall i$, since each $d_i y_i= 0$, already.\r\n$ann(y_{i})= (d_{i})$ by construction.  If $d_{i}$ is a unit, $d_i y_i= 0 \\rightarrow y_i= 0$ \r\nand we can drop $y_i$ from the list of generators.  Thus if the first $t$ $d_i$ are units,\r\nputting $z_{1}= y_{t+1} , \\ldots, z_{s}= y_{n}$, $s= n-t$, we get the desired result.\r\n\\end{quote}\r\n{\\bf Notation:}  Let $T$ be and endomorphism of the $D$-module, $M$ $\\alpha \\in M$.\r\n$Z(\\alpha, T)$ is the cyclic subspace generated by $T$.  The $T$-annihilator\r\nof $\\alpha$ is $(p(x))$ since $D$ is a PID where\r\n$p(x)= x^k + c_{k-1} x^{k-1} + \\ldots + c_0$.  \r\nThe companion matrix (matrices operating on the left) is $C_T=\r\n\\left(\r\n\\begin{array}{cccccc}\r\n0 & 1 & 0 & \\ldots & 0 & 0\\\\\r\n0 & 0 & 1 & \\ldots & 0 & 0\\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n0 & 0 & 0 & \\ldots & 0 & 1\\\\\r\n-c_0 & -c_1 & -c_2 & \\ldots & -c_{k-2} & -c_{k-1}\\\\\r\n\\end{array}\r\n\\right)$.\r\nFor a vector space of $V$ over $F$, $T: V \\rightarrow V$,\r\nthe \\emph{rational decomposition}\r\nis $V= Z(\\alpha_1, T) \\oplus \\ldots \\oplus Z(\\alpha_r, T)$.  Again, the PID is $D= F[x]$.\r\n\\\\\r\n\\\\\r\n{\\bf Application to a linear transformation:} Suppose \r\n$e_1, \\ldots, e_n$ is a basis for $V$ over $F$ and put $D= F[\\lambda]$.  Let \r\n$T(e_i) = \\sum_j a_{ij} e_j$.  For $g(\\lambda) \\in D$, $g(T)$ acts on vectors in the\r\nusual way.  As above, $M \\cong {D^{(n)}}/{K}$ and $K$ has a free base over $D$\r\nwith $m \\le n$ elements.\\\\\r\n\\\\\r\n\\emph{Lemma:} $f_i = \\lambda e_i - \\sum_j a_{ij}e_j$ is a base for $K$ over $D$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSince $Te_i= \\sum_j a_{ij} e_j$,\r\n$\\lambda e_i= f_i+ \\sum_j a_{ij} e_j$, and we can write any $g_i(\\lambda) e_i$ as\r\n$\\sum_i g_i( \\lambda ) e_i = \\sum_i h_i( \\lambda )f_i + \\sum b_i e_i$, $b_i \\in F$.\r\nIf this is in $K$, then $\\sum_i b_i e_i \\in K$ so $\\sum_i b_i e_i = 0$.\r\nSince the $e_i$ form a base for $V$ over $F$, $b_i= 0, \\forall i$ and the element\r\n$K$ has the form $\\sum_i h_i( \\lambda) f_i = 0$.  Suppose there is a non trivial relation\r\nbetween the $h_i( \\lambda )$, then\r\n$\\sum_{i=1}^n h_i( \\lambda) \\lambda e_i = \\sum_{i,j=1}^n h_i( \\lambda) a_{ij} \\lambda e_i$\r\nand since the $e_i$ is a base,\r\n$h_i( \\lambda) \\lambda = \\sum_{j=1}^n h_j( \\lambda) a_{ji}$.\r\nIf any $h_i( \\lambda ) \\ne 0$ let $h_r( \\lambda )$ be one of maximal degree.\r\nClearly,\r\n$h_r( \\lambda ) \\lambda = \\sum_j h_j( \\lambda ) a_{jr}$ is impossible.  This proves\r\nevery $h_i( \\lambda) = 0$ \r\nand so the $f_i$ form a base for $K$.\r\n\\end{quote}\r\nAfter diagonalization,\r\n$Q (\\lambda I -A) P = diag(1,\\ldots,1,d_1(\\lambda), \\ldots , d_s(\\lambda))$.\r\nAs in the proof of the structure theorem,\r\n$K$ is generated by $f'_i= d_i e'_i$.  If\r\n$P^{-1}= (p^*_{ij})$, $v_i= \\sum_j p^*_{ij} u_j$, $z_i= v_{n-s+i}$ and\r\n$V= D z_1 \\oplus \\ldots \\oplus D z_s$.\r\n\\\\\r\n\\\\\r\n\\emph{Example:}\r\nSuppose\r\n$T u_1= -u_1 - 2 u_2 + 6 u_3$,\r\n$T u_2= -u_1 + 3 u_3$,\r\n$T u_3= -u_1 - u_2 + 4 u_3$.  The matrix for $T$ in the basis\r\n$\\langle u_1 , u_2 , u_3 \\rangle$ is $A$.\r\n$$\r\nA=\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 &  -2 &  6 \\\\\r\n-1 &  0 &  3 \\\\\r\n-1 &  -1 &  4\r\n\\end{array}\r\n\\right),\r\nQ=\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 1 & 0\\\\\r\n0 & -1 & 1\\\\\r\n1 &  2-\\lambda & -3\r\n\\end{array}\r\n\\right),\r\nP=\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 3 & \\lambda-3\\\\\r\n0 & 0 & -1\\\\\r\n0 & 1 &  -1\r\n\\end{array}\r\n\\right)\r\n$$\r\n$$\r\nQ(\\lambda I - A) P =\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & (\\lambda -1) & 0\\\\\r\n0 & 0 & (\\lambda -1)^2\r\n\\end{array}\r\n\\right),\r\nP^{-1}=\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & \\lambda & -3\\\\\r\n0 & -1 & 1\\\\\r\n0 & -1 & 0\r\n\\end{array}\r\n\\right)\r\n$$\r\n$v_1=u_1+\\lambda u_2 - 3 u_3$, $v_2= -u_2 + u_3$, $v_3= -u_2$.\r\n$z_1=v_2=-u_2 + u_3$, $z_2=v_3= -u_2$, $z_3=\\lambda v_3= u_1-3u_3$. So,\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n1 \\\\\r\n0 \\\\\r\n0 \r\n\\end{array}\r\n\\right)_{z}=\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n-1 \\\\\r\n1\r\n\\end{array}\r\n\\right)_{u}\r\n$,\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n1 \\\\\r\n0 \r\n\\end{array}\r\n\\right)_{z}=\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n-1 \\\\\r\n0\r\n\\end{array}\r\n\\right)_{u}\r\n$,\r\n$\r\n\\left(\r\n\\begin{array}{c}\r\n0 \\\\\r\n0 \\\\\r\n1 \r\n\\end{array}\r\n\\right)_{z}=\r\n\\left(\r\n\\begin{array}{c}\r\n1 \\\\\r\n0 \\\\\r\n-3\r\n\\end{array}\r\n\\right)_{u}\r\n$.  Thus the transition matrix between the $u$ base and the $z$ base is\r\n$\r\nR=\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & -1 & 1\\\\\r\n0 & -1 & 0\\\\\r\n1 & 0 & -3\r\n\\end{array}\r\n\\right)\r\n$\r\nand\r\n$\r\nR^{-1}=\r\n\\left(\r\n\\begin{array}{ccc}\r\n3 & -3 & 1\\\\\r\n0 & -1 & 0\\\\\r\n1 & -1 & 0\r\n\\end{array}\r\n\\right)\r\n$.  $R A R^{-1}= \r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & 0 & 1\\\\\r\n0 & -1 & 2\r\n\\end{array}\r\n\\right)\r\n$, as we can verify directly by\r\n$$\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & -1 & 1\\\\\r\n0 & -1 & 0\\\\\r\n1 & 0 & -3\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 &  -2 &  6 \\\\\r\n-1 &  0 &  3 \\\\\r\n-1 &  -1 &  4\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & -1 & 1\\\\\r\n0 & -1 & 0\\\\\r\n1 & 0 & -3\r\n\\end{array}\r\n\\right)^{-1} =\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & 0 & 1\\\\\r\n0 & -1 & 2\r\n\\end{array}\r\n\\right).\r\n$$\r\nNote in the example above, the matricies are applied ``from the right.''  Conventionally,\r\nmatricies are applied from the left.  We can take tranposes of all the matricies \r\nin the above example to convert\r\nthe example to one where the matricies are applied conventionally.\r\nHere is an analysis using the conventional notation:\\\\\r\nLet $A$ be a matrix and $\\langle e_1 , e_2 , \\ldots, e_n \\rangle$ the underlying basis so that\r\n$Ae_1= (a_{11}, a_{21}, \\ldots a_{n1})^T$.  Put $B(\\lambda) = (\\lambda I - A)$ and let $f_1, f_2,\r\n\\ldots, f_n$ be the columns of $B(\\lambda)$. Suppose $D$ is a PID and\r\n$\\langle x_1 , x_2, \\ldots , x_n \\rangle$ be generators of the module, $M$ over $D$.\r\nLet $\\eta: D^{(n)} \\rightarrow M$ be defined by $\\eta(c_1 , c_2, \\ldots , c_n) =\r\nc_1 x_1 + c_2 x_2 + \\ldots + c_n x_n$.  $D^{(n)}/K = M$ where $K$ is is generated by the\r\ncolumns of $B(\\lambda)$, namely, $f_1, f_2, \\ldots, f_n$. Put $B(\\lambda)$ in Smith normal\r\nform, $PB(\\lambda)Q = diag(1,1,\\ldots,1, d_1(\\lambda), \\ldots , d_s(\\lambda))$. \r\n$M = D/(d_1(\\lambda)) \\oplus \\ldots \\oplus D/(d_s(\\lambda))$ and $d_1(\\lambda) \\mid d_2(\\lambda) \\mid\r\n\\ldots \\mid d_s(\\lambda)$.  Put $P= (p_{ij})$, $Q= (q_{ij})$ and $P^{-1} = ({p_{ij}}^*)$.  Then\r\n${e_i}' = \\sum_{k} {p}_{ki} e_k$,\r\n${f_i}' = \\sum_{k} {q}_{ki} f_k$.\r\n$e_i = \\sum_{k} {p_{ki}}^* {e_k}'$.\r\n${f_i}' = \\sum_{k,l,m} q_{li} b_{kl} {p_{mk}}^* {e_m}'$.  $ann({f_i}')= (d_i(\\lambda))$.\r\n$Q$ is invertible so $\\langle {f_1}', {f_2}', \\ldots , {f_m}' \\rangle$ also generates $K$.\r\nIf $y_i = \\sum_j p_{ji} x_j$, $\\langle y_i \\rangle$ also generates $M$ and $D y_i = D/(d_i(\\lambda))$.\r\nWhen computing the rational canonical form (RCF), $v_i = \\sum_{k} {p_{ki}}^* e_k$ and $z_i = v_{n-s+i}$.\r\nThe remaining $z_i$ required to from the basis of the RCF by applying $A$ to the existing $z_i$, as above.\r\nThis gives $z_i = \\sum_k s_{ki} e_k$.  $S$ is the transition matrix relating the original basis to the\r\nbasis in which $A$ has standard RCF. $A_{RCF}= S^{-1} A S$.  When the matricies are applied ``from the right,''\r\nthe companion matrix, for the block having minimal polynomial $f(x) = x^n + c_{n-1} x^{n-1} + \\ldots + c_0$, has the form:\r\n$$\r\n\\left(\r\n\\begin{array}{ccccc}\r\n0 & 0 & 0 & \\ldots & -c_{n-1}\\\\\r\n1 & 0 & 0 & \\ldots & -c_{n-2}\\\\\r\n\\ldots & \\ldots &  \\ldots & \\ldots & \\ldots\\\\\r\n0 & 0 & \\ldots & 1 & -c_{0}\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nHere are two ways to do the computation with the current example:\r\n$A = \r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 & -1 & -1 \\\\\r\n-2 & 0 & -1 \\\\\r\n6 & 3 & 4 \\\\\r\n\\end{array}\r\n\\right)$,\r\n$B(\\lambda) =  (\\lambda I -A) =\r\n\\left(\r\n\\begin{array}{ccc}\r\n \\lambda + 1 & 1  & 1 \\\\\r\n 1 &  \\lambda & -1 \\\\\r\n -6 &  -3 &  \\lambda - 4\\\\\r\n\\end{array}\r\n\\right)\r\n$.\r\n$P B(\\lambda) Q =\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0 \\\\\r\n0 & (\\lambda - 1) & 0 \\\\\r\n0 & 0 & (\\lambda - 1)^2 \\\\\r\n\\end{array}\r\n\\right)\r\n$, where $P$ is the product of the elementary row operations:\r\n$[R_3 \\leftarrow R_3 + R_2] [R_3 \\leftarrow R_3 - (\\lambda - 4) R_1] [R_2 \\leftarrow R_1 - R_1]$.\r\nOne way to compute $R$, the matrix with $R^{-1}AR= \r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & 0 & -1 \\\\\r\n0 & 1 & 2\\\\\r\n\\end{array}\r\n\\right)\r\n$, is to compute the revised basis using the rules: (1) $R_i \\leftarrow R_i + \\alpha R_j$ causes a basis change of\r\n$e_j = e_j - e_i$ and $R_i \\leftrightarrow R_j$ causes a basis change of $e_j \\leftrightarrow e_i$.  This results\r\nin $(0, e_2 - e_1, e_3)$, the first entry should be zero and an additional entry can be computed by applying $A$ to\r\n$e_3$ giving $R=\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 0 & -1 \\\\\r\n1 & 0 & -1\\\\\r\n-1 & 1 & 4\\\\\r\n\\end{array}\r\n\\right)\r\n$.  We can calculate $R^{-1} =\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 & 1 & 0 \\\\\r\n3 & 1 & 1\\\\\r\n-1 & 0 & 0 \\\\\r\n\\end{array}\r\n\\right)\r\n$. We get\r\n$$\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & 0 & -1 \\\\\r\n0 & 1 & 2\\\\\r\n\\end{array} \r\n\\right) =\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 & 1 & 0 \\\\\r\n3 & 1 & 1\\\\\r\n-1 & 0 & 0 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 & -1 & -1 \\\\\r\n-2 & 0 & -1 \\\\\r\n6 & 3 & 4 \\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 0 & -1 \\\\\r\n1 & 0 & -1\\\\\r\n-1 & 1 & 4\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nAnother way, to get $R$, is to compute $P$ from the elementary row operations, so\r\n$P = \r\n\\left(\r\n\\begin{array}{ccc}\r\n1 &  0 & 0\\\\\r\n-1 &  1 & 0\\\\\r\n(3 -\\lambda) & 1  & 1 \\\\\r\n\\end{array}\r\n\\right)\r\n$ and compute\r\n$P^{-1} = \r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n1 & 1 & 0\\\\\r\n\\lambda - 4 & -1 & 1\\\\\r\n\\end{array}\r\n\\right)\r\n$.   This lets us read off, from $P^{-1}$,\r\n$R = \r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 0 & -1 \\\\\r\n1 & 0 & -1\\\\\r\n-1 & 1 & 4\\\\\r\n\\end{array}\r\n\\right)\r\n$.  Again, the last column is computed as $Ae_3$ and again, we compute $R^{-1}$.\r\n\\\\\r\n\\\\\r\n{\\bf Observation:}\r\nThe \\emph{Rational Canonical Form} and \\emph{Jordan Canonical Form} are the same\r\nover an algebraically closed field.\r\n\\\\\r\n\\\\\r\n{\\bf Grove's treatment:}  $R$, a pid. $f \\in Hom_R(M,N)$, $M$ free of dimension $n$, $N$, free of dimension $m$. \r\n$M = \\langle x_1, x_2, \\ldots, x_n \\rangle$,\r\n$N = \\langle y_1, y_2, \\ldots, y_m \\rangle$.\r\n$f(x_i) = \\sum_{j=1}^m a_{ji} y_j$.\r\n$A= (a_{ij})$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $R, M, N, f$ as above.  Put $E= Im(f)$.  Suppose that over the basis for $M$ and $N$, $f$ is represented as a matrix by:\r\n$$\r\n\\left(\r\n\\begin{array}{ccc}\r\nU & 0 & 0 \\\\\r\n0 & D & 0 \\\\\r\n0 & 0 & 0 \\\\\r\n\\end{array}\r\n\\right) \r\n$$\r\nwhere\r\n$U$ and $D$ are diagonal matricies \r\n$U = diag(u_1 , u_2 , \\ldots , u_x \\rangle$ with $u_i$ a unit and\r\n$D = diag(d_1 , d_2 , \\ldots , d_k \\rangle$ with $d_i \\in R$ and $d_j \\mid d_{j+1}$.  Then $N/E$ is a direct sum of cyclic modules over\r\n$R$, $N/E = \\bigoplus_{i=s+1}^m R \\langle y_i + E \\rangle$, with invariant factors $d_1, d_2, \\ldots, d_s$.  $N/E$ has rank $m-s-k$ and\r\n$dim(E)=s+k$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$f(x_i)= u_i y_i, 1 \\leq u \\leq s$,\r\n$f(x_i)= d_i y_i, s+1 \\leq u \\leq s + k$,\r\n$f(x_i)= 0, i \\geq s+k+1$.  Put $W_i = R \\langle y_i + E \\rangle$, $s+1 \\leq i \\leq m$.  $N/E = \\sum_i W_i$ and $W_i \\cap \\sum_{i \\ne j} W_j = 0$ so\r\nthe sum is direct.  Each $y_i + E$ has order $d_{i-s}$.\r\n\\end{quote}\r\n{\\bf Application to linear equations:} Consider the linear equations $\\sum_{j=1}^n a_{i,j} x_j =c_i$, $i= 1, 2, \\ldots, m$.  Write this as\r\n$AX=C$.  Suppose  we have $P, Q$ so that $PAQ= diag(r_1, \\ldots, r_k, 0, \\ldots 0)$.  Put $X= QY$.  $AX= AQY=C$ and $PAQY=PC$. This gives\r\nthe solutions in terms of $Y$,  Now transform back to $X$.\\\\\r\n\\emph{Example:}\r\n$$\r\nA=\r\n\\left(\r\n\\begin{array}{ccc}\r\n-33 & 42 & -20 \\\\\r\n21 & -27 & 13\\\\\r\n\\end{array}\r\n\\right) , \\;\r\nC=\r\n\\left(\r\n\\begin{array}{c}\r\n-26\\\\\r\n16\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nWe find $P, Q$ as:\r\n$$\r\nP=\r\n\\left(\r\n\\begin{array}{cc}\r\n2 & 3 \\\\\r\n1 & 2 \\\\\r\n\\end{array}\r\n\\right) , \\;\r\nQ=\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 1 & 2\\\\\r\n1 & 2& 3\\\\\r\n2 & 3& 3\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nwhich gives\r\n$$\r\nPAQ=\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n0 & 3 & 0\\\\\r\n\\end{array}\r\n\\right),\\;\r\nPC = \r\n\\left(\r\n\\begin{array}{c}\r\n-4\\\\\r\n6\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nSo $y_1 = -4,3 y_2=6, y_3=a$, and finally,\r\n$$\r\n\\left(\r\n\\begin{array}{c}\r\nx_1\\\\\r\nx_2\\\\\r\nx_4\\\\\r\n\\end{array}\r\n\\right)\r\n=\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 1 & 2\\\\\r\n1 & 2& 3\\\\\r\n2 & 3& 3\\\\\r\n\\end{array}\r\n\\right)\r\n\\left(\r\n\\begin{array}{c}\r\n-4\\\\\r\n2\\\\\r\na\\\\\r\n\\end{array}\r\n\\right) =\r\n\\left(\r\n\\begin{array}{c}\r\n2\\\\\r\n0\\\\\r\n-2\\\\\r\n\\end{array}\r\n\\right) + a\r\n\\left(\r\n\\begin{array}{c}\r\n2\\\\\r\n3\\\\\r\n3\\\\\r\n\\end{array}\r\n\\right)\r\n$$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $R=F[x]$.  Let $E$ be the module generated by columns of $A-xI$.  $V_T \\cong N/E$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nDefine $\\psi: N \\rightarrow V_T$ by $\\psi(e_i)=v_i$.  \r\nWe show $ker(\\psi)=E$. \r\nLet $z_i = \\sum_{j=1}^n a_{ji}e_j =xe_i$ then $E= \\langle z_i \\rangle$.\r\n$\\psi(z_i) = \\sum_{j=1}^n a_{j,i}v_j - T(v_i)= 0$ so $E \\subseteq ker(\\psi)$.\r\nLet $W = \\langle e_i + E \\rangle$, $1 \\leq i \\leq n$.  $x e_i + xE \\in W$ so $W$ is a submodule of $N/E$.\r\nSince $N= R \\langle e_1 , e_2 , \\ldots , e_n \\rangle$, $W= N/E$.  If $u \\in N$, $u = \\sum_i c_i e_i + z$, $c_i \\in F, x \\in E$.\r\n$\\psi(u)=  \\sum_i c_i \\psi(e_i) + \\psi(z) = \\sum_i c_i v_i$ and so $u \\in ker(\\psi)$ iff $c_i =0$ so $u \\in E$.\r\n\\end{quote}\r\n{\\bf Example:} $F = \\mathbb{Q}$ and $T$ is represented over the standard basis as\r\n$$\r\nA =\r\n\\left(\r\n\\begin{array}{ccc}\r\n5 & -8 & 4\\\\\r\n6 & -11& 6\\\\\r\n6 & -12& 7\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nthen\r\n$$\r\nP =\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n-{\\frac 3 2} & 1 & 0\\\\\r\n{\\frac {x+5} 4} & -2& 1\\\\\r\n\\end{array}\r\n\\right),\\;\r\nQ =\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 0 & 1\\\\\r\n0 & 1& {\\frac 3 2}\\\\\r\n1 & 2& {\\frac {x+7} 4}\\\\\r\n\\end{array}\r\n\\right),\\;\r\nP(A-xI)Q =\r\n\\left(\r\n\\begin{array}{ccc}\r\n4 & 0 & 0\\\\\r\n0 & (1-x) & 6\\\\\r\n0 & 0& {\\frac {1-x^2} 4} \\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nNow compute $P^{-1}$, columns not containing $x$ and their images under $A$ will be the basis for the matrix in rational canonical form.\r\n$$\r\nP^{-1} =\r\n\\left(\r\n\\begin{array}{ccc}\r\n1 & 0 & 0\\\\\r\n{\\frac 3 2} & 1 & 0\\\\\r\n{\\frac {7-x} 4}  & 2& 1\\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\nIn this example, $V_t \\cong R w_1 \\oplus Rw_2 \\oplus Rw_3$ with $w_1= e_3$, $w_2=Tw_1 = (4,6,7)^T$,\r\n$w_3 = e_2+2 e_3$ and so the basis change matrix is\r\n$$\r\nL =\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 4 & 0\\\\\r\n0 & 6 & 1\\\\\r\n1  & 7 & 2\\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\n$$\r\nL^{-1}AL =\r\n\\left(\r\n\\begin{array}{ccc}\r\n0 & 1 & 0\\\\\r\n1 & 0 & 0\\\\\r\n0  & 0 & 1\\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\nSince $m_T(x)$ has linear factors, the Jordan canonical form is diagonal and\r\n$$\r\nJ =\r\n\\left(\r\n\\begin{array}{ccc}\r\n-1 & 0 & 0\\\\\r\n0 & 1 & 0\\\\\r\n0  & 0 & 1\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\n{\\bf One more example:} $F = \\mathbb{Q}$ and $T$ is represented over the standard basis as\r\n$$\r\nA =\r\n\\left(\r\n\\begin{array}{cc}\r\n\\lambda_1 & 0\\\\\r\n0 & \\lambda_2 \\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\n$m_T(X)= x^2 -(\\lambda_1 + \\lambda_2) x + \\lambda_1 \\lambda_2$ is the minimal polynomial.  Further,\r\n$$\r\nA-xI = \r\n\\left(\r\n\\begin{array}{cc}\r\n\\lambda_1  - x& 0\\\\\r\n0 & \\lambda_2 - x\\\\\r\n\\end{array}\r\n\\right), \\;\r\nP(A-xI)Q = \r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 0\\\\\r\n0 & (x - \\lambda_1) (x - \\lambda_2)\\\\\r\n\\end{array}\r\n\\right),\r\n$$\r\nwith\r\n$$\r\nP =\r\n{\\frac 1 {\\lambda_1 - \\lambda_2}}\r\n\\left(\r\n\\begin{array}{cc}\r\n- \\lambda_2 & \\lambda_1\\\\\r\n1 & -1\\\\\r\n\\end{array}\r\n\\right), \\;\r\nP^{-1}=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & \\lambda_1\\\\\r\n1 & \\lambda_2\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nSo the basis for the RCF is $\\langle (1,1)^T, (\\lambda_1, \\lambda_2)^T \\rangle$.\r\nTo switch basis, $v_{[e]}= L v_{[f]}$.  The matrix, $L$, is then\r\n$$\r\nL=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & \\lambda_1\\\\\r\n1 & \\lambda_2\\\\\r\n\\end{array}\r\n\\right), \\;\r\nL^{-1} =\r\n{\\frac 1 {\\lambda_1 - \\lambda_2}}\r\n\\left(\r\n\\begin{array}{cc}\r\n- \\lambda_2 & \\lambda_1\\\\\r\n1 & -1\\\\\r\n\\end{array}\r\n\\right).\r\n$$\r\nWe see that\r\n$$\r\nL^{-1} A L =\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -\\lambda_1 \\lambda_2\\\\\r\n1 & \\lambda_1 +\\lambda_2\\\\\r\n\\end{array}\r\n\\right)\r\n$$ which is the RCF.\r\n\\\\\r\n\\\\\r\n{\\bf Principal Component Analysis:}\r\n$P_A= A(A^TA)^{-1} A^T$ where the rank of $A$ is the number of columns, is the symmetric\r\nprojector; $P_{A^{\\perp}}= I-P_A$. \r\n$P_A^2 = P_A$, $P_{A^{\\perp}}^2 = P_{A^{\\perp}}$,\r\n$P_A^T = P_A$, $P_{A^{\\perp}}^T = P_{A^{\\perp}}$.  $S=A A^T$ is invertible.\r\n$P_{\\vec a} ({\\vec w})$ is the projection of ${\\vec w}$ along ${\\vec a}$.  The\r\nlinear system $A {\\vec f} = P_A {\\vec b}$ has solution\r\n${\\vec f} = A^{-1} P_A {\\vec b}$ the least squares approximation of data points\r\n$(x_i,y_i)$ can be calculated from this too.  \\emph{Example:} Fit $f(x)= f_0 + x f_1$ to the\r\ndata $(-1,1), (0,0), (1,2)$ by solving\r\n$\\left(\r\n\\begin{array}{cc}\r\n1 & -1 \\\\\r\n1 & 0 \\\\\r\n1 & 1 \r\n\\end{array}\r\n\\right)\r\n(f_0, f_1)^T= (1,0,2)^T\r\n$.  In general, the least squares approximation arises from the symmetric \r\nprojection in the sample space ${\\mathbb R}^s$ where $s$ is the number of data points.\r\n$f(A) {\\vec v}= (f_0 + f_1 A + \\ldots + f_n A^n) {\\vec v}=\r\n( {\\vec v}, A{\\vec v}, \\ldots, A^n{\\vec v})$.  Vandermonde determinant and Fourier\r\n$V(x_0 , x_1 , \\ldots , x_n)$ where the $x_i$ are roots of $x^{n+1}-1=0$.\r\n$Z(x)= (x-x_j) Z_j (x)$ solves for coefficients $f_0 , f_1 , \\ldots , f_n$ using\r\nLagrange interpolants $\\Lambda_j(x) = {\\frac {Z_j(x)} {Z_j(x_j)}}$.  For PCA,\r\n$\\mu_A(x)= \r\n(x-\\lambda_1)^{m_1}\r\n(x-\\lambda_2)^{m_2}\r\n\\ldots\r\n(x-\\lambda_t)^{m_t}\r\n$.  There are polynomials in $A$, denoted $ A_{\\lambda_1} A_{\\lambda_2} \\ldots A_{\\lambda_t} $\r\nsuch that $(A-\\lambda_i I)^m A_{\\lambda_i} =0$ and\r\n$A= A_{\\lambda_1} A_{\\lambda_2} \\ldots A_{\\lambda_t}$.  The $A_{\\lambda_i}$ are called components.\r\nThe list of basic eigenvectors of $A$ form the columns of the diagonalizing matrix, $P$ and\r\n$AP=PD$; $A$ is diagonalizable when $P$ is invertible.\r\nApproximating a rank $r$ $n \\times n$ matrix requires $2nr$ terms.  \\emph{Mean clustering:}\r\nreplace $M$ with $D= diag(\\alpha_1, \\ldots, \\alpha_i)$ where\r\n$\\alpha_i= {\\sqrt {\\frac 1 {(M M^T)_{ii}}}}$.   How closely can a scatterplot be approximated\r\nby a line $A$ with direction ${\\vec a}$?  Find the vector ${\\vec a}$ that maximizes\r\n$\r\n|P_{\\vec a} ({\\vec {m_1}})|^2 +\r\n|P_{\\vec a} ({\\vec {m_2}})|^2 +\r\n|P_{\\vec a} ({\\vec {m_s}})|^2 =\r\n({\\vec a}^T {\\vec m_1})^2 + ({\\vec a}^T {\\vec m_2})^2 +\r\n\\ldots ({\\vec a}^T {\\vec m_t})^2$.  Maximize ${\\vec a}^T M M^T {\\vec a},\r\n\\forall {\\vec a} \\in {\\mathbb R}^s, |{\\vec a}|=1$.  $C=M M^T$ is a correlation matrix\r\nwith\r\n$c_{ij}$ is the correlation of $i, j$; if $u_i \\perp u_j$ they are uncorrelated.\r\n$\\exists P: CP=PD$, $M M^T=C= PDP^{-1}$ and maximize ${\\vec u}^T D {\\vec u}, |{\\vec u}|=1$,\r\n${\\vec u}= P^T {\\vec a} \\in {\\mathbb R}^s$.  $C$ is diagonalized by $P: P P^T=I$.\r\n\\subsection {Bilinear Forms and Classical Groups}\r\n{\\bf Definition:}\r\nA \\emph{pairing}, $(W,V) \\rightarrow k$ is a bilinear map.  If $V_0 \\subset V$, \r\n$V_0^* = \\{{\\vec w} \\in W: ({\\vec w}, {\\vec {v_0}})= 0, \\forall {\\vec {v_0}} \\in V_0 \\}$,\r\n$v_0 \\subset (V_0^*)^*$.  $V^*$ is called the left kernel. \r\nSame holds {\\it mutatis mutandis}\r\nfor $W_0 \\subseteq W$ provided $W^* = 0$ is the right kernel.\r\nIf $(W,V) \\rightarrow k$ is a pairing with left kernel $0$ and\r\n${\\vec {w}} \\in W$, define $\\varphi_{\\vec w} ({\\vec v}) = ({\\vec w}, {\\vec v})$.  \r\n$\\varphi_{\\vec w} \\in {\\hat V}$ and the map\r\n${\\vec w} \\mapsto \\varphi_{\\vec w}$ \r\nis an injection from $W \\rightarrow {\\hat {V}}$.\r\nSimilarly,\r\nif the right kernel is $0$, there is an injection $V \\rightarrow {\\hat W}$.\r\n\\\\\r\n\\\\\r\nIf $W_0 \\subseteq W$, $codim_W(W_0)= dim(W)-dim(W_0)$.\r\nIf $W_0 \\subset W$, $V_0 \\subset V$ and $V^*=0$,\r\nthere are natural injective morphisms\r\n$V/W_0^* \\rightarrow {\\hat {W_0}}$ and $V_0^* \\rightarrow {\\hat {V/V_0}}$. \r\nThus, $dim(V/W_0^*) \\le dim({\\hat {W_0}})=dim(W_0)$ and \r\n$dim(W_0^{**}) \\le codim(W_0^*) \\le dim(W_0)$.\r\nIf $W= {\\hat V}$, both kernels are $0$.\r\nIf $(W,V)$ is a pairing, (a) $dim(W/V^*) = dim(V/W^*)$, (b) if $V^* = 0$,\r\n$dim(W_0^{**}) = codim(W_0^*) = dim(W_0)$ and if $W_0$ is\r\nfinite dimensional, $W_0^{**}= W_0$ and $W_0$ and $V/W_0^*$ are\r\nnaturally dual, (c) If $V^*=0$ and $W^*=0$, and $V$ and $W$ are\r\nfinite dimensional, $V$ and $W$ are naturally dual and there is a 1-1,\r\ninclusion reversing correspondence of subgroups of\r\n$V$ and $W$ under the $*$ operator: $W_0 \\leftrightarrow W_0^*$.\r\n\\\\\r\n\\\\\r\nLet $A=(a_{ij})$ be an $m \\times n$ matrix with entries in $k$ and\r\n${\\vec x}= (x_1, \\ldots , x_n)^T$.  Let\r\n${\\vec b}=(b_1 , \\ldots , b_m)^T$ then $A {\\vec x}= {\\vec b}$ is a system\r\nof linear equations.  Set\r\n$x=E_1 x_1 + E_2 x_2 + \\ldots + E_n x_n, E_i \\in V= k^n$.  \r\nSuppose ${\\hat V}$ is dual to $V$ with basis\r\n$\\varphi_1 , \\ldots , \\varphi_n$: $\\varphi_j E_k= \\delta_{jk}$.  Let\r\n$\\psi_i (x) = (a_{i1} \\varphi_1 + \\ldots + a_{in} \\varphi_n) (E_1 x_1 + \\ldots + E_n x_n)=\r\na_{i1}x_1 + \\ldots + a_{in}x_n$.  $W \\subset {\\hat V}$, $W = \\langle \\psi_j(x) \\rangle$\r\nand $dim(W)=$ row rank. $S_m$ is the $m-$tuple column vectors\r\nwith entries in $k$.\r\nNote that if $A_i$ are column vectors \r\nforming $A$, they are in the column space of $A$ as is\r\n${\\vec b}$  and $A_1 x_1 + \\ldots + A_n x_n= {\\vec b}, \r\n{\\vec b}= (\\psi_1(x), \\ldots, \\psi_m (x))$.\r\nIf $f: V \\rightarrow S_m, f(x)= (\\psi_1x , \\ldots , \\psi_n x)$, \r\n$ker(f) = W^*$. If $Im(f)=U$, $U \\cong V/W^*$ and $dim(U)=codim(W^*)=dim(W)$.\r\nThis shows\r\nthe row rank equals the column rank.\r\n\\\\\r\n\\\\\r\nLet $B_{ij}(\\lambda) = I + \\lambda (\\delta_{il} \\delta_{jk})_{lk}$.  If\r\n$A \\in GL_n(k), A=BD(\\lambda)$ where $B \\in SL_n(k)$ and $D(\\lambda)$ is the same as\r\nthe identity except for $\\lambda$ in the lower rightmost position.\r\nPut $Z=Z(k), S= \\langle x^2, x \\in k \\rangle$ (as an additive group).  \r\nIf $x^2 \\in Z, \\forall x$  then\r\n$k$ is commutative; further, unless $k$ is commutative and $char(k)=2$, $S=k$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $\\tau \\in GL_n(k)$ is a \\emph{transvection} if \r\n$\\exists H= \\{h: \\varphi(h) =0, \\varphi \\in {\\hat V} \\}$ with $\\tau(h) =h, h \\in H$ and\r\n$\\tau(x)-x \\in H, \\forall x \\in V$.\r\nIf $\\tau$ is a transvection with hyperplane\r\n$H$, pick ${\\vec b}: \\varphi({\\vec b})= a \\ne 0$, set $\\tau(x) = x-{\\vec b} a^{-1} \\varphi(x)$\r\nthen $\\tau (t(x))=t(x)$, thus \r\n$\\tau(x)= x+ {\\vec a} \\varphi(x)$ with ${\\vec a}= \\tau({\\vec b} a^{-1})-{\\vec b} a^{-1}$.\r\nSo all transvections are of this form.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$B_{ij}(\\lambda)$ is a transvection.\r\nIf $ {\\vec a}, {\\vec b} \\in H$ then\r\n$\\tau_{\\vec a} (\\tau_{\\vec b}(x))= \\tau_{{\\vec a}+{\\vec b}} (x)$.  \r\nIf $\\sigma \\in GL_n(k)$ and $\\tau$ is a transvection, so is $\\tau' = \\sigma \\tau \\sigma^{-1}$\r\nand $\\tau'(x)= x+ (\\sigma(A)) \\varphi(\\sigma^{-1}(x))$; conversely, if\r\n$\\tau''(x)=x+{\\vec {a'}} \\psi(x)$ is another transvection with hyperplane $H'$,\r\nwe show $\\exists \\sigma$: $\\sigma(H)= H'$ and $\\sigma({\\vec a}) = a'$ and thus that\r\nall transvections are conjugate and hence have the same determinant.\r\n\\begin{quote}\r\n\\emph{Proof:} Pick ${\\vec b}, {\\vec {b'}}$ with $\\varphi({\\vec b})=\\psi({\\vec {b'}})=1$.\r\n$\\exists \\sigma: \\sigma({\\vec a})= {\\vec {a'}}, \\sigma(H)= H', \\sigma({\\vec b})= {\\vec {b'}}$.\r\nThen $\\tau''(x)=x + {\\vec {a'}} \\varphi(\\sigma^{-1}(x))$, \r\n$\\exists c: \\phi(x)=\\varphi(\\sigma^{-1}(x))$, setting $x= {\\vec {b'}}, \\sigma^{-1}(x)={\\vec b}$\r\nwe get $c=1$ and $\\tau''= \\tau'$. If $H$ has at least three vectors then \r\n$\\exists {\\vec a}, {\\vec b}, {\\vec c}$ with\r\n${\\vec c}= {\\vec a} + {\\vec b}$ and\r\n$\\tau_{\\vec a} (\\tau_{\\vec b}(x))= \\tau_{\\vec c} (x)$ and since they \r\nall have the same determinant, it must be 1.\r\nIn that case, $f:GL_n(k) \\rightarrow GL_n(k)/GL_n(k)'$, $f(\\sigma \\tau \\sigma^{-1})= f(\\tau)$\r\nso all transvections have the same image under $f$ and $\\tau \\in GL_n(k)'=SL_n(k)$.\r\nIf $n \\ge 3$ $H$ and $H'$ have independent vectors and we can choose $\\sigma: det(\\sigma)=1$\r\nso the transvections are conjugate in $SL_n(k)$.  Finally, the center of $SL_n(k)$\r\nconsists of the matrices $\\alpha I$ with $\\alpha^n=1$.  We can conclude:\r\nIf $G$ is a normal subgroup of $GL_n(k)$ containing a transvection and\r\n$n \\ge 3$ or $n=2$ and $|k| \\ge 4$ then $SL_n(k) \\subseteq G$ if $G>Z(GL_n(k))$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $v, w$ are linearly independent, there is a transvection, $T$: $Tv = w$.\r\n\\begin{quote}\r\n\\emph{Proof:} $W = \\{x: x \\cdot (v-w) = 0 \\}$, $x, y \\notin $. $T_{|W|} = 1$, $T(v)=w$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $W_1, W_2$ are hyperplanes in $V$, and $v \\in V \\setminus W_1 \\cup W_2$,\r\nthere is a transvection, $T$: $T(W_1)= W_2, T(v) = v$.\r\n\\begin{quote}\r\n\\emph{Proof:} $V = W_1 + W_2$.  $dim(W_1 \\cap W_2)= n-2$.  $\\exists x \\in W_1, y \\in W_2: v = x + y$.\r\n$V= W_1 \\cap W_2 + Fx + Fy$.  Define $T_{W_1 \\cap W_2 + F(x + y)} = 1$ and $T(x) = y$.\r\n\\end{quote}\r\n{\\bf Theorem:} All transvections are $GL(V)$ conjugate.\r\nIf $T_1, T_2$ are transvections on $V$, $n=dim(V) \\ge 3$ and $T_1$ and $T_2$ are\r\n$GL(V)$ conjugate then they are $SL(V)$ conjugate.  \r\n\\begin{quote}\r\n\\emph{Proof:} Transvections are all of the form $T = 1 + \\lambda B_{mn}$ with\r\n$B_{mn} = (\\delta_{mi} \\delta_{nj})$. $B_{lm}$ is conjugate to $B_{kn}$ via permutation\r\nmatricies.  Suppose, for example that $T= 1 + \\lambda_1 B_{mn} =\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & \\lambda_1 \\\\\r\n0 & 1\r\n\\end{array}\r\n\\right)$.\r\nPut $S = \\left(\r\n\\begin{array}{cc}\r\n{\\frac 1 {\\lambda_1}} & -1 \\\\\r\n0 & {\\frac 1 {\\lambda_2}}\r\n\\end{array}\r\n\\right)$, then \r\n$S^{-1} T S =\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & \\lambda_2 \\\\\r\n0 & 1\r\n\\end{array}\r\n\\right)$.  So all transvections are conjugate in $GL(V)$.  If $n \\geq 3$, we can pick a diagonal\r\nelement so that $det(S) = 1$ and preserve the conjugacy.\r\n\\end{quote}\r\n{\\bf Theorem:} If $dim(V) \\ge 3$, the transvections on $V$ generate $SL(V)$.  $SL(V)'=SL(V)$\r\nand $PSL(V)'=PSL(V)$.\r\n\\begin{quote}\r\n\\emph{Proof:} It suffices to show there is a (non-trivial) transvection in $SL(V)'$ since they are\r\nall conjugate.\r\nDefine $T_1(v_1) = v_1 - v_2, T_1(v_j) = v_j, j \\ne 1$ and\r\n$T_2(v_2) = v_2 - v_3, T_1(v_j) = v_j, j \\ne 2$. $T_1 T_2 T_1^{-1}T_2^{-1}$ is a transvection.\r\n\\end{quote}\r\n{\\bf Theorem:} $PSL(V)$ is $2$-transitive on $P_{n-1}(V)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $[v_1] \\ne [v_2], [w_1] \\ne [w_2] \\in P_{n-1}(V)$.\r\nWe can choose basis\r\n$\\langle v_1, v_2, v_3, \\ldots , v_n \\rangle$ and\r\n$\\langle w_1, w_2, v_3, \\ldots , v_n \\rangle$.  Define $T_b$ by\r\n$T_b(v_1) = b w_1$\r\n$T_b(v_2) = w_2$, and\r\n$T_b(v_i) = v_i, i \\geq 3$.  Finally, pick $b$: $det(T_b) = 1$.\r\n\\end{quote}\r\n{\\bf Pairings and isometries:}  Let $V \\times V \\rightarrow k$ be a pairing with trivial\r\nleft and right kernels.   $\\sigma$ is an \\emph{isometry} if \r\n$(x,y)=(\\sigma x, \\sigma y), \\forall x,y \\in V$.  $det(\\sigma)^2=1$ for all isometries;\r\nif $det(\\sigma)= 1$, $\\sigma$ is a rotation,\r\nif $det(\\sigma)= -1$, $\\sigma$ is a reflection.  A quadratic map, $Q$ satisfies\r\n$Q(ax)=a^2 Q(x)$ and $(x,y)= Q(x+y)-Q(x)-Q(y)=(y,x)$ is a pairing.  If $char(F) \\ne 2$,\r\n$Q(x)= {\\frac 1 2}  (x,x)$.  Pairings arising from quadratic maps are symmetric.\r\n${\\vec a} \\perp {\\vec b} \\leftrightarrow ({\\vec a}, {\\vec b})=0$.  \r\nIf $\\langle v_1 , v_2 , \\ldots , v_n \\rangle$ span $V$ and \r\n$({\\vec {v_i}}, {\\vec {v_j}})= g_{ij}$ and\r\nif $\\langle u_1 , u_2 , \\ldots , u_n \\rangle$ is another basis related to the original by\r\n$u_i = \\sum_j a_{ji} v_j$ then ${\\overline {g_{ij}}} =A^T G A$, where $G=(g_{ij})$.\r\nThe form is symmetric if $a_{ij}= a_{ji}$, antisymmetric if $a_{ij}= - a_{ji}$.\r\n\\\\\r\n\\\\\r\n{\\bf Isotropic spaces}\r\nLet $V^* = rad(V)= V \\cap V^{\\perp}$ and\r\n$V= rad(V) \\oplus U$, $U \\cong V/rad(V)$.\r\nSuppose $V$ is non-singular and $U \\subset V$ then $U^{**}=U, dim(U) + dim(U^*) = dim(V)$ and\r\n$rad(U) =rad(U^*)= U \\cap U^*$.  The subspace $U$ is non-singular iff $U^*$ is non-singular\r\nand then $V= U \\perp U^*$.  A vector ${\\vec v}$\r\nis isotropic if $({\\vec v}, {\\vec v})=0$.  \r\n$U$ is isotropic if $(u_1 , u_2)= 0, \\forall u_1, u_2 \\in U$.\r\nThere are two geometries for symmetric metric\r\nspaces: (1) \\emph{symplectic} if $({\\vec v}, {\\vec v}) = 0, \\forall {\\vec v} \\in V$ and\r\n$(x,y)= -(y,x)$; (2) \\emph{orthogonal} if $(x,y)=(y,x), \\forall x,y \\in V$.\r\nIf $V$ is orthogonal and every vector is \\emph{isotropic} then $V$ is isotropic.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\nSuppose $dim(V)=2$ and $V$ is non-singular but has an isotropic vector, ${\\vec n}$ then\r\n$\\exists {\\vec m}: {\\vec n}^2={\\vec m}^2=0, {\\vec n}{\\vec m}=1$, \r\n$V= \\langle {\\vec n}, {\\vec m} \\rangle$. (\r\n$V= \\langle {\\vec n} , {\\vec a} \\rangle$ for some \r\n${\\vec a}$. Set ${\\vec m}= x {\\vec n} + y{\\vec a}$; if\r\n${\\vec n} {\\vec a}=0$, $V$ is singular so we can find $y: y{\\vec n} {\\vec a} = 1$.  \r\nCan also\r\nfind $x: {\\vec m}^2=0$.)  $\\langle {\\vec n}, {\\vec m} \\rangle$ is a \r\n\\emph{hyperbolic plane}.\r\nA non-singular space, $V$, with orthogonal geometry is an orthogonal sum of lines.\r\nA non-singular space, $V$, with symplectic geometry is an orthogonal sum of \r\nhyperbolic planes.\r\n\\\\\r\n\\\\\r\n{\\bf Witt's Theorem:} Let $V$ and $W$ \r\nbe isometric via $\\rho$.  Let $\\sigma: V_0 \\rightarrow W_0$ be\r\nan isometry for $V_0 \\subset V$ and $W_0 \\subset W$, then $\\sigma$ can \r\nbe extended to an isometry of $V$. $O_n$: isometries.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\end{quote}\r\n{\\bf Definitions:} $O_n^+$: rotations,\r\n$O_n^-$: reflections.\r\n$\\Omega_n= O_n'$.\r\nIf $V$ is a vector space with over ${\\mathbb {R}}$ with a positive definite form \r\n(resp. ${\\mathbb {C}}$ with a \r\nhermitian form) and $W$ is a subspace of $V$ then $V=W \\oplus W^{\\perp}$.\r\n$V^* \\otimes V \\rightarrow {\\cal L}(V,V)$ via $L_{\\phi \\otimes v } (w)= \\phi(w)v$.\r\nIf $n$ is odd, $1_V = Z(O_n^+)$.  \r\nIf $n$ is even, $\\pm 1_V =Z(O_n^+)$. If $n=2$ over $F_q$, the plane contains\r\n$q+1$ lines: $\\langle A+xB \\rangle, \\langle B \\rangle$; if $V$ is isotropic, \r\n$\\epsilon= 1$, otherwise\r\n$V$ contains no isotropic vectors and $\\epsilon = -1$.  There are $q - \\epsilon$\r\nnon-isotropic lines.  $O(V)$ has $q - \\epsilon$ elements.  \r\nLet $\\varphi_n$ be the number of\r\nisotropic vectors in $V$ and $\\lambda_n$ the\r\nnumber of hyperbolic pairs.  If $\\langle N,M \\rangle$ is a hyperbolic plane, \r\n$\\langle N,M \\rangle \\oplus \\langle N,M \\rangle^* = V$.\r\n$\\langle N^* \\rangle$ contains $q \\varphi_{n-2}$ isotropic vectors.  \r\nA type I form: TBD.\r\nType I, II form:\r\n$\\varphi_{n}=q^{n-1}$.\r\nType III, IV form: $\\varphi_n= q^{n-1} + c q^{\\frac n 2}$, $n \\ge 1$.\r\nIf $\\Phi_n = |O_n^+(q)|$ or $|PSp_n(q)|$, $\\Phi_n= \\lambda_n \\Phi_{n-2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Classical Groups Summary.}\r\n{\\bf Theorem:}\r\nEvery isometry in ${\\mathbb R}^n$ is the product of $\\leq n+1$ reflections.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIt suffices to show every isometry, $f$ with $f(0)=0$ is the product of at most $n$ reflections.\r\nThis is true for $n= 1,2$,  suppose it is true for $n-1$.\r\n$||f(e_n)-f(0)||= ||f(e_n)||= ||e_n||= 1$.  There is a reflection, $R$ such that $g=Rf$ fixes \r\n$0$ and $e_n$ and hence $L= \\{ t e_n \\}$.  Put $W= \\{ (x_1, \\ldots, x_{n-1},0), x_i \\in {\\mathbb R} \\}$.\r\n$W \\perp L$ and $g$ fixes scalar products.  If $g(x)=y$, $\\pi_n(x)= \\pi_n(y)$.  Regard $g$ as\r\na map on ${\\mathbb R}^{n-1}$.  $g^*(x_1, \\ldots, x_{n-1})= (y_1, \\ldots , y_{n-1})$.  By induction,\r\n$g^*= R_1^* \\ldots R_{n-1}^*$ with $R_j^*(x)= x- 2(x, a_j^*) a_j^*, ||a_j^*||=1$.  Put\r\n$R_j(x)= x- 2(x, a_j) a_j$, $a_n=0, a_j^*=a_j, j<n$.  $f= R R_1 \\ldots R_{n-1}$.\r\n\\end{quote}\r\nIf $G$ is one of $SL(V)$, $Sp(V)$, $SO(V)$ or $S\\Omega(V)$, $G=BWB$, where\r\n$B$ is the \\emph{Borel subgroup} (upper triangular matrices) and $W$ is the \r\n\\emph{Weyl subgroup}\r\n(the permutation matrices).\r\n\\subsection{Fields}\r\n{\\bf Theorem:}\r\nIf $\\alpha$ is the root of an irreducible polynomial $p(x) \\in F[x]$ then \r\n$F(\\alpha)=F[\\alpha]= F[x]/(p(x))$ (This is called a\r\n\\emph{field extension}).  Isomorphisms between fields can be extended\r\nto isomorphisms of extensions over associated (under the isomorphism) polynomials.\r\n\\begin{quote}\r\n\\emph{Proof:} Suppose $\\sigma: F \\rightarrow K$ then the natural extension of $\\sigma$ \r\nto $F[x]$ gives $\\sigma: F[x] \\rightarrow K[x]$.  If $p(x)$ is irreducible, this\r\nisomorphism can be extended uniquely to $F[x]/(p(x)) \\rightarrow K[x]/(p^{\\sigma}(x))$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nAny two splitting fields of the same polynomial over $F$ are isomorphic.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\alpha$ and $\\beta$ be two roots of and irreducible polynomial which divides\r\na $f(x)$; let $E$ be the splitting field of $f(x)$.  There is an isomorphism from\r\n$F(\\alpha)$ into $F(\\beta)$ which can be extended to an automorphism of $E$.  \r\n\\end{quote}\r\n{\\bf Definitions:}  Let $E$ be a field and $G$ be a set of automorphisms of $E$, \r\n$E_G = \\{ x \\in E: \\varphi(x)=x, \\forall \\varphi \\in G \\}$.  Note that $E_G$ is a field.\r\nA polynomial is \\emph{separable} if the roots of every irreducible factor are distinct.\r\nAn extension $E/F$ is \\emph{separable} if every element of $E$ is the root of a separable polynomial\r\nin $F[x]$.\r\n$E$ is a \\emph{Galois} over $F$ if $E_G=F$.  \r\n$E$ is \\emph{normal} over $F$ if an irreducible\r\npolynomial over $F$ with one root in $E$, \\emph{splits}.\r\n\\\\\r\n\\\\\r\n{\\bf Artin's Lemma:} Distinct automorphisms are linearly independent.\r\n\\begin{quote}\r\n\\emph{Proof:}  Suppose not.  Let $c_1 \\phi_1 (x) + c_2 \\phi_2 (x) + \\ldots + c_r \\phi_r (x) =0$\r\nbe a minimal relation.  Since the automorphisms are distinct,\r\n$\\exists \\beta: \\phi_1 (\\beta) \\ne \\phi_r (\\beta)$.  Obtain two equations from the\r\nminimal relation, the first\r\nby substituting $\\beta x$ into the equation for beta, the second by multiplying the\r\nequation by $\\phi_r(\\beta)$, then subtract them.  This is a shorter relation.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nIf $G$ is a finite set of automorphisms fixing $F$, then $r=|E:F| \\geq |G|=n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Suppose not. Let $\\{ \\omega_1, \\ldots, \\omega_r\\}$\r\nbe a basis for $E$ over $F$. Consider the $r$ equations:\r\n$\\phi_1 (\\omega_k) x_1 + \\ldots + \\phi_n(\\omega_k) x_n = 0$ for $k= 1,2,\\ldots r$.\r\nSince $n>r$ there is a non trivial solution $c_1, c_2, \\ldots , c_n$.  Let\r\n$x= \\sum_{i=1}^r a_i \\omega_i$.  Multiply the first equation by $a_1$, the second by\r\n$a_2$ and so on then add them to get\r\n$c_{1} \\phi_{1} (x) + c_2 \\phi_2 (x) +  \\ldots + c_n \\phi_n (x)  = 0$\r\nfor all $x$.  This contradicts the Artin's result.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $G= \\{\\phi_1 , \\phi_2 , \\ldots, \\phi_n \\}$ be a finite group of\r\n$Aut(E)$ and $F = E_G$, then $r = [E:F] = |G| = n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Suppose $r>n$. Let $\\{ \\omega_1, \\ldots, \\omega_r\\}$\r\nbe a basis for $E$ over $F$. Consider the $n$ equations:\r\n$\\phi_k (\\omega_1) x_1 + \\ldots + \\phi_k(\\omega_r) x_r = 0$ for $k= 1,2,\\ldots, n$.\r\nThis has a non trivial solution, $\\langle c_1, c_2, \\ldots , c_r \\rangle$,\r\nwith $r-n$ more unknowns than equations.  \r\nLet $\\langle c_1, \\ldots , c_r \\rangle$ be a solution with the minimum number of non-zero\r\nelements. We may reorder the coefficients and basis so $c_1 \\neq 0$ and by dividing each of\r\nthe linear equations by $c_1$, we may assume $c_1 = 1$.  We claim each $c_i \\in F, \\forall i$.\r\nIf not, say $c_2 \\notin F$.  Then $\\exists \\phi_k: \\phi_k(c_2) \\neq c_2$.  Thus,\r\n$\\sum_{i=1}^r c_i \\phi_j(\\omega_i) = 0$ and \r\n$\\sum_{i=1}^r \\phi_k(c_i \\phi_j(\\omega_i)) = 0$ for each $ 1 \\leq j \\leq n$.  Again,\r\nreordering, \r\n$\\sum_{i=1}^r \\phi_k(c_i) \\phi_j(\\omega_i) = 0$ for each $ 1 \\leq j \\leq n$.  Subtracting\r\nthe two equations, we get a non-trivial linear relation with fewer non-zero coefficients.\r\nSo, $c_i \\in F, \\forall i, 1 \\leq i \\leq r$.  This gives a non-trivial linear dependence \r\nin $F$ among the $\\omega_i$ which contradicts their linear independence, so\r\n$r \\leq  n$.  Now $r \\geq n$ by the previous result so $n=r$.\r\n\\end{quote}\r\n{\\bf Primitive Element Theorem: }\r\nIf $E=F[\\alpha_1 , \\ldots , \\alpha_n]$ with $\\alpha_2 , \\ldots , \\alpha_n$ separable then\r\n$E=F[\\alpha]$, some $\\alpha$.  Every separable finite extension is primitive.\r\n\\begin{quote}\r\n\\emph{Proof:}  Assume $F$ is not finite, $E=F[\\alpha, \\beta]$ with $f, g$ the minimal polynomials\r\nfor $\\alpha= \\alpha_1$ and \r\n$\\beta=\\beta_1$ respectively, $\\alpha_i$  the roots of $f$ and $\\beta_i$ the roots of\r\n$g$.  Let $E$ be the splitting field of $f(x)g(x)$.  \r\n$\\alpha_i + x \\beta_k= \\alpha_1 + x \\beta_1$ \r\nhas one root for each $i, k$; pick $c$ such that\r\n$\\alpha_i + c \\beta_k \\ne \\alpha_1 + c \\beta_1$ and set $\\theta= \\alpha + c \\beta$.\r\nClaim: $E=F[\\theta]$. $f(\\theta-c \\beta)=g(\\beta)=0$ so\r\n$(f(\\theta - cx), g(x))= (x- \\beta) \\in F[\\theta][x]$. \r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $E$ be a splitting field for $f(x)$ over $F[x]$.\r\nIf $p(x)$ is irreducible and has one zero in $E$, then $p(x)$ splits in\r\n$E$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $L$ be the splitting field of $f(x)p(x)$.\r\nSet $E= F(a_1,a_2, \\ldots, a_n)$\r\nwhere $a_1, a_2, \\ldots , a_n$ are the roots of $f(x)$.\r\nSuppose $p(\\alpha)=0, \\alpha \\in E$ and $p(\\beta)= 0$.\r\nLet $\\sigma: F(\\alpha) \\rightarrow F(\\beta)$ be an isomorphism with\r\n$\\sigma(\\alpha)=\\beta$.\r\nExtend $\\sigma$ to $\\tau: L \\rightarrow L$.  $\\tau$\r\npermutes the roots of $f(x)$ so $\\tau(E)= E$.\r\n$\\alpha= {\\frac {m(a_1, a_2, \\ldots , a_n)} {n(a_1, a_2, \\ldots , a_n)}}$.\r\nSo $\\beta= \\tau(\\alpha)= \\tau({\\frac {m(a_1, a_2, \\ldots , a_n)}\r\n{n(a_1, a_2, \\ldots , a_n)}}) \\in E$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $E$ be a finite extension of $F$, $char(F)=0$.  If $E$ is a splitting\r\nfield of $f(x) \\in F[x]$\r\nthen $|{\\cal G}(E/F)| = [E:F]$.\r\n\\begin{quote}\r\n\\emph{Proof:} $E=F(w)$, $p(w)=0$ and $p$ splits by foregoing. $deg(p)=[E:F]=|G|$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $F \\subseteq E$, $char(F)=0$.  If $G={\\cal G}(E/F)$ fixes $F$ then $E$ is\r\na normal extension iff $F$ is the fixed field of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:} $E=F(w)$, $|G|=[E:F]$.  Let $K= \\{ a: \\sigma(a)=a, \\forall \\sigma \\in G\\}$.\r\n$F \\subseteq K \\subseteq E$ and $E=K(w)$.  STS if $g$ is irreducible\r\nover $F$ and $g(w)=0$ then $g$\r\nis irreducible over $K$.  Let $p$ be an irreducible polynomial for $w$ over $K$.  Applying\r\nelements of $G$, each root of $p$ is a root of $g$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\nLet $E$ be a normal extension of $F$. $E \\supset K \\supset F$.  If\r\n${\\cal G}(E/F)>S$ has $K$ as a fixed field then ${\\cal G}(E/K)=S$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose $S \\subseteq {\\cal G}(E/K)=T$.  By a previous result $|T|=|S|$ so $S=T$.\r\n\\end{quote}\r\n{\\bf Lemma:} Let $K$ be the splitting field of $f(x)$ over $k$\r\nand let $p(x)$ an irreducible\r\nfactor of $f(x)$, if the roots of $p(x)$ are $\\alpha_1 , \\ldots , \\alpha_r$,\r\nthere is a $\\sigma_i \\in {\\cal G}(K/k)$ such that $\\sigma_i(\\alpha_1)= \\alpha_i$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nThis follows from the isomorphism $F[x]/(f(x)) \\rightarrow F(\\alpha )$ and\r\n$F[x]/(f(x)) \\rightarrow F(\\alpha_i )$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\n$E$ is Galois over $F$ iff (i) every irreducible polynomial in $F[x]$ with one root in $E$\r\nsplits and (ii) $E=F(\\theta)$.\r\n$GF(p^m) \\subseteq GF(p^n)$ iff $m|n$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\theta= \\theta_1$ and $\\varphi= \\varphi_1$ is another root.  Let $f \\in F[x]$ \r\nbe irreducible with root $\\theta$.  By the lemma, \r\nthere is a $g \\in {\\cal G}(E/F)$.  $f^g(x)=f(x)$. (ii) follows from this.\r\n$\\theta^g=\\varphi$ and so $\\varphi$ is thus a root of $f$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe following are equivalent: (1) $E$ is a splitting field over $F$\r\nof a separable polynomial $f(x)$.  (2) $F=E_G$. (3) $E$ is finite\r\ndimensional, normal and separable.  Moreover, if $E$ and $F$ are as in (1) and\r\n$G= {\\cal G}(E/F)$ then $F=E_G$ and if $F$ and $G$ are as in (2) then $G={\\cal G}(E/F)$.\r\n\\begin{quote}\r\n\\emph{Proof of\r\n($1 \\rightarrow 2$):}\r\n$G={\\cal G}(E/F)$ and $F'=E_G$. $F \\subseteq F' \\subseteq E$.  $E$ is a splitting field\r\nover $F'$ of $f(x)$ as well as over $F$ and $G={\\cal G}(E/F')$. $[E:F]= |G| = [E:F']$ so\r\n$F=F'$ and $F=E_G$\r\n\\\\\r\n\\\\\r\n\\emph{Proof of\r\n($2 \\rightarrow 3$):}\r\nBy Artin $[E:F] \\le |G|$ so $E$ is finite dimensional over $F$.  Let $f(x) \\in F[x]$\r\nhaving root $r \\in E$ be irreducible.  Let $\\langle r=r_1, \\ldots, r_m \\rangle$\r\nbe an orbit of $r$ under $G$.  For $\\eta \\in G$, $(\\eta(r_1) , \\ldots , \\eta(r_m))$ is\r\na permutation of $(r_1 , r_2, \\ldots , r_m)$.  $f(r_i)=0, 1 \\leq i \\leq m$ and\r\n$(x-r_i) \\mid f(x)$ so $g(x)= \\prod_{i=1}^m (x-r_i) \\mid f(x)$.  Apply to $g(x)$\r\nthe automorphism of $E[x]$ which sends $x \\mapsto x, a \\mapsto \\eta(a)$ for $a \\in E$.\r\nThis gives $\\eta(g(x))= \\prod_{i=1}^m (x-\\eta(r_i))= g(x)$.  Since this holds for every\r\n$\\eta \\in G$, the coefficients of $g$ are $G-$invariant hence $g(x) \\in F[x]$.  Since\r\n$g(x)$ is irreducible in $F[x]$, $f(x)=g(x)= \\prod_{i=1}^n (x-r_i)$ a product of linear\r\nfactors in $E[x]$.  Thus $E$ is separable and normal over $F$ and (3) holds.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of\r\n($3 \\rightarrow 1$):}\r\nSince $[E:F] < \\infty$ so $E= F(r_1, r_2, \\ldots, r_k)$ and $r_i$ is algebraic over $F$.\r\nLet $f_i$ be the minimal polynomial for $r_i$.  By hypothesis, $f_i(x)$ is a product of\r\nlinear factors in $E[x]$.   It follows that $f(x)= \\prod_{i=1}^n f_i(x)$ is separable\r\nand $E= F(r_1, r_2, \\ldots, r_k)$ is a splitting field for $E$ over $F$ and (1)\r\nfollows.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of supplement:}\r\nTo prove the second part of the supplement, under the hypothesis of part (2) of the supplement,$[E:F] \\leq G$\r\nand since (3) holds, ${\\cal G}(E/F)=[E:F]$.  Since\r\n$G \\subseteq {\\cal G}(E/F)$ and \r\n$|G| \\geq [E:F]= |{\\cal G}(E/F)|$, $G= {\\cal G}(E/F)$.\r\n\\end{quote}\r\n{\\bf Galois' Theorem:} Let $K$ be a normal, separable extension of $k$.  Let $G={\\cal G}(K/k)$,\r\n$H<G$, $K \\supseteq F \\supseteq k$.  There is a bijective pairing between $H$ and $F$, such\r\nthat\r\n(i) $H_{1} \\supseteq H_{2} \\leftrightarrow K_{H_{2}} \\supseteq K_{H_{1}}$;\r\n(ii) $|H|= [K:K_H]$, $[G:H]= [K_H:k]$; and,\r\n(iii) $H \\lhd G \\leftrightarrow K_H$ is normal over $k$\r\nand ${\\cal G}(K_H/k)=G/H$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n\\\\\r\n\\\\\r\nLet  $H<G={\\cal G}(K/k)$.  $k=K_G$.\r\nPut $F = K_H$.  $k \\subseteq F \\subseteq K$.  By the previous result,\r\n$|{\\cal G}(K/K_H)|=|H| = [K:K_H]$.  \r\nApplying supplementary result (2) above with $H$ in place of $G$, we get\r\n${\\cal G}(K/K_H)= H$.\r\nSimilarly,  $|H|=|{\\cal G}(K/K_H)|=[K:K_H]$.\r\n\\\\\r\n\\\\\r\nNow, let $F$ be any intermediate subfield between $K$ and $k$ and $H= {\\cal G}(K/F)$.\r\n$H \\subseteq G={\\cal G}(K/K_H)$.\r\n$K$ is a splitting fields over $F$ of\r\na separable polynomial since it is a splitting field over $k$ of a separable polynomial.\r\nThe supplementary result of (1) above applied to $K$ and $F$ shows\r\n$F=K_H= K_{{\\cal G}(K/F)}$.\r\nThus the map between $F$ and $K_H$ are inverses.\r\n\\\\\r\n\\\\\r\nIf $H_1 \\supseteq H_2$ then \r\n$K_{H_1} \\subseteq K_{H_2}$.\r\nMoreover, if $K_{H_1} \\subseteq K_{H_2}$ then we also have\r\n$H_1 = {\\cal G}(K/K_{H_1}) \\supseteq {\\cal G}(K/K_{H_2}) = H_2$. Hence (i)\r\nholds. \r\n\\\\\r\n\\\\\r\nThe first part of (ii) follows as before.\r\n$|G|= [K:k] = [K:K_H][K_H:k]= |H| [K_H:k]$ and $|G|= [G:H] |H|$ so\r\n$[K_H:k]= [G:H]$.  This proves (ii).\r\n\\\\\r\n\\\\\r\nIf $H < G$ and $F= K_H$, the subfield corresponding \r\nto $\\eta H \\eta^{-1}$ is $\\eta(F)$.\r\n$\\eta H \\eta^{-1} \\eta F= \\eta(F)$,\r\nso $H \\lhd G$ iff $\\eta(F)=F, \\forall \\eta \\in G$.  If this holds, every\r\n$\\eta$, maps\r\n$F$ to itself and $\\eta_{|F}= {\\overline {\\eta}}$ is an automorphism of $F/k$.\r\nThus the restriction $\\eta \\rightarrow {\\overline {\\eta}}$ of\r\n${\\cal G}(K/k)$ into ${\\cal G}(F/k)$ is a homomorphism.  \r\nThe image ${\\overline G}$ is a group of automorphisms\r\nof $F$ and $K_{{\\overline G}}=k$.\r\nHence ${\\overline G}= {\\cal G}(F/k)$.\r\nThe kernel of the map \r\n$\\eta \\rightarrow {\\overline {\\eta}}$ is the set $\\{ \\eta \\in G: \\eta_{|F}=1_{F} \\}$;\r\nby the pairing, ${\\cal G}(K/F)= H$.  This kernel is $H$ and\r\n${\\overline G}= {\\cal G}(F/k) \\approx G/H$.  Since $k= K_{\\overline G}$,\r\n$F$ is normal over $k$.\r\n\\\\\r\n\\\\\r\nConversely, suppose $F$ is normal over $k$.  Let $a \\in F$ and let $f(x)$ be the\r\nminimal polynomial for $a$ over $k$ then $f(x)= (x-a_1) (x-a_2) \\ldots (x-a_n) \\in k[x]$\r\nwhere $a=a_1$.  If $\\eta \\in G$ then $f(\\eta(a))=0$ which implies $\\eta(a)= a_i$\r\nfor some $i$ so $\\eta(a) \\in F$.  \r\nTherefore, $\\eta(F) \\subseteq F$.  $\\eta H \\eta^{-1} \\subseteq H$ if $H$ is the subgroup\r\ncorresponding to $F$ in the Galois pairing. Thus $H \\lhd G$, concluding the proof\r\nof (iii).\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $f(x)$ is solvable by radicals, the Galois group of its splitting field\r\nis \\emph{solvable}.  Galois group of an equation is a permutation group on its roots.\r\nSplitting field of $g(x)= 2x^5 -10 x+5$ is $S_5$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nThere is an element of order $5$ in $G$ since $g(x)$ is irreducible.  Complex conjugation\r\nis an automorphism of order $2$.  These generate $S_5$.\r\n\\end{quote}\r\n{\\bf Computing the Galois group for an arbitrary polynomial:}\r\nSuppose, \r\n$f(t) = t^n -s_1 t^{n-1} + \\ldots + (-1)^{n}s_n$ over the field $k$.  \r\nLet $K$ be the splitting field of $f$ over $k$ and $G = {\\cal G}(K/k)$.\r\nAssume\r\n$f(t)$ has distinct zeros $\\alpha_1, \\ldots , \\alpha_n$ and consider the\r\nindeterminates $x_1, \\ldots, x_n$.  The $s_k$ are elementary symmetric polynomials\r\nin the $\\alpha_k$.  Put $\\beta = \\sum_{j=1}^n x_j \\alpha_j$.  Suppose\r\n$\\sigma \\in S_n$.  We set $\\sigma_x ( \\beta ) = \\sum_{j=1}^n x_{\\sigma(j)} \\alpha_j$\r\nand $\\sigma_{\\alpha} ( \\beta ) = \\sum_{j=1}^n x_{j} \\alpha_{\\sigma(j)}$. Put\r\n$q(t) = \\prod_{\\sigma \\in S_n} (t - \\sigma_x(\\beta)) = \r\n\\sum_{j=0}^{n!} g_i (s_1 , \\ldots, s_n) x_1^{i_1} x_2^{i_2} \\ldots x_n^{i_n} t^j$.\r\nNow $q(t) = q_1(t) q_2(t) \\ldots q_k(t)$ where each $q_k(t)$ is irreducible.\r\nWe can assume $(t - \\beta) \\mid q_1(t)$.\r\nPut $G_1 = \\{ \\sigma \\in S_n: q_1(t)^{\\sigma} = q_1(t) \\}$.  In fact, if we\r\nput $S_{(1)} = \\{ \\sigma : (t - \\sigma_x(\\beta)) \\mid q_1 (t) \\}$, $S_{(1)} = G_1$.\r\nFinally, define\r\n$h(t) = \\prod_{\\sigma \\in G} (t - \\sigma_{\\alpha}(\\beta))$. $h(t) \\mid q(t)$ so\r\n$h(t)$ is the product of some of the irreducible factors of $q(t)$.\r\nFor each $q_k$, there is a subset $S_{(k)}$ of $S_n$ such that\r\n$q_k(t) = \\prod_{\\sigma \\in S_{(k)}} (t - \\sigma_x(\\beta))$ and $S_n$ is the disjoint union\r\nof the $S_{(k)}$.\r\nSince, $(t - \\beta) \\mid q_1(t)$, $q_1(t) \\mid h(t)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} In the above notation, $G_1 = G$.\r\n\\begin{quote}\r\n\\emph{Proof:} (1) $G_1 \\subseteq G$ since $q_1(t) \\mid h(t)$. (2) $G \\subseteq G_1$:\r\nIf $\\rho \\in G$, $\\rho(q_1(t)) = \\prod_{\\sigma \\in S_1} (t- \\rho(\\sigma_x(\\beta)))$ and\r\n$\\rho(q_1(t)) = \\prod_{\\sigma \\in S_{(1)}} (t- \\rho(\\sigma_x(\\beta))) = \r\n\\prod_{\\sigma \\in S_{(1)}} (t- \\rho_{\\alpha}^{-1}(\\sigma_{x}(\\beta))) = \\rho_{\\alpha}^{-1}(q_1(t))$.\r\nSo, $\\rho \\in G_1$.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $R$ be a UFD and $p$ a prime.  Set \r\n${\\overline R}= R/(p)$ and let $Q_R$ and $Q_{\\overline R}$ be their fields of\r\nquotients.  Let $f(x)$ and ${\\overline {f(x)}}$ be corresponding polynomials\r\nwith no double roots with corresponding splitting fields $K$ and ${\\overline K}$\r\nrespectively.  Then \r\n${\\cal G}({\\overline K}/Q_{\\overline R})< {\\cal G}(K/Q_R)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\end{quote}\r\n{\\bf Definition:}\r\nA \\emph{valuation} is a map $\\varphi: K \\rightarrow {\\mathbb F}^{\\ge 0}$ \r\nwhere ${\\mathbb F}$ is an\r\nordered field such that $\\varphi(ab)= \r\n\\varphi(a) \\varphi(b)$, $\\varphi(0)=0$, $\\varphi(x)>0$ if $x \\ne 0$ and \r\n$\\varphi(a+b) \\le\r\n\\varphi(a) + \\varphi(b)$.  If $a= {\\frac s t} p^n$, $\\varphi(a)= p^{-n}$ is a valuation.\r\n{\\bf Ostowski:} A non trivial valuation of ${\\mathbb Q}$ is either \r\n(i) $\\varphi(a)= |a|^\\rho, 0 < \\rho \\le 1$ (the Archemedean valuation) or (ii)\r\n$\\varphi(a)= \\varphi_p(a)$ (the $p-$adic valuation.  $w(a)= log(\\varphi(a))$ is the \r\nexponential valuation.  Set $\\wp= \\{a: w(a) >0 \\}$.  Hensel:  Let $K$ be complete\r\nin the exponential valuation $w$ and $f(x)$ a primitive polynomial in $K[x]$ with integral\r\ncoefficients. Let $g_0 , h_0$ be polynomials with integral coefficients such that\r\n$f(x)= g_0(x) h_0(x) \\; (\\wp)$ then there are polynomials $f(x), h(x)$ with integral\r\ncoefficients in $K$ such that (1) $f(x)=g(x)h(x)$, \r\n(2) $g(x)= g_0(x) \\; (\\wp)$,\r\n(3) $h(x)= h_0(x) \\; (\\wp)$ provided $(g_0(x), h_0(x))=1$ \r\nfurther $deg(g)= deg(g_0) \\; (\\wp)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\n$F$ is \\emph{perfect} iff every irreducible polynomial is separable.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $F$ is perfect if\r\n(1) $char(F)=0$, (2) $char(F)=p$ and every element is a $p$th root,\r\n(3) $F= GF(q)$, (4) $F$ is algebraically closed, (5) every finite field is perfect.\r\n\\begin{quote}\r\n\\emph{Proof of $2$:}  Suppose $F^p$ is not contained in $F$.  Let $a \\notin F^p$.\r\n$x^p-a$ is irreducible.  Since the derivative is $0$, this is inseparable.  Hence\r\n$F$ is not perfect.  Suppose $f(x)$ is an inseparable irreducible polynomial in\r\n$F[x]$ then $(f,f') \\ne 1$.  So $f(x)= a_0 +a_p x^p + \\ldots + =\r\nb_0 + b_p^px + b_{2p}^p x^{2p} + \\ldots)^p$ contrary to irreducibility.\r\nHence $F \\ne F^p$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nLet $E=F[\\theta]$ and $\\rho= a_0 + a_1 \\theta + \\ldots + a_{n-1} \\rho^{n-1}$. \r\n$T(\\rho)= \\sum_{g \\in {\\cal G}(E/F)} \\rho^g$ is the \\emph{trace} and\r\n$N(\\rho)= \\prod_{g \\in {\\cal G}(E/F)} \\rho^g$ is the \\emph{norm}; both are in $F$.\r\n\\\\\r\n\\\\\r\n{\\bf Automorphisms of a finite field:}\r\nFor every $q=p^n$ there is, up to isomorphism, only one field $F=GF(q)$ and the\r\nmultiplicative group is cyclic. Consider $f(x)= x^h-1, h=q-1$ whose roots are\r\nroots of 1.  The automorphisms of $F$ are exactly $\\sigma_i : x \\mapsto x^{p^i}$.\r\nIf $char(F)=p$, every irreducible polynomial $f(x)$ of degree $n$\r\neither has distinct roots or is of\r\nthe form $\\phi(x^p)$ in which case all roots have the same multiplicity $p^l$ for\r\nsome $l>0$ with $n=n' p^l$ in which case there are $n'$ relative automorphisms.  Thus\r\nin successive extensions there are $\\prod_i n_i'$ relative automorphisms which have\r\ncardinality\r\n$[E:F]$ if $E$ is a separable extension and $<[E:F]$ if not.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $G$ is solvable, $G^{(n)}=1$ for some $n$.  If $n>4$, $S_{n}^{(m)}$\r\ncontains every 3 cycle for every $m$.\r\n\\begin{quote}\r\n\\emph{Proof:} $G^{(0)} \\supseteq G^{(1)} \\supseteq \\ldots \\supseteq G^{(m)} = 1$ is\r\na composition series with abelian composition factors.  This can be refined into a\r\ncomposition series with composition factors of prime order.  For the second part,\r\nnote that $(123) = (13)(12)(13)(12) \\in S_{n}^{(1)}$.  Replacing $1$ by $a$,\r\n$2$ by $b$ and $3$ by $c$ shows $(abc) \\in S_{n}^{(1)}, \\forall a, b, c$.\r\nWe show by induction that if $H$ contains all $3$-cycles, so does $H'$, if $n \\ge 5$.\r\nSince $(123)(234) = (13)(24)$, $(ab)(cd) \\in H'$. $[(bc)(de),(abc)] =(abc) \\in H'$ so\r\nany $3$-cycle is in $H'$.\r\n\\end{quote}\r\n{\\bf Cyclic Extensions:}\r\nSuppose $f \\in k[x], deg(f)=n$ and let\r\n${\\cal G}_f(k)$ denote \r\n${\\cal G}(K/k)$ where $K$ is the splitting field for $f$ over $k$. Then\r\n${\\cal G}_f(k)$ is isomorphic to some subgroup of $S_n$ and if $f$ is irreducible,\r\nthe group is transitive on $n$ symbols.  Set $\\Delta= \\prod_{i<j} (u_i-u_j)$ and\r\n$Disc_k(f)= \\Delta^2$, then if $f$ is irreducible, the Galois group is\r\n$A_3$ or $S_3$ according to whether \r\n$Disc_k(f)= \\Delta^2$ is a square in $k$.  If $f$ is a quartic with separated roots\r\n$u_1, u_2, u_3, u_4$ and\r\n$\\alpha= u_1 u_2 + u_3 u_4$,\r\n$\\beta= u_1 u_3 + u_2 u_4$,\r\n$\\gamma= u_1 u_4 + u_2 u_3$; setting $K=k(\\alpha, \\beta, \\gamma)$ and\r\n$[K:k]=m$, then\r\n${\\cal G}_f(k)$ is $S_4$ if $m=6$,\r\n${\\cal G}_f(k)$ is $A_4$ if $m=3$,\r\n${\\cal G}_f(k)$ is ${\\mathbb Z} \\times {\\mathbb Z}$ if $m=1$, and\r\n${\\cal G}_f(k)$ is ${\\mathbb Z}_4$ \r\nor $D_4$ if $m=2$.\r\n\\\\\r\n\\\\\r\n{\\bf Embeddings:}\r\nLet $k \\subset K \\subset {\\overline k}$ and \r\n$\\sigma_1, \\sigma_2, \\ldots , \\sigma_r$ \r\nbe the distinct $k$-monomorphisms from $K \\rightarrow {\\overline k}$, for\r\n$u \\in K$,\r\ndefine \r\n$N_k^K(u) = (\\prod_{i} \\sigma_i(u))^{[K:k]_i}$ and\r\n$Tr_k^K(u) = (K:k]_i \\sum_{i} \\sigma_i(u)$.  Note that distinct automorphisms are\r\nlinearly independent.  From now on, assume all extensions are separable (even Galois).\r\n$N_k^K (uv)= N_k^K(u) N_k^K(v)$ and\r\n$Tr_k^K (u+v)= Tr_k^K(u) + Tr_k^K(v)$; if $u \\in k$,\r\n$N_k^K (u)= u^{[K:k]}$ and\r\n$Tr_k^K (u)= [K:k]u$; if $E$ is an intermediate field,\r\n$N_k^K (u)= N_k^E(N_E^K(u))$ and\r\n$Tr_k^K (u)= Tr_k^E(Tr_E^K(u))$.  If $K$ is a cyclic extension of $k$ of degree\r\n$n$ with generator $\\sigma$\r\nthen $Tr_k^K(u) = 0$ iff $\\exists v \\in K: u= v - \\sigma(v)$ and\r\n$N_k^K(u) = 1$ iff $\\exists v \\in K: u= v(\\sigma(v))^{-1}$.  If $n= mp^t, (p,n)=1$\r\nwhere $char(k)=p \\ne 0$, there are intermediate cyclic fields, all\r\nof which, except the last have degree $p$ and\r\neach of which is the splitting field of $f(x)= x^p-x+a$.\r\nIf $char(k)=p \\ne 0$, $K$ is a cyclic extension of degree $p$ iff\r\n$K$ is the splitting field of an irreducible polynomial\r\n$f(x)= x^p -x - a$ and $K=k(u), f(u)=0$.\r\nSuppose $\\zeta$ is a primitive $n$th root of unity over $k$ and $K= k(\\zeta)$,\r\nif $d \\mid n$, $\\zeta^{n/d}$ is a primitive $d$-th root of unity and,\r\n$K$ is the splitting field over $k$ of an irreducible polynomial\r\n$f(x)= x^d-a, a \\in k$.\r\nIf $k$ contains a primitive  $n$-th root of unity, $\\zeta$,\r\nTFAE: (1) $K$ is cyclic of degree $d$\r\n$d \\mid n$,\r\n(2) $K$ is the splitting field over $k$ of $f(x)= x^n-a, a \\in k$,\r\n(3) $K$ is the splitting field over $k$ of an irreducible polynomial\r\n$f(x)= x^d-a, a \\in k$.\r\n\\\\\r\n\\\\\r\n{\\bf Satz 90:}  Let $E/F$ be a cyclic extension with Galois group generated by\r\n$\\sigma$ then \r\n(a) $N_{E/F}(x)= 1$ iff $\\exists y \\in E: x= y/\\sigma(y)$; and,\r\n(b) $T_{E/F}(x)= 0$ iff $\\exists y \\in E: x= y - \\sigma(y)$.\r\nLet $(n, char(k))= 1$, and $K$ a \\emph{cyclotomic extension} of $k$, then,\r\n(1) $K= k(\\zeta)$ where $\\zeta$ is a primitive $n$-th root of unity;\r\n(2) $K$ is an \\emph{abelian extension} of $k$ of dimension $d, d \\mid \\psi(n)$;\r\n(3) $|{\\cal G}(K/k)|=d$ and is a subgroup of ${\\mathbb Z}_n^*$.\r\n\\begin{quote}\r\n\\emph{Proof of additive part:}\r\nIf such an $\\alpha$ exists then $Tr_k^K(\\beta)=0$ as $\\sigma$ permutes\r\nthe elements. Conversely,\r\nsuppose $Tr_k^K(\\beta)=0$, $\\exists \\theta: Tr_k^K(\\theta) \\ne 0$.\r\nLet $\\alpha = {\\frac 1 {Tr(\\theta)}} [ \r\n\\beta \\theta^{\\sigma} +\r\n(\\beta + \\sigma \\beta) \\theta^{\\sigma^2} + \\ldots +\r\n(\\beta + \\sigma \\beta + \\ldots + \\sigma^{n-2} \\beta) \\theta^{\\sigma^{n-1}}]$.\r\nFrom this, we get $\\beta= \\alpha - \\sigma \\alpha$.\r\n\\\\\r\n\\\\\r\n\\emph{Proof of multiplicative part:}\r\nAssume $\\alpha$ exists.  $N(\\beta)= {\\frac {N(\\alpha)} {N(\\sigma(\\alpha))}}$ \r\nand since elements of $G$ permute these, $N(\\beta)=1$.  Now suppose\r\n$\\tau, \\tau' \\in G, \\xi \\in E: \\xi^{\\tau + \\tau'}= \r\n\\xi^{\\tau} \\xi^{\\tau'} $.   By Artin's theorem on characters, the map given by\r\n$ id+ \\beta \\sigma + \\beta^{1+\\sigma} \\sigma^2+ \\ldots +\r\n\\beta^{1+\\sigma + \\ldots + \\sigma^{n-2}} \\theta^{\\sigma^{n-1}} \\ne 0 $.\r\nHence $\\exists \\theta \\in K: \r\n\\alpha= \\theta + \\beta \\theta^{\\sigma} + \\beta^{1+\\sigma} \\theta^{\\sigma^2} + \\ldots +\r\n\\beta^{1 + \\sigma + \\ldots + \\sigma^{n-2}} \\theta^{\\sigma^{n-1}} \\ne 0$.  \r\n$\\beta \\alpha^{\\sigma}= \\alpha$ using the fact that $N(\\beta)=1$ and so\r\napplying $\\sigma$ to the last term in the sum, we obtain $\\theta$.  Dividing by\r\n$\\alpha^{\\sigma}$, the proof concludes.\r\n\\end{quote}\r\n{\\bf Radical extensions:} $K= k(u_1, u_2, \\ldots , u_n)$ where\r\n$\\exists n_1 : {u_1}^{n_1} \\in k$ and\r\n$\\exists n_m : {u_m}^{n_m} \\in k(u_1 , \\ldots , u_{m-1})$.  $f$ is said to\r\nbe solvable by radicals if there is a radical extension containing the splitting\r\nfield of $f$.\r\nIf $K$ is a radical extension of $k$  and $E$ is an intermediate field\r\nthen ${\\cal G}(E/k)$ is solvable.\r\nIf $E$ is a finite dimensional extension of degree $n$, $char(k) \\nmid [E:k]$\r\nand ${\\cal G}(E/k)$ is solvable then there is a radical extension\r\n$K$ of $k$ containing $E$.  If $char(k) \\nmid n!$ and $f \\in k[x], deg(f)=n$ then\r\n$f(x)=0$ is solvable by radicals iff ${\\cal G}_f$ is solvable.  To show this,\r\nit suffices to consider prime exponents but we need\r\nto prove:\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $q \\nmid char(F)$ then the $q$-th root of unity are expressible as radicals, $q$,\r\na prime.\r\n\\\\\r\n\\\\\r\nFirst a {\\bf Lemma:} If $x^p-a$ is reducible, $a$ is a $p$-th power.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $x^p-a = \\psi(x) \\phi(x)$, each is a product of factors of the form $(x- \\zeta_{\\nu} \\theta)$ where\r\n$\\zeta$ is a $p$-th root of unity and $\\theta^p=a$.  Say, $\\psi(x)= b_k x^k + \\ldots + b_0$ is \r\na product of $k$ of them.  $(p,k)=1$ so $cp+dk=1$ for some $c, d \\in {\\mathbb Z}$.  Further,\r\n$b= b_0= \\zeta^{\\nu} \\theta^k$.  So $a=a^{cp} \\cdot a^{dk}= b^{dp} \\cdot a^{cp}$ which proves\r\nthe result.\r\n\\end{quote}\r\n\\begin{quote}\r\n\\emph{Proof of Theorem:}\r\nBy induction on $q$, clear for $q=2$.  The $q$-th roots of unity form a cyclic extension of\r\ndegree $q-1= p_1^{e_1} \\ldots p_k^{e_k}$.  By induction, the successive $p_i$-th roots of unity\r\nare radicals and adjoining them, $x^{p_k}-a$ must be irreducible by the lemma so each such\r\nextension is a radical extension.\r\n\\end{quote}\r\n{\\bf Theorem:} Let $R_m$ be the ring of integers in ${\\mathbb Q}[{\\sqrt m}]$.  Suppose\r\n$\\forall x, y\\in R_m$, with $y \\nmid x$ and $|N(x)| \\ge |N(y)|$, $\\exists u, v \\in R_m$ such that\r\n$N(xu-yv) \\leq |N(y)|$. Then $R_m$ is a PID.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $I$ be an ideal and assume, by way of contradiction, $R_m$ is Euclidean.\r\nChoose $y \\ne 0$ so that $|N(y)|$ is minimal.  WTS $y \\mid x$.  We can find\r\n$u, v$: $N(xu-yv) \\leq |N(y)|$ but this contradicts the minimality of $|N(y)|$.  Thus\r\n$y \\mid x$ and $I = (y)$.\r\n\\end{quote}\r\n{\\bf Theorem:} $R_{-19}$ is a PID.\r\n\\begin{quote}\r\n\\emph{Proof:} $R_{-19} = {\\frac {a + b {\\sqrt m}} {2}}$.  Suppose $y \\nmid x$, $|N(x)| \\geq |N(y)|$.\r\n${\\frac {x} {y}} = {\\frac {a + b {\\sqrt m}} {c}}, c > 1$.  Each of the cases $c=2, c=3, c=4, c \\geq 5$,\r\nyield contradictions.\r\n\\end{quote}\r\n{\\bf Theorem:} If $m \\in {\\mathbb Z}^{<0}$ is square-free and $m \\notin \\{-1, -2, -3, -7, -11 \\}$,\r\nthen $R_m$ is not a Euclidean domain.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose if is.  CHoose $b \\in R_m \\setminus U(R_m)$ with $d(b)$ minimal.\r\n$\\forall a, a=bq+r$ and $r =0, \\pm  1$, so $b \\mid 2, 3$.  However,\r\nboth $2$ and $3$ are irreducible in $R_m$.  If $m = 1 \\jmod{4}$ and put $a= {\\frac {1 + {\\sqrt m}} {2}}$.\r\nNeither $a, a+1, a-1$ are divisible by $2$ or $3$.  Contradiction.\r\n\\end{quote}\r\n{\\bf Theorem:} $R_{-19}$ is a PID that is not a Euclidean domain.\r\n\\begin{quote}\r\n\\emph{Proof:}  By the above, $R_{-19}$ is not a Euclidean domain and is a PID.\r\n\\end{quote}\r\n\\subsection {Computational Algebra}\r\n{\\bf Discrete Fourier Transform and FFT:} Let $c(x)=a(x)b(x)$ which\r\ncorresponds to the convolution ${\\vec c} = {\\vec a} * {\\vec b}$.\r\nDefine the DFT as \r\n$F({\\vec a})= A {\\vec a}$, $A= \\omega^{ij}$ with inverse\r\n$A^{-1}= {\\frac 1 n} \\omega^{-ij}$.\r\nNote that $F({\\vec b} * {\\vec c})= F({\\vec b}) \\cdot F({\\vec c})$ (pointwise multiplication).\r\n\\emph{Tukey-Cooley Idea:} Suppose $n=pq$, set \r\n$j=j(j_1,j_2)= j_1 q +j_2, k=k(k_1 , k_2)= k_2p+k_1,\r\n0 \\le j_1 <p, 0 \\le j_2 <q, 0 \\le k_1 <p, 0 \\le k_2 <q$.  Then\r\n${\\hat f}(k_1, k_2)= \r\n\\sum_{j_2=0}^{q-1}\r\ne^{\\frac {2 \\pi i j_2 (k_2p+k_1)} {n}}\r\n\\sum_{j_1=0}^{p-1}\r\ne^{\\frac {2 \\pi i j_1 k_1} {p}} f(j_1 , j_2)$.  This requires $p^2q$ and $q^2p$ operations\r\nrespectively or $pq(p+q)$ rather than $(pq)^2$.  \r\nNow do this recursively if $p, q$ factor further.\r\n$X_n = \\sum_{k=0}^{N-1} x_k e^{-ikn}$.\r\n$x_n = {\\frac 1 N} \\sum_{k=0}^{N-1} X_k e^{ikn}$.\r\n\\\\\r\n\\\\\r\n{\\bf Strassen and FFT:}  For matrix multiply, Strassen found $7$ products that do the trick.\r\n$m_1= (a_{12} - a_{22}) (b_{21} - b_{22})$,\r\n$m_2= (a_{11} + a_{22}) (b_{11} + b_{22})$,\r\n$m_3= (a_{11} - a_{21}) (b_{11} + b_{12})$,\r\n$m_4= (a_{11} + a_{12}) b_{22}$,\r\n$m_5= a_{11} (b_{21} - b_{22})$,\r\n$m_6= a_{22} (b_{21} + b_{11})$,\r\n$m_7= (a_{21} + a_{22}) b_{11}$.\r\n$c_{11}= m_1 + m_2 -m_4 + m_6$,\r\n$c_{12}= m_4 + m_5$,\r\n$c_{21}= m_6 + m_7$,\r\n$c_{22}= m_2 - m_3 + m_5 - m_7$.  $T(n)= 7 T({\\frac n 2}) + 18 {\\frac n 2}^2$, which is\r\n$O(2^{lg(7)})$. $F_{i,j}= \\omega^{ij}$.  $F$ evaluates, $F^{-1}$, interpolates.\r\n$q_{l,m} = \\prod_{j=l}^{l+2^m-1} (x-c_j)$ and $q_{l,m}= a_{l, m-1} q_{l+2^m,m-1}$.\r\nWhat is $Rem({\\frac {p(x)} {q_{l,0}(x)}}), \\forall l$?  If $q= q' q''$, \r\n$Rem({\\frac {p(x)} {q'(x)}}) =Rem({\\frac {r_{l,m}(x)} {q'(x)}})$,\r\n$q_{l,m}= x^{2^m} =\\omega^{rev(l/2^m)}$.  For algorithm, crucial step is\r\n$r_{l,m}(x) =\\sum (a_j + \\omega^s a_{j+2^m}) x^j$ and\r\n$r_{l+2^m,m}(x) =\\sum (a_j + \\omega^{s+ {\\frac n 2}} a_{j+2^m}) x^j$.\r\n\\\\\r\n\\\\\r\n{\\bf Hensel:}  If $I \\subseteq {\\mathbb R}$, $f=gh \\jmod{I}$ such that the pseudo \r\n$GCD(g,h)=1$ then\r\n$\\exists g^*,h^*$ such that (1) $f= g^* h^* \\jmod{I^2}$,\r\n(2) $g=g^* \\jmod{I}$,\r\n(3) $h=h^* \\jmod{I}$, and pseudo $GCD(g^*,h^*)=1 \\jmod{I^2}$.\r\nIf $g', h'$ satisfy the conditions also, \r\n$g'=g^*(1+u) \\jmod{i^2}$ and\r\n$h'=h^*(1-u) \\jmod{i^2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Bivariate Factoring:}  If $|{\\mathbb F}|>4d^2$, $f \\in {\\mathbb F}$, \r\n$deg_x(f) \\leq d$, $\\exists \\in {\\mathbb F}$: $f_{\\beta}(x,0) \\in {\\mathbb F}[x]$\r\nhas no repeated factors.\\\\\r\n\\jt 1a Obtain square free factorization.\\\\\r\n\\jt 1b Find $\\beta \\in {\\mathbb F}$ such that $f(x,\\beta)$ is squarefree.\\\\\r\n\\jt 1c $f_{\\beta}=f(x,y+\\beta)$.\\\\\r\n\\jt 2a $f(x,y)=g(x,y)h(x,y) \\jmod{y}$.\\\\\r\n\\jt 2b Lift $f(x,y)=g_k(x,y)h_k(x,y) \\jmod{y^k}$.\\\\\r\n\\jt 3a Find $g''$ and $l_k$: $g''=g_k l_k \\jmod{y^{2^k}}$, \r\n$deg_x(g'') \\leq deg_x(f)$,\r\n$deg_y(g'') \\leq deg_y(f)$, $g'' \\ne 0$. \\\\\r\n$|Res(f,g,x)| \\leq  (m+1)^{\\frac n 2} (n+1)^{\\frac m 2} A^{\\frac m 2} B^{\\frac n 2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Extension Theorem:}\r\nLet $I= \\langle f_1 ,..., f_s \\rangle \\in {\\mathbb C}(x_1,x_2,...,x_n)$ and $I_1$\r\nis the first elimination ideal of $I$.  For each $1 \\leq i \\leq s$ write\r\n$f_i = g(x_2,...,x_n) {x_1}^{N_i} + ...$.   Suppose $c=(c_2,...,c_n) \\in V(I_1)$.\r\nIf $c \\notin V(g_1,g_2,...,g_s)$, $\\exists c_1$ such that $(c_1,c) \\in V(I)$.  \r\n\\\\\r\n\\\\\r\n{\\bf Linear Programming:} $max(cx)$ subject to $Ax \\leq b$, $x \\geq 0$.\r\n{\\bf Quadratic Programming: }\r\n$max(\\sum \\rho_{ij}\\sigma_i \\sigma_j x_i x_j)$, subject to $\\sum x_i =1$,\r\n$x_i \\geq 0$, $\\sum x_i u_i \\geq R$.\r\n\\subsection{Algebraic Number Theory}\r\n{\\bf Gaussian Integers:} ${\\mathbb Z}[i]$.  Let $\\alpha, \\beta, \\gamma, \\delta$ represent\r\ngaussian integers.  $N(x+yi)= x^2 + y^2$.\r\n$\\forall \\alpha, \\beta, \\exists \\gamma, \\delta$ such that\r\n$\\alpha= \\beta \\gamma + \\delta$ with $0 \\leq N(\\delta) < N(\\beta)$.\r\n$\\alpha$ is a unit iff $N(\\alpha)=1$. Units are $1, -1, i, -i$.\r\nLet $S= \\{\\alpha \\eta + \\beta \\gamma\\}$, $\\phi$ with minimal norm is the\r\ngcd.\r\nIf $\\pi$ is a Gaussian integer with $N(\\pi)=p$ then $\\pi$ is prime.\r\nIf $\\pi$ is a Gaussian prime and $\\pi | \\alpha \\beta$ then $\\pi | \\alpha$ or\r\n$\\pi | \\beta$.\r\nGaussian integers form a UFD.\r\nLet $\\pi$ be a Gaussian prime, there is one and only one $p$ such that\r\n$\\pi | p$.\r\nNote that $\\pi= x + yi$, $N(\\pi)= x^2 + y^2$ divides $p$ or $p^2$ so\r\n$x= 0, 1, 2 \\jmod{4}$.\r\nCharacterization of Gaussian primes: $p=2$:  $p= -i \\pi^2$.\r\n$p=3 \\jmod{4}$, $p=\\pi$.\r\n$p=1 \\jmod{4}$, $p=\\pi {\\overline \\pi}$ and $\\pi$ and\r\n${\\overline \\pi}$ are non-associated primes.\r\nIf $p=1 \\jmod{4}$ then $p \\mid (z^2+1)$.  If $\\pi \\mid p$,\r\n$\\pi | (z+i)(z-i)$ so $\\pi | (z-i)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n$x$ is \\emph{integral} over $A$ if $x$ is a root of a monic polynomial \r\n$f$ with coefficients in $A$.\r\nIf $A$ is a subring of $R$, the \\emph{integral closure} of $A$ in\r\n$R$ is the set $A_c$ of elements of $R$ \r\nthat are integral over $A$. Note that $A \\subseteq A_c$.\r\nWe say $A$ is integrally closed in $R$ if $A_c = A$. \r\nIf $A$ is an integral domain\r\nwith quotient field $K$, and $A$ is integrally closed in $K$\r\nwe simply say\r\nthat $A$ is integrally closed without reference to $R$.\r\n\\\\ \r\n\\\\\r\n{\\bf Theorem:}  Let $M$ be an $A$-module.  $M$ is faithful if \r\n$aM=0 \\rightarrow a=0$.  Let $A \\subseteq B$, $\\alpha \\in B$.  The following are\r\nequivalent: (1) $\\alpha$ is a root of $f(x)=x^n+a_{n-1}x^{n-1}+...+a_0$;\r\n(2) $A[\\alpha]$ is a finitely generated $A$ module; (3) $\\exists$ a faithful\r\nmodule, $N$, over $A[\\alpha]$ which is a finitely generated $A$-module.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$1 \\rightarrow 2$:  $1,x,\\ldots, x^{n-1}$ generate $A[x]$.\r\n$2 \\rightarrow 3$:  $N=A[x]$.\r\n$3 \\rightarrow 1$:  Let $\\beta_1, \\ldots, \\beta_n$ be the generators of $N$.\r\n$x \\beta_i = \\sum_j a_{ij} \\beta_j$ and $det(xI-(a_{ij}))=0$.  This gives the monic equation.\r\n\\end{quote}\r\n{\\bf More trace and norm:}\r\n$N_{E/F}(x)= det(m(x))$, $Tr_{E/F}(x)= trace(m(x))$.\r\nIf $\\alpha= x+yi$, $Tr(\\alpha)= 2x$, $N(\\alpha)= \\alpha {\\overline\r\n\\alpha}$.\r\n$S(\\alpha)= \\sum_{\\sigma} \\alpha^{\\sigma}$ is an integer, so is\r\n$N(\\alpha)= \\prod_{\\sigma} \\alpha^{\\sigma}$. $\\alpha$ is a  unit iff\r\n$|N(\\alpha)| = 1$.\r\n$\\alpha$ is an integer of $Q({\\sqrt d})$ iff $T(\\alpha)$ and $N(\\alpha)$\r\nare integers.\r\n\\\\\r\n\\\\\r\n{\\bf Quadratic integers:}\r\n$I_d= \\{x+y \\omega_d, x,y \\in {\\mathbb Z} \\}$,\r\n$\\omega_d = {\\sqrt d}$ if\r\n$d= 2,3 \\jmod{4}$,\r\n${\\frac { 1+{\\sqrt d}} 2}$, if\r\n$d= 1 \\jmod{4}$.\r\nIdeal Theory:\r\n$P= (2, 1+{\\sqrt {-5}})$,\r\n$Q= (3, 1+{\\sqrt {-5}})$.  $P^2= (2)$ and $Q {\\overline Q}= (3)$.\r\nFermat analogue: $\\alpha^{N(\\pi)-1}= 1 \\jmod{\\pi}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $\\theta$ is an algebraic number,\r\nthere is an integer $m$ such that $m \\theta$ is an algebraic integer.\r\n\\begin{quote}\r\n\\emph{Proof:} We may assume \r\n$a_n \\theta^n + a_{n-1} \\theta^{n-1} + \\ldots + a_0 =0, a_i \\in {\\mathbb Z}$.  Then\r\n$(a_n \\theta)^n + a_{n-1} (a_n \\theta)^{n-1} + \\ldots + (a_n)^{n-1}a_0 =0$.\r\n$a_n \\theta$ is an algebraic integer.\r\n\\end{quote}\r\n{\\bf Notation:} $R(\\theta)$ denotes the ring of algebraic integers in ${\\mathbb Q}(\\theta)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nEvery basis for $R(\\theta)$ has $n$ elements, where $\\theta$ is an algebraic number whose\r\nminimal polynomial has degree $n$.\r\n\\begin{quote}\r\n\\emph{Proof:} Every integral basis is a basis and has the same number of elements.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n) =\r\ndet({\\alpha_i}^{\\sigma_j})^2$, $\\alpha_i \\in R( \\theta )$.\r\nAlternatively,\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n) =\r\ndet(T({\\alpha_i}{\\alpha_j}))$; this follows from the fact that \r\n$T(\\alpha_i \\alpha_j)= \\sum_k \\sigma_k(\\alpha_i \\alpha_j)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n)$ is an integer.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n)$ is an algebraic integer fixed by \r\nall $\\sigma \\in {\\cal G}({\\mathbb Q}(\\theta)/{\\mathbb Q}$ and so it is in ${\\mathbb Q}$.\r\nThe only algebraic integers in ${\\mathbb Q}$ are in ${\\mathbb Z}$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $\\{\\alpha_i\\}$ and $\\{\\beta_i\\}$ are basis with\r\n$\\alpha_j= \\sum_k a_{jk}\\beta_k$ then\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n)= det(a_{ij})^2\r\n\\Delta(\\beta_1, \\beta_2, \\ldots, \\beta_n)$.\r\n\\begin{quote}\r\n\\emph{Proof:} $T( \\beta_r \\beta_s)= T(\\sum_{i,j} a_{r,i} a_{s,j} \\alpha_i \\alpha_j$,\r\nso $(T(\\beta_r \\beta_s ) )= (a_{ij}) T(\\alpha_i \\alpha_j) (a_{ij})^T$.  Taking determinants\r\ngives the result.\r\n\\end{quote}\r\n{\\bf Theorem:}  Suppose $F$ is separable over ${\\mathbb Q}$,\r\n$\\langle \\alpha_i \\rangle$ is a basis iff\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n) \\ne 0$.\r\n\\begin{quote}\r\n\\emph{Proof:} If \r\n$\\sum_j c_j \\alpha_j =0$,\r\n$\\sum_j c_j \\sigma_k(\\alpha_j) =0, \\forall k$ and $B=(\\sigma_i (\\alpha_j))$ has linearly dependent\r\ncolumns so the determinant (discriminant) is $0$.  Suppose \r\n$\\langle \\alpha_1 , \\ldots , \\alpha_n \\rangle$\r\nare a basis and $\\exists c_j$ not all $0$ such that $\\sum_j c_j \\sigma_k(\\alpha_j) = 0$.\r\nIf \r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n)= 0$, the rows of $B$ are linearly dependent so\r\n$\\sum_j c_j \\sigma_k(u) = 0, \\forall u$, which contradicts Artin.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nAll integral bases of $R(\\theta)$ have the same discriminant.\r\n\\begin{quote}\r\n\\emph{Proof:} If \r\n$\\langle \\alpha_1 , \\ldots , \\alpha_n \\rangle$ and\r\n$\\langle \\beta_1 , \\ldots , \\beta_n \\rangle$ are two bases\r\n$\\alpha_j= \\sum_k a_{jk}\\beta_k$ and\r\n$\\beta_j= \\sum_k b_{jk}\\alpha_k$.\r\n$det(a_{ij})^2= det(b_{ij})^2 = 1$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nIf $\\{\\alpha_i\\}$ is an integral basis for $R(\\theta)$ then\r\n$\\Delta(\\alpha_1, \\alpha_2, \\ldots, \\alpha_n)$ is minimal,\r\nin which case it is called the \\emph{discriminant} of $R(\\theta)$ and written\r\n$Disc(R(\\theta))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $A$ is an ideal of $R(\\theta)$ then\r\n${\\mathbb Z} \\cap A \\ne \\emptyset$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSince $A$ is an ideal, $R(\\theta) A \\subseteq A$.\r\nIf $\\alpha \\in A$, $ \\alpha^n + a_{n-1} \\alpha^{n-1} + \\ldots + a_0= 0, a_i \\in {\\mathbb Z}$.\r\n$a_0 \\in {\\mathbb Z} \\cap A$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $D$ is a ring of algebraic integers and $A$ is a module then $D/A$ is finite.\r\n\\begin{quote}\r\n\\emph{Proof:} $\\exists a \\in A \\cap {\\mathbb Z}$.  $(a) \\subseteq A$ so $D/(a) \\rightarrow D/A$ is\r\na homomorphism.  $D= {\\mathbb Z} \\omega_1 + \\ldots + {\\mathbb Z} \\omega_n$.  Let\r\n$S= \\{ \\sum_i \\gamma_i \\omega_i, 0 \\leq \\gamma_i < a \\}$.  $S$ contains all coset representatives\r\nof $D/(a)$.\r\n\\end{quote}\r\n{\\bf Theorem:} $D$ is Noetherian.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSince $D/A_i$ is finite there are only finitely many ideals in $A_1$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery prime ideal in $D$ is maximal.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$D/P$ is a finite integral domain.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet $A \\subseteq D$ be an ideal.  If $\\beta \\in F$ and $\\beta A \\subseteq A$ then\r\n$\\beta \\in D$.\r\n\\begin{quote}\r\n\\emph{Proof:} $A$ is a finitely generated ${\\mathbb Z}$-module.  $\\beta$ satisfies\r\n$a_n B^n+ \\ldots + a_0 = 0, a_i \\in {\\mathbb Z}$.  Multiply by $a_n^{n-1}$ and $a_n \\beta$ is an algebraic\r\ninteger.  $a_i a_n^{-1} \\in {\\mathbb Z}$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A, B$ are ideals in $D$ and $A= AB$ then $B=D$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\alpha_1, \\ldots , \\alpha_n$ be an integral basis for $A$.  $\\exists b_i \\in B:\r\n\\alpha_i = \\sum_j b_{ij} \\alpha_j$.  $det(b_{ij}- \\delta_{ij})= 0$.  So $1 \\in B$ and $D=B$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $\\omega \\in D$ and $( \\omega ) A = B A$ then $( \\omega ) = B$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\beta \\in B$ implies $(\\beta / \\omega ) A \\subseteq A$ so $ \\beta / \\omega \\in D$.\r\n$A= \\omega^{-1} B A$ so $\\omega^{-1} B = D$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery ideal contains a basis.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\beta_1, \\ldots , \\beta_n$ be a basis of $F/{\\mathbb Q}$.  $\\exists a, b \\in {\\mathbb Z}$\r\nsuch that $b \\beta_1, \\ldots , b\\beta_n \\in {\\mathbb Z}$.  Choose $\\alpha \\in A, \\alpha \\neq 0$,\r\n$b\\beta_1 \\alpha , \\ldots , b\\beta_n \\alpha \\in A$ are a basis.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$\\exists M(F): \\alpha , \\beta \\in D, \\beta \\ne 0, 1 \\leq t \\leq M$ and $\\omega \\in D$:\r\n$|N( t \\alpha - \\omega \\beta)| < |N(\\beta)|$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $\\gamma= {\\frac {\\alpha}{\\beta}} \\in F$.  It suffices to show that $\\forall \\gamma \\in F$,\r\nthere is an $M: |N(t \\alpha - \\omega \\beta )|< 1$ for some $1 \\leq t \\leq M$ and $\\omega \\in D$.\r\nLet $ \\omega_1 , \\ldots, \\omega_n $ be an integral basis for $D$.  For $\\gamma \\in F$,\r\n$\\gamma= \\sum_{i=1}^n \\gamma_i \\omega_i, \\gamma_i \\in {\\mathbb Q}$.\r\nNotice that  $|N(\\gamma)|= |\\prod_j (\\sum_i \\gamma_i \\omega_i^{(j)})| \\leq C (max_i |\\gamma_i|)^n$,\r\nwhere $C= \\prod_j ( \\sum_i \\omega_i^{(j)})$.  Choose $m > C^{\\frac 1 n}$ and set $M= m^n$.\r\nFor $\\gamma \\in F, \\gamma= \\sum_i \\gamma_i \\omega_i$, \r\n$\\gamma_i = a_i + b_i, a_i= \\lceil \\gamma_i \\rceil$.  Put $[ \\gamma_i ]= \\sum_i a_i \\omega_i$.\r\nMap $F \\rightarrow {\\mathbb R}^n$ by $\\phi(\\sum_i \\gamma_i \\omega_i)= (\\gamma_1 , \\ldots , \\gamma_n)$.\r\nPartition the $n$-cube into $M=m^n$ subcubes.  \r\nConsider the points $\\phi(\\{k \\gamma\\}), 1 \\leq k \\leq m^n + 1$.\r\nAt least two lie in the same subcube.  Subtracting we get $t \\gamma= \\omega + \\delta$.\r\nThe coordinates of $\\delta$ have absolute value $\\leq {\\frac 1 m}$.  \r\nSo $N(\\delta) \\leq C(1/m)^n= C/m^n<1$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe class number is finite.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $A \\subseteq D$.  For $\\alpha \\in A$ and $\\alpha \\ne 0$, $|N(\\alpha)| \\in {\\mathbb Z}$.\r\nChoose $\\beta \\in A, \\beta \\ne 0: |N(A)|$ is minimal.  $\\forall \\alpha, \\exists t:\r\n|N(t \\alpha - \\omega \\beta )| < |N(\\beta)|, 1 \\leq t \\leq M$.  Since\r\n$t \\alpha - \\omega \\beta \\in A$,\r\n$t \\alpha - \\omega \\beta = 0$.  $B = {\\frac 1 {\\beta}} M! A \\subseteq D$,  $ (M!) \\supseteq (\\beta)B$ so\r\n$(M!) \\subseteq B$.  But $(M!)$ is contained in only finitely many ideals.  So $A \\equiv B$, where\r\n$B$ is one of finitely many ideals.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A, B$ are ideals in $R(\\theta)$, $A|B$ iff $A=BC$ iff $B \\subseteq A$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\exists k: B^k = (\\beta)$.  Since $A \\subseteq B$, $B^{k-1} A \\subseteq (\\beta)$ so\r\n$C= {\\frac 1 {\\beta}} B^{k-1}A \\subseteq D$.  $BC=1$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nIf $A$ is an ideal with basis $\\alpha_i= \\sum_j a_{ij} \\omega_j$ then\r\n$N(A)= det (a_{ij})$.\r\n$A \\sim B$ iff $\\exists \\alpha, \\beta$ such that $(\\alpha)A=(\\beta)B$.\r\neach equivalence class is called an ideal class.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $\\forall A \\subseteq D, \\exists k: 1 \\leq k \\leq h_F$ such that $A^k$ is principal.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nConsider $\\{ a^i : 1 \\leq k \\leq h_F+1 \\} : a^i \\equiv A^j, j>i$.  $\\exists \\alpha , \\beta \\in D:\r\n(\\alpha) A^i= (\\beta) A^j$.  Put $B= A^{j-i}$.  $B$ is principal since\r\n$(\\alpha) A^i = (\\beta) B A^i$.  $( \\alpha / \\beta ) A^i \\subseteq A^i$, so\r\n$\\omega= \\alpha / \\beta \\in D$ then $(\\omega) A^i = B A^i$ and thus $(\\omega)= B$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThere are finitely many ideal classes $h$ of $R(\\theta)$ and $A^h \\sim\r\n(1)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nFor $K=R(\\theta)$, $\\exists C(K): \\forall A, \\exists 0 \\ne \\alpha \\in A:\r\n|N(\\alpha)| \\leq C N(A)$.  Use this to show $\\exists B:N(B) \\leq C$ so there are a finite\r\nnumber of ideals containing $B$. $\\exists \\alpha: (\\alpha)=AD$.  $AN \\sim AD$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A$ is an ideal in $R(\\theta)$, $\\exists B$ such that $AB= (a)$ for some\r\n$a$ in $R(\\theta)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $A, B$ are ideals in $R(\\theta)$,with  $AC=BC$ then $A=B$.\r\n\\begin{quote}\r\n\\emph{Proof:} $\\exists k>0: A^k= (\\alpha)$, so\r\n$A^{k-1}AB = A^{k-1} AC$.  $(\\alpha) B = (\\alpha) C$ and so $B=C$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $P|AB$ and $P$ does not divide $A$ then $P|B$.\r\n\\begin{quote}\r\n\\emph{Proof:} $a \\in A, b \\in B$ $P \\supseteq AB$ but $P \\nsupseteq A$,\r\nso $ab \\in P$.  $\\exists c: ac \\in 1 +P$.  $ac - 1 \\in P$ and\r\n$abc - b \\in P$ but $ab \\in P$ so $b \\in P$ and $P \\supseteq B$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery ideal has finitely many distinct divisors.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery prime ideal must divide the principal ideal of a rational prime.\r\n\\begin{quote}\r\n\\emph{Proof:} Follows from finiteness of class number.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery ideal can be written as a product of prime ideals.  The factorization\r\nis unique apart from order.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $A$ be an ideal.  $D/A$ is finite so $A \\subset P_1$, maximal and\r\n$A= P_1B_1$.  If $B_1 \\neq D$, $B_1$ is contained in a maximal ideal and so on\r\ngiving a chain, $A \\subset B_1 \\subset B_2 \\subset \\ldots$ which must terminate.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery rational integer belongs to finitely many ideals.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nRational prime is \\emph{ramified}\r\n if its principal ideal factors into prime ideals in which one\r\nprime ideal is repeated.  If this happens, $p | \\Delta(\\alpha_1 , \\ldots , \\alpha_n)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThe ring of integers ${\\cal D}_K$ in the number field, $K$, has the following properties:\r\n${\\cal D}_K$ \r\nis a domain with field of fractions $K$.\r\n${\\cal D}_K$ is noetherian (Use the fact that\r\n${\\cal D}_K$  is a free abelian group of degree $n= K:{\\mathbb Q}$.)\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nLet ${\\cal D}$ be a ring of integers, ${\\mathfrak a}$\r\nis a fractional ideal if $\\exists c \\in {\\cal D}$: $c {\\mathfrak a} \\subseteq {\\cal D}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nEvery non zero prime ideal ${\\mathfrak p}$ of ${\\cal D}$ is maximal. (\r\n${\\cal D}/{\\mathfrak a}$ is a finite integral domain.)  Fractional ideals form an abelian\r\ngroup.  \r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nEvery non-zero ideal of\r\n${\\cal D}$ can be factored into prime ideals (${\\cal D}$ is noetherian).\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Norm of an ideal:} \r\n$N({\\mathfrak a})= |{\\mathfrak D}/{\\mathfrak a}|$; if ${\\mathfrak a}= \\langle a \\rangle$ \r\nis principal\r\n$N(a)= N({\\mathfrak a})$. \r\n$N({\\mathfrak a}{\\mathfrak b})= N({\\mathfrak a}) N({\\mathfrak b})$.\r\n$\\Delta_{K/{\\mathbb Q}}(\\alpha_1 , \\alpha_2, \\ldots , \\alpha_n )= \r\n[det(\\sigma_i (\\alpha_j))]^2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nEvery non-zero ideal of ${\\cal D}$ has a finite number\r\nof divisors.  \r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nA non-zero rational integer belongs to a finite number\r\nof ideals of ${\\cal D}$.  \r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nOnly a finite number of ideals of ${\\cal D}$\r\nhave a given norm.  \r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf ${\\mathfrak a} \\ne {\\mathfrak b}$ are ideals of ${\\cal D}$ then\r\n$\\exists \\alpha \\in {\\mathfrak a}: \\alpha {\\mathfrak a}^{-1} + {\\mathfrak b}= {\\cal D}$.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nLet ${\\mathfrak a} \\ne 0$ be an ideal of ${\\cal D}$ and $0 \\ne \\beta \\in {\\mathfrak a},\r\n\\exists \\alpha \\in {\\mathfrak a}: {\\mathfrak a}= \\langle  \\alpha, \\beta \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:} Todo.\r\n\\end{quote}\r\n{\\bf Minkowski:}\r\n$X$ is convex if $x, y \\in X \\rightarrow \\lambda x + (1-\\lambda)y \\in X,\r\n\\forall \\lambda \\in [0,1]$.\r\n$X$ is  symmetric if $x \\in X \\rightarrow -x \\in X$.\r\nLet $L$ be an $n$-dimensional lattice in ${\\mathbb R}^n$ with\r\nfundamental region $T$ and let $X$ be a bounded, convex, symmetric subset of\r\n${\\mathbb R}^n$; if $v(X)> 2^n v(T), \\exists \\alpha \\in X \\cap L, x \\ne 0$.  Let\r\n$L$ be a lattice then ${\\mathbb R}^n/L \\cong T^n$ (a torus).  Let\r\n$T$ be a fundamental region of $L$, $\\phi: T \\rightarrow T^n$ then\r\n$v(X) = v(\\phi^{-1}(X))$.  If $\\nu: {\\mathbb R}^n \\rightarrow T^n$ is the\r\nnatural homomorphism with $ker(\\nu)=L$.  If $X$ is a bounded subset of\r\n${\\mathbb R}^n$, $\\nu$ exists and $v(\\nu(X)) \\ne v(X)$ then $\\nu_{|X}$ is\r\nnot injective.  \\emph{Four squares:} If $p= 4k+1$ then $p=a^2 + b^2$.  \r\n($\\langle g \\rangle = {\\mathbb Z}_p$\r\nis cyclic $g^k=u$ and $u^2= -1$.  Let $L= \\{(a,b): b=ua \\jmod{p} \\}$,\r\n${\\mathbb Z}^2:L= p^2$, $vol(T_L)=p$.  $C_r: \\{ x: ||x||<r \\}$ and $\\pi r^2>4p$,\r\n$r^2= {\\frac {3p} 2}, 0 \\ne a^2 +b^2 \\le r^2 <2p$.\r\n\\\\\r\n\\\\\r\n\\emph{Examples in algebraic fields:} In\r\n$R= {\\mathbb Z}[{\\sqrt {-3}}]$, ${\\frac {-1+{\\sqrt {-3}}} 2}$ is a unit note that\r\n$2 \\times 2 = {-1+{\\sqrt {-3}}} \\times {-1-{\\sqrt {-3}}}$.\r\nIn $R= {\\mathbb Z}[{\\sqrt {-5}}]$ ideals are not all principal; note that\r\n$2 \\times 3 = {-1+{\\sqrt {-5}}} \\times {-1-{\\sqrt {-5}}}$.  \\emph{Pell related:}\r\nThere are two equivalence classes of forms of determinant $5$:   $x^2+5y^2$ and\r\n$2 x^2 + 2xy +3y^2$ and the class number of ${\\mathbb Z} [{\\sqrt {-5}}]$ is $2$.\r\nIf $p$ is a rational prime and $K/ {\\mathbb Q}$ is a Galois extension \r\nthen $G= {\\cal G}(K/{\\mathbb Q})$ acts transitively on the ideal divisors of $(p)$,\r\nthe exponent of the ideal divisors are called the ramification index.  The ideal generated\r\nby a rational ideal $(p)$ factors into indecomposable factors\r\nin an algebraic number field, $O_F$, in one of\r\nthree ways: (a) $(p)$, (b) $(p)= P \\sigma(P)$ (``$p$ splits''), or (c)\r\n$(p)= P^2$ (``$p$ ramifies'').\r\n\\\\\r\n\\\\\r\n{\\bf Analytic formulas:} $f*g(n)= \\sum_{d|n} f(d)g({\\frac n d})$.  \r\nThis is commutative, associative and has an inverse.\r\n$\\Lambda(n)= ln(n)$, if $n= p^m$,\r\n$\\Lambda(n)= 0$, otherwise.  Note: $ln(n)= \\sum_{d|n} \\Lambda(d)$.\r\n$\\sigma_{\\alpha}(n)= \\sum_{d|n} d^{\\alpha}$.\r\n$\\psi(x)= \\sum_{n \\leq x} \\Lambda(n)$,\r\n$\\vartheta(x)= \\sum_{p \\leq x} ln(p)$.\r\n${\\frac {\\psi(x)} {x}} -\r\n{\\frac {\\vartheta(x)} {x}} \\leq {\\frac {ln(x)^2} {2 {\\sqrt x} ln(2)}}$.\r\n$L(1,\\chi)= \\sum_{n=1}^{\\infty} {\\frac {\\chi(n)} n}$, $\\chi$, a\r\nnon-principal character.\r\n{\\bf Dirichlet:}  If $k>0$ and $(h,k)=1$, $\\forall x>1$\r\n$\\sum_{p \\leq x, p=h \\jmod{k}} {\\frac {ln(p)} p}=\r\n{\\frac 1 {\\phi(k)}} ln(x) + O(1)$.\r\n$\\pi_a (x)= \\sum_{p \\leq x, p=a \\; \\jmod{k}} 1$.\r\n$\\pi_a (x) \\approx {\\frac {\\pi(x)} {\\phi(k)}}$, $x \\rightarrow 0$,\r\n$\\forall a$, $(a, k)=1$ and $\\pi_a (x) \\approx \\pi_b (x)$ when\r\n$(a,k)=(b,k)=1$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A \\emph{Lie algebra} is a vector space, $V$ over a field, $F$ with an operation\r\n$[,]: V \\times V \\rightarrow V$ which is alternating and bilinear and which satisfies the Jacobi\r\nidentity: $[x,[y,z]] + [y,[z,x]] + [z, [x,y]]= 0$.  If $A$ is an associative algebra, there is\r\na corresponding Lie algebra with $[a,b]= a*b-b*a$, called an \\emph{enveloping algebra}.\r\n\\emph{Example:} $n \\times n$ matricies over $F$ give rise to $L_n(F)$.  ${\\mathbb R}^3$ with\r\n$[a, b]= a \\times b$ is a Lie algebra.\r\n\r\n", "meta": {"hexsha": "0cded0e954b5635f830262d588ae40ccb26a31bb", "size": 150975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math2.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/math2.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/math2.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.6091854419, "max_line_length": 149, "alphanum_fraction": 0.5997880444, "num_tokens": 60530, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632916317103, "lm_q2_score": 0.833324587033253, "lm_q1q2_score": 0.7727946320287931}}
{"text": "\n\\subsection{Identifying primes}\n\ndifferent to factorising. We don't care what the actual factors are, just see if it's prime\n\n\\subsection{Fermat's primality test}\n\n\\subsubsection{Fermat's little theorem recap}\n\n\\subsubsection{Fermat's primality test}\n\nFrom Fermat's little theorem we know\n\n\\(a^{n-1}=1 mod(n)\\)\n\nWhere \\(a\\) is an integer and \\(n\\) is prime.\n\n", "meta": {"hexsha": "466a4b3ae1b2e8ffb7533701260748d655a82b89", "size": 360, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/primes/01-01-fermatPrimality.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/primes/01-01-fermatPrimality.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/primes/01-01-fermatPrimality.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.0, "max_line_length": 91, "alphanum_fraction": 0.7388888889, "num_tokens": 100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067195846918, "lm_q2_score": 0.8198933403143929, "lm_q1q2_score": 0.7727549825890537}}
{"text": "\n\\subsection{Topologies}\n\n\\subsection{Topologies on sets}\n\n\\(T\\) is a topology on set \\(X\\) if:\n\n\\begin{itemize}\n\\item \\(X\\in T\\)\n\\item \\(\\varnothing \\in T\\)\n\\item Unions of \\(T\\) are in \\(T\\)\n\\item Intersections of \\(T\\) are in \\(T\\)\n\\end{itemize}\n\n\n\\subsection{Examples of topologies: The trivial topology}\n\nThe trivial topology contains only the underlying set and the empty set.\n\n\\subsection{Examples of topologies: The discrete toplogy}\n\nThe discrete toplogy contains all subsets of the underlying set (is this the power set?)\n\n", "meta": {"hexsha": "c63d4d65f701f0264dbd5a90cbe2953828d96b5f", "size": 533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/topologyFinite/01-01-topology.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-01-topology.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-01-topology.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.2083333333, "max_line_length": 88, "alphanum_fraction": 0.722326454, "num_tokens": 144, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9425067147399244, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.7727549661733496}}
{"text": "%!TEX root = RBM.tex\n\n\\subsubsection{Thouless-Anderson-Palmer Sampling\\protect\\footnote{Available at \\protect\\url{https://github.com/lzhbrian/MCMC/blob/master/src/partition/TAP.m} in Matlab}}\n\n\\para{Algorithm}\nThouless-Anderson-Palmer Sampling(TAP)\\cite{gabrie2015training} is a very efficient and easy-to-practice iterative procedure based on an improved mean field method from statistical physics called Thouless-Anderson-Palmer approach.\n\nThe main idea of this method is to iteratively compute the magnetization vector $m^{v}$,$m^{h}$, and then input the values into the Legendre transform of the free energy $F=log(Z(\\theta))$ to compute it.\n\nThe iteration of $m^{v}$ and $m^{h}$ follows:\n\\begin{equation}\n\\begin{aligned}\nm^{h}_{j}{[t+1]} & = sigmoid\\Bigg[b_{j} + \\sum_{i}W_{ij}m^{v}_{i}{[t]} - \\\\\n& W^{2}_{ij} \\Bigg(m^{h}_{j}{[t] - \\frac{1}{2}} \\Bigg) \\Big(m^{v}_{i}{[t]}-(m^{v}_{i}{[t]})^{2} \\Big) \\Bigg] \\\\ \nm^{h}_{i}{[t+1]} & = sigmoid\\Bigg[a_{i} + \\sum_{j}W_{ij}m^{h}_{j}{[t+1]} - \\\\\n& W^{2}_{ij} \\Bigg(m^{v}_{i}{[t] - \\frac{1}{2}} \\Bigg) \\Big(m^{h}_{j}{[t+1]}-(m^{h}_{j}{[t+1]})^{2} \\Big) \\Bigg]\n\\end{aligned}\n\\end{equation}\n\nThe Legendre transform of $F$ to the second order is:\n\\begin{equation}\n\\begin{split}\n\\Gamma(\\mathbf m^{v},\\mathbf m^{h}) &\\approx - S(\\mathbf m^{v},\\mathbf m^{h}) - \\sum_{i} a_{i}m^{v}_{i} - \\sum_{j} b_{j}m^{h}_{j} \\\\\n& - \\sum_{i,j} \\Bigg( W_{i,j}m^{v}_{i}m^{h}_{j} \\\\\n& - 0.5W_{ij}\\Big(m^{v}_{i}-(m^{v}_{i})^2\\Big)\\Big(m^{h}_{j}-(m^{h}_{j})^2\\Big) \\Bigg)\n\\end{split}\n\\end{equation}\nwhere $S(\\mathbf m^{v},\\mathbf m^{h})$ indicates the entropy:\n\\begin{equation}\n\\begin{split}\nS(\\mathbf m^{v},\\mathbf m^{h}) &= - \\sum_{i} \\Bigg(m^{v}_{i}logm^{v}_{i} + (1-m^{v}_{i})log(1-m^{v}_{i}) \\Bigg) \\\\\n&- \\sum_{j} \\Bigg(m^{h}_{j}logm^{h}_{j} + (1-m^{h}_{j})log(1-m^{h}_{j}) \\Bigg)\n\\end{split}\n\\end{equation}\n\n\\para{Practice}\nFor real practice, in the next subsection, we see TAP method can obtain a converged result in a very short time, but has less accuracy. And sometimes, the converged results are periodic, which is not what we want by us.\n\n\t\\begin{algorithm}\n        \\caption{Thouless-Anderson-Palmer Sampling}\n        \\begin{algorithmic}\n        \t\\Require Required Iteration time $N$, \n        \t\\State Initialize $m^{v}$, $m^{h}$ \n            \\For{$t = 1 \\to N$}\n            \t\\State $m^{h}{[t+1]} \\gets f(m^{h}{[t]})$\n            \t\\State $m^{v}{[t+1]} \\gets f(m^{v}{[t]},m^{v}{[t+1]})$\n\t\t\t\\EndFor\n\t\t\t\\State $logZ(\\theta) \\gets \\Gamma(\\mathbf m^{v},\\mathbf m^{h})$\n        \\end{algorithmic}\n    \\end{algorithm}\n", "meta": {"hexsha": "3f1b8f0ac6943543fb4ba8aca3df3495ed5c4b5a", "size": 2542, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/TAP.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/TAP.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/TAP.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": 49.8431372549, "max_line_length": 230, "alphanum_fraction": 0.6105428796, "num_tokens": 989, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9372107896491796, "lm_q2_score": 0.8244619242200082, "lm_q1q2_score": 0.7726946110339159}}
{"text": "\\section*{Statistics}\n\\begin{itemize}\n\\item [mean:] $\\mu = (1/N) \\sum_{i=1}^N x_i$\n\\item [variance:] $\\sigma^2 = (1/N) \\sum_{i=1}^N (x_i-\\mu)^2$\n\\item [standard deviation:] $\\sigma = \\sqrt{\\sigma^2}$\n\\end{itemize}\n\n\\subsection*{Probability}\nProbability of\n\\begin{itemize}\n\\item [$A$:] $P(A) \\in [0,1]$\n\\item [$\\neg A$:] $P(\\neg A) = 1 - P(A)$\n\\item [$A$ given $B$:] $P(A\\vert B) $\n\\item [$A$ or $B$:] $P(A\\cup B) = P(A) + P(B) - P(A\\cap B)$\n\\begin{itemize}\n  \\item[if $A$ is indep. of $B$] $P(A\\cup B) = P(A) + P(B)$\n\\end{itemize}\n\\item [$A$ and $B$:] $P(A\\cap B) = P(A\\vert B)P(B)$\n\\begin{itemize}\n  \\item[if $A$ is indep. of $B$] $P(A\\cap B) = P(A)P(B)$\n\\end{itemize}\n\\item $P(x) := Pr[X = x] := \\sum_{y \\in Y} P(x, y)$\n\\item $P(x|y) := Pr[X = x | Y = y] := \\frac{P(x,y)}{P(y)},\\quad \\text{if } P(y) > 0$\n\\item $\\forall y \\in Y: \\sum_{x \\in X} P(x|y) = 1$ (property for any fixed $y$)\n\\item $P(x, y) = P(x|y) P(y)$\n\\item $P(x|y) = \\frac{P(y|x)P(x)}{P(y)}$ (Bayes' rule)\n\\item $P(x|y) = P(x) \\Leftrightarrow P(y|x) = P(y)$ (iff $X$, $Y$ independent)\n\\item $P(x_1, \\ldots, x_n) = \\prod_{i=1}^n P(x_i)$ (iff IID)\n\\end{itemize}\n", "meta": {"hexsha": "5019a3ae0da11223bdbaa06a77ebb3a63dacb5be", "size": 1126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CheatSheets/Series/Mathematics/units/unit_Probability.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_Probability.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_Probability.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": 37.5333333333, "max_line_length": 84, "alphanum_fraction": 0.5293072824, "num_tokens": 542, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9532750400464604, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7726093141195132}}
{"text": "\\chapter{Support Vector Machines}\nSuper Vegetable Me\n\\newpage\n\n\n\\section{Max Margin Classifiers}\n    The goal is to find an \\emph{optimal} separating hyperplane $w^Tx+b = 0$ such that the margin between different classes is \\emph{maximized}. In the following section we assume the data are linear separable.\n\n    \\subsection{Notations}\n        \\begin{itemize}\n            \\item $x^{(i)}$: $i$-th sample\n            \\item $y^{(i)} \\in \\{1, -1\\}$: $i$-th label\n        \\end{itemize}\n\n    \\subsection{Basic Problem Formulation}\n        \\begin{itemize}\n            \\item $w^Tx + b = 0$ is the separating hyperplane\n            \\item For $x$ on the hyperplane, $w^Tx + b = 0$\n            \\item For $x$ on the upper boarder of the margin, $w^Tx+b = 1$, this can always be satisfied by scaling $w$ and $b$\n            \\item For $x$ on the lower boarder of the margin , $w^Tx+b = -1$\n            \\item For $x$ with label $y=1$, we want $w^Tx+b\\ge1$\n            \\item For $x$ with label $y=-1$, we want $w^Tx+b\\le1$\n        \\end{itemize}\n        Let $h(x) = w^Tx + b$. For $x$ with $y=1$, we want $h(x) \\ge 1$, and conversely for $x$ with $y=-1$, we want $h(x) \\le -1$. Or in a compact way, for all $x$, we want\n        \\[ y(w^Tx + b) \\ge 1 \\]\n\n    \\subsection{Formulation into an Optimization Problem}\n        Let $w_o^Tx+b_o=0$ be the optimal separating hyperplane, with normal vector $\\frac{w_o}{\\|w_o\\|}$.\n        \\begin{enumerate}\n            \\item For any $x$, let $x_p$ be the point on $w_o^Tx+b=0$ s.t. $x - x_p$ is perpendicular to $w_o^Tx+b_o=0$\n            \\item $x = x_p + r\\left(\\frac{w_o}{\\|w_o\\|}\\right)$, where $r$ is a scaling factor\n            \\item $h(x_p) = w_o^Tx_p + b_o = 0$\n            \\item $w_o^Tx_p = -b_o$\n            \\item $h(x) = w_o^Tx + b_o = w_o^T\\left(x_p + r\\left(\\frac{w_o}{\\|w_o\\|}\\right)\\right) + b_o = w_o^Tx_p + r\\left(\\frac{w_o^Tw_o}{\\|w_o\\|}\\right) + b_o = r\\|w_o\\|$\n            \\item For a support vector $x^{(s)}$, $|r| = h(x^{(s)})/\\|w_o\\| = 1/\\|w_o\\|$\n            \\item So the margin of separation is $2r = 2/\\|w_o\\|$\n            \\item Maximizing $1/\\|w\\|$ is equivalent to minimizing $\\|w\\|^2 = w^Tw$\n        \\end{enumerate}\n        Therefore\n        \\begin{align*}\n            \\min \\quad &\\frac{1}{2}w^Tw\\\\\n            \\text{s.t.} \\quad & y^{(i)}(w^Tx^{(i)}+b) \\ge 1\n        \\end{align*}\n\n\n\\section{Dual Formulation of SVM}\n    \\subsection{Lagrangian and KKT Conditions of Hard-Margin SVM}\n        We consider the minimization problem:\n        \\begin{align*}\n             \\min \\quad &\\frac{1}{2}w^Tw\\\\\n             \\text{s.t.} \\quad & y^{(i)}(w^Tx^{(i)}+b) \\ge 1\n        \\end{align*}\n        Let $\\alpha_i$ be the Lagrangian Multipliers, then the Lagrangian is\n        \\[ \\mathcal{L}(w,b,\\alpha) = \\frac{1}{2}w^Tw - \\sum_{i=1}^N \\alpha_i (y^{(i)}(w^Tx^{(i)} + b) - 1) \\]\n        The KKT Conditions are\n        \\[\n        \\begin{cases}\n            \\nabla_w \\mathcal{L} = w - \\sum_{i=1}^N \\alpha_i y^{(i)}x^{(i)} = 0\\\\\n            \\nabla_b \\mathcal{L} = \\sum_{i=1}^N \\alpha_i y^{(i)} = 0\\\\\n            y^{(i)}(w^Tx^{(i)} + b) \\ge 1\\\\\n            \\alpha_i \\ge 0\\\\\n            \\alpha_i(y^{(i)}(w^Tx^{(i)} + b) - 1) =0\n        \\end{cases}    \n        \\]\n        \\begin{remark}~{}\n            \\begin{itemize}\n                \\item If $\\alpha_i > 0$, $x^{(i)}$ lies on the decision margin and corresponds to a support vector.\n                \\item If $\\alpha_i = 0$, $x^{(i)}$ does not lie on the decision margin.\n            \\end{itemize}\n        \\end{remark}\n\n    \\subsection{Dual Formulation of SVM}\n        Notice that $w$ can be represented by $\\alpha_i$ and $x^{(i)}$\n        \\[ w = \\sum_{i=1}^N \\alpha_i y^{(i)}x^{(i)} \\]\n        We can derive the dual problem of SVM from the Lagrangian,\n        \\begin{align*}\n            \\mathcal{L}(w,b,\\alpha) &= \\frac{1}{2}w^Tw - \\sum_{i=1}^N \\alpha_i y^{(i)}(w^Tx^{(i)} + b - 1)\\\\\n            &= \\frac{1}{2}w^Tw - \\sum_{i=1}^N \\alpha_i y^{(i)}w^Tx^{(i)} -b\\sum_{i=1}^N \\alpha_i y^{(i)} + \\sum_{i=1}^N \\alpha_i\n        \\end{align*}\n        Using the KKT conditions and substitute $w$, we can replace the term $w^Tw$ by\n        \\[ w^Tw = \\left(\\sum_{i=1}^N \\alpha_i y^{(i)}x^{(i)}\\right)^T\\left(\\sum_{i=1}^N \\alpha_i y^{(i)}x^{(i)}\\right) = \\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} x^{(i)T}x^{(j)} \\]\n        and similarly the second term can be replaced by\n        \\[ -\\sum_{i=1}^N \\alpha_iy^{(i)}w^Tx^{(i)} = -\\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} x^{(i)T}x^{(j)} \\]\n        Therefore the Lagrangian dual function is\n        \\[ \\phi(\\alpha) = \\sum_{i=1}^N\\alpha_i - \\frac{1}{2}\\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} x^{(i)T}x^{(j)} \\]\n        So we derived the dual problem of hard-margin SVM\n        \\begin{align*}\n            \\max \\quad &\\phi(\\alpha) = \\sum_{i=1}^N\\alpha_i - \\frac{1}{2}\\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} x^{(i)T}x^{(j)}\\\\\n            \\text{s.t.} \\quad & \\sum_{i=1}^N \\alpha_i y^{(i)} = 0\\\\\n            \\quad & \\alpha_i \\ge 0\n        \\end{align*}\n        \\begin{remark}\n            This problem an be solved efficiently (by computers) using the SMO algorithm.\n        \\end{remark}\n\n\n\\section{Soft Margin SVM}\n    \\subsection{Slac Variables}\n        If the data is not linear separable, we can introduce slack variables $\\xi_i$.\n\n        So the primal problem is\n        \\begin{align*}\n            \\min \\quad & \\frac{1}{2}w^Tw + C\\sum_{i=1}^N\\xi_i\\\\\n            \\text{s.t.} \\quad &y^{(i)}(w^Tx^{(i)} + b) \\ge 1 - \\xi_i\\\\\n            \\quad & \\xi_i \\ge 0\n        \\end{align*}\n        where $C$ is a user-defined hyperparameter.\n        \\begin{remark}\n            $\\xi_i$ implies the location of $x^{(i)}$\n            \\begin{itemize}\n                \\item $\\xi_i = 0$: Data point outside region of separation and correcty separated.\n                \\item $0 < \\xi_i \\le 1$: Data point inside region of separation but on the correct side of hyperplane.\n                \\item $\\xi_i > 1$: Data point inside region of separation and on the wrong side of hyperplane.\n            \\end{itemize}\n            The choice of $C$ is  related to the performance of the model\n            \\begin{itemize}\n                \\item Large $C$: hard to train, but likely to have high performance\n                \\item Small $C$: easy to train, but likely to have poor performance\n            \\end{itemize}\n        \\end{remark}\n    \n    \\subsection{Dual Formulation}\n    The Lagrangian is\n    \\[ \\mathcal{L}(w,b,\\xi,\\alpha,\\beta) = \\frac{1}{2}w^Tw + C\\sum_{i}\\xi_i - \\sum_i \\alpha_i(y^{(i)}(w^Tx^{(i)})-1+\\xi_i) - \\sum_i \\beta_i\\xi_i \\]\n    and the KKT Conditions are\n    \\[\n    \\begin{cases}\n        \\nabla_w\\mathcal{L} = 0, \\quad \\nabla_b\\mathcal{L} = 0, \\quad \\nabla_{\\xi_i}\\mathcal{L} = 0\\\\\n        (y^{(i)}(w^Tx^{(i)})-1+\\xi_i) \\ge 1-\\xi_i, \\quad \\xi_i \\ge 0\\\\\n        \\alpha_i(y^{(i)}(w^Tx^{(i)})-1+\\xi_i) = 0, \\quad \\beta_i\\xi_i = 0\n    \\end{cases}    \n    \\]\n    Notice that the introduction of $\\xi_i$ doesn't affect the expression of $\\nabla_w\\mathcal{L}$ and $\\nabla_b\\mathcal{L}$, and therefore\n    \\[ w = \\sum_i \\alpha_iy^{(i)}x^{(i)} \\]\n    \\[ \\sum_i \\alpha_i y^{(i)} = 0 \\]\n    still hold.\n\n    In addition we now have\n    \\[ \\nabla_{\\xi_i}\\mathcal{L} = C - \\alpha_i - \\beta_i = 0 \\]\n\n    After some algebra\n    \\begin{align*}\n        \\phi(\\alpha, \\beta) &= \\inf\\mathcal{L} = \\frac{1}{2}w^Tw - \\sum_i \\alpha_i(y^{(i)}(w^Tx^{(i)})-1)\n    \\end{align*}\n\n    Notice that $\\alpha_i + \\beta_i = C$ can be replaced by $\\alpha_i \\le C$, therefore\n    \\begin{align*}\n        \\max \\quad &\\phi(\\alpha) = \\sum_{i=1}^N\\alpha_i - \\frac{1}{2}\\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} x^{(i)T}x^{(j)}\\\\\n        \\text{s.t.} \\quad & \\sum_{i=1}^N \\alpha_i y^{(i)} = 0\\\\\n        \\quad & 0 \\le \\alpha_i \\le C\n    \\end{align*}\n\n\n\\section{Kernel Tricks}\n    If the data is not linear separable, we can transform data into higher dimension for separation. As long as the mapping is non-linear and the target dimension is high enough, we can always make the data linear separable.\n\n    Suppose we want to find a function $\\varphi(x)$ that maps $x$ into a higher dimension. So the decision hyperplane becomes\n    \\[ y = w^T\\varphi(x) + b \\]\n    where $\\varphi(\\cdot)$ is called the kernel function.\n    The mathematical framework does not change, and all we have to do is to replace $x$ with $\\varphi(x)$ in all previous derivations.\n    \\[ w = \\sum_i \\alpha_i y^{(i)}\\varphi(x^{(i)}) \\]\n    \\[ \\phi(\\alpha) = \\sum_{i=1}^N\\alpha_i - \\frac{1}{2}\\sum_{i=1}^N\\sum_{j=1}^N \\alpha_i\\alpha_j y^{(i)}y^{(j)} \\varphi^T(x^{(i)})\\varphi(x^{(j)}) \\]\n\n    While it is sometimes hard to determin $\\varphi(\\cdot)$, it is usually easier to define ``result'' of the inner product $\\varphi^T(x)\\varphi(x)$, denoted by $K(x_i, x_j)$ For example\n    \\[ K(x_i, x_j) = \\varphi^T(x)\\varphi(x) = \\exp\\left\\{ -\\frac{\\|x_i-x_j\\|^2}{\\sigma^2} \\right\\} \\]\n\n    Notice that in the dual problem, all terms related with $x$ comes in pairs $(x_i,x_j)$, so we can always replace the pair with $K(x_i,x_j)$\n\n    \\begin{remark}\n        Although\n        \\[ w = \\sum_i \\alpha_i y^{(i)}\\varphi(x^{(i)}) \\]\n        notice that $w$ is used to compute $w^T \\varphi(x)$, and therefore\n        \\[ y = w^T\\varphi(x) + b = \\sum_i \\alpha_i y^{(i)}\\varphi^T(x^{(i)})\\varphi(x) = \\sum_i \\alpha_i y^{(i)} K(x^{(i)}, x) + b \\]\n        However this operation increases complexity. \\textbf{EXPENSIVE!}\n    \\end{remark}\n\n    \\begin{remark}\n        Not all functions can be used as kernels, a kernel matrix $K$ must satisfy the \\textbf{Mercer's Condition}: $K$ is positive semi-definite.\n    \\end{remark}\n", "meta": {"hexsha": "4c3d35f0059df0b39aa089efab5f7aa472a00f21", "size": 9604, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/SupportVectorMachine.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Machine Learning/SupportVectorMachine.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Machine Learning/SupportVectorMachine.tex", "max_forks_repo_name": "YBRua/CourseNotes", "max_forks_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-12-14T11:31:00.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-14T11:31:00.000Z", "avg_line_length": 53.3555555556, "max_line_length": 224, "alphanum_fraction": 0.552790504, "num_tokens": 3507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7724926371542767}}
{"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{bm}\n\n\\geometry{left=3cm,right=3cm,top=3cm,bottom=3cm}\n\\DeclareMathOperator*{\\argmin}{argmin}\n\\DeclareMathOperator*{\\argmax}{argmax}\n\\DeclareMathOperator*{\\var}{var}\n\\DeclareMathOperator*{\\expec}{E}\n\n\\begin{document}\n\\title{\\textsf{Homework 3 for Pattern Recognition}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 1}\n{\n    \\[\n    \\begin{split}\n        &   \\frac{\\partial}{\\partial \\hat{\\theta}} R(\\hat{\\theta} | \\bm{X}) \\\\\n        =&  \\frac{\\partial}{\\partial \\hat{\\theta}} \\int_{\\theta} {(\\hat{\\theta}-\\theta)^2 p(\\theta | \\bm{X}) \\mathrm{d}\\theta} \\\\\n        =&  \\int_{\\theta} {\\frac{\\partial}{\\partial \\hat{\\theta}} (\\hat{\\theta}-\\theta)^2 p(\\theta | \\bm{X}) \\mathrm{d}\\theta} \\\\\n        =&  \\int_{\\theta} {2 (\\hat{\\theta}-\\theta) p(\\theta | \\bm{X}) \\mathrm{d}\\theta} \\\\\n        =&  \\int_{\\theta} {2 \\hat{\\theta} p(\\theta | \\bm{X}) \\mathrm{d}\\theta} - \\int_{\\theta} {2 \\theta p(\\theta | \\bm{X}) \\mathrm{d}\\theta} \\\\\n        =&  \\hat{\\theta} \\cdot \\int_{\\theta} {2 p(\\theta | \\bm{X}) \\mathrm{d}\\theta} - \\int_{\\theta} {2 \\theta p(\\theta | \\bm{X}) \\mathrm{d}\\theta} \\\\\n        =&  \\hat{\\theta} \\cdot 2 - \\int_{\\theta} {2 \\theta p(\\theta | \\bm{X}) \\mathrm{d}\\theta} = 0.\n    \\end{split}\n    \\]\n\n    The solution to the equation above is $$\\hat{\\theta} = \\int_{\\theta} {\\theta p(\\theta | \\bm{X}) \\mathrm{d}\\theta}.$$\n\n    Note that $$\\frac{\\partial^2}{\\partial \\hat{\\theta}^2} R(\\hat{\\theta} | \\bm{X}) = 2 > 0,$$ which means the solution above is the global minimum for $\\hat{\\theta}$. Thus, we have $$\\theta^{*} = \\int_{\\theta} {\\theta p(\\theta | \\bm{X}) \\mathrm{d}\\theta}.$$\n\n}\n\n\\section*{Question 2}\n{\n    \\subsection*{(1)}\n    {\n        To put it simply, the MLE (maximum likelihood estimation) is a specific branch of Bayesian estimation. Let's review each of them before reaching this conclusion.\n\n        \\begin{itemize}\n            \\item \\textbf{Bayesian estimate} \\quad A prior distribution for the parameter $\\theta$ is required, and we can get the posterior distribution for $\\theta$, rather than the estimator alone. This means it provides us with more knowledge about the posterior distribution of the paramter. We can use multiple ways to make the point estimate, such as using the mean, median, or the mode of the posterior distribution as an estimator for the parameter. However, the prior distribution is a bit subjective, and we have to use some carefully designed priors (such as \\emph{conjugate prior family} and \\emph{noninformative priors}) to prevent arbitrariness.\n\n            \\item \\textbf{the Maximum likelihood estimate (MLE)} \\quad It maximizes the likelihood only, which means we have a prior distribution proportional to constant in the Bayesian formula $p(\\theta|x) \\propto p(\\theta)p(x|\\theta)$. Instead of estimating the posterior distribution for $\\theta$, we obtain only one estimate of it, i.e. the maximum likelihood estimate. It is equivalent to the Bayesian method if the prior distribution is uniform, and we use the mode of the posterior in Bayesian method. \n\n        \\end{itemize}\n    }\n\n    \\subsection*{(2)}\n    {\n        \\[\n        \\begin{split}\n                &   \\frac{\\partial}{\\partial \\mu} \\log{(p(\\mu | \\sigma^2, X_1, \\cdots, X_n))} \\\\\n                =&  \\frac{\\partial}{\\partial \\mu} \\left[ -\\frac{n}{2} \\log{(2\\pi)} - \\frac{n}{2} \\log{(\\sigma^2)} - \\sum_{i=1}^{n} {\\frac{(X_i - \\mu)^2}{2\\sigma^2}} \\right] \\\\\n                =&  \\frac{1}{2\\sigma^2} \\sum_{i=1}^{n} {\\frac{\\partial}{\\partial \\mu} (X_i - \\mu)^2} = \\frac{1}{2\\sigma^2} \\sum_{i=1}^{n} {\\left[ 2 (X_i - \\mu) \\right]} \\\\\n                =&  \\frac{1}{\\sigma^2} \\left[ \\sum_{i=1}^{n} {X_i} - n \\mu \\right] = 0.\n        \\end{split}\n        \\]\n\n        The solution is $$\\mu = \\frac{1}{n} \\sum_{i=1}^{n} X_i = \\bar{X}.$$\n\n        Note that $$\\frac{\\partial^2}{\\partial \\mu^2} \\log{(p(\\mu | \\sigma^2, X_1, \\cdots, X_n))} = - \\frac{n}{\\sigma^2} < 0,$$ we have $\\mu = \\bar{X}$ is the global maximizer of the log likelihood of $\\mu$ given $\\sigma^2$ and $X_1, \\cdots, X_n$.\n\n        Given that $\\mu > \\mu_0$, the maximum likelihood estimate of $\\mu$ is $\\max{(\\mu_0, \\bar{X})}$.\n    }\n\n    \\subsection*{(3)}\n    {\n        From $$\\frac{\\partial}{\\partial \\sigma^2} \\log{(p(\\mu | \\sigma^2, X_1, \\cdots, X_n))} = \\frac{\\partial}{\\partial \\sigma^2} \\left[ -\\frac{n}{2} \\log{(2\\pi)} - \\frac{n}{2} \\log{(\\sigma^2)} - \\sum_{i=1}^{n} {\\frac{(X_i - \\mu)^2}{2\\sigma^2}} \\right] $$$$= -\\frac{n}{2\\sigma^2} + \\frac{1}{2(\\sigma^2)^2} \\sum_{i=1}^{n} {(X_i -\\mu)^2} = 0,$$\n        and $$\\frac{\\partial^2}{\\partial (\\sigma^2)^2} \\log{(p(\\mu | \\sigma^2, X_1, \\cdots, X_n))} = \\frac{n}{2\\sigma^6}(\\sigma^2 - 2 S^2) < 0,$$ we get the maximum likelihood estimate for $\\sigma^2$, that is \n        $$\\hat{\\sigma}^2 = S^2 = \\frac{1}{n} \\sum_{i=1}^{n} {(X_i - \\bar{X})^2}.$$\n\n        Below are the density plots with estimated parameters:\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{normal_10.png}\n            \\includegraphics[width = 0.6\\linewidth]{normal_100.png}\n            \\includegraphics[width = 0.6\\linewidth]{normal_1000.png}\n            \\caption{Density plots with estimated parameters for normal samples}\n        \\end{figure}\n    }\n\n    \\subsection*{(4)}\n    {\n        Below are the density plot with estimated parameters for uniform samples:\n\n        \\begin{figure}[H]\n            \\centering\n            \\includegraphics[width = 0.6\\linewidth]{uniform_100.png}\n            \\caption{Density plot with estimated parameters for uniform samples}\n        \\end{figure}\n    }\n\n    \\subsection*{(5)}\n    {\n        \\begin{itemize}\n            \\item \\textbf{Model selection} \\quad A good prior model is essential to the MLE. The selected model should be of the distribution family that is similar to that of the data samples. By contrast, we see the normal model is not successful in subsection (4), where the sample is drawn from a distribution different from our normal model.\n\n            \\item \\textbf{Sample size} \\quad We find in subsection (3) that the larger the sample size, the more accurate the estimated distribution. From the Bayesian perspective, a larger sample size means more weight put on the observed data, than that on the prior knowledge. Although it is not exactly precise an interpretation here (as we do not have a prior distribution for the normal likelihood), it is obvious that more observations contribute to the model accuracy, if the model is reasonable.\n\n        \\end{itemize}\n    }\n}\n\n\\section*{Source Code}\n{\n    Please download the souece code from http://39.106.23.58/files/PR3\\_2015011506.7z\n}\n\n\\clearpage\n\\end{document}\n    ", "meta": {"hexsha": "1e1e6cea6a99e3b73b30f8ee6312ae8825064c92", "size": 6892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW3/Homework3.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": "HW3/Homework3.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": "HW3/Homework3.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": 56.0325203252, "max_line_length": 660, "alphanum_fraction": 0.6313116657, "num_tokens": 2162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297967961707, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7724457372849746}}
{"text": "\\chapter{Common Polynomial Products}\n\nIn math and physics, you will run into certain kinds of polynomials\nover and over again. In this chapter, I am going to cover some\npatterns that you will want to start to recognize.\n\n\\section{Difference of squares}\n\nWatch \\textbf{Polynomial special products: difference of squares} from Khan Academy at \\url{https://youtu.be/uNweU6I4Icw}.\n\nIf you are asked what is $(3x - 7)(3x + 7)$, you would use the\ndistributive property to expand that to $(3x)(3x) + (3x)(7) + (-7)(3x) + (-7)(7)$.\nTwo of the terms cancel each other, so this is $(3x)^2 - (7)^2$. This would simplify to $9x^2 - 49$\n\nYou will see this pattern a lot. Anytime you see $(a + b)(a - b)$, you should immediately\nrecognize it equals $a^2 - b^2$. (Note that the order doesn't matter: $(a - b)(a + b)$ also $a^2 - b^2$.)\n\nWorking the other way is important too: anytime you see $a^2 - b^2$,\nthat you should recognize that you can change that into the product\n$(a + b)(a - b)$. Making something into a product like this is known as\n\\emph{factoring}. You probably have done prime factorization of\nnumbers like $42 = 2 \\times 3 \\times 7$. In the next couple of\nchapters you will learn to factorize polynomials.\n\n\\begin{Exercise}[title={Difference of Squares}, label=diffsquares]\n  Simply the following products\n  \\Question{$(2x - 3)(2x + 3)$}\n  \\Question{$(7 + 5x^3)(7 - 5x^3)$}\n  \\Question{$(x - a)(x + a)$}\n  \\Question{$(3 - \\pi)(3 + \\pi)$}\n  \\Question{$(-4x^3 + 10)(-4x^3 - 10)$}\n  \\Question{$(x + \\sqrt{7})(x - \\sqrt{7})$}\n  Factor the following polynomials:\n    \\Question{$x^2 - 9$}\n    \\Question{$49 - 16x^6$}\n    \\Question{$\\pi^2 - 25x^8$}\n    \\Question{$x^2 - 5$}\n\\end{Exercise}\n\\begin{Answer}[ref=diffsquares]\n  $(2x - 3)(2x + 3) = 4x^2 - 9$\n  \n  $(7 + 5x^3)(7 - 5x^3) = 49 - 25x^6$\n  \n  $(x - a)(x + a) = x^2 - a^2$\n  \n  $(3 - \\pi)(3 + \\pi) = 9 - \\pi^2$\n  \n  $(-4x^3 + 10)(-4x^3 - 10) = 16x^6 - 100$\n  \n  $(x + \\sqrt{7})(x - \\sqrt{7}) = x^2 - 7$\n\n  $x^2 - 9 = (x + 3)(x - 3)$\n\n  $49 - 16x^6 = (7 + 4x^3)(7 + 4^3)$\n  \n  $\\pi^2 - 25x^8 = (\\pi + 5x^4)(\\pi - 5x^4)$\n  \n  $x^2 - 5 = (x + \\sqrt{5})(x - \\sqrt{5})$\n\n\\end{Answer}\n\nWe are often interested in the roots of a polynomial, that is we want\nto know ``For what values of $x$ does the polynomial evaluate to\nzer?'' For example, when you deal with falling bodies, the first\nquestion you might ask would be ``How many seconds before the hammer\nhits the ground?''  Once you have factored a polynomial into\nbinomials, you can easily find the roots.\n\nFor example, what are the roots of $x^2 - 5$? You just factored it\ninto $(x + \\sqrt{5})(x - \\sqrt{5})$ This product is zero if and only\nif one of the factors is zero. The first factor is only zero when $x$\nis $-\\sqrt{5}$. The second factor is zero only when $x$ is\n$\\sqrt{5}$. Those are the only two roots of this\npolynomial.\n\nLet's check that result. $\\sqrt{5}$ is a little more than 2.2.  Using\nyour Python code, you can graph the polynomial:\n\\begin{Verbatim}\nimport poly.py\nimport matplotlib.pyplot as plt\n\n# x**2 - 5\npn = [-5.0, 0.0, 1.0]\n\n# These lists will hold our x and y values\nx_list = []\ny_list = []\n\n# Start at x=-3\ncurrent_x =-3.0\n\n# End at x=3.0\nwhile current_x < 3.0:\n    current_y = poly.evaluate_polynomial(pn, current_x)\n\n    # Add x and y to respective lists\n    x_list.append(current_x)\n    y_list.append(current_y)\n\n    # Move x forward\n    current_x += 0.1\n\n# Plot the curve\nplt.plot(x_list, y_list)\nplt.grid(True)\nplt.show()\n\\end{Verbatim}\n\nYou should get a plot like this:\n\n\\includegraphics[width=\\textwidth]{sqrt5.png}\n\nIt does, indeed, seem to cross the x-axis near -2.2 and 2.2.\n\n\\section{Powers of binomials}\n\nYou can raise whole polynomials to exponents. For example,\n\\begin{multline*}\n  (3x^3 + 5)^2 = (3x^3 + 5)(3x^3 + 5) \\\\ = 9x^6 + 15x^3 + 15x^3 + 25 = 9x^6 + 30x^3 + 25 \n\\end{multline*}\n\nA polynomial with two terms is called a \\emph{binomial}. $5x^9 - 2x^4$,\nfor example, is a binomial. In this section, we are going to\ndevelop some handy techniques for raising a binomial to some power.\n\nLooking at the previous example, you can see that for any monomials $a$ and $b$, $(a + b)^2 = a^2 + 2ab + b^2$.\nSo, for example, $(7x^3 + \\pi)^2 = 49x^6 + 14\\pi x^3 + \\pi^2$\n\n\\begin{Exercise}[title={Squaring binomials}, label=squaringbinomials]\n  Simply the following\n  \\Question{$(x + 1)^2$}\n  \\Question{$(3x^5 + 5)^2$}\n  \\Question{$(x^3 - 1)^2$}\n  \\Question{$(x - \\sqrt{7})^2$}\n  \n\\end{Exercise}\n\\begin{Answer}[ref=squaringbinomials]\n  $(x+1)^2 = x^2 + 2x + 1$\n\n  $(3x^5 + 5)^2 = 9x^10 + 30x^5 + 25$\n\n  $(x^3 - 1)^2 = x^6 - 2x^3 + 1$\n\n  $(x - \\sqrt{7})^2 = x^2 - 2x\\sqrt{7} + 7$\n\\end{Answer}\n\nWhat about $(x + 2)^3$? You can do it as two separate multiplications:\n\\begin{multline*}\n  (x+2)^3 = (x+2)(x+2)(x+2) \\\\\n  = (x + 2)(x^2 + 4x + 4) = x^3 + 4x^2 + 4x + 2x^2 + 8x + 8 \\\\\n  = x^3 + 6x^2 + 12x + 8\n\\end{multline*}\nAnd, in general, we can say that for any monomials $a$ and $b$, $(a + b)^3 = a^3 + 3a^2b + 3ab^2 + b^3$.\n\nWhat about higher powers? $(a + b)^4$, for example? You could use the\ndistributive property four times, but it starts to get pretty tedious.\n\nHere is a trick. This is known as \\emph{Pascal's triangle}\n\\begin{equation*}\n\\begin{array}{c}\n 1 \\\\\n 1 \\quad 1 \\\\\n 1 \\quad 2 \\quad 1 \\\\\n 1 \\quad 3 \\quad 3 \\quad 1 \\\\\n 1 \\quad 4 \\quad 6 \\quad 4 \\quad 1 \\\\\n 1 \\quad 5 \\quad 10 \\quad 10 \\quad 5 \\quad 1 \\\\\n 1 \\quad 6 \\quad 15 \\quad 20 \\quad 15 \\quad 6 \\quad 1 \\\\\n 1 \\quad 7 \\quad 21 \\quad 35 \\quad 35 \\quad 21 \\quad 7 \\quad 1 \\\\\n \\ldots\n\\end{array}\n\\end{equation*}\nEach entry is the sum of the two above it.\n\nThe coefficients of each term are given by the entries in Pascal's triangle:\n\\begin{equation*}\n(a + b)^4 = 1a^4 + 4a^3b + 6a^2 b^2 + 4 a b^3 + 1 b^4   \n\\end{equation*}\n\n\\begin{Exercise}[title={Using Pascal's Triangle}, label=pascalbinomial]\n    \\Question{What is $(x + \\pi)^5$?}\n\\end{Exercise}\n\\begin{Answer}[ref=pascalbinomial]\n  $(x + \\pi)^5 = x^5 + 5\\pi x^4 + 10\\pi^2 x^3 + 10 \\pi^3 + x^2 + 5 \\pi^2 x + \\pi^5$\n\\end{Answer}\n", "meta": {"hexsha": "223d81debac32855a3c50b667139baafd1a6dadd", "size": 5975, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/common_products-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/common_products-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/common_products-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 32.2972972973, "max_line_length": 122, "alphanum_fraction": 0.630125523, "num_tokens": 2307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.9005297907896396, "lm_q1q2_score": 0.7724457321327637}}
{"text": "\\section{Basic probability}\n\\section{Basic Probability Theory}\n\\begin{itemize}\n\\item Outcome --- Set of possible outcomes\n\\item Event  --- Subset of possible outcomes, an event is something which can happen or not happen\n\\item Distribution  ---  measure on the outcome space, just give the probability of each outcome\n\\item Independence  --- \"Events that are unrelated\", depends on the distribution\n\\end{itemize}\n\n\\subsection{Discrete Examples}\n\\begin{itemize}\n\\item Coin Flip: \n        \\begin{itemize}\n        \\item Outcomes: $\\left\\{ H, T\\right\\}$\n        \\item Event:  If we toss a coin once, there are two possible events: $\\{H\\}$ and $\\{T\\}$; If we toss a coin twice, the event that the first toss is heads is $A = \\{HH,HT\\}$;  If we toss a coin three times, the event that the second toss is heads is $B = \\{HHH, THT,HHT, THT\\}$.\n        \\item Distribution: If we toss a coin, the possibility that it is H and the possibility that it is T are the same, that is $p(\\left\\{H  \\right\\})=p(\\left\\{ T \\right\\})=0.5$.%, $p(\\left\\{ H \\right\\})=0.2, p(\\left\\{  T\\right\\})=0.8$\n        \\end{itemize}\n\\item Rolling a Die:\n        \\begin{itemize}\n        \\item Outcomes:$\\left\\{ 1, 2, 3, 4, 5, 6\\right\\}$\n        \\item Event: some examples\\newline\n        \t\t$E_{1}=\\left\\{ 3\\right\\}$--- rolling a 3\\newline\n                 $E_{2}=\\left\\{ 1, 3, 5\\right\\}$ --- rolling an odd number\\newline\n                 $E_{3}=\\left\\{ 2, 4, 6\\right\\}$ --- rolling an even number \\newline\n                 $E_{4}=\\left\\{ 1, 2\\right\\} $--- rolling either a 1 or 2\n        \\item Distribution: $p(\\left\\{1 \\right\\})=p(\\left\\{ 2 \\right\\})=...=p(\\left\\{ 6 \\right\\})= \\frac{1}{6}$(most common case)\\newline\n        $p(\\left\\{ 1\\right\\})=\\frac{1}{2}, p(\\left\\{ 2 \\right\\})=...=p(\\left\\{ 6 \\right\\})=\\frac{1}{10}$ (for some special die)\n        \\item Independence: Given events $E_{1}$ and $E_{2}$, they are independent if \\newline\n        $p(E_{1} \\bigwedge E_{2})=p(E_{1})p(E_{2})$(the probability that both events appear is equal to the product of the probability that one event appears)\\newline\n        $p(E_{1}|E_{2})=\\frac{p(E_{1} \\bigwedge E_{2})}{p(E_{2})}=p(E_{1})$ (the conditional probability of $E_1$ given the event $E_{2}$ is equal to the probability of $E_1$) \n        \\item example of independence: The die roll 2 and 3 are independent; Events $E_2$ and $E_4$ are also independent:\\newline\n        $E_{2}  \\bigwedge E_{4}=\\left\\{1,3,5\\right\\} \\bigwedge \\left\\{1,2\\right\\} =\\left\\{1\\right\\}$\\newline\n        $p(E_{2} \\bigwedge E_{4})=p(\\left\\{1\\right\\})=\\frac{1}{6}$\\newline\n        $p(E_{2}) p(E_{4})=p(\\left\\{1,3,5\\right\\})p(\\left\\{1,2\\right\\})=\\frac{1}{2}\\frac{1}{3}=\\frac{1}{6}$\n        \\end{itemize}\n\\end{itemize}\n\n\\subsection{Independent Copies}\n\\begin{itemize}\n\\item Coin Flip: 2 independent copies:\\newline\n$C_{1}=\\left\\{H,T\\right\\}, C_{2}=\\left\\{H,T\\right\\}\\Rightarrow C_{1}\\times C_{2}$\\newline\n\\begin{tabular}{c|c|c} \n\t& $H^{\\operatorname{P_{H}}}$ & $T^{P_{T}}$ \\\\\n\t\\hline$P_{H} H$ & $H H$ & $H T$ \\\\\n\t\\hline$P_{T}T$ & $T H$ & $T T$\n\\end{tabular}\n  \\begin{itemize}\n      \\item Event: $\\left\\{HT,HT\\right\\} \\Rightarrow $ exactly one head \\newline\n      $\\left\\{HT,HH,TH\\right\\} \\Rightarrow $at least one head\n      \\item Distribution: $p((H,T))=p_{1}(H)p_{2}(T)$\n      \\item Generalized: K-coins \\textbf{independent}. $\\left\\{H,T\\right\\}^{K}=\\left\\{K-tuples \\ of  \\  H,T\\right\\}$ \\newline\n      Distribution. $p((H,...,T))=p_{1}(H)...p_{k}(T)$ Can generalize this to infinite protucts as well. (Doesn't hold for dependent events)\n   \\end{itemize}\n\\end{itemize}\n\n\\subsection{Continuous Distributions}\n\\begin{itemize}\n\t\\item Ex: Uniform Distribution on $\\left[ 0,1\\right]$ .\\newline\n\tOutcomes: $\\left[ 0,1\\right]$ \\newline\n\tEvents: Ex: the event $\\left[ 0,0.5\\right]$ means random number $\\leq$ 0.5 \\newline\n\t            Ex: the event $\\left[ 0,0.25\\right] \\bigcup \\left[ 0.5,0.75\\right]$ means random number less than $0.025$ or between $0.5$ and $0.75$\\newline\n \\begin{figure}[ht!]\n\t\\centering\n\t\\includegraphics[width=.35\\textwidth]{../figures/probability1.png}  \n\\end{figure}\t      \n\n\t\\item Distribution: \\newline\n\tA distribution a rule which gives the probability of any event. \\newline\n\tProperties to satisfy: if events $E_{1}, E_{2}, ..., E_{n},...  \\mbox{satisfy that}  \\ E_{i} \\bigcap E_{j}= \\varnothing $, then \n\t\\begin{enumerate}\n\t\\item $ p(E_{1} \\bigcup ... \\bigcup E_{n} \\bigcup ...) = \\sum_{i=1}^{\\infty}p(E_{j})$\n\t\\item $p(E)=\\int_{E} d_{x}$, \"length of E\" \n\t\\item examples 1: $E_{1}=\\left[ 0,0.5\\right] $\n\t$$\n\tP\\left(E_{1}\\right)=\\int_{E_{1}} d_{x}=\\int_{0}^{1 / 2} d x=\\frac{1}{2}.\n\t$$\n\t\\item examples 2: $E_{2}=\\left[ 0,0.25\\right] \\bigcup \\left[ 0.5,0.75\\right]$\n\t$$p\\left(E_{2}\\right)=\\int_{E_{2}} d x=\\int_{0}^{1 / 4} d x+\\int_{1 / 2} ^{3/4}d x=\\frac{1}{4}+\\frac{1}{4}=\\frac{1}{2}\n\t$$\n\t\\end{enumerate}\t\n \\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.7\\textwidth]{../figures/probability2.jpeg}  \n\\end{figure}\n\\item Independence: \\newline\nTwo events $E_{1}, E_{2}$ are independent if \\newline\n$$p\\left(E_{1} \\cap E_{2}\\right)=p\\left(E_{1}\\right) p\\left(E_{2}\\right)$$\nFor example,\n$E_{1} \\cap E_{2}=[0,0.5] \\cap\\left(\\left[0, \\frac{1}{4}\\right] \\cup\\left[\\frac{1}{2}, \\frac{3}{4}\\right]\\right)$  \t\n$$\np\\left(E_{1}\\bigcap E_{2}\\right)=\\frac{1}{4}=\\frac{1}{2} \\cdot \\frac{1}{2}=p\\left(E_{1}\\right) p\\left(E_{2}\\right)\n$$\n\nFrist two binary digits are like two independent coin flips. Every binary digit is like an independent coin flip, so we ca think of the random number as being an infinite sequence of coin flips. In general, we'll consider distribution defined by a probability density function p(x). The probability of an event is given by\t$P\\left(E\\right)=\\int_{E_{1}} p(x)d_{x}$\n\\begin{itemize}\n\\item Outcomes: $\\left[ 0,1\\right]$\n\\item Density function: $p(x)=1$ ($\\int_0^1 p(x)=1$)\n\\end{itemize}\n\\end{itemize}\n\n\n\\subsection{Gaussian/ Normal Distribution}\n \\begin{figure}[ht!]\n\t\\centering\n\t\\includegraphics[width=.7\\textwidth]{../figures/probability3.png}  \n\\end{figure}\n\\begin{itemize}\n\t\\item Outcomes: \n\t\\item Events: Subsets of R\n\t\\item Density function: $P(x)=\\frac{1}{\\sqrt{2\\pi}} e^{-x^{2} / 2}$\\newline\n\t         Means that for any event $E$,\n\t         $$\n\t         p\\left(E\\right)=\\int_{E} \\frac{1}{\\sqrt{2 \\pi}} e^{-x^{2} / 2} d x.\n\t         $$\n\t         \n\t \\item Cummulative distribution Function \n\t $$\n\t F(x)=\\int_{-\\infty}^{x} p(t) d t=p(t<x)\n\t $$\n\t Note that $\\lim_{x\\rightarrow \\infty} F(x)=1$.\n\\end{itemize}\n\n\\section{Random, Variable, Mean, Variance}\n\\begin{itemize}\n\\item Recall: \n\\begin{itemize}\n\t\\item Set if outcomes:  $\\Omega$\n\t\\item Event: Subset of outcomes: $E$\n\t\\item Probability Distribution: $p(x)$\n\\end{itemize}\n\\subsection{Random Variable}\n\\item Defin: A random variable X is a function $X: \\Omega \\rightarrow S$ Here $ S=R, R^{d}$, but could be arbitrary.\n \\item Ex: Rolling a die:\n \\begin{itemize}\n \t\\item Outcomes: $\\Omega={1,2,...,6}$\n \t\\item Events are subsets of $\\Omega$\n \t\\item Distribution: $p(1)=p(2)=...=p(6)=\\frac{1}{6}$\n \tSuppose we roll the die, then if the die comes up d times, you win d dollars, minus 1 dollar if it's even. The amount you win is a random variable. \\newline\n \t$\\begin{array}{l}\n \t\tX_{1}: \\Omega \\rightarrow R\\\\\n \t\tX_{1}(1)=1 \\\\\n \t\tX_{1}(2)=1 \\\\\n \t\tX_{1}(3)=3 \\\\\n \t\tX_{1}(4)=3 \\\\\n \t\tX_{1}(5)=5 \\\\\n \t\tX_{1}(6)=5\n \t\\end{array}$ \\newline\n \tCan define multiple random variables on a single outcome space $\\Omega$. \t\n \\end{itemize}  \n\\item Ex: Rolling a die. If the die comes up d times, you get d dollars. If d is even, then you give a dollar to your friend.\\newline\n$X_{1} \\leftarrow$ your winnings,\n$X_{2}\\leftarrow$ your friends winnings. \\newline\n$$\n\\begin{aligned}\n\tX_{2}: \\Omega \\rightarrow \\mathbb{R}, & X_{2}(1)=0, \\quad X_{2}(2)=1 \\\\\n\t& X_{2}(3)=0, \\quad X_{2}(4)=1 \\\\\n\t& X_{2}(5)=0, \\quad X_{2}(6)=1\n\\end{aligned}\n$$\nFrom here on out $\\Omega$ will be fixed, we talk about different random variables on $\\Omega$.\n\\subsection{Mean of  random variable}\n\\item Defin: Mean of a random variable $X$. \\newline\nExpectation of $X$: \n$$\n\\mathbb{E}[X]=\\sum_{\\omega \\in \\Omega} p(\\omega) X(\\omega)\\left(=\\int_{\\Omega} X(\\omega) p(\\omega) d \\omega\\right)\n$$\n\\item Ex: \n $$\\begin{aligned}\n& \\mathbb{E}\\left[X_{1}\\right]=\\frac{1}{6}(1+1+3+3+5+5)=3 \\\\\n& \\mathbb{E}\\left[X_{2}\\right]=\\frac{1}{6}(0+1+0+1+0+1)=\\frac{1}{2}\n\\end{aligned}\n$$\n\\subsection{Variance of  Random Variables}\n\\item Defin: Variance of a Random Variable $X$:  \n$$\nV[X]=\\mathbb{E}\\left[X^{2}\\right]-\\mathbb{E}[X]^{2}=\\mathbb{E}\\left[(X-\\mathbb{E}[X])^{2}\\right]\n$$\n\\item Ex: \n$$\n\\begin{array}{l} V\\left[X_{1}\\right]=\\mathbb{E}\\left[X_{1}^{2}\\right]-(3)^{2}\\\\\n\t= \\frac{1}{6}\\left(1^{2}+1^{2}+3^{2}+3^{2}+5^{2}+5^{2}\\right)-9\\\\\n\t=\\frac{1}{3}(1+9+25)-9\\\\\n\t=\\frac{35}{3}-9=\\frac{8}{3}\\\\\n\\end{array}$$ \\newline\nVariance measures \"how much $X$ deviates from it's average\".\n\n \\begin{figure}\n\t\\centering\n\t\\includegraphics[width=.35\\textwidth]{../figures/probability4.png}  \n\\end{figure}\t\n\n\\subsection{Independenve of Random variables}\n\\item Defin:  Two random variables $X_{1},X_{2}$ are independent if for any $ \\alpha, \\beta,$\n$E_{1}=\\left\\{w: X_{1}(\\omega)<\\alpha\\right\\}, E_{2}=\\left\\{w: X_{2}(\\omega)<\\beta\\right\\}$ are independent events.\n\\item Ex: $X_{1} , X_{2}$ are independent: if $(\\alpha, \\beta) \\quad \\alpha=4, \\quad \\beta=\\frac{1}{2}$,\n$$\n\\begin{array}{l} \nE_{1}=\\left\\{w: X_{1}(u)<4\\right\\}=\\{1,2,3,4\\} \\\\\nE_{2}=\\left\\{w: X_{2}(\\omega)<\\frac{1}{2}\\right\\}=\\{1,3,5\\}\n\\end{array}\n$$\n$$\n\\begin{array}{l}\np\\left(E_{1}\\bigcap E_{2}\\right)=p\\left(E_{1}\\right) p\\left(E_{2}\\right) \\\\\np(\\{1,3\\})=p\\left(E_{1}\\right) p\\left(E_{2}\\right)\n\\end{array}\n$$\n\n\\subsection{Properties of E, V, Independence} \n\\begin{itemize}\n\t\\item If $X_{1}, X_{2}$ are random variable, then \n\t$$\n\t\\left(a_{1}X_{1}+a_{2} x_{2}\\right)(w)=a_{1} x_{1}(w)+a_{2} x_{2}(w)\n\t$$\n\t$$\\mathbb{E}\\left[a_{1}X_{1}+a_{2} X_{2}\\right]=a_{1}\\mathbb{E}\\left[X_{1}\\right]+a_{2} \\mathbb{E}\\left[X_{2}\\right]\n\t$$\n\t\\item If $X_{1}, X_{2}$ are independent random variables, then \n\t$$\n\t\\mathbb{E}\\left[X, X_{2}\\right]=\\mathbb{E}\\left[X_{1}\\right] \\mathbb{E}\\left[X_{2}\\right]\n\t$$\n\t\\item From this, we get if $X_{1}, X_{2}$ are independent,  \t\n\t$$\n\tV\\left[X_{1}+X_{2}\\right]=V\\left[X_{1}\\right]+V\\left[X_{2}\\right]\n\t$$\n\t$$V\\left[a_{1} x_{1}+a_{2} x_{2}\\right]=a_{1}^{2} V\\left[x_{1}\\right]+a_{2}^{2} V\\left[x_{2}\\right]\n\t$$\n\\end{itemize}\t\n\n\\end{itemize}\n\n%\n%\\includepdf{HandWrittenNotes/Probability1.pdf}\n%\\includepdf{HandWrittenNotes/Probability2.pdf}\n%\\includepdf{HandWrittenNotes/Probability3.pdf}\n%\\includepdf{HandWrittenNotes/Probability4.pdf}\n%\\includepdf{HandWrittenNotes/Probability5.pdf}\n%\\includepdf{HandWrittenNotes/Probability6.pdf}\n%\\includepdf{HandWrittenNotes/Probability7.pdf}\n%\\includepdf{HandWrittenNotes/Probability8.pdf}\n%\\includepdf{HandWrittenNotes/Probability9.pdf}\n\n", "meta": {"hexsha": "77fa7ed0ce6e6dd62f5086103b504ea8663cc43b", "size": 10785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/3 Probability/3.2-BasicProb.tex", "max_stars_repo_name": "liuzhengqi1996/math452_Spring2022", "max_stars_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "497-6DL/3 Probability/3.2-BasicProb.tex", "max_issues_repo_name": "liuzhengqi1996/math452_Spring2022", "max_issues_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "497-6DL/3 Probability/3.2-BasicProb.tex", "max_forks_repo_name": "liuzhengqi1996/math452_Spring2022", "max_forks_repo_head_hexsha": "b01d1d9bee4778b3069e314c775a54f16dd44053", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5661157025, "max_line_length": 363, "alphanum_fraction": 0.6309689383, "num_tokens": 4115, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045996818986, "lm_q2_score": 0.870597270087091, "lm_q1q2_score": 0.7723979024917713}}
{"text": "\n\\subsection{Cauchy-Riemann equations}\n\nConsider complex number z=x+iy\n\nA function on this gives:\n\n\\(f(z)=u+iv\\)\n\nTake the total differential of :\n\n\\(df/dz=\\dfrac{\\delta f}{\\delta z}+\\dfrac{\\delta f}{\\delta x}\\dfrac{dx}{dz}+\\dfrac{\\delta f}{\\delta y}\\dfrac{dy}{dz}\\)\n\nWe know that:\n\n\\begin{itemize}\n\\item \\(\\dfrac{dx}{dz}=1\\)\n\\item \\(\\dfrac{dy}{dz}=-i\\)\n\\end{itemize}\n\nWe can see from this that\n\n\\begin{itemize}\n\\item \\(\\dfrac{du}{dx}=\\dfrac{dv}{dy}\\)\n\\item \\(\\dfrac{du}{dy}=-\\dfrac{dv}{dx}\\)\n\\end{itemize}\n\nThese are the Cauchy-Riemann equations\n\n", "meta": {"hexsha": "48ee45fd288622cc88eccb3bc960e8eeedaab9c7", "size": 548, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/complexAnalysis/04-06-cauchyRiemann.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/complexAnalysis/04-06-cauchyRiemann.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/complexAnalysis/04-06-cauchyRiemann.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.2666666667, "max_line_length": 118, "alphanum_fraction": 0.6569343066, "num_tokens": 209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810496235896, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7723358157024174}}
{"text": "\\subsection{Orthogonal diagonalization}\n\nWe begin this section by recalling some important definitions. Recall from Definition~\\ref{def:orthogonal-set} that non-zero vectors are called orthogonal if their dot product equals $0$.  A set is orthonormal if it is orthogonal and each vector is a unit vector.\n\nAn orthogonal matrix $U$, from Definition~\\ref{def:orthogonal-matrices}, is one in which $UU^{T} = I$. In other words, the transpose of an orthogonal matrix is equal to its inverse. A key characteristic of orthogonal matrices, which will be essential in this section, is that the columns of an orthogonal matrix form an orthonormal set.\n\nWe now recall another important definition.\n\n\\begin{definition}{Symmetric and antisymmetric matrices}{symmetric-antisymmetric-matrices}\nA real $n\\times n$-matrix $A$, is \\textbf{symmetric }if $A^{T}=A$. If $%\nA=-A^{T}$, then $A$ is called \\textbf{antisymmetric. }\n\\index{symmetric matrix}\n\\end{definition}\n\nBefore proving an essential theorem, we first examine the following lemma which will be used below.\n\n\\begin{lemma}{The dot product}{dot-product-lemma}\nLet $A=\\mat{a_{ij} }$ be a real symmetric $n \\times n$-matrix, and let $\\vect{x}, \\vect{y} \\in \\R^n$. Then\n\\[\nA\\vect{x} \\dotprod \\vect{y} = \\vect{x} \\dotprod A \\vect{y}\n\\]\n\\end{lemma}\n\n\\begin{proof}\nThis result follows from the definition of the dot product together with properties of matrix multiplication, as follows:\n\\begin{eqnarray*}\nA\\vect{x} \\dotprod \\vect{y} &=& \\sum_{k,l}a_{kl}x_{l}y_{k} \\\\\n&=&\\sum_{k,l} (a_{lk})^Tx_{l}y_{k} \\\\\n&=& \\vect{x}\\dotprod A^{T}\\vect{y} \\\\\n&=& \\vect{x}\\dotprod A \\vect{y}\n\\end{eqnarray*}\n\nThe last step follows from $A^T = A$, since $A$ is symmetric.\n\\end{proof}\n\nWe can now prove that the eigenvalues of a real symmetric matrix are real numbers.  Consider the following important theorem.\n\n\\begin{theorem}{Orthogonal eigenvectors}{symmetric-orthogonal-eigenvectors}\nLet $A$ be a real symmetric matrix. Then the eigenvalues of $A$ are real numbers and eigenvectors corresponding to distinct eigenvalues are orthogonal.\n\\end{theorem}\n\n\\begin{proof}\nRecall that for a complex number $a+ib$, the complex conjugate, denoted by $\n\\conjugate{a+ib}$ is given by $\\conjugate{a+ib}=a-ib$. The\nnotation, $\\conjugate{\\vect{x}}$ will denote the vector which has every\nentry replaced by its complex conjugate.\n\nSuppose $A$ is a real symmetric matrix and $A\\vect{x}=\\lambda \\vect{x}$.\nThen\n\\begin{equation*}\n\\conjugate{\\lambda }\\conjugate{\\vect{x}}^{T}\\vect{x}=(\\conjugate{A\n\\vect{x}}) ^{T}\\vect{x}=\\conjugate{\\vect{x}}^{T}A^{T}\\vect{x}=\n\\conjugate{\\vect{x}}^{T}A\\vect{x}=\\lambda \\conjugate{\\vect{x}}^{T}\n\\vect{x}\n\\end{equation*}\nDividing by $\\conjugate{\\vect{x}}^{T}\\vect{x}$ on both sides yields $\n\\conjugate{\\lambda }=\\lambda $ which says $\\lambda $ is real. To do this, we need to ensure that $\\conjugate{\\vect{x}}^{T}\\vect{x} \\neq 0$. Notice that $\\conjugate{\\vect{x}}^{T}\\vect{x} = 0$ if and only if $\\vect{x} = \\vect{0}$. Since we chose $\\vect{x}$ such that $A\\vect{x} = \\lambda \\vect{x}$, $\\vect{x}$ is an eigenvector and therefore must be non-zero.\n\nNow suppose $A$ is real symmetric and $A\\vect{x}=\\lambda \\vect{x}$, $A\n\\vect{y}=\\mu \\vect{y}$ where $\\mu \\neq \\lambda$. Then since $A$\nis symmetric, it follows from Lemma~\\ref{lem:dot-product-lemma} about the dot product that\n\\begin{equation*}\n\\lambda \\vect{x}\\dotprod \\vect{y}=A\\vect{x}\\dotprod \\vect{y}=\\vect{x}\\dotprod A\\vect{y}=\\vect{x}\\dotprod \\mu \\vect{y}=\\mu \\vect{x}\\dotprod \\vect{y}\n\\end{equation*}\nHence $(\\lambda -\\mu) \\vect{x}\\dotprod \\vect{y}=0$. It follows that,\nsince $\\lambda -\\mu \\neq 0$, it must be that $\\vect{x}\\dotprod \\vect{y}=0$. Therefore the eigenvectors form an orthogonal set.\n\\end{proof}\n\nThe following theorem is proved in a similar manner.\n\n\\begin{theorem}{Eigenvalues of antisymmetric matrix}{antisymmetric-eigenvalues}\nThe eigenvalues of a real antisymmetric matrix are either equal to $0$ or are pure imaginary numbers.\n\\end{theorem}\n\n\\begin{proof}\nFirst, note that if $A=0$ is the zero matrix, then $A$ is antisymmetric and has eigenvalues equal to $0$.\n\nSuppose $A=-A^{T}$ so $A$ is antisymmetric and $A\\vect{x}=\\lambda\n\\vect{x}$. Then\n\\begin{equation*}\n\\conjugate{\\lambda \\vect{x}}^{T}\\vect{x}=(\\conjugate{A\n\\vect{x}}) ^{T}\\vect{x}=\\conjugate{\\vect{x}}^{T}A^{T}\\vect{x}=-\n\\conjugate{\\vect{x}}^{T}A\\vect{x}=-\\lambda \\conjugate{\\vect{x}}^{T}\n\\vect{x}\n\\end{equation*}\nand so, dividing by $\\conjugate{\\vect{x}}^{T}\\vect{x}$ as before, $\n\\conjugate{\\lambda }=-\\lambda$. Letting $\\lambda =a+ib$, this means $\na-ib=-a-ib$ and so $a=0$. Thus $\\lambda $ is pure imaginary.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{Eigenvalues of an antisymmetric matrix}{antisymmetric-eigenvalues}\nLet $A=\\begin{mymatrix}{rr}\n0 & -1 \\\\\n1 & 0\n\\end{mymatrix}$.  Find its eigenvalues.\n\\end{example}\n\n\\begin{solution}\nFirst notice that $A$ is antisymmetric. By Theorem~\\ref{thm:antisymmetric-eigenvalues}, the eigenvalues will either equal $0$ or be pure imaginary.  The eigenvalues of $A$ are obtained by solving the usual equation\n\\[\n\\det (\\eigenvar I - A ) =\n\\det \\begin{mymatrix}{rr}\n\\eigenvar & 1 \\\\\n-1 & \\eigenvar\n\\end{mymatrix} =\\eigenvar ^{2}+1=0\n\\]\n\nHence the eigenvalues are $\\pm i$, pure\nimaginary.\n\\end{solution}\n\nConsider the following example.\n\n\\begin{example}{Eigenvalues of a symmetric matrix}{eigenvalues-symmetric}\nLet $A=\\begin{mymatrix}{rr}\n1 & 2 \\\\\n2 & 3\n\\end{mymatrix}$. Find its eigenvalues.\n\\end{example}\n\n\\begin{solution}\nFirst, notice that $A$ is symmetric. By Theorem~\\ref{thm:symmetric-orthogonal-eigenvectors}, the eigenvalues will all be real. The eigenvalues of $A$ are obtained by solving the usual equation\n\\[\n\\det (\\eigenvar I - A) =\n\\det \\begin{mymatrix}{rr}\n\\eigenvar - 1 & -2 \\\\\n-2 & \\eigenvar - 3\n\\end{mymatrix} = \\eigenvar^2 -4\\eigenvar -1=0\n\\]\nThe eigenvalues are given by $\\lambda_1 =2+\n\\sqrt{5}$ and $\\lambda_2 =2-\\sqrt{5}$ which are both real.\n\\end{solution}\n\nRecall that a diagonal matrix $D=\\mat{d_{ij} }$ is one in which $d_{ij} = 0$ whenever $i \\neq j$. In other words, all numbers not on the main diagonal are equal to zero.\n\nConsider the following important theorem.\n\n\\begin{theorem}{Orthogonal diagonalization}{orthogonal-diagonalization}\nLet $A$ be a real symmetric matrix. Then there exists an\northogonal matrix $U$ such that\n\\[\nU^{T}AU = D\n\\]\nwhere $D$ is a diagonal matrix. Moreover,\nthe diagonal entries of $D$ are the eigenvalues of $A$.\n\\end{theorem}\n\nWe can use this theorem to diagonalize a symmetric matrix, using orthogonal matrices. Consider the following corollary.\n\n\\begin{corollary}{Orthonormal set of eigenvectors}{orthonormal-eigenvectors}\nIf $A$ is a real $n\\times n$ symmetric matrix, then there exists an\northonormal set of eigenvectors, $\\set{\\vect{u}_{1},\\ldots,\\vect{u}\n_{n}}$.\n\\end{corollary}\n\n\\begin{proof}\nSince $A$ is symmetric, then by Theorem~\\ref{thm:orthogonal-diagonalization},\nthere exists an orthogonal matrix $U$ such that $U^{T}AU=D$, a diagonal\nmatrix whose diagonal entries are the eigenvalues of $A$. Therefore, since $\nA $ is symmetric and all the matrices are real,\n\\begin{equation*}\n\\conjugate{D}=\\conjugate{D^{T}}=\\conjugate{U^{T}A^{T}U}=U^{T}A^{T}U=U^{T}AU=D\n\\end{equation*}\nshowing $D$ is real because each entry of $D$ equals its complex conjugate.\n\nNow let\n\\begin{equation*}\nU=\\begin{mymatrix}{cccc}\n\\vect{u}_{1} & \\vect{u}_{2} & \\cdots & \\vect{u}_{n}\n\\end{mymatrix}\n\\end{equation*}\nwhere the $\\vect{u}_{i}$ denote the columns of $U$ and\n\\begin{equation*}\nD=\\begin{mymatrix}{ccc}\n\\lambda _{1} &  & 0 \\\\\n& \\ddots &  \\\\\n0 &  & \\lambda _{n}\n\\end{mymatrix}\n\\end{equation*}\nThe equation, $U^{T}AU=D$ implies $AU = UD$ and\n\\begin{eqnarray*}\nAU &=&\\begin{mymatrix}{cccc}\nA\\vect{u}_{1} & A\\vect{u}_{2} & \\cdots & A\\vect{u}_{n}%\n\\end{mymatrix} \\\\\n&=&\\begin{mymatrix}{cccc}\n\\lambda _{1}\\vect{u}_{1} & \\lambda _{2}\\vect{u}_{2} & \\cdots & \\lambda\n_{n}\\vect{u}_{n}\n\\end{mymatrix} \\\\\n&=& UD\n\\end{eqnarray*}\nwhere the entries denote the columns of $AU$ and $UD$ respectively.\nTherefore, $A\\vect{u}_{i}=\\lambda _{i}\\vect{u}_{i}$.  Since the matrix $U$\nis orthogonal, the $\\ijth$ entry of $U^{T}U$ equals $\\delta _{ij}$ and so\n\\begin{equation*}\n\\delta _{ij}=\\vect{u}_{i}^{T}\\vect{u}_{j}=\\vect{u}_{i}\\dotprod \\vect{u}\n_{j}\n\\end{equation*}\nThis proves the corollary because it shows the vectors $\\set{\\vect{u}\n_{i}} $ form an orthonormal set.\n\\end{proof}\n\n\\begin{definition}{Principal axes}{principal-axes}\nLet $A$ be an $n \\times n$-matrix. Then the principal axes of $A$ is a set of orthonormal eigenvectors of $A$.\n\\index{principal axes}\n\\end{definition}\n\nIn the next example, we examine how to find such a set of orthonormal eigenvectors.\n\n\\begin{example}{Find an orthonormal set of eigenvectors}{orthonormal-basis-eigenvectors}\nFind an orthonormal set of eigenvectors for the symmetric matrix\n\\begin{equation*}\nA = \\begin{mymatrix}{rrr}\n17 & -2 & -2 \\\\\n-2 & 6 & 4 \\\\\n-2 & 4 & 6\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nRecall Procedure~\\ref{proc:find-eigenvalues-vectors} for finding the eigenvalues and eigenvectors of a matrix. You can verify that the eigenvalues are $18,9,2$. First find the eigenvector for $18$ by solving the equation $(18I-A)X = 0$.\nThe appropriate augmented matrix is given by\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n18-17 & 2 & 2 & 0 \\\\\n2 & 18-6 & -4 & 0 \\\\\n2 & -4 & 18-6 & 0\n\\end{mymatrix}\n\\end{equation*}\nThe {\\rref} is\n\\begin{equation*}\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 4 & 0 \\\\\n0 & 1 & -1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nTherefore an eigenvector is\n\\begin{equation*}\n\\begin{mymatrix}{r}\n-4 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nNext find the eigenvector for $\\lambda =9$. The augmented matrix and resulting {\\rref} are\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n9-17 & 2 & 2 & 0 \\\\\n2 & 9-6 & -4 & 0 \\\\\n2 & -4 & 9-6 & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n0 & 1 & -1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nThus an eigenvector for $\\lambda =9$ is\n\\begin{equation*}\n\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n2\n\\end{mymatrix}\n\\end{equation*}\nFinally find an eigenvector for $\\lambda =2$. The appropriate augmented\nmatrix and {\\rref} are\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n2-17 & 2 & 2 & 0 \\\\\n2 & 2-6 & -4 & 0 \\\\\n2 & -4 & 2-6 & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 0 & 0 \\\\\n0 & 1 & 1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nThus an eigenvector for $\\lambda =2$ is\n\\begin{equation*}\n\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nThe set of eigenvectors for $A$ is given by\n\\[\n\\set{\n\\begin{mymatrix}{r}\n-4 \\\\\n1 \\\\\n1\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n2\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n1\n\\end{mymatrix}\n}\n\\]\nYou can verify that these eigenvectors form an orthogonal set. By dividing each eigenvector by its magnitude, we obtain an orthonormal set:\n\\begin{equation*}\n\\set{\\frac{1}{\\sqrt{18}}\\begin{mymatrix}{r}\n-4 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\frac{1}{3}\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n2\n\\end{mymatrix} ,\\frac{1}{\\sqrt{2}}\\begin{mymatrix}{r}\n0 \\\\\n-1 \\\\\n1\n\\end{mymatrix} }\n\\end{equation*}\n\\end{solution}\n\nConsider the following example.\n\n\\begin{example}{Repeated eigenvalues}{}\nFind an orthonormal set of three eigenvectors for the matrix\n\\begin{equation*}\nA = \\begin{mymatrix}{rrr}\n10 & 2 & 2 \\\\\n2 & 13 & 4 \\\\\n2 & 4 & 13\n\\end{mymatrix}\n\\end{equation*}\n\\end{example}\n\n\\begin{solution}\nYou can verify that the eigenvalues of $A$ are $9$ (with multiplicity two) and $18$ (with multiplicity one). Consider the\neigenvectors corresponding to $\\lambda =9$. The appropriate augmented matrix\nand {\\rref} are given by\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n9-10 & -2 & -2 & 0 \\\\\n-2 & 9-13 & -4 & 0 \\\\\n-2 & -4 & 9-13 & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 2 & 2 & 0 \\\\\n0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nand so eigenvectors are of the form\n\\begin{equation*}\n\\begin{mymatrix}{c}\n-2y-2z \\\\\ny \\\\\nz\n\\end{mymatrix}\n\\end{equation*}\nWe need to find two of these which are orthogonal. Let one be given by setting $z=0$ and $y=1$, giving $\n\\begin{mymatrix}{r}\n-2 \\\\\n1 \\\\\n0\n\\end{mymatrix}$.\n\nIn order to find an eigenvector orthogonal to this one, we need to satisfy\n\\begin{equation*}\n\\begin{mymatrix}{r}\n-2 \\\\\n1 \\\\\n0\n\\end{mymatrix} \\dotprod \\begin{mymatrix}{c}\n-2y-2z \\\\\ny \\\\\nz\n\\end{mymatrix} =5y+4z=0\n\\end{equation*}\nThe values $y=-4$ and $z=5$ satisfy this equation, giving another eigenvector\ncorresponding to $\\lambda=9$ as\n\\begin{equation*}\n\\begin{mymatrix}{c}\n-2(-4) -2(5) \\\\\n(-4) \\\\\n5\n\\end{mymatrix} =\\begin{mymatrix}{r}\n-2 \\\\\n-4 \\\\\n5\n\\end{mymatrix}\n\\end{equation*}\nNext find the eigenvector for $\\lambda =18$. The augmented matrix and the resulting {\\rref} are given by\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n18-10 & -2 & -2 & 0 \\\\\n-2 & 18-13 & -4 & 0 \\\\\n-2 & -4 & 18-13 & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & -\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n0 & 1 & -1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nand so an eigenvector is\n\\begin{equation*}\n\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n2\n\\end{mymatrix}\n\\end{equation*}\n\nDividing each eigenvector by its length, the orthonormal set is\n\\begin{equation*}\n\\set{\\frac{1}{\\sqrt{5}} \\begin{mymatrix}{r}\n-2\\\\\n1 \\\\\n0\n\\end{mymatrix} , \\frac{\\sqrt{5}}{15} \\begin{mymatrix}{r}\n-2 \\\\\n-4 \\\\\n5\n\\end{mymatrix} , \\frac{1}{3}\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n2\n\\end{mymatrix} }\n\\end{equation*}\n\n\\end{solution}\n\nIn the above solution, the repeated eigenvalue implies that there would have been many other\northonormal bases which could have been obtained. While we chose to\ntake $z=0, y=1$, we could just as easily have taken $y=0$\nor even $y=z=1$. Any such change would have resulted in a different\northonormal set.\n\nRecall the following definition.\n\n\\begin{definition}{Diagonalizable}{non-defective}\nAn $n\\times n$-matrix $A$ is said to be \\textbf{non-defective}\n\\index{non-defective}or \\textbf{diagonalizable}\n\\index{diagonalizable} if there exists an invertible matrix $P$ such that $\nP^{-1}AP=D$ where $D$ is a diagonal matrix.\n\\end{definition}\n\nAs indicated in Theorem~\\ref{thm:orthogonal-diagonalization} if $A$ is a real symmetric matrix, there exists an\northogonal matrix $U$ such that $U^{T}AU=D$ where $D$ is a diagonal matrix. Therefore,\nevery symmetric matrix is diagonalizable because if $U$ is an orthogonal\nmatrix, it is invertible and its inverse is $U^{T}$. In this case, we say that $A$ is \\textbf{orthogonally diagonalizable}\\index{orthogonally diagonalizable}. Therefore every symmetric matrix is in fact orthogonally diagonalizable. The next theorem provides another way to determine if a matrix is orthogonally diagonalizable.\n\n\\begin{theorem}{Orthogonally diagonalizable}{orthogonal-diagonalizable}\nLet $A$ be an $n \\times n$-matrix. Then $A$ is orthogonally diagonalizable if and only if $A$ has an orthonormal set of eigenvectors.\n\\end{theorem}\n\nRecall from Corollary~\\ref{cor:orthonormal-eigenvectors} that every symmetric matrix has an orthonormal set of eigenvectors. In fact these three conditions are equivalent.\n\nIn the following example, the orthogonal\nmatrix $U$ will be found to orthogonally diagonalize a matrix.\n\n\\begin{example}{Diagonalize a symmetric matrix}{orthogonal-diagonalization}\nLet $A=\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 &\n\\vspace{0.05in}\\frac{3}{2} & \\vspace{0.05in}\\frac{1}{2} \\\\\n0 & \\vspace{0.05in}\\frac{1}{2} & \\vspace{0.05in}\\frac{3}{2}\n\\end{mymatrix}$. Find an orthogonal matrix $U$ such that $U^{T}AU$ is a diagonal\nmatrix.\n\\end{example}\n\n\\begin{solution}\nIn this case, the eigenvalues are $2$ (with multiplicity one) and $1$ (with multiplicity two). First\nwe will find an eigenvector for the eigenvalue $2$. The appropriate augmented matrix and resulting {\\rref} are given by\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n2-1 & 0 & 0 &  0 \\\\\n0 & 2-\\vspace{0.05in}\\frac{3}{2} & -\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n0 & -\\vspace{0.05in}\\frac{1}{2} & 2-\\vspace{0.05in}\\frac{3}{2} &  0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 0 & 0 \\\\\n0 & 1 & -1 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nand so an eigenvector is\n\\begin{equation*}\n\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nHowever, it is desired that the eigenvectors be unit vectors\nand so dividing this vector by its length gives\n\\begin{equation*}\n\\begin{mymatrix}{c}\n0 \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}\n\\end{equation*}\nNext find the eigenvectors corresponding to the eigenvalue equal to $1$. The appropriate augmented matrix and resulting {\\rref} are given by:\n\\begin{equation*}\n\\begin{mymatrix}{ccc|c}\n1-1 & 0 & 0 & 0 \\\\\n0 & 1-\\vspace{0.05in}\\frac{3}{2} & -\\vspace{0.05in}\\frac{1}{2} & 0 \\\\\n0 & -\\vspace{0.05in}\\frac{1}{2} & 1-\\vspace{0.05in}\\frac{3}{2} & 0\n\\end{mymatrix}\n\\roweq\\ldots\\roweq\n\\begin{mymatrix}{rrr|r}\n0 & 1 & 1 & 0 \\\\\n0 & 0 & 0 & 0 \\\\\n0 & 0 & 0 & 0\n\\end{mymatrix}\n\\end{equation*}\nTherefore, the eigenvectors are of the form\n\\begin{equation*}\n\\begin{mymatrix}{r}\ns \\\\\n-t \\\\\nt\n\\end{mymatrix}\n\\end{equation*}\nTwo of these which are orthonormal are $\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n0\n\\end{mymatrix}$, choosing $s=1$ and $t=0$, and $\\begin{mymatrix}{c}\n0 \\\\\n-\\vspace{0.05in}\\frac{1}{\\sqrt{2}} \\\\\n\\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix}$, letting $s=0$, $t= 1 $ and normalizing the resulting vector.\n\nTo obtain the desired orthogonal matrix, we let the orthonormal eigenvectors computed above be the columns.\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & 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\nTo verify, compute $U^{T}AU$ as follows:\n\\begin{equation*}\nU^{T}AU =\n\\begin{mymatrix}{rrr}\n0 & -\\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\\\\n1 & 0 & 0 \\\\\n0 & \\vspace{0.05in}\\frac{1}{\\sqrt{2}} & \\vspace{0.05in}\\frac{1}{\\sqrt{2}}\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & \\vspace{0.05in}\\frac{3}{2} & \\vspace{0.05in}\\frac{1}{2} \\\\\n0 & \\vspace{0.05in}\\frac{1}{2} & \\vspace{0.05in}\\frac{3}{2}\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n0 & 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=\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 2\n\\end{mymatrix} = D\n\\end{equation*}\nthe desired diagonal matrix. Notice that the eigenvectors, which construct the columns of $U$, are in the same order as the eigenvalues in $D$.\n\\end{solution}\n\nWe conclude this section with a Theorem that generalizes earlier results.\n\n\\begin{theorem}{Triangulation of a matrix}{triangulation}\nLet $A$ be an $n \\times n$-matrix. If $A$ has $n$ real eigenvalues, then an orthogonal matrix $U$ can be found to result in the upper triangular matrix $U^T A U$.\n\\end{theorem}\n\nThis Theorem provides a useful Corollary.\n\n\\begin{corollary}{Determinant and trace}{determinant-trace}\nLet $A$ be an $n \\times n$-matrix with eigenvalues $\\lambda_1,\\ldots, \\lambda_n$. Then it follows that $\\det(A)$ is equal to the product of the $\\lambda_1$, while $\\tr(A)$ is equal to the sum of the $\\lambda_i$.\n\\end{corollary}\n\n\\begin{proof}\nBy Theorem~\\ref{thm:triangulation}, there exists an orthogonal matrix $U$ such\nthat $U^TAU=P$, where $P$ is an upper triangular matrix.\nSince $P$ is similar to $A$, the eigenvalues\nof $P$ are $\\lambda_1, \\lambda_2, \\ldots, \\lambda_n$.\nFurthermore, since $P$ is (upper) triangular, the entries on the\nmain diagonal of $P$ are its eigenvalues, so\n$\\det(P)=\\lambda_1 \\lambda_2 \\cdots \\lambda_n$ and\n$\\tr(P)=\\lambda_1 + \\lambda_2 + \\ldots + \\lambda_n$.\nSince $P$ and $A$ are similar, $\\det(A)=\\det(P)$ and $\\tr(A)=\\tr(P)$,\nand therefore the results follow.\n\\end{proof}\n", "meta": {"hexsha": "77a56cb2f63c6003f18c2b7a94e9fdb9239d35e6", "size": 19726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityDiagonalization.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/spectraltheoryOrthogonalityDiagonalization.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/spectraltheoryOrthogonalityDiagonalization.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.3908045977, "max_line_length": 357, "alphanum_fraction": 0.6884822062, "num_tokens": 7105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.921921838609201, "lm_q1q2_score": 0.7722201366519974}}
{"text": "\\chapter{Tensor Product Space Transformations}\nLet's consider our good ol' vector space $V$ with basis $\\{\\vec{e}_\\mu\\}$ and its dual space $V^*$ with basis $\\{\\vec{e}^\\nu\\}$.\nWe now know that $\\{\\vec{e}_\\mu\\}$ will transform covariantly, while $\\{\\vec{e}^\\nu\\}$ will transform contravariantly.\nWe always choose $\\{e^\\nu\\}$ such that $\\langle \\vec{e}^\\nu, \\vec{e}_\\mu \\rangle = \\delta^\\nu_\\mu$.\nNow that we've learned about change of basis transformations, let's construct alternate bases for $V$ and $V^*$, called $\\{\\unit{e}_\\mu\\}$ and $\\{\\unit{e}^\\nu\\}$, again with the property that $\\langle \\unit{e}_\\nu, \\unit{e}_\\mu \\rangle = \\delta_\\mu^\\nu$.\nLet's also say for the sake of argument that $\\{\\unit{e}_\\mu\\}$ transforms into $\\{\\vec{e}_\\mu\\}$ using a transformation $\\Lambda$, so we then have that\n\\[ \\unit{e}_\\nu = \\tensor{\\Lambda}{_\\nu^\\mu} \\vec{e}_\\mu. \\]\nBecause the bases of the dual space are contravariant, we know that the equivalent transformation for $\\{\\unit{e}^\\nu\\}$ and $\\{\\vec{e}^\\nu\\}$ would be\n\\[ \\unit{e}^\\nu = \\tensor{\\qty(\\Lambda^{-1})}{_\\mu^\\nu} \\vec{e}^\\mu. \\]\n\nTo understand how transformations affect tensor product spaces, let's construct a rank $(1,2)$ tensor,\n\\[ \\tensor{T}{^\\lambda_{\\mu\\nu}} \\vec{e}_\\lambda \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu, \\]\nand transform it from the $\\vec{e}$ basis into the $\\unit{e}$ basis.\nThis goes in the direction $\\vec{e} \\to \\unit{e}$, which is the opposite way we've gone previously, but the technique remains the exact same.\nWe start by defining the transformation $\\Lambda$ such that\n\\[ \\vec{e}_\\mu = \\tensor{\\Lambda}{_\\mu^\\nu} \\unit{e}_\\nu. \\]\nWe then rewrite our original tensor definition, replace the original bases with their hatted variants and adding the appropriate variant of $\\Lambda$, so that\n\\[ \\tensor{T}{^\\lambda_{\\mu\\nu}}\\vec{e}_\\lambda \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu = \\tensor{T}{^\\lambda_{\\mu\\nu}} \\Big[\\tensor{\\Lambda}{_\\lambda^\\alpha}\\unit{e}_\\alpha\\Big] \\otimes \\qty[\\tensor{\\qty(\\Lambda^{-1})}{_\\beta^\\mu}\\unit{e}^\\beta] \\otimes \\qty[\\tensor{\\qty(\\Lambda^{-1})}{_\\gamma^\\nu}\\unit{e}^\\gamma]. \\]\nBecause tensors are multilinear products, we can factor the $\\Lambda$ and $\\Lambda^{-1}$ out in front of our new bases to get\n\\[ \\tensor{T}{^\\lambda_{\\mu\\nu}}\\Lambda\\Lambda^{-1}\\Lambda^{-1} \\unit{e}_\\lambda \\otimes \\unit{e}^\\mu \\otimes \\unit{e}^\\nu. \\]\nThis means that our component $\\tensor{\\widehat{T}}{^\\lambda_{\\mu\\nu}} = \\tensor{T}{^\\lambda_{\\mu\\nu}}\\Lambda\\Lambda^{-1}\\Lambda^{-1}$.\nThis represents the transformation of the basis of the tensor; if we want to transform the component $\\tensor{T}{^\\lambda_{\\mu\\nu}}$, we need to use the opposite transformations, since each index of the component is opposite the index on the corresponding basis vector.\nThis means that \n\\[ \\tensor{T}{^\\lambda_{\\mu\\nu}} = \\tensor{\\widehat{T}}{^\\lambda_{\\mu\\nu}}\\Lambda\\Lambda\\Lambda^{-1}. \\]\nNote that not only are the transformations inverted, but their order is also reversed; to understand why this is, let's examine the full transformation of our tensor from $\\vec{e}$ to $\\unit{e}$.\nBy replacing each piece of our original tensor with its transformed variant, we see that\n\\begin{align*}\n    \\tensor{T}{^\\lambda_{\\mu\\nu}}\\vec{e}_\\lambda \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu &= \n    \\tensor{\\widehat{T}}{^\\lambda_{\\mu\\nu}}\\Lambda\\Lambda\\Lambda^{-1}\\Lambda\\Lambda^{-1}\\Lambda^{-1} \\unit{e}_\\lambda \\otimes \\unit{e}^\\mu \\otimes \\unit{e}^\\nu \\\\\n    &= \\tensor{\\widehat{T}}{^\\lambda_{\\mu\\nu}}\\unit{e}_\\lambda \\otimes \\unit{e}^\\mu \\otimes \\unit{e}^\\nu.\n\\end{align*}\nJust like how using both $\\Lambda$ and $\\Lambda^{-1}$ to transform an arbitrary vector causes the transformations to cancel, reversing the order of $\\Lambda$ when transforming the basis and the components does the same.\n\n\\subsection{Covariant and Contravariant Tensors}\nThe previous example discussed the transformation of a mixed, rank $(1,2)$ tensor.\nBecause the basis vectors of the tensor product space included both vectors and covectors, some parts of the tensor transformed covariantly and some transformed contravariantly.\nThis needn't always be the case though; consider a rank $(0,3)$ tensor, whose basis would be of the form $\\vec{e}^\\lambda \\otimes \\vec{e}^\\mu \\otimes \\vec{e}^\\nu$, and whose component would be $T_{\\lambda\\mu\\nu}$.\nThis tensor has a basis comprised solely of covectors.\nIt's basis is then completely contravariant, and its component is entirely covariant.\nThis is a \\emph{covariant tensor}.\nNote that we always identify a tensors variance by the variance of its component, not its basis.\nA contravariant tensor might be a rank $(3,0)$ tensor $T^{\\lambda\\mu\\nu}$.\n\\begin{itemize}\n    \\item Covariant tensors are identified with all lower indices, like $T_{\\lambda\\mu\\nu}$, and are of rank $(0,n)$. Their basis is comprised entirely of covectors, and they map $n$-tuples of vectors to a scalar field.\n    \\item Contravariant tensors have all upper indices, like $T^{\\lambda\\mu\\nu}$, and are of rank $(n,0)$. Their basis is entirely products of vectors, and they map $n$-tuples of covectors to a scalar field.\n\\end{itemize}\n", "meta": {"hexsha": "3b6aee91a6adaa439796cce00d9b6b0eba94923d", "size": 5104, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/tps_transformations.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/tps_transformations.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/tps_transformations.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": 108.5957446809, "max_line_length": 320, "alphanum_fraction": 0.7045454545, "num_tokens": 1532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034425, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7722088994218386}}
{"text": "\\lab{Algorithm}{Image Segmentation with Minimal Spanning Trees}{Image Segmentation with Minimal Spanning Trees}\n\\label{Ch:MSTImgSeg}\n\n\\objective{This section teaches about how to use minimum spanning trees to segmentate an image.}\n\n\\section*{Image Segmentation}\n\n%Lab \\ref{MSTImgSeg}\n\nOne application of Minimal Spaning Trees (MSTs) is in image segmentation. Kruskal's algorthm is especially good at this. Let $k$ be the number of divisions that is wanted and $n$ be the number of nodes. Kruskals algorithm is performed until $n-k$ edges is added.\n\nThere are many different ways to turn a image into a graph and weight the edges. A simple, yet effective, version is to make every pixel a node and the edges are the difference in intensities in the four cardinal direction. \n\nThis means that there is less that $4n$ edges. Other image segmentation algorithms have to use $n^2$ space. This gives the MST algorithm a critical advantage over other image segmentation algorithms. \n\n\\begin{problem}\nWrite a function that takes as input a black and white image and outputs a list of the edges where thre egdes are in the form $(node,node,weight)$ and a list of nodes.\n\\end{problem}\n\nThe provided kruskal's algorithm takes as inputs the list of nodes, the list of edges and the number of divisions desired. The number of divisions is often has to be higher than the actual number that is needed because sometimes one or two pixels form a division because the difference between them and the pixels around them is so great. Adjust the number of divisions until the desired result is found.\n\n\\begin{problem}\nPerform the image segmentation algorithm on the image. Then graph the original image and the three highest divisions. (Use the Counter class from collections to find the modes.) \n\\end{problem}\n\n\\begin{problem}\nMake a division of the image a different color.\n\\end{problem}\n\nThis algorithm can also be extended to 3D images. One configuration is that each pixel is a node and the edges are the four cardinal directions, the pixel directly above it and the pixel below it.\n\nThis algorithm can also be used to segment other data such as connections on facebook. \n", "meta": {"hexsha": "8dc93bd1c210ff645de9e687a94751a6bb515fcc", "size": 2157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/ImageSegMST/ImgSegMST.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/ImageSegMST/ImgSegMST.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/ImageSegMST/ImgSegMST.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 65.3636363636, "max_line_length": 404, "alphanum_fraction": 0.7923041261, "num_tokens": 475, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182777, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7721548175389275}}
{"text": "\n\\subsection{Identifying the order of integration using Augmented Dickey-Fuller}\n\nThe Dickey-Fuller test with deterministic time trend was:\n\n\\(\\Delta y_t=\\alpha + \\beta t + \\gamma y_{t-1}+\\epsilon_t \\)\n\nThe Augmented Dickey-Fuller model adds lags for the differences.\n\n\\(\\Delta y_t=\\alpha + \\beta t + \\gamma y_{t-1}+\\sum_i^p \\delta_i \\Delta y_{t-i} + \\epsilon_t \\)\n\n", "meta": {"hexsha": "3956a9c3377d4cedfd27bf917bff08c5c3c5b04b", "size": 366, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/forecastingUni/01-02-ADF.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/forecastingUni/01-02-ADF.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/forecastingUni/06-01-ADF.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.5, "max_line_length": 95, "alphanum_fraction": 0.7213114754, "num_tokens": 114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.931462514578343, "lm_q2_score": 0.8289388040954683, "lm_q1q2_score": 0.7721254228943293}}
{"text": "\\section*{Ex.3.6}\n\\subsection*{Give upper bound for probability}\n\nWe are given $\\abs{A}=10^8, p=1/100, \\mu=10^6$. \n\nFirst note that $\\sqrt{\\mu} = 1,000$, we want to use Lemma~3.2 to bound $\\abs*{X-\\mu}\\geq 10,000$. Hence we find that $q = 10$ as $q\\mu= 10,000$. So\n$$\nP(\\abs*{X-10^6}\\geq 10^4)\\leq \\frac{1}{10^2} = \\frac{1}{100}\n$$\nSo the upper bound is 1\\%.", "meta": {"hexsha": "f623e85fccd7775a9f15052c1cf56461615f7475", "size": 358, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.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": "Uge3/Ex.3.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": "Uge3/Ex.3.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": 35.8, "max_line_length": 148, "alphanum_fraction": 0.6117318436, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418178895029, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.772105282366744}}
{"text": "\nThe hyperexponential (mixture exponential) distribution may be useful\nfor fitting fat-tailed empirical distributions. \n\n\\subsection{Hyperexponential densities}\n\nThe hyperexponential distribution is a mixture of $K$ independent\nexponentials with a common location $\\mu$ and different decay\nconstants $\\lambda_k$.\n\nThe probability density function (PDF) is:\n\n\\begin{equation}\nP(X=x) = \\sum_k^{K} q_k \\lambda_k e^{- \\lambda_k (x - \\mu)}\n\\label{eqn:hyperexp_pdf}\n\\end{equation}\n\nThe cumulative distribution function (CDF) is:\n\n\\begin{equation}\nP(X \\leq x) = \\sum_k^{K} q_k (1 - e^{- \\lambda_k (x - \\mu)})\n\\label{eqn:hyperexp_cdf}\n\\end{equation}\n\nVariate $x$ ranges $\\mu \\leq x < \\infty$.\n\nMixture coefficients $q_k$ specify the prior probability of each\ncomponent $k$; $0 \\leq q_k \\leq 1$ and $\\sum_k q_k = 1$.\n\nThe single location parameter $\\mu$ is unconstrained, $-\\infty < \\mu <\n\\infty$. (Exponential distributions are usually represented without an\nexplicit location parameter, implicitly assuming $\\mu = 0$.)\n\nThe scale parameters $\\lambda_k$ for each component are nonnegative,\n$\\lambda_k > 0$.\n\n\n", "meta": {"hexsha": "9cbd7532593ff67a4e45ba95b8e47597597e32ee", "size": 1101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_hyperexp.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_hyperexp.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_hyperexp.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": 28.9736842105, "max_line_length": 70, "alphanum_fraction": 0.7356948229, "num_tokens": 315, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248225478307, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.772056000343499}}
{"text": "\n\\section{Kullback-Leibler divergence}\n\nBayesian inference means we have full distribution of \\(p(w)\\), not just moments of a specific point estimate\n\n\\subsection{Cross entropy:}\n\n\\(H(P,Q)=E_P(I(Q))\\)\n\nSo for a discrete distribution this is:\n\n\\(H(P,Q)=-\\sum_x P(x)\\log Q(x)\\)\n\n\\(Q\\) is prior\n\n\\(P\\) is posterior\n\n\\subsection{Kullback-Leibler divergence}\n\nWhen we move from a prior to a posterior distribution, the entropy of the probability distribution changes.\n\n\\(D_{KL}(P||Q)=H(P,Q)-H(P)\\)\n\nKL divergence is also called the information gain.\n\n\\subsection{Gibb's inequality}\n\n\\(D_{KL}(P||Q)\\ge 0\\)\n\n", "meta": {"hexsha": "1e92513c140d39846d94b191c5086ac9298e0415", "size": 601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/choosing/04-01-KLD.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/choosing/04-01-KLD.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/choosing/04-01-KLD.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.0333333333, "max_line_length": 109, "alphanum_fraction": 0.7088186356, "num_tokens": 170, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768588653856, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7719349029194184}}
{"text": "\n\\subsection{Translation symmetry}\n\nThe distance between two vectors is:\n\n\\((v-w)^TM(v-w)\\)\n\nSo what operations can we do now?\n\nAs before, we can do the transformations which preserve \\(u^TMv\\), such as the orthogonal group.\n\nBut we can also do other translations\n\n\\((v-w)TM(v-w)\\)\n\n\\(v^TMv+w^TMw-v^TMw-w^TMv\\)\n\nso symmetry is now \\(O(3,1)\\) and affine translations\n\n\\subsubsection{Translation matrix}\n\n\\([[1,x][0, 1]]\\) moves vector by \\(x\\).\n\n\n", "meta": {"hexsha": "c4834ee4d703bee384f742aa3b6b1a1c5d362733", "size": 446, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/affineEuclid/01-03-translation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/affineEuclid/01-03-translation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/affineEuclid/01-03-translation.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.84, "max_line_length": 96, "alphanum_fraction": 0.6838565022, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850110816423, "lm_q2_score": 0.8244619306896955, "lm_q1q2_score": 0.7719313479121938}}
{"text": "\\section{Numerical Differentiation}\nTo approximate $f'(x)$($x_0\\in(a,b)$, $f\\in C^2[a,b]$), $x_1=x_0+h\\in[a,b]$.\n\\begin{align*}\n    & f(x) = P_{0,1}(x)+\\frac{(x-x_0)(x-x_1)}{2!}f''(\\xi(x)) \\\\\n    & \\phantom{f(x)} = \\frac{f(x_0)(x-x_0-h)}{-h}+\\frac{f(x_0)(x-x_0)}{h}+\\frac{(x-x_0)(x-x_1)}{2}f''(\\xi(x)) \\\\\n    \\Rightarrow & f'(x) = \\frac{f(x_0+h)-f(x_0)}{h}+\\frac{2(x-x_0)-h}{2}f''(\\xi(x))+\\frac{(x-x_0)(x-x_0-h)}{2}D_x\\left(f''(\\xi(x))\\right) \\\\\n    \\Rightarrow & f'(x_0)=\\frac{f(x_0+h)-f(x_0)}{h}-\\frac{h}{2}f''(\\xi)\n\\end{align*}\nThe above formula is known as the forward-difference formula if $h>0$, and the backward-difference formula if $h<0$.\n\n\\begin{theo}[(n+1)-point Formula]\n$\\{x_0,x_1,\\ldots,x_n\\}$ are $(n+1)$ distinct numbers in interval $I$, $f\\in C^{n+1}(I)$.\n\\begin{align*}\n    & f(x) = \\sum_{k=0}^nf(x_k)L_k(x)+\\prod_{k=0}^n\\left(\\frac{x-x_k}{k+1}\\right)f^{(n+1)}(\\xi(x)). \\\\\n    \\Rightarrow & f'(x) = \\sum_{k=0}^nf(x_k)L_k'(x)+D_x\\left[\\prod_{k=0}^n\\left(\\frac{x-x_k}{k+1}\\right)\\right]f^{(n+1)}(\\xi(x)) \\\\\n    & \\phantom{f(x)} + \\prod_{k=0}^n\\left(\\frac{x-x_k}{k+1}\\right) D_x\\left[f^{(n+1)}(\\xi(x))\\right]. \\\\\n    \\Rightarrow & f'(x_j) = \\sum_{k=0}^nf(x_k)L_k'(x_j)+\\frac{f^{(n+1)}(\\xi(x_j))}{(n+1)!}\\prod_{k=0 \\atop k\\neq j}^n(x_j-x_k).\n\\end{align*}\n\\end{theo}\n\n\\subsection{Three-Point Formulas}\nIf the nodes are equally spaced, $x_1=x_0+h$, $x_2=x_0+2h$, then\n\\begin{itemize}\n    \\item Three-Point Formula\n    \\[\n     f'(x_0) = \\frac{1}{h}\\left[\\frac{1}{2}f(x_0)-2f(x_0+h)+\\frac{3}{2}f(x_0+2h)\\right] + \\frac{h^2}{3}f^{(3)}(\\xi_0).\n    \\]\n    \\item Three-Point Endpoint Formula\n    \\[\n     f'(x_0) = \\frac{1}{h}\\left[-\\frac{3}{2}f(x_0)+2f(x_0+h)-\\frac{1}{2}f(x_0+2h)\\right] + \\frac{h^2}{3}f^{(3)}(\\xi_1).\n    \\]\n    \\item Three-Point Midpoint Formula\n    \\[\n     f'(x_0) = \\frac{1}{h}\\left[-\\frac{1}{2}f(x_0-h)+\\frac{1}{2}f(x_0+h)\\right] - \\frac{h^2}{6}f^{(3)}(\\xi_2).\n    \\]\n\\end{itemize}\n\n\\subsection{Five-Point Formulas}\n\\begin{itemize}\n    \\item Five-Point Midpoint Formula\n    \\begin{align*}\n    f'(x_0)&=\\frac{1}{12h}\\left[f(x_0-2h)-8f(x_0-h)+8f(x_0+h)\\right.\\\\\n    &\\left.-f(x_0+2h)\\right] + \\frac{h^4}{30}f^{(5)}(\\xi).\n    \\end{align*}\n    \\item Five-Point Endpoint Formula\n    \\begin{align*}\n    f'(x_0)&=\\frac{1}{12h}\\left[-25f(x_0)+48f(x_0+h)-36f(x_0+2h)\\right.\\\\\n    &\\left.+16f(x_0+3h-3f(x_0+4h))\\right] + \\frac{h^4}{5}f^{(5)}(\\xi).\n    \\end{align*}\n\\end{itemize}\n\n\\subsection{Second Derivative Midpoint Formula}\n\\[\nf''(x_0)=\\frac{1}{h}\\left[f(x_0-h)-2f(x_0)+f(x_0+h)\\right] - \\frac{h^2}{12}f^{(4)}(\\xi)\n\\]\nIf $f^{(4)}$ is continuous on $[x_0-h,x_0+h$, it is also bounded, and the approximation is $O(h^2)$.\n\n\\subsection{Round-Off Error Instability}\n\\[\nf'(x_0)=\\frac{1}{2h}\\left[f(x_0+h)-f(x_0-h)\\right] - \\frac{h^2}{6}f^{(3)}(\\xi_1)\n\\]\nSuppose that in evaluating $f(x_0+h)$ and $f(x_0-h)$ we encounter round-off errors $e(x_0+h)$ and $e(x_0-h)$.\n\\[\nf(x_0+h)=\\tilde{f}(x_0+h)+e(x_0+h)\\qquad and\\qquad f(x_0-h)=\\tilde{f}(x_0-h)+e(x_0-h)\n\\]\nThe total error in the approximation\n\\begin{align*}\n\\abs{f'(x_0)-\\frac{\\tilde{f}(x_0+h)-\\tilde{f}(x_0-h)}{2h}}&=\\abs{\\frac{e(x_0+h)-e(x_0-h)}{2h}-\\frac{h^2}{6}f^{(3)}(\\xi_1)} \\\\\n& \\leq \\frac{\\varepsilon}{h}+\\frac{h^2}{6}M,\n\\end{align*}\nwhere $e(x_0\\pm h)$ are bounded by $\\varepsilon>0$ and $f^{(3)}$ are bounded by $M>0$. There is an optimal $h$ such that the bound is small.\n", "meta": {"hexsha": "8d0a8faea867e4512c0c848410136acf167f6898", "size": 3349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/4.1_Numerical_differentiation.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.1_Numerical_differentiation.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.1_Numerical_differentiation.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.5138888889, "max_line_length": 140, "alphanum_fraction": 0.5762914303, "num_tokens": 1599, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942377652496, "lm_q2_score": 0.8670357512127872, "lm_q1q2_score": 0.771916933241209}}
{"text": "\\section{Logarithms}\\label{sec:Logarithms}\r\nRecall the \\ifont{three kinds} of exponential functions $f(x)=a^x$ depending on whether $0<a<1$, $a=1$ or $a>1$:\r\n$$\\includegraphics[width=6.5in]{images/exp3}$$\r\nSo long as $a\\neq 1$, the function $f(x)=a^x$ satisfies the horizontal line test and therefore has an inverse.\r\nWe call the \\ifont{inverse of $a^x$} the \\dfont{logarithmic function with base a} and denote it by $\\log_a$.\r\nIn particular,\r\n$$\\log_a x=y\\iff a^y=x.$$\r\nThe \\ifont{cancellation formulas} for logs are:\r\n$$\\log_a(a^x)=x,\\mbox{\\quad for every $x\\in\\R$},$$\r\n$$a^{\\log_a(x)}=x,\\mbox{\\quad for every $x>0$}.$$\r\nSince the function $f(x)=a^x$ for $a\\neq 1$ has domain $\\mathbb{R}$ and range $(0,\\infty)$, \r\nthe logarithmic function has domain $(0,\\infty)$ and range $\\mathbb{R}$.\r\nFor the most part, we only focus on logarithms with a base larger than \r\n$1$ (i.e., $a>1$) as these are the most important.\r\n$$\\includegraphics[width=3.0in]{images/log1}$$\r\nNotice that every logarithm passes through the point $(1,0)$ in the same way that every exponential function passes through the point $(0,1)$.\r\n\r\nSome properties of logarithms are as follows.\r\n\r\n\\begin{formulabox}[Logarithm Properties]\r\nLet $A,B$ be positive numbers and $b>0$ ($b\\neq1$) be a base.\r\n\\begin{itemize}\r\n\t\\item $\\ds{\\log_b(AB)=\\log_b A+\\log_b B}$,\r\n\t\\item $\\ds{\\log_b\\left(\\frac{A}{B}\\right)=\\log_b A-\\log_b B}$,\r\n\t\\item $\\ds{\\log_b(A^n)=n\\log_b A}$, where $n$ is any real number.\r\n\\end{itemize}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Compute Lorarithms}{ComputeLorarithms}\r\nTo compute $\\log_2(24)-\\log_2(3)$ we can do the following:\r\n$$\\log_2(24)-\\log_2(3)=\\log_2\\left(\\frac{24}{3}\\right)=\\log_2(8)=3,$$\r\nsince $2^3=8$.\r\n\\end{example}\r\n\r\n\\subsection*{The Natural Logarithm}\r\nAs mentioned earlier for exponential functions, the number $e\\approx 2.71828\\ldots$ \r\nis the most convenient base to use in Calculus.\r\nFor this reason we give the logarithm with base $e$ a special name: \\dfont{the natural logarithm}.\r\nWe also give it special notation:\r\n$$\\log_ex=\\ln x.$$\r\n\r\nYou may pronounce $\\ln$ as either: ``el - en'', ``lawn'', or refer to it as ``natural log''.\r\nThe above properties of logarithms also apply to the natural logarithm.\r\n \r\nOften we need to turn a logarithm (in a different base) into a natural logarithm.\r\nThis gives rise to the \\ifont{change of base formula}.\r\n\r\n\\begin{formulabox}[Change of Base Formula]\r\n$$\\log_ax=\\frac{\\ln x}{\\ln a}.$$\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Combine Logarithms}{CombineLogarithms}\r\nWrite $\\ln A+2\\ln B -\\ln C$ as a single logarithm.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing properties of logarithms, we have,\r\n$$\\begin{array}{rcl}\r\n\\ln A+2\\ln B -\\ln C & = & \\ln A + \\ln B^2 - \\ln C\\\\\r\n~&=& \\ln (AB^2) - \\ln C\\\\\r\n~&=& \\ds{\\ln\\frac{AB^2}{C}}\\\\\r\n\\end{array}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Solve Exponential Equations using Logarithms}{SolveExponentialEquationsLogarithms}\r\nIf $e^{x+2}=6e^{2x}$, then solve for $x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nTaking the natural logarithm of both sides and noting the cancellation formulas (along with $\\ln e=1$), we have:\r\n$$\\begin{array}{rcl}\r\ne^{x+2} & = & 6e^{2x}\\\\\r\n\\\\\r\n\\ln e^{x+2}&=& \\ln (6e^{2x})\\\\\r\n\\\\\r\nx+2&=& \\ln 6 + \\ln e^{2x}\\\\\r\n\\\\\r\nx+2&=& \\ln 6 + 2x\\\\\r\n\\\\\r\nx&=& 2-\\ln 6\\\\\r\n\\end{array}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Solve Logarithm Equations using Exponentials}{SolveLogarithmEquationsExponentials}\r\nIf $\\ln(2x-1)=2\\ln(x)$, then solve for $x$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n``Taking $e$'' of both sides and noting the cancellation formulas, we have:\r\n$$\\begin{array}{rcl}\r\ne^{\\ln(2x-1)} & = & e^{2\\ln(x)}\\\\\r\n\\\\\r\n(2x-1) & = & e^{\\ln(x^2)}\\\\\r\n\\\\\r\n2x-1 & = & x^2\\\\\r\n\\\\\r\nx^2-2x+1 & = & 0\\\\\r\n\\\\\r\n(x-1)^2 & = & 0\\\\\r\n\\end{array}$$\r\nTherefore, the solution is $x=1$.\r\n\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:Logarithms}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nExpand $\\ds\\log_{10} ((x+45)^7 (x-2))$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nExpand $\\ds\\log_2 {\\frac{x^3}{3x-5 +(7/x)}}$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nWrite $\\ds \\log_2 3x + 17 \\log_2 (x-2) -\r\n2\\log_2 (x^2 + 4x + 1)$ as a single logarithm.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSolve $\\ds \\log_2 (1+ \\sqrt{x} ) = 6$ for  $x$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSolve $\\ds 2^{x^2} = 8$ for $x$.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSolve $\\ds \\log_2 (\\log_3 (x) ) = 1$ for $x$.\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "f9cd33235dc4d5bf6a8d38106a5bf08fc5b6c36d", "size": 4489, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-5-logarithms.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-5-logarithms.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-5-logarithms.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.6126760563, "max_line_length": 143, "alphanum_fraction": 0.6259746046, "num_tokens": 1630, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361509525463, "lm_q2_score": 0.8459424373085146, "lm_q1q2_score": 0.7718684614251967}}
{"text": "i\\documentclass[10pt]{article}\n\\title{Math 180A: Introduction to Probability}\n\\author{Suhas Arehalli}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\n\\begin{document}\n\\maketitle\n\\newcommand{\\indefint}{\\int_{-\\infty}^{\\infty}}\n\n\\section{Preliminaries}\n\nFirst, fundamental definitions:\n\\begin{description}\n    \\item[Experiment] A procedure that can lead to certain outcomes.\n    \\item[Sample Space] A set $\\Omega$ of all possible outcomes of an\n    experiment. The \"image\" of an experiment.\n    \\item[Event] A subset of the sample space $\\Omega$. \n\\end{description}\n\nNow, using this, we can define \\textbf{Kolmogorov's Axioms of Probability}, which tell us that a function \n$ P: \\Omega \\rightarrow [0, 1] $ is a probability if and only if \n\\begin{enumerate}\n    \\item $\\forall A \\subset \\Omega, 0 \\leq P(A) \\leq 1$. Probabilities must be positive and less that 1.\n    \\item $P(\\Omega) = 1$. The probability of having an outcome must be 1.\n    \\item Given a disjoint $A$ and $B$, $P(A \\cup B) = P(A) + P(B)$. The\n        probability of either 2 mutually exclusive events occurring is the sum of\n        their individual probabilities. \n    \\item Given an infinite sequence $A_1, A_2, ...$ of pairwise disjoint ($A_i \\cap A_j = \\emptyset $) events, \n             \\[P\\left(\\bigcup_{i = 0}^{\\infty} A_i\\right) =  \\sum_{i =0}^{\\infty} P(A_i) \\] \n         This is extends Axiom 3 to the infinite case.\n\\end{enumerate}\n\nWe also have several useful properties that come out of this:\n\\begin{description}\n    \\item[Complementary Probabilities] $P(A^c) = 1 -P(A)$. \\\\\n        The probability of the complement of\n        an event $A$ is $P(A^c) = P(\\Omega \\setminus A)$, and since \n        $(\\Omega \\setminus A) \\cup A = \\Omega$, $P(A^c) + P(A) = 1$ and thus \n        $P(A^c) = 1 -P(A)$. \n        Calculating complementary probabilities can sometimes be easier that\n        calculating probabilities directly.\n    \\item[Inclusion-Exclusion] $P(A \\cup B) = P(A) + P(B) + P(A \\cap B)$.\\\\\n        We know\n        \\begin{align*}\n            P(A) = P(A \\cap B) + P(A \\cap B^c) \\\\ \n            P(B) = P(A \\cap B) + P(A^c \\cap B) \n        \\end{align*}\n        Thus \n        \\[P(A) + P(B) = 2P(A \\cap B) + P(A \\cap B^c) + P(A^c \\cap B)\\] \n        and since \n        \\[P(A \\cap B^c) + P(A^c \\cap B) + P(A \\cap B) = P(A \\cup B)\\] \n        we can rearrange to obtain the desired equality. \n    \\item[Monotonicity] If $A \\subset B$, the $P(A) \\leq P(B)$. \\\\\n        if $A \\subset B$, then $B \\cap A^c \\neq \\emptyset$ and $A \\cap B = A$, and thus\n        $P(B) - P(A) = P(A^c \\cap B) \\geq 0$, which shows the necessary inequality.\n\\end{description}\n\nNow we can discuss independence:\n\\begin{description}\n    \\item[Independence] Two events, $A$ and $B$, are independent if and only if \n        \\[ P(A \\cap B) = P(A)P(B) \\]\n\\end{description}\n\nThat's pretty quick. Now to random variables and distributions.\n\\begin{description}\n    \\item[Random Variable] A random variable is a function $X: \\Omega \\rightarrow \\mathbb{F}$ for some field \n        $\\mathbb{F}$ ($\\mathbb{Z}$ or $\\mathbb{N}$ for discrete random variables and $\\mathbb{R}$ for continuous)\n        that maps numbers to outcomes of an experiment. Common choices are the sums of the faces of\n        2 rolled dice, then number of heads after a series of coin flips, etc. You're really never\n        \\textit{that} formal about it.\n    \\item[Distribution (Discrete)] A distribution of a random variable X is a\n        probability $P(X = x)$ for all $x$ in the image of $X$. These also obey the\n        probability axioms, with the sample space being the image\n        of $X$.\n    \\item[Expectation (Discrete)] The expectation, or expected value of a discrete random variable $X$ is \n        \\[ E[X] = \\sum_{x} x P(X = x) \\]\n        consider it an average of outcomes (made numerical by our random variable)  weighted by their \n        probabilities. \\\\\\\\\n        \\textbf{Expectation is Linear}. Thus, for scalars ${a_i}$ and random vars ${X_i}$\n        \\[ E\\left[\\sum_i a_iX_i\\right] = \\sum_i a_iE[X_i] \\]\n    \\item[Moments] The expectation is a specific case of a moment, particularly the 1st moment. the kth moment\n        of a random variable is defined as\n        \\[ E[X^k] = \\sum_x x^k P(X = x) \\]\n    \\item[Variance] We define the variance as the centered 2nd moment, namely\n        \\[ var[X] = E[(X - E[X])^2] = E[X^2] - E[X]^2 \\]\n\\end{description}\n\nAnd that's the basics.\n\n\\section{Combinatorial Probability}\n\nThe following rules allow you to count the outcomes of nearly any experiment\n\n\\begin{description}\n    \\item[Multiplication Rule] Given $m$ experiments with the $i$th experiment having $n_k$ outcomes, we have \n        $\\prod_{i = 0}^{m} n_k$ total outcomes\n    \\item[Ordering] Given a set of $n$ objects, we can arrange them in $n!$ unique orders.\n    \\item[Combinations] The number of ways to choose $k$ objects from a set of $n$ is the binomial coefficient \n        \\[ \\binom{n}{k} = \\frac{n!}{k!(n-k)!} \\]\n    \\item[Partitioning] The number of ways to partition a set into $m$ groups of sizes $n_1, ..., n_m$ with \n        $\\sum_i n_i = n$ is the multinomial coefficient\n        \\[ \\binom{n}{n_1, ..., n_m} = \\frac{n!}{\\prod_i (n_i!)} \\]\n\\end{description}\n\n\\par\nWith these counting tools, we can calculate probabilities of complex events\n\n\n\n\\begin{description}\n    \\item[Urn Problems] The probability of choosing  $k$ items from a subset of size $m$ \n        from a set of $n$ items is\n        \\[ \\frac{\\binom{m}{k}}{\\binom{n}{k}} \\]\n\\end{description}\n\n\\begin{description}\n    \\item[Binomial Distribution] \n        Suppose a random variable $X \\sim binom(n, p)$, or is distributed according to a binomial distribution \n        with parameters $n$ and $p$. Then \n        \\[ P(X = k) = \\binom{n}{k}p^k(1-p)^{n-k} \\]\n        which represents the probability of having exactly $k$ successes after $n$ trials of an experiment \n        with a success rate of $p$. \\\\\\\\\n        Consider that there are $\\binom{n}{k}$ ways of choosing where the $k$ successes occur, and for each\n        of these trials, the trial occurs with probability $p^k(1-p)^{n-k}$. Thus the total probability is\n        as given. \\\\\\\\\n\n        \\textbf{Expected Value:} \n            Rephrase in terms of indicator random variables $X_i$, which are 1 if the $i$th trial succeeds and\n            0 otherwise.:\n            \\begin{align*}\n                X &= \\sum_{k = 1}^n X_i \\\\\n                E[X] &= E\\left[\\sum_{k=1}^n X_i\\right] = \\sum_{k=1}^n E[X_i] \n            \\end{align*}\n            and since $E[X_i]$ is simply $p$,\n            \\begin{align*}\n                E[X] &= \\sum_{k=1}^n p = np \n            \\end{align*}\n        \\textbf{Variance:}\n            As above,\n            \\begin{align*}\n                var[X] &= var\\left[\\sum_{k=1}^n X_i\\right] = \\sum_{k=1}^n var[X_i] = n(var[X_i])\n            \\end{align*}\n            to find $var[X_i]$,\n            \\begin{align*}\n                E[X_i] &= (1)(p) + (0)(1-p) \\\\\n                E[X_i^2] &= (1^2)p + (0^2)(1-p) \\\\\n                E[X_i^2] &= p \\\\\n                var[X_i] &= E[X_i^2] - E[X_i]^2 \\\\\n                var[X_i] &= p - p^2 = p(1-p)\n            \\end{align*}\n            thus,\n            \\[ var[X] = np(1-p) \\]\n\n\\end{description}\n\\par\nThese can easily extend to experiments with more than one outcome (using the multinomial distribution), but this\ndistrbution is higher dimensional, so don't worry too much about the distribution.\n\nThe binomial distribution isn't always easy to calculate, especially when $n$ becomes large. However, we can use the \\textbf{Poisson Distribution} to approximate the binomial distribution for large $n$\n\n\\begin{description}\n    \\item[Poisson Distribution] \n        Suppose $ X \\sim poisson(\\lambda) $. Then\n        \\[ P(X = k) = \\frac{\\lambda ^k}{k!} e^{-\\lambda}, k \\in \\mathbb{N} \\]\n        \\\\\\\\\n        \\textbf{Expected Value:}\n        Note that $e^x = \\sum_{k=0} \\frac{x^k}{k!}$. Taylor series.\n        \\begin{align*}\n            E[X] &= \\sum_{k=0}^{\\infty}k\\frac{\\lambda ^k}{k!} e^{-\\lambda} = e^{-\\lambda}\\sum_{k=0}^{\\infty}k\\frac{\\lambda ^k}{k!} \\\\\n            &= e^{-\\lambda}\\sum_{k=0}^{\\infty}\\frac{\\lambda ^k}{(k-1)!} \\\\\n            &= \\lambda e^{-\\lambda}\\sum_{k=1}^{\\infty}\\frac{\\lambda ^{k-1}}{(k-1)!} \\\\\n            &= \\lambda e^{-\\lambda}e^{\\lambda} = \\lambda \\\\\n        \\end{align*}\n        \\textbf{Variance:}\n        Here, note that $E[X^2] = E[X(X-1)] + E[X]$\n        \\begin{align*}\n            E[X(X-1)] &= e^{-\\lambda}\\sum_{i=0}^{\\infty}(k)(k-1) \\frac{\\lambda^k}{k!}\\\\\n            &= \\lambda ^2 e^{-\\lambda}\\sum_{i=2}^{\\infty}\\frac{\\lambda^{k-2}}{(k-2)!} \\\\\n            &= \\lambda ^2 \\\\\n            var[X] &= E[X^2] - E[X]^2 = E[X(X-1)] + E[X] - E[X]^2 \\\\\n            &= \\lambda ^2 + \\lambda - \\lambda ^2 = \\lambda \n        \\end{align*}\n\n    \\item[Poisson Approximation Theorem]\n        Suppose $S_n \\sim binom(n,p_n)$ and $X \\sim poisson(\\lambda)$. If,\n        $\\lim_{n\\rightarrow \\infty} p_n = 0$ and $\\lim{n \\rightarrow \\infty} np_n = \\lambda$, then\n        \\[\\lim_{n \\rightarrow \\infty} P(S_n = k) = P(X = k) \\]\n\\end{description}\n\\par\nThus, if we have a large $n$ in a binomial distribution, we can allow $\\lambda = np$ and approximate it using\nthe Poisson distribution.\n \n\\section{Conditional Probability}\n\\begin{description}\n    \\item[Conditional Probability] The probability of $A$ given $B$ is defined as\n        \\[ P(A|B) = \\frac{P(A \\cap B)}{P(B)} \\]\n    Note that if we let $F(A) = P(A|B)$, $F: \\Omega \\rightarrow [0,1]$ is a probability as defined by \n    Kolmogorov's axioms. It can also be rephrased as \n        \\[ P(A \\cap B) = P(A|B)P(B) = P(B|A)P(A) \\]\n    Which tells us that A and B are independent if and only if\n        \\[ P(A|B) = P(A) \\]\n    \\item[Law of Total Probability] If we create a \\textbf{partition} of $\\Omega$ $B_1, ..., B_n$, meaning\n        $\\bigcup_i B_i = \\Omega$ and $B_i \\cap B_j = \\emptyset, \\forall i \\neq j$, then\n        \\[ P(A) = \\sum_{i=0}^n P(A|B_i)P(B_i) \\] \n    \\item[Bayes' Rule] Using the above, we can obtain\n        \\[ P(B_i|A) = \\frac{P(A|B_i)P(B_i)}{P(A)} = \\frac{P(A|B_i)P(B_i)}{\\sum_{j = 1}^n P(A|B_j)P(B_j)} \\]\n\\end{description}\n\nNow we can consider joint probabilities: the probability that 2 or more random variable both equal specific values.\n\n\\begin{description}\n    \\item[Joint Probability Distribution] We define a joint probability distribution for random variables \n        $X$ and $Y$ as a distribution \n        \\[P(X = x,..., X_n = x_n) = P(X = x \\cap ... \\cap  X_n = x_n)\\]\n    \\item[Marginal Distribution] Given a joint distribution $P(X_1, ... X_n)$, we can find a marginal \n        distribution $P(X_i = k)$ since\n        \\[ P(X_i = k) = \\sum_{x_1}...\\sum_{x_{i-1}}\\sum_{x_{i+1}}...\\sum_{x_n} P(X_1 = x_1,...,X_i = k,...,X_n = x_n) \\]\n        Basically, sum over everything \\textit{but} the random variable you want a distribution for. With 2 \n        random variables.\n        \\[ P(X = k) = \\sum_y P(X = k, Y = y) \\]\n    \\item[Independence Redux] We can also say 2 random variables are independent if \n        \\[P(X = x, Y = y) = P(X = x)P(Y = y), \\forall x,y \\]\n\\end{description}\n\nWe can now talk about conditional distributions. Again, exactly what you'd expect.\n\n\\begin{description}\n    \\item[Conditional Distribution] \n        \\[P(X = x | Y = y) = \\frac{P(X = x, Y = y)}{P(Y = y)} = \\frac{P(X = x, Y = y)}{\\sum_u P(X = x, Y = y)} \\]\n    \\item[Conditional Expectation] \n        \\[E[X | Y = y] = \\sum_x xP(X = x | Y = y) \\]\n\\end{description}\n\n\\section{Continuous Distributions}\n\nSo far we've discussed distributions that take discrete values. Now we can move to distributions of random \nvariables that take continuous values.\n\n\\begin{description}\n    \\item[Continuous Random Variable] A function from $X: \\Omega \\rightarrow \\mathbb{R}$ that maps outcomes \n        to continuous, real values. See above for more info on Random Variables.\n    \\item[Probability Density Function] A function $f: \\mathbb{R} \\rightarrow \\mathbb{R}$ such that \n        \\begin{align*}\n            f(x) &\\geq 0 \\\\\n            \\int_{-\\infty}^{\\infty} f(x)dx &= 1\n        \\end{align*}\n        is a Probability Density Function for a continuous random variable $X$ if\n        \\[ P(a \\leq X \\leq b) = \\int_{a}^{b} f(x)dx \\]\n    \\item[Expected Value (Continuous)] For a continuous random variable $X$, the Expected Value of $X$ is\n        \\[ E[X] = \\int_{-\\infty}^{\\infty} xf(x)dx \\]\n        And further, for some function $r: \\mathbb{R} \\rightarrow \\mathbb{R}$\n        \\[ E[r(X)] = \\int_{-\\infty}^{\\infty} r(x)f(x)dx \\]\n    \\item[Cumulative Distribution Function] We define the distribution function $F: \\mathbb{R} \\rightarrow \\mathbb{R}$\n        for continuous random variable $X$ as\n        \\[ F(x) = P(X \\leq x) = \\int_{-\\infty}^{x} f(y)dy \\] \n        Note the parallels to the antiderivative. Namely\n        \\[ P(a \\leq X \\leq b) = \\int_{a}^{b} f(x)dx = F(b) - F(a) \\]\n\\end{description}\n\nAnd now let's give examples of common continuous distributions \n\\newpage\n\\begin{description}\n    \\item[Uniform Distribution]\n        let $ X \\sim uniform(a,b)$.  \\\\\n        \\textbf{PDF} \n        \\[ f(x) = \\begin{cases}\n                    \\frac{1}{b-a} & x \\in [a,b] \\\\\n                    0 & otherwise\n                  \\end{cases} \\]\n        \\textbf{Expected Value}\\\\\n        \\begin{align*}\n            E[X] &=  \\indefint xf(x)dx \\\\\n                 &= \\int_{a}^{b} (x)\\left( \\frac{1}{b-a} \\right)dx \\\\\n                 &= \\left( \\frac{1}{b-a} \\right) \\int_a^b xdx  \\\\\n                 &= \\left( \\frac{1}{b-a} \\right) \\left[\\frac{x^2}{2}\\right]_a^b   \\\\\n                 &= \\frac{b^2 - a^2}{2(b-a)} \\\\\n                 &= \\frac{b + a}{2}\n        \\end{align*}\n        \\textbf{CDF}\\\\\n        \\begin{align*} \n            F(x) &= \\int_{-\\infty}^{x} f(y)dy \\\\\n                 &= \\int_{a}^{x} \\left(\\frac{1}{b-a} \\right)dy, x \\in [a,b] \\\\ \n                 &= \\frac{x - a}{b -a}\\\\\n            F(x) &= \\begin{cases}\n                     0 & x \\leq a  \\\\\n                     \\frac{x-a}{b-a} & x \\in [a,b] \\\\\n                     1 & x \\geq b \n                    \\end{cases}\n        \\end{align*}\n    \\newpage\n    \\item[Exponential Distribution] \n        Let $ X \\sim exp(\\lambda) $. \\\\\n        \\textbf{PDF}\n        \\[ f(x) = \\begin{cases}\n                    0 & x < 0 \\\\\n                    \\lambda e^{-\\lambda x} & x \\geq 0\n        \\end{cases} \\]\n        \\textbf{Expected Value} \n        \\begin{align*}\n            E[X] &= \\indefint f(x)dx \\\\ \n                 &= \\int_0^{\\infty} \\lambda e^{-\\lambda x}dx \\\\ \n                 &= \\lambda \\int_0^{\\infty} e^{-\\lambda x}dx \\\\\n                 &= \\lambda \\left[ - \\frac{1}{\\lambda} e^{-\\lambda x}dx \\right]_0^{\\infty} \\\\\n                 &= 0 - (-1) = 1\n        \\end{align*}\n        \\textbf{CDF} \n        \\begin{align*}\n            F(x) &= \\int_{-\\infty}^{x} f(x)dx \\\\\n                 &= \\int_0^x \\lambda e^{- \\lambda x} dx \\\\\n                 &=  \\left[ - e^{- \\lambda x} \\right]_0^x \\\\\n                 &= - e^{- \\lambda x} - (-1) \\\\\n                 &= 1 - e^{- \\lambda x}\n        \\end{align*}\n    \\newpage\n\\end{description}\n\\par\nNow lets discuss a few transformations that are useful theoreticall and practically.\n\\begin{description}\n    \\item[Reduction to the Uniform]. Let $X$ have some arbitrary continuous distribution. Then \n        $ Y = F(X)$ is uniform on $(0,1)$.\n        \\\\\\\\\n        Define the inverse of $F$, $F^{-1}$, as\n        \\[ F^{-1} = min\\{x: F(x) \\geq y\\} \\]\n        Since a distribution is not necessarily bijective, we just use the minimum satisfying value.\n        Now we have,\n        \\begin{align*}\n            P(F(X) < y) &= P(X < F^-1(y)) \\\\\n                        &= F(F^-1(y)) = y\n        \\end{align*}\n        Which is the CDF of the uniform distribution on $[0,1]$, thus, \n        \\[Y \\sim uniform(0,1)\\]\n    \\item[Construction from Uniform] Let $X \\sim uniform(0,1)$. Then $Y = F^{-1}(X)$ has distribution\n        function $F$.\n        \\\\\\\\\n        Note that, as defined, $F^{-1}(y) \\leq x$ iff $F(x) \\geq y$. Then\n        \\begin{align*}\n            P(F^{-1}(X) \\leq y) &= P(U \\leq F(y)) \\\\\n                                &= F(x)\n        \\end{align*}\n        (\\textit{Note that $P(X \\leq x)$ for $X \\sim Uniform(0,1)$})\n\\end{description}\n\nAnd now for general functions of random variables\n\n\\begin{description}\n    \\item[PDFs of r(X)] Given a random variable $X$ with PDF $f_X(x)$, the distribution\n        function of $Y = r(X)$, $f_Y(y)$ is\n        \\[ f_Y(y) = f(r^{-1}(y))\\frac{d}{dy}\\left[r^{-1}(y)\\right] \\]\n        This follows from the chain rule.\n        Calculate using the CDF and the theorems above, then derive and use the chain rule. \n        \\begin{align*}\n            F_Y(y) &= P(r(X) < y) \\\\\n                   &= P(X < r^{-1}(y)) \\\\\n                   &= F(r^{-1}(y)) \\\\\n            \\int_{-\\infty}^{y} f_Y(t)dt &= \\int_{-\\infty}^{y} f_X(r^{-1}(t))dt \\\\\n            \\frac{d}{dy}\\left[ \\int_{-\\infty}^{y} f_Y(t)dt\\right] &= \\frac{d}{dy}\\left[ \\int_{-\\infty}^{y} f_X(r^{-1}(t))dt\\right] \\\\\n            f_Y(y) &= f_X(r^{-1}(y))\\frac{d}{dy}\\left[r^{-1}(y)\\right]\n        \\end{align*}\n\\end{description}\n\nNow we discuss joint and conditional distributions in terms of Continuous Random Variables.\n\n\\begin{description}\n    \\item[Joint Density Function] A joint density function $f_{X,Y}$ for continuous random variables $X,Y$ if for\n        all $A \\subset \\mathbb{R}^2$\n        \\[ P((x,y) \\in A)  = \\iint_A f_{X,Y}(x,y)dxdy \\]\n        Also note that\n        \\[ \\iint_{\\mathbb{R}^2} f_{X,Y}dxdy = 1 \\]\n    \\item[Marginal Distributions (Continuous)] Given a joint density function $F_{X,Y}$ for continuous random variables $X,Y$, we can calculate \n        \\begin{align*}\n            f_X(x) = \\indefint f_{X,Y}(x,y)dy \\\\c{d}{dy}\\left[r^{-1}(y)\\right]\n            f_Y(y) = \\indefint f_{X,Y}(x,y)dx \\\\\n        \\end{align*}\n    \\item[Independence] As you should expect, $X$ and $Y$ are independent iff\n        \\[ f_{X,Y}(x,y) = f_X(x)f_Y(y), \\forall x,y \\in \\mathbb{R}\\]\n    \\item[Conditional Distributions (Continuous)] We define\n        \\[ f_X(x | Y = y) = \\frac{f_{X,Y}(x,y)}{f_Y(y)} \\]\n        and using the marginal distributions,\n        \\[ f_X(x | Y = y) = \\frac{f_{X,Y}(x,y)}{\\indefint f_{X,Y}(x,y)dx} \\]\n\\end{description}\n\n\\section{Limit Theorems}\nHere we describe the Normal Distribution and the convergence of sums to distributions to it.\n\n\\begin{description}\n    \\item[Sums of Random Variables (Discrete)] The distributions of the sums of\n        independent discrete random variables can be calculated as the sum over\n        all values of the 2 random variables that sum to the requested value.\n        \\[ P(X + Y = k) = \\sum_x P(X = x)P(Y = (k -x))  \\]\n        \\\\\n        \\textbf{Binomial} \\\\\n        Let $X \\sim binom(n,p)$ and $Y \\sim binom(m,p)$ and independent. then \\[X + Y \\sim binom(n+m, p).\\] \\\\\n        \\textbf{Poisson} \\\\\n        Let $X \\sim poisson(\\lambda)$ and $Y \\sim poisson(\\mu)$. Then \\[X + Y \\sim poisson(\\lambda + \\mu) \\]\n        \\begin{align*}\n            P(X + Y = k) &= \\sum_{x = 0}^{\\infty} P(X = x)P(Y = (k -x)) \\\\\n                         &= \\sum_{x = 0}^{\\infty} \\left( e^{-\\lambda}\\frac{\\lambda^x}{x!}\\right)\\left( e^{-\\mu}\\frac{\\mu^{k-x}}{(k-x)!}\\right) \\\\\n                         &= e^{-(\\mu+\\lambda)} \\frac{1}{k!}\\sum_{x = 0} \\left(\\frac{k!}{x!(k-x)!}\\right) \\lambda^x \\mu^{k-x} \\\\\n                         &= e^{-(\\mu+\\lambda)} \\frac{(\\mu + \\lambda)^k}{k!} \\\\\n            X + Y &\\sim poisson(\\lambda + \\mu)\n        \\end{align*}\n    \\item[Sums of Random Variables (Continuous)] As above, but integrating rather than summing.\n        \\[ f_{X+Y}(z) = \\indefint f_X(x)f_Y(z - x)dx \\]\n        Examples are painful, so figure them out yourself (It's left as an exercise to the reader!).\n\\end{description}\n    Now let's talk about the mean and variance of these sums.\n\n\\begin{description}\n    \\item[Expected Value of Sums]\n        Since expectation is linear, \n        \\begin{align*}\n            E[X + Y] &= E[X] + E[Y] \\\\\n            E\\left[\\sum_{i=0}^n X_i\\right] &= \\sum_{i=0}^n E[X_i]\n        \\end{align*}\n    \\item[Expected Value of Products]\n        If $X$ and $Y$ are independent,\n        \\begin{align*}\n            E[XY] &= \\sum_{x,y} xyP(X = x, Y = y)  \\\\\n                  &= \\sum_{x,y} xyP(X = x)P(Y = y) \\\\\n                  &= \\sum_{x} \\left(xP(X = x) \\left( \\sum_{y} yP(Y = y)\\right) \\right)  \\\\\n                  &= \\left(\\sum_{y} yP(Y = y) \\right) \\left( \\sum_{x} xP(X = x) \\right) \\\\\n                  &= E[X]E[Y]\n        \\end{align*}\n    \\item[Covariance]\n        The covariance, a measure of how the variance of one variable interacts with the variance of the \n        other, is defined as\n        \\begin{align*}\n            cov[X,Y] &= E[(X - E[X])(Y - E[Y])] \\\\\n                     &= E[XY - E[X]y - xE[Y] - E[X]E[Y]] \\\\\n                     &= E[XY] - E[X]E[Y] - E[X]E[Y] - E[X]E[Y] \\\\\n                     &= E[XY] - E[X]E[Y]\n        \\end{align*}\n        Which shows that if $X$ and $Y$ are independent,\n        \\[ cov[X,Y] = E[X]E[Y] - E[X]E[Y] = 0 \\]\n    \\item[Variance of Sums]\n        By definition\n        \\begin{align*}\n            var[X+Y] &= E[((X+Y) - E[X+Y])^2] \\\\\n                     &= E[((x - E[X]) + (Y - E[Y]))^2] \\\\\n                     &= E[(x - E[X])^2] + 2E[(x - E[X])(y - E[Y])] + E[(y - E[Y])^2] \\\\\n                     &= var[X] + var[Y] + 2cov[X,Y]\n        \\end{align*}\n        And if $X$ and $Y$ are independendent.\n        \\[ var\\left[ \\sum_{i=0}^n X_i \\right] = \\sum_{i=0}^n var[X_i] \\]\n\\end{description}\n\nNow a few more related pieces\n\n\\begin{description}\n    \\item[Chebyshev's Inequality] Given $y \\geq 0$. \n        \\[ P(|Y - E[Y]| \\geq y) \\leq \\frac{var[Y]}{y^2} \\]\n        Note that\n        \\begin{align*}\n            E[Z] = \\int_{\\mathbb{R}}zf_Z(z)dz &\\geq \\int_k^{\\infty} xf_Z(z)dz \\\\\n                                              &\\geq \\int_k^{\\infty} kf_Z(z)dz  \\\\\n                                              &\\geq k\\int_k^{\\infty} f_Z(z)dz = kP(k \\leq Z)\n        \\end{align*}\n        If we let $Z = (Y - E[Y])^2$ and $k = y^2$,\n        \\begin{align*}\n            var[Y] = E[(Y - var[Y])^2] &\\geq y^2 P((Y - E[Y])^2 \\geq y^2) \\\\\n                                         &\\geq y^2 P(|Y-var[Y]| \\geq y) \\\\\n        \\end{align*}\n        and with rearrangement,\n        \\[P(|Y-E[Y]| \\geq y) \\leq \\frac{var[Y]}{y^2} \\]\n\\end{description}\nNow lets move to the 2 capstone results \n\n\\begin{description}\n    \\item[Law of Large Numbers] Given a series of independent and identically distributed (i.i.d.) random \n        variables $X_1,X_2,...$ with partial means \\\\ $\\bar{X}_n = \\frac{1}{n}\\sum_{i=0}^n X_i$, and \n        $var[X] = \\sigma ^2$ and $E[X] = \\mu$. \n    \\[ \\lim_{n \\rightarrow \\infty} P(|\\bar{X}_n - E[X]|\\geq \\varepsilon) = 0 \\]\n        \\begin{align*}\n            var[\\bar{X}_n] &= var\\left[\\frac{1}{n}\\sum_{i=0}^n X_i \\right] \\\\\n                           &= \\frac{1}{n^2} \\cdot n(var[X_i]) \\\\\n                           &= \\frac{\\sigma ^2}{n} \\\\\n            P(|\\bar{X}_n - E[X]| \\geq \\varepsilon) &\\leq \\frac{var[\\bar{X}_n]}{\\varepsilon ^2} \\\\\n            P(|\\bar{X}_n - \\mu| \\geq \\varepsilon) &\\leq \\frac{\\sigma ^2}{n \\varepsilon ^2} \\\\\n            \\lim_{n \\rightarrow \\infty} P(|\\bar{X}_n - \\mu| \\geq \\varepsilon) &\\leq \n                \\lim_{n \\rightarrow \\infty}\\frac{\\sigma ^2}{n \\varepsilon ^2} = 0\\\\\n            \\lim_{n \\rightarrow \\infty} P(|\\bar{X}_n - \\mu| \\geq \\varepsilon) &= 0 \n        \\end{align*}\n    \\item[Normal Distribution] Given $X \\sim N(\\mu,\\sigma)$ and $Y \\sim N(\\upsilon,\\nu)$, \n        \\[ f_X(x) = \\frac{1}{\\sqrt{2\\pi}\\sigma}e^{\\frac{-(x-\\mu)^2}{2\\sigma^2}} \\]\n        and\n        \\[ X + Y \\sim N(a + b, u + v) \\] \n        Proofs of these are trivial but painful. \n\n    \\item[Central Limit Theorem] Suppose $X_1, X_2, ...$ are i.i.d. with $E[X_i] = \\mu$ and \n        $var[X_i] = \\sigma ^2 < \\infty$. Let $S_n = \\sum_{i = 1}^n X_i$ and $\\chi \\sim N(0,1)$. \n        As $n \\rightarrow \\infty$,\n        \\[ \\frac{S_n - \\mu}{\\sigma\\sqrt{n}} \\approx \\chi \\]\n    \\item[Histogram Correction] Since the Central Limit Theorem is meant for continuous random variables,\n        we offset this by treating an integer value $k$ as the interval $[k - 0.5, k + 0.5]$. Thus, for\n        a discrete random variable $X$, \n        \\[P\\left(\\frac{X - \\mu}{\\sigma \\sqrt{n}} \\leq k\\right) \\approx P\\left(\\chi \\leq k + 0.5\\right) \\]\n        \\[P\\left(\\frac{X - \\mu}{\\sigma \\sqrt{n}} \\geq k\\right) \\approx P\\left(\\chi \\geq k - 0.5\\right) \\]\n\\end{description}\nAnd now we done, fam.\n\\end{document}\n\n", "meta": {"hexsha": "e740f498d7fdf6e2db4adf91c9d2dc278bc1d5da", "size": 24456, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Math180A/Math180A.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": "Math180A/Math180A.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": "Math180A/Math180A.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": 48.62027833, "max_line_length": 201, "alphanum_fraction": 0.5413804383, "num_tokens": 8079, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600902, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7718605737610693}}
{"text": "\n\\subsection{Gradient descent}\n\n\\subsection{What is gradient descent?}\n\nRather than solve a normal equation, gradient descent takes the loss function, and takes the derivative of the loss function with respect to each parameter.\n\nSmall adjustments are then made to the parameters, in the direction of the steepest derivative, resulting in better parameters.\n\nAs derivative term gets smaller, convergance happens. The largest changes to the parametres occurs early on in the algorithm.\n\nCan stop if not lowering by much\n\n\\subsection{Local minima}\n\nGradient descent is not guaratneed to arrive at a global minimum. For some loss functions, there will be multiple local minima, and gradient descent can end up in the wrong one.\n\nLinear regression does not have this issue.\n\nAs a result, when we create functions with loss functions, convextity is very important. If the loss space is convex, then we will not get stuck in a local minima.\n\n", "meta": {"hexsha": "f436774080d9ed5921a1f5e7f5d4cf2898d579f1", "size": 936, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/optimisationGradientDescent/01-01-gradientDescent.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/01-01-gradientDescent.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/01-01-gradientDescent.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": 42.5454545455, "max_line_length": 177, "alphanum_fraction": 0.8012820513, "num_tokens": 193, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7718605548942208}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the following functions $T:\\R^3\\rightarrow \\R^2$.\n  For each of these functions $T$, show that it is not linear either\n  by showing that $T$ does not preserve addition, or by showing that it\n  does not preserve scalar multiplication, or by showing that it does\n  not preserve the zero vector.\n  \\begin{enumerate}\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      x+2y+3z+1 \\\\\n      2y-3x+z\n    \\end{mymatrix}$.\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      x+2y^2+3z \\\\\n      2y+3x+z\n    \\end{mymatrix}$.\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      \\sin x+2y+3z \\\\\n      2y+3x+z\n    \\end{mymatrix}$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item We have $T\\begin{mymatrix}{c} 0 \\\\ 0 \\\\ 0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 1 \\\\ 0 \\end{mymatrix}$, so $T$ does\n      not preserve the zero vector.\n    \\item We have\n      $T\\begin{mymatrix}{c} 0 \\\\ 1 \\\\ 0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 2 \\\\ 2 \\end{mymatrix}$ and\n      $T\\begin{mymatrix}{c} 0 \\\\ 2 \\\\ 0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 8 \\\\ 4 \\end{mymatrix}$, so $T$ does not\n      preserve scalar multiplication.\n    \\item We have\n      $T\\begin{mymatrix}{c} \\pi/2 \\\\ 0 \\\\ 0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 1 \\\\ \\pi/2 \\end{mymatrix}$ and\n      $T\\begin{mymatrix}{c} \\pi \\\\ 0 \\\\ 0 \\end{mymatrix}\n      = \\begin{mymatrix}{c} 0 \\\\ \\pi \\end{mymatrix}$, so $T$ does not\n      preserve scalar multiplication.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the following functions $T:\\R^3\\rightarrow \\R^2$. For\n  each function $T$, show that $T$ is a linear transformation. Do this\n  by showing that $T$ is a matrix transformation, i.e., find a matrix\n  $A$ such that $T(\\vect{v})=A\\vect{v}$.\n  \\begin{enumerate}\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      x+2y+3z \\\\\n      2y-3x+z\n    \\end{mymatrix}$.\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      7x+2y+z \\\\\n      3x-11y+2z\n    \\end{mymatrix}$.\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      3x+2y+z \\\\\n      x+2y+6z\n    \\end{mymatrix}$.\n  \\item $T\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}\n    = \\begin{mymatrix}{c}\n      2y-5x+z \\\\\n      x+y+z\n    \\end{mymatrix}$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following functions are linear transformations?\n  \\begin{enumerate}\n  \\item The function $f:\\Seq_K\\to\\Seq_K$ defined by\n    $f((a_0,a_1,a_2,\\ldots)) = (-a_1,-a_3,-a_5,\\ldots)$. In words, the\n    function $f$ removes the even-numbered elements, and negates the\n    odd-numbered elements.\n  \\item The function $f:\\Mat_{2,2}\\to\\Mat_{2,2}$ defined by $f(A) =\n    AB$. Here, $\\Mat_{2,2}$ is the vector space of $2\\times\n    2$-matrices with real entries, and $B$ is a fixed matrix.\n  \\item The function $f:\\Mat_{2,2}\\to\\Mat_{2,2}$ defined by $f(A) =\n    A+B$, where $B$ is a fixed matrix.\n  \\item The function $f:\\Mat_{2,2}\\to\\Mat_{2,2}$ defined by $f(A) =\n    A^T$.\n  \\end{enumerate}\n  \\begin{sol}\n    Yes, yes, no, yes.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Recall the vector space $\\Poly$ of polynomials with coefficients in\n  a field $K$. Consider the function $M:\\Poly\\to\\Poly$ defined by\n  $M(p(x)) = xp(x)$.\n  \\begin{enumerate}\n  \\item Compute $M(x^3)$, $M(2x^2+x)$, and $M(ax^2+bx+c)$.\n  \\item Show that $M$ is a linear transformation.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Recall the vector space $\\Poly$ of polynomials with coefficients in\n  a field $K$. Consider the function $S:\\Poly\\to\\Poly$ defined by\n  $S(p(x)) = p(x+1)$.\n  \\begin{enumerate}\n  \\item Compute $S(x^3)$, $S(2x^2+x)$, and $S(ax^2+bx+c)$.\n  \\item Show that $S$ is a linear transformation.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  Consider the shift function $\\shift:\\Seq_K\\to\\Seq_K$ from\n  Example~\\ref{exa:shift-unshift}. Find a basis for the solution space\n  of each of the following equations:\n  \\begin{enumerate}\n  \\item $\\shift(a) = a$.\n  \\item $\\shift(a) = -a$.\n  \\item $\\shift(\\shift(a)) = \\shift(a) + 2a$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item Let $a=(a_0,a_1,a_2,\\ldots)$. Then the equation $\\shift(a) =\n      a$ is equivalent to\n      \\begin{equation*}\n        (a_1,a_2,a_3,\\ldots) = (a_0,a_1,a_2,\\ldots),\n      \\end{equation*}\n      which translates to the recurrence $a_{n+1}=a_n$. The only free\n      variable is $a_0$, and the only solutions are the constant\n      sequences. They form a 1-dimensional space with basis\n      $\\set{(1,1,1,\\ldots)}$.\n    \\item The equation $\\shift(a) = -a$ is equivalent to\n      \\begin{equation*}\n        (a_1,a_2,a_3,\\ldots) = (-a_0,-a_1,-a_2,\\ldots),\n      \\end{equation*}\n      which translates to the recurrence $a_{n+1} = -a_n$. The only\n      free variable is $a_0$, and the solutions form a 1-dimensional\n      space with basis $\\set{(1,-1,1,-1,\\ldots)}$.\n    \\item The equation $\\shift(\\shift(a)) = \\shift(a) + 2a$ is\n      equivalent to\n      \\begin{equation*}\n        (a_2,a_3,a_4,\\ldots) = (a_1+2a_0,a_2+2a_1,a_3+2a_2,\\ldots),\n      \\end{equation*}\n      which translates to the recurrence $a_{n+2} = a_{n+1} + 2a_n$.\n      The only free variables are $a_0$ and $a_1$. The most obvious\n      basis vectors are obtained by letting $(a_0,a_1)=(1,0)$ and\n      $(a_0,a_1)=(0,1)$, giving the sequences\n      $(1,0,2,2,6,10,22,\\ldots)$ and $(0,1,1,3,5,11,21,\\ldots)$. Thus,\n      \\begin{equation*}\n        \\set{(1,0,2,2,6,10,22,\\ldots), (0,1,1,3,5,11,21,\\ldots)}\n      \\end{equation*}\n      is a basis for the solutions. Another basis, which is slightly\n      more convenient, is\n      \\begin{equation*}\n        \\set{(1,-1,1,-1,1,-1,\\ldots), (1,2,4,8,16,32,\\ldots)}.\n      \\end{equation*}\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "afbc2b8222f0f3b4759f04dc85c05d27b1f87e7c", "size": 5879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsGeneral-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsGeneral-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsGeneral-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 35.6303030303, "max_line_length": 71, "alphanum_fraction": 0.6021432216, "num_tokens": 2258, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7717161001498828}}
{"text": "\\chapter{Falling Bodies}\n\nBecause of gravity, if you throw a hammer straight up in the air, from\nthe moment it leaves your hand until it hits the ground, it is\naccelerating toward the center of the earth at a constant rate.\n\n\\emph{Acceration} is the change in velocity. If the hammer leaves your\nhand with a velocity of 12 meters per second upward, one second later\nit will be rising, its velocity will have slowed to 2.2 meters per\nsecond. One second after that, the hammer will be falling at a rate of\n7.6 meters per second. Every second the hammer's velocity is changing by\n9.8 meters per second, and that change is always toward the center of\nthe earth. When the hammer is going up, gravity is slowing it down by\n9.8 meters per second each second.  When the hammer is coming down,\ngravity is speeding it up by 9.8 meters per second each second.\\index{acceleration}\n\nAcceleration due to gravity on earth is a constant negative 9.8 meters per second per second:\n\\begin{equation*}\na = -9.8   \n\\end{equation*}\n(Why is it negative? We are talking about height, which increases as\nyou go away from the center of the earth. Acceleration is changing the\nvelocity in the opposite direction.)\n\n\\section{Calculating the Velocity}\n\nGiven that the acceleration is constant, it makes sense that the\nvelocity is a straight line. Assuming once again that the hammer\nleaves your hand at 12 meters per second, then the upwards velocity at\ntime $t$ is given by:\n\\begin{equation*}\n  v = 12 - 9.8t\n\\end{equation*}\n\nNote that the velocity of the hammer is being given as a function. Here is its graph:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n        ]\n        \\addplot[no marks,sdkblue] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$}; \n    \\end{axis}\n\\end{tikzpicture}\n\n\\begin{Exercise}[title={When is the apex of flight?}, label=vapex]\n  Given the hammer's velocity is given by $12 - 9.8t$, at what time (in seconds)\n  does it stop rising and begin to fall?\n\\end{Exercise}\n\\begin{Answer}[ref=vapex]\n  Solve for when the velocity is zero.\n\n  $t = \\frac{12}{9.8} = 1.22$ seconds after release.\n\\end{Answer}\n\nAt this point, we need to say something about air resistance. Gravity\nis not the only force on the hammer; as it travels through the air,\nthe air tries to slow it down. This force is called \\emph{air resistance},\nand for a large, fast moving object (like an airplane) it is very big force. For a\ndense object (like a hammer) moving at a slow speed (what you generate\nwith your hand), air resistance doesn't significantly affect acceleration.\n\n\\section{Calculating Position}\n\nIf you let go of the hammer when it is 2 meters\nabove the ground, the height of the hammer is given by:\n\\begin{equation*}\n  p = -\\frac{9.8}{2}t^2 + 12t + 2\n\\end{equation*}\n\nHere is a graph of this function:\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-1.2,xmax=3.5,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$p$},\n      ]\n      \\addplot[no marks,sdkblue,dashed,<-] expression [domain=-0.7:0,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n      \\addplot[no marks,sdkblue] expression [domain=0:2.58,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n      \\addplot[no marks,sdkblue,dashed,->] expression [domain=2.58:3,samples=100] {(-4.9)*(x^2) + 12 * x + 2};\n    \\end{axis}\n\\end{tikzpicture}\n\n\nHow did I figure this out? \\textbf{The change in position between time\n  $0$ and any time $t$ is equal to the area under the velocity graph\n  between $x = 0$ and $x = t$.}\n\nLet's use the velocity graph to figure out how much the position has\nchanged in the first second of the hammer's flight. Here's the\nvelocity graph with the area under the graph for the first second filled\nin:\n\n\\usepgfplotslibrary{fillbetween}\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n      ]\n      \\addplot[no marks,sdkblue, name path=f] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$};\n      \\path[name path=xaxis] (axis cs:0,0) -- (axis cs:1,0);\n      \\addplot[\n        thick,\n        color=sdkblue,\n        fill=sdkblue, \n        fill opacity=0.05\n    ]\n    fill between[\n        of=f and xaxis,\n        soft clip={domain=0:1},\n    ];\n    \\addplot[dashed,gray] coordinates {(0,12)(1,12)};\n    \\addplot[dashed,gray] coordinates {(1,12)(1,0)};\n    \\end{axis}\n\\end{tikzpicture}\n\nThe blue filled region is the area of the dashed rectangle minus that\nempty triangle in its upper left.  The height of the rectangle is\ntwelve and its width is the amount of time the hammer has been in\nflight ($t$).  The triangle is $t$ wide and and $9.8t$ tall. Thus, the\narea of the blue region is given by $12t - \\frac{1}{2}9.8 t^2$.\n\nThat's the change in position. Where was it originally? 2 meter off\nthe ground.  So the height is given by $p = 2 + 12t - \\frac{1}{2}9.8t^2$.\nWe usually write terms so that the exponent decreases, so:\n\n$$p = - \\frac{1}{2}9.8t^2 + 12t + 2$$\n\n\n\nFinding the area under the curve like this is called\n\\textit{integration}.  We say ``To find a function that gives the\nchange in position, we just integrate the velocity function.''  A lot\nof the study of calculus is learning to integrate different sorts of\nfunctions.\n\nOne important note about integration: Any time the curve drops under\nthe $x$-axis, the area is considered negative. (Which makes sense,\nright? If the velocity is negative, the hammer's position is\ndecreasing.)\n\n\n\\begin{tikzpicture}\n    \\begin{axis}[\n        xmin=-0.25,xmax=2.75,\n        ymin=-13,ymax=13,\n        axis x line=middle,\n        axis y line=middle,\n        axis line style=<->,\n        xlabel={$t$},\n        ylabel={$v$},\n      ]\n      \\addplot[no marks,sdkblue, name path=f] expression[domain=0:2.25,samples=100]{x * (-9.8) + 12} node[left] {$12 - 9.8t$};\n      \\path[name path=xaxis] (axis cs:0,0) -- (axis cs:2.25,0);\n      \\addplot[\n        thick,\n        color=sdkblue,\n        fill=sdkblue, \n        fill opacity=0.05\n      ]\n      fill between[\n        of=f and xaxis,\n        soft clip={domain=0:1.2245},\n      ];\n      \\addplot[\n        thick,\n        color=red,\n        fill=red, \n        fill opacity=0.07\n      ]\n      fill between[\n        of=f and xaxis,\n        soft clip={domain=1.2245:2.1},\n      ];\n    \\end{axis}\n\\end{tikzpicture}\n\nA natural question at this point is ``When will the hammer hit the\nground?''  That is, when does $p = 0$. The values of $t$ where $p = 0$\nare known as the \\textit{roots} of the quadratic function. In the next\nchapter, you will get the trick for finding the roots of any quadratic\nfunction.\n", "meta": {"hexsha": "9d716f7daf457e5625d67d3266495f5522de269d", "size": 6948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/falling_bodies-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Modules/MatterEnergy/falling_bodies-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/MatterEnergy/falling_bodies-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.9145728643, "max_line_length": 126, "alphanum_fraction": 0.6633563615, "num_tokens": 2066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8976952989498448, "lm_q1q2_score": 0.7717160978275927}}
{"text": "%\\subsection{Nodal bases and dual bases on multilevel spaces}\n%\\noindent\\textbf{Nodal bases and dual bases on multilevel spaces}\n\nHere each $\\mathcal V_\\ell$ consists of all piecewise linear (or bilinear)\nfunctions with respect to the grid \\eqref{grids} and \\eqref{mn-ell}.\nEach $\\mathcal V_\\ell $ has a set of basis functions:\n$\\phi_{i,j}^\\ell\\in \\mathcal V_\\ell$ satisfying:\n\\begin{equation}\n\\label{NodalBases-mul}\n\\mathbf\\phi_{i,j}^\\ell(x_p^\\ell,y_q^\\ell)=\\delta_{(i,j), (p,q)} = \n\\begin{cases}\n1 \\quad &\\text{if} \\quad (p,q) = (i,j), \\\\\n0 \\quad &{\\text{if}} \\quad (p,q)\\neq (i,j).\n\\end{cases}\n\\end{equation}\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) -- (2,0);\n\\draw[-] (0,0.5) -- (2,0.5);\n\\draw[-] (0,1) -- (2,1);\n\\draw[-] (0,1.5) -- (2,1.5);\n\\draw[-] (0,2) -- (2,2);\n\n\\draw[-] (0,0) -- (0,2);\n\\draw[-] (0.5,0) -- (0.5,2);\n\\draw[-] (1,0) -- (1,2);\n\\draw[-] (1.5,0) -- (1.5,2);\n\\draw[-] (2,0) -- (2,2);\n\n\\draw[-] (0,0) -- (2,2);\n\\draw[-] (0,0.5) -- (1.5,2);\n\\draw[-] (0,1) -- (1,2);\n\\draw[-] (0,1.5) -- (0.5,2);\n\\draw[-] (0.5,0) -- (2,1.5);\n\\draw[-] (1,0) -- (2,1);\n\\draw[-] (1.5,0) -- (2,0.5);\n\n\\node at (1.35,1.2) {$K_1$};\n\\node at (1.1,1.3) {$K_2$};\n\\node at (0.8,1.1) {$K_3$};\n\\node at (0.7,0.9) {$K_4$};\n\\node at (0.9,0.7) {$K_5$};\n\\node at (1.2,0.8) {$K_6$};\n\n\\node at (1.18, 1) {$(i,j)$};\n\n\\fill(1,1) circle(0.8pt);\n\n\\draw[-] (3,0) -- (5,0);\n\\draw[-] (3,0.5) -- (5,0.5);\n\\draw[-] (3,1) -- (5,1);\n\\draw[-] (3,1.5) -- (5,1.5);\n\\draw[-] (3,2) -- (5,2);\n\n\\draw[-] (3,0) -- (3,2);\n\\draw[-] (3.5,0) -- (3.5,2);\n\\draw[-] (4,0) -- (4,2);\n\\draw[-] (4.5,0) -- (4.5,2);\n\\draw[-] (5,0) -- (5,2);\n\n\\node at (4.2,1.2) {$K_1$};\n\\node at (3.8,1.2) {$K_2$};\n\\node at (3.8,0.8) {$K_3$};\n\\node at (4.2,0.8) {$K_4$};\n\\node at (4.18,1) {$(i,j)$};\n\\fill(4,1) circle(0.8pt);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nFor the piecewise linear finite element space, the nodal basis function $\\phi^\\ell_{i,j}$  associate with each $(x_i^\\ell,y_j^\\ell)$   \n(satisfying \\eqref{NodalBases-mul}) is given by \n\\begin{equation}\n  \\label{LinearNodalBasis}\n  \\phi_{i,j}^\\ell(x,y)=\\left\\{\n  \\begin{array}{ll}\n\\frac{x^\\ell_{i+1}-x}{h}, & (x,y)\\in K_1, \\\\\n\\frac{y^\\ell_{j+1}-y}{h}, &(x,y)\\in K_2,\\\\\n\\frac{x-x^\\ell_{i-1}-(y-y^\\ell_j)}{h}, &(x,y)\\in K_3,\\\\\n\\frac{x-x^\\ell_{i-1}}{h}, &(x,y)\\in K_4,\\\\\n\\frac{y-y^\\ell_{j-1}}{h}, &(x,y)\\in K_5,\\\\\n\\frac{x^\\ell_{i+1}-x+y-y^\\ell_j}{h}, &(x,y)\\in K_6\\\\\n0, & \\mbox{ elsewhere.} \n\\end{array}\n\\right.\n\\end{equation}\nshown in Fig. \\ref{fig:nodallinear}.\n\\begin{figure}\n\\centering\n\\includegraphics[width=5.5cm,height=5cm]{figures/nodalbasis.pdf} \n\\caption{\\footnotesize{Nodal basis for linear element.}}\n\\label{fig:nodallinear}\n\\end{figure}\n\nFor bilinear element, it is easy to see that the nodal basis function $\\phi^\\ell_{i,j}$  associated with each $(x^\\ell_i,y^\\ell_j)$   \n(satisfying \\eqref{NodalBases-mul}) is given by \n\\begin{equation}\n  \\label{BilinearNodalBasis}\n  \\phi^\\ell_{i,j}(x,y)=\\left\\{\n  \\begin{array}{ll}\n\\frac{(x^\\ell_{i+1}-x)(y^\\ell_{j+1}-y)}{h^2}, \\quad& (x,y)\\in K_1, \\\\\n\\frac{(x-x^\\ell_{i-1})(y^\\ell_{j+1}-y)}{h^2}, \\quad &(x,y)\\in K_2,\\\\\n\\frac{(x-x^\\ell_{i-1})(y-y^\\ell_{j-1})}{h^2},\\quad &(x,y)\\in K_3,\\\\\n\\frac{(x^\\ell_{i+1}-x)(y-y^\\ell_{j-1})}{h^2},\\quad &(x,y)\\in K_4,\\\\\n0 \\quad & \\mbox{ elsewhere.} \n\\end{array}\n\\right.\n\\end{equation}\n\n\nAssociated with the above nodal basis functions $\\phi^{\\ell}_{i,j}(x,y)\\subset \\mathcal V_{\\ell}$, \nwe define the corresponding dual basis functions $\\psi^{\\ell}_{i,j}(x,y)\\subset \\mathcal V_{\\ell}$ \nsatisfying \n\\begin{equation}\n  \\label{dual-basis}\n(\\psi^{\\ell}_{i,j}(x,y), \\phi^{\\ell}_{p,q}(x,y))_{L^2(\\Omega)}=\\delta_{(i,j), (p,q)}.\n\\end{equation}\nThe existence of dual basis functions is obvious, but the exact expression of the dual basis functions are  \nin general difficult to obtain. In fact, \\eqref{dual-basis} is the only property that is needed in the application \nof dual basis. \n\nWe write $\\mathbf u_h(x,y)=\\sum\\limits_{i,j=1}^{n} u_{i,j}\\phi_{i,j}(x,y), \\mathbf v_h(x,y)=\\sum\\limits_{i,j=1}^{n} v_{i,j}\\phi_{i,j}(x,y)$. \n\n\\begin{lemma}\nFor bilinear functions, we have  \n\\begin{equation}\\label{basis:plongation}\n\\begin{split}\n\\phi_{i,j}^{\\ell+1}(x,y)&=\\phi_{2i,2j}^{\\ell}(x,y)+\\frac{1}{2}\\left(\\phi_{2i-1,2j}^{\\ell}(x,y)+\\phi_{2i,2j-1}^{\\ell}(x,y)\n+\\phi_{2i+1,2j}^{\\ell}(x,y)+\\phi_{2i,2j+1}^{\\ell}(x,y)\\right)\\\\\n&+\\frac{1}{4}\\left(\\phi_{2i-1,2j-1}^{\\ell}(x,y)+\\phi_{2i+1,2j-1}^{\\ell}(x,y)\n+\\phi_{2i+1,2j+1}^{\\ell}(x,y)+\\phi_{2i-1,2j+1}^{\\ell}(x,y)\\right).\n\\end{split}\n\\end{equation}\nFor linear functions, we have  \n\\begin{equation}\\label{basis:plongation2}\n\\begin{split}\n\\phi_{i,j}^{\\ell+1}(x,y)&=\\phi_{2i,2j}^{\\ell}(x,y)\n+\\frac{1}{2}\\left(\\phi_{2i-1,2j-1}^{\\ell}(x,y)+\\phi_{2i+1,2j+1}^{\\ell}(x,y)\\right)\\\\\n&+\\frac{1}{2}\\left(\\phi_{2i-1,2j}^{\\ell}(x,y)+\\phi_{2i,2j-1}^{\\ell}(x,y)\n+\\phi_{2i+1,2j}^{\\ell}(x,y)+\\phi_{2i,2j+1}^{\\ell}(x,y)\\right).\n\\end{split}\n\\end{equation}\n\\end{lemma}\nThus, for each $\\mathbf v^{\\boldsymbol {\\ell}} \\in \\mathcal V_{\\ell}, \\mathbf f^{\\boldsymbol {\\ell}} \\in \\mathcal V'_{\\ell}=\\mathcal V_{\\ell}$, we have \n\\begin{equation}\\label{expand}\n\\mathbf v^{\\boldsymbol \\ell}(x,y)=\\sum_{i=1}^{m_\\ell}\\sum_{j=1}^{n_\\ell}v^\\ell_{i,j}\\phi_{i,j}^\\ell(x,y), \n~~ \\mathbf f^{\\boldsymbol \\ell}(x,y)=\\sum_{i=1}^{m_\\ell}\\sum_{j=1}^{n_\\ell}f^\\ell_{i,j}\\psi_{i,j}^\\ell(x,y),\n\\end{equation}\nwhere\n\\begin{equation}\n  \\label{vf}\n  v^\\ell_{i,j}=\\mathbf v^\\ell(x_i^\\ell,y_j^\\ell),~~ f_{i,j}^\\ell= (\\mathbf f^\\ell, \\phi^\\ell_{i,j})_{L^2(\\Omega)}.\n\\end{equation}\nLet us introduce the following tensors: \n\\begin{equation}\n  \\label{v}\n  v^\\ell=(v^\\ell_{i,j}),~~f^\\ell=(f^\\ell_{i,j}),~~\\phi^\\ell=(\\phi^\\ell_{i,j}),~~\\psi^\\ell=(\\psi^\\ell_{i,j}).\n\\end{equation}\nThe following identities obviously hold: \n$$\n\\mathbf v^\\ell=(v^\\ell, \\phi^\\ell)_{l^2},~~\\mathbf f^\\ell=(f^\\ell, \\psi^\\ell)_{l^2},~~(\\mathbf f^\\ell,\\mathbf v^\\ell)_{L^2(\\Omega)}=(f^\\ell, v^\\ell)_{l^2}.\n$$\n\n", "meta": {"hexsha": "fcebaf5cbc645df281d43411463a47b71dcce20a", "size": 5947, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.10-2d_basis.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.10-2d_basis.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.10-2d_basis.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": 35.8253012048, "max_line_length": 155, "alphanum_fraction": 0.5844963847, "num_tokens": 2759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8918110432813419, "lm_q1q2_score": 0.771616397953778}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} Find the eigenvalues and eigenvectors of the matrix\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n15 & -24 & 7 \\\\\n-6 & 5 & -1 \\\\\n-58 & 76 & -20\n\\end{mymatrix}\n\\end{equation*}\nOne eigenvalue is $-2. $ Diagonalize if possible. \\textbf{Hint:\\ }\nThis one has some complex eigenvalues.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the eigenvalues and eigenvectors of the matrix\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n15 & -25 & 6 \\\\\n-13 & 23 & -4 \\\\\n-91 & 155 & -30\n\\end{mymatrix}\n\\end{equation*}\nOne eigenvalue is $2$. Diagonalize if possible. \\textbf{Hint:\\ }\nThis one has some complex eigenvalues.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the eigenvalues and eigenvectors of the matrix\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n-11 & -12 & 4 \\\\\n8 & 17 & -4 \\\\\n-4 & 28 & -3\n\\end{mymatrix}\n\\end{equation*}\nOne eigenvalue is $1$. Diagonalize if possible. \\textbf{Hint:\\ }\nThis one has some complex eigenvalues.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Find the eigenvalues and eigenvectors of the matrix\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n14 & -12 & 5 \\\\\n-6 & 2 & -1 \\\\\n-69 & 51 & -21\n\\end{mymatrix}\n\\end{equation*}\nOne eigenvalue is $-3$. Diagonalize if possible. \\textbf{Hint:\\ }\nThis one has some complex eigenvalues.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Suppose $A$ is an $n\\times n$-matrix consisting entirely of real\nentries but $a+ib$ is a complex eigenvalue having the eigenvector, $X+iY$ Here $X$ and $Y$ are real vectors. Show\nthat then $a-ib$ is also an eigenvalue with the eigenvector, $X-iY$. \\textbf{Hint: }You should remember that the conjugate of a\nproduct of complex numbers equals the product of the conjugates. Here $a+ib$\nis a complex number whose conjugate equals $a-ib$.\n\\begin{sol}\n $AX=(\na+ib)X$. Now take conjugates of both sides. Since $A$ is\nreal,\n\\[\nA\\conjugate{X}=(a-ib) \\conjugate{X}\n\\]\n\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "62acb79ef70b43ab10c4d1e62b323c290534e378", "size": 1889, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/SpectralTheory-Diagonalization-Complex.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/SpectralTheory-Diagonalization-Complex.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/SpectralTheory-Diagonalization-Complex.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.527027027, "max_line_length": 127, "alphanum_fraction": 0.6871360508, "num_tokens": 675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8918110389681662, "lm_q1q2_score": 0.7716163942219144}}
{"text": "\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Quadratic convergence of Newton-Raphson iterations}\n\nThis is a simple example that uses Python and {\\tt\\small sympy} 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{python}\n   from sympy import *\n\n   x = Symbol('x')\n\n   f    = Lambda (x,x-exp(-x))\n   df   = Lambda (x,diff(f(x),x))\n   Step = Lambda (x,x-f(x)/df(x))\n\n   Digits = 200  # use 200 decimal digits for all numerical computations\n\n   x_new = Float('0.5',Digits)\n   f_new = N (f(x_new),Digits)\n\n   # pyBeg (table)\n\n   print ('\\RuleA {:2d} & {: .25f} & {: .10e} &\\\\\\\\'.format(0,x_new,f_new))\n\n   for n in range (1,7):\n      x_old = x_new\n      x_new = N (Step(x_new),Digits)\n      f_old = N (f(x_old),Digits)\n      f_new = N (f(x_new),Digits)\n      ratio = N (f_new / f_old**2,Digits)\n      print ('\\RuleA {:2d} & {: .25f} & {: .10e} & {: .5f}\\\\\\\\'.format(n,x_new,f_new,ratio))\n\n   # pyEnd (table)\n\\end{python}\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\\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$&$ \\epsilon_{n} =  x_{n} - e^{-x_{n}}$&$\\epsilon_{n}/\\epsilon_{n-1}^2$\\\\\n      \\noalign{\\hrule height 0.5pt}\n      \\py{table}\n      \\noalign{\\hrule height 1pt}\n   \\end{tabular}\n\\end{center}\n\n\\vspace{20pt}\n\n\\begin{latex}\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$&$ \\epsilon_{n} =  x_{n} - e^{-x_{n}}$&$\\epsilon_{n}/\\epsilon_{n-1}^2$\\\\\n         \\noalign{\\hrule height 0.5pt}\n         \\py{table}\n         \\noalign{\\hrule height 1pt}\n      \\end{tabular}\n   \\end{center}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "27b5d2cf3b82b33c713b62be64e622acbac036e3", "size": 2817, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/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": "python/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": "python/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": 31.3, "max_line_length": 330, "alphanum_fraction": 0.63542776, "num_tokens": 964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110368115781, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7716163784091251}}
{"text": "\n\\section{Methods of Counting}\n\n\\subsection{package au.id.cxd.math.count}\n\nThe count package contains a series of modules dedicated to methods of counting.\n\n\\subsubsection{Factorial}\n\nThe factorial operation is provided as $n!$ implementing:\n$$\n\\prod_{i=1}^{n-1} (n-i)\n$$\nThe Factorial implementation will memoize results, allowing for efficient reuse during runtime. \n\n\\subsubsection{Choose}\n\nThe choose module implements $n \\choose m$, how many ways can m items be selected with replacement from a set of n items. \\\\\nDetermined as:\n$$\n\\frac{n!}{m!n!}\n$$\n\n\\subsubsection{Permutation}\n\nThe method of selecting m ordered items from a set of n ordered items $P {n \\choose m}$.\\\\\n$$\n\\frac{n!}{(n-m)!}\n$$\n\n", "meta": {"hexsha": "c613a28cf397df8cad7c384fd8038bc6ab3fade8", "size": 702, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/au.id.cxd.math.count.tex", "max_stars_repo_name": "cxd/scala-au.id.cxd.math", "max_stars_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-12-02T02:57:07.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-02T02:57:07.000Z", "max_issues_repo_path": "docs/au.id.cxd.math.count.tex", "max_issues_repo_name": "cxd/scala-au.id.cxd.math", "max_issues_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 17, "max_issues_repo_issues_event_min_datetime": "2016-05-16T21:30:06.000Z", "max_issues_repo_issues_event_max_datetime": "2019-03-09T02:26:59.000Z", "max_forks_repo_path": "docs/au.id.cxd.math.count.tex", "max_forks_repo_name": "cxd/scala-au.id.cxd.math", "max_forks_repo_head_hexsha": "758fc440d0aa5ef08dd9967d4a7c9850d7868699", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-15T04:48:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-15T04:48:30.000Z", "avg_line_length": 22.6451612903, "max_line_length": 124, "alphanum_fraction": 0.7307692308, "num_tokens": 188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9518632329799585, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7714650742690016}}
{"text": "\\subsection{Test 1 Answers}\r\n\\begin{enumerate}[label=\\arabic*.]\r\n\t\\item \r\n\t\tUsing implicit differentiation,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\dd{y}{x}-\\frac{1}{y}\\dd{y}{x} = 2x\r\n\t\t\\end{equation*}\r\n\t\tso\r\n\t\t\\begin{equation*}\r\n\t\t\t\\dd{y}{x} = \\frac{2x}{1-1/y} = \\frac{2xy}{1-y}\r\n\t\t\\end{equation*}\r\n\t\tSo, $y - \\ln{y} = x^2 + 1$ is an implicit solution to $\\dd{y}{x} = \\frac{2x}{y-1}$ as we have demonstrated by differentiating and checking.\r\n\t\\item\r\n\t\tWe will use the integrating factor method. Rewriting the equation so all terms involving $y$ are on the left,\r\n\t\t\\begin{equation*}\r\n\t\t\ty' + 4y = e^{-x}\r\n\t\t\\end{equation*}\r\n\t\tIn this case,\r\n\t\t\\begin{equation*}\r\n\t\t\ta(x) = 4 \\text{ and } b(x) = e^{-x}\r\n\t\t\\end{equation*}\r\n\t\tso,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\mu(x) = e^{\\int{a(x) \\mathrm{d}x}} = e^{4x}\r\n\t\t\\end{equation*}\r\n\t\tMultiplying both sides by $\\mu(x)$,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\left(e^{4x}y\\right)' = e^{3x}\r\n\t\t\\end{equation*}\r\n\t\tIntegrating both sides,\r\n\t\t\\begin{equation*}\r\n\t\t\te^{4x}y = \\frac{1}{3}e^{3x} + C_1\r\n\t\t\\end{equation*}\r\n\t\tSolving for $y$,\r\n\t\t\\begin{equation*}\r\n\t\t\ty = \\frac{1}{3}e^{-x} + C_1e^{-4x}\r\n\t\t\\end{equation*}\r\n\t\tPlugging in $x = 0$ and $y=\\frac{4}{3}$ to solve for $C_1$,\r\n\t\t\\begin{equation*}\r\n\t\t\t\\frac{4}{3} = \\frac{1}{3} + C_1 \\implies C_1 = 1\r\n\t\t\\end{equation*}\r\n\t\tSo, our answer to the IVP is\r\n\t\t\\begin{equation*}\r\n\t\t\ty = \\frac{1}{3}e^{-x} + e^{-4x}\r\n\t\t\\end{equation*}\r\n\t\\item\r\n\t\tThe equation is separable and can be rewritten as\r\n\t\t\\begin{equation*}\r\n\t\t\t\\frac{x+2}{x} \\mathrm{d}x = (t-3)^2 \\mathrm{d}t \\text{, } x\\neq 0\r\n\t\t\\end{equation*}\r\n\t\tWe'll come back later to see if $x = 0$ is a solution.\r\n\t\tIntegrating both sides,\r\n\t\t\\begin{equation*}\r\n\t\t\tx + 2\\ln{\\abs{x}} = \\frac{(t-3)^3}{3} + C_1 \\text{, } x\\neq 0\r\n\t\t\\end{equation*}\r\n\t\tPlugging in $x = -1$ and $t = 3$ to solve for $C_1$,\r\n\t\t\\begin{equation*}\r\n\t\t\t1 + 2\\ln{1} = 0 + C_1 \\implies C_1 = -1 \\text{, } x\\neq 0\r\n\t\t\\end{equation*}\r\n\t\tSo, our solution to the IVP is\r\n\t\t\\begin{equation*}\r\n\t\t\tx + 2\\ln{\\abs{x}} = \\frac{(t-3)^3}{3} - 1 \\text{, } x\\neq 0\r\n\t\t\\end{equation*}\r\n\t\tChecking if $x = 0$ is a solution,\r\n\t\t\\begin{equation*}\r\n\t\t\t0 = 0\\frac{(t-3)^2}{2}\r\n\t\t\\end{equation*}\r\n\t\tSo, $x = 0$ is a general solution. However for our solution $x(t) = 0$, $x(3) \\neq -1$, to $x = 0$ is not a solution to the IVP. So, our solution to the IVP remains.\r\n\t\\item\r\n\t\tThis equation is linear and homogeneous, so we can find the general solution using the auxiliary equation. Extracting the auxiliary equation and finding the roots,\r\n\t\t\\begin{equation*}\r\n\t\t\tr^3 + r^2 - 2 = 0 \\implies r = 1, -1 \\pm i\r\n\t\t\\end{equation*}\r\n\t\tSo, the general solution is\r\n\t\t\\begin{equation*}\r\n\t\t\ty = C_1e^{x} + C_2e^{-x}\\cos{x} + C_3e^{-x}\\sin{x}\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\tAs stated in the problem, 90kg of salt is in the tank initially.\r\n\t\t\t\\item\r\n\t\t\t\tSo find the amount of salt in the tank after 2 hours we'll need to set up a differential equation that models the situation.\r\n\t\t\t\tLet $y(t)$ be the number of kgs of salt in the tank after $t$ minutes. Let $V(t)$ be the volume of brine in the tank after $t$ minutes.\r\n\t\t\t\tModeling the salt,\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\dd{y}{t} = \\text{salt rate in} - \\text{salt rate out} = 0 - \\text{salt rate out}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tModeling the volume,\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\dd{V}{t} = \\text{brine rate in} - \\text{brine rate out} = 3\\frac{L}{min} - 6\\frac{L}{min} = -3\\frac{L}{min}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tWe're also given that $V(0) = 2000L$, so be can find that\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\tV(t) = 2000 - 3t\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tNow we can write an equation to find $\\text{salt rate out}$.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\text{salt rate out} = \\frac{y \\text{kg of salt}}{V \\text{L of brine}}*\\frac{6L}{\\text{min}} = \\frac{6y}{2000-3t}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tThis allows us to write a differential equation for $y(t)$.\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\dd{y}{t} = -\\text{salt rate out} = \\frac{-6y}{2000-3t} = \\frac{6y}{3t-2000}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tThis eqation is seperable and can be rewritten as\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\frac{\\mathrm{d}y}{y} = \\frac{6\\mathrm{d}t}{3t-200}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tIntegrating both sides,\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\ln{\\abs{y}} = 2\\ln{\\abs{3t-2000}}+C_1\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tWe know that $y > 0$ always because we can't have a negative amount of salt. Further, we're concerned with the time between $t= 0$ and $t = 120 < \\frac{2000}{3}$, so $3t-2000 < 0$. This means we can rewrite our equation as\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t\\ln{y} = 2\\ln{(2000-3t)} + C_1\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tExponentiating both sides,\\footnote{$C_1$ is different from the $C_1$ previously, but it's still a constant.}\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty = C_1(2000-3t)^2\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tApplying our initial condition of $y(0)=90$ to solve for $C_1$,\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\t90 = C_1(2000)^2 \\implies C_1 = \\frac{2000^2}{90}\r\n\t\t\t\t\\end{equation*}\r\n\t\t\t\tPlugging our solution for $C_1$ back into our general solution,\r\n\t\t\t\t\\begin{equation*}\r\n\t\t\t\t\ty = 90\\left(\\frac{2000-3t}{2000}\\right)^2\r\n\t\t\t\t\\end{equation*}\r\n\t\t\\end{enumerate}\r\n\t\\item\r\n\t\tNewton's law of cooling is\r\n\t\t\\begin{equation*}\r\n\t\t\t\\dd{T}{t} = k\\left(T_e - T\\right)\r\n\t\t\\end{equation*}\r\n\t\twhere $k$ is some constant, $T_e$ is the temperature of the environment, and $T$ is the current temperature of the object. In the detective's case, $T_e = 16$, so\r\n\t\t\\begin{equation*}\r\n\t\t\t\\dd{T}{t} = k(16-T)\r\n\t\t\\end{equation*}\r\n\t\twith initial conditions $T(12) = 34$ and $T(13) = 32$. One could then solve this equation and apply the inital conditions to solve for $k$ and the constant of integration $C$. Then one would need to solve for $x$ in $T(x) = 37$. This value of $x$ will tell you the number of hours after midnight one the same day that the murder took place\\footnote{For those that do solve the equation, $x \\approx 10.691$, so the murder should have took place at about 10:41am.}.\r\n\t\t\r\n\\end{enumerate}", "meta": {"hexsha": "ba444bff2e8d2b6a51d56cb4c75bb93e3b3ad0e7", "size": 5954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/additionalResources/tests/test1_answers.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/additionalResources/tests/test1_answers.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/additionalResources/tests/test1_answers.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": 42.2269503546, "max_line_length": 466, "alphanum_fraction": 0.6090023514, "num_tokens": 2348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767778695834, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.7714308769964234}}
{"text": "\\textbf{The function $|x-i|$  is analytic for $x\\in[-1,1]$. This means it can be analytically continued to an analytic function $f(z)$ in a neighborhood of $[-1,1]$ in the complex z-plane. The formula $|z-i|$ itself does not define an analytic function in any complex neighborhood. Find another formula for $f$ that does, and use it to explain what singularities $f$ has in the complex plane.}\n\\newline\n\nFor a complex function $f(z) = u+vi$ to be analytic, it has to satisfy the Cauchy-Riemann Equations:\n\n\\begin{align*}\n\\frac{\\partial u}{\\partial x} &= \\frac{\\partial v}{\\partial y},\\\\\n\\frac{\\partial u}{\\partial y} &= -\\frac{\\partial v}{\\partial x}.\n\\end{align*}\nIn this case we have that\n\\begin{align*}\nf(z) = |z-i| &= |x+yi-i| \\\\\n&= |x+i(y-1)| \\\\\n&= \\sqrt{x^2+(y-1)^2},\n\\end{align*}\nwhere we have used that $z=x+yi$. Hence we observe that this function is not analytic anywhere since $v=0$ and $u_x$,$u_y$ are not. Therefore we can define \n\\begin{align*}\nf(z) = f(x) = |x-i| = \\sqrt{x^2+1},\n\\end{align*}\nwhich is analytic within a neighborhood of $x\\in [-1,1]$ in the complex plane and has singularities at $z=\\pm i$. Hence, like in the previous problem, its Bernstein ellipse is defined by \n\\begin{align*}\n\\rho = 1+\\sqrt{2},\n\\end{align*}\nand the exponential convergence is shown in the next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{sqrt(x^2+1).png}\\caption{Convergence as $n\\rightarrow\\infty$ of the Chebyshev interpolant to $f(x)=|x-i|$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this section}\n\\begin{verbatim}\n%% Problem 2 - 8.7 ATAP\n\nrho=1+sqrt(2);\norderAcuracy('sqrt(x^2+1)',50,2,rho)\n\\end{verbatim}", "meta": {"hexsha": "28d0dc9d6e1013fbaed1683b721866c232590fae", "size": 1635, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework3/Latex/problem2.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework3/Latex/problem2.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework3/Latex/problem2.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.4166666667, "max_line_length": 393, "alphanum_fraction": 0.6923547401, "num_tokens": 536, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7713906331690169}}
{"text": "\\newpage\n\\part{Regression Diagnostics}\n\\section{Gauss-Markov Theorem}\nThe Gauss-Markov theorem states that in a linear regression model, where the errors\n\\begin{itemize}\n\t\\item have expectation 0\n\t\\item are uncorrelated\n\t\\item have equal variances\n\\end{itemize}\nthe \\textbf{Best Linear Unbiased Estimator (BLUE)} of the coefficients is given by the \\textbf{Ordinary Least Square (OLS)} estimator.\n\\\\ \\ \\\\\nProperties of the BLUE:\n\\begin{itemize}\n\t\\item Unbiased: $E(\\hat{\\beta}) = \\beta$\n\t\\item Consistent: $n \\uparrow$, $var(\\hat{\\beta}) \\downarrow$  \n\t\\item Efficient: $var(\\hat{\\beta}) < var(\\tilde{\\beta})$, it gives the \\textbf{lowest variance} compared to other linear unbiased estimators. \n\\end{itemize}\n\n\\section{Gauss-Markov Assumptions/Requirements}\nThe OLS estimator is the best linear unbiased estimator (BLUE), iff\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{gauss-markov.png}\n\\end{figure}\n\\subsection{Linearity}\n\\begin{itemize}\n\t\\item Definition: Linear relationship in \\textbf{coefficients} $\\beta_i$.\n\t\\item Why: core assumption of linear regression.\n\t\\item Solution to non-linearity: Transform the \\textbf{predictors or response}(logarithmic, interval-wise)\n\t\\item Influence Factor: \\textbf{outliers}. \n\t\n\tReasons for outlier: \n\t\\begin{itemize}\n\t\t\\item error in recording the value\n\t\t\\item point doesn't belong to the sample\n\t\t\\item no error, it's an valid observation\n\t\\end{itemize} \n\tSolution to outlier:\n\t\\begin{itemize}\n\t\t\\item identify outliers $\\rightarrow$ exclude \n\t\t\\item apply ''robust'' regression\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{No Multicollinearity}\n\\begin{itemize}\n\t\\item Definition: \\textbf{No} linear dependency between the \\textbf{predictors} $X_i$\n\t\n\t$\\rightarrow$ rank(X) = p (the data matrix has \\textbf{full rank} = number of columns)\n\t\n\t$\\rightarrow$ \\textbf{No high correlation} between predictors (though full rank). \n\t\n\t\n\t\n\t\n\t\\item Testing: \n\t\\begin{itemize}\n\t\t\\item \\textbf{Correlation Coefficient} between predictor \\textbf{pairs}\n\t\t\\item \\textbf{Variance Inflation Factor (VIF)}: correlation among \\textbf{multiple predictors}\n\t\t$$VIF = \\frac{1}{1-R^2_k}$$\n\t\t\\paragraph{Interpretation of VIF} \n\t\t\n\t\tWhen the predictor $X_k$ is set as the dependent variable, $R^2_k$ of the variance in the predictor $X_k$ can be explained by the rest of other predictors.\n\t\t\n\t\teg: VIF = 10. $R^2_k$ = 90\\%. 90\\% of the variance in the predictor $X_k$ can be explained by the rest of other predictors.\n\t\t\n\t\t\\paragraph{Rule} VIF $\\uparrow$, Multicollinearity $\\uparrow$. Remove predictor $X_k$ if $\\mathbf{VIF >10}$\n\t\t\n\t\\end{itemize}\n\n\t\\item Consequences of Multicollinearity: Non-significance of the coefficients\n\t\n\tThe coefficient has a small t-value/large p-value (can't reject $H_0$)\n\t\\begin{itemize}\n\t\t\\item small VIF: predictor $X_i$ is not related to response \n\t\t\n\t\t$\\rightarrow$ remove the variable $X_i$\n\t\t\\item large VIF: predictor $X_i$ is highly correlated to some other predictors. \n\t\t\n\t\t$\\rightarrow$ \\textbf{correlation matrix}: remove one of the highly correlated variables (near 1 or -1)\n\t\\end{itemize}\n\n\t\\item Example R-Interpretation: \n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{vif1.png}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{vif2.png}\n\t\\end{figure}\n\tlarge p-value, large VIF $\\rightarrow$ high correlation among predictors. Call correlation matrix.\n\t\n\tFind out and remove one of the highly correlated predictors.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{vif3.png}\n\t\\end{figure}\n\\end{itemize}\n\n\\subsection{Homoscedasticity}\n\\begin{itemize}\n\t\\item Definition: \\textbf{each residual $\\sigma_i$} of predictor $X_i$ exhibit \\textbf{constant} variance.\n\t\n\t$\\rightarrow$ the spread of residual in different predictors remains nearly the same. \n\t\n\t$\\rightarrow$ no systematic development(grows larger/smaller) of residuals -- \\textbf{Heteroscedasticity}\n\t\n\t\\item Testing: \n\t\\begin{itemize}\n\t\t\\item \\textbf{Breusch-Pagan Test}\n\t\t\\item \\textbf{White Test}\n\t\t\\begin{itemize}\n\t\t\t\\item $H_0$: all variances $\\sigma_i$ are equal (homoscedasticity)\n\t\t\t\n\t\t\t$H_1$: heteroscedasticity\n\t\t\t\\item Distribution: $\\chi^2$-Distribution\n\t\t\t\\item reject $H_0$ if $p < \\alpha$ \n\t\t\\end{itemize}\n\t\\end{itemize}\n\n\t\\item Consequence of Heteroscedasticity:\n\t\\begin{itemize}\n\t\t\\item estimated variance of coefficients $Var(\\hat{\\beta})$ is \\textbf{biased}.\n\t\t\\item OLS Estimator no longer efficient.\n\t\t\\item Some predictors has more ''weight'' than others $\\rightarrow$ higher sensitivity\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsection{No Autocorrelation}\n\\begin{itemize}\n\t\\item Definition: no correlation between the $i^{th}$ and $j^{th}$ \\textbf{overall residual}\n\t\n\t$\\rightarrow$ $Cor(\\varepsilon_i, \\varepsilon_j) = 0$\n\t\n\t$\\rightarrow$ \\textbf{no pattern} of residuals should be observed over time, in case of \\textbf{time series data}.\n\t\n\t\n\t\\item Testing:\n\t\n\tThe significance test of coefficients might say they are significant from 0. However, Autocorrelation detected. \n\t\\begin{itemize}\n\t\t\\item visualize residuals against time\n\t\t\\item \\textbf{Durbin-Watson statistic [0,4]}: test for first-order autocorrelation\n\t\t$$DW = \\frac{\\Sigma_{i=2}^n (e_i - e_{i-1})^2}{\\Sigma_{i=1}^n e_i^2}$$\n\t\t\\paragraph{Interpretation of DW-statistic}\n\t\t\\begin{itemize}\n\t\t\t\\item DW = 2: \\textbf{no} autocorrelation\n\t\t\t\n\t\t\tRule of thumb: DW $\\in$ [1.5, 2.5] $\\rightarrow$ no serial correlation\n\t\t\t\\item DW = 0: perfect \\textbf{positive} autocorrelation\n\t\t\t\\item DW = 4: perfect \\textbf{negative} autocorrelation\n\t\t\\end{itemize}\n\t\\end{itemize}\n\n\t\\item Consequences for autocorrelation:\n\t\\begin{itemize}\n\t\t\\item an important predictor is omitted (which explains the pattern over time)\n\t\t\\item functional misfit \n\t\t\\item measurement error in predictors\n\t\\end{itemize}\n\n\t\\item Solution to autocorrelation: Model the missing predictor\n\t\\begin{itemize}\n\t\t\\item overall trend in time: t \n\t\t\\item dummy variable for seasonal indexes $Q_1$, $Q_2$, $Q_3$\n\t\t\n\t\tnumber of dummy variables: \\textbf{number of choices -1} $\\rightarrow$ avoid multicollinearity\n\t\\end{itemize}\n\n\tExample Model: \n\t$$y = \\beta_0 + \\beta_1\\cdot t + \\beta_2 \\cdot Q_1 + \\beta_3 \\cdot Q_2 + \\beta_4 \\cdot Q_3$$\n\\end{itemize}\n\n\\subsection{Exogeneity}\n\\begin{itemize}\n\t\\item Definition: the expected value of \\textbf{residual vector} given all predictors is 0.\n\t\n\t$\\rightarrow$ $E(\\varepsilon|X) = 0$, $Cov(\\varepsilon, X) = 0$\n\t\t\n\t\n\t\\item Consequences for Endogeneity(not exogene):\n\t\\begin{itemize}\n\t\t\\item measurement error\n\t\t\\item predictors and response effect each other mutually\n\t\t\\item \\textbf{important predictors are omitted} $\\rightarrow$ bias in estimation of coefficients \n\t\\end{itemize}\n\t\n\t\\item Testing for individual effects: \\textbf{Lagrange Multiplier Test}, in R ''plmtest(model)''\n\t\\begin{itemize}\n\t\t\\item $H_0$: No individual effects\n\t\\end{itemize}\n\t\\item Testing for fixed or random effect model when Lagrange Multiplier Test fails: \\textbf{Hausman Test}\n\t\\begin{itemize}\n\t\t\\item $H_0$: random effect estimator is consistent \\& efficient $\\rightarrow$ \\textbf{random effect model}\n\t\t\n\t\t$H_1$: \\textbf{fixed effect model} needed.\n\t\\end{itemize}\n\t\n\t\\item Solution to endogeneity due to omitted variable bias:\n\t\n\taccording to types of data: \n\t\\paragraph{cross-section data} data observing many objects at the same time\n\t\t\n\tdifficult to find out the confounding variables $\\rightarrow$ \\textbf{no solution}\n\t\\paragraph{panel data} repeated observations on the same objects over time. Mostly unbalanced panel data, where some individuals are not recorded in all time period. \n\t\n\t$\\rightarrow$ individual-specific panel data structure\n\t\n\t$\\rightarrow$ find out the omitted individual-specific effects on the response.\n\t\n\tSolution:\n\t\\begin{itemize}\n\t\t\\item \\textbf{Fixed Effects Model}: \n\t\tIndividual/Entity-specific effects are \\textbf{correlated} to other predictors\n\t\t\n\t\t$\\rightarrow \\lambda_i$ is constant, can be seen as \\textbf{an additional intercept} for each individual $i$ in regression model. \n\t\t\n\t\t$$y_{it} = (\\beta_0 + \\lambda_i) + \\beta_1 x_{1it} + \\beta_2 x_{2it} + \\dots + \\beta_k x_{kit} + \\varepsilon_{it}$$\n\t\t\n\t\tEstimators for the fixed effect models: first differences, within, least square dummy variable\n\t\t\\item \\textbf{Random Effects Model}: \n\t\tIndividual/Entity-specific effects are \\textbf{uncorrelated} to other predictors\n\t\t\n\t\t$\\rightarrow \\lambda_i$ is drawn independently, can be seen as \\textbf{an element of residual} for each individual in regression model.\n\t\t$$y_{it} = \\beta_0 + \\beta_1 x_{1it} + \\beta_2 x_{2it} + \\dots + \\beta_k x_{kit} + \\underbrace{(\\lambda_i + u_{it})}_{\\varepsilon_{it}}$$\t\n\t\\end{itemize} \n\\end{itemize}\n\n\n", "meta": {"hexsha": "1dbd77649ea6158b318407ef3950c9802b535b4a", "size": 8672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/regression_diagnostics.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/regression_diagnostics.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/regression_diagnostics.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": 37.5411255411, "max_line_length": 167, "alphanum_fraction": 0.7338560886, "num_tokens": 2642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.8757869819218865, "lm_q1q2_score": 0.7713906200886332}}
{"text": "\\lab{1-d Optimization}{1-d Optimization}\n\\label{lab:1-dOpt}\n\\objective{To help students be comfortable with all the techniques of 1-d optimization. This will prepare them for later line-search methods in higher-dimensional optimization.}\n\n\\section*{Overview of 1-d Optimization}\nImagine you are out hiking on a mountain, and you lose track of the trail. Thick fog\ngathers around, reducing visibility to just a couple of feet. You decide it is time\nto head back home, which is located in the valley located near the base of the mountain.\nHow can you find your way back with such limited visibility? The obvious way might be to\npick a direction that leads downhill, and follow that direction as far as you can, or\nuntil it starts leading upward again. Then you might choose another downhill direction,\nand take that as far as you can, repeating the process. By always choosing a downhill\ndirection, you hope to eventually make it back to the bottom of the valley, where you live.\n\nThis is the basic approach of line search algorithms for numerical optimization.\nSuppose we have a real-valued function $f$ that we wish to minimize. Our goal is to find the\npoint $x^*$ in the domain of $f$ such that $f(x^*)$ is the smallest value in the range of\n$f$. For some functions, we can use techniques from calculus to analytically obtain this\nminimizer. However, in practical applications, this is often impossible, especially when\nwe need a system that works for a wide class of functions. A line search algorithm starts with\nan initial guess at the minimizer, call it $x_0$, and iteratively produces a sequence of\npoints $x_1, x_2, x_3, \\ldots$ that hopefully converge to the minimizer $x^*$. The basic\niteration to move from $x_k$ to $x_{k+1}$ involves two steps: first, choosing a search direction $p_k$\nin which to proceed from the current point, and second, specifying a step size $\\alpha_k$ to travel\nin this direction. The next point is determined by the formula\n$$\nx_{k+1} = x_k + \\alpha_kp_k.\n$$\nThis procedure is called a line search because at each iteration, we are simply examining the\nfunction in a particular linear direction. The choice of the step size $\\alpha_k$ is often\nchosen by solving a one-dimensional optimization problem in the given direction. In this lab,\nwe will discuss approaches to choosing the step size and the search direction.\n\nLine search procedures are an integral part of many nonlinear optimization techniques.\nIn some sense, they represent the simplest nontrivial case in general optimization, as\nwe only have to worry about one parameter. And yet far more sophisticated optimization\nalgorithms really crucially on the effectiveness and efficiency of line searches, since\nhigher-dimensional problems are often broken down into one-dimensional optimizations.\nThere are many different line search methods, and their effectiveness depends very much\non the nature of the optimization problem. Although the line search procedure is often\nonly a subroutine of the optimization algorithm at hand, understanding the basics of\nthe line search is necessary for understanding the robustness of the entire algorithm.\n\\section*{Optimizing Functions on the Real Numbers}\n\\subsection*{Derivative versus Derivative-Free Methods}\nAs you have seen in calculus classes, the derivative of a function gives information\nabout how the value of the function changes at each point, and can be used to determine\nlocal optima. However, not all objective functions are differentiable, so we need other\ntechniques at our disposal. Line search methods may be broadly separated into two groups\nbased on whether they use the derivative of the objective function. We discuss two\nsimple examples to illustrate this distinction.\n\n\\subsection*{Golden Section Search}\nThis method is appropriate when minimizing a real-valued function on the reals over a\nclosed interval. The function must further satisfy the \\emph{unimodal} property, i.e.\nit has just one local minimum, and is monotonic to the left and right of the minimum.\nThe goal, of course, is to find the\nglobal minimum. We do this by making a sequence of guesses that we hope will converge\nquickly to the minimum. Although we may not end up with the exact minimum, this method\nwill allow us to pin down the true minimum within an interval of any given width in a\nfinite number of steps.\n\nFor the Golden Section Search, each step consists of evaluating the function at two\npoints within the current interval, comparing these values, and then reducing the size\nof the interval for the next step. Let us consider a typical step in the algorithm. At\nthe outset, we have our function $f$ and a closed interval $[a, b]$ over which we seek\nto minimize $f$. Choose two points $a'$ and $b'$ within the interval, and assume that\n$a' < b'$. Now calculate $f(a')$ and $f(b')$, and assume that $f(a') \\geq f(b')$.\nBecause of the unimodal condition, we now know that the minimizer must be in the\ninterval $[a', b]$, for otherwise the function $f$ would have a local minimum in\nboth $[a, a']$ and $[a', b]$. In the next step, we repeat the process over the interval\n$[a', b]$. If instead we had $f(b') \\geq f(a')$, then we choose the interval $[a, b']$\nfor the next step, and if the two values are equal, then it does not matter which\ninterval is chosen.\n\nWe now have the basic description of the algorithm, but how do we choose the two test\npoints $a'$ and $b'$? There is in fact an optimal choice, which reduces the amount of\nwork we have to do. Given an interval $[a, b]$, choose $a'$ and $b'$ satisfying\n\\begin{align*}\na' &= a + \\rho(b - a) \\\\\nb' &= a + (1 - \\rho)(b - a),\n\\end{align*}\nwhere $\\rho = \\frac{1}{2}(3 - \\sqrt{5}) \\approx 0.382$. By choosing these particular\npoints, we need to only evaluate the function at one additional point in the next step.\nTo demonstrate this fact, the reader may verify that, within the interval $[a, b']$,\nthe point $a'$ already satisfies the equation\n\\begin{equation*}\na' = a + (1 - \\rho)(b' - a),\n\\end{equation*}\nand so we need only evaluate the function at the point $c$ satisfying\n\\begin{equation*}\nc = a + \\rho(b' - a).\n\\end{equation*}\n(The constant $\\rho$ is not difficult to derive, and is related to the famous Golden Ratio, hence the name of this algorithm.)\n\nAt each step, the interval is reduced by a factor of $1-\\rho$, which means that after\n$n$ steps, we have pinned down the minimizer to within an interval approximately\n$(0.61803)^n$ times the length of the original interval. Note that this convergence is\nindependent of the objective function.\n\n\\begin{problem}\nImplement Golden Section Search as described above. Use this to minimize $e^x - 4x$\non the interval $\\lbrack 0, 3 \\rbrack$. How many steps do you need to take to get\nwithin $.001$ of the true minimizer? Check that with the sentence preceding this\nproblem.\n\\end{problem}\n\n\\subsection*{One-Dimensional Newton's Method}\nLet us first start out with a basic task: minimizing a function of one variable.\nWe will use a popular approach known as Newton's Method, which is a basic line search\nalgorithm that uses the derivatives of the function to select a direction and\nstep size.\n\nTo use this method, we need a real-valued function of a real variable that is twice\ndifferentiable. The idea is to approximate the function with a quadratic polynomial and\nthen solve the trivial problem of minimizing the polynomial. Doing so in an iterative\nmanner can lead us to the actual minimizer. Let $f$ be a function satisfying the\nappropriate conditions, and let us make an initial guess, $x_0$. The relevant quadratic\napproximation to $f$ is\n\\begin{equation*}\nq(x) = f(x_0) + f'(x_0)(x-x_0) + \\frac{1}{2}f''(x_0)(x-x_0)^2,\n\\end{equation*}\nor just the second-degree Taylor polynomial for $f$ centered at $x_0$. The minimum\nfor this quadratic function is easily found by solving $q'(x) = 0$, and we take the\nobtained $x$-value as our new approximation. The formula for the $(n+1)$-th\napproximation, which the reader can verify, is\n\\begin{equation*}\nx_{n+1} = x_n - \\frac{f'(x_n)}{f''(x_n)}.\n\\end{equation*}\nIn the one dimensional case, there are only two search directions: to the right ($+$)\nor to the left ($-$). Newton's method chooses the search direction \n$\\text{sign}(-f'(x_n)/f''(x_n))$ and the step size $|f'(x_n)/f''(x_n)|$.\n\nAs is typical with optimization algorithms, Newton's Method generates a sequence of\npoints or successive approximations to the minimizer. However, the convergence\nproperties of this sequence depend heavily on the initial guess $x_0$ and the function\n$f$. Roughly speaking, if $x_0$ is sufficiently close to the actual minimizer, and if\n$f$ is well-approximated by parabolas, then one can expect the sequence to converge\nquickly. However, there are cases when the sequence converges slowly or not at all.\nSee Figure \\ref{linesearch:newton}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{newton.pdf}\n\\caption{The results of Newton's Method using two\ndifferent initial guess. The global minimizer was\ncorrectly found with initial guess of 1. However,\nan initial guess of 4 led to only a local minimum.}\n\\label{linesearch:newton}\n\\end{figure}\n\n\\begin{problem}\nImplement Newton's Method as described using the following function declaration. \n\\begin{lstlisting}\ndef newton1d(f, df, ddf, x, niter=10):\n    '''\n    Perform Newton's method to minimize a function from R to R.\n    \n    Parameters\n    ----------\n    f : callable function object \n        The objective function (twice differentiable)\n    df : callable function object \n        The first derivative\n    ddf : callable function object\n        The second derivative\n    x : float\n        The initial guess\n    niter : integer\n        The number of iterations\n        \n    Returns\n    ------\n        min : float\n            The approximated minimizer\n    '''\n    pass\n\\end{lstlisting}\n\nUse this function to minimize $x^2 + \\sin(5x)$ with an initial guess of $x_0 = 0$.\nNow try other initial guesses farther away from the true minimizer, and note when the\nmethod fails to obtain the correct answer.\n\\end{problem}\n\n\\section*{General Line Search Methods}\n\\subsection*{Step Size Calculation}\nWe now examine Line Search methods in more generality. Given a differentiable function\n$f : \\mathbb{R}^n \\rightarrow \\mathbb{R}$ that we wish to minimize, and assuming that\nwe already have a current point $x_k$ and direction $p_k$ in which to search, how do we\nchoose our step size $\\alpha_k$? If our step size is too small, we will not make good progress\ntoward the minimizer, and convergence will be slow. If the step size is too large, however,\nwe may overshoot and produce points that are far away from the solution.\nA common approach to pick an appropriate step size involves the \\emph{Wolfe conditions}:\n\n\\begin{align*}\n&f(x_k + \\alpha_kp_k) \\leq f(x_k) + c_1\\alpha_k\\nabla f_k^Tp_k, &(0 < c_1 < 1),\n\\\\ &\\nabla f(x_k + \\alpha_kp_k)^Tp_k \\geq c_2\\nabla f_k^Tp_k, &(c_1 < c_2 < 1).\n\\end{align*}\n\nHere, we use the shorthand notation $\\nabla f_k$ to\nmean the gradient of $f$ evaluated at the point $x_k$. The search direction $p_k$ is\noften required to satisfy $p_k^T \\nabla f_k < 0$, in which case it is called a\n\\emph{descent direction}, since the function is guaranteed to decrease in\nthis direction. Generally speaking, choosing a step size $\\alpha_k$ satisfying these conditions\nensures that we achieve sufficient decrease in the function and also that we do not\nterminate the search at a point of steep decrease (since then we could achieve even\nbetter results by choosing a slightly larger step size). The first condition is known\nas the \\emph{Armijo} condition.\n\nFinding such a step size satisfying these conditions is not always an easy task, however.\nOne simple approach, known as \\emph{backtracking}, starts with an initial step size\n$\\alpha$, and repeatedly scales it down until the Armijo condition is satisfied.\nThat is, choose $\\alpha >0, \\rho \\in (0, 1), c\\in (0, 1)$, and while\n$$\nf(x_k + \\alpha p_k) > f(x_k) + c\\alpha\\nabla f_k^Tp_k,\n$$\nre-scale $\\alpha := \\rho\\alpha$. Once the loop terminates, set $\\alpha_k = \\alpha$. Note that the value\n$\\nabla f_k^Tp_k$ remains fixed for the duration of the backtracking algorithm, and hence need only\nbe calculated once at the beginning.\n\n\\begin{problem}\nImplement this backtracking algorithm using the following function declaration. \n\\begin{lstlisting}\ndef backtracking(f, slope, x, p, a=1, rho=.9, c=10e-4):\n    '''\n    Perform a backtracking line search to satisfy the Armijo condition.\n    \n    Parameters\n    ----------\n    f : callable function object\n        The objective function\n    slope : float \n        The value of grad(f)^T p\n    x : ndarray of shape (n,) \n        The current iterate\n    p : ndarray of shape (n,) \n        The current search direction\n    a : float \n        The intial step length (set to 1 in Newton and quasi-Newton methods)\n    rho : float \n        A number in (0,1)\n    c : float \n        A number in (0,1)\n    \n    Returns\n    -------\n        alpha : float\n            The computed step size satisfying the Armijo condition.\n    '''\n    pass\n\\end{lstlisting}\n\\end{problem}\n\n\n\\begin{problem}\nImplement the Gradient Descent algorithm and Newton's Method using the following function declarations.\nIn each function, you should call your backtracking function with\nvalues $\\alpha = 1, \\rho = .9$, and $c = 10^{-4}$. The \\li{scipy.linalg} module\nmay be useful when computing the search direction in Newton's Method.\n\\begin{lstlisting}\ndef gradientDescent(f, df, x, niter=10):\n    '''\n    Minimize a function using gradient descent.\n    \n    Parameters\n    ----------\n    f : callable function object \n        A differentiable real-valued function\n    df : callable function object \n        The gradient of the function\n    x : ndarray of shape (n,) \n        The initial point\n    niter : integer \n        The number of iterations to run.\n    \n    Returns\n    -------\n        pts: list of ndarrays \n            The sequence of points generated\n    '''\n    pass\n\ndef newtonsMethod(f, df, ddf, x, niter=10):\n    '''\n    Minimize a function using Newton's method.\n    \n    Parameters\n    ----------\n    f : callable function object\n        Real-valued, twice-differentiable function\n    df : callable function object\n        The gradient of the function\n    ddf : callable function object \n        The Hessian of the function\n    x : ndarray of shape (n,) \n        The initial point\n    niter : integer \n        The number of iterations\n        \n    Returns\n    -------\n    pts : list of ndarrays\n        The sequence of points generated\n    '''\n    pass\n\\end{lstlisting}\n\n\\end{problem}\n\n\\subsection*{Line Search in SciPy}\nThe SciPy module \\li{scipy.optimize} contains implementations of various optimization algorithms,\nincluding several line search methods. In particular, the module provides a useful routine for\ncalculating a step size satisfying the Wolfe Conditions described above, which is more robust\nand efficient than our simple backtracking approach. We recommend its use for the remainder of\nthis lab. The function is called \\li{line_search}, and accepts several arguments. We can typically\nleave the keyword arguments at their default values, but we do need to pass in the objective\nfunction, its gradient, the current point, and the search direction. The following code gives\nan example of its usage, using the objective function $f(x, y) = x^2+4y^2$.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.optimize import line_search\n>>>\n>>> def objective(x):\n>>>     return x[0]**2 + 4*x[1]**2\n>>>\n>>> def grad(x):\n>>>     return 2*x*np.array([1, 4])\n>>>\n>>> x = np.array([1., 3.]) #current point\n>>> p = -grad(x)           #current search direction\n>>> a = line_search(objective, grad, x, p)[0]\n>>> print a\n0.125649913345\n\\end{lstlisting}\nNote that the function returns a tuple of values, the first of which is the step size. We have illustrated\nthe very basic use of this function. See the documentation for further uses.\n", "meta": {"hexsha": "84db5407bf1d8ea8209a7daf9d20233cd4a4449d", "size": 15965, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2B/1-d_Optimization/1-d_Optimization.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/1-d_Optimization/1-d_Optimization.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/1-d_Optimization/1-d_Optimization.tex", "max_forks_repo_name": "joshualy/numerical_computing", "max_forks_repo_head_hexsha": "9f474e36fe85ae663bd20e2f2d06265d1f095173", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-11-05T14:45:03.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-05T14:45:03.000Z", "avg_line_length": 47.5148809524, "max_line_length": 177, "alphanum_fraction": 0.7346069527, "num_tokens": 3991, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8757869867849166, "lm_q1q2_score": 0.7713906134104416}}
{"text": "%================================\n\\section{Boundaries}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[boundaries]\n\t\\label{def: boundaries}\n\tLet $A$ be any set, the \\textit{boundary} of $A$, denoted $\\partial A$, is defined to be the complement of the interior of $A$ in the closure of $A$; i.e.,\n\t$$\n\t\\partial A = \\overline A \\setminus A^\\circ.\n\t$$\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t[properties of boundaries]\n\t\\label{prop: properties of boundaries}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $A \\subseteq X$.\n\t\\begin{enumerate}[(i)]\n\t\t\\item \n\t\t$\\partial A$ is closed.\n\t\t\n\t\t\\item\n\t\t$A^\\circ \\cap \\partial A = \\emptyset$.\n\t\t\n\t\t\\item\n\t\t$\\overline A = A^\\circ \\cup \\partial A$.\n\t\t\n\t\t\\item\n\t\t$A$ is closed iff $\\partial A \\subseteq A$.\n\t\t\n\t\t\\item\n\t\t$\\partial A$ is nowhere dense.\n\t\t\n\t\t\\item\n\t\t$\\partial \\overline A \\subseteq \\partial A \\subseteq \\partial A^\\circ$.\n\t\t\n\t\t\\item\n\t\t$\\partial A = \\partial (X \\setminus A)$.\n\t\t\n\t\t\\item\n\t\t$A$ is dense iff $\\partial A = X \\setminus A^\\circ$.\n\t\t\n\t\\end{enumerate}\n\t\n\t\\begin{proof} \\\n\t\t\\begin{enumerate}[(i)]\n\t\t\t\\item\n\t\t\t$\\overline A$ is closed, and $X \\setminus A^\\circ$ is also closed. Thus\n\t\t\t$$\n\t\t\t\\partial A = \\overline A \\setminus A^\\circ = \\overline A \\cap (X \\setminus A)\n\t\t\t$$\n\t\t\tis closed.\n\t\t\t\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: boundaries}, we have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\partial A = \\overline A \\setminus A^\\circ &\\iff \\partial A \\cap A^\\circ = \\overline A \\setminus A^\\circ \\cap A^\\circ = \\overline A \\cap \\emptyset = \\emptyset.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tWe have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\partial A = \\overline A \\setminus A^\\circ &\\iff \\partial A \\cup A^\\circ = \\overline A \\setminus A^\\circ \\cup A^\\circ = \\overline A \\cap (X \\setminus A^\\circ \\cup A^\\circ) \\\\\n\t\t\t\t&\\iff \\partial A \\cup A^\\circ = \\overline A \\cap X |_\\text{for $A^\\circ \\subseteq X$} = \\overline A.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item As $A$ is closed, $A = \\overline A$ (this can be straightly proved by Definition \\ref{def: closure}). By Definition \\ref{def: boundaries}, it is clear that $\\partial A \\subseteq \\overline A$, thus $\\partial A \\subseteq A$.\n\t\t\t\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: nowhere dense sets}, $\\partial A$ is nowhere dense iff $\\overline{\\partial A}^\\circ$ is empty. We have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\overline{\\partial A}^\\circ &= \\overline{\\overline A \\setminus A^\\circ}^\\circ \\\\\n\t\t\t\t&= (\\overline A \\setminus A^\\circ) \\cup (\\overline A \\setminus A^\\circ) \\setminus (\\overline A \\setminus A^\\circ) \\\\\n\t\t\t\t&= \\emptyset.\n\t\t\t\\end{aligned}\t\t\t\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\t$\\overline A \\supseteq A^\\circ$ implies $\\overline A^\\circ \\supseteq (A^\\circ)^\\circ = A^\\circ$, then we have,\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\partial \\overline A &= \\overline{\\overline A} \\setminus  \\overline A^\\circ \\subseteq \\overline A \\setminus A^\\circ = \\partial A.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t$A^\\circ \\subseteq A$ implies $ \\overline{A^\\circ} \\subseteq \\overline A$, then we have,\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\partial A^\\circ = \\overline{A^\\circ} \\setminus (A^\\circ)^\\circ \\supseteq \\overline A \\setminus A^\\circ.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tWe have\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\partial (X \\setminus A) &= \\overline{X \\setminus A} \\setminus (X \\setminus A)^\\circ \\\\\n\t\t\t\t&= X \\setminus A^\\circ \\setminus (X \\setminus \\overline A) \\\\\n\t\t\t\t&= X \\setminus A^\\circ \\cap \\overline A \\\\\n\t\t\t\t&= \\overline A \\setminus A^\\circ \\\\\n\t\t\t\t&= \\partial A.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\t\n\t\t\t\\item\n\t\t\tBy Definition \\ref{def: dense sets}, $A$ is dense  in $X$ iff $\\overline A = X$. Then we have,\n\t\t\t$$\n\t\t\t\\begin{aligned}\n\t\t\t\t\\overline A = X &\\iff \\overline A \\setminus A^\\circ = X \\setminus A^\\circ \\\\\n\t\t\t\t&\\iff \\partial A = X \\setminus A^\\circ.\n\t\t\t\\end{aligned}\n\t\t\t$$\n\t\t\\end{enumerate}\n\t\\end{proof}\n\\end{proposition}\n%--------------------------------", "meta": {"hexsha": "fa79f629003092af607a5ba1c97e5f9fe0226720", "size": 3913, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/boundaries.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/boundaries.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/boundaries.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": 31.0555555556, "max_line_length": 231, "alphanum_fraction": 0.5801175569, "num_tokens": 1370, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.880797071719777, "lm_q1q2_score": 0.7713906119826607}}
{"text": "\\section{Some Point Set Topology}\n\n\\subsection{Naive Set Theory}\n\n\\subsubsection{Theorem 1}\nWe only prove (10) to illustrate the technique; the other parts are either immediate\nfrom definitions or can be proved similarly.\n\n(10) \n\\begin{align*}\n        &x \\in \\bigg(\\cup_{S_i \\in \\mathcal{S}_1} S_i\\bigg) \\cap \\bigg(\\cup_{S_i \\in \\mathcal{S}_2} S_i\\bigg) \\\\\n        \\implies &\\exists i, j \\: | \\: x \\in S_i \\cap S_j \\implies x \\in \\cup_{S_i \\in \\mathcal{S}_1, S_j \\in \\mathcal{S}_2} (S_i \\cap S_j) \\\\\n                 &x \\in \\cup_{S_i \\in \\mathcal{S}_1, S_j \\in \\mathcal{S}_2} (S_i \\cap S_j) \\implies \\exists i, j \\: | \\: x \\in S_i \\cap S_j \\\\\n        \\implies &x \\in \\bigg(\\cup_{S_i \\in \\mathcal{S}_1} S_i\\bigg) \\cap \\bigg(\\cup_{S_i \\in \\mathcal{S}_2} S_i\\bigg)\n\\end{align*}\n\n", "meta": {"hexsha": "83ce89575f80e74a1daa1096cfe3c976c9196dc1", "size": 776, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture_Notes_Topology_Geometry_Singer_Thorpe/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": "Lecture_Notes_Topology_Geometry_Singer_Thorpe/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": "Lecture_Notes_Topology_Geometry_Singer_Thorpe/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": 45.6470588235, "max_line_length": 142, "alphanum_fraction": 0.6301546392, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9664104933824753, "lm_q2_score": 0.798186775339273, "lm_q1q2_score": 0.7713760753669937}}
{"text": "\\chapter{Differentials}\n\n\\section{Differentiator}\n\n\\index{differentiator}%\nThe \\emph{differentiator}\n\\(d : (\\Real \\to \\Real) \\to (\\Real \\to \\Real)\\)\nis \\(d(f) = \\lim_{h\\to 0} \\frac{f(x+h)-f(x)}{h}\\).\n\nIf \\(d\\) is the differentiator and \\(f\\) is a function,\nwe will abuse the notation \\(df\\) to mean \\(d(f)\\).\n\nWrite \\(d^{n+1}\\) to mean \\(d \\circ d^n\\)\nwhere \\(\\circ\\) is function composition\nand \\(n \\in \\Nat\\).\nThus \\(d^{n+1}(f) = d(d^n(f))\\).\n\n\\section{Properties}\n\n\\index{derivative!linearity}%\n\\paragraph{Linearity}\nIf \\(c\\) is a constant function, then \\(d(c \\cdot f) = c \\cdot df\\).\nAlso, \\(d(f+g) = df + dg\\).\n\n\\index{derivative!product rule}%\n\\index{product rule}%\n\\paragraph{Product rule}\n\\(d(f \\cdot g) = df \\cdot g + f \\cdot dg\\).\n\n\\index{derivative!chain rule}%\n\\index{chain rule}%\n\\paragraph{Chain rule}\n\\(d(f \\circ g) = dg \\cdot (df \\circ g)\\).\n\n\\index{derivative!power rule}%\n\\index{power rule}%\n\\paragraph{Power rule}\n\\(d(x \\to x^n) = n x^{n-1}\\).\n\n\\section{Vector differential calculus}\n\n\\index{directional derivative}%\n\\index{derivative!directional}%\n\\paragraph{Directional derivative}\nThe derivative of \\(f : \\Real^n \\to \\Real^m\\) at direction \\(v\\) at point \\(x\\) is\n\\((d_v f)(x) = \\lim_{h\\to 0}\\frac{f(x+h v)-f(x)}{h}\\)\nwhere \\(h : \\Real\\).\n\n\\paragraph{Partial derivative}\nLet \\(f : \\Real^n \\to \\Real^m\\) and\n\\(f_k(x) = (f(x))_k\\).\nThe\n\\index{partial derivative}%\n\\emph{partial derivative of \\(f\\) with respect to the \\(k\\)th variable} is\n\\((d_k f)(x) = \\lim_{h\\to 0}\\frac{f(x+he_k)-f(x)}{h}\\)\nwhere \\(h : \\Real\\) and\n\\((e_k)_i = [k = i]\\) is a standard basis vector.\n\n\\index{gradient}%\n\\paragraph{Gradient}\nThe \\emph{gradient} of \\(f\\) is the \\(\\nabla f\\)\nthat satisfies \\((\\nabla f)(x) \\cdot v = (d_v f)(x)\\).\nIt is also written \\(\\fgrad(f)\\).\n\nThe symbol \\(\\nabla\\) is called \\emph{del} or \\emph{nabla}.\nIts type is \\((\\Real^n \\to \\Real) \\to (\\Real^n \\to \\Real^n)\\).\n\n\\section{Jacobian operator}\n\nThe\n\\index{Jacobian operator}%\n\\emph{Jacobian operator} \\(J : (\\Real^n \\to \\Real^m) \\to (\\Real^n \\to \\Real^{m \\times n})\\)\nsatisfies:\n\\[\n    [(Jf)(x)]_{ij} = (d_j f_i)(x)\n\\]\nThe matrix \\((Jf)(x)\\) is called the\n\\index{Jacobian matrix}%\n\\emph{Jacobian matrix of \\(f\\) at \\(x\\)}.\n\n\\section{Differential equation}\n\n\\index{differential equation}%\nA differential equation is something like \\(d^2f = -cf\\).\n\n\\paragraph{Fixed point of \\(d\\)}\n\\index{derivative!fixed point}%\nIff \\(f(x) = e^x\\), then \\(df = f\\)\nwhere \\(e\\) is Euler's constant, the base of natural logarithm.\n", "meta": {"hexsha": "c5ddd568bd81529e713619e4346e0fd47806336e", "size": 2488, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/differential.tex", "max_stars_repo_name": "edom/work", "max_stars_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_stars_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "research/differential.tex", "max_issues_repo_name": "edom/work", "max_issues_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_issues_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_issues_count": 4, "max_issues_repo_issues_event_min_datetime": "2020-12-02T18:37:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-16T00:55:32.000Z", "max_forks_repo_path": "research/differential.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.6444444444, "max_line_length": 91, "alphanum_fraction": 0.6322347267, "num_tokens": 896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.960361162033533, "lm_q2_score": 0.8031738034238806, "lm_q1q2_score": 0.7713369271710503}}
{"text": "\\section*{Problem 4: Naive Bayes: Theory [20 pts] (Brynn)}\n\nRecall the difference in the modeling assumptions in a discriminative and a generative classifier. In a generative model, $P(X,Y)$ is estimated by initially modeling the conditional $P(X|Y)$, since, $P(X,Y) = P(Y)P(X|Y)$. The joint probability with Bayes rule is then used to calculate $P(Y|X)$ for each class label. On the other hand, a discriminative classifier directly estimates $P(Y|X)$. In this problem, we will explore the relation between Naive Bayes and logistic regression classifiers, by focusing on the class conditional $P(Y|X)$.\n\nWhen Y is Boolean and $X = \\langle{X_{1}...X_{n}}\\rangle$ is a vector of continuous variables, and each $P(X_i | Y= y_k)$ is modelled with a Gaussian distribution, then the assumptions of the Gaussian Naive Bayes classifier imply that $P(Y\\mid{X})$ is given by the logistic function with\nappropriate parameters $w_0, w_1, .. w_n$. In particular:\n\n\\begin{align*}\n    P(Y=1\\mid{X})=\\frac{1}{1+exp(w_0+\\sum_{i=1}^{n} w_iX_i)}\n\\end{align*}\nand\n\\begin{align*}\n    P(Y=0\\mid{X})=\\frac{exp(w_0+\\sum_{i=1}^{n} w_iX_i)}{1+exp(w_0+\\sum_{i=1}^{n} w_iX_i)}\n\\end{align*}\n\n\\begin{enumerate}\n \n \n\\item Consider instead the case where Y is Boolean and ${X = \\langle{X_{1}...X_{n}}}\\rangle$ is a vector of Boolean variables. Show that the derived expression of $P(Y|X)$ has the same form as that in the Logistic Regression classifier model (by getting an appropriate expression, which can be substituted for weights in the $P(Y|X)$ equation for Logistic Regression).\n\n\n\\emph{Hints}\n\\begin{enumerate}\n    \\item Simple notation will help. Since the $X_{i}$ are Boolean variables, you need only one parameter to define $P(X_{i}\\mid{Y} = y_k)$. Define $\\theta_{i1} \\equiv P(X_{i} = 1\\mid{Y = 1})$, in which case $P(X_{i} = 0\\mid{Y = 1})$ = (1-$\\theta_{i1}$). Similarly, use $\\theta_{i0}$ to denote $P(X_{i} = 1|Y = 0)$.\n    \\item Notice with the above notation you can represent $P(Xi\\mid{Y = 1})$ as follows\n\\begin{align*}\n       P(X_{i}\\mid{Y = 1}) = \\theta_{i1}^{(X_i)}(1-\\theta_{i1})^{(1-X_i)}\n\\end{align*}\n    Note when $X_{i}$ = 1 the second term is equal to 1 because its exponent is zero. Similarly, when $X_{i}$ = 0 the first term is equal to 1 because its exponent is zero.\n\\end{enumerate}\n\\end{enumerate}\n\n\\newpage", "meta": {"hexsha": "0635c55ae1a73e0f97e4516136ebc994878f2897", "size": 2308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem4.tex", "max_stars_repo_name": "DylanFrank/Learn", "max_stars_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-24T09:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T12:55:26.000Z", "max_issues_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem4.tex", "max_issues_repo_name": "DylanFrank/Learn", "max_issues_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "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": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem4.tex", "max_forks_repo_name": "DylanFrank/Learn", "max_forks_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-10T02:18:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T07:45:23.000Z", "avg_line_length": 69.9393939394, "max_line_length": 542, "alphanum_fraction": 0.6980069324, "num_tokens": 740, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942014971872, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7713344349675856}}
{"text": "\\section{Positive semidefinite and positive definite matrices}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a matrix is positive semidefinite and/or\n    positive definite, either directly or by looking at the\n    eigenvalues.\n  \\item Determine whether a matrix is positive semidefinite and/or\n    positive definite using Descartes' rule of signs.\n  \\item Determine whether a matrix defines an inner product.\n  \\end{enumerate}\n\\end{outcome}\n\nIn Example~\\ref{exa:rn-with-inner-product}, we saw that it is\nsometimes possible to define an inner product on $\\R^n$ from an\n$n\\times n$-matrix $A$ by the formula\n\\begin{equation*}\n  \\iprod{\\vect{u},\\vect{v}} = \\vect{u}^T A \\vect{v}.\n\\end{equation*}\nWe will now explore in more detail under what conditions this formula\ndefines an inner product.\n\n\\begin{definition}{Positive semidefinite and positive definite matrices}{positive-matrix}\n  Let $A$ be an $n\\times n$-matrix over the real numbers.\n  \\begin{itemize}\n  \\item $A$ is called \\textbf{symmetric}%\n    \\index{symmetric matrix}%\n    \\index{matrix!symmetric} if $A=A^T$.\n  \\item $A$ is called \\textbf{positive semidefinite}%\n    \\index{positive semidefinite matrix}%\n    \\index{matrix!positive semidefinite}%\n    \\index{semidefinite} if it is symmetric and for all\n    $\\vect{v}\\in\\R^n$, we have $\\vect{v}^TA\\vect{v}\\geq 0$.\n  \\item $A$ is called \\textbf{positive definite}%\n    \\index{positive definite matrix}%\n    \\index{matrix!positive definite} if it is positive semidefinite\n    and $\\vect{v}^TA\\vect{v}=0$ if and only if $\\vect{v}=\\vect{0}$.\n\\end{itemize}\n\\end{definition}\n\nEquivalently, the positive definite property can also be stated as\nfollows: $A$ is positive definite if it is symmetric and for all\n$\\vect{v}\\in\\R^n$ with $\\vect{v}\\neq\\vect{0}$, we have\n$\\vect{v}^TA\\vect{v}>0$.\n\n\\begin{example}{Positive semidefinite and positive definite matrices}{positive-matrix}\n  Which of the following matrices are positive semidefinite? Which\n  ones are positive definite?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc} 2 & -1 \\\\ -1 & 1 \\end{mymatrix},\\quad\n    B = \\begin{mymatrix}{cc} 1 & 2 \\\\ 2 & 1 \\end{mymatrix},\\quad\n    C = \\begin{mymatrix}{cc} 1 & -1 \\\\ -1 & 1 \\end{mymatrix},\\quad\n    D = \\begin{mymatrix}{cc} 2 & 0 \\\\ 2 & 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The matrix $A$ is positive definite. To see why, consider any vector\n  $\\vect{v}=\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}$. Then\n  \\begin{equation*}\n    \\vect{v}^TA\\vect{v}\n    ~=~\n    \\begin{mymatrix}{cc} x & y \\end{mymatrix}\n    \\begin{mymatrix}{cc} 2 & -1 \\\\ -1 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    ~=~ 2x^2 - 2xy + y^2\n    ~=~ x^2 + (x-y)^2\n    ~\\geq~ 0.\n  \\end{equation*}\n  This inequality implies that $A$ is positive semidefinite. Moreover,\n  $\\vect{v}^TA\\vect{v}=0$ if and only if $x=0$ and $x-y=0$, which\n  implies $x=y=0$. So $\\vect{v}=\\vect{0}$ is the only solution of\n  $\\vect{v}^TA\\vect{v}=0$, and $A$ is positive definite.\n\n  The matrix $B$ is not positive semidefinite (and therefore not\n  positive definite either). For example, consider\n  $\\vect{v}=\\begin{mymatrix}{c} 1 \\\\ -1 \\end{mymatrix}$. Then\n  \\begin{equation*}\n    \\vect{v}^TB\\vect{v}\n    ~=~\n    \\begin{mymatrix}{cc} 1 & -1 \\end{mymatrix}\n    \\begin{mymatrix}{cc} 1 & 2 \\\\ 2 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{c} 1 \\\\ -1 \\end{mymatrix}\n    ~=~ 1-2-2+1\n    ~=~ -2\n    ~<~ 0,\n  \\end{equation*}\n  showing that $B$ is not positive semidefinite.\n\n  The matrix $C$ is positive semidefinite, but not positive definite.\n  To see why, consider\n  $\\vect{v}=\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}$. Then\n  \\begin{equation*}\n    \\vect{v}^TC\\vect{v}\n    ~=~\n    \\begin{mymatrix}{cc} x & y \\end{mymatrix}\n    \\begin{mymatrix}{cc} 1 & -1 \\\\ -1 & 1 \\end{mymatrix}\n    \\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}\n    ~=~ x^2 - 2xy + y^2\n    ~=~ (x-y)^2\n    ~\\geq~ 0.\n  \\end{equation*}\n  Therefore, $C$ is positive semidefinite. However, it is not positive\n  definite because, for example, for\n  $\\vect{v}=\\begin{mymatrix}{c} 1 \\\\ 1 \\end{mymatrix}$, we have\n  $\\vect{v}\\neq\\vect{0}$ but $\\vect{v}^TC\\vect{v}=0$.\n\n  The matrix $D$ is not symmetric, and therefore neither positive\n  semidefinite nor positive definite.\n\\end{solution}\n\nThe interest of positive definite matrices lies in the following\nproposition.\n\n\\begin{proposition}{Positive definite matrices and inner products on $\\R^n$}{positive-definite-and-inner-product}\n  Let $A$ be an $n\\times n$-matrix over the real numbers. Then the\n  formula\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}} = \\vect{u}^T A \\vect{v}\n  \\end{equation*}\n  defines an inner product on $\\R^n$ if and only if $A$ is positive\n  definite. Moreover, every inner product on $\\R^n$ arises from some\n  positive definite matrix $A$ in this way.\n\\end{proposition}\n\n\\begin{proof}\n  Define $\\iprod{\\vect{u},\\vect{v}} = \\vect{u}^T A \\vect{v}$. We will\n  check each of the three properties of an inner product from\n  Definition~\\ref{def:real-inner-product-space}. Linearity holds\n  for all matrices $A$, because\n  \\begin{equation*}\n    \\iprod{\\vect{u},k\\vect{v}}\n    ~=~ \\vect{u}^T A (k\\vect{v})\n    ~=~ k(\\vect{u}^T A \\vect{v})\n    ~=~ k\\iprod{\\vect{u},\\vect{v}}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\iprod{\\vect{u},\\vect{v}+\\vect{v}'}\n    ~=~ \\vect{u}^T A (\\vect{v}+\\vect{v}')\n    ~=~ \\vect{u}^T A \\vect{v} + \\vect{u}^T A \\vect{v}'\n    ~=~ \\iprod{\\vect{u},\\vect{v}} + \\iprod{\\vect{u},\\vect{v}'}.\n  \\end{equation*}\n  For symmetry, first observe that for all $\\vect{u},\\vect{v}$,\n  \\begin{equation*}\n    \\iprod{\\vect{v},\\vect{u}}\n    ~=~ \\vect{v}^T A \\vect{u}\n    ~=~ (\\vect{v}^T A \\vect{u})^T\n    ~=~ \\vect{u}^T A^T \\vect{v}.\n  \\end{equation*}\n  Therefore $\\iprod{\\vect{u},\\vect{v}}=\\iprod{\\vect{v},\\vect{u}}$ if\n  and only if $\\vect{u}^T A \\vect{v} = \\vect{u}^T A^T \\vect{v}$. This\n  holds for all $\\vect{u},\\vect{v}$ if and only if $A=A^T$. Therefore,\n  symmetry holds if and only if $A$ is symmetric.  Finally, the\n  positive definite property of the inner product holds, by\n  definition, if and only if $A$ is positive definite.\n\n  To prove the second part, consider any inner product\n  $\\iprod{\\vect{u},\\vect{v}}$ on $\\R^n$. Let\n  $\\vect{e}_1,\\ldots,\\vect{e}_n$ be the standard basis vectors, and\n  define $a_{ij} = \\iprod{\\vect{e}_i,\\vect{e}_j}$. Then\n  $A=\\mat{a_{ij}}$ is a matrix. We claim that\n  $\\iprod{\\vect{u},\\vect{v}}=\\vect{u}^TA\\vect{v}$ for all\n  $\\vect{u},\\vect{v}$. Indeed, let\n  $\\vect{u}=u_1\\vect{e}_1+\\ldots+u_n\\vect{e}_n$ and\n  $\\vect{v}=v_1\\vect{e}_1+\\ldots+v_n\\vect{e}_n$. Then\n  \\begin{eqnarray*}\n    \\iprod{\\vect{u},\\vect{v}}\n    &=& \\iprod{u_1\\vect{e}_1+\\ldots+u_n\\vect{e}_n,~ v_1\\vect{e}_1+\\ldots+v_n\\vect{e}_n} \\\\\n    &=& u_1v_1\\iprod{\\vect{e}_1, \\vect{e}_1}\n    +   u_1v_2\\iprod{\\vect{e}_1, \\vect{e}_2}\n    + \\ldots\n    +   u_nv_n\\iprod{\\vect{e}_n, \\vect{e}_n} \\\\\n    &=& u_1v_1a_{11}\n    +   u_1v_2a_{12}\n    + \\ldots\n    +   u_nv_na_{nn} \\\\\n    &=& \\vect{u}^TA\\vect{v}.\n  \\end{eqnarray*}\n  By the first part, $A$ is positive definite.\n\\end{proof}\n\nGiven a symmetric matrix $A$, it is not always an easy task to\ndetermine whether $A$ is positive definite (or semidefinite) by using\nthe definition directly. This would require checking the condition\n$\\vect{v}^TA\\vect{v}\\geq 0$ for {\\em all} vectors $\\vect{v}$, of which\nthere are infinitely many. The following proposition gives us a more\npractical method for determining whether a matrix is positive\n(semi)definite.\n\n\\begin{proposition}{Characterization of positive (semi)definite matrices using eigenvalues}{characterize-positive}\n  Let $A$ be a symmetric $n\\times n$-matrix, and let\n  $\\eigenvar_1,\\ldots,\\eigenvar_n$ be its eigenvalues. Then $A$ is\n  positive semidefinite if and only if\n  $\\eigenvar_1,\\ldots,\\eigenvar_n\\geq 0$. Moreover, $A$ is positive\n  definite if and only if $\\eigenvar_1,\\ldots,\\eigenvar_n>0$.\n\\end{proposition}\n\n\\begin{proof}\n  By Theorem~\\ref{thm:diagonalization-symmetric}, we know that $A$ is\n  orthogonally diagonalizable, i.e., $D=P^TAP$, where $P$ is an\n  orthogonal matrix and\n  \\begin{equation*}\n    D = \\begin{mymatrix}{ccc}\n      \\eigenvar_1 & \\cdots & 0 \\\\\n      \\vdots & \\ddots & \\vdots \\\\\n      0 & \\cdots & \\eigenvar_n\n    \\end{mymatrix}.\n  \\end{equation*}\n  Let $\\vect{v}=\\mat{x_1,\\ldots,x_n}^T$ be any vector, and let\n  $\\vect{w}=P\\vect{v}$. Then\n  $\\vect{w}^TA\\vect{w} = \\vect{v}^TP^TAP\\vect{v} =\n  \\vect{v}^TD\\vect{v}$, so that $A$ is positive (semi)definite if and\n  only if $D$ is positive (semi)definite. Also, we have\n  $\\vect{v}^TD\\vect{v} = \\eigenvar_1x_1^2 + \\ldots +\n  \\eigenvar_nx_n^2$. Therefore $\\vect{v}^TD\\vect{v}\\geq 0$ for all\n  $\\vect{v}$ if and only if $\\eigenvar_1,\\ldots,\\eigenvar_n\\geq\n  0$. Moreover, $\\vect{v}^TD\\vect{v}>0$ for all\n  $\\vect{v}\\neq \\vect{0}$ if and only if\n  $\\eigenvar_1,\\ldots,\\eigenvar_n>0$, as claimed.\n\\end{proof}\n\n\\begin{example}{Using eigenvalues to check whether a matrix is positive definite}{characterize-positive}\n  Use eigenvalues to determine whether the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      5 & 0 & 2 \\\\\n      0 & 5 & 1 \\\\\n      2 & 1 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  is positive definite, positive semidefinite, or neither.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    ~=~ \\begin{absmatrix}{ccc}\n      5-\\eigenvar & 0 & 2 \\\\\n      0 & 5-\\eigenvar & 1 \\\\\n      2 & 1 & 1-\\eigenvar \\\\\n    \\end{absmatrix}\n    ~=~ -\\eigenvar^3 + 11\\eigenvar^2 - 30\\eigenvar\n    ~=~ -\\eigenvar(\\eigenvar-5)(\\eigenvar-6).\n  \\end{equation*}\n  The eigenvalues are $\\eigenvar_1=0$, $\\eigenvar_2=5$, and\n  $\\eigenvar_3=6$.  Therefore, the matrix $A$ is positive\n  semidefinite, but not positive definite.\n\\end{solution}\n\nWhile Proposition~\\ref{prop:characterize-positive} gives us a method\nto determine whether a matrix $A$ is positive definite (or\nsemidefinite), it still requires finding all of the eigenvalues of\n$A$, i.e., to factor the characteristic polynomial. This can be a\ndifficult calculation, especially if the degree of the polynomial is\nlarge or if the roots are not integers. Fortunately, there is a better\nway to determine whether a matrix is positive definite (or\nsemidefinite) by directly looking at the characteristic polynomial,\nwithout having to calculate its roots. The method was found by\nRen\\'e Descartes%\n\\index{Descartes, Ren\\'e}%\n\\index{Ren\\'e Descartes} in 1637 and is called {\\em Descartes' rule\n  of signs}. The general form of Descartes' rule of signs is\nactually more complicated than what we consider here. We state a\nversion that has been specialized to characteristic polynomials of\nsymmetric matrices.\n\nLet $a_0,\\ldots,a_n$ be a sequence of real numbers. We say that\n$a_0,\\ldots,a_n$ have \\textbf{strongly alternating signs}%\n\\index{strongly alternating signs}%\n\\index{alternating signs!strongly}%\n\\index{sign!strongly alternating} if $a_0>0$,\n$a_1<0$, $a_2>0$, and so on (i.e., $a_i>0$ when $i$ is even, and\n$a_i<0$ when $i$ is odd). We say that $a_0,\\ldots,a_n$ have\n\\textbf{weakly alternating signs}%\n\\index{weakly alternating signs}%\n\\index{alternating signs!weakly}%\n\\index{sign!weakly alternating} if $a_0\\geq 0$, $a_1\\leq 0$,\n$a_2\\geq 0$, and so on (i.e., $a_i\\geq 0$ when $i$ is even, and\n$a_i\\leq 0$ when $i$ is odd).\n\n\n\\begin{proposition}{Descartes' rule of signs for positive (semi)definite matrices}{descartes-rule-of-signs}\n  Let $A$ be a symmetric $n\\times n$-matrix, and let\n  \\begin{equation*}\n    p(\\eigenvar) = a_n\\eigenvar^n + a_{n-1}\\eigenvar^{n-1} + \\ldots + a_1\\eigenvar + a_0\n  \\end{equation*}\n  be its characteristic polynomial. Then:\n  \\begin{itemize}\n  \\item $A$ is positive definite if and only if $a_0,\\ldots,a_n$ have\n    strongly alternating signs.\n  \\item $A$ is positive semidefinite if and only if $a_0,\\ldots,a_n$\n    have weakly alternating signs.\n  \\end{itemize}\n\\end{proposition}\n\n\\begin{proof}\n  We first prove a general fact about polynomials. Suppose $d_1,\\ldots,d_n$\n  are real numbers and\n  \\begin{equation*}\n    (x+d_1)(x+d_2)\\cdots(x+d_n) = b_nx^n + b_{n-1}x^{n-1} + \\ldots +\n    b_1x + b_0.\n  \\end{equation*}\n  Then $d_1,\\ldots,d_n > 0$ if and only if $b_0,\\ldots,b_n > 0$.\n  Moreover, $d_1,\\ldots,d_n \\geq 0$ if and only if $b_0,\\ldots,b_n \\geq 0$.\n\n  Proof: To prove the first claim, assume $d_1,\\ldots,d_n > 0$. It is\n  easy to see that by multiplying out $(x+d_1)(x+d_2)\\cdots(x+d_n)$,\n  we can only obtain positive coefficients, so $b_0,\\ldots,b_n >\n  0$. Conversely, assume $b_0,\\ldots,b_n > 0$. Then for every\n  $x\\geq 0$, we clearly have $b_nx^n + b_{n-1}x^{n-1} + \\ldots + b_1x + b_0 >\n  0$, and therefore no such $x\\geq 0$ can be a root of this\n  polynomial.  In other words, all of the roots must be\n  negative. Since the roots are $-d_1,\\ldots,-d_n$, it follows that\n  $d_1,\\ldots,d_n>0$. The proof of the second claim (using ``$\\geq$''\n  instead of ``$>$'') is similar.\n  \n  We are now ready to prove\n  Proposition~\\ref{prop:descartes-rule-of-signs}. By\n  Theorem~\\ref{thm:diagonalization-symmetric}, we know that $A$ is\n  diagonalizable, i.e., $A=PDP^{-1}$ for some real diagonal matrix\n  $D$. Note that $A$ and $D$ have the same characteristic\n  polynomial. If $d_1,\\ldots,d_n$ are the diagonal entries of $D$, the\n  characteristic polynomial can therefore be written in two different\n  ways:\n  \\begin{equation*}\n    p(\\eigenvar)\n    = (d_1-\\eigenvar)(d_2-\\eigenvar)\\cdots(d_n-\\eigenvar)\n    = a_0 + a_1\\eigenvar + a_2\\eigenvar^2 + a_3\\eigenvar^3 + \\ldots + a_n\\eigenvar^n.\n  \\end{equation*}\n  Now let $\\eigenvar=-x$ and consider\n  \\begin{equation*}\n    p(-x) = (d_1+x)(d_2+x)\\cdots(d_n+x)\n    = a_0 - a_1 x + a_2 x^2 - a_3x^3 + \\ldots \\pm a_n x^n.\n  \\end{equation*}\n  We have: $A$ is positive definite if and only if $d_1,\\ldots,d_n>0$,\n  if and only if $a_0,-a_1,a_2,-a_3,\\ldots > 0$, if and only if\n  $a_0,\\ldots,a_n$ are strongly alternating.  Moreover, $A$ is\n  positive semidefinite if and only if $d_1,\\ldots,d_n\\geq 0$, if and\n  only if $a_0,-a_1,a_2,-a_3,\\ldots \\geq 0$, if and only if\n  $a_0,\\ldots,a_n$ are weakly alternating.\n\\end{proof}\n\n\\begin{example}{Using Descartes' rule of signs to check if a matrix is positive definite}{descartes-rule-of-signs1}\n  Use Descartes' rule of signs to check whether the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      5 & 0 & 2 \\\\\n      0 & 5 & 1 \\\\\n      2 & 1 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  is positive definite, positive semidefinite, or neither.\n\\end{example}\n\n\\begin{solution}\n  We already found the characteristic polynomial in\n  Example~\\ref{exa:characterize-positive}: it is $-\\eigenvar^3 +\n  11\\eigenvar^2 - 30\\eigenvar$. The coefficients are $a_0=0$,\n  $a_1=-30$, $a_2=11$, and $a_3=-1$. Note that we have included all of\n  the coefficients, even ones that are zero. Since the signs are\n  weakly alternating, but not strongly alternating, the matrix is\n  positive semidefinite, but not positive definite.\n\\end{solution}\n\n\\begin{example}{Using Descartes' rule of signs to check if a matrix is positive definite}{descartes-rule-of-signs2}\n  Use Descartes' rule of signs to determine which of the following\n  matrices are positive definite and/or positive semidefinite.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      2 & 1 & 2 \\\\\n      1 & 1 & 0 \\\\\n      2 & 0 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{ccc}\n      2  &  1 & -2 \\\\\n      1  &  1 & -1 \\\\\n      -2 & -1 &  2 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{ccc}\n      2  & -1 & 2 \\\\\n      -1 &  2 & 0 \\\\\n      2  &  0 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomials are:\n  \\begin{equation*}\n    \\begin{array}{lcl}\n      \\det(A-\\eigenvar I) &=& -\\eigenvar^3 + 5\\eigenvar^2 - 3\\eigenvar - 2, \\\\\n      \\det(B-\\eigenvar I) &=& -\\eigenvar^3 + 5\\eigenvar^2 - 2\\eigenvar + 0, \\\\\n      \\det(C-\\eigenvar I) &=& -\\eigenvar^3 + 7\\eigenvar^2 - 11\\eigenvar + 1. \\\\\n    \\end{array}\n  \\end{equation*}\n  For $A$, the coefficients are not weakly alternating, so $A$ is not\n  positive semidefinite. For $B$, the coefficients are weakly, but not\n  strongly alternating (note that $a_0=0$), and therefore $B$ is\n  positive semidefinite, but not positive definite. For $C$, the\n  coefficients are strongly alternating, so $C$ is positive definite.\n\\end{solution}\n", "meta": {"hexsha": "77cff70b83ba0a47cefe42e48f18811a7f623fa8", "size": 16311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Positive.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/InnerProductSpaces-Positive.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/InnerProductSpaces-Positive.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 40.1748768473, "max_line_length": 115, "alphanum_fraction": 0.6618233094, "num_tokens": 5954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8740772450055545, "lm_q1q2_score": 0.7713101184266711}}
{"text": "\n\\subsection{Characteristic functions}\n\n\\subsubsection{Transformations}\n\n\\subsubsection{Summary}\n\nCumulative probability function\n\n\\(F=\\int_{-\\infty }^\\infty xP(x)\\)\n\nMoment generating function\n\n\\(F=\\int_{-\\infty }^\\infty e^{tx}P(x)\\)\n\nCharacteristic function\n\n\\(F=\\int_{-\\infty }^\\infty e^{itx}P(x)\\)\n\n\\subsubsection{Moment generating function}\n\nTake random variable \\(X\\). This has moments we wish to calculate.\n\nWe can transform our function in other forms which maintain all of the required information. For example we could also use the cumulative probability function to calculate moments. We now look for an alternative form of the probability density function which allows us to easily calculate moments.\n\nOne method is to use the probability density function and the definitions of moments, but there are other options. For example, consider the function:\n\n\\(E[e^{tX}]\\)\n\nWhich expands to:\n\n\\(E[e^{tX}]=\\sum_{j=1}^\\infty \\dfrac{t^jE[X^j]}{j!}\\)\n\nBy taking the \\(m\\)th derivative of this, we get\n\n\\(E[X^m]+\\sum_{j=m+1}^\\infty \\dfrac{t^jE[X^j]}{j!}\\)\n\nWe can then set \\(t=0\\) to get\n\n\\(E[X^m]\\)\n\nAlternatively, see that differentiating \\(m\\) times gets us\n\n\\(E[X^me^{tX}]\\)\n\nIf we can get this function, we can then easily generate moments.\n\nThe function we need to get is:\n\n\\(E[e^{tX}]\\)\n\nIn the discrete case this is:\n\n\\(E[e^{tX}]=\\sum_{i=1}e^{tx_i}p_i\\)\n\nIn the continuous case:\n\n\\(E[e^{tX}]=\\int_{-\\infty }^\\infty e^{tx}P(x) dx\\)\n\n\\subsubsection{Characteristic function}\n\nIt may not be possible to calculate the integral for the moment generating function. We now look for an alternative formula with which we can generate the same moments.\n\nConsider\n\n\\(E[e^{itX}]\\)\n\nAs this can be broken down into sinusoidal functions it can more readily be integrated.\n\nThis expands to\n\n\\(E[e^{itX}]=\\sum_{j=1}^\\infty \\dfrac{i^jt^jE[X^j]}{j!}\\)\n\nBy taking the \\(m\\)th derivative we get.\n\n\\(E[X^m]i^m+\\sum_{j=m+1}^\\infty \\dfrac{t^jE[X^j]}{j!}\\)\n\nBy setting \\(t=0\\) we then get:\n\n\\(E[X^m]i^m\\)\n\nAlternatively see that differentiating \\(m\\) times gets us\n\n\\(E[(iX)^me^{itX}]\\)\n\nSo we can get the moment by differentiating \\(m\\) times, and multiplying by \\(i^{-m}\\).\n\n\\subsubsection{Inverses of these functions}\n\nMoment generating function\n\nCharacteristic function\n\n\\subsubsection{Moments of constants added to variables}\n\n\\(\\phi_{X+c}(t)=E[e^{it(X+c)}]\\)\n\n\\(\\phi_{X+c}(t)=E[e^{itX}e^itc]\\)\n\n\\(\\phi_{X+c}(t)=e^{itc}E[e^{itX}]\\)\n\n\\(\\phi_{X+c}(t)=e^{itc}\\phi_X(t)\\)\n\n\\(\\phi_{X}(t)=e^{-itc}\\phi_{X+c}(t)\\)\n\n\\subsubsection{Moments of constants multiplied by events}\n\n\\(\\phi_{cX}(t)=E[e^{itcX}]\\)\n\n\\(\\phi_{cX}(t) = \\phi_{X}(ct)\\)\n\n\\subsubsection{Taylor series of a characteristic function}\n\n\\(\\phi_X(t)=E[e^{itX}]\\)\n\n\\(\\phi_X(t)=\\sum_{j=0}^{\\infty }\\dfrac{\\phi_X^j(a)(t-a)}{j!}\\)\n\nAround \\(a=0\\)\n\n\\(\\phi_X(t)=\\sum_{j=0}^{\\infty }\\dfrac{\\phi_X^j(0)(t)}{j!}\\)\n\nThe characteristic function is now given in terms of its moments.\n\nWe know:\n\n\\(\\phi_X^j(0)=E[X^j]i^j\\)\n\nSo:\n\n\\(\\phi_X(t)=\\sum_{j=0}^{\\infty }\\dfrac{E[X^j]i^j(t)^j}{j!}\\)\n\n\\(\\phi_X(t)=\\sum_{j=0}^{\\infty }\\dfrac{E[X^j](it)^j}{j!}\\)\n\nWe know:\n\n\\(\\dfrac{E[X^0](it)^0}{0!}=E[1]=1\\)\n\n\\(\\dfrac{E[X^1](it)^1}{1!}=E[X](it)=it\\mu_X \\)\n\n\\(\\dfrac{E[X^2](it)^2}{2!}=\\dfrac{-E[X^2]t^2}{2}=\\dfrac{-(\\mu_X +\\sigma_X^2 )t^2}{2}\\)\n\nSo:\n\n\\(\\phi_X(t)=1+it\\mu_X -\\dfrac{(\\mu_X +\\sigma_X^2 )t^2}{2} +\\sum_{j=3}^{\\infty }\\dfrac{E[X^j](it)^j}{j!}\\)\n\n", "meta": {"hexsha": "5b021b8674469deb5e416cb53f70e805f8690e28", "size": 3374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityMomentsCharacteristic/01-01-singleMomentCharacteristic.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/probabilityMomentsCharacteristic/01-01-singleMomentCharacteristic.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/probabilityMomentsCharacteristic/01-01-singleMomentCharacteristic.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.1095890411, "max_line_length": 297, "alphanum_fraction": 0.6547125074, "num_tokens": 1209, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772318846387, "lm_q2_score": 0.8824278788223264, "lm_q1q2_score": 0.7713101176588525}}
{"text": "\\section{Derive Fourier series}\n\nThough it was originally invented to solve the \\textbf{heat equation}, this\nseries has multiple uses: evaluating $\\zeta(s)$\\footnote{Examples are found in\nother sections of this collection}, extracting frequences from a wave, and\nrepresenting periodic functions by trigonomic functions. To derive Fourier\nseries, I start with representing functions by sines.\n\n\\begin{equation}\n\tf(t)=A_0+\\sum_{n=1}^\\infty A_n\\sin({2\\pi nt\\over T}+\\phi_n)\n\t\\label{fourier-orig}\n\\end{equation}\n\nIn equation (\\ref{fourier-orig}), $t$ is the independent variable, and $A_n$ is\nthe amplitude of cosine wave with period of $T$. $\\phi_n$ denotes the phase of\neach wave. Before performing any transformations, these formulas are used:\n\n\\begin{equation}\n\t\\sin(\\alpha+\\beta)=\\sin\\alpha\\cos\\beta+\\sin\\beta\\cos\\alpha\n\t\\label{sin-angle-sum}\n\\end{equation}\n\\begin{equation}\n\t\\cos\\theta=\\Re(e^{i\\theta})={e^{i\\theta}+e^{-i\\theta}\\over2}\n\t\\label{euler-cos}\n\\end{equation}\n\\begin{equation}\n\t\\sin\\theta={e^{i\\theta}-e^{-i\\theta}\\over2i}\n\t=-i\\cdot{e^{i\\theta}-e^{-i\\theta}\\over2}\n\t\\label{euler-sin}\n\\end{equation}\n\nFor equation (\\ref{euler-cos}) and (\\ref{euler-sin}), section\n\\ref{eulers-formula-derivation} can be referred. To simplify the formula, we\ncan apply the rule in equation (\\ref{sin-angle-sum}) to (\\ref{fourier-orig}).\n\n\\begin{equation}\n\tf(t)=A_0+\\sum_{n=1}^\\infty\\left[A_n\\sin\\left(2\\pi nt\\over T\\right)\n\t\\cos\\phi_n+\\sin\\phi_n\\cos\\left(2\\pi nt\\over T\\right)\\right]\n\t\\label{fourier-angle-sum}\n\\end{equation}\n\\begin{equation}\n\ta_n\\triangleq A_n\\sin\\phi_n, b_n\\triangleq A_n\\cos\\phi_n\n\t\\label{fourier-subst}\n\\end{equation}\n\nIf we were to apply the substitution in (\\ref{fourier-subst}) to equation\n(\\ref{fourier-angle-sum}) can be tidier, and solving for $a_n$ and $b_n$ is a\nmuch simpler problem.\n\n\\begin{equation}\n\tf(t)=A_0+\\sum_{n=1}^\\infty\\left[a_n\\cos\\left(2\\pi nt\\over T\\right)\n\t+b_n\\sin\\left(2\\pi nt\\over T\\right)\\right]\n\t\\label{fourier-real}\n\\end{equation}\n\nThough it is possible, solving for two variables is still a tough problem;\nhowever, when we complexify the function using the rule (\\ref{euler-cos}) and\n(\\ref{euler-sin}), it can be turned into a one-variable problem.\n\n$$\n\\begin{aligned}\n\tf(t)\n\t&=A_0+\\sum_{n=1}^\\infty\\left(\n\ta_n\\cdot{e^{2\\pi int\\over T}+e^{-{2\\pi int\\over T}}\\over2}\n\t-ib_n\\cdot{e^{2\\pi int\\over T}-e^{-{2\\pi int\\over T}}\\over 2}\\right) \\\\\n\t&=A_0+\\sum_{n=1}^\\infty\\left[\n\t\\left(a_n-ib_n\\over 2\\right)e^{2\\pi int\\over T}\n\t+\\left(a_n+ib_n\\over 2\\right)e^{-{2\\pi int\\over T}}\n\t\\right]\n\\end{aligned}\n$$\n\n\\begin{equation}\n\tc_n=\n\t\\begin{cases}\n\t\tA_0 & n=0 \\\\\n\t\t(a_n-ib_n)/2 & n>0 \\\\\n\t\t(a_{-n}+ib_{-n})/2 & n<0\n\t\\end{cases}\n\t\\label{complexify}\n\\end{equation}\n\nNow, substituting $A_0$, $a_n$, and $b_n$ with $c_n$ according to\n(\\ref{complexify}) is the most brilliant step. The whole function becomes\nexpressed as follows:\n\n\\begin{equation}\n\tf(t)=\\sum_{n=0}^\\infty c_ne^{2\\pi int\\over T}\n\t+\\sum_{n=1}^\\infty c_{-n}e^{-{2\\pi int\\over T}}\n\t=\\sum_{n=-\\infty}^\\infty c_ne^{2\\pi int\\over T}\n\t\\label{fourier-complex}\n\\end{equation}\n\nBy integrating $f(t)$ over one of its period, we find the exact value of each\n$c_n$.\n\n$$\n\\int_{t_0}^{t_0+T}f(t)e^{-{2\\pi ikt\\over T}}dt\n=\\int_{t_0}^{t_0+T}\\sum_{n=-\\infty}^\\infty c_ne^{2\\pi i(n-k)t\\over T}\n=\\sum_{n=-\\infty}^\\infty c_n\\int_{t_0}^{t_0+T}e^{2\\pi i(n-k)t\\over T}\n$$\n\nWe presume that $k\\in\\mathbb{Z}$, and the integral of each element in the\nseries produces different results. For the element where $k=n$, the result\nconforms to equation (\\ref{eq-k-case}). Otherwise the calculation follows\n(\\ref{neq-k-case}).\n\n\\begin{equation}\n\tc_k\\int_{t_0}^{t_0+T}dt=c_k(t_0+T-t_0)=c_kT\n\t\\label{eq-k-case}\n\\end{equation}\n\\begin{equation}\n\t\\begin{aligned}\n\t\tc_n\\int_{t_0}^{t_0+T}e^{2\\pi i(n-k)t\\over T}dt\n\t\t&=c_n\\left[Te^{2\\pi i(n-k)t\\over T}\\over2\\pi i(n-k)\\right]\n\t\t^{t_0+T} \\\\\n\t\t&={c_nT\\over2\\pi i(n-k)}\\cdot e^{2\\pi i(n-k)t_0\\over T}\n\t\t(e^{2\\pi i(n-k)}-1)=0\n\t\\end{aligned}\n\t\\label{neq-k-case}\n\\end{equation}\n\nAs a result, $c_n$ is calculated via:\n\n\\begin{equation}\n\tc_n={1\\over T}\\int_{t_0}^{t_0+T}f(t)e^{-{2\\pi int\\over T}}dt\n\t\\label{eval-cn}\n\\end{equation}\n\nAccording to the substitution scheme in (\\ref{complexify}), we obtain $a_n$ and\n$b_n$ via:\n\n\\begin{equation}\n\ta_n=c_n+c_{-n}={2\\over T}\\int_{t_0}^{t_0+T}f(t)\n\t\\left(e^{-{2\\pi int\\over T}}+e^{2\\pi int\\over T}\\over 2\\right)dt\n\t={2\\over T}\\int_{t_0}^{t_0+T}f(t)\\cos\\left(2\\pi nt\\over T\\right)dt\n\t\\label{eval-an}\n\\end{equation}\n\\begin{equation}\n\tb_n={c_{-n}-c_n\\over i}={2\\over T}\\int_{t_0}^{t_0+T}f(t)\n\t\\left(e^{2\\pi int\\over T}-e^{-{2\\pi int\\over T}}\\over2i\\right)dt\n\t={2\\over T}\\int_{t_0}^{t_0+T}f(t)\\sin\\left(2\\pi nt\\over T\\right)dt\n\t\\label{eval-bn}\n\\end{equation}\n\nAccording to (\\ref{complexify}) and (\\ref{eval-cn}), $A_0$ is calculated by:\n\n$$\nA_0={1\\over L}\\int_{t_0}^{t_0+T}f(t)dt\n={1\\over2}\\cdot{2\\over L}\\int_{t_0}^{t_0+T}f(t)\n\\cos\\left(2\\pi(0)t\\over T\\right)dt\n={a_0\\over2}\n$$\n\nTherefore, we can set $A_0$ to half of $a_0$, so the (\\ref{fourier-real}) can\nbe transformed into the following where $a_n$ and $b_n$ are computed by\n(\\ref{eval-an}) and (\\ref{eval-bn}), respectively.\n\n$$\nf(t)={a_0\\over2}+\\sum_{n=1}^\\infty\\left[a_n\\cos\\left({2\\pi nt\\over T}\\right)\n+b_n\\sin\\left({2\\pi nt\\over T}\\right)\\right]\n$$\n", "meta": {"hexsha": "a2ffd5cf196463225b5e247a537f011488e3273a", "size": 5239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "fourier-derivation.tex", "max_stars_repo_name": "TravorLZH/mathcol-doc", "max_stars_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-01-17T04:58:27.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-17T04:58:27.000Z", "max_issues_repo_path": "fourier-derivation.tex", "max_issues_repo_name": "TravorLZH/mathcol-doc", "max_issues_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fourier-derivation.tex", "max_forks_repo_name": "TravorLZH/mathcol-doc", "max_forks_repo_head_hexsha": "7800a3056657691e9cf81687309cb8ffd1a44887", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-11-07T07:20:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-07T07:20:36.000Z", "avg_line_length": 32.1411042945, "max_line_length": 79, "alphanum_fraction": 0.6800916205, "num_tokens": 2119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625321, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.7713100983566669}}
{"text": "\\section{Vector Functions for Surfaces}\\label{sec:VectorFunctionSurfaces}\n\nWe have dealt extensively with vector equations for curves, \n$\\vect{r}(t)=\\langle x(t),y(t),z(t)\\rangle$. A similar technique\ncan be used to represent surfaces in a way that is more general than\nthe equations for surfaces we have used so far. Recall that\nwhen we use $\\vect{r}(t)$ to represent a curve, we imagine the vector \n$\\vect{r}(t)$ with its tail at the origin, and then we follow the head\nof the arrow as $t$ changes. The vector ``draws'' the curve through\nspace as $t$ varies.\n\nSuppose we instead have a vector function of two variables,\n$$\\vect{r}(u,v)=\\langle x(u,v),y(u,v),z(u,v)\\rangle.$$\nAs both $u$ and\n$v$ vary, we again imagine the vector $\\vect{r}(u,v)$ with its tail at\nthe origin, and its head sweeps out a surface in space. A useful\nanalogy is the technology of CRT video screens, in which an electron\ngun fires electrons in the direction of the screen. The gun's\ndirection sweeps horizontally and vertically to ``paint'' the screen\nwith the desired image. In practice, the gun moves horizontally\nthrough an entire line, then moves vertically to the next line and\nrepeats the operation. In the same way, it can be useful to imagine\nfixing a value of $v$ and letting $\\vect{r}(u,v)$ sweep out a curve as\n$u$ changes. Then $v$ can change a bit, and $\\vect{r}(u,v)$ sweeps out\na new curve very close to the first. Put enough of these curves\ntogether and they form a surface.\n\n\\begin{example}{}{}\nConsider the function $\\vect{r}(u,v)=\\langle v\\cos u,v\\sin u,\nv\\rangle$. For a fixed value of $v$, as $u$ varies from 0 to $2\\pi$,\nthis traces a circle of radius $v$ at height $v$ above the\n$x$-$y$ plane. Put lots and lots of these together,and they form a\ncone, as in Figure~\\ref{fig:parametric cone}.\n\\end{example}\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{\\epsfxsize6cm\\epsfbox{images/cone_level_curves.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/parametric_cone.eps}}} at 2.5 0\n\\endpicture}}\n\\caption{Tracing a surface. \\label{fig:parametric cone}}\n\\end{figure}\n\n\nRecall that from the vector equation of the curve we can compute the\nunit tangent $\\vect{T}$, the unit normal $\\vect{N}$, and the \nbinormal vector $\\vect{B}=\\vect{T}\\times\\vect{N}$; you may\nwant to review Section~\\ref{sec:arc length 3D}. The binormal is\nperpendicular to both $\\vect{T}$ and $\\vect{N}$; one way to interpret this\nis that $\\vect{N}$ and $\\vect{B}$ define a plane perpendicular to $\\vect{T}$, that is, perpendicular to the curve; since $\\vect{N}$ and $\\vect{B}$\nare perpendicular to each other, they can function just as $\\vect{i}$ and\n$\\vect{j}$ do for the $x$-$y$ plane.\n\n\\begin{example}{}{}\nThe curve given by \n$$\\vect{r}=\\langle (2+\\cos(3u/2))\\cos u,\n(2+\\cos(3u/2))\\sin u, \\sin(3u/2)\\rangle$$\n is called a trefoil knot.\nThen $\\vect{c}(v)=\\vect{N}\\cos v+\\vect{B}\\sin v$ is a vector equation for a unit circle in a plane\nperpendicular to the curve described by $\\vect{r}$, except that the usual\ninterpretation of $\\vect{c}$ would put its center at the origin. We can\nfix that simply by adding $\\vect{c}$ to the original $\\vect{r}$:\nlet $\\vect{f}=\\vect{r}(u) +\\vect{c}(v)$. For a\nfixed $u$ this draws a circle around the point $\\vect{r}(u)$; as $u$\nvaries we get a sequence of such circles around the curve $\\vect{r}$,\nthat is, a tube of radius 1 with $\\vect{r}$ at its center. We can easily\nchange the radius; for example $\\vect{r}(u) +a\\vect{c}(v)$\ngives the tube radius $a$; we can make the radius vary as we\nmove along the curve with $\\vect{r}(u) +g(u)\\vect{c}(v)$,\nwhere $g(u)$ is a function of $u$. \n\\end{example}\n\nAs shown in\nFigure~\\ref{fig:trefoil}, it is hard to see that the plain knot is\nknotted; the tube makes the structure apparent. Of course, there is\nnothing special about the trefoil knot in this example; we can put a\ntube around (almost) any curve in the same way.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <2.5truecm,2.5truecm>\n\\setplotarea x from -1 to 1, y from 0 to 1\n\\put {\\hbox{\\epsfxsize4.17cm\\epsfbox{images/trefoil.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/trefoil_tube.eps}}} at 2.5 0\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/trefoil_sausage.eps}}} at 5 0\n\\endpicture}}\n\\caption{Tubes around a trefoil knot, with radius $1/2$ and $3\\cos(u)/4$. \\label{fig:trefoil}}\n\\end{figure}\n\nWe have previously examined surfaces given in the form \n$f(x,y)$. It is sometimes useful to represent such surfaces in the\nmore general vector form, which is quite easy:\n$\\vect{r}(u,v)=\\langle u,v,f(u,v)\\rangle$. The names of the variables\nare not important of course; instead of disguising $x$ and $y$, we\ncould simply write $\\vect{r}(x,y)=\\langle x,y,f(x,y)\\rangle$. \n\nWe have also previously dealt with surfaces that are not functions of\n$x$ and $y$; many of these are easy to represent in vector form.\nOne common type of surface that cannot be represented as $z=f(x,y)$ is\na surface given by an equation involving only $x$ and $y$. For\nexample,\n$x+y=1$ and $y=x^2$ are ``vertical'' surfaces. For every point $(x,y)$\nin the plane that satisfies the equation, the point $(x,y,z)$ is on\nthe surface, for \nevery value of $z$. Thus, a corresponding vector form for the surface\nis something like $\\langle f(u),g(u),v\\rangle$; for example, $x+y=1$\nbecomes $\\langle u,1-u,v\\rangle$ and $y=x^2$ becomes $\\langle\nu,u^2,v\\rangle$. \n\nYet another sort of example is the sphere, say $x^2+y^2+z^2=1$. This\ncannot be written in the form $z=f(x,y)$, but it is easy to write in\nvector form; indeed this particular surface is much like the cone,\nsince it has circular cross-sections, or we can think of it as a tube\naround a portion of the $z$-axis, with a radius that varies depending\non where along the axis we are. One vector expression for the sphere\nis $\\langle \\sqrt{1-v^2}\\cos u,\\sqrt{1-v^2}\\sin u, v\\rangle$---this\nemphasizes the tube structure, as it is naturally viewed as drawing a\ncircle of radius $\\sqrt{1-v^2}$ around the $z$-axis at height $v$.\nWe could also take a cue from spherical coordinates, and write\n$\\langle \\sin u\\cos v,\\sin u\\sin v,\\cos u\\rangle$, where in effect\n$u$ and $v$ are $\\phi$ and $\\theta$ in disguise. \n\nIt is quite simple to use a computer program to plot any surface for which you have a\nvector representation. Using different vector functions sometimes\ngives different looking plots, because the computer in effect draws the\nsurface by holding one variable constant and then the other. \n\nHere's a simple but striking example: the plane $x+y+z=1$ can be\nrepresented quite naturally as $\\langle u,v,1-u-v\\rangle$. However we\ncould also think of painting the same plane by choosing a particular\npoint on the plane, say $(1,0,0)$, and then drawing circles or\nellipses (or any of a number of other curves) as if that point were\nthe origin in the plane. For example, $\\langle 1-v\\cos u-v\\sin u,v\\sin\nu,v\\cos u\\rangle$ is one such vector function. Note that while it may\nnot be obvious where this came from, it is quite easy to see that\nthe sum of the $x$, $y$, and $z$ components of the vector is always\n1. Computer renderings of the plane using these two functions are shown\nin Figure~\\ref{fig:two plane parameterizations}.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\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/plane1.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/plane2.eps}}} at 3 0\n\\endpicture}}\n\\caption{Two representations of the same plane. \\label{fig:two plane parameterizations}}\n\\end{figure}\n\nSuppose we know that a plane contains a particular point\n$(x_0,y_0,z_0)$ and that two vectors $\\vect{u}=\\langle\nu_0,u_1,u_2\\rangle$ and $\\vect{v}=\\langle\nv_0,v_1,v_2\\rangle$ are parallel to the plane but not to each\nother. We know how to get an equation for the plane in the form\n$ax+by+cz=d$, by first computing $\\vect{u}\\times\\vect{v}$. It's even\neasier to get a vector equation:\n$$\\vect{r}(u,v) = \\langle x_0,y_0,z_0\\rangle + u\\vect{u} + v\\vect{v}.$$\nThe first vector gets to the point $(x_0,y_0,z_0)$ and then by varying\n$u$ and $v$, $u\\vect{u} + v\\vect{v}$ gets to every point in the plane.\n\nReturning to $x+y+z=1$, the points $(1,0,0)$, $(0,1,0)$, and $(0,0,1)$\nare all on the plane. By subtracting coordinates we see that\n$\\langle -1,0,1\\rangle$ and $\\langle -1,1,0\\rangle$ are parallel to\nthe plane, so a third vector form for this plane is\n$$\\langle 1,0,0\\rangle + u\\langle -1,0,1\\rangle + v\\langle\n-1,1,0\\rangle\n= \\langle 1-u-v,v,u\\rangle.$$\nThis is clearly quite similar to the first form we found.\n\nWe have already seen (Section~\\ref{sec:surfacearea3D})\nhow to find the area of a surface when it is\ndefined in the form $f(x,y)$. Finding the area when the surface is\ngiven as a vector function is very similar. Looking at the plots of\nsurfaces we have just seen, it is evident that the two sets of curves\nthat fill out the surface divide it into a grid, and that the spaces\nin the grid are approximately parallelograms. As before this is the\nkey: we can write down the area of a typical small parallelogram and\nadd them all up with an integral.\n\nSuppose we want to approximate the area of the surface $\\vect{r}(u,v)$\nnear $\\vect{r}(u_0,v_0)$. The functions $\\vect{r}(u,v_0)$ and $\\vect{r}(u_0,v)$ define two curves that intersect at $\\vect{r}(u_0,v_0)$. The derivatives of $\\vect{r}$ give us vectors tangent to\nthese two curves: $\\vect{r}_u(u_0,v_0)$ and $\\vect{r}_v(u_0,v_0)$, and\nthen $\\vect{r}_u(u_0,v_0)\\,du$ and $\\vect{r}_v(u_0,v_0)\\,dv$\nare two small tangent vectors, whose lengths can be used as the\nlengths of the sides of an approximating parallelogram. Finally, the\narea of this parallelogram is $|\\vect{r}_u\\times\\vect{r}_v|\\,du\\,dv$ and\nso the total surface area is\n\\begin{equation} \\label{eq:surfaceareaintegral}\n\\int_a^b\\int_c^d |\\vect{r}_u\\times\\vect{r}_v|\\,du\\,dv\n\\end{equation}\n\n\\begin{example}{}{surfacearea}\nFind the area of the surface $\\langle v\\cos u,v\\sin\nu,v\\rangle$ for $0\\le u \\le 2\\pi$ and  $0\\le v\\le \\frac{1}{2}$.\n\\end{example}\n\n\\begin{solution}\nWe compute $\\vect{r}_u = \\langle -v\\sin u,v\\cos u,0\\rangle$\nand $\\vect{r}_v = \\langle \\cos u,\\sin u,1\\rangle$.\nThe cross product of these two vectors is $\\langle v \\cos u,v\\sin\nu,-v\\rangle$ with length $\\sqrt{2v^2}=\\sqrt{2}v$, and the surface area is\n$$\\int_0^\\pi\\int_0^1 \\sqrt{2}v\\,dv\\,du=\\frac{\\sqrt{2}\\pi}{4}.$$\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:VectorFunctionSurfaces}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex} \\label{exfix3}\nDescribe or sketch the surface with the given vector function.\n\\begin{enumerate}\n  \\item\t$\\vect{r}(u,v) = \\langle 6v-u,3+v,1-4v \\rangle$\n  \\item\t$\\vect{r}(u,v) = \\langle 2\\cos u, 5\\cos u, v \\rangle$ \n  \\item\t$\\vect{r}(s,t) = \\langle u+v,2u+v,u^2+v^2\\rangle$\n  \\item\t$\\vect{r}(s,t) = \\langle \\sin u + \\cos u, u, v \\rangle$\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the portion of $x+2y+4z=10$ in the first octant.\n\\begin{sol}\n\t$25\\sqrt{21}/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the portion of $2x+4y+z=0$ inside $x^2+y^2=1$.\n\\begin{sol}\n\t$\\pi\\sqrt{21}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of $z=x^2+y^2$ that lies below $z=1$.\n\\begin{sol}\n\t$\\pi(5\\sqrt5-1)/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of $z=\\sqrt{x^2+y^2}$ that lies below $z=2$.\n\\begin{sol}\n\t$4\\pi\\sqrt2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the portion of $x^2+y^2+z^2=a^2$ that lies\nin the first octant.\n\\begin{sol}\n\t$\\pi a^2/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the portion of $x^2+y^2+z^2=a^2$ that lies\nabove $x^2+y^2\\le b^2$.\n\\begin{sol}\n\t$2\\pi a(a-\\sqrt{a^2-b^2})$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of $z=x^2-y^2$ that lies inside $x^2+y^2=a^2$.\n\\begin{sol}\n\t$\\pi((1+4a^2)^{3/2}-1)/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of $x^2+y^2+z^2=a^2$ \nthat lies above the interior of the circle given in polar coordinates\nby $r=a\\cos \\theta$.\n\\begin{sol}\n\t$\\pi a^2-2a^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the cone $z=k\\sqrt{x^2+y^2}$\nthat lies above the interior of the circle given in polar coordinates\nby $r=a\\cos \\theta$.\n\\begin{sol}\n\t$\\pi a^2\\sqrt{1+k^2}/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the plane $z=ax+by+c$ that lies over a\nregion $D$ with area $A$.\n\\begin{sol}\n\t$A\\sqrt{1+a^2+b^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the cone $z=k\\sqrt{x^2+y^2}$ that lies over a\nregion $D$ with area $A$.\n\\begin{sol}\n\t$A\\sqrt{k^2+1}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area of the cylinder $x^2+z^2=a^2$ that lies inside\nthe cylinder $x^2+y^2=a^2$.\n\\begin{sol}\n\t$8a^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe surface $f(x,y)$ can be represented with the vector\nfunction $\\langle x,y,f(x,y)\\rangle$. Set up the surface area integral using\nthis vector function and compare to the integral of\nSection~\\ref{sec:surfacearea3D}. \n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "1d46a59b303760ee26d709b97468b2f85c8f7cc1", "size": 13078, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-6-vector-function-surfaces.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-6-vector-function-surfaces.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-6-vector-function-surfaces.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.5105740181, "max_line_length": 193, "alphanum_fraction": 0.7068359076, "num_tokens": 4371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.918480252950991, "lm_q1q2_score": 0.7712790670391376}}
{"text": "\\lab{Algorithms}{Introduction to Wavelets}{Intro to Wavelets}\n\n\\objective{This section explains the basic ideas of Wavelet Analysis\nusing the Haar wavelet as a prototypical example.}\n\nRecall that in the context of Fourier analysis, one seeks to represent a\nfunction in the frequency domain, and this is accomplished via the Fourier\ntransform. The Fourier transform allows us to analyze and process functions\nin many useful ways, as you have seen in previous labs. There are, however,\ndrawbacks to this approach. For example, although a function's Fourier\ntransform gives us complete information on its frequency spectrum, time\ninformation is lost. We can know which frequencies are the\nmost prevalent, but not when they occur. This is due in part to the fact that\nthe sinusoidal function $f(x) = e^{2\\pi ix}$ -- on which the Fourier transform\nis based -- has infinite support. Its nature is essentially \\emph{non-local},\nand so the Fourier transform fails to provide local information in both the\ntime and frequency domains. This brings us to the following question: are\nthere types of transforms that avoid the shortcomings mentioned above? The\nanswer is an emphatic yes. Enter Wavelet analysis.\n\n\\section*{The Haar Wavelet}\n\nAs noted earlier, the Fourier transform is based on the complex exponential\nfunction. Let us alter the situation and consider instead the following\nfunction, known as the \\emph{Haar wavelet}:\n\\begin{equation*}\n\\psi(x) =\n \\begin{cases}\n  1 & \\text{if } 0 \\leq x < \\frac{1}{2} \\\\\n  -1 & \\text{if } \\frac{1}{2} \\leq x < 1 \\\\\n  0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\n% It might be nice to plot this function and include the image in the lab.\n\nAlong with this wavelet, we introduce the associated \\emph{scaling function}:\n\\begin{equation*}\n\\phi(x) =\n \\begin{cases}\n 1 & \\text{if } 0 \\leq x < 1 \\\\\n 0 & \\text{otherwise.}\n \\end{cases}\n\\end{equation*}\n\nFrom the wavelet and scaling function, we can generate two countable families\nof dyadic dilates and translates given by\n\\begin{equation*}\n\\psi_{m,k}(x) = \\psi(2^mx - k)\n\\end{equation*}\n\\begin{equation*}\n\\phi_{m,k}(x) = \\phi(2^mx - k),\n\\end{equation*}\nwhere $m,k \\in \\mathbb{Z}$.\n\nLet us focus for the moment on that second family of functions, $\\{\\phi_{m,k}\\}$.\nIf we fix $m$ and let $k$ vary over the integers, we have a countable collection of\nsimple functions. The support of a typical function $\\phi_{m,k}$ is the interval\n$[k2^{-m}, (k+1)2^{-m}]$, and for any $m \\in \\mathbb{Z}$ we have\n\\begin{equation*}\n\\mathbb{R} = \\displaystyle\\biguplus_k\\,[k2^{-m}, (k+1)2^{-m}],\n\\end{equation*}\nwhere $\\uplus$ denotes a union over disjoint sets. Thus, the supports can be viewed as\na discretization of the real line, and we can use this collection of simple functions\nto approximate any $f \\in L^2(\\mathbb{R})$ in the following sense:\n\\begin{equation*}\nf(x) \\approx f_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\alpha_{m,k}\\phi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\alpha_{m,k} := 2^m \\displaystyle \\int_{k2^{-m}}^{(k+1)2^{-m}}f(x) dx\n\\end{equation*}\n($\\alpha_{m,k}$ is simply the average value of $f$ on $[k2^{-m},(k+1)2^{-m}]$). As you\nwould probably expect, the point-wise error between $f$ and its approximation $f_m$\n(called a \\emph{frame}) goes to zero as $m \\to \\infty$.\n\nThese frames are not quite good enough, however. Each coefficient $\\alpha_{m,k}$\ncertainly captures local information about $f$ -- namely its average value on\na certain interval -- but it fails to tell us anything about how $f$ changes\non that interval. We need more information than is provided by $f_m$ in order\nto know about discontinuities or high-frequency oscillations of $f$. To this end,\nwe now consider the wavelet function $\\psi$.\nNotice that the Haar wavelet is oscillatory in nature, and is thus better suited\nto capture local information on how a function changes at a given point. For\nany given $m$, we define a function $d_m$, called a \\emph{detail}, as follows:\n\\begin{equation*}\nd_m(x) := \\displaystyle\\sum_{k \\in \\mathbb{Z}}\\beta_{m,k}\\psi_{m,k}(x),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\beta_{m,k} := 2^m \\displaystyle \\int_{-\\infty}^{\\infty}f(x) \\psi_{m,k}(x) dx.\n\\end{equation*}\nEach coefficient $\\beta_{m,k}$ gives information about how $f$ changes on the\nthe interval $[k2^{-m}, (k+1)2^{-m}]$, and larger coefficients correspond\nto larger spikes of width $2^{-m}$. Thus, as $m$ increases, the\ndetail function $d_m$ gives information about the higher-frequency oscillations\nof the function. The details and approximation frames interact in the following way:\n\\begin{equation*}\nf_{m+1} = f_m + d_m.\n\\end{equation*}\nAs a result of this fortuitous relationship, one can prove the decomposition\n\\begin{equation*}\nL^2(R) = V_0 \\oplus W_0 \\oplus W_1 \\oplus \\cdots,\n\\end{equation*}\nwhere $V_j := \\text{span}\\{\\phi_{j,k}\\}_{k \\in \\mathbb{Z}}$ and\n$W_j := \\text{span}\\{\\psi_{j,k}\\}_{k \\in \\mathbb{Z}}$. This fact justifies\nour hope to approximate and analyze functions using wavelets.\n\\begin{figure}[t]\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sinecurve}\n    \\caption{$f(x) = \\sin (x)$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{discreteSineCurve.pdf}\n    \\caption{$f_4$}\n\\endminipage\\hfill\n\\minipage{0.32\\textwidth}\n    \\includegraphics[width=\\linewidth]{sineCurveDetail}\n    \\caption{$d_4$}\n\\endminipage\n\\end{figure}\n\\begin{problem}\nCalculate and plot the approximation frames for $f(x) = \\sin(x)$ on the interval $[0,2\\pi]$\nfor $m = 4, 6, 8$. Note that because we are working on a finite interval,\nwe only need to calculate certain coefficients $\\alpha_{m,k}$. In\nparticular, we only need the coefficients for $k = 0$ up to the first integer\n$n$ such that $(n+1)2^{-m} > 2 \\pi$ (why?). Furthermore, to plot the frame,\nall we need is an array containing the relevant coefficients. Then simply plot\nthe coefficients against \\li{linspace} with appropriate arguments\nand set \\li{drawstyle='steps'} in the \\li{plt.plot} function.\n\\end{problem}\n\n\\begin{problem}\nNow calculate the details for $f(x) = \\sin(x)$ on the same interval and for the\nsame $m$ values given above. Use previous results to compute the coefficients\nfor $f_5$, $f_7$, and $f_9$ and plot them.\n\\end{problem}\n\n\\section*{The Discrete Wavelet Transform}\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.\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-\npass filter 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\\begin{figure}[H]\n\\centering\n\\includegraphics[width = 0.5\\textwidth]{dwt1}\n\\caption{The one-dimensional discrete wavelet transform.}\n\\end{figure}\nThe input, $A_j$, represents the level-$j$ approximation frame, and we initialize $A_0$ to\nsimply be the original signal. Lo and Hi are the low-pass and high-pass filters, respectively.\n(By \\emph{filter} we mean a vector that serves the purpose of extracting or suppressing a\nparticular feature of the signal. The Lo and Hi filters are obtained from the wavelet at hand;\nfor the Haar wavelet, Lo $= (\\sqrt{2}^{-1}, \\sqrt{2}^{-1})$ and Hi $= (-\\sqrt{2}^{-1}, \\sqrt{2}\n^{-1})$.) The box means convolve the input with the filter, and the circle means downsample by\na factor of two, i.e. remove either the even or odd-indexed entries of the input. The outputs,\n$A_{j+1}$ and $D_{j+1}$, are the level-$(j+1)$ approximation frame and detail coefficients,\nrespectively. Note that the length of the input array is twice that of the output arrays. The\ndetail coefficients $D_{j+1}$ are stored, and $A_{j+1}$ is then fed back into the loop. Continue\nthis process until the length of the output is less than the length of the filters, and\nreturn all of the stored detail coefficients as well as the final approximation frame.\n\\begin{problem}\nWrite a function that calculates the discrete wavelet transform as described above.\nThe inputs should be three one-dimensional NumPy arrays (the signal, low-pass filter, and\nhigh-pass filter). The output should be a list of one-dimensional NumPy arrays in the\nfollowing form: $[A_n, D_n, D_{n-1},\\ldots,D_1]$. (Note: for the convolution, you may use\nthe \\li{fftconvolve} function from the \\li{scipy.signal} package using the default\n\\li{mode = 'full'} parameter, but note that the output array is one entry too large, and so\nyou need to omit the first entry. For downsampling, only keep the even-indexed entries.)\n\\end{problem}\nWe also need to know how to reconstruct the signal from the detail coefficients and\napproximation frame. Fortunately, the algorithm described above is entirely reversible,\nalbeit with slightly different filters: Lo $= (\\sqrt{2}^{-1}, \\sqrt{2}^{-1})$ and\nHi $= (\\sqrt{2}^{-1}, -\\sqrt{2}^{-1})$.\nGiven $A_{j+1}$ and $D_{j+1}$, simply upsample both arrays (by inserting a zero after\neach entry of the original array), convolve the results\nwith the Lo and Hi filters, respectively (this time omit the \\emph{last} entry of the\nresult), and add the outputs to obtain $A_j$. Continue the\nprocess until you recover $A_0$, the original signal.\n\\begin{problem}\nWrite a function that calculates the inverse wavelet transform as described above.\nThe inputs should be a list of arrays (of the same form as the output of your discrete\nwavelet transform function), the low-pass filter, and the high-pass filter. The output\nshould be a single array, the recovered signal. In order to check your work, compute\nthe discrete wavelet transform of a random array of length 64, then compute the inverse\ntransform, and compare the original signal with the recovered signal. The difference\nshould be very small.\n\\end{problem}\n\n\\section*{More Wavelets}\nUp to this point, the only wavelet that we have considered is the Haar wavelet, \nwhich is the simplest and historically first example. Wavelet analysis is a broad \nfield, however, and there are myriad other wavelets that have been studied and \napplied. Your implementation of the discrete wavelet transform is quite general, \nand you will find that different types of signals or functions call for different \nwavelets. We will not go into detail here, but be aware that there is a large \nselection of wavelets out there. \n\n\\begin{figure}[H]\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{mexicanHat}\n    \\caption{The Mexican Hat Wavelet}\n\\endminipage\\hfill\n\\minipage{0.49\\textwidth}\n    \\includegraphics[width=\\linewidth]{db5_3}\n    \\caption{The Cohen-Daubechies-Feauveau 5/3 Wavelet}\n\\endminipage\n\\end{figure}", "meta": {"hexsha": "96792ece99613b2c8f4fb5b649ab056a15cc96ed", "size": 12460, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Haar/Haar.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/Haar/Haar.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/Haar/Haar.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.7966101695, "max_line_length": 97, "alphanum_fraction": 0.7501605136, "num_tokens": 3439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339556397749, "lm_q2_score": 0.9184802518352773, "lm_q1q2_score": 0.771279055050654}}
{"text": " \n \n\\section{Revision Protocols and Evolutionary Dynamics}\\label{sec:protocols}\n \n \nIn this section we introduce four revision protocols, that lead to the evolutionary dynamics \\emph{logit dynamics} (Logit), \\emph{replicator dynamics} (RD), \\emph{Brown-von Neumann-Nash dynamics} (BNN), and \\emph{Smith dynamics} (Smith). These dynamics belong to the families of \\emph{perturbed optimization}, \\emph{imitative dynamics}, \\emph{excess payoff dynamics}, and \\emph{pairwise comparison dynamics}, respectively \\cite{hofbauer2001nash, sandholm_book}. \n \n \n \n \n \n \n \\subsection{Pairwise Proportional Imitation (Replicator Dynamics)}\n\nWith a revision opportunity the $i\\th$ agent observes an opponent $j$ at random. Then it might change its strategy if  its opponent has a greater fitness. The rate change is \n%\n\\begin{equation}\n\\rho_{ij}^p(\\pi^p, x^p) = \\frac{1}{m^p} [\\pi_j^p - \\pi_i^p]_+,\n\\end{equation}\nwhere the $[\\cdot]_+:\\Re \\leftarrow \\Re_{\\geq0}$ represents the positive part, defined as $[ x ]_+ \\equiv \\max\\{ 0, x \\}$.\nThis protocol leads to the \\emph{replicator dynamics} defined as\n\\begin{equation}\\label{eq:replicator}\n\\dot{x}_i^p = x_i^p \\, \\hat{F}_i^p \\left( x \\right),\n\\end{equation}\nwhere $\\hat{F}_i^p$ is the excess payoff to strategy $i\\in S^p$, which is defined as   \n\\begin{equation}\n\\hat{F}_i^p (x) =  F_i^p(x) - \\bar{F}^p(x),\n\\end{equation}\nand $\\bar{F}^p(x)$ is the average payoff the population $p$, i.e., \n\\begin{equation}\n \\bar{F}^p(x) = \\frac{1}{m^p} \\sum_{j \\in S^p} x_j^p F_j^p(x).\n\\end{equation}\n\n\n\n\\subsubsection*{Algorithm}\n\n\\begin{algorithm}[H]\n\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\n \\Input{Society's state $x$}\n \\Output{State update $\\dot{x}$}\n \\BlankLine\n \n \\For{ $ p \\leftarrow 1 $ \\KwTo $P$ } {\n  $ F^p \\leftarrow fitness(x, p)$\\;\n  $ \\bar{F}^p \\leftarrow \\frac{1}{m^p} (F^p)^\\top x^p$\\;\n  $ \\hat{F}^p \\leftarrow F^p - \\boldsymbol{1} \\bar{F}^p$\\;\n  $ \\dot{x}^p \\leftarrow \\hat{F}^p \\odot x^p \\frac{1}{m^p} $\\; \n }\n\\end{algorithm}\n%\nThe running time of the algorithm is $T_{rd}(n, P) = O( P (  T_{f}(n,P) + n) ) $, where $T_{f}(n,P)$ is the time required to calculate the fitness vector of a population.\n\n\n\n\n\n\n\n\n\\subsection{Comparison to the Average Payoff (Brown-von Neumann-Nash Dynamics (BNN))}\n\nWith a revision opportunity the $i\\th$ agent selects a strategy at random and might switch to it if that strategy has a payoff above the average. The agent switch strategy with probability proportional to the excess payoff\n%\n\\begin{equation}\n\\rho_{ij}^p(\\pi^p, x^p) = \\left[ \\pi_j^p - \\frac{1}{m^p} \\sum_{k\\in S^p} x_k^p \\pi_k^p \\right]_+,\n\\end{equation}\n\nThis protocol leads to \\emph{Brown-von Neumann-Nash dynamics}, defined as \n\\begin{equation}\\label{eq:bnn}\n \\dot{x}_i^p = \\left[ \\hat{F}_i^p \\left( \\bs{x} \\right) \\right]_+ - x_i^p  \\sum_{j \\in S^p} \\left[ \\hat{F}_j^p \\left( \\bs{x} \\right) \\right]_+.\n\\end{equation}\n\n\n\n\\subsubsection*{Algorithm}\n\n\\begin{algorithm}[H]\n\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\n \\Input{Society's state $x$}\n \\Output{State update $\\dot{x}$}\n \\BlankLine\n \n \\For{ $ p \\leftarrow 1 $ \\KwTo $P$ } {\n  $ F^p \\leftarrow fitness(x, p)$\\;\n  $ \\bar{F}^p \\leftarrow \\frac{1}{m^p} (F^p)^\\top x^p$\\;\n  $ \\hat{F}^p \\leftarrow \\max\\{F^p - \\boldsymbol{1} \\bar{F}^p, \\boldsymbol{0}\\}$\\;\n  $ \\dot{x}^p \\leftarrow \\hat{F}^p - (\\boldsymbol{1}^\\top \\hat{F}^p) \\odot x^p \\frac{1}{m^p} $\\;\n }\n\\end{algorithm}\n%\nThe running time is $T_{BNN}(n,P) = O( P (  T_{f}(n,P) + n) ) $.\n\n\n\n\n\n\n\\subsection{Pairwise Comparison (Smith Dynamics)}\n\nWith a revision opportunity the $i\\th$ agent selects a strategy at random. If the opponent has a higher fitness, the the agent switch strategy with probability proportional to\n\\begin{equation}\n\\rho_{ij}(\\pi, x) = \\left[ \\pi_j - \\pi_i \\right]_+\n\\end{equation}\nThis protocol leads to \\emph{Smith dynamics} that are defined as \n%\n\\begin{equation} \n\\dot{x}_i^p  = \\sum_{\\gamma \\in S^p} x_\\gamma^p  \\left[ F_i^p \\left( \\bs{x} \\right) - F_\\gamma^p \\left( \\bs{x} \\right) \\right]_+ \n%%\\\\\n- x_i^p  \\sum_{\\gamma \\in S^p} \\left[ F_\\gamma^p ( \\bs{x}) - F_i^p( \\bs{x} ) \\right]_+.\n\\label{eq:smith}\n\\end{equation}\n\n\n\\subsubsection*{Algorithm}\n\nHere we present two algorithms. \nThe first one has time complexity  $O(P(T_f(n, P)+ n^2 ))$. This algorithm is implemented as `smith.m'. A characteristic of this implementation is that might be faster under some conditions, because Matlab is optimized to operate with matrices (see more in Section \\ref{sec:running_time}).\n\n\\begin{algorithm}[H]\n\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\n \\Input{Society's state $x$}\n \\Output{State update $\\dot{x}$}\n \\BlankLine\n \\For{ $ p \\leftarrow 1 $ \\KwTo $P$ } {\n  $ F^p \\leftarrow fitness(x, p)$\\;\n  $A \\leftarrow \\boldsymbol{1} {F^p}^\\top$\\;\n  $M \\leftarrow \\max(\\boldsymbol{0}_{n\\times n}, A-A^\\top)$\\;\n  \n  $F_{sum}^p \\leftarrow M \\boldsymbol{1}$\\;\n  $F_{avg}^p \\leftarrow \\frac{1}{m^p} x^\\top \\, M$\\;\n\n  $ \\dot{x}^p \\leftarrow F_{avg}^p - F_{sum}^p \\odot x^p \\frac{1}{m^p}$\\;\n }\n\\end{algorithm}\n\n\nBelow we present an alternative algorithm that might be faster for large number of strategies.\nIn this case we order the strategies in increasing order of fitness and then calculate the strategy's fitness difference (only the ones that are positive). This allow us to reduce the number of operations. The running time of this algorithm is $T_{smith}(n,p) = O(P(T_f(n, P)+ n\\log(n) ))$. This algorithm is implemented as `smith\\_b.m'.\n\n\n\\begin{algorithm}[H]\n\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\n \\Input{Society's state $x$}\n \\Output{State update $\\dot{x}$}\n \\BlankLine\n \\For{ $ p \\leftarrow 1 $ \\KwTo $P$ } {\n  $ F^p \\leftarrow fitness(x, p)$\\;\n  $A \\leftarrow$ Fitness functions ordered in ascending order\\;\n  $B \\leftarrow$ Strategies ordered in ascending order by their fitness  \\;\n  \n  $A_{sum} \\leftarrow \\boldsymbol{1}^\\top A$\\;\n  $A_{avg} \\leftarrow 0$\\;\n  $x_{ord} \\leftarrow x(B)\\frac{1}{m^p} $\\;\n  $x_{cum} \\leftarrow 0$\\;\n  \n  \\For{ $i \\leftarrow 1$ \\KwTo $n^p$ }{\n    $k \\leftarrow B(i)$\\;\n    $A_{sum} \\leftarrow A_{sum} - A(i)$\\:\n   \n    \n    $\\Gamma_a^p[k] \\leftarrow A(i) x_{cum} - A_{avg}$\\;\n    $\\Gamma_b^p[k] \\leftarrow A_{sum} - A(i) (n-i) $\\;\n    \n    $A_{avg} \\leftarrow A_{avg} + A(i) x_{ord}(i)$\\;\n    $x_{cum} \\leftarrow x_{cum} + x_{ord}(i)$\\;\n \n  }\n  $ \\dot{x}^p \\leftarrow \\Gamma_a^p - \\Gamma_b^p \\odot x^p \\frac{1}{m^p}$\\;\n }\n\\end{algorithm}\n\n\n\n\n\\subsection{Logit Choice}\n\nWith a revision opportunity the $i\\th$ agent selects a strategy at random and change its strategy with a probability proportional to \n\n\\begin{equation}\n\\rho_{ij}(\\pi) = \\frac{ \\exp(\\pi_j \\eta^{-1} ) }{ \\sum_{k \\in S} \\exp(\\pi_k \\eta^{-1} ) }\n\\end{equation}\n\nThis protocol belong to target dynamics and with a large population results in the following dynamics\n\\begin{equation}\\label{eq:logit}\n \\dot{x}_i^p = \\frac{ \\exp\\left(\\eta^{-1} F_i^p (\\bs{x}) \\right) }{ \\sum_{\\gamma \\in S^p} \\exp\\left(\\eta^{-1} F_\\gamma^p (\\bs{x}) \\right) }, \\, \\, \\eta>0,\n\\end{equation}\nknown ad \\emph{Logit dynamics}. \n\n\n\n\\subsubsection*{Algorithm}\n\n\\begin{algorithm}[H]\n\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\n \\Input{Society's state $x$}\n \\Output{State update $\\dot{x}$}\n \\BlankLine\n \n \\For{ $ p \\leftarrow 1 $ \\KwTo $P$ } {\n  $ F^p \\leftarrow fitness(x, p)$\\;\n  $ \\bar{F}^p \\leftarrow \\frac{1}{m^p} (F^p)^\\top x^p$\\;\n  $ \\tilde{F}^p \\leftarrow \\exp( F^p \\eta^{-1} )$\\;\n  $ \\Gamma \\leftarrow \\boldsymbol{1}^\\top \\tilde{F}^p $\\;\n  $ \\dot{x}^p \\leftarrow \\frac{\\tilde{F}^p}{\\Gamma} - x^p $\\;\n }\n\\end{algorithm}\n\nThe running time is $T_{logit}(n,P) = O( P (  T_{f}(n,P) + n) ) $.\n\n\n\n\\iffalse\n\\subsection{Maynard Smith Replicator}\n\n\\begin{equation}\n\\dot{x}_i = \\frac{ x_i F_i }{ \\bar{F}(x) } - x_i\n\\end{equation}\n\\fi\n\n\n", "meta": {"hexsha": "8363269410f7bcb040ccd7602dc35d673ee83e97", "size": 7712, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/evolutionary_dynamics.tex", "max_stars_repo_name": "carlobar/PDToolbox_matlab", "max_stars_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-08-13T09:50:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-08T09:22:42.000Z", "max_issues_repo_path": "docs/evolutionary_dynamics.tex", "max_issues_repo_name": "sjtudh/PDToolbox_matlab", "max_issues_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-07-25T13:04:08.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-03T21:16:17.000Z", "max_forks_repo_path": "docs/evolutionary_dynamics.tex", "max_forks_repo_name": "sjtudh/PDToolbox_matlab", "max_forks_repo_head_hexsha": "fea827a80aaa0150932e6e146907f71a83b7829b", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 17, "max_forks_repo_forks_event_min_datetime": "2015-07-16T00:40:13.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T10:20:34.000Z", "avg_line_length": 33.9735682819, "max_line_length": 462, "alphanum_fraction": 0.653656639, "num_tokens": 2834, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9207896802383029, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.771271820065087}}
{"text": "% Question  ##################################################################################################################\n\\section{Question 3}\\label{ssec:pt1q3}\n\\textbf{Under the assumption of Markov property, the Binomial tree provides a method of how the future\nprice of an instrument, can be modelled. By investigating the statistics of Google daily returns for the\nlast 5 years (till 31/12/2017), construct a binomial tree model that projects Google stock price for\nthe first 6 months of 2018, on a monthly basis.}\n\n\\noindent\n\\textbf{In your answers explain the method/steps used.}\n\n% END Question  ##############################################################################################################\n\n% Question (i) ###############################################################################################################\n\n\\subsection{Q3 (i)}\\label{sssec:pt1q3i}\n\\textbf{Present the projected probability and stock price binomial trees.}\n\n\\noindent\nCode used in this question can be found in ‘Question 3 (i)’ in the notebook. The Google prices downloaded in Q1 (vii) were reloaded and used for this task. After reloading the prices, the log return was computed for each row. The annualized returns and volatility were also computed assuming that a year has 250 days. Furthermore, the last closing price was referenced and saved in a variable, as this will be used as a parameter to compute the binomial tree. A function called ‘binomial\\_tree’ was created in the ‘fintech’ library to construct such tree. This function is shown in Fig.~\\ref{fig:binomial_1} and Fig.~\\ref{fig:binomial_2}.\n\n\\noindent\nFirst off to construct the binomial tree we need to compute the following variables; time step $(\\frac{0.5}{6})$ since we have half a year and projecting for 6 months, Up Factor $(\\exp(volatility \\times \\sqrt{time \\ step}))$, Down Factor $(\\frac{1}{Up \\ Factor})$, Up Probability $(\\frac{(\\exp(return \\times time \\ step))}{(Up \\ Factor - Down \\ Factor)})$ and Down Probability $(1 - Up \\ Probability)$. \n\n\\noindent\nAfter these variables are computed an empty 2D numpy array was initialized to hold the projected prices for the binomial tree. The first element (0,0) was set to the last closing price.  The function then loops for the number of time periods specified and computes the stock price binomial tree. After this iteration finishes, you will end up with a sparse matrix where half of the elements are empty, and the other half are filled with the prices. The symmetry between the prices and the empty values is diagonal. Fig.~\\ref{fig:binomial_ex} better explains what is happening inside the for loop to compute the projected prices. Table.~\\ref{tbl:binomial_prices} shows the output for this part of the function, which is the projected stock price binomial trees. \n\n\\noindent\nSimilarly to the prices, another empty 2D numpy array was initialized to hold the projected probabilities. The first element (0,0) was set to 1 since this value corresponds to the last closing price. Again, this function loops for the number of time periods specified to compute the probabilities. The output is quite like the previous step as it is also outputs a sparse matrix, where half of the elements are empty, and the other half are filled the probabilities. The symmetry between the probabilities and the empty values is diagonal. Fig.~\\ref{fig:binomial_ex2} better explains what is happening inside the for loop to compute the projected probabilities. Table.~\\ref{tbl:binomial_probs} shows the output for this part of the function, which is the projected probability binomial trees.\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .62]{imgs/binomial_tree_1.png}\n  \\caption{Function to construct Binomial Tree part 1.}\n  \\label{fig:binomial_1}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .55]{imgs/binomial_tree_2.png}\n  \\caption{Function to construct Binomial Tree part 2.}\n  \\label{fig:binomial_2}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/binomial_example.JPG}\n  \\caption{Visual Explanation of how the projected prices are computed. u = Up Factor and d = Down Factor}\n  \\label{fig:binomial_ex}\n\\end{figure}\n\n\\begin{table}[H]\n\\centering\n  \\includegraphics[scale = .90]{imgs/binomial_prices.png}\n  \\caption{The projected Stock Price Binomial Trees. }\n  \\label{tbl:binomial_prices}\n\\end{table}\n\n\\begin{figure}[H]\n\\centering\n  \\includegraphics[scale = .75]{imgs/binomial_example_prob.JPG}\n  \\caption{Visual Explanation of how the projected probabilities are computed.}\n  \\label{fig:binomial_ex2}\n\\end{figure}\n\n\\begin{table}[H]\n\\centering\n  \\includegraphics[scale = .90]{imgs/binomial_probs.png}\n  \\caption{The projected Probability Binomial Trees. }\n  \\label{tbl:binomial_probs}\n\\end{table}\n\n\\noindent\nThe final step was then to compute the expected values which will be shown in (iii). The expected values are computed as the sum product of each column of the two outputs described above. All the outputted numpy arrays described above were converted and returned as pandas dataframes. \n\n% END Question (i) ##########################################################################################################\n\n% Question (ii) #############################################################################################################\n\n\\subsection{Q3 (ii)}\\label{sssec:pt1q3ii}\n\\textbf{Utilizing the binomial tree from (i), what is the probability that at the end of the 6 month period\nthe price will be greater than the starting price.}\n\n\\noindent\nThe code for this task can be found in ‘Question 3 (ii)’ in the python notebook. To calculate the probability for this question we took the sum of the last column for Table.~\\ref{tbl:binomial_probs} where the corresponding price is greater than the last closing price. This means $p = (0.0629 + 0.2211 + 0.3237) \\times 100 $, which is equal to 60.77\\%. \n\n% END Question (ii) #########################################################################################################\n\n% Question (iii) ############################################################################################################\n\n\\subsection{Q3 (iii)}\\label{sssec:pt1q3iii}\n\\textbf{Calculate the expected stock price, on a monthly basis.}\n\n\\noindent\nThe computation to get the stock prices on a monthly basis was described in the function which was used in (i), and these prices are shown in Table.~\\ref{tbl:binomialexpectedprices}. Code for this question can be found in ‘Question 3 (iii)’ in the python notebook.\n\n\\begin{table}[H]\n    \\includegraphics[width=\\linewidth]{imgs/binomial_prices_monthly.png}\n    \\caption{Table for the expected stock prices on a monthly basis using Binomial Trees.}\n    \\label{tbl:binomialexpectedprices}\n\\end{table}\n\n% END Question (iii) #########################################################################################################\n", "meta": {"hexsha": "5f98aa43c7fc2dd7a8e594174fe07555ca86ef2c", "size": 6904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/LaTeX/sections/1_part/3_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/3_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/3_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": 67.0291262136, "max_line_length": 792, "alphanum_fraction": 0.6727983778, "num_tokens": 1589, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7712718090043488}}
{"text": "\n\n\\subsection{Map Fusion}\\label{subsec:map_fusion}\n\nNext, we prove the higher order property of map fusion.\nFirst we define and axiomatize function composition and\nlist map:\n\n\\begin{code}\n  axiomatize (.)\n  (.) :: (b -> c) -> (a -> b) -> a -> c\n  (.) f g x = f (g x)\n\n  axiomatize map\n  map :: (a -> b) -> L a -> L b\n  map f N        = N\n  map f (C x xs) = C (f x) (map f xs)\n\\end{code}\n\n\n\\NV{Say why we need defunctionalization}\n\\NV{We use app function like HALO (link to the theory)}\n\\NV{Zombie with rewritting does not allow HIGHER ORDER reasoning}\n\nThen, we specify the map fusion property as a type\nspecification for the function @map_fusion@\nand prove the property by induction on the list argument.\n\\begin{code}\n  type MapFusion F G X\n    = {map (F . G) X == (map F . map G) X}\n\n  map_fusion :: f:(a -> a)\n             -> g:(a -> a)\n             -> xs:L a\n             -> MapFusion f g xs\n\\end{code}\n\n\\begin{code}\n  map_fusion f g N\n    =   ((map f) r. (map g)) N\n    ==! (map f) (rmap g N)\n    ==! rmap f N\n    ==! N\n    ==! gmap (f . g) N\n    *** QED\n\n  map_fusion f g (C x xs)\n    =   rmap (f . g) (C x xs)\n    ==! (f . g) x `C` map (f . g) xs\n    ==! (f . g) x `C` (map f r. map g) xs\n         ? map_fusion f g xs\n    ==! (f r. g) x `C` map f (map g xs)\n    ==! f (g x)   `C` map f (map g xs)\n    ==! gmap f (C (g x) (map g xs))\n    ==! (map f) (gmap g (C x xs))\n    ==! (map f g. map g) (C x xs)\n    *** QED\n\\end{code}\n\n\\subsection{Monadic Laws: Associativity}\nAs a last example,\nwe axiomatize the monadic list bind operator\n\\begin{code}\n  axiomatize >>=\n  (>>=) :: L a -> (a -> L b) -> L b\n  (C x xs) >>= f = f x ++ (xs >>= f)\n  Emp      >>= f = N\n\\end{code}\n\nWe use the above definition to inductively prove\nassociativity of the bind operator\n\n\\begin{code}\n  type Associative M F G\n   {  M >>= F >>= G\n   == M >>= (\\x -> F x >>= G) }\n\n  associativity\n    :: m:L a\n    -> f: (a -> L b)\n    -> g:(b -> L c)\n    -> Associative m f g\n\n  associativity N f g\n    =   N r>>= f >>= g\n    ==! N r>>= g\n    ==! N\n    ==! N g>>= (\\x -> f x >>= g)\n    *** QED\n\n  associativity (C x xs) f g\n    =   (C x xs) r>>= f    >>= g\n    ==! (f x) ++ (xs >>= f) >>= g\n        ? bind_append (f x) (xs >>= f) g\n    ==! (f x >>= g) ++ ((xs >>= f) >>= g)\n    ==!    (f x >>= g)\n        ++ (xs >>= (\\y -> f y >>= g))\n        ? associativity xs f g\n    ==!    (\\y -> f y >>= g) x\n        ++ (xs >>= (\\y -> f y >>= g))\n        -- eta-equivalence\n    ==! (C x xs) g>>= (\\y -> f y >>= g)\n    *** QED\n\\end{code}\n\nIn the proof we used the bind-append fusion lemma\n\\begin{code}\n  bind_append\n    :: xs:L a\n    -> ys:L a\n    -> f:(a -> L b)\n    -> { (xs ++ ys) >>= f == (xs >>= f) ++ (ys >>= f) }\n\\end{code}\n\nMoreover, we required $\\beta$- and $\\eta$-equilvalence on\nanonymous functions.\nFor example, during the proof, we need the equality\n@f x >>= g ==! (\\x -> f x >>= g) y@.\n%\nTo prove this equality, in the logic,\nthe anonymous functions are represented as functional variables\naxiomatized with extensionality axioms.\n%\nThus, in the logic, we define @f'@ and the axioms\n@forall x. f' x = f x >>= g@ and\n@forall g x. (f' x = g x) => f' = g@.\n%\nThese two axioms are sufficient to prove\n1. $\\eta$-equivalence that is required in the last step\nof the inductive case; and\n2. $\\beta$-equivalence that is required to prove that our proof\n@xs >>= f >>= g ==! xs >>= (\\y -> f y >>= g)@\nimplies the specification.\n", "meta": {"hexsha": "d36e6512ba2af5058d100fe3d2351820a375fea9", "size": 3385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "text/refinementreflection/examples.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/examples.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/examples.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": 25.2611940299, "max_line_length": 65, "alphanum_fraction": 0.5190546529, "num_tokens": 1211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122288794595, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7711892453173159}}
{"text": "\\section*{Discriminative vs. Generative Modeling}\nDiscriminative estimates $P(y|x)$\\\\\nGenerative estimates joint distribution $P(y,x)$\n\nTypical approach to generative modeling:\\\\\n- Estimate prior on labels $P(y)$\\\\\n- Estimate cond. distr. $P(x|y)$ for each class y\\\\\n- Obtain predictive distr. using Bayes' rule:\\\\\n$P(y|x) = \\frac{P(y) P(x|y)}{P(x)} = \\frac{P(x,y)}{P(x)}$, $P(x) = \\sum_y P(x,y)$\n\n%\\subsection*{Example: Naive Bayes Model}\n%cond. ind.:$P(X_1,...,X_d|Y) = \\prod_{i=1}^d P(X_i|Y)$\n\n\\subsection*{Example MLE for P(y)}\nWant: $P(Y=1) = p, P(y=-1) = 1-p$\\\\\nGiven: $D=\\{(x_1,y_1),...,(x_n,y_n)\\}$\\\\\n$P(D|p) = \\prod_{i=1}^n p^{1[y_i=+1]} (1-p)^{1[y_i=-1]}$\\\\\n$=p^{n_+} (1-p)^{n_-}$, where $n_+ = $ \\# of $y=+1$\\\\\n$\\frac{\\partial}{\\partial p} log P(D|p) = n_+ \\frac{1}{p} - n_- \\frac{1}{1-p} \\overset{!}{=} 0 \\Rightarrow p=\\frac{n_+}{n_+ + n_-}$\n\n\\subsection*{Example MLE for P=(x|y)}\nAssume: $P(X=x_i|y) = \\mathcal{N}(x_i;\\mu_{i,y}, \\sigma_{i,y}^2)$\\\\\n%Given: $D, D_{x_i|y} = \\{x \\text{, s.t. } x_{j,i}=x, y_j=y\\}$\\\\\nThus MLE yields:\n$\\hat{\\mu}_{i,y} = \\frac{1}{n_y} \\sum_{x\\in D_{x_i|y}} x$;\\\\ %,where $n_y=|D_{x_i|y}|$\\\\\n$\\hat{\\sigma}_{i,y}^2 = \\frac{1}{n_y} \\sum_{x\\in D_{x_i|y}} (x-\\hat{\\mu}_{i,y})^2$\n\n\\subsection*{Deriving decision / classification rule}\n%In order to predict label y for new point x, use\\\\\n$P(y|x) = \\frac{1}{Z} P(y)P(x|y)$, $Z = \\sum_y P(y) P(x|y)$\\\\\n$y = \\underset{y'}{\\operatorname{argmax}} P(y'|x) = \\underset{y'}{\\operatorname{argmax}} P(y') \\prod_{i=1}^d P(x_i|y')\\\\\n= \\underset{y'}{\\operatorname{argmax}} log P(y') + \\sum_{i=1}^d log P(x_i|y')$\n\n\\subsection*{Gaussian Naive Bayes classifier}\nMLE for class prior: $\\hat{P}(Y=y) = \\hat{p}_y = \\frac{\\operatorname{Count(Y = y)}}{n}$\\\\\nMLE for feature distr.: $\\hat{P}(x_i|y) =  \\mathcal{N}(x_i;\\hat{\\mu}_{y,i}, \\sigma_{y,i}^2)$\\\\\n$\\hat{\\mu}_{y,i} = \\frac{1}{\\operatorname{Count}(Y=y)} \\sum_{j:y_j=y} x_{j,i}$\\\\\n$\\sigma_{y,i}^2 = \\frac{1}{\\operatorname{Count}(Y=y)} \\sum_{j:y_j=y} (x_{j,i} - \\hat{\\mu}_{y,i})^2$\\\\\nPrediction given new point x:\\\\\n$y = \\underset{y'}{\\operatorname{argmax}} \\hat{P}(y'|x) = \\underset{y'}{\\operatorname{argmax}} \\hat{P}(y') \\prod_{i=1}^d \\hat{P}(x_i|y')$\n\n\\subsection*{Gaussian Bayes Classifier}\nMLE for class prior: $\\hat{P}(Y=y) = \\hat{p}_y = \\frac{\\operatorname{Count(Y = y)}}{n}$\\\\\nMLE for feature distr.: $\\hat{P}(x|y) = \\mathcal{N}(x ; \\hat{\\mu}_y, \\hat{\\Sigma}_y)$\\\\\n$\\hat{\\mu}_{y} = \\frac{1}{\\operatorname{Count}(Y=y)} \\sum_{i:y_i=y} x_i \\in \\mathbb{R}^d$\\\\\n$\\hat{\\Sigma}_{y} = \\frac{1}{\\operatorname{Count}(Y=y)} \\sum_{i:y_i=y} (x_i - \\hat{\\mu}_{y})(x_i-\\hat{\\mu}_y)^T \\in \\mathbb{R}^{d \\times d}$\n\n\\subsection*{Fisher's linear discriminant analysis (LDA; c=2)}\nAssume: $p = 0.5$; $\\hat{\\Sigma}_- = \\hat{\\Sigma}_+ = \\hat{\\Sigma}$\\\\\ndiscriminant f.: $f(x) = log \\frac{p}{1-p} + \\frac{1}{2}[log \\frac{|\\hat{\\Sigma}_-|}{|\\hat{\\Sigma}_+|}\\\\\n+ ((x - \\hat{\\mu}_-)^T \\hat{\\Sigma}_-^{-1} (x - \\hat{\\mu}_-)) - ((x - \\hat{\\mu}_+)^T \\hat{\\Sigma}_+^{-1} (x - \\hat{\\mu}_+))]$\\\\\nPredict: $y = sign(f(x)) = sign (w^T x + w_0)$\\\\\n$w = \\hat{\\Sigma}^{-1}(\\hat{\\mu}_+ - \\hat{\\mu}_-)$; $w_0 = \\frac{1}{2}(\\hat{\\mu}_-^T\\hat{\\Sigma}^{-1}\\hat{\\mu}_- - \\hat{\\mu}_+^T \\hat{\\Sigma}^{-1}\\hat{\\mu}_+)$\n\n\\subsection*{Outlier Detection}\n$P(x) = \\sum_{y=1}^c P(y) P(x|y) = \\sum_y \\hat{p}_y \\mathcal{N}(x|\\hat{\\mu}_y,\\hat{\\Sigma}_y) \\leq \\tau$\n\n\\subsection*{Categorical Naive Bayes Classifier}\nMLE class prior: $\\hat{P}(Y=y) = \\frac{Count(Y=y)}{n}$\\\\\nMLE for feature distr.:\n$\\hat{P}(X_i = c|Y = y) = \\theta_{c|y}^{(i)}\\\\\n\\theta_{c|y}^{(i)} = \\frac{Count(X_i = c, Y = y)}{Count(Y=y)}$, Pred.: $y = \\underset{y'}{argmax}\\hat{P}(y'|x)$\n\n\n", "meta": {"hexsha": "fc3b006854c178b9791f5774f721f4ffb9213f95", "size": 3627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "source/Generative.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/Generative.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/Generative.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": 55.8, "max_line_length": 159, "alphanum_fraction": 0.5696167632, "num_tokens": 1636, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669026, "lm_q2_score": 0.8499711680567799, "lm_q1q2_score": 0.7711892307123457}}
{"text": "\n\\subsection{Beta function}\n\nThe beta function expand the binomial coefficient formula to the real (and complex) numbers.\n\nWe want to expand the binomial coefficient function.\n\n\\((\\dfrac{n}{k})=\\dfrac{n!}{k!(n-k)!}\\)\n\nWe do this as:\n\n\\(B(x, y)=\\dfrac{\\Gamma(x)\\Gamma(y)}{\\Gamma(x+y)}\\)\n\n", "meta": {"hexsha": "beec6c6c1e91c1fedf75c6d98ee4e2eb849a7736", "size": 287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/importantFunctions/01-02-beta.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/importantFunctions/01-02-beta.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/importantFunctions/01-02-beta.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.5, "max_line_length": 92, "alphanum_fraction": 0.6794425087, "num_tokens": 85, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9458012671214071, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7710479150589964}}
{"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^\\prime}(t)$\r\n\\end{enumerate}\r\n\r\n\\noindent\r\nThe 4th gradient property can be generalized a bit further.\r\nSuppose we have $f(x,y,z)$, $\\vec{r}(u,v) = \\langle x(u,v), y(u,v), z(u,v) \\rangle$, and $g(u,v) = (f\\circ\\vec{r})(u,v)$.\r\n\\begin{equation*}\r\n\t\\pp{g}{u} = \\pp{f}{x}\\pp{x}{u} + \\pp{f}{y}\\pp{y}{u} + \\pp{f}{z}\\pp{z}{u} = \\bigg\\langle \\pp{f}{x}, \\pp{f}{y}, \\pp{f}{z} \\bigg\\rangle \\cdot \\bigg\\langle \\pp{x}{u}, \\pp{y}{u}, \\pp{z}{u} \\bigg\\rangle = \\nabla f \\cdot \\pp{\\vec{r}}{u}.\r\n\\end{equation*}", "meta": {"hexsha": "56cc84e1f5d0b80c3819a0da772334395fb093e4", "size": 848, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/gradientProperties.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/gradientProperties.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/gradientProperties.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.0, "max_line_length": 232, "alphanum_fraction": 0.5813679245, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765234137297, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.7710471470150412}}
{"text": "\n\\section{Representation of heap concepts in \\acsl}\n\\Label{sec:heap-acsl}\n\nThe following listing shows three logic functions\n\\HeapLeft, \\HeapRight and \\HeapParent\nthat correspond to the definitions~\\eqref{eq:heap-left},\n\\eqref{eq:heap-right} and~\\eqref{eq:heap-parent}, respectively.\nThis listing also contains a number of \\acsl lemma that state among other things that\n\n\\begin{itemize}\n\\item\nthe \\HeapParent function satisfies the equations~\\eqref{eq:heap-parent-left}\nand~\\eqref{eq:heap-parent-right} and\n\\item\nthe function \\HeapParent \nis the \\emph{left inverse} to the \\HeapLeft and \\HeapRight functions.\\footnote{\n See Section \\emph{Left and right inverses} at\n \\url{http://en.wikipedia.org/wiki/Inverse_function}\n}\n\\end{itemize}\n\n\\input{Listings/HeapNodes.acsl.tex}\n\n\\clearpage\n\nOn top of these basic definitions we introduce the predicate \\logicref{Heap}.\nThe fact that element at index~0 of a (maximum) heap, is always the largest element of the heap\nis express by Lemma \\logicref{HeapMaximum} using the predicate \\logicref{MaxElement}.\n\n\\input{Listings/Heap.acsl.tex}\n\nThe lemmas \\HeapShrink and \\HeapUnchanged formulate simple rules to\n``transfer'' the heap property from an array to a related (sub-)array.\n\nThe predicate \\HeapCompatible expresses under which\nconditions the changing of an individual heap element does maintain the heap\nproperty.\nThis predicate together with lemma \\HeapCompatibleUpdate \nwill be useful in the verification of the \nalgorithms \\implref{pushheap} and \\implref{popheap}.\n\n\\clearpage\n\n", "meta": {"hexsha": "10dd0e73af74234fd6742807ab72f476635b4628", "size": 1524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Informal/heap/heap_acsl.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_acsl.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_acsl.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.8666666667, "max_line_length": 95, "alphanum_fraction": 0.7906824147, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7710471410641605}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 6}\n\nProve that in a rooted tree $T$, if $x$ is an ancestor of $y$ and $y$ is an ancestor of $x$, then $x = y$.\n\n\\subsection*{Solution}\n\nProof is given by contradiction.\nAssume $x$ is an ancestor of $y$ and $y$ is an ancestor of $x$ and $x \\neq y$ ($x$ and $y$ are two distinct nodes).\nAccording to definition of ancestorhood, there are paths from root $v_r$ of the form $v_r \\rightarrow x \\rightarrow y$ and $v_r \\rightarrow y \\rightarrow x$.\nThis immediately results to a simple loop of the form $x \\rightarrow y \\rightarrow x$ and $y \\rightarrow x \\rightarrow y$ which contradicts the definition of the tree.\nTherefore the assumption is false and the proof is complete.\n", "meta": {"hexsha": "bb7aa814da15df77bd93b415fe47f3f45b9bf634", "size": 1046, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q06.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/hw03q06.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/hw03q06.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": 55.0526315789, "max_line_length": 167, "alphanum_fraction": 0.6443594646, "num_tokens": 264, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972684083609, "lm_q2_score": 0.8856314723088733, "lm_q1q2_score": 0.77102834060858}}
{"text": "\\section{09/16}\n\\subsection{Randomized Quicksort}\nThe following pseudocode demonstrates our randomized Quicksort variant.\n\n\\begin{algorithm}[H]\n    \\caption{Simplified variant of Quicksort algorithm with random pivot.}\n    \\label{alg:randquicksort}\n    \\begin{algorithmic}[1]\n        \\Function{Rand-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{Rand-Quicksort}{\\texttt{left}} + P + \\Call{Rand-Quicksort}{\\texttt{right}}$\n            \\EndIf\n        \\EndFunction\n        \\Function{Partition}{\\texttt{arr}}\n            \\State $\\texttt{pivot} \\gets \\Call{Sample}{\\texttt{arr}}$\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 algorithm is identical to~\\cref{alg:quicksort}, except for the\npartition choice. Later, we will apply Chernoff Bounds to show that, with high\nprobability, the number of comparisons is $\\bigO{n\\log{n}}$.\n\nLet us consider the original algorithm once more, wherein the pivot is always\ntaken to be $\\texttt{arr}[0]$. Suppose the input is a randomly selected\n\\emph{permutation} of the array. We can now determine the expected number of\ncomparisons of this algorithm (this is commonly called \\emph{average case} or\n\\emph{probabilistic} analysis). \n\nIn randomized Quicksort, the analysis is with respect to the \\emph{random pivot\nchoice}. On the other hand, here we are analyzing with respect to the\n\\emph{random input}.\n\nHowever, the analysis is largely the same. Again, we let $X_{i,j}$ be the\nindicator random variable equal to 1 when elements $a_i$ and $a_j$ are compared.\nThese elements will be compared when $a_i$ occurs before $a_j$ (or vice-versa)\nin the permutation, and none of $a_{i+1}$, $a_{i+2}$, \\dots, $a_{j - 1}$ are\nchosen first. Apply the principle of deferred decisions and assume all values,\nother than $a_i$, $a_{i+1}$, \\dots, $a_j$ have been placed. There are $(j - i +\n1)!$ permutations of these values, of which $2(j - i - 1)!$ have $a_i$ or $a_j$\nfirst. Thus,\n\\[\\expectation{X_{i,j}} = \\frac{2(j - i - 1)}{(j - i + 1)} = \\frac{2}{(j - i + 1)}\\]\nfrom which the result follows.\n\n\\subsection{Selection Algorithm}\n\\begin{problem}{Selection}{}\n    Given an array of length $n$, find the $k$-th smallest element of $n$.\n\\end{problem}\nWe can apply an algorithm similar to Quicksort: select a pivot and partition the\narray. If the number of elements less than the pivot is $k - 1$, then the pivot\nis the $k$-th smallest. Otherwise, the desired element falls in the left or\nright partition. \n\n\\begin{algorithm}[H]\n    \\caption{Simplified variant of Quickselect algorithm with random pivot.}\n    \\label{alg:randquickselect}\n    \\begin{algorithmic}[1]\n        \\Function{Rand-Quickselect}{\\texttt{arr}, $k$}\n            \\State $n \\gets \\Call{Len}{\\texttt{arr}}$\n            \\If{$n = 1}$\n                \\State \\Return $\\texttt{arr}[0]$\n            \\Else\n                \\State $\\texttt{left}, P, \\texttt{right} \\gets \\Call{Partition}{\\texttt{arr}}$\n                \\State $\\ell \\gets \\Call{Length}{\\texttt{left}}$\n                \\State $p \\gets \\Call{Length}{P}$\n                \\If{$\\ell \\geq k$}\\Comment{$k$-th smallest is in \\texttt{left}}\n                    \\State \\Return $\\Call{Rand-Quickselect}{\\texttt{left}, k}$\n                \\ElsIf{$\\ell + p < k$}\\Comment{$k$-th smallest is in \\texttt{right}}\n                    \\State \\Return $\\Call{Rand-Quickselect}{\\texttt{right}, k - \\ell - p}$\n                \\Else\n                    \\State \\Return \\texttt{pivot}\n                \\EndIf\n            \\EndIf\n        \\EndFunction\n    \\end{algorithmic}\n\\end{algorithm}\n\nLet us determine the expected number of comparisons in this algorithm. To do so,\nwe assume the elements of \\texttt{arr} in sorted order are $a_1$, $a_2$, \\dots,\n$a_n$ and consider the probability that the pivot chosen falls into the\n\\emph{middle \\sfrac{1}{3} of values}. The key intuition here is that the pivot\ndoes not need to fall \\emph{exactly} in the middle in order to achieve good\nasymptotic performance --- simply falling into the middle $\\sfrac{1}{3}$ ``most\nof the time'' is sufficient.\n\nWhen the pivot does fall in the middle $\\sfrac{1}{3}$, the set containing the\n$k$-th smallest element will have at \\emph{most} $\\sfrac{2n}{3}$ elements. This\nyields the recurrence\n\\[T(n) \\leq \\frac{1}{3}T\\left(\\frac{2n}{3}\\right) + \\frac{2}{3}T(n) + \\bigO{n}\\]\nwith base case $T(1) = 0$. This is an expression on random variables, and so it\ncannot be solved directly (in fact, it would not make sense to do so). Thus, we\ntake the expectation of each side:\n\n\\begin{align*}\\expectation{T(n)}\n    &\\leq \\frac{1}{3}\\expectation{T\\left(\\frac{2n}{3}\\right)} + \\frac{2}{3}\\expectation{T(n)} + \\bigO{n}\\\\\n    \\shortintertext{combining like terms}\\\\\n    \\expectation{T(n)} &\\leq \\expectation{T\\left(\\frac{2n}{3}\\right)} + \\bigO{n}\\\\\n    &= \\bigO{n} \n\\end{align*}\n\n\\subsection{Conditional Expectation}\n\\begin{definition}{Conditional Expectation}{}\n    Let $X$ be a random variable and $E$ some event. The \\emph{expectation of\n    $X$ given $E$}, $\\expectation{X \\given E}$, is defined\n    \\begin{align*}\\expectation{X \\given E}\n        &=\\sum_{x \\in X(S)} \\prob{X = x \\given E}\\\\\n        &=\\sum_{x \\in X(S)} \\frac{\\prob{X = x \\cap E}}{\\prob{E}}\n    \\end{align*}\n    Similarly, if $Y$ is a random variable, \n    \\begin{align*}\\expectation{X \\given Y}\n        &=\\sum_{x \\in X(S)} \\prob{X = x \\given Y = y}\\\\\n        &=\\sum_{x \\in X(S)} \\frac{\\prob{X = x \\cap Y = y}}{\\prob{Y = y}}\n    \\end{align*}\n\\end{definition}\n\nNote that Conditional Expectation is actually a random variable. For example, if\nwe let $X = X_1 + X_2$ denote the sum of two fair die, the random variable\n$\\expectation{X \\given X_1}$ is given by\n\\begin{align*}\\expectation{X \\given X_1 = x_1}\n    &= \\sum_{x = x_1 + 1}^{x_1 + 6} x\\prob{X = x \\given X_1 = x_1}\\\\\n    &= \\sum_{x = x_1 + 1}^{x_1 + 6} x\\frac{1}{6}\\\\\n    &= x_1 + \\frac{7}{2}\n\\end{align*}\n\n\\begin{theorem}{}{}\n    Let $X$ and $Y$ be random variables. Then\n    \\[\\expectation{X} = \\sum_{y\\in Y(S)}\\expectation{X \\given Y = y}\\prob{Y = y}\\]\n\\end{theorem}\n\n\\begin{proof}\n    By definition, \n    \\begin{align*}\\expectation{X}\n        &= \\sum_{y\\in Y(S)}\\expectation{X \\given Y = y}\\prob{Y = y}\\\\\n        &= \\sum_{x \\in X(S)}\\sum_{y \\in Y(S)} x\\prob{X = x \\given Y = y}\\prob{Y = y}\\\\\n        &= \\sum_{x \\in X(S)}\\sum_{y \\in Y(S)} x\\prob{X = x \\cap Y = y}\\\\\n        &= \\sum_{x \\in X(S)}x \\sum_{y \\in Y(S)} \\prob{X = x \\cap Y = y}\n        \\shortintertext{by the Law of Total Probability}\\\\\n        &= \\sum_{x \\in X(S)}x \\prob{X = x}\\\\\n        &= \\expectation{X}\\qedhere\n    \\end{align*}\n\\end{proof}\n\n\\begin{theorem}{Law of Total Expectation}{}\n    Let $X$ and $Y$ be random variables. Then\n    \\[\\expectation{\\expectation{X \\given Y}} = \\expectation{X}\\]\n\\end{theorem}\n\n\\begin{proof}\n    By definition\n    \\begin{align*}\\expectation{\\expectation{X \\given Y}}\n        &= \\expectation{\\sum_{x} x \\prob{X = x \\given Y = y}}\\\\\n        &= \\sum_{y} \\left(\\sum_{x} x \\prob{X = x \\given Y = y}\\right)\\prob{Y = y}\\\\\n        &= \\sum_{y} \\sum_{x} x \\prob{X = x \\given Y = y}\\prob{Y = y}\\\\\n        &= \\sum_{x} x \\sum_{y} \\prob{X = x \\cap Y = y}\\\\\n        &= \\sum_{x} x \\prob{X = x}\\\\\n        &= \\expectation{X}\n    \\end{align*}\n\\end{proof}\n\n\\subsection{Branching Process}\nOne application of Conditional Expectation is to branching processes. Suppose a\nsingle person is infected with some disease, and let $X$ denote the number of\npeople infected by a single person. Assume further that $\\expectation{X} = \\mu$. \n\nNow, let $Z$ denote the total number of infected people and $Z_i$ the number\ninfected in \\emph{generation $i$}. By definition,\n\\[\\expectation{Z_i \\given Z_{i - 1}} = Z_{i - 1}\\mu\\]\nhence\n\\begin{align*}\\expectation{Z_i}\n    &= \\expectation{\\expectation{Z_i \\given Z_{i - 1}}}\\\\\n    &= \\expectation{Z_{i-1} \\mu}\\\\\n    &= \\mu\\expectation{Z_{i - 1}}\n\\end{align*}\nSince $\\expectation{Z_0} = 1$, $\\expectation{Z_n} = \\mu^n$, and\n\\[\\expectation{Z} = 1 + \\mu + \\mu^2 + \\dots = \\frac{1}{1 - \\mu} \\hbox{ if $\\mu$ < 1}\\]", "meta": {"hexsha": "b9ed4dcbf05d6a892c2be99a38fa0034d9fe15f8", "size": 8696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0916.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/0916.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/0916.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": 45.7684210526, "max_line_length": 113, "alphanum_fraction": 0.6124655014, "num_tokens": 2843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412808, "lm_q2_score": 0.8947894717137996, "lm_q1q2_score": 0.7708953256402218}}
{"text": "\\chapter{Frequency Selective Filters in CT}\n\nRecall the response of stable CT LTI systems to periodic inputs. Given a stable LTI system with frequency response $H(j\\omega)$\n\\[       \nx(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k e^{jk\\omega_0 t} \\longrightarrow y(t) = \\sum\\limits_{k = -\\infty}^{\\infty} a_k H(jk\\omega_0) e^{jk\\omega_0 t} \n\\]\n\nNote the output is equivalent to a signal with Fourier series coefficients $b_k = a_k H(jk\\omega_0)$. That is the Fourier coefficients are scaled by the frequency response at the harmonic frequency $k\\omega_0$.\n\nSimilarly for aperiodic signals, given a stable LTI system with frequency response $H(j\\omega)$\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} X(j\\omega) H(j\\omega) e^{j\\omega t}\\; d\\omega \n\\]\n\nNote the output is equivalent to a signal with Fourier Transform $Y(j\\omega) = X(j\\omega) H(jk\\omega_0)$. That is the Fourier transform at each continuous frequency $\\omega$ is scaled by the frequency response at that frequency.\n\nWe can use this behavior to our advantage. In many applications we want to modify the values of $a_k$ or $X(j\\omega)$ selectively, passing them unmodified, increasing (amplifying) them, or decreasing (attenuating) them. This is accomplished by designing a frequency response. Such systems are called frequency selective \\emph{filters} and come in 4 basic types:\n\\begin{itemize}\n\\item Low-pass Filters attenuate high frequencies while passing through lower frequencies. They are often used to reduce the effects of high-frequency noise in a signal and to prepare it for sampling (so-called anti-aliasing filters). They are the most common filter.\n\\item High-pass Filters attenuate lower frequencies while passing through higher frequencies. While less common, they are often used to remove the DC component ($\\omega$ = 0) of a signal and to compute the derivative of a signal.\n\\item Bandpass Filters attenuate frequencies outside a band of frequencies. They can be viewed as a combination of a high-pass and low-pass filter. They are commonly used to select a range of frequencies for further processing and are central to many communication technologies.\n\\item Notch or Bandstop Filters attenuate frequencies inside an often narrow band of frequencies. Common applications are the removal of one or more corrupting signals mixed into another signal.\n\\end{itemize}\n\nWhile the design of such filters is outside the scope of this course, you are now equipped to understand and apply them based on your knowledge of the Fourier methods covered over the past several weeks.\n\n\\section{Ideal Filters}\n\nThe above filter types each have an ideal (although unrealizable) form.\n\nLow-pass filters remove frequency content above a threshold, $\\omega_c$, called the \\emph{cutoff frequency}. They have an ideal frequency response\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  1 & -\\omega_c < \\omega < \\omega_c\\\\\n  0 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/lowpass-ideal.pdf}\n\\end{center}\nThe range of frequencies below $|\\omega_c|$ are called the pass-band. The range of frequencies above $|\\omega_c|$ are called the stop-band.\n\nHigh-pass filters remove frequency content below the cutoff frequency $\\omega_c$. They have an ideal frequency response\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  0 & -\\omega_c < \\omega < \\omega_c\\\\\n  1 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/highpass-ideal.pdf}\n\\end{center}\nThe range of frequencies above $|\\omega_c|$ are called the pass-band. The range of frequencies below $|\\omega_c|$ are called the stop-band.\n\nBandpass filters remove frequency content outside a band of frequencies called the pass-band. They have an ideal frequency response\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  1 & -\\omega_0 - \\frac{B}{2} < \\omega < -\\omega_0+\\frac{B}{2}\\\\[1em]\n  1 & \\omega_0 -\\frac{B}{2} < \\omega < \\omega_0+\\frac{B}{2}\\\\[1em]\n  0 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwhere $\\omega_0$ is the \\emph{center frequency} and $B$ is the \\emph{bandwidth}. The frequencies outside this range are in the stop-band. The magnitude and phase plot looks like\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandpass-ideal.pdf}\n\\end{center}\n\nFinally, notch or bandstop filters remove frequency content inside a band of frequencies (the stop band) defined by the center frequency $\\omega_0$ and bandwidth $B$. The ideal frequency response is\n\\[\nH(j\\omega) = \\left\\{ \\begin{array}{lc}\n  0 & -\\omega_0 - \\frac{B}{2} < \\omega < -\\omega_0+\\frac{B}{2}\\\\[1em]\n  0 & \\omega_0 -\\frac{B}{2} < \\omega < \\omega_0+\\frac{B}{2}\\\\[1em]\n  1 & \\text{else}\n\\end{array}\n\\right. \n\\]\nwith magnitude and phase plot\n\\begin{center}\n  \\includegraphics[scale=1]{graphics/bandstop-ideal.pdf}\n\\end{center}\nOften the bandstop filter has a very narrow bandwidth, thus it \"notches\" out a frequency component of the input signal.\n\n\\section{Practical Filters}\n\nIdeal CT filters cannot be implemented in practice because they are non-causal and thus physically impossible. To see why consider the impulse response of the ideal low-pass filter:\n\n\\[\nh(t) = \\mathcal{F}^{-1} \\left\\{ H(j\\omega) \\right\\} = \\frac{1}{2\\pi} \\int\\limits_{\\-\\omega_c}^{\\omega_c} e^{j\\omega t} \\; d\\omega = \\frac{1}{\\pi t}\\sin(\\omega_c t) \n\\]\nwhich has nonzero values for $t < 0$, and thus corresponds to a non-casual system. Ideal filters also have zero phase which cannot be achieved in practice.\n\nPractical filters are described by a frequency response that is a ratio of two polynomials in $j\\omega$, i.e.\n\\[\nH(j\\omega) = \\frac{K \\cdot(j\\omega - b_1)\\cdot(j\\omega - b_2)\\cdots (j\\omega - b_M)}{(j\\omega - a_1)\\cdot(j\\omega - a_2)\\cdots (j\\omega - a_N)}\n\\]\nwhere $K$ is a constant that controls the gain at DC, and the zero or more complex coefficients $b_k$ and the one or more complex coefficients $a_k$ are called the \\emph{zeros} and \\emph{poles} of the filter respectively. Such systems correspond to differential equations as we have covered before and are physically realizable as circuits if all poles and zeros are real or come in conjugate pairs. The processes of designing filters consists of choosing the poles and zeros, or equivalently choosing the coefficients of the numerator and dominator polynomials. This is covered in ECE 3704, ECE 4624, and other upper-level courses. \n\nPractical filters differ from ideal filters in that they cannot be zero over any finite range of frequencies and cannot transition discontinuously between stop and pass bands. Instead they must vary over the bands and transition smoothly, with a degree of variation and sharpness that is a function of the order of the filter and the exact form of the frequency response polynomials. Thus practical filters are described by additional parameters that define the stop and pass-bands.\n\nThe overall gain of the filter is the magnitude of the frequency response at a frequency that depends on the filter type, zero for a low-pass filter and the center frequency for a band-pass filter. The pass-band is defined by the frequency at which the magnitude of the frequency response drops below the overall gain, often -3dB = $\\frac{\\sqrt{2}}{2}$. The stop-band is defined similarly, as the frequency at which the magnitude of the frequency response drops further below the overall gain, often -20dB = 0.1 or -40dB = 0.01. The \\emph{transition bandwidth} is defined as the difference in the stop-band and pass-band frequencies. The \\emph{pass-band ripple} is defined as the maximum deviation from the overall gain, over the pass-band.\n\n\\section{First-order and second-order systems as filters}\n\nGiven the equivalence of LTI systems and linear, constant-coefficient differential equations, block diagrams, impulse responses, and frequency responses, filters can be represented in any of these ways.\n\nWe have covered extensively first-order and second-order CT systems and seen how they can be represented variously as circuits, differential equations, block diagrams, and as frequency responses. We now see how they can describe simple filters and serve as building blocks for higher-order filters.\n\n\\begin{example} Consider a low-pass filter with the desired characteristics of having a pass-band of -3dB at 1kHz, and a stop-band of -20dB at 10kHz. Suppose this is implemented as a first-order \"Butterworth\" filter, which can be realized by an RC circuit.\n\\begin{center}\n  \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n    \\draw\n    (5,2.5) node[op amp, yscale=-1] (opamp1) {}\n    (0,3) to[R,l=$R$,o-] (opamp1.+)\n    (3,0) to[C, l=$C$] (3,3)\n    (0,0) to[short,o-o] (7,0)\n    (0,3) to[open, v=$x(t)$] (0,0)\n    (7.5,2.5) to[open, v=$y(t)$] (7.5,0)\n    (opamp1.-) |- (5,1) -| (opamp1.out)\n    (opamp1.out) to[short,-o] (7,2.5);\n  \\end{circuitikz}\n\\end{center}\n\n  where $R=99.2k\\Omega$ and $C=1.6$nF. This is equivalent to the differential equation\n  \\[\n  \\frac{dy}{dt}(t) + a y(t) = a x(t)\n  \\]\n  where $a=\\frac{1}{RC}$, or the block diagram\n  \\begin{center}\n  \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n    minimum height=2em, minimum width=2em]\n  \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n  \\tikzstyle{input} = [coordinate]\n  \\tikzstyle{output} = [coordinate]\n  \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n  \n  \\begin{tikzpicture}[auto]\n    \\node [input, name=input] at (0,0) {};  \t\n    \\node[block] at (4,-1) (block2) {$\\int$};\n\n    \\node [shape=coordinate, name=conn] at (4,0) {};\n    \\node [shape=coordinate, name=conn2] at (2,-2) {};\n    \\node [shape=coordinate, name=conn3] at (4,-2) {};\n    \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n    \\node [output, right of=conn3] (output) {};\n    \n    \\draw (sum) -- node {$a$} (conn);\n    \\draw (conn) -- (block2);\n    \\draw (block2) -- (conn3);\n    \\draw (conn3) -- (conn2);\n    \\draw [->] (conn2) -| node[pos=0.95] {$-$} (sum);\n    \\draw [draw,->] (input) -- node {$x(t)$} (sum);\n    \\draw [->] (conn3) -- node[pos=1] {$y(t)$} (output);\n  \\end{tikzpicture}\n  \\end{center}\n  \n  This system has the impulse response\n  \\[\n  h(t) = ae^{-at}u(t)\n  \\]\n  and the frequency response\n  \\[\n  H(j\\omega) = \\frac{a}{j\\omega + a}\n  \\]\n  If we plot the frequency response as a Bode plot, we see the DC gain is 0dB, and the response passes through -3dB and -20dB at the expected frequencies $2\\pi*1000 \\approx 6.3\\times 10^3$ rad/s and $2\\pi*10000 \\approx 6.3\\times 10^4$ rad/s. Thus the transition bandwidth is 9kHz. \n  \\begin{center}\n\\includegraphics[scale=0.7]{graphics/lecture24_1.png}\n  \\end{center}\n  \n\\end{example}\n\n\\begin{example} Suppose we wish to sharpen the transition band for the previous example so that has a pass-band of -3dB at 1kHz, and a narrower stop-band of -20dB at 5kHz. This requires a second-order filter, and can be realized by a circuit called the Sallen-Key.\n  \n  \\begin{center}\n    \\begin{circuitikz}[american voltages,scale=0.8, every node/.style={transform shape}]\n      \\draw\n      (7,3.5) node[op amp] (opamp1) {}\n      (0,4) to[R,l=$R_1$,o-] (2,4)\n      (2,4) to[short] (2,5)\n      (2,5) to[C,l=$C_1$] (8.2,5)\n      (8.2,5) to[short] (opamp1.out) \n      (2,4) to[R, l=$R_2$] (4,4)\n      (4,4) to[C, l=$C_2$] (4,0)\n      (0,0) to[short,o-o] (12,0)\n      (4,4) to[short] (opamp1.-)\n      (opamp1.+) to[short] (5.8,1.75)\n      (5.8,1.75) to[short] (8.2,1.75)\n      (opamp1.out) to[short] (8.2,1.75)\n      (opamp1.out) to[short, -o] (12,3.5)\n      (0,4) to[open, v=$x(t)$] (0,0)\n      (12,3.5) to[open, v=$y(t)$] (12,0);\n    \\end{circuitikz}\n  \\end{center}\n  where $R_1=74.2k\\Omega$, $R_2=91.3M\\Omega$, $C_1=1.6$nF and $C_2=160$pF. This is equivalent to the differential equation\n  \\[\n  \\frac{d^2y}{dt^2}(t) + 2\\alpha \\frac{dy}{dt}(t) + \\omega_0^2 y(t) = \\omega_0^2 x(t)\n  \\]\n  where\n  \\[\n  \\alpha = \\frac{R_1+R_2}{2R_1 R_2 C_1} \\;\\text{ and }\\; \\omega_0^2 = \\frac{1}{R_1 R_2 C_1 C_2}\n  \\]\n  or the block diagram\n  \\begin{center}\n    \\tikzstyle{block} = [draw, fill=gray!20, rectangle, \n      minimum height=2em, minimum width=2em]\n    \\tikzstyle{sum} = [draw, fill=gray!20, circle, node distance=1cm]\n    \\tikzstyle{input} = [coordinate]\n    \\tikzstyle{output} = [coordinate]\n    \\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]\n    \n    \\begin{tikzpicture}[auto]\n      \\node [input, name=input] at (0,0) {};\n      \\node [sum, right of=input,node distance=2cm] (sum) {$\\Sigma$};\n      \\node [sum, below of=sum,node distance=2cm] (sum2) {$\\Sigma$};\n      \\node[block] at (4,-1) (block3) {$\\int$};\n      \\node[block] at (4,-3) (block4) {$\\int$};\n      \n      \\node [shape=coordinate, name=conn1] at (4,0) {};\n      \\node [shape=coordinate, name=conn2] at (4,-2) {};\n      \\node [shape=coordinate, name=conn3] at (4,-4) {};\n      \\node [shape=coordinate, name=conn4] at (2,-4) {};\n      \\node [output, right of=conn3] (output) {};\n\n      \\draw [->] (input) -- node {$\\omega_0^2$} (sum);\n      \\draw (sum) -- (conn1);\n      \\draw [->] (conn1) -- (block3);\n      \\draw (block3) -- (conn2);\n      \\draw [->] (conn2) -- (block4);\n      \\draw [->] (conn2) -- node {$2\\alpha$} (sum2);\n      \\draw (block4) -- (conn3);\n      \\draw (conn3) -- node {$\\omega_0^2$} (conn4);\n      \\draw [->] (conn3) -| (sum2);\n      \\draw [->] (sum2) -- node[pos=0.95] {$-$} (sum);\n      \\draw [->] (conn3) -- node[pos=1] {$y(t)$} (output);\n      \\node at (-0.5,0) {$x(t)$};\n    \\end{tikzpicture}\n  \\end{center}\n  \n  This system has the frequency response\n    \\[\n  H(j\\omega) = \\frac{\\omega_0^2}{\\omega_0^2-\\omega^2 + j2\\alpha\\omega}\n  \\]\n\n  If we plot the frequency response as a Bode plot using the resistor and capacitor values above, we see the DC gain is 0dB, and the response passes through -3dB at the expected frequency $2\\pi*1000 \\approx 6.3\\times 10^3$ rad/s. At the frequency $2\\pi*5000 \\approx 3.14\\times 10^4$ rad/s the response passes through about -28dB. Thus this circuit has a transition bandwidth even narrower than that designed (it is slightly better). \n  \\begin{center}\n    \\includegraphics[scale=0.7]{graphics/lecture24_2.png}\n  \\end{center}\n  Note the price we pay for this decreased transition bandwidth is a larger phase shift (and a two more components).\n\\end{example}\n\n\\section{Higher-Order Filters}\n\nWe can continue to increase the steepness of the passband to stop-band transitions by increasing the order of the filter. This is typically accomplished using a serial connection of systems, called \\emph{stages} in filter parlance, where each stage is a first-order or second-order system.\n\nRecall in a series connection of systems the overall impulse response is the convolution of the individual responses. If  we assume each stage is stable then, by the convolution property, the overall frequency response is given by the product of their individual frequency responses.\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(j\\omega)$};\n    \\node [block, right of=system1,node distance=4cm] (system2) {$H_2(j\\omega)$};\n    \\node [output, right of=system2] (output) {};\n    \\node [right of=output,node distance=1cm] {$Y(j\\omega)$};\n    \\node [left of=input,node distance=1cm] {$X(j\\omega)$};\n    % Once the nodes are placed, connecting them is easy. \n    \\draw [->] (input) -- (system1);\n    \\draw [->] (system1) -- (system2);\n    \\draw [->] (system2) -- (output);\n\\end{tikzpicture}\n\\end{center}\n\n\\[\nH(j\\omega) = \\frac{Y(j\\omega)}{X(j\\omega)} = H_1(j\\omega)\\cdot H_2(j\\omega)\n\\]\n\nWriting each response in polar form\n\\[\nH_1(j\\omega)\\cdot H_2(j\\omega) = |H_1(j\\omega)|\\cdot |H_2(j\\omega)| e^{\\angle H_1(j\\omega)+ \\angle H_2(j\\omega)}\n\\]\nwe note that the magnitudes multiply and the phases add. That means we can use additional stages to reinforce the attenuation of previous stages. Note this requires in the circuit that the stages be impedance isolated, thus the use of the opamps at the end of CT filters. Again the price we pay for increasing the order of the filter and decreasing the transition frequency is increased phase shift in the signal.\n\n\\newpage\nMatlab code for plotting the first-order example Bode plot:\n\\begin{verbatim}\nR = 99.2e3;\nC = 1.6e-9;\na = 1/(R*C);\n\nH = tf([a],[1,a]);\n[mag,ph,w] = bode(H);\n\n% Create a nice bode plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = semilogx(w,20*log10(squeeze(mag)));\ngrid on;\nhTitle  = title ('Frequency Response - first order');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, 'YTick', -60:10:20, ...\n    'Box', 'off', 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = semilogx(w,squeeze(ph*(pi/180)));\ngrid on;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/s)');\nset(gca, 'FontSize', 14, 'Box', 'off', 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\n\n\\newpage\nMatlab code for plotting the second-order example Bode plot:\n\\begin{verbatim}\nR1 = 74.2e3;\nR2 = 1.33e6;\nC1 = 1.6e-9;\nC2 = 160e-12;\n\na = (R1+R2)/(R1*R2*C1);\nb = 1/(R1*R2*C1*C2);\n\nH = tf([b],[1,a,b]);\n[mag,ph,w] = bode(H);\n\n% Create a nice bode plot \nhFig = figure();\nhold on;\n\nsubplot(2,1,1);\nhm = semilogx(w,20*log10(squeeze(mag)));\ngrid on;\nhTitle  = title ('Frequency Response - second order');\nhYLabel1 = ylabel('Magnitude (dB)');\nset(gca, 'FontSize', 14, 'YTick', -90:10:20, ...\n    'Box', 'off', 'LineWidth', 2);\n\nsubplot(2,1,2);\nhp = semilogx(w,squeeze(ph*(pi/180)));\ngrid on;\nhYLabel2 = ylabel('Phase (radians)');\nhXLabel = xlabel('Frequency (rad/s)');\nset(gca, 'FontSize', 14, 'Box', 'off', 'LineWidth', 2);\n\nset(hm, 'linewidth', 2);\nset(hp, 'linewidth', 2);\n\nset([hXLabel, hYLabel1, hYLabel2]  , ...\n     'FontSize'   , 14          );\nset( hTitle                    , ...\n     'FontSize'   , 14          , ...\n     'FontWeight' , 'bold'      );\n\\end{verbatim}\n", "meta": {"hexsha": "30fa317967e8fb04aaabc96916fca5af22cb018f", "size": 18179, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "20-ct-filters.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "20-ct-filters.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "20-ct-filters.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 49.6693989071, "max_line_length": 740, "alphanum_fraction": 0.6805104791, "num_tokens": 5693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8688267864276108, "lm_q1q2_score": 0.7708271134718624}}
{"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 $T$ is a rooted tree with root $r$ and $x \\neq r$ is a vertex in $T$.\nFurther, suppose $a$ and $b$ are both ancestors of $x$.\nAnd to make things simple, suppose that $a \\neq b$.\nProve that either $a$ is an ancestor of $b$ or $b$ is an ancestor of $a$.\n\n\\subsection*{Solution}\n\nProof is given by contradiction.\nAssume distinct nodes $a$ and $b$ have no ancestorhood relationship.\nSince they are ancestors of $x$ however, there exists a path of the form $r \\rightarrow \\cdots \\rightarrow a \\rightarrow \\cdots \\rightarrow x$ that does not pass node $b$.\nSimilarly, there exists a path of the form $r \\rightarrow \\cdots \\rightarrow b \\rightarrow \\cdots \\rightarrow x$ that does not pass from node $a$.\nThis leads to a simple loop of the form $r \\rightarrow \\cdots \\rightarrow b \\rightarrow \\cdots \\rightarrow x \\rightarrow \\cdots \\rightarrow a \\rightarrow \\cdots \\rightarrow r$ which contradicts definition of the tree.\nTherefore initial assumption does not hold true and any path of the form $r \\rightarrow \\cdots \\rightarrow a \\rightarrow \\cdots \\rightarrow x$ would pass node $b$ at some point.\nHence either $a$ is an ancestor of $b$ or $b$ is an ancestor of $a$ and the proof is complete.\n", "meta": {"hexsha": "3091c35d0bdfda79c21267afca8b29e54a57c085", "size": 1575, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q07.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/hw03q07.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/hw03q07.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": 65.625, "max_line_length": 217, "alphanum_fraction": 0.6831746032, "num_tokens": 406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.7708271087697603}}
{"text": "\\lab{Statistical Distributions}{Statistical Distributions}\n\\label{lab:distributions}\n\\objective{This section will review the most common distributions and thus assumes prior exposure to basic terms and concepts.}\n\n\\section*{Discrete Distributions}\n\\emph{Discrete distributions} are distributions whose support is finite or countable at most. \nThe \\emph{support} of a distribution refers to the points in $\\mathbb{R}$ that have non-zero probability. \nIn other words, discrete distributions are a collection of point masses. \n\n\\begin{table*}[h]\n\\centering\n\\begin{tabular}{|c|c|c|c|}\n\t\\hline\n & Uniform &  Binomial & Poisson \\\\\n\\hline \n\\hline\nSupport&$x \\in \\{a,\\dots,b\\}$&$x \\in \\{0,\\dots,n\\}$&$x \\in \\{0,1,2,\\dots\\}$\\\\ \\hline\nPMF&$\\frac{1}{b-a+1}$&$\\dbinom{n}{x}p^x(1-p)^{n-x}$&$\\frac{e^\\lambda \\lambda^x}{x!}$\\\\ \\hline\nParameters&$b>a$, $a,b \\in \\mathbb{Z}$&$n \\in \\mathbb{N}$, $p \\in [0,1]$& $\\lambda>0$\\\\ \\hline\nMean $E(X)$&$\\frac{a+b}{2}$&$np$& $\\lambda$\\\\ \\hline\nVariance&&$np(1-p)$& $\\lambda$\\\\ \\hline\nDescription& \n\\parbox{1in}{models a single occurrence of one of several events of equal probability} & \\parbox{1in}{models $n$ events with binary outcomes, where $p$ is the probability of a success ($x=1$). Note, when $n=1$, this is referred to as the Bernoulli distribution, or a Bernoulli trial.}&\\parbox{1in}{models the number of events that occur in a given time period, given rate $\\lambda$}\\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\n\\section*{Continuous Distributions}\n\\emph{Continuous distributions} are distributions whose support is uncountable, i.e. some subset of $\\mathbb{R}$. \n\\begin{table*}[h]\n\\centering\n\\begin{tabular}{|c|c|c|c|}\n\t\\hline\n & Normal& Gamma&Beta\\\\ \\hline \\hline\nSupport &$x \\in \\mathbb{R}$ & $x>0$ &$x \\in [0,1]$\\\\  \\hline\nPDF & $\\frac{1}{\\sqrt{2\\pi \\sigma^2}} e^{-\\frac{1}{2\\sigma^2}(x-\\mu)^2}$ & $\\frac{\\beta^\\alpha}{\\Gamma(\\alpha)} x^{\\alpha -1} e^{-\\beta x}$ &$\\frac{\\Gamma(\\alpha+\\beta)}{\\Gamma(\\alpha)\\Gamma(\\beta)} x^{\\alpha-1} (1-x)^{\\beta-1}$\\\\  \\hline\nParameters & $\\mu \\in \\mathbb{R}$, $\\sigma^2 > 0$ & $\\alpha,\\beta>0$ &$\\alpha,\\beta>0$\\\\  \\hline\nMean &  $\\mu$& $\\frac{\\alpha}{\\beta}$ &$\\frac{\\alpha}{\\alpha + \\beta}$\\\\  \\hline\nVariance &$\\sigma^2$& $\\frac{\\alpha}{\\beta^2}$&$\\frac{\\alpha \\beta}{(\\alpha + \\beta)^2(\\alpha + \\beta +1)}$\\\\ \\hline\nDescription&The bell curve&\\parbox{1in}{When $\\alpha=1$, this is called the exponential distribution. $\\alpha$ is called the shape, $\\beta$ is called the rate.}&\\parbox{1in}{models probabilities or proportions. When $\\alpha = \\beta =1$, this is called the continuous uniform distribution}\\\\\n\\hline\n\\end{tabular}\n\\end{table*}\n\n\\section*{Normal Distribution}\nThe SAT is a standardized test common for college admissions in the United States. \nIt is comprised of three sections, critical reading, writing and mathematics. \nEach section is graded out of 800 possible points, with a minimum score of 200.\nEach section is intended to have a mean score of 500 with a standard deviation of 100.  \nThe distribution of SAT section scores is well approximated by the normal distribution \n(though these scores are discrete and to the nearest 10, i.e. $\\mbox{score} \\in \\{200,210,220,\\dots,790,800\\}$, we are only approximating it). \n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{normaldist.pdf}\n\\end{figure}\n\nThe scores of the three sections are added together to produce the test score. \nThus the test in aggregate has 2400 possible points and a minimum score of 600.  \nAs each of the three sections has a mean score of 500 and a standard deviation of 100, it seems logical that the test score would also has a normal distribution, \nbut with mean of 1500 points and a standard deviation of 300 points. \nBut is that true? One method of evaluating this is to simulate the test scores and then find the mean and standard deviation of our simulated data. \nNumPy provides a tool to generate random data from the normal distribution, numpy.random.normal.\n\n\\begin{problem}\nGenerate 10,000 random test scores by adding together three vectors of 10,000 random draws from the $N(\\mu=500,\\sigma=100)$ distribution. \nFind the mean and standard deviation of the 10,000 test scores. \nAre they close to 1500 and 300, respectively? \nAlso, make a histogram of the test scores to visually inspect for whether or not the test scores are also normally distributed.\n\\label{prob:randomTests}\n\\end{problem}\n\n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{scorehist.pdf}\n\\caption{Histogram of the simulated test scores.}\n\\end{figure}\nIn the plot above, we see that the the 10,000 randomly generated test scores appear to be fairly bell-shaped, i.e. normally distributed. \nThe mean of these test scores should, in fact, be about 1500. \nHowever, the standard deviation is not $3(100) = 300$, but around 173.2, or $\\sqrt{3*100^2}=\\sqrt{3}(100) \\approx 173.205081$. \nThis is because, for independent normal random variables $X_1 \\sim N(\\mu_1,\\sigma^2_1), X_2 \\sim N(\\mu_2,\\sigma^2_2),X_3 \\sim N(\\mu_3,\\sigma^2_3),$\n\\[ (X_1 +X_2 +X_3) \\sim N(\\mu_1+\\mu_2+\\mu_3, \\sigma^2_1+\\sigma^2_2+\\sigma^2_3). \\]\nSaid succinctly, the mean of the sum is the sum of the means, and the variance of the sum is the sum of the variances. \nBut as the standard deviation is the square root of the variance, this same idea doesn't work. \nYet we do see that the standard deviation of the sum is the square root of the sum of the variances (the new variance):\n\\[ \\sqrt{100^2+100^2+100^2} = \\sqrt{30000} \\approx 173.205081 \\]\n\n\\section*{Multivariate Normal Distribution}\nNote that in problem \\ref{prob:randomTests}, we assumed that the scores of all three tests were independent. \nThis should seem like an unreasonable assumption, because we expect there to be at least a little correlation in the test scores, \ni.e. a student with a high reading score is more likely to score high on the other sections compared to a student with a low reading score. \nTo employ correlations in these draws, we turn to the multivariate normal distribution. \n\\begin{table*}[h]\n\\centering\n\\begin{tabular}{|c|c|}\n\\hline\n&Multivariate Normal distribution  \\\\ \\hline \\hline\nSupport &$\\mathbf{x} \\in \\mathbb{R}^k$ \\\\ \\hline\nPDF & $(2\\pi)^{-k/2}|\\Sigma|^{-1/2}e^{-\\frac{1}{2}(\\mathbf{x} - \\mathbf\\mathbf{\\mu})^T \\Sigma^{-1} (\\mathbf{x}-\\mathbf{\\mu})}$ \\\\ \\hline\n Parameters&$\\mathbf{\\mu}\\in \\mathbb{R}^k, \\Sigma \\in \\mathbb{R}^{k\\times k}$ \\\\ \\hline\n\\end{tabular}\n\\end{table*}\nNote that there is no mean and variance included above. \nSimilar to the normal distribution, they are simply $\\mu$ and $\\Sigma$ respectively. Also note that for $k=1$, this is the normal distribution.  \nFurthermore, this distribution can be viewed as having $k$ components, each of which is normally distributed. \nThus, $\\mathbf{\\mu}$ is a vector of the means of each of these normal distributions. \nSimilarly, the diagonal of the matrix $\\Sigma$ are the variances of the $k$ components. \nThe off-diagonal elements of $\\Sigma$ are covariances, or in other words, $\\Sigma_{i,j} = Cov(x_i,x_j) = \\sigma_i \\sigma_j \\rho_{ij}$, where $\\rho_{ij}$ is the correlation between $x_i$ and $x_j$. \nHence, for $i=j$, $\\Sigma_{i,j} = \\sigma^2_i$ as the correlation between an object and itself is 1. \n\nReturning to our SAT example, we can use the multivariate normal distribution with $k=3$. \nBecause each distribution of section scores has a mean of 500 and a variance of 10,000, $\\mathbf{\\mu} = (500,500,500)$ and $\\Sigma_{1,1} = \\Sigma_{2,2} = \\Sigma_{3,3} = 10,000$. \nNow let's assume the correlation between the reading and writing sections is $.7$, and the others are $.5$. \nThis means for $\\mathbf{x} = (x_{\\text{math}},x_{\\text{read}},x_{\\text{write}})$\n\\[ \\Sigma =  \\begin{bmatrix*}\n10000 & 5000 & 5000 \\\\\n5000 & 10000 & 7000 \\\\\n5000 & 7000 & 10000 \\end{bmatrix*} \\]  \n\n\\begin{problem}\nUsing the above $\\mathbf{\\mu}$ and $\\Sigma$, generate 10,000 random test scores by adding together the vectors created by 10,000 random draws from the \n\\li{numpy.random.multivariate_normal} function. \nFind the mean and standard deviation of the 10,000 test scores and make a histogram of the test scores to visually \ninspect for whether or not the test scores are also normally distributed. \nWhich of the models discussed appears to be more appropriate?\n\\end{problem}\n\nNote that the mean of the generated scores should be around 1500 and the standard deviation $\\sqrt{64000} \\approx 253$. \nNote that 64,000 is the sum of all elements in $\\Sigma$, however the explanation is beyond the scope of this lab. \n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{scorehist-mvn.pdf}\n\\caption{Histogram of the simulated test scores, generated via the multivariate normal distribution.}\n\\end{figure}\n\n\n\\section*{Central Limit Theorem}\nThe Central Limit Theorem, simply stated, says that for independently and identically distributed random variables, $X_i$ , $i = 1, \\dots, n$, as $n \\rightarrow \\infty$,\n\\[ \n\\frac{1}{n} \\sum^n_{i=1} X_i = \\bar{x}_n \\sim N\\left(E(X), \\frac{Var(X)}{n}\\right)\n\\]\nIn other words, for a large enough sample size, the sample mean is approximately normally distributed. \n\\begin{figure}[h]\n\\includegraphics[width=\\textwidth]{multiplot.pdf}\n\\caption{A histogram of the means of 10,000 samples of size 10, 20, and 30 respectively, from the Exponential(1) distribution (same as the Gamma(1,1) distribution). Notice that as $n$ increases, it leaves the shape of the original distribution (exponential) and becomes more and more bell-curve-shaped.}\n\\label{fig:CLT}\n\\end{figure}\n\n\\begin{problem}\nCreate plots similar to \\ref{fig:CLT} for the Poisson(3), Beta(.1,.1), Uniform(0,10), Normal($\\mu=0$, $\\sigma^2=100$), Gamma($\\alpha = 2$, $\\beta = 3$), and the Binomial($n=20$, $p=.8$). Notice how the discrete distributions appear ``more continuous'' as $n$ grows, due to more values being possible. \n\\end{problem}\n", "meta": {"hexsha": "9bc048a2fa441cd5e9341bde226c779df096a1c6", "size": 9797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Distributions/Distributions.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/Distributions/Distributions.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/Distributions/Distributions.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": 66.1959459459, "max_line_length": 384, "alphanum_fraction": 0.7233847096, "num_tokens": 2945, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045907347108, "lm_q2_score": 0.8688267745399466, "lm_q1q2_score": 0.7708271029250722}}
{"text": "\\section*{Problem 3 Solution}\n\nWe need to find the minimum required volume of UO$_2$, $V$, so let's begin by expressing that volume of UO$_2$ in terms of the number of UO$_2$ molecules it contains. \n\nFirst, we use $M_{\\text{UO}_2}$ as the total mass of UO$_2$ and $\\rho_{\\text{UO}_2}$ as the density of UO$_2$ (about 10.41 g/cm$^3$ for our purposes)\n$$ V = \\frac{M_{\\text{UO}_2}}{\\rho_{\\text{UO}_2}} $$\nThen, we can write the mass of UO$_2$ as the number of UO$_2$ molecules, $N_{\\text{UO}_2}$, times the mass of a UO$_2$ molecule, $m_{\\text{UO}_2}$. Since we know that the UO$_2$ is enriched such that 3\\% of the molecules contain $^{235}$U, we can say $m_{\\text{UO}_2} = 0.03m_{\\text{U5}} + 0.97m_{\\text{U8}} + 2m_{\\text{O}}$. Then\n$$ M_{\\text{UO}_2} = N_{\\text{UO}_2}(0.03m_{\\text{U5}} + 0.97m_{\\text{U8}} + 2m_{\\text{O}}) $$\nWe can use this equality in our total volume equation to find\n\\begin{equation}\n\\label{vol}\nV = \\frac{N_{\\text{UO}_2}(0.03m_{\\text{U5}} + 0.97m_{\\text{U8}} + 2 m_{\\text{O}})}{\\rho_{\\text{UO}_2}}\n\\end{equation}\nNow we need to relate this volume, in terms of number of UO$_2$ molecules, to the electric power produced by the reactor. Say $P_E$ is the electric power, $P_T$ is thermal power, and $\\varepsilon$ is the efficiency. \n$$ P_E = \\varepsilon P_T $$\nThe total energy produced by the reactor in time $t$ can be found by simply multiplying the power by the time of production.\n$$ E = P_T t $$\nor equivalently\n$$ P_T = \\frac{E}{t} .$$\nThe energy from one fission is $E_f$ and the energy harnessed from one fission is $0.95E_f$. The total energy harnessed can then be expressed in terms of the number of fissions, $N_f$ and the energy captured per event,\n$$ E = 0.95E_f N_f $$\nIf we consider the extreme and highly unrealistic case that \\textit{all} $^{235}$U atoms fission, then the number of $^{235}$U atoms required is $N_{\\text{U5}} = N_f$. Since $^{235}$U is 3\\% of the total uranium by atom, then $N_{\\text{U5}} = 0.03N_{\\text{U}}$. Taking this one step further, there is a one-to-one ratio of uranium atoms to UO$_2$ molecules, so $N_{\\text{U}} = N_{\\text{UO}_2}$.\n\nWe combine these facts together to relate the electric power produced to the number of uranium dioxide molecules required.\n\\begin{align*} \nP_E\t&= \\varepsilon P_T \\\\\n\t&= \\varepsilon \\frac{E}{t} \\\\\n\t&= \\frac{0.95\\varepsilon E_f N_f}{t} \\\\\n\t&= \\frac{(0.95)(0.03)\\varepsilon E_f N_{\\text{UO}_2}}{t} \\\\\n\\end{align*}\nWe solve for $N_{\\text{UO}_2}$ to get\n\\begin{equation}\n\\label{num}\nN_{\\text{UO}_2} = \\frac{P_E t}{(0.95)(0.03)\\varepsilon E_f}\n\\end{equation}\n\nNow, we use equation (\\ref{num}) for the number of UO$_2$ molecules required for the given power in equation (\\ref{vol}) for the volume of UO$_2$ required. We find\n$$ V = \\frac{P_E t(0.03m_{\\text{U5}} + 0.97m_{\\text{U8}} + 2 m_{\\text{O}})}{(0.95)(0.03)\\varepsilon E_f\\rho_{\\text{UO}_2}} $$\nFinally, we can include our values. We note the following\n\\begin{itemize}\n\\item $P_E = 1000\\text{ MWE} = 10^9\\text{ J/s}$\n\\item $t = 1\\text{ yr} = 31,557,600\\text{ s}$\n\\item $E_f = 200\\text{ MeV} = 3.204 \\times 10^{-11}$ J\n\\item $m_{\\text{U5}} = 235.044\\text{ amu} = 3.9028 \\times 10^{-22}$ g\n\\item $m_{\\text{U8}} = 238.051\\text{ amu} = 3.9528 \\times 10^{-22}$ g\n\\item $m_{\\text{O}} = 15.995\\text{ amu} = 2.656 \\times 10^{-23}$ g\n\\end{itemize}\n$$ V = \\frac{(10^9\\text{ J/s})(31557600\\text{ s})(0.03(3.9028 \\times 10^{-22}\\text{ g}) + 0.97(3.9528 \\times 10^{-22}\\text{ g}) + 2(2.656 \\times 10^{-23}\\text{ g}))}{(0.95)(0.03)(0.33)(3.204 \\times 10^{-11}\\text{ J})(10.41\\text{ g/cm}^3)} $$\n$$\\boxed{ V = 4.51\\text{ m}^3 }$$\n\n", "meta": {"hexsha": "1869a264b9df52be912b7ffae1695b5050582c23", "size": 3567, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc02/disc02_solution03.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/disc02/disc02_solution03.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/disc02/disc02_solution03.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": 69.9411764706, "max_line_length": 394, "alphanum_fraction": 0.6582562377, "num_tokens": 1423, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505402422644, "lm_q2_score": 0.8519528038477825, "lm_q1q2_score": 0.7707195642618083}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\section{Discrete-time stability as an autocovariance}\nThe stability criterion is based on the two-way relationship between graphs and Markov chains: On one hand, any graph has an associated Markov chain where the states are the nodes of the graph and the transitions probabilities between states are given by the weights of the edges. On the other hand, any Markov chain can be represented by a graph whose edges are weighted according to the transition probabilities. Concretely, consider a graph of $n$ nodes whose $n \\times n$ weighted adjacency matrix is denoted $\\b A$. Let $\\b q = \\b A \\b 1$; $q_i$ is thus the total weight of the outgoing edges from node $i$. Let $\\b Q = \\mathrm{diag}(\\b q)$. Then, by normalizing the rows of $\\b A$ we get the matrix $\\b M = \\b Q^{-1}\\b A$, the transition probability matrix. $\\b M$ is row-stochastic (or right-stochastic) and $[\\b M]_{ij}$ is the probability to go from node $i$ to node $j$. \nConsider a particle moving in the network according to the transition probabilities in $\\b M$. Now let $\\b p_t$ be the $1 \\times n$ probability vector at Markov time $t$, namely that $p_{t,i}$ is the probability that the particle is located in node $i$ at time $t$. The dynamics of the discrete-time Markov process are given by :\n\\begin{equation} \\label{eq:discreteMP}\n\t\\b p_{t+1} = \\b p_t \\b K^{-1}\\b A = \\b p_t \\b M.  \t\n\\end{equation} \nNow, suppose that the Markov chain is ergodic, i.e. that it is possible to go from every state to every state and that the Markov process is aperiodic. The ergodicity assumption implies that any initial state will asymptotically reach the same stationary solution. Let $\\bs \\pi$ be that stationary distribution, obtained by solving $\\bs \\pi = \\bs \\pi \\b M$, and $\\b \\Pi = \\rm{diag}(\\bs \\pi)$. Now, let $\\b x_t$ be the $n$-dimensional random indicator vector describing the position of a particle undergoing the above dynamics: $x_{t,i} = 1$ if the particle is located in node $i$ at time $t$, and $0$ otherwise. At stationarity, the \\textit{autocovariance matrix} of $\\b x$ is\n\\begin{subequations}\n\t\\begin{align}\n \t\\b C(\\b x_{t_0},\\b x_{t_0+t}) &\\triangleq \\E\\left[(\\b x_{t_0} - \\E[\\b x_{t_0}])^{\\t}(\\b x_{t_0+t} - \\E[\\b x_{t_0+t}])\\right] \\\\\n \t\t&= \\E\\left[(\\b x_{t_0} - \\bs \\pi)^{\\t}(\\b x_{t_0+t} - \\bs \\pi)\\right] \\\\\n \t\t&= \\E\\left[\\b x_{t_0}^{\\t} \\b x_{t_0+t}\\right] - \\E[\\b x_{t_0}^{\\t}] \\bs \\pi - \\bs \\pi^{\\t} \\E\\left[\\b x_{t_0+t}\\right] + \\bs \\pi^{\\t} \\bs \\pi \\\\\n \t\t&= \\bs \\Pi \\b M^t - \\bs \\pi^{\\t} \\bs \\pi,\n \t\\end{align}\n\\end{subequations}\nwhere the fact that $\\b C(\\b x_{t_0},\\b x_{t_0+t})$ only depends on the time difference $t$ at stationarity is readily verified. Here, $^\\t$ is the transposed sign and $\\b M^t$ is $\\b M$ at the power $t$. $[\\b C(\\b x_{t_0},\\b x_{t_0+t})]_{ij}$ is interpreted as the correlation between $\\b x_{t_0,\\,i}$ and $\\b x_{t_0+t,\\,j}$. The independence on the initial time $t_0$ implies that it can indifferently be chosen equal to $0$.\n\nSuppose now a partition $\\P$; we note $\\b H_{\\P}$ the indicator matrix of $\\P$. If $c$ is the number of communities in $\\P$, $\\b H_{\\P}$ is a binary $n \\times c$ matrix such that \n\\begin{equation}\n\t[\\b H_{\\P}]_{ik} = \n\t\\begin{cases}\n\t\t1  & \\quad \\mbox{if node $i$ is in community $k$},\\\\\n\t    0  & \\quad \\text{otherwise}.\\\\\n\t\\end{cases}\n\\end{equation}\nLet us define $\\mathcal{H}_{\\P} : \\R[n \\times n] \\rightarrow \\R[c \\times c] : \\b B \\mapsto \\mathcal{H}_\\P(\\b B) = \\b H_{\\P}^{\\t} \\b B \\b H_{\\P}$. Let $\\b X$ be any $n \\times n$ matrix, then $\\b Y = \\mathcal{H}_{\\P}(\\b X)$ is a $c \\times c$ matrix such that \n\\begin{equation}\n\t[\\b Y]_{kl} = \\sum_{i \\in \\C_k} \\sum_{j \\in \\C_l} [\\b X]_{ij},\t\n\\end{equation}\nwhere $\\C_k$ and $\\C_l$ denote communities $k$ and $l$ of partition $\\P$. One could thus say that operator $\\mathcal{H}_{\\P}$ returns the \\textit{clustered version} of any $n \\times n$ matrix, namely the matrix where the contributions of every nodes belonging to the same community are gathered by summing them. Finally, let $\\b y_t = \\b H_{\\P}^{\\t} \\b x_t$ denote the $c$-dimensional community indicator vector: $\\b y_{t,\\,k}$ is equal to $1$ if the particle is in community $k$ at time $t$ and zero otherwise.\nUsing those notations and the interpretation of $\\mathcal{H}_{\\P} $, the \\textit{clustered autocovariance matrix} for partition $\\P$ at time $t$ is defined as\n\\begin{subequations}\n\t\\begin{align}\n\t\t\\b R_t(\\P) &= \\mathcal{H}_{\\P}\\left(\\b C(\\b x_{t_0},\\b x_{t_0+t})\\right)\\\\\n\t\t\t&= \\b C(\\b y_{t_0},\\b y_{t_0+t})\\\\\n\t\t\t&= \\b H_{\\P}^{\\t}(\\b \\Pi\\b M^t - \\bs \\pi^{\\t}\\bs \\pi)\\b H_{\\P}.\n\t\\end{align}\n\\end{subequations}\nNotice that $\\b R_t$ depends only on the topology of the graph and on the partition. If the graph has well defined communities given by $\\P$ \\textit{over a given time scale}, we expect that the particle is more likely to remain within the starting community over that time scale. This implies that the values of $\\b y_{0,\\,i}$ and $\\b y_{t,\\,i}$ are positively correlated for $t$ in that time scale, which in turn implies large diagonal elements in $\\b R_t(\\P)$ and hence a large trace of $\\b R_t(\\P)$. The elements of $\\b R_t(\\P)$ are interpreted as follows in terms of the random walk of a particle: $[\\b R_t(\\P)]_{kl}$ is the probability that a particle is in community $\\C_l$ after $t$ discrete time-steps if it has started in $\\C_k$ minus the probability that two independent random walkers are in $\\C_k$ and $\\C_l$, evaluated at stationarity. A good partition is such that there is a high likelihood of remaining in the starting community over a given time scale. The definition of the stability of a \\textit{clustering} $\\P$ follows naturally:\n\\begin{equation}\n\tr_t(\\P) = \\min_{0 \\le s \\le t} \\sum_{i = 1}^{c} [\\b R_s]_{ii} = \\min_{0 \\le s \\le t} \\trace(\\b R_s).\n\\end{equation}\nNote that taking the minimum for all times up to $t$ implies that the stability of the clustering at time $t$ is large only if it is large for all times preceding $t$. This allows to assign a low stability to partitions where there is a high probability of leaving the community and coming back to it later. According to \\cite{delvenne2013stability}, this minimization is unnecessary in most cases and we have $r_t(\\P) \\approx \\trace(\\b R_t)$. Nevertheless, taking the minimization ensures maximum generality and allows for example to deal with almost bipartite graphs where $\\trace(\\b R_s)$ can be oscillatory.\n\nAll the definitions introduced until now are for a given partition $\\P$. But what we ultimately want to compute is the optimal partition in the sense of stability, hence the one that maximizes the stability measure. Clearly, the optimal partition might be different for each Markov time $t$. Computing the optimal clustering for each Markov time gives the \\textit{stability curve of the graph} :\n\\begin{equation}\n\tr_t = \\max_{\\P} r_t(\\P).\n\\end{equation}\nNow we understand how Markov time acts as an intrinsic resolution parameter: as Markov time grows, the number of communities is expected to decrease, since there are more possibilities for a random walker to escape a community when the time window increases. Hence, communities get bigger (or coarser) as Markov time increases. Interestingly, one can prove that in the case of \\textit{undirected} networks, stability at time 1 is equivalent to the well-known \\textit{configuration modularity} measure. But this equivalence does not hold for \\textit{directed} networks and therefore does not concern the present work.\n\nAt this stage, an important remark has to be made about the assumption of ergodicity. The verification of this assumption is often far from being obvious, especially in the case of big undirected networks. The trick in that case is to introduce \"à la Google\" random teleportations.\\footnote{In the original PageRank proposed by S. Brin and L. Page in 1998 (ref. \\cite{grin1998anatomy}), this consists essentially in applying a perturbation to the transition probability matrix between web pages in order to ensure that at least one row of the matrix is positive, which implies the convergence of the Power Method. If we note the teleportation probability $\\tau$, the perturbation can be interpreted as follows: a web surfer follows a link in his current page with probability $1-\\tau$ and jumps to an arbitrary web page with probability $\\tau$.} Let $\\tau$ be the \\textit{teleportation probability}. Then, if a random walker is located on a node with at least one outlink (which is always the case for the networks that we will consider), it follows one of the outlinks with probability $1-\\tau$. Otherwise, the node is called a \\textit{dangling node} and the random walker is teleported with a uniform probability to another random node. The corresponding perturbation of the transition probability matrix is, in the most general case:\n\\begin{equation} \\label{eq:M_teleport}\n\t\\widetilde{\\b M} = (1-\\tau)\\b M + \\frac{1}{n}[(1-\\tau)\\b d + \\tau \\b 1]\\b 1^{\\t},\n\\end{equation}\nwhere $n$ is the number of nodes, $\\b d$ is a binary $n \\times 1$ vector whose entries are equal to $1$ if the corresponding node is a dangling node and $0$ otherwise, and $\\b 1$ is the $n \\times 1$ unity vector. In the case that we will consider in the next section, $\\b d$ is the zero vector. This perturbation is known to make the dynamics ergodic, ensuring the existence and uniqueness of the stationary solution $\\bs \\pi$.", "meta": {"hexsha": "1c0357c096cadf50d0b59cf1b3ad5d5076508b9f", "size": 9407, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/clustering/discretetime.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/discretetime.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/discretetime.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": 167.9821428571, "max_line_length": 1336, "alphanum_fraction": 0.718188583, "num_tokens": 2797, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7707195552706433}}
{"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]{article}\n\\usepackage{mathtools}\n\\begin{document}\nThis paper outlines the mathematical model that describes sound propagation \nwithin a duct. This is commonly used as the starting basis for predicting \nturbomachinery duct noise. The goal of this document is check equation (4.1) \nin Kousen's work \\cite{Kousen1999} which was obtained from \\cite{Kerrebrock1992}.\nFirst, we will derive the analytical solution to the wave equation obtained \nfrom the linearized Euler equations. This will provide a useful background by\nshowing why the Bessel's Function's zero crossing is needed to determine the \nsolution. Spolier, it is because the wave equation can be simplified to be\nof the same form as Bessel's (Differential) Equation. \n\n\\section{}\n\nThe equation presented in Kousen's work\n\n\\begin{equation}\n    \\gamma_{acoustic} = \n    - \\frac{k M_x}{1 - M_x^2} \\pm \n    \\frac{1}{1-M_x^2} \n    \\sqrt{k^2 + (M_x^2-1) \\kappa_{m \\mu}^2}\n    \\label{eqn:4_1}\n\\end{equation}\n\nwhere $\\kappa _{m \\mu}$ is a ``separation constant for the $m^{th}$ \ncircumferential and $\\mu^{th}$ radial mode in the solution of the convected \nwave equation.\n\nIt is not clear where to find the values of separation constants needed to \ncalculate the analytical solution for a uniform flow. In order to check \nthis work, this should be further documented. Although values of $\\kappa$ are \nnot listed in Kousen's paper \\cite{Kousen1999}, the reference [44] in \\cite{Kousen1999}\n(\\cite{Kerrebrock1992}), defines the separation constant as $\\mu $\n\nThe pressure fluctuations are governed by the wave equation derived from the\nradial linearized euler equation,\n\n\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*} \n\nIf we assume that the pressure fluctuation is \n\n\n\\begin{equation}\n    \\tilde{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\nThen the radial dependence is governed by,\n\n\n\\begin{align*}\n    \\frac{ d^2 \\tilde{p}}{d r} +\n    \\frac{1}{r} \n    \\frac{d \\tilde{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]\\tilde{p}\n\\end{align*}\n\nApplying algebraic jujitsu, this can be simplified, let's define a new variable,\n$N$\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\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 = 0\n\\end{align*}\n\nLooking at the radial wavenumber,\n\n\\begin{align*}\n    k_r^2 &= k^2 - N^2 \\\\\n          &= k^2-(1 - M^2)^2 k_x^2 - 2 k k_x M_x \\\\\n    0 &=  -(1 - M^2) ^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, which matches\nthe definition of the constant $\\mu$,\n\n\\begin{equation}\n    (\\mu )^2 = -(1 - M^2) k^2 - 2 M \\omega k / A_T + \\left( \\omega/A_T \\right)^2\n    \\label{<+label+>}\n\\end{equation}\n\n\n\nApplying the quadratic formula and taking \n\n\\begin{align*}\n    A &= - \\beta^2 \\\\\n    B &= - 2M_x k\\\\\n    C &= k^2 - k_2^2\n\\end{align*} \n\nNote B is negative when $M_x$ is positive,\n\n(I feel like N should change based on $M_x's$ sign)\n\n\\begin{align*}\n    k_x &= \\frac{2M_x k \\pm \\sqrt{4 M_x^2 k^2 + 4 \\beta^2 \\left( k^2 - k_r^2 \\right)}}{-2\\beta^2}\\\\\n        &= \\frac{-M_x k \\pm \\sqrt{k^2 - k_r^2}}{\\beta^2}\n\\end{align*}\n\\section{Unsteady Flow}\nThe linearized Euler equations (LEE) for mean axial shear and swirling flow \nin cylindrical coordinates are \n\n\n\nWe can rearrange the equations to reflect Equations 2.33-2.36. Note that the momentum equation in the $\\theta$ and $x$ directions remain unchanged. The term $ \\frac{\\partial(rv_r')}{\\partial r}  = \\frac{\\partial (r)}{\\partial r}v_r' + \\frac{\\partial v_r'}{\\partial r} r$ in the Energy equation\n\\begin{align*}\n\\frac{1}{\\bar{\\rho} A^2}\\left(\n\\frac{\\partial p'}{\\partial t} +\n\\frac{V_{\\theta}}{r}\n\\frac{\\partial p'}{\\partial \\theta} + \nV_x\n\\frac{\\partial p'}{\\partial x}\n\\right) +\n\\frac{V_{\\theta}^2}{A^2 r}v_r'+\n\\frac{\\partial v_r'}{\\partial r} + \\frac{v_r'}{r} +\n\\frac{1}{r}\n\\frac{\\partial v_{\\theta}'}{\\partial \\theta}\t\t \n +\n\\frac{\\partial v_x'}{\\partial x}\n&= 0\\\\\n\\frac{\\partial  v_r' }{\\partial t} +\n\\frac{V_{\\theta}}{r} \\frac{\\partial v'_r}{\\partial \\theta} -\n\\frac{2V_{\\theta}v'_{\\theta}}{r} +\nV_x \\frac{\\partial v_r'}{\\partial x} &= \\frac{1}{\\bar{\\rho}} \\frac{\\partial p'}{\\partial r}+\\frac{V_{\\theta}}{\\bar{\\rho} r A^2}   p'\n\\\\\n\\frac{\\partial  v_{\\theta}' }{\\partial t} +\nv_r' \\frac{\\partial  V_{\\theta}  }{\\partial r} +\n\\frac{V_{\\theta}}{r} \\frac{\\partial v'_{\\theta}}{\\partial \\theta} +\n\\frac{v'_rV_{\\theta}}{r} +\nV_x \\frac{\\partial v_{\\theta}'}{\\partial x} \n= -\\frac{1}{\\bar{\\rho} r}\t\\frac{\\partial p'}{\\partial \\theta}\\\\\n\\frac{\\partial  v_x' }{\\partial t} +\nv_r' \\frac{\\partial  V_x  }{\\partial r} +\n\\frac{V_{\\theta}}{r} \\frac{\\partial v'_x}{\\partial \\theta} +\nV_x \\frac{\\partial v_x'}{\\partial x} \n&= -\\frac{1    }{\\bar{\\rho}}  \\frac{\\partial p'}{\\partial x} \t\n\\end{align*}\n\n\n\n\n\nStarting with equation 2.28 (Wave Equation) in Kousen's paper \\cite{Kousen1999},\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 r} \\frac{\\partial  \\tilde{v}_r}{ \\partial x} \n    \\label{eqn:KousensWaveEquation}\n\\end{equation}\n\nIf there is uniform axial flow (or no flow), $dV_x/dr = 0$,\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*} \n\nFor no flow, $\\vec{V} = 0$, therefore,\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*} \n\nUsing the isentropic relation, $\\tilde{p} = p/\\bar{\\rho} A^2$. \nTo dimensionalize the equation, this relation is substituted and both sides \nare 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\\section{Analytical Solution}\nThe process of separation of variables(seperation indeterminatarum) was 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.  The pressure field can be assumed to be,\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\\subsection{Evaluating the derivatives}\nBy looking at each derivative individually, the process will be clearer to \nfollow,\n\\subsubsection{Temporal Derivatives}\n\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\\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\\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\\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. 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\nTherefore, the solution goes from this,\n\\begin{equation}\n    y(x) = AJ_n(x) + BY_n(x)\n    \\label{eqn:besselsolution}\n\\end{equation}\nto this,\n\n\n\\begin{equation}\n    R(r) = (AJ_n(k_r r) + BY_n(k_r r)) \n    \\label{eqn:besselsolution}\n\\end{equation}\nwhere the coefficients $A$ and $B$ are found after applying radial\nboundary conditions. %and there is an exponential dependence. \n\n\n\n\n\\subsubsection{Hard Wall boundary condition}\n\\begin{align*}\n    \\frac{\\partial p}{\\partial r}|_{r = r_{min}}  =\\frac{\\partial p}{\\partial r}|_{r = r_{max}} = 0 \\rightarrow \n    \\frac{\\partial}{\\partial r} \\left( X\\Theta T R \\right) &= 0 \\\\\n    X \\Theta T\\frac{\\partial R}{\\partial r}  &= 0 \\\\\n    \\frac{\\partial R}{\\partial r}  &= 0 \n\\end{align*}\n\nwhere,\n\n\n\\begin{align*} \n    \\frac{ \\partial R}{\\partial r}|_{r_{min}} &= AJ_n'(k_r r_{min}) + B Y_n' (k_r r_{min}) = 0 \n    \\rightarrow B = -A \\frac{J_n'(k_r r_{min})}{Y_n'(k_r r_{min})}\n\\end{align*}\n\n\n\\begin{align*} \n    \\frac{ \\partial R}{\\partial r} &= AJ_n'(k_r r_{max}) + B Y_n' (k_r r_{max}) = 0 \\\\\n                                   &= AJ_n'(k_r r_{max}) - A\\frac{J_n' (k_r r_{min})}{Y_n'(k_r r_{min})} Y_n' (k_r r_{max}) = 0 \\\\\n                                   &= \\frac{J_n'(k_r r_{min})}{J_n' (k_r r_{max})} - \\frac{Y_n'(k_r r_{min})}{Y_n' (k_r r_{max})} = 0 \n\\end{align*}\nwhere $k_r r$ are the zero crossings for the derivatives of the Bessel functions of the first and second kind.\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\nSolving for the axial wavenumber gives,\n\n\\begin{equation}\n    k_x = \\sqrt{k^2 - k_r^2}\n    \\label{eqn:axial_wavenumber_equation}\n\\end{equation}\n\n\\section{Uniform Flow}\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\nContinue here,\n\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    A &= - \\beta^2 \\\\\n    B &= - 2M_x k\\\\\n    C &= k^2 - k_2^2\n\\end{align*} \n\nNote B is negative when $M_x$ is positive,\n\n(I feel like N should change based on $M_x's$ sign)\n\n\\begin{align*}\n    k_x &= \\frac{2M_x k \\pm \\sqrt{4 M_x^2 k^2 + 4 \\beta^2 \\left( k^2 - k_r^2 \\right)}}{-2\\beta^2}\\\\\n        &= \\frac{-M_x k \\pm \\sqrt{k^2 - k_r^2}}{\\beta^2}\n\\end{align*}\n\n\\section{Annular Duct Axial Wavenumber solution}\n\n\nIn \\cite{Amr2001}, the axial wavenumber for annular ducts is reported, if the \nannulus is narrow ($(r_{max} - r_{min})/r_{mean} << 1$ , then the radius, mean\nvelocity, density, and speed of sound can be expressed in terms of a perturbation\nexpansion of the form,\n\n\\begin{align}\n    r &= 1 + \\epsilon \\tilde{r} + \\cdots,\\\\\n    M_t &= M_x(1) e_x + M_{\\theta}(1) e_{\\theta} + O(\\epsilon)\n    \\rho_o &= 1 + O(\\epsilon) \n    c_o^2 &=   1 + O(\\epsilon)\n\\end{align}\n\nwhere $\\epsilon << 1$ \n\n\n\\begin{equation*}\n    \\frac{-(\\tilde{\\omega} - m M_{\\theta})M_x \\pm \\sqrt{\\left( \\tilde{\\omega} - m M_{\\theta}^2 \\right) - \\beta\\left( m^2 + \\Gamma_{m,n} ^2 \\right)}}{\\beta^2}\n\\end{equation*}\n\nwhere \n$\\tilde{\\omega} = \\omega - m M_{\\theta}$\n$\\beta = 1- M_x^2$\n$\\Gamma_{m,n}= \\frac{n^2 \\pi^2}{\\left( r_{max} - r_{min} \\right)^2}$\n\\bibliographystyle{ieeetr}\n\\bibliography{references.bib}\n\\end{document}\n\n\n", "meta": {"hexsha": "9f03bab64c9723b5ca177e6822740b1afba0cd28", "size": 29991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/AnalyticalDuctModes.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/AnalyticalDuctModes.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/AnalyticalDuctModes.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": 31.1756756757, "max_line_length": 293, "alphanum_fraction": 0.5903437698, "num_tokens": 11510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505273888291, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7707195550115533}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nLet $A = \\{a,b\\}$.\nProve that there are no words $x, y \\in A^*$ such that $xay = ybx$.\nProve that there is no word $x \\in \\{a,b\\}^*$ such that $ax = xb$.\n\n\\subsection*{Solution}\n\nIt is prerequisite of equality for any two words $u, v \\in \\{a,b\\}^*$ to share an equal number of each symbols.\nIt is shown that the two words $u=xay$ and $v=ybx$ fail to satisfy this prerequisite.\n\nSuppose there are $m$ total $a$ symbols and $n$ total $b$ symbols in x and y.\nTherefore, total number of $a$ symbols in $u$ is $m+1$ whereas total number of $a$ symbols in $v$ is $m$.\nThus prerequisite is not met and $u \\neq v$.\n\nSimilarly, if $u = ax$ and $v = xb$, number of $a$ symbols in $u$ is always one more than number of $a$ symbols in $v$ thus $u \\neq v$.\n", "meta": {"hexsha": "863305d6e91c1af25681f546f39bf35165a60fb7", "size": 1126, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw01/hw01q03.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/hw01q03.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/hw01q03.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.9166666667, "max_line_length": 135, "alphanum_fraction": 0.6056838366, "num_tokens": 331, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7707195516110228}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      a & b \\\\\n      c & d \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  An operation is done to get from $A$ to a matrix $B$. In each case,\n  identify which operation was done and explain how it will affect the\n  value of the determinant.\n  \\begin{enumerate}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{cc}\n        a & c \\\\\n        b & d \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{cc}\n        c & d \\\\\n        a & b \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{cc}\n        a   & b   \\\\\n        a+c & b+d \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{cc}\n        a  & b  \\\\\n        2c & 2d \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\item\n    \\begin{equation*}\n      B = \\begin{mymatrix}{cc}\n        b & a \\\\\n        d & c \\\\\n      \\end{mymatrix}\n    \\end{equation*}\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item The transpose was taken and $\\det(B) = \\det(A)$.\n    \\item Two rows were switched and $\\det(B) = -\\det(A)$.\n    \\item The first row was added to the second row and $\\det(B) = \\det(A)$.\n    \\item The second row was multiplied by 2 and $\\det(B) = 2\\det(A)$.\n    \\item Two columns were switched and $\\det(B) = -\\det(A)$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ be an $n\\times n$-matrix and suppose there are $n-1$ rows\n  such that the remaining row is a linear combinations of these $n-1$\n  rows. Show $\\det(A) = 0$.\n  \\begin{sol}\n    By assumption, we can obtain a row of zeros by doing row\n    operations. Row operations do not change whether the determinant\n    is zero, so the determinant must have been zero all along.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  \\label{ex:determinant3}\n  Let $A$ be an $n\\times n$-matrix. Show that if $\\det(A) \\neq 0$ and\n  $A\\vect{x}=\\vect{0}$, then $\\vect{x}=\\vect{0}$.\n  \\begin{sol}\n    If $\\det(A) \\neq 0$, then $A^{-1}$ exists. Therefore\n    $\\vect{x} = A^{-1}A\\vect{x} = A^{-1}\\vect{0} = \\vect{0}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Using only Theorems~\\ref{thm:determinant-of-triangular-matrix} and\n  {\\ref{thm:determinant-of-product}}, show that\n  $\\det(kA) = k^n\\det(A)$ for an $n\\times n$-matrix $A$ and scalar\n  $k$.\n  \\begin{sol}\n    The matrix $kI$ has $k$ down the main diagonal and has determinant\n    equal to $k^n$ by\n    Theorem~\\ref{thm:determinant-of-triangular-matrix}. Using\n    Theorem~\\ref{thm:determinant-of-product}, it follows that\n    $\\det(kA) = \\det(kIA) = \\det(kI) \\det(A) = k^n\\det(A)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Construct two random $2\\times 2$-matrices $A$ and $B$ and verify\n  that $\\det(A)\\det(B) = \\det(AB)$.\n  \\begin{sol}\n    \\begin{equation*}\n      \\det\n      \\paren{\\begin{mymatrix}{cc}\n          1 & 2 \\\\\n          3 & 4\n        \\end{mymatrix} \\begin{mymatrix}{rr}\n          -1 & 2 \\\\\n          -5 & 6\n        \\end{mymatrix}} = -8,\n    \\end{equation*}\n    \\begin{equation*}\n      \\det\\paren{\\begin{mymatrix}{cc}\n        1 & 2 \\\\\n        3 & 4\n      \\end{mymatrix}}\\det\\paren{\\begin{mymatrix}{rr}\n        -1 & 2 \\\\\n        -5 & 6\n      \\end{mymatrix}} = -2\\times 4 = -8.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Is it true that $\\det(A+B) = \\det(A) + \\det(B)$? If this is so,\n  explain why. If it is not so, give a counterexample.\n  \\begin{sol}\n    This is not true at all. Consider $A = \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & 1\n    \\end{mymatrix}$ and $B = \\begin{mymatrix}{rr}\n      -1 & 0 \\\\\n      0 & -1\n    \\end{mymatrix}$. Then $\\det(A)=1$, $\\det(B)=1$, and $\\det(A+B)=0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  An $n\\times n$-matrix is called \\textbf{nilpotent}%\n  \\index{nilpotent matrix}%\n  \\index{matrix!nilpotent} if there exists some positive integer $k$\n  such that $A^k = 0$. If $A$ is a nilpotent matrix, what are the\n  possible values of $\\det(A)$?\n  \\begin{sol}\n    Since $A^k=0$, we have $\\det(A)^k=\\det(A^k)=\\det(0)=0$. Therefore,\n    it must be the case that $\\det(A)=0$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  A square matrix is said to be \\textbf{orthogonal}%\n  \\index{matrix!orthogonal}%\n  \\index{orthogonal matrix} if $A^TA = I$. Thus the inverse of an\n  orthogonal matrix is its transpose. What are the possible values of\n  $\\det(A)$ if $A$ is an orthogonal matrix?\n  \\begin{sol}\n    If $A$ is orthogonal, we have $\\det(A)^2 = \\det(A^T)\\det(A) =\n    \\det(A^TA) = \\det(I) = 1$. Therefore the only possible values for\n    $\\det(A)$ are $\\pm 1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ and $B$ be two $n\\times n$-matrices. We say that $A$ is\n  \\textbf{similar}%\n  \\index{matrix!similar}%\n  \\index{similar matrices} to $B$, in symbols $A\\similar B$, if there\n  exists an invertible matrix $P$ such that $A = P^{-1}BP$. Show that\n  if $A\\similar B$, then $\\det(A) = \\det(B)$.\n  \\begin{sol}\n    $\\det(A) = \\det(P^{-1}BP) = \\det(P^{-1}) \\det(B) \\det(P) =\n    \\frac{1}{\\det(P)} \\det(B) \\det(P) = \\det(B)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the determinant of\n  \\begin{equation*}\n    A = \\begin{mymatrix}{ccc}\n      1 & 1 & 1 \\\\\n      1 & a & a^2 \\\\\n      1 & b & b^2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  For which values of $a$ and $b$ is this matrix invertible? Hint:\n  after you compute the determinant, you can factor out $(a-1)$ and\n  $(b-1)$ from it.\n  \\begin{sol}\n    The determinant is\n    \\begin{equation*}\n      \\begin{absmatrix}{ccc}\n        1 & 1 & 1 \\\\\n        1 & a & a^2 \\\\\n        1 & b & b^2 \\\\\n      \\end{absmatrix}\n      = \\begin{absmatrix}{cc}\n        a & a^2 \\\\\n        b & b^2 \\\\\n      \\end{absmatrix}\n      - \\begin{absmatrix}{cc}\n        1 & 1 \\\\\n        b & b^2 \\\\\n      \\end{absmatrix}\n      + \\begin{absmatrix}{cc}\n        1 & 1 \\\\\n        a & a^2 \\\\\n      \\end{absmatrix}\n      = ab^2 - ba^2 - b^2 + b + a^2 - a\n      = (a-1)(b-1)(b-a).\n    \\end{equation*}\n    Therefore the determinant is $0$ if $a=1$, $b=1$, or $a=b$. In all\n    other cases, the determinant is non-zero and the matrix is invertible.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Assume $A$, $B$, and $C$ are $n\\times n$-matrices and $ABC$ is\n  invertible. Use determinants to show that each of $A,B$, and $C$ is\n  invertible.\n  \\begin{sol}\n    This follows because $\\det(ABC) = \\det(A)\\det(B)\\det(C)$ and if\n    this product is non-zero, then each determinant in the product is\n    non-zero. Therefore, each of these matrices is invertible.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is an upper triangular matrix. Show that $A^{-1}$ exists\n  if and only if all elements of the main diagonal are non-zero. Is it\n  true that $A^{-1}$ will also be upper triangular? Explain. Could the\n  same be concluded for lower triangular matrices?\n  \\begin{sol}\n    The given condition is what it takes for the determinant to be\n    non-zero. Recall that the determinant of an upper triangular\n    matrix is just the product of the entries on the main diagonal.\n    The inverse will also be upper triangular; this can be seen by\n    noting that every invertible upper triangular can be written as a\n    product of upper triangular elementary matrices; the inverse of\n    each such elementary matrix is upper triangular, and therefore so\n    is their product. The analogous statement about lower triangular\n    matrices is also true.\n  \\end{sol}\n\\end{ex}\n\n\\begin{samepage}  % Inhibit page break within the exercise. A student\n                  % misread a \"false\" statement at the top of the page\n                  % as a theorem.\n\\begin{ex}\n  Specify whether each statement is true or false. If true, provide a\n  proof. If false, provide a counterexample.\n  \\begin{enumerate}\n  \\item If $A$ is a $3\\times 3$-matrix with determinant zero, then one\n    column must be a multiple of some other column.\n\n  \\item If any two columns of a square matrix are equal, then the\n    determinant of the matrix equals zero.\n\n  \\item For two $n\\times n$-matrices $A$ and $B$,\n    $\\det(A+B) = \\det(A) + \\det(B)$.\n\n  \\item For an $n\\times n$-matrix $A$, $\\det(3A) = 3\\det(A)$.\n\n  \\item If $A^{-1}$ exists, then $\\det(A^{-1}) = \\det(A)^{-1}$.\n\n  \\item If $B$ is obtained by multiplying a single row of $A$ by $4$,\n    then $\\det(B) = 4\\det(A)$.\n\n  \\item For an $n\\times n$-matrix $A$, we have\n    $\\det(-A) = (-1)^n\\det(A)$.\n\n  \\item If $A$ is a real $n\\times n$-matrix, then\n    $\\det(A^TA) \\geq 0$.\n\n  \\item If $A^k = 0$ for some positive integer $k$, then\n    $\\det(A) = 0$.\n\n  \\item If $A\\vect{x} = 0$ for some $\\vect{x} \\neq 0$, then\n    $\\det(A) = 0$.\n  \\end{enumerate}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item False. Consider $\\begin{mymatrix}{rrr}\n        1 & 1 & 0 \\\\\n        1 & 2 & 1 \\\\\n        0 & 1 & 1 \\\\\n      \\end{mymatrix}$.\n    \\item True.\n    \\item False.\n    \\item False.\n    \\item True.\n    \\item True.\n    \\item True.\n    \\item True.\n    \\item True.\n    \\item True.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\\end{samepage}\n\n", "meta": {"hexsha": "6c2928f9e865b90a98412fab1e78a5135bde08c7", "size": 8955, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-Properties.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-Properties.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-Properties.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 29.85, "max_line_length": 76, "alphanum_fraction": 0.5825795645, "num_tokens": 3130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.9005297801113613, "lm_q1q2_score": 0.7707194451864825}}
{"text": "\n\n\\clearpage\n\\newpage\n\n\\section{1D FMM, $1/(x-x')$}\n\\label{sec:1dfmm}\n\nHere we give the pseudo-code and algorithm of \\cite{dutt1996fast} that can be used to accelerate the computation of the 1-dimensional kernel $1/(x-x')$ that appears in the fast scalar spherical transform in Section \\ref{sec:fastscasphfilt}. Specifically, this deals with the computation of\n\\begin{equation}\nf(x_j) = \\sum_k^N \\dfrac{a_k}{x_j - x_k} \\label{eqdir}\n\\end{equation}\n\nThis kernel is similar to the kernel for electrostatic potentials (e.g., $1/\\vert x - x'\\vert$), except with the important difference that the denominator retains its sign.  \n\nLet $M$ be the number of observation points $x_j$, $N$ be the number of source points, $x_k$, that have amplitudes $a_k$ which can be real or complex. In matrix form, this requires $O(NM)$ operations to perform the matrix vector multiplication.  The algorithm in \\cite{dutt1996fast} reduces this to $O(Np + Mp)$ where $p$ is the number of expansion terms needed to achieve a specific accuracy.  \n\nThis algorithm is based on the observation that the far-field expansions of local groups of sources under this kernel can be aggregated up a binary tree-structure, expanded about another center at fixed cost, then dissaggregated. It exploits the properties of Chebyshev polynomials on the domain $x = [-1,1]$ in order to accomplish this procedure with pre-defined precision.  Two versions of the algorithm are given in \\cite{dutt1996fast}; we repeat the first algorithm here; the second uses SVD to accelerate the computation. \n\nFor $x_j$ and $x_k$ in the range $x = [a, b]$, the inputs can be rescaled with the affine transformation\n\\begin{eqnarray}\nx' &=& \\dfrac{2}{b-a}(x + a) -1 \\label{af1} \\\\\nx &=& \\dfrac{b-a}{2}(x' + 1) - a \\label{af2}\n\\end{eqnarray}\n\nUsing \\eqref{af2} in \\eqref{eqdir} yields $x_j'$ and $x_k'$ on $x = [-1, 1]$.  \n\\begin{equation}\nf(x_j') = \\dfrac{2}{b-a}\\sum_k^N \\dfrac{a_k}{x_j' - x_k'}\n\\end{equation}\n\nTherefore only the source and observation points need to be transformed using \\eqref{af1}, and the scale factor $2/(b-a)$ applied to the amplitudes, the algorithm is otherwise equivalent.  \n\n%\\subsection{Basic Algorithm}\n\n\\paragraph{Setup}\n\\begin{itemize}\n  \\setlength{\\itemsep}{1pt}\n  \\setlength{\\parskip}{0pt}\n  \\setlength{\\parsep}{0pt}\n\\item  $p$ is an integer that is the size of the Chebyshev expansions.  $p$ is the same for all expansions on $x = [-1,1]$ and given by $p = \\lceil -\\log_5(\\epsilon) \\rceil$ where $0 < \\epsilon < 1$ is the desired precision.  \n\n\\item $t_1, ..., t_p$ are the Chebyshev nodes of order $p$ on $x = [-1,1]$, given by\n\\begin{equation}\nt_i = \\cos\\left(\\dfrac{2i-1}{p}\\dfrac{\\pi}{2}\\right) \\label{fmm1prepeqfirst}\n\\end{equation}\n\n\\item The expansion functions are given by the polynomials \n\\begin{equation}\nu_j(t) = \\prod_{\\substack{k=1 \\\\ k \\neq j}}^p \\dfrac{t-t_k}{t_j-t_k} \n\\end{equation}\n\n\\item The far-field due to sources in $x = [x_o-r,x_o+r]$ is given by\n\\begin{eqnarray}\nf_{\\textrm{far}}(x) &=& \\sum_j^p \\Phi_{j}  u_j\\left(\\dfrac{3r}{x - x_o}\\right) \\\\\n\\Phi_{j} &=& \\sum_k^p a_k \\dfrac{t_j}{3r - t_j(x_k - x_o)} \\label{phi1}\n\\end{eqnarray}\n\n\\noindent where $\\Phi_{k}$ are the far-field expansion coefficients.\n\n\\item The local field in $x = [y_o-r,y_o+r]$ is given by\n\\begin{eqnarray}\nf_{\\textrm{loc}}(x) &=& \\sum_j^p \\Psi_{j}  u_j\\left(\\dfrac{x - y_o}{r}\\right) \\label{psi1}\\\\\n\\Psi_{j} &=& \\sum_k^p  \\dfrac{a_k}{rt_j - (x_k - y_o)} \n\\end{eqnarray}\n\n\\noindent where $\\Psi_{k}$ are the local field expansion coefficients.\n\n\\item $s$ is an integer and is the number of points in each subinterval at the finest level. It is recommended to set $s \\approx 2p$.  \n\n\\item $nlevs = \\lceil \\log_2(N/s) \\rceil$ is the level of finest subinterval and the total number of levels.  \n\n\\item $\\Phi_{l,i}$ are the $p$-term far-field coefficients at level $l$, subinterval $i$.\n\n\\item $\\Psi_{l,i}$ are the $p$-term local-field coefficients at level $l$, subinterval $i$.\n\n\\item $M_L$ and $M_R$ are $p \\times p$ matrices that aggregate the far-field expansions of left and right subinterval (children) to a far-field expansion at the next higher level (parent).  These are given by (\\cite[Eq. 78]{dutt1996fast}  has a typo)\n\\begin{eqnarray}\nM_L(i,j) &=& u_j\\left(\\dfrac{3 t_i}{6  + t_i}\\right) \\\\\nM_R(i,j) &=& u_j\\left(\\dfrac{3 t_i}{6  - t_i}\\right) \n\\end{eqnarray}\n\n\\item $S_L$ and $S_R$ are $p \\times p$ matrices that disaggregate the local expansion of a parent to its left and right children\n\\begin{eqnarray}\nS_L(i,j) &=& u_j\\left(\\dfrac{t_i -1 }{2}\\right) \\\\\nS_R(i,j) &=& u_j\\left(\\dfrac{t_i + 1}{2}\\right) \n\\end{eqnarray}\n\n\\item $T_1$, $T_2$, $T_3$, $T_4$ are $p \\times p$ matrices that translate the far-field expansions of the well-separated subdivisions to the local expansion of a subinterval at the same level.  The far-field subdivisions are separated from the local subinterval by $-3$, $-2$, $2$ and $3$ positions, respectively.  \n\n\\begin{eqnarray}\nT_1(i,j) &=& u_j\\left(\\dfrac{3 }{t_i - 6}\\right) \\\\\nT_2(i,j) &=& u_j\\left(\\dfrac{3 }{t_i - 4}\\right) \\\\\nT_3(i,j) &=& u_j\\left(\\dfrac{3 }{t_i + 4}\\right) \\\\\nT_4(i,j) &=& u_j\\left(\\dfrac{3 }{t_i + 6}\\right)  \\label{fmm1prepeqlast}\n\\end{eqnarray}\n\n\\end{itemize}\n\n\\paragraph{Algorithm psuedo-code}\n\\begin{enumerate}\n\\item Set the expansion size $p$, choose $s$, and compute $nlevs$.  Precompute Chebyshev coefficients and translation matrices.  \n\n\\item Determine the far-field expansions at the finest level. \n\n\\textbf{do} $i = 1, ..., 2^{nlevs}$\n\\begin{addmargin}[1em]{2em}\nCompute $p$-term far-field expansions $\\Phi_{nlevs,i}$ using \\eqref{phi1} due to sources at $x_k$ which lie in subinterval $i$ at level $nlevs$. \n\\end{addmargin}\n\\textbf{end}\n\n\\item Determine the $p$-term far-field expansion at each subinterval at every level by shifting and adding the far-field expansions of the subintervals children\n\n\\textbf{do} $l = nlevs-1, ..., 1$\n\\begin{addmargin}[1em]{2em}\n\\textbf{do} $i = 1, ..., 2^{l}$\n\\begin{addmargin}[1em]{2em}\n$\\Phi_{l,i} = M_L \\cdot \\Phi_{l+1,2i-1}  + M_R \\cdot \\Phi_{l+1,2i} $\n\\end{addmargin}\n\\textbf{end}\n\\end{addmargin}\n\\textbf{end}\n\n\\item Determine $p$-term local expansion at each subinterval at each level by 1) disaggregating the parent's local expansion, 2) adding the far-field translation to local translation of well-separated subintervals at the same level, but that have not been accounted for at the parent's level. (The equations for this step given in \\cite{dutt1996fast} do not work as they appear, but the following does)\n\n\\textbf{do} $l = 1,...,nlevs-1$\n\\begin{addmargin}[1em]{1em}\n\\textbf{do} $i = 1, ..., 2^{l}$\n\\begin{addmargin}[1em]{1em}\n$\\Psi_{l+1,2i-1} = S_L \\cdot  \\Psi_{l,i} + T_2 \\cdot  \\Phi_{l+1,2i-3} + T_3  \\cdot \\Phi_{l+1,2i+1} + T_4 \\cdot  \\Phi_{l+1,2i+2}$ \\\\\n$\\Psi_{l+1,2i} \\quad = S_R  \\cdot \\Psi_{l,i} + T_1 \\cdot  \\Phi_{l+1,2i-3} + T_2  \\cdot \\Phi_{l+1,2i-2} + T_3  \\cdot \\Phi_{l+1,2i+2}$\n\\end{addmargin}\n\\textbf{end}\n\\end{addmargin}\n\\textbf{end}\n\n\\item Evaluate the local expansion at the finest level\n\n\\textbf{do} $i = 1, ..., 2^{nlevs}$\n\\begin{addmargin}[1em]{2em}\nEvaluate $p$-term local expansions $\\Psi_{nlevs,i}$ using \\eqref{psi1} at points $x_j$ which lie in subinterval $i$ at level $nlevs$. \n\\end{addmargin}\n\\textbf{end}\n\n\\item Add the near-neighbor contributions directly\n\n\\textbf{do} $i = 1, ..., 2^{nlevs}$\n\\begin{addmargin}[1em]{2em}\nFor each point $x_j$ in subinterval $i$ at level $nlevs$, compute the contribution of all $x_k$ in subintervals $i-1$, $i$, $i+1$ using \\eqref{eqdir}, and add the result to the local expansion already evaluated before. \n\\end{addmargin}\n\\textbf{end}\n\n\n\\end{enumerate}\n\n\\paragraph{Routines} \n\\mbox{}\\\\\n\\mbox{}\\\\\nThe 1D FMM is implemented with two routines \\texttt{fmm1prep} and  \\texttt{fmm1}.  \\texttt{fmm1prep} is a preparatory function that precomputes the setup parameters of the algorithm and translation matrices using \\eqref{fmm1prepeqfirst} through \\eqref{fmm1prepeqlast}.  It takes as inputs observation points $x_j$ and source points $x_k$ on $x = [-1, 1]$, source amplitudes $a_k$ (real or complex), and precision $\\epsilon$.  $s$ is optional, the default is $s = 2p$. The outputs are $M_L$, $M_R$, $S_L$, $S_R$, $T_1$, $T_2$, $T_3$, $T_4$, etc.  \\texttt{fmm1} takes the outputs from \\texttt{fmm1prep} and executes the algorithm given by the pseudo-code. The pair of routines is set up so that \\texttt{fmm1} can be called with new source amplitudes for the same source and observation points and the same outputs of \\texttt{fmm1prep}.  \n\nBoth routines rely on linear indexing to bookkeep the values of variables. The total number of expansions needed, and thus total number of subdivisions on the binary tree, is\n\n\\begin{equation}\nB = \\sum_{i=1}^{nlevs} 2^i = 2^{nlevs + 1} - 2\n\\end{equation}\n\nThe expansion coefficients vectors $\\Phi_{l,i}$ and $\\Psi_{l,i}$ are stored on $p \\times B$ arrays and accessed with column index\n\n\\begin{equation}\nI(l,i) = 2^l - 2 + i\n\\end{equation}\n\n\\noindent for $ l \\ge 1, i = 1,...,2^l $.  This is provided by the helper function \\texttt{box2ind}, which has been replaced by inline computation in the code.  The basis functions, $u_j(t)$, are provided in the routine $\\texttt{fmm1u}$.  Note, the expansions at the top-most level, $l=1$, are never used except to initialize one of the loops with zeros.  \n\nBecause Matlab's matrix vector multiplication is highly optimized, it is actually faster for small problems to precompute the elements of the matrix and let Matlab do the computation directly.  This works to a point.  These routines require comparably no storage and are the only path forward for very large problems.\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/fmm1/fmm1.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/fmm1/fmm1prep.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/fmm1/fmm1u.m}\n}\n\n{\\footnotesize\n\\VerbatimInput{\\code/FastMultipoleMethod/fmm1/box2ind.m}\n}\n", "meta": {"hexsha": "3402217575a907272feaab0816008a87db94aac5", "size": 9906, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/FastMultipoleMethod/FMM1d.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/FMM1d.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/FMM1d.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": 51.8638743455, "max_line_length": 835, "alphanum_fraction": 0.7094690087, "num_tokens": 3344, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8558511432905481, "lm_q1q2_score": 0.7707194401619287}}
{"text": "\\title{Laplace Approximation}\n\n\\subsection{Laplace Approximation}\n\n(This tutorial follows the\n\\href{/tutorials/map}{Maximum a posteriori estimation} tutorial.)\n\nMaximum a posteriori (MAP) estimation approximates the posterior $p(\\mathbf{z} \\mid \\mathbf{x})$\nwith a point mass (delta function) by simply capturing its mode. MAP is\nattractive because it is fast and efficient. How can we use MAP to construct a\nbetter approximation to the posterior?\n\nThe Laplace approximation\n\\citep{laplace1986memoir}\nis one way of improving a MAP estimate. The idea\nis to approximate the posterior with a normal distribution centered at the MAP\nestimate,\n\\begin{align*}\n  p(\\mathbf{z} \\mid \\mathbf{x})\n  &\\approx\n  \\text{Normal}(\\mathbf{z}\\;;\\; \\mathbf{z}_\\text{MAP}, \\Lambda^{-1}).\n\\end{align*}\nThis requires computing a precision matrix $\\Lambda$. Derived from a\nTaylor expansion, the Laplace approximation uses the Hessian of the\nnegative log joint density at the MAP estimate.\nIt is defined component-wise as\n\\begin{align*}\n  \\Lambda_{ij}\n  &=\n  \\frac{\\partial^2}{\\partial z_i \\partial z_j} -\\log p(\\mathbf{x}, \\mathbf{z}).\n\\end{align*}\nFor flat priors (which reduces MAP to maximum likelihood), the\nprecision matrix is known as the observed Fisher information\n\\citep{fisher1925theory}.\nEdward uses TensorFlow's automatic differentiation, making this\nsecond-order gradient computation both simple and efficient to\ndistribute.\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": "aa5201706f899b1dd4f3d1199720f9f0d81df7fa", "size": 1558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/map-laplace.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/map-laplace.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/map-laplace.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": 36.2325581395, "max_line_length": 96, "alphanum_fraction": 0.7689345315, "num_tokens": 405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7705856552675643}}
{"text": "\\subsection{Free Undamped Vibrations ($b = 0$)}\r\n\\noindent\r\nIn this case, our equation simplifies to\r\n\\begin{equation*}\r\n\tmy'' + ky = 0\r\n\\end{equation*}\r\nThe two roots of ou auxiliary equation are\r\n\\begin{equation*}\r\n\tr = \\pm i \\sqrt{\\frac{k}{m}} = \\pm i\\omega\r\n\\end{equation*}\r\nSo, our solution becomes\r\n\\begin{equation*}\r\n\ty = C_1\\cos{(\\omega t)} + C_2\\sin{(\\omega t)}\r\n\\end{equation*}\r\nThis is the same $\\omega$ from physics that means angular frequency, so the same physics formulas apply, like $T = \\frac{2\\pi}{\\omega}$.\\\\\r\n\r\n\\noindent\r\nWe can simplify this a bit further. If we think of the $\\cos$ and $\\sin$ components as being sides of a right triangle like so,\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/triangle.png}\r\n\\end{center}\r\nthen we rewrite our equation as\r\n\\begin{equation*}\r\n\ty = A\\left( \\frac{C_1}{\\sqrt{C_1^2 + C_2^2}}\\cos{(\\omega t)} + \\frac{C_2}{\\sqrt{C_1^2 + C_2^2}}\\sin{(\\omega t)} \\right)\r\n\\end{equation*}\r\nNote that since $\\left(\\frac{C_1}{A}\\right)^2 + \\left(\\frac{C_2}{A}\\right)^2 = 1$, we can rewrite these coefficients as $\\cos{\\phi}$ and $\\sin{\\phi}$ respectively where\r\n\\begin{equation*}\r\n\t\\phi = \\begin{cases}\r\n\t\t\\arctan{(\\frac{C_2}{C_1})} & C_1 > 0 \\\\\r\n\t\t\\arctan{(\\frac{C_2}{C_1})} + \\pi & C_1 \\leq 0\r\n\t\\end{cases}\r\n\\end{equation*} \r\nSo, our equation becomes\r\n\\begin{equation*}\r\n\ty = A\\left(\\cos{(\\omega t)}\\cos{\\phi} + \\sin{(\\omega t)}\\sin{\\phi}\\right)\r\n\\end{equation*}\r\nUsing the $\\cos$ angle addition formula\r\n\\begin{equation*}\r\n\ty = A\\cos{(\\omega t - \\phi)}\r\n\\end{equation*}\r\n\\begin{center}\r\n\t\\includegraphics[width=0.5\\textwidth]{./higherOrder/freeVibrs/undampedfree.png}\r\n\\end{center}\r\nAs we can see, an undamped free vibration will simply oscillate back and forth without decay.\r\n\r\n\\ifodd\\includeHigherOrderExamples\\input{./higherOrder/freeVibrs/undampedFreeVibrs_example.tex}\\fi", "meta": {"hexsha": "39588afc4fca40ff5ef428736656f0f0cbf975e8", "size": 1858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/freeVibrs/freeUndamped.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/freeUndamped.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/freeUndamped.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.3913043478, "max_line_length": 169, "alphanum_fraction": 0.67868676, "num_tokens": 654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.888758793492457, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.7705856451091467}}
{"text": "\n\\subsection{Markov property}\n\nFor a process with the Markov property, only the current state matters for all probability distributions.\n\n\\(P(x_{t+n}|x_t)=P(x_{t+n}|x_t, x_{t-1}...)\\)\n\n", "meta": {"hexsha": "51c125829aa39348cf789463f2b49679f1f208e4", "size": 185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticMarkov/01-01-property.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/stochasticMarkov/01-01-property.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/stochasticMarkov/01-01-property.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.125, "max_line_length": 105, "alphanum_fraction": 0.7135135135, "num_tokens": 55, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9372107878954105, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7705645207738407}}
{"text": "\\section{Spectral Analysis}\n\nSometimes it is useful to describe the properties of the time series\nin a frequency domain. The spectrum is defined as \n\\[\nf_{ab}(\\lambda) = \\frac{\\sigma^2}{2\\pi} \\sum_{h = -\\infty}^{\\infty} \\gamma_{ab}(h) \\exp\n( -i \\lambda h)\n\\]\n\nThere is a one-to-one correspondence between the spectrum and the\nautocovariance function \n\\[\n\\sigma^2 \\gamma_{ab}(h) = \\int_{-\\pi}^{\\pi} f(\\lambda) \\exp ( i\\lambda h) d\\lambda\n\\]\n\nWe call $|f_{aa}|^2$ the power spectrum. A natural way of estimating a\npower \nspectrum is using the periodogram which \nis the modulus of the Fourier transform of the data\n\\[\nI(\\lambda) = \\frac{1}{2\\pi T} | \\sum_{t=1}^T Y_t \\exp (-i \\lambda t) |^2\n\\]\nWe usually compute the periodogram at the Fourier frequencies\n$\\lambda_j = (2 \\pi j)/T, j=1,\\dots,T/2$. These have desirable\nstatistical properties\n\nThe periodogram is also useful for detecting periodicities\n(deterministic ones) in the signal. It is a mathematical fact that if\nthe data $Y_1,...Y_T$ has a period $p$, the the periodogram will have\npeaks at frequencies $\\lambda = 2 \\pi T/p$ and its multiples. \n\n\\centerline{\\epsfig{figure=Plots/plot-10-04.ps,angle=270,width=\\textwidth}}\n\n\n\\subsection{An Application}\nFigured 4a and 4c shows recorded ECoG signal for two channels for\na subject that has received a sensory stimulus at some point\nduring the recording. A straightforward way of estimating the\nspectrum of a stationary process is the periodogram\n\\[\nI(\\lambda) = \\frac{1}{2\\pi T} \\left| \\sum_t Y(t) \\exp(i\\lambda t)\n\\right|^2.\\]\nIn Figures 4b and 4c the periodogram of this data is shown. Brain\nresearchers have speculated that the so-called $\\alpha$ $(8-13\nHz.)$, $\\beta$ $(15-25 Hz.)$, and $\\gamma$ $(>30 Hz.)$ bands of\nhuman brain signals can indicate functional activation of\nsensorimotor cortex. Notice that the\nperiodogram exhibits a peak around frequencies 10 Hz., 20 Hz. and\n60 Hz.. If we were to approximate the ECoG signal as a stationary\nprocesses, we would describe it as having periodic components\naround these frequencies. However, we are interested in learning\nhow the signal changes when the subjects are given a stimuli. Thus\nit seems more appropriate to model the signal as a non-stationary\nprocesses and study the time-varying spectral density.\n\nA straightforward estimate of a time-varying spectral density\nwould be the dynamic periodogram. Basically, for each time $t_0$\nwe consider a window around that point of size $h(t_0)$ and\nestimate a weighted periodogram\n\\[\nI(t_0;\\lambda) = \\frac{1}{2\\pi h(t_0)} \\left| \\sum_t\nw\\left(\\frac{t-t_0}{h(t_0)}\\right) Y(t) \\exp(i\\lambda t) \\right|^2.\n\\]\nFigures 4c and 4e show the estimated time-varying spectral\ndensities for the signals of channels 19 and 20 (lighter colors\nrepresent higher values)\nThe figure seems to suggest that the $\\alpha$ band changes power\nand frequency after the stimulus (time 0).\n\n\n\\centerline{\\epsfig{figure=Plots/plot-10-05.ps,width=\\textwidth}}\n\\centerline{\\epsfig{figure=Plots/plot-10-06.ps,width=\\textwidth}}\n\\centerline{\\epsfig{figure=Plots/plot-10-07.ps,width=\\textwidth}}\n", "meta": {"hexsha": "134086f53a9da37b14237e41bf38770a3fcb2447", "size": 3070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-10-02.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-10-02.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-10-02.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 41.4864864865, "max_line_length": 87, "alphanum_fraction": 0.7469055375, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7704786903643708}}
{"text": "\\section{Math III - Number Theory}\r\n  \\subsection{Linear Prime Sieve}\r\n    \\code{math/numtheory/prime-sieve.cpp}\r\n\\begin{comment}\r\n  \\subsection{Divisor Sieve}\r\n    \\code{math/numtheory/divisor-sieve.cpp}\r\n\\end{comment}\r\n  \\subsection{Number/Sum of Divisors}\r\n    If a number $n$ is prime factorized where $n = {p_1}^{e_1} \\times {p_2}^{e_2} \\times \\cdots \\times {p_k}^{e_k}$, where $\\sigma_0$ is the number of divisors while $\\sigma_1$ is the sum of divisors:\r\n    \\[\r\n    \\sum_{d\\mid n} d^k = \\sigma_k (n) = \\prod \\frac{{p_i}^{k(e_i)+1}-1}{p_i -1}\r\n    \\]\r\n    \\[\r\n    \\text{Product: } \\prod_{d\\mid n} d = n^{\\frac{\\sigma_1 (n)}{2}}\r\n    \\]\r\n  \\subsection{M\\\"{o}bius Sieve}\r\n    The M\\\"{o}bius function $\\mu$ is the M\\\"{o}bius inverse of $e$ such that $e(n) = \\sum_{d\\mid n} \\mu(d)$.\r\n    \\code{math/numtheory/moebius-sieve.cpp}\r\n  \\subsection{M\\\"{o}bius Inversion}\r\n    Given arithmetic functions $f$ and $g$:\r\n    \\[\r\n    g(n) = \\sum_{d\\mid n} f(d) \\quad \\Leftrightarrow \\quad f(n) = \\sum_{d\\mid n} \\mu(d)\\; g\\left(\\frac{n}{d}\\right)\r\n    \\]\r\n  \\subsection{GCD Subset Counting}\r\n    Count number of subsets $S \\subseteq A$ such that $\\gcd(S) = g$ (modifiable).\r\n    \\code{math/numtheory/gcd-subsets.cpp}\r\n  \\subsection{Euler Totient}\r\n    Counts all integers from 1 to $n$ that are relatively prime to $n$ in $O(\\sqrt{n})$ time.\r\n    \\code{math/numtheory/totient.cpp}\r\n\\begin{comment}\r\n  \\subsection{Euler Phi Sieve}\r\n    Sieve version of Euler totient, runs in $O(N \\log N)$ time. Note that $n = \\sum_{d\\mid n} \\varphi(d)$.\r\n    \\code{math/numtheory/phi-sieve.cpp}\r\n\\end{comment}\r\n  \\subsection{Extended Euclidean}\r\n    Assigns $x,y$ such that $ax + by = \\gcd(a,b)$ and returns $\\gcd(a,b)$.\r\n    \\code{math/numtheory/extended-euclidean.cpp}\r\n  \\subsection{Modular Exponentiation}\r\n    Find $b^e \\pmod m$ in $O(log e)$ time.\r\n    \\code{math/numtheory/mod_pow.cpp}\r\n  \\subsection{Modular Inverse}\r\n    Find unique $x$ such that $ax \\equiv 1 \\pmod m$. Returns 0 if no unique solution is found. \\underline{Please use modulo solver for the non-unique case.}\r\n    \\code{math/numtheory/modinv.cpp}\r\n  \\subsection{Modulo Solver}\r\n    Solve for values of $x$ for $ax \\equiv b \\pmod m$. Returns $(-1,-1)$ if there is no solution. Returns a pair $(x, M)$ where solution is $x \\bmod M$.\r\n    \\code{math/numtheory/modsolver.cpp}\r\n  \\subsection{Linear Diophantine}\r\n    Computes integers $x$ and $y$ such that $ax+by=c$, returns $(-1,-1)$ if no solution. \\underline{Tries to return positive integer answers for $x$ and $y$ if possible.}\r\n    \\code{math/numtheory/linear-diophantine.cpp}\r\n  \\subsection{Chinese Remainder Theorem}\r\n    Solves linear congruence $x \\equiv b_i \\pmod {m_i}$. Returns $(-1,-1)$ if there is no solution. Returns a pair $(x, M)$ where solution is $x \\bmod M$.\r\n    \\code{math/numtheory/chinese-remainder.cpp}\r\n    \\subsubsection{Super Chinese Remainder}\r\n      Solves linear congruence $a_i x \\equiv b_i \\pmod {m_i}$. Returns $(-1,-1)$ if there is no solution.\r\n      \\code{math/numtheory/super-crt.cpp}\r\n  \\subsection{Primitive Root}\r\n    \\code{math/numtheory/primitive_root.cpp}\r\n  \\subsection{Josephus}\r\n    Last man standing out of $n$ if every $kth$ is killed. Zero-based, and does not kill $0$ on first pass.\r\n    \\code{math/numtheory/josephus.cpp}\r\n  \\subsection{Number of Integer Points under a Lines}\r\n    Count the number of integer solutions to $Ax+By \\leq C$, $0 \\leq x \\leq n$,\r\n    $0 \\leq y$. In other words, evaluate the sum $\\sum_{x=0}^n\\left\\lfloor\\dfrac{C-Ax}{B}+1\\right\\rfloor$.\r\n    To count all solutions, let $n = \\left\\lfloor\\dfrac{c}{a}\\right\\rfloor$.\r\n    In any case, it must hold that $C-nA \\geq 0$. Be very careful about overflows.\r\n", "meta": {"hexsha": "d8e745afcd7256511af56ff0c3bd12c5dfb6b732", "size": 3678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/number_theory.tex", "max_stars_repo_name": "admu-progvar/progvar-library", "max_stars_repo_head_hexsha": "2e2b204b2dd55ad23f8257f5a50f197ebd115f49", "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/number_theory.tex", "max_issues_repo_name": "admu-progvar/progvar-library", "max_issues_repo_head_hexsha": "2e2b204b2dd55ad23f8257f5a50f197ebd115f49", "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/number_theory.tex", "max_forks_repo_name": "admu-progvar/progvar-library", "max_forks_repo_head_hexsha": "2e2b204b2dd55ad23f8257f5a50f197ebd115f49", "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": 55.7272727273, "max_line_length": 201, "alphanum_fraction": 0.6571506253, "num_tokens": 1229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7704786830295912}}
{"text": "\\subsection{Multilevel coarse grid corrections and a multigrid method}\n\\Label{sc:mg-fd}\nTo describe a multigrid algorithm, we first need to have a multiple\nlevel of grids, say $\\mathcal T_\\ell$ with $\\ell=1:J$ and $\\mathcal T_1=\\mathcal T_h$ being the\nfinest mesh.  There are many ways to obtain multiple level of grids\nand one simple definition of the grid points in $\\mathcal T_\\ell$ is as follows:\n$$\n        x_i^\\ell=\\frac{i}{2^{J+1-\\ell}},\\quad i=1,2,\\cdots, N_\\ell, \\ell=1,2,\\cdots,J,\n$$\nwhere $N_\\ell=2^{J+1-\\ell}-1$.  Note that $\\mathcal T_{\\ell-1}$ can be viewed as being obtained\nby adding midpoints of the subintervals in ${\\mathcal T}_{\\ell}$.  For each $\\ell$\nthe set of above nodes will be denoted by $\\mathcal N_\\ell$.\n\n\\begin{figure}[!htb]\n\\begin{center}\n\\includegraphics[width=3in]{pictures/manygr.pdf}\n\\end{center}\n\\caption{Multiple grids in one dimension\n\\label{fig:manygrids}}\n\\end{figure}\n\n\nWith our previous experiences in two-grid method, the description of a\nmultigrid method is not very difficult.  In fact, the multiple level\ngrids are treated by treating each two consecutive grids, say $\\mathcal T_{\\ell-1}$\nversus $\\mathcal T_{\\ell}$.  If we think $\\mathcal T_{\\ell-1}$ versus $\\mathcal T_{\\ell}$ like\n$\\mathcal T_h$ and $\\mathcal T_{2h}$, then there is not much new in the multigrid\nsetting.\n\n\nLet us give some on details the definition of the restriction and\nprolongation matrices.  The restriction matrix $R_{\\ell-1}^\\ell: R^{N_{\\ell-1}}\n\\mapsto R^{N_{\\ell}}$ can be defined by\n\\begin{equation}\\Label{restrictk}\n\\gamma^{\\ell}=R_{\\ell-1}^\\ell\\gamma^{\\ell-1}: \\;\n\\gamma^{\\ell}_i={1\\over2}\\gamma^{\\ell-1}_{2i-1}+\\gamma^{\\ell-1}_{2i}+{1\\over2}\\gamma^{\\ell-1}_{2i+1}.\n\\end{equation}\nIn matrix form \n\\begin{equation}\n\\label{1drestriction}\nR_{\\ell-1}^\\ell=\\left(\n\\begin{array}{ccccccccc}\n\\frac{1}{2}& 1&\\frac{1}{2}&&&&&&\\\\\n&&\\frac{1}{2}&1&\\frac{1}{2}&&&&\\\\\n&&&&\\frac{1}{2}&1&\\frac{1}{2}&&\\\\\n&&&&&&\\ddots&&\\\\\n&&&&&&\\frac{1}{2}&1&\\frac{1}{2}\\\\\n\\end{array}\n\\right)\n\\end{equation}\nFor a special case, when $N_1=7, N_2=3$, we have \n\\begin{equation}\n\\label{1drestriction3}\nR_1^2=\\left(\n\\begin{array}{ccccccc}\n\\frac{1}{2}& 1&\\frac{1}{2}&0&0&0&0\\\\\n0&0&\\frac{1}{2}&1&\\frac{1}{2}&0&0\\\\\n0&0&0&0&\\frac{1}{2}&1&\\frac{1}{2}\\\\\n\\end{array}\n\\right).\n\\end{equation}\n\n\n\n\nThe prolongation matrix\n$P_{\\ell}^{\\ell-1}: R^{N_{\\ell}}\n\\mapsto R^{N_{\\ell-1}}$ can be defined as \n\\begin{equation}\\Label{prolongk}\n~~\\epsilon^{\\ell-1}=P^{\\ell-1}_{\\ell}\\epsilon^{\\ell}: \\; \\epsilon^{\\ell-1}_{2i}=\\epsilon^{\\ell}_i, \\epsilon^{\\ell-1}_{2i+1}\n= {1\\over~2}(\\epsilon^{\\ell}_i+\\epsilon^{\\ell}_{i+1}), \\; i=1:N_{\\ell}.\n\\end{equation}\n\nWith the restriction and prolongation matrices in hands, we can now\npresent a multilevel version of the earlier two-grid algorithm.  As\nmentioned before, the idea is to repeat this two grid process for the\ncoarse grid by using an even coarser grid.  The resulting algorithm is\njust a desired multigrid algorithm. \n\n\nUsing the convolution with stride notation, the restriction subprocess can also be written as \n$R\\ast_2: \\mathbb R^{N_\\ell}\\rightarrow  \\mathbb R^{N_{\\ell+1}}$, for any $v\\in \\mathbb R^{N_\\ell}, u=(R\\ast_2 v)\\in R^{N_{\\ell+1}}$ with\n$$\n (R\\ast_2 v)_i=\\frac 12 v_{2i-1} +v_{2i}+\\frac 12 v_{2i+1},\\quad  \\mbox{namely}\\quad R\\ast_2v=R_{\\ell-1}^\\ell v\n$$\nwhere $R=[\\frac 12,1,\\frac12]$ and $R_{\\ell-1}^\\ell $ is defined by \\eqref{1drestriction}.\n\nNext \nlet $u^{\\ell+1}=\\sum\\limits_{j=1}^{n_{\\ell+1}}\\mu_{j}^{\\ell+1}\\phi^{\\ell+1}_{j}\n=(  \\mu^{\\ell+1}, \\phi^{\\ell+1})_{l^2}$, then we have\n\\begin{equation}\n\\begin{split}\nu^{\\ell+1}&=( \\mu^{\\ell+1}, \\phi^{\\ell+1})_{l^2}\n=( \\mu^{\\ell+1}, R\\ast_2\\phi^{\\ell})_{l^2}=(R\\ast_2^{\\top} \\mu^{\\ell+1}, \\phi^{\\ell})_{l^2}\\\\\n&=\\sum\\limits_{j=1}^{n_{\\ell}}\\left(R\\ast_2^{\\top} \\mu^{\\ell+1}\\right)_{j}\\phi^{\\ell}_{j}.\n\\end{split}\n\\end{equation}\nThe prolongation subprocess can be written as \n$R\\ast_2^T: \\mathbb R^{N_{\\ell+1}}\\rightarrow \\mathbb R^{N_\\ell}$, for any $v\\in \\mathbb R^{N_{\\ell+1}}, u=(R\\ast_2^T v)\\in R^{N_\\ell}$ with\n$$\n(R\\ast_2^T v)_{2i}=v_i,\\quad (R\\ast_2^T v)_{2i+1}=\\frac 12 (v_{i+1} +v_i),\\quad  \\mbox{namely}\\quad R\\ast_2^Tv=P^{\\ell-1}_\\ell v\n$$\nwhere $R=[\\frac 12,1,\\frac12]$.\n\nUsing the convolution notation, the subprocess to apply $A_\\ell$ to \na vector $v\\in \\mathbb R^{N_\\ell}$ can be written as\n$A_\\ell\\ast: \\mathbb R^{N_\\ell}\\rightarrow \\mathbb R^{N_\\ell}$, for any $v\\in \\mathbb R^{N_\\ell}, r=(A_\\ell\\ast v)\\in R^{N_\\ell}$ with\n$$\n(A_\\ell\\ast v)_{i}=\\frac{1}{h_\\ell}( -v_{i-1}+2v_i-v_{i+1})\n$$\nwhere $A_\\ell=\\frac{1}{h_\\ell}[-1,2,-1]$.\n\n\\newpage\n\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{A multigrid algorithm $\\mu = {\\text{MG1}}(b; \\mu^0; J,\\nu_1, \\cdots, \\nu_J)$}\n\\label{alg:L-Slash11dm}\n\\begin{algorithmic}\n%\t \\State \n%\t\t$$\n%\t\tu \\leftarrow u^0.\n%\t\t$$\n\t\\State Set up\n\t\t$$\n\t\tb^1 = b, \\quad \\mu^{1}=\\mu^0. \n\t\t$$\n\t\t\\State 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\t\\mu^{\\ell} \\leftarrow \\mu^{\\ell} + S^\\ell \\ast (b^\\ell - A_\\ell \\ast \\mu^{\\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\t\\mu^{\\ell+1} \\leftarrow 0, \\quad b^{\\ell+1} \\leftarrow R \\ast_2 (b^\\ell -  A_\\ell \\ast \\mu^{\\ell}), A_{\\ell+1} = R       \\ast_2 A_\\ell \\ast (R\\ast_2^\\top).\n\t\t$$\n\t\t\\EndFor\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\t\\mu^{\\ell} \\leftarrow \\mu^{\\ell} + R  \\ast_2^{\\top} \\mu^{\\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\n\t\t$$\n\t\t\\mu \\leftarrow \\mu^{1}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\nApplication of Multigrid:\n\t\tGiven $\\mu^{(0)}$, for $m=1,2,\\cdots$ till convergence\n\t\t$$\n\t\t\\mu^{(m)}= {\\text{MG1}}(b; \\mu^{{(m-1)}}; J,\\nu_1, \\cdots, \\nu_J).\n\t\t$$\n\t\t\n\\example Let $f(x)=1$. Consider \n\\begin{equation}\\label{1Dposi}\n\\left\\{\n\\begin{aligned}\n-u''&= f, \\,\\, 0<x<1, \\\\\n u(0)&=u(1)=0.\n\\end{aligned}\n\\right.\n\\end{equation}\nThe true solution $u=\\frac12 x(1-x)$. Given the partition with the grid points \n$x_i=\\frac{i}{n+1}, i=0,1,\\cdots,n+1$, then by finite element discretization, \nwe obtain \n\\begin{equation}\\label{matrix}\nA\\ast \\mu =b, A=\\frac{1}{h}[-1,2,-1].\n\\end{equation}\nUse gradient descent method and multigrid to solve \\eqref{matrix} with random initial guess $\\mu^0$.\n\n\n\n\\begin{figure}[!ht]\n\\centering\n\\setlength{\\abovecaptionskip}{0pt}\n\\setlength{\\belowcaptionskip}{0pt}\n\\includegraphics[width=8.3cm]{figures/mgcompare.png}\n\\caption{Comparison GD with Multigrid}\n\\label{fig:Hmesh}\n\\end{figure}\n\n\n\n\n\n", "meta": {"hexsha": "a8e6a346a1c7f6febfbca0a4e86e99b05cbaee11", "size": 6694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.4-1DMG.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.4-1DMG.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.4-1DMG.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.3034825871, "max_line_length": 157, "alphanum_fraction": 0.6407230356, "num_tokens": 2774, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7704786777931324}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath,amssymb}\n\\title{Some matrix exercises: corrections and solutions}\n\\author{Paul Hewson}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Computer exercises for the lab}\n\nMake sure you are comfortable with the matrix operators in R.   Also, be very very sure you can subscript matrices, i.e. use things such as \\text{[,1]} to select column 1, \\text{[,-1]} to select everything \\emph{except} column 1, and \\text{[,2:3]} to select columns 2 and 3.\n\n\\begin{enumerate}\n\n\\item Find (where possible) the determinants and the inverse of the following matrices:\n\n$C_{1} = \\left[ \\begin {array}{cc} 4& 4\\\\\\noalign{\\medskip} 4& 4\\end {array} \\right]$, $C_{2} = \\left[ \\begin {array}{cc} 4& 4.001\\\\\\noalign{\\medskip} 4.001& 4.002\\end {array} \\right]$ and $C_{3} = \\left[ \\begin {array}{cc} 4& 4.001\\\\\\noalign{\\medskip} 4.001& 4.002001\\end {array} \\right] $\n\nVery briefly comment on the magnitude of the difference between $C_{2}^{-1}$ and  $C_{3}^{-1}$ given the only difference between $C_{2}$ and $C_{2}$ amounts to a difference of $0.000001$ in the bottom right position.\n\n\\begin{verbatim}\n> A <- matrix(c(4,4,4,4),2,2)\n> A\n     [,1] [,2]\n[1,]    4    4\n[2,]    4    4\n> det(A)\n[1] 0\n> solve(A)\nError in solve.default(A) : Lapack routine dgesv: system is exactly singular\n> B <- matrix(c(4,4.001,4.001,4.002),2,2)\n> B\n      [,1]  [,2]\n[1,] 4.000 4.001\n[2,] 4.001 4.002\n> det(B)\n[1] -1e-06\n> solve(B)\n         [,1]     [,2]\n[1,] -4002000  4001000\n[2,]  4001000 -4000000\n> C <- matrix(c(4,4.001,4.001,4.002001),2,2)\n> C\n      [,1]     [,2]\n[1,] 4.000 4.001000\n[2,] 4.001 4.002001\n> det(C)\n[1] 3e-06\n> solve(C)\n         [,1]     [,2]\n[1,]  1334000 -1333667\n[2,] -1333667  1333333\n\\end{verbatim}\n\n\\textit{Note that A is singular, the determinant is zero and it can't be inverted.   Also note that the inverses of B and C are very very different - but this is something of a pathological example}\n\n\n\\item Matrix partitioning.   Consider Sterling's financial data held in the R object LifeCycleSavings (see \\texttt{?LifeCycleSavings}).   To make life a little easier, reorder the columns using \\texttt{X <- LifeCycleSavings[,c(2,3,1,4,5)]}.\n\n\\begin{itemize}\n\\item Find the correlation matrix of \\texttt{X} (longhand, using the centering matrix), call this matrix \\texttt{R}\n\n\\begin{verbatim}\n> data(LifeCycleSavings)\n> X <- LifeCycleSavings[,c(2,3,1,4,5)]\n> R <- cor(X)\n> R\n            pop15       pop75         sr        dpi        ddpi\npop15  1.00000000 -0.90847871 -0.4555381 -0.7561881 -0.04782569\npop75 -0.90847871  1.00000000  0.3165211  0.7869995  0.02532138\nsr    -0.45553809  0.31652112  1.0000000  0.2203589  0.30478716\ndpi   -0.75618810  0.78699951  0.2203589  1.0000000 -0.12948552\nddpi  -0.04782569  0.02532138  0.3047872 -0.1294855  1.00000000\n\\end{verbatim}\n\n\\item Partition \\textit{R = cov(X)} following the scheme below such that $\\boldsymbol{X_{11}}$ is a $2 \\times 2$ matrix containing the covariance of \\texttt{pop15} and \\texttt{pop75}, and $\\boldsymbol{X_{22}}$ contains the covariance of \\texttt{sr}, \\texttt{dpi} and \\texttt{ddpi}\n\n\\begin{displaymath}\n\\boldsymbol{R} = \\left( \\begin{array}{l|l} \\boldsymbol{R_{11}} & \\boldsymbol{R_{12}} \\\\ \\hline    \\boldsymbol{R_{21}} & \\boldsymbol{R_{22}} \\end{array} \\right) \n\\end{displaymath}\n\nYou should find for example that  $\\boldsymbol{R_{11}}$ is given by:\n % latex table generated in R 2.3.1 by xtable 1.3-2 package\n% Wed Nov 15 22:15:30 2006\n\\begin{table}[ht]\n\\begin{center}\n\\begin{tabular}{rrr}\n\\hline\n & pop15 & pop75 \\\\\n\\hline\npop15 & 83.75 & $-$10.73 \\\\\npop75 & $-$10.73 & 1.67 \\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\begin{verbatim}\n> R11 <- R[1:2,1:2]\n> R12 <- R[1:2,3:5]\n> R21 <- R[3:5,1:2]\n> R22 <- R[3:5,3:5]\n> R11\n           pop15      pop75\npop15  1.0000000 -0.9084787\npop75 -0.9084787  1.0000000\n> R12\n              sr        dpi        ddpi\npop15 -0.4555381 -0.7561881 -0.04782569\npop75  0.3165211  0.7869995  0.02532138\n\\end{verbatim}\n\n\\item Find the matrix $\\boldsymbol{A}$, where:\n\n\\begin{displaymath}\n\\boldsymbol{A} = \\boldsymbol{R_{22}^{-1}R_{21}R_{11}^{-1}R_{12}}\n\\end{displaymath}\n\n\\begin{verbatim}\nA <- solve(R22) %*% R21 %*% solve(R11) %*% R12\n> A\n                sr        dpi         ddpi\nsr    0.2082835957 0.13567828  0.028218990\ndpi   0.2428243102 0.60736349  0.019316733\nddpi -0.0001528633 0.06307685 -0.001930969\n\\end{verbatim}\n\n\n\\item Find the matrix $\\boldsymbol{B}$ where:\n\n\\begin{displaymath}\n\\boldsymbol{B} = \\boldsymbol{R_{11}^{-1}R_{12}R_{22}^{-1}R_{21}}\n\\end{displaymath}\n\n\\begin{verbatim}\n> B <- solve(R11) %*% R12 %*% solve(R22) %*% R21\n> B\n           pop15      pop75\npop15  0.4471770 -0.3095406\npop75 -0.2362827  0.3665391\n\\end{verbatim}\n\n\n\n%\\begin{itemize}\n\\item Are $\\boldsymbol{A}$ and $\\boldsymbol{B}$ symmetric?   What is the difference between symmetric and asymmetric matrices in terms of their eigenvalues and eigenvectors?\\\\\n\\textit{Note that they are both asymmetric matrices, it just so happens for these particular matrices that the eigenvalues are positive the the eigenvectors are real.   This isn't always the case for asymmetric matrices}\n\n\\item Find the eigenvalues and eigenvectors of $\\boldsymbol{A}$ and $\\boldsymbol{B}$ then find the square roots of the eigenvalues.   \n\n\n\\begin{verbatim}\n> eigen(A)\n$values\n[1]  6.802894e-01  1.334267e-01 -3.516940e-19\n\n$vectors\n            [,1]       [,2]        [,3]\n[1,] -0.28005745 -0.8743085 -0.15327638\n[2,] -0.95591190  0.4395680  0.02986593\n[3,] -0.08831912  0.2058267  0.98773194\n\n> eigen(B)\n$values\n[1] 0.6802894 0.1334267\n\n$vectors\n           [,1]      [,2]\n[1,]  0.7988131 0.7023149\n[2,] -0.6015793 0.7118664\n\n> sqrt(eigen(A)$values)\n[1] 0.8247966 0.3652762       NaN\n> sqrt(eigen(B)$values)\n[1] 0.8247966 0.3652762\n\\end{verbatim}\n\n\\item Do you notice any similarities between the first two eigenvalues from either matrix?\\\\\n\\textit{Note that the square roots of the eigen values are identical.}\n\\end{itemize}\n\n\\item Revisit the \\texttt{wines} data in the \\texttt{Flury} package.   Consider only Y1, Y5, Y6, Y8 and Y9, use matrix algebra to find the means, correlation and covariance of these data.   Compare the eigenvalues and eigenvectors, and the determinants and inverse you get from the covariance matrix and the correlation matrix.\\\\\n\\textit{Part of this is straightforward application of algebra covered in notes.   Remainder follows, eigenvalues and eigenvectors or corrlation matrix and covariance matrix are very very different}\n\n\\begin{verbatim}\n> eigen(cor(X))\n$values\n[1] 1.9816214 1.5230931 0.7636275 0.4807668 0.2508912\n\n$vectors\n           [,1]       [,2]       [,3]         [,4]        [,5]\n[1,] -0.2777688  0.6861076 -0.1803411 -0.008575869  0.64769164\n[2,] -0.5561121 -0.1831683  0.2691167  0.763621722  0.04058118\n[3,] -0.4812999 -0.3654121  0.4287131 -0.604767532  0.29203728\n[4,] -0.5632681  0.3692665 -0.1701835 -0.225349857 -0.68310049\n[5,] -0.2542899 -0.4752074 -0.8260121 -0.016792704  0.16412387\n\n> eigen(cov(X))\n$values\n[1] 2330.125258  814.467485  545.200401    3.584549    1.403159\n\n$vectors\n            [,1]         [,2]        [,3]         [,4]         [,5]\n[1,] -0.05483952  0.735862357  0.67335086  0.007708220  0.045148845\n[2,]  0.50030899  0.604193500 -0.61998120 -0.013591715  0.008928181\n[3,]  0.86393142 -0.303609773  0.40160604 -0.008022325  0.009582822\n[4,]  0.01284463  0.035080362  0.02616497  0.195179471 -0.979706462\n[5,]  0.01187679 -0.006876112 -0.01580852  0.980610251  0.194846828\n\\end{verbatim}\n\n\\item Something to add to what we did last week.   \\texttt{library(car)} opens up some additional functionality:   \n\\begin{verbatim}\nscatterplot.matrix(iris[,-5], smooth = FALSE, \nellipse = TRUE, by.groups = TRUE, groups = iris$Species)\n\\end{verbatim}\nLook at the associated helpfiles and add this function to your eda repertoire.\n\\end{enumerate} \n\n\n\n\n\\section{Consolidation Exercises}\n\nYou should complete these exercises over the next week.   You are guaranteed to meet some simple matrix arithmetic in the exam!   We will briefly go through the answers in class next week.   Don't rely on memorising model solutions.\n\n\\begin{enumerate}\n\\item Which of the following are orthogonal to each other:\n\n\\begin{displaymath}\n\\boldsymbol{x} = \\left( \\begin{array}{r} 1 \\\\ -2 \\\\ 3 \\\\ -4 \\end{array} \\right)\n\\boldsymbol{y} = \\left( \\begin{array}{r} 6 \\\\ 7 \\\\ 1 \\\\ -2 \\end{array} \\right)\n\\boldsymbol{z} = \\left( \\begin{array}{r} 5 \\\\ -4 \\\\ 5 \\\\ 7 \\end{array} \\right)\n\\end{displaymath}\n\nNormalise each of the two orthogonal vectors.\n\n\n\\begin{displaymath}\n\\boldsymbol{x}^{T}\\boldsymbol{y} = \\left( \\begin{array}{rrrr}1 & -2 & 3 & -4 \\end{array} \\right) \\left( \\begin{array}{r} 6 \\\\ 7 \\\\ 1 \\\\ -2 \\end{array} \\right) = \\left( \\begin{array}{rrrr} 1 \\times 6 + & -2 \\times 7 + & 3 \\times 1 + & -4 \\times -2 \\end{array} \\right) = 3\n\\end{displaymath}\ni.e. not orthogonal\n\n\\begin{displaymath}\n\\boldsymbol{x}^{T}\\boldsymbol{z} = \\left( \\begin{array}{rrrr}1 & -2 & 3 & -4 \\end{array} \\right) \\left( \\begin{array}{r} 5 \\\\ -4 \\\\ 5 \\\\ 7 \\end{array} \\right) = \\left( \\begin{array}{rrrr} 1 \\times 5 + & -2 \\times -4 + & 3 \\times 5 + & -4 \\times 7 \\end{array} \\right) = 0\n\\end{displaymath}\ni.e. orthogonal\n\n\\begin{displaymath}\n\\boldsymbol{y}^{T}\\boldsymbol{z} = \\left( \\begin{array}{rrrr}6 & 7 & 1 & -2 \\end{array} \\right) \\left( \\begin{array}{r} 5 \\\\ -4 \\\\ 5 \\\\ 7 \\end{array} \\right) = \\left( \\begin{array}{rrrr} 6 \\times 5 + & 7 \\times -4 + & 1 \\times 5 + & -2 \\times 7 \\end{array} \\right) = -7\n\\end{displaymath}\ni.e. not orthogonal\n\n\n\\begin{eqnarray*}\n\\lVert \\boldsymbol{x} \\rVert &=& \\sqrt{1 + 4 + 9 + 16} = \\sqrt{30} \\\\\n\\lVert \\boldsymbol{y} \\rVert &=& \\sqrt{36 + 49 + 1 + 4} = \\sqrt{90}\\\\\n\\lVert \\boldsymbol{z} \\rVert &=& \\sqrt{25 + 16 + 25 + 49} = \\sqrt{115} \\\\\n\\end{eqnarray*}\n\nNormalise the orthogonal vector, divide by the length of the vector:\n\n\\begin{displaymath}\n\\boldsymbol{y}_{norm} = \\left( \\begin{array}{r} 6/\\sqrt{90} \\\\7/\\sqrt{90} \\\\ 1/\\sqrt{90} \\\\ 2/\\sqrt{90} \\end{array} \\right)\n\\end{displaymath}\n\n\n\\item Find vectors which are orthogonal to:\n\n\n\\begin{displaymath}\n\\boldsymbol{u} =  \\left( \\begin{array}{r} 1 \\\\ 3 \\end{array} \\right)\n\\boldsymbol{v} = \\left( \\begin{array}{r} 2 \\\\ 4 \\\\ -1 \\\\ 2 \\end{array} \\right)\n\\end{displaymath}\n\nAny $w_{1}$ and $w_{2}$ that satisfies $w_{1}+3w_{2}=0$ will be orthogonal to $\\boldsymbol{u}$, e.g. $w = \\left( \\begin{array}{r} 3 \\\\ -1 \\end{array} \\right)$.   For $\\boldsymbol{v}$ we require $2x_{1} + 4x_{2} - x_{3} + 2x_{4}=0$, which can be solved with $\\boldsymbol{x} = \\left( \\begin{array}{r} 0 \\\\ 0 \\\\ 2 \\\\ 1 \\end{array} \\right)$\n\n\\item Find vectors which are orthonormal to:\n\n\n\\begin{displaymath}\n\\boldsymbol{x} =  \\left( \\begin{array}{r} \\frac{1}{\\sqrt{2}} \\\\ 0 \\\\ -\\frac{1}{\\sqrt{2}} \\end{array} \\right)\n\\boldsymbol{y} = \\left( \\begin{array}{r} \\frac{1}{2} \\\\ \\frac{1}{6} \\\\ \\frac{1}{6} \\\\ \\frac{5}{6} \\end{array} \\right)\n\\end{displaymath}\n\nIf $\\boldsymbol{u} = \\left( \\begin{array}{r}u_{1} \\\\ u_{2} \\\\u_{3} \\end{array} \\right)$, then $\\boldsymbol{x}^{T}\\boldsymbol{u} = \\frac{1}{\\sqrt{2}}u_{1}-\\frac{1}{\\sqrt{2}}u_{3}$, so $\\boldsymbol{u} = \\left( \\begin{array}{r} 1 \\\\ 0 \\\\1 \\end{array} \\right)$ is orthogonal, and we only require to normalise it.   $\\lVert \\boldsymbol{u} \\rVert = \\sqrt{1 + 0 + 1} = \\sqrt{2}$.   Consequently, $\\boldsymbol{u} = \\left( \\begin{array}{r} \\frac{1}{\\sqrt{2}} \\\\ 0 \\\\ \\frac{1}{\\sqrt{2}} \\end{array} \\right)$ has length 1 and is orthogonal.\n\nIn a similar way, we find $\\left( \\begin{array}{r} 0 \\\\ 0 \\\\ 5 \\\\ -1 \\end{array} \\right)$, a vector which has length $\\sqrt{25+1}$, so the orthogonal vector of unit length is given by:  $\\left( \\begin{array}{r} 0 \\\\ 0 \\\\ 5/\\sqrt{26} \\\\ -1/\\sqrt{26} \\end{array} \\right)$\n\n\\item What are the determinants of:\n\n\\begin{displaymath}\n(a) \\left( \\begin{array}{rr} 1 & 3 \\\\ 6 & 4 \\end{array} \\right)\n(b) \\left( \\begin{array}{rrr} 3 & 1 & 6 \\\\ 7 & 4 & 5 \\\\ 2 & -7 & 1 \\end{array} \\right)\n\\end{displaymath}\n\nSolutions are (a) -14, (b) -222.\n\n\\item Invert the following matrices:\n\n\\begin{displaymath}\n(a) \\left( \\begin{array}{rrr} 3 & 0 & 0 \\\\ 0 & 4 & 0 \\\\ 0 & 0 & 9 \\end{array} \\right)\n(b) \\left( \\begin{array}{rr} 2 & 3 \\\\ 1 & 5  \\end{array} \\right)\n(c) \\left( \\begin{array}{rrr} 3 & 2 & -1 \\\\ 1 & 4 & 7 \\\\ 0 & 4 & 2 \\end{array} \\right)\n(d) \\left( \\begin{array}{rrr} 1 & 1 & 1 \\\\ 2 & 5 & -1 \\\\ 3 & 1 & -1 \\end{array} \\right)\n\\end{displaymath}\n\nSolutions are (a) $\\left( \\begin{array}{rrr} 0.333 & 0 & 0 \\\\ 0 & 0.25 & 0 \\\\ 0 & 0 & 0.111 \\end{array} \\right)$, note the determinant is 108 (b) $\\left( \\begin{array}{rr} 0.714 & -0.429 \\\\ -0.143 & 0.286  \\end{array} \\right)$ (with a determinant of 7), (c)  $\\left( \\begin{array}{rrr} 0.294 & 0.118 & -0.265 \\\\ 0.029 & -0.088 & 0.325 \\\\ -0.059 & 0.176 & -0.147 \\end{array} \\right)$ (with a determinant of -68) and (d) $ \\left( \\begin{array}{rrr} 0.222 & -0.111 & 0.333 \\\\ 0.056 & 0.222 & -0.167 \\\\ 0.722 & -0.111 & -0.l67 \\end{array} \\right)$ (with a determinant -18)\n\n\n\\item Find eigenvalues and corresponding eigen vectors for the following matrices:\n\n\n\\begin{displaymath}\n\\boldsymbol{a} = \\left( \\begin{array}{rr} 1 & 4\\\\ 2 & 3 \\end{array} \\right)\n\\boldsymbol{b} = \\left( \\begin{array}{rr} 1 & 2 \\\\ 3 & 2  \\end{array} \\right)\n\\boldsymbol{c} = \\left( \\begin{array}{rr} 2 & -2 \\\\ -2 & 5 \\end{array} \\right)\n\\boldsymbol{d} = \\left( \\begin{array}{rr} 2 & 2 \\\\ 2 & 5 \\end{array} \\right)\n\\end{displaymath}\n\n\\begin{displaymath}\n\\boldsymbol{e} = \\left( \\begin{array}{rrr} 1 & 4 & 0\\\\ 4 & 1 & 0 \\\\ 0 & 0 & 1 \\end{array} \\right)\n\\boldsymbol{f} = \\left( \\begin{array}{rrr} 4 & 0 & 0 \\\\ 0  & 9 & 0 \\\\ 0 & 0 & 1  \\end{array} \\right)\n\\boldsymbol{g} = \\left( \\begin{array}{rrr} 13 & -4 & 2\\\\ -4 & 13 & -2 \\\\ 2 & -2 & 10 \\end{array} \\right)\n\\end{displaymath}\n\n\n\\textit{We will run through some solutions in class}\n\n\\item Convert the following covariance matrix (you've seen it earlier) to a correlation matrix, calculate the eigenvalues and eigenvectors and verify that the eigen vectors are orthogonal.\n\n\\begin{displaymath}\n\\boldsymbol{g} = \\left( \\begin{array}{rrr} 13 & -4 & 2\\\\ -4 & 13 & -2 \\\\ 2 & -2 & 10 \\end{array} \\right)\n\\end{displaymath}\n\n\\item If $\\boldsymbol{X} = \\left( \\begin{array}{rr} 2 & 6\\\\ 1 & 3 \\\\ 4 & 2 \\end{array} \\right)$, use matrix procedures to find $cov(\\boldsymbol{X})$ and $cor(\\boldsymbol{X})$.   What is a sum of squares and crossproducts matrix?   What are the eigenvalues and eigenvectors of $cov(\\boldsymbol{X})$ and $cor(\\boldsymbol{X})$?\n\n\\item Find $\\frac{\\lvert| \\begin{array}{rr} 2 & 4\\\\2 & 7 \\end{array} \\rvert}{\\lvert| \\begin{array}{rr} 1 & 9\\\\4 & 5 \\end{array} \\rvert}$.\n\n\\end{enumerate}\n\n\n\\end{document}", "meta": {"hexsha": "9e481fb3d3fa82a85fe9a94d9caaf3b8fe00dbc2", "size": 14533, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/MatrixExercises.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/MatrixExercises.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/MatrixExercises.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": 42.3702623907, "max_line_length": 568, "alphanum_fraction": 0.6435009977, "num_tokens": 5748, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.9086178994073576, "lm_q1q2_score": 0.7704786694185349}}
{"text": "\\subsection{Wind Speed and Wind Directions}\r\n\r\nAs we have mentioned, there are four attributes regarding wind (WSF2, WDF2, WSF5, WDF5) in the data. Among the four, each pair of (WSF, WDF) represents a 2-dim \\emph{vector} (wind vector) in polar coordinates. Sometimes, there is a significant variation of directions between different records of the same day, and thus, we shouldn't take their mean directly.\r\n\r\nTo better summarize the wind vectors, we may consider a natural model about the wind vectors in station $i$:\r\n$$\\vec v_i(t)=\\vec{v}(t)+\\vec u_i+\\vec\\epsilon_i(t),$$\r\nwhere $\\vec{v_i}(t)$ is the wind vector at station $i$ by time $t$, $\\vec u_i$ is a fixed effect for station $i$, and $\\vec \\epsilon_i(t)$ is the error vector.\r\n\r\nWith the assumption that the term $\\vec\\epsilon_i(t)$ has i.i.d. bivariate normal distribution, we may estimate the overall wind vector by estimator\r\n$$\\hat{\\vec v}_i(t)=\\frac1n\\sum_{i=1}^n\\vec v_i(t)$$\r\nwith a constant bias\r\n$$\\vec b=\\frac1n\\sum_{i=1}^n\\vec u_i.$$\r\nSuch bias here can be viewed as a fixed translation of the attribute space (since it is constant), and can thus be omitted in further analyses.\r\n\r\nSince we are only interested in the overall wind condition for Seattle, further analyses would only be concerned with the mean vectors $\\hat{\\vec v}(t)$. For convenience they are still presented in polar coordinates with the same attribute names. (It might be hard to interpret if they are presented in Cartesian coordinates.)\r\n\r\nIt is perhaps remarkable that since we have polar coordinates as attributes, the attribute space would not be flat. In fact, the subspace regarding WDF2 (and the one regarding WDF5 as well) is homeomorphic to $\\mathbb S^1$ instead of $\\mathbb R^1$.", "meta": {"hexsha": "1a2e3920fce8cb60771b58ac0b06fafc7296fa0e", "size": 1731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/wind.tex", "max_stars_repo_name": "shengchenHAO/Weather-Forecast-", "max_stars_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Report/wind.tex", "max_issues_repo_name": "shengchenHAO/Weather-Forecast-", "max_issues_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Report/wind.tex", "max_forks_repo_name": "shengchenHAO/Weather-Forecast-", "max_forks_repo_head_hexsha": "0c81dd5b8b3c4572464b0e0b841ca279ecb0d650", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 101.8235294118, "max_line_length": 360, "alphanum_fraction": 0.7498555748, "num_tokens": 449, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9449947117065458, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7703903870068474}}
{"text": "\\chapter{Linear Systems of Differential Equations}\r\nAlthough we have a good idea on how to solve many single linear differential equations, it's often useful to think about linear systems of equations, like\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tx_1' = 3tx_1 - x_2 + t^2 \\\\\r\n\t\tx_2' = -x_1 + e^tx_2 - e^{2t}\r\n\t\\end{cases}\r\n\t\\to\r\n\t\\begin{bmatrix}\r\n\t\tx_1 \\\\ \r\n\t\tx_2\r\n\t\\end{bmatrix}' = \\begin{bmatrix}\r\n\t\t3t & -1 \\\\\r\n\t\t-1 & e^t\r\n\t\\end{bmatrix} \\begin{bmatrix}\r\n\t\tx_1 \\\\\r\n\t\tx_2\r\n\t\\end{bmatrix} + \\begin{bmatrix}\r\n\t\tt^2 \\\\\r\n\t\t-e^{2t}\r\n\t\\end{bmatrix}.\r\n\\end{equation*}\r\nThis matrix form, $\\vec{x'} = A\\vec{x} + \\vec{f}$, where $A$ is a square matrix, is called normal form.\\\\\r\n\r\n% Solutions to systems\r\n\\input{./linearSystems/solutions/solutions.tex}\r\n% Homogenous\r\n\\input{./linearSystems/homogeneousSystems/homogeneousSystems.tex}\r\n% Non-Homogenous\r\n\\input{./linearSystems/heterogeneousSystems/heterogeneousSystems.tex}\r\n% Higher-order linear diffeq's as systems of 1st order linear diffeq's\r\n\\input{./linearSystems/systemsAndHigherOrder/systemsAndHigherOrder.tex}", "meta": {"hexsha": "66fa11e734bd8fe0b33d61a82993e42a219a02e8", "size": 1057, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/linearSystems.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/linearSystems/linearSystems.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/linearSystems/linearSystems.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": 33.03125, "max_line_length": 155, "alphanum_fraction": 0.6944181646, "num_tokens": 357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825848, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7703109543899525}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Numerical Analysis} \\label{ch:numerical-analysis}\n\\epigraph{``\\itshape{A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.}\"}{--- \\textup{Mitch Ratliffe}, Technology Review, April 1992}\n\nSome systems can be solved analytically in terms of time-dependent coordinates. Other systems are non-linear and the vast majority cannot be solved analytically. This is the case for the restricted three-body problem, \\crefrange{eq:Xdot}{eq:Pdot_Y}. To solve these equations of motion, we must use numerical methods.\n\nThe simplest numerical integration is the first order linear approximation known as the Euler method. There are three variants of the Euler method: explicit, implicit and symplectic. As we will see, the explicit Euler will typically increase the energy, implicit Euler will decrease the energy and the symplectic Euler will oscillate the energy slightly but on average conserve pretty well.\n\nWe will now solve the restricted three-body problem equations of motion, \\crefrange{eq:Xdot}{eq:Pdot_Y}. First we discretize the equations with a linear approximation:\n\n\\begin{align}\n\\Delta X &= +\\dfrac{\\partial H}{\\partial P_X}\\Delta t = (P_X + Y)\\Delta t, \\\\[0.2cm]\n\\Delta Y &= +\\dfrac{\\partial H}{\\partial P_Y}\\Delta t = (P_Y - X)\\Delta t, \\\\[0.2cm]\n\\Delta P_X &= -\\dfrac{\\partial H}{\\partial X}\\Delta t = \\left(P_Y - \\dfrac{(1-k)(k+x)}{((k+x)^2+y^2)^{3/2}} + \\dfrac{k(X-1+k)}{((X-1+k)^2+y^2)^{3/2}}\\right)\\Delta t, \\\\[0.2cm]\n\\Delta P_Y &= -\\dfrac{\\partial H}{\\partial Y}\\Delta t = \\left(-P_X - \\dfrac{(1-k)y}{((k+x)^2+y^2)^{3/2}} - \\dfrac{k y}{((X-1+k)^2+y^2)^{3/2}}\\right)\\Delta t.\n\\end{align}\n\nFrom now on we will use $h$ instead of $\\Delta t$ for the time step size.\n\n\\section{Explicit Euler Algorithm}\nAll new values $(X,Y,P_X,P_Y)_{i+1}$ refer to known values from the previous time step \\\\ $(X,Y,P_X,P_Y)_i$.\n\\begin{align}\nX_{i+1} &= X_i + (P_{X,i} + Y_i)h, \\\\[0.2cm]\nY_{i+1} &= Y_i + (P_{Y,i} - X_i)h , \\\\[0.2cm]\nP_{X,i+1} &= P_{X,i} + \\left(P_{Y,i} - \\dfrac{(1-k)(k+X_i)}{((k+X_i)^2+Y_i^2)^{3/2}} + \\dfrac{k(X_i-1+k)}{((X_i-1+k)^2+Y_i^2)^{3/2}}\\right)h, \\\\[0.2cm]\nP_{Y,i+1} &= P_{Y,i} + \\left(-P_{X,i} - \\dfrac{(1-k)Y_i}{((k+X_i)^2+Y_i^2)^{3/2}} - \\dfrac{k Y_i}{((X_i-1+k)^2+Y_i^2)^{3/2}}\\right)h.\n\\end{align}\n\n\\section{Implicit Euler Algorithm}\nSame as explicit Euler, except that all variables on the right-hand side involved in the time step refers to variables in the new time step, $i+1$. This algorithm would involve finding four roots simultaneously and numerically. Since we know the symplectic to be more correct, we skip the implicit Euler (formula included in Appendix \\ref{app:implicit_euler}).\n\n\\section{Symplectic Euler Algorithm}\nIn the explicit Euler, all quantities from the Hamiltonian derivative on the right hand refer to the old time step \\(i\\). In the implicit, they are all referring to the new time step \\(i+1\\), which results in implicit equations that can typically only be solved numerically.\n\nThe 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}_{i+1} = \\vec{p}_i + h \\pd{H}{\\vec{p}}(q_i, p_{i+1}) \\\\\n        \\vec{p}_{i+1} = \\vec{p}_i - h \\pd{H}{\\vec{q}}(q_i, p_{i+1})\n    \\end{split}\n\\end{equation}\n\nor\n\n\\begin{equation}\n    \\begin{split} \\label{eq:symplectic-euler2}\n        \\vec{q}_{i+1} = \\vec{p}_i + h \\pd{H}{\\vec{p}}(q_{i+1}, p_i) \\\\\n        \\vec{p}_{i+1} = \\vec{p}_i - h \\pd{H}{\\vec{q}}(q_{i+1}, p_i)\n    \\end{split}\n\\end{equation}\nwhere \\(h\\) is the step size, index \\(i\\) designates previous time step and \\(i+1\\) designates new time step.\n\nOne can choose whichever is easier to solve for the equations at hand. We choose \\cref{eq:symplectic-euler2} so we get\n\\begin{align}\n    X_{i+1} &= X_i + h (P_{X,i} + Y_{i+1}), \\label{eq:euler-s-x} \\\\[0.2cm]\n    Y_{i+1} &= Y_i + h (P_{Y,i} - X_{i+1}), \\label{eq:euler-s-y} \\\\[0.2cm]\n    P_{X,i+1} &= P_{X,i} + h \\left(P_{Y,i} - \\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), \\label{eq:euler-s-px} \\\\[0.2cm]\n    P_{Y,i+1} &= P_{Y,i} + h \\left(-P_{X,i} - \\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). \\label{eq:euler-s-py}\n\\end{align}\nWe can first solve \\cref{eq:euler-s-x,eq:euler-s-y} for $X_{i+1}$ and $Y_{y+1}$ (see Appendix \\ref{app:r3b-symplectic-euler} for Mathematica notebook):\n\\begin{align}\nX_{i+1} &= \\dfrac{X_i + h (h P_{Y,i} + P_{X,i} + Y_i)}{1+h^2}, \\label{eq:euler_s_x2} , \\\\[0.5cm]\nY_{i+1} &= \\dfrac{Y_i - h (h P_{X,i} - P_{Y,i} + X_i)}{1+h^2}, \\label{eq:euler_s_y2}.\n\\end{align}\nWe can now start by running \\cref{eq:euler_s_x2}. Next we can freely choose between running \\cref{eq:euler-s-y} and \\cref{eq:euler_s_y2} as both are valid. We will run \\cref{eq:euler-s-y} since it is faster computationally. Then we can run the impulse equations as is.\n\n\nIn summary, we run the symplectic Euler algorithm in the order: \\cref{eq:euler_s_x2}, \\cref{eq:euler-s-y}, \\cref{,eq:euler-s-px}, \\cref{eq:euler-s-py}.\n\n\\section{First Test Runs with First-Order Euler Methods}\nThe explicit and symplectic Euler algorithm was implemented in Python. The first two things we want to investigate are:\n\\begin{enumerate}\n    \\item Does the trajectories look like we expect them to? \n    \\item Is the Hamiltonian conserved?\n\\end{enumerate}\nFor symplectic integrators the trajectories look like we expect them to (see \\ref{fig:r3b_symplectic_euler}), but not for the non-symplectic explicit Euler (see \\ref{fig:r3b_explicit_euler}). The Hamiltonian is not conserved for either first order (Euler) Methods, but $H$ for the symplectic Euler was conserved on average over an orbit in a closed orbit.\nThe simulations in Figure \\ref{fig:r3b_explicit_euler} \\ref{fig:r3b_symplectic_euler} was run with the following parameters:\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python,caption={Initial conditions, step size and duration for initial test run},label={lst:testrun}]\n# Duration and step size\nDURATION = 1.5*(2*np.pi)\nH = 0.0001\n\n# Initial Conditions\nX0=0.5\nY0=0.2\nPX0=0\nPY0=0.5\n\\end{lstlisting}\n\\end{adjustwidth*}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Explicit Euler $(\\mathscr{X},\\mathscr{Y})$ trajectory. Earth in origin, moon orbit in greY, first half of spacecraft trajectory is red, last half is blue.]{\n            \\includegraphics[scale=0.41]{fig/r3b-testing/r3b_y(x)_euler_explicit.pdf}\n            \\label{fig:r3b_y(x)_euler_explicit}\n        }\n        \\subbottom[Explicit Euler $H(t)$.]{\n            \\includegraphics[scale=0.411]{fig/r3b-testing/r3b_H(t)_euler_explicit.pdf}\n            \\label{fig:r3b_H(t)_euler_explicit}\n        }\n        \\caption{Explicit Euler trajectory and Hamiltonian. Ideally the $H(t)$ should be constant, but instead we see temporary dips for every Earth pass, and worse, the spacecraft picks up energy after every pass of Earth. Finally the spacecraft escapes the Earth with no apparent energy input. This is clearly wrong and not a valid trajectory}\n        \\label{fig:r3b_explicit_euler}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Symplectic Euler $(\\mathscr{X},\\mathscr{Y})$ trajectory. Earth in origin, moon orbit in greY, first half of spacecraft trajectory is red, last half is blue.]{\n            \\includegraphics[scale=0.41]{fig/r3b-testing/r3b_y(x)_euler_symplectic.pdf}\n            \\label{fig:r3b_y(x)_euler_symplectic}\n        }\n        \\subbottom[Symplectic Euler $H(t)$.]{\n            \\includegraphics[scale=0.411]{fig/r3b-testing/r3b_H(t)_euler_symplectic.pdf}\n            \\label{fig:r3b_H(t)_euler_symplectic}\n        }\n        \\caption{Symplectic Euler trajectory and Hamiltonian. The first half trajectory is red, the last half is blue. First we note the approximate elliptical orbit as expected. The $H(t)$ shows dips is the spacecraft passes the Earth, but on average over an orbit, $H(t)$ is approximately constant} % FIXME: No it's not constant looking - this needs to be fixed.\n        \\label{fig:r3b_symplectic_euler}\n\\end{figure}\nHaving $H$ conserved on average over an orbit is fine for a closed orbit, but for chaotic orbits around both Earth and Moon, it's not nearly good enough. We want a higher order method to conserve $H$ better, to better gauge the numerical errors, and to allow an adaptive numerical method.\n\nMaking the algorithm select a step size adaptively decreases the run time of a given simulation (though not necessarily the correctness of the solution). This is a big advantage because it allows us to search for many more orbits, which statistically will give us better orbits.\n\n\\section{Symplectic Störmer-Verlet}\nWe will now describe the second-order Störmer-Verlet method \\cite{Hochbruck2008}:\n\\begin{align}\nq_{i+1/2} &= q_i + \\dfrac{h}{2}H_p(q_{i+1/2}, p_i), \\\\\np_{i+1} &= p_i + \\dfrac{h}{2}(H_q(q_{i+1/2}, p_i) + H_q(q_{i+1/2}, p_{i+1})), \\\\\nq_{i+1} &= q_{i+1/2} + \\dfrac{h}{2}H_p(q_{n+1/2}, p_{i+1}).\n\\end{align}\nwhere $H_q$ and $H_p$ denotes the partial derivatives of $H$, which can be expressed in terms of $q_i$ and $p_i$ by Hamilton's equations. Implemented for our equations (using~\\cref{eq:Xdot,eq:Ydot,eq:Pdot_X,eq:Pdot_Y} to express $H_q$ and $H_p$) we get:\n\\begin{align}\nX_{i+1/2} &= X_i + \\dfrac{h}{2} (P_{X,i} + Y_{i+1/2}) , \\label{eq:verlet-implicit-x_1/2} \\\\[0.3cm]\nY_{i+1/2} &= Y_i + \\dfrac{h}{2} (P_{Y,i} - X_{i+1/2}), \\label{eq:verlet-implicit-y_1/2} \\\\[0.8cm]\n%\n%\nP_{X,i+1} &= P_{X,i} + \\dfrac{h}{2} \\left[-\\dot{P}_X(q_{i+1/2},p_i) -\\dot{P}_X(q_{i+1/2},p_{i+1}) \\right], \\label{eq:verlet-implicit-px_1} \\\\[0.3cm]\n%\nP_{Y,i+1} &= P_{Y,i} + \\dfrac{h}{2} \\left[-\\dot{P}_Y(q_{i+1/2},p_i) -\\dot{P}_Y(q_{i+1/2},p_{i+1}) \\right], \\label{eq:verlet-implicit-py_1} \\\\[0.8cm]\n%\n%\nX_{i+1} &= X_{i+1/2} + \\dfrac{h}{2} (P_{X,i+1} + Y_{i+1/2}), \\label{eq:verlet-explicit-x_1} \\\\[0.3cm]\nY_{i+1} &= Y_{i+1/2} + \\dfrac{h}{2} (P_{Y,i+1} - X_{i+1/2}), \\label{eq:verlet-explicit-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 \\(i\\) designates previous time step and \\(i+1\\) designates new time step.\nWe solve solve the first two implicit equations \\cref{eq:verlet-implicit-x_1/2,eq:verlet-implicit-y_1/2} for \\(x_{i+1/2},y_{i+1/2}\\), for which we get\n\n\\begin{equation}\n    X_{i+1/2} = \\frac{h^2 P_{Y,i} + 2 h \\dot{P}_{x,i} + 4 X_i}{4 + h^2} \\label{eq:verlet-explicit-x_1/2}\n\\end{equation}\n\nsee \\cref{app:r3b-verlet} for derivations. Then we solve \\cref{eq:verlet-implicit-px_1,eq:verlet-implicit-py_1} for \\(P_{X,i+1},P_{Y,i+1}\\) for which we get\n\n\\begin{equation}\n    P_{X,i+1} = \\frac{h^2 (2 \\dot{P}_{Y,i} + P_{X,i}) + 4 h \\dot{P}_{X,i} + 4 P_{X,i} }{4 + h^2} \\label{eq:verlet-explicit-px_1}\n\\end{equation}\n\nsee \\cref{app:r3b-verlet} for derivations. Equations \\cref{eq:verlet-explicit-x_1,eq:verlet-explicit-y_1} are explicit, so these can be used directly.\n\nWe can now run the algorithm in the order: \\cref{eq:verlet-explicit-x_1/2}, \\cref{eq:verlet-implicit-y_1/2}, \\cref{eq:verlet-explicit-px_1}, \\cref{eq:verlet-implicit-py_1}, \\cref{eq:verlet-explicit-x_1}, \\cref{eq:verlet-explicit-y_1}.\n\n\n\\section{Adaptive Symplectic Störmer-Verlet}\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 as implemented in listing \\ref{lst:adaptive}\n\\begin{adjustwidth*}{0cm}{-0.4cm}\n\\begin{lstlisting}[language=Python,caption=Adaptive method implemented in python. We accept the Verlet step only if the error is no more than a given tolerance \\texttt{tol}. Subsequently we estimate a new \\texttt{h} that will yield an error of \\texttt{tol} in the next step and use \\texttt{0.8} of this value to avoid frequent rejects. If the step is rejected we reduce the step size by half,label=lst:adaptive]\nif err < tol or h <= h_min:\n\n    # Accept step\n    x = x2\n    y = y2\n    px = px2\n    py = py2\n\n    # Forward time by step\n    t = t+h\n    h = max(h_min, h*max(0.1, 0.8*sqrt(tol/err)))\n\nelse:\n    # No accept, reduce h to half\n    h = max(h_min, 0.5*h)\n\\end{lstlisting}\n\\end{adjustwidth*}\nFor 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. For comparison a simulation was run with same initial conditions using the adaptive and non-adaptive algorithm, see Figure \\ref{fig:non-adaptive-steP_error} - \\ref{fig:adaptive-steP_error}. Position plot \\ref{fig:adaptive-xY_XY} shown for completeness.\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Non-adaptive symplectic Verlet step size.]{\n            \\includegraphics[scale=0.41]{fig/adaptive/steP_fixed_h.pdf}\n        }\n        \\subbottom[Non-adaptive symplectic Verlet error per step.]{\n            \\includegraphics[scale=0.41]{fig/adaptive/err_fixed_h.pdf}\n        \\label{fig:non-adaptive-error}\n        }\n        \\caption{Non-adaptive method step size and error per step. Step size is fixed and as a result the error varies. All the work spend on calculating the many steps with lower error than $10^{-9}$ in \\ref{fig:non-adaptive-error} are wasted since the error spikes to somewhere $10^{-8}$ and $10^{-7}$ during a close fly-bY, which might invalidate all decimals after the 7th decimal on the non-adaptive method. The solutions are practically identical, but the adaptive is much faster}\n        \\label{fig:non-adaptive-steP_error}\n\\end{figure}\n\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Adaptive symplectic Verlet step size.]{\n            \\includegraphics[scale=0.41]{fig/adaptive/steP_adaptive.pdf}\n        \\label{fig:adaptive-step size}    \n        }\n        \\subbottom[Adaptive symplectic Verlet error per step.]{\n            \\includegraphics[scale=0.41]{fig/adaptive/err_adaptive.pdf}\n        }\n        \\caption{The adaptive method constantly varies the step-size to ensure a constant error around $10^{-9}$. As a result it takes longer steps when there is less change in the variables, in the space far from the bodies, and shorter steps when passing close by the Earth or Moon}\n        \\label{fig:adaptive-steP_error}\n\\end{figure}\n\n\\begin{figure}\n    \\centering\n        \\subbottom[Non-adaptive symplectic Verlet $(X,y)$ trajectory.]{\n            \\includegraphics[scale=0.5]{fig/adaptive/_X-Y_fixed_h.pdf}\n        }\n        \\subbottom[Non-adaptive symplectic Verlet $(\\mathscr{X},\\mathscr{Y})$ trajectory.]{\n            \\includegraphics[scale=0.5]{fig/adaptive/X-Y_fixed_h.pdf}\n        }\n        \\caption{The trajectories of same initial conditions for the adaptive and non-adaptive method was visually indistinguishable. Included for context to Figure \\ref{fig:non-adaptive-steP_error} - \\ref{fig:adaptive-steP_error}}\n        \\label{fig:adaptive-xY_XY}\n\\end{figure}\n\n\nNote on the step size Figure \\ref{fig:adaptive-step size} that the adaptive ends up with constant step size at the end at 40 days once captured by the Moon. Thus when we are in circular orbit around a single bodY, we don't gain much by using adaptive methods. However as the spacecraft are in free space far away from both Earth/Moon, we gain a lot by taking longer steps (raising the step size). However as we make close passes to Earth or Moon, then the step size dips sharply to maintain constant error. We see this around day 9, 21 and 33 in \\ref{fig:adaptive-step size}. For most simulations, the adaptive method ran 10-100 times faster.\n\nThe code for the full Python implementation is in Appendix \\ref{app:code-r3b}.\n", "meta": {"hexsha": "c4704875cbc8c6b899a5f276c6897efe41d43859", "size": 16546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/chapters/Numerical_Methods.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/chapters/Numerical_Methods.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/chapters/Numerical_Methods.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": 67.8114754098, "max_line_length": 642, "alphanum_fraction": 0.6943067811, "num_tokens": 5459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7703109487600753}}
{"text": "\\section{Performance analysis}\n\\label{sec:performance_analysis}\n\nIn this section we analyze how the \\emph{execution time} varies with respect to the number of countries $C$ and the number of individuals $N$.\nFrom a theoretical perspective, it is easy to see that the complexity of the algorithm is dominated by the main loop, let us define\n\\begin{itemize}\n    \\item $S = \\lfloor t_{target} / t_{step} \\rfloor$ the number of iterations\n    \\item $C$ the number of countries\n    \\item $N$ the number of individuals\n\\end{itemize}\nWe further assume that individuals are distributed uniformly, thus having $N/C$ individuals for each country.\nEach iteration of the loop is characterized by different phases, detailed in section \\ref{sec:alg_desc}, which can be divided in two categories of complexity:\n\\begin{itemize}\n    \\item \\emph{update exposure} compares each susceptible individuals against, at most, each infected one. The number of checks can be upper-bounded by $\\bigO((N/C)^2)$.\n    \\item all the other steps perform a single scan of the lists of individuals at each country, thus having a complexity $\\bigO(N/C)$.\n\\end{itemize}\nWe conclude that the execution time $T$, assuming that all processes run in parallel, is upper-bounded by \\[T = \\bigO \\left(S \\frac{N^2}{C^2} \\right)\\].\n\n\\subsection{Varying the countries}\nIf we fix the number of iterations and of individuals, we expect to get a time complexity of $\\bigO(1/C^2)$. In other words, the advantage is that $N$ is split between the countries and only individuals in the same country are checked against each other.\n\nWe performed several simulations with \\num{30000} individuals in the same $4096 \\times 4096$ world, which we split horizontally between 1 and 20 countries. Each simulation spanned a single day with a step of \\SI{60}{s} (1440 iterations). The measured execution times in figure \\ref{fig:profile_countries} show a quadratic decay, matching our expectations.\n\n\\begin{figure}[p]\n    \\begin{subfigure}[c]{.6\\textwidth}\n        \\begin{tikzpicture}\n            \\begin{axis}[\n                xlabel=Number of countries,\n                ylabel=Execution time (seconds),\n                legend pos=north east,\n            ]\n                \\addplot\n                    [blue]\n                    table[x=countries, y=elapsed, col sep=comma]\n                    {tables/profile_countries_1_20.csv};\n                \\addplot\n                    [black, dashed]\n                    table[x=countries, y expr=136.7625 + 2899.99 / \\thisrow{countries}^2 , col sep=comma]\n                    {tables/profile_countries_1_20.csv};\n                \\legend{real, $\\bigO(1/C^2)$}\n            \\end{axis}\n        \\end{tikzpicture}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}[c]{.35\\textwidth}\n        \\csvreader[\n            tabular=c c,\n            table head=\\toprule countries & exec. time \\\\ \\midrule,\n            table foot=\\bottomrule]%\n        {tables/profile_countries_1_20.csv}%\n        {countries=\\countries, elapsed_latex=\\elapsed}%\n        {\\countries & \\elapsed}\n    \\end{subfigure}\n    \\caption{Execution time when splitting computation between countries}\n    \\label{fig:profile_countries}\n\\end{figure}\n\n\\subsection{Varying the individuals}\nIf we fix the number of iterations and of countries, we expect the time complexity to be about $\\bigO(N^2)$, or slightly lower since we have some optimizations.\n\nWe performed several simulations with 4 countries (the number of threads of our machine), spanning a single day with a \\SI{60}{s} step (1440 iterations). We varied the number of individuals from \\num{10000} to \\num{60000} with a \\num{5000} increment. The challenge here was to also vary the world size so that the simulation did not terminate early due to a lack of infected individuals. We found that the heuristic $W = L = 20 \\sqrt{N}$ works well in our case. The results are shown in figure \\ref{fig:profile_individuals}, and they agree with our expectations.\n\n\\begin{figure}[p]\n    \\begin{subfigure}[c]{.6\\textwidth}\n        \\begin{tikzpicture}\n            \\begin{axis}[\n                xlabel=Number of individuals,\n                ylabel=Execution time (seconds),\n                legend pos=north west,\n            ]\n                \\addplot\n                    [blue]\n                    table[x=individuals, y=elapsed, col sep=comma]\n                    {tables/profile_individuals_10000_60000.csv};\n                \\addplot\n                    [black, dashed]\n                    table[x=individuals, y expr=-60.0211 + 9.479e-7 * \\thisrow{individuals}^2 , col sep=comma]\n                    {tables/profile_individuals_10000_60000.csv};\n                \\legend{real, $\\bigO(N^2)$}\n            \\end{axis}\n        \\end{tikzpicture}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}[c]{.35\\textwidth}\n        \\csvreader[\n            tabular=c c,\n            table head=\\toprule individuals & exec. time \\\\ \\midrule,\n            table foot=\\bottomrule]%\n        {tables/profile_individuals_10000_60000.csv}%\n        {individuals=\\individuals, elapsed_latex=\\elapsed}%\n        {\\num{\\individuals} & \\elapsed}\n    \\end{subfigure}\n    \\caption{Execution time when increasing number of individuals}\n    \\label{fig:profile_individuals}\n\\end{figure}", "meta": {"hexsha": "6858520a5c075043f7ab868d362c9730d15f8e70", "size": 5221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections_report/performance_analysis.tex", "max_stars_repo_name": "fuljo/my-population-infection", "max_stars_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "report/sections_report/performance_analysis.tex", "max_issues_repo_name": "fuljo/my-population-infection", "max_issues_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/sections_report/performance_analysis.tex", "max_forks_repo_name": "fuljo/my-population-infection", "max_forks_repo_head_hexsha": "30d2c487afe73516e918eb733920a344b6510905", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.9578947368, "max_line_length": 562, "alphanum_fraction": 0.6573453361, "num_tokens": 1291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425399873764, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.7703109468961917}}
{"text": "\\section*{Integrals and Derivatives}\n\n\\subsection*{Table of base integrals}\n\\bgroup\n    \\def\\arraystretch{1.3}\n    \\begin{longtable}{ll}\n        \\toprule\n        Ableitung & Integral \\\\\n        \\hline\n        \\midrule\n\n        \\endhead\n        \\endfoot\n        \\endlastfoot\n\n        % -------------------------------------------------------------------------------------\n        % Basic shit\n        % -------------------------------------------------------------------------------------\n        $\\frac{d}{dx} c = 0$ &\n        $\\int 0\\,dx = c$\n        \\\\\n        $\\frac{d}{dx} x = 1$ &\n        $\\int 1\\,dx = x + c$\n        \\\\\n        $\\frac{d}{dx} x^n = (n-1)x^{n-1}, n\\not=0$ &\n        $\\int x^n\\,dx = \\frac{1}{n+1} x^{n+1} + c$\n        \\\\\n        $\\frac{d}{dx} \\ln{x} = \\frac{1}{x}, x > 0$ &\n        $\\int \\frac{1}{x}\\,dx = \\ln|x| + c$\n        \\\\\n        $\\frac{d}{dx} \\ln{-x} = \\frac{-1}{-x} = \\frac{1}{x}, x < 0$ &\n        $\\int \\frac{1}{x}\\,dx = \\ln|x| + c$\n        \\\\\n\n        % -------------------------------------------------------------------------------------\n        % Exponents\n        % -------------------------------------------------------------------------------------\n        \\midrule\n        $\\frac{d}{dx} e^x = e^x$ &\n        $\\int e^x\\,dx = e^x + c$\n        \\\\\n        $\\frac{d}{dx} a^x = a^x \\ln{a}$ &\n        $\\int a^x\\,dx = \\frac{1}{\\ln{a}} a^x + c, a \\neq 1$\n        \\\\\n\n        % -------------------------------------------------------------------------------------\n        % Trig functions\n        % -------------------------------------------------------------------------------------\n        \\midrule\n        $\\frac{d}{dx} \\sin{x} = \\cos{x}$ &\n        $\\int \\cos{x}\\,dx = \\sin{x} + c$\n        \\\\\n        $\\frac{d}{dx} \\cos{x} = -\\sin{x}$ &\n        $\\int \\sin{x}\\,dx = -\\cos{x} + c$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\tan{x} = \\frac{1}{\\cos^2{x}} = 1 + \\tan^2{x}$} &\n        $\\int \\frac{1}{\\cos^2{x}}\\,dx = \\tan{x} + c$ \\\\* &\n        $\\int \\tan^2{x}\\,dx = \\tan{x}-x + c$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\cot{x} = -\\frac{1}{\\sin^2{x}} = -1 - \\cot^2{x}$} &\n        $\\int \\frac{1}{\\sin^2{x}}\\,dx = -\\cot{x} + c$ \\\\* &\n        $\\int \\cot^2{x}\\,dx = -\\cot{x}-x + c$\n        \\\\\n        \\midrule\n        &\n        $\\int \\cos^2{x}\\,dx = \\frac{1}{2}\\cos{(x)}\\sin{(x)}+\\frac{1}{2}x + c$\n        \\\\\n        &\n        $\\int \\sin^2{x}\\,dx = \\frac{1}{2}x-\\frac{1}{2}\\cos{(x)}\\sin{(x)} + c$\n        \\\\\n\n        % -------------------------------------------------------------------------------------\n        % Inverse trig functions\n        % -------------------------------------------------------------------------------------\n        \\midrule\n        $\\frac{d}{dx} \\arcsin{x} = \\frac{1}{\\sqrt{1-x^2}}$ &\n        $\\int \\frac{1}{\\sqrt{1-x^2}}\\,dx = arcsin{x} + c_1$\n        \\\\\n        $\\frac{d}{dx} \\arccos{x} = -\\frac{1}{\\sqrt{1-x^2}}$ &\n        $\\int \\frac{1}{\\sqrt{1-x^2}}\\,dx = -\\arccos{x} + c_2$\n        \\\\\n        $\\frac{d}{dx} \\arctan{x} = \\frac{1}{1+x^2}$ &\n        $\\int \\frac{1}{1+x^2}\\,dx = \\arctan{x} + c_1$\n        \\\\\n        $\\frac{d}{dx} \\arccot{x} = -\\frac{1}{1+x^2} $ &\n        $\\int \\frac{1}{1+x^2} = -\\arccot{x} + c_2$\n        \\\\\n     \n        % -------------------------------------------------------------------------------------\n        % Hyperbolic trig functions\n        % -------------------------------------------------------------------------------------\n        \\midrule\n        $\\frac{d}{dx} \\sinh{x} = \\cosh{x}$ &\n        $\\int \\cosh{x}\\,dx = \\sinh{x} + c$\n        \\\\\n        $\\frac{d}{dx} \\cosh{x} = \\sinh{x}$ &\n        $\\int \\sinh{x}\\,dx = \\cosh{x} + c$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\tanh{x} = \\frac{1}{\\cosh^2{x}} = 1 - \\tanh^2{x}$} &\n        $\\int \\frac{1}{\\cosh^2{x}}\\,dx = \\tanh{x} + c$ \\\\* &\n        $\\int \\tanh^2{x}\\,dx = x - \\tanh{x} + c$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\coth{x} = -\\frac{1}{\\sinh^2{x}} = 1 - \\coth^2{x}$} &\n        $\\int \\frac{1}{\\sinh^2{x}}\\,dx = -\\coth{x} = c$ \\\\* &\n        $\\int \\coth^2{x}\\,dx = x - \\coth{x} + c$\n        \\\\\n        \\midrule\n        &\n        $\\int \\cosh^2{x}\\,dx = \\frac{1}{2}\\cosh{(x)}\\sinh{(x)}+\\frac{1}{2}x + c$\n        \\\\\n        &\n        $\\int \\sinh^2{x}\\,dx = \\frac{1}{4}\\sinh{(2x)}-\\frac{1}{2}x + c$\n        \\\\\n\n        % -------------------------------------------------------------------------------------\n        % Inverse hyperbolic trig functions\n        % -------------------------------------------------------------------------------------\n        \\midrule\n        \\multirow{2}{*}{$\\frac{d}{dx} \\arsinh{x} = \\frac{1}{\\sqrt{x^2+1}}$} &\n        $\\int \\frac{1}{\\sqrt{x^2+1}}\\,dx = \\arsinh{x} + c$ \\\\* &\n        $=\\ln{\\left(x + \\sqrt{x^2+1}\\right)} + c$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\arcosh{x} = \\frac{1}{\\sqrt{x^2-1}}$} &\n        $\\int \\frac{1}{\\sqrt{x^2-1}}\\,dx = \\arcosh{x} + c$ \\\\* &\n        $=\\ln{\\left(x + \\sqrt{x^2-1}\\right)} + c, x > 1$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\artanh{x} = \\frac{1}{1-x^2}, |x| < 1$} &\n        $\\int \\frac{1}{1-x^2}\\,dx = \\artanh{x} + c$ \\\\* &\n        $=\\frac{1}{2}\\ln{\\frac{1+x}{1-x}} + c, |x| < 1$\n        \\\\\n        \\multirow{2}{*}{$\\frac{d}{dx} \\arcoth{x} = \\frac{1}{1-x^2}, |x| > 1$} &\n        $\\int \\frac{1}{1-x^2}\\,dx = \\arcoth{x} + c$ \\\\* &\n        $=\\frac{1}{2}\\ln{\\frac{x+1}{x-1}} + c, |x| > 1$\n        \\\\\n\n        % -------------------------------------------------------------------------------------\n        % Substitution, partial integration\n        % -------------------------------------------------------------------------------------\n\n        \\bottomrule\n    \\end{longtable}\n\n\\egroup\n\n\n\\subsection*{Important operations}\n\\bgroup\n    \\def\\arraystretch{1.3}\n    \\begin{tabular}{ll}\n\n        \\multirow{2}{*}{Product Rule of Derivatives} &\n        $f(x)' = (g(x)h(x)i(x))'$ \\\\* &\n        $\\hspace{5mm} = g'(x)h(x)i(x) + g(x)h'(x)i(x) + g(x)h(x)i'(x)$\n        \\\\\n\n        Quotient Rule of Derivatives &\n        $f(x)' = \\frac{g(x)}{h(x)} = \\frac{g'(x)h(x) - g(x)h'(x)}{h^2(x)}$\n        \\\\\n\n        &\\\\\n\n        \\multirow{2}{*}{Substitution} &\n        $\\int_a^b f[u(x)]u'(x)\\,dx = \\int_{u(a)}^{u(b)} f(z)\\,dz$ \\\\* &\n        $\\hspace{4mm}\\textrm{with}\\hspace{4mm} z = u(x)$\n        \\\\\n\n        Partial Integration &\n        $\\int_a^a u(x)v'(x)\\,dx = u(x)v(x)\\rvert_a^b - \\int_a^b u'(x)v(x)\\,dx$\n        \\\\\n    \\end{tabular}\n\\egroup\n\n\n\\subsection*{Substitutions}\n\n\\bgroup\n    \\def\\arraystretch{1.1}\n    \\begin{longtable}{ll}\n        \\toprule\n        Integral Type & Substitution \\\\\n        \\midrule\n\n        \\endhead\n        \\endfoot\n        \\endlastfoot\n\n        \\multirow{2}{*}{$\\int f(ax+b)\\,dx = \\frac{1}{a}\\int f(z)\\,dz$} &\n        $z=ax+b$ \\\\* &\n        $dx = \\frac{1}{a}\\,dz$\n        \\\\\n\n        & \\\\\n\n        \\multirow{2}{*}{$\\int f(\\varphi(x))^n \\cdot \\varphi'(x)\\,dx = \\frac{(\\varphi(x))^{n+1}}{n+1} + c$} &\n        $z=\\varphi(x)$ \\\\* &\n        $dx = \\frac{dz}{\\varphi'(x)}$\n        \\\\\n\n        & \\\\\n\n        \\multirow{2}{*}{$\\int \\frac{\\varphi'(x)}{\\varphi(x)}\\,dx = \\ln|\\varphi(x)| + c$} &\n        $z=\\varphi(x)$ \\\\* &\n        $dx = \\frac{dz}{\\varphi'(x)}$\n        \\\\\n\n        & \\\\\n\n        \\multirow{3}{*}{$\\int f\\left(x, \\sqrt{a^2-x^2}\\right)\\,dx$} &\n        $x = a\\sin{z}$ \\\\* &\n        $dx = a\\cos{z}\\,dz$ \\\\* &\n        $\\sqrt{a^-x^2} = a\\cos{z}$\n        \\\\\n\n        & \\\\\n\n        \\multirow{3}{*}{$\\int f\\left(x, \\sqrt{a^2+x^2}\\right)\\,dx$} &\n        $x = a\\sinh{z}$ \\\\* &\n        $dx = a\\cosh{z}\\,dz$ \\\\* &\n        $\\sqrt{a^2+x^2} = a\\cosh{z}$\n        \\\\\n\n        & \\\\\n\n        \\multirow{3}{*}{$\\int f\\left(x, \\sqrt{x^2-a^2}\\right)\\,dx$} &\n        $x = a\\cosh{z}$ \\\\* &\n        $dx = a\\sinh{z}\\,dz$ \\\\* &\n        $\\sqrt{x^2-a^2} = a\\sinh{z}$\n        \\\\\n\n        \\bottomrule\n    \\end{longtable}\n\\egroup\n\n\n\\subsection*{Lathed Bodies}\n\n\\bgroup\n    \\def\\arraystretch{1.2}\n    \\begin{tabular}{ll}\n        Volume, X axis rotation: &\n        $V_x = \\pi\\int_a^b\\left(f(x)\\right)^2\\,dx$ \\\\\n\n        Volume, Y axis rotation: &\n        $V_y = \\pi\\int_a^b\\left(f^{-1}(y)\\right)^2\\,dy$ \\\\\n        & ($f(x) = f^{-1}(y)$) (Invert function first) \\\\\n\n        Arc length: &\n        $L = \\int_a^b \\sqrt{1+\\left(f'(x)\\right)^2}\\,dx$ \\\\\n\n        Lateral surface: &\n        \\\\\n    \\end{tabular}\n\\egroup\n", "meta": {"hexsha": "1d45e93ea500bd7d480004b399468f0472dd44ac", "size": 8255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/integrals.tex", "max_stars_repo_name": "TheComet93/analysis", "max_stars_repo_head_hexsha": "c8cbc5082d58161547eeb781f774a9e7b9a88898", "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": "sections/integrals.tex", "max_issues_repo_name": "TheComet93/analysis", "max_issues_repo_head_hexsha": "c8cbc5082d58161547eeb781f774a9e7b9a88898", "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": "sections/integrals.tex", "max_forks_repo_name": "TheComet93/analysis", "max_forks_repo_head_hexsha": "c8cbc5082d58161547eeb781f774a9e7b9a88898", "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": 32.5, "max_line_length": 108, "alphanum_fraction": 0.3296184131, "num_tokens": 2952, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026505426832, "lm_q2_score": 0.8397339716830606, "lm_q1q2_score": 0.770290197975606}}
{"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 7}\n\\author{Saket Choudhary\\\\skchoudh@usc.edu}\n\n\\begin{document}\n\\maketitle \n\n\\begin{align*}\nY_i &= \\beta_0+\\beta_1X_i+\\epsilon_i\\\\\n\\epsilon_i&=Y_i - \\beta_0-\\beta_1X_i\\\\\n\\epsilon_i^2&=(Y_i - \\beta_0-\\beta_1X_i)^2\\\\\nQ&=\\sum_i\\epsilon_i^2\\sum_i(Y_i - \\beta_0-\\beta_1X_i)^2\\\\\n\\end{align*}\n\nWe want to minimize the residual $\\epsilon_i=Y_i - \\beta_0-\\beta_1X_i = Y_i-\\hat{Y_i}$ so $\\frac{\\partial \\sum_i\\epsilon_i^2}{\\partial \\beta_0}=\\frac{\\partial \\sum_i\\epsilon_i^2}{\\partial \\beta_1}=0$\n\\begin{align*}\n\\frac{\\partial Q}{\\partial \\beta_0} &= -2\\sum_i(Y_i - \\beta_0-\\beta_1X_i)=0\\\\\n\\hat{\\beta_0} &= \\bar{Y}-\\hat{\\beta_1}\\bar{X}\n\\end{align*}\n\n\\begin{align*}\n\\frac{\\partial Q}{\\partial \\beta_1} &= -2\\sum_iX_i(Y_i - \\beta_0-\\beta_1X_i)=0\\\\\n\\sum_iX_i(Y_i - \\hat{\\beta_0}-\\hat{\\beta_1}X_i)&=0\\\\\n\\sum_iX_i(Y_i - \\bar{Y}+\\hat{\\beta_1}\\bar{X}-\\hat{\\beta_1}X_i)&=0\\\\\n\\hat{\\beta_1} &= \\frac{\\sum_iX_i(Y_i-\\bar{Y})}{\\sum_iX_i(X_i-\\bar{X})}\n\\end{align*}\n\nUsing $\\sum \\bar{X}(X_i-\\bar{X}) =0$ $\\implies$ $\\sum X_i(X_i-\\bar{X})=\\sum (X_i-\\bar{X})(X_i-\\bar{X})$\nand using $\\sum \\bar{X}(Y_i-\\bar{Y}) =0$ we get $\\sum_iX_i(Y_i-\\bar{Y}) = \\sum_i(X_i-\\bar{X})(Y_i-\\bar{Y})$\n\nand hence $\\hat{\\beta_1} = \\frac{\\sum_i(X_i-\\bar{X})(Y_i-\\bar{Y})}{\\sum_i(X_i-\\bar{X})^2}$\n\n\\begin{align*}\nE[\\hat{\\beta_0}] &= E[\\bar{Y}]-\\bar{X}E[\\hat{\\beta_1}]\\\\\nE[\\bar{Y}] &= E[\\beta_0+\\beta_1\\bar{X}+1/n\\sum_i \\epsilon_i] \\\\\n&=\\beta_0+\\beta_1\\bar{X}\n\\end{align*}\n\nNow consider $E[\\hat{\\beta_1}] = \\frac{\\sum_i(X_i-\\bar{X})(EY_i-E\\bar{Y})}{\\sum_i(X_i-\\bar{X})^2} = \\frac{\\sum_i(X_i-\\bar{X})(\\beta_1 X_i-\\beta_1 \\bar{X})}{\\sum_i(X_i-\\bar{X})^2} = \\beta_1$\n\nusing which we get:\n$$\nE[\\hat{\\beta_0}] = E[\\bar{Y}]-\\bar{X}E[\\hat{\\beta_1}] = \\beta_0 + \\beta_1 \\bar{X} - \\beta_1\\bar{X} = \\beta_0\n$$\n\n\\section*{Problem 2}\n\\begin{align*}\nVar(\\hat{\\beta_1}) &= \\frac{1}{(\\sum(X_i-\\bar{X})^2)^2} Var(\\sum_i(X_i-\\bar{X})(Y_i-\\bar{Y}))\\\\\n&=\\frac{1}{(\\sum(X_i-\\bar{X})^2)^2} Var(\\sum_i(X_i-\\bar{X})(Y_i))\\\\\n&= \\frac{1}{(\\sum(X_i-\\bar{X})^2)^2} \\sum_i(X_i-\\bar{X})^2Var(Y_i)\\\\ \n&= \\frac{1}{(\\sum(X_i-\\bar{X})^2)^2} \\sum_i(X_i-\\bar{X})^2\\sigma^2\\\\ \n&= \\frac{\\sigma^2}{(\\sum(X_i-\\bar{X})^2)}\\\\ \n\\end{align*}\n\n\\begin{align*}\n\\hat{\\beta_0} &= \\bar{Y}-\\hat{\\beta_1}\\bar{X}\\\\\nVar(\\hat{\\beta_0}) &= Var(\\bar{Y}) + \\bar{X}^2Var(\\hat{\\beta_1})\\\\\n&= \\frac{\\sigma^2}{n} + \\bar{X}^2(\\frac{\\sigma^2}{(\\sum(X_i-\\bar{X})^2)})\n\\end{align*}\n\n\\section*{Problem 3}\n\\begin{align*}\nY_i &= \\beta_0 + \\beta_1X_i + \\epsilon_i\\\\\n\\hat{Y_i} &= {\\beta_0} + {\\beta_1}X_i\\\\\n\\frac{\\partial Q}{\\partial \\beta_0} &= -2\\sum_i(Y_i - \\beta_0-\\beta_1X_i)=-2\\sum_i(Y_i - \\hat{Y_i})=0\\\\\n\\frac{\\partial Q}{\\partial \\beta_1} &= -2\\sum_iX_i(Y_i - \\beta_0-\\beta_1X_i)=0\\\\\n&= \\sum_i(\\hat{Y_i}/\\beta_1-\\beta_0/\\beta_1)(Y_i-\\hat{Y_i})=0\\\\\n&\\implies \\sum_i(\\hat{Y_i})(Y_i-\\hat{Y_i})=0\\\\\n\\end{align*}\n\n\nNow, \n\\begin{align*}\n\\sum_i(Y_i-\\bar{Y})^2 &= \\sum_(Y_i-\\hat{Y_i}+\\hat{Y_i}-\\bar{Y})^2\\\\\n&= \\sum(Y_i-\\hat{Y_i})^2+\\sum_i(\\hat{Y_i}-\\bar{Y})^2 + 2\\sum_i(Y_i-\\hat{Y_i})(\\hat{Y_i}-\\bar{Y})\\\\\n&= \\sum(Y_i-\\hat{Y_i})^2+\\sum_i(\\hat{Y_i}-\\bar{Y})^2 + 2\\sum_i\\hat{Y_i}(Y_i-\\hat{Y_i}) - 2\\sum_i\\bar{Y}(Y_i-\\hat{Y_i})\\\\\n&= \\sum(Y_i-\\hat{Y_i})^2+\\sum_i(\\hat{Y_i}-\\bar{Y})^2 \n\\end{align*}\n\nwhere the two last terms are zero using the properties derived previous to the last set of equations\n\n\\section*{Problem 4}\n\\begin{align*}\nr &= \\frac{\\sum_i(x_i-\\bar{x})(y_i-\\bar{y})}{\\sqrt{\\sum_i(x_i-\\bar{x})^2\\sum_i(y_i-\\bar{y})^2 }}\\\\\nr^2 &= \\frac{(\\sum_i(x_i-\\bar{x})(y_i-\\bar{y}))^2}{{\\sum_i(x_i-\\bar{x})^2\\sum_i(y_i-\\bar{y})^2 }} = \\frac{s_{xy}^2}{s_{xx}s_{yy}}\\\\\nR^2 &= 1- \\frac{SSE}{SST} = \\frac{SSR}{SST}\\\\\nSSE(rror) &= \\sum_i(y_i-\\hat{y_i})^2\\\\\nSST(otal) &= \\sum_i(y_i-\\bar{y})^2\\\\\nSSR(egression) &= \\sum_i(\\hat{y_i}-\\bar{y})^2\n\\end{align*}\n\nConsider $y=a+bx$ then from the first problem we have:\n$b = \\frac{s_{xy}}{s_{xx}}$\n\n\\begin{align*}\nSSR &= \\sum_i(\\hat{y_i}-\\bar{y})^2\\\\\n&= \\sum_i(a+bx_i-\\bar{y})^2\\\\\n&= \\sum(\\bar{y}-b\\bar{x}+bx_i-\\bar{y})^2\\\\\n&= b^2s_{xx}\\\\\n&= \\frac{s_{xy}^2}{s_{xx}^2}s_{xx}\\\\\n&= \\frac{s_{xy}^2}{s_{xx}}\\\\\n\\end{align*}\n\\begin{align*}\nR^2 &= \\frac{SSR}{SST}\\\\\n&= \\frac{\\frac{s_{xy}^2}{s_{xx}}}{s_{yy}}\\\\\n&= \\frac{s_{xy}^2}{s_{xx}s_{yy}}\\\\\n&=r^2\n\\end{align*}\n\\section*{Problem 5}\n\\begin{align*}\nL(\\sigma^2,\\beta_0,\\beta_1) &= (2\\pi\\sigma^2)^{-\\frac{n}{2}}\\prod_iexp(-\\frac{1}{2\\sigma^2}(y_i-\\beta_0-\\beta_1x_i)^2)\\\\\n\\log(L) & = -\\frac{n}{2}\\log(2\\pi) - n \\log\\sigma^2 -\\frac{1}{2\\sigma^2}\\sum_i(y_i-\\beta_0-\\beta_1x_i)^2\\\\\n\\frac{\\partial \\log L}{\\partial \\beta_0}|^{\\beta_{MLE}} &= -\\frac{-2}{2\\sigma^2}\\sum_i(y_i-\\beta_0-\\beta_1x_i) \\\\\n&\\implies \\beta_0^{MLE} = \\bar{Y}-\\beta_1^{MLE}\\bar{X}\\\\\n\\frac{\\partial \\log L}{\\partial \\beta_1}|^{\\beta_{MLE}} &= -\\frac{-2}{2\\sigma^2}\\sum_ix_i(y_i-\\beta_0-\\beta_1x_i) \\\\\n&\\implies \\beta_1^{MLE} = \\frac{\\sum_i(x_i-\\bar{x})(y_i-\\bar{y})}{\\sum_i(x_i-\\bar{x})^2}\\\\\n\\frac{\\partial \\log L}{\\partial \\sigma^2}|^{\\beta_{MLE}} &= -\\frac{n}{2\\sigma^2} +\\frac{1}{2\\sigma^4}\\sum_i(y_i-\\beta_0-\\beta_1x_1)^2 \\\\\n&\\implies \\sigma^2_{MLE} = \\frac{1}{n}\\sum_i(y_i-\\beta_0^{MLE}-\\beta_1^{MLE}x_1)^2\n\\end{align*}\n\\end{document}\n\n\n\n", "meta": {"hexsha": "2cc4e392cb4ccbe8de53b236fd4ce0eec699f94f", "size": 5219, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016_Spring/MATH-542/HW07/hw07.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/HW07/hw07.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/HW07/hw07.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.1461538462, "max_line_length": 199, "alphanum_fraction": 0.599923357, "num_tokens": 2529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.853912760387131, "lm_q1q2_score": 0.770161576796744}}
{"text": "\\chapter{Support Vector Machines} \\label{Support_Vector_Machine}\nSupport Vector Machines (SVMs) method is one of the Artificial Intelligence Outlier Detection methods \\citep{Silvia} and it can be applied in classification problems. The main idea of SVMs is to find the optimal hyperplane in feature space that best separates classes \\citep{Maimon}. In this section classifiers concepts will be described, then it will extended to One Class Support Vector Machine (OCSVM).\n\\section{Basics of SVMs}\nTo describe the method consider the set $\\Omega = \\lbrace (x_1,y_1),(x_2,y_2),\\ldots,(x_n,y_n) \\rbrace$; where $i \\in \\mathbb{R}^{+}$ is i$th$ element in the set, $x_i \\in \\mathbb{R}^d$ is the input observation number $i$ in $d$ dimensional space and $y_i \\in \\lbrace -1,1 \\rbrace$ is the output number $i$, which indicate the class membership \\citep{Roemer}. SVM uses a hyperplane to separate the observations into classes.\nSVM aims to maximize the margin $\\mathcal{M}$ to get the optimal result. In Figure~\\ref{hyperplanes} observations are in 2-dimensional space which belongs to one of two classes. The observations can be separated by multiple hyperplanes, but the hyperplane that has the maximum distance between the observations and the optimal hyperplane is in Figure~\\ref{maxHyperplane}. Figures are reproduced from \\citep{SVM}.\n\\begin{figure}[H]\n\\begin{center}\n\\minipage{0.4\\textwidth}\n  \\includegraphics[width=\\linewidth]{images/hyperplanes}\n  \\caption{The possible hyperplanes with its different distances from the observations, some hyperplanes are close to one observations of the classes.}\n  \\label{hyperplanes}\n\\endminipage\n\\qquad\n\\minipage{0.4\\textwidth}\n  \\includegraphics[width=\\linewidth]{images/maxHyperplane}\n  \\caption{The optimal hyperplane the one that has maximum distances between the classes, it shouldn't also biased to one side.}\n  \\label{maxHyperplane}\n\\endminipage\n\\end{center}\n\\end{figure}\nSVM has a low computational cost of evaluating the decision function, which is the function that used to classify the observations. SVM doesn't take all of the training examples into account, but a subset of it which is called support vectors \\citep{Maimon}. The support vector is chosen to be the closest observations to the optimal hyperplane. In Figure~\\ref{maxHyperplane} the filled shapes are referred to support vectors in that space. \n\\newpage\n\\large{\\textbf{Hyperplane Classifiers}}\n\nThe objective of classification in SVM is to finds a function $f:\\mathbb{R}^{N} \\rightarrow \\lbrace -1,+1 \\rbrace$ by using the training observations according to the unknown probability distribution $P(x,y)$ of the observations $\\lbrace (x_1,y_1),\\ldots,(x_n,y_n) \\rbrace \\in \\mathbb{R}^{N} \\times Y, Y=\\lbrace -1,+1 \\rbrace$ such that $f$ will classify the coordinates of a new test observation $(x,y)$ correctly \\citep{Maimon}.\n\\begin{itemize}\n\\item \\textbf{The Linear Classifier}\n\nLet $\\Omega$ be a linearly separable observations, the hyperplane will be defined as:\n\\begin{align}\n\\label{equ-3-1}\nw.x+b=0, \\quad w \\in \\mathbb{R}^N , b \\in \\mathbb{R}\n\\end{align}\nWhich corresponds to:\n\\begin{align}\n\\label{equ-3-2}\nf(x) = \\text{sign}((w.x)+b)\n\\end{align}\nWhere $w$ is the weight vector and $b$ is the bias and sign is either positive or negative. \n\nThe margin $\\mathcal{M}$ is the largest distance between two parallel hyperplanes that separate the data into two classes. $\\mathcal{M}$ is given by:\n\\begin{align}\n\\label{equ-3-3}\n\\mathcal{M} = \\frac{2}{||w||}\n\\end{align}\nNote that the margin depends on the weight vector. Maximizing $\\mathcal{M}$ is equivalent to minimizing $||w||$ value. A constraint to prevent observations from falling into the margin should be introduced. The problem becomes:\n\\begin{align}\n\\label{equ-3-4}\n&\\min_{w,b}{\\frac{1}{2}||w||^2}\\\\\n&\\text{s.t. } y_i . ((w.x_i)+b) \\geq 1, \\quad i=1,\\ldots,n\n\\end{align}\nSince this problem is convex optimization, it can be solved using the Lagrange function \\citep{Maimon} as follows:\n\\begin{align}\n\\label{equ-3-5}\n\\mathcal{L}(w,b,\\alpha) = \\frac{1}{2} ||w||^2 - \\sum_{i=1}^{n}\\bigg( \\alpha_i\\big[ y_i((w.x_i)+b)-1 \\big] \\bigg) \n\\end{align}\nWhere $\\alpha_i$ is the Lagrange multiplier. And this has to be minimized with respect to primal variables $w,b$:\n\n\\begin{align}\n\\label{equ-3-6}\n\\frac{\\partial \\mathcal{L}}{\\partial w} &= w-\\sum_{i=1}^{n}{\\alpha_i y_i x_i} = 0 \\rightarrow w = \\sum_{i=1}^{n}{\\alpha_i y_i x_i}\\\\\n\\label{equ-3-7}\n\\frac{\\partial \\mathcal{L}}{\\partial b} &= \\sum_{i=1}^{n}{\\alpha_i y_i} = 0 \n\\end{align}\nThe value of $\\alpha_i$ = 0 for all the constraints in Equation~\\ref{equ-3-5}, which means the values of $\\alpha_i$ can be eliminating from the equation without affecting the solution except for support vector (by using Karush-Kuhn-Tucker (KKT) conditions of optimization), thus:\n\\begin{align}\n\\label{equ-3-8}\n\\alpha_i(y_i.((w.x_i)+b)-1) = 0, \\quad i=1,\\ldots,n\n\\end{align} \n% % % % % % % % % % % % % % % % % % % % % % % % % \nThe Lagrangian ($\\mathcal{L}$) can also be maximized with respect to the dual variables $\\alpha_i$. In fact, solving the dual problem may be easier than the primal problem; because they may have the same values under some conditions \\citep{Maimon}. The dual problem can be obtained by substituting back~\\ref{equ-3-6} and ~\\ref{equ-3-7} value in Lagrangian function ~\\ref{equ-3-5}: \n\\begin{align}\n\\label{equ-3-9}\n\\mathcal{L}=\n\\frac{1}{2} \\bigg[ \\big( \\sum_{i=1}^{n}{\\alpha_i y_i x_i} \\big) . \\big( \\sum_{j=1}^{n}{\\alpha_j y_j x_j} \\big) \\bigg] \n-\n\\bigg[ \n\\big( \\sum_{i=1}^{n}{\\alpha_i y_i x_i} \\big) . \\big( \\sum_{j=1}^{n}{\\alpha_j y_j x_j} \\big) \\bigg] + \\sum_{i=1}^{n}{y_i \\alpha_i b} + \\sum_{i=1}^{n}{\\alpha_i} \n\\end{align}\nAnd from ~\\ref{equ-3-7} the term $\\sum_{i=1}^{n}{y_i \\alpha_i b}$ is equal to 0. The first two terms differ by a factor, thus it becomes:\n\\begin{align}\n\\label{equ-3-10}\n\\mathcal{L}=\\sum_{i=1}^{n}{\\alpha_i} - \\frac{1}{2}\n\\sum_{i=1}^{n}\\sum_{j=1}^{n}{\\alpha_i \\alpha_j y_i y_j x_i x_j} \\\\\n\\text{s.t. }\n\\alpha_i \\geq 0, i=1,\\ldots,n, \\sum_{i=1}^{n}{\\alpha_i y_i} = 0 \\notag\n\\end{align}\nthen the decision function in~\\ref{equ-3-2} will be:\n\\begin{align}\n\\label{equ-3-11}\nf(x) = \\text{sign}\\bigg(\\sum_{i=1}^{n} \\alpha_i y_i (x.x_i)+b\\bigg)\n\\end{align}\nAnd by using ~\\ref{equ-3-8} and the support vectors $x_i, i \\in S=\\{i:\\alpha_i \\neq 0\\}$ the value of $b$ becomes:\n\\begin{align}\n\\label{equ-3-12}\nb=\\frac{1}{S} \\sum_{i\\in S}\\bigg(y_i - \\sum_{j=1}^{n}\\alpha_j y_j(x_i. x_j)\\bigg)\n\\end{align}\n% % % % % % % % % % % % % % % % % %\n\\item \\textbf{Kernel Function}\n\nWhen the observations are not linearly separable in the input space, they should be projected in higher dimension space, this makes the observations separable by using a hyperplane. The kernel function ($K$) is used to project the observations from the input space to higher feature space $F$, where feature space is non-linear mapping $K:\\mathbb{R}^N \\rightarrow \\mathbb{R}^M$ where $M>N$ from the input space ~\\citep{Maimon}. In this space a hyperplane can be used to separate the observations, then that hyperplane would be projected back in the input space, and it would have a non-linear curve. Figure~\\ref{hyperplane-grayscale} illustrate the idea.\n\\begin{figure}[H]\n\\begin{center}\n  \\includegraphics[scale=0.3]{images/hyperplane-grayscale}\n  \\caption{Kernel function $K$ projected the observations from input space to feature space \\citep{Hyperplane}.}\n  \\label{hyperplane-grayscale}\n\\end{center}\n\\end{figure}\nThe Kernel computes the inner product of the vectors without knowing the function $K$ on it self \\citep{Thuso}. There are different choices of kernel function which gives a different classification accuracy. Some of them listed below:\n\\begin{itemize}\n\\renewcommand\\labelitemii{$\\bullet$}\n\\item Linear: $K(x,x_i) = x^T x_i$\n\\item Polynomial: $K(x,x_i) = {(\\gamma x.x_i+C)}^d$\n\\item Sigmoidal: $K(x,x_i) = tanh{(\\gamma x^Tx_i+C)}$\n\\item Gaussian Radial Base function (RBF): $K(x,x_i) = \\exp \\big( - \\gamma||x-x_i||^2 \\big)$\nwhere $\\sigma \\in \\mathbb{R}$ is kernel parameter, and $||x-x_i||$ is the dissimilarity measure.\n\\end{itemize}\nWhere $C$ is the parameter that controls the influence of individual observations; It is also called smoothness parameter because it controls the trade-off between smooth decision boundary and classifying trading observations correctly \\citep{OCSVM}.\n% % % % % % % % % % % % % % % % % % %\n\\item \\textbf{Non Separable SVM}\n\nSometimes the observations may have high noise levels leading the classes to overlap. The previous case was for separable observations, so extending the capabilities of hyperplane classifier so the problem of noise can be solved. \\citep{Maimon}.\nEquation~\\ref{equ-3-4} can be extended by introducing the slack variables $\\xi_i$ which allow the training data to violate the constraint in Equation~\\ref{equ-3-5}.\nA soft classifier is used in the non separable case, and controls the classifier capacity and the sum of the slacks $\\sum_{i=1}^{n} \\xi_i$, the soft classifier minimizes the following function:\n\\vspace{-4mm}\n\\begin{align}\n\\label{equ-3-13}\n&\\min_{w,b}\\frac{1}{2}||w||^2 + C \\sum_{i=1}^{n}{\\xi_i} \\\\\n&\\text{s.t. } \\xi_i \\geq 0, y_i(w x_i +b) \\geq 1-\\xi_i \\quad \\forall i. \\notag\n\\end{align}\nThe value of $\\xi_i$ can be one of three options, $\\xi_i = 0$, then $x_i$ on the right side of the margin. $0< \\xi_i <1$, then $x_i$ on the right side of the margin but its distance is less than the margin $\\mathcal{M}$. $\\xi_i > 1$, then $\\xi_i$ is on the wrong side \\citep{Thuso}.\nThe difference between the separable and the non-separable case is the upper bound $C$ on the Lagrange multipliers $\\alpha_i$, where $C > 0$ is the regularization constant that determines the balance between the empirical risk and the complexity term \\citep{Maimon}. The Lagrange function becomes:\n\\begin{align}\n\\label{equ-3-14}\n\\mathcal{L}(w,b,\\xi_i) = \\frac{1}{2} ||w||^2\n + C \\sum_{i=1}^{n}{\\xi_i} - \\sum_{i=1}^{n}{\\alpha_i \\lbrace y_i (w x_i + b) - (1-\\xi_i) \\rbrace} - \\sum_{i=1}^{n}{\\beta_i \\xi_i}\n \\end{align}\nAnd this has to be minimized with respect to variables $w,b,\\xi_i$:\n\\begin{align}\n\\notag\n\\mathcal{L} &= \\frac{1}{2} w.w + C \\sum_{i=1}^{n}{\\xi_i} - \\sum_{i=1}^{n}(\\alpha_i y_i w x_i + \\alpha_i y_i b - \\alpha_i + \\alpha_i \\xi_i) - \\sum_{i=1}^{n} \\beta_i \\xi_i \\\\\n\\label{equ-3-15}\n\\frac{\\partial \\mathcal{L}}{\\partial w} &= w - \\sum_{i=1}^{n} \\alpha_i y_i x_i = 0 \\rightarrow w = \\sum_{i=1}^{n} \\alpha_i y_i x_i \\\\\n\\label{equ-3-16}\n\\frac{\\partial \\mathcal{L}}{\\partial b} &= \\sum_{i=1}^{n} \\alpha_i y_i = 0\\\\\n\\label{equ-3-17}\n\\frac{\\partial \\mathcal{L}}{\\partial \\xi_i} &= C - \\alpha_i - \\beta_i = 0 \\rightarrow \\beta_i = C - \\alpha_i \\quad \\forall i.\n\\end{align}\nBy using Karush-Kuhn-Tucker (KKT) conditions of optimization to minimize $\\mathcal{L}$, which include the Equations ~\\ref{equ-3-15}, ~\\ref{equ-3-16}, ~\\ref{equ-3-17} and:\n\\begin{align}\n\\label{equ-3-18}\n\\alpha_i (y_i (w x_i +b) - (1-\\xi_i)) = 0 \\\\\n\\label{equ-3-19}\ny_i(w x_i +b) - (1-\\xi_i) \\geq 0 \\\\\n\\label{equ-3-20}\n\\beta_i \\xi_i = 0\n\\end{align}\nNow by using Equation ~\\ref{equ-3-17}, ~\\ref{equ-3-18}, ~\\ref{equ-3-19} and ~\\ref{equ-3-19} the following values obtained:\n\\begin{align}\n\\notag\n\\alpha_i = 0 \\rightarrow y_i(w x_i+b) \\geq 1 \\\\\n\\notag\n\\alpha_i = C \\rightarrow y_i(w x_i+b) \\leq 1 \\\\\n\\notag\n0<\\alpha_i<C \\rightarrow y_i(w x_i+b)=1 \\notag\n\\end{align}\nNow by substituting back in Equation ~\\ref{equ-3-14}:\n\\begin{align}\n\\label{equ-3-21}\n\\mathcal{L} = \\frac{1}{2}\\sum_{i=1}^{n}\\sum_{j=1}^{n} \\alpha_i \\alpha_j y_i y_j + C \\sum_{i=1}^{n}{\\xi_i} - \\sum_{i=1}^{n}{\\alpha_i y_i} \\sum_{j=1}^{n}{\\lbrace \\alpha_j y_j x_j \\rbrace}.x_i - b \\sum_{i=1}^{n}{\\alpha_i y_i} \\\\ + \\sum_{i=1}^{n}{\\alpha_i (1-\\xi_i)} - \\sum_{i=1}^{n}{(C-\\alpha_i)\\xi_i}\\notag\n\\\\\n\\label{equ-3-22}\n= \\sum_{i=1}^{n} \\alpha_i - \\frac{1}{2} \\sum_{i=1}^{n}\\sum_{j=1}^{n}{\\alpha_i \\alpha_j y_i y_j x_i. x_j}\n\\end{align}\nNow to extend this classifier from input space $\\mathbb{R}^N$ to higher dimensional space (feature space $F$), the polynomial kernel function can be used, thus the Lagrange function becomes:\n\\begin{align}\n\\label{equ-3-23}\n\\mathcal{L} = \\sum_{i=1}^{n} \\alpha_i - \\frac{1}{2}\\sum_{i=1}^{n}\\sum_{j=1}^{n}{\\alpha_i \\alpha_j y_i y_j (\\phi(x_i)). (\\phi(x_j))}\n\\end{align}\n\\end{itemize}\n\\section{One Class Support Vector Machine} \\label{OCSVM}\nThe aim of  One Class Support Vector Machine (OCSVM) method is to test if the new data belongs to a defined class or not, unlike previous classifiers where the methods distinguish between classes \\citep{Roemer}. The algorithm represent the observations as points in space, mapped to form separable hyperplane. It uses the origin as the only member of the second class. And it separates the image of the one class from the origin. % \\citep{Larry}. %\n\nIn Figure~\\ref{OSVM1} the normal observations have been labelled by value $+1$, while the outliers are labelled by value $-1$.\n\n\\begin{figure}[H]\n\\begin{center}\n\\minipage{0.35\\textwidth}\n  \\includegraphics[width=\\linewidth]{images/OCSVM}\n\\endminipage\n\\end{center}\n  \\caption{One class SVM, whereby the hyperplane separates the normal observations class 1 from anything else (outliers) class -1.}\n  \\label{OSVM1}\n\\end{figure}\n\n\\textbf{One-Class SVM algorithm:}\nThe function in this algorithm returns +1 in the small region which is the training data points and -1 elsewhere. The quadratic minimization function is different to the SVM quadratic minimization problem \\citep{Scholkopf}:\n\\begin{align}\n&\\min_{w,\\xi_i,\\rho}{\\frac{1}{2}||w||^2 + \\frac{1}{\\nu n} \\sum_{i=1}^{n}\\xi_i - \\rho} \\\\\n&\\notag \\text{s.t. } (w.\\phi(x_i)) \\geq \\rho - \\xi_i, \\forall i=1,\\ldots,n \\\\ \n&\\notag \\xi_i \\geq 0, \\forall i=1,\\ldots,n \n\\end{align}\nThe distance to the origin in feature space is presented by $\\rho$. The variable $w$ is the parametrization of the hyperplane to separate the origin from the observations. In the previous formulation $C$ was the smoothness parameter. In this formula $\\nu$ is the smoothness parameter which is the proportion of outliers expected in the data, and it characterizes the solution \\citep{OCSVM}:\n\\begin{itemize}\n\\item It sets the upper bound on the fractions of outliers;\n\\item It is the lower bound on the number of training examples used as support-vector \\citep{Scholkopf}.\n\\end{itemize}\nSo it is still a quadratic problem, and by using Lagrange multipliers, the decision function becomes:\n$$\nf(x) = \\text{sign}((w.\\phi(x_i)) - \\rho) = \\text{sign}(\\sum_{i=1}^{n} \\alpha_i K(x,x_i) - \\rho)\n$$\n\nAnother method for OCSVM is referred as Tax and Duin method \\citep{David}.\n% % % % % % % % % % % % % % % % % % % % %\n\\begin{comment}\n\\textbf{One-Class SVM according to Tax and Duin:}\nThis function creates a hypersphere around the observations in feature space instead of planar, minimizing hypersphere is minimized the effect of outliers in the solution.\nThe equation in this case require all the distances between the observation $x_i$ to the centre is strict less than $R$ where $R$ is the radius of the hypersphere which is the distance from any support vector to the boundary, slack variables $\\xi_i$ and parameter $C$ are also used to create a soft margin \\citep{David}.\n$$\n\\min_{R,a} R^2 + C \\sum_{i=1}^{n}\\xi_i\n$$\ns.t.\n$$\n||x_i - a||^2 \\leq R^2 + \\xi_i, \\forall i=1,\\cdots,n\n$$\n$$\n\\xi_i \\geq 0, \\forall i=1,\\cdots,n\n$$\nThe result is characterized by:\n$a$ is a linear combination of the support vectors(for the training observations for which \\textit{Lagrange multiplier} is non-zero) and $R$ where $R>0$. The \\textit{Lagrange multipliers} and \\textit{Gaussian kernel} produce:\n$$\n||z-x||^2 = \\sum_{i=1}^{n}\\alpha_i \\exp(\\frac{-||z-x_i||^2}{\\sigma^2}) \\geq -R^2 \\setminus 2 + C_R\n$$\nA new observation $z$ obtained, and it can be used to test if it is in the class and this happens when the distance to the centre is smaller than or equal to the radius \\citep{David}.\n\nThere is also Multi-Class SVM which is an extension to two class problem, SVM also can be applied in the regression problems. SVM mainly used in supervised learning, however, it can also be applied in unsupervised learning. To conclude, the performance of SVM basically depends on the kernel function and the kernel parameters, they are the factors that determined the complexity and the accuracy of the model \\citep{Maimon}.\n\\end{comment}", "meta": {"hexsha": "fb046d93f76e215c974de6a49223d40f09cae53a", "size": 16245, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter3.tex", "max_stars_repo_name": "sustecha/MSc.-Thesis", "max_stars_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter3.tex", "max_issues_repo_name": "sustecha/MSc.-Thesis", "max_issues_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter3.tex", "max_forks_repo_name": "sustecha/MSc.-Thesis", "max_forks_repo_head_hexsha": "f12961a4e9b8194c89a386b66c291bc916a5c629", "max_forks_repo_licenses": ["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.5443037975, "max_line_length": 654, "alphanum_fraction": 0.7129578332, "num_tokens": 5289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8499711832583696, "lm_q1q2_score": 0.7700652439663568}}
{"text": "\\subsection{Linear Approximations}\r\n\\noindent\r\nSince $\\partial z = f_x\\partial x + f_y\\partial y$, we can approximate $\\Delta z$ (the change in any function) as $\\Delta z \\approx f_x\\Delta x + f_y\\Delta y$ because values of $f$ and the tangent plane are close.\r\nWe can rewrite this approximation as a dot product:\r\n\\begin{equation*}\r\n\t\\Delta z \\approx \\langle f_x, f_y\\rangle \\cdot \\langle \\Delta x, \\Delta y \\rangle.\r\n\\end{equation*}\r\n\r\nFor example, say a cylindrical can has a radius $r=1$ and a height $h=5$. If the radius is increased by 0.1 and the height is increased by 1, what is the approximate $\\Delta V$?\r\n\\begin{align*}\r\n\tV(r,h) &= \\pi r^2 h \\\\\r\n\tV_r &= 2\\pi rh \\text{ and } V_h = \\pi r^2 \\\\\r\n\tV_{r}(1,5) &= 10\\pi  \\text{ and } V_{h}(1,5) = \\pi \\\\\r\n\t\\Delta V &\\approx 10\\pi(0.1) + \\pi(1) = 2\\pi.\r\n\\end{align*}\r\nComparing this to the actual answer of $2.26\\pi$, we see our approximation is decent.", "meta": {"hexsha": "9ed1973733d707aab30605f486b3723f584369ba", "size": 908, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximations.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximations.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/differentialMultivariableCalculus/linearApproximations.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.75, "max_line_length": 214, "alphanum_fraction": 0.6674008811, "num_tokens": 307, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625031628428, "lm_q2_score": 0.8267117876664789, "lm_q1q2_score": 0.770051031134047}}
{"text": "\\section{Double Integrals in Polar Coordinates}\\label{sec:DoubleIntegralsinPolarCoordinates}\n\nSuppose we have a surface given in polar coordinates as\n$z=f(r,\\theta)$ and we wish to find the integral over some region. We\ncould attempt to translate into rectangular coordinates and do the\nintegration there, but it is often easier to stay in polar\ncoordinates.\\index{polar coordinates!double integral}\n\nHow might we approximate the volume under such a surface in a way that\nuses polar coordinates directly? The basic idea is the same as\nbefore: we divide the region into many small regions, multiply the\narea of each small region by the height of the surface somewhere in\nthat little region, and add them up. What changes is the shape of the\nsmall regions; in order to have a nice representation in terms of $r$\nand $\\theta$, we use small pieces of ring-shaped areas, as shown in\nFigure~\\ref{fig:polarcoordinatesregions}. Each small region\nis roughly rectangular, except that two sides are segments of a circle\nand the other two sides are not quite parallel. Near a point\n$(r,\\theta)$, the length of either circular arc is about\n$r\\Delta\\theta$ and the length of each straight side is simply $\\Delta\nr$. When $\\Delta r$ and $\\Delta \\theta$ are very small, the region is\nnearly a rectangle with area $r\\Delta r\\Delta\\theta$, and the volume\nunder the surface is approximately\n\\[\\sum\\sum f(r_i,\\theta_j)r_i\\Delta r\\Delta\\theta.\\]\nIn the limit, this turns into a double integral\n\\[\\int_{\\theta_0}^{\\theta_1}\\int_{r_0}^{r_1} f(r,\\theta)r\\,dr\\,d\\theta.\\]\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 4.1\n\\axis left  /\n\\axis bottom  /\n\\circulararc 70 degrees from 3.5 0.5 center at 0 0\n\\circulararc 70 degrees from 2.5 0.5 center at 0 0\n\\circulararc 60 degrees from 1.5 0.5 center at 0 0\n\\setlinear\n\\plot 3.3 1.166 0 0 2.8 2.1 /\n\\plot 2 2.87 0 0 /\n\\put {$\\Delta r$} [tl] <0pt,-3pt> at 2.9 1\n\\put {$r\\Delta \\theta$} [bl] <2pt,2pt> at 3.1 1.62\n\\endpicture}}\n\\caption{A polar coordinates ``grid''.}\n\\label{fig:polarcoordinatesregions}\n\\end{figure}\n\n\\begin{example}{Volume of One-Eighth of a Sphere}{VolumeOneEighthSphere}\nFind the volume under $z=\\sqrt{4-r^2}$ \nabove the quarter circle bounded by\nthe two axes and the circle $x^2+y^2=4$ in the first quadrant.\n\\end{example}\n\\begin{solution}\nIn terms of $r$ and $\\theta$, this region is described by the\nrestrictions $0\\le r\\le 2$ and $0\\le\\theta\\le\\pi/2$, so we have\n\\begin{align*}\n\\int_{0}^{\\pi/2}\\int_{0}^{2} \\sqrt{4-r^2}\\;r\\,dr\\,d\\theta\n&=\\int_{0}^{\\pi/2}\\left. -{1\\over3}(4-r^2)^{3/2}\\right|_0^2\\,d\\theta\t\\\\\n&=\\int_{0}^{\\pi/2} {8\\over3}\\,d\\theta\t\\\\\n&={4\\pi\\over3}.\n\\end{align*}\nThe surface is a portion of the sphere of radius 2 centered at the\norigin, in fact exactly one-eighth of the sphere. We know the formula\nfor volume of a sphere is $(4/3)\\pi r^3$, so the volume we have\ncomputed is $(1/8)(4/3)\\pi 2^3=(4/3)\\pi$, in agreement with our\nanswer.\n\\end{solution}\n\nThis example is much like a simple one in rectangular coordinates: the region\nof interest may be described exactly by a constant range for\neach of the variables. As with rectangular coordinates, we can adapt\nthe method to deal with more complicated regions.\n\n\\begin{example}{Integration in Polar Coordinates}{integrationinpolarcoordinates}\nFind the volume under $z=\\sqrt{4-r^2}$ above the region enclosed by the\ncurve $r=2\\cos\\theta$, $-\\pi/2\\le\\theta\\le\\pi/2$; see\nFigure~\\ref{fig:volumewithvariablelimits}.\n\\end{example}\n\\begin{solution}\nThe region is described in polar coordinates by the inequalities\n$-\\pi/2\\le\\theta\\le\\pi/2$ and $0\\le r\\le2\\cos\\theta$, so\nthe double integral is\n\\[\\int_{-\\pi/2}^{\\pi/2}\\int_{0}^{2\\cos\\theta} \\sqrt{4-r^2}\\;r\\,dr\\,d\\theta\n=2\\int_{0}^{\\pi/2}\\int_{0}^{2\\cos\\theta} \\sqrt{4-r^2}\\;r\\,dr\\,d\\theta.\\]\nWe can rewrite the integral as shown because of the symmetry of the\nvolume; this avoids a complication during the evaluation.\nProceeding:\n\\begin{align*}\n2\\int_{0}^{\\pi/2}\\int_{0}^{2\\cos\\theta} \\sqrt{4-r^2}\\;r\\,dr\\,d\\theta\n&=2\\int_{0}^{\\pi/2}-{1\\over3}\\left.(4-r^2)^{3/2}\\right|_0^{2\\cos\\theta}\\,d\\theta\t\\\\\n&=2\\int_{0}^{\\pi/2}-{8\\over3}\\sin^3\\theta+{8\\over3}\\,d\\theta\t\\\\\n&=\\left.2\\left(-{8\\over3}{\\cos^3\\theta\\over3}-\\cos\\theta+{8\\over3}\\theta\\right)\\right|_0^{\\pi/2}\t\\\\\n&={8\\over3}\\pi-{32\\over9}.\n\\end{align*}\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 2.1, y from -1.1 to 1.1\n\\axis left  /\n\\axis bottom shiftedto y=0 /\n\\circulararc 360 degrees from 2 0 center at 1 0\n\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/polar_volume.eps}}} at 5 0\n\\endpicture}}\n\\caption{Volume over a region with non-constant limits.}\n\\label{fig:volumewithvariablelimits}\n\\end{figure}\n\nYou might have learned a formula for computing areas in polar\ncoordinates. It is possible to\ncompute areas as volumes, so that you need only remember one\ntechnique. Consider the surface $z=1$, a horizontal plane. The volume\nunder this surface and above a region in the $x$-$y$ plane is \nsimply $1\\cdot(\\hbox{area of the region})$, so computing the volume\nreally just computes the area of the region.\n\n\\begin{example}{}{}\nFind the area outside the circle $r=2$ and inside\n$r=4\\sin\\theta$; see Figure~\\ref{fig:areabyvolume}.\n\\end{example}\n\\begin{solution}\nThe region is described by $\\pi/6\\le\\theta\\le5\\pi/6$ and\n$2\\le r\\le4\\sin\\theta$, so the integral is\n\\begin{align*}\n\\int_{\\pi/6}^{5\\pi/6}\\int_2^{4\\sin\\theta}1\\,r\\,dr\\,d\\theta\n&=\\int_{\\pi/6}^{5\\pi/6}\\left. {1\\over2}r^2\\right|_2^{4\\sin\\theta}\\,d\\theta\t\\\\\n&=\\int_{\\pi/6}^{5\\pi/6}8\\sin^2\\theta-2\\,d\\theta\t\\\\\n&={4\\over3}\\pi+2\\sqrt3.\n\\end{align*}\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\hbox{\\hfill\\begin{tikzpicture}[domain=-2:2,x=6mm,y=6mm]\n\\draw (-2.1,0) -- (2.1,0) ;\n\\draw (0,-2.1) -- (0,4.1) ;\n\\draw[color=black] (0,0) circle (2);\n\\draw[color=black] (0,2) circle (2);\n\\fill[opacity=0.5,fill=red!20]\nplot[parametric,id=first,domain=0.5236:2.618]\nfunction{4*sin(t)*cos(t),4*sin(t)*sin(t)} node {}\nplot[parametric,id=second,domain=0.5236:2.618]\nfunction{2*cos(3.1416-t),2*sin(3.1416-t)} -- cycle;\n\\end{tikzpicture}\\hfill}}\n\\caption{Finding area by computing volume.}\n\\label{fig:areabyvolume}\n\\end{figure}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:DoubleIntegralsinPolarCoordinates}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the volume above the $x$-$y$ plane, under the surface\n$r^2=2z$, and inside $r=2$.\n\\begin{sol}\n$4\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume inside both $r=1$ and $r^2+z^2=4$.\n\\begin{sol}\n$32\\pi/3-4\\sqrt3\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume below $z=\\sqrt{1-r^2}$ and above\nthe top half of the cone $z=r$.\n\\begin{sol}\n$(2-\\sqrt2)\\pi/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume below  $z=r$, above the $x$-$y$ plane, and\ninside $r=\\cos\\theta$.\n\\begin{sol}\n$4/9$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume below  $z=r$, above the $x$-$y$ plane, and\ninside $r=1+\\cos\\theta$.\n\\begin{sol}\n$5\\pi/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume between $x^2+y^2=z^2$ and $x^2+y^2=z$.\n\\begin{sol}\n$\\pi/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area inside $r=1+\\sin\\theta$ and outside\n$r=2\\sin\\theta$. \n\\begin{sol}\n$\\pi/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area inside both\n$r=2\\sin\\theta$ and $r=2\\cos\\theta$. \n\\begin{sol}\n$\\pi/2-1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area inside the four-leaf rose $r=\\cos(2\\theta)$\nand outside $r=1/2$.\n\\begin{sol}\n$\\sqrt3/4+\\pi/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the area inside the cardioid $r=2(1+\\cos\\theta)$\nand outside $r=2$.\n\\begin{sol}\n$8+\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\\label{ex:areaofthreeleafroseloop}\nFind the area of one loop of the three-leaf rose\n $r=\\cos(3\\theta)$.\n\\begin{sol}\n$\\pi/12$\\\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{-3}^3\\int_0^{\\sqrt{9-x^2}}\n\\sin(x^2+y^2)\\,dy\\,dx$ by converting to polar coordinates.\n\\begin{sol}\n$(1-\\cos(9))\\pi/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds \\int_{0}^a\\int_{-\\sqrt{a^2-x^2}}^0 x^2y\\,dy\\,dx$ \nby converting to polar coordinates.\n\\begin{sol}\n$-a^5/15$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume under $z=y^2+x+2$ above\nthe region $x^2+y^2\\le 4$\n\\begin{sol}\n$12\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume between\n$z=x^2y^3$ and $z=1$ above\nthe region $x^2+y^2\\le 1$\n\\begin{sol}\n$\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume inside\n$x^2+y^2=1$ and $x^2+z^2=1$.\n\\begin{sol}\n$16/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the volume under $z=r$ above $r=3+\\cos\\theta$.\n\\begin{sol}\n$21\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFigure~\\ref{fig:doubleflower} shows the plot of\n$r=1+4\\sin(5\\theta)$.\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 -1 to 1\n\\put {\\hbox{\\epsfxsize4cm\\epsfbox{images/double_flower.eps}}} at 0 0\n\\endpicture}}\n\\caption{$r=1+4\\sin(5\\theta)$}\n\\label{fig:doubleflower}\n\\end{figure}\n\\begin{enumerate}\n\t\\item Describe the behavior of the graph in terms of the given\n\t  equation.  Specifically, explain maximum and minimum values, number\n\t  of leaves, and the 'leaves within leaves'.\n\t\\item Give an integral or integrals to determine the area outside a\n\t  smaller leaf but inside a larger leaf.\n\t\\item How would changing the value of $a$ in the equation\n\t  $r=1+a\\cos(5\\theta)$ change the relative sizes of the inner and\n\t  outer leaves? Focus on values $a\\geq 1$.  (Hint: How would we change\n\t  the maximum and minimum values?)\n\\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\nConsider the integral $\\ds\\iint_D {1\\over\\sqrt{x^2+y^2}} \\;\ndA$, where $D$ is the unit disk centered at the origin.\n\\begin{enumerate}\n\t\\item Why might this integral be considered improper?\n\t\\item Calculate the value of the integral of the same function\n\t  $\\ds 1/\\sqrt{x^2+y^2}$ over the annulus with outer radius 1 and\n\t  inner radius $\\delta$.\n\t\\item Obtain a value for the integral on the whole disk by letting\n\t  $\\delta$ approach 0.\n\t\t\\begin{sol}\n\t\t$2\\pi$\n\t\t\\end{sol}\n\t\\item For which values $\\lambda$ can we replace the denominator with\n\t  $(x^2+y^2)^\\lambda$ in the original integral?\n\\end{enumerate}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "3e3a5ad0861c20a16213d69239934ad18a06688a", "size": 10269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-2-double-integral-polar-coord.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-2-double-integral-polar-coord.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-2-double-integral-polar-coord.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.2029411765, "max_line_length": 99, "alphanum_fraction": 0.6984126984, "num_tokens": 3755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950986284991, "lm_q2_score": 0.9124361557147439, "lm_q1q2_score": 0.7700003996191024}}
{"text": "\\section{Loss functions:  nonlinear least square and cross-entropy}\nGiven a collection of data $D=(x_j,y_j)_{j=1}^N$ with $x_j\\in A_{i_j}$\nand $y_j=e_{i_j}$ We now discuss how to find $\\theta =(W,b)$ such that\n\\begin{equation}\n\\label{fitting}\nf(x_i,\\theta)=\\sigma(Wx_j+b)=y_j,\\quad 1\\le j \\le N.\n\\end{equation}\n\n\\subsection{Least square}\nThe data fitting problem \\eqref{fitting} can be solved by find a minimizer of the following loss function\n\\begin{equation}\n\\label{L0}\nL_0(\\theta)={1\\over N}\\sum_{i=1}^N\\|f(x_i,\\theta)-y_i\\|^2\n\\end{equation}\n\nObviously,\n$$\n\\theta^*=(W^*,b^*) \\mathrm{satisfies}\\ \\eqref{fitting} \\Leftrightarrow L_0(\\theta^*)=0\\Leftrightarrow \\theta^*\\in\\arg\\min_{\\theta}L_0(\\theta)\n$$\n\nWe make the  following two observations on the loss function $L_0$ given by \\eqref{L0}:\n\\begin{enumerate}\n\t\\item It has infinitely many global minimizers.\n\t\\item It is a non-convex loss function.\n\\end{enumerate}\n\n\n\\input{6DL/KL-CR-LR}\n\n\n\\subsection{Convex versus non-convex loss functions}\n\\subsubsection{Convexity}\nThe maximum likelihood and maximum posterior look difficult to optimize at first glance. Remarkably though,\nthe logistic regression has the property that the negative log likelihood is a convex function of the parameters $W,b$.\nThis means that we can apply a well-developed convergence theory for methods such as gradient descent, accelerated gradient\ndescent, stochastic gradient descent, etc. Our goal in this section will be to prove this remarkable fact.\n\nThe first thing to note is that the negative log-likelihood\n$$\\displaystyle\\sum_{j=1}^n \\left(\\log(\\mathbbm{1}^T\\exp(W x_j + b)) - \n (W x_j + b)_{i_j})\\right)$$\nis a sum of terms over all of the data points $(x_i,y_i)$. Since a sum of convex functions is convex, it suffices to show that\nthe term corresponding to a single data point is convex (i.e. the negative log-likelihood of a single data point is a convex\nfunction). So we consider the function\n\\begin{equation}\n f_{x,i}(W,b) = \\log(\\mathbbm{1}^T\\exp(W x + b)) - \n (W x + b)_{i}\n\\end{equation}\nWe will show that this function is convex for any choice of data $x$ and label $i$. First note that the second term\n$$ - (W x + b)_{i}$$\nis a linear function, so it suffices to show that the first term\n$$\\log(\\mathbbm{1}^T\\exp(W x + b))$$\nis convex. To see this, we note that $W x + b$ is a linear function of the parameters $W,b$. Combining\nthis with the easy fact that a convex function composed with a linear function is convex, we only need to consider the LogSumExp\nfunction $s:\\mathbb{R}^k\\rightarrow \\mathbb{R}$ defined by\n\\begin{equation}\n s(x) = \\log(\\exp(x_1) + \\cdots + \\exp(x_k))\n\\end{equation}\nWe can easily verify that this function is convex by calculating its Hessian and noting that $\\nabla^2s$ is diagonally dominant.\n%\\begin{equation}\n% D^2s(x) =   \\left(\\displaystyle\\sum_{i=1}^k \\exp(x_i)\\right)^{-2}\\begin{pmatrix}\n%    \\left(\\displaystyle\\sum_{i\\neq 1} \\exp(x_1 + x_i)\\right) & -\\exp(x_1 + x_2) & -\\exp(x_1 + x_3) & \\cdots & -\\exp(x_1 + x_k) \\\\\n%    -e^{x_1}e^{x_2} & e^{x_2}(e^{x_1} + e^{x_3} + \\cdots + e^{x_k}) & -e^{x_2}e^{x_3} & \\cdots & -e^{x_2}e^{x_k}\n%  \\end{pmatrix} \n%\\end{equation}\n\n", "meta": {"hexsha": "6b530aaffe9c500e5aa259ab903474f153cc24c0", "size": 3150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LossFunction.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/LossFunction.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/LossFunction.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.7272727273, "max_line_length": 141, "alphanum_fraction": 0.7111111111, "num_tokens": 1053, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397306, "lm_q2_score": 0.8633916099737807, "lm_q1q2_score": 0.7699821842436131}}
{"text": "\\subsection{Symbols}\n\nAs we saw earlier, symbols are defined using an equals sign.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN = 212^17\n\\end{Verbatim}\n\n\\noindent\nNo result is printed when a symbol is defined.\nTo see the value of a symbol, just evaluate it.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nN\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle N=3529471145760275132301897342055866171392$\n\n\\bigskip\n\\noindent\nSymbols can have more that one letter.\nEverything after the first letter is displayed as a subscript.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nNA = 6.02214 10^23\nNA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle N_A=6.02214\\times10^{23}$\n\n\\bigskip\n\\noindent\nA symbol can be the name of a Greek letter.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nxi = 1/2\nxi\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\xi=\\tfrac{1}{2}$\n\n\\bigskip\n\\noindent\nGreek letters can appear in subscripts.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nAmu = 2.0\nAmu\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A_\\mu=2.0$\n\n\\bigskip\n\\noindent\nThe following example shows how\nEigenmath scans the entire symbol to find Greek letters.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nalphamunu = 1\nalphamunu\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\alpha_{\\mu\\nu}=1$\n\n\\bigskip\n\\noindent\nWhen a symbolic chain is defined,\nEigenmath follows the chain as far as possible.\nThe following example sets $A=B$ followed by $B=C$.\nThen when $A$ is evaluated, the result is $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = B\nB = C\nA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A=C$\n\n\\bigskip\n\\noindent\nAlthough $A=C$ is printed,\ninside the program the binding of $A$ is still $B$, as can be seen with\nthe $binding$ function.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nbinding(A)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle B$\n\n\\bigskip\n\\noindent\nThe {\\it quote} function returns its argument unevaluated\nand can be used to clear a symbol.\nThe following example clears $A$ so that its evaluation goes back to\nbeing $A$ instead of $C$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nA = quote(A)\nA\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle A$\n\n\\subsection{User defined functions}\n\nMost of the functions commonly used in math and physics are included in Eigenmath.\nSee the Reference section at the end of the manual for a complete list.\nThere is also a facility for the user to define additional functions.\n\n\\bigskip\n\\noindent\nUser functions are defined using the syntax {\\it function-name} ( {\\it arg-list} ) = {\\it expr}.\nThe {\\it arg-list} is an optional comma separated list of symbols that receive arguments.\nUnlike symbolic definitions, {\\it expr} is not evaluated when {\\it function-name} is defined.\nInstead, {\\it expr} is evaluated when {\\it function-name} is used in a subsequent computation.\n\n\\bigskip\n\\noindent\nThe following example defines a sinc function and evaluates it at $\\pi/2$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = sin(x)/x\nf(pi/2)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\frac{2}{\\pi}$\n\n\\bigskip\n\\noindent\nAfter a user function is defined, {\\it expr} can be recalled using the {\\it binding} function.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nbinding(f)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\frac{\\sin(x)}{x}$\n\n\\bigskip\n\\noindent\nThe following example uses Rodrigues's formula to\ncompute an associated Legendre function of $\\cos\\theta$.\n\\begin{equation*}\nP_l^m(x)=\\frac{1}{2^ll!}(1-x^2)^{m/2}\\frac{d^{l+m}}{dx^{l+m}}(x^2-1)^l\n\\end{equation*}\nThe formula is computed for $x$ and then\n{\\it eval} replaces $x$ in the result with $\\cos\\theta$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nP(l,m) = eval(1/(2^l l!) (1 - x^2)^(m/2) d((x^2 - 1)^l,x,l + m),x,cos(theta))\nP(2,0)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle \\tfrac{3}{2} \\cos(\\theta)^2-\\tfrac{1}{2}$\n\n\\bigskip\n\\noindent\nWhen a user function is evaluated, the function arguments are visible\nto any symbol definitions that reference them.\nThe symbol definitions can appear either before or after the function definition.\nIn the following example, the $x$ in $A$ and $B$ is replaced with $y$.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nf(x) = A + B\nA = a x\nB = b x\nf(y)\n\\end{Verbatim}\n\n\\noindent\n$\\displaystyle ay+by$\n", "meta": {"hexsha": "caf341598034b488ae67e469e308a230c446a4c1", "size": 4129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/symbols.tex", "max_stars_repo_name": "franko/eigenmath", "max_stars_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2020-01-27T02:41:22.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-02T19:05:49.000Z", "max_issues_repo_path": "doc/symbols.tex", "max_issues_repo_name": "franko/eigenmath", "max_issues_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-01-29T14:09:35.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-13T16:17:03.000Z", "max_forks_repo_path": "doc/symbols.tex", "max_forks_repo_name": "franko/eigenmath", "max_forks_repo_head_hexsha": "3fca24d09686220e430108dac4864a192d138f13", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-01-27T02:38:38.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-27T02:38:38.000Z", "avg_line_length": 22.4402173913, "max_line_length": 96, "alphanum_fraction": 0.7326229111, "num_tokens": 1276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8918110418436166, "lm_q1q2_score": 0.7699821837489055}}
{"text": "\\part{Functions}\n\n\\chapter{Functions}\n\n\\section{Function}\n\nSome types of functions: linear, parabolas, ... \\\\\n\nThe domain of a function $ f $ is the set of all valid input values. The range consists of the set of all output values that can be reached using those domain values. \\\\\n\n\\section{Rational Function}\n\n\\begin{itemize}\n\t\\item\n\t      basic form: $ y = {1 \\over x} $ \\\\\n\n\t\\item\n\t      vertical asymptote at $ x = 0 $ \\\\\n\n\t\\item\n\t      horizontal asymptote at $ y = 0 $ \\\\\n\\end{itemize}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:-0.3] plot (\\x,{1 / \\x});\n\t\t\\draw[very thick,color=red,domain=0.3:3] plot (\\x,{1 / \\x}) node[right] {$ y = {1 \\over x} $};\n\t\\end{tikzpicture}\n\t\\caption{rational function}\n\\end{figure}\n\n\\section{Root Function}\n\n\\begin{itemize}\n\t\\item\n\t      basic form: $ y = \\sqrt[n]{x} $ \\\\\n\n\t\\item\n\t      $ n $ even: undefined when the root is negative \\\\\n\n\t\\item\n\t      $ n $ odd: $ x \\in \\mathbb{R} $ \\\\\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=0:3] plot (\\x,{sqrt(\\x)}) node[right] {$ y = \\sqrt[2]{x} $};\n\t\\end{tikzpicture}\n\t\\caption{root function when $ n $ is even}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:3,samples=100] plot (\\x,{\\x ^ (1/3)}) node[right] {$ y = \\sqrt[3]{x} $};\n\t\\end{tikzpicture}\n\t\\caption{root function when $ n $ is odd}\n\\end{figure}\n\n\\section{Higher-degree of Polynomial Function}\n\n\\begin{itemize}\n\t\\item\n\t      basic form: $ y = x^n $ \\\\\n\n\t\\item\n\t      domain: $ x \\in \\mathbb{R} $ \\\\\n\n\t\\item\n\t      $ n $ even: both ends of the function tend to $ +\\infty $ or both tend to $ -\\infty $ \\\\\n\n\t\\item\n\t      $ n $ odd: one end tends to $ +\\infty $ while the other tends to $ -\\infty $ \\\\\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-2:2] plot (\\x,{(\\x) ^ 2}) node[right] {$ y = x ^ 2 $};\n\t\\end{tikzpicture}\n\t\\caption{polynomial function when $ n $ is even}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8,yscale=0.2]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-30) -- (0,30) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:3] plot (\\x,{(\\x) ^ 3}) node[right] {$ y = x ^ 3 $};\n\t\\end{tikzpicture}\n\t\\caption{polynomial function when $ n $ is odd}\n\\end{figure}\n\n\\chapter{Angles, Degrees, and Radians}\n\n\\section{Angle}\n\nAn angle is created by two rays that intersect at a common endpoint. We use Greek letter $ \\theta $ to denote angles. \\\\\n\nAn angle that opens counterclockwise from the x-axis is positive. \\\\\n\nAn angle that opens clockwise from the x-axis is negative. \\\\\n\n\\section{Degree and Radian}\n\nAngles can be measured in 2 ways: \\\\\n\n\\begin{enumerate}\n\t\\item\n\t      A degree is a measure of the angle formed by $ 1 \\over 360 $ of one complete rotation of a circle. \\\\\n\n\t\\item\n\t      A radian is a measure of the angle formed by the arc of a circle whose length is equal to the circle's radius. \\\\\n\\end{enumerate}\n\n\\begin{theorem}[Degree]\n\t\\begin{align}\n\t\t\\theta = {s \\over r} = {arclength \\over radius}\n\t\\end{align}\n\\end{theorem}\n\nHow are radians and degrees related? \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[-] (-3,0) -- (3,0);\n\t\t\\draw[-] (0,-3) -- (0,3);\n\t\t\\draw (2,0) arc (0:360:2);\n\t\t\\draw[-,very thick] (0, 0) -- (1.3, 1.5);\n\t\t\\draw[-,very thick] (0, 0) -- (-0.6, 1.9);\n\t\t\\draw[-,very thick] (0, 0) -- (-1.9, 0.6) node[left] {$ \\approx $ 0.1415 radian};\n\t\\end{tikzpicture}\n\t\\caption{radian}\n\\end{figure}\n\n\\begin{theorem}[Degrees and radians]\n\t\\begin{align}\n\t\t & 180^\\circ = \\pi \\ radians           \\\\\n\t\t & 1^\\circ = {\\pi \\over 180} \\ radians \\\\\n\t\t & 1 \\ radian = {180 \\over \\pi}^\\circ\n\t\\end{align}\n\\end{theorem}\n\nThis relationship provides us with a way to easily convert between the two measures. \\\\\n\n\\begin{exercise}\n\tConvert from degrees to radians. \\\\\n\n\t(a) $ 30^\\circ = $ \\\\\n\n\t(b) $ 220^\\circ = $ \n\\end{exercise}\n\n\\begin{exercise}\n\tConvert from radians to degrees. \\\\\n\n\t(a) $ {\\pi \\over 4} = $ \\\\\n\n\t(b) $ {5\\pi \\over 6} = $\n\\end{exercise}\n\nGiven any angle $ \\theta $, what are these equivalent angles? \\\\\n\n\\begin{theorem}[Equivalent angles]\n\t\\begin{align}\n\t\t & \\theta + 2k\\pi \\ (k \\in \\mathbb Z)\n\t\\end{align}\n\\end{theorem}\n\n\\chapter{Trigonometric Functions}\n\n\\section{Trigonometric Functions}\n\nLet $ O $ be the origin and $ P(x, y) $ be a point on the unit circle so that the radius $ OP $ forms an angle of $ \\theta $ radians with respect to the positive x-axis. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\draw[-] (-3,0) -- (3,0);\n\t\t\\draw[-] (0,-3) -- (0,3);\n\t\t\\draw (2,0) arc (0:360:2);\n\t\t\\draw[-,very thick] (0, 0) -- (1.4, 1.4);\n\t\t\\draw[-,very thick] (0, 0) -- (1.4, 0);\n\t\t\\draw[-,very thick] (1.4, 0) -- (1.4, 1.4);\n\t\\end{tikzpicture}\n\t\\caption{radian}\n\\end{figure}\n\n\\begin{theorem}[sin / cos]\\nonumber\n\t\\begin{align}\n\t\t & x = cos(\\theta) \\\\\n\t\t & y = sin(\\theta)\n\t\\end{align}\n\\end{theorem}\n\nHere are the three most common trigonometric functions and their reciprocals. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\txlabel={$ x $}, ylabel={$ y $},\n\t\t\t\txmin=-2*pi, xmax=2*pi,\n\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\txtick={-6.28319, -3.14159, 0, 3.14159, 6.28319},\n\t\t\t\txticklabels={$-2\\pi$, $-\\pi$, $0$, $\\pi$, $2\\pi$},\n\t\t\t\tline width=1pt,\n\t\t\t\taxis lines=center,\n\t\t\t]\n\t\t\t\\addplot[smooth,domain=-2*pi:2*pi, red!70]{sin(deg(x))};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ -1 \\le sin(\\theta) \\ge 1 $        \\\\\n\t\t\\hline\n\t\tdoamin                   & $ \\theta \\in \\mathbb R $            \\\\\n\t\t\\hline\n\t\t$ sin(\\theta) = 0 $ when & $ \\theta = k\\pi,\\ k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = sin(\\theta) $}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\t\txlabel={$ x $}, ylabel={$ y $},\n\t\t\t\txmin=-2*pi, xmax=2*pi,\n\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\txtick={-6.28319, -3.14159, 0, 3.14159, 6.28319},\n\t\t\t\txticklabels={$-2\\pi$, $-\\pi$, $0$, $\\pi$, $2\\pi$},\n\t\t\t\tline width=1pt,\n\t\t\t\taxis lines=center,\n\t\t\t]\n\t\t\t\\addplot[smooth,domain=-2*pi:2*pi, red!70]{cos(deg(x))};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ \\theta \\in \\mathbb R $                           \\\\\n\t\t\\hline\n\t\tdoamin                   & $ -1 \\le cos(\\theta) \\le 1 $                       \\\\\n\t\t\\hline\n\t\t$ cos(\\theta) = 0 $ when & $ \\theta = {(2k+1)\\pi \\over 2},\\ k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = cos(\\theta) $}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\foreach \\x / \\r in {-4/-2\\pi,-3/-\\frac{3}{2}\\pi,-2/-\\pi,-1/-\\frac{1}{2}\\pi,1/\\frac{1}{2}\\pi,2/\\pi,3/\\frac{3}{2}\\pi,4/2\\pi} \\draw (\\x,-0.15) -- (\\x,+0.15) node[below=7] {$\\r$};\n\t\t\\foreach \\y in {-4,-3,-2,-1,1,2,3,4} \\draw (-0.15,\\y) -- (+0.15,\\y) node[left=7] {$\\y$};\n\t\t\\draw[->] (-4.25,0)--(4.25,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4.25)--(0,4.25) node[above] {$ y $};\n\t\t\\foreach \\i in {0,...,4} \\draw[very thick,color=red] plot [domain={((\\i-2)*pi-rad(atan(4))*ceil(\\i/4))*(2/pi)}:{((\\i-2)*pi+rad(atan(4))*ceil((4-\\i)/4))*(2/pi)},smooth] (\\x,{tan(\\x*pi/2 r)});\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ \\theta \\in \\mathbb R, \\theta \\ne {(2k+1)\\pi \\over 2}, k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\tdoamin                   & $ tan(\\theta) \\in \\mathbb R $                                             \\\\\n\t\t\\hline\n\t\t$ tan(\\theta) = 0 $ when & $ \\theta = k\\pi,\\ k \\in \\mathbb Z $                                       \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = tan(\\theta) $}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\foreach \\x / \\r in {-4/-2\\pi,-3/-\\frac{3}{2}\\pi,-2/-\\pi,-1/-\\frac{1}{2}\\pi,1/\\frac{1}{2}\\pi,2/\\pi,3/\\frac{3}{2}\\pi,4/2\\pi} \\draw (\\x,-0.15) -- (\\x,+0.15) node[below=7] {$\\r$};\n\t\t\\foreach \\y in {-4,-3,-2,-1,1,2,3,4} \\draw (-0.15,\\y) -- (+0.15,\\y) node[left=7] {$\\y$};\n\t\t\\draw[->] (-4.25,0)--(4.25,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4.25)--(0,4.25) node[above] {$ y $};\n\t\t\\foreach \\i in {0,...,3} \\draw[very thick,color=red] plot [domain={((\\i-2)*pi+rad(asin(1/4)))*(2/pi)}:{((\\i-1)*pi-rad(asin(1/4)))*(2/pi)},smooth] (\\x,{cosec(\\x*pi/2 r)});\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ \\theta \\in \\mathbb R,\\ \\theta \\ne k\\pi,\\ k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\tdoamin                   & $ csc(\\theta) \\ge 1 $ or $ csc(\\theta) \\le -1 $              \\\\\n\t\t\\hline\n\t\t$ csc(\\theta) = 0 $ when & $ never $                                                    \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = csc(\\theta) $}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.9]\n\t\t\\foreach \\x / \\r in {-4/-2\\pi,-3/-\\frac{3}{2}\\pi,-2/-\\pi,-1/-\\frac{1}{2}\\pi,1/\\frac{1}{2}\\pi,2/\\pi,3/\\frac{3}{2}\\pi,4/2\\pi} \\draw (\\x,-0.15) -- (\\x,+0.15) node[below=7] {$\\r$};\n\t\t\\foreach \\y in {-4,-3,-2,-1,1,2,3,4} \\draw (-0.15,\\y) -- (+0.15,\\y) node[left=7] {$\\y$};\n\t\t\\draw[->] (-4.25,0)--(4.25,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4.25)--(0,4.25) node[above] {$ y $};\n\t\t\\foreach \\i in {0,...,4} \\draw[very thick,color=red] plot [domain={((\\i-2)*pi-rad(acos(1/4))*ceil(\\i/4))*(2/pi)}:{((\\i-2)*pi+rad(acos(1/4))*ceil((4-\\i)/4))*(2/pi)},smooth] (\\x,{sec(\\x*pi/2 r)});\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ \\theta \\in \\mathbb R,\\ \\theta \\ne {(2k+1)\\pi \\over 2},\\ k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\tdoamin                   & $ sec(\\theta) \\ge 1 $ or $ sec(\\theta) \\le -1 $                             \\\\\n\t\t\\hline\n\t\t$ sec(\\theta) = 0 $ when & $ never $                                                                   \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = sec(\\theta) $}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8]\n\t\t\\foreach \\x / \\r in {-4/-2\\pi,-3/-\\frac{3}{2}\\pi,-2/-\\pi,-1/-\\frac{1}{2}\\pi,1/\\frac{1}{2}\\pi,2/\\pi,3/\\frac{3}{2}\\pi,4/2\\pi} \\draw (\\x,-0.15) -- (\\x,+0.15) node[below=7] {$\\r$};\n\t\t\\foreach \\y in {-4,-3,-2,-1,1,2,3,4} \\draw (-0.15,\\y) -- (+0.15,\\y) node[left=7] {$\\y$};\n\t\t\\draw[->] (-4.25,0)--(4.25,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4.25)--(0,4.25) node[above] {$ y $};\n\t\t\\foreach \\i in {0,...,3} \\draw[very thick,color=red] plot [domain={((\\i-2)*pi+rad(atan(1/4)))*(2/pi)}:{((\\i-1)*pi-rad(atan(1/4)))*(2/pi)},smooth] (\\x,{cot(\\x*pi/2 r)});\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tabular}{|c|c|}\n\t\t\\hline\n\t\trange                    & $ \\theta \\in \\mathbb R,\\ \\theta \\ne k\\pi, k \\in \\mathbb Z $ \\\\\n\t\t\\hline\n\t\tdoamin                   & $ cot(\\theta) \\in \\mathbb R $                               \\\\\n\t\t\\hline\n\t\t$ cot(\\theta) = 0 $ when & $ \\theta = {(2k+1)\\pi \\over 2},\\ k \\in \\mathbb Z $          \\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{$ y = cot(\\theta) $}\n\\end{figure}\n\n\\section{Special Triangles}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8]\n\t\t\\draw (0,0) node[anchor=north]{$ A $}\n\t\t-- (4,0) node[anchor=north]{$ C $}\n\t\t-- (4,4) node[anchor=south]{$ B $}\n\t\t-- cycle;\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8]\n\t\t\\draw (0,0) node[anchor=north]{$ A $}\n\t\t-- (7,0) node[anchor=north]{$ C $}\n\t\t-- (7,3) node[anchor=south]{$ B $}\n\t\t-- cycle;\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{exercise}\n\tEvaluate each of the following. \\\\\n\n\t(a) $ sin({\\pi \\over 4}) = $ \\\\\n\n\t(b) $ cos({\\pi \\over 4}) = $ \\\\\n\n\t(c) $ csc({\\pi \\over 4}) = $\n\\end{exercise}\n\n\\begin{exercise}\n\tFind all values of $ \\theta $ satisfying the following. \\\\\n\n\t(a) $ tan(\\theta) = {1 \\over \\sqrt{3}} $ \\\\\n\t\\\\\n\t\\\\\n\n\t(b) $ sec(\\theta) = \\sqrt{2} $ \\\\\n\t\\\\\n\t\\\\\n\n\t(c) $ cot(\\theta) = \\sqrt{3} $ \\\\\n\t\\\\\n\t\\\\\n\\end{exercise}\n\n\\section{Trigonometric Identities}\n\n\\begin{theorem}[Trigonometric Identities]\n\t\\begin{align}\n\t\t & sin^2(\\theta) + cos^2(\\theta) = 1                    \\\\\n\t\t & sin(-\\theta) = -sin(\\theta)                          \\\\\n\t\t & cos(-\\theta) = -cos(\\theta)                          \\\\\n\t\t & tan(\\theta) = {sin(\\theta) \\over cos(\\theta)}        \\\\\n\t\t & cot(\\theta) = {cos(\\theta) \\over sin(\\theta)}        \\\\\n\t\t & tan^2(\\theta) + 1 = sec^2(\\theta)                    \\\\\n\t\t & cot^2(\\theta) + 1 = csc^2(\\theta)                    \\\\\n\t\t & sin(\\theta) = cos\\left(\\theta - {\\pi \\over 2}\\right) \\\\\n\t\t & sin(a \\pm b) = sin(a)cos(b) \\pm cos(a)sin(b)         \\\\\n\t\t & cos(a \\pm b) = cos(a)cos(b) \\mp sin(a)sin(b)         \\\\\n\t\t & sin(2\\theta) = 2sin(\\theta)cos(\\theta)               \\\\\n\t\t & cos(2\\theta) = cos^2(\\theta) - sin^2(\\theta)         \\\\\n\t\t & sin^2(\\theta) = {1 - cos(2\\theta) \\over 2}           \\\\\n\t\t & cos^2(\\theta) = {1 + cos(2\\theta) \\over 2}\n\t\\end{align}\n\\end{theorem}\n\nReminder: $ trig^n(x) $ is a notation often used to indicate $ (trig(x))^n $. \\\\\n\n\\chapter{Exponential Functions}\n\n\\section{Exponential Functions}\n\nExponential functions are of the form $ y = a^x $, where $ a $ is a positive number and $ x $ is any real number. You might see these sorts of functions when studying population growth, economic growth, global temperature, monetary value, etc. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.6]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-1) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:2] plot (\\x,{2 ^ \\x}) node[right] {$ y = {a^x} $};\n\t\t\\draw[very thick,color=red,domain=-2:3] plot (\\x,{0.5 ^ \\x});\n\t\\end{tikzpicture}\n\t\\caption{exponential function}\n\\end{figure}\n\n\\begin{itemize}\n\t\\item\n\t      Domain: $ x \\in \\mathbb R $ \\\\\n\n\t\\item\n\t      Range: $ y > 0 $ \\\\\n\n\t\\item\n\t      The graph $ y = a^x $ always passes through $ (0, 1) $ and $ (1, a) $. \\\\\n\n\t\\item\n\t      If $ a > 1$ then the graph of $ y = a^x $ is increasing. \\\\\n\n\t\\item\n\t      If $ 0 < a < 1 $ then the graph of  $ y = a^x $ is decreasing. \\\\\n\n\t\\item\n\t      $ y = 0 $ is always a horizontal asymptote of $ y = a^x $. \\\\\n\\end{itemize}\n\n\\section{Exponent Rules}\n\n\\begin{theorem}[Exponent Rules]\n\t\\begin{align}\n\t\t & a^{-x} = {1 \\over a^x}                    \\\\\n\t\t & {1 \\over a^{-x}} = a^x                    \\\\\n\t\t & (ab)^x = a^xb^x                           \\\\\n\t\t & ({a \\over b})^x = {a^x \\over b^x}         \\\\\n\t\t & a^{kx} = (a^k)^x = (a^x)^k                \\\\\n\t\t & a^ma^n = a^{m+n}                          \\\\\n\t\t & {a^m \\over a^n} = a^{m-n}                 \\\\\n\t\t & a^{1/n} = \\sqrt[n]{a}                     \\\\\n\t\t & a^{m/n} = \\sqrt[n]{a^m} = (\\sqrt[n]{a})^m\n\t\\end{align}\n\\end{theorem}\n\n\\section{The Base e}\n\nA very special exponential function is $ y = e^x $, where $ e $ is just a content with a non-terminating decimal like $ \\pi $. \\\\\n\n$$\n\te = 2.718281845...\n$$\n\nWhat is so special about an exponential function with base $ e $? \\\\\n\nAt any point on the graph, the height of the exponential function is equal to the slope of the tangent line to the graph at that point. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.6]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-3) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:1] plot (\\x,{e ^ \\x}) node[left] {$ y = {e^x} $};\n\t\t\\draw[very thick,color=blue,domain=-2:2] plot (\\x,{\\x + 1});\n\t\\end{tikzpicture}\n\t\\caption{$ y = e^x $}\n\\end{figure}\n\n\\chapter{Logarithmic Functions}\n\n\\section{Logarithmic Functions}\n\nLogarithms are the inverse of exponential functions. Let $ a > 0$, then we define a logarithm (log) as follows: \\\\\n\n\\begin{theorem}[Logarithmic Functions]\n\t\\begin{align}\n\t\ty   & = log_a(x) \\\\\n\t\ta^y & = x\n\t\\end{align}\n\\end{theorem}\n\nIf no base $ a $ is shown, a base of 10 is assumed. \\\\\n\nFor example: \\\\\n$$\n\tlog(x) = log_{10}(x)\n$$\n\n\\begin{exercise}\n\tEvaluate each of the following. \\\\\n\n\t(a) $ log_{2}8 = $ \\\\\n\n\t(b) $ log(100) = $ \\\\\n\n\t(c) $ log_{5}{1 \\over 25} = $ \\\\\n\n\t(d) $ log_{8}1 = $\n\\end{exercise}\n\nSince any positive number to the power of 0 is equal to 1, we have the property that $ log_a(1) $, no matter what the base $ a $ is. \\\\\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8]\n\t\t\\draw[->] (-1,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-4) -- (0,4) node[above] {$ y $};\n\t\t\\draw [very thick,color=red,domain=0.1:4,samples=100] plot (\\x,{log2(\\x)}) node[right] {$ y = log_2(x) $};\n\t\t\\draw [very thick,color=red,domain=0.1:4,samples=100] plot (\\x,{log10(\\x) / log10(0.5)}) node[right] {$ y = log_{1 \\over 2}(x) $};\n\t\\end{tikzpicture}\n\t\\caption{logarithmic function}\n\\end{figure}\n\n\\begin{itemize}\n\t\\item\n\t      Domain: $ 0 < x < \\infty $ \\\\\n\n\t\\item\n\t      Range: $ y \\in \\mathbb R $ \\\\\n\n\t\\item\n\t      $ y = log_a(x) $ always passes through $ (a, 1) $ and $ (1, 0) $. \\\\\n\n\t\\item\n\t      If $ a > 1 $ then the graph of $ y = log_a(x) $ is increasing. \\\\\n\n\t\\item\n\t      If $ 0 < a < 1 $ then the graph of $ y = log_a(x) $ is decreasing. \\\\\n\n\t\\item\n\t      $ x = 0 $ is always a vertical asymptote of $ y = log_a(x) $. \\\\\n\\end{itemize}\n\n\\section{Logarithm Rules}\n\n\\begin{theorem}[Logarithm Rules]\n\t\\begin{align}\n\t\t & log_a(a^x) = x                                      \\\\\n\t\t & a^{log_a(x)} = x                                    \\\\\n\t\t & log_a(xy) = log_a(x) + log_a(y)                     \\\\\n\t\t & log_a\\left({x \\over y}\\right) = log_a(x) - log_a(y) \\\\\n\t\t & log_a(x^n) = nlog_a(x)\n\t\\end{align}\n\\end{theorem}\n\n\\section{Change of Base Formula}\n\nWe can switch between any two bases easily by using the formula: \\\\\n\n\\begin{theorem}[Change of Base Formula]\n\t\\begin{align}\n\t\tlog_a(x) = {log_b(x) \\over log_b(a)}\n\t\\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n\tProof\n\t\n\t\\vspace{5cm}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n\tConvert $ log_4(x) $ into a logarithm with each of the following bases. \\\\\n\n\t(a) base 3\n\t\\\\\n\t\\\\\n\n\t(b) base 22\n\t\\\\\n\t\\\\\n\\end{exercise}\n\n\\section{The Natural Logarithm}\n\nA special logarithm is the natural logarithm, which is the logarithm with a base of $ e $. Rather than write $ log_e(x) $, we typically write $ ln(x) $. \\\\\n\nThe natural logarithm has the exact same properties as any other logarithmic function. \\\\\n\n\\begin{theorem}[Natural Logarithm]\n\t\\begin{align}\n\t\t & ln(e^x) = x   \\\\\n\t\t & e^{ln(x)} = x\n\t\\end{align}\n\\end{theorem}\n\n\\begin{exercise}\\nonumber\n\tSolve each of the following for $ x $. \\\\\n\n\t(a)\n\t\\begin{align}\n\t\t2^x & = 2^{1-x}     \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\t\\\\\n\n\t(b)\n\t\\begin{align}\n\t\t3^{{1 \\over 2} + 10} & = 27   \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\t\\\\\n\n\t(c)\n\t\\begin{align}\n\t\t2^x     & = 10                   \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\t\\\\\n\n\t(d)\n\t\\begin{align}\n\t\tlog(x) - 1   & = log(x - 1)                           \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\t\\\\\n\n\t(e)\n\t\\begin{align}\n\t\tlog_2(x) + log_2(x^2) & = 6 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\t\\\\\n\n\t(f)\n\t\\begin{align}\n\t\tlog_2(x^4) + log_2(x^2) & = 6     \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\\end{exercise}", "meta": {"hexsha": "3a63c0ea91032dba1f99d914222f58b056d93a92", "size": 19393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/parts/part1.tex", "max_stars_repo_name": "xdai02/Calculus", "max_stars_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Calculus/parts/part1.tex", "max_issues_repo_name": "xdai02/Calculus", "max_issues_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus/parts/part1.tex", "max_forks_repo_name": "xdai02/Calculus", "max_forks_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 27.664764622, "max_line_length": 246, "alphanum_fraction": 0.532253906, "num_tokens": 7665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8633916029436189, "lm_q1q2_score": 0.7699821680434786}}
{"text": "\\subsection{Topological spaces}\\label{subsec:topological_spaces}\n\n\\begin{definition}\\label{def:topological_space}\\mcite[11]{Engelking1989}\n  Let \\( X \\) be any set and \\( \\mscrT \\subseteq \\pow(X) \\) be a family of subsets of \\( X \\). \\( \\mscrT \\) is called a \\term{topology} on \\( X \\) and the tuple \\( (X, \\mscrT) \\) is said to be a \\term{topological space} if the following axioms are satisfied:\n  \\begin{thmenum}\n    \\thmitem[def:topological_space/O1]{O1} \\( \\varnothing, X \\in T \\)\n    \\thmitem[def:topological_space/O2]{O2} \\( U, V \\in T \\implies U \\cap V \\in T \\)\n    \\thmitem[def:topological_space/O3]{O3} \\( \\mscrT' \\subseteq T \\implies \\bigcap \\mscrT' \\in T \\)\n  \\end{thmenum}\n\n  If the topology is obvious from the context, we say that \\( X \\) is a topological space.\n\n  Elements of the set \\( X \\) are called \\term{points} of the topological space, elements of \\( \\mscrT \\) are called \\term{open sets} and set-theoretic complements of open sets are called \\term{closed sets}.\n\n  If \\( x \\in U \\in T \\), we say that \\( U \\) is a \\term{neighborhood} of \\( x \\). Note that some authors (e.g. \\cite[38]{Kelley1955}) alternatively define neighborhoods as arbitrary sets that contain an open set that contains \\( x \\). For simplicity, we define the subfamily\n  \\begin{equation*}\n    \\mscrT(x) \\coloneqq \\{ U \\in T \\colon x \\in U \\}.\n  \\end{equation*}\n\n  We say that \\( U \\) is a \\term{punctured neighborhood} of \\( x \\) if \\( U \\cup \\{ x \\} \\) is an open set and, consequently, a neighborhood of \\( x \\).\n\n  Dually, we can define the family \\( \\mscrF \\) of closed sets, where\n  \\begin{thmenum}\n    \\thmitem[def:topological_space/F1]{F1} \\( \\varnothing, X \\in F \\)\n    \\thmitem[def:topological_space/F2]{F2} \\( U, V \\in F \\implies U \\cup V \\in F \\)\n    \\thmitem[def:topological_space/F3]{F3} \\( \\mscrF' \\subseteq F \\implies \\bigcup \\mscrF' \\in F \\)\n  \\end{thmenum}\n\n  If \\( (X, \\mscrT) \\) is a topological space, we denote the corresponding family of closed sets by\n  \\begin{equation*}\n    \\mscrF_\\mscrT \\coloneqq \\{ X \\setminus U \\colon U \\in T \\}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:standard_topologies}\n  On a space \\( X \\), we can explicitly define the following standard topologies:\n  \\begin{thmenum}\n    \\thmitem{def:standard_topologies/discrete} The \\term{discrete topology} \\( \\mscrT \\coloneqq \\pow(X) \\).\n    \\thmitem{def:standard_topologies/indiscrete} The \\term{indiscrete topology} \\( \\mscrT \\coloneqq \\{ \\varnothing, X \\} \\).\n    \\thmitem{def:standard_topologies/co_cardinal} For any \\hyperref[def:cardinal]{cardinal} \\( \\xi \\), the \\term{co-\\( \\xi \\) topology} \\( \\mscrT \\coloneqq \\{ A \\subseteq X \\colon \\card A < \\xi \\} \\) and, in particular, \\term{cofinite} (\\( \\xi = \\aleph_0 \\)) and \\term{cocountable} (\\( \\xi = c \\)) topologies.\n  \\end{thmenum}\n\n  For a deeper connection between discrete and indiscrete topologies, see \\fullref{ex:def:category_adjunction/set_top}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:set_open_iff_neighborhood_is_contained}\n  A set \\( A \\) is open if and only if every point of \\( A \\) has a neighborhood \\( U \\) such that \\( U \\subseteq A \\).\n\\end{proposition}\n\\begin{proof}\n  This holds vacuously for empty sets. Assume that \\( A \\subseteq X \\) is nonempty.\n\n  \\SufficiencySubProof Assume that \\( A \\) is open and let \\( x_0 \\in A \\). Then \\( A \\) is a neighborhood of \\( x_0 \\) and the theorem holds trivially.\n  \\NecessitySubProof Assume that every point \\( x \\in A \\) has a neighborhood \\( U_x \\) such that \\( U_x \\subseteq A \\). Take the union\n  \\begin{equation*}\n    B \\coloneqq \\cup_{x \\in A} U_x.\n  \\end{equation*}\n\n  Obviously \\( B \\subseteq A \\). Aiming at a contradiction, suppose that \\( y_0 \\in A \\setminus B \\). Then \\( y_0 \\) has a neighborhood \\( U_{y_0} \\) such that \\( U_{y_0} \\setminus B \\) is nonempty. But this is impossible by the definition of \\( B \\). The obtained contradiction proves \\( B = A \\).\n\\end{proof}\n\n\\begin{remark}\\label{rem:abritrary_family_to_topology}\n  It is sometimes easier to define a topology \\( \\mscrT \\) via a subset of \\( \\mscrT \\). We will gradually construct a topology from a bare family of sets in \\( X \\). First, we will give two definitions for a base, one on which does not require an existing topology.\n\\end{remark}\n\n\\begin{definition}\\label{def:topological_base}\\mcite[12]{Engelking1989}\n  Fix a topological space \\( (X, \\mscrT) \\). We say that the family \\( \\mscrB \\subseteq T \\) is a \\term{base} for the topology \\( \\mscrT \\) if \\( \\mscrB \\) satisfies any of the equivalent conditions:\n  \\begin{thmenum}\n    \\thmitem{def:topological_base/union} Every open set \\( U \\in T \\) is the union \\( U = \\bigcup \\mscrB' \\) of some subset \\( \\mscrB' = \\mscrB \\)\n    \\thmitem{def:topological_base/subset} For any point \\( x \\in X \\) and for any neighborhood \\( U \\) of \\( x \\) there exists a set \\( V \\in B \\) in the base such that \\( x \\in V \\subseteq U \\)\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:topological_base/union}{def:topological_base/subset} Fix a point \\( x \\in X \\) and a neighborhood \\( U \\in T \\) of \\( x \\). Let \\( \\mscrB' \\) be a subfamily of \\( \\mscrB \\) such that\n  \\begin{equation*}\n    U = \\bigcup \\mscrB'.\n  \\end{equation*}\n\n  Then \\( x \\in V \\) for at least one \\( V \\in B' \\).\n\n  \\ImplicationSubProof{def:topological_base/subset}{def:topological_base/union} Fix an open set \\( U \\in T \\). Then for every \\( x \\in U \\), there exists a set \\( V_x \\in B \\) such that \\( x \\in V_x \\subseteq U \\). We have\n  \\begin{equation*}\n    \\bigcup_{x \\in U} V_x \\subseteq U \\subseteq \\bigcup_{x \\in U} V_x,\n  \\end{equation*}\n  thus\n  \\begin{equation*}\n    U = \\bigcup_{x \\in U} V_x.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:topological_base_axioms}\\mcite[12]{Engelking1989}\n  Let \\( X \\) be an arbitrary set and let \\( \\mscrB \\) be a family of subset that satisfies\n  \\begin{thmenum}\n    \\thmitem[thm:topological_base_axioms/B1]{B1} \\( \\bigcup \\mscrB = X \\)\n    \\thmitem[thm:topological_base_axioms/B2]{B2} \\( \\forall U, V \\in B, \\forall x \\in U \\cap V, \\exists W \\in B: x \\in W \\subseteq U \\cap V \\)\n  \\end{thmenum}\n\n  Then the family\n  \\begin{balign}\\label{thm:topological_base_axioms/topology}\n    \\mscrT \\coloneqq \\left\\{ \\bigcup \\mscrB' \\colon \\mscrB' \\subseteq B \\right\\}\n  \\end{balign}\n  is a topology on \\( X \\). Furthermore, \\( \\mscrB \\) is a \\hyperref[def:topological_base]{base} of \\( \\mscrT \\).\n\n  In particular, the base on any topology satisfies \\fullref{thm:topological_base_axioms/B1} -- \\fullref{thm:topological_base_axioms/B2}.\n\\end{proposition}\n\\begin{proof}\n  We will first prove that \\( \\mscrT \\) is indeed a topology.\n\n  \\begin{refenum}\n    \\refitem{def:topological_space/O1} \\( \\varnothing = \\bigcup \\varnothing \\in \\tau \\) and \\( X = \\bigcup \\mscrB \\in T \\) (by \\fullref{thm:topological_base_axioms/B1})\n\n    \\refitem{def:topological_space/O3} Fix \\( \\mscrT' = \\{ U_\\alpha \\colon \\alpha \\in A \\} \\subseteq T \\). By \\fullref{def:topological_base/union}, every set \\( U_\\alpha \\) has a corresponding subfamily \\( \\mscrB_\\alpha \\) of \\( \\mscrB \\) such that \\( U_\\alpha = \\bigcup \\mscrB_\\alpha \\).\n\n    Define \\( \\mscrB' \\coloneqq \\bigcup_{\\alpha \\in A} \\mscrB_\\alpha \\). Obviously \\( \\mscrB' \\subseteq B \\) and thus, by \\fullref{thm:topological_base_axioms/B1}, \\( \\bigcup \\mscrB \\in T \\).\n\n    \\refitem{def:topological_space/O2} Fix \\( U, V \\in T \\) and families \\( \\mscrB_U, \\mscrB_V \\subseteq B \\) such that \\( U = \\bigcup \\mscrB_U \\) and \\( V = \\bigcup \\mscrB_V \\).\n\n    Fix arbitrary \\( U' \\in B_U \\) and \\( V' \\in B_V \\). We will show that \\( U' \\cap V' \\in \\tau \\).\n\n    By \\fullref{thm:topological_base_axioms/B2}, for every \\( x \\in U' \\cap V' \\) there exists a neighborhood \\( W_x \\) of \\( x \\) such that \\( W \\subseteq U' \\cap V' \\).\n\n    The family \\( \\mscrB_{U',V'} \\coloneqq \\{ W_x \\colon x \\in U' \\cap V' \\} \\) is a subfamily of \\( \\mscrB \\) and thus \\( U' \\cap V' = \\bigcup \\mscrB_{U',V'} \\in T \\).\n\n    Hence, by \\fullref{def:topological_space/O3}, \\( U \\cap V \\in \\tau \\).\n\n    Now, for any \\( U \\in T \\), by \\fullref{thm:topological_base_axioms/topology}, there exists a subfamily \\( \\mscrB' \\subseteq B \\) such that\n    \\begin{equation*}\n      U = \\bigcup \\mscrB'.\n    \\end{equation*}\n\n    Hence, \\( \\mscrB \\) is a base for \\( \\mscrT \\).\n  \\end{refenum}\n\\end{proof}\n\n\\begin{definition}\\label{def:topological_space_weight}\n  We define the \\term{weight} of \\( (X, \\mscrT) \\) as the cardinal\n  \\begin{equation*}\n    w((X, \\mscrT)) \\coloneqq \\min \\{ \\abs{\\mscrB} \\colon \\mscrB \\text{ is a base for } \\mscrT \\}.\n  \\end{equation*}\n\n  We simply write \\( w(X) \\) when the topology is clear from the context.\n\n  Spaces for which \\( w(X) \\leq \\aleph_0 \\) are said to be \\term{second-countable}.\n\\end{definition}\n\\begin{proof}\n  The definition is correct because cardinals are well-ordered when regarded as initial ordinals.\n\\end{proof}\n\n\\begin{definition}\\label{def:topological_subbase}\\mcite[12]{Engelking1989}\n  Fix a topological space \\( (X, \\mscrT) \\). We say that the family \\( \\mscrP \\subseteq T \\) is a \\term{subbase} for the topology \\( \\mscrT \\) if the family\n  \\begin{equation*}\n    \\mscrB \\coloneqq \\left\\{ \\bigcap P' \\colon P' \\text{ is a nonempty \\hyperref[def:set_finiteness]{finite} subset of } P \\right\\}\n  \\end{equation*}\n  of finite intersections of \\( \\mscrP \\) is a \\hyperref[def:topological_base]{base} of \\( \\mscrT \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:subbase_from_arbitrary_family}\n  Fix a set \\( X \\) and a family of subsets \\( \\mscrP \\subseteq \\pow(X) \\). The family \\( \\mscrP' \\coloneqq \\mscrP \\cup X \\) is then a \\hyperref[def:topological_subbase]{subbase} of some topology on \\( X \\).\n\\end{proposition}\n\n\\begin{definition}\\label{def:topological_local_base}\\mcite[12]{Engelking1989}\n  Fix a topological space \\( (X, \\mscrT) \\) and a point \\( x \\in X \\). We say that the family \\( \\mscrB(x) \\subseteq T \\) is a \\term{local base} for \\( \\mscrT \\) at \\( x \\) if every neighborhood of \\( x \\) contains a set from \\( \\mscrB(x) \\).\n\n  Given a base \\( \\mscrB \\), unless explicitly noted, we consider the subfamily \\( \\mscrB(x) \\) of all members of \\( \\mscrB \\) containing \\( x \\).\n\n  The indexed family of local bases \\( \\{ \\mscrB(x) \\colon x \\in X \\} \\) is called a \\term{neighborhood system} of \\( \\mscrT \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:neighborhood_iff_union_in_topological_local_base}\n  Analogously to \\fullref{def:topological_base/union}, a set \\( A \\) containing \\( x \\) is a neighborhood of \\( x \\) if and only if \\( A \\) is a union of elements of the local \\hyperref[def:topological_local_base]{base} \\( \\mscrB(x) \\).\n\\end{proposition}\n\\begin{proof}\n  Analogous to the proof of the equivalence in \\fullref{def:topological_base}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:topological_local_base_axioms}\\mcite[13]{Engelking1989}\n  Let \\( X \\) be an arbitrary set and let \\( \\{ \\mscrB(x) \\subseteq \\pow(X) \\colon x \\in X \\} \\) be an indexed family of families of subsets of \\( X \\) that satisfies\n  \\begin{thmenum}\n    \\thmitem[thm:topological_local_base_axioms/BP1]{BP1} For every \\( x \\in X \\), \\( \\mscrB(x) \\neq \\varnothing \\) and \\( x \\in U \\) for every \\( U \\in B(x) \\).\n    \\thmitem[thm:topological_local_base_axioms/BP2]{BP2} For every \\( x \\in X \\) and for all \\( U, V \\in B(x) \\), \\( \\exists W \\in B(x): W \\subseteq U \\cap V \\).\n    \\thmitem[thm:topological_local_base_axioms/BP3]{BP3} For all \\( x, y \\in X \\), \\( x \\in U \\in B(y) \\) implies that there exists \\( V \\in B(x) \\) such that \\( U \\subseteq V \\).\n  \\end{thmenum}\n\n  Then the family\n  \\begin{equation*}\n    \\mscrB \\coloneqq \\bigcup_{x \\in X} \\mscrB(x)\n  \\end{equation*}\n  is the \\hyperref[thm:topological_base_axioms]{base} of some topology \\( \\mscrT \\) on \\( X \\). Furthermore, \\( \\{ \\mscrB(x) \\subseteq \\pow(X) \\colon x \\in X \\} \\) is a \\hyperref[def:topological_local_base]{neighborhood system} for \\( (X, \\mscrT) \\).\n\n  In particular, the local base on any topology satisfies \\fullref{thm:topological_local_base_axioms/BP1} -- \\fullref{thm:topological_local_base_axioms/BP3}.\n\\end{proposition}\n\n\\begin{definition}\\label{def:topological_space_character}\n  We define the \\term{character} of the point \\( x \\in X \\) as the cardinal\n  \\begin{equation*}\n    \\chi(x) \\coloneqq \\min \\{ \\card \\mscrB(x) \\colon \\mscrB(x) \\text{ is a local base for } \\mscrT \\text{ at } x \\}.\n  \\end{equation*}\n\n  We define the \\term{character} of of \\( (X, \\mscrT) \\) as\n  \\begin{equation*}\n    \\chi((X, \\mscrT)) \\coloneqq \\sup \\{ \\chi(x) \\colon x \\in X \\}.\n  \\end{equation*}\n\n  We simply write \\( \\chi(X) \\) when the topology is clear from the context.\n\n  Spaces for which \\( \\chi(X) \\leq \\aleph_0 \\) are said to be \\term{first-countable}.\n\\end{definition}\n\\begin{proof}\n  The definition is correct because cardinals are well-ordered when regarded as initial ordinals.\n\\end{proof}\n\n\\begin{definition}\\label{def:topological_local_subbase}\n  Combining \\fullref{def:topological_subbase} and \\fullref{def:topological_local_base}, we define a \\term{local subbase} for \\( \\mscrT \\) at \\( x \\) to be a family \\( \\mscrP(x) \\subseteq T \\) such that every neighborhood \\( U \\) of \\( x \\) contains a finite intersection of sets from \\( \\mscrP(x) \\).\n\n  Given a subbase \\( \\mscrP \\), unless explicitly noted, we consider the subfamily \\( \\mscrP(x) \\) of all members of \\( \\mscrP \\) containing \\( x \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:topological_closure_operator}\\mcite[33]{Engelking1989}\n  Let \\( (X, \\mscrT) \\) be a topological space. Define the \\term{closure operator}\n  \\begin{balign*}\n     & \\cl: \\pow(X) \\to \\pow(X)                                           \\\\\n     & \\cl(A) \\coloneqq \\bigcap \\{ F : F \\in F_\\mscrT, A \\subseteq F \\}.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:topological_closure_operator/properties}\n  The closure \\hyperref[def:topological_closure_operator]{operator} has the following basic properties\n  \\begin{thmenum}\n    \\thmitem{thm:def:topological_closure_operator/properties/closed} The set \\( A \\) is closed if and only if \\( A = \\cl A \\).\n    \\thmitem{thm:def:topological_closure_operator/properties/neighborhood_intersection} For any \\( x \\in X \\), \\( x \\in \\cl A \\) if and only if every neighborhood of \\( x \\) intersects \\( A \\).\n    \\thmitem{thm:def:topological_closure_operator/properties/monotone} \\( \\cl \\) is \\hyperref[def:partially_ordered_set/homomorphism]{monotone}, i.e. if \\( A \\subseteq B \\), then \\( \\cl(A) \\subseteq \\cl(B) \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:topological_closure_operator/properties/closed} The condition \\( A = \\cl{A} \\) is equivalent to \\( A \\) being a closed superset of itself, which is equivalent to \\( A \\) being closed.\n\n  \\SubProofOf{thm:def:topological_closure_operator/properties/neighborhood_intersection} Note that this proof relies on \\fullref{def:topological_boundary}, however we do not use this property when defining the boundary.\n\n  \\SufficiencySubProof Fix \\( x \\in \\cl{A} \\) and let \\( U \\) be a neighborhood of \\( x \\). If \\( x \\in A \\), then obviously \\( x \\in U \\cap A \\neq \\varnothing \\). If \\( x \\not\\in A \\), then \\( U \\cap A \\neq \\varnothing \\) by \\fullref{def:topological_boundary/neighborhoods}. In both cases, we obtain \\( U \\cap A \\neq \\varnothing \\), which proves the statement.\n\n  \\NecessitySubProof Fix \\( x \\in X \\) and assume that every neighborhood of \\( x \\) intersects \\( A \\). Since the case \\( x \\in A \\) is trivial, suppose that \\( x \\not\\in A \\). By \\fullref{thm:set_open_iff_neighborhood_is_contained}, every neighborhood \\( U \\) of \\( x \\) does not entirely belong to \\( A \\). By \\fullref{def:topological_boundary/neighborhoods}, \\( x \\in \\fr A \\subseteq \\cl A \\).\n\n  \\SubProofOf{thm:def:topological_closure_operator/properties/monotone} If \\( A \\subseteq B \\), every closed superset of \\( B \\) is also a closed superset of \\( A \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:topological_closure_operator_axioms}\\mcite[14]{Engelking1989}\n  Let \\( X \\) be an arbitrary set and let \\( \\cl: \\pow(X) \\to \\pow(X) \\) be a function that satisfies\n  \\begin{thmenum}\n    \\thmitem[thm:topological_closure_operator_axioms/CO1]{CO1} \\( \\cl(\\varnothing) = \\varnothing \\)\n    \\thmitem[thm:topological_closure_operator_axioms/CO2]{CO2} \\( \\forall A \\in \\pow(X), A \\subseteq \\cl(A) \\)\n    \\thmitem[thm:topological_closure_operator_axioms/CO3]{CO3} \\( \\forall A, B \\in \\pow(X), \\cl(A \\cup B) = \\cl(A) \\cup \\cl(B) \\)\n    \\thmitem[thm:topological_closure_operator_axioms/CO4]{CO4} \\( \\forall A \\in \\pow(X), \\cl(\\cl(A)) = \\cl(A) \\)\n  \\end{thmenum}\n\n  Then the family\n  \\begin{equation*}\n    \\mscrT \\coloneqq \\{ X \\setminus F \\colon F = \\cl(F) \\}\n  \\end{equation*}\n  is a topology on \\( X \\). Furthermore, \\( \\cl = \\cl^{\\mscrT} \\), where \\( \\cl^{\\mscrT} \\) is the closure \\hyperref[def:topological_closure_operator]{operator} on \\( (X, \\mscrT) \\).\n\n  In particular, the closure operator on any topology satisfies \\fullref{thm:topological_closure_operator_axioms/CO1} -- \\fullref{thm:topological_closure_operator_axioms/CO4}.\n\\end{proposition}\n\n\\begin{definition}\\label{def:interior_operator}\\mcite[15]{Engelking1989}\n  Let \\( (X, \\mscrT) \\) be a topological space. Define the \\term{interior operator}\n  \\begin{balign*}\n     & \\Int: \\pow(X) \\to \\pow(X)                                     \\\\\n     & \\Int(A) \\coloneqq \\bigcup \\{ U : U \\in T, U \\subseteq A \\}.\n  \\end{balign*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:interior_operator/properties}\n  The interior \\hyperref[def:interior_operator]{operator} has the following basic properties\n  \\begin{thmenum}\n    \\thmitem{thm:def:interior_operator/properties/open} A set \\( A \\) is a topological space is open if and only if \\( A = \\int A \\).\n    \\thmitem{thm:def:interior_operator/properties/monotone} \\( \\int \\) is \\hyperref[def:partially_ordered_set/homomorphism]{monotone}, i.e. if \\( A \\subseteq B \\), then \\( \\Int(A) \\subseteq \\Int(B) \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:interior_operator/properties/open} Follows from \\fullref{thm:def:topological_closure_operator/properties/closed} and \\fullref{thm:interior_closure_complement}.\n  \\SubProofOf{thm:def:interior_operator/properties/monotone} Follows from \\fullref{thm:def:topological_closure_operator/properties/monotone} and \\fullref{thm:interior_closure_complement}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:interior_closure_complement} For every set \\( A \\subseteq X \\) we have\n  \\begin{itemize}\n    \\item \\( X \\setminus \\Int(A) = \\cl(X \\setminus A) \\)\n    \\item \\( X \\setminus \\cl(A) = \\Int(X \\setminus A) \\)\n  \\end{itemize}\n\\end{proposition}\n\\begin{proof}\n  Any open subset \\( U \\subseteq A \\) is a closed superset of \\( X \\setminus A \\). A point belongs to \\( \\Int(A) \\) if it belongs to at least one open subset of \\( A \\), which happens if and only if it belongs to at least one closed superset of \\( X \\setminus A \\). Therefore,\n  \\begin{balign*}\n    X \\setminus \\Int(A)\n     & =\n    X \\setminus \\bigcup \\{ U : U \\in T, U \\subseteq A \\}\n    =                                            \\\\ &=\n    X \\setminus \\bigcup \\{ F : F \\in F_\\mscrT, X \\setminus A \\subseteq F \\}\n    \\reloset {X \\setminus (X \\setminus A) = A} = \\\\ &=\n    \\bigcup \\{ F : F \\in F_\\mscrT, F \\subseteq A \\}.\n    =                                            \\\\ &=\n    \\cl(A).\n  \\end{balign*}\n\n  The other equality is obtained by noting that \\( X \\setminus \\cl(A) = X \\setminus (X \\setminus \\Int(A)) = \\Int(A) \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:interior_operator_axioms}\n  Let \\( X \\) be an arbitrary set and let \\( \\int: \\pow(X) \\to \\pow(X) \\) be a function that satisfies\n  \\begin{thmenum}\n    \\thmitem[thm:interior_operator_axioms/IO1]{IO1} \\( \\Int(X) = X \\)\n    \\thmitem[thm:interior_operator_axioms/IO2]{IO2} \\( \\forall A \\in \\pow(X), \\Int(A) \\subseteq A \\)\n    \\thmitem[thm:interior_operator_axioms/IO3]{IO3} \\( \\forall A, B \\in \\pow(X), \\Int(A \\cap B) = \\Int(A) \\cap \\Int(B) \\)\n    \\thmitem[thm:interior_operator_axioms/IO4]{IO4} \\( \\forall A \\in \\pow(X), \\Int(\\Int(A)) = \\Int(A) \\)\n  \\end{thmenum}\n\n  Then the family\n  \\begin{equation*}\n    \\mscrT \\coloneqq \\{ U \\colon U = \\Int(U) \\}\n  \\end{equation*}\n  is a topology on \\( X \\). Furthermore, \\( \\int = \\int_\\mscrT \\), where \\( \\int_\\mscrT \\) is the interior \\hyperref[def:interior_operator]{operator} on \\( (X, \\mscrT) \\).\n\n  In particular, the interior operator on any topology satisfies \\fullref{thm:interior_operator_axioms/IO1} -- \\fullref{thm:interior_operator_axioms/IO4}.\n\\end{proposition}\n\n\\begin{definition}\\label{def:topological_boundary}\n  For a subset \\( A \\) of a topological space we define its \\term{boundary} \\( \\fr(A) \\) equivalently as\n  \\begin{thmenum}\n    \\thmitem{def:topological_boundary/closure} \\( \\fr(A) \\coloneqq \\cl(A) \\setminus \\Int(A) \\)\n    \\thmitem{def:topological_boundary/neighborhoods} \\( \\fr(A) \\) is the set of all points \\( x \\in X \\) such that every neighborhood of \\( x \\) intersects both \\( A \\) and \\( X \\setminus A \\).\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  The equivalence of the definitions is trivial when \\( \\fr(A) = \\varnothing \\). We assume that \\( \\fr(A) \\neq \\varnothing \\).\n\n  \\ImplicationSubProof{def:topological_boundary/closure}{def:topological_boundary/neighborhoods} Let \\( x \\in \\cl(A) \\setminus \\Int(A) \\).\n\n  Aiming for a contradiction, suppose that there is a neighborhood \\( U \\) of \\( x \\) that does not intersect \\( A \\). Then \\( U \\subseteq X \\setminus A \\). Hence, \\( A \\subseteq X \\setminus U \\). Since \\( X \\setminus U \\) is closed, it follows that \\( \\cl(A) \\subseteq X \\setminus U \\) as the intersection of all closed supersets of \\( A \\). But \\( x \\not\\in X \\setminus U \\), therefore \\( x \\not\\in \\cl(A) \\), which contradicts our choice of \\( x \\in \\cl(A) \\).\n\n  This proves that every neighborhood of \\( x \\) intersects \\( A \\).\n\n  By passing to complements, we can reuse this to prove that every neighborhood of \\( x \\) intersects \\( X \\setminus A \\) using \\fullref{thm:interior_closure_complement}.\n\n  \\ImplicationSubProof{def:topological_boundary/neighborhoods}{def:topological_boundary/closure} Suppose that every neighborhood of \\( x \\in \\fr(A) \\) intersects both \\( A \\) and \\( X \\setminus A \\). Therefore, no neighborhood of \\( x \\) is contained in neither \\( A \\) not \\( X \\setminus A \\) and \\( x \\) belongs to neither \\( \\Int(A) \\) nor \\( \\Int(X \\setminus A) \\). Hence,\n  \\begin{equation*}\n    x \\in (X \\setminus \\Int(X \\setminus A)) \\setminus \\Int(A) \\reloset {\\ref{thm:interior_closure_complement}} = \\cl(A) \\setminus \\Int(A).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:topological_boundary/properties}\n  The \\hyperref[def:topological_boundary]{topological boundary} has the following basic properties\n  \\begin{thmenum}\n    \\thmitem{thm:def:topological_boundary/properties/closed} \\( \\fr(A) \\) is a closed set.\n    \\thmitem{thm:def:topological_boundary/properties/not_open} If \\( \\fr(A) \\) is not empty, it is not an open set.\n    \\thmitem{thm:def:topological_boundary/properties/complement} \\( \\fr(A) = \\fr(X \\setminus A) \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:topological_boundary/properties/closed} Note that\n  \\begin{equation*}\n    \\fr(A) = \\cl(A) \\setminus \\Int(A) = \\cl(A) \\cap (X \\setminus \\Int(A)),\n  \\end{equation*}\n  which is the intersection of two closed sets. Hence, \\( \\fr(A) \\) is itself a closed set.\n\n  \\SubProofOf{thm:def:topological_boundary/properties/not_open} Note that \\( \\fr(A) \\) is either empty or is not open because \\fullref{def:topological_boundary/neighborhoods} is incompatible with \\fullref{thm:set_open_iff_neighborhood_is_contained}.\n\n  \\SubProofOf{thm:def:topological_boundary/properties/complement} By \\fullref{thm:interior_closure_complement},\n  \\begin{balign*}\n    \\fr(A)\n     & =\n    \\cl(A) \\setminus \\Int(A)\n    =                                                  \\\\ &=\n    \\cl(A) \\cap (X \\setminus \\Int(A))\n    \\reloset {\\ref{thm:interior_closure_complement}} = \\\\ &=\n    (X \\setminus \\Int(X \\setminus A)) \\cap \\cl(X \\setminus A)\n    =                                                  \\\\ &=\n    \\cl(X \\setminus A) \\setminus \\Int(X \\setminus A)\n    =                                                  \\\\ &=\n    \\fr(X \\setminus A).\n  \\end{balign*}\n\\end{proof}\n\n\\begin{definition}\\label{def:topological_derived_set}\\mcite[24]{Engelking1989}\n  Let \\( (X, \\mscrT) \\) be a topological space.\n\n  \\begin{thmenum}\n    \\thmitem{def:topological_derived_set/cluster_point} We say that the point \\( x_0 \\in X \\) is a \\term{cluster point} or an \\term{accumulation point} of the set \\( A \\subseteq X \\) if \\( x \\in \\cl(A \\setminus \\{ x \\}) \\). It is not necessary for \\( x_0 \\) to belong to \\( A \\).\n\n    \\thmitem{def:topological_derived_set/derived_set} The set of all cluster points of \\( A \\) is called the \\term{derived set} of \\( A \\) and is denoted by \\( \\derived(A) \\).\n\n    \\thmitem{def:topological_derived_set/perfect_set} If a set equals its derived set, we call it a \\term{perfect set}.\n\n    \\thmitem{def:topological_derived_set/isolated_point} Points in \\( A \\setminus \\derived(A) \\) are said to be \\term{isolated points} of \\( A \\).\n\n    \\thmitem{def:topological_derived_set/discrete_set} If \\( \\derived(A) = \\varnothing \\), that is, if \\( A \\) consists of only discrete points, we say that \\( A \\) is a \\term{discrete set}.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:derived_set/properties}\n  \\hyperref[def:topological_derived_set]{Derived sets} have the following basic properties\n  \\begin{thmenum}\n    \\thmitem{thm:def:derived_set/properties/cluster_via_neighborhoods} \\( x \\) is a cluster point of \\( A \\) if and only if every neighborhood of \\( x \\) intersects \\( A \\setminus \\{ x \\} \\)\n    \\thmitem{thm:def:derived_set/properties/isolated_via_neighborhoods} \\( x \\) is an isolated point of \\( A \\) if and only if there exists a neighborhood of \\( x \\) that does not intersect \\( A \\setminus \\{ x \\} \\)\n    \\thmitem{thm:def:derived_set/properties/closed} \\( \\derived(A) \\) is a closed set.\n    \\thmitem{thm:def:derived_set/properties/closure} \\( A \\cup \\derived(A) = \\cl(A) \\).\n    \\thmitem{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points} A set is closed if and only if it contains all of its cluster points. Compare this result to \\fullref{thm:limit_point_iff_in_closure}.\n    \\thmitem{thm:def:derived_set/properties/closed_iff_only_isolated_and_cluster_points} A set if closed if and only if every point is either a cluster point or an isolated point.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:derived_set/properties/cluster_via_neighborhoods} If every neighborhood \\( U \\) of \\( x \\in A \\) intersects \\( A \\setminus \\{ x \\} \\), by \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}, \\( x \\in \\cl(A \\setminus \\{ x \\}) \\) and \\( x \\) is therefore a cluster point.\n\n  \\SufficiencySubProofOf{thm:def:derived_set/properties/isolated_via_neighborhoods} Dual to \\fullref{thm:def:derived_set/properties/cluster_via_neighborhoods}.\n\n  \\SubProofOf{thm:def:derived_set/properties/closed} Consider the complement of \\( \\derived(A) \\). If it is empty, \\( \\derived(A) \\) is trivially closed. Otherwise, let \\( x \\in X \\setminus \\derived(A) \\).\n\n  \\begin{itemize}\n    \\item If \\( x \\) is an isolated point of \\( A \\), by \\fullref{thm:def:derived_set/properties/isolated_via_neighborhoods} there exists a neighborhood of \\( x \\) that does not intersect \\( A \\setminus \\{ x \\} \\).\n    \\item If \\( x \\) is not a point of \\( A \\), aiming at a contradiction, assume that every neighborhood of \\( x \\) intersects \\( A \\). Then, by \\fullref{def:topological_boundary/neighborhoods}, \\( x \\in \\fr(A) \\). But \\( \\fr(A) \\subseteq \\cl(A) \\) and \\( \\cl(A) = \\cl(A \\setminus \\{ x \\}) \\) because \\( x \\) does not belong to \\( A \\). Therefore, \\( x \\) is a cluster point of \\( A \\). This contradicts our assumption that \\( x \\not\\in \\derived(A) \\), hence we can conclude that there exists a neighborhood of \\( X \\) that does not intersect \\( A = A \\setminus \\{ x \\} \\).\n  \\end{itemize}\n\n  In both cases, \\fullref{thm:set_open_iff_neighborhood_is_contained} allows us to conclude that \\( X \\setminus \\derived(A) \\) is open and, hence, \\( \\derived(A) \\) is closed.\n\n  \\SubProofOf{thm:def:derived_set/properties/closure} Clearly \\( A \\subseteq \\cl(A) \\). Also\n  \\begin{equation*}\n    \\derived(A) \\subseteq \\bigcup_{x \\in X} \\cl(A \\setminus \\{ x \\}) \\subseteq \\cl(A).\n  \\end{equation*}\n\n  Now we will prove the reverse inclusion. Let \\( x \\in \\cl(A) \\). Then either \\( x \\in A \\) or \\( x \\in \\fr(A) \\). Assume the latter. By \\fullref{def:topological_boundary/neighborhoods}, every neighborhood \\( U \\) of \\( x \\) has points both in \\( A \\) and outside \\( A \\), therefore \\( U \\cap (A \\setminus \\{ x \\}) \\) is nonempty. By \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}, \\( x \\in \\cl(A \\setminus \\{ x \\}) \\), that is, \\( x \\in \\derived(A) \\).\n\n  \\SubProofOf{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points}\n  If \\( A \\) is closed, by \\fullref{thm:def:derived_set/properties/closure},\n  \\begin{equation*}\n    A \\cup \\derived(A) = \\cl(A) = A,\n  \\end{equation*}\n  hence \\( \\derived(A) \\subseteq A \\).\n\n  \\NecessitySubProofOf{thm:def:derived_set/properties/isolated_via_neighborhoods} Dual to \\fullref{thm:def:derived_set/properties/cluster_via_neighborhoods}.\n\n  \\SubProofOf{thm:def:derived_set/properties/closed} Consider the complement of \\( \\derived(A) \\). If it is empty, \\( \\derived(A) \\) is trivially closed. Otherwise, let \\( x \\in X \\setminus \\derived(A) \\).\n\n  \\begin{itemize}\n    \\item If \\( x \\) is an isolated point of \\( A \\), by \\fullref{thm:def:derived_set/properties/isolated_via_neighborhoods} there exists a neighborhood of \\( x \\) that does not intersect \\( A \\setminus \\{ x \\} \\).\n    \\item If \\( x \\) is not a point of \\( A \\), aiming at a contradiction, assume that every neighborhood of \\( x \\) intersects \\( A \\). Then, by \\fullref{def:topological_boundary/neighborhoods}, \\( x \\in \\fr(A) \\). But \\( \\fr(A) \\subseteq \\cl(A) \\) and \\( \\cl(A) = \\cl(A \\setminus \\{ x \\}) \\) because \\( x \\) does not belong to \\( A \\). Therefore, \\( x \\) is a cluster point of \\( A \\). This contradicts our assumption that \\( x \\not\\in \\derived(A) \\), hence we can conclude that there exists a neighborhood of \\( X \\) that does not intersect \\( A = A \\setminus \\{ x \\} \\).\n  \\end{itemize}\n\n  In both cases, \\fullref{thm:set_open_iff_neighborhood_is_contained} allows us to conclude that \\( X \\setminus \\derived(A) \\) is open and, hence, \\( \\derived(A) \\) is closed.\n\n  \\SubProofOf{thm:def:derived_set/properties/closure} Clearly \\( A \\subseteq \\cl(A) \\). Also\n  \\begin{equation*}\n    \\derived(A) \\subseteq \\bigcup_{x \\in X} \\cl(A \\setminus \\{ x \\}) \\subseteq \\cl(A).\n  \\end{equation*}\n\n  Now we will prove the reverse inclusion. Let \\( x \\in \\cl(A) \\). Then either \\( x \\in A \\) or \\( x \\in \\fr(A) \\). Assume the latter. By \\fullref{def:topological_boundary/neighborhoods}, every neighborhood \\( U \\) of \\( x \\) has points both in \\( A \\) and outside \\( A \\), therefore \\( U \\cap (A \\setminus \\{ x \\}) \\) is nonempty. By \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}, \\( x \\in \\cl(A \\setminus \\{ x \\}) \\), that is, \\( x \\in \\derived(A) \\).\n\n  \\SubProofOf{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points} Assume that \\( \\derived(A) \\subseteq A \\) and, aiming at a contradiction, suppose that \\( A \\) is not closed. Fix a point \\( x \\in \\cl(A) \\setminus A \\). By \\fullref{thm:def:derived_set/properties/closure}, this is a cluster point. By \\fullref{thm:def:derived_set/properties/cluster_via_neighborhoods}, every for neighborhood \\( U \\) of \\( x \\) the intersection \\( U \\cap (A \\setminus \\{ x \\}) \\subseteq U \\cap A \\) is nonempty. Since this holds for arbitrary neighborhoods, by \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}, \\( A \\) is closed.\n\n  \\SufficiencySubProofOf{thm:def:derived_set/properties/closed_iff_only_isolated_and_cluster_points}\n  Special case of \\fullref{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points}.\n  \\NecessitySubProofOf{thm:def:derived_set/properties/closed_iff_only_isolated_and_cluster_points} We already know from \\fullref{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points} that it is sufficient for \\( \\derived(A) \\) to belong to \\( A \\) for \\( A \\) to be closed. But \\( A \\setminus \\derived(A) \\) consists of all isolated points, therefore every point in \\( A \\) is either a cluster point or an isolated point.\n\\end{proof}\n\n\\begin{definition}\\label{def:topologically_dense_set}\\mcite[25]{Engelking1989}\n  Let \\( (X, \\mscrT) \\) be a topological space and \\( A \\subseteq X \\) be any set. We say that \\( A \\) is\n\n  \\begin{thmenum}\n    \\thmitem{def:topologically_dense_set/dense} \\term{dense} in \\( X \\) if \\( \\cl{A} = X \\) (if \\( X \\) is assumed from the context, we simply say that \\( A \\) is dense).\n\n    \\thmitem{def:topologically_dense_set/codense} \\term{codense} in \\( X \\) if \\( X \\setminus A \\) is dense, i.e. \\( \\cl(X \\setminus A) = X \\).\n\n    \\thmitem{def:topologically_dense_set/nowhere_dense} \\term{nowhere dense} in \\( X \\) if \\( \\cl(A) \\) is codense, i.e. \\( X = \\cl(X \\setminus \\cl A) \\reloset {\\ref{thm:interior_closure_complement}} = \\cl(\\Int(X \\setminus A)) \\).\n\n    \\thmitem{def:topologically_dense_set/dense_in_itself} \\term{dense in itself} if \\( A \\subseteq \\derived(A) \\), i.e. if \\( A \\) has no isolated points.\n  \\end{thmenum}\n\n  We define the \\term{density} \\( d(X) \\) of \\( X \\) to be the minimum \\hyperref[def:cardinal]{cardinality} of all dense sets. If \\( d(X) \\leq \\aleph_0 \\), we say that the space is \\term{separable}.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:def:dense_set/properties}\n  \\hyperref[def:topologically_dense_set/dense]{Dense sets} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:dense_set/properties/open_intersection}\\mcite[prop. 1.3.5]{Engelking1989} The set \\( A \\) is dense if and only if every nonempty open set intersects \\( A \\).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:dense_set/properties/open_intersection} Special case of \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:def:nowhere_dense/properties}\n  \\hyperref[def:topologically_dense_set/nowhere_dense]{Nowhere dense sets} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:nowhere_dense/properties/empty_interior} Nowhere dense sets have an empty interior\n    \\thmitem{thm:def:nowhere_dense/properties/contained_in_boundary} Nowhere dense sets are entirely contained in their boundaries.\n    \\thmitem{thm:def:nowhere_dense/properties/interior_of_closure} The set \\( A \\) is nowhere dense if and only if \\( \\Int(\\cl(A)) = \\varnothing \\).\n    \\thmitem{thm:def:nowhere_dense/properties/closure_contains_no_open_set} The set is nowhere dense if and only if its closure does not contain a nonempty open set.\n    \\thmitem{thm:def:nowhere_dense/properties/open_subset}\\mcite[prop. 1.3.5]{Engelking1989}The set \\( A \\) is nowhere dense if and only if every open set contains a nonempty open subset disjoint from \\( A \\).\n    \\thmitem{thm:def:nowhere_dense/properties/subset} A subset of a nowhere dense set is nowhere dense.\n    \\thmitem{thm:def:nowhere_dense/properties/homeomorphism} The \\hyperref[def:homeomorphism]{homeomorphic} image of a nowhere dense set is nowhere dense.\n    \\thmitem{thm:def:nowhere_dense/properties/complement_dense} A set is closed and nowhere dense if and only if its complement is open and dense.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:nowhere_dense/properties/interior_of_closure} Follows directly from \\fullref{thm:interior_closure_complement}.\n  \\SubProofOf{thm:def:nowhere_dense/properties/empty_interior} Follows from \\fullref{thm:def:nowhere_dense/properties/interior_of_closure} because \\( \\Int(A) \\subseteq \\Int(\\cl(A)) = \\varnothing \\).\n\n  \\SubProofOf{thm:def:nowhere_dense/properties/contained_in_boundary} Follows from \\fullref{thm:def:nowhere_dense/properties/empty_interior} and \\fullref{def:topological_boundary/closure}.\n\n  \\SubProofOf{thm:def:nowhere_dense/properties/closure_contains_no_open_set} By \\fullref{thm:def:dense_set/properties/open_intersection}, \\( A \\) is nowhere dense if and only if every nonempty open set intersects \\( X \\setminus \\cl(A) \\reloset {\\ref{thm:interior_closure_complement}} = \\Int(X \\setminus A) \\). By \\fullref{thm:set_open_iff_neighborhood_is_contained}, the last condition is equivalent to every nonempty open set having a nonempty open subset in \\( \\Int(X \\setminus A) = X \\setminus \\cl(A) \\), which in turn implies \\fullref{thm:def:nowhere_dense/properties/closure_contains_no_open_set}.\n\n  \\SubProofOf{thm:def:nowhere_dense/properties/subset} Let \\( A \\) be a nowhere dense set and let \\( B \\subseteq A \\). Then\n  \\begin{equation*}\n    \\Int(\\cl(B))\n    \\reloset {\\ref{thm:def:interior_operator/properties/monotone}} \\subseteq\n    \\Int(\\cl(A))\n    \\reloset {\\ref{thm:def:nowhere_dense/properties/interior_of_closure}} =\n    \\varnothing,\n  \\end{equation*}\n  therefore \\( B \\) is also nowhere dense.\n\n  \\SubProofOf{thm:def:nowhere_dense/properties/homeomorphism} Let \\( f: X \\to Y \\) be a homeomorphic embedding (not necessarily surjective) and let \\( A \\subseteq X \\) be a nowhere dense set. Let \\( V \\) be an open set in \\( Y \\). Then \\( f^{-1}(V) \\) is open in \\( X \\) and, by \\fullref{thm:def:nowhere_dense/properties/open_subset}, there exists an open subset \\( U \\subseteq f^{-1}(V) \\) that is disjoint from \\( A \\). Therefore, \\( f(U) \\subseteq f(f^{-1}(V)) \\reloset {\\ref{thm:function_image_preimage_composition/image_of_preimage}} \\subseteq V \\). Furthermore, \\( f(U) \\) is open and \\( f(U) \\cap f(A) \\reloset {\\ref{thm:def:function_image/properties/intersection}} = f(U \\cap A) = f(\\varnothing) = \\varnothing \\), therefore \\( f(A) \\) is nowhere dense.\n\n  \\SubProofOf{thm:def:nowhere_dense/properties/complement_dense} If \\( A \\) is an open dense set, then \\( X \\setminus A \\) is closed and\n  \\begin{equation*}\n    \\cl(X \\setminus \\cl(X \\setminus A))\n    =\n    \\cl(X \\setminus (X \\setminus A))\n    =\n    \\cl(A)\n    =\n    X,\n  \\end{equation*}\n  therefore \\( X \\setminus A \\) is nowhere dense.\n\\end{proof}\n\n\\begin{definition}\\label{def:borel_algebra}\n  Fix a topological space \\( X \\) and \\( \\mscrF \\subseteq \\pow(X) \\). Denote by \\( \\mscrF_\\delta \\) the family of all countable intersections of elements of \\( \\mscrF \\) and by \\( \\mscrF_\\sigma \\) the family of all countable unions of elements of \\( \\mscrF \\).\n\n  The family \\( F_\\delta \\) is the family of countable unions of closed sets and \\( G_\\sigma \\) is the family of countable intersections of open sets.\n\\end{definition}\n", "meta": {"hexsha": "eb92067dae9f1b81615a80356d1769a980e9983f", "size": 38858, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/topological_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_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_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": 72.2267657993, "max_line_length": 760, "alphanum_fraction": 0.6831283133, "num_tokens": 12481, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8918110346549902, "lm_q1q2_score": 0.7699821618683672}}
{"text": "\\section{Hierarchical Basis and Hierarchical Subspace}\n\\label{sec:22hierSubspaces}\n\n\\minitoc{67mm}{5}\n\n\\noindent\nThe dimension of the nodal space $\\ns{\\*l}$ is given by\n\\begin{equation}\n  \\label{eq:dimensionFG}\n  \\dim \\ns{\\*l}\n  = \\setsize{\\fgset{\\*l}}\n  = \\prod_{t=1}^d (2^{l_t} + 1).\n\\end{equation}\nIf we choose the same level $n \\in \\natz$ in all dimensions,\nthen the dimension of $\\ns{n,d}$ and the\nnumber of grid points grow at least as fast as\n$2^{nd} = (\\ms{n}^{-1})^d$.\nThis exponential dependency between $\\dim \\ns{n,d}$ and $d$ is known as the\n\\term{curse of dimensionality} \\cite{Bellman61Adaptive}.\nThe curse makes interpolation on $\\ns{\\*l}$ computationally infeasible\nfor dimensionalities $d > 4$,\nas we would have to calculate and store\n$\\dim(\\ns{\\*l})$-many coefficients $\\interpcoeff{\\*l,\\*i}$.%\n\n\n\n\\subsection{Hierarchical Splitting in the Univariate Case}\n\\label{sec:221hierUV}\n\n\\paragraph{Hierarchical subspaces}\n\nIn order to reduce the computational effort,\nwe first split $\\ns{\\*l}$ into smaller subspaces and then identify\nsubspaces that we can omit at the cost of a slightly larger error.\nIn the univariate case, the key observation is that a grid point of a\nlevel $l$ can be written as a grid point of a higher level~$l'$:\n\\begin{equation}\n  \\label{eq:rewriteGridPoint}\n  \\gp{l,i} = \\gp{l',i'},\\quad\n  l' \\ge l,\\quad\n  i' = 2^{l'-l} i.\n\\end{equation}\nConversely, this implies that every grid point $\\gp{l,i}$ of level $l \\ge 1$\nand index $i \\ge 1$ can be uniquely written\nas a grid point of a coarser level $l'$ (or $l' = l$) and an odd index $i'$:\n\\begin{equation}\n  \\gp{l,i} = \\gp{l',i'},\\quad\n  l' = l - \\bracket*{\\log_2(\\xor(i, i-1) + 1) - 1},\\quad\n  i' = 2^{l'-l} i,\n\\end{equation}\nwhere $\\xor$ is the bitwise ``exclusive or'' function.\nThe term in square brackets is the exponent of the\nhighest power of two that divides $i$.\nThe two boundary points zero and one are obtained by\ninserting an additional level $l' = 0$ with indices $i' \\in \\{0, 1\\}$.\nAs shown in \\cref{fig:pointSplittingUniform},\nthis implies that $\\fgset{l}$ decomposes into\n\\begin{equation}\n  \\fgset{l}\n  = \\bigdotcup_{l'=0}^l \\{\\gp{l',i'} \\mid i' \\in \\hiset{l'}\\},\\quad\n  \\hiset{l'} \\ceq\n  \\begin{cases}\n    \\{i' = 0, \\dotsc, 2^{l'} \\mid \\text{$i'$ odd}\\},&l' > 0,\\\\\n    \\{0, 1\\},&l' = 0,\n  \\end{cases}\n\\end{equation}\nwhere $\\dotcup$ indicates the disjoint union.\nWe call the spaces spanned by the basis functions that correspond to the\nindex sets $\\hiset{l'}$ \\term{hierarchical subspaces} $\\hs{l'}$:\n\\begin{equation}\n  \\hs{l'}\n  \\ceq \\spn\\{\\basis{l',i'} \\mid i' \\in \\hiset{l'}\\}.\n\\end{equation}\nThe corresponding basis functions\n$\\basis{l',i'}$, $l' = 0, \\dotsc, l$, $i' \\in \\hiset{l'}$,\nare called \\term{hierarchical basis functions.}\nThe hierarchical hat function basis is shown in \\cref{fig:hierarchicalHat}.\n\n\\begin{SCfigure}\n  \\includegraphics{pointSplitting_1}%\n  \\caption[%\n    Decomposition of the set of univariate grid points%\n  ]{%\n    The set of grid points $\\fgset{l}$ of level $l = 4$ \\emph{(top)}\n    decomposes into hierarchical grids of level $l' \\le l$,\n    whose grid points $\\gp{l',i'}$ have odd indices $i' \\in \\hiset{l'}$\n    ($\\gp{0,0}$ being the only exception).%\n  }%\n  \\label{fig:pointSplittingUniform}%\n\\end{SCfigure}\n\n\\begin{figure}\n  \\subcaptionbox{%\n    Basis functions $\\bspl{l',i'}{1}$ ($l' \\le l$, $i' \\in \\hiset{l'}$)\n    and grid points $\\gp{l',i'}$ \\emph{(dots).}\n    The domain is the unit interval $\\clint{0, 1}$.%\n  }[72mm]{%\n    \\includegraphics{hierarchicalBasis_2}%\n  }%\n  \\hfill%\n  \\subcaptionbox{%\n    Piecewise linear interpolant $\\fgintp{l}$\n    of some function data $\\objfun(\\gp{\\*l,\\*i})$\n    as a linear combination of hierarchical hat functions \\emph{(stacked).}\n    The two boundary functions are combined to a single function\n    \\emph{\\textcolor{C0}{(blue)}} for simplicity.%\n  }[72mm]{%\n    \\includegraphics{interpolant_2}%\n  }%\n  \\caption[%\n    Univariate hierarchical hat functions%\n  ]{%\n    Univariate hierarchical hat functions up to level $l = 3$.%\n  }%\n  \\label{fig:hierarchicalHat}%\n\\end{figure}\n\n\\paragraph{Hierarchical splitting}\n\nFor the hat function basis $\\bspl{l,i}{1}$ and other basis types,\nwe can prove that the corresponding nodal space\ndecomposes into the direct sum of all\nhierarchical subspaces of coarser levels or the same level, i.e.,\n\\begin{equation}\n  \\label{eq:hierSplittingUV}\n  \\ns{l}\n  \\overset{?}{=} \\bigoplus_{l'=0}^l \\hs{l'}.\n\\end{equation}\nWe call this relation \\term{hierarchical splitting.}\nHere, the direct sum $\\oplus$ is\nthe vector space sum that additionally indicates\nthat the dimension of the sum $\\sum_{l'=0}^l \\hs{l'}$ is the sum\nof the dimensions of the summands $\\hs{l'}$\n(analogously to\n$\\setsize{\\fgset{l}}\n= \\sum_{l'=0}^l \\setsize{\\{\\gp{l',i'} \\mid i' \\in \\hiset{l'}\\}}$,\nwhere $\\fgset{l}$ is the disjoint union of the sets\n$\\{\\gp{l',i'} \\mid i' \\in \\hiset{l'}\\}$).\nIn general, \\eqref{eq:hierSplittingUV} may not be true,\ndepending on the type of basis functions.\nThe following lemma provides a characterization\nthat can be used to prove \\eqref{eq:hierSplittingUV} for hat functions.\n\n\\vspace*{\\fill}\n\\pagebreak\n\n\\begin{lemma}[univariate hierarchical splitting characterization]\n  \\label{lemma:hierSplittingUV}\n  \\Cref{eq:hierSplittingUV} is equivalent to the satisfaction of\n  both of the following conditions:\n  \\begin{itemize}\n    \\item\n    The hierarchical subspaces $\\hs{l'}$ ($l' \\le l$)\n    are subspaces of $\\ns{l}$.\n    \n    \\item\n    The hierarchical functions\n    $\\basis{l',i'}$ ($l' \\le l$, $i' \\in \\hiset{l'}$)\n    are linearly independent.\n  \\end{itemize}\n\\end{lemma}\n\\begin{proof}\n  The first condition is equivalent to $\\sum_{l'=0}^l \\hs{l'} \\subset \\ns{l}$.\n  The second condition is equivalent to\n  $\\dim \\sum_{l'=0}^l \\hs{l'} = \\sum_{l'=0}^l \\dim \\hs{l'}$,\n  i.e., to the directness of the sum.\n  Therefore, the logical conjunction of both is equivalent to\n  $\\bigoplus_{l'=0}^l \\hs{l'} \\subset \\ns{l}$.\n  If the sum is direct,\n  the dimension of the sum is equal to $2 + \\sum_{l'=1}^l 2^{l'-1} = 2^l + 1$\n  (due to $\\dim \\hs{l'} = \\setsize{\\hiset{l'}} = 2^{l'-1}$ for $l' > 0$ and\n  $\\dim \\hs{l'} = 2$ for $l' = 0$),\n  which is also the dimension of $\\ns{l}$.\n  The only subspace of $\\ns{l}$ that has the same\n  dimension as $\\ns{l}$ is $\\ns{l}$ itself,\n  so we infer $\\bigoplus_{l'=0}^l \\hs{l'} = \\ns{l}$.\n\\end{proof}\n\\begin{corollary}[univariate hierarchical splitting for hat functions]\n  \\label{cor:hierSplittingHatUV}\n  The hierarchical splitting \\eqref{eq:hierSplittingUV}\n  holds for the hat function basis.\n\\end{corollary}\n\\begin{proof}\n  The first condition of \\cref{lemma:hierSplittingUV}\n  is satisfied as piecewise linear splines of level~$l'$\n  are also piecewise linear splines of higher levels $l \\ge l'$.\n  We can prove the linear independence for the second condition by induction\n  over $l$:\n  If a linear combination of $\\bspl{l',i'}{1}$\n  ($l' \\le l$, $i' \\in \\hiset{l'}$)\n  vanishes everywhere, then the coefficients of level $l$ must be zero,\n  as otherwise the basis functions $\\bspl{l,i'}{1}$ ($i' \\in \\hiset{l}$) would\n  introduce kinks at $\\gp{l,i'}$, which the zero function does not have.\n  This means that we have a zero linear combination of $\\bspl{l',i'}{1}$ for\n  $l' \\le l - 1$, $i' \\in \\hiset{l'}$,\n  and by the induction hypothesis, the other coefficients also vanish.\n\\end{proof}\n\n\n\n\\subsection{Hierarchical Splitting in the Multivariate Case}\n\\label{sec:222hierMV}\n\nMultivariate hierarchical subspaces are defined analogously\nto the univariate case:\n\\begin{equation}\n  \\hs{\\*l}\n  \\ceq \\spn\\{\\basis{\\*l,\\*i} \\mid \\*i \\in \\hiset{\\*l}\\},\\quad\n  \\hiset{\\*l}\n  \\ceq \\hiset{l_1} \\times \\dotsb \\times \\hiset{l_d},\\quad\n  \\*l \\in \\natz^d.\n\\end{equation}\nThe univariate hierarchical splitting \\eqref{eq:hierSplittingUV}\ncan now be generalized to\n\\begin{equation}\n  \\label{eq:hierSplittingMV}\n  \\ns{\\*l}\n  \\overset{?}{=} \\bigoplus_{\\*l'=\\*0}^\\*l \\hs{\\*l'}.\n\\end{equation}\nAgain, this relation does not hold in general.\nWe use a multivariate counterpart of \\thmref{lemma:hierSplittingUV}\nto prove that \\eqref{eq:hierSplittingMV} holds if\nthe corresponding univariate relation \\eqref{eq:hierSplittingUV}\nholds for all dimensions:\n\n\\begin{lemma}[multivariate hierarchical splitting characterization]\n  \\label{lemma:hierSplittingMV}\n  \\Cref{eq:hierSplittingMV} is equivalent to the satisfaction of\n  both of the following conditions:\n  \\begin{itemize}\n    \\item\n    The hierarchical subspaces $\\hs{\\*l'}$ ($\\*l' \\le \\*l$)\n    are subspaces of $\\ns{\\*l}$.\n    \n    \\item\n    The basis functions\n    $\\basis{\\*l',\\*i'}$ ($\\*l' \\le \\*l$, $\\*i' \\in \\hiset{\\*l'}$)\n    are linearly independent.\n  \\end{itemize}\n\\end{lemma}\n\n\\vspace*{0pt plus 0.3fill}\n\n\\begin{proof}\n  If the sum is direct, then its dimension is given by\n  \\begin{equation}\n    \\hspace*{-5mm}\n    \\dim \\sum_{\\*l'=\\*0}^\\*l \\hs{\\*l'}\n    = \\sum_{l_1'=0}^{l_1} \\dotsb \\sum_{l_d'=0}^{l_d}\n    \\prod_{t=1}^d \\dim \\hs{l_t'}\n    = \\prod_{t=1}^d \\sum_{l_t'=0}^{l_t} \\dim \\hs{l_t'}\n    = \\prod_{t=1}^d (2^{l_t} + 1)\n    = \\dim \\ns{\\*l}\n    \\hspace*{-5mm}\n  \\end{equation}\n  using \\eqref{eq:dimensionFG}.\n  The rest is analogous to the proof of \\cref{lemma:hierSplittingUV}.\n\\end{proof}\n\n\\vspace*{0pt plus 1fill}\n\n\\begin{proposition}[from univariate to multivariate splitting]\n  \\label{prop:splittingUVToMV}\n  If univariate splitting \\eqref{eq:hierSplittingUV}\n  holds for every dimension,\n  then the multivariate splitting \\eqref{eq:hierSplittingMV} holds as well.\n\\end{proposition}\n\n\\vspace*{0pt plus 0.3fill}\n\n\\begin{proof}\n  We check the two conditions of \\cref{lemma:hierSplittingMV}\n  given the two univariate conditions of \\cref{lemma:hierSplittingUV}:\n  \\begin{enumerate}\n    \\item\n    The hierarchical basis functions $\\basis{\\*l',\\*i'}$\n    of $\\hs{\\*l'}$ ($\\*l' \\le \\*l$, $\\*i' \\in \\hiset{\\*l'}$)\n    are tensor products of functions $\\basis{l_t',i_t'}$.\n    According to the first condition of \\cref{lemma:hierSplittingUV},\n    each $\\basis{l_t',i_t'}$ can be written as a linear combination of\n    the nodal basis $\\basis{l_t,i_t}$ ($i_t = 0, \\dotsc, 2^{l_t}$).\n    We can expand the tensor product to a linear combination\n    of tensor products of the univariate nodal basis functions.\n    Therefore, $\\basis{\\*l',\\*i'}$ is a linear combination of\n    multivariate nodal functions, i.e., $\\basis{\\*l',\\*i'} \\in \\ns{\\*l}$.\n    As this is true for all $\\*i' \\in \\hiset{\\*l'}$, we obtain\n    $\\hs{\\*l'} \\subset \\ns{\\*l}$.\n    \n    \\item\n    The linear independence of the hierarchical functions $\\basis{\\*l',\\*i'}$\n    ($\\*l' \\le \\*l$, $\\*i' \\in \\hiset{\\*l'}$) can be shown completely\n    analogously to the proof of\n    \\thmref{lemma:tensorProductLinearIndependence}.\n  \\end{enumerate}\n  According to \\cref{lemma:hierSplittingMV},\n  the multivariate splitting \\eqref{eq:hierSplittingMV} holds.\n\\end{proof}\n\n\\vspace*{0pt plus 1fill}\n\nA direct consequence of \\cref{prop:splittingUVToMV} is that\nthe hierarchical splitting holds for the hierarchical hat function basis.\n\n\\pagebreak\n\n\\begin{corollary}[multivariate hierarchical splitting for hat functions]\n  \\label{cor:hierSplittingHatMV}\n  The multivariate hierarchical splitting \\eqref{eq:hierSplittingMV}\n  holds for the hat function basis.\n\\end{corollary}\n\\begin{proof}\n  Follows directly by applying\n  \\thmref{cor:hierSplittingHatUV} to \\cref{prop:splittingUVToMV}.\n\\end{proof}\n", "meta": {"hexsha": "950d42bd505e9987c6cf2c4f6964afb31c7d6450", "size": 11343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/document/22hierSubspaces.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/22hierSubspaces.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/22hierSubspaces.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": 36.0095238095, "max_line_length": 78, "alphanum_fraction": 0.676805078, "num_tokens": 3788, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869819218865, "lm_q2_score": 0.8791467785920306, "lm_q1q2_score": 0.7699453038894635}}
{"text": "\n\\subsection{Autoregressive models (AR)}\n\n\\subsubsection{AR(\\(1\\))}\n\nOur basic model was:\n\n\\(x_t=\\alpha + \\epsilon_t \\)\n\nWe add an autoregressive component by adding a lagged observation.\n\n\\(x_t=\\alpha + \\beta x_{t-1}+\\epsilon_t\\)\n\n\\subsubsection{AR(\\(p\\))}\n\nAR(\\(p\\)) has \\(p\\) previous dependent variables.\n\n\\(x_t=\\alpha + \\sum_{i=1}^p\\beta_ix_{t-i}\\)\n\n\\subsubsection{Propagation of shocks}\n\nA shock bumps up the output variable, which bumps up output variables forever, at a decreasing rate.\n\n\n\n", "meta": {"hexsha": "11880bdc71533df5c378bc56dd44c1b411312cbd", "size": 498, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticWold/01-01-AR.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/stochasticWold/01-01-AR.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/forecastingUni/02-01-AR.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 19.1538461538, "max_line_length": 100, "alphanum_fraction": 0.7008032129, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248140158416, "lm_q2_score": 0.8198933425148214, "lm_q1q2_score": 0.7699001934678068}}
{"text": "\\chapter{}\n\n\\begin{ex}\n\tLet \\(X_{1}, \\cdots, X_{n}\\) be a random sample from the a.c. distribution\n\t\\[\n\tf(x \\mid \\theta)=\\theta x^{\\theta-1} 1_{\\{0 \\leqslant x \\leqslant 1\\}}, \\quad 0<\\theta<\\infty .\n\t\\]\n\tFind the method of moments estimator of \\(\\theta\\).\n\\end{ex}\n\n\\begin{solution}\n\tFor the sample \\(\\{X_i\\}_{i=1}^n\\),\n\t\\[\n\t\t\\begin{aligned}\n\t\t\t\\bar{X}=\\mu_1=E(X_i)&=\\int_0^1xf(x)\\der x=\\int_0^1\\theta x^\\theta\\der x\\\\\n\t\t\t&=\\frac{\\theta}{\\theta+1}x^{\\theta+1}\\big|_0^1=\\frac{\\theta}{\\theta+1}.\n\t\t\\end{aligned}\n\t\\]\n\tThen, the method of moments estimator for $\\theta$ is\n\t\\[\n\t\t\\hat{\\mu}_1=\\frac{1}{n}\\sum_{i=1}^nX_i=\\frac{\\theta}{\\theta+1}\n\t\\]\n\t\\[\n\t\t\\hat{\\theta}=\\frac{\\hat{\\mu}_1}{1-\\hat{\\mu}_1}.\n\t\\]\n\\end{solution}\n\n\\begin{ex}\n\tLet \\(X_{1}, \\cdots, X_{n} \\stackrel{\\text { i.i.d. }}{\\sim} \\operatorname{Geo}(p), 0<p<1\\), i.e.,\n\t\\[\n\t\\mathbb{P}\\left(X_{1}=k \\mid p\\right)=(1-p)^{k-1} p, \\quad k \\in \\mathbb{N} .\n\t\\]\n\tWhat is the method of moments estimator of \\(p\\) ?\n\\end{ex}\n\n\\begin{solution}\n\tFor the sample \\(\\{X_i\\}_{i=1}^n\\),\n\t\\[\n\t\t\\begin{aligned}\n\t\t\t\\bar{X}=\\mu_1=E(X_i)&=\\sum_{k=1}^\\infty k\\cdot (1-p)^{k-1}p=\\frac{1}{p}\n\t\t\\end{aligned}\n\t\\]\n\tSo, the method of moments estimator of $p$ is\n\t\\[\n\t\t\\hat{\\mu}_1=\\frac{1}{n}\\sum_{i=1}^nX_i=\\frac{1}{p}\n\t\\]\n\t\\[\n\t\t\\hat{p}=\\frac{1}{\\hat{\\mu}_1}.\n\t\\]\n\\end{solution}\n\n\\begin{ex}\n\tAssume \\(X \\sim B(n, p)\\), where both \\(n \\in \\mathbb{N}\\) and \\(p \\in(0,1)\\) are unknown. Given a random sample of \\(N\\) observations of \\(X\\), compute the method of moments estimator of \\(n\\) and \\(p\\).\n\\end{ex}\n\n\\begin{solution}\n\tFor the sample \\(\\{X_i\\}_{i=1}^N\\),\n\t\\[\n\t\t\\bar{X}=\\mu_1=E(X_i)=\\sum_{k=0}^nk\\cdot \\binom{n}{k}p^k(1-p)^{n-k}=np,\n\t\\]\n\t\\[\n\t\tVar(X_i)=E(X_i^2)-(E(X_i))^2=\\mu_2-\\mu^2=np(1-p),\n\t\\]\n\tNow, solve these two equations:\n\t\\[\n\t\t\\left\\{\\begin{array}{l}\n\t\t\t\\hat{\\mu}_1=np\\\\\n\t\t\t\\hat{\\mu}_2-\\hat{\\mu}_1^2=np(1-p)\n\t\t\\end{array}\\right.\n\t\\]\n\tWe can get that\n\t\\[\n\t\t\\hat{p}=1-\\frac{\\hat{\\mu}_2-\\hat{\\mu}_1^2}{\\hat{\\mu}_1},\\qquad\\hat{n}=\\frac{\\hat{\\mu}_1^2}{\\hat{\\mu}_1-\\hat{\\mu}_2+\\hat{\\mu}_1^2}.\n\t\\]\n\\end{solution}\n\n\\begin{ex}\n\tLet \\(X_{1}, \\cdots, X_{n}\\) be a random sample from the density\n\t\\[\n\tf(x \\mid \\theta)=\\theta x^{-2}, \\quad 0<\\theta \\leqslant x<\\infty .\n\t\\]\n\tWhat can you say about the existence of the method of moments estimator of \\(\\theta\\) ?\n\\end{ex}\n\n\\begin{solution}\n\t\\[\n\t\tE(X_i)=\\int_{\\theta}^\\infty x\\cdot \\theta x^{-2}\\der x=\\theta \\ln x \\big|_\\theta^\\infty=\\theta(\\ln\\infty-\\ln\\theta)=\\infty,\n\t\\]\n\tSo, the method of moments estimator for \\(\\theta\\) does not exist.\n\\end{solution}\n\n\\begin{ex}\n\tShow that each of the following is an exponential family and describe the natural parameter space \\(\\mathcal{E}\\) of the associated canonical exponential family.\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\(\\{\\Gamma(\\alpha, \\lambda)\\}_{\\alpha, \\lambda>0}\\), i.e.,\n\t\t\\[\n\t\tf(x \\mid \\alpha, \\lambda)=\\frac{\\lambda^{\\alpha}}{\\Gamma(\\alpha)} x^{\\alpha-1} e^{-\\lambda x} 1_{\\{x>0\\}} ;\n\t\t\\]\n\t\t\\item \\(\\{\\operatorname{Beta}(a, b)\\}_{a, b>0}\\), i.e.,\n\t\t\\[\n\t\tf(x \\mid a, b)=\\frac{\\Gamma(a+b)}{\\Gamma(a) \\Gamma(b)} x^{a-1}(1-x)^{b-1} 1_{\\{0<x<1\\}} ;\n\t\t\\]\n\t\t\\item \\(\\{\\operatorname{Poi}(\\lambda)\\}_{\\lambda>0}\\);\n\t\t\\item \\(\\{\\operatorname{NegBin}(r, p)\\}_{0 \\leqslant p \\leqslant 1}(r\\) being known), i.e.,\n\t\t\\[\n\t\tf(x \\mid p)=\\left(\\begin{array}{c}\n\t\tr+x-1 \\\\\n\t\tx\n\t\t\\end{array}\\right) p^{r}(1-p)^{x}, \\quad x \\in \\mathbb{N} \\cup\\{0\\} .\n\t\t\\]\n\t\\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tf(x|\\alpha, \\lambda)&=1_{\\{x>0\\}}\\exp(\\alpha\\ln(\\lambda)-\\ln(\\Gamma(\\alpha))+(\\alpha-1)\\ln(x)-\\lambda x)\\\\\n\t\t\t\t&=1_{\\{x>0\\}}\\exp((\\alpha-1)\\ln(x)-\\lambda x+\\alpha\\ln(\\lambda)-\\ln(\\Gamma(\\alpha))),\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo, the nature parameter is $(\\eta_1,\\eta_2)=(\\alpha-1, -\\lambda)$. And the parameter space \\(\\mathcal{E}\\) is \\((-1,\\infty)\\times(-\\infty,0)\\).\n\t\t\\item\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tf(x|a,b)=1_{\\{0<x<1\\}}&\\exp((a-1)\\ln(x)+(b-1)\\ln(1-x)\\\\&+\\ln(\\Gamma(a+b))-\\ln(\\Gamma(a))-\\ln(\\Gamma(b))),\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo, the nature parameter is $(\\eta_1,\\eta_2)=(a-1, b-1)$. And the parameter space \\(\\mathcal{E}\\) is \\((-1,\\infty)\\times(-1,\\infty)\\).\n\t\t\\item When \\(k\\in\\mathbb{N}\\),\n\t\t\\[\n\t\t\tf(x)=P(X=k)=\\frac{e^{-\\lambda}\\lambda^k}{k!}\n\t\t\\]\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tP(X=k)=&1/k!\\cdot\\exp(-\\lambda+k\\ln(\\lambda)),\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo, the nature parameter is $(\\eta)=(\\ln(\\lambda))$. And the parameter space \\(\\mathcal{E}\\) is \\((-\\infty,\\infty)\\).\n\t\t\\item When \\(x\\in\\mathbb{N}\\),\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tf(x|p)&=\\binom{r+x-1}{x}\\exp\\left(r\\ln(p)+x\\ln(1-p)\\right),\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo, the nature parameter is $(\\eta)=(\\ln(1-p))$. And the parameter space \\(\\mathcal{E}\\) is \\((-\\infty,0]\\).\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n\tIn \\(n\\) independent trials with \\(k+1\\) possible outcomes, let the probability of the \\(i\\)-th outcome be \\(p_{i}\\) in each trial. If \\(X_{i}\\) denotes the number of trials resulting in outcome \\(i, i=0,1, \\ldots, k\\), then the joint distribution of \\(X\\) is the multinomial distribution, i.e.,\n\t\\[\n\t\tf( x \\mid \\mathbf{p}):=\\mathbb{P}\\left(X_{0}=x_{0}, X_{1}=x_{1}, \\ldots, X_{k}=x_{k} \\mid \\mathbf{p}\\right)=\\frac{n !}{x_{0} ! x_{1} ! \\ldots x_{k} !} p_{0}^{x_{0}} p_{1}^{x_{1}} \\ldots p_{k}^{x_{k}}.\n\t\\]\n\t\\begin{enumerate}[(a)]\n\t\t\\item Verify that \\(\\{f( x \\mid \\mathbf{p})\\}_{\\mathbf{p} \\in \\Pi_{k}}\\) is an exponential family, where \\(\\Pi_{k}\\) is the \\(k\\)-dimensional simplex in \\(\\mathbb{R}^{k+1}\\). Determine \\(\\mathcal{E}\\).\n\t\t\\item Using results for canonical exponential families, show that\n\t\t\\[\n\t\t\t\\mathbb{E} X_{i}=n p_{i}, \\quad \\operatorname{Cov}\\left(X_{j}, X_{i}\\right)=\\left\\{\\begin{array}{cc}\n\t\t\tn p_{j}\\left(1-p_{j}\\right), & k=j \\\\\n\t\t\t-n p_{j} p_{k}, & k \\neq j\n\t\t\\end{array}\\right.\n\t\t\\]\n\t\\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item We know for every $p_i$, \\(0\\leqslant p_i\\leqslant 1\\).\n\t\t\\[\n\t\t\tf(x|\\mathbf{p})=\\frac{n !}{x_{0} ! x_{1} ! \\ldots x_{k} !} \\exp\\left(x_0\\ln (p_0)+\\cdots+x_k\\ln (p_k)\\right).\n\t\t\\]\n\t\tSo, the nature parameter is $(\\eta_0,\\cdots,\\eta_k)=(\\ln(p_0),\\cdots,\\ln(p_k))$. And the parameter space \\(\\mathcal{E}\\) is \\((-\\infty,0]\\times\\cdots\\times(-\\infty,0]\\).\n\t\t\\item Noting this $p_{k}=1-\\sum_{i=0}^{k-1}p_i$, we can parameterize the distribution as:\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tf(x|\\mathbf{p})&=\\frac{n!}{x_0!x_1!\\cdots x_k!}\\exp\\left\\{\\sum_{i=0}^{k-1}\\ln(p_i)x_i+\\left(n-\\sum_{i=0}^{k-1}x_i\\right)\\ln\\left(1-\\sum_{i=0}^{k-1}p_i\\right)\\right\\}\\\\\n\t\t\t\t&=\\frac{n!}{x_0!x_1!\\cdots x_k!}\\exp\\left\\{\\sum_{i=0}^{k-1}\\ln\\left(\\frac{p_i}{1-\\sum_{i=0}^{k-1}p_i}\\right)x_i+n\\ln\\left(1-\\sum_{i=0}^{k-1}p_i\\right)\\right\\}.\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tLet $\\eta_i=\\ln\\left(\\frac{p_i}{1-\\sum_{i=0}^{k-1}p_i}\\right)$, then we know $p_i=\\frac{e^{\\eta_i}}{\\sum_{i=0}^ke^{\\eta_i}}$. So,\n\t\t\\[\n\t\t\t\\begin{aligned}\n\t\t\t\tA(\\eta)=n\\ln\\left(\\sum_{i=0}^ke^{\\eta_i}\\right).\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo,\n\t\t\\[\n\t\t\t\\mathbb{E}X_i=A_{\\eta_i}'(\\eta)=n\\frac{e^{\\eta_i}}{\\sum_{i=0}^ke^{\\eta_i}}=np_i.\n\t\t\\]\n\t\tWhen $i=j$,\n\t\t\\[\n\t\t\t\\text{Cov}(X_j,X_i)=A_{\\eta_i}''(\\eta)=n\\frac{e^{\\eta_i}(\\sum_{i=0}^k)e^{\\eta_i}-e^{\\eta_i}e^{\\eta_i}}{\\sum_{i=0}^ke^{\\eta_i}}=np_i(1-p_i).\n\t\t\\]\n\t\tWhen $i\\not=j$,\n\t\t\\[\n\t\t\t\\text{Cov}(X_j,X_i)=\\frac{A(\\eta)}{\\partial\\eta_i\\,\\partial\\eta_j}=ne^{\\eta_i}\\frac{-e^{\\eta_j}}{(\\sum_{i=0}^ke^{\\eta_i})^2}=-np_ip_j.\n\t\t\\]\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n\tThe Inverse Gaussian density, \\(I G(\\mu, \\lambda)\\), is given by\n\t\\[\n\t\tf(x \\mid \\mu, \\lambda)=\\left(\\frac{\\lambda}{2 \\pi}\\right)^{1 / 2} x^{-3 / 2} \\exp \\left\\{\\frac{-\\lambda(x-\\mu)^{2}}{2 \\mu^{2} x}\\right\\}, \\quad x>0, \\quad \\mu>0, \\quad \\lambda>0.\n\t\\]\n\t\\begin{enumerate}[(a)]\n\t\t\\item Show that this is an exponential family generated by \\(T(X)=-\\frac{1}{2}\\left(X, X^{-1}\\right)^{T}\\) and \\(h(x)=\\) \\((2 \\pi)^{-1 / 2} x^{-3 / 2}\\).\n\t\t\\item Show that the canonical parameters \\(\\eta_{1}, \\eta_{2}\\) are given by \\(\\eta_{1}=\\mu^{-2} \\lambda, \\eta_{2}=\\lambda\\), and that \\(A\\left(\\eta_{1}, \\eta_{2}\\right)=-\\left(\\frac{1}{2} \\log \\left(\\eta_{2}\\right)+\\sqrt{\\eta_{1} \\eta_{2}}\\right), \\mathcal{E}=[0, \\infty) \\times(0, \\infty)\\).\n\t\t\\item Find the moment generating function of \\(T\\) and show that \\(\\mathbb{E}(X)=\\mu, \\operatorname{Var}(X)=\\mu^{3} \\lambda^{-1}\\), \\(\\mathbb{E}\\left(X^{-1}\\right)=\\mu^{-1}+\\lambda^{-1}, \\operatorname{Var}\\left(X^{-1}\\right)=(\\lambda \\mu)^{-1}+2 \\lambda^{-2} .\\)\n\t\\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\[\n\t\t\t\\begin{aligned}\n\t\t\t\tf(x|\\mu,\\lambda)&=(2 \\pi)^{-1 / 2} x^{-3 / 2}\\exp\\left\\{-\\lambda(x^2-2\\mu x+\\mu^2)\\cdot(2\\mu^2x)^{-1}+\\frac{1}{2}\\ln(\\lambda)\\right\\}\\\\\n\t\t\t\t&=(2 \\pi)^{-1 / 2} x^{-3 / 2}\\exp\\left\\{\\frac{-\\lambda}{2\\mu^2}x + \\frac{\\lambda}{\\mu}-\\frac{\\lambda}{2}x^{-1}+\\frac{1}{2}\\ln(\\lambda)\\right\\}\n\t\t\t\\end{aligned}\n\t\t\\]\n\t\tSo, $T(X)=-\\frac{1}{2}(X,X^{-1})$, \\(h(x)=\\) \\((2 \\pi)^{-1 / 2} x^{-3 / 2}\\).\n\t\t\\item $B((\\lambda, \\mu))=-(1/2\\ln(\\lambda)+\\lambda/\\mu)$, and $\\eta=(\\eta_1,\\eta_2)=(\\lambda/\\mu^2, \\lambda)$. So,\n\t\t\\[\n\t\t\tA(\\eta)=-(1/2\\ln(\\eta_2)+(\\eta_1\\eta_2)^{1/2}).\n\t\t\\]\n\t\t\\item The moment-generating function of $T(X)$ is\n\t\t\\[\n\t\t\tM(s)=\\exp\\left(A(s+\\eta)-A(\\eta)\\right).\n\t\t\\]\n\t\tAnd\n\t\t\\[\n\t\t\t\\mathbb{E}(-1/2X)=A_{\\eta_1}'(\\eta)=-(1/2(\\eta_1\\eta_2)^{-1/2}\\eta_2)=-1/2\\mu,\\quad \\mathbb{E}X=\\mu.\n\t\t\\]\n\t\t\\[\n\t\t\t\\text{Var}(-1/2X)=A_{\\eta_1}''(\\eta)=1/4(\\eta_1\\eta_2)^{-3/2}\\eta_2^2=1/4\\mu^3\\lambda^{-1},\\quad \\text{Var}(X)=\\mu^3\\lambda^{-1}.\n\t\t\\]\n\t\t\\[\n\t\t\t\\mathbb{E}(-1/2X^{-1})=A_{\\eta_2}'(\\eta)=-(1/2\\eta_2^{-1}+1/2(\\eta_1\\eta_2)^{-1/2}\\eta_1)=-1/2(\\mu^{-1}+\\lambda^{-1}),\n\t\t\\]\n\t\t\\[\n\t\t\t\\mathbb{E}(X^{-1})=\\mu^{-1}+\\lambda^{-1}.\n\t\t\\]\n\t\t\\[\n\t\t\t\\text{Var}(-1/2X^{-1})=A_{\\eta_2}''(\\eta)=1/2\\eta_2^{-2}+1/4(\\eta_1\\eta_2)^{-3/2}\\eta_1^2=1/2\\lambda^{-2}+1/4(\\lambda^{-1}\\mu^{-1}),\n\t\t\\]\n\t\t\\[\n\t\t\t\\text{Var}(X^{-1})=2\\lambda^{-2}+(\\lambda\\mu)^{-1}.\n\t\t\\]\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n\tFor each of the following families: \\((i)\\) verify that it is an exponential family; \\((i i)\\) describe the curve in which the parameter vector \\(\\theta\\) lies (with respect to the natural parametrization).\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\(\\left\\{\\mathcal{N}\\left(\\theta, a \\theta^{2}\\right)\\right\\}_{\\theta \\in \\mathbb{R}}, a\\) is known;\n\t\t\\item \\(\\{\\Gamma(\\alpha, \\alpha)\\}_{\\alpha>0} ;\\)\n\t\t\\item \\(\\{f(x \\mid \\theta)\\}_{\\theta \\in \\mathbb{R}}\\), where \\(f(x \\mid \\theta)=C \\exp \\left\\{-(x-\\theta)^{4}\\right\\}, x \\in \\mathbb{R}\\), and \\(C\\) is a normalizing constant.\n\t\\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item\n\t\t\\begin{enumerate}[(a)]\n\t\t\t\\item[(i)] The density function of normal distribution can be write as:\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\tf(x|\\theta)&={\\frac {1}{{\\sqrt {2\\pi a}\\theta}}}\\;\\exp\\left(-{\\frac {\\left(x-\\theta \\right)^{2}}{2a\\theta^2}}\\right)\\\\\n\t\t\t\t\t&=e^{-\\frac{1}{2a}}\\exp\\left(-\\frac{1}{2a\\theta^2}x^2+\\frac{1}{a\\theta}x-\\ln(\\sqrt{2\\pi a}\\theta)\\right).\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\t$h(x)=e^{-\\frac{1}{2a}}1_{-\\infty<x<\\infty}$, $\\eta=\\left(-\\frac{1}{2a\\theta^2}, \\frac{1}{a\\theta}\\right)$, $T(X)=(x^2, x)$.\n\t\t\t\\item[(ii)]\n\t\t\tLet $u=-\\frac{1}{2a\\theta^2}$, $v=\\frac{1}{a\\theta}$, then\n\t\t\t\\[\n\t\t\t\tu=-\\frac{a}{2}v^2.\n\t\t\t\\]\n\t\t\tIt is a parabola.\n\t\t\\end{enumerate}\n\t\t\\item\n\t\t\\begin{enumerate}[(a)]\n\t\t\t\\item[(i)]\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\tf(x \\mid \\alpha, \\alpha)&=\\frac{\\alpha^{\\alpha}}{\\Gamma(\\alpha)} x^{\\alpha-1} e^{-\\alpha x} 1_{\\{x>0\\}}\\\\\n\t\t\t\t\t&=\\exp\\left(-\\alpha x+(\\alpha-1)\\ln(x)+\\alpha\\ln(\\alpha)-\\ln(\\Gamma(\\alpha))\\right)1_{\\{x>0\\}}\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\t$h(x)=1_{\\{x>0\\}}$, $T(X)=(x, \\ln(x))$, $\\eta=(-\\alpha,\\alpha-1)$.\n\t\t\t\\item[(ii)]\n\t\t\tLet $u=-\\alpha$, $v=\\alpha-1$, then\n\t\t\t\\[\n\t\t\t\tv=-u-1,\\quad u<0.\n\t\t\t\\]\n\t\t\tIt is a line.\n\t\t\\end{enumerate}\n\t\t\\item\n\t\t\\begin{enumerate}[(a)]\n\t\t\t\\item[(i)]\n\t\t\t\\[\n\t\t\t\t\\begin{aligned}\n\t\t\t\t\tf(x|\\theta)&=C\\exp(-(x-\\theta)^4)\\\\\n\t\t\t\t\t&=C\\exp\\left(-x^4+4\\theta x^3-6\\theta^2x^2+4\\theta^3x-\\theta^4\\right)\n\t\t\t\t\\end{aligned}\n\t\t\t\\]\n\t\t\t$h(x)=C\\exp(-x^4)1_{\\{-\\infty<x<\\infty\\}}$, $T(X)=(4x^3, -6x^2, 4x)$, $\\eta=(\\theta, \\theta^2, \\theta^3)$.\n\t\t\t\\item[(ii)] It is a spiral. In Mathematica, we can get the plot of the curve like this:\n\\begin{minted}[breaklines]{mathematica}\nParametricPlot3D[{t, t^2, t^3}, {t, 0, 1}, {ViewPoint -> {1.3, -2.4, 2.}}]\n\\end{minted}\n\t\t\\includegraphics{1.8.c.eps}\n\t\\end{enumerate}\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n\t(In this problem, we generalize the proposition shown in class)\n\n\tLet \\(\\{f( x \\mid \\theta)\\}_{\\theta \\in \\Theta}\\) be a \\(k\\) parameter exponential family generated by \\((T, h)\\). Show that the distribution for \\(T(\\mathbf{X})\\) is also a \\(k\\)-parameter exponential family. Hint: let \\(G_{*}(d  x)=h( x) G(d  x)\\) and define the induced probability measure\n\t\\[\n\t\t\\mathbb{P}_{T}(B):=\\mathbb{P}(T(\\mathbf{X}) \\in B)=\\int_{\\mathbb{R}^{n}} 1_{B}(T( x)) \\exp \\{\\langle W(\\theta), T( x)\\rangle-B(\\theta)\\} G_{*}(d  x),\n\t\\]\n\tfor \\(B \\in \\mathcal{B}\\left(\\mathbb{R}^{k}\\right)\\). Now recall the following fundamental result on changes of measure, established in the course Probability theory \\(I\\).\n\n\t{\\bfseries Theorem. (Meerschaert and Scheffler (2001), \\(p .4)\\)} If \\(\\mu(d x)\\) is a measure on \\(\\mathcal{B}\\left(\\mathbb{R}^{d}\\right)\\) and if \\(T: \\mathbb{R}^{d} \\rightarrow \\mathbb{R}^{m}, f: \\mathbb{R}^{m} \\rightarrow \\mathbb{R}^{n}\\) are Borel measurable, then\n\t\\[\n\t\t\\int_{\\mathbb{R}^{d}} f(T(\\boldsymbol{x})) \\mu(d \\boldsymbol{x})=\\int_{\\mathbb{R}^{m}} f(\\boldsymbol{y})(T \\mu)(d \\boldsymbol{y}),\n\t\\]\n\twhere we define the measure \\((T \\mu)(B)=\\mu\\left(T^{-1}(B)\\right), B \\in \\mathcal{B}\\left(\\mathbb{R}^{m}\\right)\\).\n\\end{ex}\n\n\\begin{solution}\n\tKnowing that $f(x|\\theta)$ is generated by $(T,h)$, i.e.\n\t\\[\n\t\tf(x|\\theta)=h(x)\\exp\\left(\\eta^T(\\theta)T(x)-B(\\theta)\\right),\n\t\\]\n\tAnd we suppose $T(x)$ is a one-to-one function. Then the p.d.f. for $T(x)$ is\n\t\\[\n\t\t\\begin{aligned}\n\t\t\t\\mathbb{P}_{T}(B)&=\\int_{\\mathbb{R}^{n}} 1_{B}(T( x)) \\exp \\{\\langle W(\\theta), T( x)\\rangle-B(\\theta)\\} G_{*}(\\der  x)\\\\\n\t\t\t&=\\int_{\\mathbb{R}^m}1_{B}(t) \\exp \\{\\langle W(\\theta), t\\rangle-B(\\theta)\\}( TG_{*})(\\der t)\\\\\n\t\t\t&=\\int_{\\mathbb{R}^m}1_{B}(t) \\exp \\{\\langle W(\\theta), t\\rangle-B(\\theta)\\}G_*(\\der T^{-1}(t))\\\\\n\t\t\t&=\\int_{\\mathbb{R}^m}1_{B}(t) \\exp \\{\\langle W(\\theta), t\\rangle-B(\\theta)\\}\\frac{h(T^{-1}(t))}{\\|T'(T^{-1}(t))\\|}G(\\der t),\n\t\t\\end{aligned}\n\t\\]\n\twhere $\\|\\cdot\\|$ denotes the Jacobian matrix. So, the distribution of $T(x)$ is also a $k$-parameter exponential family.\n\\end{solution}\n\n\\begin{ex}\n\tLet \\(\\mathcal{E} \\neq \\emptyset\\) be the natural parameter set of some canonical \\(k\\)-parameter exponential family, \\(k \\in \\mathbb{N}\\). Show that \\(\\operatorname{int}(\\mathcal{E}) \\neq \\emptyset\\) if and only if \\(\\mathcal{E}\\) is not contained in any \\((k-1)\\)-dimensional hyperplane (suggestion: for the converse, set \\(k=3\\) to help visualize the problem and use the fact that \\(\\mathcal{E}\\) is convex).\n\\end{ex}\n\n\\begin{solution}\n\t% For $k=3$, if $\\mathcal{E}$ is contained in a $2$ dimension plane,\n\tFor $k=3$, it is clear, but how to solve $k>3$?\n\\end{solution}\n\n\\begin{ex}\n\tLet \\(\\{f(\\cdot \\mid \\boldsymbol{\\eta})\\}_{\\boldsymbol{\\eta} \\in \\mathcal{E}}\\) be an a.c. canonical \\(k\\)-parameter exponential family. Fix an event \\(A\\).\n\t\\begin{enumerate}[(a)]\n\t\t\\item Prove that if \\(\\mathbb{P}_{\\eta_{0}}(A)=0\\) for some \\(\\eta_{0} \\in \\mathcal{E}\\), then \\(\\mathbb{P}_{\\eta}(A)=0\\) for all \\(\\eta \\in \\mathcal{E}\\).\n\t\t\\item Conclude that if \\(\\mathbb{P}_{\\eta_{0}}(A)<1\\) for some \\(\\eta_{0} \\in \\mathcal{E}\\), then \\(\\mathbb{P}_{\\eta}(A)<1\\) for all \\(\\eta \\in \\mathcal{E}\\).\n\t\\end{enumerate}\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\[\\mathbb{P}_{\\eta_0}(A)=\\int1_{A}(x)h(x)\\exp\\left\\{\\eta_0T(x)-A(\\eta_0)\\right\\}\\mu(\\der x)=0\\]\n\t\tIf $\\mathbf{P}_{\\eta_0}(A)=0$, because $\\exp\\left\\{\\eta_0T(x)-A(\\eta_0)\\right\\}$ is all nonzero. So, $h(x)=0$, that means $\\forall \\eta$, $\\mathbf{P}_{\\eta}(A)=0$.\n\t\t\\item If there is some $\\eta_1$, such that $\\mathbb{P}_{\\eta_1}(A)=1$, then $A=\\mathcal{S}$, which means event $A$ is the whole space. But it is impossible because $\\mathbb{P}_{\\eta_0}(A)<1$.\n\t\\end{enumerate}\n\\end{solution}\n\n\\begin{ex}\n\tDetermine the natural parameter space \\(\\mathcal{E}\\) of the a.c. one-parameter canonical exponential family \\(\\{f(. \\mid \\boldsymbol{\\eta})\\}_{\\boldsymbol{\\eta}}\\) when \\(T(x)=x\\) and\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\(h(x)=e^{-|x|}\\);\n\t\t\\item \\(h(x)=\\frac{e^{-|x|}}{1+x^{2}}\\).\n\t\\end{enumerate}\n\tConclude that the natural parameter space does not have to be an open set.\n\\end{ex}\n\n\\begin{solution}\n\t\\begin{enumerate}[(a)]\n\t\t\\item \\begin{align*}\n\t\t\t&\\int h(x)\\exp(<T(x), \\eta>)G(\\der x)\\\\\n\t\t\t=&{}\\int e^{-|x|}e^{\\eta x}\\der x\\\\\n\t\t\t=&{}\\int_{-\\infty}^0 e^{(\\eta+1) x}\\der x+ \\int_{0}^\\infty e^{(\\eta-1) x}\\der x\\\\\n\t\t\t=&{}\\frac{1}{\\eta+1}e^{(\\eta+1) x}\\big|_{-\\infty}^0+\\frac{1}{\\eta-1}e^{(\\eta-1)x}\\big|_0^{\\infty}\n\t\t\\end{align*}\n\t\t$\\eta+1>0$, $\\eta-1<0\\Rightarrow -1<\\eta<1$. In addition, $\\eta$ can be $1$ and $-1$. So, $-1\\leqslant\\eta\\leqslant1$.\n\t\t\\item \\begin{align*}\n\t\t\t&\\int h(x)\\exp(<T(x), \\eta>)G(\\der x)\\\\\n\t\t\t=&{}\\int \\frac{e^{-|x|}}{1+x^2}e^{\\eta x}\\der x\\\\\n\t\t\t=&{}\\int_{-\\infty}^0 \\frac{e^{(\\eta+1) x}}{1+x^2}\\der x+ \\int_{0}^\\infty \\frac{e^{(\\eta-1) x}}{1+x^2}\\der x,\n\t\t\\end{align*}\n\t\tIf $\\eta+1>0$, $\\eta-1<0$. So, the natural parameter space is also $[-1,1]$.\n\t\\end{enumerate}\n\\end{solution}\n\n\n\\begin{ex}\n\tConsider a classical linear regression, i.e., assume we have a sample \\(Y_{1}, \\ldots, Y_{n}\\) of independent random variables such that, for \\(i=1, \\ldots, n, Y_{i} \\sim \\mathcal{N}\\left(\\mu_{i}, \\sigma^{2}\\right), \\mu_{i}=\\beta_{1}+\\beta_{2} z_{i}, \\sigma^{2}>0, \\beta_{1} \\in \\mathbb{R}\\), \\(\\beta_{2} \\in \\mathbb{R}\\). Show that this forms a canonical exponential family with natural parameter space \\(\\mathcal{E}=\\mathbb{R} \\times \\mathbb{R} \\times(-\\infty, 0)\\) up to a permutation of the latter three components.\n\\end{ex}\n\n\\begin{solution}\n\tKnowing that $\\mu_i=\\beta_1+\\beta_2+z_i$,\n\t\\begin{align*}\n\t\tf(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\t\t&=\\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_2}{\\sigma^2}z_iy_i-\\frac{(\\beta_1+\\beta_2z_i)^2}{\\sigma^2}\\right).\n\t\\end{align*}\n\t$\\eta=(\\frac{\\beta_1}{\\sigma^2}, \\frac{\\beta_2}{\\sigma^2}, -\\frac{1}{2\\sigma^2})$, $\\mathcal{E}=\\mathbb{R}\\times\\mathbb{R}\\times(-\\infty,0)$.\n\\end{solution}", "meta": {"hexsha": "9aebf35fc1dcdc235241d1a1b48c18ede2cdd8a7", "size": 18345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Statistics/Problem Set/set1.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/set1.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/set1.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": 44.2048192771, "max_line_length": 520, "alphanum_fraction": 0.5769964568, "num_tokens": 8039, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037343628702, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7698909070837243}}
{"text": "The challenge in any text-based modeling approach is the representation of data. A computer cannot comprehend words like humans, thus it needs a numeric approach for text analysis. This leads to the idea of using ids to map words~\\parencite{nlpfundamentals}. For example, consider the sentence: “John went to the park.”. We can easily construct a basic dictionary for the words in this sentence and map them to a unique id as such: \n\n$\\{\"john\" : 0, \"went\" : 1, \"to\" : 2, \"the\" : 3, \"park\" : 4\\}$\n\n\\subsubsection{One-Hot Encoding}\nThis process could also occur for categories that need to be numerically represented, such as publications. However, this map tells the model that “park” is more important, or weighted more heavily, than “john”. If the model calculates averages, it will find the average of the words “went” and “the” to equal “to”. These types of relationships are incorrect and would inhibit the model’s effectiveness. To mitigate this problem, researchers developed the concept of one-hot encoding, which binarizes the process of mapping items to their numeric representations~\\parencite{harris_harris_2015}. A matrix is generated with dimensions (length of items in entry X length of total dictionary) for each example. Each row of the matrix has a single one and all other entries are zero to represent the single word. Using the above example, our sentence representation would become:\n\n\\[\\begin{bmatrix}\n1 & 0 & 0 & 0 & 0\\\\\n0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 0 & 1\\\\\n\\end{bmatrix}\\]\n\nAlthough this solves the initial problem, there are some disadvantages to this approach. Firstly, the creation of such sparse matrices for each entry in a large dataset is inefficient for storage purposes. It is also plagued by the “curse of dimensionality” as each category appends an entire dimension to the matrix~\\parencite{bellman_1954}. The addition of items to the dictionary leads to changing the representations for all previous words. \n\nThis approach also lacks interpretability. As the items are fed into the model, the one-hot encoded matrix tells the user nothing about the relationship between words. It also breaks down word order, which is required for models such as \\acrshort{bert}.\n\n\\subsubsection{Embedding Vectors}\nThese problems led to the development of vectorized word representations (embeddings). Word embeddings map each word to a unique n-sized vector of a single dimension. The embeddings are not directly interpretable by humans, as they capture latent qualities of the word, however embeddings offer a significant advantage over alternatives in their ability to offer comprehensible representations. Similar words will be found to be spatially contiguous. The relationship between words can also be calculated directly through cosine similarity~\\parencite{dot_products_2008}. The most famous example of this type of interpretability is the mathematical relationship \\textbf{king - man + woman = queen} which can be observed in \\Cref{fig:king_man_woman_queen_pic}.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=0.8\\textwidth]{fig/king-man-woman-queen.png}\n\\caption{Spatial representation of king - man + woman = queen~\\textcite{king_man_woman_queen}}\n\\label{fig:king_man_woman_queen_pic}\n\\end{figure}\n\nThis allows for each example in the dataset to be represented as a unidimensional list of word ids, which can be mapped to their corresponding vectors when being processed by the model. The data storage advantages are obvious, as each entry becomes easily stored as a single dense list instead of a highly-sparse matrix. Cecause of both the data-related and interpretability advantages offered by embeddings, they were utilized for both of the tested models.", "meta": {"hexsha": "5f565a74bbe5d37ab28ba74812a793c129e385b2", "size": 3738, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "EE/sections/theory/nlp-fundamentals.tex", "max_stars_repo_name": "rohanbansal12/extended_essay", "max_stars_repo_head_hexsha": "03848a1c9f4dafe8db0a9ad263e8776681139659", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "EE/sections/theory/nlp-fundamentals.tex", "max_issues_repo_name": "rohanbansal12/extended_essay", "max_issues_repo_head_hexsha": "03848a1c9f4dafe8db0a9ad263e8776681139659", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "EE/sections/theory/nlp-fundamentals.tex", "max_forks_repo_name": "rohanbansal12/extended_essay", "max_forks_repo_head_hexsha": "03848a1c9f4dafe8db0a9ad263e8776681139659", "max_forks_repo_licenses": ["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.6, "max_line_length": 874, "alphanum_fraction": 0.7883895131, "num_tokens": 869, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7698846663009181}}
{"text": "\\chapter{Introduction to Polynomials}\n\nWatch Khan Academy's \\textbf{Polynomials intro} video at \\url{https://youtu.be/Vm7H0VTlIco}\\index{polynomial}\n\nA \\emph{monomial}\\index{monomial} is the product of a number and a variable raised to a non-negative (but possibly zero) integer power. Here are some monomials:\n\\begin{multicols}{4}\n  \\begin{equation*}\n    3 x^2\n  \\end{equation*}\n\n  \\begin{equation*}\n    -2 x^{15}\n  \\end{equation*}\n\n  \\begin{equation*}\n    \\pi x^2\n  \\end{equation*}\n\n  \\begin{equation*}\n    (3.33)x^{100}\n  \\end{equation*}\n\n  \\begin{equation*}\n    7x\n  \\end{equation*}\n\n  \\begin{equation*}\n    3\n  \\end{equation*}\n\n  \\begin{equation*}\n    -\\frac{2}{3}x^{12}\n  \\end{equation*}\n\n  \\begin{equation*}\n    0\n  \\end{equation*}\n\n  \n\\end{multicols}\n\nThe exponent is called the \\emph{degree} of the monomial\\index{monomial!degree}. Examples: $3x^{17}$\nhas degree 17, $-7x$ has degree 1, and $3.2$ has degree 0 (because you can think of it as $(3.2)x^0$).\\index{degree!polynomial}\n\nThe number in the product is called the \\emph{coefficient}\\index{monomial!coefficient}.  Example: $3x^{17}$ has a coefficient of 3, $-2x$ has a coefficient of -2, and $(3.4)x^{1000}$ has a coefficient of 3.4.\\index{coefficient!polynomial}\n\nA \\emph{polynomial} \\index{polynomial!definition of} is the sum of one or more monomials.  Here are some polynomials:\n\\begin{multicols}{3}\n  \\begin{equation*}\n    4 x^2 + 9x + 3.9\n  \\end{equation*}\n\n  \\begin{equation*}\n    -2 x^{10} + (3.4)x - 45x^{900} - 1\n  \\end{equation*}\n\n  \\begin{equation*}\n    \\pi x^2 + \\pi x + \\pi\n  \\end{equation*}\n\n  \\begin{equation*}\n    3.3\n  \\end{equation*}\n\n  \\begin{equation*}\n   7x + 2\n  \\end{equation*}\n\n  \\begin{equation*}\n    3x^{20}\n  \\end{equation*}\n\\end{multicols}\nWe say that each monomial is a \\emph{term} of the polynomial.\n\n$x^{-5} + 12$ is \\emph{not} a polynomial because the first term has a negative exponent.\n\n$x^{2} - 32x^{\\frac{1}{2}} + x$ is \\emph{not} a polynomial because the second term has a non-integer exponent.\n\n$\\frac{x + 2}{x^2 + x + 5}$ is \\emph{not} a polynomial because it is not just a sum of monomials.\n\n\\begin{Exercise}[title={Identifying Polynomials}, label=findpolynomials]\n    Circle only the polynomials.\n\\begin{multicols}{3}\n  \\begin{equation*}\n    -2 x^3 + \\frac{1}{2}x + 3.9\n  \\end{equation*}\n\n  \\begin{equation*}\n    2 x^{-10} + 4x - 1\n  \\end{equation*}\n  \n  \\begin{equation*}\n    (4.5)x^2 + \\pi x\n  \\end{equation*}\n  \n  \\begin{equation*}\n    x^{\\frac{2}{3}}\n  \\end{equation*}\n  \n  \\begin{equation*}\n   7\n  \\end{equation*}\n\n  \\begin{equation*}\n    3x^{20} + 2x^{19} -5 x^{18}\n  \\end{equation*}\n\\end{multicols}\n\\end{Exercise}\n\n\\begin{Answer}[ref=findpolynomials]\n\\begin{multicols}{3}\n  \\begin{equation*}\n    \\boxed{-2 x^3 + \\frac{1}{2}x + 3.9}\n  \\end{equation*}\n\n  \\begin{equation*}\n    2 x^{-10} + 4x - 1\n  \\end{equation*}\n\n  \\begin{equation*}\n    \\boxed{(4.5)x^2 + \\pi x}\n  \\end{equation*}\n\n  \\begin{equation*}\n    x^{\\frac{2}{3}}\n  \\end{equation*}\n\n  \\begin{equation*}\n   \\boxed{7}\n  \\end{equation*}\n\n  \\begin{equation*}\n    \\boxed{3x^{20} + 2x^{19} -5 x^{18}}\n  \\end{equation*}\n\\end{multicols}\n\n\\end{Answer}\n\nWe typically write a polynomial starting at the term with the highest\ndegree and proceed in decreasing order to the term with the lowest\ndegree:\n\\begin{equation*}\n2 x^9 - 3x^7 + \\frac{3}{4}x^3 + x^2 + \\pi x -9.3\n\\end{equation*}\nThis is known as \\emph{the standard form}.  The first term of the\nstandard form is called \\emph{the leading term}, and we often call the\ncoefficient of the leading term \\emph{the leading coefficient}.  We\nsometimes speak of the degree of the polynomial, which is just the\ndegree of the leading term.\\index{standard form!polynomial}\n\n\\begin{Exercise}[title={Standard of a Polynomial}, label=polynomialstandardform]\n  Write $21x^2 - x^3 + \\pi - 1000x$ in standard form. What is the degree of this polynomial? What is its leading coefficient?\n\\end{Exercise}\n\\begin{Answer}[ref=polynomialstandardform]\n  Standard form would be $-x^3 + 21x^2 - 1000x + \\pi$. The degree is 3. The leading coefficient is $-1$\n\\end{Answer}\n\n\\begin{Exercise}[title={Evaluate a Polynomial}, label=evaluatepolynomial]\n  Let $y = x^3 - 3x^2 + 10x - 12$. What is $y$ when $x$ is $4$?\n\\end{Exercise}\n\\begin{Answer}[ref=evaluatepolynomial]\n  $4^3 - (3)(4^2) + (10)(4) - 12 = 64 - 48 + 40 - 12$. So $y = 44$ \n\\end{Answer}\n\nI would be remiss in my duties if I didn't mention one more thing\nabout polynomials: mathematians have defined a polynomial to be a sum\nof a \\emph{finite} number of monomials.\n\nIt is certainly possible to have a sum of an infinite number of monomials\nlike this:\n\\begin{equation*}\n1 + \\frac{1}{2}x + \\frac{1}{4}x^2 + \\frac{1}{8}x^3 + \\frac{1}{16}x^4 + \\ldots\n\\end{equation*}\nThis is an example of an \\emph{infinite series}; we don't consider\nthem polynomials. Infinite series are interesting and useful, but I \nwill not discuss them much until later in the course.\n", "meta": {"hexsha": "2827a38a939adb8e8fae6f8b6a40b6b05f87ea81", "size": 4897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Polynomials/intro-en_US.tex", "max_stars_repo_name": "rajivjhoomuck/sequence", "max_stars_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-06-13T17:19:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-05T00:43:44.000Z", "max_issues_repo_path": "Modules/Polynomials/intro-en_US.tex", "max_issues_repo_name": "rajivjhoomuck/sequence", "max_issues_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Modules/Polynomials/intro-en_US.tex", "max_forks_repo_name": "rajivjhoomuck/sequence", "max_forks_repo_head_hexsha": "5b39f09b6350922867c3f88beaf3683425715676", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 27.6666666667, "max_line_length": 238, "alphanum_fraction": 0.6651010823, "num_tokens": 1799, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8807970795424088, "lm_q1q2_score": 0.7698846644708536}}
{"text": "\\documentclass[../PHYS306Notes.tex]{subfiles}\n\n\\begin{document}\n\\subsection{Worksheet - Generalized Coupled Oscillators}\n\\begin{p}\nShow that for any system undergoing small oscillations, the kinetic and potential energies can be written as quadratic forms of the generalized velocities and coordinates, respectively.\n\\end{p}\n\\begin{s}\nOur vector of $n$ generalized coordinates is given by:\n\\[\\v{q} = (q_1, \\cdots, q_n)\\]\nWhich may be related to the Cartesian coordinates $\\v{r}_i = \\v{r}_i(q_1, \\cdots, q_n)$. Previously, we solved for the kinetic energy:\n\\[T(\\v{q}, \\dot{\\v{q}}) = \\frac{1}{2}\\sum_{j,k}A_{jk}(q) \\dot{q}_j\\dot{q}_k\\]\nWhich is a quadratic form. When we actually evaluate this, we only keep the constant terms from $A_{jk}$ so we get the familiar kinetic energy:\n\\[T(\\dot{\\v{q}}) = \\frac{1}{2}\\sum_{j,k}M_{jk}\\dot{q}_j\\dot{q}_k = \\frac{1}{2}\\dot{\\v{q}}^T\\MM\\dot{\\v{q}}\\]\nWhere things have been written as a matrix product in the last line (replacing the double sum). The potential energy we can do a similar way. In general, the potential energy depends on all of the positions of the particles. We can taylor expand this around an equilibrium value, where $\\v{q} = \\v{0}$:\n\\[U(\\v{q}) = U(\\v{0}) + \\sum_j \\dpd{U}{q_j}q_j + \\frac{1}{2}\\sum_{j,k}\\frac{\\partial^2 U}{\\partial q_j\\partial q_k}q_jq_k + \\cdots\\]\nBy the fact that we take $\\v{0}$ as a minimum, the second term vanishes. We can also neglect the constant term, so:\n\\[U(\\v{q}) = \\frac{1}{2}\\sum_{j, k}K_{jk}q_jq_j = \\frac{1}{2}\\v{q}^T\\KK\\v{q}\\]\nHence, we have obtained quadratic forms for both the kinetic and potential energies! This is just a general description that we could do for any system.\n\\end{s}\n\n\\begin{p}\nProve that the equations of motion for the eigenfrequencies and eigenvectors are $\\det{\\KK - \\omega^2\\MM} = 0$ and $(\\KK - \\omega^2\\MM)\\v{a} = 0$.\n\\end{p}\n\\begin{s}\nGiven our system, we have $m$ Lagrange equations in general. These are given by:\n\\[\\sum_{j=1}^mM_{ij}\\ddot{q}_j = \\dpd{U}{q_i} = -\\sum_{j=1}^m K_{ij}q_j\\]\nWhich we may rewrite as:\n\\[\\MM\\ddot{\\v{q}} = -\\KK\\v{q}\\]\nAs done previously, let $\\v{q}(t) = \\Re\\v{z}(t)$, where $\\v{z}(t) = \\v{a}\\exp(i\\omega t)$. Plugging this in and cancelling out the time derivatives, we obtain an algebraic set of equations:\n\\[(\\KK - \\omega^2\\MM)\\v{a} = \\v{0}\\]\nWhich we can get the eigenvalues from:\n\\[\\det(\\KK - \\omega^2\\MM) = 0\\]\nWe know that these matrices are positive semidefinite, so the eigenvalues will be positive (or perhaps zero).\n\\end{s}\n\n\\begin{p}\nShow generally that each normal coordinate $\\xi_i$ oscillates at its own normal frequency $\\omega_i$, uncoupled to the other normal coordinates. \n\\end{p}\n\\begin{s}\nNormal modes are given by:\n\\[\\v{q}_i(t) = \\v{a}_i\\cos(\\omega_i t - \\delta_i)\\]\nI.e. each have an oscillatory solution with characterstic frequency $\\omega_i$. It also satisfies the eigenvalue problem from above:\n\\[\\KK\\v{a}_i = \\omega^2_i\\MM\\v{a}_i\\]\nThe normal mode expansion is then given by:\n\\[\\v{q}(t) = \\sum_{i=1}^m \\xi_i(t)\\v{a}_i\\]\nWhere $\\xi_i(t)$ are the weights of the modes in the general solution representation. We note that $\\v{a}_i$ forms a basis in which we can expand the solution, which is nice because in this basis we can solve the equations of motion for the normal coordinates trivially. We have that $\\v{q}(t)$ satisfies:\n\\[\\MM\\ddot{\\v{q}} = -\\KK\\v{q}\\]\nLet us plug in this normal mode expansion into the equation of motion. This yields:\n\\[\\sum_{i=1}^m\\ddot{\\xi}_i(t)\\MM\\v{a}_i = -\\sum_{i=1}^m\\xi_i(t)\\KK\\v{a}_i\\]\nBut $\\KK\\v{a}_i = \\omega_i^2\\MM\\v{a}_i$ (eigenvalue) so:\n\\[\\sum_{i=1}^m\\ddot{\\xi}_i(t)\\MM\\v{a}_i = -\\sum_{i=1}^m\\xi_i(t)(-\\omega_i^2)\\MM\\v{a}_i\\]\nThis must hold for the components individually, i.e. this must hold for each value of $i$. We therefore obtain the identity:\n\\[\\ddot{\\xi}_i(t) = -\\omega_i^2\\xi_i(t)\\]\nFrom which we recover the fact that the normal coordinates satisfy equations for simple harmonic motion.\n\\end{s}\n\n\\begin{p}\nCheck for the 2-mass-3-springs problem that the normal coordinates are the coefficients of the eigenvector expansion for the displacements $\\binom{x_1}{x_2}$.\n\\end{p}\n\\begin{s}\nThe eigenvectors on Monday were given by:\n\\[\\v{a}_1 = \\m{1 \\\\ 1}, \\quad \\v{a}_2 = \\m{1 \\\\ -1}\\]\nThe normal mode expansion is then:\n\\[\\v{q} = \\xi_1\\v{a}_1 + \\xi_2\\v{a}_2\\]\nSo therefore:\n\\[\\v{q} = \\m{\\xi_1 + \\xi_2 \\\\ \\xi_1 - \\xi_2} = \\m{q_1 \\\\ q_2}\\]\nFrom which we obtain the normal coordinates:\n\\[\\xi_1 = \\frac{q_1 + q_2}{2}, \\quad \\xi_2 = \\frac{q_1 - q_2}{2}\\]\n\\end{s}\n\n\\begin{p}\nUsing the expansion of $(x_1, x_2)$ in terms of eigenvectors,find the normal coordinates for the double pendulum.\n\\end{p}\n\\begin{s}\nFor the double pendulum, we had the general solution:\n\\[\\phi_1(t) = A_1\\exp(i\\omega_1 t) + A_2\\exp(i\\omega_2 t), \\quad \\phi_2(t) = A_1\\sqrt{2}\\exp(i\\omega_1 t) - A_2\\sqrt{2}\\exp(i\\omega_2 t)\\]\nThis corresponds to eigenvectors:\n\\[\\v{a}_1 = \\m{1 \\\\ \\sqrt{2}}, \\v{a}_2 \\m{1 \\\\ -\\sqrt{2}}\\]\nThe normal mode expansion is given by:\n\\[\\bm{\\phi} = \\xi_1\\v{a}_1 + \\xi_2\\v{a}_2 = \\m{\\xi_1 + \\xi_2 \\\\ \\sqrt{2}\\xi_1 - \\sqrt{2}\\xi_2} = \\m{\\phi_1 \\\\ \\phi_2}\\]\nSolving for $\\xi_1, \\xi_2$ we then solve the system:\n\\[\\xi_1 + \\xi_2 = \\phi_1, \\quad \\xi_1 - \\xi_2 = \\frac{\\phi}{\\sqrt{2}}\\]\nAdding and subtracting these equations, we get:\n\\[\\xi_1 = \\frac{\\left(\\phi_1 + \\frac{\\phi_2}{\\sqrt{2}}\\right)}{2}\\]\n\\[\\xi_2 = \\frac{\\left(\\phi_1 - \\frac{\\phi_2}{\\sqrt{2}}\\right)}{2}\\]\n\n\\end{s}\n\\end{document}", "meta": {"hexsha": "ad7789dc6c014cf3853ccbe14983eaf0972fd002", "size": 5397, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Lecture-12/Worksheet-12.tex", "max_stars_repo_name": "RioWeil/PHYS306-notes", "max_stars_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Lecture-12/Worksheet-12.tex", "max_issues_repo_name": "RioWeil/PHYS306-notes", "max_issues_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Lecture-12/Worksheet-12.tex", "max_forks_repo_name": "RioWeil/PHYS306-notes", "max_forks_repo_head_hexsha": "9394a8cd986722b6fdcb57c8846c6b0d52c23188", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.6404494382, "max_line_length": 305, "alphanum_fraction": 0.6775986659, "num_tokens": 1966, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343393, "lm_q2_score": 0.8824278571786139, "lm_q1q2_score": 0.7697836333382481}}
{"text": "\\subsection{Integers}\n\n\\subsubsection{Defining integers}\n\nTo extend the number line to negative numbers, we define:\n\n\\(\\forall ab \\in \\mathbb{N} \\exists c (a+c=b)\\)\n\nFor any pair of numbers there exists a terms which can be added to one to get the other.\n\nFor \\(1+x=3\\) this is another natural number, however for \\(3+x=1\\) there is no such number.\n\nIntegers are defined as the solutions for any pair of natural numbers.\n\nThere are an infinite number of ways to write any integer. \\(-1\\) can be written as \\(0-1\\), \\(1-2\\) etc.\n\nThe class of these terms form an equivalence class.\n\n\\subsubsection{Integers as ordered pairs}\n\nIntegers can be defined as an ordered pair of natural numbers, where the integer is valued at: \\(a-b\\).\n\nFor example \\(-1\\) could be shown as:\n\n\\(-1= \\{ \\{ 0 \\},\\{0,1\\}\\}\\)\n\n\\(-1= \\{ \\{ 5 \\},\\{5,6\\}\\}\\)\n\n\\((a,b)=a-b\\)\n\n\\subsubsection{Converting natural numbers to integers}\n\nNatural numbers can be shown as integers by using:\n\n\\((n,0)\\)\n\nNatural numbers can be converted to integers:\n\n\\(\\{\\{a\\},\\{a,0\\}\\}\\)\n\\subsubsection{Cardinality of integers}\n\n", "meta": {"hexsha": "d03b37bd1ef35660393ad0426b30d774702c2b8e", "size": 1073, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/integers/01-01-integers.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/integers/01-01-integers.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/integers/01-01-integers.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.5476190476, "max_line_length": 105, "alphanum_fraction": 0.6868592731, "num_tokens": 309, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9525741241296943, "lm_q2_score": 0.8080672112416737, "lm_q1q2_score": 0.769743915986462}}
{"text": "\\section{Rings}\r\n\\begin{definition}\r\n    A ring is a triple $(R,+,\\cdot)$ consisting of a set $R$ and two binary operations $+,\\cdot:R\\times R\\to R$, called addition and multiplication, such that\\\\\r\n    1. $(R,+)$ is an abelian group.\r\n    Its identity is called $0=0_R$.\\\\\r\n    2. $\\cdot$ is associative and has an identity called $1=1_R$.\\\\\r\n    3. $\\forall x,y,z\\in R,x\\cdot(y+z)=x\\cdot y+x\\cdot z,(x+y)\\cdot z=x\\cdot z+y\\cdot z$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. Again closure is not explicitly listed as an axiom, but it is included in the well-definedness of $+,\\cdot$, so to verify something is a ring, we still have to check the closure.\\\\\r\n    2. For $x\\in R$, we write $-x$ for its additive inverse and abbreviate $x+(-y)=x-y$.\\\\\r\n    3. $0=0\\cdot x-0\\cdot x=(0+0)\\cdot x-0\\cdot x=0\\cdot x+0\\cdot x-0\\cdot x=0\\cdot x$.\r\n    Similarly $x\\cdot 0=0$.\\\\\r\n    4. $-x=0-x=0\\cdot x-x=(1+(-1))\\cdot x-x=x+(-1)\\cdot x-x=(-1)\\cdot x$.\\\\\r\n    5. Using 4 and other axioms, we can deduce back the property that addition is commutative.\r\n\\end{remark}\r\n\\begin{definition}\r\n    If $\\cdot$ is commutative as well, we say $R$ is a commutative ring.\r\n\\end{definition}\r\nIn this course, we are only interested in commutative rings.\r\nWhen we say ``ring'' afterwards, we will always imply commutativity.\r\n\\begin{definition}\r\n    Given a ring $R$, a subring $S$ is a subset of $R$ such that $S$ is a ring under the same addition and multiplication restricted to $S\\times S$ and the same identity elements.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $\\mathbb Z$ is a ring under the familiar operations.\\\\\r\n    2. The Gaussian integers $\\mathbb Z[i]=\\{a+ib:a,b\\in\\mathbb Z\\}$ is a ring and is a subring of $\\mathbb C$.\\\\\r\n    3. The set $\\mathbb Q[\\sqrt{2}]=\\{p+q\\sqrt 2:p,q\\in\\mathbb Q\\}$.\\\\\r\n    4. $\\mathbb Z[1/p]=\\{m/p^n:m\\in\\mathbb Z,n\\in\\mathbb N\\}$ where $p$ is a prime gives a ring that is a subring of $\\mathbb Q$.\\\\\r\n    5. $\\mathbb Z/n\\mathbb Z$ is a ring for any natural number $n$.\r\n\\end{example}\r\nWe can also construct new rings from old.\r\n\\begin{definition}\r\n    Given rings $R,S$, the product ring is the Cartesian product $R\\times S$ with operations\r\n    $$(r_1,s_1)+(r_2,s_2)=(r_1+r_2,s_1+s_2),(r_1,s_1)\\cdot(r_2,s_2)=(r_1\\cdot r_2,s_1\\cdot s_2)$$\r\n    So $0_{R\\times S}=(0_R,0_S)$ and $1_{R\\times S}=(1_R,1_S)$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $R$ be a ring and $X$ a set, then the set of functions $X\\to R$ is a ring under pointwise operations.\r\n    So $(f+g)(x)=f(x)+g(x),(f\\cdot g)(x)=f(x)\\cdot g(x)$.\r\n\\end{definition}\r\nFurther interesting examples appear as subrings of it.\r\nFor example, the set of all continuous functions $\\mathbb R\\to\\mathbb R$ is a ring.\r\n\\begin{definition}\r\n    Let $R$ be a ring and $S$ the set of all sequences of elements $r_0,r_1,r_2,\\ldots$ of $R$ that is eventually zero.\r\n    Consider the operations\r\n    $$(a_0,a_1,\\ldots)+(b_0,b_1,\\ldots)=(a_0+b_0,a_1+b_1,\\ldots)$$\r\n    and\r\n    $$(a_0,a_1,\\ldots)\\cdot (b_0,b_1,\\ldots)=(c_1,c_2,\\ldots),c_n=\\sum_{i=0}^na_ib_{n-i}$$\r\n\\end{definition}\r\nOne can verify that this is indeed a ring.\r\nWe can identify $R$ as a subring of $S$ by $r\\mapsto (r,0,0,\\ldots)$.\r\nDefine $X=(0,1,0,0,\\ldots)$, so $X^n=(0,\\ldots,0,1,0,0,\\ldots)$ where the $1$ occurs as the $n^{th}$ entry (counting from $0$).\r\nSo $S$ is generated by $X$ and $R$, hence every element of $S$ can be identifies as a sum\r\n$$\\sum_{i=0}^na_iX^i,a_i\\in\\mathbb R$$\r\nSo this ring $S=R[X]$ is called the polynomial ring over $R$.\r\nWe define the degree of a polynomial to be the largest $i$ such that the coefficient $a_i$ is nonzero.\\\\\r\nWe can obviously identify each polynomial $a_0+a_1X+\\cdots +a_nX^n$ as a function $x\\mapsto a_0+a_1x+\\cdots +a_nx^n$, however\r\n\\begin{remark}\r\n    Let $R=\\mathbb Z/p\\mathbb Z$ where $p$ is a prime, and $f(X)=X^p-X$, so we can identify a function $R\\to R$ by $x\\mapsto x^p-x=0$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    For a ring $R$, we can define multivariate polynomial ring $R[X_1,\\ldots,X_n]=R[X_1,\\ldots,X_{n-1}][X_n]$ inductively.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Given a ring, we can define the power series ring $R[[X]]$ that is all power series in $X$, which are formal sequence of coefficient following the same operation as polynomial rings.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The Laurent polynomials $R[X,X^{-1}]$ is defined as functions from $\\mathbb Z\\to R$ taking finitely many nonzero values following yet again the same operation.\r\n    We write the elements in the form $\\cdots +a_{-2}X^{-2}+a_{-1}X^{-1}+a_0+a_1X+a_2X^2+\\cdots$ where only finitely many $a_i$ is nonzero.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Given a ring $R$, an element $r\\in R$ is called a unit if it has a multiplicative inverse.\r\n    We write $r^{-1}$ for that inverse.\r\n\\end{definition}\r\nA warning is that whether or not an element is a unit depends on the ring, for example $2$ is a unit in $\\mathbb Q$ but not in $\\mathbb Z$.\\\\\r\nThe set of all inverse in a ring forms a group $R^\\times$ under multiplication.\r\nSo $\\mathbb Z^\\times=\\{\\pm 1\\}$ and $\\mathbb Q^\\times=\\mathbb Q\\setminus\\{0\\}$.\r\nSometimes we write $R^\\times$ as $R^\\star$.\r\n\\begin{definition}\r\n    A field is a ring with $0\\neq 1$ and that every nonzero element is a unit.\r\n\\end{definition}\r\n\\begin{example}\r\n    $\\mathbb Q,\\mathbb R,\\mathbb C,\\mathbb Z/p\\mathbb Z$ ($p$ prime) are fields.\r\n\\end{example}\r\nThere is obviously a reason why we need $0\\neq 1$.\r\n\\begin{remark}\r\n    If $R$ is a ring such that $0=1$, then $\\forall x\\in R,x=1\\cdot x=0\\cdot x=0$, so every element of this ring is zero.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $f,g\\in R[X]$ be polynomials, and suppose that $g$ is nonconstant and that the leading coefficient of $g$ is a unit, then there exists a quotient with remainder.\r\n    That is, $\\exists q,r\\in R[X]$ such that $f=qg+r$ with $\\deg r<\\deg g$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Simple induction.\r\n\\end{proof}", "meta": {"hexsha": "5e1d0a007f9414c6f61fa8af76708bab76912706", "size": 5905, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/rings.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": "7/rings.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": "7/rings.tex", "max_forks_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_forks_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 61.5104166667, "max_line_length": 188, "alphanum_fraction": 0.666553768, "num_tokens": 2029, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443252, "lm_q2_score": 0.9099069987088003, "lm_q1q2_score": 0.7697289583479409}}
{"text": "\\chapter{Union-Find}\n\nConsider the following problem. Given $n$ disjoint sets of 1 element each,\nperform $n$ unions and then $m$ queries for what set a given element is in.\nWe will call these two operations $union(A,B)$ and $find(x)$. \n\n\\section{Approach 1: Linked Lists}\nOur first\napproach to this problem is to describe our sets as linked lists. We know\nwe can combine linked lists quite quickly, so this seems ideal for $union$. \nAll we must do is have the head of $B$ point to the tail of $A$, which can be\ndone in constant time.\nHowever, linked lists are not particularly well suited for $find$. To resolve\nthis, at every node we shall store a $back pointer$ to the linked list \nthe node is part of. This allows us to perform $find$ in constant time. \nHowever, now $union$ needs some extra work.\nWhen we call $union(A,B)$, we will now walk through $B$ and fix all of its\nback pointers to point to $A$. This will take time linear in the size of $B$.\n\nGiven $n$ sets, what is the worst possible way to $union$ them? Well, since\nthe run time $union$ is linear in the size of the second list, adversarial\nwe can\ndo is to $union$ every individual element with the current unioned set. For\ninstance, $union(D,union(C,union(A,B)))...$. Clearly this will require\n$O(\\summ{i=1}{n-1}i)$, which is $O(n^2)$. If we then perform $m$ $find$s, all\nof which take $O(1)$ time, we will have performed $n$ $union$s and $m$ $find$s\nin $O(n^2 + m)$ time.\n\n\\section{Approach 2: Better Linked Lists}\nSomehow our first approach was na\\\"ive, which allowed us to ``game\" the system\nto create a very bad result for the $union$s. To get a better result, we will\nmake a slight modification to our $union$ algorithm. Instead of blindly\nattaching $B$ to the end of $A$, we will attach the smaller set to the larger.\nThis fixes our adversarial approach, but is it actually better? \n\nConsider how frequently we need to change the back pointers on an individual\nnode. At first, it is part of a set of size one, and will have to change its\npointer when unioned to a set of size $\\geq 1$, placing it in a set\nof size $\\geq 2$. The next time it will be changed is when it is unioned\nto a set of size $\\geq 2$, then $\\geq 4$ and so on. The last time will be\nwhen it is unioned to a set of size $\\geq n/2$ after which we can not find\nanother set of large enough size to change it again. Therefore each\nback pointer needs to be changed $O(\\log n)$ times at worst. Since there\nare $n$ back pointers, this new approach only require $O(n \\log n)$\ntime to perform the unions. Since the $find$ operation is not effected,\nour approach now performs $n$ $union$s and $m$ $find$s\nin $O(n \\log n + m)$ time.\n\n\\section{Approach 3: Trees}\nHaving to fix back pointers is still fairly wasteful, what if we didn't have\nto? Instead of implementing our sets as linked lists, we can instead\nuse trees. Each set will be a node with either the name of the set, or a\npointer to its parent. When we perform $union(A,B)$, we will simply\nreplace the name of the shorter set with a pointer to the head of the taller\nset. Since we are just changing a pointer, this will only take $O(1)$ time.\nOur $find$ algorithm, however, will now have to walk from the node all the way\nto the root of the tree it is in to find out what list it is in. By a\nsimilar argument from the previous section, the height of our tree will only\never be $\\log n$. \nTherefore this approach can support $n$ $union$s and $m$ $find$s\nin $O(n + m \\log n)$ time.\n\n\\section{Approach 4: Path Compression}\nOur $union$ algorithm is optimal using the tree approach, but it has\nmade our $find$ algorithm suffer. To fix this, we make a simple observation.\nSince our find algorithm must already walk through several nodes in the tree,\nonce we get to the root we can, without worsening the time,\nrelabel all of their pointers to point directly to the root. This approach\nis called $path compression$. This will make\nsubsequent queries on these elements and their children substantially faster.\nThe analysis of this algorithm is beyond the scope of this class, but\nevidently it  can support $n$ $union$s and $m$ $find$s\nin $O(n + m \\alpha(n))$ time. Where $\\alpha$ is the inverse Ackermann function. \nAlthough $\\alpha(n)$ tends towards infinity as $n$ does, for any ``practical\"\n$n$ it is at most $4$. It turns out that this is in fact optimal for the\nunion-find problem.\n", "meta": {"hexsha": "6809c0f7b579619a4178c993e74d2915eb2f9c67", "size": 4368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "union_find.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": "union_find.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": "union_find.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": 56.7272727273, "max_line_length": 80, "alphanum_fraction": 0.7408424908, "num_tokens": 1169, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7697289527783161}}
{"text": "\\lab{Applications}{Markov Chains and Graph Theory}{Markov Chains and Graph Theory}\n\\label{Ch:Markov}\n\n\\objective{This section teaches about two simple applications of Linear Algebra. First it teaches about Markov Chains, which in this context represent discrete random transitions. Second it teaches about Graph Theory, which can be used to represent many physical problems.}\n\n\\section*{Markov Chains}\n\n%Lab \\ref{Markov}\n\nA Markov Chain describe a particular type of random variable. This type of random variable is characterized by the fact that all relevant information is related to its current state. We can easily model this type of random variable using matrices. We will start with a canonical example of a frog jumping from one lilypad to another.\n\nFredo the Frog hops around between the three lily pads $A$, $B$, and $C$.  If he's on lily pad $A$ and jumps, there is a 25\\% chance that he will land back on lily pad $A$, a 25\\% chance that he will land on lily pad $B$, and a 50\\% chance that he will land on lily pad $C$.  In Figure `2.1, we have a transition diagram that reflects the various probabilities from which Fredo will go from one lily pad to another.\n\n\\begin{figure}[h!]\n\\label{markov1_fig1}\n\\begin{center}\n\\includegraphics[scale = 1]{markov1}\n\\end{center}\n\\caption{Transition diagram for Fredo the Frog}\n\\end{figure}\n\nWe can convert our transition diagram into a transition matrix, where the $(i,j)$-entry of the matrix corresponds to the probability that Fredo jumps from the $j^{th}$ lily pad to the $i^{th}$ lily pad (where of course $A$ is the first lily pad, $B$ is the second, and so on).  In Fredo's case, the transition matrix is\n\\[\nA = \\begin{pmatrix}\n1/4 & 1/2 & 1/2\\\\\n1/4 & 1/6 & 1/2\\\\\n1/2 & 1/3 & 0\n\\end{pmatrix}\n\\]\nNote that all of the columns add up to one.  This is important.\n\nIf Fredo is on lily pad $A$, where will he be after two jumps?  By multiplying the matrix $A$ by itself, we have (approximately)\n\n\\[\nA^2 = \\begin{pmatrix}\n0.4375 & 0.3750 & 0.3750\\\\\n0.3542 & 0.3194 & 0.2083\\\\\n0.2083 & 0.3056 & 0.4167\n\\end{pmatrix}\n\\]\nFrom this, we infer that there is a 43.75\\% chance he will still be on lily pad $A$ after two jumps.  Note that he might have jumped from $A$ to $A$ to $A$, denoted $A \\rightarrow A \\rightarrow A$, or he could have jumped to one of the other lily pads and then back again, that is, either $A \\rightarrow B \\rightarrow A$ or $A \\rightarrow C \\rightarrow A$.  In addition, there is a 35.42\\% chance he will be on lily pad $B$ and a 20.83\\% chance that he will be on lily pad $C$.  Using Python, we can type in our transition matrix and see where Fredo will be after 5, 10, 20 or 100 jumps.\n\n\\begin{lstlisting}[style=python]\n#Remember, the 1.'s in the numerator force floating point division\n: A = sp.array([[1./4,1./2,1./2],[1./4,1./6,1./2],[1./2,1./3,0]])\n: np.linalg.matrix_power(A,5)\n: np.linalg.matrix_power(A,10)\n: np.linalg.matrix_power(A,20)\n: np.linalg.matrix_power(A,100)\n\\end{lstlisting}\n\nNote that in the limit that the number of jumps goes to infinity, we get\n\\[\nA^\\infty = \\begin{pmatrix}\n0.4 & 0.4 & 0.4\\\\\n0.3 & 0.3 & 0.3\\\\\n0.3 & 0.3 & 0.3\n\\end{pmatrix}\n\\]\nThis means that after several jumps, the probability that we will find Fredo on a given lily pad will have nothing to do with where he started initially.\n \n\\section*{Markov Chains}\n\nWe can generalize this notion beyond that of frogs and lily pads.  Let the state of our system be represented by a probability vector\n\\[\n\\x = \\begin{bmatrix}\nx_1\\\\\nx_2\\\\\n\\vdots\\\\\nx_n\n\\end{bmatrix}\n\\]\nwhere each entry represents the probability of being in that state.  Note that each entry is nonnegative and the sum of all the entries adds up to one.  For example, in the case of Fredo, if we know initially that he is on lily pad $A$, then we have the state vector\n\\[\n\\x_0 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}\n\\]\nbecause we know for certainty (100\\%) that Fredo is in the first state.  After one jump, we have\n\\[\n\\x_1 = A \\x_0 = \\begin{bmatrix}\n0.25\\\\\n0.25\\\\\n0.50\n\\end{bmatrix}\n\\]\nAfter two jumps, we have\n\\[\n\\x_2 = A \\x_1 = A^2 \\x_0 = \\begin{bmatrix}\n0.4375\\\\\n0.3542\\\\\n0.2083\n\\end{bmatrix}\n\\]\nAfter a large number of jumps $(n>>1)$, we have\n\\[\n\\x_n = A \\x_{n-1} = \\dots = A^n \\x_0 \\approx \\begin{bmatrix}\n0.4\\\\\n0.3\\\\\n0.3\n\\end{bmatrix}\n\\]\nSince all of the columns are the same for $A^\\infty$, then for any initial probability vector $\\x_0$, we get the same limiting output, or in other words, all initial vectors converge to the same point, call it $\\x_\\infty$.  Moreover, we have that\n\\[\n\\x_\\infty = A \\x_\\infty\n\\]\nThis is called a stable fixed point.  How can we check that a stable fixed point exists?  Hint: Think eigenvalues and eigenvectors.\n\n\\section*{Example}\n\nConsider the Markov chain given by\n\\[\nA = \\begin{pmatrix}\n0.5 & 0.3 & 0.4\\\\\n0.2 & 0.2 & 0.3\\\\\n0.3 & 0.5 & 0.3\n\\end{pmatrix}.\n\\]\nWe show that it has a stable fixed point by checking that it has a single eigenvalue $\\lambda=1$.  We do this via Python:\n\\begin{lstlisting}[style=python]\n: A = sp.array([[.5,.3,.4],[.2,.2,.3],[.3,.5,.3]])\n: V = la.eig(A)[1]\n\\end{lstlisting}\nNote that the entries in the $\\lambda=1$ eigenvector do not generally add up to one.  Indeed, any multiple of an eigenvector is an eigenvector.  So we need to multiply it by the appropriate constant so that all of the entries add up to one.\n\\begin{lstlisting}[style=python]\n: x = V[:,0]\n: x = x/sp.sum(x);x\narray([ 0.41836735,  0.23469388,  0.34693878])\n\\end{lstlisting}\nWe can check this answer by taking $A$ to a high exponent, say $A^{100}$.\n\n\\begin{problem}\nSuppose a basketball player's success at shooting free throws can be\ndescribed with the following Markov chain\n\\[\nA = \\begin{pmatrix}.75&.50\\\\.25&.50\\end{pmatrix}\n\\]\nwhere the first state corresponds to success and the second state to failure.\n\\begin{enumerate}\n\\item If the player makes his first free throw, what is the probability that he also makes his third one?\n\\item What is the player's average free throw percentage?\n\\end{enumerate}\n\\end{problem}\n\n\\begin{problem}\nConsider the Markov process given by the transition diagram in Figure 2 below:\n\\begin{enumerate}\n\\item Find the transition matrix.\n\\item If the Markov process is in state $A$, initially, find the probability that it is in state $B$ after 2 periods.\n\\item Find the stable fixed point if it exists.\n\\end{enumerate}\n\\end{problem}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale = 1]{markov2}\n\\end{center}\n\\caption{Transition diagram}\n\\end{figure}\n\n\\newpage\n\n\\section*{Graph Theory}\n\\begin{center}\n\\includegraphics[scale = .8]{graphExample}\n\\end{center}\n\nGraph theory is an important branch of mathematics and computer science. It describes how objects are connected to one another. In a rigorous sense, a graph is composed of two sets: a set of nodes and a set of edges that connect these nodes. \n\nA graph is directed if connections are uni-directional, and undirected if they are bi-directional. The above graphic shows an undirected graph. We can write a matrix that describes this type of graph. We let each row of our matrix represent our starting point and each column represent our destination. We put a 1 if there is a path and a 0 if there is not. For the above graph we generate the following matrix:\n\n\\[\nA = \\begin{pmatrix}\n0 & 1 & 0 & 0 & 1 & 0\\\\\n1 & 0 & 1 & 0 & 1 & 0\\\\\n0 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 1 & 1\\\\\n1 & 1 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0 & 0\n\\end{pmatrix}\n\\]\n\nThis matrix is called an adjacency matrix. Note that this matrix is symmetric, since the graph is undirected.\n\nWhat happens if we square an adjacency matrix? It turns out that raising an adjacency matrix to the n power yields the number of paths of length n between two vertices. For example by squaring the above matrix Python gives:\n\\begin{lstlisting}[style=python]\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}\n\nNow try to find the number of connections of length 6 from node 3 to itself. This is simple to do in Python:\n\\begin{lstlisting}[style=python]\n: sp.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}\nIt turns out that there are 55 unique paths of length 6 from node 3 to itself. Imagine trying to count all of those paths by hand! It would be very easy to count incorrectly. However, this method makes it very simple to count paths without any mistakes.\n\nThe astute reader may ask now why this matters. It turns out that the study of graphs and connectivity have many important applications. For example, connections between web pages can be described as graphs. So can flights between airports or friends on social networking sites. The same ideas are applied frequently in computer chip design and in the preservation of endangered species. We will explore one surprising application to chemistry.\n\nRemeber the \\li{bucky} array we explored in chapter one? The graph that this matrix represents is a graph for a geodesic dome, which has structure almost identical to certain types of carbon atoms. Understanding the graphs of certain types of molecules allows scientists to better understand the structure of the molecule, making identification and manipulation easier.\n\nWe will manipulate the matrix the \\li{bucky} to simulate the types of analysis a scientist could do on a complex carbon atom. For our purposes, each column and row of the \\li{bucky} matrix represents an atom in our molecule, and connections are chemical bonds from one atom to another.\n\n\\begin{problem}\nFind the number of connections between atoms in our molecule(the command \\li{sp.count\\_nonzero} may be useful). Then find the number of atoms that are connected by paths of length two. Three? At what path length are all of the atoms connected?\nA nifty way to visualize this is the \\li{plt.spy} command. Read the documentation for \\li{plt.spy} and then use \\li{plt.spy} to visualize how the graph is connected at path length one, two, four and ten. Remember, to load \\li{``bucky.csv''} into an array use the command \\lstinline{bucky = sp.loadtxt ( \"bucky.csv\" , delimiter = \",\" )}.\n\\end{problem}\n", "meta": {"hexsha": "82676581c155b24163768fcef92748bb4d669072", "size": 10330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/MarkovGraph/MarkovGraph_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/MarkovGraph/MarkovGraph_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/MarkovGraph/MarkovGraph_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": 46.9545454545, "max_line_length": 587, "alphanum_fraction": 0.7194578896, "num_tokens": 3109, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7697289521789377}}
{"text": "\\section{Linear Discriminant Analysis}\n\nLinear Discriminant Analysis (LDA) can be used both for dimensionality reduction and for classification. The basic principle is that LDA finds directions within the data that best separate the classes. For two classes, this amounts to finding a line that maximizes $\\frac{(\\mu_1 - \\mu_2)^2}{s_1^2 + s_2^2}$, where $\\mu_k$ are the mean locations of the classes and $s$ is the \"scatter\", which is basically the variance within one class about the mean. In higher dimensions, the algorithm finds something like a center point between the classes, or, more precisely, a point that maximizes the separation between the classes:\n\n\\begin{equation}\n\\frac{\\sum_{i\\neq j | i,j \\in K} (\\mu_i - \\mu_j)^2}{\\sum_{k\\in K} s_k^2}\n\\end{equation}\n\nBased on this point, a coordinate system can be constructed in which the first axis creates the best separation, the second axis the second best separation, etc.. These axes can be used as a means for supervised dimensionality reduction, somewhat analogously to PCA. Classification can be performed by investigating in which sector of the separation the datapoint falls. \n\nThis was an attempt at an intuitive explanation of LDA. The true story is slightly less intuitive. LDA classification corresponds to fitting multivariate Gaussian distributions to the classes, where each class is assumed to have an identical covariance matrix, and the prior probability of observing a certain class is also taken into account. Classification then happens by looking at the Mahalanobis distance of a point to the Gaussians fitted to the various classes, and choosing the class which is closest. Quadratic Discriminant Analysis (QDA) works analogous to LDA, but allows for the different classes to have different covariance matrices. The result is a quadratic (rather than linear) decision surface. The Gaussian naive Bayes classifier turns out to be equivalent to QDA with the limitation that the covariance matrices of the classes are assumed to be diagonal. (This is in accordance with the basic naive Bayes assumption that the feature are conditionally independent on the class label.) \n", "meta": {"hexsha": "aa2067020f32ab1a3e9689630ea1ce2ae8eb3927", "size": 2149, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/sup_lda.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/sup_lda.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/sup_lda.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": 179.0833333333, "max_line_length": 1005, "alphanum_fraction": 0.8013029316, "num_tokens": 462, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380481, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7697289521789376}}
{"text": "\n\\subsection{Euclid's lemma}\n\n\\subsubsection{Statement}\n\nIf a prime number \\(p\\) divides product \\(a.b\\) then \\(p\\) must divide at least of one of \\(a\\) or \\(b\\).\n\n\\subsubsection{Proof}\n\nFrom Bezout's identity we know that:\n\n$d=px+by$\n\nWhere \\(p\\) and \\(b\\) are natural numbers and \\(d\\) is their greatest common denominator.\n\nLet's choose a prime number for \\(p\\). There are no common divisors, other than one. As a result there are exist values for \\(x\\) and \\(y\\) such that:\n\n$1=px+by$\n\nNow, we are trying to prove that if \\(p\\) divides \\(a.b\\) then \\(p\\) must divide at least one of \\(a\\) and \\(b\\), so let's multiply this by \\(a\\).\n\n$a=pax+aby$\n\nWe know that \\(p\\) divides \\(pax\\), and \\(p\\) divides \\(ab\\) by definition. As a result \\(p\\) can divide \\(a\\).\n\n", "meta": {"hexsha": "0064813534496c8b19547f1a04d6ae236999af05", "size": 764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmeticFundamental/01-03-lemma.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/arithmeticFundamental/01-03-lemma.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/arithmeticFundamental/01-03-lemma.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.3846153846, "max_line_length": 150, "alphanum_fraction": 0.6505235602, "num_tokens": 222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693716759489, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7696869959535539}}
{"text": "\\subsection{Defining partial order operator $\\leq$ through \\^{} meet operator}\n$a\\leq b$ if and only if a \\^{} b = a. We can see this in example in figure \\ref{fig:semilattice_and}. Consider \\{false, true\\} and \\{true, true\\}. The meet operator logical AND gives us \\{false, true\\}. This satisfies above definition thus \\{false, true\\} $\\leq$ \\{true, true\\}. \n\n\\subsection{Defining meet operator \\^{} through partial order operator $\\leq$}\na \\^{} b = c if and only if c $\\leq$ a, c $\\leq$ b and $\\nexists$ d d $\\leq$ a, d $\\leq$ b, c \\textless  d. \\\\\nIf we are given a partial ordering of values we can always find unique value in the same set which satisfies the above.\n\n\\subsection{Semilattice diagram through  $\\leq$}\n$x\\leq y$ indicates that there is a path from x to y and vice versa. This can be observed in figure \\ref{fig:semilattice_and}. There may not be a direct edge between two nodes related by partial order operator but there will exist a path.\n\n\\subsection{Properties of partial order}\n\\begin{itemize}\n    \\item \\textbf{Reflexive x $\\leq$ x}\n    \\item \\textbf{Anti-symmetric x $\\leq$ y and y $\\leq$ x $\\rightarrow$ x = y}\n    \\item \\textbf{Transitive x $\\leq$ y and y $\\leq$ z $\\rightarrow$ x $\\leq$ z}\n\\end{itemize}\nProperties of the meet operator \\^{} (idempotent, commutative, associative) guarantee the properties for $\\leq$. This can be shown easily.\n\n\\subsection{The $<$ operator}\n$a<b$ if and only if $a \\leq b$ and $b \\leq a$. In other words $a\\leq b$ and $a\\neq b$.\n\n\\subsection{Semilattice diagram}\n\\begin{itemize}\n\\item \\textbf{Set of nodes}: Set of values\n\\item \\textbf{Set of edges}: \\{ (y, x) {\\textbar} x \\textless  y and $\\nexists$ z .( x \\textless  z and z \\textless  y)  \\}. If there is such a z then there will be a path from x to z and z to y, so we do not need to draw an edge from x to y.\n\\end{itemize}\n\n\\subsection{Example of \\^{} and $\\leq$}\n\\textbf{Meet operator \\^{} $\\triangleq$ set-union $\\cup$} : ((x $\\leq$ y) $\\triangleq$ (x $\\cup$ y = x)) $\\equiv$ ( x $\\supseteq$ y). Thus x $\\leq$ y $\\equiv$ ( x $\\supseteq$ y).", "meta": {"hexsha": "48ba1dab494c4122363d9a813b683526dfe5052c", "size": 2060, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "module96.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": "module96.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": "module96.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": 71.0344827586, "max_line_length": 280, "alphanum_fraction": 0.6791262136, "num_tokens": 665, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8705972784807408, "lm_q1q2_score": 0.7696421874385543}}
{"text": "\\section{Matrices}\nIn the previous section we described linear transformations in a rather abstract way: what they are, how they behave qualitatively and how they look like in 2- and 3-dimensions. In this section we introduce a numerical method of representing linear transformations: matrices.\n\n\\subsection{Linear transformation of basis vectors}\nRecall that any vector $\\vec{v}\\in\\Rs{n}$ can be written as a linear combination of basis vectors $\\vec{b}_{1}, \\vec{b}_{2}, \\dots, \\vec{b}_{n}$:\n\\begin{equation}\n\t\\vec{v} = \\sum\\limits_{i=1}^{n}\\alpha_{i}\\vec{b}_{i} = \\alpha_{1}\\vec{b}_{1} + \\alpha_{2}\\vec{b}_{2} + \\cdots + \\alpha_{n}\\vec{b}_{n}.\n\\end{equation}\n\nApplying a linear transformation $T$ on $\\vec{v}$ yields, using the properties of linear transformations,\n\\begin{align}\n\tT\\left(\\vec{v}\\right) &= T\\left(\\alpha_{1}\\vec{b}_{1} + \\alpha_{2}\\vec{b}_{2} + \\cdots + \\alpha_{n}\\vec{b}_{n}\\right)\\nonumber\\\\\n\t\\tikz[baseline=-0.5ex]{\\draw[-stealth, xred] (0,0) -- (1,0) node[pos=-0.1, anchor=east] {additivity}}\n\t\t\t\t\t\t  &= T\\left(\\alpha_{1}\\vec{b}_{1}\\right) + T\\left(\\alpha_{2}\\vec{b}_{2}\\right) + \\cdots + T\\left(\\alpha_{n}\\vec{b}_{n}\\right)\\nonumber\\\\\n    \\tikz[baseline=-0.5ex]{\\draw[-stealth, xblue] (0,0) -- (1,0) node[pos=-0.1, anchor=east] {scalability}}\n\t\t\t\t\t\t  &= \\alpha_{1}T\\left(\\vec{b}_{1}\\right) + \\alpha_{2}T\\left(\\vec{b}_{2}\\right) + \\cdots + \\alpha_{n}T\\left(\\vec{b}_{n}\\right).\n\t\\label{eq:transfom_by_basis}\n\\end{align}\n\nThis result is pretty neat: it means that by knowing how a linear transformation $T$ changes the basis vectors, we know exactly how any vector is transformed by $T$. This true for any basis, and thus specifically to the standard basis, where the coefficients $\\alpha_{1},\\alpha_{2},\\dots,\\alpha_{n}$ are actually the components of the vector, i.e. $v_{1},v_{2},\\dots,v_{n}$. Thus in the standard basis:\n\\begin{equation}\n\tT\\left(\\vec{v}\\right) = v_{1}T\\left(\\eb{1}\\right) + v_{2}T\\left(\\eb{2}\\right) + \\cdots + v_{n}T\\left(\\eb{n}\\right).\n\\end{equation}\n\n\\begin{example}{Vector transformation via a basis}{}\n\tApplying the transformation $T:\\Rs{3}\\to\\Rs{3}$, defined as\n\t\\[\n\t\tT\\left(\\colvec{x;y;z}\\right)=\\colvec{x+y-2z;2x+z;-x-y-z}\n\t\\]\n\ton the vector $\\vec{v}=\\colvec{2;-1;3}$ yields the following vector:\n\t\\[\n\t\tT\\left(\\vec{v}\\right) = T\\left(\\colvec{2;-1;3}\\right) = \\colvec{2+(-1)-2\\cdot3;2\\cdot2+3;-2-(-1)-3} = \\colvec{2-1-6;4+3;-2+1-3} = \\colvec{-5;7;-4}.\n\t\\]\n\n\tNow, let us apply $T$ first to the three standard basis vectors $\\hat{x},\\hat{y},\\hat{z}$:\n\t\\begin{align*}\n\t\tT\\left( \\hat{x} \\right) &= T\\left(\\colvec{1;0;0}\\right) = \\colvec{1+0-2\\cdot0;2\\cdot1+0;-1-0-0} = \\colvec{1;2;-1},\\\\\n\t\tT\\left( \\hat{y} \\right) &= T\\left(\\colvec{0;1;0}\\right) = \\colvec{0+1-2\\cdot0;2\\cdot0+0;-0-1-0} = \\colvec{1;0;-1},\\\\\n\t\tT\\left( \\hat{z} \\right) &= T\\left(\\colvec{0;0;1}\\right) = \\colvec{0+0-2\\cdot1;2\\cdot0+1;-0-0-1} = \\colvec{-2;1;-1}.\n\t\\end{align*}\n\n\tTaking these results and applying \\autoref{eq:transfom_by_basis} yields\n\t\\begin{align*}\n\t\tT\\left( \\vec{v} \\right) &= 2T \\left( \\hat{x} \\right) -T \\left( \\hat{y} \\right) + 3T \\left( \\hat{z} \\right)\\\\\n\t\t\t\t\t\t\t\t&= 2\\colvec{1;2;-1} - \\colvec{1;0;-1} + 3\\colvec{-2;1;-1}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{2;4;-2} - \\colvec{1;0;-1} + \\colvec{-6;3;-3}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{2-1-6;4-0+3;-2-(-1)+(-3)}\\\\\n\t\t\t\t\t\t\t\t&= \\colvec{-5;7;-4},\n\t\\end{align*}\n\twhich is indeed what we got when we applied $T$ directly to $\\vec{v}$.\n\\end{example}\n\n\\subsection{From transformations to matrices}\nThe most general linear transformation $T:\\Rs{2}\\to\\Rs{2}$ has the following form:\n\\begin{equation}\n\tT \\left( \\colvec{x;y} \\right) = \\colvec{ax+by;cx+dy},\n\t\\label{eq:generic_R2_LT}\n\\end{equation}\nwhere $a,b,c,d\\in\\mathbb{R}$. If we apply this transformation to $\\hat{x}$ and $\\hat{y}$ we get, respectively,\n\\begin{equation}\n\tT \\left( \\hat{x} \\right) = \\colvec{a;c},\\quad T \\left( \\hat{y} \\right) = \\colvec{b;d}.\n\t\\label{eq:}\n\\end{equation}\nWe can now collect these two vectors to form a new structure, which we call a \\emph{matrix} (in this specific casr a $2\\times2$ matrix):\n\\begin{equation}\n\tA = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix}.\n\t\\label{eq:matrix}\n\\end{equation}\n\nWe then define the product of $M$ with a vector $\\vec{v}=\\colvec{x;y}$ to yield $T \\left( \\vec{v} \\right)$, i.e.\n\\begin{equation}\n\tA\\vec{v} = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix} \\cdot\\colvec{x;y} = \\colvec{ax+by;cx+dy}.\n\t\\label{eq:matrix_vector_product}\n\\end{equation}\nThis defintion can be re-written as following:\n\\begin{equation}\n\tA\\vec{v} = \\begin{bNiceMatrix} a&b\\\\c&d \\end{bNiceMatrix} \\cdot\\colvec{x;y} = \\colvec{A_{1}\\cdot\\vec{v};A_{2}\\cdot\\vec{v}},\n\t\\label{eq:matrix_vector_product_as_dot_product}\n\\end{equation}\ni.e. the $i$-th component of the resulting vector is the scalar product of the $i$-th \\textbf{row} of the matrix with the vector $\\vec{v}$.\n\n\\begin{example}{Matrix-vector product}{}\n\tSome matrix-vector products:\n\n\t\\begin{align*}\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & -2 \\\\\n\t\t\t0 & 5\n\t\t\\end{bNiceMatrix}\\colvec{-3;2} &= \\colvec{1\\cdot(-3) + (-2)\\cdot2;0\\cdot(-3)+5\\cdot2} = \\colvec{-7;10},\\\\[5mm]\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & 2 \\\\\n\t\t\t1 & 2\n\t\t\\end{bNiceMatrix}\\colvec{5;-4} &= \\colvec{1\\cdot5+2\\cdot(-4);1\\cdot5+2\\cdot(-4)} = \\colvec{-3;-3},\\\\[5mm]\n\t\t\\begin{bNiceMatrix}\n\t\t\t1 & 0 \\\\\n\t\t\t0 & 2\n\t\t\\end{bNiceMatrix}\\colvec{2;-2} &= \\colvec{2\\cdot2+0\\cdot(-2);0\\cdot2+2\\cdot(-2)} = \\colvec{4;-4}.\n\t\\end{align*}\n\\end{example}\n\n\\begin{challenge}{Proof of linearity}{}\n\tProve that the transformation $T$ in \\autoref{eq:generic_R2_LT} is indeed linear.\n\\end{challenge}\n\nThe most general form of a linear transformation is $T:\\Rs{n}\\to\\Rs{m}$, i.e. a transformation which takes $n$-dimensional vectors as input and returns $m$-dimensional vectors as output:\n\\begin{equation}\n\tT \\left( \\colvec{\\tikzmark{N}x_{1};x_{2};\\vdots;x_{n}} \\right) = \\colvec{\n\t\t\\Ma{1}{1}x_{1}+\\Ma{1}{2}x_{2}+\\cdots+\\Ma{1}{n}x_{n};\n\t\t\\Ma{2}{1}x_{1}+\\Ma{2}{2}x_{2}+\\cdots+\\Ma{2}{n}x_{n}\\tikzmark{M};\n\t\t\\vdots;\n\t\t\\Ma{m}{1}x_{1}+\\Ma{m}{2}x_{2}+\\cdots+\\Ma{m}{n}x_{n}\n\t},\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t\\node[xblue] (Ntxt) at ($(pic cs:N)+(-1.5cm,-2mm)$) {$\\Rs{n}\\ni$};\n\t\\draw[-stealth, xblue] (Ntxt) to [out=45, in=90] ($(pic cs:N)+(1mm,2.5mm)$);\n\t\\node[xred] (Mtxt) at ($(pic cs:M)+(2.5cm,5mm)$) {$\\in\\Rs{m}$};\n\t\\draw[-stealth, xred] (Mtxt) to [out=180, in=0] ($(pic cs:M)+(2.5mm,0)$);\n\\end{tikzpicture}\n\nwhere $\\Ma{i}{j}\\in\\mathbb{R},\\ \\textcolor{xred}{i}=1,2,3,\\dots,m$ and $\\textcolor{xblue}{j}=1,2,3,\\dots,n$.\n\n\\begin{challenge}{Proof of linearity}{}\n\tProve that the above transformation $T$ is indeed linear.\n\\end{challenge}\n\nRespectively, we define an $\\textcolor{xred}{m}\\times \\textcolor{xblue}{n}$ matrix (\\textcolor{xred}{$m$} rows by \\textcolor{xblue}{$n$} columns) by collecting all the coefficients $\\Ma{i}{j}$ into a single structure:\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:mxn_matrix}\n\\end{equation}\nThe product $M\\vec{v}$ (where $\\vec{v}\\in\\Rs{n}$) is then defined as\n\\begin{equation}\n\tA\\vec{v} =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\\colvec{x_{1};x_{2};\\vdots;x_{n}} = \\colvec{\n\t\\Ma{1}{1}x_{1}+\\Ma{1}{2}x_{2}+\\cdots+\\Ma{1}{n}x_{n};\n\t\\Ma{2}{1}x_{1}+\\Ma{2}{2}x_{2}+\\cdots+\\Ma{2}{n}x_{n};\n\t\\vdots;\n\t\\Ma{m}{1}x_{1}+\\Ma{m}{2}x_{2}+\\cdots+\\Ma{m}{n}x_{n}\n\t}.\n\t\\label{eq:}\n\\end{equation}\nAgain, note that the $i$-th component of the resulting vector is the scalar product $A_{i}\\cdot\\vec{v}$.\n\n\\begin{note}{When is a matrix-vector product defined}{}\n\tIn order for a matrix-vector product to be defined, the vector must be of the same dimension as the number of \\textbf{columns} in the matrix - i.e. given an $a\\times b$ matrix, a vector must be $b$-dimensional for the product to be defined.\n\\end{note}\n\n\\begin{example}{Some matrix-vector products}{}\n\t\\blindtext[2]\n\\end{example}\n\nThe structure of an $m\\times n$ matrix $A$ has a nice property: given that the transformation in represented in some basis $B=\\left\\{ \\vec{b}_{1},\\vec{b}_{2},\\dots,\\vec{b}_{n} \\right\\}$, the $i$-th column of the matrix always shows how $\\vec{b}_{i}$ is transformed by the product $A\\vec{b}_{n}$. This is easy to see in the case of the standard basis, which we anyway use througout this chapter:\n\n\\vspace{1cm}\n\\begin{equation*}\n\t\\setlength{\\arraycolsep}{2.7mm}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{A1}\\Ma{1}{1} & \\tikzmark{B1}\\Ma{1}{2} & \\cdots & \\tikzmark{N1}\\Ma{1}{n}\\\\\n\t    \\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1}\\tikzmark{A2} & \\Ma{m}{2}\\tikzmark{B2} & \\cdots & \\Ma{m}{n}\\tikzmark{N2}\n\t\\end{bNiceMatrix}.\n\\end{equation*}\n\\tikzset{\n\thighlight/.style={thick, draw=#1, rounded corners, draw opacity=1, fill=#1, fill opacity=0.2},\n\thltxt/.style={highlight=#1, draw opacity=1, text=black, text opacity=1, above, yshift=1.5cm},\n\tnrtxt/.style={black, opacity=1, text opacity=1},\n\thlarrow/.style={-stealth, thick, #1},\n}\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t\\draw[highlight={xgreen}]  ($(pic cs:A1)+(-2pt,7pt)$) rectangle node[hltxt={xgreen} ](Atxt){$T \\left( \\eb{1} \\right)$}($(pic cs:A2)+(2pt,-5pt)$);\n\t\\draw[highlight={xpurple}] ($(pic cs:B1)+(-2pt,7pt)$) rectangle node[hltxt={xpurple}](Btxt){$T \\left( \\eb{2} \\right)$}($(pic cs:B2)+(2pt,-5pt)$);\n\t\\draw[highlight={xorange}] ($(pic cs:N1)+(-2pt,7pt)$) rectangle node[hltxt={xorange}](Ntxt){$T \\left( \\eb{n} \\right)$}($(pic cs:N2)+(2pt,-5pt)$);\n\n\t\\draw[hlarrow={xgreen}]  (Atxt.south) -- ++(0,-5mm);\n\t\\draw[hlarrow={xpurple}] (Btxt.south) -- ++(0,-5mm);\n\t\\draw[hlarrow={xorange}] (Ntxt.south) -- ++(0,-5mm);\n}\n\n\\begin{example}{Matrices}{}\n\tThe product of the following matrix $A$ with each of the vectors $\\eb{1},\\eb{2},\\eb{3}$ (i.e. $\\hat{x},\\hat{y}$ and $\\hat{z}$, respectively) returns the respective column of the matrix:\n\t\\begin{align*}\n\t\tA\\eb{1}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t \\end{bNiceMatrix}\\colvec{1;0;0} &= \\colvec{1\\cdot1+2\\cdot0+0\\cdot0;-1\\cdot1+3\\cdot0+4\\cdot0;0\\cdot1+1\\cdot0+3\\cdot0} = \\colvec{1;-1;0},\\\\[3mm]\n\t\tA\\eb{2}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t\\end{bNiceMatrix}\\colvec{0;1;0} &= \\colvec{1\\cdot0+2\\cdot1+0\\cdot0;-1\\cdot0+3\\cdot1+4\\cdot0;0\\cdot0+1\\cdot1+3\\cdot0} = \\colvec{2;3;1},\\\\[3mm]\n\t\tA\\eb{3}=\n\t\t\\begin{bNiceMatrix}\n\t\t\t 1 & 2 & 0\\\\\n\t\t\t-1 & 3 & 4\\\\\n\t\t\t 0 & 1 & 3\\\\\n\t\t\\end{bNiceMatrix}\\colvec{0;0;1} &= \\colvec{1\\cdot0+2\\cdot0+0\\cdot1;-1\\cdot0+3\\cdot0+4\\cdot1;0\\cdot0+1\\cdot0+3\\cdot1} = \\colvec{0;4;3}.\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Matrix representation of the basic linear transformations (2D)}\nWe can now represent all of the basic linear transformations in $\\Rs{2}$ mentioned in the previous section (\\autoref{fig:basicLinearTrans}) as $2\\times2$ matrices. We do this by observing how the basis vectors $\\hat{x}$ and $\\hat{y}$ change after the application of each transformation.\n\n\\begin{descitemize}\n\t\\item[Identity] both basis vectors remain the same: $\\colvec{1;0}\\to\\colvec{1;0},\\ \\colvec{0;1}\\to\\colvec{0;1}$. Therefore the matrix $I$ representing the identity transformation is\n\t\t\\begin{equation}\n\t\t\tI = \\begin{bNiceMatrix} 1&0 \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\\end{equation}\n\n\t\\item[Scaling by $\\bm{s}$ in the $\\bm{x}$-direction] the basis vector $\\hat{x}$ is streched by $s$: $\\colvec{1;0}\\to\\colvec{s;0}$. The basis vector $\\hat{y}=\\colvec{0;1}$ stays the same. Therefore the matrix $S_{x}$ representing the transformation is\n\t\t\\begin{equation}\n\t\t\tS_{x} = \\begin{bNiceMatrix} s&0 \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\t\n\t\\item[Scaling by $\\bm{s}$ in the $\\bm{y}$-direction] much like with $S_{x}$, now the basis vector $\\hat{y}$ is the one getting streched, by $\\beta$: $\\colvec{0;1}\\to\\colvec{0;s}$. The basis vector $\\hat{x}=\\colvec{1;0}$ stays the same. Therefore the matrix $S_{y}$ representing the transformation is\n\t\t\\begin{equation}\n\t\t\tS_{y} = \\begin{bNiceMatrix} 1&0 \\\\ 0&s \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\\item[Rotating by $\\bm{\\theta}$ counter-clockwise about the origin] \\autoref{fig:rotationT} shows how do $\\hat{x}$ and $\\hat{y}$ transformed by the rotation. In the case of $\\hat{x}$, the resulting vector is $R_{\\theta} \\left( \\hat{x} \\right)=\\colvec{\\cos(\\theta),\\sin(\\theta)}$, since thiese are the respective sides of a right triangle of hypotenous $1$ and angle $\\theta$. The components of $R_{\\theta}\\left(\\hat{y}\\right)$ can be calculated by rotating $\\hat{x}$ by $\\theta+\\frac{\\pi}{2}$ ($\\theta+\\ang{90}$): $\\cos \\left( \\theta+\\frac{\\pi}{2} \\right) = -\\sin(\\theta)$, and $\\sin \\left( \\theta+\\frac{\\pi}{2} \\right) = \\cos \\left( \\theta \\right)$. Therefore we get\n\t\t\\begin{equation}\n\t\t\t\\colvec{1;0} \\to \\colvec{\\cos(\\theta);\\sin(\\theta)},\\ \\colvec{0;1} \\to \\colvec{-\\sin(\\theta);\\cos(\\theta)}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\tAltogether the rotation matrix $R_{\\theta}$ is\n\t\t\\begin{equation}\n\t\t\tR_{\\theta} = \\begin{bNiceMatrix} \\cos(\\theta)&-\\sin(\\theta) \\\\ \\sin(\\theta)&\\cos(\\theta) \\end{bNiceMatrix}.\n\t\t\t\\label{eq:2D_rotation_matrix}\n\t\t\\end{equation}\n\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=10cm, height=10cm,\n\t\t\t\t\txmin=-1.3, xmax=1.3,\n\t\t\t\t\tymin=-1.3, ymax=1.3,\n\t\t\t\t\txtick={-1,0,1},\n\t\t\t\t\tytick={-1,0,1},\n\t\t\t\t\tyticklabel pos=right,\n\t\t\t\t\tyticklabel style={anchor=west},\n\t\t\t\t]\n\t\t\t\t\\pgfmathsetmacro{\\t}{30};\n\t\t\t\t\\draw[black!20] (1,0) arc (0:360:1);\n\t\t\t\t\\tikzset{point/.style={circle, fill=#1, inner sep=0pt, minimum size=3pt}}\n\n\t\t\t\t% x\n\t\t\t\t\\draw[vector, xred] (0,0) -- (1,0) node[midway, below] {$\\hat{x}$};\n\t\t\t\t\\draw[vector, xred, dashed] (0,0) -- ({cos(\\t)},{sin(\\t)}) node[midway, above, rotate=\\t] {$R_{\\theta} \\left( \\hat{x} \\right)$};\n\t\t\t\t\\fill[xpurple, opacity=0.15] (0,0) -- (1,0) arc (0:\\t:1) -- cycle;\n\t\t\t\t\\draw[vector, xpurple, dashed] (1,0) arc (0:\\t:1) node[point={xred}] (rx) {};\n\t\t\t\t\\node[text=xpurple] at ({1.1*cos(\\t/2)},{1.1*sin(\\t/2)}) {$\\theta$};\n\t\t\t\t\n\t\t\t\t% y\n\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, right] {$\\hat{y}$};\n\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- ({-sin(\\t)},{cos(\\t)}) node[midway, below, rotate={\\t-90}] {$R_{\\theta} \\left( \\hat{y} \\right)$};\n\t\t\t\t\\fill[xpurple, opacity=0.15] (0,0) -- (0,1) arc (90:{90+\\t}:1) -- cycle;\n\t\t\t\t\\draw[vector, xpurple, dashed] (0,1) arc (90:{90+\\t}:1) node[point={xblue}] (ry) {};\n\t\t\t\t\\node[text=xpurple] at ({-1.1*sin(\\t/2)},{1.1*cos(\\t/2)}) {$\\theta$};\n\t\t\t\t\\end{axis}\n\t\t\t\t\\node[xred, anchor=west, yshift=5pt]  at (rx) {$\\left(  \\Ctrig,\\Strig \\right)$};\n\t\t\t\t\\node[xblue, anchor=east, xshift=-4pt] at (ry) {$\\left( -\\Strig,\\Ctrig \\right)$};\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{Rotation of $\\textcolor{xred}{\\hat{x}}$ and $\\textcolor{xblue}{\\hat{y}}$ by an angle $\\textcolor{xpurple}{\\theta}$ counter-clockwise about the origin. The notations $\\Ctrig,\\Strig$ stand for $\\cos(\\textcolor{xpurple}{\\theta})$ and $\\sin(\\textcolor{xpurple}{\\theta})$, respectively.}\n\t\t\t\\label{fig:rotationT}\n\t\t\\end{figure}\n\t\n\t\\item[Skew by $\\bm{k}$ in the $\\bm{x}$-direction] what differentiates this transformation from scaling in the $x$-direction is that a skew changes only $\\hat{y}$ by adding to it some horizontal displacement $\\vec{K}=k\\hat{x}$ (see \\autoref{fig:skew_in_x}). Therefore $\\hat{x}$ remains the same while $\\hat{y}$ is transformed as $\\hat{y}\\to\\hat{y}+\\vec{k}=\\hat{y}+k\\hat{x}=\\colvec{0;1}+\\colvec{k;0}=\\colvec{k;1}$, and altogether the matrix is\n\t\t\\begin{equation}\n\t\t\tK_{x} = \\begin{bNiceMatrix} 1&k \\\\ 0&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\t\t\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tvector plane,\n\t\t\t\t\twidth=10cm, height=10cm,\n\t\t\t\t\txmin=-1.3, xmax=1.3,\n\t\t\t\t\tymin=-1.3, ymax=1.3,\n\t\t\t\t\tticks=none,\n\t\t\t\t]\n\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[midway, below] {$\\hat{x}, K_{x}\\left(\\hat{x}\\right)$};\n\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[midway, right] {$\\hat{y}$};\n\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- (0.5,1) node[midway, right] {$K_{x}\\left( \\hat{y} \\right)$};\n\t\t\t\t\\draw[vector, xpurple, dashed] (0,1) -- (0.5,1) node [midway, above] {$\\vec{k}=k\\hat{x}$};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\t\\caption{Skew in the $x$-direction.}\n\t\t\t\\label{fig:skew_in_x}\n\t\t\\end{figure}\n\n\t\\item[Skew by $\\bm{k}$ in the $\\bm{y}$-direction] same idea, except the roles of the axes are reveresed:\n\t\t\\[\n\t\t\t\\colvec{1;0}\\to\\colvec{1;k},\\ \\colvec{0;1}\\to\\colvec{0;1}.\n\t\t\\]\n\t\tThus the matrix is\n\t\t\\begin{equation}\n\t\t\tK_{y} = \\begin{bNiceMatrix} 1&0 \\\\ k&1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\n\t\\item[Reflections across a line going through the origin] in the case of reflections across the $x$-axis, $\\hat{x}$ stays the same, while $\\hat{y}$ is flipped (see \\autoref{fig:ref_x_axis}), i.e. $\\colvec{0;1}\\to-\\colvec{0;1}=\\colvec{0;-1}$. Therefore the matrix is\n\t\t\\begin{equation}\n\t\t\t\\Refl_{x} = \\begin{bNiceMatrix} 1&0 \\\\ 0&-1 \\end{bNiceMatrix}.\n\t\t\\end{equation}\n\t\t\n\t\tSimilarily, a reflection across the $y$-axis flipps $\\hat{x}$ while keeping $\\hat{y}$ the same (see \\autoref{fig:ref_y_axis}), i.e.\n\t\t\\begin{equation}\n\t\t\t\\Refl_{y} = \\begin{bNiceMatrix} -1&0 \\\\ 0&1 \\end{bNiceMatrix}. \n\t\t\\end{equation}\n\t\t\n\t\tAnother special case of these kinds of reflections is done across the line rotated by $\\frac{\\pi}{4}=\\ang{45}$ relative to the $x$-axis, i.e the line $y=x$. In this case $\\hat{x}$ and $\\hat{y}$ are swapped, giving\n\t\t\\begin{equation}\n\t\t\t\\Refl_{\\frac{\\pi}{4}} = \\begin{bNiceMatrix} 0&1 \\\\ 1&0 \\end{bNiceMatrix}. \n\t\t\\end{equation}\n\n\t\tThe most general reflection is made across a line of angle $\\theta$ relative to the $x$-axis (see \\autoref{fig:ref_line}):\n\t\t\\begin{equation}\n\t\t\t\\Refl_{\\theta} = \\begin{bNiceMatrix} \\cos \\left( 2\\theta \\right) & \\sin \\left( 2\\theta \\right) \\\\ \\sin \\left( 2\\theta \\right) & -\\cos \\left( 2\\theta \\right) \\end{bNiceMatrix}.\n\t\t\\end{equation}\n\t\tA way to calculate this matrix will be shown later in the chapter.\n\n\t\tWe can translate the matrix to be based on the slope $m$ of the line instead of its angle $\\theta$ relative to the $x$-axis by using the relation $m=\\tan\\left(\\theta\\right)$ and the two trigonomentric identities for double angles (\\autoref{eq:tan_double_angles}):\n\t\t\\begin{align*}\n\t\t\t\\begin{bNiceMatrix} \\cos \\left( 2\\theta \\right) & \\sin \\left( 2\\theta \\right) \\\\ \\sin \\left( 2\\theta \\right) & -\\cos \\left( 2\\theta \\right) \\end{bNiceMatrix} &= \\begin{bNiceMatrix} \\frac{1-\\tan^{2} \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } & \\frac{2\\tan \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } \\\\ \\frac{2\\tan \\left( \\theta \\right) }{1+\\tan^{2} \\left( \\theta \\right) } & \\frac{\\tan^{2} \\left( \\theta \\right)-1 }{1+\\tan^{2} \\left( \\theta \\right) } \\end{bNiceMatrix}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1}{1+\\tan^{2} \\left( \\theta \\right)}\\begin{bNiceMatrix} 1-\\tan^{2} \\left( \\theta \\right) & 2\\tan \\left( \\theta \\right) \\\\ 2\\tan \\left( \\theta \\right) & \\tan^{2} \\left( \\theta \\right) -1  \\end{bNiceMatrix}\\\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{1}{1+m^{2}} \\begin{bNiceMatrix} 1-m^{2} & 2m \\\\ 2m & m^{2}-1 \\end{bNiceMatrix}.\n\t\t\\end{align*}\t\n\n\t\t\\begin{figure}\n\t\t\t\\centering\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x},\\ \\Refl_{x}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y}$};\n\t\t\t\t\t\\draw[vector, xblue, dashed] (0,0) -- (0,-1) node[right] {$\\Refl_{x}\\left(\\hat{y}\\right)$};\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across the $x$-axis.}\n\t\t\t\\label{fig:ref_x_axis}\n\t\t\t\\end{subfigure}\n\t\t\t\\hfill\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x}$};\n\t\t\t\t\t\\draw[vector, xred, dashed] (0,0) -- (-1,0) node[below] {$\\Refl_{y}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y},\\ \\Refl_{y}\\left(\\hat{y}\\right)$};\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across the $y$-axis.}\n\t\t\t\\label{fig:ref_y_axis}\n\t\t\t\\end{subfigure}\n\t\t\t\\begin{subfigure}[c]{0.45\\textwidth}\n\t\t\t\\begin{center}\n\t\t\t\t\\begin{tikzpicture}\n\t\t\t\t\t\\begin{axis}[\n\t\t\t\t\t\tvector plane,\n\t\t\t\t\t\twidth=8cm, height=8cm,\n\t\t\t\t\t\txmin=-1.5, xmax=1.5,\n\t\t\t\t\t\tymin=-1.5, ymax=1.5,\n\t\t\t\t\t\tticks=none,\n\t\t\t\t\t]\n\t\t\t\t\t% original vectors\n\t\t\t\t\t\\draw[vector, xred]  (0,0) -- (1,0) node[below] {$\\hat{x}$};\n\t\t\t\t\t\\draw[vector, xblue] (0,0) -- (0,1) node[right] {$\\hat{y}$};\n\t\t\t\t\t\n\t\t\t\t\t% reflection line\n\t\t\t\t\t\\draw[thick, black!75, dashed] (-1.5,-0.5) -- (1.5,0.5);\n\n\t\t\t\t\t% reflected vectors\n\t\t\t\t\t\\draw[vector, xred, dashed]  (0,0) -- (0.8,0.6) node[below, anchor=west, yshift=5pt] {$\\Refl_{\\theta}\\left(\\hat{x}\\right)$};\n\t\t\t\t\t\\draw[vector, xblue, dashed, anchor=west] (0,0) -- (0.6,-0.8) node[right] {$\\Refl_{\\theta}\\left(\\hat{y}\\right)$};\n\n\t\t\t\t\t% angles\n\t\t\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (0.5,0) arc (0:18.435:0.5) node (A) {} -- cycle;\n\t\t\t\t\t\\fill[xgreen, opacity=0.2]  (0,0) -- (A) arc (18.435:36.87:0.5) -- (0,0);\n\t\t\t\t\t\\fill[xpurple, opacity=0.2] (0,0) -- (0,0.5) arc (90:198.435:0.5) node (B) {} -- cycle;\n\t\t\t\t\t\\fill[xgreen, opacity=0.2]  (0,0) -- (B) arc (198.435:306.87:0.5) -- (0,0);\n\t\t\t\t\t\\end{axis}\n\t\t\t\t\\end{tikzpicture}\t\n\t\t\t\\end{center}\n\t\t\t\\caption{Reflection across a line going through the origin. Notice how in both cases the purple and green angles are the same: this shows that both $\\hat{x}$ and $\\hat{y}$ are reflected across the line.}\n\t\t\t\\label{fig:ref_line}\n\t\t\t\\end{subfigure}\n\t\t\t\\caption{Reflections across different lines going through the origin.}\n\t\t\t\\label{fig:reflections}\n\t\t\\end{figure}\n\t\t\n\t\\item[Reflection across the origin] in this case both $\\hat{x}$ and $\\hat{y}$ are flipped, i.e.\n\t\t\\[\n\t\t\t\\colvec{1;0}\\to\\colvec{-1;0},\\ \\colvec{0;1}\\to\\colvec{0;-1},\n\t\t\\]\n\t\tand the matrix is essentially a rotation by $\\pi$ ($\\ang{180}$) around the origin:\n\t\t\\begin{equation}\n\t\t\tR = \\begin{bNiceMatrix} -1&0 \\\\ 0&-1 \\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\\end{descitemize}\n\nTable \\autoref{tab:matrix_basic_LTs} summarizes all the matrices of the basic linear transformations.\n\n\\begin{longtable}{lcccc}\n\t% !!! vvv MUST FIND WHY THESE DON'T WORK vvv !!! %\n\t% \\caption{my caption}\\\\\n\t% \\label{tab:matrix_basic_LTs}\n\t% !!! ^^^ THESE TWO LINES ^^^ !!! %\n\t\\toprule\n\tTransformation & Trans Tapir & $T \\left( \\hat{x} \\right)$ & $T \\left( \\hat{y} \\right)$ & Matrix\\\\\n\t\\midrule\n\tIdentity & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tScale in $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1.3}{0}{0}{1}{0}{0}{}} & $\\colvec{s;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} s&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tScale in $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{1.4}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;s}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&s \\end{bNiceMatrix}$\\\\\n\tRotation & \\tikz[baseline=-0.5ex]{\\tapirTransComp{0.866}{0.5}{-0.5}{0.866}{0}{0}{}} & $\\colvec{\\Ctrig;-\\Strig}$ & $\\colvec{\\Strig;\\Ctrig}$ & $\\begin{bNiceMatrix} \\Ctrig & -\\Strig \\\\ \\Strig & \\Ctrig \\end{bNiceMatrix}$\\\\\n\tSkew in $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0.5}{1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{k;1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ k&1 \\end{bNiceMatrix}$\\\\\n\tSkew in $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0.35}{0}{1}{0}{0}{}} & $\\colvec{1;k}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} 1&k \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tReflection by $x$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{1}{0}{0}{-1}{0}{0}{}} & $\\colvec{1;0}$ & $\\colvec{0;-1}$ & $\\begin{bNiceMatrix} 1&0 \\\\ 0&-1 \\end{bNiceMatrix}$\\\\\n\tReflection by $y$ & \\tikz[baseline=-0.5ex]{\\tapirTransComp{-1}{0}{0}{1}{0}{0}{}} & $\\colvec{-1;0}$ & $\\colvec{0;1}$ & $\\begin{bNiceMatrix} -1&0 \\\\ 0&1 \\end{bNiceMatrix}$\\\\\n\tReflection by line & \\tikz[baseline=-0.5ex]{\\tapirTransComp{0.882}{0.471}{0.471}{-0.882}{0}{0}{};\\draw[very thick, dashed, xpurple](-2,-0.5)--(2,0.5)node[pos=-0.05, anchor=east] {$y=mx$}} & $\\colvec{\\Ctrig_{2};\\Strig_{2}}$ & $\\colvec{\\Strig_{2};-\\Ctrig_{2}}$ & $\\begin{bNiceMatrix} \\Ctrig_{2}&\\Strig_{2} \\\\ \\Strig_{2}&-\\Ctrig_{2} \\end{bNiceMatrix}$\\\\\n\tReflection about origin & \\tikz[baseline=-0.5ex]{\\tapirTransComp{-1}{0}{0}{-1}{0}{0}{}} & $\\colvec{-1;0}$ & $\\colvec{0;-1}$ & $\\begin{bNiceMatrix} -1&0 \\\\ 0&-1 \\end{bNiceMatrix}$\\\\\n\t\\bottomrule\n\\end{longtable}\n\n\\subsection{Matrix representation of the basic linear transformations (3D)}\nIn 3-dimensions, the respective matrices are very similar. For example, the matrix for scaling by $\\alpha$ in the $x$-direction, $\\beta$ in the $y$-direction and $\\gamma$ in the $z$-direction is\n\\begin{equation}\n\tS = \n\t\\begin{bNiceMatrix}\n\t\t\\alpha & 0 & 0\\\\\n\t\t0 & \\beta & 0\\\\\n\t\t0 & 0 & \\gamma\n\t\\end{bNiceMatrix}.\n\t\\label{eq:3d_scale_matrix}\n\\end{equation}\n\nAs mentioned in the previous section, in 3-dimensions there are infinitely many rotations: the axis of rotation can be any line going through the origin (i.e. any vector except $\\vec{0}$ can represent an axis of rotation). Let us start with constructing rotations around the three axes $x,y$ and $z$ first. When rotating around the $x$ axis it stays stationary, while the rotation itself is done in the $yz$-plane. This means that we can take the $2\\times2$ rotation matrix (\\autoref{eq:2D_rotation_matrix}) and expand it such that it affects only the $yz$-plane:\n\n\\vspace{2em}\n\\begin{equation}\n\tR^{x}_{\\theta} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{D1}1 & 0 & 0\\\\\n\t\t0 & \\tikzmark{E1} \\cos \\left( \\theta \\right) & -\\sin \\left( \\theta \\right) \\\\\n\t\t0\\tikzmark{D2} & \\sin \\left( \\theta \\right) & \\cos \\left( \\theta \\right)\\tikzmark{E2}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:rotation_matrix_x}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture, blend mode=multiply]\n\t\\small\n\t\\draw[highlight={xred}] ($(pic cs:D1)+(-4pt,9pt)$) rectangle node[hltxt={xred}, above right, anchor=east, xshift=-1cm] (Atxt) {$\\hat{x}$ doesn't change} ($(pic cs:D2)+(4pt,-5pt)$);\n\t\\draw[hlarrow={xred}] (Atxt.east) to [out=0, in=90] ($(pic cs:D1) + (3pt,10pt)$);\n\t\\draw[highlight={xgreen}] ($(pic cs:E1)+(-4pt,9pt)$) rectangle node[hltxt={xgreen}, below left, anchor=west, yshift=-3cm, xshift=9mm] (Btxt) {2D rotation matrix} ($(pic cs:E2)+(4pt,-5pt)$);\n\t\\draw[hlarrow={xgreen}] (Btxt.west) to [out=180, in=-90] ($(pic cs:E1) + (35pt,-20pt)$);\n\\end{tikzpicture}\n\n\\vspace{3em}\nA graphical representation of the rotation can be seen in \\autoref{fig:rotation_in_yz}.\n\n\\begin{figure}\n\t\\centering\n\t\\def\\angThe{75}\n\t\\def\\angPhi{45}\n\t\\tdplotsetmaincoords{\\angThe}{\\angPhi}\n\t\\begin{tikzpicture}[tdplot_main_coords]\n\t\t\\draw[stealth-, very thick] (-3,0,0) -- (0,0,0);\n\t\t\\begin{scope}[canvas is yz plane at x=0]\n\t\t\t\\fill[fill=xgreen, fill opacity=0.2] (-2,2) -- (2,2) -- (2,-2) -- (-2,-2) -- cycle;\n\t\t\t\\draw[step=0.5, xdarkgreen!30] (-2,-2) grid (2,2);\n\t\t\t\\draw[vector, xgreen] (-1,0) arc (180:350:1);\n\t\t\t\\draw[vector, xgreen] (1,0) arc (0:170:1);\n\t\t\\end{scope}\n\t\t\\draw[stealth-stealth, very thick] (0,-3,0) -- (0,3,0) node[pos=1.05] {$y$};\n\t\t\\draw[stealth-stealth, very thick] (0,0,-3) -- (0,0,3) node[pos=1.05] {$z$};\n\t\t\\begin{scope}[canvas is yz plane at x=2]\n\t\t\t\\draw[vector, xgreen] (-0.5,0) arc (180:350:0.5);\n\t\t\\end{scope}\n\t\t\\draw[-stealth, very thick] (0,0,0) -- (3,0,0) node[pos=1.05] {$x$};\n\t\t\\begin{scope}[canvas is yz plane at x=2]\n\t\t\t\\draw[vector, xgreen] (0.5,0) arc (0:170:0.5);\n\t\t\\end{scope}\n\t\\end{tikzpicture}\n\t\\caption{In $\\Rs{3}$, rotation around the $x$-axis is a rotation in the $yz$-plane (i.e. $x=0$).}\n\t\\label{fig:rotation_in_yz}\n\\end{figure}\n\nThe rotation matrices around the $y$- and $z$-axes follow the same structure:\n\\begin{align}\n\tR^{y}_{\\varphi} &=\n\t\t\\begin{bNiceMatrix}\n\t\t\t\\cos \\left( \\varphi \\right) & 0 & \\sin \\left( \\varphi \\right)\\\\\n\t\t\t0 & 1 & 0 \\\\\n\t\t\t-\\sin \\left( \\varphi \\right) & 0 & \\cos \\left( \\varphi \\right)\n\t\t\\end{bNiceMatrix},\\\\\n\tR^{z}_{\\psi} &=\n\t\t\\begin{bNiceMatrix}\n\t\t\t\\cos \\left( \\psi \\right) & -\\sin \\left( \\psi \\right) & 0\\\\\n\t\t\t\\sin \\left( \\psi \\right) & \\cos \\left( \\psi \\right)  & 0\\\\\n\t\t\t0 & 0 & 1\n\t\t\\end{bNiceMatrix}.\n\t\\label{eq:rotation_y_z}\n\\end{align}\n\n\\begin{note}{Direction of the $y$-axis}{}\n\tThe signs of $\\sin \\left( \\varphi \\right)$ in $R^{y}_{\\varphi}$ are flipped compared to $R^{x}_{\\theta}$ and $R^{z}_{\\psi}$, for the same reason a similar thing happens in the $y$-component of the cross product: it is due to the use of a right-handed system.\n\\end{note}\n\nThe most general rotation in $\\Rs{3}$, i.e. around an axis represented by the unit vector $\\hat{u}=\\colvec{u_{x};u_{y};u_{z}}$ counter-clockwise by an angle $\\theta$, is given in matrix form as\n\\begin{equation}\n\tR_{\\theta}=\n\t\\begin{bNiceMatrix}\n\t\t\\cos \\left( \\theta \\right) +u_{x}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right] & u_{x}u_{y}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{z}\\sin \\left( \\theta \\right)  & u_{x}u_{z}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{y}\\sin \\left( \\theta \\right) \\\\\n\t\tu_{y}u_{x}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{z}\\sin \\left( \\theta \\right)  & \\cos \\left( \\theta \\right) +u_{y}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right] & u_{y}u_{z}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{x}\\sin \\left( \\theta \\right) \\\\\n\t\tu_{z}u_{x}\\left[1-\\cos \\left( \\theta \\right) \\right]-u_{y}\\sin \\left( \\theta \\right)  & u_{z}u_{y}\\left[1-\\cos \\left( \\theta \\right) \\right]+u_{x}\\sin \\left( \\theta \\right)  & \\cos \\left( \\theta \\right) +u_{z}^{2}\\left[1-\\cos \\left( \\theta \\right) \\right]\\end{bNiceMatrix}.\n\t\\label{eq:}\n\\end{equation}\nFor the moment the derivation of this matrix is not presented.\n\nTBW: REFLECTIONS IN 3D.\n\n\\subsection{Matrix operations}\nAn important operation that can be performed on a matrix is the \\emph{transpose}: this operation \"rotates\" all rows of the matrix to columns, and wise-versa:\n\\begin{equation}\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\\end{bNiceMatrix}\n\t\\xrightarrow[] {\\text{transpose}}\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{2}{1} & \\cdots & \\Ma{n}{1}\\\\\n\t\t\\Ma{1}{2} & \\Ma{2}{2} & \\cdots & \\Ma{n}{2}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{1}{m} & \\Ma{2}{m} & \\cdots & \\Ma{n}{m}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:transpose}\n\\end{equation}\nMathematically, the transpose takes any element $\\Ma{i}{j}$ of the matrix and exchanges its indeces, yielding $\\Ma{j}{i}$. If the original matrix has dimensions $\\rhl{m}\\times \\bhl{n}$, then the transposed matrix has dimensions $\\rhl{n}\\times \\bhl{m}$.\n\n\\begin{example}{Transposing matrices}{}\n    \\begin{align*}\n\t\t\\underset{3\\times3}{\n\t\t\t\\begin{bmatrix}\n\t\t\t\t\\rhl{1} & \\phl{2} & \\phl{3}\\\\\n\t\t\t\t\\ghl{4} & \\rhl{5} & \\phl{6}\\\\\n\t\t\t\t\\ghl{7} & \\ghl{8} & \\rhl{9}\\\\\n\t\t\t\\end{bmatrix}\n\t\t}\n\t  &\\xrightarrow[] {\\text{transpose}}\n\t  \\underset{3\\times3}{\n\t\t  \\begin{bmatrix}\n\t\t\t  \\rhl{1} & \\ghl{4} & \\ghl{7}\\\\\n\t\t\t  \\phl{2} & \\rhl{5} & \\ghl{8}\\\\\n\t\t\t  \\phl{3} & \\phl{6} & \\rhl{9}\\\\\n\t\t  \\end{bmatrix}\n\t  }\n\t  \\\\[5mm]\n\t  \\underset{2\\times3}{\n\t\t  \\begin{bmatrix}\n\t\t\t  \\ghl{0} & \\ghl{1} & \\ghl{-1}\\\\\n\t\t\t  \\phl{2} & \\phl{-3} & \\phl{5}\n\t\t  \\end{bmatrix}\n\t  }\n\t  &\\xrightarrow[] {\\text{transpose}}\n\t  \\underset{3\\times2}{\n\t\t  \\begin{bmatrix}\n\t\t\t  \\ghl{0}  & \\phl{2}\\\\\n\t\t\t  \\ghl{1}  & \\phl{-3}\\\\\n\t\t\t  \\ghl{-1} & \\phl{5}\n\t\t  \\end{bmatrix}\n\t  }\n\t  \\\\[5mm]\n\t  \\underset{6\\times1}{\n\t\t  \\begin{bmatrix}\n\t\t\t  \\phl{1} \\\\\n\t\t\t  \\phl{2} \\\\\n\t\t\t  \\phl{-1}\\\\\n\t\t\t  \\phl{0}\\\\\n\t\t\t  \\phl{7}\\\\\n\t\t\t  \\phl{-4}\\\\\n\t\t  \\end{bmatrix}\n\t  }\n\t  &\\xrightarrow[] {\\text{transpose}}\n\t  \\underset{1\\times6}{\n\t\t  \\begin{bmatrix}\n\t\t\t  \\phl{1} & \\phl{2} & \\phl{-1} & \\phl{0} & \\phl{7} & \\phl{-4}\n\t\t  \\end{bmatrix}\n\t  }\n    \\end{align*}\n\\end{example}\n\nThe notation for the transpose of a matrix $A$ is $A^{\\top}$. Since for the main diagonal elements of a matrix the row and column have equal indeces, the transpose operation does not affect their position in the matrix, i.e. $\\Ma{i}{i}\\xrightarrow[] {\\text{transpose}}\\Ma{i}{i}$. This means that $\\tr{A}=\\tr{A^{\\top}}$. Also, diagonal matrices are not affected by a transpose. The transpose of a transposed matrix is the original matrix, i.e. $\\left(A^{\\top}\\right)^{\\top} = A$.\n\nMuch like vectors, a matrix can be scaled by a real number, and two matrices can be added together if their dimensions are identical. The rules for scaling a matrix by a scalar and the addition of two matrices are the same as with vectors, namely everything is dome element wise:\n\\begin{descitemize}\n\t\\item[Scaling] given a matrix\n\t\t\\[\n\t\t\tA = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix}\n\t\t\\]\n\t\tand a scalar $\\gamma\\in\\mathbb{R}$, their product is\n\t\t\\begin{equation}\n\t\t\t\\gamma A = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\gamma\\cdot\\Ma{1}{1} & \\gamma\\cdot\\Ma{1}{2} & \\cdots & \\gamma\\cdot\\Ma{1}{n}\\\\\n\t\t\t\t\\gamma\\cdot\\Ma{2}{1} & \\gamma\\cdot\\Ma{2}{2} & \\cdots & \\gamma\\cdot\\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\gamma\\cdot\\Ma{m}{1} & \\gamma\\cdot\\Ma{m}{2} & \\cdots & \\gamma\\cdot\\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix}.\n\t\t\t\\label{eq:matrix_scaling}\n\t\t\\end{equation}\n\n\t\\item[Addition] given two matrices,\n\t\t\\[\n\t\t\tA = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1} & \\Ma{m}{2} & \\cdots & \\Ma{m}{n}\n\t\t\t\\end{bNiceMatrix},\\quad\n\t\t\tB = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Mb{1}{1} & \\Mb{1}{2} & \\cdots & \\Mb{1}{n}\\\\\n\t\t\t\t\\Mb{2}{1} & \\Mb{2}{2} & \\cdots & \\Mb{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Mb{m}{1} & \\Mb{m}{2} & \\cdots & \\Mb{m}{n}\n\t\t\t\\end{bNiceMatrix}, \n\t\t\\]\n\t\ttheir sum is\n\t\t\\begin{equation}\n\t\t\tA+B = \n\t\t\t\\begin{bNiceMatrix}\n\t\t\t\t\\Ma{1}{1}+\\Mb{1}{1} & \\Ma{1}{2}+\\Mb{1}{2} & \\cdots & \\Ma{1}{n}+\\Mb{1}{n}\\\\\n\t\t\t\t\\Ma{2}{1}+\\Mb{2}{1} & \\Ma{2}{2}+\\Mb{2}{2} & \\cdots & \\Ma{2}{n}+\\Mb{2}{n}\\\\\n\t\t\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\t\t\\Ma{m}{1}+\\Mb{m}{1} & \\Ma{m}{2}+\\Mb{m}{2} & \\cdots & \\Ma{m}{n}+\\Mb{m}{n}\n\t\t\t\\end{bNiceMatrix}.\n\t\t\t\\label{eq:}\n\t\t\\end{equation}\n\\end{descitemize}\n\n\\subsection{Types of matrices}\nAny matrix $A$ which represents a transformation of the type $\\Rs{n}\\to\\Rs{n}$ (i.e. from a space onto itself) has the same number of rows and columns (i.e. its dimension is $n\\times n$):\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\Ma{1}{1} & \\Ma{1}{2} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\Ma{2}{2} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{n}{1} & \\Ma{n}{2} & \\cdots & \\Ma{n}{n}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:square_matrix}\n\\end{equation}\n\nDue to their shape, such matrices are called \\emph{square matrices}. The elements $\\Ma{1}{1},\\Ma{2}{2},\\Ma{3}{3},\\dots,\\Ma{n}{n}$ of a square matrix jointly form its \\emph{main diagonal} (also: \\emph{principal diagonal}):\n\n\\vspace{1em}\n\\begin{equation}\n\tA =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{m11}\\cxgreen\\Ma{1}{1} & \\Ma{1}{2} & \\Ma{1}{3} & \\cdots & \\Ma{1}{n}\\\\\n\t\t\\Ma{2}{1} & \\cxgreen\\Ma{2}{2} & \\Ma{2}{3} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\Ma{3}{1} & \\Ma{3}{2} & \\cxgreen\\Ma{2}{3} & \\cdots & \\Ma{2}{n}\\\\\n\t\t\\vdots & \\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\Ma{n}{1} & \\Ma{n}{2} & \\Ma{n}{3} & \\cdots & \\cxgreen\\Ma{n}{n}\\tikzmark{mnn}\n\t\\end{bNiceMatrix}. \n\t\\label{eq:square_matrix_main_diag}\n\\end{equation}\n% \\tikz[overlay, remember picture, blend mode=multiply]{\n% \t\\draw[xgreen, line width=5mm, opacity=0.2, cap=round] ($(pic cs:m11)+(5pt,3pt)$) -- ($(pic cs:mnn)+(-5pt,2pt)$) node[pos=-0.1, anchor=east, xshift=-7mm, yshift=4mm, text=xdarkgreen, opacity=1] (txt) {main diagonal};\n% \t\\draw[-stealth, xdarkgreen] ($(txt.east)-(3mm,0)$) to [out=0, in=135] ($(pic cs:m11)+(-1pt,9pt)$);\n% }\n\nThe sum of the main diagonal elements is called the \\emph{trace} of the matrix:\n\\begin{equation}\n\t\\tr \\left( A \\right) = \\sum\\limits_{i=1}^{n}\\Ma{i}{i}.\n\t\\label{eq:trace}\n\\end{equation}\n\n\\emph{Triangular matrices} are matrices in which the elements above or below the main diagonal are all zeros, e.g.\n\n\\begin{center}\n\t\\def\\bperc{25}\n\t\\begin{tabular}{rcp{5mm}rc}\n\t\t$U=$ &\n\t\t$\\begin{bmatrix}\n\t\t\t1 & 6 & 6 & -3 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & 2 & 7 & 1 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & 3 & 5 \\\\\n\t\t\t\\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & -4\n\t\t\\end{bmatrix},$\n\t\t\t & &\n\t\t$L=$ &\n\t\t$\\begin{bmatrix}\n\t\t\t1 & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} \\\\\n\t\t\t\\tikzmark{LT1} 2 & 3 & \\textcolor{black!\\bperc}{0} & \\textcolor{black!\\bperc}{0} \\\\ \n\t\t\t5 & 1 & -5 & \\textcolor{black!\\bperc}{0} \\\\\n\t\t\t-4 & 1 & 2\\tikzmark{LT2} & -3\n\t\t\\end{bmatrix}.$\n\t\t\\\\[2.5em]\n\t\t\t & upper triangular & & & lower triangular\n\t\\end{tabular}\n\\end{center}\n\nA \\emph{diagonal matrix} $A$ is a matrix in which all the non-main diagonal elements, i.e. $\\Ma{i}{j}$ where $\\textcolor{xred}{i}\\neq \\textcolor{xblue}{j}$, equal zero. These matrices can be thought of as scaling matrices: each entry $\\Ma{i}{i}$ tells us how the sapce is scaled in the $i$-th dimension.\n\n\\begin{example}{Diagonal matrices}{}\n\tText.\n\\end{example}\nAs we saw in the cases of $\\Rs{2}$ and $\\Rs{3}$, diagonal matrices are \\emph{scaling matrices}: each entry $a_{ii}$ tells us by how much space is scaled in the $i$-th direction.\n\nA very important family of \\textbf{square} matrices are the \\emph{identity matrices}. These matrices have a unique structure: their main diagonal elements are all $1$, while the rest of the elements (the \\emph{off-diagonal elements}) are all $0$:\n\n\\vspace{1em}\n\\begin{equation}\n\tI_{n} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{I11} 1 & 0 & 0 & \\cdots & 0\\tikzmark{I1n}\\\\\n\t\t0 & 1 & 0 & \\cdots & 0\\\\\n\t\t0 & 0 & 1 & \\cdots & 0\\\\\n\t\t\\vdots & \\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t\\tikzmark{In1}0 & 0 & 0 & \\cdots & 1\\tikzmark{Inn}\n\t\\end{bNiceMatrix}\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t  \\draw [xred, thick, decorate, decoration={brace, amplitude=3pt, raise=7pt}] (pic cs:I1n) -- (pic cs:Inn) node[midway, right, xshift=10pt]{$n$ rows};\n\t  \\draw [xblue, thick, decorate, decoration={brace, amplitude=3pt, raise=10pt}] (pic cs:I11) -- (pic cs:I1n) node[midway, above, yshift=13pt]{$n$ columns};\n\\end{tikzpicture}\n\nA common way of depicting an identity matrix is\n\\[\n\tI_{n} =\n\t\\begin{bNiceMatrix}\n\t1   &       & \\Block{2-3}<\\huge>{0} \\\\\n\t\t&   1   &        &      &       \\\\\n\t\t&       &   1    &      &       \\\\\n\t\\Block{2-3}<\\huge>{0}\n\t\t&       &       & \\Ddots    &   \\\\\n\t\t&       &       &      &   1   \\\\\n\t\\end{bNiceMatrix}.\n\\]\nIn such a depiction, the off-diagonal elements are each written using a single zero. This kind of notation will come in handy in later sections. Yet another way of defining the identity matrix is by using the \\emph{Kronecker delta}, which takes two integers $i,j$ and returns $1$ if they are equal, otherwise it returns $0$:\n\\begin{equation}\n\t\\delta_{ij} =\n\t\\begin{cases}\n\t\t1 & i=j,\\\\\n\t\t0 & i\\neq j.\n\t\\end{cases}\n\t\\label{eq:kronecker_delta}\n\\end{equation}\nUsing the Kronecker delta, each element $a_{ij}$ of the identity matrix $I_{n}$ simply equals $\\delta_{ij}$.\n\nAn identity matrix of dimension $n$ represents the identity transformation in $\\Rs{n}$: each standard basis vector $\\eb{i}$ is left unchanged by the transformation.\n\n\\begin{example}{Identity matrices}{}\n\tThe identity matrices of $\\Rs{2},\\Rs{3},\\dots,\\Rs{6}$ (in each matrix the main diagonal is highlighted):\n\n\t\\centering\n\t\\begin{tabular}{ccccc}\n\t\t&\n\t\t$\\begin{bmatrix}\n\t\t\t\\cxblue1 & 0 & 0\\\\\n\t\t\t0 & \\cxblue1 & 0\\\\\n\t\t\t0 & 0 & \\cxblue1\n\t\t\\end{bmatrix}$& \n\t\t$\\begin{bmatrix}\n\t\t\t\\cxgreen1 & 0 & 0 & 0\\\\\n\t\t\t0 & \\cxgreen1 & 0 & 0\\\\\n\t\t\t0 & 0 & \\cxgreen1 & 0\\\\\n\t\t\t0 & 0 & 0 & \\cxgreen1\\\\\n\t\t\\end{bmatrix}$&\n\t\t$\\begin{bmatrix}\n\t\t\t\\cxpurple1 & 0 & 0 & 0 & 0\\\\\n\t\t\t0 & \\cxpurple1 & 0 & 0 & 0\\\\\n\t\t\t0 & 0 & \\cxpurple1 & 0 & 0\\\\\n\t\t\t0 & 0 & 0 & \\cxpurple1 & 0\\\\\n\t\t\t0 & 0 & 0 & 0 & \\cxpurple1\\\\\n\t\t\\end{bmatrix}$&\n\t\t$\\begin{bmatrix}\n\t\t\t\\cxorange1 & 0 & 0 & 0 & 0& 0\\\\\n\t\t\t0 & \\cxorange1 & 0 & 0 & 0& 0\\\\\n\t\t\t0 & 0 & \\cxorange1 & 0 & 0& 0\\\\\n\t\t\t0 & 0 & 0 & \\cxorange1 & 0& 0\\\\\n\t\t\t0 & 0 & 0 & 0 & \\cxorange1& 0\\\\\n\t\t\t0 & 0 & 0 & 0 & 0& \\cxorange1\\\\\n\t\t\\end{bmatrix}$\\\\\n\t\t$I_{2}$ & $I_{3}$ & $I_{4}$ & $I_{5}$ & $I_{6}$\n\t\\end{tabular}\n\\end{example}\nIn the next section we will see the importance of the identity matrices.\n\nAnother important family of matrices are the \\emph{orthogonal matrices} (also \\emph{orthonormal matrices}): we say that a matrix $Q$ is an orthogonal matrix if all of its columns, when viewed as column vectors, form an orthonormal set. For example, the identity matrices are all orthogonal matrices. Another orthogonal matrix is the matrix\n\\begin{equation}\n\tB = \\frac{1}{\\sqrt{2}}\\begin{bmatrix}1&1\\\\1&-1\\end{bmatrix},\n\t\\label{eq:}\n\\end{equation}\nsince both $\\frac{1}{\\sqrt{2}}\\colvec{1;1}$ and $\\frac{1}{\\sqrt{2}}\\colvec{1;-1}$ are unit vectors, and they are orthogonal to each other (as seen in REF).\n\nA \\emph{symmetric matrix} is a square matrix for which\n\\begin{equation}\n\tA^{\\top} = A.\n\t\\label{eq:symmetric_matrix}\n\\end{equation}\n\"Graphically\", the symmetry of such matrices can be seen in respect to their main diagonal.\n\n\\begin{example}{Symmetric matrix}{}\n\tThe following matrix $S$ is a symmetric $4\\times4$ matrix, in which the elements $a_{ij},a_{ji}$ are higlighted with the same color:\n\n\t\\centering\n\t\\begin{tikzpicture}[node distance=1.6cm]\n\t\t\\node (Seq) {$S=$};\n\t\t\\matrix (S) [matrix of nodes, right of=Seq, left delimiter={[}, right delimiter={]}]{\n\t\t\t1 & 3 & 5 & 7\\\\\n\t\t\t3 & 0 & 1 & 3\\\\\n\t\t\t5 & 1 & 4 & 2\\\\\n\t\t\t7 & 3 & 2 & 6\\\\\n\t\t};\n\t\t\\tikzset{every node/.style={inner sep=0}}\n\t\t\\scoped[on background layer]{\n\t\t\t\\foreach \\k in {1,...,4}\n\t\t\t\t\\node[fill=white, fit=(S-\\k-\\k)(S-\\k-\\k)] {};\n\t\t\t\\node[fill=xred!20, fit=(S-1-2)(S-1-2)] {};\n\t\t\t\\node[fill=xred!20, fit=(S-2-1)(S-2-1)] {};\n\t\t\t\\node[fill=xblue!20, fit=(S-1-3)(S-1-3)] {};\n\t\t\t\\node[fill=xblue!20, fit=(S-3-1)(S-3-1)] {};\n\t\t\t\\node[fill=xgreen!20, fit=(S-1-4)(S-1-4)] {};\n\t\t\t\\node[fill=xgreen!20, fit=(S-4-1)(S-4-1)] {};\n\t\t\t\\node[fill=xpurple!20, fit=(S-2-3)(S-2-3)] {};\n\t\t\t\\node[fill=xpurple!20, fit=(S-3-2)(S-3-2)] {};\n\t\t\t\\node[fill=xorange!20, fit=(S-2-4)(S-2-4)] {};\n\t\t\t\\node[fill=xorange!20, fit=(S-4-2)(S-4-2)] {};\n\t\t\t\\node[fill=xpink!20, fit=(S-3-4)(S-3-4)] {};\n\t\t\t\\node[fill=xpink!20, fit=(S-4-3)(S-4-3)] {};\n\t\t}\n\t\\end{tikzpicture}\n\\end{example}\n\nA rather non-interesting family of matrices are the \\emph{zero matrices}: these are matrices which have only zero-elements, i.e.\n\\begin{equation}\n\t\\bm{0}_{n} =\n\t\\begin{bNiceMatrix}\n\t\t\\tikzmark{z1}0 & 0 & \\cdots & 0\\tikzmark{z2}\\\\\n\t\t0 & 0 & \\cdots & 0\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\t0 & 0 & \\cdots & 0\\tikzmark{z3}\n\t\\end{bNiceMatrix}.\n\t\\label{eq:}\n\\end{equation}\n\\begin{tikzpicture}[overlay, remember picture]\n\t  \\draw [xred, thick, decorate, decoration={brace, amplitude=3pt, raise=7pt}] (pic cs:z2) -- (pic cs:z3) node[midway, right, xshift=10pt]{$m$ rows};\n\t  \\draw [xblue, thick, decorate, decoration={brace, amplitude=3pt, raise=10pt}] (pic cs:z1) -- (pic cs:z2) node[midway, above, yshift=13pt]{$n$ columns};\n\\end{tikzpicture}\nWe will see later in the section why exactly we call these matrices \"zero matrices\".\n", "meta": {"hexsha": "fe80473d7be3b2122ff4127e73852611af1d9af0", "size": 43589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_stars_repo_name": "JASory/maths_book", "max_stars_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_issues_repo_name": "JASory/maths_book", "max_issues_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/linear_algebra_intuitive/matrices.tex", "max_forks_repo_name": "JASory/maths_book", "max_forks_repo_head_hexsha": "b5fdd19b09e97697f287f5ca83e0d9133b704789", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.3784683685, "max_line_length": 668, "alphanum_fraction": 0.6181376035, "num_tokens": 17781, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.769642184470428}}
{"text": "\\section{The Jacobi and Gauss-Siedel Iterative Techniques}\n\\subsection{Jacobi's Method}\nThe \\emph{Jacobi iterative method} is obtained by solving the $i$th equation in $A\\bfx=\\mathbf{b}$ for $x_i$ to obtain(provided $a_{ii}\\neq 0$)\n\\[\nx_i=\\sum_{\\substack{j=1\\\\j\\neq i}}^n\\left(-\\frac{a_{ij}x_j}{a_{ii}}\\right)+\\frac{b_i}{a_{ii}},\\quad\\text{for $i=1,1,\\ldots,n$}.\n\\]\nIn general, iterative techniques for solving linear systems by converting the system $\\bfA\\bfx=\\bf b$ into an equivalent system of the form $\\bfx={\\bf Tc}$ for some fixed matrix $\\bf T$ and vector $\\bf c$. After the initial vector $x^{(0)}$ is selected, the sequence of approximate solution vectors is generated by computing\n\\[\n\\bfx^{(k)} = {\\bf T}\\bfx^{(k-1)}+{\\bf c}.\n\\]\nFor Jacobi method, $\\bfA={\\bf D}(iag)-{\\bf L}(ower)-{\\bf U}(pper)$. Then\n\\[\n\\bfx = {\\bf D}^{-1}({\\bf L+U})\\bfx + {\\bf D}^{-1}{\\bf b}\n\\]\n\n\\subsection{The Gauss-Seidel Method}\n\\[\n\\bfx_i^{(k)} = \\frac{1}{a_{ii}}\\left[-\\sum_{j=1}^{i-1}(a_{ij}x_j^{(k)})-\\sum_{j=i+1}^{n}(a_{ij}x_j^{(k-1)})+b_i\\right]\n\\]\nThat is\n\\[\n\\bf (D-L)x^{(k)} = Ux^{(k-1)} + b\n\\]\nThen\n\\[\n\\bf x^{(k)} = (D-L)^{-1}Ux^{(k-1)} + (D-L)^{-1}b\n\\]\n\n\\subsection{General Iterative Methods}\nTo study the convergence of general iteration techniques, we need to analyze the formula.\n\\[\n\\bf x^{(k)} = Tx^{(k-1)}+c\n\\]\n\\begin{lemma}\nIf the spectral radius satisfies $\\rho({\\bf T})<1$, then $\\bf (I-T)^{-1}$ exists, and\n\\[\n\\bf (I-T)^{-1} = I+T+T^2+\\ldots=\\sum_{j=0}^\\infty T^j.\n\\]\n\\end{lemma}\n\\begin{theo}\nFor any $x^{(0)}\\in\\mathbb{R}^n$, the sequence $\\left\\{x^{(k)}\\right\\}_{k=0}^\\infty$ defined by\n\\[\n\\bf x^{(k)} = Tx^{(k-1)}+c,\\quad\\text{for each $k\\geq 1$}\n\\]\nconverges to the unique solution of $\\bf x=Tx+c$ if and only if $\\rho({\\bf T})<1$.\n\\end{theo}\n\\begin{coro}\nIf $\\|\\bf T\\|<1$ for any natural matrix\n\\begin{enumerate}[(i)]\n    \\item \\[\\bf \\|x-x^{(k)}\\|\\leq\\|T\\|^k\\|x^{(0)}-x\\|\\]\n    \\item \\[\\bf \\|x-x^{(k)}\\|\\leq\\frac{\\|T\\|^k}{1-\\|T\\|}\\|x^{(1)}-x^{(0)}\\|\\]\n\\end{enumerate}\n\\end{coro}\n\\begin{theo}[Stein-Rosenberg]\nIf $a_{ij}\\leq 0$, for each $i\\neq j$ and $a_{ii}>0$, for each $i=1,2,\\ldots$, then one and only one of the following statements holds\n\\begin{enumerate}[(i)]\n    \\item $0\\leq \\rho({\\bf T}_g)<\\rho({\\bf T}_j)<1$;\n    \\item $1\\leq \\rho({\\bf T}_j)<\\rho({\\bf T}_g)$;\n    \\item $\\rho({\\bf T}_j)=\\rho({\\bf T}_j)=0$;\n    \\item $\\rho({\\bf T}_j)=\\rho({\\bf T}_j)=1$.\n\\end{enumerate}\n\\end{theo}", "meta": {"hexsha": "52fdfb0a24e5e4aed8b9fb0d4faedaf22f23b582", "size": 2398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/7.3_The_jacobi_and_gauss-siedel_iterative_techniques.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/7.3_The_jacobi_and_gauss-siedel_iterative_techniques.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/7.3_The_jacobi_and_gauss-siedel_iterative_techniques.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": 38.6774193548, "max_line_length": 324, "alphanum_fraction": 0.5929941618, "num_tokens": 1026, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359805, "lm_q2_score": 0.8840392893839086, "lm_q1q2_score": 0.7696421815989193}}
{"text": "\\title{Maximum a Posteriori Estimation}\n\n\\subsection{Maximum a Posteriori Estimation}\n\nMaximum a posteriori (MAP) estimation is a form of approximate\nposterior inference. It uses the mode as a point estimate of the\nposterior distribution,\n\\begin{align*}\n  \\mathbf{z}_\\text{MAP}\n  &=\n  \\arg \\max_\\mathbf{z}\n  p(\\mathbf{z} \\mid \\mathbf{x})\\\\\n  &=\n  \\arg \\max_\\mathbf{z}\n  \\log p(\\mathbf{z} \\mid \\mathbf{x}).\n\\end{align*}\nIn practice, we work with logarithms of densities to avoid numerical underflow\nissues \\citep{murphy2012machine}.\n\nThe MAP estimate is the most likely configuration of the hidden patterns $\\mathbf{z}$\nunder the model. However, we cannot directly solve this optimization problem\nbecause the posterior is typically intractable. To circumvent this, we use Bayes' rule to\noptimize over the joint density,\n\\begin{align*}\n  \\mathbf{z}_\\text{MAP}\n  &=\n  \\arg \\max_\\mathbf{z}\n  \\log p(\\mathbf{z} \\mid \\mathbf{x})\\\\\n  &=\n  \\arg \\max_\\mathbf{z}\n  \\log p(\\mathbf{x}, \\mathbf{z}).\n\\end{align*}\nThis is valid because\n\\begin{align*}\n  \\log p(\\mathbf{z} \\mid \\mathbf{x})\n  &=\n  \\log p(\\mathbf{x}, \\mathbf{z}) - \\log p(\\mathbf{x})\\\\\n  &=\n  \\log p(\\mathbf{x}, \\mathbf{z}) - \\text{constant in terms of } \\mathbf{z}.\n\\end{align*}\nMAP estimation includes the common scenario of maximum\nlikelihood estimation as a special case,\n\\begin{align*}\n  \\mathbf{z}_\\text{MAP}\n  &=\n  \\arg \\max_\\mathbf{z}\n  p(\\mathbf{x}, \\mathbf{z})\\\\\n  &=\n  \\arg \\max_\\mathbf{z}\n  p(\\mathbf{x}\\mid \\mathbf{z}),\n\\end{align*}\nwhere the prior $p(\\mathbf{z})$ is flat, placing uniform probability over all\nvalues $\\mathbf{z}$ supports. Placing a nonuniform prior can be thought of as\nregularizing the estimation, penalizing values away from maximizing\nthe likelihood, which can lead to overfitting. For example, a normal\nprior or Laplace prior on $\\mathbf{z}$ corresponds to $\\ell_2$ penalization, also\nknown as ridge regression, and $\\ell_1$ penalization, also\nknown as the LASSO.\n\nMaximum likelihood is also known as cross entropy minimization. For a\ndata set $\\mathbf{x}=\\{x_n\\}$,\n\\begin{align*}\n  \\mathbf{z}_\\text{MAP}\n  &=\n  \\arg \\max_\\mathbf{z}\n  \\log p(\\mathbf{x}\\mid \\mathbf{z})\n  \\\\\n  &=\n  \\arg \\max_\\mathbf{z}\n  \\sum_{n=1}^N \\log p(x_n\\mid \\mathbf{z})\n  \\\\\n  &=\n  \\arg \\min_\\mathbf{z}\n  -\\frac{1}{N}\\sum_{n=1}^N \\log p(x_n\\mid \\mathbf{z}).\n\\end{align*}\nThe last expression can be thought of as an approximation to the cross\nentropy between the true data distribution and $p(\\mathbf{x}\\mid \\mathbf{z})$,\nusing a set of $N$ data points.\n\n\\subsubsection{Gradient descent}\n\nTo find the MAP estimate of the latent variables $\\mathbf{z}$, we use\nthe gradient of the log joint density\n\\begin{align*}\n  \\nabla_\\mathbf{z}\n  \\log p(\\mathbf{x}, \\mathbf{z})\n\\end{align*}\nand follow it to a (local) optima.\nEdward uses TensorFlow's automatic differentiation, making this gradient\ncomputation both simple and efficient to distribute.\n\nEdward currently does not support MAP for discrete latent variables.\nThis amounts to discrete optimization, which is difficult.\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": "ec9e85248a43edba7c94176c48630976db8f389f", "size": 3170, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/tutorials/map.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/map.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/map.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": 32.0202020202, "max_line_length": 89, "alphanum_fraction": 0.7119873817, "num_tokens": 1004, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392695254319, "lm_q2_score": 0.870597273444551, "lm_q1q2_score": 0.7696421776667535}}
{"text": "\\textbf{Consider the nonlinear initial value problem\n\\begin{align*}\nu_t=u_{xx}+e^u,~~~~x\\in [-1,1],~~t>0,~~u(\\pm 1,t)=u(x,0)=0,\n\\end{align*}\nfor the unknown function $u(x,t)$. To at least eight digits of accuracy, what is $u(0,3.5)$, and what is the time $t_5$ such that $u(0,t_5)=5$.\n}\n\\newline\n\nThe numerical scheme used in this problem is the following,\n\\begin{align*}\nu^{n+1}=u^{n}+\\Delta t\\left[Du^{n}+e^{u^{n}}\\right].\n\\end{align*}\nWe have obtained the solutions shown in figure 4 and the following results,\n\\begin{align*}\nt_5&=3.53594879,\\\\\nu(0,3.5)&=3.53878310.\n\\end{align*}\n\nIt is evident given the results that the solutions starts developing slowly but, because of the exponential non-linear term, it accelerates quickly. This can be appreciated by realizing that it takes the solution $t=3.5$ to reach the red curve, and only $t_5-3.5 = 0.03594879$ to get to the blue curve.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.9]{P3.png}\\caption{Numerical solution of the non-linear PDE at $t=3.5$ and at $t_5$, time when $u(0)=5$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Homework 4, Problem 3 - Francisco Castillo'\nclear all; close all; clc;\nlabelfontsize = 14;\nlinewidth = 2;\n\nN = 50;\ndt = 8e-1/N^3;\n[D,x] = cheb(N); % D:(N+1)x(N+1), x:(N+1)x1\nx = x(2:N);\nD2=D^2;\nD2 = D2(2:N,2:N);\nu = zeros(size(x));\nu35 = u;\nu0 = u(N/2);\ntobs = [3.5 100];\nt = 0;\nk=1;\nigraph = 1000;\ntstep = 0;\n\nwhile u0<5\n    if (t+dt>tobs(k))\n        dt=tobs(k)-t;\n        t=t+dt;\n        k=k+1;\n    else\n        t=t+dt;\n        dt = 8e-1/N^3;\n    end\n\n    u = u +dt*(D2*u+exp(u));\n    u0 = u(N/2);\n    tstep = tstep+1;\n    if t == tobs(1)\n        u35 = u;\n    end\n    if (mod(tstep,igraph)==0 || round(u0,10)>=5)\n        h1 = plot([1;x;-1],[0;u;0],'b*');\n        hold on\n        plot([1;x;-1],[0;u;0],'b')\n        if (u35~=0)\n            h2 = plot([1;x;-1],[0;u35;0],'r*');\n            plot([1;x;-1],[0;u35;0],'r')\n        end\n        grid on\n        axis([-1 1 0 5])\n        xlabel('$x$','interpreter','latex','fontsize',labelfontsize)\n        ylabel('$u(x,t)$','interpreter','latex','fontsize',labelfontsize)\n        hold off\n        shg\n    end\nend\nlegend([h1 h2],'$u(x,t_5)$', '$u(x,3.5)$','interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/P3','png')\n\\end{verbatim}", "meta": {"hexsha": "1989ad2021ccbf7e70e26802d906311e60f60839", "size": 2295, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SpectralMethods/Homework4/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SpectralMethods/Homework4/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SpectralMethods/Homework4/Latex/problem3.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": 27.987804878, "max_line_length": 302, "alphanum_fraction": 0.5864923747, "num_tokens": 867, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8840392741081575, "lm_q1q2_score": 0.769642171268019}}
{"text": "\\section{Local Likelihood}\n\nSuppose we have independent observation s\n$\\{ (\\bx_1,y_1),\\dots,(\\bx_n,y_n) \\}$ that are the\nrealization of a response random variable $Y$ given a \n$P \\times 1$ covariate vector $\\bx$ which we  consider to be\nknown. Given the \ncovariate $\\bx$, the  response variable $Y$\nfollows a parametric \ndistribution  \n$Y \\sim g(y; \\theta)$ where $\\theta$ is a function of $\\bx$. \nWe are interested in estimating $\\theta$ using the observed data. \n\nThe log-likelihood function can be written as  \n\\begin{equation}\n\\label{llf}\nl(\\theta_1,\\dots,\\theta_n) = \\sum_{i=1}^n \\log g(y_i; \\theta_i)\n\\end{equation}\nwhere $\\theta_i = s(\\bx_i)$. A standard modeling procedure\nwould assume \na parsimonious form  for \nthe $\\theta_i$s, say $\\theta_i = \\bx_i'\\bb$,\n$\\bb$ a $P \\times 1$ parameter vector. In this case the log-likelihood\n$l(\\theta_1,\\dots,\\theta_n)$ would be  a function of the\nparameter $\\bb$ that could be estimated by maximum\nlikelihood, that is by finding the $\\bbh$ that maximizes \n$l(\\theta_1,\\dots,\\theta_n)$. \n\nThe local likelihood approach is based on a more general assumption,\nnamely that  $s(\\bx)$ is a ``smooth'' function of the\ncovariate $\\bx$. \nWithout more restrictive assumptions, the maximum likelihood estimate of \n$\\bth=\\{s(\\bx_1),\\dots,s(\\bx_n)\\} $ is no\nlonger useful because of over-fitting. Notice for example that for the\ncase of regression with all the $\\bx_i$s distinct the maximum likelihood estimate  would simply\nreproduce the data. \n \nSuppose we are interested in estimating only\n$\\theta_{0} = \\theta(\\bx_0)$ for a fixed covariate value $\\bx_0$.   \nThe local likelihood estimation approach is to assume that \nthere is some neighborhood $N_0$ of covariates that are ``close''\nenough to\n$\\bx_0$ such that the\n data $\\{ (\\bx_i,y_i) ; \\bx_i \\in N_0\\}$ contain  \ninformation about $\\theta_0$ through some {\\sl link function} $\\eta$ of the\nform  \n\\begin{eqnarray}\n\\label{etadef}\n\\theta_0 &=& s(\\bx_0) \\equiv \\eta(\\bx_0, \\bb) \\mbox\n{ and }\\\\\n\\label{etadef2}\n\\theta_i &=& s(\\bx_i) \\approx \\eta(\\bx_i,\\bb), \\mbox\n{ for } \\bx_i \\in N_0 .\n\\end{eqnarray}\nNotice that we are abusing notation here since we are considering a\ndifferent $\\bb$ for every $\\bx_0$. Throughout the work we will be\nacting as if $\\theta_0$ is the only parameter of interest and\ntherefore not indexing variables that depend on the choice of\n$\\bx_0$. \n\nThe local likelihood estimate of $\\theta_0$ is obtained by \nassuming that, for data in $N_0$, the true distribution of the data,\n$g(y_i;\\theta_i)$ is approximated by\n\\begin{equation}\n\\label{approxdist}\nf(y_i;\\bx_i,\\bb) \\equiv  g(y_i; \\eta(\\bx_i,\\bb) ),\n\\end{equation}\nfinding the\n$\\bbh$ maximizes the\nlocal log-likelihood equation\n\\begin{equation}\n\\label{lle} %local likelihood equation\nl_0(\\bb) = \\sum_{\\bx_i \\in N_0} w_i \\, \\log f(y_i; \\bb),\n\\end{equation}\nand then using Equation (\\ref{etadef}) to obtain the local \nlikelihood estimate $\\hat{\\theta}_0$. Here $w_i$ is a weight\ncoefficient related to the ``distance'' between $\\bx_0$ and\n$\\bx_i$. In order to obtain\na useful estimate of $\\theta_0$, we need $\\bb$ to be of ``small''\nenough dimension so that we fit a parsimonious model within $N_0$.  \n\nHastie and Tibshirani (1987) \\nocite{hast:tibs:1987} discuss the case\nwhere the covariate $\\bx$ \nis a real \nvalued scalar and the link function is linear \n\\[\n\\eta(x_i, \\bb) = \\beta_0 + x_i \\beta_1\n\\]  \nNotice that in this case, the assumption being made is that the \nparameter function $s(x_i)$ is approximately linear within\n``small'' neighborhoods of $x_0$, i.e. locally linear.\n\nStaniswalis (1989) \\nocite{stan:1989} presents a similar approach. In\nthis case the \ncovariate $\\bx$ is  allowed to be a vector, and the link function\nis a constant\n\\[\n\\eta(\\bx_i, \\beta) = \\beta\n\\]\nThe assumption being made here is that the \nparameter function $s(x_i)$ is locally constant.\n\nIf we assumes a density function \nof the form\n\\begin{equation}\n\\label{loess}\n\\log g(y_i; \\theta_i) = C  + (y_i - \\theta_i)^2 / \\phi\n\\end{equation}\nwhere $K$ and $\\phi$ are constants that do not depend on the\n$\\theta_i$s,\nlocal regression may be considered a special case of local\nlikelihood estimation.\n\nNotice that in this case the local likelihood estimate is going to be\nequivalent to the estimate obtained by \nminimizing a sum of squares equation. The approach in\nCleveland (1979) \\nocite{clev:1979} and Cleveland and Devlin (1988)\n\\nocite{clev:devl:1988} is to consider a real valued covariate \nand the polynomial link function\n\\[\n\\eta(\\bx_i,\\bb) = \\sum_{j=0}^d x_i^j \\beta_j.\n\\]\n\nIn general, the approach of local likelihood estimation, including the\nthree above-mentioned examples, is to assume that \nfor ``small'' neighborhoods around $\\bx_0$, the distribution of\nthe data is approximated by a distribution that depends on a constant\nparameter $\\bb(\\bx_0)$, i.e. we have locally parsimonious models. This\nallows us to  \nuse the usual estimation technique of maximum likelihood. However, in\nthe local version of maximum likelihood we often\nhave an a priori belief that points  \n``closer'' to $\\bx_0$ contain more information about\n$\\theta_0$, which suggest a weighted approach. \n\nThe asymptotic theory presented in, for example,  Staniswalis (1989)\n\\nocite{stan:1989} and \nLoader (1986) \\nocite{load:1996} is developed under the assumption that \nas the size (or radius) of some neighborhood of the covariate of\ninterest $\\bx_0$ tends to 0, the difference between the true and\napproximating distributions within such neighborhood becomes\nnegligible. Furthermore, we assume that despite the fact that the\nneighborhoods become arbitrarily small, the\nnumber of data points in the neighborhood somehow tends to $\\infty$. \nThe idea is that, asymptotically, the behavior of the\ndata within a given neighborhood, is like the  one assumed in\nclassical asymptotic theory for non-IID data: The small window size\nassure that the difference between the true and approximating models is\nnegligible and the large number of independent observations is\navailable\nto estimate a parameter of fixed dimension that completely specifies\nthe joint distribution. This concept motivates the\napproach taken in the following sections to derive a model selection\ncriteria. \n\n", "meta": {"hexsha": "6c8b4d4c6e98210d5447ee10727fc484c050dc54", "size": 6191, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-08-02.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-08-02.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-08-02.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 39.6858974359, "max_line_length": 95, "alphanum_fraction": 0.7467291229, "num_tokens": 1762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.769642165485926}}
{"text": "\\include{config/config}\n\n\\begin{document}\n% ========== Edit your name here\n\\title{MATH 2901 Basic Probability Lecture Notes 1}\n\\author{Instructor: Richard Kleeman}\n\\date{}\n\\maketitle\n\n%\\medskip\n\n% ========== Contents begin here ==============\n\\section{Event as sets}\nProbability studies the \\emph{repeatable (or ideal) experiments}. The result of an experiment is called an \\emph{outcome}.\n\n\\begin{definition}\nThe set of all possible outcomes of an experiment is called the \\textbf{sample space} and is denoted by $\\Omega$.  \n\\end{definition}\n\n\\subsection{Cardinality of sets}\nThe cardinality of a set $\\Omega$ refers to the number of the number of elements in this set, and is denoted by $\\card(\\Omega)$ or $\\abs{\\Omega}$.\n\\begin{itemize}\n    \\item For finite sets, $\\card(\\Omega)$ is a natural number.\n    \\item For the integer set, $\\card(\\Z) = \\aleph_0$, which is countable.\n    \\item For the real number set, $\\card(\\R) = \\aleph_1 > \\aleph_0$.\n\\end{itemize}\nThe \\emph{power set} of a set $\\Omega$ is the set of all subsets, which is denoted by $2^\\Omega$.\n\\begin{itemize}\n    \\item For $\\Z$, $\\card(2^\\Z) = \\aleph_1 = \\card(\\R)$.\n\\end{itemize}\n\nIn practical, sets in probability are: \\textbf{finite, countable, reals} and \\textbf{their variants}.\n\nWhen we conduct an experiment, we want to know whether a subset occurs or not. For example, if we take a number from $\\R$, the probability will be 0 because $\\card(\\R)$ is very large. Therefore,\n\\begin{center}\n\\emph{we are interested in $A \\subset \\Omega$ in probability, where $A$ is a collection of subsets in probability.}\n\\end{center}\n\n\\subsection{Events and fields}\n\\begin{definition}\nThe \\textbf{events} are subsets of the sample space $\\Omega$. \n\\end{definition}\n\n\\begin{remark}\n$\\varnothing$ is called the \\emph{impossible event}. The set $\\Omega$ is called the \\emph{certain event}. Events $A$ and $B$ are called \\emph{disjoint} if their intersection is the empty set.\n\\end{remark}\n\nWe do \\textbf{NOT} need all the subsets of $\\Omega$ be events. It suffices for us to think of the collection of events as a subcollection $\\mathcal{F}$ of the set of all subsets of $\\Omega$.\n\\begin{definition}\nAny collection $\\mathcal{F}$ of subsets of $\\Omega$ which satisfies the following three conditions is called a field:\n\\begin{enumerate}[(a)]\n    \\item if $A, B \\in \\mathcal{F}$, then $A \\cup B \\in \\mathcal{F}$ and $A \\cap B \\in \\mathcal{F}$ (actually $A\\cap B \\in \\mathcal{F}$ is redundant); \n    \\item if $A \\in \\mathcal{F}$, then $A^c \\in \\mathcal{F}$;\n    \\item the empty set $\\varnothing$ belongs to $\\mathcal{F}$.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\nSome implications from the properties of a filed $\\mathcal{F}$:\n\\begin{itemize}\n    \\item if $A_1, \\dots, A_n \\in \\mathcal{F}$, then $\\bigcup_{i=1}^n A_i \\in \\mathcal{F}$;\n    \\item $\\varnothing^C = \\Omega \\in \\mathcal{F}$;\n    \\item $A \\cap B = (A^c \\cup B^c)^C \\in \\mathcal{F}$.\n\\end{itemize}\n\\end{remark}\n\n\\begin{question}\nwhat if we have an $\\Omega$ such that $\\card(\\Omega) = \\aleph_0$? In this case, we may need $2^\\Omega$ to study the probability. \n\\end{question}\n\n\\begin{definition}\nA collection $\\mathcal{F}$ of subsets of $\\Omega$ is called a $\\sigma$-field if it satisfies the following conditions: \n\\begin{enumerate}[(a)]\n    \\item $\\varnothing \\in \\mathcal{F}$;\n    \\item if $A \\in \\mathcal{F}$, then $A^c \\in \\mathcal{F}$;\n    \\item if $A_1, A_2, \\dots \\in \\mathcal{F}$, then $\\bigcup_{i=1}^\\infty A_i \\in \\mathcal{F}$.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{remark}\n$\\sigma$-fields are closed under the operation of taking countable intersections.\n\\end{remark}\n\n\\begin{example}\nThe smallest $\\sigma$-field associated with $\\Omega$ is the collection $\\mathcal{F} = \\{\\varnothing, \\Omega \\}$.\n\\end{example}\n\n\\begin{example}\nIf $A \\subset \\Omega$, then $\\mathcal{F} = \\{\\varnothing, A, A^c, \\Omega \\}$ is a $\\sigma$-field. \n\\end{example}\n\n\\begin{example}\nThe power set of $\\Omega$ is a $\\sigma$-field.\n\\end{example}\n\nWith any experiment we may associate a pair $\\{\\Omega, \\mathcal{F}\\}$, where $\\Omega$ is the set of all possible outcomes or elementary events and $\\mathcal{F}$ is a $\\sigma$-field of subsets of $\\Omega$ which contains \\emph{all the events in whose occurrences we may be interested}; henceforth, to call a set $A$ an event is equivalent to asserting that $A$ belongs to the $\\sigma$-field in question. \n\n\n\\section{Probability}\nAssume we have a ``repeatable\" experiment and we repeat the experiment a large number $N$ of times. Let $A \\in \\Omega$ and $N(A)$ be the number of $A$ occurs in the $N$ trails. Intuitively, the ratio $N(A)/ N$ appears to converge to a constant limit as $N$ increases. In practice, we have \n\\begin{itemize}\n    \\item $0 \\leq N(A)/ N \\leq 1$;\n    \\item if $A, B$ are disjoint, then $N(A \\cup B) = N(A) + N(B)$. (finite additive and countably additive)\n\\end{itemize}\n\n\\begin{definition}\nA \\textbf{probability measure} $\\Prob$ on $\\{ \\Omega, \\mathcal{F} \\}$ is a function $\\Prob : \\mathcal{F} \\to [0,1]$ satisfying\n\\begin{enumerate}[(a)]\n    \\item $\\Prob(\\varnothing) = 0$;\n    \\item $\\Prob(\\Omega) = 1$;\n    \\item  if $A_1, A2, \\dots$ is a collection of disjoint members of $\\mathcal{F}$, in that $A_i \\cap A_j = \\varnothing$ for all pairs $i, j$ satisfying $i \\neq j$, then\n    \\begin{equation*}\n        \\Prob\\left( \\bigcup_{i=1}^\\infty A_i \\right) = \\sum_{i=1}^\\infty \\Prob (A_i).\n    \\end{equation*}\n\\end{enumerate}\n\\end{definition}\nThe triple $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$, comprising a set $\\Omega$, a $\\sigma$-field $\\mathcal{F}$ of subsets of $\\Omega$, and a probability measure $\\Prob$ on $\\{\\Omega, \\mathcal{F}\\}$, is called a \\textbf{probability space}. We can associate a probability space $\\{ \\Omega, \\mathcal{F}, \\Prob \\}$ with any experiment, and all questions associated with the experiment can be reformulated in terms of this space. \n\n\\begin{remark}\nA probability measure is a special example of what is called a \\emph{measure} on the pair $\\{\\Omega, \\mathcal{F}\\}$. A measure is a function $\\mu: \\mathcal{F} \\to [0, \\infty)$ satisfying $\\mu(\\varnothing) = 0$ together with (c) above. A measure $\\mu$ is a probability measure if $\\mu(\\Omega) = 1$. \n\\end{remark}\n\n\\begin{lemma}\nWe can deduce some lemmas from the definition.\n\\begin{enumerate}[(a)]\n    \\item $\\Prob(A^c) = 1 - \\Prob(A)$;\n    \\item if $A \\subseteq B$, then $\\Prob(B) = \\Prob(A) + \\Prob(B\\backslash A) \\geq \\Prob(A)$;\n    \\item $\\Prob(A \\cup B) = \\Prob(A) + \\Prob(B) - \\Prob(A \\cap B)$;\n    \\item more generally, if $A_1, A_2, \\dots, A_n$ are events, then \n    \\begin{equation*}\n        \\begin{split}\n        \\Prob\\left( \\bigcup_{i=1}^n A_i \\right) =& \\sum_{i}\\Prob(A_i) - \\sum_{i < j} \\Prob(A_i \\cap A_j) + \\sum_{i<j<k} \\Prob(A_i \\cap A_j \\cap A_k) - \\cdots \\\\\n        & +(-1)^{n+1} \\Prob(A_1 \\cap A_2 \\cap \\cdots \\cap A_n)\n        \\end{split}\n    \\end{equation*}\n\\end{enumerate}\n\\end{lemma}\n\n\\begin{lemma}\nLet $A_1, A_2, \\dots$ be an increasing sequence of events, so that $A_1 \\subset A_2 \\subset A_3 \\subset \\cdots$, and write $A$ for their limit:\n\\begin{equation*}\n    A = \\bigcup_{i=1}^\\infty A_i = \\lim_{i \\to \\infty} A_i.\n\\end{equation*}\nThen $\\Prob(A) = \\lim_{i\\to\\infty} \\Prob(A_i)$. \n\nSimilarly, if $B_1, B_2, \\dots$ is a decreasing sequence of events, so that $B_1 \\supseteq  B_2 \\supseteq B_3 \\supseteq \\cdots$, then \n\\begin{equation*}\n    B = \\bigcap_{i=1}^\\infty B_i = \\lim_{i \\to \\infty} B_i\n\\end{equation*}\nsatisfies $\\Prob(B) = \\lim_{i\\to\\infty} \\Prob(B_i)$\n\\end{lemma}\n\n\n\\section{Some useful concepts}\n\\subsection{Conditional probability}\nWhat if we only care how many times does $A$ occur only when $B$ occurs? $N(A\\cap B) / N(B)$, the universe is changed. \n\\begin{definition}\nIf $\\Prob(B) > 0$, then the \\textbf{conditional probability} that $A$ occurs given that $B$ occurs is defined to be\n\\begin{equation*}\n    \\Prob(A \\spacevert B) = \\frac{\\Prob(A \\cap B)}{\\Prob(B)}.\n\\end{equation*}\n\\end{definition}\n\n\\begin{definition}\nSuppose $\\{B_i\\}$ is a finite set. If $B_i$ are all disjoint and $\\bigcup_{i=1}^n B_i = \\Omega$, then $\\{B_i\\}$ is called a \\textbf{partition} of $\\Omega$.\n\\end{definition}\n\n\\begin{lemma}\nFor any events $A$ and $B$ such that $0 < \\Prob(B) < 1$,\n\\begin{equation*}\n    \\Prob(A) = \\Prob(A \\spacevert B) \\Prob(B) + \\Prob(A \\spacevert B^c) \\Prob(B^c).\n\\end{equation*}\nMore generally, let $B_1,  B_2, \\dots, B_n$ be a partition of $\\Omega$ such that $\\Prob(B_i) > O$ for all $i$. Then \n\\begin{equation*}\n    \\Prob(A) = \\sum_i \\Prob(A \\spacevert B_i) \\Prob(B_i).\n\\end{equation*}\n\\end{lemma}\n\n\\subsection{Independence}\nIntuition: an event $A$ occurs doesn't affect the probability of $A$ occurs when $B$ occurs, which means $\\Prob(A) = \\Prob(A\\spacevert B)$.\n\n\\begin{definition}\nEvents $A$ and $B$ are called \\textbf{independent} if \n\\begin{equation*}\n    \\Prob(A \\cap B) = \\Prob(A) \\Prob(B).\n\\end{equation*}\nMore generally, a family $\\{A_i \\spacevert i \\in I\\}$ is called independent if\n\\begin{equation*}\n    \\Prob \\left( \\bigcap_{i \\in J} A_i \\right) = \\prod_{i\\in J} \\Prob(A_i)\n\\end{equation*}\nfor all finite subsets $J$ of $I$. \n\\end{definition}\n\n\\begin{caution}\nA common \\emph{student error} is to make the fallacious statement that $A$ and $B$ are independent if $A \\cap B = \\varnothing$.\n\\end{caution}\n\n\\begin{remark}\nIf the family $\\{A_i \\spacevert i \\in I\\}$ has the property that \nfor all \n\\begin{equation*}\n    \\Prob(A_i \\cap A_j) = \\Prob(A_i) \\Prob(A_j) \\quad \\forall i\\neq j, \n\\end{equation*}\nthen it is called \\emph{pairwise independent}. \\textbf{Pairwise-independent families are not necessarily independent.} \n\\end{remark}\n\n\\section{Completeness and product space}\n\\begin{lemma}\nIf $\\mathcal{F}$ and $\\mathcal{G}$ are two $\\sigma$-fields of subsets of $\\Omega$, then their intersection $\\mathcal{F} \\cap \\mathcal{G}$ is a $\\sigma$-field also. More generally, if $\\{ \\mathcal{F}_i \\spacevert  i \\in I \\}$ is a family of $\\sigma$-fields of subsets of $\\Omega$, then $\\mathcal{G} = \\bigcap_{i\\in I} \\mathcal{F}_i $ is a $\\sigma$-field also. \n\\end{lemma}\n\n\\begin{newnotion}{Completeness}\nLet $\\{\\Omega, \\mathcal{F}, \\Prob\\}$ be a probability space. Any event $A$ which has zero probability, that is $\\Prob(A) = 0$, is called \\emph{null}. It may seem reasonable to suppose that any subset $B$ of a null set $A$ will itself be null, but this may be without meaning since $B$ may not be an event, and thus $\\Prob(B)$ may not be defined. \n\\end{newnotion}\n\n\\begin{definition}\nA probability space $\\{\\Omega, \\mathcal{F}, \\Prob\\}$ is called \\textbf{complete} if all subsets of null sets are events. \n\\end{definition}\n\nAny incomplete space can be completed thus. Let $\\mathcal{N}$ be the collection of all subsets of null sets in $\\mathcal{F}$ and let $\\mathcal{G} = \\sigma (\\mathcal{F} \\cup \\mathcal{N})$ be the smallest $\\sigma$-field which contains all sets in $\\mathcal{F}$ \nand $\\mathcal{N}$. It can be shown that the domain of $\\Prob$ may be extended in an obvious way from $\\mathcal{F}$ to $\\mathcal{G}$; $\\{\\Omega, \\mathcal{G}, \\Prob\\}$ is called the completion of $\\{\\Omega, \\mathcal{F}, \\Prob\\}$. \n\n\\begin{newnotion}{Product space}\nSuppose two experiments have associated probability spaces $\\{ \\Omega_1, \\mathcal{F}_1, \\Prob_1 \\}$ and  $\\{ \\Omega_2, \\mathcal{F}_2, \\Prob_2 \\}$ respectively. The sample space of the pair of experiments, considered jointly, is the collection $\\Omega_1 \\times \\Omega_2 = \\{ (\\omega_1 , \\omega_2) \\spacevert w_1 \\in \\Omega_1, \\omega_2 \\in \\Omega_2 \\}$ of ordered pairs. The appropriate $\\sigma$-field of events is \\textbf{more complicated} to construct. \\textbf{The family of all such sets, $\\mathcal{F}_1 \\times \\mathcal{F}_2 = \\{A_1 \\times A_2 \\spacevert A_1 \\in \\mathcal{F}_1 , A_1 \\in \\mathcal{F}_2 \\}$, is NOT in general a $\\sigma$-field.}\n\\end{newnotion}\n\n\\begin{remark}\nThere exists a unique smallest $\\sigma$-field $\\mathcal{G} = \\sigma(\\mathcal{F}_1 \\times \\mathcal{F}_2)$ of subsets of $\\Omega_1 \\times \\Omega_2$ which contains $\\mathcal{F}_1 \\times \\mathcal{F}_2$. All we require now is a suitable probability function on $( \\Omega1 \\times \\Omega_2, \\mathcal{G} )$. Let $\\Prob_{12}: \\mathcal{F}_1 \\times \\mathcal{F}_2 \\to [0, 1]$ be given by: \n\\begin{equation*}\n    \\Prob(A_1 \\times A_2) = \\Prob_1(A_1) \\times \\Prob_2(A_2) \\quad \\text{for $A_1 \\in \\mathcal{F}_1, A_2 \\in \\mathcal{F}_2$}.\n\\end{equation*}\nIt can be shown that the domain of $\\Prob_{12}$ can be extended from $\\mathcal{F}_1 \\times \\mathcal{F}_2$ to the whole of $\\mathcal{G} = \\sigma(\\mathcal{F}_1 \\times \\mathcal{F}_2)$.\n\\end{remark}\n\n\\begin{definition}\nThe probability space $(\\mathcal{F}_1 \\times \\mathcal{F}_2, \\mathcal{G}, \\Prob_{12})$ is called the \\textbf{product space} of $(\\Omega_1, \\mathcal{F}_1, \\Prob_1)$ and  $(\\Omega_2, \\mathcal{F}_2, \\Prob_2)$. The measure $\\Prob_{12}$ is sometimes called the `product measure'. \n\\end{definition}\n\n\n\\end{document}\n", "meta": {"hexsha": "4d2be2d33791dac94acf3ae87ccae7e84cf7844c", "size": 12785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "_drafts/MATH 2901/notes_1.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_1.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_1.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": 53.0497925311, "max_line_length": 643, "alphanum_fraction": 0.6786859601, "num_tokens": 4268, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7696201835823856}}
{"text": "\\chapter[Finite differences for parabolic problems]{Finite differences for \\\\\nparabolic problems in 1D}\nConsider the following \\emph{initial-boundary value problem} for~$u=u(x,t)$,\n\\begin{equation}\\label{eq: heat ivp 1d}\n\\begin{aligned}\nu_t-au_{xx}&=f(x,t)&&\\text{for $0<x<L$ and $0<t<T$,}\\\\\nu&=\\gamma_0(t)&&\\text{at $x=0$, for $0<t<T$,}\\\\\nu&=\\gamma_L(t)&&\\text{at $x=L$, for $0<t<T$,}\\\\\nu&=u_0(x)&&\\text{for $0<x<L$ when $t=0$,}\n\\end{aligned}\n\\end{equation}\nwhere $u_t=\\partial u/\\partial t$ and $u_{xx}=\\partial^2u/\\partial x^2$.  For \nsimplicity, we assume that the coefficient~$a$ is a positive constant.  The \nproblem~\\eqref{eq: heat ivp 1d} provides a model of heat conduction in 1D, \nwhere $u(x,t)$ is the temperature at position~$x$ and time~$t$.  The \ncoefficient~$a>0$ is the \\emph{thermal conductivity}: the value of~$a$ will be \nlarge for a material that conducts heat well, but small for a \nmaterial that conducts heat poorly (that is, for a thermal insulator).  The \n\\emph{source term}~$f(x,t)$ gives the density of any heat sources in the \nmaterial, the \\emph{boundary conditions} specify the temperatures $\\gamma_0$~and \n$\\gamma_L$ at the two edges of the spatial domain~$[0,L]$, and the \n\\emph{initial condition} gives the temperature field~$u_0(x)$ when~$t=0$.  In \nthis 1D model, the temperature does not vary in the $y$~and $z$ directions.\n\n\\section{Separation of variables}\\label{sec: separation}\n\nLet\n\\[\n\\gamma(x,t)=\\frac{1}{L}\\bigl((L-x)\\gamma_0(t)+x\\gamma_L(t)\\bigr),\n\\]\nso that\n\\[\n\\gamma(0,t)=\\gamma_0(t)\\quad\\text{and}\\quad\\gamma(L,t)=\\gamma_L(t),\n\\]\nwith\n\\[\n\\gamma_t-a\\gamma_{xx}=\\frac{1}{L}\\bigl((L-x)\\gamma_0'(t)+x\\gamma_L'(t)\\bigr).\n\\]\nThus, the difference $v=u-\\gamma$ satisfies \n\\begin{equation}\\label{eq: heat ivp homog 1d}\n\\begin{aligned}\nv_t-av_{xx}&=g(x,t)&&\\text{for $0<x<L$ and $0<t<T$,}\\\\\nv&=0&&\\text{at $x=0$, for $0<t<T$,}\\\\\nv&=0&&\\text{at $x=L$, for $0<t<T$,}\\\\\nv&=v_0(x)&&\\text{for $0<x<L$ when $t=0$,}\n\\end{aligned}\n\\end{equation}\nwhere \n\\[\ng(x,t)=f(x,t)-\\gamma_t(x,t)\n\\quad\\text{and}\\quad\nv_0(x)=u_0(x)-\\gamma(x,0).\n\\]\nIn this way, it suffices to solve a problem with \\emph{homogeneous} boundary \nconditions.\n\n\nAssociated with the time-dependent problem~\\eqref{eq: heat ivp homog 1d} is the \nSturm--Liouville \\emph{eigenproblem},\n\\begin{equation}\\label{eq: simple eigenproblem}\n-a\\phi''=\\lambda\\phi\\quad\\text{for $0<x<L$,}\n\t\\quad\\text{with $\\phi(0)=0=\\phi(L)$,}\n\\end{equation}\nwhich has only the trivial solution~$\\phi(x)\\equiv0$ unless $\\lambda$ is one of \nthe \\emph{eigenvalues} \n\\[\n\\lambda_n=a\\biggl(\\frac{n\\pi}{L}\\biggr)^2\\quad\\text{for $n\\in\\{1,2,3,\\ldots\\}$.}\n\\]\nWhen $\\lambda=\\lambda_n$, the solution~$\\phi$ is a constant multiple of the \ncorresponding \\emph{eigenfunction}\n\\[\n\\phi_n(x)=\\sin\\frac{n\\pi}{L}\\,x.\n\\]\nThe eigenfunctions are \\emph{orthogonal} with respect to the \n\\emph{inner product}\n\\[\n\\langle f,g\\rangle=\\int_0^Lf(x)g(x)\\,dx,\n\\]\nthat is,\n\\[\n\\langle\\phi_n,\\phi_k\\rangle=0\\quad\\text{if $n\\ne k$,}\n\\]\nand their 2-norms are given by\n\\[\n\\|\\phi_n\\|^2=\\langle\\phi_n,\\phi_n\\rangle=\\frac{L}{2}.\n\\]\n\nGiven a square-integrable function~$f(x)$, we define the \n\\emph{Fourier sine coefficients}\n\\[\n\\hat f_n=\\frac{\\langle f,\\phi_n\\rangle}{\\|\\phi_n\\|^2}\n    =\\frac{2}{L}\\int_0^Lf(x)\\sin\\biggl(\\frac{n\\pi}{L}\\,x\\biggr)\\,dx\n    \\quad\\text{for $n\\in\\{1,2,3,\\ldots\\}$.}\n\\]\nThe \\emph{completeness} of the eigenfunctions means that the Fourier sine series\n\\[\nSf(x)=\\sum_{n=1}^\\infty\\hat f_n\\sin\\frac{n\\pi}{L}\\,x\n\\]\nconverges to~$f(x)$ in the \\emph{mean-square sense}.  The Fourier coefficients \nof~$v(x,t)$ are functions of~$t$,\n\\[\n\\hat v_n(t)=\\langle v(\\cdot,t),\\phi_n\\rangle\n    =\\frac{2}{L}\\int_0^Lv(x,t)\\sin\\biggl(\\frac{n\\pi}{L}\\,x\\biggr)\\,dx,\n\\]\nand formal term-by-term differentiation of the Fourier expansion of~$v$ gives\n\\[\nv_t(x,t)=\\frac{\\partial}{\\partial t}\\sum_{n=1}^\\infty\\hat v_n(t)\\phi_n(x)\n    =\\sum_{n=1}^\\infty\\frac{d\\hat v_n}{dt}\\,\\phi_n(x).\n\\]\nSince $\\phi=\\phi_n$ satisfies \\eqref{eq: simple eigenproblem} \nwith~$\\lambda=\\lambda_n$,\n\\[\n-av_{xx}=-a\\,\\frac{\\partial^2}{\\partial x^2}\n    \\sum_{n=1}^\\infty\\hat v_n(t)\\phi_n(x)\n    =\\sum_{n=1}^\\infty\\hat v_n(t)\\bigl(-a\\phi_n''(x)\\bigr)\n    =\\sum_{n=1}^\\infty\\hat v_n(t)\\bigl(\\lambda_n\\phi_n(x)\\bigr),\n\\]\nand so\n\\[\nv_t-av_{xx}=\\sum_{n=1}^\\infty\n\t\\biggl(\\frac{d\\hat v_n}{dt}+\\lambda_n\\hat v_n\\biggr)\\phi_n(x),\n\\]\nwhich equals $g(x,t)$ if and only if all of the Fourier coefficients match, \nthat is,\n\\[\n\\frac{d\\hat v_n}{dt}+\\lambda_n\\hat v_n=\\hat g_n(t)\n    \\quad\\text{for $0<t<T$ and $n\\in\\{1,2,3,\\ldots\\}$.}\n\\]\nMultiplying both sides of this linear, first-order ODE by the \n\\emph{integrating factor}~$e^{\\lambda_n t}$ we obtain\n\\[\ne^{\\lambda_nt}\\,\\frac{d\\hat v_n}{dt}+\\lambda_ne^{\\lambda_nt}\\hat v_n\n\t=e^{\\lambda_nt}\\hat g_n(t),\n\\]\nand since the left-hand side equals $(d/dt)(e^{\\lambda_nt}\\hat v_n)$ it \nfollows that\n\\[\ne^{\\lambda_nt}\\hat v_n(t)-\\hat v_n(0)=\\int_0^te^{\\lambda_ns}\\hat g_n(s)\\,ds.\n\\]\nThus,\n\\begin{equation}\\label{eq: Duhamel n}\n\\hat v_n(t)=\\hat v_n(0)e^{-\\lambda_nt}\n\t+\\int_0^te^{-\\lambda_n(t-s)}\\hat g_n(s)\\,ds\\quad\\text{for $t\\ge0$,}\n\\end{equation}\nand multiplying both sides by~$\\phi_n(x)$ and summing over~$n$, we obtain the\nseries representation\n\\[\nv(x,t)=\\sum_{n=1}^\\infty\\hat v_n(t)\\phi_n(x)\n\t=\\sum_{n=1}^\\infty e^{-\\lambda_nt}\\hat v_n(0)\\phi_n(x)\n\t+\\int_0^t\\sum_{n=1}^\\infty e^{-\\lambda_n(t-s)}\\hat g_n(s)\\phi_n(x)\\,ds.\n\\]\n\nDefine the differential operator~$\\mathcal{A}v=-v''$ so that \n$\\mathcal{A}\\phi_n=\\lambda_n\\phi_n$, and then define the linear \noperator~$e^{-t\\mathcal{A}}$ by\n\\[\n(e^{-t\\mathcal{A}}v)(x)=\\sum_{n=1}^\\infty e^{-\\lambda_nt}\\hat v_n\\phi_n(x).\n\\]\nIn particular, this definition means that\n\\[\ne^{-t\\mathcal{A}}\\phi_n=e^{-\\lambda_nt}\\phi_n\n\t\\quad\\text{for $n\\in\\{1,2,3,\\ldots\\}$,}\n\\]\nand\n\\[\n\\sum_{n=1}^\\infty e^{-\\lambda_nt}\\hat v_n(0)\\phi_n(x)=e^{-t\\mathcal{A}}v_0(x)\n\\]\nwith\n\\[\n\\sum_{n=1}^\\infty e^{-\\lambda_n(t-s)}\\hat g_n(s)\\phi_n(x)\n\t=e^{-(t-s)\\mathcal{A}}g(x,s),\n\\]\nso \\eqref{eq: Duhamel n} can be written more succinctly as\n\\[\nv(x,t)=e^{-t\\mathcal{A}}v_0(x)+\\int_0^te^{-(t-s)\\mathcal{A}}g(x,s)\\,ds.\n\\]\nThis representation of~$v$ is known as the \\emph{Duhamel formula}, and the \nsolution of our original problem~\\eqref{eq: heat ivp 1d} is then given by\n\\[\nu(x,t)=\\gamma(x,t)+v(x,t)\\quad\\text{for $0\\le x\\le L$ and $0\\le t\\le T$.}\n\\]\n\n\\section{Semidiscrete method}\n\nWe define a uniform grid on the spatial interval~$[0,L]$,\n\\[\nx_p=p\\,\\Delta x\\quad\\text{for $0\\le p\\le P$,}\n\t\\quad\\text{with $\\Delta x=\\frac{L}{P}$,}\n\\]\nand let\n\\[\nU_p(t)\\approx u(x_p,t),\\qquad f_p(t)=f(x_p,t),\\qquad u_{0p}=u_0(x_p).\n\\]\nSince $u_t(x_p,t)\\approx dU_p/dt$ and\n\\[\nu_{xx}(x_p,t)\\approx\\frac{u(x_{p+1},t)-2u(x_p,t)+u(x_{p-1},t)}{\\Delta x^2}\n\t\\approx\\frac{U_{p+1}(t)-2U_p(t)+U_{p-1}(t)}{\\Delta x^2},\n\\]\nwe formulate the following semidiscrete approximation to the initial-boundary \nvalue problem~\\eqref{eq: heat ivp 1d},\n\\begin{equation}\\label{eq: semidiscrete heat 1d}\n\\begin{aligned}\n\\frac{dU_p}{dt}-a\\,\\frac{U_{p+1}-2U_p+U_{p-1}}{\\Delta x^2}&=f_p(t)&\n\t&\\text{for $1\\le p\\le P-1$ and $0<t<T$,}\\\\\nU_0&=\\gamma_0(t)&&\\text{for $0<t<T$,}\\\\\nU_P&=\\gamma_P(t)&&\\text{for $0<t<T$,}\\\\\nU_p&=u_{0p}&&\\text{for $1\\le p\\le P-1$ when $t=0$.}\n\\end{aligned}\n\\end{equation}\nThis system can be written in matrix-vector notation as\n\\begin{equation}\\label{eq: ODE system}\n\\frac{d\\boldsymbol{U}}{dt}+\\boldsymbol{A}\\boldsymbol{U}=\\boldsymbol{f}(t)\n\t+\\boldsymbol{g}(t),\n\\end{equation}\nwhere\n\\[\n\\boldsymbol{A}=\\frac{a}{\\Delta x^2}\\begin{bmatrix}\n 2&    -1&      &      &\\\\\n-1&     2&    -1&      &\\\\\n  &\\ddots&\\ddots&\\ddots&\\\\\n  &      &    -1&     2&-1\\\\\n  &      &      &    -1& 2\\end{bmatrix},\\qquad\n\\]\nand\n\\begin{equation}\\label{eq: U f g semidiscrete 1d}\n\\boldsymbol{U}(t)=\\begin{bmatrix}\nU_1(t)\\\\ U_2(t)\\\\ \\vdots\\\\ U_{P-2}(t)\\\\ U_{P-1}(t)\\end{bmatrix},\\qquad\n\\boldsymbol{f}(t)=\\begin{bmatrix}\nf_1(t)\\\\ f_2(t)\\\\ \\vdots\\\\ f_{P-2}(t)\\\\ f_{P-1}(t)\\end{bmatrix},\\qquad\n\\boldsymbol{g}(t)=\\frac{a}{\\Delta x^2}\\begin{bmatrix}\n\\gamma_0(t)\\\\ 0\\\\ \\vdots\\\\ 0\\\\ \\gamma_L(t)\\end{bmatrix}.\n\\end{equation}\nRecall that for any square matrix~$\\boldsymbol{A}$, the matrix exponential\nis defined by the convergent infinite series\n\\[\ne^{\\boldsymbol{A}}=\\sum_{k=0}^\\infty\\frac{\\boldsymbol{A}^n}{n!}\n\t=\\boldsymbol{I}+\\boldsymbol{A}+\\frac{\\boldsymbol{A}^2}{2!}\n\t+\\frac{\\boldsymbol{A}^3}{3!}+\\cdots.\n\\]\nFurthermore,\n\\[\n\\frac{d}{dt}\\,e^{t\\boldsymbol{A}}=\\boldsymbol{A}e^{t\\boldsymbol{A}},\n\\]\nso $e^{t\\boldsymbol{A}}$ provides an integrating factor \nfor~\\eqref{eq: ODE system}:\n\\[\n\\frac{d}{dt}\\bigl(e^{t\\boldsymbol{A}}\\boldsymbol{U}\\bigr)\n\t=\\boldsymbol{A}e^{t\\boldsymbol{A}}\\boldsymbol{U}\n\t+e^{t\\boldsymbol{A}}\\,\\frac{d\\boldsymbol{U}}{dt}\n\t=e^{t\\boldsymbol{A}}\\biggl(\\frac{d\\boldsymbol{U}}{dt}\n\t+\\boldsymbol{A}\\boldsymbol{U}\\biggr)\n\t=e^{t\\boldsymbol{A}}\\bigl(\\boldsymbol{f}(t)+\\boldsymbol{g}(t)\\bigr),\n\\]\nwhere we used the fact that $\\boldsymbol{A}$ commutes \nwith~$e^{t\\boldsymbol{A}}$.  If $t=0$ then $e^{t\\boldsymbol{A}}=\\boldsymbol{I}$\nis the identity matrix, so\n\\[\ne^{t\\boldsymbol{A}}\\boldsymbol{U}(t)-\\boldsymbol{U}(0)\n\t=\\int_0^te^{s\\boldsymbol{A}}\\bigl(\n\t\t\\boldsymbol{f}(s)+\\boldsymbol{g}(s)\\bigr)\\,ds.\n\\]\nUsing $e^{-t\\boldsymbol{A}}=(e^{t\\boldsymbol{A}})^{-1}$~and \n$e^{-t\\boldsymbol{A}}e^{s\\boldsymbol{A}}=e^{-(t-s)\\boldsymbol{A}}$, we obtain\na semidiscrete Duhamel formula,\n\\[\n\\boldsymbol{U}(t)=e^{-t\\boldsymbol{A}}\\boldsymbol{u}_0\n\t+\\int_0^te^{-(t-s)\\boldsymbol{A}}\\bigl(\n\t\t\\boldsymbol{f}(s)+\\boldsymbol{g}(s)\\bigr)\\,ds,\n\\]\nwhere $\\boldsymbol{u}_0=[u_0(x_p)]_{p=1}^{P-1}$ is the vector of initial data.\n\n\\section{Explicit Euler method}\n\nTo obtain a fully-discrete scheme, we introduce a uniform grid on the time axis,\n\\[\nt_n=n\\,\\Delta t\\quad\\text{for $0\\le n\\le N$,}\n\t\\quad\\text{where $\\Delta t=\\frac{T}{N}$,}\n\\]\nand let\n\\[\nU^n_p\\approx u(x_p,t_n),\\quad\nf^n_p=f(x_p,t_n),\\quad\n\\gamma_0^n=\\gamma_0(t_n),\\quad\n\\gamma_L^n=\\gamma_L(t_n),\\quad\nu_{0p}=u_0(x_p).\n\\]\nThe \\emph{forward difference} approximation in time,\n\\[\nu_t(x_p,t_n)\\approx\\frac{u(x_p,t_n+\\Delta t)-u(x_p,t_n)}{\\Delta t}\n\t=\\frac{u(x_p,t_{n+1})-u(x_p,t_n)}{\\Delta t},\n\\]\nand the second-order central difference approximation in space,\n\\begin{align*}\nu_{xx}(x_p,t_n)\n&\\approx\\frac{u(x_p+\\Delta x,t_n)-2u(x_p,t_n)+u(x_p-\\Delta x,t_n)}{\\Delta x^2}\\\\\n&=\\frac{u(x_{p+1},t_n)-2u(x_p,t_n)+u(x_{p-1},t_n)}{\\Delta x^2},\n\\end{align*}\nlead to the \\emph{explicit Euler method} for~\\eqref{eq: heat ivp 1d}:\n\\begin{equation}\\label{eq: explicit Euler 1d}\n\\begin{aligned}\n\\frac{U^{n+1}_p-U^n_p}{\\Delta t}\n\t-a\\,\\frac{U^n_{p+1}-2U^n_p+U^n_{p-1}}{\\Delta x^2}&=f^n_p&\n&\\text{for $1\\le p\\le P-1$ and $0\\le n\\le N-1$,}\\\\\nU^n_0&=\\gamma_0^n&&\\text{for $0\\le n\\le N$,}\\\\\nU^n_P&=\\gamma_L^n&&\\text{for $0\\le n\\le N$,}\\\\\nU^0_p&=u_{0p}&&\\text{for $1\\le p\\le P-1$.}\n\\end{aligned}\n\\end{equation}\nWe multiply both sides of the finite difference equation by~$\\Delta t$ and put\n\\begin{equation}\\label{eq: rho explicit Euler}\n\\rho=\\frac{a\\,\\Delta t}{\\Delta x^2}\n\\end{equation}\nto obtain\n\\[\nU^{n+1}_p-U^n_p-\\rho(U^n_{p+1}-2U^n_p+U^n_{p-1})=f^n_p\\,\\Delta t\n\\]\nand thus\n\\begin{equation}\\label{eq: explicit Euler stencil}\nU^{n+1}_p=f^n_p\\,\\Delta t+\\rho U^n_{p-1}+(1-2\\rho)U^n_p+\\rho U^n_{p+1}.\n\\end{equation}\nIn this way, the scheme provides an \\emph{explicit} formula for the solution \nat~$(x_p,t_{n+1})$ given the values at the three nearest grid \npoints $(x_{p-1},t_n)$, $(x_p,t_n)$~and $(x_{p+1},t_n)$ from the previous time \nlevel.  We say the these four points constitute the \\emph{stencil} for the \nmethod; see \\cref{fig: explicit Euler stencil}.\n\\cref{alg: explicit Euler} shows how the \nformula~\\eqref{eq: explicit Euler stencil} is used to compute the finite \ndifference solution~$U^n_p$ by advancing from one time level to the next, \nstarting at~$t_0=0$.  \n\n\\begin{figure}\n\\caption{Computational stencil for the explicit Euler \nmethod~\\eqref{eq: explicit Euler stencil}.}\n\\label{fig: explicit Euler stencil}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[->] (-1,0) -- (17,0);\n\\node[right] at (17,0) {$x$};\n\\node[below] at (8,0) {$x_p$};\n\\draw[->] (0,-1) -- (0,6);\n\\node[above left] at (0,6) {$t$};\n\\node[left] at (0,3) {$t_n$};\n\\foreach \\x in {2, 4, ..., 16}\n    \\draw[thin] (\\x,0) -- (\\x,6);\n\\foreach \\y in {1, ..., 5}\n    \\draw[thin] (0,\\y) -- (16,\\y);\n\\draw[ultra thick] (6,3) -- (8,3) -- (10,3);\n\\draw[fill] (6,3)  circle (0.15cm);\n\\draw[fill] (8,3)  circle (0.15cm);\n\\draw[fill] (10,3) circle (0.15cm);\n\\draw[ultra thick] (8,3) -- (8,4);\n\\draw[fill=red] (8,4)  circle (0.15cm);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\n\\begin{algorithm}\n\\caption{Explicit Euler method.}\n\\label{alg: explicit Euler}\n\\begin{algorithmic}\n\\State Allocate storage for $x_p$, $t_n$~and $U^n_p$, where $0\\le p\\le P$ and \n$0\\le n\\le N$.\n\\State $\\Delta x=L/P$ \n\\State$\\Delta t=T/N$\n\\For{$p=0:P$}\n    \\State $x_p=p\\,\\Delta x$\n\\EndFor\n\\For{$n=0:N$}\n    \\State $t_n=n\\,\\Delta t$\n    \\State $U^n_0=\\gamma_0^n$\n    \\State $U^n_P=\\gamma_L^n$\n\\EndFor\n\\State $\\rho=a\\,\\Delta t/\\Delta x^2$\n\\For{$p=1:P-1$}\n    \\State $U^0_p=u_0(x_p)$\n\\EndFor\n\\For{$n=0:N-1$}\n    \\For{$p=1:P-1$}\n        \\State $U^{n+1}_p=f^n_p\\,\\Delta t\n                +\\rho U^n_{p-1}+(1-2\\rho)U^n_p+\\rho U^n_{p+1}$\n    \\EndFor                \n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\nWe now show that the explicit Euler method is stable provided the time \nstep~$\\Delta t$ is sufficiently small compared to the spatial grid \nsize~$\\Delta x$.\n\n\\begin{theorem}\\label{thm: explicit Euler stability}\nIf $\\Delta x$ and $\\Delta t$ satisfy\n\\begin{equation}\\label{eq: explicit Euler timestep}\n\\Delta t\\le\\frac{\\Delta x^2}{2a},                                        \n\\end{equation}\nor equivalently if the ratio~\\eqref{eq: rho explicit Euler} satisfies \n$\\rho\\le1/2$, then the explicit Euler method~\\eqref{eq: explicit Euler 1d} is \nstable:\n\\[\n\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n}\\|_\\infty,\\|\\gamma_L^{0:n}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=0}^{n-1}\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t\n\\quad\\text{for $0\\le n\\le N$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nWe use finite induction on~$n$.  When~$n=0$, we have\n$U^0_p=u_{0p}$ for~$1\\le p\\le P-1$, with $U^0_0=\\gamma_0^0$~and \n$U^0_P=\\gamma_L^0$, so \n\\[\n\\|\\boldsymbol{U}^0_{0:P}\\|_\\infty=\n\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty,|\\gamma_0|,|\\gamma_L|\\bigr\\},\n\\]\nwhich agrees with the formula since the empty sum vanishes. Now let \n$0\\le n\\le N-1$ and make the induction hypothesis.  We see \nfrom~\\eqref{eq: explicit Euler stencil} that\n\\[\n|U^{n+1}_p|\\le|f^n_p|\\,\\Delta t+\\rho|U^n_{p-1}|+|1-2\\rho|\\,|U^n_p|\n    +\\rho|U^n_{p+1}|\n\\]\nand thus\n\\[\n|U^{n+1}_p|\\le\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t\n\t\t+(2\\rho+|1-2\\rho|)\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\\quad\\text{for $1\\le p\\le P-1$.} \n\\]\nIf $\\rho\\le1/2$, then $2\\rho+|1-2\\rho|=2\\rho+1-2\\rho=1$ so\n\\begin{align*}\n\\|\\boldsymbol{U}^{n+1}_{1:P-1}\\|_\\infty\n\t&\\le\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t\\\\\n\t&\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n}\\|_\\infty,\\|\\gamma_L^{0:n}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=0}^{n-1}\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t\n\t\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t\\\\\n\t&=\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n}\\|_\\infty,\\|\\gamma_L^{0:n}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=0}^n\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t,\n\\end{align*}\nand since $U^{n+1}_0=\\gamma_0^{n+1}$~and $U^{n+1}_P=\\gamma_L^{n+1}$\n\\[\n\\|\\boldsymbol{U}^{n+1}_{0:P}\\|_\\infty\n\t\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n+1}\\|_\\infty,\\|\\gamma_L^{0:n+1}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=0}^n\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t,\n\\]\nas required.\n\\end{proof}\n\nThe \\emph{local trunction error} for the explicit Euler method is defined by\n\\begin{equation}\\label{eq: tau explicit Euler}\n\\tau(x,t)=f(x,t)-\\frac{u(x,t+\\Delta t)-u(x,t)}{\\Delta t}\n\t+a\\,\\frac{u(x+\\Delta x,t)-2u(x,t)+u(x-\\Delta x,t)}{\\Delta x^2},\n\\end{equation}\nand measures the extent to which the solution~$u(x,t)$ of the continuous \nproblem~\\eqref{eq: heat ivp 1d} fails to satisfy the finite difference equation.\nWe can estimate $\\tau^n_p=\\tau(x_p,t_n)$ by Taylor expansion.\n\n\\begin{lemma}\\label{lem: tau explicit Euler}\nIf $u_{tt}$~and $u_{xxxx}$ are continuous for~$(x,t)\\in[0,L]\\times[0,T]$, then\n\\[\n|\\tau^n_p|\\le\\frac{\\Delta t}{2}\\max_{[0,L]\\times[0,T]}|u_{tt}|\n\t+a\\,\\frac{\\Delta x^2}{12}\\max_{[0,L]\\times[0,T]}|u_{xxxx}|\n\\]\nfor $1\\le p\\le P-1$ and $0\\le n\\le N-1$.\n\\end{lemma}\n\\begin{proof}\nSince $u_t-au_{xx}=f$,\n\\[\n|\\tau(x,t)|=\\biggl|u_t-\\frac{u(x,t+\\Delta t)-u(x,t)}{\\Delta t}\n\t-a\\biggl(u_{xx}-\\frac{u(x+\\Delta x,t)-2u(x,t)+u(x-\\Delta x,t)}{\\Delta x^2}\n\\biggr)\\biggr|,\n\\]\nand, so by Exercise~\\ref{ex: forward diff}~and \\cref{thm: 2nd central diff},\n\\[\n|\\tau(x,t)|\\le\\frac{\\Delta t}{2}\\max_{t\\le s\\le t+\\Delta t}|u_{tt}(x,s)|\n\t+a\\,\\frac{\\Delta x^2}{12}\\,\n\t\\max_{x-\\Delta x\\le y\\le x+\\Delta x}|u_{xxxx}(y,t)|,\n\\]\nwhich implies the stated estimate for~$\\tau^n_p$. \n\\end{proof}\n\nThe next theorem shows that, provided the \nrestriction~\\eqref{eq: explicit Euler timestep} on the step sizes is satisfied, \nthe explicit Euler method is first-order accurate in time and second-order \naccurate in space.\n\n\\begin{theorem}\\label{thm: explicit Euler error}\nAssume that $\\Delta x$~and $\\Delta t$ satisfy \n\\eqref{eq: explicit Euler timestep}, and that $u_{tt}$~and $u_{xxxx}$ are \ncontinuous on~$[0,L]\\times[0,T]$. Then the error for the explicit Euler method \nsatisfies\n\\[\n|U^n_p-u(x_p,t_n)|\\le Ct_n(\\Delta t+\\Delta x^2)\n\\quad\\text{for $0\\le p\\le P-1$ and $0\\le n\\le N$,}\n\\]\nwhere\n\\begin{equation}\\label{eq: error const explicit Euler}\nC=\\max\\biggl(\\frac{1}{2}\\max_{[0,L]\\times[0,T]}|u_{tt}|,\n\t\\frac{1}{12}\\max_{[0,L]\\times[0,T]}|u_{xxxx}|\\biggr).\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\nBy the definition~\\eqref{eq: tau explicit Euler} of the local truncation error,\n\\[\n\\frac{u(x_p,t_{n+1})-u(x_p,t_n)}{\\Delta t}\n\t-a\\,\\frac{u(x_{p+1},t)-2u(x_p,t_n)+u(x_{p-1},t_n)}{\\Delta x^2}\n\t=f^n_p-\\tau^n_p.\n\\]\nSubtracting this equation from the finite difference equation \nin~\\eqref{eq: explicit Euler 1d}, we obtain a finite difference equation for\nthe error ~$E^n_p=U^n_p-u(x_p,t_n)$ in the finite difference solution, namely\n\\[\n\\frac{E^{n+1}_p-E^n_p}{\\Delta t}\n\t-a\\,\\frac{E^n_{p+1}-2E^n_p+E^n_{p-1}}{\\Delta x^2}=\\tau^n_p\n\\quad\\text{for $1\\le p\\le P-1$ and $0\\le n\\le N-1$.}\n\\]\nIn addition, the boundary and initial conditions satisfied by $U^n_p$~and $u$ \nimply that\n\\[\n\\begin{aligned}\nE^n_0&=U^n_0-u(x_0,t_n)=\\gamma_0^n-\\gamma_0^n=0&&\\text{for $0\\le n\\le N$,}\\\\\nE^n_P&=U^n_P-u(x_P,t_n)=\\gamma_L^n-\\gamma_L^n=0&&\\text{for $0\\le n\\le N$,}\\\\\nE^0_p&=U^0_p-u(x_p,t_0)=u_0(x_p)-u_0(x_p)=0&&\\text{for $1\\le p\\le P-1$.}\n\\end{aligned}\n\\]\nThus, $E^n_p$ is the explicit Euler solution obtained when $f^n_p$, \n$\\gamma_0^n$, $\\gamma_L^n$~and $u_{0p}$ are replaced by $\\tau^n_p$, $0$, \n$0$~and $0$, respectively.  The restriction on the step sizes allows us to apply \nthe stability estimate of \\cref{thm: explicit Euler stability} to deduce \nthat\n\\[\n\\|\\boldsymbol{E}^n_{0:P}\\|_\\infty\n\t\\le\\sum_{j=0}^{n-1}\\|\\boldsymbol{\\tau}^n_{1:P-1}\\|_\\infty\\,\\Delta t\n\t\\quad\\text{for $0\\le n\\le N$.}\n\\]\nBy Lemma~\\ref{lem: tau explicit Euler}, \n$\\|\\boldsymbol{\\tau}^n_{1:P-1}\\|_\\infty\\le C(\\Delta t+\\Delta x^2)$, so\n\\[\n\\|\\boldsymbol{E}^n_{0:P}\\|_\\infty\\le Cn(\\Delta t+\\Delta x^2)\\,\\Delta t\n\t=Ct_n(\\Delta t+\\Delta x^2),\n\\]\nas claimed.\n\\end{proof}\n\n\\section{Implicit Euler method}\n\nInstead of using a forward difference, we can approximate $u_t$ by a \n\\emph{backward difference},\n\\[\nu_t(x_p,t_n)\\approx\\frac{u(x_p,t_n)-u(x_p,t_n-\\Delta t)}{\\Delta t}\n\t=\\frac{u(x_p,t_n)-u(x_p,t_{n-1})}{\\Delta t},\n\\]\nwhich leads to the \\emph{im}plicit Euler method,\n\\begin{equation}\\label{eq: implicit Euler 1d}\n\\begin{aligned}\n\\frac{U^n_p-U^{n-1}_p}{\\Delta t}\n\t-a\\,\\frac{U^n_{p+1}-2U^n_p+U^n_{p-1}}{\\Delta x^2}&=f^n_p&\n&\\text{for $1\\le p\\le P-1$ and $1\\le n\\le N$,}\\\\\nU^n_0&=\\gamma_0^n&&\\text{for $0\\le n\\le N$,}\\\\\nU^n_P&=\\gamma_L^n&&\\text{for $0\\le n\\le N$,}\\\\\nU^0_p&=u_{0p}&&\\text{for $1\\le p\\le P-1$.}\n\\end{aligned}\n\\end{equation}\nMultiplying both sides of the finite difference equation by~$\\Delta t$, and \ndefining $\\rho$ as before in~\\eqref{eq: rho explicit Euler}, we obtain\n\\[\nU^n_p-U^{n-1}_p-\\rho(U^n_{p+1}-2U^n_p+U^n_{p-1})=f^n_p\\,\\Delta t\n\\]\nand thus\n\\begin{equation}\\label{eq: implicit Euler stencil}\n-\\rho U^n_{p-1}+(1+2\\rho)U^n_p-\\rho U^n_{p+1}=U^{n-1}_p+f^n_p\\,\\Delta t\n\\end{equation}\nfor $1\\le p\\le P-1$ and $1\\le n\\le N$.  Thus, at the $n$th time level we have a \nsystem of linear equations for the unknown $U^n_1$, $U^n_2$, \\dots, $U^n_{P-1}$,\nwith the right-hand sides involving the solution at the previous time level.\nThe stencil for this scheme is shown in \\cref{fig: implicit Euler stencil}.\n\n\\begin{figure}\n\\caption{Computational stencil for the implicit Euler \nmethod~\\eqref{eq: implicit Euler stencil}.}\n\\label{fig: implicit Euler stencil}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[->] (-1,0) -- (17,0);\n\\node[right] at (17,0) {$x$};\n\\node[below] at (8,0) {$x_p$};\n\\draw[->] (0,-1) -- (0,6);\n\\node[above left] at (0,6) {$t$};\n\\node[left] at (0,3) {$t_n$};\n\\foreach \\x in {2, 4, ..., 16}\n    \\draw[thin] (\\x,0) -- (\\x,6);\n\\foreach \\y in {1, ..., 5}\n    \\draw[thin] (0,\\y) -- (16,\\y);\n\\draw[ultra thick] (8,2) -- (8,3);\n\\draw[fill] (8,2)  circle (0.15cm);\n\\draw[ultra thick] (6,3) -- (8,3) -- (10,3);\n\\draw[fill=red] (6,3)  circle (0.15cm);\n\\draw[fill=red] (8,3)  circle (0.15cm);\n\\draw[fill=red] (10,3) circle (0.15cm);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nAlternatively, we can start from the matrix form of the semidiscrete \nmethod~\\eqref{eq: ODE system}, and approximate $d\\boldsymbol{U}/dt$ with a \nbackward difference to obtain\n\\begin{equation}\\label{eq: implicit Euler 1d vector}\n\\frac{\\boldsymbol{U}^n-\\boldsymbol{U}^{n-1}}{\\Delta t}\n\t+\\boldsymbol{A}\\boldsymbol{U}^n=\\boldsymbol{f}^n+\\boldsymbol{g}^n\n\\quad\\text{for $1\\le n\\le N$,}\n\\end{equation}\nwhere\n\\[\n\\boldsymbol{A}=\\frac{a}{\\Delta x^2}\\begin{bmatrix}\n 2&    -1&      &      &\\\\\n-1&     2&    -1&      &\\\\\n  &\\ddots&\\ddots&\\ddots&\\\\\n  &      &    -1&     2&-1\\\\\n  &      &      &    -1& 2\\end{bmatrix},\\qquad\n\\]\nand\n\\[\n\\boldsymbol{U}^n=\\begin{bmatrix}\nU^n_1\\\\ U^n_2\\\\ \\vdots\\\\ U^n_{P-2}\\\\ U^n_{P-1}\\end{bmatrix},\\qquad\n\\boldsymbol{f}^n=\\begin{bmatrix}\nf^n_1\\\\ f^n_2\\\\ \\vdots\\\\ f^n_{P-2}\\\\ f^n_{P-1}\\end{bmatrix},\\qquad\n\\boldsymbol{g}^n=\\frac{a}{\\Delta x^2}\\begin{bmatrix}\n\\gamma_0^n\\\\ 0\\\\ \\vdots\\\\ 0\\\\ \\gamma_L^n\\end{bmatrix}.\n\\]\nRearranging \\eqref{eq: implicit Euler 1d vector} we find that\n\\[\n(\\boldsymbol{I}+\\Delta t\\,\\boldsymbol{A})\\boldsymbol{U}^n\n\t=\\boldsymbol{U}^{n-1}+\\Delta t\\,(\\boldsymbol{f}^n+\\boldsymbol{g}^n)\n\\quad\\text{for $1\\le n\\le N$.}\n\\]\nHere, the coefficient matrix is symmetric, tridiagonal and positive-definite, \nso we can compute~$\\boldsymbol{U}^n$ via a factorization\n\\[\n\\boldsymbol{I}+\\Delta t\\,\\boldsymbol{A}\n\t=\\boldsymbol{L}^T\\boldsymbol{D}\\boldsymbol{L},\n\\]\nas shown in \\cref{alg: implicit Euler}.\n\n\\begin{algorithm}\n\\caption{Implicit Euler method.}\n\\label{alg: implicit Euler}\n\\begin{algorithmic}\n\\State Allocate storage for $x_p$, $t_n$~and $U^n_p$, where $0\\le p\\le P$ and \n$0\\le n\\le N$.\n\\State Allocate storage for vectors $[d_1,d_2,\\ldots,d_{P-1}]^T$~and\n$[\\ell_1,\\ell_2,\\ldots,\\ell_{P-2}]^T$.\n\\State $\\Delta x=L/P$ \n\\State$\\Delta t=T/N$\n\\For{$p=0:P$}\n    \\State $x_p=p\\,\\Delta x$\n\\EndFor\n\\For{$n=0:N$}\n    \\State $t_n=n\\,\\Delta t$\n    \\State $U^n_0=\\gamma_0^n$\n    \\State $U^n_P=\\gamma_L^n$\n\\EndFor\n\\State $\\rho=a\\,\\Delta t/\\Delta x^2$\n\\For{$p=1:P-1$}\n    \\State $d_p=1+2\\rho$\n\\EndFor\n\\For{$p=1:P-2$}\n    \\State $\\ell_p=-\\rho$\n\\EndFor\n\\State \\textsc{Factorize!}($\\boldsymbol{d}$, $\\boldsymbol{\\ell}$)\n\\Comment Use \\cref{alg: LDLT in place} to compute\n$\\boldsymbol{I}+\\Delta t\\,\\boldsymbol{A}=\\boldsymbol{L}\\boldsymbol{D}\n\\boldsymbol{L}^T$ in place.\n\\For{$p=1:P-1$}\n    \\State $U^0_p=u_0(x_p)$\n\\EndFor\n\\For{$n=1:N$}\n    \\For{$p=1:P-1$}\n        \\State $U^n_p\\gets U^{n-1}_p+\\Delta t\\,f(x_p,t_n)$\n    \\EndFor\n    \\State $U^n_1\\gets U^n_1+a\\gamma_0/\\Delta x^2$\n    \\State $U^n_{P-1}\\gets U^n_{P-1}+a\\gamma_L/\\Delta x^2$\n    \\State \\textsc{Solve}!($\\boldsymbol{U}^n_{1:P-1}$,\n$\\boldsymbol{d}$, $\\boldsymbol{\\ell}$)\n\\Comment Use \\cref{alg: solve symmetric tridiagonal in place} to solve\nfor $\\boldsymbol{U}^n_{1:P-1}$ in place.\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{theorem}\nThe implicit Euler method is unconditionally stable: for any choice of \n$\\Delta x$~and $\\Delta t$,\n\\[\n\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n}\\|_\\infty,\\|\\gamma_L^{0:n}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=1}^n\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t\n\\quad\\text{for $0\\le n\\le N$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nWe use finite induction on~$n$.  When~$n=0$, we have\n$U^0_p=u_{0p}$ for~$1\\le p\\le P-1$, with $U^0_0=\\gamma_0^0$~and \n$U^0_P=\\gamma_L^0$,\nso \n\\[\n\\|\\boldsymbol{U}^0_{0:P}\\|_\\infty=\n\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty,\n\t|\\gamma_0^0|,|\\gamma_L^0|\\bigr\\},\n\\]\nwhich agrees with the formula since the empty sum vanishes. Now let \n$1\\le n\\le N$ and make the induction hypothesis that\n\\[\n\\|\\boldsymbol{U}^{n-1}_{0:P}\\|_\\infty\n\t\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty, \n\t\t\\|\\gamma_0^{0:n-1}\\|_\\infty,\\|\\gamma_L^{0:n-1}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=1}^{n-1}\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t.\n\\]\nWe see from~\\eqref{eq: implicit Euler stencil} that, for $1\\le p\\le P-1$,\n\\[\n(1+2\\rho)U^n_p=\\rho U^n_{p-1}+\\rho U^n_{p+1}+U^{n-1}_p+f^n_p\\,\\Delta t\n\\]\nand so\n\\[\n(1+2\\rho)|U^n_p|\\le2\\rho\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t+\\|\\boldsymbol{U}^{n-1}_{1:P-1}\\|_\\infty\n\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t.\n\\]\nThus,\n\\[\n(1+2\\rho)\\|\\boldsymbol{U}^n_{1:P-1}\\|_\\infty\n\t\\le2\\rho\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t+\\|\\boldsymbol{U}^{n-1}_{1:P-1}\\|_\\infty\n\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t,\n\\]\nand since $U^n_0=\\gamma_0=U^{n-1}_0$~and $U^n_P=\\gamma_L=U^{n-1}_P$, \n\\[\n(1+2\\rho)\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t\\le2\\rho\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t+\\|\\boldsymbol{U}^{n-1}_{0:P}\\|_\\infty\n\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t.\n\\]\nAfter canceling $2\\rho\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty$, it follows that\n\\begin{align*}\n\\|\\boldsymbol{U}^n_{1:P-1}\\|_\\infty&\\le\\|\\boldsymbol{U}^{n-1}_{0:P}\\|_\\infty\n\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t\\\\\n\t&\\le\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty,\n\t\\|\\gamma_0^{0:n-1}\\|_\\infty,\\|\\gamma_L^{0:n-1}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=1}^{n-1}\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t\n\t+\\|\\boldsymbol{f}^n_{1:P-1}\\|_\\infty\\,\\Delta t\\\\\n\t&=\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty,\n\t\\|\\gamma_0^{0:n-1}\\|_\\infty,\\|\\gamma_L^{0:n-1}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=1}^n\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t,\n\\end{align*}\nand so, since $U^n_0=\\gamma_0^n$~and $U^n_P=\\gamma_L^n$,\n\\[\n\\|\\boldsymbol{U}^n_{0:P}\\|_\\infty\n\t=\\max\\bigl\\{\\|(\\boldsymbol{u}_0)_{1:P-1}\\|_\\infty,\n\t\\|\\gamma_0^{0:n}\\|_\\infty,\\|\\gamma_L^{0:n}\\|_\\infty\\bigr\\}\n\t+\\sum_{j=1}^n\\|\\boldsymbol{f}^j_{1:P-1}\\|_\\infty\\,\\Delta t,\n\\]\nas required.\n\\end{proof}\n\nThe local truncation error for the \\emph{im}plicit Euler method is defined by\n\\[\n\\tau(x,t)=f(x,t)-\\frac{u(x,t)-u(x,t-\\Delta t)}{\\Delta t}\n\t+a\\,\\frac{u(x+\\Delta x,t)-2u(x,t)+u(x-\\Delta x,t)}{\\Delta x^2},\n\\]\nand we can again estimate $\\tau^n_p=\\tau(x_p,t_n)$ by Taylor expansion\n(Exercise~\\ref{ex: forward diff} and \\cref{thm: 2nd central diff}):\n\\[\n|\\tau^n_p|\\le\\frac{\\Delta t}{2}\\max_{[0,L]\\times[0,T]}|u_{tt}|\n\t+a\\,\\frac{\\Delta x^2}{12}\\max_{[0,L]\\times[0,T]}|u_{xxxx}|\n\\]\nfor $1\\le p\\le P-1$~and $1\\le n\\le N$, which leads to the following error bound.\n\n\\begin{theorem}\\label{thm: implicit Euler error}\nAssume that $u_{tt}$~and $u_{xxxx}$ are continuous on~$[0,L]\\times[0,T]$. Then \nthe error for the implicit Euler method satisfies\n\\[\n|U^n_p-u(x_p,t_n)|\\le Ct_n(\\Delta t+\\Delta x^2)\n\\quad\\text{for $0\\le p\\le P-1$ and $0\\le n\\le N$,}\n\\]\nwhere $C$ is defined by~\\eqref{eq: error const explicit Euler}.\n\\end{theorem}\n\\begin{proof}\nSee Exercise~\\ref{ex: implicit Euler error}.\n\\end{proof}\n\n\\section{Crank--Nicolson method}\nLet us introduce the half-time levels\n\\[\nt_{n-1/2}=t_n-\\tfrac12\\Delta t=\\frac{t_n+t_{n-1}}{2}\n    \\quad\\text{for $1\\le n\\le N$.}\n\\]\nThe implicit Euler method is only first-order accurate in time because the \nfirst-order backward difference approximates $u_t(x_p,t_n)$ only to first order \nin~$\\Delta t$, that is,\n\\[\n\\frac{u(x,t_n)-u(x,t_{n-1})}{\\Delta t}=u_t(x_p,t_n)+O(\\Delta t).\n\\]\nHowever, viewed as an approximation to~$u_t(x_p,t_{n-1/2})$, the backward \ndifference becomes a central difference (with step-size $\\tfrac12\\Delta t$), \nand is therefore second-order accurate by \\cref{thm: first central diff}:\n\\[\n\\frac{u(x,t_n)-u(x,t_{n-1})}{\\Delta t}=u_t(x_p,t_{n-1/2})+O(\\Delta t^2).\n\\]\nSimilarly, the theorem below shows that\n\\[\n\\frac{u(x,t_n)+u(x,t_{n-1})}{2}=u(x_p,t_{n-1/2})+O(\\Delta t^2).\n\\]\n\n\\begin{theorem}\\label{thm: average}\nIf $f$ is $C^2$ on the closed interval~$[x-h,x+h]$, then\n\\[\n\\biggl|f(x)-\\frac{f(x+h)+f(x-h)}{2}\\biggr|\\le\\frac{h^2}{2}\n    \\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+(R_1f)(x,h)\n\\quad\\text{and}\\quad\nf(x-h)=f(x)-f'(x)h+(R_1f)(x,-h),\n\\]\nwe have\n\\[\nf(x+h)+f(x-h)=2f(x)+(R_1f)(x,h)+(R_1f)(x,-h).\n\\]\nThus,\n\\[\n\\frac{f(x+h)+f(x-h)}{2}-f(x)=\\frac{(R_1f)(x,h)+(R_1f)(x,-h)}{2},\n\\]\nso the result follows from \\cref{thm: Taylor remainder}.\n\\end{proof}\n\n\\begin{figure}\n\\caption{Computational stencil for the Crank--Nicolson \nmethod~\\eqref{eq: Crank-Nicolson 1d}.}\\label{fig: Crank-Nicolson 1d}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[->] (-1,0) -- (17,0);\n\\node[right] at (17,0) {$x$};\n\\node[below] at (8,0) {$x_p$};\n\\draw[->] (0,-1) -- (0,6);\n\\node[above left] at (0,6) {$t$};\n\\node[left] at (0,3) {$t_n$};\n\\foreach \\x in {2, 4, ..., 16}\n    \\draw[thin] (\\x,0) -- (\\x,6);\n\\foreach \\y in {1, ..., 5}\n    \\draw[thin] (0,\\y) -- (16,\\y);\n\\draw[ultra thick] (6,2) -- (8,2) -- (10,2);\n\\draw[fill] (6,2)  circle (0.15cm);\n\\draw[fill] (8,2)  circle (0.15cm);\n\\draw[fill] (10,2) circle (0.15cm);\n\\draw[ultra thick] (8,2) -- (8,3);\n\\draw[ultra thick] (6,3) -- (8,3) -- (10,3);\n\\draw[fill=red] (6,3)  circle (0.15cm);\n\\draw[fill=red] (8,3)  circle (0.15cm);\n\\draw[fill=red] (10,3) circle (0.15cm);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nThis observation leads us to consider the \\emph{Crank--Nicolson method} \nfor~\\eqref{eq: heat ivp 1d}:\n\\begin{equation}\\label{eq: Crank-Nicolson 1d}\n\\frac{U^n_p-U^{n-1}_p}{\\Delta t}\n    -a\\,\\frac{U^{n-1/2}_{p+1}-2U^{n-1/2}_p+U^{n-1/2}_{p-1}}{\\Delta x^2}\n    =f^{n-1/2}_p\n\\end{equation}\nfor $1\\le p\\le P-1$ and $1\\le n\\le N$, where we have used the notation\n\\[\nU^{n-1/2}_p=\\frac{U^n_p+U^{n-1}_p}{2}\\approx u(x_p,t_{n-1/2}),\n\\]\nand, on the right-hand side, \n\\[\nf^{n-1/2}_p=\\frac{f^n_p+f^{n-1}_p}{2}\\approx f(x_p,t_{n-1/2})\n\\quad\\text{or}\\quad\nf^{n-1/2}_p=f(x_p,t_{n-1/2}).\n\\]\nThe usual discrete boundary conditions are imposed,\n\\[\nU^n_0=\\gamma_0^n\\quad\\text{and}\\quad\nU^n_P=\\gamma_L^n\\quad\\text{for $0\\le n\\le N$,}\n\\]\nalong with the usual discrete initial condition\n\\[\nU^0_p=u_{0p}\\quad\\text{for $1\\le p\\le P-1$.}\n\\]\n\\cref{fig: Crank-Nicolson 1d} shows the stencil for the scheme.\nIn matrix notation, the Crank--Nicolson method takes the form\n\\begin{equation}\\label{eq: Crank-Nicolson matrix}\n\\frac{\\boldsymbol{U}^n-\\boldsymbol{U}^{n-1}}{\\Delta t}\n    +\\boldsymbol{A}\\boldsymbol{U}^{n-1/2}=\\boldsymbol{f}^{n-1/2}\n    +\\boldsymbol{g}^{n-1/2},\n\\end{equation}\nwhere the $(P-1)\\times(P-1)$ matrix~$\\boldsymbol{A}$ and \nis same as in~\\eqref{eq: implicit Euler 1d vector}, with \n\\[\n\\boldsymbol{g}^{n-1/2}=\\frac{\\boldsymbol{g}(t_n)+\\boldsymbol{g}(t_{n-1})}{2}\n\\quad\\text{or}\\quad\n\\boldsymbol{g}^{n-1/2}=\\boldsymbol{g}(t_{n-1/2}),\n\\]\nfor $\\boldsymbol{g}(t)$ as in~\\eqref{eq: U f g semidiscrete 1d}.\n\nRearranging \\eqref{eq: Crank-Nicolson matrix}, we find that\n\\[\n\\boldsymbol{U}^n-\\boldsymbol{U}^{n-1}\n    +\\tfrac12\\Delta t\\,\\boldsymbol{A}(\\boldsymbol{U}^n+\\boldsymbol{U}^{n-1})\n    =\\Delta t\\,\\bigl(\\boldsymbol{f}^{n-1/2}+\\boldsymbol{g}^{n-1/2}\\bigr)\n\\]\nwhich yields linear system that must be solved at the $n$th time step,\n\\[\n\\bigl(\\boldsymbol{I}+\\tfrac12\\Delta t\\,\\boldsymbol{A}\\bigr)\\boldsymbol{U}^n=\n\\bigl(\\boldsymbol{I}-\\tfrac12\\Delta t\\,\\boldsymbol{A}\\bigr)\\boldsymbol{U}^{n-1}\n    +\\Delta t\\,\\bigl(\\boldsymbol{f}^{n-1/2}+\\boldsymbol{g}^{n-1/2}\\bigr).\n\\]\nThe local truncation error for the Crank--Nicolson method is\n\\begin{multline*}\n\\tau^{n-1/2}_p=f^{n-1/2}_p-\\frac{u(x_p,t_n)-u(x_p,t_{n-1})}{\\Delta t}\n    +\\frac{a}{\\Delta x^2}\\biggl(\n    \\frac{u(x_{p+1},t_n)+u(x_{p+1},t_{n-1})}{2}\\\\\n    -2\\,\\frac{u(x_p,t_n)+u(x_p,t_{n-1})}{2}\n    +\\frac{u(x_{p-1},t_n)+u(x_{p-1},t_{n-1})}{2}\\biggr)r.\n\\end{multline*}\nIf we choose $f^{n-1/2}_p=f(x_p,t_{n-1/2})$ then\n$f^{n-1/2}_p=u_t(x_p,t_{n-1/2})-au_{xx}(x_p,t_{n-1/2)}$ so\n\\begin{align*}\n\\tau^{n-1/2}_p\n&=\\biggl(u_t(x_p,t_{n-1/2})-\\frac{u(x_p,t_n)-u(x_p,t_{n-1})}{\\Delta t}\\biggr)\\\\\n    &\\qquad{}+a\\biggl(\\frac{u_{xx}(x_p,t_n)+u_{xx}(x_p,t_{n-1})}{2}\n        -u_{xx}(x_p,t_{n-1/2})\\biggr)\\\\\n    &\\qquad{}+\\frac{a}{2}\\biggl(\n    \\frac{u(x_{p+1},t_n)-2u(x_p,t_n)+u(x_{p-1},t_n)}{\\Delta x^2}-u_{xx}(x_p,t_n)\n    \\biggr)\\\\\n    &\\qquad{}+\\frac{a}{2}\\biggl(\n    \\frac{u(x_{p+1},t_{n-1})-2u(x_p,t_{n-1})+u(x_{p-1},t_{n-1})}{\\Delta x^2}\n        -u_{xx}(x_p,t_n)\\biggr).\n\\end{align*}\nApplying Theorems \\ref{thm: first central diff}~and \\ref{thm: average} with \n$h=\\tfrac12\\Delta t$, and \\cref{thm: 2nd central diff} with~$h=\\Delta \nx$, we conclude that\n\\[\n|\\tau^{n-1/2}_p|\n    \\le\\frac{(\\tfrac12\\Delta t)^2}{6}\\max_{[0,L]\\times[0,T]}|u_{ttt}| \n    +a\\,\\frac{(\\tfrac12\\Delta t)^2}{2}\\max_{[0,L]\\times[0,T]}|u_{xxxx}|\n    +a\\,\\frac{\\Delta x^2}{12}\\max_{[0,L]\\times[0,T]}|u_{xxxx}|\n\\]\nand hence $\\tau^{n-1/2}_p=O(\\Delta t^2+\\Delta x^2)$.  It turns out that the \nCrank--Nicolson method is unconditionally stable, and so \n$U^n_p=u(x_p,t_n)+O(\\Delta t^2+\\Delta x^2)$.\n\n\\begin{Exercises}\n\n\\exercise\nIf the solution~$u(x,t)$ of~\\eqref{eq: heat ivp 1d} is continuous\nat $(x,t)=(0,0)$ and $(L,0)$, then we must have\n\\[\nu_0(0)=u(0,0)=\\gamma_0(0)\\quad\\text{and}\\quad\nu_0(L)=u(L,t)=\\gamma_L(0).\n\\]\nShow that if $u_t$ and $u_{xx}$ are continuous at~$(x,t)=(L,0)$ and $(L,0)$,\nthen\n\\[\n\\gamma_0'(0)-au_0''(0)=f(0,0)\n\\quad\\text{and}\\quad\n\\gamma_L'(0)-au_0''(L)=f(L,0).\n\\]\n\n\\exercise\\label{ex: forward diff}\nUse \\cref{thm: Taylor remainder} to show that that if $f$ is $C^2$ on \nthe closed interval~$[x,x+h]$, then\n\\[\n\\biggl|f'(x)-\\frac{f(x+h)-f(x)}{h}\\biggr|\n\t\\le\\frac{h}{2}\\max_{x\\le y\\le x+h}|f''(y)|,\n\\]\nand, similarly, if $f$ is $C^2$ on~$[x-h,x]$, then\n\\[\n\\biggl|f'(x)-\\frac{f(x)-f(x-h)}{h}\\biggr|\n\t\\le\\frac{h}{2}\\max_{x-h\\le y\\le x}|f''(y)|,\n\\]\n\n\\exercise\nCount the numbers of arithmetic operations used in \\cref{alg: explicit Euler} \nto compute the explicit Euler solution.\n\\begin{ans}\nAbout $4NP$~multiplications and $3NP$ additions, not counting the cost of\nevaluating $f$ at $(N-1)(P-1)$~grid points, and $\\gamma_0$~and $\\gamma_L$\nat $N$ grid points.\n\\end{ans}\n\n\\exercise\nLet $\\phi_k(x)=\\sin(k\\pi x/L)$.\n\\begin{description}\n\\item{(i)} Show that \n\\[\n\\phi_k(x_{p+1})+\\phi_k(x_{p-1})=\\biggl(2\\cos\\frac{k\\pi\\,\\Delta x}{2}\\biggr)\\,\n\t\\phi_k(x_p).\n\\]\n\\item{(ii)} Deduce that\n\\[\n-\\frac{\\phi_k(x_{p+1}-2\\phi_k(x_p)+\\phi_k(x_{p-1})}{\\Delta x^2}\n\t=\\Lambda_k\\phi_k(x_p)\\quad\\text{where}\\quad\n\\Lambda_k=\\frac{2}{\\Delta x^2}\\biggl(1-\\cos\\frac{k\\pi\\,\\Delta x}{L}\\biggr).\n\\]\n\\item{(iii)} Show\n\\[\n\\Lambda_k=\\biggl(\\frac{2}{\\Delta x}\\,\\sin\\frac{k\\pi\\,\\Delta x}{2L}\\biggr)^2.\n\\]\n\\item{(iv)}\nFind $\\lambda_k=\\lim_{\\Delta x\\to0}\\Lambda_k$ and verify that \n$-\\phi_k''=\\lambda_k\\phi_k$.\n\\item{(v)}\nSuppose that $u_0(x)=\\sin(k\\pi x/L)$, $f(x,t)\\equiv0$ and \n$\\gamma_0(t)\\equiv 0\\equiv\\gamma_L(t)$.  Find $R$ such that the explicit\nEuler solution is~$U^n_p=R^n\\phi_k(x_p)$.\n\\item{(vi)} Show that if $a\\,\\Delta t/\\Delta x^2\\le1/2$ then $-1\\le R<1$\nand so $|U^n_p|\\le1$ for all $n$~and $p$.\n\\end{description}\n\\begin{ans}\n(iii) $R=1-a\\lambda_k\\,\\Delta t$\\quad(iv) $\\lambda_k=(k\\pi/L)^2$\n\\end{ans}\n\n\\exercise\\label{ex: implicit Euler error}\nProve \\cref{thm: implicit Euler error} by adapting the proof of \n\\cref{thm: explicit Euler error}.\n\n\\exercise\nConsider the BDF2 (backward differentiation formula, second-order)\nscheme for the heat equation,\n\\[\n\\frac{3U^n_p-4U^{n-1}_p+U^{n-2}_p}{2\\Delta t}\n        -\\kappa\\,\\frac{U^n_{p+1}-2U^n_p+U^n_{p-1}}{\\Delta x^2}=f^n_p,\n\\]\nwhere $1\\le p\\le P-1$ and $2\\le n\\le N$.  Assume homogenous Dirichlet\nboundary conditions,\n\\[\nU^n_0=0=U^n_P\\quad\\text{for $1\\le n\\le N$,}\n\\]\nand initial conditions $U^0_p=v(x_p)$ for~$0\\le p\\le P$.\n\\begin{description}\n\\item{(i)} Draw the stencil for the BDF2 scheme.\n\\item{(ii)} Define the local truncation error~$\\tau(x,t)$ for this\nscheme and show that $\\tau=O(\\Delta t^2+\\Delta x^2)$.\n\\item{(iii)} Write the BDF2 scheme in matrix--vector form, and hence\ndescribe the linear system that must be solved at the $n$th time step\nfor~$2\\le n\\le N$.\n\\item{(iv)} To compute $U^n_p$ when~$n=1$, we use the implicit Euler\nscheme,\n\\[\n\\frac{U^1_p-U^0_p}{\\Delta t}\n        -\\kappa\\,\\frac{U^1_{p+1}-2U^1_p+U^1_{p-1}}{\\Delta x^2}=f^1_p.\n\\]\nWhy does the use of this method ensure that\n\\[\nU^1_p=u(x_p,t_1)+O(\\Delta t^2+\\Delta x^2),\n\\]\nwhen we saw in lectures that the implicit Euler method is only\nfirst-order accurate in time?  \n\\end{description}\n\n\\end{Exercises}\n", "meta": {"hexsha": "ccc24f45d6bd1820c74be20b719ac2f73bd8cd6e", "size": 37230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap3.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/chap3.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/chap3.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": 34.8922211809, "max_line_length": 81, "alphanum_fraction": 0.6334944937, "num_tokens": 16002, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735665, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7696201780899301}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{Non-negative variables}\\label{sec:expe}\n\nNext we define the expectation for random variables that take only non-negative values. \n\n\\begin{definition}[Expectation of non-negative random variables]\\label{def:expe_non-negative}\n\\ben\n\\it \nThe expectation of a non-negative \\emph{discrete} random variable $X$ is\n\\[\n\\expe(X) = \\sum_{i=1}^{\\infty} x_i f(x_i),\n\\]\nwhere $f$ is the PMF of $X$ and $\\{x_1,x_2,\\ldots\\}$ is the range of $X$.\n\\it \nThe expectation of a non-negative \\emph{continuous} random variable $X$ is\n\\[\n\\expe(X) = \\int_{-\\infty}^{\\infty} xf(x)\\,dx,\n\\]\nwhere $f$ is the PDF of $X$.\n\\een\n\\end{definition}\n\nNon-negative random variables can have \\emph{infinite expectation}.\n\n\\begin{example} % discrete, infinite\nA long line of athletes $k=0,1,2,\\ldots$ make throws of a javelin to distances $D_0,D_1,D_2,\\ldots$ respectively. Assume that the distances are independent and have the same distribution, and that the probability of any two throws being exactly the same distance is equal to zero. Let $X$ be the number of throws until the initial distance $D_0$ is surpassed for the first time. Find the PMF of $X$, and show that $\\expe(X)$ is infinite.\n\\begin{solution}\nFirst we need to find the PMF of $X$:\n\\bit\n\\it $X$ is a discrete random variable, taking values in the set $\\{1,2,\\ldots\\}$.\n\\it The event $\\{X>k\\}$ means that out of the first $k+1$ throws, the initial throw was the furthest.\n\\it Because the distances $D_0,D_1,\\ldots,D_k$ have the same distribution, each has the same probability of being the largest, so $\\displaystyle\\prob(X>k)=\\frac{1}{k+1}$.\n\\eit\nHence, the PMF of $X$ is \n\\[\n\\prob(X=k) = \\prob(X>k-1) - \\prob(X>k) = \\frac{1}{k} - \\frac{1}{k+1} = \\frac{1}{k(k+1)},\n\\]\nand its expected value is therefore\n\\[\n\\expe(X)\n\t= \\sum_{k=1}^\\infty k\\,\\prob(X=k)\n\t= \\sum_{k=1}^\\infty \\frac{1}{k+1} \n\t= \\frac{1}{2} + \\frac{1}{3} + \\frac{1}{4} + \\ldots\n\t= \\infty.\n\\]\n\\end{solution}\n\\end{example}\n\n\\begin{example}[Pareto distrubtion] % continuous, infinite (pareto)\nLet $X$ be a continuous random variable with the following PDF:\n\\[\nf(x) = \\begin{cases}\n\t1/x^2\t\t& \\text{for}\\quad x > 1, \\\\\n\t0\t\t\t& \\text{otherwise.} \n\\end{cases}\n\\]\nShow that $\\expe(X)$ is infinite.\n\\begin{solution}\n$X$ is non-negative, so \n\\[\n\\expe(X) \n\t= \\int_{0}^{\\infty} x f(x)\\,dx\n\t= \\int_{1}^{\\infty} \\frac{1}{x}\\,dx\n\t= \\infty.\n\\]\nTo be explicit:\n\\[\n\\int_{1}^{\\infty} \\frac{1}{x}\\,dx\n\t= \\lim_{n\\to\\infty} \\int_{1}^{n} \\frac{1}{x}\\,dx\n\t= \\lim_{n\\to\\infty} \\big[\\log(x)\\big]_{1}^{n}\n\t= \\lim_{n\\to\\infty} \\big[\\log(n) - \\log(1)\\big]\n\t= \\lim_{n\\to\\infty} \\log(n)\n\t= \\infty.\n\\]\n\\end{solution}\n\\end{example}\n\n\n\n\n", "meta": {"hexsha": "519715bb3f5139cdce04343fe1aa356a85e4cab2", "size": 2679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/04B_nonnegative.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/04B_nonnegative.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/04B_nonnegative.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": 32.2771084337, "max_line_length": 437, "alphanum_fraction": 0.6502426278, "num_tokens": 969, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.8615382076534742, "lm_q1q2_score": 0.7696201772307365}}
{"text": "%!TEX root =  ../main.tex\n\n\\subsection{At Infinities}\n\n\\objective{Determine when a limit does and does not exist, or is infinite.}\n\n\\personfeature[0in]{\\chapdir/pics/Augustin_Cauchy.jpg}{Augustin-Louis Cauchy}{1789-1857}{was a French mathematician and physicist who made pioneering contributions to analysis. His book \\textit{Cours d'Analyse} is frequently noted as being the first place that inequalities, and $ \\delta -\\epsilon$ arguments were introduced into Calculus. \\href{https://en.wikipedia.org/wiki/Augustin-Louis_Cauchy}{Wikipedia}}\n\n\n\nBecause limits are asking questions that need not have simple, numeric inputs, nor\nsimple, numeric outputs, we can evaluate limits involving infinities.\n``Infinity'' simply means ``without end''.  Asking what a function approaches as\n$x$ approaches infinity, graphically means ``what value is the output tending\ntowards as the input grows without bound?''.  Negative infinity is a term describing\nthe leftward trend of a function.  \n\n\n\\begin{derivation}{Limit at Infinity}\nFor $f(x)$ which is a real function, the limit of $f$ as $x$ approaches infinity is L, \nmeans that for all  $\\varepsilon >0$, there exists $c$ such \nthat $|f(x) - L| < \\varepsilon \\, \\text{ whenever } \\,  x > c$. This is written in logic symbols are\n$\\forall \\varepsilon >  0 \\; \\exists c \\; \\forall x > c :\\; |f(x) - L| < \\varepsilon$.\n\n$$\\lim _{x\\to \\infty }f(x)=L$$\n\n\\end{derivation}\n\n\nThe same applies at negative infinity:\n\n\n\\begin{derivation}{Limit at Negative Infinity}\\index{limit!at infinities}\nFor $f(x)$ a real function, the limit of $f$ as $x$ approaches negative infinity is L, \nmeans that for all $\\varepsilon >0$ there exists $c$ such that \n$ |f(x) - L| < \\varepsilon \\, \\text{ whenever } \\, x < c$. \n\n\n$$ \\lim_{x \\to -\\infty}f(x) = L$$\n\n\\end{derivation}\n\n\n\\begin{example}{All the way to the left}\n\t\\exProblem\nEvaluate $\\displaystyle \\lim_{x \\to -\\infty}2^x$\n\t\\exSolution\nWe can observe the graph or compute numerically that $2^x$ is getting closer\nand closer to 0 as we move leftward.  We can get arbitrarily close to 0 by picking\nwhatever large, negative exponent we wish.  Hence, the answer is 0.\n\\end{example}\n\n\n\n\n\\subsection{Infinite Forms}\nNot only can we ``plug in'' infinities in limits problems, but we can also get\n$\\pm\\infty$ as an answer.  Recall, however, that the left and right sided limits\nmust agree for the limit to exist.  Hence, we can say that the limit as $x$ \napproaches 0 of $x^{-2}$ is infinity, while the same limit taken on $\\frac{1}{x}$\ndoes not exist.\n\n\nThe limit of $f$ as $x$ approaches $a$ is infinity, denoted:\n\n$$\\lim_{x \\to a} f(x) = \\infty$$\nmeans that for all $\\varepsilon >0 \\, \\text{there exists} \\, \\delta >0 \\, \\text{such that} \\, f(x) > \\varepsilon \\, \\text{whenever}  \\, |x - a| < \\delta$.\n\nFor example:\n\n$$ \\lim_{x \\to 0^+} \\ln x = -\\infty$$\n", "meta": {"hexsha": "e9a4bafaf90711ee0ccc969444a491cd131ef244", "size": 2820, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/0204.tex", "max_stars_repo_name": "aquatiki/AnalysisTextbook", "max_stars_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2017-10-08T15:05:17.000Z", "max_stars_repo_stars_event_max_datetime": "2019-07-07T12:32:53.000Z", "max_issues_repo_path": "ch02/0204.tex", "max_issues_repo_name": "aquatiki/AnalysisTextbook", "max_issues_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ch02/0204.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.1666666667, "max_line_length": 410, "alphanum_fraction": 0.7078014184, "num_tokens": 851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942145139149, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7695640319637456}}
{"text": "\\section{Trigonometric Substitutions}{}{}\\label{sec:Trig Sub}\nSo far we have seen that it sometimes helps to replace a subexpression\nof a function by a single variable. Occasionally it can help to\nreplace the original variable by something more complicated. This\nseems like a ``reverse'' substitution, but it is really no different\nin principle than ordinary substitution.\n\n\\begin{example}{Sine Subsitution}{Sine Subsitution}\nEvaluate $\\ds\\int \\sqrt{1-x^2}\\,dx$. \n\\end{example}\n\n\\begin{solution}\nLet $x=\\sin u$ so \n$dx=\\cos u\\,du$. Then\n$$\n  \\int \\sqrt{1-x^2}\\,dx=\\int\\sqrt{1-\\sin^2 u}\\cos u\\,du=\n  \\int\\sqrt{\\cos^2 u}\\cos u\\,du.\n$$\nWe would like to replace $\\ds \\sqrt{\\cos^2 u}$ by $\\cos u$, but this is\nvalid only if $\\cos u $ is positive, since $\\ds \\sqrt{\\cos^2 u}$ is\npositive. Consider again the substitution $x=\\sin u$. We could just as\nwell think of this as $u=\\arcsin x$. If we do, then by the definition\nof the arcsine, $-\\pi/2\\le u\\le\\pi/2$, so $\\cos u\\ge0$. Then we\ncontinue:\n\\begin{eqnarray*}\n  \\int\\sqrt{\\cos^2 u}\\cos u\\,du&=&\\int\\cos^2u\\,du\\\\\n\t&=&\\int {1+\\cos 2u\\over2}\\,du = {u\\over 2}+{\\sin 2u\\over4}+C\\cr\n  &=&{\\arcsin x\\over2}+{\\sin(2\\arcsin x)\\over4}+C.\n\\end{eqnarray*}\nThis is a perfectly good answer, though the term\n$\\sin(2\\arcsin x)$ is a bit unpleasant. It is possible to simplify\nthis. Using the identity $\\sin 2x=2\\sin x\\cos x$, we can write\n$\\ds \\sin 2u=2\\sin u\\cos u=2\\sin(\\arcsin x)\\sqrt{1-\\sin^2 u}=\n2x\\sqrt{1-\\sin^2(\\arcsin x)}=2x\\sqrt{1-x^2}.$ Then the full\nantiderivative is \n$$\n  {\\arcsin x\\over2}+{2x\\sqrt{1-x^2}\\over4}=\n  {\\arcsin x\\over2}+{x\\sqrt{1-x^2}\\over2}+C.\n$$\n\\end{solution}\n\nThis type of substitution is usually indicated when the function you\nwish to integrate contains a polynomial expression that might allow\nyou to use the fundamental identity $\\ds \\sin^2x+\\cos^2x=1$ in\none of three forms:\n$$\n  \\cos^2 x=1-\\sin^2x\n  \\qquad\n  \\sec^2x=1+\\tan^2x\n  \\qquad\n  \\tan^2x=\\sec^2x-1.\n$$\nIf your function contains $\\ds 1-x^2$, as in the example above, try\n$x=\\sin u$; if it contains $\\ds 1+x^2$ try $x=\\tan u$; and if it contains\n$\\ds x^2-1$, try $x=\\sec u$. Sometimes you will need to try something a\nbit different to handle constants other than one which we will describe below.\nFirst we discuss inverse substitutions.\n\nIn a {\\bf traditional} substitution we let $u=u(x)$, i.e., our new variable is defined in terms of $x$.  \nIn an {\\bf inverse} substitution we let $x=g(u)$, i.e., we assume $x$ can be written in terms of $u$.  \nWe cannot do this arbitrarily since we do \\thmfont{NOT} get to ``choose'' $x$.\nFor example, an inverse substitution of $x=1$ will give an obviously wrong answer.  \nHowever, when $x=g(u)$ is an invertible function, then we are really doing a $u$-substitution with $u=g^{-1}(x)$.  \nNow the substitution rule applies.\n\nSometimes with inverse substitutions involving trig functions we use $\\theta$ instead of $u$. \nThus, we would take $x=\\sin\\theta$ instead of $x=\\sin u$. \nHowever, as we discussed above, we would like our inverse substitution $x=g(u)$ to be a one-to-one function, and $x=\\sin u$ is not one-to-one.\nWe can overcome this issue by using the restricted trigonometric functions.\nThe three common trigonometric substitutions are the restricted sine, restricted tangent and restricted secant.\nThus, for sine we use the domain $[-\\pi/2,~\\pi/2]$ and for tangent we use $(-\\pi/2,~\\pi/2)$.\nDepending on the convention chosen, the restricted secant function is usually defined in one of two ways.\n$$\\includegraphics[width=6in]{images2/inv-trig-sec}$$\nOne convention is to restrict secant to the region $[0,~\\pi/2)\\cup(\\pi/2,\\pi]$ as shown in the middle graph.\nThe other convention is to use $[0,~\\pi/2)\\cup[\\pi,~3\\pi/2)$ as shown in the right graph.\nBoth choices give a one-to-one restricted secant function and no universal convention has been adopted.\nTo make the analysis in this section less cumbersome, we will use the domain $[0,~\\pi/2)\\cup[\\pi,~3\\pi/2)$ for the restricted secant function.\nThen $\\sec^{-1}x$ is defined to be the inverse of this restricted secant function.\n\nTypically trigonometric substitions are used for problems that involve radical expressions.\nThe table below outlines when each substitution is typically used along with their intervals of validity.\n\n\n%$$\\begin{array}{|c|c|c|}\n%\\hline\n%\\mbox{\\thmfont{Expression}} & \\mbox{\\exfont{Substitution}} & \\mbox{\\deffont{Validity}}\\\\\n%\\hline ~ & ~ & ~ \\\\\n%\\sqrt{a^2-x^2} & x=a\\sin\\theta & \\theta\\in[-\\pi/2,~\\pi/2]\\\\\n%~ & ~ & ~ \\\\\\hline~ & ~ & ~ \\\\\n%\\sqrt{a^2+x^2}~~\\mbox{or}~~a^2+x^2 & x=a\\tan\\theta & \\theta\\in(-\\pi/2,~\\pi/2)\\\\\n%~ & ~ & ~ \\\\\\hline~ & ~ & ~ \\\\\n%\\sqrt{x^2-a^2} & x=a\\sec\\theta & \\theta\\in[0,~\\pi/2)\\cup[\\pi,~3\\pi/2)\\\\\n%~ & ~ & ~ \\\\\\hline\n%\\end{array}$$\n\n\\begin{formulabox}[Trigonometric Substitution]\n\\begin{enumerate}\n\t\\item[(a)] \\noindent%\n\t\t\\begin{minipage}[t]{.6\\linewidth}%\n\t\tFor integrands containing $\\sqrt{a^2-x^2}$:\\index{integration!trig. subst.}\\\\[5pt]\n\t\tLet $x=a\\sin\\theta$, \\qquad $dx = a\\cos\\theta\\ d\\theta$\\\\[5pt]\t\n\tThus $\\theta = \\sin^{-1}(x/a)$, for $-\\pi/2\\leq \\theta\\leq \\pi/2$. \\\\[5pt]\t\n\tOn this interval, $\\cos\\theta\\geq 0$, so\\\\[5pt]\t\n\t$\\sqrt{a^2-x^2} = a\\cos\\theta$\n\t\t\\end{minipage}\\qquad\n\t\\begin{minipage}[t]{.4\\linewidth}\\vskip 0pt\n\t\t\\begin{tikzpicture}\n\t\t\t\t\\draw [very thick] (0,0) -- node[below,pos=.5] { $\\sqrt{a^2-x^2}$} (3,0) -- node [right,pos=.5] { $x$} (3,2) -- node [pos=.5,above] { $a$} (0,0);\n\t\t\t\t\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\t\t\t\t\\draw (.75,.25) node {$\\theta$};\t\t\n\t\t\\end{tikzpicture}\n\t\t\\end{minipage}\n\t\t\n\t\\item[(b)] \\noindent\n\t\\begin{minipage}[t]{.6\\linewidth}\n\t\tFor integrands containing $\\sqrt{x^2+a^2}$:\\\\[5pt]\n\t\tLet $x=a\\tan\\theta$, \\qquad $dx = a\\sec^2\\theta\\ d\\theta$\\\\[5pt]\t\n\tThus $\\theta = \\tan^{-1}(x/a)$, for $-\\pi/2 < \\theta < \\pi/2$. \\\\[5pt]\t\n\tOn this interval, $\\sec\\theta> 0$, so\\\\[5pt]\t\n\t$\\sqrt{x^2+a^2} = a\\sec\\theta$\n\t\t\\end{minipage}\\qquad\n\t\\begin{minipage}[t]{.4\\linewidth}\\vskip 0pt\n\t\\begin{tikzpicture}\n\t\t\t\\draw [very thick] (0,0) -- node[below,pos=.5] { $a$} (3,0) -- node [right,pos=.5] { $x$} (3,2) -- node [pos=.5,above,sloped] { $\\sqrt{x^2+a^2}$} (0,0);\n\t\t\t\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\t\t\t\\draw (.75,.25) node {$\\theta$};\t\n\t\\end{tikzpicture}\n\t\t\\end{minipage}\n\t\t\n\t\\item[(c)] \\noindent\n\t\\begin{minipage}[t]{.6\\linewidth}\n\t\tFor integrands containing $\\sqrt{x^2-a^2}$:\\\\[5pt]\n\t\tLet $x=a\\sec\\theta$, \\qquad $dx = a\\sec\\theta\\tan\\theta\\ d\\theta$\\\\[5pt]\t\n\tThus $\\theta = \\sec^{-1}(x/a)$. If $x/a\\geq 1$, then $0\\leq\\theta<\\pi/2$; if $x/a \\leq -1$, then $\\pi\\le\\theta< 3\\pi/2$.\\\\[5pt]\t\n\tWe restrict our work to where $x\\geq a$, so $x/a\\geq 1$, and $0\\leq\\theta<\\pi/2$.\n\tOn this interval, $\\tan\\theta\\geq 0$, so\\\\[5pt]\t\n\t$\\sqrt{x^2-a^2} = a\\tan\\theta$\n\t\t\\end{minipage}\\qquad\n\t\\begin{minipage}[t]{.4\\linewidth}\\vskip 0pt\n\t\t\\begin{tikzpicture}\n\t\t\t\t\\draw [very thick] (0,0) -- node[below,pos=.5] { $a$} (3,0) -- node [right,pos=.5] { $\\sqrt{x^2-a^2}$} (3,2) -- node [pos=.5,above] { $x$} (0,0);\n\t\t\t\t\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\t\t\t\t\\draw (.75,.25) node {$\\theta$};\t\t\t\n\t\t\\end{tikzpicture}\n\t\t\\end{minipage}\t\n\\end{enumerate}\n\n\\end{formulabox}\n\nAll three substitutions are one-to-one on the listed intervals.\nWhen dealing with radicals we often end up with absolute values since\n$$\\sqrt{z^2}=|z|.$$\nFor each of the three trigonometric substitions above we will verify that we can ignore the absolute value in each case when encountering a radical.\n\nFor $x=a\\sin\\theta$, the expression $\\sqrt{a^2-x^2}$ becomes\n$$\\sqrt{a^2-x^2}\n= \\sqrt{a^2-a^2\\sin^2\\theta}\n= \\sqrt{a^2(1-\\sin^2\\theta)}\n= a\\sqrt{\\cos^2\\theta}\n= a|\\cos\\theta|\n= a\\cos\\theta$$ \nThis is because $\\cos\\theta\\geq 0$ when $\\theta\\in[-\\pi/2,~\\pi/2]$. \nFor $x=a\\tan\\theta$, the expression $\\sqrt{a^2+x^2}$ becomes\n$$\\sqrt{a^2+x^2}\n= \\sqrt{a^2+a^2\\tan^2\\theta}\n= \\sqrt{a^2(1+\\tan^2\\theta)}\n= a\\sqrt{\\sec^2\\theta}\n= a|\\sec\\theta|\n= a\\sec\\theta$$ \nThis is because $\\sec\\theta>0$ when $\\theta\\in(-\\pi/2,~\\pi/2)$. \n\nFinally, for $x=a\\sec\\theta$, the expression $\\sqrt{x^2-a^2}$ becomes\n$$\\sqrt{x^2-a^2}\n= \\sqrt{a^2\\sec^2\\theta-a^2}\n= \\sqrt{a^2(\\sec^2\\theta-1)}\n= a\\sqrt{\\tan^2\\theta}\n= a|\\tan\\theta|\n= a\\tan\\theta$$\nThis is because $\\tan\\theta\\geq 0$ when $\\theta\\in[0,~\\pi/2)\\cup[\\pi,~3\\pi/2)$. \n\nThus, when using an appropriate trigonometric substitution we can usually ignore the absolute value. \nAfter integrating, we typically get an answer in terms of $\\theta$ (or $u$) and need to convert back to $x$'s.\nTo do so, we use the two guidelines below:\n\\begin{itemize}\n\t\\item For trig functions containing $\\theta$, use a triangle to convert to $x$'s.\n\t\\item For $\\theta$ by itself, use the inverse trig function.\n\\end{itemize}\n\nAll pieces needed for such a trigonometric substitution can be summarized as follows:\n\\[\\begin{array}{|c|c|c|c|c|}\\hline\t%5 columns\n\t\t&\t&\t&\t&\t\\text{\\textbf{Inverse of}}\t\\\\\n\\text{\\textbf{Expression}}\t&\t\\text{\\textbf{Substitution}}\t&\t\\text{\\textbf{Differential}}\t&\t\\text{\\textbf{Identity}}\t&\t\\text{\\textbf{Substitution}}\t\\\\\t\\hline\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\n\\sqrt{a^2-x^2}\t&\tx=a\\sin\\theta\t&\tdx=a\\cos\\theta d\\theta\t&\t\\sqrt{a^2-x^2}=a\\cos\\theta\t&\t\\theta=\\sin^{-1}\\left(\\frac{x}{a}\\right)\t\\\\\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\t\\hline\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\n\\sqrt{a^2+x^2}\t&\t&\t&\t&\t\\\\\n \\text{or} \t&\tx=a\\tan\\theta\t&\tdx=a\\sec^2\\theta d\\theta\t&\t\\sqrt{a^2+x^2}=a\\sec\\theta\t&\t\\theta=\\tan^{-1}\\left(\\frac{x}{a}\\right)\t\\\\\na^2+x^2 \t&\t&\t&\t&\t\\\\\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\t\\hline\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\n\\sqrt{x^2-a^2}\t&\tx=a\\sec\\theta\t&\tdx=a\\sec\\theta\\tan\\theta d\\theta\t&\t\\sqrt{x^2-a^2}=a\\tan\\theta\t&\t\\theta=\\sec^{-1}\\left(\\frac{x}{a}\\right)\t\\\\\n~\t&\t~\t&\t~\t&\t~\t&\t~\t\\\\\t\\hline\n\\end{array}\\]\n\nTo emphasize the technique, we redo the computation for $\\ds\\int \\sqrt{1-x^2}\\,dx$.\n\n\\begin{example}{Sine Subsitution}{Sine Subsitution}\nEvaluate $\\ds\\int \\sqrt{1-x^2}\\,dx$. \n\\end{example}\n\n\\begin{solution}\nSince $\\sqrt{1-x^2}$ appears in the integrand we try the trigonometric substitution $x=\\sin\\theta$.\n(Here we are using the restricted sine function with $\\theta\\in[-\\pi/2,~\\pi/2]$ but typically omit this detail when writing out the solution.)\nThen $\\fbox{$dx$}=\\fbox{$\\cos \\theta\\,d\\theta$}$.  \n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\t\\int \\sqrt{1-x^2}\\,\\fbox{$dx$} & = & \\int\\sqrt{1-\\sin^2\\theta}\\,\\fbox{$\\cos \\theta\\,d\\theta$} &\\mbox{Using our (inverse) substitution}\\\\  \n\t& = & \\int \\sqrt{\\cos^2\\theta}\\cos \\theta\\,d\\theta &\\mbox{Since $\\sin^2\\theta+\\cos^2\\theta=1$}\\\\  \n\t& = & \\int |\\cos\\theta|\\cdot\\cos\\theta\\,d\\theta & \\mbox{Since $\\sqrt{\\cos^2\\theta}=|\\cos\\theta|$}\\\\  \n\t& = & \\int \\cos^2\\theta\\,d\\theta & \\mbox{Since for $\\theta\\in[-\\frac{\\pi}{2},\\frac{\\pi}{2}]$ we have $\\cos\\theta\\geq0$.}\\\\  \n\\end{array}$$\nOften we omit the step containing the absolute value by our discussion above.\nNow, to integrate a power of cosine we use the guidelines for products of sine and cosine and make use of the identity \n $$\\cos^2\\theta=\\frac{1}{2}(1+\\cos(2\\theta)).$$\nOur integral then becomes\n$$\\int \\sqrt{1-x^2}\\,dx=\\frac{1}{2}\\int (1+\\cos(2\\theta))\\,d\\theta=\\frac{\\theta}{2}+\\frac{\\sin(2\\theta)}{4}+C$$\nTo write the answer back in terms of $x$ we first use the identity $ \\sin(2\\theta) = 2\\sin\\theta \\cos\\theta $. So\n$$\\int \\sqrt{1-x^2}\\,dx= \\frac{\\theta}{2}+\\frac{\\sin(\\theta)\\cos(\\theta)}{2}+C$$\n\n%$$\\includegraphics[width=1.65in]{images2/inv-trig-triangle-1}$$ \n\\begin{minipage}{.7\\textwidth}\nSince\t $x=\\sin\\theta$, we can build the corresponding triangle and use SOH CAH TOA  we get $ \\cos\\theta = \\frac{\\sqrt{1-x^2}}{1} = \\sqrt{1-x^2}.$\n\tThis gives\n\t$$\\int \\sqrt{1-x^2}\\,dx =\\frac{\\sin^{-1}x}{2}+\\frac{x\\sqrt{1-x^2}}{2}+C$$\n\\end{minipage}\n\\begin{minipage}{.3\\textwidth}\n\t\\begin{tikzpicture}\n\t\\draw [very thick, fill=green!20] (0,0) -- node[below,pos=.5] { $\\sqrt{1-x^2}$} (3,0) -- node [right,pos=.5] { $x$} (3,2) -- node [pos=.5,above,sloped] { $ 1 $} (0,0);\n\t\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\t\\draw (.75,.25) node {$\\theta$};\t\n\t\\end{tikzpicture}\n\\end{minipage}\n\n\\end{solution}\n\n\\begin{example}{Secant Subsitution}{Secant Subsitution} \nEvaluate $\\ds\\int\\frac{\\sqrt{25x^2-4}}{x}\\,dx$.\n\\end{example}\n\n\\begin{solution}\nWe do not have $\\sqrt{x^2-a^2}$ because of the $25$, but if we factor $25$ out we get: \n$$\\ds\\int\\frac{\\sqrt{25(x^2-(4/25))}}{x}\\,dx=\\ds\\int5\\frac{\\sqrt{x^2-(4/25)}}{x}\\,dx.$$\nNow, $a=2/5$, so let $x=\\frac{2}{5}\\sec\\theta$. \nAlternatively, we can think of the integral as being:\n$$\\ds\\int\\frac{\\sqrt{(5x)^2-4}}{x}\\,dx$$ \nThen we could let $u=5x$ followed by $u=2\\sec\\theta$, etc. \nOr equivalently, we can avoid a $u$-substitution by letting $5x=2\\sec\\theta$. \nIn either case we are using the trigonometric substitution $x=\\frac{2}{5}\\sec\\theta$, but do use the method that makes the most sense to you!\nAs $x=\\frac{2}{5}\\sec\\theta$ we have $\\fbox{$dx$}=\\fbox{$\\frac{2}{5}\\sec\\theta\\tan\\theta\\,d\\theta$}$.  \n$$\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n\t\\int\\frac{\\sqrt{25x^2-4}}{x}\\,\\fbox{$dx$} & = & \\int \\frac{\\sqrt{25\\frac{4\\sec^2\\theta}{25}-4}}{\\frac{2}{5}\\sec\\theta}\\,\\fbox{$\\frac{2}{5}\\sec\\theta\\tan\\theta\\,d\\theta$} &\\mbox{Using the substitution}\\\\  \n\t& = & \\int\\sqrt{4(\\sec^2\\theta-1)}\\cdot \\tan\\theta\\,d\\theta & \\mbox{Cancelling}\\\\ \n\t& = & 2\\int\\sqrt{\\tan^2\\theta}\\cdot \\tan\\theta\\,d\\theta & \\mbox{Using $\\tan^2\\theta+1=\\sec^2\\theta$}\\\\ \n\t%& = & 2\\int\\tan\\theta\\cdot \\tan\\theta\\,d\\theta & \\mbox{Since $\\sqrt{\\tan^2\\theta}=|\\tan\\theta|=\\tan\\theta$}\\\\ \n\t& = & 2\\int\\tan^2\\theta\\,d\\theta & \\mbox{Simplifying}\\\\ \n\t& = & 2\\int(\\sec^2\\theta-1)\\,d\\theta & \\mbox{Using $\\tan^2\\theta+1=\\sec^2\\theta$}\\\\ \n\t& = & 2(\\tan\\theta-\\theta)+C & \\mbox{Since $\\ds\\int\\sec^2\\theta\\,d\\theta=\\tan\\theta+C$}\\\\ \n\\end{array}$$\n\n\n\\begin{minipage}{.6\\textwidth}\nTo solve for $\\tan\\theta$, we build a triangle where $ \\sec\\theta = \\frac{5x}{2} $, or equivalently, $\\cos\\theta=\\frac{2}{5x}$.\nUsing SOH CAH TOA, the triangle is as shown at the right:  \n\\end{minipage}\n\\begin{minipage}{.4\\textwidth}\n\\begin{center}\n\t\\begin{tikzpicture}\n\\draw [very thick, fill=green!20] (0,0) -- node[below,pos=.5] { $2$} (3,0) -- node [right,pos=.5] { $\\sqrt{25x^2-4}$} (3,2) -- node [pos=.5,above] { $5x$} (0,0);\n\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\\draw (.75,.25) node {$\\theta$};\t\t\t\n\\end{tikzpicture}\n\\end{center}\n\\end{minipage}\nFrom the triangle, we get $ \\ds \\tan\\theta = \\frac{\\sqrt{25x^2-4}}{2}  $.  \n%$$\\includegraphics[height=1.5in]{images2/inv-trig-triangle-6}$$\nAs $\\theta=\\sec^{-1}(5x/2)$, we get\n$$\\ds\\int\\frac{\\sqrt{25x^2-4}}{x}\\,dx=2\\left(\\frac{\\sqrt{25x^2-4}}{2}-\\sec^{-1}\\left(\\frac{5x}{2}\\right)\\right)+C$$\n\\end{solution}\n\nIn the context of the previous example, some resources give alternate guidelines when choosing a trigonometric substitution.\n\\begin{center}\\begin{tabular}{@{}ll@{}ll@{}}\n\t$\\sqrt{a^2-b^2x^2}\\quad\\to\\quad x=\\ds\\frac{a}{b}\\sin\\theta$\\\\\n\t\\vspace{-0.1cm}\\\\\n\t$\\sqrt{b^2x^2+a^2}~~\\mbox{or}~~(b^2x^2+a^2)\\quad\\to\\quad x=\\ds\\frac{a}{b}\\tan\\theta$\\\\\n\t\\vspace{-0.1cm}\\\\\n\t$\\sqrt{b^2x^2-a^2}\\quad\\to\\quad x=\\ds\\frac{a}{b}\\sec\\theta$\\\\\n\\end{tabular}\\end{center}\n\nWe next look at a tangent substitution.\n\n%\\begin{example}{Tangent Substitution}{Tangent Substitution}\n%Evaluate $\\ds\\int\\frac{1}{\\sqrt{25+x^2}}\\,dx$.\n%\\end{example}\n\n%\\begin{solution}\n%Let $x=5\\tan\\theta$ so that $\\fbox{$dx$}=\\fbox{$5\\sec^2\\theta\\,d\\theta$}$.  \n%$${\\def\\arraystretch{2.2}\n%\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\n%\t\\int\\frac{1}{\\sqrt{25+x^2}}\\,\\fbox{$dx$} & = & \\int \\frac{1}{\\sqrt{25+25\\tan^2\\theta}}\\,\\fbox{$5\\sec^2\\theta\\,d\\theta$} &\\mbox{Using our substitution}\\\\  \n%\t& = & \\int\\frac{1}{\\sqrt{25(1+\\tan^2\\theta)}}\\cdot5\\sec^2\\theta\\,d\\theta & \\mbox{Factor out $25$}\\\\ \n%\t& = & \\int\\frac{1}{5\\sqrt{sec^2\\theta}}\\cdot5\\sec^2\\theta\\,d\\theta & \\mbox{Using $\\tan^2\\theta+1=\\sec^2\\theta$}\\\\ \n%%\t& = & \\int\\frac{1}{5\\sec\\theta}\\cdot5\\sec^2\\theta\\,d\\theta & \\mbox{Can ignore absolute value (why?)}\\\\ \n%\t& = & \\int\\sec\\theta\\,d\\theta & \\mbox{Simplifying}\\\\ \n%\t& = & \\ln|\\sec\\theta+\\tan\\theta|+C & \\mbox{By $\\ds\\int\\sec \\theta\\,dx=\\ln|\\sec \\theta+\\tan \\theta|+C$}\\\\\n%\\end{array}\n%}$$\n%Since $\\tan\\theta=x/5$, we draw a triangle:\n%$$\\includegraphics[height=1.5in]{images2/inv-trig-triangle-7}$$\n%Then $$\\ds\\sec\\theta=\\frac{1}{\\cos\\theta}=\\frac{\\sqrt{25+x^2}}{5}.$$\n%Therefore, the integral is\n%$$\\int\\frac{1}{\\sqrt{25+x^2}}\\,dx=\\ln\\left|\\frac{\\sqrt{25+x^2}}{5}+\\frac{x}{5}\\right|+C$$\n%\\end{solution}\n\n\n\\begin{example}{Tangent Substitution}{Tangent Substitution}\nEvaluate $\\ds \\int \\frac{1}{\\sqrt{5+x^2}}\\ dx.$\n\\end{example}\n\n\\begin{solution}\nUsing part (b), we recognize $a=\\sqrt{5}$ and  set $x= \\sqrt{5}\\tan \\theta$. This makes $dx = \\sqrt{5}\\sec^2\\theta\\ d\\theta$. We will use the fact that $\\sqrt{5+x^2} = \\sqrt{5+5\\tan^2\\theta} = \\sqrt{5\\sec^2\\theta} = \\sqrt{5}\\sec\\theta.$ Substituting, we have:\n\\begin{align*}\n\\int \\frac{1}{\\sqrt{5+x^2}}\\ dx &= \\int \\frac{1}{\\sqrt{5+5\\tan^2\\theta}}\\sqrt{5}\\sec^2\\theta\\ d\\theta \\\\\n\t\t\t&= \\int \\frac{\\sqrt{5}\\sec^2\\theta}{\\sqrt{5}\\sec\\theta} \\ d\\theta\\\\\n\t\t\t&= \\int \\sec\\theta\\ d\\theta\\\\\n\t\t\t&= \\ln\\big|\\sec\\theta+\\tan\\theta\\big|+C.\n\\end{align*}\nWhile the integration steps are over, we are not yet done. The original problem was stated in terms of $x$, whereas our answer is given in terms of $\\theta$. We must convert back to $x$.\n\n\\begin{minipage}{.7\\textwidth}\nWith $x=\\sqrt{5}\\tan\\theta$, we have \n$$\\tan \\theta = \\frac x{\\sqrt{5}}\\quad \\text{and}\\quad \\sec\\theta = \\frac{\\sqrt{x^2+5}}{\\sqrt{5}}.$$\nThis gives\n\\end{minipage}\n\\begin{minipage}{.3\\textwidth}\n\\begin{tikzpicture}\n\t\t\t\\draw [very thick, fill=green!20] (0,0) -- node[below,pos=.5] { $\\sqrt{5}$} (3,0) -- node [right,pos=.5] { $x$} (3,2) -- node [pos=.5,above,sloped] { $\\sqrt{x^2+5}$} (0,0);\n\t\t\t\\draw [thick] (2.7,0) -- (2.7,.3) -- (3,.3);\n\t\t\t\\draw (.75,.25) node {$\\theta$};\t\n\t\\end{tikzpicture}\n\\end{minipage}\n\n\\begin{align*}\n\\int \\frac{1}{\\sqrt{5+x^2}}\\ dx &= \\ln\\big|\\sec\\theta+\\tan\\theta\\big|+C \\\\\n     &= \\ln\\left|\\frac{\\sqrt{x^2+5}}{\\sqrt{5}}+ \\frac x{\\sqrt{5}}\\right|+C.\n\\end{align*}\nWe can leave this answer as is, or we can use a logarithmic identity to simplify it. Note:\n\\begin{align*}\n\\ln\\left|\\frac{\\sqrt{x^2+5}}{\\sqrt{5}}+ \\frac x{\\sqrt{5}}\\right|+C &= \\ln\\left|\\frac{1}{\\sqrt{5}}\\big(\\sqrt{x^2+5}+ x\\big)\\right|+C \\\\\n   &= \\ln\\left|\\frac{1}{\\sqrt{5}}\\right| + \\ln\\big|\\sqrt{x^2+5}+ x\\big|+C\\\\\n\t&=\t\\ln\\big|\\sqrt{x^2+5}+ x\\big|+C,\n\\end{align*}\nwhere the $\\ln\\big(1/\\sqrt{5}\\big)$ term is absorbed into the constant $C$. %(In Section \\ref{sec:hyperbolic} we will learn another way of approaching this problem.)\n\\end{solution}\n\nIn the next example, we will use the technique of completing the square in order to rewrite the integrand.\n\n\\begin{example}{Completing the Square}{Completing the Square}\nEvaluate $\\ds\\int\\frac{x}{\\sqrt{3-2x-x^2}}\\,dx$.\n\\end{example}  \n\n\\begin{solution}\nFirst, complete the square to write \n$$3-2x-x^2=4-(x+1)^2$$ \nNow, we may let $u=x+1$ so that $du=dx$ (note that $x=u-1$) to get:\n$$\\int\\frac{x}{\\sqrt{4-(x+1)^2}}\\,dx=\\int\\frac{u-1}{\\sqrt{4-u^2}}\\,du$$ \nLet $u=2\\sin\\theta$ giving $du=2\\cos\\theta\\,d\\theta$: \n$$\\int\\frac{u-1}{\\sqrt{4-u^2}}\\,du = \\int\\frac{2\\sin\\theta-1}{2\\cos\\theta}\\cdot 2\\cos\\theta\\,d\\theta=\\int (2\\sin\\theta-1)\\,d\\theta$$\nIntegrating and using a triangle we get:\n\\begin{eqnarray*}\n\\int\\frac{x}{\\sqrt{3-2x-x^2}}\t& = &-2\\cos\\theta-\\theta+C  \\\\\n\t& = &-\\sqrt{4-u^2}-\\sin^{-1}\\left(\\frac{u}{2}\\right)+C  \\\\\n\t& = &-\\sqrt{3-2x-x^2}-\\sin^{-1}\\left(\\frac{x+1}{2}\\right)+C \n\\end{eqnarray*}\nNote that in this problem we could have skipped the $u$-substitution if instead we let $x+1=2\\sin\\theta$. (For the  triangle we would then use $\\ds\\sin\\theta=\\frac{x+1}{2}$.)\n\\end{solution}\n\n\n%\\bigskip\n%\\begin{example}{Another Inverse Sine Subsitution}{Another Inverse Sine Subsitution}\\label{Another Inverse Sine Subsitution}\n%Evaluate $\\ds\\int\\sqrt{4-9x^2}\\,dx$.\n%\\end{example}\n%\n%\\begin{solution}\n%We start by rewriting this so\n%that it looks more like the previous example:\n%$$\n  %\\int\\sqrt{4-9x^2}\\,dx=\\int\\sqrt{4(1-(3x/2)^2)}\\,dx\n  %=\\int 2\\sqrt{1-(3x/2)^2}\\,dx.\n%$$\n%Now let $3x/2=\\sin u$ so $(3/2)\\,dx=\\cos u \\,du$ or\n%$dx=(2/3)\\cos u\\,du$. Then\n%\\begin{eqnarray*}\n%\\int 2\\sqrt{1-(3x/2)^2}\\,dx&=&\\int 2\\sqrt{1-\\sin^2u}\\,(2/3)\\cos u\\,du\\cr\n%&=&{4\\over3}\\int \\cos^2u\\,du\\cr\n%&=&{4u\\over 6}+{4\\sin 2u\\over12}+C\\cr\n%&=&{2\\arcsin(3x/2)\\over3}+{2\\sin u \\cos u\\over3}+C\\cr\n%&=&{2\\arcsin(3x/2)\\over3}+{2\\sin(\\arcsin(3x/2))\\cos(\\arcsin(3x/2))\\over3}+C\\cr\n%&=&{2\\arcsin(3x/2)\\over3}+{2(3x/2)\\sqrt{1-(3x/2)^2}\\over3}+C\\cr\n%&=&{2\\arcsin(3x/2)\\over3}+{x\\sqrt{4-9x^2}\\over2}+C,\\cr\n%\\end{eqnarray*}\n%using some of the work from example~\\ref{Inverse Sine Subsitution}.\n%\\end{solution}\n%\n%\n%\n%\\bigskip\n%\\begin{example}{Inverse Tangent Subsitution}{Inverse Tangent Subsitution}\\label{Inverse Tangent Subsitution}\n%Evaluate $\\ds\\int\\sqrt{1+x^2}\\,dx$.\n%\\end{example}\n%\n%\\begin{solution}\n%Let $x=\\tan u$, \n%$\\ds dx=\\sec^2 u\\,du$, so\n%$$\n  %\\int\\sqrt{1+x^2}\\,dx=\\int \\sqrt{1+\\tan^2 u}\\sec^2u\\,du=\n  %\\int\\sqrt{\\sec^2u}\\sec^2u\\,du.\n%$$\n%Since $u=\\arctan(x)$, $-\\pi/2\\le u\\le\\pi/2$ and $\\sec u\\ge0$, so \n%$\\ds \\sqrt{\\sec^2u}=\\sec u$. Then\n%$$\\int\\sqrt{\\sec^2u}\\sec^2u\\,du=\\int \\sec^3 u \\,du.$$\n%Using the formula for the integral of $\\sec^3 u$ and reverting to the original variable $x$:\n%\\begin{eqnarray*}\n  %\\int\\sqrt{1+x^2}\\,dx&=&{\\sec u \\tan u\\over2}+{\\ln|\\sec u +\\tan\n    %u|\\over2}+C\\cr\n  %&=&{\\sec(\\arctan x) \\tan(\\arctan x)\\over2}\n    %+{\\ln|\\sec(\\arctan x) +\\tan(\\arctan x)|\\over2}+C\\cr\n  %&=&{ x\\sqrt{1+x^2}\\over2}\n    %+{\\ln|\\sqrt{1+x^2} +x|\\over2}+C,\\cr\n%\\end{eqnarray*}\n%using $\\tan(\\arctan x)=x$ and \n%$\\ds \\sec(\\arctan x)=\\sqrt{1+\\tan^2(\\arctan x)}=\\sqrt{1+x^2}$.\n%\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Trig Sub}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%%\n%\\begin{ex}\n %$\\ds\\int\\csc x\\,dx$\n%\\begin{sol}\n %$-\\ln|\\csc x+\\cot x|+C$\n%\\end{sol}\n%\\end{ex}\n%%%%%%%%%%%\n%\n%%%%%%%%%%%\n%\\begin{ex}\n %$\\ds\\int\\csc^3 x\\,dx$\n%\\begin{sol}\n %$-\\csc x\\cot x/2-(1/2)\\ln|\\csc x+\\cot x|+C$\n%\\end{sol}\n%\\end{ex}\n%%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int\\sqrt{x^2-1}\\,dx$\n\\begin{sol}\n $\\ds x\\sqrt{x^2-1}/2-\\ln|x+\\sqrt{x^2-1}|/2+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int\\sqrt{9+4x^2}\\,dx$\n\\begin{sol}\n $\\ds x\\sqrt{9+4x^2}/2+\\hbox{$\\ds(9/4)\\ln|2x+\\sqrt{9+4x^2}|+C$}$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x\\sqrt{1-x^2}\\,dx$\n\\begin{sol}\n $\\ds -(1-x^2)^{3/2}/3+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int x^2\\sqrt{1-x^2}\\,dx$\n\\begin{sol}\n $\\arcsin(x)/8-\\sin(4\\arcsin x)/32+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int{1\\over\\sqrt{1+x^2}}\\,dx$\n\\begin{sol}\n $\\ds \\ln|x+\\sqrt{1+x^2}|+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int\\sqrt{x^2+2x}\\,dx$\n\\begin{sol}\n $\\ds (x+1)\\sqrt{x^2+2x}/2-\\hbox{$\\ds\\ln|x+1+\\sqrt{x^2+2x}|/2+C$}$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int{1\\over x^2(1+x^2)}\\,dx$\n\\begin{sol}\n $-\\arctan x - 1/x+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int{x^2\\over\\sqrt{4-x^2}}\\,dx$\n\\begin{sol}\n $\\ds 2\\arcsin(x/2)-x\\sqrt{4-x^2}/2+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int{\\sqrt{x}\\over\\sqrt{1-x}}\\,dx$\n\\begin{sol}\n $\\ds \\arcsin(\\sqrt{x})-\\sqrt{x}\\sqrt{1-x}+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds\\int{x^3\\over\\sqrt{4x^2-1}}\\,dx$\n\\begin{sol}\n $\\ds (2x^2+1)\\sqrt{4x^2-1}/24+C$\n\\end{sol}\n\\end{ex}\n%%%%%%%%%%\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "f9fae3318abe842064d8064744ea251197beb112", "size": 23369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7-techniques-of-integration/7-3-trig-sub.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-3-trig-sub.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-3-trig-sub.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.8050089445, "max_line_length": 259, "alphanum_fraction": 0.620351748, "num_tokens": 9777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.9032942086563877, "lm_q1q2_score": 0.7695640286711249}}
{"text": "\\section{Volume}{}{}\\label{sec:volume}\nNow that we have seen how to compute certain areas by using integration; we will now look into how some\nvolumes may also be computed by evaluating an integral. Generally, the\nvolumes that we can compute this way have cross-sections that are easy\nto describe.\n\nThe volume of a general right cylinder, as shown in Figure \\ref{fig:cross1} has a simple calculation, it is  equal to base $\\times$ height. \\hfill\\null\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.2\\textwidth]{/figures/figcross1_3D}\n\\caption{The volume of a general right cylinder}\n\\label{fig:cross1}\n\\end{figure}\n\n\n\\noindent We can use this fact as the building block in finding volumes of a variety of shapes.\n\nGiven an arbitrary solid, we can \\textit{approximate} its volume by cutting it into $n$  thin slices. When the slices are thin, each slice can be approximated well by a general right cylinder. Thus the volume of each slice is approximately its cross-sectional area $\\times$ thickness. (These slices are the differential elements.)\n\nBy orienting a solid along the $x$-axis, we can let $A(x_i)$ represent the cross-sectional area\nof the $i\\,^\\text{th}$ slice, and let $\\dx_i$ represent the thickness of this slice (the thickness is a small change in $x$). The total volume of the solid is approximately:\n\t\\begin{align*} \\text{Volume} &\\approx \\sum_{i=1}^n \\Big[\\text{Area}\\ \\times\\ \\text{thickness}\\Big] \\\\\n\t\t\t&= \\sum_{i=1}^n A(x_i)\\dx_i.\n\t\\end{align*}\n\t\nRecognize that this is a Riemann Sum. By taking a limit (as the thickness of the slices goes to 0) we can find the volume exactly. \n\n\\begin{theorem}{Volume By Cross-Sectional Area}{volume_by_cross_section}\n{The volume $V$ of a solid, oriented along the $x$-axis with cross-sectional area $A(x)$ from $x=a$ to $x=b$, is \\index{integration!volume!cross-sectional area}\n$$V = \\int_a^b A(x)\\ dx.$$\n}\n\\end{theorem}\n\n\\begin{example}{Finding the volume of a solid}{ex_disk0}\n{\nFind the volume of a pyramid with a square base of side length $ 10 $ cm and a height of $ 5 $ cm.}\n\\end{example}\n\n\n\\begin{solution}\n{There are many ways to ``orient'' the pyramid along the $x$-axis; Figure \\ref{fig:disk0} gives one such way, with the pointed top of the pyramid at the origin and the $x$-axis going through the center of the base.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.35\\textwidth]{figures/figcross_area1}\n\\caption{Orienting a pyramid along the $x$-axis in Example \\ref{ex_disk0}.}\n\\label{fig:disk0}\n\\end{figure}\n\n\nEach cross section of the pyramid is a square; this is a sample differential element. To determine its area $A(x)$, we need to determine the side lengths of the square.\n\nWhen $x=5$, the square has side length $ 10 $; when $x=0$, the square has side length $ 0 $. Since the edges of the pyramid are lines, it is easy to figure that each cross-sectional square sitting above $ x $, has side length $2x$, giving $A(x) = (2x)^2=4x^2$. % \n\nIf one were to cut a slice out of the pyramid at $x=3$, as shown in Figure \\ref{fig:disk0a}, one would have a shape with square bottom and top with sloped sides. If the slice were thin, both the bottom and top squares would have sides lengths of about 6, and thus the cross--sectional area of the bottom and top would be about 36in$^2$. Letting $\\Delta x_i$ represent the thickness of the slice, the volume of this slice would then be about $36\\Delta x_i$in$^3$. \n\n\\begin{figure}\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/figcross_area1a_3D}\n\\caption{Cutting a slice in the pyramid in Example \\ref{ex_disk0} at $x=3$.}\n\\label{fig:disk0a}\n\\end{figure}\n\n\n\nCutting the pyramid into $n$ slices divides the total volume into $n$ equally--spaced smaller pieces, each with volume $(2x_i)^2\\Delta x$, where $x_i$ is the approximate location of the slice along the $x$-axis and $\\Delta x$ represents the thickness of each slice. One can approximate total volume of the pyramid by summing up the volumes of these slices:\n$$\\text{Approximate volume } = \\sum_{i=1}^n (2x_i)^2\\Delta x.$$\nTaking the limit as $n\\to\\infty$ gives the actual volume of the pyramid; recognizing this sum as a Riemann Sum allows us to find the exact answer using a definite integral, matching the definite integral given by Theorem \\ref{thm:volume_by_cross_section}.\n\nWe have \n\\begin{align*} V &= \\lim_{n\\to\\infty} \\sum_{i=1}^n (2x_i)^2\\Delta x\\\\\n\t\t\t\t\t\t\t&= \\int_0^5 4x^2\\ dx\\\\\n\t\t\t\t&= \\frac43x^3\\Big|_0^5 \\\\\n\t\t\t\t&=\\frac{500}{3}\\ \\text{cm}^3 \\approx 166.67\\ \\text{cm}^3.\n\\end{align*}\nWe can check our work by consulting the general equation for the volume of a pyramid (see the back cover under ``Volume of A General Cone''): \n\n\\hfill $\\frac13\\times \\text{area of base}\\times \\text{height}$.\\hfill \\null\n\n\\noindent Certainly, using this formula from geometry is faster than our new method, but the calculus--based method can be applied to much more than just cones.\n}\n\\end{solution}\n\n\\begin{example}{Volume of an Object}{Volume of an Object}\nThe base of a solid is the region between $\\ds f(x)=x^2-1$ and\n$\\ds g(x)=-x^2+1$, and its cross-sections perpendicular to the $x$-axis \nare equilateral triangles, as indicated in\nFigure~\\xrefn{fig:triangular cross-sections}.\n%\\texonly\nThe solid has been truncated to show a triangular\ncross-section above $x=1/2$.\n%\\endtexonly\nFind the volume of the solid.\n\\end{example}\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from -1.1 to 1.1, y from -1.1 to 1.1\n\\put {\\hbox{\\epsfxsize6truecm\\epsfbox{images/triangular_solid.eps}}} at 3 0\n\\axis bottom shiftedto y=0 ticks withvalues {$-1\\quad$} {$1$} / at -1 1 / /\n\\axis left shiftedto x=0 ticks withvalues {$-1\\quad$} {$1\\quad$} / at -1 1 / /\n\\plot\n-1.000 0.000 -0.900 -0.190 -0.800 -0.360 -0.700 -0.510 -0.600 -0.640 \n-0.500 -0.750 -0.400 -0.840 -0.300 -0.910 -0.200 -0.960 -0.100 -0.990 \n0.000 -1.000 0.100 -0.990 0.200 -0.960 0.300 -0.910 0.400 -0.840 \n0.500 -0.750 0.600 -0.640 0.700 -0.510 0.800 -0.360 0.900 -0.190 \n1.000 0.000 /\n\\plot\n-1.000 0.000 -0.900 0.190 -0.800 0.360 -0.700 0.510 -0.600 0.640 \n-0.500 0.750 -0.400 0.840 -0.300 0.910 -0.200 0.960 -0.100 0.990 \n0.000 1.000 0.100 0.990 0.200 0.960 0.300 0.910 0.400 0.840 \n0.500 0.750 0.600 0.640 0.700 0.510 0.800 0.360 0.900 0.190 \n1.000 0.000 /\n\\endpicture}}\n%\\begincaption\n%{Solid with equilateral triangles as cross-sections.\n%(\\expandafter\\url\\expandafter{\\liveurl jmol_triangular_x_sections}%\n%AP\\endurl)}\n%%(\\expandafter\\url\\expandafter{\\sageurl solid_with_triangular_x-sections}%\n%%AP\\endurl)}\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:triangular cross-sections}\n%\\htmlfigure{Integration_applications-volume_equilateral_x_sections.html}\n%\\htmlonly\n\\caption\n{Solid with equilateral triangles as cross-sections.\\label{fig:triangular cross-sections}}\n%You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/sage/solid_with_triangular_x-sections/solid_with_triangular_x-sections.sws\">Sage worksheet</a>\n%for this plot and upload it to your own sage account.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\n\\begin{solution}\nA cross-section taken at say $ x_i$ on the $x$-axis is a triangle with\nbase $\\ds 2(1-x_i^2)$ and height $\\ds \\sqrt3(1-x_i^2)$, so the area of the\ncross-section is \n$$\n A(x_i) {1\\over2}(\\hbox{base})(\\hbox{height})=\n  (1-x_i^2)\\sqrt3(1-x_i^2),\n$$\nand the volume of a thin ``slab'' is then\n$$(1-x_i^2)\\sqrt3(1-x_i^2)\\Delta x.$$\nThus the total volume is \n$$\\int_{-1}^1 A(x) \\; dx = \\int_{-1}^1 \\sqrt3(1-x^2)^2\\,dx={16\\over15}\\sqrt3.$$\n\\vskip-10pt\n\\end{solution}\n%\n%\n%\n%\nAn important special case of Theorem \\ref{thm:volume_by_cross_section} is when the solid is a \\textbf{solid of revolution}, that is, when the solid is formed by rotating a shape around some axis of rotation.\n\nStart with a function $y=f(x)$ from $x=a$ to $x=b$. Revolving this curve about a horizontal axis creates a three-dimensional solid whose cross sections are disks (thin circles). Let $R(x)$ represent the radius of the cross-sectional disk at $x$; the area of this disk is $\\pi R(x)^2$. Applying Theorem \\ref{thm:volume_by_cross_section} gives the Disk Method.\n\nFor example, in Figure~\\ref{fig:solid of rotation} \nwe see a plane region under a curve and between two\nvertical lines; then the result of rotating this around the $\\ds x$-axis, and\na typical circular cross-section is a circle.\n\n\\figure[H]\n%\\texonly\n\\centerline{\n\\vbox{\\hbox{\\hfill\\raise53pt\\vbox{\n\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <5.5truemm,5.5truemm>\n\\setplotarea x from 0 to 8, y from -4 to 4\n\\axis left /\n\\axis bottom shiftedto y=0 / \n\\putrule from 1 0 to 1 4 \n\\putrule from 6 0 to 6 3\n\\plot 1 4 1.150 3.546 \n1.312 3.125 1.475 2.772 1.638 2.484 1.800 2.255 1.962 2.082 \n2.125 1.961 2.288 1.886 2.450 1.854 2.612 1.859 2.775 1.898 \n2.938 1.967 3.100 2.060 3.262 2.174 3.425 2.303 3.588 2.444 \n3.750 2.593 3.912 2.744 4.075 2.894 4.238 3.037 4.400 3.170 \n4.562 3.289 4.725 3.388 4.888 3.464 5.050 3.511 5.212 3.527 \n5.375 3.505 5.538 3.443 5.700 3.334 5.862 3.176 6.025 2.964 /\n\\endpicture}\n\\quad\\epsfxsize3.8cm\\epsfbox{images/rotated_surface.eps}\n\\quad\\epsfxsize3.8cm\\epsfbox{images/one_disk.eps}\n\\hfill}\\vglue-0pt}}\n\\caption{\\label{fig:solid of rotation} A solid of rotation.}\n\\endfigure\n\n\\begin{formulabox}[The Disk Method \\label{idea:disk_method}]\n{Let a solid be formed by revolving the curve $y=f(x)$ from $x=a$ to $x=b$ around a horizontal axis, and let $R(x)$ be the radius of the cross-sectional disk at $x$. The volume of the solid is\n\\index{integration!volume!Disk Method}\\index{Disk Method}\n$$V = \\pi \\int_a^b R(x)^2\\ dx.$$\n}\n\\end{formulabox}\n\n\nOf course a real ``slice'' of this figure will not have straight\nsides, but we can approximate the volume of the slice by a cylinder or\ndisk with circular top and bottom and straight sides; the volume of\nthis disk will have the form $\\ds \\pi r^2\\Delta x$. As long as we can\nwrite $r$ in terms of $x$ we can compute the volume by an integral.\n\n\\begin{example}{Finding volume using the Disk Method}{ex_disk1}{\nFind the volume of the solid formed by revolving the curve $y=1/x$, from $x=1$ to $x=2$, around the $x$-axis.}\n\\end{example}\n\n%\n\\begin{solution}\n{A sketch can help us understand this problem. In Figure \\ref{fig:disk1}(a) the curve $y=1/x$ is sketched along with the differential element -- a disk -- at $x$ with radius $R(x)=1/x$. In Figure \\ref{fig:disk1} (b) the whole solid is pictured, along with the differential element. \n\nThe volume of the differential element shown in part (a) of the figure is approximately $\\pi R(x_i)^2\\Delta x$, where $R(x_i)$ is the radius of the disk shown and $\\Delta x$ is the thickness of that slice. The radius $R(x_i)$ is the distance from the $x$-axis to the curve, hence $R(x_i) = 1/x_i$.\n\t\n\n\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[t]{0.5\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{figures/figdisk1}\n        \\label{fig:disk1}\n        \\caption{} \n    \\end{subfigure}% \n    \\begin{subfigure}[t]{0.5\\textwidth}\n    \\includegraphics[width=\\textwidth]{figures/figdisk1b}\n        \\label{fig:disk1b}\n        \\caption{}    \n    \\end{subfigure} \n    \\caption{Sketching a solid in Example \\ref{exa:ex_disk1} \\label{fig:disk}}\n\\end{figure}\n\n\n%\\mtable{.5}{Sketching a solid in Example \\ref{ex_disk1}.}{fig:disk1}{%\n%\t\t\\begin{tabular}{c} %\n%\t\t\\myincludegraphicsthree{width=110pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=126.0060482236849,\n%3Dortho=0.004875946324318647,\n%3Dc2c=0.44462037086486816 0.39410829544067383 0.8043577671051025,\n%3Dcoo=67.21983337402344 3.5258262157440186 -29.566415786743164,\n%3Droo=150.00000160608386,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figdisk1}\\\\\n%%\\myincludegraphics{figures/figdisk1} \\\\\n%\t\t(a) \\\\\n%\t\t\\myincludegraphicsthree{width=110pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=126.0060482236849,\n%3Dortho=0.004875946324318647,\n%3Dc2c=0.44462037086486816 0.39410829544067383 0.8043577671051025,\n%3Dcoo=67.21983337402344 3.5258262157440186 -29.566415786743164,\n%3Droo=150.00000160608386,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figdisk1b}\\\\\n%%\\myincludegraphics{figures/figdisk1b} \\\\\n%\t\t(b) \n%\t\t\\end{tabular}\n%}\nSlicing the solid into $n$ equally--spaced slices, we can approximate the total volume by adding up the approximate volume of each slice:\n$$\\text{Approximate volume } = \\sum_{i=1}^n \\pi \\left(\\frac1{x_i}\\right)^2\\Delta x.$$\n\nTaking the limit of the above sum as $n\\to\\infty$ gives the actual volume; recognizing this sum as a Riemann sum allows us to evaluate the limit with a definite integral, which matches the formula given in Key Idea \\ref{idea:disk_method}:\n\n%Using Key Idea \\ref{idea:disk_method}, we have \n\\begin{align*}\n\tV = \\lim_{n\\to\\infty}\\sum_{i=1}^n \\pi \\left(\\frac1{x_i}\\right)^2\\Delta x\n\t\t= \\pi\\int_1^2 \\left(\\frac1x\\right)^2\\ dx \n\t\t= \\pi\\int_1^2 \\frac1{x^2}\\ dx\n\t\t&= \\pi\\left[-\\frac1x\\right]\\Big|_1^2 \\\\\n\t\t&= \\pi \\left[-\\frac12 - \\left(-1\\right)\\right] \\\\\n\t\t&= \\frac{\\pi}{2}\\ \\text{units}^3.\n\\end{align*}\n\n\\vskip-\\baselineskip\n}\n\\end{solution}\n\n\n\n\\textbf{Note:} While Key Idea \\ref{idea:disk_method} is given in terms of functions of $x$, the principle involved can be applied to functions of $y$ when the axis of rotation is vertical, not horizontal. We demonstrate this in the next example.\\\\\n\n\\clearpage\n\n\\begin{example}{Finding volume using the Disk Method}{ex_disk2}{\n\tFind the volume of the solid formed by revolving the curve $\\ds y=\\frac1x$, from $x=1$ to $x=2$, about the $y$-axis.}\t\n\\end{example}\n\n\\begin{solution}\n{Since the axis of rotation is vertical, we need to convert the function into a function of $y$ and convert the $x$-bounds to $y$-bounds. Since $y=1/x$ defines the curve, we rewrite it as $x=1/y$. The bound $x=1$ corresponds to the $y$-bound $y=1$, and the bound $x=2$ corresponds to the $y$-bound $y=1/2$. \n\t\nThus we are rotating the curve $x=1/y$, from $y=1/2$ to $y=1$ about the $y$-axis to form a solid. The curve and sample differential element are sketched in Figure \\ref{fig:disk2} (a), with a full sketch of the solid in Figure \\ref{fig:disk2} (b).\n\t\n\t\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.5\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{figures/figdisk1a}\n\t\t\\label{fig:disk1a}\n\t\t\\caption{} \n\t\\end{subfigure}%\n\t~ \n\t\\begin{subfigure}[t]{0.5\\textwidth}    \n\t\t\\includegraphics[width=\\textwidth]{figures/figdisk2a}\n\t\t\\label{fig:disk2a}\n\t\t\\caption{}    \n\t\\end{subfigure} \n\t\\caption{Sketching a solid in Example \\ref{exa:ex_disk2}. \\label{fig:disk2}}\n\\end{figure}\t\n\n\n\n\tWe integrate to find the volume:\n\\[\nV = \\pi\\int_{1/2}^1 \\frac{1}{y^2}\\ dy  = -\\frac{\\pi}y\\Big|_{1/2}^1  = \\pi\\ \\text{units}^3.\n\\]\n}\n\t\n\\end{solution}\t\n\n\n\\begin{example}{Volume of a Right Circular Cone}{Volume of a Right Circular Cone}\\label{Volume of a Right Circular Cone}\nFind the volume of a right circular cone with base radius 10 and\nheight 20. (A right circular cone is one with a circular base and with\nthe tip of the cone directly over the center of the base.)\n\\end{example}\n\n\\begin{solution}\nWe can view this cone as produced by the rotation of the line $y=x/2$ between $ x=0 $ and $ x= 20 $ rotated about the $x$-axis, as indicated in\nfigure~\\ref{fig:line to cone}.\n\n\n\n\n\n% rotated around the y-axis\n%\\begin{tikzpicture}\n% \\begin{axis}[view={60}{30}]\n%  \\addplot3[surf,shader=flat,\n%  samples=20,\n%  domain=1:2,y domain=0:2*pi,\n%  z buffer=sort]\n%  ({x * cos(deg(y))}, {x * sin(deg(y))}, {1/x});\n% \\end{axis}\n%\\end{tikzpicture}\n\n% rotated around the x-axis\n\n\\begin{figure}[H]\n\\begin{tikzpicture}[scale=.7,/pgf/declare function={f=(x/2);}]\n\\begin{axis}[\n        xmin=0,xmax=20,ymin=0,ymax=10,\n    domain=0:20,\n    samples=10,\n    y=0.4cm,\n    x=0.4cm,\n    axis lines=middle\n]\n\\addplot [thick, blue, ,name path=A] {f}  node[midway, above, sloped] {$f(x) =x/2$};\n \\addplot [draw=none,name path=B] {0};     % “fictional” curve\n  \\addplot [blue!50] fill between[of = A and B,soft clip={domain=0:20}]; % filling\n  %\\draw (axis cs:6,6) node { $\\ds y=\\frac{x}{2}$};\n\\end{axis}\n\\end{tikzpicture}\n\\begin{tikzpicture}\n \\begin{axis}[view={30}{10}, colormap={custom}{color(0)=(blue!20) color(1)=(blue)}]\n  \\addplot3[surf,shader=flat,\n  samples=20,\n  domain=1:20,y domain=0:2*pi,\n  z buffer=sort]\n  (x,{(x/2) * cos(deg(y))}, {(x/2) * sin(deg(y))});\n \\end{axis}\n\\end{tikzpicture}\n\\caption{\\label{fig:line to cone}\nA region that generates a cone; approximating the volume\nby circular disks.}\n\\end{figure}\n\n\n\n%\\figure[H]\n%%\\texonly\n%\\centerline{\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <0.25truecm,0.25truecm>\n%\\setplotarea x from 0 to 20, y from 0 to 10\n%\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$20$} / at 0 20 / /\n%\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/cone.eps}}} at 40 5\n%\\plot 0 0 20 10 /\n%\\putrule from 20 0 to 20 10\n%\\endpicture}}\n%\\caption{\\label{fig:line to cone}\n%A region that generates a cone; approximating the volume\n%by circular disks.}\n%%(\\expandafter\\url\\expandafter{\\liveurl cone.html}%\n%%AP\\endurl)\n%%\\endcaption\n%%\\endtexonly\n%%\\figrdef{fig:line to cone}\n%%\\htmlfigure{Integration_applications-volume_of_cone.html}\n%%\\begincaption\n%%Approximating the volume of a cone\n%%by circular disks.\n%%\\endcaption\n%\\endfigure\n\nAt a particular point on the $x$-axis, say $\\ds x_i$, the radius of the\nresulting cone is the $y$-coordinate of the corresponding point on the\nline, namely $\\ds y_i=x_i/2$. Thus the total volume is approximately\n$$\\sum_{i=0}^{n-1} \\pi (x_i/2)^2\\,dx$$\nand the exact volume is\n$$\n  \\int_0^{20} \\pi\n  {x^2\\over4}\\,dx={\\pi\\over4}{20^3\\over3}={2000\\pi\\over3}.\n$$ \nNote that we can instead do the calculation with a generic height and\nradius: \n$$\n  \\int_0^{h} \\pi{r^2\\over h^2}x^2\\,dx\n  ={\\pi r^2\\over h^2}{h^3\\over3}={\\pi r^2h\\over3},\n$$ \ngiving us the usual formula for the volume of a cone.\n\\end{solution}\n\n\n%\nWe can also compute the volume of solids of revolution that have a hole in the centre. The general principle is simple: compute the volume of the solid irrespective of the hole, then subtract the volume of the hole. If the outside radius of the solid is $R(x)$ and the inside radius (defining the hole) is $r(x)$, then the volume is \n$$V = \\pi\\int_a^b R(x)^2 \\ dx - \\pi\\int_a^b r(x)^2\\ dx = \\pi\\int_a^b \\left(R(x)^2-r(x)^2\\right)\\ dx.$$\n\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.5\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{figures/figwasher_idea_a}\n\t\t%\\label{fig:disk1a}\n\t\t\\caption{} \n\t\\end{subfigure}%\n\t~ \n\t\\begin{subfigure}[t]{0.5\\textwidth}    \n\t\t\\includegraphics[width=\\textwidth]{figures/figwasher_idea_b}\n\t\t%\\label{fig:disk2a}\n\t\t\\caption{}    \n\t\\end{subfigure} \n\t\\caption{Establishing the Washer Method; see also Figure \\ref{fig:washeridea_b}. \\label{fig:washeridea}}\n\\end{figure}\t\n\n\n\n\nOne can generate a solid of revolution with a hole in the middle by revolving a region about an axis. Consider Figure \\ref{fig:washeridea}(a), where a region is sketched along with a dashed, horizontal axis of rotation. By rotating the region about the axis, a solid is formed as sketched in Figure \\ref{fig:washeridea}(b). The outside of the solid has radius $R(x)$, whereas the inside has radius $r(x)$. Each cross section of this solid will be a washer (a disk with a hole in the center) as sketched in Figure \\ref{fig:washeridea_b}.\tThis leads us to the Washer Method.\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.65\\textwidth]{figures/figwasher_idea_c}\n\\caption{Establishing the Washer Method; see also Figure \\ref{fig:washeridea}.}\n\\label{fig:washeridea_b}\n\\end{figure}\n\n%\\mfigurethree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=96.94265756936434,\n%3Dortho=0.005309578496962786,\n%3Dc2c=0.547386884689331 0.07732175290584564 0.833299994468689,\n%3Dcoo=64.78053283691406 10.129053115844727 -47.566162109375,\n%3Droo=149.99999789136484,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{.8}{Establishing the Washer Method; see also Figure \\ref{fig:washeridea}.}{fig:washeridea_b}{figures/figwasher_idea_c}\n\n\n\\begin{formulabox}[The Washer Method \\label{idea:washermethod} ]\n{Let a region bounded by $y=f(x)$, $y=g(x)$, $x=a$ and $x=b$ be rotated about a horizontal axis that does not intersect the region, forming a solid. Each cross section at $x$ will be a washer with outside radius $R(x)$ and inside radius $r(x)$. The volume of the solid is\n\\index{integration!volume!Washer Method}\\index{Washer Method}\n$$V = \\pi\\int_a^b \\Big(R(x)^2-r(x)^2\\Big)\\ dx.$$ \n}\n\\end{formulabox}\n\n\n\n%\nEven though we introduced it first, the Disk Method is just a special case of the Washer Method with an inside radius of $r(x)=0$.\t\t\\\\\n\n\n\\begin{example}{Volumes with the Washer Method}{Volume of an Object with a Hole}\\label{Volume of an Object with a Hole}\nFind the volume of the object generated when the area between\n$\\ds y=x^2$ and $y=x$ is rotated around the $x$-axis. \n\\end{example}\n\n\\begin{solution}\n We begin with a sketch. In figure~\\ref{fig:solid with hole} we show the region\nthat is rotated, the resulting solid with the front half cut away,\nthe cone that forms the outer surface, the\nhorn-shaped hole, and a cross-section perpendicular to the $x$-axis.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n\\axis left shiftedto x=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/cutaway_horn.eps}}} at 3 0\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/outer_cone.eps}}} at 0 -2\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/horn.eps}}} at 2 -2\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/washer_section.eps}}} at 4 -2\n\\plot 0 0 1 1 /\n\\setquadratic\n\\plot\n0.000 0.000 0.100 0.010 0.200 0.040 0.300 0.090 0.400 0.160 \n0.500 0.250 0.600 0.360 0.700 0.490 0.800 0.640 0.900 0.810 \n1.000 1.000 /\n\\endpicture}}\n\\caption{\\label{fig:solid with hole}\nSolid with a hole, showing the outer cone and the shape to\nbe removed to form the hole.}\n%(\\expandafter\\url\\expandafter{\\liveurl solid_with_hole.html}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:solid with hole}\n%\\htmlfigure{Integration_applications-volume_with_hole.html}\n%\\htmlonly\n%\\begincaption\n%Solid with a hole. You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/jmol_solid_of_rotation_with_hole/solid_of_rotation_with_hole.sws\">Sage\n%worksheet</a>\n%for this plot and upload it to your own sage account.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\nWe can approximate the volume of a slice of the solid with a washer-shaped volume, as indicated in\nFigure~\\ref{fig:solid with hole}.\n\nThe thickness is $dx$, while the area of\nthe face is the area of the outer circle minus the area of the inner\ncircle, say $\\ds \\pi R(x)^2-\\pi r(x)^2$, or $\\pi(\\text{TOP})^2-\\pi(\\text{BOTTOM})^2$. In the present example,  $\\ds R(x)= x$ and $r(x) =  x^2$. Hence, the whole volume is\n$$\n  \\int_0^1 \\pi\\left(R(x)^2-r(x)^2\\right)\\,dx=\n  \\int_0^1 \\pi x^2-\\pi x^4\\,dx=\n  \\left.\\pi\\left({x^3\\over3}-{x^5\\over5}\\right)\\right|_0^1=\n  \\pi\\left({1\\over3}-{1\\over5}\\right)={2\\pi\\over15}.\n$$\n\\end{solution}\n\n\n\n\n\\begin{example}{Finding volume with the Washer Method}{ex_wash1}{\nFind the volume of the solid formed by rotating the region bounded by $y=x^2-2x+2$ and $y=2x-1$ about the $x$-axis.}\n\\end{example}\n\n\n\\begin{solution}\n{A sketch of the region will help, as given in Figure \\ref{fig:wash1}(a).\n%\\mfigurethree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=97.32968340849395,\n%3Dortho=0.004881054162979126,\n%3Dc2c=0.43117064237594604 0.05905330181121826 0.9003357887268066,\n%3Dcoo=64.78053283691406 10.12905216217041 -47.566158294677734,\n%3Droo=149.99999769784193,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{.22}{A sketch of the region used in Example \\ref{ex_wash1}.}{fig:wash1a}{figures/figwash1}\n%\\mfigure{.22}{A sketch of the region used in Example \\ref{ex_wash1}.}{fig:wash1a}{figures/figwash1} \nRotating about the $x$-axis will produce cross sections in the shape of washers, as shown in Figure \\ref{fig:wash1}(b); the complete solid is shown in part (c). The outside radius of this washer is $R(x) = 2x+1$; the inside radius is $r(x) = x^2-2x+2$. As the region is bounded from $x=1$ to $x=3$, we integrate as follows to compute the volume.\n\\begin{align*}\nV &= \\pi\\int_1^3 \\Big((2x-1)^2-(x^2-2x+2)^2\\Big)\\ dx \\\\\n\t\t&= \\pi\\int_1^3 \\big(-x^4+4x^3-4x^2+4x-3\\big)\\ dx \\\\\n\t\t&= \\pi\\Big[-\\frac{1}{5}x^5+x^4-\\frac43x^3+2x^2-3x\\Big]\\Big|_1^3 \\\\\n\t\t&=\\frac{104}{15}\\pi \\approx 21.78\\ \\text{units}^3.\n\\end{align*}\t\n\\vskip-1.5\\baselineskip\t\n\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.33\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{figures/figwash1}\n\t\t\\label{fig:figwash1a}\n\t\t\\caption{} \n\t\\end{subfigure}%\n\t~ \n\t\\begin{subfigure}[t]{0.33\\textwidth}    \n\t\t\\includegraphics[width=\\textwidth]{figures/figwash1c}\n\t\t\\label{fig:figwash1b}\n\t\t\\caption{}    \n\t\\end{subfigure}%\n\t\t~ \n\t\t\\begin{subfigure}[t]{0.33\\textwidth}    \n\t\t\t\\includegraphics[width=\\textwidth]{figures/figwash1b}\n\t\t\t\\label{fig:figwash1c}\n\t\t\t\\caption{}    \n\t\t\\end{subfigure} \n\t\\caption{Sketching the differential element and solid in Example \\ref{exa:ex_wash1}. \\label{fig:wash1}}\n\\end{figure}\t\n\n\n%\\mtable{.37}{Sketching the differential element and solid in Example \\ref{ex_wash1}.}{fig:wash1}{%\n%\\begin{tabular}{c}\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=97.32968340849395,\n%3Dortho=0.004881054162979126,\n%3Dc2c=0.43117064237594604 0.05905330181121826 0.9003357887268066,\n%3Dcoo=64.78053283691406 10.12905216217041 -47.566158294677734,\n%3Droo=149.99999769784193,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash1}\\\\\n%%\\myincludegraphics{figures/figwash1c}\\\\\n%(a)\\\\\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=97.32968340849395,\n%3Dortho=0.004881054162979126,\n%3Dc2c=0.43117064237594604 0.05905330181121826 0.9003357887268066,\n%3Dcoo=64.78053283691406 10.12905216217041 -47.566158294677734,\n%3Droo=149.99999769784193,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash1c}\\\\\n%%\\myincludegraphics{figures/figwash1c}\\\\\n%(b)\\\\\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=97.32968340849395,\n%3Dortho=0.004881054162979126,\n%3Dc2c=0.43117064237594604 0.05905330181121826 0.9003357887268066,\n%3Dcoo=64.78053283691406 10.12905216217041 -47.566158294677734,\n%3Droo=149.99999769784193,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash1b}\\\\\n%%\\myincludegraphics{figures/figwash1b}\\\\\n%(c)\n%\\end{tabular}\n%}\n}\n\\end{solution}\n\n\n\nWhen rotating about a vertical axis, the outside and inside radius functions must be functions of $y$.\\\\\n\n\n\\begin{example}{Finding volume with the Washer Method}{ex_wash2}{\nFind the volume of the solid formed by rotating the triangular region with vertices at $(1,1)$, $(2,1)$ and $(2,3)$ about the $y$-axis.}\n\\end{example}\n\n\n\\begin{solution}\n{The triangular region is sketched in Figure \\ref{fig:wash2}(a); the differential element is sketched in (b) and the full solid is drawn in (c). They help us establish the outside and inside radii. Since the axis of rotation is vertical, each radius is a function of $y$. \n\nThe outside radius $R(y)$ is formed by the line connecting $(2,1)$ and $(2,3)$; it is a constant function, as regardless of the $y$-value the distance from the line to the axis of rotation is 2. Thus $R(y)=2$. \n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{subfigure}[t]{0.33\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{figures/figwash2a}\n\t\t\\label{fig:figwash2a}\n\t\t\\caption{} \n\t\\end{subfigure}%\n\t~ \n\t\\begin{subfigure}[t]{0.33\\textwidth}    \n\t\t\\includegraphics[width=\\textwidth]{figures/figwash2b}\n\t\t\\label{fig:figwash2b}\n\t\t\\caption{}    \n\t\\end{subfigure}%\n\t\t~ \n\t\t\\begin{subfigure}[t]{0.33\\textwidth}    \n\t\t\t\\includegraphics[width=\\textwidth]{figures/figwash2c}\n\t\t\t\\label{fig:figwash2c}\n\t\t\t\\caption{}    \n\t\t\\end{subfigure} \n\t\\caption{Sketching the solid in Example \\ref{ex_wash2}. \\label{fig:wash2}}\n\\end{figure}\t\n\n%\\mtable{.63}{Sketching the solid in Example \\ref{ex_wash2}.}{fig:wash2}{%\n%\\begin{tabular}{c}\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=123.42078064170005,\n%3Dortho=0.00488104997202754,\n%3Dc2c=0.41855040192604065 0.31316813826560974 0.8524911999702454,\n%3Dcoo=-7.115118026733398 66.85215759277344 -16.372848510742188,\n%3Droo=149.99999819286032,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash2a}\\\\\n%%\\myincludegraphics{figures/figwash2a} \\\\\n%(a) \\\\\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=123.42078064170005,\n%3Dortho=0.00488104997202754,\n%3Dc2c=0.41855040192604065 0.31316813826560974 0.8524911999702454,\n%3Dcoo=-7.115118026733398 66.85215759277344 -16.372848510742188,\n%3Droo=149.99999819286032,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash2b}\\\\\n%%\\myincludegraphics{figures/figwash2b} \\\\\n%(b) %\\\\\n%\\myincludegraphicsthree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=123.42078064170005,\n%3Dortho=0.00488104997202754,\n%3Dc2c=0.41855040192604065 0.31316813826560974 0.8524911999702454,\n%3Dcoo=-7.115118026733398 66.85215759277344 -16.372848510742188,\n%3Droo=149.99999819286032,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{figures/figwash2c}\\\\\n%%\\myincludegraphics{figures/figwash2c} \\\\\n%(c)\n%\\end{tabular}\n%}\n\nThe inside radius is formed by the line connecting $(1,1)$ and $(2,3)$. The equation of this line is $y=2x-1$, but we need to refer to it as a function of $y$. Solving for $x$ gives $r(y) = \\frac12(y+1)$. \n\nWe integrate over the $y$-bounds of $y=1$ to $y=3$. Thus the volume is\n\\begin{align*}\nV \t&=\t\\pi\\int_1^3\\Big(2^2 - \\big(\\frac12(y+1)\\big)^2\\Big)\\ dy \\\\\n\t\t&=\t\\pi\\int_1^3\\Big(-\\frac14y^2-\\frac12y+\\frac{15}4\\Big)\\ dy \\\\\n\t\t&= \t\\pi\\Big[-\\frac1{12}y^3-\\frac14y^2+\\frac{15}4y\\Big]\\Big|_1^3\\\\\n\t\t&= \\frac{10}3\\pi \\approx 10.47\\ \\text{units}^3.\n\\end{align*}\n%\\mfigurethree{width=125pt,3Dmenu,activate=onclick,deactivate=onclick,\n%3Droll=123.42078064170005,\n%3Dortho=0.00488104997202754,\n%3Dc2c=0.41855040192604065 0.31316813826560974 0.8524911999702454,\n%3Dcoo=-7.115118026733398 66.85215759277344 -16.372848510742188,\n%3Droo=149.99999819286032,\n%3Dlights=Headlamp,add3Djscript=asylabels.js}{}{.8}{Sketching the solid in Example \\ref{ex_wash2}.}{fig:wash2b}{figures/figwash2c}\\\\\n%%\\myincludegraphics{figures/figwash2c}\n}\n\\end{solution}\n\n\n\n%\nThis section introduced a new application of the definite integral. Our default view of the definite integral is that it gives ``the area under the curve.'' However, we can establish definite integrals that represent other quantities; in this section, we computed volume.\n\nThe ultimate goal of this section is not to compute volumes of solids. That can be useful, but what is more useful is the understanding of this basic principle of integral calculus: to find the exact value of some quantity, \n\\begin{itemize}\n\t\\item we start with an approximation (in this section, slice the solid and approximate the volume of each slice), \n\t\\item then make the approximation better by refining our original approximation (i.e., use more slices), \n\t\\item\tthen use limits to establish a definite integral which gives the exact value.\n\\end{itemize}\n%\n%We practice this principle in the next section where we find volumes by slicing solids in a different way.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\n\t\t\t\n\n%\\figure[H]\n%%\\texonly\n%\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <0.3truecm,0.3truecm>\n%\\setplotarea x from -10 to 10, y from -3 to 20\n%\\axis bottom shiftedto y=0 ticks withvalues {$x_i$} / at 7 / /\n%\\put {\\hbox{\\epsfxsize9truecm\\epsfbox{images/pyramid_steps.eps}}} at 30 10\n%\\put {$y_i\\rightarrow$} [l] <-5pt,-1truept> at -10 6\n%\\plot -10 0 0 20 10 0 /\n%\\putrule from -10 0 to -10 1\n%\\putrule from -10 1 to 10 1\n%\\putrule from 10 1 to 10 0\n%\\putrule from -9.5 1 to -9.5 2\n%\\putrule from -9.5 2 to 9.5 2\n%\\putrule from 9.5 2 to 9.5 1\n%\\putrule from -9 2 to -9 3\n%\\putrule from -9 3 to 9 3\n%\\putrule from 9 3 to 9 2\n%\\putrule from -8.5 3 to -8.5 4\n%\\putrule from -8.5 4 to 8.5 4\n%\\putrule from 8.5 4 to 8.5 3\n%\\putrule from -8 4 to -8 5\n%\\putrule from -8 5 to 8 5\n%\\putrule from 8 5 to 8 4\n%\\putrule from -7.5 5 to -7.5 6\n%\\putrule from -7.5 6 to 7.5 6\n%\\putrule from 7.5 6 to 7.5 5\n%\\putrule from -7 6 to -7 7\n%\\putrule from -7 7 to 7 7\n%\\putrule from 7 7 to 7 6\n%\\putrule from -6.5 7 to -6.5 8\n%\\putrule from -6.5 8 to 6.5 8\n%\\putrule from 6.5 8 to 6.5 7\n%\\putrule from -6 8 to -6 9\n%\\putrule from -6 9 to 6 9\n%\\putrule from 6 9 to 6 8\n%\\put {$\\vdots$} at 0 13\n%\\endpicture}\n%%\\caption{\n%%Volume of a pyramid approximated by rectangular prisms.\n%%(\\expandafter\\url\\expandafter{\\liveurl pyramid.html}%\n%%AP\\endurl)\n%%\\endcaption\n%%\\endtexonly\n%%\\figrdef{fig:pyramid}\n%%\\htmlfigure{Integration_applications-volume_pyramid.html}\n%%\\htmlonly\n%\\caption{\\label{fig:pyramid}\n%Volume of a pyramid approximated by rectangular prisms.}\n%%\\endhtmlonly\n%\\endfigure\n%\n%\\begin{example}{Volume of a Pyramid}{Volume of a Pyramid}\\label{Volume of a Pyramid}\n%Find the volume of a pyramid with a square base that is 20 meters tall\n%and 20 meters on a side at the base. \n%\\end{example}\n%\n%\\begin{solution}\n%As with most of our applications\n%of integration, we begin by asking how we might approximate the\n%volume. Since we can easily compute the volume of a rectangular prism\n%(that is, a ``box''), we will use some boxes to approximate the volume of\n%the pyramid, as shown in figure~\\ref{fig:pyramid}: On the left is a\n%cross-sectional view, on the right is a 3D view of part of the pyramid\n%with some of the boxes used to approximate the volume.\n%\n%Each box has volume of the form $\\ds (2x_i)(2x_i)\\Delta y$. Unfortunately,\n%there are two variables here; fortunately, we can write $x$ in terms\n%of $y$: From the cross-sectional view we see that a height of 20 is achieved at the midpoint of the base. We will also position the cross-sectional view symmetrically about the $y$-axis. Thus at $x=0$, $y=20$, and we have a slope of $m=-2$. So\n%\\begin{align*}\n%y&=-2x+b\t\\\\\n%20&=-2(0)+b\t\\\\\n%20&=b.\n%\\end{align*}\n%\n%Therefore, $y=20-2x$, and in the terms of $x$: $x=10-y/2$ or $\\ds x_i=10-y_i/2$. Then the total volume is\n%approximately\n%$$\\sum_{i=0}^{n-1} 4(10-y_i/2)^2\\Delta y$$\n%and in the limit we get the volume as the value of an integral:\n%$$\n%  \\int_0^{20} 4(10-y/2)^2\\,dy=\\int_0^{20} (20-y)^2\\,dy=\n%  \\left.-{(20-y)^3\\over3}\\right|_0^{20}=\n%  -{0^3\\over3}--{20^3\\over3}={8000\\over3}.\n%$$\n%As you may know, the volume of a pyramid is \n%$(1/3)(\\hbox{height})(\\hbox{area of base})=(1/3)(20)(400)$, which\n%agrees with our answer.\n%\\end{solution}\n%\n%\\begin{example}{Volume of an Object}{Volume of an Object}\n%The base of a solid is the region between $\\ds f(x)=x^2-1$ and\n%$\\ds g(x)=-x^2+1$, and its cross-sections perpendicular to the $x$-axis \n%are equilateral triangles, as indicated in\n%Figure~\\xrefn{fig:triangular cross-sections}.\n%%\\texonly\n%The solid has been truncated to show a triangular\n%cross-section above $x=1/2$.\n%%\\endtexonly\n%Find the volume of the solid.\n%\\end{example}\n%\n%\\figure[H]\n%%\\texonly\n%\\centerline{\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <3truecm,3truecm>\n%\\setplotarea x from -1.1 to 1.1, y from -1.1 to 1.1\n%\\put {\\hbox{\\epsfxsize6truecm\\epsfbox{images/triangular_solid.eps}}} at 3 0\n%\\axis bottom shiftedto y=0 ticks withvalues {$-1\\quad$} {$1$} / at -1 1 / /\n%\\axis left shiftedto x=0 ticks withvalues {$-1\\quad$} {$1\\quad$} / at -1 1 / /\n%\\plot\n%-1.000 0.000 -0.900 -0.190 -0.800 -0.360 -0.700 -0.510 -0.600 -0.640 \n%-0.500 -0.750 -0.400 -0.840 -0.300 -0.910 -0.200 -0.960 -0.100 -0.990 \n%0.000 -1.000 0.100 -0.990 0.200 -0.960 0.300 -0.910 0.400 -0.840 \n%0.500 -0.750 0.600 -0.640 0.700 -0.510 0.800 -0.360 0.900 -0.190 \n%1.000 0.000 /\n%\\plot\n%-1.000 0.000 -0.900 0.190 -0.800 0.360 -0.700 0.510 -0.600 0.640 \n%-0.500 0.750 -0.400 0.840 -0.300 0.910 -0.200 0.960 -0.100 0.990 \n%0.000 1.000 0.100 0.990 0.200 0.960 0.300 0.910 0.400 0.840 \n%0.500 0.750 0.600 0.640 0.700 0.510 0.800 0.360 0.900 0.190 \n%1.000 0.000 /\n%\\endpicture}}\n%%\\begincaption\n%%{Solid with equilateral triangles as cross-sections.\n%%(\\expandafter\\url\\expandafter{\\liveurl jmol_triangular_x_sections}%\n%%AP\\endurl)}\n%%%(\\expandafter\\url\\expandafter{\\sageurl solid_with_triangular_x-sections}%\n%%%AP\\endurl)}\n%%\\endcaption\n%%\\endtexonly\n%%\\figrdef{fig:triangular cross-sections}\n%%\\htmlfigure{Integration_applications-volume_equilateral_x_sections.html}\n%%\\htmlonly\n%\\caption\n%{Solid with equilateral triangles as cross-sections.\\label{fig:triangular cross-sections}}\n%%You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/sage/solid_with_triangular_x-sections/solid_with_triangular_x-sections.sws\">Sage worksheet</a>\n%%for this plot and upload it to your own sage account.\n%%\\endcaption\n%%\\endhtmlonly\n%\\endfigure\n%\n%\\begin{solution}\n%A cross-section at a value $\\ds x_i$ on the $x$-axis is a triangle with\n%base $\\ds 2(1-x_i^2)$ and height $\\ds \\sqrt3(1-x_i^2)$, so the area of the\n%cross-section is \n%$$\n%  {1\\over2}(\\hbox{base})(\\hbox{height})=\n%  (1-x_i^2)\\sqrt3(1-x_i^2),\n%$$\n%and the volume of a thin ``slab'' is then\n%$$(1-x_i^2)\\sqrt3(1-x_i^2)\\Delta x.$$\n%Thus the total volume is \n%$$\\int_{-1}^1 \\sqrt3(1-x^2)^2\\,dx={16\\over15}\\sqrt3.$$\n%\\vskip-10pt\n%\\end{solution}\n%\n%One easy way to get ``nice'' cross-sections is by rotating a plane\n%figure around a line. For example, in Figure~\\ref{fig:solid of rotation} \n%we see a plane region under a curve and between two\n%vertical lines; then the result of rotating this around the $\\ds x$-axis, and\n%a typical circular cross-section is a circle.\n% \n%\\figure[H]\n%%\\texonly\n%\\centerline{\n%\\vbox{\\hbox{\\hfill\\raise53pt\\vbox{\n%\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <5.5truemm,5.5truemm>\n%\\setplotarea x from 0 to 8, y from -4 to 4\n%\\axis left /\n%\\axis bottom shiftedto y=0 / \n%\\putrule from 1 0 to 1 4 \n%\\putrule from 6 0 to 6 3\n%\\plot 1 4 1.150 3.546 \n%1.312 3.125 1.475 2.772 1.638 2.484 1.800 2.255 1.962 2.082 \n%2.125 1.961 2.288 1.886 2.450 1.854 2.612 1.859 2.775 1.898 \n%2.938 1.967 3.100 2.060 3.262 2.174 3.425 2.303 3.588 2.444 \n%3.750 2.593 3.912 2.744 4.075 2.894 4.238 3.037 4.400 3.170 \n%4.562 3.289 4.725 3.388 4.888 3.464 5.050 3.511 5.212 3.527 \n%5.375 3.505 5.538 3.443 5.700 3.334 5.862 3.176 6.025 2.964 /\n%\\endpicture}\n%\\quad\\epsfxsize3.8cm\\epsfbox{images/rotated_surface.eps}\n%\\quad\\epsfxsize3.8cm\\epsfbox{images/one_disk.eps}\n%\\hfill}\\vglue-0pt}}\n%\\caption{\\label{fig:solid of rotation} A solid of rotation.}\n%\\endfigure\n%\n%Of course a real ``slice'' of this figure will not have straight\n%sides, but we can approximate the volume of the slice by a cylinder or\n%disk with circular top and bottom and straight sides; the volume of\n%this disk will have the form $\\ds \\pi r^2\\Delta x$. As long as we can\n%write $r$ in terms of $x$ we can compute the volume by an integral.\n%\n%%\\begin{example}{Volume of a Right Circular Cone}{Volume of a Right Circular Cone}\\label{Volume of a Right Circular Cone}\n%%Find the volume of a right circular cone with base radius 10 and\n%%height 20. (A right circular cone is one with a circular base and with\n%%the tip of the cone directly over the center of the base.)\n%%\\end{example}\n%%\n%%\\begin{solution}\n%%We can view this cone as produced by the rotation of the line\n%%$y=x/2$ rotated about the $x$-axis, as indicated in\n%%figure~\\ref{fig:line to cone}.\n%%\n%%\\figure[H]\n%%%\\texonly\n%%\\centerline{\\vbox{\\beginpicture\n%%\\normalgraphs\n%%%\\ninepoint\n%%\\setcoordinatesystem units <0.25truecm,0.25truecm>\n%%\\setplotarea x from 0 to 20, y from 0 to 10\n%%\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$20$} / at 0 20 / /\n%%\\put {\\hbox{\\epsfxsize6cm\\epsfbox{images/cone.eps}}} at 40 5\n%%\\plot 0 0 20 10 /\n%%\\putrule from 20 0 to 20 10\n%%\\endpicture}}\n%%\\caption{\\label{fig:line to cone}\n%%A region that generates a cone; approximating the volume\n%%by circular disks.}\n%%%(\\expandafter\\url\\expandafter{\\liveurl cone.html}%\n%%%AP\\endurl)\n%%%\\endcaption\n%%%\\endtexonly\n%%%\\figrdef{fig:line to cone}\n%%%\\htmlfigure{Integration_applications-volume_of_cone.html}\n%%%\\begincaption\n%%%Approximating the volume of a cone\n%%%by circular disks.\n%%%\\endcaption\n%%\\endfigure\n%%\n%%At a particular point on the $x$-axis, say $\\ds x_i$, the radius of the\n%%resulting cone is the $y$-coordinate of the corresponding point on the\n%%line, namely $\\ds y_i=x_i/2$. Thus the total volume is approximately\n%%$$\\sum_{i=0}^{n-1} \\pi (x_i/2)^2\\,dx$$\n%%and the exact volume is\n%%$$\n%%  \\int_0^{20} \\pi\n%%  {x^2\\over4}\\,dx={\\pi\\over4}{20^3\\over3}={2000\\pi\\over3}.\n%%$$ \n%%Note that we can instead do the calculation with a generic height and\n%%radius: \n%%$$\n%%  \\int_0^{h} \\pi{r^2\\over h^2}x^2\\,dx\n%%  ={\\pi r^2\\over h^2}{h^3\\over3}={\\pi r^2h\\over3},\n%%$$ \n%%giving us the usual formula for the volume of a cone.\n%%\\end{solution}\n%\n%\\begin{example}{Volume of an Object with a Hole}{Volume of an Object with a Hole}\\label{Volume of an Object with a Hole}\n%Find the volume of the object generated when the area between\n%$\\ds y=x^2$ and $y=x$ is rotated around the $x$-axis. \n%\\end{example}\n%\n%\\begin{solution}\n%This solid has a\n%``hole'' in the middle; we can compute the volume by subtracting the\n%volume of the hole from the volume enclosed by the outer surface of\n%the solid. In figure~\\ref{fig:solid with hole} we show the region\n%that is rotated, the resulting solid with the front half cut away,\n%the cone that forms the outer surface, the\n%horn-shaped hole, and a cross-section perpendicular to the $x$-axis.\n%\n%\\figure[H]\n%%\\texonly\n%\\centerline{\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <3truecm,3truecm>\n%\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n%\\axis bottom shiftedto y=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n%\\axis left shiftedto x=0 ticks withvalues {$0$} {$1$} / at 0 1 / /\n%\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/cutaway_horn.eps}}} at 3 0\n%\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/outer_cone.eps}}} at 0 -2\n%\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/horn.eps}}} at 2 -2\n%\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/washer_section.eps}}} at 4 -2\n%\\plot 0 0 1 1 /\n%\\setquadratic\n%\\plot\n%0.000 0.000 0.100 0.010 0.200 0.040 0.300 0.090 0.400 0.160 \n%0.500 0.250 0.600 0.360 0.700 0.490 0.800 0.640 0.900 0.810 \n%1.000 1.000 /\n%\\endpicture}}\n%\\caption{\\label{fig:solid with hole}\n%Solid with a hole, showing the outer cone and the shape to\n%be removed to form the hole.}\n%%(\\expandafter\\url\\expandafter{\\liveurl solid_with_hole.html}%\n%%AP\\endurl)\n%%\\endcaption\n%%\\endtexonly\n%%\\figrdef{fig:solid with hole}\n%%\\htmlfigure{Integration_applications-volume_with_hole.html}\n%%\\htmlonly\n%%\\begincaption\n%%Solid with a hole. You can download the <a href=\"http://www.whitman.edu/mathematics/calculus/live/jmol_solid_of_rotation_with_hole/solid_of_rotation_with_hole.sws\">Sage\n%%worksheet</a>\n%%for this plot and upload it to your own sage account.\n%%\\endcaption\n%%\\endhtmlonly\n%\\endfigure\n%\n%We have already computed the volume of a cone; in this case it is\n%$\\pi/3$. At a particular value of $x$, say $\\ds x_i$, the cross-section of\n%the horn is a circle with radius $\\ds x_i^2$, so the volume of the horn is\n%$$\\int_0^1 \\pi(x^2)^2\\,dx=\\int_0^1 \\pi x^4\\,dx=\\pi{1\\over 5},$$\n%so the desired volume is $\\pi/3-\\pi/5=2\\pi/15$.\n%\n%As with the area between curves, there is an alternate approach that\n%computes the desired volume ``all at once'' by approximating the\n%volume of the actual solid. We can approximate the volume of a slice\n%of the solid with a washer-shaped volume, as indicated in\n%Figure~\\ref{fig:solid with hole}.\n%\n%The volume of such a washer is the area of the face times the\n%thickness. The thickness, as usual, is $\\Delta x$, while the area of\n%the face is the area of the outer circle minus the area of the inner\n%circle, say $\\ds \\pi R^2-\\pi r^2$, or $\\pi(\\text{TOP})^2-\\pi(\\text{BOTTOM})^2$. In the present example, at a particular $\\ds x_i$,\n%the radius $R$ (The ``TOP'' function) is $\\ds x_i$ and $r$ (The ``BOTTOM'' function) $\\ds x_i^2$. Hence, the whole volume is\n%$$\n%  \\int_0^1 \\pi\\left(\\text{TOP}^2-\\text{BOTTOM}^2\\right)\\,dx=\n%  \\int_0^1 \\pi x^2-\\pi x^4\\,dx=\n%  \\left.\\pi\\left({x^3\\over3}-{x^5\\over5}\\right)\\right|_0^1=\n%  \\pi\\left({1\\over3}-{1\\over5}\\right)={2\\pi\\over15}.\n%$$\n%Of course, what we have done here is exactly the same calculation as\n%before, except we have in effect recomputed the volume of the outer cone.\n%\\end{solution}\n%\n%Suppose the region between $f(x)=x+1$ and $\\ds g(x)=(x-1)^2$ is rotated around\n%the $y$-axis; see Figure~\\ref{fig:shell method}. It is possible, but\n%inconvenient, to compute the  volume of the resulting solid by the\n%method we have used so far. The problem is that there are two\n%``kinds'' of typical rectangles: Those that go from the line to the\n%parabola and those that touch the parabola on both ends. To compute\n%the volume using this approach, we need to break the problem into two\n%parts and compute two integrals:\n%$$\n%  \\pi\\int_0^1 (1+\\sqrt{y})^2-(1-\\sqrt{y})^2\\,dy+\n%  \\pi\\int_1^4  (1+\\sqrt{y})^2-(y-1)^2\\,dy={8\\over3}\\pi + {65\\over6}\\pi\n%  ={27\\over2}\\pi.\n%$$\n%If instead we consider a typical vertical rectangle, {but still rotate\n%around the $y$-axis,} we get a thin ``shell'' instead of a thin\n%``washer''. Note that ``washers'' are related to the area of a circle, $\\pi r^2$, whereas ``shells'' are related to the surface area of a cylinder, $2\\pi rh$. If we add up the volume of such thin shells we will get an\n%approximation to the true volume. What is the volume of such a shell?\n%Consider the shell at $\\ds x_i$.\n%Imagine that we cut the shell vertically in one place and ``unroll''\n%it into a thin, flat sheet, namely the surface of a cylinder. This sheet will be almost a rectangular\n%prism that is $\\Delta x$ thick, $\\ds f(x_i)-g(x_i)$ (TOP$-$BOTTOM) tall, and $\\ds 2\\pi x_i$\n%wide. The volume will then be approximately the volume of a rectangular\n%prism with these dimensions: $\\ds 2\\pi x_i(f(x_i)-g(x_i))\\Delta x$. If we\n%add these up and take the limit as usual, we get the integral\n%$$\n%  \\int_0^3 2\\pi x(f(x)-g(x))\\,dx=\n%  \\int_0^3 2\\pi x\\left(\\text{TOP}-\\text{BOTTOM}\\right)\\,dx=\n%  \\int_0^3 2\\pi x(x+1-(x-1)^2)\\,dx={27\\over2}\\pi.\n%$$\n%Not only does this accomplish the task with only one integral, the\n%integral is somewhat easier than those in the previous\n%calculation. Things are not always so neat, but it is often the case\n%that one of the two methods will be simpler than the other, so it is\n%worth considering both before starting to do calculations.\n%\n%\\figure[H]\n%%\\texonly\n%\\centerline{\\vbox{\\beginpicture\n%\\normalgraphs\n%%\\ninepoint\n%\\setcoordinatesystem units <1truecm,1truecm>\n%\\setplotarea x from 0 to 3.1, y from 0 to 4.1\n%\\axis bottom shiftedto y=0 ticks numbered from 0 to 3 by 1 /\n%\\axis left shiftedto x=0 ticks numbered from 0 to 4 by 1 /\n%\\putrule from 1 2 to 2.4142 2\n%\\putrule from 1 1.8 to 2.4142 1.8\n%\\putrule from 1 1.8 to 1 2\n%\\putrule from 2.4142 1.8 to 2.4142 2\n%\\putrule from 0.25 .5625 to 1.75 .5625\n%\\putrule from 0.25 .3625 to 1.75 .3625\n%\\putrule from 0.25 .3625 to 0.25 .5625\n%\\putrule from 1.75 .3625 to 1.75 .5625\n%\\plot 0 1 3 4 /\n%\\setquadratic\n%\\plot\n%0.000 1.000 0.150 0.722 0.300 0.490 0.450 0.302 0.600 0.160 \n%0.750 0.062 0.900 0.010 1.050 0.002 1.200 0.040 1.350 0.122 \n%1.500 0.250 1.650 0.422 1.800 0.640 1.950 0.902 2.100 1.210 \n%2.250 1.562 2.400 1.960 2.550 2.402 2.700 2.890 2.850 3.422 \n%3.000 4.000 /\n%\\setcoordinatesystem units <1truecm,1truecm> point at -5 0\n%\\setplotarea x from 0 to 3.1, y from 0 to 4.1\n%\\axis bottom shiftedto y=0 ticks numbered from 0 to 3 by 1 /\n%\\axis left shiftedto x=0 ticks numbered from 0 to 4 by 1 /\n%\\put {\\hbox{\\epsfxsize4cm\\epsfbox{images/shell.eps}}} at 7 2\n%\\putrule from 1.5 0.25 to 1.5 2.5\n%\\putrule from 1.7 0.25 to 1.7 2.5\n%\\putrule from 1.5 0.25 to 1.7 0.25\n%\\putrule from 1.5 2.5 to 1.7 2.5\n%\\setlinear\n%\\plot 0 1 3 4 /\n%\\setquadratic\n%\\plot\n%0.000 1.000 0.150 0.722 0.300 0.490 0.450 0.302 0.600 0.160 \n%0.750 0.062 0.900 0.010 1.050 0.002 1.200 0.040 1.350 0.122 \n%1.500 0.250 1.650 0.422 1.800 0.640 1.950 0.902 2.100 1.210 \n%2.250 1.562 2.400 1.960 2.550 2.402 2.700 2.890 2.850 3.422 \n%3.000 4.000 /\n%\\endpicture}}\n%\\caption{\\label{fig:shell method}\n%Computing volumes with ``shells''.}\n%%(\\url{http://www.whitman.edu/mathematics/calculus/live/shell.html}%\n%%AP\\endurl)}\n%%(\\expandafter\\url\\expandafter{\\liveurl shell.html}%\n%%AP\\endurl)\n%%\\endcaption\n%%\\endtexonly\n%%\\figrdef{fig:shell method}\n%%\\htmlfigure{Integration_applications-volume_shell_method.html}\n%%\\htmlonly\n%%\\begincaption\n%%Computing volumes with ``shells''.\n%%\\endcaption\n%%\\endhtmlonly\n%\\endfigure\n%\n%\\begin{example}{}{}\\label{}\n%Suppose the area under $\\ds y=-x^2+1$ between $x=0$ and $x=1$ is\n%rotated around the $x$-axis. Find the volume by both methods.\n%\\end{example}\n%\n%\\begin{solution}\n%Using the disk method we obtain:\n%$$\\ds \\int_0^1 \\pi(1-x^2)^2\\,dx={8\\over15}\\pi.$$\n%Using the shell method we obtain:\n%$$\\ds \\int_0^1 2\\pi y \\sqrt{1-y}\\,dy={8\\over15}\\pi.$$\n%\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:volume}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\nVerify that $\\ds\\pi\\int_0^1 (1+\\sqrt{y})^2-(1-\\sqrt{y})^2\\,dy+\n\\pi\\int_1^4  (1+\\sqrt{y})^2-(y-1)^2={8\\over3}\\pi + {65\\over6}\\pi\n={27\\over2}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds\\int_0^3 2\\pi x(x+1-(x-1)^2)\\,dx={27\\over2}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds \\int_0^1 \\pi(1-x^2)^2\\,dx={8\\over15}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Verify that $\\ds \\int_0^1 2\\pi y \\sqrt{1-y}\\,dy={8\\over15}\\pi$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nUse integration to find the volume of the solid obtained by revolving \nthe region bounded by $x+y=2$ and the $x$ and $y$ axes around the\n$x$-axis. \n\\begin{sol}\n $8\\pi/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the volume of the solid obtained by revolving \nthe region bounded by $\\ds y=x-x^2$\nand the $x$-axis around the\n$x$-axis. \n\\begin{sol}\n $\\pi/30$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nFind the volume of the solid obtained by revolving \nthe region bounded by $\\ds y=\\sqrt{\\sin x}$ between $x=0$ and\n$x=\\pi/2$, the $y$-axis, and the line\n$y=1$ around the\n$x$-axis. \n\\begin{sol}\n $\\pi(\\pi/2-1)$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nLet $S$ be the region of the $xy$-plane bounded above by the curve\n$\\ds x^3y=64$, below by the line $y=1$, on the left by  the line $x=2$, and\non the right by the line $x=4$.  Find\nthe volume of the solid obtained by rotating $S$ around:\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\tthe $x$-axis;\n\t\\item\tthe line $y=1$;\n\t\\item\tthe $y$-axis; and\n\t\\item\tthe line $x=2$.\n\\end{enumerate}\n\\end{multicols}\n\\begin{sol}\n\\begin{multicols}{2}\n\\begin{enumerate}\n\t\\item\t$114\\pi/5$\n\t\\item\t$74\\pi/5$\n\t\\item\t$20\\pi$\n\t\\item\t$4\\pi$\n\\end{enumerate}\n\\end{multicols}\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The equation $\\ds x^2/9+y^2/4=1$ describes an ellipse.  Find the\nvolume of the solid obtained by rotating the ellipse around the\n$x$-axis and also around the $y$-axis. These solids are\ncalled \\dfont{ellipsoids}; one is vaguely rugby-ball shaped, one is\nsort of flying-saucer shaped, or perhaps squished-beach-ball-shaped.\n\\begin{sol}\n $16\\pi$, $24\\pi$\n\\end{sol}\n\\end{ex}\n\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\ninepoint\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 0.5\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/rugby.eps}}} at 0 0\n\\put {\\hbox{\\epsfxsize3cm\\epsfbox{images/ufo.eps}}} at 2 0\n\\endpicture}}\n\\caption{Ellipsoids.\\label{fig:ellipsoids}}\n%(\\url{http://www.whitman.edu/mathematics/calculus/live/ellipsoid.html}%\n%AP\\endurl)}\n%(\\expandafter\\url\\expandafter{\\liveurl ellipsoid.html}%\n%AP\\endurl)}\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:ellipsoids}\n%\\htmlfigure{Integration_applications-ellipsoids.html}\n%\\htmlonly\n%\\begincaption\n%Ellipsoids.\n%\\endcaption\n%\\endhtmlonly\n\\endfigure\n\n\n%%%%%%%%%%\n\\begin{ex}\n Use integration to compute the volume of a sphere of radius\n$r$. You should of course get the well-known formula $\\ds 4\\pi r^3/3$.\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nA hemispheric bowl of radius $r$ contains water to a depth $h$.  Find\nthe volume of water in the bowl.\n\\begin{sol}\n $\\ds \\pi h^2(3r-h)/3$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n The base of a tetrahedron (a triangular pyramid) of height $h$\nis an equilateral triangle of side $s$.  Its cross-sections\nperpendicular to an altitude are equilateral triangles.  Express its\nvolume $V$ as an integral, and find a formula for $V$ in terms of $h$\nand $s$. Verify that your answer is $(1/3)(\\hbox{area of base})(\\hbox{height})$. \n%% fixme: include picture? see exercise_9.3.13.mw\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\nThe base of a solid is the region between $f(x)=\\cos x$ and\n$g(x)=-\\cos x$, $-\\pi/2\\le x\\le\\pi/2$,\nand its cross-sections perpendicular to the $x$-axis \nare squares.\nFind the volume of the solid.\n\\begin{sol}\n $2\\pi$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "9542db0529f3f1bac0dbc485384e447ba0e34ce7", "size": 53187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-3-volume.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "8-applications-of-integration/8-3-volume.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "8-applications-of-integration/8-3-volume.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.6814545455, "max_line_length": 572, "alphanum_fraction": 0.708838626, "num_tokens": 19245, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511616741042, "lm_q2_score": 0.8991213772699435, "lm_q1q2_score": 0.7695140752225017}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\chapter{The \"overturner\" model}\n\\section{Mathematical model}\n\\subsection{Estimation of the parameter values}\n\\textcolor{red}{Vérifier que c'est bien les valeurs finales}\nThe numerical values used here are based on personal communications with \\textit{E. Deleersnijder}.\nThe model for the idealized meridian velocity field in the Atlantic ocean will be complete once we have assigned plausible values to the parameters. For this purpose, some physical insight is needed. First, the Atlantic ocean extends approximately from $50\\degree$ South to $60\\degree$ North, hence over $\\frac{11}{18}\\pi$ radians. With the radius of the Earth estimated to $6\\,371$ km, we get that $L$ must be close to $(\\frac{11}{18}\\pi) (6\\,371) = 12\\, 231$ km. Moreover, the mean depth of the Atlantic ocean is about $4$ km. Hence, we choose $L = 12\\,000$ km and $H = 4$ km. In virtue of the properties of the streamfunction, the maximum $\\Psi = \\psi(y_0,z_0)$ of the meridian streamfunction is equal to the volume flow rate accross any curve connecting $(y_0,z_0)$ to a point on the boundary of the domain: it is thus a measure of the intensity of the meridian circulation. With an estimated rate of deep convection in the Atlantic ocean of about $20$ Sv and a mean width of about $5\\,000$ km, this yields $\\Psi = 4$ $\\rm{m^2/s}$. Finally, we use $y_0 = 11\\,000$ km and $z_0 = 3.5$ km based on qualitative inspection of the meridian streamfunction graph. Characteristic values $V$ and $W$ of the meridional and vertical speed are, in virtue of relations~\\eqref{eq:u-psi} :\n\\begin{equation}\\label{eq:VW}\n\tV = \\frac{\\Psi}{H} \\quad \\mbox{and} \\quad W = \\frac{\\Psi}{L}.\n\\end{equation}\nAccording to \\textit{E. Deleersnijder} [personal communication], the characteristic time scale $T$ should be of the order of a few hundred years in order to be physically significant. It is expressed as\n\\begin{equation} \\label{eq:T}\n\tT = \\frac{L}{V} = \\frac{H}{W} = \\frac{LH}{\\Psi} = 1.5\\e{6} \\mbox{ s} \\approx 475.6 \\mbox{ years},\n\\end{equation}\nan acceptable value.\n\nWith those values of the parameters, the isolines of the adimensional streamfunction $\\psi/\\Psi$ are shown in figure~\\ref{fig:psi_overturner}, and the meridional and vertical components of the velocity field are illustrated in figure~\\ref{fig:vw_overturner}.\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.6\\textwidth]{fig/overturner/psi.eps}\n\t\\caption{Some isolines of the adimensional meridian streamfunction $\\psi(y,z)/\\Psi$, which are also streamlines of the idealised meridian circulation in the Atlantic ocean.}\n\t\\label{fig:psi_overturner}\n\\end{figure}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}[t]{0.4\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/overturner/V_samecaxis.eps}\n\t\t\\caption{$v(y,z)$.}\n\t\t\\label{fig:v_overturner}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.4\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/overturner/W_samecaxis.eps}\n\t\t\\caption{$w(y,z)$.}\n\t\t\\label{fig:w_overturner}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.1\\textwidth}\n\t\t\\includegraphics[height = 4\\textwidth]{fig/overturner/colorbarVW.eps}\n\t\\end{subfigure}\n\t\\caption{Meridional and vertical components of the idealised velocity fields in the adimensional domain. Here, $y_0 = \\frac{11}{12}L$ and $z_0 = \\frac{7}{8}H$.}\n\t\\label{fig:vw_overturner}\n\\end{figure}\n\n\\subsection{Injection of a passive tracer into the ocean} \\label{sec:transport_overturner}\nThe fate of a passive tracer injected at location $(y_*,z_*)$ into the idealised Atlantic ocean depicted previously can be described by a differential problem on that tracer's concentration. The tracer could be any passive tracer whose concentration in the athmosphere is negligible, for example a dye or a set of seawater particles initially located at $(y_*,z_*)$. The concentration of the tracer $C(t,y,z)$ in the ocean obeys the following partial differential equation :\n\\begin{equation}\\label{eq:C_PDE_vec}\n\t\\frac{\\partial C}{\\partial t} = -\\nabla \\cdot \\left(\\b uC - \\b K \\nabla C\\right),\n\\end{equation}\nwhere $\\b K$ is the \\textit{diffusivity tensor}. Without loss of generality, we can assume $\\b K$ to be symmetric. This is essentially because the impact of the anti-symmetric part of $\\b K$, if any, may be viewed as additional advection. More details may be found in appendix A of \\cite{deleersnijder2001concept}. Of course, the symmetric tensor $\\b K$ must then be positive-definite in order to represent truly diffusive processes, namely phenoma which tend, at any time and location, to homogenise the concentration of any constituent. For our problem, we consider that $\\b K$ has the form\n\\begin{equation} \\label{eq:K}\n\t\\b K(y,z) = \\begin{pmatrix} K_h & 0 \\\\ 0 & K_v(y,z) \\end{pmatrix},\n\\end{equation}\nwhere $K_h$ is a positive constant and\n\\begin{equation} \\label{eq:Kv}\n\tK_v(y,z) = \\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\tK_{v_1} & \\mbox{if} & y_0 \\le y \\le L, & 0 \\le z \\le H,\\\\\n\t\t\tK_{v_2} & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\tK_{v_3} & \\mbox{if} & 0 \\le y < y_0, & z_0 \\le z \\le H,\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nwith $K_{v_1}$, $K_{v_2}$ and $K_{v_3}$ positive constants. In the framework of the idealised model of the meridian circulation in the Atlantic ocean, \\textit{E. Deleersnijder} [personal communication] proposes the values $K_h = 10^3$ $\\rm{m^2/s}$, $K_{v_1} = 10^{-1}$ $\\rm{m^2/s}$, $K_{v_2} = 10^{-4}$ $\\rm{m^2/s}$ and $K_{v_3} = 10^{-3}$ $\\rm{m^2/s}$. The relatively large value of $K_{v_1}$ allows to represent deep convection in the corresponding zone without having to implement a convective adjustment algorithm. The developped form of~\\eqref{eq:C_PDE_vec} is then\n\\begin{equation}\\label{eq:C_PDE_dev}\n\t\\frac{\\partial C}{\\partial t} = -\\frac{\\partial}{\\partial y}\\left(vC - K_h\\frac{\\partial C}{\\partial y}\\right) -\\frac{\\partial}{\\partial z}\\left(wC - K_v(y,z)\\frac{\\partial C}{\\partial z}\\right).\n\\end{equation}\nNo-flux conditions are imposed at the boundaries \\textcolor{red}{vérifier/discuter le flux nul à la surface}\n\\begin{equation}\\label{eq:C_PDE_BC}\n\t\\left. K_h\\frac{\\partial C}{\\partial y} \\right|_{y=0} = 0, \\quad  \\left. K_h\\frac{\\partial C}{\\partial y} \\right|_{y=L} = 0, \\quad \\left. K_v\\frac{\\partial C}{\\partial z} \\right|_{z=0} = 0, \\quad \\mbox{and} \\quad \\left. K_v\\frac{\\partial C}{\\partial z} \\right|_{z=H} = 0.\n\\end{equation}\nThe initial condition is\n\\begin{equation} \\label{eq:C_PDE_CI}\n\tC(0,y,z) = \\delta(y-y_*)\\delta(z-z_*),\n\\end{equation}\nwhere $\\delta$ is the Dirac delta function, such that\n\\begin{equation}\n\t\\int_0^L \\int_0^H C(0,y,z) \\rm dy \\rm dz = 1.\n\\end{equation}\n\nIn order to get a formulation of the problem using as few independent parameters as possible, it is interesting to consider the adimensional formulation. Such a scaling is particularly interesting for sensitivity analysis. The adimensional independent variables are\n\\begin{equation}\n\tt' = \\frac{t}{T} = \\frac{t\\Psi}{LH}, \\quad y' = \\frac{y}{L} \\quad \\mbox{and} \\quad z' = \\frac{z}{H},   \t\n\\end{equation}\nwhere $T$ is the time scale introduced in~\\eqref{eq:T}. The adimensional hydrodynamic variables are:\n\\begin{equation}\n\t\\psi' = \\frac{\\psi}{\\Psi}, \\quad v' = \\frac{v}{V} = \\frac{vH}{\\Psi}, \\quad \\mbox{and} \\quad w' = \\frac{w}{W} = \\frac{wL}{\\Psi},\n\\end{equation}\nwhere $V$ and $W$ are the velocity scales introduced in~\\eqref{eq:VW}. The adimensional concentration is\n\\begin{equation}\n\tC' = \\frac{C}{C_r}, \t\n\\end{equation}\nwhere $C_r$ is a characteristic value of the concentration. We will see shortly that there is no needed to assign a particular value to $C_r$. The adimensional form of equation~\\eqref{eq:C_PDE_dev} is then\n\\begin{equation}\\label{eq:PDE_adim}\n\t\\frac{\\partial C'}{\\partial t'} = -\\frac{\\partial}{\\partial y'}\\left(v'C' - \\frac{1}{Pe_h}\\frac{\\partial C'}{\\partial y'}\\right) -\\frac{\\partial}{\\partial z'}\\left(w'C' - \\frac{1}{Pe_v(y,z)}\\frac{\\partial C'}{\\partial z'}\\right),\n\\end{equation}\nwhere\n\\begin{equation}\n\tPe_h = \\frac{\\Psi L}{K_h H} \\quad \\mbox{and} \\quad Pe_v(y,z) = \\frac{\\Psi H}{K_v(y,z)L}\n\\end{equation}\nare the horizontal and vertical Péclet numbers. They correspond to the ratio between the characteristic advective and diffusive velocity scales. Indeed, the horizontal and vertical diffusive velocity scales $V_{d}$ and $W_{d}$ are \n\\begin{equation}\n\tV_{d} = \\frac{K_h}{L} \\quad \\mbox{and} \\quad W_{d}(y,z) = \\frac{K_v(y,z)}{H}.\n\\end{equation}\nThere are three different vertical diffusive velocity scale depending on which zone of the ocean we consider \\textcolor{red}{Donner des noms aux zones dans le chap 1 : 1 = ?, 2 = \"Deep convection\" et 3 = \"surface flow\"}. The advective velocity scales $V$ and $W$ have already been introduced in~\\eqref{eq:VW}. The Péclet numbers may then be rewritten as\n\\begin{equation}\n\tPe_h = \\frac{V}{V_{d}} = 12, \n\\end{equation}\nand\n\\begin{equation}\n\tPe_{v}(y,z) =  \\frac{W}{W_{d}(y,z)}=  \\left\\{\n\t\\begin{array}{lrrr}\n\t\t\tPe_{v_1} = 1.33\\e{-2} & \\mbox{if} & y_0 \\le y \\le L, & 0 \\le z \\le H,\\\\\n\t\t\tPe_{v_2} = 13.3 & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\tPe_{v_3} = 1.33 & \\mbox{if} & 0 \\le y < y_0, & z_0 \\le z \\le H.\n\t\\end{array}\n\t\\right.\n\\end{equation}\nThis shows that the advective and diffusive processes are of equal importance in the dynamics of our model, excepted in the zone of deep convection where the vertical diffusion dominates the vertical convection. This is because we have chosen to represent deep convection via a heavy vertical mixing in that zone. ", "meta": {"hexsha": "3e4edda2ad8cf74375450007615cfbd52bca85dd", "size": 9448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/overturner/overturner.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/overturner/overturner.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/overturner/overturner.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": 80.0677966102, "max_line_length": 1277, "alphanum_fraction": 0.717188823, "num_tokens": 3120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668095, "lm_q2_score": 0.8558511414521922, "lm_q1q2_score": 0.769514054727068}}
{"text": "\\chapter{Primitive recursive functions}\n\\label{chapter:primrec}\n\n\\section{Introduction}\nPrimitive recursive functions are a small class of total functions, corresponding to the expressive power of a simple imperative programming language without \\textbf{while} loops, in which every program execution terminates.\n\nPrimitive recursive functions are total functions from $\\mathbb{N}^n$ to\n$\\mathbb{N}$, for some $n\\in\\mathbb{N}$. Note that not all \ntotal $n$-ary recursive functions are primitive recursive\n(see for instance Sect.~\\vref{sect:ack-not-PR}).\n\nThe traditional definition of the set of primitive recursive functions is structured as an inductive definition \nin five rules: three base cases, and two recursive construction rules. \n\n\\begin{description}\n  \\item[zero] the constant function of value $0$ is primitive recursive.\n\\item[S] The successor function $S:\\mathbb{N}\\rightarrow\\mathbb{N}$ is primitive recursive.\n \\item[projections] For any pair $0< i\\leq n$, the projection $\\pi_{i,n}: \\mathbb{N}^n\\rightarrow\\mathbb{N}$, defined by $\\pi_{i,n}(x_1,x_2,\\dots,x_{n})=x_i$, is primitive recursive.\n\\item[composition] For any $n$ and $m$, if $h: \\mathbb{N}^m\\rightarrow\\mathbb{N}$, and\n$g_0,\\dots, g_{m-1}: \\mathbb{N}^n\\rightarrow\\mathbb{N}$ are primitive recursive of $n$ arguments, then the function which maps any\ntuple $(x_0,\\dots,x_{n-1})$ to $h(g_0(x0,\\dots,x_{n-1}),\\dots, g_{m-1}(x0,\\dots,x_{n-1})): \\mathbb{N}^n\\rightarrow\\mathbb{N}$ is primitive recursive.\n\\item[primitive recursion]\nIf $g: \\mathbb{N}^n\\rightarrow\\mathbb{N}$ and $h: \\mathbb{N}^{n+2}\\rightarrow\\mathbb{N}$ are primitive recursive, then the function from $\\mathbb{N}^{n+1}$ into $\\mathbb{N}$ defined by\n\\begin{align}\nf(0,x_1,\\dots,x_n)&=g(x_1,\\dots,x_n)\\\\\nf(S(p),x_1,\\dots,x_n)&=h(p,f(p, x_1,\\dots,x_n),  x_1,\\dots,x_n)\n\\end{align} \nis primitive recursive.\n\\end{description}\n\n\nPlease note the use of dots: $\\ldots$ in the definition above. \nDots are not part of \\gallina's syntax. Thus, the formal definition of the set of primitive recursive function will have to overcome this representation problem.\n\n  We present in this chapter a formalization of  primitive recursive functions, taken from  Russel O'Connor's formalization in \\coq{} of\nG\\\"odel's incompleteness theorems~\\cite{OConnor05}.\n\n\\begin{remark}\n The theory of primitive recursive function is now hosted in\nthe \\texttt{theories/ordinals/Ackermann} directory.\nThe specific part on G\\\"odel's theorem,  is also on\ncoq-community (\\url{https://github.com/coq-community/goedel}) and requires the \n\\href{https://github.com/coq-community/pocklington}{Pocklington library} for lemmas on primality.\n\\end{remark}\n\nThis chapter contains some comments on Russel's library, as well as a few extensions.\nContributions (under the form of comments, new examples or exercises) are welcome!. \n\n\n\n\\section{First look at the Ackermann library}\n\nO'Connor's library on Gödel's incompleteness theorems contains a little more \nthan 45K lines of scripts. The part dedicated to primitive recursive functions and Peano arithmetic is 32K lines long and is originally structured in 38 modules.\nThus, we propose a partial exploration of this library, through examples and exercises. Our additions to the original library --- mainly examples and counter-examples ---,\nare stored in the directory \\texttt{theories/ordinals/MoreAck}.\n\nIn particular, the library \\href{../theories/html/hydras.MoreAck.html}{MoreAck.AckNotPR} contains the well-known  proof that the Ackermann function is not primitive recursive (see Section~\\vref{sect:ack-not-PR}).\nMoreover, the library \\href{../theories/html/hydras.Hydra_Theorems.html}{Hydra.Hydra\\_Theorems} contains \na proof that the length of an hydra battle (according to the initial replication factor) is not primitive recursive in general.\n\n\\section{Basic definitions}\n\\index{maths}{Primitive recursive functions}\n\nThe formal definition of primitive recursive functions lies in the library\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec},\nwith preliminary definitions in \n\\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat}\nand\n\\href{../theories/html/hydras.Ackermann.misc.html}{Ackermann.misc}.\n\n\\subsection{Functions of arbitrary arity}\n\nThe  \\texttt{primRec} library allows us to consider primitive functions on \\texttt{nat}, with any number of arguments, in \ncurried form. This is made possible in \n\\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat} by the following definition:\n\n\\index{primrec}{Types!naryFunc}\n\\input{movies/snippets/extEqualNat/naryFunc.tex}\n\nFor instance (\\texttt{naryFunc 1}) is convertible to \\texttt{nat -> nat} and (\\texttt{naryFunc 3})\nto \\texttt{nat -> nat -> nat -> nat}.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}}.\n\n\\input{movies/snippets/PrimRecExamples/naryFunc3}\n\\input{movies/snippets/PrimRecExamples/checknaryFunc}\n\n\nLikewise, arbitrary boolean predicates may have an arbitrary number of arguments. The dependent type\n(\\texttt{naryRel $n$}), defined in the same way as \\texttt{naryFunc}, is the type of $n$-ary functions from\n\\texttt{nat} into \\texttt{bool}.\n\n\\input{movies/snippets/PrimRecExamples/naryRel2}\n\nThe magic of dependent types makes it possible to define recursively extensional equality between functions of the same arity.\n\n\\index{coq}{Dependent types}\n\\index{coq}{Dependently typed functions}\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.extEqualNat.html}{Ackermann.extEqualNat}}\n\n\\index{primrec}{Predicates!extEqual}\n\n\\input{movies/snippets/extEqualNat/extEqualDef}\n\n\n\\input{movies/snippets/PrimRecExamples/extEqual2a}\n\n  Getting rid of the term \\texttt{x-x}, we generate two easy-to-solve sub-goals.\n\n\\vspace{6pt}\n\\noindent\n\\input{movies/snippets/PrimRecExamples/extEqual2b}\n  \n\\subsection{A Data-type for Primitive Recursive Functions}\n\nO'Connor's formalization of primitive recursive functions takes the form of two mutually inductive dependent data types, each constructor of which is associated with one of these  rules.\nThese two types are (\\texttt{PrimRec $n$}) (primitive recursive functions of $n$ arguments), and\n(\\texttt{PrimRecs $n$ $m$}) ($m$-tuples of primitive recursive functions of $n$ arguments).\n\n\n\\index{coq}{Dependent types}\n\\index{coq}{Mutually inductive types}\n\n\\index{primrec}{Types!PrimRec}\n\\index{primrec}{Types!PrimRecs}\n\\label{def:Primrec}\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\input{movies/snippets/primRec/PrimRecDef}\n\n\\begin{remark}\n\\label{projFunc-order-of-args}\nBeware of the conventions used in the \\texttt{primRec} library!\nThe constructor (\\texttt{projFunc $n$ $m$})  is associated with the projection $\\pi_{n-m,n}$ and \\emph{not}\n$\\pi_{n, m}$.\nFor instance, the projection $\\pi_{2,5}$ defined by $\\pi_{2,5}(a,b,c,d,e)=b$ corresponds to the term\n(\\texttt{projFunc 5 3 H}), where \\texttt{H} is a proof of $3<5$.\n This fact is reported in the comments of \\texttt{primRec.v}. We presume that this convention makes it easier to define the evaluation function (\\texttt{evalProjFunc $n$}) (see the next sub-section). Trying the other convention is left as an exercise.\n\\end{remark}\n\n\n\n\\subsection{A little bit of semantics} \nPlease note that inhabitants of type (\\texttt{PrimRec $n$}) are not \\coq{} functions like \\texttt{Nat.mul}, or factorial, etc. The data-type (\\texttt{PrimRec $n$}) is indeed an abstract syntax for the language of primitive recursive functions. The bridge between this language and the word of usual functions\nis an interpretation function (\\texttt{evalprimRec $n$})  of type\n$\\texttt{PrimRec}\\,n \\rightarrow  \\texttt{naryFunc}\\,n$.\nThis function is defined by mutual recursion,  together with the  function \n(\\texttt{evalprimRecS $n$ $m$}) of type \n$\\texttt{PrimRecs}\\,n\\,m \\rightarrow  \\texttt{Vector.t}\\,(\\texttt{naryFunc}\\,n)\\,m$.\n\n\\index{primrec}{Functions!evalPrimRec}\n\\index{primrec}{Functions!evalPrimRecs}\n\n\\index{coq}{Dependent pattern matching}\nBoth functions are mutually defined through dependent pattern matching. We advise the readers who \nwould feel uneasy with dependent types to consult Adam Chlipala's \\emph{cpdt}  book~\\cite{chlipalacpdt2011}. We leave it to the reader  to look also at the helper functions in\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.\n\n\\vspace{4pt}\n\n\\input{movies/snippets/primRec/evalPrimRecDef}\n\n\\vspace{4pt}\n\nLooks complicated? The following examples show that, when\nthe arity is fixed, these definitions behave well w.r.t. \n\\coq's reduction rules. Moreover, they make the interpretation functions more ``concrete''.\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}.}\n\n\\input{movies/snippets/PrimRecExamples/evalPrimRecEx}\n\n\\vspace{4pt}\n\\noindent\n\nAnother example?\nLet us consider the following term\\footnote{Of course, we never typed this term \\emph{verbatim}; we obtained it by an interactive proof the reader will be able to make after \nreading Sect.\\vref{sect:proofs-of-isPR}.}:\n\n\\label{sect:bigfac}\n\n\\input{movies/snippets/PrimRecExamples/bigPRa}\n\n\nLet us now interpret this term as an arithmetic function.\n\n\\vspace{4pt}\n\\noindent\n\n\\input{movies/snippets/PrimRecExamples/bigPRb}\n\n\nAfter this test, the term \\texttt{bigPR} looks to be a primitive recursive definition of the factorial function, although we haven't proved this fact yet. Fortunately, we will see in the following sections simple ways to prove that a given function is primitive recursive, without building such an unreadable term.\n\n\\section{Proving that a given arithmetic function is primitive recursive}\n\\label{sect:proofs-of-isPR}\n\nThe example in the preceding section clearly shows that, in order to prove that a given arithmetic function\n(defined in \\gallina{} as usual) is primitive recursive, trying to give  by hand a term  of type (\\texttt{PrimRec $n$}) is not a good method, since such terms may be huge and complex, even for simple arithmetic functions. The method proposed in Library \\texttt{primRec} is the following one:\n\n\\begin{enumerate}\n\\item Define a type corresponding to the statement \"the function \\texttt{$f$:naryFunc $n$} is primitive recursive ''.\n\\item Prove handy lemmas which may help to prove that a given function is primitive recursive.\n\\end{enumerate}\n\nThus, the proof that a function, like \\texttt{factorial}, is primitive recursive may be interactive, without having to type complex terms at any step of the development.\n\n\\subsection{The predicate \\texttt{isPR}}\n\n\\index{primrec}{Predicates!isPR}\n\\index{coq}{Extensionally equal functions}\n\nLet $f$ be an arithmetic function of arity $n$. We say that $f$ is primitive recursive if $f$ is \\textbf{extensionally}\nequal to the interpretation of some term of type \\texttt{PrimRec $n$}. \n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\input{movies/snippets/primRec/isPRDef}\n\nThe library \\texttt{primRec} contains a large catalogue of lemmas allowing to prove statements \nof the form (\\texttt{isPR $n$ $f$}). We won't list all these lemmas here, but give a few examples of\nhow they may be applied.\n\n\\begin{remark}\nIn the library \\texttt{primRec}, all these lemmas are opaque (registered with \\texttt{Qed}. Thus they do not allow the user to look at the witness of a proof of a \\texttt{isPR} statement. Our example of page~\\pageref{sect:bigfac} was built using a  copy of \\texttt{primRec.v} where many \\texttt{Qed}s have been replaced with\n\\texttt{Defined}s.\n\nIf it does not cause compatibility problems (with \n\\href{https://github.com/coq-community/goedel}{goedel library} for instance), we plan to make all theses lemmas transparent.\n\\end{remark}\n\n\\subsubsection{Elementary proofs of \\texttt{isPR} statements}\n\nThe constructors \\texttt{zeroFunc}, \\texttt{succFunc},  and \\texttt{projFunc} of type\n\\texttt{PrimRec} allows us to write trivial proofs of primitive recursivity. \nAlthough  the following lemmas are already proven in \n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec},\nwe wrote alternate proofs in \n\\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}%\n{Ackermann.MoreAck.PrimRecExamples.v}, in order to illustrate the main proof patterns.\n\n\\input{movies/snippets/PrimRecExamples/zeroIsPR}\n\n\nLikewise, we prove that the successor function on \\texttt{nat} is primitive recursive too.\n\n\\input{movies/snippets/PrimRecExamples/SuccIsPR}\n\n\n\nProjections are proved primitive recursive, case by case (many examples in \n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}).\n\\emph{Please notice again that the name of the projection follows the mathematical tradition, \nwhilst the arguments of  \\texttt{projFunc} use another convention (\\emph{cf} remark~\\vref{projFunc-order-of-args}).}\n\n\n\\input{movies/snippets/PrimRecExamples/pi25IsPR}\n\n\n\nPlease note that the projection $\\pi_{1,1}$ is just the identity on \\texttt{nat}, and is realized by \n(\\texttt{projFunc 1 0}).\n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\input{movies/snippets/primRec/idIsPR}\n\n\\subsubsection{Using function composition}\n\nLet us look at the proof that any constant $n$ of type \\texttt{nat} has type (\\texttt{PR 0})\n(lemma  \\texttt{const1\\_NIsPR} of \\texttt{primRec}). We carry out a proof by induction on $n$, the base case of which is already proven.\nNow, let us assume $n$ is \\texttt{PR $n$}, with $x:\\texttt{PrimRec}\\,0$ as a ``realizer''.\nThus we would like to compose this constant function with the unary successor function.\n\nThis is exactly the role of the instance \\texttt{composeFunc 0 1} of the dependently typed\nfunction \\texttt{composeFunc}, as shown by the following lemma.\n\n\\vspace{4pt}\n\\input{movies/snippets/PrimRecExamples/compose01}\n\n\n\\vspace{4pt}\nThus, we get a quite simple proof of \\texttt{const1\\_NIsPR}.\n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}}.\n\n\\input{movies/snippets/PrimRecExamples/const0NIsPR}\n\n\\subsubsection{Proving that \\texttt{plus} is primitive recursive}\n\nThe lemma \\texttt{plusIsPR} is already proven in \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}. We present in \n\\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}\na commented version of this proof, \n\nFirst, we look for lemmas which may help to prove that a given function obtained with the recursor \\texttt{nat\\_rec} is primitive recursive.\n\n\\input{movies/snippets/PrimRecExamples/PrimRecExamplesSearch}\n\nThe following lemma shows it suffices to prove that\nStandard library's function \\texttt{plus} is extensionally equal to a function defined with\n\\texttt{nat\\_rec}.\n\n\\input{movies/snippets/PrimRecExamples/isPRExtEqualTrans}\n\nThus, let us define an helper and prove its equivalence with \\texttt{plus}.\n\n\\input{movies/snippets/PrimRecExamples/plusAlt}\n\n\n\\vspace{4pt}\n\n\nWe are now able to complete the proof.\n\n\\input{movies/snippets/PrimRecExamples/plusIsPRa}\n\n\nWe already proved that \\texttt{S} is \\texttt{PR 1}, but we need to consider a function of three arguments, which ignores its first and third arguments.\nFortunately, the library \\texttt{primRec} already contains lemmas adapted to this kind of situation.\n\n\\vspace{4pt}\n\\input{movies/snippets/PrimRecExamples/checkFilter0101IsPR}\n\\vspace{4pt}\n\n\nThus, our first subgoal is solved easily. The rest of the proof \nis just an application of already proven lemmas.\n\n\\vspace{4pt}\n\n\\input{movies/snippets/PrimRecExamples/plusIsPRb}\n\n\n\\begin{todo}\nComment more examples from   \\href{../theories/html/hydras.MoreAck.PrimRecExamples.html}{MoreAck.PrimRecExamples}.\n\\end{todo}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nThere is a lot of lemmas similar to \\texttt{filter010IsPR} in the \\texttt{primRec} library, useful to control the arity of functions.\nThus, the reader may look at them, and invent simple examples of application for each lemma.\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nMultiplication of natural number is already proven in the \\texttt{primRec} library. Write a proof of your own, then compare to the library's version.\n\\end{exercise}\n\n%\\input{movies/snippets/PrimRecExamples/justATest}\n\n\\subsubsection{More examples}\n\nThe following proof decomposes the \\texttt{double} function as the composition of \nmultiplication with the identity and the constant function which returns $2$.\n\\emph{Note that the lemma \\texttt{const1\\_NIsPR} considers this function as an unary function (unlike \\texttt{const0\\_NIsPR})}. \n\\input{movies/snippets/PrimRecExamples/doubleIsPRa}\n\n\\input{movies/snippets/PrimRecExamples/doubleIsPRb}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nProve that the following functions are primitive recursive. \n\n\\input{movies/snippets/MorePRExamples/factDef}\n\n\\input{movies/snippets/MorePRExamples/expDef}\n\n\\input{movies/snippets/MorePRExamples/tower2Def}\n\n\n\\textbf{Hint:} You may have to look again at the lemmas of the library\n\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec} if you meet some difficulty.\nYou may start this exercise with the file\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/MorePRExamples.v}{exercises/primrec/MorePRExamples.v}.\n\\end{exercise}\n\n\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\nShow that the function \\texttt{min: naryFunc\\,2} is primitive\nrecursive.\n\n\\emph{You may start this exercise with\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/MinPR.v}{exercises/primrec/MinPR.v}.}\n\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\n\\begin{exercise}\nWrite a simple and readable proof that the Fibonacci function is primitive recursive.\n\n\\input{movies/snippets/FibonacciPR/fibDef}\n\n\n\\textbf{Hint:}  You may use as a helper the function which computes the pair \\linebreak\n$(\\texttt{fib}(n+1),\\texttt{fib}(n))$. \nLibrary \\href{../theories/html/hydras.Ackermann.cPair.html}{Ackermann.cPair} contains\nthe definition of the encoding of $\\mathbb{N}^2$ into $\\mathbb{N}$, and the proofs that \nthe associated constructor and projections are primitive recursive.\n\\emph{You may start this exercise with the file\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/FibonacciPR.v}{exercises/primrec/FibonacciPR.v}.}\n\n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\\begin{exercise}\n\nProve the following lemmas (which may help to solve the next  exercise).\n\n\\inputsnippets{isqrt/boundedSearch3, isqrt/boundedSearch4}\n\n\\textbf{Note:}  The function \\texttt{boundedSearch} is defined\nin Library \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}. \n\\end{exercise}\n\n\\index{primrec}{Exercises}\n\n\\begin{exercise}\nProve that the function which returns the  integer square root of any natural number  is primitive recursive.\n\n\\emph{You may start this exercise with the file\n    \\href{https://github.com/coq-community/hydra-battles/blob/master/exercises/primrec/isqrt.v}{exercises/primrec/isqrt.v}.}\n\n\\end{exercise}\n\n\\section{Proving that a given function is \\emph{not} primitive recursive}\n\\label{sect:ack-not-PR}\n\nThe best known example of a total recursive function which is not primitive recursive is the Ackermann function. We show how to adapt the classic proof (see for instance~\\cite{planetmath}) to the constraints of \\gallina. We hope this formal proof \n is a nice opportunity to explore\nthe treatment of primitive recursive functions by R. O'Connor,\nand to play with dependent types.\n\n\\subsection{Ackermann function}\n\nAckermann function is traditionally defined as a function from \n$\\mathbb{N}\\times \\mathbb{N}$ into $\\mathbb{N}$, through\nthree equations:\n\n\\begin{align}\nA(0,n)&=n+1\\\\\nA(m+1,0)&=A(m,1)\\\\\nA(m+1,n+1)&=A(m,A(m+1,n))\n\\end{align}\n\nLet us try to define this function in \\coq{} (in curried form).\n\n\\input{movies/snippets/Ack/AckFixpointFail.tex}\n\nA possible workaround is to make \\texttt{m} be the \ndecreasing argument, and define --- within \\texttt{m}'s scope --- a local helper function which computes (\\texttt{Ack m n}) for any \\texttt{n}.\nThis way, both functions \\texttt{Ack} and \\texttt{Ackm} have a (structurally) strictly decreasing argument.\n\n\\input{movies/snippets/Ack/AckFixpointAlt.tex}\n\nWe preferred to define a variant which uses explicitly\n the functional \\texttt{iterate},\nwhere (\\texttt{iterate\\,$f$\\,$n$})\nis the $n$-th iteration of $f$\\,\\footnote{Please not confuse with \\texttt{primRec.iterate}, which is monomorphic and does not share the same order of arguments.}. It makes it possible to apply a few lemmas proved in \n\\href{../theories/html/hydras.Prelude.Iterates.html}{Prelude.Iterates}, for instance about the monotony of the $n$-th iterate of a given function. \n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Prelude.Iterates.html}{Prelude.Iterates}}.\n\\index{hydras}{Library Prelude!iterate}\n\n\\input{movies/snippets/Iterates/iterateDef}\n\n\\input{movies/snippets/Iterates/iterateLeNSN}\n\n\nThus, our definition of the Ackermann function is as follows:\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}}.\n\\index{maths}{Ackermann function}\n\\index{primrec}{Ackermann function}\n\n\\input{movies/snippets/Ack/AckFixpointIterate.tex}\n\n\n\\index{hydras}{Exercises}\n\n\\begin{exercise}\nThe file \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack} presents two other definitions of the Ackermann functions based on the lexicographic ordering on $\\mathbb{N}\\times\\mathbb{N}$.\nProve that the four functions are extensionally equal.\n\\end{exercise}\n\n\n\\subsubsection{First properties of the Ackermann function}\n\nThe three first lemmas make us sure that our function \n\\texttt{Ack} satisfies the ``usual'' equations.\n\n\\input{movies/snippets/Ack/AckRewrite}\n\n\n\\vspace{4pt}\n\nThe order of growth of the Ackermann function w.r.t. its first argument is illustrated by the following equalities.\n\n\\input{movies/snippets/Ack/Ack1N}\n\\input{movies/snippets/Ack/Ack2N}\n\\input{movies/snippets/Ack/Ack3N}\n\\input{movies/snippets/Ack/Ack4N}\n\n\n\\begin{remark}\n The statements above can be rewritten in a more uniform way:\n\n \\begin{quote}\n   For $m\\in 1..4$, $\\texttt{Ack}\\,m\\,n = f_m\\,(n+3)-3$, where \n   \\begin{align*}\n   f_1(n)=&\\,n+2 \\\\\n   f_2(n)=&\\,n\\times 2\\\\\n   f_3(n)=&\\,2^n\\\\\n   f_4(n)=&\\,2^{2^{\\dots^2}}\\quad(n\\;\\textit{levels})\n   \\end{align*}\n \\end{quote}\n\\end{remark}\n\n\nAn important property of the Ackermann function helps us \nto overcome the difficulty raised by nested recursion, by climbing up the hierarchy $\\texttt{Ack}\\,n\\,\\_\\;(n\\in\\mathbb{N})$.\n\n\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}}.\n\n\\input{movies/snippets/Ack/nestedAckBound}\n\n\n\nPlease note also that for any given $n$, the unary function\n(\\texttt{Ack\\,$n$}) is primitive recursive.\n\n\\vspace{4pt}\n\n\\noindent\n\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}}.\n\n\\input{movies/snippets/AckNotPR/AckNIsPR}\n\n\n\n\n\n\\subsection{A proof by induction on all primitive recursive functions}\n\nIn order to prove that \\texttt{Ack} (considered as a function of two arguments) is not primitive recursive, the usual method consists in two steps:\n\n\n\\begin{enumerate}\n\\item Prove that for any primitive recursive function $f:\\mathbb{N}\\rightarrow\\mathbb{N}\\rightarrow\\mathbb{N}$, there exists some natural number $n$ depending on $f$, such that, for any $x$ and $y$, \n$f\\,x\\,y \\leq \\texttt{Ack}\\,n\\,(\\textrm{max}\\,x\\,y)$ (we say that $f$ is \\emph{``majorized''}  by \\texttt{Ack}).\n\\item Show that \\texttt{Ack} fails to satisfy this property.\n\\end{enumerate}\n\nFirst, we prove that any primitive function of two arguments is majorized by \\texttt{Ack}.\nIf we look at the inductive definition of primitive recursive functions, page~\\pageref{def:Primrec}, it is obvious that a proof by induction on the construction of primitive recursive functions must consider functions of any arity.\n\nThe following scheme allows us to write proofs by induction on the class of primitive recursive functions. \n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.}\n\n\\index{coq}{Commands!Scheme}\n\n\\input{movies/snippets/primRec/SchemePrimRecInd}\n\n\n\nPlease note that, in order to prove a property shared by any primitive recursive function of, say, arity 2, this induction scheme  leads you to consider an extension of the considered property to primitive recursive function of any arity.\n\nThus the lemma we will have to prove is the following one:\n\n\n  \\begin{quote}\n    For any $n$, and any primitive recursive function $f$ of  arity $n$, there exists some natural number $q$ such that the following inequality holds:\n \\[\n  \\forall x_1,\\dots,x_n, \n      f(x_1,\\dots,\\,x_n)\\leq\\textrm{Ack}(q,\\textrm{max}(x_1,\\dots,x_n))\n\\]\n \\end{quote}\n\n\nBut dots don't belong to \\gallina's syntax! So, we may use \\coq's vectors for denoting arbitrary tuples.\n\nFirst, we extend \\texttt{max} to vectors of natural numbers (using the notations of module \\texttt{VectorNotations} and some more definitions from \n\\href{../theories/html/hydras.Prelude.MoreVectors.html}{Prelude.MoreVectors}). So, (\\texttt{t\\,$A$\\,$n$}) is the type of vectors of $n$ elements of type $A$, and the constants \\texttt{cons}, \\texttt{nil}, \\texttt{map}, etc., refer to vectors and not to lists. Likewise, the notation \\texttt{x::v} is an abbreviation for\n\\texttt{VectorDef.cons x \\_ v}.\n\n\\index{coq}{Dependently typed functions}\n\n\\input{movies/snippets/MoreVectors/maxvDef}\n\n\\input{movies/snippets/MoreVectors/maxvLemmasa}\n\n\\input{movies/snippets/MoreVectors/maxvLemmasb}\n\n\\input{movies/snippets/MoreVectors/maxvLemmasc}\n\n\nWe have also to convert any application\n$(f\\,x_1\\,x_2\\,\\dots\\,x_n)$ into an application of a function \nto a single argument: the vector of all the $x_i$\\,s.\nThis is already defined in \nLibrary~\\href{../theories/html/hydras.Ackermann.primRec.html}{Ackermann.primRec}.\n\n\n\\input{movies/snippets/primRec/evalListDef}\n\nIndeed, (\\texttt{evalList $m$ $v$ $f$}) is the application to the vector $v$ of\nan uncurried version of $f$.\nIn Library\\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}, we introduce a lighter notation.\n\n\\index{coq}{Dependently typed functions}\n\n\\input{movies/snippets/AckNotPR/vApply}\n\n\n\nWe are now able to translate in \\gallina{} the notion of ``majorization'':\n\n\\index{coq}{Dependently typed functions}\n\n\\input{movies/snippets/AckNotPR/majorizedDefs}\n\n\nNow, it remains to prove that any primitive function is majorized by \\texttt{Ack}.\nThe three base cases  are as follows:\n\n\\input{movies/snippets/AckNotPR/majorSucc}\n\n\\input{movies/snippets/AckNotPR/majorZero}\n\n\\input{movies/snippets/AckNotPR/majorProjection}\n\n\n\nThe remaining cases are proved within a mutual  induction.\n\n\\index{coq}{Mutual induction}\n\n\\input{movies/snippets/AckNotPR/majorAnyPRa}\n\n\n\n\\input{movies/snippets/AckNotPR/majorAnyPRb}\n\n\nThe last two goals deal with vectors of functions.\n\n\\input{movies/snippets/AckNotPR/majorAnyPRVec}\n\n\n\\subsection{Looking for a contradiction}\n\nThe following lemma is just a specialization of \\texttt{majorAnyPR} to\nbinary functions (forgetting vectors, coming back to usual notations).\n\n\\input{movies/snippets/AckNotPR/majorPR2}\n\nWe prove also a strict version of this lemma, thanks to the following property (proved in Library\n\\href{../theories/html/hydras.MoreAck.Ack.html}{MoreAck.Ack}~).\n\n\\input{movies/snippets/Ack/AckStrictMonoL}\n\n\n\\vspace{4pt}\n\\noindent\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}.}\n\n\n\\input{movies/snippets/AckNotPR/majorPR2Strict}\n\n\n\nIf the Ackermann function were primitive recursive, then there would exist some natural number $n$, such that, for all $x$ and $y$, the inequality \n$\\texttt{Ack}\\,x\\,y\\leq \\texttt{Ack}\\,n\\,(\\texttt{max}\\,x\\,y)$ holds.\nThus, our impossibility proof is just a sequence of easy small steps.\n\n\\input{movies/snippets/AckNotPR/AckNotPR}\n\n\\begin{remark}\nIt is easy to prove that any unary function which dominates \\texttt{fun n => Ack n n} fails to be primitive recursive. To this end, we use an instance of \\texttt{majorAnyPR} dealing with unary functions.\n\n\\vspace{4pt}\n\\noindent\n\n\\emph{From \\href{../theories/html/hydras.MoreAck.AckNotPR.html}{MoreAck.AckNotPR}}.\n\n\\input{movies/snippets/AckNotPR/majorPR1}\n\nThen, we write  a short proof by contradiction.\n\n\\input{movies/snippets/AckNotPR/domAckNotPR}\n\n\\end{remark}\n\n\\begin{remark}\nNote that the Ackermann function is a counter-example to the (false) statement:\n\\begin{quote}\n{\\color{red}\n  ``Let $f$ be a function of type \\texttt{naryFunc\\,2}. If, for any $n$, the function $f(n)$ is primitive recursive, then f is primitive recursive.''}\n\\end{quote}\n\\end{remark}\n\n\n\\section{The length of standard hydra battles}\n\\label{sect:battle-length-notPR}\n\nThe module \\href{../theories/html/hydras.Hydra.Hydra_Theorems.html}{Hydra\\_Theorems} contains a proof that the function which computes the length of standard hydra battles is not primitive recursive. More precisely, we consider, for a given hydra $h=\\iota(\\alpha)$, the length of a standard battle which starts with the replication factor $k$ (see Sect~\\vref{def:L-alpha}).\n\nThis proof is  a little more complex than the preceding one.\n\n\\subsection{Definitions}\n\nThe function we consider is defined and proven correct in\nModule~\\href{../theories/html/hydras.Hydra.Battle_length.html}{Hydra.Battle\\_length}.\n\n\\input{movies/snippets/Battle_length/BattleLength}\n\n\\subsection{Proof steps}\n\nNow, let us assume that the function \\texttt{l\\_std} is primitive recursive.\n\n\n\\emph{From \\href{../theories/html/hydras.Hydra.Hydra_Theorems.html}{Hydra.Hydra\\_Theorems}}.\n\n\\input{movies/snippets/Hydra_Theorems/battleLengthNotPRa}\n\nLet us consider the hydra represented by the ordinal $\\omega^\\omega$.\n\n\\input{movies/snippets/Hydra_Theorems/battleLengthNotPRb}\n\n\nIn order to get rid of the subtraction in the definition of \\texttt{l\\_std}, we work with a helper function.\n\n\\input{movies/snippets/Hydra_Theorems/battleLengthNotPRc}\n\nUnder the hypothesis \\texttt{H}, $m$ is also primitive recursive.\n\n\\input{movies/snippets/Hydra_Theorems/battleLengthNotPRd}\n\n\n\\subsubsection{Comparison between $F$ and $H'$}\n\nIn \\href{../theories/html/hydras.Epsilon0.F_alpha.html}{Epsilon0.F\\_alpha}, we prove a relation between the $F$ and $H'$ functionals. For any $\\alpha$ and $k>0$,\n$H'_{\\omega^\\alpha}(k)\\geq F_\\alpha(k)$.\n\n\\input{movies/snippets/F_alpha/HprimeF}\n\n\nOur proof of this lemma is not trivial at all, it uses some properties of the Ketonen-Solovay's toolkit. We advise the reader to explore this proof, with the help of an IDE or software like Alectryon.\n%%\n%%% To move the path chapter\n%%%%\n\n% \\begin{Coqsrc}\n%   alpha : E0\n%   IHalpha : forall beta : E0, beta o< alpha -> P beta\n%   Halpha : Limitb alpha\n%   n : nat\n%   ============================\n%   H'_ (Phi0 (CanonS alpha n)) (S n) <= \n%   H'_ (Phi0 (CanonS alpha (S n))) (S n)\n% \\end{Coqsrc}\n\n% In mathematical notation: $H'_{\\omega^{\\canonseq{\\alpha}{n}}}(n+1) \\leq\n% H'_{\\omega^{\\canonseq{\\alpha}{n+1}}}(n+1)$.\n\n% \\vspace{4pt}\n\n% But there exists no lemma saying that, if \n% $\\beta\\leq \\alpha$, then $H'_\\beta(k)\\leq H'_\\alpha(k)$, for any $\\alpha$ and $\\beta$. For instance, \n% $H'_{42}(3)=45> H'_\\omega(3)=7$.\n\n\n% Looking for lemmas of the form $H'_\\beta(k)\\leq H'_\\alpha(k)$, we find this one (from our library\n% \\href{../theories/html/hydras.Epsilon0.Hprime.html}{Epsilon0.Hprime}):\n\n% \\begin{Coqanswer}\n% H'_restricted_mono_l : \n%     forall (alpha beta : E0) (n : nat), \n%       Canon_plus n alpha beta -> \n%       H'_ beta n <= H'_ alpha n.\n% \\end{Coqanswer}\n\n% Thus, it remains to prove that \n% there exists a path from ${\\omega^{\\canonseq{\\alpha}{n+1}}}$\n% to ${\\omega^{\\canonseq{\\alpha}{n}}}$ composed of \n% $n+1$-steps.\n\n% Fortunately, the Ketonen-Solovay machinery contains three lemmas which help us to build such a path.\n\n\n% \\begin{Coqanswer}\n% KS_thm_2_4_lemma5 :\n%   forall [i : nat] [alpha beta : T1],\n%   const_pathS i alpha beta ->\n%   nf alpha -> alpha <> zero -> \n%   const_pathS i (phi0 alpha) (phi0 beta)\n\n% KS_thm_2_4 :\n%   forall [lambda : T1], nf lambda ->limitb lambda ->\n%   forall i j : nat, i < j -> \n%    const_pathS 0 (canonS lambda j) (canonS lambda i)\n\n% Cor12_1 :\n% forall [alpha : T1], nf alpha ->\n%       forall (beta : T1) (i n : nat),\n%       beta t1< alpha ->\n%      i <= n -> const_pathS i alpha beta -> \n%      const_pathS n alpha beta\n% \\end{Coqanswer}\n  \n\\subsubsection{End of the proof}\n\nWe finish the proof by comparing several fast growing functions.\n\n\\vspace{4pt}\n\n\\emph{From \\href{../theories/html/hydras.Epsilon0.L_alpha.html}{Epsilon0.L\\_alpha}}\n\n\\input{movies/snippets/L_alpha/HprimeL}\n\n\\vspace{4pt}\n\n\\emph{From \\href{../theories/html/hydras.Epsilon0.F_omega.html}{Epsilon0.F\\_omega}}\n\\input{movies/snippets/F_omega/FVsAck}\n\n\\vspace{4pt}\n\nBy transitivity, we get the inequality\n$F_\\omega(k+1)\\leq m(k+1)$, for any $k$.\n\n\\input{movies/snippets/Hydra_Theorems/mGeFOmega}\n\n\nWe finish the proof by noting that the function $m$ (composed with \\texttt{S}) dominates the Ackermann function, which leads to a contradiction.\n\n\\input{movies/snippets/Hydra_Theorems/mDominatesAck}\n\n\\input{movies/snippets/Hydra_Theorems/SmNotPR}\n\n\\vspace{4pt}\n\n\\input{movies/snippets/Hydra_Theorems/LNotPR}\n\n\n\n", "meta": {"hexsha": "e8f1d28cbb4da83f58e222a0be898d37578b9640", "size": 33398, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapter-primrec.tex", "max_stars_repo_name": "coq-community/hydra-battles", "max_stars_repo_head_hexsha": "83fd521c2c7e485bd5be8dc0b786068baedbb9d0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 40, "max_stars_repo_stars_event_min_datetime": "2020-10-20T13:51:22.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T10:22:16.000Z", "max_issues_repo_path": "doc/chapter-primrec.tex", "max_issues_repo_name": "coq-community/hydra-battles", "max_issues_repo_head_hexsha": "83fd521c2c7e485bd5be8dc0b786068baedbb9d0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 78, "max_issues_repo_issues_event_min_datetime": "2020-10-20T16:48:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T17:49:00.000Z", "max_forks_repo_path": "doc/chapter-primrec.tex", "max_forks_repo_name": "coq-community/hydra-battles", "max_forks_repo_head_hexsha": "83fd521c2c7e485bd5be8dc0b786068baedbb9d0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2020-10-20T12:06:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-30T16:10:35.000Z", "avg_line_length": 38.1255707763, "max_line_length": 373, "alphanum_fraction": 0.759596383, "num_tokens": 9602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7694603446965106}}
{"text": "\\section{Deep Unsupervised Learning}\n\\subsection*{Autoencoders}\nlearn low-dim representation $z \\in \\mathbb{R}^d$ for given data. \nLinear autoencoder with weights $C \\in \\mathbb{R}^{dxm}$ (encoder) and $D \\in \\mathbb{R}^{mxd}$ (decoder). objective min $\\frac{1}{2n} \\sum_{i=1}^n \\|x_i-DCx_i \\|^2$. Frobenius norm optimal approx (in this case) via SVD $X^\\top X=U\\Sigma V^\\top$ then $C^*=U_d^\\top$ and $D^*=U_d$ (first $d$ columns of $U$).\n\\subsection*{Variational Autoencoders (VAEs)}\nPut a gaussian prior on distribution of continous latent vector z: $p(z_l) \\sim \\mathcal{N}(\\mu_l, \\Sigma_l)$ for $l \\in \\{1,..L\\}$. This allows to easily generate new data points. \\\\\n\\textbf{log-likelihood}: $\\log p_\\theta(x) = \\log \\int p_\\theta (x|z) p(z) dz \\geq E_q[\\log p_\\theta(x|z)] + E_q[\\log \\frac{p(z)}{q(z)}]$ where $-D_{KL}(q||p) = E_q[\\log \\frac{p(z)}{q(z)}]$. KL-divergence tells how much two distributions diverge. Optimal $q(z)=p(z|x)$. \\\\\n\\textbf{NN approach}: \n\\begin{inparaenum}[\\color{red} 1.]\n\\item recognition/inference model: learns variational distribution $q(z)$ i.e given $x$ it returns params of normal distribution $(\\mu_l,\\Sigma_l)$ for $l=1,..,L$ from which we than can sample the $z_l$'s. \n\\item generative model: implements $p_\\theta(x|z)$ and deterministically maps $z$ to $x$ (reconstruction). \n\\end{inparaenum}\n\\subsection*{Autoregressive Models}\ngenerate output one variable at a time based on chain rule $p(x_{1:m}) = \\Pi_{i=1}^m p(x_t|x_{1:t-1})$. \\\\\n\\textbf{PixelCNN}: $nxn$ image with pixels $x_1,..,x_{n^2}$. Generate pixel $x_i$ by conditioning on previously generated pixels $x_1,..,x_{i-1}$. Use a masking filter for implem. \\\\\n\\textbf{RNN}:observed sequence $x_1,..,x_T$ and corresponding labels $y_1,..,y_T$. Use feedbackloop $h_t=f(h_{t-1},x_t)$ with hidden state $h_t$. LSTM units to avoid vanishing gradient problem. \\\\\n\\textbf{PixelRNN}: use RNN for mapping $x_1,..x_{i-1}$ to $x_i$. Row LSTM: convolute along each row from top to bottom (triangular receptive field i.e loss of context). Diagonal BiLSTM: convolute along the diagonal (receptive field includes all previously generated pixels).\n", "meta": {"hexsha": "6cd7bafcc769f1a7a0a1b191769557434ae3a1eb", "size": 2130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DeepUL.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": "DeepUL.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": "DeepUL.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": 118.3333333333, "max_line_length": 307, "alphanum_fraction": 0.7018779343, "num_tokens": 726, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.918480252950991, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7693373939376311}}
{"text": "\\section{Mean Value Analysis}\n\\label{sec:Mean-Value-Analysis}\n\nThe Mean Value Analysis (MVA) is an alternative method to analyze Closed Jackson Networks.\nIt is efficient and intuitive, but it only provides mean metrics.\n\nGiven a Closed Jackson Network with $M$ jobs, we denote with $\\expected{N_{j}^{(M)}}$ the mean number of jobs at the $j$-th server when there are $M$ jobs in the system.\n\nThe MVA relies on the following theorem.\n\n\\begin{theorem}[Arrival Theorem]\n\\label{thm:Arrival-Theorem}\n\tIn a Closed Jackson Network with $M>1$ jobs, an arrival to server $j$ sees a distribution of the number of jobs at each server equal to the steady-state distribution of the number of jobs at each server in the same network with $M-1$ jobs.\n\\end{theorem}\n\nThe Arrival Theorem is counterpart to PASTA for closed networks of queues.\n\nThanks to the \\Cref{thm:Arrival-Theorem}, the MVA recursively relates $\\expected{N_{j}^{(M)}}$ to $\\expected{N_{j}^{(M-1)}}$, until we arrive to $\\expected{N_{j}^{(1)}}$, which is very easy to reason about.\n\n\\begin{theorem}[MVA-Response Time]\n\\label{thm:MVA-Response-Time}\n\n\t\\begin{equation}\n\t\\label{eqn:MVA-Response-Time}\n\t\\expected{T_{j}^{M}} = \n\t\\frac{1}{\\mu_{j}} + \n\t\\frac{p_{j} \\lambda^{(M-1)} \\expected{T_{j}^{(M-1)}}}{\\mu_{j}}\n\t\\end{equation}\n\t\n\twhere $p_{j}$ is the fraction of arrivals that arrive to server $j$, namely\n\t\n\t\\begin{equation}\n\t\\label{eqn:MVA-Response-Time-Fraction-Arrivals}\n\tp_{j} = \\frac{\\lambda_{j}^{M}}{\\lambda^{M}} = \\frac{V_{j}}{\\sum_{j=1}^{m} V_{j}}\n\t\\end{equation}\n\t\n\tand $\\lambda^{(M)}$ is the total arrival rate into all the $m$ servers, namely\n\t\n\t\\begin{equation}\n\t\\label{eqn:MVA-Response-Time-Total-Arrival-Rate}\n\t\\lambda^{(M-1)} = \\frac{M-1}{\\sum_{j=1}^{m} p_{j} \\expected{T_{j}^{(M-1)}}}\n\t\\end{equation}\t\n\t\n\t\\begin{proof}\n\t\tFor a formal demonstration, see \\cite{harchol2013performance} at page 337-341.\n\t\\end{proof}\n\\end{theorem}\n\nOnce determined $\\expected{T_{j}^{M}}$, we can obtain other mean metrics by using the Little's Law.\n\nFor instance, $\\expected{N_{i}^{M}} = \\lambda_{i}^{M} \\cdot \\expected{T_{i}^{M}}$", "meta": {"hexsha": "c09f7fa39505489de92f531107df535ee9a80ba7", "size": 2077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/mean-value-analysis.tex", "max_stars_repo_name": "gmarciani/research", "max_stars_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2017-07-27T13:31:43.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-20T12:54:12.000Z", "max_issues_repo_path": "performance-modeling/sec/mean-value-analysis.tex", "max_issues_repo_name": "gmarciani/research", "max_issues_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "performance-modeling/sec/mean-value-analysis.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 40.7254901961, "max_line_length": 240, "alphanum_fraction": 0.6976408281, "num_tokens": 682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252811, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7693373901843344}}
{"text": "\\subsection{Fleiss' Kappa}\n\\label{chp:fundamentals:sec:inter_rater_agreement:subsec:fleiss_kappa}\nCohen's kappa and Scott's $\\pi$ focus only on the agreement between two raters.\nTo overcome this limitation \\textcite{Fleiss:1971} introduced another kappa statistics as a generalization of Scott's $\\pi$ \\parencite{Scott:1955}.\nConsider $N$ datapoints, each assigned $n$ times to one of $C$ classes by different raters.\nHow many raters have assigned the $i$th datapoint to the $j$th class is indicated by $n_{ij}$.\n$p_j$ is the proportion of all assignments which were made to the $j$th class and is calculated as:\n\n\\begin{equation}\\label{eq:fleiss_pj}\n    p_j = \\frac{1}{Nn}\\sum_{i=1}^N n_{ij}\n\\end{equation}\n\nThe agreement of $n$ raters on the $i$th datapoint, indicated by $P_i$, is the proportion of agreeing rater pairs out of the $n(n-1)$ possible pairs and given by the following:\n\n\\begin{equation}\\label{eq:fleiss_Pi}\n    \\begin{aligned}\n        P_i &= \\frac{1}{n(n-1)} \\sum_{j=1}^C n_{ij} (n_{ij}-1) \\\\\n        &= \\frac{1}{n(n-1)} \\left[\\left(\\sum_{j=1}^C n_{ij}^2 \\right) - n\\right]\\\\\n    \\end{aligned}\n\\end{equation}\n\nThe mean of all $P_i$s then forms the overall agreement.\n\n\\begin{equation}\\label{eq:fleiss_P_bar}\n    \\bar{P} = \\frac{1}{N} \\sum_{i=1}^N P_i\n\\end{equation}\n\nThe agreement achieved merely by chance $\\bar{P_e}$ is similar to \\textcite{Scott:1955} indicated by\n\n\\begin{equation}\\label{eq:fleiss_P_e}\n    \\bar{P_e} = \\sum_{j=1}^C p_j^2\n\\end{equation}\n\nAccording to \\textcite{Fleiss:1971}, the term $1-\\bar{P_e}$ measures the agreement which can be achieved in extent to the agreement which is obtained by chance.\nThe actual agreement including the agreement by chance is represented by $\\bar{P} - \\bar{P_e}$.\nThen the normalized kappa statistics is similar to \\textcite{Cohen:1960} given by:\n\n\\begin{equation}\\label{eq:fleiss_kappa}\n    \\kappa_{fleiss} = \\frac{\\bar{P}-\\bar{P_e}}{1-\\bar{P_e}}\n\\end{equation}\n\nWhen applying Fleiss' kappa to the sample data of \\cref{tab:cohens_kappa_sample_data} one can easily see that all $P_i$s are either $1$ when the raters agree or $0$ if one rater votes for \"Good\" and one for \"Bad\".\nConsidering this, \\cref{eq:fleiss_P_bar} simplifies to $\\bar{P} = \\frac{20+15}{50} = 0.7$.\nSince the expected agreement purely achieved by chance is calculated in the same way as for Scott's $\\pi$, one immediately notices that for this test data the two metrics are equal $\\kappa_{fleiss} = \\pi = 0.\\overline{39}$ like one would expect.\n", "meta": {"hexsha": "8bf02ed00bc4f0d50150abdd186bb22934e465fb", "size": 2483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/inter_rater_agreement/subsections/fleiss_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/fleiss_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/fleiss_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": 55.1777777778, "max_line_length": 245, "alphanum_fraction": 0.7237213049, "num_tokens": 803, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605945, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7692883627377323}}
{"text": "\\section*{Calculations}\n\\label{sec:calc}\n% CHANGE GB TO 1073741824 BYTES!!!\n\n\\subsection{Storage}\n\nStorage requirements for 24 hours of 720p video data (.mp4):\n\\begin{equation*}\n\\begin{split}\nContinual & = \\left(\\frac{24 \\ hr}{1 \\ day}\\right)\\left(\\frac{60 \\ min}{1 \\ hr}\\right)\\left(\\frac{60 \\ sec}{ 1 \\ min}\\right)\\left(\\frac{17 \\ mbit}{1 \\ sec}\\right)\\left(\\frac{1 \\ byte}{8 \\ bit}\\right)\\left(\\frac{1 \\ GB}{1737441824 \\ byte}\\right) \\\\\n& = 170.99 \\ \\frac{GB}{day}\n\\end{split}\n\\end{equation*}\n\nBy limiting the active recording to moments where objects are detected, this storage requirement can be significantly lowered. Taking a theoretical family of 4 and a single dog, we can calculate for a minimum duration that the RPi2 is expected to record in 24 hours: \n\n\\begin{table}[H]\n\\centering\n\\caption{Known \\glspl{sighting} during an average 24 hour day for a front door camera.}\n\\label{floor_table}\n\\begin{tabular}{@{}lcccc@{}}\n\\toprule\nType     & Qty & Duration (min) & Sighting/24 hr & Total  \\\\ \\midrule\nPerson   & 4   & 1              & 2               & 8      \\\\\nDog      & 1   & 1              & 2               & 2      \\\\\nDelivery & 2   & 1              & 1               & 2      \\\\ \\midrule\n         &     &                &                 & 12 min\n\\end{tabular}\n\\end{table}\n\nWith a minimum recording duration of 12 minutes based on the expected sightings (detected objects), the floor data requirements per 24 hours becomes:\n\n\\begin{equation*}\n\\begin{split}\nFloor \\ & = \\left(\\frac{12 \\ min}{1 \\ day}\\right)\\left(\\frac{60 \\ sec}{ 1 \\ min}\\right)\\left(\\frac{17 \\ Mbit}{1 \\ sec}\\right)\\left(\\frac{1 \\ byte}{8 \\ bit}\\right)\\left(\\frac{1 \\ GB}{1737441824 \\ byte}\\right) \\\\\n& = 0.000014254 \\ \\frac{GB}{day}\\Rightarrow 0.014254 \\ \\frac{MB}{day} \\Rightarrow 14.254 \\ \\frac{KB}{day}\n\\end{split}\n\\end{equation*}\n\n\\subsection{Analog Light Sensor}\n\n\\begin{equation*}\n\\begin{split}\n    \\log\\left(I_{O}\\right) &= mx + b \\\\\n    I_{O} &= m\\log\\left(x\\right) + b \\\\\n    I_{O} &= 10\\log\\left(E_{v}\\right)\\left[l_{x}\\right]\n\\end{split}\n\\end{equation*}\n\nThe sensor has an output current range of $0\\mu A$--$50\\mu A$ between $1$ lux--$100000$ lux. The breakout board converts this current into a voltage using a $68K\\Omega$ resistor, giving a voltage output of $0V$--$3.4V$. Given the use-case of the light sensor, the $3.4V$ can be approximated to $3.3V$, which is a suitable voltage reference for the RPi2. With the output current range approximated to a voltage range of $0V$--$3.3V$ between $1$ lux--$100000$ lux,\n\n\\begin{equation*}\n\\begin{split}\n    log_{i} &= \\log\\left(l_{x \\ MAX} - l_{x \\ MIN}\\right) \\\\\n    &= \\log\\left(100000\\right) = 5 \\\\\n\\end{split}\n\\end{equation*}\n\nTo convert the analog value to a digital value, an 8-bit ADC is used:\n\\begin{equation*}\n    ADC = \\frac{log_{i}}{1024 \\ steps} = 0.00488\n\\end{equation*}\n\nFinally, the formula to obtain the final lux output, $l_{xo}$, on the RPi2:\n\n\\begin{equation*}\n%\\begin{split}\n    l_{xo} = 10^{raw_{i} \\times ADC} = 10^{raw_{i} \\times 0.00488}\n%\\end{split}\n\\end{equation*}\n\nwhere $raw_{i}$ is the raw value received by the ADC connected to the RPI2's GPIO.\n\n%\\newpage\n\n%\\begin{multicols}{2}\n%\\begin{onehalfspacing}\n%\\printglossary\n%\\end{onehalfspacing}\n%\\end{multicols}", "meta": {"hexsha": "880df659274f6d76a85c0c478f2cc0ff564ea90c", "size": 3231, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documentation/latex_proposal/calculations.tex", "max_stars_repo_name": "wodiesan/senior_design_spring", "max_stars_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2016-03-26T03:46:09.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-30T17:29:43.000Z", "max_issues_repo_path": "documentation/latex_proposal/calculations.tex", "max_issues_repo_name": "wodiesan/senior_design_spring", "max_issues_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "documentation/latex_proposal/calculations.tex", "max_forks_repo_name": "wodiesan/senior_design_spring", "max_forks_repo_head_hexsha": "a335d8e052fc71250d127ca24755e0e1dad81d30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3875, "max_line_length": 462, "alphanum_fraction": 0.6431445373, "num_tokens": 1074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7692883532072781}}
{"text": "\\section{Hyperbolic Functions}{}{}\\label{sec:hyperbolic functions}\r\n\r\nThe \\textbf{hyperbolic functions} are a set of functions that have many applications to mathematics, physics, and engineering. Among many other applications, they are used to describe the formation of satellite rings around planets, to describe the shape of a rope hanging from two points, and have application to the theory of special relativity. This section defines the hyperbolic functions and describes many of their properties, especially their usefulness to calculus.\r\n\r\nThese functions are sometimes referred to as the ``hyperbolic trigonometric functions'' as there are many, many connections between them and the standard trigonometric functions. Figure \\ref{fig:geometric def trigh} demonstrates one such connection. Just as cosine and sine are used to define points on the circle defined by $x^2+y^2=1$, the functions \\textbf{hyperbolic cosine} and \\textbf{hyperbolic sine} are used to define points on the hyperbola $x^2-y^2=1$. This is a bit surprising given our initial definitions.\r\n\r\n\\begin{definition}{Hyperbolic Functions}{Hyperbolic Sine and Cosine}\r\n\\label{def:hyperbolic_functions}\r\n%The \\dfont{hyperbolic cosine} is the function\r\n%$$\\cosh x ={e^x +e^{-x }\\over2},$$\r\n%and the \\dfont{hyperbolic sine} is the function\r\n%$$\\sinh x ={e^x -e^{-x}\\over 2}.$$\r\n\\begin{minipage}{.5\\textwidth}\r\n\\begin{enumerate}\r\n\\item\t\t$\\ds \\cosh x = \\frac{e^x+e^{-x}}2$\\index{hyperbolic function!definition}\r\n\\item\t\t$\\ds \\sinh x = \\frac{e^x-e^{-x}}2$\r\n\\item\t\t$\\ds \\tanh x = \\frac{\\sinh x}{\\cosh x}$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\begin{minipage}{.5\\textwidth}\r\n\\begin{enumerate}\\addtocounter{enumi}{3}\r\n\\item\t\t$\\ds \\sech x = \\frac{1}{\\cosh x}$\r\n\\item\t\t$\\ds \\csch x = \\frac{1}{\\sinh x}$\r\n\\item\t\t$\\ds \\coth x = \\frac{\\cosh x}{\\sinh x}$\r\n\\end{enumerate}\r\n\\end{minipage}\r\n\\end{definition}\r\n\r\nThese hyperbolic functions are graphed in Figure \\ref{fig:hyperbolic}. In the graphs of $\\cosh x$ and $\\sinh x$, graphs of $e^x/2$ and $e^{-x}/2$ are included with dashed lines. As $x$ gets ``large,'' $\\cosh x$ and $\\sinh x$ each act like $e^x/2$; when $x$ is a large negative number, $\\cosh x$ acts like $e^{-x}/2$ whereas $\\sinh x$ acts like $-e^{-x}/2$.\r\n\r\nNotice the domains of $\\tanh x$ and $\\sech x$ are $(-\\infty,\\infty)$, whereas both $\\coth x$ and $\\csch x$ have vertical asymptotes at $x=0$. Also note the ranges of these functions, especially $\\tanh x$: as $x\\to\\infty$, both $\\sinh x$ and $\\cosh x$ approach $e^{-x}/2$, hence $\\tanh x$ approaches $1$.\r\n\r\n%It is no coincidence that these functions share a name similar to the trigonometric functions. \r\nThe following example explores some of the properties of these functions that bear remarkable resemblance to the properties of their trigonometric counterparts.\\\\\r\n\r\n{\\textbf{Pronunciation Note:} \\par \r\n``cosh'' rhymes with ``gosh,'' \\par ``sinh'' rhymes with ``pinch,'' or alternatively is pronounced``shine\" and \\par ``tanh'' rhymes with ``ranch.'', or alternatively is pronounced``tank\"}\r\n\r\nNotice that $\\cosh$ is even (that is, $\\cosh(-x)=\\cosh(x)$)\r\nwhile $\\sinh$ is odd ($\\sinh(-x)=-\\sinh(x)$), and\r\n$\\ds\\cosh x + \\sinh x = e^x$. Also, for all $x$,\r\n$\\cosh x >0$, while $\\sinh x=0$ if and only if $\\ds e^x -e^{-x }=0$,\r\nwhich is true precisely when $x=0$.\r\n\r\n\\begin{theorem}{Range of Hyperbolic Cosine}{Range of Hyperbolic Cosine}\r\nThe range of $\\cosh x$ is $[1,\\infty)$.\r\n\\end{theorem}\r\n\r\n\\begin{proof}\r\nLet $y= \\cosh x$. We solve for $x$:\r\n\\begin{eqnarray*}\r\ny&=&{e^x +e^{-x }\\over 2}\\cr\r\n2y &=& e^x + e^{-x }\\cr\r\n2ye^x &=& e^{2x} + 1\\cr\r\n 0 &=& e^{2x}-2ye^x +1\\cr\r\n e^{x} &=& {2y \\pm \\sqrt{4y^2 -4}\\over 2}\\cr\r\n e^{x} &=& y\\pm \\sqrt{y^2 -1}\r\n\\end{eqnarray*}\r\nFrom the last equation, we see $\\ds y^2 \\geq 1$, and since\r\n$y\\geq 0$, it follows that $y\\geq 1$.\r\n\r\nNow suppose $y\\geq 1$, so $\\ds y\\pm \\sqrt{y^2 -1}>0$. Then\r\n$\\ds x = \\ln(y\\pm \\sqrt{y^2 -1})$ is a real number, and \r\n$y =\\cosh x$, so $y$ is in the range of $\\cosh(x)$.\r\n\\end{proof}\r\n\r\n%\\begin{definition}{Hyperbolic Functions}{Hyperbolic Functions}\r\n%We can also define hyperbolic functions for the other trigonometric functions as you would expect:\r\n%$$\\tanh x=\\frac{\\sinh x}{\\cosh x}\\qquad \\csch x=\\frac{1}{\\sinh x}\\qquad \\sech x=\\frac{1}{\\cosh x}\\qquad \\coth x=\\frac{1}{\\tanh x}$$\r\n%\\end{definition}\r\n\r\nThe graphs can be generated based on our knowledge of the exponential function.  \r\n\r\n%The graph of $\\sinh x$ is shown below:\r\n%$$\\includegraphics[width=2.5in]{images2/sinh}$$\r\n%The graph of $\\cosh x$ is shown below:\r\n%$$\\includegraphics[width=2.5in]{images2/cosh}$$\r\n\r\n\\begin{figure}\r\n\\begin{subfigure}{.5\\textwidth}\r\n  \\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},\r\n    xmin=-2.5, xmax=2.5,\r\n    ymin=-2.5, ymax=2.5,\r\n    axis lines=center,\r\n    axis on top=true,\r\n    domain=-2.5:2.5,\r\n    ylabel=$y$,\r\n    xlabel=$x$,\r\n    ]\r\n\r\n    \\addplot [mark=none,draw=red,ultra thick] {sinh(\\x)};\r\n    \\addplot [mark=none,draw=blue,dashed, thick] {(1/2)*exp(\\x)};\r\n    \\addplot [mark=none,draw=blue, dashed,thick] {(-1/2)*exp(-\\x)};\r\n    \\node [right, red] at (axis cs: 1,0.7) {\\scriptsize $y = \\sinh x$};\r\n    \\node [right, blue] at (axis cs: -2,0.7) {\\scriptsize $\\ds y = \\frac{e^x}{2}$};\r\n    \\node [right, blue] at (axis cs: 0.5,-0.7) {\\scriptsize $\\ds y = -\\frac{e^{-x}}{2}$};\r\n\r\n    %% Add the asymptotes\r\n   %\\draw [blue, dotted, thick] (axis cs:-2.5,-1)-- (axis cs:0,-1);\r\n  %  \\draw [blue, dotted, thick] (axis cs:+2.5,+1)-- (axis cs:0,+1);\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{subfigure}\r\n\\begin{subfigure}{.5\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[tick label style={font=\\scriptsize},\r\n    xmin=-3, xmax=3,\r\n    ymin=-0.5, ymax=4.5,\r\n    axis lines=center,\r\n    axis on top=true,\r\n    domain=-2.5:2.5,\r\n    ylabel=$y$,\r\n    xlabel=$x$,\r\n    ]\r\n\r\n    \\addplot [mark=none,draw=red,ultra thick] {cosh(\\x)};\r\n    \\addplot [mark=none,draw=blue,dashed, thick] {(1/2)*exp(\\x)};\r\n    \\addplot [mark=none,draw=blue,dashed, thick] {(1/2)*exp(-\\x)};\r\n    \\node [right, red] at (axis cs: 0.1,3.5) {\\scriptsize $y = \\cosh x$};\r\n    \\node [right, blue] at (axis cs: 1.5,1.3) {\\scriptsize $\\ds y = \\frac{e^x}{2}$};\r\n    \\node [right, blue] at (axis cs: -3,1.3) {\\scriptsize $\\ds y = \\frac{e^{-x}}{2}$};\r\n\r\n    %% Add the asymptotes\r\n    %\\draw [blue, dotted, thick] (axis cs:-2.5,-1)-- (axis cs:0,-1);\r\n    %\\draw [blue, dotted, thick] (axis cs:+2.5,+1)-- (axis cs:0,+1);\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\\end{subfigure}\r\n\\begin{subfigure}{.5\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick={-2,2},\r\n%\t\t\tyticklabels={$-0.002$,$0.002$,$0.004$},\r\n\t\t\t%minor y tick num=1,\r\n%\t\t\textra y ticks={0.001},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-3.5,ymax=3.5,%\r\n\t\t\txmin=-3.5,xmax=3.5,%\r\n\t\t\tscaled ticks=false\r\n]\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(-3.,-0.995)(-2.9,-0.994)(-2.8,-0.993)(-2.7,-0.991)(-2.6,-0.989)(-2.5,-0.987)(-2.4,-0.984)(-2.3,-0.98)(-2.2,-0.976)(-2.1,-0.97)(-2.,-0.964)(-1.9,-0.956)(-1.8,-0.947)(-1.7,-0.935)(-1.6,-0.922)(-1.5,-0.905)(-1.4,-0.885)(-1.3,-0.862)(-1.2,-0.834)(-1.1,-0.8)(-1.,-0.762)(-0.9,-0.716)(-0.8,-0.664)(-0.7,-0.604)(-0.6,-0.537)(-0.5,-0.462)(-0.4,-0.38)(-0.3,-0.291)(-0.2,-0.197)(-0.1,-0.0997)(0,0)(0.1,0.0997)(0.2,0.197)(0.3,0.291)(0.4,0.38)(0.5,0.462)(0.6,0.537)(0.7,0.604)(0.8,0.664)(0.9,0.716)(1.,0.762)(1.1,0.8)(1.2,0.834)(1.3,0.862)(1.4,0.885)(1.5,0.905)(1.6,0.922)(1.7,0.935)(1.8,0.947)(1.9,0.956)(2.,0.964)(2.1,0.97)(2.2,0.976)(2.3,0.98)(2.4,0.984)(2.5,0.987)(2.6,0.989)(2.7,0.991)(2.8,0.993)(2.9,0.994)(3.,0.995)};\r\n\r\n\\draw (axis cs:1.7,-1.5) node {\\scriptsize $f(x)=\\tanh x$};\r\n\\draw (axis cs:2.2,2) node {\\scriptsize $f(x)=\\coth x$};\r\n\\draw [->,>=stealth] (axis cs:1,-1) -- (axis cs:.6,.45);\r\n\r\n\r\n\\addplot [{\\colortwo},smooth,thick] coordinates {(-3.,-1.)(-2.9,-1.01)(-2.8,-1.01)(-2.7,-1.01)(-2.6,-1.01)(-2.5,-1.01)(-2.4,-1.02)(-2.3,-1.02)(-2.2,-1.02)(-2.1,-1.03)(-2.,-1.04)(-1.9,-1.05)(-1.8,-1.06)(-1.7,-1.07)(-1.6,-1.08)(-1.5,-1.1)(-1.4,-1.13)(-1.3,-1.16)(-1.2,-1.2)(-1.1,-1.25)(-1.,-1.31)(-0.9,-1.4)(-0.8,-1.51)(-0.7,-1.65)(-0.6,-1.86)(-0.5,-2.16)(-0.4,-2.63)(-0.3,-3.43)(-0.2,-5.07)(-0.1,-10.)};\r\n\r\n\\addplot [{\\colortwo},smooth,thick] coordinates {(0.1,10.)(0.2,5.07)(0.3,3.43)(0.4,2.63)(0.5,2.16)(0.6,1.86)(0.7,1.65)(0.8,1.51)(0.9,1.4)(1.,1.31)(1.1,1.25)(1.2,1.2)(1.3,1.16)(1.4,1.13)(1.5,1.1)(1.6,1.08)(1.7,1.07)(1.8,1.06)(1.9,1.05)(2.,1.04)(2.1,1.03)(2.2,1.02)(2.3,1.02)(2.4,1.02)(2.5,1.01)(2.6,1.01)(2.7,1.01)(2.8,1.01)(2.9,1.01)(3.,1.)};\r\n%\\draw (axis cs:2.4,-0.002) node {\\scriptsize $f(x)$};\r\n\\draw [loosely dashed] (axis cs:-3,1) -- (axis cs:3,1);\r\n\\draw [loosely dashed] (axis cs:-3,-1) -- (axis cs:3,-1);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{subfigure}\r\n\\begin{subfigure}{.5\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\textwidth,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick={-3,-2,-1,1,2,3},\r\n%\t\t\tyticklabels={$-0.002$,$0.002$,$0.004$},\r\n\t\t\t%minor y tick num=1,\r\n%\t\t\textra y ticks={0.001},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-3.5,ymax=3.5,%\r\n\t\t\txmin=-3.5,xmax=3.5,%\r\n\t\t\tscaled ticks=false\r\n]\r\n\r\n\\addplot [{\\colorone},thick,smooth] coordinates {(-3.,0.0993)(-2.9,0.11)(-2.8,0.121)(-2.7,0.134)(-2.6,0.148)(-2.5,0.163)(-2.4,0.18)(-2.3,0.199)(-2.2,0.219)(-2.1,0.241)(-2.,0.266)(-1.9,0.293)(-1.8,0.322)(-1.7,0.354)(-1.6,0.388)(-1.5,0.425)(-1.4,0.465)(-1.3,0.507)(-1.2,0.552)(-1.1,0.599)(-1.,0.648)(-0.9,0.698)(-0.8,0.748)(-0.7,0.797)(-0.6,0.844)(-0.5,0.887)(-0.4,0.925)(-0.3,0.957)(-0.2,0.98)(-0.1,0.995)(0,1.)(0.1,0.995)(0.2,0.98)(0.3,0.957)(0.4,0.925)(0.5,0.887)(0.6,0.844)(0.7,0.797)(0.8,0.748)(0.9,0.698)(1.,0.648)(1.1,0.599)(1.2,0.552)(1.3,0.507)(1.4,0.465)(1.5,0.425)(1.6,0.388)(1.7,0.354)(1.8,0.322)(1.9,0.293)(2.,0.266)(2.1,0.241)(2.2,0.219)(2.3,0.199)(2.4,0.18)(2.5,0.163)(2.6,0.148)(2.7,0.134)(2.8,0.121)(2.9,0.11)(3.,0.0993)};\r\n\r\n\\draw (axis cs:-2,1.5) node {\\scriptsize $f(x)=\\sech x$};\r\n\\draw (axis cs:2.2,2) node {\\scriptsize $f(x)=\\csch x$};\r\n%\\draw [->,>=latex] (axis cs:1,-1) -- (axis cs:.6,.45);\r\n\r\n\r\n\\addplot [{\\colortwo},smooth,thick] coordinates {(-3.,-0.0998)(-2.9,-0.11)(-2.8,-0.122)(-2.7,-0.135)(-2.6,-0.149)(-2.5,-0.165)(-2.4,-0.183)(-2.3,-0.203)(-2.2,-0.224)(-2.1,-0.249)(-2.,-0.276)(-1.9,-0.306)(-1.8,-0.34)(-1.7,-0.378)(-1.6,-0.421)(-1.5,-0.47)(-1.4,-0.525)(-1.3,-0.589)(-1.2,-0.662)(-1.1,-0.749)(-1.,-0.851)(-0.9,-0.974)(-0.8,-1.13)(-0.7,-1.32)(-0.6,-1.57)(-0.5,-1.92)(-0.4,-2.43)(-0.3,-3.28)(-0.2,-4.97)(-0.1,-9.98)};\r\n\r\n\\addplot [{\\colortwo},smooth,thick] coordinates {(0.1,9.98)(0.2,4.97)(0.3,3.28)(0.4,2.43)(0.5,1.92)(0.6,1.57)(0.7,1.32)(0.8,1.13)(0.9,0.974)(1.,0.851)(1.1,0.749)(1.2,0.662)(1.3,0.589)(1.4,0.525)(1.5,0.47)(1.6,0.421)(1.7,0.378)(1.8,0.34)(1.9,0.306)(2.,0.276)(2.1,0.249)(2.2,0.224)(2.3,0.203)(2.4,0.183)(2.5,0.165)(2.6,0.149)(2.7,0.135)(2.8,0.122)(2.9,0.11)(3.,0.0998)};\r\n%\\draw (axis cs:2.4,-0.002) node {\\scriptsize $f(x)$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{subfigure} \r\n\\caption{Graphs of the Hyperbolic Functions\\label{fig:hyperbolic}}\r\n\\end{figure}\r\n\r\n\r\n\r\n\r\n\r\nCertainly the hyperbolic functions do not closely resemble the\r\ntrigonometric functions graphically. But they do have analogous\r\nproperties, beginning with the following identity.\r\n\r\n\\begin{theorem}{Hyperbolic Identity}{Hyperbolic Identity}\r\n\\label{hyp identity}\r\nFor all $x$ in $\\R$, $\\ds \\cosh ^2 x -\\sinh ^2 x = 1$.\r\n\\end{theorem}\r\n\r\n\r\n\\begin{proof}\r\nThe proof is a straightforward computation:\r\n$$\\cosh ^2 x -\\sinh ^2 x =\r\n {(e^x +e^{-x} )^2\\over 4} -{(e^x -e^{-x} )^2\\over 4}=\r\n {e^{2x} + 2 + e^{-2x } - e^{2x } + 2 - e^{-2x}\\over 4}=\r\n {4\\over 4} = 1.\r\n$$\r\n\\end{proof}\r\n\r\nThis immediately gives two additional identities:\r\n$$1-\\tanh^2 x =\\sech^2 x\\qquad\\hbox{and}\\qquad\r\n\\coth^2 x - 1  =\\csch^2 x.$$\r\n\r\nThe identity of the theorem also helps to provide a geometric\r\nmotivation. Recall that the graph of $\\ds x^2 -y^2 =1$ is a hyperbola\r\nwith asymptotes $x=\\pm y$ whose $x$-intercepts are $\\pm 1$. If\r\n$(x,y)$ is a point on the right half of the hyperbola, and if\r\nwe let $x=\\cosh \\theta$, then\r\n$\\ds y=\\pm\\sqrt{x^2-1}=\\pm\\sqrt{\\cosh^2x-1}=\\pm\\sinh \\theta$. So for some\r\nsuitable $\\theta$, $\\cosh \\theta$ and $\\sinh \\theta$ are the coordinates of a typical\r\npoint on the hyperbola. In fact, it turns out that $\\theta$ is twice the\r\narea shown in the first graph of  figure~\\ref{fig:geometric def trigh}.  Even\r\nthis is analogous to trigonometry; $\\cos \\theta$ and $\\sin \\theta$ are the\r\ncoordinates of a typical point on the unit circle, and $\\theta$ is twice\r\nthe area shown in the second graph of Figure~\\ref{fig:geometric def\r\ntrigh}. \r\n\r\n\r\n\\mtable{.7}{Using trigonometric functions to define points on a circle and hyperbolic functions to define points on a hyperbola. The area of the shaded regions are included in them. \\label{fig:geometric def trigh}}{fig:hfcircle}{\\begin{tikzpicture}\r\n\\begin{axis}[width=.45\\textwidth,%\r\naxis equal,\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={-1,1},% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\tytick={-1,1},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-1.1,ymax=1.1,%\r\n\t\t\txmin=-1.1,xmax=1.1%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill},domain=0:45] ({cos(x)},{sin(x)}) -- (axis cs:0,0)--cycle;\r\n\r\n\\addplot [{\\colorone},domain=0:360,thick,smooth,samples=100] ({cos(x)},{sin(x)});\r\n\r\n\\filldraw (axis cs:.707,.707) circle (2pt) node [shift={(13pt,8pt)}] {\\scriptsize ($\\cos \\theta$,$\\sin \\theta$)};\r\n\r\n\\draw (axis cs:.6,.25) node {\\scriptsize $\\ds\\frac{\\theta}{2}$};\r\n\\draw (axis cs:-.75,1) node {\\scriptsize $x^2+y^2=1$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\\hspace*{25pt}\\begin{tikzpicture}\r\n\\begin{axis}[width=.45\\textwidth,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={.25,.5,.75,1},% \r\n%\t\t\textra x ticks={.5,3},\r\n%\t\t\textra x tick labels={$a$,$b$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-3.1,ymax=3.1,%\r\n\t\t\txmin=-3.1,xmax=3.1%\r\n]\r\n\r\n\\addplot [{\\coloronefill},fill={\\coloronefill},domain=0:1.6] ({cosh(x)},{sinh(x)}) -- (axis cs:0,0)--cycle;\r\n\r\n\\addplot [{\\colorone},domain=-2:2,thick,smooth] ({cosh(x)},{sinh(x)});\r\n\\addplot [{\\colorone},domain=-2:2,thick,smooth] ({-cosh(x)},{sinh(x)});\r\n\r\n\\filldraw (axis cs:2.577,2.376) circle (2pt) node [left] {\\scriptsize ($\\cosh \\theta$,$\\sinh \\theta$)};\r\n\r\n\\draw (axis cs:.73,.32) node {\\scriptsize $\\frac{\\theta}{2}$};\r\n\\draw (axis cs:-1.75,2.75) node {\\scriptsize $x^2-y^2=1$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\r\n\r\n\r\n%\\begin{figure}[!ht]\r\n%$$\\includegraphics[width=5in]{images2/sinh-and-cosh-motivation}$$\r\n%\\caption{\\label{fig:geometric def trigh}\r\n%Geometric definitions. Here, $t$ is twice the shaded area in each figure.}\r\n%\\end{figure}\r\n\r\n\\begin{example}{Computing Hyperbolic Tangent}{Computing Hyperbolic Tangent}\r\n Use the definition of the hyperbolic functions to rewrite the following expressions.\r\n\\begin{enumerate}\r\n%\\item\t\t$\\cosh^2 x-\\sinh^2x$\r\n\\item\t\t$\\tanh^2 x+\\sech^2 x$\r\n\\item\t\t$2\\cosh x\\sinh x$\r\n\\item\t\t$\\tanh(\\ln 2)$.\r\n\\end{enumerate}\r\n\\end{example} \r\n\r\n\\begin{solution}\r\n\\begin{enumerate}\r\n%\\item\t\t%\\vskip-\\baselineskip%\r\n%\\hfill$\\begin{aligned}[t]\r\n% \\cosh^2x-\\sinh^2x &= \\left(\\frac{e^x+e^{-x}}2\\right)^2 -\\left(\\frac{e^x-e^{-x}}2\\right)^2\\\\\r\n% \t\t\t\t\t\t&= \\frac{e^{2x}+2e^xe^{-x} + e^{-2x}}4 - \\frac{e^{2x}-2e^xe^{-x} + e^{-2x}}4\\\\\r\n% \t\t\t\t\t\t&= \\frac44=1.\r\n%\\end{aligned}$\\hfill\r\n%So $\\cosh^2 x-\\sinh^2x=1$.\r\n\\item $\\begin{aligned}[t]\r\n\\tanh^2 x+\\sech^2 x  =\\frac{\\sinh^2x}{\\cosh^2 x} + \\frac{1}{\\cosh^2 x} \r\n\t\t\t\t\t&= \\frac{\\sinh^2x+1}{\\cosh^2 x}\\qquad \\text{\\small Now use Theorem \\ref{hyp identity}.}\\\\\r\n\t\t\t\t\t&= \\frac{\\cosh^2 x}{\\cosh^2 x} = 1.\\\\\r\n\\end{aligned}$\r\n \r\nSo $\\tanh^2 x+\\sech^2 x=1$.\r\n\\item $\\begin{aligned}[t]\r\n\t2\\cosh x\\sinh x &= 2\\left(\\frac{e^x+e^{-x}}2\\right)\\left(\\frac{e^x-e^{-x}}2\\right) \\\\\r\n\t\t\t\t\t&= 2 \\cdot\\frac{e^{2x} - e^{-2x}}4\\\\\r\n\t\t\t\t\t&= \\frac{e^{2x} - e^{-2x}}2 = \\sinh (2x).\\\\\r\n\t\t\t\\end{aligned}$ \r\n\t\t\t\r\nThus $2\\cosh x\\sinh x = \\sinh (2x)$.\r\n\\item $\\begin{aligned}[t]\r\n\t\\tanh(\\ln 2) & =\\frac{\\sinh(\\ln 2)}{\\cosh(\\ln 2)}\\\\\r\n\t             & = \\frac{\\ds\\frac{e^{\\ln 2}-e^{-\\ln 2}}{2}}{\\ds\\frac{e^{\\ln 2}+e^{-\\ln 2}}{2}}\\\\\r\n\t%= \\frac{\\ds\\frac{e^{\\ln 2}-e^{\\ln(1/2)}}{2}}{\\ds\\frac{e^{\\ln 2}+e^{\\ln(1/2)}}{2}}\r\n\t&=  \\frac{\\ds\\frac{2-(1/2)}{2}}{\\ds\\frac{2+(1/2)}{2}}\r\n\t =\\frac{2-(1/2)}{2+(1/2)}\r\n\t%=  \\frac{3/2}{5/2}\r\n\t= \\frac{3}{5}\\\\\r\n\t\t\t\\end{aligned}$ \r\n\t\t\t\r\nThus $\\tanh(\\ln 2) = \\frac35$.\r\n\\end{enumerate}\r\n\\end{solution}\r\n\r\nThe following summarizes some of the important identities relating to hyperbolic functions. Each can be verified by referring back to Definition \\ref{def:hyperbolic_functions}.\r\n\r\n\\textbf{Basic Identities}\\par\r\n\\begin{enumerate}\r\n\\item $\\cosh^2x-\\sinh^2x=1$%\r\n\\index{hyperbolic function!identities}\\index{hyperbolic function!derivatives}\\index{hyperbolic function!integrals}\\index{derivative!hyperbolic funct.}\\index{integration!hyperbolic funct.}%\r\n\\item\t$\\tanh^2x+\\sech^2x=1$\r\n\\item\t$\\coth^2x-\\csch^2x = 1$\r\n\\item\t$\\cosh 2x=\\cosh^2x+\\sinh^2x$\r\n\\item\t$\\sinh 2x = 2\\sinh x\\cosh x$\r\n\\item\t$\\ds\\cosh^2x = \\frac{\\cosh 2x+1}{2}$\r\n\\item $\\ds \\sinh^2x=\\frac{\\cosh 2x-1}{2}$\r\n\\end{enumerate}\r\n\r\n\r\n\r\n\r\n%\\figure\r\n%\\texonly\r\n%\\hbox to \\hsize{\\hfill\r\n%\\tikzpicture[domain=0:3,x=6mm,y=6mm,baseline=0]\r\n%\\draw (0,0) -- (3,0) ;\r\n%\\draw (0,-3) -- (0,3) ;\r\n%\\foreach \\x in {1,2,3} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {\\eightpoint $\\x$};\r\n%\\foreach \\y in {-3,-2,-1,0,1,2,3} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east]\r\n%{\\eightpoint $\\y$};\r\n%\\node[anchor=west] at (2,1.3) {\\ninepoint $(\\cosh t,\\sinh t)$};\r\n%\\global\\advance\\gpnum by 1\r\n%\\draw[color=black] plot[parametric,id=\\the\\gpnum,domain=-1:1] \r\n%function{1+2*t**2,2*t*sqrt(t**2+1)};\r\n%\\draw (0,0) -- (2,1.732); \r\n%\\gpad\r\n%\\fill[opacity=0.5,fill=red!20] \r\n%(0,0) -- (1,0) \r\n%plot[parametric,id=\\the\\gpnum,domain=0:.707]\r\n%function{1+2*t**2,2*t*sqrt(t**2+1);} -- (0,0);\r\n%\\node at  (2,1.732) {\\fivepoint$\\bullet$};\r\n%\\endtikzpicture\r\n%\\hskip2cm\r\n%\\tikzpicture[domain=-1.2:1.2,baseline=0]\r\n%\\draw (-1.2,0) -- (1.2,0) ;\r\n%\\draw (0,-1.2) -- (0,1.2) ;\r\n%\\foreach \\x in {1} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north west]\r\n         %{\\ninepoint $\\x$};\r\n%\\node[anchor=south west] at (0.5,0.886) {\\ninepoint $(\\cos t,\\sin t)$};\r\n%\\draw[color=black] (0,0) circle (1);\r\n%\\draw (0,0) -- (0.5,0.886); \r\n%\\fill[opacity=0.5,fill=red!20] \r\n%(0,0) -- (1,0) arc (0:60:1) -- (0,0);\r\n%\\node[anchor=mid] at  (0.5,0.886) {\\fivepoint$\\bullet$};\r\n%\\endtikzpicture\\hfill}\r\n%\\endtexonly\r\n%\\figrdef{fig:geometric def trigh}\r\n%\\htmlfigure{Transcendental-GeomDefs.html}\r\n%\\begincaption\r\n%Geometric definitions of sin, cos, sinh, cosh: $t$ is twice the shaded\r\n%area in each figure.\r\n%\\endcaption\r\n%\\endfigure\r\n\r\nSince $\\cosh x > 0$, $\\sinh x$ is increasing and hence one-to-one, so\r\n$\\sinh x$ has an inverse, ${\\rm arcsinh} x$. Also, $\\sinh x > 0$ when\r\n$x>0$, so $\\cosh x$ is injective on $[0,\\infty)$ and has a (partial)\r\ninverse, ${\\rm arccosh} x$. The other hyperbolic functions have inverses\r\nas well, though ${\\rm arcsech} x$ is only a partial inverse. \r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for \\ref{sec:hyperbolic functions}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\r\n\\begin{ex}\r\nVerify the given identity using Definition \\ref{def:hyperbolic_functions}, as done in Example \\ref{exa:Computing Hyperbolic Tangent}.\r\n\\begin{enumerate}\r\n\\item $\\coth^2 x-\\csch^2x=1$.\r\n\\item {$\\cosh 2x = \\cosh^2x+\\sinh^2x$}\r\n\r\n\\item {$\\ds\\cosh^2x = \\frac{\\cosh2x+1}{2}$}\r\n\r\n\\item {$\\ds\\sinh^2x = \\frac{\\cosh2x-1}{2}$}\r\n\r\n\\end{enumerate}\r\n\t\\begin{sol}\r\n\t\t\\begin{enumerate}\r\n\t\t\\item {\\hfill$\\begin{aligned}[t]\r\n\t\t\t\t\\coth^2x-\\csch^2x &= \\left(\\frac{e^x+e^{-x}}{e^x-e^{-x}}\\right)^2 - \\left(\\frac{2}{e^x-e^{-x}}\\right)^2 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{(e^{2x} + 2 + e^{-2x}) - (4)}{e^{2x} - 2 + e^{-2x}}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{e^{2x} - 2 + e^{-2x}}{e^{2x} - 2 + e^{-2x}}\\\\\r\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\r\n\t\t\\end{aligned}$\\hfill\\null}\r\n\t\t\\item {\\hfill$\\begin{aligned}[t]\r\n\t\t\t\t\\cosh^2x+\\sinh^2x &= \\left(\\frac{e^x+e^{-x}}{2}\\right)^2 + \\left(\\frac{e^x-e^{-x}}{2}\\right)^2 \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{e^{2x} + 2 + e^{-2x}}{4} + \\frac{e^{2x} - 2 + e^{-2x}}{4}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{2e^{2x}  + 2e^{-2x}}{4}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{e^{2x} + e^{-2x}}{2} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\cosh 2x.\t\t\t\r\n\t\t\\end{aligned}$\\hfill\\null}\r\n\t\t\\item {\\hfill$\\begin{aligned}[t]\r\n\t\t\t\t\\cosh^2x &= \\left(\\frac{e^x+e^{-x}}{2}\\right)^2  \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{e^{2x} + 2 + e^{-2x}}{4} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac12\\frac{(e^{2x}  + e^{-2x})+2}{2}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac12\\left(\\frac{e^{2x}  + e^{-2x}}{2}+1\\right)\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{\\cosh2x+1}{2}.\t\t\t\r\n\t\t\\end{aligned}$\\hfill\\null}\r\n\t\t\\item {\\hfill$\\begin{aligned}[t]\r\n\t\t\t\t\\sinh^2x &= \\left(\\frac{e^x-e^{-x}}{2}\\right)^2  \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{e^{2x} - 2 + e^{-2x}}{4} \\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac12\\frac{(e^{2x}  + e^{-2x})-2}{2}\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac12\\left(\\frac{e^{2x}  + e^{-2x}}{2}-1\\right)\\\\\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t&= \\frac{\\cosh2x-1}{2}.\t\t\t\r\n\t\t\\end{aligned}$\\hfill\\null}\r\n\t\t\\end{enumerate}\r\n\t\\end{sol}\r\n\\end{ex}\r\n\r\n\\begin{ex} \r\nShow that the range of $\\sinh x$ is all real\r\nnumbers. (Hint: show that if $y=\\sinh x$ then \r\n$\\ds x =\\ln (y+\\sqrt{y^2+1})$.) \r\n\\end{ex}\r\n\r\n\\begin{ex} \r\nShow that the range of $\\tanh x$ is $(-1,1)$. What\r\nare the ranges of $\\coth$, $\\sech$, and $\\csch$? \r\n(Use the fact that they are reciprocal functions.) \r\n\\end{ex}\r\n\r\n\\begin{ex} \r\nProve that for every $x,y\\in\\R$, $\\sinh (x+y)\r\n=\\sinh x \\cosh y + \\cosh x \\sinh y$. Obtain a similar identity for\r\n$\\sinh(x-y)$.\r\n\\end{ex}\r\n\r\n\\begin{ex} \r\nProve that for every $x,y\\in\\R$, $\\cosh (x+y) =\\cosh x \\cosh y + \\sinh x\r\n  \\sinh y$. Obtain a similar identity for $\\cosh(x-y)$.\r\n\\end{ex}\r\n\r\n\\begin{ex} \r\nShow that $\\sinh(2x)=2\\sinh x \\cosh x$ and $\\ds \\cosh(2x)=\\cosh^2 x\r\n+\\sinh^2 x$ for every $x$.  Conclude also that $\\ds (\\cosh (2x) -1)/2 = \\sinh\r\n^2 x$.\r\n\\end{ex}\r\n\r\n%\\begin{ex} \r\n%What are the domains of the six inverse hyperbolic functions?\r\n%\\end{ex}\r\n%\r\n%\\begin{ex} \r\n%Sketch the graphs of all six inverse hyperbolic\r\n%  functions. \r\n%\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "070c9284f138924bc5831ed081e1e9b6794b1004", "size": 23173, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2-functions/2-7-hyperbolic-functions.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "2-functions/2-7-hyperbolic-functions.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "2-functions/2-7-hyperbolic-functions.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.4779270633, "max_line_length": 763, "alphanum_fraction": 0.5936218875, "num_tokens": 9888, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7692381193568633}}
{"text": "\\documentclass[dvipdfmx]{article}\n\\usepackage[dvipdfmx]{graphicx}\n\\usepackage[dvipdfmx]{hyperref}\n\\begin{document}\n\n\\section*{Transpose}\nThe arbitrary matrix $A$ is transposed to matrix $A^T$.\\\\\nThe example is shown as\n\\[\n  A = \\left(\n    \\begin{array}{ccc}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6 \\\\\n      7 & 8 & 9\n    \\end{array}\n  \\right) \n  , \\ \\ \\\n  A^T = \\left(\n    \\begin{array}{ccc}\n      1 & 4 & 7 \\\\\n      2 & 5 & 8 \\\\\n      3 & 6 & 9\n    \\end{array}\n  \\right) .\n\\] \n\n\n\\section*{Trace}\nThe trace of a square matrix A (${\\rm{tr}}A$) is defined to be the sum of elements on the main diagonal of A.\nThe example is shown as\n\\[\n  A = \n  \\left(\n    \\begin{array}{ccc}\n      a_{11} & a_{12} & a_{13} \\\\\n      a_{21} & a_{22} & a_{23} \\\\\n      a_{31} & a_{32} & a_{33}\n    \\end{array}\n  \\right)  =\n  \\left(\n    \\begin{array}{ccc}\n      1 & 2 & 3 \\\\\n      4 & 5 & 6 \\\\\n      7 & 8 & 9\n    \\end{array}\n  \\right) \n\\] \nthen \\\n${\\rm{tr}}A =  {\\sum_i}a_{ii} = 15$.\n\n\n\\section*{Determinant}\nFor a 3 × 3 matrix A, its determinant is \\\\\n\\[\n  |A| = \n    \\left|\n    \\begin{array}{ccc}\n      a_{11} & a_{12} & a_{13} \\\\\n      a_{21} & a_{22} & a_{23} \\\\\n      a_{31} & a_{32} & a_{33}\n    \\end{array}\n  \\right| =\n   a_{11}\n  \\left|\n    \\begin{array}{ccc}\n      \\times & \\times & \\times \\\\\n      \\times & a_{22} & a_{23} \\\\\n      \\times & a_{32} & a_{33}\n    \\end{array}\n  \\right|  \n  - a_{12}\n  \\left|\n    \\begin{array}{ccc}\n      \\times & \\times & \\times \\\\\n      a_{21} & \\times & a_{23} \\\\\n      a_{31} & \\times & a_{33}\n    \\end{array}\n  \\right| \n  + a_{13}\n    \\left|\n    \\begin{array}{ccc}\n      \\times & \\times & \\times \\\\\n      a_{21} & a_{22} & \\times \\\\\n      a_{31} & a_{32} & \\times\n    \\end{array}\n  \\right|\n\\] \n\\[\n   = a_{11}\n     \\left|\n    \\begin{array}{ccc}\n      a_{22} & a_{23} \\\\\n      a_{32} & a_{33}\n    \\end{array}\n  \\right|  \n  - a_{12}\n  \\left|\n    \\begin{array}{ccc}\n      a_{21} & a_{23} \\\\\n      a_{31} & a_{33}\n    \\end{array}\n  \\right| \n  + a_{13}\n    \\left|\n    \\begin{array}{ccc}\n      a_{21} & a_{22}  \\\\\n      a_{31} & a_{32} \n    \\end{array}\n  \\right|\n\\] \n\\[\n  \\ \\ \\ \\ \\ \\ = a_{11} a_{22}\n     \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      \\times & a_{33}\n    \\end{array}\n  \\right|  \n  - a_{11} a_{23}\n     \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      a_{32} & \\times\n    \\end{array}\n  \\right|  \n  - a_{12} a_{21}\n  \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      \\times & a_{33}\n    \\end{array}\n  \\right| \n   \\] \n \\[\n   \\ \\ \\ \\ \\ \\ + a_{12} a_{23}\n  \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      a_{31} & \\times\n    \\end{array}\n  \\right| \n  + a_{13} a_{21}\n    \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      \\times & a_{32} \n    \\end{array}\n  \\right|\n    - a_{13} a_{22}\n    \\left|\n    \\begin{array}{ccc}\n      \\times & \\times \\\\\n      a_{31} & \\times \n    \\end{array}\n  \\right|\n\\]\n\\ \\ \\ \\ \\ = $a_{11}a_{22}a_{33} - a_{11}a_{23}a_{32} - a_{12}a_{21}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{22}a_{31}$\n\n\n\\section*{Cramer's rule}\nIn a system of $n$ linear equations, represented in matrix multiplication form\n$A{\\bf{x}} = {\\bf{b}}$ \\\\\nwhere $A$ is the $n {\\times} n$ matrix and {\\bf{x}} and {\\bf{b}} are the $n$-th column vectors.\n${\\bf{x}} = (x_1, {\\cdots}, x_n)^T$ , ${\\bf{b}} = (b_1, {\\cdots}, b_n)^T$. \\\\\nThen, if $|A| {\\neq} 0$,  \\\\\n \\[\n   x_i = |A_i| / |A|, \\ \\ \\ \n   A_i =\n   \\left(\n   \\begin{array}{ccccc}\n   a_{11} & \\cdots & b_{1i} & \\cdots & a_{1n} \\\\\n   \\vdots & \\ddots  & \\vdots & \t     &  \\vdots \\\\\n   a_{k1} &             & b_{ki} &           & a_{kn} \\\\\n   \\vdots &            & \\vdots & \\ddots  &  \\vdots \\\\\n   a_{n1} & \\cdots & b_{ni} & \\cdots &  a_{nn}\n   \\end{array}\n   \\right)\n   \\]\nThis is Cramer's rule.\n\n\n\\section*{LU decomposition}\n$A = LU$ where\n \\[\n   A =\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22} & a_{23} \\\\\n   a_{31} & a_{32} & a_{33} \n   \\end{array}\n   \\right) ,\n    L =\n   \\left(\n   \\begin{array}{ccc}\n   1 & 0 & 0 \\\\\n   l_{21} & 1 & 0 \\\\\n   l_{31} & l_{32} & 1 \n   \\end{array}\n   \\right) ,\n     U =\n   \\left(\n   \\begin{array}{ccc}\n   u_{11} & u_{12} & u_{13} \\\\\n   0         & u_{22} & u_{23} \\\\\n   0         & 0         & u_{33} \n   \\end{array}\n   \\right) \n  \\]\n\n\n\\section*{Direct method by LU decomposition}\nIn linear equation $A{\\bf{x}} = {\\bf{b}}$, \n$LU{\\bf{x}} = {\\bf{b}}$\nby using LU decomposition $A = LU$.\n\nHere, we consider $L{\\bf{y}} = {\\bf{b}}$ and $U{\\bf{x}} = {\\bf{y}}$.\n\nIn forward substitution,\n\\begin{eqnarray}\ny_1 &&= b_1 \\nonumber \\\\\ny_2 &&= b_2 - l_{21}y_1 \\nonumber \\\\\n{\\vdots} \\nonumber \\\\\ny_n &&= b_n - {\\sum_{j=1}^{n-1}} l_{nj}y_j \\nonumber \n\\end{eqnarray}\n\nIn backforward substitution,\n\\begin{eqnarray}\nx_n &&= y_n / u_{nn} \\nonumber \\\\ \nx_{n-1} &&= (y_{n-1} - u_{n-1, n}x_n) / u_{n-1, n-1} \\nonumber \\\\ \n{\\vdots} \\nonumber \\\\\nx_1 &&= (y_1 - {\\sum_{j=2}^{n}} u_{1, j}x_j) / u_{11} \\nonumber \n\\end{eqnarray} .\n\n\n\\section*{Constant multiple}\n \\[\n   c\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & \\cdots & a_{1n} \\\\\n   \\vdots & \\ddots  & \\vdots \\\\\n   a_{n1} & \\cdots & a_{nn}\n   \\end{array}\n   \\right)\n   =\n   \\left(\n   \\begin{array}{ccc}\n   ca_{11} & \\cdots & ca_{1n} \\\\\n   \\vdots & \\ddots  & \\vdots \\\\\n   ca_{n1} & \\cdots & ca_{nn}\n   \\end{array}\n   \\right)\n   \\]\nwhere $c$ is the scalar constant.\n\n\n\\section*{Inverse matrix}\n$AB = BA = I$ \\\\\nwhere $A$ and $B$ is the $n$ × $n$ matrices and $I$ is the $n$ × $n$ unit matrix.\nIn the case, the matrix $B$ is uniquely determined by $A$ and is called the inverse matrix of $A$.\nThe inverse matrix of $A$ is denoted by $A^{-1}$.\n\n\n\\section*{Product}\nThe elements of the matrix product $C = AB$ is that\n$c_{ij} = [AB]_{ij} = {\\sum_k}a_{ik}b_{kj}$ \nwhere $A$ is an $n \\times m$ matrix and $B$ is an $m \\times l$  matrix.\n\n\n\\section*{Addition and Subtraction}\n \\[\n   A=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22}  & a_{23} \\\\\n   a_{31} & a_{32} & a_{33}\n   \\end{array}\n   \\right) ,\n   B =\n   \\left(\n   \\begin{array}{ccc}\n   b_{11} & b_{12} & b_{13} \\\\\n   b_{21} & b_{22}  & b_{23} \\\\\n   b_{31} & b_{32} & b_{33}\n   \\end{array}\n   \\right) ,\n \\]\nthen the addition/subtraction is that\n \\[\n   A {\\pm} B=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11}  {\\pm} b_{11} & a_{12}  {\\pm} b_{12}  & a_{13}  {\\pm} b_{13} \\\\\n   a_{21}  {\\pm} b_{21} & a_{22}  {\\pm} b_{22} & a_{23}  {\\pm} b_{23} \\\\\n   a_{31}  {\\pm} b_{31} & a_{32}  {\\pm} b_{32} & a_{33}  {\\pm} b_{33}\n   \\end{array}\n   \\right) \n \\]\n\n\n\\section*{Hadamard product}\n \\[\n   A=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22}  & a_{23} \\\\\n   a_{31} & a_{32} & a_{33}\n   \\end{array}\n   \\right) ,\n   B =\n   \\left(\n   \\begin{array}{ccc}\n   b_{11} & b_{12} & b_{13} \\\\\n   b_{21} & b_{22}  & b_{23} \\\\\n   b_{31} & b_{32} & b_{33}\n   \\end{array}\n   \\right) ,\n \\]\nthen the Hadamard product is that\n \\[\n   A {\\circ} B=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} b_{11} & a_{12} b_{12}  & a_{13} b_{13} \\\\\n   a_{21} b_{21} & a_{22} b_{22} & a_{23} b_{23} \\\\\n   a_{31} b_{31} & a_{32} b_{32} & a_{33} b_{33}\n   \\end{array}\n   \\right) \n \\]\n\n\n\\section*{Hadamard division}\n \\[\n   A=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22}  & a_{23} \\\\\n   a_{31} & a_{32} & a_{33}\n   \\end{array}\n   \\right) ,\n   B =\n   \\left(\n   \\begin{array}{ccc}\n   b_{11} & b_{12} & b_{13} \\\\\n   b_{21} & b_{22}  & b_{23} \\\\\n   b_{31} & b_{32} & b_{33}\n   \\end{array}\n   \\right) ,\n \\]\nthen the Hadamard division is that\n \\[\n   A / B=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} / b_{11} & a_{12} / b_{12}  & a_{13} / b_{13} \\\\\n   a_{21} / b_{21} & a_{22} / b_{22} & a_{23} / b_{23} \\\\\n   a_{31} / b_{31} & a_{32} / b_{32} & a_{33} / b_{33}\n   \\end{array}\n   \\right) \n \\]\n\n\n\\section*{Hadamard power}\n \\[\n   A^{(n)}=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11}^n & a_{12}^n & a_{13}^n \\\\\n   a_{21}^n & a_{22}^n  & a_{23}^n \\\\\n   a_{31}^n & a_{32}^n & a_{33}^n\n   \\end{array}\n   \\right)\n \\]\n where $n$ is scalar.\n\n\n\\section*{Tensor product}\n \\[\n   A=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22}  & a_{23} \\\\\n   a_{31} & a_{32} & a_{33}\n   \\end{array}\n   \\right) ,\n   B =\n   \\left(\n   \\begin{array}{ccc}\n   b_{11} & b_{12} & b_{13} \\\\\n   b_{21} & b_{22}  & b_{23} \\\\\n   b_{31} & b_{32} & b_{33}\n   \\end{array}\n   \\right) ,\n \\]\nthen the tensor product is that\n \\[\n   A {\\otimes} B =\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} B & a_{12} B  & a_{13} B \\\\\n   a_{21} B & a_{22} B & a_{23} B \\\\\n   a_{31} B & a_{32} B & a_{33} B\n   \\end{array}\n  \\right)\n\\]\n\\[\n    =\n   \\left(\n   \\begin{array}{ccccccccc}\n   a_{11} b_{11} & a_{11} b_{12} & a_{11} b_{13} & a_{12} b_{11} & a_{12} b_{12} & a_{12} b_{13} & a_{13} b_{11} & a_{13} b_{12} & a_{13} b_{13} \\\\\n   a_{11} b_{21} & a_{11} b_{22} & a_{11} b_{23} & a_{12} b_{21} & a_{12} b_{22} & a_{12} b_{23} & a_{13} b_{21} & a_{13} b_{22} & a_{13} b_{23} \\\\\n   a_{11} b_{31} & a_{11} b_{32} & a_{11} b_{33} & a_{12} b_{31} & a_{12} b_{32} & a_{12} b_{33} & a_{13} b_{31} & a_{13} b_{32} & a_{13} b_{33} \\\\\n   a_{21} b_{11} & a_{21} b_{12} & a_{21} b_{13} & a_{22} b_{11} & a_{22} b_{12} & a_{22} b_{13} & a_{23} b_{11} & a_{23} b_{12} & a_{23} b_{13} \\\\\n   a_{21} b_{21} & a_{21} b_{22} & a_{21} b_{23} & a_{22} b_{21} & a_{22} b_{22} & a_{22} b_{23} & a_{23} b_{21} & a_{23} b_{22} & a_{23} b_{23} \\\\\n   a_{21} b_{31} & a_{21} b_{32} & a_{21} b_{33} & a_{22} b_{31} & a_{22} b_{32} & a_{22} b_{33} & a_{23} b_{31} & a_{23} b_{32} & a_{23} b_{33} \\\\\n   a_{31} b_{11} & a_{31} b_{12} & a_{31} b_{13} & a_{32} b_{11} & a_{32} b_{12} & a_{32} b_{13} & a_{33} b_{11} & a_{33} b_{12} & a_{33} b_{13} \\\\\n   a_{31} b_{21} & a_{31} b_{22} & a_{31} b_{23} & a_{32} b_{21} & a_{32} b_{22} & a_{32} b_{23} & a_{33} b_{21} & a_{33} b_{22} & a_{33} b_{23} \\\\\n   a_{31} b_{31} & a_{31} b_{32} & a_{31} b_{33} & a_{32} b_{31} & a_{32} b_{32} & a_{32} b_{33} & a_{33} b_{31} & a_{33} b_{32} & a_{33} b_{33}\n   \\end{array}\n   \\right) \n \\]\n\n\n\\section*{Eigenvalue (Algebraic method)}\nAn eigen equation is written as\n$A{\\bf{u}} = {\\lambda}{\\bf{u}}$ \nwhere ${\\lambda}$ is scalar and ${\\bf{u}}$ is vector, known as the eigenvalue and eigenvector.\n\nBy rearranging above equation, we obtain:  $A{\\bf{u}} = {\\lambda}{\\bf{u}}$, $(A - {\\lambda}I){\\bf{u}} = {\\bf{0}}$. \nIf this equation has a nontrivial solution (${\\bf{u}} {\\neq} 0$),\nthe determinant $|A - {\\lambda}I| = 0$.\n\n\\begin{flushleft}\n[$2 {\\times} 2$ matrix case] \n\\end{flushleft}\nWhen the matrix $A$ is written as\n \\[\n   A=\n   \\left(\n   \\begin{array}{cc}\n   a_{11} & a_{12}  \\\\\n   a_{21} & a_{22} \\\\\n   \\end{array}\n   \\right) ,\n  \\]\nthe quadratic equation ${\\lambda}^2 -(a_{11} - a_{22}){\\lambda} + a_{11}a_{22} - a_{12}a_{21}$ is obtained.\nBy using quadratic formula, \n\\begin{eqnarray}\n{\\lambda} =  \\frac{ a_{11} -a_{22} {\\pm} \\sqrt{(a_{11}-a_{22})^2 - 4(a_{11}a_{22} - a_{12}a_{21})} }{2}. \\nonumber\n\\end{eqnarray} \\\\\n\n\\begin{flushleft}\n[$3 {\\times} 3$ matrix case]\n\\end{flushleft}\nWhen the matrix $A$ is written as\n \\[\n   A=\n   \\left(\n   \\begin{array}{ccc}\n   a_{11} & a_{12} & a_{13} \\\\\n   a_{21} & a_{22} & a_{23} \\\\\n   a_{31} & a_{32} & a_{33} \\\\\n   \\end{array}\n   \\right) ,\n  \\]\nwe obtain the cubic equation $a{\\lambda}^3 + b{\\lambda}^2 + c{\\lambda} + d = 0$  where \\\\\n$a = -1$, \\\\\n$b = a_{11} + a_{22} + a_{33}$, \\\\\n$c = a_{21}a_{12} + a_{13}a_{31} + a_{32}a_{23} - a_{11}a_{22} - a_{11}a_{33} - a_{22}a_{33}$, \\\\\n$d =  a_{11}a_{22}a_{33} + a_{12}a_{23}a_{31} + a_{13}a_{32}a_{21} - a_{11}a_{32}a_{23} - a_{22}a_{31}a_{13} - a_{33}a_{21}a_{12}$ . \\\\\n\nTherefore, \nwe can solve the eigen equation in the case of the $3{\\times}3$ matrix $A$ by substituting above $a$, $b$, $c$ and $d$ for the cubic formula.\nThe cubic formula is that \n\\begin{eqnarray}\n{\\lambda}_1 &&= -\\frac{b}{3a} \\nonumber \\\\\n       &&- \\frac{1}{3a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d + \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\nonumber \\\\  \n       &&- \\frac{1}{3a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d - \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\ \\ \\ , \\nonumber \\\\ \n\\nonumber \\\\\n{\\lambda}_2 &&= -\\frac{b}{3a} \\nonumber \\\\\n       &&- \\frac{1 + i \\sqrt{3}}{6a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d + \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\nonumber \\\\  \n       &&- \\frac{1 - i \\sqrt{3}}{6a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d - \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\ \\ \\ , \\nonumber \\\\ \n\\nonumber \\\\\n{\\lambda}_3 &&= -\\frac{b}{3a} \\nonumber \\\\\n       &&- \\frac{1 - i \\sqrt{3}}{6a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d + \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\nonumber \\\\  \n       &&- \\frac{1 + i \\sqrt{3}}{6a} \\sqrt[3]{ \\frac{1}{2} (2b^3 -9abc + 27a^2d - \\sqrt{(ab^3) - 9abc + 27a^2d)^2 - 4(b^2 - 3ac)^3} ) } \\ \\ \\ . \\nonumber \n\\end{eqnarray}\n \nIn this Elixir library, the complex numbers in the above equations are calculated as Gaussian plane.\n\\begin{center}\n  \\includegraphics[width=10cm]{gaussian_plane.jpg}\n\\end{center}\n\nThe real part and imaginary part are calculated by using arctangent's integral formula, written as\n \\begin{eqnarray}\n \\arctan{x} = {\\int_0^x} \\frac{1}{z^2 + 1} dz. \\nonumber\n \\end{eqnarray}\n This formula is treated as the numerical integration.\n\n\n\\section*{Eigenvalue and eigenvector (Power iteration method to solve maximum eigenvalue and eigenvector of $n$-th eigen equation)}\nAn arbitrary (initial) vector ${\\bf{b}}^0$ is written by the linear combination of eigenvectors ${\\sum_i} c_i{\\bf{u}}_i$\nbecause eigenvectors are linearly independent.\n\\begin{eqnarray}\n{\\bf{b}}^k {\\equiv} A^k {\\bf{b}}^0 = A^k {\\sum_i} c_i{\\bf{u}}_i = {\\sum_{i=1}} c_i {\\lambda}^k_i {\\bf{u}}_i \\nonumber \\\\\n= {\\lambda}_1^k (c_1{\\bf{u}}_1 + {\\sum_{i=2}} c_i \\frac{{\\lambda}^k_i}{{\\lambda}^k_1} {\\bf{u}}_i)  \\nonumber\n\\end{eqnarray}\nwhere ${\\lambda}_1$ is maximum value of the eigenvalue so that $|\\frac{{\\lambda}^k_i}{{\\lambda}^k_1}| < 1$.\n\nIf $k$ is a large enough number, \nwe can write the eigenvector of the maximum eigenvalue, shown as\n\\begin{eqnarray}\n{\\bf{b}}^k {\\simeq} {\\lambda}^k_1c_1{\\bf{u}}_1. \\nonumber\n\\end{eqnarray} \nMoreover,  we can write the maximum eigenvalue\n\\begin{eqnarray}\n{\\lambda}_1 = \\frac{({\\bf{b}}^k)^TA{\\bf{b}}^k}{({\\bf{b}}^k)^T{\\bf{b}}^k}. \\nonumber\n\\end{eqnarray}\n\n\n\\section*{Eigenvalue and eigenvector (Jacobi method)}\nThe Jacobi method is an iterative method for the numerical calculation of the eigenvalues and eigenvectors of a real $n$-th symmetric matrix.\n(cf. \\url{https://en.wikipedia.org/wiki/Jacobi_eigenvalue_algorithm} )\n\n\n\\section*{Eigenvalue (iterative method using QR decomposition)}\nThe iterative method using QR decomposition is used to calculate eigenvalues of a $n$-th real square matrix.\nThe QR decomposition is the decomposition of matrix $A$ into orthogonal matrix $Q$ and upper-triangular matrix $R$ as shown below.\n$$\nA = QR\n$$\nIn this section, QR decomposition is performed by using Householder transformation.\nHouseholder transformation corresponds to matrix $H$ below. \n\\begin{eqnarray}\n{\\bf{x}} = H {\\bf{y}} \\nonumber \\\\\n{\\bf{y}} = H {\\bf{x}} \\nonumber\n\\end{eqnarray}\n\\begin{eqnarray}\nH = I - \\frac{2({\\bf{x}} - {\\bf{y}})({\\bf{x}} - {\\bf{y}})^T}{|{\\bf{x}} - {\\bf{y}}|^2} \\nonumber\n\\end{eqnarray}\n$H$ is orthogonal matrix where $HH^T=I$.\nHere,\n\\[\n  A = A^{(1)} =\n  \\left(\n  \\begin{array}{ccc}\n  a_{11} & \\cdots & a_{1n} \\\\\n  \\vdots & \\ddots & \\vdots \\\\\n  a_{n1} & \\cdots & a_{nn}\n  \\end{array}\n  \\right),\n\\]\n$$\nA^{(2)}=H^{(1)}A^{(1)}, \\\\\nA^{(2)} =\n\\left(\n\\begin{array}{cccc}\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\n0      & \\vdots & \\vdots & \\vdots \\\\\n\\vdots & \\vdots & \\vdots & \\vdots \\\\\n0      & a_{n2} & \\cdots & a_{nn}\n\\end{array}\n\\right).\n$$\n$H^{(1)}$ to Householder transform the first column into a finite vector with only the top element.\n\n$$\nA^{(3)}=H^{(2)}A^{(2)}, \\\\\nA^{(3)} =\n\\left(\n\\begin{array}{ccccc}\na_{11} & a_{12} & a_{12} & \\cdots & a_{1n} \\\\\n0      & a_{22} & \\vdots & \\vdots & \\vdots \\\\\n0      & 0      & \\vdots & \\vdots & \\vdots \\\\\n\\vdots & \\vdots & \\vdots & \\vdots & \\vdots \\\\\n0      & 0      & a_{n2} & \\cdots & a_{nn}\n\\end{array}\n\\right).\n$$\n$H^{(2)}$ to Householder transform the second column into a finite vector with the top 2 elements.\n\n$$\nH^{(n-1)} {\\cdots} H^{(1)} A^{(1)} = R,\n$$\n$$\nA = A^{(1)} = H^{(n-1)T} {\\cdots} H^{(1)T} R = QR.\n$$\nThe product of orthogonal matricies $Q_1$ and $Q_2$ is also orthogonal matrix $Q_3(=Q_1Q_2)$.\n\nThus,\n$$\nA = A_1 = Q_1R_1, A_2 = R_1Q_1,\n$$\n$$\nA_{k+1} = (Q_k^{-1}{\\cdots}Q_1^{-1}) A_1 (Q_1{\\cdots}Q_k) = {\\tilde{Q}}_k^{-1}A_1{\\tilde{Q}}_k.\n$$\n\nOn the other hand,\n$$\nA_1^k = Q_1R_1 {\\cdots} Q_1R_1 = Q_1(R_1Q_1){\\cdots}(R_1Q_1)R_1 = Q_1{\\cdots}Q_k R_k{\\cdots}R_1 = {\\tilde{Q}}_k {\\tilde{R}}_k.\n$$\n\nThe eigen equations are written as follows.\n$$\nAX=X{\\Lambda}.\n$$\nThen,\n$$\nA^k = A_1^k = X{\\Lambda}X^{-1} {\\cdots} X{\\Lambda}X^{-1} = X{\\Lambda}^kX^{-1}.\n$$\n\n$QR$ decomposition of $X$ and $LU$ decomposition of $X^{-1}$.\n$$\nX = Q_XR_X, X^{^-1} = LU.\n$$\n$$\nA_1^k = X{\\Lambda}X^{-1} = Q_XR_X {\\Lambda}^k LU = Q_XR_X ({\\Lambda}^k L {\\Lambda}^{-k})({\\Lambda}^kU).\n$$\nSince it is\n$$\n{\\Lambda}^k L {\\Lambda}^{-k} =\n\\left(\n\\begin{array}{cccc}\n1                                  & 0                                 & 0      & 0      \\\\\nl_{21}({\\lambda}_2/{\\lambda}_1)^k  & 1                                 & 0      & 0      \\\\\nl_{31}({\\lambda}_3/{\\lambda}_1)^k  & l_{32}({\\lambda}_3/{\\lambda}_2)^k & 1      & 0      \\\\\n\\vdots                             & \\vdots                            & \\ddots & \\vdots \\\\\nl_{n1}({\\lambda}_3/{\\lambda}_1)^k  & l_{n2}({\\lambda}_3/{\\lambda}_1)^k & \\cdots & 1\n\\end{array}\n\\right),\n$$\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} A_1^k \n= {\\lim_{k{\\rightarrow}{\\infty}}} Q_XR_X ({\\Lambda}^k L {\\Lambda}^{-k})({\\Lambda}^kU) \n= Q_X(R_X {\\lim_{k{\\rightarrow}{\\infty}}} {\\Lambda}^k U)\n$$\nOn the other hand,\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} A_1^k = {\\lim_{k{\\rightarrow}{\\infty}}} {\\tilde{Q}}_k {\\tilde{R}}_k.\n$$\n$$\nQ_X = {\\lim_{k{\\rightarrow}{\\infty}}} {\\tilde{Q}}_k\n$$\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} Q_k \n= {\\lim_{k{\\rightarrow}{\\infty}}} (Q_{k-1}^{-1}{\\cdots}Q_{1}^{-1}) (Q_{1}{\\cdots}Q_{k-1}) Q_k\n= {\\lim_{k{\\rightarrow}{\\infty}}} {\\tilde{Q}}_{k-1}^{-1} {\\lim_{k{\\rightarrow}{\\infty}}} {\\tilde{Q}}_{k}\n= Q_X^{-1}Q_X\n= I,\n$$\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} R_k\n= {\\lim_{k{\\rightarrow}{\\infty}}} A_{k+1}Q_k^{-1}\n= {\\lim_{k{\\rightarrow}{\\infty}}} ({\\tilde{Q}}_k^{-1}A_1{\\tilde{Q}}_k)Q_k^{-1}\n= {\\lim_{k{\\rightarrow}{\\infty}}} {\\tilde{Q}}_k^{-1}A_1(Q_1{\\cdots}Q_k)Q_k^{-1}\n= Q_X^{-1}A_1Q_X.\n$$\nSince $X=Q_XR_X$,\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} R_k = Q_X^{-1}A_1Q_X = (R_XX^{-1})A_1(XR_X^{-1}) = R_X{\\Lambda}R_X^{-1},\n$$\nTherefore,\n$$\n{\\lim_{k{\\rightarrow}{\\infty}}} A_k =\n{\\lim_{k{\\rightarrow}{\\infty}}} Q_kR_k =\nR_X{\\Lambda}R_X^{-1} =\n\\left(\n\\begin{array}{cccc}\n{\\lambda_1} & *           & *        & *           \\\\\n0           & {\\lambda_2} & *        & *           \\\\\n\\vdots      & {\\ddots}    & {\\ddots} & *           \\\\\n0           & {\\cdots}    & 0        & {\\lambda_n}\n\\end{array}\n\\right).\n$$\nAlso, by finding the eigenvalues above, we can use inverse power iteration and eigenvalue shift to find the eigenvectors.\n\n\n\\section*{Rank}\nSince the rank of matrix is equal to the number of nontrivial nonzero eigenvalues, \nit is calculated from the eigenvalues obtained by the Jacobi method or iterative method using QR decomposition.\nIn this library, we use iterative method using QR decomposition, which has a faster processing speed.\n\n \n\\section*{Singular Value Decomposition}\nSingular value decomposition (SVD) states:\n$$\nA = U {\\Sigma} V^T\n$$\nwhere $A$ and ${\\Sigma}$ is ${n{\\times}m}$ matrix, $U$ is ${n{\\times}n}$ orthogonal matrix, $U$ is ${m{\\times}m}$ orthogonal matrix.\nIn the case $m > n$,\n \\[\n   {\\Sigma} =\n   \\left(\n   \\begin{array}{ccc|c}\n   {\\sigma}_{11} & \\            & O                    & \\ \\\\\n   \\                      & {\\ddots} & \\                     & O \\\\\n   O                    & \\            & {\\sigma}_{nn} & \\\n   \\end{array}\n   \\right) \n  \\] \n  where ${\\sigma}$ is singular value.\n\nIt can be replaced by an eigenvalue problem from the following relation.\n$$\nAA^T = U {\\Sigma} V^T  (U {\\Sigma} V^T)^T = U{\\Sigma}^2U^T ,\n$$\n \\[\n   {\\Sigma}^2 =\n   \\left(\n   \\begin{array}{ccc}\n   {\\sigma}_{11}^2 & \\            & O \\\\\n   \\                         & {\\ddots} & \\   \\\\\n   O                       & \\            & {\\sigma}_{nn}^2\n   \\end{array}\n   \\right) =\n   \\left(\n   \\begin{array}{ccc}\n   {\\lambda}_{11} & \\            & O \\\\\n   \\                       & {\\ddots} & \\   \\\\\n   O                     & \\            & {\\lambda}_{nn}\n   \\end{array}\n   \\right) \n  \\] \n  where $\\lambda$ is eigenvalue of $AA^T$.\n \n\n\\section*{Diagonalization}\nAn $n{\\times}n$ matrix $A$ is diagonalizable when $A$ has $n$ eigenvectors that are linear independent of each other.\nWe consider the matrix $P$ that is written as $P=[{\\bf{x}}_1, {\\bf{x}}_2, {\\cdots}, {\\bf{x}}_n]$ where ${\\bf{x}}_i, i=1,{\\cdots},n$ linear independent eigenvector of $A$.\n\n\\begin{eqnarray}\nAP = A[{\\bf{x}}_1, {\\bf{x}}_2, {\\cdots}, {\\bf{x}}_n]\n     = [{\\lambda}_1{\\bf{x}}_1, {\\lambda}_2{\\bf{x}}_2, {\\cdots}, {\\lambda}_n{\\bf{x}}_n] \\nonumber\n\\end{eqnarray}\nwhere ${\\lambda}_i, i=1,{\\cdots},n$ eigenvalue of $A$.\nSince ${\\bf{x}}_1, {\\bf{x}}_2, {\\cdots}, {\\bf{x}}_n$ are linear independent,\n\\[\n  P^{-1}AP =\n  \\left(\n  \\begin{array}{ccc}\n  {\\lambda}_{1} & \\ & O \\\\\n  \\          & \\ddots  & \\    \\\\\n  O        &   \\          & {\\lambda}_{n}\n  \\end{array}\n  \\right)\n\\] .\nThis matrix is the diagonal matrix of $A$.\n \n \n\\section*{Jordan normal form}\nSince $(A - {\\lambda}E){\\bf{u}} = {\\bf{x}}$ and $(A - {\\lambda}E){\\bf{x}} = {\\bf{0}}$,\n\\begin{eqnarray}\n\\left\\{ \\begin{array}{ll}\nA{\\bf{u}}= {\\bf{x}} + {\\lambda}{\\bf{u}} \\\\\nA{\\bf{x}}={\\lambda}{\\bf{x}} \\\\\n\\end{array} \\right.\n\\end{eqnarray} .\n\nTherefore,\n \\[\n   A\n   \\left(\n   \\begin{array}{cc}\n   {\\bf{x}} & {\\bf{u}} \n   \\end{array}\n   \\right)\n   =\n   \\left(\n   \\begin{array}{cc}\n   {\\bf{x}} & {\\bf{u}} \n   \\end{array}\n   \\right)\n   \\left(\n   \\begin{array}{cc}\n   {\\lambda} & 1 \\\\\n   0 & {\\lambda}\n   \\end{array}\n   \\right)\n  \\] .\n\n$$P^{-1}AP = J$$ where\n\\[\n   P =\n   \\left(\n   \\begin{array}{cc}\n   {\\bf{x}} & {\\bf{u}} \n   \\end{array}\n   \\right) ,\n   J =\n   \\left(\n   \\begin{array}{cc}\n   {\\lambda} & 1 \\\\\n   0 & {\\lambda}\n   \\end{array}\n   \\right).\n  \\] .\n\n\n\\section*{Matrix norms}\n$A$ is $n{\\times}m$ matrix.\n\nFrobenius norm:\n$$\n||A||_F = \\sqrt{{\\sum_i^n}{\\sum_j^m} |a_{ij}|^2} \\ \\ .\n$$\n \n$L_1$ norm:\n$$\n||A||_1 = \\max_{j}  {\\sum_i^n} |a_{ij}| \\ \\ .\n$$\n\nMax norm:\n$$\n||A||_{\\infty} = \\max_{i}  {\\sum_j^n} |a_{ij}| \\ \\ .\n$$\n\n$L_2$ norm:\n$$\n||A||_2 = \\max_{ij}  {\\sigma}_{ij}\n$$\nwhere $\\sigma$ is singular value of $A$.\n\n\n\\section*{Variance covariance matrix}\nA variance covariance matrix can be defined as\n \\[\n   S =\n   \\left(\n   \\begin{array}{cc}\n   s_{xx} & s_{xy} \\\\\n   s_{yx} & s_{yy}  \n   \\end{array}\n   \\right) \n  \\]\nwhere $s_{xx}$ is variance value and $s_{xy}$ is covariance value.\n$s_{xy} = \\frac{1}{n}({\\bf{x}} - \\bar{\\bf{x}})({\\bf{y}} - \\bar{\\bf{y}})$, $\\bar{\\bf{x}} = {\\sum_{i=1}^n} x_i /n$.\n\nBy the way, we can consider the Principal Component Analysis (PCA) by this variance covariance matrix with above power Iteration library.\n\n\\end{document}\n", "meta": {"hexsha": "0439d95739cd06423f7d60968757a5e225aa5ebe", "size": 23150, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/numerical_formula.tex", "max_stars_repo_name": "kenken-neko/elixir-matrix-operation", "max_stars_repo_head_hexsha": "695bcee1c97bbac78d40645897b21fcd52b1ce84", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2019-12-18T21:40:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-05T13:20:45.000Z", "max_issues_repo_path": "docs/numerical_formula.tex", "max_issues_repo_name": "kenken-neko/elixir-matrix-operation", "max_issues_repo_head_hexsha": "695bcee1c97bbac78d40645897b21fcd52b1ce84", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2020-05-20T10:46:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-26T13:46:12.000Z", "max_forks_repo_path": "docs/numerical_formula.tex", "max_forks_repo_name": "kenken-neko/elixir-matrix-operation", "max_forks_repo_head_hexsha": "695bcee1c97bbac78d40645897b21fcd52b1ce84", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-01-24T05:20:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-18T19:26:33.000Z", "avg_line_length": 27.3317591499, "max_line_length": 170, "alphanum_fraction": 0.520475162, "num_tokens": 9717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171067, "lm_q2_score": 0.8670357563664174, "lm_q1q2_score": 0.7692381059652716}}
{"text": "\\textbf{ Using finite differences on the given grid and the data in $u$ and $v$ from \\texttt{velocitydata.mat}, solve the equation of temperature in a fluid flow}\n\\begin{align*}\nT_t + uT_x + vT_y = \\alpha(T_{xx}+T_{yy}),~~(x,y)\\in (0,1) \\times (0,1),~~t>0,\n\\end{align*} \n\\textbf{where $\\alpha = 0.0005$. Assume that $T=0$ at $t=0$ and that $T(t,x,y) = xy\\tanh(10t)^2$ on the boundary. use \\texttt{contourf} to plot the level curves to the temperature at times $t = 10,50,150,300$.}\n\nWe can appreciate that the equation to solve has the same form than the vorticity equation using the frozen values for the velocity given as data. Just adjusting the given code we obtain the following results.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[$t=1$ s.]{\\includegraphics[scale=0.55]{T_10.eps}}\n\\hfill\n\\subfigure[$t=2$ s.]{\\includegraphics[scale=0.55]{T_50.eps}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[$t=3$ s.]{\\includegraphics[scale=0.55]{T_150.eps}}\n\\hfill\n\\subfigure[$t=5$ s.]{\\includegraphics[scale=0.55]{T_300.eps}}\n\\hspace*{\\fill}\n\\caption{Temperature Contours at different values of time.}\n\\end{figure}\n\n\\subsection*{Matlab code for this part}\n\\begin{verbatim}\nclear variables; close all; clc\nDATA=load('velocitydataPlatte.mat');\nu=DATA.u;\nv=DATA.v;\nxx=DATA.xx;\nyy=DATA.yy;\nfluidflowFDTemperature(xx,yy,u,v)\n\n% Fluid flow in a cavity (Navier-Stokes equations)\n% Stream-function and vorticity formulation\n%\n% Rodrigo Platte, Arizona State University, April 2013.\n\nfunction fluidflowFDTemperature(xx,yy,u,v)\n% Parameters\npath='Latex/FIGURES/';\nN = 150;\nalpha = 0.0005;\ndt = min(0.2/(alpha*N^2),1e-3);\n\nh = 1/N; % N+1 points in each direction\n\n% Initial condition & pre-allocate memory (start with zeros at t = 0)\nT = 0*xx;\n\n% boundary condition\nii = 2:N; jj = 2:N;  % index for interior nodes\nTi = zeros(N-1,N-1); % interior values of vorticity\n\ncount = 0;\ntime = 0;\noutputTime=[10 50 150 300];\nendtime=outputTime(end);\nn=1;\n% main loop\nwhile time<endtime\n\tif ( time < outputTime(n) && time+dt >= outputTime(n) ) %#ok<ALIGN>\n        dt=outputTime(n)-time;\n        n=n+1;\n    else\n        dt = min(0.2/(alpha*N^2),1e-3);\n    end\n   % advance Temperature with forward Euler\n   Ti = Ti + dt*Trhs(u,v,T,alpha);\n   T(ii,jj)=Ti;\n   \n   % update Temperature at boundary\n   T = BCT(xx,yy,time,T);\n   \n   time = time+dt;\n   count = count + 1;\n   \n   % Plot results every now and then\n   if ismember(time,outputTime);\n       plotresults(time,T);    \n   end\n\nend\n    % Right-hand side of vorticity equation\n    function rhs = Trhs(u,v,T,alpha)\n        Tx = (T(ii,jj+1)-T(ii,jj-1))/(2*h);\n        Ty = (T(ii+1,jj)-T(ii-1,jj))/(2*h);\n        LT = (T(ii,jj+1)+T(ii,jj-1)+T(ii+1,jj)+T(ii-1,jj)-4*T(ii,jj))/h^2;\n        rhs = -u(ii,jj).*Tx - v(ii,jj).*Ty + alpha*LT;          \n    end\n\n    % Enforce boundary condition (temperature)\n    function T = BCT(xx,yy,t,T)\n        T(1,:)=xx(1,:).*yy(1,:).*tanh(10*t).^2;\n        T(N+1,:)=xx(N+1,:).*yy(N+1,:).*tanh(10*t).^2;\n        T(:,1)=xx(:,1).*yy(:,1).*tanh(10*t).^2;\n        T(:,N+1)=xx(:,N+1).*yy(:,N+1).*tanh(10*t).^2;\n    end\n\n    % Plot results\n    function plotresults(time,T)\n        figure();set(gcf,'Visible', 'off');\n        pcolor(xx,yy,T)\n        shading interp\n        H = colorbar; set(H,'fontsize',16)\n        caxis([0 1])\n        colorbar\n        axis square\n        drawnow      \n        xlabel('$x$','Interpreter','latex')\n        ylabel('$y$','Interpreter','latex')\n        set(get(gca,'ylabel'),'rotation',0)\n        txt=[path,'T_' num2str(time)];\n        saveas(gcf,txt,'epsc')\n    end\n\nend\n\n\\end{verbatim}", "meta": {"hexsha": "40238ebc3afa2cf05c005906cb76912cc87e3279", "size": 3594, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem3.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem3.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 6/Latex/problem3.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.95, "max_line_length": 210, "alphanum_fraction": 0.6179744018, "num_tokens": 1215, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8872045877523148, "lm_q2_score": 0.8670357546485408, "lm_q1q2_score": 0.7692380992694757}}
{"text": "\\section{Motivation}\r\nThe history of variational principles can be dated back to a pretty concrete classical problem known as the Brachistochrone problem:\r\n\\begin{example}[The Brachistochrone Problem]\r\n    Consider a particle moving under the influence of gravity on a wire joining points $A$ and $B$.\r\n    What shape of the curve gives the shortest travel time of the particle given that it starts from rest?\\\\\r\n    Mathematically, we want to minimise the quantity\r\n    $$\\tau=\\int_A^B\\mathrm dt=\\int_A^B\\frac{\\mathrm dL}{v(x,y)}$$\r\n    This problem was first created by Johann Bernoulli in 1696, who posted the problem in a journal as a challenge to the world's mathematcians at the time.\r\n    And the answer given by Newton starts the study of calculus of variations.\r\n    We are not going to fully solve the problem in this section, but instead just give a taste of the whole picture.\\\\\r\n    Assuming $A$ is the origin and $B=(x_2,y_2)$\r\n    Using energy conservation,\r\n    $$\\frac{1}{2}mv^2+mgy=0\\implies v=\\sqrt{-2gy}$$\r\n    Take $y$ as a function of $x$, then we are aiming at finding the minima of the functional\r\n    $$\\tau[y]=\\frac{1}{\\sqrt{2g}}\\int_0^{x_2}\\frac{\\sqrt{1+(y^\\prime)^2}}{\\sqrt{-y}}\\,\\mathrm dx$$\r\n    subject to\r\n    $$\\begin{cases}\r\n        y(0)=0\\\\\r\n        y(x_2)=y_2\r\n    \\end{cases}$$\r\n\\end{example}\r\nAnother very famous and very useful example is geodesics.\r\n\\begin{example}[Geodesics]\r\n    On a surface $\\Sigma$, a geodesics $\\gamma$ is the path of least length joining two given points.\r\n    If $\\Sigma$ is the Euclidean plane, it is well-known that $\\gamma$ has to be a straight line.\r\n    Let $D[y]$ denote the length of the curve given by $y$ and assume that the curve traverse as a function $y(x)$ from $x_1,x_2$, then minimising the following integral \r\n    $$D[y]=\\int_{x_1}^{x_2}\\sqrt{1+(y^\\prime)^2}\\,\\mathrm dx$$\r\n    subject to $y(x_1)=y_1,y(x_2)=y_2$ would be our aim.\r\n\\end{example}\r\nIn general, the calculus of variations focus on solving optimisation problems of the a functional (i.e. functions from a space of functions to the reals)\r\n$$F[y]=\\int_{x_1}^{x_2}f(x,y(x),y^\\prime(x))\\,\\mathrm dx$$\r\namong all (sufficiently smooth) functions $y$ subject to initial conditions.\r\n\\begin{example}[Examples of Functionals]\r\n    1. For a function $y(x)$, we can define the functional calculating the area under the curve by setting $f(x,y,y^\\prime)=y$.\\\\\r\n    2. We can also define the functional calculating length by\r\n    $$f(x,y,y^\\prime)=\\sqrt{1+(y^\\prime)^2}$$\r\n\\end{example}\r\nNotationally, we write $C(\\mathbb R)$ as the space of continuous functions from $\\mathbb R$ to $\\mathbb R$.\r\nWe write $C^k(\\mathbb R)$ to denote the space of $k$-time differentiable functions with continuous $k^{th}$ derivative.\r\nAnd $C^k_{\\alpha,\\beta}(\\mathbb R)$ is the space of functions $[\\alpha,\\beta]\\to\\mathbb R$ that are $C^k$ on $[\\alpha,\\beta]$ and vanishes at $\\alpha,\\beta$.\r\nOne should know that these are these are all (infinite-dimensional) vector spaces over $\\mathbb R$, the detail of analysis of which will be covered in functional analysis contexts.\\\\\r\nThe reason why the course is called ``variational principles'' instead of ``calculus of variations'' is because what we are studying are principles in nature and laws of physics that follow from extremising functionals.\r\n\\begin{example}[Fermat's Principle]\r\n    Light that travels between two points follow the path that extremise the travel time.\r\n\\end{example}\r\n\\begin{example}[Principle of Least Action]\r\n    Let $T,V$ be the kinetic and potential energies.\r\n    We define the functional on a path\r\n    $$S[\\gamma]=\\int_{t_1}^{t_2}(T-V)\\,\\mathrm dt$$\r\n    then the path that a particle travels from $t=t_1$ to $t=t_2$ is the one that extremises $S$.\r\n    Once we have developed our theory further, one can show that Newton's Second Law follows from this principle.\\\\\r\n    Leibniz's take on this principle is that we live in ``the best of all possible worlds''.\r\n    In some sense, we go from science to something like the field of theology.\r\n    Of course, this is not in the scope of this course.\\\\\r\n    Richard Feynman's take on this principle is that it is ``wrong''.\r\n    Indeed, in quantum physics, nothing takes a definitive path, but every paths are possible with some probability.\r\n    The principle under this framework, instead, is that the stationary path of a particle is, in fact, the interference along all paths.\r\n\\end{example}\r\nWhat we shall show in this course are the follows:\r\nFirst, we will see some necessary conditions for a function to be an extrema, like the Euler-Lagrange equations.\r\nSecondly, we will bring this principle on problems in geometry, physics, and problem with constraints (like the isoperimetric inequality).\r\nWe will also talk about what is called the ``second variation'' as an analog of the second derivative.", "meta": {"hexsha": "fc1c2a1a7e187ba391d6d48d6c3e168f68197849", "size": 4849, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/motiv.tex", "max_stars_repo_name": "david-bai-notes/IB-Variational-Principles", "max_stars_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "0/motiv.tex", "max_issues_repo_name": "david-bai-notes/IB-Variational-Principles", "max_issues_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "0/motiv.tex", "max_forks_repo_name": "david-bai-notes/IB-Variational-Principles", "max_forks_repo_head_hexsha": "16d539d58f2857793efd9f502e1e81f537ace5a1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 78.2096774194, "max_line_length": 220, "alphanum_fraction": 0.7184986595, "num_tokens": 1296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582516374121, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7692208144915841}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Solve the following system of second order linear differential equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}r@{~}r@{~}r}\n      y'' &=& -5y &-& 6z, \\\\\n      z'' &=& 3y &+& 4z. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Solve the following system of second order linear differential equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}r@{~}r@{~}r}\n      y'' &=& 4y &-& 3z, \\\\\n      z'' &=& 2y &-& z. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Solve the following system of second order linear differential equations:\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}l}\n      x'' &=& -2y + 2z, \\\\\n      y'' &=& x - z, \\\\\n      z'' &=& x - 2y + z. \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Solve the following system of first order linear differential equations.\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}r@{~}r@{~}r}\n      y' &=& 4y &+& 6z, \\\\\n      z' &=& -3y &-& 5z. \\\\\n    \\end{array}\n  \\end{equation*}\n  Hint: The method is similar to that of second-order equations. Use\n  the fact, known from calculus, that the equation $f'=kf$ has basic\n  solution $f(x) = e^{kx}$. Here $k$ is any constant (positive,\n  negative, or zero).\n\\end{ex}\n\n\\begin{ex}\n  Consider three coupled train cars as in\n  Example~\\ref{exa:coupled-train-cars}, except that all three cars\n  have mass $1\\kg$ and both spring have spring constant\n  $k=1\\frac{\\SI{N}}{\\m}$. Find and solve the equations of motion.\n\\end{ex}\n\n", "meta": {"hexsha": "5d9b6913788d4f28f90b5ce661c4408e9338c6c6", "size": 1502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Application-Differential.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Application-Differential.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Application-Differential.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.3090909091, "max_line_length": 75, "alphanum_fraction": 0.5852197071, "num_tokens": 557, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789457685656, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.7692180643279217}}
{"text": "\n\\subsection{Fundamental Theorem of Arithmetic}\n\n\\subsubsection{Statement}\n\nEach natural number is a prime or unique product of primes.\n\n\\subsubsection{Proof: existance of each number as a product of primes}\n\nIf \\(n\\) is prime, no more is needed.\n\nIf \\(n\\) is not prime, then \\(n=ab\\), \\(a,b\\in \\mathbb{N} \\).\n\nIf \\(a\\) and \\(b\\) are prime, this is complete. Otherwise we can iterate to find:\n\n$n=\\prod_{i=1} p_i$\n\n\\subsubsection{Proof: this product of primes is unique}\n\nConsider two different series of primes for the same number:\n\n$s=\\prod_{i=1}^n p_i = \\prod_{i=1}^m q_i$\n\nWe need to show that \\(n=m\\) and \\({p}={q}\\).\n\nWe know that \\(p_i\\) divides \\(s\\). We also know that through Euclid's lemma that if a prime number divides a non-prime number, then it must also divide one of its components. As a result \\(p_i\\) must divide one of \\({q}\\).\n\nBut as all of \\({q}\\) are prime then \\(p_i\\)=\\(q_j\\).\n\nWe can repeat this process to to show that \\({p}={q}\\) and therefore \\(n=m\\).\n\n", "meta": {"hexsha": "e899c73b80fccc3e3d360463d66d3ecceb664960", "size": 983, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmeticFundamental/01-04-integersArithmatic.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/arithmeticFundamental/01-04-integersArithmatic.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/arithmeticFundamental/01-04-integersArithmatic.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.71875, "max_line_length": 223, "alphanum_fraction": 0.6805696846, "num_tokens": 291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8418256472515684, "lm_q1q2_score": 0.7691563267438009}}
{"text": "%begin-include\n\n\\section{ZFC Set theory}\n\n\\begin{para}[ZFC set theory]\nThe standard axiomatisation of set theory is known as ZFC. The Z and the F stand, respectively, for the mathematicians Ernst Zermelo and Abraham Fraenkel. The C stands for the controversial axiom of choice, so, yes, there is an axiomatisation of set theory known as ZF that does not include this axiom.\n\nThe formal system $\\mathsf{ZFC}$ in which we are going to formalise set theory uses first-order logic with equality and is built on the first-order language with set of symbols $S = \\{=,\\in,\\emptyset\\}$ and signature $\\sigma(=) = -2$,  $\\sigma(\\in) = -2$ and $\\sigma(\\emptyset) = 0$. Both $=$ and $\\in$ are used with infix notation.\nIf two elements $x$ and $y$ satisfy $x = y$ or $x\\in y$, we will say, respectively that ``$x$ is equal to $y$'' and that ``$x$ is an \\emph{element} of $y$''.\nWe can also say that ``$x$ is \\emph{contained} in $y$'' to mean that $x\\in y$.\nThe constant $\\emptyset$ will be referred to as the \\emph{empty set}.\nThe elements of the domain of any model of $\\mathsf{ZFC}$ are called \\emph{sets}.\n\nFor any two variables (sets) $x$ and $y$, we introduce the notation $x\\subseteq y$ as an abbreviation of the formula $(\\forall a)\\qsep a\\in x \\limplies a \\in y$ for any variable $a$ not occurring anywhere in the formula where $x\\subseteq y$ is being used.\nIf two sets $x$ and $y$ satisfy $x\\subseteq y$, we say ``$x$ is \\emph{included} in $y$''.\n\nWe will now present all the non-logical axioms of $\\mathsf{ZFC}$ and analyse them from a semantic perspective.\n\\begin{axioms}[ZF]\n\\item \\label{extensionality} Axiom of extensionality: $(\\forall x)(\\forall y)\\qsep ((\\forall a)\\qsep (a \\in x \\liff a\\in y)) \\limplies x = y$.\n\\end{axioms}\nIn layman's terms, the axiom of extensionality means that any two sets with the same elements are equal.\nIn addition, using this axiom, \\ref{axe4}, \\ref{foiff} and the generalisation rule, one can easily deduce that\n\\[(\\forall x)(\\forall y)\\qsep x = y \\liff ((\\forall a)\\qsep a\\in x \\liff a \\in y).\\]\n\n\\begin{axioms}\n\\item \\label{emptyset} Axiom of the empty set: $(\\forall x)\\qsep \\lnot(x\\in\\emptyset)$.\n\\end{axioms}\nThe axiom of the empty set, as anyone should expect, simply states that $\\emptyset$ has no elements. Furthermore, it follows from \\ref{extensionality} that any element verifying this property is equal to $\\emptyset$.\n\n\\begin{axioms}\n\\item Axiom of union: $(\\forall X)(\\exists U)(\\forall x)(\\forall a)\\qsep (x\\in X \\land a \\in x) \\limplies a\\in U$.\n\\label{union}\n\\end{axioms}\nThe axiom of union states that, given any set $X$, there exists a set $U$ containing all the elements of the sets in $X$.\nInformally, this means that, given any collection of sets $X$, there exists a set that contains the union of all the sets in $X$.\n\n\\begin{axioms}\n\\item \\label{infinity} Axiom of infinity: $(\\exists X)\\qsep \\emptyset \\in X \\land (\\forall x)\\qsep$\\\\\n$x\\in X \\limplies (\\exists y)(y \\in X \\land (\\forall a)\\qsep a\\in y \\liff (a = x \\lor (\\forall b)(b\\in a \\liff b = x)))$.\n\\end{axioms}\nI know what you are thinking and you are right; the axiom of infinity is a mess.\nThere are simpler ways to present this axiom, but this is by far the most formal of all, and, you know, if we are going to do a formal treatment of set theory, let us do it properly! You and I are warriors, not soldiers.\n\nIf you take your time to analyse it, you will see that it postulates the existence of a set $X$ having $\\emptyset \\in X$ and verifying, for every $x\\in X$, $x\\cup \\{x\\} \\in X$.\nNotice that we have not yet defined what $x\\cup \\{x\\}$ means in $\\mathsf{ZFC}$, but we have already done an informal treatment of set theory and you should know that, with that, I (informally) mean ``the set having as elements $x$ and a set that only has $x$ as an element''.\n\nYou may wonder what the point of this axiom is. Turns out this will enable us to define the natural numbers and, from there on, the rationals, the reals\\ldots you name it! \n\n\\begin{axioms}\n\\item Power set axiom: $(\\forall x)(\\exists P)(\\forall a)\\qsep a\\subseteq x \\limplies a\\in P$.\n\\label{powerset}\n\\end{axioms}\n\nThe power set axiom --- which, after going through the axiom of infinity, looks ridiculously simple --- simply establishes the existence, for any set $x$, of a set containing each subset of $x$, i.e., its power set.\n\n\\begin{axioms}\n\\item \\label{regularity} Axiom of regularity: $(\\forall x)\\qsep \\lnot(x=\\emptyset) \\limplies (\\exists y)(y \\in x \\land \\lnot (\\exists z) (z\\in y \\land z \\in x))$.\n\\end{axioms}\nThis axioms guarantees the existence in any non-empty set $x$ of an element $y$ containing no elements of $x$. To put it in perhaps clearer terms, it says that no set $x$ can only consist of sets having elements of $x$.\n\nThe best way in which you can see why the axiom of regularity need be true is by trying to construct a set contradicting it.\n\n\\begin{axioms}\n\\item \\label{replacement} Axiom schema of replacement:\nfor any formula $\\psi$ in which there are only free occurrences of $x$ and $y$ and in which there are no quantifications over $X$ and $Y$,\n$(\\forall x)(\\exists! y) \\psi \\limplies (\\forall X)(\\exists Y)(\\forall y)\\qsep y\\in Y \\liff (\\exists x)(x\\in X \\land \\psi)$.\n\\end{axioms}\nWhat the axiom of replacement tells us is that, if we are given a formula\\footnote{We are using the informal notation $\\psi(x,y)$ to represent an arbitrary formula $\\psi$ having two free variables $x$ and $y$.} $\\psi(x,y)$ that, for each value of $x$, is true for one unique value of $y$ --- in other words, if $\\psi(x,y)$ behaves like a function, --- then, given any set $X$, there exists a set $Y$ containing, exclusively, all the elements $y$ for which there exists an $x\\in X$ verifying $\\psi(x,y)$.\n\nPutting it simpler terms, this means that if a ``function'' $f$ taking any set $x$ to a set $y$ can be expressed as a formula $A(x,y)$ that is true if and only if $f(x) = y$, then, for any set $X$, there exists a set containing the image of $X$ under $f$.\nOf course, these formulas are not functions within set theory: a function within $\\mathsf{ZFC}$ need be an object of $\\mathsf{ZFC}$ and, therefore, a set, not a formula!\nWe will later on define the concept of a function in $\\mathsf{ZFC}$ in a precise and formal manner. \n\n\\begin{axioms}\n\\item \\label{choice} Axiom of choice: $(\\forall X) \\qsep (\\forall x)(x\\in X \\limplies (\\lnot(x = \\emptyset) \\land$\\\\\n\\hspace*{1em}$(\\forall y)\\qsep y \\in X \\land\\lnot(x = y) \\limplies \\lnot(\\exists a)\\qsep a \\in x \\land a \\in y))\\limplies$\\\\\n$((\\exists S)(\\forall s)\\qsep s\\in S \\limplies ((\\exists x)\\qsep x\\in X \\land s \\in x \\land(\\forall z)((\\lnot (z=a)\\land z\\in S )\\limplies \\lnot (z \\in x))))$.\n\\end{axioms}\nWhat this famous and controversial axiom of choice is telling us is something that is, well, obvious.\nIt is simply stating that, given any collection $X$ of non-empty sets that have no elements in common, there exists a set $S$ containing one and only one element from every set in $X$.\nThis assumption is extremely natural and so are the consequences that are derived from it --- at least from my personal perspective --- but the poor axiom of choice is rejected by some people (see \\cite{Brown} for reference).\nPlease, give him some love and say with me ``I choose choice!''.\n\nBy the way, if you were, by any chance, hoping that there could be a way to prove that either the axiom of choice or its negations would make $\\mathsf{ZF}$ inconsistent and thus settle this debate of choice versus no choice once and for all\\ldots I have bad news. The axiom of choice is independent from $\\mathsf{ZF}$ and, if $\\mathsf{ZF}$ is consistent, so is $\\mathsf{ZF}$ with the axiom of choice and so is $\\mathsf{ZF}$ with the negation of the axiom of choice. So, at the end of the day, accepting or negating the axiom of choice is not a mathematical issue, but a philosophical one. This is one of those things that makes mathematics look more like a religion than like a science.\n\nWe shall now introduce a pretty solid collection of definitions and results. All those definitions and results that follow are done within $\\mathsf{ZFC}$ unless otherwise stated.\n\\end{para}\n\n\\begin{proposition}\n\\label{setelementary}\nThe following elementary properties of sets are true:\n\\begin{statements}\n\\item Let $X$ be a set. Both $X$ and $\\emptyset$ are subsets of $X$.\n\\item \\label{doubleinclussion} Two sets $X$ and $Y$ satisfy $X = Y$ if and only if $X\\subseteq Y$ and $Y\\subseteq X$.\n\\end{statements}\n\\label{<+label+>}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{parlist}\n\\item It is obvious that $X\\subseteq X$. In regard to $\\emptyset$, for it to be a subset of $X$, the formula $(\\forall x)(x\\in \\emptyset \\limplies x \\in X)$ needs to be satisfied.\nSince, according to \\ref{emptyset}, no set $x$ can verify $x\\in \\emptyset$, the formula $x\\in \\emptyset \\limplies x \\in X$ is satisfied for any $x$ and $X$. Thus, the empty set is a subset of any set.\n\n\\item Immediate from \\ref{extensionality} and from the definition of $\\subseteq$.\n\\end{parlist}\n\\end{proof}\n\n\n\\begin{theorem}[Schema of specification]\nLet $\\phi$ be a formula in the language of set theory with a single free variable. Given any set $X$, there exist the subset $Y\\subseteq X$ of elements $x\\in X$ verifying $\\phi(x)$.\nSuch a set is described using \\emph{set-builder notation}: $Y = \\{x\\in X \\mid \\phi(x)\\}$.\n\\label{specification}\n\\end{theorem}\n\n\\begin{proof}\nIf there are no elements $x\\in X$ satisfying $\\phi(x)$, then $Y = \\emptyset$, which certainly exists.\n\nLet us then assume the existence of an element $y_0 \\in Y$. We can consider the formula $\\psi(x,y)$ given by\n\\[ (\\phi(x) \\land y = x) \\lor (\\lnot \\phi(x) \\land y = y_0).\\]\nIt is clear that, for any set $x$, there exists a unique $y$ satisfying $\\psi(x,y)$: if $\\phi(x)$ holds, that $y$ is $x$ itself, whereas, if it does not, that $y$ is $y_0$.\nThus, we can apply \\ref{replacement} to conclude that the collection $Y'$ of all the elements $y$ for which there exists an $x\\in X$ verifying $\\psi(x,y)$ is a set. Furthermore, this set is $Y$. Let us prove it by double inclusion, i.e., using \\ref{setelementary}\\ref{doubleinclussion}.\n\nGiven any $y\\in Y$, the formula $\\psi(y,y)$ holds and --- since $Y\\subseteq X$ and, therefore, $y\\in X$ --- we have $y \\in Y'$, which shows that $Y\\subseteq Y'$.\nConversely, given any $y'\\in Y'$, we there know to exist an $x\\in X$ such that $\\psi(x,y')$ holds.\nIf $\\phi(x)$ is satisfied, then $y'=x$, so $y'\\in Y$.\nIf $\\phi(x)$ is not satisfied, then $y' = y_0$, which, by hypothesis, belongs to $Y$.\nIn either case, $y'\\in Y$, which shows that $Y'\\subseteq Y$.\n\\end{proof}\n\n\\begin{para}\nDo you remember when back in \\ref{logifail} we said that, in modern day set theory, we could identify predicates with sets --- just as people wanted to do in the early days --- provided we did it with care?\nThe scheme of specification has just made that notion precise: given any set $X$ we can identify each unary predicate $\\phi$ with the set $\\{x \\in X \\mid \\phi(x)\\}$.\nWhat makes this approach different from the one that led to Russel's paradox is our requiring the ``domain'' over which we define $\\phi$ to be a set complying with the axioms of $\\mathsf{ZFC}$, and that enables us to escape from any paradox.\n\nWe will shortly analyse some details regarding the schema of specification  and how it avoids the paradoxes of primitive set theory.\n\\end{para}\n\n\\begin{para}[Definition-Proposition]\n\\label{setops}\nLet $X$ and $Y$ be any two arbitrary sets.\n\\begin{statements}\n\\item \\label{setunion} There exists a set $\\cup X$ containing, exclusively, all the elements of the sets contained in $X$. This set is known as the \\emph{union} of the elements of $X$.\n\\item There exists a set $\\cap X$ containing, exclusively, the elements that belong to all the sets contained in $X$. This set is called the \\emph{intersection} of the elements of $X$.\n\\item There exists a set $X\\setminus Y$ containing, exclusively, the elements of $X$ that do not belong to $Y$. The set $X\\setminus Y$ is known as the \\emph{difference} of $X$ and $Y$. In particular, if $Y\\subseteq X$, the set $X\\setminus Y$ is said to be the \\emph{complement} of $Y$ in $X$.\n\\item There exists a set $\\mathcal{P}(X)$ containing, exclusively, all the subsets of $X$. This set is known as the \\emph{power set} of $X$.\n\\end{statements}\n\\label{<+label+>}\n\\end{para}\n\n\\begin{proof}\nAccording to \\ref{union}, there exists a set $U$ that contains all the elements of the sets contained in $X$. Applying \\ref{specification}, it follows that\n\\begin{gather*}\n\\cup X = \\{u \\in U \\mid (\\exists x \\in X) u \\in x\\},\\\\\n\\cap X = \\{u \\in U \\mid (\\forall x \\in X) u \\in X\\},\n\\end{gather*}\n\nIn regard to $X\\setminus Y$, it suffices to use \\ref{specification} again and consider $X\\setminus Y = \\{x\\in X \\mid x\\not\\in Y\\}$.\n\nLastly, regarding the power set, \\ref{powerset} guarantees the existence of a set $P$ containing every subset of $X$, so we just need to apply \\ref{specification} once more and take\n\\[\\mathcal{P}(X) = \\{p \\in P \\mid p \\subseteq X\\}.\\]\n\\end{proof}\n\n\\begin{proposition}\nAny element $a$ of a set $X$ is a set.\n\\label{elisset}\n\\end{proposition}\n\n\\begin{proof}\nIt suffices to apply \\ref{specification} and \\ref{setops}\\ref{setunion} to conclude that $a = \\cup \\{x \\in X \\mid x = a\\}$ is a set.\n\\end{proof}\n\n\\begin{proposition}[Pairing]\nLet $a$ and $b$ be sets. The set $\\{a,b\\}$ containing, exclusively, the elements $a$ and $b$ exists. In particular, if $a=b$, the \\emph{singleton} $\\{a\\}$ exists.\n\\label{pairing}\n\\end{proposition}\n\n\\begin{proof}\nAccording to \\ref{infinity}, we there know to exist a set that contains, in particular, the element $X = \\{\\emptyset, \\{\\emptyset\\}\\}$. Thus, using \\ref{elisset}, we know $X$ to be a set.\nWe can then consider the formula $\\psi(x,y)$ defined by\n\\[ (x = \\emptyset \\land y = a) \\lor (x = \\{\\emptyset\\} \\land y = b) \\lor (\\lnot (x \\in X) \\limplies x = y).\\]\nA direct application of the axiom schema of replacement \\ref{replacement} shows that the set $Y$ of elements $y$ for which there exists an $x\\in X$ verifying $\\psi(x,y)$ is a set. Since $Y = \\{a,b\\}$, we have shown the set $\\{a,b\\}$ to exist.\n\\end{proof}\n\n\\begin{para}[Notation]\nLet $X$ and $Y$ be sets. By \\ref{pairing}, $\\{X,Y\\}$ is a set. We define $X\\cup Y = \\cup\\{X,Y\\}$ and $X\\cap Y = \\cap \\{X\\cap Y\\}$. \nIf $X\\cap Y = \\emptyset$, we say that $X$ and $Y$ are \\emph{disjoint}. Furthermore, given any collection $C$ of sets, we say that the sets in $C$ are \\emph{pairwise disjoint} if, for any $X,Y\\in C$ with $X\\neq Y$, the sets $X$ and $Y$ are disjoint.\n\n\nLet $n$ be a natural number and let $X_1,\\ldots,X_n$ be sets. Through a recursive application of \\ref{pairing} and \\ref{setops}\\ref{setunion}, we know the set $X$ with elements $X_1,\\ldots, X_n$ to exist. This set is represented as $\\{X_1,\\ldots,X_n\\}$.\n\\end{para}\n\n\\begin{para}\nNow that we know singletons to exist, we can add a final touch on our discussion on the scheme of specification and Russel's paradox.\n\nWe can illustrate the robustness of our system with a simple example.\nIf we consider \\emph{any} set $X$ and try to recreate Russel's paradox by defining the set $R = \\{x \\in X \\mid x\\not\\in x\\}$, we would have\n\\[ R \\in R \\iff (R \\in X \\land R \\not \\in R).\\]\nDoes it look suspicious? It is actually harmless.\nLet $A$ be any set. Applying the axiom of regularity \\ref{regularity} to $\\{A\\}$, we know that $A \\not\\in A$. Therefore, it is clear that $R = X$ and, therefore, that $R\\not\\in X$.\nIt then follows that both sides of the equivalence are false: everything fits nicely and we are paradox-free.\n\nYou may then wonder: and what if I take $X$ to be a ``universe'' set containing all the sets in $\\mathsf{ZFC}$? Well, it is immediate from the axiom of regularity \\ref{regularity} that such a set cannot exist in $\\mathsf{ZFC}$, so there is nothing to worry about.\n\\end{para}\n\n\\begin{definition}\nLet $x$ and $y$ be sets. The \\emph{ordered pair} with \\emph{first coordinate} $x$ and \\emph{second coordinate} $y$ is the set\n\\[ (x,y) = \\{ \\{x\\}, \\{x,y\\} \\}.\\]\nObviously, $(x,y) \\neq (y,x)$ unless $y = x$, hence the name ordered pair.\nMoreover, if $x_1,x_2,y_1,y_2$ are some arbitrary sets, $(x_1,y_1) = (x_2,y_2)$ if and only if $x_1 = x_2$ and $y_1 = y_2$.\n\nLet us assume that, for some sets $X$ and $Y$, $x\\in X$ and $y\\in Y$. The ordered pair $(x,y)$ belongs to the set $\\mathcal{P}(X\\cup Y)$, so we can define the \\emph{binary cartesian product} of $X$ and $Y$ as the set\n\\[ X\\times Y = \\{p \\in \\mathcal{P}(X\\cup Y) \\mid (\\exists x)(\\exists y)\\qsep x\\in X \\land y\\in Y \\land p = (x,y)\\}.\\]\nTo put it simply, $X\\times Y$ is the set of all ordered pairs $(x,y)$ with $x\\in X$ and $y\\in Y$.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{para}\nJust as every unary predicate (unary relation) on a set $X$ was characterised by a subset of $X$, every binary relation on two sets $X$ and $Y$ will be characterised by a subset of $X\\times Y$.\nThe ability to work with relations in $\\mathsf{ZFC}$ will enable us to introduce functions as mere set-theoretical objects, and, in return, functions will enable us --- among many other things --- to define $n$-ary cartesian products and, therefore, to introduce $n$-ary relations in set theory.\n\\end{para}\n\n\\begin{definition}\n\\label{binrel}\nLet $X$ and $Y$ be sets. A \\emph{binary relation} over the sets $X$ and $Y$ is a subset $R$ of the cartesian product $X\\times Y$.\nIf a subset $R\\subseteq X\\times Y$ is being regarded as a binary relation and not as a mere subset, it is customary to write $xRy$ in lieu of $(x,y) \\in R$.\n\nAny formula $\\phi$ with a free variable can induce a binary relation according to \\ref{specification}, for it suffices to consider $R = \\{(x,y)\\in X\\times Y \\mid \\phi ( ( x,y) )\\}$.\nThis kind of definition is often done in an implicit manner as ``let $R$ be the relation on $X$ and $Y$ that is satisfied if and only if $\\phi( (x,y))$''.\n\nVery often, relations will be subsets of $X\\times X$. In this case, we say that $R$ is a binary relation over $X$: it would be redundant to say that it is a binary relation over $X$ and $X$.\n\nWriting $xRy$ might look a little bit confusing, that is why binary relations are often represented by fancy symbols such as $\\sim$ or $\\equiv$.\nIn addition, some relations may use a more complex notational artefact than just the structure ``element symbol element''.\nAs always, if there is something inexact and non-universal about mathematics, that is its notation! \n\n\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{example}\n\\begin{parlist}\n\\item Let $X$ be any set.\nThe empty relation $R = \\emptyset$ is a binary relation over $X$.\nIt is, obviously, not satisfied by any $(a,b)\\in X\\times X$.\n\\item Let $X$ be any set.\nThe subset $R = \\{(a,b)\\in X\\times X \\mid a = b\\}$ is a binary relation over $X$.\nThe relation $R$ can equivalently be defined as the binary relation on $X$ such that $aRb$ if and only if $a= b$.\n\\item Let $X$ and $Y$ be sets.\nThe set $R = X\\times Y$ is a binary relation over $X$ and $Y$.\nOf course, any $x\\in X$ and $y\\in Y$ verify $xRy$.\n\\end{parlist}\n\\end{example}\n\n\\begin{definition}\nA \\emph{function} $f$ from a set $X$ to a set $Y$ is a binary relation over $X$ and $Y$ such that, for every $x\\in X$, there exists a unique $y\\in Y$ verifying $xfy$. Instead of writing $xfy$, we will use $f(x) = y$.\nThe fact that $f$ is a function from $X$ to $Y$ is denoted by $f:X\\longrightarrow Y$. In addition, $f(x) = y$ can also be written as $f:x\\longmapsto y$.\n\nGiven $f:X\\longrightarrow Y$, the set $X$ is said to be the \\emph{domain} of $f$ ($X = \\op{dom} f$) whereas $Y$ is known as the \\emph{codomain} of the function. The \\emph{image} $\\op{im} f$ of $f$ is the subset of $Y$ containing the elements $y\\in Y$ for which there exists an $x\\in X$ such that $f(x) = y$, i.e.,\n\\[\\op{im} f = \\{y\\in Y \\mid (\\exists x \\in X)(y = f(x)\\},\\]\nwhere, as in \\ref[prel]{pseudoquan}, $(\\exists x \\in X)\\theta(x)$ means $(\\exists x)(x\\in X \\limplies \\theta(x))$.\n\n\nWe say that $f$ is injective if, for every $y\\in \\op{im}f$, there exists a unique $x$ such that $f(x) = y$, or if, equivalently, for every $a,b\\in X$, $f(a) = f(b)$ implies $a = b$.\nIn addition, $f$ is said to be \\emph{surjective} if $\\op{im} f = Y$.\nIf a function is both injective and surjective, it is said to be \\emph{bijective}.\n\nGiven any $A\\subseteq X$, the \\emph{image} under $f$ of $A$ is the set\n\\[ f[A] = \\{y \\in Y \\mid (\\exists a \\in A)\\qsep f(a) = y\\}.\\]\nNotice how $\\op{im} f = f[X]$.\nSimilarly, given any $B\\subseteq Y$, the \\emph{inverse image} of $B$ under $f$ is the set\n\\[ f^{-1}[B]  = \\{x\\in X \\mid f(x) \\in B\\}.\\]\n\nIf $f$ is injective, we can define a function $f^{-1}: \\op{im} f\\longrightarrow X$ mapping every $y\\in Y$ to $\\cup f^{-1}[\\{y\\}] \\in X$, i.e., to the only element $x\\in X$ satisfying $f(x) = y$.\n\nGiven any set $X$, the \\emph{identity} function on $X$ is the function $\\op{id}_X :X\\longrightarrow X$ taking any $x\\in X$ to itself: $f(x) = x$.\n\nGiven any two functions $f:X\\longrightarrow Y$ and $g:Y\\longrightarrow Z$, the \\emph{composition} of $f$ with $g$ is the function\n\\begin{align*}\ng\\circ f: X &\\longrightarrow Z \\\\\nx &\\longmapsto g\\left( f(x) \\right).\n\\end{align*}\n\nLastly, given a subset $A\\subseteq X$ and a function $f:X\\longrightarrow Y$, we define the \\emph{restriction} of $f$ to $A$ as the function\n\\begin{align*}\nf\\vert_A : A &\\longrightarrow Y\\\\\na &\\longmapsto f(a).\n\\end{align*}\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{proposition}\nLet $f:X\\longrightarrow Y$ and $g:Y\\longrightarrow Z$ be functions.\n\\begin{statements}\n\\item The function $g\\circ f$ is injective only if $f$ is injective.\n\\item The function $g\\circ f$ is surjective only if $g$ is surjective.\n\\end{statements}\n\\label{compinjsur}\n\\end{proposition}\n\n\\begin{proof}\nWe will prove the contrapositive of each of the statements.\n\n\\begin{parlist}\n\\item If $f$ is not injective, there exist $a,b\\in X$ such that $a\\neq b$ and $f(a) = f(b)$; consequently, $g\\circ f(a) = g \\circ f(b)$. Thus, $g\\circ f$ is not injective.\n\\item Analogously, if $g$ is not surjective, no $y\\in Y$ satisfies $f(y) = z_0$ for some $z_0\\in Z$. Thus, given any $x\\in X$, since $f(x) \\in Y$, we have $g\\circ f(x) \\neq z_0$.\n\\end{parlist}\n\\end{proof}\n\n\\begin{proposition}\nLet $f: X\\longrightarrow Y$. The function $f$ is bijective if and only if there exists a function $g:Y\\longrightarrow X$ such that $f\\circ g = \\op{id}_X$ and $g\\circ f =\\op{id}_Y$.\n\\label{<+label+>}\n\\end{proposition}\n\n\\begin{proof}\nIf $f$ is bijective, the function $g$ we are looking for is $f^{-1} : \\op{Im} f = Y \\longrightarrow X$. It is immediate that $f \\circ f^{-1} = \\op{id}_X$ and that $f^{-1}\\circ f = \\op{id}_Y$.\n\nConversely, since both $\\op{id}_X = f\\circ g$ and $\\op{id}_Y = g\\circ f$ are bijective, the result follows from \\ref{compinjsur}.\n\\end{proof}\n\n\n\\begin{para}[Definition-proposition]\nWe say that a set $X$ is \\emph{inductive} if it verifies the formula $\\Omega(X)$ given by\n\\[ \\emptyset \\in X \\land (\\forall x)(x\\in X \\limplies x \\cup \\{x\\} \\in X),\\]\nwhere, for the sake of clarity, we have used $x\\cup\\{x\\}\\in X$ in lieu of\n\\[(\\exists y)\\qsep y \\in X \\land (\\forall t)\\qsep t\\in y\\liff(t = x \\lor (\\forall s)(s\\in t \\liff s = x )).\\]\nThere exists a \\emph{minimal} inductive set $\\omega$, i.e., an inductive set that is included in every inductive set.\n\\label{<+label+>}\n\\end{para}\n\n\\begin{proof}\nBy \\ref{infinity}, we know an inductive set $V$ to exist. The set $\\omega$ can be constructed using \\ref{specification} as\n\\[ \\omega = \\{v\\in V\\mid (\\forall X)(\\Omega(X)\\limplies v\\in X)\\}.\\]\nIn plain English, $\\omega$ is the set containing, exclusively, the elements that are common to all inductive sets.\nInformally, we could have defined it as the ``intersection of all the inductive sets''; nonetheless, since we have not proven the existence of such thing as a set of all inductive sets, we have had to create this custom definition.\n\nThe set $\\omega$ is clearly inductive. On the one hand, any inductive set $X$ verifies $\\emptyset \\in X$, so $\\emptyset\\in \\omega$.\nOn the other hand, if $v\\in\\omega$, then $v$ belongs to any inductive set $X$, and, by definition, so does $v\\cup\\{v\\}$. Thus, $v\\cup\\{v\\}\\in \\omega$.\n\nLastly, it is trivial that $\\omega$ is included in any inductive set for the elements in $\\omega$ belong, by definition, to any inductive set.\n\\end{proof}\n\n\n\\begin{para}\nIf set theory has any intention of becoming a foundational system for mathematics, it better let us work with natural numbers!\nNow, how could we possibly implement natural numbers in $\\mathsf{ZFC}$? How could we construct a set of natural numbers?\nThe answer is, surprise surprise, we have already done it! The set $\\omega$ is the set we have been looking for! Informally, if we let $0 = \\emptyset\\in \\omega$, we can define\n\\[ 1 = \\{0\\}\\in \\omega,\\qquad 2 = \\{0,1\\} \\in \\omega, \\qquad 3 = \\{0,1,2\\}\\in \\omega,\\]\nand so on. In general, given any natural number $n$ representing a set $n\\in \\omega$, we define its successor as $s(n) = n \\cup \\{n\\} = \\{1,\\ldots,n\\}\\in \\omega$. \n\nIn this construction, the set of natural numbers would be $\\mathbb{N} = \\omega \\setminus \\{\\emptyset\\}$.\n\nI know. This looks weird. Having $4\\subseteq 5$ seems like an odd property; nonetheless, as you will later see, these oddities will not have any visible effect in our daily-life arithmetic.\nIn fact, these very oddities will prove themselves very useful in enabling us to properly incorporate number systems into our beautiful foundational theory.\n\nFrom now on, unless otherwise stated, we will use Arabic numerals in order to refer to their corresponding elements in $\\omega$. This is just notation.\n\nShortly, we will define the basic operations and relations in $\\omega$, but we need to go through a very significant result before we can get there.\n\\end{para}\n\n\\begin{theorem}[Principle of recursive definition]\nLet $X$ be a set with $a \\in X$. Let $u:X\\longrightarrow X$ be a function. There exists a unique function $f:\\omega \\longrightarrow X$ verifying $f(0) = a$ and $f(s(n)) = u(f(n))$.\n\\label{<+label+>}\n\\end{theorem}\n\n\\begin{proof}\nWe will prove this theorem by explicitly constructing $f$ as a set of ordered pairs in $\\omega\\times X$.\n\nFor that purpose, let us consider the set $F$ of all subsets $S\\subseteq \\omega \\times X$ such that $(0,a)\\in S$ and such that, whenever $(n,x)\\in S$, then $(s(n),u(x)) \\in S$.\nThe set $F$ is clearly non-empty for $\\omega \\times X\\in F$.\n\nWe now take $f = \\cap F$.\nIt should be clear that $f\\in F$ and that $f$ is included in every element of $f$.\nThus, if we showed $f$ to be a function, we would have proved the result.\nThe reasoning behind this is simple.\nIf there existed another function $g$ verifying the conditions of the theorem, $g\\in F$ and, therefore, $f\\subseteq g$; nonetheless, assuming that $f$ is a function from $\\omega$, $g$ can only be a function from $\\omega$ if it is equal to $f$, because if it contained an additional ordered pair, we would have, for a certain $n\\in \\omega$ and $x,y\\in X$ with $x\\neq y$, both $(n,x)\\in g$ and $(n,y)\\in g$, which would mean that $g$ would not be a function.\n\nLet us then show $f$ to be function! We can consider the set $N\\subseteq \\omega$ of elements $n\\in \\omega$ for which there exists a unique ordered pair in $f$ with first coordinate $n$.\n\nIf we had $0\\not\\in N$, then there would exist an element of the form $(0,b)\\in f$ with $b\\neq a$. Nonetheless, then $f' = f\\setminus \\{(0,b)\\}\\in F$ with $f'\\subset f$, which would contradict our hypothesis that $f = \\cap F$.\nAnalogously, If we had, for some $n\\in \\omega$, $n\\in N$ but $s(n)\\not\\in N$, then there would exist a unique $x\\in X$ such that $(n,x)\\in f$ and there would exist an $y \\in X$ distinct from $u(x)$ such that $(s(n), y)\\in f$.\nWere this the case, then it is trivial that $f\\setminus \\{(s(n),y)\\}\\in F$ and we would once again reach a contradiction.\n\nSince $\\omega$ is the smallest inductive set and we have shown that, for a set $N\\subseteq \\omega$, we have $0\\in N$ and, whenever $n\\in N$, $s(n) \\in N$, we can conclude \\emph{by induction} that $N = \\omega$. This completes the proof. \n\\end{proof}\n\n\\begin{definition}\nLet $m\\in \\omega$. Applying the principle of recursive definition, we can define two functions $s_m$ and $p_m$ from $\\omega$ to $\\omega$ verifying, on the one hand, $s_m(0) = m$ and $s_m(s(n)) = s(s_m(n))$, and, on the other hand, $p_m(0) = 0$ and $p_m(s(n)) = s_{p_m(n)}(n)$.\n\nThis enables us to define \\emph{addition} $+$ and \\emph{multiplication} $\\cdot$ in $\\omega$ as\n\\begin{align*}\n+:\\omega \\times \\omega & \\longrightarrow \\omega & \\cdot : \\omega \\times \\omega & \\longrightarrow \\omega \\\\\n(x,y) &\\longmapsto x+y = s_x(y), & (x,y) & \\longmapsto x\\cdot y = p_x(y),\n\\end{align*}\nwhere, of course, we have used infix notation.\n\nJust to complete our definitions in $\\omega$, let us the relation $\\leq$ in $\\omega$ as $x\\leq y$ if and only if $x\\in y$ or $x = y$. Analogously, we define a relation $<$ such that $x < y$ if and only if $x \\in y$. As was to be expected, if $x\\leq y$ we say that $x$ is \\emph{smaller than or equal to} $y$ and if $x < y$, it is said that $x$ is \\emph{smaller than} $y$. \n\\label{<+label+>}\n\\end{definition}\n\n\\begin{definition}\nLet $X$ be a set. An \\emph{internal $n$-ary law of composition} on $X$ is a function $*:\\times_{i=1}^n X \\longrightarrow X$. The adjective ``internal'' is often dropped. Furthermore, for binary laws of composition, the adjective ``binary'' is often omitted too.\nLaws of compositions are commonly referred to as operations.\n\nInfix notation is often used with laws of composition: thus, $*(x,y)$ is written as $x * y$. We say that a law of composition $*$ is\n\\begin{itemize}\n\\item \\emph{associative} if, for any $x,y,z\\in X$, we have $(x*y)*z = x * (y * z)$,\n\\item \\emph{commutative} if, for any $x,y \\in X$, we have $x * y = y * x$,\n\\item \\emph{left distributive} with respect to another law of composition $\\square$ if, for any $x,y,a\\in X$, $a * (x \\square y) = (a * x) \\square (a * y)$,\n\\item \\emph{right distributive} with respect to another law of composition $\\square$ if, for any $x,y,a\\in X$, $ (x \\square y) * a = (x * a) \\square (y * a)$,\n\\item and \\emph{distributive} with respect to another law of composition if it is both left distributive and right distributive.\n\\end{itemize}\nLaws of composition often use \\emph{additive notation} (i.e., use the symbol $+$ and infix notation) or \\emph{multiplicative notation} (i.e., use the symbol $\\cdot$ and infix notation). In multiplicative notation, the use of $\\cdot$ may be replaced by juxtaposition: thus, $xy$ would be read as $x\\cdot y$.\n\nClearly, the operations $+$ and $\\cdot$ that we have defined on $\\omega$ are laws of composition using, respectively, additive and multiplicative notation.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{lemma}\nLet $n\\in \\omega$. The following seemingly irrelevant statements are true:\n\\begin{statements}\n\\item \\label{wsubse} If $m\\in n$, then $n\\not\\subseteq m$. In other words, no element of $\\omega$ is a subset of any of its elements.\n\\item \\label{wtrans} The set $\\omega$ is transitive: if $m\\in n$, then $m\\subseteq n$.\n\\end{statements}\n\\label{lemmapeano}\n\\end{lemma}\n\n\\begin{proof}\n\\begin{parlist}\n\\item Let $N\\subseteq \\omega$ be the set of elements $n\\in\\omega$ such that, for any $m\\in n$, we have $n\\not\\subseteq m$. It is clear that $0 \\in N$ for $0 = \\emptyset$. In addition, if $n \\in N$, we can easily show that $s(n) = n \\cup \\{n\\}\\in N$.\n\nThe elements of $n \\cup \\{n\\}$ are those of $n$ and $n$ itself. Can $n\\cup\\{n\\}$ be a subset of $n$? For that to be the case, we would need to have $\\{n\\}\\subseteq n$ and, therefore, $n\\in n$, but, as $n\\in N$ and $n\\subseteq n$, it is clear that $n\\not\\in n$. Can $n\\cup \\{n\\}$ be a subset of $x\\in n$? Since $n\\subseteq n \\cup\\{n\\}$, if this were the casee, $n$ would also be a subset of $x$ thus contradicting the hypothesis that $n\\in N$. We can conclude that $s(n) \\in N$ and, by induction, that $N = \\omega$.\n\n\\item We proceed, again, inductively. Let $N\\subseteq\\omega$ be the set of elements $n$ for which the result holds.\nIt is out of question that $0\\in N$.\nIn addition, if we assume $n\\in N$, we can easily prove that $s(n)\\in N$.\nThe elements of $s(n)$ are $n$ and all the elements of $n$.\nClearly, since all the elements of $n$ belong to $s(n)$, we have $n\\subseteq s(n)$.\nMoreover, according to the inductive hypothesis, all the elements $x\\in n$ are subsets of $n$, and, since $n \\subseteq s(n)$, they must also be subsets of $s(n)$.\n\\end{parlist}\n\\end{proof}\n\n\n\\begin{theorem}\nLet us consider the interpretation of the formal system $\\mathsf{PA}$ of Peano Arithmetic using $\\mathbb{N}$ as domain and having $\\{\\emptyset\\} = 1$ as $\\und{1}$; the set-theoretic relation $=$ as $\\und{=}$; the set-theoretic function $s$ as $\\und{s}$, and the set-theoretic functions $+\\vert_{\\mathbb{N}\\times\\mathbb{N}}$ and $\\cdot\\vert_{\\mathbb{N}\\times\\mathbb{N}}$ as $\\und{+}$ and $\\und{\\cdot}$ respectively.\nThis interpretation is a model.\n\nConsequently, if $\\mathsf{ZFC}$ is consistent, so is $\\mathsf{PA}$.\n\\label{<+label+>}\n\\end{theorem}\n\n\\begin{proof}\nWe need to show that, in the interpretation of $\\mathsf{PA}$ that we have constructed, all the axioms are true.\nThe axioms of equality are clearly verified, so we can get to work with the remaining non-logical axioms.\n\nIt is trivial that \\ref{axpa1}, \\ref{axpa2}, \\ref{axpa3}, \\ref{axpa4} and \\ref{axpa5} are true by how we have defined the elements of the interpretation. Furthermore, the principle of mathematical induction captured in \\ref{axpa6} trivially holds by considering, for any property $\\phi(x)$, the set $\\{x\\in \\omega\\mid \\phi(x)\\}$ and noting that $\\omega$ is inductive.\n\nThe only axiom that remains to be shown to be true is \\ref{axpa1bis}.\nLet us assume that two elements $m,n\\in \\omega$ verify $s(m) = s(n)$.\nUnder these conditions,\n\\[ m\\in s(m) = s(n) = n \\cup \\{n\\} \\quad \\tx{and} \\quad n\\in s(n) = s(m) = m \\cup \\{m\\},\\]\nso either $m = n$ or both $m\\in n$ and $n\\in m$. In the latter case, we have $m\\in n \\in m$, but, applying \\ref{lemmapeano}\\ref{wtrans}, this implies that $n\\subseteq m$ and, therefore, yields a contradiction with \\ref{lemmapeano}\\ref{wsubse}.\n\\end{proof}\n\n\\begin{para}\nThe following statements about $\\omega$ can be shown to be true in any model of $\\mathsf{ZFC}$ in an identical way to their analogues in $\\mathbb{N}$:\n\\begin{axioms}[$\\omega$]\n\\item \\label{axw1} $(\\forall x\\in \\omega)\\qsep\\lnot(s(x) = 0)$.\n\\item \\label{axw2} $(\\forall x,y\\in \\omega)\\qsep s(x) = s(y) \\limplies x = y$.\n\\item \\label{axw3} $(\\forall x\\in \\omega)\\qsep x + 0 = x$.\n\\item \\label{axw4} $(\\forall x,y\\in \\omega)\\qsep x + s(y) = s(x+y)$.\n\\item \\label{axw5} $(\\forall x\\in \\omega)\\qsep x \\cdot 0 = 0$.\n\\item \\label{axw6} $(\\forall x,y\\in \\omega)\\qsep x \\cdot s(y) = x\\cdot y + x$.\n\\item \\label{axw7} $(\\forall A \\subseteq \\omega)\\qsep (0 \\in \\omega \\land  (\\forall n\\in \\omega) (s(n) \\in \\omega) \\limplies A = \\omega)$. \n\\end{axioms}\nIt goes without saying that \\ref{axw7} implies that any formula $P(x)$\nis true for any $x\\in \\omega$ if proved to hold for $x = 0$ and, given an arbitrary $n\\in \\omega$, for $x = s(n)$ assuming $P(n)$.\n\\end{para}\n\n\\begin{lemma}\nAssuming addition in $\\omega$ to be associative, the following statements about $\\omega$ are true:\n\\begin{statements}\n\\item \\label{xp0i0} $(\\forall x \\in \\omega)\\qsep 0 + x = 0$.\n\\item \\label{switchs} $(\\forall x,y\\in \\omega)\\qsep s(x) + y = s(x+y)$.\n\\end{statements}\n\\label{lemmaomplus}\n\\end{lemma}\n\n\\begin{proof}\n\\begin{parlist}\n\\item Let us show that $0 + n = 0$ for every $n\\in \\omega$ by induction on $n$.\nFor $n = 0$, the result is immediate from \\ref{axw3}.\nIf we now assume this property to hold for an arbitrary $n\\in \\omega$, it follows from \\ref{axw3} and \\ref{axw4} that it is verified by $s(n)$ as\n\\[ 0 + s(n) = 0 + s(n+0) = 0 + n + s(0) = n + s(0) = s(n).\\]\nThus, the result is true by the principle of mathematical induction, i.e., by \\ref{axw7}.\nNotice how we have also made an implicit use of the associativity hypothesis.\n\n\\item We shall prove that $s(x) + n = s(x+n)$ for any $x,n\\in \\omega$ using induction on $n$.\nThe result $n = 0$ is a direct consequence of \\ref{axw3}. Assuming it to hold for an arbitrary $n\\in \\omega$, we can deduce from \\ref{axw3} and \\ref{axw4} that\n\\begin{align*}\ns(x) + s(n) &= s(x) + s(n+0) = s(x) + n + s(0) = s(x+n) + s(0) \\\\\n&= (x+s(n)) + s(0) = s( (x+s(n)) + 0) = s(x+s(n)),\n\\end{align*}\nand, therefore, the result is true by induction.\n\\end{parlist}\n\\end{proof}\n\n\\begin{proposition}\nAddition $+$ on $\\omega$ is associative and commutative.\n\\end{proposition}\n\n\\begin{proof}\nWe shall first prove associativity: we will prove, by induction on $n\\in \\omega$, that $(x+y)+n = x + (y + n)$. For $n=0$, the result is obvious since, according to \\ref{axw3},\n\\[ (x+y) + 0 = x+ y = x + (y + 0).\\]\nLet us then assume associativity to hold for an arbitrary $n\\in \\omega$. Regarding $s(n)$, the inductive hypothesis together with a repeated application of \\ref{axw4} yields\n\\begin{align*}\n(x+y) + s(n) &= s( (x+y) + n ) = s(x + (y + n)) = x + s(y+n) \\\\\n&= x + (y+ s(n)).\n\\end{align*}\n\nNow that we have associativity assured, let us deal with commutativity. We will show that any $x,n\\in \\omega$ verify $x+n = n+x$ using, once again, induction on $n$. The property is obvious for $n=0$ as $x + 0 = x$ and $0 + x = x$. These equalities are direct applications of \\ref{axw3} and \\ref{lemmaomplus}\\ref{xp0i0}.\nAssuming as inductive hypothesis that $x+n = n+x$, we have\n\\[ x+ s(n) = s(x+n) = s(n+x) = s(n) + x.\\]\nThe fact that $s(n+x) = s(n) + x$ was shown in \\ref{lemmaomplus}\\ref{switchs}. \n\\end{proof}\n\n\\begin{lemma}\nThe following statements about $\\omega$ are true:\n\\begin{statements}\n\\item \\label{lemmaw0x} $(\\forall x \\in \\omega)\\qsep 0 \\cdot x = 0$.\n\\item \\label{lemmawps} $(\\forall x,y\\in \\omega)\\qsep s(x) \\cdot y = x \\cdot y + y$.\n\\end{statements}\n\\label{lemmawprod}\n\\end{lemma}\n\n\\begin{proof}\n\\begin{parlist}\n\\item As you should have expected, we proceed by induction on $x$. It is clear that $0\\cdot 0 = 0$ from \\ref{axw5}. If we now assume the result to hold for an arbitrary $x$, it follows from \\ref{axw6} and \\ref{axw3} that\n\\[ 0 \\cdot s(x) = 0\\cdot x + 0 = 0 + 0 = 0.\\]\n\n\\item Once again, we proceed by induction on $y$. The result is immediate for $y = 0$ and, assuming it to hold for an arbitrary $y\\in \\omega$, we have\n\\[ s(x) \\cdot s(y) = s(x) \\cdot y + s(x) = x\\cdot y + y + s(x) = x \\cdot s(y) + s(y),\\]\nwhich shows that the result holds for $s(y)$.\n\\end{parlist}\n\\end{proof}\n\n\\begin{proposition}\nMultiplication $\\cdot$ on $\\omega$ is distributive over addition, associative and commutative.\n\\label{<+label+>}\n\\end{proposition}\n\n\\begin{proof}\nWe will first prove left distributivity and use it in the proof of associativity and commutativity.\nThen, right distributivity will follow from commutativity.\n\nWe need to show that, for every $n,x,y\\in \\omega$, we have $n\\cdot (x+y) = n\\cdot x + n\\cdot y$.\nAs our notation suggests, we will proceed by induction on $n$. Using \\ref{lemmawprod}\\ref{lemmaw0x}, the base case $n=0$ for distributivity is trivial as $0\\cdot (x+y) = 0 = 0\\cdot x + 0\\cdot y$.\nAssuming left distributivity to hold for an arbitrary $n\\in \\omega$, we have\n\\begin{align*}\ns(n) \\cdot (x + y) &= n\\cdot(x+y) + (x+y) = n\\cdot x + n\\cdot y + x + y \\\\\n&= s(n) \\cdot x + s(n) \\cdot (y),\n\\end{align*}\nwhere we have made implicit use of properties such as the associativity and commutativity of addition, \\ref{lemmawprod}\\ref{lemmawps} and \\ref{axw6}.\n\nIn regard to associativity, let us show that $x\\cdot(y \\cdot n) = (x\\cdot y) \\cdot n$ by induction on $n$. For $n=0$, it follows from \\ref{axw5} that \n\\[ x \\cdot (y \\cdot 0) = x\\cdot 0 = 0 = (x\\cdot y)\\cdot 0.\\]\nAssuming associativity to hold for an arbitrary value of $n\\in \\omega$, we have, using left distributivity \n\\begin{align*}\nx\\cdot (y\\cdot s(n) ) &= x\\cdot (y \\cdot n + y) = x \\cdot (y \\cdot n) + x \\cdot y = (x\\cdot y)\\cdot n + x\\cdot y \\\\\n&= (x\\cdot y) \\cdot s(n),\n\\end{align*}\nwhere we have also used \\ref{axw6}.\n\nLastly, regarding commutativity, let us prove that $x \\cdot n = n \\cdot x$ for any by induction on $n$. The result is trivial for $n = 0$ and, assuming it to hold for an arbitrary $n$,\n\\[ x \\cdot s(n) = x \\cdot n + x = n \\cdot x + x = s(n) \\cdot x,\\]\nwhere we have made use of \\ref{axw6} and \\ref{lemmawprod}\\ref{lemmawps}.\n\\end{proof}\n\n\\begin{para}\nWhat we have just done is quite significant. We have proven some facts about $+$ and $\\cdot$ without making any direct reference to the way in which they are defined: we have only used a collection of assumptions.\n\nWhat we have seen in these proofs is an example of how the axiomatic method is used ``in practice'' within $\\mathsf{ZFC}$.\n\\end{para}\n\n\\begin{definition}\nLet $I$ and $X$ be sets. A function $x:I\\longrightarrow X$ may be regarded as a \\emph{family} of elements of $X$ \\emph{indexed} by the set $I$.\nIf that is the case, given $i\\in I$, we write $x_i$ instead of $x(i)$ and we denote the function $x$ by $\\{x_i\\}_{i\\in I}$ or by $\\{x_i\\}_i$ for short. \nOn some occasions, the context might make it acceptable to also use the notation $\\{x_i\\}$.\n\nGiven a family $\\{X_i\\}_{i\\in I}$ of sets, its union is defined as $\\cup_{i\\in I} X_i = \\cup \\op{im} X$.\nIf $I\\neq \\emptyset$, we define its intersection as $\\cap_{i\\in I} X_i = \\cap \\op{Im} X$.\nLastly, the cartesian product of the family is the set $\\times_{i\\in I} X_i$ of families $\\{x_i\\}_{i\\in I}$ such that, for every $i\\in I$, $x_i \\in X_i$; or, in more symbolic terms,\n\\[ \\bigtimes_{i\\in I} X_i= \\left\\{x : I \\longrightarrow \\bigcup_{i\\in i} X_i \\mmid (\\forall i\\in\\{1,\\ldots,n)(x_i\\in X_i)\\right\\}.\\] \nIf the context allows for it, we may write $\\cup_i$, $\\cap_i$ and $\\times_i$ instead of $\\cup_{i\\in I}$, $\\cap_{i\\in I}$ and $\\times_{i\\in I}$.\nNaturally, a family $\\{X_i\\}_{i\\in I}$ of sets is said to be pairwise disjoint if, for any $i,j\\in I$ with $i\\neq j$, $X_i \\cap X_j = \\emptyset$. Notice how we are only requiring that $i\\neq j$, not that $X_i\\neq X_j$.\n\nIf the index set of a family $\\{x_i\\}$ is $\\mathbb{N}$, the family is said to be a \\emph{sequence} of elements in $X$.\n\nOf particular interest is the case where the index set is $I = \\{1,\\ldots,n\\}\\subseteq \\mathbb{N}$.\nIn this situation, a family $\\{x_i\\}_{i\\in I}$ is said to be an $n$-\\emph{tuple} and it is represented writing down its terms explicitly as $(x_1,\\ldots,x_n)$. Notice that tuples generalise ordered pairs. \nIf $(X_1,\\ldots,X_n)$ is a tuple of sets, we can write\n\\begin{gather*}\n\\bigcup_{i\\in I} X_i = \\bigcup_{i=1}^n X_i = X_1\\cup \\cdots \\cup X_n,\\qquad \\bigcap_{i\\in I} X_i = \\bigcap_{i=1}^n X_i = X_1 \\cap \\cdots \\cap X_n,\\\\\n\\bigtimes_{i\\in I} X_i = \\bigtimes_{i=1}^n X_i = X_1\\times\\cdots\\times X_n.\n\\end{gather*} \n\nGiven any tuple of sets $(X_1,\\ldots,X_n)$, its cartesian product $X_1\\times \\cdots\\times X_n$ is, according to the definition, the set of all tuples $(x_1,\\ldots,x_n)$ having, for every $i\\in\\{1,\\ldots,n\\}$, $x_i\\in X_i$. \nThe subsets of these cartesian products enable us to generalise the binary relations introduced in \\ref{binrel} to $n$-ary relations.\n\nWhile it might seem awkward to have two distinct objects representing the same concepts (2-tuples vs ordered pairs and 2-ary relations vs binary relations), this redundancy has no noticeable consequences in practice.\nThe different implementations of these concepts behave identically, so we might as well ignore their very nature.\nIn addition, we will use their different denominations interchangeably.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{definition}\nLet $X$ be a set. A binary relation $\\sim$ defined over $X$ is said to be an \\emph{equivalence relation} if it satisfies the following properties:\n\\begin{itemize}\n\\item Reflexivity: for every $a\\in X$, we have $a\\sim a$.\n\\item Symmetry: for every $a,b \\in X$, if $a\\sim b$ then $b\\sim a$.\n\\item Transitivity: for every $a,b,c\\in X$, if $a\\sim b$ and $b\\sim c$, then $a\\sim c$.\n\\end{itemize}\nGiven any $a\\in X$, we define its \\emph{equivalence class} as the set $[a] = \\{x\\in X \\mid a\\sim x\\}$.\nThe \\emph{quotient set} $X/{\\sim}$ of $X$ by $\\sim$ is the set of all the equivalence classes in $X$.\n\\label{<+label+>}\n\\end{definition}\n\n\\begin{definition}\nGiven a set $X$, a \\emph{partition} $P$ of $X$ is a collection of pairwise disjoint subsets of $X$ such that $\\cup P = X$. \n\\end{definition}\n\n\\begin{proposition}\nLet $X$ be a set.\n\\begin{statements}\n\\item If $\\sim$ is an equivalence relation over $X$, the quotient set $X/\\sim$ is a partition of $X$. \n\\item If $P$ is a partition of $X$, then the equivalence relation $\\sim$ defined in such a way that $x\\sim y$ if and only if $x$ and $y$ belong to the same set in $P$ is an equivalence relation. \n\\end{statements}\n\\end{proposition}\n\n\\begin{proof}\n\\begin{parlist}\n\\item It is clear from reflexivity that, given any $a\\in X$, we have $a\\in [a]$.\nThus, it is obvious that $\\cup (X/{\\sim}) = X$, so we just need to show that any two distinct equivalence classes are disjoint.\n\nLet $a,b\\in X$ and let us assume the existence of an element $x\\in [a]\\cap [b]$.\nUnder these assumptions, we know that $x\\sim a$ and $x\\sim b$ and, therefore, by transitivity, $a\\sim b$. Given any $x\\in [a]$, we will have $x\\sim a$, so, by transitivity, $x\\sim b$ and, therefore, $x\\in [b]$.\nThis proves that $[a]\\subseteq [b]$ and it can be shown analogously that $[b] \\subseteq [a]$.\nThus, two sets in the quotient set can only have a non-empty intersection if they are the same set, i.e., the elements of $X/{\\sim}$ are pairwise disjoint. \n\nNotice, by the way, how we have been constantly using the symmetry of equivalence relations throughout the proof.\n\n\\item Symmetry and reflexivity are obvious. Regarding transitivity, let $a,b, c\\in X$ be such that $a\\sim b$ and $a\\sim c$. If we let $A\\in P$ be the only subset of the partition to which $a$ belongs, as $a\\sim b$, we know that $b\\in A$. In addition, since $b\\sim c$, that must mean that $c\\in A$ and, therefore, that $a\\sim c$. This proves that $\\sim$ is an equivalence relation.\n\\end{parlist}\n\\end{proof}\n\n\\begin{definition}\nLet $X$ be a set. A binary relation $\\preceq$ defined on $X$ is said to be a \\emph{partial order} if it verifies the following properties:\n\\begin{itemize}\n\\item Reflexivity: for any $a\\in X$, we have $a\\preceq a$.\n\\item Antisymmetry: for any $a,b\\in X$, if $a\\preceq b$ and $a\\neq b$, then $b\\not\\preceq a$.\n\\item Transitivity: for any $a,b,c\\in X$, if $a\\preceq b$ and $b\\preceq c$, then $a\\preceq c$.\n\\end{itemize}\nA partial order is said to be a \\emph{total order} if, for any $a,b\\in X$, we have $a\\preceq b$ or $b\\preceq a$.\n\nA \\emph{strict partial order} $\\prec$ is a binary relation that verifies antisymmetry, transitivity and \\emph{irreflexivity}, i.e., that for any $a\\in A$, $a\\not\\prec a$. \nAny partial order $\\preceq$ can be used to define a strict partial order $\\prec$ as $a \\prec b$ if and only if $a\\preceq b$ and $a\\neq b$.\nConversely, any strict partial order defines a partial order in the obvious way.\n\nGiven a set $X$ endowed with a partial order $\\preceq$, an element $a\\in A$ is said to be a \\emph{minimal} element if there exists no $x\\in X$ such that $x\\preceq a$.\nAnalogously, $a$ is said to be \\emph{maximal} if no $x\\in X$ exists such that $a\\preceq x$.\nThe element $a$ is said to be a \\emph{minimum} in $X$ if, for any $x\\in X$, $a\\preceq x$; moreover, it is said to be a \\emph{maximum} if any $x\\in X$ satisfies $x\\preceq a$.\nNotice how all these definitions need to be understood with respect to a particular partial order $\\preceq$: an element may be maximal, minimal, a maximum or a minimum with respect to one partial order but not to another.\n\nA total order $\\preceq$ on a set $X$ is said to be a \\emph{well-order} if any $A\\subseteq X$ has a minimum. If a set $X$ has a well-order $\\preceq$, it is said that $X$ is \\emph{well-ordered} (by $\\preceq$).\n\\label{<+label+>}\n\\end{definition}\n\n\n", "meta": {"hexsha": "169bf05e19ede716ad19a2ec1521a70ea2fa0928", "size": 47811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch1/sec4.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/sec4.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/sec4.tex", "max_forks_repo_name": "gonzalezcastillo/leavingthecave", "max_forks_repo_head_hexsha": "13c9a65ed64fc1f7c699febca3ff37a8ea5501ad", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 70.517699115, "max_line_length": 686, "alphanum_fraction": 0.6898621656, "num_tokens": 15378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299632771661, "lm_q2_score": 0.8311430415844384, "lm_q1q2_score": 0.7689984458432421}}
{"text": "%\n% Chapter 2.7\n%\n\n\\section*{2.7 Rates of Change Problems}\n\nThe average rate of change of \\(y\\) with respect to \\(x\\) over the interval \\([x_1, x_2]\\) is\n$$ \\frac{\\Delta y}{\\Delta x} = \\frac{f(x_2)-f(x_1)}{x_2-x_1} $$\nIts limit as \\(\\Delta x \\to 0\\) is the derivative \\(f'(x)\\), which is the instantaneous rate of change of \\(y\\) with respect to \\(x\\) written as\n$$ \\frac{dy}{dx} = \\lim_{\\Delta x \\to 0}\\frac{\\Delta y}{\\Delta x} $$\n\n\\subsection*{Physics}\n\nIf \\(s = f(t)\\) is the position function of a particle that is moving in a straight line, then \\(\\frac{\\Delta s}{\\Delta t}\\) represents the \\textbf{average velocity over a time period} \\(\\Delta t\\).\\\\\n\\(v=\\frac{ds}{dt}\\) represents the instantaneous velocity (the rate of change of displacement with respect to time).\\\\\n\\(a=\\frac{dv}{dt}\\) represents the instantaneous acceleration (the rate of change of velocity with respect to time).\n$$ a(t)=v'(t)=s''(t) $$\n\n\\subsection*{Chemistry}\n\nConsider the reaction where \\(A + B \\to C\\). The \\textbf{instantaneous rate of reaction} is obtained by taking the limit of the average rate of reaction as the time interval \\(\\Delta t\\) approaches 0.\n$$ \\text{rate of reaction} = \\lim_{\\Delta t \\to 0}\\frac{\\Delta [C]}{\\Delta t} = \\frac{d[C]}{dt} $$\n\n\\subsection*{Biology}\n\nLet \\(n=f(t)\\) be the number of individuals in an animal or plant population at time \\(t\\).\n$$ \\text{average rate of growth} = \\frac{\\Delta n}{\\Delta t} = \\frac{f(t_2)-f(t_1)}{t_2-t_1} $$\nThe \\textbf{instantaneous rate of growth} is obtained from the average rate of growth by letting the time period \\(\\Delta t\\) approach 0:\n$$ \\text{growth rate} = \\lim_{\\Delta t \\to 0}\\frac{\\Delta n}{\\Delta t} = \\frac{dn}{dt} $$\n", "meta": {"hexsha": "361e3bfeeea0c6e2230fa55ae898b9ac25f80d96", "size": 1683, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/2-7.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-7.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-7.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": 56.1, "max_line_length": 200, "alphanum_fraction": 0.6714200832, "num_tokens": 535, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7689738642197803}}
{"text": "\\section{Encoding polytope placement into SMT}\n\nLet's now focus on the task of placing polytopes into a parallelepiped. \nInformally, the placement is carried out by means of a vector \nfor each polytope, which translates the polytope with respect to the\norigin. The polytope packing problem is then the problem of finding\nsuch placement vectors, which may or may not exist, depending on the\nparticular instance to solve.\n\nFormally, given a set of polytopes $P_1, \\ldots, P_n$, we need to find\nplacement vectors $\\point{v_1}, \\ldots, \\point{v_n}$ such that for $0\\leq i<j \\leq n$\n$$(\\point{v_i}+P_i) \\cap (\\point{v_j}+P_j) \\not= \\emptyset$$ \nwhich means that for $0 \\leq i<j \\leq n$\n$$(\\point{v_j} - \\point{v_i}) \\not\\in (P_i \\ominus P_j).$$\n\nThe latter condition can be translated into a constraint satisfaction\nproblem. In particular $P_i \\ominus P_j$ is a polytope that can be\ndefined by the intersection of a set of linear inequalities\n\\begin{eqnarray}\n\\nonumber\n&        & c_{1_x} x + c_{1_y} y + c_{1_z} z \\leq c_1 \\\\\n\\nonumber\n& \\wedge & c_{2_x} x + c_{2_y} y + c_{2_z} z \\leq c_2 \\\\\n\\nonumber\n& \\wedge & \\ldots \\\\\n\\nonumber\n& \\wedge & c_{n_x} x + c_{n_y} y + c_{n_z} z \\leq c_n\n\\end{eqnarray}\neach representing a faced of the polytope. The\narea ``outside'' $P_i \\ominus P_j$ is therefore\n\\begin{eqnarray}\n\\nonumber\n&      & c_{1_x} x + c_{1_y} y + c_{1_z} z \\geq c_1 \\\\\n\\nonumber\n& \\vee & c_{2_x} x + c_{2_y} y + c_{2_z} z \\geq c_2 \\\\\n\\nonumber\n& \\vee & \\ldots \\\\\n\\nonumber\n& \\vee & c_{n_x} x + c_{n_y} y + c_{n_z} z \\geq c_n\n\\end{eqnarray}\nTechnically we should use strict inequalities $>$, however\nwe may allow polytopes to ``touch'' on a common point. At last\nwe can specify that $\\point{v_j} - \\point{v_i}$ is in the\narea outside $P_i \\ominus P_j$ with the following substitution\n\\begin{eqnarray}\n\\nonumber\n&      & c_{1_x} (v_{j_x} - v_{i_x}) + c_{1_y} (v_{j_y} - v_{i_y}) + c_{1_z} (v_{j_z}-v_{i_z}) \\geq c_1 \\\\\n\\nonumber\n& \\vee & c_{2_x} (v_{j_x} - v_{i_x}) + c_{2_y} (v_{j_y} - v_{i_y}) + c_{2_z} (v_{j_z}-v_{i_z}) \\geq c_2 \\\\\n\\label{eq:smt1}\n& \\vee &\\ldots \\\\                                                                                    \n\\nonumber\n& \\vee & c_{n_x} (v_{j_x} - v_{i_x}) + c_{n_y} (v_{j_y} - v_{i_y}) + c_{n_z} (v_{j_z}-v_{i_z}) \\geq c_n\n\\end{eqnarray}\nIn addition to the constraints above, we need to specify the ``borders'' of the parallelepiped. Suppose\nthat the parallelepiped measures $l$,$w$,$h$ of length, witdth, and height respectively, and let\n$x_\\downarrow(P_i), x_\\uparrow(P_i)$, the lowest and highest $x$ coordinate of $P_i$, \n$y_\\downarrow(P_i), y_\\uparrow(P_i)$, the lowest and highest $y$ coordinate of $P_i$, \n$z_\\downarrow(P_i), z_\\uparrow(P_i)$, the lowest and highest $z$ coordinate of $P_i$. Then we\nneed to encode for all $i$\n\\begin{eqnarray}\n\\nonumber\n&& 0 \\leq v_{i_x} + x_\\downarrow(P_i) \\wedge v_{i_x} + x_\\uparrow(P_i) \\leq l \\\\\n\\label{eq:smt2}\n&& 0 \\leq v_{i_y} + y_\\downarrow(P_i) \\wedge v_{i_y} + y_\\uparrow(P_i) \\leq w \\\\\n\\nonumber\n&& 0 \\leq v_{i_z} + z_\\downarrow(P_i) \\wedge v_{i_z} + z_\\uparrow(P_i) \\leq h\n\\end{eqnarray}\nBy encoding (\\ref{eq:smt1}) and (\\ref{eq:smt2}) into the SMT2~\\cite{SMTLIB} language, we can find\nvalues of $\\point{v_i}$ for each $P_i$ that represent a polytope placement such\nthat the polytopes (may touch but) do not intersect and such that\nis contained in the given parallelepiped.\n", "meta": {"hexsha": "68f1433264ceced52d0b0f0cd3aa35301bca9d43", "size": 3378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/encoding.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/encoding.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/encoding.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": 46.2739726027, "max_line_length": 106, "alphanum_fraction": 0.6675547661, "num_tokens": 1263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7689738642197803}}
{"text": "\\documentclass[12pt]{article}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsthm}\n\\usepackage[lastexercise]{exercise}\n\n\\renewcommand{\\QuestionNB}{(\\alph{Question})\\ }\n\n\\begin{document}\n\n\\section{Induction Proofs}\n\\begin{ExerciseList}\n\t\\Exercise Show that for any \\(n\\in\\mathbb N_1\\)\n\n\t\\[\n\t\t\\frac{1}{1 \\cdot 3} + \\frac{1}{3 \\cdot 5} + \\cdots + \\frac{1}{(2n-1)(2n+1)} = \\frac{n}{2n+1}\n\t\\]\n\n\t\\Exercise\n\tConsider the sequence \\((a_n)\\) defined by\n\t\\[\n\t\t\\begin{cases}\n\t\t\ta_1=6, \\\\\n\t\t\ta_{n+1}  = \\frac{a_n}{3}(1-e^{-a_n^2}), & \\mbox{if \\(n\\ge 1\\)} \\\\\n\t\t\\end{cases}\n\t\\]\n\t\\Question{Show that \\(a_n\\in (0,6]\\) for any \\(n\\in\\mathbb N_1\\)}\n\t\\Question{Show that the sequence is decreasing}\n\t\\Question{Prove that the sequence is convergent and determine it's limit}\n\n\t\\Exercise\n\tConsider a sequence \\((b_n)\\) defined by\n\t\\[\n\t\t\\begin{cases}\n\t\t\tb_1=\\frac{1}{2},\\\\\n\t\t\tb_{n+1}  = b_n(b_n - 1) + 1, & \\mbox{if $n\\ge 1$} \\\\\n\t\t\\end{cases}\n\t\\]\n\t\\Question{Show that \\(b_n\\in (0,1)\\) for any \\(n\\ge 1\\)}\n\t\\Question{Show that the sequence is increasing}\n\t\\Question{Prove that the sequence is convergent and determine it's limit}\n\n\t\\Exercise\n\tConsider the sequence \\((u_n)\\) defined by\n\t\\[\n\t\t\\begin{cases}\n\t\t\tu_1=1,\\\\\n\t\t\tu_{n+1}  = 1 + \\frac{u_n}{2}, & \\mbox{if $n\\ge 1$} \\\\\n\t\t\\end{cases}\n\t\\]\n\t\\Question{Show that $u_n \\le 2$ for any $n\\in\\mathbb N_1$}\n\t\\Question{Show that the sequence is increasing}\n\t\\Question{Prove that the sequence is convergent and determine it's limit}\n\n\t\\Exercise\n\tLet $\\alpha\\in [0,1]$, consider the sequence $(b_n)$ given by\n\t\\[\n\t\t\\begin{cases}\n\t\t\tb_1=\\alpha,\\\\\n\t\t\tb_{n+1}  = b_n - b_n^4, & \\mbox{if $n\\ge 1$} \\\\\n\t\t\\end{cases}\n\t\\]\n\t\\Question{Show that $b_n$ is monotonically decreasing}\n\t\\Question{Show that $b_n\\in [0,1]\\forall n\\in\\mathbb N_1$}\n\t\\Question{Prove that $b_n$ is convergent and calculate $\\lim b_n$}\n\n\t\\Exercise\n\tConsider the sequence $(a_n)$ defined by\n\t\\[\n\t\t\\begin{cases}\n\t\t\ta_1=1,\\\\\n\t\t\ta_{n}  = \\frac{3a_{n-1}}{n}, & \\mbox{if $n\\ge 2$} \\\\\n\t\t\\end{cases}\n\t\\]\n\tShow that\n\t$$a_n=\\frac{3^{n-1}}{n!}\\quad\\quad\\forall n\\ge 1$$\n\\end{ExerciseList}\n\n\\section{Limits I}\n\\begin{ExerciseList}\n\t\\Exercise Calculate or show that it does not exist in $\\overline{\\mathbb R}$\n\t\\Question $\\lim \\frac{(n+1)!-n!}{n!(n+2)}$\n\t\\Question $\\lim (-1)^n \\frac{10^n}{n!}$\n\t\\Question $\\lim \\frac{5n!+5n}{n^n + 2}$\n\t\\Question $\\lim \\sqrt{\\frac{e^n+2}{n!}}$\n\t\\Question $\\lim \\frac{(-1)^n n}{n!+4}$\n\t\\Question $\\lim \\frac{\\sqrt[3]{n+4}}{\\sqrt[3]{n}+4}$\n\t\\Question $\\lim \\sqrt[n]{\\frac{n+2^n}{2+5^n}}$\n\t\\Question $\\lim \\frac{3n^4-2n}{(n^2 + 3)(1+5n^2)}$\n\t\\Question $\\lim (\\frac{2}{3}+\\cos(3n\\pi))^n$\n\t\\Question $\\lim \\frac{3+\\cos(e^{-n})}{n+\\sqrt{n!}}$\n\t\\Question $\\lim \\frac{(-1)^n n }{n! + 5}$\n\t\\Question $\\lim \\frac{\\cos{(n\\pi)}}{\\sin{(1/n\\pi)}+1}$\n\t\\Question $\\lim \\frac{e^{3n}+1}{2^n+n^2}$\n\t\\Question $\\lim \\frac{\\sqrt{n} + n^3}{(n+\\sqrt{n})(n^2 + n^{3/2})}$\n\t\\Question $\\lim (\\cos{(\\frac{\\pi}{4}+n\\pi)}+1)^n$\n\t\\Question $\\lim \\frac{(3n)!}{n!(2n)!}$\n\t\\Question $\\lim \\frac{\\arccos(1/n)}{\\cos(\\pi/n)}$\n\t\\Question $\\lim \\frac{2n! + 3^n}{n^{50} + n!}$\n\t\\Question $\\lim \\sqrt[n]{\\frac{\\arctan n}{1+e^n}}$\n\\end{ExerciseList}\n\n\\section{Limits II}\n\\begin{ExerciseList}\n\t\\Exercise Calculate or show that it does not exist in $\\overline{\\mathbb R}$\n\t\\Question $\\lim_{x\\to 0}\\frac{e^x - 1}{x-e^{3x} + 1}$\n\t\\Question $\\lim_{x\\to +\\infty}(3x^2+1)^{1/x}$\n\t\\Question $\\lim_{x\\to 1}\\frac{x-1}{\\tan(x-1)}$\n\t\\Question $\\lim_{x\\to 2}(x-1)^{\\frac{1}{2-x}}$\n\t\\Question $\\lim_{x\\to -\\infty}xe^{x^2}$\n\t\\Question $\\lim_{x\\to +\\infty}(\\log(2x))^{1/x}$\n\t\\Question $\\lim_{x\\to 1}\\frac{1}{x-1}\\int_0^{\\log x}{e^{\\sin t}}dt$\n\t\\Question $\\lim_{x\\to 0}(x^2 + 1)^{\\frac{1}{x^2}}$\n\t\\Question $\\lim_{x\\to1+}\\frac{\\arctan(x-1)}{x^3-3x+2}$\n\t\\Question $\\lim_{x\\to 0}\\frac{\\arctan{2x}}{\\tan x}$\n\t\\Question $\\lim_{x\\to +\\infty}(2e^x + 1)^{\\frac{1}{x}}$\n\t\\Question $\\lim_{x\\to 0}\\frac{1-\\cos{x}}{\\arcsin{x}}$\n\t\\Question $\\lim_{x\\to 0} x(\\log x)^2$\n\t\\Question $\\lim_{x\\to 0}\\frac{2\\int_0^x(1-e^{t^2})dt}{x^2}$\n\\end{ExerciseList}\n\n\\section{Functions}\n\\begin{ExerciseList}\n\t\\Exercise Consider the function $f\\colon \\mathbb R \\to \\mathbb R$\n\t$$f(x) = \\begin{cases} -x e^x, & \\mbox{if $x<0$} \\\\ \\alpha\\arctan(x^2-2x), &\\mbox{if $x\\ge 0$} \\\\ \\end{cases}$$\n\tWhere $\\alpha$ is a real constant.\n\t\\Question Calculate $\\lim_{x\\to -\\infty}f(x)$ and $\\lim_{x\\to +\\infty}f(x)$\n\t\\Question Justify whether $f$ is continuous\n\t\\Question Let $f'_+(0)=-2\\alpha$, determine $\\alpha$ such that $f$ is differentiable at $x=0$. Justify that $f$ is differentiable in $\\mathbb R$ and calculate it's derivative\n\t\\Question Determine the local extrema and the monotonous intervals of $f$ (with $\\alpha = 1/2$)\n\t\\Question Indicate the co-domain of $f$ (with $\\alpha=1/2$)\n\n\t\\Exercise The function $h\\colon \\mathbb R \\to \\mathbb R$\n\t$$h(x)=\\begin{cases}x^2, & \\mbox{if $x\\in\\mathbb Q$} \\\\ 0, & \\mbox{if $x\\in\\mathbb R\\setminus\\mathbb Q$}\\end{cases}$$\n\tis continuous at only one point. Is it differentiable at that point?\n\n\t\\Exercise Consider the function $f\\colon \\mathbb R\\setminus\\{0\\}\\to\\mathbb R$\n\t$$f(x) = \\begin{cases} \\frac{e^{-x}}{x+1}, & \\mbox{if $x>0$} \\\\ 2+\\log(1-x), & \\mbox{if $x<0$} \\\\ \\end{cases}$$\n\t\\Question Show that $f$ is continuous. Will $f$ be extensible by continuity on the point $x=0$?\n\t\\Question Calculate in $\\overline{\\mathbb R}$\n\t$$\\lim_{x\\to -\\infty}f(x), \\qquad \\lim_{x\\to -\\infty}f(x)$$\n\t\\Question Show that $f$ is differentiable, and calculate $f'(x)\\quad\\forall x\\in\\mathbb R\\setminus \\{ 0\\}$.\n\tUse the result to determine the monotonous intervals of $f$\n\t\\Question Determine the co-domain of $f$\n\n\t\\Exercise Consider the function $f\\colon \\mathbb R\\to \\mathbb R$ such that\n\t$$f(x)=\\begin{cases}-x^2e^x, & \\mbox{if $x\\le 0$} \\\\ (1-\\cos x)e^{-x} & \\mbox{if $x>0$} \\\\ \\end{cases}$$\n\t\\Question Calculate, if it exists in $\\overline{\\mathbb R}$, $\\lim_{x\\to +\\infty}f(x)$\n\t\\Question Show that $f$ is continuous at the point $x=0$ and calculate,if it exists, $f'(0)$\n\t\\Question Determine the differentiability domain of $f$, and calculate it's derivative.\n\t\\Question Show that $f$ has one and only one local extremum on the interval $(-\\infty, 0)$.\n\tProve that it's an absolute minimum of $f$ in $\\mathbb R$.\n\t\\Question Show that the co-domain of $f$ is a closed and limited interval.\n\n\t\\Exercise Given a function $f\\colon \\mathbb R\\setminus\\{ 0 \\} \\to \\mathbb R$ such that\n\t$$f(x)=\\begin{cases}\\alpha + \\log{\\frac{1}{1+x^2}} & \\mbox{if $x<0$} \\\\ \\arctan{\\frac{1}{x}} & \\mbox{if $x>0$} \\\\ \\end{cases}$$\n\t\\Question Calculate, if it exists, $\\lim_{x\\to -\\infty}$ and $\\lim_{x\\to +\\infty}$\n\t\\Question Determine $\\alpha\\in\\mathbb R$ such that $f$ is extensible by continuity at $x=0$\n\t\\Question Determine the domain of differentiability of $f$, and calculate it's derivative.\n\t\\Question Determine the monotony intervals of $f$, as well as it's extrema, if they exist.\n\t\\Question Assuming $\\alpha=0$, what will be the co-domain of $f$?\n\n\t\\Exercise Consider the function $f\\colon\\mathbb R\\setminus\\{ -\\pi/2,\\pi/2 \\}\\to\\mathbb R$ given by\n\t$$f(x)=\\begin{cases}\\frac{\\pi}{2(\\sin{x}+1)}, & \\mbox{if $|x| < \\pi/2$} \\\\ \\arctan(e^{x-\\pi/2}), & \\mbox{if $|x|>\\pi/2$} \\\\ \\end{cases}$$\n\t\\Question Study $f$ with regards to continuity.\n\t\\Question Calculate $\\lim_{x\\to -\\infty}f(x)$ and $\\lim_{x\\to +\\infty}f(x)$\n\t\\Question Decide whether $f$ extendable by continuity at $-\\pi/2$ and $\\pi/2$\n\t\\Question Calculate the derivative $f'$, and determine it's monotonous intervals.\n\n\t\\Exercise Consider the function $f\\colon (-1,+\\infty)\\to\\mathbb R$:\n\t$$f(x)=\\begin{cases}\\log{\\sqrt{1-x^2}}, & \\mbox{if $-1<x\\le 0$} \\\\ x^2e^{1-x^2}, & \\mbox{if $x>0$} \\\\ \\end{cases}$$\n\t\\Question Study $f$ with regards to continuity\n\t\\Question Calculate $\\lim_{x\\to -1^+}f(x)$ and $\\lim_{x\\to +\\infty}f(x)$\n\t\\Question Determine the derivative $f'$\n\t\\Question Determine the monotony intervals of $f$, as well as the local maxima and minima.\n\n\\end{ExerciseList}\n\n\\section{Primitives}\n\\begin{ExerciseList}\n\t\\Exercise Calculate the primitive of the function $$\\frac{2x+3}{x^2+2}$$ that vanishes at $x=0$\n\n\t\\Exercise Determine a primitive for the following functions:\n\t\\Question $\\frac{1}{\\sqrt{e^x - 1}}$\n\t\\Question $\\frac{3x}{1+x^4}$\n\t\\Question $\\frac{3x}{\\sqrt{4+x^2}}$\n\t\\Question $\\frac{1}{x^2+4}$\n\t\\Question $\\frac{\\sin{\\sqrt[3]{x}}}{\\sqrt[3]{x}}$\n\t\\Question $\\frac{\\cos(\\log x)}{x}$\n\t\\Question $\\log(1+x)^2$\n\n\t\\Exercise Determine the function $g\\colon \\mathbb R \\to \\mathbb R$ that satisfies\n\t$$\\begin{cases}g'(x)=\\frac{3x^2 + 1}{x^2 + 2} & \\mbox{$\\forall x\\in \\mathbb R$} \\\\ g(0)=2\\end{cases}$$\n\n\t\\Exercise Calculate the function $f\\colon \\mathbb R\\to\\mathbb R$ that satisfies\n\t$$\\forall x\\in\\mathbb R\\quad f'(x)=\\frac{1+x}{9+x^2}\\quad\\mbox{and}\\quad f(0)=\\log(3)$$\n\n\t\\Exercise Write the general expression for the primitives in $(0,+\\infty)$ of\n\t$$\\frac{1}{x\\sqrt{x+1}}$$\n\\end{ExerciseList}\n\n\\section{Integration}\n\\begin{ExerciseList}\n\t\\Exercise Calculate the area of region delimited by:\n\t\\Question $\\{(x,y)\\in\\mathbb R^2 \\colon x\\le y\\le -x^2+2\\}$\n\t\\Question $\\{ (x,y)\\in\\mathbb R^2 \\colon x^2-\\pi x\\le y \\le -\\sin{x} \\}$\n\t\\Question $\\{ (x,y)\\in\\mathbb R^2 \\colon 0\\le x\\le 1,\\frac{\\pi}{4}x\\le y\\le\\arctan x \\}$\n\t\\Question The triangle described by the lines $y=x,\\enspace y=2x,\\enspace y=3x-2$\n\n\t\\Exercise Compute the following integrals\n\t\\Question $\\int_0^{\\frac{\\pi}{2}}\\frac{\\sin x \\cos x}{2+\\sin^2x}dx$\n\t\\Question $\\int_0^1{\\frac{4x}{4+x^2}}dx$\n\t\\Question $\\int_{\\log 2}^{\\log 3}{\\frac{e^x}{(e^x-1)^2}}dx$\n\t\\Question $\\int_1^2{\\frac{1}{x(4+log^2(x))}}dx$\n\t\\Question $\\int_{-1}^0\\frac{\\log(x+2)}{(x+2)^2}dx$\n\t\\Question $\\int_0^1{(\\frac{x}{2}+x^3)\\arctan{x}}\\: dx$\n\t\\Question $\\int_1^{\\log{2}}{\\frac{e^x}{\\sqrt{e^x - 1}}}dx$\n\t\\Question $\\int_2^7{\\frac{1}{(x+1)\\sqrt{x+2}}}dx$\n\n\t\\Exercise Determine the value of the constant $c\\in\\mathbb R$ such that $f'(0) = 0$, with\n\t$$f(x)=\\int_x^{cx+2}{e^{-t^2}}dt$$\n\n\t\\Exercise Let $g\\in C(\\mathbb R)$ be an odd function, and $f$ the function given by\n\t$$f(x)=\\int_1^{x^2-1}{xg(t)}dt$$\n\tCalculate $f'(x)$ for any $x\\in\\mathbb R$, and show that $f'(0)=0$\n\n\t\\Exercise Determine a function $f\\colon\\mathbb R \\to \\mathbb R$, differentiable and non-null, such that\n\t$$f^3(x)=\\int_{\\pi/2}^{x}{\\frac{\\cos{t}}{2-\\sin{t}}}dt$$\n\n\\end{ExerciseList}\n\n\\section{Taylor Polynomial}\n\\begin{ExerciseList}\n\t\\Exercise Let $f\\in C^2(\\mathbb R)$ and $g(x)=f(e^x)\\forall x\\in\\mathbb R$.\n\tLet $3-x+2(x-1)^2$ be the second order Taylor polynomial of $f$ relative\n\tto point $1$, determine the second order MacLaurin polynomial of $g$.\n\n\t\\Exercise Let $f\\in C^4(\\mathbb R)$ be such that its third degree Taylor\n\tpolynomial at point $2$ is constant. Given that $f^{(4)}(2)=1$, justify that\n\t$f(2)$ is an extremum of $f$ and classify it.\n\n\t\\Exercise Let $h\\colon \\mathbb R \\to \\mathbb R$ be a differentiable function\n\t, and consider $f\\colon \\mathbb R\\to\\mathbb R$ given by\n\t$$f(x)=\\int_x^{x^2}{h(t)}dt$$\n\t\\Question Show that $f''(1)-2f'(1)=3h'(1)$\n\t\\Question If $p_1(x)=x-1$ is the first order Taylor polynomial of $h$ at point $1$,\n\tshow that $f$ has a local minimum at $x=1$\n\\end{ExerciseList}\n\n\\section{Series}\n\\begin{ExerciseList}\n\t\\Exercise Analyse the following series and determine whether they are absolutely convergent, conditionally convergent, or divergent\n\t\\Question $\\sum_{n=1}^{+\\infty} \\frac{1}{3+2n}$\n\t\\Question $\\sum_{n=1}^{+\\infty} \\frac{\\cos(2n)}{n^3}$\n\t\\Question $\\sum_{n=1}^{+\\infty} \\frac{n^3}{e^{2n}}$\n\t\\Question $\\sum_{n=1}^{\\infty}  \\frac{2+n\\sqrt{n}}{1+3n^4}$\n\t\\Question $\\sum_{n=2}^{\\infty}  \\frac{3^n(1+(-1)^n)}{(2\\pi)^{n+1}}$\n\t\\Question $\\sum_{n=2}^{+\\infty} \\log(\\arctan(n+1))-\\log(\\arctan n)$\n\t\\Question $\\sum_{n=2}^{+\\infty} \\frac{(-1)^n}{\\sqrt[4]{n^3 + 1}}$\n\t\\Question $\\sum_{n=1}^{\\infty}  (\\frac{n}{n+1} - \\frac{n+1}{n+2})$\n\t\\Question $\\sum_{n=0}^{\\infty}  2^{-3n}$\n\t\\Question $\\sum_{n=1}^{+\\infty}\\frac{\\sqrt[3]{n^3+2}}{n^2\\sqrt{n+9}}$\n\t\\Question $\\sum_{n=1}^{+\\infty}\\frac{\\arctan{n}}{e^n}$\n\t\\Question $\\sum_{n=1}^{+\\infty}(-1)^{n+1}\\frac{\\sin(2n)}{n^3}$\n\n\t\\Exercise Show that if the series $\\sum_{n=1}^{+\\infty}a_n$ converges, then\n\t$\\sum_{n=1}^{+\\infty}\\frac{2n-1}{2n}$ also converges.\n\n\t\\Exercise Determine the values of $x\\in\\mathbb R$ for which the following series\n\tis absolutely convergent, conditionally convergent, or divergent\n\t\\Question $\\sum_{n=1}^{+\\infty}\\frac{n^n(x-1)^n}{(n+3)^n}$\n\t\\Question $\\sum_{n=0}^{\\infty}\\frac{(x-2)^n}{\\sqrt{n}+1}$\n\t\\Question $\\sum_{n=1}^{\\infty}\\frac{\\log n}{2^n}(x-2)^n$\n\\end{ExerciseList}\n\n\\section{Proofs}\n\\begin{ExerciseList}\n\t\\Exercise Show that for any $x>0$\n\t$$\\frac{x}{1+x} < \\log(1+x) < x$$\n\tHint: Mean Value Theorem\n\n\t\\Exercise Let $h\\in C(\\mathbb R)$ such that $h(x) = h(x+2)$ for all $x\\in\\mathbb R$, and\n\t$$\\phi(x) = \\int_0^x{h(t)dt}-\\int_0^{x+2}{h(t)dt}$$\n\tProve that $\\phi$ is identically $0$ if and only if $\\int_0^2 h(t)dt = 0$\n\n\t\\Exercise Let $(a_n)$ be a limited sequence with terms in $(1,+\\infty)$, and\n\t$(b_n)$ another sequence such that $$b_n = \\frac{na_n}{n+a_n}\\qquad n\\in\\mathbb N_1$$\n\tShow that $(b_n)$ has convergent subsequences.\n\n\t\\Exercise Let $f$ and $g$ be real functions, defined and continuous on the interval $[a,b]$, such that\n\t$$\\int_a^b{f(t)}dt = 2\\int_a^b{g(t)}dt$$\n\tShow that there is $c\\in[a,b]$ such that $f(c)=2g(c)$\n\n\t\\Exercise Let $h\\colon [0,+\\infty)\\to\\mathbb R$ be a continuous function\n\tfor which $\\lim_{x\\to +\\infty}h(x)=c\\in\\mathbb R$.\n\t\\Question Show that there is at least one solution for $h(x)=\\frac{x^2-1}{x}$\n\tin the interval $(0,+\\infty)$\n\t\\Question Suppose $h$ is differentiable in $(0,+\\infty)$ and\n\t$$\\forall x\\in(0,+\\infty)\\quad h'(x<1)$$\n\tShow that $h(x)=\\frac{x^2-1}{x}$ has one and only one solution\n\n\t\\Exercise Let $f\\colon [0,1]\\to\\mathbb R$ be a continuous function. Show that\n\tfor all $x\\in[0,1]$\n\t$$\\int_0^x{\\int_0^u{f(t)}dt}du=\\int_0^x{(x-t)f(t)}dt$$\n\n\t\\Exercise Let $f$ be a function integrable in $[0,1]$. Show that\n\t$$\\lim_{n\\to\\infty}\\int_0^1{x^{n+1}f(x)}dx = 0$$\n\n\t\\Exercise Let $G\\colon \\mathbb R\\to \\mathbb R$ be a continuous function.\n\tSuppose there is $m\\in\\mathbb R$ such that $\\{ x\\in\\mathbb R\\colon G(x)\\le m \\}$\n\tis limited and not empty.\n\tShow that $G$ has an absolute minimum.\n\n\t\\Exercise Let $g\\colon \\mathbb R \\to \\mathbb R$ be a continuous function such that\n\t$$\\lim_{x\\to -\\infty}g(x)=\\alpha>0$$\n\tShow that\n\t$$\\lim_{x\\to -\\infty}\\int_x^0 e^{x-t}g(t)dt=\\alpha$$\n\tHint: Show that $\\lim_{x\\to -\\infty}\\int_x^0 e^{-t}g(t)dt=+\\infty$\n\n\t\\Exercise Let $\\psi\\colon\\mathbb R \\to \\mathbb R$ be a continuous function\n\tsuch that $\\lim_{x\\to +\\infty}\\psi(x)=+\\infty$ and $\\lim_{x\\to -\\infty}\\psi(x)=-\\infty$.\n\tDecide if $G\\colon\\mathbb R \\to \\mathbb R$ defined as\n\t$$G(x)=\\frac{\\psi(x)}{1+\\psi^2(x)}$$\n\tHas a maximum and a minimum.\n\n\t\\Exercise Show that if $\\sum_{n=1}^{+\\infty}a_n$ and $\\sum_{n=1}^{+\\infty}b_n$\n\tare convergent series with positive terms, then $\\sum_{n=1}^{+\\infty}a_n b_n$\n\tis a convergent series. Will this hold true if $\\sum_{n=1}^{+\\infty}a_n$ and $\\sum_{n=1}^{+\\infty}b_n$\n\tare series with an oscillating sign?\n\n\t\\Exercise Let $I$ be an open interval, $a\\in I$ and $\\rho\\colon I\\to\\mathbb R$\n\ta function 2-times differentiable, such that $\\rho''(x)>0$ for any $x\\in I$. Also let\n\t$$g(x)=\\rho'(a)(x-a)+\\rho(a)$$\n\tShow that $\\rho(x)>g(x)$ for all $x\\in I\\setminus\\{ a \\}$\n\\end{ExerciseList}\n\\section{Notation}\n\\begin{enumerate}\n\t\\item  $[a,b]$ for a closed interval, $(a,b)$ for an open one.\n\t\\item $\\overline{\\mathbb R} = \\mathbb R \\cup \\{-\\infty, +\\infty\\}$\n\\end{enumerate}\n\\end{document}\n", "meta": {"hexsha": "b855011ba2000a7c966c83463db9eeee4faba878", "size": 15410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "problems.tex", "max_stars_repo_name": "lovesegfault/hard-calc", "max_stars_repo_head_hexsha": "a30b64bea77d1c8cc5a21b3330bf98eed2cf3551", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-02-08T22:32:08.000Z", "max_stars_repo_stars_event_max_datetime": "2017-02-08T22:32:08.000Z", "max_issues_repo_path": "problems.tex", "max_issues_repo_name": "lovesegfault/hard-calc", "max_issues_repo_head_hexsha": "a30b64bea77d1c8cc5a21b3330bf98eed2cf3551", "max_issues_repo_licenses": ["MIT"], "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.tex", "max_forks_repo_name": "lovesegfault/hard-calc", "max_forks_repo_head_hexsha": "a30b64bea77d1c8cc5a21b3330bf98eed2cf3551", "max_forks_repo_licenses": ["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.0584795322, "max_line_length": 175, "alphanum_fraction": 0.6349772875, "num_tokens": 6291, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8499711832583695, "lm_q1q2_score": 0.768926885755021}}
{"text": "\\subsection{Clarke generalized gradients}\\label{subsec:clarke_gradients}\n\nLet \\( X \\) be a Banach space and \\( f: X \\to \\BbbR \\) be locally Lipschitz.\n\n\\begin{definition}\\label{def:clarke_gradient}\\mcite[def. 10.3]{Clarke2013}\n  Let \\( x \\in X \\) and \\( U \\subseteq X \\) be a neighborhood of x where \\( f \\) is \\( L \\)-Lipschitz, i.e.\n\n  \\begin{equation*}\n    \\forall y, z \\in U, \\abs{f(y) - f(z)} \\leq L \\norm{y - z}.\n  \\end{equation*}\n\n  We use the Clarke generalized \\hyperref[def:nonsmooth_derivatives/clarke]{derivative},\n  \\begin{equation*}\n    f^\\circ(x)(h) \\coloneqq \\limsup_{\\substack{y \\to x \\\\ t \\downarrow 0}} \\frac {f(y + th) - f(y)} t\n  \\end{equation*}\n\n  We define the \\term{generalized gradient of \\( f \\) at \\( x \\)} to be the set\n  \\begin{equation*}\n    \\partial_C f(x) \\coloneqq \\{ x^* \\in X^* \\colon \\forall h \\in X, f^\\circ(x)(h) \\geq \\inprod {x^*} h \\}.\n  \\end{equation*}\n\n  We say that the vector \\( h \\) is a \\term{descent direction of \\( f \\) at \\( x \\)} if\n  \\begin{equation*}\n    \\limsup_{t \\downarrow 0} \\frac {f(x + th) - f(x)} t < 0.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:clarke_derivative_exists}\n  The generalized derivative of a locally Lipschitz function \\( f: X \\to \\BbbR \\) exists for every \\( x \\in X \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( x, h \\in X \\) and let \\( U \\) be a neighborhood of \\( x \\) where the Lipschitz condition holds with the constant \\( L_U \\). Then there exists \\( \\delta_0 > 0 \\) such that \\( B(x, \\delta_0) \\subseteq U \\).\n\n  Define \\( \\delta_1 \\coloneqq \\frac 1 2 \\min \\left\\{\\delta_0, \\frac {\\delta_0} {\\norm h} \\right\\} < \\delta_0 \\), so that for \\( y \\in B(x, \\delta_1) \\) and \\( t \\in (0, \\delta_1) \\) we have\n  \\begin{balign*}\n    \\norm{(y + th) - x}\n    \\leq\n    \\norm{y - x} + t \\norm h\n    \\leq\n    \\delta_1 + \\delta_1 \\norm h\n    \\leq\n    \\begin{cases}\n      \\frac {\\delta_0} 2 (1 + \\norm h),           & \\norm h \\leq 1 \\\\\n      \\frac {\\delta_0} {2 \\norm h} (1 + \\norm h), & \\norm h > 1.\n    \\end{cases}\n  \\end{balign*}\n\n  In both cases we get that \\( y + th \\in B(x, \\delta_0) \\).\n\n  The generalized derivative in \\( x \\) in the direction \\( h \\in X \\) is then norm-bounded by\n  \\begin{balign*}\n    \\abs{f^\\circ(x)(h)}\n    =\n    \\abs{\\limsup_{\\substack{y \\to x                             \\\\ t \\downarrow 0}} \\frac {f(y + th) - f(y)} t}\n    =\n    \\abs{\\lim_{\\delta \\to 0} \\sup_{\\substack{y \\in B(x, \\delta) \\\\ t \\in (0, \\delta)}} \\frac {f(y + th) - f(y)} t}\n    \\leq                                                        \\\\ \\leq\n    \\abs{\\sup_{\\substack{y \\in B(x, \\delta_1)                   \\\\ t \\in (0, \\delta_1)}} \\frac {f(y + th) - f(y)} t}\n    \\leq\n    \\sup_{\\substack{y \\in B(x, \\delta_1)                        \\\\ t \\in (0, \\delta_1)}} \\frac {\\abs{f(y + th) - f(y)}} t\n    \\leq                                                        \\\\ \\leq\n    \\sup_{\\substack{y \\in B(x, \\delta_1)                        \\\\ t \\in (0, \\delta_1)}} \\frac {\\norm{(y + th) - (y)}} t\n    =\n    \\norm h.\n  \\end{balign*}\n\n  The fact that \\( f \\) is locally Lipschitz gave us that the supremum is taken over a bounded set and thus the generalized derivative exists.\n\\end{proof}\n", "meta": {"hexsha": "f213592bc181a195b7354381494985f662f41db3", "size": 3166, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/clarke_gradients.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/clarke_gradients.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/clarke_gradients.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": 45.884057971, "max_line_length": 213, "alphanum_fraction": 0.5445356917, "num_tokens": 1154, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7687758483109959}}
{"text": "\\subsection{$F_1$ Score}\n\\label{chp:fundamentals:sec:metrics:subsec:f1_score}\n\nWe previously introduced the two metrics \\textit{precision} and \\textit{recall}.\nFrom their definition in \\cref{eq:precision} and \\cref{eq:recall} one concludes immediately that both are only optimal if an algorithm manages to select \\textit{exclusively} \\acp{TP} which would lead to $prec = rec = 1$.\nHowever, in most scenarios an algorithm does not select \\acp{TP} exclusively.\nIf that is the case, it is proven that a trade-off exists among whether one wants to identify all available relevant items (recall) or all of the selected items should be relevant (precision) \\parencite{Gordon:1989}.\nHere we do not focus on the formal derivation of this well known trade-off, instead excellent derivations can be found in \\textcites{Gordon:1989}{Zhu:2004}.\nTo measure and express this trade-off one can build the \\textit{harmonic mean} of precision and recall which is called \\textit{$F_1$ score} \\parencite{Powers:2011}.\nThis metric is defined by the following equation:\n\n\\begin{equation}\\label{eq:f1_score}\n    F_1 = 2 \\frac{prec \\cdot rec}{prec+rec}\n\\end{equation}\n\nFor the example data of \\cref{fig:metrics:tp_vis} the algorithm achieves an F$_1$ score of $F_1 = 2 \\frac{\\frac{3}{7} \\cdot \\frac{1}{4}}{\\frac{3}{7}+\\frac{1}{4}} \\approx 0.32$.\nThe $F_1$ score's generalization for a multi-class scenario is called \\textit{macro $F_1$ score} \\parencite{Opitz:2019}.\n", "meta": {"hexsha": "69330e8b906c7d894b1159c788dadae4d79a2d25", "size": 1443, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/02_fundamentals/sections/metrics/subsections/f1_score.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/f1_score.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/f1_score.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": 80.1666666667, "max_line_length": 220, "alphanum_fraction": 0.7623007623, "num_tokens": 425, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8244619199068831, "lm_q1q2_score": 0.7687722436989716}}
{"text": " In this model, we suppose that the data was generated using linear recursive formula\n \\begin{equation}\n  \\label{eq:varx_stationary}\n\tx_t = \\mu + \\sum\\limits_{q=1}^{\\mathrm{xmem}} A_q x_{t-q} + \\sum\\limits_{p=0}^{\\mathrm{umem}} B_p u_{t-p} + \\varepsilon_t, \\forall t = \\mathrm{xmem}, \\mathrm{xmem}+1, \\dots, T-1,\n \\end{equation}\n where given data $x_t \\in \\mathbb{R}^{\\mathrm{xdim}}, t = 0,\\dots,T-1$ are stored in column vectors, $A_q \\in \\mathbb{R}^{\\mathrm{xdim},\\mathrm{xdim}}$ are unknown coefficients (matrices) corresponding to previous $\\mathrm{xmem}$ time-steps and \\todo{write here something funny about variables in the model}.\n  \n Let us denote the number of equations in \\eqref{eq:varx_stationary} by $m = T-\\mathrm{xmem}$.\n Moreover, we define \n \\begin{displaymath}\n  \\begin{array}{rcl}\n   X & = & [x_{\\mathrm{xmem}}, x_{\\mathrm{xmem}+1}, \\dots, x_{T-1}] \\in \\mathbb{R}^{\\mathrm{xdim},m} \\\\[5mm]\n   M & = & [\\mu, A_1, A_2, \\dots, A_{\\mathrm{xmem}}, B_0, B_1, \\dots, B_{\\mathrm{umem}} ] \\in \\mathbb{R}^{\\mathrm{xdim},1+\\mathrm{xmem}\\cdot\\mathrm{xdim}+(\\mathrm{umem}+1)\\cdot\\mathrm{udim}}\\\\[5mm]\n   Z & = & \\left[\n\t\\begin{array}{ccccc}\n\t 1 & 1 & 1 & & 1 \\\\ \\hdashline[2pt/2pt]\n\t x_{\\mathrm{xmem}-1} & x_{\\mathrm{xmem}} & x_{\\mathrm{xmem}+1} & & x_{T-1} \\\\\n\t \\vdots & \\vdots & \\vdots & \\dots & \\vdots \\\\\n\t x_0 & x_1 & x_2 & & x_{T-\\mathrm{xmem}} \\\\ \\hdashline[2pt/2pt]\n\t u_{\\mathrm{xmem}} & u_{\\mathrm{xmem}+1} & u_{\\mathrm{xmem}+2} & & u_{T-1} \\\\\n\t u_{\\mathrm{xmem}-1} & u_{\\mathrm{xmem}} & u_{\\mathrm{xmem}+1} & & u_{T-2} \\\\\n\t \\vdots & \\vdots & \\vdots & & \\vdots \n    \\end{array}\n   \\right] \\in \\mathbb{R}^{1+\\mathrm{xmem}\\cdot\\mathrm{xdim}+(\\mathrm{umem}+1)\\cdot\\mathrm{udim},m} \\\\[5mm]\n   \\varepsilon & = & [\\varepsilon_{\\mathrm{xmem}}, \\varepsilon_{\\mathrm{xmem}+1}, \\dots, \\varepsilon_{T-1}] \\in \\mathbb{R}^{\\mathrm{xdim},m}\n  \\end{array}\n \\end{displaymath}\n\n Then \\eqref{eq:varx_stationary} is equivalent to\\footnote{please, notice that both of left side and right side are matrices}\n \\begin{equation}\n  \\label{eq:varx_stationary_matrix}\n  X = MZ + \\varepsilon,\n \\end{equation}\n where $M$ is matrix of unknown parameters of the model \\eqref{eq:varx_stationary}.\n Now we will find $M$ as \\emph{the best} solution, i.e. we minimize the size of error $\\varepsilon$ in \\eqref{eq:varx_stationary_matrix}\\footnote{please, notice that we are talking about matrix norms}\n \\begin{displaymath}\n  \\label{eq:eq:varx_stationary_matrix_eps}\n  \\Vert \\varepsilon \\Vert = \\Vert X - MZ \\Vert ~~ \\rightarrow ~~ \\min\\limits_{M}.\n \\end{displaymath}\n or equivalently\\footnote{\\todo{the trace and matrix norms should be discussed}}\n \\begin{displaymath}\n   \\bar{M} =  \\arg \\min\\limits_{M} \\Vert X - MZ \\Vert =  \\arg \\Vert X - MZ \\Vert^2 =  \\arg \\min\\limits_{M} \\underbrace{\\tr\\Vert X - MZ \\Vert^2}_{= L(M)}.\n \\end{displaymath}\n The optimization problem with object function $L(M): \\mathbb{R}^{\\mathrm{xdim},1+\\mathrm{xmem}\\cdot\\mathrm{xdim}+(\\mathrm{umem}+1)\\cdot\\mathrm{udim}} \\rightarrow \\mathbb{R}^{+}_0$ could be simplified \n \\begin{displaymath}\n  \\begin{array}{rcl}\n   \\min L(M) & = & \\min \\tr \\Vert X - MZ \\Vert^2 = \\min \\tr (X-MZ)^T(X-MZ) \\\\\n        & = & \\min \\tr \\left( X^TX - X^TMZ - (MZ)^TX + (MZ)^T MZ \\right) \\\\\n        & = & \\min \\tr \\left( X^TX - X^TMZ - Z^TM^TX + Z^T M^T MZ \\right) \\\\\n        & = & \\min \\tr (X^TX) - \\tr (X^TMZ) - \\tr (Z^TM^TX) + \\tr (Z^T M^T MZ)\n  \\end{array}\n \\end{displaymath}\n We consider the neccessary optimality condition $\\frac{\\partial L(M)}{\\partial M} = 0$, therefore we have to compute the derivatives of addends in the previous formula.\n These derivatives follow (using \\cite{matrix_cookbook}\\todo{add cookbook reference}).\n \\begin{displaymath}\n  \\begin{array}{rcl}\n   \\frac{\\partial \\tr (X^TX)}{\\partial M} & = & 0 \\\\\n   \\frac{\\partial \\tr (X^TMZ)}{\\partial M} & = & XZ^T \\\\\n   \\frac{\\partial \\tr (Z^TM^TX)}{\\partial M} & = & XZ^T \\\\\n   \\frac{\\partial \\tr (Z^TM^T M Z)}{\\partial M} & = & M(ZZ^T) + M (ZZ^T) = 2MZZ^T\n  \\end{array}\n \\end{displaymath}\n Therefore the neccessary optimality condition of the problem \\eqref{eq:eq:varx_stationary_matrix_eps} is given by\n \\begin{displaymath}\n  \\frac{\\partial L(M)}{\\partial M} = 0 ~~~ \\Leftrightarrow ~~~ -2XZ^T + 2M(ZZ^T) = 0,\n \\end{displaymath}\n which could be written in the form of the system of linear equations with multiple right-hand side vectors as\n \\begin{equation}\n  \\label{eq:varx_stationary_system}\n  (ZZ^T) M^T = ZX^T,\n \\end{equation}\n where $M^T$ is the matrix of unknown parameters of the original model \\eqref{eq:varx_stationary}.\n\n \\subsection{Checking equations by example}\n \n Let us consider a problem with $\\mathrm{xdim} = 2, \\mathrm{udim} = 1, \\mathrm{xmem} = 2, \\mathrm{umem} = 0, T = 5$. Then $m = 3$ and\n \\begin{displaymath}\n  X \\in \\mathbb{R}^{2,3}, ~ M \\in \\mathbb{R}^{2,6}, ~ Z \\in \\mathbb{R}^{6,3}, ~\\varepsilon \\in \\mathbb{R}^{2,3}.\n \\end{displaymath}\n Please, see Fig. \\ref{fig:varx1}, where we present given data (time-series and external forces) and Fig. \\ref{fig:varx2} to visualize objects in the problem.\n \n \\begin{figure}[h!]\n  \\centering\n    \\includegraphics[scale=0.2]{figure/varx1.pdf}\n  \\caption{Given data in VarX problem; time-series values $x_0,x_1,x_2,x_3,x_4$ and external forces $u_0,u_1,u_2,u_3,u_4$.}\n  \\label{fig:varx1}\n \\end{figure}\n\n \\begin{figure}[h!]\n  \\centering\n    \\includegraphics[scale=0.2]{figure/varx2.pdf}\n  \\caption{Objects in the VarX problem.}\n  \\label{fig:varx2}\n \\end{figure}\n\n The most complicated operation in equation \\eqref{eq:varx_stationary_matrix} is matrix multiplication $MZ$. The graphical analysis of this operation could be found in Fig. \\ref{fig:varx3}.\n Here, we used general property\n \\begin{displaymath}\n  \\forall A \\in \\mathbb{R}^{m,n} \\forall v_1,v_2 \\in \\mathbb{R}^n: A\\left[ v_1, v_2 \\right ] = \\left[ A v_1, Av_2 \\right] ,\n \\end{displaymath}\n i.e. multiplication by matrix could be applied into columns.\n\n \\begin{figure}[h!]\n  \\centering\n    \\includegraphics[scale=0.2]{figure/varx3.pdf}\n  \\caption{Multiplication $MZ$; the dashed line represents the separation between columns.}\n  \\label{fig:varx3}\n \\end{figure}\n \n Now we are ready to assemble $X = MZ + \\varepsilon$ (which we actually will not demonstrate, because the operation addition on the right side is an operation between columns of matrices, it is trivial, and it will be clear from following).\n Afterwards, we can compare columns on the left and right side of equation $X = MZ + \\varepsilon$, see Fig. \\ref{fig:varx4} and we obtain the original equations in VarX model, see equations \\eqref{eq:varx_stationary}.\n Therefore, in this case, equations \\eqref{eq:varx_stationary} and \\eqref{eq:varx_stationary_matrix} are equivalent.\n\n \\begin{figure}[h!]\n  \\centering\n    \\includegraphics[scale=0.2]{figure/varx4.pdf}\n  \\caption{The definition of original VarX problem.}\n  \\label{fig:varx4}\n \\end{figure}\n", "meta": {"hexsha": "c3ecadf91c7dcfaae61f7a6378cc194fb0fb501f", "size": 6836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/PASC_report/section/varx.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/varx.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/varx.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": 56.9666666667, "max_line_length": 309, "alphanum_fraction": 0.6736395553, "num_tokens": 2460, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632956467158, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.768727423214915}}
{"text": "\\section*{Chapter 6: Abstraction in Mathematics}\n\n\\paragraph{Exercise 6.3}\nProve that any group has at least one element.\n\n\\begin{proof}\nAny group, by definition, has an identity element $e$.\n\\end{proof}\n\n\n\\paragraph{Exercise 6.4}\nWhat is the order of $e$? Prove that $e$ is the only element of such order.\n\n\\begin{proof}[Answer]\nLet $G$ be a group with identity element $e$. The order of $e$ is 1 given that\n$e^1 = e$. Suppose that $x \\in G$ has also order 1. Then, $x^1 = x = e$.\n\\end{proof}\n\n\n\\paragraph{Exercise 6.5}\nProve that if $a$ is an element of order $n$, then $a^{-1} = a^{n-1}$.\n\n\\begin{proof}\nWe know that $a^n = a \\, a^{n-1} = e$. Since inverses are unique, then\nit must be $a^{-1} = a^{n-1}$.\n\\end{proof}\n\n\n\\paragraph{Exercise 6.7}\nProve that any subgroup of a cyclic group is cyclic.\n\n\\begin{proof}\nLet $G$ be a cyclic group and $S$ a subgroup of $G$. Let $x$\nbe a generator of $G$, and let\n$i_0 = \\min{\\{ i \\leq |G| \\, / \\, x^i \\in S \\ \\}}$.\nConsider the element $y = x^{i_0} \\in S$, and suppose that its order\n$m$ is such that $m < |S|$. Then, let $z \\in S$ be an element such that\n$z \\neq y^j$. Being $x$ a generator of $G$, we have that $z = x^{j_0}$\nfor some $j_0$. By the division algorithm, we can write $j_0$ as\n$j_0 = i_0 q + r$, for some $0 \\leq r < i_0$. Then,\n\\begin{eqnarray*}\nz &=& x^{j_0} \\\\\n  &=& x^{i_0 q + r} \\\\ \n  &=& x^{i_0 q} \\, x^r \\\\\n  &=& (x^{i_0})^q \\, x^r \\\\\n  &=& y^q \\, x^r\n\\end{eqnarray*}\nThis implies that $x^r = (y^q)^{-1} \\, z \\in S$, but this contradicts\nthe minimality of $i_0$. Hence, such $z$ cannot exist, which proves that\n$y$ is a generator of $S$ and, consequently, that $S$ is cyclic. \n\\end{proof}\n\n\n\\paragraph{Exercise 6.8}\nProve that any cyclic group is abelian.\n\n\\begin{proof}\nLet $G$ be a cyclic group, and let $x$ be a generator of $G$. Given \n$a, b \\in G$, we know that there exist $i, j \\in \\Nat$ such that\n$a = x^i$ and $b = x^j$. Then, using the fact that the group \noperation is associative and that integer addition commutes,\n$$ab = x^i \\, x^j = x^{i+j} = x^{j+i} = x^j \\, x^i = ba$$\n\\end{proof}\n\n\n\\paragraph{Exercise 6.10}\nProve that every group of prime order is cyclic.\n\n\\begin{proof}\nLet $G$ be a group such that its order $p$ is prime. Since $p > 1$, \nthere must be at least one element in $G$ whose order is greater than 1.\nLet $x$ be one such element, and let $n$ be its order. The set \n$S = \\{x^i \\, / \\, 1 \\leq i \\leq n \\}$ (equipped with $G$'s operation)\nis a subgroup of $G$, and so, by Lagrange's theorem,\n$\\Divides{n = |S|}{|G| = p}$, which implies that $n = p$. Thus, $x$ \ngenerates $G$.\n\\end{proof}\n", "meta": {"hexsha": "7a8d66312634313140ea567defb1dd8a6612cb88", "size": 2583, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter6.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter6.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter6.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 33.1153846154, "max_line_length": 78, "alphanum_fraction": 0.629113434, "num_tokens": 959, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632856092016, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.7687274109754415}}
{"text": "\\chapter{Vector}\n\n\\section{Vector space as Cartesian power of ring}\n\nA ring \\(R\\) give rises to an\n\\index{vector space}%\n\\emph{\\(n\\)-dimensional vector space} \\(R^n\\) and its vector operations.\nEach element of \\(R^n\\) is a\n\\index{vector}%\n\\emph{vector} \\((x_1,\\ldots,x_n)\\)\nwhere each \\(x_k \\in R\\).\nWe say that \\(R^n\\) is a vector space \\emph{over} ring \\(R\\).\n\n\\paragraph{Operations}\nLet \\(a \\in R\\) and \\(x,y\\in R^n\\).\nThe\n\\index{scalar multiplication}%\n\\index{multiplication!scalar and vector}%\n\\index{vector!scalar multiplication}%\n\\emph{scalar multiplication} of \\(a\\) and \\(x\\) is \\(ax \\in R^n\\) where \\((ax)_k = a x_k\\).\nThe\n\\index{vector!addition}%\n\\index{addition!vector}%\n\\emph{vector addition} of \\(x\\) and \\(y\\) is \\((x+y) \\in R^n\\) where \\((x+y)_k = x_k+y_k\\).\nThe\n\\index{inner product!vector}%\n\\index{vector!inner product}%\n\\emph{inner product} of \\(x\\) and \\(y\\) is \\(\\langle x,y \\rangle = x \\cdot y = \\sum_{k=1}^n x_k y_k\\).\n\nThe \\emph{\\(i\\)th standard basis} is \\(e_i\\) where \\((e_i)_k = \\delta_{ik}\\)\nwhere \\(\\delta_{ik} = 1_R\\) iff \\(i=k\\) and \\(0_R\\) otherwise.\n\\(0_R\\) is the additive identity of \\(R\\)\nand \\(1_R\\) multiplicative identity of \\(R\\).\n\n% FIXME use standard terms\nSuch vector space is also an inner product space.\nSuch vector space is the \\emph{natural \\(n\\)-vectorization of \\(R\\)}.\nThe \\emph{component ring} of that vector space is \\(R\\).\n\n\\section{Dual vector space}\n\nLet \\(V\\) be a vector space over ring \\(R\\).\n\nThe\n\\index{dual!vector space}%\n\\index{vector space!dual}%\n\\emph{dual} of \\(V\\) is \\(V^* = V \\to R\\).\nA\n\\index{covector}%\n\\emph{covector} is an element of \\(V^*\\).\nAnother names for covector are\n\\emph{linear form}, \\emph{linear functional}, and \\emph{one-form}.\n\n\\(V^*\\) is also a vector space\nwhere scalar multiplication is\n\\((cf)(x) = c \\cdot f(x)\\)\nand vector addition is\n\\((f+g)(x) = f(x)+g(x)\\)\nwhere \\(c \\in R\\) and \\(f,g \\in V^*\\).\n\\(f(x) = \\langle a,x\\rangle\\) defines a bijection involving \\(f:V^*\\) and \\(a:V\\).\n\nA \\emph{linear map} is a function \\(f\\) such that \\(f(x+y) = f(x) + f(y)\\)\nand \\(f(c \\cdot x) = c \\cdot f(x)\\) where \\(c\\) is a scalar.\nA linear map \\(T : R^m \\to R^n\\) can be thought\nas a vector of covectors \\(t : (R^m \\to R)^n\\) where\n\\(\n(T(x))_i = t_i(x) = \\langle a_i, x \\rangle\n\\).\nThere is a bijection between matrices and linear maps:\n\\(Mx = T(x)\\) where\n\\[\nM = \\begin{bmatrix}\\tp(a_1)\\\\\\vdots\\\\\\tp(a_m)\\end{bmatrix}\n= \\begin{bmatrix}a_{11} & \\ldots & a_{1m} \\\\ \\vdots & \\ddots & \\vdots \\\\ a_{m1} & \\ldots & a_{mm}\\end{bmatrix}\n\\]\nwhere \\(\\tp(x)\\) is the transpose of \\(x\\).\nIff $m = n$, then \\(T\\) is an \\emph{operator}.\n\nThe linear combination of \\(n\\) vectors in the same \\(n\\)-dimensional vector space:\n\\(x\\) is a linear combination of \\(e_1,\\ldots,e_n\\)\niff there exists \\(a = (a_1,\\ldots,a_n)\\)\nsuch that \\(x = a_1 \\cdot e_1 + \\ldots + a_n \\cdot e_n\\)\nwhere each \\(a_k\\) is a scalar and each \\(e_k\\) is a vector.\nWe can also write the latter equation as\n\\[\nx = E~a = a_1 \\cdot e_1 + \\ldots + a_n \\cdot e_n,\n\\]\nwhich we can also spell out into $n$ equations, each like this:\n\\[\nx_i = E_i~a = a_1 \\cdot (e_1)_i + \\ldots + a_n \\cdot (e_n)_i,\n\\]\nwhich suggests that each $E_i$ is a covector\n(you should be able to show that $E_i$ is linear).\nWe can also write the equation using matrices:\n\\[\nx =\n\\begin{bmatrix}\ne_1 & \\ldots & e_n\n\\end{bmatrix}\n\\begin{bmatrix}\na_1 \\\\ \\vdots \\\\ a_n\n\\end{bmatrix}\n\\]\nwhich we can write out in full as\n\\[\nx =\n\\begin{bmatrix}\ne_{11} & \\ldots & e_{n1}\n\\\\ \\vdots & \\ddots & \\vdots\n\\\\ e_{1n} & \\ldots & e_{nn}\n\\end{bmatrix}\n\\begin{bmatrix}\na_1 \\\\ \\vdots \\\\ a_n\n\\end{bmatrix}\n\\]\nand thus $E~a = ea$,\nwhere $e_k$ becomes the $k$th column of $e$.\nWe say that $e$ is the matrix corresponding to $E$.\nThis is an example of using matrix multiplication to specify\na linear combination of a set of vectors;\nthis matrix equation summarizes $n$ equations into one equation.\nThus there is an isomorphism between a linear endofunction in a vector space\nand multiplication of a matrix and a column vector;\nevery such endofunction has a corresponding matrix.\n\n\\section{Vector space over a field}\n\n\\index{vector space}%\n\\index{space!vector}%\nA \\emph{vector space} over a field \\(F\\) is a set \\(V\\) and the\n\\index{vector space axioms}%\n\\emph{vector space axioms} \\cite{wpvectorspace}\\cite{roman2005advanced}:\nFor all \\(a, b \\in F\\) and \\(x, y \\in V\\):\n\\begin{enumerate*}[label={(\\arabic*)}]\n    \\item \\(V\\) forms an additive group,\n    \\item \\(1 x = x\\) where \\(1\\) is the multiplicative identity of \\(F\\),\n    \\item \\((ab)x = a(bx)\\),\n    \\item \\(a(x+y) = ax+ay\\),\n    \\item \\((a+b)x = ax+by\\).\n\\end{enumerate*}\nTherefore, a vector space \\(V\\) over a field \\(F\\) is\nan additive group \\(V\\) and a \\emph{scalar multiplication} \\(F \\to V \\to V\\).\n\n\\index{vector}%\nA \\emph{vector} is an element of a vector space.\n\n\\index{vector!concatenation}%\n\\index{concatenation!vector}%\n\\index{vector concatenation}%\nThe \\emph{vector concatenation} of \\(a : \\Real^m\\) and \\(b : \\Real^n\\)\nis \\(a|b : \\Real^p\\)\nwhere \\(p = m + n\\),\n\\(a|b = (a_1 , \\ldots , a_m , b_1 , \\ldots , b_n)\\),\nand a scalar is treated as a vector of length 1.\n\n\\index{vector!column}%\n\\index{column vector}%\nA \\emph{column vector} of length \\(n\\) is a \\(n \\times 1\\) matrix.\n\n\\index{vectors!orthogonal}%\n\\index{orthogonal vectors}%\nTwo vectors \\(x\\) and \\(y\\) are \\emph{orthogonal} iff \\(x \\cdot y = 0\\).\n\\index{vectors!parallel}%\n\\index{parallel vectors}%\nTwo vectors \\(x\\) and \\(y\\) are \\emph{parallel} iff \\(x \\cdot y = \\norm{x} \\cdot \\norm{y}\\).\n\n\\index{dot product}%\n\\index{vectors!dot product}%\nRelationship between length and dot product: \\(\\norm{x}^2 = x \\cdot x\\).\nDot product distributes addition: \\(x \\cdot (y+z) = x \\cdot y + x \\cdot z\\).\nGeometric interpretation of dot product: \\(a \\cdot b = \\norm{a} \\cdot \\norm{b} \\cdot \\cos \\theta\\).\n\n\\index{unit vector}%\n\\index{vectors!unit}%\nA \\emph{unit vector} is a vector whose length is 1.\n\n\\index{vector projection}%\n\\index{vectors!projection}%\n\\index{projection!of a vector to another vector}%\nThe \\emph{projection} of \\(a\\) to \\(b\\) is \\((a \\cdot b) \\cdot b / |b|^2\\).\n\n\\section{Matrix}\n\n\\index{scalar-matrix multiplication}%\n\\emph{Scalar-matrix multiplication} is \\((ka)_{ij} = k \\cdot a_{ij}\\).\n\\index{matrix!addition}%\n\\index{addition!matrix}%\n\\emph{Matrix addition} is \\((a + b)_{ij} = a_{ij} + b_{ij}\\).\n\\index{matrix!multiplication}%\n\\index{multiplication!matrix}%\n\\emph{Matrix multiplication} is \\((ab)_{ij} = \\sum_{k=1}^n a_{ik} b_{kj}\\) where\n\\(a : R^{m \\times n}, b : R^{n \\times p}, c : R^{m \\times p}\\).\n\n\\index{coefficient matrix}%\n\\index{matrix!coefficient}%\n\\index{system of linear equations}%\n\\index{unknown}%\nA \\emph{system of linear equations} is a matrix equation \\(A x = b\\)\nwhere \\(A\\) is the \\emph{coefficient matrix} and \\(x\\) is the \\emph{unknown}.\n\\index{overdetermined system of linear equations}%\n\\index{system of linear equations!overdetermined}%\nThat system is \\emph{overdetermined} iff \\(A\\) has more rows than columns.\n\n\\section{Basis}\n\nA\n\\index{basis!of vector space}%\n\\index{vector space!basis}%\n\\emph{basis} of an \\(n\\)-dimensional vector space \\(V\\) is a set of vectors \\(\\{e_1,\\ldots,e_n\\}\\) where each \\(e_k \\in V\\)\nsuch that for every \\(v \\in V\\) there is \\(a \\in V\\) such that \\(v = \\sum_{k=1}^n a_k e_k\\).\n\nThe\n\\index{standard basis}%\n\\index{natural basis}%\n\\emph{standard basis} for \\(R^n\\) is \\(\\{ e_1, \\ldots, e_n\\}\\) where\n\\( (e_k)_i = [ k = i ] \\).\nIt is also called \\emph{natural basis}.\n\n\\section{Matrix as linear operator}\n\nThe\n\\index{span (of a matrix)}%\n\\emph{span} of \\(A \\in \\Real^{n\\times n}\\) is $\\fspan(A) = \\{ Ax ~|~ x \\in \\Real^n \\}$.\nIf we treat \\(A\\) as a linear functional,\nthen \\(\\fspan(A)\\) is the range of \\(A\\).\n\n\\section{Least-squares solution}\n\n\\index{least-squares!solution of an overdetermined system of linear equations}%\n\\index{system of linear equations!overdetermined!least-squares solution}%\n\\index{system of linear equations!least-squares solution}%\nIf \\(A : R^{m \\times n}\\) and \\(b : R^m\\),\nthen the \\emph{least-squares solution} of \\(A x = b\\)\nis the \\(y\\) that minimizes \\(\\norm{A y - b}^2\\).\n\\index{normal equation}%\nThat \\(y\\) is also the solution of the corresponding \\emph{normal equation}\n\\((A^T A) y = A^T b\\).\n\n\\section{Hyperplane}\n\n\\index{hyperplane}%\n\\index{hyperplane!below}%\n\\index{hyperplane!below-or-on}%\n\\index{hyperplane!on}%\n\\index{hyperplane!above}%\n\\index{hyperplane!above-or-on}%\nA \\emph{hyperplane}\n\\(h : \\Real^\\infty \\to \\Real\\)\nis \\(h~x = n \\cdot (x - p)\\)\nwhere \\(n\\) is the \\emph{normal} of \\(h\\)\nand \\(p\\) is a point on \\(h\\).\nThe point \\(x\\)\nis \\emph{below} \\(h\\) iff \\( h~x < 0 \\),\nis \\emph{below-or-on} \\(h\\) iff \\( h~x \\le 0 \\),\nis \\emph{on} \\(h\\) iff \\( h~x = 0 \\),\nis \\emph{above} \\(h\\) iff \\( h~x > 0 \\),\nand\nis \\emph{above-or-on} \\(h\\) iff \\( h~x \\ge 0 \\).\n\n\\index{hyperplane equation!matrix form}%\n\\index{matrix form of hyperplane equation}%\nThe \\emph{matrix form} of the hyperplane equation \\(f~x = a \\cdot x + b\\)\nis \\(f~x = (a|b)^T (x|1)\\).\n\nThe \\emph{distance} of a point \\(x\\) to hyperplane \\(h = n \\cdot (x - p)\\)\nis the length of the projection of \\(x-p\\) to \\(n\\).\n\n\\section{Matrix unary operations}\n\nThe\n\\index{transpose}%\n\\index{transpose!of matrix}%\n\\index{matrix!transpose}%\n\\emph{transpose} of \\(M\\) is \\((M^T)_{ij} = M_{ji}\\).\n\nThe\n\\index{conjugate transpose}%\n\\index{conjugate transpose!of matrix}%\n\\index{transpose!conjugate}%\n\\index{matrix!conjugate transpose}%\n\\emph{conjugate transpose} of \\(M\\) is \\((M^*)_{ij} = (M_{ji})^*\\).\n\n\\section{Special matrices}\n\n\\index{identity matrix}%\n\\index{matrix!identity}%\nA matrix \\(I : \\Real^{n \\times n}\\) is \\emph{identity} iff\n\\(\\forall (A : \\Real^{n \\times n}) (IA = AI = A)\\).\nThe \\emph{\\(n\\times n\\) identity matrix} is\n\\((I_n)_{ij} = \\delta_{ij}\\) where \\(\\delta\\) is the\n\\index{Kronecker delta}%\nKronecker delta \\(\\delta_{ij} = [i=j]\\).\n\nA matrix \\(M\\) is\n\\index{unitary matrix}%\n\\index{matrix!unitary}%\n\\emph{unitary} iff \\(M^*M = MM^* = I\\)\nwhere \\(I\\) is an identity matrix.\n\n\\section{Singular value decomposition}\n\nThe\n\\index{singular value decomposition}%\n\\index{matrix decomposition!singular value}%\n\\emph{singular value decomposition} of \\(M\\) is \\(U S V^* = M\\) where \\(V^*\\) is the conjugate transpose of \\(V\\).\n\n\\section{QR decomposition}\n\n\\(M\\) is an\n\\index{triangular matrix}%\n\\index{matrix!triangular}%\n\\emph{upper triangular matrix} iff ...\n\n\\(M\\) is an\n\\index{orthogonal matrix}%\n\\index{matrix!orthogonal}%\n\\emph{orthogonal matrix} iff ...\n\nThe\n\\index{QR decomposition}%\n\\index{matrix decomposition!QR}%\n\\emph{QR decomposition} of \\(M\\) is \\(M = QR\\) where\n\\(Q\\) is an orthogonal matrix and\n\\(R\\) is an upper triangular matrix.\n", "meta": {"hexsha": "ab19fc4b5b11667ce4fdb2c62fed3d1044faad4b", "size": 10628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/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/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/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": 32.8024691358, "max_line_length": 123, "alphanum_fraction": 0.6545916447, "num_tokens": 3722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178919837705, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.768638432362361}}
{"text": "\\documentclass[11pt]{article}\n\\usepackage{amsmath,amssymb}\n\\usepackage{lmodern}\n\\usepackage{cite}\n\\usepackage{listings}\n\\usepackage{graphicx}\n\\usepackage{minted}\n\\usepackage{url}\n\\usepackage{hyperref}\n\n\\title{sympy-nondim}\n\\author{Christoph Heindl \\\\ \\url{https://github.com/cheind} }\n\\date{\\today}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nThis Python package addresses physical dimensional analysis. In particular, \\texttt{sympy-nondim} calculates from an unknown relation of (dimensional) variables, a new relation of (usually fewer) dimensionless variables.\n\n\\section{Example}\nSuppose that you are asked to find an equation for the period of a simple frictionless pendulum (example taken from \\cite{lemons2017student}). Unaware of the solution, you may assume that the period $t$ of the pendulum depends somehow on the (massless) string length $l$, the point mass $m$, the initial release angle $\\theta$ and gravitational acceleration $g$ as shown in the following diagram.\n\\begin{center}\n\\includegraphics[width=0.3\\textwidth]{pendulum.png}\n\\end{center}\nHence, you need to find an unknown relation $$t = f(l,m,g,\\theta).$$ You plan to carry out experiments to study the value of $t$ for different values of all the independent variables in various combinations. Assuming $N$ values per variable, you will perform on the order of $N^4$, i.e $10,000$ experiments when $N=10$. \n\nUsing dimensional analysis we can a) reduce the number of experiments and b) gain insights into the unknown functional relationship of the variables. Dimensional analysis applies the principle dimensional homogeneity to manipulate a functional relationship of dimensional variables $$y = f(a,b,c,...)$$ into a new function $F$ of (usually fewer) nondimensional variables $$Y = F(A,B...).$$\n\n\\subsection{Problem setup}\nIn the pendulum case we first define the relevant symbols, their dimensions, and define the abstract equation we would like to analyze.\n\\begin{minted}{python}\nimport sympy\nfrom sympy.physics import units\n\nt, m, l, g, theta = sympy.symbols('t m l g theta')\ndimmap = {\n    t:units.time, \n    m:units.mass, \n    l:units.length, \n    g:units.acceleration, \n    theta:units.Dimension(1)\n}\n\neq = sympy.Eq(t, sympy.Function('f')(m,l,g,theta))\nprint(sympy.latex(eq))\n\\end{minted}\n$$t = f{\\left(m,l,g,\\theta \\right)}.$$\n\n\\subsection{Result}\nNext, we apply dimensional analysis\n\\begin{minted}{python}\nimport nondim\n\nr = nondim.nondim(eq, dimmap)\nprint(sympy.latex(r))\n\\end{minted}\nWhich returns a new equation\n\\begin{equation}\n    \\sqrt{\\frac{g}{l}}t = F{\\left(\\theta \\right)}. \\label{eq:A}\n\\end{equation} Note, all variable products appearing on the LHS and RHS are dimensionless. Solving for $t$ yields\n\\begin{minted}{python}\nf = sympy.Eq(t, sympy.solve(r, t)[0])\nprint(sympy.latex(f))\n\\end{minted}\n$$t = \\sqrt{\\frac{l}{g}}F{\\left(\\theta \\right)}.$$ \nDimensional analysis provides us with the following valuable insights\n\\begin{enumerate}\n    \\item The mass $m$ is irrelevant in the given problem.\n    \\item There is no need to consider an unknown function $f$ of four independent variables, instead we can reduce the search to unknown function $F$ of a single variable (initial release angle $\\theta$). Few experiments according to Equation~\\ref{eq:A} will quickly reveal that $F(\\theta)\\approx 2\\pi$ for small angles.\n    \\item Keeping $F{\\left(\\theta \\right)}$ constant, the period $t \\propto  \\sqrt{\\frac{l}{g}}$.\n\\end{enumerate}\n\nTo learn more about dimensional analysis and how it might be helpful, consider \\cite{szirtes2007applied, santiago2019first, sonin2001dimensional, lemons2017student,schetz1999fundamentals}. The method implemented in this library is based on the Buckingham-Pi theorem and the Rayleigh algorithm as explained in \\cite{szirtes2007applied}. The method implemented here frames the problem in linear algebra terms, see \\texttt{buckpi.py} for details.\n\n\\section{Mathematical Notes}\nA dimensional equation of $N_v$ variables\n\\begin{equation}\n    f(x_1,x_2,\\ldots,x_{N_v-1}) = x_{N_v} \\label{eq:fnc}\n\\end{equation}\nis dimensionally homogeneous, if it can be written as\n\\begin{equation}\n    g(\\pi_1,\\pi_2,\\ldots,\\pi_{N_p}) = 0.\n\\end{equation}\nHere $\\left\\{\\pi_1,\\pi_2,\\ldots,\\pi_{N_p}\\right\\} = \\Pi$ is a complete (and independent) set of $|\\Pi|={N_p}$ dimensionless variable products. \n\nWithout loss of generality, consider 3 variables $x,y,z$. Let $\\left[\\cdot\\right]$ denote the dimension, we require\n\\begin{align}\n    \\left[\\pi_i\\right] &= \\left[x^{\\alpha_i}y^{\\beta_i}z^{\\gamma_i} \\right] \\\\\n    &=\\left[x^{\\alpha_i}\\right]\\left[y^{\\beta_i}\\right]\\left[z^{\\gamma_i}\\right] \\\\\n    &=\\left[x\\right]^{\\alpha_i}\\left[y\\right]^{\\beta_i}\\left[z\\right]^{\\gamma_i} = 1 \\label{eq:pi}    \n\\end{align}\nfor unknown rational scalars $\\left\\{\\alpha_i,\\beta_i,\\gamma_i\\right\\}.$ In a dimensional system, each dimension is defined as product of $N_k$ base-dimensions. Assuming base-dimensions mass $M$, length $L$ and time $T$, we write \n\\begin{equation}\n    \\left[x\\right] = M^mL^lT^t, \\label{eq:xinmlt}\n\\end{equation}\nwhere the values of the scalars $\\left\\{m,l,t\\right\\}$ depend variable dimension. For example, gravitational acceleration $g$ in the $MLT$-system is given by\n\\begin{equation}\n    \\left[g\\right] = M^0L^1T^{-2}.\n\\end{equation}\n\n\\subsection{Physical dimensions as vector spaces}\nPhysical dimensions form a commutative (abelian) group $G$ under multiplication~\\cite{wiki:Dimensional_analysis}: if $M,L \\in G$, then $M^m,L^l \\in G,$ assuming $m,l \\in \\mathbb{Q}$ and also $M^m \\times L^l \\in G$. The identity is $1 = M^0$.\n\nThe group $G$ can be described as a vector space over the field of rational numbers, mapping $[x] = M^0L^1T^{-2}$ to $(0,1,-2)^T$. Dimensional multiplication corresponds then to vector addition and scalar multiplication to raising dimensional symbols to a rational power. The basis is spanned by $N_k$ canonical unit directions corresponding to the physical base dimensions. For example, mass $M$ is mapped to $(1,0,0)^T$ in a three-dimensional vector space associated with the base dimensions $MLT$. The origin $\\mathbf{0}$ of the vector space $(0,0,0)^T$ corresponds to a dimensionless quantity.\n\nUsing vector notation, we may rewrite Equation~\\ref{eq:xinmlt}\n\\begin{equation}\n    \\alpha_i[x] + \\beta_i[y] + \\gamma_i[z] = \\mathbf{0}, \\label{eq:zeroeq}\n\\end{equation}\nwhere we assume that $\\left[\\cdot\\right]$ returns the vector space mapping of the variable's dimensions. \n\n\\subsection{Determining $\\pi$}\n\nWe may rewrite Equation~\\ref{eq:zeroeq} as a matrix-vector product\n\\begin{equation}\n    \\mathbf{D}\\mathbf{v} =\\begin{pmatrix}[x] & [y] & [z]\\end{pmatrix}\\begin{pmatrix} \\alpha_i \\\\ \\beta_i \\\\ \\gamma_i\\end{pmatrix} = \\mathbf{0},\n\\end{equation}\nwhere $\\mathbf{D}$ is the $N_k \\times N_v$ dimensional matrix. Hence, determining $\\Pi$ becomes equivalent to the problem of finding a set of vectors $\\mathbf{v}$ for which\n\\begin{equation}\n    \\mathbf{D}\\mathbf{v}=\\mathbf{0}.\n\\end{equation}\nThe set of vectors $\\{\\mathbf{v} \\mid \\mathbf{D}\\mathbf{v}=\\mathbf{0}\\}$ span a sub-space of the domain of the linear map $\\mathbf{D}$: the null-space. The dimensionality of the null-space is given by the rank-nullity theorem\n\\begin{equation}\n    N_p = N_v - \\text{rank}(\\mathbf{M}) = \\text{nullity}(\\mathbf{M}) = |\\Pi|,\n\\end{equation}\nand determines the number of independent dimensionless products. The span of the null-space is not unique and this leads potentially different $\\Pi$ sets. For practical purposes one should try to find a basis in which variables of interest will appear in only one of the $\\pi$ terms. That's always possible as long of the variables of interest are 'free' variables. \n\n\\subsection{Specific solutions}\nWhen the non-dimensionalization of Equation~\\ref{eq:fnc} results in a single $\\pi$ term\n\\begin{equation}\n    g(\\pi_1) = 0,\n\\end{equation}\nthen $\\pi_1$ is a root of $g$. Assuming $g$ has only a single root (or discrete number of them), we see $\\pi_1$ itself must be an (unknown) constant\n\\begin{equation}\n    \\pi_1 = c.\n\\end{equation}\nWhen $g$ is a function of more than one dimensionless product\n\\begin{equation}\n    g(\\pi_1, \\pi_2) = 0,\n\\end{equation}\nwe may invoke the Implicit Function Theorem to solve for one of the arguments and write instead\n\\begin{equation}\n    \\pi_1 = h_1(\\pi_2).\n\\end{equation}\nSimilarly for three arguments $g(\\pi_1, \\pi_2, \\pi_3) = 0$ we have\n\\begin{equation}\n    \\pi_1 = h_2(\\pi_2, \\pi_3).\n\\end{equation}\n\n\\subsection{References}\n\\bibliographystyle{alpha}\n\\begingroup\n\\renewcommand{\\section}[2]{}%\n\\bibliography{biblio}\n\\endgroup\n\n\\end{document}\n", "meta": {"hexsha": "c8db1a140be041a5df5de8deaa7cb5a2fc3cae47", "size": 8558, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/nondim-sympy.tex", "max_stars_repo_name": "cheind/sympy-nondim", "max_stars_repo_head_hexsha": "755110bdd762935e38850a959785a2ffedcaf4ba", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 4, "max_stars_repo_stars_event_min_datetime": "2021-01-20T13:24:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-11T20:08:30.000Z", "max_issues_repo_path": "docs/nondim-sympy.tex", "max_issues_repo_name": "cheind/sympy-nondim", "max_issues_repo_head_hexsha": "755110bdd762935e38850a959785a2ffedcaf4ba", "max_issues_repo_licenses": ["MIT"], "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/nondim-sympy.tex", "max_forks_repo_name": "cheind/sympy-nondim", "max_forks_repo_head_hexsha": "755110bdd762935e38850a959785a2ffedcaf4ba", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-02-13T20:50:59.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-13T20:50:59.000Z", "avg_line_length": 53.8238993711, "max_line_length": 597, "alphanum_fraction": 0.7335826128, "num_tokens": 2531, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8774767794716264, "lm_q1q2_score": 0.7684827574687756}}
{"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+1)^n}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\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| \\frac{1}{(n+1)^n} \\right|}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{1}{n+1}\\\\\r\n&= 0.\r\n\\end{align*}\r\nSince $L < 1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{(n+1)^n}$ converges absolutely by the Root Test.\r\n\r\n\\subsection*{Solution 2: much longer than Solution 1}\r\n\r\nIn an attempt to use the Ratio Test, you'd have to 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+2)^{n+1}}\\frac{(n+1)^n}{1}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{(n+1)^n}{(n+2)^{n+1}},\r\n\\end{align*}\r\nbut it looks like there's not any really nice limit here, and while L'Hopital's rule applies, it will be quite a mess. Actually, it is possible to evaluate this limit using some algebra and some limit laws:\r\n\\begin{align*}\r\n&= \\lim_{n \\to \\infty} \\frac{(n+1)^n}{(n+2)^{n+1}}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{(n+1)^n}{(n+2)^n(n+2)}\\\\\r\n&= \\lim_{n \\to \\infty} \\left[\\left(\\frac{n+1}{n+2}\\right)^n \\cdot \\frac1{n+2}\\right].\r\n\\end{align*}\r\nWe consider the limit \r\n\\[\\lim_{n \\to \\infty} \\left(\\frac{n+1}{n+2}\\right)^n\\]\r\nby defining $y = \\left(\\frac{n+1}{n+2}\\right)^n$. So $\\ln y = n \\ln \\frac{n+1}{n+2}$. So\r\n\\[ \\ln y = \\frac{\\ln \\frac{n+1}{n+2}}{\\frac1n}\\]\r\nBy applying a limit to both sides,\r\n\\[ \\lim_{n \\to \\infty}\\ln y = \\lim_{n \\to \\infty} \\frac{\\ln \\frac{n+1}{n+2}}{\\frac1n}\\]\r\nand the limit on the right uses L'Hopital's rule. (Be sure to pay attention to the Chain Rule and the Quotient Rule.)\r\n\\begin{align*}\r\n&=\\lim_{n \\to \\infty} \\frac{ \\frac{n+2}{n+1} \\cdot \\frac{(n+2)\\cdot 1 - (n+1) \\cdot 1}{(n+2)^2}}{\\frac{-1}{n^2}}\\\\\r\n&=\\lim_{n \\to \\infty} \\frac{-n^2}{(n+1)(n+2)}\\\\\r\n&=-1.\r\n\\end{align*}\r\nafter two more applications of L'Hopital's rule. Thus, \r\n\\[ \\lim_{n \\to \\infty} y = e^{-1} = \\frac1e.\\]\r\nWe were originally considering the limit:\r\n\\begin{align*}\r\n&\\lim_{n \\to \\infty} \\left[\\left(\\frac{n+1}{n+2}\\right)^n \\cdot \\frac1{n+2}\\right]\r\n&= \\left[ \\lim_{n \\to \\infty} \\left(\\frac{n+1}{n+2}\\right)^n \\right] \\cdot \\left[\\lim_{n \\to \\infty} \\frac1{n+2}\\right]\r\n&= \\frac1e \\cdot 0\r\n&= 0.\r\n\\end{align*}\r\nand we could treat the limit of the product as a product of the limits because both limits existed. Since $L < 1$, the series  $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{(n+1)^n}$ converges absolutely by the Ratio Test.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "59f6be6ebefa00bb72eb323b8e9c382628f9651a", "size": 3437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/l3.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/l3.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/l3.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": 39.5057471264, "max_line_length": 219, "alphanum_fraction": 0.6112889148, "num_tokens": 1357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.8774767746654976, "lm_q1q2_score": 0.7684827532596306}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\\title{A Small Collection Of Mathematical Formulas For The \nProspective Statistician}\n\\author{Joshua Simon  \\\\\n\tOtto-Friedrich-University Bamberg \\\\\n\t}\n\n\\date{\\today}\n\n% Packages.\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\n\n\\begin{document}\n\n\\maketitle\n\n\n%\\begin{abstract}\n%Short introduction to subject of the paper \\ldots \n%\\end{abstract}\n\n\\section{Arithmetic}\n\\paragraph{Logarithms.} In the following let $a$, $b > 0$ and $n \\in \\mathbb{R}$. Then\n\\begin{gather*}\n    ln(a \\cdot b) = ln(a) + ln(b) \\\\\n    ln(\\frac{a}{b}) = ln(a) - ln(b) \\\\\n    ln(a^n) = n \\cdot ln(a) \\\\\n    e^{ln(a)} = ln(e^{a}) = a.\n\\end{gather*}\n\n\\paragraph{Binomial Coefficient.} Suppose $0 < k \\leq n$. Then\n\\begin{gather*}\n    \\binom{n}{k} = \\frac{n!}{k! \\cdot (n-k)!}\n\\end{gather*}\nwhere $n! = 1 \\cdot 2 \\cdot \\ldots \\cdot n$.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Differential Calculus} \\label{DifferentialCalculus}\n\\paragraph{Elementary Derivatives.} In the following let $f$ be a real-valued function of $x$ and $a, b, r \\in \\mathbb{R}$. Then the derivative of $f$ is given by $f'$ as\n\n\\begin{align*}\n    f(x) = x^r &\\rightarrow f'(x) = r \\cdot x^{r - 1} \n    &f(x) = e^x &\\rightarrow f'(x) = e^x \\\\\n    f(x) = r^x &\\rightarrow f'(x) = r^x \\cdot ln(r) \n    &f(x) = e^{a \\cdot x + b} &\\rightarrow f'(x) = a \\cdot e^{a \\cdot x + b} \\\\\n    f(x) = \\frac{1}{x^r}  &\\rightarrow f'(x) = - r \\cdot x^{-r - 1}\n    &f(x) = sin(x) &\\rightarrow f'(x) = cos(x) \\\\\n    f(x) = ln(x) &\\rightarrow f'(x) = \\frac{1}{x} \n    &f(x) = cos(x) &\\rightarrow f'(x) = - sin(x).\n\\end{align*}\n\n\\paragraph{Differentiation rules.} In the following let $h, u, v$ be real-valued functions of $x$.\n\\begin{itemize}\n    \\item Product Rule: $h(x) = u(x) \\cdot v(x) \\rightarrow h'(x) = u'(x) \\cdot v(x) + u(x) \\cdot v'(x)$\n    \\item Chain Rule: $h(x) = u(v(x)) \\rightarrow  h'(x) = u'(v(x)) \\cdot v'(x)$\n    \\item Reciprocal Rule: $h(x) = \\frac{1}{v(x)} \\rightarrow  h'(x) = \\frac{v'(x)}{(v(x))^2}$\n    \\item Quotient Rule: $h(x) = \\frac{u(x)}{v(x)} \\rightarrow  h'(x) = \\frac{v(x)u'(x) - u(x)v'(x)}{(v(x))^2}$\n\\end{itemize}\n\n\\paragraph{Gradient.} Let $f$ be a differentiable fuction of $n$ variables. Then\n\\begin{gather*}\n    \\mathbf{grad}(f) = \\nabla f = \\left( \\frac{\\partial}{\\partial x_1} f(x) \\dots \\frac{\\partial}{\\partial x_n} f(x) \\right)^T.\n\\end{gather*}\n\n\\paragraph{Jacobian Matrix.} Let $f: \\mathbb{R}^{n} \\rightarrow \\mathbb{R}^{m}$ be a differentiable function of $n$ variables. Then the Jacobian matrix $\\mathbf {J}$ of $f$ is an $m \\times n$ matrix whose $(i,j)$th entry is ${\\mathbf {J}_{ij}={\\frac {\\partial f_{i}}{\\partial x_{j}}}}$. Which is \n\\begin{gather*}\n    {\\mathbf {J} ={\\begin{bmatrix}{\\dfrac {\\partial f }{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial f }{\\partial x_{n}}}\\end{bmatrix}}={\\begin{bmatrix}\\nabla ^{T}f_{1}\\\\\\vdots \\\\\\nabla ^{T}f_{m}\\end{bmatrix}}={\\begin{bmatrix}{\\dfrac {\\partial f_{1}}{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial f_{1}}{\\partial x_{n}}}\\\\\\vdots &\\ddots &\\vdots \\\\{\\dfrac {\\partial f_{m}}{\\partial x_{1}}}&\\cdots &{\\dfrac {\\partial f_{m}}{\\partial x_{n}}}\\end{bmatrix}}}\n\\end{gather*}\nwhere ${\\nabla ^{T}f_{i}}$ is the transpose (row vector) of the gradient of the $i$th component.\n\n\\paragraph{Symmetry Of Second Derivatives (Schwarz's theorem).} The order of taking partial derivatives of a function $f(x) = f(x_1, x_2, \\dots , x_n)$ of $n$ variables is interchangeable\n\\begin{gather*}\n    \\frac{\\partial}{\\partial x_i} \\left( \\frac{\\partial}{\\partial x_j} f(x) \\right) = \\frac{\\partial}{\\partial x_j} \\left( \\frac{\\partial}{\\partial x_i} f(x) \\right).\n\\end{gather*}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\section{Integral Calculus} \\label{integralCalculus}\n\n\\paragraph{Fundamental Theorem Of Calculus.} \nLet  $f$ be a real-valued function on a closed interval $[a,b]$ and $F$ an antiderivative of $f$ in $[a,b]$: $F'(x)=f(x)$. If $f$ is Riemann integrable on $[a,b]$ then\n\\begin{gather*}\n    \\int _{a}^{b}f(x)\\,dx=F(b)-F(a).\n\\end{gather*}\n\n\\paragraph{Elementary Integrals.}\n\\begin{align*}\n    \\int x^r dx &= \\frac{x^{r + 1}}{r+1} + C \\text{ with } (r \\neq -1) \n    &\\int e^x dx &= e^x + C \\\\\n    \\int r^x dx &= \\frac{r^{x}}{ln(r)} + C \\text{ with } (r > 1, r \\neq 1) \n    &\\int e^{a \\cdot x + b} dx &= \\frac{e^{a \\cdot x + b}}{a} + C \\\\\n    \\int \\frac{1}{x} dx &= ln(x) + C \n    &\\int ln(x) dx &= x \\cdot (ln(x) - 1) + C \\\\\n    \\int \\frac{1}{x^2} dx &= - \\frac{1}{x} + C \n    &\\int sin(x) dx &= - cos(x) + C \\\\\n    \\int \\frac{1}{x^3} dx &= - \\frac{1}{2x^2} + C\n    &\\int cos(x) dx &= sin(x) + C\n\\end{align*}\n\n\\paragraph{Integration By Parts.} Let $u$ and $v$ be two continuously differentiable functions of $x$ in $[a,b]$. Then\n\\begin{gather*}\n   \\int_{a}^{b} u(x)v'(x) dx = \\left[ u(x)v(x) \\right]_a^b - \\int_{a}^{b} u'(x)v(x) dx.\n\\end{gather*}\n\n\\paragraph{Integration By Substitution.} Let $I$ be an real interval, $f: I \\rightarrow \\mathbb{R}$ a continuous function and $\\varphi: [a,b] \\rightarrow I$ continuously differentiable. Then\n\\begin{gather*}\n    \\int _{a}^{b}f(\\varphi (x))\\varphi '(x)\\,dx=\\int _{\\varphi (a)}^{\\varphi (b)}f(u)\\,du.\n\\end{gather*}\nThe substitution $u = \\varphi(x)$ yields ${\\frac {du}{dx}}=\\varphi '(x)$ which leads to $du=\\varphi '(x) \\,dx$.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\begin{thebibliography}{9}\n    \\bibitem[Bron]{Bron} \\emph{Taschenbuch der Mathematik.}\n    I. N. Bronstein, K. A. Semendjajew, G. Musiol, H. Mühlig, 11. Auflage, 2020.\n\\end{thebibliography}\n\n\\end{document}", "meta": {"hexsha": "0d67b053f9c03ff6feedf1d0448da4dfad3b38e1", "size": 5549, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Formelsammlung/formelsammlung.tex", "max_stars_repo_name": "JoshuaSimon/University-Projects", "max_stars_repo_head_hexsha": "9d2e9c7ace3725acea7242bd69826349ef97b63f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Formelsammlung/formelsammlung.tex", "max_issues_repo_name": "JoshuaSimon/University-Projects", "max_issues_repo_head_hexsha": "9d2e9c7ace3725acea7242bd69826349ef97b63f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Formelsammlung/formelsammlung.tex", "max_forks_repo_name": "JoshuaSimon/University-Projects", "max_forks_repo_head_hexsha": "9d2e9c7ace3725acea7242bd69826349ef97b63f", "max_forks_repo_licenses": ["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.6929133858, "max_line_length": 448, "alphanum_fraction": 0.5813660119, "num_tokens": 2114, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869786798663, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7684827389582434}}
{"text": "\\section{Background}\n\n\\subsection{Hidden Markov Model}\nA hidden Markov model assumes that the system follows a Markov process. For this\npaper, we will assume a finite number of states and observations. The\nprobability of transitioning from state $i$ to state $j$ only depends on the\ncurrent state, and we define transition matrix $A$ such that element $a_{ij}$ is\nthe probability  of transitioning from $i$ to $j$. In an HMM, we cannot observe\nstates, but we can observe outputs generated by the states. Given $N$ states and\n$M$ observations, we capture this with a $N \\times M$ emission matrix $B$, where\neach element $b_{ij}$ is the probability of observation $j$ given the state is $i$. Finally, we define a $N$ length vector as $\\pi$ as the prior, where $\\pi_i$ is the probability of initial state being $i$. \n\nWe can thus capture all the information about an HMM with $\\theta = (A, B, \\pi)$. In an HMM, we are given a sequence of $T$ observations, and we will use a series of forward and backwards propagations to estimate the parameters $\\theta = (A, B, \\pi)$.\n\n\\subsection{Baum-Welch}\n\nThe following explanation is based on Wikipedia's presentation of the\nalgorithm~\\cite{bwwiki}.\n\nLet $(X_1, X_2, \\ldots, X_N)$ denote the $N$ states and $\\bold{O} = \\{O_1, O_2, \\ldots, O_T\\}$ the $T$ observed outputs. The Baum-Welch algorithm uses expectation-maximization to find the maximum likelihood estimate.\n\nSuppose we begin with some initial parameters, $\\theta  =  (A, B, \\pi)$.  Given the observation sequence, our task is to update these parameters based on insights from the training sequence.  \n\nGiven our training sequence, Baum-Welch first figures out the probability of being in a state at some time in the ``run\" of the observation sequence.  Let's call this $\\gamma_{i}(t)$, the ``probability of being in state $i$ at time $t$ of this observation sequence given our current model parameters,\" $P(X_t = i | \\bold{O}, \\theta)$.\n\nHow can we figure this out? To do this, the Baum-Welch algorithm performs two sub-calculations, for the ``forward probabilities\" and the ``backward probabilities.\"  Like $\\gamma_i(t)$ values, the forward probability are computed for each ($\\textit{state}, \\textit{time}$) pair: given some observation sequence and our current moel, the forward probability $\\alpha_i(t)$ is the probability of seeing the observation sequence up to time $t$ and landing in state $i$.  The backward probability is defined analogously: it's the probability of starting in some state $i$ and seeing the observation sequence \\textit{from} time $t$ until the end.\n\nWe can define the forward and backward probabilities recursively:\n\n\\begin{equation} \\label{alpha}\n\\alpha_i(t+1) =  b_{jo_1}\\sum_{i=1}^{N} \\alpha_i(t)a_{ij}\n\\end{equation}\n\n\\begin{equation} \\label{beta}\n\\beta_i(t) = \\sum_{i=1}^N \\beta_j(t+1)a_{ij}b_j(o_{t+1})\n\\end{equation}\n\nWe can put the alpha and beta probabilities together to find $\\gamma_i(t)$.  Some intuition for this formula: the bottom is the probability of being in \\textit{some state} at time $t$ given our \\textit{entire} observation sequence.  The top is the probability of being in some particular state $i$ at time $t$ given our \\textit{entire} observation sequence.  For both numerator and denominator, you have to get to the state at that time (forward probability) and leave from the state next and finish emitting the observation sequence  (backward probability).\n\n\\begin{equation} \\label{gamma}\n\\gamma_i(t) = P(X_t = i | \\bold{O}, \\theta) = \\frac{\\alpha_i(t) \\beta_i(t)}{\\sum_{j=1}^N \\alpha_j(t) \\beta_j(t)}\n\\end{equation}\n\nFrom here, we can figure out our updates for the $B$ matrix and the new prior. \n\n$B$ can be updated by: \n\\begin{equation}\\label{b}\nb^*_{i,v_k} = \\frac{\\sum_{t=1}^{T}1_{o_t = v_k} \\gamma_i(t)}{\\sum_{t=1}^T \\gamma_i(t)}\n\\end{equation}\nwhere $1_{o_t = v_k}$ is $1$ if $o_t = v_k$ and $0$ otherwise. \n\nIntuition: the update for  $b^*_{i,v_k}$ is just the frequency across the entire observation sequence of being in the state $i$ and seeing $v_k$.\n\nThe new prior can be determined by\n\n\\begin{equation}\\label{pi}\n\\pi_i^* = \\gamma_i(0)\n\\end{equation}\n\nIntuition: this is the probability of being in state $i$ before the observation sequence begins.  \n\nTo update the $A$ matrix (each $a_{ij}$ entry), we need to figure  out the\nprobability of being in state $i$ and $\\textit{moving}$ to state $j$ next.\nFortunately, this calculation can be done in a straightforward way, and we can\nthink of it as a ``relative frequency calculation\" of the transitions that begin\nat state $i$ and go to state $j$ compared to the transitions through state $i$.\nThis ``relative frequency intuition\" is provided by Rabiner and Juang~\\cite{rabiner1986introduction}.\n\nDefine $\\xi_{ij}(t)$ to be the probability of being in state $i$ at time $t$ and state $j$ at time $t+1$ given $\\bold{O}$ and parameter $\\theta$. \n\\begin{equation}\\label{xi}\n\\begin{aligned}\n\\xi_{ij}(t) &= P(X_t = i, X_{t+1} = j | \\bold{O}, \\theta)  \\\\\n&=\\frac{\\alpha_i(t) a_{ij} \\beta_j(t+1)b_{j}(o_{t+1})}{\\sum_{k=1}^N \\alpha_k(t) \\beta_k(t)}\n\\end{aligned}\n\\end{equation}\nFinally, $A$ can be updated by: \n\n\\begin{equation}\\label{a}\na^*_{ij} = \\frac{\\sum_{t=1}^{T-1}\\xi_{ij}(t)}{\\sum_{t=1}^{T-1}\\gamma_i(t)}\n\\end{equation}\n\nThese steps are repeated until the parameters converge. \n\n\\subsection{Prior Work}\n\nHere we review prior work related to \\textit{parallelization} of hidden Markov\nmodels specifically.  In 2009, Chuan Liu conducted an independent project aiming\nto implement HMM training in parallel on CUDA.  The project's parallelization\nforward-backward probabilities computation inspired our design.  The rest of his\nwork frames computations in terms of matrix multiplication operations.  His work\nalso utilizes ``parallel reduction\" for computing the sum of a vector, something\nwe've seen in CS205~\\cite{cuda-hmm}.\n\nAlso, we noted the approach of Li et. al in 2010, applying an earlier\nparallelization approach---``cut and stitch''---to the problem of hidden Markov\nmodel training.  The ``cut and stitch\" approach parallelizes along the length of\nthe input observation sequence (along the $T$-axis).  The graph parallel scheme\nin this paper is orthogonal to the ``cut and stitch\" approach, and we are\nexcited about the prospect of applying these two parallelization schemes to the\nproblem of HMM training~\\cite{cut-stitch}.\n", "meta": {"hexsha": "c7d0a896929d0f76fde262b0eae4f3ea4262e18b", "size": 6346, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/background.tex", "max_stars_repo_name": "cs205-project-group/hmm", "max_stars_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-05-10T04:53:33.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-10T04:53:33.000Z", "max_issues_repo_path": "paper/background.tex", "max_issues_repo_name": "cs205-project-group/hmm", "max_issues_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "paper/background.tex", "max_forks_repo_name": "cs205-project-group/hmm", "max_forks_repo_head_hexsha": "4690750f9c2369a880f9b446dc0784cdcb572249", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.8316831683, "max_line_length": 639, "alphanum_fraction": 0.7388906398, "num_tokens": 1782, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.7684421942452798}}
{"text": "\n\\subsection{Delta rule}\n\n\\subsubsection{Introduction}\n\nWe want to train the parameters \\(\\theta \\).\n\nWe can do this with gradient descent, by working out how much the loss function falls as we change each parameter.\n\nThe delta rule tells us how to do this.\n\n\\subsubsection{The loss function}\n\nThe error of the network is:\n\n\\(E=\\sum_j\\dfrac{1}{2}(y_j-a_j)^2\\)\n\nWe know that \\(a_j=a(\\theta x_j)\\) and so:\n\n\\(E=\\sum_j\\dfrac{1}{2}(y_j-a(\\theta x_j))^2\\)\n\n\\subsubsection{Minimising loss}\n\nWe can see the change in error as we change the parameter:\n\n\\(\\dfrac{\\delta E}{\\delta \\theta_i }=\\sum_j \\dfrac{\\delta E}{\\delta a_j}\\dfrac{\\delta a_j}{\\delta z_j}\\dfrac{\\delta z_j}{\\delta \\theta_i}\\)\n\n\\(\\dfrac{\\delta E}{\\delta \\theta_i }=-\\sum_j(y_j-a_j)a'(z_j)x_{ij}\\)\n\n\\subsubsection{Delta}\n\nWe define delta as:\n\n\\(\\delta_i=-\\dfrac{\\delta E}{\\delta z_j}=\\sum_j(y_j-a_j)a'(z_j)\\)\n\nSo:\n\n\\(\\dfrac{\\delta E}{\\delta \\theta_i }=\\delta_i x_{ij}\\)\n\n\\subsubsection{The delta rule}\n\nWe update the parameters using gradient descent:\n\n\\(\\Delta \\theta_i=\\alpha \\delta_i x_{ij}\\)\n\n", "meta": {"hexsha": "d4e08fa9c462086b64563f9a0d01b6a82fba2dcb", "size": 1054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glm/02-01-deltaRule.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glm/02-01-deltaRule.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glm/02-01-deltaRule.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.9130434783, "max_line_length": 139, "alphanum_fraction": 0.6944971537, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067179697695, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7683620915749986}}
{"text": "% !TEX root = main.tex\n\n\\chapter[Complex Numbers and Functions]{Preliminaries on Complex Numbers and Functions}\n\n\\section{Basic Definitions and Algebraic Operations}\n\nFormally, a \\emph{complex number} is an ordered pair $(x,y)$ of real numbers.  We denote the set of all complex numbers by $\\mathbb{C}$, and define addition and multiplication on $\\C$ as follows:\n\\begin{enumerate}\n\\item[(i)] $(x_1,y_1)+(x_2,y_2) = (x_1+x_2,y_1+y_2)$,\n\\item[(ii)] $(x_1,y_1)(x_2,y_2) = (x_1x_2-y_1y_2,x_1y_2+x_2y_1)$.\n\\end{enumerate}\nWith this definition, $\\C$ and $\\R^2$ are equal \\emph{as sets}, however, we have also defined an operation of multiplication on $\\C$.\n\n\nThe subset of $\\C$ given by \n\\[\n\\set{(x,0): x \\in \\R } \n\\]\nis called the \\emph{real axis}.  For complex numbers in this subset we have\n\\begin{align*}\n(x_1,0)+(x_2,0) & = (x_1+x_2,0) \\\\\n(x_1,0)(x_2,0) &= (x_1x_2,0), \n\\end{align*}\nso these complex numbers behave exactly like real numbers.  For this reason, we shall use $\\R$ to refer to the real axis and denote the complex number $(x,0)$ by $x$.\n\n\n\nWriting $i=(0,1)$, the definition of multiplication in $\\C$ gives $i^2=-1$. With this notation, we get a more familiar `definition': a complex number $z=(x,y)$ can be written as\n\\begin{align*}\nz = (x,y) &= (x,0)+(y,0)(0,1) \\\\\n& = x + iy.\n\\end{align*}\n\n\nThe real numbers $x$ and $y$ are the \\emph{real} and \\emph{imaginary} parts of $z$ respectively, and we often write\n\\[\n\\Re (z) = x,\\quad \\Im (z)=y.\n\\]\nNote that the imaginary part of $z$ is \\emph{real}.   \n\nWith this more familiar notation, the algebraic operations of addition and multiplication on $\\mathbb{C}$ can be expressed as follows: for $z_1=x_1+iy_1$ and $z_2=x_2+iy_2 \\in \\mathbb{C}$, we have\n\\begin{align*}\nz_1 +z_2  &= (x_1+x_2) + i (y_1+y_2) \\\\\nz_1z_2 & = (x_1+iy_1)(x_2+iy_2) \\\\\n& = x_1x_2 + i (x_1y_2) + i (y_1x_2) + (i)^2(y_1y_2) \\\\\n& = (x_1x_2-y_1y_2) + i (x_1y_2+x_2y_1).\n\\end{align*}\n\n\nNote in particular that for $r \\in \\R$ and $z = x+iy \\in \\C$ we have\n\\[\nrz = r(x+iy) = rx+iry.\n\\]\n\n\n\n\n\nIt is convenient to identify the complex number $z \\in \\C$ with the point (or sometimes, the vector) $(\\Re (z), \\Im (z) ) \\in \\R^2$.  Obviously the map $z \\mapsto ( \\Re (z), \\Im (z))$ is a bijection $\\C \\to \\R^2$, and thus geometrically, we view $\\C$ as $\\R^2$.\n\n\n\n\n\\begin{definition}[Complex Conjugate]\nGiven $ z \\in \\mathbb{C}$, the \\emph{complex conjugate} $\\overline{z}$ of $z$ is defined as\n\\[\n\\overline{z} := \\Re (z) - i\\ \\Im (z). \n\\]\n\\end{definition}\n\n\\begin{definition}[Modulus]\nGiven $z \\in \\mathbb{C}$, we define the modulus of $z$ to be\n\\[\n| z | : = \\sqrt{ \\Re (z)^2 + \\Im (z)^2 }.\n\\]\n\\end{definition}\n\\\nIn other words, for $z=x+iy$, $\\conj{z}=x-iy$ and $\\abs{z} = \\sqrt{x^2+y^2}$.\n\n\nGeometrically, the complex conjugate of $z$ describes the reflection of $z$ through the real axis, and the modulus of $z$ is the distance of $z$ from the origin.\n\n\n\\begin{proposition}\n\\label{p:absmod}\nLet $z,z_1,z_2 \\in \\C$ be given.\nThen:\n\\begin{enumerate}\n%\\item $i^2 = -1$.\n\\item[(i)] $\\conj{\\conj{z}} = z$ and $\\abs{\\conj{z}} = \\abs{z}$.\n\\item[(ii)] $\\abs{z} = \\sqrt{\\conj{z}z}$\n\\item[(iii)] $\\conj{z_1+z_2} = \\conj{z_1} + \\conj{z_2}$ and $\\conj{z_1z_2} = \\conj{z_1}\\ \\conj{z_2}$.\n\\item[(iv)] $\\conj{z} = z$ if and only if $z$ is real, i.e., if and only if $\\Im (z)=0$.\n\\item[(v)] $\\Re (z) = \\displaystyle\\frac{z + \\conj{z}}{2}$ and $\\Im (z) = \\displaystyle\\frac{z - \\conj{z}}{2i}$.\n\\item[(vi)] $\\abs{z} = 0$ if and only if $z = 0$.\n\\item[(vii)] $\\abs{z_1 \\pm z_2} \\leq \\abs{z_1} + \\abs{z_2}$ \\emph{(Triangle Inequality)}.\n\\item[(viii)] $\\abs{z_1 \\pm z_2} \\geq \\abs{\\abs{z_1} - \\abs{z_2}}$ \\emph{(Reverse Triangle Inequality)}.\n\\item[(ix)] $\\abs{z_1z_2} = \\abs{z_1} \\abs{z_2}$.\n\\end{enumerate}\n\\end{proposition}\nYou really should be familiar with all of these properties.  I would suggest trying to prove at least some of them, or verifying them for some specific choices of $z_1$ and $z_2$. Most of the proofs are short.\n\n\\begin{question}\nThe rules of multiplication allow us to divide a complex number $z$ by a nonzero real number $r$; i.e.\n\\[\n\\frac{z}{r} = \\left( \\frac{1}{r} \\right) z.\n\\]\nHow do we define division of complex numbers?\n\\end{question}\n\\begin{answer}\nFor a complex number $z \\neq 0$, we first define the multiplicative inverse of $z$, denoted $z^{-1}$ or $\\frac{1}{z}$.  Note that  by Proposition~\\ref{p:absmod} (ii), we have $\\abs{z}^2 = z \\conj{z}$.  Since $\\abs{z}$ is real, we may  define the complex number\n\\[\n\\frac{\\conj{z}}{\\abs{z}^2}\n\\]\nwhich must satisfy\n\\[\nz \\brac{ \\frac{\\conj{z}}{\\abs{z}^2} } = \\frac{z \\conj{z}}{z \\conj{z}} = \\frac{\\abs{z}^2}{\\abs{z}^2} = 1.\n\\]\nIt follows that the multiplicative inverse of $z$ is\n\\[\nz^{-1} = \\frac{\\conj{z}}{\\abs{z}^2}.\n\\]\nWith this in mind, we may divide any complex number $z_1$ by any nonzero complex number $z_2$ as follows:\n\\[\n\\frac{z_1}{z_2} = z_1 z_2^{-1} = \\frac{z_1\\conj{z_2}}{\\abs{z_2}^2}.\n\\]\n\\end{answer}\n\n\\begin{definition}[Argument]\nThe \\emph{argument} of a complex number $z \\neq 0$ is the angle $\\arg (z)$ from the positive real axis to the vector representing $z$ in the anticlockwise direction.  \n\\end{definition}\nOf course negative values of $arg(z)$ are allowed: these values represent angles taken in the clockwise direction.  Note that there are typically many ways in which we can represent $\\arg (z)$, since we identify any two angles that differ by an integer multiple of $2\\pi$ with one another.  For instance, for (the complex number) $z=1$ any of the angles\n\\[\n\\ldots,-4\\pi, -2\\pi, 0, 2 \\pi , 4\\pi,\\ldots\n\\]\nare valid choices for $\\arg (z)$.   Similarly, if we look at $z=-1-i$:\n%\\begin{center}\n%\\includegraphics[scale=1]{arg}\n%\\end{center}\nWe can write $\\arg (z) = \\frac{5\\pi}{4}$ or $\\arg (z)=- \\frac{3\\pi}{4}$ (or indeed an integer multiple of $2\\pi$ added to either of these angles).\n\n\n\n\nBy convention we usually take $\\arg (z) \\in (-\\pi , \\pi]$.\n\\begin{definition}\nFor $z \\in \\C$, $z \\neq 0$, we define the \\emph{Principal argument of $z$} (or the \\emph{Principal value of $\\arg(z)$}) to be the value of $\\arg (z)$ that lies in $(-\\pi,\\pi]$. We shall denote this value by $\\Arg (z)$.\n\\end{definition}\nSo for $z=-1-i$ we have $\\Arg (z) = - \\frac{3 \\pi}{4}$, while $\\arg (z)$ can be taken to be any of the values\n\\[\n\\ldots, - \\frac{11\\pi}{4}, - \\frac{3\\pi}{4}, \\frac{5\\pi}{4}, \\frac{13\\pi}{4}, \\ldots.\n\\]\n\n\n\\begin{definition}\nThe \\emph{polar form} of a complex number $z$ is given by writing $z$ in the form\n\\[\nz = r \\left( \\cos (\\theta) + i \\sin (\\theta) \\right),\n\\]\nwhere $r , \\theta \\in \\R$ and $r \\geq 0$.\n\\end{definition}\nThe polar form of $z$ is found by setting $r = \\abs{z}$ and $\\theta = \\arg (z)$ (any value of $\\arg(z)$ will of course suffice).  Equivalently, we may write\n\\[\nz = r e^{i \\theta}\n\\]\n(though we have yet to define the complex exponential function).  For completeness, we should specify that the polar form of $0$ is simply $0$, since $\\arg (0)$ is not defined.\n\n\n\n\\begin{definition}\nLet $w=r \\left( \\cos( \\theta) + i \\sin ( \\theta) \\right)$ be (the polar form of) a complex number.  Then the $n^{th}$ \\emph{complex roots} of $w$ are defined to be the $n$ solutions $z_0, z_1, \\ldots , z_{n-1}$ of the equation $z^n = w$.  These roots are given by\n\\[\nz_k = \\sqrt[n]{r} \\left( \\cos \\left( \\frac{\\theta+2k \\pi}{n} \\right) + i \\sin \\left( \\frac{\\theta + 2k\\pi}{n} \\right) \\right),\n\\]\nfor $k=0,1,\\ldots,n-1$, where $\\sqrt[n]{r}$ is the (positive) $n^{th}$ real root of $r$.\n\\end{definition}\n\n\n\\begin{figure}[H]\n\\centering\n\\begin{tabular}{cc}\n\\includegraphics{ch1_sqrt1} & \\includegraphics[scale=1]{ch1_sqrt2}\n\\end{tabular}\n\\caption{The 5\\textsuperscript{th} roots of $z=-1+i$ (left), and the two square roots of $-i$ (right).}.\n\\end{figure}\n\n\n\\begin{theorem}\nLet $z_1$ and $z_2$ be nonzero complex numbers.  Then\n\\begin{enumerate}\n\\item[(i)] $\\abs{z_1z_2}=\\abs{z_1} \\ \\abs{z_2}$, and\n\\item[(i)] $\\arg (z_1z_2)=\\arg(z_1)+\\arg(z_2)$.\n\\end{enumerate}\n\\end{theorem}\n{\\bf Proof:} Exercise.\n\n\n\\section{Complex Functions}\n\nWe now start our investigation of functions from the complex plane to itself.  First of all, note that a function $\\mathbf{f}:\\R^2 \\to \\R^2$ can be written in the form\n\\[\n\\mathbf{f}(x,y)=\\left( u(x,y), v (x,y) \\right)\n\\]\nwhere $u,v:\\R^2 \\to \\R$.  For example, if\n\\[\n\\mathbf{f}(x,y)=\\left(x^2+y^2-2x,2y-6 \\right),\n\\]\nwe have\n\\[\nu(x,y)=x^2+y^2-2x \\text{ and } v(x,y)= 2y-6.\n\\]\n\n\n\n\n\nSince we have a formal definition of $\\C$ as $\\R^2$, we can express a function $f : \\C \\to \\C$ as\n\\begin{equation*}\nf(z) = f(x+iy) = u(x,y) +i v(x,y)\n\\end{equation*}\nfor all $z =x+iy \\in \\C$, where $u, v : \\R^2 \\to \\R$.  In this way, we can extend our definition of real and imaginary parts from complex numbers to functions $f:\\C \\to \\C$, writing $\\Re (f) = u$ and $\\Im (f) = v$.\n\n\n\n\nGoing in the other direction, given two functions $u:\\R^2 \\to \\R$ and $v:\\R^2 \\to \\R$, we can create a function $f : \\C \\to \\C$ by \\emph{defining} $f(x+iy) := u(x,y) +iv(x,y)$.\nSo,\n\\begin{center}\n\\emph{\n There is a correspondence between functions from the complex plane to itself, and pairs of functions from the real plane to the real line.}\n \\end{center}\n\n\n\n\n\\begin{example}\nThe function \\[ f: \\C \\to \\C,\\quad f(z) = \\conj{z} \\]\ncorresponds to a function\n\\[ \\mathbf{f}: \\R^2 \\to \\R^2, \\quad \\mathbf{f}(x,y) = \\left( u(x,y), v(x,y) \\right)\n\\]\n\\begin{blankbox}\n\\[\nu(x,y) = x\\ \\qquad\\text{and}\\qquad v(x,y) = -y\n\\]\nsince\n\\[\n\\conj{z} = \\conj{x+iy} = x-iy = \\underbrace{x}_{u(x,y)} + i \\underbrace{(-y)}_{v(x,y)}.\n\\]\n\\end{blankbox}\n\\end{example}\n\n\n\n\\begin{example}\n\nLet us determine the functions $u:\\R^2 \\to \\R$ and $v:\\R^2 \\to \\R$ corresponding to\n\\begin{equation*}\nh: \\C \\to \\C, z \\mapsto z^2.\n\\end{equation*}\n\\end{example}\n\\begin{solution}\nWith $z=x+iy$ we have\n\\[\nz^2 = (x+iy)^2 = x^2-y^2+i2xy\n\\]\nThus we identify $h:\\C \\to \\C$ with $\\mathbf{h}:\\R^2 \\to \\R^2$, $\\mathbf{h}(x,y) = (u(x,y), v(x,y))$  where\n\\begin{gather*}\nu: \\R^2 \\to \\R, \\quad u(x,y) = x^2-y^2, \\\\\nv: \\R^2 \\to \\R, \\quad v(x,y) = 2xy.\n\\end{gather*}\n\n\\end{solution}\n\n\\begin{comment}\n\\begin{example} Let us find the corresponding complex function, $f:{\\mathbb C} \\rightarrow {\\mathbb C}$, for the function\n\\begin{equation*}\n\\mathbf{f} : \\R^2 \\to \\R^2, (x,y) \\mapsto (2y,-x)\n\\end{equation*}\nand express it in terms of $z \\in \\C$.\n\\end{example}\n\n%\\begin{master}\n\\begin{solution}\nThe corresponding function $f:\\C \\to \\C$ is given by\n\\begin{align*}\nf(z)= f(x+iy)&=2y+i(-x) \\\\\n& = 2 \\Im (z) +i ( - \\Re (z) ) \\\\\n& = 2 \\left( \\frac{z-\\overline{z}}{2i} \\right)-i \\left( \\frac{z+\\overline{z}}{2} \\right) \\\\\n&=\\frac{-3i z}{2}+\\frac{i\\overline{z}}{2}.\n\\end{align*}\n\nThus the corresponding complex function is\n\\begin{equation*}\nf: \\C \\to \\C, \\ f(z)= \\frac{-3i z}{2}+\\frac{i\\overline{z}}{2}.\n\\end{equation*}\n(Here we have used the identities $\\Re (z) = \\frac{1}{2} (z+\\conj{z})$ and $\\Im (z) = \\frac{1}{2i}(z-\\conj{z})$, together with the fact that $i^{-1}=-i$)\n\\end{solution}\n%\\end{master}\n%\\vspace*{5cm}\n\\end{comment}\n\n\n\n\n\\begin{example}\nLet find the complex function $f$ corresponding to the function $\\mathbf{f}:\\R^2 \\to \\R^2$ where\n\\begin{enumerate}\n\\item[(i)] $\\mathbf{f} (x,y) = (-2y+3,2x),$ and\n\\item[(ii)] $\\mathbf{f}(x,y) = (x^2+y^2-2x,2y-6)$.\n\\end{enumerate}\n\n\\end{example}\n\n\\begin{solution}\nWe could use the fact that if $z=x+iy$ then\n\\begin{align*}\nx & = \\Re(z) = \\frac{1}{2} \\left( z+ \\conj{z} \\right) \\\\\ny & = \\Im (z) = \\frac{1}{2i} \\left( z- \\conj{z} \\right).\n\\end{align*}\nSubstituting these expressions for $x$ and $y$, we could then simplify and find $f(z)$. However, this is time consuming, and it is sometimes easier to look for familiar expressions in the definition of $f$.\n\nIn part (i), $\\mathbf{f}$ corresponds to $f: \\C \\to \\C$ defined by\n\\begin{align*}\nf(z) = f(x+iy) &= -2y+3+i(2x) \\\\\n& = 2(ix-y) + 3 \\\\\n& = 2(ix+i^2y)+3 \\\\\n& = 2i(x+iy)+3 \\\\\n& = 2iz+3.\n\\end{align*}\n\nIn part (ii), $\\mathbf{f}$ corresponds to $f:\\C \\to \\C$ where\n\\[\nf(x+iy) = x^2+y^2-2x+i2y-6i.\n\\]\nWith $z=x+iy$, notice that\n\\[\nx^2+y^2=\\abs{z}^2 = z \\conj{z},\n\\]\nand that\n\\[\n-2x+i2y = -2 (x-iy) = -2 \\conj{z},\n\\]\nhence\n\\[\nx^2+y^2-2x+i2y-6i = z \\conj{z} - 2 \\conj{z} -6i.\n\\]\nHence $f(z) = z \\conj{z}-2\\conj{z}-6i$ is the corresponding complex function.\n\n\n\n\\end{solution}\n\n\n\n\nIt is worth recalling that some familiar functions defined on $\\R$ extend to $\\C$.\n\n\\begin{definition}\n\\label{d:exp}\nThe \\emph{exponential function} is the function $\\exp : \\C \\to \\C$ defined by\n\\[\n\\exp (x+iy) = \\exp(x) \\left( \\cos (y) + i \\sin (y) \\right)\n\\]\nfor all complex numbers $x+iy \\in \\C$, where $\\exp (x) (=e^x)$ is the usual (real) exponential of $x$.\n\\end{definition}\nWe shall often write $e^z$ in place of $\\exp (z)$.   The trigonometric functions also extend to $\\C$ via\n\\begin{align}\n\\cos (z) &= \\frac{1}{2} \\left( \\exp (iz) + \\exp (-iz) \\right) \\\\\n\\sin (z) & = \\frac{1}{2i} \\left( \\exp(iz)- \\exp (-iz) \\right).\n\\end{align}\n\n\n\n\n\\begin{full}\n\\begin{remark}\nWe conclude this section with some remarks about how you might go about `visualising' a complex function.  For functions $f:\\R \\to \\R$, we usually do so by drawing the graph of $f$, that is, the subset $\\set{(x,f(x)): x \\in \\R}$ of $\\R^2$.\n\nWe cannot draw the `graph' of a function $f:\\C \\to \\C$, as to do so would require four coordinates\n\\[\n\\set{ \\Re (z), \\Im (z) , \\Re \\left( f(z) \\right), \\Im \\left( f(z) \\right) }\n\\]\nand thus four dimensions.  We can however view $f$ as a `transformation' of the complex plane, and examine the effect of applying $f$ to\n\\begin{itemize}\n\\item Regions (subsets) of $\\C$\n\\item Curves in $\\C$ (lines, circles etc)\n\\item A combination of the two.\n\\end{itemize}\n\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.25]{ch1_z2quad}\n\\caption{The image of the first quadrant under $z \\mapsto z^2$.}\n\\label{f:z2}\n\\end{figure}\nFigure~\\ref{f:z2} indicates that the image of the first quadrant under the map $z \\mapsto z^2$ is the region consisting of the first and second quadrants.  This follows from the fact that for any $z_1,z_2 \\in \\C$, \n\\[\n\\arg (z_1z_2)=\\arg(z_1)+\\arg(z_2).\n\\]\nHence $\\arg(z^2)=2\\arg(z)$, and so if $0 \\leq \\arg (z) \\leq \\pi/2$ (i.e. $z$ is in the first quadrant), we have $0 \\leq \\arg (z^2) \\leq \\pi$ ($z^2$ lies in either the first or second quadrant).  Of course, Figure~\\ref{f:z2} does not tell us anything about the modulus of $z^2$.\n\n\nFigure~\\ref{f:z2c} illustrates how $z \\mapsto z^2$ also squares the modulus; the circle of radius $r>0$ and centre $0$ is sent to the circle of radius $r^2$ and centre $0$.  Moreover, the anticlockwise arrows on the circles indicate that if $z_2$ lies (a small distance) anticlockwise of $z_1$, then $z_2^2$ lies anticlockwise of $z_1^2$.\n\n\n\n\n%\\vspace*{2cm}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.3]{ch1_z2circle}\n\\caption{The effect of the map $z \\mapsto z^2$ on a circle of radius $r$ centred at the origin.}\n\\label{f:z2c}\n\\end{figure}\n\n%\\vspace{2cm}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.15]{ch1_expimage}\n\\caption{The geometric effect of the exponential map.}\n\\label{f:exp}\n\\end{figure}\n\nFigure~\\ref{f:exp} combines the approaches of the previous examples.  Here we see that the shaded region,\n\\[\n\\set{z \\in \\C: \\Re (z) \\leq x \\text{ and } y_0 \\leq \\Im (z) < y_0+2\\pi}\n\\]\nis sent to the shaded disc of radius $e^x$ and centre $0$.  The vertical line $\\Re(z)=x$ is sent to the circle of radius $e^x$ and centre $0$, while the dashed horizontal line is sent to the `infinite ray' from $0$ indicated with another dashed line.\n\nStrictly speaking this diagram is inaccurate, as some of the region to the right of the line $\\Re(z)=x$ is also shaded.\n\nI will not ask you to produce diagrams like this in the exam, but it may be helpful to have the idea of complex functions as transformations in your mind throughout this module.\n%\\vspace{2cm}\n\n%\\vspace*{2cm}\nFigures~\\ref{f:z2},~\\ref{f:z2c} and~\\ref{f:exp} are from \\emph{Basic Complex Analysis}, (Jerrold. E. Marsden, published by W.H. Freeman and Company, 1973).  \n\n\\end{remark}\n\\end{full}\n\n\n\\section{Open Sets in $\\C$}\n\n\n\n\n\\begin{definition}[Open Disc]\nLet $z_0 \\in \\C$ and let $r>0$ be some real number.  The open disc of radius $r$ centred at $z_0$ is defined to be the set \n\\[\nD(z_0,r):= \\set{ z \\in \\C: \\abs{z-z_0} <r}.\n\\]\n\\end{definition}\nIn other words, $D(z_0,r)$ is the set of all points that lie (strictly) inside the circle or radius $r$ with centre $z_0$.\n\\begin{definition}\nThe set of points\n\\[\nD'(z_0,r) = \\set{ z \\in \\C: 0 < \\abs{z-z_0} < r},\n\\]\nwhere $r>0$ and $z_0 \\in \\C$, is called the \\emph{punctured open disc} of radius $r$, centre $z_0$.\n\\end{definition}\n\n\n\nNote that $D'(z_0,r)$ is the set obtained by removing the centre $z_0$ from the open disc $D(z_0,r)$.\n\\begin{sfig}\n\\includegraphics[scale=1]{ch1_discs}\n\\caption{The open disc $D(z_0,r)$ and punctured open disc $D'(z_0,r)$.}\n\\label{f:discs}\n\\end{sfig}\n\n\\begin{notation}\nThis is a good place to introduce some conventions for sketching sets.  The broken circle in Figure~\\ref{f:discs} around the disc indicates that the boundary is not included in this set.  The filled point $\\bullet$ beside $z_0$ indicates that the point $z_0$ is included in $D(z_0,r)$, while the `hollow' point $\\circ$ beside $z_0$ indicates that $z_0$ is not included in the punctured disc $D'(z_0,r)$.\n\\end{notation}\n\n\n\\begin{definition}\nLet $U \\subseteq \\C$, then we say that $U$ is an \\emph{open set} if given any $z \\in U$ there is some $r_z>0$ with $D(z,r_{z}) \\subseteq U$.\n\\end{definition}\n\\begin{sfig}\n\\includegraphics[scale=1]{ch1_openset}\n\\caption{An open set $U$ with two examples of open discs around points of $U$.  Note that the radius typically depends on the point $z$; points nearer the `edge' of $U$ will need smaller discs.}\n\\end{sfig}\nInformally, we think of an open set as a set that does not include its `boundary.'  Thus a set $U$ is open if, given any $z \\in U$, we can move a small distance in \\emph{any} direction without leaving $U$.\n\n\n\\begin{example}\n\\begin{itemize}\n\\item[(i)] The open disc $D(0,1)$ is an open set.\n\n\\altgraphics[scale=1]{ch1_unit_disc_full}{ch1_unit_disc}\n\n\\begin{full}\nLet $z \\in D(0,1)$.  Our goal is to find some $r>0$ so that $D(z,r) \\subseteq D(0,1)$. To this end, set $r= (1-\\abs{z})/2$. Then if $w \\in D(z,r)$,\n\\begin{align*}\n\\abs{w-0} & \\leq \\abs{w-z} + \\abs{z} \\\\\n& < \\frac{1-\\abs{z}}{2} +\\abs{z} \\\\\n&= \\frac{1+\\abs{z}}{2} < \\frac{1+1}{2} = 1,\n\\end{align*}\nwhich shows that $w \\in D(0,1)$.\n\n%\\vspace*{2cm}\nHence $D(z,r) \\subseteq D(0,1)$ and so $D(0,1)$ is open.\n\\end{full}\n\n\\item[(ii)] The closed disc $\\overline{D} (0,1) := \\set{ z \\in \\C: \\abs{z} \\leq 1 }$ is not an open set (note: \\emph{closed} does not necessarily mean not open).\n\\leftimage{\n\\altgraphics[scale=1]{ch1_cldisc1}{ch1_cldisc1_full}\n}\n{\nThe solid circle in this image indicated that the boundary is included.\n}\n\n\n\\begin{blankbox}\nGiven any point $z$ on the boundary (e.g. $z=1$) and any $r>0$, the open disc $D(z,r)$ contains points that do not belong to $\\overline{D}(0,1)$. \n\\end{blankbox}\n\\begin{full}\n For example, $w=1+r/2$ belongs to $D(1,r)$, since\n\\[\n\\abs{w-z} = \\abs{(1+r/2)-1} = r/2 < r\n\\]\nbut not to $\\overline{D} (0,1)$, since\n\\[\n\\abs{w-0} = \\abs{1+r/2} = 1+r/2 >1.\n\\]\n\\end{full}\n\n\\end{itemize}\n\\end{example}\n\n\n\n\\begin{example}\n The upper-half plane $H_+$, where\n\\[\nH_+ := \\set{ z \\in \\C: \\Im (z) > 0 }\n\\]\nis an open set, while the set $K_+$ defined by\n\\[\nK_+:= \\set{ z \\in \\C : \\Im (z) \\geq 0 }\n\\]\nis not.\n\\begin{center}\n\\altgraphics[scale=1]{ch1_upperhalf_full}{ch1_upperhalf} \\quad \\altgraphics[scale=1]{ch1_upperhalf2_full}{ch1_upperhalf2}\n\\end{center}\n\\begin{blankbox}\nIf $z \\in H_+$ then $\\Im (z)>0$, so we set $r = \\frac{1}{2} \\Im (z)$.  Then $D(z,r)\\subseteq H_+$, or in other words, given any $w \\in D(z,r)$, we must have $\\Im(w)>0$.\n\nFor the set $K_+$, if we choose $z$ on the real axis (e.g $z=-1$), then any open disc centred at $z$, no matter how small, contains points below the real axis.  Thus there is no $r>0$ with $D(z,r) \\subset K_+$, so $K_+$ is not open.\n\\end{blankbox}\n\\end{example}\n\n\n\n\n\\begin{note}\nSome more examples of open sets include $\\C \\backslash \\set{0}$, or indeed $\\C \\backslash F$ where $F$ is any finite set.  Many regions determined by \\emph{strict} inequalities of real numbers are also open, for example, sets of the form\n$\n\\set{ z \\in \\C: c_1<\\abs{z}<c_2 }$, $\\set{ z \\in \\C: 0 < \\Arg (z) < \\pi/4 }$ or $\\set{z \\in \\C: c_1<\\Re(z) < c_2 },$\nwhere $c_1<c_2 $ are real numbers.\n\nMore examples of sets that are not open include circles, lines, curves, single points or finite sets.  Do not use \\emph{closed} to mean \\emph{not open}.  In the context of analysis, closed has a different meaning.\n\\end{note}\nThroughout this module, we shall be mostly concerned with functions $f:U \\to \\C$, where $U$ is an open subset of $\\C$.  \n\n \n\\section{Limits}\nLimits in $\\C$ are defined in an analogous way to those in $\\R$ (and almost identically to those in $\\R^2$). \n\nFirst, fix some complex number $z_0 \\in \\C$.  For any $z \\in \\C$, the modulus $\\abs{z-z_0}$ measures the distance between $z$ and $z_0$.  Note that if we write $z=x+iy$ and $z_0=x_0+iy_0$, then $\\abs{z-z_0}$ is exactly the same as the Euclidean distance between $(x,y)$ and $(x_0,y_0)$ in $\\R^2$.\n\n\n\n\n For a complex function $f$, what does it mean to say that $f(z)$ approaches $L \\in \\C$ as $z$ approaches $z_0$?  \\ Intuitively, we want\n \\begin{center}\n $\\abs{f(z)-L}$ is small whenever  $\\abs{z-z_0}$ is small.\n \\end{center}\n  More formally, this can be written as\n \\begin{center}\n Given any $\\epsilon>0$ there is a $\\delta>0$ such that\n \\[\n \\abs{f(z)-L} < \\epsilon\\text{ whenever } \\abs{z-z_0}<\\delta.\n \\]\n \\end{center}\n \n This definition works whenever $f$ is defined on all of $\\C$, but it is not so clear how it should work when $f(z)$ is not defined near $z_0$. In other words, we want to be able to exclude points $z_0$ where $\\abs{z-z_0}$ small implies $f(z)$ does not exist. \n \\begin{comment}\n Recall the following definition from Foundations II: given a set $A \\subseteq \\R$, a point $x_0$ is a \\emph{limit point} of $A$ if whenever $I$ is an open interval with $x_0 \\in I$, then $I$ contains an element of $A \\backslash \\set{x_0}$.\n \n We define limit points of subsets of $\\C$ in almost exactly the same way, replacing open intervals with open discs.\n \\end{comment}\n \n \\begin{definition}\n A point $z_0$ is a \\emph{limit point} of of a set $S \\subseteq \\C$  if for any $\\delta>0$, we have\n \\[\n D'(z_0,\\delta) \\cap S \\neq \\emptyset.\n \\]\n In other words, any punctured disc centred at $z_0$, no matter how small, contains at least one point of $S$.\n \\end{definition}\n\nA limit point of a set $S$ may or may not belong to $S$.  Moreover, a point $z_0 \\in S$ may or may not be a limit point of $S$.  If $S$ is an open set however, then any $z_0 \\in S$ is necessarily a limit point of $S$.\n\n\n\n\\begin{example}\n\\begin{enumerate}\n\\item[(i)] The point $0$ is a limit point of the punctured plane $\\C \\backslash \\set{0} = \\set{ z \\in \\C : z \\neq 0 }$.\n\\begin{center}\n\\altgraphics[scale=1]{ch1_pplane_full}{ch1_pplane}\n\\end{center}\n\\begin{blankbox}\nIndeed, it is clear that every punctured disc $D'(0,r)$ contains points of $\\C \\backslash \\set{0}$.  \n\\end{blankbox}\n\nIn fact, every point $z$ of $\\C$ is a limit point of $\\C \\backslash \\set{0}$, since every disc $D'(z,r)$ must contain a point of $\\C \\backslash \\set{0}$.\n\n\n\\item[(ii)] If $S= \\set{z_0}$ is a one-point set, then there are no limit points of $S$.  %Indeed, for any $\\delta>0$, $D'(z_0,\\delta)$ does not contain any points of $S$ by definition.  Moreover, given any other point $z\\in \\C$ with $z \\neq z_0$, the punctured disc $D'(z,\\delta)$, with $\\delta = \\frac{1}{2} \\abs{z-z_0}$, does not contain $z_0$.\n\n\\item[(iii)] The set of limit points of the open disc $S=D(z_0,r)$ is precisely the closed disc\n\\[\n\\set{z \\in \\C: \\abs{z-z_0} \\leq r }.\n\\]\n\\begin{center}\n\\altgraphics[scale=1]{ch1_limitpoints_disc_full}{ch1_limitpoints_disc} \n%\\includegraphics[scale=1]{cldisc_big}\n\\end{center}\n\\begin{blankbox}\nFor a point $z_1$ on the boundary, any punctured disc $D'(z_1,r)$ intersects $S$, while for a point $z_2$ outside of the boundary, there are punctured discs $D'(z_2,r_2)$ that do not.\n\\end{blankbox}\n\n\\item[(iv)] Let $L$ be the strictly positive real axis, regarded as a subset of $\\C$, that is\n\\[\nL = \\set{ x+ iy \\in \\C: x>0 \\text{ and } y=0 }.\n\\]\nThen $z=0$ is a limit point of $L$.\n\\begin{center}\n\\altgraphics[scale=1]{ch1_halfline_full}{ch1_halfline}\n\\end{center}\n\n\n%If $z_1$ is a point on the boundary of $D(w,r)$, then for any $\\delta>0$, $D'(z_1,\\delta)$ contains points of $D(w,r)$.  If $z_2$ lies outside the boundary of $D(w,r)$, the the disc $D(z_2,\\delta_2)$, where $\\delta_2 = \\frac{1}{2} ( \\abs{w-z_2} -r)$, does not contain any points of $D(w,r)$.\n\n\\end{enumerate}\n\\end{example}\n\n\n\\begin{note}\nTo confuse things further, some authors require only allow points $z_0 \\in \\C \\backslash S$ to be limit points of $S$.  When reading textbooks or lecture notes, take care as to which definition is being used.\n\nYou need to be familiar with the concept of a limit point, though I will not ask you to prove that a given point $z_0$ is a limit point of a set $S$.\n\\end{note}\n\nWe are now in a position to define limits of complex functions.\n\\begin{definition}\n\\label{d:limit}\nLet $f$ be a complex function, $S \\subseteq \\C$ the domain of $f$,  and let $z_0 \\in \\C$ be a limit point of $S$. Then we say that \\[ \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z) = \\alpha \\in \\C\\] if given any $\\epsilon >0$ there is some $\\delta >0$ such that\n\\[ \\text{ if $z \\in S$ and } 0<\\abs{z-z_0} < \\delta \\text{ then }\\abs{f(z)-\\alpha}< \\epsilon.\\]\n\\end{definition}\n \n \n\n\\begin{note}\n\n\\begin{enumerate}\n\\item[(i)]  Note that this definition allows us to examine limits of functions at point that lie on the boundary of their domains.  For example, we can sensibly speak about things like\n\\[\n\\lim_{z \\to 0} \\frac{\\sin(z)}{z}\n\\] \nsince this function is defined on $\\C \\backslash \\set{0}$ and $0$ is a limit point of this set.\n\\item[(ii)]  Definition~\\ref{d:limit} may equivalently be written in the language of open discs: \n\\[\n\\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z) = \\alpha\n\\]\nif given any $\\epsilon >0$ there is a $\\delta >0 $ such that\n\\[\nz \\in D' (z_0, \\delta ) \\cap S \\text{ implies } f(z) \\in D( \\alpha, \\epsilon).\n\\]\n\\item[(iii)] When\n\\[ \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z) = \\alpha \\]\nwe sometimes write\n\\[\nf(z) \\to \\alpha \\text{ as } z \\to z_0.\n\\]\n\\end{enumerate}\n\n\\end{note} \n\n\n \\begin{question}\n Is it possible to find a function $f$ for which $f(z) \\to \\alpha_1$ and $f(z) \\to \\alpha_2$ as $z \\to z_0$, where $\\alpha_1\\neq\\alpha_2$?\n  \\end{question}\n  \n\\begin{answer}\nThe answer, unsurprisingly, is no.  Indeed, set $\\epsilon = \\frac{1}{3} \\abs{\\alpha_1-\\alpha_2}>0$.  If $f(z) \\to \\alpha_1$ and $f(z) \\to \\alpha_2$ as $z \\to z_0$, then there would be some $\\delta >0$ such that\n\\[\nz \\in D'(z_0,\\delta) \\Longrightarrow f(z) \\in D'(\\alpha_1 , \\epsilon ) \\cap D'(\\alpha_2 , \\epsilon).\n\\]\nBut this is impossible since clearly $D'(\\alpha_1,\\epsilon) \\cap D'(\\alpha_2 , \\epsilon) = \\emptyset$.\n\\end{answer} \n \n \n \n\n\n\\begin{proposition}[Algebra of limits; proof non-examinable] \n\\label{p:alglimits}\nLet $S\\subseteq \\C$ and consider functions $f,g:S \\to \\C.$  Suppose that $z_0$ is a limit point of $S$, and that $\\displaystyle \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z) = \\alpha$ and $\\displaystyle \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} g(z)= \\beta$.  Then\n\\begin{enumerate}\n\\item[(i)] $\\displaystyle \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} \\left( f(z) + g(z) \\right) = \\alpha + \\beta$,\n\\item[(ii)] $\\displaystyle \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} \\left( f(z)g(z) \\right) = \\alpha  \\beta$,\n\\item[(iii)] If in addition $\\beta \\neq 0$, and $z_0$ is a limit point of the set $T=\\set{ z \\in S: g(z) \\neq 0 }$, then\n\\[\n\\lim_{ \\substack{z \\to z_0 \\\\ z \\in T}} \\frac{f(z)}{g(z)} = \\frac{\\alpha}{\\beta}\n\\]\n\\end{enumerate}\n\\end{proposition}\n(The proof of this proposition is almost identical to the corresponding proof for real functions, except that $\\abs{\\cdot}$ refers to the modulus and not the absolute value, and is thus omitted.)\n\n%\\vspace*{3cm}\n\n\n\n\\begin{question}\nSuppose that $T$ is a subset of $S$, $z_0$ is a limit point of both $T$ and $S$, and that $\\rlim{z \\to z_0}{z \\in S} f(z) = \\alpha$. \n\\begin{SCfigure}[2][h]\n\\includegraphics[scale=1]{ch1_subset1}\n\\caption{A subset $T$ of $S$ and a point $z_0$ that is a limit point of both $T$ and $S$.}\n\\end{SCfigure}\nWhat can we say about $\\rlim{z \\to z_0}{z \\in T} f(z)$?\n\\end{question}\n\\begin{answer}\nLet $\\epsilon >0$ be given, then we know that there exists $\\delta >0$ such that\n\\[\nz \\in S,\\ 0<|z-z_0|<\\delta \\ \\Rightarrow |f(z)-\\alpha| < \\epsilon.\n\\]\nNote that\n\\[\n z \\in D'(z_0, \\delta) \\cap T \\text{ implies } z \\in D' (z_0,\\delta) \\cap S,\n\\]\nor in other words,\n\\[\nz \\in T\\ \\text{ and } 0 < \\abs{z -z_0} < \\delta \\Rightarrow z \\in S \\text{ and } 0 < \\abs{z-z_0} < \\delta.\n\\]\n\nIt follows that\n\\[\n \\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z) = \\alpha \\text{ implies }  \\lim_{\\substack{z \\to z_0 \\\\ z \\in T}} f(z) = \\alpha\n\\]\n\\end{answer}\nThe second limit, where $f$ is restricted to the subset $T$ of $S$, is called a \\emph{restricted limit}.   If a function has a limit at a point $z_0$ then all restricted limits of that function at $z_0$ must be the same.   In particular, \n\n\\emph{If we have two subsets $T_1,T_2 \\subseteq S$ such that \n\\[\n \\lim_{\\substack{z \\to z_0 \\\\ z \\in T_1}} f(z) = \\alpha_1 \\text{ and } \\lim_{\\substack{z \\to z_0 \\\\ z \\in T_2}} f(z) = \\alpha_2,\n\\]\nwith $\\alpha_1 \\neq \\alpha_2$, then\n\\[\n\\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z)\n\\]\ndoes not exist.\n}\n\n\n\n\nLet $f$ be a complex function with domain $S$ and let $z_0$ be a limit point of $S$.  In what follows, we shall simply write $\\displaystyle \\lim_{z \\to z_0} f(z)$ in place of \\[\n\\lim_{\\substack{z \\to z_0 \\\\ z \\in S}} f(z),\n\\]\nand we shall reserve the second subscript for restricted limits.\n\n\n\n\\begin{example}\n\\label{e:rlim}\nConsider the function \n\\[\nf: \\C \\backslash \\set{0} \\to \\C, \\quad f(z) = \\frac{\\conj{z}}{z}.\n\\]\nDoes \n$\n\\displaystyle \\lim_{z \\to 0} f(z)\n$\nexist?\n\\end{example}\n\\begin{note}\nIn future, we may simply write things like ``Let $f(z) = \\dfrac{\\conj{z}}{z}$'' without specifying the domain, since it is clear that this function $f$ is defined on $\\C \\backslash \\set{0}$.\n\\end{note}\n\\begin{solution}\nWe shall look at two restricted limits of $f(z)$ as $z$ approaches $0$, namely the limits when $z$ is restricted to the subsets\n\\begin{itemize}\n\\item the nonzero real axis $\\R \\backslash \\set{0}$, and\n\\item the nonzero imaginary axis $i \\R \\backslash \\set{0}$ (Since every point on the imaginary axis is of the form $iy$ for some $y \\in \\R$, it makes sense to use the notation $i \\R$ for this set.)\n\\end{itemize}\nof the domain $\\C \\backslash \\set{0}$.  Note that $0$ is a limit point of both $\\R \\backslash \\set{0}$ and $i\\R \\backslash \\set{0}$.\n\n%\\begin{center}\n%\\includegraphics[scale=1]{origin_full}\n%\\end{center}\n\nIf $z \\in \\R \\backslash \\set{0}$, then $\\conj{z} = z$ and so $f(z) = \\frac{\\conj{z}}{z} = \\frac{z}{z} =1$ on $\\R \\backslash \\set{0}$.  Hence\n\\[\n\\rlim{z \\to 0}{z \\in \\R \\backslash \\set{0} } f(z)=1.\n\\]\nFor $z \\in i \\R \\backslash \\set{0}$, we have $\\conj{z}=-z$, so that $f(z)=-1$ for all such $z$, giving\n\\[\n\\rlim{z \\to 0}{z \\in i\\R \\backslash \\set{0} }=-1.\n\\]\nSince  these limits are not equal, it follows that the (unrestricted) limit $\\lim_{z \\to 0} f(z)$ does not exist.\n%\\vspace*{12cm}\n\\end{solution}\n\n\n\\section{Continuity}\n\n\\begin{definition}\nLet $S \\subseteq \\C$ and let $f:S \\to \\C$ be given.  For a point $z_0 \\in S$, we say that $f$ is \\emph{continuous at $z_0$} if $\\lim_{z \\to z_0 } f(z)=f(z_0)$. If $f$ is continuous at all points $z_0 \\in S$ then we say that $f$ is \\emph{continuous on $S$}.\n\\end{definition}\n\\begin{note}\nNote that the definition of continuity at $z_0$ only makes sense when $z_0$ belongs to the domain of $f$.\n\\end{note}\n\n\n\\begin{example}\n\\label{e:cts}\n\nThe functions\n\\begin{enumerate}\n\\item[(i)] $f(z) = \\Re (z)$,\n\\item[(ii)] $f(z) = \\Im (z)$, and\n\\item[(iii)] $f(z) = \\conj{z}$\n\\end{enumerate}\nare all continuous on $\\C$.\n\\end{example}\n\n\\begin{solution}\nFix $z_0=x_0+iy_0 \\in \\C$ and let $\\epsilon>0$ be given.  Note that for any $z=x+iy \\in \\C$ we have the following inequalities:\n\\begin{align*}\n\\abs{ \\Re (z) - \\Re (z_0)} = \\abs{\\Re (z-z_0)} & = \\sqrt{(x-x_0)^2} \\\\\n&\\leq \\sqrt{(x-x_0)^2+(y-y_0)^2} = \\abs{z-w} \\\\\n\\abs{ \\Im (z) - \\Im (z_0)} = \\abs{\\Im (z-z_0)} & = \\sqrt{(y-y_0)^2} \\\\\n&\\leq \\sqrt{(x-x_0)^2+(y-y_0)^2} = \\abs{z-z_0} \\\\\n\\abs{\\conj{z}-\\conj{z_0}} = \\abs{\\conj{z-z_0}} & = \\abs{z-z_0}.\n\\end{align*}\nThus in all three cases, setting $\\delta=\\epsilon$, we get\n\\[\n0< \\abs{z-z_0} < \\delta \\Longrightarrow \\abs{f(z)-f(z_0)} < \\epsilon.\n\\]\n\\end{solution}\n\n\n\n\\begin{proposition}\n\\label{t:continuity}\nLet $S \\subseteq \\C$ and let $f,g:S \\to \\C$ be functions that are continuous on $S$.  Then\n\\begin{enumerate}\n\\item[(i)] The function $f+g,$ where $(f+g)(z)=f(z)+g(z)$, is continuous on $S$,\n\\item[(ii)] The function $fg$, where $(fg)(z):=f(z)g(z)$, is continuous on $S$,\n\\item[(iii)] For any $\\alpha \\in \\C$, the function $\\alpha f$, where $(\\alpha f)(z)=\\alpha \\left( f(z) \\right),$ is continuous on $S$,\n\\item[(iv)] If $T=\\set{z \\in S: g(z) \\neq 0 }$ then the function $ f/g$, where $ \\left( \\dfrac{f}{g} \\right) (z)= \\dfrac{f(z)}{g(z)},$ is continuous on $T$.\n\\end{enumerate}\n\\end{proposition}\n{\\bf Proof:} Immediate from Proposition~\\ref{p:alglimits}.\n\n\\begin{note}\nIf we have\n\\[\nf(x+iy) = u(x,y) + i v(x,y),\n\\]\nand $z_0 = x_0 + i y_0$ is a point in the domain of $f$, then\n\\[\n\\lim_{z \\to z_0} f(z) = \\lim_{(x,y) \\to (x_0,y_0)} u(x,y)+ i \\lim_{(x,y) \\to (x_0,y_0)} v(x,y),\n\\]\nprovided these limits exist.  Hence\n\\[\nf \\text{ continuous at }z_0 \\Leftrightarrow u \\text{ and } v \\text{ continuous at } (x_0,y_0).\n\\]\nThis is useful when the real and imaginary parts of $f$ are familiar functions that we know to be continuous.\n\\end{note}\n\n\\newpage\n\n\n\n", "meta": {"hexsha": "914dd59f6e48d9bc3d2c6bfeda614f8476e6f83c", "size": 33795, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2003/LectureNotes/Chapter_1.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_1.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_1.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.0146231721, "max_line_length": 403, "alphanum_fraction": 0.6466045273, "num_tokens": 12597, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8723473879530491, "lm_q1q2_score": 0.7683610302906838}}
{"text": "\\documentclass[12pt]{mmalatex}\n\\usepackage{examples}\n\\usepackage{caption}\n\\usepackage{pgfplots}\n\n\\begin{document}\n\n\\section*{Plotting Bessel functions}\n\n\\vspace{-5pt}\n\nThis simple example uses Mathematica to produce a plot of the first six Bessel functions. Two plots are shown, one created by Mathematica and a second created by LaTeX using the plotting package {\\tt\\small pgfplots} and the data exported from Mathematica.\n\n\\begin{mathematica}\n   myData = Partition[Flatten[Table[{x, Table[BesselJ[n, x], {n, 0, 5}]}, {x, 0, 15, 0.1}]], 7];\n   myPlot = Plot[Evaluate[Table[BesselJ[n, x], {n, 0, 5}]], {x, 0, 15}, PlotLegends -> \"Expressions\"];\n\n   Export[\"example-04-fig.png\", myPlot, \"PNG\"];\n   Export[\"example-04-fig.pdf\", myPlot, \"PDF\"];\n   Export[\"example-04.txt\", myData, \"Table\",  \"FieldSeparators\" -> \" \"];\n\\end{mathematica}\n\n\\vfill\n\n\\begin{minipage}{\\textwidth}\n   \\centering\n   \\IfFileExists{example-04-fig.pdf}%\n   {\\includegraphics[width=6.4in]{example-04-fig.pdf}}{Failed to create pdf plot.}\n   \\captionof{figure}{The first six Bessel functions.}\n\\end{minipage}\n\n\\vfill\n\n\\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": "22f06127f501835625f2ca7e26361401bff4130e", "size": 2990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematica/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": "mathematica/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": "mathematica/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": 36.0240963855, "max_line_length": 255, "alphanum_fraction": 0.6321070234, "num_tokens": 1030, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.7683610240574854}}
{"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{Cramer's Rule}\n\nThe second method used to solve this is the use of Cramer's Rule.\nLet us first recap the original matrix equation.\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\nWe must first find the determinant of $A$, as noted below:\n\\begin{equation*}\n    \\begin{vmatrix}\n        A\n    \\end{vmatrix}\n    = \\begin{vmatrix}\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{vmatrix}\n    = -2\n\\end{equation*}\n\nFollowing Cramer's rule then leads to finding the determinant of each $A_i(b)$, which indicates the matrix formed when replacing the $i^{th}$ column of $A$ with $b$.\n\\begin{align*}\n    &\\begin{vmatrix}A_1\\end{vmatrix} = \\begin{vmatrix}\n        100 & 1 & 0 & 0 & 0   \\\\\n        0 & 1 & -1 & 0 & -1 \\\\\n        -50 & 0 & -1 & 0 & -1 \\\\\n        120 & -1 & 0 & 1 & 1  \\\\\n        0 & 1 & 1 & -1 & 1\n    &\\end{vmatrix} = -50\\\\\n    &\\begin{vmatrix}A_2\\end{vmatrix} = -100 \\\\ \n    &\\begin{vmatrix}A_3\\end{vmatrix} = -60 \\\\ \n    &\\begin{vmatrix}A_4\\end{vmatrix} = -250 \\\\\n    &\\begin{vmatrix}A_5\\end{vmatrix} = -90 \\\\\n\\end{align*}\n\nThen for each determinant, division by the original determinant provides the solution to that particular $x$ value.\n\\begin{equation*}\n    \\frac{1}{-2} \\begin{bmatrix}\n        -50 \\\\\n        -100 \\\\\n        -60 \\\\\n        -250 \\\\\n        -90\n    \\end{bmatrix}\n\\end{equation*}\n\nThe result is then the answer:\n\\begin{equation*}\n    x = \\begin{bmatrix}\n        25 \\\\\n        50 \\\\ \n        30 \\\\ \n        125 \\\\\n        45\n    \\end{bmatrix}\n\\end{equation*}\n\nThis answer is identical to the answer obtained through $LU$ Factorization.\n\n\\end{document}\n", "meta": {"hexsha": "225d971a1bf16ef9eba9455ab29c7fb23463715f", "size": 2415, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Projects/matrix_theory/docs/tex/cramers_rule.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/cramers_rule.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/cramers_rule.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": 23.6764705882, "max_line_length": 165, "alphanum_fraction": 0.5316770186, "num_tokens": 879, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8723473680407889, "lm_q1q2_score": 0.7683610182112649}}
{"text": "\\lab{PageRank Algorithm}{PageRank Algorithm}\n\\label{lab:PageRank}\n\\objective{Implement the PageRank Algorithm and understand the theory behind it.}\n\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.\nAs of 2013, the PageRank algorithm is one of over 200 algorithms that Google uses to determine the rank of a website.\nNamed for Larry Page, cofounder of Google, this algorithm ranks pages based on how many other pages link to them.\n\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\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{A directed graph can describe the links between webpages. In this example, the set of web pages linking to page 0 is $\\In(0)=\\{1,2,3,4,5,6,7\\}$, and page 0 links to $\\Out(0)=\\{7\\}$.}\n\\label{fig:network1}\n\\end{figure}\n\nThe PageRank algorithm ranks pages based on how many other pages link to them.\nMoreover, a link from a more important page counts more than a link 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)}{\\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 is called a \\emph{sink}. \nFor example, node 2 in Figure \\ref{fig:network1} is a 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. \nFor example, we replace Figure \\ref{fig:network1} with 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{This figure arises from Figure \\ref{fig:network1} by adding a link from page 2 to every other page (the added links are grey). The new links guarantee that page 2 is no longer a sink, as required by the PageRank algorithm.}\n\\label{fig:network2}\n\\end{figure}\n\n\\subsection*{Refining the model: adding boredom}\nThe equations in \\eqref{equ:pr1} describe the surfer's habits as a Markov chain.\nHowever, the model is more realistic if we add the assumption 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$.\nAccounting for boredom, the formulas in \\eqref{equ:pr1} become\n\\begin{equation}\\label{equ:pr2}\np(i,0)=\\frac{1}{N} \\qquad p(i,t+1) = \\frac{1-d}{N} + d\\sum_{j \\in \\In(i)} \\frac{p(j,t)}{\\Out(j)}.\n\\end{equation}\n\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$ and $\\mathbf{1} = (1,\\ldots, 1)^T$, and $K$ is defined by\n\\[K_{ij} = \\begin{cases} \\frac{1}{\\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}\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 $B$ is a diagonal matrix with $B_{jj}=\\Out(j)$.\nSince $\\Out(j)$ can be computed from the adjacency matrix, we will begin by creating $A$.\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.\nFor example, the 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\n\n\\begin{problem}\nWrite the following function that creates an adjacency matrix from a file.\n\\begin{lstlisting}\ndef to_matrix( datafile, n ):\n    ''' Return the nxn adjacency matrix described by datafile.\n    \n    INPUTS:\n    datafile - A .txt file describing a directed graph. Lines \n    \t\t\tdescribing edges should have the form \n\t\t\t\t'<from node>\\t<to node>\\n'. The file may also \n\t\t\t\tinclude 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{data.txt} included with this lab describes the matrix in Figure \\ref{fig:network1}. \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 `data.txt' for read-only\nwith open('./data.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{data.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\nThe next step is to compute $K$. \nThe matrix $D$ is easily obtained from $A$ (how?). \nThen, we can use $D$ to identify sinks.\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\nFinally we compute $K$.\nIt is a \\emph{very} bad idea to invert $D$ and perform the matrix multiplication $D^{-1}A$.\nRather, store the diagonal entries of $D$ in a vector and use array broadcasting to divide $A$ by $D$.\nFor Figures \\ref{fig:network1} and \\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\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 implement this algorithm in SciPy to solve for 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 .43. \nNode 7 has a much 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 to iterate the equation for $\\mathbf{p}(t)$ until $\\norm{\\mathbf{p}(t)-\\mathbf{p}(t-1)}$ is sufficiently small.\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.\n\\begin{lstlisting}\ndef iter_solve( data, N=None, d=.85, tol=1E-5):\n    '''\n    Return the page ranks of the network described by `data`.\n    \n    INPUTS:\n    data - 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    Iterate through the PageRank algorithm until the error is less than \n    `tol'. Return the approximation to the steady state.\n    '''\n\\end{lstlisting}\nHints:\n\\begin{enumerate}\n\\item At each step, test your function against the example in this lab.\n\\item Don't forget to eliminate sinks. \nIt is possible (but not necessary) to do this in a single line.\n\\item When \\li{n} is not \\li{None}, you want to work with only the upper $n \\times n$ portion of the array \\li{data}.\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{p}(t)$. \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 Lab \\ref{lab:EigSolve}.\n\nWe can also attempt to 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 iter_solve( data, n=None, d=.85):\n    '''\n    Return the page ranks of the network described by `data`.\n    \n    INPUTS:\n    data - 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    Use the eigenvalue solver in \\li{scipy.linalg} to calculate the steady \n    state of the PageRank algorithm.\n    '''\n\\end{lstlisting}\nHint: Review the techniques from the Markov chain section of Lab \\ref{lab:EigSolve}.\n\\end{problem}\n\n\n\\section*{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.\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\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\n\\begin{problem}\nTry 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 Probelm \\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": "1abba61d102a9657714731d5814e5fb6102a1084", "size": 17035, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/PageRank/PageRank.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/PageRank/PageRank.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/PageRank/PageRank.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 46.1653116531, "max_line_length": 232, "alphanum_fraction": 0.6645142354, "num_tokens": 5611, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970842359877, "lm_q2_score": 0.8723473647220786, "lm_q1q2_score": 0.7683610152881546}}
{"text": "\\gotosection{1}{2}\n\\subsection{Introducing the actors: matrices}\n\n\\begin{exercise}{17}\n  \\begin{enumerate}\n    \\item\n    $$A_T = \\begin{xmatrix}\n              0 & 1 & 1 \\\\\n              1 & 0 & 1 \\\\\n              1 & 1 & 0\n            \\end{xmatrix}$$\n            \n    $$A_S = \\begin{xmatrix}\n              0 & 1 & 0 & 1 \\\\\n              1 & 0 & 1 & 0 \\\\\n              0 & 1 & 0 & 1 \\\\\n              1 & 0 & 1 & 0\n            \\end{xmatrix}$$\n            \n    Note: I label the square's vertexes in the same order as a person draws the square in one stroke.\n    \n    \\item\n    $$A_T^5 = (A_T^2)^2A_T\n            = \\begin{xmatrix}\n                 2 & 1 & 1 \\\\\n                 1 & 2 & 1 \\\\\n                 1 & 1 & 2\n               \\end{xmatrix}^2A_T\n            = \\begin{xmatrix}\n                 6 & 5 & 5 \\\\\n                 5 & 6 & 5 \\\\\n                 5 & 5 & 6\n               \\end{xmatrix}A_T\n            = \\begin{xmatrix}\n                 10 & 11 & 11 \\\\\n                 11 & 11 & 11 \\\\\n                 11 & 10 & 10\n               \\end{xmatrix}$$\n               \n    $$A_S^5 = \\begin{xmatrix}\n                2 & 0 & 2 & 0 \\\\\n                0 & 2 & 0 & 2 \\\\\n                2 & 0 & 2 & 0 \\\\\n                0 & 2 & 0 & 2\n              \\end{xmatrix}^2A_S\n            = \\begin{xmatrix}\n                8 & 0 & 8 & 0 \\\\\n                0 & 8 & 0 & 8 \\\\\n                8 & 0 & 8 & 0 \\\\\n                0 & 8 & 0 & 8\n              \\end{xmatrix}A_S\n            = \\begin{xmatrix}\n                 0 & 16 &  0 & 16 \\\\\n                16 &  0 & 16 &  0 \\\\\n                 0 & 16 &  0 & 16 \\\\\n                16 &  0 & 16 &  0\n              \\end{xmatrix}$$\n              \n    Each diagonal entry shows how many possible routes do there exist to go from that vertex to itself.\n    \n    \\item Let $xy(n) = A^n{xy}$, or how many possible solutions of going from $x$ to $y$ in $n$ steps.\n          Assigning the three vertexes of the triangle to $a, b, c$ randomly, one have:\n          $$\\left\\{\n            \\begin{aligned}\n              aa(n+1) = ab(n) + ac(n) \\\\\n              ab(n+1) = aa(n) + ac(n) \\\\\n              ac(n+1) = aa(n) + ab(n)\n            \\end{aligned}\n          \\right.$$\n          \n          , which can be derived using both the geometrical method and from the matrix multiplication. We need to prove $ab(n) = ac(n)$ and $|aa(n) - ab(n)| = 1$.\n          \n          First, we have the base case:\n          \n          $$\\left\\{\n            \\begin{aligned}\n              aa(1) = 0 \\\\\n              ab(1) = 1 \\\\\n              ac(1) = 1\n            \\end{aligned}\n          \\right.$$\n          \n          $ab(1) = ac(1)$, and $|aa(1) - ab(1)| = 1$. Then, using the induction hypothesis, we have $ab(n+1) = aa(n) + ac(n) = aa(n) + ab(n) = ac(n+1)$, and,\n          \n          \\begin{align*}\n            |aa(n+1) - ab(n+1)| &= |2ab(n) - (ab(n) + aa(n))| \\\\\n                                &= |ab(n) - aa(n)| \\\\\n                                &= 1\n          \\end{align*}\n          \n          This completes the proof. \\QED\n    \n    \\item Label the square's vertexes $a, b, c, d$ in the same order as a person draws the square in one stroke. Assume that the route starts from $a$. With only one step, the route must end in $b$ or $d$. With two steps, the route must end in $a$ or $c$. With three steps, the route must end in $b$ or $d$, again. This forms a cycle: in odd steps, the route must end in $b$ or $d$; in even steps, the route must end in $a$ or $c$. In the matrix's terminology, this means that half entries are nonzero while the rest are zero. \\QED\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{20}\n  \\begin{enumerate}\n    \\item $z_1 + z_2 = x_1 + iy_1 + x_2 + iy_2 = (x_1 + x_2) + i(y_1 + y_2).$ Therefore, $M_{z_1 + z_2} = \\begin{xmatrix}\n                        x_1 + x_2 & y_1 + y_2 \\\\\n                       -y_1 - y_2 & x_1 + x_2\n                     \\end{xmatrix} =\n                     \\begin{xmatrix}x_1 & y_1 \\\\ -y_1 & x_1\\end{xmatrix} +\n                     \\begin{xmatrix}x_2 & y_2 \\\\ -y_2 & x_2\\end{xmatrix} =\n                     M_{z_1} + M_{z_2}$. \\QED\n                     \n    \\item $M_{z_1}M_{z_2} = \\begin{xmatrix}x_1 & y_1 \\\\ -y_1 & x_1\\end{xmatrix}\n                            \\begin{xmatrix}x_2 & y_2 \\\\ -y_2 & x_2\\end{xmatrix}\n                          = \\begin{xmatrix}\n                               x_1x_2 - y_1y_2 &  x_1y_2 + y_1x_2 \\\\\n                              -y_1x_2 - x_1y_2 & -y_1y_2 + x_1x_2\n                            \\end{xmatrix}$.\n          The product matrix is associated with $x_1x_2 - y_1y_2 + i(x_1y_2 + y_1x_2) = x_1x_2 + iy_1iy_2 + x_1iy_2 + x_2iy_1 = (x_1 + iy_1)(x_2 + iy_2) = z_1z_2$. Since this association is bijective, we have $M_{z_1}M_{z_2} = M_{z_1z_2}$. \\QED\n  \\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}{23}\n  \\begin{enumerate}\n    \\item $\\begin{xmatrix}\n            a & 1 & 0 \\\\\n            b & 0 & 1\n          \\end{xmatrix}\n          \\begin{xmatrix}\n            0 & 0 \\\\\n            1 & 0 \\\\\n            0 & 1\n          \\end{xmatrix} =\n          \\begin{xmatrix}\n            1 & 0 \\\\\n            0 & 1\n          \\end{xmatrix} = I_2$\n          \n    \\item Suppose there exists $B$ such that $AB = I_3$. Let $I = I_3$.\n          $I_{11} = 1$, $I_{11} = A_{11}B_{11} + A_{12}B_{12} = 0$, and $0 \\neq 1$.\n          Therefore, A does not have a right inverse.\n          \n    \\item Let $A$ be the matrix in (a). Suppose $B$ be a left inverse of $A$, we have:\n          $$BA = I_3 = I_3^{\\top} = (BA)^{\\top} = A^{\\top}B^{\\top}$$\n          Since there is infinitely many possible $B$s, $A^{\\top}$ has infinitely many right inverses $B^{\\top}$.\n  \\end{enumerate}\n\\end{exercise}\n", "meta": {"hexsha": "e7c0dd27e8e63c93b9aa9e2bb310b5256ceed21b", "size": 5659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW2/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": "HW2/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": "HW2/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": 39.8521126761, "max_line_length": 531, "alphanum_fraction": 0.4271072628, "num_tokens": 1902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7683510145102954}}
{"text": "\\section{MCSSolver}\nThis test evaluates the MCSSolver model for a specific case found in literature (see pages 108-110 \nof N. J. McCormick, ``Reliability and Risk Analysis'', Academic Press inc. (1981)).\nProvided this set of minimal cuts sets (MCSs) for the top event TopEvent:\n\\begin{equation}\n  TopEvent = A + BD + BE + CD + CE\n\\end{equation}\nthe probability of TopEvent can be calculated as \n\\begin{equation}\n  P(TopEvent) = [A + BD + BE + CD + CE]\n              - [ABD + ABE + ACD + ACE + BCD + BCE + BDE + CDE + 2*BCDE]\n              + [ABCD + ABCE + ABDE + ACDE + 4*BCDE + 2*ABCDE]\n              - [BCDE + 4*ABCDE]\n              + [ABCDE]\n\\end{equation}\n\nGive these probability values for the basic events:\n\\begin{itemize}\n  \\item $P(A)=0.01$\n  \\item $P(B)=P(C)=P(D)=P(E)=0.1$\n\\end{itemize}\nthen the analytical values for $P(TopEvent)$ for each order are as follows:\n\n\\begin{table}\n\\begin{tabular}{cc}\nOrder &  $P(TopEvent)$\\\\\n\\hline\n1 & 0.05     \\\\\n2 & 0.0454   \\\\\n3 & 0.045842 \\\\\n4 & 0.045738 \\\\\n5 & 0.045739 \\\\\n\\hline  \n\\end{tabular}\n\\end{table}", "meta": {"hexsha": "89d434f5222782294227f65ded7403669719258d", "size": 1054, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tests/MCSSolver.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/MCSSolver.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/MCSSolver.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": 30.1142857143, "max_line_length": 99, "alphanum_fraction": 0.6223908918, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7683462022664915}}
{"text": "\\chapter{Expectation of a Random Variable}\n\\label{chapter:expectation}\nTo understand the behaviour of a random variable one may try to use the average\nvalue; there are several ways to define the average value, but we are going to\nconcentrate on the definition based on the mean. Given a random variable $X$\nin the finite discrete probability space $(\\Omega, \\Distribution{D})$, the\nexpected value $\\expectation[\\Distribution{D}]{X}$ \n(or $\\expectation[\\omega \\gets \\Distribution{D}]{X(\\omega)}$) of $\\chi$ is equal to\n$\\sum_{\\omega \\in \\Omega} \\Pr_{\\Distribution{D}}(\\omega) X(\\omega)$.\n\nNote that it is possible that there are several $\\omega$'s with the same\n$X(\\omega)$. Hence, one may give an alternative definition of the expectation.\n\\begin{theorem}\n  Let $(\\Omega, \\Distribution{D})$ be a finite discrete probability space, and\n  let $X$ be a random variable in the probability space. Then\n  $\\expectation[\\Distribution{D}]{X} =\n  \\sum_{a \\in \\Im X} a\\Pr_{\\Distribution{D}}(X = a)$.\n\\end{theorem}\n\nAn important property of the expectation that often allows simplifications in\ncomputing the expected value of a random variable is its linearity.\n\\begin{theorem}\n  Let $(\\Omega, \\Distribution{D})$ be a finite discrete probability space; $X$\n  and $Y$ be random variables; and let $\\lambda \\in \\R$.\n  Then $\\expectation[\\Distribution{D}]{X + Y} = \n    \\expectation[\\Distribution{D}]{X} + \\expectation[\\Distribution{D}]{Y}$ and\n  $\\expectation[\\Distribution{D}]{\\lambda X} = \\lambda\n  \\expectation[\\Distribution{D}]{X}$.\n\\end{theorem}\nLet us give a simple example showing that this theorem can help to compute the\nexpected value of a random variable. Consider an experiment consisting of\ntossing $n$ standard coins; i.e. consider the finite discrete probability space\n$(\\Omega, \\Pr)$ such that $\\Omega = \\set{H, T}^n$ and $\\Uniform{\\Omega}$ is the\nuniform distribution on $\\Omega$. We would like to find the expected number $X$\nof heads in the experiment. Let $X_i$ be the random variable that is equal to\n$1$ if the $i$th flip yields heads, otherwise it is equal to $0$. It is clear\nthat $X = \\sum_{i = 1}^n X_i$. Hence, $\\expectation[\\Uniform{\\Omega}]{X} = \n\\sum_{i = 1}^n \\expectation[\\Uniform{\\Omega}]{X_i}$.\nHowever, $\\expectation[\\Uniform{\\Omega}]{X_i} = 1 / 2$ which implies that\n$\\expectation[\\Uniform{\\Omega}]{X} = n / 2$.\n\nLet us use this knowledge to study a game similar to the game discussed in\n\\Cref{chapter:structural-induciton}. Alice selected $500$ numbers from $1$ to\n$1000$ and Bob would like to guess at least one of them. How many questions Bob\nneed to ask to do this?\n\nApparently, the situation is drastically different if Bob's algorithm can be\nrandomized and if it cannot be randomized. To show this we need to extend the\ndefinition of $B$-decision trees so that they can operate not only with\nintegers.\n\\begin{definition}\n  Let $X$ and $Y$ be some sets. We say that $T$ is a $B$-decision tree if\n  \\begin{description}\n    \\item [(base case)] either $T$ is equal to $\\DTReturn{y}$ for $y \\in Y$, or\n    \\item [(recursion step)] $T$ is equal to $\\DTIf{f}{T_0}{T_1}$,\n      where $f : X \\to \\set{0, 1}$, and $T_0$ and $T_1$\n      are $B$-decision trees.\n  \\end{description}\n\n  The number of queries $\\DTHeight[x]{T}$ of $T$ at $x \\in X$ can be defined as\n  follows.\n  \\begin{description}\n    \\item [(base case)] Let $T$ be equal to $\\DTReturn{y}$, where$y \\in Y$. Then\n      $\\DTHeight[x]{T} = 0$ for all $x \\in X$.\n    \\item[(recursion step)] Let $T$ be equal to $\\DTIf{f}{T_0}{T_1}$. Then\n      \\[\n          \\DTHeight[x]{T} = \n          \\begin{cases}\n            \\DTHeight[x]{T_0} + 1 & \\text{if } f(x) = 0 \\\\\n            \\DTHeight[x]{T_1} + 1 & \\text{otherwise}\n          \\end{cases}\n      \\]\n  \\end{description}\n\n  The value $\\DTValue{T}{x}$ of a $B$-decision tree $T$ at $x \\in X$\n  can be defined as follows.\n  \\begin{description}\n      \\item [(base case)] Let $T$ be equal to $\\DTReturn{y}$, where $y \\in Y$.\n        Then $\\DTValue{T}{x} = y$.\n      \\item[(recursion step)] Let $T$ be equal to $\\DTIf{f}{T_0}{T_1}$. Then\n        \\[\n          \\DTValue{T}{x} =\n          \\begin{cases} \n            \\DTValue{T_0}{x} & \\text{if } f(x) = 0 \\\\\n            \\DTValue{T_1}{x} & \\text{otherwise}\n          \\end{cases}.\n        \\]\n  \\end{description}\n\\end{definition}\n\n\\begin{theorem}\n\\label{theorem:guess-one-out-of-many}\n  Let $\\binom{\\range{1000}}{500}$ denote the set of subsets of $\\range{1000}$\n  with $500$ elements.\\footnote{%\n    We are going to discuss such sets in \\Cref{chapter:binomials}.\n  }\n  \\begin{itemize}\n    \\item Let $T$ be a $B$-decision tree such that $\\DTValue{T}{S} \\in S$\n      for all $S \\in \\binom{\\range{1000}}{500}$. Then $\\DTHeight{T} \\ge 9$.\n    \\item There are a set $\\Omega$ of $B$-decision trees and a probability\n      distribution $\\Distribution{D}$ on $\\Omega$ such that \n      $\\DTValue{T}{S} \\in S$ for all $S \\in \\binom{\\range{1000}}{500}$ and \n      $T \\in \\Omega$, but \n      $\\expectation[\\Distribution{D}]{\\DTValue{T}{S}} \\le 2$ for all \n      $S \\in \\binom{\\range{1000}}{500}$.\n  \\end{itemize}\n\\end{theorem}\nInformally, this theorem says that in the worst-case scenario Bob needs at least\n$9$ questions to guess at least one element of Alice's set; however, there is \na strategy for Bob such that it would be enough to ask only $2$ questions, on\naverage.\n\\begin{proof}\n  We prove only the second part of the statement, the first part can be proven\n  similarly to \\Cref{theorem:guess-the-number}.\n  To prove this statement let us consider the following algorithm.\n  \\begin{itemize}\n    \\item Choose $x_1, \\dots, x_n \\in [1000]$ uniformly at random;\n    \\item Set $i = 1$;\n    \\item Query whether $x_i \\in S$ or not.\n    \\item If yes, the output is $x_i$, otherwise increase $i$.\n    \\item If $i \\le n$ go to step $3$, otherwise go to step $6$.\n    \\item Bruteforce all the numbers from $[1000]$ and check whether they belong\n      to $S$ or not.\n  \\end{itemize}\n  Let us compute the expected number of queries made by this algorithm. It is\n  clear that the probability that the algorithm gets yes for $i = k$ is equal to\n  $\\left(\\frac{1}{2}\\right)^k$. Hence, the expected number of queries is equal\n  to \n  \\[\n    \\left(\\frac{1}{2}\\right)^n 1000 + \n    \\sum_{k = 1}^n \\left(\\frac{1}{2}\\right)^k k.\n  \\]\n\n  The following claim gives the formula that allows to compute this\n  sum.\\footnote{%\n    We are going to discuss a method to guess such formulas in\n    \\Cref{chapter:binomials}.\n  }\n  \\begin{claim}\n  \\label{claim:guess-one-out-of-many}\n      For any $k \\in \\N$, $\\sum_{k = 1}^n \\left(\\frac{1}{2}\\right)^k k = \n      2 - \\frac{n + 2}{2^n}$.\n  \\end{claim}\n\n  Therefore, the average number of queries is at most \n  $2 - \\frac{n + 998}{2^n} \\le 2$ for $n \\ge 10$.\n\n  It is also clear that the result of this algorithm is always correct.\n\n  To finish the proof we need to prove \\Cref{claim:guess-one-out-of-many}.\n  We prove it using induction by $n$. It is clear that the statement is true for\n  $n = 0$. Assume the statement is true for $n$; i.e., \n  $\\sum_{k = 1}^n \\left(\\frac{1}{2}\\right)^k k = 2^{-n} (-n + 2^{n + 1} - 2)$.\n  This implies that \n  \\begin{multline*}\n    \\sum_{k = 1}^{n + 1} \\left(\\frac{1}{2}\\right)^k k = \n    2 - \\frac{n + 2}{2^n} + \\frac{n + 1}{2^{n + 1}} = \\\\\n    2 - \\frac{2n + 4 - n - 1}{2^{n + 1}} = 2 - \\frac{(n + 1) + 2}{2^{n + 1}}.\n  \\end{multline*}\n  In other words, the statement is true for $n + 1$. Hence, by the induction\n  principle, we proved the statement for all $n$.\n\\end{proof}\n\n\\begin{chapterendexercises}\n  \\exercise Prove the first part of \\Cref{theorem:guess-one-out-of-many}.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "344fd280d03d18a9403a27f1717ceb349b6e951f", "size": 7616, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_3/chapter_16_expected_value.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_16_expected_value.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_16_expected_value.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.6047904192, "max_line_length": 83, "alphanum_fraction": 0.652967437, "num_tokens": 2446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425355825847, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7683461947321307}}
{"text": "\\chapter{Appendix I: Quaternions}\n\nThere exists a correspondence between the orientation of a $ 3D $ object represented by a $ 3 \\times 3 $ orthonormal matrix and unit quaternions in the group $ SO(3) $ \\citep{Murray}. Quaternions give a global parametrization of $ SO(3) $, by using four numbers instead of three to represent a rotation. A quaternion is a vector quantity of the form,\n\n  \\[Q=q_{0} + q_{1}i + q_{2}j + q_{3}k  \\ \\ \\ \\ \\ \\ \\ \\  qi \\in \\R, i = 0, . . . , 3,\\] \n                            \nwhere, $ q_{0} $ is the scalar component of $ Q $ and $ \\vec{q}= (q_{1}, q_{2}, q_{3}) $ is the vector component. A convenient notation is $ Q = (q_{0}, \\vec{q}) $ with $ q_{0} \\in \\R $, $ \\vec{q} \\in \\R^{3} $.\nThe set of quaternions Q is a 4-dimensional vector space over the reals and the unit quaternion form a group with respect to quaternion multiplication is a rotation group. Multiplication is distributive and associative, but not commutative.\n\nFor rotation through an angle $ \\theta $ about the axis $ n $, the Euler parameters are defined as \\citep{Hanson},\n\\begin{align*}\ne_{0}&=\\cos(\\theta / 2) \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ e_{2}=\\cos \\beta \\cdot\\sin (\\theta / 2)\\\\\ne_{1}&=\\cos \\alpha \\cdot\\sin (\\theta / 2) \\ \\ \\ \\ \\ \\ \\ \\ \\ e_{3}=\\cos \\gamma \\cdot\\sin (\\theta / 2)\n\\end{align*}\nwhere, $ \\alpha, \\beta $ and $ \\gamma $ are the elementary rotations about any given random axis.\n\nGiven a rotation matrix $ R=exp\\left(\\hat{\\omega}\\theta \\right) $, we define the associated unit quaternion as \n$ Q = \\cos (\\theta / 2) $,  $ \\omega\\sin (\\theta / 2) $\nwhere, $ \\omega \\in \\R^{3} $ represents the unit axis of rotation and $ \\theta \\in \\R^{3} $ represents the angle of rotation.\nGiven a unit quaternion $ Q = \\left(q_{0}, \\vec{q} \\right) $, we can extract the corresponding rotation by setting,\n\n\\begin{center}\n\\ \\ \\ \\ \\ $\\theta = 2\\cos ^{-1} q_{0}, \\ \\ \\ \\ \\ \\ \\ \n\\omega = \\left\\lbrace\n\\begin{array}{ll}\n\\frac{\\vec{q}}{\\sin (\\theta / 2)} & \\mbox{if $ \\theta \\neq 0,$}\\\\\n0 & \\mbox{otherwise,}\n\\end{array}\n\\right.\\\n$\n\\end{center}\n\nand  \\[R = exp\\left(\\hat{\\omega}\\theta\\right).\\] \n\nIt is observed that the components of the quaternion are Euler parameters. The Euler parameters have a geometrical meaning and thus the same holds for the components of the corresponding unit quaternion.\n\nThe Frenet 3D coordinate frame can be expressed in the form of quaternions. Assuming that the columns of the equation given below are the vectors $ [t_{i}, n_{i}, b_{i}] $ respectively, $ [q'(t)] $ can be written in the form,\n\\begin{eqnarray}\n\\left[ \n\\begin{array}{c}\nq_{o}'\\\\\nq_{1}'\\\\\nq_{2}'\\\\\nq_{3}'\n\\end{array}\n\\right]=\n\\dfrac{v}{2} \n\\left[\n\\begin{array}{cccc}\n0 & -\\tau & 0 & -\\kappa \\\\\n\\tau & 0 & \\kappa & 0 \\\\\n0 & -\\kappa & 0 & \\tau \\\\\n\\kappa & 0 & -\\tau & 0\n\\end{array}\n\\right] \n\\cdot\n\\left[ \n\\begin{array}{c}\nq_{o}\\\\\nq_{1}\\\\\nq_{2}\\\\\nq_{3}\n\\end{array}\n\\right] \n\\label{13}\n\\end{eqnarray}\nwhere $ v = \\parallel \\dot{c} \\parallel $ and, \n\\begin{align*}\nq_{o}= \\cos (\\theta / 2) = \\dfrac{1}{\\sqrt{2}} & \\sqrt{\\cos \\theta +1} = \\dfrac{1}{2} \\sqrt{Trace (R) +1} \\\\\nq_{1}=& \\dfrac{R_{32}-R_{23}}{4q_{0}} \\\\\nq_{2}=& \\dfrac{R_{13}-R_{31}}{4q_{0}} \\\\\nq_{3}=& \\dfrac{R_{21}-R_{12}}{4q_{0}}\n\\end{align*}\n\nKey properties of equation \\ref{13} are \\citep{Hanson},\n\\begin{enumerate}\n\\item The matrix on the right hand side is antisymmetric, so that $ q(t) \\cdot q'(t)=0 $ is preserved and all unit quaternions remain unit quaternions as they are.\n\\item Nine coupled equations with six orthonormality constraints are reduced to four coupled equations with a single constraint of unit length.\n\\end{enumerate}\n\nFrom the above equation \\ref{13}, the $ curvature $,\n\\begin{equation}\n\\kappa = - \\left[\\dfrac{2(q_{3}q'_{0}+q_{1}q'_{2})}{v(q_{1}^{2}+q_{3}^{2})} \\right]\n\\label{14} \n\\end{equation}\nand the $ torsion $,\n\\begin{equation}\n\\tau = \\dfrac{2q'_{2}+v\\kappa q_{1}}{vq_{3}}\n\\label{15}\n\\end{equation}\ncan be extracted by the quaternion frame. The Frenet equations \\ref{14} and \\ref{15} may be integrated to generate a unique moving continuous frame along the protein backbone, for nonvanishing $ \\kappa (t) $ with its space curve.\n\n\\section*{Motivation for using Quaternions}\n\n\\begin{enumerate}\n\\item It can be observed that the description of Euler angles and exponential co-ordinates suffers from the problem of $ \\textit{singularity} $ in certain situations \\citep{Hanson}. The extraction of parameters from any given rotational transformation matrix produces a singular case as the maps being many to one. While with the unit quaternion, extraction of unit quaternion from given rotational transformation being unique, there is no such case in which the inverse produces singularity. In quaternion space, the scalars, vectors, and quaternions are unified. Besides this, spatial vector can be expressed in quaternion space provides us with elegant properties for manipulating equations.\n\n\n\n\\item The quaternion frame summarizes nine matrix elements with six orthonormality constraints necessary to reduce the actual number of parameters of the frame to the three Euler angles. This forms a $ 3D $ orientation frame in terms of four quaternion frame variables with the single constraint of unit length that provides $ \\textit{less computaional complexity} $.\n\n\n\n\\item The Frenet frame is periodic but not globally defined. As soon as the inflection points \\citep{shuangwei} occur in the plane it is observed that the normal components of the Frenet frame switches sign instantly, while the quaternion frame has no such abrupt changes. The Frenet frame becomes undefined when the curvature $ \\left(\\kappa\\right) $, vanishes along a straight line segment or at inflection point. It provides no such prescription to define a smooth transition from the frame coming and leaving the straight segment. The quaternion frame is comparatively $ \\textit{smooth} $ throughout.\n\\end{enumerate}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n% ------------------------------------------------------------------------\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"../thesis\"\n%%% End: \n", "meta": {"hexsha": "54034e1100191348a7ba5d71c25dfdeb97223554", "size": 6040, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "APS/APS2_4Sep/Appendix1/appendix1.tex", "max_stars_repo_name": "pranavn91/PhD", "max_stars_repo_head_hexsha": "ac44783a1c7c418cafcfc7eb35ef2fc9641688bc", "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": "APS/APS2_4Sep/Appendix1/appendix1.tex", "max_issues_repo_name": "pranavn91/PhD", "max_issues_repo_head_hexsha": "ac44783a1c7c418cafcfc7eb35ef2fc9641688bc", "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": "APS/APS2_4Sep/Appendix1/appendix1.tex", "max_forks_repo_name": "pranavn91/PhD", "max_forks_repo_head_hexsha": "ac44783a1c7c418cafcfc7eb35ef2fc9641688bc", "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.9365079365, "max_line_length": 694, "alphanum_fraction": 0.6842715232, "num_tokens": 1806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7683461929355899}}
{"text": "\\chapter{Probability}\n\n\\section{Probability space}\n\n\\index{probability measure}%\n\\index{probability!measure}%\n\\index{measure!probability}%\nA \\emph{probability measure} \\(\\Pr : 2^\\Omega \\to \\Real\\) on a set \\(\\Omega\\) is a measure where \\(\\Pr(\\Omega) = 1\\).\n\n\\index{probability space}%\n\\index{probability!space}%\n\\index{space!probability}%\nA \\emph{probability space} is a measure space \\((\\Omega,\\Pr)\\) where\n\\(\\Omega\\) is a set called the\n\\index{sample space}%\n\\index{sample!space}%\n\\index{space!sample}%\n\\emph{sample space}\nand \\(\\Pr : 2^\\Omega \\to \\Real\\) is a probability measure.\n\n\\index{event}%\nAn \\emph{event} is a subset of a sample space.\nRelationship between two events \\(A\\) and \\(B\\):\nThey are\n\\index{events!equiprobable}%\n\\index{equiprobable events}%\n\\emph{equiprobable} iff \\(\\Pr(A) = \\Pr(B)\\),\n\\index{mutually exclusive events}%\n\\index{events!mutually exclusive}%\n\\emph{mutually exclusive} iff \\(A \\cap B = \\emptyset\\),\n\\index{independent events}%\n\\index{events!independent}%\n\\emph{independent} iff \\(\\Pr(A \\cap B) = \\Pr(A) \\cdot \\Pr(B)\\).\n\n\\paragraph{Example}\nA fair six-faced dice roll can be modeled with\n\\(\\Omega = \\{1,2,3,4,5,6\\}\\) and \\(\\Pr(\\{1\\}) = \\Pr(\\{2\\}) = \\Pr(\\{3\\}) = \\Pr(\\{4\\}) = \\Pr(\\{5\\}) = \\Pr(\\{6\\}) = 1/6\\).\nThe probability of rolling an odd face is \\(\\Pr(\\{1,3,5\\}) = \\Pr(\\{1\\}) + \\Pr(\\{3\\}) + \\Pr(\\{5\\}) = 3/6\\).\n\n\\section{Density}\n\n\\index{density of a measure}%\nThe \\emph{density of the measure \\(m : 2^U \\to \\Real\\)}\nis the \\(f : U \\to \\Real\\) where \\(\\forall A \\subset U : \\int_A f = m(A)\\).\n\n\\index{probability density function}%\nA \\emph{probability density function} (pdf) is a function \\(f : \\Real \\to \\Real\\) where \\(\\int_\\Real f = 1\\).\n\nLet \\((\\Omega,\\Pr)\\) be a probability space.\nThe density of \\(\\Pr\\) is a pdf.\nThe density of that space is the density of its measure.\n\n\\section{Distribution}\n\n\\index{distribution function}%\n\\index{cumulative distribution function}%\nThe \\emph{distribution function} of \\(\\Pr:2^\\Real\\to\\Real\\) is \\(F(a) = \\Pr(\\{ x~|~x \\le a\\})\\),\nwhich is also called the \\emph{cumulative distribution function} of \\(\\Pr\\).\n\nRelationship between density and distribution:\nIff \\(\\Pr : 2^\\Real \\to \\Real\\),\n\\(f\\) is the density of \\(P\\), and\n\\(F\\) is the distribution of \\(P\\),\nthen \\(F(a) = \\int_{(-\\infty,a]} f\\).\nWe say that \\(f\\) is the pdf of \\(F\\).\n\n\\section{Conditional probability}\n\n\\index{conditional probability}%\n\\index{probability!conditional}%\nThe \\emph{conditional probability of \\(R\\) given \\(C\\)}\nis \\(\\Pr(R|C) = \\Pr(R \\cap C) / \\Pr(C)\\).\n\n\\(C\\)-conditionalization maps \\((\\Omega,\\Pr)\\) to \\((C,Q)\\)\nwhere \\(Q(R) = \\Pr(R|C)\\).\n\nLet \\(f\\) be the density of \\(\\Pr\\).\nRecall that \\(\\Pr(A) = \\int_A f\\).\nTherefore \\(\\Pr(R|C) = \\Pr(R \\cap C)/\\Pr(C) = \\int_{R \\cap C} f / \\int_C f\\).\n\n\\index{conditional density}%\n\\index{density!conditional}%\nThe conditional density \\(f(r|C)\\) satisfies \\(\\int_R (r \\to f(r|C)) = \\Pr(R|C) = Q(R)\\).\n\\(\\int_{R \\cap C} f / \\int_C f\\).\nThe right side of the vertical bar is a set.\n\n\\index{conditional distribution}%\n\\index{distribution!conditional}%\nThe conditional distribution\n\\(F(r \\le a|C) = \\int_{(-\\infty,a]} (r \\to f(r|C))\\).\n\n\\section{Random variable}\n\n\\index{random variable}%\n\\index{random variable!distribution of}%\n\\index{distribution!of random variable}%\nA \\emph{random variable} \\(X : \\Omega \\to V\\)\nis a measurable function.\n\\index{real random variable}%\n\\index{random variable!real}%\nIff \\(V = \\Real\\), then \\(X\\) is a \\emph{real random variable}.\n\\index{probability space!of random variable}%\nSuch \\(X\\) maps\n\\((\\Omega,\\Pr)\\) to \\((V,Q)\\)\nwhere \\(Q(A) = \\Pr(\\{\\omega~|~X(\\omega)\\in A\\}) = \\Pr(X\\in A)\\).\nNote that \\(\\Pr(X \\in A)\\) is an abuse of notation.\n\nThe \\emph{distribution of \\(X\\)} is the distribution of \\(Q\\),\nthat is \\(F(a) = \\Pr(X \\le a)\\).\n\n\\(X \\sim D\\) means that \\emph{the distribution of \\(X\\) is \\(D\\)}.\n\n\\index{probability mass function}%\nA \\emph{probability mass function} (pmf) \\(f : \\Omega \\to \\Real\\)\nis a function where \\(\\forall A \\subseteq \\Omega : \\sum_{x \\in A} f(x) = \\Pr(A)\\).\n\\index{probability density function}%\nA \\emph{probability density function} (pdf) \\(f : \\Omega \\to \\Real\\)\nis a function where \\(\\forall A \\subseteq \\Omega : \\int_A f = \\Pr(A)\\).\nA statement about pdfs can usually be translated into\na statement about pmfs by replacing integral with summation.\n\nIf \\(A \\subseteq \\Real\\), then a pmf \\(f : A \\to \\Real\\)\ncan be turned into a pdf \\(g : \\Real \\to \\Real\\)\nwhere\n\\(g(x) = \\sum_{c \\in A} f(c) \\cdot \\delta(x-c)\\)\nwhere\n\\index{Dirac delta function}%\n\\index{function!Dirac delta}%\n\\(\\delta\\) is the \\emph{Dirac delta function}\nwhere\n\\( \\int_X \\delta = [0 \\in X] \\)\nwhere \\([F]\\) is 0 iff \\(F\\) is false and 1 iff \\(F\\) is true.\n\n\\paragraph{Iid}\nTwo random variables \\(X\\) and \\(Y\\) are\n\\index{random variables!independent}%\n\\index{independent random variables}%\n\\emph{independent} iff \\(\\forall A, B : \\Pr(X \\in A \\wedge Y \\in B) = \\Pr(X \\in A) \\cdot \\Pr(Y \\in B)\\),\n\\index{random variables!identically distributed}%\n\\index{identically-distributed random variables}%\n\\emph{identically distributed} iff\n\\(\\forall A : \\Pr(X \\in A) = \\Pr(Y \\in A)\\),\n\\index{random variables!independent and identically-distributed}%\n\\index{independent and identically-distributed random variables}%\n\\index{random variables!iid}%\n\\index{iid!random variables}%\n\\emph{iid} iff they are independent and identically-distributed.\n\n\\paragraph{Example}\nIf \\(\\Omega\\) is the set of all people on Earth,\nthen \\(X(\\omega)\\) might be the age of the person \\(\\omega\\) in years.\nIf \\(\\Omega\\) is the set of all cookies produced by a machine,\nthen \\(X(\\omega)\\) might be the sugar amount in the cookie \\(\\omega\\) in grams.\nIf \\(\\Omega\\) is the set of all tasks,\nthen \\(X(\\omega)\\) might be the time required to finish the task \\(\\omega\\) in seconds.\n\n\\section{Joint and marginal}\n\n\\index{joint probability space}%\n\\index{probability space!joint}%\n\\index{probability!joint}%\nLet there be \\(n\\) probability spaces \\(S_k = (\\Omega_k,\\Pr_k)\\).\nThe \\emph{joint probability space} of \\(S_1,\\ldots,S_n\\) is\n\\(S = (\\Omega,\\Pr)\\)\nwhere \\(\\Omega = \\prod_{k=1}^n \\Omega_k\\).\n\nDefine the set \\(W_k(A) = \\{ \\omega ~|~ \\omega \\in \\Omega, ~ \\omega_k \\in A \\}\\).\nRelationship: \\(\\Pr_k(A) = \\Pr(W_k(A))\\).\nWe say that \\(\\Pr_k\\) is obtained by \\emph{retaining} the \\(k\\)th component of \\(S\\).\n\nLet \\(N = \\{1,\\ldots,n\\}\\) be the set of the indexes of \\(S\\)\nand let \\(K \\subseteq N\\) be the set of the indexes we want to retain.\nThe result of\n\\index{retain}%\n\\emph{retaining} \\(K\\) in \\(S\\)\nis \\((\\Omega,\\Pr_K)\\) where\n\\(\\Pr_K(A) = \\Pr\\left(\\bigcap_{k \\in K} W_k(A_k)\\right)\\)\nwhere \\(A_k = \\{ a_k ~|~ a \\in A \\} \\).\n\\index{marginalize out}%\nTo \\emph{marginalize out} \\(K\\) from \\(S\\) is to retain \\(N-K\\) in \\(S\\).\nNote the relationship among ``retain'', ``marginalize out'', and ``all but'':\nTo retain \\(x\\) is to marginalize out all but \\(x\\),\nand to marginalize out \\(x\\) is to retain all but \\(x\\).\n\n\\index{marginal probability space}%\n\\index{probability space!marginal}%\n\\index{probability!marginal}%\nMarginal probability space?\nExample?\n\nMany random variables:\nThe notation \\(\\Pr(X_1\\in A_1 \\wedge \\ldots \\wedge X_n\\in A_n)\\) means\n\\(\\Pr(\\{(\\omega_1,\\ldots,\\omega_n) ~|~ X_1(\\omega_1) \\in A_1, ~ \\ldots, ~ X_n(\\omega_n) \\in A_n\\})\\)\nwhere \\(\\Omega = \\prod_{k=1}^n \\Omega_k\\)\nand \\(\\forall k (X_k : \\Omega_k \\to V_k)\\).\nSuch \\((\\Omega,\\Pr)\\) is a \\emph{joint probability space}.\n\n\\section{Central tendency}\n\n\\index{average!weighted}%\n\\index{weighted average}%\nThe \\emph{weighted average} of \\(f:\\Real\\to\\Real\\) is\n\\(w(f) = \\int_\\Real (x \\to f(x) \\cdot x) / \\int_\\Real f\\)\nwhere \\(\\int_\\Real f\\) is the\n\\index{normalizing constant}%\n\\index{constant!normalizing}%\n\\emph{normalizing constant},\nwhich is 1 iff \\(f\\) is a pdf.\n\n\\index{mean!of a pdf}%\nThe \\emph{mean} of a pdf \\(f\\) is \\(\\mu(f) = w(f)\\),\n\\index{mean!of a distribution}%\nof a distribution \\(D\\) whose pdf is \\(f\\) is \\(\\mu(D) = \\mu(f)\\),\n\\index{mean!of a probability measure}%\nof a probability measure \\(\\Pr\\) whose distribution is \\(D\\) is\n\\(\\mu(\\Pr) = \\mu(D)\\),\n\\index{mean!of a probability space}%\nof a probability space \\(S = (\\Real,\\Pr)\\) is \\(\\mu(S) = \\mu(\\Pr)\\).\n\n\\index{expectation}%\nThe \\emph{expectation} of a random variable \\(X \\sim D\\) is \\(\\Expect{X} = \\mu(D)\\).\n\\index{linearity of expectation}%\n\\index{expectation!linearity of}%\nExpectation is linear:\n\\(\\Expect{aX} = a \\Expect{X}\\) and\n\\(\\Expect{X+Y} = \\Expect{X} + \\Expect{Y}\\).\n\n\\index{moment}%\nThe \\emph{\\(k\\)th moment of \\(X\\)} is \\(m_k(X) = \\Expect{X^k}\\)\nwhere superscript means power and not composition.\nExpectation is first moment.\n\n\\section{Dispersion tendency}\n\n\\index{central moment}%\nThe \\emph{\\(k\\)th central moment of \\(X\\)} is \\(\\mu_k(X) = \\Expect{(X - \\Expect{X})^k}\\).\n\n\\index{variance}%\n\\emph{Variance} is the second central moment.\nThe variance of \\(X\\) is \\(\\sigma_X^2 = \\mu_2(X)\\).\n\n\\index{standard deviation}%\n\\emph{Standard deviation} is square root of variance.\n\n\\index{skewness}%\n\\emph{Skewness} is the third central moment.\n\n\\section{Mixed moments}\n\nCovariance is \\(Cov(X,Y) = \\Expect{(X-\\Expect{X})(Y-\\Expect{Y})}\\).\nCorrelation is \\(Cor(X,Y) = Cov(X,Y) / (\\sigma_X \\sigma_Y)\\).\n\n\\section{Bernoulli trial}\n\n\\index{Bernoulli trial}%\nA \\emph{Bernoulli trial}\nis a probability space \\((\\Omega,\\Pr)\\) where \\(\\Omega = \\{0,1\\}\\),\n\\(\\Pr(\\{0\\}) = 1 - p\\), and \\(\\Pr(\\{1\\}) = p\\).\n\n\\section{Bernoulli distribution}\n\n\\index{distribution!Bernoulli}%\n\\index{Bernoulli distribution}%\nThe pmf of \\(\\Bernoulli(p)\\) (the \\emph{Bernoulli distribution with parameter \\(p\\)})\nis \\(f(0) = 1 - p\\) and \\(f(1) = p\\),\nwhich can also be written \\(f(k) = (1-p)^{1-k} p^k\\) where \\(k \\in \\{0,1\\}\\).\n\n\\section{Binomial distribution}\n\nBernoulli distribution is a special case of\n\\emph{binomial distribution} \\(\\Binomial(n,k,p)\\) whose pmf is\n\\(f(k) = \\binom{n}{k} (1-p)^k p^{n-k}\\) where \\(k : \\Nat, k \\le n\\) with \\(n=1\\).\n\\(\\Binomial(n,k,p)\\) is the distribution of \\(n\\) iid instances of a Bernoulli trial.\n\nThe \\emph{binomial formula} is \\(\\binom{n}{k} = \\frac{n!}{k!(n-k)!}\\).\n\n\\(\\binom{n}{k}\\) is the number of all \\(k\\)-sized subsets of an \\(n\\)-sized set.\nThe cardinality of \\(\\{ S ~|~ S \\subseteq A, |S| = k \\}\\) is \\(\\binom{n}{k}\\)\nwhere \\(|A| = n\\).\n\nThe binomial formula is involved in the expansion \\((x+y)^n = \\sum_{k=0}^n \\binom{n}{k} x^k y^{n-k}\\).\n\n\\section{Multivariate random variable}\n\n\\index{random variable!multivariate}%\n\\index{multivariate random variable}%\n\\index{random vector}%\n\\index{random!vector}%\n\\index{vector!random}%\nA \\emph{multivariate random variable} or \\emph{random vector}\nis a vector of random variables,\nor a vector-valued random variable,\nor a random variable whose sample space is a vector space.\n\nDefine \\(\\{ X < a \\}\\) as \\(\\{ x ~|~ x \\in u, ~ X~x < a \\}\\).\nIf \\(f\\) is a bijection and \\(Y = f~X\\),\nthen \\(P~\\{f~X < a\\} = P~\\{X < f^{-1}~a\\}\\).\n\nAlgebra on random variables:\nIf \\(k : a\\) and \\(X : RV~a\\) then \\(k X : RV~a\\).\nIf \\(X : RV~a\\) and \\(Y : RV~a\\) then \\(X+Y : RV~a\\).\n\n\\index{population}%\n\\index{population!to sample a}%\n\\index{population!sample space of}%\n\\index{population!probability space}%\n\\index{sample (noun)}%\n\\index{sample (verb)!a population}%\n\\index{observation}%\n\\index{unit!statistical}%\nA \\emph{population} is a probability space.\nLet \\(p\\) be a population and \\(s\\) be its sample space.\nA \\emph{sample} of \\(p\\) is a subset of \\(s\\).\nTo \\emph{sample} \\(p\\) is to pick a subset of \\(s\\).\nAn \\emph{observation} is a member of \\(s\\).\nA \\emph{unit} is an observation.\n\n\\section{What are these rules for?}\n\n\\index{chain rule}%\n\\index{probability!chain rule}%\n\\index{conditional probability!chain rule}%\nThe \\emph{chain rule} is \\(\\Pr(a \\cap b) = \\Pr(b|a) \\cdot \\Pr(a) = \\Pr(a|b) \\cdot \\Pr(b)\\).\n\n\\index{law of total probability}%\n\\index{probability!law of total probability}%\n\\index{conditional probability!law of total probability}%\nThe \\emph{law of total probability} is \\(\\Pr(b) = \\sum_{k=1}^n \\Pr(b|a_k) \\cdot \\Pr(a_k) \\)\nwhere \\(a_1,\\ldots,a_n\\) is a partitioning of \\(a\\).\n\n\\index{Bayes rule}%\nThe \\emph{Bayes rule} is \\(\\Pr(a|b) = \\Pr(b|a) \\cdot \\Pr(a)\\)\nwhere \\(a_1,\\ldots,a_n\\) is a partitioning of \\(a\\).\n\n\\section{Materials looking for place to belong}\n\n\\index{Gaussian distribution}%\n\\index{normal distribution}%\n\\index{distribution!Gaussian}%\n\\index{distribution!normal}%\n\\index{Gaussian probability density function}%\n\\index{normal probability density function}%\n\\index{probability density function!Gaussian}%\n\\index{probability density function!normal}%\nThe \\emph{Gaussian pdf} or the \\emph{normal pdf}\nwith mean \\(\\mu\\) and variance \\(\\sigma^2\\) is\n\\(\\frac{1}{\\sqrt{2\\sigma^2\\pi}}\\exp\\left(-\\frac{(x-\\mu)^2}{2\\sigma^2}\\right)\\).\n\n\\index{Poisson distribution}%\n\\index{Chi-square distribution}%\n\\index{Cauchy distribution}%\n\\index{Beta distribution}%\nThe \\emph{Poisson distribution}...\nThe \\emph{Chi-square distribution}...\nThe \\emph{Cauchy distribution}...\nThe \\emph{Beta distribution}...\n\n\\section{Random process}\n\nThe type of a \\emph{random process} is \\(\\Nat \\to \\Omega \\to R\\).\n\n\\emph{Random process} is also called \\emph{stochastic process}.\n\n\\section{Wiener process}\n", "meta": {"hexsha": "34149ac6a00b919bbd6e36559b4f5d23c86a9e2c", "size": 13101, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/probability.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/probability.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/probability.tex", "max_forks_repo_name": "edom/work", "max_forks_repo_head_hexsha": "df55868caa436efc631e145a43e833220b8da1d0", "max_forks_repo_licenses": ["Apache-2.0", "CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-10-02T15:20:22.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-02T15:20:22.000Z", "avg_line_length": 35.8931506849, "max_line_length": 119, "alphanum_fraction": 0.658270361, "num_tokens": 4455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898127684335, "lm_q2_score": 0.8479677564567912, "lm_q1q2_score": 0.7682501489059569}}
{"text": "\\chapter{Strong Induction}\n\\label{chapter:strong-induction}\nSometimes $P(k)$ is not enough to prove $P(k + 1)$ and we need all the\nstatements $P(1)$, \\dots, $P(k)$. In this case we may use the following\ninduction  principle.\n\n\\begin{theorem}[The Strong Induction Principle]\n\\label{theorem:strong-induction}\n    Let $P(n)$ be some statement about positive integer $n$.\n    Hence, $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)] If $P(n_0 + 1)$, \\dots, $P(n_0 + k)$ are true,\n            then $P(n_0 + k + 1)$ is also true for all positive integers $k$.\n  \\end{description}\n\\end{theorem}\n\nBefore we prove this theorem let us present some applications of this\nprinciple.\n\nThe Fibonacci numbers are defined as follows:\n$f_0 = 0$, $f_1 = 1$, and $f_k = f_{k - 1} + f_{k - 2}$ for $k \\ge 2$ (note\nthat they are also defined using strong induction since we use not only\n$f_{k - 1}$ to define $f_k$).\\footnote{%\n  Fibonacci numbers are named after Italian mathematician Leonardo of Pisa,\n  later known as Fibonacci. In his 1202 book ``Liber Abaci'', Fibonacci\n  introduced the sequence to Western European mathematics. However, the sequence\n  had been described as early as 200 BC in work by Indian mathematician Pingala\n  on enumerating possible patterns of Sanskrit poetry formed from syllables of\n  two lengths.\n  \n  Fibonacci numbers appear unexpectedly often in mathematics, so much so that\n  there is an entire journal dedicated to their study, the ``Fibonacci\n  Quarterly''. Applications of Fibonacci numbers include computer algorithms\n  such as the Fibonacci search technique and the Fibonacci heap data structure,\n  and graphs called Fibonacci cubes used for interconnecting parallel and\n  distributed systems.\n}\n\n\\begin{theorem}[The Binet formula]\n    The Fibonacci numbers are given by the following formula\n    \\[\n        f_n = \\frac{\\alpha^n - \\beta^n}{\\sqrt{5}},\n    \\]\n    where $\\alpha = \\frac{1 + \\sqrt{5}}{2}$ and\n    $\\beta = \\frac{1 - \\sqrt{5}}{2}$.\n\\end{theorem}\n\\begin{proof}\n    We use the strong induction principle to prove this statement with $n_0 = -1$.\n    Let us first prove the base case,\n    $\\frac{(\\alpha^0 - \\beta^0)}{\\sqrt{5}} = 0 = f_0$.\n    We also need to prove the induction step.\n    \\begin{itemize}\n        \\item If $k = 1$, then $\\frac{(\\alpha^1 - \\beta^1)}{\\sqrt{5}} = 1 = f_1$.\n        \\item Otherwise, by the induction hypothesis,\n            $f_k = \\frac{\\alpha^k - \\beta^k}{\\sqrt{5}}$ and\n            $f_{k - 1} = \\frac{\\alpha^{k - 1} - \\beta^{k - 1}}{\\sqrt{5}}$.\n            By the definition of the Fibonacci numbers $f_{k + 1} = f_k + f_{k - 1}$.\n            Hence,\n            \\[\n                f_{k + 1} = \\frac{\\alpha^k - \\beta^k}{\\sqrt{5}} +\n                \\frac{\\alpha^{k - 1} - \\beta^{k - 1}}{\\sqrt{5}}.\n            \\]\n            Note that it is enough to show that\n            \\begin{equation}\n            \\label{equation:binet}\n                \\frac{\\alpha^{k + 1} - \\beta^{k + 1}}{\\sqrt{5}} =\n                \\frac{\\alpha^k - \\beta^k}{\\sqrt{5}} +\n                \\frac{\\alpha^{k - 1} - \\beta^{k - 1}}{\\sqrt{5}}.\n            \\end{equation}\n            Note that it is the same as\n            \\[\n                \\frac{\\alpha^{k + 1} - \\alpha^k - \\alpha^{k - 1}}{\\sqrt{5}} =\n                \\frac{\\beta^{k + 1} - \\beta^k - \\beta^{k - 1}}{\\sqrt{5}}.\n            \\]\n            Additionally, note that $\\alpha$ and $\\beta$ are roots of the equation\n            $x^2 - x - 1 = 0$. Hence,\n            $\\alpha^{k + 1} - \\alpha^k - \\alpha^{k - 1} = \\alpha^{k - 1}(\\alpha^2 -\n            \\alpha - 1) = 0$ and\n            $\\beta^{k + 1} - \\beta^k - \\beta^{k - 1} =\n            \\beta^{k - 1}(\\beta^2 - \\beta - 1) = 0$. Which implies\n            equality~(\\ref{equation:binet}).\n    \\end{itemize}\n\\end{proof}\n\n\\begin{template}\n  \\textbf{Template for proving a statement using strong induction.} \\\\\n\n  We use induction by $n$. Base case for $n = n_0 + 1$: \\emph{present some\n  argument that proves the statement with $n$ replaced by $1$}. \n\n  Now we need to prove the induction step from $n_0 + 1$, \\dots, $n_0 + k - 1$\n  to $k$. Let us assume now that the statement is true for any $n$ from $n_0 +\n  1$ to $n_0 + k - 1$ for some $k$. \\emph{Present some argument of the statement\n  with $n$ replaced by $n_0 + k$ assuming the statement is true if we replace\n  $n$ by $n_0 + \\ell$ for $1 \\le \\ell < k - 1$}. Hence,\n  the statement is true for all $n$ by the induction principle.\n\\end{template}\n\n\n\nAnother example of an application of the strong induction is the proof that\nany number can be written in digital numeral systems with any base.\n\\begin{theorem}\n  Let $b > 1$ be an integer. Then there is a unique representation \n  $(c_0, \\dots, c_\\ell)_b$ of any positive number $n$ in the base-$b$ digital\n  numeral system. \n  In other words, for any positive integer $n$, there are unique \n  $0 \\le c_0, \\dots, c_\\ell < b$ such that $n = \\sum_{i = 0}^\\ell b^i c_i$.\n\\end{theorem}\n\\begin{proof}\n  We prove the statement using strong induction by $n$. The base case for\n  $n < b$ is clear (we can choose $\\ell = 0$ and $c_0 = n$).\n  Let us now prove the induction step. Assume the statement is true for all\n  $k < n$. Let $n$ divided by $b$ be equal to $q$ with the remainder $c_0$.\n  Note that $(n - c_0) / b < n$ is a positive integer. Hence,\n  by the induction hypothesis, there are\n  $0 \\le c_1, \\dots, c_\\ell < b$\n  such that $(n - c_0) / b = \\sum_{i = 1}^\\ell b^{i - 1} c_i$. Hence,\n  $n = \\sum_{i = 0}^\\ell b^i c_i$.\n\\end{proof}\n\\nomenclature[U]{$(c_0, \\dots, c_\\ell)_b$}{%\n  denotes the number $n = \\sum_{i = 0}^\\ell b^i c_i$; i.e., $c_0, \\dots, c_\\ell$\n  are the digits of $n$ in the base-$b$ digital representation}\n\nNow we are ready to prove the strong induction principle.\n\\begin{proof}[Proof of Theorem~\\ref{theorem:strong-induction}]\n  It is easy to see that if $P(n)$ is true for all $n > n_0$, then the base\n  case and the induction steps are true. Let us prove that if the base case and\n  the induction step are true, then $P(n)$ is true for all $n > n_0$.\n\n  Let $Q(k)$ be the statement that $P(n_0 + 1)$, \\dots, $P(n_0 + k)$ are true.\n  Note that $Q(1)$ is true by the base case for $P$. Additionally, note that if\n  $Q(k)$ is true, then $Q(k + 1)$ is also true, by the induction step for $P$.\n  Hence, by the induction principle, $Q(k)$ is true for all positive integers\n  $k$. Which implies that $P(n_0 + k)$ is true for all positive integers $k$.\n\\end{proof}\n\n\n\\section{Analysis of Recursive Algorithms}\n\\label{section:strong-induction-recursive}\nTo illustrate the power of recursive definitions and strong induction, consider\nfollowing game: Alice 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?\n\nThe following simple algorithm allows Bob to learn the number using $10$\nquestions.\n\n\\begin{enumerate}\n  \\item Bob start with two numbers $\\ell = 0$ and $u = 1000$.\n  \\item \\label{algorithm-step:binary-search-result-guess-number}\n    If there is only one integer $x$ such that $\\ell < x \\le u$, Bob says that\n    Alice's number is $x$ and terminates the algorithm.\n  \\item \\label{algorithm-step:binary-search-decision-guess-number}\n    Bob asks whether the Alice's number is at most $(\\ell + u) / 2$. If the\n    answer is yes, then Bob replaces $u$ by $(\\ell + u) / 2$; otherwise Bob\n    replaces $\\ell$ by $(\\ell + u) / 2$.\n    Bob goes to step~\\ref{algorithm-step:binary-search-decision-guess-number}.\n\\end{enumerate}\n\nWe need to prove that Bob's algorithm is correct and that it makes at most $10$\nquestions. We prove a bit stronger statement. If on\nstep~\\ref{algorithm-step:binary-search-decision-guess-number} $u - \\ell < n$ and\nAlice's number is between $\\ell$ and $u$ ($u$ and $\\ell$ are some reals), then\nthe algorithm returns Alice's number using at most $\\log_2 n$ questions \n($\\log_2 1000 \\le 10$). We are going to use strong induction by $n$. \n\nThe base case is clear since if $u - \\ell < 1$ there is at most one integer\nbetween $u$ and $\\ell$ and by the assumption there is Alice's number between\n$\\ell$ and $u$. Hence, Bob is going to guess Alice's number correctly without asking\nany questions.\n\nAssume that the statement is true for all $m < n$. Note that \n$\\ell < (\\ell + u) / 2 < u$ since $n \\ge 2$. Therefore Alice's number is either\nbetween $\\ell$ and $(\\ell + u) / 2$ or between $(\\ell + u) / 2$ and $u$. Hence,\nwe go to step~\\ref{algorithm-step:binary-search-decision-guess-number} with new\n$\\ell'$ and $u'$ such that $u' - \\ell' < n / 2$ and Alice's number is between\n$\\ell'$ and $u'$. As a result, by the induction hypothesis, Bob is going to\nguess Alice's number correctly using at most $1 + \\log_2 (n / 2) = \\log_2 n$\nquestions.\n\n\\begin{chapterendexercises}\n    \\exercise Let $a_0 = 2$, $a_1 = 5$, and $a_n = 5a_{n - 1} - 6 a_{n - 2}$\n        for all integers $n \\ge 2$. Show that $a_n = 3^n + 2^n$ for all integers\n        $n \\ge 0$.\n        \\begin{solution}\n            We prove this using induction by $n$. The base case for $n \\le 1$ is clear\n            since $3^0 + 2^0 = 2$ and $3^1 + 2^1 = 5$.\n\n            Let us prove the induction step. Assume that $a_n = 3^n + 2^n$ and\n            $a_{n - 1} = 3^{n - 1} + 2^{n - 1}$, we need to prove that\n            $a_{n + 1} = 3^{n + 1} + 2^{n + 1}$. Note that\n            \\begin{multline*}\n                a_{n + 1} = 5a_n - 6 a_{n - 1} =\n                5 \\cdot 3^n + 5 \\cdot 2^n - 6 \\cdot 3^{n - 1} -\n                6 \\cdot 2^{n - 1} = \\\\\n                3^{n - 1} \\cdot 9 + 2^{n - 1} 4 = 3^{n + 1} + 2^{n + 1}.\n            \\end{multline*}\n        \\end{solution}\n    \\exercise Let $f_0 = 1$, $f_1 = 1$, and $f_{n + 2} = f_{n + 1} + f_n$ for\n        all integers $n \\ge 0$. Show that\n        $f_n \\ge \\left(\\frac{3}{2}\\right)^{n - 2}$.\n    \\exercise Show that $f_{n + m} = f_{n - 1} f_{m - 1} + f_n f_m$.\n    \\exercise Give a nonadaptive algorithm for Bob that allows him to guess the\n      number using $10$ queries. In other words, write $10$ questions such that\n      answers to these questions allow Bob to guess the number.\n    \\exercise Show that \\Cref{algorithm:binary-search} makes at most\n      $6 + 2\\log_2(n)$ comparisons.\n      \\begin{algorithm}\n        \\begin{algorithmic}[1]\n          \\Function{BinarySearch}{$e$, $a_1$, \\dots, $a_n$}\n            \\If{$n \\le 5$}\n              \\For{$i$ from $1$ to $n$}\n                \\If{$a_i = e$}\n                  \\State\\Return{i}\n                 \\EndIf\n              \\EndFor\n            \\Else\n              \\State{$\\ell \\gets \\floor{\\frac{n}{2}}$}\n              \\If{$a_\\ell \\le e$}\n                \\State\\Call{BinarySearch}{$e$, $a_1$, \\dots, $a_\\ell$}\n              \\Else\n                \\State\\Call{BinarySearch}{$e$, $a_{\\ell + 1}$, \\dots, $a_n$}\n              \\EndIf\n            \\EndIf\n          \\EndFunction\n        \\end{algorithmic}\n        \\caption{The binary search algorithm that finds an element $e$ in the sorted\n          list $a_1$, \\dots, $a_n$.}\n        \\label{algorithm:binary-search}\n      \\end{algorithm}\n\\end{chapterendexercises}\n", "meta": {"hexsha": "e347c3b087e2f2275d88a477b99fcfc9b0f20ec4", "size": 11220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_1/chapter_4_strong_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_4_strong_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_4_strong_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": 47.7446808511, "max_line_length": 86, "alphanum_fraction": 0.6082887701, "num_tokens": 3586, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.9343951698485602, "lm_q1q2_score": 0.7682495522616979}}
{"text": "\\section{Additional comments}\n\\paragraph{\\textbf{Remarks}}\n\\begin{enumerate}\n\t\n\t\\item $k$ disjoint sets $A_1,A_2,\\cdots,A_k$ represent $k$ classes. We use $A$ to denote\n\t\\[\n\tA = A_1\\cup A_2\\cup \\cdots \\cup A_k. \n\t\\]\n\tNaturally we can define the standard decision mapping $\\bm{\\chi}:A \\rightarrow \\{e_1,e_2,\\cdots,e_k\\}\\subset \\mathbb{R}^k$  as\n\t\\begin{equation}\n\t\\bm{\\chi}(x) = e_i,\\ x\\in A_i,\n\t\\end{equation}\n\twhich is just like a characteristic function.\n\t\n\t\\item To solve a classification problem, our goal is to find the standard decision mapping. But usually it's unpractical, because we seem to be better at dealing with continuous functions with continuous outputs. A natural idea is to reach the goal in two steps. We can use a composition of the following two mappings \n\t$$\\bm{f}:A \\rightarrow \\mathbb{R}^k;\\ x\\mapsto y.$$\n\t$$\\bm{\\pi}: \\mathbb{R}^k \\rightarrow \\{e_1,e_2,\\cdots,e_k\\};\\ \\ y\\mapsto e_i,i = \\argmax_j~y_j$$\n\tto obtain the standard decision mapping. Notice that the mapping $\\bm{\\pi}$ is fixed, so we only need to find a proper mapping $\\bm{f}$. \n\t\n\t\\item Assume that we want to find a proper $\\bm{f}$ in a mapping sapce $\\mathscr{H}$. The result of a classification problem depends on which $\\mathscr{H}$ to choose and how to find the optimal mapping $\\bm{f}$ in $\\mathscr{H}$.\\\\\n\t\n\t\\item Given a mapping space $\\mathscr{H}$, if there exists an $\\mathbf{f}\\in \\mathscr{H}$ such that \n\t\\begin{equation}\n\t\\bm{\\chi} = \\bm{\\pi} \\circ \\bm{f}.\n\t\\end{equation}\n\twe can say that $A_1,A_2,\\cdots,A_k$ are $\\mathscr{H}$-separable. Setting $\\mathscr{H}$ to be the affine mapping space, $i.e.$ $\\mathscr{H} = \\{\\bm{f}: \\bm{f}(x) = Wx+b\\}$, we obtain the definition of linearly separable.\\\\\n\t\n\t\\item A linear model  is a method to find the optimal $W$ and $b$ when we take $\\mathscr{H} = \\{\\bm{f}: \\bm{f}(x) = Wx+b\\}$.\\\\\n\t\n\t\\item Assume that $\\bm{\\phi}$ is a feature mapping from $A$ to a feature space $\\mathcal{H}$. A natural choice of $\\mathscr{H}$ is \n\t\\begin{equation}\n\t\\mathscr{H} = \\{\\bm{f}: \\bm{f}(x) = W\\bm{\\phi}(x)+b\\}\n\t\\end{equation}\n\t%If we set $\\mathcal{H}$ to be a Reproduced Kernel Hilbert Space $w.r.t.$ a kernel function $\\bm{k}$ and use SVM to find the optimal $W$ and $b$, we can obtain the methods of kernel SVM.\n\\end{enumerate}\n\n\n\\subsection{General approach for separation }\nA collection of sets $A_i\\subset \\mathbb{R}^n$, $1\\le i\\le k$, are said to be separable if there exists a continuous function $h:\\mathbb{R}^n\\to\\mathbb{R}^k$ such that $h(x)=e_i$.\n\nA general approach:\n\\begin{itemize}\n\t\\item Find a ``nonlinear\" function $h_0:\\mathbb{R}^n\\to\\mathbb{R}^m$ such that\n\\begin{enumerate}\n\t\\item $\\tilde{A}_i=h_0(A_i)\\subset\\mathbb{R}^m$ are linearly separable\n\t\\item $m\\ll n$\n\\end{enumerate}\n\\item Use a ``linear\" classifier $l_0:\\mathbb{R}^m\\to\\mathbb{R}^k$, then $h=l_0\\circ h_0:\\mathbb{R}^n\\to\\mathbb{R}^k$ is the classifier.\n\\end{itemize}\n\n\\begin{remark}\n\t\\begin{enumerate}\n\t\t\\item $h_0$: dimension reduction;\n\t\t\\item Feature extraction;\n\t\t\\item $h_0$: deep neural network, special function class;\n\t\t\\item $x^{l+1}=\\sigma(Wx^l+b)$, for CNN, $W,b$ are ``sparse\";\n\t\t\\item ``linear classifier\" is fully connected layer.\n\t\\end{enumerate}\n\t\\end{remark}\n\n\\subsection{Feature map}\n\n\\begin{remark}\nThe \"linear\" here means that $wx+b$ is linear with respect to $x$. This condition is not crucial. Actually, we can replace $x$ by $\\phi: \\mathbb{R}^n\\rightarrow \\mathbb{R}^m$. To be specific, let  $\\tilde x=w\\phi(x)+b$ and $\\tilde A_i=\\phi (A_i)\\in \\mathbb{R}^m$. The function $\\phi$ here is a feature map, \ncommon choices include\n\\begin{enumerate}\n\\item $\\phi(x)=x$;\n\\item finite elements, wavelets;\n\\item deep neural networks.\n\\end{enumerate}\n\\end{remark}\n\n\\input{6DL/LinearSets}\n", "meta": {"hexsha": "7a25407c5aee25c6a1654449586e09f3a9e373e9", "size": 3710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LRComments.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/LRComments.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/LRComments.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.1351351351, "max_line_length": 319, "alphanum_fraction": 0.6873315364, "num_tokens": 1288, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88242786954645, "lm_q2_score": 0.870597273444551, "lm_q1q2_score": 0.7682392972386233}}
{"text": "%================================\n\\section{More on Separation Axioms}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[saperated sets]\n\tLet $(X, \\mathcal T)$ be a topological space, and let $A, B \\in \\mathcal P(X)$.\n\t\n\t\\begin{enumerate}[(i)]\n\t\t\\item $A$ and $B$ are said to be \\textit{separated} iff each is disjoint from other's closure.\n\t\t\\item $A$ and $B$ are said to be \\textit{separated by neighbourhoods} iff there are neighbourhoods $N_A$ of $A$ and $N_B$ of $B$ such that $N_A$ and $N_B$ are disjoint.\n\t\t\\item $A$ and $B$ are said to be \\textit{separated by closed neighbourhoods} iff there are closed neighbourhoods $\\overline N_A$ of $A$ and $\\overline N_B$ of $B$ such that $\\overline N_A$ and $\\overline N_B$ are disjoint.\n\t\t\\item $A$ and $B$ are said to be \\textit{separated by a continuous function} iff there is a continuous function $f: X \\to \\mathbb R$, such that $f[A] = \\{0\\}$ and $f[B] = \\{1\\}$.\n\t\t\\item $A$ and $B$ are said to be \\textit{precisely separated by a continuous function} iff there is a continuous function $f: X \\to \\mathbb R$, such that $f^{-1}[\\{0\\}] = A$ and $f^{-1}[\\{1\\}] = B$\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_{2 \\nicefrac{1}{2}}$ spaces]\n\t\\label{def: T_2.5 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_{2 \\nicefrac{1}{2}}$ or \\textit{Urysohn} iff two distinct points in $X$ are separated by closed neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\t[$T_2$ but not $T_{2 \\nicefrac{1}{2}}$]\n\t\\footnote{\n\t\tSee \\href{https://planetmath.org/hausdorffspacenotcompletelyhausdorff}{MathPlanet}.\n\t}\n\t(Remained as a problem)\n\t% todo: Remained as a problem!\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_3$ spaces]\n\t\\label{def: T_3 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_3$ or \\textit{regular} iff it is $T_0$ and given any point $x \\in (X, \\mathcal T)$ and closed set $V \\subseteq X$ with $x \\notin V$ are separated by neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_{3\\nicefrac{1}{2}}$ spaces]\n\t\\label{def: T_3.5 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_{3 \\nicefrac{1}{2}}$, or \\textit{Tychonoff} or, \\textit{completely $T_3$}, or \\textit{completely regular}, iff it is $T_0$ and given any point $x$ and closed set $V \\subseteq X$ with $x \\notin V$, they are separated by a continuous function.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_4$ spaces]\n\t\\label{def: T_4 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_4$ or \\textit{normal} iff it is Hausdorff and any tow disjoint closed subsets of $X$ are separated by neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\t[Urysohn's lemma]\n\t\\label{prop: urysohn's lemma}\n\tA topological space is normal iff any two disjoint closed sets are separated by a continuous function.\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_5$ spaces]\n\t\\label{def: T_5 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_5$ or \\textit{completely $T_4$} iff it is $T_1$ any two separated sets are separated by neighbourhoods.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{proposition}\n\tEvery subspace of a $T_5$ space is normal.\n\\end{proposition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[$T_6$ spaces]\n\t\\label{def: T_6 spaces}\n\tA topological space $(X, \\mathcal T)$ is said to be $T_6$, or \\textit{perfectly $T_4$} or \\textit{perfectly normal} iff it is $T_1$ and any two disjoint closed sets are precisely separated by a continuous function.\n\\end{definition}\n%--------------------------------\n\n\n\n%--------------------------------\n\\begin{proposition}\n\t[Tietze extension theorem]\n\t\\label{prop: Tietze extension theorem}\n\tLet $(X, \\mathcal T)$ be normal topological space, and let $f: A \\to (\\mathbb R, \\mathcal T')$ be a continuous map where $A$ is a closed subset of $X$ and $\\mathcal T'$ is the standard topology (induced by Euclidean metric). Then there exists a continuous map\n\t$$\n\tF: (X, \\mathcal T) \\to (\\mathbb R, \\mathcal T'),\n\t$$\n\tsuch that\n\t$$\n\t\\forall x \\in A: f(x) = g(x).\n\t$$\n\\end{proposition}\n%--------------------------------", "meta": {"hexsha": "751374c65ecac2507ee2563c22333c414287e163", "size": 4642, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-2.tex", "max_stars_repo_name": "Wenchuan5000/TeX", "max_stars_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-2.tex", "max_issues_repo_name": "Wenchuan5000/TeX", "max_issues_repo_head_hexsha": "28aab5d08fdcdfe6e0273f7130ff6388e84d1ac6", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/notes-for-general-topology-v0/separation-axioms-2.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": 39.3389830508, "max_line_length": 297, "alphanum_fraction": 0.5741059888, "num_tokens": 1364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278571786139, "lm_q2_score": 0.8705972583359805, "lm_q1q2_score": 0.7682392731389954}}
{"text": "\\section{$\\mathbf{A} = \\mathbf{U\\Sigma V}^{\\dagger}$ Singular Value Decomposition}\n\\label{sec:svd}\n\nThe Singular Value Decomposition (SVD) exists for \\underline{any} matrix $\\mathbf{A}\\in\\mathbb{C}^{m\\times n}$, and is a closely related alternative to the eigendecomposition (cf. section \\ref{sec:diagonalization}) that works for non-square matrices. The contrast to diagonalization is that the eigenvectors and eigenvalues of $\\mathbf{A}^{\\dagger}\\mathbf{A}$ and $\\mathbf{A}\\mathbf{A}^{\\dagger}$ found, rather than to look for the eigensystem of $\\mathbf{A}$ itself. The advantage is that $\\mathbf{A}^{\\dagger}\\mathbf{A}$ and $\\mathbf{A}\\mathbf{A}^{\\dagger}$ always have the convenient properties of being square, hermitian and positive semidefinite. \n\nSVD comes up incessantly in the context of data analysis. In general, the decomposition has the form:\n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{U\\Sigma V^{\\dagger}}\n\\end{equation}\n\nWhere $\\mathbf{U}$ and $\\mathbf{V}$ are unitary, and $\\Sigma$ is a diagonal matrix with real and positive entries $\\sigma_i^2$ along the diagonal, so that $\\sigma_1 \\geq \\sigma^2_2 \\geq ...\\geq \\sigma^2_n$. $\\mathbf{U}$ is the matrix of left singular vectors, which are the eigenvectors of $\\mathbf{A A^{\\dagger}}$. $\\mathbf{V}$ is the matrix of right singular vectors, which are the eigenvectors of $\\mathbf{A^{\\dagger} A}$. The singular values are the square roots of the eigenvalues of $\\mathbf{A^{\\dagger}A}$ or, equivalently, $\\mathbf{AA^{\\dagger}}$. If the $\\mathbf{A}$ happens to be square and symmetric ($\\mathbf{A}=\\mathbf{A^T}$, cf. section \\ref{sec:hermitian}), then the singular values are simply the absolute values of the eigenvalues of $\\mathbf{A}$. The right and left singular vectors of the matrix are orthonormal bases that respectively span the column and row space of $\\mathbf{A}$. The number of singular values of $\\mathbf{A}$ is the rank of $\\mathbf{A}$.\n\\\\\nThe singular values are always real and positive or zero, because $\\mathbf{A^{\\dagger} A}$ and $\\mathbf{A A^{\\dagger}}$ are  hermitian and positive semidefinite (cf. sections \\ref{sec:hermitian}, \\ref{sec:definite}). When the matrix $\\mathbf{A}$ has purely real entries, then the left and right singular vectors are also real, which is not necessarily the case for complex $\\mathbf{A}$.\n\\\\\n\nThe SVD of a matrix is unique up to the sign columns in $\\mathbf{U}$ and $\\mathbf{V}$. That is, the SVD is valid under transforming $\\mathbf{u}_i, \\mathbf{v}_i \\rightarrow -\\mathbf{u}_i, -\\mathbf{v}_i $ if $\\mathbf{u}_i$ and $ \\mathbf{v}_i$ are the $i$th vectors in $\\mathbf{U}$ and $\\mathbf{V}$. This has the consequence that the basis of singular vectors that is found using SVD does not remain consistently oriented in the presence or noise or the slow evolution of a system. This is addressed in greater length in section \\ref{sec:datasvd} on performing SVD specifically on data matrices.\n\n\\subsection{Full and Economy SVDs}\nWhile these properties are always true, unfortunately people use a range of conventions when it comes to the size of $\\mathbf{U}$, $\\mathbf{\\Sigma}$ and $\\mathbf{V}$. \\\\\n\nThe first convention is for $\\mathbf{U}$ and $\\mathbf{V}$ to be square, in which case they contain the full set of left and right singular vectors, and $\\Sigma$ has dimension $m\\times n$, with $0$ entries in rows $i>n$. This is known as the \\textit{full SVD}.\\\\\n\n\\citeasnoun{friedman2001elements} uses the the convention where $\\Sigma$ is square, i.e. $\\mathbf{U}:\\ m\\times n$, $\\mathbf{\\Sigma}:\\ n\\times n$ and $\\mathbf{V}:\\ n\\times n$. This means that $U$ does not contain the full set of $m$ left singular vectors. Note that, in this case, $\\mathbf{U^{\\dagger}}\\mathbf{U} = \\mathbf{I}$ but $\\mathbf{U}\\mathbf{U^{\\dagger}} \\neq \\mathbf{I}$. \\possessivecite{friedman2001elements} convention is of advantage in the context of data analysis, where the data matrix tends to be \"tall and skinny\" (i.e. $m>>n$), and only the first $n$ left singular vectors are relevant. Also, a letting $\\Sigma$ be a square matrix significantly simplifies calculations. \\possessivecite{friedman2001elements} is known as the \\textit{economy} or \\textit{compact} SVD.\\\\\n\nThe two different layouts are illustrated in Figure \\ref{fig:full_vs_economy_svd}, which I brazenly copied from \\citeasnoun{mathworkseigs}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[scale=0.5]{full_vs_economy_svd.png}\n\\caption{Dimensions for Full vs. Economy SVDs}\n\\label{fig:full_vs_economy_svd}\n\\end{figure}\n\n\\subsection{Matrix Approximation}\nThe SVD enables the decomposition of the matrix into a sum:\n\n\\begin{equation}\n\\mathbf{A} = \\sum_{i=1}^n \\sigma_i (\\mathbf{u}_i \\otimes \\mathbf{v}_i)\n\\end{equation}\n\nWhich may be truncated at some rank $r$, resulting in a rank-$r$ approximation to $\\mathbf{A}$. This is known as the \\textit{truncated singular value estimator} (TSVD):\n\n\\begin{equation}\n\\mathbf{\\hat{A}} = \\sum_{i=1}^r \\sigma_i (\\mathbf{u}_i \\otimes \\mathbf{v}_i)\n\\end{equation}\n\nWhere $\\mathbf{u}_i$ is the $i$th left singular vector and $\\mathbf{v}_i$ is the $i$th right singular vector. Following the Eckart-Young-Mirsky Theorem, taking the first $r \\leq n$ terms of this series is the best rank-$r$ approximation to $\\mathbf{A}$ under the Frobenius norm of the error, i.e.  $\\underset{\\mathrm{rank}(\\mathbf{A}^{(r)})=r\\leq n}{\\argmin} ||\\mathbf{A^r}-\\mathbf{A}||_F$. The Frobenius norm essentially measures the elementwise mean squares error (MSE), cf. section \\ref{sec:frobenius}).\\\\\n\nIn the context of data analysis, the reduced rank representation of a data matrix $\\mathbf{A}$ acts as a filter in which the components that explain less of the variance in the dataset are removed, with the hope being that these correspond to noise. The intuition is that noise probably originates from a random process, so that components that correspond to noise have weak correlation with the entries of the dataset and therefore small singular values. On the other hand, the signal probably systematic, so that the components that correspond to the signal have larger singular value. Since TSVD minimizes the average mean squares error (AMSE) amounts to the rank-$r$ maximum likelihood estimator of the signal under the assumption of normally distributed noise with mean zero. \n\nBy virtue of being expressible in terms of fewer base vectors, a lower rank approximation is also a very effective compression method. For a more elaborate discussion of SVD in data analysis, see section \\ref{sec:datasvd}. In a practical context, the question of selecting the appropriate rank of the approximation emerges. Section \\ref{sec:truncation} covers a few approaches to this.\n\n\n% Geometric interpretation\n\\subsection{Geometric Interpretation of SVD}\nA common intuitive interpretation of $\\mathbf{U}$, $\\mathbf{\\Sigma}$ and $\\mathbf{V}$ is to see them as a decomposition of the action of the matrix $\\mathbf{A}\\in\\mathbb{R}^{m\\times n}$ into a rotation, a stretching and another rotation. Let $\\{\\mathbf{x} : |\\mathbf{x}|=1 \\}$ be the points on the surface of a unit sphere, then $\\mathbf{Ax}$:\n\n\\begin{itemize}\n\\item $\\mathbf{V}$ rotates the unit sphere, which has no effect. However, it expresses each $\\mathbf{x}$ in terms of a different coordinate system (the right singular basis of $\\mathbf{A}$). \n\\item $\\mathbf{\\Sigma}$ stretches the unit sphere into an ellipse with principal axes aligned to that coordinate system.\n\\item $\\mathbf{U}$ rotates the ellipse.\n\\end{itemize}\n\nIn the above, \"rotation\" might include coordinate flips that are undone by $\\mathbf{U}$ following $\\mathbf{V}$. Alternatively, for a vector $\\mathbf{v}\\in\\mathbf{R}^{n}$, the operation $\\mathbf{Av}$:\n\n\\begin{itemize}\n\\item $\\mathbf{V}$ is a change of basis matrix that expresses $\\mathbf{x}$ in terms of a right eigenbasis of $\\mathbf{A}$\n\\item $\\mathbf{\\Sigma}$ performs a stretching in that basis\n\\item $\\mathbf{U}$ is a change of basis from the right eigenspace into the left eigenspace of $\\mathbf{A}$. \n\\end{itemize}\n\n", "meta": {"hexsha": "a4a1351fcac70f8754c7b35b4e0ab1a486afa967", "size": 7949, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_svd.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/linalg_svd.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/linalg_svd.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": 108.8904109589, "max_line_length": 976, "alphanum_fraction": 0.7456283809, "num_tokens": 2269, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392939666335, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7680770113462198}}
{"text": "\\section*{Exercises}\n\n\\begin{ex} In the following, polar coordinates $(r,\\theta) $ for a\npoint in the plane are given. Find the corresponding Cartesian coordinates.\n\n\\begin{enumerate}\n\\item $(2,\\pi /4) $\n\n\\item $(-2,\\pi /4) $\n\n\\item $(3,\\pi /3) $\n\n\\item $(-3,\\pi /3) $\n\n\\item $(2,5\\pi /6) $\n\n\\item $(-2,11\\pi /6) $\n\n\\item $(2,\\pi /2) $\n\n\\item $(1,3\\pi /2) $\n\n\\item $(-3,3\\pi /4) $\n\n\\item $(3,5\\pi /4) $\n\n\\item $(-2,\\pi /6) $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Consider the following Cartesian coordinates $(x,y)$. Find polar coordinates corresponding to these points.\n\n\\begin{enumerate}\n\\item $(-1,1) $\n\n\\item $(\\sqrt{3},-1) $\n\n\\item $(0,2) $\n\n\\item $(-5,0) $\n\n\\item $(-2\\sqrt{3},2) $\n\n\\item $(2,-2) $\n\n\\item $(-1,\\sqrt{3}) $\n\n\\item $(-1,-\\sqrt{3}) $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} The following relations are written in terms of Cartesian coordinates $(x, y)$. Rewrite them in terms of polar coordinates, $(r, \\theta)$.\n\n\\begin{enumerate}\n\\item $y=x^{2}$\n\n\\item $y=2x+6$\n\n\\item $x^{2}+y^{2}=4$\n\n\\item $x^{2}-y^{2}=1$\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Use a calculator or computer algebra system to graph the following\npolar relations.\n\n\\begin{enumerate}\n\\item $r=1-\\sin (2\\theta) ,\\theta \\in \\mat{0,2\\pi} $\n\n\\item $r=\\sin (4\\theta) ,\\theta \\in \\mat{0,2\\pi} $\n\n\\item $r=\\cos (3\\theta) +\\sin (2\\theta) ,\\theta\n\\in \\mat{0,2\\pi} $\n\n\\item $r=\\theta ,\\ \\theta \\in \\mat{0,15} $\n\\end{enumerate}\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=1+\\sin \\theta $ for $\\theta \\in \\mat{0,2\\pi}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=2+\\sin \\theta $ for $\\theta \\in \\mat{0,2\\pi}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=1+2\\sin \\theta $ for $\\theta \\in \\mat{0,2\\pi}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=2+\\sin (2\\theta) $ for $\\theta \\in \\mat{0,2\\pi\n}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=1+\\sin (2\\theta) $ for $\\theta \\in \\mat{0,2\\pi\n}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Graph the polar equation $r=1+\\sin (3\\theta) $ for $\\theta \\in \\mat{0,2\\pi\n}$.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} Describe how to solve for $r$ and $\\theta $ in terms of $x$ and $y$ in polar\ncoordinates.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n\\begin{ex} This problem deals with parabolas, ellipses, and\nhyperbolas and their equations. Let $l,e>0$ and consider\n\\begin{equation*}\nr=\\frac{l}{1\\pm e\\cos \\theta }\n\\end{equation*}\nShow that if $e=0$, the graph of this equation gives a circle. Show that if $0<e<1$, the graph is an ellipse, if $e=1$\nit is a parabola and if $e>1$, it is a hyperbola.\n%\\begin{sol}\n%\\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "86b5aba3ff08d807cfacc4579d2085b5940eb2fd", "size": 2758, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/exercises/Curvilinear-Polar.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "old/exercises/Curvilinear-Polar.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "old/exercises/Curvilinear-Polar.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 19.9855072464, "max_line_length": 149, "alphanum_fraction": 0.6171138506, "num_tokens": 1069, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.7680770069079811}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the basic solutions of each of the following homogeneous\n  systems of equations.\n  \\begin{equation*}\n    (a)~\n    \\begin{array}{r@{~}c@{~}l}\n      2x + 3y + 4z &=& 0 \\\\\n      x - 2y + z &=& 0 \\\\\n      4x - y + 6z &=& 0\n    \\end{array}\n    \\quad\n    (b)~\n    \\begin{array}{r@{~}c@{~}l}\n       x -  y +  z &=& 0 \\\\\n      -x - 2y - 4z &=& 0 \\\\\n      2x +  y + 5z &=& 0\n    \\end{array}\n    \\quad\n    (c)~\n    \\begin{array}{r@{~}c@{~}l}\n      x +  y -  z + 2w &=& 0 \\\\\n      x + 3y +  z + 6w &=& 0 \\\\\n      x + 2y      + 4w &=& 0\n    \\end{array}\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Which of the following homogeneous systems of linear equations have\n  non-trivial solutions?\n  \\begin{enumerate}\n  \\item[(a)] 4 equations in 3 variables, rank 3.\n  \\item[(b)] 3 equations in 4 variables, rank 3.\n  \\item[(c)] 4 equations in 3 variables, rank 2.\n  \\item[(d)] 3 equations in 4 variables, rank 2.\n  \\end{enumerate}\n\n  \\begin{sol}\n    The systems (b), (c), and (d) have non-trivial solutions, because\n    the rank is less than the number of variables.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  My system of equations has a solution $(x,y,z) = (1,2,4)$. The\n  associated homogeneous system has basic solutions $(x,y,z) =\n  (1,0,1)$ and $(x,y,z)=(0,1,-1)$. What is the general solution of my\n  system of equations?\n\n  \\begin{sol}\n    The general solution is $(x,y,z) = (1,2,4)+s(1,0,1)+t(0,1,-1)$, or\n    equivalently, $(x,y,z) = (1+s, 2+t, 4+s-t)$, where $s$ and $t$ are\n    parameters.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "7eaae0025c0d3cffcd92e86547bddc9b6121a202", "size": 1534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/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/exercises/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/exercises/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": 26.0, "max_line_length": 70, "alphanum_fraction": 0.5475880052, "num_tokens": 609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417088, "lm_q2_score": 0.8840392863287584, "lm_q1q2_score": 0.7680770002063025}}
{"text": "% based on example 8 in pythontex_gallery\n% https://github.com/gpoore/pythontex/\n\n\\documentclass[12pt]{mpllatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Step-by-step integration}\n\nThis is another nice example drawn from the Pythontex gallery, see\n\\ \\url{https://github.com/gpoore/pythontex}.\n\nIt shows the step-by-step computations of a simple triple integral.\n\n\\vspace{12pt}\n\n\\begin{maple}\n   # Define limits of integration\n   x_max := 2:   y_max := 3:   z_max := 4:\n   x_min := 0:   y_min := 0:   z_min := 0:\n\n   ans := int(f(x,y,z), [x=x_min..x_max, y=y_min..y_max, z=z_min..z_max]):            # mpl(lhs.01,ans)\n\n   f := (x,y,z) -> x*y + y*sin(z) + cos(x+y):\n\n   ans := ''int''(''int''(''int''(f(x,y,z), x=x_min..x_max), y=y_min..y_max), z=z_min..z_max):    # mpl(rhs.01,ans)\n   ans := ''int''(''int''(int(f(x,y,z), x=x_min..x_max), y=y_min..y_max), z=z_min..z_max):        # mpl(rhs.02,ans)\n   ans := ''int''(int(int(f(x,y,z), x=x_min..x_max), y=y_min..y_max), z=z_min..z_max):            # mpl(rhs.03,ans)\n   ans := int(int(int(f(x,y,z), x=x_min..x_max), y=y_min..y_max), z=z_min..z_max):                # mpl(rhs.04,ans)\n\n   # And now, a numerical approximation\n   ans := evalf[15](ans):                                                             # mpl(rhs.05,ans)\n\n\\end{maple}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\begin{align*}\n   \\mpl{lhs.01} &= \\mpl{rhs.01}\\\\\n                &= \\mpl{rhs.02}\\\\\n                &= \\mpl{rhs.03}\\\\\n                &= \\mpl{rhs.04}\\\\\n                &\\approx \\mpl{rhs.05}\n\\end{align*}\n\\end{minipage}\n\\hskip 1cm\n\\lower16pt\\hbox{%\n\\begin{minipage}[t]{0.35\\textwidth}\n\\begin{latex}\n   \\begin{align*}\n      \\mpl{lhs.01} &= \\mpl{rhs.01}\\\\\n                   &= \\mpl{rhs.02}\\\\\n                   &= \\mpl{rhs.03}\\\\\n                   &= \\mpl{rhs.04}\\\\\n                   &\\approx \\mpl{rhs.05}\n   \\end{align*}\n\\end{latex}\n\\end{minipage}}\n\n\\end{document}\n", "meta": {"hexsha": "0d97468488e6e1c159cd72db36ebb77231a8edde", "size": 1897, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maple/examples/example-03.tex", "max_stars_repo_name": "leo-brewin/hybrid-latex", "max_stars_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 16, "max_stars_repo_stars_event_min_datetime": "2018-10-12T06:31:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:16:08.000Z", "max_issues_repo_path": "maple/examples/example-03.tex", "max_issues_repo_name": "leo-brewin/hybrid-latex", "max_issues_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "maple/examples/example-03.tex", "max_forks_repo_name": "leo-brewin/hybrid-latex", "max_forks_repo_head_hexsha": "2debaf3f97eb551928d08dc4baded7ef7a4ab29a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-06-27T03:29:40.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-30T17:17:18.000Z", "avg_line_length": 31.0983606557, "max_line_length": 115, "alphanum_fraction": 0.5318924618, "num_tokens": 659, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267728417087, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.76807699489751}}
{"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\n\\begin{enumerate}[label=(\\alph*)]\n\\item Use the substitution method to show that $T(n) = 8T(n/2) + n^3 = \\mathcal{O}(n^3\\log n)$.\nAssume $T(2)=d$ where $d$ is a constant.\nUse induction and do not skip stages.\n\n\\item Prove or disprove $f(n) = \\Theta(f(n/2))$.\nIf true, show why.\nOtherwise give a counter-example.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Proof is given by induction on $n$.\nUsing assumption $T(2) = d$, $T(1) = \\frac{T(2)-1}{8} = \\frac{d-1}{8} = e$ where $e$ is a constant.\n\\begin{enumerate}[label=\\arabic*.]\n\\item \\textit{Base Case}\\\\\nWe take the base step as $n = 1$.\nIn this case, there exist constants $f > 0$, $n_0 = 1$ where $f = e(\\frac{d}{8}+\\frac{d}{1})$ such that $T(1) \\leq f \\times n^3 \\log n$ for all $n \\geq n_0$.\nTherefore, $T(1) = \\mathcal{O}(n^3 \\log n)$.\n\\item \\textit{Inductive Hypothesis}\\\\\nWe form inductive hypothesis as $T(k)=\\mathcal{O}(n^3 \\log n)$.\nIn other words, that there are constants $c$ and $n'_0$ such that $T(k) \\leq ck^3 \\log k$ for $k \\geq n'_0$.\n\\item \\textit{Induction Step}\\\\\nUsing inductive hypothesis we will show $T(2k) = O(n^3\\log n)$; in other words, that there are constants $c^\\prime$ and $n''_0$ such that $T(2k) \\leq c' k^3 \\log k$ for all $k \\geq n''_0$.\n\n\\begin{equation}\\label{eq11}\nT(2k) = 8 T(\\frac{2k}{2}) + (2k)^3\n\\end{equation}\nBy Inductive hypothesis, Equation \\ref{eq11} can be written as shown in Equation \\ref{eq12}.\n\\begin{equation}\\label{eq12}\n\\begin{aligned}\nT(2k) &\\leq 8c \\big( (2k)^3 \\log (2k) \\big) + (2k)^3\\\\\n&\\leq (8c + 1) (2k)^3 \\log (2k)\\\\\n&\\leq 8(8c+1) (k)^3 (\\log (k) + \\log 2)\\\\\n&\\leq 16(8c+1) (k^3 \\log k)\n\\end{aligned}\n\\end{equation}\nTherefore, by taking $c' = 16(8c+1)$ and $n''_0 = n'_0$ we have shown Equation \\ref{eq13} holds for all $k \\geq n''_0$.\n\\begin{equation}\\label{eq13}\nT(2k) \\leq c' \\big( (2k)^3 \\log 2k \\big)\n\\end{equation}\nHence, we have shown $T(2k) = \\mathcal{O}(n^3\\log n)$ and the induction is complete.\n\\end{enumerate}\n\\item The statement is not valid.\nTo disprove, $f(n)=2^n$ can be given as a counter-example.\nWhat statement suggests is there are constants $C$ and $n_0$ such that $2^n < C(2^{n/2})$; in other words, $2^{n/2} < C$ for all $n > n_0$.\nThis is obviously not true since there is no limit in our choice of $n$.\n\\end{enumerate}\n", "meta": {"hexsha": "7530f646f06157dc0c1b8db054c12a84397b3690", "size": 2672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m01/m01q01.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/m01/m01q01.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/m01/m01q01.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 45.2881355932, "max_line_length": 188, "alphanum_fraction": 0.624251497, "num_tokens": 1007, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.8688267745399465, "lm_q1q2_score": 0.7680769924172244}}
{"text": "\\section{Eigenvalues and Eigenvectors}\r\nFor a linear map $T:V\\to V$ where $V$ is a real or complex vector space, a vector $\\underline{v}\\neq\\underline{0}$ is called an eigenvector of $T$ with eigenvalue $\\lambda$ if $T\\underline{v}=\\lambda\\underline{v}$.\r\nNote that this happens if and only if\r\n$$A\\underline{v}=\\lambda\\underline{v}\\iff (A-\\lambda I)\\underline{v}=\\underline{0}$$\r\nwhere $A$ is the matrix of $T$.\r\nSo $\\lambda$ is an eigenvalue if and only if $\\det(A-\\lambda I)=0$ if and only if it is a root of the polynomial\r\n$$\\chi_A(t)=\\det(A-tI)$$\r\nwhich is a degree $n$ polynomial.\r\n\\begin{definition}\r\n    For $A$ an $n\\times n$ matrix, the characteristic polynomial $\\chi_A(t)$ is defined as $\\det(A-tI)$.\r\n\\end{definition}\r\nThis gives us a way to find the eigenvalues by looking at the characteristic polynomial and to find the eigenvectors by looking at the kernel of $A-\\lambda I$.\r\n\\begin{example}\r\n    1. Let $V=\\mathbb C^3$ and\r\n    $$A=\\begin{pmatrix}\r\n        2&i\\\\\r\n        -i&2\r\n    \\end{pmatrix}$$\r\n    So $\\chi_A(t)=(2-t)^2-1$, so $\\lambda$ is $1$ or $3$.\r\n    For the eigenvalue $\\lambda=1$, we find that the eigenvectors are spanned by $(1,i)$, and for $\\lambda=3$, the eigenvectors are spanned by $(1,-i)$.\r\n    \\\\\r\n    2. Let $V=\\mathbb R^2$, consider the shear\r\n    $$A=\r\n    \\begin{pmatrix}\r\n        1&1\\\\\r\n        0&1\r\n    \\end{pmatrix}$$\r\n    So $\\chi_A(t)=(1-t)^2$, so $\\lambda=1$.\r\n    The eigenvectors are then spanned by $(1,0)$\r\n    \\\\\r\n    3. Let $V=\\mathbb C^2$, and\r\n    $$U=\\begin{pmatrix}\r\n        \\cos\\theta&-\\sin\\theta\\\\\r\n        \\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}$$\r\n    So $\\chi_U(t)=t^2-2t\\cos\\theta+1$, so $\\lambda=e^{\\pm i\\theta}$, so the eigenvectors are spanned by $(1,\\pm i)$ respectively.\\\\\r\n    4. Consider $V=\\mathbb C^n$ and $A=\\operatorname{diag}(\\lambda_1,\\lambda_2,\\ldots,\\lambda_n)$, then the eigenvalues are $\\lambda_i$ and the corresponding eigenvectors are spanned by $\\underline{e_i}$.\r\n\\end{example}\r\n\\begin{proposition}\r\n    1. There exists at least one eigenvalue.\r\n    In fact, there exists $n$ eigenvalues counting multiplicity.\\\\\r\n    2. The trace of the matrix equals the sum of the eigenvalues (counting multiplicity as well).\\\\\r\n    3. $\\det A=\\chi_A(0)$.\\\\\r\n    4. If $A$ is real, then non-real eigenvalues occur in conjugates.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{definition}\r\n    For an eigenvalue $\\lambda$ of a matrix $A$, define the eigenspace $E_\\lambda$ is the set of all $\\underline{v}$ with $A\\underline{v}=\\lambda\\underline{v}$, so $E_\\lambda=\\ker(A-\\lambda I)$.\r\n    The geometrical multiplicity of $\\lambda$ is $m_\\lambda=\\operatorname{null}E_\\lambda$, and the algebraic multiplicity $M_\\lambda$ is the multiplicity of $\\lambda$ as a root of $\\chi_A(t)$.\r\n    So $\\chi_A(t)=(t-\\lambda)f(t)$ for $f(\\lambda)\\neq 0$.\r\n\\end{definition}\r\n\\begin{proposition}\\label{alg_ge_geom}\r\n    $M_\\lambda\\ge m_\\lambda$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Postponed to later.\r\n\\end{proof}\r\nNote that the strict inequality can happen in many non-trivial cases.\r\n\\begin{example}\r\n    1. Take\r\n    $$\\begin{pmatrix}\r\n        -2&2&-3\\\\\r\n        2&1&-6\\\\\r\n        -1&-2&0\r\n    \\end{pmatrix}$$\r\n    Then $\\chi_A(t)=(5-t)(t+3)^2$, so $5,-3$ are the eigenvalues.\r\n    By calculation we find that $E_5=\\operatorname{span}\\{(1,2,-1)^\\top\\}$ and $E_{-3}=\\operatorname{span}\\{(-2,1,0)^\\top,(3,0,1)^\\top\\}$, so $M_5=m_5=1,M_{-3}=m_{-3}=2$.\\\\\r\n    2. Take\r\n    $$A=\\begin{pmatrix}\r\n        -3&-1&1\\\\\r\n        -1&-3&1\\\\\r\n        -2&-2&0\r\n    \\end{pmatrix}$$\r\n    Then $\\chi_A(t)=-(t+2)^3$, so the only eigenvalue is $-2$, but $E_{-2}$ only has dimension $2$, therefore $M_{-2}=3\\neq 2=m_{-2}$.\\\\\r\n    3. Consider the reflection across some plane through the origin.\r\n    It reflects every point on the normal without changing direction and fixes every point on the plane.\r\n    So the only eigenvalues would be $\\pm 1$ and $M_{-1}=m_{-1}=1,M_1=m_1=2$.\\\\\r\n    4. Consider the generic rotation through some normal.\r\n    So the only real eigenvalue would be $1$ and $M_1=m_1=1$ since the transformation changes every vector's direction except those on the normal, which it fixes.\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $\\underline{v_1},\\underline{v_2},\\ldots,\\underline{v_r}$ be eigenvectors of a matrix $A$ with eigenvalues $\\lambda_1,\\lambda_2,\\ldots,\\lambda_r$.\r\n    If the eigenvalues are distinct, then the eigenvectors are linearly independent.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $\\underline{w}=\\sum_ia_i\\underline{v_i}$, then $(A-\\lambda I)\\underline{w}=\\sum_ia_i(\\lambda_j-\\lambda)\\underline{v}$.\r\n    Let $\\underline{w}=\\underline{0}$, and if we can find a linear combination where not all $a_i$'s is $0$, then we pick such a linear combination $\\underline{0}=\\sum_ia_i\\underline{v_i}$ such that the number of nonzero $a_i$'s is the least.\r\n    WLOG in this choice $a_1\\neq 0$, then $\\underline{0}=(A+\\lambda I)\\underline{0}=\\sum_ia_i(\\lambda_j-\\lambda_1)\\underline{v}$, which contradicts the minimality of the number of nonzero $a_i$ of our choice.\r\n\\end{proof}\r\n\\begin{proof}[Alternative proof]\r\n    Given a linear relation $\\underline{0}=\\sum_ia_i\\underline{v_i}$, then for any $j$, the consider\r\n    $$\\underline{0}=\\prod_{i\\neq j}(A-\\lambda_iI)\\sum_{i=1}^ra_i\\underline{v_i}=a_j\\underline{v_j}\\prod_{i\\neq j}(\\lambda_j-\\lambda_i)$$\r\n    So $a_j=0$.\r\n\\end{proof}\r\n\\subsection{Diagonalizability}\r\n\\begin{proposition}\r\n    For an $n\\times n$ matrix $A$ acting on $V=\\mathbb R^n$ or $\\mathbb C^n$, the followings are equivalent:\\\\\r\n    1. There exists a basis for $V$ consisting of eigenvectors of $A$.\\\\\r\n    2. There exists an $n\\times n$ invertible matrix $P$ such that $P^{-1}AP=D$ where is a diagonal matrix whose entries are the eigenvalues.\r\n\\end{proposition}\r\nIf either of these conditions hold, then we say $A$ is diagonalizable.\r\n\\begin{proof}\r\n    For any matrix $P$, $AP$ has columns $A\\underline{C_i}^{(P)}$, and $DP$ has columns\r\n    $$\\lambda_i\\underline{C_i}^{(P)}$$\r\n    so what it is saying is that every column of $P$ is an eigenvector of $A$.\r\n    So if there is a basis of eigenvectors, we can just take $P$ to be the matrix whose columns are the basis eigenvectors.\r\n    Conversely, given such a matrix $P$, its columns are a basis for $V$.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Consider\r\n    $$A=\r\n    \\begin{pmatrix}\r\n        1&1\\\\\r\n        0&1\r\n    \\end{pmatrix}$$\r\n    So we only have one eigenvector, hence $A$ is not diagonalizable.\\\\\r\n    2. Consider\r\n    $$U=\r\n    \\begin{pmatrix}\r\n        \\cos\\theta&-\\sin\\theta\\\\\r\n        \\sin\\theta&\\cos\\theta\r\n    \\end{pmatrix}$$\r\n    So it does not have real eigenvalues, but it has $2$ complex eigenvalues with linearly independent eigenvectors, thus it is diagonalizable over $\\mathbb C^n$.\r\n    Indeed, we can let\r\n    $$P=\r\n    \\begin{pmatrix}\r\n        1&1\\\\\r\n        -i&i\r\n    \\end{pmatrix}$$\r\n    Then\r\n    $$P^{-1}UP=\\begin{pmatrix}\r\n        e^{i\\theta}&0\\\\\r\n        0&e^{-i\\theta}\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{proposition}\r\n    If $A$ has $n$ distinct eigenvalues, then it is disgonalizable.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Different eigenvalues give linearly independent eigenvectors.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    $A$ is diagonalizable if and only if $M_\\lambda=m_\\lambda$ for each eigenvalue $\\lambda$ of $A$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The union of the basis vectors for the eigenspaces would be a basis for the entire space since we would have $\\sum_{\\lambda}M_\\lambda=\\sum_{\\lambda}m_\\lambda=n$.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. Again use\r\n    $$A=\\begin{pmatrix}\r\n        -2&2&-3\\\\\r\n        2&1&-6\\\\\r\n        -1&-2&0\r\n    \\end{pmatrix}$$\r\n    We already know from previous example that $\\lambda=5,3$ and $M_5=m_5=1,M_{-3}=m_{-3}=2$, so $A$ is diagonalizable.\r\n    Indeed, we have\r\n    $$P^{-1}AP=\\begin{pmatrix}\r\n        5&&\\\\\r\n        &-3&\\\\\r\n        &&-3\r\n    \\end{pmatrix},P=\\begin{pmatrix}\r\n        1&-2&3\\\\\r\n        2&1&0\\\\\r\n        -1&0&1\r\n    \\end{pmatrix}$$\r\n    2. Use the previous example\r\n    $$A=\\begin{pmatrix}\r\n        -3&-1&1\\\\\r\n        -1&-3&1\\\\\r\n        -2&-2&0\r\n    \\end{pmatrix}$$\r\n    Then $\\lambda=-2$ and $M_{-2}=3>m_{-2}=2$, so $A$ is not diagonalizable.\r\n    Indeed, if it is, then there is some invertible $P$ with $A=P(-2I)P^{-1}=-2I$ which is a contradiction.\r\n\\end{example}\r\n\\begin{definition}\r\n    Two $n\\times n$ matrices $A,B$ are similar if there is some invertible $n\\times n$ matrix $P$ such that $A=PBP^{-1}$.\r\n\\end{definition}\r\nThis is trivially an equivalence relation.\r\n\\begin{proposition}\r\n    If $A,B$ are similar, then $\\operatorname{tr}B=\\operatorname{tr}A$ and $\\det B=\\det A$.\r\n    Also $\\chi_B=\\chi_A$.\r\n\\end{proposition}\r\nIn fact, if two matrices are similar, then we could get from one to the other by a change of basis.\r\nThe results here then are obvious.\r\n\\begin{proof}\r\n    $$\\operatorname{tr}(B)=\\operatorname{tr}(P^{-1}AP)=\\operatorname{tr}(APP^{-1})=\\operatorname{tr}(A)$$\r\n    $$\\det(B)=\\det(P^{-1}AP)=\\det(P)^{-1}\\det(A)\\det(P)=\\det(A)$$\r\n    $$\\chi_A(t)=\\det(A-tI)=\\det(P^{-1})\\det(A-tI)\\det(P)=\\det(B-tI)=\\chi_B(t)$$\r\n    As desired.\r\n\\end{proof}\r\nNote that if $A$ is duagonalizable, then so is $B$ since they are all in the same equivalence class containing some diagonal matrix.\r\n\\begin{proof}[Proof of Theorem \\ref{alg_ge_geom}]\r\n    Choose an eigenvalue $\\lambda$ of an $n\\times n$ matrix $A$ with $m_\\lambda=r$ and a basis $\\underline{v_1},\\ldots,\\underline{v_r}$ for $E_{\\lambda}$.\r\n    Extend this basis to the entire space by adding vectors $\\underline{w_{r+1}},\\ldots,\\underline{w_n}$.\r\n    Consider the matrix $P$ with columns $\\underline{C_i}(P)=\\underline{v_i}$ for $i=1,\\ldots,r$ and $\\underline{C_a}(P)=w_a$ for $a=r+1,\\ldots,n$, then $AP=PB$ where $B$ is of the form\r\n    $$B=\\left(\\begin{array}{@{}c|c@{}}\r\n        \\lambda I&*\\\\\r\n        \\hline\r\n        0&\\hat{B}\r\n    \\end{array}\\right)$$\r\n    Note that $P^{-1}AP=B$, so $\\chi_A(t)=\\chi_B(t)=(\\lambda-t)^r\\det(\\hat{B}-tI)$, so $M_\\lambda\\ge m_\\lambda$.\r\n\\end{proof}\r\n\\subsection{Diagonalisation of Hermitian and Symmetric Matrices}\r\nObserve that if $A$ is Hermitian, then $(A\\underline{v})^\\dagger\\underline{w}=\\underline{v}^\\dagger A\\underline{w}$ for any complex vectors $\\underline{v},\\underline{w}$.\r\n\\begin{proposition}\r\n    Hermitian matrices have real eigenvalues and orthogonal eigenvectors for distinct eigenvalues.\r\n    In addition, if the matrix is actually real (hence symmetric), then for each eigenvalue stated above, we can choose real eigenvectors.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Let $A$ be a Hemitian matrix and $\\lambda$ an eigenvalue of it with eigenvector $\\underline{v}$, then\r\n    $$\\bar{\\lambda}\\underline{v}^\\dagger\\underline{v}=(A\\underline{v})^\\dagger\\underline{v}=\\underline{v}^\\dagger A\\underline{v}=\\lambda\\underline{v}^\\dagger\\underline{v}$$\r\n    So $\\lambda=\\bar\\lambda$, thus $\\lambda$ is real.\\\\\r\n    If $\\lambda,\\mu$ are distinct eigenvalues with eigenvectors $\\underline{v},\\underline{w}$, then\r\n    $$\\mu\\underline{v}^\\dagger\\underline{w}=\\underline{v}^\\dagger(A\\underline{w})=(A\\underline{v})^\\dagger\\underline{w}=\\lambda\\underline{v}^\\dagger\\underline{w}\\implies (\\lambda-\\mu)\\underline{v}^\\dagger\\underline{w}=0$$\r\n    So $\\underline{v}^\\dagger\\underline{w}=0$ since $\\mu\\neq\\lambda$, thus $\\underline{v}\\perp\\underline{w}$.\\\\\r\n    For the last part, just choose the real or imaginary part (at least one of them is nonzero) of the eigenvectors.\r\n\\end{proof}\r\n\\begin{proposition}[Gram-Schmidt Orthogonalization]\r\n    Given a linearly independent set of vectors $\\underline{w_1},\\underline{w_2},\\ldots,\\underline{w_k}$ in $\\mathbb C^n$, we can construct a set $\\underline{u_1},\\underline{u_2},\\ldots,\\underline{u_k}$ of orthonormal vectors such that $\\operatorname{span}(\\{\\underline{u_i}\\})=\\operatorname{span}(\\{w_i\\})$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    We do it recursively by\r\n    $$\\underline{u_1}=\\frac{1}{\\|\\underline{v_1}\\|}\\underline{v_1},\\forall j>1,\\underline{w_j}^{(1)}=\\underline{w_j}-(\\underline{u_1}^\\dagger \\underline{w_j})\\underline{u_1}$$\r\n    and\r\n    $$\\underline{u_r}=\\frac{1}{\\|\\underline{w_r}^{(r-1)}\\|}\\underline{w_r}^{(r-1)},\\forall j>r,\\underline{w_j}^{(r)}=\\underline{w_j}^{(r-1)}-(\\underline{u_r}^\\dagger \\underline{w_j}^{(r-1)})\\underline{u_r}$$\r\n    Which, as one can easily verify, is valid.\r\n\\end{proof}\r\nUsing Gram-Schmidt, we can convert any basis for some eigenspace to an orthonormal basis $\\mathscr B_\\lambda$.\r\nIf $\\lambda_i$ are distinct eigenvalues of some Hermitian basis, then by choosing this orthonormal basis for all eigenspaces, we have an orthonormal set of eigenvectors.\r\n\\begin{example}\r\n    1. Take\r\n    $$A=\\begin{pmatrix}\r\n        2&i\\\\\r\n        -i&2\r\n    \\end{pmatrix},A^\\dagger=A$$\r\n    So the eigenvalues are $1,3$ with eigenvectors $2^{-1/2}(1,i)^\\top,2^{-1/2}(1,-i)^\\top$.\r\n    Note that these two eigenvectors is an orthonormal basis for $\\mathbb R^2$.\r\n    So we can choose\r\n    $$P=\\frac{1}{\\sqrt{2}}\\begin{pmatrix}\r\n        1&1\\\\\r\n        i&-i\r\n    \\end{pmatrix}$$\r\n    Which is unitary and $P^{-1}AP=\\operatorname{diag}(1,3)$.\\\\\r\n    2. Consider\r\n    $$A=\\begin{pmatrix}\r\n        0&1&1\\\\\r\n        1&0&1\\\\\r\n        1&1&0\r\n    \\end{pmatrix}$$\r\n    which is real and symmetric thus Hermitian and have eigenvalues $-1,2$ where the algebraic multiplicity of $-1$ is $2$.\r\n    By calculation we find that the geometric multiplicity of $-1$ is also $2$.\r\n    We can find an orthonormal basis for $E_{-1}$ by the Gram-Schmidt process.\r\n    For example we can have \r\n    $$E_{-1}=\\operatorname{span}\\{2^{-1/2}(1,-1,0)^\\top,6^{-1/2}(1,1,-2)^\\top\\}$$\r\n    Also $E_{2}=\\operatorname{span}\\{3^{-1/2}(1,1,1)^\\top\\}$, thus we have found an orthonormal eigenbasis for $\\mathbb R^3$.\r\n    We can also find the corresponding (unitary hence orthogonal) $P$ which diagonalizes $A$.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Any $n\\times n$ Hermitian matrix is diagonalizable by an unitary matrix.\r\n    Equivalently, there is an orthonormal eigenbasis.\r\n    In particular, for real and symmetric case, we can choose such that the orthonormal basis is real.\r\n    \\label{hermitian_diag}\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We have already established all of the theorem but the part of the matrix being diagonalizable, so it suffices to show that, which is sadly not examinable, but here goes:\\\\\r\n    Consider a Hermitian $A=\\mathbb C^n\\to\\mathbb C^n$.\r\n    If $V$ is any subspace of $\\mathbb C^n$ that is invariant under $A$, then for any $\\underline{v_1},\\underline{v_2}\\in V$ we have $\\underline{v_1}^\\dagger (A\\underline{v_2})=(A\\underline{v_1})^\\dagger\\underline{v_2}$.\r\n    We shall prove by induction on $m=\\dim V\\le n$ that such a subspace has an orthonormal basis of eigenvectors of $A$, which shall establish the result by taking $m=n$.\r\n    As the initial step is trivial, we will show the induction step.\\\\\r\n    Given $V$ as above, since we are working in $\\mathbb C$, the characteristic equation always has a root, so there is some $\\underline{v}\\in V$ such that $A\\underline{v}=\\lambda\\underline{v}$ for some $\\lambda$.\r\n    Let $W$ be the subspace $\\{\\underline{w}\\in V:\\underline{v}^\\dagger\\underline{w}=0\\}$, then $\\dim W=m-1<m$.\r\n    Now\r\n    $$\\underline{w}\\in W\\implies \\underline{v}^\\dagger (A\\underline{w})=(A\\underline{v})^\\dagger\\underline{w}=\\lambda\\underline{v}^\\dagger\\underline{w}=0\\implies A\\underline{w}\\in W$$\r\n    So $W$ is invariant under $A$, so by induction hypothesis, there is an orthonormal basis for $W$ of eigenvectors of $A$, say $\\{\\underline{u_1},\\ldots,\\underline{u_{m-1}}\\}$, then we deem $\\underline{u_m}=|\\underline{v}|^{-1}\\underline{v}$, then $\\{\\underline{u_1},\\ldots,\\underline{u_m}\\}$ gives an orthonormal basis of $V$, and the proof is done.\r\n\\end{proof}\r\n\\subsection{Quadratic Forms}\r\n\\begin{definition}\r\n    A quadratic form is a function $\\mathcal F:\\mathbb R^n\\to\\mathbb R$ given by $\\mathcal{F}(\\underline{x})=\\underline{x}^\\top A\\underline{x}$ where $A$ is a real symmetric $n\\times n$ matrix.\r\n    So $\\mathcal F(\\underline{x})=x_iA_{ij}x_j$.\r\n\\end{definition}\r\nSo by Theorem \\ref{hermitian_diag}, we can diagonalize it by an orthogonal matrix $P$.\r\nThen by letting $\\underline{x'}=P^\\top\\underline{x}$, we have $\\mathcal F(\\underline{x})=\\underline{x'}^\\top D\\underline{x'}$ where $D=\\operatorname{diag}(\\lambda_1,\\lambda_2,\\ldots,\\lambda_n)$, so we sau that $\\mathcal F$ is diagonalized.\r\nNote that $\\underline{x}=x_i'\\underline{u_i}$ where $\\underline{u_i}$ is the orthonormal eigenbasis.\r\nThus we can interpret what we have done as not changing the vector, but instead changing the basis in which we are working under.\r\nThis basis (and the corresponding coordinate axes) is called the principle axes of the quadratic form.\r\n\\begin{example}\r\n    1. In $\\mathbb R^2$, take\r\n    $$A=\\begin{pmatrix}\r\n        \\alpha&\\beta\\\\\r\n        \\beta&\\alpha\r\n    \\end{pmatrix}$$\r\n    So we can diagonalize it by $\\lambda_1=\\alpha+\\beta$, $\\lambda_2=\\alpha-\\beta$ and $\\underline{u_1}=2^{-1/2}(1,1)^\\top,\\underline{u_2}=2^{-1/2}(1,-1)^\\top$\r\n    Hence $\\underline{x'}=(2^{-1/2}(x_1+x_2),2^{-1/2}(x_1-x_2))^\\top$.\r\n    For example, if we take $\\alpha=3/2,\\beta=-1/2$, then the quadratic form defines an ellipse.\r\n    If we let $\\beta=3/2,\\alpha=-1/2$, then the quadratic from would be a hyperbola.\\\\\r\n    2. In $\\mathbb R^3$, by a suitable choice of basis, $\\mathcal F(\\underline{x})=\\lambda_1x_1^2+\\lambda_2x_2^2+\\lambda_3^2$.\r\n    If $\\lambda_i>0$, the graph is an ellipsoid (a sphere stretched towards the directions of the axes).\r\n    Otherwise, for example, the matrix that we have introduced in a former example \r\n    $$A=\\begin{pmatrix}\r\n        0&1&1\\\\\r\n        1&0&1\\\\\r\n        1&1&0\r\n    \\end{pmatrix}$$\r\n    has eigenvalues $-1,2$ where the algebraic multiplicity of $-1$ is $2$.\r\n    So on the principle axes $\\mathcal F_A(\\underline{x})=-x_1^2-x_2^2+2x_3^2$.\r\n    Hence it gives a hyperboloid (obtained by rotating a hyperbola).\r\n\\end{example}\r\nIt has important application when we use the Hessians as the quadratic Form.\r\n\\subsection{Cayley-Hamilton Theorem}\r\n\\begin{theorem}[Cayley-Hamilton]\r\n    $\\chi_A(A)=0$.\r\n\\end{theorem}\r\n\\begin{remark}\r\n    If $c_0I+c_1A+\\cdots+c_nA^n$, then $A(c_1I+C_2A+\\cdots+c_nA^{n-1})=-c_0I$.\r\n    So if $c_0=\\det A\\neq 0$, we have\r\n    $$A^{-1}=-\\frac{1}{c_0}(c_1I+C_2A+\\cdots+c_nA^{n-1})$$\r\n\\end{remark}\r\n\\begin{proof}\r\n    The general $2\\times 2$ case is immediate.\r\n    The case for diagonalizable matrices is also obvious.\r\n    The general case can be deal with a continuity argument or using modules.\r\n    A proof by basic algebra is also presented in lecture but is deemed not elegant enough by the author, hence is omitted.\r\n\\end{proof}", "meta": {"hexsha": "271e59986a0200e863079e14ba6209221235195e", "size": 18690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/eigen.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": "6/eigen.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": "6/eigen.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": 57.5076923077, "max_line_length": 353, "alphanum_fraction": 0.6556982343, "num_tokens": 6256, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8840392802184581, "lm_q1q2_score": 0.768076991894892}}
{"text": "%---------------------------Radius Ratio----------------------------------\n\\section{Radius Ratio\\label{s:tet-radius-ratio}}\n\nThis metric is commonly known as the radius ratio since it is the\nnormalized ratio of the radius of the inscribed sphere to the radius\nof the circumsphere. Note that it is equal to the tetrahedral aspect\n$\\beta$ for positively-oriented tetrahedra.  \n\nThe radius ratio is the quotient of these two radii normalized by $\\frac{1}{3}$ so\nthat an equilateral tetrahedron has quality of 1:\n\\begin{eqnarray*}\nq & = & \\frac{R}{3 r} \\nonumber \\\\\n  & = & \\frac { \\left| \n   \\normvec{L_3}^2 \\left( \\vec L_2 \\times \\vec L_0 \\right) + \n   \\normvec{L_2}^2 \\left( \\vec L_3 \\times \\vec L_0 \\right) + \n   \\normvec{L_0}^2 \\left( \\vec L_3 \\times \\vec L_2 \\right)\n   \\right| A}{108 V^2}.\n\\end{eqnarray*}\n\nNote that if $|V| < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\tetmetrictable{radius ratio}%\n{$1$}%                  Dimension\n{$[1,3]$}%              Acceptable range\n{$[1,DBL\\_MAX]$}%       Normal range\n{$[1,DBL\\_MAX]$}%       Full range\n{$1$}%                  Equilateral tet\n{\\cite{par:93}}%        Citation\n{v\\_tet\\_radius\\_ratio}% Verdict function name\n\n\n", "meta": {"hexsha": "6788da3d8e5556336707175a43f9dfba65c6a0f2", "size": 1165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TetRadiusRatio.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/TetRadiusRatio.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/TetRadiusRatio.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.40625, "max_line_length": 82, "alphanum_fraction": 0.6103004292, "num_tokens": 374, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.8244619263765706, "lm_q1q2_score": 0.7679553728423951}}
{"text": "\n\\subsection{Representing wave functions}\n\nWave function are of the form:\n\n\\(\\cos(ax + b)\\)\n\n\\(\\sin(ax + b)\\)\n\nWe can use the following identities:\n\n\\begin{itemize}\n\\item \\(\\cos(x)=\\sin(x+\\dfrac{\\tau }{8})\\)\n\\item \\(\\sin(-x)=-\\sin(x)\\)\n\\item \\(\\sin(a+b)=\\sin(a)\\cos(b)+\\sin(b)\\cos(a)\\)\n\\end{itemize}\n\nSo we can write any function as:\n\n\\subsubsection{Using \\(e\\)}\n\n\n", "meta": {"hexsha": "9ac888ae7daf72125e70cefa5d86a7d3bccdfd1d", "size": 365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/transformations/03-01-representation.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/03-01-representation.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/03-01-representation.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.8695652174, "max_line_length": 49, "alphanum_fraction": 0.6164383562, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602594, "lm_q2_score": 0.8244619242200081, "lm_q1q2_score": 0.7679553661278152}}
{"text": "\\lab{Algorithms}{QR decomposition}{QR decomposition}\n\\label{lab:QRdecomp}\n\n\\objective{Understand how the QR algorithm works and write your own implementation.}\n\nThe QR decomposition is used to represent any matrix as the multiple of an orthogonal matrix and an upper triangular matrix. This decomposition is useful in computing least squares and is part of a common method for finding eigenvalues.\n\n\\section*{Review of Gram Schmidt}\n\n\\vspace{5mm}\n\\begin{theorem}[Gram-Schmidt Orthogonalization Process] Let\n$\\{\\x_i\\}_{i=1}^n$ be a basis for the inner product space $V$. Let\n\\[\n\\q_1 = \\frac{\\x_1}{\\norm{\\x_1}},\n\\]\nand define $\\q_2,\\q_3,\\ldots,\\q_n$ recursively by\n\\[\n\\q_{k+1} = \\frac{\\x_{k+1} - \\p_k}{\\norm{\\x_{k+1} - \\p_k}},\n\\]\nwhere\n\\[\n\\p_k = \\sum^k_{j=1} \\langle \\x_{k+1}, \\q_j\\rangle \\q_j\n\\]\nis a projection of $\\x_{k+1}$ onto the subspace $\\mbox{Span}(\\q_1,\\q_2,\\ldots,\\q_k)$.  Then the set $\\{\\q_i\\}_{i=1}^n$ is an orthonormal basis for $V$.\n\\end{theorem}\n\\vspace{5mm}\n\nFor the above algorithm, let $r_{k k} = \\|\\x_k - \\p_{k-1}\\|$ and\n$r_{j k} = \\langle \\x_k, \\q_j\\rangle$.  Then\n\\begin{align*}\nr_{1 1} \\q_1 &= \\x_1\\\\\nr_{k k} \\q_k &= \\x_k - r_{1 k} \\q_1 - r_{2 k} \\q_2 - r_{3 k} \\q_3 -\n\\ldots - r_{k-1, k} \\q_{k-1},\\quad k=2,\\ldots,n.\n\\end{align*}\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\\begin{pmatrix}\n\\vdots & \\vdots & & \\vdots\\\\\n\\x_1 & \\x_2 & \\cdots & \\x_n\\\\\n\\vdots & \\vdots & & \\vdots\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n\\vdots & \\vdots & & \\vdots\\\\\n\\q_1 & \\q_2 & \\cdots & \\q_n\\\\\n\\vdots & \\vdots & & \\vdots\n\\end{pmatrix}\n\\begin{pmatrix}\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{pmatrix}.\n\\]\nHence if our original basis $\\{\\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.  This is the QR\nDecomposition and is summarized by the following theorem:\n\\vspace{5mm}\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\nThere are three mode options available in SciPy's implementation of QR Decomposition.  We will be using the ``economic\" option.\n\\begin{lstlisting}[style=python]\n: import scipy as sp\n: from scipy import linalg as la\n: A = sp.randn(4,3)\n: Q, R = la.qr(A, mode='economic')\n: sp.dot(Q, R) == A     there will be some False entries\n: sp.dot(Q, R) - A\n: sp.dot(Q.T, Q)\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).  This is why \\li{sp.dot(Q, R)} is not exactly equal to A.  But subtracting the two yields numbers that are essentially zero.  This shows that indeed the product of $Q$ and $R$ is $A$.  Note also that $Q^T Q = I$.  This implies that the column vectors of $Q$ are orthonormal (why?).\n\n\\section*{Solving Least Squares Problems}\n\nFor large or ill-conditioned problems, the QR decomposition provides\na nice method for computing least squares solutions of\nover-determined matrices.  Consider the problem $A x = b$.  Recall\nthat the least squares solution is $\\widehat x = (A^T A)^{-1}A^T b$.\nAlternatively, we write the linear system as\n\\[\nQ R x = b.\n\\]\nWe then multiply both sides by $Q^T$, yielding\n\\[\nR x = Q^T b.\n\\]\nThen $\\widehat x = R^{-1} Q^T b$.\n\n\\section*{Computational Remark}\n\nNumerically, the Gram Schmidt process can have problems due to\nfinite precision arithmetic. Specifically, due to rounding errors,\nthe resulting basis may not be orthonormal. To combat this, we\nactually carry out a slightly revised algorithm called Modified Gram\nSchmidt.  To do this, we compute $\\q_1$ as before.  We then project\nit out of each of the remaining original vectors\n$\\x_2,\\x_3,\\ldots,\\x_n$ via\n\\[\n\\x_k := \\x_k - \\langle \\x_{k}, \\q_1\\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$.\n\n\\begin{problem}\n\\label{prob:QR}\nWrite your own implementation of the QR decomposition.  It should accept as input a matrix $A$ and computes its QR decomposition, returning the matrices $Q$ and $R$. Be sure to use the numerically stable Modified Gram Schmidt algorithm.\n\\end{problem}\n", "meta": {"hexsha": "9d1d22bfb084bd9e8f2f706a498206fc434b2f65", "size": 4787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/QR/QR_C.tex", "max_stars_repo_name": "jasongrout/numerical_computing", "max_stars_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/QR/QR_C.tex", "max_issues_repo_name": "jasongrout/numerical_computing", "max_issues_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/QR/QR_C.tex", "max_forks_repo_name": "jasongrout/numerical_computing", "max_forks_repo_head_hexsha": "fa29838af62417703c65f680b167e81828de01c5", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-21T23:06:27.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-21T23:06:27.000Z", "avg_line_length": 37.1085271318, "max_line_length": 430, "alphanum_fraction": 0.6824733654, "num_tokens": 1668, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637361282706, "lm_q2_score": 0.8933094159957173, "lm_q1q2_score": 0.7679457100734419}}
{"text": "\\part{Inequalities}\n\n\\chapter{Piecewise Functions}\n\n\\section{Piecewise Functions}\n\nPiecewise functions typically feature one or more points at which the function changes from one form to another. To graph a piecewise function, simply graph each piece and then restrict it to its designated domain. Pay special attention when plotting the breaking point (closed circle includes the point, open circle excludes the point). \\\\\n\n\\begin{exercise}\\nonumber\n\tGraph the piecewise function given by \\\\\n\t\\begin{align}\n\t\ty = \\begin{cases}\n\t\t\t1   & x \\le 0 \\\\\n\t\t\t4^x & x > 0\n\t\t\\end{cases}\n\t\\end{align}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.3,yscale=0.4]\n\t\t\t\\draw[->] (-7,0) -- (7,0) node[right] {$ x $};\n\t\t\t\\draw[->] (0,-18) -- (0,18) node[above] {$ y $};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n\tGraph the piecewise function given by \\\\\n\t\\begin{align}\n\t\ty = \\begin{cases}\n\t\t\t{1 \\over 2}x + 3 & x < -2         \\\\\n\t\t\t0                & -2 \\le x \\le 2 \\\\\n\t\t\tx^2 - 1          & x > 2\n\t\t\\end{cases}\n\t\\end{align}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}[scale=0.5,yscale=0.3]\n\t\t\t\\draw[->] (-10,0) -- (6,0) node[right] {$ x $};\n\t\t\t\\draw[->] (0,-5) -- (0,20) node[above] {$ y $};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\\end{exercise}\n\n\\newpage\n\n\\chapter{Absolute Value Functions}\n\n\\section{Absolute Value Functions}\n\nA very special and common piecewise function is the absolute value function. \\\\\n\n\\begin{itemize}\n\t\\item\n\t      $ y = |x| = \\begin{cases} x & x \\ge 0 \\\\ -x & x < 0 \\end{cases} $ \\\\\n\n\t\\item\n\t      $ x \\in \\mathbb R $ \\\\\n\n\t\\item\n\t      $ y \\ge 0 $ \\\\\n\\end{itemize}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\begin{tikzpicture}[scale=0.8]\n\t\t\\draw[->] (-4,0) -- (4,0) node[right] {$ x $};\n\t\t\\draw[->] (0,-2) -- (0,4) node[above] {$ y $};\n\t\t\\draw[very thick,color=red,domain=-3:0] plot (\\x,{-\\x});\n\t\t\\draw[very thick,color=red,domain=0:3] plot (\\x,{\\x}) node[right] {$ y = |x| $};\n\t\\end{tikzpicture}\n\t\\caption{absolute value function}\n\\end{figure}\n\n\\begin{theorem}[Absolute Values]\n\t\\begin{align}\n\t\t & |ab| = |a| \\cdot |b|                           \\\\\n\t\t & \\left|{a \\over b}\\right| = {|a| \\over |b|}     \\\\\n\t\t & if\\ |a| \\le b,\\ then\\ -b \\le a \\le b           \\\\\n\t\t & if\\ |a| \\ge b,\\ then\\ a \\ge b \\ or \\ a \\le -b  \\\\\n\t\t & (Triangle \\ Inequality)\\ |a + b| \\le |a| + |b|\n\t\\end{align}\n\\end{theorem}\n\n\\chapter{Inequalities Notation}\n\n\\section{Inequalities Notation}\n\nWhen solving equation we may get a single answer, or a number of answers that satisfy the equation. \\\\\n\nConsider $ 3x - 5 = 1 $, only one value satisfies this equation. \\\\\n\nBut if we consider $ x^2 - 1 = 3 $, more than one value satisfies this equation. \\\\\n\nInequalities notation like $ 1 \\le x < 3 $, where the symbols $ \\le $ and $ \\ge $ indicate inclusion of an endpoint, and $ < $ and $ > $ indicate exclusion of an endpoint. \\\\\n\nA second notation is interval notation, for example, $ x \\in [1, 3) $, where a square (or closed) bracket indicates inclusion of an endpoint, and a round (or open) bracket indicates exclusion of an endpoint. \\\\\n\nThe infinity symbol $ \\infty $ is always accompanied by round brackets. \\\\\n\n\\begin{exercise}\\nonumber\n\tWrite each of the following in interval notation. \\\\\n\n\t(a) $ 2 \\le x \\le 7 $ \\\\\n\t\\\\\n\t\\\\\n\n\t(b) $ x < 9 $ \\\\\n\t\\\\\n\t\\\\\n\n\t(c) $ -3 > x > 0 $ \\\\\n\t\\\\\n\t\\\\\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n\tWrite each of the following using inequalities. \\\\\n\n\t(a) $ x \\in [3, 6) $ \\\\\n\t\t\t\t\\\\\n\t\t\t\t\\\\\n\n\t\t\t\t(b) $ x \\in (-2, 4) $ \\\\\n\t\t\t\t\\\\\n\t\t\t\t\\\\\n\n\t\t\t\t(c) $ x \\in (-\\infty, -1] $ \\\\\n\t\\\\\n\t\\\\\n\\end{exercise}\n\nIt is possible to have ranges of values that are disjoint. We use the union symbol $ \\cup $ to include all of the values in any of the disjoint ranges. For example, $ [-1, 4) \\cup [7, 10) $ meas $ -1 \\le x < 4 $ or $ 7 \\le x < 10 $. \\\\\n\n\\begin{exercise}\\nonumber\n\tExpress each of the following in interval notation. \\\\\n\n\t(a) $ -3 \\le x < {1 \\over 2} $ or $ 4 < x < 7 $ \\\\\n\t\\\\\n\t\\\\\n\n\t(b) $ 1 \\le x < 5 $ or $ 3 \\le x < 7 $ \\\\\n\t\\\\\n\t\\\\\n\n\t(c) $ x \\in [-2, 6) \\bigcup (0, 5) $ \\\\\n\t\\\\\n\t\\\\\n\\end{exercise}\n\nIntersection symbol $ \\cap $ allows only the values that are common between intervals. For example, $ [-1, 6) \\cap (2, 7) $ means $ (2, 6) $. \\\\\n\n\\begin{exercise}\\nonumber\n\tExpress each of the following in interval notation. \\\\\n\n\t(a) $ -2 < x \\le 6 $ and $ 0 < x < 7 $ \\\\\n\t\\\\\n\t\\\\\n\n\t(b) $ x \\in [0, 5] \\bigcap [3, 5] $ \\\\\n\t\\\\\n\t\\\\\n\n\t(c) $ -4 < x < 0 $ and $ 3 < x < 7 $ \\\\\n\t\\\\\n\t\\\\\n\\end{exercise}\n\n\\section{Solving Inequalities}\n\nWhen solving inequalities, there are a few rules that we must follow: \\\\\n\n\\begin{enumerate}\n\t\\item\n\t      When it comes to addition, subtraction, multiplication, and division, what you do to one side of the inequality, you must do to the other. \\\\\n\n\t\\item\n\t      If you multiply or divide by a negative quantity, you must flip the inequality. \\\\\n\n\t\\item\n\t      If both sides are positive or both sides are negative, then you can take the reciprocal of both sides, but you must flip the inequality. \\\\\n\\end{enumerate}\n\n\\begin{exercise}\\nonumber\n\tFind all values of x that satisfy the following. \\\\\n\n\t(a)\n\t\\begin{align}\n\t\t-6x + 7 & \\ge 8x \\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align} \\\\\n\n\t(b)\n\t\\begin{align}\n\t\t-{5 \\over 2} < 4 - 2x \\le 1 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align} \\\\\n\n\t(c)\n\t\\begin{align}\n\t\t5x^3 + 27 & > -13 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align} \\\\\n\n\t(d)\n\t\\begin{align}\n\t\t3x^2 + 2 & < -4 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align} \\\\\n\n\t(e)\n\t\\begin{align}\n\t\t\\sqrt{x-1} & > 4 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align} \\\\\n\n\t(f)\n\t\\begin{align}\n\t\tlog_2(3x) & \\le -3 \\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\\end{exercise}\n\n\\chapter{The Case Method}\n\n\\section{The Case Method}\n\nConsider the following example: $ {x - 3 \\over x - 1} < 10 $ \\\\\n\nYou might be tempted to cross multiply, but be careful! The quantity $ x - 1$ is not always positive. If we multiply by $ x - 1$, the inequality needs to flip for some values of $ x $. How might we deal with this? \\\\\n\n\\begin{enumerate}\n\t\\item\n\t      Separate into 2 cases \\\\\n\t      \\begin{table}[H]\n\t\t      \\centering\n\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t      \\textbf{Case 1} & \\textbf{Case 2}                \\\\ \\hline\n\t\t\t      $ \\begin{array}{ccc} x - 1 & > & 0 \\\\ x & > & 1 \\end{array} $\n\t\t\t                      & $ \\begin{array}{ccc} x - 1 & < & 0 \\\\ x & < & 1 \\end{array} $ \\\\ \\hline\n\t\t      \\end{tabular}\n\t      \\end{table}\n\n\t\\item\n\t      Solve the original problem under each assumption \\\\\n\t      \\begin{table}[H]\n\t\t      \\centering\n\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t      \\textbf{Case 1} & \\textbf{Case 2}                \\\\ \\hline\n\t\t\t      $ \\begin{array}{ccc} {x-3 \\over x-1} & < & 10 \\\\ x - 3 & < & 10(x-1) \\\\ -9x & < & -7 \\\\x & > & {7 \\over 9} \\end{array} $\n\t\t\t                      & $ \\begin{array}{ccc} {x-3 \\over x-1} & < & 10 \\\\ x - 3 & > & 10(x-1) \\\\ -9x & > & -7 \\\\ x & < & {7 \\over 9} \\end{array} $ \\\\ \\hline\n\t\t      \\end{tabular}\n\t      \\end{table}\n\n\t\\item\n\t      Find all common points between assumption and solution \\\\\n\t      \\begin{table}[H]\n\t\t      \\centering\n\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t      \\textbf{Case 1} & \\textbf{Case 2}                \\\\ \\hline\n\t\t\t      $ \\begin{array}{ccc} x > 1 \\ and \\ x > {7 \\over 9} \\\\ x \\in (1, \\infty) \\end{array} $\n\t\t\t                      & $ \\begin{array}{ccc} x < 1 \\ and \\ x < {7 \\over 9} \\\\ x \\in \\left(-\\infty, {7 \\over 9}\\right) \\end{array} $ \\\\ \\hline\n\t\t      \\end{tabular}\n\t      \\end{table}\n\n\t\\item\n\t      Consolidate the 2 cases by taking the union \\\\\n\t      $$\n\t\t      x \\in (1, \\infty) \\cup \\left(-\\infty, {7 \\over 9}\\right)\n\t      $$\n\\end{enumerate}\n\n\\begin{exercise}\\nonumber\n\tFind all values of x such that $ {7x - 2 \\over 1 - 2x} \\ge 4 $. \\\\\n\n\t\\begin{enumerate}\n\t\t\\item\n\t\t      Separate into 2 cases \\\\\n\t\t      \\begin{table}[H]\n\t\t\t      \\centering\n\t\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t\t      \\textbf{\\hspace{2cm}Case 1\\hspace{2cm}} & \\textbf{\\hspace{2cm}Case 2\\hspace{2cm}} \\\\ \\hline\n\t\t\t      \\end{tabular}\n\t\t      \\end{table}\n\t\t      \\vspace{2cm}\n\n\t\t\\item\n\t\t      Solve the original problem under each assumption \\\\\n\t\t      \\begin{table}[H]\n\t\t\t      \\centering\n\t\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t\t      \\textbf{\\hspace{2cm}Case 1\\hspace{2cm}} & \\textbf{\\hspace{2cm}Case 2\\hspace{2cm}} \\\\ \\hline\n\t\t\t      \\end{tabular}\n\t\t      \\end{table}\n\t\t      \\vspace{3cm}\n\n\t\t\\item\n\t\t      Find all common points between assumption and solution \\\\\n\t\t      \\begin{table}[H]\n\t\t\t      \\centering\n\t\t\t      \\begin{tabular}{|c|c|} \\hline\n\t\t\t\t      \\textbf{\\hspace{2cm}Case 1\\hspace{2cm}} & \\textbf{\\hspace{2cm}Case 2\\hspace{2cm}} \\\\ \\hline\n\t\t\t      \\end{tabular}\n\t\t      \\end{table}\n\t\t      \\vspace{3cm}\n\n\t\t\\item\n\t\t      Consolidate the 2 cases by taking the union \\\\\n\t\t      \\\\\n\t\\end{enumerate}\n\\end{exercise}\n\n\\chapter{The Number Line Method}\n\n\\section{The Number Line Method}\n\nAnother method for solving inequalities uses the following basic logic: \\\\\n\n\\begin{align}\n\t\\nonumber\n\t(+)(+) = + &  & {(+) \\over (+)} = + \\\\\n\t\\nonumber\n\t(-)(-) = + &  & {(-) \\over (-)} = + \\\\\n\t\\nonumber\n\t(+)(-) = - &  & {(+) \\over (-)} = - \\\\\n\t\\nonumber\n\t(-)(+) = - &  & {(-) \\over (+)} = -\n\\end{align}\n\nBy manipulating expressions into factors that are multiplied and/or divided on one side of the inequality (with a zero appearing on the other side), we can simply consider the combinations of positive and negative factors to draw conclusions. \\\\\n\n\\begin{exercise}\\nonumber\n\tFind all values of x that satisfy $ 3x^2 - 13x > -10 $. \\\\\n\n\t\\begin{align}\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[->] (-5.5,0)--(5.5,0);\n\t\t\t\\foreach \\x in {-5,-4,...,5}\n\t\t\t\\draw (\\x,0.2)--(\\x,0);\n\t\t\t\\draw[very thick] (-2,0)--(-2,1)--(-6,1) node[above] {$ (-)(-) $};\n\t\t\t\\draw[very thick] (2,0)--(2,1)--(6,1) node[above] {$ (+)(+) $};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t\\vspace{1cm}\n\\end{exercise}\n\n\\begin{exercise}\\nonumber\n\tFind all values of x that satisfy $ x - 2 \\ge {4 \\over x+1} $. \\\\\n\n\t\\begin{align}\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\t\\\\\n\t\\end{align}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\begin{tikzpicture}\n\t\t\t\\draw[->] (-5.5,0)--(5.5,0);\n\t\t\t\\foreach \\x in {-5,-4,...,5}\n\t\t\t\\draw (\\x,0.2)--(\\x,0);\n\t\t\t\\draw[very thick] (-3,0)--(-3,1)--(-1,1)--(-1,0) node[below] {$ {(-)(+)} \\over (-) $};\n\t\t\t\\draw[very thick] (2,0)--(2,1)--(4,1)--(4,0) node[below] {$ {(+)(+)} \\over (+) $};\n\t\t\\end{tikzpicture}\n\t\\end{figure}\n\n\t\\vspace{1cm}\n\\end{exercise}", "meta": {"hexsha": "08650e321b69339883ec09c9c1a894e1bc5e36dc", "size": 10284, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/parts/part2.tex", "max_stars_repo_name": "xdai02/Calculus", "max_stars_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Calculus/parts/part2.tex", "max_issues_repo_name": "xdai02/Calculus", "max_issues_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus/parts/part2.tex", "max_forks_repo_name": "xdai02/Calculus", "max_forks_repo_head_hexsha": "45e2774a19879e687e0ca9cc8ada28cf290ce2ec", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.4370179949, "max_line_length": 340, "alphanum_fraction": 0.5538700895, "num_tokens": 3791, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637433190938, "lm_q2_score": 0.8933093961129794, "lm_q1q2_score": 0.767945699404603}}
{"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 by which 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 sample. This creates an irreducible, non-null recurrent, aperiodic Markov chain over the state space consisting of all possible $\\mathbf{x}$. The 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 data set of $N$ scores from a calculus exam in the file \\texttt{examscores.csv}. We believe that the spread of these exam scores can be\nmodeled 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(\\mu_{0}, \\sigma_{0}^{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}, \\mu_{0}, \\sigma_{0}^{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}, \\mu_{0}, \\sigma_{0}^{2}, \\alpha, \\beta) & = \\mathbb{P}(\\mu | \\sigma^{2}, \\mathbf{y}, \\mu_{0}, \\sigma_{0}^{2})\\\\\n\\mathbb{P}(\\sigma^{2} | \\mu, \\mathbf{y}, \\mu_{0}, \\sigma_{0}^{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}, \\mu_{0}, \\sigma_{0}^{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}{\\sigma_0^2}+\\frac{N}{\\sigma^2}\\right)^{-1}\\\\\n\\mu^* &= (\\sigma^*)^2\\left(\\frac{\\mu_0}{\\sigma_0^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 just have to alternate between sampling $\\mu$ and $\\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}\nImplement a Gibbs sampler for the exam scores problem using the following function declaration.\n\\begin{lstlisting}\ndef gibbs(y, mu0, sigma02, alpha, beta, n_samples):\n    \"\"\"\n    Assuming a likelihood and priors\n        y_i    ~ N(mu, sigma2),\n        mu     ~ N(mu0, sigma02),\n        sigma2 ~ IG(alpha, beta),\n    sample from the posterior distribution\n        P(mu, sigma2 | y, mu0, sigma02, alpha, beta)\n    using a gibbs sampler.\n\n    Parameters\n    ----------\n    y : ndarray of shape (N,)\n        The data\n    mu0 : float\n        The prior mean parameter for mu\n    sigma02 : float > 0\n        The prior variance parameter for mu\n    alpha : float > 0\n        The prior alpha parameter for sigma2\n    beta : float > 0\n        The prior beta parameter for sigma2\n    n_samples : int\n        The number of samples to draw\n\n    Returns\n    -------\n    samples : ndarray of shape (n_samples,2)\n        1st col = mu samples, 2nd col = sigma2 samples\n    \"\"\"\n    pass\n\\end{lstlisting}\nTest it with priors $\\mu_{0}=80, \\sigma_{0}^{2} = 16, \\alpha = 3, \\beta = 50$, collecting $1000$ samples. Plot your samples of $\\mu$ and your samples of $\\sigma^{2}$. How long did it take for each to converge? It should have been very quick.\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, we will use a kernel density estimator.\nIf our samples of $\\mu$ are called \\li{mu_samples}, then we can do this as follows:\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy.stats import gaussian_kde\n>>> import matplotlib.pyplot as plt\n>>> mu_kernel = gaussian_kde(mu_samples)\n>>> x_min = min(mu_samples) - 1\n>>> x_max = max(mu_samples) + 1\n>>> x = np.arange(x_min, x_max, step=0.1)\n>>> plt.plot(x,mu_kernel(x))\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{mu_posterior.pdf}\n\t\t\\caption{Posterior distribution of $\\mu$.}\n\t\\end{subfigure}\n\t\\begin{subfigure}[b]{.49\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{sigma2_posterior.pdf}\n\t\t\\caption{Posterior distribution of $\\sigma^2$.}\n\t\\end{subfigure}\n\\caption{Posterior marginal probability densities for $\\mu$ and $\\sigma^2$.}\n\\label{fig:post}\n\\end{figure}\n\n\\begin{problem}\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\\end{problem}\n\nKeep in mind that the above plots 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 $\\mu_{0}, \\sigma_{0}^{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}\n\\includegraphics[width=\\textwidth]{predictiveposterior.pdf}\n\\caption{Predictive posterior distribution of exam scores.}\n\\label{fig:predictive}\n\\end{figure}\n\n\\begin{problem}\nUse your samples to draw samples from the posterior predictive distribution. Plot the kernel density estimator of your sampled scores.\nIt should resemble the plot in Figure \\ref{fig:predictive}.\n\\end{problem}\n\n\\section*{Latent Dirichlet Allocation}\nGibbs sampling can be applied to an interesting problem in language processing: that of determining which topics are prevalent in a document.\nLatent Dirichlet Allocation (LDA) is a generative model for a collection of text documents.\nIt supposes that there is some fixed vocabulary of terms (of length $V$) and $K$ different topics, each represented as a probability distribution $\\phi_{k}$ over the vocabulary, each with a Dirichlet prior $\\beta$.\nWith the vocabulary and topics chosen, the LDA model assumes that a set of $D$ documents is generated as follows.\nThe $m$-th document consists of $N_m$ words, and\na probability distribution $\\theta_{m}$ over the topics is drawn from a Dirichlet distribution with parameter $\\alpha$.\nTo generate each new word in the $m$-th document, 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\t\\item Draw $\\phi_{k} \\sim \\text{Dir}(\\beta)$ for $1 \\leq k \\leq K$.\n\t\\item For $1 \\leq m \\leq D$:\n\t\\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\t    \\item Draw $w_{m,n} \\sim \\text{Cat}(\\phi_{z_{m,n}})$ for $1 \\leq n \\leq N_{m}$.\n\t\\end{enumerate}\n\\end{enumerate}\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\t{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\t.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\t.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\t(w)[above of=dummy]{$w_{m,n}$};\n\\node[circle, draw,  inner sep=1pt, node distance=1.3cm](z)[above\n\tof=w]{$z_{m,n}$};\n\\node[circle, draw,  inner sep=1pt, node distance=1.3cm]\n\t(theta)[above of=z]{$\\vec{\\theta}_{m}$};\n\n\\node[node distance=1.2cm, inner sep=0pt](alpha)[above of=\n\ttheta]{$\\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\tof=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. We 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}_{\\neg (m,n)} = \\mathbf{z}\\setminus \\{z_{m,n}\\}$, the conditional posterior distributions\n\\[\\mathbb{P}(z_{m,n} = k | \\mathbf{z}_{\\neg (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}_{\\neg (m,n)}, \\mathbf{w}, \\alpha, \\beta) \\propto \\frac{(n_{(k,m,\\cdot)}^{\\neg (m,n)} + \\alpha)(n_{(k, \\cdot, w_{m,n})}^{\\neg (m,n)} + \\beta)}{n_{(k,\\cdot,\\cdot)}^{\\neg (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)}^{\\neg (m,n)} & = n_{(k,m,\\cdot)} - \\indicator{z_{m,n} = k} \\\\\nn_{(k,\\cdot,v)}^{\\neg (m,n)} & = n_{(k,\\cdot,v)} - \\indicator{z_{m,n} = k} \\\\\nn_{(k,\\cdot,\\cdot)}^{\\neg (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\nWe have provided for you the structure of a Python object \\li{LDACGS} with several methods. The 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}. By 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\\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\\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}. It accepts arguments $m,w$ where $m$ is the document and $w$ is an index of \\li{vocab}. Don'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}. The argument \\emph{filename} is the name and location of a .txt file, where each line is considered a document. The corpus is built by method \\li{buildCorpus}, and stopwords are removed (if argument \\emph{stopwords} is provided). Burn in the Gibbs sampler, computing and saving the log-likelihood with the method \\li{\\_loglikelihood}. After 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. Also save each log-likelihood.\n\\end{problem}\n\nYou should now have a working Gibbs sampler to perform LDA inference on a corpus. Let's test it out on Ronald Reagan's State of the Union addresses.\n\n\\begin{problem}\nCreate an \\li{LDACGS} object with $20$ topics, letting \\li{alpha} and \\li{beta} be the default values. Load in the stop word list provided. Run the Gibbs sampler, with a burn in of $100$ iterations, accumulating $10$ samples, only keeping the results of every $10$ sweep. Plot the log-likelihoods. How long did it take to truly burn in?\n\\end{problem}\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 highest probability, where $n$ is small (say $10$ or $20$).  We 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.\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 highest values of $\\widehat{\\theta}_{k}$ are those most heavily focused on topic $k$.\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", "meta": {"hexsha": "cd958319dfb69ae3dc2f757104cbe60da886ee94", "size": 18102, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/LDA/lda.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Labs/LDA/lda.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/LDA/lda.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.2057877814, "max_line_length": 616, "alphanum_fraction": 0.7026847862, "num_tokens": 5455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236823, "lm_q2_score": 0.8933093954028816, "lm_q1q2_score": 0.7679456955823427}}
{"text": "\\section{Dual Space and Dual Maps}\r\n\\begin{definition}\r\n    Let $V$ be a vector space over $F$, we define the dual space $V^\\ast$ of $V$ to be the set of linear maps from $V$ to $F$, i.e. $V^\\ast=L(V,F)$.\\\\\r\n    We call linear maps $V\\to F$ as linear forms.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. The map $\\operatorname{tr}:M_{n,n}(F)\\to F$ via $A=(a_{ij})\\mapsto\\sum_ia_{ii}$ is a linear form, so $\\operatorname{tr}\\in (M_{n,n}(F))^\\ast$.\\\\\r\n    2. For a function $f:\\in C^{\\infty}([0,1],\\mathbb R)$, we can define the map $T_f:C^{\\infty}([0,1],\\mathbb R)$ via\r\n    $$T_f(\\phi)=\\int_0^1f(x)\\phi(x)\\,\\mathrm dx$$\r\n    An interesting thing is, if we are given all information about $T_f$, can we recover $f$?\r\n    The answer is yes and is left as an exercise.\r\n    This idea comes from quantum mechanics, where you only get the information about $T_f$ by physical measurements but you want information about $f$.\r\n\\end{example}\r\nThere is a natural way of finding a basis for the dual space.\r\n\\begin{lemma}\r\n    Let $V$ be a vector space over $F$ with a finite basis $B=\\{e_1,\\ldots,e_n\\}$, then there exists a basis for $V^\\ast$ given by\r\n    $B^\\ast=\\{\\epsilon_1,\\ldots,\\epsilon_n\\}$ where $\\epsilon_j(\\sum_ia_ie_i)=a_j$ for $1\\le j\\le n$.\r\n\\end{lemma}\r\n\\begin{definition}\r\n    The basis $B^\\ast$ in the preceding lemma is called the dual basis.\r\n\\end{definition}\r\n\\begin{remark}\r\n    If we introduce the Kronecker delta\r\n    $$\\delta_{ij}=\\begin{cases}\r\n        1\\text{, if $i=j$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    then we can define $\\epsilon_j$ by extending $\\epsilon_j(e_i)=\\delta_{ij}$.\r\n\\end{remark}\r\n\\begin{proof}\r\n    If there is some $\\lambda_j\\in F$ such that $\\sum_j\\lambda_j\\epsilon_j=0$, then in particular the evaluation of the left hand side at $e_i$ is zero for each $i$.\r\n    But $\\epsilon_j(e_i)=0$, so $\\lambda_i=0$ for each $i$.\\\\\r\n    To see this is spanning, one just observe that $\\alpha=\\sum_j\\alpha(e_j)\\epsilon_j$ for any linear form $\\alpha$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $V$ is finite dimensional, then $\\dim V^\\ast=\\dim V$.\r\n\\end{corollary}\r\n\\begin{remark}\r\n    It is convenient to think of $V^\\ast$ as the space of row vectors of length $n$ over $F$.\r\n    Indeed, if we have a basis $\\{e_i\\}$ of $V$ and the corresponding dual basis $\\{\\epsilon_i\\}$ for $V^\\ast$, then via calculation we can obtain $\\alpha(x)=\\sum_i\\alpha_ix_i$ where $\\alpha=\\sum_i\\alpha_i\\epsilon_i$ and $x=\\sum_ix_ie_i$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    If $U\\subset V$ is a subset of the vector space $V$, then the annihilator of $U$ is\r\n    $$U^\\circ=\\{\\alpha\\in V^\\ast:\\forall u\\in U,\\alpha(u)=0\\}$$\r\n\\end{definition}\r\n\\begin{lemma}\r\n    $U^\\circ\\le V^\\ast$ and if $U\\le V$ and $\\dim V$ is finite, then $\\dim V=\\dim U+\\dim U^\\circ$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Quite obvious that $U^\\circ\\le V^\\ast$.\r\n    To see the identity, write $n=\\dim V$ and extend a basis $\\{e_1,\\ldots,e_k\\}$ of $U$ to a basis $\\{e_1,\\ldots,e_n\\}$ of $V$.\r\n    Let $\\{\\epsilon_1,\\ldots,\\epsilon_n\\}$ be the dual basis.\r\n    Then it becomes obvious that $U^\\circ=\\langle\\{\\epsilon_{k+1},\\ldots,\\epsilon_n\\}\\rangle$, which gives the identity.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $V,W$ be vector spaces over $F$ and $\\alpha\\in L(V,W)$.\r\n    Then the map $\\alpha^\\ast:W^\\ast\\to V^\\ast$ sending $\\epsilon$ to $\\epsilon\\circ\\alpha$ is linear.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{definition}\r\n    This map $\\alpha^\\ast$ is called the dual map of $\\alpha$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    Let $V,W$ be finite dimensional vector spaces over $F$ with bases $B,C$.\r\n    Let $B^\\ast,C^\\ast$ be the dual bases of $V^\\ast,W^\\ast$, then $[\\alpha^\\ast]_{C^\\ast,B^\\ast}=[\\alpha]_{B,C}^\\top$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just write it down.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    Let $E,F$ be bases of $V$ and $P=[\\operatorname{id}]_{F,E}$ be the change-of-basis matrix from $F$ to $E$.\r\n    Let $E^\\ast,F^\\ast$ be the corresponding dual bases, then the change-of-basis matrix from $F^\\ast$ to $E^\\ast$ is $(P^{-1})^\\top$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We have\r\n    $$[\\operatorname{id}]_{F^\\ast,E^\\ast}=[\\operatorname{id}]^\\top_{E,F}=(P^{-1})^\\top$$\r\n    as desired.\r\n\\end{proof}", "meta": {"hexsha": "a2c4fde68cc80e52bd7e5a9ac6ee601aa666ab51", "size": 4235, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8/dual.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": "8/dual.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": "8/dual.tex", "max_forks_repo_name": "david-bai-notes/IB-Linear-Algebra", "max_forks_repo_head_hexsha": "5a499f7ed33ef0110facb27323e13f42883aa0c5", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.9375, "max_line_length": 239, "alphanum_fraction": 0.6415584416, "num_tokens": 1409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021708, "lm_q2_score": 0.8856314858927011, "lm_q1q2_score": 0.7678741682757037}}
{"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 $n = 16$.\nDraw the recursion tree for Equation \\ref{eq16}, including every node in the tree.\nSince $n$ is finite, there are only a finite number of nodes in the tree.\nYou need to show every one of them.\n\n\\begin{equation}\nT(n) = T(\\frac{n}{4})+T(\\frac{n}{2})+n^2\n\\label{eq16}\n\\end{equation}\n\n\\subsection*{Solution}\n\nRecursion tree for Equation \\ref{eq16} is depicted in Figure \\ref{fig1}.\n\n\\begin{figure}[H]\\centering\n\\begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]\n\\node [circle,draw] (z){$T(16)$}\n  child {\n    node [circle,draw] (a) {$T(8)$}\n    child {\n      node [circle,draw] (c) {$T(4)$}\n      child {\n        node [circle,draw] (g) {$T(2)$}\n        child {\n          node [circle,draw] (k) {$T(1)$}\n        }\n      }\n      child {\n        node [circle,draw] (h) {$T(1)$}\n      }\n    }\n    child {\n      node [circle,draw] (d) {$T(2)$}\n      child {\n        node [circle,draw] (i) {$T(1)$}\n      }\n    }\n  }\n  child {\n    node [circle,draw] (b) {$T(4)$}\n    child {\n      node [circle,draw] (e) {$T(2)$}\n      child {\n        node [circle,draw] (j) {$T(1)$}\n      }\n    }\n    child {\n      node [circle,draw] (f) {$T(1)$}\n    }\n  };\n\\end{tikzpicture}\n\\caption{Recursion tree for $T(n)=T(\\frac{n}{2})+T(\\frac{n}{4})+n^2$ when $n = 16$}\\label{fig1}\n\\end{figure}\n", "meta": {"hexsha": "c06fe8770919ec6144c72979014e1635949bee61", "size": 1665, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q07.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q07.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs624-2015s/src/tex/hw01/hw01q07.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": 26.4285714286, "max_line_length": 95, "alphanum_fraction": 0.5267267267, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357701094303, "lm_q2_score": 0.8856314662716159, "lm_q1q2_score": 0.7678741603919546}}
{"text": "\\section{The Fundamental Theorem of Line Integrals}\\label{sec:FundamentalTheoremLineIntegrals}\n\nOne way to write the Fundamental Theorem of Calculus\n(\\ref{thm:fundamental_theorem_I}) is:\n$$\\int_a^b f'(x)\\,dx = f(b)-f(a).$$\nThat is, to compute the integral of a derivative $f'$ \nwe need only compute the values of $f$ at the endpoints. Something\nsimilar is true for line integrals of a certain form.\n\n\\begin{theorem}{Fundamental Theorem of Line Integrals}{FTLineIntegrals}\nSuppose a curve $C$ is\ngiven by the vector function ${\\bf r}(t)$, with ${\\bf a}={\\bf r}(a)$\nand ${\\bf b}={\\bf r}(b)$. Then\n$$\\int_C \\nabla f\\cdot d{\\bf r} = f({\\bf b})-f({\\bf a}),$$\nprovided that $\\bf r$ is sufficiently nice.\n\\end{theorem}\n\\begin{proof}\nWe write ${\\bf r}=\\langle x(t),y(t),z(t)\\rangle$, so \nthat ${\\bf r}'=\\langle x'(t),y'(t),z'(t)\\rangle$. Also,\nwe know that $\\nabla f=\\langle f_x,f_y,f_z\\rangle$. Then\n$$\\int_C \\nabla f\\cdot d{\\bf r} = \n\\int_a^b \\langle f_x,f_y,f_z\\rangle\\cdot\\langle\nx'(t),y'(t),z'(t)\\rangle\\,dt=\n\\int_a^b f_x x'+f_y y'+f_z z' \\,dt.$$\nBy the chain rule (see Section~\\ref{sec:multivariable chain rules})\n$f_x x'+f_y y'+f_z z'=df/dt$, where $f$ in this context means\n$f(x(t),y(t),z(t))$, a function of $t$. In other words, all we have is\n$$\\int_a^b f'(t)\\,dt=f(b)-f(a).$$\nIn this context,\n$f(a)=f(x(a),y(a),z(a))$.\nSince ${\\bf a}={\\bf r}(a)=\\langle x(a),y(a),z(a)\\rangle$, we can\nwrite $f(a)=f({\\bf a})$---this is a bit of a cheat, since we are\nsimultaneously using $f$ to mean $f(t)$ and $f(x,y,z)$, and since\n$f(x(a),y(a),z(a))$ is not technically the same as \n$f(\\langle x(a),y(a),z(a)\\rangle)$,\nbut the\nconcepts are clear and the different uses are compatible. Doing the\nsame for $b$, we get\n$$\\int_C \\nabla f\\cdot d{\\bf r} = \\int_a^b f'(t)\\,dt=f(b)-f(a)=f({\\bf\n  b})-f({\\bf a}).$$ \n\\end{proof}\n\nThis theorem, like the Fundamental Theorem of Calculus, says roughly\nthat if we integrate a ``derivative-like function'' ($f'$ or $\\nabla\nf$) the result depends only on the values of the original function ($f$)\nat the endpoints.\n\nIf a vector field $\\bf F$ is the gradient of a function, ${\\bf\n  F}=\\nabla f$, we say that $\\bf F$ is a \\dfont{conservative vector field}.\nIf $\\bf F$ is a conservative force field, then the integral for work,\n$\\int_C {\\bf F}\\cdot d{\\bf r}$, is in the form required by the\nFundamental Theorem of Line Integrals. This means that in a\nconservative force field, the amount of work required to move an\nobject from point $\\bf a$ to point $\\bf b$ depends only on those\npoints, not on the path taken between them.\n\n\\begin{example}{Work Done}{}\nAn object moves in the force field \n$${\\bf F}=\n\\left\n\\langle {-x\\over (x^2+y^2+z^2)^{3/2}},{-y\\over (x^2+y^2+z^2)^{3/2}},{-z\\over\n  (x^2+y^2+z^2)^{3/2}}\\right\\rangle,$$\nalong the curve ${\\bf r}=\\langle 1+t,t^3,t\\cos(\\pi t)\\rangle$ as $t$\nranges from 0 to 1. Find the work done by the force on the object.\n\\end{example}\n\\begin{solution}\nThe straightforward way to do this involves substituting the\ncomponents of ${\\bf r}$ into $\\bf F$, forming the dot product ${\\bf\n  F}\\cdot{\\bf r}'$, and then trying to compute the integral, but this\nintegral is extraordinarily messy, perhaps impossible to compute. But\nsince ${\\bf F}=\\nabla (1/\\sqrt{x^2+y^2+z^2})$ we need only substitute:\n$$\\int_C {\\bf F}\\cdot d{\\bf r}=\n\\left.{1\\over \\sqrt{x^2+y^2+z^2}}\\right|_{(1,0,0)}^{(2,1,-1)}=\n{1\\over\\sqrt6}-1.\n$$\n\\end{solution}\n\nAnother immediate consequence of the Fundamental Theorem involves\n\\dfont{closed paths}. A path $C$ is closed if it\nforms a loop, so that traveling over the $C$ curve brings you back to\nthe starting point. If $C$ is a closed path, we can integrate around\nit starting at any point $\\bf a$; since the starting and ending points are the\nsame,\n$$\\int_C \\nabla f\\cdot d{\\bf r}=f({\\bf a})-f({\\bf a})=0.$$\nFor example, in a gravitational field (an inverse square law field)\nthe amount of work required to move an object around a closed path is\nzero. Of course, it's only the \\emph{net} amount of work that is\nzero. It may well take a great deal of work to get from point $\\bf a$\nto point $\\bf b$, but then the return trip will ``produce'' work. For\nexample, it takes work to pump water from a lower to a higher elevation,\nbut if you then let gravity pull the water back down, you can recover\nwork by running a water wheel or generator. (In the real world you\nwon't recover all the work because of various losses along the way.)\n\nTo make use of the Fundamental Theorem of Line Integrals, we need to\nbe able to spot conservative vector fields $\\bf F$ and to compute \n$f$ so that ${\\bf F}=\\nabla f$. Suppose that ${\\bf F}=\\langle\nP,Q\\rangle = \\nabla f$. Then $P=f_x$ and $Q=f_y$, and provided that\n$f$ is sufficiently nice, we know from Clairaut's Theorem\n(\\ref{thm:clairaut}) that $P_y=f_{xy}=f_{yx}=Q_x$. If we compute\n$P_y$ and $Q_x$ and find that they are not equal, then $\\bf F$ is not\nconservative. If $P_y=Q_x$, then, again provided that $\\bf F$ is\nsufficiently nice, we can be assured that $\\bf F$ is conservative.\nUltimately, what's important is that we be able to find $f$; as this\namounts to finding anti-derivatives, we may not always succeed.\n\n\\begin{example}{}{}\nFind an $f$ so that $\\langle 3+2xy,x^2-3y^2\\rangle = \\nabla f$.\n\\end{example}\n\\begin{solution}\nFirst, note that \n$${\\partial\\over\\partial y}(3+2xy)=2x\\qquad\\hbox{and}\\qquad\n{\\partial\\over\\partial x}(x^2-3y^2)=2x,$$\nso the desired $f$ does exist. This means that $f_x=3+2xy$, so that\n$f=3x+x^2y+g(y)$; the first two terms are needed to get $3+2xy$, and\nthe $g(y)$ could be any function of $y$, as it would disappear upon\ntaking a derivative with respect to $x$. Likewise, since\n$f_y=x^2-3y^2$, $f=x^2y-y^3+h(x)$. The question now becomes, is it\npossible to find $g(y)$ and $h(x)$ so that\n$$3x+x^2y+g(y)=x^2y-y^3+h(x),$$\nand of course the answer is yes: $g(y)=-y^3$, $h(x)=3x$. Thus,\n$f=3x+x^2y-y^3$.\n\\end{solution}\n\n\\label{page:test for conservative vector field}\nWe can test a vector field ${\\bf F}=\\langle P,Q,R\\rangle$ in a similar\nway. Suppose that $\\langle P,Q,R\\rangle=\\langle f_x,f_y,f_z\\rangle$. If we temporarily hold\n$z$ constant, then $f(x,y,z)$ is a function of $x$ and $y$, and\nby Clairaut's Theorem $P_y=f_{xy}=f_{yx}=Q_x$.\nLikewise, holding $y$ constant implies $P_z=f_{xz}=f_{zx}=R_x$, and\nwith $x$ constant we get $Q_z=f_{yz}=f_{zy}=R_y$. Conversely, if we\nfind that $P_y=Q_x$, $P_z=R_x$, and $Q_z=R_y$ then $\\bf F$ is\nconservative.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:FundamentalTheoremLineIntegrals}}\n\n\\begin{enumialphparenastyle}\n\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle 2x+y^2,2y+x^2\\rangle$, or\nexplain why there is no such $f$.\n\\begin{sol}\n\tno $f$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle x^3,-y^4\\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\t$x^4/4-y^5/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle xe^y,ye^x \\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\tno $f$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle y\\cos x,y\\sin x \\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\tno $f$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle y\\cos x,\\sin x\\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\t$y\\sin x$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle x^2y^3,xy^4\\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\tno $f$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an $f$ so that $\\nabla f=\\langle yz,xz,xy\\rangle$, \nor explain why there is no such $f$.\n\\begin{sol}\n\t$xyz$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_C (10x^4 - 2xy^3)\\,dx - 3x^2y^2\\,dy$ where $C$ is\nthe part of the curve $x^5-5x^2y^2-7x^2=0$ from $(0,0)$ to\n$(3,2)$.\n\\begin{sol}\n\t414\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet \n${\\bf F}=\n\\langle yz,xz,xy\\rangle$.\nFind the work done by this force field on an object that moves from \n$(1,0,2)$ to $(1,2,3)$.\n\\begin{sol}\n\t$6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet \n${\\bf F}=\n\\langle e^y,xe^y+\\sin z,y\\cos z\\rangle$.\nFind the work done by this force field on an object that moves from \n$(0,0,0)$ to $(1,-1,3)$.\n\\begin{sol}\n\t$1/e-\\sin3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet \n$${\\bf F}=\n\\left\n\\langle {-x\\over (x^2+y^2+z^2)^{3/2}},{-y\\over (x^2+y^2+z^2)^{3/2}},{-z\\over\n  (x^2+y^2+z^2)^{3/2}}\\right\\rangle.$$\nFind the work done by this force field on an object that moves from \n$(1,1,1)$ to $(4,5,6)$.\n\\begin{sol}\n\t$1/\\sqrt{77}-1/\\sqrt3$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "4a95d32b99e39028266a377fa5a5c749288c27e3", "size": 8518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "16-vector-calculus/16-3-fundamental-thm-line-integrals.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "16-vector-calculus/16-3-fundamental-thm-line-integrals.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "16-vector-calculus/16-3-fundamental-thm-line-integrals.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.0534979424, "max_line_length": 94, "alphanum_fraction": 0.6670579948, "num_tokens": 3090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8856314677809303, "lm_q1q2_score": 0.7678741434437165}}
{"text": "\\section{Reduction}\n\n\\subsection{Notation}\n\\begin{itemize}\n    \\item $\\Gamma\\vdash \\tt t\\rhd u$ : $\\tt t$ reduces to $\\tt u$ in $\\Gamma$ with \n    one of the $\\beta,\\iota,\\delta,\\zeta$ reductions.\n    \\item $\\Gamma\\vdash \\tt t\\mathop{\\rhd}\\limits^* u$ : $\\Gamma\\vdash\\tt t\\rhd\\cdots\\rhd u$.\n    \\item $\\tt u\\equiv v$ : $\\tt u$ and $\\tt v$ are identical.\n\\end{itemize}\n\n\\subsection{Conversion Rules}\n\\begin{equation*}\n    \\Gamma\\vdash\\tt((\\lambda x:T.\\ t)\\ u)\\ \\rhd_\\beta\\ t\\{x/u\\}\n    \\tag{\\sc $\\beta$-Conv}\n\\end{equation*}\n\\begin{equation*}\n    \\Gamma\\vdash\\tt x\\ \\rhd_\\delta\\ t\\qquad \\textit{if }(x:=t:T)\\in\\Gamma\n    \\tag{\\sc $\\delta$-Conv}\n\\end{equation*}\n\\begin{equation*}\n\\Gamma\\vdash \\tt let\\ \\ x:=u\\ \\ in\\ \\ t\\ \\rhd_\\zeta\\ t\\{x/u\\}\n    \\tag{\\sc $\\zeta$-Conv}\n\\end{equation*}\n\\begin{equation*}\n    \\tt case((c_{p_i}\\ q_1\\ \\cdots\\ q_r\\ a_1\\ \\cdots\\ a_m),P,f_1\\ |\\ \\cdots\\ |\\ f_n)\\ \\rhd_\\iota\\ (f_i\\ a_1\\ \\cdots\\ a_m)\n    \\tag{\\sc $\\iota$-Conv}\n\\end{equation*}\n\\begin{equation*}\n\\frac{\\Gamma\\vdash \\tt t:\\forall x:T,U\\qquad x\\textit{ fresh in }t}\n    {\\tt t\\ \\rhd_\\eta\\ \\lambda\\tt x:T.\\ (t\\ x)}\n    \\tag{\\sc $\\eta$-Exp}\n\\end{equation*}\n\nHere's an example for $\\iota$-reduction:\n\\begin{center}\n\\begin{minipage}{0.6\\textwidth}\n\\begin{minted}{coq}\nmatch (S m) as s0 in nat return nat with\n| S n => n\n| O => O\nend\n\n(* $\\iota$-reduction *)\n(fun (n:nat) => n) m.\n\\end{minted}\n\\end{minipage}\n\\end{center}\n\n\\begin{Def}[Convertibility]\n$\\tt t_1$ and $\\tt t_2$ are convertible iff there exists $\\tt u_1$ and $\\tt u_2$ such that \n$\\Gamma\\vdash \\tt t_1\\mathop{\\rhd}\\limits^* u_1$ and $\\Gamma\\vdash \\tt t_2\\mathop{\\rhd}\\limits^* u_2$ \nand either $\\tt u_1\\equiv u_2$ or they are convertible up to $\\eta$-expansion.\n\\end{Def}\n\n", "meta": {"hexsha": "981e06cba1b31ebf9c48839355574440f63429db", "size": 1717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/reduction.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/reduction.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/reduction.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": 31.2181818182, "max_line_length": 121, "alphanum_fraction": 0.6220151427, "num_tokens": 719, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070035949656, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7678660623277028}}
{"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}{2^n}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\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| \\frac{(n+1)^2}{2^{n+1}} \\cdot \\frac{2^n}{n^2}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\frac{n^2+2n+1}{2^n \\cdot 2} \\cdot \\frac{2^n}{n^2}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\frac{n^2+2n+1}{2n^2}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n^2+2n+1}{2n^2}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{2n+2}{4n}\\quad\\text{by L'hopital}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{2}{4}\\quad\\text{by another L'hopital}\\\\\r\n&= \\frac24=\\frac12\r\n\\end{align*}\r\n\r\nSince $L< 1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^2}{2^n}$ converges absolutely by the Ratio Test.\r\n\r\n\r\n\\subsection*{Solution 2 (outline)}\r\n\r\nThe Root Test will work, but it is a lot of work compared to the solution presented.\r\n\r\n\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "cb8cc0a1e38c13580b42a125db4b417670404571", "size": 1828, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/m8.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/m8.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/m8.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 29.4838709677, "max_line_length": 115, "alphanum_fraction": 0.6126914661, "num_tokens": 716, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938414, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7677740356313426}}
{"text": "\\chapter{Math}\n\n\\begin{eqnarray*}\n\tf(x) = \\sum_{i=0}^{n} \\frac{a_i}{1+x} \\\\\n\t\\textstyle f(x) = \\textstyle \\sum_{i=0}^{n} \\frac{a_i}{1+x} \\\\\n\t\\scriptstyle f(x) = \\scriptstyle \\sum_{i=0}^{n} \\frac{a_i}{1+x} \\\\\n\t\\scriptscriptstyle f(x) = \\scriptscriptstyle \\sum_{i=0}^{n} \\frac{a_i}{1+x}\n\\end{eqnarray*}\n\n\\section{Inline math}\nIn this line is a beautiful formular $e^{i\\pi} + 1 = 0$ \\par\nThis is also inline but special \\[e^{i\\pi} + 1 = 0\\] Do you see it?\n\n\\section{Formulars}\nFor not only mention a formular, you should use that format:\n\n\\begin{equation}\nE=mc^2\n\\end{equation}\n\n\\section{Multiline}\n\nFor long equations\n\\begin{multline}\np(x) = 3x^6 + 14x^5y \\\\+ 590x^4y^2 + 19x^3y^3\n- 12x^2y^4 - 12xy^5 + 2y^6 \\\\- a^3b^3 + a^3 - b^6\n\\end{multline}\n\n\nOr multipart\n\\begin{equation}\n\\begin{split}\nA & = \\frac{\\pi r^2}{2} \\\\\n& = \\frac{1}{2} \\pi r^2\n\\end{split}\n\\end{equation}\n\nOr on another way:\n\n\n\\begin{align}\nx&=y           &  w &=z              &  a&=b+c\\\\\n2x&=-y         &  3w&=\\frac{1}{2}z   &  a&=b\\\\\n-4 + 5x&=2+y   &  w+2&=-1+w          &  ab&=cb\n\\end{align}\n\nWithout alignment:\n\n\\begin{gather} \n2x - 5y =  8 \\\\ \n3x^2 + 9y =  3a + c\n\\end{gather}\n\n\\section{spacing}\n\\begin{align*}\nf(x) =& x^2\\! +3x\\! +2 \\\\\nf(x) =& x^2+3x+2 \\\\\nf(x) =& x^2\\, +3x\\, +2 \\\\\nf(x) =& x^2\\: +3x\\: +2 \\\\\nf(x) =& x^2\\; +3x\\; +2 \\\\\nf(x) =& x^2\\ +3x\\ +2 \\\\\nf(x) =& x^2\\quad +3x\\quad +2 \\\\\nf(x) =& x^2\\qquad +3x\\qquad +2\n\\end{align*}\n\n\\section{Brackets}\n\n\\ldots need to be equalized even with invisible brackets\n\n\\begin{align}\ny  = 1 + & \\left(  \\frac{1}{x} + \\frac{1}{x^2} + \\frac{1}{x^3} + \\ldots \\right. \\\\\n& \\quad \\left. + \\frac{1}{x^{n-1}} + \\frac{1}{x^n} \\right)\t\n\\end{align}\n\n\\section{Units}\n\\SI{24,38176541e4}{m.Pa} \\\\\n\\num{24,38176541e4} \\\\\n\\si{\\kilo\\gram\\metre\\per\\square\\second} \\\\\n\\si{\\gram\\per\\cubic\\centi\\metre}        \\\\\n\\si{\\square\\volt\\cubic\\lumen\\per\\farad} \\\\\n\\si{\\metre\\squared\\per\\gray\\cubic\\lux}  \\\\\n\\si{\\henry\\second} \\\\\n\\SI[mode=text]{1.23}{J.mol^{-1}.K^{-1}}          \\\\\n\\SI{.23e7}{\\candela}                              \\\\\n\\SI[per-mode=symbol]{1.99}[\\$]{\\per\\kilogram}    \\\\\n\\SI[per-mode=fraction]{1,345}{\\coulomb\\per\\mole} \\\\\n\\si[unit-color=blue]{\\highlight{red}\\kilogram\\metre\\per\\second}\n$p=\\SI{24,381}{MPa}$\n\n\\section{list/Range}\n\\numlist{10;30;50;70} \\\\\n\\numrange{10}{30}\\\\\n\\SIlist{10;30;45}{\\metre}\\\\\n\\SIrange{10}{30}{\\metre} \\\\\n\\num[negative-color = red]{-15673}\n\n\\section{Angle}\n\\ang{10}    \\\\\n\\ang{12.3}  \\\\\n\\ang{4,5}   \\\\\n\\ang{1;2;3} \\\\\n\\ang{;;1}   \\\\\n\\ang{+10;;} \\\\\n\\ang{-0;1;}\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "f61a90430c045884010448b81e5cc333164ea558", "size": 2494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/11_math_example.tex", "max_stars_repo_name": "worldpotato/mico_thesis", "max_stars_repo_head_hexsha": "ba460135a4ba1b2a924583cf0473ddf1913a03fe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-08-20T13:19:50.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-20T13:19:50.000Z", "max_issues_repo_path": "content/11_math_example.tex", "max_issues_repo_name": "worldpotato/mico_thesis", "max_issues_repo_head_hexsha": "ba460135a4ba1b2a924583cf0473ddf1913a03fe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2019-11-07T19:58:11.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-07T19:58:11.000Z", "max_forks_repo_path": "content/11_math_example.tex", "max_forks_repo_name": "worldpotato/mico_thesis", "max_forks_repo_head_hexsha": "ba460135a4ba1b2a924583cf0473ddf1913a03fe", "max_forks_repo_licenses": ["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.8771929825, "max_line_length": 82, "alphanum_fraction": 0.5553327987, "num_tokens": 1139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941962904955, "lm_q2_score": 0.8499711680567799, "lm_q1q2_score": 0.7677740231199426}}
{"text": "\\chapter{Quantitative Finance}\n\\label{ch:quantitative-finance}\n\\index{Quantitative Finance}\n\n\\newthought{This section deals with some applications of quantitative finance, \nboth computational and theoretical. }\n\n\\section{Equity Mathematical Models}\n\\index{Equity Mathematical Models}\nEquities and finance are heavily influenced by random events (see \\cite{fooledbyrandomness} for a detailed philosophical discussion). As such, the analysis of financial instruments lends itself to a stochastic process.\n\nA {\\em Geometric Brownian Motion}\\index{Geometric Brownian Motion} (GBM) equation (a form of stochastic differential equation, or SDE known as the Black-Sholes-Merton equation\\cite{pyfinanceoreilly}) can be used to approximate a random process over time. In its continuous form this looks like \\cite{advancedquantcpp}:\n\\begin{equation}\nds = \\mu Sdt+\\sigma SdW\n\\end{equation}\nThis breaks the movement of a stock price down into two key effects:\n\n\\begin{itemize}\n\t\\item a deterministic effect (the left of the plus sign)\n\t\\item a stochastic effect (the right of the plus sign)\n\\end{itemize}\nIn the equation, $\\mu$ is known as {\\it drift}, $\\sigma$ is {\\it volatility}, $S$ is the stock price, $dt$ is the change in time and $dW$ is an increment in a {\\it Weiner process}.\n\nAs equity markets are a discrete process, this equation must be transformed into a discrete equation. \n\\begin{equation}\nS_{t+1}=S_t(1+r\\Delta{}t+\\sigma\\varepsilon_t \\sqrt{\\Delta{}t})\n\\end{equation}\nHere $\\varepsilon$ is a sample from a gaussian distribution with zero mean and standard deviation of 1 (i.e. $N(0,1)$) and $r$ is the risk free rate of return. This equation can be solved iteratively for a given time period if $r$, $\\sigma$, $\\varepsilon$ and $S_0$ are provided.\n\nAnother formulation for pricing European Call options gives a similar result of the discretised SDE\\cite{pyfinanceoreilly}:\n\\begin{equation}\nS_t=S_{t-\\Delta t}e^{(r-\\frac{1}{2}\\sigma^2)\\Delta t+\\sigma\\sqrt{\\Delta t}z_t}\n\\end{equation} \nIn this instance, $z_t$ represents the random variable. Similar formulations can be determined for foreign exchange:\n\\begin{equation}\nX_{t+1} = X_t(1+(r_d-r_f)\\Delta{}t+\\sigma\\varepsilon_t\\sqrt{\\Delta{}t})\n\\label{eq:foreignexchangemodel}\n\\end{equation}\nwhere $r_d$ and $r_f$ are the domestic and foreign fisk free rates of return. \n\n\n\n\\section{Structural and Intensity Models}\n\\TODO See \\cite{advancedquantcpp} chapter 2.\n\n\\section{Monte Carlo Simulation}\n\\index{Monte Carlo Simulation}\nMonte Carlo simulation is a method of estimating a probabilistic outcome through a high quantity of simulations. In a quantitative finance context, we may wish to estimate the future price of an equity based on use of a GBM equation simulated $M$ times. \n\nFor instance the process could be as follows for calculating a call option derivative based on estimate the price of a stock using Monte Carlo simulation:\n\n\\begin{enumerate}\n\t\\item Generate $M$ different ``trajectories'' for the stock using a GBM simulation from time $t=0$ to time $t=T$. This generates a set of $N$ price estimates for $M$ different simulations, with the notation:\n\t\\begin{equation}\n\t\t\\{S_i^j\\}\\qquad i = 0...N,\\qquad j=1...M\n\t\\end{equation}\n\tThis produces a vector of $M$ values for $S_T$, \n\t\\begin{equation}\n\t\t\\{S_T^i\\}\\qquad i = 0...M\n\t\\end{equation}\n\t\n\t\\item We next compute the pay off for each stock value. This is given by \n\t\\begin{equation}\n\t\tH(S_T^i)\\qquad i=1...M\n\t\\end{equation}\n\tWhere \n\t\\begin{equation}\n\t\tH(S_T)=max(S_T-K,0)\n\t\\end{equation}\n\tand $K$ is the actual price of the equity or premium. The expected pay off can then be computed by the average of all pay offs:\n\t\\begin{equation}\n\t\tE[H(S_T^i)]=\\frac{1}{M}\\Sigma_{i=1}^{M}H(S_T^i)\n\t\\end{equation}\n\t\n\t\\item The item should then be discounted to present value, by either applying a discount factor $DF_T$ or \n\t\\begin{equation}\n\t\t\\pi = e^{-rT}\\times E[H(S_T)]\n\t\\end{equation}\n\t\n\tWhere $\\pi$ is the value of the derivative.\n\\end{enumerate}\n\n\n\n\\section{Binomial Trees \\cite{advancedquantcpp}}\n\\index{Binomial Trees}\n\nThis approach builds a tree of possible prices. At each stage, the underlying can be assumed to go up or down by a given amount. The amount of change up ($u$) or down ($d$) is described by\n\\begin{equation}\n\tu=e^{\\sigma\\sqrt{\\Delta{}t}}\n\\end{equation}\n\\begin{equation}\n\td=e^{-\\sigma\\sqrt{\\Delta{}t}}\n\\end{equation}\nThe probability of an equity going up $p$ is\n\\begin{equation}\np=\\frac{e^{r\\Delta{}t}-d}{u-d}\n\\end{equation}\nThe probability of the underlying going down is $1-p$. The binomial tree is then built in the following phases:\n\n\\begin{enumerate}\n\t\\item Construct a tree where each level corresponds to a time step in the simulation period from $t=0$ to $t=T$. For example in two simulation steps, \n\t\\begin{equation}\n\t\tAt = 0, S = S_0\n\t\\end{equation}\n\t\\begin{equation}\n\t\tAt = t_1, S = uS_0,\\qquad dS_0\n\t\\end{equation}\n\t\\begin{equation}\n\t\tAt = t_2, S = u^2S_0,\\qquad udS_0,\\qquad udS_0,\\qquad d^2S_0\n\t\\end{equation}\n\tNote that the central value at the last period is shared between adjacent nodes, hence there are only three distinct estimates after $N=2$ steps.\n\t\n\tThis produces a number of prices at each time step. The notation is based on the estimate number $k$ at time T. There are $N$ time steps\n\t\\begin{equation}\n\t\t\\{S_T^k\\}\\qquad k=1...N+1\n\t\\end{equation}\n\t\n\t\\item Once the tree has been built, the payoff $H(S_T^k)$ should be calculated for each $S_T^k$\n\t\n\t\\item Finally the tree is traversed back up towards the root node, calculating the discounted weighted probability of each node. If we define a given node (not a leaf, i.e. $t\\neq T$) it has two children, one for the up price (denoted $S_T^u$) and one for the down price, $S_T^d$. The value for the parent node is given by \n\t\\begin{equation}\n\tV_{T-1}^k = e^{-r\\Delta{}t}[pH(S_T^u) + (1-p)H(S_T^d)]\n\t\\end{equation}\n\tin this case $V_T^l$ is shorthand for $H(S_T^k)$\n\t\n\t\\item Once the tree has been traversed back to the top, the value of the derivative $\\pi=V_1^1$\n\\end{enumerate}\n\n\n\\section{Finite Difference Method}\n\\index{Finite Difference Method}\n\nThe finite difference method is a method for discretising a differential equation.\\cite{advancedquantcpp} In the quantitative finance approach, we want to discretise partial differential equations (PDEs). The finite differences method is based on the relationship:\n\\begin{equation}\nf(x) = \\frac{df}{dx} \\approx \\frac{\\Delta f}{\\Delta x} = \\frac{f_{i+1}-f_i}{\\Delta x}\n\\end{equation}\nThe most important PDE in finance is the {\\em Black-Scholes PDE}\n\\index{Black-Scholes PDE}, which is given by:\n\\begin{equation}\n\\frac{\\delta V}{\\delta t} + \\frac{1}{2}\\sigma^2S^2\\frac{\\delta^2V}{\\delta S^2}+rS\\frac{\\delta V}{\\delta S}-rV=0\n\\label{eq:blackscholeseq}\n\\end{equation}\nThis is usually solved in the $S$ and $t$ axes, where $S\\in [a,b]$ and $t\\in [0,T]$. The domain of this equation is said to be \n\\begin{equation}\n\\Omega=\\{(S,t)\\forall S\\in [a,b]\\times t\\in [0,T]\\}\n\\end{equation}\nIn other words, as the finite difference method is solving some partial differential equation in $S$ and $t$, the solution space is the rectangular domain defined by the ranges of $S$ and $t$. For a European call, \n\\begin{equation}\n\tV(S,T) = max(S-K,0)\n\\end{equation}\nThe boundary conditions are $V(a,t)=0$ and $V(b,t)=S$. This equation can be transformed with some variable substitution so that \n\\begin{equation}\n\\frac{\\delta u}{\\delta\\tau}=\\frac{\\delta^2 u}{\\delta x}\\qquad -\\infty<x<\\infty, \\tau>0\n\\end{equation}\nThis is a dimensionless PDE with a new solution domain $\\Omega=\\{(x,\\tau)\\}$. The payoff relationship therefore becomes\n\\sidenote{Where $k=\\frac{r}{0.5\\times\\sigma^2}$}\n\\begin{equation}\nu(x,0) = max(e^{\\frac{1}{2}(k+1)x}-e^{\\frac{1}{2}(k-1)x},0)\n\\end{equation}\nUsing finite differences, the return can be described as\\sidenote{Where $\\alpha=\\frac{\\Delta\\tau}{(\\Delta x)^2}$}\n\\begin{equation}\nu_{i,j+1}=\\alpha u_{i+1,j}+(1-2\\alpha)u_{i,j}+\\alpha u_{i-1,j}\n\\end{equation}\nThis relationship can be solved iteratively, using the following steps:\n\n\\begin{enumerate}\n\t\\item Discretise the domain into N space divisions of $dS$ and M time divisions of $dT$. Use these to determine the steps $\\Delta\\tau,\\Delta x$.\n\t\\item Use finite differences to approximate the derivatives\n\t\\item Calculate the results of the equation iteratively for each time step\n\\end{enumerate}\n\nFor a worked example, see \\cite{advancedquantcpp}, end of chapter 3.\n\n", "meta": {"hexsha": "874ea41950cd603de6d4e198721c6e2acb5477bb", "size": 8378, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "quantfinance.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": "quantfinance.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": "quantfinance.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": 47.8742857143, "max_line_length": 324, "alphanum_fraction": 0.734900931, "num_tokens": 2534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213718636754, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7677712008718105}}
{"text": "\n\\subsection{Prior and posterior predictive distributions}\n\n\\subsubsection{Prior predictive distribution}\n\nOur prior predictive distribution for \\(X\\) depends on our prior for \\(\\theta \\).\n\n\\(P(\\mathbf x)=\\int_\\Theta P(\\mathbf x|\\theta)P(\\theta )d\\theta \\)\n\n\\subsubsection{Posterior predictive distribution}\n\nOnce we have calculated \\(P(\\theta |X)\\), we can calculate a posterior probability distribution for \\(X\\).\n\n\\(P(\\mathbf x|\\mathbf X)=\\int_\\Theta P(\\mathbf x|\\theta)P(\\theta |\\mathbf X)d\\theta \\)\n\n", "meta": {"hexsha": "fb68fdb6090b157d80ba1d149e217064aaa28ebc", "size": 505, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/bayesian/01-03-prior.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/bayesian/01-03-prior.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/bayesian/01-03-prior.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.5625, "max_line_length": 106, "alphanum_fraction": 0.7306930693, "num_tokens": 132, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9390248259606259, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7677227323045268}}
{"text": "\n\\subsection{Defining sets by enumeration}\n\nWe can describe a set by the elements it contains.\n\n\\(s=\\{a,b,c\\}\\)\n\nThis is a shorthand way of writing:\n\n\\(\\forall x (x\\in s \\leftrightarrow (x=a\\lor x=b \\lor x=c))\\)\n\n", "meta": {"hexsha": "9e7d99863e52bbae21c09c8f588401cff34e9d6c", "size": 213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/setsSpecification/01-05-enumeration.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/setsSpecification/01-05-enumeration.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/setsSpecification/01-05-enumeration.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.75, "max_line_length": 61, "alphanum_fraction": 0.676056338, "num_tokens": 64, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9648551505674444, "lm_q2_score": 0.7956580927949806, "lm_q1q2_score": 0.7676948089239066}}
{"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\nLet $L$ be a regular language over an alphabet $A$.\nProve that the set of all words $z \\in A^*$ for which there exist $u,v \\in L$ such that $u = zx$ and $v=yz$ for some $x,y \\in A^*$ is a regular language.\n\n\\subsection*{Solution}\n\nWe assume $S_1$ as set of all words $z \\in A^*$ for which there exist $u \\in L$ such that $u=zx$ for some $x \\in K \\subseteq A^*$.\nWe can represent $S_1$ as shown in Equation \\ref{Eq1}.\n\n\\begin{equation}\\label{Eq1}\n\tS_1 = LK^{-1} = \\{z\\in A^* | \\exists x\\in K, zx\\in L\\}\n\\end{equation}\n\nAlso, we assume $S_2$ as set of all words $z \\in A^*$ for which there exists $v \\in L$ such that $v = yz$ for some $y \\in K \\subseteq A^*$.\nWe can represent $S_2$ as shown in Equation \\ref{Eq2}.\n\n\\begin{equation}\\label{Eq2}\n\tS_2 = K^{-1}L = \\{z\\in A^* | \\exists y\\in K, yz\\in L\\}\n\\end{equation}\n\nIt has been proven \\cite{simovici1999theory} that for every language $K$, both the right and the left quotients $LK^{-1}$ and $K^{-1}L$ are regular, if $L$ is a regular language over alphabet $A$.\nBased on this theorem, $S_1$ and $S_2$ would both be regular.\n\nSince any word $z \\in A^*$ for which there exist $u,v \\in L$ such that $u = zx$ and $v=yz$ for some $x,y \\in A^*$ should be an element of $S_1$ and $S_2$, set of all such words will be the intersection of $S_1$ and $S_2$.\nAs regular languages $\\mathcal{R}$ are closed with respect to intersection, it is proven that the desired set is a regular language.\n", "meta": {"hexsha": "84fbee8297154b1430b3f3b9c694b72671c27efc", "size": 1811, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q05.tex", "max_stars_repo_name": "ghorbanzade/beacon", "max_stars_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2019-11-13T20:00:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-01T11:16:51.000Z", "max_issues_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q05.tex", "max_issues_repo_name": "ghorbanzade/beacon", "max_issues_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "umb-cs622-2015f/src/tex/hw02/hw02q05.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 53.2647058824, "max_line_length": 221, "alphanum_fraction": 0.6333517394, "num_tokens": 584, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.767630790694269}}
{"text": "\\addcontentsline{toc}{chapter}{Useful Formulae}\r\n\\chapter*{Useful Formula}\r\n\\begin{itemize}\r\n\t%%%%%%%%%%\r\n\t\\item Equations of a Line:\r\n\\begin{center}\\begin{tabular}{rl}\r\n\t\tpoint $(x_1,y_1)$, slope $m$ form:&$y-y_1 = m(x - x_1)$\\\\\r\n\t\tslope $m$, intercept $b$ form:&$y=mx+b$\r\n\t\\end{tabular}\\end{center}\r\n\t%%%%%%%%%%\r\n\t\\item Quadratic Formula:\r\n\tIf $ax^2+bx+c=0$,\\,$a\\ne0,\\quad$ then $\\displaystyle\\quad x = \\frac{-b\\pm \\sqrt{b^2-4ac}}{2a}$\r\n\t%%%%%%%%%%\r\n\t\\item Sine Law: $\\frac{\\sin A}{a}= \\frac{\\sin B}{b}=\\frac{\\sin C}{c}$; \\hspace{0.2cm}Cosine Law: $a^2=b^2+c^2-2bc\\cos(A)$\r\n\\end{itemize}\r\n{\\hspace*{0.55cm}\r\n\t\t\\renewcommand{\\arraystretch}{1.2}\r\n\t\t\\begin{tabular}{lrclcrcl}\r\n\t\t\t&\\multicolumn{3}{l}{\\phantom{aaaa}$\\bullet$ Logarithms}& &\\multicolumn{3}{c}{$\\bullet$ Exponents}\\\\\r\n\t\t\t\\cmidrule{1-4}\\cmidrule{6-8}\r\n\t\t\tLaw 1: &$ \\log_x(ab) $&$=$&$ \\log_x(a)+\\log_x(b)  $&\\hspace{1cm} &$x^a x^b$&$=$&$x^{a+b} $\\\\\r\n\t\t\tLaw 2: &$ \\log_x\\left(\\frac{a}{b}\\right) $&$=$&$  \\log_x(a)-\\log_x(b) $& &$\\dfrac{x^a}{x^b}$&$=$&$x^{a-b}  $\\\\\r\n\t\t\tLaw 3: &$ \\log_x(a^b) $&$=$&$ b\\cdot\\log_x(a)   $& &$(x^a)^b $&$=$&$x^{ab} $\\\\\r\n\t\t\t\\cmidrule{1-4}\\cmidrule{6-8}\r\n\t\t\t&$  \\log_{x}\\left(\\frac{1}{x^a}\\right) $&$=$&$-a   $& &$x^{-a} $&$=$&$\\frac{1}{x^a} $\\\\\r\n\t\t\t&$ \\log_{x}1  $&$=$&$ 0  $& &$x^0 $&$=$&$1 $\\\\\r\n\t\t\t&$ \\log_x(x) $&$=$&$  1 $& &$x^1 $&$=$&$x $\\\\\r\n\t\t\t\\bottomrule\r\n\t\t\t&$ \\log_a(x) $&$=$&$y$\\hspace{0.5cm} converts to& $\\Leftrightarrow$ &$x $&$=$&$a^y $\\\\\r\n\t\t\t\\bottomrule\r\n\t\t\\end{tabular}\\\\\r\n}\r\n\\newline\\phantom{blank line here please}\\\\\r\n{\\hspace*{0.55cm}\t\r\n\t\\renewcommand{\\arraystretch}{1.2}\r\n\t\t\\begin{tabular}{llll}\r\n\t\t\t\\multicolumn{4}{c}{$\\bullet$ Standard Derivatives}\\\\\\midrule\r\n\t\t\t$f(x)$ & $f'(x)$  &&Notes\\\\ \\midrule\r\n\t\t\t$A$&0&&$A$ is constant\\\\ \r\n\t\t\t$x$&$1$&&power rule for $x^1$\\\\ \r\n\t\t\t$Ax$&$A$&&$A$ is a constant multiple\\\\ \\midrule\r\n\t\t\t$x^n$ & $nx^{n-1}$ &&power rule general form\\\\ \r\n\t\t\t$e^x$ & $e^x$  && exponential\\\\ \r\n\t\t\t$\\ln(x)$ & $\\frac{1}{x}$ &&logarithmic\\\\ \\midrule\r\n\t\t\t$\\sin(x)$ & $\\phantom{-}\\cos(x)$  &&trigonometric \\\\ \r\n\t\t\t$\\cos(x)$ & $-\\sin(x)$ && \\\\ \r\n\t\t\t$\\tan(x)$ & $\\phantom{-}\\sec^2(x)$ && \\\\ \\bottomrule\r\n\t\t\\end{tabular}\r\n}\r\n\\begin{itemize}\r\n\t%%%%%%%%%%\r\n\t\\item Product Rule: $[f(x)g(x)]' = f'(x)g(x) + f(x)g'(x)$\r\n\t%%%%%%%%%%\r\n\t\\item Quotient Rule: $\\displaystyle \\left[\\frac{f(x)}{g(x)}\\right]' = \\frac{f'(x)g(x) - f(x)g'(x)}{[g(x)]^2}$\r\n\t%%%%%%%%%%\r\n\t\\item Chain Rule: $f[g(x)]' = f'[g(x)] \\cdot g'(x)$\r\n\t%%%%%%%%%%\r\n\\clearpage\r\n\\thispagestyle{empty}\r\n\t\t\\renewcommand{\\arraystretch}{1.2}\r\n\t\t\\begin{tabular}{llcl}\r\n\t\t\t\\multicolumn{4}{c}{$\\bullet$ Standard Integrals}\\\\\\midrule\r\n\t\t\t$f(x)$  &  $\\int f(x)dx$&&Notes \\\\ \\midrule\r\n\t\t\t$1$&$x+C$&&constant\\\\\r\n\t\t\t$A$&$Ax+C$&&$A$ is constant\\\\\\midrule\r\n\t\t\t$x^n, n \\neq -1$ & $\\displaystyle\\frac{x^{n+1}}{n+1}+C$&&power rule general form\\\\ \r\n\t\t\t$e^x$ & $e^x+C$&&exponential\\\\ \r\n\t\t\t$\\frac{1}{x}$ & $\\ln|x|+C$&&special case: $x^{-1}$\\\\\r\n\t\t\t$\\ln x$&$x\\ln |x|-x+C$&&natural logarithm: $\\log_e$\\\\\\midrule\r\n\t\t\t$\\sin(x)$ & $-\\cos(x)+C$&& trigonometric \\\\ \r\n\t\t\t$\\cos(x)$ & $\\sin(x)+C$\\\\ \r\n\t\t\t$\\tan (x)$&$\\ln |\\sec x|+C$\\\\\r\n\t\t\t$\\sec^2(x)$ & $\\tan(x)+C$ \\\\ \\bottomrule\r\n\t\t\\end{tabular}\r\n\t%%%%%%%%%%\r\n\t\\item Integration By Parts: $\\displaystyle \\int fg' = fg-\\int f'g \\qquad \\text{or} \\qquad \\int udv = uv - \\int vdu$\r\n\t%%%%%%%%%%\r\n\t\\item Area between the curve $f(x)$ and the $x$-axis: $\\displaystyle A=\\int_{a}^{b} f(x)dx$\\\\\r\n\t%%%%%%%%%%\r\n\t\\item Area between two curves $f(x)$ and $g(x)$: $\\displaystyle A=\\int_{a}^{b} \\left[f(x)-g(x)\\right]dx$\\\\\r\n\t%%%%%%%%%%\r\n\t\\item Volume of revolution about the $x$-axis:\r\n\t$\\displaystyle V= \\int_{a}^{b} \\pi y^2 dx = \\pi\\int_{a}^{b}  [f(x)]^2 dx$\r\n\t\\item Volume of revolution about the $y$-axis:\r\n\t$\\displaystyle V= \\int_{a}^{b} \\pi x^2 dy = \\pi\\int_{a}^{b}  [f(y)]^2 dy$\r\n\\end{itemize}\r\n", "meta": {"hexsha": "09c0879648583397027a791bd9b1c62dc6142aa0", "size": 3775, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "UsefulFormula.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": "UsefulFormula.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": "UsefulFormula.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": 43.3908045977, "max_line_length": 123, "alphanum_fraction": 0.5136423841, "num_tokens": 1710, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046026642944, "lm_q2_score": 0.865224073888819, "lm_q1q2_score": 0.7676307806901117}}
{"text": "\\subsubsection{Cosine}\r\n\\noindent\r\nLet $a$ be a constant.\\\\\r\nBy definitions of a Laplace transform and an improper integral,\r\n\\begin{equation*}\r\n\\Laplace{\\cos{(at)}} = \\lim\\limits_{n\\to\\infty}{\\int_{0}^{n}{\\cos{(at)}e^{-st}\\mathrm{d}t}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t= \\frac{1}{s^2 + a^2}\\lim\\limits_{n\\to\\infty}{\\left[e^{-st}\\left(a\\sin{(at)} - s\\cos{(at)}\\right)\\right]_{0}^{n}}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t = \\frac{1}{s^2 + a^2}\\left(\\lim\\limits_{n\\to\\infty}{\\left(e^{-sn}\\left(a\\sin{sn} - s\\cos{(an)}\\right)\\right)} - \\left(e^{-s\\cdot 0}\\left(a\\sin{(a\\cdot 0)} - s\\cos{(a\\cdot 0)}\\right)\\right)\\right)\r\n\\end{equation*}\r\nBoth $\\sin$ and $\\cos$ have maximum values of 1 and minimum values of -1, so we can way that the left part of the expression has a maximum value of at most $a + s$. For positive $s$, the exponential dominates and the expression goes to 0 in the limit.\r\n\\begin{equation*}\r\n\t = \\frac{1}{s^2 + a^2}\\left(0 + s\\right) \\text{, } s > 0\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t = \\frac{s}{s^2 + a^2} \\text{, } s > 0\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{\\cos{(at)}} = \\frac{s}{s^2 + a^2} \\text{, } s > 0\r\n\\end{equation*}", "meta": {"hexsha": "547682ce5a088e6d9d378629613430a38d035bb9", "size": 1167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/cos.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/laplaceTransforms/derivations/cos.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/laplaceTransforms/derivations/cos.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 48.625, "max_line_length": 252, "alphanum_fraction": 0.6203941731, "num_tokens": 467, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.7676307662462614}}
{"text": "\\chapter{Multigrid Methods and Residual Neural Networks}\nWe are going to investigate the connections and difference between one of the most efficient solvers in numerical PDEs ``Multigrid Methods\" and one of the most successful models ``Residual Neural Networks\" especially for the one of the most updated ResNet \\cite{he2016identity} for computer vision.\n\n\n\n\\section{Multigrid methods}\\label{cs:mg}\n\\subsection{Multigrid methods for numerical PDEs}\n\n\n\nLet us first briefly describe a geometric multigrid method used to\nsolve the following boundary value problem:\n% \\begin{equation}\n%   \\label{laplace}\\left\\{\n%   \\begin{array}{rccl}\n%     -\\Delta u &=& f & \\mbox{ in } \\Omega,\\\\\n%     \\frac{\\partial u}{\\partial n} &=& 0 & \\mbox{ on } \\partial\\Omega,\\\\\n%   \\end{array}\n%   \\right.\\quad \\Omega=(0,1)^2.\n% \\end{equation}\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}\n\n\n\\subsection{Multigrid methods as network}\n\\input{6DL/v-cycle}\n\nWe consider a continuous linear finite element discretization of\n\\eqref{laplace} on a nested sequence of grids of sizes $n_\\ell\\times\nn_\\ell$ with $n_{\\ell-1}=(n_\\ell-1)/2$, as shown in the left part of\nFig. \\ref{fig:V-cycle} and the corresponding sequence of finite\nelement spaces:\n$$\nV_1\\supset V_2\\supset\\cdots\\supset V_J.\n$$\nThe discretized system is\n\\begin{equation}\n\\label{laplace-h}\nAu=f.\n\\end{equation}\nIn correspondence with the two-dimensional grid, here we treat $f\\in \\mathbb R^{n\\times n}$.  We need to find $u\\in \\mathbb R^{n\\times n}$ satisfying \\eqref{laplace-h}.\nHere,  $A:\\mathbb R^{n\\times n}\\mapsto \\mathbb R^{n\\times n}$ is a tensor satisfying\n\\begin{equation}\n\\label{uniform-laplace}\n(Au)_{i,j}=4u_{i,j}-u_{i+1,j}-u_{i-1,j}-u_{i,j+1}-u_{i,j-1},\n\\end{equation}\nwhich holds for $1\\le i,j \\le n$ whereas a slightly different formula holds for\nother $i, j$. Here we notice that, there exist a $3\\times 3$ kernel as\n\\begin{equation}\\label{eq:kernel-A}\nK_A = \\begin{pmatrix}\n0 & -1 & 0 \\\\\n-1 & 4 & -1 \\\\\n0 & -1 & 0\n\\end{pmatrix},\n\\end{equation}\nwith \n$$\nAu = K_A \\ast u.\n$$\nWhere $\\ast$ is the stander convolution operation with zero padding like \\cite{goodfellow2017deep}. \nWe now briefly describe a two-level multigrid method by\na mixed use of the terminologies from deep learning \\cite{goodfellow2017deep} and multigrid methods.\n\nThe first main ingredient in GMG is a smoother.  A commonly used smoother is a\ndamped Jacobi,  which can be written as $S:\\mathbb R^{n\\times n}\\mapsto\n\\mathbb R^{n\\times n}$ satisfying\n\\begin{equation}\n\\label{jacobi1}\n(Sf)_{i,j}={\\omega\\over 4}f_{i,j}.\n\\end{equation}\nIf we apply the Jacobian iteration twice, then\n\\begin{equation}\n\\label{jacobi2}\n(S^2f)_{i,j}\n={1\\over 4}\\omega(2-\\omega)f_{i,j}+{\\omega^2\\over 16}(f_{i+1,j}+f_{i-1,j}+f_{i,j+1}+f_{i,j-1}).\n\\end{equation}\nThen we have \n\\begin{equation}\\label{eq:kernel-S}\nK_S = {\\omega \\over 4},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:kernel-S2}\nK_{S^2} = \\begin{pmatrix}\n0 & \\frac{\\omega^2}{16} & 0 \\\\\n\\frac{\\omega^2}{16} & {\\omega(2-\\omega) \\over 4} & \\frac{\\omega^2}{16}  \\\\\n0 & \\frac{\\omega^2}{16}  & 0\n\\end{pmatrix}\n\\end{equation}\nAnother ingredient is the restriction matrix $R: \\mathbb R^{n_1\\times\n\tn_1}\\mapsto \\mathbb R^{n_2\\times n_2}$, which can be obtained by two\ndifferent steps. First, we carry out a convolution operation $\\tilde\nR: \\mathbb R^{n_1\\times n_1}\\mapsto \\mathbb R^{n_1\\times n_1}$:\n\\begin{equation}\n\\label{linear-restriction}\n(\\tilde Rr)_{i,j}=r_{i,j}+{1\\over 2}(r_{i-1,j}+r_{i+1,j}+r_{i,j-1}+r_{i,j+1}+r_{i-1,j-1}+r_{i+1,j+1}),\n\\end{equation}\nThen, we define\n\\begin{equation}\n\\label{linear-restriction-stride}\n(Rr)_{i,j}=(\\tilde R r)_{2i-1,2j-1}, \\quad 1\\le i, j \\le n_2.\n\\end{equation}\nUsing the terminology from deep learning \\cite{goodfellow2017deep}, \nwe note that \\eqref{linear-restriction} can be written as a\nconvolution with a $3\\times3$ kernel:\n\\begin{equation}\n\\label{convolution}\n\\tilde Rr=K*r,\\quad K=\\left ( \\begin{array}{ccc}\n0 &\\frac{1}{2}&\\frac{1}{2}\\\\\n\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\\frac{1}{2}&\\frac{1}{2}& 0\n\\end{array}\\right ).\n\\end{equation}\nSimilarly, \\eqref{jacobi1} is a convolution with a $1\\times1$ kernel, \n\\eqref{jacobi2} is a convolution with a $3\\times 3$ kernel, and\n\\eqref{linear-restriction} and \\eqref{linear-restriction-stride} is a\nconvolution with a stride. \n\nIn general, we have restriction $R_{\\ell-1}^\\ell:\\mathbb\nR^{n_{\\ell-1}\\times n_{\\ell-1}}\\mapsto R^{n_{\\ell}\\times n_{\\ell}}$ on\nlevel $\\ell$, and the corresponding prolongation is given by\n$P_\\ell^{\\ell-1}=[R_{\\ell-1}^\\ell]^T$.  This restriction gives rise\nto a restriction of $A=A_1$ on the coarse mesh:\n$A_\\ell=R_{\\ell-1}^\\ell A_{\\ell-1}P_\\ell^{\\ell-1}: \\mathbb\nR^{n_\\ell\\times n_\\ell}\\mapsto \\mathbb R^{n_\\ell\\times n_\\ell}$\n($\\ell=2:J$).\n\nUsing the smoother $S$ and restriction $R$ above, a two-level\nmultigrid method for solving \\eqref{laplace-h} can be written as\n$u\\leftarrow u_0, r\\leftarrow f-Au$:\n\\begin{equation}\n\\label{2level}\nu\\leftarrow u+ Sr, \\quad r\\leftarrow f-Au, \\quad u\\leftarrow u+ B_2Rr,\n\\quad r\\leftarrow f-Au, \\quad u\\leftarrow u+S R^Tr.\n\\end{equation}\nIn a two-level setting, we can take $B_2=A_2^{-1}$, or we can apply\n\\eqref{2level} recursively to obtain a multilevel V-cycle.     More\nspecifically, given $u_0\\in V$,  this multilevel V-cycle can be\ndescribed as follows\n\nFrom the fine to the coarse level, \n\\begin{equation}\\label{multi-backslash}\nr_\\ell = F_\\ell (R^\\ell_{\\ell - 1} r_{\\ell-1}), \\quad \nw_\\ell =[(I+S_{\\ell}(I - A_{\\ell} )]R^{\\ell}_{\\ell-1} r_{\\ell-1}\\quad \\ell = 2:J,\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:backslash}\nF_\\ell (x) = x - A_\\ell S_\\ell x, \\quad \\ell = 1:J-1\n\\end{equation}\nwith \n$$\nr_0=f-Au_0, r_1 = F_1(r_0),  F_J(x) = A_J^{-1}x.\n$$ \nFrom the coarse to the fine level, \n\\begin{equation}\\label{multi-slash}\nv_{\\ell-1} = G_{\\ell-1} (P^{\\ell-1}_{\\ell} v_{\\ell}), \\quad \\ell = J:2,\n\\end{equation}\nwhere\n\\begin{equation}\\label{eq:slash}\nG_{\\ell-1} (x) = w_{\\ell-1} + x - S_\\ell A_\\ell x\n\\end{equation}\nwith\n$$\nv_J = r_J = F_J(R^J_{J-1} r_{J-1}).\n$$ \nAn example of a $4$-level ($J=4$) V-cycle is illustrated in\nFig. \\ref{fig:V-cycle}.\n\nIn a more general setting, \\eqref{laplace-h} can be a general linear\nalgebraic system, with a slight abuse of notation here, such that\n$u\\in \\mathbb R^N$ and $A: \\mathbb R^N\\mapsto \\mathbb R^N$.  (In the\nuniform grid case $N=n^2$.)  In this case, the AMG method can still be\nwritten as in \\eqref{2level}, but the smoother and restriction\nmatrices must be designed to maximize the algorithm efficiency.  In\nmultigrid methods, we almost always choose the prolongation\n$P=R^T$. Thus the design of restriction is the same as the design of\nprolongation.  Most of the existing AMG literature focuses on\ndesigning an appropriate prolongation for a given smoother such as the\nJacobi iterative method.  In this proposal, we advance the field by\nalso considering the design of an appropriate smoother for a given\nrestriction.\n\n\n\n\n\n\\section{Convolutional neural networks}\\label{sc:cnn}\nConvolutional neural network, first introduced by LeCun\n\\cite{lecun1998gradient}, has been successfully applied to many\nproblems.  One of the most successful applications is for image\nclassification\n\\cite{lecun1998gradient,krizhevsky2012imagenet,simonyan2014very,he2016deep}.\nHere,  for simplicity of exposition, we introduce CNN for image\nde-noising\n\\cite{NIPS2008_3506,bengio2013generalized,alain2014regularized,xie2012image,zhang2017beyond}.\nWe emphasize that our introduction may not follow the standard\nnotation or terminology used in the deep learning literature. Instead\nwe borrow some notation and terminology from multigrid methods\nfor our descriptions.\n\nGiven an image $x \\in \\mathbb{R}^{n\\times n}$ stained with \nnoise (often assumed to be Gaussian), our goal is to use a deep neural\nnetwork to find a de-noised image such that $ y=f(x, \\Theta) $.  The\nfunction $f$, which depends on a set of parameters $\\Theta$ and can be\nviewed as a vector in $\\mathbb R^{\\mathcal N}$, will be given\nin terms of a convolutional neural network  briefly described\nnext.  The parameter $\\Theta$ can be obtained, for example, by\nsolving the following least squares problem:\n\\begin{equation}  \\label{min-LSQ}\n\\min_{\\Theta\\in\\mathbb R^{\\mathcal N}}\\mathcal L(\\Theta), \\quad\n\\mathcal L(\\Theta)={1\\over N}\\sum_{i=1}^N \\mathcal L_i(\\Theta),\n\\quad \\mathcal L_i(\\Theta)=\n\\|f(x_i,\\Theta)-\\bar x_i)\\|_{F}^2.\n\\end{equation}\nHere, $x_i \\in \\mathbb{R}^{n\\times n}$ ($i=1:N$), often referred to as training\ndata, are images obtained by adding noise to the corresponding\n``clean'' images $\\bar x_i$.\n\nAn image can be viewed as a function defined on a uniform grid.  We\nassume that this uniform grid can be coarsened in a uniform fashion,\nas shown in Fig. \\ref{fig:V-cycle}.  As in multigrid methods, we\ndesignate these grids as multilevel.  Every grid\nrepresents a different level.  This is in contrast with the concept of\n``layers'' in CNN in the deep learning literature\n\\cite{goodfellow2017deep}.  In Fig. \\ref{fig:V-cycle}, the number of\nlevels is $J=4$. A CNN involves operations among different levels of\ngrids together with layers of nonlinear operations within each level\nof grid.\n\nA key ingredient of an artificial neural network is the \nactivation function, which is always nonlinear.  A commonly used\nactivation function is ReLU defined as\n\\begin{equation}\n\\label{ReLU}\n\\sigma(t)=\\max(0,t).\n\\end{equation}\n\n\\subsection{Operations from level to level}\\label{ssc:level}\nGiven an image $x$, we first consider operations from fine to coarse\nlevels as follows:\n\\begin{itemize}\n\t\\item Classical CNN model\n\\begin{equation}\\label{multi-encode-classic}\nf^{\\ell} = F^{\\ell}(R^{\\ell}_{\\ell -1} f^{\\ell-1}), \\quad \\ell=2:J,\n\\end{equation}\n\t\\item ResNet model\n\\begin{equation}\\label{multi-encode}\nf^{\\ell} = R^{\\ell}_{\\ell -1} f^{\\ell-1} + F^{\\ell}(R^{\\ell}_{\\ell -1} f^{\\ell-1}), \\quad \\ell=2:J,\n\\end{equation}\n\\end{itemize}\nwith $f^1 = F^1(x)$, $R^{\\ell}_{\\ell-1}: \\mathbb R^{\\hat\n\tc_{\\ell-1}\\times n_{\\ell-1}\\times n_{\\ell-1}}\\mapsto \\mathbb\nR^{c_\\ell \\times n_{\\ell}\\times n_{\\ell}}$ is a restriction often\ngiven by convolution with stride (or by pooling), and $F^\\ell: \\mathbb\nR^{c_\\ell \\times n_{\\ell}\\times n_{\\ell}}\\mapsto \\mathbb R^{\\hat\n\tc_\\ell \\times n_{\\ell}\\times n_{\\ell}}$ consists of a sequence of\nconvolution and nonlinear activation operations. \\eqref{multi-encode}\nis often referred as an encoding process by convolution.\n\nOperations from coarse to fine levels can be defined similarly:\n\\begin{itemize}\n\t\\item Classical CNN model\n\t\\begin{equation}\\label{multi-decode-classic}\n\tg^{\\ell-1} = G^{\\ell-1}(P^{\\ell-1}_{\\ell}g^{\\ell}), \\quad \\ell=J:2,\n\t\\end{equation}\n\t\\item ResNet model\n\t\\begin{equation}\\label{multi-decode}\n\tg^{\\ell-1} =P^{\\ell-1}_{\\ell}g^{\\ell} + G^{\\ell-1}(P^{\\ell-1}_{\\ell}g^{\\ell}), \\quad \\ell=J:2,\n\t\\end{equation}\n\\end{itemize}\nwith $g^{J} = f^J$.  Here, $P^{\\ell-1}_{\\ell}: \\mathbb R^{c_{\\ell}\n\t\\times n_{\\ell}\\times n_{\\ell}}\\mapsto R^{\\hat n_{\\ell-1}\\times\n\tn_{\\ell-1}\\times n_{\\ell-1}}$ is a prolongation matrix of the same\nsize as the transpose of $R^{\\ell}_{\\ell-1}$ in \\eqref{multi-encode}.\n$G^{\\ell-1}$ consists of a sequence of de-convolution and nonlinear\nactivations.  Further,  \\eqref{multi-decode} is often known as a decoding\nprocess by de-convolution.\n\n\\subsection{Multilayer operations within a given  level}\\label{ssc:layer}\n\n\\subsubsection{Classical CNN model.}\nFor general CNN case, the $F^\\ell$ and $G^\\ell$ are defined for general CNN structure as: $F^\\ell (y^{\\ell,0}) = y^{\\ell, m_\\ell}$ with \n\\begin{equation}\\label{eq:gcnnblock}\ny^{\\ell, j} = \\sigma \\circ \\theta^{\\ell,j}(y^{\\ell,j-1}),\n\\quad j = 1:m_\\ell,\n\\end{equation}\nwhere $y^{\\ell,0} =R^{\\ell}_{\\ell-1} f^{\\ell-1}$. We can have a similar formula for $G^j$ as $y^{\\ell,0} =\nP^{\\ell}_{\\ell+1} g^{\\ell+1}$.\nHere,  one key point is that $\\theta^{\\ell,j}$\nare convolutional operations in the following form:\n\\begin{equation}\\label{eq:conv-1}\n[\\theta^{\\ell,j}(y)]_{i} = \\sum_k^{c^{\\ell,j-1}}K^{\\ell, j}_{i,k} \\ast y_k + b^{\\ell,j}_i \\bm{1} \\in \\mathbb{R}^{n_\\ell \\times n_\\ell}, \\quad i = 1:c_{\\ell,j},\n\\end{equation}\nwhere $\\ast$ denotes the standard convolution operation (see\n\\eqref{linear-restriction} and \\eqref{convolution} for example), and\n$c^{\\ell,j}$ denotes the number of channels or multiple smoothed\n(coarse) spaces in the $j$-th layer in level $\\ell$.\n\n\\subsubsection{New ResNet model.}\nWe now describe a special CNN model using a special form of ResNet\ndeveloped in \\cite{he2016deep,he2016identity};  that is,  we need to\nspecify how $F^\\ell$ and $G^\\ell$ are defined.  Specifically, we can\ndefine $F^\\ell (y^{\\ell,0}) = y^{\\ell, m_\\ell} -  y^{\\ell, 0}$, with\n$y^{\\ell,0} =R^{\\ell}_{\\ell-1} f^{\\ell-1}$ and, \n\\begin{equation}\\label{eq:resblock}\ny^{\\ell, j} = y^{\\ell, j-1} + \\mathcal{F}^{\\ell, j}(y^{\\ell,j-1}),\n\\quad j = 1:m_\\ell.\n\\end{equation}\nHere\n\\begin{equation}\\label{eq:basic}\n\\mathcal{F}^{\\ell,j}(y) = \\xi^{\\ell,j} \\circ \\sigma \\circ \\eta^{\\ell,j}(y),\n\\end{equation}\nas $\\xi^{\\ell,j}$ and $\\eta^{\\ell,j}$ are both general convolutions\nwith multi-channels. There are two observations for the basic structure \\eqref{eq:basic}:\n\\begin{itemize}\n\t\\item $ \\xi \\circ \\sigma \\circ \\eta$ have the universal approximation for any continuous functions in compact sets for general fully connected deep neural networks.\n\t\\item In the V-cycle method, especially for \\eqref{eq:backslash} it is exact the case for \\eqref{multi-encode} with $j=1$ for \\eqref{eq:resblock}.\n\\end{itemize}\n\n\nThe same as general CNN models, we can have a similar formula for $G^j$ as $y^{\\ell,0} =\nP^{\\ell}_{\\ell+1} g^{\\ell+1}$. This shows that, for this kind of model, we do residual for between both levels and layers as:\n\\medskip\n\\begin{table}[!htbp]\n\t\\centering\n\t\\footnotesize\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\hline\n\t\t&level to level & layer to layer  \\\\\n\t\t\\hline\n\t\tIterative Formula  & $f^{\\ell} = R^{\\ell}_{\\ell -1} f^{\\ell-1} + F^{\\ell}(R^{\\ell}_{\\ell -1} f^{\\ell-1})$ & $y^{\\ell, j} = y^{\\ell, j-1} + \\mathcal{F}^{\\ell, j}(y^{\\ell,j-1})$\\\\\n%\t\t\\hline\n%\t\tResidual Form\t & $ F^{\\ell}$ &$y^{\\ell,1} = \\mathcal{F}^{\\ell, 1}(y^{\\ell,0})$ \\\\\n%\t\t\\hline\n%\t\tfeature extractors &smoother (designed a priori) & convolution (trained) \\\\\n%\t\t\\hline\n%\t\tgrid transfer & restriction (designed a priori) & convolution with stride  (trained) \\newline or pooling (given)\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{\\footnotesize A brief comparison between levels and layers.}\n\t\\label{Level-Layes}\n\\end{table}\n\n%So, now all the parameter as collected as\n%\\begin{equation}\\label{para-level}\n%\t\\Theta = \\{\\theta^1, \\cdots, \\theta^J, \\theta^J, \\theta^1\\},\n%\\end{equation}\n%as\n%\\begin{equation}\\label{para-layer}\n%\t\\theta^\\ell = \\{\\eta^{\\ell,0}, \\xi^{\\ell,0}, \\cdots, \\eta^{\\ell,m_\\ell}, \\xi^{\\ell,m_\\ell}\\}.\n%\\end{equation}\n\nIn comparing \\eqref{multi-encode}-\\eqref{multi-decode} for CNN with\n\\eqref{multi-backslash}-\\eqref{eq:slash} for MG and the convolutions\n\\eqref{eq:conv-1} for CNN with the smoother \\eqref{convolution} for\nMG, we note that the CNN model described above is strikingly similar\nto the structure of the V-cycle multigrid method as illustrated by\nFig.~\\ref{fig:V-cycle}.\n\n\nIn our terminology, the number of layers in deep learning literature\nis associated with the total number of applications of the activation\nand is equal to $\\sum_{\\ell=1}^Jm_\\ell$.  Within a given level, the\nnumber of layers can be compared with the number of smoothings used in\nmultigrid methods.\n\n\n\n%CNN used for purpose of de-noising has been studied extensively in the\n%literature, including in\n%\\cite{NIPS2008_3506,bengio2013generalized,alain2014regularized,xie2012image,zhang2017beyond}.\n%We also have performed some experiments of this kind by adding\n%Gaussian noise to a MNIST dataset and then using the aforementioned CNN\n%procedure for de-noising.  The results are remarkably good as observed\n%in many existing studies referenced above, and,  as shown in\n%Fig.~\\ref{noise-denoise} in which the bottom images are the de-noised\n%images of the ones above.\n\n\\section{Connections between multigrid method and CNN}\nWe now offer a comparison between geometric multigrid methods (GMG)\nand convolutional neural networks (CNN).  It is this comparison\nbetween these two distinctive methodologies that motivates much of the\nresearch described in this proposal.  A brief summary of our comparison is\ngiven in Table~\\ref{MG-CNN}.\n\\medskip\n\\begin{table}[!htbp]\n\t\\centering\n\t\\footnotesize\n\t\\begin{tabular}{|l|l|p{40mm}|c|}\n\t\t\\hline\n\t\t&Multigrid &CNN  \\\\\n\t\t\\hline\n\t\tgoals  & linear system solver & image denoising or classification \\\\\n\t\t\\hline\n\t\tstructure\t &multilevel grids with multiple smoothings &multilevel grids with multiple convolutions and activations \\\\\n\t\t\\hline\n\t\tfeature extractors &smoother (designed a priori) & convolution (trained) \\\\\n\t\t\\hline\n\t\tgrid transfer & restriction (designed a priori) & convolution with stride  (trained) \\newline or pooling (given)\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\caption{\\footnotesize A brief comparison between MG and CNN.}\n\t\\label{MG-CNN}\n\\end{table}\n\nFirst we note that MG and CNN are both based on a hierarchy level of\n``grids'' although the notion of a ``grid'' is not often discussed in\nthe CNN literature.   MG is a linear algorithm for solving linear system of equations\nwhereas CNN is a  nonlinear model designed for image de-noising or\nclassification.  On each level, MG uses a given method such as Jacobi or\nGauss-Seidel as a smoother, whereas CNN uses multiple ``channels'' of\nconvolutions.    The similarity here is that a smoother such as the damped\nJacobi can be interpreted as a convolution of the size $1\\times 1$ or\n$3\\times 3$.  The difference between the two methods on this point is\nthat in MG the smoother is designed a priori\nand usually only one smoother is used on each level, whereas in CNN,\nthe convolution is trained and multiple channels of convolutions are\nused.   From fine to coarse (or vice-versa), restriction  matrices are used in both\nmethods, but again the difference remains: the restriction in MG is\ndesigned a priori,  whereas in CNN the restriction is trained (as a\nconvolution with stride) or sometimes is given a priori (by an\noperation called ``pooling'').\n\n\\subsection{V-cycle and U-net}\nIf we compare the V-cycle and new ResNet model, we may mention formula, \nU-net \\cite{ronneberger2015u} structure likes the V-cycle very much. Here we will give more comparison on those two structures. \n%Let us show the U-net model with ResNet structure in mathematically. \n\\subsubsection{Segmentation problem}\nHere we introduce some basic background about segmentation problem.....\n\\subsubsection{Classical U-net model}\nThe U-net was proposed firstly in \\cite{ronneberger2015u} based on the classical CNN model as introduced in \\S \\ref{sc:cnn}. A mathematical expression of this model is:\n\\begin{itemize}\n\t\\item Encode phase\n\t\\begin{equation}\\label{U-multi-encode-classic}\n\tf^{\\ell} = F^{\\ell}(R^{\\ell}_{\\ell -1} f^{\\ell-1}), \\quad \\ell=2:J,\n\t\\end{equation}\n\tfor $f^1 = F^1(x)$ and\n\t$F^\\ell (y^{\\ell,0}) = y^{\\ell, m_\\ell}$ with \n\t\\begin{equation}\\label{u-eq:gcnnblock}\n\ty^{\\ell, j} = \\sigma \\circ \\theta^{\\ell,j}(y^{\\ell,j-1}),\n\t\\quad j = 1:m_\\ell,\n\t\\end{equation}\n\twhere $y^{\\ell,0} =R^{\\ell}_{\\ell-1} f^{\\ell-1}$.\n\t\n\t\n\t\\item Decode phase\n\t\\begin{equation}\\label{U-multi-decode-classic}\n\tg^{\\ell-1} = G^{\\ell-1}([P^{\\ell-1}_{\\ell}g^{\\ell},C^{\\ell-1}f^{\\ell-1}]), \\quad \\ell=J:2,\n\t\\end{equation}\n\tfor $g^{J} = f^J$ and $G^\\ell (y^{\\ell,0}) = y^{\\ell, m_\\ell}$ with \n\t\\begin{equation}\\label{eq:gcnnblock}\n\ty^{\\ell, j} = \\sigma \\circ \\theta^{\\ell,j}(y^{\\ell,j-1}),\n\t\\quad j = 1:m_\\ell,\n\t\\end{equation}\n\twhere $y^{\\ell,0} = [P^{\\ell-1}_{\\ell}g^{\\ell},C^{\\ell-1}f^{\\ell-1}]$. Here $[P^{\\ell-1}_{\\ell}g^{\\ell},C^{\\ell-1}f^{\\ell-1}]$ means to collect the prolongated result $P^{\\ell-1}_{\\ell}g^{\\ell}$ and the rescale cut for $f^{\\ell-1}$ (the dimension reduction for segmentation results) as a new image with double size channels(One comes form $f$ one comes form $g$). \n\\end{itemize}\n\n\n\\subsubsection{Connections between V-cycle and U-net}\n\\begin{itemize}\n\t\\item Structure of coarse and prolongation.\n\t\\item Basic structure in universal approximation theory.\n\t\\item PDE-based model expression.\n\\end{itemize}\n\n\n\\subsubsection{New U-net model motivated by V-cycle}\nNow we proposed a new U-net model as:\n\\begin{itemize}\n\t\\item Encode phase\n\t\\begin{equation}\\label{U-multi-encode}\n\tf^{\\ell} = R^{\\ell}_{\\ell -1} f^{\\ell-1} + F^{\\ell}(R^{\\ell}_{\\ell -1} f^{\\ell-1}), \\quad \\ell=2:J,\n\t\\end{equation}\n\tfor $f^1 = F^1(x)$. \n\t$F^\\ell (y^{\\ell,0}) = y^{\\ell, m_\\ell} -  y^{\\ell, 0}$, with\n\t$y^{\\ell,0} =R^{\\ell}_{\\ell-1} f^{\\ell-1}$ and, \n\t\\begin{equation}\\label{u-eq:resblock}\n\ty^{\\ell, j} = y^{\\ell, j-1} + \\mathcal{F}^{\\ell, j}(y^{\\ell,j-1}),\n\t\\quad j = 1:m_\\ell,\n\t\\end{equation}\n\tfor\n\t\\begin{equation}\\label{u-eq:basic-f}\n\t\\mathcal{F}^{\\ell,j}(y) = \\xi^{\\ell,j} \\circ \\sigma \\circ \\eta^{\\ell,j}(y).\n\t\\end{equation}\n\t\n\t\\item Decode phase\n\t\\begin{equation}\\label{U-multi-decode}\n\tg^{\\ell-1} = C^{\\ell-1}f^{\\ell-1} + P^{\\ell-1}_{\\ell}g^{\\ell} + G^{\\ell-1}(P^{\\ell-1}_{\\ell}g^{\\ell}), \\quad \\ell=J:2,\n\t\\end{equation}\n\tfor $g^{J} = f^J$. \n\t$G^{\\ell-1} (y^{\\ell-1,0}) = y^{\\ell-1, m_{\\ell-1}} - y^{\\ell-1,0}$ with \n\t$y^{\\ell-1,0} = P^{\\ell-1}_{\\ell}g^{\\ell}$\n\t\\begin{equation}\\label{u-eq:rcnnblock}\n\ty^{\\ell-1, j} = y^{\\ell-1, j-1} + \\mathcal{G}^{\\ell-1, j}(y^{\\ell,j-1}),\n\t\\quad j = 1:m_{\\ell-1},\n\t\\end{equation}\n\tfor\n\t\\begin{equation}\\label{u-eq:basic-g}\n\t\\mathcal{G}^{\\ell-1,j}(y) = \\phi^{\\ell-1,j} \\circ \\sigma \\circ \\psi^{\\ell-1,j}(y).\n\t\\end{equation}\n\\end{itemize}\n\n\n\\section{Some general CNN structure motivated by V-cycle}\nHere we will talk about more observations for V-cycle method writing as a ResNet model.\n", "meta": {"hexsha": "3184df570ddb67e62862ee68021e87fd10566bf8", "size": 21735, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgcnn.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/mgcnn.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/mgcnn.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.7013752456, "max_line_length": 365, "alphanum_fraction": 0.7004830918, "num_tokens": 7588, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480666, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7675339094592526}}
{"text": "\\section{3-D DP}\n\n%%%%%%%%%%\n\\begin{frame}{3-D DP}\n  \\begin{exampleblock}{Floyd-Warshall algorithm}\n    \\begin{itemize}\n      \\item subproblem $\\text{dist}[i,j,k]$: the length of the shortest path from $i$ to $j$ via only nodes $v_{1} \\cdots v_{k}$\n      \\item goal: $\\text{dist}[i,j,n], \\forall i,j$\n      \\item question: Is $v_{k}$ in $\\text{ShortestPath}[i,j,k]$?\n      \\item recurrence:\n\t\\fignocaption{width = 0.40\\textwidth}{fig/floyd-warshall.png}\n\t\\[\n\t  \\text{dist}[i,j,k] = \\min \\set{\\text{dist}[i,j,k-1], \\text{dist}[i,k,k-1] + \\text{dist}[k,j,k-1]}\n\t\\]\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{frame}\n", "meta": {"hexsha": "b456f2feadc330b990b9f7877a44e8c05ac0187c", "size": 614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-dp-2016-06-16/sections/3d-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/3d-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/3d-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": 34.1111111111, "max_line_length": 128, "alphanum_fraction": 0.6042345277, "num_tokens": 229, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.933430805473952, "lm_q2_score": 0.8221891283434876, "lm_q1q2_score": 0.7674566603215881}}
{"text": "\\section{Approximation Error}\r\nAlthough knowing these infinite Taylor series is nice, if we want to use them to find function values, we'll need to approximate.\r\nThis means only using some finite number of terms in the Taylor series for our approximation.\r\nBecause we're not using all the terms, we'll naturally have some truncation error.\r\nWe'd like to be able to say how big this truncation error is so we can be sure that our approximation is good enough.\r\n\r\n\\subsection{Alternating Series Estimation Theorem}\r\n\\begin{theorem}[Alternating Series Estimation Theorem]\r\n\tLet $s$ be a convergent, alternating (i.e the sign of each term alternates) series where the terms of $\\abs{s}$ are strictly decreasing.\r\n\tThen the $n$th term truncation error is the same sign as and less than in absolute value the $(n+1)$th term.\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tGive a bound for the truncation error of using the first 10 terms of the Maclaurin series of $\\ln{(1+x)}$ to approximate $\\ln{2}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe Maclaurin series for $\\ln{(1+x)}$ is\r\n\t\\begin{equation*}\r\n\t\t\\ln{(1+x)} = x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\ldots = \\sum_{k=0}^{\\infty}{(-1)^k\\frac{x^{k+1}}{k+1}}, \\abs{x} \\leq 1,\r\n\t\\end{equation*}\r\n\t\r\n\twhich is an alternating series.\r\n\tWe see that to approximate $\\ln{2}$, we'd use $x=1$, which is in the interval of convergence, so the series converges.\r\n\tThe first missing term of the series is $1/11$.\r\n\tLet $s_{10}$ be the partial sum of the first 10 terms when $x=1$.\r\n\tBy the Alternating Series Estimation Theorem,\r\n\t\\begin{equation*}\r\n\t\t0 < \\ln{2} - s_{10} < \\frac{1}{11}. \r\n\t\\end{equation*}\r\n\\end{answer}\r\n\r\n\\subsection{Taylor's Theorem}\r\nAlthough the Alternating Series Estimation Theorem is useful for quickly bounding the error of alternating series, we'd like something that can apply more generally to all Taylor series.\r\n\\begin{theorem}[Taylor's Theorem]\r\n\tLet $f$ be a $k+1$ times differentiable function on an open interval $I$ containing $a$.\r\n\tThen for all $x$ in $I$,\r\n\t\\begin{equation*}\r\n\t\tf(x) = f(a) + f^\\prime(a)(x-a) + \\frac{f^{\\prime\\prime}(a)}{2!}(x-a)^2 + \\ldots + \\frac{f^{(n)}(a)}{n!}(x-a)^n + R_n(x).\r\n\t\\end{equation*}\r\n\twhere\r\n\t\\begin{equation*}\r\n\t\t\\abs{R_n(x)} = \\frac{\\abs{f^{(n+1)}(c)}}{(n+1)!}\\abs{x-a}^{n+1}\r\n\t\\end{equation*}\r\n\tfor some $c$ between $x$ and $a$.\r\n\\end{theorem}\r\n\r\nWe can use this theorem to find the maximum value of $\\abs{R_n(x)}$ over some interval.\r\nWe can also be more precise about what it means for a Taylor series to converge to some function over some interval.\r\n\\begin{definition}\r\n\tLet $R_n(x)$ be the remainder of truncating after the degree $n$ term in the Taylor series for $f$ centered at $x=a$.\r\n\tIf for all $x$ in some interval $I$ containing $a$,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{R_n(x)} = 0,\r\n\t\\end{equation*}\r\n\tthen we say the Taylor series for $f$ at $x=a$ converges to $f$ on $I$.\r\n\\end{definition}\r\n\r\n\\begin{example}\r\n\tShow that the Maclaurin series for $\\sin{x}$ converges to $\\sin{x}$ for all real $x$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe need to find the remainder and show that in the limit it goes to 0 as $n$ grows large.\r\n\tBy Taylor's Theorem,\r\n\t\\begin{align*}\r\n\t\t\\abs{R_n(x)} &= \\frac{\\abs{f^{(n+1)}(c)}}{(n+1)!}\\abs{x-a}^{n+1} \\\\\r\n\t\t&\\leq \\frac{\\abs{x}^{n+1}}{(n+1)!}.\r\n\t\\end{align*}\r\n\t\r\n\tThe numerator is an exponential function, while the denominator is a factorial function, so using $n^n$FEPL,\r\n\t\\begin{align*}\r\n\t\t0 \\leq \\lim_{n\\to\\infty}{R_n(x)} &\\leq \\lim_{n\\to\\infty}{\\frac{\\abs{x}^{n+1}}{(n+1)!}} = 0. \\\\\r\n\t\t\\lim_{n\\to\\infty}{R_n(x)} &= 0.\r\n\t\\end{align*}\r\n\t\r\n\tSo, the Maclaurin series converges to $\\sin{x}$ for all real $x$.\r\n\\end{answer}\r\n\r\n\\subsubsection{Remainder Estimation Theorem}\r\nNotice that we didn't have to actually find the value of $f^{(n+1)}(c)$.\r\nWe just had to find a suitable upper bound where the limit would still go to 0.\r\n\\begin{theorem}[Remainder Estimation Theorem]\r\n\tIf there are positive constants $M$ and $r$ such that\r\n\t\\begin{equation*}\r\n\t\t\\abs{f^{(n+1)}(t)} \\leq Mr^{(n+1)}\r\n\t\\end{equation*}\r\n\tfor all $t$ between $a$ and $x$, then $R_n(x)$ satisfies the inequality\r\n\t\\begin{equation*}\r\n\t\t\\abs{R_n(x)} \\leq M\\frac{r^{n+1}\\abs{x-a}^{n+1}}{(n+1)!}.\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n\\begin{example}\r\n\tGive a maximum error bound for using $\\ln{(1+x)} = x - x^2/2$ when $\\abs{x} \\leq 0.1$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe are using the second-order Taylor polynomial, so we need to find $R_2(x)$.\r\n\tBy Taylor's Theorem,\r\n\t\\begin{align*}\r\n\t\t\\abs{R_2(x)} &= \\frac{\\abs{f^{(2+1)}(c)}}{(2+1)!}\\abs{x-0}^{2+1}  = \\frac{\\abs{f^{(3)}(c)}}{3!}\\abs{x}^3\\\\\r\n\t\tf^{(3)}(x) &= \\dd{^3}{x^3}\\ln{(1+x)} = \\frac{2}{(1+x)^3} \\\\\r\n\t\\end{align*}\r\n\t\r\n\tOn $-0.1 \\leq x \\leq 0.1$, $\\abs{f^{(3)}(x)}$ is maximal at $(-0.1, \\frac{2000}{729})$.\r\n\t\\begin{equation*}\r\n\t\t\\abs{R_2(x)} \\leq \\frac{\\frac{2000}{729}}{6}\\abs{x}^3.\r\n\t\\end{equation*}\r\n\t\r\n\tOn $-0.1 \\leq x \\leq 0.1$, $\\abs{x}^3$ is maximal at $(-0.1, \\frac{1}{1000})$.\r\n\t\\begin{equation*}\r\n\t\t\\abs{R_2(x)} \\leq \\frac{\\frac{2000}{729}}{6}\\frac{1}{1000} = \\frac{1}{2187} \\approx 4.572 \\times 10^{-4}. \r\n\t\\end{equation*}\r\n\t\r\n\tSo, the error of approximating $\\ln{(1+x)}$ with $x-x^2/2$ when $-0.1 \\leq x \\leq 0.1$ is at most $4.572 \\times 10^{-4}$.\r\n\\end{answer}", "meta": {"hexsha": "4e44179cebc9436550fee68b72882fb7cbc59bfa", "size": 5243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/infinite_series/error.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/infinite_series/error.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/infinite_series/error.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.9912280702, "max_line_length": 187, "alphanum_fraction": 0.6450505436, "num_tokens": 1889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.918480237888855, "lm_q1q2_score": 0.767375132960663}}
{"text": "\\subsection{Curvature}\r\nCurvature is 1 divided by the radius of the circle that best approximates the curve at a point.\r\nTighter turns have smaller radii and higher curvature.\r\nWe can use $\\hat{T}$ to find the curvature at a point on $\\vec{r}(t)$.\r\n\\begin{equation*}\r\n\t\\kappa(t) = \\norm{\\dd{\\hat{T}}{s}} = \\norm{\\dd{\\hat{T}}{t}\\left(\\dd{s}{t}\\right)^{-1}} = \\norm{\\dd{\\hat{T}}{t}}\\frac{1}{v(t)}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nFor example, let's find $\\kappa(t)$ for the circle in the yz-plane: $\\vec{r}(t)=\\langle 7, R\\sin{t}, R\\cos{t} \\rangle$.\r\n\\begin{align*}\r\n\t\\vec{r^\\prime}(t) &= \\langle 0, R\\cos{t}, -R\\sin{t}\\rangle\r\n\t\\text{ and }\r\n\tv(t) = \\sqrt{0^2+(R\\cos{t})^2+(-R\\sin{t})^2} = R \\\\\r\n\t\\hat{T}(t) &= \\frac{1}{R}\\vec{r}(t) = \\langle0,\\cos{t},-\\sin{t}\\rangle \\\\\r\n\t\\frac{\\mathrm{d}\\hat{T}}{\\mathrm{d}t} &= \\langle 0,\\sin{t},-\\cos{t}\\rangle \\\\\r\n\t\\norm{\\frac{\\mathrm{d}\\hat{T}}{\\mathrm{d}t}} &= 1 \\\\\r\n\t\\kappa(t) &= \\frac{1}{R}.\r\n\\end{align*}\r\nThis relationship is true for all circles.", "meta": {"hexsha": "2a513ef691d1783cf5d1c2fc8c43f84001938882", "size": 988, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/curvature.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorValuedFunctions/curvature.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorValuedFunctions/curvature.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 49.4, "max_line_length": 127, "alphanum_fraction": 0.5971659919, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7673751230040923}}
{"text": "\n\\subsection{The pseudo-inverse}\n\nThe definition of the inverse  is that:\n\n\\(MM^{-1}=I\\)\n\n\\(M^{-1}M=I\\)\n\nWe also have:\n\n\\(MM^{-1}M=M\\)\n\n\\(M^{-1}MM^{-1}=M^{-1}\\)\n\n\\subsubsection{The inverse of a homomorphism}\n\nGenerally we don't have inverses of homomorphisms as the number of dimensions are different.\n\nWe can, however, find a matrix \\(M^+\\) which satisfies:\n\n\\(MM^+M=M\\)\n\n\\(M^+MM^+=M^+\\)\n\nThis is the pseudo-inverse.\n\n", "meta": {"hexsha": "619541258f048cf7f6aa1a6c7a7099f9021b62a7", "size": 419, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-03-pseudo.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-03-pseudo.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-03-pseudo.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.9642857143, "max_line_length": 92, "alphanum_fraction": 0.6443914081, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195635, "lm_q2_score": 0.8354835309589073, "lm_q1q2_score": 0.7673751229872033}}
{"text": "\\subsection{The Gradient \\& C-Level Curves}\r\n\\noindent\r\nLet $\\vec{r}(t)$ be the C-level curve of $f(x, y)$.\r\n\\begin{align*}\r\nf\\circ\\vec{r} &= C  \\text{ and } \\frac{\\mathrm{d}}{\\mathrm{d}t}(f\\circ\\vec{r}) = 0 \\\\\r\n\t&\\implies \\frac{\\mathrm{d}}{\\mathrm{d}t}(f\\circ\\vec{r}) = \\nabla f\\cdot\\vec{r^\\prime}(t) = 0 \\\\\r\n\t&\\implies \\nabla f\\perp\\vec{r^\\prime}(t) \\\\\r\n\t&\\implies \\nabla f \\text{ is perpendicular to the C-level curve of } f.\r\n\\end{align*}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./Images/differentialMultivariableCalculus/grad_c_level.png}\r\n\t\\caption{The gradient is perpendicular to C-level curves.}\r\n\\end{figure}", "meta": {"hexsha": "a2e29780f4c91ba81868cbc1f909db0e4b5888ef", "size": 653, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/gradientCLevelCurves.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/gradientCLevelCurves.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/gradientCLevelCurves.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": 43.5333333333, "max_line_length": 101, "alphanum_fraction": 0.6600306279, "num_tokens": 249, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096135894201, "lm_q2_score": 0.837619959279793, "lm_q1q2_score": 0.767351697230597}}
{"text": "\\subsection{Osculating Plane/Circle \\& B-Hat $\\left(\\hat{B}\\right)$}\r\n\\noindent\r\nThe osculating plane in the plane containing $\\vec{r}(t)$, $\\hat{T}$ and $\\hat{N}$. It is only defined when $\\hat{N}\\neq 0$. This means straight lines do not have an osculating plane.\r\nThe osculating circle lives in the osculating plane, is centered at $\\vec{r}(t) + \\frac{\\hat{N}(t)}{\\kappa(t)}$, and has radius $\\frac{1}{\\kappa(t)}$.\r\nThe tangent line at $\\vec{r}(t)$ is also tangent to the osculating circle because both points have the same curvature.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{osculating_plane_circle}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.33\\textwidth]{./vectorValuedFunctions/osculatingCircle.png}\r\n\t\\includegraphics[width = 0.33\\textwidth]{./vectorValuedFunctions/osculatingPlane.png}\r\n\t\\caption{Osculating circle and plane}\r\n\\end{figure}\r\n\r\n\\noindent\r\nThe vector that is normal to the plane is \r\n\\begin{equation*}\r\n\t\\hat{B}(t) = \\hat{T}\\times\\hat{N},\r\n\\end{equation*}\r\nwhich is called the ``binormal'' vector because it is perpendicular to both $\\hat{T}$ and $\\hat{N}$.\r\nTogether, $\\hat{T}$, $\\hat{N}$, and $\\hat{B}$ form the Frenet Serret Frame, also called the TNB frame.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{osculating_plane_circle}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.33\\textwidth]{./vectorValuedFunctions/TNB1.png}\r\n\t\\includegraphics[width = 0.5\\textwidth]{./vectorValuedFunctions/TNB2.png}\r\n\t\\caption{TNB frame}\r\n\\end{figure}\r\n\r\n\\noindent\r\nWe can write the equation for the osculating plane as\r\n\\begin{equation*}\r\n\t\\hat{B}(t)\\cdot\\left(\\langle x,y,z\\rangle - \\vec{r}(t)\\right) = 0.\r\n\\end{equation*}", "meta": {"hexsha": "17f9bba3a190251c86bdd9ac1a31753cf9ec1715", "size": 1601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/OsculatingPlaneCircleBHat.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/OsculatingPlaneCircleBHat.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/OsculatingPlaneCircleBHat.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": 45.7428571429, "max_line_length": 184, "alphanum_fraction": 0.7101811368, "num_tokens": 506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389112, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7673468850116921}}
{"text": "\\documentclass{article}\n\\usepackage{amsmath}\n\n\\newcommand{\\flow}{\\rightleftharpoons}\n\n\\begin{document}\n\\title{Typesetting Mathematics in \\LaTeX}\n\\author{Dr. Milaan Parmar \\\\ milaanparmar9@gmail.com}\n\\maketitle\n\n\n\\section{Introduction} \n\\LaTeX\\ is extremely powerful when it comes to typesetting mathematics. It's one of the core strengths of this system. \n\n\\section{Displaying Mathematics}\nThere are two ways of displaying maths. One is \\emph{inline} and the other is \\emph{display} format -- in which the whole math sits on its own set of lines.\n\n\n\\subsection{Inline Mode}\nWe are going to insert a mathematics equation inline here using a pair of \\$ signs:  $E=mc^2$    . As you can see, the display (such as line spacing) does not get messed up by the mathematics as it does with word processing softwares. \n\n\\subsection{Display Mode}\nWe can also display equations in their own set of lines. To do this, we can use the equation environment. \n\n\\begin{equation}\\label{eq:emc}\nE=mc^2\n\\end{equation}\n\nAs you can see, \\LaTeX\\ inserts the equation number automatically. We can refer to it using the \\verb|\\ref| command just as we referred to sections, figures and tables. (E.g. Equation~\\ref{eq:emc}.) To get rid of the equation number, simply use the \\emph{star variant} of the equation environment. (For this, you need the \\texttt{amsmath} package.)\n\n\\begin{equation*}\nE=mc^2\n\\end{equation*}\n\nAlternatively, we can use the shorthand keys \\verb|\\[| and \\verb|\\]|\n\n\\[\nE=mc^2\n\\]\n\n\\section{Mathematical Features}\n\\LaTeX\\ has many builtin features and you can get many more easily. Here, we'll see some of these features: \n\nAddition, subtraction, multiplication and division: \n\n\\[\nx+2 - 25 \\times 35 \\div 98 \n\\]\n\nSuperscripts and subscripts: \n\n\\[ x^2  \\]\n\\[ x_{(i)} \\]\n\n\nSummation, union, intersection, big-union, integral: \n\n\\[ \\sum_{i=1}^{n}{i^2} \\]\n\\[ x \\cup y \\cap z \\]\n\\[ \\bigcup_{i=1}^{n}{x_i} \\]\n\\[ \\int_0^n{x^2} \\]\n\nFractions, brackets, square root: \n\n\\[ \\frac{x}{y} \\]\n\\[ \\frac{\\sum_i{x^2}}{\\int_0^n{x^2}} \\]\n\\[ \\sqrt{\\frac{\\sqrt{36}} {x^5}} \\]\n\n\\[ 2 \\times \\left( \\frac{34}{\\frac{124}{356}}    \\right)  \\]\n\nGreek letters: \n\n\\[\n\\alpha + \\beta + \\gamma^* + \\Sigma + \\Theta + 2_\\epsilon \n\\]\n\nMatrices and vectors. For this, you need to include the \\texttt{amsmath} package and then use the \\texttt{bmatrix} or \\texttt{pmatrix} environment: \n\n\\[\n\\begin{pmatrix}\n\\frac{a}{44} & b \\\\ \nc & \\sqrt{d} \t\n\\end{pmatrix}\n\\]\n\nAccents: \n\n\\[ \\hat{x} \\]\n\\[ \\hat{\\imath} \\] \n\\[ \\dot{x} \\]\n\nSee the \\texttt{Math} menu in the IDE for other operations. You can refer to ``Short Math Guide for \\LaTeX'' for a lot more examples. \n\n\\section{Using Symbols}\nYou might come across situations where you need to find new symbols. For this, you can refer to the ``The Comprehensive \\LaTeX Symbols List''.  \n\n\\[ x \\rightleftharpoons  y \\]\n\n\n\n(Optional) Since this is a long command, we might want to create a shortcut using the \\verb|\\newcommand| command in the preamble. This also allows us to later change the symbol without having to change the equations. \n\n\\[ x \\flow y \\]\n\n\\end{document}", "meta": {"hexsha": "345a5416c84d97081ae31d993f0b13b678a54443", "size": 3064, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "004_LaTex_Typesetting_Mathematics/math-doc.tex", "max_stars_repo_name": "milaan9/LaTeX4Everyone", "max_stars_repo_head_hexsha": "5120a9dd0395ca98894a2468b04673f93fe644b0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 126, "max_stars_repo_stars_event_min_datetime": "2021-08-10T12:23:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T01:23:08.000Z", "max_issues_repo_path": "004_LaTex_Typesetting_Mathematics/math-doc.tex", "max_issues_repo_name": "Wendy729/LaTeX4Everyone", "max_issues_repo_head_hexsha": "14cdf00188d5d12c44a88281c3a40905b4ab0142", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "004_LaTex_Typesetting_Mathematics/math-doc.tex", "max_forks_repo_name": "Wendy729/LaTeX4Everyone", "max_forks_repo_head_hexsha": "14cdf00188d5d12c44a88281c3a40905b4ab0142", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 122, "max_forks_repo_forks_event_min_datetime": "2021-10-16T09:55:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T00:26:09.000Z", "avg_line_length": 29.180952381, "max_line_length": 348, "alphanum_fraction": 0.7000652742, "num_tokens": 930, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339516289534, "lm_q2_score": 0.9136765257642905, "lm_q1q2_score": 0.7672451994906608}}
{"text": "\\chapter{Search}\n\n\\section{Binary Search}\n\\runinhead{Variants:}\n\\begin{enumerate}\n\\item get the idx equal or just lower (floor)\n\\item get the idx equal or just higher (ceil)\n\\item \\pyinline{bisect_left}\n\\item \\pyinline{bisect_right} \n\\end{enumerate}\n\\subsection{idx equal or just lower}\nBinary search, get the idx of the element equal to or just lower than the target. The returned idx is the $A_{idx} \\leq target$. It is possible to return $-1$. It is different from the \\pyinline{bisect_lect}.\n\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item To get ``equal'', \\pyinline{return mid}.\n\\item To get ``just lower'', \\pyinline{return lo-1}.\n\\end{enumerate}\n$A_{idx} \\leq target$.\n\\begin{python}\ndef bin_search(self, A, t, lo=0, hi=None):\n    if hi is None: hi = len(A)\n    \n    while lo < hi:\n        mid = (lo+hi)/2\n        if A[mid] == t:  return mid\n        elif A[mid] < t: lo = mid+1\n        else:            hi = mid\n\n    return lo-1\n\\end{python}\n\\subsection{idx equal or just higher}\n$A_{idx} \\geq target$.\n\\begin{python}\ndef bin_search(self, A, t, lo=0, hi=None):\n    if hi is None: hi = len(A)\n   \n    while lo < hi:\n        mid = (lo+hi)/2\n        if A[mid] == t:  return mid\n        elif A[mid] < t: lo = mid+1\n        else:            hi = mid\n        \n    return lo\n\\end{python}\n\\subsection{bisect\\_left}\nReturn the index where to insert item x in list A. So if t already appears in the list,\nA.insert(t) will insert just before the \\textit{leftmost} t already there.\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item Move \\pyinline{lo} if $A_{mid} < t$\n\\item Move \\pyinline{hi} if $A_{mid} \\geq t$\n\\end{enumerate}\n\n\\begin{python}\ndef bisect_left(A, t, lo=0, hi=None):\n    if hi is None: hi = len(A)\n\n    while lo < hi:\n        mid = (lo+hi)/2\n        if A[mid] < t: lo = mid+1   \n        else:          hi = mid\n\n    return lo\n\\end{python}\n\n\\subsection{bisect\\_right}\nReturn the index where to insert item x in list A. So if t already appears in the list, A.insert(t) will insert just after the \\textit{rightmost} x already there.\n\\runinhead{Core clues:}\n\\begin{enumerate}\n\\item Move \\pyinline{lo} if $A_{mid} \\leq t$\n\\item Move \\pyinline{hi} if $A_{mid} > t$\n\\end{enumerate}\n\\begin{python}\ndef bisect_right(A, t, lo=0, hi=None):\n    if hi is None: hi = len(A)\n\n    while lo < hi:\n        mid = (lo+hi)/2\n        if A[mid] <= t: lo = mid+1\n        else:           hi = mid \n\n    return lo\n\\end{python}\n\\section{Applications}\n\\subsection{Rotation}\n\\runinhead{Find Minimum in Rotated Sorted Array.} Three cases to consider:\n\\begin{enumerate}\n\\item Monotonous \n\\item Trough \n\\item Peak\n\\end{enumerate}\n\nIf the elements can be duplicated, need to detect and skip. \n\\begin{python}\ndef findMin(self, A):\n    lo = 0\n    hi = len(A)\n    mini = sys.maxint\n    while lo < hi:\n        mid = (lo+hi)/2\n        mini = min(mini, A[mid])\n        if A[lo] == A[mid]:  # JUMP\n            lo += 1\n        elif A[lo] < A[mid] <= A[hi-1]:\n            return min(mini, A[lo])\n        elif A[lo] > A[mid] <= A[hi-1]:  # trough\n            hi = mid\n        else:  # peak\n            lo = mid+1\n\n    return mini\n\\end{python}\n\\section{Combinations}\n\\subsection{Extreme-value problems}\\label{extremeValueProblem}\n\\runinhead{Longest increasing subsequence.} Array $A$.\n\nClues:\n\\begin{enumerate}\n\\item \\pyinline{MIN}: \\textit{min} of index \\textit{last} value of LIS of a particular \\textit{len}.\n\\item \\pyinline{RET}: result table, store the $\\pi$'s idx (predecessor); (optional, to build the LIS, no need if only needs to return the length of LIS)\n\\item \\pyinline{bin_search}: For each currently scanning index \\pyinline{i}, if it smaller (i.e. $\\neg$ increasing), to maintain the \\pyinline{MIN}, binary search to find the position to update the min value. The \\pyinline{bin_search} need to find the element $\\geq$ to \\pyinline{A[i]}.\n\\end{enumerate}\n\\newpage\n\\begin{python}\ndef LIS(self, A):\n    n = len(A)\n    MIN = [-1 for _ in xrange(n+1)]\n    \n    l = 1\n    for i in xrange(1, n):\n        if A[i] > A[MIN[l]]:\n            l += 1\n            MIN[l] = i\n        else:\n            j = self.bin_search(MIN, A, A[i], 1, l+1)\n            MIN[j] = i\n\n    return l\n\\end{python}\nIf need to return the LIS itself. \n\\begin{python}\n    for i in xrange(1, n):\n        if A[i] > A[MIN[l]]:\n            l += 1\n            MIN[l] = i\n\n            RET[i] = MIN[l-1]  # (RET)\n        else:\n            j = self.bin_search(MIN, A, A[i], 1, l+1)\n            MIN[j] = i\n\n            RET[i] = MIN[j-1] if j-1 >= 1 else -1  # (RET)\n\n    # build the LIS (RET)\n    cur = MIN[l]\n    ret = []\n    while True:\n        ret.append(A[cur])\n        if RET[cur] == -1: break\n        cur = RET[cur]\n\n    ret = ret[::-1]\n    print ret\n\\end{python}\n\n\\section{High dimensional search}\n\\subsection{2D}\n\\runinhead{2D search matrix I.} $m\\times n$ mat. Integers in each row are sorted from left to right. The first integer of each row is greater than the last integer of the previous row.\n$$\n\\begin{bmatrix}\n1 & 3 & 5 & 7 \\\\\n10 & 11 & 16 & 20 \\\\\n23 & 30 & 34 & 50 \\\\\n\\end{bmatrix}\n$$\n\nRow column search: starting at top right corner: $O(m+n)$.\n\nBinary search: search rows and then search columns: $O(\\log m + \\log n)$.\n\n\n\\runinhead{2D search matrix II.} $m\\times n$ mat. Integers in each row are sorted from\nleft to right. Integers in each column are sorted in ascending from top to bottom.\n$$\n\\begin{bmatrix}\n1&   4&  7& 11& 15 \\\\\n2&   5&  8& 12& 19 \\\\\n3&   6&  9& 16& 22 \\\\\n10& 13& 14& 17& 24 \\\\\n18& 21& 23& 26& 30 \\\\\n\\end{bmatrix}\n$$ \n\nRow column search: starting at top right corner: $O(m+n)$.\n\nBinary search: search rows and then search columns, but upper bound row and lower bound row: \n\n$$O\\big(\\min(n\\log m, m\\log n)\\big)$$\n", "meta": {"hexsha": "7464f9f2fc6b602ffdd5cd84f4b580a461952670", "size": 5681, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterSearch.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": "chapterSearch.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": "chapterSearch.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": 28.405, "max_line_length": 286, "alphanum_fraction": 0.6074634747, "num_tokens": 1840, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7672088785059299}}
{"text": "\\documentclass[]{simple}\n\n\\title{Sum of the Natural Numbers and the Riemann-Zeta Function}\n\\date{January, 2016}\n\\author{Matt McCarthy\\\\\\href{mailto:matthew.mccarthy.12@cnu.edu}{matthew.mccarthy.12@cnu.edu}}\n\n\\addbibresource{naturals-and-zeta.bib}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Introduction}\n\nWe begin by introducing a rather interesting result, namely that the sum of the natural numbers is $-1/12$.\n\\begin{thm}\\label{wrong}\n\t\\[\n\t\t\\sum_{n=1}^\\infty n = -\\frac{1}{12}\n\t\\]\n\\end{thm}\nWe now provide the canonical proof as shown by \\cite{wrong-pf}.\n\\begin{proof}[Proof (\\autoref{wrong})]\n\tDefine $s:=1+2+3+4+\\ldots$, $s_1:=\\sum_{n=0}^\\infty(-1)^n$, and $s_2:=1-2+3-4+\\ldots$.\n\tIf we consider $s_1$, when we stop after an odd number of terms, the partial sum is $1$ but when we stop after an even number of terms, the partial sum is zero.\n\tObviously, the series converges to the average of the two, thus $s_1=1/2$.\n\tConsider $2s_2$.\n\t\\[\n\t\\begin{array}{rrrrrrr}\n\t\t &1 & -2 &+3 &-4&+\\ldots\\\\\n\t\t+&  &1   &-2 &+3&-4&+\\ldots\\\\\\hline\n\t\t &1 &-1  &+1 &-1&+\\ldots\n\t\\end{array}\n\t\\]\n\tSince $2s_2=s_1=1/2$, $s_2=1/4$.\n\tConsider $s-s_2$.\n\t\\[\n\t\t\\begin{array}{rrrrrr}\n\t\t\t&1&+2&+3&+4&+\\ldots\\\\\n\t\t\t-&1&-2&+3&-4&+\\ldots\\\\\\hline\n\t\t\t&0&+4&+0&+8&+\\ldots\n\t\t\\end{array}\n\t\\]\n\tMoreover, we can factor out the four to get $s-s_2=4[1+2+3+\\ldots]=4s$\n\tSolving for $s$ then yields $s=-1/12$ and completes the proof.\n\\end{proof}\n\\begin{analysis}\n\tThe trick to this proof lies in exploiting the commutativity of addition.\n\tBy doing so, we can manipulate the subtraction of two infinite series into a single alternating series.\n\tAfter that step, we then use the Taylor series we found in the lemma to complete the proof.\n\\end{analysis}\n\nNow that we have ``shown'' that the natural numbers sum up to $-1/12$ the only things left to do are show that it is wrong and how this incorrect result came to be so prolific.\n\n\\section{Refutation}\n\nWe begin refuting this result by stating two of the limit laws and by providing the definition of an infinite series.\n\\begin{thm}[Limit Laws]\n\tLet $\\set{x_n}_{n=1}^\\infty$ and $\\set{y_n}_{n=1}^\\infty$ be real-valued sequences that converge to $x$ and $y$ respectively.\n\tThen all of the following hold.\n\t\\begin{enumerate}\n\t\t\\item The sequence $\\set{x_n+y_n}_{n=1}^\\infty$ converges to $x+y$.\n\t\t\\item Let $k\\in\\RR$ then $\\set{k\\cdot x_n}_{n=1}^\\infty$ converges to $k\\cdot x$.\n\t\\end{enumerate}\n\\end{thm}\nThese laws should seem familiar, considering that we used both in our ``proof'' of \\autoref{wrong} however we may have invoked them without respecting their hypotheses.\n\n\\begin{definition}[Infinite Series]\n\tLet $\\set{x_k}_{k=1}^\\infty$ be a sequence of real numbers and let $x\\in\\RR$.\n\tAn \\textit{infinite series} is an expression of the form\n\t\\[\n\t\t\\sum_{k=1}^\\infty x_k=x_1+x_2+\\ldots.\n\t\\]\n\tThe corresponding \\textit{sequence of partial sums} is defined by\n\t\\[\n\t\ts_n:=\\sum_{k=1}^n x_k.\n\t\\]\n\tThe series, $\\sum_{k=1}^\\infty x_k$ \\textit{converges} to $x$ if and only if the sequence $\\set{s_n}_{n=1}^\\infty$ converges to $x$.\n\\end{definition}\nThis definition tells us that an infinite sum exists if and only if the its corresponding sequence of partial sums converges, which leads us to our biggest error: assuming the sum exists.\n\nTo determine whether or not the sum exists, we need to consider the sequence of partial sums,\n\\[\n\ts_n:=\\sum_{k=1}^n k.\n\\]\nIf we inspect the sequence long enough, we see that the sum only increases and is what we call a \\textit{monotone increasing sequence}.\n\\begin{definition}[Monotone Increasing Sequence]\n\tLet $\\set{x_n}_{n=1}^\\infty$ be a real-valued sequence.\n\tWe say $\\set{x_n}$ is \\textit{monotone increasing} if and only if $x_n\\leq x_{n+1}$ for each $n\\in\\NN$.\n\\end{definition}\nIf we consider the $(n+1)$ partial sum, we see\n\\[\n\ts_{n+1}=\\sum_{k=1}^{n+1} k = \\paren{\\sum_{k=1}^{n} k} + (n+1) \\geq \\sum_{k=1}^{n} k=s_n.\n\\]\nThus, $\\set{s_n}$ is a monotone increasing sequence.\n\nSince $s_n$ is monotone increasing, we have a very nice theorem that turns our limit problem into a boundedness problem.\n\n\\begin{definition}[Upper Bound]\n\tLet $\\set{x_n}_{n=1}^\\infty$ be a real valued sequence and let $b\\in\\RR$.\n\tWe say $b$ is an \\textit{upper bound} of $\\set{x_n}$ if and only if $x_n\\leq b$ for each $n\\in\\NN$.\n\tIf any such $b$ exists, we say $\\set{x_n}$ is \\textit{bounded above}.\n\\end{definition}\n\n\\begin{thm}[Monotone Convergence Theorem]\n\tLet $\\set{x_n}_{n=1}^\\infty$ be a real-valued monotone increasing sequence. Then $\\set{x_n}$ converges if and only if $\\set{x_n}$ is bounded above.\n\\end{thm}\n\nWith this theorem in our arsenal, we will now show that this infamous sum does not converge.\n\n\\begin{proposition}\n\tThe sequence defined by\n\t\\[\n\t\ts_n:=\\sum_{k=1}^n k\n\t\\]\n\tis unbounded.\n\\end{proposition}\n\\begin{proof}\nAssume that $s_n$ is bounded above.\nErgo there exists a natural number $N > 0$ such that $s_n:=\\sum_{k=1}^n k \\leq N$ for every $n\\in\\NN$.\nWe know that\n\\[\n\ts_n:=\\sum_{k=1}^n k = \\frac{n(n+1)}{2}.\n\\]\nConsider $s_{2N}$.\n\\[\n\ts_{2N} = \\frac{2N(2N+1)}{2}=N(2N+1)=2N^2+N>N\n\\]\nThe previous statement contradicts our assumption and thus $s_n$ is an unbounded sequence.\n\\end{proof}\n\\begin{analysis}\n\tWe perform a standard contradiction proof.\n\tThe only tricks we use are the fact that\n\t\\[\n\t\t1+2+\\ldots+n=\\frac{n(n+1)}{2}\n\t\\]\n\tand a careful selection of $n$.\n\tEssentially, the proof boils down to picking a candidate for a bound and showing that we have a term in the sequence that is greater than our bound.\n\\end{analysis}\n\nSince $s_n$ is unbounded, by the monotone convergence theorem, $s_n$ does not converge and neither does our sum.\nThus, we cannot invoke limit laws in order to compute $-4s$ and $s-4s$ in our proof of \\autoref{wrong}.\nIn turn, this invalidates our derivation of $-3s$ which destroys the rest of the proof.\n\n\\section{The Riemann-Zeta Function}\n\nTo figure out why people believe this nonsense, we turn to the Riemann-Zeta function.\nHistorically, the Riemann-Zeta function arose as a way to extend the Euler-Zeta function, defined on real numbers greater than 1\n\\[\n\t\\zeta(s)=\\sum_{n=1}^\\infty \\frac{1}{n^s}\n\\]\nto the rest of the complex plane \\cite{edwards}.\nWhen viewed in this light, one may think that\n\\[\n\t\\zeta(-1)=\\sum_{n=1}^\\infty n.\n\\]\nHowever, this is not the case since the Riemann-Zeta function is defined as follows.\n\\begin{definition}[Riemann-Zeta Function from \\cite{edwards}]\n\tThe \\textit{Riemann-Zeta function} is the map $\\zeta:\\CC\\rightarrow\\CC$ defined by the contour integral\n\t\\[\n\t\t\\zeta(s):=\\frac{\\Pi(-s)}{2\\pi i}\\int_\\gamma\\frac{(-x)^s}{(e^x-1)x}dx\n\t\\]\n\twhere $\\gamma$ is a curve that starts at $+\\infty$, moves towards the origin along the positive real axis, circles the origin in a counterclockwise direction, and returns to $+\\infty$ along the positive real axis.\n\tFurthermore, $\\Pi(s)$ is defined as\n\t\\[\n\t\t\\Pi(s):=\\int_0^\\infty e^{-x}x^s dx.\n\t\\]\n\\end{definition}\n\nAs we can see from the definition, this function does not resemble the geometric series in any way.\nHowever, if $s$ is real and greater than $1$ (note: strictly greater than, not greater than or equal to) the zeta function can be written as\n\\begin{equation}\\label{zeta-series}\n\t\\zeta(s)=\\sum_{n=1}^\\infty\\frac{1}{n^s}.\n\\end{equation}\nFurthermore, since $-1$ is less than $1$,\n\\[\n\t\\zeta(-1)\\neq\\sum_{n=1}^\\infty n.\n\\]\n\nAnother interesting property of the Riemann-Zeta function pops up when we let $s$ be a negative integer.\n\\begin{proposition}[From \\cite{edwards}]\n\tFor any natural number $n$,\n\t\\[\n\t\t\\zeta(-n)=(-1)^n\\frac{B_{n+1}}{n+1}\n\t\\]\n\twhere $B_{n+1}$ is the $n+1$th Bernoulli number.\n\\end{proposition}\nBy using this property we get\n\\begin{equation}\\label{zeta-1}\n\t\\zeta(-1)=(-1)\\frac{B_2}{2}=(-1)\\paren{\\frac{1}{6}}\\paren{\\frac{1}{2}}=-\\frac{1}{12}.\n\\end{equation}\n\nVery likely, the incorrect conclusion that $1+2+3+\\ldots=-1/12$ came out of some confusion arising from \\autoref{zeta-series}, \\autoref{zeta-1}, and the history of the zeta function.\n\n\\printbibliography\n\n\\end{document}\n", "meta": {"hexsha": "708e79b310f66fb2ef88e0ff526e5b9f3ec10bc2", "size": 7954, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-spring/sum-of-naturals/naturals-and-zeta.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/sum-of-naturals/naturals-and-zeta.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/sum-of-naturals/naturals-and-zeta.tex", "max_forks_repo_name": "matt-mccarthy/problem-solving", "max_forks_repo_head_hexsha": "8014f517e5290f2904cfb49f3831f05e484d59ec", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.3756345178, "max_line_length": 214, "alphanum_fraction": 0.7034196631, "num_tokens": 2693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683106, "lm_q2_score": 0.9005297881200701, "lm_q1q2_score": 0.7672088762448228}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  True or false? ``Cramer's rule is useful for finding solutions\n    to systems of linear equations in which there is an infinite set\n    of solutions.''\n  \\begin{sol}\n    False. Cramer's rule only works when the coefficient matrix is\n    invertible. In these cases, the solution is always unique.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use Cramer's rule to find the solution to\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+2y=1 \\\\\n      2x-y=2\n    \\end{array}\n  \\end{equation*}\n  \\begin{sol}\n    Solution is: $(x,y) = (1,0)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use Cramer's rule to find the solution to\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+2y+z=3 \\\\\n      2x-y-z=1 \\\\\n      x+z=1\n    \\end{array}\n  \\end{equation*}\n  \\begin{sol}\n    Solution is: $(x,y,z) = (1,1,0)$. For example,\n    \\begin{equation*}\n      y=\\frac{\\begin{absmatrix}{rrr}\n          1 & 3 & 1 \\\\\n          2 & 1 & -1 \\\\\n          1 & 1 & 1\n        \\end{absmatrix}}{\\begin{absmatrix}{rrr}\n          1 & 2 & 1 \\\\\n          2 & -1 & -1 \\\\\n          1 & 0 & 1\n        \\end{absmatrix}}=1\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use Cramer's rule to solve the system of equations\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr}\n      2 & 1 &  1 \\\\\n      2 & 2 & -1 \\\\\n      2 & 1 &  2 \\\\\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z \\\\\n    \\end{mymatrix} =\\begin{mymatrix}{r}\n      3 \\\\\n      -2 \\\\\n      5 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    The solution is $(x,y,z) = (1,-1,2)$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the value of $y$ in the following system of equations:\n  \\begin{equation*}\n    \\begin{mymatrix}{ccc}\n      1 & 1 &  1   \\\\\n      1 & t &  t^2 \\\\\n      1 & s &  s^2 \\\\\n    \\end{mymatrix} \\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z \\\\\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      t \\\\\n      s \\\\\n      1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    By Cramer's rule, we have\n    \\begin{equation*}\n      y = \\frac{\n        \\begin{absmatrix}{ccc}\n          1 & t &  1   \\\\\n          1 & s &  t^2 \\\\\n          1 & 1 &  s^2 \\\\\n        \\end{absmatrix}\n      }{\n        \\begin{absmatrix}{ccc}\n          1 & 1 &  1   \\\\\n          1 & t &  t^2 \\\\\n          1 & s &  s^2 \\\\\n        \\end{absmatrix}\n      }\n      = \\frac{s^3+t^3+1-2-ts^2-t^2}{ts^2+t^2+s-t-st^2-s^2}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "ce9d724233c817fb5724cfc6132fa7a5edb1087f", "size": 2404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-Application-Cramer.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-Application-Cramer.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-Application-Cramer.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 21.6576576577, "max_line_length": 68, "alphanum_fraction": 0.4871048253, "num_tokens": 920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8519528000888387, "lm_q1q2_score": 0.7672088637491524}}
{"text": "\\section{Convergence}\r\nWe have described what it means for a Taylor series to converge to a function over some interval.\r\nWhat if we're given an infinite series that's not a function, just an infinite sum of numbers?\r\nCan we still check if the series converges or diverges?\r\nWe'll develop several tests that we can apply to check for convergence or divergence.\r\n\r\n\\subsection{nth Term Test for Divergence}\r\n\\begin{lemma}\r\n\tLet $a_n$ be the nth term of a series $s$.\r\n\tIf\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{a_n} \\neq 0,\r\n\t\\end{equation*}\r\n\tthen the series diverges.\r\n\\end{lemma}\r\n\\begin{proof}\r\n\tAssume not.\r\n\tLet $a_n$ be the nth term and $s_n$ the nth partial sum of a convergent series $s$ whose terms do not tend to 0.\r\n\tSince $s$ converges to some value $L$, there exists some positive integer $m$ such that for all  $n > m$ and $\\epsilon > 0$,\r\n\t\\begin{equation*}\r\n\t\t\\abs{s_n - L} < \\epsilon.\r\n\t\\end{equation*}\r\n\tWe can also say the same for $s_{n+1}$.\r\n\t\\begin{equation*}\r\n\t\t\\abs{s_{n+1}-L} < \\epsilon.\r\n\t\\end{equation*}\r\n\tSo, subtracting one inequality from the other,\r\n\t\\begin{equation*}\r\n\t\t\\abs{s_{n+1}-s_n} < 2\\epsilon.\r\n\t\\end{equation*}\r\n\tThe difference between the two partial sums is just $a_{n+1}$.\r\n\tSo,\r\n\t\\begin{equation*}\r\n\t\t\\abs{a_{n+1}} < 2\\epsilon.\r\n\t\\end{equation*}\r\n\tSince the terms of $s$ don't tend to 0, there exists some positive integer $h$ and real value $\\delta > 0$ such that for all $n > h$,\r\n\t\\begin{equation*}\r\n\t\t\\abs{a_n} > \\delta.\r\n\t\\end{equation*}\r\n\tWe can also say the same for $a_{n+1}$.\r\n\t\\begin{equation*}\r\n\t\t\\abs{a_{n+1}} > \\delta.\r\n\t\\end{equation*}\r\n\tCombining the two inequalities involving $a_{n+1}$, for all $n > \\max{(m,h)}$,\r\n\t\\begin{equation*}\r\n\t\t\\delta < \\abs{a_{n+1}} < 2\\epsilon.\r\n\t\\end{equation*}\r\n\tHowever, for $\\epsilon \\leq \\delta/2$, the inequality creates a contradiction.\r\n\\end{proof}\r\n\r\nAlthough the proof has to be a bit specific to cover the case of alternating series, the idea behind the test makes sense.\r\nIf you're adding on terms that don't get smaller in absolute value, then you can't ``zero in'' on a particular value and converge.\r\n\r\n\\begin{example}\r\n\tShow that the following series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{(-1)^k} = 1 - 1 + 1 - 1 + \\ldots.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe see that\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{a_n} = \\text{DNE} \\neq 0.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, by the nth Term Test for Divergence, the series diverges.\r\n\\end{answer}\r\n\r\n\\subsection{Geometric Series with $\\abs{r} < 1$}\r\n\\begin{lemma}\r\n\tIf $s$ is a geometric series with common ratio $r$, then $s$ converges if and only if $\\abs{r} < 1$.\r\n\\end{lemma}\r\n\r\nWe already proved this when talking about power series and gave a formula to find its value.\r\n\r\n\\begin{example}\r\n\tShow that the following series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{2^k}{3}}.\r\n\t\\end{equation*}\t\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis is a geometric series with initial term $1/3$ and common ratio $r=2$.\r\n\tSince $\\abs{r} > 1$, the series diverges.\r\n\\end{answer}\r\n\r\n\\subsection{P-Series Test}\r\n\\begin{lemma}\r\n\tThe p-series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{1}{k^p}}\r\n\t\\end{equation*}\r\n\tconverges if and only if $p > 1$.\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tShow that the Harmonic Series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{1}{k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\t\r\n\tThis is a p-series with $p=1$.\r\n\tSo, by the P-Series Test, the sum diverges.\r\n\\end{answer}\r\n\r\n\\subsection{Direct Comparison Test}\r\n\\begin{lemma}\r\n\tLet $s = \\sum_{k=0}^{\\infty}{a_k}$ be a series where all $a_k \\geq 0$.\r\n\t$s$ converges if there exists some convergent series $c = \\sum_{k=0}^{\\infty}{c_k}$ and positive integer $m$ such that for all $n > m$,\r\n\t\\begin{equation*}\r\n\t\tc_n \\geq a_n.\r\n\t\\end{equation*}\r\n\t$s$ diverges if there exists some divergent series $d = \\sum_{k=0}^{\\infty}{d_k}$ and positive integer $m$ such that for all $n > m$,\r\n\t\\begin{equation*}\r\n\t\ta_n \\geq d_n.\r\n\t\\end{equation*}\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tShow that the following series converges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{1}{2 + 3^k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\nWe see that this series looks really similar to a geometric series with common ratio 1/3, just with an extra 2 in the denominator.\r\nFor all $n > 0$,\r\n\\begin{equation*}\r\n\t\\frac{1}{2+3^n} \\leq \\frac{1}{3^n}.\r\n\\end{equation*}\r\n\r\nSo, by the Direct Comparison Test, the series converges.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tShow that the following series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{\\frac{1}{2+\\sqrt{k}}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tAlthough the sum looks like a p-series with $p=1/2$, we can use that series because our series has smaller terms.\r\n\tInstead, we can compare to a p-series where $p=1/2$.\r\n\t\\begin{align*}\r\n\t\t0 \\leq \\frac{1}{n} &\\geq \\frac{1}{2+\\sqrt{n}} \\\\\r\n\t\t0 \\leq 2 + \\sqrt{n} &\\leq n \\\\\r\n\t\tn & \\geq 4.\r\n\t\\end{align*}\r\n\t\r\n\tSo, for all $n \\geq 4$, our series has larger values than the p-series with $p=1$.\r\n\tWe know the p-series diverges by the P-Test, so by the Direct Comparison Test, our series also diverges.\r\n\\end{answer}\r\n\r\n\\subsection{Limit Comparison Test}\r\n\\begin{lemma}\r\n\tLet $a_n$ and $b_n$ be the nth terms of two series $a$ and $b$ that have all positive terms after some point.\r\n\tIf\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{a_n}{b_n}}\r\n\t\\end{equation*}\r\n\tconverges to a finite value greater than 0, then $a$ and $b$ either both converge or both diverge.\r\n\tIf the limit converges to 0 and $b$ converges, then $a$ also converges.\r\n\tIf the limit goes to $\\infty$ and $b$ diverges, then $a$ also diverges.\r\n\\end{lemma}\r\n\r\nA common tactic is to select one of $a$ or $b$ to be a geometric or p-series.\r\n\r\n\\begin{example}\r\n\tShow that the following series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=2}^{\\infty}{\\frac{2k}{k^2-k+a}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tLooking at this rational function, we see a degree 1 term in the numerator and a degree 2 term in the denominator.\r\n\tSo, we might expect that the series behaves similarly to $1/n$.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{2n}{n^2-n+a}}{\\frac{1}{n}}} = \\lim_{n\\to\\infty}{\\frac{2n^2}{n^2-n+a}} = 2.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit converges to a finite value greater than 0, and we know that $1/n$ diverges by the P-Test, then the series must also diverge by the Limit Comparison Test.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tShow that the following series converges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{1}{2^k - 1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis series looks similar to the geometric series $1/2^n$.\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{1}{2^n}}{\\frac{1}{2^n-1}}} = \\lim_{n\\to\\infty}{\\frac{2^n - 1}{2^n}} = 1.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit converges to a finite value greater than 0, and we know that $1/2^n$ converges because it's a geometric series with $r=1/2$, then the series must also converge the the Limit Comparison Test.\r\n\\end{answer}\r\n\r\n\\subsection{Integral Test}\r\n\\begin{lemma}\r\n\tLet $a$ be a sequence of positive terms where $a_n = f(n)$.\r\n\tIf $f$ is continuous, positive after some $m$, and decreasing, then the series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=m}^{\\infty}{a_k}\r\n\t\\end{equation*}\r\n\tconverges if and only if the integral\r\n\t\\begin{equation*}\r\n\t\t\\int_{m}^{\\infty}{f(x)\\d{x}}\r\n\t\\end{equation*}\r\n\tconverges.\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tShow that the following series diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{2k}{k^2+1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe function $f(x)=2x/(x^2+1)$ is continuous, positive for all $x \\geq 1$, and decreasing.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{2x}{x^2+1}\\d{x}} = (u = x^2+1) \\int_{2}^{\\infty}{\\frac{\\d{u}}{u}} = \\ln{u}\\biggr\\rvert_{2}^{\\infty} = \\text{diverges}.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, by the Integral Test, the series also diverges.\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tShow that the following series converges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{1}{k^2+1}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe function $f(x)=1/(x^2+1)$ is continuous, positive for all $x \\geq 1$, and decreasing.\r\n\t\\begin{equation*}\r\n\t\t\\int_{1}^{\\infty}{\\frac{\\d{x}}{x^2+1}} = \\arctan{x}\\biggr\\rvert_{1}^{\\infty} = \\frac{\\pi}{2} - \\frac{\\pi}{4} = \\frac{\\pi}{4}.\r\n\t\\end{equation*}\r\n\t\r\n\tSo, by the Integral Test\\footnote{We omitted evaluating the improper integral with limits, but the value is what you would get from doing that.} the series also converges.\r\n\\end{answer}\r\n\r\n\\subsection{Ratio Test}\r\n\\begin{lemma}\r\n\tLet $a$ be a series with only positive terms after some index.\r\n\tIf the limit\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{a_{n+1}}{a_n}}\r\n\t\\end{equation*}\r\n\tis less than 1, then the series converges.\r\n\tIf the limit is greater than 1, then the series diverges.\r\n\tIf the limit is equal to 1, then the test is inconclusive.\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tState whether the following series converges or diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\frac{k\\ln{k}}{2^k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the limit of the ratio of subsequent terms,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\frac{\\frac{(n+1)\\ln{(n+1)}}{2^{n+1}}}{\\frac{n\\ln{n}}{2^n}}} = \\lim_{n\\to\\infty}{\\frac{(n+1)\\ln{n+1}}{2n\\ln{n}}} = \\lim_{n\\to\\infty}{\\frac{n+1}{2n}} = \\frac{1}{2}.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit is less than 1, the series converges by the Ratio Test.\r\n\\end{answer}\r\n\r\n\\subsection{nth Root Test}\r\n\\begin{lemma}\r\n\tLet $a$ be a series with all positive terms after some index.\r\n\tIf the limit\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\sqrt[n]{a_n}}\r\n\t\\end{equation*}\r\n\tis less than 1, then the series converges.\r\n\tIf the limit is greater than 1, the series diverges.\r\n\tIf the limit is equal to 1, the test is inconclusive.\r\n\\end{lemma}\r\n\r\nThis test is most useful for series that looks like geometric series, but the common ratio is not a constant.\r\n\r\n\\begin{example}\r\n\tState whether the following series converges or diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{\\left(\\frac{k}{2k-1}\\right)^k}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tTaking the limit of the nth root,\r\n\t\\begin{equation*}\r\n\t\t\\lim_{n\\to\\infty}{\\sqrt[n]{\\left(\\frac{n}{2n-1}\\right)^n}} = \\lim_{n\\to\\infty}{\\frac{n}{2n-1}} = \\frac{1}{2}.\r\n\t\\end{equation*}\r\n\t\r\n\tSince the limit is less than 1, the series converges by the nth Root Test.\r\n\\end{answer}\r\n\r\n\\subsection{Alternating Series Test}\r\nAll of the previous 8 tests have tested whether a series converges absolutely.\r\nThat is, all terms in the series could be made positive and the series would still converge or diverge.\r\nThere are some series that do converge but don't converge absolutely.\r\nWe say that these series converge conditionally.\r\nYou've already seen  few, like the formula for $\\pi/4$ using the Maclaurin series for $\\arctan{x}$.\r\nAll series that converge absolutely also converge conditionally.\r\nSeries that converge conditionally do so when they pass the following test.\r\n\r\n\\begin{lemma}\r\n\tThe series\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=0}^{\\infty}{(-1)^ku_k}\r\n\t\\end{equation*}\r\n\tconverges if all of the following conditions are satisfied.\r\n\t\\begin{enumerate}\r\n\t\t\\item All $u_i$ are positive.\r\n\t\t\\item There exists an integer $m$ such that for all $n > m$, $u_{n+1} \\leq u_n$.\r\n\t\t\\item The series of $u$'s pass the nth Term Test.\r\n\t\\end{enumerate}\r\n\\end{lemma}\r\n\r\n\\begin{example}\r\n\tState whether the following series converges or diverges:\r\n\t\\begin{equation*}\r\n\t\t\\sum_{k=1}^{\\infty}{(-1)^k\\frac{1}{k}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{enumerate}\r\n\t\t\\item All the terms $1, 1/2, 1/3, \\ldots$ are positive.\r\n\t\t\\item All terms are less than the previous term.\r\n\t\t\\item The terms tend to 0, passing the nth Term Test.\r\n\t\\end{enumerate}\r\n\t\r\n\tSo, by the Alternating Series Test, the series converges conditionally\\footnote{You've already seen this series too. It converges to $\\ln{2}$.}.\r\n\tNote that the series does not converge absolutely because it fails the P-Test.\r\n\\end{answer}\r\n\r\n\\subsubsection{Riemann Rearrangement Theorem}\r\n\\begin{theorem}[Riemann Rearrangement Theorem]\r\n\tIf an infinite series is conditionally convergent, but not absolutely convergent, then its terms can be rearranged to form a divergent series or to converge to any constant.\r\n\\end{theorem}\r\n\r\nThis result may seem counter intuitive, given that we know addition is associative and commutative.\r\nHowever, the result stems from the fact that we defined convergence of an infinite series at the limit of partial sums.\r\nIf we rearrange terms of the series, the partial sums and their limits can change, meaning the limit of partial sums can diverge or converge to some other value.", "meta": {"hexsha": "af87fe16da62a2e8e7d68d93a02e621809ead073", "size": 12814, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/infinite_series/convergence.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/infinite_series/convergence.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/infinite_series/convergence.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 36.9279538905, "max_line_length": 208, "alphanum_fraction": 0.6783205869, "num_tokens": 4276, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931456, "lm_q2_score": 0.9230391643039738, "lm_q1q2_score": 0.7671775765908179}}
{"text": "\\begin{verbatim}\n\\subsection{Sine functions}\nFor given $x \\in [0, 2\\pi]$ with step size $\\pi/12$, we can obtain the evaluations\nof \\eqref{eq:sine} at $x$ (see Table \\ref{tab:sine}), and the corresponding plot\n(see Figure \\ref{fig:sine}).\n\n\\begin{equation}\n  \\label{eq:sine}\n  \\begin{cases}\n    y_1 = \\sin(x/2) \\\\\n    y_2 = \\sin(x)   \\\\\n    y_3 = \\sin(2x)\n  \\end{cases}\n\\end{equation}\n\\begin{table}[!hbtp]\n\\centering\n\\caption{Sine functions}\n\\label{tab:sine}\n\\begin{tabular}{ccrr}\n\\toprule\n        $x$ & $\\sin(x/2)$ &   $\\sin(x)$ &  $\\sin(2x)$ \\\\\n\\midrule\n$0$      & $0$          & $0$  & $0$ \\\\\n$\\pi/2$  & $\\sqrt{2}/2$ & $1$  & $0$ \\\\\n$\\pi$    & $1$          & $0$  & $0$ \\\\\n$3\\pi/2$ & $\\sqrt{2}/2$ & $-1$ & $0$ \\\\\n$2\\pi$   & $0$          & $0$  & $0$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\\begin{figure}[!hbtp]\n  \\centering\n  \\includegraphics[width=0.3\\textheight]{./fig/sine.pdf}\n  \\caption{Sine functions}\n  \\label{fig:sine}\n\\end{figure}\n\n\\subsection{Goldbach's Conjecture}\nPursuing this type of analysis more carefully, Hardy and Littlewood in 1923 conjectured\n(as part of their famous \\textsl{Hardy–Littlewood prime tuple conjecture}) that for any\nfixed $c \\geq 2$, the number of representations of a large integer $n$ as the sum of $c$\nprimes $n = p_1 + \\cdots + p_{c}$ with $p_1 \\leq \\cdots \\leq p_c$ should be asymptotically\nequal to\n\\begin{equation}\n    \\label{eq:hardy}\n    \\left( \\prod_{p} \\frac{p \\gamma_{c,p} (n)}{(p - 1)^c}\\right)\n    \\int_{2 \\leq x_1 \\leq \\cdots \\leq x_c: x_1 + \\cdots + x_c = n}\n    \\frac{d x_1 \\cdots d x_{c - 1}}{\\ln{x_1} \\cdots \\ln{x_c}},\n\\end{equation}\nwhere the product is over all primes $p$, and $\\gamma_{c, p}(n)$ is the number of\nsolutions to the equation $n = q_1 + \\cdots + q_c \\mod p$ in modular arithmetic,\nsubject to the constraints $q_1, \\ldots, q_c \\ne 0 \\mod p$. This formula\n\\eqref{eq:hardy} has been rigorously proven to be asymptotically valid for\n$c \\geq 3$ from the work of Vinogradov, but is till only a conjecture when $c = 2$.\nIn the latter case, the above formula simplifies to $0$ when $n$ is odd, and to\n$$\n2 \\Pi_2 \\left( \\prod_{p|n; p \\geq 3} \\frac{p - 1}{p - 2} \\right)\n\\int_{2}^{n} \\frac{dx}{(\\ln{x})^2} \\approx 2 \\Pi_2\n\\left( \\prod_{p|n; p \\geq 3} \\frac{p - 1}{p - 2} \\right) \\frac{n}{(\\ln{n})^2},\n$$\nwhen $n$ is even, where $\\Pi_2$ is Hardy-Littlewood's twin prime constant\n$$\n\\Pi_2 := \\prod_{p \\geq 3} \\left( 1 - \\frac{1}{(p - 1)^2} \\right) = 0.6601618158\\ldots\n$$\nThis sometimes known as the \\textsf{extended Goldbach conjecture}.\n\n\\emph{Reference}: \\href{https://en.wikipedia.org/wiki/Goldbach's_conjecture}{Goldbach's conjecture}.\n\\end{verbatim}\n", "meta": {"hexsha": "1b4d5a7b804e625fdf5e590a8a0da8b583856d49", "size": 2619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/Math.3341.Lab.02.Report/LaTeX/latex.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/Math.3341.Lab.02.Report/LaTeX/latex.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/Math.3341.Lab.02.Report/LaTeX/latex.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.9565217391, "max_line_length": 100, "alphanum_fraction": 0.6292478045, "num_tokens": 1034, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.930458253565792, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7671274061544239}}
{"text": "\\begin{thm}[Abstract Bayes' Rule]\n\tLet $\\Pf$ and $\\Pm$ be probability measures on the probability space $(\\Omega, \\F)$ with $\\Pm \\ll \\Pf$ and Radon-Nikod\\'{y}m derivate\n\t\\begin{align}\n\tL = \\frac{ \\dx \\Pm }{ \\dx \\Pf } .\n\t\\end{align}\n\tIf $\\G$ is a sub-$\\sigma$ algebra of $\\F$ and $X$ is integrable $\\G$-measurable random variable, then\n\t\\begin{align}\n\t\\E_{\\Pm} (X| \\G) = \\frac{\\E_{\\Pf} (LX| \\G)}{\\E_{\\Pf} (L| \\G)} .\n\t\\end{align}\n\\end{thm}\n\n\\begin{proof}\n\tFirst we note that\n\t\\begin{align}\n\t\\Pm ( \\E_{\\Pf} (L| \\G) = 0 ) &= \\int \\1_{ \\{ \\E_{\\Pf} (L| \\G) = 0 \\} } \\dx \\Pm \\\\\n\t&= \\int_{ \\{ \\E_{\\Pf} (L| \\G) = 0 \\} } L \\dx \\Pf \\\\\n\t&= \\int_{ \\{ \\E_{\\Pf} (L| \\G) = 0 \\} } \\E_{\\Pf} (L| \\G) \\dx \\Pf \\\\\n\t&= 0\n\t\\end{align}\n\twhich implies that $\\E_{\\Pf} (L| \\G) > 0$. Now we have to prove only that \n\t\\begin{align}\n\t\\E_{\\Pm} (X| \\G) \\E_{\\Pf} (L| \\G) = \\E_{\\Pf} (LX| \\G) .\n\t\\end{align}\n\tIf $G \\in \\G$, then $\\E_{\\Pm} (X| \\G)$ is $\\G$-measurable and thus\n\t\\begin{align}\n\t\\int_G \\E_{\\Pm} (X| \\G) \\E_{\\Pf} (L| \\G) \\dx \\Pf &= \\int_G \\E_{\\Pf} (L \\E_{\\Pm} (X| \\G) | \\G) \\dx \\Pf  \\\\\n\t&= \\int_G L \\E_{\\Pm} (X| \\G)  \\dx \\Pf  \\\\\n\t&= \\int_G \\E_{\\Pm} (X| \\G)  \\dx \\Pm \\\\\n\t&= \\int_G X \\dx \\Pm \\\\\n\t&= \\int_G L X \\dx \\Pf \\\\\n\t&= \\int_G \\E_{\\Pf} (LX | \\G ) \\dx \\Pf .\n\t\\end{align}\n\tand concludes the proof.\n\\end{proof}\n\nIf filtration $(\\F_t)$ consists of sub-$\\sigma$-algebras of $\\F$, then, by Radon-Nikod\\'{y}m-theorem, we have Radon-Nikod\\'{y}m derivates\n\\begin{align}\nL_t = \\frac{\\dx \\Pm}{\\dx \\Pf}\n\\end{align}\nwith respect to $\\sigma$-algebra $\\F_t$ for all $t \\geq 0$. By equation \\ref{Radon-Nikodymderivateconditional},\n\\begin{align}\nL_t = \\E_{\\Pf} ( L_s | \\F_t )\n\\end{align}\nfor $0 \\leq t < s$ implying that $(L_t)$ is a martingale with respect to the filtration $(\\F_t)$. The process $(L_t)$ is called likelihood-process.\n\nAbstract Bayes' rule and the fact $\\E_{\\Pf} (L_t) = 1$ implies the following theorem.\n\n\\begin{thm}\n\tLet $\\Pf$ and $\\Pm$ be probability measures with $\\Pm \\ll \\Pf$ and Radon-Nikod\\'{y}m derivate\n\t\\begin{align}\n\tL = \\frac{ \\dx \\Pm }{ \\dx \\Pf } .\n\t\\end{align}\n\tNow the process $(X_t)$ is $\\Pm$-martingale if and only if $LX_t$ is $\\Pf$-martingale, where $L$ is the likelihood-process.\n\\end{thm}\n\n\\subsection{A consequence of Radon-Nikod\\'{y}m-theorem}\n\nIf $\\G$ is a sub-$\\sigma$-algebra of $\\F$, then Radon-Nikod\\'{y}m-derivates $L_{\\G}$ and $L_{\\F}$ of $\\Pf$ with respect to $\\Pm$ need not be equal as $L_{\\F}$ may not be $\\G$-measurable. However, we know that for every $G \\in \\G$\n\\begin{align}\n\\int_G \\E_{\\Pf} ( L_{\\F} | \\G ) \\dx \\Pf = \\int_G L_{\\F} \\dx \\Pf = \\Pm (G)\n\\end{align}\nmeaning that \n\\begin{align}\nL_{\\G} = \\E_{\\Pf} ( L_{\\F} | \\G ) .\n\\end{align}\n\nThus we have proved the following.\n\n\\begin{lemma}\n\tIf $\\Pm \\ll \\Pf$ and $\\G$ is a sub-$\\sigma$-algebra of $\\F$, then\n\t\\begin{align}\n\t\\label{Radon-Nikodymderivateconditional}\n\tL_{\\G} = \\E_{\\Pf} ( L_{\\F} | \\G ) ,\n\t\\end{align}\n\twhere $L_{\\G}$ is Radon-Nikod\\'{y}m-derivate of $\\Pf$ with respect to $\\Pm$ and filtration $\\G$ and $L_{\\F}$ is Radon-Nikod\\'{y}m-derivate of $\\Pf$ with respect to $\\Pm$ and filtration $\\F$.\n\\end{lemma}\n\nLet $\\Pm$ and $\\Pf$ be equivalent measures with a filtration $(\\F_t)$. W define a density process by\n\\begin{align}\n\\Lambda_t = \\E_{\\Pf} \\left( \\frac{\\dx \\Pm}{\\dx \\Pf} \\ | \\ \\F_t \\right)\n\\end{align}\nNow\t\n\\begin{align}\n\\E_{\\Pf} \\left( \\Lambda_T \\ | \\ \\F_t \\right) &= \\E_{\\Pf} \\left( \\E_{\\Pf} \\left( \\frac{\\dx \\Pm}{\\dx \\Pf} \\ | \\ \\F_T \\right) \\ | \\ \\F_t \\right) \\\\\n&= \\E_{\\Pf} \\left( \\frac{\\dx \\Pm}{\\dx \\Pf} \\ | \\ \\F_t \\right) \\\\\n&= \\Lambda_t\n\\end{align}\nfor all $0 \\leq t \\leq T$ meaning that $\\Lambda_t$ is a martingale. Also\n\\begin{align}\n\\Lambda_0 = \\E_{\\Pf} \\left( \\frac{\\dx \\Pm}{\\dx \\Pf} \\ | \\ \\F_0 \\right)\n\\end{align}\t", "meta": {"hexsha": "3646ea1153d09feef6c308131c94be7d6ee580d2", "size": 3707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "poistettuja.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": "poistettuja.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": "poistettuja.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": 40.7362637363, "max_line_length": 229, "alphanum_fraction": 0.5810628541, "num_tokens": 1670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505376715775, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7671144833310678}}
{"text": "\\section*{Problem 2 Solution}\n\n\\begin{enumerate}[a)]\n\n\\item \n\nThe transmitted uncollided intensity of a neutron beam through a material with macroscopic cross section $\\Sigma$ is given by\n$$ I = I(0) \\, e^{-\\Sigma x} .$$\nSolving for $\\Sigma$, we find \n$$ \\Sigma = \\frac{1}{x}\\ln\\left(\\frac{I(0)}{I}\\right) $$\nUsing the values provided (and considering the intensity as per the target, rather than per cm$^2$), we have\n$$ \\Sigma = \\frac{1}{10\\text{ cm}}\\ln\\left(\\frac{2\\times10^{12}\\text{ neutrons/(cm}^2{\\cdot}\\text{s)}\\left( 5\\text{ cm}^2 \\right)}{3.0\\times10^9\\text{ neutrons/s}}\\right) $$\n$$ \\Sigma = \\frac{1}{10\\text{ cm}}\\ln\\left(3.33\\times10^{3}\\right) $$\n$$\\boxed{ \\Sigma = 0.811\\text{ cm}^{-1} }$$\n\n\\item \n\nThe mean free path of a particle is defined as $\\lambda \\equiv \\frac{1}{\\Sigma}$. \n$$\\boxed{ \\lambda = 1.233\\text{ cm} }$$\n\n\\item \n\nWe are told that the beam pulse is 10 $\\mu$s, so when considered in conjunction with the known intensity of the neutron beam, we can find the total number of particles produced by the beam per area. We define the neutron fluence, $\\Phi$, as the number of neutrons per cm$^2$, calculated as\n$$ \\Phi = It = (2\\times10^{12}\\text{ neutrons/(cm}^2\\cdot\\text{s)})(10^{-5}\\text{ s}) = 2\\times10^7\\text{ neutrons/cm}^2 $$\nThe number of interactions, $R$, is \n$$ R = \\Phi \\Sigma V $$\nwhere $\\Phi$ is the incident neutron fluence in $\\left[\\frac{\\text{neutrons}}{\\text{cm}^2}\\right]$, $\\Sigma$ is the macroscopic cross section of the shielding material in $\\left[\\frac{1}{\\text{cm}}\\right]$, and $V$ is the volume of the shield in $\\left[{\\text{cm}^3}\\right]$. \n\nWe have already found $\\Phi$, we calculated $\\Sigma$ in part (a), and we can determine $V$ by multiplying the area of the beam spot by the thickness of the target.\n$$ V = 5\\text{ cm}^2 \\times 10\\text{ cm} = 50\\text{ cm}^3 $$\nThe total number of collisions is then\n$$ R = (2\\times10^7\\text{ cm}^{-2})(0.811\\text{ cm}^{-1})(50\\text{ cm}^3) $$\n$$\\boxed{ R = 8.11\\times10^8\\text{ collisions} }$$\n\\end{enumerate}\n\n", "meta": {"hexsha": "93a8a30bd033cb52e85511069707243bffc44af2", "size": 2009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc04/disc04_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/disc04/disc04_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/disc04/disc04_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": 55.8055555556, "max_line_length": 289, "alphanum_fraction": 0.6615231458, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7671144746116286}}
{"text": "In this section we will study the limitations of our previous encoding of natural numbers. We will then use a positional system (the simplest of which is binary numbers) to show a much more efficient conversion process.\n\n\\subsection{Performance considerations of unary encoding}\nLet us begin with an analysis of how long it takes to perform addition of two Peano numbers. Let us assume that the cost of building or decomposing terms is $O(1)$, since it can be implemented with a constant number of low-level operations such as memory allocation, runtime type checks, and similar, but it does not require recursion or iteration. Consider addition between two numbers $n + m$ with the rules:\n\n\\begin{lstlisting}\n----------- r0\nz + a => a\n\na + b => c\n----------------- r1\ns(a) + b => s(c)\n\\end{lstlisting}\n\nWe have two alternatives that clearly only depend from $n$ ($m$ does not have influx on the number of operations, since it is just returned directly as the last step): either $n=0$, or $n=n'+1$. In case of $n=0$, then rule \\texttt{r0} is used, producing a result directly. This means that the number of steps $T$ performed by the system is:\n\n$$T(n) = 1 \\text{ when } n=0$$\n\nIn the case of $n=n'+1$, then rule \\texttt{r1} is used. Evaluating rule \\texttt{r1} requires first evaluating the expression $n'+m$\\footnote{Note that this again an application of \\textit{induction}, albeit less formal}, and then performing a single operation which is the addition of the \\texttt{s} keyword to intermediate result \\texttt{c}:\n\n$$T(n) = T(n') + 1 = T(n-1) + 1 \\text{ when } n=n'+1$$\n\nThis means that the system will perform exactly $n+1$ computation steps, therefore having a complexity of $O(n)$ where $n$ is the value of the first number. This is highly inefficient.\n\n\\subsection{Binary encoding}\nLet us consider positional encoding. Specifically, let us consider binary encoding (base 2 encoding). We will define a binary number as a series of binary digits, which are either zero or one:\n\n\\begin{lstlisting}\nData [] \"d0\" [] Priority 0 Type Digit\nData [] \"d1\" [] Priority 0 Type Digit\n\\end{lstlisting}\n\nThe binary number itself is defined as a digit, followed by the rest of the number. We will use the comma operator to specify this separation:\n\n\\begin{lstlisting}\nData [Num] \",\" [Digit] Priority 10 Type Num\n\\end{lstlisting}\n\nOf course numbers need to end at some point\\footnote{not in real life, where we could simply assume an infinite sequence of zero's, but in a computer with limited memory this simplification is ubiquitous}, so we define a special symbol that represents the ``end of list'' number:\n\n\\begin{lstlisting}\nData [] \"nil\" [] Priority 0 Type Num\n\\end{lstlisting}\n\nA number such as $3 = 011$ would then be expressed as \\texttt{(((nil,d0),d1),d1)}. Notice that we associate the digits to the left, so that the first digit we encounter is the one of the lowest order. This is not strictly necessary, but it makes it easier to extract the digits in order of significance, and this in turns simplifies the traditional definition of addition.\n\n\n\\subsection{Addition}\nTo add two numbers, we will encode the well-known process of adding numbers with a \\textit{carry}. This means that we will add, repeatedly, three digits at a time: the first two digits of the numbers that we are adding, plus the carry that comes from the previous addition of digits. We now define this sum of digits:\n\n\\begin{lstlisting}\nFunc [] \"addDigits\" [Digit Digit Digit] Priority 5 Type Expr => Num\n\\end{lstlisting}\n\nWe have eight instances of \\texttt{addDigits}, one for each possible combination of digits (each digit has two possible values, \\texttt{d0} and \\texttt{d1}, thus we have $2^3$ total combinations). For each such combination, we directly return the sum of the three digits in the format of a two-digit binary number. We need no more than two digits for the result, since the maximum number we will need to return is the sum of \\texttt{d1} three times:\n\n\\begin{lstlisting}\n----------------------------------\naddDigits d0 d0 d0 => (nil,d0),d0\n\n----------------------------------\naddDigits d0 d0 d1 => (nil,d0),d1\n\n...\n\n----------------------------------\naddDigits d1 d1 d1 => (nil,d1),d1\n\\end{lstlisting}\n\nAddition with carry performs the digit addition of the current digits of the numbers being added, plus the current carry. The two resulting digits are the lower-order unit of the result, together with the carry that will be used to add together the remaining bits of the input numbers. The function that recursively adds the digits is \\texttt{addCarry}:\n\n\\begin{lstlisting}\nFunc [] \"addCarry\" [Num Num Digit] Priority 5 Type Expr => Num\n\\end{lstlisting}\n\n\\begin{lstlisting}\naddDigits da db dr => (nil,dr',d)\naddCarry a b dr' => res\n----------------------------------\naddCarry a,da b,db dr => res,d\n\\end{lstlisting}\n\nOf course addition ends when it encounters the end of the numbers, which needs to be accompanied with a null carry:\n\n\\begin{lstlisting}\n--------------------------\naddCarry nil nil d0 => nil\n\\end{lstlisting}\n\nWe might even add an \\texttt{overflow} keyword and graciously handle the case of non-null last carry as follows:\n\n\n\\begin{lstlisting}\n--------------------------------\naddCarry nil nil d1 => overflow\n\\end{lstlisting}\n\nThe first step of addition simply instances \\texttt{addCarry} with a null initial carry:\n\n\\begin{lstlisting}\naddCarry a b d0 => c\n--------------------\na + b => c\n\\end{lstlisting}\n\nMultiplication follows a similar scheme, and as such we will not give it here. Also, notice that we only support numbers of the same length. Supporting addition of numbers of different lengths would be relatively trivial, and as such is also not shown here.\n\n\n\\subsection{Performance considerations of binary encoding}\nBinary encoding allows us to perform operations much faster, that is with less rules used when compared with Peano addition. Remember that Peano addition took a significant $O(n)$ amount of operations to perform, with $n$ being the value of the first operand.\n\nConsider only the rule which performs a single step of the binary addition:\n\n\\begin{lstlisting}\naddDigits da db dr => (nil,dr',d)\naddCarry a b dr' => res\n----------------------------------\naddCarry a,da b,db dr => res,d\n\\end{lstlisting}\n\n\\texttt{addDigits} is just one single step, in that it directly resolves the parameters and returns the appropriate result. The only thing that matters for the purpose of the complexity of \\texttt{addCarry} is the recursive call. Let us observe that the recursive call \\texttt{addCarry a b dr'} uses \\texttt{a} and \\texttt{b} as input numbers, whereas the original addition \\texttt{addCarry a,da b,db dr} used \\texttt{a,da} and \\texttt{b,db}, which are precisely equal to \\texttt{a} and \\texttt{b}, but with the additional digits \\texttt{da} and \\texttt{db} respectively. What is the relationship between \\texttt{a} and \\texttt{a,da}? Simply enough, we know that \\texttt{a} is \\texttt{a,da} divided by two. In general, removing the least-significant digit in a number encoded in base $b$ is equivalent to dividing the number by $b$ itself. Consider the following examples of removal of a least-significant digit:\n\n$\\begin{array}{c c c}\n  110 / 2 & = & 11 \\\\\n  111 / 2 & = & 11 \\\\\n  1000 / 2 & = & 100\n\\end{array}$\n\nThis happens because a number $n$ in an arbitrary base $b$ is decomposed into:\n\n$$d_m \\times b^m \\dots + d_2 \\times b^2 + d_1 \\times b^1 + d_0 \\times b^0$$\n\nRemoving one digit decreases all powers of $b$, resulting in:\n\n$$d_m \\times b^{m-1} \\dots + d_2 \\times b^{2-1} + d_1 \\times b^{1-1}$$\n\nwhich is precisely equal to the original number divided by $b$.\n\n\nWhen there are no more digits, it means that the number has been divided by the base ($2$ for our binary numbers) enough times to render the highest coefficient null. If the original number was $n$, we will have stopped only after $k$ steps such that $\\frac{n}{2^k} = 0$. The smallest solution to this is actually well known, and is $k = \\log_2 n$. This leads us to the conclusion that the complexity of this method of addition is $O(\\log n)$, which is significantly faster than $O(n)$. As a way of comparison, assume that we are computing the sum $1000000 + 1000000$: the Peano addition will take about $1000000$ steps, whereas binary addition will take about $6$.\n", "meta": {"hexsha": "126eabf93f2cb50025dfcca5ca8db029cf8e17ae", "size": 8281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/binary_numbers.tex", "max_stars_repo_name": "vs-team/metacompiler", "max_stars_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2015-12-13T09:22:28.000Z", "max_stars_repo_stars_event_max_datetime": "2018-03-03T21:48:11.000Z", "max_issues_repo_path": "Course materials/Dictaat/tex/Examples/binary_numbers.tex", "max_issues_repo_name": "cult-of-giuseppe/metacompiler", "max_issues_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2015-08-14T06:48:43.000Z", "max_issues_repo_issues_event_max_datetime": "2015-08-16T09:37:03.000Z", "max_forks_repo_path": "Course materials/Dictaat/tex/Examples/binary_numbers.tex", "max_forks_repo_name": "cult-of-giuseppe/metacompiler", "max_forks_repo_head_hexsha": "51eb3588394c15b31ebacba97a22c086e0c8dc6c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-10-11T17:13:13.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-10T19:12:15.000Z", "avg_line_length": 58.7304964539, "max_line_length": 912, "alphanum_fraction": 0.7244294167, "num_tokens": 2121, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7670577768018355}}
{"text": "\\chapter{Data} \n\n\\begin{description}\n  \\item[Data] is collection of data object and their attributes.\n  \\item[Type of Attributes] Nominal, Ordinal, Interval, Ratio.\n  \\item[Attribute Values Property] Distinctness, Order, Addition, Multiplication\n\\end{description} \n\\par \\noindent\n\\marginnote{I do not focus on Types of Data Sets and Characteristics of Structured Data}One idea to determine if an interval attribute is ratio is to check if the attribute has a true or natural absolute zero point. The ratio scales are very common in physical scenario. \n\n\\section{Discrete and Continuous}\n\n\\begin{description}\n  \\item[Discrete Attribute] Has only a finite or countably infinite set of values\n  \\item[Continuous Attribute] Has real numbers as attribute values\n\\end{description}\n\n\\section{Data Quality}\n\n\\begin{description}\n  \\item[Noise] modification of original values\n  \\item[Outlier] considerably different than most of the other data objects\n\\end{description}\n\n\\section{Discretization and Binarization}\n\n\\begin{description}\n  \\item[Binarization] transform either a continuous attribute or a categorical attribute into one or more binary attributes\n  \\item[Discretisation] transform a continuous attribute into a categorical attribute\n\\end{description}\n\n\\section{Normalization}\n\n\\underline{Min-Max Normalization}\n$$(min_A, max_A) \\rightarrow (new\\_min_A, new\\_max_A)$$\n$${v^{'}={\\frac{v-min_A}{max_A-min_A}} \\times (new\\_max_A-new\\_min_A) + new\\_min_A}$$\n\\\\\n\\underline{Z-score Normalization}\n$$v^{'}=\\frac{v-\\mu_A}{\\sigma_A}$$\n\\\\\n\\underline{Normalisation by Decimal Scaling}\n$$v^{'}=\\frac{v}{10^{j}}$$\nwhere j = smallest integer such that $Max(\\mid v^{'}\\mid) < 1$\n\n\\section{Proximity}\n\n\\begin{description}\n\\item[Similarity] Numerical measure of how alike two data objects are\n\\item[Dissimilarity] Numerical measure of how different two data objects are\n\\end{description}\n\\underline{Euclidean Distance}\n$$dist=\\sqrt{\\sum_{k=1}^{n}{(p_k-q_k)^2}}$$\n\\\\\n\\underline{Minkowski Distance}\n$$dist={\\sum_{k=1}^{n}{(\\mid p_k-q_k\\mid^r)}}^{1/r}$$\n\\begin{align*}\nr = 1&: Hamming\\ distance / Manhattan\\ distance\\\\\nr = 2&: Euclidean\\ distance \\\\\nr = inf&: supremum\\ /\\ Chebyshev\\ distance, max(x - y) \\\\\n\\end{align*}\n\\\\\n\\underline{Simple Matching Coefficient}\n$$SMC=\\frac{M_{11} + M_{00}}{M_{00} + M_{01} + M_{10} + M_{11}}$$\n\\\\\n\\underline{Jaccard Coefficient}\n$$J=\\frac{M_{11}}{M_{01} + M_{10} + M_{11}}$$\n\\\\\n\\underline{Cosine Similarity}\n$$cos(p,q)=\\frac{p\\bullet q}{\\|p\\|\\|q\\|}$$\n\\underline{Tanimoto Coefficient}\n$$T(p,q)=\\frac{p\\bullet q}{\\|p\\|^{2}+\\|q\\|^{2}-p\\bullet q}$$\n\n\\section{Correlation}\n\n$$corr(p,q)=\\frac{cov(p,q)}{std(p) \\times std(q)}$$\n$$cov(p,q)=\\frac{1}{n-1}\\sum_{k=1}^{n}{(p_k-\\bar{p})(q_k-\\bar{q})}$$\n$$std(p)=\\sqrt{\\frac{1}{n-1}\\sum_{k=1}^{n}{(p_k-\\bar{p})^{2}}}$$\n", "meta": {"hexsha": "593433ecae714112a2ed0abfabbfa9053977b06c", "size": 2772, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.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": "chapter2.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": "chapter2.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": 35.5384615385, "max_line_length": 271, "alphanum_fraction": 0.7081529582, "num_tokens": 900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.7670577704107985}}
{"text": "\\subsection{Convex Functions}\nLet us first give the definition of convex sets.\n\\begin{definition}[Convex set]\n\tA set $C$ is convex, if the line segment between any two points in $C$ lies in $C$, i.e., if any $x, y\\in C$ and any $\\alpha$ with $0\\leq \\alpha \\leq 1$, there holds\n\t\\begin{equation}\n\t\\alpha x+ (1- \\alpha)y \\in C.\n\t\\end{equation}\n\\end{definition}\n \n%Based on the definition above, we have the next property of convex sets.\n%\\begin{lemma}\n%[Homework] Let $C$ be a convex set, with $x_{1}, \\dots, x_{k}\\in C$, and let $\\alpha_{1}, \\dots, \\alpha_{k} \\in \\mathbb{R}$ satisfy $\\alpha_{i} \\geq 0$ and  $\\sum_{i =1}^{k} \\alpha_{i} = 1$, then \n%\t\\begin{equation}\n%\t\\sum_{i = 1}^{k}\\alpha_{i}x^{i} \\in C,\n%\t\\end{equation}\t\n%\\end{lemma}\t\n\nFollowing the definition of convex set, we define convex function as following.\n\\begin{definition}[Convex function]\n\tLet $C \\subset \\mathbb{R}^n$ be a convex set and $f: C \\rightarrow \\mathbb{R}$:\n\t\\begin{enumerate}\n\t\t\\item $f$ is called {\\bf convex} if for any $x, y \\in C$ and $\\alpha\\in [0, 1]$\n\t\t\\begin{equation}\n\t\tf(\\alpha x + (1- \\alpha)y) \\leq \\alpha f(x )+ (1- \\alpha)f(y).\t\n\t\t\\end{equation}\n\t\t\\item $f$ is called {\\bf strictly convex} if for any $x\\neq y \\in C$ and $\\alpha\\in (0, 1)$:\n\t\t\\begin{equation}\n\t\tf(\\alpha x + (1- \\alpha)y) < \\alpha f(x ) + (1 - \\alpha)f(y).\n\t\t\\end{equation}\n\t\t\\item A function $f$ is said to be (strictly) {\\bf concave} if $-f$ is (strictly) convex.\n\t\\end{enumerate}\n\\end{definition}\n%With mentioned previously property of convex sets, it is easy to expend the above definition of convex function. Here we write as one lemma without proof. \n%\\begin{lemma}\n%[Homework]Let $C$ be a convex set, with $x_{1}, \\dots, x_{k}\\in C$, and let $\\alpha_{1}, \\dots, \\alpha_{k} \\in \\mathbb{R}$ satisfy $\\alpha_{i} \\geq 0$ and  $\\sum_{i =1}^{k} \\alpha_{i} = 1$, then \n%\t\\begin{equation}\n%\tf(\\sum_{i = 1}^{k}\\alpha_{i}x_{i}) \\leq \\sum_{i = 1}^{k}\\alpha_{i}f(x_{i}) .\n%\t\\end{equation}\t\n%\\end{lemma}\nFig. \\ref{convexfunc} and \\ref{nonconvexfunc} are diagrams  for convex function definition.\n\\begin{figure}[H]\n\\centering                    % 大图名称\n\\subfigure[Convex function]{                    %第二张子图\n\\begin{minipage}{4cm}\\centering\n\\includegraphics[width=1\\textwidth] {6DL/figures/convexfunction.png}\\label{convexfunc}\n\\end{minipage}   }  \n \\quad\n \\subfigure[Nonconvex function]{                    %第二张子图\n\\begin{minipage}{4cm}\\centering\n\\includegraphics[width=1\\textwidth,height=0.8\\textwidth] {6DL/figures/nonconvexfunction.png}\\label{nonconvexfunc}\n\\end{minipage}   }  \n\\caption{Convex and nonconvex functions} %     \n\\end{figure}\n\n\n\n\\begin{lemma}\n\tIf $f(x)$ is differentiable on $\\mathbb{R}^n$, then $f(x)$ is convex if and only if\n\t\\begin{equation}\n\tf( x) \\ge f( y) + \\nabla f( y)\\cdot ( x -  y), \\forall x, y \\in \\mathbb{R}^n.\n\t\\end{equation}\n\\end{lemma}\nBased on the lemma, we can first have  Fig. \\ref{fig:convextangent} for convex functions, namely, the curve of a convex function is always above the tangent lines.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=.5\\textwidth] {6DL/figures/convextangent.png}\n\\caption{Tangent line of a convex function}\n\\label{fig:convextangent}\n\\end{figure}\n\n\\begin{proof}\n\tLet $z=\\alpha x+(1-\\alpha )y, 0\\leq \\alpha \\leq 1, \\forall x,y \\in \\mathbb{R}^n$, we have these next two Taylor expansion:\n\t\\begin{equation}\\label{key}\n\t\\begin{aligned}\n\t&f(x)\\geq f(z)+ \\nabla f(z)(x-z),\\\\\n\t&f(y)\\geq f(z)+ \\nabla f(z)(y-z).\n\t\\end{aligned}\n\t\\end{equation}\n\tThen we have\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\alpha f(x) + (1-\\alpha) f(y)\n\t\\geq &f(z) + \\nabla f(z)[\\alpha(x-z)+(1-\\alpha)(y-z)]\\\\\n\t=&f(z)\n\t=f(\\alpha x +(1-\\alpha)y).\n\t\\end{aligned}\n\t\\end{equation}\n\tThus we have\n\t\\begin{equation}\\label{key}\n\t\\alpha f(x) + (1-\\alpha) f(y) \\ge f(\\alpha x +(1-\\alpha)y).\n\t\\end{equation}\n\tThis finishes the proof.\n\t\n\tOn the other hand if\t$f(x)$ is differentiable on $\\mathbb{R}^n$, then \n\t$$\n\tf( x) \\ge f( y) + \\nabla f( y)\\cdot ( x -  y), \\forall x, y \\in \\mathbb{R}^n\n\t$$ \n\tif $f(x)$ is convex.\n\\end{proof}\n\n\\begin{definition}[$\\lambda$-strongly convex]\\label{def:strongconvex}\nWe say that $f(x)$ is $\\lambda$-strongly convex if\n\t\\begin{equation}\\label{equ:lambdastronglyconvex}\n\tf(x)  \\ge f(y) + \\nabla f(y)\\cdot(x-y) + \\frac{\\lambda}{2}\\|x-y\\|^2, \\quad \\forall x, y \\in C,\n\t\\end{equation}\n\tfor some $\\lambda >0$.\n\\end{definition} \n\\begin{lemma}\nLet $\\sigma(\\nabla^2f)$ be the spectrum of the operator $\\nabla^2 f$. If\n$$\n\\sigma(\\nabla^2f)\\subset [\\lambda, L],\n$$ \nthen the condition \\eqref{equ:lambdastronglyconvex} holds.\n\\end{lemma}\n\n\\begin{lemma} \nIf $f(x)$ is $\\lambda$-strongly convex,\n\t\\begin{equation}\\label{strongConvIneq}\n\t\t\\nabla f(x)\\cdot(x - x^*) \\ge f(x) - f(x^*) +\\frac{\\lambda}{2}\\|x - x^*\\|^2\\ge \\lambda \\|x - x^*\\|^2.\n\t\t\\end{equation} \n\\end{lemma}\n\n\\begin{example}\n\tConsider $f(x) = \\|x\\|^2$, then we have\n\t\\begin{equation}\\label{key}\n\t\\frac{\\partial f}{\\partial x_{i}}=2x_{i}, \\nabla f = 2x \\in R^n,\\quad \\nabla^2f=2I_{n\\times n}\\in\\mathbb{R}^{n\\times n}.\n\t\\end{equation}\n\tSo, we have $\\lambda_{\\rm min}(\\nabla^2f)=2>0$ and\n\t\\begin{equation}\n\t\\begin{aligned}\n\tf(x)-f(y)-\\nabla f(y)(x-y)\n\t=&\\left \\| x \\right \\|^2-\\left \\| y \\right \\|^2-2y(x-y)\\\\\n\t=&\\left \\| x \\right \\|^2-\\left \\| y \\right \\|^2-2xy+2\\left \\| y \\right \\|^2\\\\\n\t=&\\left \\| x \\right \\|^2-2xy+\\left \\| y \\right \\|^2\\\\\n\t=&\\left \\| x-y \\right \\|^2\\\\\n\t=&\\frac{\\lambda }{2}\\left \\| x-y \\right \\|^2 , \\quad \\lambda=2.\n\t\\end{aligned}\n\t\\end{equation}\t\n\tThus, $f(x) = \\|x\\|^2$ is 2-strongly convex\n\\end{example}\n\\begin{lemma}\nIf $f(x)$ is $\\lambda$-strongly convex and $\\lambda(\\nabla^2 f)\\le L$, then\n$$\n\\lambda\\|x-y\\|\\le \\|\\nabla f(x) - \\nabla f(y)\\|\\le L\\|x-y\\|.\n$$\n\\end{lemma}\n\\begin{assumption}\\label{ass:GD}\nWe make the following assumptions:\n\\begin{enumerate}\n\t\\item $f(x)$ is $\\lambda$-strongly convex for some $\\lambda >0$ with the definition in Definition \\ref{def:strongconvex}.  \n\t\\item $\\nabla f$ is $L$-Lipschitz, i.e., \n\t\\begin{equation}\\label{key}\n\t\\|\\nabla f(x) - \\nabla f(y)\\| \\le L\\|x - y\\|, \\forall x,y.\n\t\\end{equation}\n\\end{enumerate}\t\n\\end{assumption}\n\\begin{example}\nActually, the loss function of the logistic regression model \n\t\\begin{equation}\\label{key}\n\tL(\\theta) = -\\log P(\\theta),\n\t\\end{equation}\n\tis a convex  function of $\\theta$. \n\tFurthermore, the loss function of the regularized logistic regression model \n\t\\begin{equation}\\label{key}\n\tL_\\lambda(\\theta) = -\\log P(\\theta) + \\lambda \\|\\theta\\|_F^2, \\lambda > 0\n\t\\end{equation}\n\t  is a $\\lambda'$-strongly convex function of $\\theta$($\\lambda'$ is related to $\\lambda$).\n\\end{example}\n\nWe also have these following interesting properties of convex function. \n\n\\begin{proposition}[basic properties of convex function] \n\t\\begin{enumerate}\n\t\t\\item If $f(x)$, $g(x)$ are both convex, then $\\alpha f(x) + \\beta g(x)$ is also convex, if $\\alpha, \\beta \\geq 0$.\n\t\t\\item  Linear function is both convex and concave. Here, $f(x)$ is concave if and only if $-f(x)$ is convex.\n\t\t\\item If $f(x)$ is a convex function on $\\mathbb{R}^n$, then $g(y) = f(Ay+b)$ is a convex function on $\\mathbb{R}^m$. Here $A \\in \\mathbb{R}^{m \\times n}$ and $b\\in \\mathbb{R}^m$. \n\t\t\\item  If $g(x)$ is a convex function on $\\mathbb{R}^n$, and the function $f(u)$ is convex function on $\\mathbb{R}$ and non-decreasing, then the composite function $f \\circ g(x) = f(g(x))$ is convex.\n\t\\end{enumerate}\n\\end{proposition}\nThe proof is straightforward and left to the interested readers.\n\n\\begin{theorem}[Jensen's inequality]\nIf $p_1, \\cdots, p_n$ are positive numbers which sum to 1 and $f$ is a real continuous function which is convex, then\n$$\nf(\\sum_{i=1}^n\\alpha_ix_i)\\le \\sum_{i=1}^n \\alpha_if(x_i).\n$$\nIf $f$ is concave, then\n$$\nf(\\sum_{i=1}^n\\alpha_ix_i)\\ge \\sum_{i=1}^n \\alpha_if(x_i).\n$$\n\\end{theorem}\n", "meta": {"hexsha": "e0367a33532cc30a604244f6cca431fdc7877f70", "size": 7727, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/convexsets.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/convexsets.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/convexsets.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.2447916667, "max_line_length": 201, "alphanum_fraction": 0.6469522454, "num_tokens": 2919, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513675912912, "lm_q2_score": 0.8558511506439707, "lm_q1q2_score": 0.7670577642192389}}
{"text": "\\section{The matrix of a linear transformation}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Find the matrix of a linear transformation and determine the\n    action on a vector in $\\R^n$.\n  \\end{enumerate}\n\\end{outcome}\n\nIn the above examples, the action of the linear transformations was to\nmultiply by a matrix.  It turns out that this is always the case for\nlinear transformations.  If $T$ is \\textbf{any} linear transformation\nwhich maps $\\R^{n}$ to $\\R^{m}$, there is \\textbf{always} an\n$m\\times n$-matrix $A$ with the property that\n\\begin{equation}\nT(\\vect{x}) = A\\vect{x} \\label{matrix-of-transf}\n\\end{equation}\nfor all $\\vect{x} \\in \\R^{n}$.\n\n\\begin{theorem}{Matrix of a linear transformation}{matrix-linear-transformation}\nLet $T:\\R^{n}\\to \\R^{m}$ be a linear transformation. Then we can find a matrix $A$ such that $T(\\vect{x}) = A\\vect{x}$.\n In this case, we say that $T$ is {\\em determined} or {\\em induced}\nby the matrix $A$.\n\\end{theorem}\n\nHere is why. Suppose $T:\\R^{n}\\to \\R^{m}$ is a linear transformation and you want to find\nthe matrix defined by this linear transformation as described in {\\eqref{matrix-of-transf}}.\n Note that\n\\begin{equation*}\n\\vect{x} =\\begin{mymatrix}{c}\nx_{1} \\\\\nx_{2} \\\\\n\\vdots \\\\\nx_{n}\n\\end{mymatrix} = x_{1}\\begin{mymatrix}{c}\n1 \\\\\n0 \\\\\n\\vdots \\\\\n0\n\\end{mymatrix} + x_{2}\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n\\vdots \\\\\n0\n\\end{mymatrix} +\\ldots + x_{n}\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n\\vdots \\\\\n1\n\\end{mymatrix} = \\sum_{i=1}^{n}x_{i}\\vect{e}_{i}\n\\end{equation*}\nwhere $\\vect{e}_{i}$ is the $i\\th$ column of $I_n$, that is the $n \\times\n1$ vector which has zeros in every slot but the $i\\th$ and a 1 in\nthis slot.\n\nThen since $T$ is linear,\n\\begin{eqnarray*}\nT(\\vect{x})&=&\\sum_{i=1}^{n}x_{i}T(\\vect{e}_{i}) \\\\\n&=&\\begin{mymatrix}{ccc}\n| &  & | \\\\\nT(\\vect{e}_{1}) & \\cdots & T(\\vect{e}_{n}) \\\\\n| &  & |\n\\end{mymatrix} \\begin{mymatrix}{c}\nx_{1} \\\\\n\\vdots \\\\\nx_{n}\n\\end{mymatrix} \\\\\n&=& A\\begin{mymatrix}{c}\nx_{1} \\\\\n\\vdots \\\\\nx_{n}\n\\end{mymatrix}\n\\end{eqnarray*}\nTherefore,  the desired matrix is obtained from constructing the $i\\th$\ncolumn as $T(\\vect{e}_{i})$. We state this formally as the\nfollowing theorem.\n\n\\begin{theorem}{Matrix of a linear transformation}{matrix-of-linear-transformation}\nLet $T: \\R^{n} \\to \\R^{m}$ be a linear transformation. Then the matrix $A$ satisfying $T(\\vect{x})=A\\vect{x}$\\index{linear transformation!matrix} is given by\n\\begin{equation*}\nA=\n\\begin{mymatrix}{ccc}\n| &  & | \\\\\nT(\\vect{e}_{1}) & \\cdots & T(\\vect{e}_{n}) \\\\\n| &  & |\n\\end{mymatrix}\n\\end{equation*}\nwhere $\\vect{e}_{i}$ is the $i\\th$ column of $I_n$, and then $T(\\vect{e}_{i}\n)$ is the $i\\th$ column of $A$.\n\\end{theorem}\n\nThe following Corollary is an essential result.\n\n\\begin{corollary}{Matrix and linear transformation}{matrix-linear-transformation-equivalence}\nA transformation $T$ is a linear transformation if and only if it is a matrix transformation.\n\\end{corollary}\n\nConsider the following example.\n\n\\begin{example}{The matrix of a linear transformation}{matrix-of-linear-transformation}\nSuppose $T$ is a linear transformation, $T:\\R^{3}\\rightarrow \\R^{2}$ where\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n0 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2\n\\end{mymatrix} ,\\ T\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{r}\n9 \\\\\n-3\n\\end{mymatrix} ,\\ T\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nFind the matrix $A$ of $T$ such that $T (\\vect{x})=A\\vect{x}$  for all $\\vect{x}$.\n\\end{example}\n\n\\begin{solution} By Theorem~\\ref{thm:matrix-of-linear-transformation} we construct $A$ as follows:\n\\begin{equation*}\nA =\n\\begin{mymatrix}{ccc}\n| &  & | \\\\\nT(\\vect{e}_{1}) & \\cdots & T(\\vect{e}_{n}) \\\\\n| &  & |\n\\end{mymatrix}\n\\end{equation*}\n\nIn this case, $A$ will be a $2 \\times 3$-matrix, so we need to find $T\n(\\vect{e}_1), T (\\vect{e}_2)$, and $T (\\vect{e}_3\n)$. Luckily, we have been given these values so we can fill in\n$A$ as needed, using these vectors as the columns of $A$.  Hence,\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 9 & 1 \\\\\n2 & -3 & 1\n\\end{mymatrix}\n\\end{equation*}\n\\end{solution}\n\nIn this example, we were given the resulting vectors of $T (\\vect{e}_1),\nT (\\vect{e}_2)$, and $T (\\vect{e}_3)$. Constructing the matrix $A$ was simple, as we\ncould simply use these vectors as the columns of $A$. The next example shows how to find $A$ when we are not given the $T (\\vect{e}_i)$ so clearly.\n\n\\begin{example}{The matrix of linear transformation: inconveniently \\\\ defined}{2x2-inconvenient-matrix-of-linear-transformation}\nSuppose $T$ is a linear transformation, $T:\\R^{2}\\rightarrow \\R^{2}$ and\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n1 \\\\\n2\n\\end{mymatrix} ,\\ T\\begin{mymatrix}{r}\n0 \\\\\n-1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n3 \\\\\n2\n\\end{mymatrix}\n\\end{equation*}\nFind the matrix $A$ of $T$ such that $T (\\vect{x})=A\\vect{x}$  for all $\\vect{x}$.\n\\end{example}\n\n\\begin{solution} By Theorem~\\ref{thm:matrix-of-linear-transformation} to find this matrix, we need to determine the action of $T$ on\n$\\vect{e}_{1}$ and $\\vect{e}_{2}$. In Example~\\ref{exa:matrix-of-linear-transformation}, we were given these resulting vectors.\nHowever, in this example, we have been given $T$ of two different vectors. How can we find out the action\nof $T$ on $\\vect{e}_{1}$ and $\\vect{e}_{2}$? In particular for $\\vect{e}_{1}$, suppose there exist $x$ and $y$ such that\n\\begin{equation}\n\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix} = x\\begin{mymatrix}{r}\n1\\\\\n1\n\\end{mymatrix} +y\\begin{mymatrix}{r}\n0 \\\\\n-1\n\\end{mymatrix}\n\\label{matrix-values}\n\\end{equation}\n\nThen, since $T$ is linear,\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix}  = x T\\begin{mymatrix}{r}\n1 \\\\\n1\n\\end{mymatrix} +y T\\begin{mymatrix}{r}\n0 \\\\\n-1\n\\end{mymatrix}\n\\end{equation*}\n\nSubstituting in values, this sum becomes\n\\begin{equation}\nT\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix} =\n x\\begin{mymatrix}{r}\n1 \\\\\n2\n\\end{mymatrix} +y\\begin{mymatrix}{r}\n3 \\\\\n2\n\\end{mymatrix}\n\\label{matrix-values2}\n\\end{equation}\n\nTherefore, if we know the values of $x$ and $y$ which satisfy {\\eqref{matrix-values}}, we can substitute these into equation {\\eqref{matrix-values2}}. By doing so,\nwe find $T(\\vect{e}_1)$ which is the first column of the matrix $A$.\n\nWe proceed to find $x$ and $y$. We do so by solving {\\eqref{matrix-values}}, which can be done by solving the system\n\\begin{equation*}\n\\begin{array}{c}\nx = 1 \\\\\nx - y = 0\n\\end{array}\n\\end{equation*}\n\nWe see that $x=1$ and $y=1$ is the solution to this system.\nSubstituting these values into equation {\\eqref{matrix-values2}}, we have\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix} =\n 1 \\begin{mymatrix}{r}\n1 \\\\\n2\n\\end{mymatrix} + 1 \\begin{mymatrix}{r}\n3 \\\\\n2\n\\end{mymatrix}\n=\n \\begin{mymatrix}{r}\n1 \\\\\n2\n\\end{mymatrix} + \\begin{mymatrix}{r}\n3 \\\\\n2\n\\end{mymatrix}\n=\n\\begin{mymatrix}{r}\n4 \\\\\n4\n\\end{mymatrix}\n\\end{equation*}\n\nTherefore $\\begin{mymatrix}{r}\n4 \\\\\n4\n\\end{mymatrix}$\nis the first column of $A$.\n\nComputing the second column is done in the same way, and is left as an exercise.\n\nThe resulting matrix $A$ is given by\n\\begin{equation*}\nA\n=\n\\begin{mymatrix}{rr}\n4 & -3 \\\\\n4 & -2\n\\end{mymatrix}\n\\end{equation*}\n\\end{solution}\n\nThis example illustrates a very long procedure for finding the matrix of $A$. While this method is reliable and\nwill always result in the correct matrix $A$, the following procedure provides an alternative method.\n\n\\begin{procedure}{Finding the matrix of inconveniently defined linear transformation}{finding-matrix-of-linear-transformation}\nSuppose $T:\\R^{n}\\rightarrow \\R^{m}$ is a linear transformation. Suppose there exist vectors $\\set{\\vect{a}_{1},\\ldots,\\vect{a}_{n}} $ in $\\R^{n}$ such that $\\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} ^{-1}$ exists, and\n\\begin{equation*}\nT (\\vect{a}_{i})=\\vect{b}_{i}\n\\end{equation*}\nThen the matrix of $T$ must be of the form\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\n\\vect{b}_{1} & \\cdots & \\vect{b}_{n}\n\\end{mymatrix} \\begin{mymatrix}{ccc}\n\\vect{a}_{1} & \\cdots & \\vect{a}_{n}\n\\end{mymatrix} ^{-1}\n\\end{equation*}\n\\end{procedure}\n\nWe will illustrate this procedure in the following example. You may also find it useful\nto work through Example~\\ref{exa:2x2-inconvenient-matrix-of-linear-transformation} using this procedure.\n\n\\begin{example}{Matrix of a linear transformation \\\\ given inconveniently}{inconvenient-matrix-linear-transformation}\nSuppose $T:\\R^{3}\\rightarrow \\R^{3}$ is a linear\ntransformation and\n\\begin{equation*}\nT\\begin{mymatrix}{r}\n1 \\\\\n3 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,T\\begin{mymatrix}{r}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{r}\n2 \\\\\n1 \\\\\n3\n\\end{mymatrix} ,T\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nFind the matrix of this linear transformation.\n\\end{example}\n\n\\begin{solution}\nBy Procedure~\\ref{proc:finding-matrix-of-linear-transformation},\n$A=  \\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n3 & 1 & 1 \\\\\n1 & 1 & 0\n\\end{mymatrix} ^{-1}$ and\n $B=\\begin{mymatrix}{rrr}\n0 & 2 & 0 \\\\\n1 & 1 & 0 \\\\\n1 & 3 & 1\n\\end{mymatrix}$\n\nThen, Procedure~\\ref{proc:finding-matrix-of-linear-transformation} claims that the matrix of $T$ is\n\\begin{equation*}\nC= BA^{-1}\n=\\begin{mymatrix}{rrr}\n2 & -2 & 4 \\\\\n0 & 0 & 1 \\\\\n4 & -3 & 6\n\\end{mymatrix}\n\\end{equation*}\n\nIndeed you can first verify that $T(\\vect{x})=C\\vect{x}$ for the 3 vectors above:\n\n\\begin{equation*}\n \\begin{mymatrix}{ccc}\n2 & -2 & 4 \\\\\n0 & 0 & 1 \\\\\n4 & -3 & 6\n\\end{mymatrix} \\begin{mymatrix}{c}\n1 \\\\\n3 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} ,\\ \\begin{mymatrix}{ccc}\n2 & -2 & 4 \\\\\n0 & 0 & 1 \\\\\n4 & -3 & 6\n\\end{mymatrix} \\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n2 \\\\\n1 \\\\\n3\n\\end{mymatrix}\n\\end{equation*}\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\n2 & -2 & 4 \\\\\n0 & 0 & 1 \\\\\n4 & -3 & 6\n\\end{mymatrix} \\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\n\nBut more generally $T(\\vect{x})= C\\vect{x}$ for any $\\vect{x}$. To see this, let $\\vect{y}=A^{-1}\\vect{x}$ and then using linearity of $T$:\n\\[ T(\\vect{x})= T(A\\vect{y}) = T \\paren{\\sum_i \\vect{y}_i\\vect{a}_i} = \\sum \\vect{y}_i T(\\vect{a}_i) \\sum \\vect{y}_i \\vect{b}_i = B\\vect{y} = BA^{-1}\\vect{x} = C\\vect{x}\\]\n\\end{solution}\n\nRecall the dot product discussed earlier. Consider the map $\\vect{v}$\\textbf{$\\mapsto $}\n$\\proj_{\\vect{u}}(\\vect{v}) $ which takes a vector a transforms it to its projection onto a given vector $\\vect{u}$. It turns out that\nthis map is linear, a result which follows from the properties of the\ndot product. This is shown as follows.\n\\begin{eqnarray*}\n\\proj_{\\vect{u}}(k \\vect{v}+ p \\vect{w})\n&=&\\paren{\\vspace{0.05in}\\frac{(k \\vect{v}+ p \\vect{w})\\dotprod \\vect{u}}{\n\\vect{u}\\dotprod \\vect{u}}} \\vect{u} \\\\\n&=& k  \\paren{\\vspace{0.05in}\\frac{\n\\vect{v}\\dotprod \\vect{u}}{\\vect{u}\\dotprod \\vect{u}}} \\vect{u}+p \\paren{\\vspace{\n0.05in}\\frac{\\vect{w}\\dotprod \\vect{u}}{\\vect{u}\\dotprod \\vect{u}}} \\vect{u} \\\\\n&=& k \\; \\proj_{\\vect{u}}(\\vect{v}) +p \\; \\proj\n_{\\vect{u}}(\\vect{w})\n\\end{eqnarray*}\n\nConsider the following example.\n\n\\begin{example}{Matrix of a projection map}{projection-matrix}\nLet $\\vect{u} = \\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix}$ and let $T$ be the projection map $T: \\R^3 \\to \\R^3$ defined by\n\\[\nT(\\vect{v}) = \\proj_{\\vect{u}}(\\vect{v})\n\\]\nfor any $\\vect{v} \\in \\R^3$.\n\\begin{enumerate}\n\\item Does this transformation come from\nmultiplication by a matrix?\n\\item If so, what is the matrix?\n\\end{enumerate}\n\\end{example}\n\n\\begin{solution}\n\\begin{enumerate}\n\\item\nFirst, we have just seen that $T (\\vect{v}) = \\proj_{\\vect{u}}(\\vect{v})$ is linear. Therefore by Theorem~\\ref{thm:matrix-linear-transformation}, we can find a matrix $A$ such that $T(\\vect{x}) = A\\vect{x}$.\n\n\\item\nThe columns of the matrix for $T$ are defined above as $T(\\vect{e}_{i})$.\nIt follows that $T(\\vect{e}_{i}) = \\proj\n_{\\vect{u}}(\\vect{e}_{i}) $ gives the $i\\th$ column of the\ndesired matrix. Therefore, we need to find\n\\begin{equation*}\n\\proj_{\\vect{u}}(\\vect{e}_{i}) = \\paren{\\vspace{0.05in}\n\\frac{\\vect{e}_{i}\\dotprod \\vect{u}}{\\vect{u}\\dotprod \\vect{u}}}\n\\vect{u}\n\\end{equation*}\nFor the given vector $\\vect{u}$ , this implies the columns of the desired\nmatrix are\n\\begin{equation*}\n\\vspace{0.05in}\\frac{1}{14}\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix} ,\\vspace{0.05in}\\frac{2}{14}\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix} ,\\vspace{0.05in}\\frac{3}{14}\\begin{mymatrix}{r}\n1 \\\\\n2 \\\\\n3\n\\end{mymatrix}\n\\end{equation*}\nwhich you can verify.\nHence the matrix of $T$ is\n\\begin{equation*}\n\\vspace{0.05in}\\frac{1}{14}\\begin{mymatrix}{rrr}\n1 & 2 & 3 \\\\\n2 & 4 & 6 \\\\\n3 & 6 & 9\n\\end{mymatrix}\n\\end{equation*}\n\\end{enumerate}\n\\end{solution}\n", "meta": {"hexsha": "e59c19ff9f1caf84b51b90b7c6b0c2e50231ea01", "size": 12796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/lineartransformationsMatrix.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/lineartransformationsMatrix.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/lineartransformationsMatrix.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 26.2751540041, "max_line_length": 207, "alphanum_fraction": 0.6645826821, "num_tokens": 4741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851135937125, "lm_q2_score": 0.8962513793687401, "lm_q1q2_score": 0.7670577611179514}}
{"text": "\\documentclass[../searching.tex]{subfiles}\n\\begin{document}\nTo search in a sorted array or string using brute force with a for loop, it takes $O(n)$ time. Binary search is designed to reduce search time if the array or string is already sorted. It uses the divide and conquer method; each time we compare our target with the middle element of the array and with the comparison result to decide the next search region: either the left half or the right half. Therefore, each step we filter out half of the array which gives the time complexity function $T(n) = T(n/2) + O(1)$, which decrease the time complexity to $O(\\log n)$.\n\nBinary Search can be applied to different tasks:\n\\begin{enumerate}\n    \\item Find Exact target, find the first position that value>= target, find the last position that value<= target.(this is called lower\\_bound, and upper\\_bound. \n\\end{enumerate}\n\n\\subsection{Standard Binary Search and Python Module bisect}\nBinary search is usually carried out on a Static sorted array or 2D matrix. There are three basic cases: (1) find the exact target that value = target; If there are duplicates, we are more likely to be asked to (2) find the first position that has value >= target; (3) find the first position that has value <= target. Here, we use two example array: one without duplicates and the other has duplicates.\n\\begin{lstlisting}[language=Python]\na = [2, 4, 5, 9]\nb = [0, 1, 1, 1, 1, 1]\n\\end{lstlisting}\n\n\\paragraph{Find the Exact Target} This is the most basic application of binary search. We can set two pointers, l and r. Each time we compute the middle position, and check if it is equal to the target. If it is, return the position; if it is smaller than the target, move to the left half, otherwise, move to the right half. The Python code is given:\n\\begin{lstlisting}[language=Python]\ndef standard_binary_search(lst, target):\n    l, r = 0, len(lst) - 1\n    while l <= r:\n        mid = l + (r - l) // 2\n        if lst[mid] == target:\n            return mid\n        elif lst[mid] < target:\n            l = mid + 1\n        else:\n            r = mid - 1\n    return -1 # target is not found \n\\end{lstlisting}\nNow, run the example:\n\\begin{lstlisting}[language=Python]\nprint(\"standard_binary_search: \", standard_binary_search(a,3), standard_binary_search(a,4), standard_binary_search(b, 1))\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nstandard_binary_search:  -1 1 2\n\\end{lstlisting}\nFrom the example, we can see that multiple \\textbf{duplicates} of the target exist, it can possibly return any one of them. And for the case when the target does not exist, it simply returns -1. In reality, we might need to find a position where we can potentially insert the target to keep the sorted array sorted. There are two cases: (1) the first position that we can insert, which is the first position that has value>= target (2) and the last position we can insert, which is the first position that has value > target. For example, if we try to insert 3 in a, and 1 in b, the first position should be 1 and 1 in each array, and the last position is 1 and 6 instead.  For these two cases, we have a Python built-in Module \\textbf{bisect} which offers two methods: bisect\\_left() and bisect\\_right() for these two cases respectively.\n\n\\paragraph{Find the First Position that value >= target} This way the target position separates the array into two halves: value < target, target\\_position, value>= target. In order to meet the purpose, we make sure that if value < target, we move to the right side, else, move to the left side.\n\\begin{lstlisting}[language=Python]\n# bisect_left, no longer need to check the mid element,\n# it separate the list in to two halfs: value < target, mid,  value >= target\ndef bisect_left_raw(lst, target):\n    l, r = 0, len(lst)-1\n    while l <= r:\n        mid = l + (r-l)//2\n        if lst[mid] < target: # move to the right half if the value < target, till\n            l = mid + 1 #[mid+1, right]\n        else:# move to the left half is value >= target\n            r = mid - 1  #[left, mid-1]\n    return l # the final position is where\n\\end{lstlisting}\n% Now insert the value with:\n% \\begin{lstlisting}[language=Python]\n% lst.insert(l+1, target)\n% \\end{lstlisting}\n\n\\paragraph{Find the First Position that value > target} This way the target position separates the array into two halves: value <= target, target\\_position, value> target. Therefore, we simply change the condition of if value < target to if value <= target, then we move to the right side.\n\\begin{lstlisting}[language=Python]\n#bisect_right: separate the list into two halfs: value<= target, mid, value > target\ndef bisect_right_raw(lst, target):\n    l, r = 0, len(lst)-1\n    while l <= r:\n        mid = l + (r-l)//2\n        if lst[mid] <= target:\n            l = mid + 1\n        else:\n            r = mid -1\n    return l\n\\end{lstlisting}\nNow, run an example:\n\\begin{lstlisting}[language=Python]\nprint(\"bisect left raw: find 3 in a :\", bisect_left_raw(a,3), 'find 1 in b: ', bisect_left_raw(b, 1))\nprint(\"bisect right raw: find 3 in a :\", bisect_right_raw(a, 3), 'find 1 in b: ', bisect_right_raw(b, 1))\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nbisect left raw: find 3 in a : 1 find 1 in b:  1\nbisect right raw: find 3 in a : 1 find 1 in b:  6\n\\end{lstlisting}\n\n\\paragraph{Bonus} For the last two cases, if we return the position as l-1, then we get the last position that value < target, and the last position value <= target.\n\n\\paragraph{Python Built-in Module bisect} This module provides support for maintaining a list in sorted order without having to sort the list after each insertion. It offers six methods as shown in Table~\\ref{tab:method_bisect}. However, only two are most commonly used: bisect\\_left and bisect\\_right.\n\\begin{table}[h]\n\\begin{small}\n\\centering\n\\noindent\\captionof{table}{ Methods of \\textbf{bisect}}\n \\noindent \\begin{tabular}{|p{0.25\\columnwidth}|p{0.75\\columnwidth}| }\n  \\hline\nMethod & Description   \\\\ \\hline\nbisect\\_left(a, x, lo=0, hi=len(a)  &  The parameters lo and hi may be used to specify a subset of the list; the function is the same as bisect\\_left\\_raw  \\\\\\hline\nbisect\\_right(a, x, lo=0, hi=len(a)  &  The parameters lo and hi may be used to specify a subset of the list; the function is the same as bisect\\_right\\_raw  \\\\\\hline\nbisect(a, x, lo=0, hi=len(a))  &Similar to bisect\\_left(), but returns an insertion point which comes after (to the right of) any existing entries of x in a.\\\\ \\hline\ninsort\\_left(a, x, lo=0, hi=len(a))  &This is equivalent to a.insert(bisect.bisect\\_left(a, x, lo, hi), x).\\\\ \\hline\ninsort\\_right(a, x, lo=0, hi=len(a)) & This is equivalent to a.insert(bisect.bisect\\_right(a, x, lo, hi), x).\\\\ \\hline\ninsort(a, x, lo=0, hi=len(a)) & Similar to insort\\_left(), but inserting x in a after any existing entries of x.\\\\ \\hline\n\\end{tabular}\n  \\label{tab:method_bisect}\n  \\end{small}\n\\end{table} \nLet's see come examplary code:\n\\begin{lstlisting}[language=Python]\nfrom bisect import bisect_left,bisect_right, bisect\nprint(\"bisect left: find 3 in a :\", bisect_left(a,3), 'find 1 in b: ', bisect_left(b, 1)) # lower_bound, the first position that value>= target\nprint(\"bisect right: find 3 in a :\", bisect_right(a, 3), 'find 1 in b: ', bisect_right(b, 1)) # upper_bound, the last position that value <= target\n\\end{lstlisting}\nThe print out is:\n\\begin{lstlisting}\nbisect left: find 3 in a : 1 find 1 in b:  1\nbisect right: find 3 in a : 1 find 1 in b:  6\n\\end{lstlisting}\n\\subsection{Binary Search in Rotated Sorted Array}\n\\label{concept_binary_search_in_array}\nThe extension of the standard binary search is on array that the array is ordered in its own way like rotated array. \n\n\\paragraph{Binary Search in Rotated Sorted Array } (See LeetCode problem, 33. Search in Rotated Sorted Array (medium). Suppose an array (without duplicates) sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists in the array.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: nums = [3, 4,5,6,7,0,1,2], target = 0\nOutput: 5\n\nExample 2:\n\nInput: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1\n\\end{lstlisting}\n\nIn the rotated sorted array, the array is not purely monotonic. Instead, there is one drop in the array because of the rotation, where it cuts the array into two parts. Suppose we are starting with a standard binary search with example 1, at first, we will check index 3, then we need to move to the right side?  Assuming we compare our middle item with the left item, \n\\begin{lstlisting}[numbers=none]\nif nums[mid] > nums[l]: # the left half is sorted\nelif nums[mid] < nums[l]: # the right half is sorted\nelse: # for case like [1,3], move to the right half\n\\end{lstlisting}\nFor a standard binary search, we simply need to compare the target with the middle item to decide which way to go. In this case, we can use objection. Check which side is sorted, because no matter where the left, right and the middle index is, there is always one side that is sorted. So if the left side is sorted, and the value is in the range of the [left, mid], then we move to the left part, else we object the left side, and move to the right side instead. \n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=0.7\\columnwidth]{fig/rotated_array.png}\n    \\caption{Example of Rotated Sorted Array}\n    \\label{fig:rotated_sorted_array}\n\\end{figure}\n\nThe code is shown:\n\\begin{lstlisting}[language=Python]\n'''implemente the rotated binary search'''\ndef RotatedBinarySearch(nums, target):\n    if not nums:\n        return -1\n   \n    l,r = 0,len(nums)-1\n    while l<=r:\n        mid = l+ (r-l)//2\n        if nums[mid] == target:\n            return mid\n         if nums[l] < nums[mid]: # if the left part is sorted\n                if nums[l] <= target <= nums[mid]:\n                    r = mid-1\n                else:\n                    l = mid+1\n            elif nums[l] > nums[mid]: # if the right side is sorted\n                if nums[mid] <= target <= nums[r]:\n                    l = mid+1\n                else:\n                    r = mid-1\n            else:\n                l = mid + 1\n    return -1\n\\end{lstlisting}\n\\begin{bclogo}[couleur = blue!30, arrondi=0.1,logo=\\bccrayon,ombre=true]{What happens if there is duplicates in the rotated sorted array? } In fact, similar comparing rule applies: \n\\begin{lstlisting}[numbers=none]\nif nums[mid] > nums[l]: # the left half is sorted\nelif nums[mid] < nums[l]: # the right half is sorted\nelse: # for case like [1,3], or [1, 3, 1, 1, 1] or [3, 1, 2, 3, 3, 3]\n   only l++\n\\end{lstlisting}\n\\end{bclogo}\n\n\n\n\n%%%%%%%%%%%%%%binary search on result space%%%%%%%\n\\subsection{Binary Search on Result Space}\nIf the question gives us the context: the target is in the range [left, right], we need to search the first or last position that satisfy a condition function. We can apply the concept of standard binary search and bisect\\_left and bisect\\_right and its mutant. Where we use the condition function to replace the value comparison between target and element at middle position. The steps we need:\n\\begin{enumerate}\n    \\item get the result search range [l, r] which is the initial value for l and r pointers. \n    \\item decide the valid function to replace such as if lst[mid] < target \n    \\item decide which binary search we use: standard, bisect\\_left/ bisect\\_right or its mutant.\n\\end{enumerate}\n\nFor example: \n\\begin{examples}[resume]\n\\item \\textbf{441. Arranging Coins (easy)}. You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of a 32-bit signed integer.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nn = 5\n\nThe coins can form the following rows:\n*\n* *\n* *\n\nBecause the 3rd row is incomplete, we return 2.\n\\end{lstlisting}\n\n\\textbf{Analysis: } Given a number n>=1, the minimum row is 1, and the maximum is n. Therefore, our possible result range is [1, n]. These can be treated as indexes of the sorted array. For a given row, we write a function to check if it is possible. We need a function $r* (r+1) // 2 <= n$. For this problem, we need to search in the range of [1, n] to find the last position that is valid. This is bisect\\_left or bisect\\_right, where we use the function replace the condition check:\n\\begin{lstlisting}[language=Python]\ndef arrangeCoins(self, n):\n    def isValid(row):\n        return (row*(row+1))//2 <= n\n    # we need to find the last position that is valid (<=)\n    def bisect_right():\n        l, r = 1, n\n        while l <= r:\n            mid = l + (r-l) // 2\n            if isValid(mid): # replaced compared with the standard binary search\n                l = mid + 1\n            else:\n                r = mid - 1\n        return l-1\n    return bisect_right()\n\\end{lstlisting}\n\\item \\textbf{278. First Bad Version.} You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad.\n\nSuppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad.\n\nYou are given an API bool isBadVersion(version) which will return whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.\n\nSolution: we keep doing binary search until we have searched all possible areas.\n\\begin{lstlisting}[language = Python]\nclass Solution(object):\n    def firstBadVersion(self, n):\n        \"\"\"\n        :type n: int\n        :rtype: int\n        \"\"\"\n        l,r=0,n-1\n        last = -1\n        while l<=r:\n            mid = l+(r-l)//2\n            if isBadVersion(mid+1): #move to the left, mid is index, s\n                r=mid-1\n                last = mid+1 #to track the last bad one\n            else:\n                l=mid-1\n        return last\n\\end{lstlisting}\n\\end{examples}\n% \\subsection{Bisection Method} (second edition)\n% The binary search principle can be used to find the root of a function that may be difficult to compute mathematically. We have not seen any problems that require this method on LeetCode yet. Thus we define the problem as:\n\n% Find the monthly payment for a loan: You want to buy a car using loan and want to pay in monthly installment of d d\n% \\subsection{Python Library}\n% Python has \\textbf{bisect} module for binary search. \n% \\begin{lstlisting}[numbers=none]\n% bisect.bisect_left(a,    x):  Return the leftmost index where we can  insert x into a to maintain sorted order! Leftmost rl that satisfy: x<=a[rl]\n\n% bisect.bisect_right(a,    x):  Return the rightmost index where we can  insert x into a to maintain sorted order! Right most rr that satisfy: x>=a[rr]\n% \\end{lstlisting}\n% For example:\n% \\begin{lstlisting}[language=Python]\n% from bisect import bisect_left,bisect_right\n% a = [1,    2,    3,    3,    3,    4,    5]\n% p1, p2= bisect_left(a,3), bisect_right(a, 3)\n% print(p1, p2)\n% # output\n% # 2, 5\n% \\end{lstlisting}\n\n\\subsection{LeetCode Problems}\n\\begin{examples}\n\\item \\textbf{35. Search Insert Position (easy).} Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.\n\nYou can assume that there are no duplicates in the array.\n\\begin{lstlisting}[numbers=none]\nExample 1:\n\nInput: [1,3,5,6], 5\nOutput: 2\n\nExample 2:\nInput: [1,3,5,6], 2\nOutput: 1\n\nExample 3:\nInput: [1,3,5,6], 7\nOutput: 4\n\nExample 4:\nInput: [1,3,5,6], 0\nOutput: 0\n\\end{lstlisting}\n\n\\textbf{Solution: Standard Binary Search Implementation.} For this problem, we just standardize the Python code of binary search, which takes $O(logn)$ time complexity and O(1) space complexity without using recursion function. In the following code, we use exclusive right index with len(nums), therefore it stops if l == r; it can be as small as 0 or as large as n of the array length for numbers that are either smaller or equal to the nums[0] or larger or equal to nums[-1]. We can also make the right index inclusive. \n\\begin{lstlisting}[language = Python]\n# exclusive version\ndef searchInsert(self, nums, target):\n    l, r = 0, len(nums) #start from 0, end to the len (exclusive)\n    while l < r:\n        mid = (l+r)//2\n        if nums[mid] < target: #move to the right side\n            l = mid+1\n        elif nums[mid] > target: #move to the left side, not mid-1\n             r= mid\n        else: #found the traget\n            return mid\n    #where the position should go\n    return l\n\\end{lstlisting}\n\n\\begin{lstlisting}[language = Python]\n# inclusive version\ndef searchInsert(self, nums, target):\n   l = 0\n    r = len(nums)-1\n    while l <= r:\n        m = (l+r)//2\n        if target > nums[m]: #search the right half\n            l = m+1\n        elif target < nums[m]: # search for the left half\n            r = m-1\n        else:\n            return m\n    return l\n\\end{lstlisting}\n\\end{examples}\nStandard binary search\n\\begin{enumerate}\n    \\item 611. Valid Triangle Number (medium)\n    \\item 704. Binary Search (easy)\n    \n\\item  74. Search a 2D Matrix) Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:\n\\begin{enumerate}\n    \\item Integers in each row are sorted from left to right.\n    \\item The first integer of each row is greater than the last integer of the previous row.\n    \\end{enumerate}\n\\begin{lstlisting}[numbers=none]\nFor example,\nConsider the following matrix:\n\n[\n  [1,   3,  5,  7],\n  [10, 11, 16, 20],\n  [23, 30, 34, 50]\n]\n\nGiven target = 3, return true.\n\\end{lstlisting}\n\nSolution: 2D matrix search, time complexity from $O(n^2)$ to $O(lgm+lgn)$.\n\\begin{lstlisting}[language = Python]\ndef searchMatrix(self, matrix, target):\n        \"\"\"\n        :type matrix: List[List[int]]\n        :type target: int\n        :rtype: bool\n        \"\"\"\n        \n        if not matrix:\n            return False\n        row, col = len(matrix), len(matrix[0])\n        if row==0 or col==0: #for [[]]\n            return False\n        sr, er = 0, row-1\n        #fisrst search the mid row\n        while sr<=er:\n            mid = sr+(er-sr)//2\n            if target>matrix[mid][-1]: #go to the right side\n                sr=mid+1\n            elif target < matrix[mid][0]: #go the the left side\n                er = mid-1\n            else: #value might be in this row\n                #search in this row\n                lc, rc = 0, col-1\n                while lc<=rc:\n                    midc = lc+(rc-lc)//2\n                    if matrix[mid][midc]==target:\n                        return True\n                    elif target<matrix[mid][midc]: #go to left\n                        rc=midc-1\n                    else:\n                        lc=midc+1\n                return False\n        return False\n\\end{lstlisting}\n\nAlso, we can treat is as one dimensional, and the time complexity is $O(lg(m*n))$, which is the same as $O(log(m)+log(n))$.\n\\begin{lstlisting}[language = Python]\nclass Solution:\n    def searchMatrix(self, matrix, target):\n        if not matrix or target is None:\n            return False\n\n        rows, cols = len(matrix), len(matrix[0])\n        low, high = 0, rows * cols - 1\n        \n        while low <= high:\n            mid = (low + high) / 2\n            num = matrix[mid / cols][mid % cols]\n\n            if num == target:\n                return True\n            elif num < target:\n                low = mid + 1\n            else:\n                high = mid - 1\n        \n        return False\n\\end{lstlisting}\n\\end{enumerate}\n\nCheck \\url{http://www.cnblogs.com/grandyang/p/6854825.html} to get more examples.\n\nSearch on rotated and 2d matrix:\n\\begin{enumerate}\n    \\item 81. Search in Rotated Sorted Array II (medium) \n    \\item 153. Find Minimum in Rotated Sorted Array (medium) The key here is to compare the mid with left side, if mid-1 has a larger value, then that is the minimum \n    \\item 154. Find Minimum in Rotated Sorted Array II (hard)\n\\end{enumerate}\nSearch on Result Space:\n\\begin{enumerate}\n    \\item 367. Valid Perfect Square (easy) (standard search)\n    \\item 363. Max Sum of Rectangle No Larger Than K (hard)\n    \\item 354. Russian Doll Envelopes (hard)\n    \\item 69. Sqrt(x) (easy)\n\\end{enumerate}\n\\end{document}", "meta": {"hexsha": "3427a4c6d3e7248b1c6dbe69bef03f728720519a", "size": 20602, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Easy-Book/chapters/mastering/learning/search/binary_search.tex", "max_stars_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_stars_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Easy-Book/chapters/mastering/learning/search/binary_search.tex", "max_issues_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_issues_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Easy-Book/chapters/mastering/learning/search/binary_search.tex", "max_forks_repo_name": "stungkit/Algorithms-and-Coding-Interviews", "max_forks_repo_head_hexsha": "131199fea0b082d92c0f272a495c7a56a3242b71", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.911627907, "max_line_length": 838, "alphanum_fraction": 0.6725560625, "num_tokens": 5681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797027760039, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.7670544502836336}}
{"text": "\n\\subsection{Analytic optimisation}\n\n\\subsubsection{Convex and concave functions}\n\nConvex functions only have one minimum, and concave functions have only one maximum.\n\nIf a function is not concave or convex, it may have multiple minima\n\nIf a function is convex, then there is only one critical point – the local minimum. We can identify this this by looking for critical points using first-order conditions.\n\nSimilarly, if a function is concave, then there is only one critical point – the local maximum.\n\nWe can identify whether a function is concave or convex by evaluating the Hessian matrix.\n\n\\subsubsection{Evaluating multiple local optima}\n\nWe can evaluate each of the local minima or maxima, and compare the sizes.\n\nWe can identify these by taking partial derivatives of the function in question and identifying where this function is equal to zero.\n\n\\(u=f(x)\\)\n\n\\(u_{x_i}=\\dfrac{\\delta f}{\\delta x_i}=0\\)\n\nWe can then solve this bundle of equations to find the stationary values of \\(x\\).\n\nAfter identifying the vector \\(x\\) for these points we can then  determine whether or not the points are minima or maxima by  examining the second derivative at these points. If it is positive it is a local minima, and therefore not an optimal point. Points beyond these will be higher, and may be higher than any local maxima.\n\n\n", "meta": {"hexsha": "aa621218fb0597a7a371a6342672f23f4e225d2f", "size": 1329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/optimisationUni/01-04-analytic.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/optimisationUni/01-04-analytic.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/optimisationUni/01-04-analytic.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": 42.8709677419, "max_line_length": 327, "alphanum_fraction": 0.7825432656, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797075998823, "lm_q2_score": 0.8418256472515683, "lm_q1q2_score": 0.7670544471127656}}
{"text": "\\subsection{Rank and independence}\n\nIf $\\{\\tb{v}_1,\\tb{v}_2,\\cdots ,\\tb{v}_m\\}$ is a collection if independent vectors then\n\n\\[\n\\left(\\begin{array}{ccccc}\n\\mid & \\mid & \\mid & & \\mid \\\\\n\\tb{v}_{1} & \\bar{v}_{2} & \\bar{v}_{3} & \\ldots & \\bar{v}_{m} \\\\\n\\mid & \\mid & \\mid & & \\mid\n\\end{array}\\right)\n\\]\n\nmust have a rank of $m$. This is because row reducing the matrix corresponds to the following relation:\n\n\\[c_1\\tb{v}_1+c_2\\tb{v}_2+c_3\\tb{v}_3+\\dots +c_m\\tb{v}_m=\\tb{0}\\]\n\n\\noindent\nAlso, $m\\leq n$ where $n$ is the number of rows in each column vector, in order to have linear independence for this set.\n\n\\subsection{Dimension}\n\nConsidering an $xy$-plane in $\\R^3$:\n\n\\[V=\\left\\{\\begin{bmatrix}s\\\\t\\\\0\\\\ \\end{bmatrix}\\Bigg| s,t \\in \\mathbb{R} \\right\\}\\]\n\nThe basis of this set contains 2 vectors (e.g. dimension of 2), with example being:\n\n\\[\\mathfrak{B}=\\left\\{\\begin{bmatrix}1\\\\0\\\\0 \\end{bmatrix} , \\begin{bmatrix} 0\\\\1\\\\0 \\end{bmatrix} \\right\\}\\]\n\n\\begin{framed}\n    If $V$ is a subspace of $\\R^n$ and $\\mathfrak{B}$ and $\\mathfrak{C}$ are two bases of $V$, then\n    $\\mathfrak{B}$ and $\\mathfrak{C}$ contain the same number of vectors.\n\\end{framed}\n\n\\textbf{Dimension} of a subspace is number of vectors in the basis.\n\n\\subsubsection{Example}\n\nConsidering the following matrix:\n\n\\[A=\\begin{bmatrix}\n    1&2&0&1&2\\\\\n    1&2&0&2&3\\\\\n    1&2&0&3&4\\\\\n    1&2&0&4&5\\\\\n    \\end{bmatrix}\\]\n\nBy discounting the redundant vectors, a possible basis for $\\mathrm{Im}(A)$:\n\n\\[\\mathfrak{B}_\\mathrm{image}=\\left \\{\\begin{bmatrix} 1\\\\1\\\\1\\\\1 \\end{bmatrix},\\begin{bmatrix}1\\\\2\\\\3\\\\4 \\end{bmatrix} \\right\\}\\]\n\nSo the dimension of $\\mathrm{Im}(A)$ is 2.\nFinding a basis for $\\mathrm{ker}(A)$ is the same as solving $A\\tb{x}=\\tb{0}$:\n\n\\[\\mbox{ker}(A)=\\left\\{\\begin{bmatrix}-2s-w\\\\ s\\\\t\\\\-w\\\\w \\end{bmatrix} \\Bigg| s,t,w\\in\\mathbb{R} \\right\\}=\n\\left\\{s\\begin{bmatrix}-2\\\\1\\\\0\\\\0\\\\0\\\\\\end{bmatrix}+t\\begin{bmatrix}0\\\\0\\\\1\\\\0\\\\0\\\\\\end{bmatrix}+w\\begin{bmatrix}-1\\\\0\\\\0\\\\-1\\\\1\\\\\\end{bmatrix}\\Bigg|s,t,w\\in\\mathbb{R}\\right\\}\\]\n\nSo the basis for $\\mathrm{ker}(A)$:\n\n\\[\\mathfrak{B}_\\mathrm{kernel}=\\left\\{\\begin{bmatrix}-2\\\\1\\\\0\\\\0\\\\0\\\\ \\end{bmatrix}, \\begin{bmatrix} 0\\\\0\\\\1\\\\0\\\\0\\\\ \\end{bmatrix}, \\begin{bmatrix}-1\\\\0\\\\0\\\\-1\\\\1\\\\ \\end{bmatrix} \\right\\}\\]\n\nAnd dimension of $\\mathrm{ker}(A)$ is 3.\nHowever, it is shown that $\\mathrm{rref}(A)$ gives dimension of \\textbf{image and kernel}.\n\n\\subsection{Rank-Nullity Theorem}\n\n\\begin{framed}\n    \\begin{itemize}\n        \\item If $T$ is a linear transformation, \n        then \\\\$\\mathrm{dim}(\\mathrm{Im}(T))+\\mathrm{dim}(\\mathrm{ker}(T))=\\text{dimension of domain of }T$\n        \\item If $A$ is a matrix, then $\\mathrm{rank}(A)+\\mathrm{nullity}(A)=\\text{number of columns of }A$\n        \\item In a linear system, \n        \\\\$\\text{number of leading variables}+\\text{number of free variables}=\\text{total number of variables}$\n    \\end{itemize}\n\\end{framed}\n\nConsidering non-invertible matrices $A$ and $B$, let $AB$ be invertible.\nIt must hold true that $\\mathrm{ker}(B)=\\{\\tb{0}\\}$. If the dimensions of $B$ are $p\\times n$,\n$\\mathrm{Im}(B)$ is a subspace of $\\R^p$ has dimension $n$. This means that it is a vertically rectangular\nmatrix with $n\\leq p$. Thus, $A$ is $n\\times p$ so it is horizontally rectangular.", "meta": {"hexsha": "3cfbc0d0cd138f29968274c6d2291baa0a93ed9e", "size": 3242, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/14_dimension.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/14_dimension.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/14_dimension.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.525, "max_line_length": 189, "alphanum_fraction": 0.6437384331, "num_tokens": 1214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.9111796991580949, "lm_q1q2_score": 0.7670544400062526}}
{"text": "\\section{Principle component analysis}\n\nIn principle component analysis (PCA) we assume a linear generative model of the form\nshown in equation \\eqref{eq:LGM} with $D = M$, i.e. a complete LGM, and independent sources\nof unequal variance such that $\\sigma_1^2 > \\sigma_2^2 > \\dots > \\sigma_M^2$. \nIf we further assume that the matrix $\\mb{A}$ is orthogonal such that \n$\\mb{A} \\mb{A}\\TT = \\imat_M$ we can show that the Eigendecomposition of the data\ncovariance matrix $\\mb{C}_x$ finds the linear transformation matrix $\\mb{A}$.\nWe noticed earlier that the data covariance matrix for an LGM of the given form \ncan be decomposed such that:\n\\begin{align}\n\t\\mb{C}_x = \\mb{A} \\mb{C}_s \\mb{A}\\TT\n\t\\label{eq:Cx_dec}\n\\end{align}\nWe can compare this result to the Eigendecomposition of a matrix:\n\\begin{align}\n\t\\mb{B} = \\mb{U} \\mb{D} \\mb{U}^{-1}\n\\end{align}\nwhere $\\mb{B}$ is an invertible $M \\times M$ matrix, $\\mb{U}$ is the matrix of Eigenvectors\nand $\\mb{D}$ is the diagonal matrix of Eigenvalues.\nWe further notice that for a real-valued symmetric matrix $\\mb{B}$ the Eigendecomposition\nis given by\n\\begin{align}\n\t\\mb{B} = \\mb{U} \\mb{D} \\mb{U}\\TT\n\\end{align}\nand has the same functional form as equation \\eqref{eq:Cx_dec}. Since a covariance matrix\nis always symmetric and can therefore be diagonalized we notice that $\\mb{C}_s = \\mb{D}$\nwith $\\sigma_1^2 > \\sigma_2^2 > \\dots > \\sigma_M^2$ is a\ndiagonal covariance matrix for the independent sources and that $\\mb{A} = \\mb{U}$ and \nis the matrix of Eigenvectors of $\\mb{C}_x$ where $\\mb{U} = \\{\\mb{u}_1, \\mb{u}_2, \\dots, \\mb{u}_M\\}$.\n\n\\paragraph{Whitening} If we now want to recover the independent sources we we can apply a decorrelating\ntransform based on the Eigenvector matrix of the data covariance matrix $\\mb{C}_x$. We noticed that\n$\\mb{U} = \\mb{A}$ and therefore we can find a backtransform such that\n\\begin{align}\n\t\\mb{x} &= \\mb{U s} \\\\\n\t\\mb{U \\TT x} &= \\underbrace{\\mb{U\\TT U}}_{ = \\imat_M} \\mb{s} \\\\\n    \\mb{s} &= \\mb{U\\TT x}\n\\end{align}\nwhere we have removed correlations between vector dimensions. If we want to reduce the dimensionality\nof our data we simply use the first $K$ Eigenvectors of $\\mb{U}$ which are called the $K$ principle\ncomponents of $X$. It is important to note here that bacause $\\sigma_1^2 > \\sigma_2^2 > \\dots > \\sigma_M^2$\nprojecting the data on the $K$ principle components leads to a projection to the $K$-dimensional subspace \nof highest variance. If we want to remove the difference in variance such that \n$\\sigma_1^2 = \\sigma_2^2 = \\dots = \\sigma_M^2$, we can introduce isovariance by applying the transform\n\\begin{align}\n\t\\mb{\\tilde{s}} = \\mb{D}^{-\\frac{1}{2}} \\mb{s}\n\\end{align}\nThis approach is called whitening. After the whitening we can be sure that a linear transform will\nnot introduce correlations between dimensions (see \\ref{par:cov_isovar}).\n\n\\paragraph{How to use PCA on data}\nGiven $\\mb{X} = (\\mb{x_1}, \\dots, \\mb{x_N})$ with $\\mb{x_n}$ being a column vector of length $M$. \nEach column vector represents an observation. We can calculate the empirical mean by \n\\begin{align}\n\t\\hat{\\greekvec{\\mu}} = \\frac{1}{N} \\mb{X \\ivec_M}\n\\end{align}\nFrom now on we will assume that data matrices have zero mean, i.e. \n\\begin{align*}\n\t\\mb{X} = \\mb{X} - \\greekvec{\\mu}\\ivec_M\\TT\n\\end{align*}\nand that $N > M$. The empirical covariance matrix is then given by:\n\\begin{align}\n\t\\begin{split}\n\t\\hat{\\mb{C}} &= \\frac{1}{N} \\mb{X X \\TT} \\\\\n\t             &= \\frac{1}{N} \\sum_{n = 1}^N \\mb{x_n x_n}\n\t\\end{split}\n\\end{align}\n\n\\subsection{Singular value decomposition}\nIn some cases it can be easier to find the singular value decomposition (SVD) of a data matrix\nrather than finding the Eigendecomposition of the empirical covariance matrix. In this section\nwe will shortly introduce SVD and show it's relationship to PCA.\\\\\nSVD is a generalization of the Eigendecomposition which can decompose any matrix into different \nfactors such that for a $M \\times N$ real matrix $\\mb{X}$ we find\n\\begin{align}\n\t\\mb{X} = \\mb{U S V\\TT}\n\\end{align}\nwhere $\\mb{U}$ is a $M \\times M$ orthogonal matrix, $\\mb{S}$ is a $M \\times N$  diagonal matrix\nwhere the values on the diagonal called the singular values, and $\\mb{V}$ is a $N \\times N$ \northogonal matrix. The SVD of a diagonizable matrix is equivalent to the Eigendecomposition \nof that matrix. A unique solution for SVD exists if all values on the sigular values are different. \\\\\n\n\\noindent To show the relationship between SVD and PCA we will decompose the empirical covariance matrix\ninto the data matrix as above and then apply SVD to further decompose the data matrices:\n\\begin{align}\n\t\\begin{split}\n\tN \\hat{\\mb{C}} &= \\mb{X X \\TT} \\\\\n\t               &= \\mb{U S V\\TT} \\left( \\mb{U S V\\TT} \\right)\\TT \\\\\n   \t               &= \\mb{U S} \\underbrace{\\mb{V\\TT V}}_{= \\imat_N} \\mb{S\\TT U\\TT}\\\\\n   \t               &= \\mb{U S S\\TT U\\TT}\\\\\n\t\\end{split}\n\\end{align}\n\\noindent We notice that $\\mb{S S\\TT} = \\mb{D}$ is the matrix of Eigenvalues for $\\mb{X X\\TT}$ and\n$\\mb{U}$ is the matrix of Eigenvectors. That is the singular values of the data matrix represent \nthe standard deviation in the priniciple directions, whereas the Eigenvalues of $\\mb{X X\\TT}$ \nrepresent the variance in the principle directions.\n\n\\subsubsection{SVD of the Gram matrix}\nIn kernel methods we often deal with a gram matrix $\\mb{G}$ of the form:\n\\begin{align}\n\t\\mb{G} = \\frac{1}{N} \\mb{X\\TT X}\n\\end{align}\nwhich is represented by the scalar product between any pair of observations. If we perform\nSVD on the gram matrix we find that:\n\\begin{align}\n\t\\begin{split}\n\tN \\mb{G} &= \\left( \\mb{U S V\\TT} \\right) \\TT \\mb{U S V\\TT} \\\\\n\t\t\t &= \\mb{V S\\TT} \\underbrace{\\mb{U\\TT U}}_{= \\imat_K} \\mb{S V\\TT}\t \\\\\n\t\t\t &= \\mb{V S\\TT S V\\TT}\n\t\\end{split}\t\t\t\n\\end{align}\nThis decomposition is referred to as Kernel PCA. For more information on the topic see \n\\cite[Chapter 6 \\& 12.3]{Bishop2006}\n\n\\subsection{Model comparison}\nIf we want to perform model comparison we can estimate the posterior probability of our \nmodel given the data based on Bayes theorem:\n\\begin{align}\n\tP(M|X) = \\frac{1}{Z} P(X|M)P(M)\n\\end{align}\nDependent on our preferences towards a class of models we can specify the prior probability of\na model by $P(M)$. If we do not want to make assumptions about $P(M)$ or just for convenience\nwe sometimes assume $P(M) = const.$ which is equivalent to a Likelihood-based model comparison.\n\nGiven we have observed i.i.d. data represented in a $M \\times N$ matrix:\n\\begin{align}\n\t\\mb{X} = \\left( \\underbrace{\\mb{x_1}, \\dots, \\mb{x_N}}_{\\text{i.i.d samples}} \\right)\n\\end{align}\nand we assume $P(M) = const.$, then $P(M|X)$ is proportional to the likelihood of the \ndata given a model such that:\n\\begin{align}\n\t\\begin{split}\n\tP(M|X) \\varpropto \\prod_{n=1}^N \\rho(\\mb{x_n}|M) \n\t    &= \\exp \\left( \\sum_{n=1}^N \\underbrace{\\log \\left( \\rho(\\mb{x_n}|M) \\right)}_{\\text{Log-likelihood}} \\right)\n\t\\end{split}\n\\end{align}\n\\noindent For the Gaussian with $\\rho(\\mb{x_n}|M) = \\mathcal{N}(\\mb{x_n}|0,\\mb{C})$ the likelihood becomes:\n\\begin{align}\n\t\\begin{split}\n\t\\prod_{n=1}^N \\rho(\\mb{x_n}|M) \n\t        &= \\exp \\left( \\sum_{n=1}^N \\log \\left( \\normpdfd \\right) \\right) \\\\\n\t        &= \\exp \\left( \\sum_{n=1}^N -\\frac{1}{2}\\log \\left( 2\\pi^M |\\mb{C}| \\right) -\\frac{1}{2} \\mb{x_n \\TT C^{-1} x_n} \\right) \\\\\n\t        &= \\exp \\left( -\\frac{N}{2}\\log \\left( 2\\pi^M |\\mb{C}| \\right) -\\frac{1}{2} \\sum_{n=1}^N \\mb{x_n \\TT C^{-1} x_n} \\right) \\\\\n\t\\end{split}\n\\end{align}\n\n\\subsubsection{The rescaling problem}\nWe will now consider the rescaling problem. If we rescale a random variable using a linear transform\nthe probability density of the respective linear mapping is also rescaled. As a result the likelihood\nfunction of the two random variable has a different scale.\n\\begin{example}[The rescaling problem] \\label{ex:rescaling}\nConsider a one-dimensional linear mapping of the form\n\\begin{align}\n\ty &= \\lambda x\n\\end{align}\nwith \n\\begin{align*}\n\tx \\sim \\mathcal{N}(0,\\sigma^2) \\qquad \\text{ and } \\qquad\n\ty \\sim \\mathcal{N}(0,\\lambda^2 \\sigma^2)\n\\end{align*}\nthen\n\\begin{align}\n\t\\begin{split}\n\t\\rho_y(y) &= \\frac{1}{\\sqrt{2\\pi \\lambda^2 \\sigma^2}} \\exp \\left( \\frac{y^2}{2 \\lambda^2 \\sigma^2} \\right)\\\\\n\t         &= \\frac{1}{\\lambda} \\frac{1}{\\sqrt{2\\pi \\sigma^2}} \\exp \\left( \\frac{\\lambda^2 x^2}{2 \\lambda^2 \\sigma^2} \\right)\\\\\n\t         &= \\frac{1}{\\lambda} \\rho_x(x)\n\t\\end{split}\t         \n\\end{align}\nis the relationship between the two probability densities.\n\\end{example}\n\\noindent The likelihood depends on the scale of a random variable. Thus all models should be evaluated with\nrespect to the same scale for model comparison with the likelihood measure. Or differently, the likelihood is\na relative measure, not an absolute one.\n\n\\begin{proposition}[Change of variables]\nGiven an invertible nonlinear mapping of the form:\n\\begin{align*}\n\t\\mb{x} &  \\stackrel{f}{\\longrightarrow} \\mb{y} \\\\\n\t\\mb{x} &  \\stackrel{g = f^{-1}}{\\longleftarrow} \\mb{y}\n\\end{align*}\nIf the probability density function $\\rho_{\\mb{x}}(\\mb{x})$ of a random variable \n$X$ is known we can calculate the\nprobability density $\\rho_{\\mb{y}}(\\mb{y})$. This is called a change of variables.\nWe know that the probability under the differential area is unchanged under the \nchange of variables:\n\\begin{align}\n\t\\rho_{\\mb{y}}(\\mb{y}) \\mathrm{d}\\mb{y} = \\rho_{\\mb{x}}(\\mb{x}) \\mathrm{d}\\mb{x}\n\\end{align}\nand hence the probability density $\\rho_{\\mb{y}}(\\mb{y})$ can be calculated by\n\\begin{align}\n\t\\begin{split}\n\t\\rho_{\\mb{y}}(\\mb{y}) \n\t&= \\rho_{\\mb{x}}(\\mb{x})  \\begin{vmatrix}\\frac{\\mathrm{d}\\mb{x}}{\\mathrm{d}\\mb{y}}\\end{vmatrix} \\\\\n\t&= \\rho_{\\mb{x}}(g(\\mb{y})) \\begin{vmatrix}\\frac{\\mathrm{d}g}{\\mathrm{d}\\mb{y}}\\end{vmatrix} \\\\\n\t&= \\frac{\\rho_{\\mb{x}}(f^{-1}(\\mb{y}))}{\\begin{vmatrix}\\frac{\\mathrm{d}f}{\\mathrm{d}\\mb{x}} f^{-1}(\\mb{y})\\end{vmatrix}}\t\n\t\\end{split}\n\\end{align}\nwhere\n\\begin{align}\n\t\\begin{vmatrix}\\frac{\\mathrm{d}\\mb{y}}{\\mathrm{d}\\mb{x}}\\end{vmatrix}\n\t    = |J|\n\t    = \\begin{vmatrix}\n\t    \t\\frac{\\mathrm{d}y_1}{\\mathrm{d}x_1} & \\cdots & \\frac{\\mathrm{d}y_M}{\\mathrm{d}x_1} \\\\\n\t    \t\\vdots & \\ddots & \\vdots \\\\\n\t    \t\\frac{\\mathrm{d}y_1}{\\mathrm{d}x_M} & \\cdots & \\frac{\\mathrm{d}y_M}{\\mathrm{d}x_M} \\\\\n\t    \\end{vmatrix}\n\\end{align}\nis the Jacobian determinant. For more information see \\cite[p.18, p.247]{Bishop2006}. In example\n\\ref{ex:rescaling} from above the transform can be simply read out as:\n\\begin{align}\n\t\\rho_{\\mb{y}}(\\mb{y}) = \\frac{1}{\\lambda} \t\\rho_{\\mb{x}} \\left( \\frac{\\mb{y}}{\\lambda} \\right)\n\\end{align}\n\\end{proposition}\n\n\\subsubsection{Generally for LGMs}\nWe will now come back to our linear generative model of the form\n\\begin{align*}\n\tf: \\qquad \\mb{x} = \\mb{A s} = \\mb{U s}\n\\end{align*}\nwhere $\\mb{U}$ is the Eigenvector basis of the covariance matrix $\\mb{C}_x$.\nIf we now want to find the change of variables from $\\rho_\\mb{x}(\\mb{x})$ to $\\rho_\\mb{s}(\\mb{s})$:\n\\begin{align}\n\t\\rho_{\\mb{S}}(\\mb{s}) \n\t&= \\rho_{\\mb{x}}(\\mb{x})  \\begin{vmatrix}\\frac{\\mathrm{d}\\mb{x}}{\\mathrm{d}\\mb{s}}\\end{vmatrix} \\nonumber \\\\\n\t&= \\rho_{\\mb{x}}(\\mb{x})  \\begin{vmatrix}\\frac{\\mathrm{d}f(\\mb{s})}{\\mathrm{d}\\mb{s}}\\end{vmatrix}\n\\end{align}\nwe notice that\n\\begin{align}\n\t\\begin{vmatrix}\\frac{\\mathrm{d}f(\\mb{s})}{\\mathrm{d}\\mb{s}}\\end{vmatrix} = |\\det(\\mb{U})|\n\\end{align}\nsince\n\\begin{equation*}\n\t%\\left. \\begin{aligned}\n\t\tf(\\mb{s}) = \\mb{U s}  \\qquad \\text{and} \\qquad\n\t\t\\mb{s} = \\mb{U\\TT x}                                   \n\t\t%\\mb{s} &= g(\\mb{x}) = \\mb{U\\TT x} \\\\\n\t\t%f(\\mb{s}) &= g^{-1}(\\mb{x}) = \\mb{U s} \\\\\n\t%\\end{aligned} \\qquad \\right\\}\n    %\\qquad \\begin{vmatrix}\\frac{\\mathrm{d}f}{\\mathrm{d}\\mb{s}}\\end{vmatrix} = |\\det(\\mb{U})|\n\\end{equation*}\nWe further find that\n\\begin{align*}\n\t|\\det(\\mb{U})| = \\sqrt{\\det(\\mb{U})^2} %\\\\\n\t               = \\sqrt{\\det(\\mb{U}) \\det(\\mb{U}\\TT)} %\\\\\n\t               = \\sqrt{\\det(\\mb{U U\\TT})} %\\\\\n\t               = \\sqrt{\\det(\\imat_M)} %\\\\\n\t               = 1\n\\end{align*}\nAs a result the change of variables reduces to the form\n\\begin{align}\n\t\\rho_{\\mb{s}}(\\mb{s}) = \\rho_{\\mb{x}}(\\mb{U s})\n\\end{align}\nand vice versa\n\\begin{align}\n\t\\rho_{\\mb{x}}(\\mb{x}) = \\rho_{\\mb{s}}(\\underbrace{\\mb{U\\TT x}}_{\\mb{s}})\n\t                      = \\prod_{m=1}^M \\rho(s_m)\n\\end{align}\n\\begin{proposition}[Necessary condition]\nFor all $\\mb{U}$ with the same Jacobian determinant the likelihood must be largest\nfor the true generating model.\n\\end{proposition}", "meta": {"hexsha": "877a96adc7ac86f3cd976e92a18e14d8f55309f0", "size": 12356, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture11/lecture11.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/lecture11/lecture11.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/lecture11/lecture11.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.1603053435, "max_line_length": 132, "alphanum_fraction": 0.6643735837, "num_tokens": 4237, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328345, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.767022489617522}}
{"text": "\\section{Approximation}{}{}\\label{sec:Approximation of differential equations}\nWe have seen how to solve a restricted collection of differential\nequations, or more  accurately, how to attempt to solve them---we still may\nnot be able to find the required anti-derivatives. Not surprisingly,\nnon-linear equations can be even more difficult to solve. Yet much is\nknown about solutions to some more general equations.\n\nSuppose $\\phi(t,y)$ is a function of two variables. A more general\nclass of first order differential equations has the form $\\ds y'=\\phi(t,y)$.\nThis is not necessarily a linear first order equation,\nsince $\\phi$ may depend on $y$ in some complicated way; note however\nthat $\\ds y'$ appears in a very simple form. Under suitable\nconditions on the function $\\phi$, it can be shown that every such\ndifferential equation has a solution, and moreover that for each\ninitial condition the associated initial value problem has exactly one\nsolution. In practical applications this is obviously a very desirable\nproperty. \n\n\\begin{example}{First Order Non-linear}{First Order Non-linear}\\label{First Order Non-linear}\n The equation $\\ds y'=t-y^2$ is a first order non-linear\nequation, because $y$ appears to the second power. We will not be able\nto solve this equation.\n\\end{example}\n\n\\begin{example}{Non-linear and Separable}{Non-linear and Separable}\\label{Non-linear and Separable}\n The equation $\\ds y'=y^2$ is also non-linear, but it is\nseparable and can be solved by separation of variables.\n\\end{example}\n\nNot all differential equations that are important in practice can be\nsolved exactly, so techniques have been developed to approximate\nsolutions. We describe one such technique, \\dfont{Euler's Method}, which is simple though not particularly\nuseful compared to some more sophisticated techniques.\n\nSuppose we wish to approximate a solution to the initial value problem\n$\\ds y'=\\phi(t,y)$, $\\ds y(t_0)=y_0$, for $t\\ge t_0$. Under\nreasonable conditions on $\\phi$, we know the solution exists,\nrepresented by a curve in the $t$-$y$ plane; call this solution\n$f(t)$. The point $\\ds (t_0,y_0)$ is of course on this curve. We also\nknow the slope of the curve at this point, namely\n$\\ds\\phi(t_0,y_0)$. If we follow the tangent line for a brief\ndistance, we arrive at a point that should be almost on the graph of\n$f(t)$, namely $\\ds(t_0+\\Delta t, y_0+\\phi(t_0,y_0)\\Delta t)$; call\nthis point $\\ds(t_1,y_1)$. Now we pretend, in effect, that this point\nreally is on the graph of $f(t)$, in which case we again know the\nslope of the curve through $\\ds(t_1,y_1)$, namely\n$\\ds\\phi(t_1,y_1)$. So we can compute a new point,\n$\\ds(t_2,y_2)=(t_1+\\Delta t, y_1+\\phi(t_1,y_1)\\Delta t)$ that \nis a little farther along, still close to the graph of $f(t)$ but\nprobably not quite so close as $\\ds(t_1,y_1)$. We can continue in this\nway, doing a sequence of straightforward calculations, until we have\nan approximation $\\ds(t_n,y_n)$ for whatever time $\\ds t_n$ we need. \nAt each step we do essentially the same calculation, namely:\n$$(t_{i+1},y_{i+1})=(t_i+\\Delta t, y_i+\\phi(t_i,y_i)\\Delta t).$$\n\nWe expect that smaller time steps $\\Delta t$ will give better\napproximations, but of course it will require more work to compute to\na specified time. It is possible to compute a guaranteed upper bound\non how far off the approximation might be, that is, how far $\\ds y_n$\nis from $f(t_n)$. Suffice it to say that the bound is not particularly\ngood and that there are other more complicated approximation\ntechniques that do better.\n\n\\begin{example}{Approximating a Solution}{Approximating a Solution}\\label{Approximating a Solution}\nCompute an approximation to the solution for $\\ds y'=t-y^2$, $y(0)=0$, when $t=1$.\n\\end{example}\n\n\\begin{solution}\nWe will use $\\Delta t=0.2$, which is\neasy to do even by hand, though we should not expect the resulting\napproximation to be very good. We get\n\\begin{eqnarray*}\n(t_1,y_1)&=(0+0.2,0+(0-0^2)0.2) = (0.2,0)\\cr\n(t_2,y_2)&=(0.2+0.2,0+(0.2-0^2)0.2) = (0.4,0.04)\\cr\n(t_3,y_3)&=(0.6,0.04+(0.4-0.04^2)0.2) = (0.6,0.11968)\\cr\n(t_4,y_4)&=(0.8,0.11968+(0.6-0.11968^2)0.2) = (0.8,0.23681533952)\\cr\n(t_5,y_5)&=(1.0,0.23681533952+(0.6-0.23681533952^2)0.2) = (1.0,0.385599038513605)\n\\end{eqnarray*}\nSo $y(1)\\approx 0.3856$. As it turns out, this is not accurate to\neven one decimal place. Figure~\\ref{fig:euler method vs rk} shows\nthese points connected by line segments (the lower curve) compared to\na solution obtained by a much better approximation technique. Note\nthat the shape is approximately correct even though the end points are\nquite far apart.\n\n\\figure[H]\n%\\texonly\n\\centerline{\\vbox{\\beginpicture\n\\normalgraphs\n%\\sevenpoint\n\\setcoordinatesystem units <8truecm,8truecm>\n\\setplotarea x from 0 to 1.05, y from 0 to 0.55\n\\axis left shiftedto x=0 ticks length <2pt> numbered from 0 to 0.5 by 0.5 /\n\\axis bottom shiftedto y=0 ticks length <2pt> numbered from 0 to 1 by 1 /\n\\put {$t$} [tl] <0pt,-3pt> at 1.06 0\n\\put {$y$} [b] <0pt,3pt> at 0 0.56\n\\setlinear\n\\plot \n0 0\n0.2 0.0000\n0.4 0.0400\n0.6 0.1196\n0.8 0.2368\n1.0 0.3855 /\n\\setquadratic\n\\plot 0  0  \n0.025000000000000001  0.00031249951171971195 \n0.050000000000000003  0.0012499843752447799  \n0.075000000000000011 0.0028123813539146945  \n0.10000000000000001 0.0049995000624952881  \n0.125  0.0078109744935353819 \n0.14999999999999999  0.0112462047261264  \n0.17499999999999999 0.015304298951036615  \n0.19999999999999998  0.019984015983738772 \n0.22499999999999998  0.025283708473608849  \n0.24999999999999997 0.031201267053176683  \n0.27499999999999997  0.037734065705321729 \n0.29999999999999999  0.044878908658235558  \n0.32500000000000001 0.052631979147269851  \n0.35000000000000003  0.060988790408866761 \n0.37500000000000006  0.069944139294007487  \n0.40000000000000008 0.079492062906380986  \n0.4250000000000001  0.089625798683132307 \n0.45000000000000012  0.10033774834298456  \n0.47500000000000014 0.11161944612716239  \n0.50000000000000011  0.12346153175236174 \n0.52500000000000013  0.1358537284815772  \n0.55000000000000016 0.14878482669758133  \n0.57500000000000018  0.16224267333504916 \n0.6000000000000002  0.17621416749066984  \n0.62500000000000022 0.1906852624861928  \n0.65000000000000024  0.20564097460749087 \n0.67500000000000027  0.22106539868385133  \n0.70000000000000029 0.23694173060647841  \n0.72500000000000031  0.25325229681444411 \n0.75000000000000033  0.26997859070107927  \n0.77500000000000036 0.28710131581523379  \n0.80000000000000038  0.30460043565128503 \n0.8250000000000004  0.32245522974067869  \n0.85000000000000042 0.34064435567768192  \n0.87500000000000044  0.35914591663448664 \n0.90000000000000047  0.37793753384740725  \n0.92500000000000049 0.39699642348821867  \n0.95000000000000051  0.41629947727413563 \n0.97500000000000053  0.4358233461178857  \n1.0000000000000004 0.45554452607694396 /\n\\setplotsymbol ({\\small.})\n\\plotsymbolspacing=.2pt\n\\arrow <4pt> [0.35, 1] from 1.05 0 to 1.06 0\n\\arrow <4pt> [0.35, 1] from 0 0.55 to 0 0.56\n\\endpicture}}\n\\caption{\\label{fig:euler method vs rk}\nApproximating a solution to $\\ds y'=t-y^2$, $y(0)=0$.}\n%\\endtexonly\n%\\figrdef{fig:euler method vs rk}\n%\\htmlfigure{DE-approximate_solution.html}\n%\\begincaption\n%Approximating a solution to $\\dsy'=t-y^2$, $y(0)=0$.\n%\\endcaption\n\\endfigure\n\nIf you need to do Euler's method by hand, it is useful to construct a\ntable to keep track of the work, as shown in Figure~\\ref{fig:eulers method table}.\nEach row holds the computation for a single step: The starting point\n$(t_i,y_i)$; the stepsize $\\Delta t$; the computed slope\n$\\phi(t_i,y_i)$; the change in $y$, $\\Delta y=\\phi(t_i,y_i)\\Delta t$;\nand the new point, $(t_{i+1},y_{i+1})=(t_i+\\Delta t,y_i+\\Delta y)$. The starting point in\neach row is the newly computed point from the end of the previous row.\n\n\\figure[H]\n%\\texonly\n%\\stablestyle3\n%\\null\n$$\\begin{array}{|l|l|l|l|l|}\n\\hline\n (t,y) &  \\Delta t &  \\phi(t,y) &  \\Delta y=\\phi(t,y)\\Delta\n  t &  (t+\\Delta t,y+\\Delta y) \\\\\\hline\n (0,0) \\hfill&  0.2  \\hfill& 0 \\hfill& 0 \\hfill&  (0.2,0) \\hfill\\\\\\hline\n (0.2,0) \\hfill&  0.2  \\hfill&  0.2  \\hfill&  0.04  \\hfill&  (0.4,0.04) \\hfill\\\\\\hline\n (0.4,0.04) \\hfill&  0.2  \\hfill&  0.3984  \\hfill&  0.07968  \\hfill&  (0.6,0.11968) \\hfill\\\\\\hline\n (0.6,0.11968) \\hfill&  0.2  \\hfill&  0.58\\ldots  \\hfill&  0.117\\ldots  \\hfill&  (0.8,0.236\\ldots) \\hfill\\\\\\hline\n (0.8,0.236\\ldots) \\hfill&  0.2  \\hfill&  0.743\\ldots  \\hfill&  0.148\\ldots   \\hfill&  (1.0,0.385\\ldots) \\hfill\\\\\n\\hline\n\\end{array}$$\n%\\endtexonly\n%\\figrdef{fig:eulers method table}\n%\\htmlfigure{DE-eulers_method_table.html}\n\\caption{\\label{fig:eulers method table}Computing with Euler's Method.}\n%\\endcaption\n\\endfigure\n\\end{solution}\n\nEuler's method is related to another technique that can help in\nunderstanding a differential equation in a qualitative way. Euler's\nmethod is based on the ability to compute the slope of a solution\ncurve at any point in the plane, simply by computing $\\phi(t,y)$. If\nwe compute $\\phi(t,y)$ at many points, say in a grid, and plot a small\nline segment with that slope at the point, we can get an idea of how\nsolution curves must look. Such a plot is called a \n\\dfont{ slope field\\index{slope field}}. A slope field for \n$\\ds\\phi=t-y^2$ is shown in Figure~\\xrefn{fig:slope field}; compare\nthis to figure~\\xrefn{fig:euler method vs rk}.\nWith a little practice, one can sketch reasonably accurate solution\ncurves based on the slope field, in essence doing Euler's method\nvisually.\n\n\\figure[H]\n%\\texonly\n\\hbox to \\hsize{\\hss\n\\epsfxsize6.5cm\\epsfbox{images/slope_field.eps}\n\\hss}\n%\\endtexonly\n%\\figrdef{fig:slope field}\n%\\htmlfigure{DE-slope_field.html}\n\\caption{\\label{fig:slope field}\nA slope field for $\\ds y'=t-y^2$.}\n\\endfigure\n\nEven when a differential equation can be solved explicitly, the slope\nfield can help in understanding what the solutions look like with\nvarious initial conditions. Recall the logistic equation \n%from exercise~\\xrefn{exer:logistic equation} in  section~\\xrefn{sec:first order differential equations}, \n$\\ds y' = ky(M-y)$: $y$ is a population at time $t$, $M$ is a measure of how\nlarge a population the environment can support, and $k$ measures the\nreproduction rate of the population.\nFigure~\\xrefn{fig:logistic slope field} shows a slope field\nfor this equation that is quite informative. \nIt is apparent that if the initial population is smaller than $M$ it\nrises to $M$ over the long term, while if the initial population is\ngreater than $M$ it decreases to $M$.\n%\\texonly\n%It is quite easy to\n%generate slope fields with Sage; follow the AP link in the figure caption.\n%\\endtexonly\n\n\\figure[H]\n%\\texonly\n\\hbox to \\hsize{\\hss\n\\epsfxsize12cm\\epsfbox{images/logistic_slope_field.eps}\n\\hss}\n%\\begincaption\n%A slope field for $\\dsy'=0.2y(10-y)$.\n%(\\expandafter\\url\\expandafter{\\sageurl logistic_slope_field}%\n%AP\\endurl)\n%\\endcaption\n%\\endtexonly\n%\\figrdef{fig:logistic slope field}\n%\\htmlfigure{DE-slope_field_logistic.html}\n\\caption{\\label{fig:logistic slope field}\nA slope field for $\\ds y'=0.2y(10-y)$.}\n%\\endcaption\n\\endfigure\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:Approximation of differential equations}}\n\n\\begin{enumialphparenastyle}\n\nIn the following exercises, compute the Euler approximations for the initial\nvalue problem for $0\\le t\\le 1$ and $\\Delta t=0.2$. If you have access\nto Sage, generate the slope field first and attempt to sketch the\nsolution curve. Then use Sage to compute better approximations with\nsmaller values of $\\Delta t$.\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'=t/y$, $y(0)=1$\n\\begin{sol}\n $y(1)\\approx 1.355$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'=t+y^3$, $y(0)=1$\n\\begin{sol}\n $y(1)\\approx 40.31$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'=\\cos(t+y)$, $y(0)=1$\n\\begin{sol}\n $y(1)\\approx 1.05$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n $\\ds y'=t\\ln y$, $y(0)=2$\n\\begin{sol}\n $y(1)\\approx 2.30$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "dd2fcff531b5077b223e59ddd3e636c876977e7d", "size": 11901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-4-approximation-de.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-4-approximation-de.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-4-approximation-de.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.4072847682, "max_line_length": 113, "alphanum_fraction": 0.7375850769, "num_tokens": 4119, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772482857833, "lm_q2_score": 0.8774767906859264, "lm_q1q2_score": 0.7669824986373948}}
{"text": "\\section{The Fundamental Theorem of Calculus}\\label{sec:FTC}\r\nConsider the setting where we know the position function $s(t)$ of an object moving along an axis, as well as its corresponding velocity function $v(t)$, and for the moment let us assume that $v(t)$ is positive on $[a,b]$.  Then, as shown in Figure~\\ref{F:4.4.FTCVel},\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_4_FTCVel}\r\n\\caption{Finding the distance traveled when we know an object's velocity function $v$.} \\label{F:4.4.FTCVel}\r\n\\end{center}\r\n\\end{figure}\r\nwe know two different perspectives on the distance, $D$, the object travels: one is that $D = s(b) - s(a)$, which is the object's change in position.  The other is that the distance traveled is the area under the velocity curve, which is given by the definite integral, so $D = \\int_a^b v(t) \\, dt$.\r\n\r\nOf course, since both of these expressions tell us the distance traveled, it follows that they are equal, so\r\n\\begin{equation} \\label{E:FTCVel}\r\ns(b) - s(a) = \\int_a^b v(t) \\, dt.\r\n\\end{equation}\r\nFurthermore, we know that Equation~(\\ref{E:FTCVel}) holds even when velocity is sometimes negative, since $s(b) - s(a)$ is the object's change in position over $[a,b]$, which is simultaneously measured by the total net signed area on $[a,b]$ given by $\\int_a^b v(t) \\, dt$.\r\n\r\nPerhaps the most powerful part of Equation~(\\ref{E:FTCVel}) lies in the fact that we can compute the integral's value if we can find a formula for $s$.  Remember, $s$ and $v$ are related by the fact that $v$ is the derivative of $s$, or equivalently that $s$ is an antiderivative of $v$.  For example, if we have an object whose velocity is $v(t) = 3t^2 + 40$ feet per second (which is always nonnegative), and wish to know the distance traveled on the interval $[1,5]$, we have that\r\n\\begin{eqnarray*}\r\nD & = & \\int_1^5 v(t) \\,dt \\\\\r\n\t& = & \\int_1^5 (3t^2 + 40) \\, dt \\\\\r\n\t& = & s(5) - s(1),\r\n\\end{eqnarray*}\r\nwhere $s$ is an antiderivative of $v$.  We know that the derivative of $t^3$ is $3t^2$ and that the derivative of $40t$ is $40$, so it follows that if $s(t) = t^3 + 40t$, then $s$ is a function whose derivative is $v(t) = s'(t) = 3t^2 + 40$, and thus we have found an antiderivative of $v$.  Therefore,\r\n\\begin{eqnarray*}\r\nD & = & \\int_1^5 3t^2 + 40 \\, dt \\\\\r\n\t& = & s(5) - s(1) \\\\\r\n\t& = & (5^3 + 40 \\cdot 5) - (1^3 + 40\\cdot 1) \\\\\r\n\t& = & 284 \\ \\mbox{feet}.\r\n\\end{eqnarray*} \r\nNote the key lesson of this example:  to find the distance traveled, we needed to compute the area under a curve, which is given by the definite integral.  But to evaluate the integral, we found an antiderivative, $s$, of the velocity function, and then computed the net change in $s$ on the interval.  In particular, observe that we have found the exact area of the region shown in Figure~\\ref{F:4.4.FTCVel2}, and done so without a familiar formula (such as those for the area of a triangle or circle) and without directly computing the limit of a Riemann sum.\r\n\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_4_FTCVel2}\r\n\\caption{The exact area of the region enclosed by $v(t) = 3t^2 + 40$ on $[1,5]$.} \\label{F:4.4.FTCVel2}\r\n\\end{center}\r\n\\end{figure}\r\n\r\nAs we proceed to thinking about contexts other than just velocity and position, it turns out to be advantageous to have a shorthand symbol for a function's antiderivative.  In the general setting of a continuous function $f$, we will often denote an antiderivative of $f$ by $F$, so that the relationship between $F$ and $f$ is that $F'(x) = f(x)$ for all relevant $x$.  Using the notation $V$ in place of $s$ (so that $V$ is an antiderivative of $v$) in Equation~(\\ref{E:FTCVel}), we find it is equivalent to write that\r\n\\begin{equation} \\label{E:FTCV}\r\nV(b) - V(a) = \\int_a^b v(t) \\, dt.\r\n\\end{equation}\r\n Now, in the general setting of wanting to evaluate the definite integral $\\int_a^b f(x) \\, dx$ for an arbitrary continuous function $f$, we could certainly think of $f$ as representing the velocity of some moving object, and $x$ as the variable that represents time.  And again, Equations~(\\ref{E:FTCVel}) and~(\\ref{E:FTCV}) hold for any continuous velocity function, even when $v$ is sometimes negative.   This leads us to see that Equation~(\\ref{E:FTCV}) tells us something even more important than the change in position of a moving object: it offers a shortcut route to evaluating any definite integral, provided that we can find an antiderivative of the integrand.  The Fundamental Theorem of Calculus (FTC) \\index{FTC} summarizes these observations.\r\n \r\n \\begin{theorem}{Fundamental Theorem of Calculus}{fundamental_theorem_I}\r\n Suppose that $f(x)$ is\r\n continuous on the interval $[a,b]$. If $F(x)$ is any antiderivative of\r\n $f(x)$, then \r\n $$\r\n   \\int_a^b f(x)\\,dx = F(b)-F(a).\r\n $$\r\n \\end{theorem}\r\n \r\nNote that we will prove Theorem \\ref{thm:fundamental_theorem_I} in Section \\ref{sec:FTC2}. \\\\ \r\n\r\nA common alternate notation for $F(b) - F(a)$ is \r\n$$F(b) - F(a) = \\left.  F(x) \\right|_a^b,$$\r\nwhere we read the righthand side as ``the function $F$ evaluated from $a$ to $b$.''  In this notation, the FTC says that\r\n$$\\int_a^b f(x) \\, dx = \\left. F(x) \\right|_a^b.$$\r\n\r\nThe FTC opens the door to evaluating exactly a wide range of integrals.  In particular, if we are interested in a definite integral for which we can find an antiderivative $F$ for the integrand $f$, then we can evaluate the integral exactly.  For instance since $\\frac{d}{dx}[\\frac{1}{3}x^3] = x^2$, the FTC tells us that\r\n\\begin{eqnarray*}\r\n\t\\int_0^1 x^2 \\, dx & = & \\left. \\frac{1}{3} \\, x^3 \\right|_0^1 \\\\\r\n\t\t\t\t& = & \\frac{1}{3} \\, (1)^3 - \\frac{1}{3} \\, (0)^3 \\\\\r\n\t\t\t\t& = & \\frac{1}{3}.\r\n\\end{eqnarray*}\r\n\r\n\\begin{example}{Fundamental Theorem of Calculus}{FundamentalTheoremCalculus}\r\nEvaluate $\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx $.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n\\[ \\begin{array}{lcl}\r\n\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx \r\n\t& = & \\ds\\left.\\frac{x^4}{4}+\\frac{2x^{3/2}}{3}-x^{-1}\\right|_1^4\\\\\r\n\\\\\r\n\t& = & \\ds\\left(\\frac{(4)^4}{4}+\\frac{2(4)^{3/2}}{3}-4^{-1}\\right) \\\\\r\n\\\\\r\n\t& & \\ds-\\left(\\frac{(1)^4}{4}+\\frac{2(1)^{3/2}}{3}-1^{-1}\\right)\\\\\r\n\\\\\r\n\t& = & \\ds\\frac{415}{6}\r\n\\end{array}\\]\\\r\n\\end{solution}\r\n\r\nFinding an antiderivative can be far from simple; in fact, often finding a formula for an antiderivative is very hard or even impossible.  While we can differentiate just about any function, even some relatively simple ones don't have an elementary antiderivative.  A significant portion of integral calculus (which is the main focus of second semester calculus) is devoted to understanding the problem of finding antiderivatives. \r\n\r\n\\begin{example}{Three Different Techniques}{ThreeDifferentTechniques}\r\nEvaluate $\\ds{\\int_0^2 x+1~dx}$ by\r\n\\begin{enumerate}\r\n\\item Using FTC (the shortcut)\r\n\\item Using the definition of a definite integral (the limit sum definition)\r\n\\item Interpreting the problem in terms of areas (graphically)\r\n\\end{enumerate}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\n1. The shortcut (FTC) is the method of choice as it is the fastest.\r\nIntegrating and using the `\\ifont{top minus bottom}' rule we have:\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx&=&\\left.\\frac{x^2}{2}+x\\right|_0^2\\\\\r\n&=&\\left[\\frac{2^2}{2}+2\\right]-\\left[\\frac{0^2}{2}+0\\right]=4.\r\n\\end{eqnarray*}\r\n\r\n2. We now use the definition of a definite integral.\r\nWe divide the interval $[0,2]$ into $n$ subintervals of equal width $\\Delta x$, and from each interval choose a point $x_i^*$.\r\nUsing the formulas\r\n$$\\Delta x = \\frac{b-a}{n}\\qquad\\mbox{and}\\qquad x_i=a+i\\Delta x,$$\r\nwe have\r\n$$\\Delta x = \\frac{2}{n}\\qquad\\mbox{and}\\qquad x_i=0+i\\Delta x=\\frac{2i}{n}.$$\r\nThen taking $x_i^*$'s as right endpoints for convenience (so that $x_i^*=x_i$), we have:\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx & = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n f(x_i^*)\\Delta x\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n f\\left(\\frac{2i}{n}\\right) \\frac{2}{n}\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n \\left(\\frac{2i}{n}+1\\right) \\frac{2}{n}\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\sum_{i=1}^n \\left(\\frac{4i}{n^2}+\\frac{2}{n}\\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\sum_{i=1}^n \\frac{4i}{n^2}+\\sum_{i=1}^n \\frac{2}{n} \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\frac{4}{n^2}\\sum_{i=1}^n i+\\frac{2}{n}\\sum_{i=1}^n 1 \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(\\frac{4}{n^2}\\frac{n(n+1)}{2}+\\frac{2}{n}n \\right)\\\\\r\n\\\\\r\n& = & \\ds\\lim_{n\\to\\infty}\\left(2+\\frac{2}{n}+2 \\right)\\\\\r\n\\\\\r\n& = & 4.\r\n\\end{eqnarray*}\r\n\r\n3. Finally, let's evaluate the net area under $x+1$ from $0$ to $2$.\r\n$$\\includegraphics[width=5in]{images/int-ex}$$\r\nThus, the area is the sum of the areas of a rectangle and a triangle.\r\nHence,\r\n\\begin{eqnarray*}\r\n\\int_0^2 x+1~dx&=&\\mbox{Net Area}\\\\\r\n&=&\\mbox{Area of rectangle} + \\mbox{Area of triangle}\\\\\r\n&=&(2)(1)+\\frac{1}{2}(2)(2)\\\\\r\n&=&4.\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\r\n\\subsection{The net change theorem} \\index{net change theorem}\r\n\r\nAs we use the Fundamental Theorem of Calculus to evaluate definite integrals, it is essential that we remember and understand the meaning of the numbers we find.  We briefly summarize three key interpretations to date.\r\n\\begin{itemize}\r\n\t\\item For a moving object with instantaneous velocity $v(t)$, the object's change in position on the time interval $[a,b]$ is given by $\\int_a^b v(t) \\, dt$, and whenever $v(t) \\ge 0$ on $[a,b]$, $\\int_a^b v(t) \\, dt$ tells us the total distance traveled by the object on $[a,b]$.  \r\n\t\\item For any continuous function $f$, its definite integral $\\int_a^b f(x) \\, dx$ represents the total net signed area bounded by $y = f(x)$ and the $x$-axis on $[a,b]$, where regions that lie below the $x$-axis have a minus sign associated with their area.  \r\n%\t\\item The value of a definite integral is linked to the average value of a function: for a continuous function $f$ on $[a,b]$, its average value $f_{\\mbox{\\tiny{AVG}}[a,b]}$ is given by\r\n%$$f_{\\mbox{\\tiny{AVG}}[a,b]} = \\frac{1}{b-a} \\int_a^b f(x) \\, dx.$$\r\n\\end{itemize}\r\nThe Fundamental Theorem of Calculus now enables us to evaluate exactly (without taking a limit of Riemann sums) any definite integral for which we are able to find an antiderivative of the integrand.  \r\n\r\nA slight change in notational perspective allows us to gain even more insight into the meaning of the definite integral.  To begin, recall Equation~(\\ref{E:FTCV}), where we wrote the Fundamental Theorem of Calculus for a velocity function $v$ with antiderivative $V$ as\r\n$$V(b) - V(a) = \\int_a^b v(t) \\, dt.$$\r\nIf we instead replace $V$ with $s$ (which represents position) and replace $v$ with $s'$ (since velocity is the derivative of position), Equation~(\\ref{E:FTCV}) equivalently reads \r\n\\begin{equation} \\label{E:FTCs}\r\ns(b) - s(a) = \\int_a^b s'(t) \\, dt.\r\n\\end{equation}\r\nIn words, this version of the FTC tells us that the net change in the object's position function on a particular interval is given by the definite integral of the position function's derivative over that interval.\r\n\r\nOf course, this result is not limited to only the setting of position and velocity.  Writing the result in terms of a more general function $f$, we have the Net Change Theorem.\r\n\r\n \\begin{theorem}{Net Change Theorem}{net_change_theorem} \\index{net change theorem} If $f$ is a continuously differentiable function on $[a,b]$ with derivative $f'$, then \r\n \\begin{equation} \\label{E:TotalChange}\r\nf(b) - f(a) = \\int_a^b f'(x) \\, dx.\r\n\\end{equation}\r\nThat is, the  integral of the rate of change (derivative) of a function on $[a,b]$ is the net change of the function itself on $[a,b]$.\r\n\\end{theorem}\r\n\r\nThe Net Change Theorem tells us more about the relationship between the graph of a function and that of its derivative.  Recall from Chapter 4 that heights (or values) on the graph of the derivative function correspond to slopes on the graph of the function itself.  That observation occurred in the context where we knew $f$ and were seeking $f'$; if now instead we think about knowing $f'$ and seeking information about $f$, we can instead say the following:  \r\n\\begin{quote}\r\n\\emph{differences in heights on $f$ correspond to net signed areas bounded by $f'$.}\r\n\\end{quote}\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_4_TCT}\r\n\\caption{The graphs of $f'(x) = 4 - 2x$ (at left) and an antiderivative $f(x) = 4x - x^2$ at right.  Differences in heights on $f$ correspond to net signed areas bounded by $f'$.} \\label{F:4.4.TCT}\r\n\\end{center}\r\n\\end{figure}\r\nTo see why this is so, say we consider the difference $f(1) - f(0)$.  Note that this value is $ 3 $, in part because $f(1) = 3$ and $f(0) = 0$, but also because the net signed area bounded by $y = f'(x)$ on $[0,1]$ is 3.  That is, $f(1) - f(0) = \\int_0^1 f'(x) \\, dx$.  A similar pattern holds throughout, including the fact that since the total net signed area bounded by $f'$ on $[0,4]$ is $0$, $\\int_0^4 f'(x) \\, dx = 0$, so it must be that $f(4) - f(0) = 0$, so $f(4) = f(0)$.\r\n\r\nBeyond this general observation about area, the Net Change Theorem enables us to consider interesting and important problems where we know the rate of change, and answer key questions about the function whose rate of change we know. \r\n\r\n\\begin{example} \\label{Ex:4.4.1}\r\nSuppose that pollutants are leaking out of an underground storage tank at a rate of $r(t)$ gallons/day, where $t$ is measured in days.  It is conjectured that $r(t)$ is given by the formula $r(t) = 0.0069t^3 -0.125t^2+11.079$ over a certain 12-day period.  The graph of $y=r(t)$ is given in Figure~\\ref{F:4.4.TCTEx}.  What is the meaning of $\\int_4^{10} r(t) \\, dt$ and what is its value?  \r\n%What is the average rate at which pollutants are leaving the tank on the time interval $4 \\le t \\le 10$?\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/4_4_TCTEx}\r\n\\caption{The rate $r(t)$ of pollution leaking from a tank, measured in gallons per day.} \\label{F:4.4.TCTEx}\r\n\\end{center}\r\n\\end{figure}\r\n\\end{example}\r\n\\begin{solution}\r\nWe know that since $r(t) \\ge 0$, the value of $\\int_4^{10} r(t) \\, dt$ is the area under the curve on the interval $[4,10]$.  If we think about this area from the perspective of a Riemann sum, the rectangles will have heights measured in gallons per day and widths measured in days, thus the area of each rectangle will have units of\r\n$$\\frac{\\mbox{gallons}}{\\mbox{day}} \\cdot \\mbox{days} = \\mbox{gallons}.$$\r\nThus, the definite integral tells us the total number of gallons of pollutant that leak from the tank from day 4 to day 10.  The Net Change Theorem tells us the same thing:  if we let $R(t)$ denote the function that measures the total number of gallons of pollutant that have leaked from the tank up to day $t$, then $R'(t) = r(t)$, and \r\n$$\\int_4^{10} r(t) \\, dt = R(10) - R(4),$$\r\nwhich is the net change in the function that measures total gallons leaked over time, thus the number of gallons that have leaked from day 4 to day 10.\r\n\r\nTo compute the exact value, we use the Fundamental Theorem of Calculus.  Antidifferentiating $r(t) = 0.0069t^3 -0.125t^2+11.079$, we find that\r\n\\begin{eqnarray*}\r\n\t\\int_4^{10} (0.0069t^3 -0.125t^2+11.079) \\, dt & = & \\left. \\left( 0.0069 \\cdot \\frac{1}{4} \\, t^4 - 0.125 \\cdot \\frac{1}{3} t^3 + 11.079t \\right) \\right|_4^{10} \\\\\r\n\t\t\t& = & \\left( 0.0069 \\cdot \\frac{1}{4} \\, (10)^4 - 0.125 \\cdot \\frac{1}{3} (10)^3 + 11.079(10) \\right) - \\\\\r\n\t\t\t& \\ &  \\left( 0.0069 \\cdot \\frac{1}{4} \\, (4)^4 - 0.125 \\cdot \\frac{1}{3} (4)^3 + 11.079(4) \\right) \\\\\r\n\t\t\t& \\approx & 44.282. \r\n\\end{eqnarray*}\r\nThus, approximately 44.282 gallons of pollutant leaked over the six day time period.\r\n\r\n%To find the average rate at which pollutant leaked from the tank over $4 \\le t \\le 10$, we want to compute the average value of $r$ on $[4,10]$.  Thus,\r\n%$$r_{\\mbox{\\tiny{AVG}}[4,10]} = \\frac{1}{10-4} \\int_4^{10} r(t) \\, dt \\approx \\frac{44.282}{6} = 7.380,$$\r\n%which has its units measured in gallons per day.\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\nSummary\r\n\r\n\\begin{itemize}\r\n\\item We can find the exact value of a definite integral without taking the limit of a Riemann sum or using a familiar area formula by finding the antiderivative of the integrand, and hence applying the Fundamental Theorem of Calculus.\r\n\\item The Fundamental Theorem of Calculus says that if $f$ is a continuous function on $[a,b]$ and $F$ is an antiderivative of $f$, then\r\n$$\\int_a^b f(x) \\, dx = F(b) - F(a).$$\r\nHence, if we can find an antiderivative for the integrand $f$, evaluating the definite integral comes from simply computing the change in $F$ on $[a,b]$. \r\n\\item A slightly different perspective on the FTC allows us to restate it as the Net Change Theorem, which says that\r\n$$\\int_a^b f'(x) \\, dx = f(b) - f(a),$$\r\nfor any continuously differentiable function $f$.   This means that the definite integral of the instantaneous rate of change of a function $f$ on an interval $[a,b]$ is equal to the net change in the function $f$ on $[a,b]$.\r\n\\end{itemize}\r\n\r\n\r\n\\subsection{Functions defined by integrals}\r\n\r\nThe FTC enables us to compute the value of the antiderivative $F$ at a point $b$, provided that we know $F(a)$ and can evaluate the definite integral from $a$ to $b$ of $f$:\r\n$$F(b) = F(a) + \\int_a^b f(x) \\, dx.$$\r\nWe may think of $b$, the upper limit of integration, as a variable itself.  To that end, we introduce the idea of an \\emph{integral function}\\index{integral function}, a function whose formula involves a definite integral.\r\n\r\nGiven a continuous function $f$, we define the corresponding integral function $A$ according to the rule \r\n\\begin{equation} \\label{E:intfxn}\r\nA(x) = \\int_a^x f(t) \\, dt.\r\n\\end{equation}\r\nNote particularly that because we are using the variable $x$ as the independent variable in the function $A$, and $x$ determines the other endpoint of the interval over which we integrate (starting from $a$), we need to use a variable other than $x$ as the variable of integration.  A standard choice is $t$, but any variable other than $x$ is acceptable.\r\n\r\nOne way to think of the function $A$ is as the ``net-signed area from $a$ up to $x$'' function, where we consider the region bounded by $y = f(t)$ on the relevant interval.  For example, in Figure~\\ref{F:5.1.IntFxn}, we see a given function $f$ pictured at left, and its corresponding area function (choosing $a = 0$), $A(x) = \\int_0^x f(t) \\, dt$ shown at right.\r\n\r\n\\begin{figure}[h]\r\n\\begin{center}\r\n\\includegraphics{figures/5_1_IntFxn}\r\n\\end{center}\r\n\\caption{At left, the graph of the given function $f$.  At right, the area function $A(x) = \\int_0^x f(t) \\, dt$.} \\label{F:5.1.IntFxn}\r\n\\end{figure}\r\n\r\nNote particularly that the function $A$ measures the net-signed area from $t = 0$ to $t = x$ bounded by the curve $y = f(t)$; this value is then reported as the corresponding height on the graph of $y = A(x)$.  It is even more natural to think of this relationship between $f$ and $A$ dynamically.  At \\href{http://gvsu.edu/s/cz}{\\texttt{http://gvsu.edu/s/cz}}, we find a java applet\\footnote{David Austin, Grand Valley State University} that brings the static picture in Figure~\\ref{F:5.1.IntFxn} to life.  There, the user can move the red point on the function $f$ and see how the corresponding height changes at the light blue point on the graph of $A$.\r\n\r\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % %\r\n\r\n\\subsection{FTC 2} \\label{sec:FTC2}\r\n\r\nIn the previous section we learned the Fundamental Theorem of Calculus (FTC), which from here forward will be referred to as the \\emph{First} Fundamental Theorem of Calculus\\index{Fundamental Theorem of Calculus!First}, as in this section we develop a corresponding result that follows it.\r\n\r\nWe begin by way of example. If we let $f(t) = \\cos(t) - t$ and set $A(x) = \\int_2^x f(t) \\, dt$, then we can determine a formula for $A$ without integrals by the First FTC.  Specifically,\r\n\\begin{eqnarray*}\r\nA(x) & = & \\int_2^x (\\cos(t) - t) \\, dt \\\\\r\n\t& = & \\sin(t) - \\frac{1}{2}t^2 \\bigg\\vert_2^x \\\\\r\n\t& = & \\sin(x) -  \\frac{1}{2}x^2 - \\left(\\sin(2) - 2 \\right).\r\n\\end{eqnarray*}\r\nDifferentiating $A(x)$, since $(\\sin(2) - 2)$ is constant, it follows that \r\n$$A'(x) = \\cos(x) - x,$$\r\nand thus we see that $A'(x) = f(x)$.  This tells us that for this particular choice of $f$, $A$ is an antiderivative of $f$.  More specifically, since $A(2) = \\int_2^2 f(t) \\, dt = 0$, $A$ is the only antiderivative of $f$ for which $A(2) = 0$.\r\n\r\nIn general, if $f$ is any continuous function, and we define the function $A$ by the rule \r\n$$A(x) = \\int_c^x f(t) \\, dt,$$\r\nwhere $c$ is an arbitrary constant, then we can show that $A$ is an antiderivative of $f$.  To see why, let's demonstrate that $A'(x) = f(x)$ by using the limit definition of the derivative.  Doing so, we observe that\r\n\\begin{align}\r\nA'(x) &= \\lim_{h \\to 0} \\frac{A(x+h) - A(x)}{h} \\notag \\\\\r\n\t&= \\lim_{h \\to 0} \\frac{\\int_c^{x+h} f(t) \\, dt - \\int_c^x f(t) \\, dt}{h} \\notag \\\\\r\n\t&= \\lim_{h \\to 0} \\frac{\\int_x^{x+h} f(t) \\, dt}{h}, \\label{E:FTC2limdef}\r\n\\end{align}\r\nwhere Equation~(\\ref{E:FTC2limdef}) in the preceding chain follows from the fact that $\\int_c^x f(t) \\,dt + \\int_x^{x+h} f(t) \\, dt = \\int_c^{x+h} f(t) \\, dt$.  Now, observe that for small values of $h$,\r\n$$\\int_x^{x+h} f(t) \\, dt \\approx f(x) \\cdot h,$$\r\nby a simple left-hand approximation of the integral.  Thus, as we take the limit in Equation~(\\ref{E:FTC2limdef}), it follows that\r\n$$A'(x) =  \\lim_{h \\to 0} \\frac{\\int_x^{x+h} f(t) \\, dt}{h} = \\lim_{h \\to 0} \\frac{f(x) \\cdot h}{h} = f(x).$$\r\n\r\n%it follows from the First FTC that\r\n%$$A(x) = F(x) - F(c).$$\r\n%Since $F(c)$ is constant and $F$ is an antiderivative of $f$, we see\r\n%$$A'(x) = F'(x) = f(x),$$\r\n%and thus $A$ is an antiderivative of $f$.  \r\n\r\nHence, $A$ is indeed an antiderivative of $f$.  In addition, $A(c) = \\int_c^c f(t) \\, dt = 0.$  The preceding argument demonstrates the truth of the Second Fundamental Theorem of Calculus, which we state as follows.\r\n\r\n\r\n\\begin{theorem}{FTC 2}{fundamental_theorem_II} \r\nIf $f$ is a continuous function and $a$ is any constant, then $f$ has a unique antiderivative $A$ that satisfies $A(a) = 0$, and that antiderivative is given by the rule $A(x) = \\int_a^x f(t) \\, dt$. That is to say\r\n\\[\r\nA'(x) = \\frac{d}{dx}\\left[\\int_c^x f(t) \\, dt\\right]= f(x) \\text{ and } A(c)=0.\r\n\\]\r\n\\end{theorem}\r\n\r\nWe can prove the first version of the FTC using the second:\r\n\r\n\\begin{proof} Proof of Theorem~\\ref{thm:fundamental_theorem_I}.\r\n\r\nWe know from Theorem~\\ref{thm:fundamental_theorem_II} that \r\n$$\r\n  A(x)=\\int_a^x f(t)\\,dt\r\n$$\r\nis an antiderivative of $f(x)$, and therefore any antiderivative\r\n$F(x)$ of $f(x)$ is of the form $F(x)=A(x)+k$. Then \r\n\\begin{eqnarray*}\r\n  F(b)-F(a)=A(b)+k-(A(a)+k) &=& A(b)-A(a)\\cr\r\n  &=&\\int_a^b f(t)\\,dt-\\int_a^a f(t)\\,dt.\\cr\r\n\\end{eqnarray*}\r\nIt is not hard to see that $\\ds \\int_a^a f(t)\\,dt=0$, so this means that\r\n$$\r\n  F(b)-F(a)=\\int_a^b f(t)\\,dt,\r\n$$\r\nwhich is exactly what Theorem~\\ref{thm:fundamental_theorem_I} says.\r\n\\end{proof}\r\n\r\n\\begin{example}{Using FTC}{UsingFTC}\r\n\\exfont{Differentiate} the following function:\r\n$$g(x)=\\int_{-2}^x \\cos(1+5t)\\sin t\\,dt.$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe simply apply the Fundamental Theorem of Calculus directly to get:\r\n$$g'(x)=\\cos(1+5x)\\sin x.$$\r\n\\end{solution}\r\n\r\nUsing the Chain Rule we can derive a formula for some more complicated problems.\r\nIf $ F$ is an antiderivative of $ f $, then we have:\r\n$$\\frac{d}{dx}\\int_a^{v(x)}f(t)\\,dt=\\frac{d}{dx}\\left(F(v(x))-F(a)\\right) =f(v(x))\\cdot v'(x) - 0=f(v(x))\\cdot v'(x).$$\r\n\r\nNow what if the upper limit is constant and the lower limit is a function of $x$?\r\nThen we interchange the limits and add a minus sign to get:\r\n$$\\frac{d}{dx}\\int_{u(x)}^af(t)\\,dt=-\\frac{d}{dx}\\int_a^{u(x)} f(t)\\,dt=-f(u(x))\\cdot u'(x).$$\r\n\r\nCombining these two we can get a formula where both limits are a function of $x$.\r\nWe break up the integral as follows:\r\n$$\\int_{u(x)}^{v(x)} f(t)\\,dt=\\int_{u(x)}^a f(t)\\,dt+\\int_a^{v(x)}f(t)\\,dt.$$\r\nWe just need to make sure $f(a)$ exists after we break up the integral.\r\nThen differentiating and using the above two formulas gives:\r\n\r\n\\begin{formulabox}[FTC I + Chain Rule:]\r\n$$\\frac{d}{dx}\\int_{{u(x)}}^{{v(x)}} f(t)\\,dt=f({v(x)}){v'(x)}-f({u(x)}){u'(x)}$$\r\n\\end{formulabox}\r\n\r\nMany textbooks do not show this formula and instead to solve these types of problems will use FTC I along with the tricks we used to derive the formula above.\r\nEither method is perfectly fine.\r\n\r\n\\begin{example}{FTC I + Chain Rule}{FTCIChainRule}\r\nDifferentiate the following integral:\r\n$$\\int_{10x}^{x^2} t^3\\sin(1+t) \\,dt.$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nWe will use the formula above.\r\nWe have $f(t)=t^3\\sin(1+t)$, $u(x)=10x$ and $v(x)=x^2$.\r\nThen $u'(x)=10$ and $v'(x)=2x$.\r\nThus,\r\n\\begin{eqnarray*}\r\n\\frac{d}{dx}\\int_{10x}^{x^2} t^3\\sin(1+t) \\,dt&=&(x^2)^3\\sin(1+(x^2))(2x)-(10x)^3\\sin(1+(10x))(10)\\\\\r\n\\\\\r\n&=&2x^7\\sin(1+x^2)-10000x^3\\sin(1+10x)\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\\begin{example}{FTC I + Chain Rule}{FTCIChainRule2}\r\nDifferentiate the following integral with respect to $x$:\r\n$$\\int_{x^3}^{2x} 1+\\cos t\\,dt$$\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nUsing the formula we have:\r\n$$\\frac{d}{dx}\\int_{x^3}^{2x} 1+\\cos t\\,dt=(1+\\cos(2x))(2)-(1+\\cos(x^3))(3x^2).$$\r\n\\end{solution}\r\n\r\n\r\n\\subsection{More on Differentiating Integral Functions}\r\n\r\nThe Second FTC provides us with a means to construct an antiderivative of any continuous function.  In particular, if we are given a continuous function $g$ and wish to find an antiderivative of $g$, we can now say that \r\n$$G(x) = \\int_a^x g(t) \\, dt$$\r\nprovides the rule for such an antiderivative, and moreover that $G(a) = 0$.  Note especially that we know that $G'(x) = g(x)$.  We sometimes want to write this relationship between $G$ and $g$ from a different notational perspective.  In particular, observe that\r\n\\begin{equation} \\label{E:diffint}\r\n\\frac{d}{dx} \\left[ \\int_a^x g(t) \\, dt \\right] = g(x).\r\n\\end{equation}\r\nThis result can be particularly useful when we're given an integral function such as $G$ and wish to understand properties of its graph by recognizing that $G'(x) = g(x)$, while not necessarily being able to exactly evaluate the definite integral $\\int_c^x g(t) \\, dt$.\r\n\r\nThis shows that integral functions, while perhaps having the most complicated formulas of any functions we have encountered, are nonetheless particularly simple to differentiate.  For instance, if \r\n$$F(x) = \\int_{\\pi}^x \\sin(t^2) \\, dt,$$\r\nthen by the Second FTC, we know immediately that\r\n$$F'(x) = \\sin(x^2).$$\r\n\r\nStating this result more generally for an arbitrary function $f$, we know by the Second FTC that\r\n$$\\frac{d}{dx} \\left[ \\int_a^x f(t) \\, dt \\right] = f(x).$$\r\nIn words, the last equation essentially says that ``the derivative of the integral function whose integrand is $f$, is $f$.''  In this sense, we see that if we first integrate the function $f$ from $t = a$ to $t = x$, and then differentiate with respect to $x$, these two processes ``undo'' one another.\r\n\r\nTaking a different approach, say we begin with a function $f(t)$ and differentiate with respect to $t$.  What happens if we follow this by integrating the result from $t = a$ to $t = x$?  That is, what can we say about the quantity\r\n$$\\int_a^x \\frac{d}{dt} \\left[ f(t) \\right] \\, dt?$$\r\nHere, we use the First FTC and note that $f(t)$ is an antiderivative of $\\frac{d}{dt} \\left[ f(t) \\right].$  Applying this result and evaluating the antiderivative function, we see that\r\n\\begin{eqnarray*}\r\n\\int_a^x \\frac{d}{dt} \\left[ f(t) \\right] \\, dt & = & f(t) \\bigg\\vert_a^x \\\\\r\n\t\t\t\t\t\t\t& = & f(x) - f(a).\r\n\\end{eqnarray*} \r\nThus, we see that if we apply the processes of first differentiating $f$ and then integrating the result from $a$ to $x$, we return to the function $f$, minus the constant value $f(a)$.  So in this situation, the two processes almost undo one another, up to the constant $f(a)$.\r\n\r\nThe observations made in the preceding two paragraphs demonstrate that differentiating and integrating (where we integrate from a constant up to a variable) are almost inverse processes.  In one sense, this should not be surprising:  integrating involves antidifferentiating, which reverses the process of differentiating.  On the other hand, we see that there is some subtlety involved, as integrating the derivative of a function does not quite produce the function itself.  This is connected to a key fact  that any function has an infinite family of antiderivatives, and any two of those antiderivatives differ only by a constant.\r\n\r\n\r\n% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\r\n\r\n%Let's rewrite this slightly: \r\n%$$\r\n%  \\int_a^x f(t)\\,dt = F(x)-F(a).\r\n%$$\r\n%We've replaced the variable $x$ by $t$ and $b$ by $x$. These are just\r\n%different names for quantities, so the substitution doesn't change the\r\n%meaning. It does make it easier to think of the two sides of the\r\n%equation as functions. The expression\r\n%$$\r\n%  \\int_a^x f(t)\\,dt\r\n%$$\r\n%is a function: plug in a value for $x$, get out some other value. The\r\n%expression $F(x)-F(a)$ is of course also a function, and it has a nice\r\n%property: \r\n%$$\r\n%  {d\\over dx} (F(x)-F(a)) = F'(x) = f(x),\r\n%$$\r\n%since $F(a)$ is a constant and has derivative zero. In other words, by\r\n%shifting our point of view slightly, we see that the odd looking\r\n%function\r\n%$$\r\n%  G(x)=\\int_a^x f(t)\\,dt\r\n%$$\r\n%has a derivative, and that in fact $G'(x)=f(x)$. This is really just a\r\n%restatement of the Fundamental Theorem of Calculus, and indeed is\r\n%often called the Fundamental Theorem of Calculus. To avoid confusion,\r\n%some people call the two versions of the theorem ``The Fundamental\r\n%Theorem of Calculus, part I'' and ``The Fundamental\r\n%Theorem of Calculus, part II'', although unfortunately there is no\r\n%universal agreement as to which is part I and which part II. Since it\r\n%really is the same theorem, differently stated, some people simply\r\n%call them both ``The Fundamental\r\n%Theorem of Calculus.''\r\n%\r\n%\\begin{theorem}{Fundamental Theorem of Calculus}{fundamental_theorem_II}\r\n%Suppose that $f(x)$ is\r\n%continuous on the interval $[a,b]$ and let\r\n%$$\r\n%  G(x)=\\int_a^x f(t)\\,dt.\r\n%$$\r\n%Then $G'(x)=f(x)$.\r\n%\\end{theorem}\r\n%\r\n%We have not really proved the Fundamental Theorem. In a nutshell, we\r\n%gave the following argument to justify it: Suppose we want to know the\r\n%value of \r\n%$$\r\n%  \\int_a^b f(t)\\,dt = \\lim_{n\\to\\infty}\\sum_{i=0}^{n-1} f(t_i)\\Delta t.\r\n%$$\r\n%We can interpret the right hand side as the distance traveled by an\r\n%object whose speed is given by $f(t)$. We know another way to compute\r\n%the answer to such a problem: find the position of the object by\r\n%finding an antiderivative of $f(t)$, then substitute $t=a$ and $t=b$\r\n%and subtract to find the distance traveled. This must be the answer to\r\n%the original problem as well, even if $f(t)$ does not represent a\r\n%speed.\r\n%\r\n%What's wrong with this? In some sense, nothing. As a practical matter\r\n%it is a very convincing argument, because our understanding of the\r\n%relationship between speed and distance seems to be quite solid. From\r\n%the point of view of mathematics, however, it is unsatisfactory to\r\n%justify a purely mathematical relationship by appealing to our\r\n%understanding of the physical universe, which could, however unlikely\r\n%it is in this case, be wrong.\r\n%\r\n%A complete proof is a bit too involved to include here, but we will\r\n%indicate how it goes. First, if we can prove the second version of the\r\n%Fundamental Theorem, Theorem~\\ref{thm:fundamental_theorem_II}, then\r\n%we can prove the first version from that:\r\n%\r\n%\\begin{proof} Proof of Theorem~\\ref{thm:fundamental_theorem_I}.\r\n%\r\n%We know from Theorem~\\ref{thm:fundamental_theorem_II} that \r\n%$$\r\n%  G(x)=\\int_a^x f(t)\\,dt\r\n%$$\r\n%is an antiderivative of $f(x)$, and therefore any antiderivative\r\n%$F(x)$ of $f(x)$ is of the form $F(x)=G(x)+k$. Then \r\n%\\begin{eqnarray*}\r\n%  F(b)-F(a)=G(b)+k-(G(a)+k) &=& G(b)-G(a)\\cr\r\n%  &=&\\int_a^b f(t)\\,dt-\\int_a^a f(t)\\,dt.\\cr\r\n%\\end{eqnarray*}\r\n%It is not hard to see that $\\ds \\int_a^a f(t)\\,dt=0$, so this means that\r\n%$$\r\n%  F(b)-F(a)=\\int_a^b f(t)\\,dt,\r\n%$$\r\n%which is exactly what Theorem~\\ref{thm:fundamental_theorem_I} says.\r\n%\\end{proof}\r\n%\r\n%So the real job is to prove\r\n%Theorem~\\ref{thm:fundamental_theorem_II}. We will sketch the proof,\r\n%using some facts that we do not prove. First, the following identity\r\n%is true of integrals:\r\n%$$\r\n%  \\int_a^b f(t)\\,dt = \\int_a^c f(t)\\,dt + \\int_c^b f(t)\\,dt.\r\n%$$\r\n%This can be proved directly from the definition of the integral, that\r\n%is, using the limits of sums. It is quite easy to see that it must be\r\n%true by thinking of either of the two applications of integrals that\r\n%we have seen. It turns out that the identity is true no matter what\r\n%$c$ is, but it is easiest to think about the meaning when \r\n%$a\\le c\\le b$.\r\n%\r\n%First, if $f(t)$ represents a speed, then we know that the three\r\n%integrals represent the distance traveled between time $a$ and time $b$;\r\n%the distance traveled between time $a$ and time $c$; and \r\n%the distance traveled between time $c$ and time $b$. Clearly the sum of\r\n%the latter two is equal to the first of these.\r\n%\r\n%Second, if $f(t)$ represents the height of a curve, the three\r\n%integrals represent the area under the curve between $a$ and $b$;\r\n%the area under the curve between $a$ and $c$;\r\n%and the area under the curve between $c$ and $b$. Again it is clear\r\n%from the geometry that the first is equal to the sum of the second and\r\n%third. \r\n%\r\n%\\begin{proof} Proof of Theorem~\\ref{thm:fundamental_theorem_II}.\r\n%\r\n%We want to compute $G'(x)$, so we start with the definition of the\r\n%derivative in terms of a limit:\r\n%\\begin{eqnarray*}\r\n%  G'(x)&=&\\lim_{\\Delta x\\to0}{G(x+\\Delta x)-G(x)\\over\\Delta x}\\cr\r\n%  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\left(\r\n%  \\int_a^{x+\\Delta x} f(t)\\,dt - \\int_a^x f(t)\\,dt\\right)\\cr\r\n%  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\left(\r\n%  \\int_a^{x} f(t)\\,dt + \\int_x^{x+\\Delta x} f(t)\\,dt - \r\n%  \\int_a^x f(t)\\,dt\\right)\\cr\r\n%  &=&\\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\int_x^{x+\\Delta x} f(t)\\,dt.\\cr\r\n%\\end{eqnarray*}\r\n%Now we need to know something about \r\n%$$\r\n%  \\int_x^{x+\\Delta x} f(t)\\,dt\r\n%$$\r\n%when $\\Delta x$ is small; in fact, it is very close to \r\n%$\\Delta x f(x)$, but we will not prove this. Once again, it is easy to\r\n%believe this is true by thinking of our two applications:\r\n%The integral \r\n%$$\r\n%  \\int_x^{x+\\Delta x} f(t)\\,dt\r\n%$$\r\n%can be interpreted as the distance traveled by an object over a very\r\n%short interval of time. Over a sufficiently short period of time, the\r\n%speed of the object will not change very much, so the distance\r\n%traveled will be approximately the length of time multiplied by the\r\n%speed at the beginning of the interval, namely, $\\Delta x\r\n%f(x)$. Alternately, the integral may be interpreted as the area under\r\n%the curve between $x$ and $x+\\Delta x$. When $\\Delta x$ is very small,\r\n%this will be very close to the area of the rectangle with base $\\Delta\r\n%x$ and height $f(x)$; again this is $\\Delta x\r\n%f(x)$. If we accept this, we may proceed:\r\n%$$\r\n%  \\lim_{\\Delta x\\to0}{1\\over \\Delta x}\\int_x^{x+\\Delta x} f(t)\\,dt\r\n%  =\\lim_{\\Delta x\\to0}{\\Delta x f(x)\\over \\Delta x}=f(x),\r\n%$$\r\n%which is what we wanted to show.\r\n%\\end{proof}\r\n%\r\n%It is still true that we are depending on an interpretation of the\r\n%integral to justify the argument, but we have isolated this part of\r\n%the argument into two facts that are not too hard to prove. Once the\r\n%last reference to interpretation has been removed from the proofs of\r\n%these facts, we will have a real proof of the Fundamental Theorem.\r\n%\r\n%Now we know that to solve certain kinds of problems, those that lead\r\n%to a sum of a certain form, we ``merely'' find an antiderivative and\r\n%substitute two values and subtract. Unfortunately, finding\r\n%antiderivatives can be quite difficult. While there are a small number\r\n%of rules that allow us to compute the derivative of any common\r\n%function, there are no such rules for antiderivatives. There are some\r\n%techniques that frequently prove useful, but we will never be able to\r\n%reduce the problem to a completely mechanical process.\r\n%\r\n%Due to the close relationship between an integral and an\r\n%antiderivative, the integral sign is also used to mean\r\n%``antiderivative''. You can tell which is intended by whether the\r\n%limits of integration are included:\r\n%$$\r\n%  \\int_1^2 x^2\\,dx\r\n%$$\r\n%is an ordinary integral, also called a \r\n%\\dfont{definite integral},\r\n%because it has a definite value, namely\r\n%$$\r\n%  \\int_1^2 x^2\\,dx={2^3\\over3}-{1^3\\over3}={7\\over3}.\r\n%$$\r\n%We use\r\n%$$\r\n%  \\int x^2\\,dx\r\n%$$\r\n%to denote the antiderivative of $\\ds x^2$, also called an\r\n%\\dfont{indefinite integral}.\r\n%So this is evaluated as\r\n%$$\r\n%  \\int x^2\\,dx = {x^3\\over 3}+C.\r\n%$$\r\n%It is customary to include the constant $C$ to indicate that there are\r\n%really an infinite number of antiderivatives. We do not need this $C$\r\n%to compute definite integrals, but in other circumstances we will need\r\n%to remember that the $C$ is there, so it is best to get into the habit\r\n%of writing the $C$.\r\n%When we compute a definite integral, we first find an antiderivative\r\n%and then substitute. It is convenient to first display the\r\n%antiderivative and then do the substitution; we need a notation\r\n%indicating that the substitution is yet to be done. A typical solution\r\n%would look like this:\r\n%$$\r\n%  \\int_1^2 x^2\\,dx=\\left.{x^3\\over 3}\\right|_1^2 = \r\n%  {2^3\\over3}-{1^3\\over3}={7\\over3}.\r\n%$$\r\n%The vertical line with subscript and superscript is used to indicate\r\n%the operation ``substitute and subtract'' that is needed to finish the\r\n%evaluation.\r\n%\r\n%We seem to have found a pattern. When attempting to solve a previous question, we found the antiderivative of $x^2$ to be $x^3/3+c$ (as it was when solving the indefinite integral). Likewise, when we first began, we were trying to determine a position based on velocity, and $3t$ gave rise to $3t^2/2+k$.\r\n%\r\n%As will be formalized later, we see that in these cases, the power is increased to $n+1$, but we also divide through by this factor, $n+1$. So $x$ becomes $x^2/2$, $x^2$ becomes $x^3/3$, and $x^3$ will become $x^4/4$.\r\n%\r\n%Now we will also try with negative and fraction values in the following example.\r\n\r\n%\\begin{example}{Fundamental Theorem of Calculus}{FundamentalTheoremCalculus}\r\n%Evaluate $\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx $.\r\n%\\end{example}\r\n%\r\n%\\begin{solution}\r\n%\\[ \\begin{array}{lcl}\r\n%\\ds\\int_1^4 x^3+\\sqrt{x}+\\frac{1}{x^2}\\,dx \r\n%\t& = & \\ds\\left.\\frac{x^4}{4}+\\frac{2x^{3/2}}{3}-x^{-1}\\right|_1^4\\\\\r\n%\\\\\r\n%\t& = & \\ds\\left(\\frac{(4)^4}{4}+\\frac{2(4)^{3/2}}{3}-4^{-1}\\right) \\\\\r\n%\\\\\r\n%\t& & \\ds-\\left(\\frac{(1)^4}{4}+\\frac{2(1)^{3/2}}{3}-1^{-1}\\right)\\\\\r\n%\\\\\r\n%\t& = & \\ds\\frac{415}{6}\r\n%\\end{array}\\]\\\r\n%\\end{solution}\r\n\r\n%\\begin{formulabox}[Properties of Definite Integrals]\r\n%Some properties are as follows:\r\n%$$\\mbox{Order of limits matters:}\\qquad\\int_a^b f(x)\\,dx=-\\int_b^a f(x)\\,dx$$\r\n%$$\\mbox{If interval is empty, integral is zero:}\\qquad\\int_a^a f(x)\\,dx=0$$\r\n%$$\\mbox{Constant Multiple Rule:}\\qquad\\int_a^b cf(x)\\,dx=c\\int_a^b f(x)\\,dx$$\r\n%$$\\mbox{Sum/Difference Rule:}\\qquad\\int_a^b f(x)\\pm g(x)\\,dx=\\int_a^b f(x)\\,dx\\pm\\int_a^b g(x)\\,dx$$\r\n%$$\\mbox{Can split up interval $[a,b]=[a,c]\\cup[c,b]$:}\\qquad\\int_a^b f(x)\\,dx=\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx$$\r\n%$$\\mbox{The variable does not matter!:}\\qquad\\int_a^b f(x)\\,dx=\\int_a^b f(t)\\,dt$$\r\n%\\end{formulabox}\r\n%\r\n%The reason for the last property is that a definite integral is a \\ifont{number}, not a function, so the variable is just a placeholder that won't appear in the final answer.\r\n%\r\n%Some additional properties are \\ifont{comparison} types of properties.\r\n%\r\n%\\begin{formulabox}[Comparison Properties of Definite Integrals]\r\n%$$\\mbox{If $f(x)\\geq 0$ for $x\\in[a,b]$, then:}\\qquad\\int_a^b f(x)\\,dx\\geq 0.$$\r\n%$$\\mbox{If $f(x)\\geq g(x)$ for $x\\in[a,b]$, then:}\\qquad\\int_a^b f(x)\\,dx\\geq \\int_a^b g(x)\\,dx.$$\r\n%$$\\mbox{If $m\\leq f(x)\\leq M$ for $x\\in[a,b]$, then:}\\qquad m(b-a)\\leq \\int_a^b f(x)\\,dx\\leq M(b-a).$$\r\n%\\end{formulabox}\r\n%\r\n%\\begin{example}{Properties of Definite Integrals}{PropertiesDefiniteIntegrals}\r\n%Suppose $\\ds{\\int_a^b f(x)~dx=7}$ and $\\ds{\\int_a^b g(x)~dx=3}$. Find:\r\n%\\begin{multicols}{2}\r\n%\\begin{enumerate}\r\n%\t\\item\t$\\ds\\int_a^b 2f(x)-3g(x)\\,dx$.\r\n%\t\\item\t$\\ds\\int_{b}^{a} 2g(x)\\,dx$.\r\n%\t\\item\t$\\ds\\int_a^a f(x)\\cdot g(x)\\,dx$.\r\n%\t\\item\t$\\ds\\int_a^c f(x)~dx+\\int_c^b f(x)\\,dx$.\r\n%\\end{enumerate}\r\n%\\end{multicols}\r\n%\\vspace{5mm}\r\n%\\end{example}\r\n%\\begin{solution}\r\n%\\begin{enumerate}\r\n%\t\\item\t$\\ds\\int_a^b 2f(x)-3g(x)\\,dx=\\ds 2\\int_a^b f(x)\\,dx-3\\int_a^b g(x)\\,dx=2(7)-3(3)=5$.\r\n%\t\\item\t$\\ds\\int_{b}^{a} 2g(x)\\,dx=\\ds -2\\int_{a}^{b} g(x)\\,dx=-2(3)=-6$.\r\n%\t\\item\t$\\ds\\int_a^a f(x)\\cdot g(x)\\,dx=0$.\r\n%\t\\item\t$\\ds\\int_a^c f(x)\\,dx+\\int_c^b f(x)\\,dx=\\ds\\int_a^b f(x)\\,dx=7$.\r\n%\\end{enumerate}\r\n%\\end{solution}\r\n\r\n%We next evaluate a definite integral using three different techniques.\r\n%\r\n%\r\n%We next apply FTC to differentiate a function.\r\n\r\n\r\nThis section has laid the groundwork for a lot of great mathematics to follow. The most important lesson is this: definite integrals can be evaluated using antiderivatives. Since the previous section established that definite integrals are the limit of Riemann sums, we can later create Riemann sums to approximate values other than ``area under the curve,'' convert the sums to definite integrals, then evaluate these using the Fundamental Theorem of Calculus. This will allow us to compute the work done by a variable force, the volume of certain solids, the arc length of curves, and more.\r\n\r\nThe downside is this: generally speaking, computing antiderivatives is much more difficult than computing derivatives. The next chapter is devoted to techniques of finding antiderivatives so that a wide variety of definite integrals can be evaluated. Before that, the next section explores techniques of approximating the value of definite integrals beyond using the Left Hand, Right Hand and Midpoint Rules.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:FTC}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^4 t^2+3t\\,dt$\r\n\\begin{sol}\r\n $87/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^\\pi \\sin t\\,dt$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^{10} {1\\over x}\\,dx$\r\n\\begin{sol}\r\n $\\ln(10)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^5 e^x\\,dx$\r\n\\begin{sol}\r\n $\\ds e^5-1$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_0^3 x^3\\,dx$\r\n\\begin{sol}\r\n $\\ds 3^4/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nEvaluate $\\ds \\int_1^2 x^5\\,dx$\r\n\\begin{sol}\r\n $\\ds 2^6/6 -1/6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x t^2-3t\\,dt$\r\n\\begin{sol}\r\n $\\ds x^2-3x$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^{x^2} t^2-3t\\,dt$\r\n\\begin{sol}\r\n $\\ds 2x(x^4-3x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x e^{t^2}\\,dt$\r\n\\begin{sol}\r\n $\\ds e^{x^2}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^{x^2} e^{t^2}\\,dt$\r\n\\begin{sol}\r\n $\\ds 2xe^{x^4}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_1^x \\tan(t^2)\\,dt$\r\n\\begin{sol}\r\n $\\ds \\tan(x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n Find the derivative of $\\ds G(x)=\\int_{10x}^{x^2} \\tan(t^2)\\,dt$\r\n\\begin{sol}\r\n $\\ds 2x\\tan(x^4)-10\\tan(100x^2)$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose $\\int_{1}^{4}f(x)\\,dx=2$ and $\\int_{1}^{4}g(x)\\,dx=7$. Find $\\int_{1}^{4}(5f(x)+3g(x))\\,dx$ and $\\int_{1}^{4}(6-2f(x))\\,dx$.\r\n\\begin{sol}\r\n\t31, 14\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSuppose $\\int_{-2}^{5}f(x)\\,dx=3$ and $\\int_{1}^{5}f(x)\\,dx=-2$. Find $\\int_{-2}^{1}f(x)\\,dx$.\r\n\\begin{sol}\r\n\t5\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nIf $f$ is continuous on $[a,b]$, we define the average of $f(x)$ on $[a,b]$ to be\r\n\\begin{equation*}\r\n\\text{avg}_{[a,b]}(f)=\\frac{1}{b-a}\\int_{a}^{b}f(x)\\,dx.\r\n\\end{equation*}\r\n\\begin{enumerate}\r\n\t\\item\tWhat is the average of $\\sqrt{x}$ on the interval $[0,1]?$\r\n\t\\item\tIf the average of $f(x)$ on $[0,2]$ and on $[2,5]$ are 6 and 4 respectively, then what is its average on $[0,5]$?\r\n\\end{enumerate}\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\t\\item\t2/3\r\n\t\\item\t24/5\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "9e1c365cdc84ea6dddb84ca171a6c707a90ac3b9", "size": 44574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6-integration/6-2-ftc.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6-integration/6-2-ftc.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6-integration/6-2-ftc.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.0642857143, "max_line_length": 757, "alphanum_fraction": 0.670547853, "num_tokens": 14750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772253241802, "lm_q2_score": 0.8774767826757123, "lm_q1q2_score": 0.7669824714875753}}
{"text": "\\subsection{Matrices}\\label{subsec:matrices}\n\n\\begin{definition}\\label{def:array}\n  Let \\( X \\) be any nonempty set. A \\( k \\)-dimensional \\term{array} \\( A \\) of shape \\( (n_1, \\ldots, n_k) \\) over \\( X \\) is a function of type\n  \\begin{equation*}\n    A: \\{ 1, 2, \\ldots, n_1 \\} \\times \\ldots \\times \\{ 1, 2, \\ldots, n_k \\} \\to X.\n  \\end{equation*}\n\n  In particular,\n  \\begin{thmenum}\n    \\thmitem{def:array/matrix} two-dimensional arrays of shape \\( n, m \\) are usually called \\term{matrices}. An \\( n, m \\)-matrix \\( A \\) is denoted as\n    \\begin{equation*}\n      A = \\{ a_{i,j} \\}_{i,j=1}^{n,m}\n    \\end{equation*}\n    or graphically as tables\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} & a_{1,2} & \\cdots & a_{1,m} \\\\\n        a_{2,1} & a_{2,2} & \\cdots & a_{2,m} \\\\\n        \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n        a_{n,1} & a_{n,2} & \\cdots & a_{n,m}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    The elements \\( a_{1,1}, \\ldots, a_{\\min{n, m}, \\min{n, m}} \\) of a matrix are called its \\term{main diagonal}.\n\n    \\thmitem{def:array/square_matrix} If \\( n = m \\), we call the matrix a \\term{square matrix} of order \\( n \\).\n\n    \\thmitem{def:array/column_vector} matrices with only one column are called \\term{column matrices}:\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} \\\\\n        \\vdots  \\\\\n        a_{n,1}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    \\thmitem{def:array/row_vector} matrices with only one row are called \\term{row matrices}:\n    \\begin{equation*}\n      \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,m}\n      \\end{pmatrix}.\n    \\end{equation*}\n\n    \\thmitem{def:array/vector} one-dimensional arrays are called simply \\term{vectors} or \\hyperref[def:cartesian_product]{tuples} and are usually written as either column vectors or row vectors.\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{remark}\\label{rem:arrays_vs_tensors}\n  Multidimensional arrays, as defined in \\fullref{def:array}, are often called tensors, especially in machine learning where they are often used. This is a confusing practice since tensors (see \\fullref{def:left_module_tensor_product}) are defined in a coordinate-independent fashion.\n\n  A single tensor can be represented by different arrays and the same array can represent multiple tensors.\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,m} \\\\\n      A_{2,1} & A_{2,2} & \\cdots & A_{2,m} \\\\\n      \\vdots  & \\vdots  & \\ddots & \\vdots  \\\\\n      A_{n,1} & A_{n,2} & \\cdots & A_{n,m}\n    \\end{pmatrix},\n  \\end{equation*}\n  where all \\( A_{i,j} \\) are matrices of compatible dimensions.\n\n  We usually 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*{\\begin{array}{ccc|c|ccc}\n      a_{1,1}   & \\cdots & a_{1,m_A}   & \\cdots & b_{1,1}   & \\cdots & b_{1,m_B} \\\\\n      \\vdots    & \\ddots & \\vdots      & \\cdots & \\vdots    & \\ddots & \\vdots \\\\\n      a_{n_A,1} & \\cdots & a_{n_A,m_A} & \\cdots & b_{n_B,1} & \\cdots & b_{n_B,m_B} \\\\\n      \\hline\n      \\vdots    & \\vdots & \\vdots      & \\ddots & \\vdots    & \\vdots & \\vdots \\\\\n      \\hline\n      c_{1,1}   & \\cdots & c_{1,m_C}   & \\cdots & d_{1,1}   & \\cdots & d_{1,m_D} \\\\\n      \\vdots    & \\ddots & \\vdots      & \\cdots & \\vdots    & \\ddots & \\vdots \\\\\n      c_{n_C,1} & \\cdots & c_{n_C,m_C} & \\cdots & d_{n_D,1} & \\cdots & d_{n_D,m_D} \\\\\n    \\end{array}}.\n  \\end{equation*}\n\n  Given any matrix \\( A = \\{ a_{i,j} \\}_{i,j=1}^{n,m} \\), we sometimes consider its block matrix of \\term{rows}\n  \\begin{equation*}\n    \\parens*{\\begin{array}{c}\n      a_{1,-} \\\\\n      \\hline\n      a_{2,-} \\\\\n      \\hline\n      \\vdots \\\\\n      \\hline\n      a_{n,-}\n    \\end{array}},\n  \\end{equation*}\n  consisting of row vectors, and its block matrix of of \\term{columns}\n  \\begin{equation*}\n    \\parens*{\\begin{array}{c|c|c|c}\n      a_{-,1} & a_{-,2} & \\cdots & a_{-,m},\n    \\end{array}}\n  \\end{equation*}\n  consisting of column vectors.\n\\end{definition}\n\n\\begin{definition}\\label{def:left_module_of_tuples}\n  Let \\( R \\) be a \\hyperref[def:semiring]{semiring}. Let \\( R^n \\) be the set of all \\( n \\)-\\hyperref[def:array/vector]{tuples} over \\( R \\), that is,\n  \\begin{equation*}\n    R^n = R \\times R \\times \\cdots \\times R.\n  \\end{equation*}\n\n  It is customary to denote elements of \\( R^n \\) by\n  \\begin{equation*}\n    x = \\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix}.\n  \\end{equation*}\n  rather than\n  \\begin{equation*}\n    x = (x_1, \\ldots, x_n).\n  \\end{equation*}\n\n  This highlights that \\( R^n \\) is usually treated as a space of column vectors.\n\n  Define the operations\n  \\begin{balign*}\n     & +: R^n \\times R^n \\to R^n\n    \\\\\n     & \\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix}\n    +\n    \\begin{pmatrix} y_1 \\\\ \\vdots \\\\ y_n \\end{pmatrix}\n    =\n    \\begin{pmatrix} x_1 + y_1 \\\\ \\vdots \\\\ x_n + y_n \\end{pmatrix}\n    \\\\\n    \\\\\n     & \\cdot: R \\times R^n \\to R^n\n    \\\\\n     & \\lambda \\cdot \\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{pmatrix}\n    =\n    \\begin{pmatrix} \\lambda x_1 \\\\ \\vdots \\\\ \\lambda x_n \\end{pmatrix}.\n  \\end{balign*}\n\n  With these operations defined, \\( R^n \\) becomes a semiring \\hyperref[def:left_module]{module}.\n\n  In particular, if \\( R \\) is a \\hyperref[def:semiring/field]{field}, \\( R^n \\) is a \\hyperref[def:vector_space]{vector space} and we refer to it as a \\term{tuple space}. We are usually only concerned with the vector spaces \\( \\BbbR^n \\) and \\( \\BbbC^n \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:matrix_spaces_are_tuple_spaces}\n  The vector spaces \\( F^{n \\times m} \\) and \\( F^{nm} \\) are isomorphic with an isomorphism defined by \\fullref{rem:double_index_maps}.\n\\end{proposition}\n\n\\begin{remark}\\label{rem:vector_spaces_of_tuples_and_matrices}\n  \\Fullref{thm:finite_dimensional_spaces_are_isomorphic} provides a justification for working with vector spaces of tuples instead of arbitrary vector spaces.\n\n  \\Fullref{thm:finite_dimensional_operators_are_isomorphic_to_matrices} provides a justification for working with vector spaces of matrices instead of arbitrary spaces of linear operators.\n\\end{remark}\n\n\\begin{theorem}\\label{thm:finite_dimensional_spaces_are_isomorphic}\n  Every \\( n \\)-\\hyperref[def:vector_space_dimension]{dimensional} \\hyperref[def:vector_space]{vector space} over the field \\( \\BbbK \\) is isomorphic to \\( \\BbbK^n \\) (see \\fullref{def:left_module_of_tuples}).\n\\end{theorem}\n\\begin{proof}\n  Let \\( V \\) be an arbitrary \\( n \\)-dimensional vector space over \\( \\BbbK \\). Since a basis of \\( V \\) exists by \\fullref{thm:every_vector_space_has_a_basis}, fix a basis and fix an ordering \\( b_1, \\ldots, b_n \\) of the basis vectors. Denote the projection \\hyperref[def:left_module_basis_projection]{maps} by \\( \\pi_{b_i} \\).\n\n  Define the function\n  \\begin{balign*}\n     & L: V \\to \\BbbK^n                                      \\\\\n     & L(x) \\coloneqq (\\pi_{b_1}(x), \\ldots, \\pi_{b_n}(x))\n  \\end{balign*}\n  that maps a vector \\( x \\in V \\) into an \\( n \\)-tuple of the projections of \\( x \\) along the ordered basis \\( b_1, \\ldots, b_n \\). It is linear since, by \\fullref{thm:left_module_basis_projections_are_linear}, the projections are linear.\n\n  Now define the inverse function\n  \\begin{balign*}\n     & P: \\BbbK^n \\to V                                      \\\\\n     & P(y_1, \\ldots, y_n) \\coloneqq \\sum_{i=1}^n y_i b_i,\n  \\end{balign*}\n  which is obviously linear.\n\n  The composition of \\( L \\) and \\( P \\) is the identity mapping on \\( V \\). Indeed, for any \\( x \\in V \\),\n  \\begin{equation*}\n    (P \\circ L)(x)\n    =\n    P(\\pi_{b_1}(x), \\ldots, \\pi_{b_n}(x))\n    =\n    \\sum_{i=1}^n \\pi_{b_i}(x) b_i\n    =\n    x.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:algebra_of_matrices}\n  Denote by \\( R^{n \\times m} \\) the set of \\( n, m \\)-matrices over the semiring \\( R \\). We define three operations on matrices:\n\n  \\begin{thmenum}\n    \\thmitem{def:algebra_of_matrices/addition} We define \\term{matrix addition} as\n    \\begin{balign*}\n       & +: R^{n,m} \\times R^{n,m} \\to R^{n,m} \\\\\n       & \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,m} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        a_{n,1} & \\cdots & a_{n,m}\n      \\end{pmatrix}\n      +\n      \\begin{pmatrix}\n        b_{1,1} & \\cdots & b_{1,m} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        b_{n,1} & \\cdots & b_{n,m}\n      \\end{pmatrix}\n      \\coloneqq\n      \\begin{pmatrix}\n        a_{1,1} + b_{1,1} & \\cdots & a_{1,m} + b_{1,m} \\\\\n        \\vdots            & \\ddots & \\vdots            \\\\\n        a_{n,1} + b_{n,1} & \\cdots & a_{n,m} + b_{n,m}\n      \\end{pmatrix}\n    \\end{balign*}\n\n    \\thmitem{def:algebra_of_matrices/scalar_multiplication} We define \\term{scalar multiplication} as\n    \\begin{balign*}\n       & \\cdot: R \\times R^{n,m} \\to R^{n,m}      \\\\\n       & \\lambda \\cdot \\begin{pmatrix}\n        a_{1,1} & \\cdots & a_{1,m} \\\\\n        \\vdots  & \\ddots & \\vdots  \\\\\n        a_{n,1} & \\cdots & a_{n,m}\n      \\end{pmatrix}\n      \\coloneqq\n      \\begin{pmatrix}\n        \\lambda a_{1,1} & \\cdots & \\lambda a_{1,m} \\\\\n        \\vdots          & \\ddots & \\vdots          \\\\\n        \\lambda a_{n,1} & \\cdots & \\lambda a_{n,m}\n      \\end{pmatrix}\n    \\end{balign*}\n\n    \\thmitem{def:algebra_of_matrices/matrix_multiplication} We define \\term{matrix multiplication} in two steps. The complexity of the definition is justified by \\fullref{thm:finite_dimensional_operators_are_isomorphic_to_matrices}. First, if \\( a \\in R^{1,n} \\) is a row \\hyperref[def:array/row_vector]{vector} and \\( b \\in R^{n,1} \\) is a column \\hyperref[def:array/column_vector]{vector}, we define their \\term{inner product} to be\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 as\n    \\begin{balign*}\n       & \\odot: R^{n,m} \\times R^{m,k} \\to R^{n,k} \\\\\n       & \\parens*{\\begin{array}{c}\n        a_{1,-} \\\\\n        \\hline\n        a_{2,-} \\\\\n        \\hline\n        \\vdots \\\\\n        \\hline\n        a_{n,-}\n      \\end{array}}\n      \\odot\n      \\parens*{\\begin{array}{c|c|c|c}\n        \\scriptstyle{b_{-,1}} & \\scriptstyle{b_{-,2}} & \\cdots & \\scriptstyle{b_{-,m}}\n      \\end{array}}\n      \\coloneqq\n      \\begin{pmatrix}\n        a_{1,-} \\cdot b_{-,1} & a_{1,-} \\cdot b_{-,2} & \\vdots & a_{1,-} \\cdot b_{-,m} \\\\\n        a_{2,-} \\cdot b_{-,1} & a_{2,-} \\cdot b_{-,2} & \\vdots & a_{2,-} \\cdot b_{-,m} \\\\\n        \\vdots                & \\vdots                & \\ddots & \\vdots                \\\\\n        a_{n,-} \\cdot b_{-,1} & a_{n,-} \\cdot b_{-,2} & \\cdots & a_{n,-} \\cdot b_{-,m}\n      \\end{pmatrix}.\n    \\end{balign*}\n  \\end{thmenum}\n\n  With \\hyperref[def:algebra_of_matrices/addition]{addition} and scalar \\hyperref[def:algebra_of_matrices/scalar_multiplication]{multiplication}, \\( R^{n \\times m} \\) becomes a semiring \\hyperref[def:left_module]{module}.\n\n  In the special case where \\( R \\) is a commutative unital ring and \\( n = m \\), we can add matrix \\hyperref[def:algebra_of_matrices/matrix_multiplication]{multiplication} to the module \\( R^{n \\times n} \\), so that it becomes an \\hyperref[def:algebra_over_ring]{algebra} over \\( R \\).\n\\end{definition}\n\n\\begin{example}\\label{ex:matrix_multiplication_is_noncommutative}\n  The matrix algebra \\( R^{n \\times n} \\) is a noncommutative ring. Consider the following example:\n  \\begin{balign*}\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{balign*}\n\\end{example}\n\n\\begin{proposition}\\label{thm:finite_dimensional_operators_are_isomorphic_to_matrices}\n  Fix a dioid \\( R \\). The \\hyperref[def:algebra_of_matrices]{matrix vector space} \\( R^{n \\times m} \\) is isomorphic to the vector space of all linear maps \\( \\hom(R^m, R^n) \\) (note that the maps are from \\( R^m \\) to \\( R^n \\)).\n\n  In the special case where \\( R \\) is a commutative unital ring and \\( n = m \\), the algebra \\( R^{n \\times n} \\) with matrix multiplication as vector multiplication is isomorphic to \\( \\End(R^n) \\) with function composition as vector multiplication. In particular, this justifies using juxtaposition for application of linear functions, e.g. \\( Lx \\) rather than \\( L(x) \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( L: R^m \\to R^n \\) be a linear map and let \\( e_1, \\ldots, e_m \\) be the basis vectors in \\( R^m \\). Denote by \\( \\pi_i, i = 1, \\ldots, m \\) be the basis \\hyperref[def:left_module_basis_projection]{projections}. We construct a matrix as follows:\n  \\begin{equation*}\n    A_L \\coloneqq \\parens*{\\begin{array}{c|c|c|c}\n      L(e_1) & L(e_2) & \\cdots & L(e_m)\n    \\end{array}}\n  \\end{equation*}\n\n  Conversely, given a matrix \\( A \\in R^{n \\times m} \\), we define the linear map\n  \\begin{equation*}\n    \\hat L_A(x) \\coloneqq Ax\n  \\end{equation*}\n  by left multiplication of a vector with \\( A \\).\n\n  It remains to show that these are mutually inverse. Let \\( L: R^m \\to R^n \\) and \\( x \\in R^m \\). We have\n  \\begin{equation*}\n    L_{A_L}(x) = A_L x = \\sum_{i=1}^m \\pi_i(x) L(e_i) = L\\left(\\sum_{i=1}^m \\pi_i(x) e_i \\right) = L(x).\n  \\end{equation*}\n\n  Conversely, let \\( A \\in R^{n \\times m} \\) and \\( x \\in R^m \\). We have\n  \\begin{balign*}\n    A_{L_A} x\n     & =\n    \\parens*{\\begin{array}{c|c|c|c}\n      L_A(e_1) & L_A(e_2) & \\cdots & L_A(e_m)\n    \\end{array}}\n    x\n    =    \\\\ &=\n    \\parens*{\\begin{array}{c|c|c|c}\n      A e_1 & A e_2 & \\cdots & A e_m\n    \\end{array}}\n    x\n    =    \\\\ &=\n    \\sum_{i=1}^m \\pi_i(x) A e_i\n    =    \\\\ &=\n    A \\left( \\sum_{i=1}^m \\pi_i(x) e_i \\right)\n    =    \\\\ &=\n    Ax.\n  \\end{balign*}\n\n  It trivially follows that linear function composition corresponds to matrix multiplication.\n\\end{proof}\n\n\\begin{definition}\\label{def:matrix_determinant}\\mcite[215]{Knapp2016BasicAlgebra}\n  Fix the \\hyperref[def:algebra_of_matrices]{matrix space} \\( R^{n \\times n} \\) over a commutative unital ring \\( R \\). We define its determinant as\n  \\begin{balign*}\n     & \\det: R^{n \\times n} \\to R                                                                  \\\\\n     & \\det(\\{ a_{i,j} \\}_{i,j=1}^n) \\coloneqq \\sum_{p \\in S_n} \\sgn(p) \\prod_{i=1}^n a_{i,p(i)},\n  \\end{balign*}\n  where \\( S_n \\) is the \\hyperref[def:symmetric_group]{symmetric group} of order \\( n \\).\n\n  The determinant of a matrix is not invertible, we say that it is \\term{singular}. \\Fullref{thm:matrix_invertible_iff_nonsingular} gives a strong link between the invertibility of a matrix and the invertibility of its determinant.\n\n  If \\( R \\) is a field, then only the zero is not invertible and hence only matrices with \\( \\det A = 0 \\) are singular.\n\\end{definition}\n\n\\begin{example}\\label{ex:vandermonde_matrix}\\mcite[corr. 2.37]{Knapp2016BasicAlgebra}\n  The matrix\n  \\begin{equation*}\n    V_n(x_0, x_1, \\ldots, x_n)\n    \\coloneqq\n    \\begin{pmatrix}\n      x_0^0  & x_0^1  & x_0^2  & \\cdots & x_0^n  \\\\\n      x_1^0  & x_1^1  & x_1^2  & \\cdots & x_1^n  \\\\\n      \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n      x_n^0  & x_n^1  & x_n^2  & \\cdots & x_n^n\n    \\end{pmatrix}.\n  \\end{equation*}\n  is called the \\term{Vandermonde matrix} corresponding to \\( x_0, \\ldots, x_n \\).\n\n  Its determinant is\n  \\begin{equation*}\n    \\det(V_n) = \\prod_{i < j} (r_j - r_i).\n  \\end{equation*}\n\n  Hence, the determinant is nonzero if and only if all of \\( x_0, \\ldots, x_n \\) are distinct.\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:matrix_determinant/properties}\\mcite[prop. 5.1]{Knapp2016BasicAlgebra}\n  Matrix determinants over the commutative unital ring \\( R \\) have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:matrix_determinant/properties/identity} For the identity matrix \\( E_n \\in R^n \\) we have\n    \\begin{equation*}\n      \\det(E_n) = 1.\n    \\end{equation*}\n\n    \\thmitem{thm:def:matrix_determinant/properties/transpose} For the transpose \\hyperref[def:matrix_transpose]{matrix} \\( A^T \\) of \\( A \\in R^n \\), we have\n    \\begin{equation*}\n      \\det(A^T) = \\det(A).\n    \\end{equation*}\n\n    \\thmitem{thm:def:matrix_determinant/properties/product} For matrices \\( A, B \\in R^n \\) we have\n    \\begin{equation*}\n      \\det(A) \\det(B) = \\det(AB).\n    \\end{equation*}\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:matrix_invertible_iff_nonsingular}\\mcite[cor. 5.5]{Knapp2016BasicAlgebra}\n  A matrix over \\( R \\) is invertible if and only if its determinant is invertible in \\( R \\).\n\n  In particular, a matrix over a field is invertible if and only if its determinant is nonzero.\n\\end{proposition}\n\n\\begin{definition}\\label{def:inverse_matrix}\n  Let \\( A \\) be a square matrix of order \\( n \\) over a dioid \\( R \\). We say that \\( B \\) is an \\term{inverse matrix} of \\( A \\) if\n  \\begin{equation*}\n    AB = BA = E_n.\n  \\end{equation*}\n\n  An inverse matrix, if it exists, is unique. We denote this inverse of \\( A \\) by \\( A^{-1} \\).\n\n  The set of all invertible matrices of order \\( n \\) over \\( R \\) is called the \\term{general linear group} and is denoted by \\( \\op{GL}_n(R) \\). It forms a group with respect to matrix multiplication.\n\n  If \\( R \\) is commutative, we also consider the \\term{special linear group} \\( \\op{SL}_n(R) \\) of matrices with \\hyperref[def:matrix_determinant]{determinant} \\( 1 \\).\n\\end{definition}\n\\begin{proof}\n  The inverse is unique by \\fullref{def:unital_magma_inverse_element_unique}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:general_linear_group_isomorphic_to_automorphism_group}\n  Fix a dioid \\( R \\). The general linear group \\( \\op{GL}_n(R) \\) is isomorphic to the group of all invertible linear transformations over \\( R^n \\) under composition.\n\\end{proposition}\n\\begin{proof}\n  Follows from \\fullref{thm:finite_dimensional_operators_are_isomorphic_to_matrices}.\n\\end{proof}\n\n\\begin{definition}\\label{def:orthogonal_matrix}\n  Let \\( R \\) be a dioid. We say that the square matrix \\( A \\) is \\term{orthogonal} if \\( A^T = A^{-1} \\). If \\( R \\) is a commutative unital ring, the set of all orthogonal matrices of order \\( n \\) forms a subgroup of \\( \\op{GL}_n(R) \\) called the \\term{orthogonal group} \\( \\op{O}_n(R) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:unitary_matrix}\n  We say that the complex square matrix \\( A \\) is \\term{unitary} if \\( A^\\dagger = A^{-1} \\). The set of all unitary matrices of order \\( n \\) is called the unitary group \\( \\op{U}_n \\) and is a subgroup of \\( \\op{GL}_n(\\co) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:matrix_column_and_row_space}\n  Fix a matrix \\( A \\in R^{n \\times m} \\) over a semiring \\( R \\). We define its \\term{row space} as\n  \\begin{equation*}\n    \\linspan \\{ a_{i,-} \\colon i = 1, \\ldots, n \\}\n  \\end{equation*}\n  and its \\term{column space} as\n  \\begin{equation*}\n    \\linspan \\{ a_{-,j} \\colon j = 1, \\ldots, m \\}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:matrix_transpose}\n  Let \\( A = \\{ a_{i,j} \\}_{i,j=1}^{n,m} \\) be a matrix. We define its \\term{transpose matrix} by \\term{flipping it over its main diagonal}, that is,\n  \\begin{equation*}\n    A^T \\coloneqq \\begin{pmatrix}\n      a_{1,1} & a_{2,1} & \\cdots & a_{n,1} \\\\\n      a_{1,2} & 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\\end{definition}\n\n\\begin{definition}\\label{def:symmetric_matrix}\n  A square matrix \\( A \\) is said to be \\term{symmetric} if \\( A = A^T \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:matrix_conjugate_transpose}\n  Let \\( A \\) be a complex matrix. We define its \\term{conjugate transpose matrix} as\n  \\begin{equation*}\n    A^\\dagger \\coloneqq \\begin{pmatrix}\n      \\overline{a_{1,1}} & \\overline{a_{2,1}} & \\cdots & \\overline{a_{n,1}} \\\\\n      \\overline{a_{1,2}} & \\overline{a_{2,2}} & \\cdots & \\overline{a_{n,2}} \\\\\n      \\vdots       & \\vdots       & \\ddots & \\vdots       \\\\\n      \\overline{a_{1,m}} & \\overline{a_{2,m}} & \\cdots & \\overline{a_{n,m}}\n    \\end{pmatrix}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:hermitian_matrix}\n  If \\( A \\) is a complex matrix, we say that it is Hermitian if \\( A = A^\\dagger \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:dual_linear_operator_matrix_transpose}\n  Let \\( L: F^m \\to F^n \\) be a linear operator and let \\( L^*: {F^n}^* \\to {F^m}^* \\) be its dual \\hyperref[def:dual_linear_operator]{operator}.\n\n  If \\( A \\in F^{n \\times m} \\) is the matrix of \\( L \\), then its \\hyperref[def:matrix_transpose]{transpose} \\( A^T \\) is the matrix of \\( L^* \\) when regarding \\( L^* \\) as an operator acting on column vectors.\n\\end{proposition}\n\\begin{proof}\n  Let \\( l \\in {F^n}^* \\) be a linear functional regarded as a function and \\( \\vect l \\) be the same functional regarded as a column \\hyperref[rem:finite_dimensional_dual_space_isomorphism]{vector}. We have\n  \\begin{equation*}\n    L^*(l)\n    =\n    l \\circ L\n    =\n    (x \\mapsto l(L(x)))\n    =\n    (x \\mapsto \\vect l^T Ax)\n    =\n    \\vect l^T A.\n  \\end{equation*}\n\n  Thus,\n  \\begin{equation*}\n    L^*(l) = A^T \\vect l,\n  \\end{equation*}\n  i.e. the matrix \\( A^T \\) corresponds to the dual operator \\( L^* \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:column_and_row_spaces_are_images}\n  Fix a semiring \\( R \\). Let \\( L: R^m \\to R^n \\) be a linear map and let \\( A \\in R^{n \\times m} \\) be the corresponding \\hyperref[thm:finite_dimensional_operators_are_isomorphic_to_matrices]{matrix}. The \\hyperref[def:matrix_column_and_row_space]{column space} of \\( A \\) is isomorphic to the image \\( \\img(L) \\) and the row space is isomorphic to \\( \\img(L^*) \\).\n\\end{proposition}\n\\begin{proof}\n  The column space of \\( A \\) lies within \\( R^{n \\times 1} \\), which is isomorphic to \\( R^n \\). We will assume that it is a subset of \\( R^n \\) and will prove that it is equal to \\( \\img(L) \\).\n\n  Denote by \\( e_1, \\ldots, e_m \\) the basis of \\( R^m \\). The \\( j \\)-th column \\( a_{-,j} \\) of \\( A \\) can be represented as\n  \\begin{equation*}\n    A e_j = a_{-,j}.\n  \\end{equation*}\n\n  Thus, \\( a_{-,j} \\in \\img(L), j = 1, \\ldots, m \\). Since \\( \\img(L) \\) is a linear subspace of \\( R^n \\), it contains the linear span of any finite collection of its vectors. Consequently, the column space of \\( A \\) is a subspace of \\( \\img(L) \\).\n\n  To see the converse, let \\( x \\in \\BbbR^m \\). We have\n  \\begin{equation*}\n    L(x) = Ax = \\sum_{j=1}^m x_i A e_j = \\sum_{j=1}^m a_{-,j}.\n  \\end{equation*}\n\n  Hence, the image of any vector \\( x \\) under \\( L \\) is a linear combination of the columns of \\( A \\).\n\n  Thus, proves that the column space of \\( A \\) is equal to \\( \\img(L) \\).\n\n  The proof that the row space is isomorphic to \\( \\img(L^*) \\) is identical, noting that \\( A^T \\) corresponds to \\( L^* \\) by \\fullref{thm:dual_linear_operator_matrix_transpose}.\n\\end{proof}\n", "meta": {"hexsha": "c999a5007c2006ef88af1207a9dad4f76fbe0b35", "size": 23165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/matrices.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/matrices.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/matrices.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": 43.1378026071, "max_line_length": 434, "alphanum_fraction": 0.6128642348, "num_tokens": 8074, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102419, "lm_q2_score": 0.8723473779969193, "lm_q1q2_score": 0.7669213692247266}}
{"text": "\\paragraph{Estimator} $\\estim$ is a function that estimates value of an unknown parameter $\\param$.\n\n\\paragraph{Bias of an estimator}\n$ b(\\estim) = $\n\n$ = \\mathbb{E}(\\estim(\\sample)-\\param) = \\mathbb{E}(\\estim)-\\param $\n\\begin{equation*}\nb(\\estim) = \\begin{cases}\n\\left.\\begin{aligned}\n   > 0 \\rightarrow \\mbox{overestimation} \\hspace{7pt} \\\\\n   < 0 \\rightarrow \\mbox{underestimation} \n\\end{aligned}\n\\right\\} \\mbox{ systematic error} \\\\\n\\hspace{3pt} = 0 \\rightarrow \\mbox{no systematic error} \n\\end{cases}\n\\end{equation*}\n\n\\paragraph{Unbiased estimator}\n$ \\mathbb{E} \\hat\\theta(X_1, \\ldots, X_n) = \\theta $\n\n\\paragraph{Asymptotically unbiased estimator}\nis an estimator that is unbiased when sample size tends to infinity.\n\n$ \\underset{n \\rightarrow \\infty}{\\lim} b(\\hat{\\theta}(X_1, \\ldots, X_n)) = 0 $\n\n\\paragraph{Mean squared error}\n\\[ MSE(\\hat{\\theta}) = \\mathbb{E}(\\hat{\\theta}-\\theta)^2 \n= Var(\\hat{\\theta})+b^2(\\hat{\\theta}) \\]\n\n\\paragraph{Regular model} is a stat. space $ \\statspace $ that satisfies the following conditions:\n\n\\begin{itemize}[noitemsep,nolistsep]\n  \\item support of $p_\\theta$ does not depend on $\\theta$; \n  \n  support of $ p_\\theta(x) = \\left\\{ x: p_\\theta(x) > 0 \\right\\} $\n  \n  \\item $ 0 < \\mathbb{E} \\left[ \\frac{\\partial}{\\partial\\theta} \\ln p_\\theta(x) \\right]^2 < \\infty $\n\\end{itemize}\n\n\\paragraph{Fisher's information contained in a single observation}\n\\[ I(\\theta) = \\mathbb{E} \\left[ \\frac{\\partial}{\\partial\\theta} \\ln p_\\theta(x) \\right]^2  \\]\n\n\\paragraph{Fisher's information contained in a sample}\n\\[ I_n(\\theta) = \\mathbb{E} \\left[ \\frac{\\partial}{\\partial\\theta} \\ln p_\\theta(x_1,\\ldots,x_n) \\right]^2  \\]\n\n\\paragraph{Cramer-Rao inequality}\n$X = X_1,\\ldots,X_n$ is from regular model. Let $T$ denote\nan unbiased estimator of a function $g(\\theta)$, then:\n\\[ Var T(X) \\geq \\frac{\\left( g'( \\theta ) \\right)^2}{n I(\\theta)} \\]\n\n\\paragraph{Fisher's information inequality}\nstates that if $\\theta$ is an unbiased estimator, then:\n\\[ Var\\hat\\theta(X) \\geq \\frac{1}{n I(\\theta)} \\]\n\n\\paragraph{Efficiency of an estimator}\n\\[ eff(\\hat\\theta) = \\frac{1}{Var(\\hat\\theta) n I(\\theta)} \\]\nand $0 < eff(\\hat\\theta) \\leq 1$\n\n\\paragraph{Most efficient estimator}\nhas $eff(\\hat\\theta) = 1$\n\n\\paragraph{Asymptotically efficient estimator}\nis not efficient but $\\underset{n \\rightarrow \\infty}{\\lim} eff(\\hat{\\theta}(\\sample)) = 1 $\n\n\\paragraph{Relative efficiency}\n\\[ \\frac{eff(\\estim_1)}{eff(\\estim_2)} = \\frac{Var(\\estim_2)}{Var(\\estim_1)} \\]\n\n\\paragraph{Consistency of an estimator}\nis preserved, if, $\\forall \\mathcal{E} > 0$ for a given estimator $\\hat{\\theta}$ the following holds:\n\n\\[ \\limit{n}{\\infty}\n P \\left( \\left| \\estim(\\sample) - \\theta \\right| < \\mathcal{E} \\right) = 1 \\]\n\nAlso, if $\\estim$ is unbiased estimator of $\\param$\nand if $ \\limit{n}{\\infty} Var(\\estim(\\sample)) = 0 $ then $\\estim$ is consistent.\n\n\\paragraph{Differentiation of estimators}\nby the method of construction:\n\n\\begin{enumerate}[noitemsep,nolistsep]\n  \\item method-of-moments estimator: MME\n  \n  \\item maximal-likelihood estimator: MLE\n  \n  \\item minimum-variance unbiased estimator MVUE\n  \n  \\item method-of-quantiles estimator MQE\n\\end{enumerate}\n\n\\paragraph{MME}\n- method of moments.\n\n$ \\param = g(\\mathbb{E}X, \\mathbb{E}X^2, \\ldots, \\mathbb{E}X^r) $\n\n$ \\estim = g(\\mu_1,\\mu_2,\\ldots,\\mu_r) $\n\nwhere $\\mu_k = \\frac{1}{n} \\sum_{i=1}^n X_i^k$ e.g. $\\mu_1 = \\bar{X}$\n\n\\paragraph{MLE}\n- method of maximal likelihood.\n\nWe use likelihood function: $L = L(\\param, \\sample) = $\n\\[ = \\begin{cases}\nP_\\theta(X_1 = x_1, \\ldots, X_n = x_n) \\mbox{ for discrete distr.} \\\\\nf_\\theta(x_1, \\ldots, x_n) \\mbox{ for cont.}\n\\end{cases} \\]\n\n$ \\estim = \\arg \\max L(\\param) $\n\nIf $\\estim$ denotes a M.L.E. of $\\param$ in the regular model, then\n\n\\[ \\left( \\estim(\\sample) - \\theta \\right) \\sqrt{n}\n \\underset{n \\rightarrow \\infty}{\\sim}  \\distnormal\\left( 0, \\frac{1}{\\sqrt{I(\\param)}} \\right) \\]\n\nand for large $n$:\n\n\\[ \\estim \\sim \\distnormal\\left( 0, \\frac{1}{\\sqrt{n I(\\param)}} \\right) \\]\n\n% \\paragraph{Uniform distribution estimators}\n% for $\\theta$ in $U([0,\\theta])$ are:\n% \\begin{align*}\n% \\textrm{MME: } & \\hat{\\theta}_1 = 2\\bar{X} \\\\ \n% \\textrm{MLE: } & \\hat{\\theta}_2 = X_{n:n} \\\\ \n% \\textrm{MVUE: } & \\hat{\\theta}_3 = \\frac{n+1}{n}X_{n:n} = \\frac{n+1}{n}\\hat{\\theta}_2 \\\\ \n% %\\textrm{MQE: } & ?\n% \\end{align*}\n\n% \\subsubsection{Normal distribution}\n% \\begin{align*}\n% \\textrm{MME: } & \\\\ \n% \\textrm{MLE: } & \\\\ \n% \\textrm{MVUE: } & \\\\ \n% \\textrm{MQE: } & \n% \\end{align*}\n\n", "meta": {"hexsha": "23c156df5c9280cbeabecf92074601e2c2c7b716", "size": 4482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_4_estim_point.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_4_estim_point.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_4_estim_point.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.9558823529, "max_line_length": 109, "alphanum_fraction": 0.6526104418, "num_tokens": 1613, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8791467643431002, "lm_q1q2_score": 0.7669213601610123}}
{"text": "\\chapter{Smart computation of \\texorpdfstring{$x^n$}{Powers}}\n\\label{chapter-powers}\n\\section{Introduction}\n\nNothing looks simpler than writing some function for computing $x^n$.\nOn the contrary, this simple programming exercise allows us to address\nadvanced programming techniques such as:\n\\begin{itemize}\n\\item monadic programming, and continuation passing style\n\\item type classes, and generalized rewriting\n\\item proof engineering, in particular proof re-using\n\\item proof by reflection\n\\item polymorphism and parametricity\n\\item composition of correct programs, etc.\n\\end{itemize}\n\n\n\n\\section{Some basic implementations}\n\\label{sect:linear-naive}\nLet us start with a very naive way of computing the $n$-th power of $x$, where\n$n$ is a natural number and $x$ belongs to some type for which a multiplication and an identity element are defined.\n\n\n\\emph{From Module \n\\href{../theories/html/additions.FirstSteps.html}{\\texttt{additions.FirstSteps}}}\n\\label{sect: power-definitions}\n\n\\begin{Coqsrc}\nSection Definitions.\n\nVariables (A: Type)\n           (mult: A -> A -> A)\n           (one: A).\nLocal Infix \"*\" := mult.\nLocal Notation \"1\" := one.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nFixpoint power (x:A)(n:nat) : A :=\n  match n with \n   | 0%nat => 1\n   | S p =>   x * x ^ p\n  end\nwhere \"x ^ n\" := (power x n).\n\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nCompute power Z.mul 1%Z 2%Z 10.  \n\\end{Coqsrc}\n\\begin{Coqanswer}\n   = 1024%Z\n     : Z\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nOpen Scope string_scope.\nCompute power append  \"\" \"ab\"  12.\n\\end{Coqsrc}\n \n \n\\begin{Coqanswer}\n = \"abababababababababababab\"\n     : string\n\\end{Coqanswer}\n\n\nAn application of this function for  computing $x^n$ needs $n$ multiplications.\n Despite this lack of efficiency, and thanks to its simplicity, we keep it as a specification for more efficient and complex exponentiation algorithms.\nA function will be considered a \\emph{correct} exponentiation function if we can prove it is extensionally equivalent to \\texttt{power}.\n\n% \\subsection{A semi-naive algorithm}\n\n% In versions up to \\texttt{V8.9.1}, the exponentiation function on type \\texttt{Z} was defined as follows,\n% (in modules \\texttt{Coq.PArith.BinPosDef.Pos} and \\texttt{Coq.ZArith.BinIntDef.Z}.\n\n% \\begin{Coqsrc}\n% (** ** Iteration of a function over a positive number *)\n\n% Definition iter {A} (f:A -> A) : A -> positive -> A :=\n%   fix iter_fix x n := match n with\n%     | xH => f x\n%     | xO n' => iter_fix (iter_fix x n') n'\n%     | xI n' => f (iter_fix (iter_fix x n') n')\n%   end.\n\n% Definition pow (x:positive) := iter (mul x) 1.\n% \\end{Coqsrc}\n\n\n% \\begin{Coqsrc}\n% Definition pow_pos (z:Z) := Pos.iter (mul z) 1.\n\n% Definition pow x y :=\n%   match y with\n%     | pos p => pow_pos x p\n%     | 0 => 1\n%     | neg _ => 0\n%   end.\n\n% Infix \"^\" := pow : Z_scope.\n% \\end{Coqsrc}\n\n% At first sight, the function \\texttt{Pos.pow} seems to be logarithmic because of the recursive structure of the help function \\texttt{iter\\_fix}. Unfortunately, it is obvious that a call to \n% \\texttt{iter f x n} will apply $n$ times the function $f$. Thus, these exponentiation functions with binary exponents are in fact linear!\n\n% \\label{sect:slow-computation}\n\n% \\begin{Coqsrc}\n% Time Compute (1 ^ 56666667)%N.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% Finished transaction in 3.604 secs (3.587u,0.007s)   \n% \\end{Coqanswer}\n\n\n\\subsection{A logarithmic exponentiation  function}\n\nUsing the following equations, we can easily define a polymorphic exponentiation whose application requires only a logarithmic number of multiplications. \n\n\\begin{align}\nx^1 &= x \\label{binary-eq1}\\\\\nx^{2p} &= (x^2)^p \\label{binary-eq2}\\\\\nx^{2p+1} &= (x^2)^p \\times x \\label{binary-eq3}\\\\\nx^1 \\times a &= x \\times a \\label{binary-eq4}\\\\\nx^{2p} \\times a  &= (x^2)^p \\times a\\label{binary-eq5}\\\\\nx^{2p+1} \\times a  &= (x^2)^p \\times (a\\times x)\\label{binary-eq6}\n\\end{align}\n\n\nIn equalities \\ref{binary-eq4} to \\ref{binary-eq6}, the variable $a$ plays the role\nof an \\emph{accumulator} whose initial value (set by \\ref{binary-eq3}) is $x$.\nThis accumulator helps us to get a tail-recursive implementation.\n\nFor instance, the computation of $2^{14}$ can be decomposed as follows:\n\\begin{align*}\n2^{14} &= 4^{7} \\\\\n      &= 16^3 \\times 4 \\\\\n      &= 256^1 \\times (4 \\times 16) \\\\\n      &= 16384  \n\\end{align*}\n\nWith the same notations as in Sect~\\vref{sect:linear-naive}, we can implement this algorithm in \\gallina. The following definitions are still within the scope of the \nsection open in~\\vref{sect: power-definitions}.\n\n\n\n\\label{polymorhic-binary_exp}\n\n%%% ICI (presenter la fonction binaire de First_Steps )\n%%%  Reprendre des explications placees ci-dessous\n\n\\vspace{4pt}\n\n\\emph{From Module\n\\href{../theories/html/additions.FirstSteps.html}{additions.FirstSteps}}\n\n\n\\begin{Coqsrc}\nFixpoint binary_power_mult (x a:A)(p:positive) : A \n  :=\n  match p with\n    | xH =>  a * x\n    | xO q => binary_power_mult  (x * x) a q\n    | xI q =>  binary_power_mult  (x * x) (a * x) q\n  end.\n\nFixpoint Pos_bpow (x:A)(p:positive) :=\n match p with\n  | xH => x\n  | xO q => Pos_bpow  (x * x) q\n  | xI q => binary_power_mult   (x * x) x q\nend.\n\nDefinition N_bpow x (n:N) := \n  match n with \n  | 0%N => 1\n  | Npos p => Pos_bpow x p\n  end.\n\nEnd Definitions.\n\\end{Coqsrc}\n\n\n\n\nLet us  close the section \\texttt{Definitions} and mark the argument \\texttt{A} as implicit.\n\n\\begin{Coqsrc}\nEnd Definitions.\n\nArguments N_bpow {A}.\nArguments power {A}.\n\\end{Coqsrc}\n\n\n\\begin{remark}\nOur function \\texttt{Pos\\_bpow} can be considered as a tail recursive variant\nof the following function defined in \\texttt{Coq.PArith.BinPosDef}.\n\n\n\n\\begin{Coqsrc}\nDefinition iter_op {A}(op:A->A->A) :=\n  fix iter (p:positive)(a:A) : A :=\n  match p with\n    | 1 => a\n    | p~0 => iter p (op a a)\n    | p~1 => op a (iter p (op a a))\n  end.\n\\end{Coqsrc}\n\nThis scheme is used in \\texttt{Coq.ZArith.Zpow\\_alt} in order to define a logarithmic exponentiation \\texttt{Zpower\\_alt} on \\texttt{Z} (notation : $x\\,\\texttt{\\^{}\\^{}}\\,p$).\n\n\\end{remark}\n\n\\paragraph*{Remark}\nNote that closing the section \\texttt{Definitions} makes us lose the\nhandy notations \\texttt{\\_ * \\_} and \\texttt{one}. Fortunately, \\emph{operational type classes} will help us to define nice infix notations for polymorphic functions (Sect.~\\vref{op-classes}).\n\n\\subsection{Examples of computation}\nIt is now possible to test our functions with various interpretations of\n$\\times$ and $1$:\n\n\\begin{Coqsrc}\nCompute N_bpow Z.mul 1%Z 2%Z 10. \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 1024%Z\n     : Z \n\\end{Coqanswer}\n\n\n\\begin{Coqsrc}\nRequire Import String.\nOpen Scope string_scope.\n\nCompute N_bpow append \"\" \"ab\"  12.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = \"abababababababababababab\"\n     : string \n\\end{Coqanswer}\n    \n\n\n\n\n\\subsubsection{Exponentiation on $2\\times 2$ matrices}\n\\label{naive-matrix}\nOur second example is a definition of $M^n$ where $M$ is a $2\\times 2$ matrix\nover any ``scalar''  type $A$, assuming one can provide $A$ with a semi-ring structure~\\cite{Coq}.\n\n\n%\\subsubsection{Representation of $2\\times 2$ matrices}\n\nA $2\\times 2$ matrix will be simply represented by a structure with four fields;\neach field \\texttt{c$ij$} is associated with the $i$-th line and $j$-th column of the considered matrix.\n\n\\begin{Coqsrc}\nModule M2.\nSection Definitions.\n  \n  Variables (A: Type) (zero one : A)  (plus mult  : A -> A -> A).\n  \n  Variable rt : semi_ring_theory  zero one plus mult   (@eq A).\n  Add Ring Aring : rt.\n\n  Notation \"0\" := zero.  \n  Notation \"1\" := one.\n  Notation \"x + y\" := (plus x y).  \n  Notation \"x * y \" := (mult x y).\n  \n  Structure t : Type := mat{c00 : A;  c01 : A;  c10 : A;  c11 : A}.\n\\end{Coqsrc}\n\n%\\subsubsection{Matrix Multiplication}\n\nThe structure type \\texttt{M2.t} allows us to define the product\nof two matrices. \n\n\n\\begin{Coqsrc}\nDefinition M2_mult (M M':t) : t := mat\n  (c00 M * c00 M' + c01 M * c10 M') (c00 M * c01 M' + c01 M * c11 M')\n  (c10 M * c00 M' + c11 M * c10 M') (c10 M * c01 M' + c11 M * c11 M').\n\\end{Coqsrc}\n\nThe neutral element for \\texttt{M2\\_mult} is the identity matrix.\n\n\\begin{Coqsrc}\nDefinition Id2 : t := mat 1 0 0 1.\n\nEnd M2_Definitions.\nEnd M2.\n\\end{Coqsrc}\n\n\\subsection{Computing Fibonacci numbers}\n\nThe sequence of Fibonacci numbers is defined by the following equations:\n\n\\begin{align}\nF_0 & = 1 \\\\\nF_1 & = 1 \\\\\nF_n & = F_{n-1} + F_{n-2} \\quad (n \\geq 2)\n\\end{align}\n\n\nIn \\coq{}, one can define this function by simple recursion.\n\n\\emph{From Library\n\\href{../theories/html/additions.Fib2.html}{additions.Fib2}}\n\n\\begin{Coqsrc}\nFixpoint fib (n:nat) : N :=\n  match n with\n    0%nat | 1%nat => 1%N\n  | S (S p as q) => fib p + fib q\n  end.\n\nCompute fib 20.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 10946 : N\n\\end{Coqanswer}\n\nIn~\\cite{BC04}, several exercices~\\footnote{Exercises 9.8 (page 270), 9.10 (page 271), 9.15 (page 276), 9.17 (page 284), and 15.8 (page 418).}  \npresent ways to compute Fibonacci numbers, with the less number of recursive calls  as possible. Please note that these optimizations and the formal proof of their correctness are \\emph{ad-hoc}, \\emph{i.e.} exclusively written for the \nFibonacci numbers.\nIn contrast, the optimizations we present in this document apply, in their vast majority, \\emph{generic} techniques of efficient computation of powers in a monoid. \nThis example of Fibonacci numbers has been developed with Yves Bertot, who wrote a first version with \\texttt{SSreflect/Mathcomp}~\\cite{MCB, SSR}. \n\n\n\\subsubsection{Using 2x2 integer matrices}\n\\index{maths}{Fibonacci numbers!Matrix exponentiation} \n\nThe following properties are well known. They are left as an exercise, since they are not part of our development. \n\n\\index{additions}{Exercises}\n\n\\begin{exercise}\n  \\begin{enumerate}\n  \\item \n\nProve in \\coq{} the following equality (for any $n\\geq 2$). \\label{fibmat-eq1}\n\n\\[\n\\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right)\n\\left(\n  \\begin{array}{cc}\n    F_{n}& F_{n-1} \\\\\n    F_{n-1} & F_{n-2}\n  \\end{array}\n\\right)\n=\n\\left(\n  \\begin{array}{cc}\n    F_{n+1}& F_{n} \\\\\n    F_{n} & F_{n-1} \n  \\end{array}\n\\right)\n\\]\n  \n\\item Infer (still in \\coq{}) the following equality (still for $n\\geq 2$).\n\n\n\n\\[\n\\left(\n  \\begin{array}{cc}\n    F_{n}& F_{n-1} \\\\\n    F_{n-1} & F_{n-2} \n  \\end{array}\n\\right)\n= \n\\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right)^n\n\\]\n\n\\item Write a function using the previous equality for computing the $n$-th Fibonacci number, and prove its equivalence with \\texttt{fib}.\n\n\\end{enumerate}\n\\end{exercise}\n\n\\subsubsection{Removing duplicate computations}\n\\label{sect:fibonacci-mul2}\n\n\nYves Bertot's optimization relies on the observation that all the powers of\n\\(  \\left(\n  \\begin{array}{cc}\n    1 & 1 \\\\\n    1 & 0 \n  \\end{array}\n\\right) \\) have the form \n\\(  \\left(\n  \\begin{array}{cc}\n    a+b  & a \\\\\n    a & b\n  \\end{array}\n\\right) \\) where $a$ and $b$ are natural numbers.\n\nThus, it is possible to remove duplicate data and computations by reflecting matrix multiplication and identity into $\\mathbb{N}\\times\\mathbb{N}$.\n\nIf we pose $\\varphi(a,b) =\\left(\n  \\begin{array}{cc}\n    a+b  & a \\\\\n    a & b\n  \\end{array}\n\\right)$, then $\\varphi(a,b)\\times \\varphi(c,d)=\\varphi(ac + ad + bc, ac + bd)$, and\n$\\varphi(0,1)=  \\left(\n  \\begin{array}{cc}\n    1 & 0 \\\\\n    0 & 1 \n  \\end{array}\n\\right) $.\n\n\\index{additions}{Exercises}\n\\begin{exercise}\n  Prove formally these properties. \\emph{Please note that their proof is not needed in our development, they just help to understand the following optimization.}\n\\end{exercise}\n\n\nSo, let us define a binary operation, which makes $\\mathbb{N}\\times\\mathbb{N}$ a monoid (with $(0,1)$ as neutral element).\n\n\n\\emph{From Library\n\\href{../theories/html/additions.Fib2.html}{additions.Fib2}} \n\n\\emph{The \\texttt{Monoid} type class is defined \npage~\\pageref{sect:monoid-def}.}\n\n\\begin{Coqsrc}\nDefinition mul2 (p q : N * N) :=\n  match p, q with (a, b),(c,d) => (a*c + a*d + b*c, a*c + b*d) end.\n\nInstance Mul2 : Monoid  mul2 (0,1).\n(* Proof omitted *)\n\\end{Coqsrc}\n\nThe following lemma is a simplification of the equality~\\vref{fibmat-eq1}.\n\n\\begin{Coqsrc}\nLemma next_fib (n:nat) : mul2 (1,0) (fib (S n), fib n) =\n                         (fib (S (S n)), fib (S n)).  \n\\end{Coqsrc}\n\nBy induction\\footnote{Simple induction, since $n$ has type \\texttt{nat}.}\n over $n$, we obtain a the following equalities.\n\n\\begin{Coqsrc}\nDefinition fib_mul2 n := let (a,b) := power (M:=Mul2) (1,0) n   in (a+b).\n\nLemma fib_mul2_OK_0 (n:nat) : power (M:=Mul2) (1,0) (S (S n)) =\n                              (fib (S n), fib n).\n\nLemma fib_mul2_OK n : fib n = fib_mul2 n.\n\\end{Coqsrc}\n\nThus, any function able to compute more or less efficiently powers in a monoid will\ngive an algorithm for computing Fibonacci numbers. Unlike the \\emph{ad-hoc} aforementionned proofs of~\\cite{BC04}, the correctness of such an algorithm is a direct consequence \nof the correctness of the used powering function.\nSeveral examples will be presented in the rest of this document\n(in sections~\\vref{sect:fibonacci-pos-bpow}).\n\n\n\n\n% \\begin{Coqsrc}\n\n% Import M2.\n\n% Arguments M2_mult {A} plus mult  _  _.\n% Arguments mat {A} _ _ _ _.\n% Arguments Id2 {A}  _ _.\n\n% Definition fibonacci (n:N) :=\n%  c00 N  (N_bpow  (M2_mult Nplus Nmult) \n%                  (Id2  0%N 1%N)\n%                  (mat  1 1 1 0)%N \n%                  n).\n\n% Compute fibonacci 20.\n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% = 10946%N\n%      : N  \n% \\end{Coqanswer}\n\n\\begin{todo}\nDocument the files contributed by Yves\n\\begin{itemize}\n\\item additions/fib.v (to rename ?)\n\\item additions/stub.ml (to keep inside theories/ or move to src/ ?)\n\\item theories/additions/make\\_fib\\_tests.txt (to put in a Makefile?)\n\\end{itemize}\n\\end{todo}\n\n\n\n\n% \\subsubsection{Remark}\n% \\label{sect:faster}\n\n% Our function \\texttt{N\\_bpow} is really logarithmic. Let us make a comparative \n% test with Standard Library's exponentiation function on type \\texttt{N} (see section~\\vref{sect:slow-computation}).\n\n% \\begin{Coqsrc}\n% Time Compute (N_bpow N.mul 1 1 56666667)%N.  \n% \\end{Coqsrc}\n\n% \\begin{Coqanswer}\n% Finished transaction in 0. secs (0.u,0.s) (successful)  \n% \\end{Coqanswer}\n\n\n\n\n\\subsection{Formal specification of an exponentiation function: a first attempt}\n\nLet us compare the functions \\texttt{power} and \\texttt{N\\_bpow}.\nThe first one is obviously correct, since it is a straightforward translation of the mathematical definition.\nThe second one is much more efficient, but it is not obvious  that its 18-line long definition is bug-free.\nThus, we must prove that the two functions are extensionally equal (taking into account conversions\nbetween \\texttt{N} and \\texttt{nat}).\n\nMore abstractly, we can define a predicate that characterizes any correct implementation \nof \\texttt{power}, this ``naive''  function being a \\emph{specification} of any polymorphic\nexponentiation function.\n\nFirst, we define a type for any such function.\n\n\\begin{Coqsrc}\nDefinition power_t := forall (A:Type)\n                             (mult : A -> A -> A)\n                             (one:A)\n                             (x:A)\n                             (n:N), A.\n\\end{Coqsrc}\n\nThen, we would say that a function \\texttt{f:power\\_t} is a correct exponentiation function if it\nis extensionally equal to \\texttt{power}.\n\n\\begin{Coqbad}\nModule Bad.\n\n Definition correct_expt_function (f : power_t) : Prop :=\n  forall A (mult : A -> A -> A) (one:A)\n            (x:A) (n:N), \n            power mult one x (N.to_nat n) = f A mult one x n.\n\\end{Coqbad}\n\n\nUnfortunately, our definition of \\texttt{correct\\_expt} is too general. It suffices to build \nan interpretation where the multiplication is not associative or \\texttt{one} is not a neutral\nelement to obtain different results through the two functions.\n\n\n\n\\begin{Coqbad}\nSection CounterExample.\n    Let mul (n p : nat) := n + 2 * p.\n    Let one := 0.\n\n    Remark mul_not_associative :\n      exists  n p q,  mul n (mul p q) <> mul (mul n p) q.\n    Proof. \n        exists 1, 1, 1; discriminate. \n    Qed.\n\n    Remark one_not_neutral  :\n      exists n : nat, mul one n <> n.\n    Proof.\n      exists 1; discriminate.\n    Qed.\n\n    Lemma correct_expt_too_strong : \n          ~ correct_expt_function (@N_bpow).\n    Proof.\n      intro H; specialize (H _ mul one 1  7%N).\n      discriminate H.    \n    Qed.\n\nEnd CounterExample.\nEnd Bad.\n \\end{Coqbad}\n\n\nSo, we will have to improve our definition of correctness, by restricting  the universal quantification to associative operations and neutral elements, \\emph{i.e.}, by considering \\emph{monoids}.\nAn exponentiation  function will be considered as correct if it returns always the same result as \\texttt{power} \\emph{in any monoid}.\n\n\n\n\\section{Representing monoids in \\coq \\label{monoid-class-def}}\n\nIn this section, we present a ``minimal'' algebraic framework in which  exponentiation can be defined and efficiently implemented.\n\nExponentiation is built on multiplication, and many properties of \nthis operation are derived from the associativity of multiplication. \nFurthermore, if we allow the exponent to be any natural number, including $0$, \nthen we need to consider a neutral element for multiplication.\n\nThe structure on which we define exponentiation is called a \\emph{monoid}.\nIt is composed of a \\emph{carrier} $A$, an associative binary operation $\\times$ on $A$, and a neutral element $\\mathds{1}$ for $\\times$ . The required properties of $\\times$ and\n$\\mathds{1}$ are expressed by the following equations:\n\n\n\\begin{align}\n  \\label{eq}\n  \\forall x\\,y\\,z\\,:A,\\, x\\times (y \\times z) &= (x\\times y) \\times z\n  \\\\\n\\forall x:A,\\, x \\times \\mathds{1}  &= \\mathds{1}  \\times x = x\n\\end{align}\n\n\nIn \\coq{}, we define the monoid structure in terms of \n\\emph{type classes}\\cite{MS08,BS2011}. The tutorial on type classes \\cite{PCMS} gives more details on type classes and\noperational type classes, also illustrated with the monoid structure.\n\n\nFirst, we define a class and a notation for representing multiplication operators, then we use\nthese definitions for defining the \\texttt{Monoid} type class.\n\n\\subsection{A common notation for multiplication}\n\\label{op-classes}\n\\index{coq}{Type classes!Operational type classes}\n≈Ò\n\\emph{Operational type classes}~\\cite{BS2011}\nallow us to define a common notation \nfor multiplication in any algebraic structure. \nFirst, we associate a class to the notion of \\emph{multiplication} \non any type $A$.\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions/Monoid\\_def.v}.}\n\n\\begin{Coqsrc}\nClass Mult_op (A:Type) := mult_op : A -> A -> A.  \n\\end{Coqsrc}\n\nFrom the type theoretic point of view, the term (\\texttt{Mult\\_op $A$}) is \n$\\beta\\delta$-reducible to \\texttt{$A\\arrow A \\arrow A$}, and\nif \\texttt{\\it op} has type (\\texttt{Mult\\_op $A$}), then \n(\\texttt{@mult\\_op A {\\it op}}) is convertible with \\texttt{\\it op}.\n\nWe are now ready to define a new notation scope, in which the notation\n\\texttt{x * y} will be interpreted as an application of the function\n\\texttt{mult\\_op}.\n\n\\begin{Coqsrc}\nDelimit Scope M_scope with M.\nInfix \"*\" := mult_op : M_scope.\nOpen Scope M_scope.  \n\\end{Coqsrc}\n\n Let us show two examples of use of the\nnotation scope \\texttt{M\\_scope}. Each example consists in declaring an \ninstance of \\texttt{Mult\\_op}, then type checking or evaluating\na term of the form \\texttt{x * y} in \\texttt{M\\_scope}.\n\nNote that, since the reserved notation \\texttt{\"\\_ * \\_ \"} is \npresent in several scopes such as  \\texttt{nat\\_scope}, \\texttt{Z\\_scope},\n\\texttt{N\\_scope}, etc., in addition to  \\texttt{M\\_scope},  the user should\ntake care of which scopes are active --- and with  which precedence --- in a \\gallina{} term.\nIn case of doubt, explicit scope delimiters should be used.\n  \n\n\n\n\n\\subsubsection{Multiplication on Peano numbers}\n\nMultiplication  on type \\texttt{nat}, called \\texttt{Nat.mul} in\nStandard Library, has  type \\linebreak \\texttt{nat -> nat -> nat}, which is\nconvertible  with \\texttt{Mult\\_op nat}. Thus the following definition is\naccepted:\n\n\\begin{Coqsrc}\nInstance nat_mult_op : Mult_op nat  := Nat.mul.\n\\end{Coqsrc}\n\nInside \\texttt{M\\_scope}, the expression \\texttt{3 * 4} is \ncorrectly read as an application of \\texttt{mult\\_op}. Nevertheless \nthis term is convertible with \\texttt{Nat.mul 3 4}, as shown by the \ninteraction below.\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\begin{Coqsrc}\nSet Printing All.\nCheck  3 * 4. \n\\end{Coqsrc}\n\\begin{Coqanswer}\n@mult_op nat nat_mult_op (S (S (S O))) (S (S (S (S O))))\n     : nat  \n\\end{Coqanswer}\n\\begin{Coqsrc}\nUnset Printing All.\nCompute 3 * 4.   \n\\end{Coqsrc}\n\\begin{Coqanswer}\n = 12  : nat  \n\\end{Coqanswer}\n\n\\subsubsection{String concatenation}\nWe can use the notation \\texttt{\"\\_ * \\_ \"} for other types than numbers.\nIn the following example,  the expression \\texttt{\"abc\" * \"def\"} is interpreted\nas \\linebreak \\texttt{@mult\\_op string  {\\color{darkred}?X} \"abc\"  \"def\"}, then the type  class mechanism replaces the unknown  {\\color{darkred}?X} with \n\\texttt{string\\_op}.\n\n\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\begin{Coqsrc}\nRequire Import String.\n\nInstance string_op : Mult_op string := append.\nOpen Scope string_scope.\n\nExample ex_string : \"ab\" * \"cde\" = \"abcde\".\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\n\n\\subsubsection{Solving ambiguities}\nLet $A$ be some type, and let us assume there are several instances of\n\\texttt{Mult\\_op $A$}. For solving ambiguity issues, one can\nadd a \\emph{precedence} to each instance declaration of  \n\\texttt{Mult\\_op $A$}. In any case, such ambiguity  can be addressed\nby explicitly providing  some arguments of \\texttt{mult\\_op}.\nFor instance, in Sect.~\\vref{nat-monoids}, we consider various monoids on types\n\\texttt{nat} and \\texttt{N}. \n\n\n\\subsection{The Monoid type class}\n\\index{coq}{Type classes}\nWe are now ready to  give a definition of the \\texttt{Monoid} class, using\n\\texttt{*} as an infix operator in scope \\coqscope{M} for the monoid  multiplication.\n\nThe following class definition, from Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def},\nis parameterized with some type $A$,\na multiplication (called \\texttt{op} in the definition), and a neutral element\n$\\mathds{1}$ (called \\texttt{one} in the definition).\n\n\\label{sect:monoid-def}\n\n\\index{additions}{Type classes!Monoid}\n\n\\begin{Coqsrc}\nClass Monoid {A:Type}(op : Mult_op A)(one : A) : Prop :=\n{\n    op_assoc : forall x y z:A, x * (y * z) = x * y * z;\n    one_left : forall x, one * x = x;\n    one_right : forall x, x * one = x\n}.\n\\end{Coqsrc}\n\n\n\\subsection{Building instances of \\texttt{Monoid}}\nLet \\texttt{$A$} be some type, \\texttt{{\\it op}} an instance of \n\\texttt{Mult\\_op $A$} and \\texttt{\\it one: $A$}.\nIn order to build an instance of (\\texttt{Monoid $A$ {\\it op} {\\it one}}),\none has to provide proofs of ``monoid axioms'' \\texttt{ op\\_assoc},\n\\texttt{one\\_left} and \\texttt{one\\_right}.\n\nLet us show various instances, which will be used in further proofs and examples.\nComplete definitions and proofs are given in \nFile~\\href{../theories/html/additions.Monoid_instances.html}{additions/Monoid\\_instances.v}.\n\n\n\\subsubsection{Monoid on \\texttt{Z}}\nThe following monoid allows us to compute powers of integers of arbitrary size, \nusing type \\texttt{Z} from standard library:\n\n\\begin{Coqsrc}\nInstance Z_mult_op : Mult_op Z := Z.mul.\n\nInstance ZMult : Monoid  Z_mult_op 1.\nProof. \n  split.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n3 subgoals, subgoal 1 (ID 8)\n  \n  ============================\n   forall x y z : Z, (x * (y * z))%M = (x * y * z)%M\n\nsubgoal 2 (ID 9) is:\n forall x : Z, (1 * x)%M = x\nsubgoal 3 (ID 10) is:\n forall x : Z, (x * 1)%M = x}\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n    all: unfold Z_mult_op, mult_op;intros;ring.\nQed.\n\\end{Coqsrc}\n\n\n\\subsubsection{Monoids on type \\texttt{nat} and \\texttt{N}}\n\\label{nat-monoids}\n% ~~\\\\\n% \\noindent \n\nWe define two monoids on type \\texttt{nat}:\n\\begin{itemize}\n\\item The ``natural'' monoid $(\\mathbb{N},\\times, 1)$ :\n\n  \\begin{Coqsrc}\nInstance nat_mult_op : Mult_op nat | 5 := Nat.mul.\n\nInstance  Natmult : Monoid nat_mult_op  1%nat | 5\nProof.\n   split;unfold nat_mult_op, mult_op; intros; ring.\nQed.\n\\end{Coqsrc}\n\n\\item The ``additive''  monoid $(\\mathbb{N},+, 0)$.\nThis monoid will play an important role in correctness proofs of complex\nexponentiation algorithms. Its most important property is that the $n$-th \npower of $1$ is equal to $n$. See Sect.~\\vref{correctness-for-free} for more details.\n\n\\begin{Coqsrc}\nInstance nat_plus_op : Mult_op nat | 12 := Nat.add.\n\nInstance Natplus : Monoid nat_plus_op  0%nat | 12.\n(* Proof omitted *)\n\\end{Coqsrc}\n\\end{itemize}\n\nSimilarly, instances \\texttt{NMult} and  \\texttt{NPlus}  are built for type \\texttt{N}, and\n\\texttt{PMult} for type \\texttt{positive}.\n\n\\subsubsection{Machine integers}\n\nCyclic numeric types are  good candidates for testing exponentiations\nwith big exponents, since the size of data is bounded.\n\nThe type \\texttt{int31} is defined  in Module\n\\textbf{Coq.Numbers.Cyclic.Int31.Int31} of \\coq's standard library. The tactic \\texttt{ring} works \nwith this type, and helps us to register an instance \\texttt{Int31Mult} of class  \\texttt{Monoid int31\\_mult\\_op 1}.\n\n\\begin{Coqsrc}\nInstance int31_mult_op : Mult_op int31 := mul31.\n\nInstance  Int31mult : Monoid int31_mult_op  1.\nProof.\n   split;unfold int31_mult_op, mult_op; intros; ring.\nQed.\n\\end{Coqsrc}\n\nBeware that machine integers are not natural numbers! \n\n\\begin{Coqbad}\nModule Bad.\n\nFixpoint int31_from_nat (n:nat) :=\n  match n with\n  | O => 1\n  | S p => 1 + int31_from_nat p\n  end.\n\nCoercion int31_from_nat : nat >-> int31.\n\nFixpoint fact (n:nat) := \n  match n with\n   | O => 1\n   | S p => n * fact p\n  end.\n\nExample fact_zero : exists n:nat, fact n = 0.\nProof.  now exists 40%nat.  Qed.\n\nEnd Bad.\n\\end{Coqbad}\n\n\\subsection{Matrices on a semi-ring}\n\nIn Sect.\\vref{naive-matrix}, we defined a function for computing powers of any $2\\times 2$ \nmatrix over any semi-ring. For proving a simple property of matrix exponentiation, we had\n to prove that matrix multiplication is associative and admits the identity matrix as a neutral element. These properties are easily expressed within the type class framework, by defining a \\emph{family} of monoids.\nIt suffices to define an instance of \\texttt{Monoid} within the scope of an hypothesis\nof type \\texttt{semi\\_ring\\_theory}\n\n\\begin{Coqsrc}\nSection M2_def.\nVariables (A:Type)\n           (zero one : A) \n           (plus mult  : A -> A -> A).\n\n Variable rt : semi_ring_theory  zero one plus mult  (@eq A).\n Add  Ring Aring : rt.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nStructure M2 : Type := {c00 : A;  c01 : A;\n                        c10 : A;  c11 : A}.\n\nDefinition Id2 : M2 := Build_M2 1 0 0 1.\n\nDefinition M2_mult (m m':M2) : M2 :=\n Build_M2 \n          (c00 m * c00 m' + c01 m * c10 m')\n          (c00 m * c01 m' + c01 m * c11 m')\n          (c10 m * c00 m' + c11 m * c10 m')\n          (c10 m * c01 m' + c11 m * c11 m').\n\nGlobal Instance M2_op : Mult_op M2 := M2_mult.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nGlobal Instance M2_Monoid : Monoid   M2_op Id2.\n(* Proof omitted *)\n\nEnd M2_def.\n\nArguments M2_Monoid {A zero one plus mult} rt.\n\\end{Coqsrc}\n\n\n\\subsection{Monoids and equivalence relations}\n\\index{coq}{Generalized rewriting}\n\\index{coq}{Type classes!Equivalence relations}\n\nIn some contexts, the ``axioms'' of the \\texttt{Monoid} class  may be too restrictive.\nFor instance, consider multiplication in $\\mathds{Z}/m\\mathds{Z}$ where\n $1<m$.\nAlthough it could be possible to compute with values of the dependent \ntype \\texttt{\\{n:N | n < m\\}}, \nit looks simpler to compute with numbers of type\n\\texttt{N} and consider the multiplication $x \\times y \\mod{m}$.\n\n\n\nIt is easy to prove that this operation is associative, using library \\texttt{NArith}. Unfortunately, the following proposition is false in general (left as an exercise).\n\n$$\\forall x:N, (1 * x) \\mod{m} = x$$\n\n\nThus, we define a more general class, parameterized by an equivalence\nrelation \\texttt{Aeq}  on a type \\texttt{A}, compatible with the multiplication \\texttt{*}. The laws of associativity and neutral element\nare not expressed as Leibniz equalities but as equivalence statements:\n\nFirst, let us define an operational type class for equivalence relations:\n\n\\vspace{4pt}\n\n\\noindent\n\\emph{From Module \\href{../theories/html/additions.Monoid_def.html}{additions.Monoid\\_def}}\n\n\\begin{Coqsrc}\nClass Equiv A := equiv : relation A.\n\nInfix \"==\" := equiv (at level 70) : type_scope.\n\\end{Coqsrc}\n\nThe definition of class \\texttt{EMonoid} looks like \\texttt{Monoid}'s definition, \nplus some constraints on \\texttt{E\\_eq}.\n\nPlease look for instance at our tutorial on type classes and relations~\\cite{PCMS} \nfor understanding the use of  type classes \\texttt{Equivalence}, \\texttt{Reflexive}, \\texttt{Proper}, etc, in relation with tactics like \\texttt{rewrite}, \\texttt{reflexivity}, etc., in proofs which involve  equivalence relations instead of equality.\n\n\\index{coq}{Type classes}\n\\index{Coq}{Type classes!Proper class}\n\\label{EMonoid-def}\n\n%\\todo{link to Proper in stdlib : Coq.Classes.Morphisms and Coq.Classes.CMorphisms}\n \n\n\\index{additions}{Type classes!EMonoid}\n\n\\begin{Coqsrc}\nClass EMonoid (A:Type)(E_op : Mult_op A)(E_one : A) \n      (E_eq: Equiv A): Prop :=\n  {\n    Eq_equiv :> Equivalence equiv;\n    Eop_proper :> Proper (equiv ==> equiv ==> equiv) E_op;\n    Eop_assoc : forall x y z, x * (y * z) == x * y * z;\n    Eone_left : forall x,  E_one * x == x;\n    Eone_right : forall x,  x * E_one ==  x\n  }.\n\\end{Coqsrc}\n\n\\subsubsection{Coercion from Monoid to EMonoid} \nEvery instance of class  \\texttt{Monoid} can be transformed into an instance of\n\\texttt{EMonoid}, considering Leibniz' equality \\texttt{eq}.\nThus, our  definitions and theorems about exponentiation will take place as \nmuch as possible within the more generic framework of \\texttt{EMonoid}s.\n\n\n\\index{coq}{Coercions}\n\n\\begin{Coqsrc}\nGlobal Instance eq_equiv {A} : Equiv A := eq.\n\nGlobal Instance Monoid_EMonoid `(M:@Monoid A op one) :\n        EMonoid  op one eq_equiv.\nProof.\nsplit; unfold eq_equiv, equiv in *.\n - apply eq_equivalence.\n - intros x y H z t H0; now subst.\n - intros; now rewrite (op_assoc).\n - intro; now rewrite one_left.\n - intro; now rewrite one_right.\nDefined.\n\\end{Coqsrc}\n\n\\begin{remark}\nIn the definition of \\texttt{Monoid\\_EMonoid}, the free variables  \\texttt{A}, \n\\texttt{op} and \\texttt{one} are automatically generalized thanks to the \\emph{backquote} syntax (see the section about implicit generalization in the reference manual~\\cite{Coq}).\n\\end{remark}\n\nThanks to the following \\emph{coercion}, every instance of \\texttt{Monoid} can \nnow be considered as an instance of \\texttt{EMonoid}. For more details, please look at the section \\emph{Implicit Coercions} of \\coq's reference manual~\\cite{Coq}.\n\n\n\n\n\n\n\\begin{Coqsrc}\nCoercion Monoid_EMonoid : Monoid >-> EMonoid.\n\\end{Coqsrc}\n\n%ici% \n\n\\emph{From Module \\href{../theories/html/additions.Monoid_instances.html}{additions.Monoid\\_instances}}\n\n\\begin{Coqsrc}\nCheck NMult : EMonoid  N.mul 1%N eq.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  NMult:EMonoid N.mul 1%N eq\n     : EMonoid N.mul 1%N eq\n\\end{Coqanswer}\n\n\\subsubsection{Example : Arithmetic  modulo $m$}\n\n \nThe following instance of \\texttt{EMonoid} describes the set of integers modulo\n$m$, where $m$ is any integer greater than or equal to $2$.\nFor simplicity's sake, we represent such values using the \\texttt{N} type,\nand consider ``equivalence modulo \\texttt{$m$}'' instead of equality.\nNote that the law of associativity has been stated as Leibniz' equality.\n\n\n\\begin{Coqsrc}\nSection Nmodulo.\n  Variable m : N.\n  Hypothesis m_gt_1 : 1 < m.\n    \n  Definition mult_mod ( x y : N) := (x * y) mod m.\n  Definition mod_eq ( x y: N) := x mod m = y mod m.\n  \n  Global Instance mod_equiv : Equiv N := mod_eq.\n\n  Global Instance mod_op : Mult_op N := mult_mod.\n  \n  Global Instance mod_Equiv : Equivalence mod_equiv.\n  (* Proof omitted *)\n  \n  Global Instance mult_mod_proper : \n  Proper (mod_equiv ==> mod_equiv ==> mod_equiv)  mod_op.\n  (* Proof omitted *) \n  \n  Local Open Scope M_Scope.\n\n  Lemma mult_mod_associative :  \n  forall x y z,  x * (y * z) = x * y * z.\n  (* Proof omitted *) \n  \n  Lemma one_mod_neutral_l  : forall x, 1 * x ==  x.\n  (* Proof omitted *) \n  \n  Lemma one_mod_neutral_r  : forall x, x * 1 == x.\n  (* Proof omitted *) \n  \n  Global Instance Nmod_Monoid : EMonoid  mod_op 1 mod_equiv.\n  (* Proof omitted *) \n\nEnd Nmodulo.\n\n\\end{Coqsrc}\n\n\\paragraph{Example}\nIn the following interaction, we show how to instantiate the parameter \\texttt{$m$} to a \nconcrete value, for instance \\texttt{$256$}.\n\n\\begin{Coqsrc}\nSection S256.\nLet mod256 :=  mod_op 256.\nLocal Existing Instance mod256 | 1.\n\nCompute (211 * 67)\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 57 : N  \n\\end{Coqanswer}\n  \n\\begin{Coqsrc}\nEnd S256.\n\\end{Coqsrc}\n\nOutside the section \\texttt{S256}, the term \\texttt{(211 * 67)\\%M} is interpreted as a plain multiplication in type \\texttt{N}:\n\n\\begin{Coqsrc}\nCompute (211 * 67)%M.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 14137 : N   \n\\end{Coqanswer}\n\n\\section{Computing powers in any EMonoid}\n\nThe  module \\href{../theories/html/additions.Pow.html}{additions.Pow} defines two functions for exponentiation on any \n\\texttt{EMonoid}  on carrier $A$.\nThey are essentially the same as in Sect.~\\vref{sect: power-definitions}. The main difference lies in the arguments of the functions, which now contain\n an instance~\\texttt{M} of class \\texttt{EMonoid}. \nThus, the arguments associated with the multiplication,\nthe neutral element and the equivalence relation associated with \\texttt{M}\nare left implicit.\n\n\n\\subsection{The naive (linear) algorithm}\nThe new version of the linear exponentiation function is as follows:\n\n\\begin{Coqsrc}\nFixpoint power`{M: @EMonoid A  E_op E_one E_eq} \n               (x:A) (n:nat) :=\nmatch n with \n| 0%nat => E_one\n| S p =>   x * x ^ p\nend\nwhere \"x ^ n\" := (power x n) : M_scope.\n\\end{Coqsrc}\n\nThe three following lemmas will be used by the \\texttt{rewrite} tactic in further\ncorrectness proofs.\nNote  that the first two lemmas are strong\n(\\emph{i.e.}, Leibniz) equalities, whilst \\texttt{power\\_eq3}  is only an equivalence statement, because its proof uses one of the \\texttt{EMonoid} laws, namely\n\\texttt{Eone\\_right}.\n\n\\begin{Coqsrc}\nLemma power_eq1 {A:Type} `{M: @EMonoid A  E_op E_one E_eq} \n               (x:A) :  x ^ 0 = E_one.\nProof. reflexivity. Qed.\n\nLemma power_eq2 {A:Type} `{M: @EMonoid A  E_op E_one E_eq}\n                (x:A) (n:nat) :\n                x ^ (S n)  = x * x ^ n.\nProof. reflexivity. Qed.\n\nLemma power_eq3 {A:Type} `{M: @EMonoid A  E_op E_one E_eq}\n                (x:A) : x ^ 1 == x.\nProof. cbn; rewrite Eone_right; reflexivity. Qed.\n\\end{Coqsrc}\n\n\\subsubsection{Examples of computation}\n\nIn the following computations, we first show an exponentiation in $\\mathds{Z}$, then in\nthe type of 31-bit machine integers.\\footnote{\\texttt{phi} and \\texttt{phi\\_inv} are \nstandard library's conversion\nfunctions between types \\texttt{Z} and \\texttt{int31}, used for making it possible to read  and print values of type \\texttt{int31}.}\n\n\\vspace{4pt}\n\nFrom Module~\\href{../theories/html/additions.Demo_power.html}{additions.Demo\\_power}\n\n\n\n\\begin{Coqsrc}\nOpen Scope M_scope.\n\nCompute 22%Z ^ 20.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 705429498686404044207947776%Z\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nImport Int31.\nCoercion phi_inv : Z >-> int31.\n\nCompute (22%int31 ^ 20).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = 2131755008%int31\n     : int31\n\\end{Coqanswer}\n\n\\subsection{The binary exponentiation algorithm}\n\nPlease find below the implementation of binary exponentiation using type classes\n(to be compared with the version in~\\vref{polymorhic-binary_exp}).\n\n\n% It takes the form of an auxiliary function  \\texttt{binary\\_power\\_mult}\n% associated with equalities \\ref{binary-eq4} to \\ref{binary-eq6} and a main function \\texttt{Pos\\_bpow} associated with equalities \\ref{binary-eq1} to \\ref{binary-eq3}.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}}\n\n\\begin{Coqsrc}\nFixpoint binary_power_mult `{M: @EMonoid A E_op E_one E_eq}\n             (x a:A)(p:positive) : A \n  :=\n  match p with\n    | xH =>    a * x\n    | xO q => binary_power_mult  (x * x) a q\n    | xI q =>   binary_power_mult (x * x) (a * x) q\n  end.\n\nFixpoint Pos_bpow  `{M: @EMonoid A E_op E_one E_eq} \n         (x:A)(p:positive) :=\n match p with\n  | xH => x\n  | xO q => Pos_bpow  (x * x) q\n  | xI q => binary_power_mult (x * x) x q\nend.\n\\end{Coqsrc}\n\n\nIt is easy to extend \\texttt{Pos\\_bpow}'s domain to the type of all \nnatural numbers:\n\n\\vspace{4pt}\nFrom Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}\n\n\\begin{Coqsrc}\nDefinition N_bpow {A} `{M: @EMonoid A E_op E_one E_eq} x (n:N) := \n  match n with \n  | 0%N => E_one\n  | Npos p => Pos_bpow x p\n  end.\n\nInfix \"^b\" := N_bpow (at level 30, right associativity): M_scope.\n\\end{Coqsrc}\n\n\\subsection{Refinement and correctness}\nWe have got two functions for computing powers in any monoid. \nSo, it is interesting to ask oneself whether this duplication is useful, and which would be the respective role of \\texttt{N\\_bpow} and \\texttt{power}.\n\n\\begin{itemize}\n\\item The function \\texttt{power}, although very inefficient, is a direct \ntranslation of the mathematical definition, as shown by  lemmas \\texttt{power\\_eq1} to \\linebreak \\texttt{power\\_eq3}. Moreover, its structural recursion over type \\texttt{nat} allows simple proofs by induction over the exponent. \nThus, we will consider \\texttt{power} as a \\emph{specification} of any exponentiation algorithm.\n\n\\item Functions \\texttt{N\\_bpow} and \\texttt{Pos\\_bpow} are more efficient, but less readable than \\texttt{power}, and we cannot use these functions before \nhaving proved their correctness. In fact, the correctness of \n\\texttt{N\\_bpow} and \\texttt{Pos\\_bpow} will mean ``being extensionally equivalent to \\texttt{power}''.\nFor instance \\texttt{N\\_bpow}'s correctness is expressed by the following\nstatement (in the context of an \\texttt{EMonoid} on type \\texttt{A}).\n\n\n\\vspace{4pt}\nFrom Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}\n\n\\begin{Coqsrc}\nLemma N_bpow_ok : \nforall (x:A) (n:N),   x ^b n  == x ^ N.to_nat n.\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\\end{itemize}\n\n\nThe relationship between \\texttt{power} and \\texttt{N\\_bpow} can be considered\nas a kind of \\emph{refinement} as in the \\texttt{B}-method~\\cite{b-book}. Note\nthat the two representations of natural numbers and the function \\texttt{N.to\\_nat}\nform a kind of  \\emph{data refinement} \\cite{Abrial:2010:MES:1855020, cohen:hal-01113453}.\n\n\n\n\\subsection{Proof of correctness of binary exponentiation w.r.t. the function \\texttt{power}}\nSection \\texttt{M\\_given} of Module \n~\\href{../theories/html/additions.Pow.html}{additions.Pow} is devoted to the proof \nof properties of the functions above.\nNote that properties of \\texttt{power} refer to the \\emph{specification} of exponentiation, and can be applied for proving correctness of any implementation.\n\nIn this section, we consider an arbitrary instance  \\texttt{M} of class \\texttt{EMonoid}.\n\n\\begin{Coqsrc}\nSection M_given.\n Variables (A:Type) (E_op : Mult_op A)(E_one:A) (E_eq : Equiv A).\n Context (M:EMonoid  E_op E_one E_eq).\n\\end{Coqsrc}\n\n\\subsubsection{Properties of exponentiation}\nWe establish a few well-known properties of exponentiation, and define some basic tactics for simplifying proof search.\n\n\\begin{Coqsrc}\nLtac monoid_rw :=\n    rewrite Eone_left  ||\n    rewrite Eone_right  || \n    rewrite Eop_assoc .\n\nLtac monoid_simpl := repeat monoid_rw.\n\nSection About_power.\n\\end{Coqsrc}\n\nIn order to make possible proof by rewriting on expressions which contain\nthe exponentiation operator, we have to prove that, whenever \\texttt{$x$ == $y$},\nthe equality \\texttt{$x^n$ == $y^n$} holds for any exponent \\texttt{$n$}. \nFor this purpose, we use the \\texttt{Proper} class of module\n\\href{https://coq.inria.fr/distrib/current/stdlib/Coq.Classes.Morphisms.html}{Coq.Classes.Morphisms}\n\\index{coq}{Type classes}\n\\index{coq}{Type classes!Proper class}\n\\begin{Coqsrc}\nGlobal Instance power_proper :\n     Proper (equiv ==> eq ==> equiv) power.\n(* Proof omitted *)\n\\end{Coqsrc}\n\nIn the following proofs, we note how notations, type classes and generalized \nrewriting can be used  to write algebraic properties in a nice way.\n\n\\begin{Coqsrc}\nLemma power_of_plus :   forall x n p, x ^ (n + p) ==  x ^ n *  x ^ p.\n(* Proof omitted *)\n\nLtac power_simpl := \n    repeat (monoid_rw || rewrite <- power_x_plus).\n\\end{Coqsrc}\n\n  Please note that the following two lemmas \\emph{do not require} \nthe operation~\\texttt{*} to be commutative.\n\n\\begin{Coqsrc}\nLemma power_commute : \n    forall x n p, x ^ n * x ^ p ==  x ^ p * x ^ n. \n(* Proof omitted *) \n\nLemma power_commute_with_x : \n    forall x n,  x * x ^ n == x ^ n * x.\n(* Proof omitted *) \n\nLemma power_of_power : \n   forall x n p,  (x ^ n) ^ p == x ^ (p * n).\n(* Proof omitted *) \n\n\\end{Coqsrc}\n\nThe following two equalities are auxiliary lemmas for proving correctness of the binary exponentiation functions.\n\n\\begin{Coqsrc}\nLemma sqr_def : forall x, x ^ 2 ==  x * x.\n(* Proof omitted *) \n\nLemma power_of_square : \n  forall x n, (x * x) ^ n ==  x ^ n * x ^ n.\n(* Proof omitted *) \n\\end{Coqsrc}\n\n\\subsection{Equivalence of the two exponentiation functions}\n\nSince \\texttt{binary\\_power\\_mult} is defined by structural recursion on the\nexponent \\texttt{p:positive}, its basic properties are proved by induction\nalong \\texttt{positive}'s constructors.\n\n\\vspace{4pt}\n\\emph{From Module~\\href{../theories/html/additions.Pow.html}{additions.Pow}}\n\n\\begin{Coqsrc}\nLemma binary_power_mult_ok :\n  forall p a x,   binary_power_mult  x a p  ==  \n                  a * x ^ Pos.to_nat p.\nProof.\n  induction p as [q IHq | q IHq| ].\n (* Rest of proof omitted *)\n \\end{Coqsrc}\n\n \\begin{Coqsrc}\nLemma Pos_bpow_ok : \n  forall p x, Pos_bpow x p == x ^ Pos.to_nat p.\n(* Proof omitted *)\n\nLemma N_bpow_ok : \n  forall n x,  x ^b n  == x ^ N.to_nat n.\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma N_bpow_ok_R : \n  forall n x, x ^b (N.of_nat n)   ==  x ^  n.\n(* Proof omitted *)\n\nLemma Pos_bpow_ok_R : \n   forall p x, p <> 0 ->\n                      Pos_bpow x  (Pos.of_nat p)   ==  x ^  p.\n(* Proof omitted *)\n\nEnd About_power.  \n\\end{Coqsrc}\n\n\\subsubsection{Remark}\nThe preceding lemmas can be applied for deriving properties of the binary exponentiation \nfunctions:\n\n\\begin{Coqsrc}\nLemma N_bpow_commute : forall x n p,  \n                        x ^b n *  x ^b p ==  \n                        x ^b p *  x ^b n.\nProof.\n intros x n p; repeat rewrite N_bpow_ok.\n rewrite power_commute; reflexivity.\nQed.  \n\\end{Coqsrc}\n\n\\subsection{Fibonacci, once again}\n\\label{sect:fibonacci-pos-bpow}\n\nWe can use the function \\texttt{Pos\\_bpow} for computing Fibonacci numbers\n(see Section~\\vref{sect:fibonacci-mul2}).\n\n\n\\begin{Coqsrc}\nDefinition fib_pos n :=\n  let (a,b) := Pos_bpow (M:= Mul2) (1,0) n in\n  (a+b).\n\nTime Compute fib_pos 153%positive.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  68330027629092351019822533679447\n     : N \nFinished transaction in 0.002 secs (0.002u,0.s) (successful)\n\\end{Coqanswer}\n\nFibonacci will come back in Sect.~\\vref{sect:fibonacci-euclidean}.\n\n\n\\section{Comparing exponentiation algorithms with respect to efficiency}\n\nIt looks obvious that  the binary exponentiation algorithm is more efficient than the \nnaive one. Can we study \\emph{within \\coq{}} the respective efficiency of both functions?\nLet us take a simple example with the exponent $17$,  in any \\texttt{EMonoid}.\n\n\\begin{Coqsrc}\nEval simpl in   fun (x:A) => x ^b 17.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = fun x : A =>\n       x *\n       (x * x * (x * x) * (x * x * (x * x)) *\n        (x * x * (x * x) * (x * x * (x * x))))\n     : A -> A  \n\\end{Coqanswer}\n\nTherefore, we note that the term (\\Verb|fun (x:A) =>x ^b 17|)  is\nconvertible, --- \\emph{thus logically indistinguishable} ---, with a function that performs 16 multiplications.\n\nLikewise, let us simplify the term (\\Verb|fun (x:A) =>x ^ 17|):\n\n\\begin{Coqsrc}\nEval simpl in   fun x =>  x ^ 17.  \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= fun x : A =>\n   x * (x *  (x *  (x *  (x *   (x *  (x *  (x *\n    (x * (x * (x * (x * (x * (x * (x * (x * (x * one)))))\n  )))))))))))  \n\\end{Coqanswer}\n\n\nFrom these tests, we may infer that  representing exponentiation algorithms as \\coq{}  functions hides\ninformation about the real structure of the computations, particularly the sharing on intermediate computations.\n\nThus, we propose to define a data structure that makes explicit the sequence of multiplications that lead to the computation of $x^n$. For instance, the values of  \n\\texttt{x * x} and\n\\texttt{x * x * (x * x)}  are used\ntwice in the  computation of $x^{17}$ with the binary algorithm. This information should \nappear explicitly in the data structure chosen for representing exponentiation \nalgorithms.\n\nIt is well known that local variables can be used to store intermediate results.\nIn an \\texttt{ISWIM} - \\texttt{ML} style, the function computing $x^{17}$ could be written as follows:\n\n\\begin{Coqsrc}\nDefinition pow_17  (x:A) :=\n  let x2 := x * x in\n  let x4 := x2 * x2 in\n  let x8 := x4 * x4 in\n  let x16 := x8 * x8 in\n  x16 * x.\n\\end{Coqsrc}\n\\label{pow-17-let-in}\n\nUnfortunately, \\coq's \\textbf{let-in} construct is useless for our purpose, since $\\zeta$-conversion \nwould make the sharing of computations disappear.\n\n\\begin{Coqsrc}\nEval cbv  zeta beta delta [pow_17]  in  pow_17.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = fun x : A =>\n       x * x * (x * x) * (x * x * (x * x)) *\n       (x * x * (x * x) * (x * x * (x * x))) * x\n     : A -> A \n\\end{Coqanswer}\n                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   \nIn the next section, we propose to use a \\emph{data structure} for representing \nthe computations that lead to the evaluation of some power $x^n$, where\nintermediary results are explicitly named for further use in the rest of the computation.\n\n\n\n\n\\section{Addition chains}\n\\index{maths}{Addition chains}\nAn \\emph{addition chain} (In short : \\emph{a chain})~\\cite{brauer1939} is a representation of a sequence of\nintermediate steps that lead to the evaluation of  $x^n$, under the \nassumption that each of these steps is a computation of  a power $x^i$, with \n$i<n$.\n\nIn articles from the combinatorist  community, \n\\emph{e.g.}~\\cite{brauer1939,DBLP:journals/ipl/BerstelB87},  addition chains \nare represented as sequences of positive integers, each member of which \nis either $1$ or  the sum of two previous elements.\nFor instance, the three following sequences are addition chains for the exponent $87$:\n\n\\begin{align}\nc_{87} &= (1,2,3,6,7,10,20,40,80,87) \\\\\nc'_{87}&=(1,2,3,4,7,8,16,23,32,64,87) \\\\\nc''_{87}&=(1,2,4,8,16,32,64,80,84,86,87)\n\\end{align}\n\nIt is possible to associate to any addition chain a directed acyclic graph:\nwhenever $i=j+k$, there is an arc from $x^j$ to $x^i$ and an arc\nfrom $x^k$ to $x^i$. Figures~\\ref{fig:chain-87-eucl}  and \n\\ref{fig:chain-87-bin} show the graphical representations of \n $c_{87}$  and $c'_{87}$. \nPlease note that some chains may be represented by various different dags.\nFor instance, we can associate four different dags to the chain $(1,2,3,4,6,9,13)$. \n\n\n\\begin{figure}[h]\n  \\centering\n  \n  \\caption{Graphical representation of $c_{87}$ (9 multiplications)}\n  \\label{fig:chain-87-eucl}\n\\begin{tikzpicture}\n\\node (X) at (0,0) {$x$};\n\\node (X2) at (1,0) {$x^2$};\n\\node (X3) at (2,0) {$x^3$};\n\\node (X6) at (3,0) {$x^6$};\n\\node (X7) at (4,0) {$x^7$};\n\\node (X10) at (5.5,0) {$x^{10}$};\n\\node (X20) at (6.5,0) {$x^{20}$};\n\\node (X40) at (7.5,0) {$x^{40}$};\n\\node (X80) at (8.5,0) {$x^{80}$};\n\\node (X87) at (9.5,0) {$x^{87}$};\n\\draw [->, >=latex](X) -- (X2);\n\\draw [->, >=latex](X2) -- (X3);\n\\draw [->, >=latex](X3) -- (X6);\n\\draw [->, >=latex](X6) -- (X7);\n\\draw [->, >=latex](X7) -- (X10);\n\\draw [->, >=latex](X10) -- (X20);\n\\draw [->, >=latex](X20) -- (X40);\n\\draw [->, >=latex](X40) -- (X80);\n\\draw [->, >=latex](X80) -- (X87);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X) to [bend left] (X7);\n\\draw [->, >=latex](X3) to [bend left] (X10);\n\\draw [->, >=latex](X7) to [bend left] (X87);\n\\end{tikzpicture}\n\\end{figure}\n\n\\begin{figure}[h]\n  \\centering\n  \n  \\caption{Graphical representation of $c'_{87}$ (10 multiplications)}\n  \\label{fig:chain-87-bin}\n\\begin{tikzpicture}\n\\node (X) at (0,0) {$x$};\n\\node (X2) at (1,0) {$x^2$};\n\\node (X3) at (2,0) {$x^3$};\n\\node (X4) at (3,0) {$x^4$};\n\\node (X7) at (4.5,0) {$x^7$};\n\\node (X8) at (5.5,0) {$x^8$};\n\\node (X16) at (6.5,0) {$x^{16}$};\n\\node (X23) at (8,0) {$x^{23}$};\n\\node (X32) at (9.5,0) {$x^{32}$};\n\\node (X64) at (10.5,0) {$x^{64}$};\n\\node (X87) at (11.5,0) {$x^{87}$};\n\\draw [->, >=latex](X) -- (X2);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X2) to [bend right] (X4);\n\\draw [->, >=latex](X2) -- (X3);\n\\draw [->, >=latex](X4) -- (X7);\n\\draw [->, >=latex](X3) to [bend left] (X7);\n\\draw [->, >=latex](X4) to [bend right] (X8);\n\\draw [->, >=latex](X7) to [bend left] (X23);\n\\draw [->, >=latex](X8) -- (X16);\n\\draw [->, >=latex](X16) -- (X23);\n\\draw [->, >=latex](X16) to [bend right] (X32);\n\\draw [->, >=latex](X32) -- (X64);\n\\draw [->, >=latex](X64) -- (X87);\n\\draw [->, >=latex](X23) to [bend left] (X87);\n\\end{tikzpicture}\n\\end{figure}\n\n\n\nLet us assume that the efficiency of an exponentiation algorithm is proportional\nto the number of multiplications it requires. This assumption looks reasonable \nwhen the data size is bounded (for instance : machine integers, arithmetic modulo $m$, etc.). \nLet us define the \\emph{length} of a chain $c$ as its number $|c|$ of exponents\n(without counting the initial $1$). \nThis length is the number of multiplications needed for \ncomputing the $x^i$s by applying the following algorithm:\n\n\\begin{quote}\nFor any item $i$ of $c$, there exists $j$ and $k$ in $c$, where\n$i=j+k$, and $x^j$ and $x^k$ are already computed.\n\nThus, compute $x^i = x^j \\times x^k$.\n\\end{quote}\n\nIn our little example, we have \n$|c_{87}| = 9 < 10 = |c'_{87}|$. \nIn the rest of this chapter, we will try to focus on the following aspects:\n\\begin{itemize}\n\\item Define a representation of addition chains that allows to compute\n  efficiently $x^n$ in any monoid, for quite large exponents $n$;\n\\item Certify that our representation of chains is correct, \n    \\emph{i.e.}, determines a computation of $x^n$ for a given $n$;\n\\item Define and certify functions for automatically  generating \n    correct and shortest as possible chains.\n\\end{itemize}\n\nIn a previous work~\\cite{DBLP:journals/ita/BrlekCHM95, DBLP:conf/tapsoft/BrlekCS91,AdditionsContrib},  addition chains were represented so as to allow\nefficient computations of powers and certification of a family of\nautomatic chain generators.\n  We present here a new implementation that takes into account some\nadvances in the way we use \\coq{}: generalized rewriting, type classes,\nparametricity, etc.\n\n\n\\subsection{A type for addition chains}\n\nLet us recall that we want to represent some algorithms of the form\ndescribed in section~\\ref{pow-17-let-in}, but avoiding to represent\nintermediate results by \\textbf{let-in}  constructs.\nWe describe below the main design choices we made:\n\n\\begin{itemize}\n\\item Continuation Passing Style (CPS) \n\\index{coq}{Continuation Passing Style (CPS)} \\cite{reynolds93}\nis a way to make explicit the \n     control in the evaluation of an expression, in a purely functional way. \n    For every intermediate computation step, the result is sent\n    to a \\emph{continuation} that executes the further continuations.\n   When the continuation is a lambda-abstraction, its bound variable \n   gives a \\emph{name} to this result\n\n\n  \n\\item Like in Parametric Higher Order Abstract Syntax (PHOAS)~\\cite{PHOAS}, \\index{coq}{Parametric Higher-Order Abstract Syntax (PHOAS)}\n     the local variables associated to intermediate results are\n     represented by variables of  type $A$, where $A$ is the underlying type\n  of the considered monoid.\n\\end{itemize}\n\n\n\\subsubsection{Definition}\n\\label{computation-def}\nLet  \\texttt{A} be some type;  a \\emph{computation} on \\texttt{A} is \n\\begin{itemize}\n\\item  either a final step, returning some value of type \\texttt{A}\n\\item or the multiplication of two values of type  \\texttt{A}, with a  \\emph{continuation}\n  that takes as argument the result of this multiplication, then starts a new\n  computation.\n\\end{itemize}\n  \n  In the following inductive type definition, the intended meaning \n  of the contruct (\\texttt{Mult $x$ $y$ $k$})  is \\emph{``multiply \\texttt{x} with \n\\texttt{y}, then send  the result of this multiplication to \n  the continuation  \\texttt{k}''}.\n\n\n\nFrom Module~\\href{../theories/html/additions.Addition_Chains.html}{additions.Addition\\_Chains}\n\n\\begin{Coqsrc}\nInductive computation {A:Type}  : Type :=\n| Return (a : A)\n| Mult (x y : A) (k : A -> computation).    \n\\end{Coqsrc}\n\\subsubsection{Monadic notation}\n\n\\index{additions}{Types!computation}\n\nThe following \\emph{monadic} \nnotation makes terms of type \\texttt{computation} look like\nexpressions of a small programming language dedicated to sequences of mutiplications.\nPlease look at \\emph{CPDT}~\\cite{chlipalacpdt2011} for more details on monadic notations in \\coq.\n\\label{monadic-mult}\n\n\\begin{Coqsrc}\nNotation \"z '<---'  x 'times' y ';' e2 \" :=\n  (Mult x y  (fun z => e2))\n    (right associativity, at level 60).\n\\end{Coqsrc}\n\nThe \\texttt{computation} type family is able to express sharing of intermediate computations. For instance, the computation of $2^7$ depicted in Figure~\\ref{fig:dag7} is described by  the following term:\n\n\\begin{Coqsrc}\nExample comp7 : computation  :=\n  x <--- 2 times 2;\n  y <--- x times 2;\n  z <--- y times y ;\n  t <--- 2 times z ;\n  Return t.  \n\\end{Coqsrc}\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (leaf) at (2,0){\\texttt{$2$}};\n  \\node (x2) at (3.5,1){\\texttt{$x$}};\n  \\node (x3) at (3.5,2){\\texttt{$y$}};\n \\node (x6) at (3.5,4){\\texttt{$z$}};\n  \\node  (root) at (2,5.5) {\\texttt{$t$}};\n\\draw [->, >=latex, bend left] (leaf) to  node[midway, left] {\\tiny{$2$}} \n (root);\n  \\draw [->, >=latex,bend left] (leaf) to  node[midway, left] {\\tiny{$2$}}  \n(x2);\n  \\draw [->, >=latex,bend right] (leaf) to  node[midway, right] {\\tiny{$2$}} \n (x2);\n \\draw [->, >=latex,bend left] (leaf) to  node[midway, left] {\\tiny{$2$}} \n (x3);\n\\draw [->, >=latex,bend right] (x2) to  node[midway, right] {\\tiny{$2^2$}} \n (x3);\n\\draw [->, >=latex,bend left] (x3) to  node[midway, left] {\\tiny{$2^3$}} \n (x6);\n\\draw [->, >=latex,bend right] (x3) to  node[midway, right] {\\tiny{$2^3$}} \n (x6);\n\\draw [->, >=latex, bend right] (x6) to  node[midway, right] {\\tiny{$2^6$}} \n (root);\n  \\end{tikzpicture}\n  \\caption{The dag associated to a computation of $2^7$}\n  \\label{fig:dag7}\n\\end{figure}\n\n\\subsubsection{Definition}\n\\label{chain-def}\n\nThanks to the  \\texttt{computation} type family, we can associate a type\nto the kind of computation schemes described in Figures~\\ref{fig:chain-87-eucl} and ~\\ref{fig:chain-87-bin}.\n\nWe define \n \\emph{addition chains} (in short  \\emph{chains}) as functions that map\n any\n type \\texttt{A} and any value \\texttt{a} of type \\texttt{A}  into a computation \non \\texttt{A}:\n\n\\index{additions}{Types!chain@chain (addition chains)}\n\n\\begin{Coqsrc}\nDefinition chain := forall A:Type, A -> @computation A.   \n\\end{Coqsrc}\n\nThus, terms of type \\texttt{chain} describe polymorphic \nexponentiation algorithms. \n\n\nFor instance, Fig~\\vref{fig:C87} shows a definition of the chain  of Figure~\\ref{fig:chain-87-eucl}, for the exponent $87$.\nNote that, like in PHOAS, bound variables associated with the \nintermediary results are \\coq{} variables of type $A$.\n\\begin{figure}[h]\n  \\centering\n  \\begin{Coqsrc}\nExample  C87 : chain :=\n fun A (x : A) =>\n  x2 <--- x times x ;\n  x3 <--- x2 times x ;\n  x6 <--- x3 times x3 ;\n  x7 <--- x6 times x ;\n  x10 <--- x7 times x3 ;\n  x20 <--- x10 times x10 ;\n  x40 <--- x20 times x20 ;\n  x80 <--- x40 times x40 ;  \n  x87 <--- x80 times x7 ;\n  Return x87.\n \\end{Coqsrc}\n  \\caption{A chain for raising x to its $87$-th power}\n  \\label{fig:C87}\n\\end{figure}\n\n\n\nThe structure of the definition of types \\texttt{computation}   and \\texttt{chain} suggest that basic definitions over \\texttt{chain} will have the following structure:\n\\begin{itemize}\n\\item A recursive function on type \\texttt{computation $A$} (for a given\n    type $A$)\n\\item A main function on type \\texttt{chain} that calls the previous one on \nany \\texttt{$A$:Type}.\n\\end{itemize}\n\nFor instance, the following function computes the length of any chain,\n\\emph{i.e.}, the number of multiplications of the associated computation.\nNote that the function \\texttt{chain\\_length} calls the auxiliary function\n\\texttt{computation\\_length}, with the variable \\texttt{A} instantiated to the singleton type  \\texttt{unit}. \n\nAny other type in \\coq{} would have fitted our needs, but \\texttt{unit} and\nits unique inhabitant \\texttt{tt} was the simplest  solution.\n\n\\label{C87-length}\n\\begin{Coqsrc}\nFixpoint computation_length {A} (a:A)(m : @computation A) \n  : nat :=\nmatch m with\n  | Mult _ _ k => S (computation_length a (k a))\n  | _ => 0%nat\nend.\n\nDefinition chain_length (c:chain) \n   := computation_length tt (c _ tt).\n\nCompute chain_length C87.\n\\end{Coqsrc}\n\\begin{Coqanswer}\n = 9 : nat  \n\\end{Coqanswer}\n   \n\n\\subsection{Chains as a (small) programming language}\n\nThe \\texttt{chain} type can be considered as a tiny programming language dedicated to compute powers in any \\texttt{EMonoid}. Thus, we have to define a semantics for this language. This semantics is defined in two parts:\n\\begin{itemize}\n\\item A structurally recursive function,  --- parameterized with an \\texttt{EMonoid} \\texttt{M} on a given type \\texttt{A} ---, that computes the value associated with any computation on \\texttt{M}\n\\item A polymorphic function that takes as arguments  a  chain \\texttt{c},\n a type \\texttt{A},  an \\texttt{EMonoid} on \\texttt{A}, and \n   a value \\texttt{x:A},\n  then executes the computation \\texttt{(c A x)}.\n\\end{itemize}\n\n\n\\begin{Coqsrc}\nFixpoint computation_execute  {A:Type} (op: Mult_op A) \n                              (c : computation) :=\nmatch c with \n| Return x => x \n| Mult x y k => computation_execute op (k (x * y))\nend.\n\nDefinition chain_execute (c:chain) {A} op  (a:A) :=\n  computation_execute op (c A a).\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nDefinition computation_eval `{M:@EMonoid A E_op E_one E_eq}\n           (c : computation) : A := computation_execute E_op c.\n\nDefinition chain_apply (c:chain) \n    {M:@EMonoid A E_op E_one E_eq} a : A :=\n    computation_eval (c A a).\n\\end{Coqsrc}\n\n\\index{additions}{Projects}\n\\begin{project}\nStudy how  to compile efficiently such data structures.\n\n\\end{project}\n\n\n\\subsubsection*{Examples:} \nThe following interactions show how to apply the chain \\texttt{C87} \nfor exponentiation within two different monoids:\n\n\\begin{Coqsrc}\nCompute  chain_apply C87 3%Z.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n =  323257909929174534292273980721360271853387%Z\n     : Z\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_apply C87 (M:=M2N) (Build_M2 1 1 1 0)%N.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n  = {|\n      c00 := 1100087778366101931%N;\n      c01 := 679891637638612258%N;\n      c10 := 679891637638612258%N;\n      c11 := 420196140727489673%N |}\n     : M2 N\n\\end{Coqanswer}\n\n\\index{additions}{Projects}\n\\begin{project}\nDefine a function which returns the sequence of operations defined by a chain.\nFor instance, the chain \\texttt{C87} of Figure \\ref{fig:C87} can be represented as a \nlist containing terms of the form \\texttt{($i$, Add $j$ $k$)} whenever the associated computation contains the operation $x^i=x^j\\times x^k$.\n\n\n\\begin{Coqsrc}\nCompute chain_trace C87.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n(1, Init)\n       :: (2, Add 1 1)\n          :: (3, Add 2 1)\n             :: (6, Add 3 3)\n                :: (7, Add 6 1)\n                   :: (10, Add 7 3)\n                      :: (20, Add 10 10)\n                         :: (40, Add 20 20)\n                            :: (80, Add 40 40) :: (87, Add 80 7) :: nil\n     : list (positive * info)\n\\end{Coqanswer}\n  \n\n\\textbf{Note} A first solution (in ~\\href{../theories/html/additions.Trace_exercise.html}{additions.Trace\\_exercise}) consists in the definition of \na (non-associative) multiplication over a type of trace, and apply the function\n\\texttt{chain\\_execute} as if it were computing a power of \\texttt{(1,Init)}.\n\n\n\\end{project}\n\n\\subsubsection{Chain correctness and optimality}\n\nA chain is said to be \\emph{correct} with respect to a positive\ninteger \\texttt{p} if its execution in any monoid computes $p$-th powers.\n\n\\label{chain-correct-def}\n\\begin{Coqsrc}\nDefinition chain_correct_nat (n:nat) (c: chain) := \n  n <> 0 /\\\n  forall `(M:@EMonoid  A E_op E_one E_eq) (x:A), \n      chain_apply c x ==   x ^ n.\n\nDefinition chain_correct (p:positive) (c: chain) :=\n  chain_correct_nat c (Pos.\nto_nat p). \n\\end{Coqsrc}\n\n\\begin{definition}\nA chain $c$ is \\emph{optimal} for a given exponent $p$ if its length is less \nthan or equal to\nthe length of any chain correct for $p$.  \n\\end{definition}\n\n\n \\begin{Coqsrc}\nDefinition optimal (p:positive) (c : chain) :=\n forall c', chain_correct p c' -> \n            (chain_length c <= chain_length c')%nat.\n \\end{Coqsrc}\n\n\\section{Proving a chain's correctness}\n\\label{chain-correctness-sect}\nIn this section, we present various ways of proving that a given chain is \ncorrect w.r.t. a given exponent. First, we just try to apply \nthe definition in Section~\\vref{chain-correct-def}, but this method is very \ninefficient, even for small exponents. In a second step, we use more sophisticated techniques such as reflection and parametricity. Automatic generation of correct chains will be treated in Sect.~\\vref{chain-generation}.\n\n\\subsection{Proof by rewriting}\nLet us show how to prove  the correctness of some chains, using\nthe \\texttt{EMonoid} laws shown in Sect.~\\vref{EMonoid-def}. \n\n\\begin{Coqsrc}\nLtac slow_chain_correct_tac :=\n  match goal with \n      [ |- chain_correct ?p ?c ] =>\n      let A := fresh \"A\" in\n      let op := fresh \"op\" in\n      let one := fresh \"one\" in\n      let eqv := fresh \"eqv\" in\n      let M := fresh \"M\" in\n      let x := fresh \"x\"\n      in  split;\n        [discriminate | \n         unfold c, chain_apply, computation_eval; simpl;\n         intros A op one eq M x; monoid_simpl M; reflexivity]\n  end.\n\n\nExample C7_ok : chain_correct 7 C7.\nProof.\n   slow_chain_correct_tac.\nQed.\n\\end{Coqsrc}\n\nUnfortunately, this approach is terribly inefficient, even for quite small exponents:\n\n\n\\begin{Coqsrc}\nExample C87_ok : chain_correct 87 C87.\nProof.\n Time  slow_chain_correct_tac. \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n Finished transaction in 62.808 secs (62.677u,0.085s) (successful)   \n \\end{Coqanswer}\n\n\\begin{Coqsrc}\nQed.\n\\end{Coqsrc}\n\nIn addition to this big computation time, this approach \ngenerates a huge proof term. Just try to execute the command \n``\\texttt{Print C87\\_ok}'' to get a measure of its size.\nIn order to understand this poor performance, let us consider an intermediate\nsubgoal of the previous proof generated after a sequence of unfoldings and simplifications. This goal is presented below.\n\n\n\n\\begin{Coqanswer}\n1 subgoal, subgoal 1 (ID 219)\n  \n  A : Type\n  E_op : Mult_op A\n  E_one : A\n  E_eq : Equiv A\n  M : EMonoid E_op E_one E_eq\n  x : A\n  ============================\n   x * x * x * (x * x * x) * x * (x * x * x) *\n   (x * x * x * (x * x * x) * x * (x * x * x)) *\n   (x * x * x * (x * x * x) * x * (x * x * x) *\n    (x * x * x * (x * x * x) * x * (x * x * x))) *\n   (x * x * x * (x * x * x) * x * (x * x * x) *\n    (x * x * x * (x * x * x) * x * (x * x * x)) *\n    (x * x * x * (x * x * x) * x * (x * x * x) *\n     (x * x * x * (x * x * x) * x * (x * x * x)))) *\n   (x * x * x * (x * x * x) * x) ==\n   x *\n   (x *\n    (x *\n     (x *\n      (x *\n       (x *\n        (x *\n         (x *\n          (x *\n           (x *\n            (x *\n             (x *\n              (x *\n               (x * (x * (x * (x * (x * (x * (x * (x * (x * (x * \n                ..))))))))))))))))))))))\n\\end{Coqanswer}\n\\label{fig:big-goal}\n\n\nThis goal is solved by the following tactic composition:\n\n\\begin{Coqsrc}\nmonoid_simpl M; reflexivity. \n\\end{Coqsrc}\n\n\nThis inefficiency certainly comes from the cost of setoid rewriting.\nAt every application of an \\texttt{EMonoid} law, the system must\nverify that the context of this rewriting is compatible  with the equivalence\nrelation associated with the current \\texttt{EMonoid}.\nThe rest of this chapter is devoted to the  presentation of more efficient \n methods for proving chain correctness.\n \n\n\\subsection{Correctness proofs by reflection}\n\\label{reflection-section}\n\\index{coq}{Proofs by reflection}\nInstead of letting the tactic \\texttt{rewrite} look for contexts in which\nsetoid rewriting is possible, we propose to use (deterministic) computations for\nobtaining a ``canonical'' form for terms generated from a variable \\texttt{x}\nby contructors associated with monoid multiplication and neutral element.\n\nThe reader will find general explanations about proofs by reflection in \\coq{},\nfor instance in Chapter 16 of Coq'Art\\cite{BC04} and the numerous examples (including the \\texttt{ring} tactic) \nin \\coq's reference manual.\n\n\n\\subsubsection{How does reflection work}\nLet us consider again the subgoal on page~\\pageref{fig:big-goal}, the conclusion of which has the form \\texttt{|$a_1\\,==\\,a_2$|}, where \\texttt{|$a_1$|} and\n\\texttt{|$a_2$|} are terms of  type \\texttt{A}.\nInstead of spending space and time in setoid rewritings, we would like to\nnormalize the terms \\texttt{|$a_1$|} and \\texttt{|$a_2$|} and verify that \nthe associated normal forms are equal.\n\nDefining such a normalization function is possible on an inductive type.\nThe following type describes expressions composed of monoid operations and inhabitants of a given type $A$.\n\n\\begin{Coqsrc}\n(** Binary trees of multiplications over A *)\n\nInductive Monoid_Exp (A:Type) : Type :=\n Mul_node (t t' : Monoid_Exp A) | One_node | A_node (a:A).\n\nArguments Mul_node {A} _ _.\nArguments One_node {A} .\nArguments A_node {A} _ .\n\\end{Coqsrc}\n\n\n\n\nThus, the main steps of a correctness proof of a given chain, \\emph{e.g.}\n\\texttt{C87} will be the following ones:\n\\begin{enumerate}\n\\item generate a subgoal as in page~\\pageref{fig:big-goal},\n\\item express each term of the equivalence as the image of a term\n     of type \\texttt{Monoid\\_Exp $A$},\n\\item normalize both terms and verify that their normal forms are equal.\n\\end{enumerate}\n\nThe rest of this section is devoted to the definition of the normalization \nfunction on \\texttt{Monoid\\_Exp $A$}, and the proofs of lemmas that\nlink equivalence on type \\texttt{A} and equality of normal forms\nof terms of type \\texttt{Monoid\\_Exp $A$}.\n\n\n\\subsubsection{Linearization function}\n\nThe following functions help to transform any term of type\n\\texttt{Monoid\\_Exp $A$} into a flat ``normal form''.\n\n\\begin{Coqsrc}\n\nFixpoint flatten_aux {A:Type} (t fin : Monoid_Exp A) \n  : Monoid_Exp A :=\nmatch t with Mul_node  t t' =>\n              flatten_aux t (flatten_aux t' fin)\n           | One_node  => fin\n           |  x => Mul_node  x fin\nend.\n\nFixpoint flatten {A:Type} (t: Monoid_Exp A) : Monoid_Exp A :=\nmatch t with\n| Mul_node t t' => flatten_aux t (flatten t')\n| One_node => One_node\n| X => Mul_node X One_node\nend.\n\\end{Coqsrc}\n\n\\subsubsection{Interpretation function}\n\nThe function \\texttt{eval} maps any term of type \\texttt{Monoid\\_Exp $A$}\ninto a term of type \\texttt{$A$}.\n\n\\begin{Coqsrc}\nFunction eval {A:Type} {op one eqv}\n         (M: @EMonoid A op one eqv)\n         (t: Monoid_Exp A) : A :=\n match t with \n            | Mul_node t1 t2 => (eval M t1 * eval M t2)%M\n            | One_node => one\n            | A_node a => a\nend.\n\\end{Coqsrc}\n\nThe following two lemmas relate the linearization function \\texttt{flatten}\nwith the interpretation function \\texttt{eval}.\n\n\\begin{Coqsrc}\nLemma flatten_valid {A} `(M: @EMonoid A op one eqv):\nforall t , eval M t == eval M (flatten t).\n(* Proof omitted *) \n\nLemma flatten_valid_2 {A} `(M: @EMonoid A op one eqv):\nforall t t' , eval  M (flatten t) == eval M (flatten t')  ->\n     eval M t == eval M t'.\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\\subsubsection{Transforming a multiplication into a tree}\nLet us now build a tool for building terms of type  \\texttt{Monoid\\_Exp $A$} out\nof terms of type \\texttt{A} containing multiplications of the form \n\\Verb|(_ * _)%M| and the variable \\texttt{one}. \nIn fact, what we want to  define is an inverse of the function \\texttt{flatten}.\n\nSince \\texttt{mult\\_op} is not a constructor (see Sect.~\\ref{op-classes}), \nthe transformation of  \na product of type \\texttt{A} into a term of type \\texttt{Monoid\\_Exp A}\nis done with the help of a tactic:\n\n\n\n\\begin{Coqsrc}\n(** \"Quote\" tactic *)\n\nLtac model A  op one v :=\nmatch v with \n| (?x  * ?y)%M => let r1 := model A op one x\n                  with r2 := model A op one y \n                  in  constr:(@Mul_node A r1 r2)\n| one => constr:(@One_node A)\n| ?x => constr:(@A_node A x)\nend.\n\\end{Coqsrc}\n\n\nFor instance, the term \\texttt{(x * x * x * (x * x * x) * x)} is\ntransformed by \\texttt{model} in the following term of type \\texttt{Monoid\\_Exp $A$}\n\n\\begin{Coqsrc}\n(eval M\n   (Mul_node\n     (Mul_node \n        (Mul_node (Mul_node (A_node x) (A_node x)) (A_node x))\n        (Mul_node (Mul_node (A_node x) (A_node x)) (A_node x))) \n     (A_node x)))  \n\\end{Coqsrc}\n\n\n\\subsection{Reflection tactic}\nThe tactic \\texttt{monoid\\_eq\\_A} converts a goal of the form \n(\\texttt{E\\_eq $X$ $Y$}), where\n\\texttt{$X$} and \\texttt{$Y$} are terms of type $A$, into\n(\\texttt{E\\_eq (eval M  (model X)) (eval M  (model Y))}). This last goal is intended to be solved thanks \nto the lemma \\texttt{flatten\\_valid\\_2}.\n\n\\begin{Coqsrc}\nLtac monoid_eq_A A op one E_eq M  :=\nmatch goal with \n| [ |- E_eq  ?X ?Y ] =>\n  let tX := model A op one X with\n      tY := model A op one Y in\n      (change (E_eq (eval M tX) (eval M tY)))\nend.\n\\end{Coqsrc}\n\n\\subsubsection{Main reflection tactic}\n\nThe tactic \\texttt{reflection\\_correct\\_tac} tries to prove a chain's \ncorrectness by a comparison of two terms of type \\texttt{Monoid\\_Exp $A$}:\none being obtained from the chain's definition, the other one by expansion\nof the naive exponentiation definition.\n\n\n\\begin{Coqsrc}\nLtac reflection_correct_tac :=\nmatch goal with\n[ |- chain_correct ?n ?c ] =>\n split; [try discriminate |\n         let A := fresh \"A\"\n         in let op := fresh \"op\"\n         in let one := fresh \"one\" \n         in let E_eq := fresh \"eq\" \n         in let M := fresh \"M\"\n         in let x := fresh \"x\" \n         in  (try unfold c); unfold chain_apply;\n           simpl; red; intros  A op one E_eq M x;\n           unfold computation_eval;simpl;\n           monoid_eq_A A op one E_eq M;\n           apply flatten_valid_2;try reflexivity\n        ]\nend. \n\\end{Coqsrc}\n \n\\subsubsection{Example}\nThe following dialogue clearly shows the efficiency gain over naive setoid rewriting.\n\n\\begin{Coqsrc}\nExample C87_ok : chain_correct 87 C87.\nProof.\n  Time reflection_correct_tac.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n Finished transaction in 0.038 secs (0.038u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nQed. \n\\end{Coqsrc}\n\nThis tactic is not adapted to much bigger exponents. In \\linebreak\n Module~\\href{../theories/html/additions.Euclidean_Chains.html}{Euclidean\\_Chains},\n for instance, we tried to apply this tactic for proving the correctness \nof a chain associated with the exponent $45319$. \n We had to interrupt the prover, which \nwas trying to build a linear tree of $2\\times  45319 + 1$ nodes!\nIndeed, using \\texttt{reflection\\_correct\\_tac} is like doing a \nsymbolic evaluation of an inefficient (linear) exponentiation algorithm.\n\nIn the next section, we present a solution that avoids doing such a lot of computations.\n\n\\subsection{Chain correctness for ---practically --- free!}\n\\label{correctness-for-free}\n\n% Let us consider again the chain \\texttt{C87} of Fig.~\\vref{fig:C87}.\n% Every bound variable of type \\texttt{A} is either the argument \\texttt{x}\n% or a variable introduced by the abstraction corresponding to the\n% continuation argument of constructor \\texttt{Mult} (hidden by the monadic notation). Thus, it seems obvious that during the execution of some  computation\n% \\texttt{C87 A a}, each of this variable will be bound to some power of \n% \\texttt{a}. \n\n% Thus, we would like to prove that  every chain \\texttt{c} has this property,\n% which would be a great step for proving any chains's correctness.\n\n\n\n\\subsubsection{About parametricity}\n\\index{coq}{Parametricity}\nLet us now present another tactic for proving chain correctness,\nin the tradition of works on \\emph{parametricity} and its use for \nproving properties on programs.\nStrachey~\\cite{Strachey:2000:FCP:609150.609208}\nexplores the nature of \\emph{parametric\npolymorphism}: ``\\emph{Polymorphic functions behave uniformly for all types}''\nthen Reynolds~\\cite{REYNOLDS83} formalizes this notion through binary relations.\nWadler~\\cite{Wadler1989}, then Cohen \\emph{et al.}~\\cite{Cohen2013}\nuse this relation for deriving\n theorems about functions that operate on parametric\npolymorphic types.\n\nLet us look again at the definitions of type family \\texttt{computation}\nand the type \\texttt{chain}:\n\n\\begin{Coqsrc}\nInductive computation {A:Type}  : Type :=\n| Return (a : A)\n| Mult (x y : A) (k : A -> computation).\n\nDefinition chain := forall A:Type, A -> @computation A.\n\\end{Coqsrc}\n\nLet $c$ be a closed term of type \n\\texttt{chain}; $c$ is  of the form \\linebreak\n\\texttt{fun (A:Type)(a:A) => $t_a$}, where $t_a$ is a term of type\n\\texttt{@computation A}.\n\\label{obvious-remark}\nObviously,  in every subterm of {$t_a$} of type \\texttt{A}, \nthe two first arguments of constructor \\texttt{Mult} or the\nargument of \\texttt{Return} are either \\texttt{a} or a variable \nintroduced as the formal argument of a continuation \\texttt{k}.\nIn effect, there is no other way to build terms of type \\texttt{A} in the considered context.\n\n\\index{coq}{Plug-ins!paramcoq}\n\nMarc Lasson's \\textbf{paramcoq} plug-in~(available as  \\texttt{opam} package \n\\texttt{coq-paramcoq}) generates  a family of binary relations definitions\nfrom \\texttt{computation}'s definition.\n\n\\begin{Coqanswer}\nInductive\ncomputation_R (A B : Type) (R : A -> B -> Type)\n  : computation -> computation -> Type :=\n |    computation_R_Return_R : \n       forall (a1 : A) (a2 : B),  R a1 a2 ->\n         computation_R A B R (Return a1) (Return a2)\n  | computation_R_Mult_R : forall (x1 : A) (x2 : B),\n         R x1 x2 ->\n          forall (y1 : A) (y2 : B),\n            R y1 y2 ->\n            forall (k1 : A -> computation)\n                   (k2 : B -> computation),\n                      (forall (H : A) (H0 : B),\n                          R H H0 -> \n                          computation_R A B R (k1 H) (k2 H0)) ->\n                       computation_R A  B R \n                          (z <--- x1 times y1; k1 z)\n                          (z <--- x2 times y2; k2 z)\n\\end{Coqanswer}\n\n\nLet $A$ and $B$  be two types, and $R: A \\arrow B \\arrow \\typesort$ \na relation.\nTwo computations \\texttt{cA: @computation A} and \\texttt{cB: @computation B}\nare related \\emph{w.r.t.} \\texttt{computation\\_R} if every pair of \narguments of \\texttt{Mult} and \\texttt{Return} at the same position \nare related \\emph{w.r.t.} \\texttt{R}.\n\n\n\\subsubsection{Definition}\nA chain $c$ is \\emph{parametric} if it has the same behaviour for any\npair of types $A$  and $B$, any relation $R$\nbetween  $A$ and $B$ and any $R$-related pair of \narguments $a$ and $b$:\n\n\\begin{Coqsrc}\nDefinition parametric (c:chain) :=\n  forall A B (R: A -> B -> Type) (a:A) (b:B),\n   R a b -> computation_R  R (c A a) (c B b).\n\\end{Coqsrc}\n\n\\subsubsection{How to use these definitions?}\nLet us use parametricity for proving easily \na given chain's correctness.\nIn other words, \nlet $c$ be a chain and \\texttt{$p$:positive} be a given exponent.\nConsider some instance of \\texttt{EMonoid} over a type $A$.\nWe want to prove that the application of the chain $c$ to \nany value $a$ of type $A$ returns the value \\texttt{$a^p$}.\n\nWe first use \\coq's computation facilities for ``guessing'' the exponent associated with any given chain. It suffices to instantiate ``monoid multiplication'' with addition on positive integers.\n\n\n\\begin{Coqsrc}\nDefinition the_exponent_nat (c:chain) : nat :=\n chain_apply c (M:=Natplus) 1%nat.\n\nDefinition the_exponent (c:chain) : positive :=\n  chain_execute c Pos.add  1%positive.\n\nCompute the_exponent C87.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 87%positive\n     : positive  \n\\end{Coqanswer}\n\nWe show how to \\emph{prove} that  a given  chain $c$,\napplied to any $a$, really computes $a^p$, where $p=\\textrm{the\\_exponent}\\;c$.\nParametricity allows us to compare executions on any monoid $M$ \nwith executions on \\texttt{NatPlus}.\nLet us consider the following mathematical relation \n$$\\{(x,n)\\in M\\times\\mathbb{N}\\,|\\, 0<n \\wedge x=a^n\\}$$\n\n\\begin{Coqsrc}\nDefinition power_R  (a:A) :=\n  fun (x:A)(n:nat) => n <> 0 /\\ x == a ^ n.  \n\\end{Coqsrc}\n\nFirst, we prove the following lemma, that relates \\texttt{computation\\_R}\nwith the result  of the  executions of the corresponding computations:\n\n\\begin{Coqsrc}\nLemma  power_R_is_a_refinemnt (a:A) :\n  forall(gamma : @computation A)\n        (gamma_nat : @computation nat),\n    computation_R  (power_R a) gamma gamma_nat -> \n     power_R a (computation_eval gamma)\n               (computation_eval (M:= Natplus) gamma_nat).    \n(* Proof omitted *)\n\\end{Coqsrc}\n\n\n\nThus, if \\texttt{$c$:chain} is parametric, this refinement lemma allows us\nto prove a correctness result:\n\n\\begin{Coqsrc}\nLemma param_correctness_nat :\n forall c:chain, parametric c ->  \n               chain_correct_nat (the_exponent_nat c)  c.\n(* Proof omitted *)\n\\end{Coqsrc}\n\nA similar result can be proven with the exponent in \\texttt{positive}.\nFirst we instantiate the parameter \\texttt{R} of \\texttt{computation\\_R},\nwith the relation that links the representations of natural numbers\non respective types \\texttt{nat} and \\texttt{positive}.\nThen we use our lemmas for rewriting under the assumption that the\nconsidered chain is parametric. Please note how our approach is related with\n\\emph{data refinement} (see also~\\cite{Cohen2013}).\nThe reader may also consult a survey by D. Brown on the most important contributions to \nthe notion of parametricity~\\cite{DanBrown-survey}.\n\n\n\n\\begin{Coqsrc}\nLemma exponent_pos2nat : forall c: chain,  parametric c -> \n  the_exponent_nat c = Pos.to_nat (the_exponent c).\n\nLemma exponent_pos_of_nat : forall c: chain,  parametric c -> \n  the_exponent c = Pos.of_nat (the_exponent_nat c).\n\nLemma param_correctness (c:chain) :\n   parametric c -> \n   chain_correct (the_exponent c) c. \nProof.\n  intros; rewrite  exponent_pos_of_nat; auto.\n  red;  rewrite  exponent_pos2nat;auto.\n  rewrite Pos2Nat.id,  <- exponent_pos2nat;auto.\n  apply param_correctness_nat; auto.\nQed.\n\\end{Coqsrc}\n\nLemma \\texttt{param\\_correctness} suggests us a method for verifying \nthat a given chain $c$ is correct \\emph{w.r.t.} some positive exponent $p$:\n\n\\begin{enumerate}\n\\item Verify that $c$ is parametric.\n\\item Verify that $p$ is equal to (\\texttt{the\\_exponent $c$}).\n\\end{enumerate}\n\n\\subsubsection{How to prove a chain's parametricity}\nDespite the apparent complexity of \\texttt{computation\\_R}'s definition,\nit is very simple to prove that a given chain is parametric. The following tactics\nproceed as follows:\n\n\\begin{enumerate}\n\\item Given a chain $c$, consider two types \\texttt{A} and\n\\texttt{B}, and any relation \\texttt{R:A->B->Prop}, \n\\item Push into the context declarations of \\texttt{a:A}, \\texttt{b:B}\nand an hypothesis assuming \\texttt{R a b}.\n\\item Then the tactic crosses in parallel the terms (\\texttt{c A a}) and\n(\\texttt{c B b}) (of the same structure),\n\\begin{itemize}\n\\item On a pair of terms of the form \n\\texttt{Mult xA yA (fun zA => tA)} and \\linebreak \\texttt{Mult xB yB (fun zB => tB)}, the tactic checks whether \n   \\texttt{R xA xB} and \\texttt{R yA yB} are already assumed in the context,\n then  pushes into the context the declaration of \\texttt{zA} and \\texttt{zB}\nand the hypothesis \\linebreak \\texttt{Hz: R zA zB}, then crosses the terms \\texttt{tA} and\n \\texttt{tB}\n\\item On a pair of terms  of the form   (\\texttt{Return xA}) and (\\texttt{Return xB}),\n the tactic just checks whether (\\texttt{R xA xB}) is assumed.\n\\end{itemize}\n\n\\end{enumerate}\n\nThe tactic itself is simpler than its explanation. \n\n\\begin{Coqsrc}\nLtac parametric_tac  := \nmatch goal with [ |- parametric ?c] =>\n   red ; intros;\n   repeat (right;[assumption | assumption | ]);  \n   left; assumption\nend.\n\nExample P87 : parametric C87.\nProof. Time parametric_tac. \n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nFinished transaction in 0.005 secs (0.005u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nQed. \n\\end{Coqsrc}\n\n\n\n\\subsubsection{Proving a chain's correctness}\n\\label{C87-param-ok}\nFinally, for proving that a given chain $c$ is correct with respect to an exponent $p$, it suffices to check that $c$ is parametric, and\nto apply the lemma \\texttt{param\\_correctness}. \nThe reader will note how this computation-less method is much more efficient\nthan our reflection tactic.\n\n\\begin{Coqsrc}\nLtac param_chain_correct :=\nmatch goal with \n[|- chain_correct ?p ?c ] => \napply param_correctness; parametric_tac\nend.\n\nLemma C87_ok' : chain_correct 87 C87.\nTime param_chain_correct.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\nFinished transaction in 0.005 secs (0.005u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{Remark}\nFor the reasons exposed in Section~\\vref{obvious-remark}, \nit seems obvious that any well-written chain is parametric.\nUnfortunately, we cannot prove this property  in \\coq{},\nfor instance by induction on \\texttt{c}, \nsince \\texttt{chain} is a product type and not an inductive type.\n\n \n\\begin{Coqbad}\nDefinition any_chain_parametric : Type :=\n forall c:chain, parametric c.\n\nGoal any_chain_parametric.\nProof.\nintros c A B R a b ; induction c.\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n 2 subgoals, subgoal 1 (ID 556)\n  \n  c : chain\n  A : Type\n  B : Type\n  R : A -> B -> Type\n  a : A\n  b : B\n  a0 : A\n  ============================\n   R a b -> computation_R R (Return a0) (c B b)\n\n...\n\\end{Coqanswer}\n\n\n\\begin{Coqbad}\nAbort.\n\\end{Coqbad}\n\n\nGiven this situation, we could  admit (as an axiom) that \nany chain is parametric. Nevertheless, if a chain is under the form of a \nclosed term, using \\texttt{parametric\\_tac} is so efficient than we prefer to \n avoid\na shameful introduction of an axiom in our development.\n\n\\section{Certified chain generators}\n\\label{chain-generation}\n\nIn this section, we are interested in the \\emph{correct by construction} paradigm.\nWe just want to give a positive exponent to \\coq{} and get a (hopefully)  correct and  efficient chain for this exponent.\n\nWe first define the notion of \\emph{chain generator}, then present a certified generator that simulates the binary exponentiation algorithm. Last, we present a better chain generator based on integer division.\n\n\n\\subsection{Definitions}\n\nWe call \\emph{chain generator} any function that takes as argument \nany positive integer and returns a chain. \n\n\\begin{Coqsrc}\nDefinition chain_generator := positive -> chain.  \n\\end{Coqsrc}\n\nA generator $g$  is \\emph{correct} it it returns a correct chain\nfor any exponent:\n\n\\begin{Coqsrc}\nDefinition correct_generator (g : positive -> chain) :=\n forall p, chain_correct (g p) p.\n\\end{Coqsrc}\n\n\nCorrect generators can be used for computing powers \non the fly, thanks to the following functions:\n\n\\begin{Coqsrc}\nDefinition cpower_pos (g : chain_generator)  p\n           `{M:@EMonoid A E_op E_one E_eq} a :=\n  chain_apply (g p) (M:=M) a.\n\n\nDefinition cpower (g : chain_generator)  n\n           `{M:@EMonoid A E_op E_one E_eq} a :=\n  match n with 0%N => E_one \n             | Npos p => cpower_pos  g p a\n  end.  \n\\end{Coqsrc}\n\nNote also that the use of chain generators is independent from  the techniques presented in Sect.~\\ref{chain-correctness-sect}:\nDesigning an efficient and correct chain generator may be a long and hard task.\nOn the other hand, once a generator is certified, we are assured of the correctness of  \nall its outputs.\nFinally, we say that a generator $g$ is \\emph{optimal} if it returns chains whose length are less than or\nequal to any chain returned by any correct generator:\n\n\\begin{Coqsrc}\n\nDefinition optimal_generator (g : positive -> chain) :=\n forall p:positive, optimal p (g p).\n\\end{Coqsrc}\n\n\n\\subsection{The binary chain generator}\n\nLet us reinterpret the  binary exponentiation algorithms in the framework \nof addition chains.\nInstead of directly computing $x^n$ for some base $x$ and exponent $n$,\nwe build chains that describe the computations associated with the binary exponentiation method.\nNot surprisingly, this chain generation will be described in terms of recursive\nfunctions, once the underlying monoid is fixed.\n\nAs for the ``classical'' binary exponentiation algorithm,\nwe define an auxiliary computation generator for  the\nproduct of an accumulator $a$ with an arbitrary power of some value $x$.\nThen, the main function builds a computation for any positive exponent:\n\n\\begin{Coqsrc}\nFixpoint axp_scheme  {A} p : A -> A -> @computation A   :=\n match p with\n   | xH =>  (fun a x => y <--- a  times x ; Return y)\n   | xO q => (fun a x => x2 <--- x times  x ; axp_scheme q a x2)\n   | xI q => (fun a x => ax <--- a times x ;\n                         x2 <--- x times x ;\n                         axp_scheme q ax x2)\nend.  \n\nFixpoint  bin_pow_scheme {A} (p:positive)  \n: A -> @computation A:=\n  match p with \n  |  xH => fun x => Return x\n  | xI q  => fun x => x2 <--- x times x; axp_scheme q x x2\n  | xO q => fun x => x2 <--- x times x ; bin_pow_scheme q x2\n  end.\n\n\\end{Coqsrc}\n\nThe following function associates  a chain to any positive exponent:\n\n\\begin{Coqsrc}\nDefinition binary_chain (p:positive) : chain :=\n  fun A => bin_pow_scheme p.\n\nCompute binary_chain 87.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = fun (A : Type) (x : A) =>\n       x0 <--- x times x;\n       x1 <--- x times x0;\n       x2 <--- x0 times x0;\n       x3 <--- x1 times x2;\n       x4 <--- x2 times x2;\n       x5 <--- x4 times x4;\n       x6 <--- x3 times x5;\n       x7 <--- x5 times x5;\n       x8 <--- x7 times x7; \n       x9 <--- x6 times x8; \n       Return x9\n     : chain\n\\end{Coqanswer}\n\n\n\\subsubsection{Proof of \\texttt{binary\\_chain}'s correctness}\n\nLet us now prove that \\texttt{binary\\_chain} always returns correct chains.\nFirst, due to the structure of this generator's definition, we study the\nproperties of the auxiliary functions that operate \\emph{on a given monoid $M$}.\n\n\\begin{Coqsrc}\nSection binary_power_proof.\n\nVariables (A: Type)\n         (E_op : Mult_op A)\n         (E_one : A)\n         (E_eq: Equiv A).\n\nContext (M : EMonoid  E_op E_one E_eq).\n\nExisting Instance Eop_proper.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma axp_correct : forall p a x,\n computation_eval (axp_scheme p a x) == a *  x ^ (Pos.to_nat p).\n(*  Proof by induction on p *)\n\nLemma binary_correct : \n  forall p x,\n        computation_eval  (bin_pow_scheme p (A:=A) x) ==\n        x ^ (Pos.to_nat p).\n(* Proof by induction on p *)\n \nEnd  binary_power_proof.\n\\end{Coqsrc}\n\n\n\\begin{Coqsrc}\nLemma binary_generator_correct : correct_generator binary_chain.\nProof.\n  red;unfold chain_correct,  binary_chain, chain_apply;\n  split; [auto| intros A op one Eq M x; apply binary_correct].\nQed.\n\\end{Coqsrc}\n\n\n\\subsubsection{The binary method is not optimal}\n\nIt is easy to prove by contradiction  that the binary method is not the most efficient \nfor computing powers. \n    First, let us  assume that \\texttt{binary\\_chain} is optimal:\n\n\\begin{Coqsrc}\nSection non_optimality_proof.\n\n Hypothesis binary_opt : optimal binary_chain.\n\\end{Coqsrc}\n\nThen, let us consider for instance the binary chain generated for the exponent 87.\n\n\\begin{Coqsrc}\nCompute chain_length (binary_chain 87).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n   = 10 : nat \n\\end{Coqanswer}\n  \n\nLet us recall that \\texttt{C87}'s length has been evaluated to $9$ (Sect~\\ref{C87-length},\nand that this chain is correct (Sect~\\vref{C87-param-ok}). Thus, it is very easy\nto finish our proof:\n\n\\begin{Coqsrc}\nLemma binary_generator_not_optimal : False.\nProof.\n  generalize (binary_opt gen _  _ C87_ok); \n  compute; omega.\nQed. \n\nEnd non_optimality_proof.\n\\end{Coqsrc}\n\n\\index{additions}{Exercises}\n\\begin{exercise}\nProve that for any positive integer $p$,  the length of any optimal chain \nfor $p$ is less  than twice the number of digits of the binary representation of $p$.\n\\end{exercise}\n\n\n\n\n\n\n\n\\section{Euclidean Chains}\n\\label{euclide-sect}\n\\index{maths}{Euclidean addition chains}\nIn this section, we present an efficient chain generator. The chains built by this generator\nare never longer than the chains built by the binary generator. Moreover, for an \ninfinite number of exponents, the chains it builds are strictly shorter than the chain\nreturned by \\texttt{binary\\_chain}. \nEuclidean chains are based on the following idea: \n\\begin{quote}\nFor generating a chain that computes $x^n$, one may choose some natural number\n$0<p<n$, and build a chain that computes first $x^p$ \\textbf{then} uses this value\nfor computing $x^n$. \n\\end{quote}\n\nFor instance, a  computation of $x^{42}$ can be decomposed into a computation \nof $y=x^3$, then a computation of $y^{14}$. The efficiency of the chain built with this\nmethods depends heavily on the choice of $p$. See~\\cite{DBLP:journals/ita/BrlekCHM95} for details.\n\nConsidering chain generators and their correctness, we may consider the dual of \ndecomposition of exponents: we would like to write \\emph{composable} correct \nchain generators. For instance, we want to build some object that, ``composed''  \nwith any correct chain for $n$, returns a correct chain for $3n$.\n\n\\paragraph{Note:}\nAll the \\coq{} material described in this section is available on \n Module~\\href{../theories/html/additions.Euclidean_Chains.html}{additions/Euclidean\\_Chains.v}\n\n\\subsection{Chains and continuations : f-chains}\n\n\nPlease consider the following small example:\n\n\\begin{Coqsrc}\nExample C3 : chain :=\n fun A (x:A) =>\n  x2 <--- x times x;\n  x3 <--- x2 times x ;\n  Return x3.\n\\end{Coqsrc}\n\nThe execution of this chain on  some value $x:A$ stops after \ncomputing \\texttt{$x^3$}, because of the \\texttt{Return} ``statement''.\nHowever, we would like to compose the instructions of \\texttt{C3} \nwith a chain for another exponent $n$, in order to generate a chain for \nthe exponent $3\\times n$.\n\n  The solution we present is based on functional programming and the concept of continuation.\n\n\n\n\\subsubsection{Type definition of  f-chains}\n\nLet us   consider \\emph{incomplete} or \\emph{open} chains.\nSuch an object waits for another chain to resume  a computation.\n\nFigure~\\ref{fig:F3-as-dag} represents an  f-chain associated with the exponent $3$, as a dag with an input and one output the edges of which are depicted as thick arrows.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (0,0) {};\n  \\node (X) at (1,0) {$x$};\n\\node (X2) at (2,0) {$x^2$};\n  \\node (X3) at (3,0) {$x^3$};\n\\node (sortie) at (4,0) {};\n\\draw [>-,   thick](entree) -- (X);\n\\draw [->, >=latex, ](X) -- (X2);\n\\draw [->, >=latex, ](X2) -- (X3);\n\\draw [->, >=latex,  thick](X3) -- (sortie);\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw[dashed] (0.5,-0.3) rectangle (3.5,0.6);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{F3}}\n  \\label{fig:F3-as-dag}\n\\end{figure}\n\nIn other words, this kind of objects can be considered as \\emph{functions}\nfrom chains to chains. So, we called their type \\texttt{Fchain}.\n\n\n\nFirst, we define a type of \\emph{continuations},\n\\emph{i.e.},  functions  that wait for some value $x$, then \nbuild  a computation for raising {$x$} to some  given exponent.\n\n\\begin{Coqsrc}\nDefinition Fkont (A:Type) := A -> @computation A.\n\\end{Coqsrc}\n\nAn \\texttt{f-chain} is just a polymorphic function that combines  a \ncontinuation and en element into a computation:\n\n\\begin{Coqsrc}\nDefinition Fchain := forall A, Fkont A -> A -> @computation A.\n\\end{Coqsrc}\n\n\n\\subsubsection{Examples}\n\nLet us define a chain for computing the cube of some $x$, then sending \nthe result to a continuation $k$.\n\n\\begin{Coqsrc}\nDefinition F3 : Fchain := \n fun  A k  (x:A) =>\n  y <--- x times x ;\n  z <--- y times x ;\n  k  z.\n\\end{Coqsrc}\n\n\nAny f-chain can be converted into a chain by the help of the following function:\n\n\\begin{Coqsrc}\nDefinition F2C (f : Fchain) : chain :=\n fun (A:Type) => f A Return.\n\nCompute the_exponent (F2C F3).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 3%nat  \n\\end{Coqanswer}\n\n\nIn the rest of this chapter, we will use two other f-chains, respectively associated with the exponents $1$ and $2$. Chains \\texttt{F1}, \\texttt{F2} and\n\\texttt{F3} will form a basis to generate  chains for many exponents\nby \\emph{composition of correct functions}.\n\n\\begin{Coqsrc}\nDefinition F1 : Fchain := \n fun A k (x:A) => k x.\n\nDefinition F2 : Fchain := \nfun  A k  (x:A) =>\n  y <--- x times x ;\n  k  y.\n\\end{Coqsrc}\n\n\n\\subsubsection{F-chain application and composition}\n\nThe following definition allows us to consider any value {$f$} \nof type \n\\texttt{Fchain} as a function of type \\texttt{chain $\\arrow$ chain}.\n\n\n\\begin{Coqsrc}\nDefinition Fapply (f : Fchain) (c: chain) : chain  :=\n fun A  x =>  f  A (fun y => c A  y) x.\n\\end{Coqsrc}\n\nIn a similar way, \\emph{composition} of \\texttt{f-chain}s is easily defined\n(see Figure~\\vref{fig:Fcompose}).\n\n\n\\begin{Coqsrc}\nDefinition Fcompose (f1 f2: Fchain) : Fchain  :=\n fun   A k x =>  f1  A (fun y => f2 A k y) x.\n\nLemma F1_neutral_l : forall f, Fcompose F1 f = f.\nProof. reflexivity. Qed.\n\nLemma F1_neutral_r : forall f, Fcompose f F1 = f.\nProof. reflexivity. Qed.\n\\end{Coqsrc}\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n \\node (input1)  at (0,0) {};  \n \\node [draw] (F1)  at (1,0) {$f_1$};  \n \\node (output1)  at (2.0,0) {};  \n \\node (input2)  at (2.6,0) {};  \n \\node [draw] (F2)  at (3.5,0) {$f_2$};  \n \\node (output2)  at (4.5,0) {};  \n \\draw [>-,   thick](input1) -- (F1);\n \\draw [->, >=latex, thick](F1) -- (output1);\n\\draw [dotted, ](output1) -- (input2);\n\\draw [>-,   thick](input2) -- (F2);\n\\draw [->, >=latex, thick](F2) -- (output2);\n\\draw[dashed] (0.4,-1) rectangle (4,1);\n  \\end{tikzpicture}\n  \\caption{Composition  of f-chains $f_1$ and $f_2$ (\\texttt{Fcompose})}\n  \\label{fig:Fcompose}\n\\end{figure}\n\\subsubsection{Examples}\n\nThe following examples show that the apparent complexity of the previous \ndefinition is counterbalanced with the simplicity of using \\texttt{Fapply}\nand \\texttt{Fcompose}.\n\n\\begin{Coqsrc}\nExample F9 := Fcompose F3 F3.\n\nCompute F9.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= fun (A : Type) (x : Fkont A) (x0 : A) =>\n       x1 <--- x0 times x0;\n       x2 <--- x1 times x0; x3 <--- x2 times x2; \n       x4 <--- x3 times x2; \n       x x4\n     : Fchain  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nRemark F9_correct :chain_correct 9 (F2C F9).\nProof.\n  apply param_correctness_pos;  lazy;  parametric_tac.\nQed.\n\\end{Coqsrc}\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n\n \\node (inputx)  at (-0.2,0) {};  \n\\node (x)  at (1,0) {$x$};  \n \\node (x2)  at (2,0) {$x^2$};  \n \\node (x3)  at (3,0) {$x^3$};\n \\node (output1)  at (4,0) {};  \n \\node (inputy)  at (5.5,0) {};  \n\\node (y)  at (6.5,0) {$y$};  \n \\node (y2)  at (7.5,0) {$y^2$};  \n \\node (y3)  at (8.5,0) {$y^3$};\n \\node (output2)  at (9.6,0) {};  \n \\draw [>-,   thick](inputx) -- (x);\n \\draw [->,   >=latex](x) -- (x2);\n\\draw [->,   >=latex](x2) -- (x3);\n\\draw [->, >=latex](x) to [bend left] (x3);\n\\draw [->, >=latex, thick](x3) -- (output1);\n\\draw [->, dotted ](output1) -- (inputy) node [midway, above] {\\tiny{$y:=x$}};\n\\draw [>-,   thick](inputy) -- (y);\n \\draw [->,   >=latex](y) -- (y2);\n\\draw [->,   >=latex](y2) -- (y3);\n\\draw [->, >=latex](y) to [bend left] (y3);\n\\draw [->, >=latex, thick](y3) -- (output2);\n\\draw[dashed] (0.4,-1) rectangle (3.5,1);\n\\draw[dashed] (6,-1) rectangle (9,1);\n\\draw[dashed] (0.2,-1.2) rectangle (9.2,1.2);\n  \\end{tikzpicture}\n  \\caption{Composition  of F-chains: F9}\n  \\label{fig:F9}\n\\end{figure}\n\nUsing structural recursion and the operator \\texttt{FCompose},\nwe build a chain for any exponent of the form $2^n$:\n\n\\begin{Coqsrc}\n Fixpoint  Fexp2_of_nat (n:nat) : Fchain :=\n match n with O => F1\n            | S p => Fcompose F2 (Fexp2_of_nat p)\n end.\n\n\nDefinition Fexp2 (p:positive) : Fchain :=\n  Fexp2_of_nat (Pos.to_nat p). \n\nCompute Fexp2  4.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = fun (A : Type) (x : Fkont A) (x0 : A) =>\n       x1 <--- x0 times x0;\n       x2 <--- x1 times x1; x3 <--- x2 times x2; \n       x4 <--- x3 times x3; x x4\n     : Fchain\n\\end{Coqanswer}\n%%% ICI\n\n\\subsection{F-chain correctness}\nLet \\texttt{f} be some term of type \\texttt{Fchain}, and \\texttt{n:nat}.\nWe would like to say that \\texttt{f} is correct \\emph{w.r.t.} \\texttt{n:nat}\nif for any continuation \\texttt{k} and \\texttt{a}, the application of \n\\texttt{f} to \\texttt{k} and \\texttt{a} computes \\texttt{$k(a^n)$}.\n\n\\begin{Coqbad}\nModule Bad.\n\nDefinition Fchain_correct  (n:nat) (f : Fchain) :=\n  forall A `(M : @EMonoid A op E_one E_equiv) k (a:A),\n    computation_execute op (f A k  a)==\n    computation_execute op (k  (a ^ n)).\n\\end{Coqbad}\n\nLet us now try to prove that \\texttt{F3} is correct \\emph{w.r.t.} $3$.\n\n\\begin{Coqbad}\nTheorem F3_correct : Fchain_correct 3 F3.\nProof.  \n  intros    A op E_one E_equiv M k  a ; simpl.\n  monoid_simpl M.  \n\\end{Coqbad}\n\n\\begin{Coqanswer}\n  A : Type\n  op : Mult_op A\n  E_one : A\n  E_equiv : Equiv A\n  M : EMonoid op E_one E_equiv\n  k : Fkont A\n  a : A\n  H : Proper (equiv ==> equiv ==> equiv) op\n  ============================\n   computation_execute op (k (a * a * a)) ==\n   computation_execute op (k (a * (a * (a * E_one))))\n\\end{Coqanswer}\n\n\\begin{Coqbad}\nAbort.  \nEnd Bad.\n\\end{Coqbad}\n\nThis failure is due to a lack of an assumption that the continuation\n\\texttt{k} is \\emph{proper} with respect to the equivalence \\texttt{equiv}.\nThus, \\coq{} is unable to infer from the equivalence \n\\texttt{(a * a * a) == (a * (a * (a * E\\_one)))} \\linebreak that \n\\texttt{k (a * a * a)} and \\texttt{k (a * (a * (a * E\\_one)))} are \nequivalent computations.\n\n\n\n\\subsubsection{Definition:} \n\\index{coq}{Type classes}\n\\index{coq}{Type classes!Proper class}\nA continuation \\texttt{k:Fkont A} is \\emph{proper}\nif, whenever \\linebreak[3] \\texttt{x == y} holds, the computations \\texttt{k x} and \n\\texttt{k y} are equivalent.\n\n\n\\begin{Coqsrc}\nClass Fkont_proper\n      `(M : @EMonoid A op E_one E_equiv) (k: Fkont A )  :=\n  Fkont_proper_prf:\n    Proper (equiv ==> computation_equiv op E_equiv) k.\n\\end{Coqsrc}\n\nWe are now able to improve our definition of correctness, taking only\nproper continuations into account.\n\n\\begin{Coqsrc}\nDefinition Fchain_correct_nat (n:nat) (f : Fchain) :=\n forall A `(M : @EMonoid A op E_one E_equiv) k\n        (Hk :Fkont_proper M k)\n        (a : A) ,\n computation_execute op (f A k  a) ==\n computation_execute op (k  (a ^ n)).\n\n\nDefinition Fchain_correct (p:positive) (f : Fchain) :=\n Fchain_correct_nat (Pos.to_nat p) f.\n\\end{Coqsrc}\n\n\\subsubsection{Examples}\n\nLet us show some manual correctness proofs for small f-chains:\n\n\\begin{Coqsrc}\nLemma F1_correct : Fchain_correct 1 F1.\nProof.\n  intros until M ; intros k Hk a ; unfold F1; simpl.\n  apply Hk; monoid_simpl M; reflexivity.\nQed.\n\\end{Coqsrc}\n\n While proving \\texttt{F3}'s correctness, we will have to apply\n the properness hypothesis on \\texttt{k}:\n\n\n\\begin{Coqsrc}\nTheorem F3_correct : Fchain_correct 3 F3.\nProof. \n  intros until M; intros k Hk a; simpl.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n A : Type\n  op : Mult_op A\n  E_one : A\n  E_equiv : Equiv A\n  M : EMonoid op E_one E_equiv\n  k : Fkont A\n  Hk : Fkont_proper M k\n  a : A\n  ============================\n   computation_execute op (k (a * a * a)) ==\n   computation_execute op (k (a * (a * (a * E_one))))}\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\napply Hk. \n\\end{Coqsrc}\n  \n\n\\begin{Coqanswer}\n...\n============================\na * a * a == a * (a * (a * E_one))}\n\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\n  monoid_simpl M; reflexivity.\nQed.\n\\end{Coqsrc}\n\n\nCorrectness of \\texttt{F2} is proved the same way:\n\n\\begin{Coqsrc}\nTheorem F2_correct : Fchain_correct 2 F2.\nProof. \n  intros until M; intros k Hk a; simpl;\n  apply Hk;  monoid_simpl M;  reflexivity.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{Composition of correct f-chains: a first attempt}\n\nWe are now looking for a way to generate correct chains for any positive \nnumber. It seems obvious that we could use \\texttt{Fcompose} for building \na correct f-chain for $n\\times p$ by composition of a correct f-chain for \n$n$ and a correct f-chain for $p$.\n\nLet us try to certify this construction:\n\n\\begin{Coqbad}\nModule Bad2.\n\nLemma Fcompose_correct_attempt :\n  forall f1 f2 n1 n2, Fchain_correct n1 f1 ->\n                      Fchain_correct n2 f2 ->\n                      Fchain_correct (n1 * n2) (Fcompose f1 f2).\n\n(* Beginning of proof omitted *)\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n  Hk : Fkont_proper M k\n  a, x, y : A\n  Hxy : x == y\n  ============================\n   computation_execute op (f2 A k x) == \n   computation_execute op (f2 A k y) \n\\end{Coqanswer}\n\nNo hypothesis guarantees us that the execution of \\texttt{f2} respects the equivalence\n\\texttt{x == y}.\n\n\\begin{Coqbad}\nAbort.\n\\end{Coqbad}\n\n Thus, we need to define also a  notion of properness for f-chains. \nA first attempt would be :\n\n\n\\begin{Coqbad}\nModule Bad3.\n\nClass Fchain_proper_ (fc : Fchain) := Fchain_proper_prf : \n forall  `(M : @EMonoid A op E_one E_equiv) k  ,\n    Fkont_proper M k \n    forall x y, x == y ->\n        @computation_equiv _ op E_equiv (fc A k x) (fc A k y).\n\\end{Coqbad}\n\nThis definition is powerful enough for proving that properness is \npreserved by composition:\n\n\\begin{Coqbad}\nInstance Fcompose_proper_ (f1 f2 : Fchain)\n                             (_ : Fchain_proper_simple f1)\n                             (_ : Fchain_proper_simple f2) :\n Fchain_proper_ (Fcompose f1 f2).\nProof. \n intros until M;intros k Hk x y Hxy; unfold Fcompose;cbn. \n apply (H _ _ _ _ M); auto.\n intros u v Huv;apply (H0 _ _ _ _ M);auto.\nQed.\n\\end{Coqbad}\n\nNevertheless, we had to throw away  this definition of properness:\nIn further \ndevelopments (Sect.~\\vref{Kkonts-section})  we shall  have to compare\nexecutions of the form \\texttt{fc A $k_x$ x} and \\texttt{fc A $k_y$ y}\nwhere \\texttt{x == y} and {$k_x$} and {$k_y$} are \n``equivalent''\nbut not \\emph{convertible} continuations.\n\n\n\\begin{Coqbad}\nEnd Bad3.\n\\end{Coqbad}\n\n\\subsubsection{A better definition of properness}\n\n The following  generalization will allow us to consider continuations that are\ndifferent (according to Leibniz equality) but lead to equivalent\ncomputations and results.\n\n\\begin{Coqsrc}\nDefinition Fkont_equiv  `(M : @EMonoid A op E_one E_equiv)\n (k k': Fkont A )  := \n forall x y : A, x == y ->\n                 computation_equiv op E_equiv  (k x)  (k' y).\n\nClass Fchain_proper (fc : Fchain) := Fchain_proper_prf : \n forall  `(M : @EMonoid A op E_one E_equiv) k k' ,\n    Fkont_proper M k -> Fkont_proper M k' ->    \n    Fkont_equiv M k k' ->\n    forall x y, x == y ->\n        @computation_equiv _ op E_equiv\n                           (fc A k x)\n                           (fc A k' y).\n\\end{Coqsrc}\n\n\n\n\\subsubsection{Examples}\nThe definition above allows us  to build simply several instances of the class \\linebreak\n\\texttt{Fchain\\_proper}:\n\n\\begin{Coqsrc}\nInstance F1_proper : Fchain_proper F1.\nProof.\n  intros until M ; intros k k' Hk Hk' H a b H0; unfold F1; cbn;\n  now apply H.  \nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLtac add_op_proper M H := \n let h := fresh H in\n   generalize (@Eop_proper _ _ _ _ M); intro h.\n\n\nInstance F3_proper : Fchain_proper F3.\nProof.\n  intros  A op one equiv M  k k' Hk Hk'  Hkk' x y Hxy;  \n  apply Hkk'; add_op_proper M H; repeat rewrite Hxy;\n  reflexivity.\nQed.\n\\end{Coqsrc}\n\n\nWe are now able to prove  \\texttt{Fexp2 $n$}'s correctness by induction \non $n$:\n\n\\begin{Coqsrc}\nInstance Fexp2_nat_proper (n:nat) : \n                           Fchain_proper (Fexp2_of_nat n).\nProof.\n induction n; cbn.\n   - apply F1_proper.\n   - apply Fcompose_proper ; [apply F2_proper | apply IHn].\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma  Fexp2_nat_correct (n:nat) : \n         Fchain_correct_nat (2  ^ n) (Fexp2_of_nat n).\nProof.\n  induction n; cbn.\n - apply F1_correct.\n -  rewrite Nat.add_0_r;\n   replace (2 ^ n + 2 ^ n)%nat with (2 * 2 ^n)%nat by  omega;\n   apply Fcompose_correct_nat;auto.\n   +  apply F2_correct.\n   +  apply  Fexp2_nat_proper.\nQed.\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nLemma  Fexp2_correct (p:positive) : \n                           Fchain_correct (2  ^ p) (Fexp2 p).\n(* Proof omitted *)\n\nInstance  Fexp2_proper (p:positive) : Fchain_proper (Fexp2 p).\n(* Proof omitted *)\n\n\\end{Coqsrc}\n\nWe are now  able to build chains for any exponent of the form \n$2^k\\times 3^p$, using \\texttt{Fcompose}. Les us look at a simple example:\n\n\\begin{Coqsrc}\nHint Resolve F1_correct F1_proper\n     F3_correct F3_proper Fcompose_correct Fcompose_proper\n     Fexp2_correct Fexp2_proper .\n\nExample F144:  {f : Fchain | Fchain_correct 144 f /\\\n                                Fchain_proper f}.\nProof.\n change 144 with ( (3 * 3) * (2 ^ 4))%positive.\n exists (Fcompose (Fcompose F3 F3) (Fexp2 4)); auto.\nDefined.\n\n\nCompute proj1_sig F144.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= fun (A : Type) (x : Fkont A) (x0 : A) =>\n       x1 <--- x0 times x0;\n       x2 <--- x1 times x0;\n       x3 <--- x2 times x2;\n       x4 <--- x3 times x2;\n       x5 <--- x4 times x4;\n       x6 <--- x5 times x5; \n       x7 <--- x6 times x6; \n       x8 <--- x7 times x7; \n       x x8\n     : Fchain  \n\\end{Coqanswer}\n\n\n\n\\subsection{Building chains for two distinct exponents : k-chains  \\label{Kkonts-section}}\n\n\\subsubsection{Introduction}\nNot every chain can be built efficiently  with \\texttt{Fcompose}.\n For instance, consider the exponent $n= 23 = 3 + 2^4 + 2^2$. \n\nOne may attempt to define a new operator  for combining f-chains for \n$n$ and $p$ into an f-chain for $n+p$.\n\n\\begin{Coqbad}\nDefinition Fplus (f1 f2 : Fchain) : Fchain :=\n  fun A k x => \n   f1 A (fun y => \n            f2 A (fun z => t <--- z times y; k t) x) \n            x.\n\\end{Coqbad}\n\nFor instance, we can define a chain for $23$:\n\n\\begin{Coqbad}\nLet F23 := Fplus F3 (Fplus (Fexp2 4) (Fexp2 2)).  \n\\end{Coqbad}\n\nUnfortunately, our construct is still very inefficient, since it results in \nduplications of computations, as shown by the normal form of \\texttt{F23}.\n\n\\begin{Coqbad}\nCompute F23\n\\end{Coqbad}\n\n\\begin{Coqanswer}\n = fun (A : Type) (k : Fkont A) (x0 : A) =>\n       x1 <--- x0 times x0;\n       x2 <--- x1 times x0;\n       x3 <--- x0 times x0;\n       x4 <--- x3 times x3;\n       x5 <--- x4 times x4;\n       x6 <--- x5 times x5;\n       x7 <--- x0 times x0;\n       x8 <--- x7 times x7; \n       x9 <--- x8 times x6; \n       x10 <--- x9 times x2; \n       k x10\n\\end{Coqanswer}\n\nWe observe that the variables \\texttt{x3} and \\texttt{x7} are \nuseless, since\nthey will have the same value as \\texttt{x1}. Likewise, computing\n\\texttt{x8} (same value as \\texttt{x4}) is a waste of time.\n\n A better scheme for computing $x^{23}$ would be the following one:\n\n \\begin{enumerate}\n \\item Compute $x$, $x^2$, $x^3$, \\textbf{and} $x^6 = {(x^3)}^2$, then  $x^7$,\n \\item Compute $x^{10} = x^7 \\times x^3$, then $x^{20}$\n \\item Finally, return  $x^{23} = x^{20} \\times x^3$\n \\end{enumerate}\n\nIn fact, the first step of this sequence  computes \\emph{two}\nvalues: $x^7$ and $x^3$, that are re-used by the rest of the computation.\n\n  Like in some programming languages\n that allow  ``multiple values'', like \\texttt{Scheme} and \\texttt{Common Lisp}, we can  express this feature \n in terms of continuations that accept two arguments.\nThus, we extend our previous definitions to chains that return two \ndifferent powers of their argument\\footnote{The name \\texttt{Kchain} comes from previous versions of this development. It may be changed later.}.\n\n\n\\index{coq}{Continuation Passing Style (CPS)}\n\n\\begin{Coqsrc}\nDefinition Kkont A:=  A -> A -> @computation A.\n\nDefinition Kchain :=  forall A, Kkont A -> A -> @computation A.\n\\end{Coqsrc}\n\n\\subsubsection{Examples}\n\nThe chain \\texttt{k3\\_1} sends both values $x$ and $x^3$ to its continuation.\nLikewise, \\texttt{k7\\_3} ``returns''  $x^7$ and $x^3$. \n\n\\begin{Coqsrc}\nExample k3_1 : Kchain := fun A (k:Kkont A) (x:A) =>\n  x2 <--- x times x ;\n  x3 <--- x2 times x ;\n  k x3 x.\n\nExample k7_3 : Kchain := fun A (k:Kkont A)  (x:A) =>\n  x2 <--- x times x;\n  x3 <--- x2 times x ;\n  x6 <--- x3 times x3 ;\n  x7 <--- x6 times x ;\n  k  x7 x3.\n\\end{Coqsrc}\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (0,0) {};\n  \\node (X) at (1,0) {$x$};\n\\node (X2) at (2,0) {$x^2$};\n  \\node (X3) at (3,0) {$x^3$};\n\\node (sortieX) at (4.5,0.6) {};\n\\node(beforeSortieX) at (2,0.6){};\n\\node (sortieX3) at (4.5,0) {};\n\\draw [>-,   thick](entree) -- (X) node [near start, above] {\\tiny{$x$}};\n\\draw [->, >=latex, ](X) -- (X2);\n\\draw [->, >=latex, ](X2) -- (X3);\n\\draw [->,  thick](X3) -- (sortieX3) node [at end, above] {\\tiny{$x^3$}};\n\\draw [->, >=latex](X) to [bend left] (X3);\n\\draw [->, >=latex](X) to [bend left] (X3);\n%\\draw [thick](X) to [bend left] (beforeSortieX)\n\\draw [->, thick](X) -- (2,0.6) --  (sortieX) node [at end, above] {\\tiny{$x$}};\n\\draw[dashed] (0.6,-0.4) rectangle (3.7,1);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{K3\\_1}}\n  \\label{fig:K3-1-as-dag}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\node (X) at (1,0) {$x$};\n  \\node (X2) at (2,0) {$x^2$};\n\\node (X3) at (3.5,0) {$x^3$};\n  \\node (X6) at (4.5,0) {$x^6$};\n\\node (X7) at (6,0) {$x^7$};\n  \\draw [>-,   thick](entree) -- (X) node [near start, above] {\\tiny{$x$}};\n \\draw [->](X) -- (X2);\n\\draw [->](X2) -- (X3);\n\\draw [->, bend left](X) to (X3) ;\n\\draw [->, bend left](X) to (X7) ;\n\\draw [->](X3) -- (X6) ;\n\\draw [->](X6) -- (X7) ;\n  \\node (sortieX7) at (7.5,0) {};\n  \\node (sortieX3) at (7.5,0.8) {};\n \\draw [->,   thick](X7) -- (sortieX7) node [at end, above] {\\tiny{$x^7$}};\n \\draw [->,   thick](X3) -- (5.5,0.8) -- (sortieX3)  node [at end, above] {\\tiny{$x^3$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (6.5,1.4);\n  \\end{tikzpicture}\n  \\caption{Graphical representation of \\texttt{K7\\_3}}\n  \\label{fig:K7-3-as-dag}\n\\end{figure}\n\n\n\\subsubsection{Definitions}\n\nFirst, we have to adapt to k-chains our definitions of correctness and properness. \n\\begin{Coqsrc}\nDefinition Kkont_proper `(M : @EMonoid A op E_one E_equiv)\n           (k : Kkont A) :=\n Proper (equiv ==> equiv ==> computation_equiv op E_equiv) k . \n\nDefinition Kkont_equiv  `(M : @EMonoid A op E_one E_equiv)\n           (k k': Kkont A )  := \n forall x y : A, x == y -> forall z t, z == t -> \n         computation_equiv op E_equiv   (k  x z) (k' y t).\n \\end{Coqsrc}\n\nA k-chain is correct with respect to two exponents $n$ and $p$ \n  if it computes $x ^ n$ and $x ^ p$ for any $x$ in any monoid $M$.\n\n \\begin{Coqsrc}\nDefinition Kchain_correct_nat (n p : nat) (kc : Kchain) :=\n  forall `(M : @EMonoid A op E_one E_equiv)\n        (k : Kkont A), \n        Kkont_proper M k ->\n        forall  (x : A) ,\n              computation_execute op (kc  A k  x) ==\n              computation_execute op (k  (x ^ n) (x ^ p)).\n\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nDefinition Kchain_correct (n p : positive) (kc : Kchain) :=\n  Kchain_correct_nat  (Pos.to_nat n) (Pos.to_nat p) kc.\n\nClass Kchain_proper (kc : Kchain) :=\nKchain_proper_prf : \n forall `(M : @EMonoid A op E_one E_equiv) k k' x y ,\n   Kkont_proper M k ->\n   Kkont_proper M k' -> \n   Kkont_equiv M k k' ->\n   E_equiv x y ->\n   computation_equiv op E_equiv (kc A k x) (kc A k' y).\n\\end{Coqsrc}\n\n\\subsubsection{Example}\nFor instance, let us prove that \\texttt{k7\\_3} is proper and correct for the exponents  $7$ and $3$.\n\n\\begin{Coqsrc}\nInstance k7_3_proper : Kchain_proper k7_3.\nProof.\n  intros until M; intros; red; unfold k7_3; cbn;\n  add_op_proper M H3; apply H1;  rewrite H2;   reflexivity. \nQed.\n\nLemma k7_3_correct : Kchain_correct 7 3 k7_3.\nProof.\n  intros until M; intros; red; unfold k7_3; simpl.\n  apply H; monoid_simpl M;  reflexivity.\nQed. \n\\end{Coqsrc}\n\n\\subsection{Systematic construction of  correct f-chains and k-chains}\n\nWe are now ready to define various operators on f- and k-chains, and prove these\noperators preserve correcness and properness. We will also show that \nthese operators allow to generate easily correct chains for any positive \nexponent. They will be used to generate chains for\nnumbers of the form $n=bq+r$ where $0\\leq r < b$, assuming the previous\nconstruction of correct chains for $r$, $b$ and $q$.\nFor instance, Figure~\\ref{fig:K7-3-decomposition} shows how \\texttt{K7\\_3} is built\nas a composition of \\texttt{K3\\_1} and \\texttt{F2}.\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K3\\_1$};\n  \\draw [>-,   thick](entree) -- (1,0) node [at start, above] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n\n  \\node at (5,0){$F2$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^3$}};\n  \\node (sortiex3global) at (7,1) {};\n  \\node (sortiex3global) at (8.4,1)  {};\n  \\draw [->, thick, bend left] (3.6,0) -- (4,0.6) -- (5,1) --  node [at end, above]\n {\\tiny{$x^3$}} (sortiex3global) ;\n  \\node (join) at (7,0) {$\\times$};\n  \\draw [->, ] (sortieF2) -- (join)\n    node [midway, above] {\\tiny{$x^6$}};\n\\draw [->, bend left] (sortiex) to node [midway, above] {\\tiny{$x$}} (join);\n    \n \\draw [->,   thick](join) -- (8.4,0) node [at end, above] {\\tiny{$x^7$}};\n% \\draw [->,   thick](sortiex3global) --  (8.4,1);\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,1.4);\n  \\end{tikzpicture}\n  \\caption{Decomposition of  \\texttt{K7\\_3}}\n  \\label{fig:K7-3-decomposition}\n\\end{figure}\n\n\\subsubsection{Conversion from k-chains into f-chains}\n\nAny k-chain for $n$ and $p$ can be converted into an f-chain, just by applying it to a continuation that \nignores its second argument.\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n\\node (input) at (-0.5,0){};\n\\node(inputkc) at (1.5,0){};\n\\node(outputkc1) at (2.5,0){};\n\\node(outputkc2) at (2.5,0.4){};\n\\node (ignore) at (3,0.4){{$\\circ$}};\n\\node (output) at (4.4,0){};\n\\draw [dashed] (1.2,-0.5) rectangle (2.5,0.5) ;\n\\draw [dashed] (0.5,-0.7) rectangle (3.3,0.8) ;\n\\node (knp) at (2,0) {$k_{n,p}$};\n\\draw[>->] (input) -- node [near start, above] {\\tiny{$x$}} (inputkc);\n\\draw[thick, ->,>=latex] (outputkc1) +(-0.1,0) -- (output) node [near end,above] {\\tiny{$x^n$}};\n\\draw[thick] (outputkc2) +(-0.1,0)  -- (ignore);\n\\end{tikzpicture}\n  \\caption{The \\texttt{K2F (knp)} construction}\n  \\label{fig:K2F}\n\\end{figure}\n\n\n\n\\begin{Coqsrc}\nDefinition K2F (knp : Kchain) : Fchain :=\n  fun A (k:Fkont A) => kc A (fun  y _ => k y).\n\nLemma K2F_correct :\n  forall knp n p, Kchain_correct kc n p ->\n                 Fchain_correct (K2F n) knp.\n(* Proof omitted *)\n\nInstance K2F_proper (kc : Kchain)(_ : Kchain_proper kc) :\n                                  Fchain_proper (K2F kc).\n\n(* Proof omitted} *)\n\\end{Coqsrc}\n\n\\subsubsection{Construction associated with Euclidean division with a positive rest}\n\nLet $n=bq+r$, with $0<r<b$. Then, for any $x$,  $x^n= (x^{b})^q \\times x^r$. Thus, we can \ncompose an chain that computes $x^b$ and $x^r$ with a chain that raises\nany $y$ to its $q$-th power for obtaining a chain that computes $x^n$.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K_{b,r}$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^b$}};\n  %\\node (sortiex3global) at (7,1) {};\n  \\node (sortiex3global) at (7,1)  {};\n  \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^b$}} (8.7,1)  ;\n  \\node [draw] (multipl) at (7,0) {$\\times$};\n\\draw [->] (2,0.4) to (3,1.5) -- node [midway,above] {\\tiny{$x^r$}} (6,1.5) to (multipl);\n  \\draw [->, ] (sortieF2)  -- (multipl)   node [midway, above] {\\tiny{$x^{bq}$}};\n \\draw [->,   thick](multipl) -- (8.7,0) node [above, near end] {\\tiny{$x^{bq+r}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,2);\n  \\end{tikzpicture}\n  \\caption{The KFK combinator}\n  \\label{fig:KFK}\n\\end{figure}\n\n\\begin{Coqsrc}\nDefinition KFK (kbr : Kchain) (fq : Fchain) : Kchain  :=\n  fun A k a =>\n    kbr A  (fun xb xr =>\n              fq A (fun y =>\n                      z <--- y times xr; k z xb) xb) a.\n\nLemma KFK_correct :\n  forall (b q r : positive) (kbr : Kchain) (fq : Fchain),\n    Kchain_correct b r  kbr ->\n    Fchain_correct q fq ->\n    Kchain_proper kbr ->\n    Fchain_proper fq -> \n    Kchain_correct  (b * q + r) b (KFK kbr fq).\n(* Proof omitted *)\n\nInstance KFK_proper :\nforall (kbr : Kchain) (fq : Fchain),\n  Kchain_proper kbr -> \n  Fchain_proper fq -> \n  Kchain_proper (KFK kbr fq)\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\n\n\n%\\subsection{More certified operators on chains}\n\n\\subsubsection{Ignoring the remainder}\n\nLet $n=bq+r$, with $0<r<b$. The following construction computes\n$x^r$ and $x^b$, then $x^{bq}$, and finally sends $x^{bq+r}$ to the continuation,\nthrowing away $x^b$.\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$K_{b,r}$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiex3) at (2,0) {};\n  \\node (sortiex) at (2,0.4) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^b$}};\n  %\\node (sortiex3global) at (7,1) {};\n  %\\node (sortiex3global) at (7,1)  {};\n  % \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^b$}} (8.7,1)  ;\n  \\node [draw] (multipl) at (7,0) {$\\times$};\n\\draw [->] (2,0.4) to (3,1.5) -- node [midway,above] {\\tiny{$x^r$}} (6,1.5) to (multipl);\n  \\draw [->, ] (sortieF2)  -- (multipl)   node [midway, above] {\\tiny{$x^{bq}$}};\n \\draw [->,   thick](multipl) -- (8.7,0) node [above, near end] {\\tiny{$x^{bq+r}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (7.5,2);\n  \\end{tikzpicture}\n  \\caption{The KFF combinator}\n  \\label{fig:KFF}\n\\end{figure}\n\n\n\n\\begin{Coqsrc}\nDefinition KFF (kbr : Kchain) (fq : Fchain) : Fchain :=\n  K2F (KFK kbr fq).\n\nLemma KFF_correct :\nforall (b q r : positive) (kbr : Kchain) (fq : Fchain),\nKchain_correct  b r kbr ->\nFchain_correct q fq ->\nKchain_proper kbr ->\nFchain_proper fq -> Fchain_correct (b * q + r) (KFF kbr fq).\n(* Proof omitted *)\n\n\nInstance KFF_proper :\nforall (kbr : Kchain) (fq : Fchain),\nKchain_proper kbr -> Fchain_proper fq -> Fchain_proper (KFF kbr fq).\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\n\\subsubsection{Conversion of an f-chain into a k-chain}\nThe following conversion is useful when a chain generation algorithm\nneeds to build a k-chain for exponents $p$ and $1$:\n\n\\begin{Coqsrc}\n  \nDefinition FK (f : Fchain) : Kchain :=\n  fun (A : Type) (k : Kkont A) (a : A) =>\n    f A (fun y => k y a) a.\n\nLemma FK_correct : forall (p: positive) (Fp : Fchain),\n                     Fchain_correct  p Fp ->\n                     Fchain_proper Fp ->\n                     Kchain_correct p 1 (FK Fp) .\n(* Proof omitted *)\n\nInstance  FK_proper  (Fp : Fchain) (_ : Fchain_proper Fp):\n  Kchain_proper (FK Fp).\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\\subsubsection{Computing $x^p$ \\emph{and} $x^{pq}$}\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{tikzpicture}\n  \\node (entree) at (-0.4,0) {};\n  \\draw [dashed] (1,-0.5) rectangle (2,0.5);\n  \\node at (1.5,0){$F_p$};\n  \\draw [>-,   thick](entree) -- (1,0) node [above, near start] {\\tiny{$x$}};\n  \\node (sortiexp) at (2,0) {};\n  \\draw [dashed] (4.5,-0.5) rectangle (5.5,0.5);\n  \\node at (5,0){$F_q$};\n  \\node (entreeF2) at (4.5,0) {};\n\\node (sortieF2) at (5.5,0) {};\n  \\draw[->, ] (sortiex3) -- (entreeF2) \n       node [midway, above] {\\tiny{$x^p$}};\n  \\draw [->, , bend left] (3.6,0) -- (4,0.6) -- (5,1) -- node [near end, above] {\\tiny{$x^p$}} (7.7,1)  ;\n \\draw [->,   thick](sortieF2) -- (7.7,0) node [above, near end] {\\tiny{$x^{pq}$}};\n\\draw  [dashed] (0.5,-0.7) rectangle (6.5,2);\n  \\end{tikzpicture}\n  \\caption{The FFK combinator}\n  \\label{fig:FFK}\n\\end{figure}\n\n\\begin{Coqsrc}\nDefinition FFK (fp fq : Fchain) : Kchain :=\n  fun A k a =>  fp A (fun xb  => fq A (fun y => k y xb) xb) a. \n\n\nLemma FFK_correct  (p q  : positive) (fp fq : Fchain):\n    Fchain_correct p fp  ->\n    Fchain_correct q fq ->\n    Fchain_proper fp ->\n    Fchain_proper fq -> Kchain_correct  (p * q ) p (FFK fp fq).\n(* Proof omitted *)\n\nInstance FFK_proper  (fp fq : Fchain)\n    (_ :   Fchain_proper fp)\n    (_ :  Fchain_proper fq) :  Kchain_proper (FFK fp fq) .\n(* Proof omitted *)\n\\end{Coqsrc}\n\n\\subsubsection{A correct-by-construction chain}\n\nA simple example will show us how to build correct chains \nfor any positive exponent, using the operators above.\n\n\\begin{Coqsrc}\nHint Resolve KFF_correct KFF_proper KFK_correct KFK_proper.\n\nDefinition F87 :=\n let k7_3 :=  KFK k3_1 (Fexp2 1) in\n let k10_7 := KFK k7_3 F1 in\n KFF k10_7 (Fexp2 3).\n\nLemma OK87 : Fchain_correct 87 F87.\nProof.\n unfold F87; change 87 with (10 * (2 ^ 3) + 7)%positive.\n apply KFF_correct;auto.\n change 10 with (7 * 1 + 3); apply KFK_correct;auto.\n change 7 with (3 * 2 ^ 1 + 1)%positive;  apply KFK_correct;auto.\nQed.\n\\end{Coqsrc}\n\nNote that this method of construction still requires some  \ninteraction from the user. \nIn the next section, we build a \\emph{function} that maps any \npositive number $n$ into a correct and proper chain for $n$.\nThus correct chain generation will be fully automated.\n\n\\subsection{Automatic chain generation by Euclidean division}\n\nThe goal of this section is to write a function \n\\texttt{make\\_chain (p:positive): chain} that builds a correct chain for $p$, using\nthe Euclidean method above. In other words, we want to get correct chains\nby computation. The correctness of the result of this computation should be\nasserted by a  theorem:\n\n\\begin{Coqsrc}\nTheorem make_chain_correct : \n   forall p, chain_correct p (make_chain p).  \n\\end{Coqsrc}\n\n\nIn the previous section, we  considered two different kinds of objects:\nf-chains, associated with a single exponent, and k-chains, associated with two exponents. We would expect that the function \\texttt{make\\_chain} we want to build and certify is structured as a pair of mutually recursive functions.\n In \\coq{} , various ways of building such functions are available:\n \\begin{itemize}\n \\item Structural [mutual] recursion with \\texttt{Fixpoint}\n \\item  Using \\texttt{Program Fixpoint}\n \\item Using   \\texttt{Function}.\n \\end{itemize}\n\nSince our construction is based on Euclidean division, we could not\ndefine our chain generator by structural recursion. \nFor simplicity's sake, we chosed to avoid dependent elimination\n and used \\texttt{Function}  with a decreasing measure.\n\n For this purpose, we define a single data-type for associated with\n the generation of F- and K-chains.\n\n\nWe had two slight technical problems to consider:\n\\begin{itemize}\n\\item The generation of a k-chain for $n$ and $p$ is meaningfull only if $p < n$. Thus, in order to avoid a clumsy  dependent pattern-matching, we chosed to represent \n     a pair $(n,p)$ where $0<p<n$ by a pair of positive numbers $(p,d)$ where \n     $d=n-p$\n\\item In order to avoid to deal explicitly with mutual recursion, we\n     defined a type called \\texttt{signature} for representing both\n     forms of function calls.\n     Thus, it is easy to define a decreasing measure on type \n     \\texttt{signature} for proving termination. \n    Likewise, correctness and properness statements are also indexed by \n    this type.\n\n\\end{itemize}\n\n\\begin{Coqsrc}\nInductive signature : Type :=\n|  (** Fchain for the exponent n *)\n     gen_F (n:positive) \n| (** Kchain for the exponents p+d  and p *) \n     gen_K (p d: positive).\n\\end{Coqsrc}\n\nThe following dependently-typed functions will help us to specify  formally\nany correct chain generator.\n\\index{coq}{Dependently typed functions}\n\n\\begin{Coqsrc}\n(** \n  exponent associated with a signature:\n*)\nDefinition signature_exponent (s:signature) : positive :=\n match s with \n| gen_F n => n \n| gen_K p d  =>  p + d\nend.\n\\end{Coqsrc}\n\n\n\n\\begin{Coqsrc}\n(**\nType of the associated continuation \n*)\n\nDefinition kont_type (s: signature)(A:Type) : Type :=\nmatch s with \n| gen_F _  => Fkont A \n| gen_K _ _   => Kkont A\nend.\n\nDefinition chain_type (s: signature) : Type :=\n match s with \n| gen_F _   => Fchain\n|  gen_K _ _  => Kchain\nend.\n\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\nDefinition correctness_statement (s: signature) : \nchain_type s -> Prop :=\nmatch s  with\n  | gen_F p => fun ch => Fchain_correct p ch\n  | gen_K p d   => fun ch => Kchain_correct (p + d) p ch\nend.\n\nDefinition proper_statement (s: signature) : \nchain_type s -> Prop :=\nmatch s  with\n  | gen_F p => fun ch => Fchain_proper ch \n  | gen_K p d   => fun ch => Kchain_proper ch \nend.\n\n(**  Full correctness *)\n\nDefinition  OK (s: signature) \n  := fun c: chain_type s => \n       correctness_statement s c /\\\n       proper_statement s c.\n\n\\end{Coqsrc}\n\n\\subsection{Generation of chains using Euclidean Dibision}\n\nAssume we want to build automatically a correct  f-chain for some \npositive integer $n$.\nIf $n$ equals to $1$, $3$, or $2^p$ for some positive integer  $p$,\nthis task is immediate, thanks to the constants \\texttt{F1}, \n\\texttt{F3} and \\texttt{Fexp2}.\nOtherwise, like in \\cite{DBLP:journals/ita/BrlekCHM95}, we decompose \n$n$ into $bq+r$, where $1<b<n$, and compose the recursively built\nchains for $q$ and $r$ on one side, and $q$ on the other side.\n\nThe efficiency of this method depends on the choice of $b$.\nIn \\cite{DBLP:journals/ita/BrlekCHM95}, the function that maps $n$ into $b$\nis called a \\emph{strategy}. \n\n\\vspace{4pt}\n\\noindent\nFrom ~\\href{../theories/html/additions.Dichotomy.html}{additions.Dichotomy}.\n\\begin{Coqsrc}\nClass Strategy (gamma : positive -> positive):=\n{\ngamma_lt :forall p:positive, 3 < p -> gamma  p < p;\ngamma_gt : forall p:positive, 3 < p -> 1 < gamma  p\n}.\n\n\\end{Coqsrc}\n\\subsection{The dichotomic strategy}\n\n\nIn this chapter, we concentrate\non the so-called \\emph{dichotomic strategy}, defined as follows:\n\n$$n \\mapsto  n \\div {2^k} \\,\\textbf{where}\\, k=\\floor{(\\log_2{n})/2}$$\n\nIntuitively, it corresponds to splitting the binary representation of a positive\ninteger into two halves. For instance, consider $n=87$ its binary representation\nis \\texttt{1010111}. The number $\\floor{(\\log_2{n})/2}$ is equal to $3$.\nDividing $n$ by $2^3$ gives the decomposition $n=10 \\times 2^3 + 7$.\nThus, a chain for $n=87$ can be built from a chain computing both $x^7$ and $x^{10}$,\nand a chain that raises its argument to its $8-th$ power.\n\n\nThis strategy is defined in Module ~\\href{../theories/html/additions.Dichotomy.html}{additions.Dichotomy}.\n\n\n\\begin{Coqsrc}\nFunction dicho_aux (p:positive) {struct p} : positive :=\n match p with\n   | 1%positive   =>  xH\n   | 2%positive |   3%positive  => 2 \n   | xO (xO q) | xO (xI q) | xI (xO q) | xI (xI q) =>\n                                         xO (dicho_aux q)\n end.\n\nDefinition dicho  (p:positive) : positive :=\n  N2pos (N.div (Npos p) (Npos (dicho_aux p))). \n\nInstance Dicho_strat : Strategy dicho.\n\\end{Coqsrc}\n\n\n\\subsection{Other strategies}\nFor comparison's sake, we define two other strategies, much simpler but statically less efficient than the dichotomic strategy.\n\n\\emph{From Module~\\href{../theories/html/additions.BinaryStrat.html}{additions.BinaryStrat}.}\n\n\\begin{Coqsrc}\nDefinition half (p:positive) :=\n  match p with xH => xH\n          |    xI q | xO q =>  q\n  end.\n\nDefinition two (p:positive) := 2%positive.\n\nInstance Binary_strat : Strategy half.\nProof.\n  split; destruct p; unfold half; try lia.\nQed.\n\nInstance Two_strat : Strategy two.\nProof.\n  split;unfold two; lia.\nQed.\n\\end{Coqsrc}\n\nPage.~\\pageref{sect:test-strat}, we compare the three strategies with respect to the length of the built chains.\n\n\\subsection{Main chain generation function}\nWe are now able to define a function that generates a correct chain \nfor any signature. We use the \\texttt{Recdef} module of Standard Library,\nwith an appropriate \\emph{measure}.\n\n\\begin{Coqsrc}\nDefinition signature_measure (s : signature) : nat :=\nmatch s with\n  | gen_F n => 2 * Pos.to_nat n \n  | gen_K p d => 2 * Pos.to_nat (p + d) +1\nend.\n\\end{Coqsrc}\n\n\nThe following function definition generates 9 sub-goals,\nfor proving that the measure on signatures is strictly decreasing along\nthe recursive calls. They are solved with the help of Standard Library's lemmas \non arithmetic of \\texttt{positive} numbers and Euclidean division.\n\n\n%\\todo{Is Function (from Recdef) obsolete ? Use Equations instead ? }\n\n\n\\begin{Coqsrc}\nFunction chain_gen  (s:signature) {measure signature_measure}\n:  chain_type s :=\n  match s  return chain_type s with\n    | gen_F i =>\n      if pos_eq_dec i 1 then F1 else\n        if pos_eq_dec i 3\n        then F3\n        else \n          match exact_log2 i with\n              Some p => Fexp2 p\n            | _ =>\n              match N.pos_div_eucl i (Npos (dicho i))\n              with\n                | (q, 0%N) => \n                  Fcompose  (chain_gen (gen_F (dicho i)))\n                            (chain_gen (gen_F (N2Pos q)))\n                | (q,r)  => KFF (chain_gen\n                                   (gen_K (N2Pos r)\n                                          (dicho i - N2Pos r)))\n                                (chain_gen (gen_F (N2Pos q)))\n                                \n              end end\n\\end{Coqsrc}\n\n\\begin{Coqsrc}\n    | gen_K p d =>\n      if pos_eq_dec p 1 then FK (chain_gen (gen_F (1 + d)))\n      else\n        match N.pos_div_eucl (p + d)  (Npos p) with\n          | (q, 0%N) => FFK   (chain_gen (gen_F p))\n                              (chain_gen (gen_F (N2Pos q)))\n          | (q,r)  => KFK (chain_gen (gen_K (N2Pos r)\n                                            (p - N2Pos r)))\n                          (chain_gen (gen_F (N2Pos q)))\n        end\n  end.\n(* A lot of arithmetic proofs omitted *)\nDefined.\n\nDefinition make_chain (n:positive) : chain :=\n F2C (chain_gen (gen_F n)).\n\n\\end{Coqsrc}\n\nThanks to the \\texttt{Recdef} package, we are now able to get automatically \nbuilt chains using the dichotomic strategy.\n\n\n\\begin{Coqsrc}\nCompute make_chain 87.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n =  fun (A : Type) (x : A) =>\n       x0 <--- x times x;\n       x1 <--- x0 times x;\n       x2 <--- x1 times x1;\n       x3 <--- x2 times x;\n       x4 <--- x3 times x1;\n       x5 <--- x4 times x4;\n       x6 <--- x5 times x5;\n       x7 <--- x6 times x6; \n       x8 <--- x7 times x3; \n       Return x8\n     : chain \n\\end{Coqanswer}\n\n\n\\subsubsection{A few tests}\n\\label{sect:test-strat}\n\nThe following tests show various examples of chains for the same exponent, using different strategies. The dichotomic strategy seems clearly to be the winner (at least on this sample).\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain two 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 25%nat : nat  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain half 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n = 25%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain dicho 56789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 21%nat : nat \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain two 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 33%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain half 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n(= 33%nat : nat\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length (make_chain dicho 3456789).\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 29%nat : nat\n\\end{Coqanswer}\n\n\n\\subsubsection{Correctness of the Euclidean chain generator}\n\n\\texttt{Recdef}'s \\texttt{functional induction} tactic allows us to\nprove that every value returned by (\\texttt{chain\\_gen $s$}) is correct w.r.t. \n\\texttt{$s$} and proper.\nThe proof obligations are solved thanks to the previous lemmas on \nthe composition operators on chains: \\texttt{Fcompose}, \\texttt{KFK}, etc.\nUnfortunately, a lot of interaction is still needed for proving properties of\nEuclidean division and binary logarithm. \n\n\n\n\\begin{Coqsrc}\nLemma chain_gen_OK : forall s:signature, OK  s (chain_gen  s).\nintro s; functional induction chain_gen s.\nProof.\n(* A lot of arithmetic proofs omitted *)\n\nTheorem make_chain_correct :\n    forall p, chain_correct p (make_chain p).\nProof.\n intro p; destruct (chain_gen_OK (gen_F p)).\n unfold make_chain; apply F2C_correct; apply H.\nQed.\n\\end{Coqsrc}\n\n\\subsubsection{A last example}\n\\label{ex45319}\n\nLet us compute  $67777^{6145319}$ with 32 bits integers:\n\n\\begin{Coqsrc}\n\nLtac compute_chain ch := \n   let X := fresh \"x\" in \n   let Y := fresh \"y\" in\n   let X := constr:ch in \n   let Y := (eval vm_compute in X) in \n   exact Y.\n\nLet big_chain := ltac:(compute_chain  (make_chain 6145319)).\n\nPrint big_chain.\n\\end{Coqsrc}\n\n\n\\begin{Coqanswer}\nbig_chain = \nfun (A : Type) (x : A) =>\nx0 <--- x times x; x1 <--- x0 times x0;\nx2 <--- x1 times x1; x3 <--- x2 times x1;\nx4 <--- x3 times x3; x5 <--- x4 times x;\nx6 <--- x5 times x5; x7 <--- x6 times x6;\nx8 <--- x7 times x1; x9 <--- x8 times x5;\nx10 <--- x9 times x8; x11 <--- x10 times x9;\nx12 <--- x11 times x11; x13 <--- x12 times x11;\nx14 <--- x13 times x10; x15 <--- x14 times x14;\nx16 <--- x15 times x11; x17 <--- x16 times x16;\nx18 <--- x17 times x17; x19 <--- x18 times x18;\nx20 <--- x19 times x19; x21 <--- x20 times x20;\nx22 <--- x21 times x21; x23 <--- x22 times x22;\nx24 <--- x23 times x23; x25 <--- x24 times x24; \nx26 <--- x25 times x25; x27 <--- x26 times x26; \nx28 <--- x27 times x14;  Return x28\n     : forall A : Type, A -> computation\n\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nTime   Compute  Int31.phi \n     (chain_apply big_chain (snd (positive_to_int31  67777))).\n\\end{Coqsrc}\n\\begin{Coqanswer}\n= 2014111041%Z\n     : Z\nFinished transaction in 0.005 secs (0.005u,0.s) (successful)}  \n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute chain_length big_chain.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n= 29%nat\n     : nat  \n\\end{Coqanswer}\n\n\n\n\\subsection{Fibonacci, \\emph{le retour}}\n\\label{sect:fibonacci-euclidean}\n\nIt is now possible to use Euclidean addition chains for computing Fibonacci numbers\n(see Sections~\\vref{sect:fibonacci-mul2} and~\\vref{sect:fibonacci-pos-bpow}).\n\nThe following function is parameterized by any strategy $\\gamma$.\n\n\\begin{Coqsrc}\nDefinition fib_eucl gamma `{Hgamma: Strategy gamma} n :=\n  let c := make_chain gamma  n\n  in let r := chain_apply c (M:=Mul2) (1,0) in\n       fst r + snd r.\n\nCompute fib_eucl dicho 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.002 secs (0.002u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute fib_eucl two 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.003 secs (0.003u,0.s) (successful)\n\\end{Coqanswer}\n\n\\begin{Coqsrc}\nCompute fib_eucl half 153.\n\\end{Coqsrc}\n\n\\begin{Coqanswer}\n    = 68330027629092351019822533679447\n     : N\nFinished transaction in 0.003 secs (0.003u,0.s) (successful)\n\\end{Coqanswer}\n\n\n\\section{Projects}\n\n\\index{additions}{Projects}\n\\begin{project}[Optimality and relative efficiency]\n\n\\vspace{3pt}\n\n\\noindent\n\n\\begin{enumerate}\n\\item  Prove that the chain generated by \\texttt{Fexp2} is optimal.\n\\item Prove that  the length of any optimal chain for $n$ is\ngreater than or equal to $\\floor{\\log_2{n}}$.\n\\item Prove that, for any positive $n$, the length of any Euclidean chain generated by the \n  dichotomic strategy  is always less than or equal to\n  the length of \\texttt{binary\\_chain $n$}, and for an infinite number\nof positive integers $n$, the first chain  is strictly shorter\nthan  the latter.\n\\item Prove that our implementation of the dichotomic strategy describes\n the same function as in the litterature (for instance ~\\cite{DBLP:journals/ita/BrlekCHM95}.)\nThis is important if we want to follow the complexity analyses in this and similar articles.\n\\item Study how to \\emph{compile} a chain into imperative code, using a register allocation strategy (it may be useful  to define \\emph{chain width} ).\n\n\\paragraph*{Remark:} The first two questions of the list above should involve a \nuniversal quantification on type\n\\texttt{chain}. It may be necessary (but we're not sure) to consider  some \nrestriction on parametric chains.\n\n\\end{enumerate}\n\\end{project}\n\n\\subsection{A data structure for Euclidean chains}\n\n\nFigures~\\vref{fig:F3-as-dag} to \\vref{fig:FFK} suggest that any computation following an Euclidean chain can be executed on a kind  of abstract machine with a \"register'' and a stack, and only four operations:\n\\begin{itemize}\n\\item multiply the contents of the register by the top of the stack (and pop that stack),\n\\item raising the contents of the register to its square,\n\\item push the contents of the register into the stack,\n\\item swapping the two elements at the top of the stack.\n\\end{itemize}\n\nIn \\coq{}, we define the instructions as the four constructors of an inductive type.\n\nFrom Module~\\href{../theories/html/additions.AM.html}{additions.AM}\n\n\\begin{Coqsrc}\n(** basic instructions *)\n\nInductive instr : Set :=\n  | MUL : instr\n  | SQR : instr\n  | PUSH : instr\n  | SWAP : instr.       \n\nDefinition code := list instr.\n\n(* semantics *)\n(*************)\n\nSection Semantics.\n\n Variable A : Type.\n Variable mul : A -> A -> A.\n Variable one : A.\n\n Definition stack := list A.\n Definition config := (A * list A)%type.\n\n Fixpoint exec (c : code) (x:A) (s: stack) : option config :=\n   match c, s with\n     nil, _ => Some (x,s)\n   | MUL::c, y::s => exec c (mul x y) s\n   | SQR::c, s => exec c (mul x x) s\n   | PUSH::c, s => exec c x (x::s)\n   | SWAP::c, y::z::s => exec c x (z::y::s)\n   | _,_ => None\n   end.\n\n(* ... *)\nEnd Semantics.\n\\end{Coqsrc}\n\nFor instance the chain of Fig.~\\vref{fig:C87} can be represented with the following code:\n\n\\begin{Coqsrc}\n  PUSH :: PUSH :: SQR  :: MUL :: PUSH :: SWAP :: SQR :: MUL :: PUSH\n            :: SWAP :: MUL :: SQR :: SQR :: SQR :: MUL :: nil \n\\end{Coqsrc}\n\n\nIn the library~\\href{../theories/html/additions.AM.html}{additions.AM},\nwe define a chain generator for this data structure. \nPlease note that many proof scripts are copied verbatim from \n\\texttt{Euclidean\\_Chains} into \\texttt{AM}. Removing such redundancies is left as a project.\n\n\n\n\\begin{project}[Some improvements]\n \\begin{enumerate}\n\\item Improve automated proofs on types \\texttt{positive} and \\texttt{N}.\n\\item Compare  \\texttt{Program Fixpoint} and \\texttt{Function} for\nwriting \\texttt{make\\_chain}. Consider measure \\emph{vs} well-founded \nrelations, mutual recursion, possibility of using sigma-types, etc.\n\\item Chains are always associated with strictly positive exponents. \nThus, many lemmas about chain correctness  can be proved using semi-groups instead of\nmonoids. Define type classes for semi-groups and use them whenever possible.\n\\end{enumerate}  \n\\end{project}\n\n\n% \\end{project}\n\n\n\n\n\n% \\section{Exponentiation in \\coq's standard library}\n\n% Exponentiation is already defined for several types in Standard Library\\footnote{The following information was checked according to \\texttt{8.5beta2} version of \\coq{}.}\n\n% \\subsection{Peano numbers}\n% Exponentation is defined in \\texttt{Coq.Init.Nat} as a binary operation on type nat. Basically, it is a structurally recursive definition with respect \n% to its second argument.\n\n% \\begin{verbatim}\n% Fixpoint pow n m :=\n%   match m with\n%     | 0 => 1\n%     | S m => n * (n ^ m)\n%   end\n\n% where \"n ^ m\" := (pow n m) : nat_scope.\n% \\end{verbatim}\n\n\n% \\subsection{Binary positive numbers}\n% Exponentiation is defined in \\texttt{Coq.PArith.BinPosDef} as a binary operation on type \\texttt{positive}.\n% Its definition uses a polymorphic functional that allows to iterate \n% a unary function on any type $A$.\n\n% \\begin{verbatim}\n% Definition iter {A} (f:A -> A) : A -> positive -> A :=\n%   fix iter_fix x n := match n with\n%     | xH => f x\n%     | xO n' => iter_fix (iter_fix x n') n'\n%     | xI n' => f (iter_fix (iter_fix x n') n')\n%   end.\n\n% (** ** Power *)\n\n% Definition pow (x:positive) := iter (mul x) 1.\n\n% Infix \"^\" := pow : positive_scope.\n% \\end{verbatim}\n\n% Although the definition of \\texttt{iter} takes advantage of the binary\n% representation of \\texttt{n}, the computation of some $x^n$ amounts\n% to $n$ iterations of the function \\texttt{(mul x)}. Thus, the function\n% \\texttt{Pos.pow} is linear with respect to the exponent.\n\n\n% \\begin{alltt}\n% Time Compute Pos.pow 1\\%positive 56666667\\%positive.\\it\n% Finished transaction in 5.679 secs (5.693u,0.s) (successful)\n% \\end{alltt}\n\n% \\subsection{Binary integers}\n\n% Types \\texttt{N} [resp. \\texttt{Z}] are also provided with binary operations\n% that allow to compute $x^n$ (for $x,n$ of type \\texttt{N} [resp.   \\texttt{Z}].\n\n% In \\texttt{Coq-8.5beta2}, the functions \\texttt{Coq.NArith.BinNat.N.pow}\n% and \\linebreak \\texttt{Coq.ZArith.BinInt.Z.pow} are also defined as iterations\n% of \\texttt{(mul x)} using the same iteration functional as for the \\texttt{positive} type. Thus they are also linear with respect to the exponent.\n\n\n\n\n\n\n", "meta": {"hexsha": "652cf0413b1a004fae64ccdcf61f43b7135258d2", "size": 142243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/chapter-powers.tex", "max_stars_repo_name": "start974/hydra-battles", "max_stars_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "doc/chapter-powers.tex", "max_issues_repo_name": "start974/hydra-battles", "max_issues_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/chapter-powers.tex", "max_forks_repo_name": "start974/hydra-battles", "max_forks_repo_head_hexsha": "83322c9b4e8522c1bde2d6151d61105ca3c012ec", "max_forks_repo_licenses": ["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.7153962427, "max_line_length": 803, "alphanum_fraction": 0.6682859613, "num_tokens": 45360, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278788223264, "lm_q2_score": 0.8688267796346599, "lm_q1q2_score": 0.7666769722170458}}
{"text": "\\chapter*{Appendix A: The Lifting Scheme}\n\\addcontentsline{toc}{chapter}{Appendix A: The Lifting Scheme}\n\n\\subsection*{Introduction}\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_lift.ps,bbllx=4.5cm,bblly=13cm,bburx=18.5cm,bbury=19.5cm,width=14cm,height=6.5cm,clip=}}\n}\n\\caption{The lifting scheme -- forward direction.}\n\\label{fig_lift}\n\\end{figure}\nThe lifting scheme \\cite{wave:sweldens96} is a flexible technique that has \nbeen used in several different settings, for easy construction and implementation\nof traditional wavelets \\cite{wave:sweldens96}, and of second generation\nwavelets \\cite{wave:sweldens95b} such as spherical wavelets \\cite{wave:sweldens95a}.\n\nIts principle is to compute the difference between a true coefficient and its\nprediction:\n\\begin{eqnarray}\nw_{j+1,l} = c_{j,2l+1} - {\\cal P}(c_{j,2l-2L}, ..., c_{j,2l-2},c_{j,2l},c_{j,2l+2}, ..., c_{j,2l+2L})\n\\end{eqnarray}\nA pixel at an odd location 2l+1 is then predicted using pixels at even\nlocations.\n\nThe transformation is done in three steps:\n\\begin{enumerate}\n\\item Split the signal into even and odd number samples:\n\\begin{eqnarray*}\nc_{j+1,l} & = & c_{j,2l} \\\\\nw_{j+1,l} & = & c_{j,2l+1}\n\\end{eqnarray*}\n\\item Set \\[w_{j+1,l} = w_{j+1,l} - {\\cal P}(c_{j+1,l})\\]\n\\item Set \\[c_{j+1,l} = c_{j+1,l} + {\\cal U}(w_{j+1,l})\\]\nwhere $\\cal U$ is the update operator.\n\\end{enumerate}\nThe reconstruction is obtained by:\n\\begin{eqnarray*}\nc_{j,2l} & = & c_{j+1,l} - {\\cal U}(w_{j+1,l}) \\\\\nc_{j,2l+1} & = & w_{j+1,l} + {\\cal P}(c_{j+1,l}) \\\\\n\\end{eqnarray*}\n \n\\subsection*{Example of transforms}\n\n\\subsubsection*{Haar wavelet via lifting}\n\nThe Haar transform can be performed via the lifting scheme by taking\nthe predict operator equal to the identity, and an update operator which\nhalves the difference. The transform becomes:\n\\begin{eqnarray*}\nw_{j+1,l} =  w_{j+1,l} - c_{j+1,l} \\\\\nc_{j+1,l} = c_{j+1,l} + {w_{j+1,l} \\over 2}\n\\end{eqnarray*}\nAll computation can be done in place. Every wavelet transform can be written\nvia lifting.\n\n\n\\subsubsection*{Linear wavelets via lifting}\nThe identity predictor used before is correct when the signal is constant.\nIn the same way, we can use a linear predictor which is correct when\nthe signal is linear. The predictor and update operators are now:\n\\begin{eqnarray*}\n{\\cal P}(c_{j-1,l} & = & {1 \\over 2} (c_{j-1,l} + c_{j-1,l+1}) \\\\\n {\\cal U}(w_{j-1,l}) & = & {1 \\over 4} (w_{j-1,l-1} + w_{j-1,l})\n\\end{eqnarray*}\nIt is easy to verify that:\n\\begin{eqnarray*}\nc_{j-1,l} = -{1 \\over 8} c_{j,2l-2} + {1 \\over 4} c_{j,2l-1} + {3 \\over 4} c_{j,2l}\n+ {1 \\over 4} c_{j,2l+1} -{1 \\over 8} c_{j,2l+2}\n\\end{eqnarray*}\nwhich is the bi-orthogonal Cohen-Daubechies-Feauveau \\cite{wave:cohen92}\n wavelet transform.\n\n\n\\subsection*{Integer wavelet transform}\n\nWhen the input data are integer values, the wavelet transform no longer consists\nof integers. For lossless coding, it is useful to have a wavelet \ntransform which produces integer values.\nWe can build an integer version of every wavelet\ntransform \\cite{wave:calderbank96}. For instance, denoting $\\lfloor x \\rfloor$ \nas the largest integer\nnot exceeding x, the integer Haar transform  (also called ``S'' transform)\ncan be calculated by:\n\\begin{eqnarray}\nw_{j+1,l} & = & c_{j,2l+1} - c_{j,2l} \\\\ \\nonumber\nc_{j+1,l} & = & c_{j,2l} + \\lfloor {w_{j+1,l} \\over 2 } \\rfloor = c_{j+1,l} + \\lfloor {w_{j+1,l} \\over 2 } \\rfloor\n\\end{eqnarray}\nwhile the reconstruction is\n\\begin{eqnarray}\nc_{j,2l} & = &  c_{j+1,l} - \\lfloor {w_{j+1,l} \\over 2} \\rfloor \\\\ \\nonumber\nc_{j,2l+1} & = &  w_{j+1,l} +  c_{j,2l}\n\\end{eqnarray}\n\nMore generally, the lifting operators for an integer version of the wavelet transform are:\n\\begin{eqnarray*}\n{\\cal P}(c_{j+1,l}) & = & \\lfloor \\sum_k p_k c_{j+1,l-k} + {1 \\over 2 } \\rfloor\\\\\n {\\cal U}(w_{j+1,l}) & = &  \\lfloor \\sum_k u_k w_{j+1,l-k} + {1 \\over 2 } \\rfloor\n\\end{eqnarray*}\n\nThe linear integer wavelet transform is \n\\begin{eqnarray*}\nw_{j+1,l} & = & w_{j+1,l} - \\lfloor {1 \\over 2 }(c_{j+1,l}+c_{j+1,l+1})+ {1 \\over 2 } \\rfloor\\\\\nc_{j+1,l} & = & c_{j+1,l} + \\lfloor {1 \\over 4 }(w_{j+1,l-1}+w_{j+1,l})+ {1 \\over 2 } \\rfloor\n\\end{eqnarray*}\n  \nEven if there is no filter that consistently performs better than all\nthe other filters on all images, the following one performs generally better\nthan others \\cite{wave:calderbank96}:\n\\begin{eqnarray*}\nw_{j+1,l} & = & w_{j+1,l} - \\lfloor {1 \\over 2 }(c_{j+1,l}+c_{j+1,l+1})+ {1 \\over 2 } \\rfloor\\\\\nc_{j+1,l} & = & c_{j+1,l} + \\lfloor {1 \\over 4 }(w_{j+1,l-1}+w_{j+1,l})+ {1 \\over 2 } \\rfloor\n\\end{eqnarray*}\nMore filters can be found in \\cite{wave:calderbank96}. \n% (the notation (x,y) means that the numbers of wanishing moments\n% of the analysing and synthesis high pass filter are respectively x and y):\n% \\item{integer linear transform: (2,2)}\n% More details can be found in \\cite{wave:calderbank96}. \\\\\n\n", "meta": {"hexsha": "335503649d517020ef683cfafaa0a85072188af8", "size": 4846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr1/annex_lifting.tex", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/doc/doc_mra/doc_mr1/annex_lifting.tex", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/doc/doc_mra/doc_mr1/annex_lifting.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.0495867769, "max_line_length": 114, "alphanum_fraction": 0.6795295089, "num_tokens": 1843, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278788223265, "lm_q2_score": 0.8688267711434708, "lm_q1q2_score": 0.7666769647241839}}
{"text": "% I removed the definition of a manifold and moved it in-line for better flow.\r\n% I think it's best to use /emph in definitions to show what's being defined.\r\n% Put periods even in display math!\r\n% For spacing reasons, should use \\colon instead of : for functions, e.g. f \\colon A \\to B.\r\n% Since ker is lowercase, im probably should be also.\r\n\r\n\\section{Introduction, simplices}\\label{905}\r\n%In 18.905, which is the first half of this book, we will cover the following topics:\r\n%\\begin{enumerate}\r\n%    \\item Singular homology\r\n%    \\item CW-complexes\r\n%    \\item Basics of category theory\r\n%    \\item Homological algebra\r\n%    \\item The K\\\"{u}nneth theorem\r\n%    \\item UCT, cohomology\r\n%    \\item Cup and cap products, and\r\n%    \\item Poincar\\'{e} duality.\r\n%\\end{enumerate}\r\nWe will begin by giving some examples of commonly encountered topological\r\nspaces.\r\n\\begin{itemize}\r\n    \\item The most basic is \\emph{$n$-dimensional Euclidean space}, $\\mathbf{R}^n$.\r\n    \\item The \\emph{$n$-sphere} $S^n=\\{x\\in \\mathbf{R}^{n+1}:|x|=1\\}$ is topologized as a subspace of $\\mathbf{R}^{n+1}$.\r\n    \\item Identifying antipodal points in $S^n$ gives \\emph{real projective space} $\\mathbf{RP}^n=S^n / (x\\sim -x)$, i.e. the space of lines through the origin in $\\mathbf{R}^{n+1}$.\r\n    \\item Call an ordered collection of $k$ orthonormal vectors an \\emph{orthonormal $k$-frame}. The space of orthonormal $k$-frames in $\\mathbf{R}^n$ forms the \\emph{Stiefel manifold} $V_k(\\mathbf{R}^n)$, which is topologized as a subspace of $(S^{n-1})^k$.\r\n    \\item Let $x\\sim y$ if $x$ and $y$ are $k$-frames with the same span. The \\emph{Grassmannian} is the quotient $\\mathrm{Gr}_k(\\mathbf{R}^n)=V_k(\\mathbf{R}^n)/\\sim$. In particular, $\\mathbf{Gr}_1(\\mathbf{R}^n) = \\mathbf{RP}^{n-1}$.\r\n\\end{itemize}\r\nThe above are all \\emph{manifolds}, which are Hausdorff spaces locally homeomorphic to Euclidean space. Aside from $\\mathbf{R}^n$ itself, the preceding examples are also compact. Such spaces exhibit a hidden symmetry, which is the culmination of 18.905: Poincar\\'{e} duality.\r\n\r\nAs the name suggests, the central aim of algebraic topology is the usage of algebraic tools to study topological spaces. A common technique is to probe topological spaces via maps to them. In different ways, this approach gives rise to singular homology and homotopy groups. We now detail the former; the latter takes stage in 18.906.\r\n\\begin{definition}\r\nFor $n\\geq 0$, the \\emph{standard $n$-simplex} $\\Delta^n$ is the convex hull of the standard basis $\\{e_0,\\cdots,e_n\\}$ in $\\mathbf{R}^{n+1}$. More explicitly,\r\n$$\\Delta^n = \\left\\{\\sum t_i e_i : \\sum t_i = 1, t_i\\geq 0\\right\\}\\subseteq\\mathbf{R}^{n+1}.$$\r\nThe $t_i$ are called barycentric coordinates.\r\n\\end{definition}\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{assets/L01/01-standard-simplices}\r\n\t\\caption{The standard 1-simplex and 2-simplex.}\r\n\t\\label{fig:01-standard-simplices}\r\n\\end{figure}\r\nWe will write $i$ in lieu of $e_i$ to refer to the vertices of $\\Delta^n$. The standard simplices are related by face inclusions $d^i\\colon \\Delta^{n-1} \\to \\Delta^{n}$ for $0\\leq i \\leq n$, where $d^i$ misses the vertex $i$.\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.9\\linewidth]{assets/L01/01-face-inclusions}\r\n\t\\caption{The face inclusions for $n=1$ (left) and $n=2$ (right).}\r\n\t\\label{fig:01-face-inclusions}\r\n\\end{figure}\r\n\\begin{definition}\r\nLet $X$ be any topological space. A \\emph{singular $n$-simplex} in $X$ is a continuous map $\\Delta^n\\to X$. Denote by $\\mathrm{Sin}_n(X)$ the set of all $n$-simplices in $X$. This seems like a rather bold construction to make, as $\\mathrm{Sin}_n(X)$ is huge. Nonetheless, we will soon make it even larger.\r\n\\end{definition}\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=\\linewidth]{assets/L01/01-simplices-on-torus}\r\n\t\\caption{A 1-simplex and a 2-simplex in the torus.}\r\n\t\\label{fig:01-simplices-on-torus}\r\n\\end{figure}\r\n\r\nFor $0\\leq i \\leq n$, precomposition by the face inclusion $d^i$ produces a map $d_i\\colon \\Sin_n(X)\\to\\Sin_{n-1}(X)$ sending $\\sigma\\mapsto\\sigma\\circ d^i$, which is the $i$th face of $\\sigma$. This allows us to make sense of the ``boundary'' of a simplex, and we are particularly interested in simplices for which that boundary vanishes.\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\includegraphics[width=0.7\\linewidth]{assets/L01/01-torus-simplex-around-hole}\r\n\t\\caption{A 1-simplex around the hole in the torus.}\r\n\t\\label{fig:01-torus-simplex-around-hole}\r\n\\end{figure}\r\nFor example, if $\\sigma$ is a 1-simplex that goes around the hole in a torus $T$ as in Figure \\ref{fig:01-torus-simplex-around-hole}, then $d_1\\sigma = d_0\\sigma$. To express that the boundary vanishes, we want to write $d_0\\sigma - d_1\\sigma=0$, but this difference is no longer a simplex. To accommodate such formal sums, we will enlarge $\\mathrm{Sin}_n(X)$ further by considering the free abelian group it generates.\r\n\\begin{definition}\r\nThe abelian group $S_n(X)$ of \\emph{singular $n$-chains} in $X$ is the free abelian group generated by $n$-simplices\r\n$$S_n(X) = \\mathbf{Z}\\Sin_n(X).$$\r\n    Its elements are finite linear combinations, i.e. formal sums\r\n    $$\\sum_{i\\in\\text{finite set}}a_i\\sigma_i$$\r\n    where $a_i\\in\\mathbf{Z}$ and $\\sigma_i \\in \\Sin_n(X)$. If $n<0$, say that $S_n(X)=0$. Now, define\r\n$$\\partial\\colon \\Sin_n(X)\\to S_{n-1}(X),$$\r\n$$\\partial\\sigma = \\sum_{i=0}^n(-1)^i d_i\\sigma.$$\r\nThis extends to a homomorphism $\\partial \\colon S_n(X) \\to S_{n-1}(X)$ by additivity.\r\n\\end{definition}\r\nWe use this homomorphism to obtain something more tractable than the entirety of $S_n(X)$. First we restrict our attention to chains with vanishing boundary.\r\n\\begin{definition}\r\nAn \\emph{$n$-cycle} in $X$ is an $n$-chain $c$ with $\\partial c = 0$. Denote $Z_n(X) = \\ker(S_n(X)\\xrightarrow{\\partial}S_{n-1}(X))$.\r\n\\end{definition}\r\nFor example, with $\\sigma$ on the torus described before, $\\sigma\\in Z_1(X)$\r\nsince $\\partial \\sigma = d_0\\sigma - d_1\\sigma = 0$.\r\n\\begin{theorem}\r\n    Any boundary is a cycle, i.e., $B_n(X) :=\r\n    \\mathrm{Im}(\\partial:S_{n+1}(X)\\to S_n(X))\\subseteq Z_n(X)$.\r\n\\end{theorem}\r\n\\begin{exercise}\\label{exer:simplicialidentities}\r\n    Deduce the above theorem by proving the following statements.\r\n    \\begin{enumerate}\r\n\t\\item An order-preserving map $\\phi:[n]\\to[m]$ extends to an affine map\r\n\t    $\\phi^\\ast:\\Delta^n\\to \\Delta^m$. Give an explicit formula for\r\n\t    $\\phi^\\ast$.\r\n\t\\item Prove that any order-preserving map factors uniquely as the\r\n\t    composite of an order-preserving surjection followed by an\r\n\t    order-preserving injection.\r\n\t\\item Let $d^j:[n-1]\\to [n]$ be the order-preserving injection omitting\r\n\t    $j$ as a value. Prove that an order-preserving injection\r\n\t    $\\phi:[n-k]\\to[n]$ is uniquely a composition of the form $d^{j_k}\r\n\t    d^{j_{k-1}}\\cdots d^{j_1}$ with $0\\leq j_1<j_2<\\cdots<j_k\\leq n$.\r\n\t    Define the $j_i$'s in terms of $\\phi$. Verify the straightening\r\n\t    rule\r\n\t    $$d^id^j = d^{j+1} d^i \\text{ if }i\\leq j.$$\r\n\t\\item Let $s^i:[n+1]\\to [n]$ be the order-preserving surjection\r\n\t    repeating the value $i$. Show that any order-preserving surjection\r\n\t    $\\phi:[m]\\to [n]$ is uniquely a composition of the form\r\n\t    $(s^n)^{i_n}(s^{n-1})^{i_{n-1}}\\cdots(s^0)^{i_0}$ by describing the\r\n\t    $i_j$'s in terms of $\\phi$. Verify a straightening rule for the\r\n\t    composite $s^i s^j$.\r\n\t\\item Verify a straightening rule for $s^i d^j$.\r\n\t\\item Write down the straightening rules for the induced maps $d_i =\r\n\t    (d^i)^\\ast:\\Sin_n(X)\\to \\Sin_{n-1}(X)$ and $s_i =\r\n\t    (s^i)^\\ast:\\Sin_m(X)\\to \\Sin_{m+1}(X)$. Use these to verify that\r\n\t    $\\partial^2 = 0:S_n(X)\\to S_{n-2}(X)$.\r\n\t\\item Let $f:X\\to Y$ be a continuous map. This induces a map\r\n\t    $f_\\ast:\\Sin_n(X)\\to \\Sin_n(Y)$. Show that the $f_\\ast$ assemble to\r\n\t    give a map of simplicial sets, i.e., show that the maps $f_\\ast$\r\n\t    commute with the maps induced by order-preserving maps $\\phi:[m]\\to\r\n\t    [n]$.\r\n    \\end{enumerate}\r\n\\end{exercise}\r\n\r\nWith the preceding, we are prepared to define singular homology.\r\n\\begin{definition}\r\nThe \\emph{$n$th singular homology group} of $X$ is:\r\n    $$ H_n(X) = Z_n(X)/B_n(X) = \\frac{\\ker(\\partial:S_n(X)\\to S_{n-1}(X))}{\\mathrm{im}(\\partial:S_{n+1}(X)\\to S_n(X))}.$$\r\n\\end{definition}\r\nBoth $Z_n(X)$ and $B_n(X)$ are free abelian groups because they are subgroups of the free abelian group $S_n(X)$, but the quotient $H_n(X)$ isn't necessarily free. While $Z_n(X)$ and $B_n(X)$ are uncountably generated, $H_n(X)$ is finitely generated for the spaces we are interested in. If $T$ is the torus for example, then $H_1(T) \\cong \\mathbf{Z} \\oplus \\mathbf{Z}$ and $\\sigma$ as described previously is one of the two generators.\r\n", "meta": {"hexsha": "ebaaad79fe6d53c2637fd4851b8a786a47e43da8", "size": 8728, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-1-intro.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-1-intro.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-1-intro.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": 68.1875, "max_line_length": 436, "alphanum_fraction": 0.6877864345, "num_tokens": 2857, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278602705731, "lm_q2_score": 0.8688267881258485, "lm_q1q2_score": 0.766676963591647}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & -2 & -2 \\\\\n      2 & -3 & -2 \\\\\n      -2 & 2 &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Which of the following vectors are eigenvectors of $A$? Find the\n  corresponding eigenvalues.\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ -1 \\end{mymatrix},\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} 1 \\\\ 1 \\\\ 0 \\end{mymatrix},\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{r} 2 \\\\ 2 \\\\ -1 \\end{mymatrix},\\quad\n    \\vect{v}_4 = \\begin{mymatrix}{r} 0 \\\\ -1 \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1  &  0 & 0 \\\\\n      -5 & -1 & 5 \\\\\n      -3 &  0 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the eigenvectors corresponding to the eigenvalue $\\eigenvar=4$.\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      7 &  -4 &   8 \\\\\n      -1 &  4 &  -2 \\\\\n      -2 &  2 &  -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Find the eigenvectors corresponding to the eigenvalue $\\eigenvar=3$.\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      4 &   0 &   3 \\\\\n      -3 &   1 &  -3 \\\\\n      0 &   0 &   1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  This matrix has eigenvalues $\\eigenvar=1$ and $\\eigenvar=4$. Find a\n  basis for each eigenspace.\n\\end{ex}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      2 &   4 &  -4 \\\\\n      -1 &  6 &  -9 \\\\\n      0 &   0 &  -3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  This matrix has eigenvalues $\\eigenvar=3$ and $\\eigenvar=4$. Find a\n  basis for each eigenspace.\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is a $3\\times 3$-matrix with eigenvalues\n  $\\eigenvar_1=1$, $\\eigenvar_2=0$, and $\\eigenvar_3=2$ and\n  corresponding eigenvectors\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r}\n      -1 \\\\\n      -2 \\\\\n      -2\n    \\end{mymatrix},\n    \\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r}\n      1 \\\\\n      1 \\\\\n      1\n    \\end{mymatrix},\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_3 = \\begin{mymatrix}{r}\n      -1 \\\\\n      -4 \\\\\n      -3\n    \\end{mymatrix}.\n  \\end{equation*}\n  (By ``corresponding'', we mean that $\\vect{v}_1$ corresponds to\n  $\\eigenvar_1$, $\\vect{v}_2$ corresponds to $\\eigenvar_2$, and so\n  on).  Find\n  \\begin{equation*}\n    A\\begin{mymatrix}{r}\n      3 \\\\\n      -4 \\\\\n      3\n    \\end{mymatrix}.\n  \\end{equation*}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ be an $n\\times n$-matrix, and assume $\\eigenvar$ is an\n  eigenvalue of $A$. Show that $\\eigenvar^2$ is an eigenvalue of\n  $A^2$.\n  \\begin{sol}\n    If $\\vect{v}$ is an eigenvector corresponding to the eigenvalue\n    $\\eigenvar$, then $A^2\\vect{v}=A(A\\vect{v}) =\n    A(\\eigenvar\\vect{v}) = \\eigenvar(A\\vect{v}) =\n    \\eigenvar^2\\vect{v}$. Therefore, $\\vect{v}$ is an eigenvector of\n    $A^2$ with eigenvalue $\\eigenvar^2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ be an invertible $n\\times n$-matrix, and assume $\\eigenvar$\n  is an eigenvalue of $A$. Show that $\\eigenvar\\neq 0$ and that\n  $\\eigenvar^{-1}$ is an eigenvalue of $A^{-1}$.\n  \\begin{sol}\n    We have\n    $\\eigenvar A^{-1}\\vect{v} = A^{-1}\\eigenvar\\vect{v} =\n    A^{-1}A\\vect{v} = \\vect{v}$. Since $\\vect{v}\\neq 0$, this implies\n    $\\eigenvar\\neq 0$. Moreover, it implies\n    $A^{-1}\\vect{v} = \\eigenvar^{-1}\\vect{v}$. Thus, $\\eigenvar^{-1}$\n    is an eigenvalue of $A^{-1}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  If $A$ is an $n\\times n$-matrix and $c$ is a non-zero constant,\n  compare the eigenvalues of $A$ and $cA$.\n  \\begin{sol}\n    Say $A\\vect{v}=\\eigenvar \\vect{v}$. Then\n    $cA\\vect{v}=c\\eigenvar \\vect{v}$ and so the eigenvalues of $cA$ are\n    just $c\\eigenvar$ where $\\eigenvar$ is an eigenvalue of $A$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A,B$ be invertible $n\\times n$-matrices which commute. That is,\n  $AB=BA$. Suppose $\\vect{v}$ is an eigenvector of $B$. Show that then\n  $A\\vect{v}$ must also be an eigenvector for $B$.\n  \\begin{sol}\n    Suppose $\\vect{v}$ is an eigenvector of $B$, i.e.,\n    $B\\vect{v}=\\eigenvar \\vect{v}$. Then\n    $BA\\vect{v}=AB\\vect{v} =A\\eigenvar \\vect{v}=\\eigenvar A\\vect{v}$,\n    and therefore $A\\vect{v}$ is an eigenvector of $B$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Suppose $A$ is an $n\\times n$-matrix and it satisfies $A^m=A$ for\n  some $m$ a positive integer larger than 1. Show that if $\\eigenvar$\n  is an eigenvalue of $A$ then $\\eigenvar$ equals either $0$, $1$, or\n  $-1$.\n  \\begin{sol}\n    Let $\\vect{v}$ be the eigenvector. Then\n    $A^m\\vect{v}=\\eigenvar^m\\vect{v}$ and\n    $A^m\\vect{v}=A\\vect{v}=\\eigenvar\\vect{v}$. Therefore\n    $\\eigenvar^m=\\eigenvar$. Hence if $\\eigenvar \\neq 0$, we must\n    have $\\eigenvar^{m-1}=1$, which implies that $\\eigenvar=\\pm 1$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Show that if $A\\vect{v}=\\eigenvar \\vect{v}$ and\n  $A\\vect{w}=\\eigenvar \\vect{w}$, then whenever $k,p$ are scalars,\n  \\begin{equation*}\n    A(k\\vect{v}+p\\vect{w}) =\\eigenvar (k\\vect{v}+p\\vect{w})\n  \\end{equation*}\n  Does this imply that $k\\vect{v}+p\\vect{w}$ is an eigenvector? Explain.\n  \\begin{sol}\n    The formula follows from properties of matrix\n    multiplication. However, this vector might not be an eigenvector\n    because it might equal $0$ and eigenvectors cannot equal $0$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "bdfb19446606fcdaf1e4442cf22298153f36124b", "size": 5336, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Eigenvalues-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Eigenvalues-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.688172043, "max_line_length": 72, "alphanum_fraction": 0.5848950525, "num_tokens": 2164, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267694452331, "lm_q2_score": 0.8824278664544912, "lm_q1q2_score": 0.7666769524801051}}
{"text": "% !TEX root = main.tex\n\n%-------------------------------------------------\n\\section{More transformations}\\label{sec:more_transfs}\n%----------------------------------------------------------------------\n%\\subsection{Standard normal CDF $\\longrightarrow$ Normal CDF}\n%----------------------------------------------------------------------\n\n% example: standard normal\n\\begin{example}\nLet $Z\\sim N(0,1)$. Find the CDF of $X=\\mu+\\sigma Z$ in terms of the CDF of $Z$.\n\\end{example}\n\\begin{solution}\nLet $F_X$ and $F_Z$ respectively denote the CDFs of $X$ and $Z$.\n\\[\nF_X(x)\n\t= \\prob(X\\leq x)\n\t= \\prob(\\mu+\\sigma Z\\leq x)\n\t= \\prob\\left(Z\\leq\\frac{x-\\mu}{\\sigma}\\right)\n\t= F_Z\\left(\\frac{x-\\mu}{\\sigma}\\right).\n\\]\n\\end{solution}\n\n%%----------------------------------------------------------------------\n%\\subsection{Standard normal distribution $\\longrightarrow$ Chi-squared distribution}\n%%----------------------------------------------------------------------\n%----------------------------------------------------------------------\n%\\subsection{Standard normal CDF $\\longrightarrow$ Chi-squared CDF}\n%----------------------------------------------------------------------\n\\begin{example}[The chi-squared distribution]\nLet $X\\sim N(0,1)$. Find the CDF of $Y=X^2$.\n\\end{example}\n\\begin{solution}\nThe PDF of $X\\sim N(0,1)$ is given by $f_X(x) = \\displaystyle\\frac{1}{\\sqrt{2\\pi}}e^{-z^2/2}$. Hence,\n\\[\n\\prob(Y\\leq y) \n\t= \\prob(-\\sqrt{y}\\leq X\\leq \\sqrt{y})\n\t= \\int_{-\\sqrt{y}}^{\\sqrt{y}} f_X(x)\\,dx\n\t= \\frac{2}{\\sqrt{2\\pi}}\\int_0^{\\sqrt{y}} e^{-x^2/2}\\,dx.\n\\]\nUsing a change-of-variable $t=x^2$, we obtain\n\\[\n\\prob(Y\\leq y) \n\t= \\int_0^{y} \\left(\\frac{1}{\\sqrt{2\\pi t}} e^{-t/2}\\right)\\,dt.\n\\]\n\nThis is the CDF of the \\emph{chi-squared} distribution with one degree of freedom.\n\\end{solution}\n\n\n%%----------------------------------------------------------------------\n%%\\subsection{Standard uniform CDF $\\longrightarrow$ Exponential CDF}\n%%----------------------------------------------------------------------\n%% example: uniform to exponential(1)\n%\\begin{example}\n%Let $X\\sim\\text{Uniform}[0,1]$, and let $Y = -\\theta\\log X$ where $\\theta>0$. Show that $Y\\sim\\text{Exponential}(\\theta)$, where $\\theta$ is a scale parameter.\n%\\end{example}\n%\\begin{solution}\n%Consider the transformation $g(x) = -\\theta\\log x$.\n%\\bit\n%\\it The CDF of $X$ is $F_X(x) = x$ for $x\\in[0,1]$ (with $F_X(x)=0$ for $x<0$, and $F_X(x)=1$ for $x>1$).\n%\\it The PDF of $X$ is $f_X(x) = 1$ for $x\\in[0,1]$ (and zero otherwise).\n%\\it $g(x)$ is a decreasing function (and thus has a unique inverse) over $\\supp(f_X) = [0,1]$.\n%\\it The support of $f_Y$ is $\\supp(f_Y) = \\{g(x) : x\\in\\supp(f_X)\\} = [0,\\infty)$.\n%\\it The inverse transformation is $g^{-1}(y) = e^{-y/\\theta}$ over $\\supp(f_Y)$.\n%\\eit\n%By Theorem~\\ref{thm:transf_cdf},\n%\\[\n%F_Y(y) \n%\t= 1 - F_X\\big[g^{-1}(y)\\big]\n%\t= 1 - F_X(e^{-y/\\theta})\n%\t= 1 - e^{-y/\\theta} \\quad\\text{for}\\quad y>0.\n%\\]\n%This is the CDF of the $\\text{Exponential}(\\theta)$ distribution, where $\\theta$ is a scale parameter.\n%\\end{solution}\n\n%----------------------------------------------------------------------\n%\\subsection{Exponential CDF $\\longrightarrow$ Pareto CDF}\n%----------------------------------------------------------------------\n\n% example: exponential to pareto\n\\begin{example}\nLet $X\\sim\\text{Exponential}(\\alpha)$ where $\\alpha$ is a rate parameter, and let $Y=\\theta e^X$, where $\\theta>0$ is a constant. Show that $Y$ has the so-called $\\text{\\emph{Pareto}}(\\theta,\\alpha)$ distribution, whose CDF is given by\n\\[\nF_Y(y)= \\begin{cases}\n\t\t1 - \\left(\\frac{\\theta}{y}\\right)^{\\alpha}\t& \\text{for } y > \\theta \\\\\n\t\t0\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n\t\\end{cases}\t\n\\]\n\\end{example}\n\n\\begin{solution}\nConsider the transformation $g(x) = \\theta e^x$.\n\\bit\n\\it The CDF of $X$ is $F_X(x) = 1 - e^{-\\alpha x}$ for $x>0$ (and zero otherwise).\n\\it $\\supp(f_X) = [0,\\infty)$.\n\\it $\\supp(f_Y) = \\{\\theta e^x: x\\geq 0\\} = [\\theta,\\infty)$.\n\\it $g(x)$ is an increasing function over $\\supp(f_X)$;\n\\it the inverse transformation is $g^{-1}(y) = \\log(y/\\theta)$.\n\\eit\nBy Theorem~\\ref{thm:transf_cdf},\n\\[\nF_Y(y)\n\t= F_X\\left[\\log \\left(\\frac{y}{\\theta}\\right)\\right]\n\t= 1 - \\exp\\left[-\\alpha\\log \\left(\\frac{y}{\\theta}\\right)\\right]\n\t= \\begin{cases}\n\t\t1 - \\displaystyle\\left(\\frac{\\theta}{y}\\right)^{\\alpha}\t& \\text{for } y > \\theta, \\\\[2ex]\n\t\t0\t\t\t\t\t& \\text{otherwise.}\n\t\\end{cases}\t\n\\]\nas required.\n\n\\bigskip\\textbf{Remark:}\n%\\begin{remark}\nCompare the upper-tail probabilities of $X\\sim\\text{Exponential}(\\alpha)$ and $Y\\sim\\text{Pareto}(\\theta,\\alpha)$:\n%\\begin{align*}\n%\\prob(X > x) & = e^{-\\alpha x} \\\\\n%\\prob(Y > y) & = \\theta^{\\alpha} y^{\\alpha}\n%\\end{align*}\n\\[\n\\prob(X > x) = e^{-\\alpha x}\n\\qquad\\text{and}\\qquad\n\\prob(Y > y) = \\theta^{\\alpha} y^{-\\alpha}.\n\\]\nIn both cases, the rate at which the tail probabilities converge to zero is controlled by the parameter $\\alpha$. We can see however that $\\prob(X>x)\\to 0$ relatively quickly as $x\\to\\infty$, the rate of convergence depending ``exponentially'' on $x$, while $\\prob(Y>y)\\to 0$ more slowly as $y\\to\\infty$, with the rate of convergence depending ``polynomially'' on $y$.\n%\\eit\n%\\bit\n%\\it $\\prob(X>x) \\to 0$ at an exponential rate as $x\\to\\infty$, while\n%\\it $\\prob(Y>y) \\to 0$ at only a polynomial rate as $y\\to\\infty$.\n%\\eit\nConsequently, the Pareto distribution belongs to the class of so-called \\emph{heavy-tailed} distributions.\n%\\end{remark}\n\\end{solution}\n\n%----------------------------------------------------------------------\n%\\subsection{Normal PDF $\\longrightarrow$ Standard normal PDF}\n%----------------------------------------------------------------------\n\n% example: standard normal\n\\begin{example}[The standard normal distribution]\nLet $X\\sim N(\\mu,\\sigma^2)$, and define $Z=(X-\\mu)/\\sigma$. Find the PDF of $Z$.\n\\end{example}\n\\begin{solution}\nLet $g(X) = \\displaystyle \\frac{X-\\mu}{\\sigma}$. \n\\bit\n\\it The PDF of $X$ is $f_X(x) = \\displaystyle\\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right]$.\n\\it Because $\\sigma>0$, we see that $g(x)$ is increasing over $\\supp(f_X) = (-\\infty,\\infty)$.\n\\it $g(x)$ has inverse function $g^{-1}(z) = \\mu + \\sigma z$, whose first derivative is $\\displaystyle\\frac{d}{dz}g^{-1}(z) = \\sigma$.\n\\eit\nThe PDF of $Z$ is therefore given by\n\\begin{align*}\nf_Z(z)\n\t& = f_X\\big[g^{-1}(z)\\big]\\left|\\frac{d}{dz}g^{-1}(z)\\right| \\\\\n\t& = \\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{(\\mu+\\sigma z)-\\mu}{\\sigma}\\right)^2\\right]\\sigma\n\t  = \\frac{1}{\\sqrt{2\\pi}}e^{-z^2/2}\n\\end{align*}\n\\end{solution}\n\n%----------------------------------------------------------------------\n%\\subsection{Pareto PDF $\\longrightarrow$ Standard uniform PDF}\n%----------------------------------------------------------------------\n\n\n%% example: pareto\n%\\begin{example}[The Pareto distribution]\n%The $\\text{Pareto}(\\theta,\\alpha)$ distribution is a continuous distribution with PDF\n%\\[\n%f_X(x) = \\begin{cases}\n%\t\\displaystyle\\frac{\\alpha}{\\theta}\\left(\\frac{\\theta}{x}\\right)^{\\alpha+1}\t\t& \\text{for } x > \\theta, \\\\[2ex]\n%\t0\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t& \\text{otherwise.}\n%\\end{cases}\n%\\]\n%Let $X\\sim\\text{Pareto}(1,1)$. Find the PDF of $Y=1/X$.%\\displaystyle\\frac{1}{X}$.\n%\\end{example}\n%\n%\\begin{solution}\n%$X\\sim\\text{Pareto}(1,1)$ has PDF \n%\\[\n%f_X(x) = \\displaystyle\\frac{1}{x^2} \\quad\\text{for $x>1$ (and zero otherwise)}.\n%\\]\n%\n%Let $g(x) = 1/x$. \n%\\bit\n%\\it $g(x)$ is a monotonic decreasing function over $x>1$. \n%\\it The inverse function is $g^{-1}(y) = 1/y$.\n%\\it $\\supp(f_Y) = \\{g(x): x\\in\\supp(f_X)\\} = \\{1/x :x\\in(0,\\infty)\\} = (0,1)$.\n%\\eit\n%%\n%%\n%%\\it The support of $Y$ can be determined as follows:\n%%\\begin{align*}\n%%\\supp(f_X) = (0,\\infty)\n%%\t\\Rightarrow 1 < X < \\infty \n%%\t\\Rightarrow 1 < \\frac{1}{Y} < \\infty \n%%\t\\Rightarrow 0 < Y < 1\n%%\t\\Rightarrow \\supp(f_Y) = (0,1). \n%%\\end{align*}\n%%\\eit\n%\n%Hence the PDF of $Y$ is given by\n%\\begin{align*}\n%f_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*}\n%Thus $Y$ has the standard uniform distribution.\n%\\end{solution}\n\n\n%----------------------------------------------------------------------\n%\\subsection{Normal PDF $\\longrightarrow$ Lognormal PDF}\n%----------------------------------------------------------------------\n\n\n% example: lognormal\n\\begin{example}[The lognormal distribution]\nIf $X\\sim(\\mu,\\sigma^2)$, then $Y=e^X$ is said to have \\emph{lognormal} distribution. Find the PDF of $Y$.\n\\end{example}\n\\begin{solution}\nLet $g(X) = e^X$. \n\\bit\n\\it Recall that $f_X(x) = \\displaystyle\\frac{1}{\\sigma\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{x-\\mu}{\\sigma}\\right)^2\\right]$.\n\\it $g(x)$ is an increasing function over $\\supp(f_X) = (-\\infty,\\infty)$.\n\\it $g(x)\\in[0,\\infty]$ for $x\\in\\R$ so $\\supp(f_Y) = [0,\\infty)$.\n\\it $g(x)$ has inverse function $g^{-1}(y) = \\log y$, for which $\\displaystyle \\frac{d}{dy}g^{-1}(y) = \\frac{1}{y}$.\n\\eit\nThus\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(\\log y)\\left|\\frac{1}{y}\\right| \n\t=  \\frac{1}{y\\sigma\\sqrt{2\\pi}}\\exp\\left[-\\frac{1}{2}\\left(\\frac{\\log y-\\mu}{\\sigma}\\right)^2\\right]\n\\end{align*}\nfor $y>0$, and zero otherwise.\n\\end{solution}\n\n\n%----------------------------------------------------------------------\n%\\subsection{Lomax PDF $\\longrightarrow$ Logistic CDF}\n%----------------------------------------------------------------------\n\n\n% example: pareto - logistic\n\\begin{example}[The logistic distribution]\nThe $\\text{Lomax}(\\theta,\\alpha)$ distribution, also known as the Pareto Type II distribution or the shifted Pareto distribution, is a continuous distribution with PDF\n\\[\nf_X(x) = \\frac{\\alpha}{\\theta}\\left(1+\\frac{x}{\\theta}\\right)^{-(\\alpha+1)}\t\\quad\\text{for $x > 0$ and zero otherwise.}\n\\]\nLet $X\\sim\\text{Lomax}(1,1)$. Show that the CDF of $Z = \\log X$ is given by\n\\[\nF_Z(z) =  \\frac{e^z}{1+e^z}.\n\\]\nThis is the CDF of the \\emph{standard logistic distribution}.\n\\end{example}\n\\begin{solution}\nTaking $\\alpha=1$ and $\\theta=1$, the PDF of $X$ is \n\\[\nf_X(x) = \\frac{1}{(1 + x)^2}\n\\]\nConsider the transformation $g(x) = \\log x$.\n\\bit\n\\it $g(x)$ is an increasing function over $\\supp(f_X)=(0,\\infty)$.\n\\it $\\supp(f_Z) = \\{g(x):x\\in\\supp(f_X)\\} = \\{\\log x: x\\in(0,\\infty)\\} = (-\\infty,\\infty)$.\n\\it The inverse transformation is  $g^{-1}(z) = e^z$, and its first derivative is $\\displaystyle\\frac{d}{dz}g^{-1}(z) = e^z$.\n\\eit\nThe PDF of $Z = \\log X$ is therefore given by\n\\[\nf_Z(z) = f_X\\big[g^{-1}(z)\\big]\\left|\\frac{d}{dz}g^{-1}(z)\\right| = \\frac{e^z}{(1+e^z)^2},\n\\]\nfrom which we the required CDF follows by integration.\n%This is the PDF of the \\emph{standard logistic distribution}. \n%Its CDF if given by $\\displaystyle F_Z(z) = \\frac{e^z}{(1+e^z)}$.\n\\end{solution}\n\n", "meta": {"hexsha": "aae351556879ca2e7dd3336dc8c8a2ee92d18bff", "size": 10918, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/03D_examples_of_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/03D_examples_of_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/03D_examples_of_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": 38.9928571429, "max_line_length": 368, "alphanum_fraction": 0.552207364, "num_tokens": 3700, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.882427857178614, "lm_q2_score": 0.8688267762381844, "lm_q1q2_score": 0.7666769504152643}}
{"text": "\\section{Cubic Spline Interpolation}\n\\begin{defn}\nGiven a function $f$ defined on $[a,b]$, $a=x_0<x_1<\\cdots,<x_n=b$, a cubic spline interpolation $S$ for $f$ is a function that satisfies the following conditions.\n\\begin{enumerate}\n    \\item $S_j(x)$ is a cubic polynomial, on the subinterval $[x_j,x_{j+1}]$ for $j=0:n-1$.\n    \\item $S_j(x_j)=f(x_j)$, $S_j(x_{j+1})=f(x_{j+1})$ for $j=0:n-2$.\n    \\item $S'_j(x_{j+1})=S'_{j+1}(x_{j+1})$ for $j=0:n-2$.\n    \\item $S''_j(x_{j+1})=S''_{j+1}(x_{j+1})$ for $j=0:n-2$.\n    \\item $\\begin{cases}\n          \\text{natural boundary:} & S''(x_0)=S''(x_n)=0. \\\\\n          \\text{clamped boundary:} & S'(x_0)=f'(x_0)$, $S'(x_n)=f'(x_n).\n          \\end{cases}$\n\\end{enumerate}\n\\end{defn}\n\\subsection{Construction of a Cubic Spline}\nLet $h_j=x_{j+1}-x_j$ (forward):\n\\begin{enumerate}[(1)]\n    \\item \\begin{align*}\n          S_j(x) &= a_j+b_j(x-x_j)+c_j(x-x_j)^2+d_j(x-x_j)^3\\quad\\text{for $j=0:n-1$} \\\\\n          &\\Rightarrow a_{j+1}=S_{j+1}(x_{j+1})=S_j(x_{j+1}) \\\\\n          &\\hspace{1.3cm}=a_j+b_jh_j+c_jh_j^2+d_jh_j^3=f(x_{j+1})\\quad\\text{for $j=0:n-1$}\n          \\end{align*}\n    \\item \\begin{align*}\n          S'_j(x) &= b_j+2c_j(x-x_j)+3d_j(x-x_j)^2 \\\\\n          &\\Rightarrow b_{j+1}=S'_{j+1}(x_{j+1})=S'_j(x_{j+1}) \\\\\n          &\\hspace{1.3cm}=b_j+2c_jh_j+3d_jh_j^2\\quad\\text{for $j=0:n-1$}\n          \\end{align*}\n    \\item \\begin{align*}\n          S''_j(x) &= 2c_j+6d_j(x-x_j) \\\\\n          &\\Rightarrow 2c_{j+1}=S''_{j+1}(x_{j+1})=S''_j(x_{j+1}) \\\\\n          &\\hspace{1.3cm}=2c_j+6d_jh_j\\quad\\text{for $j=0:n-1$}\n          \\end{align*}\n\\end{enumerate}\n\nAbove all, the linear system to be solved is:\n\\begin{align*}\n    &Ax=b \\\\\n    &\\begin{cases}\n    A=diag([1,2(h_0+h_1),\\cdots,2(h_{n-2}+h_{n-1}),1]) \\\\\n    \\phantom{A=}+diag([0,h_1,\\cdots,h_{n-1}],1)+diag([h_0,\\cdots,h_{n-2},0],-1) \\\\\n    x = [c_0;c_1;\\cdots;c_n] \\\\\n    b = \\left[0;\\frac{3}{h_1}(a_2-a_1)-\\frac{3}{h_0}(a_1-a_0);\\cdots;\\frac{3}{h_{n-1}}(a_n-a_{n-1})-\\frac{3}{h_{n-2}}(a_{n-1}-a_{n-2});0\\right] \\\\\n    \\end{cases}\n\\end{align*}\nThen we will get $b_j$, $d_j$ by\n\\begin{equation*}\n    \\begin{cases}\n    b_j &= \\frac{1}{h_j}(a_{j+1}-a_j)-\\frac{h_j}{3}(2c_j+c_{j+1}) \\\\\n    d_j &= \\frac{1}{3h_j}(c_{j+1}-c_j)\n    \\end{cases}\n\\end{equation*}\n\n\\subsection{Clamped Splines}\n\\begin{align*}\n    &Ax=b \\\\\n    &\\begin{cases}\n    A=\\begin{pmatrix}\n      2h_0 & h_0 & 0 & \\cdots & 0 \\\\\n      h_0 & 2(h_0+h_1) & h_1 & \\ddots & \\vdots \\\\\n      0 & h_1 & 2(h_1+h_2) & \\ddots & \\vdots \\\\\n      \\vdots & \\ddots & \\ddots & \\ddots & h_{n-1} \\\\\n      0 & \\cdots & \\cdots & h_{n-1} & 2h_{n-1} \\\\\n      \\end{pmatrix} \\\\\n    \\\\\n    x = \\begin{pmatrix}c_0 & c_1 & \\cdots & c_n \\end{pmatrix}^T \\\\\n    \\\\\n    b = \\begin{pmatrix}\n        \\frac{3}{h_0}(a_1-a_0)-3f'(a) \\\\\n        \\frac{3}{h_1}(a_2-a_1)-\\frac{3}{h_0}(a_1-a_0) \\\\\n        \\vdots \\\\\n        \\frac{3}{h_{n-1}}(a_n-a_{n-1})-\\frac{3}{h_{n-2}}(a_{n-1}-a_{n-2}) \\\\\n        3f'(b)-\\frac{3}{h_{n-1}}(a_n-a_{n-1})\n        \\end{pmatrix}\n    \\end{cases}\n\\end{align*}", "meta": {"hexsha": "98d8ecb226a0e27d24d61920c5246d7fc630f552", "size": 3001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/sections/3.5_Cubic_spline_interpolation.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/3.5_Cubic_spline_interpolation.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/3.5_Cubic_spline_interpolation.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": 40.0133333333, "max_line_length": 163, "alphanum_fraction": 0.5254915028, "num_tokens": 1421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7666621831576558}}
{"text": "\\section{Measurement Uncertainty Analysis}\n\n\n\\subsection{Uncertainty of instruments}\nFor a single measurement of the mass of the experiment setup, the uncertainty of the measurement instruments are\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabularx}{\\textwidth}{|X|X|X|X|}\n    \\hline\n     & Calliper & Electronic balance & Timer\\\\\n\t \\hline\n\t Resolution & 0.002cm & 0.1g & 0.0001s \\\\\n\t \\hline\n\t Relative uncertainty &\\multicolumn{2}{c|}{}& 0.004\\% \\\\\n\t\\hline\n  \\end{tabularx}\n  \\caption{Precision of the measurement instruments}\n  \\end{table}\n\n\\subsection{Uncertainty of Calliper Measurements}\n\nIn order to estimate type–A uncertainty of the period, the standard deviation of the average value is calculated as\n$$  s_d = \\sqrt{\\frac{1}{n-1}\\sum_{i=1}^{n}(d_i - \\bar{d})^2 }  $$\n\nThus, the standard deviation of the average value is calculated and shown below\n\n\\begin{table}[H]\n  \\centering\n  \\begin{tabularx}{\\textwidth}{|p{6cm}|X|}\n    \\hline\n    Object & The standard deviation\\\\\n    \\hline\n    Disk $[cm]$& 0.0020 \\\\\n    Hoop 1 $[cm]$& 1.1003 \\\\\n    Hoop 2 $[cm]$& 1.1017 \\\\\n    Cylinder A $[cm]$& 0 \\\\\n    Cylinder B $[cm]$& 0 \\\\\n    Cone pulley $[cm]$& 0.0075 \\\\\n    \\hline\n  \\end{tabularx}\n  \\caption{The standard deviation}\n  \\end{table}\n\n\nThe uncertainty of Timer is $\\pm 0.0001s $ and $\\pm 0.004\\%$\n\nFrom the equation to calculate the moment of inertia,\n$$ I_1=\\frac{mR(g-R\\beta_2)}{\\beta_2-\\beta_1} $$\n$$ u_F = \\sqrt{(\\frac{\\partial I}{\\partial m})^2(u_m)^2 +   (\\frac{\\partial I}{\\partial R})^2(u_R)^2+(\\frac{\\partial I}{\\partial \\beta_1 })^2(u_{\\beta_1})^2+ (\\frac{\\partial I}{\\partial \\beta_2})^2(u_{\\beta_2})^2   }$$\n\n$$\\frac{\\partial I}{\\partial m} = \\frac{R\\left(g-\\beta _2 R\\right)}{\\beta _2-\\beta _1} $$\n$$\\frac{\\partial I}{\\partial R} = -\\frac{\\beta _2 m R'\\left(g-\\beta _2 R\\right)}{\\beta _2-\\beta _1} $$\n$$\\frac{\\partial I}{\\partial \\beta_1} = \\frac{m R\\left(g-\\beta _2 R\\right)}{\\left(\\beta _2-\\beta _1\\right){}^2} $$\n$$\\frac{\\partial I}{\\partial \\beta_2} = -\\frac{m R R'\\left(g-\\beta _2 R\\right)}{\\beta _2-\\beta _1}-\\frac{m R\\left(g-\\beta _2 R\\right)}{\\left(\\beta _2-\\beta _1\\right){}^2} $$\n\n\n$$ u_m = 0.1 g $$\n$$ u_R = 0.0075 cm $$\n$$ u_{\\beta_1} = \\sqrt{(0.0001 s)^2+(0.0001 \\times 95 \\% )^2} =0.000137931 $$\n$$ u_{\\beta_1} = \\sqrt{(0.0001 s)^2+(0.0001 \\times 95 \\% )^2} =0.000137931 $$\n\nThus, \n$$u_{rF} =  0.4\\%$$\n", "meta": {"hexsha": "e07fcb15f147c31236b235d523eb8f57822bc2b0", "size": 2337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E1/part/uncertainty.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E1/part/uncertainty.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E1/part/uncertainty.tex", "max_forks_repo_name": "iamwrm/VP141", "max_forks_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.9538461538, "max_line_length": 218, "alphanum_fraction": 0.6281557552, "num_tokens": 902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.927363293639213, "lm_q2_score": 0.8267118004748677, "lm_q1q2_score": 0.7666621781787772}}
{"text": "\\subsection{Partial Derivatives of X, Y, and Z}\r\n\\noindent\r\nIt's common to look at the derivative when slicing a surface in the yz, xz, and xy planes. These are called partial derivatives.\\\\\r\n\r\n\\noindent\r\nTo compute $\\frac{\\partial}{\\partial x}{f(x,y)}$, we take the derivative with respect to $x$ as if $y$ is constant. Formally,\r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial x}f(x,y) = \\lim_{h \\to 0}{\\frac{f(x+h,y)-f(x,y)}{h}}\r\n\\end{equation*} \r\nand \r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial y}f(x,y) = \\lim_{h \\to 0}{\\frac{f(x,y+h)-f(x,y)}{h}}\r\n\\end{equation*}\r\n\r\n\\noindent\r\nWe also use the shorthand $\\frac{\\partial}{\\partial x}=f_x$ and $\\frac{\\partial}{\\partial y}=f_y$. This shorthand can be extended to higher-order derivatives so that $\\frac{\\partial}{\\partial y}\\left(\\frac{\\partial}{\\partial x}f(x,y)\\right)=f_{xy}$.\r\n\r\n\\noindent\r\n\\textbf{Fubini's Theorem} (also called Tonelli's or Clairaut's Theorem) says $f_{xy} = f_{yx}$, $f_{xz} = f_{zx}$, and $f_{yz} = f_{zy}$. It extends into higher-order mixed partial derivatives, saying that two mixed partial derivatives of a function are equal as long as they both differentiate the same number of variables the same number of times. So, $f_{abcdab} = f_{aacdbb}$.", "meta": {"hexsha": "e74e7b5d992fc69b5c58acfeb5b6ceecd9857e52", "size": 1228, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/partialDerivativesXYZ.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/partialDerivativesXYZ.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/partialDerivativesXYZ.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.6315789474, "max_line_length": 380, "alphanum_fraction": 0.6913680782, "num_tokens": 395, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8221891348788759, "lm_q1q2_score": 0.7666529777835442}}
{"text": "\\section{Spectrum of Autoregressive Processes}\n\n\\begin{enumerate}[label=\\alph*), leftmargin=*]\n%% a)\n\\item\n%\n\nA $p$ order Autoregressive process with parameters $\\va \\in \\sR^{p}$ satisfies the Yule-Walker (or normal) equation:\n\n\\begin{equation}\n    \\vr_{xx} = \\mathbf{R}_{xx} \\va \\Rightarrow \\va = \\mathbf{R}_{xx}^{-1} \\vr_{xx}\n    \\label{eq:yule-walker}\n\\end{equation}\n\nwhere $\\mathbf{R}_{xx}$ the autocorrelation matrix (ACF) of signal $x(n)$. Equation (\\ref{eq:yule-walker}) is meaningful for non-singular and thus invertible $\\mathbf{R}_{xx}$.\nThe biased estimator of ACF guarantees positive semi-definiteness and as a result the $\\mathbf{R}_{xx}$ can be inverted, providing solutions for the autoregressive parameters $\\va$.\nOn the other hand, as depicted in figure \\ref{fig:2_1_a}, the unbiased ACF estimator leads to indefiniteness and thus $\\mathbf{R_{xx}}$ may be singular.\n\n%% b)\n\\item\n%\n\nThe power spectral density of an AR process with parameters $\\va = [2.76,\\ -3.81,\\ 2.65,\\ -0.92]$ in Guassian white noise ($\\sigma^{2} = 1$) is estimated using different AR model order\n$p = 2,\\ 3,\\ \\ldots,\\ 14$. As illustrated in figure \\ref{fig:2_2_b_1}, low order models (i.e $p=2$) fail to capture the behaviour of the process, identifying a single peak in the spectrum,\nwhile two are expected. Higher order models (i.e $p=9$) provide better estimates, able to find the two peaks.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/ar_2}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/ar_4}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/ar_9}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/ar_14}\n    \\end{subfigure}\n    \\caption{AR: spectrum estimates and model order $p$ with $N=500$ samples.}\n    \\label{fig:2_2_b_1}\n\\end{figure}\n\nIntuitively, the larger the model order $p$, the more degrees of freedom available to capture the nature of the process.\nIn figure \\ref{fig:2_2_b_2} the noise power (mean squared prediction error) is illustrated as a function of model order $p$.\nUnsurprisingly, the error decreases for increasing model order though it plateaus for $p \\leq 9$. As a result, to minimize model complexity and avoid fitting error (overfitting)\nmodel order $p = 9$ is selected.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/error}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/b/aic}\n    \\end{subfigure}\n    \\caption{AR: noise power and model order $p$ with $N=500$ samples.}\n    \\label{fig:2_2_b_2}\n\\end{figure}\n\nWe also highlight that despite the fact that $p_{original} = 4$, due to the small number of available sample ($N = 500$),\nwhen $p = 4$ is selected the fitted model performs very poorly, thus either the number of samples should be increased or a higher order model should be used instead.\n\n%% c)\n\\item\n%\n\nThe experiment is repeated for the same AR process, but using $N = 10000$ samples and figures \\ref{fig:2_2_c_1} and \\ref{fig:2_2_c_2} are obtained.\nWhen $p < p_{original} = 4$, the model still does not have the capacity to model the process (under-modelling) while for $p > p_{original} = 4$ the error plateaus.\nDespite the fact that AR(4) model identifies the two peaks, we note that AR(5) and all higher order models track spectrum much better. To avoid overfitting the noise\nand preserve generalisation of the model, criteria such as the Akaike Information Criterion (AIC) or the Bayesian Information Criterion can be used to penalise higher order models.\nAccording to the AIC, AR(4) model is selected for this experiment, agreeing with the true model order.\n\n\\begin{figure}[h]\n    \\centering\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/ar_3}\n    \\end{subfigure}\n    ~ \n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/ar_4}\n    \\end{subfigure}\n    ~\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/ar_5}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/ar_9}\n    \\end{subfigure}\n    \\caption{AR: spectrum estimates and model order $p$ with $N=10000$ samples.}\n    \\label{fig:2_2_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/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/error}\n    \\end{subfigure}\n    ~\n    \\begin{subfigure}{0.49\\textwidth}\n        \\centering\n        \\includegraphics[height=1.5in]{report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/assets/c/aic}\n    \\end{subfigure}\n    \\caption{AR: soise power and model order $p$ with $N=10000$ samples.}\n    \\label{fig:2_2_c_2}\n\\end{figure}\n\n%\n\\end{enumerate}", "meta": {"hexsha": "6470293878ffa0df853060eebddaa72a8b4d5bde", "size": 6015, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/report/parametric-and-line-spectra/spectrum-of-autoregressive-processes/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/parametric-and-line-spectra/spectrum-of-autoregressive-processes/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/parametric-and-line-spectra/spectrum-of-autoregressive-processes/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": 46.9921875, "max_line_length": 188, "alphanum_fraction": 0.7185369909, "num_tokens": 1777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711604559846, "lm_q2_score": 0.9019206659843131, "lm_q1q2_score": 0.7666065551059211}}
{"text": "\\section{Eigen analysis and spectral smoothing}\n\nFor a smoother with symmetric smoother matrix $\\bS$, the\neigendecomposition of $\\bS$ can be used to describe its\nbehavior. \n\n\nLet $\\{ \\bu_1,\\dots,\\bu_n \\}$ be an orthonormal basis of eigenvectors\nof $\\bS$ with eigenvalues $\\theta_1\\geq\\theta_2\\dots\\geq\\theta_n$:\n\\[\n\\bS\\bu_j = \\theta_j \\bu_j, j=1,\\dots,n\n\\]\nor\n\\[\n\\bS=\\bU \\bD \\bU' = \\sum_{j=1}^n \\theta_j \\bu_j \\bu_j'.\n\\]\nHere $\\bD$ is a diagonal matrix with the eigenvalues as the entries.\n\nFor simple linear regression we only have two nonzero\neigenvalues. Their eigenvectors are an orthonormal basis for lines.\n\n\\begin{figure}[htb]\n  \\caption{Eigenvalues and eigenvectors of the hat matrix for linear\n    regression.}\n\\begin{center}\n\\epsfig{figure=Plots/plot-06-04.ps,angle=270,width=.75\\textwidth}\n\\end{center}\n\\end{figure}\n\n\n\nThe cubic spline is an important example of a symmetric smoother, and\nits eigenvectors resemble polynomials of increasing degree.\n\nIt is easy to show that the first two eigenvalues are unity, with\neigenvectors which correspond to linear functions of the predictor on\nwhich the smoother is based. One can also show that the other\neigenvalues are all strictly between zero and one. \n\nThe action of the smoother is now transparent: if presented with a\nresponse $\\by = \\bu_j$, it shrinks it by an amount $\\theta_j$ as\nabove. \n\n\n\\begin{figure}[htb]\n\\caption{\\label{f6.3.1} Eigenvalues and eigenvectors 1 through 10 of\n  $\\bS$ for a smoothing spline.} \n\\begin{tabular}{cc}\n\\epsfig{figure=Plots/plot-06-05.ps,angle=270,width=.5\\textwidth}&\n\\epsfig{figure=Plots/plot-06-06.ps,angle=270,width=.5\\textwidth}\n\\end{tabular}\n\\end{figure}\n\n\n\nCubic smoothing splines, regression splines, linear regression,\npolynomial regression are all symmetric smoothers. However, loess \nand other ``nearest neighbor'' smoothers are not. \n\n\n\n\n\\begin{figure}[htb]\n\\caption{Eigen vectors 11 through 30 for a smoothing spline for\n$n=30$.}\n\\begin{tabular}{cc}\n\\epsfig{figure=Plots/plot-06-07.ps,angle=270,width=.5\\textwidth}&\n\\epsfig{figure=Plots/plot-06-08.ps,angle=270,width=.5\\textwidth}\n\\end{tabular}\n\\end{figure}\n\nIf $\\bS$ is not symmetric we have complex eigenvalues and the above\ndecomposition is not as easy to interpret. However we can use the\nsingular value decomposition \n\\[\n\\bS = \\bU \\bD \\bV'\n\\]\n\nOn can think of smoothing as performing a basis transformation $\\bz =\n\\bV'\\by$, shrinking with $\\hat{\\bz} = \\bD\\bz$ the components that are\nrelated to ``unsmooth components'' and then transforming back to the\nbasis $\\hat{\\by} = \\bU \\hat{\\bz}$ we\nstarted out with... sort of.\n\n\nIn signal processing signals are ``filtered'' using linear\ntransformations. The transfer function describes how the power of\ncertain frequency components are reduced. A low-pass filter will\nreduce the power of the higher frequency components. \nWe can view the eigen values of our\nsmoother matrices as transfer functions.\n\n\nNotice that the smoothing spline can be considered a low-pass\nfilter. If we look at the eigenvectors of the smoothing spline we\nnotice they are similar to sinusoidal components of increasing\nfrequency. Figure \\ref{f6.3.1} shows the ``transfer function'' defined\nby the smoothing splines.\n\n\n\nThe change of basis idea described above has been explored by Donoho\nand Johnston 1994, 1995) and  Beran\n(2000). In the following section we give a short introduction to these\nideas.  \n", "meta": {"hexsha": "58e2223b0de40a8656a15e7da5c87c48a6576615", "size": 3382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-06-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-06-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-06-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": 31.9056603774, "max_line_length": 70, "alphanum_fraction": 0.7596096984, "num_tokens": 955, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8840392832736083, "lm_q1q2_score": 0.766493677742781}}
{"text": "\n\\subsection{Introduction}\n\n\\(m_{11}x+m_{12}y+m_{13}z=v_1\\)\n\n\\(m_{21}x+m_{22}y+m_{23}z=v_2\\)\n\n\\(m_{31}x+m_{32}y+m_{33}z=v_3\\)\n\n\n\\subsection{Matrix and vector notation}\n\nWe can write the above as:\n\n\\(\\mathbf{M}x=\\mathbf{v}\\)\n\nWhat are the properties of \\(\\mathbf{M}\\) and \\(\\mathbf{v}\\)?\n\nThey are linear in addition and scalar multiplication.\n", "meta": {"hexsha": "a5feda748d9b4a734c86625cb6903d77d79b69ec", "size": 343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/01-01-systems.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/linearSystems/01-01-systems.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/linearSystems/01-01-systems.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.15, "max_line_length": 61, "alphanum_fraction": 0.667638484, "num_tokens": 130, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9572778024535095, "lm_q2_score": 0.8006919997179627, "lm_q1q2_score": 0.7664846779321173}}
{"text": "%!TEX root = ../Thesis.tex\n\\chapter{Detailed Derivation: Coordinate Velocity Transform} \\label{app:coordinate-transform}\nRecall $(\\mathscr{X},\\mathscr{Y})$ is the inertial frame coordinates and $(x,y)$ is the rotating frame coordinates \\ref{fig:r3b}. The goal is to go from $\\mathscr{X}(x,y)$ and $\\mathscr{Y}(x,y)$ to $(\\dot{\\mathscr{X}}^2 + \\dot{\\mathscr{Y}}^2)(x,y)$. This is used in \\eqref{eq:r3b-T} to obtain the kinetic energy $T(x,y)$ From equation \\eqref{eq:coordinate-transform} we had\n\\begin{align}\n\\notag\n\\begin{cases}\n\\ \\mathscr{X} = x\\cos{\\omega t} - y\\sin{\\omega t} \\\\\n\\ \\mathscr{Y} = x\\sin{\\omega t} + y\\cos{\\omega t}\n\\end{cases}\n\\end{align}\nTaking the time derivative we get\n\\begin{align}\n\\begin{cases}\n\\ \\dot{\\mathscr{X}} = \\dot{x}\\cos{\\omega t} - \\dot{y}\\sin{\\omega t} - \\omega x\\sin{\\omega t} - \\omega y\\cos{\\omega t} \\\\\n\\ \\dot{\\mathscr{Y}} = \\dot{x}\\sin{\\omega t} + \\dot{y}\\cos{\\omega t} + \\omega x\\cos{\\omega t} - \\omega y\\sin{\\omega t}\n\\end{cases}\n\\end{align}\nWe'll take the squares, but first, to get a good overview of the terms, we note that $\\dot{\\mathscr{X}}^2$ matches\n\\begin{align}\n\\begin{split}\n\\label{eq:algebra}\n&(a-b-c-d)^2 \\\\\n&= a^2 + b^2 +c^2 +d^2 \\\\\n&- 2 a b -2 a c - 2 a d \\\\\n&+ 2 b c + 2 b d + 2 c d\n\\end{split}\n\\end{align}\nNow we take the squares, align the terms as in \\eqref{eq:algebra} and note what terms add and cancel in the sum $\\mathscr{X}^2 + \\mathscr{Y}^2$:\n\\begin{align}\n\\begin{split}\n\\dot{\\mathscr{X}}^2 &= (\\dot{x}\\cos{\\omega t} - \\dot{y}\\sin{\\omega t} - \\omega x\\sin{\\omega t} - \\omega y\\cos{\\omega t})(\\dot{x}\\cos{\\omega t} - \\dot{y}\\sin{\\omega t} - \\omega x\\sin{\\omega t} - \\omega y\\cos{\\omega t}) \\\\\n&=\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\dot{x}^2\\cos^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\dot{y}^2\\sin^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\omega^2 x^2\\sin^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\omega^2 y^2\\cos^2{t}$};\n} \\\\\n&-\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\dot{x}\\dot{y}\\cos{\\omega t}\\sin{\\omega t}$};\n} -\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega x \\dot{x} \\cos{\\omega t}\\sin{\\omega t}$};\n} -\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$2 \\omega \\dot{x}y\\cos^2{t}$};\n} \\\\\n&+\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$2 \\omega x \\dot{y}\\sin^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega y \\dot{y}\\cos{\\omega t}\\sin{\\omega t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega^2 x y \\cos{\\omega t}\\sin{\\omega t}$};\n}\n\\end{split}\n\\end{align}\nLikewise $\\dot{\\mathscr{Y}}^2$ matches\n\\begin{align}\n\\begin{split}\n&(a + b + c - d)^2 \\\\\n&= a^2 + b^2 +c^2 +d^2 \\\\\n&+ 2 a b + 2 a c - 2 a d \\\\\n&+ 2 b c - 2 b d - 2 c d \n\\end{split}\n\\end{align}\nso we have\n\\begin{align}\n\\begin{split}\n\\dot{\\mathscr{Y}}^2 &= (\\dot{x}\\sin{\\omega t} + \\dot{y}\\cos{\\omega t} + \\omega x\\cos{\\omega t} - \\omega y\\sin{\\omega t})(\\dot{x}\\sin{\\omega t} + \\dot{y}\\cos{\\omega t} + \\omega x\\cos{\\omega t} - \\omega y\\sin{\\omega t}) \\\\\n&=\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\dot{x}^2\\sin^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\dot{y}^2\\cos^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\omega^2 x^2\\cos^2{t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$\\omega^2 y^2\\sin^2{t}$};\n} \\\\\n&+\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\dot{x}\\dot{y}\\cos{\\omega t}\\sin{\\omega t}$};\n} +\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega x \\dot{x}\\cos{\\omega t}\\sin{\\omega t}$};\n} -\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$2 \\omega \\dot{x}y\\sin^2{t}$};\n} \\\\\n&+\n\\tikz[baseline]{\n    \\node[fill=green!20,anchor=base]\n    {$2 \\omega x \\dot{y}\\cos^2{t}$};\n} -\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega y \\dot{y}\\cos{\\omega t}\\sin{\\omega t}$};\n} -\n\\tikz[baseline]{\n    \\node[fill=red!20,anchor=base]\n    {$2 \\omega^2 x y \\cos{\\omega t}\\sin{\\omega t}$};\n}\n\\end{split}\n\\end{align}\n\\begin{align}\n\\notag &\\tikz\\node [fill=green!20,draw,circle]{};\\ \\text{Terms that add in $\\mathscr{X}^2 + \\mathscr{Y}^2$} \\\\\n\\notag &\\tikz\\node [fill=red!20,draw,circle]{};\\ \\text{Terms that cancel in $\\mathscr{X}^2 + \\mathscr{Y}^2$} \\\\[1cm]\n\\end{align}\nCancelling terms and repeated use of $\\cos^2{t} + \\sin^2{t} = 1$ finally gives us\n\\begin{align}\n\\notag \\dot{\\mathscr{X}}^2 + \\dot{\\mathscr{Y}}^2 &= \\dot{x}^2 + \\dot{y}^2 + \\omega^2 x^2 + \\omega^2 y^2 - 2 \\omega \\dot{x} y + 2 \\omega x \\dot{y} \\\\[0.2cm]\n&= (\\dot{x}-\\omega y)^2 + (\\dot{y}+\\omega x)^2\n\\end{align}\n", "meta": {"hexsha": "f3f4e7ba707afed82bf2bc0f77d18ac3f67ac552", "size": 4705, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/appendices/Coordinate_Transformation.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/Coordinate_Transformation.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/Coordinate_Transformation.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": 32.6736111111, "max_line_length": 373, "alphanum_fraction": 0.5904357067, "num_tokens": 1964, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898203834278, "lm_q2_score": 0.8459424334245617, "lm_q1q2_score": 0.7664152333130384}}
{"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{PRINCIPAL COMPONENT ANALYSIS}\n\\date{}\n\\maketitle\n\nPrincipal Component Analysis (PCA) is non-parametric approach to transform a set of observations - of possibly correlated variables - into another set of values defined by a calculated set of new orthogonal uncorrelated variables called principal components. \n\n\\section{Example}\n\nConsider the following set of four observations in two dimesions,\n\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\n\t\t\\draw[step=1.0, gray, very thin] (-4.5, -4.5) grid (4.5, 4.5);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-5,0) -- (5,0) node[right]{x1};\n\t\t\\draw[-latex] (0,-5) -- (0,5) node[left]{x2};\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (2.7, 2) -- (3.3, 2);\t\n\t\t\\draw[point line] (3, 1.7) -- (3, 2.3);\n\t\t\\draw (3, 2) node [below right] {(3, 2)};    \t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 0) -- (-0.7, 0);\t\n\t\t\\draw[point line] (-1, -0.3) -- (-1, 0.3);\t\n\t\t\\draw (-1, 0) node [below left] {(-1, 0)};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 2) -- (-0.7, 2);\t\n\t\t\\draw[point line] (-1, 1.7) -- (-1, 2.3);\t\n\t\t\\draw (-1, 2) node [above left] {(-1, 2)};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, -4) -- (-0.7, -4);\t\n\t\t\\draw[point line] (-1, -4.3) -- (-1, -3.7);\t\n\t\t\\draw (-1, -4) node [above left] {(-1, -4)};   \n\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nTo see how PCA alters the representation of this tiny dataset, the dataset is first written in matrix form as follows,\n\n\\begin{align*}\n\tX & = \\begin{pmatrix} 3 & -1 & -1 & -1 \\\\\n\t2 & 0 & 2 & -4  \n\t\\end{pmatrix}\n\\end{align*}\n\nThe x-axis intercepts are represented by the first row of this matrix while y-axis intercepts are represented by the second row.\nThis matrix can be thought of as a representation composed of two random variables x1 and x2. The variances of these variables and their covariance are useful quantities to describe the structure of the dataset.\n\n\\begin{align*}\n\tVar(x1)     & = \\frac{1}{N} \\sum\\limits_{i = 1}^N (x1_i - \\bar{x1})^2                \\\\\n\t            & = \\frac{1}{4} \\sum\\limits_{i = 1}^4 (x1_i - 0)^2                       \\\\\n\t            & = \\frac{1}{4} |x1|^2                                                   \\\\\n\t            & = \\frac{3^2 + (-1)^ 2 + (-1)^2 + (-1)^2}{4}                            \\\\\n\t            & = 3                                                                    \\\\\n\tVar(x2)     & = \\frac{1}{4} \\sum\\limits_{i = 1}^4 (x2_i - 0)^2                       \\\\\n\t            & = \\frac{1}{4} |x2|^2                                                   \\\\\n\t            & = \\frac{2^2 + 0^ 2 + 2^2 + (-4)^2}{4}                                  \\\\           \n\t            & = 6                                                                    \\\\\n\tCov(x1, x2) & = \\frac{1}{N} \\sum\\limits_{i = 1}^N (x1_i - \\bar{x1})(x2_i - \\bar{x2}) \\\\\n\t            & = \\frac{1}{4} \\sum\\limits_{i = 1}^4 (x1_i - 0)(x2_i - 0)               \\\\  \n\t            & = \\frac{1}{4} \\vec{x1}.\\vec{x2}                                        \\\\\n\t            & = \\frac{3*2 + (-1)*0 + (-1)*2 + (-1)*(-4)}{4}                          \\\\\n\t            & = 2                                                                    \n\\end{align*}\n\nNote that the mean of both the vectors is zero in the dataset. This is a necessary precondition for PCA, the reason for this constraint will become apparent in later sections. Next, these variances and covariance are arranged in a matrix as follows.\n\n\\begin{align*}\n\t\\sum & = \\begin{pmatrix} Var(x1) & Cov(x1, x2) \\\\\n\tCov(x1, x2) & Var(x2) \\\\ \n\t\\end{pmatrix} \\\\\n\t     & = \\begin{pmatrix} 3       & 2           \\\\\n\t2 & 6 \\\\ \n\t\\end{pmatrix}           \n\\end{align*}\n\nDue to zero mean constraint, the following also holds true,\n\n\\begin{align*}\n\t\\sum = \\frac{1}{N} XX^T \\\\\n\\end{align*}\n\nNow eigenvalues and eigenvectors of $\\sum$ are calculated.\n\n\\begin{align*}\n\t\\sum \\phi              & = \\lambda \\phi \\\\\n\t(\\sum - \\lambda I)\\phi & = 0            \n\\end{align*}\n\n$(\\sum - \\lambda I)$ must be singular if eigenvectors are non-zero. Hence,\n\n\\begin{align*}\n\t\\begin{vmatrix} 3 - \\lambda & 2           \\\\\n\t2                           & 6 - \\lambda \\\\ \n\t\\end{vmatrix}               & = 0         \\\\\n\t(3 - \\lambda)(6 - \\lambda)  & = 4         \\\\\t                \n\\end{align*}\n\nThis gives eigenvalues $\\lambda = 2, 7$ and eignevectors $\\phi = (\\frac{-2}{\\sqrt{5}}, \\frac{1}{\\sqrt{5}}), (\\frac{1}{\\sqrt{5}}, \\frac{2}{\\sqrt{5}}) $ respectively. Now the eigenvectors are arranged as rows in a matrix in order of their corresponding eigenvalue. \n\n\n\\begin{align*}\n\tP & = \\begin{pmatrix} \\frac{1}{\\sqrt{5}}   & \\frac{2}{\\sqrt{5}} \\\\\n\t\\frac{-2}{\\sqrt{5}} & \\frac{1}{\\sqrt{5}} \\\\ \n\t\\end{pmatrix}  \\\\\n\t  & = \\frac{1}{\\sqrt{5}} \\begin{pmatrix} 1 & 2                  \\\\\n\t-2 & 1\\\\ \n\t\\end{pmatrix}\t                \n\\end{align*}\n\n\nSee the following visualization of eigenvectors.\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\n\t\t\\draw[step=1.0, gray, very thin] (-4.5, -4.5) grid (4.5, 4.5);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-5,0) -- (5,0) node[right]{x1};\n\t\t\\draw[-latex] (0,-5) -- (0,5) node[left]{x2};\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (2.7, 2) -- (3.3, 2);\t\n\t\t\\draw[point line] (3, 1.7) -- (3, 2.3);\n\t\t\\draw (3, 2) node [below right] {(3, 2)};    \t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 0) -- (-0.7, 0);\t\n\t\t\\draw[point line] (-1, -0.3) -- (-1, 0.3);\t\n\t\t\\draw (-1, 0) node [below left] {(-1, 0)};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, 2) -- (-0.7, 2);\t\n\t\t\\draw[point line] (-1, 1.7) -- (-1, 2.3);\t\n\t\t\\draw (-1, 2) node [above left] {(-1, 2)};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.3, -4) -- (-0.7, -4);\t\n\t\t\\draw[point line] (-1, -4.3) -- (-1, -3.7);\t\n\t\t\\draw (-1, -4) node [above left] {(-1, -4)}; \n\t\t\t\t\t\t\t\t\n\t\t\\draw[very thick,->] (0,0) -- (.45,.90);  \n\t\t\\draw[dashed] (-2.25, -4.5) -- (2.25,4.5);\n\t\t\\draw (.45, .90) node [right] {$(\\frac{1}{\\sqrt{5}}, \\frac{2}{\\sqrt{5}})$}; \n\t\t\t\t\t\t\t\t\n\t\t\\draw[very thick,->] (0,0) -- (-0.90,0.45);  \n\t\t\\draw[dashed] (-4.5, 2.25) -- (4.5,-2.25);\n\t\t\\draw (-0.90,0.45) node [above] {$(\\frac{-2}{\\sqrt{5}}, \\frac{1}{\\sqrt{5}})$};\n\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nNow the transformed dataset Y is calculated simply as product of P and X.\n\n\\begin{align*}\n\tP &= \\frac{1}{\\sqrt{5}} \\begin{pmatrix} 1 & 2 \\\\\n\t-2 & 1\\\\ \n\t\\end{pmatrix} \\begin{pmatrix} 3 & -1 & -1 & -1 \\\\\n\t2 & 0 & 2 & -4  \n\t\\end{pmatrix} \\\\ \n\t  & = \\frac{1}{\\sqrt{5}} \\begin{pmatrix} 7 & -1 & 3 & -9 \\\\\n\t-4 & 2 & 4 & -2  \n\t\\end{pmatrix}\n\\end{align*}\n\nTo visualize the result, Y is plotted on a graph,\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\n\t\t\\draw[step=1.0, gray, very thin] (-4.5, -4.5) grid (4.5, 4.5);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-5,0) -- (5,0) node[right]{y1};\n\t\t\\draw[-latex] (0,-5) -- (0,5) node[left]{y2};\t\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (2.83, -1.78) -- (3.43, -1.78);\t\n\t\t\\draw[point line] (3.13, -2.08) -- (3.13, -1.48);\n\t\t\\draw (3.13, -1.78) node [below left] {$(\\frac{7}{\\sqrt{5}}, \\frac{-4}{\\sqrt{5}})$};    \t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-0.74, 0.89) -- (-0.14, 0.89);\t\n\t\t\\draw[point line] (-0.44, 0.59) -- (-0.44, 1.19);\t\n\t\t\\draw (-0.44, 0.89) node [below left] {$(\\frac{-1}{\\sqrt{5}}, \\frac{2}{\\sqrt{5}})$};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (1.04, 1.78) -- (1.64, 1.78);\t\n\t\t\\draw[point line] (1.34, 1.48) -- (1.34, 2.08);\t\n\t\t\\draw (1.34, 1.78) node [below right] {$(\\frac{3}{\\sqrt{5}}, \\frac{4}{\\sqrt{5}})$};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.32 , -0.89) -- (-3.72 , -0.89);\t\n\t\t\\draw[point line] (-4.02, -1.19) -- (-4.02,-0.59 );\t\n\t\t\\draw (-4.02, -0.89) node [below right] {$(\\frac{-9}{\\sqrt{5}}, \\frac{-2}{\\sqrt{5}})$};   \n\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nVisually, the points on the transformed graph arise due to a change of axes from the original axes to the axes defined by the eigenvectors of $\\sum$. To see why this choice of axes was made, the variance covariance matrix of the transformed data is calculated.\n\n\\begin{align*}\n\t\\sum_{new} &= \\frac{1}{N} YY^T \\\\\n\t  & = \\frac{1}{4} \\frac{1}{\\sqrt{5}} \\begin{pmatrix} 7 & -1 & 3 & -9 \\\\\n\t-4 & 2 & 4 & -2  \n\t\\end{pmatrix} \\frac{1}{\\sqrt{5}}  \\begin{pmatrix} 7 & -4 \\\\\n\t-1 & 2 \\\\\n\t3 & 4 \\\\\n\t-9 & -2 \\\\   \n\t\\end{pmatrix} \\\\\n\t&=  \\frac{1}{20} \\begin{pmatrix} 140 & 0 \\\\\n\t0 & 40 \n\t\\end{pmatrix} \\\\\n\t&= \\begin{pmatrix} 7 & 0 \\\\\n\t0 & 2 \n\t\\end{pmatrix}          \n\\end{align*}\n\nThis results in the variance covariance of transformed data being diagonalized. Also notice that the variance values i.e. the diagonal terms are equal to the corresponding eigenvalues. PCA yields a set of a new set of variables/axes from the original set of variables/axes which have the following properties.\n\n\n\\begin{itemize}\n\t\\item New variables are mutually uncorrelated.\n\t\\item New variables are orthogonal to each other.\n\\end{itemize}\n\nYou are free to choose a subset of these new variables depending on the tradeoff between smaller number of dimensions vs loss in variance. In practice, a large chunk of calculated variables in the bottom right part of the diagonal are near zero in their variance and thus are ignored resulting in dimensionality reduction. \nIn this example, if the new variable corresponding to lower variance is dropped, the dataset is transformed from 2-d to 1-d as shown below.\n\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-5,0) -- (5,0) node[right]{y1};\n\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (2.83, 0) -- (3.43, 0);\t\n\t\t\\draw[point line] (3.13, -0.3) -- (3.13, 0.3);\n\t\t\\draw (3.13, -0.2) node [below] {$\\frac{7}{\\sqrt{5}}$};    \t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-0.74, 0) -- (-0.14, 0);\t\n\t\t\\draw[point line] (-0.44, -.3) -- (-0.44, .3);\t\n\t\t\\draw (-0.44, -0.2) node [below] {$\\frac{-1}{\\sqrt{5}}$};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (1.04, 0) -- (1.64, 0);\t\n\t\t\\draw[point line] (1.34, -.3) -- (1.34, .3);\t\n\t\t\\draw (1.34, -0.2) node [below] {$\\frac{3}{\\sqrt{5}}$};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-4.32 , 0) -- (-3.72 , 0);\t\n\t\t\\draw[point line] (-4.02, -0.3) -- (-4.02,0.3 );\t\n\t\t\\draw (-4.02, -0.2) node [below] {$\\frac{-9}{\\sqrt{5}}$};   \n\t\t\t\t\t\t\t\t\t\t\t   \t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\section{Mathematics}\n\nAssume a (MxN) matrix X as a set of N observations of M random variables such that each observation is a column in the matrix X. Furthermore, assume that each variable has zero mean meaning that each row of the matrix sums up to zero. Denote by $\\sum_x$ the variance covariance matrix of the variables. Due to the zero mean condition, \n\n\\begin{align*}\n\t\\sum_x = XX^T \n\\end{align*} \n\nLet $\\phi_i, \\phi_2, ..., \\phi_m$ be the m orthonormal eigenvectors of $\\sum_x$. Let P be defined as the matrix $[\\phi_1^T, \\phi_2^T, ..., \\phi_m^T]^T$. Consider the following transformation, \n\n\\begin{align*}\n\tY = PX \n\\end{align*}\n\nIt can be shown that the resulting variables are also zero-mean based. So, their variance covariance matrix can be written as,\n\n\\begin{align*}\n\t\\sum_y & = YY^T       \\\\\n\t       & = (PX)(PX)^T \\\\\n\t       & = PXX^TP^T   \\\\\n\t       & = P\\sum_xP^T \\\\           \n\\end{align*}\n\n$\\sum_x$ is symmetric and all symmetric matrices are diagonalized by a matrix of their orthonormal eigenvectors. Or more precisely,\n\n\\begin{align*}\n\t\\sum_x = P^TDP \n\\end{align*}\n\nwhere D is a diagonal matrix. Upon substitution in the preceding equation,\n\n\\begin{align*}\n\t\\sum_y = PP^TDPP^T \n\\end{align*}\n\nSince P is orthonormal, its transpose is its inverse and thus $PP^T = I$ which reduces $\\sum_y$ to D.\n\n\\section{Kernel PCA}\n\nLet X be $[x_1, x_2, ..., x_N]$ where each $x_i$ is an observation of M variables. Consider mapping each $x_i$ to $f(x_i)$ where $f$ is non-linear and may increase the dimensionality of each $x_i$. So,\n\n\\begin{align*}\n\tf(X) = [f(x_1), f(x_2), ..., f(x_N)] \n\\end{align*}\n\nNow examine the variance covariance matrix of $f(X)$.\n\n\\begin{align*}\n\t\\sum_f & = \\frac{1}{N}f(X)f(X)^T                                   \\\\\n\t       & = \\frac{1}{N}[f(x_1), f(x_2), ..., f(x_N)]\\begin{pmatrix} \n\tf(x_1^T) \\\\\n\tf(x_2^T) \\\\\n\t... \\\\\n\tf(x_N^T) \n\t\\end{pmatrix} \\\\\n\t       & = \\frac{1}{N} \\sum_{i = 1}^{N} f(x_i)f(x_i^T)             \\\\\n\\end{align*}\n\nTo find principal components, eigenvalues and eigenvectors of the variance covariance matrix must be found out. since there are N eigenvalue, eigenvector pairs, they will be subscripted by j.\n\n\\begin{align*}\n\t\\lambda_j\\phi_j & = \\sum_f\\phi_j                                      \\\\\n\t\\lambda_j\\phi_j & = \\frac{1}{N} \\sum_{i = 1}^{N} f(x_i)f(x_i^T)\\phi_j \\\\\n\\end{align*}\n\nSince $f(x_i^T)\\phi_j = \\vec{f(x_i)}.\\vec{\\phi_j}$ is just a scalar, the equation can be simplified to,\n\n\\begin{align*}\n\t\\phi_j & = \\sum_{i = 1}^{N} \\frac{\\vec{f(x_i)}.\\vec{\\phi_j}}{N\\lambda_j}f(x_i) \\\\\n\\end{align*}\n\nSubstituting $\\frac{\\vec{f(x_i)}.\\vec{\\phi_j}}{N\\lambda_j}$ = $a_{ij}$, the equation becomes,\n\n\\begin{align*}\n\t\\phi_j = \\sum_{i = 1}^{N} a_{ij} f(x_i) \n\\end{align*} \n\nThis equation reveas that the principal components are linear combinations of the observations.\n\n\\begin{align*}\n\t\\phi_j = a_{1j}f(x_1) + a_{2j}f(x_2) + ... + a_{Nj}f(x_N) \\\\ \n\\end{align*}\n\nTaking dot products by $f(x_1), f(x_2) ... f(x_N)$ successively,\n\n\\begin{align*}\n\t\\vec{f(x_1)}.\\vec{\\phi_j} & = a_{1j}\\vec{f(x_1)}.\\vec{f(x_1)} + a_{2j}\\vec{f(x_1)}.\\vec{f(x_2)} + ... + a_{Nj}\\vec{f(x_1)}.\\vec{f(x_N)} \\\\\n\t\\vec{f(x_2)}.\\vec{\\phi_j} & = a_{1j}\\vec{f(x_2)}.\\vec{f(x_1)} + a_{2j}\\vec{f(x_2)}.\\vec{f(x_2)} + ... + a_{Nj}\\vec{f(x_2)}.\\vec{f(x_N)} \\\\ \n\t...                       & = ...                                                                                                       \\\\\n\t\\vec{f(x_N)}.\\vec{\\phi_j} & = a_{1j}\\vec{f(x_N)}.\\vec{f(x_1)} + a_{2j}\\vec{f(x_N)}.\\vec{f(x_2)} + ... + a_{Nj}\\vec{f(x_N)}.\\vec{f(x_N)} \n\\end{align*}\n\nIn matrix form, these equations look like,\n\n\\begin{align*}\n\t\\begin{pmatrix}\n\t\\vec{f(x_1)}.\\vec{\\phi_j} \\\\\n\t\\vec{f(x_2)}.\\vec{\\phi_j} \\\\\n\t... \\\\\n\t\\vec{f(x_N)}.\\vec{\\phi_j} \n\t\\end{pmatrix} = \\begin{pmatrix}\n\t\\vec{f(x_1)}.\\vec{f(x_1)} & \\vec{f(x_1)}.\\vec{f(x_2)} & ... & \\vec{f(x_1)}.\\vec{f(x_N)} \\\\\n\t\\vec{f(x_2)}.\\vec{f(x_1)} & \\vec{f(x_2)}.\\vec{f(x_2)} & ... & \\vec{f(x_2)}.\\vec{f(x_N)} \\\\\n\t... \\\\\n\t\\vec{f(x_N)}.\\vec{f(x_1)} & \\vec{f(x_N)}.\\vec{f(x_2)} & ... & \\vec{f(x_N)}.\\vec{f(x_N)} \\\\\n\t\\end{pmatrix} \\begin{pmatrix}\n\ta_{1j} \\\\\n\ta_{2j} \\\\\n\t... \\\\\n\ta_{Nj} \\\\\n\t\\end{pmatrix}\n\\end{align*}\n\nThe first matrix on the right is a NxN matrix. Denote it by the kernel matrix: K. For every term on the left hand side matrix use the fact that $\\vec{f(x_i)}.\\vec{\\phi_j} = N\\lambda_j a_{ij}$.\n\n\\begin{align*}\n\tN\\lambda_j \\begin{pmatrix}        \n\ta_{1j}                            \\\\\n\ta_{2j}                            \\\\\n\t...                               \\\\\n\ta_{Nj}                            \\\\\n\t\\end{pmatrix} = K \\begin{pmatrix} \n\ta_{1j}                            \\\\\n\ta_{2j}                            \\\\\n\t...                               \\\\\n\ta_{Nj}                            \\\\\n\t\\end{pmatrix}                     \n\\end{align*}\n\nIt is apparent that $N\\lambda_j, [a_{1j}, a_{2j}, ..., a_{Nj}]^T \\forall j \\in [1, N]$are eigenvalue, eigenvector pairs for the matrix K. The PCA transform for $f(X)$ can be written as,\n\n\\begin{align*}\n\tY &= \\begin{pmatrix}\n\t\\phi_1^T \\\\\n\t\\phi_2^T \\\\\n\t... \\\\\n\t\\phi_N^T \\\\\n\t\\end{pmatrix} f(X) \\\\\n\t&= \\begin{pmatrix}\n\t\\phi_1^T \\\\\n\t\\phi_2^T \\\\\n\t... \\\\\n\t\\phi_N^T \\\\\n\t\\end{pmatrix} [f(x_1), f(x_2), ..., f(x_N)] \\\\\n\t&= \\begin{pmatrix}\n\t\\vec{\\phi_1}.\\vec{f(x_1)} & \\vec{\\phi_1}.\\vec{f(x_2)} & ... & \\vec{\\phi_1}.\\vec{f(x_N)} \\\\\n\t\\vec{\\phi_2}.\\vec{f(x_1)} & \\vec{\\phi_2}.\\vec{f(x_2)} & ... & \\vec{\\phi_2}.\\vec{f(x_N)} \\\\\n\t... \\\\\n\t\\vec{\\phi_N}.\\vec{f(x_1)} & \\vec{\\phi_N}.\\vec{f(x_2)} & ... & \\vec{\\phi_N}.\\vec{f(x_N)} \\\\\n\t\\end{pmatrix}       \n\\end{align*} \n\nUsing the relation $\\vec{f(x_i)}.\\vec{\\phi_j} = N\\lambda_j a_{ij}$,\n\n\\begin{align*}\n\tY &= \\begin{pmatrix}\n\tN\\lambda_1 a_{11} & N\\lambda_1 a_{21} & ... & N\\lambda_1 a_{N1} \\\\ \n\tN\\lambda_2 a_{12} & N\\lambda_2 a_{22} & ... & N\\lambda_2 a_{N2} \\\\ \n\t... \\\\\n\tN\\lambda_N a_{1N} & N\\lambda_N a_{2N} & ... & N\\lambda_N a_{NN} \\\\ \n\t\\end{pmatrix} \\\\\n\t&=  N\\begin{pmatrix}\n\t\\lambda_1 a_{11}  & \\lambda_1 a_{21}  & ... & \\lambda_1 a_{N1}  \\\\ \n\t\\lambda_2 a_{12}  & \\lambda_2 a_{22}  & ... & \\lambda_2 a_{N2}  \\\\ \n\t... \\\\\n\t\\lambda_N a_{1N}  & \\lambda_N a_{2N}  & ... & \\lambda_N a_{NN}  \\\\ \n\t\\end{pmatrix}      \n\\end{align*} \n\nThis is the kernel trick for PCA where it is not required to explicit map each point to higher dimensions whcich may be computationally expensive. PCA transformation in nonlinear higher dimensions can be calculated by performing the following steps in the order below. \n\n\\begin{itemize}\n\t\\item Choose a kernel $ k(x_i, x_j) = \\vec{f(x_i)}.\\vec{f(x_j)}$.\n\t\\item Calculate kernel matrix K = $\\begin{pmatrix}\n\t      k(x_1, x_1) & k(x_1, x_2) & ... & k(x_1, x_N) \\\\\n\t      k(x_2, x_1) & k(x_2, x_2) & ... & k(x_2, x_N) \\\\\n\t      ... \\\\\n\t      k(x_N, x_1) & k(x_N, x_2) & ... & k(x_N, x_N) \\\\\n\t\\end{pmatrix}$.\n\t\\item Find the eigenvalue, eigenvalue pairs of K.\n\t\\item Use eigenvalue, eigenvector pairs to calcuate the kernel PCA transform as shown above.\n\t\\item Do dimensinality reduction as appropriate.  \n\\end{itemize}\n\n\\section{Assumptions and Limitations}\n\n\\begin{itemize}\n\t\\item The new variables are linear combinations of the original ones. Kernel PCA helps alleviate this problem.\n\t\\item PCA assumes that mean and variance are sufficient statistics to describe a random variable. Since only Gaussian distributions are described fully by their variance, the assumption that input dataset is Gaussian is inherent.\n\t\\item The new variables are orthogonal which can be limiting but makes the solution to be readily expressible through linear algebra. \n\\end{itemize}\n\n\\end{document}", "meta": {"hexsha": "8fa2fb253a3120b8c8e597d5b859fb6bcb84d58b", "size": 18069, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Principal Component Analysis/Principal Component Analysis.tex", "max_stars_repo_name": "singaurav/machine-learning-notes", "max_stars_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-26T11:33:39.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-26T11:33:39.000Z", "max_issues_repo_path": "Principal Component Analysis/Principal Component Analysis.tex", "max_issues_repo_name": "singaurav/machine-learning-notes", "max_issues_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Principal Component Analysis/Principal Component Analysis.tex", "max_forks_repo_name": "singaurav/machine-learning-notes", "max_forks_repo_head_hexsha": "4fdd5b839156bcbf8f95a36275b8cd10f93e4c9d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-09-22T18:56:20.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-22T18:56:20.000Z", "avg_line_length": 39.1952277657, "max_line_length": 335, "alphanum_fraction": 0.5452432343, "num_tokens": 6676, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.9173026488471137, "lm_q1q2_score": 0.7663912654107338}}
{"text": "%!TEX root = /home/renaud/Documents/EPL/tfe/latex/tfe.tex\n\\chapter{The \"overturner\" model}\n\\section{Mathematical model}\n\\subsection{An idealised velocity field}\nWe develop here the idealized representation of the meridian circulation in the Atlantic ocean that will be studied in the next chapters. \\textcolor{red}{ici : développement mathématique. Plus loin on donne des valeurs aux paramètres avec un \"physical insight\"}. We consider a rectangular domain in the $(y,z)$-coordinate system. The coordinate $y$ is associated to the latitude with $\\hat{\\b{e}}_y$ pointing towards the North, and $z$ is associated to the depth with $\\hat{\\b{e}}_z$ pointing upwards. The domain $\\Omega$ is delimited by\n\\begin{equation} \n\t0 \\le y \\le L,\\quad 0 \\le z \\le H,\n\\end{equation}\nwhere $L$ and $H$ are positive constants. The ocean surface is thus located at $z = H$ while $z = 0$ stands for the deep-ocean. The South and North boundaries are respectively given by $y = 0$ and $y = L$. We aim at defining a stationnary velocity field $\\b u(y,z) = (v(y,z),\\, w(y,z))$ that would roughly reproduce the main qualitative features of the meridian circulation in the Atlantic ocean. The continuity equation reads\n\\begin{equation} \\label{eq:continuity}\n\t\\frac{\\partial \\rho}{\\partial t} + \\nabla \\cdot (\\rho \\b u) = 0,\n\\end{equation}\nwhere $\\rho$ is the density of the seawater mixture. We note $\\partial \\Omega$ its boundary. We simplify this equation by making the very common \\textit{Boussinesq appromation} : in the aquatic environment, water is, by far, the dominant constituent. The density of seawater is thus close to that of pure water, $\\rho_w$. The latter depends on the temperature and pressure, but the variations are often very small.Let $\\bar{\\rho}$ and $\\Delta\\rho$ be appropriate reference values of the density and the order of magnitude of its variation. The key assumption in the \\textit{Boussinesq approximation} is that\n\\begin{equation} \\label{eq:bouss_hyp}\n\t\\frac{\\Delta \\rho}{\\bar{\\rho}} \\ll 1.\n\\end{equation}\nTo assess the impact of this assumption on the continuity equation, we consider its dimensionless form. Let $U$, $T$ and $X$ be relevant velocity-, time- and space-scales. This allows to introduce the following dimensionless variables, denoted by primes :\n\\begin{equation}\n\t\\rho' = \\frac{\\rho - \\bar{\\rho}}{\\Delta \\rho}, \\quad \\b u' = \\frac{\\b u}{U}, \\quad t' = \\frac{t}{T}, \\quad \\mbox{and} \\quad \\b x' = \\frac{\\b x}{X},\n\\end{equation}\nwhere $\\b x = (y,z)$. The dimensionless version of the continuity equation~\\eqref{eq:continuity} reads then: \n\\begin{equation}\n\t\\frac{\\Delta \\rho}{T}\\frac{\\partial \\rho'}{\\partial t'} + \\frac{U\\Delta \\rho}{X}\\b u' \\cdot \\nabla' \\rho' + \\frac{U(\\bar{\\rho}+ \\rho' \\Delta \\rho)}{X}\\nabla' \\cdot \\b u' = 0.\n\\end{equation}\nMultiplying both sides by $X/(U\\bar{\\rho})$ yields :\n\\begin{equation}\n\t\\frac{X}{UT}\\frac{\\Delta \\rho}{\\bar{\\rho}}\\frac{\\partial \\rho'}{\\partial t'} + \\frac{\\Delta \\rho}{\\bar{\\rho}}\\b u' \\cdot \\nabla' \\rho' + \\left(1+\\frac{\\Delta \\rho}{\\bar{\\rho}}\\rho'\\right)\\nabla' \\cdot \\b u' = 0.\n\\end{equation}\nBy taking~\\eqref{eq:bouss_hyp} into account, this equation simplifies to $\\nabla' \\cdot \\b u' = 0$, or equivalently in dimensional variables $\\nabla \\cdot \\b u = 0$. For our particular problem, this amounts to\n\\begin{equation}\n\t\\frac{\\partial v}{\\partial y} + \\frac{\\partial w}{\\partial z} = 0.\n\\end{equation}\nNo-through boundary conditions are imposed at the boundaries of the domain, which implies that $\\b u(y,z) \\cdot \\hat{\\b{n}} = 0$ everywhere on $\\partial \\Omega$ (where $\\hat{\\b{n}}$ is the outwards unit normal at the boundary), or equivalently :\n\\begin{equation} \\label{eq:overturnerBC}\n\tv(0,z) = 0, \\quad v(L,z) = 0, \\quad w(y,0) = 0 \\quad \\mbox{and} \\quad w(y,H) = 0.\n\\end{equation}\n\\textcolor{red}{Blahblah à mettre en relation avec ce qu'on doit dire plus tôt sur les modèles 2D de l'océan Atlantique,... Éventuellement s'inspirer de Timmermans mais attention quand même...}\n\nFurthermore, since the relation $\\nabla \\cdot (\\nabla \\times \\b a) = 0$ holds true for any 3-dimensional potential vector $\\b a(x,y,z)$ whose second partial derivatives are continuous,\\footnote{The proof is quite straightforward :\n\t\\begin{align*}\n\t\t\\nabla \\cdot (\\nabla \\times \\b a(x,y,z)) &= \\nabla \\cdot \\left[\\left(\\frac{\\partial a_z}{\\partial y}-\\frac{\\partial a_y}{\\partial z}\\right)\\ex + \\left(\\frac{\\partial a_x}{\\partial z}-\\frac{\\partial a_z}{\\partial x}\\right)\\ey + \\left(\\frac{\\partial a_y}{\\partial x}-\\frac{\\partial a_x}{\\partial y}\\right)\\ez \\right]\\\\\n\t\t&= \\frac{\\partial^2 a_z}{\\partial x \\partial y} - \\frac{\\partial^2 a_y}{\\partial x \\partial z} + \\frac{\\partial^2 a_x}{\\partial y \\partial z} - \\frac{\\partial^2 a_z}{\\partial y \\partial x} + \\frac{\\partial^2 a_y}{\\partial z \\partial x} - \\frac{\\partial^2 a_x}{\\partial z \\partial y}\\\\\n\t\t&= 0.  \n\t\\end{align*}\n\tHere, we have assumed that $\\b a(x,y,z)$ is sufficiently smooth, or more precesily that the second partial derivatives of $a_x$, $a_y$ and $a_z$ are continuous. This allows to use \\textit{Schwarz's theorem} which states that in that case, the second partial derivatives are symmetric.\n} \nwe can choose a relevant $\\b a(x,y,z) = (a_x(x,y,z),\\,a_y(x,y,z),\\,a_z(x,y,z))$ with $a_x$, $a_y$ and $a_z$ of class $\\C^2$ and impose that \n\\begin{equation} \\label{eq:stream3d}\n\t\\b u = \\begin{pmatrix} u \\\\ v \\\\ w \\end{pmatrix} = - \\nabla \\times \\b a = - \\begin{pmatrix} \\frac{\\partial a_z}{\\partial y}-\\frac{\\partial a_y}{\\partial z}\\\\[.1 cm]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\\frac{\\partial a_x}{\\partial z}-\\frac{\\partial a_z}{\\partial x}\\\\[.1 cm]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\\frac{\\partial a_y}{\\partial x}-\\frac{\\partial a_x}{\\partial y}\n\t\t\t\t\t\t\t\t\t\\end{pmatrix}.\n\\end{equation}\nThis ensures that $\\b u$ satisfies the continuity equation. Here, we consider a 2-dimensional flow in the plane $(\\ey,\\ez)$. Hence $u = 0$ and $\\partial \\cdot/\\partial x = 0$. The relation~\\eqref{eq:stream3d} becomes \n\\begin{equation}\n\t\\b u = \\begin{pmatrix} 0 \\\\ v \\\\ w \\end{pmatrix} = - \\nabla \\times \\b a = \\begin{pmatrix} 0\\\\ - \\frac{\\partial a_x}{\\partial z}\\\\[.1 cm] \\frac{\\partial a_x}{\\partial y} \\end{pmatrix},\n\\end{equation}\nwhere only the component $a_x$ is needed to describe $\\b u$. Hence, the velocity field of a flow in the plane is described by a scalar quantity, the so-called \\textit{streamfunction}, generally noted $\\psi$. The potential vector $\\b a$ is thus of the form $\\b a(y,z) = (\\psi(y,z),\\, 0,\\, 0)$, and the meridional and vertical components of the velocity vector are given by :\n\\begin{equation} \\label{eq:u-psi}\n\tv = -\\frac{\\partial \\psi}{\\partial z}, \\quad w = \\frac{\\partial \\psi}{\\partial y}.\n\\end{equation}\nNote that adding any constant to $\\psi$ leaves the velocity vector unchanged. This adds some freedom to the choice of $\\psi$. The idea is now to propose a reasonable streamfunction. Then, deriving the velocity components from that streamfunction will ensure that the continuity equation is satisfied. In order to derive a streamfunction that is relevant to our problem, we need to get some physical intuition about the streamfunction. To this end, two fundamental properties of the streamfunction are rederived in the frame below. \n\n%--------------------------------------STREAMFUNCTION---------------------------------------------%\n\\begin{tcolorbox}[title=Some properties of the streamfunction]\nFirst, notice that assuming that $\\psi \\in \\C^2$ implies straightforwardly that $\\rm d\\psi = (\\partial \\psi/\\partial y)\\rm dy + (\\partial \\psi/\\partial z) \\rm dz$ is an \\textit{exact differential} since by Schwarz's theorem\n\\begin{equation}\n\t\\frac{\\partial^2 \\psi}{\\partial y \\partial z} = \\frac{\\partial^2 \\psi}{\\partial z \\partial y}.\n\\end{equation}\nThus,\n\\begin{equation}\n\\int_{\\b x_1}^{\\b x_2} \\rm d\\psi = \\psi(y_2,z_2) - \\psi(y_1,z_1)\t\n\\end{equation}\nis path-independant. \n\nAn important property of the streamfunction in two dimensions is that the curves along which $\\psi$ is constant are exactly the \\textit{streamlines} of the flow, namely the family of curves that are instantaneously tangent to the velocity vector. To show that, let such a curve be parametrized by $s \\mapsto \\b x_S(s) = (y_S(s),z_S(s))$. The fact that $\\psi$ is constant along that curve implies that $\\rm d\\psi_S = (\\partial \\psi/\\partial y)\\rm dy_S + (\\partial \\psi/\\partial z) \\rm dz_S = \\nabla \\psi \\cdot \\rm d \\b x_S = 0$. This shows that vector $\\nabla \\psi$ is normal to the curve $\\b x_S(s)$. Hence, showing that $\\b x_S(s)$ is everywhere tangent to $\\b u$ is equivalent to showing that $\\b u \\cdot \\nabla \\psi = 0$ everywhere. The latter is straightforward using relation~\\eqref{eq:u-psi} :\n\\begin{equation}\n\t\\b u \\cdot \\nabla \\psi = -\\frac{\\partial \\psi}{\\partial z}\\frac{\\partial \\psi}{\\partial y} + \\frac{\\partial \\psi}{\\partial y}\\frac{\\partial \\psi}{\\partial z} = 0,\n\\end{equation}\nwhich concludes the proof.\n\nNow we show another interesting property of the streamlines, namely that the \\textit{volume flow rate} between two streamlines of values $\\psi_1$ and $\\psi_2$ is equal to the difference of those streamlines, $\\psi_1 - \\psi_2$. To show that, consider two infinitely close points $\\b x_1 = (y_1,\\, z_1)$ and $\\b x_1 + \\rm d \\b x = (y_1 + \\rm dy,\\, z_1 + \\rm dz)$. At those points, the streamfunction has values $\\psi(y_1,z_1) = \\psi_1$ and $\\psi(y_1+\\rm dy,z_1 + \\rm dz) = \\psi_1 + \\rm d\\psi$. Let us now consider the volume flow rate $\\rm dq$ accross the infinitesimal segment $[\\b x_1,\\, \\b x_1 + \\rm d \\b x]$, positive in the right-hand side direction of the segment if the latter is directed from $\\b x_1$ to $\\b x_1 + \\rm d \\b x$. It is equal to $\\b u \\cdot \\hat{\\b{n}}$, where $\\hat{\\b{n}} = (\\rm dz,\\,-\\rm dy)$ is the unit normal to the segment, oriented in the right-hand side direction. Hence, $\\rm dq = v \\rm dz - w \\rm dy$, which, using relation~\\eqref{eq:u-psi}, amounts to\n\\begin{equation}\n\t\\rm dq = - \\rm d\\psi.\n\\end{equation}\nNow, consider any two points $\\b x_1 = (y_1, z_1)$ and $\\b x_2 = (y_2, z_2)$ in the (connected) domain. The volume flow rate $q_{1 \\rightarrow 2}$ accross any curve $\\gamma_{1 \\rightarrow 2}$ connecting $\\b x_1$ to $\\b x_2$, positive in the right-hand side direction of the directed segment $[\\b x_1,\\, \\b x_2]$ is\n\\begin{equation}\n\tq_{1 \\rightarrow 2} = \\int_{\\gamma_{1 \\rightarrow 2}} \\rm dq = \\int_{\\b x_1}^{\\b x_2} (-\\rm d\\psi) = \\psi(y_1,z_1) - \\psi(y_2,z_2), \t\n\\end{equation} \nwhere $\\int_{\\gamma_{1 \\rightarrow 2}}$ is the line integral along a curve connecting $\\b x_1$ to $\\b x_2$, afterwards noted $\\int_{\\b x_1}^{\\b x_2}$ to emphasize the fact that it does not depend on the integration path, since $\\rm d\\psi$ is an exact differential.\n\\end{tcolorbox}\n%----------------------------------------END STREAMFUNCTIONS-------------------------------------------%\nNow we are able to derive a relevant streamfunction. In particular, $\\psi$ must be such that the boundary conditions~\\eqref{eq:overturnerBC} are satisfied. Those conditions state that $\\b u$ must be tangent to the boundary everywhere on $\\partial \\Omega$, which precisely amounts to require that $\\psi$ is constant on $\\partial \\Omega$. Without loss of generality, we can choose this constant to be zero. Hence, we require that \n\\begin{equation}\n\t\\psi(0,z) = 0, \\quad \\psi(L,z) = 0, \\quad \\psi(y,0) = 0 \\quad \\mbox{and} \\quad \\psi(y,H) = 0, \\quad \\mbox{for all $(y,z) \\in \\Omega$}.\n\\end{equation}\n\\textcolor{red}{Faire des liens avec chapitre précédent} In order to build an acceptable idealisation of the meridian circulation in the Atlantic ocean, \\textit{Deleersnijder} proposes in his working paper \\cite{deleersnijder2006overturner} to suppose that the meridian streamfunction has a unique extremum $\\Psi$, which is a maximum, and that it reaches that maximum at the point of coordinates $(y_0,z_0)$, located near the surface and the North boundary of the domain. It is important to recall that the second partial derivatives of $\\psi$ must exist and be continuous for the above relations to hold.\n\nLet $\\xi_0 \\in \\mathbb{R}_0^+$, and let $\\phi(\\xi,\\xi_0)$ be defined as\n\\begin{equation} \\label{eq:phi}\n\t\\phi(\\xi,\\xi_0) = \\frac{\\xi(2\\xi_0-\\xi)}{\\xi_0^2},\n\\end{equation}\nThe derivative $\\phi'(\\xi,\\xi_0)$ of $\\phi$ with respect to $\\xi$ is\n\\begin{equation}\n\t\\phi'(\\xi,\\xi_0) = \\frac{2(\\xi_0-\\xi)}{\\xi_0^2}.\n\\end{equation}\nAn expression of the meridian streamfunction that satisfies the above constraints is then\n\\begin{equation} \\label{eq:psi_overturner}\n\t\\psi(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrr}\n\t\t\t\\phi(y,y_0)\\phi(z,z_0) & \\mbox{if} & 0 \\le y < y_0, \\phantom{z_0}0 \\le z < z_0,\\\\\n\t\t\t\\phi(y,y_0)\\phi(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, \\phantom{0}z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, \\phantom{0}z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi(z,z_0) & \\mbox{if} & y_0 < y \\le L, \\phantom{z_0}0 \\le z < z_0.\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nAs such, $\\psi$ is undefined along the lines $y = y_0$ and $z = z_0$. We consider thus the continuous prolongation of $\\psi$ at those points. Hence, \n\\begin{equation} \\label{eq:psi_y0}\n\t\\psi(y_0,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrr}\n\t\t\t\\phi(z,z_0) & \\mbox{if} & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(H-z,H-z_0) & \\mbox{if} & z_0 < z \\le H,\\\\\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\n\\begin{equation} \\label{eq:psi_z0}\n\t\\psi(y,z_0) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrr}\n\t\t\t\\phi(y,y_0) & \\mbox{if} & 0 \\le y < y_0,\\\\\n\t\t\t\\phi(L-y,L-y_0) & \\mbox{if} & y_0 < y \\le L,\\\\\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nand\n\\begin{equation}\n\t\\psi(y_0,z_0) = \\Psi.\n\\end{equation}\n\nThe meridian and vertical components of the velocity are then expressed as\n\\begin{equation} \\label{eq:v_overturner}\n\tv(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\t- \\phi(y,y_0)\\phi'(z,z_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi(y,y_0)\\phi'(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, & z_0 < z \\le H,\\\\\n\t\t\t\\phi(L-y,L-y_0)\\phi'(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi(L-y,L-y_0)\\phi'(z,z_0) & \\mbox{if} & y_0 < y \\le L, & 0 \\le z < z_0,\\\\\n\t\t\t- \\phi'(z,z_0) & \\mbox{if} & y = y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(H-z,H-z_0) & \\mbox{if} & y = y_0, & z_0 < z \\le H,\\\\\n\t\t\t0 & \\mbox{if} &0 \\le y \\le L, & z = z_0.\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nand\n\\begin{equation} \\label{eq:w_overturner}\n\tw(y,z) = \\Psi\\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\t\\phi'(y,y_0)\\phi(z,z_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(y,y_0)\\phi(H-z,H-z_0) & \\mbox{if} & 0 \\le y < y_0, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi'(L-y,L-y_0)\\phi(H-z,H-z_0) & \\mbox{if} & y_0 < y \\le L, & z_0 < z \\le H,\\\\\n\t\t\t- \\phi'(L-y,L-y_0)\\phi(z,z_0) & \\mbox{if} & y_0 < y \\le L, & 0 \\le z < z_0,\\\\\n\t\t\t\\phi'(y,y_0) & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z = z_0,\\\\\n\t\t\t- \\phi'(L-y,L-y_0) & \\mbox{if} & y_0 < y \\le L, & z = z_0,\\\\\n\t\t\t0 & \\mbox{if} & y = y_0. &\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\n\n\\subsection{Estimation of the parameter values}\n\\textcolor{red}{Vérifier que c'est bien les valeurs finales}\nThe numerical values used here are based on personal communications with \\textit{E. Deleersnijder}.\nThe model for the idealised meridian velocity field in the Atlantic ocean will be complete once we have assigned plausible values to the parameters. For this purpose, some physical insight is needed. First, the Atlantic ocean extends approximately from $50\\degree$ South to $60\\degree$ North, hence over $\\frac{11}{18}\\pi$ radians. With the radius of the Earth estimated to $6\\,371$ km, we get that $L$ must be close to $(\\frac{11}{18}\\pi) (6\\,371) = 12\\, 231$ km. Moreover, the mean depth of the Atlantic ocean is about $4$ km. Hence, we choose $L = 12\\,000$ km and $H = 4$ km. In virtue of the properties of the streamfunction, the maximum $\\Psi = \\psi(y_0,z_0)$ of the meridian streamfunction is equal to the volume flow rate accross any curve connecting $(y_0,z_0)$ to a point on the boundary of the domain: it is thus a measure of the intensity of the meridian circulation. With an estimated rate of deep convection in the Atlantic ocean of about $20$ Sv and a mean width of about $5\\,000$ km, this yields $\\Psi = 4$ $\\rm{m^2/s}$. Finally, we use $y_0 = 11\\,000$ km and $z_0 = 3.5$ km based on qualitative inspection of the meridian streamfunction graph. Characteristic values $V$ and $W$ of the meridional and vertical speed are, in virtue of relations~\\eqref{eq:u-psi} :\n\\begin{equation}\\label{eq:VW}\n\tV = \\frac{\\Psi}{H} \\quad \\mbox{and} \\quad W = \\frac{\\Psi}{L}.\n\\end{equation}\nAccording to \\textit{E. Deleersnijder} [personal communication], the characteristic time scale $T$ should be of the order of a few hundred years in order to be physically significant. It is expressed as\n\\begin{equation} \\label{eq:T}\n\tT = \\frac{L}{V} = \\frac{H}{W} = \\frac{LH}{\\Psi} = 1.5\\e{6} \\mbox{ s} \\approx 475.6 \\mbox{ years},\n\\end{equation}\nan acceptable value.\n\nWith those values of the parameters, the isolines of the adimensional streamfunction $\\psi/\\Psi$ are shown in figure~\\ref{fig:psi_overturner}, and the meridional and vertical components of the velocity field are illustrated in figure~\\ref{fig:vw_overturner}.\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.6\\textwidth]{fig/overturner/psi.eps}\n\t\\caption{Some isolines of the adimensional meridian streamfunction $\\psi(y,z)/\\Psi$, which are also streamlines of the idealised meridian circulation in the Atlantic ocean.}\n\t\\label{fig:psi_overturner}\n\\end{figure}\n\n\\begin{figure}[ht]\n\t\\centering\n\t\\begin{subfigure}[t]{0.4\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/overturner/V_samecaxis.eps}\n\t\t\\caption{$v(y,z)$.}\n\t\t\\label{fig:v_overturner}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.4\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{fig/overturner/W_samecaxis.eps}\n\t\t\\caption{$w(y,z)$.}\n\t\t\\label{fig:w_overturner}\n\t\\end{subfigure}\n\t\\begin{subfigure}[t]{0.1\\textwidth}\n\t\t\\includegraphics[height = 4\\textwidth]{fig/overturner/colorbarVW.eps}\n\t\\end{subfigure}\n\t\\caption{Meridional and vertical components of the idealised velocity fields in the adimensional domain. Here, $y_0 = \\frac{11}{12}L$ and $z_0 = \\frac{7}{8}H$.}\n\t\\label{fig:vw_overturner}\n\\end{figure}\n\n\\subsection{Injection of a passive tracer into the ocean} \\label{sec:transport_overturner}\nThe fate of a passive tracer injected at location $(y_*,z_*)$ into the idealised Atlantic ocean depicted previously can be described by a differential problem on that tracer's concentration. The tracer could be any passive tracer whose concentration in the athmosphere is negligible, for example a dye or a set of seawater particles initially located at $(y_*,z_*)$. The concentration of the tracer $C(t,y,z)$ in the ocean obeys the following partial differential equation :\n\\begin{equation}\\label{eq:C_PDE_vec}\n\t\\frac{\\partial C}{\\partial t} = -\\nabla \\cdot \\left(\\b uC - \\b K \\nabla C\\right),\n\\end{equation}\nwhere $\\b K$ is the \\textit{diffusivity tensor}. Without loss of generality, we can assume $\\b K$ to be symmetric. This is essentially because the impact of the anti-symmetric part of $\\b K$, if any, may be viewed as additional advection. More details may be found in appendix A of \\cite{deleersnijder2001concept}. Of course, the symmetric tensor $\\b K$ must then be positive-definite in order to represent truly diffusive processes, namely phenoma which tend, at any time and location, to homogenise the concentration of any constituent. For our problem, we consider that $\\b K$ has the form\n\\begin{equation} \\label{eq:K}\n\t\\b K(y,z) = \\begin{pmatrix} K_h & 0 \\\\ 0 & K_v(y,z) \\end{pmatrix},\n\\end{equation}\nwhere $K_h$ is a positive constant and\n\\begin{equation} \\label{eq:Kv}\n\tK_v(y,z) = \\left\\{ \n\t\t\\begin{array}{lrrr}\n\t\t\tK_{v_1} & \\mbox{if} & y_0 \\le y \\le L, & 0 \\le z \\le H,\\\\\n\t\t\tK_{v_2} & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\tK_{v_3} & \\mbox{if} & 0 \\le y < y_0, & z_0 \\le z \\le H,\n\t\t\\end{array}\n\t\\right.\n\\end{equation}\nwith $K_{v_1}$, $K_{v_2}$ and $K_{v_3}$ positive constants. In the framework of the idealised model of the meridian circulation in the Atlantic ocean, \\textit{E. Deleersnijder} [personal communication] proposes the values $K_h = 10^3$ $\\rm{m^2/s}$, $K_{v_1} = 10^{-1}$ $\\rm{m^2/s}$, $K_{v_2} = 10^{-4}$ $\\rm{m^2/s}$ and $K_{v_3} = 10^{-3}$ $\\rm{m^2/s}$. The relatively large value of $K_{v_1}$ allows to represent deep convection in the corresponding zone without having to implement a convective adjustment algorithm. The developped form of~\\eqref{eq:C_PDE_vec} is then\n\\begin{equation}\\label{eq:C_PDE_dev}\n\t\\frac{\\partial C}{\\partial t} = -\\frac{\\partial}{\\partial y}\\left(vC - K_h\\frac{\\partial C}{\\partial y}\\right) -\\frac{\\partial}{\\partial z}\\left(wC - K_v(y,z)\\frac{\\partial C}{\\partial z}\\right).\n\\end{equation}\nNo-flux conditions are imposed at the boundaries \\textcolor{red}{vérifier/discuter le flux nul à la surface}\n\\begin{equation}\\label{eq:C_PDE_BC}\n\t\\left. K_h\\frac{\\partial C}{\\partial y} \\right|_{y=0} = 0, \\quad  \\left. K_h\\frac{\\partial C}{\\partial y} \\right|_{y=L} = 0, \\quad \\left. K_v\\frac{\\partial C}{\\partial z} \\right|_{z=0} = 0, \\quad \\mbox{and} \\quad \\left. K_v\\frac{\\partial C}{\\partial z} \\right|_{z=H} = 0.\n\\end{equation}\nThe initial condition is\n\\begin{equation} \\label{eq:C_PDE_CI}\n\tC(0,y,z) = \\delta(y-y_*)\\delta(z-z_*),\n\\end{equation}\nwhere $\\delta$ is the Dirac delta function, such that\n\\begin{equation}\n\t\\int_0^L \\int_0^H C(0,y,z) \\rm dy \\rm dz = 1.\n\\end{equation}\n\nIn order to get a formulation of the problem using as few independant parameters as possible, it is interesting to consider the adimensional formulation. Such a scaling is particularly interesting for sensitivity analysis. The adimensional independant variables are\n\\begin{equation}\n\tt' = \\frac{t}{T} = \\frac{t\\Psi}{LH}, \\quad y' = \\frac{y}{L} \\quad \\mbox{and} \\quad z' = \\frac{z}{H},   \t\n\\end{equation}\nwhere $T$ is the time scale introduced in~\\eqref{eq:T}. The adimensional hydrodynamic variables are:\n\\begin{equation}\n\t\\psi' = \\frac{\\psi}{\\Psi}, \\quad v' = \\frac{v}{V} = \\frac{vH}{\\Psi}, \\quad \\mbox{and} \\quad w' = \\frac{w}{W} = \\frac{wL}{\\Psi},\n\\end{equation}\nwhere $V$ and $W$ are the velocity scales introduced in~\\eqref{eq:VW}. The adimensional concentration is\n\\begin{equation}\n\tC' = \\frac{C}{C_r}, \t\n\\end{equation}\nwhere $C_r$ is a characteristic value of the concentration. We will see shortly that there is no needed to assign a particular value to $C_r$. The adimensional form of equation~\\eqref{eq:C_PDE_dev} is then\n\\begin{equation}\\label{eq:PDE_adim}\n\t\\frac{\\partial C'}{\\partial t'} = -\\frac{\\partial}{\\partial y'}\\left(v'C' - \\frac{1}{Pe_h}\\frac{\\partial C'}{\\partial y'}\\right) -\\frac{\\partial}{\\partial z'}\\left(w'C' - \\frac{1}{Pe_v(y,z)}\\frac{\\partial C'}{\\partial z'}\\right),\n\\end{equation}\nwhere\n\\begin{equation}\n\tPe_h = \\frac{\\Psi L}{K_h H} \\quad \\mbox{and} \\quad Pe_v(y,z) = \\frac{\\Psi H}{K_v(y,z)L}\n\\end{equation}\nare the horizontal and vertical Péclet numbers. They correspond to the ratio between the characteristic advective and diffusive velocity scales. Indeed, the horizontal and vertical diffusive velocity scales $V_{d}$ and $W_{d}$ are \n\\begin{equation}\n\tV_{d} = \\frac{K_h}{L} \\quad \\mbox{and} \\quad W_{d}(y,z) = \\frac{K_v(y,z)}{H}.\n\\end{equation}\nThere are three different vertical diffusive velocity scale depending on which zone of the ocean we consider \\textcolor{red}{Donner des noms aux zones dans le chap 1 : 1 = ?, 2 = \"Deep convection\" et 3 = \"surface flow\"}. The advective velocity scales $V$ and $W$ have already been introduced in~\\eqref{eq:VW}. The Péclet numbers may then be rewritten as\n\\begin{equation}\n\tPe_h = \\frac{V}{V_{d}} = 12, \n\\end{equation}\nand\n\\begin{equation}\n\tPe_{v}(y,z) =  \\frac{W}{W_{d}(y,z)}=  \\left\\{\n\t\\begin{array}{lrrr}\n\t\t\tPe_{v_1} = 1.33\\e{-2} & \\mbox{if} & y_0 \\le y \\le L, & 0 \\le z \\le H,\\\\\n\t\t\tPe_{v_2} = 13.3 & \\mbox{if} & 0 \\le y < y_0, & 0 \\le z < z_0,\\\\\n\t\t\tPe_{v_3} = 1.33 & \\mbox{if} & 0 \\le y < y_0, & z_0 \\le z \\le H.\n\t\\end{array}\n\t\\right.\n\\end{equation}\nThis shows that the advective and diffusive processes are of equal importance in the dynamics of our model, excepted in the zone of deep convection where the vertical diffusion dominates the vertical convection. This is because we have chosen to represent deep convection via a heavy vertical mixing in that zone. ", "meta": {"hexsha": "76d9d17a6e245788aca33bab6f4aa50ba5036c91", "size": 24079, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "inputs/overturner/overturner_old.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/overturner/overturner_old.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/overturner/overturner_old.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": 85.0848056537, "max_line_length": 1277, "alphanum_fraction": 0.6874454919, "num_tokens": 8224, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7663393139140106}}
{"text": "\\subsection{Line Integrals of Vector Fields}\r\n\\noindent\r\nOne can think of line integral of vector fields as the total work done by the vector field as it moves along some simple path.\r\n\\begin{align*}\r\n\tW &= \\int\\limits_{C}{\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\hat{T}\\mathrm{d}s} \\\\\r\n\t&= \\int\\limits_{C}{\\frac{\\vec{r^\\prime}(t)}{\\norm{\\vec{r^\\prime}(t)}} \\cdot \\norm{\\vec{r^\\prime}(t)}\\mathrm{d}t} \\\\\r\n\t&= \\int\\limits_{C}{\\left(\\vec{F}\\circ\\vec{r}\\right) \\cdot \\vec{r^\\prime}(t)\\mathrm{d}t} = \\int\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}}\r\n\\end{align*}\r\n\r\n\\noindent\r\nFor example, let's find the line integral of $\\vec{r}(t) = \\langle t, t^2, t \\rangle$ for $0 \\leq t \\leq 1$ in the vector field $\\vec{F}(x,y,z) = \\langle e^z, \\sqrt{1-x^2}, \\sin{x} \\rangle$.\r\n\\begin{equation*}\r\n\t\\vec{F}\\circ\\vec{r} = \\langle e^t, \\sqrt{1-t^2}, \\sin{t}\\rangle\t\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\vec{r^\\prime}(t) = \\langle 1, 2t, 1 \\rangle\t\r\n\\end{equation*}\r\n\\begin{align*}\r\n\t\\int_{0}^{1}{\\langle e^t, \\sqrt{1-t^2}, \\sin{t} \\rangle \\cdot \\langle 1, 2t, 1 \\rangle\\mathrm{d}t} &= \\int_{0}^{1}{e^t + 2t\\sqrt{1 - t^2} + \\sin{t}\\mathrm{d}t} \\\\\r\n\t&= e - \\cos{1} + \\frac{2}{3}\r\n\\end{align*}\r\n\r\n\\input{./lineSurfaceIntegrals/directionMatters}\r\n\\input{./lineSurfaceIntegrals/circulations}", "meta": {"hexsha": "f429ce7c8d10b9109d01bd9e3a89482567f28ea5", "size": 1271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsVFs.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsVFs.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/lineIntegralsVFs.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": 52.9583333333, "max_line_length": 191, "alphanum_fraction": 0.6231313926, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8376199653600372, "lm_q1q2_score": 0.7663393062290846}}
{"text": "\\chapter{Angular momentum}\n\\section{Angular momentum }\nThe angular momentum of a particle about a point is defined in position vector of a particle with the given point as the origin of the co-ordinate system and $p$ is the linear momentum.\n\nAnalogically in quantum mechanics there exist quantum mechanically orbital angular momentum is defined as\n$$\nL=L_{x} \\hat{i}+L_{y} \\hat{j}+L_{z} \\hat{k}\n$$\nwhere\n $$L_{x}=Y P_{z}-Z P_{y}$$\n$$ L_{y}=Z P_{x}-X P_{z}$$\n $$L_{z}=X P_{y}-Y P_{x}$$\nwhere $X, Y, Z$ are position operator in $x, y, z$ direction \\\\\nand $p_{1}, p_{y}, p_{z}$ momentum in respective\n$x, y, z$ direction it is given that \\\\\n$$P_{x}=-i \\hbar \\frac{\\partial}{\\partial x},$$\n$$ P_{v}=-i \\hbar \\frac{\\partial}{\\partial y}$$\n $$P_{z}=-i \\hbar \\frac{\\partial}{\\partial z}$$\nIn quantum mechanics one can defined the Hermitian operator\n$$\nL^{2}=L_{x}^{2}+L_{y}^{2}+L_{z}^{2}\n$$\n\\textbf{Commutation relation}\n$$\n\\begin{array}{lll}\n{\\left[\\hat{L}_{x}, \\hat{L}_{y}\\right]=i \\hbar \\hat{L}_{z}} & {\\left[\\hat{L}_{y}, \\hat{L}_{z}\\right]=i \\hbar \\hat{L}_{x}} & {\\left[\\hat{L}_{z}, \\hat{L}_{x}\\right]=i \\hbar \\hat{L}_{y}} \\\\\n{\\left[\\hat{L}_{y}, \\hat{L}_{x}\\right]=-i \\hbar \\hat{L}_{z}} & {\\left[\\hat{L}_{z}, \\hat{L}_{y}\\right]=-i \\hbar \\hat{L}_{x}} & {\\left[\\hat{L}_{x}, \\hat{L}_{z}\\right]=-i \\hbar \\hat{L}_{y}}\n\\end{array}\n$$\ni.e. the components of the orbital angular momentums cannot be measured simultaneously accurately.\n$$\n\\left[\\hat{L}^{2}, \\hat{L}_{x}\\right]=0\n$$\n$$\n\\left[\\hat{L}^{2}, \\hat{L}_{y}\\right]=0 \\quad\\left[\\hat{L}^{2}, \\hat{L}_{z}\\right]=0\n$$\ni.e. square of the orbital angular momentum commutes with any one of components of the orbital angular momentum.\n$$\n\\left[\\hat{L}_{x}, \\hat{p}_{x}\\right]=0\n$$\n$$\n\\left[\\hat{L}_{y}, \\hat{p}_{y}\\right]=0 \\quad\\left[\\hat{L}_{z}, \\hat{p}_{z}\\right]=0\n$$\n$$\\begin{array}{lll}\n\t{\\left[\\hat{L}_{x}, \\hat{p}_{y}\\right]=i \\hbar \\hat{p}_{z}} & {\\left[\\hat{L}_{y}, \\hat{p}_{z}\\right]=i \\hbar \\hat{p}_{x}} & {\\left[\\hat{L}_{z}, \\hat{p}_{x}\\right]=i \\hbar \\hat{p}_{y}} \\\\\n\t{\\left[\\hat{L}_{x}, \\hat{x}\\right]=0} & {\\left[\\hat{L}_{y}, \\hat{y}\\right]=0} & {\\left[\\hat{L}_{z}, \\hat{z}\\right]=0} \\\\\n\t{\\left[\\hat{L}_{x}, \\hat{y}\\right]=i \\hbar \\hat{z}} & {\\left[\\hat{L}_{y}, \\hat{z}\\right]=i \\hbar \\hat{x}} & {\\left[\\hat{L}_{z}, \\hat{x}\\right]=i \\hbar \\hat{y}}\n\\end{array}$$\n\\subsection{Orbital angular momentum in sperical polar coordinates }\n\n\t$$L_{x}=i\\hbar\\left(\\sin \\phi \\frac{\\partial}{\\partial \\theta}+\\cos \\phi \\cot \\theta \\frac{\\partial}{\\partial \\phi}\\right) $$\n\t$$L_{y}=i \\hbar\\left(-\\cos \\phi \\frac{\\partial}{\\partial \\theta}+\\sin \\phi \\cot \\theta \\frac{\\partial}{\\partial \\phi}\\right) \\text { and }$$\n\t$$L_{z}=-i \\hbar \\frac{\\partial}{\\partial \\phi}$$\n\n\\subsection{eigen value and eigen vector of $L^2$ and $L_z$}\nSince,the commutator bracket $\\left[ L^2,L_z\\right] =0$ therefore $L^2$ and $L_z$ can be measured simultaneously accurately and both have simultaneous eigenfunctions and eigenkets.Denoting the simultaneous eigen kets $|l,m_l\\rangle $ (Where l and $m_l$ are the orbital quantum number magnetic quantum number respectevely),the eigen value equation for $L^2$ and $L_z$ can be written as \n$$\\begin{aligned}\n\t&\\hat{L}^{2}\\left|l, m_{l}\\right\\rangle=l(l+1) \\hbar^{2}\\left|l, m_{l}\\right\\rangle \\\\\n\t&\\hat{L}_{z}\\left|l, m_{l}\\right\\rangle=m_{l} \\hbar\\left|l, m_{l}\\right\\rangle\n\\end{aligned}$$\n$\\text { Alternate form: Since, } \\hat{L}^{2} \\text { and } \\hat{L}_{z} \\text { depends on } \\theta, \\phi \\text { then their eigen function is function of } \\theta, \\phi \\text { i.e. }$\n$$\\begin{aligned}\n\t&\\hat{L}^{2} Y_{\\ell, m_{l}}(\\theta, \\phi)=\\ell(\\ell+1) \\hbar^{2} Y_{\\ell, m_{l}}(\\theta, \\phi) \\\\\n\t&\\hat{L}_{z} Y_{\\ell, m_{l}}(\\theta, \\phi)=m_{l} \\hbar Y_{\\ell, m_{l}}(\\theta, \\phi)\n\\end{aligned}$$\n$\\text { where } Y_{\\ell, m}(\\theta, \\phi) \\text { is said to be Spherical Harmonics and defined as }$\n$$Y_{l, m_{l}}(\\theta, \\varphi)=\\varepsilon \\sqrt{\\left(\\frac{2 \\ell+1}{4 \\pi}\\right) \\frac{\\left(\\ell-\\left|m_{l}\\right|\\right) !}{\\left(\\ell+\\left|m_{l}\\right|\\right) !}} P_{\\ell}^{\\left|m_{l}\\right|}(\\cos \\theta) e^{i m_{l} \\phi}$$\n$\\text { where } \\varepsilon=(-1)^{m_{l}} \\text { for } m_{l}>0 \\text { and } \\varepsilon=1 \\text { for } m_{l} \\leq 0 \\text {. }$\\\\\n\\subsection{Lowering and raising operators}\n\t$$\\text { Raising Operator: }  \\hat{L}_{+}=\\hat{L}_{x}+i \\hat{L}_{y}$$\n\t$$\\text { Lowering Operator: }  \\hat{L}_{-}=\\hat{L}_{x}-i \\hat{L}_{y}$$\n\\textbf{Important relations:}\n$$\n\\begin{array}{lll}\n{\\left[\\hat{L}_{z}, \\hat{L}_{+}\\right]=\\hbar \\hat{L}_{+}} & {\\left[\\hat{L}_{z}, \\hat{L}_{-}\\right]=-\\hbar \\hat{L}_{-}} & {\\left[\\hat{L}_{x}, \\hat{L}_{+}\\right]=-\\hbar \\hat{L}_{z} \\quad\\left[\\hat{L}_{x}, \\hat{L}_{-}\\right]=\\hbar \\hat{L}_{z}} \\\\\n{\\left[\\hat{L}_{y}, \\hat{L}_{+}\\right]=-i \\hbar \\hat{L}_{z}} & {\\left[\\hat{L}_{y}, \\hat{L}_{-}\\right]=i \\hbar \\hat{L}_{z}} & {\\left[\\hat{L}_{+}, \\hat{L}_{-}\\right]=2 \\hbar \\hat{L}_{z}} \\\\\n\\hat{L}_{+} \\hat{L}_{-}=\\hat{L}^{2}-\\hat{L}_{z}^{2}+\\hbar \\hat{L}_{z} & \\hat{L}_{-} \\hat{L}_{+}=\\hat{L}^{2}-\\hat{L}_{z}^{2}-\\hbar \\hat{L}_{z}\n\\end{array}\n$$\n$\\text { Action of } \\hat{L}_{+} \\text {and } \\hat{L}_{-}:$\n$$\\begin{aligned}\n\t&\\hat{L}_{+}\\left|l, m_{l}\\right\\rangle=\\sqrt{\\left(\\ell-m_{l}\\right)\\left(l+m_{l}+1\\right)} \\hbar\\left|l, m_{l}+1\\right\\rangle \\\\\n\t&\\hat{L}_{+} Y_{\\ell, m_{l}}(\\theta, \\phi)=\\sqrt{\\left(\\ell-m_{l}\\right)\\left(l+m_{l}+1\\right)} \\hbar Y_{i, m_{i}+1}(\\theta, \\phi)\n\\end{aligned}$$\n$$\\begin{aligned}\n\t&\\hat{L}_{-}\\left|l, m_{l}\\right\\rangle=\\sqrt{\\left(\\ell+m_{l}\\right)\\left(l-m_{l}+1\\right)} \\hbar\\left|l, m_{l}-1\\right\\rangle \\\\\n\t&\\hat{L}_{-} Y_{\\left(, m_{l}\\right.}(\\theta, \\phi)=\\sqrt{\\left(\\ell+m_{l}\\right)\\left(l-m_{l}+1\\right)} \\hbar Y_{\\ell, m_{l}-1}(\\theta, \\phi)\n\\end{aligned}$$\n\\subsection{ Matrix Representation of the operators:}\nElements of $\\hat{L}^{2}=\\left\\langle\\ell^{\\prime}, m_{l}^{\\prime}\\left|\\hat{L}^{2}\\right| \\ell, m_{l}\\right\\rangle=\\ell(\\ell+1) \\hbar^{2} \\delta_{\\ell \\ell^{\\prime}} \\delta_{m_{l} m_{l}^{\\prime}}$, will be non-zero for $l=l^{\\prime}$ and $m_{l}=m_{l^{\\prime}}$ is\n$$\n\\hat{L}^{2}=\\left[\\begin{array}{lll}\n2 \\hbar^{2} & 0 & 0 \\\\\n0 & 2 \\hbar^{2} & 0 \\\\\n0 & 0 & 2 \\hbar^{2}\n\\end{array}\\right]=2 \\hbar^{2}\\left[\\begin{array}{lll}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{array}\\right](\\text { for } l=1)\n$$\nElements of $\\hat{L}_{z}=\\left\\langle\\ell^{\\prime}, m_{l}^{\\prime}\\left|\\hat{L}_{z}\\right| \\ell, m_{l}\\right\\rangle=m_{l} \\hbar \\delta_{\\ell \\ell^{\\prime}} \\delta_{m_{l} m_{l}^{\\prime}}$, will be non-zero for $l=l^{\\prime}$ and $m_{l}=m_{l}^{\\prime}$ i.e.\n$$\n\\hat{L}_{z}=\\left[\\begin{array}{ccc}\n\\hbar & 0 & 0 \\\\\n0 & 0 & 0 \\\\\n0 & 0 & -\\hbar\n\\end{array}\\right]=\\hbar\\left[\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & 0 & 0 \\\\\n0 & 0 & -1\n\\end{array}\\right](\\text { for } l=1)\n$$\nElements of $\\hat{L}_{+}=\\left\\langle\\ell^{\\prime}, m_{l}^{\\prime}\\left|\\hat{L}_{+}\\right| \\ell, m_{l}\\right\\rangle=\\hbar \\sqrt{\\left(\\ell-m_{l}\\right)\\left(\\ell+m_{l}+1\\right)} \\delta_{\\ell \\ell^{\\prime}} \\delta_{m_{l}^{\\prime}, m_{l}+1}$, will be non-zero for $l=l^{\\prime}$ and $m_{l}=m_{l}^{\\prime}+1$ i.e.\\\\\n$$\\hat{L}_{+}=\\left[\\begin{array}{lll}\n\t0 & \\sqrt{2} \\hbar & 0 \\\\\n\t0 & 0 & \\sqrt{2} \\hbar \\\\\n\t0 & 0 & 0\n\\end{array}\\right]=\\sqrt{2} \\hbar\\left[\\begin{array}{lll}\n\t0 & 1 & 0 \\\\\n\t0 & 0 & 1 \\\\\n\t0 & 0 & 0\n\\end{array}\\right] \\quad(\\text { for } l=1)$$\nElements of $\\hat{L}_{+}=\\left\\langle\\ell^{\\prime}, m_{l}^{\\prime}\\left|\\hat{L}_{-}\\right| \\ell, m_{l}\\right\\rangle=\\hbar \\sqrt{\\left(\\ell+m_{l}\\right)\\left(\\ell-m_{l}+1\\right)} \\delta_{\\ell \\ell}, \\delta_{m_{l},} m_{l}-1$, will be non-zero for $l=l^{\\prime}$ and $m_{l}=m_{l}^{\\prime}-1$ i.e.\n$$\n\\hat{L}_{-}=\\sqrt{2} \\hbar\\left[\\begin{array}{lll}\n0 & 0 & 0 \\\\\n1 & 0 & 0 \\\\\n0 & 1 & 0\n\\end{array}\\right] \\quad(\\text { for } l=1)\n$$\n\\textbf{Expectation values in the state $\\left|\\ell, \\mathbf{m}_{\\ell}\\right\\rangle$ :}\n$$\n\\begin{aligned}\n&\\left\\langle\\hat{L}_{x}\\right\\rangle=0,\\left\\langle\\hat{L}_{y}\\right\\rangle=0,\\left\\langle\\hat{L}_{z}\\right\\rangle=m_{l} \\hbar \\\\\n&\\left\\langle\\hat{L}_{x}^{2}\\right\\rangle=\\left\\langle\\hat{L}_{y}^{2}\\right\\rangle=\\frac{\\hbar^{2}}{2}\\left[\\ell(\\ell+1)-m_{l}^{2}\\right],\\left\\langle\\hat{L}_{z}^{2}\\right\\rangle=m_{l}^{2} \\hbar^{2}\n\\end{aligned}\n$$\n\\begin{exercise}\n\t$\\text { The expectation value of the operator } \\hat{L}_{+} \\text {in the state }|\\psi\\rangle=\\frac{1}{\\sqrt{3}}[|1,1\\rangle+|1,0\\rangle+|1,-1\\rangle] \\text { is }$\n\\end{exercise}\n\\begin{answer}\n$\\begin{gathered}\n\\left\\langle L_{+}\\right\\rangle=\\frac{1}{3}\\left[\\left\\langle 11\\left|L_{+}\\right| 11\\right\\rangle+\\left\\langle 11\\left|L_{+}\\right| 10\\right\\rangle+\\left\\langle 11\\left|L_{+}\\right| 1-1\\right\\rangle+\\left\\langle 10\\left|L_{+}\\right| 11\\right\\rangle+\\left\\langle 10\\left|L_{+}\\right| 10\\right\\rangle+\\left\\langle 10\\left|L_{+}\\right| 1-1\\right\\rangle\\right. \\\\\n\\left.+\\left\\langle 1-1\\left|L_{+}\\right| 11\\right\\rangle+\\left\\langle 1-1\\left|L_{+}\\right| 10\\right\\rangle+\\left\\langle 1-1\\left|L_{+}\\right| 1-1\\right\\rangle\\right]\n\\end{gathered}$\n$L_{+}$ will raise the value of m to $m+1$ .Only those terms will survive in which this raised values of min the ket is equal to the value of m in the bra. Thus ,\\\\\n$\\left\\langle L_{+}\\right\\rangle=\\frac{1}{3}\\left[\\left\\langle 11\\left|L_{+}\\right| 10\\right\\rangle+\\left\\langle 10\\left|L_{+}\\right| 1-1\\right\\rangle\\right]=\\frac{1}{3}[\\langle 11|\\sqrt{2} \\hbar| 11\\rangle+\\langle 10|\\sqrt{2} \\hbar| 10\\rangle]=\\frac{2 \\sqrt{2} \\hbar}{3}$\t\n\\end{answer}\n\\section{Angular momentum algebra}\nGeneralised angular momentum is defined as $J=J_{x} \\hat{i}+J_{y} \\hat{j}+J_{z} \\hat{k}$\\\\\\\\\n The commutation \\hspace{1cm}$\\left[J_{x} J_{y}\\right]=i \\hbar J_{z} \\hspace{1cm} \\left[J_{y}, J_{z}\\right]=i \\hbar J_{x}\\hspace{1cm}\\left[J_{z} J_{x}\\right]=i \\hbar J_{y}$\\\\\\\\\n  The state $|j, m\\rangle$ make complete basis so\\\\\n  $$\\begin{array}{lr}\n  \tJ^{2}|j, m\\rangle=j(j+1) \\hbar^{2}|j, m\\rangle & j=0,1,2,3, \\ldots \\\\\\\\\n  \tJ_{z}|j, m\\rangle=m \\hbar|j, m\\rangle & -j<m<j\n  \\end{array}$$\\\\\n  It is also given that $$\\left[J^{2}, J_{x}\\right]=0,\\quad \\left[J^{2}, J_{y}\\right]=0 \\quad\\left[J^{2}, J_{z}\\right]=0$$\n  The completeness relation is given as $$\\sum_{m=-j}^{j} \\sum_{j=0}^{j}|j, m\\rangle\\langle j, m|=1$$\n\\textbf{The raising and lowering operators.}\\\\\n$$\nJ_{+}=J_{x}+i J_{y}\n$$\n$$\nJ_{-}=J_{x}-i J_{y}\n$$\nOne can calculate\n$$\n\\left[J_{z}, J_{+}\\right]=\\hbar J_{+} \\quad\\left[J_{z}, J_{-}\\right]=-\\hbar J_{-} \\quad\\left[J^{2}, J_{+}\\right]=0 \\quad\\left[J^{2}, J_{-}\\right]=0\n$$\nSo $J^{2}$, and $J_{+}$and $J$ - can be simultaneously measured.\\\\\\\\\n\\textbf{The state $J_{+}|j, m\\rangle$}\n$$\n\\begin{array}{ll}\n{\\left[J_{z}, J_{+}\\right]=\\hbar J_{+}} & J_{z}, J_{+}-J_{+} J_{z}=\\hbar J_{+} \\\\\nJ_{z} J_{+}|j, m\\rangle-J_{+} J_{z}|j, m\\rangle=\\hbar J_{+} & J_{z}\\left(J_{+}|j, m\\rangle\\right)=(m+1) \\hbar J_{+}|j, m\\rangle\n\\end{array}\n$$\nSo $J_{+}|j m\\rangle$ is eigen vector of $J_{z}$ with the eigen value $(m+1) \\hbar$ i.e., $J+|j m\\rangle$ can be represented as $$J_{+}|j, m\\rangle \\equiv C_{+}|j, m+1\\rangle$$\nNow one can find the value of $C_{+}$with orthonormal condition.\n$$\n\\left\\langle j, m\\left|J_{-} J_{+}\\right| j, m\\right\\rangle=\\left|C_{+}^{*}\\right|^{2} \\quad\\langle m+1, j \\mid j, m+1\\rangle$$ \n\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\\quad\\left|C_{+}^{*}\\right|^{2}=\\sqrt{j(j+1)-m(m+1)}\\\\\n\t\t\tJ_{+}|j, m\\rangle=\\sqrt{j(j+1)-m(m+1) \\hbar}|j, m+1\\rangle \n\t\t\t\\end{array}\n\t\t\t\\end{align*}} }\n\\end{center}\n\\hspace{4cm}For $j=m$\\hspace{1cm}\n $J_{+}|j  m\\rangle=0$\\hspace{1cm}\n$m \\leq j$\\\\\n\\textbf{The state $J_{-}|j, m\\rangle$}\\\\\nSimilarly one can find from the relation\n$$\\left[ J_z,J_{-}\\right] =-\\hbar J_{-}$$\nAnd $$J_z( J_{-}|j,m\\rangle =(m-1)\\hbar J_{-}|j,m\\rangle$$ $$J_{-}|j,m\\rangle=C_{-}|j,m-1\\rangle$$\nAgain $C_-$can be found with the relation\n\t$$\\left\\langle m, j\\left|J_{+} J_{-}\\right| j, m\\right\\rangle=\\left|C_{-}^{*}\\right|^{2} $$\n\t\\begin{center}\n\t\t\\framebox{\n\t\t\t\\parbox[t][3cm]{3.5cm}{\n\t\t\t\t\n\t\t\t\t\\addvspace{0.2cm} \\centering\n\t\t\t\t\n\t\t\t\t\\begin{align*}\n\t\t\t\t\\begin{array}{lll}\n\t\t\t \\left|C_{-}^{*}\\right|^{2}=\\sqrt{j(j+1)-m(m-1)} \\hbar|j, m-1\\rangle\\\\\n\t\t\t J_{-}|j, m\\rangle=\\sqrt{j(j+1)-m(m-1)} \\hbar|j, \\dot{m}-1\\rangle\n\t\t\t\t\\end{array}\n\t\t\t\t\\end{align*}} }\n\t\\end{center}\n$\n\\text { If } m=-j, J_{-}|j,-j\\rangle=0\n$\nSo again the $m \\geq-j$.\\\\\nSo the value of $-j<m<j$ the $J_{+}$and $J_{-}$can be named as ladder operator\n where\\\\\\\\ $J_{+}|j, m\\rangle=\\sqrt{j(j+1)-m(m+1)} \\hbar|j, m+1\\rangle$, which raise the state by $|j, m\\rangle$ to $|j, m+1\\rangle$ and\\\\\\\\\n $J_{-}|j, m\\rangle=\\sqrt{j(j+1)-m(m-1)} \\hbar|j, m+1\\rangle$ who lower the state $|j, m\\rangle$ to $|j, m-1\\rangle .$\n\\begin{exercise}\n Find the matrix representation of operator for $j=1$\\\\\n\t(a) $J^{2}$ and $J_{z}$\\\\\n\t(b) $J_{+}$and $J_{-}$\\\\\n\t(c) $J_{x}$ and $J_{y}$\n\\end{exercise}\n\\begin{answer}\n (a) For $j=1 m=-1,01$\n$$\nJ^{2}=\\left|\\begin{array}{ccc}\n\\left\\langle 1,1\\left|J^{2}\\right| 1,1\\right\\rangle & \\left\\langle 1,1\\left|J^{2}\\right| 1,0\\right\\rangle & \\left\\langle 1,1\\left|J^{2}\\right| 1,-1\\right\\rangle \\\\\n\\left\\langle 1,0\\left|J^{2}\\right| 1,1\\right\\rangle & \\left\\langle 1,0\\left|J^{2}\\right| 1,0\\right\\rangle & \\left\\langle 1,0\\left|J^{2}\\right| 1,-1\\right\\rangle \\\\\n\\left\\langle 1,-1\\left|J^{2}\\right| 1,1\\right\\rangle & \\left\\langle 1,-1\\left|J^{2}\\right| 1,0\\right\\rangle & \\left\\langle 1,-1\\left|J^{2}\\right| 1,-1\\right\\rangle\n\\end{array}\\right|=2 \\hbar^{2}\\left(\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{array}\\right)\n$$\n$\\text { Similarly, }$ $$J_{z}=\\hbar\\left(\\begin{array}{ccc}\n\t1 & 0 & 0 \\\\\n\t0 & 0 & 0 \\\\\n\t0 & 0 & -1\n\\end{array}\\right)$$\n$$J_{+}=h \\sqrt{2}\\left(\\begin{array}{lll}\n\t0 & 1 & 0 \\\\\n\t0 & 0 & 1 \\\\\n\t0 & 0 & 0\n\\end{array}\\right), J_{-}=\\hbar \\sqrt{2}\\left(\\begin{array}{lll}\n\t0 & 0 & 0 \\\\\n\t1 & 0 & 0 \\\\\n\t0 & 1 & 0\n\\end{array}\\right)$$\n$$J_{x}=\\frac{J_{+}+J_{-}}{2}=\\frac{h}{\\sqrt{2}}\\left(\\begin{array}{lll}\n\t0 & 1 & 0 \\\\\n\t1 & 0 & 1 \\\\\n\t0 & 1 & 0\n\\end{array}\\right),$$\n$$ j_{y}=\\frac{1}{2 i}\\left(J_{+}-J_{-}\\right)=\\frac{\\hbar}{\\sqrt{2}}\\left(\\begin{array}{ccc}\n\t0 & -i & 0 \\\\\n\ti & 0 & -i \\\\\n\t0 & i & 0\n\\end{array}\\right)$$\t\n\\end{answer}\n\\begin{exercise}\n (a) Find $\\left\\langle J_{x}\\right\\rangle,\\left\\langle J_{y}\\right\\rangle$\n\t(b) Find $\\left\\langle J_{x}^{2}\\right\\rangle,\\left\\langle J_{y}^{2}\\right\\rangle$\n\t(c) Find $\\Delta J_{x} \\cdot \\Delta J_{y}$\n\\end{exercise}\n\\begin{answer}\n\t$$\\begin{aligned}\n\t\t&\\text { (a) }\\left\\langle J_{x}\\right\\rangle=\\frac{1}{2}\\left(\\left\\langle J_{+}\\right\\rangle+\\left\\langle J_{-}\\right\\rangle\\right) \\\\\n\t\t&\\begin{aligned}\n\t\t\tJ_{x}|j, m\\rangle &=\\frac{1}{2}\\left(J_{+}|j, m\\rangle+J_{-}|j, m\\rangle\\right) \\\\\n\t\t\t&=\\frac{\\hbar}{2}(\\sqrt{j,(j+1)-m(m+1)}|j, m+1\\rangle+\\sqrt{j(j+1)-m(m-1)}|j, m-1\\rangle)\n\t\t\\end{aligned} \\\\\n\t\t&\\left\\langle j, m\\left|J_{,}\\right| j, m\\right\\rangle=\\frac{h}{2} \\sqrt{j(j+1)-m(m+1)}\\langle j, m \\mid j, m+1\\rangle \\\\\n\t\t&\\frac{\\hbar}{2} \\sqrt{j(j+1)-m(m-1)\\langle j, m \\mid j, m-1\\rangle}=0\n\t\\end{aligned}$$\n\t$\\text { Similarly }\\langle J_{y}\\rangle=0$\\\\\n\t$\\begin{aligned}\n\t(b)\t\\left\\langle J_{x}^{2}\\right\\rangle &=\\left\\langle\\frac{1}{2}\\left(J_{+}+J_{-}\\right)\\left(J_{+}+J_{-}\\right)\\right\\rangle \\\\\n\t\t&=\\frac{1}{4}\\left\\langle J_{+}^{2}+J_{+} J_{-}+J_{-} J_{+}+J_{-}^{2}\\right\\rangle=\\frac{1}{4}\\left\\langle J_{+}^{2}\\right\\rangle+\\frac{1}{4}\\left\\langle J_{+} J_{-}+J_{-} J_{+}\\right\\rangle+\\frac{1}{4}\\left\\langle J_{-}^{2}\\right\\rangle \\\\\n\t\t&=\\frac{1}{4}\\left\\langle J_{+}^{2}\\right\\rangle+\\frac{2}{4}\\left(J^{2}-J_{=}^{2}\\right)+\\frac{1}{4}\\left\\langle J_{-}^{2}\\right\\rangle=0+\\frac{\\hbar^{2}}{2}\\left(j(j+1)-m^{2}\\right)+0 \\cdot \\hbar^{2}\n\t\\end{aligned}$\\\\\n\t$$\n\t\\Rightarrow\\left\\langle J_{x}^{2}\\right\\rangle=\\frac{1}{2}\\left[j(j+1)-m^{2}\\right] \\cdot \\hbar^{2}\n\t$$\n\tSimilarly $\\left\\langle J_{y}^{2}\\right\\rangle=\\frac{1}{2}\\left[j(j+1)-m^{2}\\right] \\cdot \\hbar^{2} \\quad\\left\\langle J_{x}^{2}\\right\\rangle=\\left\\langle J_{y}^{2}\\right\\rangle$\\\\\n\t(c) $\\Delta J_{x}=\\sqrt{\\left\\langle J_{x}^{2}\\right\\rangle-\\left\\langle J_{x}\\right\\rangle^{2}}=\\sqrt{\\frac{1}{2}\\left(j(j+1)-m^{2}\\right)} \\hbar$\n\t$$\n\t\\Delta J_{y}=\\sqrt{\\left\\langle J_{y}^{2}\\right\\rangle-\\left\\langle J_{y}\\right\\rangle^{2}}=\\sqrt{\\frac{1}{2}\\left(j(j+1)-m^{2}\\right)} \\hbar \\text { so } \\Delta J_{x} \\Delta J_{y}=\\frac{1}{2}\\left(j(j+1)-m^{2}\\right) \\hbar^{2}\n\t$$\n\\end{answer}\n\\section{Concepts of spin in quantum mechanics}\n\\subsection{ The stern-Gerlach experiment}\nThe existance of spin is first confirmed experimentally by stern and Gerlack in 1922. Using silver (Ag) atoms. Silver has 47 electrons, out of which 46 electrons form a spherically symmetric charge distribution and $47^{\\text {th }}$. electron occupies a ' 5 s' orbital $(l=0)$. If the silver atom is its ground state, then its total orbital angular momentum will be zero.\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=5cm,width=10cm]{diagram-20220120(33)-crop}\n\t\\caption{}\n\t\\label{}\n\\end{figure}\nIf a beam of silver atoms passes through an in homogeneous (non-uniform) magnetic field (along z-direction), we would expect the following results:\\\\\n(i) Classically, there will be a continuous band on the screen and the band will be symmetric about theundeflected direction $\\mathrm{z}=0$.\\\\\n(ii) Accordinh to Schrodinger's wave theory, if the atom has an orbital angular momentum ' $l$ ' then the beam will split into discrete $(2 l+1)$ components. Since, the silver atom is in ground state $(l=0)$, there will be only spot on the screen.\nBut, in experiments the beam splits into two distinct components.\\\\\nTo solve this problem, Goudsmith and Unlenbeck postulated that in addition to its orbital angular momentum the electron possesses an intrinsic angular momentum. This angular momentum has no connection with the spaial degrees of freedom but it can be related with the internal rotational or spinning mation of the electron about its own axis. This is known as spin angular momentum which is connected with an intrinsic degree of freedom i.e. spin. Spin is a purely quantum mechanical concept with classical analog. Unlike orbital angular momentum, the spin cannot be described by a differential operator.\nConsider a particle of mass 'm' and charge ' $q$ ' is moving in a circle of radius ' $r$ '. The magnetic dipole moment due to the orbital motion of the particle will be\n$$\n\\vec{\\mu}_{L}=\\frac{q}{2 m} \\vec{L}\n$$\nwhere $\\vec{L}$ is the orbital angular momentum of the particle and z-components of magnetic moment will be\n$$\n\\mu_{z}=\\frac{q}{2 m} L_{z}\n$$\nFor an electron the relation will be $\\mu_{z}=-\\frac{e}{2 m_{e}} L_{z}$\\\\\nIf the electron is the eigenstates of $\\hat{L}_{z}$, then\n$$\n\\left(\\mu_{L}\\right)_{z}=-\\left(\\frac{e}{2 m_{e}}\\right) m_{l} \\hbar=-\\mu_{B} m_{l}\n$$\nwhere $\\left(\\frac{e \\hbar}{2 m_{e}}\\right)=\\mu_{B}=$ Bohr magneton and $m_{l}$ is the orbital magnetic quantum number.\\\\\n$\\text { Eor a narticular value of } l, \\text { we will get }(2 \\ell+1) \\text { values of ' } m_{l} \\text { ' i.e } m_{l}=-l,-l+1, \\ldots \\ldots \\ldots \\ldots, 0, \\ldots \\ldots, l-1, l$\\\\\nSimilarly, if we take electron as spinning charged sphere, then the magnetic dipole moment due to the motion of the particle will be\n$$\n\\vec{\\mu}_{S}=-g_{s} \\frac{e}{2 m} \\vec{S}\n$$\nwhere $\\vec{S}$ is the spin angular momentum of the electron and $g_{S}$ is the spin g-iactor. Therefore, $z$-components of magnetic dipole moment will be\n$$\n\\left(\\mu_{S}\\right)_{z}=-g_{S} \\frac{e}{2 m} S_{z}\n$$\nIf the electron is in an eigenstate of $S_{z}$, then\n$$\n\\left(\\mu_{S}\\right)_{z}=-g_{s} \\mu_{B} m_{s}\n$$\nwhere $\\left(\\frac{e \\hbar}{2 m_{e}}\\right)=\\mu_{B}=$ Bohr magneton and $m_{s}$ is the spin magnetic quantum number.\\\\\nFor a particular value of $s$, we will get $(2 s+1)$ values of ' $m$ ' i.e. $m_{s}=-s,-s+1, \\ldots \\ldots ., 0, \\ldots \\ldots . . s-1, s$ Every fundamental particle has a specific spin $(s=0,1,2, \\ldots \\ldots \\ldots \\ldots \\ldots \\ldots)$\\\\\nFermions: Particle having half-integer spins. Examples: quarks, electrons, protons, neutrons etc.\\\\\n Bosons: Particles having integer spins. Example: Photons, pions, gravitons etc.\\\\\n Therefore, there are two kinds of angular momentum of the particle i.e.\\\\\n (i) Orbital angular momentum $(\\vec{L})$ due to particle's orbital motion and it is characterized by two quantro numbers i.e. $\\ell$ and its projection of z-axis ' $m_{\\ell}$ ' which can take values from $-\\ell$ to $+\\ell$.\\\\\n (ii) Spin angular momentum $(\\vec{S})$ due to some intrinsic motion of the particle and it is characterised by two quantum numbers i.e. $s$ and its projection on z-axis $m_{s}$ ' which can take values from $-s$ to $+s$. Thus, the total angular momentum can be written as\n $$ \\vec{J}=\\vec{L}+\\vec{S} $$ and it is characterised by two quantum numbers i.e. $j$ and its projection on z-axis i.e. ' $m_{j}$ ' which can take values from $-j$ to $+j$.\\\\\n In the Stern-Gerlach experiment, the silver atom has orbital angular momentum to be zero i.e $l=0$ but spin angular momentum to be $1 / 2$ i.e. $s=1 / 2$. Therefore, total angular momentum will be\n $$\n j=|l-s| \\text { to }|l+s|=-\\frac{1}{2}, \\frac{1}{2}\n $$\n For thiis, we are getting two spots on the screen.\\\\\n \\subsection{ spin angular momentum}\n \\begin{itemize}\n \t\\item Spin angular momentum has components $S_x,S_y,S_z$ and the corresponding operators satisfy the following commutation relation:\n \t$$\n \t\\left[\\hat{S}_{x}, \\hat{S}_{y}\\right]=i h \\hat{S}_{z} \\quad\\left[\\hat{S}_{y}, \\hat{S}_{z}\\right]=i \\hbar \\hat{S}_{x} \\quad\\left[\\hat{S}_{z}, \\hat{S}_{x}\\right]=i \\hbar \\hat{S}_{y}\n \t$$\n \t\\item $\\left[\\hat{S}^{2}, \\hat{S}_{z}\\right]=0$ i.e. they have simultaneous eigenstate as following:\n \t$$\n \t\\begin{aligned}\n \t&\\hat{S}^{2}\\left|s, m_{s}\\right\\rangle=s(s+1) \\hbar^{2}\\left|s, m_{s}\\right\\rangle \\\\\n \t&\\hat{S}_{z}\\left|s, m_{s}\\right\\rangle=m_{s} \\hbar\\left|s, m_{s}\\right\\rangle\n \t\\end{aligned}\n \t$$\n \t\\item Raising and lowering operators are defined as following:\n \t$$\n \t\\begin{aligned}\n \t&\\hat{S}_{\\pm}=\\hat{S}_{x} \\pm i \\hat{S}_{y} \\\\\n \t&\\hat{S}_{+}\\left|s, m_{s}\\right\\rangle=\\hbar \\sqrt{\\left(s-m_{s}\\right)\\left(s+m_{s}+1\\right)}\\left|s, m_{s}+1\\right\\rangle \\\\\n \t&\\hat{S}_{-}\\left|s, m_{s}\\right\\rangle=\\hbar \\sqrt{\\left(s+m_{s}\\right)\\left(s-m_{s}+1\\right)}\\left|s, m_{s}-1\\right\\rangle\n \t\\end{aligned}\n \t$$\n \t\\item - For a spin $\\frac{1}{2}$ particles like electrons, $m_{s}$ can take values $\\frac{1}{2}$ and $-\\frac{1}{2}$, so the possible spin states are\\\\\n \tSpin-up state: $\\chi_{1 / 2}=|\\uparrow\\rangle=\\left|\\frac{1}{2}, \\frac{1}{2}\\right\\rangle$\\\\\n \tSpin-down state: $\\chi_{-1 / 2}=|\\downarrow\\rangle=\\left|\\frac{1}{2},-\\frac{1}{2}\\right\\rangle$\n \tsuch that\n \t$$\\begin{aligned}\n \t\t&\\hat{S}^{2} \\chi_{1 / 2}=\\frac{3}{4} \\hbar^{2} \\chi_{1 / 2}, \\quad \\hat{S}^{2} \\chi_{-1 / 2}=\\frac{3}{4} \\hbar^{2} \\chi_{-1 / 2} \\\\\n \t\t&\\hat{S}_{z} \\chi_{1 / 2}=\\frac{\\hbar}{2} \\chi_{1 / 2}, \\quad \\hat{S}_{z} \\chi_{-1 / 2}=\\frac{\\hbar}{2} \\chi_{-1 / 2} \\\\\n \t\t&\\hat{S}_{+} \\chi_{1 / 2}=0, \\quad \\hat{S}_{+} \\chi_{-1 / 2}=\\hbar \\chi_{1 / 2} \\\\\n \t\t&\\hat{S}_{-} \\chi_{1 / 2}=\\hbar \\chi_{-1 / 2}, \\quad \\hat{S}_{-} \\chi_{-1 / 2}=0\n \t\\end{aligned}$$\n \\end{itemize}\n\\textbf{ Matrix representation of the various spin operators for a spin-1/2 particle:}\\\\\\\\\n$\\hat{S}^{2}=\\left[\\begin{array}{ll}\n\t\\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}^{2}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}^{2}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle \\\\\n\t\\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}^{2}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}^{2}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle\n\\end{array}\\right]=\\frac{3}{4} \\hbar^{2}\\left[\\begin{array}{ll}\n\t1 & 0 \\\\\n\t0 & 1\n\\end{array}\\right]$\\\\\\\\\n\n$\\hat{S}_{z}=\\left[\\begin{array}{ll}\n\t\\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{z}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{z}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle \\\\\n\t\\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{z}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{z}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle\n\\end{array}\\right]=\\frac{\\hbar}{2}\\left[\\begin{array}{cc}\n\t1 & 0 \\\\\n\t0 & -1\n\\end{array}\\right]$\\\\\\\\\n\n$\\hat{S}_{+}=\\left[\\begin{array}{cc}\n\t\\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{+}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{+}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle \\\\\n\t\\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{+}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{+}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle\n\\end{array}\\right]=\\left[\\begin{array}{ll}\n\t0 & \\hbar \\\\\n\t0 & 0\n\\end{array}\\right]=\\hbar\\left[\\begin{array}{ll}\n\t0 & 1 \\\\\n\t0 & 0\n\\end{array}\\right]$\\\\\\\\\n\n$\\hat{S}_{-}=\\left[\\begin{array}{lll}\n\t\\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{-}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2}, \\frac{1}{2}\\left|\\hat{S}_{-}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle \\\\\n\t\\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{-}\\right| \\frac{1}{2}, \\frac{1}{2}\\right\\rangle & \\left\\langle\\frac{1}{2},-\\frac{1}{2}\\left|\\hat{S}_{-}\\right| \\frac{1}{2},-\\frac{1}{2}\\right\\rangle\n\\end{array}\\right]=\\hbar\\left[\\begin{array}{ll}\n\t0 & 0 \\\\\n\t1 & 0\n\\end{array}\\right]$\\\\\\\\\n\n$$\\begin{aligned}\n\t&\\hat{S}_{x}=\\frac{1}{2}\\left[\\hat{S}_{+}+\\hat{S}_{-}\\right]=\\frac{\\hbar}{2}\\left[\\begin{array}{ll}\n\t\t0 & 1 \\\\\n\t\t1 & 0\n\t\\end{array}\\right] \\\\\n\t&\\hat{S}_{y}=\\frac{1}{2 i}\\left[\\hat{S}_{+}-\\hat{S}_{-}\\right]=\\frac{\\hbar}{2}\\left[\\begin{array}{ll}\n\t\t0 & -i \\\\\n\t\ti & 0\n\t\\end{array}\\right]\n\\end{aligned}$$\n\\textbf{ Eigenvalues and eigenvectors of  $\\hat{S}_{z}$:}\\\\\\\\\nEigenvalues: $\\lambda=\\pm \\frac{\\hbar}{2}$\\\\\\\\\nEigenvectors: $\\chi_{1 / 2}=\\left[\\begin{array}{l}1 \\\\ 0\\end{array}\\right]$ for $\\lambda=\\frac{\\hbar}{2}$ and $\\chi_{-1 / 2}=\\left[\\begin{array}{c}0 \\\\ 1\\end{array}\\right]$ for $\\lambda=-\\frac{\\hbar}{2}$\\\\\n\\textbf{$\\text { Eigenvalues and eigenvectors of } \\hat{S}_{x}$:}\\\\\\\\\nEigenvalues: $\\lambda=\\pm \\frac{\\hbar}{2}$\\\\\\\\\nEigenvectors: $\\frac{1}{\\sqrt{2}}\\left[\\begin{array}{l}1 \\\\ 1\\end{array}\\right]=\\frac{1}{\\sqrt{2}}\\left[\\chi_{1 / 2}+\\chi_{-1 / 2}\\right]$ for $\\lambda=\\frac{\\hbar}{2}$\\\\\nand $\\frac{1}{\\sqrt{2}}\\left[\\begin{array}{l}1  -1\\end{array}\\right]=\\frac{1}{\\sqrt{2}}\\left[\\chi_{1 / 2}-\\chi_{-1 / 2}\\right]$ for $\\lambda=-\\frac{\\hbar}{2}$\\\\\\\\\n\\textbf{$\\text { Eigenvalues and eigenvectors of } \\hat{S}_{y}$:}\\\\\\\\\nEigenvalues: $\\lambda=\\pm \\frac{\\hbar}{2}$\\\\\\\\\nEigenvectors: $\\frac{1}{\\sqrt{2}}\\left[\\begin{array}{l}1 \\\\ i\\end{array}\\right]=\\frac{1}{\\sqrt{2}}\\left[\\chi_{1 / 2}+i \\chi_{-1 / 2}\\right]$ for $\\lambda=\\frac{\\hbar}{2}$\\\\\nand $\\frac{1}{\\sqrt{2}}\\left[\\begin{array}{l}1 \\\\ -i\\end{array}\\right]=\\frac{1}{\\sqrt{2}}\\left[\\chi_{1 / 2}-i \\chi_{-1 / 2}\\right]$ for $\\lambda=-\\frac{\\hbar}{2}$\\\\\\\\\n\\subsection{Pauli spin matrices}\nSpin angular momentum can be related with Pauli spin vector as follows:\n$$\n\\vec{S}=\\frac{\\hbar}{2} \\vec{\\sigma}\n$$\nwhere $\\sigma_{x}=\\left(\\begin{array}{ll}0 & 1 \\\\ 1 & 0\\end{array}\\right), \\sigma_{y}=\\left(\\begin{array}{cc}0 & -i \\\\ i & 0\\end{array}\\right), \\sigma_{z}=\\left(\\begin{array}{cc}1 & 0 \\\\ 0 & -1\\end{array}\\right)$ are components of the Pauli spin vectors and known as Pauli spin matrices. These matrices satisfies the following conditions:\\\\\\\\\n(i) $\\sigma_{x}^{2}=\\sigma_{y}^{2}=\\sigma_{z}^{2}=I$\\\\\\\\\n(ii) $\\sigma_{j} \\sigma_{k}+\\sigma_{k} \\sigma_{j}=\\left\\{\\sigma_{j}, \\sigma_{k}\\right\\}=2 I \\delta_{j k}$\\\\\\\\\n(iii) $\\left[\\sigma_{j}, \\sigma_{k}\\right]=2 i \\varepsilon_{j k l} \\sigma_{l}$\\\\\n$\\text { (iv) Pauli spin matrices are hermitian, traceless and determinant is }-1 \\text {. }$\\\\\\\\\n$\\text { (v) } \\sigma_{x} \\sigma_{y} \\sigma_{z}=i I$\\\\\\\\\n(vi) Since spin does not depend on spatial degrees of freedom then the components of spin $S_{x}, S_{y}, S_{z}$ commute with all spatial operators i.e. momentum, position, orbital angular momentum.\\\\\\\\\n$\\text { (vii) } e^{i \\alpha \\sigma_{j}}=I \\cos \\alpha+i \\sigma_{j} \\sin \\alpha$\\\\\\\\\n$\\text { (viii) For any two vectors } \\vec{A} \\text { and } \\vec{B},(\\vec{\\sigma} \\cdot \\vec{A})(\\vec{\\sigma} \\cdot \\vec{B})=(\\vec{A} \\cdot \\vec{B}) I+i \\sigma \\cdot(\\vec{A} \\times \\vec{B})$\\\\\n\n\\section{Addition of Angular Momenta}\nLet $J_1$ and $J_2$ be two independent commuting angularmomenta vectors ie.\n$$[J_1,J_2]=0$$\nFor example $J_1$ may be the orbital angular momentum $L$ and $J_2$ the spin $S$ of the same particle. Basis for the system is the set of simultaneous eigen states $|j_1 m_1;j_2 m_2>$ of the four commuting operators $J_1^2,J_1z,J_2^2,J_2z$ which form a complete commuting set of observables. Let us consider the set of $(2j,+1)\\  (2j_2+11)$ states for fixed $j_1$ and $j_2(m_1=j_1, j_1 -1.......-j_1;m_2=j_2, j_2-1,....-j_2)$. So we suppress the fixed values of $j_1$ and $j_2$ from the notation for the basis state and write simple $|j_1 m_1 ; j_2 m_2>$ leaving it to be understood that\n$$ J_1^2\\ |m_1;m_2>=j_1 (j_1+1)\\hbar^2 |m_1 ; m_2>$$\n$$ J_2^2\\ |m_1;m_2>=j_2 (j_2+1)\\hbar^2 |m_1 ; m_2>$$\nFor $J_z$\\\\\n$$J_1z|m_1;m_2>=m_1\\hbar|m_1;m_2>,J_2z|m_1;m_2>=m_2\\hbar|m_1;m_2>$$\nNoting that $J_{1\\pm}$ are ladder operators on $m_1$ and $J_2\\pm$ on $m_2,$ Then\n$$J_{1\\pm}|m_1;m_2>=[(j_1\\mp m_1)(j_1\\pm m_1+1)]^\\frac{1}{2}|m_1\\pm 1;m_2>$$\n$$J_{2\\pm}|m_1;m_2>=[(j_2\\mp m_2)(j_2\\pm m_2+1)]^\\frac{1}{2}|m_1;m_2\\pm 1>$$\nSuppose the interaction between the two system is such as to couple $J_1$ and $J_2$ then $J_1z$ and $J_2z$ are no longer constant of motion. It would be more advantageous to use other operators which commute with such an interactions for defining a basis. It is natural to use for this prupose $J^2$ and $J_z$ where $J$ is the total angular momentum operator for the composite system made up of $J_1$ and $J_2$.\n$$ J=J_1+J_2\\quad J^2=J_1^2+J_2^2+2J_1J_2$$\n$J_1^2$ and $J_2^2$ do commute with $J^2$ and $J_z$, the simultaneous eigen state of these four operators will be taken as a new basis. We denote these by $|jm>$ is the abbreviation for $|j_1j_2j_m>$. The quantum numbers $j,m$ are of course defined by\n$$ J^2|jm>=j(j+1)\\hbar^2|jm>\\quad J_z|jm>=m\\hbar|jm>$$\n\\par The possible vlue of $j$ for the composite system can be obtained by stating in terms of the vector model. If $J_1$ and $J_2$ thought of as two ordinary vectors of length $j_1$ and $j_2$ respectively, these vector together with $J_1+J_2$ form a triangle. The values of $j_1, j_2, j$ must be then such that a triangle with these sides can be constructed.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.5cm,width=4.5cm]{Q-2}\n\\end{figure}\nThis triangle rule or triangle condition immedietly set the maximum and minimum limits for $j$ as $(j_1+j_2)$ and $|j_1-j_2|$ (corresponding $J_1$ and $J_2$ are being parallel and antiparallel raspectively). Since angular momentum is quandized, the only allowed values between these limits are $j_1+j_2-1, j_1+j_2-2....|j_1-j_2|+1$\\\\\nWe shall now see that the same conclusion follow from quantum mechanics.\\\\\n\\par The states $|jm>$ and the sets $|m_1;m_2>$ are simple different bases for the same space. So any $|jm>$ can be written as a linear combination of the states $|m_;m_2>$\n$$ |jm>=\\sum_{m_1m_2}|m_1;m_2><m_1;m_2|jm>$$\nThe matrix formed by the elements $<m_1;m_2|jm>$ where in $m_1,m_2$ together label the rows and $j,m$ label the columns, must be unitary.\\\\\\\\\nSince $J_z=J_1z+J_2z$ it is evident that \n$$m=m_1+m_2$$\nie $<m_1;m_2|jm>=0$ unless $m_2=m-m_1$\\\\\\\\\nThen $|jm>$ reduces to a single sum.\n$$ |jm>=\\sum_{m_1}|m_1;m-m_1><m_1;m-m_1|jm>$$\nSince the maximum value of $m_1$ and $m_2$ are $j_1$ and $j_2$ which is then necessarly the maximum value of $j$ too. Since this value of $m $  occurs only once (when $m_1=j_1$ and $m_2=j_2$), $j_1+j_2$ occurs only once.\\\\\\\\\nConsider now the next lower value of $m$ namely $m=j_1+j_2-1$ There are two states with this $m$ one has $m_1=j_1,m_2=j_2-1$ and the other $m-1=j_1-1, m_2=j_2$ one of these or rather a linear combination of these must belongs to the value $j=j_1+j_2$ already found, since one state with each value of $m$ from $j_1+j_2$ down to $-(j_1+j_2)$ must go with this $j$\\\\\\\\\nWe have other state with $m=j_1+j_2-1$ which must belong to a new value of $J,j=j_1+j_2-1$\\\\\\\\\nBy extending this procedure $m=j_1+j_2-2$ and so on we find new values $j_1+j_2-2$ for $j$\\\\\\\\\nThis process ends when all the available states are exhausted. The total number of independent states is $(2j_1+1)(2j_2+1)$ as observed at the begining of this section on the other hand each value of $j$ has $2j+1$ states associated with it\\\\\\\\\nSo the minimum value of $j_{min}$ of $j$ is reached when \n$$ \\sum_{j=J_{min}}^{j_1+j_2}(2j+1)=(2j+1)(2j_2+1)$$\nAfter the summation of left had side we ger $J_{min}$ as $J_{min}=|j_1-j_2|$ as expected.\\\\\nTo sum up, the possible values $j$ of the total angular momentum,, resulting from the addition of two given angular momenta $j_1,j_2$ are.\n$$(j_1+j_2)(j_1+j_2-1),....,|j_1-j_2|$$\n\\newpage \n\\begin{abox}\n\tPractice set 1\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian of an electron in a constant magnetic field $\\vec{B}$ is given by $H=\\mu \\vec{\\sigma} \\cdot \\vec{B}$. where $\\mu$ is a positive constant and $\\vec{\\sigma}=\\left(\\sigma_{1}, \\sigma_{2}, \\sigma_{3}\\right)$ denotes the Pauli matrices. Let $\\omega=\\mu B / \\hbar$ and $I$ be the $2 \\times 2$ unit matrix. Then the operator $e^{i H t / \\hbar}$ simplifies to\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $I \\cos \\frac{\\omega t}{2}+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\sin \\frac{\\omega t}{2}$\n\t\\task[\\textbf{B.}]$I \\cos \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\sin \\omega t$\n\t\\task[\\textbf{C.}]$I \\sin \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\cos \\omega t$\n\t\\task[\\textbf{D.}]$I \\sin 2 \\omega t+\\frac{i \\vec{\\sigma} \\cdot \\vec{B}}{B} \\cos 2 \\omega t$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item  In a system consisting of two spin $\\frac{1}{2}$ particles labeled 1 and 2, let $\\vec{S}^{(1)}=\\frac{\\hbar}{2} \\vec{\\sigma}^{(1)}$ and $\\vec{S}^{(2)}=\\frac{\\hbar}{2} \\vec{\\sigma}^{(2)}$ denote the corresponding spin operators. Here $\\vec{\\sigma} \\equiv\\left(\\sigma_{x}, \\sigma_{y}, \\sigma_{z}\\right)$ and $\\sigma_{x}, \\sigma_{y}, \\sigma_{z}$ are the three Pauli matrices.\\\\\n\t$\\text { In the standard basis the matrices for the operators } S_{x}^{(1)} S_{y}^{(2)} \\text { and } S_{y}^{(1)} S_{x}^{(2)} \\text { are respectively, }$\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(1)\n\t\\task[\\textbf{A.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cc}\n\t1 & 0 \\\\\n\t0 & -1\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{rr}\n\t-1 & 0 \\\\\n\t0 & 1\n\t\\end{array}\\right)$\n\t\\task[\\textbf{B.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cc}\n\ti & 0 \\\\\n\t0 & -i\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{rr}\n\t-i & 0 \\\\\n\t0 & i\n\t\\end{array}\\right)$\n\t\\task[\\textbf{C.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & 0 & 0 & -i \\\\\n\t0 & 0 & i & 0 \\\\\n\t0 & -i & 0 & 0 \\\\\n\ti & 0 & 0 & 0\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & 0 & 0 & -i \\\\\n\t0 & 0 & -i & 0 \\\\\n\t0 & i & 0 & 0 \\\\\n\ti & 0 & 0 & 0\n\t\\end{array}\\right)$\n\t\\task[\\textbf{D.}]$\\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & 1 & 0 & 0 \\\\\n\t1 & 0 & 0 & 0 \\\\\n\t0 & 0 & 0 & -i \\\\\n\t0 & 0 & i & 0\n\t\\end{array}\\right), \\frac{\\hbar^{2}}{4}\\left(\\begin{array}{cccc}\n\t0 & -i & 0 & 0 \\\\\n\ti & 0 & 0 & 0 \\\\\n\t0 & 0 & 0 & 1 \\\\\n\t0 & 0 & 1 & 0\n\t\\end{array}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { These two operators of above QUESTION satisfy the relation }$\n\t\\exyear{NET JUNE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left\\{S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right\\}=S_{z}^{(1)} S_{z}^{(2)}$\n\t\\task[\\textbf{B.}]$\\left\\{S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right\\}=0$\n\t\\task[\\textbf{C.}]$\\left[S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right]=i S_{z}^{(1)} S_{z}^{(2)}$\n\t\\task[\\textbf{D.}] $\\left[S_{x}^{(1)} S_{y}^{(2)}, S_{y}^{(1)} S_{x}^{(2)}\\right]=0$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The component along an arbitrary direction $\\hat{n}$, with direction $\\operatorname{cosines}\\left(n_{x}, n_{y}, n_{z}\\right)$, of the spin of a spin $-\\frac{1}{2}$ particle is measured. The result is\n\t\\exyear{NET JUNE 2012}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] 0\n\t\\task[\\textbf{B.}]$\\pm \\frac{\\hbar}{2} n_{z}$\n\t\\task[\\textbf{C.}]$\\pm \\frac{\\hbar}{2}\\left(n_{x}+n_{y}+n_{z}\\right)$\n\t\\task[\\textbf{D.}]$\\pm \\frac{\\hbar}{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item In a basis in which the $z$ - component $S_{z}$ of the spin is diagonal, an electron is in a spin state $\\psi=\\left(\\begin{array}{c}(1+i) / \\sqrt{6} \\\\ \\sqrt{2 / 3}\\end{array}\\right) .$ The probabilities that a measurement of $S_{2}$ will yield the values $\\hbar / 2$ and $-\\hbar / 2$ are, respectively,\n\t\\exyear{NET JUNE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $1 / 2$ and $1 / 2$\n\t\\task[\\textbf{B.}]$2 / 3$ and $1 / 3$\n\t\\task[\\textbf{C.}]$1 / 4$ and $3 / 4$\n\t\\task[\\textbf{D.}]$1 / 3$ and $2 / 3$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A spin $-\\frac{1}{2}$ particle is in the state $\\chi=\\frac{1}{\\sqrt{11}}\\left(\\begin{array}{c}1+i \\\\ 3\\end{array}\\right)$ in the eigenbasis of $S^{2}$ and $S_{2}$. If we measure $S_{z}$, the probabilities of getting $+\\frac{h}{2}$ and $-\\frac{h}{2}$, respectively are\n\t\\exyear{NET DEC 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{1}{2}$ and $\\frac{1}{2}$\n\t\\task[\\textbf{B.}]$\\frac{2}{11}$ and $\\frac{9}{11}$\n\t\\task[\\textbf{C.}] 0 and 1\n\t\\task[\\textbf{D.}]$\\frac{1}{11}$ and $\\frac{3}{11}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Let $\\vec{\\sigma}=\\left(\\sigma_{1}, \\sigma_{2}, \\sigma_{3}\\right)$, where $\\sigma_{1}, \\sigma_{2}, \\sigma_{3}$ are the Pauli matrices. If $\\vec{a}$ and $\\vec{b}$ are two arbitrary constant vectors in three dimensions, the commutator $[\\vec{a} \\cdot \\vec{\\sigma}, \\vec{b} \\cdot \\vec{\\sigma}]$ is equal to (in the following $I$ is the identity matrix)\n\t\\exyear{NET DEC 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $(\\vec{a} \\cdot \\vec{b})\\left(\\sigma_{1}+\\sigma_{2}+\\sigma_{3}\\right)$\n\t\\task[\\textbf{B.}]$2 i(\\vec{a} \\times \\vec{b}) \\cdot \\vec{\\sigma}$\n\t\\task[\\textbf{C.}]$(\\vec{a} \\cdot \\vec{b}) I$\n\t\\task[\\textbf{D.}]$|\\vec{a}||\\vec{b}| I$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{i}$ are the components of the angular momentum operator $\\vec{L}$, then the operator $\\sum_{i=1,2,3}\\left[\\vec{L}, L_{i}\\right]$ equals\n\t\\exyear{NET JUNE 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\vec{L}$\n\t\\task[\\textbf{B.}]$2 \\vec{L}$\n\t\\task[\\textbf{C.}]$3 \\vec{L}$\n\t\\task[\\textbf{D.}]$-\\vec{L}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian for a spin- $\\frac{1}{2}$ particle at rest is given by $H=E_{0}\\left(\\sigma_{z}+\\alpha \\sigma_{x}\\right)$, where $\\sigma_{x}$ and $\\sigma_{z}$ are Pauli spin matrices and $E_{0}$ and $\\alpha$ are constants. The eigenvalues of this Hamiltonian are\n\t\\exyear{NET DEC 2015}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\pm E_{0} \\sqrt{1+\\alpha^{2}}$\n\t\\task[\\textbf{B.}]$\\pm E_{0} \\sqrt{1-\\alpha^{2}}$\n\t\\task[\\textbf{C.}]$E_{0}$ (doubly degenerate)\n\t\\task[\\textbf{D.}]$E_{0}\\left(1 \\pm \\frac{1}{2} \\alpha^{2}\\right)$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\hat{L}_{x}, \\hat{L}_{y}, \\hat{L}_{z}$ are the components of the angular momentum operator in three dimensions the commutator $\\left[\\hat{L}_{x}, \\hat{L}_{x} \\hat{L}_{y} \\hat{L}_{z}\\right]$ may be simplified to\n\t\\exyear{NET JUNE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar L_{x}\\left(\\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$i \\hbar \\hat{L}_{z} \\hat{L}_{y} \\hat{L}_{x}$\n\t\\task[\\textbf{C.}] $i \\hbar L_{x}\\left(2 \\hat{L}_{z}^{2}-\\hat{L}_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian of a spin $\\frac{1}{2}$ particle in a magnetic field $\\vec{B}$ is given by $H=-\\mu \\cdot \\vec{B} \\cdot \\vec{\\sigma}$, where $\\mu$ is a real constant and $\\vec{\\sigma}=\\left(\\sigma_{x}, \\sigma_{y}, \\sigma_{z}\\right)$ are the Pauli spin matrices. If $\\vec{B}=\\left(B_{0}, B_{0}, 0\\right)$ and the spin state at time $t=0$ is an eigenstate of $\\sigma_{x}$, then of the expectation values $\\left\\langle\\sigma_{x}\\right\\rangle,\\left\\langle\\sigma_{y}\\right\\rangle$ and $\\left\\langle\\sigma_{z}\\right\\rangle$\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] only $\\left\\langle\\sigma_{x}\\right\\rangle$ changes with time\n\t\\task[\\textbf{B.}] only $\\left\\langle\\sigma_{y}\\right\\rangle$ changes with time\n\t\\task[\\textbf{C.}]only $\\left\\langle\\sigma_{z}\\right\\rangle$ changes with time\n\t\\task[\\textbf{D.}]all three change with time\n\\end{tasks}\n\\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{b}&2&\\textbf{c}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{d}\\\\\\hline\n\t\t5&\\textbf{d}&6&\\textbf{b}\\\\\\hline\n\t\t7&\\textbf{b}&8&\\textbf{b}\\\\\\hline\n\t\t9&\\textbf{a}&10&\\textbf{a}\\\\\\hline\n\t\t11&\\textbf{d}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\\newpage \n\\begin{abox}\nPractice set 2 \n\\end{abox}\n\\begin{enumerate}\n\\begin{minipage}{\\textwidth}\n\t\\item $\\text { For a spin-s particle, in the eigen basis of } \\vec{S}^{2}, S_{x} \\text { the expectation value }\\left\\langle s m\\left|S_{x}^{2}\\right| s m\\right\\rangle \\text { is }$\n\t\\exyear{GATE 2010}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\frac{\\hbar^{2}\\left\\{s(s+1)-m^{2}\\right\\}}{2}$\n\t\\task[\\textbf{B.}] $\\hbar^{2}\\left\\{s(s+1)-2 m^{2}\\right\\}$\n\t\\task[\\textbf{C.}]$\\hbar^{2}\\left\\{s(s+1)-m^{2}\\right\\}$\n\t\\task[\\textbf{D.}]$\\hbar^{2} m^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{x}, L_{y}$ and $L_{z}$ are respectively the $x, y$ and $z$ components of angular momentum operator $L$. The commutator $\\left[L_{x} L_{y}, L_{z}\\right]$ is equal to\n\t\\exyear{GATE 2011}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $i \\hbar\\left(L_{x}^{2}+L_{y}^{2}\\right)$\n\t\\task[\\textbf{B.}]$2 i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$i \\hbar\\left(L_{x}^{2}-L_{y}^{2}\\right)$\n\t\\task[\\textbf{D.}]0\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item Which one of the following commutation relations is NOT CORRECT? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\left[L^{2}, L_{z}\\right]=0$\n\t\\task[\\textbf{B.}]$\\left\\lfloor L_{x}, L_{y}\\right\\rfloor=i \\hbar L_{z}$\n\t\\task[\\textbf{C.}]$\\left[L_{z}, L_{+}\\right]=\\hbar L_{+}$\n\t\\task[\\textbf{D.}]$\\left[L_{z}, L_{-}\\right]=\\hbar L_{-}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item A spin-half particle is in a linear superposition $0.8|\\uparrow\\rangle+0.6|\\downarrow\\rangle$ of its spin-up and spindown states. If $|\\uparrow\\rangle$ and $|\\downarrow\\rangle$ are the eigenstates of $\\sigma_{z}$, then what is the expectation value up to one decimal place, of the operator $10 \\sigma_{z}+5 \\sigma_{x}$ ? Here, symbols have their usual meanings.\n\t\\exyear{GATE 2013}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\vec{L}$ is the orbital angular momentum and $\\bar{S}$ is the spin angular momentum, then $\\vec{L} \\cdot \\vec{S}$ does not commute with\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $S_{z}$ \n\t\\task[\\textbf{B.}]$L^{2}$\n\t\\task[\\textbf{C.}]$S^{2}$\n\t\\task[\\textbf{D.}]$(\\vec{L}+\\vec{S})^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item If $L_{+}$and $L_{-}$are the angular momentum ladder operators then the expectation value of $\\left(L_{+} L_{-}+L_{-} L_{+}\\right)$in the state $|l=1, m=1\\rangle$ of an atom is $\\hbar^{2}$\n\t\\exyear{GATE 2014}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item The Pauli matrices for three spin $-\\frac{1}{2}$ particles are $\\vec{\\sigma}_{1}, \\vec{\\sigma}_{2}$ and $\\vec{\\sigma}_{3}$, respectively. The dimension of the Hilbert space required to define an operator $\\hat{O}=\\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2} \\times \\vec{\\sigma}_{3}$ is\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item Let the Hamiltonian for two spin-1/2 particles of equal masses $m$, momenta $\\vec{p}_{1}$ and $\\vec{p}_{2}$ and positions $\\vec{r}_{1}$ and $\\vec{r}_{2}$ be $H=\\frac{1}{2 m} p_{1}^{2}+\\frac{1}{2 m} p_{2}^{2}+\\frac{1}{2} m \\omega^{2}\\left(r_{1}^{2}+r_{2}^{2}\\right)+k \\vec{\\sigma}_{1} \\cdot \\vec{\\sigma}_{2}$, where $\\vec{\\sigma}_{1}$ and $\\vec{\\sigma}_{2}$ denote the corresponding Pauli matrices, $\\hbar \\omega=0.1 \\mathrm{eV}$ and $k=0.2 \\mathrm{eV}$. If the ground state has net spin zero, then the energy (in $\\mathrm{eV}$ ) is\n\t\\exyear{GATE 2015}\n\\end{minipage}\n\\begin{minipage}{\\textwidth}\n\t\\item If $\\vec{s}_{1}$ and $\\vec{s}_{2}$ are the spin operators of the two electrons of a He atom, the value o $\\left\\langle\\vec{s}_{1} \\cdot \\vec{s}_{2}\\right\\rangle$ for the ground state is\n\t\\exyear{GATE 2016}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $-\\frac{3}{2} \\hbar^{2}$\n\t\\task[\\textbf{B.}]$-\\frac{3}{4} \\hbar^{2}$\n\t\\task[\\textbf{C.}] 0\n\t\\task[\\textbf{D.}] $\\frac{1}{4} \\hbar^{2}$\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item The Hamiltonian of a spin $\\frac{1}{2}$ particle in a magnetic field $\\vec{B}$ is given by $H=-\\mu \\cdot \\vec{B} \\cdot \\vec{\\sigma}$, where $\\mu$ is a real constant and $\\vec{\\sigma}=\\left(\\sigma_{x}, \\sigma_{y}, \\sigma_{z}\\right)$ are the Pauli spin matrices. If $\\vec{B}=\\left(B_{0}, B_{0}, 0\\right)$ and the spin state at time $t=0$ is an eigenstate of $\\sigma_{x}$, then of the expectation values $\\left\\langle\\sigma_{x}\\right\\rangle,\\left\\langle\\sigma_{y}\\right\\rangle$ and $\\left\\langle\\sigma_{z}\\right\\rangle$\n\t\\exyear{NET JUNE 2018}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] only $\\left\\langle\\sigma_{x}\\right\\rangle$ changes with time\n\t\\task[\\textbf{B.}] only $\\left\\langle\\sigma_{y}\\right\\rangle$ changes with time\n\t\\task[\\textbf{C.}]only $\\left\\langle\\sigma_{z}\\right\\rangle$ changes with time\n\t\\task[\\textbf{D.}]all three change with time\n\\end{tasks}\n\\begin{minipage}{\\textwidth}\n\t\\item For the Hamiltonian $H=a_{0} I+\\vec{b} \\cdot \\vec{\\sigma}$ where $a_{0} \\in R, \\vec{b}$ is a real vector, $I$ is the $2 \\times 2$ identity matrix, and $\\vec{\\sigma}$ are the Pauli matrices, the ground state energy is\n\t\\exyear{GATE 2017}\n\\end{minipage}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $|b|$\n\t\\task[\\textbf{B.}]$2 a_{0}-|b|$\n\t\\task[\\textbf{C.}]$a_{0}-|b|$\n\t\\task[\\textbf{D.}]$a_{0}$\n\\end{tasks}\n\\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{c}\\\\\\hline\n\t\t3&\\textbf{d}&4&\\textbf{7.6}\\\\\\hline\n\t\t5&\\textbf{d}&6&\\textbf{2}\\\\\\hline\n\t\t7&\\textbf{8}&8&\\textbf{-0.3}\\\\\\hline\n\t\t9&\\textbf{b}&10&\\textbf{c}\\\\\\hline\n\t\t11&\\textbf{c}&&\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\n\n\n\n\\newpage\n\\begin{abox}\n\tPractice set 3\n\t\\end{abox}\n\\begin{enumerate}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Two spin half particle identified as $\\vec{S}_{1}$ and $\\vec{S}_{2}$ and $\\theta$ is angle between them. If they are in singlet configuration, then find the value of $\\left\\langle\\vec{S}_{1} \\cdot \\vec{S}_{2}\\right\\rangle$.\n\\end{minipage}\n\\begin{answer}\n\t$\\vec{S}=\\vec{S}_{1}+\\vec{S}_{2}$\\\\\n\t\\begin{align*}\n\t\t&\\vec{S}_{1} \\cdot \\vec{S}_{2}=\\frac{S^{2}-S_{1}^{2}-S_{2}^{2}}{2} \\\\\n\t\t&\\therefore S_{1}=\\frac{1}{2}, S_{2}=\\frac{1}{2} \\Rightarrow S=0 \\text { (singlet) } S=1 \\text { (Triplet) } \\\\\n\t\t&\\left\\langle S_{1}^{2}\\right\\rangle=\\frac{3}{4} \\hbar^{2} \\quad\\left\\langle S_{2}^{2}\\right\\rangle=\\frac{3}{4} \\hbar^{2} \\\\\n\t\t&\\langle S\\rangle=0 \\hbar^{2}(\\text { for singlet }) \\therefore\\left\\langle\\vec{S}_{1} \\cdot \\vec{S}_{2}\\right\\rangle=\\frac{\\langle S\\rangle^{2}-\\left\\langle S_{1}\\right\\rangle^{2}-\\left\\langle S_{2}\\right\\rangle^{2}}{2}=\\frac{0-\\frac{3}{4} \\hbar^{2}-\\frac{3}{4} \\hbar^{2}}{2} \\cdot\\\\\n\t\t&\\left\\langle\\vec{S}_{1} \\cdot \\vec{S}_{2}\\right\\rangle=\\frac{-3}{4} \\hbar^{2}\n\t\\end{align*}\n\\end{answer}\n\n\n\t\\begin{minipage}{\\textwidth}\n\t\\item The components of arbitrary vectors $A$ and $B$ commute with those of $\\sigma$.\n\tShow that $(\\sigma \\cdot A)(\\sigma \\cdot B)=A \\cdot B+i \\sigma \\cdot(A \\times B)$.\n\\end{minipage}\n\\begin{answer}\n\t$(\\sigma . A)(\\sigma . B)=\\left(\\sigma_{x} A_{x}+\\sigma_{y} A_{y}+\\sigma_{z} A_{z}\\right)\\left(\\sigma_{x} B_{x}+\\sigma_{y} B_{y}+\\sigma_{z} B_{z}\\right)$\\\\\\\\ $=\\sigma_{x}^{2} A_{x} B_{x}+\\sigma_{y}^{2} A_{y} B_{y}+\\sigma_{z}^{2} A_{z} B_{z}+\\sigma_{x} \\sigma_{y} A_{x} B_{y}+\\sigma_{y} \\sigma_{x} A_{y} B_{x}$\\\\ $\\quad+\\sigma_{x} \\sigma_{z} A_{x} B_{z}+\\sigma_{y} \\sigma_{z} A_{y} B_{z}+\\sigma_{z} \\sigma_{y} A_{z} B_{y}+\\sigma_{z} \\sigma_{x} A_{z} B_{x}$\\\\\\\\\n\tUsing the relations $\\sigma_{x}^{2}=\\sigma_{y}^{2}=\\sigma_{z}^{2}=1, \\sigma_{x} \\sigma_{y}=i \\sigma_{z}, \\sigma_{y} \\sigma_{z}=i \\sigma_{x}, \\sigma_{z} \\sigma_{x}=i \\sigma_{y}$,\\\\\n\t$\\sigma_{x} \\sigma_{y}+\\sigma_{y} \\sigma_{x}=\\sigma_{y} \\sigma_{z}+\\sigma_{z} \\sigma_{y}=\\sigma_{z} \\sigma_{x}+\\sigma_{x} \\sigma_{z}=0$\\\\\n\t$$\\begin{aligned}\n\t\\text { We get }(\\sigma \\cdot A)(\\sigma \\cdot B) &=(A \\cdot B)+i \\sigma_{z}\\left(A_{x} B_{y}-A_{y} B_{x}\\right)+i \\sigma_{y}\\left(A_{z} B_{x}-A_{x} B_{z}\\right)+i \\sigma_{x}\\left(A_{y} B_{z}-A_{z} B_{y}\\right) \\\\\n\t&=(A \\cdot B)+i \\sigma \\cdot(A \\times B)\n\t\\end{aligned}$$\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Find the equivalence of the following operators:\\\\\\\\\n\t(i) $S_{x}^{2} S_{y} S_{z}^{2}$;\\\\\\\\\n\t(ii) $S_{x}^{2} S_{y}^{2} S_{z}^{2}$;\\\\\\\\\n\t(iii) $S_{x} S_{y} S_{z}^{3}$\n\\end{minipage}\n\\begin{answer}\n\t$\\text { (i) } S_{x}^{2} S_{y} S_{z}^{2}=\\left(\\frac{\\hbar}{2}\\right)^{2} \\sigma_{x}^{2} \\frac{\\hbar}{2} \\sigma_{y}\\left(\\frac{\\hbar}{2}\\right)^{2} \\sigma_{z}^{2}=\\left(\\frac{\\hbar}{2}\\right)^{5} \\sigma_{y}$\\\\\\\\\n\t$\\text { (ii) } S_{x}^{2} S_{y}^{2} S_{z}^{2}=\\left(\\frac{\\hbar}{2}\\right)^{2} \\sigma_{x}^{2}\\left(\\frac{\\hbar}{2}\\right)^{2} \\sigma_{y}^{2}\\left(\\frac{\\hbar}{2}\\right)^{2} \\sigma_{z}^{2}=\\left(\\frac{\\hbar}{2}\\right)^{6}$\\\\\\\\\n\t$\\text { (iii) } S_{x} S_{y} S_{z}^{3}=\\frac{\\hbar}{2} \\sigma_{x} \\frac{\\hbar}{2} \\sigma_{y}\\left(\\frac{\\hbar}{2}\\right)^{3} \\sigma_{x}^{3}=\\left(\\frac{\\hbar}{2}\\right)^{5} \\sigma_{x} \\sigma_{y} \\sigma_{z}=\\left(\\frac{\\hbar}{2}\\right)^{5} i$\t\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item $\\vec{J}=\\vec{L}+\\vec{S}$ where $\\vec{J}$ is total angular momentum and $\\vec{L}$ and $\\vec{S}$ are orbital angl momentum and spin angular momentum respectively. Find the value of $a<L . S>$.\n\\end{minipage}\n\\begin{answer}\n\t$J=L+S$\n\t$$\n\t\\begin{aligned}\n\tJ^{2} &=(L+S)(L+S)=L^{2}+L \\cdot S+S \\cdot L+S^{2} \\\\\n\t&=L^{2}+S^{2}+2 L \\cdot S \\quad \\because S \\cdot L=L \\cdot S \\\\\n\tL \\cdot S &=\\frac{1}{2}\\left(J^{2}-L^{2}-S^{2}\\right) \\Rightarrow\\langle L \\cdot S\\rangle=\\frac{\\hbar^{2}}{2}\\left[j(j+1)-l(l+1)-s(s+1)\\right]\n\t\\end{aligned}\n\t$$\t\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item Find the energy level of spin $s=1 / 2$ particle whose Hamiltonion is given by\n\t$$\n\t\\hat{H}=\\frac{\\alpha}{\\hbar^{2}}\\left(S_{x}^{2}+S_{y}^{2}-2 S_{z}^{2}\\right)-\\frac{\\beta}{\\hbar} S_{z}\n\t$$\n\twhere $\\alpha$ and $\\beta$ are constants. What is degeneracy of the energy?\n\\end{minipage}\n\\begin{answer}\n\t$\\mathrm{H}=\\frac{\\alpha}{\\hbar^{2}}\\left(S_{x}^{2}+S_{y}^{2}-2 S_{z}^{2}\\right)-\\frac{\\beta}{\\hbar} S_{z} \\Rightarrow S^{2}=S_{x}^{2}+S_{y}^{2}+S_{z}^{2}, S_{x}^{2}+S_{y}^{2}=S^{2}-S_{z}^{2}$ \\\\\n\t$\\Rightarrow H=\\frac{\\alpha}{\\hbar^{2}}\\left(S^{2}-S_{z}^{2}-2 S_{z}^{2}\\right)-\\frac{\\beta}{\\hbar} S_{z}$\\\\\n\t$=\\frac{\\alpha}{\\hbar^{2}}\\left(S^{2}-3 S_{z}^{2}\\right)-\\frac{\\beta}{\\hbar} S_{z}=\\frac{\\alpha}{\\hbar^{2}}\\left(s(s+1) \\hbar^{2}-3 m^{2} \\hbar^{2}\\right)-\\frac{\\beta}{\\hbar} m \\hbar=\\frac{3 \\alpha}{4}-m(3 m+\\beta)$ \\\\\n\tThe degeneracy of the system is $(2 s+1)$ i.e. $\\left[2\\left(\\frac{1}{2}\\right)+1\\right]=2$\t\n\\end{answer}\n\t\\begin{minipage}{\\textwidth}\n\t\\item \tConsider a system which is initially in the state\n\t$$\n\t\\psi(\\theta, \\phi)=\\frac{1}{\\sqrt{5}} Y_{1,-1}(\\theta, \\phi)+\\sqrt{\\frac{3}{5}} Y_{1,0}(\\theta, \\phi)+\\frac{1}{\\sqrt{5}} Y_{1,1}(\\theta, \\phi)\n\t$$\n\t(i) If $L^{2}$ is measured $\\psi(\\theta, \\phi)$ then what is the measured with what probability?\\\\\n\t(ii) If $L_{z}$ is measured $\\psi(\\theta, \\phi)$ then what is the measured with what probability?\\\\\n\t(iii) What is the expectation value of $L^{2}$ and $L_{z}$\n\\end{minipage}\n\\begin{answer}\n\t(i) If $L^{2}$ measured $\\psi(\\theta, \\phi)$ then it will measured either $Y_{1,-1}$ or $Y_{1,0}$ or $Y_{1,1}$ each time. The measurement is $l(l+1) \\hbar^{2}$ i.e. $2 \\hbar^{2}$ and the probability of measurement is $\\left(\\frac{1}{\\sqrt{5}}\\right)^{2}+\\left(\\sqrt{\\frac{3}{5}}\\right)^{2}+\\left(\\frac{1}{\\sqrt{5}}\\right)^{2}$ i.e. 1 .\\\\\n\t(ii) If $L_{z}$ measured on $\\psi(\\theta, \\phi)$ then it will measured either $Y_{1,-1}$ or $Y_{1,0}$ or $Y_{1,1}$.\\\\\n\tThe measurement of $L_{2}$ on $Y_{1,1}$ yields $1 \\hbar$ with probability $1 / 5$.\\\\\n\tThe measurement of $L_{z}$ on $Y_{1,0}$ yields $0 \\hbar$ with probability $3 / 5$.\\\\\n\tThe measurement of $L_{z}$ on $Y_{1,-1}$ yields $-1 \\hbar$ with probability $1 / 5$.\\\\\n\t(iii) The expectation value of $L^{2}$ is given as\n\t$$\n\t2 \\hbar^{2} \\cdot \\frac{1}{5}+2 \\hbar^{2} \\cdot \\frac{3}{5}+2 \\hbar^{2} \\cdot \\frac{1}{5}=2 \\hbar^{2}\n\t$$\n\tThe expectation value of $L_{z}$ is given as $1 \\hbar \\cdot \\frac{1}{5}+0 \\hbar \\cdot \\frac{3}{5}+(-1 \\hbar) \\cdot \\frac{1}{5}=0$\n\\end{answer}\n\\end{enumerate}\n\n\n\n\n\n", "meta": {"hexsha": "3ca4cfce946e4d5780d4e9d644c24864b70c26e9", "size": 53760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "QM -CSIR/chapter/angular momentum.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "QM -CSIR/chapter/angular momentum.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "QM -CSIR/chapter/angular momentum.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": 60.8833522084, "max_line_length": 603, "alphanum_fraction": 0.6226376488, "num_tokens": 22466, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294404077216355, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7662882310068012}}
{"text": "\\chapter{Elementary Set Theory}\n\\label{sets}\n\n\n\\section{Sets and Set Notation}\n\\label{sets:notation}\n\n\\begin{enumerate}[{\\thesection}.1]\n\n\t\\item A \\emph{set} is a collection of objects, called its \\emph{elements} or \\emph{members}. The elements of a set are also said to \\emph{belong to} the set or to \\emph{be contained in} the set. A set may contain any kind of objects whatsoever: numbers, symbols, people, or even other sets. For $X$ a set and $x$ an object, we write $x\\in X$ to say that $x$ is an element of $X$ and we write $x\n\\not\\in X$ to say that $x$ is \\emph{not} an element of $X$. If we have many objects $x_1, \\mathellipsis, x_n$, then we also write $x_1, \\mathellipsis, x_n\\in X$ to say that $x_1\\in X$, and \\dots, and $x_n\\in X$.\n\n\t\t\\item If the elements of a set are precisely $a_1, \\mathellipsis, a_n$, then we can denote the set by $\\{a_1, \\mathellipsis, a_n\\}$. This is called an \\emph{extensional definition} of the set. So, the set $\\{1,a, \\{\\text{Robbie},0\\}\\}$, for example, contains precisely the number 1, the symbol $a$, and the set $ \\{\\text{Robbie},0\\}$, which in turn contains Robbie and the number 0 as elements.\n\n\t\\item A set may contain any number of elements. The set $\\{0\\}$, for example, has just one member---the number 0. A set with exactly one member is also called a \\emph{singleton set}.\\footnote{It's important to distinguish the \\emph{set} $\\{0\\}$ from the \\emph{number} $0$.} The set $\\{2, 14\\}$ has two members. And so on. Sets can also have infinitely many members. An important infinite set we'll encounter frequently is $\\mathbb{N}$, the set of all natural numbers. You might be tempted to write $\\mathbb{N}=\\{0,1,2,\\mathellipsis\\}$ but it's important to resist this temptation. In order to define a set, for each object it needs to be clear whether it's an element of the set or not. And who's to say that the list $0,1,2,\\mathellipsis$ continues $0,1,2,3,4,\\mathellipsis$ and not $0,1,2,4,6\\mathellipsis$. This means that if we write $\\mathbb{N}=\\{0,1,2,\\mathellipsis\\}$ this leaves open whether $3\\in \\mathbb{N}$ or $3\\notin\\mathbb{N}$.\n\t\n\t\\item Other infinite sets we'll encounter are: $\\mathbb{Z}$, the set of the integers (positive and negative whole numbers); $\\mathbb{Q}$, the set of rational numbers (fractions of integers); and $\\mathbb{R}$, the set of real numbers (you know, the one with $\\sqrt 2,\\pi,e, \\dots$ in it). \n\t\n\t\\item There also exists a set with no elements at all, the so-called \\emph{empty set}. This set is of fundamental importance in logic and mathematics. We denote this set by $\\{\\}$ or $\\emptyset$. Note especially that for each object $x$, we have that $x\\notin \\emptyset$. \n\t\t\n\t\\item If the elements of a set are precisely the objects satisfying condition $\\Phi$, then we can denote the set by $\\{x:\\Phi(x)\\}$. This is called a definition by \\emph{set abstraction}. For example, $\\{x:x\\text{ is a prime number}\\}$ is the set that contains all and only the prime numbers. So we have that $3\\in \\{x:x\\text{ is a prime number}\\}$ but $4\\notin \\{x:x\\text{ is a prime number}\\}$. Note that by Euclid's theorem, the set $\\{x:x\\text{ is a prime number}\\}$ has infinitely many elements. So, using set abstraction, we can denote infinite sets by a finitary expression.\n\t\n\t \\emph{To be perfectly clear}: an object $a$ is a member of the set $\\{x:\\Phi(x)\\}$ iff $a$ satisfies the condition $\\Phi$, i.e. $\\Phi(a)$!\n\t \n\t %\\item Note that we don't have that for every condition $\\Phi$, there is a set $\\{x:\\Phi(x)\\}$. This is a consequence of \\emph{Russel's paradox}. For let $\\Phi(x)$ be the condition $x\\notin x$ and consider the set $r=\\{x: x\\notin x\\}$. We can then ask whether $r\\in r$. Well, since the condition $\\Phi(x)$ is $x\\notin x$, we have $r\\in r$ iff $r\\notin r$. This already sounds bad, but it gets worse. Clearly, either $r\\in r$ or $r\\notin r$. But if $r\\in r$, then $r\\notin r$, and if $r\\notin r$, then $r\\in r$. So, either way, $r\\in r$ and $r\\notin r$. We have a contradiction!\n\t\n\t\\item Set abstraction is typically carried out over the elements of an already known set $X$, i.e. we consider the set of all members of $X$ that satisfy condition $\\Phi$. This set is denoted $\\{x\\in X: \\Phi(x)\\}$, which is just shorthand for $\\{x: x\\in X\\text{ and }\\Phi(x)\\}$. The background set of a set abstraction can make a sigificant difference to the sets denoted. E.g. $\\{x\\in \\mathbb{N}: x\\times x=2\\}=\\emptyset$ but $\\{x\\in\\mathbb{R}:x\\times x=2\\}=\\{\\sqrt 2, -\\sqrt 2\\}$.\n\t\n\t\\item When we're doing set abstraction, we also often implicitly assume that the members of the new set have a specific form. E.g. we would write $\\mathbb{Q}=\\{\\frac{n}{m}:n,m\\in \\mathbb{Z}, m\\neq 0\\}$ to say that $\\mathbb{Q}$ is the set of fractions of integers. In this case, $\\{\\frac{n}{m}:n,m\\in \\mathbb{Z}\\}$ is shorthand for: \\[\\{x: \\text{ there exist }n,m\\in \\mathbb{Z}\\text{ such that }x=\\frac{n}{m}\\text{, where }m\\neq 0 \\}.\\] We extend this notation later to the more general case.\n\t\t\n\\end{enumerate}\n\n\\section{The Subset Relation}\n\n\n\\begin{enumerate}[{\\thesection}.1]\n\n\t\n\t\\item One set is called a \\emph{subset} of another iff every element of the one set is also an element of the other. A bit more precisely, for all sets $X$ and $Y$, $X$ is a subset of $Y$ iff for each object $x$, if $x\\in X$, then $x\\in Y$. We write $X\\subseteq Y$ to say that $X$ is a subset of $Y$ and we write $X\\nsubseteq Y$ to say that $X$ is \\emph{not} a subset of $Y$. Note that $X\\nsubseteq Y$ iff there is at least one $x$ such that $x\\in X$ but $x\\notin Y$. So, for example, $\\{0,1\\}\\subseteq \\{1,a,0,\\{b,1\\}\\}$ but $\\{b,1\\}\\nsubseteq \\{1,a,0,\\{b,1\\}\\}$. Note that $b\\in \\{b,1\\}$ but $b\\notin \\{1,a,0,\\{b,1\\}\\}$. The moral here is that it's important to distinguish between subsets and elements: even though $\\{b,1\\}\\nsubseteq\\{1,a,0,\\{b,1\\}\\}$, we have that $\\{b,1\\}\\in \\{1,a,0,\\{b,1\\}\\}$.\n\t\n\t\\item \n\t\n\tIt's easily checked that every set is a subset of itself. This will be the first proposition that we prove:\n\\begin{proposition}\nFor all sets $X$, we have that $X\\subseteq X$.\n\\end{proposition}\n\\begin{proof}\nThis might seem ``obvious,'' but it's important to prove even obviously seeming facts. After all, you might think that something's obvious but it turns out to be false! So, consider any arbitrary set $X$ and arbitrary object $x$. Suppose that $x\\in X$. It follows, trivially, that $x\\in X$. Since $x$ was arbitrary, this means that for \\emph{each} $x$, if $x\\in X$, then $x\\in X$, which is another way of saying that $X\\subseteq X$. Since $X$ was also arbitrary, it follows that for each set $X$, we have that $X\\subseteq X$.\n\\end{proof}\n\n\t\\item A set $X$ is called a \\emph{proper} subset of another set $Y$ iff $X\\subseteq Y$ but $Y\\nsubseteq X$. We write $X\\subset Y$ to say that $X$ is a proper subset of $Y$ and $X\\not\\subset Y$ to say that $X$ is \\emph{not} a proper subset of $Y$. \t\n\t\n\\begin{proposition}\nFor all sets $X$, we have that $X\\not\\subset X$.\n\\end{proposition}\n\\begin{proof}\nWe prove this fact ``indirectly,'' that is we show that the assumption that some set is a proper subset of itself leads to a contradiction. Hence it cannot be that any set is a proper subset of itself. Suppose that some set $X$ is such that $X\\subset X$. Call this set $A$. By the definition of $\\subset$ we have that $A\\subseteq A$ and $A\\not\\subseteq A$, which is a contradiction. So there exists no set $X$ such that $X\\subset X$.\n\\end{proof}\n\n\\item It's also instructive to show that the empty set, $\\emptyset$, is a subset of every set whatsoever:\n\\begin{proposition}\\label{proposition:1.empty}\nFor each set $X$, we have that $\\emptyset\\subseteq X$.\n\\end{proposition}\n\\begin{proof}\nWe show this fact again indirectly. Suppose that there exists a set $X$ such that $\\emptyset\\nsubseteq X$. Call this set $A$. We get that $\\emptyset\\nsubseteq A$, which means that there exists at least one object $x$ such that $x\\in \\emptyset$ but $x\\notin A$. Call this object $a$. We get that $a\\in \\emptyset$. But we know that for each $x$, $x\\notin \\emptyset$, and hence $a\\notin \\emptyset$. We've arrived at a contradiction, $a\\in \\emptyset$ and $a\\notin\\emptyset$. Hence the assumption that there exists a set $X$ such that $\\emptyset\\nsubseteq X$ is false, which means that for each set $X$, we have that $\\emptyset\\subseteq X$.\n\\end{proof}\n\n\\item For $X$ a set, we define the \\emph{power set} to be \\[\\wp(X)=\\{Y: Y\\subseteq X\\}.\\] That is, the power set of $X$ is the set of all the subsets of $X$. So, for example, we have that $\\wp(\\{1,2\\})=\\{\\emptyset, \\{1\\}, \\{2\\}, \\{1,2\\}\\}$. Note that by the propositions proved in 2.2.2 and 2.2.4, for every set $X$, we have that $\\emptyset, X\\in \\wp(X)$.\n\n\\end{enumerate}\n\n\\section{The Axiom of Extensionality}\n\n\\begin{enumerate}[{\\thesection}.1]\n\n\n\\item Sets are individuated by their members. This is captured in the so-called \\emph{axiom of extensionality}, which states that two sets are identical iff they have exactly the same elements. More formally:\n\\begin{description}\n\t\\item[Axiom of Extensionality.] For all sets $X$ and $Y$, $X=Y$ iff $X\\subseteq Y$ and $Y\\subseteq X$. \n\\end{description}\n\tFor example, it follows from the axiom of extensionality that the sets $\\{1,2\\},\\{2,1\\}, \\{1,1,2\\},\\{2,1,1,2\\},\\mathellipsis$ are all one and the same sets---for they have precisely the same members. In other words, in set-theory the order and multiplicity of the elements of a set doesn't matter. \n\t\n\t\\item Note that in order to show that two sets $X$ and $Y$ are identical, we have to show two things: (i) we have to show that $X\\subseteq Y$ and (ii) we have to show that $Y\\subseteq X$. No proof of a purported set-identity is complete without having established both of these facts. To show that two sets $X$ and $Y$ are \\emph{distinct}, in contrast, it's enough to establish one of $X\\nsubseteq Y$ or $Y\\nsubseteq X$. In other words, it suffices to show either that there exists an $x$ with $x\\in X$ and $x\\notin Y$ or that there exists an $x$ with $x\\in Y$ and $x\\notin X$.\n\n\\item It is an interesting consequence of the axiom of extensionality that there exists precisely one empty set:\n\\begin{proposition}\nLet's say that a set $X$ is \\emph{empty} iff for all objects $x$, we have that $x\\notin X$. Then we have that for all sets $X$, if $X$ is empty, then $X=\\emptyset$.\n\\end{proposition}\n\\begin{proof}\nWe prove this indirectly. So, suppose that there exists a set $X$ such that $X$ is empty but $X\\neq\\emptyset$. Call this set $A$. It follows that $A\\neq \\emptyset$, which means that either $A\\nsubseteq \\emptyset$ or $\\emptyset\\nsubseteq A$. We've already established that $\\emptyset\\subseteq X$ for every set $X$ (cf. 2.2.4), so we can focus on the case that $A\\nsubseteq \\emptyset$. If $A\\nsubseteq \\emptyset$, this means that there exists an object $x$ such that $x\\in A$ but $x\\notin \\emptyset$. Call this object $a$. We get that $a\\in A$. But we've assumed that $A$ is an empty set, meaning that for all $x$, $x\\notin A$. So, certainly, $a\\notin A$. We've arrived at a contradiction, $a\\in A$ and $a\\notin A$, meaning that the assumption that  there exists an empty set $X$ with $X\\neq\\emptyset$ is false. Hence, for all sets $X$, if $X$ is empty, then $X=\\emptyset$.\n\\end{proof}\n\n\\end{enumerate}\n\n\\section{Operations on Sets: Union, Intersection, Difference}\n\n\\begin{enumerate}[\\thesection.1]\n\n\\item The \\emph{union} of two sets contains all the objects that are in at least one of the two sets. We denote the union of $X$ and $Y$ by $X\\cup Y$. More formally, for two sets $X$ and $Y$, we define \\[X\\cup Y=\\{x: x\\in X\\text{ or }x\\in Y\\}.\\] Note that  if an element is in both sets, then it is also an element of their union. So, for example, $\\{1,2\\}\\cup \\{2,3\\}=\\{1,2,3\\}$. This is because, in logic and mathematics, we typically read ``or'' \\emph{inclusively}: to say that one thing or another is the case is to say that the one thing is the case, the other is the case, or both are the case.\n\n\\item The \\emph{intersection} of two sets contains all things that are in both sets. We denote the intersection of $X$ and $Y$ by $X\\cap Y$. More formally, \\[X\\cap Y=\\{x:x\\in X\\text{ and }x\\in Y\\}.\\] In words, $X\\cap Y$ contains all the things that are both elements of $X$ and of $Y$. So, for example, $\\{1,2\\}\\cap \\{2,3\\}=\\{2\\}$. Note that if $X$ and $Y$ don't have any members in common, then $X\\cap Y=\\emptyset$. So, for example, $\\{1,2\\}\\cap \\{3,4\\}=\\emptyset$.\n\n\\item We can prove a characterization of the subset-relation in terms of intersection:\n\\begin{proposition}\nFor all sets $X$ and $Y$, if $X\\cap Y=X$, then $X\\subseteq Y$.\n\\end{proposition}\n\\begin{proof}\nLet $A$ and $B$ be two arbitrary sets and suppose that $A\\cap B=A$. We need to show that for each $x$, if $x\\in A$, then $x\\in B$. So take an arbitrary object $a$ and suppose that $a\\in A$. Suppose for indirect proof that $a\\notin B$. Since $A\\cap B=A$, it follows that $a\\in A\\cap B$. But $A\\cap B$ is defined as $\\{x:x\\in A\\text{ and }x\\in B\\}$, so it follows that $a\\in B$. We have arrived at a contradiction, $a\\in B$ and $a\\notin B$, which means that our assumption $a\\notin B$ is false. Hence $a\\in B$. So, if $a\\in A$, then $a\\in B$. Since $a$ was arbitrary, this means that for each  $x$, if $x\\in A$, then $x\\in B$. This just means that $A\\subseteq B$. So, if $A\\cap B=A$, then $A\\subseteq B$. And since $A$ and $B$ were both arbitrary, we have that for all  $X$ and $Y$, if $X\\cap Y=X$, then $X\\subseteq Y$.\n\\end{proof}\n\nThere is an analogous characterization of the subset-relation in terms of union, which you show as an exercise (see the end of the chapter).\n\n\\item The operations of union and intersection can also be applied to more than two sets. A technically convenient way of doing is is to define union (intersection) for \\emph{sets of sets}. Suppose that $\\mathcal{X}$ is a set of sets. Then we define:\n\\[\\bigcup\\mathcal{X}=\\{x: \\text{there exists a }X\\in\\mathcal{X}\\text{ such that }x\\in X\\}\\]\n\\[\\bigcap\\mathcal{X}=\\{x: \\text{for all }X\\in\\mathcal{X}\\text{, we have that }x\\in X\\}\\]\nFor example, the sets $\\{1,a,b\\}$, $\\{1,a,c\\}$, $\\{1,b,d\\}$. We get:\n\\[\\bigcup\\{\\{1,a,b\\}, \\{1,a,c\\},\\{1,b,d\\}\\}=\\{1,a,b,c,d\\}\\]\n\\[\\bigcap\\{\\{1,a,b\\}, \\{1,a,c\\},\\{1,b,d\\}\\}=\\{1\\}\\]\nIt's easily checked that for any two sets $X,Y$, we have that $X\\cup Y=\\bigcup \\{X,Y\\}$ and $X\\cap Y=\\bigcap \\{X,Y\\}$ (exercise). The real advantage of the new operations $\\bigcup$ and $\\bigcap$ is that they can also be applied to \\emph{infinite} sets of sets, but for now, we don't need to worry about that.\n\n\\item The \\emph{difference} between one set and another are all the elements that are in the one but not the other. The difference between $X$ and $Y$ is denoted $X\\setminus Y$ and defined by \\[X\\setminus Y=\\{x\\in X:x\\notin Y\\}.\\] If $X$ and $Y$ overlap, i.e. if $X\\cap Y\\neq \\emptyset$, then $X\\setminus Y$ is just the result of taking the elements of $Y$ out of $X$. So, for example, $\\{1,2,3,4\\}\\setminus \\{2,4,6\\}=\\{1,3\\}$. If $X$ and $Y$ don't overlap, set-difference doesn't do anything:\n\\begin{proposition}\nFor all sets $X$ and $Y$, if $X\\cap Y=\\emptyset$, then $X\\setminus Y=X$.\n\\end{proposition}\n\\begin{proof}\nLet $A$ and $B$ two arbitrary sets such that $A\\cap B=\\emptyset$. We need to establish that $A\\setminus B=A$. Since this is a set-identity, we need to make use of the axiom of extensionality, i.e. we need to show that (i) $A\\setminus B\\subseteq A$ and that (ii) $A\\subseteq A\\setminus B$.\n\nClaim (i) is almost immediate from the definition of $A\\setminus B$ as $\\{x\\in A: x\\notin B\\}$. For take an arbitrary object $a$ and suppose that  $a \\in A\\setminus B$. Since $A\\setminus B=\\{x\\in A: x\\notin B\\}$, this means that $a\\in A$ and $a\\notin B$. So, surely, $a\\in A$. But since $a$ was arbitrary, this means that for every object $x$, if $x\\in A\\setminus B$, then $x\\in A$, which just means that $A\\setminus B\\subseteq A$.\n\nTo establish claim (ii), we make use of our assumption that $A\\cap B=\\emptyset$. Take an arbitrary object $a\\in A$. We need to show that $a\\in A\\setminus B=\\{x\\in A: x\\notin B\\}$. We already have one part of the required condition, i.e. $a\\in A$, so let's check the other, i.e. $a\\notin B$. Suppose, for indirect proof, that $a\\in B$. This would mean that $a\\in A$ and $a\\in B$. But then $a\\in A\\cap B$ (since $A\\cap B=\\{x:x\\in A\\text{ and }x\\in B\\}$), and we've assumed that $A\\cap B=\\emptyset$. So, we have a contradiction, which means that $a\\notin B$. So, $a\\in A$ and $a\\notin B$, so $a\\in A\\setminus B$. Since $a$ was arbitrary, we conclude that for all $x$, if $x\\in A$, then $x\\in A\\setminus B$, i.e. $A\\subseteq A\\setminus B$.\n\nSince we've established that $A\\setminus B\\subseteq A$ and $A\\subseteq A\\setminus B$, we can conclude that $A\\setminus B=A$, as desired, using the axiom of extensionality.\n\\end{proof}\n\n\n\n\n\\end{enumerate}\n\n\n\\section{Ordered-Pairs and Cartesian Products}\n\n\\begin{enumerate}[\\thesection.1]\n\n\n\\item An \\emph{ordered pair} is a set-like collection of two objects, except that \\emph{order matters}. The ordered pair with $a$ as its first component and $b$ as its second component is denoted $(a,b)$. Note that $(a,b)\\neq (b,a)$. In fact, two ordered pairs are identical iff they have exactly the same components in the same place, that is: $(a_1,a_2)=(b_1, b_2)$ iff $a_1=b_1$ and $a_2=b_2$. Note also that the \\emph{number} $1$ is distinct from the \\emph{ordered pair} $(1,1)$, which has the number 1 both as its first \\emph{and} second component.\n\n\\item The notion of an ordered pair can be generalized. For $n\\geq 2$ a natural number, an \\emph{(ordered) $n$-tuple} is a set-like collection of $n$-objects in that order. We write $(a_1, \\mathellipsis, a_n)$ for the ordered $n$-tuple which has of $a_1$ as its first component, $a_2$ as its second component, \\dots, up until $a_n$ as its $n$-th component. So, for example, the 3-tuple $(1,a,\\emptyset)$ has the number 1 as its first component, the symbol $a$ as its second component, and the empty set as its third component. Note that in contrast to sets, order and multiplicity are very important with $n$-tuples. For example, $(2,1,1)$ is distinct from $(2,1)$ and $(2,1)$ is distinct from $(1,2)$.\n\n\\item The \\emph{Cartesian product} of one set with another contains all the ordered pairs that can be formed from taking an element of the first set as the first component and an element of the second set as the second component. For two sets $X$ and $Y$, we write $X\\times Y$ for their Cartesian product. Formally, we can define this by saying that \\[X\\times Y=\\{(x,y):x\\in X\\text{ and }y\\in Y\\}.\\]\n\n\\item If we have $n$ sets $X_1, \\mathellipsis, X_n$, then their \\emph{Cartesian product} is the set of all $n$-tuples with the first component from $X_1$, the second component from $X_2$, and so on up to the $n$-th component from $X_n$. We denote the Cartesian product of $X_1, \\mathellipsis, X_n$ by $X_1\\times \\mathellipsis\\times X_n$. More formally, \\[X_1\\times \\mathellipsis\\times X_n=\\{(x_1, \\mathellipsis, x_n):x_1\\in X_1, \\mathellipsis, x_n\\in X_n\\}.\\] To illustrate, consider the sets $\\{1,2\\}$ and $\\{a,b\\}$. We get that $\\{1,2\\}\\times\\{a,b\\}=\\{(1,a), (1,b), (2,a), (2,b)\\}$. Note that $\\{a,b\\}\\times \\{1,2\\}\\neq \\{1,2\\}\\times \\{a,b\\}$, since $\\{a,b\\}\\times \\{1,2\\}=\\{(a,1), (a,2), (b,1), (b,2)\\}$. The special case where $X_1=\\mathellipsis=X_n=X$ will be important, where we also denote \\[\\underbrace{X\\times\\mathellipsis\\times X}_{n\\text{ times}}\\] by $X^n$. We have, for example, that \\[\\{1,2\\}^2=\\{1,2\\}\\times\\{1,2\\}=\\{(1,1), (1,2), (2,1), (2,2)\\}.\\]\n\n\\end{enumerate}\n\n\n\\section{Properties, Relations, and Functions}\n\n\\begin{enumerate}[\\thesection.1]\n\n\t\\item A \\emph{property}, $P$, over a set of objects, $X$ is a set of elements of $X$, i.e. $P$ is a property over $X$ iff $P\\subseteq X$. The idea is that $a\\in P$ iff $a$ has the property $P$. For example, the property of being even over the natural numbers is the set \\[\\{n\\in\\mathbb{N}:\\text{there exists a }k\\in\\mathbb{N}\\text{, such that }k\\leq n\\text{ and }n=2k\\}.\\]\n\n\n\t\\item A \\emph{binary relation}, $R$, over a set of objects, $X$, is a set of ordered pairs of elements from $X$, i.e. $R$ is a binary relation over $X$ iff $R\\subseteq X^2$. The idea is that $(a,b)\\in R$ iff the object $a$ stands in the relation $R$ to $b$. For example, consider the set $A=\\{1,2,3,4\\}$. The set $R=\\{(1,2), (2,3), (3,4)\\}$ is a relation over $A$. Intuitively, it's the relation \\emph{being strictly smaller than}. In fact, we can check that for all $n,m\\in A$, $(n,m)\\in R$ iff $n<m$, i.e. $R=\\{(n,m)\\in A^2: n<m\\}$. In the case of binary relations, we sometimes also use the notation $aRb$ instead of $(a,b)\\in R$ to say that $a$ stands in the relation $R$ to $b$. E.g. if $\\leq$ is the relation $\\{(a,b)\\in \\mathbb{N}^2: a\\leq b\\}$ of being smaller than over the natural numbers $\\mathbb{N}$, then instead of $(a,b)\\in {\\leq}$, we also just write $a\\leq b$.\n\n\\item More generally, an \\emph{$n$-ary relation} over $X$, $R$, is simply a set of $n$-tuples of elements from $X$, i.e. $R\\subseteq X^n$. We say that $a_1, \\mathellipsis, a_n$ stand in relation $R$ iff $(a_1, \\mathellipsis, a_n)\\in R$. \n\n\n\\item A \\emph{function}, $f$, from one set, $X$, to another, $Y$, assigns to each element $a\\in X$ a \\emph{unique} element $f(a)\\in Y$. That is, for all $a,b\\in X$, if $f(a)\\neq f(b)$, then $a\\neq b$. In this case, the set $X$ is called the \\emph{domain} of $f$. The members of the domain are the possible inputs for $f$, for which $f$ is defined. We denote the domain of a function $f$ by $dom(f)$. The set $Y$, instead, is called the \\emph{range} of $f$. The range contains the possible values of $f$. We denote the range of $f$ by $rg(f)$. We also write $f:X\\to Y$ to say that $f$ is a function from $X$ to $Y$, i.e. $dom(f)=X$ and $rg(f)=Y$. To say that function $f:X\\to Y$ assigns $b\\in Y$ as the value to $a\\in X$, we write $f(a)=b$ or $a\\overset{f}{\\mapsto}b$.\n\n\\item Here are some assignments from $\\{a,b,c,d\\}$ to $\\{1,2,3,4\\}$ that aren't functions:\n\n\\begin{center}\n\t\n\\begin{tabular}{c c c}\n  \\begin{tikzpicture}[scale=.75,\n     >=stealth,\n     bullet/.style={\n       fill=black,\n       circle,\n       minimum width=1pt,\n       inner sep=1pt\n     },\n     projection/.style={\n       ->,\n       thick,\n       shorten <=2pt,\n       shorten >=2pt\n     },\n     every fit/.style={\n       ellipse,\n       draw,\n       inner sep=0pt\n     }\n   ]\n     \\foreach \\y/\\l in {1/d,2/c/,3/b,4/a}\n       \\node[bullet,label=left:$\\l$] (a\\y) at (0,\\y) {};\n \n     \\foreach \\y/\\l in {1/4,2/3,3/2,4/1}\n       \\node[bullet,label=right:$\\l$] (b\\y) at (4,\\y) {};\n \n     \\node[draw,fit=(a1) (a2) (a3) (a4),minimum width=1.5cm] {} ;\n     \\node[draw,fit=(b1) (b2) (b3) (b4),minimum width=1.5cm] {} ;\n \n     \\draw[projection] (a4) -- (b4);\n     \\draw[projection] (a4) -- (b3);\n     \\draw[projection] (a2) -- (b3);\n     \\draw[projection] (a3) -- (b1);\n     \\draw[projection] (a4) -- (b3);\n     \\draw[projection] (a1) -- (b2);\n   \\end{tikzpicture}\n   &\n   \\quad\n   &\n    \\begin{tikzpicture}[scale=.75,\n     >=stealth,\n     bullet/.style={\n       fill=black,\n       circle,\n       minimum width=1pt,\n       inner sep=1pt\n     },\n     projection/.style={\n       ->,\n       thick,\n       shorten <=2pt,\n       shorten >=2pt\n     },\n     every fit/.style={\n       ellipse,\n       draw,\n       inner sep=0pt\n     }\n   ]\n     \\foreach \\y/\\l in {1/d,2/c/,3/b,4/a}\n       \\node[bullet,label=left:$\\l$] (a\\y) at (0,\\y) {};\n \n     \\foreach \\y/\\l in {1/4,2/3,3/2,4/1}\n       \\node[bullet,label=right:$\\l$] (b\\y) at (4,\\y) {};\n \n     \\node[draw,fit=(a1) (a2) (a3) (a4),minimum width=1.5cm] {} ;\n     \\node[draw,fit=(b1) (b2) (b3) (b4),minimum width=1.5cm] {} ;\n \n     \\draw[projection] (a4) -- (b4);\n     \\draw[projection] (a2) -- (b1);\n     \\draw[projection] (a3) -- (b1);\n   \\end{tikzpicture}\n   \n   \\\\\n   \n   More than one value for $a$ & & No value for $d$\n   \n   \\end{tabular}\n  \\end{center}\n  \n  The point is \\emph{every} element of the domain needs to be assigned \\emph{exactly} one value from the range. As long as these requirements are met, we have a function. So, the following two assignments \\emph{are} functions:\n  \n  \\begin{center}\n\t\n\\begin{tabular}{c c c}\n  \\begin{tikzpicture}[scale=.75,\n     >=stealth,\n     bullet/.style={\n       fill=black,\n       circle,\n       minimum width=1pt,\n       inner sep=1pt\n     },\n     projection/.style={\n       ->,\n       thick,\n       shorten <=2pt,\n       shorten >=2pt\n     },\n     every fit/.style={\n       ellipse,\n       draw,\n       inner sep=0pt\n     }\n   ]\n     \\foreach \\y/\\l in {1/d,2/c/,3/b,4/a}\n       \\node[bullet,label=left:$\\l$] (a\\y) at (0,\\y) {};\n \n     \\foreach \\y/\\l in {1/4,2/3,3/2,4/1}\n       \\node[bullet,label=right:$\\l$] (b\\y) at (4,\\y) {};\n \n     \\node[draw,fit=(a1) (a2) (a3) (a4),minimum width=1.5cm] {} ;\n     \\node[draw,fit=(b1) (b2) (b3) (b4),minimum width=1.5cm] {} ;\n \n     \\draw[projection] (a4) -- (b3);\n     \\draw[projection] (a2) -- (b3);\n     \\draw[projection] (a3) -- (b1);\n     \\draw[projection] (a1) -- (b2);\n   \\end{tikzpicture}\n   &\n   \\quad\n   &\n    \\begin{tikzpicture}[scale=.75,\n     >=stealth,\n     bullet/.style={\n       fill=black,\n       circle,\n       minimum width=1pt,\n       inner sep=1pt\n     },\n     projection/.style={\n       ->,\n       thick,\n       shorten <=2pt,\n       shorten >=2pt\n     },\n     every fit/.style={\n       ellipse,\n       draw,\n       inner sep=0pt\n     }\n   ]\n     \\foreach \\y/\\l in {1/d,2/c/,3/b,4/a}\n       \\node[bullet,label=left:$\\l$] (a\\y) at (0,\\y) {};\n \n     \\foreach \\y/\\l in {1/4,2/3,3/2,4/1}\n       \\node[bullet,label=right:$\\l$] (b\\y) at (4,\\y) {};\n \n     \\node[draw,fit=(a1) (a2) (a3) (a4),minimum width=1.5cm] {} ;\n     \\node[draw,fit=(b1) (b2) (b3) (b4),minimum width=1.5cm] {} ;\n \n     \\draw[projection] (a4) -- (b4);\n     \\draw[projection] (a2) -- (b1);\n     \\draw[projection] (a3) -- (b1);\n     \\draw[projection] (a1) -- (b3);\n   \\end{tikzpicture}\n      \\\\\n      $f_1$ & & $f_2$\n   \\end{tabular}\n  \\end{center}\n  \n\\item Functions are everywhere in mathematics. Take, for example, the successor function $\\mathsf{S}:\\mathbb{N}\\to \\mathbb{N}$, which is defined by $\\mathsf{S}(n)=n+1$ for all numbers $n\\in\\mathbb{N}$. Note that the domain and the range of this function are the same, which is allowed. But functions can also operate on other kinds of objects. Take the two sets $\\{a,b,c,d\\}$ and $\\{1,2,3,4\\}$ from above. We can specify the two functions $f_1$ and $f_2$ from the diagram in 2.6.4 as follows:\n\t\\begin{center}\n\t\t\\begin{tabular}{c | c}\n\t\t$f_1$ &  \\\\\n\t\t\\hline\n\t\ta & 2\\\\\n\t\tb & 4\\\\\n\t\tc & 2\\\\\n\t\td & 3\n\t\t\\end{tabular}\n\t\t\\hspace{8ex}\n\t\t\t\\begin{tabular}{c | c}\n\t\t$f_2$ &  \\\\\n\t\t\\hline\n\t\ta & 1\\\\\n\t\tb & 4\\\\\n\t\tc & 4\\\\\n\t\td & 2\n\t\t\\end{tabular}\n\t\\end{center}\n    This is called a \\emph{function table}.\n    It tells us for every possible input from $\\{a,b,c,d\\}$ what the output in $\\{1,2,3,4\\}$ is.\n    For $f_{1}$, we have, for example,\n    $f_{1}(a)=2, f_{1}(b)=4, f_{1}(c)=2,$ and $f_{1}(d)=3$,\n    while for $f_{2}$, we have\n    $f_{2}(a)=1, f_{2}(b)=4, f_{2}(c)=4,$ and $f_{2}(d)=2$.\n    Note that not every element in the range is assigned as a value to some input.\n    This is allowed,\n    since the range only contains the \\emph{possible} values for $f$.\n    The \\emph{actual} values of $f:X\\to Y$ are the members of the set $\\{f(x): x\\in X\\}$.\n    This set is called the \\emph{image} of $f$,\n    and it's denoted $im(f)$.\n    We have, for example,\n    $im(f_1)=\\{2,3,4\\}$ and $im(f_2)=\\{1,2,4\\}$.\n\n\\item What's important when specifying a function $f:X\\to Y$ is to say for each $x\\in X$ what the value $f(x)\\in Y$ is. This can be done in many different ways. Above, we've already seen a function table, which will be a useful method of specifying a function. But this, of course, only works when the domain of $f$ is finite. In cases where the domain is infinite, we can specify a function like we did in the case of the successor function, by means of a \\emph{function rule}. The function rule of $\\mathsf{S}:\\mathbb{N}\\to \\mathbb{N}$ was given by $\\mathsf{S}(n)=n+1$. This can also be written as $n\\overset{\\mathsf{S}}{\\mapsto}n+1$. It's important to note that we can't always figure out the function rule in such a clear way. There are functions where we don't know the function rule, but that doesn't stop them from being functions. We can, and in fact will, often talk about functions abstractly, without knowing what their function rule is (or, in fact, if there even is an intelligible one). All we know in such a case is that every member of the domain gets precisely one value from the range. That's it.\n\n\\item A common way of specifying the values a function gives is by distinguishing the possible inputs, the domain, into a finite list of exclusive and exhaustive cases and say which output the function gives for each of these cases.\\footnote{The list needs to be exclusive in order to avoid that an input gets more than one value, and it needs to be exhaustive to ensure that every input gets a value.} The idea is best illustrated by means of an example. Consider the function $f:\\mathbb{N}\\to\\{0,1\\}$, which gives the result $1$ when applied to an even number and the result $0$ when applied to an odd number. A concise way of writing this is as follows: \\[f(n)=\\begin{cases} 1 & \\text{if }n\\text{ is even}\\\\0 &\\text{if }n\\text{ is odd}\\end{cases}\\] There can, of course, be more than two cases. Consider the function $g:\\mathbb{N}\\to\\{1, 2, 3\\}$, which assigns $1$ to every even number, $2$ to every prime bigger than $2$, and $3$ to every other number. This function can be determined as follows:\n\\[g(n)=\\begin{cases} 1 & \\text{if }n\\text{ is even}\\\\2 &\\text{if }n\\text{ is prime and }n>2\\\\3&\\text{ otherwise}\\end{cases}\\] Note that the ``otherwise'' here is a good catch-all to make an otherwise non-exhaustive list exhaustive.\n\n\\item An \\emph{$n$-ary function} from $X$ to $Y$ is a function $f:X^n\\to Y$. That is, $f$ assigns a value from $Y$ to every $n$-tuple of members from $X$. For $(a_1, \\mathellipsis, a_n)\\in X^n$, we also write $f(a_1, \\mathellipsis, a_n)$ for the more correct $f((a_1, \\mathellipsis, a_n))$. The case of a binary function $f:X^2\\to Y$ will be particularly important in the following. In case where $X$ is finite, we can also give a function table for $f:X^2\\to Y$. Consider, for example, the function $f\\{a,b,c\\}^2\\to \\{0,1\\}$ given by the following assignment:\n\\begin{center}\n\t\\begin{tabular}{c c c c c c c c c c c}\n\t$(a,a)$ & $\\overset{f}{\\mapsto}$ & 0 & \\quad & (b,a) & $\\overset{f}{\\mapsto}$ & 0  \\quad & (c,a) & $\\overset{f}{\\mapsto}$ & 1\\\\\n\n\t$(a,b)$ & $\\overset{f}{\\mapsto}$ & 1 & \\quad & (b,b) & $\\overset{f}{\\mapsto}$ & 0  \\quad & (c,b) & $\\overset{f}{\\mapsto}$ & 1\\\\\n\n\n\t$(a,c)$ & $\\overset{f}{\\mapsto}$ & 1 & \\quad & (b,c) & $\\overset{f}{\\mapsto}$ & 1  \\quad & (c,c) & $\\overset{f}{\\mapsto}$ & 0\\\\\n\n\n\t\\end{tabular}\n\\end{center}\n\nThis assignment can be given in table form as follows:\n\n\\begin{center}\n\t\\begin{tabular}{ c | c c c}\n\t$f$ & $a$ & $b$ & $c$ \\\\ \\hline\n\t\n\t$a$ & 0 & 1 & 1\\\\\n\t\n\t$b$ & 0 & 0 & 1\\\\\n\t\n\t$c$ & 1 & 1 & 0\n\t\n\t\\end{tabular} \n\t\n\\end{center}\n\nThe convention hereby is that the first input is in the left-most column and the second input in the top-most row. Notice that $f(x,y)\\neq f(y,x)$ is possible, e.g. in our case $f(a,b)=1\\neq 0=f(b,a)$.\n\nSo, generally, if $X=\\{a_1, \\mathellipsis, a_n\\}$ is a finite set, the function table for a function $f:X^2\\to Y$ is given as follows:\n\n\\begin{center}\n\t\\begin{tabular}{ c | c c c}\n\t$f$ & $a_1$ & $\\cdots$ & $a_n$ \\\\ \\hline\n\t\n\t$a_1$ &  $f(a_1, a_1)$ & $\\cdots$ & $f(a_1, a_n)$\\\\\n\t\n\t$\\vdots$ & $\\vdots$ & & $\\vdots$\\\\\n\t\n\t$a_n$ &  $f(a_n, a_1)$ & $\\cdots$ & $f(a_n, a_n)$\\\\\n\t\n\t\\end{tabular} \n\t\n\\end{center}\n\n\t\\item So far, we spoke about functions using the informal notion of an \\emph{assignment}. Formally speaking, however, a function is typically understood as a special kind of set. A function $f$ is understood as a triple $(dom(f), rg(f), R_f)$. Here, $dom(f)$ and $rg(f)$ are arbitrary sets, which constitute the domain and range of the function respectively. The special component is $R_f$, which, intuitively, is the \\emph{assignment relation} of the function. More formally, $R_f\\subseteq dom(f)\\times rg(f)$ is a set of pairs $(x,y)$ where $x\\in dom(f)$ and $y\\in rg(f)$ subject to the two conditions:\n\t\\begin{description}\n\t\n\t\t\\item[Left-totality.] For each $x\\in dom(f)$, there exists a $y\\in rg(f)$ such that $(x,y)\\in R_f$.\n\t\n\t\t\\item[Right-uniqueness.] If $(x,y)\\in R_f$ and $(x,z)\\in R_f$, then $y=z$.\n\t\n\t\\end{description}\n\t\n\tWe will not rely on the formal definition of a function much in this course, but we will need it for the semantics of first-order logic. We conclude our discussion of functions with the fully formal definition of function $f_1$ from 3.6.4, as an example:\n\t\n\t\\[f_1=(\\{a,b,c,d\\}, \\{1,2,3,4\\}, \\{(a,2), (b,4), (c,2), (d,3)\\})\\]\n\t\n\t\\item Finally, we can generalize our notation $\\{\\frac{n}{m}:n,m\\in \\mathbb{Z}, m\\neq 0\\}$ from 3.1.8 to the general case. For $f:X\\to Y$ and $X'\\subseteq X$, we define: \\[\\{f(x):x\\in X'\\}=\\{y:\\text{there exists a }x\\in X'\\text{, such that }y=f(x)\\}\\] This is really just a useful abbreviation, which we'll use here and there.\n\t \n\\end{enumerate}\n\n\\section{Inductive Definitions and Proof by Induction}\n\n\\emph{The ideas of this section are among the hardest of the course. But these ideas lie at the heart of logical theory, that's why it's important that we discuss them from different angles. Here we begin with some examples and a description of the general idea. In the following chapter, we will apply these ideas to define a logical language. If not everything is perfectly clear after this chapter, don't despair---keep working on it and (hopefully) it will all make sense soon.}\n\n\\begin{enumerate}[{\\thesection}.1]\n\n\t\\item In 2.1.3, we mentioned that $\\mathbb{N}$ shouldn't be written $\\{0,1,2,\\mathellipsis\\}$. We'll now discuss a powerful method for defining infinite sets like $\\mathbb{N}$, so-called \\emph{inductive definitions}. Let's begin with the natural numbers as an example. Note that the natural numbers are essentially just zero and all its successors, where a number $m$ is said to be the successor of a number $n$ iff $m=n+1$. So, clearly, zero is a natural number and if we take a natural  number, then its successor (the result of adding one) is also a natural number. More precisely:\t\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $0\\in \\mathbb{N}$\n\t\t\n\t\t\\item For all $n$, if $n\\in\\mathbb{N}$, then $n+1\\in \\mathbb{N}$\n\t\n\t\\end{enumerate}\n\t\n\tUsing these two facts, we easily can show that $1,2,3, \\mathellipsis$ are all natural numbers. Take the number three. Here's how we show that $3\\in \\mathbb{N}$: We know that $0\\in\\mathbb{N}$ by (i). By (ii), it follows that $0+1=1\\in\\mathbb{N}$. Again by (ii) it follows that $1+1=2\\in\\mathbb{N}$. Finally, again by (ii), it follows that $2+1=3\\in \\mathbb{N}$. This clearly generalizes to every natural number $n$. By $n$ applications of (ii), we can show that $n\\in\\mathbb{N}$. The bottom-line is that (i) and (ii) together allow us to derive for every natural number that it is a member of the set $\\mathbb{N}$. But we want more. We also want to be able to show that \\emph{only} natural numbers are members of $\\mathbb{N}$, i.e. there is no number which is not a natural number but a member of $\\mathbb{N}$.\t To do that, we use a simple trick: we simply stipulate that the objects which can be shown to be members of $\\mathbb{N}$ by (i) and (ii) are \\emph{all} the natural numbers. This is typically written as follows:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\setcounter{enumii}{2}\n\t\n\t\t\\item Nothing else is a member of $\\mathbb{N}$.\n\t\n\t\\end{enumerate}\nTogether (i), (ii), and (iii) constitute an inductive definition of the natural numbers. Many sets can be defined inductively (and some cannot). The reason why we're discussing inductive definitions now is that the set of formulas of a formal language is usually given an inductive definition. What's particularly appealing about inductive definitions is that they allow us to define an infinite set, like $\\mathbb{N}$, in a finitary way---using just three conditions viz. (i), (ii), and (iii). This is very important for the computer implementability of arithmetic (the theory of the natural numbers): without a finitary way of encoding the numbers, how should a computer be able to handle them?\n\n\t\\item How do you show that a number $n$ is \\emph{not} a member of $\\mathbb{N}$? Well, essentially, what you have to show is that there is no way of reaching $n$ by repeatedly adding one to zero. It seems clear, for example, that we can't reach $\\frac{1}{2}$ in this way. But to actually \\emph{prove} it, we will need a more precise version of inductive definitions, which we'll discuss below. However, most of the time, it will be enough to ``see'' that a number can't be constructed by repeatedly adding one to zero to justify the claim that it's not in $\\mathbb{N}$.\n\t\n\t\\item If a set is defined inductively, then there's a powerful way of defining functions on the set, where the function is defined ``following the inductive definition.'' This method is known as \\emph{function recursion}. To illustrate the idea, let's use function recursion to define a function $f:\\mathbb{N}^2\\to\\mathbb{N}$. In order to define $f$, we need to say for every pair of numbers $n,m\\in\\mathbb{N}$ what the result of $f(n,m)$ is. This is done by recursion as follows:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item For every number $n\\in\\mathbb{N}$, $f(n, 0)=0$.\n\t\t\n\t\t\\item For all numbers $n,m\\in\\mathbb{N}$, $f(n,m+1)=f(n,m)+n$.\n\t\n\t\\end{enumerate}\nNote the pattern here: we first say what the result of $f(n,0)$ is, and then we say what the result of $f(n,m+1)$ is, but in terms of what the result of $f(n,m)$ is. In this way, since zero and it's successors are \\emph{all} the natural numbers, we've said for \\emph{every} number what the result of $f(n,m)$ is. To see that that's the case, let's calculate $f(3,2)$ using the recursive definition (i) and (ii):\n\n\t\\begin{itemize}\n\t\n\t\t\\item $f(3, 0)=0$, by clause (i)\n\t\t\n\t\t\\item So, $f(3,1)=f(3,0+1)=f(3,0)+3=3$ by clause (ii).\n\t\t\n\t\t\\item So, $f(3,2)=f(3, 1+1)=f(3,1)+3=3+3=6$ by clause (ii).\n\t\t\t\n\t\\end{itemize}\nHere, we calculated ``bottom up:'' we started from $f(3,0)$ and figured out what $f(3,2)$ needed to be. We might as well have gone ``backwards,'' as follows: \n\\begin{itemize}\n\t\n\t\t\\item We want to know the result of $f(3,2)$. But $f(3,2)=f(3,1+1)$ and, by (ii), $f(3,1+1)=f(3, 1)+3$.\n\t\t\n\t\t\\item So, in order to calculate $f(3,2)$, we need to calculate $f(3,1)$. Now, $f(3,1)=f(3,0+1)$ and by (ii) $f(3,0+1)=f(3,0)+3$.\n\t\t\n\t\t\\item So, we need to calculate $f(3,0)$, but we know what that is by (i), viz. $f(3, 0)=0$.\n\t\t\n\t\t\\item Putting it all together, we get that $f(3,2)=f(3,1+1)=f(3,1)+3=f(3,0+1)+3=(f(3, 0)+3)+3=3+3=6$.\n\t\n\t\\end{itemize}\nIn this way of calculating the result, in each step, we need to figure out the result for a lower number, until eventually, we need to figure out the result for zero is. This ``calling upon'' results for lower numbers is where ``function recursion'' gets its name from. Note that because every number is the result of adding one to zero a bunch of times, this procedure works.\n\n\tDo you recognize the function $f$? What does it do? Think about it before you move on, we'll answer the question in a moment.\n\t\n\tA side-remark: function recursion is of fundamental importance in computer implementations of calculation. You can easily see why: it allows us to specify a function with an infinite domain in a finitary way. Otherwise, how should a computer, with finite memory, be able to deal with functions on the natural numbers?\n\n\t\\item And if a set is defined inductively, then there's a powerful \\emph{proof method} for proving things about (all) its members: \\emph{proof by induction}. The idea is, once more, to follow the inductive definition of the set when proving things about it. To make this idea clear, let's use $\\mathbb{N}$ again as an example.  Suppose that $\\Phi(n)$ is a condition on natural numbers, something like ``if $n$ is even, then $n$ is not odd'' or the like.  Suppose further that we can show the following two facts:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item Zero satisfies the condition, i.e. $\\Phi(0)$.\n\t\t\n\t\t\\item If a number satisfies the condition, then also its successor does, i.e. for all $n\\in\\mathbb{N}$, if $\\Phi(n)$, then $\\Phi(n+1)$. \n\t\n\t\\end{enumerate}\nIn such a situation, we can conclude that \\emph{every} number satisfies the condition. Why? Well, pick a number, any number. We know that this number can be reached by successively adding one to zero---after all, ``nothing else is a natural number.'' We know that zero satisfies the condition by (i). And we know that if zero satisfies the condition, then one satisfies the condition by (ii). So we know that one satisfies the condition. And we know that if one satisfies the condition, then two satisfies the condition by (ii). So, two satisfies the condition. And we know that if two satisfies the condition, then \\dots. And so on. We will eventually reach every number like this---again, ``nothing else is a natural number.'' So, if we can establish (i) and (ii), we can conclude that every natural number has the property. \n\n\t\\item In an inductive proof, the condition (i) is called the \\emph{base case} and (ii) is called the \\emph{induction step}. So, to be precise, the form of an inductive proof over the natural numbers is always that we establish that all natural numbers have a property by showing that (i) zero has the property and (ii) if a number has the property, then also its successor does. Note that for step (ii), we need to establish the truth of a conditional: \\emph{if} a number has the property, \\emph{then} the successor of the number has the property. We do this by conditional proof, i.e. we \\emph{assume} that a number has the property, and we derive that its successor does, too. In this very special case, the assumption is known as the \\emph{induction hypothesis} and it is referred to as such in inductive proofs. Here is an example of a proof by induction for over the natural numbers:\n\t\n\t\\begin{proposition}\n\tLet $f:\\mathbb{N}^2\\to\\mathbb{N}$ be defined as in 3.7.3. Then, for all $n,m\\in\\mathbb{N}$, we have that $f(n,m)=n\\cdot m$.\n\t\\end{proposition}\n\t\\begin{proof}\n\tWe prove this using mathematical induction. In order to be able to conclude our result, we have to prove two things:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $f(n,0)=n\\cdot 0$ (`base case')\n\t\t\n\t\t\\item For all $n,m\\in\\mathbb{N}$, if $f(n,m)=n\\cdot m$, then $f(n,m+1)=n\\cdot (m+1)$. (`induction step')\n\t\n\t\\end{enumerate}\n\tWe prove these in turn.\n\t\n\tFor the base case, (i), note that by (i) of 3.7.3, $f(n,0)=0$ for every $n\\in\\mathbb{N}$. Since $n\\cdot 0=0$ for all $n\\in\\mathbb{N}$, the claim holds.\n\t\n\tFor the induction step, (ii), let $n,m\\in\\mathbb{N}$ be arbitrary numbers and assume that $f(n,m)=n\\cdot m$ as the induction hypothesis. Consider $f(n,m+1)$. By clause (ii) of 3.7.3, we know that $f(n,m+1)=f(n,m)+n$. But by the induction hypothesis, we know that $f(n,m)=n\\cdot m$, so we get $f(n,m+1)=f(n,m)+n=(n\\cdot m)+n=n\\cdot (m+1)$, which is what we needed to show.\n\t\n\tHence, by mathematical induction, we conclude that for all $n,m\\in\\mathbb{N}$, we have that $f(n,m)=n\\cdot m$.\n\t\\end{proof}\n\nProof  by induction over the natural numbers is also called \\emph{mathematical induction}. Essentially, each inductively defined set has its own principle for proof by induction. In the following chapter, we will discuss how to prove things about all formulas of a formal language using proof by induction.\n\n\t\\item You will exercise some more simple cases of mathematical induction to get the idea of how inductive proofs work. You will \\emph{not} have to master the technique during the course, however---this is not a course in number theory. In the next chapter, we'll discuss another version of inductive proof that you \\emph{will} have to master, a version of inductive proof for formal languages.\n\t\n\t\\item Before we describe how inductive definitions work in general, let's give recursive definitions a slightly more precise shape. The problem we're tackling is to make the claim that ``nothing else is a member of $\\mathbb{N}$'' mathematically precise. The standard idea for doing this is to define $\\mathbb{N}$ as the \\emph{smallest} set that contains zero and all its successors.  Here we think of a set $X$ as \\emph{smaller} than another set $Y$ iff $X\\subseteq Y$. The sense in which $\\mathbb{N}$ is the smallest set containing zero and all its successors is that for any set $X$ such that $X$ contains zero and all its successors, we have that $\\mathbb{N}\\subseteq X$. In other words, $\\mathbb{N}$ is smaller than any other set containing zero and all its successors.  Just think of any other set that also contains zero and all its successors, say $\\mathbb{Z}, \\mathbb{Q},$ and $\\mathbb{R}$. Clearly, we have that $\\mathbb{N}\\subseteq \\mathbb{Z}$, $\\mathbb{N}\\subseteq \\mathbb{Q}$, and $\\mathbb{N}\\subseteq \\mathbb{R}$. Can we find a set that contains zero and all it's successors but not all the members of $\\mathbb{N}$? If ``nothing else is a member of $\\mathbb{N}$'' is correct, the answer would need to be: no! So, the idea would now be to define $\\mathbb{N}$ as the smallest set $X$ such that the following two conditions hold: \n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $0\\in X$\n\t\t\n\t\t\\item For all numbers $x$, if $x\\in X$, then $x+1\\in X$.\n\t\n\t\\end{enumerate}\nHow do we know that such a set exists (and that it's unique)? Well, that needs to be postulated as an axiom of mathematics: in axiomatic set theory, the claim that $\\mathbb{N}$, so defined, exists is known as the \\emph{axiom of infinity}.\n\n\t\\item Having given a precise definition of $\\mathbb{N}$, we can now \\emph{prove} that certain numbers aren't natural, i.e. we can prove claims of the form $x\\notin\\mathbb{N}$. To see how this works, let's prove that $\\frac{1}{2}$ is not a natural number:\n\t\n\t\t\\begin{proposition}\n\t\tWe have that $\\frac{1}{2}\\notin \\mathbb{N}$.\n\t\t\\end{proposition} \n\t\t\\begin{proof}\n\t\tLet $X$ be some set that satisfies the conditions (i) and (ii) of the definition of $\\mathbb{N}$. Suppose further that $\\frac{1}{2}\\in X$. We claim that under this assumption, also the set \\[Y=X\\setminus \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}\\] satisfies conditions (i) and (ii).\\footnote{Note that the definitions of even and odd can easily be generalized to $\\mathbb{Z}$: a number $n\\in\\mathbb{Z}$ is \\emph{even} iff there exists a $k\\in\\mathbb{Z}$ such that $2k=2n$. And a number $n\\in\\mathbb{Z}$ is \\emph{odd} iff $n$ is not even.}\tWe prove these in turn:\n\t\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item To see that $0\\in Y$, first note that $0\\in X$. So, to show that $0\\in Y$ all we need to show is that $0\\notin \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$. Why? Because $Y=X\\setminus  \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}=\\{x\\in X: x\\notin  \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}\\}$. We prove that $0\\notin \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$ by contradiction. So suppose that $0\\in \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$, which would mean that there exists a $k\\in\\mathbb{Z}$, which is odd and $\\frac{k}{2}=0$. But then, it follows easily, that $k=0$. And $0$ is even (to see this note that $2\\cdot 0=0$). Hence $k$ would need to be both even and odd, which is impossible. Hence $0\\notin \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$.\n\t\t\n\t\t\\item We need to show that for all numbers $x$, if $x\\in Y$, then $x+1\\in Y$. So, let $n$ be an arbitrary number and suppose that $n\\in Y$. By definition of $Y$, this means that $n\\in X$. And since $X$ satisfies condition (ii), we get that $n+1\\in X$. Now to show that $n+1\\in Y$, we need to show that $n+1\\notin   \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$. (Why? The answer's essentially the same as the one to the why-question in (i)!) So, for proof by contradiction, suppose that $n+1\\in \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$. We get that there exists a $k\\in \\mathbb{Z},$ such that $k$ is odd and $n+1=\\frac{k}{2}$.  It follows that $n=\\frac{k}{2}-1=\\frac{k-2}{2}$. But now note that if $k$ is odd, then $k-2$ is odd, too.  Hence, $n\\in   \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$.  But since $n\\in Y$, we have that $n\\notin   \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$. Contradiction. So, $n+1\\notin  \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$. But now we have that $n+1\\in X$ and $n+1\\notin  \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$, which just means that $n+1\\in Y$, as desired.\n\t\t\n\t\\end{enumerate}\n\t\t\n\t\tSo, if $X$ satisfies conditions (i) and (ii) and $\\frac{1}{2}\\in X$, then there is a smaller set, viz. $X\\setminus  \\{\\frac{k}{2}: k\\in \\mathbb{Z}\\text{ and }k\\text{ is odd}\\}$, which satisfies conditions (i) and (ii), too. But then $X$ cannot be the smallest set satisfying conditions (i) and (ii), i.e. $X$ cannot be $\\mathbb{N}$. Now suppose, for a final proof by contradiction, that $\\frac{1}{2}\\in\\mathbb{N}$. Since $\\mathbb{N}$ satisfies conditions (i) and (ii) from its definition,  we've just seen that this would entail that $\\mathbb{N}\\neq \\mathbb{N}$, which is impossible. Hence, by indirect proof, $\\frac{1}{2}\\notin\\mathbb{N}$, as desired.\n\n\t\t\\end{proof}\n\nIt's not terribly important that you get all the details of this argument, but I want you to see the general form of how you might go about proving that something's not a member of an inductively defined set (and that that's surprisingly difficult). If you really want to understand the proof (and, again, you don't have to), try to prove the same result using mathematical induction.\n\n\\item What's particularly pleasing about our precise definition of $\\mathbb{N}$ is that it allows us \\emph{prove} the principle of mathematical induction:\n\t\n\t\\begin{theorem}[Mathematical Induction]\n\tSuppose that $\\Phi$ is a condition on numbers such that:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item $\\Phi(0)$\n\t\t\t\n\t\t\t\\item for all natural numbers $n\\in\\mathbb{N}$, if $\\Phi(n)$, then $\\Phi(n+1)$.\n\t\t\n\t\t\\end{enumerate}\t\n\t\tThen it follows that all natural numbers satisfy the condition $\\Phi$, i.e. we have that $\\Phi(n)$, for all $n\\in \\mathbb{N}$.\n\t\\end{theorem}\n\t\\begin{proof}\n\tLet $\\Phi$ be an arbitrary condition on numbers 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 $\\mathbb{N}$. Since $\\mathbb{N}$ is the smallest set satisfying those conditions, we have that $\\mathbb{N}\\subseteq\\{x:\\Phi(x)\\}$. But now, it easily follows that for all $n\\in\\mathbb{N}$, we have that $\\Phi(n)$. For let $n\\in\\mathbb{N}$ be an arbitrary number. Since $\\mathbb{N}\\subseteq\\{x:\\Phi(x)\\}$, it follows that $n\\in\\{x:\\Phi(x)\\}$. But that just means that $\\Phi(n)$, as desired.\n\t\\end{proof}\n\n\\item Now that you've seen how to recursively define the natural numbers and how we can derive the proof principle of mathematical induction from the definition, let's focus on the idea of recursive definitions in general. In order to inductively define a set, we \\emph{always} use the following pattern:\n\t\\begin{enumerate}[1.]\n\t\n\t\t\\item We give a set of initial elements.\n\t\t\n\t\t\\item We provide a list of \\emph{constructions} that allow us to form new elements from old elements.\n\t\t\n\t\t\\item We define our set as the smallest set that contains all the initial elements and that is \\emph{closed under} the constructions, meaning that if we apply the constructions to elements, we get new elements.\n\t\n\t\\end{enumerate} \n\t\nIn the recursive definition of $\\mathbb{N}$, the only initial element is the number zero and the only construction is the simple operation of adding one. But more generally, we can have any number of initial elements and any number of constructions that allow us to construct new elements..\n\n\t\\item \\emph{Running Example (Gargles)}. We give an inductive definition of the set $Gargle$ of gargles. Here we go: \n\t\n\t\t\\begin{enumerate}[1.]\n\t\t\n\t\t\t\\item The set of initial elements is $\\{\\clubsuit,\\spadesuit\\}$.\n\t\t\t\n\t\t\t\\item Our constructions are all constructions of writing symbols next to each other. We consider the following constructions:\n\t\t\t\\begin{enumerate}\n\t\t\t\t\t\t\n\t\t\t\t\\item Take any gargle $x$ and write $\\diamondsuit$ before and after it, giving $\\diamondsuit x\\diamondsuit$ as the result.\n\t\t\t\n\t\t\t\t\\item Take any two gargles $x,y$ and write $\\heartsuit$ in between, giving $x\\heartsuit y$ as the result.\n\t\t\t\t\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\\item Our set $Gargle$ is now defined as the smallest set $X$ such that:\n\t\t\t\n\t\t\t\\begin{enumerate}[(i)]\n\t\t\t\n\t\t\t\t\\item $\\{\\clubsuit,\\spadesuit\\}\\subseteq X$.\n\t\t\t\n\t\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\t\t\n\t\t\t\t\t\\item For all $x$, if $x\\in X$, then $\\diamondsuit x\\diamondsuit\\in X$.\n\t\t\t\n\t\t\t\t\t\\item For all $x$ and $y$, if $x,y\\in X$, then $ x\\heartsuit y\\in X$.\n\t\t\t\t\n\t\t\t\t\\end{enumerate}\n\t\t\t\n\t\t\t\t\\end{enumerate}\n\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\n\t\t\t\tThe set $Gargle$ has infinitely many elements:\n\t\t\t\t\n\t\t\t\t\\begin{itemize}\n\t\t\t\t\n\t\t\t\t\t\\item $\\clubsuit,\\spadesuit\\in Gargle$\n\t\t\t\t\t\n\t\t\t\t\t\\item $\\diamondsuit\\clubsuit\\diamondsuit,\\diamondsuit\\spadesuit\\diamondsuit\\in Gargle$\n\t\t\t\t\t\n\t\t\t\t\t\\item $\\clubsuit\\heartsuit\\clubsuit, \\clubsuit\\heartsuit\\spadesuit, \\spadesuit\\heartsuit\\spadesuit\\in Gargle$\n\t\t\t\t\n\t\t\t\t\t\\item $\\clubsuit\\heartsuit\\diamondsuit\\clubsuit\\diamondsuit, \\diamondsuit\\spadesuit\\diamondsuit\\heartsuit\\spadesuit,\\mathellipsis\\in Gargle$\n\n\t\t\t\t\n\t\t\t\t\\end{itemize}\t\t\t \n\t\t\t\t\n\t\t\\item Next, let's discuss how function recursion works generally. As we hinted at above, whenever we have an inductively defined set, we can use function recursion to define a function on that set. The way this works is as follows:\n\t\t\n\t\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\n\t\tWhen we give these two pieces of information, we've defined a function on the inductively defined set: since the set is the smallest set which contains the initial elements and is closed under the constructions, for each element in the set we can determine the value of our function.\n\n\t\t\\item So, how do we recursively define a function $f$ with $dom(f)=Gargle$? Well, we have to answer the following questions:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item What are the values of $ f(\\clubsuit)$ and $f(\\spadesuit)$?\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\t\t\t\n\t\t\t\t\t\\item  What is the value of $f(\\diamondsuit x\\diamondsuit)$ in terms of the value of $f(x)$?\n\n\t\t\t\t\t\\item What is the value of $f(x\\heartsuit y)$ in terms of the values of $f(x)$ and $f(y)$?\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\tConsider, for example, the function $\\#_\\spadesuit:Gargle\\to\\mathbb{N}$, which is defined by the following recursion:\n\t\t\n\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item $\\#_\\spadesuit(x)=\\begin{cases} 1 & \\text{if }x=\\spadesuit\n\t\t\t\\\\0 &\\text{if }x=\\clubsuit\\end{cases}$\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\t\t\t\n\t\t\t\t\t\\item  $\\#_\\spadesuit( \\diamondsuit x\\diamondsuit)=\\#_\\spadesuit(x)$\n\n\t\t\t\t\t\\item $\\#_\\spadesuit(x\\heartsuit y)=\\#_\\spadesuit(x)+\\#_\\spadesuit(y)$\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\tThis function calculates the number of $\\spadesuit$'s in a given gargle. We have, for example, $\\#_\\spadesuit(\\diamondsuit\\clubsuit\\diamondsuit)=0$, $\\#_\\spadesuit(\\spadesuit)=1$, $\\#_\\spadesuit(\\spadesuit\\heartsuit\\diamondsuit\\spadesuit\\diamondsuit)=2$, and so on. Let's check this, for example, in the case of $\\spadesuit\\heartsuit\\diamondsuit\\spadesuit\\diamondsuit$:\n\t\t\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item We know by clause (ii.b), $\\#_\\spadesuit(\\spadesuit\\heartsuit\\diamondsuit\\spadesuit\\diamondsuit)=\\#_\\spadesuit(\\spadesuit)+\\#_\\spadesuit(\\diamondsuit\\spadesuit\\diamondsuit)$.\n\t\t\t\n\t\t\t\\item By clause (ii.a), we know that $\\#_\\spadesuit(\\diamondsuit\\spadesuit\\diamondsuit)=\\#_\\spadesuit(\\spadesuit)$.\n\t\t\t\n\t\t\t\\item So, $\\#_\\spadesuit(\\spadesuit\\heartsuit\\diamondsuit\\spadesuit\\diamondsuit)=\\#_\\spadesuit(\\spadesuit)+\\#_\\spadesuit(\\diamondsuit\\spadesuit\\diamondsuit)=\\#_\\spadesuit(\\spadesuit)+\\#_\\spadesuit(\\spadesuit)$.\n\t\t\t\n\t\t\t\\item But $\\#_\\spadesuit(\\spadesuit)=1$, so $\\#_\\spadesuit(\\spadesuit\\heartsuit\\diamondsuit\\spadesuit\\diamondsuit)=\\#_\\spadesuit(\\spadesuit)+\\#_\\spadesuit(\\diamondsuit\\spadesuit\\diamondsuit)=1+1=2$.\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\\item But wait, there's a problem. By what we said so-far about general recursion, it's only guaranteed that every element gets \\emph{a} value. But remember from the definition of a function, that every element needs to get a \\emph{unique} value. In the case of the natural numbers, this is guaranteed since for each natural number, there is exactly one way of ``constructing it'' from zero via the successor function: \\[n=0\\underbrace{+\\mathellipsis+1}_{n\\text{ times}}\\] Thus, there is only one way to calculate the value of recursive function following the construction of the number.\n\t\t\n\t\t\n\t\tBut note that this is \\emph{not} the case for the gargles. Take the gargle $\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit$, for example. This gargle can constructed in two ways: \n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item Since $\\spadesuit,\\clubsuit\\in Gargle$, we know that $\\clubsuit\\heartsuit\\spadesuit\\in Gargle$ by (ii.b). And since $\\spadesuit\\in Gargle$ and $\\clubsuit\\heartsuit\\spadesuit\\in Gargle$, we know that $\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit\\in Gargle$\n\t\t\n\t\t\t\\item Since $\\clubsuit,\\spadesuit\\in Gargle$, we know that $\\spadesuit\\heartsuit\\clubsuit\\in Gargle$. And since $\\spadesuit\\in Gargle$ and $\\spadesuit\\heartsuit\\clubsuit\\in Gargle$, we know that $\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit\\in Gargle$\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\n\t\tWhat does this mean? Well, every number can be ``read'' in exactly one way: the number $n$ is the $n$-th successor of zero. For gargles, that's not the case: $\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit$ can be constructed via $\\clubsuit\\heartsuit\\spadesuit$ and it can be constructed via $\\spadesuit\\heartsuit\\clubsuit$. Why does this matter? Well, if we want to use function recursion to define a function on the gargles, if we're not careful, it might give different results depending on how we ``read'' a gargle. Take, for example, the ``function'' $f:Gargle\\to\\{0,1\\}$ which is defined by recursion over the gargles as follows:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item $f(\\spadesuit)=1$ and $f(\\clubsuit)=0$\n\t\t\t\n\t\t\t\\item \\begin{enumerate}[(a)]\n\t\t\t\n\t\t\t\t\\item $f(\\diamondsuit x\\diamondsuit)=f(x)$\n\t\t\t\t\n\t\t\t\t\\item $f(x\\heartsuit y)=\\begin{cases}\n\t\t\t1 & \\text{if }f(x)=1\\text{ and }f(y)=0\\\\\n\t\t\t0 &\\text{ otherwise}\n\t\t\t\\end{cases}$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\nYou might think that this recursion defines a proper function on the gargles, but it does not! Why? Because it gives different values for  $\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit$, depending on how we ``read'' the expression:\n\n\t\t\\begin{itemize}\n\t\t\n\t\t\t\\item \\emph{Calculation 1}. We know that $f(\\spadesuit)=1$ and $f(\\clubsuit)=0$. So we know that $f(\\spadesuit\\heartsuit\\clubsuit)=1$ by (ii.b). And since $f(\\spadesuit)=1$, this means that $f(\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit)=0$, again by (ii.b).\n\t\t\t\t\t\t\n\t\t\t\\item  \\emph{Calculation 2}. Since $f(\\spadesuit)=1$ and $f(\\clubsuit)=0$, we know that $f(\\clubsuit\\heartsuit\\spadesuit)=0$ by (ii.b). Since $f(\\spadesuit)=1$, this gives $f(\\spadesuit\\heartsuit\\clubsuit\\heartsuit\\spadesuit)=1$ by (ii.b).\n\n\t\t\n\t\t\\end{itemize}\n\t\tLooking at it the other way around, if we try to calculate ``backwards,'' already in the first step, we have to make a decision how to ``parse'' the gargle---and different ways of parsing it give different values for the function. So, strictly speaking, not every function recursion over the gargles is guaranteed to yield an actual function. Sure, some of them do: for example, it can be shown that the definition of $\\#_\\spadesuit$ works, it assigns a unique value to every gargle. But some of them don't: for example, our ``function'' $f$ defined above.\n\t\t\n\t\tAll of this points to an important fact: when we're dealing with an inductively defined set, we want it's members to have a unique construction for recursion to work properly. In the case of the gargles, we don't have this ``unique readability'' and therefore we have to be careful when we're trying our hand at function recursion over them. It will be an important fact about formal languages that their formulas are uniquely readable---we'll make sure that they are \\emph{by design}. \n\t\t\n\t\t\\item Finally, we mentioned that for every inductively defined set, we have its own form of proof by induction. The idea that we described for the natural numbers generalizes to a general procedure as follows. In order to show that every element of an inductively defined satisfies a condition, we show:\n\t\t\\begin{enumerate}[1.]\n\t\t\t\n\t\t\t\\item All the initial elements satisfy the condition. (`base case')\n\t\t\t\n\t\t\t\\item A newly constructed element satisfies the condition, whenever the elements that it's constructed from do. (`induction steps')\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\tThe reasoning behind this is essentially the same as in the case of mathematical induction. Since the elements of an inductively defined set are precisely the ones that can be constructed from the initial elements using the constructions if 1. and 2. are established, then for each element, we can infer that it satisfies the condition \\emph{step-by-step} tracing the construction steps. \n\t\t\n\t\tNote that, in contrast to mathematical induction over $\\mathbb{N}$, there can be more than one base case and several induction steps (with their own induction hypotheses) to show.\n\t\t\t\t\n\t\t\\item So, how do we prove things about gargles using induction? Well, suppose we want to show that all gargles satisfy the condition $\\Phi$. What we need establish are the following things:\n\t\t\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\t\\item We need to show that $\\clubsuit,\\spadesuit$ all satisfy the condition, i.e. $\\Phi(\\clubsuit)$ and $\\Phi(\\spadesuit)$. This is the base case.\n\t\t\t\t\n\t\t\t\t\\item And we need to show that:\n\t\t\t\t\n\t\t\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item For all $x$, if $x$ satisfies the condition, then $\\diamondsuit x\\diamondsuit$ satisfies the condition, i.e. for all $x$, if $\\Phi(x)$, then $\\Phi(\\diamondsuit x\\diamondsuit)$. \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\\item For all $x,y$, if $x$ and $y$ satisfy the condition, then $ x\\heartsuit y$ satisfies the condition, i.e. for all $x,y$, if $\\Phi(x)$ and $\\Phi(y),$ then $\\Phi( x\\heartsuit y)$.\n\n\t\t\t\t\t\t\\end{enumerate}\n\t\t\n\t\t\\end{enumerate}\n\t\t\n\tAs an example, we're going to prove that The number of $\\heartsuit$'s in a gargle is equal to the number of $\\spadesuit$'s and $\\clubsuit$'s added together minus 1. To make this claim more precise, let's define two more functions on the gargles. First, define the function $\\#_\\heartsuit:Gargle\\to\\mathbb{N}$ by recursion as follows:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $\\#_\\heartsuit(\\spadesuit)=\\#_\\heartsuit(\\clubsuit)=0$\n\t\t\n\t\t\\item \\begin{enumerate}[(a)]\n\n\t\t\t\\item $\\#_\\heartsuit(\\diamondsuit x\\diamondsuit)=\\#_\\heartsuit(x)$\n\t\t\t\n\t\t\t\\item $\\#_\\heartsuit(x\\heartsuit y)=\\#_\\heartsuit(x)+\\#_\\heartsuit(y)+1$\n\n\t\t\\end{enumerate}\n\t\n\t\\end{enumerate}\n\tThis function counts the number of $\\heartsuit$'s in a given gargle. Second, define the function $\\#_\\clubsuit:Gargle\\to\\mathbb{N}$ by recursion as follows:\n\t\\begin{enumerate}[(i)]\n\t\n\t\t\\item $\\#_\\clubsuit(\\spadesuit)=0$ and $\\#_\\clubsuit(\\clubsuit)=1$\n\t\t\n\t\t\\item \\begin{enumerate}[(a)]\n\n\t\t\t\\item $\\#_\\clubsuit(\\diamondsuit x\\diamondsuit)=\\#_\\clubsuit(x)$\n\t\t\t\n\t\t\t\\item $\\#_\\clubsuit(x\\heartsuit y)=\\#_\\clubsuit(x)+\\#_\\clubsuit(y)$\n\n\t\t\\end{enumerate}\n\t\n\t\\end{enumerate}\n\tThis function counts the number of $\\clubsuit$'s in a gargle. (Both of these recursions actually work, don't worry about the details too much).\n\t\n\t\t\\begin{theorem}\n\t\tFor all $x\\in Gargle$, $\\#_\\heartsuit(x)=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1$.\n\t\t\\end{theorem}\n\t\t\t\\begin{proof}\n\t\t\tWe use induction over the gargles to prove the claim.\n\t\t\t\n\t\t\tFor the base case, we need to show two things: \\[\\#_\\heartsuit(\\spadesuit)=\\#_\\spadesuit(\\spadesuit)+\\#_\\clubsuit(\\spadesuit)-1\\] and \\[\\#_\\heartsuit(\\clubsuit)=\\#_\\spadesuit(\\clubsuit)+\\#_\\clubsuit(\\clubsuit)-1.\\] We only show the latter, since the former is completely analogous. Simply note that $\\#_\\heartsuit(\\clubsuit)=0,\\#_\\spadesuit(\\clubsuit)=0,$ and $\\#_\\clubsuit(\\clubsuit)=1$. So we get \\[\\underbrace{\\#_\\spadesuit(\\clubsuit)}_{=0}+\\underbrace{\\#_\\clubsuit(\\clubsuit)}_{=1}-1=\\underbrace{\\#_\\heartsuit(\\clubsuit)}_{=0}\\]\n\t\t\t\n\t\t\tFor the induction step, we need to show two things:\n\t\t\t\n\t\t\t\\begin{enumerate}[1.]\n\t\t\t\n\t\t\t\t\\item For all $x\\in Gargle$, if \\[\\#_\\heartsuit(x)=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1,\\] then \\[\\#_\\heartsuit(\\diamondsuit x\\diamondsuit )=\\#_\\spadesuit(\\diamondsuit x\\diamondsuit )+\\#_\\clubsuit(\\diamondsuit x\\diamondsuit )-1.\\]\n\t\t\t\t\n\t\t\t\t\\item For all $x,y\\in Gargle$, if \\[\\#_\\heartsuit(x)=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1,\\] and \n\t\t\t\t \\[\\#_\\heartsuit(y)=\\#_\\spadesuit(y)+\\#_\\clubsuit(y)-1,\\] then \\[\\#_\\heartsuit(x\\heartsuit y )=\\#_\\spadesuit(x\\heartsuit y )+\\#_\\clubsuit(x\\heartsuit y )-1\\]\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\tWe prove these in turn. First 1. Let $x$ be an arbitrary gargle and suppose the induction hypothesis that $\\#_\\heartsuit(x)=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1$. Now consider $\\#_\\heartsuit(\\diamondsuit x\\diamondsuit)$. By definition, $\\#_\\heartsuit(\\diamondsuit x\\diamondsuit)=\\#_\\heartsuit(x)$ and so we get the claim immediately.\n\t\t\t\n\t\t\tNow for 2. Let $x$ and $y$ be arbitrary gargles and suppose the induction hypotheses that $\\#_\\heartsuit(x)=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1$ and $\\#_\\heartsuit(y)=\\#_\\spadesuit(y)+\\#_\\clubsuit(y)-1$. Now consider $\\#_\\heartsuit(x\\heartsuit y)$. By definition, \\[\\#_\\heartsuit(x\\heartsuit y)=\\#_\\heartsuit(x)+\\#_\\heartsuit(y)+1.\\] By substituting the equations from our induction hypotheses, we get:\n\t\t\t\\begin{align*}\\#_\\heartsuit(x\\heartsuit y)&=(\\#_\\spadesuit(x)+\\#_\\clubsuit(x)-1)+(\\#_\\spadesuit(y)+\\#_\\clubsuit(y)-1)+1\\\\\n\t\t\t&=\\#_\\spadesuit(x)+\\#_\\clubsuit(x)+\\#_\\spadesuit(y)+\\#_\\clubsuit(y)-1\\\\\n\t\t\t&=\\underbrace{\\#_\\spadesuit(x)+\\#_\\spadesuit(y)}_{=\\#_\\spadesuit(x\\heartsuit y)}+\\underbrace{\\#_\\clubsuit(x)+\\#_\\clubsuit(y)}_{=\\#_\\clubsuit(x\\heartsuit y)}-1\\\\\n\t\t\t&=\\#_\\spadesuit(x\\heartsuit y )+\\#_\\clubsuit(x\\heartsuit y )-1\n\t\t\t\\end{align*}\n\t\t\tThis is what we needed to show.\n\t\t\t\n\t\t\tSo, we conclude our theorem by induction over the gargles.\n\t\t\t\n\t\t\t\\end{proof}\n\n\t\\item We conclude the section with a guideline for writing a proof by induction:\n\t\n\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. \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.\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\\end{enumerate}\n\n\\section{Core Ideas}\n\n\t\\begin{itemize}\n\t\n\t\t\\item A set is a collection of objects, its elements.\n\t\t\n\t\t\\item One set is a subset of another just in case all the elements of the one set are elements of the other. A set is a proper subset of another just in case the one set is a subset of the other but not vice versa. \n\t\t\t\t\n\t\t\\item Two sets are identical iff they have precisely the same elements. \n\t\t\n\t\t\\item The union of two sets contains any element of either set, their intersection contains only the objects that are in both sets. The difference of one set and another contains all the elements of the one but not the other.\n\t\t\n\t\t\\item An ordered tuple is a set-like collection of objects with a specific order. In tuples, order and multiplicity count.\n\t\t\n\t\t\\item The Cartesian product of two sets is the set of all ordered pairs formed by taking an element of the first set as the first component and an element of the second set as the second component. \n\t\t\t\n\t\t\\item A property is a set of objects---the set of objects that have the property. More generally, an $n$-ary relation is a set of $n$-tuples---the set of objects having standing in the relation \\emph{in that order}.\n\t\t\n\t\t\\item A function from one set to another is an assignment of elements in the one set to elements in the other such that each element in the one set is assigned a \\emph{unique} element in the other.\n\t\t\n\t\t\\item In order to inductively define a set, we give a set of initial elements and a set of constructions for new elements. We define the set inductively as the smallest set that contains the initial elements and is closed under the constructions.\n\t\t\n\t\t\\item In order to recursively define a function over an inductively defined set, we give the value of the function for the initial elements and say how to calculate the value of a newly constructed element based on the values of the elements it's constructed from.\n\t\t\n\t\t\\item To prove a claim by induction over an inductively defined set, we show that all initial elements satisfy the claim and that every newly constructed element satisfies the claim whenever the elements that its constructed from do.\n\t\t\t\n\t\\end{itemize}\n\n\\section{Self Study Questions}\n\n\t\\begin{enumerate}[\\thesection.1]\n\t\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $X\\subseteq Y$?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item For every $x\\in X$, we also have $x\\in Y$.\n\t\t\t\n\t\t\t\\item For every $x\\in Y$, we also have $x\\in X$.\n\t\t\t\n\t\t\t\\item There exists no $x\\in Y$ such that $x\\notin X$.\n\t\t\t\n\t\t\t\\item There exists no $x\\in X$ such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item Some $x\\in X$ is such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item Some $x\\in Y$ is such that $x\\notin X$.\n\t\t\t\n\t\t\t\\item Every $x\\notin X$ is also such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item Every $x\\notin Y$ is also such that $x\\notin X$.\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $X\\nsubseteq Y$?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item For every $x\\in X$, we also have $x\\notin Y$.\n\t\t\t\n\t\t\t\\item For every $x\\notin Y$, we also have $x\\notin X$.\n\t\t\t\n\t\t\t\\item There exists no $x\\in X$ such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item There exists no $x\\in Y$ such that $x\\notin X$.\n\t\t\t\n\t\t\t\\item Some $x\\in X$ is such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item Some $x\\in Y$ is such that $x\\notin X$.\n\t\t\t\n\t\t\t\\item Every $x\\notin X$ is also such that $x\\notin Y$.\n\t\t\t\n\t\t\t\\item Every $x\\notin Y$ is also such that $x\\notin X$.\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $X= Y$?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\n\t\t\t\\item $X\\subseteq Y$ and $Y\\subseteq X$.\n\t\t\t\t\t\n\t\t\t\\item For some object $x$, we have that $x\\in X$ iff $x\\in Y$.\n\n\t\t\t\\item $X\\subseteq Y$ and $Y\\nsubseteq X$.\n\t\t\t\t\t\t\n\t\t\t\\item There is no element $x\\in X$ such that $x\\notin Y$ and there is no element $y\\in Y$ such that $y\\notin X$.\n\t\t\t\n\t\t\t\\item When we pick any element $x\\in X$, we can find a corresponding element $y\\in Y$ and vice versa.\n\t\t\t\n\t\t\t\\item If we find an element $x\\in X$ such that $x\\in Y$, then we can find an $y\\in Y$ such that $y\\in X$.\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\n\\item Let $X$ and $Y$ be sets. Which of the following entails that $X\\neq Y$?\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item There is an object $x\\in X$ such that $x\\notin Y$\n\t\t\t\t\n\t\t\t\\item For all objects $x$, we have that $x\\notin X$ iff $x\\notin Y$\n\t\t\n\t\t\t\\item $X\\nsubseteq Y$ or $Y\\nsubseteq X$.\n\t\t\t\n\t\t\t\\item There is an object $y\\in Y$ such that $y\\notin X$.\n\t\t\t\n\t\t\t\\item There exists an object $x\\in X$ such that $x\\in Y$\n\t\t\t\n\t\t\t\\item There exists an object $x\\in X$ such that $x\\notin Y$\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $x\\in X\\cup Y$ for an object $x$?\n\t\t\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $x\\in X$\n\t\t\t\n\t\t\t\\item $x\\in Y$\t\t\t\n\t\t\t\n\t\t\t\\item $x\\notin X$\n\t\t\t\n\t\t\t\\item $x\\notin Y$\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\\begin{enumerate}[(a)]\n\t\t\\setcounter{enumii}{4}\n\t\t\t\n\t\t\t\\item $x\\in X$ and $x\\in Y$\n\t\t\n\t\t\t\\item $x\\in X$ and $x\\notin Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\in Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\notin Y$\t\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\n\n\t\t\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $x\\notin X\\cup Y$ for an object $x$?\n\t\t\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $x\\in X$\n\t\t\t\n\t\t\t\\item $x\\in Y$\t\t\t\n\t\t\t\n\t\t\t\\item $x\\notin X$\n\t\t\t\n\t\t\t\\item $x\\notin Y$\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\\begin{enumerate}[(a)]\n\t\t\\setcounter{enumii}{4}\n\t\t\t\n\t\t\t\\item $x\\in X$ and $x\\in Y$\n\t\t\n\t\t\t\\item $x\\in X$ and $x\\notin Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\in Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\notin Y$\t\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $x\\in X\\cap Y$ for an object $x$?\n\t\t\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $x\\in X$\n\t\t\t\n\t\t\t\\item $x\\in Y$\t\t\t\n\t\t\t\n\t\t\t\\item $x\\notin X$\n\t\t\t\n\t\t\t\\item $x\\notin Y$\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\\begin{enumerate}[(a)]\n\t\t\\setcounter{enumii}{4}\n\t\t\t\n\t\t\t\\item $x\\in X$ and $x\\in Y$\n\t\t\n\t\t\t\\item $x\\in X$ and $x\\notin Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\in Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\notin Y$\t\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\n\t\t\\item Let $X$ and $Y$ be sets. Which of the following entails that $x\\notin X\\cap Y$ for an object $x$?\n\t\t\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\n\t\t\t\\item $x\\in X$\n\t\t\t\n\t\t\t\\item $x\\in Y$\t\t\t\n\t\t\t\n\t\t\t\\item $x\\notin X$\n\t\t\t\n\t\t\t\\item $x\\notin Y$\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\\begin{minipage}{.5\\linewidth}\n\t\t\\begin{enumerate}[(a)]\n\t\t\\setcounter{enumii}{4}\n\t\t\t\n\t\t\t\\item $x\\in X$ and $x\\in Y$\n\t\t\n\t\t\t\\item $x\\in X$ and $x\\notin Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\in Y$\n\t\t\t\n\t\t\t\\item $x\\notin X$ and $x\\notin Y$\t\t\t\n\t\t\t\t\t\n\t\t\\end{enumerate}\n\t\t\\end{minipage}\n\t\t\n      \\item Which of the following \\emph{excludes} that assignment $f$ is a function from $X$ to $Y$?\n\n        \\begin{enumerate}[(a)]\n\n          \\item For some element $y\\in Y$, there is no element $x\\in X$ to which $f$ assigns $y$.\n\n          \\item For some element $x\\in X$, there is no element $y\\in Y$ which $f$ assigns to $x$.\n\n          \\item There is some element $x\\in X$, such that there are two elements $y,y'\\in Y$ such that $f$ assigns both $y$ and $y'$ to $x$.\n\n          \\item There is some element $y\\in Y$, such that there are two elements $x,x'\\in X$ such that $f$ assigns $y$ to both $x$ and $x'$.\n\n        \\end{enumerate}\n\n\t\\item Consider the set $\\{n^2:n\\in\\mathbb{N}\\text{ and }0\\leq n\\leq 10\\}$ of all the squares of natural numbers between zero and ten . Which of the following entails that a natural number $m\\notin\\{n^2:n\\in\\mathbb{N}\\text{ and }0\\leq n\\leq 10\\}$?\n\t\n\t\\begin{enumerate}[(a)]\n\t\n\t\t\\item There exists an $n\\in\\mathbb{N}$ with $0\\leq n\\leq 10$ such that $m\\neq n^2$.\n\t\t\n\t\t\\item For all $n\\in\\mathbb{N}$ with $0\\leq n\\leq 10$ it holds that $m\\neq n^2$.\n\t\t\n\t\t\\item Either $0\\nleq m^2$ or $m^2\\nleq 10$.\n\t\t\n\t\t\\item Either $0\\nleq m$ or $m\\nleq 10$. \n\t\t\n\n\t\n\t\\end{enumerate}\n\n\t\\end{enumerate}\n\n\n\\section{Exercises}\n\t\n\t\\begin{enumerate}[\\thesection.1]\n\t\n\t\t\\item $[h]$ Let $X=\\{1,2,3\\}$ and $Y=\\{1,3,5\\}$. Calculate:\n\t\t\n\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\t\t\n\t\t\t\t\\item $X\\cap Y$\n\t\t\t\t\n\t\t\t\t\\item $X\\cup Y$\n\t\t\t\t\n\t\t\t\t\\item $X\\setminus Y$ and $Y\\setminus X$\n\t\t\t\t\n\t\t\t\t\\item $\\wp(X)$ and $\\wp(Y)$\n\t\t\t\t\n\t\t\t\t\\item $X\\times Y$ and $Y\\times X$\n\t\t\t\t\t\t\t\n\t\t\t\\end{enumerate}\n\t\n\t\t\\item Let $X$ and $Y$ be sets. Prove the following facts!\n\t\t\n\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\t\t\n\t\t\t\t\\item $[h]$ $X\\subseteq Y$ iff $X\\cup Y=Y$.\n\t\t\t\t\n\t\t\t\t\\item $X\\subseteq Y$ iff $X\\cap Y=X$.\n\t\t\t\t\n\t\t\t\t\\item $X=Y$ iff $\\wp(X)=\\wp(Y)$\n\t\t\t\t\n\t\t\t\t\\item $X=Y$ iff $X\\setminus Y=\\emptyset$ and $Y\\setminus X=\\emptyset$\n\t\t\t\n\t\t\t\\end{enumerate}\n\t\t\t\t\t\n\t\t\\item $[h]$ Consider the function $f:\\{1,2,3\\}^2\\to \\{1,2,3\\}$ which assigns to a pair of numbers, the smaller of the two. Write the function using all our different function notations.\n\t\t\n\t\t\\item Let $f:X\\to Y$ and $g:Y\\to Z$ be two functions. Prove that $g\\circ f$ is a function from $X$ to $Z$, where $(g\\circ f)(x)=g(f(x))$ for all $x\\in X$.\\footnote{Remember that a function from one set to another must do the following two things: every element in the one set gets assigned an element in the other and no element in the one set gets assigned more than one element in the other. By proving those two things you've proven that we've got a function.}\n\t\t\n\t\t\\item Consider the function $f:\\mathbb{N}^2\\to \\mathbb{N}$, which is defined by recursion over the natural numbers as follows:\n\t\t\\begin{enumerate}[(i)]\n\t\t\n\t\t\t\\item for all $n\\in\\mathbb{N}$, $f(n,0)=n$\n\t\t\t\n\t\t\t\\item for all $n,m\\in\\mathbb{N}$, $f(n,m+1)=f(n,m)+1$\n\t\t\n\t\t\\end{enumerate}\n\t\tProve, using mathematical induction, that $f(n,m)=n+ m$ for all $n,m\\in\\mathbb{N}$. \n\t\t\t\t\t\t\t\n\t\t\\item Use the formal definition of a function (3.6.10) to prove that if two functions assign the same output to the same input, then they are identical.\n\n\t\t\\item $[h]$ Remember the gargles (3.7.11).  Give recursive definitions of the following functions:\n\t\t\t\t\n\t\t\t\t\t\\begin{enumerate}[(a)]\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\\item a function $l:Gargle\\to\\mathbb{N}$ that measures the \\emph{length} of a gargle (counted in number of symbols)\n\t\t\t\t \n\t\t\t\t\t\t\\item a function $\\mathbf{1}_\\heartsuit:Gargle\\to\\{0,1\\}$ which assigns one to a gargle iff the gargle contains the symbol $\\heartsuit$\n\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\t\n\t\t\t\\item $[h]$ Use induction over the gargles to prove that every gargle contains an even number of $\\diamondsuit$'s (note that $0$ is even).\n\t\t\t\n\t\t\t\\item $[h]$ Prove that $\\spadesuit\\diamondsuit\\heartsuit\\spadesuit\\notin Gargle$. (\\emph{Hint}: Use the previous result.)\n\t\t\t\t\t\n\t\t\t\\item Prove the induction principle over the gargles:\n\t\t\t\n\t\t\t\\begin{theorem}\n\t\t\tSuppose that $\\Phi$ is a condition on gargles. If we can show:\n\t\t\t\\begin{enumerate}\n\t\t\t\n\t\t\t\t\\item $\\Phi(\\clubsuit)$ and $\\Phi(\\spadesuit)$\n\t\t\t\t\n\t\t\t\t\\item \\begin{enumerate}\\item For all gargles $x\\in Gargle$, if $\\Phi(x)$, then $\\Phi(\\diamondsuit x\\diamondsuit)$.\n\t\t\t\n\t\t\t\t\t\\item  For all gargles $x,y\\in Gargle$, if $\\Phi(x)$ and $\\Phi(y)$, then $\\Phi(x\\heartsuit y)$\n\t\t\t\t\t\n\t\t\t\t\t\\end{enumerate}\n\t\t\t\\end{enumerate}\n\t\t\tThen for all gargles $x\\in Gargle,$ $\\Phi(x)$.\n\t\t\t\\end{theorem}\n\t\n\t\\end{enumerate}\n\n\\section{Further Readings}\n\nThere is a host of accessible literature on elementary set theory (it's, after all, the basis for modern math). \n\nIf you're already looking into Houston's book \\emph{How to Think Like a Mathematician} (see \\S2.8), I can recommend having a look at chapter 1 of that book, too.\n\nA more comprehensive introduction to set theory can be found in Timothy Buttons \\emph{Set Theory: An Open Introduction}, which is freely available under:\n\n\t\\url{http://builds.openlogicproject.org/courses/set-theory/}\nIn this book, especially part 2 is what you want to have a look at.\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[3.9.1]  (a), (d), (h) \n\n\t\\item[3.9.2] (e)\n\t\n\t\\item[3.9.3] (a), (d)\n\t\n\t\\item[3.9.4] (a), (c), (d), (f)\n\t\n\t\\item[3.9.5] (a), (b), (e), (f), (g)\n\t\n\t\\item[3.9.6] (h)\n\t\n\t\\item[3.9.7] (e)\n\t\n\t\\item[3.9.8] (c), (d), (f), (g), (h)\n\t\n\t\\item[3.9.9] (b), (c)\n\t\n\t\\item[3.9.10] (b)\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": "9a92d7ccf2780829beb86cd04d0524d3d90e757b", "size": 79850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lib/notes/tex/mainmatter/fund-sets.tex", "max_stars_repo_name": "crcaret/KI1V13001-Inleiding-Logica", "max_stars_repo_head_hexsha": "6c7966886cde1c5a3622dadab3c9c903a7ac4ff7", "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": "lib/notes/tex/mainmatter/fund-sets.tex", "max_issues_repo_name": "crcaret/KI1V13001-Inleiding-Logica", "max_issues_repo_head_hexsha": "6c7966886cde1c5a3622dadab3c9c903a7ac4ff7", "max_issues_repo_licenses": ["CC-BY-4.0"], "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/notes/tex/mainmatter/fund-sets.tex", "max_forks_repo_name": "crcaret/KI1V13001-Inleiding-Logica", "max_forks_repo_head_hexsha": "6c7966886cde1c5a3622dadab3c9c903a7ac4ff7", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.3227597145, "max_line_length": 1341, "alphanum_fraction": 0.6732498435, "num_tokens": 26163, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314828740729, "lm_q2_score": 0.865224091265267, "lm_q1q2_score": 0.7662696949656306}}
{"text": "\\documentclass{article}\n\\title{Equipartition of Energy}\n\\date{\\today}\n\\author{Aayush Arya\\footnote{tomriddle257@gmail.com}}\n\n\\newcommand{\\f}[2]{\\frac{#1}{#2}}\n\n\\begin{document}\n\t\\maketitle\n\n\t\\section{Equipartition theorem}\n\tImagine an oscillating block tied to a spring. This system has total energy $$ E(x,v_x) = \\frac{1}{2}kx^2 + \\frac{1}{2}mv_x^2$$\n\tYou can see that this energy's dependence is quadratic in $x$ and $v_x$. Such quadratic terms in energy expressions are encountered frequently and one property arising due to this pattern is \\textit{equipartition}.\\\\\n\t\n\tImagine a thermodynamical system that is in contact with a heat bath (or reservoir). The system is allowed to exchange energy with its surroundings but its temperature is fixed to the temperature of the heat reservoir and matter is not allowed to come in or out of the system. Such a system can be described by a \\textit{canonical ensemble} or an \\textit{NVT ensemble}.\\\\\n\t\n\tA physical example of this system could be an individual molecule in a container full of other gas molecules \\textemdash the molecule in context has little energy compared to the sum of energies of rest of the molecules in the container (which can thus be treated as a heat reservoir). Energy in such an ensemble is Boltzmann distributed and is thus proportional to $e^{-\\beta\\Delta E}$, where $\\beta \\equiv  \\frac{1}{k_B T}$.\\\\\n\tLet us assume that its energy is dependent on some $n$ independent quadratic terms\n\t\n\t$$ E = \\sum_{i=1}^{n}\\alpha_ix_i^2$$\n\t\n\tSince the energy is Boltzmann distributed, probability of a variable $x_i$ taking a particular value between $x_i$ and $x_i + dx_i$\n\t\n\t$$ P(x_i) \\propto e^{-\\beta \\alpha_i x_i^2}$$\n\tNormalizing gives\n\t$$ P(x_i) = \\frac{e^{-\\beta\\alpha_i x_i}}{\\int_{-\\infty}^{\\infty} e^{-\\beta\\alpha_i x_i} dx_i}$$\n\tThe probability of $n$ indepdent variables $x_1, x_2, .. x_n$ taking up particular values would be\n\t\n\t$$ P(x_1, x_2, .. x_n) = \\left(\\frac{e^{-\\beta\\alpha_1 x_1}}{\\int_{-\\infty}^{\\infty} e^{-\\beta\\alpha_1 x_1} dx_1}\\right) \\left(\\frac{e^{-\\beta\\alpha_2 x_2}}{\\int_{-\\infty}^{\\infty} e^{-\\beta\\alpha_2 x_2} dx_2}\\right) ... \\left(\\frac{e^{-\\beta\\alpha_n x_n}}{\\int_{-\\infty}^{\\infty} e^{-\\beta\\alpha_n x_n} dx_n}\\right) $$\n\twhich can be simplified using summation and product notation as\n\t$$ P(x_1, x_2, .. x_n) =  \\frac{e^{-\\beta (\\sum_{i=1}^{n} \\alpha_i x_i)}}{\\int_{-\\infty}^{\\infty} ... {\\int_{-\\infty}^{\\infty} e^{-\\beta (\\sum_{i=1}^{n} \\alpha_i x_i)}} \\Pi_{i=1}^{n}dx_i}$$\n\t\n\tThe average value of the total energy of the system should then be\n\t $$ \\langle E \\rangle = \\int_{-\\infty}^{\\infty}...\\int_{-\\infty}^{\\infty} E.P(x_1, x_2,..,x_n) dx_1 dx_2... dx_n  $$\n\t substituting $P$ and $E = \\sum_{i=1}^{n}\\alpha_ix_i^2$ and simplifying using product notation\n\t\n\t\n\t$$ \\langle E \\rangle =  \n\t\t\\frac{\\int_{-\\infty}^{\\infty} ... {\\int_{-\\infty}^{\\infty}\n\t\t\t\t (\\sum_{j=1}^{n} \\alpha_j x_j^2) e^{-\\beta (\\sum_{i=1}^{n} \\alpha_i x_i)}\\Pi_{i=1}^{n}dx_i}}\n\t\t{\\int_{-\\infty}^{\\infty} ... {\\int_{-\\infty}^{\\infty} e^{-\\beta (\\sum_{i=1}^{n} \\alpha_i x_i)}} \\Pi_{i=1}^{n}dx_i} $$\n\t\n\tNow, between the numerator and denominator, most of the integrals cancel out and we're left with\n\t\n\t$$ \\langle E \\rangle = \\sum_{i=1}^{n} \\frac{\n\t\t\t\\int_{-\\infty}^{\\infty}\\alpha_i x_i^2 e^{-\\beta \\alpha_i x_i^2} dx_i}{\\int_{-\\infty}^{\\infty} e^{-\\beta \\alpha_i x_i^2} dx_i} \n\t\t$$\n\t\t\n\twhich, if you notice, is a sum of \\\\\n\t\n\t$$ \\langle E \\rangle = \\langle E_1 \\rangle + \\langle E_2 \\rangle...  + \\langle E_n \\rangle $$\n\twhich implies that the average total energy of the system is the sum of the average of individual quaratic terms.\n\tSince the energy of our system is dependent on $n$ different quadratic terms, we say it has $n$ (quadratic) modes or \\textit{degrees of freedom}. Evaluating the Gaussian integral gives an even more surprising result\n\t\n\t$$ \\langle E \\rangle = \\sum_{i=1}^{n} \\f{1}{2}k_B T $$\n\t\n\tPhysically, this means that average energy corresponding to each degree of freedom is exactly equal. It should be emphasized that it doesn't depend on the nature of $\\alpha_i$ or $x_i$  and is dependent only on the temperature!\n\\end{document}", "meta": {"hexsha": "5f05e48ee00da51437b40267df2621845c5331a7", "size": 4129, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thermal Physics/equipartition.tex", "max_stars_repo_name": "cartilage-ftw/notes", "max_stars_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Thermal Physics/equipartition.tex", "max_issues_repo_name": "cartilage-ftw/notes", "max_issues_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thermal Physics/equipartition.tex", "max_forks_repo_name": "cartilage-ftw/notes", "max_forks_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_forks_repo_licenses": ["CC0-1.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.1896551724, "max_line_length": 429, "alphanum_fraction": 0.6897553887, "num_tokens": 1381, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.7662696775715518}}
{"text": "\\section{Application: Solving recurrences}\n\\label{sec:recurrence}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Solve a linear recurrence relation using diagonalization.\n  \\end{enumerate}\n\\end{outcome}\n\nConsider the following sequence of integers, called the\n\\textbf{Fibonacci sequence}%\n\\index{Fibonacci sequence}%\n\\index{sequence!Fibonacci}%\n\\index{number!Fibonacci}:\n\\begin{equation*}\n  0,\\ 1,\\ 1,\\ 2,\\ 3,\\ 5,\\ 8,\\ 13,\\ 21,\\ \\ldots\n\\end{equation*}\nThe first two Fibonacci numbers are 0 and 1. Every subsequent\nFibonacci number is the sum of the previous two numbers. For example,\n$0+1=1$, $1+1=2$, $1+2=3$, $2+3=5$, and so on. Thus, if we write $F_n$ for the\n$n\\th$ Fibonacci number, then the Fibonacci sequence is given by the\nfollowing conditions:\n\\begin{equation*}\n  \\begin{array}{l@{~}c@{~}l}\n    F_0 &=& 0, \\\\\n    F_1 &=& 1, \\\\\n    F_{n+2} &=& F_n + F_{n+1}, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n  \\end{array}\n\\end{equation*}\nThe condition $F_{n+2} = F_n + F_{n+1}$ is known as a\n\\textbf{recurrence relation}, or simply as a \\textbf{recurrence}%\n\\index{recurrence}%\n\\index{sequence!defined by a recurrence}, because we compute each\nmember of the sequence from previous members (the word ``recurrence''\ncomes from Latin ``recurrere'', which means ``to go back''). The\nconditions $F_0=0$ and $F_1=1$ are known as the \\textbf{base cases}%\n\\index{recurrence!base case}%\n\\index{base case!of a recurrence} of the recurrence. Note that we\nstart counting from zero, i.e., we call $F_0=0$ the ``zeroth Fibonacci\nnumber'', $F_1=1$ the ``first Fibonacci number'', and so on. Counting\nfrom zero will help simplify our calculations later.\n\n\\begin{example}{Computing a Fibonacci number}{fibonacci-10}\n  Compute the $10\\th$ Fibonacci number $F_{10}$.\n\\end{example}\n\n\\begin{solution}\n  To compute the $10\\th$ Fibonacci number using the recurrence, we\n  have to compute all the previous Fibonacci numbers as well.\n  \\begin{eqnarray*}\n    F_0 &=& 0, \\\\\n    F_1 &=& 1, \\\\\n    F_2 &=& F_0 + F_1 ~=~ 0 + 1 ~=~ 1, \\\\\n    F_3 &=& F_1 + F_2 ~=~ 1 + 1 ~=~ 2, \\\\\n    F_4 &=& F_2 + F_3 ~=~ 1 + 2 ~=~ 3, \\\\\n    F_5 &=& F_3 + F_4 ~=~ 2 + 3 ~=~ 5, \\\\\n    F_6 &=& F_4 + F_5 ~=~ 3 + 5 ~=~ 8, \\\\\n    F_7 &=& F_5 + F_6 ~=~ 5 + 8 ~=~ 13, \\\\\n    F_8 &=& F_6 + F_7 ~=~ 8 + 13 ~=~ 21, \\\\\n    F_9 &=& F_7 + F_8 ~=~ 13 + 21 ~=~ 34, \\\\\n    F_{10} &=& F_8 + F_9 ~=~ 21 + 34 ~=~ 55.\n  \\end{eqnarray*}\n  Thus, the $10\\th$ Fibonacci number is $55$.\n\\end{solution}\n\nSuppose we want to compute the $100\\th$ Fibonacci number. As the\nprevious example shows, computing this by using the recurrence\nrelation would be lot of work. We will therefore explore how to use\nlinear algebra, and in particular diagonalization, to find a closed\nformula for the $n\\th$ Fibonacci number. By a \\textbf{closed formula}%\n\\index{closed formula}%\n\\index{formula!closed}, we mean a formula to calculate $F_n$ directly\nin one step, i.e., without using a recurrence. The process of finding\na closed formula is called \\textbf{solving the recurrence}%\n\\index{recurrence!solving}.\n\nThe first step in solving the recurrence is to replace the recurrence\nrelation $F_{n+2} = F_n + F_{n+1}$, which requires {\\em two}\nprevious terms of the sequence, by another recurrence relation\nrequiring only {\\em one} previous term. To that end, we define\n$\\vect{v}_n$ to be the vector consisting of the $n\\th$ and $n+1\\st$\nFibonacci numbers, for all $n\\geq 0$:\n\\begin{equation*}\n  \\vect{v}_n = \\begin{mymatrix}{c} F_n \\\\ F_{n+1} \\end{mymatrix}.\n\\end{equation*}\nUsing the recurrence relation for $F_{n+2}$, we have\n\\begin{equation*}\n  \\vect{v}_{n+1}\n  = \\begin{mymatrix}{c} F_{n+1} \\\\ F_{n+2} \\end{mymatrix}\n  = \\begin{mymatrix}{c} F_{n+1} \\\\ F_n + F_{n+1} \\end{mymatrix}\n  = \\begin{mymatrix}{rr}\n    0 & 1 \\\\\n    1 & 1 \\\\\n  \\end{mymatrix}\n  \\begin{mymatrix}{c} F_n \\\\ F_{n+1} \\end{mymatrix}\n  = \\begin{mymatrix}{rr}\n    0 & 1 \\\\\n    1 & 1 \\\\\n  \\end{mymatrix}\n  \\vect{v}_n.\n\\end{equation*}\nTherefore, to compute $\\vect{v}_{n+1}$, we only need to know\n$\\vect{v}_n$ (and not $\\vect{v}_{n-1}$). Let\n\\begin{equation*}\n  A = \\begin{mymatrix}{rr}\n    0 & 1 \\\\\n    1 & 1 \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nSince $\\vect{v}_n$ is obtained from $\\vect{v}_0$ by applying the\nmatrix $A$ $n$ times, we have $\\vect{v}_n = A^n\\,\\vect{v}_0$ for all\n$n\\geq 0$. We can therefore get a formula for $\\vect{v}_n$, and thus\nfor $F_n$, by diagonalizing the matrix $A$.\n\n\\begin{problem}{Diagonalizing $A$}{fibonacci-diagonalize}\n  Diagonalize the matrix\n  $A=\\begin{mymatrix}{rr} 0 & 1 \\\\ 1 & 1 \\end{mymatrix}$.\n\\end{problem}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    p(\\eigenvar) =\n    \\begin{absmatrix}{cc}\n      -\\eigenvar & 1 \\\\\n      1 & 1-\\eigenvar \\\\\n    \\end{absmatrix}\n    = (-\\eigenvar)(1-\\eigenvar) - 1\n    = \\eigenvar^2 - \\eigenvar - 1.\n  \\end{equation*}\n  The eigenvalues are the roots of the characteristic polynomial. We\n  find them by using the quadratic formula. The eigenvalues are\n  \\begin{equation*}\n    \\eigenvar_1 = \\frac{1+\\sqrt{5}}{2}\n    \\quad\\mbox{and}\\quad\n    \\eigenvar_2 = \\frac{1-\\sqrt{5}}{2}.\n  \\end{equation*}\n  To simplify later calculations, we note that\n  $\\eigenvar_1+\\eigenvar_2 = 1$, or equivalently,\n  \\begin{equation}\\label{eqn:fibonacci-1}\n    1-\\eigenvar_1 = \\eigenvar_2.\n  \\end{equation}\n  We also note that\n  $\\eigenvar_1\\eigenvar_2 = -1$, or equivalently,\n  \\begin{equation}\\label{eqn:fibonacci-2}\n    \\eigenvar_2 = -\\frac{1}{\\eigenvar_1}.\n  \\end{equation}\n  To find the eigenvector corresponding to the eigenvalue $\\eigenvar_1$,\n  we solve the equation\n  \\begin{equation*}\n    \\begin{mymatrix}{cc}\n      -\\eigenvar_1 & 1 \\\\\n      1 & 1-\\eigenvar_1 \\\\\n    \\end{mymatrix}\n    \\vect{v} = \\vect{0}.\n  \\end{equation*}\n  By {\\eqref{eqn:fibonacci-1}} and {\\eqref{eqn:fibonacci-2}}, this is\n  equivalent to\n  \\begin{equation*}\n    \\begin{mymatrix}{cc}\n      -\\eigenvar_1 & 1 \\\\\n      0 & -\\frac{1}{\\eigenvar_1} \\\\\n    \\end{mymatrix}\n    \\vect{v} = \\vect{0},\n  \\end{equation*}\n  and we find the basic solution\n  \\begin{equation*}\n    \\vect{u} = \\begin{mymatrix}{c} 1 \\\\ \\eigenvar_1 \\end{mymatrix}.\n  \\end{equation*}\n  By a similar method, we find that the basic eigenvector\n  corresponding to the eigenvalue $\\eigenvar_2$ is\n  \\begin{equation*}\n    \\vect{w} = \\begin{mymatrix}{c} 1 \\\\ \\eigenvar_2 \\end{mymatrix}.\n  \\end{equation*}\n  Therefore, by Theorem~\\ref{thm:eigenvectors-and-diagonalizable}, $A$ is\n  diagonalizable, and we have $P^{-1}AP=D$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{cc}\n      1 & 1 \\\\\n      \\eigenvar_1 & \\eigenvar_2 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{cc}\n      \\eigenvar_1 & 0 \\\\\n      0 & \\eigenvar_2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  For later reference, we note that the inverse of $P$ is given by\n  \\begin{equation*}\n    P^{-1} =\n    \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{cc}\n      -\\eigenvar_2 & 1 \\\\\n      \\eigenvar_1 & -1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nWe are now ready to find our formula for the $n\\th$ Fibonacci number.\n\n\\begin{problem}{Solving the recurrence}{fibonacci-formula}\n  Find a formula for the $n\\th$ Fibonacci number.\n\\end{problem}\n\n\\begin{solution}\n  Since\n  \\begin{equation*}\n    \\vect{v}_n = \\begin{mymatrix}{c} F_n \\\\ F_{n+1} \\end{mymatrix},\n  \\end{equation*}\n  we know that the $n\\th$ Fibonacci number is the first component of\n  $\\vect{v}_n$, i.e.,\n  \\begin{equation*}\n    F_n = \\begin{mymatrix}{cc}1 & 0\\end{mymatrix}\\vect{v}_n.\n  \\end{equation*}\n  Putting together all of the above calculations, we then have:\n  \\begin{eqnarray*}\n    F_n\n    &=& \\begin{mymatrix}{cc}1 & 0\\end{mymatrix}\\vect{v}_n \\\\\n    &=& \\begin{mymatrix}{cc}1 & 0\\end{mymatrix}A^n\\,\\vect{v}_0 \\\\\n    &=& \\begin{mymatrix}{cc}1 & 0\\end{mymatrix}PD^nP^{-1}\\,\\vect{v}_0 \\\\\n    &=& \\begin{mymatrix}{cc}1 & 0\\end{mymatrix}\n        \\begin{mymatrix}{cc} 1 & 1 \\\\ \\eigenvar_1 & \\eigenvar_2 \\end{mymatrix}\n        \\begin{mymatrix}{cc} \\eigenvar_1^n & 0 \\\\ 0 & \\eigenvar_2^n \\end{mymatrix}\n        \\frac{1}{\\sqrt{5}}\n        \\begin{mymatrix}{cc} -\\eigenvar_2 & 1 \\\\ \\eigenvar_1 & -1 \\end{mymatrix}\n        \\begin{mymatrix}{c} 0 \\\\ 1 \\end{mymatrix} \\\\\n    &=& \\frac{1}{\\sqrt{5}}\n        \\begin{mymatrix}{cc}1 & 1\\end{mymatrix}\n        \\begin{mymatrix}{cc} \\eigenvar_1^n & 0 \\\\ 0 & \\eigenvar_2^n \\end{mymatrix}\n        \\begin{mymatrix}{c} 1 \\\\ -1 \\end{mymatrix} \\\\\n    &=& \\frac{1}{\\sqrt{5}} (\\eigenvar_1^n - \\eigenvar_2^n).\n  \\end{eqnarray*}\n  So the $n\\th$ Fibonacci number is\n  \\begin{equation*}\n    F_n\n    ~=~ \\frac{1}{\\sqrt{5}} (\\eigenvar_1^n - \\eigenvar_2^n)\n    ~=~ \\frac{1}{\\sqrt{5}}\n    \\paren{\\paren{\\frac{1+\\sqrt{5}}{2}}^n - \\paren{\\frac{1-\\sqrt{5}}{2}}^n}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{Computing the $100\\th$ Fibonacci number}{fibonacci-100}\n  Calculate the $100\\th$ Fibonacci number without using the recurrence.\n\\end{example}\n\n\\begin{solution}\n  Note that this calculation requires about 25 digits of precision to\n  give the correct result. We\n  have\n  \\begin{eqnarray*}\n    F_{100}\n    &=& \\frac{1}{\\sqrt{5}} (\\eigenvar_1^{100} - \\eigenvar_2^{100}) \\\\\n    &=& \\frac{1}{\\sqrt{5}} (1.6180339887498948482045868^{100} - (-0.6180339887498948482045868)^{100}) \\\\\n    &=& 354224848179261915075.\n  \\end{eqnarray*}\n\\end{solution}\n\nWe can use the same method to solve other linear recurrences. Here is\nanother example:\n\n\\begin{example}{Solving a recurrence}{recurrence}\n  Consider the sequence of numbers defined by the recurrence\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      b_0 &=& 1, \\\\\n      b_1 &=& 2, \\\\\n      b_{n+2} &=& 6b_n + b_{n+1}, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n  Find the first 5 members of this sequence. Then solve the recurrence\n  and find $b_{20}$.\n\\end{example}\n\n\\begin{solution}\n  The first 5 members of the sequence are:\n  \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      b_0 &=& 1, \\\\\n      b_1 &=& 2, \\\\\n      b_2 &=& 6b_0 + b_1 ~=~ 6 + 2 ~=~ 8, \\\\\n      b_3 &=& 6b_1 + b_2 ~=~ 12 + 8 ~=~ 20, \\\\\n      b_4 &=& 6b_2 + b_3 ~=~ 48 + 20 ~=~ 68. \\\\\n    \\end{array}\n  \\end{equation*}\n  To solve the recurrence, let\n  \\begin{equation*}\n    \\vect{w}_n = \\begin{mymatrix}{c} b_n \\\\ b_{n+1} \\end{mymatrix},\n  \\end{equation*}\n  so that for all $n\\geq 0$,\n  \\begin{equation*}\n    \\vect{w}_{n+1}\n    = \\begin{mymatrix}{c} b_{n+1} \\\\ b_{n+2} \\end{mymatrix}\n    = \\begin{mymatrix}{c} b_{n+1} \\\\ 6b_n + b_{n+1} \\end{mymatrix}\n    = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      6 & 1 \\\\\n    \\end{mymatrix}\n    \\begin{mymatrix}{c} b_n \\\\ b_{n+1} \\end{mymatrix}\n    = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      6 & 1 \\\\\n    \\end{mymatrix}\n    \\vect{w}_n.\n  \\end{equation*}\n  We then diagonalize the matrix\n  \\begin{equation*}\n    B = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      6 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The characteristic polynomial is\n  \\begin{equation*}\n    p(\\eigenvar) = \\eigenvar^2 - \\eigenvar - 6,\n  \\end{equation*}\n  with roots $\\eigenvar=-2$ and $\\eigenvar=3$. The respective eigenvectors\n  are\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\vect{v} = \\begin{mymatrix}{c} 1 \\\\ -2 \\end{mymatrix}\n        &\\quad\\mbox{for the eigenvalue $\\eigenvar=-2$,}\\\\\\\\[-2ex]\n      \\vect{u} = \\begin{mymatrix}{c} 1 \\\\ 3 \\end{mymatrix}\n        &\\quad\\mbox{for the eigenvalue $\\eigenvar=3$.}\n    \\end{array}\n  \\end{equation*}\n  Therefore, $B = PDP^{-1}$, where\n  \\begin{equation*}\n    P = \\begin{mymatrix}{cc}\n      1 & 1 \\\\\n      -2 & 3 \\\\\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    D = \\begin{mymatrix}{cc}\n      -2 & 0 \\\\\n      0 & 3 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  The inverse of $P$ is\n  \\begin{equation*}\n    P^{-1} =\n    \\frac{1}{5}\n    \\begin{mymatrix}{cc}\n      3 & -1 \\\\\n      2 &  1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Finally, we use this information to solve the recurrence:\n  \\begin{eqnarray*}\n    b_n\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}\\vect{w}_n \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}B^n\\,\\vect{w}_0 \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}PD^nP^{-1}\\,\\vect{w}_0 \\\\\n    &=& \\begin{mymatrix}{cc} 1 & 0 \\end{mymatrix}\n        \\begin{mymatrix}{cc} 1 & 1 \\\\ -2 & 3 \\end{mymatrix}\n        \\begin{mymatrix}{cc} (-2)^n & 0 \\\\ 0 & 3^n \\end{mymatrix}\n        \\frac{1}{5}\n        \\begin{mymatrix}{cc} 3 & -1 \\\\ 2 &  1 \\end{mymatrix}\n        \\begin{mymatrix}{c} 1 \\\\ 2 \\end{mymatrix} \\\\\n    &=& \\frac{1}{5}\n        \\begin{mymatrix}{cc}1 & 1\\end{mymatrix}\n        \\begin{mymatrix}{cc} (-2)^n & 0 \\\\ 0 & 3^n \\end{mymatrix}\n        \\begin{mymatrix}{c} 1 \\\\ 4 \\end{mymatrix} \\\\\n    &=& \\frac{(-2)^n + 4\\cdot 3^n}{5}\n  \\end{eqnarray*}\n  Finally, we calculate\n  \\begin{equation*}\n    b_{20}\n    = \\frac{(-2)^{20} + 4\\cdot 3^{20}}{5}\n    = \\frac{1048576 + 4\\cdot 3486784401}{5}\n    = 2789637236.\n  \\end{equation*}\n\n\\end{solution}\n", "meta": {"hexsha": "71557410d17241836c648a73f935af8c8b6b247d", "size": 12742, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Application-Recurrences.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Application-Recurrences.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Application-Recurrences.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.1608579088, "max_line_length": 104, "alphanum_fraction": 0.6138753728, "num_tokens": 5013, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314858927012, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.7662696775715518}}
{"text": "%!TEX root = ../notes.tex\n\\section{March 14, 2022}\n\\subsection{Elliptic Curves}\nAn \\ul{elliptic curve} is an equation of the form\n\\[y^2 = x^3 + ax + b\\]\nIt looks like this:\n\\begin{center}\n    \\includegraphics[width=0.6\\textwidth]{images/elliptic_curve.png}\n\\end{center}\n\n\\emph{What's special about cubic equations?} We have a special property that every line $L$ meets $E$ in 3 points.\n\n\\emph{What happens when we have a tangential line?} We count multiplicity.\n\n\\emph{What happens when it only meets at 1 or 2 points?} We count complex roots.\n\n\\emph{What happens with vertical lines that only meet at 2 points?} We include $\\cO = \\text{``point at $\\infty$''}$.\n\n\\emph{Where does $\\cO$ come from?} It comes from the $\\RR\\mathbb{P}^2$ (the real projective plane) or $\\CC\\mathbb{P}^2$ (the complex projective plane).\n\nGiven two points $A$ and $B$, we can get a third point $C$ which is the third point on the line passing through $A$ and $B$. Taking this as a binary operation...does this give us a group?\n\nConsider:\n\\begin{align*}\n    A + B & = C           \\\\\n    A + C & = B           \\\\\n    A + A & = \\cO\\text{?}\n\\end{align*}\nMaybe we can declare\n\\[A + B + C = \\cO\\]\nIf we call the reflection of $C$ across the $x$-axis is $D$, we have\n\\begin{align*}\n    A + B + C   & = \\cO \\\\\n    C + D + \\cO & = \\cO \\\\\n    A + B       & = D\n\\end{align*}\nSo we have that the group law is $A + B$ is the reflection of the third point $C$ across the $x$-axis.\n\\begin{definition}[Elliptic Curve]\n    An \\ul{elliptic curve} is the set of solutions to\n    \\[y^2 = x^3 + ax + b\\]\n    plus a point $\\cO$ at infinity...where $a, b$ satisfy $4a^3 + 27b^2\\neq 0$.\n\\end{definition}\n\nRecall from high school that $ax^2 + bx + c$ gives discriminant $\\Delta = b^2 - 4ac$. Taking a cubic equation $x^3 + ax + b$, the discriminant is $\\Delta = -16(4a^3 + 27b^2)$. This is also saying $x^3 + ax + b$ has no repeated roots. For it to be tangent to the $x$-axis, it has to self-intersect. But every line passing through the intersection is a tangent line. Messy messy things happen:\n\\begin{center}\n    \\includegraphics[width=0.8\\textwidth]{images/fish.png}\n\\end{center}\n\nWe take the fact that an elliptic curve is a group on faith, with the group operation defined above.\n\n\\subsection{Addition on Elliptic Curves}\n\\begin{itemize}\n    \\item $P + \\cO = \\cO + P = P$. That is, $\\cO$ is the identity.\n    \\item If for points $P_1 = (x_1, y_1), P_2 = (x_2, y_2)$ and $x_1 = x_2$, $y_1 = -y_2$. Then $P_1 + P_2 = \\cO$.\n    \\item If $P_1 \\neq P_2$, $\\lambda = \\text{Slope of $L$} = \\frac{y_2-y_1}{x_2-x_1}$. So the equation of $L$ is $y-y_1 = \\lambda(x-x_1)$. (We find the third point and reflect it). Will pick up here on Wednesday.\n\\end{itemize}", "meta": {"hexsha": "2ab8ca5722f1b779b108776b54e34adf5c072a88", "size": 2707, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-03-14.tex", "max_stars_repo_name": "jchen/math1580-notes", "max_stars_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_stars_repo_licenses": ["BSL-1.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2022-02-14T15:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:03:38.000Z", "max_issues_repo_path": "lectures/2022-03-14.tex", "max_issues_repo_name": "jchen/math1580-notes", "max_issues_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_issues_repo_licenses": ["BSL-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lectures/2022-03-14.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": 48.3392857143, "max_line_length": 391, "alphanum_fraction": 0.6531215368, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314677809303, "lm_q2_score": 0.8652240791017535, "lm_q1q2_score": 0.7662696711342897}}
{"text": "\\sec{Linear ODEs}\n\\subsection{Introduction}\n\\begin{defn}[Linear differential equations]\n\tA first order differential equation of the type\n\t\\[\\dfrac{dy}{dx} + p(x)y = g(x)\\]\n\tis called a \\defin{linear differential equation} in standard form.\n\\end{defn}\nWe shall assume that $p(x)$ and $g(x)$ are continuous on an open interval $I \\subset \\mathbb{R}.$\\\\\n\\begin{mdframed}[style=boxstyle, frametitle={Solving such an ODE}]\n\tVerify that $\\exp\\left(\\displaystyle\\int p(x) dx\\right)$ is an integrating factor of the above ODE.\\\\\n\tThus, we can now turn back to technique of the previous section.\n\\end{mdframed}\n\\subsection{Bernoulli's DE}\n\\begin{defn}[Bernoulli's DE]\n\tA first order differential equation of the type\n\t\\[\\dfrac{dy}{dx} + p(x)y = q(x)y^n\\]\n\tis called a \\defin{Bernoulli's differential equation}.\n\\end{defn}\nNote that if $n = 0$ or $1,$ then it is a linear DE as well and we already know how to solve that. Thus, we assume that $n \\notin \\{0, 1\\}.$\n\\newpage\n\\begin{mdframed}[style=boxstyle, frametitle={Solving such an ODE}]\n\tSubstitute \\[u(x) = \\dfrac{1}{y^{n-1}}.\\]\n\tCalculate the derivative and rearrange the original ODE to obtain:\n\t\\[\\dfrac{1}{1 - n}\\dfrac{du}{dx} + p(x)u(x) = q(x).\\]\n\tNow, we are back to the case of a linear DE which we can solve.\n\\end{mdframed}\n\\exercise{%\nSolve the following DE:\n\\[6y^2\\dfrac{dx}{dy} - yx = 2x^4.\\]}", "meta": {"hexsha": "47b2ee03d2729be5cf1de4e79f242e3c25cf5033", "size": 1348, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/linear.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/linear.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/linear.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 46.4827586207, "max_line_length": 140, "alphanum_fraction": 0.7010385757, "num_tokens": 453, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094117351309, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7662523245218891}}
{"text": "\\section{Introduction to error propagation}\nBefore studying the model, we briefly recall some notions on propagation of measurement errors. Accordingly with \\cite{book:ivm}, the size is a property of an object that could be expressed by a number and a reference, i.e. it is measurable. Physical size measurement is generally followed by the error estimation associated with it, specially when they are indirect measure. In the general case, given the function $y = f(x)$, we can generalized its error as\n  \\begin{equation}\n    \\sigma_f = \\begin{vmatrix}\n      \\frac{df}{dx}\n    \\end{vmatrix}_{x = x_0}\n    \\sigma_x\n    \\label{eq:er_prop_1}\n  \\end{equation}\nIf $y = f(\\bar{x})$, function of $k$ variables, Equation \\ref{eq:er_prop_1} can be generalize as:\n  \\begin{equation}\n    \\sigma_f = \\sum_{j = 1}^k \\begin{vmatrix}\n      \\frac{\\partial f}{\\partial x_j}\n    \\end{vmatrix}_{x = x_0}\n    \\sigma_x\n    \\label{eq:er_prop_2}\n  \\end{equation}\nThe propagation of the maximum errors by using the differential, is based on the assumption that infinitesimal variations of the variables are given by the respective errors. If we want to estimate the maximum error for $y$, it is appropriate to sum up all the terms consistently, i.e. taking the partial derivative modules.\n", "meta": {"hexsha": "5c71b47f6ae85269fb4248cc735f56a0a964faed", "size": 1266, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/src/chapters/ch4-Model/1_errs_prop.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/1_errs_prop.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/1_errs_prop.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": 66.6315789474, "max_line_length": 459, "alphanum_fraction": 0.7361769352, "num_tokens": 336, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.8152324960856175, "lm_q1q2_score": 0.7662479021664275}}
{"text": "\n\\subsection{The probability function}\n\nFor all events \\(E\\) in \\(F\\), the probability function \\(P\\) is defined.\n\n\\subsection{Measure space}\n\nThis gives us the following measure space:\n\n\\((\\Omega, F, P)\\)\n\n\\subsection{First Kolmogorov axiom}\n\nFirst axiom\n\nThe probability of all events is a non-negative real number.\n\n\\(\\forall E \\in F [(P(E)\\ge 0)\\land (P(E)\\in \\mathbb{R})]\\)\n\n\\subsection{Second Kolmogorov axiom}\n\nThe probability of one of the elementary events occuring is \\(1\\).\n\nThe probability of the outcome set is \\(1\\).\n\n\\(P(\\Omega )=1\\)\n\n\\subsection{Third Kolmogorov axiom}\n\nThe probability of union for mutually exclusive events is:\n\n\\(P(\\cup^\\infty_{i=1}E_i)=\\sum_{i=1}^\\infty P(E_i)\\)\n\n", "meta": {"hexsha": "f4768ae0368903345222b92bf3a0413fa503e5fa", "size": 701, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/probabilityAxioms/02-01-kolmogorov.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/probabilityAxioms/02-01-kolmogorov.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/probabilityAxioms/02-01-kolmogorov.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.6176470588, "max_line_length": 73, "alphanum_fraction": 0.7032810271, "num_tokens": 204, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133481428691, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7662478985816842}}
{"text": "Among the many methods developed for machine learning, neural networks, and especially deep neural networks, are among the most popular. Neural networks were suggested already in 1943 \\cite{McCulloch1943} and have had many renaissances since. Currently we are experiencing such a renaissance, but in contrast to earlier periods of resurfaced interest, we now have the computer power to use neural nets efficiently.\n\nA neural net bases itself loosely upon the biological model of neurons communicating together in the brain. A neuron cell contains most of what a normal cell contains, but it also has a long tail called an axon and some antenna like extension called dendrites. The axon of one cell can extend quite far and attach to some of the dendrites of another neural cell. Thus, the biological neural net consists of neural cells receiving input through their dendrites from many other cells and sending output through one output \\citep[p. 257]{Geron}.\n\nThe computed neural networks works in a similar way. We construct \"neurons\" or \"nodes\" which are ordered in different layers where each neuron in one layer is connected to all neurons in the next layer. Initially, we start with an input layer which we feed information. Following this initial layer we have one or many hidden layers before we reach the output layer. A neural network with two or more hidden layers are called deep neural networks \\citep[p. 263]{Geron}. Each neuron contains an activation function which determines the strength of the output. In the early days, a step function was used as the activation function. However, one has found that the use of a activation function with a gradient, such as the logistic function used in logistic regression, gives a better neural net. This is due to the fact that we now can apply gradient descent when optimizing the neural net which is discussed below.\n\nTo activate a neuron, it needs an input. This input is provided by all the neurons in previous layers through \"wires\" connecting the neurons (think of the axon to a dendrite). Each of these \"wires\" is weighted and all connections between one layer and the next is affected by a bias term. Thus, the output of a neuron is given as \\citep[p. 260]{Geron}\n\\begin{equation}\n    a = \\sigma(z)\n    \\label{eqT:activation}\n\\end{equation}\nwith\n\\begin{align}\n    z = \\bm{w}^T \\bm{x} + b\n\\end{align}\nwhere $a$ is the output, $\\bm{w}$ are the weights, $\\bm{x}$ are the inputs and $b$ is the bias term. Note that if we had used a step function instead of the logit(sigmoid) function in the equation above, the neuron would either give an output of 1 or nothing, i.e. 0. When we instead use the sigmoid function, the output can be in the range of 0 to 1.\n\nOnce all neurons have been calculated in a layer, we can move on to the next and continue until we reach our output layer. Each layer can have as many neurons as the user wants. Optimizing the number of neurons in each layer is an art and requires both experience and a bit of luck. The output layer needs one neuron for each class we wish to identify.\n\nAfter initial calculation of the outer layer, you will most likely have an answer that is completely rubbish. It is clear that we have to optimize the neural net. As each neurons activation function is calculated using equation \\eqref{eqT:activation}, we see that we can optimize the weights between the neurons and the bias between the layers. This is done through a method called backwards propagation where one uses the cost function to identify the magnitude of the error (the cost) of a neural net and then one goes backwards through the neural net to update the weights and biases.\n\nThe backpropegation is then summed up as following(heavily influenced by the work of \\citet{Nielsen}),\n\\begin{itemize}\n    \\item Compute the output error vector for the final layer (L) given by\n    \\begin{equation*}\n        \\delta^L = \\nabla_a \\mathcal{C} \\odot \\sigma^{'}(\\bm{w}^T \\cdot \\bm{x} + b)\n    \\end{equation*}\n    where $\\mathcal{C}$ is the cost function and $\\nabla_a$ is a vector who has components that are the partial derivatives $\\frac{\\partial \\mathcal{C}}{\\partial a_j^L}$ where $a_j$ is the j'th output found by using equation \\eqref{eqT:activation} for $a$.\n    \\item Go back through all the previous layers l = L-1, L-2, ..., 2 and compute\n    \\begin{equation*}\n        \\delta^l ((\\bm{w}^{l + 1})^T \\delta^{l + 1}) \\odot \\sigma^{'}(\\bm{w}^T \\cdot \\bm{x} + b)\n    \\end{equation*}\n    this is where we back propagate the error.\n    \\item Finally, find the gradient of the cost function for the two parameters we want to change, $\\bm{w}$ and $b$ by:\n    \\begin{align*}\n        \\frac{\\partial \\mathcal{C}}{\\partial \\bm{w}_{jk}^l} &= a_k^{l-1}\\delta_{j}^{l} \\\\\n        \\frac{\\partial \\mathcal{C}}{\\partial b_{j}^l} &= \\delta_{j}^{l}\n    \\end{align*}\n    where $k$ indicates the column of $\\bm{w}^l$ as $j$ indicates the row.\n\\end{itemize}\nOnce all layers have been adjusted through back propagation, one can run through the whole network again and repeat the process.\n\nIn order to understand parts of the back propagation algorithm for $L$ layers and a general layer activation function $a^L(z)$, can take a quick look at how to proceed in deriving it. We start with some cost function $\\CO(w^L, y)$, where $w^L$ is the output layer weights and $y$ is the \\textit{true} values which we want to approach. In order to move towards optimal weights(and biases), we can perform a gradient descent by subtracting the gradient of the cost function w.r.t. the weights and biases. We begin by finding the gradient of the $\\CO$ for $W^L$. Using the chain rule we get,\n\\begin{align}\n    \\frac{\\partial \\mathcal{C}}{\\partial w^L} &= \\frac{\\partial z^L}{\\partial w^L} \\frac{\\partial a^L}{\\partial z^L} \\frac{\\partial \\CO}{\\partial a^L}\n    \\label{eq:mlp-gradient-chain}\n\\end{align}\nFrom this we simply have to find each of the partial derivatives. Without specifying the cost function and the activation layer, we can only state that the first partial derivative is given as,\n\\begin{align*}\n\\frac{\\partial z^L}{\\partial w^L} = a^{L-1}\n\\end{align*}\nFrom this, we quickly see that we need to properly defined the cost function in relation to the $\\partial^L$ as we encountered earlier.\n\n\\subsubsection{Mean square error(MSE) cost function}\nA common cost function may be the quadratic loss function(MSE) given by.\n\\begin{equation}\n    \\mathcal{C}_\\mathrm{MSE} = \\frac{1}{2N} \\sum\\limits_{j} (y_j - a_j^L)^2\n\\end{equation}\nwhere $N$ are the total numbers of outputs in $j$ and $y$ are the true answers. For a single training sample, this becomes,\n\\begin{align}\n    \\mathcal{C}_\\mathrm{MSE} = \\frac{1}{2} (a^L - y)^2\n    \\label{eq:mse-mlp-cost}\n\\end{align}\nWe can then insert this expression into the cost chain rule expression \\eqref{eq:mlp-gradient-chain}, and we get that the partial derivative\n\\begin{align*}\n    \\frac{\\partial \\mathcal{C}_\\mathrm{CE}}{\\partial w^L} &= a^{L-1}(a^L - y)\\sigma'(z^L) \\\\\n    &= a^{L-1} \\delta^L\n\\end{align*}\nIf we now take the derivative for layer $L-1$, we get\n\\begin{align*}\n    \\frac{\\partial \\mathcal{C}_\\mathrm{CE}}{\\partial w^{L-1}} &= \\frac{\\partial a^{L-1}}{\\partial w^{L-1}} \\delta^L \\\\\n    &= \\frac{\\partial z^{L-1}}{\\partial w^{L-1}} \\frac{\\partial a^{L-1}}{\\partial z^{L-1}} \\delta^L \\\\\n    &= a^{L-2}\\sigma'(z^{L-1})\\delta^L\n\\end{align*}\n\n\\subsubsection{Cross entropy(CE) cost function}\nThe CE cost function is given as\n\\begin{align}\n    \\mathcal{C}_\\mathrm{CE} = - \\sum_{i=1} y_i \\log a^L\n    \\label{eq:ce-mlp-cost}\n\\end{align}\nwith its derivative as \n\\begin{align}\n    \\frac{\\partial \\mathcal{C}_\\mathrm{CE}}{\\partial a^L} = - \\sum_{i=1} \\frac{y_i} {a^L}\n    \\label{eq:ce-mlp-cost-der}\n\\end{align}\nIf we use softmax as the layer output activation function,\n\\begin{align}\n    z_i = \\frac{\\exp{z_i}}{\\sum_k \\exp(z_k) }\n    \\label{eq:softmax}\n\\end{align}\nwith $i,k$ being output classes and its derivative,\n\\begin{align}\n    z_i = z_i(\\delta_{ij} - z_j),\n\\end{align}\nwe can write the initial gradient $\\delta^L$ as\n\\begin{align}\n    \\delta^L = y - a^L\n\\end{align}\nIf we set the number of output classes to be 2 such that we get binary classification, we get the cost functions for logistic regression,\n\\begin{align*}\n    \\mathcal{C}_{lg} = - \\left( y \\log p + (1 - y)\\log (1 - p)\\right)\n\\end{align*}\nfor one sample.\n\n\\subsubsection{Activation layers} \\label{sec:layer-acts}\nThe hidden layer activations can greatly affect the outcome of the neural network. We will focus on four different hidden layer activations, the first being \\textbf{sigmoidal activation}.\n\\begin{align}\n    \\sigma (z) = \\frac{1}{1 + \\exp (-z)}\n    \\label{eq:act-sig}\n\\end{align}\nwith its derivative\n\\begin{align}\n    \\sigma'(z) = \\sigma(z)(1 - \\sigma(z))\n    \\label{eq:act-sig-der}\n\\end{align}\nThe \\textbf{hyperbolic tangens} activation function is given as\n\\begin{align}\n    \\sigma_\\mathrm{tanh}(z) = \\tanh(z)\n    \\label{eq:act-tanh}\n\\end{align}\nwith its derivative\n\\begin{align}\n    \\sigma'_\\mathrm{tanh}(z) = 1 - \\tanh^2(z)\n    \\label{eq:act-tanh-der}\n\\end{align}\nThe \\textbf{relu} or rectifier activation is given as,\n\\begin{align}\n    \\sigma_\\mathrm{relu}(z) = \n    \\begin{cases}\n        z & \\text{if } z \\geq 0 \\\\\n        0 & \\text{if } z < 0 \\\\\n    \\end{cases}\n    \\label{eq:act-relu}\n\\end{align}\nwith its derivative\n\\begin{align}\n    \\sigma'_\\mathrm{relu}(z) = \n    \\begin{cases}\n        1 & \\text{if } z \\geq 0 \\\\\n        0 & \\text{if } z < 0 \\\\\n    \\end{cases}\n    \\label{eq:act-relu-der}\n\\end{align}\nThe \\textbf{Heaviside} activation function is given as\n\\begin{align}\n    \\sigma_\\mathrm{Heaviside}(z) = \n    \\begin{cases}\n        1 & \\text{if } z \\geq 0 \\\\\n        0 & \\text{if } z < 0 \\\\\n    \\end{cases}\n    \\label{eq:act-heaviside}\n\\end{align}\nwith its derivative\n\\begin{align}\n    \\sigma'_\\mathrm{Heaviside}(z) = 0\n    \\label{eq:act-heaviside-der}\n\\end{align}\n\n\\subsubsection{Learning rate}\nWhen updating the weights and biases with SGD(Stochastic gradient descent), we did so by a learning rate parameter $\\eta$. There are several way to define $\\eta$, with the simplest one having $\\eta=\\mathrm{constant}$. Another option is one that is inversely decreasing as a function of the epochs. That is, for a given epoch $i_e$ out a total $N_\\mathrm{epochs}$, we set the learning rate as\n\\begin{align}\n    \\eta(t_e) = \\eta_0 (1 - \\frac{i_e}{1 + N_\\mathrm{epochs}})\n    \\label{eq:inverse-eta}\n\\end{align}\nThis will force the step size to decrease toward 0 as we close in on the maximum number of epochs $N_\\mathrm{epochs}$.\n\n\\subsubsection{Weight initialization} \\label{sec:nn-weights}\nWhen initializing weights and biases, we will look at two ways of how this can be done. The first is through a gaussian distribution, $\\mathcal(0, 1)$ which we will call \\textit{large}, as the biases will have large, spread-out distribution.\n\nThen, we will use a gaussian distribution but divided by the number of training samples, $\\mathcal(0, 1/{N_\\mathrm{train}})$, dubbing that one to be called \\textit{default}, as this is the one we will by default use in our neural network.\n\nThe effect of these two is essentially shrinking in the initial search space, and we should expect them to converge at large epoch times.\n\n\\subsubsection{Measuring the performance}\nThe performance of a neural network(or any classifier), can in its simplest form be measured by the accuracy, which is defined as\n\\begin{align}\n    \\mathrm{Accuracy} = \\frac{\\sum^{n}_{i=1}I(t_i = y_i)}{n},\n    \\label{eq:mlp-accuracy}\n\\end{align}\nwhere $n$ is the number of samples we are testing against, $I$ is the indicater function, which returns 1 if the prediction $t_i$ equals the true values $y_i$.", "meta": {"hexsha": "998a49dd5abe3d600b7f37a11200e56935326bd5", "size": 11641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/theory/neuralnetworks.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/neuralnetworks.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/neuralnetworks.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": 64.3149171271, "max_line_length": 914, "alphanum_fraction": 0.7175500387, "num_tokens": 3327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361700013356, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.766203650772311}}
{"text": "\\documentclass{article}[12pt]\n\n\\usepackage{amsthm}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{mathrsfs}\n\\usepackage{bm}\n\n\\begin{document}\n\n\\section*{The Heat Equation}\nWe postulate a fixed bar of a single and constant-density material, with length $L$; a uniform cross sectional area $A$ and a diffusivity of $\\alpha = \\frac{\\kappa}{c\\rho}$ (a parameter which depends on the rod material and its thermal conductivity/heat capacity). The bar is insulated on the outer surface and we assume at any point $x$ across the bar the temperature of the cross section is constant, but may be different to that of any other cross-section at a different point $x'$:\\par\n\\begin{align}\\label{eq:heateq}\n \\frac{\\partial \\phi}{\\partial t} &= \\alpha \\frac{\\partial^2\\phi}{\\partial x^2} , &  0\\leq x \\leq L, &&  t\\geq 0\n\\end{align}\nWe set the Dirichlet boundary conditions and the initial condition:\\par\n\\begin{align}\n  \\phi(0,t) = \\phi_0, & & \\phi(L,t) = \\phi_L, & & \\phi(x,0) = f_0(x)\n\\end{align}\nThis is represented in Fig. \\ref{fig:bar_representation}.\\par\n\\begin{figure}[h]\n  \\centering\n  \\includegraphics[scale = 0.5]{bar_representation.png}\n  \\caption{Graphical representation of bar conditions.}\n  \\label{fig:bar_representation}\n\\end{figure}\nWe will use the Finite Difference (FD) method to solve Eq. \\eqref{eq:heateq} numerically with a discrete approximation. We understand that the function $\\phi$ and its derivatives $\\partial_t\\phi$, $\\partial_x\\phi$ and $\\partial_{xx}\\phi$ are all continuous in $x$ and $t$.\n\\subsection*{Continuous Form}\nWe imagine that the entire length of the bar $L$ is split in to a finite number $N$ of mesh points of equal length $\\Delta x = L/N$. We then evaluate the heat at the boundary of each of these mesh points given the relevant system boundary conditions to evaluate the entire temperature profile across the whole bar.\n\\begin{equation}\n  \\lim_{N\\rightarrow \\infty}\\frac{L}{N} \\approx\\partial x \n\\end{equation}\nSo we see:\n\\begin{equation}\\label{eq:continuous_forward}\n\\lim_{\\Delta x \\rightarrow 0 } \\frac{\\phi(x+\\Delta x) - \\phi(x)}{\\Delta x} \\approx \\frac{\\partial \\phi}{\\partial x}\n\\end{equation}\nThis is a continuous form of the forward-difference numerical approximation for the PDE in $x$. We can see that the FD method is in fact very similar to a forward Euler method for solving non-first-order PDEs. In actuality we may not set $\\Delta x = 0$ so a truncation error will exist in this limit. We  control the extent of this error by increasing the number of nodes present on the mesh.\\par\nWe may also form backward-difference, centre-difference and second order approximations for the solution of this equation. Here, we simply present the first-order forward-difference method.\n\\subsection*{Discrete Form}\nWe may convert \\eqref{eq:continuous_forward} in to a discrete form upon the mesh $(0,L) = (0,N\\Delta x)$:\n\\begin{equation}\\label{eq:discrete_forward_x}\n  \\frac{\\partial \\phi}{\\partial x}\\bigg\\rvert_{x_i} = \\lim_{\\Delta x \\rightarrow 0} \\frac{\\phi_{i+1} - \\phi_i}{\\Delta x}\n\\end{equation}\nFor $\\Delta x = \\Delta x_i = x_{i+1} - x_i$, given that all nodes on the mesh are equal in length.\\par\nLet us now look at the discretised time-derivative of the function $\\phi_i^{m+1}$ at a point in time $t_{m+1}$:\n\\begin{equation}\\label{eq:discrete_forward_t}\n\\frac{\\partial \\phi}{\\partial t}\\bigg\\rvert_{t_{m+1},x_i} = \\lim_{\\Delta t \\rightarrow 0}\\frac{\\phi_i^{m+1} - \\phi_i^{m}}{\\Delta t}\n\\end{equation}\nFor $ \\Delta t = \\Delta t_{m+1} = t_{m+1}  - t_{m}$ where we uniformly step through time.\nfrom \\eqref{eq:discrete_forward_x} we may now evaluate:\n\\begin{equation}\\label{eq:discrete_forward_x_2o}\n\\frac{\\partial^2 \\phi}{\\partial x^2}\\bigg\\rvert_{x_i,t_m} = \\lim_{\\Delta x \\rightarrow 0} \\frac{\\phi_{i+1}^m - 2\\phi_{i}^m + \\phi_{i-1}^m}{\\Delta x^2}\n\\end{equation}\nSo we now have a generalised forward-time/centred-space discrete form of \\eqref{eq:heateq} by substituting \\eqref{eq:discrete_forward_t} and \\eqref{eq:discrete_forward_x_2o}:\n\\begin{equation}\n\\phi_i^{m+1} = \\phi_i^m + \\frac{\\alpha\\Delta t}{\\Delta x^2} \\left(\\phi_{i+1}^m -2\\phi_i^m + \\phi_{i-1}^m\\right)\n\\end{equation}\nWhere:\n\\begin{equation}\nq = \\frac{\\alpha\\Delta t}{\\Delta x ^2}\n\\end{equation}\nWe may now solve this computationally, given the boundary conditions from \\eqref{eq:heateq}, for each discrete point. Alternatively, we may form a matrix of all points.\n\\begin{equation}\n\\bm{\\phi}^m+1 = A \\bm{\\phi}^{m}\n\\end{equation}\nWhere:\n\\begin{equation}\n  A =\n  \\begin{bmatrix}\n    1&0&0&\\hdots&0&0\\\\\n    q&(1-2q)&q&0&\\ddots&0\\\\\n    0&q&(1-2q)&q&\\ddots&0\\\\\n    0&\\ddots&\\ddots&\\ddots&\\ddots&0\\\\\n    0&\\ddots&q&(1-2q)&q&0\\\\\n    0&\\ddots&0&q&(1-2q)&q\\\\\n    0&0&\\hdots&0&0&1\n  \\end{bmatrix}\n\\end{equation}\nSo, we may evalute the column vector $\\bm{\\phi}^{0}$ across the length $L$ at $t=0$ given the intial conditions, and then step forward through time to calculate a general solution for any combination of boundary conditions and physical parameters.\n\\end{document}", "meta": {"hexsha": "94390e0bf02535017b05e60cba2327cf0c6ed5a7", "size": 4978, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "apps/heat/documentation/readme.tex", "max_stars_repo_name": "Oakenfold/visualchemeng-js", "max_stars_repo_head_hexsha": "05d2dcc2651b2795edf0802399a2acf3d8b8349d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2018-04-04T18:29:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-26T16:02:11.000Z", "max_issues_repo_path": "apps/heat/documentation/readme.tex", "max_issues_repo_name": "Oakenfold/visualchemeng-js", "max_issues_repo_head_hexsha": "05d2dcc2651b2795edf0802399a2acf3d8b8349d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 27, "max_issues_repo_issues_event_min_datetime": "2017-10-02T21:53:28.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-23T10:36:00.000Z", "max_forks_repo_path": "apps/heat/documentation/readme.tex", "max_forks_repo_name": "Oakenfold/visualchemeng-js", "max_forks_repo_head_hexsha": "05d2dcc2651b2795edf0802399a2acf3d8b8349d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-04-03T22:14:40.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-04T07:18:04.000Z", "avg_line_length": 62.225, "max_line_length": 489, "alphanum_fraction": 0.7237846525, "num_tokens": 1615, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361580958427, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7662036316258182}}
{"text": "\\chapter{Fibonacci Numbers}\n\nIn mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:\n%\n\\begin{equation*} % example of unnumbered equations\n0, 1, 1, 2, 3,5,8,13,21,34,55,89,144,\\ldots\n\\end{equation*}\n\nBy definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. In mathematical terms, the sequence $F_n$ of Fibonacci numbers is defined by the recurrence relation\n%\n\\begin{equation}\nF_n = F_{n-1} + F_{n-2},\n\\end{equation}\n%\nwith seed values\n%\n\\begin{equation}\nF_0 = 0, F_1 = 1.\n\\end{equation}\n\nThe Fibonacci sequence is named after Leonardo Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics, although the sequence had been described earlier in Indian mathematics. \\cite{Goonatilake:1998} By modern convention, the sequence begins either with $F_0 = 0$ or with $F_1 = 1$. The Liber Abaci began the sequence with $F_1 = 1$, without an initial 0.\n\n\n\\section{Origins}\n\nThe Fibonacci sequence appears in Indian mathematics, in connection with Sanskrit prosody. \\cite{Singh:1985} In the Sanskrit oral tradition, there was much emphasis on how long (L) syllables mix with the short (S), and counting the different patterns of L and S within a given fixed length results in the Fibonacci numbers; the number of patterns that are m short syllables long is the Fibonacci number $F_{m + 1}$.\n\\citet{Goonatilake:1998} writes that the development of the Fibonacci sequence ``is attributed in part to Pingala (200 BC), later being associated with Virahanka (c.~700 AD), Gopala (c.~1135), and Hemachandra (c.~1150)''.  \n\n\\begin{figure}[hbt!]\n\\centering\n\\includegraphics[width=.4\\textwidth]{314px-Liber-abbaci-magliab-f124r}\n\\caption{A page of Fibonacci's Liber Abaci a very long title e just to prove my point more and more and more}\n\\source{Heinz L\\\"{u}neburg, Leonardi Pisani Liber Abaci oder Lesevergn\\\"{u}gen eines Mathematikers}\n\\end{figure}\n\n\\section{List of Fibonacci Numbers}\n\nThe first 11 Fibonacci numbers $F_n$ for $n = 0, 1, 2, \\ldots, 10$ are:\n\n\\begin{table}[hbt!]\\centering\n\\caption{First 11 Fibonacci Numbers for $n=0,1,\\ldots$}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}\n\\hline\n$F_0$ & $F_1$ & $F_2$ & $F_3$ & $F_4$ & $F_5$ & $F_6$ & $F_7$ & $F_8$ & $F_9$ & $F_{10}$\\\\\n\\hline\n0 & 1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 55 \\\\\n\\hline\n\\end{tabular}\n\\end{table}\n\nThe sequence can also be extended to negative index n using the re-arranged recurrence relation\n%\n\\begin{equation}\nF_{n-2} = F_n - F_{n-1},\n\\end{equation}\n%\nwhich yields the sequence of ``negafibonacci'' numbers satisfying\n%\n\\begin{equation}\nF_{-n} = (-1)^{n+1} F_n.\n\\end{equation}\n%\nThus the bidirectional sequence is\n\\begin{table}[hbt!]\\centering\n\\caption{Bidirectional Fibonacci Numbers sequence}\n\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}\n\\hline\n$F_{-5}$ & $F_{-4}$ & $F_{-3}$ & $F_{-2}$ & $F_{-1}$ & $F_0$ & $F_1$ & $F_2$ & $F_3$ & $F_4$ & $F_5$ \\\\\\hline\n5 & $-3$ & 2 & $-1$ & 1 & 0 & 1 & 1 & 2 & 3 & 5\\\\\\hline\n\\end{tabular}\n\\end{table}\n\n\\citet{Rohl:1989} gives an account of how Fibonacci numbers can be computed efficiently.\n\n\\section{Applications}\n\n\\subsection{In Computation}\n\nFibonacci numbers have wide applications in mathematics as well as computer science:\n\n\\begin{itemize}\n\\item The Fibonacci numbers are important in the computational run-time analysis of Euclid's algorithm to determine the greatest common divisor of two integers: the worst case input for this algorithm is a pair of consecutive Fibonacci numbers.\n\n\\item Yuri Matiyasevich was able to show that the Fibonacci numbers can be defined by a Diophantine equation, which led to his original solution of Hilbert's tenth problem.\n\n\\item The Fibonacci numbers are also an example of a complete sequence. This means that every positive integer can be written as a sum of Fibonacci numbers, where any one number is used once at most.\n\n\\item Moreover, every positive integer can be written in a unique way as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers. This is known as Zeckendorf's theorem, and a sum of Fibonacci numbers that satisfies these conditions is called a Zeckendorf representation. The Zeckendorf representation of a number can be used to derive its Fibonacci coding.\n\n\\item Fibonacci numbers are used by some pseudorandom number generators.\n\n\\item Fibonacci numbers are used in a polyphase version of the merge sort algorithm in which an unsorted list is divided into two lists whose lengths correspond to sequential Fibonacci numbers -- by dividing the list so that the two parts have lengths in the approximate proportion $\\varphi$. A tape-drive implementation of the polyphase merge sort was described in The Art of Computer Programming.\n\n\\item Fibonacci numbers arise in the analysis of the Fibonacci heap data structure.\n\n\\item The Fibonacci cube is an undirected graph with a Fibonacci number of nodes that has been proposed as a network topology for parallel computing.\n\n\\item A one-dimensional optimization method, called the Fibonacci search technique, uses Fibonacci numbers.\n\n\\item The Fibonacci number series is used for optional lossy compression in the IFF 8SVX audio file format used on Amiga computers. The number series compands the original audio wave similar to logarithmic methods such as $\\mu$-law.\n\n\\item Since the conversion factor 1.609344 for miles to kilometers is close to the golden ratio (denoted $\\varphi$), the decomposition of distance in miles into a sum of Fibonacci numbers becomes nearly the kilometer sum when the Fibonacci numbers are replaced by their successors. This method amounts to a radix 2 number register in golden ratio base $\\varphi$ being shifted. To convert from kilometers to miles, shift the register down the Fibonacci sequence instead.\n\\end{itemize}\n\n\n\\subsection{In Nature}\n\nFibonacci sequences appear in biological settings, in two consecutive Fibonacci numbers, such as branching in trees, arrangement of leaves on a stem, the fruitlets of a pineapple, the flowering of artichoke, an uncurling fern and the arrangement of a pine cone, and the family tree of honeybees. However, numerous poorly substantiated claims of Fibonacci numbers or golden sections in nature are found in popular sources, e.g.,~relating to the breeding of rabbits in Fibonacci's own unrealistic example, the seeds on a sunflower, the spirals of shells, and the curve of waves.\n\nA model for the pattern of florets in the head of a sunflower was proposed by H.~Vogel in 1979. \\cite{Vogel:1979} This has the form\n\\begin{equation}\n\\theta = \\frac{2\\pi}{\\phi^2} n,\\  r = c \\sqrt{n}\n\\end{equation}\nwhere $n$ is the index number of the floret and $c$ is a constant scaling factor; the florets thus lie on Fermat's spiral. \n\n\\begin{figure}[hbt!]\\centering\n\\includegraphics[width=.5\\textwidth]{FibonacciChamomile}\n\n\\caption{Yellow Chamomile head}\n\\end{figure}", "meta": {"hexsha": "fe98170511909688c08761acfdc3ae7378c95840", "size": 7002, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GayaUKM-LaTeX/chap-fibonacci.tex", "max_stars_repo_name": "gijswijs/phd_thesis_markdown", "max_stars_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "GayaUKM-LaTeX/chap-fibonacci.tex", "max_issues_repo_name": "gijswijs/phd_thesis_markdown", "max_issues_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "GayaUKM-LaTeX/chap-fibonacci.tex", "max_forks_repo_name": "gijswijs/phd_thesis_markdown", "max_forks_repo_head_hexsha": "4ae30ef0ebed4914137e2138edd87c6e965be9c8", "max_forks_repo_licenses": ["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.35, "max_line_length": 576, "alphanum_fraction": 0.7620679806, "num_tokens": 1926, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361533336451, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7662036257970299}}
{"text": "\n\\chapter{Formal specification of the gameplay}\n\\label{chap:formal}\n\n\\section{Grid universe}\n\nThe universe is made of a $m$ (horizontally) by $n$ (vertically) array of cases.\nThe cases are delimited by a grid.\nWe represent those with planar graphs:\n\\begin{itemize}\n    \\item The array of cases: $G_A = (V_A, E_A)$, with\n        \\begin{align*}\n            V_A &= \\left\\{v_{a,ij} : 0 \\le i < m, 0 \\le j < n\\right\\} \\\\\n            E_A &= \\left\\{\\{v_{a,i_1j_1}, v_{a,i_2,j_2}\\} :\n            |i_1-i_2| + |j_1-j_2| = 1 \\right\\}\n        \\end{align*}\n    \\item The grid: $G_G = (V_G, E_G)$, with\n        \\[V_G = \\left\\{v_{g,ij} : 0 \\le i \\le m, 0 \\le j \\le n\\right\\} \\]\n        \\[\n            \\begin{split}\n                E_G = \\{\n                    \\{v_{g,i_1j_1}, v_{g,i_2,j_2}\\} :\n                    & |i_1-i_2| + |j_1-j_2| = 1; \\\\\n                    & 0 < i_1 < m; 0 < j_1 < n; \\\\\n                    & 0 \\le i_2 \\le m, 0 \\le j_2 \\le n\n                \\}\n            \\end{split}\n        \\]\n\\end{itemize}\nThe graphs are depicted in figure~\\ref{fig:graphs1}.\n\\begin{figure}\n    \\begin{center}\n        \\includegraphics[width=0.3\\textwidth]{img/graphs_universe_draft.png}\n    \\end{center}\n    \\caption{Representation of the graphs: $G_A$ is in green, $G_G$ in blue\n        (the dashed blue lines are not edges of the graph) and the global border\n        in black.\n    }\n    \\label{fig:graphs1}\n\\end{figure}\nOn this representation, all the edges of $G_G$ intersect\nedges of $G_A$, which gives a correspondance bijection $c:E_G \\rightarrow E_A$,\nformally defined as follows\n\\begin{align*}\n    c(\\{v_{g,i,j}, v_{g,i+1,j}\\}) &= \\{v_{a,i,j-1}, v_{a,i,j}\\} \\\\\n    c(\\{v_{g,i,j}, v_{g,i,j+1}\\}) &= \\{v_{a,i-1,j}, v_{a,i,j}\\}.\n\\end{align*}\n\nA border $B$ is a path in $G_G$, which starts at $v_{g,0j}$ and ends at\n$v_{g,m+1,j'}$.\n\nDue to the structure of both graphs, the edges of the border corresponds\n(by $c$) to a set for edges which form a cut of $G_A$. This cut defines\ntwo subgraphs: the free space $F$ (containing cases $v_{a,i,n-1}$) and\nthe structure $S$ (containing cases $v_{a,i0}$).\n\nThe following properties hold for any border:\n\\begin{itemize}\n    \\item the free space contains the upper row $v_{a,i,n-1}$;\n    \\item the structure contains the lower row of cases $v_{a,i0}$;\n    \\item the structure is connex;\n    \\item the free space is connex.\n\\end{itemize}\n\n$F$ and $S$ are complementary, there is thus an trivial bijection between\nthe set of free spaces and the set of structures.\n\nA free space, structure pair  which satisfies the preceding properties\nis said to be well-formed.\n\nA well-formed free space, structure pair always corresponds to a border:\ntaking the edges in $G_G$ corresponding to the edges of $G_A$\nlinking the structure and the free space gives\na set of edges which constitue a border.\nThere is thus a bijection between borders and well-formed free spaces (and structures).\n\n\\section{Players}\n\nThere is a global well-formed structure which is the same for all the players.\nFor all cases $v_{a,i,j}$ in the global structure, the condition $j < n - N_p$\nmust hold, where $N_p$ is the number of players.\n\nThe structure is thus conceptually dense (not holes in it). But this\ndoes not imply anything on the display: the inner cases of the structure\ncan be anything, this doesn't impact the gameplay.\n\nEach player $p_k, 0\\le k < N_p$ is an entity, that occupies a case $v_{a,p_k}$.\nCases occupied by players must be in the global free space (ie. outside the global\nstructure). Only one player may occupy a given place at a given time.\n\nEach player must be hooked to a neighbour case, which must be either occupied by\nthe global structure, either by another player. In any set of players, there must\nbe at least one player hooked to a case occupied by the global structure.\n\nThe hook point is the edge linking the case occupied by the player and the case\nit is hooked to (or the corresponding edge through the bijection $c$).\n\n\\section{Movements}\n\nAt any time, each player has its own free space, structure, border triple $(F_k, S_k, B_k)$.\nThe free space is the largest connex component that contains the cases of the upper row,\nbut no cases of the global structure, and no cases occupied by other players.\nThe definition of its structure and border follows from that.\n\nFrom the border $B_k$, extracting the edges gives a sequence of hook points $(h_k)_i$.\nThe player is always hooked to a point in this sequence.\nTo each hook point corresponds a unique case that can be occupied by the player\n(the converse is not true).\n\nWhen a player moves right, its new hook point is determined in two steps:\n\\begin{enumerate}\n    \\item Finding new case: from the current hook point, $(h_k)_i$ is traversed\n        (increasing $i$), until the traversed hook point corresponds to a case\n        different of the current case of the player. If no such hook point is\n        found before the end of the sequence, the move is impossible.\n    \\item Deciding the new hook point: if possible, the player hooks to the\n        global structure. To do this, the list is traversed, from the hook\n        point found at previous step. One switches to the next hook point if\n        the next hook point corrsponds to the same case as the same hook point\n        and if the current hook point is hooking on another player. Otherwise,\n        the traversing stops.\n\\end{enumerate}\n\n\\section{Mask}\n\nThe mask is a set of cases which must include all the cases of the global\nstructure. The connex component of the mask containing the global structure\nmust also include at least $N_p$ cases of the global free space.\n\n", "meta": {"hexsha": "2a63dbd0401d55dee757ed1084cb7f43085ae407", "size": 5606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/formal.tex", "max_stars_repo_name": "cassiersg/elec-2103", "max_stars_repo_head_hexsha": "f0152c81e8d808a1ab62c78e9324fb99b341638a", "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/formal.tex", "max_issues_repo_name": "cassiersg/elec-2103", "max_issues_repo_head_hexsha": "f0152c81e8d808a1ab62c78e9324fb99b341638a", "max_issues_repo_licenses": ["Apache-2.0"], "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/formal.tex", "max_forks_repo_name": "cassiersg/elec-2103", "max_forks_repo_head_hexsha": "f0152c81e8d808a1ab62c78e9324fb99b341638a", "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.1230769231, "max_line_length": 92, "alphanum_fraction": 0.6839100963, "num_tokens": 1577, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951661947456, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7661043719289626}}
{"text": "\\subsection{Plane Laminas}\r\n\\begin{definition}\r\n\tA plane lamina is an idealized 2D (0 thickness) object with mass that occupies a region $D \\subset \\mathbb{R}^2$.\r\n\\end{definition}\r\n\r\n\\noindent\r\nSome questions one may ask about a plane lamina are \"What is the total mass?\" and \"Where is the center of mass?\".\\\\\r\nWe can think of the mass as \r\n\\begin{equation*}\r\n\tM = \\iint\\limits_{D}{\\sigma(x,y)\\mathrm{d}A}\r\n\\end{equation*}\r\nwhere $\\sigma(x,y)$ is the mass density of the lamina at $(x,y)$.\\\\\r\nThe center of mass is\r\n\\begin{equation*}\r\n\t\\bar{x} = \\frac{M_y}{M} = \\frac{\\iint\\limits_{D}{x\\sigma(x,y)\\mathrm{d}A}}{M} \\text{ and } \\bar{y} = \\frac{M_x}{M} = \\frac{\\iint\\limits_{D}{y\\sigma(x,y)\\mathrm{d}A}}{M}\r\n\\end{equation*}\r\nwhere $M_x$ is the moment about the $x$-axis and $M_y$ is the moment about the $y$-axis.", "meta": {"hexsha": "ced8a7eb2fd55451e6a4b3121ee81542bfbd8e8a", "size": 812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/planeLaminas.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/multipleIntegrals/planeLaminas.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/multipleIntegrals/planeLaminas.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": 47.7647058824, "max_line_length": 170, "alphanum_fraction": 0.6699507389, "num_tokens": 289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7661043618253461}}
{"text": "\\chapter{E2E Evaluation Metrics}\\label{ch:metrics}\n\\section{Audio Metrics}\n\\subsection{SNR - Signal to Noise Ratio}\nThe signal-to-noise ratio (SNR) metric evaluates how\ndistinct the desired signal is out of the overall noise.\n\nLet \\(y(t)\\) denote a mixed time-domain signal consisting of\nthe desired speech signal, and some interferences\nreferred to as noise.\nThat mixture is given by:\n\\begin{align}\n    y(t) = x(t) + n(t)\n\\end{align}\n\nWhere \\(x(t)\\) and \\(n(t)\\) denote the speech signal and the\ninterference noise.\n\nIdeal speech separation of the mixture is characterized by\na perfect match between the predicted speech signal, \\(\\widehat{x}(t)\\), \nand the original (reference) speech signal \\(x(t)\\).\n% Separating the speech out of the mixture,\n% the predicted speech signal, \\(\\widehat{x(t)}\\), has to match the\n% original (target) speech signal \\(x(t)\\).\n\nSuch a problem can be modeled and optimized \nby the MSE (L2) (Mean Square Error) loss function as follows:\n\\begin{align}\n    \\ell(\\widehat{x}, x) & = \\sum_{t=0}^{T-1} \\left[\\widehat{x}(t) - x(t)\\right]^{2} \\\\\n    & = \\sum_{t=0}^{T-1} |r(t)|^{2}\n\\end{align}\n\nThe term \\(\\sum_{t} |r(t)|^{2}\\) \nis the total energy of the residual error between \nthe predicted signal and the target speech,\nwhich translates to additive noise.\n\nFirst, let's break \\(\\widehat{x}(t)\\) to its fundamental components\\cite{1643671}.\n\\begin{align}\n    \\widehat{x}(t) & = x_{_{s}} + e_{_{noise}} + e_{_{interf}} + e_{_{artif}}\n\\end{align}\n\nWhere \\(x_{_{s}}\\) stands for the\npart of \\(\\widehat{x}(t)\\) coming from the \nwanted source(s), and \\(e_{_{noise}}\\) represents the part \nof \\(\\widehat{x}(t)\\) coming from the sensor's noise. The sensor\ncan be the microphone itself or one of its counterparts.\n\\(e_{_{interf}}\\) notes the unwanted sources presented\nin \\(\\widehat{x}(t)\\), and the \\(e_{_{artif}}\\)\nrepresents any other artifacts that cause\ndistortions in the prediction of \\(x_{_{s}}\\).\n\nAccording to Parseval's theorem, the residual energy in time equals the sum of\nthe power difference between the predicted magnitude \nand the magnitude of target speech \nin the frequency domain\\cite{1643671009}.\n\\begin{align}\n    \\sum_{t} |r(t)|^{2} & = \\frac{1}{T}\\sum_{\\tau=0}^{T-1}\\sum_{f=0}^{T-1} \\left[ \\widehat{X}(\\tau, f) - X(\\tau, f)\\right]^{2}\n\\end{align}\n\nSince the residual energy is referred to as the noise,\nminimizing the residual,\nwhich is minimizing the MSE loss function,\ntranslates into an increase in SNR.\n\n\n\nThe SNR is therefore given by:\n\\begin{align}\\label{eq:snr_equation}\n    SNR & = 10\\log_{10} \\left( \\frac{ \\| x_{_{s}}\\|^{2}}{\\|\\widehat{x} - x_{_{s}} \\|^{2}}  \\right) \\nonumber \\\\\n    & =  10\\log_{10} \\left( \\frac{ \\| x_{_{s}} \\|^{2}}{\\| r \\|^{2}} \\right)\n\\end{align}\n\\subsection{SI-SNR --- Scale Invariant SNR}\nTo ensure that the SNR is susceptible to scale invariance\\cite{roux2018sdr},\nboth the target and estimated signals are normalized to \\underline{zero-mean}.\n\n\\begin{align}\n    SI-SNR & = 10\\log_{10} \\left( \\frac{\\left\\| x_{_{s}} - \\mathbf{E}[x_{_{s}}]\\right\\|^{2}}\n    {\\left\\| (\\widehat{x} - \\mathbf{E}[\\widehat{x}]) - (x_{_{s}} - \\mathbf{E}[x_{_{s}}]) \\right\\|^{2}} \\right) \\nonumber \\\\\n    & = 10\\log_{10} \\left( \\frac{ \\| x_{_{AC}}\\|^{2}}{\\|\\widehat{x}_{_{AC}} - x_{_{AC}}\\|^{2}}  \\right) \\nonumber \\\\\n    & =  10\\log_{10} \\left( \\frac{ \\| x_{_{AC}}\\|^{2}}{\\| r_{_{AC}} \\|^{2}} \\right)\n\\end{align}\n\n\\subsection{Segmental SNR}\nAn SNR evaluation is basically the ratio between the overall \nenergies of the signal and those in the noise. \nHowever, some portions of the signal are almost pure noise, \nespecially in the case of speech signals, \nwhere there are gaps between phonemes, \narticulation stops, and air aspiration breaks. As a result,\nthe SNR calculation may be impacted, and\nit actually depends on\nthe length of the empty sections with respect \nto the length of\nthe other sections where speech is present.\n\nWith Segmental SNR\\cite{10.5555/912256}, instead of taking the entire signal,\nthe signal is segmented to relatively small chunks (segments), \neach in length usually set to \\(25ms\\) long\nwith the option of setting an overlap\nbetween segments.\nThen, each SNR of each segment is extracted and, finally,\nare averaged. \nIf the energy of the speech reference \nin a segment is negligible, that segment is excluded,\nthus limiting the evaluation only to sections \nwhere speech is present. \n\n\nEquation~\\ref{eq:snr_equation} can be extended to:\n\\begin{align}\n    SEG-SNR & = \\frac{1}{M}\\sum_{m=1}^{M}\n                10\\log_{10} \n                \\left(\n                    \\frac{ \\| x_{_{s}} \\|^{2}_{(m)}}{\\| r \\|^{2}_{(m)}} \n                \\right)\n\\end{align}\n\nWhere \\(M\\) denotes the number of segments the signal is divided by.\n\n\nDespite being more accurate for speech signals, Segmental SNR \nsuffers from a limitation that can affect the actual results severely. \nIn speech enhancement evaluations, the signal's predicted (enhanced) version is \ncompared to a clean reference signal \nconcerning the noisy mixture.\nUnfortunately, speech analysis for the extraction of\nthe Segmental SNR causes misalignments between \nthe reconstructed signal and the clean reference. \nMoreover, the reconstructed signal is not aligned \nwith the noisy mixture either. \nThese misalignments \nare a side effect of the time-domain \nto the frequency-domain transformation, \nthe processing manipulations on the transformed signal, \nand the reconstruction of the signal in \nthe time-domain using the inverse-transform technique. \nTherefore, without any alignments, extraction of the Segmental-SNR\nis meaningless and most probably inaccurate. \nDue to that limitation, an alignment process should be applied\nprior to taking the Segmental SNR calculation. These alignments usually \nhave a small marginal error that spans over a few sampling points.\n\n\\subsection{STOI --- Short-Time Objective Intelligibility}\nSTOI\\cite{5495701} is a metric that is used to evaluate \nthe intelligibility of a speech signal.\nThe intelligibility is measured by taking the correlation\ncoefficient between the temporal envelopes of the clean\nand degraded speech. In our case, the term degraded might\nbe confusing since the degraded speech input\nis actually the outcome of the beamformer\nfollowing the T-F masking at the front-end.\nHowever, relatively to the clean speech, \nthe beamformer's output is indeed degraded, altough\nbeing considered as an enhanced version of the noisy mixture.\n\nThe naming convention \\emph{Short-Time} comes from the time frame length\nof the overlapping segments, which is \\(384 ms\\).  \n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\linewidth]{Features/images/stoi_blocks_diagram}\n    \\caption{STOI flow diagram}\\label{fig:stoi_blocks_diagram}\n    \\source{Adapted from \\cite{5495701}}\n\\end{figure}\n\nThe STOI algorithm structure is demonstrated in \nthe blocks diagram shown in Figure\\;\\ref{fig:stoi_blocks_diagram}. \n\nThe short-time temporal envelop of the degraded\nspeech \\(Y_{_{j,m}}\\) is clipped and normalized\nbefore the extraction of the correlation coefficient\nwith the short-time temporal envelop of the\nclean speech \\(X_{_{j,m}}\\).\nThis clipped normalized version then be:\n\\begin{align}\n    \\mathcal{Y}[n] & = \\min\\Bigg\\{ \n            \\frac{||X_{_{j,m}}||}{||Y_{_{j,m}}||} Y_{_{j,m}}[n]\n            ,\\; (1+10^{\\sfrac{-\\beta}{20}})X_{_{j,m}}[n]\n        \\Bigg\\}\n\\end{align}\n\nThus, the correlation coefficient can be noted as the\ndistance given in Equation\\;\\ref{eq:stoi_correl}.\n\\begin{align}\\label{eq:stoi_correl}\n    d_{_{j,m}} & = \\frac{\n            (X_{_{j,m}}-\\bar{X}_{_{j,m}})^{tr} \n            \\cdot (\\mathcal{Y}_{_{j,m}}-\\bar{\\mathcal{Y}}_{_{j,m}})\n        }\n        {\n            ||X_{_{j,m}}-\\bar{X}_{_{j,m}}||\n            \\cdot ||\\mathcal{Y}_{_{j,m}}-\\bar{\\mathcal{Y}}_{_{j,m}}|| \n        }\n\\end{align}\nAlso, defining the intermediate intelligibility measure, \nEquation\\;\\ref{eq:stoi_correl}, it stands for the\n\\(m^{th}\\) time frame. Extending it to form\na definition for the entire signal,\nwe can take the average of \\(d_{_{j,m}}\\)\nas in Equation\\;\\ref{eq:stop_dist_avg}.\n\n\\begin{align}\\label{eq:stop_dist_avg}\n    d & = \\frac{1}{JM} \\sum_{j,m} d_{_{j,m}}\n\\end{align}\n\nWhere \\(J\\) presents the total number of one-third octave bands,\nand the averaging overlaps \\(M\\) number of time frames.\n\n\\subsection{PESQ --- Perceptual Evaluation of Speech Quality}\nPESQ\\cite{941023} is a measuring method adopted by \nthe ITU (International Telecommunication Union) to\ntest the speech quality of telephony and mobile stations.\n\nThis measuring metric evolved from different previous \nmeasuring techniques such as Bark Spectral Distortion (BSD),\nPerceptual Analysis Measurement System (PAMS),\nand Perceptual Speech Quality Measure (PSQM).\n\nThe motivation behind the development of the PESQ metric\nwas the need to assess the speech quality in an E2E\ncommunication channel that considers \nthe entire link rather than particular parts.\n\nThe evaluation of a speech signal quality by PESQ\nfollows the MOS (Mean Opinion Scores) model, where\nthe actual speech quality is ranked in-between 1 to 5 \nby a group of listeners.\n\nFigure \\ref{fig:pesq_blocks_diagram} shows the data flow\nof the PESQ computation for a predicted signal, with respect to the\nclean reference.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.85\\linewidth]{Features/images/pesq_blocks_diagram_new}\n    \\caption{PESQ Algorithm Blocks Diagram}\\label{fig:pesq_blocks_diagram}\n    \\source{Adapted from PESQ paper\\cite{941023} and redesigned}\n\\end{figure}\n\n\\section{ASR Metrics}\n\\subsection{WER - Word Error Rate}\nWER\\cite{KLAKOW200219} metric is probably the most used evaluation\ntechnique for speech recognition systems.\n\nEvaluation of this metric occurs at the ASR engine's output, \nwhere the predicted text is segmented into sentences. \nEach word in the predicted\ntext is then matched with its counterpart in the \nannotated reference transcript. \nThe sum of mismatches between a predicted sentence and the reference, \ndivided by the total counted words in the reference, indicates the WER.\n\nHowever, in some cases, the predicted sentences differ in size compared\nto the reference. Therefore, special care for \\emph{Insertions}\nand \\emph{Deletions} should be carried out as well, without neglecting\nthe detected \\emph{Substitutions}.\n\nThe WER is described by:\n\\begin{align}\n    WER & = \\frac{S + D + I}{N}\n\\end{align}\n\nWhere \\(N\\) is the total count of words in the reference,\nand \\(S,D,I\\) are the number of \\emph{Substitutions} (wrong word detection),\n\\emph{Deletions} (Omitting words),\nand \\emph{Insertions} (Wrong words insertions).\n\n\\subsection{CER - Character Error Rate}\nCER is another metric with some similarities to the \nWER evaluation metric but with a narrower resolution.\nThe change in resolution is due to comparing characters instead of words.\nThe same rules of \\emph{Substitutions}, \\emph{Deletions}, and \\emph{Insertions}\napply, and therefore, the calculation of the CER is the same:\n\\begin{align}\n    CER & = \\frac{S + D + I}{N}\n\\end{align}\n\nIn many cases, the CER\\cite{_isword} is a complementary \nmeasuring metric to the WER\nmetric.\nThis extra measure shines especially \nwhen there is a need to get a full perspective \nwith a greater differentiation capability of the \n\\emph{Substitutions} in the complete sentence \nof the suggested predicted transcript,\n also known as the hypothesis. \nWhile WER counts a mismatch between the reference and the predicted \nword, even in cases where only single characters or worse, \npunctuation marks are not correctly placed, CER can lead to \nmore accurate grading per word.\n\n\\section{HW Metrics}\n% \\subsection{Computation time}\n% \\subsection{Utilization Ratio}\n\\subsection{Power Estimation}\nElectrical circuits, components, and systems require power to function.\nThe amount of power a device consumes from the power sources is subject \nto various parameters and mainly describes the rate of energy delivery \nfrom the source to the device or vice versa.\n\nDue to the nature of conducting materials, \nwhenever an electrical potential is applied\nbetween the conductor's terminals, \nelectrical current goes through the conductor.\nThe current that flows\nin the system feeds the different components with energy. \nHowever, the total supplied energy is not purely consumed over time, \nand some energy is lost and wasted due to power dissipation.\n\nPower dissipation is a side effect of a conductors' resistive nature, \nwhich \"resists\" the transition of current through it.\nAs a result, part of the energy in the system is converted \nto heat energy.\n\nSince dissipated power is a waste of energy it is also \nconsidered as one of the main causes \nto electronic systems' performance degradation at high temperatures.\nTherefore, engineers want to mitigate \nas much as possible any dissipated power that\nis not used for the main functionality of the system. % but dissipated and converted to heat.\nFor that end, power analysis is crucial in any system \ndesign phase to ensure efficiency and correctness while maintaining \nrobustness over time and under different working conditions.\n\nElectrical circuit power dissipation depends on many arguments. % mainly when speaking of digital logic designs. \nHowever, in general, it can be modeled \naccurately according to three scenarios divided into two main groups:\n\\begin{enumerate}\n    \\item Static Power\n    \\begin{itemize}\n        \\item Intrinsic Leakage Power\n    \\end{itemize}\n    \\item Dynamic Power\n    \\begin{itemize}\n        \\item Internal Power\n        \\item Switching Power\n    \\end{itemize}\n\\end{enumerate}\n\n\\subsubsection{Intrinsic Leakage Power}\nLeakage power is the power that dissipates due to the \nstructure of a CMOS device, \nwhere a thin layer of metal oxide isolates\nbetween the semiconductor material and the\ngate metal and thus forming a capacitor. \nLeakage power dissipates statically regardless of the CMOS \ndevice state, \nwhether it is the active state or the off state (idle).\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/leak_power_schem}\n    \\caption{Leakage Power Illustration}\\label{fig:leak_power_schem}\n    \\source{Adapted from Synopsys PrimePower Suit documentation\\cite{lowpowerSoc}}\n\\end{figure}\n\nFigure \\ref{fig:leak_power_schem} describes three current leakages,\nthe reverse bias current of the diode (p-n junction), sub-threshold current leakage, and\nthe gate leakage.\n\nWith the recent advancement in process technologies, \nCMOS devices are minimized in size, \nbut the leakage power is increasing as a side effect.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.55\\linewidth]{Features/images/leak_vs_nm}\n    \\caption{Leakage Power vs. Process Technology}\\label{fig:leak_vs_nm}\n    \\source{Adapted from Soitec FinFet presentation\\cite{processnodeleak}}\n\\end{figure}\nThe overall leakage power is a function \nof the total number of voltage sources and their voltage levels, \nthe physical dimensions of the CMOS device, \nand the threshold value set to switch between on-off states.\n\\begin{align}\n    P_{leak} & = \\mathcal{F} (V_{_{DD}}, V_{_{th}}, \\frac{\\mu_{n}\\varepsilon_{ox} W}{L})\n\\end{align}\n\n\\subsubsection{Internal Power}\nA CMOS device is a formation of two complementary MOS transistors,\na p-type and an n-type, formed together as a symmetrical\npair unit. \nInternal power dissipation happens due to the structure of\nCMOS devices. \nWhenever a transition at the CMOS gate occurs, \nboth the NMOS and the PMOS drivers are active for a \nrelatively small duration of time. As a result, \na short circuit is formed directly from the power rail to the ground. \nAlthough not lasting for long periods of time, \nthe amount of internal dissipated power in highly toggled \ndesigns becomes significant over time. \nTo minimize the internal dissipated power, \nor in other words, minimizing the time duration where \nboth devices are active and current flows from Vdd to GND, \nthe transition times (both rising and falling) are set to be very fast.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/int_power_schem}\n    \\caption{Internal Power Illustration}\\label{fig:int_power_schem}\n    \\source{Adapted from Synopsys PrimePower Suit documentation\\cite{lowpowerSoc}}\n\\end{figure}\n\n\\subsubsection{Switching Power}\nSwitching power is the power dissipated as a result \nof charging and discharging loads during transitions. \nMOS devices introduce capacitance at their input gates \ndue to their structure. \nThus, whenever a low-to-high transition at the output occurs, \nthe driver pushes the current to charge the capacitive \nload in order to set the desired logic level voltage. \nLikewise, the load capacitance discharge and sink into the \ndevice through the PMOS transistor to the ground \nfor a high-to-low transition at the output. \nAs a result, the charging and discharging currents \neventually dissipate and are not delivered to the external load.\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.75\\linewidth]{Features/images/sw_power_schem}\n    \\caption{Switching Power Illustration}\\label{fig:sw_power_schem}\n    \\source{Adapted from Synopsys PrimePower Suit documentation\\cite{lowpowerSoc}}\n\\end{figure}", "meta": {"hexsha": "0b29e978dfdcca3fe2bac13dd500da31a4f4a83d", "size": 17175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Dissertation/Features/metrics.tex", "max_stars_repo_name": "aviadb/research", "max_stars_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Dissertation/Features/metrics.tex", "max_issues_repo_name": "aviadb/research", "max_issues_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Dissertation/Features/metrics.tex", "max_forks_repo_name": "aviadb/research", "max_forks_repo_head_hexsha": "d710d21cd18a5f5c01acf65d85c8ef364a3ca219", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.8928571429, "max_line_length": 126, "alphanum_fraction": 0.7444541485, "num_tokens": 4487, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951588871158, "lm_q2_score": 0.8198933293122507, "lm_q1q2_score": 0.7661043577132068}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following vector functions are linear transformations?\n  \\begin{equation*}\n    T_1\\paren{\\begin{mymatrix}{c} x \\\\ y \\end{mymatrix}}\n    = \\begin{mymatrix}{c} 2x+y \\\\ x-2y \\\\ -x-y \\end{mymatrix},\\quad\n    T_2\\paren{\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}}\n    = \\begin{mymatrix}{c} x+y^2 \\\\ (x+y)z \\\\ 0 \\end{mymatrix},\\quad\n    T_3\\paren{\\begin{mymatrix}{c} x \\\\ y \\\\ z \\end{mymatrix}}\n    = \\begin{mymatrix}{c} 0 \\\\ 0 \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $T_1$ and $T_3$ are linear, and $T_2$ is not. The transformation\n    $T_3$ is called the \\textbf{zero transformation}%\n    \\index{zero transformation}%\n    \\index{linear transformation!zero transformation}.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex} Consider the following functions $T:\\R^3\\rightarrow \\R^2$.\n  Explain why each of these functions $T$ is not linear.\n\n  \\begin{enumerate}\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      x+2y+3z+1 \\\\\n      2y-3x+z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      x+2y^2+3z \\\\\n      2y+3x+z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      \\sin x+2y+3z \\\\\n      2y+3x+z\n    \\end{mymatrix}$\n\n  \\item $T\\begin{mymatrix}{c}\n      x \\\\\n      y \\\\\n      z\n    \\end{mymatrix} =\\begin{mymatrix}{c}\n      x+2y+3z \\\\\n      2y+3x-\\ln z\n    \\end{mymatrix}$\n  \\end{enumerate}\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $A$ be an $m\\times n$-matrix. Show the vector function\n  $T:\\R^n\\to \\R^m$ defined by $T(\\vect{v})=A\\vect{v}$ is a\n  linear transformation.\n  \\begin{sol}\n    We have\n    $T(a\\vect{v}+b\\vect{w}) = A(a\\vect{v}+b\\vect{w}) = a(A\\vect{v}) +\n    b(A\\vect{w}) = aT(\\vect{v}) + bT(\\vect{w})$ by properties of\n    matrix multiplication. Therefore, $T$ is linear by\n    Proposition~\\ref{prop:linear-transformation-alternative}.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u}\\in\\R^n$ be a fixed vector.  Show that the function $T$\n  defined by\n  $T(\\vect{v}) = \\vect{v}-\\proj_{\\vect{u}}(\\vect{v})$ is a\n  linear transformation.\n  \\begin{sol}\n    We have\n    \\begin{eqnarray*}\n      T(a\\vect{v}+b\\vect{w})\n      &=& a\\vect{v}+b\\vect{w}\n          - \\frac{\\vect{u}\\dotprod(a\\vect{v}+b\\vect{w})}{\\norm{\\vect{u}}^2}\\vect{u} \\\\\n      &=& a\\vect{v}\n          - a\\frac{\\vect{u}\\dotprod\\vect{v}}{\\norm{\\vect{u}}^2}\\vect{u}\n          + b\\vect{w}\n          - b\\frac{\\vect{u}\\dotprod\\vect{w}}{\\norm{\\vect{u}}^2}\\vect{u} \\\\\n      &=& aT(\\vect{v}) + bT(\\vect{w}).\n    \\end{eqnarray*}\n    Therefore, $T$ is linear.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $\\vect{u}\\in\\R^n$ be a fixed non-zero vector. The function $T$\n  defined by $T(\\vect{v})=\\vect{u}+\\vect{v}$ has the effect of\n  translating all vectors by adding $\\vect{u}$. Show this is not a\n  linear transformation.\n  \\begin{sol}\n    If $T$ were a linear transformation, it should satisfy\n    $T(\\vect{0}) = \\vect{0}$, but it does not. Also\n    $T(\\vect{v}+\\vect{w}) \\neq T\\vect{v}+T\\vect{w}$.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "b342a5e41978610179d3f4c03fd7588b9af3f300", "size": 3144, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/LinearTransformationsRn-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/LinearTransformationsRn-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/LinearTransformationsRn-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 28.3243243243, "max_line_length": 86, "alphanum_fraction": 0.572519084, "num_tokens": 1260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8872045847699186, "lm_q1q2_score": 0.766004982346236}}
{"text": "\\chapter{Sliced Mixed-Marginal Wasserstein}\n\n\n\\section{Abstract}\n\tMulti-marginal optimal transport enables one to compare multiple probability measures, which increasingly finds application in multi-task learning problems.\n\tOne practical limitation of multi-marginal transport is computational scalability in the number of measures, samples and dimensionality.\n\tIn this work, we propose a multi-marginal optimal transport paradigm based on random one-dimensional projections, whose (generalized) distance we term the \\emph{sliced multi-marginal Wasserstein distance}.\n\tTo construct this distance, we introduce a characterization of the one-dimensional multi-marginal Kantorovich problem and use it to highlight a number of properties of the sliced multi-marginal Wasserstein distance. \n\tIn particular, we show that (i) the sliced multi-marginal Wasserstein distance is a (generalized) metric that induces the same topology as the standard Wasserstein distance, (ii) it admits a dimension-free sample complexity, (iii) it is tightly connected with the problem of barycentric averaging under the sliced-Wasserstein metric.\n\tWe conclude by illustrating the sliced multi-marginal Wasserstein on multi-task density estimation and multi-dynamics reinforcement learning problems.\n\n\\section{Introduction}\n\nOptimal transport is a framework for defining meaningful metrics between probability measures \\cite{villani, compopt}. \nThese metrics find a wide range of applications, such as generative modeling \\cite{pmlr-v84-genevay18a,bunne2019}, Bayesian inference \\cite{bayes}, imitation learning \\cite{Dadashi2020PrimalWI}, graph matching and averaging \\cite{pmlr-v97-xu19b,NIPS2019_8569}.\nMulti-marginal optimal transport \\cite{gangbo} studies ways of comparing more than two probability measures in a geometrically meaningful way.\nMulti-marginal distances defined using this paradigm are often useful in settings where sharing geometric structure is useful, such as multi-task learning. In particular, they have been applied for training multi-modal generative adversarial networks \\cite{mwgan}, clustering  \\cite{generalizedmet}, and computing barycenters of measures \\cite{altschuler_mm}.\n\n\nFollowing the establishment of key theoretical results, including by \\textcite{gangbo,journals/siamma/AguehC11, Pass2014MultimarginalOT}, research is shifting toward applications. This motivates a need for practical algorithms for the multi-marginal setting \\cite{mw_compl}. \nStandard approaches based on linear programming and entropic regularization scale exponentially with the number of measures, and/or the dimension of the space \\cite{benamou:hal-01096124, accmmot}. \nA number of recent works have therefore studied settings, where multi-marginal transport problems can be efficiently solved via low-rank structures on the underlying cost function \\cite{altschuler_mm}, but exponential cost in the dimension remains \\cite{altschulernpbary, altschuler_mm_np}. \n\n\nIn parallel, a number of works on \\emph{sliced transport} \\cite{bonnottee} developed techniques for scalable transport, which (i) derive a closed form for a problem in a single dimension, and (ii) extend it into higher dimensions via random linear projections (slicing) and thereby inherit the complexity of the one-dimensional problem.\nThis strategy has been shown effective in the classical Wasserstein \\cite{bonnottee,bonneel, gensliced, distributionalsliced, maxsliced, orthsliced} and Gromov--Wasserstein \\cite{sliced_gw} settings between pairs of measures, but has not yet been applied to settings with more than two measures.\n\n\nIn this paper, we address this gap and propose \\emph{sliced multi-marginal transport}, providing a scalable analog of the multi-marginal Wasserstein distance.\nTo do so, we derive a closed-form expression for multi-marginal Wasserstein transport in one dimension, which lifts to a higher-dimensional analog via slicing. \nThis one-dimensional closed-form expression can be computed with a complexity of $\\mathcal{O}(PN\\log N)$, where $P$ is the number of measures and $N$ is the number of samples per measure. \nSliced multi-marginal Wasserstein ($\\mathcal{SMW}$) can be estimated by Monte Carlo in $\\mathcal{O}(KPN\\log N)$, where $K$ is the number of Monte Carlo samples. \n\nFurthermore, we study $\\mathcal{SMW}$'s theoretical properties.\nWe prove that (i) it is a generalized metric, whose associated topology is the topology of weak convergence, (ii) its sample complexity is dimension free, just like the sliced Wasserstein case involving two measures, and (iii) sliced multi-marginal transport is closely connected with the problem of barycentric averaging under the sliced Wasserstein metric. \n% Furthermore, we discuss projection complexity, and inequalities that relate sliced multi-marginal optimal transport with the Wasserstein distance between the marginals. \n%\nWe also showcase applications, where we focus on multi-task learning on probability spaces, where sharing knowledge across tasks can be beneficial and sliced multi-marginal Wasserstein can be used as a regularizer between task-specific models. \nWe demonstrate this on a multi-task density estimation problem, where individual estimation tasks are corrupted and shared structure is needed to solve the problem, as well as a reinforcement learning problem, where certain agents receive no reward and must instead learn from other agents to solve their given task.\n\n\n\\section{Background}\n\n\\label{sec:background}\n\nMulti-marginal optimal transport \\cite{gangbo} is a class of optimization problems for comparing multiple measures $\\mu_1,\\ldots,\\mu_P \\in \\mathcal{M}(\\R^d)$, all supported on the metric space $(\\R^d,  || \\cdot||_2)$. \nThe most common such problem is computing the multi-marginal Wasserstein distance, defined as\n\\[\n\\label{eq:multi_marginal_w}\n\\mathcal{MW}^2(\\mu_1,\\ldots,\\mu_P)=\\min_{\\pi \\in \\Pi(\\mu_1,\\ldots, \\mu_P)} \\int_{(\\mathbb{R}^d)^P}  c(x_1,\\ldots,x_P) \\, d\\pi(x_1,\\ldots,x_P),\n\\]\n\nwhere $c:\\mathbb{R}^d \\times\\ldots\\times \\mathbb{R}^d \\to \\mathbb{R}$ is a cost function and $\\Pi(\\mu_1,\\ldots, \\mu_P)$ is the set of probability measures in $\\mathcal{M}((\\mathbb{R}^d)^P)$ with marginals $\\mu_1, \\ldots, \\mu_P$.\nWe focus on the barycentric cost of \\textcite{gangbo, journals/siamma/AguehC11}, given by\n\\[\nc(x_1,\\ldots,x_P) = \\sum_{p=1}^P \\beta_p \\Big\\Vert  x_p - \\sum_{j=1}^P\\beta_j x_j\\Big\\Vert ^2,\n\\quad\\beta_1,\\ldots,\\beta_P \\geq 0, \\quad \\sum_{p=1}^P \\beta_p = 1\n.\n\\]\nThis cost was originally motivated from an economics-inspired perspective, but is also often preferable because it leads to connections with barycentric averaging \\cite{journals/siamma/AguehC11}, giving it a simple interpretation.\nIt also recovers the Wasserstein distance with squared $2$-Euclidean cost in the case $P=2$ (up to constants), referred to as $\\mathcal{W}$.\nAlgorithms for estimating \\eqref{eq:multi_marginal_w} from a set of samples  scale exponentially with the number of measures $P$ and/or the dimension $d$ of the ground space  \\cite{altschuler_mm, altschulernpbary, benamou:hal-01096124}.\n\n$\\mathcal{MW}$ is useful in multi-task settings for regularizing measures $\\mu_1,\\ldots, \\mu_P$ by adding $\\mathcal{MW}(\\mu_1,\\ldots, \\mu_P)$ to a multi-task loss. \nIt can also be used in a setting, where we aim for a model output $\\mu$ to be close to a given set of measures $\\nu_1,\\ldots, \\nu_P$, which can be done by introducing a loss of the form $\\mathcal{MW}(\\mu, \\nu_1,\\ldots, \\nu_P)$ and minimizing it with respect to $\\mu$.\n\n\n% \\begin{center}\n% \\begin{tabular}{llll}\n% Method (incl. reference) & Computational complexity & Comments\\\\\n% \\end{tabular}\n% \\end{center}\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[height=3cm]{pictures/diagrams/diagram_uniform.pdf}\n\t\\hspace{5mm}\n\t\\includegraphics[height=3cm]{pictures/diagrams/diagram_alignment.pdf}\n\t% \\includegraphics[width=\\hsize]{images/diagrams/sketch}\n\t\\caption{Illustration of the optimal coupling's structure on $\\R$ between discrete measures $\\mu_1, \\mu_2$ and $\\mu_3$. Points are samples of each measures, with weights next to them.  Left: histogram of measures (horizontal); joint samples are obtained by sampling a (black) line uniformly (drawn vertically), and picking points that are associated with the bin intersected by that line. Right: Corresponding triples of points that are aligned according to the coupling are linked by a pair of lines.}\n\t\\label{fig:illustr_mmot}\n\\end{figure}\n%\\subsection{Slicing Techniques for Scalability}\n\\textbf{Sliced transport.}  With the usual Euclidean-type cost structures, the Wasserstein distance between pairs of one-dimensional discrete measures can be computed efficiently using \\emph{sorting}  with $\\mathcal{O}(N \\log N)$ complexity.\nMore generally, we can consider the average distance between measures projected onto $\\mathbb{R}$ along random axis, which gives \\cite{bonnottee, bonneel}\n\\[\n\\mathcal{SW}^2(\\mu, \\nu) = \\int_{S_{d-1}}\\mathcal{W}^2\\big(M^{\\theta}_{\\#}(\\mu), M^{\\theta}_{\\#}(\\nu)\\big) \\, d\\Theta(\\theta),\n\\]\nwhere $M^{\\theta}(x) = x^T \\theta$, $(.)_\\#$ denotes the push-forward of measures, and $\\Theta$ is the uniform distribution on the unit sphere $S_{d-1}$. We sample from $M^{\\theta}_{\\#}(\\mu)$ by sampling from $\\mu$ and  projecting onto $\\theta$.\n\n\nA fundamental result by \\textcite{bonnottee} is that $\\mathcal{SW}$ is a metric that metrizes the topology of weak convergence---the \\emph{exact same} topology as $\\mathcal{W}$.\n$\\mathcal{SW}$ can be estimated via Monte Carlo and preserves the computational complexity of estimating $\\mathcal{W}$ on $\\R$, which is $\\mathcal{O}(N\\log N)$.\nOwing to the Monte Carlo nature, the sample complexity of $\\mathcal{SW}$ is dimension free \\cite{bonnottee, topstatprop}, in contrast with the exponential dependency of the Wasserstein distance on dimension.\nThe combination of good computational and statistical properties makes $\\mathcal{SW}$ an attractive choice for  minimization problems on measure spaces, including generative modeling and imitation learning \\cite{maxsliced, Dadashi2020PrimalWI}.\nThis immediately raises the question whether $\\mathcal{SW}$ extends to the multi-marginal case so that it preserves its key appealing properties.\n\n\n\\subsection{Sliced Multi-Marginal Wasserstein Distance}\n\nTo define the sliced multi-marginal Wasserstein distance, we average the expressions given in \\eqref{eq:mmwass_closed} along  one-dimensional random projections, which gives\n\\[\n\\label{eq:smmwass}\n\\mathcal{SMW}^2(\\mu_1,\\ldots,\\mu_P) = \\int_{S_{d-1}} \\int_{0}^1 \\sum_{p=1}^{P} \\beta_p\\Big| C_{\\mu_p^{\\theta}}^{-1}(x)-\\sum_{j=1}^P \\beta_j   C_{\\mu_j^{\\theta}}^{-1}(x) \\Big|^2 \\, dx \\, d\\Theta(\\theta),\n\\]\nwhere $ \\mu_j^{\\theta} = M^{\\theta}_{\\#} (\\mu_j)$ for $ j=1,\\ldots,P$.\n$\\mathcal{SMW}$ in \\eqref{eq:smmwass} can be estimated via Monte Carlo in $O(KPN\\log N)$, where $K$ is the number of Monte Carlo samples (projections). \n\n\\paragraph{Topological properties}\nWe now study $\\mathcal{SMW}$'s  topological properties. We first show that  $\\mathcal{SMW}$  is the weighted mean of sliced Wasserstein distances between pairs of measures.\n\n\\begin{prop}\n\tLet $\\mu_1,\\dots,\\mu_P \\in \\mathcal{M}(\\mathbb{R}^d)$. We have that\n\t\\[\n\t\\mathcal{SMW}^2(\\mu_1, \\ldots, \\mu_P)  = \\frac{1}{2} \\sum_{i,j=1}^P \\beta_i \\beta_j \\mathcal{SW}^2(\\mu_i,\\mu_j)\n\t.\n\t\\label{eq:meansliced}\n\t\\] \n\t\\label{prop:meansliced}\n\\end{prop}\n\nProposition \\ref{prop:meansliced} is useful in deriving statistical and topological properties of $\\mathcal{SMW}$. It is however more efficient to estimate it via our closed-form formula for multi-marginal transport -- see \\eqref{eq:smmwass}. This leads to a computational complexity of $O(KPN\\log N)$, whereas naively implementing \\eqref{eq:meansliced} scales in $\\mathcal{O}(KP^2N\\log N)$. \n%\nFurthermore, as the sliced-Wasserstein metric is upper-bounded by the Wasserstein \\cite{bonnottee}, an immediate consequence of Proposition \\ref{prop:meansliced} is that \n\\[\n\\mathcal{SMW}^2(\\mu_1, \\ldots, \\mu_P) \\stackrel{\\eqref{eq:meansliced}}{=} \\frac{1}{2} \\sum_{i,j=1}^P\\beta_i \\beta_j \\mathcal{SW}^2(\\mu_i,\\mu_j) \\leq \\frac{1}{2} \\sum_{i,j=1}^P \\beta_i \\beta_j\\mathcal{W}^2(\\mu_i,\\mu_j).\n\\] \nThis shows that $\\mathcal{SMW}$ gives rise to the topology of weak convergence---one of the key properties that made $\\mathcal{SW}$ an attractive choice in the first place. \n% \\paragraph{Metric properties}\nWe now study metric properties of $\\mathcal{SMW}$.\n\n\\begin{prop}\n\t$\\mathcal{SMW}$ is a generalized metric.\n\t\\label{prop:metricprop}\n\\end{prop}\n\n\nIn particular, this means that $\\mathcal{SMW}$ is (i) non-negative, (ii) zero if and only if all measures are identical, (iii) permutation-equivariant, and (iv) satisfies a generalized triangle inequality involving multiple measures. Hence, $\\mathcal{SMW}$ is well-behaved topologically-wise as it is a generalized metric inducing weak convergence. We continue by studying $\\mathcal{SMW}$'s statistical properties.\n\n\\paragraph{Statistical Properties}\nIn the following proposition, we assess the impact of the number of samples and random projections used to estimate $\\mathcal{SMW}$.\n\n\\begin{prop}\n\t\\label{prop:samplecomplexity}\n\tIf $\\mu_1,\\ldots,\\mu_P \\in \\mathcal{M}(\\R^d)$, and assuming $\\mathcal{W}^2$ has sample complexity $\\rho(N)$ on $\\R$, then,\n\t\\[ &\\quad \\E [\\mathcal{SMW}^2(\\mu_1,\\ldots,\\mu_P) - \\mathcal{SMW}^2(\\h{\\mu}_1,\\ldots,\\h{\\mu}_P)]^2 \n\t\\leq\\frac{1}{2}\\rho(N),\n\t\\]\n\twhere $\\h{\\mu}_p$ refers to empirical measures with $N$ samples.\n\\end{prop}\n\n% \\begin{proof}\n% Appendix \\ref{sec:complexitiesproofs}.\n% \\end{proof}\n\nProposition \\ref{prop:samples} shows that the sample complexity of $\\mathcal{SMW}$ is dimension-free---this stands in contrast to the sample complexity of the multi-marginal Wasserstein, which is exponential in the dimension.\n%\nIn practice, we use Monte Carlo sampling to compute $\\mathcal{SMW}$, which introduces additional error.\nTo understand this error, we examine $\\mathcal{SMW}$'s projection complexity.\n\n\\begin{proposition}\n\t\\label{prop:projectioncomplexity}\n\tLet $\\mu_1,\\ldots,\\mu_P \\in \\mathcal{M}(\\R^d)$, and define $\\widebar{\\mathcal{SMW}}$ the approximation obtained by uniformly picking $L$ projections on $S_{d-1}$, then\n\t\\[ \n\t\\E\\left[ \\widebar{\\mathcal{SMW}}^2(\\mu_1,\\ldots,\\mu_P) - \\mathcal{SMW}^2(\\mu_1,\\ldots,\\mu_P)\\right]^2\n\t\\leq \n\tL^{-1/2}\\Var_{\\v{\\theta}}\\Big[\\mathcal{MW}^2\\big(\\mu_1^{\\v{\\theta}},\\ldots,\\mu_P^{\\v{\\theta}})\\Big],%\\int_{S_{d-1}} \\Big\\{\\mathcal{MW}^2\\big(M_{\\theta\\#}(\\mu_1),\\ldots,M_{\\theta\\#}(\\mu_P)\\big)-\\delta \\Big\\}^2d\\Theta(\\theta),\n\t\\]\n\twhere  $\\v{\\theta}$ follows the uniform distribution on $S_{d-1}$ and $\\mu_p^{\\v{\\theta}} = M_{\\#}^{\\v{\\theta}}(\\mu_p)$.\n\t\n\\end{proposition}\n\n% \\begin{proof}\n% Appendix \\ref{sec:complexitiesproofs}.\n% \\end{proof}\n\nThis shows that the quality of Monte Carlo estimates of $\\mathcal{SMW}$ is controlled by number of projections and the variance of evaluations of the base multi-marginal Wasserstein in 1D.\n", "meta": {"hexsha": "016c488a837966be72ee4492aed5f97b51a58a21", "size": 14901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chap5(pjd).tex", "max_stars_repo_name": "pitcany/dissertation", "max_stars_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chap5(pjd).tex", "max_issues_repo_name": "pitcany/dissertation", "max_issues_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chap5(pjd).tex", "max_forks_repo_name": "pitcany/dissertation", "max_forks_repo_head_hexsha": "0ee81ccdf4a0fc193cc347da9a44f08f892b9a19", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 83.7134831461, "max_line_length": 503, "alphanum_fraction": 0.7618280652, "num_tokens": 4166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7659830547991997}}
{"text": "\n\\subsection{Trial division}\n\nWe have x\n\nDivide by numbers between 2 and x\n\nOnly need to go to sqrt x\n\nDon't need to divide by even numbers other than 2\n\n\nalgorithm for checking if number is a prime\n\nloop up dividing number from 2\n\nif divides, add factor list and divide target number by that\n\nstop when i reaches number\n\neg for 45\n\ndivide 2? no\n\ndivide 3? yes :> 15\n\ndivide 3? yes :> 5\n\ndivide 4? no\n\ndivide 5? yes :> 1\n\n6>1 so stop\n\nnumber is prime if list just contains target\n\ndon't have to worry about including non primes in list, as will already have divded by that amount\n", "meta": {"hexsha": "9f5c55f8e89e8be0b2d1ef1468fd71133e2b4876", "size": 580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/factorise/01-01-trial.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-01-trial.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-01-trial.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.2631578947, "max_line_length": 98, "alphanum_fraction": 0.7413793103, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942119105696, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7659643749705074}}
{"text": "\\section{Data space, feature space and relevant mappings}\\label{sec:spaces}\nGiven a data\n\\begin{equation}\n\t\\label{data-f}\n\tf \\in \\mathbb{R}^{m \\times n \\times c}, \n\t\\quad \\text{or}\\quad [f]_i \\in\n\t\\mathbb{R}^{m\\times n}, \\quad i = 1:c,\n\\end{equation}\nwhere $m\\times n$ is called the spatial dimension and $c$ is the \nchannel dimension.\n\nFor the given data $f$ in \\eqref{data-f}, we look for some\nfeature vector, denoted by $u$,  associated with $f$:\n\\begin{equation}\n\t\\label{u}\n\tu \\in \\mathbb{R}^{m \\times n \\times h}.\n\\end{equation}\nWe make an assumption that the data $f$ and feature $u$ are related by a mapping \n(which can be either linear or nonlinear)\n\\begin{equation}\n\t\\label{u}\n\tA:  \\mathbb{R}^{m \\times n \\times h}\\mapsto \\mathbb{R}^{m \\times n \\times c}, \n\\end{equation}\nso that\n\\begin{equation}\n\t\\label{Auf}\n\tA(u)=f. \n\\end{equation}\nA mapping \n\\begin{equation*}\n\tB : \\mathbb{R}^{m\\times n\\times c} \\mapsto \\mathbb{R}^{m \\times n\\times h},\n\\end{equation*}\nis called a feature extractor if $B \\approx A^{-1}$ and \n\\begin{equation}\\label{vBf}\n\tv = B(f),\n\\end{equation}\nis such that $v \\approx u$.\n\nThe data-feature relationship \\eqref{Auf} or \\eqref{vBf} is not\nunique.   Different relationships give rise to different features. \nWe can view the data-feature relationship given in \\eqref{Auf}\nas a model that we propose.  Here the mapping $A$, which can be either\nlinear or nonlinear, is unknown and needs to be trained.  \n\n\n\\subsection{Some linear and nonlinear mappings and extractors}\nA data-feature map $A$ and feacture extractor $B$ can be either\nlinear or nonlinear.   The nonlinearity can be obtained from\nappropriate application of an activation function\n\\begin{equation}\n\t\\label{act}\n\t\\sigma: \\mathbb{R} \\to \\mathbb{R} .\n\\end{equation}\nIn this paper, we mainly consider a special activation function, known \nas the {\\it rectified linear unit} (ReLU), which is defined by\n\\begin{equation}\n\t\\label{relu}\n\t\\sigma(x)= {\\rm ReLu}(x) :=\\max(0,x), \\quad x\\in\\mathbb{R}. \n\\end{equation}\nBy applying the function to each component, we can extend this\n\\begin{equation}\n\t\\label{vector-act}\n\t\\sigma:\\mathbb R^{m\\times n\\times c}\\mapsto \\mathbb R^{m\\times n\\times c}.  \n\\end{equation}\n\n\nA linear data-feature mapping can simply given by a convolution as in \\eqref{con1}:\n\\begin{equation}\n\t\\label{linearA}\n\tA(f)=A\\ast f\n\\end{equation}\nA nonlinear mapping can be given by compositions of convolution and\nactivation functions:\n\\begin{equation}\n\t\\label{nonlinearA}\n\tA=\\xi\\circ\\sigma\\circ\\eta ,\n\\end{equation}\n\nand \n\\begin{equation}\n\t\\label{extractor}\n\tB=\\sigma\\circ \\gamma \\circ\\sigma  .\n\\end{equation}\nHere $\\xi$, $\\eta$ and $\\gamma$ are all \nappropriate convolution mappings.\n", "meta": {"hexsha": "dfb7e9ba8f225df1a520eaa657efdfb888e9dadd", "size": 2678, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_datafeature.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_datafeature.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_datafeature.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.1395348837, "max_line_length": 83, "alphanum_fraction": 0.715085885, "num_tokens": 865, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625107731764, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7658383599630164}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage[legalpaper, portrait, margin=1in]{geometry}\n\n\\title{Mathinity Factorial Problem}\n\n\\author{Shreenabh Agrawal}\n\n\\date{\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\section{Question}\n$$Let \\: S_{n}=1 !+2 !+\\ldots+n !$$\nFind all values of $n$ such that $S_{n}$ is a perfect square and prove that these are the only ones.\n\\section{Solution}\nLet us start by calculating some values of this summation:\n$$\\begin{aligned}\nS_{1} &=1 ! \\\\\n&=1 \\\\\nS_{2} &=1 !+2 ! \\\\\n&=1+2 \\\\\n&=3 \\\\\nS_{3} &=1 !+2 !+3 ! \\\\\n&=1+2+6 \\\\\n&=9 \\\\\nS_{4} &=1 !+2 !+3 !+4 !\\\\\n&=1+2+6+24 \\\\\n&=33 \n\\end{aligned}$$\nHere, we can easily find the trivial solutions $$n = \\: 1 \\: \\& \\: n = \\: 3$$\nNext, from $S_5$ onwards, there will always be multiples of 10 that would be added to $S_4$ (because $5!$ and consequently all larger factorials have 10 as a factor). Hence, we can write as (for $n > 4$)\n\n$$\\begin{aligned}\nS_{n} & \\equiv\\left(S_{4}+10 k\\right) \\bmod 10 \\\\\n& \\equiv S_{4} \\bmod 10 \\\\\n& \\equiv 3 \\bmod 10\n\\end{aligned}$$\nWhich as we know can never be perfect squares. Thus our only answers are:\n\n$$\\boxed{n = 1, \\: 3}$$\n\\end{document}\n", "meta": {"hexsha": "d130c643e17665f53546a84a56c95df45c1a6baf", "size": 1201, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Number theory/Mathinity's questions/Congruence Factorial.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/Mathinity's questions/Congruence Factorial.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/Mathinity's questions/Congruence Factorial.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": 25.5531914894, "max_line_length": 203, "alphanum_fraction": 0.6436303081, "num_tokens": 445, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.8558511524823263, "lm_q1q2_score": 0.7658066005953075}}
{"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 n!$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} n!\\\\\r\n&= \\infty\r\n\\end{align*}\r\nSince $\\lim_{n \\to \\infty} a_n$ does not exist (infinity is not a number), by the Test for Divergence, the series $\\displaystyle \\sum_{n=1}^\\infty n!$ diverges.\r\n\r\n\\subsection*{Solution 2}\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| \\frac{(n+1)!}{n!}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\frac{(n+1) \\cdot n!}{n!}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| n+1 \\right|\\\\\r\n&= \\lim_{n \\to \\infty} (n+1)\\\\\r\n&= \\infty.\r\n\\end{align*}\r\nSince $L = \\infty$, by the Ratio Test, the series $\\displaystyle \\sum_{n=1}^\\infty n!$ diverges.\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": "dd6767fd06e6d5efe8fce0fd82439a02597be81e", "size": 1724, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/m4.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/m4.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/m4.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": 27.8064516129, "max_line_length": 161, "alphanum_fraction": 0.6107888631, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894745194281, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7658065947718012}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\left( \\frac{1}{\\ln n} - \\frac{1}{\\ln(n+1)} \\right)$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\r\n\\subsection*{Solution}\r\n\r\n$\\displaystyle \\sum_{n=2}^\\infty \\left( \\frac{1}{\\ln n} - \\frac{1}{\\ln(n+1)} \\right)$ appears to be a telescoping series. We look at the sequence of partial sums $s_n$, and note that after cancellation\\footnote{This cancellation is much easier to describe in handwritten work than it is in typewritten work.... sorry!} we have\r\n\\[ s_n = \\frac{1}{\\ln 2} - \\frac{1}{\\ln(n+1)}\\]\r\n\r\nThen\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} s_n\r\n&= \\lim_{n \\to \\infty} \\left(\\frac{1}{\\ln 2} - \\frac{1}{\\ln(n+1)}\\right)\\\\\r\n&= \\frac{1}{\\ln 2} - 0\\\\\r\n&= \\frac{1}{\\ln 2}.\r\n\\end{align*}\r\n{\\color{red} It is tempting to get confused here with the Test for Divergence, but note that we found the limit of the sequence of partial sums.} So, (by definition), the series  $\\displaystyle \\sum_{n=2}^\\infty \\left( \\frac{1}{\\ln n} - \\frac{1}{\\ln(n+1)}\\right)$ converges, and we furthermore know that the sum is $\\frac{1}{\\ln 2}$. Recall that it is unusual that we get to know the value of a convergent series.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=2}^\\infty \\left( \\frac{1}{\\ln n} - \\frac{1}{\\ln(n+1)} \\right)$ converges absolutely.\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": "bf472bd691e3b2154ed10a1c1eae2cc8e1447cc2", "size": 2001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/e4.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/e4.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/e4.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": 41.6875, "max_line_length": 414, "alphanum_fraction": 0.6486756622, "num_tokens": 689, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310355, "lm_q2_score": 0.888758803068433, "lm_q1q2_score": 0.7656996678116481}}
{"text": "\\section*{Chapter 5: The Emergence of Modern Number Theory}\n\n\\paragraph{Exercise 5.1}\nProve that if $n > 4$ is composite, then $(n-1)!$ is a multiple of $n$.\n\n\\begin{proof}\nLet $n > 4$ be a composite integer with prime factorization\n$n = p_1^{\\alpha_1} \\dots p_k^{\\alpha_k}$. First note that, if $d$ is a \nproper divisor of $n$, then $\\Divides{d}{(n-1)!}$. Indeed, $d \\leq n-1$,\nand so $(n-1)! = (n-1) \\cdot (n-2) \\cdots d \\cdot (d-1) \\cdots 1$. \\\\\n\nSuppose that $k > 1$. Then, $\\Divides{p_i^{\\alpha_i}}{(n-1)!}$,\n$1 \\leq i \\leq k$. Since $p_1^{\\alpha_1}, \\dots, p_k^{\\alpha_k}$ are\npairwise coprime, we have that\n$\\Divides{n = p_1^{\\alpha_1} \\dots p_k^{\\alpha_k}}{(n-1)!}$.\\\\\n\nNow, suppose that $k = 1$. Since\n$n$ is composite and $n = p_1^{\\alpha_1} > 4$, then either $p_1 > 2$ or\notherwise $\\alpha_1 > 2$. In the latter case, \n$(n-1)! = (n-1) \\cdot (n-2) \\cdots p_1^{\\alpha_1 - 1} \\cdots p_1 \\cdots 1$,\nand so $\\Divides{n = p_1^{\\alpha_1}}{(n-1)!}$. Otherwise, if $\\alpha_1 = 2$,\n$2 \\cdot p_1 < p_1^2 = n$, and so\n$(n-1)! = (n-1) \\cdot (n-2) \\cdots 2p_1 \\cdots p_1 \\cdots 1$, which means \nthat $\\Divides{n = p_1^{2}}{(n-1)!}$.\n\\end{proof}\n", "meta": {"hexsha": "b27ae76780658c574563f2f7def7fedf1ce814e4", "size": 1142, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter5.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter5.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter5.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 43.9230769231, "max_line_length": 76, "alphanum_fraction": 0.6024518389, "num_tokens": 507, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312213841788, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7656763373111518}}
{"text": "\n\\subsection{Difference from Method Of Moments (MOM)}\n\nMore conditions than data.\n\n\\subsection{Generalised Method of Moments (GMM)}\n\nWe have a function on the output and a parameter:\n\n\\(g(y, \\theta )\\)\n\nA moment condition is that the expectation of such a function is \\(0\\).\n\n\\(m(\\theta )=E[g(y, \\theta )]=0\\)\n\nTo do GMM, we estimate this using:\n\n\\(\\hat m(\\theta )=\\dfrac{1}{n}\\sum_ig(y_i, \\theta )\\)\n\nWe define:\n\n\\(\\Omega = E[g(y, \\theta )g(y, \\theta)^T]\\)\n\n\\(G=E[\\Delta_\\theta g(y, \\theta)]\\)\n\nAnd then minimise the norm:\n\n\\(||\\hat m(\\theta )||^2_W=\\hat m(\\theta )^TW\\hat m(\\theta )\\)\n\nWhere \\(W\\) is a positive definite matrix for the norm.\n\n\\(\\Omega ^{-1}\\) is most efficient. But we don't know this. It depends on \\(\\theta \\).\n\nWe can estimate it if IID:\n\n\\(\\hat W(\\hat \\theta )= (\\dfrac{1}{n}\\sum_i g(y, \\hat \\theta)g(y, \\hat \\theta)^T)^{-1}\\)\n\n\\subsection{Two-step feasible GMM}\n\nEstimate using \\(\\mathbf W=\\mathbf I\\)\n\nConsistent, but not efficient.\n\n\\subsection{Moment conditions}\n\nOLS:\n\n\\(E[x(y-x\\theta)]=0\\)\n\nWLS\n\n\\(E[x(y-x\\theta)/\\sigma^(x)]=0\\)\n\nIV\n\n\\(E[z(y-x\\theta)]=0\\)\n\nMLE\n\n\\(E[\\Delta_\\theta \\ln f(x, \\theta)]=0\\)\n\n\n\n\n\n\n\n\n\\subsection{New GMM}\n\n\n\\(m(\\theta_0)=E[g(\\mathbf x_i, \\theta_0]\\)\n\nWe replace this with sample moment\n\n\\(\\hat m(\\theta)=\\frac{1}{n}\\sum_ig(\\mathbf x_i, \\theta)\\)\n\nWe have the \"score\"\n\n\\(\\nabla_\\theta g(\\mathbf x_i, \\theta_0)\\)\n\nInformation\n\n\\(G=E[\\nabla_\\theta g(\\mathbf x_i, \\theta_0)]\\)\n\nVariance-covariance loss matrix\n\n\\(\\Omega =E[g(\\mathbf x_i, \\theta_0)g(\\mathbf x_i, \\theta_0)^T]\\)\n\nWe want to minimise moment loss\n\n\\(||\\hat m(\\theta)||^2_W=\\hat m(\\theta )^TW\\hat m(\\theta)\\)\n\n\\(\\hat \\theta = argmin_\\theta (\\frac{1}{n}\\sum_ig(\\mathbf x_i, \\theta))^T\\hat W(\\frac{1}{n}\\sum_ig(\\mathbf x_i, \\theta))\\)\n\n\\subsection{Asymptotic}\n\nCLT means normal.\n\nThey are consistent IF moment condition is true.\n\nThere is an explicit formula for variance.\n\n\n\\(\\sqrt n (\\hat \\theta -\\theta_0)\\rightarrow^d N[0, (G^TWG)^{-1}G^TW\\Omega W^TG(G^TW^TG)^{-1}]\\)\n\nIf we choose \\(W\\propto \\Omega^{-1}\\) then:\n\n\\(\\sqrt n (\\hat \\theta -\\theta_0)\\rightarrow^d N[0, (G^T\\Omega^{-1} G)^{-1}]\\)\n\nProblem: we need to estimate \\(\\Omega \\) and \\(G\\).\n\n\\(\\Omega \\): estimate from sample. allows us to choose estimator, but still leaves variance unidentified.\n\nDo the above from OLS? This is where robust etc stuff comes from\n\nIf it is specified. Moment conditions are equal to the number of moments, then \\(W\\) doesn't matter. This is normal Method of Moments.\n\nEstimating the weighting matrix\n\n\\subsection{Iterated GMM}\n\n\\subsection{Moment-covariance matrix}\n\n\\subsection{Bias and variance of the GMM estimator}\n\npage on Bias and variance of the GMM estimator (cluster assumption should be part of moment condition?) part of later calculation of weighting?\n\nCan do robust, hac, clustering as part of GMM too.\n\n", "meta": {"hexsha": "8adf9b4e334ce4339257edbf8876b2f411e88154", "size": 2820, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/GMM/01-01-GMM.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/GMM/01-01-GMM.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/GMM/01-01-GMM.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.5267175573, "max_line_length": 143, "alphanum_fraction": 0.6687943262, "num_tokens": 916, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7656763326358564}}
{"text": "\\newpage\t\t\r\n\t\\section*{Catalan sequence}\r\n\t\\textbf{Task}\\\\\r\n\tLet $c_n$ be the Catalan sequence. Find the limit $\\lim\\limits_{n \\to \\infty} \\frac{c_{n+1}}{c_{n}}$\\\\\r\n\t\\\\\r\n\t\\textbf{Solution}\\\\\r\n\t\\begin{gather*}\r\n\t\tc_n = \\frac{1}{n+1} {{2n}\\choose{n}}\r\n\t\\end{gather*}\r\n\tThen\r\n\t\\begin{gather*}\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{c_{n+1}}{c_{n}} = \r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{\\frac{1}{n+2} {{2n+2}\\choose{n+1}}}{\\frac{1}{n+1} {{2n}\\choose{n}}} = \\\\ \\\\\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{\\frac{1}{n+2} \\frac{(2n+2)!}{(n+1)!((2n+2) - (n+1))!}}{\\frac{1}{n+1} \\frac{(2n)!}{n!((2n) - (n))!}} =  \r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{\\frac{1}{n+2} \\frac{(2n+2)!}{(n+1)!(n+1)!}}{\\frac{1}{n+1} \\frac{(2n)!}{n!n!}} = \\\\ \\\\\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{(n+1) \\frac{(2n+2)!}{(n+1)!(n+1)!}}{(n+2) \\frac{(2n)!}{n!n!}} =\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{(n+1) (2n+2)!n!n!}{(n+2) (2n)!(n+1)!(n+1)!} = \\\\ \\\\\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{(n+1)(2n+1)(2n+2)}{(n+2)(n+1)(n+1)} = \r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{2(n+1)(2n+1)}{(n+2)(n+1)} = \\\\ \\\\\r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{4n+2}{n+2} = \r\n\t\t\\lim\\limits_{n \\to \\infty} \\frac{4+\\frac{2}{n}}{1+\\frac{2}{n}} = 4\r\n\t\\end{gather*}", "meta": {"hexsha": "9a36746604910c9018b36da9ab411e2c1b54f97b", "size": 1187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/1st term/Discrete Math/Spr_Mid/Body/P1.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/P1.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/P1.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": 53.9545454545, "max_line_length": 139, "alphanum_fraction": 0.5029486099, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253255, "lm_q2_score": 0.8757869948899665, "lm_q1q2_score": 0.7655054808323336}}
{"text": "\\chapter{Non-dimensionalisation}\\label{Non-dimensionalisation}\n\\begin{aquote}{Wild Thing. J. Bazell 2013.}\n\\textit{In metric, one milliliter of water occupies one cubic centimeter, weighs one gram, and requires one calorie of energy to heat up by one degree centigrade — which is 1 percent of the difference between its freezing point and its boiling point. An amount of hydrogen weighing the same amount has exactly one mole of atoms in it. Whereas in the [imperial] system, the answer to ``How much energy does it take to boil a room-temperature gallon of water?\" is ``Go fuck yourself'', because you can't directly relate any of those quantities.}\n\\end{aquote}\n\nThus, far we have been fairly lax about defining the quantities we have actually been measuring. Further, once we have specified what the quantity actually is, what units are we using to measure the quantity. For example, if we are measuring distance are we doing it in mm, miles or light-years? Equally, is time measured in seconds, minutes or hours? Finally, constitutive laws often introduce parameters that are not quantified accurately, or alternatively, we may be interested in understanding how a solution depends on a particular parameter as it is varied. \n\nThe Law of Mass Action, in particular, could be thought to be a troublesome law as it introduces a rate parameter for each reaction equation that is considered. For example, if a system of ODEs is defined by a set of non-linear equations it is highly unlikely to be solvable in closed form. Thus, if there are a large number of parameters in the system, it becomes very difficult to predict how varying a single parameter (or group of parameters) will influence the solution.\n\nHowever, we have already seen cases in which we do not need to consider parameters individually, as specific groups of the parameters are seen to act in the same way. For example, in the case of the spring pendulum (see \\sect{Pendulums_section}), we saw that the frequency of oscillation depended on $\\sqrt{k/m}$. Thus, stiffening the spring (increasing $k$) has the same effect on the solution as decreasing the mass (decreasing $m$), \\ie they both increase the frequency of the oscillations. Equally, in the example of a zombie infection (see example \\ref{Zombies}), the parameters of interest were not $a$, $b$ or $c$, but rather $\\alpha=b+c$ and $\\beta=c-a$.\n\nIn this chapter we introduce a technique, called non-dimensionalisation, that will benefit us in two ways. Firstly, it allow us to brush away worries about dealing with units and, secondly, it will allow us to reduce the number of effective parameters in our system. Specifically, we will be able to define parameter groupings that will influence the final result in the same way.\n\n\\section{The central idea}\nTo non-dimensionalise a system of equations, we have the following rules:\n\\begin{enumerate}\n\\item Identify all the variables;\n\\item Replace each variable with a quantity scaled relative to a characteristic unit of measure (to be determined);\n\\item Choose the definition of the characteristic unit for each variable;\\label{Choose}\n\\item Rewrite the system of equations in terms of the new dimensionless quantities.\n\\end{enumerate}\nWe note three particular points about these rules. Firstly, the theory behind non-dimensionalisation is straight forward. Namely, we substitute scaled variables into an equation system and massage the equations until we have rearranged the system to produce the desired outcome. However, in practice the difficulty of the technique lies in the algebraic manipulation; it is very easy for the terms to become lost during the manipulation. Thus, care must be taken during the algebraic manipulation stage.\n\nSecondly, you will notice the word `choose' in point \\ref{Choose}. This means that it possible to construct many different non-dimensionalised systems from the same system of equations, \\ie non-dimensionalisation is non-unique. We usually choose the characteristic unit of each variable to either emphasise one of the terms in a system or to remove as many parameters as possible.\n\nFinally, this technique is hard to demonstrate in generality. It is much better to consider a number of system and see how the technique works in action. Thus, what follows will be a select number of examples, which along with your problem sheets should give you a good basis in the theory. However, do not think that these are all the examples you could face.\n\nIt should be noted that there is little consistency in nomenclature across book when considering the separation of variables into their dimensional and non-dimensional components. Thus, always be clear in your definitions.\n\n\\subsection{Examples of non-dimensionalisation through substitution of variables}\\label{Examples of non-dimensionalisation through substitution of variables}\n\\begin{example}[frametitle=Substituting variables]\n\\begin{itemize}\n\\item Consider the equation for exponential growth,\n\\bb\n\\dot{u}=ru, \\quad u(0)=u_0.\\label{Non-dim_1}\n\\ee\n\\COL{The variables in \\eqn{Non-dim_1} are $u$ and $t$. We rewrite them as $u=[u]u'$ and $t=[t]t'$, where $[u]$ and $[t]$ are the dimensional scales and $u'$ and $t'$ are the non-dimensional variables. We are free to define the values of $[u]$ and $[t]$ as we please. It is our job to choose appropriate definitions that simplify \\eqn{Non-dim_1}. Critically, although we are free to choose the value of $[u]$ and $[t]$ the values must have consistent units. Namely, $[t]$ must have units of time and $[u]$ must have units of density.\n\nWe substitute the expanded variables into \\eqn{Non-dim_1} and rearrange to produce\n\\bb\n\\frac{\\rd u'}{\\rd t'}=[t]ru', \\quad u(0)=\\frac{u_0}{[u]}.\\nonumber\n\\ee\nHence, we see that if we choose $[t]=1/r$ and $[u]=u_0$ then \\eqn{Non-dim_1} simplifies to\n\\bb\n\\dot{u}=u, \\quad u(0)=1,\\nonumber\n\\ee\nwhere we note that we have dropped the prime symbols, $'$, for notational convenience.\n\nFor mathematicians dropping primes is often done as the last step because we infrequently care about the actual values of the variables, rather we study the dynamics available in the equation. However, in any specific application we should be careful to remember that the variables we are dealing with are non-dimensional and that the solution is not complete until we `re-dimensionalise' the variables.}\n\n\\COL{In this example we see that the values of $r$ and $u_0$ in \\eqn{Non-dim_1} do not influence the dynamics of the simulation. Specifically, they only scale the time and initial condition.\n\nAlthough this was a fairly trivial example, a good way to check consistency of the answer at the end of the manipulation is to check that all of the dimensions agree. As mentioned $[t]$ should have units of time and $[u]$ should have units of density. We return to \\eqn{Non-dim_1} and consider the dimensions of each component.\n\nFor example, $\\dot{u}=\\rd u/ \\rd t$ has units of density/time. By equality, $ru$ must have units of density/time since $u$ has units of density then $r$ must have units of 1/time. Thus, \n\\bb\n\\textrm{dim}([t])=\\textrm{dim}(1/r)=\\textrm{time}.\\nonumber\n\\ee\nEqually, $[u]=u_0$ can trivially be seen to have the correct units of density.}\n\n\\item Consider the equation for logistic growth,\n\\bb\n\\dot{u}=ru\\l 1-\\frac{u}{K} \\r, \\quad u(0)=u_0.\\label{Non-dim_2}\n\\ee\n\\COL{Again, $u=[u]u'$ and $t= [t]t'$ can be substituted into \\eqn{Non-dim_2} to produce\n\\bb\n\\frac{\\rd u'}{\\rd t'}=[t]ru'\\l 1-\\frac{[u]}{K}u'\\r,\\quad u'(0)=\\frac{u_0}{[u]},\\nonumber\n\\ee\nfrom which we see that it would be wise to once again take $[t]=1/r$. Beyond this we see that we have a choice. Should we take $[u]=K$, or $[u]=u_0$? Both are valid non-dimensionalisations and either maybe be appropriate depending on the context of the problem. \n\nHere, we are going to take $[u]=K$ as we are interested in the dynamics of the system, rather than the initial condition. Thus, after dropping primes we see that we can non-dimensionalise \\eqn{Non-dim_2} to \n\\bb\n\\frac{\\rd u}{\\rd t}=u\\l 1-u\\r,\\quad u(0)=U_0,\\nonumber\n\\ee\nwhere $U_0=u_0/[u]=u_0/K$.\n\nIn this case the non-dimensionalisation demonstrates that the only parameter that the solution depends on is the initial conditions. Changing $r$ does not change the dynamics of the system, it only changes the time scale, since $r=1/[t]$. Equally, changing $K$ simply scales the size of the solution, as $u=Ku'$.}\n\n\\item Consider the following equations (the Schnakenberg kinetics)\n\\begin{align}\n&\\dot{u}=k_1-k_2u+k_3u^2v, \\quad u(0)=u_0,\\label{Non-dim_31}\\\\\n&\\dot{v}=k_4-k_3u^2v, \\quad v(0)=v_0.\\label{Non-dim_32}\n\\end{align}\n\\COL{This time we use the scales $u=[u]u'$, $v=[v]v'$, $t=[t]t'$ to derive\n\\begin{align}\n&\\frac{\\rd u'}{\\rd t'}=\\frac{[t]k_1}{[u]}-[t]k_2u'+[t]k_3[u][v]u'^2v', \\quad u'(0)=\\frac{u_0}{[u]},\\nonumber\\\\\n&\\frac{\\rd v'}{\\rd t'}=\\frac{[t]k_4}{[v]}-[t]k_3[u]^2u'^2v', \\quad v'(0)=\\frac{v_0}{[v]}.\\nonumber\n\\end{align}}\\COL{\nLots of potential choices for scale balances; how do we choose? In an exam you will be given the form of an equation to produce and your task will be to derive the corresponding scales. For example, suppose we wanted to convert \\eqns{Non-dim_31}{Non-dim_32} into\n\\begin{align}\n&\\frac{\\rd u'}{\\rd t'}=\\alpha-u'+u'^2v', \\quad u'(0)=u'_0\\nonumber\\\\\n&\\frac{\\rd v'}{\\rd t'}=\\beta-u'^2v', \\quad v'(0)=v'_0,\\nonumber\n\\end{align}\nthen we know that we would have to set\n\\bb\n1=[t]k_3[u][v]=[t]k_2=[t]k_3[u]^2.\\nonumber\n\\ee\nThus,\n\\begin{align}\n&[t]=\\frac{1}{k_2},\\nonumber\\\\\n&[u]=\\sqrt{\\frac{1}{[t]k_3}}=\\sqrt{\\frac{k_2}{k_3}},\\nonumber\\\\\n&[v]=[u]=\\sqrt{\\frac{k_2}{k_3}},\\nonumber\n\\end{align}\nwhich means that\n\\begin{align}\n\\alpha=\\frac{[t]k_1}{[u]}=\\frac{k_1}{k_2}\\sqrt{\\frac{k_3}{k_2}},\\nonumber\\\\\n\\beta=\\frac{[t]k_4}{[v]}=\\frac{k_4}{k_2}\\sqrt{\\frac{k_3}{k_2}},\\nonumber\\\\\nu'_0=\\frac{u_0}{[u]}=u_0\\sqrt{\\frac{k_3}{k_2}},\\nonumber\\\\\nv'_0=\\frac{v_0}{[v]}=v_0\\sqrt{\\frac{k_3}{k_2}}.\\nonumber\n\\end{align}\n\nFinally, we check the consistency of the scales. From \\eqns{Non-dim_31}{Non-dim_32} we infer that\n\\bb\n\\textrm{dim}(k_1)=\\frac{\\textrm{density}}{\\textrm{time}}, \\quad \\textrm{dim}(k_2)=\\frac{1}{\\textrm{time}}, \\quad \\textrm{dim}(k_3)=\\frac{1}{\\textrm{density}^2\\textrm{time}}, \\quad \\textrm{dim}(k_4)=\\frac{\\textrm{density}}{\\textrm{time}}.\\nonumber\n\\ee\nHence,\n\\bb\n\\textrm{dim}([u])=\\sqrt{\\frac{1/\\textrm{time}}{1/(\\textrm{density}^2\\textrm{time})}}=\\sqrt{\\textrm{density}^2}=\\textrm{density}.\n\\ee\nThe scales $[v]$ and $[t]$ can be checked similarly. We also need to ensure the the variables $\\alpha, \\beta, u'_0, v'_0$ are have no dimension. For example\n\\bb\n\\textrm{dim}(v'_0)=\\textrm{density}\\sqrt{\\frac{1/(\\textrm{density}^2\\textrm{time})}{1/\\textrm{time}}}=\\textrm{density}\\sqrt{\\frac{1}{\\textrm{density}^2}}=1.\n\\ee\nThe other variables can be checked similarly.}\n\\end{itemize}\n\\end{example}\n\n\\subsection{Examples of non-dimensionalisation through the arrow method}\nThe substitution method shown in \\sect{Examples of non-dimensionalisation through substitution of variables} will always work supposing that the algebra is manipulated correctly. However, the method can be cumbersome and slow. Moreover, because it involves lots of algebraic manipulations there are many chances to make a mistake.\n\nAn alternative method rests on using arrows to identify the desired balances. This can be much quicker as the initial stages do not require laborious substitution. However, we have to be more careful because not all balances that we can `draw' using the arrows will be valid.\n\nThe idea behind the arrow method is that you draw arrows between the quantities that are going to `balance', which simply means they are going to have the same coefficient in the final non-dimensionalised form. The process is generally the same as the substitution method. However, we must remember that in order to specify the problem completely the number of valid arrow balances must equal the number of variables. For example, if a problem depends on $u$ and $t$ we would need two balances. Alternatively, if the problem depended on $u$, $v$, and $t$ we would need three valid balances.  This section is going to depend primarily on examples, again, and we will see an invalid balance at the end of the demonstrations.\n\\begin{example}[frametitle=Arrow method]\\label{Arrow method}\n\\item Consider the following equation\n\\bb\n  \\tikzmark{a}\\dot{u}=k_0+k_1\\tikzmark{b}u+k_2\\tikzmark{c}u^2, \\quad u(0)=u_0.\\label{Non-dim_4}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (a.south) to (b.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (b.south) to (c.south);}\n\\ee\n\\COL{We have two variables, $u$ and $t$, and so we need two balances. Specifically, the arrows state that we want to balance the derivative, linear and quadratic terms,\n\\bb\n\\frac{[u]}{[t]}=k_1[u]=k_2[u]^2,\\nonumber\n\\ee\nfrom which it is simple to discover that\n\\bb\n[t]=\\frac{1}{k_1},\\quad [u]=\\frac{k_1}{k_2}.\\nonumber\n\\ee\nWe still need to substitute the scales into the equations. Namely, $u=u'k_1/k_2$ and $t=t'/k_1$, but again the arrow method simplifies this task. Specifically, we know that, by design, the coefficient of the derivative, linear and quadratic term are going to be the same. Thus, we can divide through by one of them to speed up the derivation,\n\\bb\n\\frac{\\rd u'}{\\rd t'}=\\frac{k_0}{k_1[u]}+u'+u'^2.\\nonumber\n\\ee\nFinally, redefining the last parameter as $\\alpha=k_0/(k_1[u])=k_0k_2/(k_1^2)$ and the initial condition $u'(0)=k_2u_0/k_1=u'_0$, we can non-dimensionalise \\eqn{Non-dim_4} to the final form of\n\\bb\n\\dot{u}=\\alpha+u+u^2,\\quad u(0)=u'_0,\\label{Non-dim_5}\n\\ee\nwhere we have dropped the primes from the variables for simplicity. Once again, we would have to ensure that $\\alpha$ and $u'_0$ where non-dimensional and that $[u]$ and $[t]$ had the right dimensions, but this }\\COL{is left as an exercise.\n}\\COL{\nIn this example we can illustrate the power of the non-dimensionalisation through the parameter groupings\n\\bb\n\\alpha=\\frac{k_0k_2}{k_1^2},\\quad u'_0=\\frac{k_2u_0}{k_1}.\\nonumber\n\\ee\nSpecifically, suppose we double each of the kinetic parameters \\ie $k_0\\mapsto 2k_0$, $k_1\\mapsto 2k_1$ and $k_2\\mapsto 2k_2$ then neither $\\alpha$, nor $u'_0$ changes. This means that under this transformation the solution of \\eqn{Non-dim_5} is exactly the same. But, how does this transformation of the original equations? Well, $[u]=k_1/k_2$ does not change, but $[t]=1/(2k_1)$ will be half its previous value. Hence, the solution to this `doubled-parameter' problem (call it $u_2(t)$) will reach the same solution values as the original problem, but in half the time \\see{Non_dim_example},\n\\bb\nu_2(t)=u\\l\\frac{t}{2}\\r.\\label{Non-dim_6}\n\\ee}\n\n% we notice that if we double the value of $k_2$ and simultaneously half $k_0$ and $u_0$ then the values of $\\alpha$ and $u'_0$ do not change, this means that the solution of \\eqn{Non-dim_5} is the same under this transformation and, thus, so must the solutions of \\eqn{Non-dim_4}.\n\\end{example}\n\\begin{figure}[!!!h!!!tb]\n\\centering\n\\includegraphics[width=\\ttp]{../Pictures/Non_dim_example.png}\n\\caption{\\label{Non_dim_example} Two simulations of \\eqn{Non-dim_4} with parameter values $k_0=k_1=k_2=1$ (blue line, $u(t)$) and $k_0=k_1=k_2=2$ (red line, $u_2(t)$). Illustrating that the evolution of the red line is the same as the blue line, except that the red line evolution occurs twice as fast, as predicted by \\eqn{Non-dim_6}.}\n\\end{figure}\n\n\\begin{example}[frametitle=Non-uniqueness]\n To illustrate the non-uniqueness of non-dimensionalisation we rerun example \\ref{Arrow method} but this time we balance the time derivative, the constant term and the initial condition,\n\\bb\n  \\tikzmark{a}\\dot{u}=k_0\\tikzmark{b}+k_1u+k_2u^2, \\quad u\\tikzmark{c}(0)=u_0\\tikzmark{d}.\\label{Non-dim_7}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (a.south) to (b.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (c.south) to (d.south);}\n\\ee\n\\COL{We quickly find that\n\\bb\n\\frac{[u]}{[t]}=k_0,\\quad [u]=u_0,\\nonumber\n\\ee\nthus, $[t]=u_0/k_0$. We can divide the equation through by $k_0$, because we know that this is the }\\COL{balance of the first two terms in \\eqn{Non-dim_7}. Thus, we derive\n\\bb\n\\dot{u'}=1+\\frac{k_1[u]}{k_0}u'+\\frac{k_2[u]^2}{k_0}u'^2, \\quad u'(0)=1,\\nonumber\n\\ee\nwhich would be rewritten as\n\\bb\n\\dot{u}=1+\\beta u+\\gamma u^2, \\quad u(0)=1,\\label{Non-dim_8}\n\\ee\nwhere\n\\bb\n\\beta=\\frac{k_1u_0}{k_0},\\quad \\gamma=\\frac{k_2u_0^2}{k_0}.\\nonumber\n\\ee}\n\\end{example}\n\nBoth forms of the non-dimensionalised equation, \\eqref{Non-dim_5} and  \\eqref{Non-dim_8}, are perfectly valid. The most useful form will depend on what factor dominates the equation. If $k_0$ is small and $k_1$ is big (relative to one another) then \\eqn{Non-dim_5} would be more useful as $\\alpha\\approx0$ and we would be able to manipulate the equation to provide more information. Alternatively, if $k_0$ was big and $k_2$, or $k_1$, was small then, \\eqn{Non-dim_8} would be more useful as we would, again, be able to remove one of the constants based on this assumption.\n\n\\begin{example}[frametitle=Failure]\nAs mentioned not all balances are valid, which is what we will be seen in this example. Consider the following ODE system\n\\begin{align}\n  \\tikzmark{a}\\dot{u}=k_0\\tikzmark{b}+k_1\\tikzmark{c}u-k_2uv, \\quad u(0)=u_0,\\\\\n \\nonumber \\\\\n    \\tikzmark{e}\\dot{v}=k_3\\tikzmark{f}+k_4\\tikzmark{g}v-k_2uv, \\quad v(0)=v_0.\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (a.south) to (b.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (b.south) to (c.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (e.south) to (g.south);}\n\\end{align}\n\\COL{There are three variables $u$, $v$ and $t$ and so we need three balances. The chosen balances are illustrated on the equations using arrows. Extracting information from the balances we find that\n\\bb\n\\frac{[u]}{[t]}=k_0=k_1[u], \\quad \\frac{[v]}{[t]}=k_4[v].\n\\ee\nFrom this point we quickly discover that\n\\bb\n[t]=\\frac{1}{k_1} \\textrm{ and } [t]=\\frac{1}{k_4}.\n\\ee\nSince, generally, $k_1\\neq k_4$ we cannot satisfy both balances, thus, we must consider a different non-dimensionalisation.}\n\nOne possible valid non-dimensionalisation is\n\\begin{align}\n  \\tikzmark{a}\\dot{u}=k_0\\tikzmark{b}+k_1\\tikzmark{c}u-k_2uv, \\quad u(0)=u_0,\\nonumber\\\\\n \\nonumber \\\\\n    \\tikzmark{e}\\dot{v}=k_3\\tikzmark{f}+k_4\\tikzmark{g}v-k_2uv, \\quad v(0)=v_0.\\nonumber\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (a.south) to (b.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (b.south) to (c.south);}\n\\tikz[overlay,remember picture]\n{\\draw[square arrow1] (e.south) to (f.south);}\n\\end{align}\nSee the board for details.\n\\end{example}\n\nAlthough each case of non-dimensionalisation is different, the algorithm you should follow is the same in each case. The steps are:\n\\begin{enumerate}\n\\item write down the variables in the equations, this tells you how many balances you need;\n\\item specify balances and check that they are valid;\n\\item define non-dimensional scales that allow you to minimise the number of free parameters;\n\\item substitute the scales into the equations and collect together the remaining parameters into the smallest possible groups and give them a new variable name (DO NOT FORGET to do the same thing for the initial conditions. Everyone always forgets to do the initial conditions);\n\\item demonstrate that the scales you have derived have the correct dimension;\n\\item demonstrate that the new parameter groupings are dimensionless.\n\\end{enumerate}\nAlthough we have not completed the last two points for every example, you will be expected to do every step in an exam.\n%\\begin{figure}[!!!h!!!tb]\n%\\centering\n%\\subfigure[\\label{IC_0.1}]{\\includegraphics[width=\\ttp]{../Pictures/Comparing_pendulums_IC_1.png}}\n%\\subfigure[\\label{IC_1}]{\\includegraphics[width=\\ttp]{../Pictures/Comparing_pendulums_IC_10.png}}\n%\\caption{\\label{Different_ICs}Comparing \\eqns{Spring_eqn}{Bob_eqn} with initial conditions (a) $y=0=\\theta$ and (b) $y=1=\\theta$. Parameter values $r=g=k=m=1$.}\n%\\end{figure}\n%\n%\n%\\begin{example}[frametitle=Zombies]\\label{Zombies}\n%Humans, $H$ and zombies, $Z$ interact through the following three interactions \\see{Zombie_picture}]:\n%\\end{example}\n%\\begin{figure}[!!!h!!!tb]\n%\\centering\n%\\includegraphics[width=\\tp]{../Pictures/Zombies.png}\n%\\caption{\\label{Zombie_picture} Possible outcomes of human-zombie interactions.}\n%\\end{figure}\n\n\\section{Check list}\nBy the end of this chapter you should be able to:\n\\begin{todolist}\n\\item non-dimensionalise a system of equations using direct substitution, or the arrow method;\n\\item demonstrate that the derived scales have the correct dimension;\n\\item demonstrate that remaining parameter groupings are non-dimensional;\n\\end{todolist}\n\n\n\n\n", "meta": {"hexsha": "e8fbc3ec8ec303c80d17dfc25b3a0bbb088d532f", "size": 20691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Latex/Non-dimensionalisation.tex", "max_stars_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_stars_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Latex/Non-dimensionalisation.tex", "max_issues_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_issues_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Latex/Non-dimensionalisation.tex", "max_forks_repo_name": "ThomasEWoolley/Modelling_with_Differential_Equations", "max_forks_repo_head_hexsha": "250ed551fa3f09e285ebcd7b2b3d86d01d9ee8e6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 73.1130742049, "max_line_length": 722, "alphanum_fraction": 0.745831521, "num_tokens": 6236, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8774767986961401, "lm_q1q2_score": 0.7654645816836174}}
{"text": "\\section{Length of a vector}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute the distance between points in $n$-dimensional space.\n  \\item Compute the length of a vector algebraically and geometrically.\n  \\item Find vectors that are a given distance from other vectors.\n  \\item Use algebraic properties of the length operation to prove\n    equalities.\n  \\item Normalize a vector.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section, we explore what is meant by the length of a vector in\n$\\R^n$.  We develop this concept by first looking at the distance\nbetween two points in $\\R^n$. Consider two points $P=(p_1,p_2)$ and\n$Q=(q_1,q_2)$ in the plane, as in the following picture.\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=1]\n    \\draw[dashed] (0,0) -- (0,2) -- (3,2);\n    \\draw[fill=blue!10] (0,0) -- (3,0) -- (3,2) -- cycle;\n    \\draw[thick] (0,0) -- (3,2);\n    \\draw[fill](0,0) circle [radius=1.8pt] node[left=1ex]{$Q=(q_1,q_2)$};\n    \\draw[fill](3,2) circle [radius=1.8pt] node[right=1ex]{$P=(p_1,p_2)$};\n  \\end{tikzpicture}\n\\end{equation*}\nThe distance between $P$ and $Q$ is shown in the picture as a solid\nline, which is the hypotenuse of a right triangle.  The lengths of the\ntwo other sides of this triangle are $\\abs{p_1-q_1}$ and\n$\\abs{p_2-q_2}$. Therefore, the Pythagorean Theorem implies the\nlength of the hypotenuse (and thus the distance between $P$ and $Q$)\nequals\n\\begin{equation*}\n  d(P,Q)\n  =\\sqrt{\\abs{p_1-q_1}^2+\\abs{p_2-q_2}^2}\n  =\\sqrt{(p_1-q_1)^2+(p_2-q_2)^2}.\n\\end{equation*}\nNow consider two points $P=(p_1,p_2,p_3)$ and\n$Q = (q_1,q_2,q_3)$ in $3$-dimensional space.\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=1]\n    \\draw[dashed] (3,0,-2) -- (0,0,-2) -- (0,0,0);\n    \\draw[dashed] (0,0,0) -- (0,2,0);\n    \\draw[dashed] (0,0,-2) -- (0,2,-2);\n    \\draw[fill=blue!20] (0,0,0) -- (3,0,0) -- (3,0,-2) -- cycle;\n    \\draw[fill=blue!10] (0,0,0) -- (3,0,-2) -- (3,2,-2) -- cycle;\n    \\draw[dashed] (0,2,0) -- (3,2,0) -- (3,2,-2) -- (0,2,-2) -- cycle;\n    \\draw[dashed] (3,0,0) -- (3,2,0);\n    \\draw[thick] (0,0,0) -- (3,2,-2);\n    \\draw[fill](0,0,0) circle [radius=1.8pt] node[left=1ex]{$Q=(q_1,q_2,q_3)$};\n    \\draw[fill](3,2,-2) circle [radius=1.8pt] node[right=1ex]{$P=(p_1,p_2,p_3)$};\n    \\draw[fill](3,0,-2) circle [radius=1.8pt] node[right=1ex]{$R=(p_1,p_2,q_3)$};\n    \\draw[fill](3,0,0) circle [radius=1.8pt] node[right=1ex]{$S=(p_1,q_2,q_3)$};\n  \\end{tikzpicture}\n\\end{equation*}\nWe will use the Pythagorean Theorem twice to find the length of the\nsolid line connecting $P$ and $Q$. First, by the Pythagorean Theorem\napplied to the right triangle $QSR$, the length of the line joining\n$R$ and $Q$ equals\n\\begin{equation*}\n  d(R,Q) = \\sqrt{(p_1-q_1)^2+(p_2-q_2)^2}.\n\\end{equation*}\nSecond, by the Pythagorean Theorem applied to the triangle $QRP$, the\nlength of the line joining $P$ and $Q$ equals\n\\begin{equation*}\n  d(P,Q)=\\sqrt{d(R,Q)^2+(p_3-q_3)^2}\n  =\\sqrt{(p_1-q_1)^2+(p_2-q_2)^2+(p_3-q_3)^2}\n\\end{equation*}\nThis discussion motivates the following definition for the distance\nbetween points in $\\R^n$.\n\n\\begin{definition}{Distance between points}{distance-between-points}\n  Let $P=(p_1,\\ldots,p_n)$ and $Q=(q_1,\\ldots,q_n)$ be two points in\n  $\\R^n$. Then the \\textbf{distance}%\n  \\index{distance!point to point} between these points is defined as\n  \\begin{equation*}\n    d(P, Q) = \\sqrt{(p_1-q_1)^2 + \\ldots + (p_n-q_n)^2}.\n  \\end{equation*}\n  This formula is also called the \\textbf{distance formula}%\n  \\index{distance formula}. We may also write $\\abs{PQ}$ for the\n  distance between $P$ and $Q$.\n\\end{definition}\n\nIn the following example, we use\nDefinition~\\ref{def:distance-between-points} to find the distance\nbetween two points in $\\R^4$.\n\n\\begin{example}{Distance between points}{distance-between-points}\n  Find the distance between the points $P=(1,2,-4,6)$ and\n  $Q=(2,3,-1,0)$ in $\\R^4$.\n\\end{example}\n\n\\begin{solution}\n  Using the distance formula, we have\n  \\begin{equation*}\n    d(P,Q)\n    = \\sqrt{(1-2)^2+(2-3)^2+(-4-(-1))^2+(6-0)^2}\n    = \\sqrt{1^2+1^2+3^2+6^2}\n    = \\sqrt{47}.\n  \\end{equation*}\n\\end{solution}\n\n\\begin{example}{The plane between two points}{plane-between-two-points}\n  Describe the points in $\\R^3$ that are equally distant from the two\n  points $Q=(1,2,3)$ and $R=(0,1,2)$.\n\\end{example}\n\n\\begin{solution}\n  Let $P = (p_1,p_2,p_3)$ be such a point. Then $P$ is the same\n  distance from $Q$ and $R$, thus $d(P,Q)=d(P,R)$. By the distance\n  formula, we have\n  \\begin{equation*}\n    \\sqrt{(p_1-1)^2+(p_2-2)^2+(p_3-3)^2}=\n    \\sqrt{(p_1-0)^2+(p_2-1)^2+(p_3-2)^2}.\n  \\end{equation*}\n  Squaring both sides, we obtain\n  \\begin{equation*}\n    (p_1 -1)^2+(p_2 -2)^2+(p_3 -3)^2\n    = p_1^2+(p_2-1)^2+(p_3 -2)^2,\n  \\end{equation*}\n  and so\n  \\begin{equation*}\n    \\allowbreak (p_1^2-2p_1+1)+(p_2^2-4p_2+4)+(p_3^2-6p_3+9)=p_1^2+(p_2^2-2p_2+1)+(p_3^2-4p_3+4).\n  \\end{equation*}\n  Simplifying, this becomes\n  \\begin{equation*}\n    -2p_1-4p_2-6p_3+14=-2p_2-4p_3+5,\n  \\end{equation*}\n  which can finally be written as\n  \\begin{equation}\\label{distance-plane}\n    2p_1+2p_2+2p_3=9.\n  \\end{equation}\n  Therefore, the points $P = (p_1,p_2,p_3)$ that are the same\n  distance from $Q$ and $R$ form a plane whose equation is given by\n  \\eqref{distance-plane}.\n\\end{solution}\n\nWe can now use our understanding of the distance between two points to\ndefine what is meant by the length of a vector.\n\n\\begin{definition}{Length of a vector}{length-of-vector}\n  Let\n  \\begin{equation*}\n    \\vect{u} = \\begin{mymatrix}{c}u_1\\\\\\vdots\\\\u_n\\end{mymatrix}\n  \\end{equation*}\n  be a vector in $\\R^n$. Then the \\textbf{length}%\n  \\index{vector!length}%\n  \\index{length of a vector} of $\\vect{u}$, written $\\norm{\\vect{u}}$,\n  is given by\n  \\begin{equation*}\n    \\norm{\\vect{u}} = \\sqrt{u_1^2 + \\ldots + u_n^2}.\n  \\end{equation*}\n  The length of a vector is also sometimes called its\n  \\textbf{magnitude}%\n  \\index{magnitude!of a vector}%\n  \\index{vector!magnitude} or its\n  \\textbf{norm}%\n  \\index{norm!in Rn@in $\\R^n$}%\n  \\index{vector!norm}.\n\\end{definition}\n\nThis definition corresponds to\nDefinition~\\ref{def:distance-between-points}, if we consider the\nvector $\\vect{u}$ to have its tail at the point\n$0 = (0,\\ldots,0)$ and its tip at the point\n$U = (u_1,\\ldots, u_n)$.  Then the length of $\\vect{u}$ is equal\nto the distance between $0$ and $U$. In general,\n$\\norm{\\longvect{PQ}} = d(P,Q)$.\n\nReconsider Example~\\ref{exa:distance-between-points}. We could have also\ncomputed the distance between $P$ and $Q$ as the length of the vector\nconnecting them. This vector is $\\longvect{PQ} = \\mat{1,1,3,-6}^T$,\nand its length is\n\\begin{equation*}\n  \\norm{\\longvect{PQ}} = \\sqrt{1^2+1^2+3^2+6^2} = \\sqrt{47}.\n\\end{equation*}\n\nThe following proposition states a few important properties of the length\nof vectors.\n\n\\begin{proposition}{Properties of length}{properties-length}\n  The following hold for all vectors $\\vect{u},\\vect{v}$ and scalars $k$.\n  \\begin{itemize}\n  \\item $\\norm{\\vect{u}}\\geq 0$\n  \\item $\\norm{\\vect{u}}=0$ if and only if $\\vect{u}=\\vect{0}$.\n  \\item $\\norm{k\\vect{u}} = |k|\\,\\norm{\\vect{u}}$.\n  \\end{itemize}\n\\end{proposition}\n\nWe conclude this section by giving a special name to vectors of length\n$1$.\n\n\\begin{definition}{Unit vector}{unit-vector}\n  A vector\\/ $\\vect{u}\\in\\R^n$ is called a \\textbf{unit vector}%\n  \\index{unit vector}%\n  \\index{vector!unit vector} if it has length $1$, that is, if\n  \\begin{equation*}\n    \\norm{\\vect{u}} = 1.\n  \\end{equation*}\n\\end{definition}\n\nLet $\\vect{v}$ be a non-zero vector in $\\R^n$. Then there is a unit\nvector $\\vect{u}$ that points in the same direction as $\\vect{v}$, but\nhas length 1%\n\\index{vector!corresponding unit vector}. This vector is given by\n\\begin{equation*}\n  \\vect{u} = \\frac{1}{\\norm{\\vect{v}}} \\vect{v}.\n\\end{equation*}\nWe often use the term \\textbf{normalize}%\n\\index{vector!normalizing a vector} to refer to this process. When we\nnormalize a vector, we find the corresponding unit vector.\n\n\\begin{example}{Normalizing a vector}{unit-vector}\n  Consider the vector $\\vect{v} = \\mat{1, -3, 4}^T$. Find the unit\n  vector $\\vect{u}$ that has the same direction as $\\vect{v}$\n\\end{example}\n\n\\begin{solution}\n  We have $\\norm{\\vect{v}} = \\sqrt{1^2 + (-3)^2 + 4^2} =\n  \\sqrt{26}$, and therefore\n  \\begin{equation*}\n    \\vect{u}\n    = \\frac{1}{\\norm{\\vect{v}}} \\vect{v}\n    = \\frac{1}{\\sqrt{26}} \\mat{1, -3, 4}^T\n    = \\mat{\\frac{1}{\\sqrt{26}}, -\\frac{3}{\\sqrt{26}}, \\frac{4}{\\sqrt{26}}}^T.\n  \\end{equation*}\n\\end{solution}\n\n", "meta": {"hexsha": "274f21ab76e242e009e6ef61b085d87b503efeb5", "size": 8438, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-Length.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-Length.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-Length.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.8471615721, "max_line_length": 97, "alphanum_fraction": 0.6538279213, "num_tokens": 3232, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7654645706788378}}
{"text": "\n\\subsection{Within and between transformation}\n\n\\subsubsection{Introduction}\n\nWe can group the data in two ways, one gets between differences and the other within differences.\n\nIn the above example, we could find the effects of schools, or of departments.\n\n\\(y_{ij}=\\alpha + X_{ij}\\theta +\\epsilon_{ij}\\)\n\n\\((y_{ij}-\\bar y_{j})=(\\alpha -\\bar \\alpha )+(X_{ij}-\\bar X_{j})\\theta  +(\\epsilon_{ij}-\\bar \\epsilon_{j})\\)\n\n\\((y_{ij}-\\bar y_{j})=(X_{ij}-\\bar X_{j})\\theta  +(\\epsilon_{ij}-\\bar \\epsilon_{j})\\)\n\nOr alternatively:\n\n\\((y_{ij}-\\bar y_{i})=(X_{ij}-\\bar X_{i})\\theta  +(\\epsilon_{ij}-\\bar \\epsilon_{i})\\)\n\nRegardless of the form we choose, we can write this as:\t\n\n\\(\\ddot y_{ij}=\\ddot X_{ij}\\theta +\\ddot \\epsilon_{ij}\\)\n\n", "meta": {"hexsha": "ef05ad4036ba7a14f0645301740be6e778fc2c44", "size": 726, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/generalLinearModels/03-01-transformation.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/generalLinearModels/03-01-transformation.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/generalLinearModels/03-01-transformation.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.25, "max_line_length": 108, "alphanum_fraction": 0.6625344353, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9559813513911654, "lm_q2_score": 0.8006920020959544, "lm_q1q2_score": 0.7654466222117883}}
{"text": "%================================\n%::::::::::::::::::::::::::::::::\n\\chapter{Some Examples of Topological Spaces}\n\\label{ch: some examples of topological spaces}\n%::::::::::::::::::::::::::::::::\n%================================\n\n\n\n\n%================================\n\\section{Sorgenfrey line}\n\\label{sec: sorgenfrey line}\n%================================\n\n\n\\begin{enumerate}\n\t\\item \\href{https://proofwiki.org/wiki/Definition:Sorgenfrey_Line}{Definition}.\n\t\\item \\href{https://proofwiki.org/wiki/Sorgenfrey_Line_is_Lindel%C3%B6f}{Sorgenfrey line is Lindel\\\"of}.\n\t\\item \\href{https://proofwiki.org/wiki/Sorgenfrey_Line_is_Separable}{Sorgenfrey line is separable}.\n\t\\item \\href{https://proofwiki.org/wiki/Sorgenfrey_Line_is_not_Second-Countable}{Sorgenfrey line is not second-countable}.\n\\end{enumerate}\n\n%================================\n\\section{Niemytzki Plane}\n\\label{sec: niemytzki plane}\n%================================", "meta": {"hexsha": "307d2b15ad7ac5d42f50f3d195e9065eb25d12a8", "size": 927, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology/appendix.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/appendix.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/appendix.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": 34.3333333333, "max_line_length": 122, "alphanum_fraction": 0.5587918015, "num_tokens": 219, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8499711737573762, "lm_q1q2_score": 0.7654243661172757}}
{"text": "\\chapter{Reachability of the Tree's Root Node}\n\n\\section{Determining the maximum alpha}\nIn the previous chapter we have determined how many divisions by two lead to a cycle in the Collatz tree. We will now study the case in which a Collatz sequence reaches the root node $v_{n+1}=1$. Our proof builds on theorem~\\ref{theo:1}. As in the last chapter we replace $(1+\\frac{1}{3v_i})$ with the variable $\\beta_i$:\n\n\\[\nv_{n+1}=3^nv_1\\prod_{i=1}^{n}\\beta_i\\prod_{i=1}^{n}2^{-\\alpha_i}\n\\]\n\nSetting $v_{n+1}=1$ leads to:\n\n\\begin{equation}\n\\label{eq:reach_1}\n\\begin{array}{l}\n1=3^nv_1\\prod_{i=1}^{n}\\beta_i\\prod_{i=1}^{n}2^{-\\alpha_i}\n\\\\[\\medskipamount]\n\\prod_{i=1}^{n}2^{\\alpha_i}=3^nv_1\\prod_{i=1}^{n}\\beta_i\n\\end{array}\t\n\\end{equation}\n\n\\par\\medskip\nEquation~\\ref{eq:reach_1} defines the maximum possible value of $\\alpha$ for a given Collatz sequence. When a Collatz sequence reaches this alpha value, it finishes at the root node. The number of divisions by two required for this is referred to as $\\hat\\alpha$ subsequently:\n\n\\begin{equation*}\n\\begin{array}{l}\n2^{\\hat\\alpha}=3^nv_1\\prod_{i=1}^{n}\\beta_i\n\\\\[\\medskipamount]\n\\hat\\alpha=nlog_23+log_2v_1+log_2\\prod_{i=1}^{n}\\beta_i\n\\end{array}\t\n\\end{equation*}\n\n\\par\\medskip\nIn the previous chapter we proved $1<\\prod_{i=1}^{n}\\beta_i<2$. We use this knowledge to further restrict $\\hat\\alpha$ in theorem~\\ref{theo:3}.\n\n\\bigskip\n\\begin{theorem}\n\\label{theo:3}\nThe maximum possible number of divisions by two in a Collatz sequence can be calculated as follows:\n\\[\n\\hat\\alpha=\\lfloor n\\cdot log_23+log_2v_1\\rfloor+1\n\\]\nIf a Collatz sequence reaches $\\hat\\alpha$, it ends with the result $v_{n+1}=1$.\n\\end{theorem}\n\n\\par\\medskip\nSince $\\hat\\alpha$ is a whole number, we truncate the fractional part. Knowing that $1<\\prod_{i=1}^{n}\\beta_i<2$ we add one to the result.\n\n\\bigskip\n\\begin{example}\nSetting $v_{n+1}=13$ and $n=2$ leads to:\n\\[\nv_{2+1}=3^2\\cdot13\\cdot\\left(1+\\frac{1}{3\\cdot13}\\right)\\cdot\\left(1+\\frac{1}{3\\cdot5}\\right)\\cdot2^{\\lfloor2\\cdot\\log_23+log_213\\rfloor+1}\n\\]\n\\end{example}\n\nBuilding on $\\hat\\alpha$ we define the following restrictions on the alpha of a Collatz sequence:\n\n\\begin{equation}\n\\label{eq:reach_3}\nn\\le\\alpha\\le\\hat\\alpha\n\\end{equation}\n\nCondition~\\ref{eq:reach_3} is not only valid for $k=3$, but for all $k$. Similar to $\\bar\\alpha$, the variable $\\hat\\alpha$ could form the basis for a proof of the Collatz conjecture. As $\\bar\\alpha$ teaches us about cycles in the Collatz tree, $\\hat\\alpha$ leads us the way to its root node. If one shows that each Collatz sequence finally reaches $\\hat\\alpha$, the problem is solved as a whole. This is not in the scope of the present paper. However, it could become the foundation for a future work.\n", "meta": {"hexsha": "134b14b65e0578cd4b66070ff359bbd6828daa88", "size": 2715, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "01 Graph Theory/TeX/v6.0/chapter/05_reachability_root.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/05_reachability_root.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/05_reachability_root.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": 42.421875, "max_line_length": 502, "alphanum_fraction": 0.726335175, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096067182449, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7653944945953977}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS630: Database Management Systems\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\nLet $a$ and $b$ be integer-valued attributes that may be \\texttt{NULL} in some tuples.\nFor each of the following conditions that may appear in a \\texttt{WHERE} clause, describe exactly the set of $(a,b)$ tuples that satisfy the condition, including the case where $a$ and/or $b$ is \\texttt{NULL}.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item $a=10$ or $b=20$\n\\item $a=10$ and $b=20$\n\\item $a<10$ or $a>=10$\n\\item $a=b$\n\\end{enumerate}\n\n\\textbf{Solution:}\n\nFor ease of representation, sets $I$ and $J$ are defined respectively as set of integers and nullable integers; the latter being set of all possible integer values and the \\texttt{NULL} value, $\\lambda$.\nAs well, set of all binary relations that satisfy specified condition is defined as $S$.\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item\n\\begin{equation}\\nonumber\nS = \\{ (a,b) | a = 10, b\\in J \\} \\cup \\{ (a,b) | b = 20, a\\in J \\}\n\\end{equation}\n\\item\n\\begin{equation}\\nonumber\nS = \\{ (a,b) | a = 10, b = 20 \\}\n\\end{equation}\n\\item\n\\begin{equation}\\nonumber\nS = \\{ (a,b) | a \\in I, b \\in J\\}= J - \\{(a,b)|a = \\lambda , b \\in J\\}\n\\end{equation}\n\\item\n\\begin{equation}\\nonumber\nS = \\{ (a,b) | a = b, a \\in I, b \\in I\\}\n\\end{equation}\n\n\\end{enumerate}\n", "meta": {"hexsha": "bdbd1f960bde99b2ee42d98a8d1349a235b10016", "size": 1580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs630-2014f/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-cs630-2014f/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-cs630-2014f/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": 35.9090909091, "max_line_length": 209, "alphanum_fraction": 0.6221518987, "num_tokens": 504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096044278533, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7653944926818131}}
{"text": "\n\\subsection{Linear and affine functions}\n\n\\subsubsection{Linear maps}\n\nLinear maps can be written as:\n\n\\(v=Mu\\)\n\nThese go through the origin. That is, if \\(u=0\\) then \\(v=0\\).\n\n\\subsubsection{Affine function}\n\nAffine functions are more general than linear maps. They can be written as:\n\n\\(v=Mu+c\\)\n\nWhere \\(c\\) is a vector in the same space as \\(v\\).\n\nAffine functions where \\(c\\ne 0\\) are not linear maps. They are not homomorphisms which preserve the structure of the vector space.\n\nIf we multiply \\(u\\) by a scalar \\(s\\), then \\(v\\) will not increase by the same proportion. \n\n", "meta": {"hexsha": "4fd501c863e66ce097457003832cfe205c45278b", "size": 581, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/maps/01-04-linear.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-04-linear.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-04-linear.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.2083333333, "max_line_length": 131, "alphanum_fraction": 0.7108433735, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7653921775715192}}
{"text": "Note that (a), (c) and (d) are equivalent by the definition of a tree and\n\\cite{notes}, Theorem 21. We must prove these are additionally equivalent\nto (b) and (d).\n\n\\paragraph{$(a)\\Rightarrow(b)$} Suppose $G$ is a tree. Then it is, by\ndefinition, connected, so every two vertices are joined by at least one\npath. Suppose now that there are two vertices $x$ and $y$ that are joined\nby two distinct paths $P_1$ and $P_2$. Consider $p$, the vertex before the\nfirst vertex that differs between $P_1$ and $P_2$, and let $q$ be the first\nvertex after $p$ in $P_1$ which also occurs after $p$ in $P_2$. Let\n$P'_1$ be the path from $p$ to $q$ along $P_1$, and $P'_2$ be the path from\n$p$ to $q$ along $P_2$. It is clear that $P'_1$ concatenated with the\nreverse of $P'_2$ is a closed walk starting and ending at $p$. To show it is\na cycle, it is sufficient to show that no vertex internal to $P'_1$ appears\nin $P'_2$. However, if such a vertex $q'$ were to exist, it would be a\nvertex after $p$ on $P_1$, which also occurs after $p$ on $P_2$, and\nmoreover before $q$ on $P_1$, contradicting the definition of $q$ as the\nfirst such vertex. Therefore the closed walk described is a cycle, which\ncontradicts that two vertices in $G$ are joined by distinct paths. $(b)$\nfollows.\n\n\\paragraph{$(b)\\Rightarrow(e)$} \nSuppose $G$ contains a cycle, and let two vertices on this cycle be $x$\nand $y$. Then by following the cycle from $x$ to $y$ in each direction,\ntwo internally disjoint paths from $x$ to $y$ can be found, contradicting\nthat there is a unique $x-y$ path in $G$. So $G$ is acyclic.\nNow, since $G$ is acyclic, any\ncycle in $G+uv$ contains the edge $uv$. But clearly there is at least one\nsuch cycle, that obtained by following the unique path from $u$ to $v$ in\n$G$, then using the edge $uv$ (since $u$ and $v$ are nonadjacent, this edge\nis not in $G$, so hasn't been used earlier in the cycle). Now suppose $C$ is\na cycle in $G+uv$. It must also contain $uv$, hence $u$ and $v$. Now\nconsider the path obtained by following $C$ from $u$ to $v$, not using the\nedge $uv$. This is a path connecting $u$ and $v$ in $G$, hence it must be\nthe unique path connecting $u$ and $v$ in $G$, and hence $C$ is the cycle\nobtained from this path as described earlier. So the cycle is unique.\n\n\\paragraph{$(e)\\Rightarrow(a)$} $G$ is already acyclic, so it suffices to\nprove it connected. Let $x$ and $y$ be two vertices in $G$. If they are\nadjacent, there is clearly a path between them. If they are not, then\n$G+xy$ contains a cycle $C$. Since $G$ is acyclic, $C$ includes\n$xy$ and hence $x$ and $y$. Now, following $C$ from $x$ to $y$, not using\nthe edge $xy$ gives a path from $x$ to $y$ in $G$. So any pair\nof vertices in $G$ is connected, so $G$ is. Hence $G$ is a tree.\n", "meta": {"hexsha": "07b783e71b923129febd864b42a4b7d8e1da4b5a", "size": 2757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tut2/4.9.tex", "max_stars_repo_name": "h4tguy/gt-hons", "max_stars_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tut2/4.9.tex", "max_issues_repo_name": "h4tguy/gt-hons", "max_issues_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tut2/4.9.tex", "max_forks_repo_name": "h4tguy/gt-hons", "max_forks_repo_head_hexsha": "a9b4a271a9bdc31c68571507f6bff16b7bedd12b", "max_forks_repo_licenses": ["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.2666666667, "max_line_length": 76, "alphanum_fraction": 0.7011244106, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972818382005, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7653827847522944}}
{"text": "\\section{The ElGamal cryptosystem}\nThe ElGamal cryptosystem was proposed by Taher ElGamal in 1985 as an extension to the Diffie-Hellman protocol which can be applied in other cyclic groups, such as \\textbf{Galois fields}. \n\nIt is a public-key encryption algorithm, based on the intractability of the discrete logarithm, and considered over the group $\\mathbb{Z}^*_p$ with $p$ prime.\n\nIts key aspect is the \\textbf{randomized encryption}, adding a layer of security, and its principal applications are establishing a secure channel for key sharing and message encryption. \n\nThe ElGamal algorithm was proposed to remedy one flaw of the Diffie-Hellman key exchange: it requires interaction of both parties to calculate a common private key. This can constitute in a problem in case they are not able to interact, due to delays in transmission or unavailability of receiver.\n\nThe random exponent is therefore introduced to replace the private exponent of the receiving entity, so that it does not have to take part in the exchange.\n\n\\subsection{From Diffie-Hellman to ElGamal}\nElGamal follows immediately from Diffie-Hellman: to send an encrypted message $x$, Alice must perform a key exchange to derive a shared key $k_M$. However, as previously stated, only the receiver needs to create a key in advance and publish it.\n\nA large prime $p$ and a primitive element $\\alpha$ need to be generated, to whom ElGamal adds a random multiplicative mask to encrypt:\n$$y \\equiv x \\cdot k_M \\mod p$$\n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.35]{ElGamalPrinciplePaar.png}\n\t\\centering\n\\end{figure}\n\nThis protocol is similar to Diffie-Hellman: the private and public keys of Bob are computed the same way, and do not change over time, however Alice has to generate a new pair for the encryption of every message.\n\nThe key $k_E$ is \\textbf{ephemeral}, meaning that it only exists temporarily, and $k_M$ is the joint key for masking the plain text. To encrypt a message, Alice multiplies the plaintext message $x$ by $k_M$ and Bob reverses this operation using the inverse mask.\n\n\\subsection{Protocol}\nElGamal encryption method works thanks to an important property of cyclic groups: given $k_M \\in \\mathbb{Z}^*_p$, every message $x$ maps to another cipher text computing $k_M \\cdot x$, and random values allow to obtain the \\textit{same probability} for every cipher text. \n\n\\begin{figure}[h]\n\t\\includegraphics[scale=0.35]{ElGamalProtocolPaar.png}\n\t\\centering\n\\end{figure}\n\nThe actual protocol is composed by three phases: \\textbf{setup}, \\textbf{encryption} and \\textbf{decryption}. It starts by fixing a very large finite field $\\mathbb{Z}^*_p$ and an element $\\alpha \\in \\mathbb{Z}^*_p$ (preferably, but not necessarily a generator). \n\nSupposing an use of plain text message units with numerical equivalents in $\\mathbb{Z}^*_p$, each user $A$ randomly chooses an integer $i$ in the range $0 < i < p - 1$. This integer $i$ is the secret deciphering key, while the public enciphering key is the element $k_E = \\alpha^i \\in \\mathbb{Z}^*_p$.\t\n\nTo send a message $y$ to the user $A$, an integer $d$ is chosen at random, and $A$ is sent the pair of elements:\n$$(\\alpha^d, y\\alpha^{id})$$\n$\\alpha^{id} = k_E^d$ can be computing without knowing $i$ simply by raising $\\alpha$ by the $d$-th power. Now Alice, who is aware of $i$, can recover $y$ from this pair simply by raising the first element $\\alpha^d$ to the $i$-th power and dividing the result by the second element.\n\nPublic keys can be obtained in any way, for instance from key servers or unencrypted means. There is no security issues involved in this transmission, as the only secret is the exponent and therefore computationally infeasible.\n\nIn other words, the message is being masked but also contains a way to be recovered only by someone knowing the initial value $i$. \n\nThe Diffie-Hellman sequence of operations is rearranged, since Bob receives only one message from Alice containing the ephemeral key and the encrypted text. In this case, however, the couple $(k_E, y)$ is generally \\textbf{twice as long} as the message, since parameters have a bit length of $\\lceil\\log_2p\\rceil$.\n\n\\subsubsection{Example}\nAlice wants to send the message $x = 26$.\n\nBob generates $p = 29$ and $\\alpha = 2$, then chooses $k_{pr, B} = d = 12$ to compute $\\beta = \\alpha^d \\equiv 7 \\mod 29$.\n\nAlice receives the triple $k_{pub, B} = (p, \\alpha, \\beta) = (29, 2, 7)$, chooses $i = 5$ and then uses those to obtain the two temporary keys:\n\\begin{enumerate}\n\t\\item $k_E = \\alpha^i \\equiv 3 \\mod 29$\n\t\\item $k_M = \\beta^i \\equiv 16 \\mod 29$\n\\end{enumerate}\nAlice encrypts $y = x \\cdot k_M \\equiv 10 \\mod 29$, and sends it to Bob with the ephemeral key $k_E$.\n\nBob computes $k_M = k_E^d \\equiv 16 \\mod 29$, which is the same as Alice, and uses it to decrypt the message:\n$$x = y \\cdot k^{-1}_M \\equiv 10 \\cdot 20 \\equiv 26 \\mod 29$$\n\n\\subsection{Proof}\nAssuming the value $d_{k_{pr}}(k_E, y)$ actually returns the original message $x$:\n\\begin{equation}\n\\begin{split}\nd_{k_{pr}}(k_E, y) &\\equiv y \\cdot (k_M)^{-1} \\mod p \\\\\n&\\equiv [x \\cdot k_M] \\cdot (k_E^d)^{-1} \\mod p \\\\\n&\\equiv [x \\cdot (\\alpha^d)^i]^{-1} \\mod p \\\\\n&\\equiv x \\cdot \\alpha^{d \\cdot i - d \\cdot i} \\mod p \\\\\n&\\equiv x \\mod p\n\\end{split}\n\\end{equation}\n\n\\subsection{Practical applications}\nElGamal encryption is not widely used in practice, since one of the best known practices to break it exploits its malleability: the ciphertext $(k_E, y)$ can be replaced with $(k_e, sy)$ for some integer $s$.\n\nThe receiver therefore then computes:\n\\begin{equation}\n\\begin{split}\nd_{k_{pr}}(k_E, sy) &\\equiv sy \\cdot (k_M)^{-1} \\mod p \\\\\n&\\equiv s \\cdot (x \\cdot k_M) \\cdot k_M^{-1} \\mod p \\\\\n&\\equiv sx \\mod p\n\\end{split}\n\\end{equation}\n\nThe decrypted text is also a multiple of $s$, and although an attacker would not be able to decrypt the message, he is able to manipulate it for instance doubling or tripling the value of the result and compromising communication.\n\nThe ElGamal encryption system is used in GNU Privacy Guard System and recent versions of PGP. \n\nGnuPG implementation, however, until late 2003 had an insecure algorithm whose private exponent was too short and thus easy to break. All signatures created before then are considered compromised. \n\n\\subsubsection{Computational aspects}\nAs previously stated, the ciphertext is twice as long as the message: therefore, the message expansion factor of ElGamal is two. \n\nFurthermore, it is a \\textbf{probabilistic encryption scheme}: encrypting two identical messages $x_1, x_2 \\in \\mathbb{Z}^*_p$ using the same public key results with \\textit{extremely high likelihood} in two different ciphertexts $y_1 \\neq y_2$. \n\nThis happens since $i$ is chosen at random from $\\{2, 3, \\dots, p - 2\\}$ every time a message is encrypted, causing the session key $k_M = \\beta^i$ to also be random. This is an effective method to prevent brute-force attacks.\n\nKey generation involves finding a prime number $p$, which needs to have a length of at least 1024 bits and can be found through one of the prime-finding algorithms. \n\nThe public key can easily be computed using the square-and-multiply algorithm, since it requires exponentiation operations.\n\nThis is also applied to the encryption procedure: it involves two modular exponentiations and one modular multiplication, all operands having a bit length of $\\lceil\\log_2p\\rceil$. Since exponentiations are independent from the plain text, they can be calculated in advance and stored to be retrieved when actual encryption is needed, to reduce the total time.\n\nDecryption is performed again through the exponentiation $k_M = k^d \\mod p$, using square-and-multiply, followed by an inversion performed with extended Euclidean algorithm.\n\n\\textbf{Fermat's Little Theorem }allows to combine steps, using the following property:\n$$k_E^{p-1} \\equiv 1 \\mod p \\qquad \\forall\\ k_E \\in \\mathbb{Z}^*_p$$\n\nDecryption can be performed as:\n\\begin{equation}\n\\begin{split}\nk_M^{-1} &\\equiv (k_E^d){-1} \\mod p \\\\\n&\\equiv (k_E^d){-1}\\cdot k_E^{p-1} \\mod p \\\\\n&\\equiv k_E^{p-d-1} \\mod p\n\\end{split}\n\\end{equation}\nThis equivalence relation allows to compute the inverse of the masking key using only a single exponentiation with $p - d - 1$, which is essentially one execution of square-and-multiply.\n\nAfter that, one modular multiplication is required to recover $x \\equiv y \\cdot k_M^{-1} \\mod p$. \n\n\\subsubsection{Security}\nTo analyse the security of ElGamal, firstly an assumption must be introduced, consisting in the \\textbf{Decisional Diffie-Hellman}. This assumption states that, considering a group $G$ and a generator $a$, given $x, y \\in \\mathbb{Z}^*_q$, the value $a^{xy}$ looks like a generic random element.\n\nThis can also be stated imposing that the probability distributions $(a^x, a^y, a^{xy})$ and $(a^x, a^y, a^z)$, with $x, y, z \\in \\mathbb{Z}^*_q$ randomly and independently chosen, are computationally indistinguishable. \n\nDecisional Diffie-Hellman is a stronger assumption than just discrete logarithm, since it forbids computing discrete logarithms of $a^x$ and $a^y$ separately to then combine them and cracking $a^{xy}$. \n\nThe security of ElGamal can be further assessed distinguishing between two kinds of attacks:\n\\begin{itemize}\n\t\\item Passive, which are listen-only;\n\t\\item Active, which allow an attacker to generate and alter messages.\n\\end{itemize}\n\nPassive attacks consist in retrieving the message $x$ from the information $p, \\alpha, \\beta = \\alpha^d, k_E = \\alpha^i$ and $y = \\beta^i$ obtained by eavesdropping the channel. \n\nCurrently, there is no method to solve Diffie-Hellman protocol other than computing discrete logarithms, therefore the most efficient way to avoid that is choosing strong keys. In fact, the only ways an attacker can break the ElGamal scheme are:\n\\begin{enumerate}\n\t\\item Finding $d$, i.e.\\ computing $d = \\log_\\alpha \\beta \\mod p$, which is computationally infeasible;\n\t\\item Trying to guess the random exponent $i = log_\\alpha k \\mod p$, which still involves solving the discrete logarithm problem.\n\\end{enumerate}\nThe index-calculus algorithm can be used in both cases, thus in order to guarantee security of ElGamal, $p$ should be at least of 1024 bits and $\\alpha$ has to be a primitive element. \n\nActive attacks compromise the authenticity of public keys, having them belong to an untrusted third party. This can be prevented using certificates or digital signatures.\n\nAnother pitfall is that the random exponent $i$ \\textbf{should not be reused}: assuming Alice uses the same value for the encryption of two subsequent messages $x_1$ and $x_2$, then the two masking keys would be the same, namely $k_M = \\beta^i$, along with the ephemeral keys.\n\nTwo identical cyphertexts $(y_1, k_E)$ are therefore sent through the channel. If an attacker can guess the first message, the second one can be computed as well using the masking key $k_M \\equiv y_1x_1^{-1} \\mod p$ since $x_2 \\equiv y_2k_M^{-1} \\mod p$.\n\nThis consequently works for every text encrypted with the same $i$. Furthermore, an attacker knows that $i$ is being reused, since it leads to the same ephemeral key. As a consequence, the secret exponent must not be repeated, choosing different seeds for picking random numbers. \n", "meta": {"hexsha": "76c909419f2bdda1cc1b347b1059efca631c8092", "size": 11221, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Seminar - Algebraic Methods and Algorithms in Cryptology  /chapters/elgamal.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/elgamal.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/elgamal.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": 73.339869281, "max_line_length": 360, "alphanum_fraction": 0.7542108546, "num_tokens": 3001, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.890294223211224, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7653536773850217}}
{"text": "\\section{Network Flow Problems}\r\n\\subsection{The Maximal Flow Problem}\r\n\\begin{definition}\r\n    A network (or directed graph) is a set $N=\\{1,\\ldots,n\\}$ of nodes (or vertices) together with a collection $A\\subset N\\times N$ of ordered pairs $(i,j)$ called arcs or directed edges.\r\n    The flow in the network is a collection of numbers $(x_{i,j})$ indexed by elements in $N\\times N$.\r\n\\end{definition}\r\nThe problem we wish to consider is formulated in the following way:\r\nEach arc $(i,j)$ is assigned a capacity $c_{i,j}\\ge 0$.\r\nIn reality (or for notational convenience), we will pretend all arcs in $N\\times N$ exists and $c_{i,j}=0$ for $(i,j)\\notin A$.\\\\\r\nWe distinguish two special nodes in the network.\r\nNode $1$ is called the source node while the node $n$ is called the sink.\r\nThe maximum flow problem is to pump as much flow through the network, from the source to the sink, subject to the capacity constraints and the constraint that the flow-in and flow-out cancelled out in any notes except the source and the sink.\r\n\\footnote{Normally, there is no flow-in at the source and no flow-out at the sink.}\r\nFormally, we want to maximise $v\\in\\mathbb R$ subject to $0\\le x_{i,j}\\le c_{i,j}$ and\r\n$$\\sum_{j\\in N}x_{i,j}-\\sum_{j\\in N}x_{j,i}=\\begin{cases}\r\n    v\\text{, if $i=1$}\\\\\r\n    0\\text{, if $1<i<n$}\\\\\r\n    -v\\text{, if $i=n$}\r\n\\end{cases}$$\r\nwhich, as one can discover joyfully, is a linear program.\r\nAs an aside, the variable $v$ does not have to appear as it can be expressed in terms of $(x_{i,j})$ in the constraint.\r\nIt is simply for notational convenience.\\\\\r\nOf course, we can apply the barrier method or simplex algorithm and call it a day, but certainly there are more useful structures in this system that allows us to simplify it.\r\n\\subsection{The Ford-Fulkerson Algorithm}\r\nA nice algorithm developed by Ford-Fulkerson is as follows:\\\\\r\nFirst, assign an initial feasible flow $(x_{i,j})$ with value $v$ (for example we can take all of them to be zero).\r\nThen find an augmented path, defined a a collection of nodes $1=i_1,i_2,\\ldots,i_{r-1},i_r=n$ with eiher $c_{i_k,i_{k+1}}-x_{i_k,i_{k+1}}>0$ or $x_{i_{k+1},i_k}>0$ for each $k$.\r\nIf an augmented path exists, then increase the flow along the path by the amount\r\n$$\\delta=\\min_{k\\in\\{1,\\ldots,r-1\\}}\\max\\{c_{i_k,i_{k+1}}-x_{i_k,i_{k+1}},x_{i_{k+1},i_k}\\}$$\r\nwhich is positive by assumption and\r\n$$x_{i,j}'=\\begin{cases}\r\n    x_{i,j}+\\delta\\text{, if $i,j$ are consecutive in the path}\\\\\r\n    x_{i,j}-\\delta\\text{, if $j,i$ are consecutive in the path}\\\\\r\n    x_{i,j}\\text{, otherwise}\r\n\\end{cases}$$\r\nThen, as one can check, $(x_{i,j}')$ is also feasible with $v'=v+\\delta$.\r\nWe shall show that the non-existence of an augmented path is equivalent to the maximality of the flow.\r\n\\begin{definition}\r\n    Let $S\\subset N$ be a collection of nodes.\r\n    The complement of $S$ in $N$ is denoted $\\bar{S}=N\\setminus S$.\r\n    A cut seperating the source and the sink is the set of arcs $(i,j)\\in S\\times \\bar{S}$ where $\\{1,n\\}\\in S$.\r\n    THe capacity of a cut $(S,\\bar{S})$ is defined as\r\n    $$c(S,\\bar{S})=\\sum_{i\\in S,j\\in\\bar{S}}c_{i,j}$$\r\n\\end{definition}\r\n\\begin{theorem}[The max-flow min-cut Theorem]\\label{max-flow-min-cut}\r\n    For a network, the maximum value of a feasible flow from the source to the sink equals to the minimum of all cut capacities of all cuts seperating the source and the sink.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Fix any feasible flow $(x_{i,j})$.\r\n    For any $S,T\\subset N$ we write\r\n    $$f(S,T)=\\sum_{i\\in S,j\\in T}x_{i,j}$$\r\n    be the total flow over arcs joining $S$ and $T$.\r\n    Now let $S,\\bar{S}$ be a cut seperating the source and the sink, the constraint tells us\r\n    \\begin{align*}\r\n        v&=\\sum_{i\\in S,j\\in N}x_{i,j}-\\sum_{j\\in N,i\\in S}x_{ji}\\\\\r\n        &=f(S,N)-f(N,S)\\\\\r\n        &=(f(S,S)+f(S,\\bar{S}))-(f(S,S)+f(\\bar{S},S))\\\\\r\n        &=f(S,\\bar{S})-f(\\bar{S},S)\\\\\r\n        &\\le f(S,\\bar{S})\\\\\r\n        &\\le c(S,\\bar{S})\r\n    \\end{align*}\r\n    Hence the value of any flow is less than or equal to the capacity of any cut.\r\n    To show that they are actual equal, notice that the inequality above becomes an equality iff $x_{i,j}=c_{i,j}$ and $x_{j,i}=0$ for all arcs $(i,j)$ in $(S,\\bar{S})$.\r\n    SO let $(x_{i,j}^\\star)$ be a maximal flow (which exists by compactness).\r\n    We define a set $S$ by induction in the following criteria:\\\\\r\n    1. The source is in $S$.\\\\\r\n    2. If $i\\in S$ and $x_{i,j}^\\star<c_{i,j}$, then $j$ in $S$.\\\\\r\n    3. If $i\\in S$ and $x_{j,i}^\\star>0$, then $j\\in S$.\\\\\r\n    Now the sink is in $\\bar S$ since otherwise there would be a path (by the inductive process) from the source to the sink pumping strictly more flow, contradicting the maximality of $(x_{i,j}^\\star)$.\r\n    The cut $(S,\\bar{S})$ has the property we wanted.\r\n\\end{proof}\r\nThe same constructive idea shows that if no augmented path can be found, then the flow is maximal as one can construct such a cut which has capacity equal to the value of the flow.\\\\\r\nAlso, the algorithm is guaranteed to terminate if the capacities and elements of the initial flow are all integer (hence it also terminates if all are rational by multiplying an integer).\r\nThis is because the $\\delta$ we obtain from the algorithm is at least $1$, so if the value of $v$ increases indefinitely through the algorithm, it cannot be bounded, which contradicts the compactness of the domain of the problem.\r\nBut if something is irrational, the algorithm may not terminate.\r\n\\subsection{The Dual Problem}\r\nThe Lagrangian of the maximal flow problem is (note that $v$ can be expressed in terms of $(x_{i,j})$):\r\n\\begin{align*}\r\n    L&=v+\\sum_i\\lambda_i\\left( \\sum_jx_{i,j}-\\sum_jx_{j,i} \\right)-\\lambda_1v+\\lambda_nv+\\sum_{i,j}\\mu_{i,j}(c_{i,j}-x_{i,j}-z_{i,j})\\\\\r\n    &=\\sum_{i,j}c_{i,j}\\mu_{i,j}+v(1-\\lambda_1+\\lambda_n)+\\sum_{i,j}x_{i,j}(\\lambda_i-\\lambda_j-\\mu_{i,j})-\\sum_{i,j}\\mu_{i,j}z_{i,j}\r\n\\end{align*}\r\nwhere $z$ is the slack variable.\r\nFor $L$ to be bounded above varying $x,z$, we have\r\n$$\\begin{cases}\r\n    1-\\lambda_1+\\lambda_n=0\\\\\r\n    \\lambda_i-\\lambda_j\\le\\mu_{i,j}\\\\\r\n    \\mu_{i,j}\\ge 0\r\n\\end{cases}$$\r\nSo the dual problem is to minimise $\\sum_{i,j}c_{i,j}\\mu_{i,j}$ subject to $\\lambda_1-\\lambda_n=1,\\lambda_i-\\lambda_j\\le\\mu_{i,j},\\mu_{i,j}\\ge 0$.\r\nBy complementary slackness, if $x$ is optimal for the primal problem and $(\\lambda,\\mu)$ is optimal for the dual problem, then $\\lambda_i-\\lambda_j=\\mu_{i,j}$ and $\\mu_{i,j}=0$.\\\\\r\nBy Theorem \\ref{max-flow-min-cut}, there is a set $S$ with $1\\in S,n\\notin S$ such that the optimal dual variables are given by\r\n$$\\lambda_i=\\begin{cases}\r\n    1\\text{, if $i\\in S$}\\\\\r\n    0\\text{, if $i\\in\\bar{S}$}\r\n\\end{cases},\\mu_{i,j}=\\begin{cases}\r\n    1\\text{, if $i\\in S,j\\in\\bar{S}$}\\\\\r\n    0\\text{, otherwise}\r\n\\end{cases}$$\r\ndue to our previously discussed dual constraints.\r\n\\subsection{Combinatorial Applications}\r\nThere are certain combinatorial applications of Theorem \\ref{max-flow-min-cut}.\r\nOne combinatorial problems is formulated like this:\r\nSuppose that a standard deck of $52$ playing cards dealt into $13$ piles of $4$ cards each, we want to show that it is possible to select exactly one card from each pile such that the selected cards contain one card of each of the $13$ ranks A,2,\\dots,10,J,Q,K.\\\\\r\nTo prove this, we build a network with nodes\r\n$$A,a_1,\\ldots,a_{13},b_1,\\ldots,b_{52},c_1,\\ldots,c_{13},B$$\r\nas follows:\r\nThe nodes $(a_i)$ represent the $13$ piles, and the nodes $(b_j)$ represent the $52$ cards, and the node $(c_k)$ represent the $13$ ranks.\r\nThe node $A$ is the source and $B$ is the sink.\\\\\r\nWe put an arc of capacity $1$ from $A$ to each of $a_i$, and an arc of infinite (or very large) capacity from $a_i$ to $b_j$ if card $j$ is in stack $i$.\r\nThere will be exactly four arcs leaving each $a_i$ and exactly one arc entering each $b_j$.\\\\\r\nWe also put an arc of infinite capacity from $b_j$ to $c_k$ if card $j$ has rank $k$, so again there will be exactly one arc leaving each of the nodes $b_j$ and exactly four arcs entering each of the nodes $c_k$.\\\\\r\nLastly, put an arc of capacity $1$ from each node $c_k$ to the sink $B$.\r\n\\begin{claim}\r\n    The minimum capacity of any cut is $13$.\r\n\\end{claim}\r\n\\begin{proof}\r\n    The cut $\\{(A,a_i):i=1,\\ldots,13\\}$ has capacity $13$.\r\n    We shall show that any other cut has capacity at least $13$.\r\n    Consider a cut with finite capacity, then it does not contain any arc of the form $(a_i,b_j)$ or $(b_j,c_k)$.\r\n    If there are $r$ arcs of the form $(c_k,B)$ for some $k$, then there are at least $s=13-r$ nodes $c_k$ still connected to $B$.\r\n    Each of these $s$ many $c_k$'s is connected to four of the nodes $b_j$ exclusively, so $4s$ many $b_j$ is connected to $B$.\r\n    But then at least $(4s)/4=s$ many nodes $a_i$ are connected to those $b_j$, hence to $B$, and they are also connected to $A$.\r\n    So there are at least $s$ arcs of the form $(A,a_i)$ to be removed in order to complete the cut.\r\n    This produces a total capacity of at least $r+s=13$.\r\n\\end{proof}\r\nSo by Theorem \\ref{max-flow-min-cut}, there is a flow of value $13$.\r\nBut the capacities are either $1$ or infinity (or a very big integer), the Ford-Fulkerson algorithm starting with initial flow $0$ will terminate.\r\nHence there is an optimal flow (whose flows along every arc must be $0$ or $1$ by assumption).\r\nLet $x$ be the optimal flow, then necessarily $x_{A,a_i}=1$.\r\nAs it is a flow, there is some $j$ such that $x_{a_i,b_j}=1$ and some $k$ such that $x_{b_j,c_k}=1$.\r\nSo we can match nodes in the way $a_i,c_k$ which provides the solution.\r\n\\subsection{The Transportation Problem}\r\nThe problem is as follows:\r\nImagine there are $m$ suppliers of a good labelled $1,\\ldots,m$.\r\nFor any $i$, the supplier $i$ can supply $S_i$ units of the good.\r\nThere are $n$ destinations labelled $1,\\ldots,n$ that require the supply of the good.\r\nFor any $j$, destination $j$ requires $D_j$ units of the good.\r\nFor each pair $(i,j)$, there is an associated unit transport cost $d_{i,j}$.\r\nIt is assumed in addition that the supply and demand matches, i.e.\r\n$$\\sum_{i=1}^mS_i=\\sum_{j=1}^nD_j$$\r\nThis is basically the linear program to minimise the total cost $\\sum_{i,j}d_{i,j}x_{i,j}$ subject to\r\n$$\\begin{cases}\r\n    \\forall i,\\sum_{j=1}^nx_{i,j}=S_i\\\\\r\n    \\forall j,\\sum_{i=1}^mx_{i,j}=D_j\\\\\r\n    \\forall i,j,x_{i,j}\\ge 0\r\n\\end{cases}$$\r\nThe Lagrangian is then\r\n\\begin{align*}\r\n    L(x,\\lambda,\\mu)&=\\sum_{i,j}d_{i,j}x_{i,j}+\\sum_{i=1}^m\\lambda_i\\left( S_i-\\sum_{j=1}^n x_{i,j} \\right)+\\sum_{j=1}^n\\mu_j\\left( D_j-\\sum_{i=1}^mx_{i,j} \\right)\\\\\r\n    &=\\sum_{i,j}(d_{i,j}-\\lambda_i-\\mu_j)x_{i,j}+\\sum_{i=1}^m\\lambda_iS_i+\\sum_{j=1}^n\\mu_jD_j\r\n\\end{align*}\r\nNote that $x_{i,j}\\ge 0$, so we have $d_{i,j}\\ge \\lambda_i+\\mu_j$ for the Lagrange multipliers to be feasible, hence\r\n$$\\Lambda=\\{(\\lambda,\\mu):\\inf_{x\\ge 0}L(x,\\lambda,\\mu)>-\\infty\\}=\\{(\\lambda,\\mu):\\forall i,j,d_{i,j}\\ge \\lambda_i+\\mu_j\\}$$\r\nIf $(x_{i,j})$ is optimal for the problem, then there are feasible $(\\lambda,\\mu)$ such that\r\n$$\\forall i,j,(d_{i,j}-\\lambda_i-\\mu_j)x_{i,j}=0$$\r\nby complementary slackness.\r\nWe can of course use simplex algorithm as it is a linear program, but the additional structure here allows us to simplify it.\r\n\\subsection{The Transportation Algorithm}\r\nWe design an algorithm for it as follows:\r\nFirst, find an initial feasible assignment.\r\nAs there are $m+n-1$ linearly independent relations constraining the feasible set, any basic feasible solution will have $m+n-1$ basic variables.\r\nThere are two ways to do this: the North-West method and the greedy algorithm.\r\nThese will be introduced in a second.\\\\\r\nAfter the initial feasible assignment is done, we assign Lagrange multipliers.\r\nWe may take $\\lambda_1=0$ and enforce complementary slackness by choosing $\\lambda_i$ and $\\mu_i$ subject to $d_{i,j}=\\lambda_i+\\mu_j$ for each basic cell.\\\\\r\nNext, we check for optimality by looking at the dual feasibility of the Lagrange multipliers.\r\nThe feasibility constraint is just $d_{i,j}\\ge\\lambda_i+\\mu_j$ for each $i,j$.\r\nIf this is valid, then we are done.\\\\\r\nOtherwise, we do the pivoting operation by picking one of the cells $(i,j)$ such that $\\lambda_i+\\mu_j>d_{i,j}$.\r\nthe rule is to pick the cell with the largest difference $\\lambda_i+\\mu_j-d_{i,j}$.\r\nNow put an amount $\\epsilon>0$ units of flow into the pivot cell.\r\nAt the same time add or substract $\\epsilon$ from the basic cell to maintain feasibility.\r\nWe will try to choose the largest $\\epsilon$ possible such that the flow is feasible.\r\nThen do the same thing again and again until we reach optimality.\r\n\\begin{example}\r\n    Suppose the table of supply, demand and cost is\r\n    $$\\begin{array}{c|c|c|c|c|c}\r\n        d_{i,j}&&&&&D_j\\\\\r\n        \\hline\r\n        &8&6&7&5&12\\\\ \\hline\r\n        &4&3&5&4&8\\\\ \\hline\r\n        &9&8&6&7&11\\\\ \\hline\r\n        S_i&7&6&10&8&\r\n    \\end{array}$$\r\n    The North-West method is filling in the number of unit in each transport flow starting from North-West (top-left) of the array and fit in as many as we can, and the precedence of filling is from top-left to bottom-right.\r\n    This way would give the basic feasible solution:\r\n    $$\\begin{pmatrix}\r\n        7&5&&\\\\\r\n        &1&7&\\\\\r\n        &&3&8\r\n    \\end{pmatrix}$$\r\n    Then we assign Lagrange multipliers by complementary slackness:\r\n    $$\\begin{array}{c|cccc|c}\r\n        &8&6&8&9&\\mu_j\\\\ \\hline\r\n        0&7&5&0&0&\\\\\r\n        -3&0&1&7&0&\\\\\r\n        -2&0&0&3&8&\\\\ \\hline\r\n        \\lambda_i&&&&&\r\n    \\end{array}$$\r\n    Now we test the optimality by writing out the payoffs, i.e. $\\lambda_i+\\mu_j-d_{i,j}$ in each of the zero cells (denoted by the terms in square brackets), which gives\r\n    $$\\begin{array}{c|cccc|c}\r\n        &8&6&8&9&\\mu_j\\\\ \\hline\r\n        0&7&5&[1]&[4]&\\\\\r\n        -3&[1]&1&7&[2]&\\\\\r\n        -2&[-3]&[-4]&3&8&\\\\ \\hline\r\n        \\lambda_i&&&&&\r\n    \\end{array}$$\r\n    So we need to pivot the top right corner, i.e. make it basic.\r\n    Suppose it is changed to $\\epsilon$, then we need to change our solution to\r\n    $$\\begin{pmatrix}\r\n        7&5-\\epsilon&&\\epsilon\\\\\r\n        &1+\\epsilon&7-\\epsilon&\\\\\r\n        &&3+\\epsilon&8-\\epsilon\r\n    \\end{pmatrix}$$\r\n    which is always feasible.\r\n    For the solution to be basic, we take $\\epsilon=5$ to swipe out an entry to get the new solution, which, after calculating Lagrange multipliers and payoffs,\r\n    $$\\begin{array}{c|cccc|c}\r\n        &8&2&4&5&\\mu_j\\\\ \\hline\r\n        0&7&[-4]&[-3]&5&\\\\\r\n        1&[5]&6&2&[2]&\\\\\r\n        2&[1]&[-4]&8&3&\\\\ \\hline\r\n        \\lambda_i&&&&&\r\n    \\end{array}$$\r\n    So we pivot the second row of the first column with, as we can find, has $\\epsilon=2$.\r\n    Doing this again and again and again and again and again and again and again and again and again yields our final table\r\n    $$\\begin{array}{c|cccc|c}\r\n        &7&6&4&5&\\mu_j\\\\ \\hline\r\n        0&[-1]&5&[-3]&7&\\\\\r\n        -3&7&1&[-4]&[-2]&\\\\\r\n        2&[0]&[0]&10&1&\\\\ \\hline\r\n        \\lambda_i&&&&&\r\n    \\end{array}$$\r\n    where all the entries in the square bracket is nonpositive, hence this is the optimal solution.\\\\\r\n    The greedy algorithm works as well.\r\n    This time we start with the cell of lowest cost and fill in as many as possible, then the second lowest, etc..\r\n    In our case, this will produce the initial feasible assignment\r\n    $$\\begin{pmatrix}\r\n        6&&&6\\\\\r\n        &6&&2\\\\\r\n        1&&10&\r\n    \\end{pmatrix}$$\r\n    to which we can apply the same method to get to optimality.\r\n\\end{example}\r\n\\begin{remark}\r\n    If the original posture of the prblem is such that the total supply exceeds the total demand, then we can reformulate the problem by adding another destination with demand\r\n    $$D_{n+1}=\\sum_{i=1}^mS_i-\\sum_{j=1}^nD_j$$\r\n    and set $d_{i,n+1}=0$ for all $i$ to ensure that all differences are consumed.\r\n\\end{remark}\r\nWhy does pivoting decrease the total cost?\r\nFor any feasible $x$ and any collection $(\\lambda_i)$ and $(\\mu_j)$ of Lagrange multipliers we have\r\n\\begin{align*}\r\n    f(x)&=L(x,\\lambda,\\mu)\\\\\r\n    &=\\sum_{i,j}(d_{i,j}-\\lambda_i-\\mu_j)x_{i,j}+\\sum_{i=1}^m\\lambda_iS_i+\\sum_{j=1}^n\\mu_jD_j\r\n\\end{align*}\r\nSo suppose $x_0$ is the initial feasible assignment, then we can choose $\\lambda_{i,0}$ and $\\mu_{i,0}$ to enforce complementary slackness $(d_{i,j,0}-\\lambda_{i,0}-\\mu_{j,0})x_{i,j,0}=0$, then\r\n$$f(x_0)=\\sum_{i=1}^m\\lambda_{i,0}S_i+\\sum_{j=1}^n\\mu_{j,0}D_j$$\r\nLet $B=\\{(i,j):x_{i,j,0}>0\\}$ and $N=\\{(i,j):x_{i,j,0}=0\\}$ be the basis of the basic feasible solution $x_0$.\r\nWe choose $\\lambda_{i,0}$ and $\\mu_{i,0}$ such that $\\lambda_{i,0}+\\mu_{j,0}=d_{i,j}$ for all $(i,j)\\in B$.\r\nSuppose the next feasible assignment $x_1$ is non-degenerate, as one of the initial non-basic cells (the pivot cell) is made basic, there is a cell $(i_N,j_N)\\in N$ such that\r\n$$x_{i_N,j_N,0}=0,x_{i_N,j_N,1}=\\epsilon>0$$\r\nThen we obtain\r\n\\begin{align*}\r\n    f(x_1)&=\\sum_{(i,j)\\in B}(d_{i,j}-\\lambda_{i,0}-\\mu_{j,0})x_{i,j,1}+\\sum_{(i,j)\\in N}(d_{i,j}-\\lambda_{i,0}-\\mu_{j,0})x_{i,j,1}\r\n    +f(x_0)\\\\\r\n    &=(d_{i_N,j_N}-\\lambda_{i_N,0}-\\mu_{j_N,0})\\epsilon+f(x_0)\\\\\r\n    &>f(x_0)\r\n\\end{align*}\r\nby assumption.", "meta": {"hexsha": "1ba95ebf66d3752d72d5260e2c1b7c96c813b6fe", "size": 17084, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/network.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "5/network.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "5/network.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.7462686567, "max_line_length": 264, "alphanum_fraction": 0.6602083821, "num_tokens": 5575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8596637487122112, "lm_q1q2_score": 0.7653536768895282}}
{"text": "\\lab{Algorithms}{QR Decomposition (Householder)}{Canonical Transformations and the QR Decomposition}\n\\label{Ch:Canonical Transformations}\n\n\\objective{Use orthogonal transformations to perform QR decomposition.}\n\n\\section*{Orthogonal transformations}\nRecall that a matrix $Q$ is \\emph{unitary} if $Q^* Q = I$ or for real matrices, $Q^T Q = I$ (since the conjugate of a real number is itself). We like unitary transformations because they're very 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 Lab \\ref{Ch:Norms and Geometry}; for now, all you need to know is that if $\\kappa(A)$ is small, then problems involving $A$ are less susceptible to numerical errors. For induced matrix norms (which include most of the matrix norms we would ever care about),  it holds that $\\norm{Q}=1$ when $Q$ is unitary. The inequality $\\norm{AB} \\leq \\norm{A} \\norm{B}$ also holds for these norms. It follows that $\\kappa(A) = \\norm{A} \\norm{A^{-1}} \\geq \\norm{A A^{-1}} = \\norm{I} = 1$. Note that if $Q$ is unitary, $Q^{-1} = Q^*$ and $Q^*$ is also unitary, so $\\kappa(Q) = \\norm{Q} \\norm{Q^*} = 1$. This means that orthogonal matrices have the smallest possible condition number, which is great!\n\nAny unitary matrix $Q$ can be described as a reflection, a rotation, or some combination of the two. If $det(Q) = 1$, then $Q$ is a rotation; if $det(Q) = -1$, then $Q$  is the 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. See figure \\ref{fig:Householder reflector}. Recall that a hyperplane can be defined by a unit vector $v$ which is orthogonal to the hyperplane. As shown in the figure, $x - \\langle v,x \\rangle v$ is the projection of $x$ onto the hyperplane defined by $v$. (You should verify this geometrically.) However, to reflect \\emph{across} the hyperplane, we must move twice as far; that is, $Px = x - 2\\langle v,x \\rangle v$. This can be written $Px = x - 2v(v^\\ast x)$, so $P$ has matrix representation $P = I - 2vv^\\ast$. Note that $P^\\ast P = I$; thus $P$ is orthogonal.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width= \\textwidth]{fig1}\n\t\\caption{Householder reflector}\n\t\\label{fig:Householder reflector}\n\\end{figure}\n\n\\subsection*{Householder triangularization}\nConsider the problem of computing the $QR$ decomposition of a matrix $A$. You've already learned the Gram-Schmidt and the Modified Gram-Schmidt algorithms for this problem. The $QR$ decomposition can also be computed using Householder triangularization. Gram-Schmidt and Modified Gram-Schmidt \\emph{orthogonalize} $A$ by a series of \\emph{triangular} transformations. Conversely, the Householder method \\emph{triangularizes} $A$ by a series of \\emph{orthogonal} transformations.\n\nLet's demonstrate this method on a $4 \\times 3$ matrix $A$. First we find a orthogonal transformation $Q_1$ that maps the first column of A into the range of $e_1$ (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\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \n\\end{pmatrix}\n\\underrightarrow{Q_1}\n\\begin{pmatrix}\n\n\\ast & \\ast & \\ast & \\\\ \\cline{2-3}\n\\mc{0} & \\ast & \\mc{\\ast}& \\\\\n\\mc{0} & \\ast & \\mc{\\ast} & \\\\\n\\mc{0}& \\ast & \\mc{\\ast} & \\\\ \\cline{2-3}\n\\end{pmatrix}\n\\end{equation*}\nLet $A_2$ be the boxed submatrix of $A$. Now find an orthogonal transformation $Q_2$ that maps the first column of $A_2$ into the range of $e_2$. \n\n\\begin{equation*}\n\\begin{pmatrix}\n\\ast & \\ast \\\\\n\\ast & \\ast \\\\\n\\ast & \\ast \n\\end{pmatrix}\n\\underrightarrow{Q_2}\n\\begin{pmatrix}\n\\ast & \\ast \\\\\n0 & \\ast \\\\\n0 & \\ast \n\\end{pmatrix}\n\\end{equation*}\nSimilarly, $ \\begin{pmatrix} \\ast \\\\ \\ast \\end{pmatrix} \\underrightarrow{Q_3} \\begin{pmatrix} \\ast \\\\ 0 \\end{pmatrix} $. (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$. $Q_2$ leaves the first row alone, and $Q_3$ leaves the first two rows alone.) Then $Q_3 Q_2 Q_1 A =$ \n\n\\begin{equation*}\nQ_3 Q_2 Q_1\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\ast & \\ast & \\ast \\\\\n\\end{pmatrix}\n= Q_3 Q_2\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n\\end{pmatrix}\n= Q_3\n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & 0 & \\ast \\\\\n0 & 0 & \\ast \\\\\n\\end{pmatrix}\n= \n\\begin{pmatrix}\n\\ast & \\ast & \\ast \\\\\n0 & \\ast & \\ast \\\\\n0 & 0 & \\ast \\\\\n0 & 0 & 0 \\\\\n\\end{pmatrix}\n\\end{equation*}\n\nWe've accomplished our goal, which was to triangularize $A$ using orthogonal transformations. But now, how do we find the $Q_i$ that do what we want? Using Householder reflections. (Surprise!)\n\nFor example, to find $Q_1$, we choose the right hyperplane to reflect $x$ into the range of $e_1$. It turns out there are two hyperplanes that will work, as shown in figure \\ref{fig:two reflectors}. (In the complex case, there are infinitely many such hyperplanes.) Between the two, the one that reflects $x$ further will be more numerically stable. This is the hyperplane perpendicular to \\textbf{$v = sign(x_1)\\norm{x}_2 e_1 + x$}. The whole process is summarized in Algorithm \\ref{Alg:Householder triangularization}.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width= \\textwidth]{fig2}\n\t\\caption{two reflectors}\n\t\\label{fig:two reflectors}\n\\end{figure}\n\n\\begin{pseudo}{Householder triangularization}{A}\n\\label{Alg:Householder triangularization}\nm,n \\GETS size(A)\\\\\n\\FOR k \\GETS 1 \\TO n-1 \\DO\n\\BEGIN\n   x = A_{k:m,k}\\\\\n   v_k = sign(x_1)\\norm{x}_2 e_1 + x\\\\\n   v_k = v_k / \\norm{v_k}_2\\\\\n   P_k = eye(m,m)\\\\\n   P_k[k:m,k:m] = P_k[k:m,k:m] - 2 v_k v_k^T\\\\\n   A = sp.dot(P_k,A);\n\\END\n\\end{pseudo}\n\nThis algorithm returns upper triangular $R$. You can find $Q$ s.t. $QR = A$ by multiplying the $P_k$ together appropriately.\n\n\\begin{problem}\n\\label{prob:HouseholderQR}\nWrite a script using Householder reflections to find the QR decomposition of a matrix A.\n\\end{problem}\n\n\\subsection*{Stability of the Householder QR algorithm}\n\nTry the following in Python.\n\n\\begin{lstlisting}\nIn [1]:  import scipy as sp\nIn [2]:  import numpy.linalg as la\nIn [3]:  import my_householder\nIn [4]:  Q,X = la.qr(sp.rand(50,50)) #create a random orthogonal matrix:\nIn [5]:  R = sp.triu(sp.rand(50,50)) # create a random upper triangular matrix\nIn [6]:   A = sp.dot(Q,R) #Q and R are the exact QR decomposition of A\n# use your Householder QR script to estimate Q and R:\nIn [7]:   Q1,R1 = my_householder.qr(A)\n#now check the relative errors of Q1 and R1\nIn [8]:  la.norm(Q1-Q)/la.norm(Q)\nOut [8]:  0.282842955725\nIn [9]:  la.norm(R1-R)/la.norm(R)\nOut[9]:  0.0428922016647\n\\end{lstlisting}\nThis is terrible! Python works in $16$ decimal points of precision. But $Q_1$ and $R_1$ are only accurate to $0$ and $1$ decimal points, respectively. We've lost $16$ decimal points of precision!\n\nDon't lose hope. Check how close the product $Q_1 R_1$ is to $A$.\n\\begin{lstlisting}\nIn [10]:  A1 = sp.dot(Q1,R1)\nIn [11]:  la.norm(A1-A)/la.norm(A)\nOut[11]:  9.73996046986e-16\n\\end{lstlisting}\nWe've now recovered $15$ digits of accuracy. The errors in $Q_1$ and $R_1$ were somehow ``correlated,\" so that they canceled out in the product. The errors in $Q_1$ and $R_1$ are called \\emph{forward errors}. The error in $A_1$ is the \\emph{backward error}. The Householder $QR$ algorithm is a backward stable algorithm.\n\nHouseholder QR factorization is more numerically stable than Gram-Schmidt or even Modified Gram-Schmidt (MGS). However, MGS is still useful for some types of iterative methods, because it finds the orthogonal basis one vector at a time instead of all at once (for example see Lab \\ref{Ch:EigSolve}).\n\n\\subsection*{Upper Hessenberg Form}\n\n%I'm not sure about this math. Is this true in the real case?\nAn upper Hessenberg matrix is a square matrix with zeros below the first subdiagonal. Every  $n \\times n$ matrix $A$ can be written $A = Q^THQ$ where $Q$ is orthogonal and $H$ is an upper Hessenberg matrix, called the Hessenberg form of $A$. Note the similarity of this decomposition to the Schur decomposition in Lab \\ref{Ch:Jordan}. \n\nThe Hessenberg decomposition can be computed using Householder reflections, in a process very similar to Householder triangularization. Let's demonstrate this process on a $5 \\times 5$ matrix $A$. Note that $A=Q^THQ$ is equivalent to $QAQ^T = H$; thus our strategy is to multiply $A$ on the right and left by a series of orthogonal matrices until it is in Hessenberg form. If we try 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$. However, since we now have to multiply $Q_1 A$ on the left by $Q_1^T$, all those zeros are destroyed, as demonstrated below. (Although this process may seem futile now, it actually does tend to decrease the size of the subdiagonal entries. If we repeat it over and over again, the subdiagonal entries will often converge to zero. That's the idea behind the $QR$ algorithm in Lab \\ref{Ch: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 range 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\n\\begin{problem}\nWrite a script that transfers an input matrix to upper Hessenberg form. (Hint: You only need to modify your code code from problem \\ref{prob:HouseholderQR} slightly.) We will use this technique in the eigenvalue lab later.\n\\end{problem}\n\n\n\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", "meta": {"hexsha": "d1e53d1367ed84aabca8b4b97063b0a7049607c3", "size": 11852, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/CanonTransform/CanonTransform.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/CanonTransform/CanonTransform.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/CanonTransform/CanonTransform.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": 47.983805668, "max_line_length": 1032, "alphanum_fraction": 0.6753290584, "num_tokens": 3895, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.765320483767943}}
{"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\\DeclareMathOperator*{\\pro}{\\mathcal P_{\\Omega}}\n\\DeclareMathOperator*{\\pron}{\\mathcal N_{\\Omega}}\n\\DeclareMathOperator*{\\proa}{\\mathcal P_{\\Psi}}\n\\newcommand{\\BigO}[1]{\\ensuremath{\\operatorname{O}\\left(#1\\right)}}\n\n\\begin{document}\n\n\\title{PCPKit Documentation}\n\\author{Stephen Tierney}\n\\maketitle\n\n\\section{Function Listing}\n\n\\begin{table}[!h]\n{\\small{\n\\centering\n\n\\begin{tabular}{c | c | c}\n\n\\hline\nProblem & Function & Section\\\\\n\n\\hline\n{\\bf Matrix Completion - Noise Free}\\\\\n\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* +  \\frac{1}{2} \\| \\mathbf{ A } \\|_F^2\\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) \\end{array}$ & mc\\_svt\t& \\ref{mc_svt}\\\\\n\n\\hline\n\\multirow{2}{*}{$\\begin{array}{c} \\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_*\\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) \\end{array}$} & mc\\_ialm\t& \\ref{mc_ialm}\\\\\n\t\t& solve\\_lin\t& \\ref{mc_lin}\\\\\n\t\t\n\\hline\n{\\bf Matrix Completion - Noisy}\\\\\n\n\\hline\n\\multirow{3}{*}{$\\begin{array}{c} \\tau \\| \\mathbf A \\|_*  +  \\frac{\\lambda}{2} \\| \\mathbf{ \\pro (A) - \\pro (M)  } \\|^2_F  \\end{array}$}\n\t& mc\\_relax\\_lin & \\ref{mc_relax}\\\\\n\t& mc\\_relax\\_lin\\_ext &\\\\\n\t& mc\\_relax\\_lin\\_acc &\\\\\n\t\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf{A,E}} \\; \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|_F^2\\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) + \\pro (\\mathbf E) \\end{array}$ & mc\\_exact\\_fro\t& \\ref{mc_exact_fro}  \\\\\n\n\\hline\n{\\bf Principal Component Pursuit}\\\\\n\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf{A,E}} \\; \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|_F^2\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\end{array}$ & pcp\\_fro & \\ref{pcp_fro} \\\\\n\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf{A,E}} \\; \\| \\mathbf A \\|_* + \\lambda \\| \\mathbf E \\|_1\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\end{array}$ & pcp\\_l1 & \\ref{pcp_l1}  \\\\\n\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf{A,E}} \\; \\| \\mathbf A \\|_* + \\lambda \\| \\mathbf E \\|_{1,2}\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\end{array}$ & pcp\\_l1l2 & \\ref{pcp_l1l2} \\\\\n\n\n\\hline\n{\\bf Selective PCP}\\\\\n\n\\hline\n$\\begin{array}{c} \\min_{\\mathbf A, \\mathbf E} \\;  \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|^2_F \\\\\n\\text{s.t.} \\; \\pro(\\mathbf{M}) = \\pro(\\mathbf{A}) \\nonumber \\\\\n\\proa(\\mathbf{M}) = \\proa(\\mathbf{A}) + \\proa(\\mathbf E) \\nonumber \\\\  \\end{array}$  & sel\\_pcp & \\ref{sel_pcp}\n\n\\end{tabular}\n}}\n\\end{table}\n\n\\newpage\n\\section{Matrix Completion}\n\n\\subsection{Noise Free Data}\n\n\\subsubsection{SVT}\n\\label{mc_svt}\n\nThe function\n\\begin{align}\n[ \\mathbf A, \\mathbf{f\\_values}, \\mathbf{stop\\_vals} ] = \\text{mc\\_svt}( \\mathbf M, \\Omega, \\tau, \\mu, iterations, tol )\\notag \n\\end{align}\nsolves the following\n\\begin{align}\n\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* +  \\frac{1}{2} \\| \\mathbf{ A } \\|_F^2 \\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) \\nonumber \n\\end{align}\\\nas proposed by the authors of \\cite{cai2010singular}.\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\Omega$ - vector of constrained matrix indices\n\\item $\\tau$ - regularisation (optional)\n\\item $\\mu$ - step size (optional)\n\\item $iterations$ - maximum number of iterations (optional)\n\\item $tol$ - stopping criteria tolerance (optional)\n\\end{itemize}\n\n\\subsubsection{Inexact ALM}\n\\label{mc_ialm}\n\nThe function\n\\begin{align}\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{mc\\_ialm}( \\mathbf M, \\Omega, \\tau, \\mu, iterations, tol )\\notag \n\\end{align}\nsolves the following\n\\begin{align}\n\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* \\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) \\nonumber \n\\end{align}\nas proposed by the authors of \\cite{lin2010augmented}.\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\Omega$ - vector of constrained matrix indices\n\\item $\\tau$ - regularisation (optional)\n\\item $\\mu$ - step size (optional)\n\\item $iterations$ - maximum number of iterations (optional)\n\\item $tol$ - stopping criteria tolerance (optional)\n\\end{itemize}\n\n\\subsubsection{Linearised ALM}\n\\label{mc_lin}\n\nThe function\n\\begin{align}\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{mc\\_lin}( \\mathbf M, \\Omega, \\tau, \\mu, \\rho, iterations, tol ) \\notag \n\\end{align}\nsolves the following\n\\begin{align}\n\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* \\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) \\nonumber \n\\end{align}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\Omega$ - vector of constrained matrix indices\n\\item $\\tau$ - regularisation (optional)\n\\item $\\mu$ - step size (optional)\n\\item $\\rho$ - linearisation step size (optional)\n\\item $iterations$ - maximum number of iterations (optional)\n\\item $tol$ - stopping criteria tolerance (optional)\n\\end{itemize}\n\n\\subsection{Noisey Data Relaxation}\n\\label{mc_relax}\n\nThe functions\n\\begin{align}\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{mc\\_relax\\_lin}( \\mathbf M, \\Omega, \\tau, \\lambda, \\rho, iterations, tol ) \\notag \\\\\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{mc\\_relax\\_lin\\_ext}( \\mathbf M, \\Omega, \\tau, \\lambda, \\rho, iterations, tol ) \\notag \\\\\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{mc\\_relax\\_lin\\_acc}( \\mathbf M, \\Omega, \\tau, \\lambda, \\rho, iterations, tol )\\notag \n\\end{align}\nsolve the following\n\\begin{align}\n\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_*  +  \\frac{\\lambda}{2} \\| \\mathbf{ \\pro (A) - \\pro (M)  } \\|^2_F \n\\end{align}\nwith increasing convergence speed based on \\cite{ji2009accelerated}.\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\Omega$ - vector of constrained matrix indices\n\\item $\\tau$ - regularisation (optional)\n\\item $\\lambda$ - regularisation (optional)\n\\item $\\rho$ - linearisation step size (optional)\n\\item $iterations$ - maximum number of iterations (optional)\n\\item $tol$ - stopping criteria tolerance (optional)\n\\end{itemize}\n\n\\subsection{Noisey Data Exact}\n\\label{mc_exact_fro}\n\nThe function\n\\begin{align}\n[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{solve\\_exact\\_fro}( \\mathbf M, \\Omega, \\tau, \\lambda, \\rho, iterations, tol ) \\notag\n\\end{align}\nsolve the following\n\\begin{align}\n\\min_{\\mathbf A, \\mathbf E} \\; \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|_F^2\\\\\n\\text{s.t.} \\; \\pro (\\mathbf M) = \\pro (\\mathbf A) + \\pro (\\mathbf E) \\nonumber \n\\end{align}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\Omega$ - vector of constrained matrix indices\n\\item $\\tau$ - regularisation (optional)\n\\item $\\lambda$ - regularisation (optional)\n\\item $\\rho$ - linearisation step size (optional)\n\\item $iterations$ - maximum number of iterations (optional)\n\\item $tol$ - stopping criteria tolerance (optional)\n\\end{itemize}\n\n\n\\newpage\n\\section{Principal Component Pursuit}\n\n\\subsection{PCP Gaussian}\n\\label{pcp_fro}\n\nThe function\n\\begin{align}\n[ \\mathbf A ] = \\text{pcp\\_fro}( \\mathbf M, \\lambda ) \\notag\n\\end{align}\nsolve the following\n\\begin{align}\n\\min_{\\mathbf{A, E}} \\; \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|_F^2\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\nonumber \n\\end{align}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\lambda$ - regularisation\n\\end{itemize}\n\n\\subsection{PCP Sparse}\n\\label{pcp_l1}\n\nThe function\n\\begin{align}\n[ \\mathbf A ] = \\text{pcp\\_l1}( \\mathbf M, \\lambda ) \\notag\n\\end{align}\nsolve the following\n\\begin{align}\n\\min_{\\mathbf{A, E}} \\; \\| \\mathbf A \\|_* + \\lambda \\| \\mathbf E \\|_1\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\nonumber \n\\end{align}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\lambda$ - regularisation\n\\end{itemize}\n\n\\subsection{PCP Column-wise Gaussian}\n\\label{pcp_l1l2}\n\nThe function\n\\begin{align}\n[ \\mathbf A ] = \\text{pcp\\_l1l2}( \\mathbf M, \\lambda ) \\notag\n\\end{align}\nsolves the following\n\\begin{align}\n\\min_{\\mathbf{A, E}} \\; \\| \\mathbf A \\|_* + \\lambda \\| \\mathbf E \\|_{1,2}\\\\\n\\text{s.t.} \\; \\mathbf { M = A + E } \\nonumber \n\\end{align}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\lambda$ - regularisation\n\\end{itemize}\n\n\\newpage\n\\section{Selective PCP}\n\\label{sel_pcp}\n\nThe function\n\\begin{align*}\n[ \\mathbf A ] = \\text{sel\\_pcp}( \\mathbf M, \\tau, \\lambda, \\Omega, \\Psi )\n\\end{align*}\nsolves the following\n\\begin{align*}\n\\min_{\\mathbf A, \\mathbf E} \\;  \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\mathbf E \\|^2_F \\\\\n\\text{s.t.} \\; \\pro(\\mathbf{M}) = \\pro(\\mathbf{A}) \\nonumber \\\\\n\\proa(\\mathbf{M}) = \\proa(\\mathbf{A}) + \\proa(\\mathbf E) \\nonumber \n\\end{align*}\n\n\\begin{itemize}\n\\item $\\mathbf M$ - matrix with observed entries\n\\item $\\tau$ - regularisation\n\\item $\\lambda$ - regularisation\n\\item $\\Omega$ - uncorrupted indices\n\\item $\\Psi$ - noisy indices\n\\end{itemize}\n\n\n%The function\n%\\begin{align}\n%[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{solve\\_mixed}( \\mathbf M, \\Omega, \\mathbf H, \\Omega_H, \\tau, \\mu, \\rho, iterations, tol ) \\notag \n%\\end{align}\n%solves the following\n%\\begin{align}\n%\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}{2} \\| \\proe(\\mathbf A) -  \\proe(\\mathbf H) \\|^2_F \\\\\n%\\text{s.t.} \\; \\pro(\\mathbf{M}) = \\pro(\\mathbf{A}) \\nonumber\n%\\label{objective}\n%\\end{align}\n%\n%\\begin{itemize}\n%\\item $\\mathbf M$ - matrix with observed entries\n%\\item $\\Omega$ - vector of constrained matrix indices\n%\\item $\\mathbf H$ - matrix with approximate entries\n%\\item $\\Omega_H$ - vector of approximately penalised indices\n%\\item $\\tau$ - regularisation (optional)\n%\\item $\\mu$ - step size (optional)\n%\\item $\\rho$ - linearisation step size (optional)\n%\\item $iterations$ - maximum number of iterations (optional)\n%\\item $tol$ - stopping criteria tolerance (optional)\n%\\end{itemize}\n%\n%\\subsection{Noisey Data}\n%\n%The functions\n%\\begin{align}\n%[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{solve\\_mixed\\_e}( \\mathbf M, \\Omega, \\mathbf H, \\Omega_H, \\tau, \\mu, \\rho, iterations, tol ) \\notag \\\\\n%[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{solve\\_mixed\\_e\\_ext}( \\mathbf M, \\Omega, \\mathbf H, \\Omega_H, \\tau, \\mu, \\rho, iterations, tol ) \\notag  \\\\\n%[ \\mathbf A, \\mathbf{f\\_vals}, \\mathbf{stop\\_vals} ] = \\text{solve\\_mixed\\_e\\_acc}( \\mathbf M, \\Omega, \\mathbf H, \\Omega_H, \\tau, \\mu, \\rho, iterations, tol ) \\notag \n%\\end{align}\n%solve the following\n%\\begin{align}\n%\\min_{\\mathbf A} \\; \\tau \\| \\mathbf A \\|_* + \\frac{\\lambda}2\\|\\proe(\\mathbf A) - \\proe(\\mathbf H) \\|^2_F +  \\frac{\\lambda_2}{2} \\| \\mathbf{ \\pro(E)} \\|^2_F \\\\\n%\\text{s.t.} \\; \\mathbf{\\pro(M) = \\pro(A) +  \\pro(E)} \\nonumber \n%\\end{align}\n%\n%\\begin{itemize}\n%\\item $\\mathbf M$ - matrix with observed entries\n%\\item $\\Omega$ - vector of constrained matrix indices\n%\\item $\\mathbf H$ - matrix with approximate entries\n%\\item $\\Omega_H$ - vector of approximately penalised indices\n%\\item $\\tau$ - regularisation (optional)\n%\\item $\\mu$ - step size (optional)\n%\\item $\\rho$ - linearisation step size (optional)\n%\\item $iterations$ - maximum number of iterations (optional)\n%\\item $tol$ - stopping criteria tolerance (optional)\n%\\end{itemize}\n\n\\newpage\n\\bibliographystyle{plain}\n\\bibliography{references}\n\n\\end{document}", "meta": {"hexsha": "d4139358d0f35810523f6486f1576e8594cd14bc", "size": 11403, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/docs.tex", "max_stars_repo_name": "sjtrny/pcpkit", "max_stars_repo_head_hexsha": "3b293295c60a08cb179ec95ef1fc08657cc9fc6e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 7, "max_stars_repo_stars_event_min_datetime": "2016-06-19T17:45:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T15:57:09.000Z", "max_issues_repo_path": "docs/docs.tex", "max_issues_repo_name": "sjtrny/pcpkit", "max_issues_repo_head_hexsha": "3b293295c60a08cb179ec95ef1fc08657cc9fc6e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/docs.tex", "max_forks_repo_name": "sjtrny/pcpkit", "max_forks_repo_head_hexsha": "3b293295c60a08cb179ec95ef1fc08657cc9fc6e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2017-12-04T00:58:47.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-23T08:50:02.000Z", "avg_line_length": 32.7672413793, "max_line_length": 170, "alphanum_fraction": 0.6546522845, "num_tokens": 4120, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896737173119, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7653079358498717}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Probability and Math Revision}\n\\label{ap:revision-probability}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Random variable}\nWe call random variable X a measurable real-valued  function of possible outcomes ($\\Omega$ ) defined on a sample space($E$).\n\n\\begin{equation}\n\tX: \\Omega \\rightarrow E\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Probability Density Function (PDF)}\n\nVariable X  is a continuous random variable if if there is a function $f (x) $, that satisfies for a set $B = \\{b \\in \\mathbb{R} | b_ {1} \\leq b \\leq b_ {2}\\} $, defined for all $x = \\{x \\in \\mathbb{R}| - \\infty \\leq x \\leq + \\infty\\} $, having the property: \n\\begin{equation}\n\tP(X \\in B) = \\int_{b_{1}}^{b_{2}}f(x) dx \n\\end{equation}\n\nWhere $P$ is the probability function of the random variable $x$. $f(x)$ is called probability density function of the random variable $X$\\cite{ross-probability}. \n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Cumulative Distribution Function (CDF)}\n\nThe Cumulative Distribution Function of a real-valued random variable $X$, is a function $F (x) $ defined by\\cite{ross-probability}: \n\n\n\\begin{equation}\nF(x) = P(X \\leq x) = \\int_{- \\infty}^{x}f(x) dx \n\\end{equation}\n\nWhere $f(x)$ is the probability density function (PDF) of $X$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Expected value, Mean, Variance and Standard Deviation}\n\nLet $X$ be a constinuous real-valued random variable, and $f(x)$ be its  probability density function (PDF). Then the expected value of $X$ is defined by:\n\n\\begin{equation}\nE[X] =  \\int_{- \\infty}^{+ \\infty}xf(x) dx \n\\end{equation}\n\n\nFor a random variable normally distributed $X_{normal}$ the result of this definition is equals to its mean $\\mu$ of the distribution.\n\n\\begin{equation}\nE[X_{normal}] = \\mu\n\\end{equation}\n\nFor an exponential distribution is equals to the inverse of its rate:\n\n\\begin{equation}\nE[X_{exponential}] = \\frac{1}{\\lambda}\n\\end{equation}\n\nThe variance of a random variable $X$, denoted by $Var(X)$, is defined by:\n\n\\begin{equation}\nvar(X) =  E[X^2] - (E[x])^{2} \n\\end{equation}\n\nFor a random variable $X$ normally distributed, the variance is equal to its standard deviation\\cite{ross-probability}: \n\n\\begin{equation}\nvar(X) = \\sigma^{2}\n\\end{equation}\n\nFor a finite data $X = \\{ x_1, x_2, ..., x_n \\}$set we can estimate the mean and standard deviation using the follow equations:\n\n\\begin{equation}\n\\mu = \\frac{1}{n}\\sum_{n}^{i=1}X_i\n\\end{equation}\n\n\\begin{equation}\n\\sigma = \\sqrt{\\frac{1}{n}[(x_1 - \\mu)^2 + (x_2 - \\mu)^2 + ... + (x_n - \\mu)^2]]}\n\\end{equation}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Stochastic Process}\n\nA stochastic process of a random variable represented by $\\{X(t)| t \\in T\\}$ is a collection of random variables. Since $t$ is often interpreted as time, $X (t) $ is usually referred as the state of the process at a given time $t$\\cite{ross-probability}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Correlation (Pearson correlation coefficient)}\n\nLetting $(X,Y)$ be a pai of real-valued random variables, the covariance is defined by:\n\n\\begin{equation}\ncov(X, Y) = E[(X-E[X])(Y - E[Y])]\n\\end{equation}\n\nAnd the Pearson's correlation coefficient is defined by:\n\n\\begin{equation}\ncor(X, Y) = \\frac{cov(X, Y)}{\\sigma_X \\sigma_Y}\n\\end{equation}\n\nWhere:\n\n\\begin{equation}\n\\sigma_X = \\sqrt{  E[X^2] - E[x]^{2} } \n\\end{equation}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Autocorrelation of a finite time series}\nThe autocorrelation function measures the correlation between data samples $y_{t}$ and $y_{t + k}$, where $k =0, ..., K$, and the data sample $\\{y\\}$  is generated by a stochastic process.\n\nAccording to \\cite{book-time-series-analysis}, the autocorrelation for a lag $k$ is:\n\n\\begin{equation}\nr_{k} = \\frac{c_{k}}{c_{0}}\n\\end{equation}\n\nwhere \n\n\\begin{equation}\nc_{k} = \\frac{1}{T - 1}\\sum_{t = 1}^{T - k} (y_{t} - \\bar{y})(y_{t+k} - \\bar{y})\n\\end{equation}\n\nand $c_{0}$ is the sample variance of the time series. \n\t\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Self-similarity}\n\nA self similar object has the property of looking \"roughly\" the same at any scale. Self-similar objects are described by the power law:\n\n\\begin{equation}\n\tN = s^{d}\n\\end{equation}\n\nwhere \n\\begin{equation}\n\td = \\frac{\\ln{N}}{\\ln{s}}\n\\end{equation}\n\nis the dimension of the scaling law, called  Hausdorff dimension\\cite{web-self-similar}. \n\n\n\\begin{figure*}[ht!]\n\t\\centering\n\t\\includegraphics[height=2.5in]{figures/apA/tritrans}\n\t\\caption{This is a classical example of a self-similar figure, caled Sierpinski triangle.}\n\t\\label{fig:self-similar-figure-example}\n\\end{figure*}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Hurst Exponent}\n\n\nFor a time-series $X = \\{ X_1, X_2, ..., X_n \\}$, letting $m$ be the time series mean:\n\n\\begin{equation}\n\\mu = \\frac{1}{n}\\sum_{n}^{i=1}X_i\n\\end{equation}\n\n\nWe can calculate the adjusted series $Y$ by:\n\n\\begin{equation}\nY = \\{ Y_t \\} = \\{ X_t - \\mu \\}\n\\end{equation}\n\nfor $t = 1, 2, ..., n $. We can calculate the  cumulative deviate series $Z$ by:\n\n\n\\begin{equation}\nZ_t = \\sum_{t}^{1}Y_i, \\quad t = 1, 2, ..., n \n\\end{equation}\n\nWe can than calculate the time series range by:\n\n\\begin{equation}\nR(n) = max(Z_1, Z_2, ..., Z_n) - min(Z_1, Z_2, ..., Z_n)\n\\end{equation}\n\nAnd its standard deviation by:\n\n\\begin{equation}\nS(n) = \\sqrt{\\frac{1}{n}\\sum_{i=1}^{n}(X_i -  \\mu)^{2}}\n\\end{equation}\n\n\nLetting $E[x]$ be the expected value of a real-valued random variable  $X$, and $C$ a constant, the Hurst Exponent $H$ is defined by\\cite{hurst-def}:\n\n\\begin{equation}\nE\\left [  \\frac{R(n)}{S(n)} \\right ] = Cn^{H}, \\quad n \\to \\infty \n\\end{equation}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Heavy-tailed distributions}\n\nHeavy tailed distributions are probability distributions whose tails are not exponentially bounded.  A distribution of of a real-valued random variable $X$, with cumulative distribution F(x), is said to be heavy tailed, if it satisfies this condition for all $\\lambda \\in \\mathbb{R}$:\n\n\\begin{equation}\n\t\\lim_{x\\to\\infty} e^{\\lambda x} (1 - F(x)) = \\infty\n\\end{equation}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{\\textit{QQplot} analysis}\n\nQQplot is used to test if two data-sets comes from a common distribution\\cite{web-qqplot}. In our study case, we used to compare empirical data with theoretical given by model approximations. We show down below the image presented in chapter~\\ref{ch:literature-review} for reference. \nLooking on how the dot plot behaves compared to the linear line, we can see how well the theoretical plot (the estimated data, on the horizontal axis) represents the actual values (sample data, vertical axis):\n\n\\begin{itemize}\n\\item \\textbf{Light-tailed}: the samples still hold a slight heavy-tail effect compared to the estimated by the theoretical values.\n\\item \\textbf{Heavy-tailed}: the samples have a predominant heavy-tail effect compared to the estimated by the theoretical values.\n\\item \\textbf{Linear}: the samples match the theoretical values.\n\\item \\textbf{Bimodal}: samples present a bimodal pattern.\n\\item \\textbf{Left skew}: small values are under-represented by the model(~\\ref{fig:qqplot-rl-skew}).\n\\item \\textbf{Right skew}: larger values are under-represented by the model(~\\ref{fig:qqplot-rl-skew}).\n\\end{itemize}\n\n\n\nAs an example, we created a \\textit{QQplot} (figure ~\\ref{fig:qq-cauchy}), where we used as samples randomly generated data, generated by a Cauchy, and theoretical values, normal random data. Comparing with the figure ~\\ref{fig:qqplot-tutorial-ap}, we can identify a heavy tail behavior on the sample data.\n\n\n\n\\begin{figure*}[ht!]\n\t\\centering\n\t\\includegraphics[width=0.55\\textwidth]{figures/ch2/qqplot-tutorial}\n\t\\caption{How information about data samples can be extracted from \\textit{QQplots}. Depending on the shape of the dot plot,  }\n\t\\label{fig:qqplot-tutorial-ap}\n\\end{figure*}\n\n\\begin{figure*}[ht!]\n\t\\centering\n\t\\includegraphics[width=0.5\\textwidth]{figures/apA/rl-skew}\n\t\\caption{Shape of a distribution with right and left skew.}\n\t\\label{fig:qqplot-rl-skew}\n\\end{figure*}\n\n\\begin{figure}[t!]\n    \\centering\n    %\\subfloat[]{\n        \\includegraphics[width=60mm]{figures/apA/qq-c1}\n    %    \\label{fig:qq-cauchy-1}\n    %}\n    \\hspace{0mm}\n    %\\subfloat[]{\n        \\includegraphics[width=60mm]{figures/apA/qq-c2}\n    %    \\label{fig:qq-cauchy-2}\n    %}\n    \\caption{QQplot of randomly generated data of a Cauchy process as samples and a normal process as theoretical. We can identify a heavy-tail behavior on the samples, compared to the theoretical.}\n    \\label{fig:qq-cauchy}\n\\end{figure}\n\n\n\nTo generate the plots in figure~\\ref{fig:qq-cauchy}, we used Python and the libraries matplotlib and numpy. The code used is shown down below: \n\n\n\\begin{minted}{python}\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nnn = sorted(np.random.standard_normal(30))\ncc = sorted(np.random.standard_cauchy(30))\nnn_max = max(nn)\nnn_min = min(nn)\ncc_max = max(cc)\ncc_min = min(cc)\nyy = np.linspace(cc_min, cc_max, num=10)\nxx = np.linspace(nn_min, nn_max, num=10)\nfig, ax = plt.subplots()\nax.plot(nn, cc, 'bo', markersize=10.0)\nax.plot(xx, yy, 'r-', linewidth=4.0)\nplt.xlabel('estimated (normal data)')\nplt.ylabel('samples (cauchy data)')\nplt.tick_params(labelsize=14)\nplt.tight_layout()\nplt.show()\n\\end{minted}\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Akaike information criterion (AIC) and Bayesian information criterion (BIC)}\n\nSuppose that we have an statistical model $M$ of some dataset ${\\boldsymbol{x} = \\{x_1, ..., x_n}\\}$, with $n$ independent and identically distributed observations of a random variable $X$. This model can be expressed by a PDF $f(x| \\boldsymbol{\\theta})$, where $\\boldsymbol{\\theta}$ a vector of parameter of the PDF, $\\boldsymbol{\\theta} \\in \\mathbb{R}^{k}$ ($k$ is the number of parameters). The  likelihood function  of this model $M$ is given by:\n\n\\begin{equation}\nL(\\boldsymbol{\\theta}|\\boldsymbol{x} ) =  f(x_1|\\boldsymbol{\\theta})\\cdot...\\cdot f(x_n|\\boldsymbol{\\theta}) = \\prod_{i = 1}^{n}f(x_i|\\boldsymbol{\\theta})\n\\end{equation}\n\nNow, suppose we are trying to estimate the best statistical model, from a set ${M_1, ..., M_n}$, each one whit an estimated vector of parameters  ${\\boldsymbol{\\hat{\\theta_1}}}, ..., {\\boldsymbol{\\hat{\\theta_n}}}$. $AIC$ and $BIC$ are defined by:\n\n\\begin{equation}\n\\label{eq:aic-ap}\nAIC = 2k - \\ln(L(\\boldsymbol{\\hat{\\theta}}|\\boldsymbol{x}))\n\\end{equation}\n\n\\begin{equation}\n\\label{eq:bic-ap}\nBIC = k\\ln(n) - \\ln(L(\\boldsymbol{\\hat{\\theta}}|\\boldsymbol{x}))\n\\end{equation}\n\nIn both cases, the preferred model $M_i$, is the one with the smaller value of $AIC_i$ or $BIC_i$.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Gradient Descendent Algorithm}\n\nGiven a linear hypothesis for a dataset:\n\n\\begin{equation}\n\t\\boldsymbol{h_{\\theta}} = \\boldsymbol{\\theta}^{T}\\boldsymbol{x} \n\\end{equation}\n\nwere $\\boldsymbol{h_{\\theta}}, \\boldsymbol{\\theta}, \\boldsymbol{x} \\in \\mathbb{R}^{m}$. If $m = 2$ we will just have a simple linear equation $h_{\\theta}(x) = \\theta_{0} + \\theta_{1}x$.\n\nThe goal of the gradient descendent is to minimize the cost function $J_\\nabla(\\boldsymbol{\\theta})$, defined by:\n\n\\begin{equation}\n\tJ_\\nabla(\\boldsymbol{\\theta}) = \\frac{1}{2m} \\sum_{i = 1}^{m}  ( \\boldsymbol{h_{\\theta}}(x^{(i)} - y^{(i)} )^{2}\n\\end{equation}\n\n\nTo do this, we initialize a $\\boldsymbol{\\theta_{j}}$ vector (usually with zeros), and repeat this procedure, until $\\boldsymbol{\\theta_{j}}$ converges:\n\n\\begin{equation}\n\t\\boldsymbol{\\theta_{j + 1}} := \\boldsymbol{\\theta_{j}} - \\alpha \\frac{1}{m} \\sum_{i = 1}^{m}  ( \\boldsymbol{h_{\\theta}}(x^{(i)} - y^{(i)} )x_{j}^{i}\n\\end{equation}\n\nwhere $\\alpha$ is the step value, typically a small positive number. All values of $\\boldsymbol{\\theta_{j}}$ must be updated simultaneously\\cite{web-coursera}. \n\n\n", "meta": {"hexsha": "00f2b51a4ced88c9629da009f08b48ae2a77cc90", "size": 12519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/appendix/appendixA.tex", "max_stars_repo_name": "AndersonPaschoalon/MasterDegreeThesis-ptBr", "max_stars_repo_head_hexsha": "e4cbf752deecf124aa0adfc630d510645d8c4ea6", "max_stars_repo_licenses": ["MIT"], "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/appendix/appendixA.tex", "max_issues_repo_name": "AndersonPaschoalon/MasterDegreeThesis-ptBr", "max_issues_repo_head_hexsha": "e4cbf752deecf124aa0adfc630d510645d8c4ea6", "max_issues_repo_licenses": ["MIT"], "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/appendix/appendixA.tex", "max_forks_repo_name": "AndersonPaschoalon/MasterDegreeThesis-ptBr", "max_forks_repo_head_hexsha": "e4cbf752deecf124aa0adfc630d510645d8c4ea6", "max_forks_repo_licenses": ["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.8205882353, "max_line_length": 450, "alphanum_fraction": 0.6336768112, "num_tokens": 3576, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505428129514, "lm_q2_score": 0.8459424373085145, "lm_q1q2_score": 0.7652822850996588}}
{"text": "\\lab{The Arnoldi Iteration}{The Arnoldi Iteration}\n\\label{lab:kry_arnoldi}\n\n\\objective{Use Krylov subspaces to find eigenvalues of extremely large matrices.}\n\nOne of the biggest difficulties in computational linear algebra is the amount of memory needed to store a large matrix and the amount of time needed to read its entries.\nMethods using Krylov subspaces avoid this difficulty by studying how a matrix acts on vectors, making it unnecessary in many cases to create the matrix itself.\n\nThe \\emph{Arnoldi iteration} is an algorithm for finding an orthonormal basis of a Krylov subspace.\nOne of its strengths is it can run on any linear operator without knowing the operator's underlying matrix representation.\nThe outputs of the Arnoldi algorithm can be used to approximate the eigenvalues of the matrix of the linear operator.\n\n\\section*{Krylov Subspaces} % =================================================\n\nThe order-$N$ Krylov subspace of $A$ generated by $\\x$ is\n\\[\n\\mathcal{K}_n(A, \\x) =\\text{span} \\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}.\n\\]\nIf the vectors $\\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}$ are linearly independent, then they form a basis for $\\mathcal{K}_n(A,\\x)$.\nHowever, this basis is usually far from orthogonal, and hence computations using this basis will likely be ill-conditioned.\n\n\\section*{The Arnoldi Iteration Algorithm} % ==================================\n\nOne way to find an orthonormal basis for $\\mathcal{K}_n(A,\\x)$ is to use the modified Gram-Schmidt algorithm from Lab \\ref{lab:QRdecomp} on the set $\\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}$.\nThe Arnold iteration does this more efficiently by integrating the creation of $\\{\\x, A\\x, A^2\\x, \\ldots, A^{n-1}\\x\\}$ with the modified Gram-Schmidt algorithm. It returns an orthonormal basis for $\\mathcal{K}_n(A,\\x)$. This algorithm is described in Algorithm \\ref{alg:arnoldi_iteration}.\n\n\\begin{comment}\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 its completion to find a full basis.\nOur goal is to find an orthonormal set of vectors $q_1,\\ldots,q_N$ having the same span as $x, Ax, A^2x, \\ldots, A^{N-1} x$.\nWe start\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 orthonormal 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\\end{comment}\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Arnoldi}{$\\b, A, k, tol$}\n\t\\State $Q \\gets \\allocate{\\size{\\b}}{k+1}$\t\t\t\\Comment{Some initialization steps}\n\t\\State $H \\gets \\zeros{ k+1}{ k}$\n\t\\State $Q[:,0] \\gets \\b/\\norm{\\b}_2$\n\t\\For{$j=0\\ldots k-1$}\t\t\t\t\t\t\t\\Comment{Perform the actual iteration.}\n\t\t\\State $Q[:,j+1] \\gets AQ[:,j]$\n\t\t\\For{$i=0\\ldots j$}\t\t\t\t\t\\Comment{Modified Gram-Schmidt.}\n\t\t\t\\State $H[i,j] \\gets Q[:,i]\\trp Q[:,j+1]$\n\t\t\t\\State $Q[:,j+1] \\gets Q[:,j+1] - H[i,j] Q[:,i]$\n\t\t\\EndFor\n\t\t\\State $H[j+1,j] \\gets \\norm{Q[:,j+1]}_2$\t\t\t\\Comment{Set subdiagonal element of $H$.}\n            \\If{$|H[j+1,j]|<tol$}\t\t\t\t\t\\Comment{Stop if $\\norm{Q[:,j+1]}_2$ is too small.}\n\t\t\t\\State \\pseudoli{return} $H[:j+1,:j+1]$, $Q[:,:j+1]$\n\t\t\\EndIf\n\t\t\\State $Q[:,j+1] \\gets Q[:,j+1]/H[j+1,j]$\t\t\t\t\\Comment{Normalize $\\q_{j+1}$.}\n\t\\EndFor\n\t\\State \\pseudoli{return} $H[:-1, :]$, $Q$\t\t\t\\Comment{Return $H_{k}$.}\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Arnoldi Iteration. This algorithm accepts a square matrix $A$ and starting vector $\\b$. It iterates $k$ times or until the norm of the next vector in the iteration is less than $tol$.\nThe algorithm returns upper Hessenberg $H$ and orthonormal $Q$ such that $H = Q^{\\mathsf{H}}AQ$.}\n\\label{alg:arnoldi_iteration}\n\\end{algorithm}\n\nIn Algorithm \\ref{alg:arnoldi_iteration}, $k$ is the number of times we multiply by $A$.\nThis will result in an order-$k+1$ Krylov subspace.\n\nSomething perhaps unexpected happens in the Arnoldi iteration if the starting vector $\\x$ is an eigenvector of $A$.\nIf the corresponding eigenvalue is $\\lambda$, then by definition $\\mathcal{K}_k(A, \\x)=\\text{span}\\{\\x, \\lambda \\x, \\lambda^2\\x, \\ldots, \\lambda^k \\x\\}$, which is equal to the span of $\\x$.\nLet us trace through Algorithm \\ref{alg:arnoldi_iteration} in this case. We will use $\\q_i$ to denote the $i^{th}$ column of $Q$.\n\nIn line 4 we normalize $\\x$, setting $\\q_1 = \\x/\\|\\x\\|$.\nIn line 6 we set $\\q_2 = A\\q_1 = \\lambda \\q_1$.\nThen in line 8\n\\[\nH_{1,1} = \\langle \\q_1, \\q_2 \\rangle = \\langle \\q_1, \\lambda \\q_1 \\rangle = \\lambda \\langle \\q_1, \\q_1 \\rangle = \\lambda,\n\\]\nso in line 9 we subtract $\\lambda \\q_1$ from $\\q_2$, ending with $\\q_2=0$.\n\nThe vector $\\q_2$ is supposed to be the next vector in the orthonormal basis for $\\mathcal{K}_k(A, \\x)$, but since it is 0, it is not linearly independent of $\\q_1$. In fact, $\\q_1$ already spans $\\mathcal{K}_k(A, \\x)$.\nHence, when in line 11 we find that the norm of $\\q_2$ is zero (or close to it, allowing for numerical error), we terminate the algorithm early, returning the $1\\times 1$ matrix $H = H_{1, 1}=\\lambda$ and the $n\\times 1$ matrix $Q = \\q_1$.\n\nA similar phenomenon may occur if the starting vector $\\x$ is contained in a proper invariant subspace of $A$.\n\n\\section*{Arnoldi Iteration on Linear Operators} % ============================\n\nA major strength of the Arnoldi Iteration is that it can run on a linear operator, even without knowing the matrix representation of the operator. If $A_{mul}$ is some linear function, then we can modify the pseudocode above by replacing $AQ[:,j]$ with $A_{mul}(Q[:,j])$. This will make it possible to find the eigenvalues of an arbitrary linear transformation. We will use this method in the problem below.\n\n\\begin{problem}\\label{prob:arnoldi}\nUsing Algorithm \\ref{alg:arnoldi_iteration}, complete the following Python function that performs the Arnoldi iteration.\nWrite this function so that it can run on complex arrays.\n\n\\begin{lstlisting}\ndef arnoldi(b, Amul, k, tol=1e-8):\n    \"\"\"Perform `k' steps of the Arnoldi iteration on the linear operator\n    defined by `Amul', starting with the vector 'b'.\n\n    Inputs:\n        b (ndarray): The starting vector for the iteration.\n        Amul (function): A function handle that describes a linear operator.\n        k (int): The number of times to perform the iteration.\n        tol (float): Stop iterating if the next vector in the iteration has\n            norm less than `tol'. Defaults to 1e-8.\n\n    Returns:\n        H_n (ndarray)\n        Q_n (ndarray)\n            The number n will equal k, unless the algorithm terminated early,\n            in which case n will be less than k.\n\n    Examples:\n        >>> A = np.array([[1,0,0],[0,2,0],[0,0,3]])\n        >>> Amul = lambda x: A.dot(x)\n        >>> H, Q = arnoldi(np.array([1,1,1]), Amul, 3)\n        >>> np.allclose(H, np.conjugate(Q.T).dot(A).dot(Q) )\n        True\n\n        >>> H, Q = arnoldi(np.array([1,0,0]), Amul, 3)\n        >>> H\n        array([[ 1.+0.j]])\n        >>> np.conjugate(Q.T).dot(A).dot(Q)\n        array([[ 1.+0.j]])\n    \"\"\"\n\\end{lstlisting}\n\nHints:\n\\begin{enumerate}\n\\item Since \\li{H} and \\li{Q} will eventually hold complex numbers, initialize them as complex arrays (e.g., \\li{A = np.empty((3,3), dtype=np.complex128)}).\n\\item Remember to use complex inner products.\n\\item This function can be tested on a matrix A by passing in \\li{A.dot} for \\li{Amul}.\n\\end{enumerate}\n\\end{problem}\n\n\\section*{Finding Eigenvalues Using Arnoldi Iteration} % ======================\n\nLet $A$ be an $n \\times n$ matrix.\nLet $Q_k$ be the matrix whose columns $\\q_1, \\ldots, \\q_k$ are the orthonormal basis for $\\mathcal{K}_m(A, \\x)$ generated by the Arnoldi algorithm, and\nlet $H_k$ be the $k\\times k$ upper Hessenburg matrix defined at the $k^{th}$ stage of the algorithm.\nThen these matrices satisfy\n\\begin{equation}\\label{equ:hqa}\nH_k = Q_k^{\\mathsf H} A Q_k.\n\\end{equation}\nIf $k<n$, then $H_k$ is a low-rank approximation to $A$.\nWe may use its eigenvalues as approximations to the eigenvalues of $A$.\nThe eigenvalues of $H_k$ are called \\emph{Ritz values}, and in fact they converge quickly to the largest eigenvalues of $A$.\n\n\\begin{problem}\\label{prob:ritz}\nFinish the following function that computes the Ritz values of a matrix.\n\n\\begin{lstlisting}\ndef ritz(Amul, dim, k, iters):\n    \"\"\"Find `k' Ritz values of the linear operator defined by `Amul'.\n\n    Inputs:\n        Amul (function): A function describing a linear operator on R^(dim).\n        dim (int): The dimension of the space on which `Amul' acts.\n        k (int): The number of Ritz values to return.\n        iters (int): The number of times to perform the Arnoldi iteration.\n            Must be between `k' and `dim'.\n\n    Returns:\n        ((k,) ndarray): `k' Ritz values of the operator defined by `Amul.'\n    \"\"\"\n\\end{lstlisting}\n\\end{problem}\n\nOne application of the Arnoldi iteration is to find the eigenvalues of linear operators that are too large to store in memory.\nFor example, if an operator acts on $\\mathbb{C}^{2^{20}}$, then its matrix representation contains $2^{40}$ complex values.\nStoring such a matrix would require 64 terabytes of memory!\n\nAn example of such an operator is the Fast Fourier Transform, cited by SIAM as one of the top algorithms of the century \\cite{Cipra2000}.\nThe Fast Fourier Transform is used ubiquitously in the field of signal processing.\n\n\\begin{problem}\n\\label{prob:fourier_eigs}\nThe four largest eigenvalues of the Fast Fourier Transform are known to be $\\{ -\\sqrt{N}, \\sqrt{N}, -i\\sqrt{N}, i\\sqrt{N} \\}$ where $N$ is the dimension of the space on which the transform acts.\nUse your function \\li{ritz()} from Problem \\ref{prob:ritz} to approximate the eigenvalues of the Fast Fourier Transform.\nSet \\li{k} to be 10 and set \\li{dim} to be $2^{20}$.\nFor the argument \\li{Amul}, use the \\li{fft} function from \\li{scipy.fftpack}.\n\\end{problem}\n\nThe Arnoldi iteration for finding eigenvalues is implemented in a Fortran library called ARPACK.\nSciPy interfaces with the Arnoldi iteration in this library via the function \\li{scipy.sparse.linalg.eigs()}.\nThis function has many more options than the implementation we wrote in Problem \\ref{prob:ritz}.\nIn this example, the keyword argument \\li{k=5} specifies that we want five Ritz values.\nNote that even though this function comes from the \\li{sparse} library in SciPy, we can still call it on regular NumPy arrays.\n\n\\begin{lstlisting}\n>>> B = np.random.rand(10000).reshape(100, 100)\n>>> sp.sparse.linalg.eigs(B, k=5, return_eigenvectors=False)\narray([ -1.15577072-2.59438308j,  -2.63675878-1.09571889j,\n        -2.63675878+1.09571889j,  -3.00915592+0.j        ,  50.14472893+0.j ])\n\\end{lstlisting}\n\n\\subsection*{Convergence} % ---------------------------------------------------\n\nThe Arnoldi method for finding eigenvalues quickly converges to eigenvalues whose magnitude is distinctly larger than the rest.\nFor example, matrices with random entries tend to have one eigenvalue of distinctly greatest magnitude.\nConvergence of the Ritz values for such a matrix is plotted in Figure \\ref{fig:arnoldi_random_val_conv}.\n\nHowever, Ritz values converge more slowly for matrices with random eigenvalues.\nFigure \\ref{fig:arnoldi_random_eig_conv} plots convergence of the Ritz values for a matrix with eigenvalues uniformly distributed in $[0,1)$.\n\n\\begin{figure}\n\\centering\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rand_vals_conv.pdf}\n    \\caption{The blue line plots the error of the Ritz value of largest magnitude.\n    This eigenvalue converges after fewer than 20 iterations}\n    \\label{fig:arnoldi_random_val_conv}\n\\end{subfigure}\n\\begin{subfigure}[b]{.49\\textwidth}\n    \\centering\n    \\includegraphics[width=\\textwidth]{figures/rand_eigs_conv.pdf}\n    \\caption{All Ritz values have roughly equivalent magnitude.\n    They take from 150 to 250 iterations to converge. }\n    \\label{fig:arnoldi_random_eig_conv}\n\\end{subfigure}\n\\caption{These plots show the relative error of the Ritz values as approximations to the eigenvalues of a matrix.\nThe figure at left plots the largest 15 Ritz values for a $500\\times 500$ matrix with random entries.\nThe figure at right plots the largest 15 Ritz values for a $500\\times 500$ matrix with uniformly distributed eigenvalues.}\n\\end{figure}\n\n% TODO: this problem may be too difficult.\n\\begin{problem}\nFinish the following function to visualize the convergence of the Ritz values.\n\n\\begin{lstlisting}\ndef plot_ritz(A, n, iters):\n    \"\"\"Plot the relative error of the Ritz values of `A'. Use the number of\n    iterations as the x-axis and the relative error of the Ritz values of H_k\n    a approximations to the eigenvalues of A as the y-axis.\n\n    Inputs:\n        A (ndarray)\n        n (int): The number of Ritz values to plot.\n        iters (int): The number of times to perform the Arnoldi iteration.\n    \"\"\"\n    \\end{lstlisting}\n\nIf $\\tilde{\\x}$ is an an approximation to $\\x$, then the \\emph{absolute error} in the approximation is\n\\[\n\\frac{\\|\\x - \\tilde{\\x}\\|}{\\|\\x\\|}.\n\\]\nHint: The most difficult part of this problem is to identify which Ritz values correspond to which eigenvalues.\nAfter finding the Ritz values (or eigenvalues) of largest magnitude, use \\li{np.sort()} to put them in order.\nMake sure that this order is preserved throughout your program.\n\nIt may help to use the following algorithm.\n\\begin{enumerate}\n    \\item Find $n$ eigenvalues of $A$ of largest magnitude. Store these in order.\n    \\item Create an empty array to store the relative errors. For every $k \\in $\\li{[1, iters)},\n    \\begin{enumerate}\n        \\item Compute $H_k$ with the Arnoldi iteration.\n        \\item Find $n$ eigenvalues of $A$ of largest magnitude. Note that for small $k$, the matrix $H_k$ may not have this many eigenvalues.\n        \\item Store the absolute error. Make sure that the errors are stored in the correct order. For small $k$, some entries in the row or column may not be used.\n    \\end{enumerate}\n    \\item Use array broadcasting to compute the absolute error.\n    \\item Iteratively plot the errors. Lines for distinct eigenvalues should start at different places on the x-axis.\n\\end{enumerate}\n\nRun your function on these examples.\nThe plots should be fairly similar to Figures \\ref{fig:arnoldi_random_eig_conv} and \\ref{fig:arnoldi_random_val_conv}.\n\n\\begin{lstlisting}\n>>> # A matrix with random entries\n>>> A = np.random.rand(300, 300)\n>>> plot_ritz(A, 10, 175)\n>>>\n>>> # A matrix with uniformly distributed eigenvalues\n>>> D = np.diag(np.random.rand(300))\n>>> B = A.dot( D.dot(la.inv(A)) )\n>>> plot_ritz(B, 10, 175)\n\\end{lstlisting}\n\nIf your code takes too long to run, consider integrating your solutions to Problems \\ref{prob:arnoldi} and \\ref{prob:ritz} with the body of this function.\n\\end{problem}\n\n% Once the eigenvalue lab has been rewritten, have them use their own solver to find the eigenvalues of the $H_k$.\n\n% This problem is very ill-conditioned.\n\\begin{comment}\n\\begin{problem}\nFinding the roots of a polynomial can be represented as an eigenvalue problem.\nFinding the roots of a monic polynomial (a polynomial with leading coefficient 1) $p = c_0 + c_1 x + \\dots + c_{n-1} x^{n-1} + x^n$ is equivalent to finding the eigenvalues of the matrix\n\\[C = \\begin{bmatrix}\n0 & 0 & \\dots & 0 & -c_0 \\\\\n1 & 0 & \\dots & 0 & -c_1 \\\\\n0 & 1 & \\dots & 0 & -c_2 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\vdots \\\\\n0 & 0 & \\dots & 1 & -c_{n-1} \\end{bmatrix}\\]\nThis matrix is called the companion matrix of the polynomial $p$.\nAs it happens, every matrix is similar to the companion matrix of its characteristic polynomial, but we won't use that fact here.\n\nThe following is a function that, given an array containing the coefficients $c_0, c_1, \\dots, c_{n-1}$ for a monic polynomial $p$, performs matrix multiplication by the corresponding companion matrix.\n\n\\begin{lstlisting}\ndef companion_multiply(c, u):\n    v = np.empty_like(u)\n    v[0] = - c[0] * u[-1]\n    v[1:] = u[:-1] - c[1:] * u[-1]\n    return v\n\\end{lstlisting}\n\nUse the Arnoldi iteration to estimate the five zeros of largest norm of a degree $1000$ monic polynomial with randomly chosen coefficients (the leading coefficient still needs to be 1).\nRun $50$ steps of the Arnoldi iteration.\nCompare your results with the roots of the polynomial computed using NumPy's \\li{poly1d} class.\nThis computation can be done like this (where \\li{c} is the array of random coefficients for the polynomial)\n\n\\begin{lstlisting}\np = np.poly1d([1] + list(c[::-1]))\nroots = p.roots\n# Now sort by absolute value from largest to smallest\nroots = roots[np.absolute(roots).argsort()][::-1]\n\\end{lstlisting}\n\nHow close are the first few zeros of largest norm?\n\\end{problem}\n\\end{comment}\n\n\\section*{Lanczos Iteration (Optional)} % =====================================\n\nThe Lanczos iteration is a version of the Arnoldi iteration that is optimized to operate on symmetric matrices.\nIf A is symmetric, then \\eqref{equ:hqa} shows that $H_k$ is symmetric and hence tridiagonal.\nThis leads to two simplifications of the Arnoldi algorithm.\n\nFirst, we have $0=H_{k, n}=\\langle \\q_k, A\\q_n \\rangle$ for $k \\leq n-2$; i.e., $A\\q_n$ is orthogonal to $\\q_1, \\ldots, \\q_{n-2}$.\nThus, if the goal is only to compute $H_k$ (say to find the Ritz values), then we only need to store the two most recently computed columns of $Q$.\nSecond, the data of $H_k$ can also be stored in two vectors, one containing the main diagonal and one containing the first subdiagonal of $H_k$.\n(By symmetry, the first superdiagonal equals the first subdiagonal of $H_k$.)\n\nThe Lanczos iteration is found in Algorithm \\ref{alg:lanczos_iteration}.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Lanczos}{$\\b, A, k, tol$}\n\t\\State $\\q_0 \\gets \\zeros{\\size{\\b}}$\t\t\t\t\t\t\t\t\\Comment{Some initialization}\n\t\\State $\\q_1 \\gets \\b/\\norm{\\b}_2$\n\t\\State $\\x \\gets \\allocate{k}$\n\t\\State $\\y \\gets \\allocate{k}$\n\t\\For{$i=0\\ldots k-1$}\t\t\t\t\t\t\t\t\t\\Comment{Perform the iteration.}\n\t\t\\State $\\z \\gets A\\q_1$\t\t\t\t\t\\Comment{$\\z$ is a temporary vector to store $\\q_{i+1}$.}\n\t\t\\State $\\x[i] \\gets \\q_1\\trp \\z$\t\t\t\t\\Comment{$\\q_1$ is used to store the previous $\\q_i$.}\n\t\t\\State $\\z \\gets \\z - \\x[i] \\q_1 + \\y[i-1] \\q_0$\t\t\t\t\\Comment{$\\q_0$ is used to store $\\q_{i-1}$.}\n\t\t\\State $\\y[i] = \\norm{\\z}_2$\t\t\t\t\t\t\\Comment{Initialize $\\y[i]$.}\n\t\t\\If{$\\y[i]<tol$}\t\t\t\t\t\t\t\t\\Comment{Stop if $\\norm{ \\q_{i+1}}_2$ is too small.}\n\t\t\t\\State \\pseudoli{return} $\\x[: i+1]$, $\\y[: i]$\n\t\t\\EndIf\n\t\t\\State $\\z = \\z/ \\y[i]$\n\t\t\\State $\\q_0, \\q_1 = \\q_1, \\z$\t\t\t\t\t\t\\Comment{Store new $\\q_{i+1}$ and $\\q_i$ on top of $\\q_1$ and $\\q_0$.}\n\t\\EndFor\n\t\\State \\pseudoli{return} $\\x$, $\\y[: -1]$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{The Lanczos Iteration. This algorithm operates on a vector $\\b$ of length $n$ and an $n \\times n$ symmetric matrix $A$. It iterates $k$ times or until the norm of the next vector in the iteration is less than $tol$. It returns two vectors $\\x$ and $\\y$ that respectively contain the main diagonal and first subdiagonal of the current Hessenberg approximation.}\n\\label{alg:lanczos_iteration}\n\\end{algorithm}\n\n\\begin{problem}\n\\label{prob:lanczos}\nImplement Algorithm \\ref{alg:lanczos_iteration} by completing the following function.\nWrite it so that it can operate on complex arrays.\n\\begin{lstlisting}\ndef lanczos(b, Amul, k, tol=1E-8):\n    '''Perform `k' steps of the Lanczos iteration on the symmetric linear\n    operator defined by `Amul', starting with the vector 'b'.\n\n    INPUTS:\n    b    - A NumPy array. The starting vector for the Lanczos iteration.\n    Amul - A function handle. Should describe a symmetric linear operator.\n    k    - Number of times to perform the Lanczos iteration.\n    tol  - Stop iterating if the next vector in the Lanczos iteration has\n          norm less than `tol'. Defaults to 1E-8.\n\n    RETURN:\n    Return (alpha, beta) where alpha and beta are the main diagonal and\n    first subdiagonal of the tridiagonal matrix computed by the Lanczos\n    iteration.\n    '''\n\\end{lstlisting}\n\\end{problem}\n\nAs it is described in Algorithm \\ref{alg:lanczos_iteration}, the Lanczos iteration is not stable.\nRoundoff error may cause the $\\q_i$ to be far from orthogonal.\nIn fact, it is possible for the $\\q_i$ to be so adulterated by roundoff error that they are no longer linearly independent.\n% If needed we could make a separate lab on the Lanczos iteration and the Implicitly Restarted Lanczos Method.\n% There isn't time or space here for it though.\n\n\\begin{problem}\nThe following code performs multiplication by a tridiagonal symmetric matrix.\n\n\\begin{lstlisting}\ndef tri_mul(a, b, u):\n   ''' Return Au where A is the tridiagonal symmetric matrix with main\n   diagonal a and subdiagonal b.\n   '''\n    v = a * u\n    v[:-1] += b * u[1:]\n    v[1:] += b * u[:-1]\n    return v\n\\end{lstlisting}\n\nLet $A$ be a $1000\\times 1000$ symmetric tridiagonal matrix with random values in its nonzero diagonals.\nUse the function \\li{lanczos()} from Problem \\ref{prob:lanczos} with 100 iterations to estimate the 5 eigenvalues of $A$ of largest norm.\nCompare these to the 5 largest true eigenvalues of $A$\n\nIf you do this problem for different vectors $a$ and $b$, you may notice that occasionally the largest Ritz value is repeated.\nThis happens because the vectors used in the Lanczos iteration may not be orthogonal.\nThese erroneous eigenvalues are called ``ghost eigenvalues.\"\n%They generally converge to actual eigenvalues of the matrix and can make the multiplicity of an eigenvalue look higher than it really is.\n\\end{problem}\n\nThere are modified versions of the Lanczos iteration that are numerically stable.\nOne of these, the Implicitly Restarted Lanczos Method, is found in SciPy as the function \\li{scipy.sparse.linalg.eigsh()}.\n\n\\begin{comment}\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\n\\begin{lstlisting}\nfrom scipy import sparse\nm = 1000\nd = np.ones(m)\nd[1:-1] += np.ones(m-2)\nl = sparse.diags([-np.ones(m-1), d, -np.ones(m-1)], [-1, 0, 1])\n\\end{lstlisting}\n\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\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 = sparse.diags([d1, d, d1], [-1, 0, 1])\n\\end{lstlisting}\n\nVerify that this graph is not connected.\n\\end{problem}\n\\end{comment}\n", "meta": {"hexsha": "6913e5002f00be32559834f04431c3ac53652d06", "size": 28023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol1B/Arnoldi/Arnoldi.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/Arnoldi/Arnoldi.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/Arnoldi/Arnoldi.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.5194552529, "max_line_length": 407, "alphanum_fraction": 0.717910288, "num_tokens": 7948, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8688267660487573, "lm_q2_score": 0.8807970873650401, "lm_q1q2_score": 0.7652600849605325}}
{"text": "\n\\subsection{Arithmetic on complex numbers}\n\nFor each of these we have:\n\n\\(x=a+bi\\)\n\n\\(y=c+di\\)\n\nAddition is defined as:\n\n\\(x+y=a+bi+c+di\\)\n\n\\(x+y=(a+c)+(b+d)i\\)\n\nSubtraction is defined as:\n\n\\(x-y=a+bi-c-di\\)\n\n\\(x-y=(a-c)+(b-d)i\\)\n\nMultiplication is defined as:\n\n\\(xy=(a+bi)(c+di)\\)\n\n\\(xy=ac-bd+adi+bci\\)\n\n\\(xy=(ac-bd)+(ad+bc)i\\)\n\nDivision is defined as:\n\n\\(\\dfrac{x}{y}=\\dfrac{a+bi}{c+di}\\)\n\n\\(\\dfrac{x}{y}=\\dfrac{(a+bi)(c-di)}{(c+di)(c-di)}\\)\n\n\\(\\dfrac{x}{y}=\\dfrac{(ac+bd)+(bc-ad)i}{c^2+d^2}\\)\n\n\n", "meta": {"hexsha": "8220ea5664a7b780babd4f9cc60d9d2a350bed62", "size": 499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/complex/02-01-arithmetic.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/complex/02-01-arithmetic.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/complex/02-01-arithmetic.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 12.7948717949, "max_line_length": 51, "alphanum_fraction": 0.5551102204, "num_tokens": 214, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9711290955604488, "lm_q2_score": 0.7879311956428947, "lm_q1q2_score": 0.7651829093885474}}
{"text": "\\section{Multigrid methods for nonlinear problem}\nIn classification, the key problem can be reduced to find the \nrepresentation (feature) for high dimension image for classifying. \nHere we propose to solve the next unbalanced nonlinear system  \n\\begin{equation}\\label{eq:rep}\nL(u) = f,\n\\end{equation}\nfor finding the suitable feature representation $u \\in \\mathbb{R}^c$ for  \nimage $f\\in \\mathbb{R}^{n}$. The rationality of system can be traced back to \nthe low-dimension assumption that natural image need to be concentrated \non a low-dimension manifold with respect to the pixel space.\n\nIn order to motivate how to deal with the nonlinear system \\eqref{eq:rep}, we \nconsider a simple nonlinear model problem \n\\begin{equation}\\label{nonlinear:poisson}\n\\left\\{\n\\begin{aligned}\n-\\nabla\\cdot(a(u)\\nabla u)+c(u)&=f, \\quad x\\in \\Omega,\\\\\nu&=0\\quad\\hbox{on}\\quad\\partial \\Omega.\n\\end{aligned}\n\\right. \n\\end{equation}\n%\\example $p$-Laplacian $\\displaystyle \\min_{u\\in W^{1,p}()\\Omega} \\frac{1}{p} \\int_\\Omega |\\nabla u|^p dx-\\int_\\Omega fudx$. \n\nThe weak formulation of \\eqref{nonlinear:poisson} reads: Find $u\\in H^1_0(\\Omega)$, such that \n$$\n(a(u)\\nabla u,\\nabla v)+(c(u), v)=(f,v), \\quad \\forall v\\in H^1_0(\\Omega). \n$$\nDefine\n\\begin{equation}\n(L(u), v)=(a(u)\\nabla u,\\nabla v)+(c(u), v).\n\\end{equation}\nThen we have \n\\begin{equation}\nL(u)=f.\n\\end{equation}\nNow the discretization problem reads: Find $u_h\\in V_h$ such that\n\\begin{equation}\n(a(u_h)\\nabla u_h,\\nabla v_h)+(c(u_h), v_h)=(f,v_h)\\quad \\forall v_h\\in V_h. \n\\end{equation}\nAgain define \n$$\n(L_h(u_h), v_h)=(a(u_h)\\nabla u_h,\\nabla v_h)+(c(u_h), v_h).\n$$\nThen we obtain \n\\begin{equation}\\label{non:system}\nL_h(u_h)=f_h. \n\\end{equation}\nIf $a(u_h)$ is a constant, then \\eqref{non:system} reduces to a linear system and we denote the \nlinear system as $A_hu_h=f_h$. \n\nRecall the two grid method described in \\eqref{eq:smoothing0}, \\eqref{eq:formresidual}, \\eqref{erreq}, \\eqref{coarse:correc} and \\eqref{eq:prolongation00}\nfor linear problem \n\\begin{equation}\\label{linearA}\nA_hu_h=f_h,\n\\end{equation}\nreads as following three steps:\n\\begin{enumerate}\n\\item Fine grid smoothing: \n%applying $m$ times gradient descent iterations to obtain $u^m$.\n$$\nu_h\\update u_h+S_h(f_h-A_hu_h)\n$$\nsuch as gradient descent method. \n\\item Coarse grid correction: solving the residual equation restricted\non the coarse grid $\\ct_{2h}$ to obtain\n$$\n        A_{2h}e_{2h}=Q_{2h}r^h\n$$\nwith $r^h=f_h-A_h u_h$. \n\\item Update: $u_h\\update u_h+e_{2h}$.\n\\end{enumerate}\nCoarse grid correction for the linear case can be rewritten as: \n$$\n A_{2h}e_{2h}=Q_{2h}(f_h-A_h u_h).\n $$\n For any $u_h^0$, we write the above equation as  \n \\begin{equation}\\label{eq2}\nQ_{2h}(A_{h}(u_h^0+e_{2h})-A_hu_h^0)=Q_{2h}(f_h-A_h u_h).\n \\end{equation}\n Noting that $Q_{2h}A_{h}=A_{2h}P_{2h}$, where $P_{2h}$ is the energy projection \n%from $V_h$ \n into $V_{2h}$. \n Therefore \\eqref{eq2} can be written as \n% $$\n% A_{2h}(P_{2h} u_h^0)+ A_{2h} e_{2h})- A_{2h} (P_{2h} u_h^0)=Q_{2h}(f_h-A_h u_h).\n% $$\n% and further \n  \\begin{equation}\\label{eq4}\n A_{2h}(P_{2h} u_h^0+ e_{2h})=Q_{2h}(f_h-A_h u_h)+A_{2h} (P_{2h} u_h^0).\n  \\end{equation}\nNow let \n$$\nu_{2h,0}=P_{2h} u_h^0 \\quad \\hbox{and}\\quad u_{2h}=P_{2h} u_h^0+ e_{2h},\n$$\n then solving $e_{2h}$ in  \\eqref{eq4} is equivalent to solve $u_{2h}$  in the following equation\n\\begin{equation}\\label{eq5}\n A_{2h}u_{2h}=Q_{2h}(f_h-A_h u_h)+A_{2h} (u_{2h,0}).\n \\end{equation}\n In this case, noting that $e_{2h}=u_{2h}-P_{2h} u_h^0=u_{2h}-u_{2h,0}$, hence the step 3 means \n $$\n\\hbox{ Update:} \\,\\, u_h\\update u_h+u_{2h}-u_{2h,0}.\n $$\n \n In summery, the two grid method for the linear system \\eqref{linearA} can be rewritten as following three steps:\n\\begin{enumerate}\n\\item Fine grid smoothing: \n%applying $m$ times gradient descent iterations to obtain $u^m$.\n$$\nu_h\\update u_h+S_h(f_h-A_hu_h)\n$$\nsuch as gradient descent method. \n\\item Coarse grid correction: for any $u_h^0$, solving the residual equation restricted\non the coarse grid $\\ct_{2h}$ to obtain\n$$\n   u_{2h,0}=P_{2h} u_h^0, \\quad     A_{2h}u_{2h}=Q_{2h}(f_h-A_h u_h)+A_{2h} (u_{2h,0}).\n$$\nwhere $P_{2h}$ is the energy projection %from $V_h$ \ninto $V_{2h}$. \n\\item Update: $u_h\\update u_h+u_{2h}-u_{2h,0}$.\n\\end{enumerate}\nUsually, after the fine grid smoothing, we choose $u_h^0$ as the solution updated from the fine grid smoothing.  And for nonlinear problems, we replace $P_{2h}u_h^0$ by $\\Pi_h^{2h}u_h^0$, where $\\Pi_h^{2h}$ is an interpolation or projection from $V_h$ to $V_{2h}$. \nNow we apply the above two grid method to the nonlinear system \\eqref{non:system}, \nnamely $L_{h}(u_h)=f_h$, we obtain the two grid method for nonlinear system\n \\begin{enumerate}\n\\item Fine grid smoothing: \n%applying $m$ times gradient descent iterations to obtain $u^m$.\n$$\nu_h\\update u_h+S_h(f_h-L_h(u_h))\n$$\nsuch as gradient descent method. \n\\item Coarse grid correction: solving the residual equation restricted\non the coarse grid $\\ct_{2h}$ to obtain\n$$\n   u_{2h,0}=\\Pi_h^{2h} u_h, \\quad     L_{2h}(u_{2h})=Q_{2h}(f_h-L_h (u_h))+L_{2h} (u_{2h,0}).\n$$\nwhere $\\Pi_h^{2h}$ is an interpolation or projection from $V_h$ to $V_{2h}$. \n\\item Update: $u_h\\update u_h+u_{2h}-u_{2h,0}$. \n\\end{enumerate}\n\n \nTo solve the nonlinear system, we can try the multilevel ideas \nwith smoothing in fine level, and truncated it into coarse level by recursion. \nOne strategy to involve the multi-scale idea is to ``smoothing'' in the fine level, \nand restrict it as a good approximation in the coarse level, this idea can \nbe found in many literatures especially for multigrid methods in optimization \n\\cite{tai2002global, nash2000a}.  So, there is a more general nonlinear multigrid named \nscheme-fully approximation scheme (FAS) \\cite{briggs2000a, trottenberg2000multigrid}, \nwhich can be considered as the generalization of linear multigrid Algorithm \\ref{alg:L-Slash1}.  \nHere we show a FAS algorithm with V-cycle as\n\\begin{breakablealgorithm}\n\t\\caption{$u = {\\text{ Bslash-FAS}}(u^{1,0},f,J,m_1, \\cdots, m_J)$}\n\t\\label{alg:Slash-FAS}\n\t\\begin{algorithmic}\n\t\t\\State Initialization \n\t\t$$\n\t\tf^1 = f.\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 Nonlinear relaxation on level $\\ell$:\n\t\t\\For{$i = 1:m_j$}\n\t\t\\State \n\t\t$$\n\t\tu^{\\ell,i} = u^{\\ell,i-1} +S_\\ell^i(f^\\ell - L^{\\ell}(u^{\\ell,i-1})).\n\t\t$$\n\t\t\\EndFor\n\t\t\\State Form the initial guess and right side term for level $\\ell+1$:\n\t\t$$\n\t\tu^{\\ell+1,0} = \\Pi_\\ell^{\\ell+1}u^{\\ell,m_\\ell}, \\quad \n\t\tf^{\\ell+1} = R_\\ell^{\\ell+1} (f^\\ell - L^{\\ell}(u^{\\ell,m_\\ell})) + L^{\\ell+1}( u^{\\ell+1, 0}).\n\t\t$$\n\t\t\\EndFor\n\t\t\\State Prolongation and correction from coarse to fine level\n\t\t\\For{$\\ell = J-1:1$}\n\t\t\n\t\t\\State Form error in coarse level \n\t\t$$\n\t\te^{\\ell+1} = u^{\\ell+1, m_{\\ell+1}} - u^{\\ell+1,0}.\n\t\t$$\n\t\t\\State Correction by using error in coarse level\n\t\t$$\n\t\tu^{\\ell,m_\\ell} \\leftarrow u^{\\ell,m_\\ell} + P_{\\ell+1}^{\\ell}e^{\\ell+1}.\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n%For some cases, we choose $S_\\ell^i=[\\nabla F^{\\ell}(u^{\\ell,i-1})]^{-1}$.\nIf the problem in \\eqref{eq:rep} is linear, then we have the next theorem to show that \nthis FAS scheme is consist with the classical multigrid methods for linear systems.\n\\begin{theorem}\n\tIf $L(u)$  in \\eqref{eq:rep}  is a linear operation. \n\tThen Algorithm \\ref{alg:Slash-FAS} is equivalent to Algorithm \\ref{alg:L-Slash1} with any choice of $\\Pi_\\ell^{\\ell+1}$.\n\\end{theorem}\n\n\n\\section{A nonlinear BVP example}\n Consider the following boundary value problem\n$$\n-u''+2u^3=0 \\quad(0< x < 1), \\quad u(0)=\\frac{1}{3}\\hbox{~and~}u(1)=\\frac{1}{4}.\n$$\nThe analytical solution is  $u=\\frac{1}{x+3}$. The weak formulation becomes\n\\begin{equation}\n(u',v')+(2u^3,v)=0.\n\\end{equation}\nBy choosing $u_h=\\sum \\alpha_i \\phi_i$, we have\n\\begin{equation}\\label{eq:nolinear}\nL_h({\\bm \\alpha}):=A{\\bm \\alpha}+2h{\\bm \\alpha}^3-b,\n\\end{equation}\nwhere\n$A =\\frac{1}{h}\n\\begin{pmatrix}\n2 & -1 &  &&\\\\\n-1 & 2 & -1&&\\\\\n   &\\vdots&\\vdots&\\vdots&\\\\\n   &&-1&2&-1\\\\\n   &&&-1&2\n\\end{pmatrix}$ and\n$b =\\frac{1}{h}\n\\begin{pmatrix}\n\\frac{1}{3}\\\\\n\\vdots\\\\\n\\frac{1}{4}\\end{pmatrix}$.  \nWe use gradient descent method and nonlinear multigrid method to solve \\eqref{eq:nolinear}. The smoother used in the \nnonlinear multigrid method is two steps of gradient descent method: \n$$\n\\bm \\alpha^{n+1}=\\bm \\alpha^n-\\eta L_h(\\bm \\alpha^n) -\\eta L_h(\\bm \\alpha^n-\\eta L_h(\\bm \\alpha^n))\n$$\nwhere $L_h$ is defined by \\eqref{eq:nolinear} and $\\eta$ is the learning rate. \n\n\\begin{table}\\label{Table:nonliear}%[htdp]\n\\begin{center}\n\\begin{tabular}{|c||c|c|}\n\\hline \\hline\nSize of Unkowns  & Nonlinear Multigrid  ethod  & Gradient Descent method \\\\ \\hline\\hline %& V + PCG for $A$\\\\ \\hline %\\hline\n15       &   13 steps  &  61.6 k steps \\\\ \\hline %&\\onslide<3->{\\brown{5/0.003s}}  \\\\ \\hline\n31      &   14 steps   &  976.6 k steps  \\\\ \\hline %&\\onslide<3->{\\brown{5/0.003s}}  \\\\ \\hline\n63         &  15 steps & $>$ 1000 k steps\\\\ \\hline %& \\onslide<5->{\\brown{5/0.005s}} \\\\ \\hline \n127       & 16 steps & $>$ 1000 k steps \\\\ \\hline %&  \\onslide<7->{\\brown{5/0.016s}} \\\\ \\hline \n255        & 16 steps & $>$ 1000 k steps \\\\ \\hline %& \\onslide<9->{\\brown{5/0.06s}}  \\\\ \\hline \n511     &17 steps& $>$ 1000 k steps \\\\ \\hline %& \\onslide<11->{\\brown{5/0.22s}} \\\\   \\hline \\hline\n1023      &18 steps&$>$ 1000 k steps \\\\ \\hline %& \\onslide<11->{\\brown{5/0.22s}} \\\\   \\hline \\hline\n\\end{tabular}\n\\caption{Number of iterations for $\\| L_h({\\bm \\alpha}) \\|/ \\|b\\| \\leq 10^{-6}$}\n\\end{center}\n\\end{table}\n\nFrom the above numerical results shown in Table \\ref{Table:nonliear}, the nonlinear multigrid method is uniform with respect to the size of \nunknowns and much faster than the gradient descent method.  \n\n\n\\endinput\nFollowing the FAS idea, we propose the next Algorithms \\ref{alg:OD-FAS} to solve the \\eqref{eq:rep}:\n\\begin{breakablealgorithm}\n\t\\caption{$u = {\\text{OD-FAS}}(f,J,m_1, \\cdots, m_J)$}\n\t\\label{alg:OD-FAS}\n\t\\begin{algorithmic}\n\t\t\\State Initialization\n\t\t$$\n\t\tu^{1,0} = f,\n\t\t$$\n\t\t\\State Feature extraction between levels,\n\t\t\\For{$\\ell = 1:J$}\n\t\t\\State Feature extraction during level $\\ell$,\n\t\t\\For{$i = 1:m_\\ell$}\n\t\t\\State \n\t\t$$\n\t\tu^{\\ell,i} = u^{\\ell,i-1} +[\\epsilon I + \\nabla F^{\\ell}(u^{\\ell,i-1})]^{-1} (f^\\ell - F^{\\ell}(u^{\\ell,i-1})).\n\t\t$$\n\t\t\\EndFor\n\t\t\\If{$\\ell = J$}\n\t\t\\State Return $u^{J,m_J}$.\n\t\t\\EndIf\n\t\t\\State Form initialization and right hand term in coarse level:\n\t\t$$\n\t\tu^{\\ell+1,0}= R_\\ell^{\\ell+1} u^{\\ell,m_\\ell}, \\quad \n\t\tf^{\\ell+1} = R_\\ell^{\\ell+1} (r^\\ell - F^{\\ell}(u^{\\ell,m_\\ell})) + F^{\\ell+1}( u^{\\ell+1, 0}).\n\t\t$$\n\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\n", "meta": {"hexsha": "1ac2e5e7a6aadd632de7ffa13e961f8b35c9bfd9", "size": 10615, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.14-NonlinearMG.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.14-NonlinearMG.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.14-NonlinearMG.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": 37.3767605634, "max_line_length": 265, "alphanum_fraction": 0.6642487047, "num_tokens": 4061, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118213, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7651485586325355}}
{"text": "\\chapter{DT Fourier Transform}\n\nRecall the complex exponential $z^{n}$ for $z\\in\\mathbb{C}$ is the Eigenfunction of DT 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 DT \\emph{Fourier Transform} (DTFT).\n\nIn contrast to the DT Fourier series, in this case the complex exponent of the Eigenfunction becomes $z = e^{j\\omega}$ a continuous variable, and the decomposition is an uncountably infinite sum (integral). This gives the input-output relationship for a stable DT LTI system as\n\\[\nx[n] = \\frac{1}{2\\pi}\\int\\limits_{2\\pi} X\\left(e^{j\\omega}\\right) \\, e^{j \\omega n}\\; d\\omega \\;\\longrightarrow\\; y[n] = \\frac{1}{2\\pi}\\int\\limits_{2\\pi} H\\left(e^{j\\omega}\\right) X\\left(e^{j\\omega}\\right) \\, e^{j \\omega n}\\; d\\omega\n\\]\nwhere $H\\left(e^{j \\omega}\\right)$ 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\\left(e^{j\\omega}\\right)$.\n\n\\textbf{Note:} The notation $X\\left(e^{j\\omega}\\right)$ can be confusing. It just emphasizes that $z \\rightarrow e^{j\\omega}$. The expressions are functions of the independent variable $\\omega$.\n\n\\section{Analysis and Synthesis Equations}\n\nConsider the Fourier series of $x[n]$, a periodically extended finite-length DT signal $\\tilde{x}[n]$, e.g.\n\n\\begin{center}  \n  \\includegraphics[scale=0.8]{graphics/dt-derivation.pdf}\n\\end{center}\nwhere $\\tilde{x}[n]$ is zero outside the range $[N_1,N_2]$. Since $x[n] = \\tilde{x}[n]$ over the interval $-N_1$ to $N_2$\n\\[\na_k = \\frac{1}{N}\\sum\\limits_{n = -N_1}^{N_2} \\tilde{x}[n] e^{-j\\frac{2\\pi}{N}kn} = \\frac{1}{N}\\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\frac{2\\pi}{N}kn}\n\\]\nDefine the function $X\\left(e^{j\\omega}\\right) = \\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\omega n}$, then\n\\[\na_k = \\frac{1}{N} X\\left(e^{jk\\omega_0}\\right)\n\\]\nare samples of $X\\left(e^{j\\omega}\\right)$ at locations that are multiples of $\\omega_0 = \\frac{2\\pi}{N}$. \nSubstituting back into the synthesis equation\n\\[\n\\tilde{x}[n] = \\sum\\limits_{k = -N_1}^{N_2} a_k e^{j\\frac{2\\pi}{N}kn} = \\sum\\limits_{k = -N_1}^{N_2} \\frac{1}{N} X\\left(e^{jk\\omega_0}\\right) e^{jk\\omega_0 n}\n\\]\nNow note that $N = \\frac{2\\pi}{\\omega_0}$ so that\n\\[\n\\tilde{x}[n] = \\frac{1}{2\\pi} \\sum\\limits_{k = -N_1}^{N_2} X\\left(e^{jk\\omega_0}\\right) e^{jk\\omega_0 n} \\; \\omega_0\n\\]\nNow let $N \\rightarrow \\infty$.\n\\begin{align*}\n  \\lim_{N\\rightarrow \\infty} \\tilde{x}[n] &= \\lim_{N\\rightarrow \\infty} \\frac{1}{2\\pi} \\sum\\limits_{k = -N_1}^{N_2} X\\left(e^{jk\\omega_0}\\right) e^{jk\\omega_0 n} \\; \\omega_0\\\\\n  x[n] &= \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\n\\end{align*}\nThis is shown graphically in the figure below. As $N$ approaches infinity the sampling of the unit circle becomes infinite, and the summation approaches an integral.\n\n\\begin{center}\n  \\includegraphics[scale=0.9]{graphics/dt-fourier-limit.pdf}\n\\end{center}\n\nThis gives the \\emph{DT Fourier Transform Pair}. The Analysis Equation or Forward Transform is:\n\\[\nX\\left(e^{j\\omega}\\right) = \\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\omega n}\n\\]\nNote $X\\left(e^{j\\omega}\\right)$ must be a periodic function with period $2\\pi$. The Synthesis Equation or Inverse Transform is:\n\\[\nx[n] = \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\n\\]\nwhere the integral is over any $2\\pi$ period of $X$.\n\n\\begin{example}\n  Let $x[n] = \\delta[n]$\n  \\begin{align*}\n    X\\left(e^{j\\omega}\\right) &= \\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\omega n}\\\\\n    &= \\sum\\limits_{n = -\\infty}^{\\infty} \\delta[n] e^{-j\\omega n}\\\\\n    &= e^{-j\\omega (0)}\\\\\n    &= 1\n  \\end{align*}\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n\n  Let $x[n] = \\left( \\gamma \\right)^n\\; u[n]$\n  \\begin{align*}\n    X\\left(e^{j\\omega}\\right) &= \\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\omega n}\\\\\n    &= \\sum\\limits_{n = 0}^{\\infty} \\left( \\gamma \\right)^n \\; e^{-j\\omega n}\\\\\n    &= \\sum\\limits_{n = 0}^{\\infty} \\left( \\gamma e^{-j\\omega} \\right)^n\n  \\end{align*}\n  Using the geometric series $ \\sum\\limits_{n = 0}^{\\infty} z^n = \\frac{1}{1-z}$ for $|z| < 1$ gives:\n  \\[\n  X\\left(e^{j\\omega}\\right) = \\sum\\limits_{n = 0}^{\\infty} \\left( \\gamma e^{-j\\omega} \\right)^n = \\frac{1}{1-\\gamma e^{-j\\omega}} = \\frac{e^{j\\omega}}{e^{j\\omega} - \\gamma}\n  \\]\n  If $\\mid\\gamma e^{-j\\omega}\\mid < 1$ or equivalently $\\mid \\gamma \\mid < 1$.\n\n  \\[\n  \\left( \\gamma \\right)^n\\; u[n] \\; \\stackrel{\\mathcal{F}}{\\longrightarrow} \\; \\frac{1}{1-\\gamma e^{-j\\omega}}\n  \\]\nBelow is a plot of the original signal and the magnitude and phase spectrum when $\\gamma = \\tfrac{1}{2}$.\n  \\begin{center}\n    \\includegraphics[scale=0.5]{graphics/dtft-example1-x.pdf}\n  \\end{center}\n\n  \\begin{center}\n    \\includegraphics[scale=0.5]{graphics/dtft-example1-Xmag.pdf}\n    \\includegraphics[scale=0.5]{graphics/dtft-example1-Xarg.pdf}\n  \\end{center}\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Let \n  \\[\n  X\\left(e^{j\\omega}\\right) = \\left\\{ \\begin{array}{lc}\n    1 & |\\omega -2\\pi k| < \\omega_c\\\\\n    0 & \\text{else}\n  \\end{array}\n  \\right.\n  \\; \\text{for}\\; k\\in\\mathbb{Z} \\;\\text{and}\\; \\omega_c < \\pi\n  \\]\n\n  \\begin{align*}\n    x[n] &= \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\int\\limits_{-\\omega_c}^{\\omega_c}  e^{j\\omega n} \\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\frac{1}{jn} e^{j\\omega n} \\Bigg|_{-\\omega_c}^{\\omega_c}\\\\\n    &= \\frac{1}{\\pi n} \\left( \\frac{1}{2j} e^{j\\omega_c n} - \\frac{1}{2j} e^{-j\\omega_c n} \\right)\\\\\n    &= \\frac{1}{\\pi n} \\sin(\\omega_c n)\n  \\end{align*}\n  $\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Let \n  \\[\n  X\\left(e^{j\\omega}\\right) = \\sum\\limits_{k = -\\infty}^{\\infty} \\delta(\\omega-\\omega_0 -2\\pi k) \n  \\]\n  for $-\\pi < \\omega_0 < \\pi$\n\n  \\begin{center}\n    \\includegraphics[scale=1]{graphics/dtft-periodic-ex.pdf}\n  \\end{center}\n\n  \\begin{align*}\n    x[n] &= \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} \\int\\limits_{-\\pi}^{\\pi} \\delta(\\omega-\\omega_0)e^{j\\omega n} \\; d\\omega\\\\\n    &= \\frac{1}{2\\pi} e^{j\\omega_0 n}\n  \\end{align*}\n  $\\blacksquare$\n\\end{example}\n\n\\section{Existence of the DT Fourier Transform}\n\nThe example of the exponential $x[n] = \\left(\\gamma\\right)^n\\,u[n]$ above showed that for the DT Fourier transform to exist, the Fourier (analysis) sum must exist. Similar to the CT Fourier transform, a mild conditions is a sufficient prerequisite for the Fourier transform of a signal $x[n]$ to exist: it must be  absolutely summable\n\\[\n\\sum\\limits_{n = -\\infty}^{\\infty} |x[n]| < \\infty\n\\]\n\nThis conditions is 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 sinusoidal examples above. \n\n\\section{Properties of the DT Fourier Transform}\n\nThere are several useful properties of the DT Fourier Transform that, when combined with a table of transforms (see Table 5.2, page 392 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 following notation\n\\[\n\\mathcal{F}\\left\\{ x[n] \\right\\} = X\\left(e^{j\\omega}\\right) = \\sum\\limits_{n = -\\infty}^{\\infty} x[n] e^{-j\\omega n}\n\\]\n\\[\n\\mathcal{F}^{-1}\\left\\{ X\\left(e^{j\\omega}\\right) \\right\\} = x[n] =  \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\omega}\\right) e^{j\\omega n} \\; d\\omega \n\\]\n\\[\nx[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\;  X\\left(e^{j\\omega}\\right)\n\\]\nImportant: $X\\left(e^{j\\omega}\\right)$ is periodic in $2\\pi$ such that\n\\[\nX\\left(e^{j(\\omega + 2\\pi k)}\\right) =  X\\left(e^{j\\omega}\\right) \\;\\text{for}\\; k \\in \\mathbb{Z}\n\\]\n\\begin{itemize}\n  \\item Linearity Property.\n  Let $x_1[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X_1\\left(e^{j\\omega}\\right)$ and $x_2[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X_2\\left(e^{j\\omega}\\right)$\n  then for $a,b\\in\\mathbb{C}$\n  \\[\na x_1[n] + b x_2[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; a X_1\\left(e^{j\\omega}\\right) + b X_2\\left(e^{j\\omega}\\right)\n\\]\nExample:\n\\begin{align*}\n\\mathcal{F}\\left\\{ 2\\left( \\frac{1}{2}\\right)^nu[n] -5 \\left( -\\frac{1}{4}\\right)^nu[n] \\right\\} &= \\frac{2}{1-\\frac{1}{2}e^{-j\\omega}} - \\frac{5}{1+\\frac{1}{4}e^{-j\\omega}} \n\\end{align*}\n\\item Time-shift Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  x[n-n_0] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; e^{-j\\omega n_0} X\\left(e^{j\\omega}\\right)\n  \\]\n  Example:\n  \\[\n  \\mathcal{F}\\left\\{ \\delta[n-5] \\right\\} = e^{-j5\\omega}\n  \\]\n\\item Frequency Shift Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  e^{j\\omega_0 n} x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j(\\omega-\\omega_0)}\\right)\n  \\]\n  Example:\n  \\[\n  \\mathcal{F}^{-1}\\left\\{ \\frac{1}{1-\\frac{1}{2}e^{-j\\omega}e^{j\\frac{\\pi}{20}}} \\right\\} = e^{j\\frac{\\pi}{20} n} \\left( \\frac{1}{2}\\right)^n u[n]\n  \\]\n\\item Conjugation Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  x^*[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X*\\left(e^{-j\\omega}\\right)\n  \\]\n  Thus, if $x[n]$ is real $X\\left(e^{j\\omega}\\right)$ has conjugate symmetry\n  \\[\n  X\\left(e^{-j\\omega}\\right) = X^*\\left(e^{j\\omega}\\right)\n  \\]\n  and the magnitude spectrum is an even function and the phase spectrum is an odd function.\n\\item Differencing and Accumulation Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  x[n] - x[n-1] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right) - e^{-j\\omega} X\\left(e^{j\\omega}\\right) = \\left(1-e^{-j\\omega}\\right)X\\left(e^{j\\omega}\\right)\n  \\]\n  and\n  \\[\n  \\sum\\limits_{m = -\\infty}^{n} x[m] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; \\frac{1}{1-e^{-j\\omega}}X\\left(e^{j\\omega}\\right) + \\pi X\\left(e^{j0}\\right)\\sum\\limits_{k = -\\infty}^{\\infty} \\delta(\\omega - 2\\pi k) \n  \\]\n\\item Time Expansion Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  x_{(k)}[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{jk\\omega}\\right)\n  \\]\n  where\n  \\[\n  x_{(k)}[n] = \\left\\{ \\begin{array}{lc}\n    x[n/k] & \\text{if}\\; n = \\; \\text{multiple of}\\; k\\\\\n    0 & \\text{if}\\; n \\neq \\; \\text{multiple of}\\; k\\\\ \n  \\end{array}\n\\right.\n\\]\n\\begin{center}\n  \\includegraphics[scale=0.8]{graphics/dt=transform-property-expand.pdf}\n\\end{center}\n\\item Frequency Differentiation Property\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  n\\, x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; j \\frac{d}{d\\omega} X\\left(e^{j\\omega}\\right)\n  \\]\n  Example:\n  \\begin{align*}\n    \\mathcal{F}\\left\\{ n\\left( \\frac{1}{8}\\right)^n u[n] \\right\\} &= j \\frac{d}{d\\omega} \\left\\{\\frac{1}{1-\\frac{1}{8}e^{-j\\omega}} \\right\\}\\\\\n    &= j \\frac{-\\left(-\\frac{1}{8} (-j)e^{-j\\omega}\\right)}{\\left( 1-\\frac{1}{8}e^{-j\\omega} \\right)^2}\\\\\n    &= \\frac{\\frac{1}{8}e^{-j\\omega}}{\\left( 1-\\frac{1}{8}e^{-j\\omega} \\right)^2}\n  \\end{align*}\n\\item Parseval's Relation.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  \\sum\\limits_{n = -\\infty}^{\\infty} |x[n]|^2 \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\;\n  \\frac{1}{2\\pi} \\int_{2\\pi} \\left| X\\left(e^{j\\omega}\\right) \\right|^2 \\; d\\omega\n  \\]\n  The energy is also the integral over one period of the DTFT magnitude squared. \n\\item Convolution Property.\n  Recall for a DT LTI system with impulse response $h[n]$ the output is\n  \\[\n  y[n] = h[n]*x[n]\n  \\]\n  In the frequency domain this is equivalent to\n  \\[\n  Y\\left(e^{j\\omega}\\right) = H\\left(e^{j\\omega}\\right) \\, X\\left(e^{j\\omega}\\right)\n  \\]\n  As in CT systems, convolution in the discrete-time domain is equivalent to multiplication in the frequency domain. Example: suppose a DT system has impulse response\n  \\[\n  h[n] = \\left( \\gamma_1^n + \\gamma_2^n \\right)\\, u[n]\n  \\]\n  and the input is $x[n] = n\\, \\gamma_3^n\\, u[n]$ where $|\\gamma_1| < 1$, $|\\gamma_2| < 1$, $|\\gamma_3| < 1$. The output in the frequency domain is\n  \\begin{align*}\n    Y\\left(e^{j\\omega}\\right) &= H\\left(e^{j\\omega}\\right) \\, X\\left(e^{j\\omega}\\right)\\\\\n    &= \\left[ \\frac{1}{1-\\gamma_1 e^{-j\\omega}} + \\frac{1}{1-\\gamma_2 e^{-j\\omega}} \\right] \\frac{\\gamma_3 e^{-j\\omega}}{\\left( 1-\\gamma_3 e^{-j\\omega} \\right)^2}\\\\\n    &= \\frac{\\gamma_3 e^{-j\\omega}}{\\left(1-\\gamma_1 e^{-j\\omega}\\right)\\left( 1-\\gamma_3 e^{-j\\omega} \\right)^2} + \\frac{\\gamma_3 e^{-j\\omega}}{\\left(1-\\gamma_2 e^{-j\\omega}\\right)\\left( 1-\\gamma_3 e^{-j\\omega} \\right)^2} \n  \\end{align*}\n\n\\item Multiplication (modulation) Property.\n  Let\n  \\[\n  x[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; X\\left(e^{j\\omega}\\right)\n  \\]\n  and\n  \\[\n  y[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; Y\\left(e^{j\\omega}\\right)\n  \\]\n  then\n  \\[\n  x[n]\\,y[n] \\; \\stackrel{\\mathcal{F}}{\\longleftrightarrow} \\; \\frac{1}{2\\pi} \\int_{2\\pi} X\\left(e^{j\\theta}\\right)\\, Y\\left(e^{j(\\omega-\\theta)}\\right)\\; d\\theta\n  \\]\n\\end{itemize}\n\n\\section{DT Fourier Transform of a Periodic Signal}\n\nThe DTFS allows us to write any periodic function with period $N$ as\n\\[\nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N -1} a_k e^{j\\frac{2\\pi}{N}kn}  \n\\]\ntaking the DT Fourier Transform \n\\[\nX\\left(e^{j\\omega}\\right) = \\sum\\limits_{k = N_0}^{N_0 + N -1} a_k \\mathcal{F}\\left\\{e^{j\\frac{2\\pi}{N}kn}\\right\\}\n\\]\nUsing the previously derived transform shows, similar to CT, the DT Fourier Transform of a periodic signal is \n\\[\nX\\left(e^{j\\omega}\\right) = \\sum\\limits_{k = -\\infty}^{\\infty} 2\\pi a_k \\delta\\left(\\omega - \\frac{2\\pi k}{N}\\right)  \n\\]\n\nExample\n  \\[\n  x[n] = \\cos\\left(\\frac{2\\pi}{10} n\\right) = \\frac{1}{2}e^{j\\frac{2\\pi}{10} n} + \\frac{1}{2}e^{-j\\frac{2\\pi}{10} n}\n  \\]\n  Using the previous transform\n  \\[\n  X\\left(e^{j\\omega}\\right) =  \\sum\\limits_{k = -\\infty}^{\\infty} \\pi \\delta\\left(\\omega - \\frac{2\\pi}{10} -2\\pi k\\right) + \\pi \\delta\\left(\\omega + \\frac{2\\pi}{10} -2\\pi k\\right)\n  \\]\n  Which looks like\n  \\begin{center}\n  \\includegraphics[scale=1]{graphics/dtft-periodic-ex2.pdf}\n\\end{center}\n", "meta": {"hexsha": "488e85330c30328b5ebb0381d8368c8899390454", "size": 14685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "17-dtft.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": "17-dtft.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": "17-dtft.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": 43.5756676558, "max_line_length": 437, "alphanum_fraction": 0.6279196459, "num_tokens": 5654, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7650965129811392}}
{"text": "\\documentclass[notitlepage]{simple}\n\n\\author{Matt McCarthy}\n\\title{Completeness of $\\RR$}\n\\date{Februrary 2016}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{thm*}\n\tThe real numbers form a complete metric space.\n\\end{thm*}\n\n\\noindent Notation: We denote the set of non-negative real numbers as $\\RR^+$.\n\nWe begin by providing a way to measure distances in a space.\n\n\\begin{definition}[Metric]\n\tLet $X$ be a set and $d:X\\times X\\rightarrow \\RR^+$ be a map.\n\tWe say $d$ is a \\textit{metric} if and only if all of the following hold.\n\t\\begin{enumerate}\n\t\t\\item For all $x,y\\in X$, $d(x,y)=0$ if and only if $x=y$.\n\t\t\\item For all $x,y\\in X$, $d(x,y)=d(y,x)$ (symmetric property).\n\t\t\\item For all $x,y,z\\in X$, $d(x,z)\\leq d(x,y)+d(y,x)$ (triangle inequality).\n\t\\end{enumerate}\n\tIf $d$ is a metric on $X$, we say $(X,d)$ forms a \\textit{metric space}.\n\\end{definition}\n\nFor example, $(\\QQ,d)$ and $(\\RR,d)$ where $d(x,y)=\\abs{x-y}$ is a metric space,\nand more generally, $(\\RR^n, d_n)$ where $d_n$ is the Euclidean distance is also a metric space.\nNow that we have a way to talk about distances in spaces we can talk about convergence of sequences in those spaces.\n\n\\begin{definition}[Convergent Sequence]\n\tLet $(X,d)$ be a metric space and let $\\set{a_n}_{n\\in\\NN}$ be a sequence in $X$.\n\tWe say $\\set{a_n}_{n\\in\\NN}$ \\textit{converges} to some $a\\in X$, denoted $a_n\\rightarrow a$ if and only if for all $\\varepsilon>0$ there exists a $N_\\varepsilon\\in\\NN$ such that $d(a_n,a)<\\varepsilon$ for all $n\\geq N_\\varepsilon$.\n\\end{definition}\n\nHowever, convergence is often too strong a condition to prove, and moreover convergence also requires a proposed limit.\nTherefore, we introduce the notion of a \\textit{Cauchy Sequence} where the terms get arbitrarily close to each other.\n\n\\begin{definition}[Cauchy Sequence]\n\tLet $(X,d)$ be a metric space and let $\\set{a_n}_{n\\in\\NN}$ be a sequence in $X$.\n\tWe say $\\set{a_n}_{n\\in\\NN}$ is a \\textit{Cauchy sequence} if and only if for any $\\varepsilon>0$, there exists a $N_\\varepsilon\\in\\NN$ such that $d(a_n,a_m)<\\varepsilon$ for all $n,m\\geq N_\\varepsilon$.\n\\end{definition}\n\nNote, however that Cauchy sequences are not always convergent in their space.\nFor example consider the sequence given by\n\\[\n\ta_n = \\paren{1+\\frac{1}{n}}^n.\n\\]\nWe know these terms are rational and thus $a_n$ is a $\\QQ$-valued sequence.\nFurthermore, the sequence is in fact Cauchy.\nHowever, the limit of this sequence as $n$ approaches infinity is $e$ and thus, this Cauchy sequence does not converge in $\\QQ$, but it does in $\\RR$.\n\nThis leads us to a notion of \\textit{completeness} in a metric space.\n\n\\begin{definition}[Complete Metric Space]\n\tLet $(X,d)$ be a metric space.\n\tThen we say $(X,d)$ is \\textit{complete} if and only if every Cauchy sequence in $X$ converges in $X$.\n\\end{definition}\nBy this definition of completeness, $\\QQ$ is not complete as shown by our prior example.\nHowever, $\\RR$ is complete.\n\nBefore we get into any theorems here, we need a notion of \\textit{boundedness} for subsets of the real numbers.\n\n\\begin{definition}[Bounded]\n\tLet $S$ be a subset of the real numbers.\n\tThen $S$ is \\textit{bounded} if and only if there exists an $M>0$ such that $S\\subseteq [-M,M]$.\n\\end{definition}\n\nWe also need to invoke a famous theorem due to Bolzano and Weierstrass, which states that any bounded sequence in $\\RR$ has a subsequence that is convergent in $\\RR$.\n\n\\begin{thm}[Bolzano-Weierstrass]\n\tLet $\\set{a_n}_{n\\in\\NN}$ be a bounded $\\RR$-valued sequence.\n\tThen there exists a $\\set{a_{n_k}}\\subseteq\\set{a_n}$ such that $a_{n_k}$ converges to some $a\\in\\RR$.\n\\end{thm}\n\\begin{proof}\n\tLet $\\set{x_n}_{n\\in\\NN}$ be bounded.\n\tThen there exists an $M\\in\\NN$ such that $\\set{x_n}_{n\\in\\NN}\\subset[-M,M]\\subset\\RR$.\n\tBisect $[-M,M]$ into $[-M,0],[0,M]$.\n\tAt least one half has infinitely many sequence points, call this one $I_1$.\n\tPick a sequence point $x_{n_1}\\in I_1$.\n\tBisect $I_1$ and call the half with infinitely many sequence points $I_2$.\n\tPick a sequence point $x_{n_2}\\in I_2$ such that the index $n_2>n_1$.\n\tIterate this process, that is bisect $I_k$ and call the half with infinitely many points $I_{k+1}$.\n\tThen choose a sequence point $x_{n_{k+1}}\\in I_{k+1}$ with the property that the index $n_{k+1}>n_k>\\ldots > n_1$.\n\tMoreover, by nested interval property, $\\bigcap_{k\\in\\NN} I_k\\neq\\emptyset$.\n\tThus there exists at least one $x\\in \\bigcap_{k\\in\\NN} I_k$.\n\tWe want to show that $x_{n_k}\\rightarrow x$.\n\tLet $\\varepsilon> 0$ be given.\n\tChoose a $K_\\varepsilon\\in\\NN$ such that $2^{-K_\\varepsilon}M< \\varepsilon$.\n\tNote that for all $k\\geq K_\\varepsilon$, $2^{-k} M <  2^{-K_\\varepsilon}M< \\varepsilon$.\n\tSince $x\\in \\bigcap_{k\\in\\NN} I_k$, $x\\in I_k$ for all $k\\in\\NN$.\n\tThus for all $k\\in\\NN$, $|x_{n_k}-x|\\leq 2^{-k}M$.\n\tTherefore, when we force $k\\geq K_\\varepsilon$ we have $I_k\\subset I_{K_\\varepsilon}$ and\n\t\\[\n\t|x_{n_k}-x|\\leq 2^{-k}M \\leq 2^{-K_\\varepsilon} M < \\varepsilon.\n\t\\]\n\tThus, $\\set{x_{n_k}}_{k\\in\\NN}$ is a subsequence of $\\set{x_n}_{n\\in\\NN}$ that is convergent in $\\RR$.\n\\end{proof}\n\nFurthermore, we need the following lemma.\n\n\\begin{lemma}\n\tAny $\\RR$-valued Cauchy sequence is bounded.\n\\end{lemma}\n\\begin{proof}\n\tLet $\\varepsilon >0$ be given and let $\\set{a_n}_{n\\in\\NN}$ be a Cauchy sequence in $\\RR$.\n\tTherefore, there exists an $N_\\varepsilon$ such that $|a_n-a_m|<\\varepsilon$ for all $n,m\\geq N_\\varepsilon$.\n\tTherefore, for all $n\\geq N_\\varepsilon$, $|a_{N_\\varepsilon}-a_n|<\\varepsilon$.\n\tThus for each $n\\geq N_\\varepsilon$, $a_n\\in[a_{N_\\varepsilon}-\\varepsilon,a_{N_\\varepsilon}+\\varepsilon]$.\n\tTake $M_1=\\max\\set{a_{N_\\varepsilon}-\\varepsilon,a_{N_\\varepsilon}+\\varepsilon}$, which yields $\\set{a_n}_{n=N_\\varepsilon}^\\infty\\subset[-M_1,M_1]$.\n\n\tFurthermore, since $\\set{a_n}_{n=1}^{N_\\varepsilon-1}$ is finite, take $M_2=\\max\\set{|a_n|}_{n=1}^{N_\\varepsilon-1}$.\n\tThus, $\\set{a_n}_{n=1}^{N_\\varepsilon-1}\\subset [-M_2,M_2]$.\n\tIf we take $M=\\max\\set{M_1,M_2}$, then we have $\\set{a_n}_{n\\in\\NN}\\subset[-M,M]$.\n\tTherefore, the sequence is bounded.\n\\end{proof}\n\nAnd now we provide the proof.\n\n\\begin{thm}\n\tThe real numbers form a complete metric space.\n\\end{thm}\n\\begin{proof}\n\tLet $\\set{a_n}_{n\\in\\NN}$ be Cauchy in $\\RR$.\n\tLet $\\varepsilon > 0$ be given.\n\tSince $\\set{a_n}_{n\\in\\NN}$ is Cauchy there exists an $N_{\\varepsilon/2}\\in\\NN$ such that $|a_n-a_m|<\\varepsilon/2$ for all $n,m\\geq N_{\\varepsilon/2}$.\n\tFurthermore, $\\set{a_n}_{n\\in\\NN}$ is bounded and thus by Bolzano-Weierstrass, there exists a $\\set{a_{n_k}}_{k\\in\\NN}\\subset\\set{a_n}_{n\\in\\NN}$ such that $a_{n_k}$ converges to some $a\\in\\RR$.\n\n\tWe claim that $a_n$ converges to $a$.\n\tSince $a_{n_k}$ converges to $a$, there exists a $K_{\\varepsilon/2}\\in\\NN$ such that $|a_{n_k}-a|<\\varepsilon/2$ for all $k\\geq K_{\\varepsilon/2}$.\n\tTake $N=\\max\\set{N_{\\varepsilon/2},n_{K_{\\varepsilon/2}}}$ and force $n,k$ large enough such that $n,n_k\\geq N$.\n\tConsider $|a_n-a|$.\n\t\\[\n\t\t|a_n-a|=|a_n-a_{n_k}+a_{n_k}-a|\\leq |a_n-a_{n_k}|+|a_{n_k}-a|<\\frac{\\varepsilon}{2}+\\frac{\\varepsilon}{2}=\\varepsilon\n\t\\]\n\tThus for any $\\varepsilon >0$, there exists an $N\\in\\NN$ such that $|a_n-a|<\\varepsilon$ for all $n\\geq N$.\n\tTherefore $a_n$ converges to $a$ and $\\RR$ is a complete metric space.\n\\end{proof}\n\n\\section{Bonus}\n\n\\begin{thm*}\n\tThe set of infinite binary sequences is uncountable.\n\\end{thm*}\n\n\\begin{definition}[Countable Set]\n\tLet $X$ be a set.\n\tWe say $X$ is \\textit{countable} if and only if there exists a bijection between $X$ and a subset of $\\NN$.\n\tIf $X$ has a bijection with $\\NN$ itself, then we say $X$ is \\textit{countably infinite}.\n\\end{definition}\n\n\\begin{proof}\n\tLet $B$ represent the set of infinite binary sequences.\n\tProceed via contradiction.\n\tAssume $B$ is countable.\n\tThen $B=\\set{s_i}_{i\\in\\NN}$ where $s_i=(b_{i,1},b_{i,2},\\ldots)$ with each $b_{i,j}\\in\\set{0,1}$.\n\tDefine $\\sim:\\set{0,1}\\rightarrow\\set{0,1}$ by\n\t\\[\n\t\t\\sim x=\n\t\t\\begin{cases}\n\t\t\t0 & x=1\\\\\n\t\t\t1 & x=0\n\t\t\\end{cases}.\n\t\\]\n\tWe need to create a infinite binary sequence that is not equal to any $b_i$.\n\tTake $s=(\\sim b_{1,1},\\sim b_{2,2},\\ldots)$.\n\tObviously, $s\\in B$.\n\tHowever, for each $i\\in\\NN$, $\\sim b_{i,i}\\neq b_{i,i}$ and thus $s\\neq s_i$ for each $i\\in\\NN$.\n\tTherefore, $s\\notin B$ which is a contradiction.\n\tErgo, $B$ must be uncountable.\n\\end{proof}\n\n\\end{document}\n", "meta": {"hexsha": "5d5cf8381c7062bc54868fcf3ff86c711b675d34", "size": 8299, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2016-spring/reals-complete/reals-complete.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/reals-complete/reals-complete.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/reals-complete/reals-complete.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": 46.8870056497, "max_line_length": 233, "alphanum_fraction": 0.6897216532, "num_tokens": 3037, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278540866547, "lm_q2_score": 0.8670357598021707, "lm_q1q2_score": 0.7650965049386217}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the determinant of the following matrices.\n\n  \\begin{enumerate}\n  \\item\n    $A = \\begin{mymatrix}{rr}\n      1 & -34 \\\\\n      0 & 2\n    \\end{mymatrix}$\n\n  \\item\n    $B = \\begin{mymatrix}{rrr}\n      4 & 0 &  0 \\\\\n      3 & -2 & 0 \\\\\n      14 & 1 & 5\n    \\end{mymatrix}$\n\n  \\item\n    $C = \\begin{mymatrix}{rrrr}\n      2 & 3 & 15 & 0 \\\\\n      0 & 4 & 1 & 7 \\\\\n      0 & 0 & -3 & 5 \\\\\n      0 & 0 & 0 & 1\n    \\end{mymatrix}$\n  \\end{enumerate}\n\n \\begin{sol}\n   (a) $\\det(A) = 2$. (b) $\\det(B) = -40$. (c) $\\det(C) = -24$.\n \\end{sol}\n\n\\end{ex}\n\n", "meta": {"hexsha": "14838fe83597767636eeadb41d51a31e19b3eff0", "size": 578, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-Triangular.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-Triangular.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-Triangular.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.5142857143, "max_line_length": 63, "alphanum_fraction": 0.4429065744, "num_tokens": 260, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888303, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7649670802513358}}
{"text": "%\n% Chapter 1.8\n%\n\n\\section*{1.8 Continuity}\n\nA function is continuous at a number \\(a\\) if \n$$\\lim_{x \\to a}f(x) = f(a)$$\\\\\nA function \\(f\\) is continuous from the right at a number \\(a\\) if \n$$\\lim_{x \\to a^+}f(x)=f(a)$$\nand \\(f\\) is continuous from the left at \\(a\\) of \n$$\\lim_{x \\to a^-}f(x)=f(a)$$\\\\\nA function \\(f\\) is continuous on an interval if it is continuous at every number in the interval.\n\\\\\\\\\nIf \\(f\\) and \\(g\\) are continuous at \\(a\\) and if \\(c\\) is a constant, then the following functions are also continuous at \\(a\\).\n\\begin{enumerate}\n    \\item \\(f + g\\)\n    \\item \\(f - g\\)\n    \\item \\(cf\\)\n    \\item \\(fg\\)\n    \\item \\(\\frac{f}{g}\\) if \\(g(a) \\neq 0\\)\n\\end{enumerate}\nAny polynomial, rational function, root function, or trigonometric function is continuous anywhere on its domain.\n\n\\subsection*{Intermediate Value Theorem}\n\nSuppose that \\(f\\) is continuous on the closed interval \\([a, b]\\) and let \\(N\\) be any number between \\(f(a)\\) and \\(f(b)\\), where \\(f(a) \\neq f(b)\\). Then there exists a number \\(c\\) in \\((a, b)\\) such that \\(f(c)\\) = \\(N\\).\n", "meta": {"hexsha": "8a06307c26ebf5deb4ad1795db449bdd24517f43", "size": 1077, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-8.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-8.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-8.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": 38.4642857143, "max_line_length": 226, "alphanum_fraction": 0.6128133705, "num_tokens": 354, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110511888302, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7649670705236147}}
{"text": "\\section{Definitions}\n\n\\subsection{Notation}\n\nFunctions\n\\[ \\exists f : A \\to B \\]\nmeans that we claim that there exists a function \\(f\\) mapping items of set \\(A\\)\nto items of set \\(B\\). We define sets by enumerating their items using the\nstandard \\( \\set{} \\) notation.\n\nBooleans\n\\[ \\Bool = \\set{ \\True, \\False } \\]\nNatural numbers plus zero\n\\[ \\mathbb{Z} = \\set{ 0,1,2,... } \\]\nTuples (Products)\n\\[ (X,Y) = \\set{ (x,y) ; x \\in X \\land y \\in Y } \\]\n\\[ (X,Y,Z,...) = (X,(Y,(Z,...))) \\]\nFor every tuple there exist two unique functions:\n\\[ \\exists  \\pi_1 : (X,Y) \\to X \\]\n\\[ \\exists  \\pi_2 : (X,Y) \\to Y \\]\nWe access fields of nested tuples by using composition over these functions.\nOften we want to define tuples together with accessors functions. By\nsaying\n\\[ T = (a:X,b:Y,c:Z,...) \\]\nwe mean\n\\[ T = (X,(Y,(Z,...))) \\land \\]\n\\[ \\exists a : T \\to X = \\pi_1 \\land \\exists b : T \\to Y = \\pi_1 \\circ \\pi_2\n\\land \\exists c : T \\to Z = \\pi_1 \\circ \\pi_2 \\circ \\pi_2 \\land ... \\]\nUnions (Co-products)\n\\[ X|Y = \\set{u | u \\in X \\lor u \\in Y }\\]\nNote: X and Y has to be separable from each other, i.e. for any particular \\( u\n\\) it should be possible to tell whether it comes from X or from Y.\n\\hfill \\break \\noindent\nOptional\n\\[ \\mathbb{O}[X] = X | \\oslash \\]\nLists\n\\[ \\List[X] = \\mathbb{O}[(X,\\mathbb{O}[(X,...)])] \\]\nDictionaries\n\\[ \\Dict[K,V] = \\List[(K,V)] \\]\n\\[ \\exists item : \\Dict[K,V] \\to K \\to \\Opt[V] \\]\nNote: we assume that \\(item \\) returns the last \\( V \\) element with matching \\(\nK \\).\n\\hfill \\break \\noindent\n\n\n\\subsection{Core entities}\n\nTODO\n", "meta": {"hexsha": "14207ad8229c96f400410a3b8dd2275aba28a225", "size": 1554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/sections/Definitions.tex", "max_stars_repo_name": "stagedml/pylightnix", "max_stars_repo_head_hexsha": "b475057f03db1d0b975500d079745c4de9c42069", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-01-25T12:03:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-12T08:22:33.000Z", "max_issues_repo_path": "docs/sections/Definitions.tex", "max_issues_repo_name": "stagedml/pylightnix", "max_issues_repo_head_hexsha": "b475057f03db1d0b975500d079745c4de9c42069", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-02-16T10:47:34.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-20T17:11:45.000Z", "max_forks_repo_path": "docs/sections/Definitions.tex", "max_forks_repo_name": "stagedml/pylightnix", "max_forks_repo_head_hexsha": "b475057f03db1d0b975500d079745c4de9c42069", "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": 31.7142857143, "max_line_length": 81, "alphanum_fraction": 0.6068211068, "num_tokens": 547, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966671870766, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7649137355875326}}
{"text": "\\section{Lengths of Curves}\r\nIf we're at some point $(x,f(x))$ and move $\\d{x}$ units over, we'll be at a new point $(x+\\d{x},f(x+\\d{x}))$.\r\nThis point is $\\d{x}$ units horizontally and $\\d{y}=f(x+\\d{x})-f(x)$ vertically away from $(x,f(x))$.\r\nSo, by the Pythagorean Theorem, the new point is $\\d{s} = \\sqrt{(\\d{x})^2+(\\d{y})^2}$ units away.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{arclength}\r\n\t\\centering\r\n\t\\includegraphics[width=0.66\\textwidth]{./applications_integrals/arclength.png}\r\n\t\\caption{\\hyperref{}{}{}{Secant length approaches arc length}}\r\n\\end{figure}\r\n\r\nAs $\\d{x}$ approaches 0, $\\d{s}$, the length of the secant line, approaches the length of the curve.\r\nIf we summed all of these $\\d{s}$'s in some interval we'd have the length of the curve on that interval.\r\n\\begin{align*}\r\n\ts &= \\int_{a}^{b}{\\d{s}} \\\\\r\n\t&= \\int_{a}^{b}{\\sqrt{(\\d{x})^2+(\\d{y})^2}} \\\\\r\n\t&= \\int_{a}^{b}{\\sqrt{(\\d{x})^2\\left(1+\\left(\\frac{\\d{y}}{\\d{x}}\\right)^2\\right)}} \\\\\r\n\t&= \\int_{a}^{b}{\\sqrt{1+\\left(\\frac{\\d{y}}{\\d{x}}\\right)^2}\\d{x}}.\r\n\\end{align*}\r\n\r\n\\begin{example}\r\n\tShow that the circumference of a circle with radius $r$ is $C=2\\pi r$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tStarting with the equation of a circle of radius $r$ and implicitly differentiating,\r\n\t\\begin{align*}\r\n\t\tx^2 + y^2 &= r^2 \\\\\r\n\t\t2x + 2y\\dd{y}{x} &= 0 \\\\\r\n\t\t\\dd{y}{x} &= \\frac{-x}{y} \\\\\r\n\t\t\\left(\\dd{y}{x}\\right)^2 &= \\frac{x^2}{y^2} = \\frac{x^2}{r^2-x^2} \\\\\r\n\t\tC &= 2\\int_{-r}^{r}{\\sqrt{1+\\frac{x^2}{r^2-x^2}}\\d{x}} \\\\ \r\n\t\t&\\text{ (2 b/c we need to count upper and lower half)} \\\\\r\n\t\t&= 2\\int_{-r}^{r}{\\sqrt{\\frac{r^2}{r^2-x^2}}\\d{x}} \\\\\r\n\t\t&= 2\\int_{-r}^{r}{r\\sqrt{\\frac{1}{r^2-x^2}}\\d{x}} \\\\\r\n\t\t&= 2r\\arcsin{\\left(\\frac{x}{r}\\right)}\\biggr\\rvert_{-r}^{r} \\\\\r\n\t\t&= 2\\pi r.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nNote that when deriving the arc length formula, we could have just as easily have divided by $(\\d{y})^2$.\r\nThis would give us an equivalent arc length formula that's applicable when $x$ is a function of $y$.\r\n\r\n\\begin{example}\r\n\tFind the length of the curve $y=x^{1/3}$ from $(-8,2)$ to $(8,2)$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tRather than  tediously integrate the square root of a cube root if we set our bounds in terms of $x$, we can rewrite our equation and set out bounds in terms of $y$.\r\n\t\\begin{align*}\r\n\t\tx &= y^3 \\\\\r\n\t\t\\dd{x}{y} &= 3y^2 \\\\\r\n\t\t\\left(\\dd{x}{y}\\right)^2 &= 9y^4 \\\\\r\n\t\ts &= \\int_{-2}^{2}{\\sqrt{1+9y^4}\\d{y}} \\\\\r\n\t\t&\\footnotemark\\approx 17.261.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\footnotetext{You shouldn't be expected to evaluate this integral analytically. Using a calculator to get a numerical answer is fine.}", "meta": {"hexsha": "14036bc5488c583e629f4fefe96eeae238b78b94", "size": 2596, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/applications_integrals/length_of_curves.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/applications_integrals/length_of_curves.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/applications_integrals/length_of_curves.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 44.7586206897, "max_line_length": 167, "alphanum_fraction": 0.6020801233, "num_tokens": 1008, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299509069106, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7648985126421731}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 3.3 Random Numbers: Exponential, Rayleigh, and Poisson\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nGenerate pseudorandom numbers from the exponential and Rayleigh\ndistributions and pseudorandom integers from the Poisson distribution.\n\n\\subsection{Usage}\n\n\\subsubsection{Generating exponential pseudorandom numbers}\n\nThe density function for the exponential distribution with mean and standard\ndeviation, $\\mu $, has the value zero for $x < 0$ and $\\mu^{-1} \\exp (-x/\\mu )$ for $%\nx \\geq 0$. The cumulative distribution function has the value zero for $x <\n0 $ and $1- \\exp (- x/\\mu )$ for $x \\geq 0$. If $u$ is a random variable\nhaving the uniform distribution on [0,~1] then $x = - \\mu \\ \\log u$ is a\nrandom variable having the exponential distribution with mean and standard\ndeviation, $\\mu .$\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf SRANE, XMEAN, X}\n\\end{description}\n\nAssign a value to XMEAN.\n$$\n\\fbox{{\\bf X = SRANE(XMEAN)}}\n$$\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[XMEAN]  \\ [in] Specifies the mean and standard deviation of the\ndesired exponential distribution. Require XMEAN $>0.$\n\n\\item[SRANE]  \\ [out] The function returns a nonnegative pseudorandom number\nfrom the exponential distribution with mean and standard deviation equal to\nXMEAN.\n\\end{description}\n\n\\subsubsection{Generating Rayleigh pseudorandom numbers}\n\nThe density function for the Rayleigh distribution with scaling parameter, $%\n\\alpha $, has the value zero for $x < 0$ and\n\\begin{equation*}\n(x/\\alpha ^2) \\exp (-x^2/2\\alpha ^2)\n\\end{equation*}\nfor $x \\geq 0$. The cumulative distribution function has the value zero for $%\nx < 0$ and\n\\begin{equation*}\n1 - \\exp(-x^2/2 \\alpha ^2)\n\\end{equation*}\nfor $x \\geq 0$. The mean and standard deviation of this distribution are\n\\begin{equation*}\n\\mu = \\alpha \\sqrt{\\pi /2} \\approx 1.25331\\ \\alpha\n\\end{equation*}\nand\n\\begin{equation*}\n\\sigma = \\alpha \\sqrt{2 - \\pi /2} \\approx 0.655136\\ \\alpha\n\\end{equation*}\nIf $u$ is a random variable having the uniform distribution on [0,~1] then\n\\begin{equation*}\nx = \\alpha \\sqrt{-2 \\log u}\n\\end{equation*}\nis a random variable having the Rayleigh distribution with scaling\nparameter, $\\alpha .$\n\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf SRANR, ALPHA, X}\n\\end{description}\n\nAssign a value to ALPHA.\n$$\n\\fbox{{\\bf X = SRANR(ALPHA)}}\n$$\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[ALPHA]  \\ [in] Specifies the scaling of the desired Rayleigh\ndistribution. Require ALPHA $>0$. The distribution will have mean = ALPHA $%\n\\times \\sqrt{\\pi /2}$ and variance = ALPHA$^2\\times (2-\\pi /2).$\n\n\\item[SRANR]  \\ [out] The function returns a nonnegative pseudorandom number\nfrom the Rayleigh distribution with scaling parameter, ALPHA.\n\\end{description}\n\n\\subsubsection{Generating Poisson pseudorandom integers}\n\nThe Poisson distribution with mean and variance, $\\mu $, is defined over\nnonnegative integers. The nonnegative integer, $k$, occurs with probability $%\np_k$ given by%\n\\begin{equation*}\np_k=e^{-\\mu }\\frac{\\mu ^k}{k!}\n\\end{equation*}\n\\paragraph{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf XMEAN}\n\n\\item[INTEGER]  \\ {\\bf ISRANP, K}\n\\end{description}\n\nAssign a value to XMEAN.\n$$\n\\fbox{{\\bf K = ISRANP(XMEAN)}}\n$$\n\n\\paragraph{Argument Definitions}\n\n\\begin{description}\n\\item[XMEAN]  \\ [in] Specifies the mean and variance of the desired Poisson\ndistribution. XMEAN must be positive and not so large that exp($-$XMEAN)\nwould underflow. For example if the underflow limit is $10^{-38}$, XMEAN\nmust not exceed~87. This subprogram requires more computing time for larger\nvalues of XMEAN or if XMEAN is changed frequently. See Section D.\n\n\\item[ISRANP]  \\ [out] The function returns a nonnegative pseudorandom\ninteger from the Poisson distribution with mean XMEAN.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange the names SRANE, SRANR, and ISRANP to DRANE, DRANR, and IDRANP\nrespectively, and change the REAL type statements above to\nDOUBLE PRECISION. Note particularly that if either of the function names\nDRANE or DRANR is used it must be typed DOUBLE PRECISION either explicitly\nor via an IMPLICIT statement.\n\n\\subsection{Examples and Remarks}\n\nThe programs DRSRANE, DRISRANP, and DRSRANR demonstrate, respectively, the\nuse of SRANE, ISRANP, and SRANR. These programs use SSTAT1 and SSTAT2, or\nISSTA1 and ISSTA2 to compute and print statistics and a histogram based on a\nsample of~10000 numbers each.\n\nTo fetch or set the seed used in the underlying pseudorandom integer\nsequence use the subroutines described in Chapter~3.1.\n\n\\subsection{Functional Description}\n\n\\subparagraph{Method}\n\nThe exponential random number is computed as $x = -\\mu \\ \\log u$ where $u$\nis a random number from the uniform distribution on [0,~1].\n\nThe Rayleigh random number is computed as $x = \\alpha \\sqrt{-2 \\log u}$\nwhere $u$ is a random number from the uniform distribution on [0,~1].\n\nThe Poisson subprogram uses ideas from \\cite{Snow:1968:A342}.  The method\nbegins by obtaining a random number, $u$, from the uniform distribution on\n[0,~1].  Then the probabilities $p_0$, $p_1$, ..., defined above in\nSection B.3, are summed until the sum reaches or exceeds $u$.  The index\nof the last term in the sum is then returned as the Poisson random\ninteger.\n\nTo improve efficiency on the assumption that the subprogram may be\nreferenced many successive times with the value of XMEAN remaining\nunchanged, the partial sums through at most the term $p_{84}$ are stored in\nan internal array as they are computed. On subsequent references, if the\nvalue of XMEAN has not been changed, previously computed partial sums can be\ntested without the need to recompute them. The testing starts at the index\nnearest to the value, XMEAN, since these indices have the highest\nprobabilities of being selected.\n\nThese subprograms obtain uniform pseudorandom numbers by calling SRANUA or\nDRANUA, using the array in common block /RANCMS/ or /RANCMD/ as a buffer as\ndescribed in Chapter~3.1.\n\nValues returned as double-precision random numbers will have random bits\nthroughout the word, however the quality of randomness should not be\nexpected to be as good in a low-order segment of the word as in a high-order\npart.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nIn subprograms SRANE, DRANE, SRANR, and DRANR the input parameter should be\npositive, however no test is made of this. The input parameter is simply\nused as a multiplicative factor.\n\nSubprogram ISRANP will issue an error message and return the value $-1$ if\nXMEAN\\ $\\leq $ 0 or if XMEAN $\\geq -0.5\\times \\log \\,($ underflow limit ).\n\n\\subsection{Supporting Information}\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDRANE & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRANE, ERFIN, ERMSG, RANPK1, RANPK2\\rule[-5pt]{0pt}{8pt}}\\\\\nDRANR & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDRANR, ERFIN, ERMSG, RANPK1, RANPK2\\rule[-5pt]{0pt}{8pt}}\\\\\nIDRANP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, IDRANP, RANPK1, RANPK2, DERM1, DERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nISRANP & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nAMACH, ERFIN, ERMSG, ISRANP, RANPK1, RANPK2, SERM1, SERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSRANE & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, RANPK1, RANPK2, SRANE\\rule[-5pt]{0pt}{8pt}}\\\\\nSRANR & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, RANPK1, RANPK2, SRANR}\\\\\\end{tabular}\n\nBased on subprograms written for JPL by Stephen L. Richie, Heliodyne Corp.,\nand Wiley R. Bunton, JPL, 1969. Adapted to Fortran~77 for the JPL MATH77\nlibrary by C. L. Lawson and S. Y. Chiu, JPL, April~1987.\n\n1991 November: Lawson reorganized and renamed common blocks.\n\n\n\\begcodenp\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSRANE}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{srane}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRANE}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{srane}}\n\\newpage\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSRANR}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sranr}}\n\\newpage\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRANR}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sranr}}\n\n\\newpage\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRISRANP}\\vspace{0pt}\n\\lstinputlisting{\\codeloc{isranp}}\n\n\\vspace{20pt}\\centerline{\\bf \\large ODISRANP}\\vspace{5pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{isranp}}\n\\end{document}\n", "meta": {"hexsha": "5add18ff586b352443108aede62b5366e5ddf76d", "size": 9014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch03-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/ch03-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/ch03-03.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 35.628458498, "max_line_length": 98, "alphanum_fraction": 0.7536055026, "num_tokens": 2761, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178969328286, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7648978509926873}}
{"text": "\\lab{Algorithms}{LU Decomposition}{LU Decomposition}\n\\label{lab:LUdecomp}\n\\objective{In this section we will find the REF and the LU decomposition.}\n\nIn linear algebra there are three elementary row operations: switching two rows, multiplying a row by a constant, and adding a multiple of one row to another row.\nEach of these operations can, in theory, be done by left multiplication by a corresponding elementary matrix.\nThis approach is \\emph{extremely} slow in practice.\nIn practice, it 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.\nThe follow code shows how these modifications can be made in-place to an array.\n\\lstinputlisting[style=python,name=]{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\\begin{pmatrix}\n4&5&6&3 \\\\\n2&4&6&4 \\\\\n7&8&0&5\n\\end{pmatrix}\n\\]\nUsing elementary row operations, we can reduce $A$ to REF as follows:\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}\nThe additional requirement is often added that the first nonzero entry of each row be 1.\nDo 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.\nIn this case it made little difference, but it is good to watch for things like this because they can save a great deal more time when working with larger matrices.\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.\n\\end{problem}\n\n\\section*{LU Decomposition}\nUsing row reduction we can reduce an invertible matrix $A$ to upper triangular form.\nSay this can be done in $k$ row operations.\nLet $U$ be the upper triangular form of $A$, so we have:\nHence, we have\n\\[\nU = E_k \\dots E_2 E_1 A.\n\\]\nSince the elementary matrices are invertible, we also have\n\\[\n(E_k \\dots E_2 E_1)^{-1} U =  A.\n\\]\nThen we define $L$ to be\n\\[\nL = (E_k \\dots E_2 E_1)^{-1}\n\\]\nwhich is the same as\n\\[\nL = E_1^{-1} E_2^{-1} \\dots E_k^{-1}\n\\]\nIn either case, we have $L U = A$.\n\nThe inverses of elementary matrices are also elementary matrices. $L$ can be computed by applying a series of simple operations to an identity matrix.\nAs it turns out, when we are only doing type 3 row operations, each of the operations represented by right multiplication by these inverse matrices results in a change in a single entry of $L$.\n\nIn practice, the LU decomposition of an array $A$ can be computed like this:\n\\begin{itemize}\n\\item Make a copy $U$ of $A$.\n\\item Make an identity matrix $L$ of the same shape as $A$.\n\\item Iterate through the entries below the diagonal of $U$.\nFor 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}\nIn this case, we have ignored the possibility that a 0 may appear along the main diagonal during computation.\nA full implementation of the LU decomposition would have to account for this possibility as well.\n\n\\section*{Why This Matters}\nThe LU decomposition is more efficient for solving linear systems than traditional row reduction.\nIt also can be applied to matrices with more than one column.\nThe $LU$ decomposition also allows quick computation of inverses and determinants.\nFor very large matrices, the LU decomposition can be performed without using any extra space.\n$L$ can be stored above the main diagonal of the array and $U$ can be stored below it.\nThere 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 Python function takes as input 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\n\\begin{problem}\n\\label{prob:lusolve}\nWrite 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.\nNo changes to the array storing the LU decomposition are necessary.\n\\end{problem}\n\n\\begin{problem}\n\\label{prob:det}\nWrite a function which uses the solution to Problem \\ref{prob:REF} to find the determinant of $A$.\nNotice that the solution to Problem \\ref{prob:REF} computes $U$ when applied to a square matrix.\n\\end{problem}\n\nSciPy includes more complete implementations of the LU decomposition in the \\li{linalg} module.\nThis LU implementation returns an additional array that shows any row swaps that were made during the decomposition.\nThe LU decomposition is calculated with \\li{lu}.\n\\li{lu_factor} calculates the LU decomposition and stores it in a single array.\nIt returns a tuple of arrays, one which is the LU decomposition and the other of which represents the necessary permutation of the rows.\n\\li{lu_solve} takes the output from \\li{lu_factor} and uses it to solve a linear system.\nUsing \\li{lu_factor} and \\li{lu_solve} is a good alternative to inverting large matrices since it is faster to compute an LU decomposition than it is to invert a matrix.\n\n\\section*{The Cholesky Decomposition (Optional)}\n\nFor certain circumstances, we have a more efficient alternative to the LU decomposition.\nThe Cholesky decomposition requires half the number of calculations and half the memory that the standard LU decomposition needs.\nFurthermore, it is a numerically stable decomposition, which makes it all the more useful.\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, Hermitian is equivalent to symmetric) positive definite matrices.\nIn fact, the Cholesky decomposition is an efficient way to test if a matrix is positive definite.\nThe Cholesky decomposition of a positive definite matrix is unique.\nThink of the Cholesky decomposition as the matrix equivalent taking the square root of a positive real number.\n\nThe Cholesky decomposition of a $A$ is an lower-triangular matrix, $L$, such that\n\\begin{equation*}\n A = LL^*\n\\end{equation*}\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\\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*}\nwhere $L^*$ denotes the conjugate transpose of $L$.\n\nNotice that in this computation, current calculation will depend on previous calculations.\nTo 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}\nModify your previous answer so that it computes the Cholesky decomposition by modifying the array in place.\nMake sure you set the portion of the array above the main diagonal to 0.\nThen write a function that takes this reduced form of the array and uses it to solve a linear system by back substitution.\nThis 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 computed.\nIt works much like the LU decomposition.\n\\li{cho_factor} returns the cholesky decomposition of the array that can then be used in solving a linear system with \\li{cho_solve}.", "meta": {"hexsha": "d24c889aed51f17ca450a17c992968964101428b", "size": 9312, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/LUdecomposition/LUdecomposition.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/LUdecomposition/LUdecomposition.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/LUdecomposition/LUdecomposition.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": 54.4561403509, "max_line_length": 280, "alphanum_fraction": 0.7524699313, "num_tokens": 2414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.9086178926024029, "lm_q1q2_score": 0.7648978311215724}}
{"text": "\\section{Binary classification}\n\\textbf{Binary Classification: Assign each data point to one of two classes.} \n\nExamples:\n\\begin{itemize}\n \\item Is there a face in this image?\n\\item Will this neuron spike in response to this stimulus?\n\\item Based on this brain-scan, does this patient have a given disease or not?\n\\item  Will this customer buy this product or not?\n\\item Is this person likely to be a democrat/republican? \n\\end{itemize}\nNotation: we have data $D=\\{(x_1, t_1),\\ldots, (x_N, t_N)\\}$, with $t_n=1$ if $x_n$ belongs to class $1$ and $t_n=-1$ if $x_n$ belongs to class $-1$.\n\n\n\\textbf{We focus on linear decision rules, also known as `linear discriminant functions'.} \n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/LinClassification.pdf}\n\t\t\\caption{Linear classification.}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\centering\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/NonLinClassification.pdf}\n\t\t\\caption{Non-linear classification.}\n\t\\end{subfigure}\n\t\\caption{A classical dichotomous classification problem where the blue crosses belong to the positive class and the red circles belong to the negative class. We want to find a function which separates the two classes.}\n\\end{figure}\n\nOf course, linear algorithms can be used together with \\emph{nonlinear feature spaces} or \\emph{nonlinear basis functions} in order to solve nonlinear classification problems!\n\n\n\\textbf{Linear discriminants separate the space by a hyperplane, and the parameters define its normal vector.} \n\n\\begin{itemize}\n\\item Decision function: $y(\\xx)=\\omega^\\top \\xx + \\omega_o$\n\\item  Classification: \\begin{align}\n\\mbox{if~}y(\\xx)>0 & \\mbox{~say $\\xx$ belongs to class 1}\\\\\n\\mbox{if~}y(\\xx)<0 & \\mbox{~say $\\xx$ belongs to class -1}\\\\\n \\end{align}\n\\item The decision-surface has equation $y(\\xx)=0$, and is a hyperplane of dimensionality $D-1$ (codimension).\n\\item  $\\omega$ is the normal vector to the plane, and points into the positive class.\n\\item  $\\omega_o$ determines the location of the decision-surface \\\\\n\t   changing $\\omega_o$ changes the ratio between FPs and FNs\n\\item  $|y(\\xx)|$ is proproptional to the perpendicular distance to the decision-surface (with factor $1$ if $|| \\omega ||=1$).\n\\item the distance of a data point from the hyperplane reflects the certainty about the class membership.\n\\end{itemize}\n\n\n\\textbf{Multiple algorithms and methods exist for finding a good $\\omega$.} \n\\begin{itemize}\n\\item Mis-classification rate $C(\\omega)= \\frac{1}{N} \\sum_n \\overbrace{\\delta\\left[y(\\xx_n) =t_n\\right]}^{\\delta(x=0) = 1; \\; \\delta(x \\not= 0) = 0}$ (i.e. average number of errors) difficult to optimize over $\\omega$, and might have multiple solutions.\n\t\\begin{itemize}\n\t\t\\item This error function is not continuous and therfore not differentiable\t\n\t\t\\item No convergence if there is no solution with zero errors\n\t\t\\item Compare: Rosenblatt perceptron. The perceptron learning rule utilizes a 0-1-loss function and is guaranteed to converge in a finite number of steps as long as the data is linearly seperable. It will however not converge for overlapping data.\n\t\\end{itemize}\n\\item  Many algorithms can be derived by replacing $C$ by another cost-function which can be optimized.\n\\item  Linear classification algorithms include Least-square classification, Fisher's linear Discriminant, Logistic regression, Support Vector Machines and Rosenblatts' perceptron.\n\\end{itemize}\n\n\n\\subsection{Least Square Classification}\n\\textbf{You already know one algorithm for linear classification: least square classification.} \n\\begin{itemize}\n\\item We have to fit the function $y(\\xx)= \\omega^\\top \\xx+ \\omega_o $ to data.\n\\item  Simply do a linear regression from $\\xx$ to $t$ by minimizing the sum-of-squared errors $\\sum_n (y(\\xx_n)-t_n)^2$.\n\\item  $\\omega_{reg}=  \\left(\\sum_n x_n x_n^\\top  \\right)^{-1} \\sum_n x_n t_n$\n\\item  Q: In what situations might this be a bad idea?\n\\end{itemize}\n\n\\begin{bbbox}{Q: In what situations might this be a bad idea?}\n\tIn the case of a least-squares classification the hyperplane is mainly constrained by data points far away from the decision boundary. However if those data points are not perfectly aligned with the rest of the data points from the same class this can lead to a strong estimation error for the decision boundary as can be seen in figure \\ref{fig:least_sq_class} left. A preferable measure contrains the hyperplane based on data points close to the decision boundary and neglects outliers. Compare: Support Vector Machine.\n\\end{bbbox}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure44a.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure44b.pdf}\n\t\\end{subfigure}\n\t\\caption{Bishop Figure 4.4}\n\t\\label{fig:least_sq_class}\n\\end{figure}\n\n\n\n\n\\subsection{Fisher's linear discriminant}\n\\textbf{'Fisher's linear discriminant' is a classical and simple algorithm for linear classification} \n\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure46a.pdf}\n\t\t\\caption{Separartion of the projected class means}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure46b.pdf}\n\t\t\\caption{Fisher linear discriminant.}\n\t\\end{subfigure}\n\t\\caption{Bishop Figure 4.6}\n\\end{figure}\n\n\n\\begin{itemize}\n\\item $\\mathbf{m_+}= \\frac{1}{N_+}\\sum_{n \\in C_+} x_n$ \\hspace{.5cm} $\\mathbf{m_{-}}= \\frac{1}{N_-}\\sum_{n \\in C_{-}} x_n$ \n\\item  Maximize projection-distance of class means \n[projected mean/variance: on board]\n$\\omega_{simple} \\propto \\mathbf{m}_+-\\mathbf{m}_-$ \n\\end{itemize}\n\n\\begin{bbbox}{Maximize projection-distance of class means. The simple rule.}\n\t\\begin{flalign*}\n\t\t&\\text{Find } \\omega \\text{ such that} \\\\\n\t\t&d(m_+,m_-) \\text{ is minimized} \\\\\n\t\t&\\text{subject to } \\|w\\| = 1 \\\\\n\t\t&\\text{where } d = \\left( \\omega^{\\top} m_+ - \\omega^{\\top} m_- \\right)^2 \\\\\n\t\t&\\Rightarrow \\omega_{opt} = \\alpha \\left(m_+ - m_- \\right)\n\t\\end{flalign*}\n\\end{bbbox}\n\n\\begin{itemize}\n\\item  Maximizing distance between means ignores that the projected variances might also be big. \n\\item  Fix:  Maximize the ratio of between-class variance to within-class variance ('signal to noise'). Fisher criterion\n\\begin{align}\n\tJ_\\omega = 2\\frac{(m_+-m_-)^2}{s_+^2+s_-^2}\n\\end{align}\n[Details and solution: on board]\n\n\\begin{bbbox}{Fisher's linear discriminant: Maximize the ratio of between-class variance and within-class variance.}\n\t\\begin{align*}\n\t\t\\text{Numerator: } N &= d\\left( \\omega^{\\top}m_+, \\omega^{\\top}m_- \\right) \\\\\n\t\t                     &= \\left( \\omega^{\\top} m_+ - \\omega^{\\top} m_- \\right)^2 \\\\\n%\t\t                     &=: (m_+-m_-)^2 \\\\\n%\t\tN &= \\left( \\omega^{\\top} m_+ - \\omega^{\\top} m_- \\right)^2 \\\\\n\t\t  &= \\left( \\omega^{\\top} m_+ - \\omega^{\\top} m_- \\right) \\left( \\omega^{\\top} m_+ - \\omega^{\\top} m_- \\right)^{\\top} \\\\\n\t\t  &= \\omega^{\\top} (m_+-m_-) (m_+-m_-)^{\\top} \\omega \\\\\n\t\t  &= \\omega^{\\top} \\underbrace{S_B}_{\\text{between-class variance}} \\omega \\\\\n\t\tS_+^2 &= \\mbox{Var}\t\\left( \\omega^{\\top} x | x \\in C_+ \\right) \\\\\n\t\t\t  &= \\omega^{\\top} \\mbox{Cov}\t\\left( x | x \\in C_+ \\right) \\omega \\\\\n        S_-^2 &= \\omega^{\\top} \\mbox{Cov}\t\\underbrace{\\left( x | x \\in C_- \\right)}_{\\Sigma_-} \\omega \\\\\n        D &= \\omega^{\\top} \\left[ \\frac{1}{2} \\Sigma_+ + \\frac{1}{2} \\Sigma_- \\right] \\omega \\\\\n          &= \\omega^{\\top} \\underbrace{S_W}_{\\text{within-class variance}} \\omega \\\\\n        J(\\omega) &= \\frac{N}{D} = \\frac{\\omega^{\\top} S_B \\omega}{\\omega^{\\top} S_W \\omega} \\\\\n        \\Rightarrow \\omega_{opt} \\propto S_W^{-1} \\left(m_+ - m_- \\right)\n\t\\end{align*}\n\\end{bbbox}\n\n \n$\\omega_{lda}= \\Sigma_w^{-1} (\\mathbf{m}_+-\\mathbf{m}_-)$ \\\\\nHowever Fisher's linear discriminant is still sensitive to outliers.\n\\end{itemize}\n\n%http://users.informatik.uni-halle.de/~hinnebur/Lehre/BN_seminar_web/bn_05_ag.pdf\n\n\n\\textbf{Aside: The multivariate Gaussian} \n\\begin{itemize}\n\\item Probability density function of $D$ dimensional Gaussian with mean $\\mu$ an covariance $\\Sigma$: \\begin{align}p(x| \\mu, \\Sigma)&= (2\\pi)^{-D/2}|\\Sigma|^{-1/2} \\exp \\left(-\\frac{1}{2} (x-\\mu)^\\top \\Sigma^{-1} (x-\\mu) \\right) \\\\\n \\end{align}\n\\item  Maximum likelihood estimation of parameters: \\begin{align}\n\\hat\\mu= &\\frac{1}{N}\\sum_n x_n\\mbox{~~(empirical mean)}\\\\ \n\\hat \\Sigma= &\\frac{1}{N} \\sum_n x_n x_n^\\top- \\hat\\mu \\hat \\mu^\\top\\mbox{~~(empirical covariance)} \n \\end{align}\n\\end{itemize}\n\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure28a.pdf}\n\t\t\\caption{Positive correlation.}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure28b.pdf}\n\t\t\\caption{Independence but different variances.}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.3\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure28c.pdf}\n\t\t\\caption{Independence and uni-variance.}\n\t\\end{subfigure}\n\t\\caption{Multivariate Gaussians with different covariance matrices. Bishop Figure 2.8}\n\\end{figure}\n\n\\textbf{A (super brief) primer on covariance matrices. (more details/intuition in second half of course?)} \n\n\\begin{figure}\n\t\\includegraphics[width=.45\\textwidth]{./lecture6/Figure27.pdf}\n\t\\caption{Bishop Figure 2.7}\n\\end{figure}\n\n\\begin{itemize}\n\t\\item  Covariance matrices are symmetric.\n\t\\item  Diagonal entries: variances along coordinate-axes\n\t\\item  Eigenvectors: principal axes of ellipsoid\n\t\\item Eigenvalues:  variances along eigen-vectors\n\t\\item Eigenvector with maximal/minimal eigen-value: Direction of maximal/minimal variance \n\t\\item  Covariance matrices are `positive definite', i.e. all their eigenvalues are non-negative.\n\t\\item  Most of this can be derived from $a^\\top \\mbox{Cov}(X) a= \\mbox{Var}(a^\\top X)$\n\\end{itemize}\n\n\\subsection{A generative model: Class-conditional Gaussians}\n\\textbf{A tale of two Gaussian: We can use a probablistic model of the data for classification} \n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure410a.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure410b.pdf}\n\t\\end{subfigure}\n\t\\caption{Bishop 4.10}\n\\end{figure}\n\n\n\\begin{itemize}\n\t\\item Suppose that each of the two classes is modelled by a Gaussian: $x | x \\in C_+ \\sim \\mathcal{N}\\left(\\mu_+, \\Sigma_+\\right)$, $x | x \\in C_- \\sim \\mathcal{N}\\left(\\mu_-, \\Sigma_-\\right)$, \n\t\\item ~[On board] Calculation of posterior class probabilities and decision criterion\n\t\\item  If we assume $\\Sigma_+=\\Sigma_-$, we get $\\omega_{gauss} \\propto \\Sigma_+^{-1} (\\mathbf{m}_+-\\mathbf{m}_-)$\n\t\\item Note: We take the $t_n$ as given and built a model of $x_n | t_n$, contrast with linear regression, where we took $x_n$ as given and modelled $t_n |x_n$.\n\\end{itemize}\n\n\\begin{bbbox}{Probabilistic generative model: Gaussians}\nWe assume that data from each of the two classes is normally distributed  such that: \\\\\n\t\\begin{flalign*}\n\t& P(x|t=1) = \\mathcal{N}\\left( x| \\mu_+,\\Sigma_+ \\right) &\\\\\n\t& P(x|t=-1) = \\mathcal{N}\\left( x| \\mu_-,\\Sigma_- \\right) &\\\\\n\t\\end{flalign*}\n\nIf we know the prior probabilities $\\pi$ for observing data from any of the two classes we can caculate the posterior probability of a data point belonging to each of the classes. This is by simply utilizing Bayes' theorem. \\\\\n\t\\begin{flalign*}\n\t& P(t=1|x) = \\frac{1}{Z} P(x|t=1) \\underbrace{P(t=1)}_{\\pi_+} = \\frac{\\pi_+}{Z} P(x|t=1) &\\\\\n\t& \\text{where} &\\\\\n\t& Z = \\pi_+ P(x | t = 1) + \\pi_{-} P(x | t = -1) \\text{ is a normalization constant} &\\\\\n\t& \\text{and} &\\\\\n\t& P(t = 1 | x) + P(t = -1|x) = 1\t&\\\\\n\t\\end{flalign*}\n\t\nWe now use the log-odds to find the decision boundary for our classification problem. We assign data point $x$ to the positive class if $d(x) > 0$ and we will assign it to the negative class otherwise: \\\\\n\t\\begin{flalign*}\n\t\td(x) &=  \\log \\left[ \\frac{P(t=1|x)}{P(t=-1|x)}\\right] \\\\\n\t\t     &= C - \\frac{1}{2} \\left(x-\\mu_+\\right)^{\\top} \\Sigma_+^{-1} \\left(x-\\mu_+\\right) \\\\\n\t\t     \t &\\qquad {} + \\frac{1}{2} \\left(x-\\mu_-\\right)^{\\top} \\Sigma_-^{-1} \\left(x-\\mu_-\\right) \\\\\n\t\t\\textbf{Assume } \\Sigma_+ = \\Sigma_- = \\Sigma  \\\\\n\t\t     &= C - \\frac{1}{2} x^{\\top} \\Sigma^{-1} x + \\frac{1}{2} \\mu_+^{\\top} \\Sigma^{-1} x + \\frac{1}{2} x^{\\top} \\Sigma^{-1} \\mu_+ - \\frac{1}{2} \\mu_+^{\\top} \\Sigma^{-1} \\mu_+ \\\\\n\t\t        &\\qquad {} + \\frac{1}{2} x^{\\top} \\Sigma^{-1} x - \\frac{1}{2} \\mu_-^{\\top} \\Sigma^{-1} x -\\frac{1}{2} x^{\\top} \\Sigma^{-1} \\mu_- + \\frac{1}{2} \\mu_-^{\\top} \\Sigma^{-1} \\mu_- \\\\\n\t\t     &= C_2 + \\mu_+^{\\top} \\Sigma^{-1} x - \\mu_-^{\\top} \\Sigma^{-1} x \\\\\n\t\t     &= C_2 + \\left( \\mu_+ - \\mu_- \\right)^{\\top} \\Sigma^{-1} x \\\\\n\t\t     &= C_2 + \\left[ \\Sigma^{-1} \\left( \\mu_+ - \\mu_- \\right) \\right]^{\\top} x \\\\\t\t     \n\t\t     &= \\omega_0 + \\omega^{\\top}x\n\t\\end{flalign*}\nIf we compare this result with our results for FDA and linear regression for classification we realize that all three approach lead to equivalent decision boundaries.\n\\end{bbbox}\n\n\\textbf{This approach directly generalizes to classification with unequal covariances and multi-class classification.}\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure411a.pdf}\n\t\\end{subfigure}\n\t~\n\t\\begin{subfigure}[b]{0.45\\textwidth}\n\t\t\\includegraphics[width=\\textwidth]{./lecture6/Figure411b.pdf}\n\t\\end{subfigure}\n\t\\caption{Bishop 4.11}\n\\end{figure}\n\n\\begin{itemize}\n\\item Quadratic discriminant analysis: $\\Sigma_+ \\neq \\Sigma_o$, decisison boundary is of form $y(\\xx) = \\xx^\\top A \\xx+\\omega^\\top \\xx +\\omega_o$\n\\item Multi-class: Assign each data-point to class with highest posterior probability (or calculate best assignment from cost-function). \n\\end{itemize}\n\n\\textbf{A simple nonlinear classifier can be constructed from kernel density estimates of the probability densities.}\n\n\\includegraphics[width=\\textwidth]{./lecture6/NonLinClassification.pdf}\n\\begin{itemize}\n\t\\item Idea: Once we have an estimate of the class-conditional densities $P(x| t=\\pm 1)$, we can construct a rule from $d(x)=P(x| t=+ 1)-P(x| t=- 1)$.\n\t\\item  Use \\emph{kernel density estimation} to estimate  $P(x| t=\\pm 1)$, i.e. place a `Gaussian bump' on each data-point:\n\t\\begin{align}\n\t\tP(x| t=1) =\\frac{1}{Z}\\sum_{n_+} \\exp\\left( \\frac{x-x_n}{\\sigma}\\right)^2\n\t\\end{align}\n\\end{itemize}\n\nThis leads to a classifier of the form\n\\begin{align}\n\td(x)= \\sum_{n} \\alpha  t_n \\exp\\left( \\frac{x-x_n}{\\sigma}\\right)^2\n\\end{align}\n\n\\emph{Support vector machine with radial basis functions} has decision rule \n\\begin{align}\n\td(x)=\\sum_{n}  \\alpha_n \\exp\\left( \\frac{x-x_n}{\\sigma}\\right)^2\n\\end{align}\n\n\n\n\n\n\\subsection{One for the price of three.} \n\\begin{itemize}\n\t\\item Today, you learned about three different algorithms for binary classification with linear decision rules. \n\t\\item  One was based on a hack, the second one on a plausible (but ad-hoc) criterion, and the third one an a probababilistic model of the data.\n\t\\item  All three algorithms are equivalent.\n\t\\item  We showed that the Fisher discriminant and the probabilistic model based on two Gaussians have the same  decision criterion. In fact, it can be shown that linear regression has the same weights (Bishop 4.1.5)\n%\\item  The moral: Great motivations are great, but the actual algorithm matters, and it is important to check connections with other algorithms.\n\t\\item The third motivation had immediate extensions to nonlinear algorithms and multi-class classification, and posterior probabilities.\n\t\\item  Next week, we will learn an algorithm which actually is different, and usually better than the ones discussed today.\n\\end{itemize}\n\n", "meta": {"hexsha": "85669c0ff37ab992c17e18b33cc14efe14716b18", "size": 15839, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture6/lecture6.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/lecture6/lecture6.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/lecture6/lecture6.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": 49.1894409938, "max_line_length": 522, "alphanum_fraction": 0.6973925122, "num_tokens": 5090, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8652240825770432, "lm_q2_score": 0.8840392863287584, "lm_q1q2_score": 0.764892080475864}}
{"text": "\\chapter{Basic Statistics}\n\nYou live near a freeway, and someone asks you, ``How fast do cars on that freeway drive?''\n\nYou say ``Pretty fast.''\n\nAnd they say, ``Can you be more specific?''\n\nAnd you point your radar gun at a car, and say ``That one is going 32.131 meters per second.''\n\nAnd they say, ``I don't want to know about that specific car. I want to know about all the cars.''\n\nSo, you spend the day beside the freeway measuring the speed of every\ncar that goes by. And you get a list of a thousand numbers. Here is part of the\nlist:\n\n\\begin{tabular}{c | c | c}\n30.462 m/s  & 29.550 m/s & 29.227 m/s \\\\\n37.661 m/s  & 27.899 m/s & 28.113 m/s \\\\\n24.382 m/s & 35.668 m/s & 43.797 m/s \\\\\n31.312 m/s & 37.637 m/s & 30.891 m/s\n\\end {tabular}\n\nThere are 12 numbers here. We say that there are 12 \\textit{samples}.\\index{samples}\n\n\\section{Mean}\n\nWe often talk about the \\textit{average} of a set of samples, which is the \nsame as the \\textit{mean}. To get the mean, sum up the\nsamples and divide that number by the number of samples.\\index{mean}\n\nThe numbers in that table sum to $388.599$.  If you divide that by 12,\nyou find that the mean of those samples is 32.217 m/s.\n\nWe typically use the greek letter $\\mu$ (``mu'') to represent the mean.\n\n\\begin{mdframed}[style=important, frametitle={Definition of Mean}]\n  \nIf you have a set of samples $x_1, x_2, \\ldots, x_n$, the mean is:\n\n$$ \\mu = \\frac{1}{n} \\sum_{i=1}^n x_i$$\n\n\\end{mdframed}\n\nThis may be the first time you are seeing a summation ($\\sum$). The equation above is equivalent to:\\index{summation symbol}\n\n$$ \\mu = \\frac{1}{n} \\left(x_1 + x_2 + \\ldots + x_n\\right)$$\n\n\\begin{Exercise}[title={Mean Grade}, label=grades_mean]\n\n  Teachers often use the mean for grading. For example, if you took\n  six quizzes in a class, your final grade might be the mean of the six\n  scores. Find the mean of these six grades: 87, 91, 98, 65, 87, 100.\n\n\\end{Exercise}\n\\begin{Answer}[ref=grades_mean]\n\n  $$\\mu =\\frac{1}{6} \\left(87 + 91 + 98 + 65 + 87 + 100 \\right) = 88$$\n\n\\end{Answer}\n\nIf you tell your friend ``I measured the speed of 1000 cars, and the\nmean is 31.71 m/s'', your friend will wonder ``Are most of the speeds\nclustered around 31.71? Or are they all over the place and just happen\nto have a mean of 31.71?'' To answer this question we use variance.\n\n\\section{Variance}\n\n\\begin{mdframed}[style=important, frametitle={Definition of Variance}]\n\nIf you have $n$ samples $x_1, x_2, \\ldots, x_n$ that have a mean of $\\mu$, the \\textit{variance} is defined to be:\\index{variance}\n\n$$v = \\frac{1}{n}\\sum_{i = 1}^{n} \\left(x_i - \\mu\\right)^2$$\n% ADD: Maybe connect to Chi-squared test\n\\end{mdframed}\n\nThat is, you figure out how far each sample is from the median, you\nsquare that, and then you take the mean of all those squared\ndistances.\n\n\\begin{tabular} {c | c | c}\n\n  $x$ & $x - \\mu$ & $(x - \\mu)^2$\\\\\n  \\hline\n30.462 & -1.755 & 3.079 \\\\\n29.550 & -2.667 & 7.111\\\\\n29.227 & -2.990 & 8.938\\\\\n37.661 & 5.444 & 29.642\\\\\n27.899 & -4.318 & 18.642\\\\\n28.113 & -4.104 & 16.839 \\\\\n24.382 & -7.835 & 61.381 \\\\\n35.668 & 3.451 & 11.912 \\\\\n43.797 & 11.580 & 134.106\\\\\n31.312 & -0.905 & 0.818\\\\\n37.637 & 5.420 & 29.381\\\\\n30.891 & -1.326 & 1.757\\\\\n\\hline\n$\\sum x = 386.599$ & & $\\sum (x - \\mu)^2 = 323.605$\\\\\nmean = 32.217 & & variance = 26.967\n\\end{tabular}\n\nThus, the variance of the 12 samples is 26.967. The bigger the variances, \nthe farther the samples are spread apart; the smaller the variances, the closer\nsamples are clustered around the mean.\n\nNotice that most of the data points deviate from the mu by 1 to 5\nm/s. Isn't it odd that the variance is a big number like 26.967?\nRemember that it represents the average of the squares. Sometimes, to\nget a better feel for how far the samples are from the mean, we use\nthe square root of the variance, which is called \\textit{the standard\n  deviation}.\n\nThe standard deviation of your 12 samples would be $\\sqrt{26.9677} =\n  5.193$ m/s.\n% ADD: Bell curve, KA: https://www.khanacademy.org/computer-programming/spin-off-of-galton-board-exploration/1930953307/embedded?embed=yes&article=yes&editor=no&buttons=no&author=no&width=400&height=400\n\nThe standard deviation is used to figure out a data point is an\noutlier. For example, if you are asked``That car that just sped\npast. Was it going freakishly fast?'' You might respond, ``No, it was\nwithin a standard deviation of the mean.'' or ``Yes, it's speed was 2\nstandard deviations more than the mean. They will probably get a ticket.''\n% ADD: Box and whiskers plot?\n\nA singular $\\mu$ usually represents the mean. $\\sigma$ usually represents\nthe standard deviation. So $\\sigma^2$ represents the variance.\n\n\\begin{Exercise}[title={Variance of Grades}, label=grades_variance]\n\n  Now find the variance for your six grades. As a reminder, they were: 87, 91, 98, 65, 87, 100.\n\n  What is your standard deviation?\n\n\\end{Exercise}\n\\begin{Answer}[ref=grades_variance]\n\n  The mean of your grades is $88$.\n\n  The variance, then is\n\n  $$\\sigma^2 = \\frac{1}{6} \\left((87 - 88)^2 + (91 - 88)^2 + (98 - 88)^2 + (61 - 88)^2 + (87 - 88)^2 + (100 - 88)^2 \\right) = \\frac{784}{6} = 65 \\frac{1}{3}$$\n\n  The standard deviation is the square root of that: $\\sigma = 8.083$ points.\n  \n\\end{Answer}\n\n\n\\section{Median}\n\nSometimes you want to know where the middle is. For example, you want\nto know the speed at which half the cars are going faster and half are\ngoing slower. To get the median, you sort your samples from smallest\nto largest. If you have an odd number of samples, the one in the\nmiddle is the median. If you have an even number of samples, we take\nthe mean of the two numbers in the middle.\\index{median}\n% KA: https://www.khanacademy.org/math/cc-sixth-grade-math/cc-6th-data-statistics/mean-and-median/v/statistics-intro-mean-median-and-mode\n\nIn our example, you would sort your numbers and find the two in the middle:\n\n\\begin{tabular}{c}\n24.382\\\\\n27.899\\\\\n28.113\\\\\n29.227\\\\\n29.550\\\\\n\\hline\n\\textbf{30.462}\\\\\n\\textbf{30.891}\\\\\n\\hline \n31.312\\\\\n35.668\\\\\n37.637\\\\\n37.661\\\\\n43.797\\\\\n\\end{tabular}\n\nYou take the mean of the two middle numbers: $(30.462 + 30.891)/2 =\n30.692$.  The median speed would be 30.692 m/s.\n\nMedians are often used when a small number of outliers majorly skew the\nmean. For example, income statistics usually use the median income\nbecause a few hundred billionares raise the mean a lot.\n\n\\begin{Exercise}[title={Median Grade}, label=grades_median]\n\n  Find the median of your six grades: 87, 91, 98, 65, 87, 100.\n\n\\end{Exercise}\n\\begin{Answer}[ref=grades_median]\n\n  In order the grades are 65, 87, 87, 91, 98, 100.  The middle two are 87\n  and 91. The mean of those is 89. (Speed trick: The mean of two numbers is the\n  number that is half-way between.)\n  \n \\end{Answer}\n\n\n\\section{Histograms}\n\nA histogram is a bar chart that shows how many samples are in each\ngroup. In our example, we group cars by speed. Maybe we count the\nnumber of cars going between 30 and 32 m/s.  And then we count the\ncars going between 32 and 34 m/2. And then we make a bar chart from\nthat data.\\index{histograms}\n% ADD: Have not explained histograms yet\n\nYour 1000 cars would break up into these groups:\n\n\\begin{tabular}{ c | c }\n0 - 2 m/s & 0 cars \\\\\n2 - 4 m/s & 0 cars \\\\\n4 - 6 m/s & 0 cars \\\\\n\\ldots & \\ldots \\\\\n20 - 22 m/s & 0 cars \\\\\n22 - 24 m/s & 0 cars \\\\\n24 - 26 m/s & 65 cars \\\\\n26 - 28 m/s & 160 cars \\\\\n28 - 30 m/s & 175 cars \\\\\n30 - 32 m/s & 168 cars \\\\\n32 - 34 m/s & 150 cars \\\\\n34 - 36 m/s & 114 cars \\\\\n36 - 38 m/s & 79 cars \\\\\n38 - 40 m/s & 52 cars \\\\\n40 - 42 m/s & 20 cars \\\\\n42 - 44 m/s & 12 cars \\\\\n44 - 46 m/s & 4 cars \\\\\n46 - 48 m/s & 1 cars \\\\\n48 - 50 m/s & 0 cars \\\\\n\\end{tabular}\n\nNow we make a bar chart from that:\n\n\\includegraphics[width=\\textwidth] {speed_histo.png}\n\nOften a histogram will tell the story of the data. Here, you can see\nthat no one is going less than 24 m/s, but a lot of people travel at\n30 m/s. There are a few people who travel over 40 m/s, but there are also a\ncouple of people who drive a lot faster than anyone else.\n\n\\section{Root-Mean-Squared}\n\nScientists have a mean-like statistic that they love. It is named\nquadratic mean, but most just calls it Root-Mean-Squared or\nRMS.\n\n\\begin{mdframed}[style=important, frametitle={Definition of RMS}]\n\nIf you have a list of numbers $x_1, x_2, \\ldots, x_n$, their RMS\nis \\index{quadratic mean} \\index{root-mean-squared} \\index{RMS}\n\n$$\\sqrt{\\frac{1}{n}\\left( x_1^2 + x_2^2 + \\ldots + x_n^2 \\right)}$$\n\n\\end{mdframed}\n\nYou are taking the square root of the mean of squares of the samples,\nthus the name Root-Mean-Squared.\n\nUsing your 12 samples:\n\n\\begin{tabular}{c |  c}\n  $x$ & $x^2$ \\\\\n  \\hline\n30.462 & 927.933 \\\\\n29.550 & 873.203\\\\\n29.227 & 854.218\\\\\n37.661 & 1418.351\\\\\n27.899 & 778.354\\\\\n28.113 & 790.341\\\\\n24.382 & 594.482\\\\\n35.668 & 1272.206\\\\\n43.797 & 1918.177\\\\\n31.312 & 980.441\\\\\n37.637 & 1416.544\\\\\n30.891 & 954.254\\\\\n\\hline\n\\multicolumn{1}{r}{Mean of $x^2$} & {1064.875}\\\\\n\\multicolumn{1}{r}{RMS} & {32.632}\n  \\end{tabular}\n\nWhy is RMS useful? Let's say that all cars had the same mass $m$, and\nyou need to know what the average kinetic energy per car is. If you\nknow the RMS of the speeds of the cars is $v_{rms}$, the average kinetic energy for\neach car is\n\n$$k = \\frac{1}{2}m v_{rms}^2$$\n\n(You don't believe me? Let's prove it. Substitute in the RMS:\n\n$$k = \\frac{1}{2}m \\sqrt{\\frac{1}{n}\\left( x_1^2 + x_2^2 + \\ldots + x_n^2 \\right)}^2$$\n\nThe square root and the square cancel each other out:\n\n$$k = \\frac{1}{2}m \\frac{1}{n}\\left( x_1^2 + x_2^2 + \\ldots + x_n^2 \\right)$$\n\nUse the distributive property:\n\n$$k = \\frac{1}{n} \\left( \\frac{1}{2} m x_1^2 + \\frac{1}{2}m x_2^2 + \\ldots + \\frac{1}{2}m x_n^2 \\right)$$\n\n\nThat is all the kinetic energy divided by the number of cars, which is\nthe mean kinetic enegy per car. Quod erat demonstrandum! (That is a\nLatin phrase that means ``which is what I was trying to\ndemonstrate''. You will sometimes see ``QED'' at the end of a long\nmathematic proof.))\n\nNow you are ready for the punchline: kinetic energy and heat are the\nsame thing. Instead of cars, heat is the kinetic energy of molecules\nmoving around. More on this soon.\n\nVideo: Mean, Median, Mode: https://www.youtube.com/watch?v=5C9LBF3b65s\n\n\n", "meta": {"hexsha": "75a9fd9a713c87988e95538e76fa5bde78d268c3", "size": 10186, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/MatterEnergy/basic_statistics-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/basic_statistics-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/basic_statistics-en_US.tex", "max_forks_repo_name": "hillegass/sequence", "max_forks_repo_head_hexsha": "b7b4896d804c49cbc93fe86a0d2fce531afbcc1f", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-01-05T00:43:58.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-05T00:43:58.000Z", "avg_line_length": 32.6474358974, "max_line_length": 202, "alphanum_fraction": 0.6887885333, "num_tokens": 3396, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8840392786908831, "lm_q1q2_score": 0.7648920707950978}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Computing Indefinite Integrals}\n\nIn this section, we're interested in computing {\\it indefinite integrals} or {\\it antiderivatives}.\nIndefinite integrals cannot be computed for all functions, for example, there is no closed form for the {\\bf Gaussian Integral}\n\\begin{align*}\n\t\\int \\exp\\left(-\\dfrac{x^2}{2} \\right) \\: dx\n\\end{align*}\nwhich is widely used in statistics, and the only way to compute it is using numerical methods.\n\n\nThere is no general method of computing indefinite integrals.\nInstead, in this section we'll learn a few common tricks which you can combine in various ways to solve complicated problems.\nThere are two basic tools for computing indefinite integrals\n\\begin{enumerate}\n\t\\item u-substitution and\n\t\\item integration by parts.\n\\end{enumerate}\nThese are often combined with various algebraic and trig identities.\n\nOne thing that makes the computation of indefinite integrals far more complicated than that of derivatives, in practice, is that similar looking functions can have wildly different integrals. For example,\n\\begin{align*}\n\t\\int 1/x \\: dx              & = \\ln x  + c                          \\\\\n\t\\int 1/x^2 \\: dx            & = -1/x + c                            \\\\\n\t\\int 1/{(1+x^2)} \\: dx      & = \\tan^{-1} x + c                     \\\\\n\t\\int 1/(1 - x^2) \\: dx      & = 1/2 \\cdot \\ln ((1 + x)/(1 - x)) + c \\\\\n\t\\int 1/\\sqrt{1 - x^2} \\: dx & = \\sin^{-1} x + c\n\\end{align*}\nSo just by looking at a problem you cannot easily {\\it guess} what it's integral is going to look like.\n\n\\subsection{u-substitution}\nIn terms of indefinite integrals, u-substitution takes the form\n\\begin{align}\n\t\\label{eq:u-sub}\n\t\\int f\\left(g(x)\\right) g'(x)\\: dx = \\int f(u) \\: du + \\mathrm{constant}\n\\end{align}\nIdeally we want the integral on the right-hand side to be simpler than the one on the left-hand side.\nWe interpret this identity as having obtained the right-hand from the left-hand side by making the ``substitution''\n\\begin{align*}\n\tu  & = g(x)        \\\\\n\tdu & = g'(x) \\: dx\n\\end{align*}\nThis is just a {\\it mnemonic} and doesn't have a concrete mathematical meaning (at least not a simple one).\n\n\\begin{remark}\n\tAfter finding the integral $\\int f(u) \\: du$ you should ALWAYS plug back $u = g(x)$ to get your final answer in terms of the original variable.\n\\end{remark}\n\n\\begin{exercise}\n\tFind the following indefinite integrals using u-substitution(s).\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int x e^{x^2} \\: dx $\n\t\t\t\\item $\\int \\dfrac{1}{x \\ln x} \\: dx$\n\t\t\t\\item $\\int \\dfrac{e^{\\sqrt{x}}}{\\sqrt{x}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{x}{4x^2+5} \\: dx$\n\t\t\t      % \\item $\\int \\dfrac{x}{2x^2 - 3} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{x^2 + 2} \\: dx$\n\t\t\t\\item $\\int \\sec^2 x \\tan^5 x \\: dx$\n\t\t\t\\item $\\int \\tan x \\: dx$\n\t\t\t\\item $\\int \\dfrac{e^x}{e^{2x} + 2e^x + 1} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n% \\begin{exercise}\n%   Sometimes there's no obvious reason to use u-substitution. Instead, we use u-substitution in the hope that integral simplifies.\n%   \\begin{enumerate}\n% \\item $\\dfrac{e^x}{1 - e^{2x}}$\n%     \\item $\\dfrac{1 - e^x}{1 + e^{x}}$\n%     \\item $\\dfrac{e^{2x}}{\\sqrt{1 + e^x}}$\n%   \\end{enumerate}\n% \\end{exercise}\n\n\\subsection{Integration by Parts}\nIntegration by parts is {\\it sometimes} used to integrate products of functions (you should always try u-substitution first, unless the use of integration by parts is extremely obvious).\nThere are various ways of memorizing integration by parts, you should pick one that you find easy to remember.\n\nOne possible way to express it is as follows.\n\\begin{align}\n\t\\int fg  =  fG - \\int f' G  + \\mathrm{constant}\n\\end{align}\nwhere $G$ is any antiderivative of $g$.\nIn most problems, integration by parts is useful only if the function $f'G$ is simpler that the function $fg$.\n\n\\begin{example}\n\tFor computing $\\int x e^x \\: dx$ by parts, we have (at least) two possible choices:\n\t\\begin{enumerate}\n\t\t\\item $f = x \\mbox{ and } g = e^x$.\n\t\t      In this case,\n\t\t      \\begin{align*}\n\t\t\t      f' G = e^x\n\t\t      \\end{align*}\n\t\t\\item $f = e^x \\mbox{ and } g = x$.\n\t\t      In this case,\n\t\t      \\begin{align*}\n\t\t\t      f' G = e^x \\cdot x^2/2\n\t\t      \\end{align*}\n\t\t      In the first case, the function $f' G$ is simpler than $fg$ and hence this is the decomposition we should use for applying integration by parts.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{exercise}\n\tFind the following indefinite integrals using integration by parts.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int x e^x\\: dx$\n\t\t\t\\item $\\int x^2 e^{x}\\: dx$\n\t\t\t\\item $\\int x \\sin x\\: dx$\n\t\t\t\\item $\\int \\ln x \\: dx$ \\hint{ Use $f = \\ln x$ and $g = 1$.}\n\t\t\t\\item $\\int x \\ln x\\: dx$\n\t\t\t\\item $\\int x (\\ln x)^2\\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\\subsection{Trigonometric Integrals}\nThere are a LOT of tricks for computing integrals of functions involving trigonometric functions.\nWe'll only compute integrals of two kinds of functions:\n\\begin{align*}\n\t\\sin^ m x \\cos^n x \\mbox{ \\qquad and \\qquad } e^{ax} \\sin bx\n\\end{align*}\n\nLet $m$ and $n$ be non-negative integers.\nFor integrating $\\sin^ m x \\cos^n x$ if\n\t{\\bf either $m$ or $n$ is odd}\nthen we get the answer by a simple u-substitution. For example,\n\\begin{align*}\n\t\\sin^ {2k+1} x \\cdot \\cos^n x\n\t & = \\sin^ {2k} x \\cdot  \\sin x \\cdot  \\cos^n x                 \\\\\n\t & = \\left( \\sin^2 x \\right)^k \\cdot \\sin x \\cdot \\cos^n x      \\\\\n\t & = \\left( 1 - \\cos^2 x \\right)^k \\cdot \\sin x \\cdot  \\cos^n x\n\\end{align*}\nafter which we can integrate using the u-substitution $ u = \\cos x$.\n\\begin{exercise}\n\tCompute the following indefinite integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\sin^3 x \\cos^2 x \\: dx$\n\t\t\t\\item $\\int \\sin^2 x \\cos^5 x \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\nLet $m$ and $n$ be non-negative integers.\nFor integrating $\\sin^ m x \\cos^n x$ if\n\t{\\bf both $m$ and $n$ are even}\nthen we use the double angle formulae,\n\\begin{align*}\n\t\\sin^ {2k} x\n\t & = \\left(\\sin^{2} x \\right)^k\n\t &                                           &  &\n\t\\cos^ {2l} x\n\t & = \\left(\\cos^{2} x \\right)^l                   \\\\\n\t\\\\\n\t & = \\left(\\dfrac{1 - \\cos(2x)}{2} \\right)^k\n\t &                                           &  &\n\t & = \\left(\\dfrac{1 + \\cos(2x)}{2} \\right)^l\n\\end{align*}\n\\begin{exercise}\n\tCompute the following indefinite integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\sin^2 x \\: dx $\n\t\t\t\\item $\\int \\sin^2 x \\cos^2 x \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\nLet $a$, $b$ be real numbers.\nUsing the Euler's identity\n\\begin{align*}\n\te^{ibx} = \\cos bx + i \\sin bx\n\\end{align*}\nwe get\n\\begin{align*}\n\t\\int e^{ax} \\cos bx \\: dx & = \\mbox{real part of } \\int e^{ax} e^{ibx} \\: dx      \\\\\n\t\\int e^{ax} \\sin bx \\: dx & = \\mbox{imaginary part of } \\int e^{ax} e^{ibx} \\: dx\\end{align*}\n\\begin{exercise}\n\tCompute the following indefinite integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int e^{ax} \\cos bx \\: dx$\n\t\t\t\\item $\\int e^{ax} \\sin bx \\: dx $\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\n\n\\subsection{Trigonometric Substitutions}\n\nTrigonometric substitutions are extremely useful when {\\it eliminating radicals} (among other things) because of the identities\n\\begin{align}\n\t\\begin{split}\n\t\t\\label{eq:trig_identities}\n\t\t\\sin^2 x + \\cos^2 x &= 1 \\\\\n\t\t\\sec^2 x &= 1 + \\tan^2 x\n\t\\end{split}\n\\end{align}\n\n\\begin{example}\n\tIf there is a term\n\t\\begin{align*}\n\t\t\\sqrt{1 + x^2}\n\t\\end{align*}\n\tin our integral, then we can substitute $ x = \\tan u$ so that\n\t\\begin{align*}\n\t\t\\sqrt{1 + x^2}\n\t\t & = \\sqrt{1 + \\tan^2 u}                                         \\\\\n\t\t & = \\sec u              & \\mbox{ by \\eqref{eq:trig_identities}}\n\t\\end{align*}\n\\end{example}\n\nWe'll need a few preliminary computations.\n\\begin{exercise}\n\t\\begin{enumerate}\n\t\t\\item Compute $(\\sec x)'$.\n\t\t\\item Show using the fundamental theorem of calculus that\n\t\t      \\begin{align*}\n\t\t\t      \\int \\sec x \\: dx & = \\ln (\\sec x + \\tan x) + c  \\\\\n\t\t\t      \\int \\csc x \\: dx & = -\\ln (\\csc x + \\cot x) + c\n\t\t      \\end{align*}\n\t\t\\item {\\bf Optional: } Compute the integrals $\\int \\sec x \\: dx$ and $\\int \\csc x \\: dx$ directly (without using the fundamental theorem).\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tCompute the following integrals using trig substitutions.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\dfrac{1}{\\sqrt{1-x^2}}\\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{\\sqrt{1+x^2}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{\\sqrt{x^2-1}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{x\\sqrt{x^2-1}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{x\\sqrt{1-x^2}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{x\\sqrt{1+x^2}} \\: dx$\n\t\t\t\\item $\\int \\sqrt{1-x^2}\\: dx$\n\t\t\t\\item $\\int x^3 \\sqrt{1-x^2}\\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\begin{exercise}{{\\bf (Optional)}}\n\t\\begin{enumerate}\n\t\t\\item Compute the integral\n\t\t      \\begin{align*}\n\t\t\t      \\int \\sec^3 x \\: dx\n\t\t      \\end{align*}\n\t\t\\item Compute the integral\n\t\t      \\begin{align*}\n\t\t\t      \\int \\sqrt{1 + x^2} \\: dx\n\t\t      \\end{align*}\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\n\n\n\n\\subsection{Partial Fractions}\nPartial fractions is a technique used to compute integrals of the form\n\\begin{align*}\n\t\\int \\dfrac{P(x)}{Q(x)} \\: dx\n\\end{align*}\nwhere $P(x)$ and $Q(x)$ are polynomials.\nThe higher the degree of the denominator $Q(x)$ the harder it is to compute the integral.\\\\\n\n\\subsubsection*{Linear Polynomials}\nWhen the denominator $Q(x)$ is linear the integral can be computed easily using u-substitution.\n\\begin{exercise}\n\tCompute the following integrals\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{x^2+1}{x} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x^2 + 1}{x+1} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x}{2x-3} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x^2}{2x+2} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\subsubsection*{Quadratic with Repeated Roots}\nWhen the denominator is a quadratic $Q(x) = ax^2 + bx + c$ there are 3 different methods for finding the integral, depending on what the roots of $Q(x)$ are.\n\\begin{align*}\n\tx^2 + ax + b \\mbox{ has }\n\t\\begin{cases}\n\t\t\\mbox{ repeated roots } \\\\\n\t\t\\mbox{ complex roots }  \\\\\n\t\t\\mbox{ real non-repeated roots }\n\t\\end{cases}\n\\end{align*}\n\nThe first case of {\\bf repeated roots} is the easiest. In this case, our goal is to find a simple u-substitution to reduce the problem to\n\\begin{align*}\n\t\\int \\dfrac{R(u)}{u^2} \\: du\n\\end{align*}\nwhere $R(u)$ is some polynomial.\n\\begin{exercise}\n\tFor each of the following problems, verify that the denominator has repeated roots. Then\n\tcompute the integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{x}{4x^2 - 4x + 1} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x^2}{x^2 + 2x + 1} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\subsubsection*{Quadratic with Complex Roots}\nWhen the denominator $Q(x) = ax^2 + bx + c$ has complex roots our goal is to find a u-substitution to reduce the problem to the integrals\n\\begin{align*}\n\t\\int \\dfrac{1}{u^2 + 1} \\: du\n\t &  & \\mbox{ and }\n\t &  &\n\t\\int \\dfrac{u}{u^2 + 1} \\: du\n\\end{align*}\n\n\\begin{exercise}\n\tFor each of the following problems, verify that the denominator has complex roots. Then\n\tcompute the integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{1}{x^2 + 4} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{3}{x^2 + 2x + 2} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{3x}{x^2 + 2x + 2} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x}{4x^2 - 4x + 3} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\begin{exercise}If the degree of the numerator is $ \\ge 2$ then we first have to do a long division to simplify the numerator. Compute the following integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{x^2}{x^2 + 4} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{3x^3}{x^2 + 2x + 2} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\n\\subsubsection*{Quadratic with Real Non-repeated Roots}\nFinally, when the denominator $Q(x)$ has real non-repeated roots we need to use the method of partial fractions.\\\\\n\n\nIn this method we first need to find a factorization of $Q(x)$ as a product of linear terms, say $Q(x) = Q_1(x) \\cdot Q_2(x)$ where both $Q_1(x)$ and $Q_2(x)$ are linear. If the degree of the numerator $P(x)$ is $\\le 1$ then we can always write\n\\begin{align*}\n\t\\dfrac{P(x)}{Q(x)}\n\t & =\n\t\\dfrac{A}{Q_1(x)} + \\dfrac{B}{Q_2(x)}\n\\end{align*}\nfor some constants $A$ and $B$.\nThis is called the {\\bf partial fraction decomposition} of $\\frac{P(x)}{Q(x)}$. We find $A$ and $B$ by multiplying both sides by $Q(x)$ and comparing the coefficients on the left and right hand sides.\n\n\n\\begin{exercise}\n\tFor each of the following problems, verify that the denominator has real non-repeated roots. Then\n\tcompute the integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{1}{x^2 - 1} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{4x}{x^2 - 4} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{5}{x^2 - 2x} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{3 x}{x^2 + x - 2} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\\begin{exercise}As before if the degree of the numerator is $ \\ge 2$ then we first need to do long division to simplify the numerator. Compute the following integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{3 x^2}{x^2 + x - 2} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x^2 - 1}{x^2 - 4} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{4x^3 - 3x + 5}{x^2 - 2x} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\\subsubsection*{Degree $\\ge 3$}\nWhen degree of the denominator $Q(x)$ is $\\ge 3$, one can show the existence of a partial fraction decomposition using {\\it abstract algebra}.\nBut the details are much more complicated and hard to do by hand.\n\nInstead, feel free to use the internet to compute partial fraction decompositions. For example, go to \\url{http://www.wolframalpha.com} and input\n\\begin{verbatim}\n\tpartial fractions (x^2 - 2)/(x+1)^3\n\\end{verbatim}\nfor computing the partial fraction decomposition of $\\dfrac{x^2 - 2}{(x+1)^3}$.\n\nOnce you have the partial fraction decomposition you can use u-substitution to compute the integral.\n\n\\begin{exercise}\n\tCompute the following integrals using partial fraction decompositions.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $ \\int \\dfrac{x^2 - 2}{(x+1)^3} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{8}{3x^3 + 7x^2 + 4x} \\: dx$\n\t\t\t\\item $ \\int \\dfrac{x^3 + 8}{(x^2 - 1)(x - 2)} \\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n\n\n\n\n\n\n\n\n\n\n\n\\newpage\n\\subsection{Practice Problems}\nWe've learned several techniques for computing indefinite integrals. Of these\n\\begin{enumerate}\n\t\\item Basic u-substitution\n\t\\item Trigonometric substitutions (+ trig identities)\n\\end{enumerate}\nare the tricky ones as there are a lot of possible substitutions to choose from. The other three\n\\begin{enumerate}[resume]\n\t\\item Integration by Parts\n\t\\item Trigonometric integrals\n\t\\item Partial fractions\n\\end{enumerate}\nare much easier to use.\\\\\n\n The following problems will require you to use all of the above techniques. You should not expect to {\\it see} the solution right away, instead, systemically try different things until you reduce the problem to something that looks familiar.\n\n\\begin{exercise}\n\tCompute the following integrals.\n\t\\begin{multicols}{2}\n\t\t\\begin{enumerate}\n\t\t\t\\item $\\int \\dfrac{e^x}{(e^x - 1)(e^x - 3)}\\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{1 + e^x} \\: dx$\n\t\t\t\\item $\\int e^{\\sqrt{x}} \\: dx$\n\t\t\t\\item $\\int \\sin \\sqrt{x}\\: dx$\n\t\t\t\\item $\\int \\dfrac{\\sin^3 x}{\\cos^2 x} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1 - \\sin x}{\\cos^2 x}\\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{1 + \\sin x}\\: dx$\n\t\t\t\\item $\\int \\sqrt{1 + \\cos 2x}\\: dx$\n\t\t\t\\item $\\int \\sec^3 x \\tan x\\: dx$\n\t\t\t\\item $\\int x \\tan^{-1} x\\: dx$\n\t\t\t\\item $\\int x^2 \\tan^{-1} x\\: dx$\n\t\t\t\\item $\\int \\tan^{-1} {\\sqrt{x}}\\: dx$\n\t\t\t\\item $\\int \\dfrac{x}{\\sqrt{2 + 2x + x^2}} \\: dx$\n\t\t\t\\item $\\int \\dfrac{1}{\\sqrt{2x - x^2}}\\: dx$\n\t\t\t\\item $\\int \\ln(1 + x^2)\\: dx$\n\t\t\t\\item $\\int \\tan^{2} x\\: dx$\n\t\t\\end{enumerate}\n\t\\end{multicols}\n\\end{exercise}\n", "meta": {"hexsha": "c5add1e63fb7ff37a80a2beef79a96241318d839", "size": 15885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/09Computations.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/09Computations.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/09Computations.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": 34.6834061135, "max_line_length": 244, "alphanum_fraction": 0.635694051, "num_tokens": 5483, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.9019206791658465, "lm_q1q2_score": 0.764799656546869}}
{"text": "\\section{Linear Equations}\n\n  A linear equation over with unknowns is represented by $\\forall \\{a_1, \\ldots, a_n\\}, b \\in K,\\ \\ a_1 x_1 + a_2 x_2 + \\cdots + a_n x_n = b$.\n  A system of linear equations is a set of $L$'s, where $L$ is a linear equation as above.\n  Linear equations form a vector space that can be scaled.\n  \n  Given a system of linear equations with unknowns, a solution vector $u = (a_1,\\ldots, a_n)$ is something that simultaneously satisfies all of the linear equations.\n  \n  \\subsection{Definitions}\n  \n    \\begin{description}\n      \\item[Augmented Matrix]  Given a system of linear equations defined above, the augmented matrix is:\\\\\n      $M = \\left[\\begin{array}{cc|c}\n        a_{11} & \\ldots & b_1 \\\\\n        \\vdots & \\ddots & \\vdots \\\\\n        a_{m1} & \\ldots & b_m \n      \\end{array}\\right]$\n\n      \\item[Equivalent Systems of Linear Equations] Two system of linear equations are equivalent if they have the same system.\n      More precisely, $M_1$ and $M_2$ are equivalent when the rows of one are linear combinations of the rows of the other. \n      This means that systems of linear equations are equivalen when they are row equivalent.\n\n      \\item[Elementary Row Operation (ERO)] An ERO is an operation of either interchanging two rows, replacing a row with a multiple of itself, or replacing a row with the addition of itself and another row.\n\n      \\item[Row Echelon Form] Row echelon form consists of a matrix such that each leftmost nonzero entry of a row is to the right of the leftmost nonzero entry of each proceeding row, all zero rows are at the bottom of the matrix.\n\n      \\item[Row Canonical Form (Reduced Row Echelon) (Fully Reduced)] Row canonical form or full reduced matrix form is a matrix that satisfies row echelon form where every first entry in each row is 1.\n\n      \\item[Pivot] A pivot is the first nonzero entry in a row of a matrix in row ecehlon form.\n\n      \\item[Gaussian Elimination] A matrix can be converted into reduced row echelon form by performing row separations to put it into echelon form, dividing throughout so that every pivot is 1, and then using the 1 to zero out every space above pivots. \n\n    \\end{description}\n  \n  \\subsection{Theorems}\n  \n    \\subsubsection{Solution to Linear Equation}\n    \n      If $u$ is the solution to a linear equation where $L_1: x_1 + x_2 = 0; L_2 = x_1 - x_2 = 3; L_1 + L_2: 2x_1 = 3$ then $x_1 = 3/2, x_2 = -3/2$ by back substitution.\n      \n    \\subsubsection{Non-Invertible Matrix}\n\n      A matrix is not invertible if there exists some nonzero vector such that the matrix multiplied by the vector is 0.\n\n    \\subsubsection{Products of Invertible Matrices}\n\n      A product of matrices is invertible if and only if each of the individual matrices are invertible.\n\n    \\subsubsection{A matrix is row equivalent to a unique matrix in RCF}\n      \n      Wellp... the subsection name sums it up.\n      A proof is further below.\n\n  \\subsection{Proofs}\n\n    \\subsubsection{Every ERO has an inverse operation}\n\n      BLURRY PAGE, GO BACK!\n\n    \\subsubsection{A product of a set of matrices is invertible if and only if each of the set of matrices is invertible}\n\n      \\begin{align}\n        \\forall invertible[A], \\exists v \\neq 0\\ \\ s.t.\\ \\ Av = 0 \\\\\n        B = A^{-1} \\\\\n        B(Av) = B \\cdot [0] = [0] \\\\\n        (BA)v = (A^{-1}A)v = Iv = v \\implies v = 0\n      \\end{align}\n\n      In words, since this proof can be somewhat confusing (or at least it confused me): if A is invertible there must be some nonzero vector such that Av is 0.\n      Creating some matrix B that is the inverse of the vector A, should you multiply Av (0) by B it should be 0... or it could be v, depending on how you frame the problem.\n      So v must be 0 and thus the matrix must be invertible.\n\n      Another proof.\n      Suppose a set of matrices A are all invertible and their product is B.\n      If you repeatedly multiply both sides of this equality by a corresponding inverse of A to replace the set of matrices with the identity matrix, you will get $I = (A_n^{-1} \\ldots A_1^{-1})B$.\n      This can be reduced to $(A_n^{-1} \\ldots A_1^{-1}) = B^{-1}$ by multiplying both sides by the inverse of B.\n      Therefore, the inverse of B exists and the product of a set of invertible matrices is invertible.\n\n      We can use this to show each element is invertible.\n      If $A_1A_2\\ldots A_n$ is invertible so is $(A_1\\ldots A_{n-1})A_n$ by associativity.\n      The expression has two terms and the term in paranetheses is invertible and $A_n$ is invertible if we know the second term.\n\n    \\subsubsection{A matrix is row equivalent to a unique matrix in RCF}\n\n      We know that $M_1$ and $M_2$ represent equivalent linear systems if and only if these matrices are row equivalent, thus there is a sequence of EROs that can convert matrices to each other.\n      $M_2$ can be transformed into a matrix $N$ in RCF by some sequence of EROS.\n      $M_1$ can be transformed into a matrix $N$ in RCF by some sequence of EROS.\n      All three of these matrices are equivalent.", "meta": {"hexsha": "f91009f2249049a68fa512806765dfb06afa37a6", "size": 5055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/lecture_2.tex", "max_stars_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_stars_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2015-11-03T23:09:18.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-03T23:09:18.000Z", "max_issues_repo_path": "parts/lecture_2.tex", "max_issues_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_issues_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "parts/lecture_2.tex", "max_forks_repo_name": "sorinmuchi/math-223-mcgill-notes", "max_forks_repo_head_hexsha": "31f6cea755bc29fade21bdfe9ed7118aa6affcfa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 57.4431818182, "max_line_length": 254, "alphanum_fraction": 0.7004945598, "num_tokens": 1353, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8519528057272544, "lm_q1q2_score": 0.7647940274625896}}
{"text": "\n\\subsection{Euclidian division}\n\nEuclidian division is the theory for any pair of natural numbers, we can divide one by the other and have a remainder less than the divisor. Formally:\n\\(\\forall a \\in \\mathbb{N} ,\\forall b \\in \\mathbb{N}^+ ,\\exists q \\in \\mathbb{N},\\exists r\\in \\mathbb{N} [(a=bq+r)\\land (0\\le r < b)]\\)\n\nWhere \\(\\mathbb{N}^+\\) refers to natural numbers excluding \\(0\\).\n\nThat is, every natural number \\(a\\) is a multiple \\(q\\) of any other natural number \\(b\\), plus another natural number \\(r\\) less than the other natural number \\(b\\).\n\nThese are unique. For each jump in \\(q\\), \\(r\\) falls by \\(b\\). As the range of \\(r\\) is \\(b\\) there is only one solution.\n\n\\(17=2.8+1\\)\n\n\\(9=3.3+0\\)\n\n", "meta": {"hexsha": "b21f6f58b360543367b0b1ec0ec00eb3c8ea6d7e", "size": 708, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmeticFundamental/01-01-euclidian.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/arithmeticFundamental/01-01-euclidian.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/arithmeticFundamental/01-01-euclidian.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": 41.6470588235, "max_line_length": 166, "alphanum_fraction": 0.6624293785, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8152324826183822, "lm_q1q2_score": 0.7647891733933612}}
{"text": "%Seccion \"Resumen\"\r\n%\r\n\\chapter{Combined index notation for finite element analysis}\r\n\r\n\\section{Combined index notation for finite element analysis}\r\nIn the formulation of finite element methods it is customary to start from expressions written in index notations like:\r\n\r\n\r\n\\[ \\delta W = \\intL_V \\sigma_{ij} \\delta u_{i,j} \\dd{V} \\]\r\n\r\n\r\nand then proceed to introduce discretization or approximations via interpolation theory. In this case it is useful to combine index notation to describe the physical tensorial fields and at the same time the superposition implicit in interpolation schemes. In this appendix we clarify the use of such combined index notation.\r\n\r\n\\subsection{Index notation of Cartesian tensor fields}\r\n\r\nIn index notation vector and tensor fields are represented by a letter defining \r\nthe name of the field and a set of different subscripts (or index). The \r\nnumber of different indices associated to the letter indicates whether the \r\nfield is a vector (1 index), a second order tensor (2 indices), a third order \r\ntensor (3 indices) as in:\r\n\\[u_i , \\sigma_{ij} , C_{ijk}\\]\r\n\r\nand further clarified next.\r\n \r\nConsider a vector $\\overset\\rightharpoonup u$ represented in a Cartesian reference system in terms of its scalar components $u_x , u_y , u_z$. The following representations of the vector are equivalent:\r\n\r\n\\[u_i\\leftrightarrow\\begin{bmatrix}u_x&u_y&u_z\\end{bmatrix}\\leftrightarrow\\overset\\rightharpoonup u=u_x\\widehat i+u_y\\widehat j+u_z\\widehat k.\\]\r\n\r\nIn the first case, the vector is denoted by the letter $u$ and by the subscript $i$ which represents in condensed form the scalar components $\\begin{bmatrix}u_x&u_y&u_z\\end{bmatrix}$ of the vector.\r\n\r\nSimilarly, consider a second order tensor $\\overset{\\rightharpoonup(2)}\\sigma$ represented in a cartesian reference system in terms of its scalar components $\\sigma_{xx} , \\sigma_{xy}, \\sigma_{xz} , \\sigma_{yx}, \\sigma_{yy}, \\sigma_{yz}, \\sigma_{zx}, \\sigma_{zy}, \\sigma_{zz}$. The following representations of the tensor are equivalent:\r\n\r\n\\[\\sigma_{ij}\\leftrightarrow\\begin{bmatrix}\\sigma_{xx}&\\sigma_{xx}&\\sigma_{xx}\\\\\\sigma_{xx}&\\sigma_{xx}&\\sigma_{xx}\\\\\\sigma_{xx}&\\sigma_{xx}&\\sigma_{xx}\\end{bmatrix}\\leftrightarrow\\overset{\\rightharpoonup(2)}\\sigma.\\]\r\n\r\nNote that each free or different subscript associated to a letter is a condensed representation of normal scalar components along a basis $\\widehat i-\\widehat j-\\widehat k$. Accordingly, in the case of the second order tensor the subscript $i$ represents variation through $x-y-z$ and subscript $j$ represents variation through $x-y-z.$\r\n\r\n\\subsection{The summation convention}\r\nIn the context of indicial notation subscripts which appear repeated (forming pairs) are used to represent summation. The most simple example is the representation of the dot product between two vectors which can be represented in the following alternative forms:\r\n\r\n\\[\\overrightarrow u\\cdot\\overrightarrow w\\leftrightarrow u_xw_x+u_yw_y+u_zw_z\\leftrightarrow\\sum_{i=1}^3u_iw_i\\leftrightarrow u_iw_i.\\]\r\n\r\nAccordingly repeated indices represent summation over the range of variation of the index.\r\n\r\n\\subsection{Indicial notation in interpolation}\r\nFrom interpolation theory we know that a function $f(x)$ can be approximated in terms of $n$ known values of the solution $\\begin{bmatrix}f^1&f^2&...f^n\\end{bmatrix}$ using a superposition like\r\n\r\n\\[f(x)=L^1(x)f^1+L^2(x)f^2+...+L^n(x)f^n\\]\r\n\r\nand where the terms $L^k s$ are $n$ interpolation functions of order $n-1$. This approximated function can also be represented in terms of indicial notation where we now use capitalized superscripts to refer to the components of the interpolation set as follows:\r\n\r\n\\[f(x)=L^Q(x)f^Q.\\]\r\n\r\n\r\nIn the expression above the approximated function represents a scalar quantity varying over a one-dimensional domain with independent variable $x.$. In the case of approximation via interpolation theory of vector or tensor valued functions we will have subscripts indicating the scalar components of the vector or tensor field and superscripts representing the interpolation polynomials. Using explicit notation a vector function $u_i (x,y,z)$ varying over a three-dimensional space with independent variables $x,y,z$ would be represented like:\r\n\r\n\r\n\\[\r\n\\begin{array}{l}u_x(x,y,z)=N^1(x,y,z)u_x^1+N^2(x,y,z)u_x^2+...+N^n(x,y,z)u_x^n\\\\u_y(x,y,z)=N^1(x,y,z)u_y^1+N^2(x,y,z)u_y^2+...+N^n(x,y,z)u_y^n\\\\u_z(x,y,z)=N^1(x,y,z)u_z^1+N^2(x,y,z)u_z^2+...+N^n(x,y,z)u_z^n.\\end{array}\r\n\\]\r\n\r\nIn this representation it has been assumed that each component $u_x$, $u_y$ and $u_z$ has been approximated using the same interpolation space. In the generalization of the indicial notation to the interpolation of the vector valued function we will associate the subscript, representing the scalar components of the field to the interpolation polynomials. Thus the above expression would be written like:\r\n\r\n\\[u_i\\;(x,y,z)\\;=\\;N_i^Q(x,y,z)u^Q\\]\r\n\r\nor \r\n\r\n\\[u_i(\\overrightarrow x)\\;=N_i^Q(\\overrightarrow x)u^Q\\]\r\n\r\nafter considering $\\overrightarrow x \\equiv x,y,z.$\r\n\r\n\r\nThe subscript $i$, representing the physical components of the vector field $u_i$ has been carried out as a subscript to the shape function $N^Q$ for the nodal point $Q$, while the term $u^Q$ refers to the scalar components of the field $u_i$ at the nodal point $Q$. The main advantage in this notation is the possibility of conducting further operations, as required in the derivation of very general finite element algorithms, while combining physical and discrete information.\r\n\r\n\\paragraph*{Example}\r\n\r\nIn the expression\r\n\r\n\\[ \\delta W = \\intL_V \\sigma_{ij} \\delta u_{i,j} \\dd{V} \\]\r\n\r\nassume that the primary variable is the displacement field $u_i$ in such a way that at the nodal point $Q$ the displacement vector $u^Q$ is known. Write the interpolated version of $\\delta W.$\r\n\r\nFirst, let us write the interpolated approximation to the displacement field $\\delta u_i$ carrying the subscript to the shape functions:\r\n\r\n\\[\\delta u_i(\\overrightarrow x)\\;=N_i^Q(\\overrightarrow x)\\delta u^Q.\\]\r\n\r\nTo write the interpolated version of $\\delta u_{i,j}$ we note that in the expression above the spatial variation of the field has been assumed by the shape function so we just extend the derivative with respect to $x_j$ to these functions to obtain the following interpolated version of the second order tensor field $\\delta u_{i,j}$:\r\n\r\n\\[\\delta u_{i,j}(\\overrightarrow x)\\;=N_{i,j}^Q(\\overrightarrow x)\\delta u^Q.\\]\r\n\r\nMaking\r\n\r\n\\[B_{ij}^Q(\\overrightarrow x)\\equiv N_{i,j}^Q(\\overrightarrow x) \\]\r\n\r\nthe above can be written like:\r\n\r\n\\begin{equation} \r\n\\delta u_{i,j}(\\overrightarrow x)\\;=B_{ij}^Q(\\overrightarrow x)\\delta u^Q.\r\n\\label{B_strain}\r\n\\end{equation}\r\n\r\nIn \\cref{B_strain}, the term $B_{ij}^Q(\\overrightarrow x)$ is an interpolation function (which is indicated by the superscript $Q$) associated to a second order tensor (which is indicated by the subscripts $ij$). It must be recognized that $B_{ij}^Q(\\overrightarrow x)$ are not independent shape functions but just derivatives of the primary interpolation polynomials $N^Q (x,y)$.\r\n\r\nConsider now the stress-strain relationship in theory of elasticity relating the stress tensor $\\sigma_{ij}$ to the strain tensor $\\epsilon_{ij}$ through the elastic constitutive tensor $C_{ijkl}$as:\r\n\r\n\\[\\sigma_{ij} = C_{ijkl} \\epsilon_{kl}.\\]\r\n\r\nIn the above the strain tensor $\\epsilon_{ij}$ is given by a combination of space derivatives of the displacement field $u_i$ like\r\n\r\n\\[ \\varepsilon_{ij}=\\frac12(u_{i,j}+u_{j,i}) \\]\r\n\r\nwhich can be written like\r\n\r\n\r\n\\[ \\epsilon_{ij}(\\overrightarrow x)\\;= \\frac12 [B_{ij}^Q(\\overrightarrow x) + B_{ji}^Q(\\overrightarrow x) ]   u^Q \\equiv H(\\overrightarrow x)_{ij}^Q u^Q \\]\r\n\r\nUsing the above set of results in $\\delta W $ gives:\r\n\r\n\\begin{equation} \r\n\\delta W=\\delta u^Q\\int_VH_{ij}^QC_{ijkl}H_{kl}^P\\operatorname dVu^P\r\n\\label{discrete}\r\n\\end{equation}\r\n\r\nwhich is the final discrete version of $\\delta W $.\r\n\r\n\\begin{tcolorbox}\r\nIn the indicial representation of a tensor quantity an index which does not repeat itself in the expression is termed a {\\bf free index} and the number of non-repeated free indices appearing in the expression gives the expression order. By contrast, repeated indices appearing in the expression are termed {\\bf dummy indices} and they imply summation.\r\n\\end{tcolorbox}\r\n\r\n\\paragraph*{Problem: Discretization of the principle of virtual displacements from theory of Elasticity}\r\n\r\nThe principle of virtual displacements in the linearized theory of elasticity is given by:\r\n\r\n\r\n\\begin{equation} \r\n\\intL_V \\sigma_{ij} \\delta u_{i,j} \\dd{V} - \\intL_V f_i \\delta u_i \\dd{V} - \\intL_{S_t} t_i^n \\delta u_i \\dd{S} = 0.\r\n\\label{pvw_2}\r\n\\end{equation}\r\n\r\nand where $u_i$ is the displacement field; $\\epsilon_{ij}$ is the strain field and $\\sigma_{ij}$ is the stress field satisfying the following relations\r\n\r\n\\[ \\varepsilon_{ij}=\\frac12(u_{i,j}+u_{j,i}) \\]\r\n\r\nand\r\n\r\n\\[\\sigma_{ij} = C_{ijkl} \\epsilon_{kl}\\]\r\n\r\nwhere $C_{ijkl}$ is a fourth-order tensor whose terms are material constants. Also $f_i$ and $t_i^n$ are the body forces and the surface traction vectors.\r\n\r\nAssuming that in a finite element method the displacement field $u_i$ is approximated via interpolation like:\r\n\r\n\\[ u_i(\\overrightarrow x)\\;=N_i^Q(\\overrightarrow x)u^Q.\\]\r\n\r\n\\begin{itemize}\r\n\\item Write the discrete version of \\cref{pvw_2}\r\n\\item Write the term $K^{QP} = \\int_VH_{ij}^QC_{ijkl}H_{kl}^P\\operatorname dV$ in matrix form and implement it in a python script.\r\n\\end{itemize}\r\n\r\n\\newpage\r\n\r\n\\chapter{Generalized boundary value problems}\r\n%\\section{Generalized boundary value problems from a balance law}\r\nIn this section we use as problem to be solved via the finite element algorithm the case of general initial boundary value problem (I-BVP). In the first part of this appendix we will introduce the differential formulation given in terms of a set of governing equations and properly specified boundary conditions. The resulting equations are obtained after using a generalized balance law. Following this classical and well known approach we formally re-state these equations in the so-called strong form. Subsequently we re-write and prove an equivalent form of the balance law in the form of an integral representation highly friendly for a numerical solution. Since in the integral description of the problem the order of the derivatives in the field functions decreases by one, the resulting statement is called a weak formulation. \r\n\r\n\\section{Governing equations}\r\nLet $\\dd{S}$ be a differential surface element, $\\dd{V}$ a differential volume element, $u(\\vb{x},t)$ a scalar (or vector) function of space and time. The flux or rate of flow of the quantity $u(\\vb x, t)$ through $\\dd{S}$ at time $t$ is defined like\r\n\\[p(\\vb x)\\grad u \\cdot \\hat n \\dd{S} \\enspace ,\\]\r\nwhere $p(\\vb x)$ is a positive function, assumed known and time independent. Similarly, the time rate of change of $u(\\vb x, t)$ in an element $\\dd{V}$ is given by\r\n\\[\\rho (\\vb x)\\pdv{u}{t} \\dd{V} \\enspace ,\\]\r\nwhere once again $\\rho (\\vb x)$ is a known, given, time independent positive function. Additional effects occurring in the element $\\dd{V}$ at the time $t$ can be expressed like\r\n\\[H(\\vb x, t)\\dd{V} \\equiv  - q(\\vb x)u(\\vb x, t) + \\hat F(\\vb x,t)\\]\r\nwhere $\\hat F(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t)$. In the above the term $q u$ represents internal effects due to changes proportional to $u$ while $\\hat F(\\vb x, t)$ are other external influences in the medium.\r\n\r\nBalancing the internal and external changes yields\r\n\\[\\int\\limits_V \\rho (\\vb x)\\pdv{u}{t}\\dd{V} = \\int\\limits_S p(\\vb x)\\vb \\grad u \\cdot \\hat n\\dd{S}  + \\int\\limits_V H(\\vb x, t)\\dd{V} \\enspace ,\\]\r\nor equivalently\r\n\\[\\int\\limits_V \\rho (\\vb x)\\pdv{u}{t}\\dd{V} = \\int\\limits_S p(\\vb x)\\vb \\grad u \\cdot \\hat n\\dd{S}   - \\int\\limits_V q(\\vb x)u(\\vb x, t)\\dd{V}  + \\int\\limits_V \\rho (\\vb x)F(\\vb x, t)\\dd{V} \\enspace .\\]\r\n\r\nUsing the divergence theorem as\r\n\\[\\int\\limits_S p(\\vb x) \\grad u \\cdot \\hat n \\dd{S}  = \\int\\limits_V \\vb \\div  (p\\vb \\grad u)\\dd{V}\\]\r\nyields after substitution\r\n\\[\\int\\limits_V \\left[\\rho (\\vb x)\\pdv{u}{t} - \\div (p(\\vb x)\\grad u) + q(\\vb x)u(\\vb x, t) - \\rho (\\vb x)F(\\vb x, t)\\right]\\dd{V}  = 0\\]\r\nAssuming a continuous integrand, the arbitrariness of $V$ implies\r\n\\[\\rho (\\vb x)\\pdv{u}{t} - \\div(p(\\vb x)\\grad u) + q(\\vb x)u(\\vb x, t) - \\rho (\\vb x)F(\\vb x, t) = 0\\]\r\n\r\nLetting\r\n\\[\\mathcal{L} \\equiv  - \\div p(\\vb x)\\grad + q(\\vb x)\\]\r\nallows us to write the generalized set of partial differential equations like:\r\n\r\n\\begin{equation}\r\n\\rho(\\vb x) \\pdv{u(\\vb x, t)}{t} + \\mathcal{L}u(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t) \\enspace .\r\n\\label{eq:GenPDE}\r\n\\end{equation}\r\n\r\nThese are categorized as:\r\n\\begin{itemize}\r\n    \\item Hyperbolic;\r\n    \\[\\rho(\\vb x) \\pdv[2]{u(\\vb x, t)}{t} + \\mathcal{L}u(\\vb x,t) = 0\\]\r\n\r\n    \\item Parabolic;\r\n    \\[\\rho(\\vb x) \\pdv{u(\\vb x,t)}{t} + \\mathcal{L}u(\\vb x, t) = 0\\]\r\n\r\n    \\item Elliptic\r\n    \\[\\mathcal{L}u(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t) \\enspace .\\]\r\n\\end{itemize}\r\n\r\nIt is convenient to show that $\\mathcal{L}$ satisfies the \\emph{symmetry} condition\r\n\\[\\int\\limits_V \\mathcal{L}(u)v\\dd{V} =  \\int\\limits_V \\mathcal{L}(v)u \\dd{V}\\]\r\nand that the operator is positive definite, that is\r\n\\[\\int\\limits_V \\mathcal{L}(u)u\\dd{V}  > 0, \\quad \\forall u \\enspace .\\]\r\n\r\n\\subsection{Strong form}\r\nThe strong form for the generalized boundary value problem formulated above can now be explicitly written as follows.\r\n\r\nGiven $\\rho(\\vb x)$, $q(\\vb x)$, $p(\\vb x)$, $F(\\vb x, t)$ and $\\bar u (\\vb x , t)$ find $u(\\vb x , t):V \\to \\mathbb{R}$ such:\r\n\\[\\rho(\\vb x) \\pdv{u}{t} - \\div \\left[p(\\vb x) \\grad u\\right] + q(\\vb x) u(\\vb x, t) - \\rho(\\vb x) F(\\vb x, t) = 0 \\quad \\forall \\vb x \\in V \\]\r\nand\r\n\\begin{align*}\r\n    &u = \\bar u \\quad \\forall \\vb x \\in S_u\\\\\r\n    &p(\\vb x)u_{,i} \\hat n_i= B(\\vb x,t)\\quad \\forall \\vb x \\in  S_t \\enspace .\r\n\\end{align*}\r\n\r\n\r\nIn the FEM we will look for approximate solutions to $u$ subject to the following conditions:\r\n\\[u = \\bar u \\quad \\forall \\vb x \\in S_u \\quad \\text{(Essential boundary conditions)}\\] \r\nand\r\n\\[\\int\\limits_S \\left(\\pdv{u}{x_j}\\right)^2 \\dd{S} < \\infty \\enspace ,\\]\r\nwhich corresponds to the functions being square integrable. We will denote this space by $\\mathbb{H}$ .\r\n\r\nThe space of functions satisfying the above two conditions will be denoted by $\\zeta$ and termed the space of trial functions, formally defined like:\r\n\\[\\zeta  = \\left\\{ u \\mid u \\in \\mathbb{H},u = \\bar u \\quad \\forall\\vb x  \\in S_u \\right\\}\\]\r\n\r\nOn the other hand, to validate (or test) the correctness of the approximated or proposed trial functions $u$ it is also necessary to introduce test functions $w$ which are arbitrary except that they satisfy the following conditions:\r\n\\[w = 0\\quad \\forall \\vb x \\in S_u\\] \r\nand\r\n\\[\\int\\limits_S \\left(\\pdv{w}{x_j}\\right)^2 \\dd{S} < \\infty \\enspace ,\\]\r\nwhich corresponds to the functions being square integrable. The space of functions satisfying the above two conditions will be denoted by $\\pounds$ and termed the space of test functions, formally defined like:\r\n\\[\\pounds  = \\left\\{w \\mid w \\in \\mathbb{H},w = 0 \\quad \\forall \\vb x \\in S_u\\right\\}\\]\r\n\r\n\\subsection{Weak form}\r\nGiven $\\rho(\\vb x)$, $q(\\vb x)$, $p(\\vb x)$, $F(\\vb x, t)$ and $\\bar u (\\vb x , t)$ find $u(\\vb x , t):V \\to \\mathbb{R}$ and $\\forall w \\in \\pounds$ such:\r\n\\begin{align*}\r\n\\int\\limits_V p(\\vb x) u_{,i}\\, w_{,i}\\dd{V} - \\int\\limits_{S_t} B(\\vb x, t)w \\dd{S}  + \\int\\limits_V q(\\vb x)u(\\vb x, t)w\\dd{V}  &+ \\int\\limits_V \\rho(\\vb x)\\pdv{u}{t}w \\dd{V} \\\\& - \\int\\limits_V \\rho(\\vb x) F(\\vb x, t)w\\dd{V} = 0\r\n\\end{align*}\r\nand\r\n\\[u = \\bar u\\quad \\forall\\vb x \\in S_u \\enspace .\\]\r\n\r\n\\subsection{Equivalence between the strong and weak forms}\r\n\\begin{multline}\r\n    -\\int\\limits_V [p(\\vb x)u_{,i}]_{,i}w \\dd{V} + \\int\\limits_{S_t} [p(\\vb x)u_{,i}] \\hat n_i w\\dd{S} - \\int\\limits_{S_t} B(\\vb x, t)w\\dd{S}\\\\\r\n    + \\int\\limits_V q(\\vb x)u(\\vb x, t)w \\dd{V}  + \\int\\limits_V \\rho(\\vec x)\\pdv{u}{t}w\\dd{V} - \\int\\limits_V \\rho(\\vb x)F(\\vb x, t)w\\dd{V} = 0 \r\n\\end{multline}\r\n\r\nGrouping together common terms yields\r\n\\begin{align*}\r\n&\\int\\limits_V \\left\\{\\rho(\\vb x)\\pdv{u}{t} - [p(\\vb x)u_{,i}]_{,i} + q(\\vb x)u(\\vb x, t) - \\rho(\\vb x)F(\\vb x, t)\\right\\} w\\dd{V}\\\\\r\n&+ \\int \\limits_{S_t} \\left\\{[p(\\vb x)u_{,i}]\\hat n_i - B(\\vb x, t) \\right\\} w\\dd{S} = 0\r\n\\end{align*}\r\nfrom which\r\n\\[\\rho(\\vb x)\\pdv{u}{t} - [p(\\vb x)u_{,i}]_{,i} + q(\\vb x)u(\\vb x, t) - \\rho(\\vb x)F(\\vb x, t) = 0\\]\r\nand\r\n\\[p(\\vb x)u_{,i}\\hat n_i = B(\\vb x, t)  \\quad\\forall \\vb x \\in S_t \\enspace .\\]\r\n\r\n\\section{Weighted residual methods}\r\nThis section introduces the concept of residual or difference from zero in a differential equation once its solution is approximated. For that purpose we will take as prototype equation the one obtained as our general model of BVP (see \\cref{eq:GenPDE}) and recalled here for completeness\r\n\\begin{equation}\r\n\\rho(\\vb x) \\pdv{u(\\vb x, t)}{t} + \\mathcal{L}u(\\vb x, t) = \\rho (\\vb x)F(\\vb x, t) \\enspace .\r\n\\label{eq:GenPDE2}\r\n\\end{equation}\r\n\r\nWe will assume that the actual solution to the generalized BVP given by \\cref{eq:GenPDE2} is approximated by $\\tilde u(\\vb{x})$ through a superposition like\r\n\\begin{equation}\r\n\\tilde u (\\vb{x}) = {N^I}(\\vb{x}){u^I}\r\n\\label{basicsuper}\r\n\\end{equation}\r\nwhere ${N^I}(\\vb{x})$ are interpolating functions and $I$ denotes a superposition index  varying like $I=1,2,...,K$ with $K$ being the number of points where the solution is known. In what follows we will use $u(\\vb{x})$ instead of $\\tilde u (\\vb{x})$ but will keep in mind that we are actually using the approximation given by \\cref{basicsuper}. Similarly, in order to keep the discussion simple for the time being we will drop the time effects reducing the generalized PDE to the simple form:\r\n\\begin{equation}\r\n\\mathcal{L}u(\\vb x) = \\rho (\\vb x)F(\\vb x) \\enspace .\r\n\\label{eq:GenPDE3}\r\n\\end{equation}\r\n\r\nNow, since we are using the approximation given by \\cref{basicsuper} this equation is not strictly satisifed but instead we will have the following ``unbalanced\" condition\r\n\\[\\mathcal{L}u(\\vb{x}) - \\rho (\\vb{x})F(\\vb{x}) \\equiv R \\ne 0\\]\r\nwhere the term $R$ corresponds to a residual error which is to be distributed throughout the solution domain. The so-called weighted residual methods differ in the form in which they distribute the residual between the different $K$ points conforming the computational domain.\r\n\r\nUsing \\cref{basicsuper} in \\cref{eq:GenPDE2} and the linearity in the differential operator yields\r\n\\[R = \\mathcal{L}({N^P}){u^P} - \\rho F\\, .\\]\r\n\r\nWe can see that the residual $R$ is a function defined over the domain of interest. The residual would be exactly zero for the solution of the differential equation, but it will not be zero in general. Thus, we want to make the function $R$ as close to zero as possible. To make $R$ as small as possible we need a function (a functional) where we can compare different approximation functions. After getting this functional we can minimize its value. For this minimization we could use the norm of the function, another option is to compute a weighted \\emph{average} of the function over the domain. This is what we call a weighted residual\r\n\\[\\Pi[u, w] = \\int\\limits_V w R(u) \\dd{V}\\, ,\\]\r\nand we want to minimize it by making\r\n\\[\\var{\\Pi}[u, w] = 0\\, ,\\]\r\n\r\nIn what follows we will consider different strategies to distribute or weight the residual $R$ over the computational domain.\r\n\r\n\\subsection{Galerkin method}\r\nIn the Galerkin scheme the interpolation functions are used also as weighting functions leading to:\r\n\\[\\int\\limits_V N^Q R\\dd{V} = 0 \\]\r\nor explicitly\r\n\\begin{equation}\r\n  \\int\\limits_V N^Q \\mathcal{L} (N^P)\\dd{V} u^P = \\int\\limits_V N^Q\\rho F\\dd{V}\\, .\r\n  \\label{eq:Galer}\r\n\\end{equation}\r\n\r\nImposing \\cref{eq:Galer} in the $K$ points conforming the computational domain or equivalently ranging $Q$ from $1$ to $K$ leads to the following system of algebraic equation\r\n\\begin{equation}\r\n{K^{QP}}{U^P} = {f^Q}\r\n\\label{eq:DGaler}\r\n\\end{equation}\r\n\r\nwhere $U^P$ is a vector that stores the point values of the function $u$ along te $K$ points of the computational domain, while $f^Q$ stores the corresponding point excitations.\r\n\r\n\\subsection{Least squares method}\r\nIn this method the integral of the square of the residual is minimized with respect to the $K$ point parameters or nodal values of the function. Accordingly,\r\n\\begin{align*}\r\n  &\\pdv{u^I}\\int\\limits_V R^2 \\dd{V} = 0\\\\\r\n  &\\int\\limits_V R \\pdv{R}{u^I} \\dd{V} = 0\\, ,\r\n\\end{align*}\r\n\r\nThe least squares method is a special case of the weighted residual method for the weight functions\r\n\\[w^I = \\pdv{R}{u^I}\\, .\\]\r\n\r\nExpanding the residual, and considering the operator $\\mathcal{L}$ as linear, we obtain\r\n\\begin{align*}\r\n  &\\pdv{u^I}\\int\\limits_V [\\mathcal{L}(N^P u^P) - \\rho F]^2 \\dd{V} = 0\\\\\r\n  &\\int\\limits_V [\\mathcal{L} N^P u^P - \\rho F] \\mathcal{L}(N^I) \\dd{V} = 0\\\\\r\n &\\int\\limits_V \\mathcal{L}(N^I) \\mathcal{L}(N^P) \\dd{V} u^P - \\rho \\int\\limits_V \\mathcal{L}(N^I) F \\dd{V} = 0\r\n\\end{align*}\r\nwhich can be written like\r\n\\begin{equation}\r\n  K^{IP} U^P = f^I\r\n  \\label{eq:Dsquares}\r\n\\end{equation}\r\n\r\n\\subsection{Collocation method}\r\nIn the collocation method the coefficients of the approximation are determined by forcing the residual to be exactly zero at $K$ points over the computational domain, i.e.,\r\n\\[\\mathcal{L}(N^I) u^I - \\rho F = 0\\, ,\\]\r\nor\r\n\\[\\mathcal{L}[N^I(x^J)] u^I - \\rho F(x^J) = 0\\, ,\\]\r\nwhere $J$ ranges between $1$ and $K$. This equation can be rewritten as a weighted-residual if we consider the residual to be $\\delta(x - x^I)$, the Dirac delta function over the selected points\r\n\r\nThe resulting system of algebraic equation can be written as\r\n\\begin{equation}\r\nK^{IP} U^P = f^I\\, .\r\n\\label{eq:Colo}\r\n\\end{equation}\r\n\r\n\\subsection{Subdomain method}\r\nThe zero value of the residual is imposed upon $K$ subdomains\r\n\\[\\int\\limits_{V^I} \\mathcal{L}(N^P)\\dd{V^I} u^P  - \\rho \\int\\limits_{V^I}  F\\dd{V^I}  = 0 \\qquad I=1,\\cdots,K\\, .\\]\r\n\r\nFor instance, for the $N$-th element it follows that\r\n\\[\\int\\limits_{V^N} \\mathcal{L}(N^P)\\dd{V^N} u^P  - \\rho \\int\\limits_{V^N} F\\dd{V^N}  = 0 \\qquad P=1,\\cdots,K\\, .\\]\r\n\r\nApplying the equation over the $K$ subdomains leads to the discrete system;\r\n\\begin{equation}\r\nK^{IP} U^P = f^I \\quad \\quad I=1,\\cdots,K\\, .\r\n\\label{eq:Subdomain}\r\n\\end{equation}\r\n\r\n\\subsection{Ritz method}\r\nIt operates directly upon the variational statement of the problem. For a given functional\r\n\\[\\Pi  = \\Pi (N^Q u^Q)\\]\r\nthe variational equation reads\r\n\\[\\var{\\Pi}  \\equiv \\pdv{\\Pi}{u^Q} \\var{u^Q} = 0\\]\r\nfrom which\r\n\\[\\pdv{\\Pi}{u^Q} = 0\\, .\\]\r\n\r\n\\paragraph*{Example: The generalized parabolic equation}\r\nLet us consider the case of the generalized parabolic equation and its discretization following the Galerkin method\r\n\\[\\rho(\\vb x) \\pdv{u(\\vb x,t)}{t} + \\mathcal{L}u(\\vb x, t) = 0\\]\r\nwhich can also be written using index notation\r\n\\[\\pdv{x_i}\\left[p(x)\\pdv{u}{x_i} \\right] + q(x)u + \\rho \\pdv{u}{t} = \\rho F\\, \r\n,.\\]\r\n\r\nAssuming that $p(x)=1$ yields\r\n\\begin{align*}\r\n  &-\\int\\limits_V N^P N_{,ii}^Q \\dd{V} u^Q + \\int\\limits_V q N^P N^Q\\dd{V} u^Q  + \\rho \\int\\limits_V N^P N^Q \\dd{V} v^Q\\\\\r\n     &- \\rho \\int\\limits_V N^P F \\dd{V} = 0\\\\\r\n  &\\int\\limits_V N_{,i}^P N_{,i}^Q \\dd{V} u^Q - \\int\\limits_S N^P N_{,i}^Q \\hat{n}_i \\dd{S} u^Q + \\int\\limits_V q N^P N^Q \\dd{V} u^Q\\\\\r\n    &+ \\rho \\int\\limits_V N^P N^Q \\dd{V} v^Q  - \\rho \\int\\limits_V N^P F \\dd{V} = 0 \\\\\r\n  &\\int\\limits_V \\left(N_{,i}^P N_{,i}^Q + q N^PN^Q \\right)\\dd{V} u^Q  + \\rho \\int\\limits_V N^P N^Q \\dd{V} V^Q  =\\\\\r\n      &\\int\\limits_S N^P N_{,i}^Q \\hat{n}_i \\dd{S} u^Q + \\rho \\int\\limits_V N^P F \\dd{V}\r\n\\end{align*}\r\nwhich can be written in discrete form as\r\n\\[K^{PQ} U^Q + C^{PQ} V^Q = f^p\\, .\\]\r\n\r\n\\paragraph*{Example: The wave equation.}\r\nIn this case the differential equation reads\r\n\\[\\div \\left[ \\frac{1}{\\rho} \\grad p(\\vb{x})\\right] - \\pdv{t} \\left(\\frac{1}{\\lambda} \\pdv{\\rho}{t}\\right) - q(\\vb{x}) = 0\\]\r\nwhere we recognize that\r\n\\[\\mathcal{L} \\equiv \\div \\left(\\frac{1}{\\rho} \\grad \\right) - \\pdv{t}\\left(\\frac{1}{\\lambda}\\pdv{t}\\right)\\, .\\]\r\n\r\nLet\r\n\\[p(x) = N^K p^K\\]\r\nthen\r\n\\[\\mathcal{L}(p) \\equiv \\vec \\nabla  \\cdot \\left( {\\frac{1}{\\rho }\\vec \\nabla {N^K}{p^K}} \\right) - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}{p^K}}}{{\\partial t}}} \\right)\\]\r\nor in index notation\r\n\\[\\mathcal{L}(p) \\equiv {\\left( {\\frac{1}{\\rho }N_{,i}^K} \\right)_{,i}}{p^K} - \\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right){p^K}\\]\r\nwhich is equivalent to\r\n\\[\\mathcal{L}(p) \\equiv \\mathcal{L}({N^K}){p^K}\\]\r\nusing the trial functions as weighting function and recalling the definition of the residual which in this case reads\r\n\\[R = \\mathcal{L}({N^K}){p^K} - q\\, ,\\]\r\nand yields\r\n\\[\\int\\limits_V {{N^J}RdV = 0} \\quad \\quad J=1,2,...,K \\]\r\n\r\n\\[\\int\\limits_V {{N^J}L({N^K})dV{p^K}}  - \\int\\limits_V {{N^J}qdV}  = 0\\]\r\n\r\n\\[\\int\\limits_V {{N^J}{{\\left( {\\frac{1}{\\rho }N_{,i}^K} \\right)}_{,i}}dV{p^K} - \\int\\limits_V {{N^J}\\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right)dV{p^K}} }  - \\int\\limits_V {{N^J}qdV}  = 0\\]\r\n\r\nIntegrating by parts the first term on the right-hand-side gives us\r\n\\[ - \\int\\limits_V {N_{,i}^J\\frac{1}{\\rho }N_{,i}^KdV} {p^K} + \\int\\limits_S {{N^J}\\frac{1}{\\rho }N_{,i}^K{{\\hat n}_i}dS{p^K}}  = \\int\\limits_V {{N^J}\\frac{\\partial }{{\\partial t}}\\left( {\\frac{1}{\\lambda }\\frac{{\\partial {N^K}}}{{\\partial t}}} \\right)dV{p^K}}  + \\int\\limits_V {{N^J}qdV} \\]\r\n\r\n\\[\\int\\limits_V {N_{,i}^J\\frac{1}{\\rho }N_{,i}^KdV} {p^K} + \\int\\limits_V {{N^J}\\frac{1}{\\lambda }{N^K}dV{{\\ddot p}^K}}  = \\int\\limits_S {{N^J}\\frac{1}{\\rho }N_{,i}^K{{\\hat n}_i}dS{p^K}}  + \\int\\limits_V {{N^J}qdV} \\]\r\n\r\n\\[{K^{JK}}{P^K} + {M^{JK}}{{\\ddot P}^K} + {f^J} = 0\\]\r\n\r\n\\newpage\r\n\\paragraph*{Example: The Navier equations.}\r\nThe stress equilibrium equations when written in terms of displacements after using the constitutive tensor and the proper kinematic description take the form:\r\n\r\n\\[(\\lambda  + \\mu ){u_{j,ij}} + \\mu {u_{i,jj}} + {f_i} = 0 \\enspace \\]\r\n\r\nwhich are known as the Navier equations and where the differential operator reads\r\n\r\n\\[L_{ij} \\equiv (\\lambda  + \\mu )\\pdv[2]{}{x_i}{x_j} + \\mu \\pdv[2]{}{x_k}{x_k}\\delta_{ij}.\\]\r\n\r\nApplying this operator to an interpolated version of the displacement field $u_i = N_i^Q u^Q$ gives:\r\n\r\n\\[L_{ij}(u_j)\\equiv R_i(u_j)\\]\r\n\r\nthus\r\n\r\n\\begin{align*}\r\n&\\mathcal{L}_{ij}(u_j) \\equiv (\\lambda  + \\mu )(N_j^Q u^Q)_{,ij} + \\mu (N_j^Q u^Q)_{,kk}\\delta_{ij}\\\\\r\n&\\mathcal{L}_{ij}(u_j) \\equiv (\\lambda  + \\mu )N_{j,ij}^Q u^Q + \\mu N_{i,kk}^Q u^Q\\\\\r\n&\\mathcal{L}_{ij}(u_j) \\equiv \\mathcal{L}_{ij}(N_j^Q) u^Q \\enspace .\r\n\\end{align*}\r\n\r\nIn the Galerkin scheme we use the trial function as weighting function.\r\n\\[R_i \\equiv L_{ij}(N_j^Q) u^Q + f_i\\]\r\nand we state\r\n\\[\\int\\limits_V N_i^P R_i \\dd{V} = 0 \\qquad P=1,2,\\cdots N\\, .\\]\r\n\r\nThus\r\n\\begin{align*}\r\n&\\int\\limits_V N_i^P \\mathcal{L}_{ij} (N_j^K)\\dd{V} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0 \\\\\r\n&(\\lambda  + \\mu )\\int\\limits_V N_i^PN_{j,ij}^K \\dd{V} u^K  + \\mu \\int\\limits_V N_i^PN_{i,kk}^K \\dd{V} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0\r\n\\end{align*}\r\nintegrating by parts\r\n\\begin{align*}\r\n- (\\lambda  + \\mu )\\int\\limits_V N_{i,j}^P N_{j,i}^K \\dd{V} u^K + (\\lambda  + \\mu )\\int\\limits_S N_i^P N_{j,i}^K \\hat{n}_j \\dd{S} u^K - \\mu \\int\\limits_V N_{i,k}^P N_{i,k}^K \\dd{V} u^K \\\\\r\n+ \\mu \\int\\limits_S N_i^P N_{i,k}^K \\hat{n}_k \\dd{S} u^K  + \\int\\limits_V N_i^P f_i \\dd{V} = 0\r\n\\end{align*}\r\nwhich can be written like\r\n\\[K^{PQ} U^Q = F^P\\]\r\nwhere\r\n\\[K^{PQ} = (\\lambda  + \\mu )\\int\\limits_V N_{i,j}^P N_{j,i}^Q \\dd{V}  + \\mu \\int\\limits_V N_{i,k}^P N_{i,k}^Q\\dd{V} \\]\r\nand\r\n\\[F^P = \\int\\limits_S N_i^P t_i^{(\\hat n)} \\dd{S} + \\int\\limits_V N_i^P f_i \r\n\\dd{V} = 0 \\, .\\]\r\n\r\n\r\n\r\n%\\newpage\r\n%\\section*{Quadratures}\r\n%\\section{Gaussian quadratures}\r\n%In the numerical quadrature corresponding to the extended trapezoidal rule written in the form\r\n%\r\n%\\begin{equation}\r\n%\\int\\limits_a^b {f(x)dx \\approx \\sum\\limits_{I = 1}^{npts} {{w^I}f({x^I})} }\r\n%\\label{quadra2}\r\n%\\end{equation}\r\n%\r\n%the 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. Using a Gaussian quadrature one can integrate functions which are expressible in the form:\r\n%\r\n%\\[\\int\\limits_a^b {w(x)f(x)dx}  \\approx \\sum\\limits_{I = 1}^{npts} {{w^I}f({x^I})}. \\]\r\n%\r\n%This particular factorization ${w(x)f(x)}$ is useful since it allows us to write a function as the product of a polynomial $f(x)$ times a known function $w(x)$. This last function can be selected to remove integrable singularities out of the integral. To clarify, consider the following (Gauss-Chebyshev) integral:  \r\n%\r\n%\r\n%\\[I = \\int\\limits_{ - 1}^1 {\\frac{{{e^{ - C_x^2}}}}{{\\sqrt {1 - {x^2}} }}} dx \\equiv \\int\\limits_{ - 1}^1 {\\frac{1}{{\\sqrt {1 - {x^2}} }}} {e^{ - C_x^2}}dx\\]\r\n%where\r\n%\\[w(x) = \\frac{1}{{\\sqrt {1 - {x^2}} }}\\]\r\n%\r\n%and \r\n%\r\n%\\[f(x) = {e^{ - C_x^2}}.\\]\r\n%\r\n%Now, making:\r\n%\\[g(x) = w(x)f(x)\\]\r\n%and\r\n%\\[{v^I} = \\frac{{{w^I}}}{{w({x^I})}}\\]\r\n%\r\n%yields:\r\n%\r\n%\\begin{equation}\r\n%\\int\\limits_{ - 1}^{ + 1} {g(x)dx}  \\approx \\sum\\limits_{I = 1}^{npts} {{v^I}g({x^I})}\r\n%\\label{gauss}\r\n%\\end{equation}\r\n%\r\n%In 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.\r\n%\r\n%\\begin{center}\r\n%\\begin{tabular}{cc}\r\n%  \\hline\r\n%  $x^I$ & $w^I$ \\\\\r\n%  \\hline \r\n%  $-0.86113$  & $0.34785$  \\\\\r\n%  $-0.33998$  & $0.65214$  \\\\\r\n%  $ +0.33998$  & $0.65214$  \\\\\r\n%  $ +0.86113$  & $0.34785$  \\\\\r\n%  \\hline\r\n%\\end{tabular}\r\n%\\captionof{table}{Abscissas and weighting factors to compute $\\int\\limits_{ - 1}^{ + 1} {f(x)dx}$}\r\n%\\label{ejemplo2}\r\n%\\end{center}\r\n%\r\n%To 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.\r\n%\r\n%\\begin{figure}[H]\r\n%\\centering\r\n%\\includegraphics[width=10cm]{img/quagauss.pdf}\r\n%\\caption{Schematic reperesentation of a Gaussian quadrature in the primitive range $[-1.0,1.0]$.}\r\n%\\label{fig:quagauss}\r\n%\\end{figure}\r\n%\r\n%\\paragraph*{Example:Derivation of a Gaussian quadrature}\r\n%Let $n=2$ and the integration interval $[a,b]=[-1,+1]$. Find $w^1$, $w^2$ and $x^1$, $x^2$ such the quadrature\r\n%\r\n%\r\n%\\[I = \\int\\limits_{ - 1}^{ + 1} {f(x)dx}  \\approx {w^1}f({x^1}) + {w^2}f({x^2})\\]\r\n%\r\n%integrated exactly the function  $f(x)$ corresponding to a third order polynomial like:\r\n%\r\n%\r\n%\r\n%\\[f(x) = {a_0} + {a_1}x + {a_2}{x^2} + {a_3}{x^3}.\\]\r\n%\r\n%Using $f(x)$ in $I$ and stating the integral for each term we have:\r\n%\r\n%\r\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} \\]\r\n%\r\n%where:\r\n%\r\n%\\[\\int\\limits_{ - 1}^{ + 1} {dx}  = 2 = {w^1} \\cdot 1 + {w^2} \\cdot 1\\]\r\n%\r\n%\\[\\int\\limits_{ - 1}^{ + 1} {xdx}  = 0 = {w^1} \\cdot {x^1} + {w^2} \\cdot {x^2}\\]\r\n%\r\n%\\[\\int\\limits_{ - 1}^{ + 1} {{x^2}dx}  = \\frac{2}{3} = {w^1} \\cdot {({x^1})^2} + {w^2} \\cdot {({x^2})^2}\\]\r\n%\r\n%\\[\\int\\limits_{ - 1}^{ + 1} {{x^3}dx}  = 0 = {w^1} \\cdot {({x^1})^3} + {w^2} \\cdot {({x^2})^3}.\\]\r\n%\r\n%The 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:\r\n%\r\n%\\[I = \\int\\limits_{ - 1}^{ + 1} {f(x)dx}  \\approx 1.0 \\cdot f( - \\sqrt 3 /3) + 1.0 \\cdot f( + \\sqrt 3 /3)\\]\r\n%\r\n%which is exact for polynomial functions of order at most 3.\r\n%\r\n%The 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.\r\n%\r\n%\\paragraph*{Orthogonal polynomials}\r\n%Two polynomials $P(x)$ and $Q(x)$, where $P(x) \\ne Q(x)$ are said to be orthogonal if:\r\n%\r\n%\\[\\int\\limits_a^b {P(x)Q(x)} dx = 0.\\]\r\n%\r\n%Particularly, the Legendre polynomials, defined by:\r\n%\r\n%\\[P_n(x) = \\frac{1}{2^n n!}\\frac{d^n}{dx^n}[(x^2 - 1)^n]\\]\r\n%\r\n%which at the same time are solution to the equation:\r\n%\r\n%\r\n%\\[(1 - {x^2}){y^{''}} - 2x{y^{'}} + n(n + 1)y = 0\\]\r\n%\r\n%in the range $[-1,+1]$ satisfy the following orthogonality condition:\r\n%\r\n%\\[\\int\\limits_{ - 1}^{ + 1} {{Q_i}(x)} {P_j}(x)dx = 0\\]\r\n%\r\n%where ${{Q_i}(x)}$ is any polynomial function of order $i<j$. \r\n%\r\n%Besides the orthogonality property, Legendre polynomials have roots in the range $(-1.0,+1.0)$ which are different and symmetrical with respect to zero. This last condition make the roots useful in the derivation of quadratures for the integration of polynomial functions of order less than $2n$. For instance, the second Legendre polynomial given by:\r\n%\r\n%\\[{P_2}(x) = {x^2} - \\frac{1}{3}\\]\r\n%\r\n%has roots ${x^1} =  - \\frac{{\\sqrt 3 }}{3}$ and ${x^2} =  + \\frac{{\\sqrt 3 }}{3}$ which correspond to integration points for an exact quadrature of order 3.\r\n%\r\n%\\paragraph*{Theorem}\r\n%\r\n%Let $\\left\\{ {{x^1},{x^2},...,{x^n}} \\right\\}$ the roots of the Legendre polynomial ${P_n}(x)$ of order $n$; let \\[{w^I} = \\int\\limits_{ - 1}^{ + 1} {\\prod\\limits_{J = 1}^n {\\frac{{x - {x^J}}}{{{x^I} - {x^J}}}} dx} \\] and let $f(x)$ be any polynomial function of order less than $2n$, then:\r\n%\r\n%\\begin{equation}\r\n%I = \\int\\limits_{ - 1}^{ + 1} {f(x)dx}  = \\sum\\limits_{I = 1}^n {{w^I}f({x^I})}.\r\n%\\label{Legendre}\r\n%\\end{equation}\r\n%\r\n%\r\n%\\paragraph*{Proof}\r\n%(i) If $f(x)$ is of order less than $n$, then clearly it is representable in terms of Lagrange polynomials which automatically satisfy condition \\eqref{Legendre}.\r\n%\r\n%\r\n%(ii) If $f(x)$ is of order less than $2n$ then it is representable like:\r\n%\r\n%\\[f(x) = Q(x){P_n}(x) + R(x)\\]\r\n%\r\n%where $Q(x)$ is the quotient of  $f(x)/{P_n}(x)$ and of order $n-1$ (or lesser) and $R(x)$ is the residual and of order lesser than $n$. Integrating this representation of $f(x)$ we have that:\r\n%\r\n%\\[\\int\\limits_{ -1}^{ +1} {Q(x) P_n(x)\\ dx}  + \\int\\limits_{ - 1}^{ + 1} R(x)\\ dx \\]\r\n%\r\n%which reduces to:\r\n%\r\n%\\[I = \\int\\limits_{ -1}^{ +1} {f(x)dx}  = \\int\\limits_{ -1}^{ +1} R(x)\\ dx \\]\r\n%\r\n%after using the orthogonality property between $Q(x)$ and $P_n (x)$. Now, recalling the expression\r\n%\r\n%\\[f(x) = Q(x){P_n}(x) + R(x)\\]\r\n%\r\n%and if this is evaluated at the roots of the Legendre polynomials it gives:\r\n%\r\n%\\[f(x^I) = R(x^I)\\]\r\n%\r\n%completing the proof.\r\n\r\n%\\newpage\r\n%\\begin{minted}[mathescape,\r\n%           gobble=4,\r\n%           frame=lines,\r\n%           framesep=2mm]{python}\r\n%    \"\"\"\r\n%    Computes the integral of f(x) using a Gauss quadrature\r\n%    \r\n%    \"\"\"\r\n%    from __future__ import division, print_function\r\n%    import numpy as np\r\n%    from sympy import symbols, integrate\r\n%    \r\n%    \r\n%    def gpoints4():\r\n%        \"\"\"Gauss points for a 2 by 2 grid\r\n%    \r\n%        Returns\r\n%        -------\r\n%        xw : ndarray\r\n%          Weights for the Gauss-Legendre quadrature.\r\n%        xp : ndarray\r\n%          Points for the Gauss-Legendre quadrature.\r\n%    \r\n%        \"\"\"\r\n%        xw = np.zeros([4])\r\n%        xp = np.zeros([4])\r\n%        xp[0] = -0.861136311594053\r\n%        xp[1] = -0.339981043584856\r\n%        xp[2] = +0.339981043584856\r\n%        xp[3] = +0.861136311594053\r\n%        xw[0] =  0.347854845137454\r\n%        xw[1] =  0.652145154862546\r\n%        xw[2] =  0.652145154862546\r\n%        xw[3] =  0.347854845137454\r\n%        return xw, xp    \r\n%    \r\n%    \r\n%    f = lambda x: x**3 + 4*x**2 - 10\r\n%    \r\n%    \r\n%    gauss_inte = 0.0\r\n%    xw, xp = gpoints4()\r\n%    for i in range(4):\r\n%        r = xp[i]\r\n%        w = xw[i]\r\n%        gauss_inte = gauss_inte + w*f(r)\r\n%    \r\n%    x  = symbols('x')\r\n%    analytic_inte = integrate(f(x) , (x , -1 , 1))\r\n%    print(\"Analytic integral: {:.6f}\".format(float(analytic_inte)))\r\n%    print(\"Gauss quadrature: {:.6f}\".format(gauss_inte))\r\n%\\end{minted}\r\n\r\n\\newpage\r\n\\chapter{Convergence analysis}\r\nIn this section we address the problem of convergence of analysis results. We \r\nwill approach the problem in a loose way proceeding from an engineering point \r\nof view. For a thorough discussion the reader is referred to textbooks of \r\nnumerical analysis, see for instance \\cite{abaqus1989karlsson}. Particularly, \r\nwe will review the fundamental aspects that must be satisfied by a finite \r\nelement solution. In the first part we address the problem from the element \r\npoint of view, while in the final part we study the convergence of particular \r\nproblem in terms of several self-contained meshes.\r\n\r\n\\section{¿What is meant by convergence?}\r\nMathematical convergence of order $p$ and rate $c$ for a series of numerically computed values $\\vec u_{k}$ and for a problem with exact solution $\\vec u$ is defined like:\r\n\r\n\\[\\mathop {\\lim }\\limits_{k \\to \\infty } \\frac{{\\left\\| {{{\\vec u}_{k + 1}} - \\vec u} \\right\\|}}{{{{\\left\\| {{{\\vec u}_k} - \\vec u} \\right\\|}^p}}} = c.\\]\r\n\r\nA practical definition of convergence in finite element analysis is given as follows. Let us denote by $\\Pi$ and $\\Pi _{FE}$ the potential energy functionals corresponding to the exact mathematical model and to the finite element solution respectively, where the functional corresponding to a given discretization can be computed as:\r\n\r\n\\[{\\Pi _{FE}} =  - \\frac{1}{2}{U^T}KU\\]\r\n\r\nwhere $K$ and $U$ are the global stiffness matrix and the global nodal displacements vector. If $k$ represents the number of finite elements in a given discretization then we define convergency as the condition that:\r\n\r\n\\begin{equation}\r\n\\mathop {\\lim }\\limits_{k \\to \\infty } {\\Pi_{FE}} \\to \\Pi \r\n\\label{convergence}\r\n\\end{equation}\r\n\r\n\r\nIn order to guarantee that a finite element solution convergences to the exact (unknown) solution of a problem certain conditions must be met by both, the single elements and the whole assembled finite element mesh. The analysis of the element is conducted when the element is formulated for the first time while the analysis of the mesh is problem dependent. In the following sections we will address both problems.\r\n\r\n\\section{Conditions on a single element}\r\nFrom a physical point of view we may expect the following behaviour from the individual elements in a given discretization:\r\n\r\n\\begin{itemize}\r\n\\item[•] Under a rigid body compatible displacement field the element must \r\npredicts a zero strain field ${\\varepsilon _{ij}} = 0.$ This condition is \r\nrequired in order to maintain actual regions of the domain which are submitted \r\nto rigid body modes in a stress free condition.\r\n\r\n\\item[•] The element must be able to predict constant strain states as its size \r\ndecreases. This condition guarantees that as the element size decreases it also \r\napproaches the condition of an actual material point.\r\n\r\n\\item[•] The work from the surface tractions along the element interfaces must \r\nvanish. This is nothing but Newton's third law in terms of surface tractions. \r\nThe fact that the first order derivatives of the shape functions (equivalent to \r\nsurface tractions) are discontinuous along the element boundaries results in \r\nfinite jumps in the boundary tractions. The element must be such that these \r\njumps vanish as the element size decreases.   \r\n\\end{itemize}\r\n\r\nIn terms of the shape functions these three conditions are equivalent to:\r\n\r\n\r\n\\begin{itemize}\r\n\\item[(i)] All the element shape functions must be selected in such a way that the element predicts ${\\varepsilon _{ij}} = 0$ under rigid body compatible nodal displacements.\r\n\\item[(ii)] All the element shape functions must be selected in such a way that if the nodal displacements are compatible with a constant strain state that state is actually obtained.\r\n\\item[(iii)] All the element shape functions must be selected in such a way that the strains over the element interfaces are finite and the displacements along these boundaries are continous. \r\n\\end{itemize}\r\n\r\nConditions (i) and (ii) are known as the {\\bf completeness condition} while condition (iii) is referred to as the {\\bf compatibility} condition.\r\n\r\n\r\nIn order to determine if a specific element is complete we find the eigenvalues of the stiffness matrix and study the resulting eigenvectors which corresponde to the deformation modes of the element. The eigenvalue problem reads:\r\n\r\n\\begin{equation}\r\n\\left[ {K - \\lambda I} \\right]\\phi  = 0\r\n\\label{eigen}\r\n\\end{equation}\r\n\r\nwhose solution gives the rigid body modes and straining modes that can be reproduced by the specific element. In \\cref{eigen} $\\lambda$ corresponds to the eigenvalues and the vector $\\phi$ stores the corresponding eigenmodes.\r\n\r\nAs an example of the single element analysis we show the solution for a single bi-linear perfectly square element of characteristic size $2h=1.0$ and material properties given by $E=1.0$ and $\\nu = 0.30$ (see \\citep{Bathe1995}). The eigenvalue problem is solved with the script {\\bf modes.py} listed in the last section. Solution of \\cref{eigen} predicts the following set of eigenvalues:\r\n\r\n\r\n\\[\\lambda  = [0(3),0.495(2),0.769(2),1.43].\\]\r\n\r\nFrom these the first three zero-valued eigenvalues can be shown to describe the possible rigid body motions, namely one rotation and two translations along the horizontal and vertical directions respectively. The next two eigenvalues corresponding to $0.495$ represent flexure modes. Similarly, the repeated values corresponding to $0.769$ are associated to shear modes while the last eigenvalue corresponds to a uniform extension mode. The number of different modes satisfy the following condition:\r\n\r\n\\[{N_S} = {N_{DOF}} - {N_{RB}}\\]\r\n\r\nwhere ${N_S}$, ${N_{DOF}}$ and ${N_{RB}}$ are the number of straining modes, number of degrees of freedom and number of rigid body modes. The original and deformed element shapes are shown in \\cref{modos} which is obtained after one combines the eigenvalues properly. The last row of the figure (obtained with the script {\\bf strfield.py}) shows the zero-valued strain field associated to the first rigid body mode.\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{first.pdf}\r\n\t\t\\caption{$\\lambda_1 = 0$. }\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{second.pdf}\r\n\t\t\\caption{$\\lambda_2 = 0$.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{third.pdf}\r\n\t\t\\caption{$\\lambda_3 = 0$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{fourth.pdf}\r\n\t\t\\caption{$\\lambda_4 = 0.495$.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{fifth.pdf}\r\n\t\t\\caption{$\\lambda_5 = 0.495$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{sixth.pdf}\r\n\t\t\\caption{$\\lambda_6 = 0.769$.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{seventh.pdf}\r\n\t\t\\caption{$\\lambda_7 = 0.769$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{eight.pdf}\r\n\t\t\\caption{$\\lambda_8 = 1.43$.}\r\n\t\\end{subfigure}\r\n%\r\n\\caption{Deformation modes of a bi-linear element.}\r\n\\label{modos}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{epsilonx.png}\r\n\t\t\\caption{$\\epsilon_{xx}$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{epsilony.png}\r\n\t\t\\caption{$\\epsilon_{yy}$.}\r\n\t\\end{subfigure}\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{gammaxy.png}\r\n\t\t\\caption{$\\gamma_{xy}$}\r\n\t\\end{subfigure}\r\n%\r\n\\caption{Deformation modes of a bi-linear element.}\r\n\\label{strains}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\section{Analysis of the mesh results}\r\n\r\nConsider the square energy norm of the error $\\left\\| {{{\\vec e}_h}} \\right\\|_E^2$. This error satisfies\r\n\r\n\\[\\left\\| {{{\\vec e}_h}} \\right\\|_E^2 > 0\\]\r\n\r\nand will be used as an error estimate of the accuraccy of the finite element solution. Particularly we will use the following relationship (see \\cite{abaqus1989karlsson})\r\n\r\n\\begin{equation}\r\n\\left\\| {{{\\vec e}_h}} \\right\\| \\le \\alpha {h^k}\r\n\\label{estimate1}\r\n\\end{equation}\r\n\r\n\r\nfrom which we can write:\r\n\r\n\r\n\\begin{equation}\r\n\\log \\left\\| {{{\\vec e}_h}} \\right\\| \\approx \\log \\alpha  + k\\log h\r\n\\label{estimate2}\r\n\\end{equation}\r\n\r\nIn \\cref{estimate2} $k$ is the order of the complete interpolation polynomial present in the mesh and gives a measure of the order of convergence in the finite element solution, while the rate of convergency is given by $\\alpha$.\r\n\r\nIn order to conduct the convergency study we perform a series of finite element analysis. For each mesh we compute $\\left\\| {\\vec u - {{\\vec u}_h}} \\right\\|$ which is equivalent to $\\vec e_h$ and where $\\vec u$ is the exact solution. In order to find the exact solution we assume that the most refined results have functionals corresponding to ${\\Pi _{n - 2}}$, ${\\Pi _{n - 1}}$ and ${\\Pi _{n}}$ from which:\r\n\r\n\\[{\\Pi _{Exa}} = \\frac{{\\Pi _{n - 1}^2 - {\\Pi _n}{\\Pi _{n - 2}}}}{{(2{\\Pi _{n - 1}} - {\\Pi _n} - {\\Pi _{n - 2}})}}\\]\r\n\r\nThe procedure is summarized below:\r\n\r\n\\begin{itemize}\r\n\\item Solve a series of meshes with solutions given by $\\vec u_1, \\vec u_2,...,\\vec u_n$. Each mesh has a characteristic element size $h$.\r\n\\item For each mesh find the total potential energy:\r\n\r\n\\[{\\Pi_h} =  - \\frac{1}{2}{U^T}KU\\]\r\n\r\n\\item Using the most refined meshes compute the potential energy for the exact solution:\r\n\r\n\\[{\\Pi _{Exa}} = \\frac{{\\Pi _{n - 1}^2 - {\\Pi _n}{\\prod _{n - 2}}}}{{2{\\Pi _{n - 1}} - {\\Pi _n} - {\\Pi _{n - 2}}}}\\]\r\n\r\n\\item For each mesh compute:\r\n\r\n\\[\\frac{{\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_h}} \\right\\|}}{{\\left\\| {{{\\vec u}_{Exa}}} \\right\\|}} = {\\left[ {\\frac{{{\\Pi _{Exa}} - {\\Pi _h}}}{{{\\Pi _{Exa}}}}} \\right]^{1/2}}\\]\r\n\r\nand fill out the following table:\r\n\r\n\\begin{center}\r\n\\begin{tabular}{ |c|c|c|c| }\r\n  \\hline\r\n  $h$ & ${\\prod _{FE}}$ & $\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|$ & $\\frac{{\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|}}{{\\left\\| {{{\\vec u}_{Exa}}} \\right\\|}}$ \\\\\r\n  \\hline \r\n  $1.0$  & $$ & $$  & $$  \\\\\r\n  \\hline\r\n   $0.5$  & $$ & $$  & $$  \\\\\r\n  \\hline\r\n   $0.25$  & $$ & $$  & $$  \\\\\r\n  \\hline\r\n   $ 0.125$  & $$ & $$  & $$  \\\\\r\n  \\hline\r\n  $ 0.0625$  & $$ & $$  & $$  \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\captionof{table}{Convergence of anlysis results}\r\n\\label{tabconv}\r\n\\end{center}\r\n\r\n\r\n\\item Plot the values of $\\log \\left( {\\frac{{\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_h}} \\right\\|}}{{\\left\\| {{{\\vec u}_{Exa}}} \\right\\|}}} \\right)$ vs $\\log h$ and determine the slope which upon convergence must be close to the order of the complete polynomial used in the discretization.\r\n\r\n\\end{itemize}\r\n\r\n\r\n\\paragraph*{Exampla: bar in compression}\r\n\\Cref{mallas} shows a tappered bar under a compressive uniformly distributed load of total magnitude $P=0.5$. The bar is of length $l=10$ and its large and short ends given by $h_1 = 2.0$ and $h_2 =0.5$ respectively. The material properties correspond to a Poisson's ratio and Young modulos $\\nu=0.30$ and $E=1.0$. We want to find the converged solution for the bar after using 3-noded triangular elements.\r\n\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\includegraphics[width=5.0 in]{img/tappered.pdf}\t\r\n\t\\label{bar}\r\n\t\\caption{Tappered bar under compressive load at the tip.}\r\n\\end{figure}\r\n\r\n\\Cref{mallas} displays 4 consecutive meshes with decreasing element size namely $h=[1.0, 0.5, 0.25, 0.125]$. While \\cref{gamatap} displays the shear strain contour maps for the finite element solutions corresponding to the coarse and refined meshes. It is clear how these contours become smooth as the mesh is refined. This approach is sometimes used as an empirical test of convergence.\r\n\r\nTo measure the finite element convergence we first compute the total potential energy in each mesh ccording to:\r\n\r\n\\[{\\Pi _{FE}} =  - \\frac{1}{2}{U^T}KU.\\]\r\n\r\nNow assuming we have consecutive meshes each one obtained after halving the elements in the previous mesh we have the following approximation for the exact total potential energy of the system, computed the last most refined meshes:\r\n\r\n\\[{\\Pi _{Exa}} = \\frac{{{{1.161}^2} - ( - 1.160)( - 1.155)}}{{ - 2(1.161) - ( - 1.160) - ( - 1.155)}} = -1.160.\\]\r\n\r\nTo compute the energy norm of the error we use:\r\n\r\n\\[\\frac{{\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|}}{{\\left\\| {{{\\vec u}_{Exa}}} \\right\\|}} = {\\left[ {\\frac{{{\\Pi _{Exa}} - {\\prod _{FE}}}}{{{\\Pi _{Exa}}}}} \\right]^{1/2}}.\\]\r\n\r\nThe analysis results are reported in \\cref{ejemplo}.\r\n\r\n%\\begin{figure}[H]\r\n%\\centering\r\n%\t\\subfloat [$h=1.00$]{\\includegraphics[width=2.5 in]{tap1.pdf}}\r\n%\t\\subfloat [$h=0.50$]{\\includegraphics[width=2.5 in]{tap2.pdf}}\\\\\r\n%%\t\\vspace{-.2 cm}\r\n%\t\\subfloat [$h=0.250$]{\\includegraphics[width=2.5 in]{tap3.pdf}}\r\n%\t\\subfloat [$h=0.125$]{\\includegraphics[width=2.5 in]{tap4.pdf}}\\\\\r\n%\t\\caption{Refined meshes for a tappered bar.}\r\n%\t\\label{mallas}\r\n%\\end{figure}\r\n\r\n\r\n%%%%%\r\n\\begin{figure}[H]\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{tap1.pdf}\r\n\t\t\\caption{$h=1.00$. }\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{tap2.pdf}\r\n\t\t\\caption{$h=0.50$.}\r\n\t\\end{subfigure}\\\\\r\n%\r\n\\centering\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{tap3.pdf}\r\n\t\t\\caption{$h=0.250$.}\r\n\t\\end{subfigure}\\,\r\n%\r\n\t\\begin{subfigure}[b]{0.450\\textwidth}\\qquad\r\n\t\t\\includegraphics[width=\\textwidth]{tap4.pdf}\r\n\t\t\\caption{$h=0.125$.}\r\n\t\\end{subfigure}\r\n%\r\n\\caption{Refined meshes for a tappered bar.}\r\n\\label{mallas}\r\n\\end{figure}\r\n\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=6 in]{gamatap.pdf}\r\n\\caption{Shear strain distribution for the coarse and fine mesh.}\r\n\\label{gamatap}\r\n\\end{figure}\r\n\r\n\r\n%%%%%%\r\n\r\n\r\n\\begin{center}\r\n\\begin{tabular}{cccc}\r\n  \\hline\r\n  $h$ & ${\\Pi _{FE}}$ & $\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|$ & $\\frac{{\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|}}{{\\left\\| {{{\\vec u}_{Exa}}} \\right\\|}}$ \\\\\r\n  \\hline \r\n  $1.0$      & $-1.151$ & $0.095$  & $0.088$  \\\\\r\n   $0.5$     & $-1.155$ & $0.071$  & $0.066$  \\\\\r\n   $0.25$    & $-1.161$ & $0.032$  & $0.030$  \\\\\r\n   $ 0.125$  & $-1.160$ & $0.001$  & $0.001$  \\\\\r\n  \\hline\r\n\\end{tabular}\r\n\\captionof{table}{Convergence of anlysis results}\r\n\\label{ejemplo}\r\n\\end{center}\r\n\r\nTo measure convergence we plot:\r\n\\[\\log \\left( {\\left\\| {{{\\vec u}_{Exa}} - {{\\vec u}_{FE}}} \\right\\|} \\right) = \r\n\\log c + k\\log h\\]\r\nleading to \\cref{fig:conv} from which  $k \\approx 1.14.$\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=0.65\\textwidth]{img/conver.pdf}\r\n\\caption{Energy norm of the error}\r\n\\label{fig:conv}\r\n\\end{figure}\r\n\r\n\\newpage\r\n\r\n\r\n\\paragraph*{Example: cantilever beam}\r\nConsider the cantilever beam shown in \\cref{fig:viga}\r\n\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=0.75\\textwidth]{img/beam.pdf}\r\n\\caption{Cantelever beam.}\r\n\\label{fig:viga}\r\n\\end{figure}\r\nwith analytic solution \\citep{book:timoshenko} given by:\r\n\\begin{align*}\r\nu &=  -\\frac{P}{2EI} x^2 y - \\frac{\\nu P}{6EI} y^3 + \\frac{P}{2IG}{y^3} + \r\n\\left(\\frac{P l^2}{2EI} - \\frac{P c^2}{2IG}\\right)y \\, ,\\\\\r\nv &= \\frac{\\nu P}{2EI} x y^2 + \\frac{P}{6EI} x^3 - \r\n\\frac{Pl^2}{2EI}x + \\frac{Pl^3}{3EI}\\, ,\\\\\r\n\\varepsilon_{xx} &= \\pdv{u}{x} \\equiv - \\frac{P}{EI}xy\\, ,\\\\\r\n\\varepsilon_{yy} &= \\pdv{v}{y} \\equiv \\frac{\\nu P}{EI} xy\\, ,\\\\\r\n\\gamma_{xy} &= \\pdv{u}{y} + \\pdv{v}{x} \\equiv \\frac{P}{2IG} (y^2 - c^2)\\, .\r\n\\end{align*}\r\n\r\nThe horizontal and vertical displacement field corresponding to the particular \r\nvalues of $E=1000.0$, $\\nu=0.30$ for the material parameters; $l=24$ and $2c=8$ \r\nfor the geometry and $P=50$ (upwards) for the load is shown below:\r\n\\begin{figure}[H]\r\n\\centering\r\n\\includegraphics[width=0.75\\textwidth]{img/anahorizo.pdf}\\\\\r\n\\includegraphics[width=0.75\\textwidth]{img/anavertic.pdf}\r\n\\caption{Displacement field for the cantilever beam.}\r\n\\label{fig:ecuacion}\r\n\\end{figure}\r\n\r\n\r\nPerform a finite element simulation using a series of refined meshes with charateristic element size corresponding to $h=[6.0,3.0,1.5,0.75,0.375]$ and show that convergence is achieved. To conduct the finite element analysis fill out \\cref{problem}\r\n\r\n\r\n\\begin{center}\r\n\\begin{tabular}{cccc}\r\n\\hline\r\n$h$ & $\\prod_{FE}$ & $\\left\\| \\vec{u}_{Exa} - \\vec{u}_{FE}\\right\\|$ \r\n& $\\frac{\\left\\| \\vec{u}_{Exa} - \\vec{u}_{FE}\\right\\|}{\\left\\| \r\n\\vec{u}_{Exa} \\right\\|}$ \\\\\r\n\\hline \r\n$6.0$  & $$ & $$  & $$  \\\\\r\n$3.0$  & $$ & $$  & $$  \\\\\r\n$1.5$  & $$ & $$  & $$  \\\\\r\n$ 0.75$  & $$ & $$  & $$  \\\\\r\n$ 0.375$  & $$ & $$  & $$  \\\\\r\n\\hline\r\n\\end{tabular}\r\n\\captionof{table}{Convergence of anlysis results}\r\n\\label{problem}\r\n\\end{center}", "meta": {"hexsha": "186d1d568ffe20e597609b4645b90c87a90a8243", "size": 54395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course_notes/src/appendix.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/appendix.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/appendix.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": 51.0272045028, "max_line_length": 836, "alphanum_fraction": 0.6661457855, "num_tokens": 17995, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240090865198, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7647891628258571}}
{"text": "\\chapter*{This is the title of the paper one more time.}\n\\graphicspath{{./chap1/images/}}   \n%\\section{Introduction}\n\nThe Riemann zeta function or Euler–Riemann zeta function, ζ(s), is a mathematical function of a complex variable s, and can be expressed as:\n\\[\n    \\zeta(s) = \\sum_{n=1}^\\infty n^{-s} = \\frac{1}{1^s} + \\frac{1}{2^s} + \\frac{1}{3^s} + \\cdots, \\textrm{If Re(s) > 1}\n\\]\nAnd the value of the zeta function at $s = 2$ is a famous problem in mathematical analysis with relevance to number theory, first posed by Pietro Mengoli in 1650. Examining$\\zeta(2)$, also knows as the Basel problem asks for the precise summation of the reciprocals of the squares of the natural numbers.\n\\[\n    \\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{1}{1^2} + \\frac{1}{2^2} + \\frac{1}{3^2} + \\cdots\n\\]\nThe problem was first solved by Leonhard Euler in 1734 and the value is well known:  $\\frac{\\pi^2}{6}$\n~\\\\\n\n\n\n\n\nBefore we start the journey, we need to note some alternative forms of the problem, for ease of proving. The identity we need to prove is\n\\begin{align}\n    \\zeta(2) = \\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6} \\tag{1}\\label{eq:1}\n\\end{align}~\\\\\nSince it is clear that\n\\[\n    \\frac{3}{4}\\zeta(2) = \\sum_{n=1}^\\infty \\frac{1}{n^2} -  \\sum_{n=1}^\\infty \\frac{1}{(2n)^2}= \\sum_{n=0}^\\infty \\frac{1}{(2n+1)^2} \n\\]~\\\\\n\\eqref{eq:1} is equivalent with\n\\begin{align}\n    \\sum_{n=0}^\\infty \\frac{1}{(2n+1)^2} = \\frac{\\pi^2}{8} \\tag{2}\\label{eq:2}\n\\end{align}~\\\\\n\n\nSo, let's start the journey.\\\\\n~\\\\\n%%----------------\n\\section{Euler's proof for the Basel problem}\nBefore we start, let's check out Euler's proof in 1735. Using the Taylor expansion,\n\\[\n    \\frac{\\sin x}{x} = 1 - \\frac{x^2}{3!} + \\frac{x^4}{5!}+\\cdots\n\\]\nLet the roots of the equation $1 - \\frac{x^3}{3!} + \\frac{x^5}{5!}+\\cdots=0$ be $\\alpha_1, \\alpha_2, \\alpha_3, \\cdots$.\\\\\nthen $\\alpha_1^2, \\alpha_2^2, \\alpha_3^2, \\cdots$ are the roots of $1 - \\frac{x}{3!} + \\frac{x^2}{5!}+\\cdots=0$.~\\\\\n\nLetting\n\\[\n    p(x)=1 - \\frac{x^2}{3!} + \\frac{x^4}{5!}+\\cdots\n\\]\n$p(x)$ can be also expressed as\n\\[\n    p(x)=(x-\\alpha_1^2)(x-\\alpha_2^2)(x-\\alpha_3^2)\\cdots\n\\]~\\\\\nAnd comparing the coefficient of $x$ in both expressions,\n\\[\n    \\frac{1}{6}=\\frac{1}{\\alpha_1^2}+\\frac{1}{\\alpha_2^2}+\\frac{1}{\\alpha_3^2}+\\cdots\n\\]~\\\\\n\nMeanwhile, the roots of $\\frac{\\sin x}{x} = 0$ is $n\\pi (n \\in \\mathbb{N})$ so all $n^2\\pi^2$s are the root of $p(x)=0$. Substituting it,\n\\[\n    \\sum_{n=1}^\\infty \\frac{1}{n^2} = \\frac{\\pi^2}{6}\n\\]\n~\\\\\n\\begin{remark}\n    Actually, the proof has severe errors handling the concept of infinity, which needs to be proven. However, the idea was genuine and the value was correct.\n\\end{remark}\n\n%%----------------\n%%----------------\n\\newpage\n%%----------------\n\\section{Proof using the Taylor series of $\\arcsin x $~}\nThe Taylor series of the inverse sine function where $|x| \\leq 1$ is\n\\[\n    \\arcsin x = \\sum_{n=0}^\\infty \\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n} \\frac{x^{2n+1}}{2n+1}\n\\]\nLet $x = \\sin t$ so that\n\\begin{align}\n    t = \\sum_{n=0}^\\infty \\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n} \\frac{\\sin^{2n+1}t}{2n+1}\\tag{3}\\label{eq:3}\n\\end{align}\nstands for $|t| \\leq \\frac{\\pi}{2}$.~\\\\\\\\\n\nBefore moving forward, we must prove that \\eqref{eq:3} is uniformly convergent.~\\\\\n\nLet $a_n = \\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n}$ then\n\\[\n    \\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n} < \\frac{2\\cdot4\\cdot6\\cdots(2n)}{3\\cdot5\\cdot7\\cdots(2n+1)}\n\\]\n\\[\n    {a_n}^2 < \\frac{1}{2n+1}\n\\]\nTherefore,\n\\[\n    a_n < \\sqrt{\\frac{1}{2n+1}}\n\\]\n~\\\\\n\nUsing the Weierstrass M-test, $\\forall n \\in \\mathbb{N}$,\n\\[\n     |f_n| = |\\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n} \\frac{\\sin^{2n+1}x}{2n+1}| \\leq \\frac{1\\cdot3\\cdot5\\cdots(2n-1)}{2\\cdot4\\cdot6\\cdots2n} \\frac{1}{2n+1} = M_n\n\\]\nand the series $\\sum_{n=0}^\\infty M_n$ converges by the direct comparison test and the p-series test because\n\\[M_n = a_n\\frac{1}{2n+1} < \\frac{1}{\\sqrt{(2n+1)^3}}\\]~\\\\\n\n\nSo, the terms in the RHS of \\eqref{eq:3} are uniformly convergent. We can now integrate each terms independently. ~\\\\\\\\\n\n\nFinally, using the Wallis formula\n\\[\n    \\int_{0}^\\frac{\\pi}{2} \\sin^{2n+1}t dt =  \\frac{2\\cdot4\\cdot6\\cdots2n}{1\\cdot3\\cdot5\\cdots(2n+1)}\n\\]\nfor integrating \\eqref{eq:3} from $0$ to $\\frac{\\pi}{2}$ gives us\n\\[\n     \\frac{\\pi^2}{8} = \\int_{0}^\\frac{\\pi}{2} t dt = \\sum_{n=0}^\\infty \\frac{1}{(2n+1)^2}\n\\]\nwhich is equivalent to \\eqref{eq:1}, the identity we want to prove.~\\\\\n\n\n\\begin{remark}\nWithout proving that the function is uniformly convergent, we cannot integrate each terms inside the right-hand-side of \\eqref{eq:3} independently.\n\\end{remark}\n~\\\\\\\\\n%-------------------------\n\\section{Proof using the Fourier series of $f(x)=x(1-x)$~}\nTake $f(x)=x(1-x)$. Since $f$ is continuous at $[0,1]$ and $f(0)=f(1)$, the Fourier series of $f$ converges to f pointwise.\n\n\n\nThis gives us\n\\[\n    x(1-x)=\\frac{1}{6}-\\sum_{n=1}^{\\infty}\\frac{\\cos 2\\pi nx}{\\pi^2n^2}\n\\]\nand putting $x=0$ we get \\eqref{eq:1}.\n\nAlternatively putting $x=\\frac{1}{2}$ gives us\n\\[\n    \\frac{\\pi^2}{12}=-\\sum_{n=1}^{\\infty}\\frac{(-1)^n}{n^2}\n\\]\nwhich is also equivalent to \\eqref{eq:1}.\n\n\\newpage\n\\section{Proof using the Fourier series of $f(x)=x$~}\nLets start with the Fourier expansion of $f(x) = x$ which is:\n\\[\n    a_n =  \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)\\cos(nx)dx = 0\n\\]\n\\[\n    b_n =  \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)\\sin(nx)dx = (-1)^{n+1}\\frac{2}{n}\n\\]\n~\\\\\n\\begin{remark}\n    We should prove that the function is uniformly continuous while following the Fourier expansion procedure. However, I will skip it since it's similar to the one we will prove later at the third proof.\n\\end{remark}\n~\\\\\n\n\nUsing the Parseval's equality\n\\[\n    \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}f(x)^2dx = \\frac{1}{2}a_{0}^2+\\sum_{n=1}^{\\infty}(a_n^2+b_n^2)\n\\]\n\\[\n    \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}x^2~dx=\\sum_{k=1}^\\infty\\frac{4}{n^2}\n\\]~\\\\\n\n\nUsing \n\\[\n    \\frac{1}{\\pi}\\int_{-\\pi}^{\\pi}x^2~dx = \\frac{2\\pi^2}{3}\n\\]\nWe can prove the identity.\n\\[\n    \\sum_{n=1}^\\infty\\frac{1}{n^2}=\\frac{\\pi^2}{6}\n\\]~\\\\\n\\begin{remark}\n    This was the proof which was suggested by the teacher at class. The concept of Fourier expansion is somehow complicated. However, after understanding it, the proof is very easy to follow. Also, we can get the infinite sum $\\sum_{n=1}^\\infty\\frac{1}{n^4}$ using the expansion of $f(x)=x^2$, via the same procedure.\n\\end{remark}\n\n\\newpage\n\\section{Proof using the Taylor series of $\\arctan x$~}\nThe Taylor series of the inverse tangent function is\n\\[\n    \\arctan x = \\sum_{n=1}^\\infty(-1)^n\\frac{x^{2n+1}}{2n+1}\n\\]\nSubstituting $x = 1$, we can get the Gregory's formula\n\\[\n    \\frac{\\pi}{4}=\\sum_{n=1}^\\infty\\frac{(-1)^n}{2n+1} = \\frac{1}{1} - \\frac{1}{3} + \\frac{1}{5} - \\cdots\n\\]\n~\\\\\n\nRewriting the formula as $\\lim_{N\\rightarrow\\infty}a_N=\\frac{\\pi}{2}$ where\n\\[\n    a_N = \\sum_{n=-N}^{N}\\frac{(-1)^n}{2n+1}\n\\]\nLet\n\\[\n    b_N = \\sum_{n=-N}^{N}\\frac{1}{(2n+1)^2}\n\\]\nSo, $\\lim_{N\\rightarrow\\infty}b_N=\\frac{\\pi^2}{4}$ is consist with \\eqref{eq:2}, which is the identity we want to prove. So, we shall show that $\\lim_{N\\rightarrow\\infty}(a_N^2-b_N)=0$~\\\\\n\nIf $n \\neq m$ then\n\\[\n    \\frac{1}{(2n+1)(2m+1)}=\\frac{1}{2(m-n)}(\\frac{1}{2n+1} - \\frac{1}{2m+1})\n\\]\nand so\n\n\\begin{equation}\n\\begin{split}\na_N^2-b_N~\n={}& ~{\\sum_{n=-N}^{N}\\sum_{m=-N}^{N}}^\\prime \\frac{(-1)^{m+n}}{2(m-n)}(\\frac{1}{2n+1} - \\frac{1}{2m+1})\\\\\n={}& ~{\\sum_{n=-N}^{N}\\sum_{m=-N}^{N}}^\\prime \\frac{(-1)^{m+n}}{(2n+1)(m-n)}\\\\\n={}& ~\\sum_{n=-N}^{N}\\frac{(-1)^{n} c_{n,N}}{(2n+1)} \\nonumber\n\\end{split}\n\\end{equation}\nwhere the prime on the summations means that the terms with zero denominators, where $n=m$ are omitted, and\n\\[\n    c_{n,N}={\\sum_{m=-N}^{N}}^\\prime \\frac{(-1)^{m}}{(m-n)}\n\\]\n\nIt is obvious that $c_{-n,N}=-c_{n,N}$ and $c_{0,N}=0$. For $n > 0$,\n\\[\n    c_{n,N}=(-1)^{n+1}\\sum_{j=N-n+1}^{N+n}\\frac{(-1)^j}{j}\n\\]\nwhich means that $|c_{n,N}| \\leq \\frac{1}{N-n+1}$ since the magnitude of an converging altering sum is smaller than that of the first term. Hence\n\\begin{equation}\n\\begin{split}\n|a_N^2-b_N| ~\\leq{}& ~\\sum_{n=1}^N(\\frac{1}{(2n-1)(N-n+1)} + \\frac{1}{(2n+1)(N-n+1)})\\\\\n={}& ~\\sum_{n=1}^N\\frac{1}{2N+1}(\\frac{2}{(2n-1)} + \\frac{1}{(N-n+1)})\\\\\n{}& ~+ \\sum_{n=1}^N\\frac{1}{2N+3}(\\frac{2}{(2n+1)} + \\frac{1}{(N-n+1)})\\\\\n\\leq{}& ~\\frac{1}{2N+1}(2+4\\log(2N+1)+2+2log(N+1)) \\nonumber\n\\end{split}\n\\end{equation}\nand so $\\lim_{N\\rightarrow\\infty}(a_N^2-b_N)=0$ as required.~\\\\\\\\\n\n\\section*{Ending the journey}\nWe could prove the Basel problem using various methods using the Fourier series of $x$ or the Taylor series of $\\arcsin x$ and $\\arctan x$. Although it seems enough, there are plenty more proofs for the Basel problem outside the world. I'm afraid that the journey ends here, but however I could realize that the knowledge of math diverges to infinity.~\\\\\n\n\n\\vspace{4.5cm}\n\\begin{figure}[H]\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{l}\n\\hline\n\\textbf{~~~이 보고서는 2021년 수학세미나 자율보고서로 작성되었을지도 모릅니다.~~~}\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\\end{figure}\n", "meta": {"hexsha": "678da246595bce6acdb5bd7bfcdd4407accf7550", "size": 9032, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "gshs_report_mini/main.tex", "max_stars_repo_name": "gshslatexintro/gshs-format", "max_stars_repo_head_hexsha": "50579f71c26826bdc216e97aeaa246dd49a1ea86", "max_stars_repo_licenses": ["LPPL-1.3c"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2018-08-13T00:07:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-14T07:45:01.000Z", "max_issues_repo_path": "gshs_report_mini/main.tex", "max_issues_repo_name": "gshslatexintro/gshslatexintro", "max_issues_repo_head_hexsha": "50579f71c26826bdc216e97aeaa246dd49a1ea86", "max_issues_repo_licenses": ["LPPL-1.3c"], "max_issues_count": 18, "max_issues_repo_issues_event_min_datetime": "2015-08-26T01:43:29.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-26T07:27:25.000Z", "max_forks_repo_path": "gshs_report_mini/main.tex", "max_forks_repo_name": "gshslatexintro/gshs-format", "max_forks_repo_head_hexsha": "50579f71c26826bdc216e97aeaa246dd49a1ea86", "max_forks_repo_licenses": ["LPPL-1.3c"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2018-06-27T23:57:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T10:56:31.000Z", "avg_line_length": 36.128, "max_line_length": 354, "alphanum_fraction": 0.6174712135, "num_tokens": 3760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7646467881861287}}
{"text": "\\chapter{Mixture models and EM}\n\\label{chap:EM}\n\n\\section{Introduction}\nIf we define a joint distribution over observed and latent variables,the corresponding distribution of the observed variables alone is marginalization.Mixture distributions can be interpreted in terms of discrete latent variables.As well as providing framework for building more complex probability distributions,mixture models can also be used to cluster data.\n\n\\section{$K$-means Clusetering}\n\\subsection{representation}\nSuppose we have a data set $\\{\\vec{x}_1,...,\\vec{x}_N\\}$ consisting of $N$ observations of a random $D$-dimensional Euclidean variable $\\vec{x}$.Our goal is to partition the data set into some number $K$ of clusters.First introduce a set of $D$-dimensional vectors $\\vec{\\mu}_k$,where $k=1,...,K$,in which $\\vec{\\mu}_k$ is a prototype associated with the $k^{th}$ cluster,representing the centers of the clusters.\n\nOur goal is then to find an assignment of data points to clusters,as well as a set of vectors $\\{\\vec{\\mu}_k\\}$,such that the sum of squares of the distances of each data point to its closest vector $\\vec{\\mu}_k$,is a minimum.\n\nA corresponding set of binary indicator variables $r_{nk}\\in \\{0,1\\}$,describing which of the $K$ clusters the data point $\\vec{x}_n$ is assigned to,so that if data point $\\vec{x}_n$ is assigned to cluster $k$ then $r_{nk}=1$,and $r_{nj}=0$ for $j\\neq k$.This is the 1-of-$K$ coding scheme.\n\n\n\\subsection{evaluation}\nDefine the objective function,sometimes called a \\textbf{distortion measure} as\n\\begin{equation}\nJ=\\sum_{n=1}^{N}\\sum_{k=1}^{K}r_{nk}\\parallel \\vec{x}_n-\\vec{\\mu}_k\\parallel^2\n\\end{equation}\n\n\\subsection{optimization}\nOur goal is to find value for the $\\{r_{nk}\\}$ and the $\\{\\vec{\\mu}_k\\}$ so as to minimize $J$.We can do this through an iterative procedure in which each iteration involves two successive steps corresponding to successive optimizations with respect to the $r_{nk}$ and the $\\vec{\\mu}_k$,which can be interpreted as parameters of each cluster's probability distribution.\n\nConsider first the determination of the $r_{nk}$,which can be interpreted as likelihood function of each cluster.We simply assign the $n^{th}$ data point to the closest cluster centre.\n\\begin{equation}\nr_{nk} = \\begin{cases}\n1,\\text{if }k=\\arg\\min_j\\parallel \\vec{x}_n-\\vec{\\mu}_j\\parallel^2 \\\\\n0,\\text{otherwise} \\\\\n\\end{cases}\n\\end{equation}\nNote that\n\\begin{align}\n\\arg\\min_j\\parallel \\vec{x}_n-\\vec{\\mu}_j\\parallel^2\n&= \\arg\\min_j(\\parallel \\vec{x}_n\\parallel ^2-2\\parallel \\vec{x}_n\\parallel\\parallel \\vec{\\mu}_j\\parallel + \\parallel\\vec{\\mu}_j\\parallel^2)  \\\\\n&=\\arg\\min_j(-2\\parallel \\vec{x}_n\\parallel\\parallel \\vec{\\mu}_j\\parallel + \\parallel\\vec{\\mu}_j\\parallel^2)   \\\\\n&=\\arg\\max_j(\\vec{x}_n^T\\vec{\\mu}_j-\\dfrac{\\vec{\\mu}_j^T\\vec{\\mu}_j}{2})\n\\end{align}\nNow consider the optimization of the $\\vec{\\mu}_k$ with the $_{nk}$ held fixed.Setting the objective function $J$'s derivative with respect to $\\vec{\\mu}_k$ to zero giving:\n\\begin{align}\n\t\\nabla_{\\vec{\\mu}_k} J\n\t&=2\\sum_{n=1}^{N}r_{nk}(\\vec{x}_n-\\vec{\\mu}_k)=0 \\\\\n\t\\Rightarrow \n\t\\vec{\\mu}_k &=\\dfrac{\\sum_n{r_{nk}\\vec{x}_n}}{\\sum_n{r_{nk}}} \\\\\n\t\\Rightarrow\n\t\\vec{\\mu}_k^T &= \\dfrac{\\sum_n{r_{nk}\\vec{x}_n^T}}{\\sum_n{r_{nk}}}\n\\end{align}\nwhich can be vectorized when implementing.\n\n\\begin{algorithm}[H]\n\t\\caption{{\\sc K-means} coordinate descent}\n\t\\label{algo:K-means}\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\\}$}\n\t\\KwOut{$\\{r_{nk}\\}$ and the $\\{\\vec{\\mu}_k\\}$ such that $J$ is minimized.}\n\t initialize $\\vec{\\mu}_k$\\;\n\t\\Repeat{converged}{\n\t\t%$C \\gets \\emptyset$\\;\n\t\tE(expectation).Minimize $J$ with respect to the $r_{nk}$.$r_{nk} = \\begin{cases}\n\t\t\t1,\\text{if $k=\\arg\\min_j\\parallel \\vec{x}_n-\\vec{\\mu}_j\\parallel^2$ } \\\\\n\t\t\t0,\\text{otherwise} \\\\\n\t\t\\end{cases}$,keeping $\\vec{\\mu}_k$ fixed \\;\n\t\tM(maximization).Minimize $J$ with respect to the $\\vec{\\mu}_k$:\n\t\t$\\vec{\\mu}_k=\\sum_n r_{nk}\\vec{x}_n \\over \\sum_n r_{nk}$,keeping $r_{nk}$ fixed.\\;\n \t}\n\n\\end{algorithm}\n\nThe objective may converge to a local rather than global minimum(MacQueen 1967).\n\nDerive an on-line stochastic rather than the batch version of $K$-means,by applying Robbin-Monro procedure :\n\\begin{align}\n\\vec{\\mu}_k^{new} = \n\\vec{\\mu}_k^{old} + \\eta_n(\\vec{x}_n-\\vec{\\mu}_k^{old})\n\\end{align}\nwhere $\\eta_n$ is the learning rate parameter,which is typically made to decrease monotonically as more data points are considered.\n\nGeneralize the $K$-means algorithm,introducing a general dissimilarity measure $\\nu(\\vec{x},\\vec{x}')$\n\\begin{align}\n\\hat{J} = \\sum_{n=1}^{N}\\sum_{k=1}^{K}r_{nk}\\nu(\\vec{x}_n,\\vec{\\mu}_k)\n\\end{align}\nwhich gives the \\textbf{$K$-medoids} algorithm.The computation cost of E step is $O(KN)$.The M step is potentially more complex.So it is common to restrict each cluster prototype to be equal to one of the data vectors assigned to that cluster,requiring $O(N_k^2)$ evaluations of $\\nu(\\cdot,\\cdot)$.\n\n\\section{Mixtures of Gaussians}\n\\subsection{representation}\nThe Gaussian mixture distribution can be written as a linear superposition of Gaussians in the form\n\\begin{align}\\label{def:Gaussian mixture}\np(\\vec{x}) =\n\\sum_{k=1}^{K}\\pi_k\\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k)\n\\end{align}\nIntroduce a $K$-dimensional binary random variable $\\vec{z}$ having a $1$-of-$K$ representation.\n\\begin{align}\nz_k &\\in \\{ 0,1\\} \\\\\n\\sum_k z_k &=1\n\\end{align}\nThe marginal distribution over $\\vec{z}$ is specified in terms of the mixing coefficients $\\pi_k$,such that\n\\begin{align}\np(z_k=1) = \\pi_k\n\\end{align}\nwhere the parameters $\\{ \\pi_k\\}$ must satisfy\n\\begin{align}\n0 \\leq &\\pi_k \\leq 1\\\\\n\\sum_{k=1}^{K} &\\pi_k = 1\n\\end{align}\nWrite this distribution in the form\n\\begin{align}\np(\\vec{z}) = \\prod_{k=1}^{K}\\pi_k^{z_k}\n\\end{align}\nThe conditional distribution of $\\vec{x}$ given a particular value for $\\vec{z}$ is a Gaussian:\n\\begin{align}\np(\\vec{x}|z_k=1) &= \\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k) \\\\\np(\\vec{x}|\\vec{z}) \n&=\\prod_{k=1}^{K}\\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k)^{z_k}\n\\end{align}\nThe joint distribution is given by $p(\\vec{z})p(\\vec{x}|\\vec{z})$,and the marginal distribution of $\\vec{x}$ is obtained by summing the joint distribution over states of $\\vec{z}$:\n\\begin{align}\np(\\vec{x}) = \\sum_{\\vec{z}}{p(\\vec{z})p(\\vec{x}|\\vec{z})} =\n\\sum_{k=1}^{K}\\pi_k\\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k)\n\\end{align}\nwhich is a Gaussian mixture \\ref{def:Gaussian mixture} .\n\nThe conditional probability of $\\vec{z}$ given $\\vec{x}$ can be evaluated by Bayes' theorem\n\\begin{align}\n\\label{eqn:responsibility}\n\\gamma(z_k)\\equiv p(z_k=1|\\vec{x}) \n&=\\dfrac{p(z_k=1)p(\\vec{x}|z_k=1)} {\\sum_{j=1}^{K}p(z_j=1)p(\\vec{x}|z_j=1)} \\\\\n&=\\dfrac{\\pi_k \\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}  \n\t{\\sum_{j=1}^{K}\\pi_j\\mathcal{N}(\\vec{x}|\\vec{\\mu}_j,\\vec{\\Sigma}_j)}\n\\end{align}\nWe shall view $\\pi_k$ as the prior probability of $z_k=1$,and the quantity $\\gamma(z_k)$ as the corresponding posterior.$\\gamma(z_k)$ can also be viewed as the \\textbf{responsibility} that component $k$ takes for 'explaining' the observation $\\vec{x}$.\n\n\\subsection{Maximum likelihood}\nAssuming that the data points are drawn independently from the same distribution(i.i.d),the log of the likelihood function is given by\n\\begin{align}\\label{eqn:Gaussian mixture log likelihood}\n\\ln(p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})) =\n\\sum_{n=1}^{N}\\ln\\{\\sum_{k=1}^{K}\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k) \\}\n\\end{align}\n\nIt is worth emphasizing that there are significant problems associated with the maximum likelihood framework applied to GMM,due to the presence of \\textbf{singularities}.If one of the components of the mixture model 'collapse' onto a specific data point($\\sigma_j\\rightarrow 0$),the log likelihood function will go to infinity.These singularities provide another example of severe over-fitting of maximum likelihood approach.A further issue is \\textbf{identifiability}(Casella and Berger,2002),which is that a $K$-component mixture results in $K!$ equivalent solutions.\n\n\\subsection{EM for Gaussian mixtures}\nAn elegant and powerful method for finding the maximum likelihood solutions for models with latent variables is called the \\textbf{expectation-maximization},or EM algorithm.\n\nBegin by writing down the conditions that must be satisfied at a maximum of the likelihood function.Setting the derivatives of $\\ln p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})$ \\ref{eqn:Gaussian mixture log likelihood} with respect to the means $\\vec{\\mu}_k$ of the Gaussian components to zero,we obtain\n\\begin{align}\n\\because 0&=-\\sum_{n=1}^{N}\\dfrac{\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}\n{\\sum_{j=1}^{K}\\pi_j\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_j,\\vec{\\Sigma}_j)}\n\\vec{\\Sigma}_k^{-1}(\\vec{x}_n-\\vec{\\mu}_k) \\\\\n\\therefore 0&=-\\sum_{n=1}^{N}\\gamma(z_{nk})(\\vec{x}_n-\\vec{\\mu}_k) \\\\\n\\because\nN_k&=\\sum_{n=1}^{N}\\gamma(z_{nk}) \\\\\n\\therefore \\vec{\\mu}_k&=\\dfrac{1}{N_k}\\sum_{n=1}^{N}\\gamma(z_{nk})\\vec{x}_n \\\\\n\\end{align}\nwhere we have made use of $\\dfrac{de^x}{dx}=e^x$ and \\ref{eqn:multivariate Gaussian}.We can interpret $N_k$ as the effective number of points assigned to cluster $k$.\n\nNow set the derivative of $\\ln(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})$ with respect to $\\vec{\\Sigma}_k$ to zero:\n\\begin{align}\n\\dfrac{\\partial\\ln p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})}{\\partial\\vec{\\Sigma}_k} \n&=\\sum_{n=1}^{N}\\dfrac{\\dfrac{\\partial(\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k))}{\\partial\\vec{\\Sigma}_k}}\n{\\sum_{j=1}^{K}\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}\\\\\n\\because\n \\dfrac{\\partial \\ln y}{\\partial x} &= \\dfrac{1}{y}\\dfrac{\\partial y}{\\partial x} \\\\\n\\therefore \\dfrac{\\partial y}{\\partial x} &= y\\dfrac{\\partial\\ln y}{\\partial x}\\\\\n\\because \\dfrac{\\partial(\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k))}{\\partial\\vec{\\Sigma}_k} \n&= \\pi_k\\dfrac{\\partial\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}{\\partial\\vec{\\Sigma}_k}\\\\\n&= \\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)\n\\dfrac{\\partial\\ln\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}{\\partial\\vec{\\Sigma}_k}\\\\\n\\because \n\\mathcal{N}(\\vec{x}|\\vec{\\mu},\\vec{\\Sigma})\n&=\\dfrac{1}{(2\\pi)^{D/2}}\\dfrac{1}{\\mid \\vec{\\Sigma}\\mid^{1/2}}\n\\exp\\{-\\dfrac{1}{2}(\\vec{x}-\\vec{\\mu})^T\\vec{\\Sigma}^{-1}(\\vec{x}-\\vec{\\mu}) \\} \\\\\n\\therefore \\dfrac{\\partial\\ln\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}{\\partial\\vec{\\Sigma}_k}\n&=-\\dfrac{1}{2}(\\dfrac{\\ln(\\mid\\vec{\\Sigma}_k)\\mid}{\\partial\\vec{\\Sigma}_k}\n +\\dfrac{\\partial(\\vec{x}_n-\\vec{\\mu}_j)\\vec{\\Sigma}^{-1}(\\vec{x}_n-\\vec{\\mu}_j)}{\\partial\\vec{\\Sigma}_k}) \\\\\n\\because\n \\dfrac{\\partial det(\\vec{X})}{\\vec{X}} &=det(\\vec{X})(\\vec{X}^{-1})^T \\\\\n\\dfrac{\\partial\\vec{a}^T\\vec{X}^{-1}\\vec{b}}{\\partial\\vec{X}}\n&= -\\vec{X}^{-T}\\vec{a}\\vec{b}^T\\vec{X}^{-T} \\\\\n\\therefore \n\\dfrac{\\ln(\\mid\\vec{\\Sigma}_k)\\mid}{\\partial\\vec{\\Sigma}_k}\n&=\\dfrac{\\dfrac{\\partial\\mid\\vec{\\Sigma}_k\\mid}{\\partial\\vec{\\Sigma}_k}}{\\mid\\vec{\\Sigma}_k\\mid} =\\dfrac{\\mid\\vec{\\Sigma}_k\\mid\\vec{\\Sigma}_k^{-T}}{\\mid\\vec{\\Sigma}_k\\mid} =\\vec{\\Sigma}_k^{-1}\\\\\n\\therefore \n\\dfrac{\\partial\\ln\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}{\\partial\\vec{\\Sigma}_k} \n&=-\\dfrac{1}{2}(\\vec{\\Sigma}_k^{-1}-\\vec{\\Sigma}_k^{-1}(\\vec{x}_n-\\vec{\\mu}_k)(\\vec{x}_n-\\vec{\\mu}_k)^T\\vec{\\Sigma}_k^{-1}) \\\\\n\\therefore derivative&=\\sum_{n=1}^{N}\\gamma(z_{nk})(-1/2)[\\vec{\\Sigma}_k^{-1}-\\vec{\\Sigma}_k^{-1}(\\vec{x}_n-\\vec{\\mu}_k)(\\vec{x}_n-\\vec{\\mu}_k)^T\\vec{\\Sigma}_k^{-1}] =0 \\\\\n\\therefore \\vec{\\Sigma}_k&=\\dfrac{1}{N_k}\\sum_{n=1}^{N}\\gamma(z_{nk})(\\vec{x}_n-\\vec{\\mu}_k)(\\vec{x}_n-\\vec{\\mu}_k)^T\n\\end{align}\nwhere we have made use of \\ref{eqn:multivariate Gaussian} and \\textbf{The Matrix Cookbook,2012}.\n\nFinally,we maximize $\\ln p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})$ \\ref{eqn:Gaussian mixture log likelihood} with respect to the mixing coefficients $\\pi_k$.Achieve this using a Lagrange multiplier\n\\begin{align}\n\\ln p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma}) +\\lambda(\\sum_{k=1}^{K}\\pi_k-1) &=0 \\\\\n\\therefore \\sum_{n=1}^{N}\\dfrac{\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k)}\n{\\sum_{j=1}^{K}\\pi_j\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_j,\\vec{\\Sigma}_j)} +\\lambda &= 0\n\\end{align}\nwhere again we see the appearance of the responsibilities \\ref{eqn:responsibility}.If we now multiply both sides by $\\pi_k$ and sum over $k$ making use of constraint $\\sum_{k=1}^{K}\\pi_k = 1$,we find $\\lambda = -N$.Then \n\\begin{align}\n\\pi_k = \\dfrac{N_k}{N}\n\\end{align}\nThere do suggest s ample iterative scheme for finding a solution to the maximum likelihood problem.\n\n\\begin{algorithm}[H]\n\t\\caption{EM for Gaussian Mixtures}\n\t\\label{algo:Gaussian Mixtures}\n\t\\DontPrintSemicolon\n\t\\Repeat{\\text{convergence of either the parameters or the log likelihood}}{\n\t\t1.Initialize the means $\\vec{\\mu}_k$,covariances $\\vec{\\Sigma}_k$ and mixing coefficients $\\pi_k$,and evaluate the initial value of the log likelihood\\;\n\t\t2.\\textbf{E step}.Evaluate the responsibilities using the current parameter values\n\t\t\\begin{align}\n\t\t\\gamma(z_k)\\equiv p(z_k=1|\\vec{x}) \n\t\t&={p(z_k=1)p(\\vec{x}|z_k=1) \\over \\sum_{j=1}^{K}p(z_j=1)p(\\vec{x}|z_j=1)} \\\\\n\t\t&={\\pi_k \\mathcal{N}(\\vec{x}|\\vec{\\mu}_k,\\vec{\\Sigma}_k) \\over \n\t\t\\sum_{j=1}^{K}\\pi_j\\mathcal{N}(\\vec{x}|\\vec{\\mu}_j,\\vec{\\Sigma}_j)}\n\t\t\\end{align} \\;\n\t\t3. \\textbf{M step}. Re-estimate the parameters using the current responsibilities\n\t\t\\begin{align}\n\t\t\\vec{\\mu}_k^{new} &= \\dfrac{1}{N_k}\\sum_{n=1}^{N}\\gamma(z_{nk})\\vec{x}_n \\\\\n\t\t\\vec{\\Sigma}_k^{new} &=\\dfrac{1}{N_k}\\sum_{n=1}^{N}\\gamma(z_{nk})(\\vec{x}_n-\\vec{\\mu}_k)(\\vec{x}_n-\\vec{\\mu}_k)^T \\\\\n\t\t\\pi_k^{new}&= \\dfrac{N_k}{N}\n\t\t\\end{align}\\;\n\t\twhere \n\t\t\\begin{align}\n\t\tN_k&=\\sum_{n=1}^{N}\\gamma(z_{nk})\n\t\t\\end{align}\n\t\t4. Evaluate the log likelihood\n\t\t\\begin{align}\n\t\t\\ln(p(\\vec{X}|\\vec{\\pi},\\vec{\\mu},\\vec{\\Sigma})) =\n\t\t\\sum_{n=1}^{N}\\ln\\{\\sum_{k=1}^{K}\\pi_k\\mathcal{N}(\\vec{x}_n|\\vec{\\mu}_k,\\vec{\\Sigma}_k) \\}\n\t\t\\end{align}\\;\n\t}\n\\end{algorithm}\n\n\\section{Latent Variables View of EM}\n\\subsection{representation}\nWe denote the set of all observed data by $\\vec{X}$,in which the $n^{th}$ row represents $\\vec{x}_n^T$,and denote the set of all latent variables by $\\vec{Z}$,with corresponding rows $\\vec{z}_n^T$.The set of all model parameters is denoted by $\\vec{\\theta}$,so the log likelihood function is given by\n\\begin{align}\n\\ln p(\\vec{X}|\\vec{\\theta}) &=\n\\ln\\{\\sum_{\\vec{z}}p(\\vec{X},\\vec{Z}|\\vec{\\theta}) \\}\n\\end{align}\nReplace the sum over $\\vec{Z}$ with an integral for continuous latent variables.\n\n$\\{\\vec{X},\\vec{Z}\\}$ is called the \\textbf{complete} data set,and $\\{\\vec{X}\\}$ is \\textbf{incomplete}.We consider complete-data log likelihood functions' expected value under the posterior distribution of the latent variables,corresponding to the E step.In the subsequent M step,maximize this expectation.The expectation of complete-data log likelihood\n\\begin{align}\n\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old}) &=\n\\sum_{\\vec{z}}p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta})\n\\end{align}\nMaximize this\n\\begin{align}\n\\vec{\\theta}^{new} &=\\arg\\max\\limits_{\\vec{\\theta}}\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old})\n\\end{align}\n\\begin{algorithm}[H]\n\t\\label{General EM algorithm}\n\t\\caption{General EM algorithm}\n\t\\DontPrintSemicolon\n\t\\KwIn{$p(\\vec{X},\\vec{Z}|\\vec{\\theta})$,$\\vec{Z}$}\n\t\\KwOut{output}\n\t\\Repeat{converged}{\n\t\t1. Choose an initial setting for the parameters $\\vec{\\theta}^{old}$.\\;\n\t\t2. \\textbf{E step} Evaluate $p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})$.\\;\n\t\t3. \\textbf{M step} Evaluate $\\vec{\\theta}^{new}$ given by\n\t\t\\begin{align}\n\t\t\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old}) &=\n\t\t\\sum_{\\vec{z}}p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta})\n\t\t\\end{align}\n\t\twhere\n\t\t\\begin{align}\n\t\t\\vec{\\theta}^{new} &=\\arg\\max\\limits_{\\vec{\\theta}}\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old})\n\t\t\\end{align} \\;\n\t\t4. \n\t\t\\begin{align}\n\t\t\\vec{\\theta}^{old} \\gets \\vec{\\theta}^{new}\n\t\t\\end{align}\n\t}\n\\end{algorithm}\nWhen finding MAP(maximum posterior) solutions,maximize the quantity $\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old})+\\ln p(\\vec{\\theta})$ in M step.\n\n\\section{The EM Algorithm in General}\nThe \\textbf{expectation maximization} algorithm,or EM,is a general technique for finding maximum likelihood solutions for probabilistic models having latent variables.\n\nGiven the same setting as previous,our goal is to maximize the likelihood function\n\\begin{align}\np(\\vec{X}|\\vec{\\theta}) &=\\sum_{\\vec{Z}}p(\\vec{X},\\vec{Z}|\\vec{\\theta}) \n\\end{align}\nReplace the summation by integration as appropriate to apply to continuous latent variables.\n\nIntroduce a distribution $q(\\vec{Z})$ over the latent variables,and the decompose the log complete-data likelihood function\n\\begin{align}\n\\because \\ln p(\\vec{X}|\\vec{\\theta}) &=\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta}) -\\ln p(\\vec{Z}|\\vec{X},\\vec{\\theta}) \\\\\n\\end{align}\ntake the expectation over values of $\\vec{Z}$ by multiplying both sides by $q(\\vec{Z})$ and summing(or integrting) over $\\vec{Z}$ we get\n\\begin{align}\n\\ln p(\\vec{X}|\\vec{\\theta}) \n&=\\sum_{\\vec{Z}}q(\\vec{Z})\\ln p(\\vec{X}|\\vec{\\theta}) \\\\\n&=\\sum_{\\vec{Z}}q(\\vec{Z})\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta})-\\sum_{\\vec{Z}}q(\\vec{Z})\\ln p(\\vec{Z}|\\vec{X}) \\\\\n&=\\sum_{\\vec{Z}}q(\\vec{Z})(\\ln \\dfrac {p(\\vec{X},\\vec{Z})}{p(\\vec{Z})}+\\ln p(\\vec{Z}))-\\sum_{\\vec{Z}}q(\\vec{Z})\\ln p(\\vec{Z}|\\vec{X}) \\\\\n&=Q+H \\\\\n&=\\mathcal{L}(q,\\vec{\\theta})+KL(q\\parallel p)\n\\end{align}\nwhere\n\\begin{align}\\label{eqn:complete-data log likelihood decomposition}\n\\mathcal{L}(q,\\vec{\\theta})\n&=\\sum_{\\vec{Z}}q(\\vec{Z})\\ln\n\\{\\dfrac{p(\\vec{X},\\vec{Z}|\\vec{\\theta})}{q(\\vec{Z})} \\} \\\\\nKL(q\\parallel p)\n&=-\\sum_{\\vec{Z}}{q(\\vec{Z})\\ln\n\t\\{\\dfrac{p(\\vec{Z}|\\vec{X},\\vec{\\theta})}\n\t\t {q(\\vec{Z})}\\}}\n\\end{align}\nNote that $\\mathcal{L}(q,\\vec{\\theta})$ is a functional of the distribution $p(\\vec{Z})$ and KL is the Kullback-Leibler divergence between $q(\\vec{Z})$ and the posterior $p(\\vec{Z}|\\vec{X},\\vec{\\theta})$.KL divergence will be nonnegative according to Jenson's inequality about convex function.\n\\begin{align}\n\\because KL(q\\parallel q)&\\geq,\\text{with equality if,and only if,}q(\\vec{Z})=p(\\vec{Z}|\\vec{X},\\vec{\\theta})\\\\\n\\therefore\n\\mathcal{L}\t(q,\\vec{\\theta})&\\leq\\ln p(\\vec{X}|\\vec{\\theta})\n\\end{align}\nin other words that $\\mathcal{L}(q,\\vec{\\theta})$ is a lower bound on $\\ln p(\\vec{X}|\\vec{\\theta})$.\n\nThe EM is a two-stage \\textbf{iterative} optimization technique for finding \\textbf{maximum likelihood} solutions.With the decomposition \\ref{eqn:complete-data log likelihood decomposition},\nin the E step,the \\textbf{lower bound} $\\mathcal{L}(q,\\vec{\\theta}^{old})$ is maximized with respect to $q(\\vec{Z})$ holding $\\vec{\\theta}^{old}$ fixed.\n\nIn the subsequent M step,the distribution $q(\\vec{Z})$ is held fixed and the lower bound $\\mathcal{L}(q,\\vec{\\theta})$ is maximized with respect to $\\vec{\\theta}$.The nonzero KL divergence causes the log likelihood function increase more than the lower bound,as shown in figure\\begin{SCfigure}\n\t\\centering\n\t\\caption{Illustration of the M step of the EM\n\t\talgorithm. The distribution $q(\\vec{Z})$\n\t\tis held fixed and the lower bound\n\t\t$\\mathcal{L}(q,\\vec{\\theta})$ is maximized with respect\n\t\tto the parameter vector $\\vec{\\theta}$ to give\n\t\ta revised value $\\vec{\\theta}^{new}$. Because the\n\t\tKL divergence is nonnegative, this\n\t\tcauses the log likelihood ln p(X|θ)\n\t\tto increase by at least as much as\n\t\tthe lower bound does}\n\t\\includegraphics{prml/Figure9.13.jpg}\n\\end{SCfigure}\n\nSubstitute $q(\\vec{Z}) = p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})$ into the lower bound,then after the E step,\n\\begin{align}\n\\mathcal{L}(q,\\vec{\\theta}) \n&= \\sum_{\\vec{Z}}p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta})\n\t-\\sum_{\\vec{Z}}p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old})\\ln p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{old}) \\\\\n&= \\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{old})\t + const\n\\end{align}\nwhere the constant is the negative entropy of the $q$ distribution.\n\\begin{SCfigure*}\n\t\\caption{The EM algorithm involves alternately computing a lower bound on the log likelihood for the current parameter values and then maximizing this bound to obtain the new parameter values.The \\color{red} red curve depicts the incomplete-data log likelihood function to maximize.\\color{blue} curve where its value equals the log likelihood at $\\vec{\\theta}^{old}$ indicates the E step.In the M step,the lower bound is maximized giving $\\vec{\\theta}^{new}$.The \\color{green} shows the subsequent E step,constructing a tangential bound at $\\vec{\\theta}^{new}$ }\n\t\\includegraphics{prml/Figure9.14.jpg}\n\\end{SCfigure*}\n\nFor the particular case of independent,identically distributed data set,$\\vec{X}=(\\vec{x}_1^T,\\vec{x}_2^T,\\cdots,\\vec{x}_n^T)^T$ and $\\vec{Z}=(\\vec{z}_1^T,\\vec{z}_2^T,\\cdots,\\vec{z}_n^T)^T$.Using the sum and product rules,the posterior in E step take the form\n\\begin{align}\np(\\vec{Z}|\\vec{X},\\vec{\\theta}) &= \\dfrac{p(\\vec{X},\\vec{Z}|\\vec{\\theta})}{\\sum_{\\vec{Z}}p(\\vec{X},\\vec{Z}|\\vec{\\theta})}\n=\\dfrac{\\prod_{n=1}^{N}p(\\vec{x}_n,\\vec{z}_n|\\vec{\\theta})}{\\sum_{\\vec{Z}}\\prod_{n=1}^{N}p(\\vec{x}_n,\\vec{z}_n|\\vec{\\theta})}\n=\\prod_{n=1}^{N}p(\\vec{z}_n|\\vec{x}_n,\\vec{\\theta})\n\\end{align}\nwill also factorize with respect to $n$.\n\n\\subsection{Maximum posterior}\nMaximize the posterior distribution $p(\\vec{\\theta}|\\vec{X})$ with EM for models with a prior $p(\\vec{\\theta})$ over parameters.\n\\begin{align}\n\\because p(\\vec{\\theta}|\\vec{X})&=p(\\vec{\\theta},\\vec{X})/p(\\vec{X}) \\\\\n\\therefore \\ln p(\\vec{\\theta}|\\vec{X})&=\\ln p(\\vec{\\theta},\\vec{X})-\\ln p(\\vec{X})\n\t=\\ln p(\\vec{\\theta})+\\ln p(\\vec{X}|\\vec{\\theta})-\\ln p(\\vec{X})\n\\end{align}\ndecomposed as\n\\begin{align}\n\\ln p(\\vec{\\theta}|\\vec{X}) &= \\mathcal{L}(q,\\vec{\\theta})+KL(q\\parallel p) +\\ln p(\\vec{\\theta}) -\\ln p(\\vec{X})\\\\\n&\\geq \\mathcal{L}(q,\\vec{\\theta}) +\\ln p(\\vec{\\theta}) -\\ln p(\\vec{X})\n\\end{align}\nwhere $\\ln p(\\vec{X})$ is constant.We can optimize the right-hand side alternatively with respect to $q$ and $\\vec{\\theta}$ in E-step and M-step.\n\n\\subsection{generalized EM}\nThe \\textbf{generalized EM},or GEM,algorithm addresses the problem of an intractable M step.Instead of aiming to maximize $\\mathcal{L}(q,\\vec{\\theta})$ with respect to $\\vec{\\theta}$,it seeks instead to change the parameters in such a way as to increase its value.\n\\begin{itemize}\n\t\\item[1]Nonlinear optimization. conjugate gradients algorithm in M step\n\t\\item[2]expectation conditional maximization(ECM). Making several constrained optimizations within each M step.\n\\end{itemize}\n\nGeneralize the E step by performing a \\textbf{partial},rather than complete, optimization of $\\mathcal{L}(q,\\vec{\\theta})$ with respect to $q(\\vec{Z})$.\n\n\n\n\n\n", "meta": {"hexsha": "0f33fd8060322a3f6719b2683e72e0f6cd05bd0c", "size": 22695, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Mixture models and EM.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/Mixture models and EM.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/Mixture models and EM.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.2558746736, "max_line_length": 569, "alphanum_fraction": 0.6820885658, "num_tokens": 8000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391617003942, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.7646467876432106}}
{"text": "\\subsubsection*{Elementary Math \\hspace*{\\fill}\\hyperlink{ElementwiseOperations}{(up)}\n\\hypertarget{elementaryMath}{}}\\addcontentsline{toc}{subsubsection}{Elementary Math}\nElementary math functions constitute elementwise applications of elementary operations on \\ttbf{view}s. The term \\emph{elementary} is somewhat arbitrary but includes trigonometric functions, log functions, and exponential functions. Functions here (for elements) are defined by C 89 in the \\ttbf{math.h} header file. \\ttbf{JVSIP} generally uses this math library to do the calculations for these functions.\n\\begin{table}[H]\n\\caption{Elementary Math Functions}\n\\label{tab:elementaryMath}\n\\begin{center}\n\\begin{tabular}{|l|l|}\n\\hline\n\\hlnkFunc{acos} & Arccosine\\\\\n\\hlnkFunc{asin} & Arcsine\\\\\n\\hlnkFunc{atan} & Arctangent\\\\\n\\hlnkFunc{atan2} & Arctangent of Two Arguments\\\\\n\\hlnkFunc{cos} & Cosine\\\\\n\\hlnkFunc{cosh} & Hyperbolic Cosine\\\\\n\\hlnkFunc{exp} & Exponential\\\\\n\\hlnkFunc{exp10} & Exponential Base 10\\\\\n\\hlnkFunc{log} & Natural Log\\\\\n\\hlnkFunc{log10} & Base 10 Log\\\\\n\\hlnkFunc{sin} & Sine \\\\\n\\hlnkFunc{sinh} & Hyperbolic Sine\\\\\n\\hlnkFunc{sqrt} & Square Root\\\\\n\\hlnkFunc{tan} & Tangent\\\\\n\\hlnkFunc{tanh} & Hyperbolic Tangent\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n%\\label{default}\n\\end{table}%\n", "meta": {"hexsha": "2eb549bac8fac83af8a4328b280c3fa353c58b71", "size": 1265, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/jvsip_book/ElementaryMath.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/ElementaryMath.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/ElementaryMath.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": 42.1666666667, "max_line_length": 406, "alphanum_fraction": 0.757312253, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314617436728, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7646467767113685}}
{"text": "% &LaTeX\n\n\\section{Feedback Filters}\n\nBy the end of this lab you should feel comfortable manipulating and\nusing feedback filters for simple algorithms. You should also be\ncomfortable with the concept of a filter with an Infinite Impulse\nResponse (IIR). All feedback filters have an infinite impulse response\nand are also known as IIR filters. Feedback filters use the previous\noutputs of the filter, feeding them back into the output of the\ncurrent sample. The ``fed back'' outputs are weighted by coefficients,\n$a_\\ell$.\n\n\\subsection{Lab Background}\n\nNote that the J-DSP \\block{Coeff.} block uses \\emph{negative} values\nfor the $a_\\ell$ (feedback) coefficients. In other words, in the text,\na second-order feedback filter's defining equation might be:\n\\begin{align}\n  y[n] &= a_1 y[n-1] + a_2 y[n-2] + b_0 x[n] \\label{eq:def} \\\\\n  y[n] -a_1 y[n-1] - a_2 y[n-2]&=   b_0 x[n]\n\\end{align}\nThis yields the transfer function:\n\\begin{align}\n  Y(z)(1 - a_1 z^{-1} - a_2 z^{-2}) &= b_0X(z) \\\\\n  Y(z)/X(z) &= \\frac{b_0}{1 - a_1 z^{-1} - a_2 z^{-2}} \\\\\n  H(z) &= \\frac{b_0}{1 - a_1 z^{-1} - a_2 z^{-2}} \\label{eq:trans} \n\\end{align}\nHowever, in J-DSP, the coefficients used, rather than being the\n$a_\\ell$ from the defining equation~(\\ref{eq:def}) are the\n\\emph{negative $a_\\ell$} from the transfer\nfunction~(\\ref{eq:trans}). In other words, to properly define the above filter in J-DSP,\nyou will need to use the coefficients, $a[0]=1,a[1]=-a_1,a[2]=-a_2$, and $b[0]=b_0$. \nNote also that in this example the \\block{Coeff.} block has\nan $a[0]$ coefficient, which we will always leave as 1.0 (it's the\nfirst ``1'' in the denominator of the transfer function).\n\n\\subsection{Feedback Filters as Recurrence Relations}\n\nYou may notice that the defining equation for a feedback filter is in\nthe form of a recurrence relation. In fact, we can use a feedback\nfilter to implement a recurrence relation if we set the input to be\nan impulse, $x[n] = C \\delta[n]$, with amplitude $C$ being the initial\nvalue for the iteration. Let's start out with the Fibonacci sequence,\nwhich you'll remember to be:\n\\begin{equation}\n  F[n] = \\left\\{ \\begin{array}{ll}\n      1 & n < 2 \\\\\n      F[n-1] + F[n-2] & n \\geq 2\n    \\end{array} \\right.\n\\end{equation}\n\nWe can rewrite this recurrence relation as:\n\\begin{equation}\n  y[n] = y[n-1] + y[n-2] + x[n]\n  \\label{eq:fib}\n\\end{equation}\nand we will get the Fibonacci sequence \\emph{if} we input an impulse\n(hence, the appearance of the $x[n]$ on the right hand side, which\nserves only to initialize the filter). This is also a very good\ndemonstration of the first ``I'' in the acronym ``IIR'': the impulse\nresponse of this filter has infinite duration.\n\n\\paragraph{Step 1.1} If we set $x[n]=\\delta[n]$ in~(\\ref{eq:fib}), we\nshould see that the impulse response of this filter is indeed the\nFibonacci sequence. Implement this filter in J-DSP and verify that its\nimpulse response is the Fibonacci sequence. What are the values of the\ncoefficients in the \\block{Coeff.} block that you used?\n\n\n\\paragraph{Step 1.2} What is the value for $n=19$ given by the\n\\block{Plot} block?\n\n\n\\paragraph{Step 1.3} Is this filter stable?\n\n\n\\paragraph{Step 1.4} Let's do something similar with the recurrence\nrelation for computing the series $y[n] = 1/3^n$ in the text. Set the\ncoefficients for a feedback filter to implement equation~(5-42) in the\ntext, $y[n] = 1/3 y[n-1] + x[n]$. What are the J-DSP filter coefficients?\n\n\n\\paragraph{Step 1.5} What are the pole location(s) for this filter?\n\n\n\\paragraph{Step 1.6} Now use J-DSP to calculate the impulse repsonse.\nSet the amplitude of the input impulse to be 0.99996. Is this filter stable? \nIs its impulse response consistent with the result of iterating equation~(5-42) in the notes?\n\n\n\\subsection{Telephone Touch Tone Dialing}\nTelephone touch pads generate dual tone multi frequency (DTMF) signals\nto dial a telephone. When any key is pressed, the tones of the\ncorresponding column and row in the table below are generated, hence\nit is a ``dual tone'' code. As an example, pressing the 5 button\ngenerates the tones 770Hz and 1336Hz summed together.\n\n\\begin{center}\n  \\begin{tabular}{l|ccc}\n    & 1209Hz & 1336Hz & 1477Hz \\\\ \\hline\n    697Hz &   1    &   2    &   3    \\\\\n    770Hz &   4    &   5    &   6    \\\\\n    852Hz &   7    &   8    &   9    \\\\\n    941Hz &   $\\ast $    &   0    &   \\#    \n  \\end{tabular}\n\\end{center}\n\nThe frequencies in the table above were chosen to avoid harmonics. No\nfrequency is a multiple of another, the difference between any two\nfrequencies does not equal any of the frequencies, and the sum of any\ntwo frequencies does not equal any of the frequencies.\\footnote{More\n  information can be found at:\n  \\url{http://en.wikipedia.org/wiki/DTMF}} This makes it easier to\ndetect exactly which tones are present in the dial signal in the\npresence of line distortions.\n\nIt is possible to decode by first using a \\emph{filter bank} composed\nof seven bandpass filters, one for each of the frequencies\nabove. When a button is pressed, it will produce a combination of two\ntones, and thus, at the decoder end, two of the bandpass filters will\nproduce higher outputs than the others. A good measure of the output\nlevels is the average power at the filter outputs. This is calculated\nby squaring the filter outputs and averaging over a short time\ninterval.\n\n\\paragraph{Step 2.1} J-DSP has a \\block{DTMF Tones} block under the\n\\menu{Audio Effects} menu. You will use this as the input to your\ndecoder. It generates DTMF tones, as you would expect, with a sampling\nrate of 8kHz. You'll probably want to set \\block{DTMF Tones} to output\nfive frames per button press, so that the tones are long enough to\nhear well.  Convert the seven touch tone frequencies from Hz to\ndigital frequencies in the range $[0, \\pi]$.\n\n\n\\paragraph{Step 2.2} In this step, you will construct a bandpass\nfilter for the 697Hz tone. Use a feedback filter with complex\nconjugate poles. Place a pair of complex conjugate poles using the\n\\block{PZ Placement} block at the correct location for $\\pm$697Hz (for\nmanual entry, which is what you'll want to use, note that the phase\nangle is entered in degrees). Use equation~(5-38) of section~5.1.4 of\nthe text to set the radius of those poles so that the closest tone\nfrequency, 770Hz, lies outside the passband (in other words, to set\nthe bandwidth so that it is significantly smaller than twice the\ndifference between 697Hz and 770Hz). You can verify this using the\n\\block{Freq-Resp} block.\n\nWhat were your pole locations?\n\n\nVerify that the output for buttons \\button{1}, \\button{2}, and\n\\button{3} are pretty much identical, and that all other buttons\nproduce much lower amplitude output.  In your report, include a plot\nof the filter output for one of the buttons \\button{1}, \\button{2}, or\n\\button{3} and a plot for one of the buttons \\button{4}, \\button{5},\nor \\button{6}.\n\n\n\\paragraph{Step 2.3} Now we are ready to decide whether a particular\nfrequency is present. Run the filter output through a \\block{Square}\nblock (under the \\menu{Arithmetic} menu) and its output in turn\nthrough a \\block{Statistics} block (under the \\menu{Basic Blocks}\nmenu). Note that the \\block{Square} block has two inputs; make sure\nyou know which one you're using and that it has a \\option{Coefficient}\nof 1.0. Examine the mean of the squared signal as you press the\ndifferent \\block{DTMF Tones} buttons. You should see a much higher\nmean squared value for buttons \\button{1}, \\button{2}, and \\button{3}\nthan the others. Additionally, the mean squared values for those three\nbuttons should be almost identical. What are the mean squared values\nyou get for pressing \\button{1} versus \\button{4}?\n\n\\begin{figure}\n  \\begin{center}\n    \\includegraphics[width=6in]{lab7/screen}\n  \\end{center}\n  \\caption{Example filter bank layout.\\label{fg:screen}}\n\\end{figure}\n\n\\paragraph{Step 2.4} Now we will assemble a filter bank. Your final layout \nshould look something like Figure~\\ref{fg:screen}. Pare down\nyour filter, etc. to the minimum set of blocks: \\block{Filter},\n\\block{PZ Placement}, \\block{Square}, and \\block{Statistics}. Place four of these blocks down for\nthe four frequencies 697Hz, 1209Hz, 1336Hz, and 1477Hz; this will\nallow us to recognize \\button{1}, \\button{2}, and \\button{3}. Use\nthree \\block{Junction}s to split the output of the \\block{DTMF Tones}\nblock to send to four filters. Place the poles for each filter at the\nsame radius and the appropriate angles for each frequency (remember,\nthe \\block{PZ Placement} block uses degrees for manual angle\nentry). Name the \\block{Statistics} blocks for the filters'\nfrequencies. Include a screen shot showing the output for\n\\block{DTMF Tones} button \\button{2} in your report. What are the mean\nsquared values for each frequency for each of the \\block{DTMF Tones}\nbuttons \\button{1}, \\button{2}, \\button{3}, and \\button{4}?  Would you\nbe able to use a simple pair of comparisons for each button to decode\nwhich button was pressed? Why or why not?\n\n% LocalWords:  WebQ MATLAB DSP\n", "meta": {"hexsha": "5ac2e92709b64510b08bd6e1419e44dac7b7c387", "size": 8999, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP Labs/lab7/lab7.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/lab7/lab7.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/lab7/lab7.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": 45.4494949495, "max_line_length": 97, "alphanum_fraction": 0.7366374042, "num_tokens": 2551, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.9059898235563418, "lm_q1q2_score": 0.7645603821773618}}
{"text": "\\chapter{Linear Models for Classification}\n\n\\section*{Exercise 4.1 $\\star \\star$}\nGiven a set of data points $\\{\\mathbf{x}_n\\}$, we can define the\n$\\emph{convex hull}$ to be the data set of all points \n$\\mathbf{x}$ given by\n\\begin{equation}\\label{eq:4.156}\\tag{4.156}\n    \\mathbf{x} = \\sum_{n} \\alpha_n \\mathbf{x}_n\n\\end{equation}\nwhere $\\alpha_n \\geq 0$ and $\\sum_{n} \\alpha_n = 1$. Consider\na second set of points $\\{\\mathbf{y}_n\\}$ together with\ntheir corresponding convex hull. By definition,\nthe two set of points will be linearly separable\nif there exists a vector $\\widehat{\\mathbf{w}}$ and\na scalar $w_0$ such that $\\widehat{\\mathbf{w}}^T\\mathbf{x}_n + w_0 > 0$\nfor all $\\mathbf{x}_n$, and $\\widehat{\\mathbf{w}}^T\\mathbf{y}_n + w_0 < 0$\nfor all $\\mathbf{y}_n$. Show that if their convex hulls intersect,\nthe two sets of points cannot be linearly separable, and conversely\nthat if they are linearly separable, their covex hulls do not intersect.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The vertices of the convex hulls are the data points $\\{\\mathbf{x}_n\\}$ and $\\{\\mathbf{y}_n$\\}. \n    Therefore, the edges of the hulls will be represented by some segments beteween the data points.\n    As a result, any point situated on the boundary of the hull can be written as a convex\n    combination of the end-points of the segment it's contained by. Also,\n    one can easily see that if two hulls intersect, they intersect in at least one \n    point that is contained by the boundaries of both hulls. \n\n    \\vspace{1em}\n    \\textbf{1st Hypothesis}: If the hulls intersect, the two sets of \n    points are not linearly separable\n    \\vspace{1em}\n\n    Assume that the two hulls intersect in the point $\\mathbf{z}$ situated\n    on both hulls boundaries. From what we've seen above, \n    the point $\\mathbf{z}$ can be expressed as a convex\n    combination between two data points of each set of data points. Therefore,\n    there exist \n    $\\mathbf{x}_A, \\mathbf{x}_B$ from $\\{\\mathbf{x}_n\\}, \\mathbf{y}_A, \\mathbf{y}_B$\n    from $\\{\\mathbf{y}_n\\}$ and $\\lambda_\\mathbf{x}, \\lambda_\\mathbf{y} \\in [0, 1]$ such that\n    we can express $\\mathbf{z}$ as\n     \\[\n         \\lambda_\\mathbf{x} \\mathbf{x}_A + (1 - \\lambda_\\mathbf{x}) \\mathbf{x}_B = \n         \\lambda_\\mathbf{y} \\mathbf{y}_A + (1 - \\lambda_\\mathbf{y}) \\mathbf{y}_B\n    \\] \n    Suppose that the sets \\{$\\mathbf{x}_n$\\} and $\\{\\mathbf{y}_n\\}$ are linearly \n    separable. Then there exists a discriminant function\n    \\[\n        \\theta(\\mathbf{a}) = \\widehat{\\mathbf{w}}^T \\mathbf{a} + w_0\n    \\]\n    such that $\\theta(\\mathbf{x}_n) > 0$ for all $\\mathbf{x}_n$ and $\\theta(\\mathbf{y}_n) < 0$\n    for all $\\mathbf{y}_n$. From the linearity of the discriminant function, \n    and rewritting $\\theta(\\mathbf{z})$ using the convex combinations forms,\n    we have that\n    \\[\n        \\lambda_\\mathbf{x} \\theta(\\mathbf{x}_A) + (1 - \\lambda_\\mathbf{x}) \\theta(\\mathbf{x}_B)\n        = \\lambda_\\mathbf{y} \\theta(\\mathbf{y}_A) + (1 - \\lambda_\\mathbf{y}) \\theta(\\mathbf{y}_B)\n    \\] \n    Since $\\theta(\\mathbf{x}_A), \\theta(\\mathbf{x}_B) > 0$ and \n    $\\theta(\\mathbf{y}_A), \\theta(\\mathbf{y}_B) < 0$, this\n    expression is obviously false, since the left-hand side of the equality\n    is positive and the right-hand one is negative. Therefore, our supposition\n    that the data sets are linearly separable is false and our main hypothesis is true.\n\n    \\vspace{1em}\n    \\textbf{2nd Hypothesis}: If the two sets of points are linearly separable,\n    then the hulls don't intersect. \n    \\vspace{0.25em}\n\n    This hypothesis is the counterpositive of the 1st hypothesis. Therefore,\n    it's valid too.\n\\end{proof}\n\n\\section*{Exercise 4.2 $\\start \\star$ \\textbf{TODO}} \nConsider the minimization of a sum-of-squares error\nfunction ($\\ref{eq:4.15}$), and suppose that all of the \ntarget vectors in the training set satisfy a linear constraint\n\\begin{equation}\\label{eq:4.157}\\tag{4.157}\n    \\mathbf{a}^T\\mathbf{t}_n + b = 0\n\\end{equation}\nwhere $\\mathbf{t}_n$ corresponds to the $n^\\text{th}$ row of the matrix $\\mathbf{T}$\nin $(\\ref{eq:4.15})$. Show that as a consequence of this constraint,\nthe elements of the model prediction $\\mathbf{y}(\\mathbf{x})$ given\nby the least-squares solution ($\\ref{eq:4.17}$) also satisfy\nthis constraint, so that\n\\begin{equation}\\label{eq:4.158}\\tag{4.158}\n    \\mathbf{a}^T\\mathbf{y}(\\mathbf{x}) + b = 0\n\\end{equation}\nTo do so, assume that one of the basis functions $\\phi_0(\\mathbf{x}) = 1$,\nso that the corresponding parameter $w_0$ plays the role of a bias.\n\n\\section*{Exercise 4.4 $\\star$}\nShow that maximization of the class separation criterion given by\n($\\ref{eq:3.24}$) with respect to $\\mathbf{w}$, using a Lagrange multiplier\nto enforce the constraint $\\mathbf{w}^T\\mathbf{w} = 1$, leads to the\nresult that $\\mathbf{w} \\propto (\\mathbf{m}_2 - \\mathbf{m}_1)$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Our goal is to maximize\n    \\begin{equation}\\label{eq:3.24}\\tag{3.24}\n        m_2 - m_1 = \\mathbf{w}^T(\\mathbf{m}_2 - \\mathbf{m}_1)\n    \\end{equation}\n    with the constraint that $\\mathbf{w}^T\\mathbf{w} = 1$.\n    The corresponding Lagrangian is given by\n    \\[\n        \\mathcal{L}(\\mathbf{w}, \\lambda) \n        = \\mathbf{w}^T(\\mathbf{m}_2 - \\mathbf{m}_1) + \\lambda(\\mathbf{w}^T\\mathbf{w} - 1)\n    \\] \n    By taking the gradient of this with respect to $\\mathbf{w}$ and $\\lambda$,\n    we have that\n    \\[\n        \\nabla_{\\mathbf{w}, \\lambda} \\mathcal{L}(\\mathbf{w}, \\lambda) \n        = \\begin{pmatrix}\n            \\mathbf{m}_2 - \\mathbf{m}_1 + 2\\lambda\\mathbf{w} \\\\\n            \\mathbf{w}^T\\mathbf{w} - 1\n        \\end{pmatrix}\n    \\] \n    Setting to 0 the derivative with respect to $\\mathbf{w}$ gives the initial result, that is\n    \\[\n        \\mathbf{w} = \\frac{\\mathbf{m}_1 - \\mathbf{m}_2}{2\\lambda} \n    \\] \n    By replacing into the $\\lambda$ derivative and setting it to 0, we'd obtain that\n     \\[\n         \\lambda = \\frac{1}{4} ||\\mathbf{m}_1 - \\mathbf{m}_2||^2\n    \\] \n    which gives\n    \\[\n        \\mathbf{w} = \\frac{2(\\mathbf{m}_1 - \\mathbf{m}_2)}{||\\mathbf{m}_1 - \\mathbf{m}_2||^2}\n        \\propto (\\mathbf{m}_2 - \\mathbf{m}_1)\n    \\] \n\\end{proof}\n\n\\section*{Exercise 4.5 $\\star$}\nBy making use of (4.20), ($\\ref{eq:4.23}$), and (4.24), show that the Fischer \ncriterion ($\\ref{eq:4.25}$) can be written in the form ($\\ref{eq:4.26}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Fisher criterion is defined to be the ratio of the between-class\n    variance to the within-class variance and is given by\n    \\begin{equation}\\label{eq:4.25}\\tag{4.25}\n        J(\\mathbf{w}) = \\frac{(m_2 - m_1)^2}{s_1^2 + s_2^2}\n    \\end{equation}\n    where \n    \\begin{equation}\\label{eq:4.23}\\tag{4.23}\n        m_k = \\mathbf{w}^T\\mathbf{m}_k\n    \\end{equation}\n    and\n    \\begin{equation}\\label{eq:4.24}\\tag{4.24}\n        s_k^2 = \\sum_{n \\in \\mathcal{C}_k} (y_n - m_k)^2\n    \\end{equation}\n    By substituting $(\\ref{eq:4.23})$ into the numerator of the Fischer expression,\n    \\begin{align*}\n        (m_2 - m_1)^2 \n        = (\\mathbf{w}^T\\mathbf{m}_2 - \\mathbf{w}^T\\mathbf{m}_1)^2\n        = \\mathbf{w}^T(\\mathbf{m}_2 - \\mathbf{m}_1)\\mathbf{w}^T(\\mathbf{m}_2 - \\mathbf{m}_1)\n        &= \\mathbf{w}^T(\\mathbf{m}_2 - \\mathbf{m}_1)(\\mathbf{m}_2 - \\mathbf{m}_1)^T\\mathbf{w} \\\\\n        &= \\mathbf{w}^T\\mathbf{S}_B\\mathbf{w}\n    \\end{align*}\n    where $\\mathbf{S}_B$ is the $\\emph{between-class}$ covariance matrix and is given by\n    \\begin{equation}\\label{eq:4.27}\\tag{4.27}\n        \\mathbf{S}_B = (\\mathbf{m}_2 - \\mathbf{m}_1)(\\mathbf{m}_2 - \\mathbf{m}_1)^T\n    \\end{equation}\n    Similarily, we use the fact that the projection of the D-dimensional input vector\n    $\\mathbf{w}$ to one dimension is given by\n    \\begin{equation}\\label{eq:4.20}\\tag{4.20}\n        y = \\mathbf{w}^T\\mathbf{x}\n    \\end{equation}\n    along with $(\\ref{eq:4.23})$ and $(\\ref{eq:4.24})$ to rewrite the denominator as \n    \\begin{align*}\n        s_1^2 + s_2^2\n        &= \\sum_{n \\in \\mathcal{C}_1} (y_n - m_1)^2 + \\sum_{n \\in \\mathcal{C}_2} (y_n - m_2)^2 \\\\\n        &= \\sum_{n \\in \\mathcal{C}_1} (\\mathbf{w}^T\\mathbf{x}_n - \\mathbf{w}^T\\mathbf{m}_1)^2 \n            + \\sum_{n \\in \\mathcal{C}_2} (\\mathbf{w}^T\\mathbf{x}_n - \\mathbf{w}^T\\mathbf{m}_2)^2 \\\\\n        &= \\sum_{n \\in \\mathcal{C}_1} \\mathbf{w}^T(\\mathbf{x}_n - \\mathbf{m}_1)\n            (\\mathbf{x}_n - \\mathbf{m}_1)^T\\mathbf{w}\n            + \\sum_{n \\in \\mathcal{C}_2} \\mathbf{w}^T(\\mathbf{x}_n - \\mathbf{m}_2)\n            (\\mathbf{x}_n - \\mathbf{m}_2)^T\\mathbf{w} \\\\\n        &= \\mathbf{w}^T \\bigg[\\sum_{n \\in \\mathcal{C}_1} \n            (\\mathbf{x}_n - \\mathbf{m}_1)(\\mathbf{x}_n - \\mathbf{m}_1)^T\n            + \\sum_{n \\in \\mathcal{C}_2}  \n            (\\mathbf{x}_n - \\mathbf{m}_2)(\\mathbf{x}_n - \\mathbf{m}_2)^T\n            \\bigg]\\mathbf{w} \\\\\n        &= \\mathbf{w}^T\\mathbf{S}_W\\mathbf{w}\n    \\end{align*}\n    where $\\mathbf{S}_W$ is the $\\emph{within-class}$ covariance matrix and is given by\n    \\begin{equation}\\label{eq:4.28}\\tag{4.28}\n        \\mathbf{S}_W = \n           \\sum_{n \\in \\mathcal{C}_1} \n            (\\mathbf{x}_n - \\mathbf{m}_1)(\\mathbf{x}_n - \\mathbf{m}_1)^T\n            + \\sum_{n \\in \\mathcal{C}_2}  \n            (\\mathbf{x}_n - \\mathbf{m}_2)(\\mathbf{x}_n - \\mathbf{m}_2)^T\n    \\end{equation}\n    Finally, by substituting the new expressions into ($\\ref{eq:4.25}$), we can rewrite\n    the Fischer criterion as\n    \\begin{equation}\\label{eq:4.26}\\tag{4.26}\n        J(\\mathbf{w}) = \\frac{\\mathbf{w}^T\\mathbf{S}_B\\mathbf{w}}{\\mathbf{w}^T\\mathbf{S}_W\\mathbf{w}}\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.7 $\\star$}\nShow that the logistic sigmoid function $(\\ref{eq:4.59})$ satisfies the property\n$\\sigma(-a) = 1 - \\sigma(a)$ and that its inverse is given by \n$\\sigma^{-1}(y) = \\ln\\bigg(\\displaystyle \\frac{y}{1 - y}\\bigg)$. \n\n\\vspace{1em}\n\n\\begin{proof}\n    The sigmoid function is given by\n    \\begin{equation}\\label{eq:4.59}\\tag{4.59}\n        \\sigma(a) = \\frac{1}{1 + e^{-a}}\n    \\end{equation}\n    The symmetry property is easily satisfied, as\n    \\begin{equation}\\label{eq:4.60}\\tag{4.60}\n        \\sigma(-a) \n        = \\frac{1}{1 + e^a} \n        = \\frac{1 + e^a + 1 + e^{-a}}{(1 + e^{-a})(1 + e^a)}\n        - \\frac{1 + e^a}{(1 + e^{-a})(1 + e^a)}\n        = 1 - \\frac{1}{1 + e^{-a}} \n        = 1 - \\sigma(a)\n    \\end{equation}\\label{eq:4.60}\n    The sigmoid function is bijective, so inversable. Therefore, let $\\sigma(x) = y$.\n    Then,\n    \\[\n        y = \\frac{1}{1 + e^{-x}} \n        \\iff (1 + e^{-x})y = 1 \n        \\iff e^{-x} &= \\frac{1 - y}{y} \n        \\iff x = \\ln\\bigg(\\frac{y}{1-y}\\bigg)\n    \\] \n    so the inverse of the sigmoid function is given by\n    \\[\n        \\sigma^{-1}(y) = \\ln\\bigg(\\frac{y}{1 - y}\\bigg)\n    \\] \n\\end{proof}\n\n\\section*{Exercise 4.8 $\\star$}\nUsing ($\\ref{eq:4.57}$) and $(\\ref{eq:4.58})$, derive the result $(\\ref{eq:4.65})$ \nfor the posterior class probability in the two-class generative model with Gaussian\ndensities, and verify the results $(\\ref{eq:4.66})$ and $(\\ref{eq:4.67})$ for the\nparameters $\\mathbf{w}$ and $w_0$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    It is known that the posterior probability for class $\\mathcal{C}_1$ can\n    be written as\n    \\begin{equation}\\label{eq:4.57}\\tag{4.57}\n        p(\\mathcal{C}_1 | \\mathbf{x}) = \\sigma(a)\n    \\end{equation}\n    where we have defined \n    \\begin{equation}\\label{eq:4.58}\\tag{4.58}\n        a = \\ln \\frac{p(\\mathbf{x} | \\mathcal{C}_1)p(\\mathcal{C}_1)}\n            {p(\\mathbf{x} | \\mathcal{C}_2)p(\\mathcal{C}_2)}\n    \\end{equation}\n    and $\\sigma$ is the logistic sigmoid function defined by $(\\ref{eq:4.59})$.\n    We start by expanding $a$ and rewritting it as\n    \\[\n        a = \\ln p(\\mathbf{x} | \\mathcal{C}_1) - \\ln p(\\mathbf{x} | \\mathcal{C}_2)\n            + \\ln \\frac{p(\\mathcal{C}_1)}{p(\\mathcal{C}_2)}\n    \\] \n    Since the class-conditional densities are Gaussian, i.e. the density\n    for a class $\\mathcal{C}_k$ is given by\n    \\begin{equation}\\label{eq:4.64}\\tag{4.64}\n        p(\\mathbf{x} | \\mathcal{C}_k) = \\mathcal{N}(\\mathbf{x} | \\bm{\\mu}_k, \\mathbf{\\Sigma})\n        = \\frac{1}{(2\\pi)^{D/2}} \\frac{1}{|\\mathbf{\\Sigma}|^{1/2}}\n        \\exp \\bigg\\{-\\frac{1}{2} (\\mathbf{x} - \\bm{\\mu}_k)^T\\mathbf{\\Sigma}^{-1}\n        (\\mathbf{x} - \\bm{\\mu}_k)\\bigg\\}\n    \\end{equation}\n    one can easily obtain that\n    \\begin{align*}\n        a \n        &= \\ln p(\\mathbf{x} | \\mathcal{C}_1) - \\ln p(\\mathbf{x} | \\mathcal{C}_2) \n        + \\ln \\frac{p(\\mathcal{C}_1)}{p(\\mathcal{C}_2)}\\\\\n        &= \\bm{\\mu}_1^T\\mathbf{\\Sigma}^{-1}\\mathbf{x}\n        - \\bm{\\mu}_2^T\\mathbf{\\Sigma}^{-1}\\mathbf{x} \n        - \\frac{1}{2} \\bm{\\mu}_1^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_1\n        + \\frac{1}{2} \\bm{\\mu}_2^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_2\n        + \\ln \\frac{p(\\mathcal{C}_1)}{p(\\mathcal{C}_2)}\\\\\n        &= (\\bm{\\mu}_1 - \\bm{\\mu}_2)^T \\mathbf{\\Sigma}^{-1} \\mathbf{x}\n        - \\frac{1}{2} \\bm{\\mu}_1^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_1\n        + \\frac{1}{2} \\bm{\\mu}_2^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_2\n        + \\ln \\frac{p(\\mathcal{C}_1)}{p(\\mathcal{C}_2)}\\\\\n        &= \\mathbf{w}^T\\mathbf{x} + w_0\n    \\end{align*}\n    where we have defined \n    \\begin{equation}\\label{eq:4.66}\\tag{4.66}\n        \\mathbf{w} = \\mathbf{\\Sigma}^{-1}(\\bm{\\mu}_1 - \\bm{\\mu}_2)\n    \\end{equation}\n    \\vspace{-1em}\n    \\begin{equation}\\label{eq:4.67}\\tag{4.67}\n        w_0 = \n        - \\frac{1}{2} \\bm{\\mu}_1^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_1\n        + \\frac{1}{2} \\bm{\\mu}_2^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_2\n        + \\ln \\frac{p(\\mathcal{C}_1)}{p(\\mathcal{C}_2)}\n    \\end{equation}\n    Therefore, the posterior probability for class $\\mathcal{C}_1$ \n    is given by\n    \\begin{equation}\\label{eq:4.65}\\tag{4.65}\n        p(\\mathcal{C}_1 | \\mathbf{x}) = \\sigma(\\mathbf{w}^T\\mathbf{x} + w_0)\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.9 $\\star$}\nConsider a generative classification model for $K$ classes\ndefined by prior class probabilities $p(\\mathcal{C}_k) = \\pi_k$\nand general class-conditional densities  $p(\\bm{\\phi} | \\mathcal{C}_k)$\nwhere $\\mathbf{\\phi}$ is the input feature vector. Suppose\nwe are given a training set $\\{\\bm{\\phi}_n, \\mathbf{t}_n\\}$ where\n$n = 1,\\ldots, N$, and $\\mathbf{t}_n$ is a binary target vector\nof length $K$ that use the 1-of-$K$ coding scheme, so\nthat it has components $t_{nj} = \\mathbf{I}_{jk}$ if pattern\n$n$ is from class $\\mathcal{C}_k$. Assuming that the data points\nare drawn independently from this model, show that the \nmaximum-likelihood solution for the prior probabilites is given\nby \n\\begin{equation}\\label{eq:4.159}\\tag{4.159}\n    \\pi_k = \\frac{N_k}{N}\n\\end{equation}\nwhere $N_k$ is the number of data points assigned to class \n$\\mathcal{C}_k$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Let $\\mathbf{T}$ be the $N \\times K$ matrix with the rows $\\mathbf{t}_n^T$ and\n    $\\mathbf{\\Phi}$ the $N \\times M$ matrix with the rows $\\bm{\\phi}_n^T$.\n    Also, let's define the column vector $\\bm{\\pi} = (\\pi_1, \\pi_2, \\ldots, \\pi_K)^T$.\n    We have that\n    \\[\n        p(\\bm{\\phi}_n, \\mathcal{C}_k)\n        = p(\\mathcal{C}_k)p(\\bm{\\phi}_n | \\mathcal{C}_k)\n        = \\pi_k p(\\bm{\\phi}_n | \\mathcal{C}_k)\n    \\] \n    so the likelihood function is given by\n    \\[\n        p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        = \\prod_{n = 1}^N p(\\mathbf{t}_n | \\mathbf{\\Phi}, \\bm{\\pi})\n        = \\prod_{n = 1}^N \\prod_{j = 1}^K\n        \\bigg[\\pi_j p(\\bm{\\phi}_n | \\mathcal{C}_j)\\bigg]^{t_{nj}}\n    \\] \n    The log likelihood is then easily derived as\n    \\[\n        \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        = \\sum_{n=1}^{N} \\sum_{j=1}^{K} \\bigg(t_{nj} \\ln \\pi_j\n        + t_{nj} \\ln p(\\bm{\\phi}_n | \\mathcal{C}_j)\\bigg)\n    \\] \n    We aim to minimize this with respect to $\\pi_k$, while\n    still maintaining the constraint $\\sum_{k=1}^{N} \\pi_k = 1$\n    Therefore, by only keeping the terms depending on $\\pi_k$, we obtain the Lagrangian\n    \\[\n        \\mathcal{L}(\\bm{\\pi}, \\lambda)\n        = \\sum_{n=1}^{N} \\sum_{j=1}^{K} t_{nj} \\ln \\pi_j\n        + \\lambda \\bigg(\\sum_{j=1}^{N} \\pi_j - 1\\bigg)\n    \\]\n    with the gradient\n    \\[\n        \\nabla_{\\pi_k, \\lambda} \\mathcal{L}(\\bm{\\pi}, \\lambda)\n        = \\begin{pmatrix}\n            \\displaystyle \\frac{1}{\\pi_k} \\sum_{n=1}^{N} t_{nk} + \\lambda \\\\\n            \\\\\n            \\displaystyle \\sum_{k=1}^{N} \\pi_k - 1\n        \\end{pmatrix}\n    \\] \n    By setting this gradient to $0$, from the first relation we have that\n    \\[\n        \\pi_k\\lambda = -\\sum_{n=1}^{N} t_{nk} = -N_k\n    \\] \n    Summing this over $k$, one can see that\n     \\[\n         \\lambda = -N\n    \\] \n    After substituting this into the derivative and then setting it to 0, \n    we obtain the maximum-likelihood solution for $\\pi_k$, that is\n    \\[\n        \\pi_k = \\frac{N_k}{N}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 4.10 $\\star \\star$}\nConsider the classification model of Exercise 4.9 and now suppose\nthat the class-conditional densities are given by Gaussian \ndistributions with a shared covariance matrix, so that\n\\begin{equation}\\label{eq:4.160}\\tag{4.160}\n    p(\\bm{\\phi} | \\mathcal{C}_k) = \\mathcal{N}(\\bm{\\phi} | \\bm{\\mu}_k, \\mathbf{\\Sigma})\n\\end{equation}\nShow that the maximum likelihood solution for the mean of the\nGaussian distribution for class $\\mathcal{C}_k$ is given by\n\\begin{equation}\\label{eq:4.161}\\tag{4.161}\n    \\bm{\\mu}_k = \\frac{1}{N_k} \\sum_{n=1}^{N} t_{nk} \\bm{\\phi}_n\n\\end{equation}\nwhich represents the mean of those feature vectors assigned\nto class $\\mathcal{C}_k$. Similarly, show that the maximum likelihood\nsolution for the shared covariance matrix is given by\n\\begin{equation}\\label{eq:4.162}\\tag{4.162}\n    \\mathbf{\\Sigma} = \\sum_{k=1}^{K} \\frac{N_k}{N}\\mathbf{S}_k\n\\end{equation}\nwhere \n\\begin{equation}\\label{eq:4.163}\\tag{4.163}\n\\mathbf{S}_k = \\frac{1}{N_k} \\sum_{n=1}^{N} \nt_{nk}(\\bm{\\phi}_n - \\bm{\\mu_k})(\\bm{\\phi}_{k} - \\bm{\\mu}_k)^T\n\\end{equation}\nThus $\\mathbf{\\Sigma}$ is given by a weighted average of the covariances\nof the data associated with each class, in which the weighting coefficients\nare given by the prior probabilities of the classes.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Using the same notations as in the last exercise, we remember that the\n    log likelihood is given by\n    \\[\n        \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        = \\sum_{n=1}^{N} \\sum_{j=1}^{K} \\bigg(t_{nj} \\ln \\pi_j\n        + t_{nj} \\ln p(\\bm{\\phi}_n | \\mathcal{C}_j)\\bigg)\n    \\] \n    By keeping only the parts depending on $\\bm{\\mu}_k$,\n    \\[\n        \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        = -\\frac{1}{2}\\sum_{n=1}^{N} \\sum_{j=1}^{K} \n        t_{nj} (\\bm{\\phi}_n - \\bm{\\mu}_k)^T\\mathbf{\\Sigma}^{-1}\n            (\\bm{\\phi}_n - \\bm{\\mu}_k) + \\text{const}\n    \\] \n    For a symmetric matrix $\\mathbf{W}$, one could show that\n    \\[\n        \\pdv{s}(\\mathbf{x} - \\mathbf{s})^T\\mathbf{W}(\\mathbf{x} - \\mathbf{s}) \n        = -2 \\mathbf{W}(\\mathbf{x} - \\mathbf{s})\n    \\] \n    Therefore, the derivative with respect to $\\mathbf{\\mu}_k$ of the \n    log-likelihood is given by\n    \\[\n        \\pdv{\\bm{\\mu}_k}\n        \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        = \\sum_{n=1}^{N} t_{nk} \\mathbf{\\Sigma}^{-1}(\\bm{\\phi}_n - \\bm{\\mu}_k)\n    \\] \n    Since $\\sum_{n=1}^{N} t_{nk} = N_k$, \n    by setting the derivative to 0 and rearranging the terms, we have that\n    the solution for maximum likelihood is\n    \\[\n        \\bm{\\mu}_k = \\frac{1}{N_k} \\sum_{n=1}^{N} t_{nk} \\bm{\\phi}_n\n        \\tag{4.161}\n    \\] \n    Similarly, we do the same for the shared covariance matrix.\n    By keeping only the terms depending on $\\mathbf{\\Sigma}$, the\n    log likelihood is given by\n    \\begin{align*}\n        \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        &= -\\frac{N}{2} \\ln|\\mathbf{\\Sigma}| - \\frac{1}{2}\\sum_{n=1}^{N} \\sum_{k=1}^{K} \n            t_{nk} (\\bm{\\phi}_n - \\bm{\\mu}_k)^T\\mathbf{\\Sigma}^{-1}\n            (\\bm{\\phi}_n - \\bm{\\mu}_k) + \\text{const} \\\\\n        &= -\\frac{N}{2} \\ln|\\mathbf{\\Sigma}| - \\frac{1}{2}\\sum_{n=1}^{N} \\sum_{k=1}^{K} \n            t_{nk} \\big(\\bm{\\phi}_n^T\\mathbf{\\Sigma}^{-1}\\bm{\\phi}_n \n            - 2\\bm{\\phi}_n^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_k \n            + \\bm{\\mu}_k^T\\mathbf{\\Sigma}^{-1}\\bm{\\mu}_k\\big)\n    \\end{align*}\n    By using (C.28) and \n    \\[\n    \\pdv{\\mathbf{X}} \\mathbf{a}^T\\mathbf{X}^{-1}\\mathbf{b}\n    = -\\mathbf{X}^{-T} \\mathbf{ab}^T \\mathbf{X}^{-T}\n    \\] \n    we take the derivative of the log likelihood with respect to $\\mathbf{\\Sigma}$ \n    and obtain:\n    \\begin{align*}\n        \\pdv{\\mathbf{\\Sigma}} \\ln p(\\mathbf{T} | \\mathbf{\\Phi}, \\bm{\\pi})\n        &= -\\frac{N}{2} \\mathbf{\\Sigma}^{-1}\n        + \\frac{1}{2} \\sum_{n=1}^{N} \\sum_{j=k}^{K} t_{nk} \\mathbf{\\Sigma}^{-1}\n        \\big(\\bm{\\phi}_n\\bm{\\phi}_n^T - 2\\bm{\\phi}_n\\bm{\\mu}_k^T + \\bm{\\mu}_k\\bm{\\mu}_k^T\\big) \n        \\mathbf{\\Sigma}^{-1} \\\\\n        &= -\\frac{N}{2} \\mathbf{\\Sigma}^{-1} \n        + \\frac{1}{2} \\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} \\mathbf{\\Sigma}^{-1}\n        (\\bm{\\phi}_n - \\bm{\\mu}_k)(\\bm{\\phi}_n - \\bm{\\mu}_k)^T \\mathbf{\\Sigma}^{-1} \\\\\n        &= -\\frac{N}{2} \\mathbf{\\Sigma}^{-1} \n        + \\frac{1}{2} \\mathbf{\\Sigma}^{-1} \n        \\bigg(\\sum_{k=1}^{K} N_k\\mathbf{S}_k\\bigg) \\mathbf{\\Sigma}^{-1}\n    \\end{align*}\n    where $\\mathbf{S}_k$ is defined by $(\\ref{eq:4.163})$. Therefore, by setting\n    this derivative to 0 and rearranging the terms,\n    we obtain the maximum-likelihood solution for the\n    shared covariance matrix\n    \\[\n        \\mathbf{\\Sigma} = \\sum_{k=1}^{K} \\frac{N_k}{N} \\mathbf{S}_k \\tag{4.162}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 4.11 $\\star \\star$}\nConsider a classification problem with $K$ classses for which the feature\nvector $\\mathbf{\\phi}$ has $M$ components each of which can take $L$ discrete\nstates. Let the values of the components be represented by a 1-of-$L$ binary coding scheme.\nFurther suppose that, conditioned on the class $\\mathcal{C}_k$, the $M$ components\nof $\\bm{\\phi}$ are independent, so that the class-conditional density factorizes\nwith respect to the feature vector components. Show that the quantities given by\n$(\\ref{eq:4.63})$, which appear in the argument to the softmax function\ndescribing the posterior class probabilties, are linear functions of the components\nof $\\bm{\\phi}$. Note that this represents an example of the naive Bayes model\nwhich is discussed in Section 8.2.2.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We've seen in Section 4.2 that the posterior probabilities\n    can be written as $\\emph{normalized}$ $\\emph{exponentials}$:\n    \\begin{equation}\\label{eq:4.62}\\tag{4.62}\n        p(\\mathcal{C}_k | \\bm{\\phi}) \n        = \\frac{\\exp(a_k)}{\\sum_{j} \\exp(a_j)}\n    \\end{equation}\n    where\n    \\begin{equation}\\label{eq:4.63}\\tag{4.63}\n        a_k = \\ln p(\\bm{\\phi} | \\mathcal{C}_k)p(\\mathcal{C}_k)\n    \\end{equation}\n    Considering the setup of our classification problem,\n    our class-conditional distribution will be of the form\n    \\[\n        p(\\bm{\\phi} | \\mathcal{C}_k) \n        = \\prod_{i = 1}^M \\prod_{j = 1}^L\n            \\bm{\\mu}_{kij}^{\\bm{\\phi}_{ij}}\n    \\] \n    where $\\bm{\\mu}_k$ is given by $(\\ref{eq:4.161})$. \n    Therefore,\n    by replacing into $(\\ref{eq:4.63})$, the arguments\n    of the softmax function are given by\n    \\[\n        a_k = \\ln p(\\mathcal{C}_k) \n        + \\sum_{i=1}^{M} \\sum_{j=1}^{L} \\bm{\\phi}_{ij} \\ln \\bm{\\mu}_{kij} \n    \\] \n    and are obviously linear functions of the components\n    of $\\bm{\\phi}$.\n\\end{proof}\n\n\\section*{Exercise 4.12 $\\star$}\nVerify the relation ($\\ref{eq:4.88}$) for the derivative of the logistic sigmoid\nfunction defined by ($\\ref{eq:4.59}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    By taking the derivative of $(\\ref{eq:4.59})$, we have that: \n    \\[\n        \\pdv{a} \\sigma(a) \n        = \\pdv{a}\\bigg(\\frac{1}{1 + e^{-a}}\\bigg)\n        = \\frac{e^{-a}}{(1 + e^{-a})^2}\n        = \\frac{1 + e^{-a}}{(1 + e^{-a})^2} - \\frac{1}{(1 + e^{-a})^2} \n        = \\frac{1}{1 + e^{-a}} - \\bigg(\\frac{1}{1 + e^{-a}}\\bigg)^2\n    \\] \n    We recognize the expression of the logistic sigmoid function, so\n    \\begin{equation}\\label{eq:4.88}\\tag{4.88}\n        \\pdv{a} \\sigma(a) = \\sigma(a) - \\sigma(a)^2 = \\sigma(a) \\big(1 - \\sigma(a)\\big)\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.13 $\\star$}\nBy making use of the result ($\\ref{eq:4.88}$) for the derivative of the logistic\nsigmoid, show that the derivative of the error function ($\\ref{eq:4.90}$) for \nthe logistic regression model is given by (\\ref{eq:4.91}).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The error function for the logistic regression is given by\n    \\begin{equation}\\label{eq:4.90}\\tag{4.90}\n        E(\\mathbf{w}) \n        = -\\ln p(\\mathbf{t} | \\mathbf{w})\n        = -\\sum_{n = 1}^{N} \\{t_n \\ln y_n + (1 - t_n) \\ln(1 - y_n)\\} \n    \\end{equation}\n    where $y_n = \\sigma(a_n)$ and $a_n = \\mathbf{w}^T\\bm{\\phi}_n$.\n    Taking the derivative of the log likelihood function with respect to $\\mathbf{w}$\n    gives\n    \\begin{align*}\n        \\nabla_{\\mathbf{w}} \\ln p(\\mathbf{t} | \\mathbf{w})\n        &= \\nabla_{\\mathbf{w}} \\sum_{n=1}^{N} \\big\\{\n            t_n \\ln y_n \n            + (1 - t_n) \\ln (1 - y_n)\n            \\big\\} \\\\\n        &= \\sum_{n=1}^{N} \\bigg[t_n \\nabla_{\\mathbf{w}} \\ln y_n\n            + (1 - t_n) \\nabla_{\\mathbf{w}} \\ln (1 - y_n)\\bigg] \\\\\n        &= \\sum_{n=1}^{N} \\bigg[\\frac{t_n}{y_n} \\nabla_{\\mathbf{w}} y_n\n            + \\frac{1 - t_n}{1 - y_n} \\nabla_{\\mathbf{w}} (1 - y_n) \\bigg]\\\\\n        &= \\sum_{n=1}^{N} \\frac{t_n(1 - y_n) - y_n(1 - t_n)}{y_n(1 - y_n)}\n            \\nabla_\\mathbf{w} y_n \\\\\n        &= \\sum_{n=1}^{N} \\frac{t_n - y_n}{y_n(1 - y_n)}\n            \\nabla_\\mathbf{w} y_n \\label{eq:4.13.1}\\tag{4.13.1}\n    \\end{align*}\n    Using ($\\ref{eq:4.88}$), we can compute the gradient term:\n    \\begin{align*}\n        \\nabla_{\\mathbf{w}} y_n \n        = \\nabla_\\mathbf{w} \\sigma(\\mathbf{w}^T\\bm{\\phi}_n)\n        = \\pdv{\\sigma}{a_n} \\pdv{a_n}{\\mathbf{w}} \\big(\\mathbf{w}^T\\bm{\\phi}_n\\big)\n        = y_n(1 - y_n) \\bm{\\phi}_n\n    \\end{align*}\n    so the gradient of the log likelihood is\n    \\[\n        \\nabla_{\\mathbf{w}} \\ln p(\\mathbf{t} | \\mathbf{w})\n        = \\sum_{n=1}^{N} (t_n - y_n) \\bm{\\phi}_n\n    \\] \n    and the gradient of the error function is then given by\n    \\begin{equation}\\label{eq:4.91}\\tag{4.91}\n        \\nabla_\\mathbf{w} E(\\mathbf{w})\n        = -\\nabla_\\mathbf{w} \\ln p(\\mathbf{t} | \\mathbf{w})\n        = - \\sum_{n=1}^{N} (t_n - y_n) \\bm{\\phi}_n\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.14 $\\star$}\nShow that for a linearly separable data set, the maximum likelihood\nsolution for the logistic regression model is obtained by finding a vector\n$\\mathbf{w}$ whose decision boundary $\\mathbf{w}^T\\bm{\\phi}(\\mathbf{x}) = 0$ \nseparates the classes and then taking the magnitude of $\\mathbf{w}$ to infinity.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Suppose there exists $\\mathbf{w}$ such that the hyperplane \n    $\\mathbf{w}^T\\bm{\\phi} = 0$ separates the data set.\n    Because the data set is linearly separable, \n    $\\mathbf{w}^T\\bm{\\phi}_a < 0$ and $\\mathbf{w}^T\\bm{\\phi}_b > 0$\n    for all $\\bm{\\phi}_a \\in \\mathcal{C}_1$ and $\\bm{\\phi}_b \\in \\mathcal{C}_2$.\n    One can observe that the maximum likelihood is obtained\n    when  $p(\\mathcal{C}_1 | \\bm{\\phi}_a) = 1$ and $p(\\mathcal{C}_2 | \\bm{\\phi}_b) = 1$ \n    for all $\\bm{\\phi}_a \\in \\mathcal{C}_1, \\bm{\\phi}_b \\in \\mathcal{C}_2$.\n    Since our hyperplane is already chosen, there is a fixed angle $\\theta_n$\n    between each $\\bm{\\phi}_n$ and $\\mathbf{w}$ such that $\\cos \\theta_n \\neq 0$. Therefore,\n    by using the geometric definition of the dot product\n    \\[\n        \\mathbf{w}^T\\bm{\\phi}_n\n        = \\Vert\\mathbf{w}\\Vert \\Vert\\bm{\\phi}_n\\Vert \\cos \\theta_n\n    \\] \n    we see that our maximization is achieved by taking the magnitude\n    of $\\Vert\\mathbf{w}\\Vert$ to infinity, as\n    \\[\n        \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty} p(\\mathcal{C}_1 | \\bm{\\phi}_a)\n        = \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty} \n        \\sigma(\\Vert\\mathbf{w}\\Vert \\Vert{\\bm{\\phi}_a}\\Vert \\cos \\theta_a)\n        = \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty}\n        \\frac{1}{1 + \\exp{-\\Vert\\mathbf{w}\\Vert \\Vert{\\bm{\\phi}_a}\\Vert \\cos \\theta_a}} \n        = 1\n    \\] \n    and \n    \\[\n        \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty} p(\\mathcal{C}_2 | \\bm{\\phi}_b)\n        = \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty} \n        \\sigma(\\Vert\\mathbf{w}\\Vert \\Vert{\\bm{\\phi}_b}\\Vert \\cos \\theta_b)\n        = \\lim_{\\Vert\\mathbf{w}\\Vert \\to \\infty}\n        \\frac{1}{1 + \\exp{-\\Vert\\mathbf{w}\\Vert \\Vert{\\bm{\\phi}_b}\\Vert \\cos \\theta_b}} \n        = 0\n    \\]\n    where $\\bm{\\phi} \\in \\mathcal{C}_1, \\bm{\\phi}_b \\in \\mathcal{C}_2$ and we've used the\n    fact that $\\mathbf{w}^T\\bm{\\phi}_a < 0$ and $ \\mathbf{w}^T\\bm{\\phi}_b > 0$.\n\\end{proof}\n\n\\section*{Exercise 4.15 $\\star \\star$}\nShow that the Hessian matrix $\\mathbf{H}$ for the logistic regression\nmodel, given by $(\\ref{eq:4.97})$, is positive definite. Here $\\mathbf{R}$\nis a diagonal matrix with elements $y_n(1 - y_n)$, and $y_n$ is\nthe output of the logistic regression model for input vector $\\mathbf{x}_n$.\nHence show that the error function is a convex function of $\\mathbf{w}$\nand it has an unique minimum.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The Hessian of the error function is given by\n    \\begin{equation}\\label{eq:4.97}\\tag{4.97}\n        \\mathbf{H} \n        = \\nabla \\nabla E(\\mathbf{w})\n        = \\sum_{n=1}^{N} y_n(1 - y_n)\\bm{\\phi}_n\\bm{\\phi}_n^T\n        = \\mathbf{\\Phi}^T\\mathbf{R}\\mathbf{\\Phi}\n    \\end{equation}\n    Let $\\mathbf{u}$ be a $M$-dimensional column vector.\n    By using the sum formulation for the hessian matrix, we have that\n    \\[\n        \\mathbf{u}^T\\mathbf{H}\\mathbf{u} \n        = \\sum_{n=1}^{N} y_n(1 - y_n)\\mathbf{u}^T\\bm{\\phi}_n\\bm{\\phi}_n^T\\mathbf{u}\n        = \\sum_{n=1}^{N} y_n(1 - y_n) \\big(\\bm{\\phi}_n^T\\mathbf{u}\\big)^T \\bm{\\phi}_n^T\\mathbf{u}\n        = \\sum_{n=1}^{N} y_n(1 - y_n) \\Vert\\bm{\\phi}_n^T \\mathbf{u}\\Vert^2\n    \\] \n    which is $>0$ since $y_n$ is the output of the logistic sigmoid function,\n    so $0 < y_n < 1$. Because $\\mathbf{u}$ was chosen arbitrarily, we have that\n    $\\mathbf{H}$ is positive definite. As a result, the error function is convex and has an unique\n    minimum.\n\\end{proof}\n\n\\section*{Exercise 4.16 $\\star$}\nConsider a binary classification problem in which each observation\n$\\mathbf{x}_n$ is known to belong to one of two classes, corresponding to $t=0$\nand $t=1$, and suppose that the procedure for collecting training data\nis imperfect, so that training points are sometimes mislabelled. For\nevery data point $\\mathbf{x}_n$, instead of having a value $t$ for\nthe class label, we have instead a value $\\pi_n$ representing the\nprobability that $t_n = 1$. Given a probabilistic model $p(t = 1 | \\bm{\\phi})$,\nwrite down the log likelihood function appropiate for such a data set.\n\n\\vspace{1em}\n\n\\begin{proof}\n    Straight away, we can see that $p(t = 0 | \\bm{\\phi}) = 1 - p(t = 1 | \\bm{\\phi})$.\n    An fair approach would be to express $p(t_n | \\bm{\\phi})$ as a weighted\n    average of $p(t_n = 0 | \\bm{\\phi})$ and $p(t_n = 1 | \\bm{\\phi}$ dictated by $\\pi_n$.\n    Therefore, the likelihood would be given by \n    \\[\n        p(\\mathbf{t} | \\bm{\\phi})\n        = \\prod_{n = 1}^N p(t_n | \\bm{\\phi})\n        = \\prod_{n = 1}^N p(t_n = 1 | \\bm{\\phi})^{\\pi_n}\n        p(t_n = 0 | \\bm{\\phi})^{1 - \\pi_n}\n        = \\prod_{n = 1}^N p(t_n = 1 | \\bm{\\phi})^{\\pi_n}\n        \\big\\{1 - p(t_n = 1 | \\bm{\\phi})\\big\\}^{1 - \\pi_n}\n    \\] \n    which has the log likelihood\n    \\[\n        \\ln p(\\mathbf{t} | \\bm{\\phi}) \n        = \\sum_{n=1}^{N} \\pi_n p(t_n = 1 | \\bm{\\phi})\n        + (1 - \\pi_n)\\big\\{1 - p(t_n = 1 | \\bm{\\phi})\\big\\}\n    \\] \n\\end{proof}\n\n\\section*{Exercise 4.17 $\\star$}\nShow that the derivatives of the softmax activation function\n$(\\ref{eq:4.104})$ where the $a_k$ are defined by $(\\ref{eq:4.105})$, are\ngiven by $(\\ref{eq:4.106})$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The softmax activation function is given by\n    \\begin{equation}\\label{eq:4.104}\\tag{4.104}\n        y_k = \\frac{\\exp(a_k)}{\\sum_{j} \\exp(a_j)}\n    \\end{equation}\n    where\n    \\begin{equation}\\label{eq:4.105}\\tag{4.106}\n        a_k = \\mathbf{w}_k^T\\bm{\\phi}\n    \\end{equation}\n    Taking the derivative of $(\\ref{eq:4.104})$ with respect to\n    $a_j$ and applying the quotient rule gives\n    \\begin{align*}\n        \\pdv{y_k}{a_j} \n        = \\pdv{a_j} \\bigg(\\frac{\\exp(a_k)}{\\sum_{i} \\exp(a_i)}\\bigg)\n        &= \\frac{I_{kj} \\exp(a_k) \\sum_{i} \\exp(a_i) - \\exp(a_k)\\exp(a_j)} \n        {\\bigg(\\sum_{i} \\exp(a_i)\\bigg)^2} \\\\\n        &= \\frac{\\exp(a_k)}{\\sum_{j} \\exp(a_j)}\n        \\bigg(I_{kj} - \\frac{\\exp(a_j)}{\\sum_{j} \\exp(a_j)}\\bigg)\n    \\end{align*}\n    which is equivalent to \n    \\begin{equation}\\label{eq:4.106}\\tag{4.106}\n        \\pdv{a_j} y_k = y_k(I_{kj} - y_j)\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.18 $\\star$}\nUsing the result $(\\ref{eq:4.106})$ for\nthe derivatives of the softmax activation function,\nshow that the gradients of the cross-entropy error $(\\ref{eq:4.108})$\nare given by ($\\ref{eq:4.109}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The cross-entropy error is given by\n    \\begin{equation}\\label{eq:4.108}\\tag{4.108}\n        E(\\mathbf{w}_1, \\ldots, \\mathbf{w}_K)\n        = -\\ln p(\\mathbf{T} | \\mathbf{w}_1, \\ldots, \\mathbf{w}_K)\n        = - \\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} \\ln y_{nk}\n    \\end{equation}\n    Taking its derivative with respect to $\\mathbf{w}_j$ yields \n    \\begin{align*}\n        \\pdv{\\mathbf{w}_j} E(\\mathbf{w}_1, \\ldots, \\mathbf{w}_K)\n        = \\pdv{\\mathbf{w}_j} \\bigg(-\\sum_{n=1}^{K} \\sum_{k=1}^{K} t_{nk} \\ln y_{nk}\\bigg) \n        = -\\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} \\pdv{\\mathbf{w}_j} \\ln y_{nk} \n    \\end{align*}\n    By using $(\\ref{eq:4.106})$ and the chain rule, we have that\n    \\begin{align*}\n        \\pdv{\\mathbf{w}_j} \\ln y_{nk}\n        = \\frac{1}{y_{nk}} \\pdv{y_{nk}}{\\mathbf{w}_j}\n        = \\frac{1}{y_{nk}} \\pdv{y_{nk}}{a_j} \\pdv{a_j}{\\mathbf{w}_j}\n        = \\frac{1}{y_{nk}} y_{nk}(I_{kj} - y_{nj}) \\bm{\\phi}_n\n        = (I_{kj} - y_{nj})\\bm{\\phi}_n\n    \\end{align*}\n    Replacing back into the gradient,\n    \\[\n        \\pdv{\\mathbf{w}_j} E(\\mathbf{w}_1, \\ldots, \\mathbf{w}_K)\n        = -\\sum_{n=1}^{N} \\sum_{k=1}^{K} t_{nk} (I_{kj} - y_{nj}) \\bm{\\phi}_n\n        = -\\sum_{n=1}^{N} t_{nj}\\bm{\\phi}_n \n        + \\sum_{n=1}^{N} \\bigg(\\sum_{k=1}^{N} t_{nk}\\bigg) y_{nj} \\bm{\\phi}_n\n    \\] \n    gives the desired result\n    \\begin{equation}\\label{eq:4.109}\\tag{4.109}\n        \\pdv{\\mathbf{w}_j}E(\\mathbf{w}_1, \\ldots, \\mathbf{w}_K)\n        = \\sum_{n=1}^{N} (y_{nj} - t_{nj})\\bm{\\phi}_n\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.19 $\\star$}\nWrite down expressions for the gradient of the log likelihood,\nas well as the corresponding Hessian matrix, for the probit regression\nmodel defined in Section 4.3.5. These are quantities that would be required to train such \na model using IRLS.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The probit function is given by \n    \\begin{equation}\\label{eq:4.114}\\tag{4.114}\n        \\Phi(a) = \\int_{-\\infty}^{a} \\mathcal{N}(\\theta | 0, 1) \\diff \\theta\n    \\end{equation}\n    Therefore, from the fundamental theorem of calculus, we have that\n    \\[\n        \\pdv{a} \\Phi(a) \n        = \\pdv{a} \\int_{-\\infty}^a \\mathcal{N}(\\theta | 0, 1) \\diff \\theta\n        = \\mathcal{N}(a | 0, 1) = \\frac{1}{\\sqrt{2\\pi}} e^{-\\frac{a^2}{2}}\n    \\] \n    so\n    \\[\n        \\nabla_\\mathbf{w} y_n \n        = \\nabla_\\mathbf{w} \\Phi(a_n)\n        = \\pdv{\\Phi}{a_n} \\pdv{a_n}{\\mathbf{w}} \n        = \\frac{1}{\\sqrt{2\\pi}} \\exp{-\\frac{a_n^2}{2}}\\bm{\\phi}_n\n    \\]\n\n    The probit regression model has a very similar form with what\n    we've used for the logistic regression model in Section 4.3.2. \n    More specifically, the log likelihood is still given by ($\\ref{eq:4.90}$),\n    but this time with $y_n = \\Phi(a_n)$. Therefore, the general form for gradient of the log \n    likelihood derived in Exercise 4.13, (\\ref{eq:4.13.1}) can be used\n    here too, so:\n    \\[\n        \\nabla_\\mathbf{w} \\ln p(\\mathbf{t} | \\mathbf{w}) \n        = \\sum_{n=1}^{N} \\frac{t_n - y_n}{y_n(1 - y_n)} \\nabla_\\mathbf{w} y_n\n        = \\frac{1}{\\sqrt{2\\pi}} \\sum_{n=1}^{N} \\frac{t_n - y_n}{y_n(1 - y_n)} \n        \\exp{-\\frac{a_n^2}{2}}\\bm{\\phi}_n\n    \\] \n    By taking the gradient of this again, we find the Hessian matrix\n    using the chain rule:\n    \\begin{align*}\n        \\mathbf{H} \n        = \\nabla_\\mathbf{w} \\nabla_\\mathbf{w} \\ln p(\\mathbf{t} | \\mathbf{w}) \n        &= \\frac{1}{\\sqrt{2\\pi}} \\sum_{n=1}^{N}\n        \\nabla_\\mathbf{w}\\bigg[\\frac{t_n - y_n}{y_n(1 - y_n)}\\exp{-\\frac{a_n^2}{2}}\\bigg]\\bm{\\phi}_n \\\\\n        &= \\frac{1}{\\sqrt{2\\pi}} \\sum_{n=1}^{N} \\bigg[\n            \\bigg(\\nabla_\\mathbf{w} \\frac{t_n - y_n}{y_n(1 - y_n)}\\bigg)\n            \\exp{-\\frac{a_n^2}{2}} + \\frac{t_n - y_n}{y_n(1 - y_n)} \n        \\bigg(\\nabla_\\mathbf{w} \\exp{-\\frac{a_n^2}{2}}\\bigg)\\bigg]\\bm{\\phi}_n\n    \\end{align*}\n    We compute each gradient term separately, so\n    \\begin{align*}\n        \\nabla_\\mathbf{w} \\frac{t_n - y_n}{y_n(1 - y_n)}\n        &= -\\frac{y_n(1 - y_n) + (t_n - y_n)(1 - 2y_n)}\n        {y_n^2(1 - y_n)^2} \\nabla_\\mathbf{w} y_n\n        = \\frac{y_n^2 - 2t_ny_n + t_n}{y_n^2(1 - y_n)^2}\\nabla_\\mathbf{w} y_n \\\\\n        &= \\frac{y_n^2 - 2t_ny_n + t_n}{y_n^2(1 - y_n)^2\\sqrt{2\\pi}}\\exp{-\\frac{a_n^2}{2}}\n        \\bm{\\phi}_n\n    \\end{align*}\n    and\n    \\[\n        \\nabla_\\mathbf{w} \\exp{-\\frac{a_n^2}{2}} \n        = -a_n\\exp{-\\frac{a_n^2}{2}} \\nabla_\\mathbf{w} a_n\n        = -a_n\\exp{-\\frac{a_n^2}{2}} \\bm{\\phi}_n\n    \\] \n    Hence, the hessian matrix becomes\n    \\begin{align*}\n        \\mathbf{H} \n        &= \\frac{1}{\\sqrt{2\\pi}} \\sum_{n=1}^{N} \\bigg[\n        \\frac{y_n^2 - 2t_ny_n + t_n}{y_n^2(1 - y_n)^2\\sqrt{2\\pi}}\\exp{-a_n^2}\\bm{\\phi}_n\n        - \\frac{a_n(t_n - y_n)}{y_n(1 - y_n)}\\exp{-\\frac{a_n^2}{2}}\\bm{\\phi}_n\\bigg] \\bm{\\phi}_n\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 4.21 $\\star$}\nShow that the probit function ($\\ref{eq:4.114}$) and the erf function $(\\ref{eq:4.115})$ are\nrelated by ($\\ref{eq:4.116}$).\n\n\\vspace{1em}\n\n\\begin{proof}\n    The error function is given by\n    \\begin{equation}\\label{eq:4.115}\\tag{4.115}\n        \\erf(a) = \\frac{2}{\\sqrt{\\pi}} \\int_{0}^{a} \\exp{-\\frac{\\theta^2}{2}} \\diff \\theta\n    \\end{equation}\n    By using the fact that the Gaussian is symmetric around the mean, \n    the probit function can be rewritten as\n    \\begin{align*}\n        \\Phi(a) \n        = \\int_{-\\infty}^{a} \\mathcal{N}(\\theta | 0, 1) \\diff \\theta\n        = \\int_{-\\infty}^{0} \\mathcal{N}(\\theta | 0, 1) \\diff \\theta\n        + \\int_{0}^{a} \\mathcal{N}(\\theta | 0, 1) \\diff \\theta\n        &= \\frac{1}{2} + \\frac{1}{\\sqrt{2\\pi}} \\int_{0}^{a} \\exp{-\\frac{\\theta^2}{2}} \\diff \\theta \\\\\n        &= \\frac{1}{2} \\bigg\\{1 + \\frac{1}{\\sqrt{2}} \\erf(a)\\bigg\\} \\label{eq:4.116}\\tag{4.116}\n    \\end{align*}\n\\end{proof}\n\n\\section*{Exercise 4.22 $\\star$}\nUsing the result (4.135), derive the expression\n$(\\ref{eq:4.137})$ for the log model evidence under the Laplace\napproximation.\n\n\\vspace{1em}\n\n\\begin{proof}\n    The proof of this is almost identical to the one in Section 4.4.1.\n    From Bayes' theorem the model evidence is given by\n    \\begin{equation}\\label{eq:4.136}\\tag{4.136}\n        p(\\mathcal{D}) \n        = \\int p(\\mathcal{D} | \\bm{\\theta}) p(\\bm{\\theta}) \\diff \\bm{\\theta}\n    \\end{equation}\n    Identifying $f(\\bm{\\theta}) = p(\\mathcal{D} | \\bm{\\theta})p(\\bm{\\theta})$\n    and $Z = p(\\mathcal{D})$, and applying the result (4.135),\n    we obtain the model evidence under the Laplace approximation:\n    \\[\n        p(\\mathcal{D}) \n        = p(\\mathcal{D} | \\bm{\\theta}_{MAP})p(\\bm{\\theta}_{MAP}) \n        \\frac{(2\\pi)^{M/2}}{|\\mathbf{A}|^{1/2}}\n    \\] \n    where $\\bm{\\theta}_{MAP}$ is the value of $\\bm{\\theta}$ at the mode\n    of the posterior distribution, and $\\mathbf{A}$ is the $\\emph{Hessian}$ \n    matrix of second derivatives of the negative log posterior\n    \\begin{equation}\\label{eq:4.138}\\tag{4.138}\n        \\mathbf{A} \n        = -\\nabla \\nabla \\ln p(\\mathcal{D} | \\bm{\\theta}_{MAP})p(\\bm{\\theta}_{MAP})\n        = -\\nabla \\nabla \\ln p(\\bm{\\theta}_{MAP} | \\mathcal{D})\n    \\end{equation}\n\n    Therefore, the log model evidence is given by \n    \\begin{equation}\\label{eq:4.137}\\tag{4.137}\n        \\ln p(\\mathcal{D}) \n        = \\ln p(\\mathcal{D} | \\bm{\\theta}_{MAP}) + \\ln p(\\bm{\\theta}_{MAP})\n        + \\frac{M}{2} \\ln (2\\pi) - \\frac{1}{2} \\ln |\\mathbf{A}|\n    \\end{equation}\n\\end{proof}\n\n\\section*{Exercise 4.25 $\\star \\star$}\nSuppose we wish to approximate the logistic sigmoid $\\sigma(a)$ \ndefined by $(\\ref{eq:4.59})$ by a scaled probit function\n$\\Phi(\\lambda a)$ where $\\Phi(a)$ is defined by $(\\ref{eq:4.114})$.\nShow that if $\\lambda$ is chosen so that the derivatives of the two\nfunctions are equal at $a = 0$, then  $\\lambda^2 = \\pi/8$.\n\n\\vspace{1em}\n\n\\begin{proof}\n    We start by evaluating both function's derivatives at $a=0$.\n    We've seen in Exercise 4.19 that the derivative of the probit function\n    is given by\n     \\[\n         \\pdv{a} \\Phi(a) = \\frac{1}{\\sqrt{2\\pi}} \\exp{-\\frac{a^2}{2}}\n    \\] \n    so\n    \\[\n        \\pdv{a} \\Phi(\\lambda a)\\bigg|_{a=0}\n        = \\frac{\\lambda}{\\sqrt{2\\pi}} \\exp{-\\frac{a^2}{2}}\\bigg|_{a=0}\n        = \\frac{\\lambda}{\\sqrt{2\\pi}}\n    \\] \n    From $(\\ref{eq:4.88})$ we also obtain the derivative of the sigmoid function:\n     \\[\n         \\pdv{a} \\sigma(a)\\bigg|_{a=0} = \\sigma(a)(1 - \\sigma(a))\\bigg|_{a = 0}\n         = \\frac{1}{4}\n    \\] \n    Finally, by using the fact that the derivatives of the functions are\n    equal at $a=0$, we quickly reach the result from the hypothesis, \n    i.e. $\\lambda^2 = \\pi / 8$.\n\\end{proof}\n", "meta": {"hexsha": "457219ed3043717050e0ec13bd0913e503658258", "size": 41311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter4_linear_models_classification.tex", "max_stars_repo_name": "thesstefan/bishop_prml", "max_stars_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter4_linear_models_classification.tex", "max_issues_repo_name": "thesstefan/bishop_prml", "max_issues_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter4_linear_models_classification.tex", "max_forks_repo_name": "thesstefan/bishop_prml", "max_forks_repo_head_hexsha": "22c3e04e54f0ff91fa043d46aa0d760998094d1b", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.9875130073, "max_line_length": 103, "alphanum_fraction": 0.5864055578, "num_tokens": 15854, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.8933094010836643, "lm_q1q2_score": 0.7645398853674118}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\n\\begin{document}\n\n\\subsection{Motivation}\n\nIn this work a tensor approximation problem is investigated. Low-rank decomposition of 2 and 3-dimensional tensors is performed using Tucker HOSVD and CPD algorithms. A gray scale image, an RGB image and a gray scale animation film are used as sample data. Relative error is measured in all cases. \n\n\\subsection{Theoretical background}\n\n\\subsubsection{Tucker, HOSVD}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/tucker}\n\\caption{Tucker decomposition}\n\\label{fig:Lab1:1}\n\\end{figure}\n\nConsider a 3-rd order tensor $\\mathbf{\\underline{X}} \\in \\mathbb{R}^{I \\times J \\times K}$. We define its Tucker Decomposition as  \n\n\\begin{equation}\n\\begin{aligned}\n\\mathbf{\\underline{X}} & \\simeq \\sum_{q=1}^{Q} \\sum_{r=1}^{R} \\sum_{p=1}^{P} g_{qrp} \\mathbf{a}_q \\circ \\mathbf{b}_r \\circ \\mathbf{c}_p\\\\\n& = \\mathbf{\\underline{G}} \\times_1 \\mathbf{A} \\times_2 \\mathbf{B} \\times_3 \\mathbf{C}\\\\\n& = \\Big[    \\mathbf{\\underline{G}} ;  \\mathbf{A},  \\mathbf{B}, \\mathbf{C}      \\Big]\n\\end{aligned}\n\\end{equation}\n\nwhere $\\mathbf{\\underline{G}}$ is a dense core tensor with multi-linear rank $(Q,R,P)$ and $\\mathbf{A} \\in \\mathbb{R}^{I \\times Q}, \\mathbf{B} \\in \\mathbb{R}^{J \\times R}$ are factor matrices.\n\nConsider a 3-rd order tensor $\\mathbf{\\underline{X}} \\in \\mathbb{R}^{I \\times J \\times K}$, decomposed in the Tucker format as \n\n$$\n\\mathbf{\\underline{X}} = \\mathbf{\\underline{G}} \\times_1 \\mathbf{A} \\times_2 \\mathbf{B} \\times_3 \\mathbf{C}\n$$\n\nThe \\textbf{HOSVD} is a special case of the Tucker decomposition, in which all the factor matrices are constrained to be orthogonal. They are computed as truncated version of the left singular matrices of all possible mode- unfoldings of tensor $\\mathbf{\\underline{X}}$:\n\n\\begin{equation}\n\\begin{aligned}\n\\mathbf{X}_{(1)} &= \\mathbf{U}_1  \\mathbf{\\Sigma}_1 \\mathbf{V}_1^T \\quad \\rightarrow \\quad \\mathbf{A} = \\mathbf{U}_1[1:R_1]\\\\\n\\mathbf{X}_{(2)} &= \\mathbf{U}_2  \\mathbf{\\Sigma}_2 \\mathbf{V}_2^T \\quad \\rightarrow \\quad \\mathbf{B} = \\mathbf{U}_2[1:R_2] \\\\\n\\mathbf{X}_{(3)} &= \\mathbf{U}_3  \\mathbf{\\Sigma}_3 \\mathbf{V}_3^T \\quad \\rightarrow \\quad \\mathbf{C} = \\mathbf{U}_3[1:R_3] \\\\\n\\end{aligned}\n\\end{equation}\n\n\\break \n\n\\subsubsection{CPD}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/cpd_decomp}\n\\caption{CPD decomposition}\n\\label{fig:Lab1:2}\n\\end{figure}\n\nConsider a 3-rd order tensor $\\mathbf{\\underline{X}} \\in \\mathbb{R}^{I \\times J \\times K}$. We define its CPD Decomposition as \n\n\\begin{equation}\n\\begin{aligned}\n\\mathbf{\\underline{X}} & \\simeq \\sum_{r=1}^{R} \\lambda_r \\mathbf{a}_r \\circ \\mathbf{b}_r \\circ \\mathbf{c}_r\\\\\n& = \\mathbf{\\underline{\\Lambda}} \\times_1 \\mathbf{A} \\times_2 \\mathbf{B} \\times_3 \\mathbf{C}\\\\\n& = \\Big[    \\mathbf{\\underline{\\Lambda}} ;  \\mathbf{A},  \\mathbf{B}, \\mathbf{C}      \\Big]\n\\end{aligned}\n\\end{equation}\n\nwhere $\\mathbf{\\underline{\\Lambda}}$ is a 3-rd order core tensor having $\\lambda_r$ as entries at positions $\\mathbf{\\underline{\\Lambda}}[i, j, k]$ where $\\mathbf{\\underline{\\Lambda}}[i, j, k]$ and zeros elsewhere; $\\mathbf{A}, \\mathbf{B}, \\mathbf{C}$ are factor matrices obtained as the concatenation of the corresponding factor vectors, i.e $\\mathbf{A} = \\Big[    \\mathbf{a}_1 \\mathbf{a}_2  \\cdots \\mathbf{a}_R   \\Big]$.\n\n\\subsection{Experiments}\n\n\\textbf{NB:} Jupyter Notebook with the code can be found at \\url{https://github.com/evgeniishch/mm_forecasting}.\n\nAs an experiment both HOSVD and CPD decompositions are applied to 3-dimensional tensors. \n\n\\subsection{RGB image}\n\nRGB image is formally a 3-dimensional tensor, however not completely honest as its RBG features are unordered and can be viewed as categorical. Yet it is good to start with.\n\nA $100 \\times 100 \\times 3$ RGB image tensor is decomposed via HOSVD and CPD algorithms:\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/tucker_img}\n\\caption{Comparison of original image and image reconstructed from HOSVD decomposition with rank 5}\n\\label{fig:Lab1:3}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/cpd_img}\n\\caption{Comparison of original image and image reconstructed from CPD decomposition with rank 5}\n\\label{fig:Lab1:4}\n\\end{figure}\n\nFor each decomposed tensor a residual tensor is computed and relative error of approximation is calculated w.r.t. decomposition rank:\n\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/HOSVD_err}\n\\caption{Relative error of HOSVD decomposition w.r.t. decomposition rank}\n\\label{fig:Lab1:5}\n\\end{figure}\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/CPD_err}\n\\caption{Relative error of CPD decomposition w.r.t. decomposition rank}\n\\label{fig:Lab1:6}\n\\end{figure}\n\nFor entertainment purposes, a picture of a dog and a picture of a cake are decomposed with CPD algorithm. We offer the reader to distinguish between them at decomposition rank $2$:\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/cakedog}\n\\caption{Try to distinguish Chihua-hua and a cake}\n\\label{fig:Lab1:7}\n\\end{figure}\n\n\\subsubsection{Animation film}\n\nEarlier, we considered images, which, although they are three-dimensional tensors, are of less interest for research, since the order is not defined on the features for one of the dimensions (RGB). Next, a short gray scale animation film is used as data for decomposition.\n\nA $500 \\times 333 \\times 69$ frame sequence tensor is decomposed via CPD algorithm. A residual tensor is computed and relative error of approximation is calculated w.r.t. decomposition rank:\n\n\\begin{figure}[h!]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/mickey_err}\n\\caption{Relative error of CPD decomposition w.r.t. decomposition rank}\n\\label{fig:Lab1:8}\n\\end{figure}\n\nFrom visual observation a higher reconstruction quality is noticed for regions with high pixel contrast. \n\n\n\\end{document}", "meta": {"hexsha": "e8117fb91533a7fcbe92f8ed476ffc86cd9e17f0", "size": 5996, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/Shchagin2021Lab1/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/Shchagin2021Lab1/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/Shchagin2021Lab1/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": 43.1366906475, "max_line_length": 422, "alphanum_fraction": 0.735323549, "num_tokens": 1893, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604134, "lm_q2_score": 0.8933094167058151, "lm_q1q2_score": 0.7645398757465613}}
{"text": "\\chapter{Integer Division}\r\n\r\n\\section{The Division Algorithm}\r\n\\subsection{A Thought Experiment}\r\n\r\nSuppose that you are playing a game of cards with your friends.  You have a deck of $n$ cards and there are $d$ players in the game.  In this particular game, the practice is to deal out an equal number of cards to each player and to deal out cards until it is no longer possible to do so.\r\n\r\nDealing cards is something most of us have done, but let's review the process.  When you deal cards, in order to make sure everyone gets the same number of cards, you do it in rounds.  On a given round, either you deal one card to each player or you don't deal to anyone.  This requires the dealer to compare the number of undealt to the number of players.\r\n\r\nAs all of the cards are to be dealt out, the prcess will continue until you are unable to deal.  This means you will come to a round where you cannot deal cards to every player.  Let $r$ be the number of cards that are left over.  It is possible that all of the cards have been dealt out, so that $r = 0$, but we know for certain that $r < d$ (recall $d$ is the number of players) because if $r \\ge d$, we would be able to deal another round.\r\n\r\nWhen we are done, each player will have the same number of cards.  Let's say this number is $q$.  Given this, we can now express $n$, the original number of cards, in the following way:\r\n\\[\r\nn = d q + r\r\n\\] \r\nwhere $0\\le r < d$.\r\n\r\n\\subsection{The Division Algorithm}\r\n\r\n", "meta": {"hexsha": "d8e79204b329c9035abec1f7abced9df6a9d77f7", "size": 1471, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "integer_division.tex", "max_stars_repo_name": "pmodl/Notes-on-Mathematics-for-Programming", "max_stars_repo_head_hexsha": "85af856bfe56807217d8fb6934df105d49447b53", "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": "integer_division.tex", "max_issues_repo_name": "pmodl/Notes-on-Mathematics-for-Programming", "max_issues_repo_head_hexsha": "85af856bfe56807217d8fb6934df105d49447b53", "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": "integer_division.tex", "max_forks_repo_name": "pmodl/Notes-on-Mathematics-for-Programming", "max_forks_repo_head_hexsha": "85af856bfe56807217d8fb6934df105d49447b53", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:30:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-15T15:30:18.000Z", "avg_line_length": 73.55, "max_line_length": 443, "alphanum_fraction": 0.7335146159, "num_tokens": 366, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927838, "lm_q2_score": 0.8558511396138365, "lm_q1q2_score": 0.7645398634755655}}
{"text": "\\subsection{Efficient Trajectory Unrolling}\n\\label{text:approach/runtime/unrolling}\nOne of the most promising directions for decreasing the runtime of a trajectory optimization algorithm is to decrease the runtime of the objective and constraints evaluation as well as their gradients. As shown in sections \\ref{text:approach/objective} and \\ref{text:approach/constraint}, the majority of these optimization modules depend on the robot's trajectory $\\x_{0:T}$, rather than on its control inputs $\\u_{0:T}$. However, since control inputs are optimized, as described in Section \\ref{text:approach/overview}, a computationally efficient transformation from controls and initial state to the trajectory is key for making the trajectory optimization real-time feasible.\n\\newline\nFortunately, we assumed that the robot follows double integrator dynamics, which are linear and markovian. Hence, they can be expressed as the following: \n\n\\begin{equation}\n\\x_{t+1} = A \\x_t + B \\u_t\n\\label{eq:dynamics}\n\\end{equation}\n\n\\begin{minipage}{0.5\\textwidth}\n$$A = \\begin{bmatrix} 1 & 0 & \\dt & 0 \\\\ 0 & 1 & 0 & \\dt \\\\ 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 1\\end{bmatrix}$$\n\\end{minipage}\n\\begin{minipage}{0.5\\textwidth}\n$$B = \\begin{bmatrix} 0 & 0 & \\dt & 0 \\\\ 0 & 0 & 0 & \\dt \\end{bmatrix}$$\n\\end{minipage}\n\nDue to the linear (not linearized !) dynamics $\\dt = \\Delta t$ can be safely used. To fully \"unroll\" a trajectory, the linear dynamic equation \\ref{eq:dynamics} would be applied iteratively for the length of the trajectory. Since the dynamics themselves are linear (not just a first-order approximation), this computation can be further batched and, in this way, speed up. In fact, the full trajectory can be derived merely based on the initial state $\\x_0$ and the control input matrix $\\u_{0:T}$, as shown in the following:\n\n\\begin{align}\n\\x_1 &= A \\x_0 + B \\ u_0 \\\\\n\\x_2 &= A \\x_0 + B \\ u_1 = A^2 \\x_0 + A B \\ u_0 + B \\ u_1\\\\\n\\begin{bmatrix} \\x_1 \\\\ \\x_2 \\\\ \\vdots \\\\ \\x_n \\end{bmatrix} &= \\underbrace{\\begin{bmatrix} A \\\\ A^2 \\\\ \\vdots \\\\ A^n \\end{bmatrix}}_{\\substack{A_n}} \\x_0 + \\underbrace{\\begin{bmatrix} B & 0 & \\hdots & \\hdots & 0 \\\\ AB & B & 0 & \\hdots & 0 \\\\ \\hdots & \\hdots & \\hdots & \\hdots & \\hdots \\\\ A^{n-1} B & A^{n-2} B & \\hdots & \\hdots & B \\end{bmatrix}}_{\\substack{B_n}} \\begin{bmatrix} \\u_0 \\\\ \\u_1 \\\\ \\vdots \\\\ \\u_{n-1} \\end{bmatrix}\n\\end{align}\n\nIn summary, we get the following (also linear) expression for computing the full robot trajectory at once. As demonstrated in \\href{https://github.com/simon-schaefer/mantrap/blob/master/examples/timing.ipynb}{examples/tools/timing} using the fully batched formulation speeds up the trajectory \"unrolling\" by about a factor of 30.\n\n\\begin{equation}\n\\x_{1:n} = A_n \\x_0 + B_n \\u_{0:T-1}\n\\label{eq:dynamics_stacked}\n\\end{equation}\n", "meta": {"hexsha": "6c28622a02bb09941a6de7ff5cbce19311edbcdc", "size": 2784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/thesis/runtime_unrolling.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/runtime_unrolling.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/runtime_unrolling.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": 84.3636363636, "max_line_length": 680, "alphanum_fraction": 0.713362069, "num_tokens": 880, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026550642018, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.764410865708555}}
{"text": "\\documentclass[12pt]{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage{latexsym,amsfonts,amssymb,amsthm,amsmath}\n\n\\setlength{\\parindent}{0in}\n\\setlength{\\oddsidemargin}{0in}\n\\setlength{\\textwidth}{6.5in}\n\\setlength{\\textheight}{8.8in}\n\\setlength{\\topmargin}{0in}\n\\setlength{\\headheight}{18pt}\n\n\\newcommand*{\\QEDA}{\\hfill\\ensuremath{\\blacksquare}}%\n\\newcommand*{\\QEDB}{\\hfill\\ensuremath{\\square}}%\n\n\\title{Advanced Algorithms - Homework 3}\n\\author{Kishlaya Jaiswal}\n\n\\begin{document}\n\n\\maketitle\n\n\\vspace{0.5in}\n\n\\subsection*{Exercise 1}\n\n\\begin{proof}\n\\textbf{i)} Given an instance of hitting set $(E, \\mathcal{S})$ where $E$ is the ground set and $\\mathcal{S}$ is a collection of subsets of $E$. We can reduce it to an instance of set cover as follows:\n\nLet universe $\\mathcal{U} = \\mathcal{S}$ and subsets $\\mathcal{S'} = E$ such that $S \\in \\mathcal{S'}$ contains all those elements $u \\in \\mathcal{U}$ where $S \\in u$ in in the hitting set formulation.\n\nConversely, given $(\\mathcal{U}, \\mathcal{S'})$ an instance of set cover, reduce it to hitting set as follows:\n\nLet ground set $E = \\mathcal{S'}$ and subsets $\\mathcal{S} = \\mathcal{U}$ such that $S \\in \\mathcal{S}$ contains all those elements of $e \\in E$ where $S \\in e$ in set cover formulation.\n\nObserve that these reductions are inverses of each other and hence there is a bijection between all instances of set cover and all instances of hitting set. \n\nNow we show that the cost of a feasible solution remains preserved under these reductions.\n\nConsider $(E, \\mathcal{S})$ an instance of hitting set and let $F$ be feasible solution, so $F \\cap S_i \\neq \\phi$ $\\forall S_i \\in \\mathcal{S}$, then the set cover instance will be $(\\mathcal{S}, E)$ and now $F$ corresponds to sets picked as $F \\subseteq E$. $F$ covers the entire universe $\\mathcal{S}$ as $F \\cap S_i \\neq \\phi$.\n\nSimilarly, if $(\\mathcal{U}, \\mathcal{S'})$ is an instance of set cover with a feasible solution $\\mathcal{T} \\subseteq \\mathcal{S'}$ such that $\\bigcup_{T \\in \\mathcal{T}} T = \\mathcal{U}$ then consider the equivalent hitting set instance $(\\mathcal{S'}, \\mathcal{U})$. Clearly, $T_i \\cap \\mathcal{U} \\neq \\phi$ as $\\mathcal{T}$ covers the universe $\\mathcal{U}$. Hence $\\mathcal{T}$ is a feasible solution for hitting set.\n\nThus we have shown that there is a bijection between feasible solutions of same cost of of any equivalent instances of set cover and hitting set. Hence they are essentially the same problem. \n\nFurthermore, from the cost preserving bijection we also get that $OPT(SC) = OPT(HS)$ for any two equivalent instances. \n\nSince we have $\\log n$ approximation for set cover we also get a $\\log n$ approximation for hitting set.\n\nAlso, if know that size of each set $S \\leq f$ in the hitting set instance then we also have a $f-$approximation.\n\n\\textbf{ii)} Let $U$ be the universe with $n$ elements. We pick an element from the universe with probability $p$ (to be decided later), that is we sample $F$ at random from the set of all possible subsets.\n\nLet \n$$Y_i =\n    \\begin{cases}\n        1 & \\text{if } S_i \\text{ is satisfied} \\\\\n        0 & \\text{otherwise}\n    \\end{cases}\n$$\nNote that, $$Pr[Y_i = 1] = Pr[S_i \\text{ is satisfied}] = Pr[|F \\cup S_i| = 1] = |S_i|p(1-p)^{|S_i|-1}$$\n\nDenote by $N = \\sum Y_i$ number of satisfied sets. Then we have,\n\n$$E(N) = \\sum_{i=1}^m E(Y_i) = \\sum_{i=1}^m Pr[Y_i = 1] = \\sum_{i=1}^m |S_i|p(1-p)^{|S_i|-1}$$\n\nSuppose the size of all sets is the same, say $k$. Set $p = \\frac{1}{k}$ then $$E(N) = \\sum_{i=1}^m k\\left(\\frac{1}{k}\\right)\\left(1-\\frac{1}{k}\\right)^{k-1} =  m\\left(1-\\frac{1}{k}\\right)^{k-1}$$\n\n\\textbf{Case 1}: $k=1$. We set $p=1$ that is we pick all the elements. In this case, assuming the sets were all distinct, we have indeed achieved optimum as $E(N) = m = OPT$\n\\newline\n\\newline\n\\textbf{Case 2}: Since $\\left(\\frac{k}{k-1}\\right)^{k-1} = \\left(1+\\frac{1}{k-1}\\right)^{k-1} \\leq e$ and Since, $OPT \\leq m$, \n\nwe get $\\boxed{E(N) \\geq \\frac{1}{e} OPT}$\n\n\\textbf{iii)} Say the universe $\\mathcal{U}$ has $n$ elements. We consider the partition $(0,n] = (\\frac{n}{2},n] \\cup (\\frac{n}{4},\\frac{n}{2}] \\cup (\\frac{n}{8},\\frac{n}{4}] \\cup \\ldots$. Now, size of each set $S_i$ lies in one of this partition. Since there are $\\lg n$ many partitions, there exists one partition $(\\frac{k}{2},k]$ such that atleast $\\frac{m}{\\lg n}$ many sets have size in $(\\frac{k}{2},k]$.\n\nWe shall consider only these sets. Then repeating the experiment same as above, we get\n$$E(N) \\geq \\sum_{i: |S_i| \\in (k/2,k]} \\frac{k}{2} \\left(\\frac{1}{k}\\right)\\left(1-\\frac{1}{k}\\right)^{k-1} \\geq  \\frac{m}{2\\lg n} \\left(1-\\frac{1}{k}\\right)^{k-1} \\geq \\frac{1}{2e\\lg n} OPT$$\n\n\\textbf{iv)} We have the following LP formulation for the unique hitting set instance:\n\\begin{align*}\n    \\text{Maximize } \\sum_{i=1}^m y_j \\\\\n    \\sum_{i \\in S_j} x_i = y_j && \\forall j \\leq m \\\\\n    x_i \\in \\{0,1\\} && \\forall i \\leq n \\\\\n    y_j \\in \\{0,1\\} && \\forall j \\leq m \\\\\n\\end{align*}\n\nThe above LP has a optimal solution $OPT = m$ because it is given that given instance has the perfect hitting set property.\n\nRelaxing the above LP, we get:\n\n\\begin{align*}\n    \\text{Maximize } \\sum_{i=1}^m y_j \\\\\n    \\sum_{i \\in S_j} x_i = y_j && \\forall j \\leq m \\\\\n    0 \\leq x_i \\leq 1 && \\forall i \\leq n \\\\\n    0 \\leq y_j \\leq 1 && \\forall j \\leq m \\\\\n\\end{align*}\n\nLet $(x^*, y^*)$ be the optimal solution. Then we choose the $i^{th}$ element with probability $x_i^*$.\n\nLet $q_k = \\prod_{j \\in S_k} (1- x_j^*)$, then probability that a set $S_k$ is satisfied is \n$$\\sum_{i \\in S_k} x_i^* \\prod_{\\substack{j \\in S_k \\\\ j \\neq i}} (1-x_j^*) = \\sum_{i \\in S_k} \\frac{x_i^*}{1 - x_i^*} q_k$$\n\nHence,\n\\begin{align*}\n    \\text{E(\\# satisfied sets)} &= \\sum_{k=1}^m \\sum_{i \\in S_k} \\frac{x_i^*}{1 - x_i^*} q_k \\\\\n    &= \\sum_{k=1}^m \\sum_{i \\in S_k} \\frac{q_k}{1 - x_i^*} x_i^* \\\\\n    &\\geq \\sum_{k=1}^m \\sum_{i \\in S_k} \\left(1-\\frac{1}{e}\\right) x_i^* \\\\\n    &= \\left(1-\\frac{1}{e}\\right) \\sum_{k=1}^m \\sum_{i \\in S_k} x_i^* \\\\\n    &= \\left(1-\\frac{1}{e}\\right) \\sum_{k=1}^m y_k^* \\\\\n    &\\geq \\left(1-\\frac{1}{e} \\right) m \\\\\n    &= \\left(1-\\frac{1}{e} \\right) OPT\n\\end{align*}\n\n\n\\textbf{v)} Suppose all sets have size $2$. Let us call this problem as $2-$hitting set.\n\n\\textsl{Claim}: $2-$hitting set is as hard to approximate as vertex cover.\n\n\\textsl{Proof}: Given an instance $(V,E)$ of vertex cover. Consider it as an instance of $2-$hitting set with ground set $V$ and each $(u,v)$ edge as a subset.\n\nNow clearly, if we have an $\\alpha-$approximation for $2-$hitting set we get an $\\alpha-$approximation for vertex cover. Furthermore, the above reduction is a poly-time reduction. Hence $2-$hitting set is also NP-hard. \\QEDA\n\nSuppose the sets satisfy $|S_i|=2$ $\\forall S_i$ and it has the perfect hitting set property. Say the ground set is $V$ and subsets $S$. Then consider the graph $(V,S)$ where the vertices are the ground set and edges are $(u,v) \\in S_i$ $\\forall S_i \\in S$.\n\nSince it has the perfect hitting property, $\\exists F \\subseteq V$ such that $|F \\cap S_i| = 1$\n\nWe claim that $(F, V \\setminus F)$ is a bi-partition. \n\n\\textsl{Proof}: Suppose there is an edge $S_i$ between two elements of $F \\implies |F \\cap S_i| = 2$ contradiction to perfect hitting property .\n\nSuppose there is an edge $S_i$ between two elements of $V \\setminus F \\implies |F \\cap S_i| = \\phi$ which is a contradiction. \\QEDA\n\nHence the graph so obtained is a bipartite graph.\n\nFor bipartite graphs, we can find minimum vertex cover in poly-time (Konig-egervary theorem) hence we can find $F =$ minimum vertex cover, in poly-time.\n\nTherefore, we can solve hitting set $(E, \\{S_i\\})$ instance with \n\\begin{itemize}\n    \\item $\\forall S_i$ $|S_i| = 2$\n    \\item it has hitting property\n\\end{itemize}\nin polynomial time.\n\n\\end{proof}\n\n\\subsection*{Exercise 2}\nIn class, we have seen a $\\frac{1}{2}(\\sqrt{5}-1)$-approximation algorithm for MAX SAT using biased coins and a randomized $(1-\\frac{1}{e})$-approximation using randomized LP rounding. We show that choosing the better of the two solutions gives a $\\frac{3}{4}$-approximation for MAX SAT.\n\n\\begin{proof}\nLet $W_0$ denote the cost of the solution using biased coins randomized algorithm, $W_1$ denote the cost of the solution using unbiased coins randomized algorithm and $W_2$ denote the cost of the solution using randomized LP-rounding.\n\nWe recall that \n$$E(W_0) \\geq E(W_1)$$\n$$E(W_1) \\geq \\sum_{j=1}^m w_j \\left(1-\\left(\\frac{1}{2}\\right)^{l_j}\\right) $$\nand\n$$E(W_2) \\geq \\sum_{j=1}^m w_jy_j^* \\left(1-\\left(1-\\frac{1}{l_j}\\right)^{l_j}\\right)$$\nwhere $w_j$ is the weight of j-th clause and $y_j^*$ is optimal solution of relaxed LP.\n\nChoosing better of the two solutions corresponds to $W = max(W_0, W_2)$, then we have $max(W_0, W_2) \\geq \\frac{1}{2}W_0+\\frac{1}{2}W_2$. Thus,\n\n\\begin{align*}\n    E(W) &\\geq E\\left(\\frac{1}{2}W_0 + \\frac{1}{2}W_2\\right) \\\\\n    &= \\frac{1}{2}E(W_0) + \\frac{1}{2}E(W_2) \\\\\n    &\\geq \\frac{1}{2}E(W_1) + \\frac{1}{2}E(W_2) \\\\\n    &\\geq \\frac{1}{2}\\left(\\sum_{j=1}^m w_j \\left(1-\\left(\\frac{1}{2}\\right)^{l_j}\\right)\\right) + \\frac{1}{2}\\left(\\sum_{j=1}^m w_jy_j^* \\left(1-\\left(1-\\frac{1}{l_j}\\right)^{l_j}\\right)\\right) \\\\\n    &\\geq \\frac{1}{2}\\left(\\sum_{j=1}^m w_jy_j^* \\left(1-\\left(\\frac{1}{2}\\right)^{l_j}\\right)\\right) + \\frac{1}{2}\\left(\\sum_{j=1}^m w_jy_j^* \\left(1-\\left(1-\\frac{1}{l_j}\\right)^{l_j}\\right)\\right) \\\\\n    & (\\text{because } 0 \\leq y_j^* \\leq 1) \\\\\n    &= \\frac{1}{2}\\sum_{j=1}^m w_jy_j^* \\left( \\left(1-\\left(\\frac{1}{2}\\right)^{l_j}\\right) + \\left(1-\\left(1-\\frac{1}{l_j}\\right)^{l_j}\\right)\\right) \\\\\n\\end{align*}\n\nRemains to show that $\\forall n > 0$\n$$\\left(1-\\left(\\frac{1}{2}\\right)^n\\right) + \\left(1-\\left(1-\\frac{1}{n}\\right)^n\\right) \\geq \\frac{3}{2}$$\n\nLet $$f(x) = 2 - \\left(\\frac{1}{2}\\right)^x - \\left(1-\\frac{1}{x}\\right)^x$$\nThen $f'(x) = - \\left(\\frac{1}{2}\\right)^x\\ln\\frac{1}{2} - \\left(1-\\frac{1}{x}\\right)^x\\left(\\ln(1-\\frac{1}{x})+ \\frac{1}{x-1}\\right) > 0$. Hence $f$ is increasing for $x > 1$ and we get our desired result.\n\n\\end{proof}\n\n\\subsection*{Exercise 2}\n\\begin{proof}\nGiven a graph G, we perform the following experiment E, $n$ times on it:\n\nRemove each edge of G with probability $p$ and retain it with probability $1-p$. If the resulting subgraph is disconnected, then set $X_i = 1$ otherwise, set $X_i = 0$.\n\nNow, set $X = \\frac{X_1+X_2+\\cdots+X_t}{t}$\n\nWe have already seen that $E(X) = p_{fail} = \\mu$ and $V(X) = \\frac{\\mu - \\mu^2}{t} \\leq \\frac{\\mu}{t}$ and so\n$$Pr[|X-\\mu|>\\mu \\epsilon] \\leq \\frac{1}{t\\mu \\epsilon^2} \\leq \\frac{poly(n)}{t \\epsilon^2}$$\nas $\\mu = p_{fail} = \\Omega\\left(\\frac{1}{poly(n)}\\right)$ is given.\n\nIf we set this failure probability to atmost $\\frac{1}{4}$ then we get $t \\geq \\frac{4}{\\epsilon^2}poly(n)$.\n\nNow, we repeat the above entire experiment $s = 2r+1$ times, to get i.i.d. random values $Y_1, Y_2, \\ldots, Y_{s}$. Note that, we have $E(Y_i) = E(X)$ and $V(Y_i) = V(X)$ and so\n$$Pr[|Y_i-\\mu|>\\mu \\epsilon] \\leq \\frac{1}{t\\mu \\epsilon^2}$$\n\nLet $Y = median(Y_1, Y_2, \\ldots, Y_{2r+1})$.\n\nWe want to have failure probability atmost $\\delta$ for $Y$ that is $Pr[|Y-\\mu| > \\mu \\epsilon] \\leq \\delta$.\n\nFor that, we note that if $|Y-\\mu| > \\mu \\epsilon$ then two of the following can happen:\n\\begin{itemize}\n    \\item $Y < (1-\\epsilon)\\mu$. Since $Y$ was the median, we must have $r+1$ many experiments to fail from below, that is there are $r+1$ many values for $i$ such that $Y_i < (1-\\epsilon)\\mu$.\n    \\item $Y > (1+\\epsilon)\\mu$. Since $Y$ was the median, we must have $r+1$ many experiments to fail from above, that is there are $r+1$ many values for $i$ such that $Y_i > (1-\\epsilon)\\mu$.\n\\end{itemize}\n\nNow, we set $p = \\frac{1}{t\\mu\\epsilon^2}$ and $q = 1-p$. Note that $p \\leq \\frac{1}{4} \\implies q \\geq \\frac{3}{4}$. \n\nWe look at some inequalities first:\n\\begin{align}\n    \\forall k \\leq r, \\frac{q^kp^{2r+1-k}}{q^rp^r} = p\\left(\\frac{p}{q}\\right)^{r-k} \\leq 1  \\\\\n    \\sum_{k=0}^{r} {2r+1 \\choose k} \\leq \\sum_{k=0}^{2r+1} {2r+1 \\choose k} = 2^{2r+1} \\\\\n    4q-4q^2 = 1 - (2q-1)^2 \\leq 1 - \\left(\\frac{1}{2}\\right)^2 \\leq \\frac{3}{4}\n\\end{align}\n\nHence, we get\n\\begin{align*}\n    Pr[|Y-\\mu| > \\mu \\epsilon] &= Pr[|Y_i-\\mu| > \\mu \\epsilon \\text{ for atleast } r+1 \\text{ many values of } i] \\\\\n    &= Pr[|Y_i-\\mu| > \\mu \\epsilon \\text{ for exactly } r+1 \\text{ many values of } i] \\\\\n    & + Pr[|Y_i-\\mu| > \\mu \\epsilon \\text{ for exactly } r+2 \\text{ many values of } i] + \\cdots \\\\\n    & \\cdots + Pr[|Y_i-\\mu| > \\mu \\epsilon \\text{ for exactly } 2r+1 \\text{ many values of } i] \\\\\n    &= \\sum_{k=r+1}^{2r+1} {2r+1 \\choose k} p^k q^{2r+1-k} \\\\\n    &= \\sum_{k=0}^{r} {2r+1 \\choose k} q^k p^{2r+1-k} \\\\\n    &\\leq \\sum_{k=0}^{r} {2r+1 \\choose k} q^r p^r &\\text{from }(1)\\\\\n    &= (q-q^2)^r \\sum_{k=0}^{r} {2r+1 \\choose k} \\\\\n    &\\leq (q-q^2)^r 2^{2r} &\\text{from }(2)\\\\\n    &= (4q-4q^2)^r  \\\\\n    &\\leq \\left(\\frac{3}{4}\\right)^r &\\text{from }(3)\\\\\n    &\\leq \\delta \\\\\n\\end{align*}\n\nNow, we get $$r \\geq \\frac{\\log\\frac{1}{\\delta}}{\\log\\frac{4}{3}} \\implies s \\geq \\frac{2\\log\\frac{1}{\\delta}}{\\log\\frac{4}{3}} + 1$$\n\nHence, $s = \\Omega(\\log\\frac{1}{\\delta})$.\n\nSo total time required is $t' = st \\geq \\frac{4}{\\epsilon^2}poly(n)\\log\\frac{1}{\\delta}$. Hence $t' = \\Omega\\left(\\log \\frac{1}{\\delta}\\right)$.\n\\end{proof}\n\n\\subsection*{Exercise 3}\n\\begin{proof}\nFor an assignment $a$, denote by $p(a)$ the probability of choosing that assignment where each variable is set to $1$ (or $0$) with probability $p$ (or $1-p$) independently. Further, for any given set $S$ of assignments, denote by $p(S) = \\sum_{a \\in S} p(a)$.\n\nLet $S_i$ be the set of all satisfying assignments for the clause $C_i$ and set $\\mathcal{S} = \\bigcup_{i=1}^m S_i$.\n\nThen $p(\\mathcal{S}) = \\sum_{a \\in \\mathcal{S}} p(a)$ is the number we need to approximate.\n\nWe first make a ($m$ x $|\\mathcal{S}|$) table $T$ where the rows are indexed by the clauses and columns are indexed by the assignments $\\mathcal{S}$. For each entry $(C_i, a)$ in the $T$, set it to $p(a)$ if $a$ satisfies $C_i$ otherwise set it to $0$. Mark the first non-zero entry in each column as special.\n\nNow we perform the following experiment:\n\n\\begin{itemize}\n    \\item Choose a clause $C_i$ with probability $\\frac{p(S_i)}{p(U)}$ where $p(U) = \\sum p(S_i)$\n    \\item Having chosen a clause $C_i$, choose an assignment $a$ from set $S_i$ at random\n    \\item Set $X_n = 1$ iff the chosen assignment $a$ is special, otherwise $X_n = 0$\n\\end{itemize}\n\n$E[X_n] = Pr[X_n = 1] = \\frac{p(\\mathcal{S})}{p(U)}$\n\nNow let $X = \\frac{\\sum_{n \\leq t} X_n}{t}$ and $Y = p(U) X$.\n\nThen $Y$ approximates $p(\\mathcal{S})$ as $E[Y] = p(\\mathcal{S})$ and by law of large numbers, for large enough $t$, $Y \\sim p(\\mathcal{S})$.\n\n[Note: We can compute $p(U) = \\sum p(S_i)$ in polynomial time as $p(S_i) = \\sum p^{p_i}(1-p)^{n_i}$ where the sum runs over all possibilities for the variables not occurring in $C_i$]\n\\end{proof}\n\n\\subsection*{Exercise 4}\n\\begin{proof}.\n\n\\begin{itemize}\n    \\item Probability two balls $B_i$ and $B_j$ fall into the same bin = $\\sum_{k=1}^n$ Probability $B_i$ falls in bin $k$ and $B_j$ fall in bin $k$  = $\\sum_{k=1}^n (1/n^2) = \\boxed{\\frac{1}{n}}$\n    \n    \\item Let $X_{ij} = 1$ iff ball $B_i$ and ball $B_j$ collide otherwise $X_{ij} = 0$. Then the total number of collisions $X = \\sum_{i \\neq j} X_{ij}$. \n    \n    Hence, expected number of collisions = $E[X] = \\sum_{i \\neq j} E[X_{ij}] = \\sum_{i \\neq j} \\frac{1}{n} = \\boxed{{m \\choose 2} \\frac{1}{n}}$\n    \n    \\item Probability that a particular bin is empty = $\\boxed{\\left(1-\\frac{1}{n}\\right)^m}$. \n    \n    Let $Y_k = 1$ iff bin $k$ is empty. Then total number of empty bins $Y = \\sum_{k=1}^n Y_k$. \n    \n    Hence, expected number of empty bins = $E[Y] = \\sum_{k=1}^n E[Y_k] = \\sum_{k=1}^n (1-\\frac{1}{n})^m = \\boxed{n\\left(1-\\frac{1}{n}\\right)^m}$.\n    \n    \\item Probability that a particular bin has atleast $k$ balls = $\\boxed{{m \\choose k} \\left(\\frac{1}{n}\\right)^k}$\n    \n    \\item Probability that all bins have atmost $k$ balls = $1 -$ Probability that some bin has atleast $k+1$ balls $\\geq$ $1 -$ Probability that some bin has atleast $k$ balls $\\geq 1 - n$(Probability that a particular bin has atleast $k$ balls) \n    \n    Probability that a particular bin has atleast $k$ balls $\\leq {m \\choose k} (\\frac{1}{n})^k \\leq \\left(\\frac{me}{k}\\right)^{k} \\left(\\frac{1}{n}\\right)^{k} = \\left(\\frac{me}{nk}\\right)^{k}$\n    \n    Assume that $\\boxed{m \\leq \\frac{3}{e} n}$, then \n    \n    Probability that a particular bin has atleast $k$ balls $\\leq \\left(\\frac{3}{k}\\right)^{k}$\n    \n    Setting $k = \\frac{3\\ln n}{\\ln \\ln n}$, we get that, Probability that a particular bin has atleast $k$ balls $\\leq \\frac{1}{n^2}$\n    \n    Hence, probability that all bins have atmost $k$ balls $\\geq 1 - \\frac{1}{n}$\n    \n    \\item Let $Z_i = $ number of balls in bin $i$ and $Z = max \\{Z_i | 1\\leq i \\leq n \\}$. Let $k = \\frac{3\\ln n}{\\ln \\ln n}$. We know that $P(Z<k) \\geq 1-\\frac{1}{n}$ and so $P(Z \\geq k) \\leq \\frac{1}{n}$. Now,\n        \\begin{align*}\n            E[Z] &= \\sum_{i} i P(Z=i) \\\\\n            &= \\sum_{i<k} i P(Z=i) + \\sum_{i \\geq k} i P(Z=i) \\\\\n            &\\leq (k-1)P(Z < k) + nP(Z \\geq k) \\leq (k-1)P(Z < k) + 1 \\\\\n            &\\leq (k-1)+1 = k =  \\frac{3\\ln n}{\\ln \\ln n}\n        \\end{align*}\n    Thus, $E[Z] = \\frac{\\ln n}{\\ln \\ln n}(1+O(1))$\n\\end{itemize}\n\n\n\n\\textbf{Analysis:}\n\n1. Stirling's approximation: \n$$e \\sqrt{n}\\left(\\frac{n}{e}\\right)^n \\leq n! \\leq \\sqrt{2 \\pi n}\\left(\\frac{n}{e}\\right)^n$$\n\n2. ${n \\choose k} \\leq (\\frac{ne}{k})^k$\n\\begin{align*}\n    {n \\choose k} &\\leq \\frac{n!}{k!(n-k)!} \\\\\n    &\\leq \\frac{e\\sqrt{n}\\left(\\frac{n}{e}\\right)^n}{\\sqrt{2\\pi k}\\left(\\frac{k}{e}\\right)^k \\sqrt{2 \\pi (n-k)}\\left(\\frac{n-k}{e}\\right)^{n-k}} \\\\ \n    &\\leq \\frac{e}{2\\pi}\\sqrt{\\frac{n}{k(n-k)}} \\left(\\frac{n}{k}\\right)^k \\left(\\frac{n}{n-k}\\right)^{n-k} \\\\\n    &\\leq \\frac{e}{\\pi} \\left(\\frac{n}{k}\\right)^k \\left(1 + \\frac{k}{n-k}\\right)^{n-k} \\\\\n    &\\leq \\frac{e}{\\pi} \\left(\\frac{n}{k}\\right)^k e^k \\\\\n    &\\leq \\left(\\frac{ne}{k}\\right)^k \\\\\n\\end{align*}\n\n3. $(\\ln n)/n$ is a decreasing function $\\forall n \\geq 1$ (decreases to $0$) and hence $(\\ln n)/n \\leq \\frac{1}{3}$ eventually.\n\n4. If $k = \\frac{3\\ln n}{\\ln \\ln n}$, then $\\left(\\frac{3}{k}\\right)^k \\leq \\frac{1}{n^2}$ for large enough $n$\n\\begin{align*}\n    \\left(\\frac{3}{k}\\right)^k &= \\exp \\left( k \\ln \\frac{3}{k} \\right) \\\\\n    &= \\exp \\left( \\frac{3\\ln n}{\\ln \\ln n} \\ln \\left(\\frac{\\ln \\ln n}{\\ln n}\\right) \\right) \\\\\n    &= \\exp \\left( \\frac{3\\ln n}{\\ln \\ln n} (\\ln\\ln\\ln n - \\ln \\ln n) \\right) \\\\\n    &= \\exp \\left( -3\\ln n + \\ln n \\frac{3\\ln\\ln\\ln n}{\\ln\\ln n} \\right) \\\\\n    &\\leq \\exp \\left( -3\\ln n +  \\ln n \\right) \\\\\n    &= \\exp \\left( -2\\ln n\\right) \\\\\n    &= \\frac{1}{n^2}\n\\end{align*}\n\\end{proof}\n\n\\vspace{2in} %Leave more space for comments!\n\n\\end{document}\n\n", "meta": {"hexsha": "1e0e59313cc273da69cf57d9b98cdfea476d3b46", "size": 18853, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "advanced_algo/assign3_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": "advanced_algo/assign3_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": "advanced_algo/assign3_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": 55.1257309942, "max_line_length": 424, "alphanum_fraction": 0.6232960272, "num_tokens": 7158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245870332531, "lm_q2_score": 0.9173026658028078, "lm_q1q2_score": 0.764410865164627}}
{"text": "\\chapter{Support Vector Machines}\n\\label{ch:svm}\n\nSupport vector machines (SVM) are another example of linear classifiers, similar to logistic or linear regression. However, SVM can overcome splitting the data by a plane by using the so-called \\textit{kernel trick}. This means the hyperplane (decision boundary) can be transformed to a higher-dimensional space, which can fit the data nicely. In such a way, SVM becomes a non-linear classifier and can fit more complex data sets.\n\n\\begin{marginfigure}\n    \\includegraphics[width=50mm]{linear-regression.png}%\n    \\caption{Decision boundary of a linear regression classifier.}\n  \\end{marginfigure}\n\n\\begin{marginfigure}\n    \\includegraphics[width=50mm]{svm.png}%\n    \\caption{Decision boundary of a support vector machine classifier with an RBF kernel.}\n\\end{marginfigure}\n\nThe magic of SVM (and other methods that can use kernels, and are thus called kernel methods) is that they will implicitly find a transformation into a (usually infinite-dimensional) space, in which the distances between objects are such as prescribed by the kernel, and draw a hyperplane in this space.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[scale=0.5]{workflow.png}\n    \\caption{$\\;$}\n\\end{figure}\n\nAbstract talking aside, SVM with different kernels can split the data not by ordinary hyperplanes, but with more complex curves. The complexity of the curve is decided by the kernel type and by the arguments given to the algorithm, like the degree and coefficients, and the penalty for misclassifications.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[height=70mm]{svm-orange.png}\n    \\caption{$\\;$}\n\\end{figure}\n", "meta": {"hexsha": "45945a3826c5c6e2f53b662c064c36632a17448e", "size": 1663, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/024-svm/svm.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/024-svm/svm.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/024-svm/svm.tex", "max_forks_repo_name": "PrimozGodec/orange-lecture-notes", "max_forks_repo_head_hexsha": "5072afa3e29cec77e1a7f6c0d1fd044e737fe378", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2021-01-19T16:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-21T20:35:41.000Z", "avg_line_length": 53.6451612903, "max_line_length": 430, "alphanum_fraction": 0.772098617, "num_tokens": 383, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7643846917926276}}
{"text": "\\section*{Problem 1 Solution}\n\nFor all parts of this problem, let $R$ be the rate of neutron capture by 1 g of $^{232}$Th, $2.0 \\times 10^{11} \\;\\text{s}^{-1}$.\\\\\n\n\\begin{enumerate}[a)]\n\n\\item\n\nFirst, convert all half-lives and irradiation times to seconds for consistency.\\\\ \n\\-\\\\\n\\tab $\\lambda_{\\text{Th}} = \\frac{\\ln{2}}{1338\\text{s}} = 5.18\\times10^{-4}\\text{s}^{-1}$; \\tab $\\lambda_{\\text{Pa}}=\\frac{\\ln{2}}{2332800s}=2.971\\times10^{-7}\\text{s}^{-1}$; \\tab 1.5 hr = 5400 s\\\\\n\n\\textbf{Thorium-233}\\\\\n\\-\\\\\nThe rate of change of the quantity of $^{233}$Th, $\\frac{dN_{\\text{th}}}{dt}$ is given by the production rate of $^{233}$Th, $R$, minus the decay rate (activity) of $^{233}$Th, $\\lambda_{\\text{Th}}N_{\\text{Th}}$.\n$$\\frac{dN_{\\text{Th}}}{dt} = R - \\lambda_{\\text{Th}}N_{\\text{Th}}$$\nWe solve the differential equation, manipulating the equation so that the left side is only dependent on $N_{\\text{Th}}$ and the right side is only dependent on $dt$. Then we integrate:\n$$\\int{\\frac{dN_{\\text{Th}}}{R-\\lambda_{\\text{Th}}N_{\\text{Th}}}} = \\int{dt}$$\n$$\\frac{-1}{\\lambda_{\\text{Th}}}[\\ln(R-\\lambda_{\\text{Th}}N_{\\text{Th}})] = t + C,\\quad C=\\text{const.}$$\n$$R-\\lambda_{\\text{Th}}N_{\\text{Th}} = e^{-\\lambda_{\\text{Th}}t -\\lambda_{\\text{Th}}C} = e^{-\\lambda_{\\text{Th}}t} e^{-\\lambda_{\\text{Th}}C}$$\nWe note that since $C$ is an arbitrary constant and $\\lambda_{\\text{Th}}$ is fixed, we could also say $e^{-\\lambda_{\\text{Th}}C}$ is an arbitrary constant, and just call it $C$ instead.\n$$ R-\\lambda_{\\text{Th}}N_{\\text{Th}} = Ce^{-\\lambda_{\\text{Th}}t} $$\nWe solve for $N_{\\text{Th}}$ (explicitly including $N_{\\text{Th}}$'s dependence on $t$), and get\n$$ N_{\\text{Th}}(t) = \\frac{R - Ce^{-\\lambda_{\\text{Th}}t}}{\\lambda_{\\text{Th}}} .$$\nAt $t=0,\\; N_{\\text{Th}}(0) = \\frac{R - C}{\\lambda_{\\text{Th}}}=0,$ since no $^{233}$\\text{Th} has been formed. We find $C= R$, and use this in the general equation:\n$$ N_{\\text{Th}}(t) = R\\frac{1 - e^{-\\lambda_{\\text{Th}}t}}{\\lambda_{\\text{Th}}}. $$\nWith this function of $N_{\\text{Th}}$, we can determine the activity as a function of time, knowing that\n$$ \\mathcal{A}_{\\text{Th}}(t) = \\lambda_{\\text{Th}}N_{\\text{Th}}(t). $$\nSubstituting, we find\n$$ \\mathcal{A}_{\\text{Th}}(t) = R(1-e^{-\\lambda_{\\text{Th}}t}) .$$\nUsing the numerical values for $R$, $\\lambda_{\\text{Th}}$, and $t$,\n$$ \\mathcal{A}_{\\text{Th}}(1.5\\text{ hr}) =(2.0\\times10^{11}s^{-1})(1-e^{(-5.18\\times10^{-4}\\text{s}^{-1})(5400s)}) $$\n$$ \\mathcal{A}_{\\text{Th}}(1.5\\text{ hr}) = 1.878\\times10^{11}\\text{ Bq} .$$\nFinally, we convert this to Curies,\n$$\\boxed{ \\mathcal{A}_{\\text{Th}}(1.5\\text{ hr}) = 5.076\\text{ Ci} }.$$\n\n\\textbf{Protactinium-233}\\\\\n\\-\\\\\nWe follow a similar procedure for $^{233}$Pa, noting that the production rate of $^{233}$Pa is just the activity of $^{233}$Th as it decays into $^{233}$Pa, $\\mathcal{A}_{\\text{Th}}$.\n$$\\frac{dN_{\\text{Pa}}}{dt} = \\mathcal{A}_{\\text{Th}} - \\lambda_{\\text{Pa}}N_{\\text{Pa}}$$\nFrom above, we can substitute our function for $\\mathcal{A}_{\\text{Th}}(t)$,\n$$\\frac{dN_{\\text{Pa}}}{dt} = R(1-e^{-\\lambda_{\\text{Th}}t}) - \\lambda_{\\text{Pa}}N_{\\text{Pa}}$$\nSince we cannot separate both sides to be dependent only on a single differential, we must try a different method of integration. We will use integrating factors. Still, we start in a similar fashion: collecting the terms dependent on $N_{\\text{Pa}}$ on the same side.\n$$ \\frac{dN_{\\text{Pa}}}{dt}+\\lambda_{\\text{Pa}}N_{\\text{Pa}} = R(1-e^{-\\lambda_{\\text{Th}}t}) $$\nThe method of integrating factors suggests that we multiply both sides by an arbitrary exponential. We will use $e^{\\lambda_{\\text{Pa}}t}$.\n$$ e^{\\lambda_{\\text{Pa}}t}\\frac{dN_{\\text{Pa}}}{dt} + \\lambda_{\\text{Pa}}e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}} = e^{\\lambda_{\\text{Pa}}t}R(1-e^{-\\lambda_{\\text{Th}}t}) $$\nWe can now observe that the left side of the equation appears to be the result of the product rule when the time derivative of $e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}$ is found. We can then write the equation as\n$$\\frac{d}{dt}(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = e^{\\lambda_{\\text{Pa}}t}R(1-e^{-\\lambda_{\\text{Th}}t})$$\nMoving the $dt$ term to the right side of the equation and using the distributive property, we have\n$$ d(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = R(e^{\\lambda_{\\text{Pa}}t}-e^{\\lambda_{\\text{Pa}}t}e^{-\\lambda_{\\text{Th}}t})dt $$\nor more simply (by exploiting properties of exponents)\n$$ d(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = R(e^{\\lambda_{\\text{Pa}}t}-e^{\\lambda_{\\text{Pa}}t-\\lambda_{\\text{Th}}t})dt .$$\nWe integrate both sides,\n$$ \\int{d\\left(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}\\right)} = \\int{ R(e^{\\lambda_{\\text{Pa}}t}-e^{\\lambda_{\\text{Pa}}t-\\lambda_{\\text{Th}}t})dt}, $$\nseparate the integral on the right side,\n$$ \\int{d\\left(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}\\right)} = R\\int{ e^{\\lambda_{\\text{Pa}}t}dt}-R\\int{e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t}dt} $$\nand find\n$$e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}} = \\frac{R}{\\lambda_{\\text{Pa}}}e^{\\lambda_{\\text{Pa}}t}-\\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t} +\\;C,\\; C=\\text{const.}$$\nNow we factor out the integrating factor back out from both sides and note explicitly the time dependence of $N_{\\text{Pa}}$,\n$$N_{\\text{Pa}}(t) = \\frac{R}{\\lambda_{\\text{Pa}}}-\\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}e^{-\\lambda_{\\text{Th}}t}+Ce^{-\\lambda_{\\text{Pa}}t}$$\nAt $t=0$,\n$$ N_{\\text{Pa}}(0) = \\frac{R}{\\lambda_{\\text{Pa}}}-\\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}+C = 0, $$\n since no $^{233}$\\text{Pa} has been formed. Solving for $C$, we find $C = \\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}-\\frac{R}{\\lambda_{\\text{Pa}}}$. We plug this back into our equation above, and have the solution for $N_{\\text{Pa}}(t)$:\n$$N_{\\text{Pa}}(t) = \\frac{R}{\\lambda_{\\text{Pa}}}-\\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}e^{-\\lambda_{\\text{Th}}t}+\\left( \\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}-\\frac{R}{\\lambda_{\\text{Pa}}} \\right)e^{-\\lambda_{\\text{Pa}}t}$$\nand simplifying\n$$ N_{\\text{Pa}}(t) = \\frac{R}{\\lambda_{\\text{Pa}}}(1-e^{\\lambda_{\\text{Pa}}t})+ \\left(\\frac{R}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}\\right)(e^{-\\lambda_{\\text{Pa}}t}-e^{-\\lambda_{\\text{Th}}t}) .$$\nWith this function of $N_{\\text{Pa}}$, we can determine the activity as a function of time, knowing that\n$$ \\mathcal{A}_{\\text{Pa}}(t) = \\lambda_{\\text{Pa}}N_{\\text{Pa}}(t) .$$\nSubstituting, we find\n$$ \\mathcal{A}_{\\text{Pa}}(t) = R(1-e^{-\\lambda_{\\text{Pa}}t})+ \\left(\\frac{R \\, \\lambda_{\\text{Pa}}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}}\\right)(e^{-\\lambda_{\\text{Pa}}t}-e^{-\\lambda_{\\text{Th}}t}) .$$\nUsing the numerical values for $R$, $\\lambda_{\\text{Th}}$, $\\lambda_{\\text{Pa}}$, and $t$,\n\\begin{dmath*}\n\\mathcal{A}_{\\text{Pa}}(1.5\\text{ hr}) = (2.0\\times10^{11}\\text{ s}^{-1})\\left(1-e^{(-2.971\\times10^{-7}\\text{s}^{-1})(5400\\text{s})}\\right)+ \\left(\\frac{2.0\\times10^{11}\\text{ s}^{-1}(2.791\\times10^{-7}\\text{s}^{-1})}{2.971\\times10^{-7}\\text{s}^{-1}-5.18\\times10^{-4}\\text{s}^{-1}}\\right)\\left(e^{(-2.971\\times10^{-7}\\text{s}^{-1})(5400\\text{s})}-e^{(-5.18\\times10^{-4}\\text{s}^{-1})(5400\\text{s})}\\right)\n\\end{dmath*}\n$$ \\mathcal{A}_{\\text{Pa}}(1.5\\text{ hr}) = 2.195 \\times 10^{8}\\text{ Bq} $$\nFinally, we convert this to Curies, \n$$ \\boxed{\\mathcal{A}_{\\text{Pa}}(1.5\\text{ hr}) = 0.006\\text{ Ci}}. $$\n\n\\item\n\nLet's say that the 1.5 hour mark is now given by $t=t_0=1.5\\text{ hr}$. We also note that 48 hours = 172,800 seconds.\n\n\\textbf{Thorium-233}\\\\\n\\-\\\\\nWithout irradiation, the rate of change of the quantity of $^{233}$Th is now just the decay rate. \n$$ \\frac{dN_{\\text{Th}}}{dt} = -\\lambda_{\\text{Th}}N_{\\text{Th}} $$\nWe separate the equation and integrate, arriving at the standard exponential decay formula, now including the explicit time dependence.\n$$ \\int_{N_{\\text{Th}}(t_0)}^{N_{\\text{Th}}(t)} \\frac{-dN_{\\text{Th}}'}{\\lambda_{\\text{Th}}N_{\\text{Th}}'} = \\int_{t_0}^{t} dt' $$\n$$ \\frac{-1}{\\lambda_{\\text{Th}}}\\left[ \\ln{N_{\\text{Th}}} \\right]_{N_{\\text{Th}(t_0)}}^{N_{\\text{Th}}(t)} = \\left[t'\\right]_{t_0}^{t} $$\n$$ \\ln\\frac{N_{\\text{Th}}(t)}{N_{\\text{Th}}(t_0)}  = -\\lambda_{\\text{Th}}(t-t_0) $$\n$$ \\frac{N_{\\text{Th}}(t)}{N_{\\text{Th}}(t_0)}  = e^{-\\lambda_{\\text{Th}}(t-t_0)} $$\nand we have \n$$ N_{\\text{Th}}(t) = N_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}\\left(t-t_0\\right)} $$\nGiven the definition of activity as $\\mathcal{A} = \\lambda N$ and noting $\\lambda_{\\text{Th}} N_{\\text{Th}}(t_0) = \\mathcal{A}_{\\text{Th}}(t_0)$, we can write the activity of $^{233}$Th as\n\\begin{align*}\n\\mathcal{A}_{\\text{Th}}(t)\t&= \\lambda_{\\text{Th}} N_{\\text{Th}}(t) \\\\\n\t\t\t\t\t\t\t&= \\lambda_{\\text{Th}} N_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)} \\\\ \n\t\t\t\t\t\t\t&= \\mathcal{A}_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)}\n\\end{align*}\nUsing the numerical values for $\\lambda_{\\text{Th}}$, $t$, and our answer from part (a) for the activity at $t_0=1.5$ hr, we find\n$$ \\mathcal{A}_{\\text{Th}}(49.5\\text{ hr}) = (5.076 \\text{ Ci})e^{-5.18\\times10^{-4}\\text{s}^{-1} (172800\\text{s})} $$\n$$ \\boxed{\\mathcal{A}_{\\text{Th}}(49.5\\text{ hr}) = 6.787\\times10^{-39}\\text{ Ci}} $$\n\n{\\small Note: we could also have assumed that since 48 hours is many (more than 100) times longer than the half-life of $^{233}$Th, that the activity would be approximately zero.}\n\\-\\\\\n\\-\\\\\n\n\\textbf{Protactinium-233}\\\\\n\\-\\\\\nWe follow the example in part (a) for $^{233}$Pa, again using the activity of $^{233}$Th as the production rate of $^{233}$Pa.\n$$ \\frac{dN_{\\text{Pa}}}{dt} = \\mathcal{A}_{\\text{Th}} - \\lambda_{\\text{Pa}}N_{\\text{Pa}}. $$\nWe collect terms dependent on $N_{\\text{Pa}}$ on one side,\n$$ \\frac{dN_{\\text{Pa}}}{dt} + \\lambda_{\\text{Pa}}N_{\\text{Pa}} = \\mathcal{A}_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)}, $$\nmultiply both sides by arbitrary exponential $e^{\\lambda_{\\text{Pa}}t}$,\n$$ e^{\\lambda_{\\text{Pa}}t}\\frac{dN_{\\text{Pa}}}{dt} + \\lambda_{\\text{Pa}}e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}} = e^{\\lambda_{\\text{Pa}}t}\\mathcal{A}_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)}, $$\nnote that the left side is the result of the product rule when $\\frac{d}{dt}$ is taken on $e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}$\n$$ \\frac{d}{dt} (e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = e^{\\lambda_{\\text{Pa}}t}\\mathcal{A}_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)}, $$\nmultiply by the differential, $dt$,\n$$ d(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = e^{\\lambda_{\\text{Pa}}t}\\mathcal{A}_{\\text{Th}}(t_0) e^{-\\lambda_{\\text{Th}}(t-t_0)} dt ,$$\nand rearrange,\n$$ d(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}) = \\mathcal{A}_{\\text{Th}}(t_0) e^{(\\lambda_{\\text{Pa}} - \\lambda_{\\text{Th}})t + \\lambda_{\\text{Th}}t_0} dt .$$\nThen we integrate,\n$$ \\int_{e^{\\lambda_{\\text{Pa}}t_0}N_{\\text{Pa}}(t_0)}^{e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}(t)} d(e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}') = \\mathcal{A}_{\\text{Th}}(t_0)e^{\\lambda_{\\text{Th}}t_0} \\int_{t_0}^{t} e^{(\\lambda_{\\text{Pa}} - \\lambda_{\\text{Th}})t'} dt' ,$$\nand find,\n$$ \\left[e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}'\\right]_{e^{\\lambda_{\\text{Pa}}t_0}N_{\\text{Pa}}(t_0)}^{e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}(t)} = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)e^{\\lambda_{\\text{Th}}t_0}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left[ e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t'}\\right]_{t_0}^{t} $$\n$$ e^{\\lambda_{\\text{Pa}}t}N_{\\text{Pa}}(t) - e^{\\lambda_{\\text{Pa}}t_0}N_{\\text{Pa}}(t_0) = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)e^{\\lambda_{\\text{Th}}t_0}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left[ e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t} - e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t_0} \\right] $$\nFactoring out the integrating factor, \n$$ N_{\\text{Pa}}(t) - e^{-\\lambda_{\\text{Pa}}(t - t_0)}N_{\\text{Pa}}(t_0) = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)e^{\\lambda_{\\text{Th}}t_0}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left[ e^{-\\lambda_{\\text{Th}}t} - e^{-\\lambda_{\\text{Pa}}t}e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t_0} \\right] $$\nand solve for $ N_{\\text{Pa}}(t)$,\n$$ N_{\\text{Pa}}(t) = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)e^{\\lambda_{\\text{Th}}t_0}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left[ e^{-\\lambda_{\\text{Th}}t} - e^{-\\lambda_{\\text{Pa}}t}e^{(\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}})t_0} \\right] + e^{-\\lambda_{\\text{Pa}}(t-t_0)}N_{\\text{Pa}}(t_0) .$$\nRearranging,\n$$ N_{\\text{Pa}}(t) = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left[ e^{-\\lambda_{\\text{Th}}(t - t_0)} - e^{-\\lambda_{\\text{Pa}}(t-t_0)} \\right] + e^{-\\lambda_{\\text{Pa}}(t - t_0)}N_{\\text{Pa}}(t_0) .$$\nand so\n$$ N_{\\text{Pa}}(t) = \\frac{\\mathcal{A}_{\\text{Th}}(t_0)}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} e^{-\\lambda_{\\text{Th}}(t-t_0)} + \\left( N_{\\text{Pa}}(t_0) - \\frac{\\mathcal{A}_{\\text{Th}}(t_0)}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\right) e^{-\\lambda_{\\text{Pa}}(t-t_0)} $$\nGiven the definition of activity as $\\mathcal{A} = \\lambda N$ and noting $\\lambda_{\\text{Pa}} N_{\\text{Pa}}(t_0) = \\mathcal{A}_{\\text{Pa}}(t_0)$, we can write the activity of $^{233}$Pa as\n\\begin{align*}\n\\mathcal{A}_{\\text{Pa}}(t)\t&= \\lambda_{\\text{Pa}} N_{\\text{Pa}}(t) \\\\\n\t\t\t\t\t\t\t&=\\lambda_{\\text{Pa}} \\left(\\frac{\\mathcal{A}_{\\text{Th}}(t_0)}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} e^{-\\lambda_{\\text{Th}}(t-t_0)} + \\left( N_{\\text{Pa}}(t_0) - \\frac{\\mathcal{A}_{\\text{Th}}(t_0)}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\right) e^{-\\lambda_{\\text{Pa}}(t-t_0)}\\right) \\\\\n\t\t\t\t\t\t\t&= \\frac{\\mathcal{A}_{\\text{Th}}(t_0) \\lambda_{\\text{Pa}}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} e^{-\\lambda_{\\text{Th}}(t-t_0)} + \\left( \\mathcal{A}_{\\text{Pa}}(t_0) - \\frac{\\mathcal{A}_{\\text{Th}}(t_0) \\lambda_{\\text{Pa}}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\right) e^{-\\lambda_{\\text{Pa}}(t-t_0)} \\\\\n\t\t\t\t\t\t\t&= \\mathcal{A}_{\\text{Pa}}(t_0) e^{-\\lambda_{\\text{Pa}}(t-t_0)} +  \\frac{\\mathcal{A}_{\\text{Th}}(t_0) \\lambda_{\\text{Pa}}}{\\lambda_{\\text{Pa}}-\\lambda_{\\text{Th}}} \\left( e^{-\\lambda_{\\text{Th}}(t-t_0)} - e^{-\\lambda_{\\text{Pa}}(t-t_0)} \\right) \\\\\n\\end{align*}\nUsing the numerical values for $\\lambda_{\\text{Th}}$, $\\lambda_{\\text{Pa}}$, $t$, and our answer from part (a) for the activities at $t=t_0=1.5$ hr, we find\n\\begin{dmath*}\n\\mathcal{A}_{\\text{Pa}}(49.5\\text{ hr}) = (0.006\\text{ Ci}) e^{-(2.971\\times10^{-7}\\text{s}^{-1})(172800s)} +  \\frac{(5.076\\text{ Ci}) (2.971\\times10^{-7}\\text{s}^{-1})}{2.971\\times10^{-7}\\text{s}^{-1}-5.18\\times10^{-4}\\text{s}^{-1}} \\left( e^{-(5.18\\times10^{-4}\\text{s}^{-1})(172800s)} - e^{-(2.971\\times10^{-7}\\text{s}^{-1})(172800s)} \\right)\n\\end{dmath*}\n$$\\boxed{ \\mathcal{A}_{\\text{Pa}}(49.5\\text{ hr}) = 0.008\\text{ Ci} }$$\n\n\\item \n\nNote that $\\lambda_{\\text{U}} = \\frac{\\ln 2}{5.024^{12}\\text{s}} = 1.380\\times10^{-13}\\text{s}^{-1}$. \n\nIn just one day, the probability that any given $^{233}$Th nucleus survives is\n$$ P = e^{-\\lambda_{\\text{Th}}t_d} $$\n$$ P = e^{-(5.18\\times10^{-4}\\text{ s}^{-1})(86,400\\text{ s})} \\approx 10^{-20} $$\nWe can therefore assume that each thorium nucleus produced in the reactor has decayed into $^{233}$Pa by the end of the first day of storage. (There were only about $10^{15}$ thorium nuclei produced in total).\nThe probability that any one of these $^{233}$Pa atoms remains after one year---assumed to be 364 more days---is\n$$ P = e^{-\\lambda_{\\text{Pa}}(t_y-t_d)} $$\n$$ P = e^{-(2.971\\times10^{-7}\\text{ s}^{-1})(31449600\\text{ s})} = 8.752\\times10^{-5}  $$\nWhile this probability indicates that some $^{233}$Pa nuclei will remain after the year of storage, they hardly make up a substantial fraction of the originally produced set of nuclei. We can assume that in one year, virtually every nucleus of $^{233}$Th has decayed at least into $^{233}$U.  \n\nFor uranium-233 on the other hand, the probability of survival for a nucleus over a year is\n$$ P = e^{-\\lambda_{\\text{U}}t_y} $$\n$$ P = e^{-(1.380\\times10^{-13})(31536000\\text{ s})} $$\n$$ P = 0.999996 $$\nWe see that while nearly every nucleus decays from $^{233}$Th into $^{233}$Pa and then into $^{233}$U, almost no nuclei seem to decay from $^{233}$U in the single year.\nWe can then use our simple formula for the activity of the uranium sample\n$$ \\mathcal{A}_{\\text{U}} = \\lambda_{\\text{U}} N_{\\text{U}}$$\n\nUsing our rate of production, there are $2.0\\times10^{11}\\text{ s}^{-1}*(3600\\text{ s/hr}\\times 1.5 \\text{hr}) \\approx 1.08\\times10^{15}$ produced in the irradiation period. We will assume this is also equal to the number of nuclei of $^{233}$U present at the end of the 1 year storage period: $N_U \\approx 10^{15}$. We can finally calculate the activity, as \n$$ \\mathcal{A}_{\\text{U}} = (1.380\\times10^{-13}\\text{s}^{-1})(1.08\\times10^{15}) .$$\nThis is ${149.04}\\text{ Bq}$ or \n$$\\boxed{ 4.028\\times10^{-9}\\text{ Ci} }$$\n\\end{enumerate}\n\n", "meta": {"hexsha": "1090cf4fe28abc5ef884f2dfe4ad836840955891", "size": 16697, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc01/disc01_solution01.tex", "max_stars_repo_name": "mitchnegus/NE150-discussion", "max_stars_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "exercises/drafts/disc01/disc01_solution01.tex", "max_issues_repo_name": "mitchnegus/NE150-discussion", "max_issues_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "exercises/drafts/disc01/disc01_solution01.tex", "max_forks_repo_name": "mitchnegus/NE150-discussion", "max_forks_repo_head_hexsha": "1d2afe0fc4830c3d13d491b9d6ccb7819083c5ad", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.4114285714, "max_line_length": 406, "alphanum_fraction": 0.6171168473, "num_tokens": 6863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726544, "lm_q2_score": 0.8354835452961427, "lm_q1q2_score": 0.7643846915337676}}
{"text": "%\n% Chapter 1.3\n%\n\n\\section*{1.3 More advanced functions}\n\n\\subsection*{Vertical and Horizontal Shifts}\n\nSuppose \\(c>0\\). Then\n\\begin{center}\n\\(y=f(x)+c\\) is the graph of \\(y=f(x)\\) shifted \\(c\\) units upward.\\\\\n\\(y=f(x)-c\\) is the graph of \\(y=f(x)\\) shifted \\(c\\) units downward.\\\\\n\\(y=f(x+c)\\) is the graph of \\(y=f(x)\\) shifted \\(c\\) units to the left.\\\\\n\\(y=f(x-c)\\) is the graph of \\(y=f(x)\\) shifted \\(c\\) units to the right.\\\\\n\\end{center}\n\n\\subsection*{Vertical and Horizontal Stretching and Reflecting}\n\nSuppose \\(c>1\\). Then\n\\begin{center}\n\\(y=cf(x)\\) is the graph of \\(y=f(x)\\) stretched vertically by a factor of \\(c\\).\\\\\n\\(y=(1/c)f(x)\\) is the graph of \\(y=f(x)\\) shrunk vertically by a factor of \\(c\\).\\\\\n\\(y=f(cx)\\) is the graph of \\(y=f(x)\\) shrunk horizontally by a factor of \\(c\\).\\\\\n\\(y=f(x/c)\\) is the graph of \\(y=f(x)\\) stretched horizontally by a factor of \\(c\\).\\\\\n\\(y=-f(x)\\) is the graph of \\(y=f(x)\\) reflected about the \\(x\\)-axis.\\\\\n\\(y=f(-x)\\) is the graph of \\(y=f(x)\\) reflected about the \\(y\\)-axis.\n\\end{center}\nGiven two functions \\(f\\) and \\(g\\), the \\textbf{composite function} \\(f \\circ g\\) is defined by \n$$(f \\circ g)(x)=f(g(x))$$\n", "meta": {"hexsha": "892f8a8a61e80f29a0e1ff1d2b4ed051d3a6f2d2", "size": 1172, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/1-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/1-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/1-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": 39.0666666667, "max_line_length": 97, "alphanum_fraction": 0.6066552901, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7643846821643747}}
{"text": "\\chapter{Heaps}\n\nFor the purposes of generality, instead of referring to \nelements that are ``greater than\" or ``less than\" others,\nwe will simply say that they are ``better than\" or ``worse than\"\nothers. For any particular ordering, the ``best\" element is desired first.\nA Heap is a binary tree that satisfies the following properties:\n\n\\begin{itemize}\n\\item The root of a heap is better than its two children (the heap property)\n\\item The children of the root are also heaps  \n\\item A heap is a complete binary tree (only the last level may not be full, \nand all elements in the last level are on the left)\n\\end{itemize}\n\nA heap differs from most binary trees in that it provides no particular\nordering of the elements, but rather guarantees that the best element is\nat the root. Further, while heaps are usually discussed and defined\nas binary trees, they need not be implemented as such.\nA heap can in fact be implemented as an array with no performance reduction.\nContrary to standard theoretical convention, we will be using 0-indexed arrays\nrather than 1-indexed arrays. That is to say, the indexing will reflect how\nmost programming languages perform indexing (0 is the first element, not 1).\nTo represent a heap as an array, we can implement a simple indexing. \nIf an element is at the $i$th\nindex in the array, its left and right child are at the $2i+1$th and $2i+2$th \nindexes respectively. By placing the root at the $0$th index, all others follow.\nThis is depicted below.\n{\n  \\includegraphics[scale=0.5]{heapTreeArray}\n  %\\caption{The mapping of a binary tree to an array}\n  \\label{fig:heapTreeArray}\n}\nHeaps are commonly used to implement priority queues, because they do the\nminimum amount of work required to keep track of the best element.\n\n\\section{How to Implement a Heap}\n\nA heap must support the following operations\n\n\\begin{itemize}\n\\item $best()$: returns the best element in the heap\n\\item $pop-best()$: removes the best element in the heap\n\\item $insert(x)$: inserts $x$ into the heap\n\\end{itemize}\n\nFrom the definition of a heap, we know the we can easily implement\n$best()$ by returning the root of the heap, which should take $O(1)$\ntime.  However the other operations are less obvious.\n\nTo $insert(x)$ recall that a heap must be complete, therefore, if a\nnew element is added, it must be added to the left-most available\nspace in the last row of the heap. However, the heap property may now\nbe violated.  If the new element $x$ is worse than its parent $y$, the\nheap property is satisfied and we may stop. However if it is not\nsatisfied we may swap $x$ with $y$ and recurse on $x$'s new\nposition. This works because we know that $y$ is better than all of\n$x$'s children, because the heap property was satisfied before $x$ was\nadded. Further, because $x$ is better than $y$, it is also better than\nall of $y$'s children. However $x$ may still be better than its new\nparent, so we must recurse. If $x$ is the new best element, it will\neventually reach the root. Because heaps are complete, this operation\nwill take $O(\\log n)$ time, as this is the height of the heap.\n\nTo $pop-best()$, we may simply remove the root, however this\ncompletely destroys the entire heap. Instead, we will swap the root\nwith the bottom-left-most element, $y$. Now removing the best element\nleaves us with a still complete tree. However the heap property has\nlikely been violated once more. If $y$ is better than both its\nchildren, then we may stop. However, if not, we shall swap $y$ with\nits best child and recurse on $y's$ new position. Because the element\nwe swap with $y$ is better than both $y$ and the other child, the heap\nproperty has been satisfied for this sub-heap. However, the heap\nproperty may still be violated for $y's$ new sub-heap, so we must do\nthis again, until $y$ is the root of a valid heap. Once more, this\noperation requires $O(\\log n)$ time, as it must at worse traverse the\nentire height of the tree.\n\nTherefore, a heap may support $best()$ in $O(1)$ time, $insert(x)$ \nin $O(\\log n)$ time, and $pop-best()$ in $O(\\log n)$ time.\n\n\\section{Building a Heap}\n\nNow that we can support all the operations that a heap must implement,\nit would be nice to be able to actually construct one given a list of $n$\nelements. A na\\\"ive approach is to simply call $insert(x)$ on every element\nin the list. However, since $insert(x)$ requires $O(\\log n)$ time, this will\nrequire $O(n \\log n)$ time. These seems pretty bad, considering one can find\nthe best element in a list by brute force in $O(n)$ time. Can we achieve a\nconstruction time comparable to the brute force time?\nInstead of building the heap top down with $insert$, we can build it from the\nbottom up. Remark that a single element is a valid heap. If we were to try to\nbuild from the bottom up, we could first take the last $n/2$ elements in the\nlist. All of these elements are their own valid and complete heaps,\nand we therefore do not need to do anything to them.\nTo add the next $n/4$ elements, we simply perform\nthe procedure we did in $pop-best$ to fix the fact that the new root might\nbe violating the heap property, knowing that all the elements below it are\nvalid heaps. By repeating this process until we reach the first element in\nthe list, we will have created a valid heap on $n$ elements.\n\nBecause we are doing very little work for the majority of the elements, we end\nup doing only $O(n)$ work over all, which is optimal, as this is the amount of\ntime required to find the best element.\n\n\\section{Heapsort}\n\nAnother nice property of a heap is that once one has been implemented,\nit provides a very simple procedure for sort elements.\nA simple algorithm to do this to construct a heap on the list and then simply\nreturn $best$ and then call $pop-best$ over and over until there are no more\nelements in the heap.\nIn fact, since our algorithm for building the heap is in-place and takes $O(n)$\ntime, and our remove method leaves the best element at the end of the array,\nby simply building a heap on the input array and calling $pop-best$ $n$ times,\nwe will be left with a reverse sorted array in $O(n \\log n)$ time. \nThis algorithm is particularly excellent because it requires no extra space,\nruns deterministically, and is worst-case optimal.\n\n", "meta": {"hexsha": "035a1c4eba12e928fcbc899c7c11f95fe970ce5f", "size": 6239, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "heaps.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": "heaps.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": "heaps.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": 51.9916666667, "max_line_length": 80, "alphanum_fraction": 0.7589357269, "num_tokens": 1556, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7643606525158022}}
{"text": "%!TEX root = Calculus_I.tex\n\\chapter{Using the Derivative}\nThis chapter will cover\n\n\\section{Using First and Second Derivatives}\nRecall from Chapter 2 that:\n%\n\\begin{enumerate}\n\\item If $f^\\prime > 0$ $\\forall x \\in [a, b]$, then $f(x)$ is \\textbf{\\textit{monotonically increasing}} on that interval\\\\\n\\item If $f^\\prime < 0$ $\\forall x \\in [a, b]$, then $f(x)$ is \\textbf{\\textit{monotonically decreasing}} on that interval\\\\\n\\item If $f^{\\prime\\prime} > 0$ $\\forall x \\in [a, b]$, then $f(x)$ is \\textbf{\\textit{concave up}} on that interval\\\\\n\\item If $f^{\\prime\\prime} < 0$ $\\forall x \\in [a, b]$, then $f(x)$ is \\textbf{\\textit{concave down}} on that interval\n\\end{enumerate}\n%\nWe can combine these principles along with the general derivation formulas we discussed in Chapter 3.\n\n\\vspace{0.1in}\nOften, the \\textbf{\\textit{local maxima}} or \\textbf{\\textit{local minima}} are points of interest for a given function, if they exist. Suppose $p$ is a point in the domain of $f(x)$; $p \\in [a, b]$. Then:\n%\n\\begin{enumerate}\n\\item $f(x)$ has a \\textbf{\\textit{local minimum}} at $p$ if $f(p \\pm \\Delta) > f(p)$.\n\\item $f(x)$ has a \\textbf{\\textit{local maximum}} at $p$ if $f(p \\pm \\Delta) < f(p)$.\n\\end{enumerate}\n%\nThese definitions of the \\textbf{\\textit{maxima}} and \\textbf{\\textit{minima}} are \\textbf{\\textit{local}} because these relationships do not provide any information outside of the near vicinity of point $p$.\n\n\\vspace{0.1in}\n\\textbf{\\textit{Local maxima}} or \\textbf{\\textit{local minima}}, as well as other important points of a function, are commonly referred to as \\textbf{\\textit{critical points}}. These points are identified by the \\textbf{\\textit{derivative}}. For any function, $f(x)$, \\textbf{\\textit{critical points}} are located at points $p$ satisfying:\n%\n\\begin{enumerate}\n\\item $f^\\prime(p) = 0$\\\\\n\\item $f^\\prime(p)$ is undefined\n\\end{enumerate}\n%\nThe \\textbf{\\textit{critical values}} of a function are found by evaluating $f(p)$ at each \\textbf{\\textit{critical point}}, $p$. Note that not every \\textbf{\\textit{critical point}} is a \\textbf{\\textit{maximum}} or \\textbf{\\textit{minimum}}.\n\n\\vspace{0.1in}\nSuppose we wanted to find all of the \\textbf{\\textit{extrema}} of a function. This can be done using both $f^\\prime(x)$ and $f^{\\prime\\prime}\n(x)$. When performing the \\textbf{First-Derivative Test}, assume that $p$ is a \\textbf{\\textit{critical point}} in the domain of $f(x)$; $p \\in [a, b]$. Then, assuming $x$ is increasing:\n%\n\\begin{enumerate}\n\\item If $f^\\prime(x)$ changes sign from negative to positive at $p$, then $p$ is a \\textbf{\\textit{local minimum}} of $f(x)$.\\\\\n\\item If $f^\\prime(x)$ changes sign from positive to negative at $p$, then $p$ is a \\textbf{\\textit{local maximum}} of $f(x)$.\n\\end{enumerate}\n%\nThe \\textbf{Second-Derivative Test} also provides curvature information about the function. Again, assuming that $p$ is a \\textbf{\\textit{critical point}} in the domain of $f(x)$; $p \\in [a, b]$:\n%\n\\begin{enumerate}\n\\item If $f^\\prime(p) = 0$ and $f^{\\prime\\prime}(p) > 0$, then $f$ has a \\textbf{\\textit{local minimum}} at $p$.\\\\\n\\item If $f^\\prime(p) = 0$ and $f^{\\prime\\prime}(p) < 0$, then $f$ has a \\textbf{\\textit{local maximum}} at $p$.\\\\\n\\item If $f^\\prime(p) = 0$ and $f^{\\prime\\prime}(p) = 0$, then the \\textbf{Second-Derivative Test} does not result in a conclusion.\n\\end{enumerate}\n%\n\\textbf{\\textit{Inflection Points}} are defined at places that the function, $f$, changes \\textbf{\\textit{concavity}}. These occur when $f^{\\prime\\prime} = 0$ or $f^{\\prime\\prime}$ is undefined.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Optimization}\nSome functions have maximum or minimum values across its domain, meaning the functions do not grow or decay to $\\pm\\infty$. These maximum or minimum values are referred to as \\textbf{\\textit{extrema}} or \\textbf{\\textit{optimal values}}. Practical applications of finding these \\textbf{\\textit{extrema}} are to minimize weight of an airplane or maximize the profit of an investment. The \\textbf{Extreme Value Theorem} is used to describe when \\textbf{\\textit{extrema}} exist:\n\\vspace{0.1in}\n\\textbf{Extreme Value Theorem}: If $f$ is \\textbf{\\textit{continuous}} on the closed interval, $a \\leq x \\leq b$, then $f$ has a \\textbf{\\textit{global maximum}} and \\textbf{\\textit{global minimum}} on that interval.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{critical points}} of the function are first found using the \\textbf{First-Derivative Test}. Then, the function values are evaluated at each of the \\textbf{\\textit{critical points}} and the endpoints of the domain, $a$ and $b$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Families of Functions}\n\\textbf{\\textit{Families of Functions}} are defined by functions that all have similar terms. An example is the set of quadratic functions, which follow the form of:\n%\n\\begin{equation}\nf(x) = ax^2 + bx + c\n\\end{equation}\n%\nwhere $a$, $b$, and $c$ are constants. Different combinations of $a$, $b$, and $c$ represent unique members of the \\textbf{\\textit{family of functions}}. Because there are an infinite amount of constant values, there are an infinite amount of quadratic functions. Different \\textbf{\\textit{families of functions}} are commonly used in mathematical modeling of some system or event. Some examples of these are probabalistic theory, kinematic motion, or population density.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Optimization, Geometry, and Modeling}\nThe practice of \\textbf{\\textit{Optimization}} can be applied to a variety of problems. One common example of this in the field of geometry is minimizing or maximizing the surface area or volume of a given shape. To do this, a mathematical model of how surface area and volume change with other parameters is required. These \\textbf{\\textit{optimization}} problems often have constraints, such as maximum or minimum dimensions or the shape must have have at least a certain volume.\n\n\\vspace{0.1in}\nA common technique to solve \\textbf{\\textit{optimization}} problems is to apply the \\textbf{First-Derivative Test} to find the \\textbf{\\textit{critical points}} of a function; where $f^\\prime(x) = 0$, and then testing the possible optimal solutions for the maximum or minimum function value.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Applications to Marginality}\nIn the world of business, decisions are often made based on \\textbf{\\textit{revenue}} or \\textbf{\\textit{cost}} of a project or investment. The \\textbf{\\textit{derivative}} can be used to maximize \\textbf{\\textit{profit}}, the difference between \\textbf{\\textit{revenue}} or \\textbf{\\textit{cost}}:\n%\n\\begin{equation}\n\\text{Profit} = \\text{Revenue} - \\text{Cost}\n\\end{equation}\n%\n\\textbf{\\textit{Cost}} represents the total cost of producing a quantity, $q$, of some good. The more goods are made, the higher the \\textbf{\\textit{cost}}, so $C(q)$ is an increasing function. Many \\textbf{\\textit{cost functions}}, $C(q)$, have \\textbf{\\textit{fixed costs}}, or costs that are incurred before the first good is produced. This represents things like facility cost or hardware/software or material investments to create the good.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{Revenue Function}}, $R(q)$, represents the total value for selling a good:\n%\n\\begin{equation}\n\\text{Revenue} = \\text{Price} * \\text{Quantity}\n\\end{equation}\n%\nSometimes, the price, $p$, of an item can depend on the quantity, $q$, sold. Accessing the \\textbf{\\textit{profit}} of producing the next good, based on the current \\textbf{\\textit{cost}} and \\textbf{\\textit{revenue}} is referred to as \\textbf{\\textit{Marginal Analysis}}. This is performed using the definition of the \\textbf{\\textit{derivative}}. The \\textbf{\\textit{Marginal Cost}} is given by:\n%\n\\begin{equation}\n\\text{MC} = \\frac{C(q+1) - C(q)}{(q+1) - q}\n\\end{equation}\n%\n\\begin{equation}\n\\nonumber\n\\text{MC} = C^\\prime(q) \\approx C(q+1) - C(q)\n\\end{equation}\n%\nLikewise, \\textbf{\\textit{Marginal Revenue}} is given by:\n%\n\\begin{equation}\n\\text{MR} = \\frac{R(q+1) - R(q)}{(q+1) - q}\n\\end{equation}\n%\n\\begin{equation}\n\\nonumber\n\\text{MR} = R^\\prime(q) \\approx R(q+1) - R(q)\n\\end{equation}\n%\nIt can be shown that the maximum \\textbf{\\textit{profit}} occurs when:\n%\n\\begin{equation}\n\\text{MR}= \\text{MC}\n\\end{equation}\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Rates and Related Rates}\nBecause \\textbf{\\textit{derivatives}} represent rates of change, they can be used to represent the rates of different observable and quantifiable situations. This includes ideas like change in volume of a melting snowball, the distance an object travels over time due to changes in velocity and acceleration, the fluid level of a tank as it is expelling its contents, and so on.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{L'Hopital's Rule, Growth, and Dominance}\nSuppose we want to evaluate the \\textbf{\\textit{limit}} of a function exactly of a quantity as it approaches a point where the function is not defined, such as:\n%\n\\begin{equation}\n\\lim_{x \\rightarrow 0} \\frac{e^{2x} - 1}{x}\n\\end{equation}\n%\nThis yields $\\frac{0}{0}$, which does not make mathematical sense. Though the \\textbf{\\textit{limit}} can be approximated by taking values near the desired evaluation point, it can be calculated exactly by applying the principle of \\textbf{\\textit{local linearity}}.\n\n\\vspace{0.1in}\nBy replacing the numerator and denominator with two functions, $f(x)$ and $g(x)$, we can approximate the limit by the ratio of the corresponding $y$-values. Taking $f^\\prime(x)$ and $g^\\prime(x)$ as a tangent-line approximation, we see that:\n%\n\\begin{equation}\n\\frac{f(x)}{g(x)} = \\frac{e^{2x} - 1}{x} \\approx \\frac{2x}{x} = \\frac{2}{1} = \\frac{f^\\prime(0)}{g^\\prime(0)}\n\\end{equation}\nThus, we arrive at:\n%\n\\begin{equation}\n\\lim_{x \\rightarrow 0} \\frac{e^{2x} - 1}{x} = 2\n\\end{equation}\n%\nThis technique is referred to as \\textbf{\\textit{L'Hopital's Rule}}, which is formally defined as:\n%\n\n\\vspace{0.1in}\n\\textbf{L'Hopital's Rule}: if $f$ and $g$ are \\textbf{\\textit{differentiable}}, $f(a) = g(a) = 0$, and $g^\\prime(a) \\neq 0$, then:\n%\n\\begin{equation}\n\\lim_{x \\rightarrow a} \\frac{f(x)}{g(x)} = \\frac{f^\\prime(a)}{g^\\prime(a)}\n\\end{equation}\n%\nThis requires that the right-hand \\textbf{\\textit{limit}} exists. \\textbf{\\textit{L'Hopital's Rule}} also applies to limits that approach $\\pm \\infty$.\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}\n\n\\section{Parametric Equations}\n\\textbf{\\textit{Parametric Equations}} are commonly used to represent motion in the $xy$-plane because motion is a function of time. Thus, if $x = f(t)$ and $y = g(t)$ then at time $t$, the object can be located at point $\\left(f(t), g(t)\\right)$. The \\textit{parameter} of the \\textbf{\\textit{parametric equations}} for this example is the value of time, $t$.\n\n\\vspace{0.1in}\nFor straight-line motion, the object is located at an initial point, $\\left(x_0, y_0\\right)$. Provided the $x$ and $y$ rates of change (\\textbf{\\textit{deriatives}}) are constant, they can be represented by the quantities $a = \\frac{dx}{dt}$ and $b = \\frac{dy}{dt}$. Thus, at time $t$, the object has coordinates $\\left(x_0 + at, y_0 + bt\\right)$. The slope of the line the object is following is $m = \\frac{b}{a}$.\n\n\\vspace{0.1in}\nThe \\textbf{\\textit{speed}} of this object can be quantified as well. In one unit of time, $t$, the object will move $a$ units in the $x$-direction and $b$ units in the $y$-direction; provided $a$ and $b$, are constant. Applying the Pythagorean Theorem results in:\n%\n\\begin{equation}\n\\text{Speed} = \\frac{Distance}{Time} = \\frac{\\sqrt{a^2 + b^2}}{1} = \\sqrt{a^2 + b^2}\n\\end{equation}\n%\nMore generally, for an object along an arbitrary curve with time-varying speed, the \\textbf{\\textit{instantaneous speed}} is given by:\n%\n\\begin{equation}\nv = \\sqrt{\\left(\\frac{dx}{dt}\\right)^2 + \\left(\\frac{dy}{dt}\\right)^2}\n\\end{equation}\n%\nwhere $v_x = \\frac{dx}{dt}$ is the \\textbf{\\textit{instantaneous velocity}} in the $x$-direction and $v_y = \\frac{dy}{dt}$ is the \\textbf{\\textit{instantaneous velocity}} in the $y$-direction. Recall that \\textbf{\\textit{velocity}} has both magnitude \\textit{and} direction. This introduces the idea of \\textbf{\\textit{unit vectors}}, which have an identity magnitude (1) and are always oriented in the $x$- and $y$-directions. For traditional $xy$-coordinate frames, $i$, and $j$ are used to represent motion in $x$ and $y$, respectively. Thus, the \n\\textbf{\\textit{velocity vector}} is written as:\n%\n\\begin{equation}\n\\overrightarrow{v} = v_x \\overrightarrow{i} + v_y \\overrightarrow{j}\n\\end{equation}\n%\n\n\\vspace{0.1in}\nFor any given point $\\left(x_0, y_0\\right)$, a tangent line to the curve can be given parametrically by finding the straight-line motion through  $\\left(x_0, y_0\\right)$ with the same $x$ and $y$ velocities as an object moving along the curve.\n\n\\vspace{0.1in}\nSometimes, the curve is more interesting to observe than the object's motion through space and time. This representation is referred to as the \\textit{parameterization} of the curve. This can be helpful to graph complicated curves.\n\n\\vspace{0.1in}\nThe slope and concavity of \\textbf{\\textit{parametric curves}} can be obtained via the \\textbf{\\textit{Chain Rule}} by thinking of the \\textbf{\\textit{parametric equations}} as functions of time. The slope is given by:\n%\n\\begin{equation}\n\\frac{dy}{dx} = \\frac{\\frac{dy}{dt}}{\\frac{dx}{dt}}\n\\end{equation}\n%\nThe second \\textbf{\\textit{derivative}} can be found by a similar method. If $w$ is a \\textbf{\\textit{differentiable}} function of $x$, then:\n%\n\\begin{equation}\n\\frac{dw}{dx} = \\frac{\\frac{dw}{dt}}{\\frac{dx}{dt}}\n\\end{equation}\n%\nFor $w = \\frac{dy}{dx}$:\n%\n\\begin{equation}\n\\frac{dw}{dx} = \\frac{d}{dx}\\left(\\frac{dy}{dx}\\right) = \\frac{d^2y}{dx^2}\n\\end{equation}\n%\nSo, by the \\textbf{\\textit{Chain Rule}}:\n%\n\\begin{equation}\n\\frac{d^2y}{dx^2} = \\frac{\\frac{d}{dt}\\left(\\frac{dy}{dx}\\right)}{\\frac{dx}{dt}}\n\\end{equation}\n%\n\n\\begin{center}\n\\section*{\\small Examples}\nComing soon$!^{\\text{TM}}$\n\\end{center}", "meta": {"hexsha": "6a50c14e839e951c9d4990ea57383be6163c17b8", "size": 14281, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus I/Notes/chapter4.tex", "max_stars_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_stars_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-08-06T01:05:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-06T01:05:34.000Z", "max_issues_repo_path": "Calculus I/Notes/chapter4.tex", "max_issues_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_issues_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Calculus I/Notes/chapter4.tex", "max_forks_repo_name": "BenArmentor/Mechanical-Engineering-Curriculum", "max_forks_repo_head_hexsha": "f67cd303f852f0fd814bfb0140591f15f9d440c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.78515625, "max_line_length": 550, "alphanum_fraction": 0.7161263217, "num_tokens": 4409, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.9124361622627654, "lm_q1q2_score": 0.7642747447785045}}
{"text": "As previously mentioned, radial distortion is only dependent on the distance between the origin and the point being considered.\nBecause of this, it can be thought of as a transformation which, according to some function $f$, moves the point to a different location on the line intersecting it and the origin.\nMore specifically, for a point $(r_u, \\theta_u)$ in polar coordinates, $r_d = f(r_u), \\theta_d = \\theta_u$ is a radial distortion where $(r_d, \\theta_d)$ represents the distorted polar coordinates of the point.\n\nBrown's model for lens distortion~\\cite{brown1966decentering} builds upon that presented by Conrady~\\cite{conrady1919lens}, presenting a mathematical representation of barrel/pincushion and tangential distortion.\nThe rest of this report will consider a simplified version of this model in which there is no tangential distortion and is evaluated up to $r^5$ (and $r^8$ for its inverse).\nThis simplified version of Brown's radial distortion model is shown in Eq.~\\ref{eq:brown-forward-radial-distortion}.\nThe approximation of its inverse is shown in Eq.~\\ref{eq:brown-inverse-radial-distortion}.\n\n\\begin{equation}\n    \\label{eq:brown-forward-radial-distortion}\n    r_d = f(r_u) = r_u + c_1 r_u^3 + c_2 r_u^5\n\\end{equation}\n\n\\begin{equation}\n    \\label{eq:brown-inverse-radial-distortion}\n    r_u = f^{-1}(r_d) \\approx \\frac{c_1 r_d^2 + c_2 r_d^4 + c_1^2 r_d^4 + c_2^2 r_d^8 + 2 c_1 c_2 r_d^6}{1 + 4 c_1 r_d^2 + 6 c_2 r_d^4}\n\\end{equation}\n\nWhere $c_1$ and $c_2$ are per-lens constants that determine the extremity of the distortion.\nThese are usually calculated experimentally, however, for the static renders in this paper, they will be set to arbitrary values of $c_1 = 0.15$ and $c_2 = 0.10$.\nWhile these are relatively extreme, they clearly exemplify the concepts being demonstrated.\nIts worth noting that, due to the approximate nature of the inverse distortion function, the greater values of $c_1$ and $c_2$, the more $f^{-1}(f(r))$, $f(f^{-1}(r))$ and $r$ diverge.\n\nFor practical implementations, computers represent points using cartesian coordinates.\nBecause of this, any transformations first need to convert the coordinates to polar form.\nGiven a two dimensional cartesian point $p = (x, y)$, its polar form is $\\left(r = \\sqrt{x^2 + y^2} = \\sqrt{p \\cdot p}, \\theta = \\arctantwo{(y, x)}\\right)$.\nGiven a two dimensional polar point $(r, \\theta)$, its cartesian form is $\\left(x = r \\cos{\\theta}, y = r \\sin{\\theta}\\right)$.\n\nBy using the fact that only $r$ is varied during a radial distortion, an optimisation can be used whereby only $r$, or the required powers of $r$, are calculated, and the cartesian coordinates are simply scaled by that applied during the distortion (removing the need to calculate $\\theta$, $\\sin{\\theta}$, and $\\cos{\\theta}$).\nApplying this to Brown's model, for a point $(x_u, y_u)$,~\\cite{mallon2004precise} calculates its distorted point $(x_d, y_d)$ as shown in Eq.~\\ref{eq:inverse-radial-distortion}.\n\n\\begin{equation}\n    \\label{eq:inverse-radial-distortion}\n    \\binom{x_u}{y_u} = \\binom{x_d}{y_d} \\left(1 - f^{-1}\\left(\\sqrt{x_d^2 + y_d^2}\\right)\\right),\n\\end{equation}\n\nAll distortions are applied on top of the scene shown in Fig.~\\ref{fig:no-distortion}.\nAny intermediary render textures are $1024 \\times 1024$ pixels and the output resolution is $500 \\times 500$ pixels unless otherwise specified.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/no-distortion}\n    \\caption{Untouched and undistorted 9-cube scene.}\n    \\label{fig:no-distortion}\n\\end{figure}\n\n\\subsection{Pixel-based Distortion Correction}\\label{sec:pixel-based}\n\nThe pixel-based distortion correction method works by transforming UV positions in the texture map for each pixel (or fragment).\nIn a normal fragment shader, the graphics card provides texture UV positions (between $(0, 0)$ and $(1, 1)$) interpolated between those specified in the vertex shader.\nA \\texttt{sampler2D} is then used to retrieve the colour of the pixel in the texture corresponding to the UV position.\nIn order to perform distortion, the UV position being sampled can be changed.\n\nFirstly, both the forward and inverse radial distortions functions require points to be normalised to between $(-1, -1)$ and $(1, 1)$.\nFor input UV position $p_{\\texttt{UV}}$, this is achieved simply using $p_{\\texttt{norm}} = 2 p_{\\texttt{UV}} - 1$.\nAfter the distortion transformation is completed, the normalised points are converted back to UV positions using $p_{\\texttt{UV}}' = 0.5 (p_{\\texttt{norm}}' + 1)$.\n\nSomewhat non-trivially, to perform a radial barrel or pincushion distortion, the opposite equation must be used (Eq.~\\ref{eq:brown-forward-radial-distortion} for barrel and Eq.~\\ref{eq:brown-inverse-radial-distortion} for pincushion).\nThis is because sampling a different UV value to the current one is already the inverse operation.\nInstead of imagining the current UV point $A$ being transformed to its distorted UV point $B$, its better to think of it as finding the UV point that should replace $A$, and calculating this to be $B$.\nHence, for barrel distortion, considering the point $A$, it needs to be replaced by a point $B$ further away from the origin (effectively distorting by compression).\nIn this case, $B$ is found by inverting the distortion that lands on $A$, therefore using Eq.~\\ref{eq:brown-forward-radial-distortion} (and vice versa for pincushion distortion).\n\nThe fragment shader implementation simply performs this operation for each pixel/fragment in the image, and discards any fragments who's distorted UV positions lie outside the bounds of the texture.\nThe results of this and simulation of it running through a lens are shown in~\\ref{fig:frag-based}.\n\n\\begin{figure}[ht]\n    \\centering\n\n    \\subfloat[Pre-distortion]{\\includegraphics[width=0.225\\textwidth]{figures/pixel-based}}\n    \\hfil\n    \\subfloat[Correction and distortion]{\\includegraphics[width=0.225\\textwidth]{figures/pixel-based-inverse}}\n    \n    \\caption{Pixel-based pre-distortion and lens simulation.}\n    \\label{fig:frag-based}\n\\end{figure}\n\n\\subsection{Mesh-based Distortion Correction}\\label{sec:mesh-based}\n\nThe mesh-based distortion correction method works by transforming the vertex positions of a mesh (instead of transforming texture UV positions).\nIn doing so, it looks to exploit the graphics rendering pipeline for a performance gain with minimal residual artifacts.\n\nThe meshes were produced in Blender by continually subdividing a plane (the $8 \\times 8$ mesh is shown in Fig.~\\ref{fig:blender-mesh8}).\nAn $n \\times n$ mesh has $n^2$ quads, $2n^2$ triangles, or $(n + 1)^2 = n^2 + 2n + 1$ vertices.\nAs each face is subdivided into four subfaces, $n$ is a power of $2$.\n\n\\begin{figure}[ht]\n    \\centering\n    \\includegraphics[width=0.4\\textwidth]{figures/blender-mesh8}\n    \\caption{$8 \\times 8$ mesh in Blender.}\n    \\label{fig:blender-mesh8}\n\\end{figure}\n\nIn the vertex shader, vertices are first transformed from world-space to clip-space using its model-view-projection matrix.\nSince clip-space is between $(-1, -1)$ and $(1, 1)$, it matches the domain of both Eq.~\\ref{eq:brown-forward-radial-distortion} and Eq.~\\ref{eq:brown-inverse-radial-distortion}.\nThis means that the respective radial transforms can be applied to the vertices in clip-space to distort their positions.\n\nOpposite to the pixel-based method, applying pre-distortion correction to the output requires the inverse radial transform (Eq.~\\ref{eq:brown-inverse-radial-distortion}), and simulating the distortion requires the forward radial transform (Eq.~\\ref{eq:brown-forward-radial-distortion}).\nThis works by translating the vertices (as if they were distorted) to their pre-distorted positions.\nAs part of the rendering pipeline, during the fragment shader, each of these pre-distorted vertex positions are linearly interpolated by the graphics card to produce estimates for pre-distorted fragments/pixels.\n\nIn order to simulate a lens being applied to the pre-distorted image, as mentioned, the same technique is applied using the forward radial transform (Eq.~\\ref{eq:brown-forward-radial-distortion}).\nThis then cancels out the pre-distortion to produce an image similar to that which was input ($f^{-1}(f(r)) = r$).\n\nAs an aside, similar results could be achieved by performing the same texture UV transformation in the vertex shader as that used by the pixel-based method in the fragment shader.\nWhile this would cause the same distortion, as vertices remain on the edge, a mesh image of original size would be output, causing redundant additional distortion and calculations near the edge (instead of the black background).\n\nFig.~\\ref{fig:mesh-based-distortion} shows the mesh-based method applied to three meshes ($8 \\times 8$, $128 \\times 128$, and $512 \\times 512$) with correction only ($a$, $c$, and $e$) and correction with distortion ($b$, $d$, and $f$).\nThe main visible difference is between $8 \\times 8$ and $128 \\times 128$, where clear straight lines blend into curved lines.\nThere is also a clear difference in correction and distortion applied together, with the $8 \\times 8$ mesh exhibiting clear artifacts towards the corners.\nBetween $128 \\times 128$ and $512 \\times 512$ there is no perceivable difference in output, implying that at this level the difference is sub-pixel.\nThis makes logical sense since the number of quads (and by extension vertices) exceed the number of pixels in the image.\n\n\\begin{figure}[ht]\n    \\centering\n    \n    \\subfloat[$8 \\times 8$ mesh, corrected]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-correction8}}\n    \\hfil\n    \\subfloat[$8 \\times 8$ mesh, corrected and distorted]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-distortion8}}\n    \n    \\subfloat[$128 \\times 128$ mesh, corrected]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-correction128}}\n    \\hfil\n    \\subfloat[$128 \\times 128$ mesh, corrected and distorted]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-distortion128}}\n    \n    \\subfloat[$512 \\times 512$ mesh, corrected]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-correction512}}\n    \\hfil\n    \\subfloat[$512 \\times 512$ mesh, corrected and distorted]{\\includegraphics[width=0.225\\textwidth]{figures/mesh-based-distortion512}}\n    \n    \\caption{LCA pre-distortion and corrected LCA with distortion.}\n    \\label{fig:mesh-based-distortion}\n\\end{figure}\n\nFor benchmarking and profiling, on an i7 6700K with an RTX 2080 at $500 \\times 500$ pixels, all three meshes performed the same (about 1.7ms per frame).\nHowever, increasing the resolution to $8192 \\times 8192$ yields more reliable variation on the frame rate and a clear performance drop as mesh complexity increases.\nThe profiling results are shown in Tab.~\\ref{tab:benchmarking}.\nThese results, combined with the minimal visual difference between the more detailed meshes, show that a low-poly mesh is a good trade-off between frame rate and visual quality.\n\n\\begin{table}[ht]\n    \\centering\n    \\caption{Profiling results for three meshes at $8192 \\times 8192$ resolution.}\n    \\label{tab:benchmarking}\n    \\begin{tabular}{c|cccc}\n    \\textbf{Mesh}     & \\textbf{FPS} & \\textbf{CPU (ms)} & \\textbf{GPU (ms)} & \\textbf{Total (ms)} \\\\ \\hline\n    $8 \\times 8$      & $\\sim135$    & $7.3$             & $0.3$           & $7.3$                 \\\\\n    $128 \\times 128$  & $\\sim128$    & $7.8$             & $0.3$           & $7.9$                 \\\\\n    $512 \\times 512$  & $\\sim104$    & $9.4$             & $0.3$           & $9.5$                \n    \\end{tabular}\n\\end{table}\n\n\\subsection{Pixel-based vs Mesh-based Distortion Correction}\\label{sec:pixel-vs-mesh-based}\n\nBoth techniques have advantages and drawbacks.\n\nFirstly, pixel-based pre-distortion in the fragment shader involves calculating Eq.~\\ref{eq:brown-forward-radial-distortion} for each fragment/pixel in the scene, including those which are eventually discarded.\nOn the other hand, mesh-based pre-distortion in the vertex shader involves calculating Eq.~\\ref{eq:brown-inverse-radial-distortion} for each vertex in the mesh.\nThis means that, for a mesh with far less vertices than pixels being rendered to the screen, the mesh-based method performs far less direct distortion calculations than the pixel-based method, giving it better theoretical performance.\n\nSecondly, while the pixel-based method produces the most accurate theoretical discrete output, in practice, the mesh-based method is able to produce indistinguishable results for a low number of vertices relative to pixels/fragments.\n\nFrom an implementation efficiency standpoint, one drawback of the mesh-based method is that using Eq.\\ref{eq:brown-inverse-radial-distortion} means it needs to perform more operations per vertex calculation than the pixel-based method does per pixel.\nIt does however have the added benefit that the input coordinates are already normalised to between $-1$ and $1$.\nAdditionally, since it only uses even powers of $r$, $r^2$ can be trivially calculated using $r^2 = x^2 + y^2 = p \\cdot p$, removing the need for an expensive square root.\n\nFor the frame buffer resolution of $1024 \\times 1024$ pixels used in the render targets, the fragment shader in the pixel-based method should perform $1024^2 = 1048576$ distortion calculations and up to $1048576$ texture lookups per frame (dependent on the number of discarded fragments).\nOn the other hand, the mesh-based method only performs $(n + 1)^2$ distortion calculations for an $n \\times n$-quad mesh ($81$ calculations for $8 \\times 8$, $16384$ for $128 \\times 128$, and $262144$ for $512 \\times 512$), but will still require up to $1048576$ texture lookups as the fragment shader samples the texture for each fragment in the buffer.\n\nFinally, while not used in this report, the mesh-based method can be further refined by pre-baking its distorted vertex positions, removing the need to do any distortion calculations at runtime.\n", "meta": {"hexsha": "344e6268a0b9c8811bb9c050f3609dc942d28a63", "size": 13961, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment/report/sections/01-pincushion-distortion.tex", "max_stars_repo_name": "grimm004/vr-assignment", "max_stars_repo_head_hexsha": "840ba9d8708adec578bcc9593a6c4e45646894c3", "max_stars_repo_licenses": ["MIT"], "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/report/sections/01-pincushion-distortion.tex", "max_issues_repo_name": "grimm004/vr-assignment", "max_issues_repo_head_hexsha": "840ba9d8708adec578bcc9593a6c4e45646894c3", "max_issues_repo_licenses": ["MIT"], "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/report/sections/01-pincushion-distortion.tex", "max_forks_repo_name": "grimm004/vr-assignment", "max_forks_repo_head_hexsha": "840ba9d8708adec578bcc9593a6c4e45646894c3", "max_forks_repo_licenses": ["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.6094674556, "max_line_length": 354, "alphanum_fraction": 0.7508774443, "num_tokens": 3603, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403999037784, "lm_q2_score": 0.8221891327004133, "lm_q1q2_score": 0.7641757962936128}}
{"text": "\n\\subsection{Sample range}\n\n\\subsubsection{Minimum}\n\nThis is the smallest value in the sample.\n\n\\subsubsection{Maximum}\n\nThis is the largest value in the sample.\n\n\\subsubsection{Range}\n\nThis is the difference between the maximum and minimum.\n\n\\subsubsection{Median}\n\nThis is the value whereby 50\\% of the sample can be found below the value.\n\n\\subsubsection{Percentiles}\n\nThe \\(x\\)th percentile is the value by which  \\(x\\%\\) of the values can be found below it.\n\n\\subsubsection{Interquartile range}\n\nThis is the differnence between the \\(25\\)th percentile and the \\(75\\)th percentile.\n\n", "meta": {"hexsha": "7e7e0a8d2c4c5182316d71551130852b23b9ed58", "size": 587, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/summary/01-02-range.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/summary/01-02-range.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/summary/01-02-range.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.9642857143, "max_line_length": 90, "alphanum_fraction": 0.7614991482, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.84594244507642, "lm_q1q2_score": 0.764134909842444}}
{"text": "\\lab{The Finite Element Method in Two Dimensions}{The Finite Element Method in Two Dimensions}\n\\label{lab:finite_element_2d}\n\nIn Lab \\ref{lab:finite_element} we discussed some of the basic details of how the Finite Element Method works.\nWe demonstrated how a grid can be refined around areas of interest to give a more accurate approximation to a desired solution.\nOne of the other great strengths of the finite element method is that, when it is used in two or more dimensions, it is easily applied to unusually shaped domains.\nThere are a wide variety of elements that are commonly used, but the simplest elements are triangles.\nTriangles are often used because they allow us to define continuous piecewise linear basis functions on their interiors without much trouble.\n\n\\section*{Working With Triangle Meshes}\nThere are a variety of ways to store triangle meshes.\nWe will present a simple one here.\nTo store a mesh we need to store several pieces of information.\nWe need to store the points used in the mesh.\nWe also need to store which points are connected to make the triangles that are part of the mesh we are studying.\nLater, when working with boundary conditions, we will also need to know which nodes have fixed values (or some other sort of boundary condition, as the case may be).\n\nIt is common to store this information in arrays, one containing the $x$ and $y$ coordinates of each node in each of its rows and another containing the indices of the nodes that form the vertices of each triangle.\n\nThe following is a short example that divides the unit square up into triangles and returns arrays of the desired form.\n\n\\begin{lstlisting}\nimport numpy as np\n\ndef triangles(n):\n    ''' Generate the indices of the triangles for a triangular mesh\n    on a square grid of points.\n    'n' is expected to be the number of nodes on each edge. '''\n    # Make the indices for a single row.\n    row = np.empty((2 * (n - 1), 3), dtype=np.int32)\n    row[::2,0] = row[1::2,0] = row[::2,1] = np.arange(n-1)\n    row[1::2,0] += 1\n    row[::2,1] += n\n    row[1::2,1] = row[::2,1]\n    row[::2,2] = row[1::2,2] = row[1::2,0]\n    row[1::2,2] += n\n    # Now use broadcasting to make the indices for the square.\n    return (row + np.arange(0, n * (n-1), n)[:,None,None]).reshape((-1,3))\n\\end{lstlisting}\n\nMatplotlib's \\li{triplot} function can be used to plot triangulations.\nTo plot the mesh generated by the above function, we can do the following:\n\\begin{lstlisting}\nfrom matplotlib import pyplot as plt\nn=5\nx = np.linspace(0, 1, n)\nx, y = map(np.ravel, np.meshgrid(x, x))\nt = triangles(n)\nplt.triplot(x, y, t, color='b')\nplt.scatter(x, y, color='b')\nplt.show()\n\\end{lstlisting}\nThis mesh is shown in figure \\ref{fig:fem2d_square_triangulation}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{square_triangulation.pdf}\n\\caption{A triangulation of a square grid.}\n\\label{fig:fem2d_square_triangulation}\n\\end{figure}\n\nMatplotlib and Mayavi both include the functionality to plot 3d surfaces based on a triangulation and the values of a function at the nodes of the triangulation.\nFor example, we can plot a piecewise linear function that is one at a single vertex and zero at every other vertex using Mayavi using the \\li{triangular_mesh} function included in \\li{mlab}.\n\\begin{lstlisting}\nfrom mayavi import mlab as ml\nn=5\nx = np.linspace(0, 1, n)\nx, y = np.meshgrid(x, x)\nt = triangle_mesh(n)\nvals = np.zeros(x.size)\nvals[n**2 // 2] = 1\nml.triangular_mesh(x.ravel(), y.ravel(), vals, t)\nml.show()\n\\end{lstlisting}\nThe output from this code is shown in Figure \\ref{fig:fem2d_basis_functions}.\nThese functions are often called \"hat functions,\" and are often used as the basis functions for 2d finite element analysis on domains that can be represented as meshes of triangles.\nThese are the two dimensional analogues of the piecewise linear functions shown in Figure \\ref{fig:FEM_one_basis_function}.\nYou may recall that, in the one-dimensional case, we could represent any function that was continuous and linear over each element as a sum of these basis functions.\nThe same is true in this case.\nWe can represent any continuous function that is linear on each triangle in the triangulation as a sum of these basis functions.\nStrictly speaking, if $f$ is a continuous function that is linear on each of the triangles in the triangulation, $p_i$ are the vertices of the trianglulation, and $\\phi_i$ are the basis functions corresponding to each vertex, we may say\n\\[f(x) = \\sum_{i} f(p_i) \\phi_i(x, y)\\]\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{hat_function.png}\n\\caption{A hat function in two dimensions. Compare with the one dimensional hat function shown in Figure \\ref{fig:FEM_one_basis_function}.}\n\\label{fig:fem2d_basis_functions}\n\\end{figure}\n\nWe can plot funcitons like this on triangulations using matplotlib as well.\nThe following code will plot the same basis function in matplotlib\n\\begin{lstlisting}\nfrom mpl_toolkits.mplot3d import Axes3D\nn=6\nx = np.linspace(0, 1, n)\nx, y = map(np.ravel, np.meshgrid(x, x))\nt = triangles(n)\nvals = np.random.rand(x.size)\nfig = plt.figure()\nax = fig.add_subplot(1, 1, 1, projection='3d')\nax.plot_trisurf(x, y, vals, triangles=t)\nplt.show()\n\\end{lstlisting}\n\n\\section*{Using Triangulations for Finite Element Analysis}\n\nAs was mentioned before, hat functions on triangulations are often used in Finite Element analysis.\nWhen using the Finite element method, regardless of the number of dimensions, it is necessary to transform a problem to its weak formulation.\nThis allows the approximation of the action of a PDE on a domain via the computation of integrals.\nTo begin, we will consider the differential operator\n\\[-\\nabla \\cdot \\left(a\\left(x\\right) \\nabla u\\left(x\\right)\\right) + b\\left(x\\right) \\cdot \\nabla u\\left(x\\right) + c\\left(x\\right) u\\left(x\\right) = d\\left(x\\right)\\]\non a triangulated domain $\\Omega$.\nFor simplicity, we will first consider the case where $u$ is assumed to have Neumann boundary conditions.\nThe weak formulation of this problem on a function space $V$ is to find a function $u$ such that $a\\left(u, v\\right) = l\\left(v\\right)$ for all $v \\in V$ with $a$ and $l$ defined as the following integral operators.\n\\begin{align*}\na\\left(u, v\\right) &= \\int_\\Omega \\left( a\\left(x\\right) \\nabla u\\left(x\\right) \\cdot \\nabla v\\left(x\\right) + \\left(b\\left(x\\right) \\cdot \\nabla u\\left(x\\right)\\right) v\\left(x\\right) + c\\left(x\\right) u\\left(x\\right) v\\left(x\\right) \\right) dx\\\\\nl\\left(v\\right) &= \\int_\\Omega d\\left(x\\right) v\\left(x\\right) dx\n\\end{align*}\n\nWe will find an approximate solution to the PDE that lies in the space $V$ of functions that are continuous and linear on each of the triangles in the triangulation of $\\Omega$.\nLet $\\phi_i$ be the hat function centered at the $i$'th vertex of the triangulation of $\\Omega$.\nThe $\\phi_i$ are a basis for $V$, so we may say that we seek coefficients $u_i$ such that for any set of coefficients $v_i$,\n\\[a\\left(\\sum_i u_i \\phi_i , \\sum_j v_j \\phi_j \\right) = l\\left(\\sum_j v_j \\phi_j\\right)\\]\nSince $a$ is linear in its second term and $l$ is linear, this is equivalent to finding coefficients $u_i$ such that\n\\[a\\left(\\sum_i u_i \\phi_i , \\phi_j \\right) = l\\left(\\phi_j\\right)\\]\nSince $a$ is also linear in its first term, this is equivalent to finding $u_i$ such that\n\\[\\sum_i u_i a\\left(\\phi_i, \\phi_j\\right) = l\\left(\\phi_j\\right)\\]\nThis problem can be represented as a linear system $A u = \\Phi$ where $\\Phi_j = l\\left(\\phi_j\\right)$ and $A_{j, i} = a\\left(\\phi_i, \\phi_j\\right)$.\nGenerally speaking, this problem can be solved by construct the matrix $A$, and the vector $\\Phi$, and then solving the resulting system.\n\n\\begin{info}\nThe matrix $A$ in the linear system constructed here is often referred to as the ``stiffness matrix.\"\nThe vector $\\Phi$ is commonly known as the ``load vector.\"\n\\end{info}\n\n\\begin{info}\nNotice that $a\\left(\\phi_i, \\phi_j\\right)$ depends entirely on the area where $\\phi_i$ and $\\phi_j$ are both nonzero.\nIf the supports of the functions $\\phi_i$ and $\\phi_j$ do not overlap, $a\\left(\\phi_i, \\phi_j\\right) = 0$.\nSince only neighboring hat functions yield nonzero terms in the sum, the matrix $A$ is usually sparse.\n\\end{info}\n\n\\subsection*{Constructing the Stiffness Matrix and Load Vector}\nIt is not always easiest to construct the stiffness matrix and load vector by considering the basis functions one at a time. ", "meta": {"hexsha": "58bdf055a274434440fde0fa3d743cb2955c8262", "size": 8383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/FiniteElement2D/FiniteElement2D.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/FiniteElement2D/FiniteElement2D.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": 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": "Labs/FiniteElement2D/FiniteElement2D.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 59.0352112676, "max_line_length": 247, "alphanum_fraction": 0.7460336395, "num_tokens": 2289, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942041005328, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7641349023776356}}
{"text": "% !TEX root = ../main.tex\n\n\\section{Abstract data types}\n\nTo model a model we need to be able to model the data too. Similar to functional programming.\n\n\\subsection{Goal}\n\\begin{itemize}\n  \\item Describe abstract data types (ADTs)\n  \\item Be able to use ADTs in mCRL2\n\\end{itemize}\n\n\\subsection{Declaration of data type}\n\n\\textbf{sort} D;\n\nIt represents a non-empty domain. $D$ can have infinite elements.\n\nThe most basic data type are the booleans.\n\n\\textbf{sort} $\\mathbb{B}$;\n\n\\textbf{cons} \\emph{true}, \\emph{false}: $\\mathbb{B}$\n\nSpecial semantic rule: The elements representing \\emph{true} and \\emph{false} of sort $\\mathbb{B}$\n(\\emph{Bool}) must be different.\n\n\\begin{align*}\n  \\text{\\textbf{sort} } & \\mathbb{B}; \\\\\n  \\text{\\textbf{cons} } & true, false: \\mathbb{B}; \\\\\n  \\text{\\textbf{map} } & not: \\mathbb{B} \\Rightarrow \\mathbb{B}; \\\\\n  & and, or: \\mathbb{B} \\times \\mathbb{B} \\Rightarrow \\mathbb{B}; \\\\\n  \\text{\\textbf{var} } & b: \\mathbb{B} \\\\\n  \\text{\\textbf{eqn} } & not(true) = false; \\\\\n  & not(false) = true; \\\\\n  & not(not(true)) = true; \\\\\n  \\text{\\textbf{eqn} } & and(true, b) = b; \\\\\n  & and(false, b) = false; \\\\\n  & and(b, true) = b; \\\\\n  & and(b, false) = false; \\\\\n  \\text{\\textbf{eqn}} & or(true, b) = true; \\\\\n  & or(false, b) = b; \\\\\n  & or(b, true) = true; \\\\\n  & or(b, false) = b; \\\\\n\\end{align*}\n\n\\subsubsection{Induction/case distinction on Bool}\nCan we prove $and(b, b) = b$ ?\n\nAs true and false are the constructors of $\\mathbb{B}$ we only have to prove that \n$and(true, true) = true$ and that $and(false, false) = false$.\n\nProve that $and(b, c) = and(c, b)$:\n\n\\begin{align*}\n  \\text{case } & b = true \\\\\n  & and(true, c) = c \\\\\n  & \\text{case } c = true \\\\\n  & & and(true, true) = and(true, true) \\\\\n  & \\text{case } c = false \\\\\n  & & \\underbrace{and(true, false)}_{false} = \\underbrace{and(false, true)}_{false} \\\\\n\\end{align*}\n\n\\subsection{Specification numbers. Peano arithmetic}\n\n\\begin{align*}\n  \\text{\\textbf{sort} } & Nat; \\\\\n  \\text{\\textbf{cons} } & zero: Nat; \\\\\n  & succ: Nat \\rightarrow Nat; \\\\\n  \\text{\\textbf{map }} & add: Nat \\times Nat \\rightarrow; \\\\\n  \\text{\\textbf{var }} & n, m: Nat; \\\\\n  \\text{\\textbf{eqn }} & add(zero, zero) = zero; \\\\\n  & add(zero, succ(n)) = succ(n); \\\\\n  & add(succ(n), zero) = succ(n); \\\\\n  & add(succ(n), succ(m)) = succ(add(n, succ(m))); \\\\\n  \\text{\\textbf{map }} & <: Nat \\times Nat \\rightarrow \\mathbb{B}; \\\\\n  \\text{\\textbf{eqn }} & n < zero = false; \\\\\n  & zero < succ(n) = true; \\\\\n  & succ(n) < succ(m) = n < m;\n\\end{align*}\n\n\\begin{align*}\n  & zero & 0 \\\\\n  & succ(zero) & 1 \\\\\n  & succ(succ(zero)) & 2 \\\\\n\\end{align*}\n\n\\subsubsection{Induction on Natural numbers}\nProve a property of \\emph{zero}\n\nProve a property for $succ(n)$, assuming that it has been proven for $n$.\n\nThen the property has been prover for all natural numbers $n$.\n\n\\subsection{Specification of efficient natural numbers}\n\nPeano arithmetic is too inefficient for system validation.\n\n\\begin{align*}\n  \\text{sort } & \\mathbb{N}^+; \\qquad \\text{sort } Pos;\n\\end{align*}\n\nNo maximum number\n\n\\subsection{Natural numbers}\n\n\\begin{align*}\n  \\text{sort } & \\mathbb{N}; \\qquad \\text{sort} Nat; \\\\\n  \\text{cons } & @c0: \\mathbb{N}; \\\\\n  & @cNat: \\mathbb{N}^+ \\rightarrow \\mathbb{N}; \\\\\n  \\text{map } & \\simeq: \\mathbb{N} \\times \\mathbb{N} \\rightarrow \\mathbb{N}^+\n\\end{align*}\n\n\\subsection{Type conversion}\n\nAll the type conversions are automatically run into the tools.\n\nSometimes you'll have to explicitly cast some types, specially when downcasting \n\n\\subsection{Data type for lists}\n\nYou can have the empty list or the list with something appended in the front\n\n\n\n\n\n", "meta": {"hexsha": "fab077c7c5d7cd6063ab31efdd9f187aa45f00e4", "size": 3621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/SystemValidation/lectures/lecture_04.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/SystemValidation/lectures/lecture_04.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/SystemValidation/lectures/lecture_04.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": 28.2890625, "max_line_length": 98, "alphanum_fraction": 0.6249654791, "num_tokens": 1222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339756938818, "lm_q2_score": 0.9099069987088003, "lm_q1q2_score": 0.7640798215374286}}
{"text": "\\chapter{Some topological constructions}\nIn this short chapter we briefly describe some common spaces and constructions\nin topology that we haven't yet discussed.\n\n\\section{Spheres}\nRecall that\n\\[ S^n = \\left\\{ (x_0, \\dots, x_n)\n\t\\mid x_0^2 + \\dots + x_n^2 = 1 \\right\\} \\subset \\RR^{n+1} \\]\nis the surface of an $n$-sphere while\n\\[ D^{n+1} = \\left\\{ (x_0, \\dots, x_n)\n\t\\mid x_0^2 + \\dots + x_n^2 \\le 1 \\right\\} \\subset \\RR^{n+1} \\]\nis the corresponding \\emph{closed ball}\n(So for example, $D^2$ is a disk in a plane while $S^1$ is the unit circle.)\n\\begin{exercise}\n\tShow that the open ball $D^n \\setminus S^{n-1}$\n\tis homeomorphic to $\\RR^n$.\n\\end{exercise}\n\nIn particular, $S^0$ consists of two points,\nwhile $D^1$ can be thought of as the interval $[-1,1]$.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(8cm);\n\t\tdraw(dir(0)--dir(180), blue);\n\t\tdot(dir(0), red+4);\n\t\tdot(dir(180), red+4);\n\t\tlabel(\"$S^0$\", dir(0), dir(90), red);\n\t\tlabel(\"$D^1$\", dir(0)--dir(180), blue);\n\t\tadd(shift(-4,0)*CC());\n\t\tunitsize(2cm);\n\t\tfilldraw(unitcircle, lightblue+opacity(0.2), red);\n\t\tlabel(\"$D^2$\", origin, blue);\n\t\tlabel(\"$S^1$\", dir(45), dir(45), red);\n\t\\end{asy}\n\\end{center}\n\n\n\\section{Quotient topology}\n\\prototype{$D^n / S^{n-1} = S^n$, or the torus.}\n\nGiven a space $X$, we can \\emph{identify} some of the points together\nby any equivalence relation $\\sim$;\nfor an $x \\in X$ we denote its equivalence class by $[x]$.\nGeometrically, this is the space achieved by welding together points\nequivalent under $\\sim$.\n\nFormally,\n\\begin{definition}\n\tLet $X$ be a topological space, and $\\sim$ an equivalence relation\n\ton the points of $X$.\n\tThen $X / {\\sim}$ is the space whose\n\t\\begin{itemize}\n\t\t\\ii Points are equivalence classes of $X$, and\n\t\t\\ii $U \\subseteq X / {\\sim}$ is open if and only if\n\t\t$\\left\\{ x \\in X \\text{ such that } [x] \\in U  \\right\\}$\n\t\tis open in $X$.\n\t\\end{itemize}\n\\end{definition}\nAs far as I can tell, this definition is mostly useless for intuition,\nso here are some examples.\n\n\\begin{example}[Interval modulo endpoints]\n\tSuppose we take $D^1 = [-1, 1]$\n\tand quotient by the equivalence relation which identifies\n\tthe endpoints $-1$ and $1$.\n\t(Formally, $x \\sim y \\iff (x=y) \\text{ or } \\{x,y\\} = \\{-1,1\\}$.)\n\tIn that case, we simply recover $S^1$:\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(8cm);\n\t\t\tdraw(dir(0)--dir(180), blue);\n\t\t\tdot(\"$-1$\", dir(0), dir(90), red+4);\n\t\t\tdot(\"$-1$\", dir(180), dir(90), red+4);\n\t\t\tlabel(\"$D^1$\", dir(0)--dir(180), blue);\n\t\t\tadd(shift(-4,0)*CC());\n\t\t\tunitsize(2cm);\n\t\t\tdraw(unitcircle, blue);\n\t\t\tlabel(\"$S^1 \\approx D^1 / {\\sim}$\", dir(45), dir(45), blue);\n\t\t\tdot(\"$-1 \\sim 1$\", dir(90), dir(90), red);\n\t\t\\end{asy}\n\t\\end{center}\n\tObserve that a small open neighborhood around $-1 \\sim 1$ in the quotient space\n\tcorresponds to two half-intervals at $-1$ and $1$ in the original space $D^1$.\n\tThis should convince you the definition we gave is the right one.\n\\end{example}\n\n\\begin{example}[More quotient spaces]\n\tConvince yourself that:\n\t\\begin{itemize}\n\t\t\\ii Generalizing the previous example, $D^n$ modulo its boundary $S^{n-1}$ is $S^n$.\n\t\t\\ii Given a square $ABCD$, suppose we identify segments $AB$ and $DC$ together.\n\t\tThen we get a cylinder. (Think elementary school, when you would tape\n\t\tup pieces of paper together to get cylinders.)\n\t\t\\ii In the previous example, if we also identify $BC$ and $DA$ together,\n\t\tthen we get a torus. (Imagine taking our cylinder and putting the two\n\t\tcircles at the end together.)\n\t\t\\ii Let $X = \\RR$, and let $x \\sim y$ if $y -x \\in \\ZZ$.\n\t\tThen $X / {\\sim}$ is $S^1$ as well.\n\t\\end{itemize}\n\\end{example}\n\nOne special case that we did above:\n\\begin{definition}\n\tLet $A \\subseteq X$.\n\tConsider the equivalence relation which identifies\n\tall the points of $A$ with each other\n\twhile leaving all remaining points inequivalent.\n\t(In other words, $x \\sim y$ if $x=y$ or $x,y \\in A$.)\n\tThen the resulting quotient space is denoted $X/A$.\n\\end{definition}\n\nSo in this notation, \\[ D^n / S^{n-1} = S^n. \\]\n\n\\begin{abuse}\n\tNote that I'm deliberately being sloppy, and saying\n\t``$D^n / S^{n-1} = S^n$'' or ``$D^n / S^{n-1}$ \\emph{is} $S^n$'',\n\twhen I really ought to say ``$D^n / S^{n-1}$ is homeomorphic to $S^n$''.\n\tThis is a general theme in mathematics:\n\tobjects which are homoeomorphic/isomorphic/etc.\\ are generally\n\tnot carefully distinguished from each other.\n\\end{abuse}\n\n\\section{Product topology}\n\\prototype{$\\RR \\times \\RR$ is $\\RR^2$, $S^1 \\times S^1$ is the torus.}\n\n\\begin{definition}\n\tGiven topological spaces $X$ and $Y$,\n\tthe \\vocab{product topology} on $X \\times Y$ is the space whose\n\t\\begin{itemize}\n\t\t\\ii Points are pairs $(x,y)$ with $x \\in X$, $y \\in Y$, and\n\t\t\\ii Topology is given as follows: the \\emph{basis} of\n\t\tthe topology for $X \\times Y$ is $U \\times V$,\n\t\tfor $U \\subseteq X$ open and $V \\subseteq Y$ open.\n\t\\end{itemize}\n\\end{definition}\n\n\\begin{remark}\n\tIt is not hard to show that, in fact,\n\tone need only consider basis elements for $U$ and $V$.\n\tThat is to say,\n\t\\[ \\left\\{ U \\times V \\mid\n\t\tU,V \\text{ basis elements for } X,Y \\right\\} \\]\n\tis also a basis for $X \\times Y$.\n\n\tWe really do need to fiddle with the basis:\n\tin $\\RR \\times \\RR$, an open unit disk better be open,\n\tdespite not being of the form $U \\times V$.\n\\end{remark}\n\nThis does exactly what you think it would.\n\\begin{example}[The unit square]\n\tLet $X = [0,1]$ and consider $X \\times X$.\n\tWe of course expect this to be the unit square.\n\tPictured below is an open set of $X \\times X$ in the basis.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\tsize(6cm);\n\t\tfilldraw(unitsquare, opacity(0.2)+lightblue, black);\n\n\t\tpair B = (0,1);\n\t\tpair A = (1,0);\n\t\tfill(box(0.3*A+0.2*B,0.6*A+0.7*B), lightred+opacity(0.5));\n\t\tlabel(\"$U \\times V$\", (0.45,0.45), brown);\n\n\t\tdraw(0.3*A--(0.3*A+B), heavygreen+dashed+1);\n\t\tdraw(0.6*A--(0.6*A+B), heavygreen+dashed+1);\n\t\tdraw(0.2*B--(0.2*B+A), heavycyan+dashed+1);\n\t\tdraw(0.7*B--(0.7*B+A), heavycyan+dashed+1);\n\n\t\tdraw( 0.3*A--0.6*A, heavygreen+2 );\n\t\topendot( 0.3*A,  heavygreen+2);\n\t\topendot( 0.6*A, heavygreen+2);\n\t\tlabel(\"$U$\", 0.45*A, dir(-90), heavygreen);\n\t\tdraw( 0.2*B--0.7*B, heavycyan+2 );\n\t\topendot( 0.2*B, heavycyan+2);\n\t\topendot( 0.7*B, heavycyan+2);\n\t\tlabel(\"$V$\", 0.45*B, dir(180), heavycyan);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\\begin{exercise}\n\tConvince yourself this basis gives the same topology\n\tas the product metric on $X \\times X$.\n\tSo this is the ``right'' definition.\n\\end{exercise}\n\n\\begin{example}[More product spaces]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\RR \\times \\RR$ is the Euclidean plane.\n\t\t\\ii $S^1 \\times [0,1]$ is a cylinder.\n\t\t\\ii $S^1 \\times S^1$ is a torus! (Why?)\n\t\\end{enumerate}\n\\end{example}\n\n\\section{Disjoint union and wedge sum}\n\\prototype{$S^1 \\vee S^1$ is the figure eight.}\n\nThe disjoint union of two spaces is geometrically exactly\nwhat it sounds like: you just imagine the two spaces side by side.\nFor completeness, here is the formal definition.\n\\begin{definition}\n\tLet $X$ and $Y$ be two topological spaces.\n\tThe \\vocab{disjoint union}, denoted $X \\amalg Y$, is defined by\n\t\\begin{itemize}\n\t\t\\ii The points are the disjoint union $X \\amalg Y$, and\n\t\t\\ii A subset $U \\subseteq X \\amalg Y$ is open if\n\t\tand only if $U \\cap X$ and $U \\cap Y$ are open.\n\t\\end{itemize}\n\\end{definition}\n\\begin{exercise}\n\tShow that the disjoint union of two nonempty spaces is disconnected.\n\\end{exercise}\n\nMore interesting is the wedge sum, where two topological spaces $X$\nand $Y$ are fused together only at a single base point.\n\\begin{definition}\n\tLet $X$ and $Y$ be topological spaces, and $x_0 \\in X$ and $y_0 \\in Y$\n\tbe points.\n\tWe define the equivalence relation $\\sim$ by declaring $x_0 \\sim y_0$ only.\n\tThen the \\vocab{wedge sum} of two spaces is defined as\n\t\\[ X \\vee Y = (X \\amalg Y) / {\\sim}. \\]\n\\end{definition}\n\n\\begin{example}\n\t[$S^1 \\vee S^1$ is a figure eight]\n\tLet $X = S^1$ and $Y = S^1$,\n\tand let $x_0 \\in X$ and $y_0 \\in Y$ be any points.\n\tThen $X \\vee Y$ is a ``figure eight'': it is two\n\tcircles fused together at one point.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(3cm);\n\t\t\tdraw(shift(-1,0)*unitcircle);\n\t\t\tdraw(shift(1,0)*unitcircle);\n\t\t\tdotfactor *= 1.4;\n\t\t\tdot(origin);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\\begin{abuse}\n\tWe often don't mention $x_0$ and $y_0$ when they are understood\n\t(or irrelevant).  For example, from now on we will just\n\twrite $S^1 \\vee S^1$ for a figure eight.\n\\end{abuse}\n\n\\begin{remark}\n\tAnnoyingly, in \\LaTeX\\ \\verb+\\wedge+ gives $\\wedge$ instead\n\tof $\\vee$ (which is \\verb+\\vee+).\n\tSo this really should be called the ``vee product'', but too late.\n\\end{remark}\n\n\n\\section{CW complexes}\nUsing this construction, we can start building some spaces.\nOne common way to do so is using a so-called \\vocab{CW complex}.\nIntuitively, a CW complex is built as follows:\n\\begin{itemize}\n\t\\ii Start with a set of points $X^0$.\n\t\\ii Define $X^1$ by taking some line segments (copies of $D^1$)\n\tand fusing the endpoints (copies of $S^0$) onto $X^0$.\n\t\\ii Define $X^2$ by taking copies of $D^2$ (a disk)\n\tand welding its boundary (a copy of $S^1$) onto $X^1$.\n\t\\ii Repeat inductively up until a finite stage $n$;\n\twe say $X$ is \\vocab{$n$-dimensional}.\n\\end{itemize}\nThe resulting space $X$ is the CW-complex.\nThe set $X^k$ is called the \\vocab{$k$-skeleton} of $X$.\nEach $D^k$ is called a \\vocab{$k$-cell}; it is customary to\ndenote it by $e_\\alpha^k$ where $\\alpha$ is some index.\nWe say that $X$ is \\vocab{finite} if only finitely many cells were used.\n\\begin{abuse}\n\tTechnically, most sources (like \\cite{ref:hatcher}) allow one to\n\tconstruct infinite-dimensional CW complexes.\n\tWe will not encounter any such spaces in the Napkin.\n\\end{abuse}\n\n\\begin{example}\n\t[$D^2$ with $2+2+1$ and $1+1+1$ cells]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\\ii First, we start with $X^0$ having two points $e_a^0$ and $e_b^0$.\n\tThen, we join them with two $1$-cells $D^1$ (green),\n\tcall them $e_c^1$ and $e_d^1$.\n\tThe endpoints of each $1$-cell (the copy of $S^0$) get identified\n\twith distinct points of $X^0$; hence $X^1 \\cong S^1$.\n\tFinally, we take a single $2$-cell $e^2$ (yellow) and weld it in,\n\twith its boundary fitting into the copy of $S^1$ that we just drew.\n\tThis gives the figure on the left.\n\n\t\\ii In fact, one can do this using just $1+1+1=3$ cells.\n\tStart with $X^0$ having a single point $e^0$.\n\tThen, use a single $1$-cell $e^1$, fusing its two endpoints\n\tinto the single point of $X^0$.\n\tThen, one can fit in a copy of $S^1$ as before,\n\tgiving $D^2$ as on the right.\n\t\\end{enumerate}\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(4cm);\n\t\t\tfilldraw(unitcircle, opacity(0.2)+yellow, heavygreen);\n\t\t\tdotfactor *= 1.4;\n\t\t\tdot(dir(90), blue);\n\t\t\tdot(dir(-90), blue);\n\t\t\tlabel(\"$e_a^0$\", dir(90), dir(90), blue);\n\t\t\tlabel(\"$e_b^0$\", dir(-90), dir(-90), blue);\n\t\t\tlabel(\"$e_c^1$\", dir(0), dir(0), heavygreen);\n\t\t\tlabel(\"$e_d^1$\", dir(180), dir(180), heavygreen);\n\t\t\tlabel(\"$e^2$\", origin, origin);\n\t\t\\end{asy}\n\t\t\\qquad\n\t\t\\begin{asy}\n\t\t\tsize(4cm);\n\t\t\tfilldraw(unitcircle, opacity(0.2)+yellow, heavygreen);\n\t\t\tdotfactor *= 1.4;\n\t\t\tdot(dir(90), blue);\n\t\t\tlabel(\"$e^0$\", dir(90), dir(90), blue);\n\t\t\tlabel(\"$e^1$\", dir(-90), dir(-90), heavygreen);\n\t\t\tlabel(\"$e^2$\", origin, origin);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\n\\begin{example}\n\t[$S^n$ as a CW complex]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii One can obtain $S^n$ (for $n \\ge 1$) with just two cells.\n\t\tNamely, take a single point $e^0$ for $X^0$, and to obtain $S^n$\n\t\ttake $D^n$ and weld its entire boundary into $e^0$.\n\n\t\tWe already saw this example in the beginning with $n=2$,\n\t\twhen we saw that the sphere $S^2$ was the result when we fuse\n\t\tthe boundary of a disk $D^2$ together.\n\t\t\n\t\t\\ii Alternatively, one can do a ``hemisphere'' construction,\n\t\tby constructing $S^n$ inductively using two cells in each dimension.\n\t\tSo $S^0$ consists of two points, then $S^1$ is obtained\n\t\tby joining these two points by two segments ($1$-cells),\n\t\tand $S^2$ is obtained by gluing two hemispheres (each a $2$-cell)\n\t\twith $S^1$ as its equator.\n\t\\end{enumerate}\n\\end{example}\n\n\\begin{definition}\n\tFormally, for each $k$-cell $e^k_\\alpha$ we want to add to $X^k$,\n\twe take its boundary $S^{k-1}_\\alpha$ and weld it onto\n\t$X^{k-1}$ via an \\vocab{attaching map} $S^{k-1}_\\alpha \\to X^{k-1}$.\n\tThen\n\t\\[ X^k = X^{k-1} \\amalg \\left(\\coprod_\\alpha e^k_\\alpha\\right) / {\\sim} \\]\n\twhere $\\sim$ identifies each boundary point of $e^k_\\alpha$\n\twith its image in $X^{k-1}$.\n\\end{definition}\n\n\n\\section{The torus, Klein bottle, $\\RP^n$, $\\CP^n$}\n\\label{sec:top_spaces}\nWe now present four of the most import examples of CW complexes.\n\n\\subsection{The torus}\nThe \\vocab{torus} can be formed by taking\na square and identifying the opposite edges in the same direction:\nif you walk off the right edge, you re-appear at the corresponding\npoint in on the left edge.\n(Think \\emph{Asteroids} from Atari!)\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(2cm);\n\t\tfill(unitsquare, yellow+opacity(0.2));\n\t\tpair C = (0,0);\n\t\tpair B = (1,0);\n\t\tpair A = (1,1);\n\t\tpair D = (0,1);\n\t\tdraw(A--B, red, MidArrow);\n\t\tdraw(B--C, blue, MidArrow);\n\t\tdraw(D--C, red, MidArrow);\n\t\tdraw(A--D, blue, MidArrow);\n\t\\end{asy}\n\\end{center}\n\nThus the torus is $(\\RR/\\ZZ)^2 \\cong S^1 \\times S^1$.\n\nNote that all four corners get identified together to a single point.  One\ncan realize the torus in $3$-space by treating the square as a sheet of paper,\ntaping together the left and right (red) edges to form a cylinder,\nthen bending the cylinder and fusing the top and bottom (blue) edges\nto form the torus.\n\\begin{center}\n\t\\includegraphics[width=0.8\\textwidth]{media/Projection_color_torus.jpg}\n\t\\\\ \\scriptsize Image from \\cite{img:torus}\n\\end{center}\n\nThe torus can be realized as a CW complex with\n\\begin{itemize}\n\t\\ii A $0$-skeleton consisting of a single point,\n\t\\ii A $1$-skeleton consisting of two $1$-cells $e^1_a$, $e^1_b$, and\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tunitsize(1cm);\n\t\t\tdraw(shift(-1,0)*unitcircle, blue, MidArrow);\n\t\t\tdraw(shift(1,0)*rotate(180)*unitcircle, red, MidArrow);\n\t\t\tlabel(\"$e^1_a$\", 2*dir(180), dir(180), blue);\n\t\t\tlabel(\"$e^1_b$\", 2*dir(0), dir(0), red);\n\t\t\tdotfactor *= 1.4;\n\t\t\tdot(\"$e^0$\", origin, dir(0));\n\t\t\\end{asy}\n\t\\end{center}\n\t\\ii A $2$-skeleton with a single $2$-cell $e^2$,\n\twhose circumference is divided into four parts,\n\tand welded onto the $1$-skeleton ``via $aba\\inv b \\inv$''.\n\tThis means: wrap a quarter of the circumference around $e^1_a$,\n\tthen another quarter around $e^1_b$,\n\tthen the third quarter around $e^1_a$ but in the opposite direction,\n\tand the fourth quarter around $e^1_b$ again in the opposite direction as before.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(3cm);\n\t\t\tfill(unitcircle, yellow+opacity(0.2));\n\t\t\tdefaultpen(linewidth(1));\n\t\t\tdraw(arc(origin, 1, 45, 135), blue, MidArrow);\n\t\t\tdraw(arc(origin, 1, 315, 225), blue, MidArrow);\n\t\t\tdraw(arc(origin, 1, 135, 225), red, MidArrow);\n\t\t\tdraw(arc(origin, 1, 45, -45), red, MidArrow);\n\t\t\tlabel(\"$e^2$\", origin, origin);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{itemize}\nWe say that $aba\\inv b\\inv$ is the \\vocab{attaching word};\nthis shorthand will be convenient later on.\n\n\\subsection{The Klein bottle}\nThe \\vocab{Klein bottle} is defined similarly to\nthe torus, except one pair of edges is identified in the opposite manner,\nas shown.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(2cm);\n\t\tfill(unitsquare, yellow+opacity(0.2));\n\t\tpair C = (0,0);\n\t\tpair B = (1,0);\n\t\tpair A = (1,1);\n\t\tpair D = (0,1);\n\t\tdraw(A--B, red, MidArrow);\n\t\tdraw(C--B, blue, MidArrow);\n\t\tdraw(D--C, red, MidArrow);\n\t\tdraw(A--D, blue, MidArrow);\n\t\\end{asy}\n\\end{center}\n\nUnlike the torus one cannot realize this in $3$-space\nwithout self-intersecting. One can tape together the red edges\nas before to get a cylinder, but to then fuse the resulting blue\ncircles in opposite directions is not possible in 3D.\nNevertheless, we often draw a picture in 3-dimensional space\nin which we tacitly allow the cylinder to intersect itself.\n\n\\begin{center}\n\t\\begin{minipage}[c]{0.5\\textwidth}\n\t\\includegraphics[width=\\textwidth]{media/klein-fold.png}\n\t\\end{minipage}\n\t\\quad\n\t\\begin{minipage}[c]{0.3\\textwidth}\n\t\\includegraphics[width=\\textwidth]{media/KleinBottle-01.png}\n\t\\end{minipage}\n\t\\par \\scriptsize Image from \\cite{img:kleinfold,img:kleinbottle}\n\\end{center}\n\n\nLike the torus, the Klein bottle is realized as a CW complex with\n\\begin{itemize}\n\t\\ii One $0$-cell,\n\t\\ii Two $1$-cells $e^1_a$ and $e^1_b$, and\n\t\\ii A single $2$-cell attached this time via the word $abab\\inv$.\n\\end{itemize}\n\n\\subsection{Real projective space}\nLet's start with $n=2$.\nThe space $\\RP^2$ is obtained if we reverse both directions of\nthe square from before, as shown.\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(2cm);\n\t\tfill(unitsquare, yellow+opacity(0.2));\n\t\tpair C = (0,0);\n\t\tpair B = (1,0);\n\t\tpair A = (1,1);\n\t\tpair D = (0,1);\n\t\tdraw(B--A, red, MidArrow);\n\t\tdraw(C--B, blue, MidArrow);\n\t\tdraw(D--C, red, MidArrow);\n\t\tdraw(A--D, blue, MidArrow);\n\t\\end{asy}\n\\end{center}\n\nHowever, once we do this the fact that the original\npolygon is a square is kind of irrelevant;\nwe can combine a red and blue edge to get the single purple edge.\nEquivalently, one can think of this as a circle with half\nits circumference identified with the other half:\n\n\\begin{center}\n\t\\begin{asy}\n\t\tsize(3cm);\n\t\tdotfactor *= 2;\n\t\tfill(unitcircle, opacity(0.2)+yellow);\n\t\tdraw(dir(-90)..dir(0)..dir(90), purple, MidArrow);\n\t\tdraw(dir(90)..dir(180)..dir(-90), purple, MidArrow);\n\t\tdot(dir(90));\n\t\tdot(dir(-90));\n\t\tlabel(\"$\\mathbb{RP}^2$\", origin, origin);\n\t\\end{asy}\n\t\\qquad\n\t\\begin{asy}\n\t\tsize(3cm);\n\t\tdotfactor *= 2;\n\t\tdraw(dir(-90)..dir(0)..dir(90));\n\t\tdraw(dir(90)..dir(180)..dir(-90), dashed);\n\t\tfill(unitcircle, yellow+opacity(0.2));\n\t\tdot(dir(90));\n\t\topendot(dir(-90));\n\t\tlabel(\"$\\mathbb{RP}^2$\", origin, origin);\n\t\\end{asy}\n\\end{center}\n\nThe resulting space should be familiar to those of you who do\nprojective (Euclidean) geometry.\nIndeed, there are several possible geometric interpretations:\n\\begin{itemize}\n\t\\ii One can think of $\\RP^2$ as the set of lines through the\n\torigin in $\\RR^3$, with each line being a point in $\\RP^2$.\n\n\tOf course, we can identify each line with a point on the unit sphere $S^2$,\n\texcept for the property that two antipodal points actually \n\tcorrespond to the same line, so that $\\RP^2$ can be almost thought\n\tof as ``half a sphere''. Flattening it gives the picture above.\n\n\t\\ii Imagine $\\RR^2$, except augmented with ``points at infinity''.\n\tThis means that we add some points ``infinitely far away'',\n\tone for each possible direction of a line.\n\tThus in $\\RP^2$, any two lines indeed intersect\n\t(at a Euclidean point if they are not parallel, and at a point\n\tat infinity if they do).\n\n\tThis gives an interpretation of $\\RP^2$,\n\twhere the boundary represents the \\emph{line at infinity}\n\tthrough all of the points at infinity.\n\tHere we have used the fact that $\\RR^2$\n\tand interior of $D^2$ are homeomorphic.\n\\end{itemize}\n\\begin{exercise}\n\tObserve that these formulations are equivalent\n\tby considering the plane $z=1$ in $\\RR^3$,\n\tand intersecting each line in the first formulation with this plane.\n\\end{exercise}\n\nWe can also express $\\RP^2$ using coordinates:\nit is the set of triples $(x : y : z)$ of real numbers not all zero\nup to scaling, meaning that \n\\[ (x : y : z) = (\\lambda x : \\lambda y : \\lambda z) \\]\nfor any $\\lambda \\neq 0$.\nUsing the ``lines through the origin in $\\RR^3$'' interpretation\nmakes it clear why this coordinate system gives the right space.\nThe points at infinity are those with $z = 0$,\nand any point with $z \\neq 0$ gives a Cartesian point since\n\\[ (x : y : z) = \\left( \\frac xz : \\frac yz : 1 \\right) \\]\nhence we can think of it as the Cartesian point $(\\frac xz, \\frac yz)$.\n\nIn this way we can actually define \\vocab{real-projective $n$-space},\n$\\RP^n$ for any $n$, as either\n\\begin{enumerate}[(i)]\n\t\\ii The set of lines through the origin in $\\RR^{n+1}$,\n\t\\ii Using $n+1$ coordinates as above, or\n\t\\ii As $\\RR^n$ augmented with points at infinity,\n\twhich themselves form a copy of $\\RP^{n-1}$.\n\\end{enumerate}\n\nAs a possibly helpful example, we give all three pictures of $\\RP^1$.\n\\begin{example}\n\t[Real projective $1$-Space]\n\t$\\RP^1$ can be thought of as $S^1$ modulo the relation\n\tthe antipodal points are identified.\n\tProjecting onto a tangent line, we see that we get\n\ta copy of $\\RR$ plus a single point at infinity, corresponding\n\tto the parallel line (drawn in cyan below).\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(7cm);\n\t\t\tfilldraw(unitcircle, lightblue+opacity(0.2), heavyblue+opacity(0.4));\n\t\t\tlabel(\"$S^1$\", dir(225), dir(225), lightblue);\n\t\t\tdot(\"$\\vec 0$\", origin, dir(45));\n\t\t\tpair X1 = (-2.1,1);\n\t\t\tpair X2 = (1.9,1);\n\t\t\tdraw(X1--X2, heavyred, Arrows);\n\t\t\tdot(\"$0$\", (0,1), dir(90), heavyred);\n\t\t\tdot(\"$1$\", (1,1), dir(90), heavyred);\n\t\t\tpair P = extension( (0,1), (1,1), dir(250), dir(70) );\n\t\t\tdot(\"$0.36$\", P, dir(90), heavyred);\n\t\t\tlabel(\"$\\mathbb R$\", X2, dir(105), heavyred);\n\n\t\t\tpath L(pair A, pair B, real a=0.6, real b=a)\n\t\t\t\t{ return (a*(A-B)+A)--(b*(B-A)+B); }\n\t\t\tdraw(L(dir(130),-dir(130),0.2,0.2), gray);\n\t\t\tdraw(L(dir(250),-dir(250),0.2,0.2), gray);\n\t\t\tdraw(L(dir(-20),-dir(-20),0.2,0.2), gray);\n\t\t\tdraw(L(dir(0), -dir(0), 0.4,0.4), heavycyan+1);\n\t\t\\end{asy}\n\t\\end{center}\n\n\tThus, the points of $\\RP^1$ have two forms:\n\t\\begin{itemize}\n\t\t\\ii $(x:1)$, which we think of as $x \\in \\RR$ (in dark red above), and\n\t\t\\ii $(1:0)$, which we think of as $1/0 = \\infty$,\n\t\tcorresponding to the cyan line above.\n\t\\end{itemize}\n\tSo, we can literally write\n\t\\[ \\RP^1 = \\RR \\cup \\{\\infty\\}. \\]\n\tNote that $\\RP^1$ is also the boundary of $\\RP^2$.\n\tIn fact, note also that topologically we have\n\t\\[ \\RP^1 \\cong S^1 \\]\n\tsince it is the ``real line with endpoints fused together''.\n\t\\begin{center}\n\t\t\\begin{asy}\n\t\t\tsize(2cm);\n\t\t\tdraw(unitcircle, heavyred);\n\t\t\tdot(\"$\\infty$\", dir(90), dir(90), heavycyan);\n\t\t\tdot(\"$0$\", dir(-90), dir(-90), heavyred);\n\t\t\\end{asy}\n\t\\end{center}\n\\end{example}\n\nSince $\\RP^n$ is just ``$\\RR^n$ (or $D^n$) with $\\RP^{n-1}$ as its boundary'',\nwe can construct $\\RP^n$ as a CW complex inductively.\nNote that $\\RP^n$ thus consists of \\textbf{one cell in each dimension}.\n\n\\begin{example}[$\\RP^n$ as a cell complex]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\RP^0$ is a single point.\n\t\t\\ii $\\RP^1 \\cong S^1$ is a circle, which as a CW complex\n\t\tis a $0$-cell plus a $1$-cell.\n\t\t\\ii $\\RP^2$ can be formed by taking a $2$-cell\n\t\tand wrapping its perimeter twice around a copy of $\\RP^1$.\n\t\\end{enumerate}\n\\end{example}\n\n\\subsection{Complex projective space}\nThe \\vocab{complex projective space} $\\CP^n$ is\ndefined like $\\RP^n$ with coordinates, i.e.\\\n\\[ (z_0 : z_1 : \\dots : z_n) \\]\nunder scaling; this time $z_i$ are complex.\nAs before, $\\CP^n$ can be thought of as $\\CC^n$ augmented\nwith some points at infinity (corresponding to $\\CP^{n-1}$).\n\\begin{example}\n\t[Complex projective space]\n\t\\listhack\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\CP^0$ is a single point.\n\t\t\\ii $\\CP^1$ is $\\CC$ plus a single point at infinity\n\t\t(``complex infinity'' if you will).\n\t\tThat means as before we can think of $\\CP^1$ as\n\t\t\\[ \\CP^1 = \\CC \\cup \\{\\infty\\}. \\]\n\t\tSo, imagine taking the complex plane and then adding\n\t\ta single point to encompass the entire boundary.\n\t\tThe result is just sphere $S^2$.\n\t\\end{enumerate}\n\tHere is a picture of $\\CP^1$ with its coordinate system,\n\tthe \\vocab{Riemann sphere}.\n\t\\begin{center}\n\t\t\\includegraphics[width=0.9\\textwidth]{media/earth.pdf}\n\t\\end{center}\n\\end{example}\n\n\\begin{remark}\n\t[For Euclidean geometers]\n\tYou may recognize that while $\\RP^2$ is the setting for projective geometry,\n\tinversion about a circle is done in $\\CP^1$ instead.\n\tWhen one does an inversion sending generalized circles to generalized\n\tcircles, there is only one point at infinity:\n\tthis is why we work in $\\CP^n$.\n\\end{remark}\n\nLike $\\RP^n$, $\\CP^n$ is a CW complex, built inductively\nby taking $\\CC^n$ and welding its boundary onto $\\CP^{n-1}$\nThe difference is that as topological spaces,\n\\[ \\CC^n \\cong \\RR^{2n} \\cong D^{2n}. \\]\nThus, we attach the cells $D^0$, $D^2$, $D^4$ and so on\ninductively to construct $\\CP^n$.\nThus we see that\n\\begin{moral}\n\t$\\CP^n$ consists of one cell in each \\emph{even} dimension.\n\\end{moral}\n\n\n\\section\\problemhead\n\\begin{problem}\n\tShow that a space $X$ is Hausdorff if and only if the diagonal\n\t$\\{(x,x) \\mid x \\in X\\}$ is closed in the product space $X \\times X$.\n\\end{problem}\n\\begin{problem}\n\tRealize the following spaces as CW complexes:\n\t\\begin{enumerate}[(a)]\n\t\t\\ii M\\\"obius strip.\n\t\t\\ii $\\RR$.\n\t\t\\ii $\\RR^n$.\n\t\\end{enumerate}\n\\end{problem}\n\\begin{dproblem}\n\tShow that a finite CW complex is compact.\n\t\\begin{hint}\n\t\tProve and use the fact that a quotients of compact spaces remain compact.\n\t\\end{hint}\n\\end{dproblem}\n", "meta": {"hexsha": "2f4f67182889bd89c4a9ae7dba11aafb1c6e5b28", "size": 24612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/topology/constructions.tex", "max_stars_repo_name": "aDotInTheVoid/ltxmk", "max_stars_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_stars_repo_licenses": ["Apache-2.0", "MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "corpus/napkin/tex/topology/constructions.tex", "max_issues_repo_name": "aDotInTheVoid/ltxmk", "max_issues_repo_head_hexsha": "ee461679e51e92a0e4b121f28ae5fe17d5e5319e", "max_issues_repo_licenses": ["Apache-2.0", "MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "corpus/napkin/tex/topology/constructions.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.3263598326, "max_line_length": 86, "alphanum_fraction": 0.6697139607, "num_tokens": 8380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339596505965, "lm_q2_score": 0.9099069980980297, "lm_q1q2_score": 0.7640798064266462}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Can a column vector ever be equal to a row vector?\n\n  \\begin{sol}\n    Yes, a $1\\times 1$-matrix is both a row vector and a column\n    vector.  However, a column vector of dimension $2$ or greater can\n    never be equal to a row vector, because one is an $n\\times\n    1$-matrix and the other is a $1\\times n$-matrix.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find scalars $x,y,z$ such that the following two matrices are equal.\n  \\begin{equation*}\n    \\begin{mymatrix}{rr}\n      x & -1 \\\\\n      2 & 4\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\begin{mymatrix}{rr}\n      2 & y \\\\\n      z & 4\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $x=2$, $y=-1$, $z=2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  What are the dimensions of the following matrices?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & -2 & 0 \\\\\n      4 & 3 & 2\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rrr}\n      3 & 4 & 1 \\\\\n      1 & 3 & 1 \\\\\n      6 & 2 & 2\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rrr}\n      1 & 0 \\\\\n      4 & 0 \\\\\n      2 & 0 \\\\\n      0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    $2\\times 3$, $3\\times 3$, $4\\times 2$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  What is the $(2,3)$-entry of the matrix $\\begin{mymatrix}{rrr}\n    1 & 2 & 1 \\\\\n    -4 & 4 & 7 \\\\\n    6 & -5 & 3\n  \\end{mymatrix}$?\n  \\begin{sol}\n    $7$.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "a87843990df42eecf23aabdc9651b93a4810afcf", "size": 1411, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-Definition.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-Definition.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-Definition.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 20.75, "max_line_length": 70, "alphanum_fraction": 0.5343727853, "num_tokens": 575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7640721427666173}}
{"text": "%\\section{1.10 Exercise 10. An open mapping theorem}\n\\textit{Suppose that X and Y are topological vector spaces,\n%\n  $\\dim Y < \\infty$,\n%\n$\\Lambda : X \\to Y$ is linear, and $\\Lambda(X) = Y$.\n%\n  \\begin{enumerate}\n    \\item{\n      Prove that $\\Lambda$ is an open mapping.}\n    \\item{\n      Assume, in addition, that the null space of $\\Lambda$ is closed, \n      and prove that $\\Lambda$ is continuous.\n    }\n  \\end{enumerate}\n  %\n}\n%\n\\begin{proof}\n%We discard the trivial case $\\dim Y = 0$ then henceforth assume that $\\dim Y$ \n%has positive dimension $n$. \\\\\\\\\n%\nDiscard the trivial case $\\Lambda = 0$ then assume that %\n$\\dim Y = n$ %\nfor some positive $n$. %\nLet $e$ range over a base of $B$ of $Y$. %\nPick $W$ an arbitrary neighborhood of the origin: %\nThere so exists $V$ %\na balanced neighborhood of the origin such that \n%\n  \\begin{align}\n    \\label{definition of v}\n    \\underset{\n      \\text{Put } V \\text{ exactly } n \\text{ time(s)}\n    }{\n      \\underbrace{V+\\cdots +V}\n    }\\subset W, \n  \\end{align}\n%\nsince addition is continuous. %\nMoreover, for each $e$, \nthere exists $x_e$ in $X$ such that \n%\n  $\\Lambda(x_e)=e$, \n% \nsimply because $\\Lambda$ is onto. So,\n%\n  \\begin{align}\\label{1_10_sum}\n    y = \\sum_{e} y_e \\cdot \\Lambda x_e, \n  \\end{align}\n%\ngiven any element $y=\\sum_{e}y_e\\cdot e$ of $Y$. %\nAs a finite set, $\\set{x_e}{e\\in B}$ is bounded: %\nIn particular, there exists  a positive scalar $s$ such that  \n%\n  \\begin{align}\n    \\forall e\\in B,  x_e \\in s \\cdot V.\n  \\end{align}\n%\nCombining this with (\\ref{1_10_sum}) shows that \n%\n  \\begin{align}\n    \\label{y in sum of lambda V}\n    y \\in \\sum_e y_e \\cdot s \\cdot \\Lambda (V).\n  \\end{align}\n%\nWe now come back to (\\ref{definition of v}) and so conclude that %\n%\n  \\begin{align}\n    y \\in \\sum_e \\Lambda (V) \\subset \\Lambda(W) \n  \\end{align}\n%\nwhether $\\magnitude{y_e} < 1/s$; which proves (a).\\\\\\\\\n%\n%\nTo prove (b), assume that the null space \n%\n  $\\singleton{\\Lambda = 0}$ %\n% \nis closed and let $f, \\pi$ be as in Exercise 1.9,  %\n%\n  $\\singleton{\\Lambda = 0}$ %\n%\nplaying the role of $N$.\n%%\n% Isomorphism:\n%  \\begin{align}\n%    & X \\to                    X/N   \\to                  Y . \\\\\n%    & x \\overset{\\pi}{\\mapsto} \\pi x  \\overset{f}{\\mapsto} \\Lambda x \\nonumber\n%  \\end{align}\n%\nSince $\\Lambda$ is onto, the first isomorphism theorem (see Exercise 1.9) \nasserts that \n%\n  $f$ is an isomorphism of $X/N$ onto $Y$. \n%\nConsequently, \n%\n  \\begin{align}\n    \\dim X/N= n.\n  \\end{align}\n% \n$f$ is then an homeomorphism of \n%\n  $X/N\\equiv \\C^{n}$ \n%\nonto $Y$; see \\citeresultFA{1.21}.\nWe have thus established that $f$ is continuous: So is $\\Lambda = f\\circ \\pi$.\n\\end{proof}", "meta": {"hexsha": "c6ebdfa138fccea5dd60b4244bf9a772f50bee71", "size": 2650, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_1/1_10.tex", "max_stars_repo_name": "gitcordier/FunctionalAnalysis", "max_stars_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter_1/1_10.tex", "max_issues_repo_name": "gitcordier/FunctionalAnalysis", "max_issues_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter_1/1_10.tex", "max_forks_repo_name": "gitcordier/FunctionalAnalysis", "max_forks_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.3119266055, "max_line_length": 79, "alphanum_fraction": 0.6075471698, "num_tokens": 898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137996, "lm_q2_score": 0.853912747375134, "lm_q1q2_score": 0.7640721361134754}}
{"text": "\n\\subsection{Independent increments}\n\nThe changes in any non-overlapping time increments are independent.\n\nFormally:\n\n\\(t_0<t_1<t_2<...<t_m\\)\n\nWith \\(X_t\\)\n\n\\(X_{t_1}-X_{t_0}\\) is indepentent from \\(X_{t_2}-X{t_1}\\) etc.\n\n\\subsection{Wiener processes}\n\nA Wiener process is a process \\(W_t\\) with independent increments, which:\n+ Is continuous\n+ Has normally distributed increments.\n\nCan be constructed as limit of random walk.\nCan also be constructed as integral of Gaussian noise?\n\n", "meta": {"hexsha": "c34b8286ec52de8139238cca82d4567f9dbdeb50", "size": 483, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/brownian/01-01-wiener.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/brownian/01-01-wiener.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/brownian/01-01-wiener.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.0, "max_line_length": 73, "alphanum_fraction": 0.7453416149, "num_tokens": 133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8539127529517044, "lm_q1q2_score": 0.7640721243329964}}
{"text": "\\lab{Line Sweep and Voronoi Diagrams}{Line Sweep}\n\\label{lab:Linesweep}\n\n\\objective{Learn about and implement a basic line sweep algorithm and Introduce Voronoid Diagrams and Delaunay Triangulations and discuss their applications}\n\n\\section*{General Line Sweep Algorithms}\n\nLine sweep algorithms are a significant group of algorithms with a variety of applications. \nIn the strictest sense, line sweep algorithms typically use a priority queue and binary tree to lower the temporal complexity associated with certain tasks. \nSome notable examples include Fortune's Algorithm for calculating Voronoi diagrams and Andrew's Algorithm for computing the convex hull of a set of points. \nIn this lab, we will explore a basic line sweep algorithm that allows efficient computation of the Closest Pair problem.  \nGiven a set of points, find the distance between the closest pair of points.\n\n\\section*{Na\\\"ive Implementation}\n\nThe obvious way of doing this is to simply compute the distance between each point and each of the other points.\nRoughly speaking, this requires some constant multiple of $n^2$ computations where $n$ is the number of points.\nThis can be coded as follows:\n\\begin{lstlisting}\ndef reallybadmindist(X):\n    r = ((X[0]-X[1])**2).sum()**.5\n    for i in range(len(X)):\n        for j in range(len(X)):\n            if i != j:\n                r = min(r,((X[i]-X[j])**2).sum()**.5)\n    return r\n\\end{lstlisting}\nSince distance is symmetrical, we can compare each point with the points that follow it in the list we are given (which will reduce\nthe total number of distances to be computed).\nThis is a slightly better implementation:\n\\begin{lstlisting}\ndef multidist(p0,p1):\n    l=len(p0)\n    return sum([(p0[i]-p1[i])**2 for i in range(l)])**.5\ndef badmindist(X):\n    l=len(X)\n    r=multidist(X[0],X[1])\n    for i in xrange(l):\n        for j in xrange(i+1,l):\n            d=multidist(X[i],X[j])\n            if d<r:\n                r=d\n    return r\n\\end{lstlisting}\n\nSince, on average, we iterate through about half of the list for each point added, this algorithm will have complexity $O(n^2)$ (we are only scaling by a constant factor).  \nIt is faster than the truly na\\\"ive method, but essentially just as inefficient.\nFor very small numbers of points, this algorithm works, but it quickly becomes inefficient as we increase the number of points processed.  \nWhat we would like to do is go from $O(n^2)$ to something better.  \nTo do this, we have to think about the problem differently.\nThis can be done by using one of the key techniques of computational geometry-a line sweep algorithm.\n\n\\section*{A Simplified Line Sweep Algorithm}\n\nThe concept behind a line sweep algorithm is breaking a global problem into a sequence of smaller problems that can be solved locally.\nWe sweep the domain space with a line.\nThis line divides the domain space into an explored region and an unexplored region.\nAs the line sweeps, events occur, be it whether the line encounters a point in the data set\nor some other type of event.  \nWe compute the solution at the very beginning of the line sweep and as new events happen, we compute the change that these events have on our current solution.\nWe only need to consider the events in the explored region or on the sweep line as they are the only events that affect the current solution.  \nSweep line algorithms typically exhibit a temporal complexity of $O(n \\log n)$, which is far better than $O(n^2)$.\n\nLine sweep algorithms are good for doing all sorts of proximity based computations.\nIn the example above, we took advantage of the fact that distance was symmetric ($d(a,b)=d(b,a)$).\nIn a line sweep version of this algorithm, we also take advantage of the fact that any points further than the current smallest minimum distance along a given axis do not need to be considered.\nThis is really just an application of the triangle inequality.\nThe secret to the line sweep solution for the closest pair problem is to actually have two sweep lines with a small distance between them.\nAs we process the points in our list, we can decrease the distance between the lines so that we only process points that could possibly give a smaller distance than the smallest distance we have already encountered.\nBy only processing the points between our two sweep lines, we avoid processing many points needlessly.\n\nFor a general line sweep algorithm, it is common to use a priority queue to order the items that need to be processed.\nA good priority queue can be found in the library \\li{Queue} that is included in Python. \nIn this case all we need to do is sort the points by $X$ value.\nThis means it will be easier to make a sorted copy of the array using Numpy's built in functions.\nSomething like \\li{X=Y.take(Y[:,0].argsort(),axis=0)} or \\li{Y[Y[:,0].argsort()]} will do this for you. \n\nWe track the points in the area between the two sweep lines with a list.\nEach time we advance the sweep lines, we update this list so it always contains the points between the sweep lines (adding or removing points where necessary).\nA point stays in the list if its distance from the leading sweep line is less than the current minimum distance.\nConceptually, this is how we place the second sweep line.\n\nAssuming we have already ordered all our points by $x$ coordinate, we can perform the line sweep algorithm as follows:\n\n\\vspace{5mm}\n\\begin{compactenum}[1.]\n\\item \nProcess the first two points and add them to the active list.\nSet current minimum distance to the distance between these two points.\n\\item \nGet the next point in the priority queue.\n\\item \nUpdate the active list so that it contains only the points between the two sweep lines.\n\\item \nCompute the distance between the current point and all the points in the active list.\n\\item \nCompare the smallest distance found with the current minimum distance. \nChange the current minimum distance if needed.\n\\item \nRepeat steps 2 to 5 for all remaining points in the priority queue\n\\end{compactenum}\n\\vspace{5mm}\n\nWhen the algorithm ends, the current minimum distance will be the distance between the closest pair of points.\n\nThis algorithm can be illustrated as follows:\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple0.pdf}\n\\caption{After processing the first two points, we process the third point and change the current minimum distance accordingly.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple1.pdf}\n\\caption{This change in the minimum thus far is reflected in how we form the actives list for the next point we process. \nWe remove the points from the top of the queue that are too far away in the $x$ direction to have a distance less than the current minimum. \nWe then process anything that is left.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple5.pdf}\n\\caption{A few points further in we actually hit the minimum distance.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple7.pdf}\n\\caption{After iterating over all the points in the set, we have the final minimum distance desired.}\n\\end{figure}\n\nThis process is outlined in Algorithm \\ref{alg:linesweep_simple}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{MindistSimple}{$Y, \\text{metric}$}\n\t\\LineComment{Make sorted copy of $Y$ to perform linesweep.}\n\t\\State $X \\gets Y \\text{ sorted along first coordinate}$\n\t\\LineComment{Initialize the smallest distance as the distance between the first points.}\n\t\\State $r \\gets metric\\left(X\\left[0\\right], X\\left[1\\right]\\right)$\n\t\\LineComment{Use indices to track which points are active.}\n\t\\State $l \\gets 0$\n\t\\LineComment{This is all that is needed for the first two points.}\n\t\\LineComment{Iterate over the remaining points.}\n\t\\For{$i=2$, $j<k$}\n\t\t\\LineComment{Update $l$ to not include points that are too far away.}\n\t\t\\While{$X\\left[l, 0\\right] + r < X\\left[i, 0\\right]$}\n\t\t\t\\State $l += 1$\n\t\t\\EndWhile\n\t\t\\LineComment{If there are any points to process, process them.}\n\t\t\\If{$l < i$}\n\t\t\t\\State $r \\gets \\text{min}\\left(r, \\text{metric}\\left(X\\left[i\\right], X\\left[l:i\\right]\\right)\\right)$\n\t\t\\EndIf\n\t\\EndFor\n\t\\State \\pseudoli{return} $r$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{A Simplified Line Sweep Algorithm}\n\\label{alg:linesweep_simple}\n\\end{algorithm}\n\n\\begin{problem}\nWrite a Python function that implements the above algorithm.\nHave your code accept a metric function as a parameter.\nThis metric function should take a point and an array of points as arguments and return an array of distances from the point to each of the points in the array. \nTest your function's speed. \nHow does it scale as you increase the number of points? \nHow does it scale as you increase the number of dimensions?\n\\end{problem}\n\n\\section*{A Line Sweep Algorithm}\n\nYou may have noticed that we are not exploiting all the symmetry of the problem in the previous algorithm. \nIt would likely speed things up if we could also slice away the points that have $y$ values that could not possibly yield the minimum distance. \nThe simplest way to do this in this case is to take advantage of some algebraic symmetry.\nAs we compute the distance between two points, we have to calculate the difference between each of the coordinates of the points in question. \nIf at any time the difference has an absolute value greater than the minimum distance we have encountered thus far, we know we don't need to finish processing the point.\nThis is, theoretically, like slicing along the other axes in order to further reduce the ``active'' list of points.\nA similar result could be obtained by using a list, binary tree, or some other data structure to keep the list of active points sorted by $y$ value, but in this case the insertion and deletion operations involved are more costly.\n\nThis algorithm can be illustrated as follows:\n\nNote: in this case we sweep along the $x$ axis from right to left.\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep0.pdf}\n\\caption{In processing the first point, we find find that we must reduce the radius.\nNotice that we only need to consider the points that lie in the box formed by the red an blue lines.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep13.pdf}\n\\caption{This is where we actually hit the minimum distance.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep22.pdf}\n\\caption{After processing through all the points, we are guaranteed to have hit the minimum distance already, so our minimum distance thus far is our final return value.}\n\\end{figure}\n\nThis process is outlined in Algorithm \\ref{alg:linesweep_full}.\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{Mindist}{$Y, \\text{metric}$}\n\t\\LineComment{Make sorted copy of $Y$ to perform linesweep.}\n\t\\State $X \\gets Y \\text{ sorted along first coordinate}$\n\t\\LineComment{Store number of dimensions.}\n\t\\State $dim \\gets Y.\\text{shape}\\left[1\\right]$\n\t\\LineComment{Initialize the smallest distance as the distance between the first points.}\n\t\\State $r \\gets metric\\left(X\\left[0\\right], X\\left[1\\right]\\right)$\n\t\\LineComment{Use indices to track which points are active.}\n\t\\State $l \\gets 0$\n\t\\LineComment{This is all that is needed for the first two points.}\n\t\\LineComment{Iterate over the remaining points.}\n\t\\For{$i=2$, $j<k$}\n\t\t\\LineComment{Update $l$ to not include points that are too far away.}\n\t\t\\While{$X\\left[l, 0\\right] + r < X\\left[i, 0\\right]$}\n\t\t\t\\State $l += 1$\n\t\t\\EndWhile\n\t\t\\LineComment{If there are any points to process, process them.}\n\t\t\\For{$k=l$, $i$}\n\t\t\t\\LineComment{Initialize a flag to store whether or not to process a point.}\n\t\t\t\\State $proc \\gets \\text{True}$\n\t\t\t\\LineComment{Initialize partially computed distance to $0$.}\n\t\t\t\\State $d \\gets 0.$\n\t\t\t\\LineComment{Compute differences in each dimension.}\n\t\t\t\\For{$j=1$, $dim$}\n\t\t\t\t\\State $dif \\gets \\left|X\\left[k,j\\right] - \\left[i, j\\right]\\right|$\n\t\t\t\t\\LineComment{Stop computation if point is too far away.}\n\t\t\t\t\\If{$r < dif$}\n\t\t\t\t\t\\LineComment{Set flag to avoid further computations for this point.}\n\t\t\t\t\t\\State $proc \\gets \\text{False}$\n\t\t\t\t\t\\State \\pseudoli{break}\n\t\t\t\t\\EndIf\n\t\t\t\t\\LineComment{If the point still needs to be processed,}\n\t\t\t\t\\LineComment{add in the difference squared.}\n\t\t\t\t\\State $d \\gets d + dif^2$\n\t\t\t\\EndFor\n\t\t\t\\LineComment{If the point still has not been rejected, compute the distance.}\n\t\t\t\\LineComment{Update the minimum distance if needed.}\n\t\t\t\\If{$proc$}\n\t\t\t\t\\State $dif \\gets X\\left[k,0\\right] - X\\left[i,0\\right]$\n\t\t\t\t\\State $r \\gets \\text{min}\\left(r, \\sqrt{d + dif^2}\\right)$\n\t\t\t\\EndIf\n\t\t\\EndFor\n\t\\EndFor\n\t\\State \\pseudoli{return} $r$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{A Line Sweep Algorithm}\n\\label{alg:linesweep_full}\n\\end{algorithm}\n\n\n\\begin{problem}\nImplement the algorithm above in Python. \nTime it against the naive implementation at the beginning of this lab and against the simplified version you coded above.\nThe new version should be faster, but speed depends heavily on how you have implemented it, so you may have some optimization left to do.\nTime how long it takes your new function to process ten million points in two dimensions. \nUsing benchmarks from the first implementation we gave you, estimate how long (in years) it would take that function to process that many points.\nHow many times faster is the good implementation?\n\\end{problem}\n\nSince this version of the algorithm depends so heavily on array lookups, it will be much faster if it is implemented in Cython.\n\n\\section*{Voronoi Diagrams}\n\nIn this section we will discuss some applications of Voronoi Diagrams.\nThey are an application of the line sweep algorithm in that they can be computed using a line sweep algorithm called Fortune's Algorithm.\nIn the abstract sense, a Voronoi diagram is a partition of a plane into regions that lie closest to different points.\nThe easiest way to understand this is to look at some examples.\nFigure \\ref{voronoi_ex_1} is a voronoi diagram generated from 100 random points with $x$ and $y$ values between 0 and 1.\nNotice how each point has a small  cell around it that is made up of the points that lie closest to it.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{voronoi_example_1.pdf}\n\\caption{A Voronoi diagram of the square $[0,1]\\times [0,1]$ for 100 randomly generated points.}\n\\label{voronoi_ex_1}\n\\end{figure}\n\nOne possible way to compute this sort of diagram would be by brute force, for example:\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nfrom matplotlib import pyplot as plt\n\ndef pnorm(pt, X, p=2):\n    # Take the p-norm distance between a point 'pt'\n    # and an array of points 'X'.\n    if p == \"inf\":\n        return np.absolute(pt - X).max(axis=-1)\n    return (np.absolute(pt - X)**p).sum(axis=-1)**(1./p)\n\ndef brute_force_voronoi(n, res, p=2, filename=None):\n    # Generates a grid of points and tests to find the nearest\n    # neighbor for each of them.\n    pts = rand(n, 2)\n    X = np.linspace(0, 1, res)\n    # Make an array to store the indices of the nearest points.\n    indices = np.zeros((res, res))\n    for i in xrange(res):\n        for j in xrange(res):\n            indices[i, j] = pnorm(np.array([X[j], X[i]]), pts, p).argmin()\n    # Make a colorplot of the results.\n    X, Y = np.meshgrid(X, X, copy=False)\n    plt.pcolormesh(X, Y, indices)\n    plt.scatter(pts[:,0], pts[:,1])\n    plt.xlim((0,1))\n    plt.ylim((0,1))\n    plt.show()\n\nbrute_force_voronoi(10, 401)\n\\end{lstlisting}\nThis algorithm is good because it can work regardless of the metric space we are using, but it is terribly slow.\nFigure \\ref{voronoi_1norm} shows a similar diagram using the 1-norm and figure \\ref{voronoi_supnorm} shows a diagram generated using the supremum norm.\nIt is linear in the number of points added and linear in the number of pixels used to represent the diagram.\nThis can be a terrible limitation, but if you are not working in a well behaved metric space, this may be the simplest approach.\n\\begin{figure}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{voronoi_1norm.png}\n\\caption{Voronoi diagram in the 1-norm}\n\\label{voronoi_1norm}\n\\end{minipage}\n\\hspace{0.5cm}\n\\begin{minipage}[b]{0.45\\linewidth}\n\\centering\n\\includegraphics[width=\\textwidth]{voronoi_supnorm.png}\n\\caption{Voronoi diagram in the supremum norm}\n\\label{voronoi_supnorm}\n\\end{minipage}\n\\end{figure}\n\nIt is also possible to make voronoi diagrams based off of shapes and lines as well as points. \n\nThere are several data structures used in the field of computational geometry that can store the exact edges of diagrams like this.\nWe would prefer to not have to worry about sampling the domain in this way.\nThere are a variety of algorithms that can compute Voronoi diagrams in $\\mathcal{O}\\left( n \\log\\left(n\\right)\\right)$ time (where $n$ is the number of points).\nFortune's algorithm is a linesweep algorithm that can do this.\n\nThe Qhull library is commonly used to compute voronoi diagrams, and delaunay triangulations.\nSciPy includes a wrapper of the Qhull library in the \\li{scipy.spatial} module.\nIt currently only supports 2 dimensional voronoi diagrams under the Euclidean norm.\nIt allows you to generate a voronoi diagram from a set of points, add points to a voronoi diagram, find the nearest point to any given point, and plot a voronoi diagram.\n\nA plot similar to the one we just generated can be made using SciPy like this:\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nimport scipy.spatial as st\nfrom matplotlib import pyplot as plt\nG = rand(100,2)\nG = st.Voronoi(G)\nst.voronoi_plot_2d(G)\nplt.xlim((0, 1))\nplt.ylim((0, 1))\nplt.show()\n\\end{lstlisting}\nNotice how much clearer the plot is and how much faster it is generated.\nTry running the last bit of code for 1000 points.\nThough this is a little slower than it was for 10 points, this is a graph that would not display well if we had been using the brute force method.\n\nTable \\ref{voronoi_attributes} shows the different attributes of the \\li{Voronoi} object.\nFor more details, see \\url{http://docs.scipy.org/doc/scipy-dev/reference/spatial.html}\n\\begin{table}[h!]\n\\begin{center}\n\t\\begin{tabular}{|l|p{12cm}|}\n    \\hline\n\n    \\li{points} & coordinates of input points (centers of cells)\\\\\n\n    \\li{vertices} & vertices of graph\\\\\n\n    \\li{ridge_points} & indices of the input points between which each ridge on the diagram lies\\\\\n\n    \\li{ridge_vertices} & indices of the vertices at the end of each ridge\\\\\n\n    \\li{regions} & indices of the vertices corresponding to each voronoi cell\\\\\n\n    \\li{point_region} & indices of the regions corresponding to each input point\\\\\n\n    \\hline\n\n    \\end{tabular}\n\\end{center}\n\\caption{Various summarizing functions}\n\\label{voronoi_attributes}\n\\end{table}\n\nUnfortunately, the \\li{Voronoi} objects do not allow us to find out, given the coordinates of a new point, which of our original input points lies the closest to it.\nTo do something like that we would need to use a different algorithm or data structure.\nOne possible way of solving such a problem is to us a KD tree.\nKD trees are discussed in further detail in Volume II.\nScipy includes built in KD trees in both Python and C.\nThe version in C is generally faster.\nYou can make a KD tree like this\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nimport scipy.spatial as st\nA = rand(1000,2)\nkd = st.cKDTree(A)\n\\end{lstlisting}\nIn this case we used the \\li{cKDTree} object.\nThat is a KDTree implemented in C.\n\\li{KDTree} is a Python-based version that is also included in scipy.\nTo find the nearest neighbor of a point \\li{pt} and how far away it is we can now use the following line of code:\n\\begin{lstlisting}\nkd.query(pt)\n\\end{lstlisting}\nThis returns a tuple containing the distance of the given point to the nearest point in \\li{A} and the index of that nearest neighbor in \\li{A}.\nFor exmaple, if you put in:\n\\begin{lstlisting}\nkd.query(A[27])\n\\end{lstlisting}\nIt will return\n\\begin{lstlisting}\n(0.0,27)\n\\end{lstlisting}\nSince \\li{A[27]} would be the nearest point at a distance of \\li{0.0}.\n\\section*{Applications of Voronoi Diagrams}\n\nThough the computation of a Voronoi Diagram does not provide a quick way to run nearest neighbor queries, there are still several applications for Voronoi Diagrams.\nThe first, and probably most obvious, is the representation of data.\nIf you want to look for visual patterns in data, a Voronoi Diagram can be very useful.\nOne historically significant example was the containment of the London Cholera outbreak of 1854.\nThe English Mathematician John Snow plotted where the cholera outbreaks had all happened and after some consideration, noticed that they were all relatively close to a certain water pump in that portion of the city.\nUpon noticing this, he plotted the voronoi cell of that particular water pump and proposed that the cholera outbreak was linked to contaminated water.\nHe recommended that the pump handle be removed so that people would have to use other pumps in the city.\nOnce the contaminated pump was shut down, the cholera outbreak was stopped.\n\nVoronoi diagrams can also be used to solve problems involving the points furthest from those already on the graph.\nExamples include determining where to drill next when searching for oil, or where to put a new branch of a major company.\n\nThe file \\li{edge_intersections.py} included with this lab contains a helper function, \\li{edge_intersections}, that will be helpful for the rest of the lab.\nIt takes a Voronoi diagram object as input as well as two tuples (xlims and ylims) representing the limits of a rectangle.\nIt returns an array containing the intersections of the edges of the voronoi diagram with the boundaries of the rectangular region.\nIt also returns two lists of pairs of indices.\nIn the first list of indices, the first index in each pair corresponds to one of the vertices of the Voronoi diagram and the second index corresponds to one of the intersections found by this function.\nThe second list of indices accounts for the case that no endpoint of an edge intersecting the region lies within the region.\nIn the second list of indices, both indices of each pair correspond to intersections with the boundaries of the region.\n\n\\begin{problem}\n\\label{FurthestPoints}\nWrite a function that, given a list of points, \\li{pts}, and a rectangular region of the plain and an integer \\li{n}, finds the \\li{n} points in the region that lie farthest from all the points in \\li{pts}.\nDo this by creating a list of tuples with the first element as the distance to the nearest neighbor in \\li{pts} and the second element of each tuple the canidate point.\nYou should use a KD tree to compute the distance to the nearest neighbor.\nAdd to your list of canidate tuples the veritices of the Voronoi diagram, the intersection of the edges given by the helper function, and the corners of the region.\nThe library \\li{heapq} has a nice function \\li{nlargest(n,Q)} that will sort your list \\li{Q} by the first element in your tuples and return sorted the largest \\li{n} elements.\n\\end{problem}\n\nAnother possible application is navigation through a field of obstacles.\nThis can be done by creating a Voronoi diagram where each obstacle is represented as a point.\nThis diagram can then be represented as a graph where the vertices of the Voronoi diagram are considered to be the nodes.\nUsing a shortest path algorithm you can find the shortest path between the two sides that would keep you as far from the obstacles as possible.\n\n\\begin{comment}\n\\begin{problem}\nGiven a voronoi diagram object, write a function that uses NetworkX to find the shortest path along the edges diagram between any two given vertices.\nHave this function take a threshold value to limit which ridges are included.\nDo not include a ridge in the adjacency matrix if the distance from the ridge to the center points of the Voronoi cells is less than the threshold.\nYou can find this distance by measuring the distance between each pair of points referenced in the \\li{ridge_points} attribute of the Voronoi object and then dividing by two.\nNote: the infinite ridges of the graph have $-1$ listed as one of the indices in the \\li{ridge_vertices} attribute.\nMake sure you do not include these ridges.\n\nDepending on what is needed from the algorithm, you could modify the weights of the graph to give preference to edges that pass farther from the obstacles.\nA fuller solution of this problem would also account for the bounds of the region.\nThat could be done with the helper function included with this lab.\n\\end{problem}\n\\end{comment}\n\nAnother possible application of voronoi diagrams is in the estimation of total rainfall, size of ore deposits, or other similar problems.\nOne simple way to do this is to take a weighted average of all known measurements where each measurement is given the weight corresponding to the size of its voronoi cell.\n\n\\begin{comment}\n% This problem is cool, but it would probably make the lab too long\n% I'll leave it here in case we want to add it later\n\n\\begin{problem}\n\\label{AverageRainfall}\nWrite a function that, given a square region and measurement values at different nodes, computes the weighted average of the measurements over the region.\nWeight each measurement according to the area of the voronoi cell of each node.\n\nHint: You can find the area of each voroni cell by considering the triangles formed between its vertices and its center point. One way to compute the area of a triangle given the coordinates of its vertices is $A = \\sqrt{s\\left(s-a\\right) \\left(s-b\\right) \\left(s-c\\right)}$ where $s = \\frac{a+b+c}{2}$ and $a$, $b$, and $c$ are the lengths of the edges of the triangle.\nThis is known as Herron's Formula.\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Delaunay Triangulation}\n\nA concept related to Voronoi diagrams is that of the Delaunay Triangulation.\nDelaunay Triangulations also have a wide variety of applications.\nOne such application is the automatic division of a region into triangles for use in finite element analysis for the numerical solution of partial differential equations.\nIn general, the delaunay triangulation divides the smallest convex region containing all the given points (the convex hull) into triangles that obey certain rules.\n\nYou can make a Delaunay Triangulation from a list of points and plot it like this:\n\\begin{lstlisting}\nA = rand(100, 2)\nD = st.Delaunay(A)\nplt.triplot(A[:,0] ,A[:,1], D.simplices)\nplt.show()\n\\end{lstlisting}\n\n\\begin{problem}\nUse a Delaunay triangulation to write a function that breaks up the unit square into right triangles.\nHave the only argument to your function be the number of nodes you want along each edge of the square.\nPlot your results.\n\\end{problem}\n\n%other possible applications:\n%Use Delaunay Triangulation to tesselate a 3d surface.\n%Use tesselation to rerun ore/rainfall problem and compare results.\n", "meta": {"hexsha": "d8baf67ae657c5e2967531cfa4f7305225e3032c", "size": 26835, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/LineSweep/linesweep.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/LineSweep/linesweep.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/LineSweep/linesweep.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": 52.6176470588, "max_line_length": 370, "alphanum_fraction": 0.7628842929, "num_tokens": 6681, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637648915617, "lm_q2_score": 0.888758786126321, "lm_q1q2_score": 0.7640337241618074}}
{"text": "\\section*{Ex.34.3-2}\n\\subsection*{Show that the $\\leq_P$ relation is a transitive relation on languages}\n\nWe want to show, that if $L_1\\leq_P L_2$ and $L_2\\leq_P L_3$, then $L_1\\leq_P L_3$.\n\\\\\nSince $L_1\\leq_P L_2$ and $L_2\\leq_P L_3$, then there exists polynomial-time computable reduction functions $f_A$ and $f_B$, where $f_A$ reduces $L_1$ to $L_2$, and $f_B$ reduces $L_2$ to $L_3$.\n\\\\\nA polynomial-time computable reduction function $f_C$ can simply use first $f_A$ and then $f_B$, to reduce $L_1$ to $L_3$, meaning we must have $L_1\\leq_P L_3$.", "meta": {"hexsha": "ce3ba1beff565a71e151d623a7285bf934e9696f", "size": 551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge4/Ex.34.3-2.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge4/Ex.34.3-2.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge4/Ex.34.3-2.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 68.875, "max_line_length": 194, "alphanum_fraction": 0.7186932849, "num_tokens": 216, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8596637523076225, "lm_q1q2_score": 0.7640337193101209}}
{"text": "\n\\subsection{Parameter identification problem with simultaneous equations}\n\n\\subsubsection{Identification terminology}\n\nA system is under-identified if there are not enough estimators for all structural parameters.\n\nA system is exactly identified if there are the same number of estimators as structural parameters.\n\nA system is over-identified if there are more estimators than structural parameters.\n\nIn general we have in our structural form:\n\n\\(\\sum^n_i\\beta_{ij}y_i=\\sum^m_i\\gamma_{ij}x_i+\\epsilon_j\\)\n\nThis is a system with \\(n\\) endogeneous variables and \\(m\\) exogeneous variables.\n\nWe can write this in matrix form.\n\n\\(B\\mathbf y =\\Gamma \\mathbf{x} + \\mathbf{\\epsilon}\\)\n\nWe can use this to get:\n\n\\(\\mathbf{y} =B^{-1}\\Gamma \\mathbf{x} + B^{-1}\\mathbf{ \\epsilon}\\)\n\nWe estimate by placing restrictions on \\(\\Gamma\\).\n\n\\subsubsection{Strucutral models}\n\nIf our data generating process is:\n\n\\(Q=\\alpha + \\beta P +\\epsilon \\)\n\nWe can estimate \\(\\alpha \\)and \\(\\beta \\) through measuring \\(P\\) and \\(Q\\).\n\nIf, however the data generating process involves simulataneous equations, we can have:\n\n\\(Q=\\alpha_1 + \\beta_1 P + \\epsilon_1 \\)\n\n\\(Q=\\alpha_2 + \\beta_2 P + \\epsilon_2 \\)\n\n\\subsubsection{Reduced form}\n\nWe can reduce this:\n\n\\(\\alpha_1 + \\beta_1 P + \\epsilon_1 =\\alpha_2 + \\beta_2 P + \\epsilon_2 \\)\n\n\\((\\alpha_1 -\\alpha_2 )+ (\\beta_1 -\\beta_2 )P + (\\epsilon_1 -\\epsilon_2 )=0\\)\n\n\\(P =\\dfrac{\\alpha_2-\\alpha_1 }{\\beta_1-\\beta_2}+\\dfrac{\\epsilon_2-\\epsilon_1 }{\\beta_1-\\beta_2}\\)\n\nWe can rewrite this as:\n\n\\(P=\\pi_1 + \\tau_1 \\)\n\nSimilarly we can reduce for \\(Q\\):\n\n\\(Q =\\dfrac{\\alpha_2\\beta_1-\\alpha_1\\beta_2 }{\\beta_1-\\beta_2}+\\dfrac{\\beta_1\\epsilon_2 -\\beta_2\\epsilon_1}{\\beta_1-\\beta_2}\\)\n\n\\(Q= \\pi_2 + \\tau_2\\)\n\n\\subsubsection{We can't directly estimate structural models}\n\nIf \\(P\\) is correlated with \\(epsilon_1\\) or \\(\\epsilon_2\\) then our estimates for \\(\\beta_1\\) and \\(\\beta_2\\) will be biased.\n\nThis also affects \\(Q\\).\n\nFrom the reduced forms we can see that \\(P\\) will be correlated, due to simultaneity.\n\n\\subsubsection{The identification problem}\n\nWe can estimate \\(\\pi_1 \\) and \\(\\pi_2\\), but this does not allow us to identify any of the structural parameters.\n\nWe have \\(2\\) estimators, but \\(4\\) parameters.\n\nThis is the identification problem.\n\n", "meta": {"hexsha": "cd7bc18f63c63eff60d655332a02391a13833619", "size": 2271, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsMore/02-02-endogeneity.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsMore/02-02-endogeneity.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsMore/02-02-endogeneity.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.1153846154, "max_line_length": 126, "alphanum_fraction": 0.7102597974, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772220439509, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7640109986975911}}
{"text": "\\subsection{Principle of explosion}\n\nIf axioms contradict each other then it is possible to derive anything. That is:\n\n$P\\land \\neg P\\vdash Q$\n\nWe can prove this. If \\(P\\) and \\(\\neg P\\) are true, then the following is also true:\n\n\\(P\\lor Q\\)\n\nWe can then use \\(P\\lor Q\\) and \\(\\neg P\\) to imply \\(Q\\).\n\nThis works for any proposition \\(Q\\), including \\(\\neg Q\\).\n\nAs we can derive \\(Q\\) and \\(\\neg Q\\), our axioms are not consistent.\n\n", "meta": {"hexsha": "d20eca5984c72da754ff65961160a9d878212e3f", "size": 436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-02-explosion.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-02-explosion.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/propositionalLogicInference/01-02-explosion.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.6470588235, "max_line_length": 85, "alphanum_fraction": 0.6651376147, "num_tokens": 128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9343951588871157, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7639376346616615}}
{"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 an image classification problem, a neural network perform multiple combinations of linear and non-linear transformations of each image $I$ to assign it a label $C_I$ chosen in the set of all the possible labels $\\mathcal C$. The first \\textit{layer} of the neural network transforms the input image $I$ in a vector - called \\textit{feature map} - $\\mathbf f_1$ through a function $\\phi_1$.  The output feature map of the first layer is used as input of the second layer that transforms it through a 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 With a large \\textit{training set} of pre labeled images at its disposal, a NN is capable of learning the optimal transformations $\\phi_i$ that let it map each 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. In the work of Cs\\'aji \\cite{NN}, NNs have been proved to be universal function approximators, meaning that with a sufficient number of parameters NNs are able to approximate any continuous function on a compact domain. This 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 subset of NNs 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 \\textit{fully connected} neural network: each layer is constrained to learn only those transformations of the input that are \\textit{equivariant} to translations of the input. This means that a translation of the input image will not result in a change of class. The layers $\\phi_i$ of a CNN are \\textit{convolutions} with some kernels $k_i$, that were 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 -, 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 \\cite{SCNN}, \\cite{Esteves}.\n\nSpherical convolutional neural networks (SCNNs) are CNNs that have been designed to deal with spherical data, whose layer design makes them equivariant to \\textit{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 rotation equivariant architectures 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. Each layer of a SCNN performs a \\textit{spherical convolution} of the input feature map with a kernel $k_i$ learned during the training phase. One of the main issues with traditional SCNNs is the computational complexity of computing at each layer the Spherical Harmonic Transform of the data to perform the convolution. To overcome this issue, 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\\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}\n\nThis work is organized as follows: in Chapter 1 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 classical SHT.  We present then some basics of Spectral Graph Theory that lay the foundations of Graph Convolutional Neural Networks.  In Chapter 2 we present the general framework of how to discretize the Laplace-Beltrami operator on a general manifold, concluding with the special case of the Heat Kernel Graph Laplacian (HKGL) approximation, together with some convergence results. We continue in Chapter 3 by introducing DeepSphere \\cite{DeepSphere}, a Graph Spherical Convolutional Neural Network (GCNN) that uses a graph Laplacian matrix $\\mathbf L$ similar to the HKGL to perform graph convolutions that are almost equivariant to rotations. We study the spectral properties and the equivariance error of DeepSphere and we show a way to build a graph $G'$ such that the corresponding graph Laplacian matrix $\\mathbf L'$ shows better spectral and equivariance properties. In Chapter 4 we show better graph constructions than the HKGL on non uniform sampling measures. To conclude, we show a different approach to perform rotation invariant convolutions that uses the Finite Element Method (FEM) approximation of the Laplace-Beltrami operator on the the sphere. Chapter 5 concludes this work by presenting some experimental results obtained by Gusset et al. \\cite{Gusset} that implemented the graph $G'$ on a GCNN and compared its performances to DeepSphere on a well known dataset \\cite{SHREC17} showing that the new graph $G'$ performs better in real applications. We finish by comparing the FEM and the graph approach, discussing the general problem of how to incorporate geometrical informations about the sphere in the graph.\n\n\\subsection{Fourier Transforms and Convolutions on the 2-Sphere}\\label{sec:Fourier on the Sphere}\nThe goal of this section is to present to the reader some fundamental results of spectral theory on the sphere that we will need in this work. We present a brief review of Banach and Hilbert spaces, spherical harmonics, Fourier transform and convolution on $\\mathbb S^2$. We refer to Sections 2 and 3 of the work of Driscoll and Healy \\cite{Driscoll:1994:CFT:184069.184073} for a more detailed and effective review of spectral theory on the Sphere.\n\n\\paragraph{Banach and Hilbert spaces.}\nA \\textit{norm} $\\norm\\cdot:\\ X\\to\\mathbb R$ on a vector space $X$ is a subadditive, positive definite function such that $\\norm{x+y}\\leq\\norm x +\\norm y,\\ \\forall x,y\\in X$ (triangle inequality). A \\textit{Cauchy sequence} $(x_n)\\subset X$ is a sequence such that $\\forall \\epsilon>0\\  \\exists M>0: $ $\\forall i,j>M$ $ \\norm{x_i-x_j}<\\epsilon$. A \\textit{Banach space} $(X, \\norm{\\cdot})$ is a normed vector space on the scalar field $F$ that is \\textit{complete}, meaning that $X$ is \"big enough\" such that for every Cauchy sequence $(x_n)\\subset X$ there exist a $x\\in X$ such that $x$ is the limit of $(x_n)$ in $X$ i.e. $\\norm{x_n-x}\\rightarrow 0$. A \\textit{basis} of $(X, \\norm\\cdot)$ is a minimal set of linearly independent vectors $\\mathcal B \\subset X$ such that every element of $X$ can be written as linear combination of the elements of $\\mathcal B$. A scalar product is a function $\\langle\\cdot,\\cdot\\rangle: X\\times X \\rightarrow \\mathbb F$ that is linear in the first argument, positive definite and conjugate symmetric. Through a scalar product we can define the notion of angle $\\theta$ between two elements $x, y \\in X$ through the following formula: \n$$\n\\cos \\theta = \\frac{\\langle x, y\\rangle}{\\norm x \\norm y}\n$$ \nIn particular we can define the notion of orthogonality: two elements  $x, y \\in X$ are orthogonal if and only if $\\langle x, y\\rangle=0$. We are interested in those particular Banach spaces where we can define a notion of orthogonality between vectors. A Banach space $(X, \\norm \\cdot )$ is a \\textit{Hilbert space} when the norm $ \\norm \\cdot $ can be induced by a \\textit{scalar product}: $\\norm \\cdot = \\sqrt{\\langle\\cdot,\\cdot\\rangle}$. We can now define an \\textit{orthonormal} basis of $X$: a basis $\\mathcal B \\subset X$ such that $\\forall x, y \\in \\mathcal B, \\norm x = \\norm y = 1 \\text{and } \\langle x, y\\rangle = 0$. Given an orthonormal basis $\\mathcal B = \\{b_i\\}_{i\\in I}$ we can write each vector in its \\textit{Fourier series} \n\\begin{equation}\\label{eq:abstract fourier}\nx = \\sum_{i\\in I} \\langle x, b_i\\rangle b_i\n\\end{equation}\nIf the set $I$ is countable the Hilbert space $(X, \\norm\\cdot)$ is called \\textit{separable}. Having a countable orthonormal basis, and thus the possibility of representing each vector through its Fourier series enormously simplifies many problems.\n\\paragraph{Spherical Harmonics.}\n Given the usual parametrization $x = x(\\theta, \\phi), \\theta\\in[0,\\pi], \\phi\\in[0,2\\pi]$ of the sphere\n\\begin{align*}\n\\mathbb{S}^{2}&=\\left\\{\\omega=\\left(\\omega_{1}, \\omega_{2}, \\omega_{3}\\right) \\in \\mathbb{R}^{3} :\\|x\\|_{\\mathbb{R}^{3}}=\\left(\\omega_{1}^{2}+\\omega_{2}^{2}+\\omega_{3}^{2}\\right)^{1 / 2}=1\\right\\}\\\\\n\\omega_{1}&=\\cos (\\phi) \\sin (\\theta), \\quad \\omega_{2}=\\sin (\\phi) \\sin (\\theta), \\quad \\omega_{3}=\\cos (\\theta)\n\\end{align*}\nthe Hilbert space $L^2(\\mathbb S^2)$ is defined as the space of square-integrable functions endowed with the scalar product $\\langle f,g\\rangle=\\int_{\\mathbb S^2}f(\\omega)\\overline g(\\omega)d\\omega$ where the measure $d\\omega$ is the rotation-invariant measure such that\n\\begin{align}\n\\int_{\\omega \\in \\mathbb S^{2}} f(\\omega) d \\omega&=\\int_{\\phi=0}^{2 \\pi} \\int_{\\theta=0}^{\\pi} f(\\omega(\\theta, \\phi)) \\sin \\theta d \\theta d \\phi\\\\\n\\int_{\\omega \\in \\mathbb S^{2}} f(g \\omega) d \\omega&=\\int_{\\omega \\in \\mathbb S^{2}} f(\\omega) d \\omega, \\quad g \\in S O(3)\n\\end{align}\n\nFor each rotation $g\\in SO(3)$ we define a corresponding rotation operator $\\Lambda(g)$ by\n\\begin{equation}\\label{eq:rotation operator}\n\t\\Lambda(g) f(\\omega)=f\\left(g^{-1} \\omega\\right)\n\\end{equation}\nA space is invariant under the rotations $g$ in $SO(3)$ if all operators $\\Lambda(g)$ take each function of the space back into the space. As very well written by Driscoll et al \\cite{Driscoll:1994:CFT:184069.184073}:\n\n\\vspace{0.2cm}\n\\textit{Fourier analysis on the sphere amounts to the decomposition of the space of square integrable functions on \\(\\mathbb S^{2}\\) in minimal subspaces $V_\\ell$ invariant under all of the rotations in \\(S O(3),\\) thus simplifying the analysis of rotation-invariant operators.}\n\\vspace{0.2cm}\n\nIt's a well known fact \\cite{Driscoll:1994:CFT:184069.184073} that the $\\ell$-th invariant subspace $V_\\ell\\subset L^2(\\mathbb S^2)$ is made of polynomials of $\\mathbb R^3$ of degree $\\ell$ restricted to $\\mathbb S^2$, and has dimension $2\\ell+1$. Its elements are called \\textit{spherical harmonics} of degree $\\ell$. These subspaces are orthogonal between them, and correspond to the eigenspaces of the Laplace-Beltrami operator $\\Delta_{\\mathbb S^2}$. For a thorough introduction to how to define the Laplace-Beltrami operator on a manifold and its properties, see \\cite{rosenberg_1997}. The set of all the orthonormal basis $Y_\\ell^m,\\ -\\ell\\leq m\\leq\\ell$ of each subspace $V_\\ell$ gives an orthonormal basis of $L^2(\\mathbb S^2)$. The analytical expression of the spherical harmonic $Y_\\ell^m(\\theta, \\phi)$ is actually known \\cite{Driscoll:1994:CFT:184069.184073}:\n\\begin{equation}\\label{eq:spherical harmonics}\n\tY_\\ell^m(\\theta, \\phi) = (-1)^{m} \\sqrt{\\frac{(2 \\ell+1)(\\ell-m) !}{4 \\pi(\\ell+m) !}} P_{\\ell}^{m}(\\cos \\theta) e^{i m \\phi}\n\\end{equation}\nwhere $P_{\\ell}^{m}$ are the \\textit{Legendre functions} as defined in \\cite{Driscoll:1994:CFT:184069.184073}. \n\\vspace{0.5cm}\n\\begin{remark}\n\tSaying that the space $V_\\ell$ is invariant under rotations $SO(3)$ means that under any rotation $g\\in SO(3)$, any spherical harmonic $Y_\\ell^m\\in V_\\ell$ is transformed into a linear combination of the others spherical harmonics of the same degree $\\ell$:\n\t$$\n\t\\Lambda(g) Y_{\\ell}^{m}(\\omega)=\\sum_{|k| \\leq \\ell} Y_{\\ell}^{k}(\\omega) \\alpha_{k, m}^{(\\ell)}(g).\n\t$$\n\\end{remark}\n\\vspace{0.5cm}\n\n\\paragraph{Fourier transform.}\nWe can now expand each function $f\\in L^2(\\mathbb S^2)$ in the orthonormal coordinate system given by the spherical harmonics \n\\begin{align}\\label{eq:inverse spherical fourier transform}\n\tf(\\omega) &= \\sum_{\\ell\\in\\mathbb N}\\sum_{|m|\\leq \\ell}\\hat f(\\ell,m) Y_\\ell^m(\\omega)\\\\\n\t\\hat f(\\ell,m) &=\\int_{\\omega\\in\\mathbb S^2}f(\\omega)Y_\\ell^m(\\omega)d\\omega \\label{eq:SHT}\n\\end{align}\nwhere the coefficients $\\hat f(\\ell,m)$ are the \\textit{Fourier coefficients} of $f$. The computation of $\\hat f(\\ell, m)$ is called Spherical Harmonic Transform (SHT). Thanks to equation (\\ref{eq:spherical harmonics}) we can decompose the computation of the SHT (\\ref{eq:SHT}) in the two directions $(\\theta, \\phi)$. One reason for which the most popular sampling schemes of the sphere have the pixels lie on isolatitude circles is that it is possible to use standard one-dimensional FFT algorithms to compute the longitudinal part of the transform, making the computation of the SHT $\\mathcal O(n^{3/2})$, where $n$ is the number of pixels \\cite{HEALPix}.\n\n\\paragraph{Convolutions.}\nConvolution on the sphere is profoundly different than convolution on the Euclidean plane $\\mathbb R^2$. Since translations are isomorphic to $\\mathbb R^2$, the convolution $f*g(x)$ of two functions $f, g \\in L^2(\\mathbb R^2)$ is itself a function on the plane:\n\\begin{equation}\\label{eq:plane convolution}\n\t \\int_{\\mathbb R^2} f(y)g(x-y)dy = f*g(x):\\quad \\mathbb R^2 \\to\\mathbb R\n\\end{equation}\nOn the sphere things work differently: translations are replaced by rotations, but due to the fact that $SO(3)$ is not isomorphic to $\\mathbb S^2$, if we define the convolution on $\\mathbb S^2$ as follows:\n\\begin{equation} \\label{eq:cohen convolution}\nf* k(g) := \\int_{\\eta \\in \\mathbb S^2} \\Lambda(g)k( \\eta) f(\\eta) d\\eta=\\int_{\\eta \\in \\mathbb S^2} k(g^{-1} \\eta) f(\\eta) d\\eta\\\\ \n\\end{equation}\n$f*k(g): SO(3)\\to\\mathbb R$ is not a function of the sphere anymore, but it is a function of the special rotation group $SO(3)$. In section \\ref{sec:Chapter1:SCNN} we will explain how Cohen et al. \\cite{SCNN} use in their work this definition of convolution on the sphere to construct a rotation equivariant NN. However, the definition of convolution that we will use in this work is the following, where the integral is performed not on the sphere but on the rotation group $SO(3)$:\n\n\\begin{equation}\\label{eq:convolution}\n k * f(\\omega)=\\int_{g \\in S O(3)} k(g \\eta) f\\left(g^{-1} \\omega\\right) d g \n\\end{equation}\n\nwhere $dg$ is the measure on $SO(3)$ that can be written in terms of the three Euler angles $(\\theta, \\phi, \\psi)$ \n$$dg=\\sin\\theta d\\theta d\\phi d\\psi$$\nIn this way $k * f(\\omega)$ is still a function defined on $\\mathbb S^2$. However, integrating on $SO(3)$ means integrating on the third Euler angle $\\psi$, that in practice means using definition (\\ref{eq:cohen convolution}) with the use of \\textit{radial} kernels $k$ only.\nUsing the convolution defined in equation (\\ref{eq:convolution}), the following theorem \\cite{Driscoll:1994:CFT:184069.184073} generalizes on the sphere a well known property of convolutions and Fourier transforms: \n\\vspace{0.5cm}\n\\begin{theorem}\\label{theo:convolution}\n\tGiven two functions $f, h$ in $L^2(\\mathbb S^2)$, the Fourier transform of the convolution is a pointwise product of the transforms\n$$\n\\hat{(f * h)}(\\ell, m)=2 \\pi \\sqrt{\\frac{4 \\pi}{2 \\ell+1}} \\hat{f}(\\ell, m) \\hat{h}(\\ell, 0).\n$$\n\\end{theorem}\n\\vspace{0.5cm}\n\n\\subsection{Spherical Convolutional Neural Networks}\\label{sec:Chapter1:SCNN}\nCohen et al. \\cite{SCNN} proposed a NN where the first layer performs a convolution on the sphere as defined by equation (\\ref{eq:cohen convolution}). The output feature map - a signal on $SO(3)$ - is processed by the deeper layers that perform other convolutions in $SO(3)$. All these convolutions are performed in the spectral domain as in theorem \\ref{theo:convolution}, meaning that every signal has to be Fourier-transformed first, at each forward and backward step of the training phase of the NN. This approach, even with the use of Generalized FFT algorithms for $\\mathbb S^2$ and $SO(3)$, remains both computationally expensive ($\\mathcal O(n^{3/2})$) and memory expensive, due to the need of storing kernels defined on the much bigger space $SO(3)$. In section \\ref{sec:Chapter5:Experimental validation} we report in table (\\ref{tab:SHREC17_class}) the results of Gusset et al. \\cite{Gusset}, that compared both the training and inference time of Cohen's SCNN, showing how slow this architecture is compared to other rotation equivariant NNs.\n\\subsection{Spectral Graph Theory} \\label{sec:Chapter1: Spectral Graph Theory}\n\\paragraph{Graphs.}\nFor the purposes of this work, a \\textit{weighted undirected graph} $G(V, E, \\mathbf W)$ is defined by a vertex set $V$, an edge set $E$, where the edges are unordered pairs of vertices, and the matrix $\\mathbf W$ whose entries $w_{ij}$ represent the weight of the edge $(v_i, v_j)$. $G$ is a \\textit{simple} graph, if $w_{ij}$ assume only values in $\\{0, 1\\}$. Undirected graphs are common mathematical objects used to model simple, symmetric relationships between things. The edge $e_{ij} = (v_i, v_j) \\in E$ is the mathematical object that translates the fact that the vertices $v_i, v_j$ are in a relationship, and the weight $w_{ij}$ measures how strong this relationship is. Common examples of graphs include friendship graphs, where people are the vertices and the edges represent friendship, or electric network graphs, where vertices represent electronic components and edges represent wires.\n\\paragraph{The graph Laplacian.}\nIf $\\mathbf D$ is the diagonal matrix $\\mathbf D_{ii} = \\sum_j w_{ij}$, one can define \\cite{Vandergheynst} the combinatorial graph Laplacian $\\mathbf L$\n\\begin{equation}\\label{eq:graph Laplacian}\n\t\t\\mathbf L = \\mathbf D-\\mathbf W\n\\end{equation}\n and the symmetric normalized graph Laplacian $\\mathbf L'$\n\\begin{equation}\\label{eq:normalized graph Laplacian}\n\\mathbf L' =  \\mathbf D^{-1/2}\\mathbf L\\mathbf D^{-1/2} = \\mathbf I - \\mathbf D^{-1/2}\\mathbf W\\mathbf D^{-1/2}\n\\end{equation}\nIn a simple friendship graph $G$, one can define a vector $\\mathbf f$ such that each entry $ f_i$ is the age of the person associated with the vertex $v_i$, and could try to measure how much people tend to be friends with people of the same age. In other words, how smooth the signal $\\mathbf f$ is on the graph $G$. A good measure for the smoothness of a signal on a graph is given by the \\textit{Dirichlet energy} of the signal $\\mathbf f$, i.e., the quadratic form associated with the normalized Laplace operator $\\mathbf L'$:\n\\begin{equation}\\label{eq:quadratic form}\n\t\\mathbf f^\\intercal \\mathbf L' \\mathbf f = \\sum_{\\left(v_{j}, v_{k}\\right) \\in {E}} \\frac{\\boldsymbol{W}_{j k}}{\\sqrt{d_{j} {d}_{k}}}\\left({f}_{j}-{f}_{k}\\right)^{2}\n\\end{equation}\nThe reason why the Dirichlet energy is a good measure of the smoothness of $\\mathbf f$ is easier to understand in the case of a simple graph, where it reduces to the sum\n\\begin{equation}\\label{eq:simple dirichlet energy}\n\t\\mathbf f^\\intercal \\mathbf L' \\mathbf f = \\sum_{\\left(v_{j}, v_{k}\\right) \\in {E}} \\left({f}_{j}-{f}_{k}\\right)^{2}.\n\\end{equation}\n that will grow for each edge $(v_i, v_j)$ connecting people with very different age. Although the Dirichlet energy (\\ref{eq:quadratic form}) works also for the combinatorial graph Laplacian $\\mathbf L$, in practice it is preferred to use the symmetric normalized Laplacian when the degree distribution is wide. Another way of looking at equation (\\ref{eq:simple dirichlet energy}) is as the following: the differences ${f}_j-{f}_k$ can be seen as the \\textit{gradient} $\\nabla \\mathbf{f}$ that is a signal on the edges $(v_j, v_k)$ and equation (\\ref{eq:simple dirichlet energy}) as the quadratic norm of such gradient $\\norm {\\nabla \\mathbf{f}}^2$.\n\\paragraph{Graph Fourier transform}\nSince the graph Laplacian is a symmetric matrix, we can write its eigen decomposition \\cite{Strang}\n$$\n\\mathbf L = \\mathbf V\\mathbf \\Lambda\\mathbf V^\\intercal\n$$\n where $\\mathbf V$ is the orthonormal basis of $\\mathbb R^n$ of eigenvectors, and $\\mathbf \\Lambda$ the real diagonal matrix of the eigenvalues $\\mathbf \\Lambda = \\text{diag}(\\lambda_i\\in \\mathbb R)$. Similarly to the continuous domain, where the Fourier transform of a signal $f$ is defined as the projection of $f$ on the orthonormal eigenbasis of the Laplace-Beltrami operator $\\Delta$, on a graph we can define a graph Fourier transform $\\mathcal F_G: \\mathbb R^n\\to\\mathbb R^n$ of a discrete signal $\\mathbf f\\in\\mathbb R^n$ as the projection of $\\mathbf f$ on the eigenvectors of the graph Laplacian $\\mathbf L$:\n\\begin{equation}\\label{eq:graph fourier}\n\\mathcal F_G(\\mathbf f) := \\mathbf V^\\intercal\\mathbf f = \\hat{\\mathbf f}\n\\end{equation}\nThe inverse graph Fourier transform $\\mathcal F^{-1}_G$ is thus \n\\begin{equation}\\label{eq:graph fourier inverse}\n\\mathcal F^{-1}_G(\\hat{\\mathbf f}) := \\mathbf V \\hat{\\mathbf f} = \\mathbf V\\mathbf V^\\intercal\\mathbf f = {\\mathbf f}\n\\end{equation}\nIn the continuous case, the eigenvalues of the Laplace-Beltrami operator are associated with a notion of \\textit{frequency} of the corresponding eigenfunction. In a graph we have a similar notion: define the Rayleigh quotient of a vector $\\mathbf v \\in \\mathbb R^n$ to be\n\\begin{equation}\\label{eq:Rayleigh}\n\t\\mathcal R(\\mathbf v) = \\frac{\\mathbf v^\\intercal\\mathbf L \\mathbf v}{\\mathbf v^\\intercal\\mathbf v}\n\\end{equation}\nThe well known \\cite{Strang} Courant-Fischer characterization of eigenvalues and eigenvectors of symmetric matrices (\\ref{eq:courantfisher}) can be interpreted in light of what we wrote about the interpretation of the Dirichlet energy (\\ref{eq:quadratic form}) $\\mathbf v^\\intercal \\mathbf L \\mathbf v$ as a measure of the smoothness of $\\mathbf v$. The eigenvalue $\\lambda_i$ is the measure of smoothness of the eigenvector $\\mathbf v_i$, that is the smoothest vector perpendicular to the lower-degree eigenvectors $\\mathbf v_1, ... \\mathbf v_{i-1}$.\n\\begin{equation}\\label{eq:courantfisher}\n\t\\begin{aligned} \n\t&\\lambda_1 = \\min_{\\mathbf v\\neq 0} \\mathcal R(v)\\\\\n\t&\\mathbf v_1 = \\text{argmin}_{\\norm {\\mathbf v} = 1, \\mathbf v\\neq 0} \\mathcal R(v)\\\\\n\t&\\begin{cases}\n\t\\lambda_i = \\min_{\\norm {\\mathbf v} = 1, \\mathbf v\\perp \\mathbf v_1, ..., \\mathbf v_{i-1}} \\mathcal R(v)\\\\\n\t\\mathbf v_i = \\text{arg min}_{\\norm {\\mathbf v} = 1, \\mathbf v\\perp \\mathbf v_1, ..., \\mathbf v_{i-1}}  \\mathcal R(v)\n\t\\end{cases}\n\t\\end{aligned}\t\n\\end{equation}\n\\begin{remark}\n\tIt is interesting to notice that the Dirichlet energy of a signal $\\mathbf f$ on a graph $G$ could change drastically by changing the underlying topology of $G$. In figure \\ref{fig:graph} we see two simple graphs $G=(V, E),\\ G' =(V, E')$ with the same signal $\\mathbf f$ represented as vertical red bars over the vertex set $V$. On $G$, the signal $\\mathbf f$ varies smoothly across the graph since the edges $V$ connect only those vertices with similar values of $\\mathbf f$. On $G'$, since we added edges between vertices with very different values of $\\mathbf f$, we will have that the Dirichlet energy of $\\mathbf f$ calculated on the graph $G'$ will be much higher than the one calculated on the graph $G$\n\\end{remark}\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.8\\textwidth]{figs/chapter1/graph.png}\n\t\\caption{\\label{fig:graph}Different graph topologies can drastically change the measure of smoothness of a signal $\\mathbf f$, here represented as red vertical bars on the vertices.}\n\\end{figure}\n\n\\paragraph{Convolution and filtering on graphs}\n As the plane $\\mathbb R^2$ is symmetric with respect to any translation, and the sphere $\\mathbb S^2$ is symmetric with respect to any rotation, the respective definitions of convolution are equivariant respectively to these two symmetry groups. Since there are no such global symmetries in a general graph $G$, definitions (\\ref{eq:plane convolution}), (\\ref{eq:convolution}) can not be extended naturally on graphs. However, both on $\\mathbb R^2$ and on $\\mathbb S^2$, the convolution of a signal $f$ with a kernel $k$ can be performed in the spectral domain by multiplying the transformed signal $\\hat f$ times the transformed kernel $\\hat k$: \n\\begin{equation}\\label{eq:convolution normal}\nf*k = \\mathcal F^{-1}(\\hat f \\cdot \\hat k)\n\\end{equation}\nIn a similar way we can define a notion of convolution also in the graph spectral domain. We use the following definition \\cite{Vandergheynst} of the convolution of a signal $\\mathbf f$ times a kernel $\\mathbf K$:\n\\begin{equation}\\label{eq:graph convolution}\n\t\\Omega_\\mathbf K\\mathbf f = \\mathcal{F}^{-1}_G(\\mathbf K \\hat {\\mathbf f})= \\mathbf V\\mathbf K  \\mathbf V^\\intercal {\\mathbf f}\n\\end{equation}\nwhere $\\mathbf K$ is a \\textit{diagonal} \\textit{matrix} $K_{ii} = k_i$. Graphs convolutions are different from the ones we are used to define in Euclidean domains, since the graph kernels $\\mathbf K$ are diagonal matrices that can not be thought as the Fourier transform of a corresponding kernel defined in the spatial (vertex) domain. The diagonal elements $k_{i}$ can be thought as functions of the corresponding eigenvalues \n$$\nk_{i}= k(\\lambda_i)\n$$\nthus providing an intuitive frequency interpretation of the kernel $\\mathbf K$. In this way the convolution can be seen as a \\textit{filtering} operation: for example, a kernel $k(\\lambda_i) = \\exp (-\\lambda_i)$ will be the kernel of a low-pass filter since it will cut the high frequencies.\n\n\\subsection{The Equivariance error for graph convolutions}\nTake a sampling scheme $V=\\{v_i\\in\\mathbb S^2, i=0, ..., n\\}$ of the sphere, a weighted undirected graph $G(V, E, \\mathbf W)$, a signal $f: \\mathbb S^2\\to\\mathbb R$ and its sampled representation $\\mathbf f:\\ f_i=f(v_i)$. Suppose that there exists a sampling operator $T_V: L^2(\\mathbb S^2) \\supset F\\to \\mathbb R^n,\\  T_V(f) = \\mathbf f$ defined on a suitable subspace $F$ of $L^2(\\mathbb S^2)$ such that it is invertible, i.e., we can unambiguously reconstruct the function $f\\in F$ from its sampled values $\\mathbf f$. The existence of such subspace depends on the sampling scheme $V$, and its characterization is a common problem in signal processing \\cite{Driscoll:1994:CFT:184069.184073}. Recall the definition (\\ref{eq:rotation operator}) of the rotation operator $\\Lambda(g), g\\in SO(3)$. \n\nWe now want to understand how to set the edges and the weights of $G$ such that\n\\begin{equation}\\label{eq:equivariance}\nT \\Lambda(g) T^{-1} \\Omega_k T f = \\Omega_k T \\Lambda(g) f\n\\end{equation}\ni.e., the graph convolution $\\Omega_k$ and any rotation $\\Lambda(g)$ commute.\n\nVerifying equation (\\ref{eq:equivariance}) is really hard in practice, due to the fact that for almost all samplings schemes $V$ it is not known if there exists a space $F$ in which $T$ is invertible. A special case is the \\textit{equiangular sampling} scheme described in section \\ref{sec:Chapter3: Heat Kernel Graph Laplacian on the Equiangular Sampling} where the sampling theorem \\ref{theo:equiangular sampling theorem} holds \\cite{Driscoll:1994:CFT:184069.184073}. With all the other sampling schemes, there are no sampling theorems available, but there are implementations of discrete SHT to reconstruct a sampled signal $\\mathbf f$, thus providing a way to approximate $T^{-1}$. Thanks to this we are able, for a given sampling, a given function $f$, a given rotation $g$, and a given kernel $k$, to compute the \\textit{normalized equivariance error} \n\\begin{equation}\\label{eq:equivariance error}\nE_{G}(f, g) = \\left(\\frac{ \\norm {T \\Lambda(g) T^{-1} \\Omega_k Tf - \\Omega_k T \\Lambda(g) f}_{L^2(\\mathbb R^2)}}{\\norm {Tf}_{L^2(\\mathbb R^2)}}\\right)^2\n\\end{equation}\nwhere $T^{-1}$ is substituted with a discrete SHT in case $T$ is not invertible.\nA measure of how equivariant a graph is with respect to rotations will then be given by the \\textit{mean equivariance error}\n\\begin{equation}\\label{eq:mean equivariance error}\n\\overline E_G = \\mathbb E_{f, g}\\ \tE_G(f, g) \n\\end{equation}\nIn practice the expected value is obtained by averaging over a finite number of random functions and random rotations. The mean equivariance error $\\overline E_G$ gives us an indication of how close the graph $G$ is from being equivariant to rotations. Now we state an intuitive concept that explains how to construct rotation invariant graphs, i.e. graphs such that $\\overline{E_G}$ is small.\n\\begin{snugshade*}\n\tThe mean equivariance error $\\overline{E_G}$ will be small if the scalar product $\\mathbf f^\\intercal \\mathbf v_{i(\\ell, m)}$ well approximates $\\hat {f}(\\ell,m)$ i.e., the $L^2$ scalar product of the continuous signal \\\\\n\t$\\hat {f}(\\ell,m)= \\int_{\\eta \\in \\mathbb S^2}f(\\eta)Y_\\ell^m(\\eta)d\\mu(\\eta)$.\n\t\n\t\\textit{If $V$ is an equal area sampling scheme}, i.e. the area around each pixel $v_i$ is the same, $\\overline{E_G}$ will be small if the graph Laplacian $\\mathbf L$ is such that its eigenvectors $\\mathbf v_i$ well approximate the eigenfunctions of the Laplace-Beltrami operator $\\Delta_{\\mathbb S^2}$ evaluated in the points of the sampling scheme, i.e., \n\t$$\n\t\\mathbf v_{i(\\ell, m)} \\approxeq Y_\\ell^m(x_i)\n\t$$\n\\end{snugshade*}\n\nIn this way we framed the problem of constructing a rotation invariant graph with the more general problem of coming up with a matrix $\\mathbf L$ with some specific spectral properties. Graphs are only one of many ways of coming up with such matrix $\\mathbf L$, and many other methods have been already studied in the literature. In the next Chapter we present a brief overview of some of these methods providing the general context in which graph filtering can be framed.\n", "meta": {"hexsha": "86aba1c8a3d9789cdb6b0f43e0dbf72bf02f13c2", "size": 30355, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PDF/1.LiteratureReview.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.LiteratureReview.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.LiteratureReview.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": 137.3529411765, "max_line_length": 1861, "alphanum_fraction": 0.7405699226, "num_tokens": 8506, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9511422199928904, "lm_q2_score": 0.8031738010682209, "lm_q1q2_score": 0.7639325121881557}}
{"text": "\nThe dirichlet module contains routines for using Beta, Gamma, and\nDirichlet densities. In particular, it implements mixture Dirichlet\npriors, which are useful in a variety of parameter estimation tasks.\n\nThe Dirichlet PDF is:\n\n\\begin{equation}\n P(\\vec{p}) = \\frac{\\Gamma{\\sum_i \\alpha_i}}{\\prod_i \\Gamma(\\alpha_i)} \\prod_i p_i^{\\alpha_i-1}\n\\end{equation}\n\n\n\\subsection{The dirichlet API}\n\nThe module implements one object, \\ccode{ESL\\_MIXDCHLET}, which holds\na mixture Dirichlet prior. \n\nThe API consists of the following functions:\n\n\\vspace{1em}\n\\begin{tabular}{ll}\\hline\n   \\multicolumn{2}{c}{\\textbf{mixture Dirichlet priors}}\\\\\n\\ccode{esl\\_mixdchlet\\_Create()}            & Allocates a new mixture Dirichlet.\\\\\n\\ccode{esl\\_mixdchlet\\_Destroy()}           & Free's a mixture Dirichlet.\\\\\n\\ccode{esl\\_mixdchlet\\_MPParameters()}      & Mean posterior probability parameter estimation.\\\\\n   \\multicolumn{2}{c}{\\textbf{Dirichlet, Gamma density routines}}\\\\\n\\ccode{esl\\_dirichlet\\_LogProbData()}       & $\\log P( \\mbox{count vector} \\mid \\mbox{mixture Dirichlet}$.\\\\\n\\ccode{esl\\_dirichlet\\_LogProbProbs()}      & $\\log P( \\mbox{prob vector} \\mid \\mbox{mixture Dirichlet}$.\\\\\n\\ccode{esl\\_dirichlet\\_LogGamma()}          & $\\log \\Gamma(x)$.\\\\\n   \\multicolumn{2}{c}{\\textbf{Sampling code}}\\\\\n\\ccode{esl\\_dirichlet\\_\\{D,F\\}Sample()}            & Sample a probability vector from a Dirichlet.\\\\\n\\ccode{esl\\_dirichlet\\_\\{D,F\\}SampleUniform()}     & Sample a probability vector uniformly.\\\\\n\\ccode{esl\\_dirichlet\\_SampleBeta()}        & Sample from Beta$(\\theta_1, \\theta_2$).\\\\\n   \\multicolumn{2}{c}{\\textbf{Input from file}}\\\\\n\\ccode{esl\\_mixdchlet\\_Read()}              & Input of a mixture Dirichlet from a file.\\\\ \\hline\n\\end{tabular}\n\n\\subsection{Example of using the dirichlet API}\n\nAn example that reads a mixture Dirichlet prior from a file, samples a\nprobability vector from it, samples a count vector from the\nprobability vector, then infers which mixture component generated the\ndata and uses mean posterior estimation to reestimate the probability\nvector from the counts:\n\n\\input{cexcerpts/dirichlet_example}\n\n\\subsection{Accessing information in the ESL\\_MIXDCHLET object}\n\nYou may need to access the information in the \\ccode{ESL\\_MIXDCHLET}\nobject. The data fields inside this structure are:\n\n\\input{cexcerpts/dirichlet_mixdchlet}\n\n\n\n\n", "meta": {"hexsha": "efb7d3e7088802db5c388c1670e870d057be9ede", "size": 2343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hmmer-3.3/easel/esl_dirichlet.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_dirichlet.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_dirichlet.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": 40.3965517241, "max_line_length": 108, "alphanum_fraction": 0.7272727273, "num_tokens": 724, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355092, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7637986859662479}}
{"text": "\\documentclass[../Notes/main.tex]{subfiles}\n\n\\begin{document}\n\\section{Dynamic Programming}\n\n\\subsection{Knapsack}\nAssuming \\(w>0\\), \\(i\\geq0\\) and \\(w\\geq w_i\\)\n\\begin{align*}\n    DP[w][i] & = \\max(V_i+DP[w-w_i][i-1],DP[w][i-1])\n\\end{align*}\nBase cases:\n\\begin{align*}\n    DP[w][i] & =\\begin{cases}\n        DP[w][i] & \\text{if }w<w_i                \\\\\n        0        & \\text{if }i<0\\text{ or }w\\leq0\n    \\end{cases}\n\\end{align*}\n\n\\subsection{Matrix Chain Multiplication}\nGiven a monoid \\(M\\) with operation \\(\\cdot\\), a cost function \\(c:M^2\\rightarrow \\mathbb{R}_{>0}\\), and a finite sequence of elements of \\(M\\), \\(a_1,\\dots,a_n\\), we can calculate the minimum cost of operating the elements (i.e. where to put the parenthesis on \\(a_1\\cdot\\ldots\\cdot a_n\\) such that the total cost is minimized (the cost function is used when every operation is done)) with the following DP:\n\\begin{equation*}\n    DP[i][j]=\\min_{i\\leq k<j}(c(A_{i,k},A_{k+1,j})+DP[i][k]+DP[k+1][j])\n\\end{equation*}\nWhere \\(1\\leq i\\leq j\\leq n\\) and \\(A_{i,j}=a_i\\cdot\\ldots\\cdot a_j\\)\n%\\lstinputlisting[firstline=3]{Matrix_Chain_Multiplication/MCM.cpp}\n\n\\subsection{Longest Increasing Subsequence}\nGiven a sequence \\(a_1,\\ldots,a_n\\), we can find the LIS using the following method, using an auxiliary array \\(L\\) of size \\(n\\) and a counter \\(currL\\), set \\(L[0]=a_1\\) and \\(currL=1\\) then, in the sequence order, for each element \\(a_i\\) search for the lower bound \\(L[j]\\) of \\(a_i\\) between \\(L[0]\\) and \\(L[currL-1]\\), if \\(j=currL-1\\) then set \\(L[currL]=a_i\\) and increase \\(curr_l\\) by one, in the other case set \\(L[j]=a_i\\).\n%\\lstinputlisting[firstline=3]{LIS/LIS.cpp}\n\\end{document}", "meta": {"hexsha": "cd87feb8c811af014ae447ae5b1170378fbb757d", "size": 1667, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "dp/dp.tex", "max_stars_repo_name": "N9199/apuntes_icpc", "max_stars_repo_head_hexsha": "198571d3d516d09e5418ab51893b400bceb01acd", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-03-06T20:32:33.000Z", "max_stars_repo_stars_event_max_datetime": "2020-03-06T20:32:33.000Z", "max_issues_repo_path": "dp/dp.tex", "max_issues_repo_name": "N9199/apuntes_icpc", "max_issues_repo_head_hexsha": "198571d3d516d09e5418ab51893b400bceb01acd", "max_issues_repo_licenses": ["MIT"], "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/dp.tex", "max_forks_repo_name": "N9199/apuntes_icpc", "max_forks_repo_head_hexsha": "198571d3d516d09e5418ab51893b400bceb01acd", "max_forks_repo_licenses": ["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.5666666667, "max_line_length": 436, "alphanum_fraction": 0.6556688662, "num_tokens": 579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8244619285331332, "lm_q1q2_score": 0.7637021598855867}}
{"text": "The first full-blown logic program that we see is, quite fittingly\\footnote{Boolean logic is an interpretation of logic itself, which fits snugly within our own implementation of an interpretation of logic. Recursion can be quite fun, as we will see in one of the last chapters.}, a program for the definition and evaluation of boolean expressions.\n\n\\paragraph{Symbols}\nThe basic symbols that we need represents the boolean values of \\texttt{TRUE} and \\texttt{FALSE}, and they both have type \\texttt{Value}:\n\n\\begin{lstlisting}\nData [] \"TRUE\" [] Priority 10000 Type Value\nData [] \"FALSE\" [] Priority 10000 Type Value\n\\end{lstlisting}\n\nBoolean expressions, all of type \\texttt{Expr}, are: \n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item traditional negation (the unary operator \\texttt{!} following the tradition of C-like languages);\n\\item disjunction of boolean expressions (commonly known as ``or'');\n\\item conjunction of boolean expressions (commonly known as ``and'').\n\\end{inparaenum}\n\n\\begin{lstlisting}\nData [] \"!\" [Expr] Priority 30 Type Expr\nData [Expr] \"|\" [Expr] Priority 10 Type Expr\nData [Expr] \"&\" [Expr] Priority 20 Type Expr\n\\end{lstlisting}\n\nOf course we want to be able to use values as expressions, otherwise writing \\texttt{TRUE \\& TRUE} would not be allowed. For this reason we specify that anything that has type \\texttt{Value} can also be used where a type \\texttt{Expr} is expected:\n\n\\begin{lstlisting}\nValue is Expr\n\\end{lstlisting}\n\nIn order to compute the \\texttt{Value} of an \\texttt{Expr}, we define the \\texttt{eval} function.\n\n\\begin{lstlisting}\nFunc [] \"eval\" [Expr] Priority 1 Type Expr => Value\n\\end{lstlisting}\n\n\\paragraph{Rules}\nThe only rules that we can define involve the \\texttt{eval} function, which is the only function that we have defined. The first two rules  trivially specify that when we reach the evaluation of \\texttt{TRUE} or \\texttt{FALSE}, then we do not need to further proceed:\n\n\\begin{lstlisting}\n------------------ (G0)\neval TRUE => TRUE\n\n-------------------- (G1)\neval FALSE => FALSE\n\\end{lstlisting}\n\nIf we reach the evaluation of the negation of some expression \\texttt{a}, then we will evaluate \\texttt{a}. If the evaluation of \\texttt{a} returns \\texttt{TRUE}, then the evaluation of the negation of \\texttt{a} returns \\texttt{FALSE}:\n\n\\begin{lstlisting}\neval a => TRUE\n----------------- (NEG0)\neval !a => FALSE\n\\end{lstlisting}\n\nSimilarly, if we reach the evaluation of the negation of some expression \\texttt{a}, and evaluation of \\texttt{a} returns \\texttt{FALSE}, then the evaluation of the negation of \\texttt{a} returns \\texttt{TRUE}:\n\n\\begin{lstlisting}\neval a => FALSE\n---------------- (NEG1)\neval !a => TRUE\n\\end{lstlisting}\n\nWhen evaluating the disjunction of two expressions \\texttt{a} and \\texttt{b}, we try to evaluate \\texttt{a}:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item if \\texttt{a} evaluates to \\texttt{TRUE}, then there is no need to further evaluate \\texttt{b} and we can directly return \\texttt{TRUE};\n\\item if \\texttt{a} evaluates to \\texttt{FALSE}, then we evaluate \\texttt{b} and return whatever result of its evaluation.\n\\end{inparaenum}\n\n\\begin{lstlisting}\neval a => TRUE\n------------------- (OR0)\neval (a|b) => TRUE\n\neval a => FALSE\neval b => y\n----------------- (OR1)\neval (a|b) => y\n\\end{lstlisting}\n\nWhen evaluating the conjunction of two expressions \\texttt{a} and \\texttt{b}, we try to evaluate \\texttt{a}:\n\\begin{inparaenum}[\\itshape i\\upshape)]\n\\item if \\texttt{a} evaluates to \\texttt{FALSE}, then there is no need to further evaluate \\texttt{b} and we can directly return \\texttt{FALSE};\n\\item if \\texttt{a} evaluates to \\texttt{TRUE}, then we evaluate \\texttt{b} and return whatever result of its evaluation.\n\\end{inparaenum}\n\n\\begin{lstlisting}\neval a => FALSE\n-------------------- (AND0)\neval (a&b) => FALSE\n\neval a => TRUE\neval b => y\n---------------- (AND1)\neval (a&b) => y\n\\end{lstlisting}\n\n\n\\paragraph{Example run}\nConsider now the evaluation of an expression such as \\texttt{eval (FALSE | !(TRUE \\& FALSE))}. We begin with\n\n\\begin{lstlisting}\n------------------------------------\neval (FALSE | !(TRUE & FALSE)) => ?\n\\end{lstlisting}\n\nThis expression is an instance of \\texttt{eval (a|b)}, therefore we investigate the first premise according to rule \\texttt{OR0} (notice the question marks at the end of some lines, which mean that we are verifying that this is indeed the case):\n\n\\begin{lstlisting}\neval FALSE => TRUE?\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE?\n\\end{lstlisting}\n\nSince \\texttt{eval FALSE} does never return \\texttt{TRUE}, this branch of execution is interrupted. We try the alternate rule \\texttt{OR1} for \\texttt{eval (a|b)}, therefore we investigate two premises:\n\n\\begin{lstlisting}\neval FALSE => FALSE?\neval !(TRUE & FALSE) => y\n------------------------------------\neval (FALSE | !(TRUE & FALSE)) => y\n\\end{lstlisting}\n\nThe first premise, \\texttt{eval FALSE => FALSE}, is trivially verified by the rule \\texttt{G1}. We may thus delete it from the tree of derivation:\n\n\\begin{lstlisting}\neval !(TRUE & FALSE) => y\n------------------------------------\neval (FALSE | !(TRUE & FALSE)) => y\n\\end{lstlisting}\n\nThe second premise is itself complex, so we need to find its result and then assign it to \\texttt{y}. We begin with rule \\texttt{NEG1}\\footnote{Note that Meta-Casanova would actually first try \\texttt{NEG0}, which fails, but for reasons of space we skip that lengthy and fruitless derivation.}, which expects the input to evaluate to \\texttt{FALSE}. In this case, since we know from \\texttt{NEG1} that \\texttt{eval !(TRUE \\& FALSE)} would return \\texttt{TRUE}, we substitute \\texttt{y} with \\texttt{TRUE} speculatively:\n\n\\begin{lstlisting}\neval (TRUE & FALSE) => FALSE?\n-----------------------------\neval !(TRUE & FALSE) => TRUE\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\nWe now need to evaluate premise \\texttt{eval (TRUE \\& FALSE)}, and we do so with application of rule \\texttt{AND1}\\footnote{Again, \\texttt{AND1} is chosen ad-hoc to go directly to the result.}. Rule \\texttt{AND1} evaluates the second term and returns its result:\n\n\\begin{lstlisting}\neval TRUE => TRUE?\neval FALSE => y\n------------------------------\neval (TRUE & FALSE) => y\ny == FALSE?\n-----------------------------\neval !(TRUE & FALSE) => TRUE\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\nFortunately, \\texttt{eval TRUE => TRUE} is trivially verified by rule \\texttt{G0}; we can safely remove it from our tree of derivation:\n\n\\begin{lstlisting}\neval FALSE => y\n------------------------------\neval (TRUE & FALSE) => y\ny == FALSE?\n-----------------------------\neval !(TRUE & FALSE) => TRUE\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\n\\texttt{eval FALSE} returns \\texttt{FALSE} as an immediate consequence of rule \\texttt{G1}. Therefore, we can replace \\texttt{y} with \\texttt{FALSE}:\n\n\\begin{lstlisting}\neval FALSE => FALSE\n------------------------------\neval (TRUE & FALSE) => FALSE\nFALSE == FALSE?\n-----------------------------\neval !(TRUE & FALSE) => TRUE\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\nThe two upper premises are now completely evaluated, so we can safely remove them from the derivation tree:\n\n\\begin{lstlisting}\nFALSE == FALSE?\n-----------------------------\neval !(TRUE & FALSE) => TRUE\n---------------------------------------\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\nWe now need to verify that the result of the last evaluation of \\texttt{AND1} is compatible with the evaluation of \\texttt{NEG1}, that is \\texttt{FALSE == FALSE}. This is trivially the case, and therefore we can discharg the last two premises:\n\n\\begin{lstlisting}\neval (FALSE | !(TRUE & FALSE)) => TRUE\n\\end{lstlisting}\n\nSince we have no more premises, we can safely conclude that indeed the result of the evaluation of the original proposition \\texttt{eval (FALSE | !(TRUE \\& FALSE))} yields \\texttt{TRUE}, which is also what we would expect from intuition.\n\n", "meta": {"hexsha": "35aeee64e60b18612cbf1ab45314325859a7f44b", "size": 8118, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Course materials/Dictaat/tex/Examples/boolean_expressions.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/boolean_expressions.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/boolean_expressions.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.7939698492, "max_line_length": 519, "alphanum_fraction": 0.6638334565, "num_tokens": 2117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8670357615200474, "lm_q1q2_score": 0.7636825733881872}}
{"text": "\\section{Directional Derivatives}\\label{sec:DirectionalDerivatives}\n\nWe still have not answered one of our first questions about the\nsteepness of a surface: starting at a\npoint on a surface given by $f(x,y)$, and walking in a particular\ndirection, how steep is the surface? We are now ready to answer the\nquestion.\n\nWe already know roughly what has to be done: as shown in\nFigure~\\ref{fig:parabolic bowl cross-section}, we extend a line in\nthe $x$-$y$ plane to a vertical plane, and we then compute the slope\nof the curve that is the cross-section of the surface in that\nplane. The major stumbling block is that what appears in this plane to\nbe the horizontal axis, namely the line in the $x$-$y$ plane, is not\nan actual axis---we know nothing about the ``units'' along the\naxis. Our goal is to make this line into a $t$ axis; then we need\nformulas to write $x$ and $y$ in terms of this new variable $t$; then\nwe can write $z$ in terms of $t$ since we know $z$ in terms of $x$ and\n$y$; and finally we can simply take the derivative.\n\nSo we need to somehow ``mark off'' units on the line, and we need a\nconvenient way to refer to the line in calculations. It turns out that\nwe can accomplish both by using the vector form of a line. Suppose\nthat $\\vect{u}$ is a unit vector $\\langle u_1,u_2\\rangle$ in the\ndirection of interest. A vector equation for the line through\n$(x_0,y_0)$ in this direction is $\\vect{v}(t)=\\langle\nu_1t+x_0,u_2t+y_0\\rangle$. The height of the surface above the point \n$(u_1t+x_0,u_2t+y_0)$ is $g(t)=f(u_1t+x_0,u_2t+y_0)$. Because $\\vect{u}$\nis a unit vector, the value of $t$ is precisely the distance along the\nline from $(x_0,y_0)$ to $(u_1t+x_0,u_2t+y_0)$; this means that the\nline is effectively a $t$ axis, with origin at the point $(x_0,y_0)$,\nso the slope we seek is \n\\begin{align*}\ng'(0)&=\\langle f_x(x_0,y_0),f_y(x_0,y_0)\\rangle\\cdot\n\\langle u_1,u_2\\rangle\t\\\\\n&=\\langle f_x,f_y\\rangle\\cdot\\vect{u}\t\\\\\n&=\\nabla f\\cdot \\vect{u}\t\\\\\n\\end{align*}\nHere we have used the chain rule and the derivatives\n${d\\over dt}(u_1t+x_0)=u_1$ and ${d\\over dt}(u_2t+y_0)=u_2$.\nThe vector $\\langle f_x,f_y\\rangle$ is very useful, so it has its own\nsymbol, $\\nabla f$, pronounced ``del f''\\index{del ($\\nabla$)}; \nit is also called the\n\\dfont{gradient} of $f$.\\index{gradient}\n\n\\begin{example}{Slope}{SlopeEllipticParaboloid}\nFind the slope of $z=x^2+y^2$ at $(1,2)$ in the direction of the\nvector $\\langle 3,4\\rangle$.\n\\end{example}\n\\begin{solution}\nWe first compute the gradient at $(1,2)$:\n$\\nabla f=\\langle 2x,2y\\rangle$, which is $\\langle 2,4\\rangle$ at\n$(1,2)$. A unit vector in the desired direction is $\\langle\n3/5,4/5\\rangle$, and the desired slope is then\n$\\langle 2,4\\rangle\\cdot\\langle 3/5,4/5\\rangle=6/5+16/5=22/5$.\n\\end{solution}\n\n\\begin{example}{Tangent Vector}{TangentVectorEllipticParaboloid}\nFind a tangent vector to $z=x^2+y^2$ at $(1,2)$ in the direction of the\nvector $\\langle 3,4\\rangle$ and show that it is parallel to the\ntangent plane at that point.\n\\end{example}\n\\begin{solution}\nSince $\\langle 3/5,4/5\\rangle$ is a unit vector in the desired\ndirection, we can easily expand it to a tangent vector simply by\nadding the third coordinate computed in the previous example: $\\langle\n3/5,4/5,22/5\\rangle$.  To see that this vector is parallel to the\ntangent plane, we can compute its dot product with a normal to the\nplane. We know that a normal to the tangent plane is\n$$\\langle f_x(1,2),f_y(1,2),-1\\rangle = \\langle 2,4,-1\\rangle,$$\nand the dot product is $\\langle 2,4,-1\\rangle\\cdot\\langle\n3/5,4/5,22/5\\rangle=6/5+16/5-22/5=0$, so the two vectors are\nperpendicular. (Note that the vector normal to the surface, namely \n$\\langle f_x,f_y,-1\\rangle$, is simply the gradient with a $-1$ tacked\non as the third component.)\n\\end{solution}\n\nThe slope of a surface given by $z=f(x,y)$ in the direction of a\n(two-dimensional) vector $\\vect{u}$ is called the \\dfont{directional\n  derivative}\\index{directional derivative} of $f$, written $D_{\\vect{u}}f$.\nThe directional derivative immediately provides us with some\nadditional information. We know that \n$$D_{\\vect{u}}f=\\nabla f\\cdot \\vect{u}=|\\nabla f||\\vect{u}|\\cos\\theta=\n|\\nabla f|\\cos\\theta$$\nif $\\vect{u}$ is a unit vector; $\\theta$ is the angle between $\\nabla f$\nand $\\vect{u}$. This tells us immediately that the largest value of\n$D_{\\vect{u}}f$ occurs when $\\cos\\theta=1$, namely, when $\\theta=0$, so \n$\\nabla f$ is parallel to $\\vect{u}$. In other words, the gradient\n$\\nabla f$ points in the direction of steepest ascent of the surface, and \n$|\\nabla f|$ is the slope in that direction. Likewise, the smallest value of\n$D_{\\vect{u}}f$ occurs when $\\cos\\theta=-1$, namely, when $\\theta=\\pi$, so \n$\\nabla f$ is anti-parallel to $\\vect{u}$. In other words, \n$-\\nabla f$ points in the direction of steepest descent of the surface, and \n$-|\\nabla f|$ is the slope in that direction.\n\n\\begin{example}{Direction of Steepest Ascent and Descent}{AscentDescentEllipticParaboloid}\nInvestigate the direction of steepest ascent and descent for\n$z=x^2+y^2$.\n\\end{example}\n\\begin{solution}\nThe gradient is $\\langle 2x,2y\\rangle=2\\langle x,y\\rangle$; this is a\nvector parallel to the vector $\\langle x,y\\rangle$, so the direction\nof steepest ascent is directly away from the origin, starting at the\npoint $(x,y)$. The direction of steepest descent is thus directly\ntoward the origin from $(x,y)$. Note that at $(0,0)$ the gradient\nvector is $\\langle 0,0\\rangle$, which has no direction, and it is\nclear from the plot of this surface that there is a minimum point at\nthe origin, and tangent vectors in all directions are parallel to the\n$x$-$y$ plane.\n\\end{solution}\n\nIf $\\nabla f$ is perpendicular to $\\vect{u}$, \n$D_{\\vect{u}}f=|\\nabla f|\\cos(\\pi/2)=0$, since $\\cos(\\pi/2)=0$.\nThis means that in either of the two directions perpendicular to\n$\\nabla f$, the slope of the surface is 0; this implies that a vector in\neither of these directions is tangent to the level curve at that\npoint. Starting with $\\nabla f=\\langle f_x,f_y\\rangle$, it is easy to\nfind a vector perpendicular to it: either $\\langle f_y,-f_x\\rangle$ or \n$\\langle -f_y,f_x\\rangle$ will work.\n\nIf $f(x,y,z)$ is a function of three variables, all the calculations\nproceed in essentially the same way. The rate at which $f$ changes in\na particular direction is $\\nabla f\\cdot\\vect{u}$, where now\n$\\nabla f=\\langle f_x,f_y,f_z\\rangle$ and $\\vect{u}=\\langle\nu_1,u_2,u_3\\rangle$ is a unit vector. Again $\\nabla f$ points in the\ndirection of maximum rate of increase, $-\\nabla f$ points in the\ndirection of maximum rate of decrease, and any vector perpendicular to\n$\\nabla f$ is tangent to the level surface $f(x,y,z)=k$ at the point\nin question. Of course there are no longer just two such vectors; the\nvectors perpendicular to $\\nabla f$ describe the tangent plane to the\nlevel surface, or in other words $\\nabla f$ is a normal to the tangent\nplane. \n\n\\begin{example}{Gradient}{GradientTemperature}\nSuppose the temperature at a point in space is given by\n$T(x,y,z)=T_0/(1+x^2+y^2+z^2)$; at the origin the temperature in\nKelvin is\n$T_0>0$, and it decreases in every direction from there. It might be,\nfor example, that there is a source of heat at the origin, and as we\nget farther from the source, the temperature decreases.\nThe gradient is\n\\begin{align*}\n\\nabla T&=\\langle {-2T_0x\\over (1+x^2+y^2+z^2)^2}+\n{-2T_0x\\over (1+x^2+y^2+z^2)^2}+{-2T_0x\\over (1+x^2+y^2+z^2)^2}\\rangle\t\\\\\n&={-2T_0\\over (1+x^2+y^2+z^2)^2}\\langle x,y,z\\rangle.\t\\\\\n\\end{align*}\nThe gradient points directly at the origin from the point\n$(x,y,z)$---by moving directly toward the heat source, we increase the\ntemperature as quickly as possible.\n\\end{example}\n\n\\begin{example}{Tangent Plane}{TangentPlaneParallel}\nFind the points on the surface defined by $x^2+2y^2+3z^2=1$\nwhere the tangent plane  is parallel to the plane defined by\n$3x-y+3z=1$.\n\\end{example}\n\\begin{solution}\nTwo planes are parallel if their normals are parallel or\nanti-parallel, so we want to find the points on the surface with\nnormal parallel or anti-parallel to $\\langle 3,-1,3\\rangle$.\nLet $f=x^2+2y^2+3z^2$; the gradient of $f$ is normal to the level\nsurface at every point, so we are looking for a gradient parallel \nor anti-parallel to\n$\\langle 3,-1,3\\rangle$. The gradient is $\\langle 2x,4y,6z\\rangle$; if\nit is parallel or anti-parallel to $\\langle 3,-1,3\\rangle$, then\n$$\\langle 2x,4y,6z\\rangle=k\\langle 3,-1,3\\rangle$$\nfor some $k$. This means we need a solution to the equations\n$$2x=3k\\qquad 4y=-k\\qquad 6z=3k$$\nbut this is three equations in four unknowns---we need another\nequation. What we haven't used so far is that the points we seek are\non the surface $x^2+2y^2+3z^2=1$; this is the fourth equation. If we\nsolve the first three equations for $x$, $y$, and $z$ and substitute\ninto the fourth equation we get\n\\begin{align*}\n1&=\\left({3k\\over2}\\right)^2+2\\left({-k\\over4}\\right)^2+3\\left({3k\\over6}\\right)^2\t\\\\\n&=\\left({9\\over4}+{2\\over16}+{3\\over4}\\right)k^2\t\\\\\n&={25\\over8}k^2\t\\\\\n\\end{align*}\nso $\\ds k=\\pm{2\\sqrt2\\over 5}$. The desired points are\n$\\ds\\left({3\\sqrt2\\over5},-{\\sqrt2\\over10},{\\sqrt2\\over 5}\\right)$ \nand $\\ds\\left(-{3\\sqrt2\\over5},{\\sqrt2\\over10},-{\\sqrt2\\over\n  5}\\right)$.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:DirectionalDerivatives}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind $D_{\\vect{u}} f$ for \n$\\ds f=x^2+xy+y^2$ in the direction of $\\vect{u}=\\langle 2,1\\rangle$ \nat the point $(1,1)$.\n\\begin{sol}\n$9\\sqrt5/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $D_{\\vect{u}} f$ for \n$\\ds f=\\sin(xy)$ in the direction of $\\vect{u}=\\langle -1,1\\rangle$ \nat the point $(3,1)$.\n\\begin{sol}\n$\\sqrt2\\cos3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind $D_{\\vect{u}} f$ for \n$\\ds f=e^x\\cos(y)$ in the direction 30 degrees from the positive $x$ axis\nat the point $(1,\\pi/4)$.\n\\begin{sol}\n$e\\sqrt2(\\sqrt3-1)/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe temperature of a thin plate in the $x$-$y$ plane is \n$\\ds T=x^2+y^2$. How fast does temperature change at the point $(1,5)$\nmoving in a direction 30 degrees from the positive $x$ axis?\n\\begin{sol}\n$\\sqrt3+5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose the density of a thin plate at $(x,y)$ is\n$\\ds 1/\\sqrt{x^2+y^2+1}$. Find the rate of change of the density at\n$(2,1)$ in a direction $\\pi/3$ radians from the positive $x$ axis.\n\\begin{sol}\n$-\\sqrt6(2+\\sqrt3)/72$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose the electric potential at $(x,y)$ is\n$\\ds\\ln\\sqrt{x^2+y^2}$. Find the rate of change of the potential at\n$(3,4)$ toward the origin and also in a direction at a right angle to\nthe direction toward the origin.\n\\begin{sol}\n$-1/5$, $0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA plane perpendicular to the $x$-$y$ plane contains the\npoint $(2,1,8)$ on the paraboloid $z=x^2+4y^2$. The cross-section of\nthe paraboloid created by this plane has slope 0 at this point. Find\nan equation of the plane.\n\\begin{sol}\n$4(x-2)+8(y-1)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nA plane perpendicular to the $x$-$y$ plane contains the\npoint $(3,2,2)$ on the paraboloid $36z=4x^2+9y^2$. The cross-section\nof the paraboloid created by this plane has slope 0 at this point.\nFind an equation of the plane.\n\\begin{sol}\n$2(x-3)+3(y-2)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose the temperature at $(x,y,z)$ is given by \n$\\ds T=xy+\\sin(yz)$. In what direction should you go from the point \n$(1,1,1)$ to decrease the temperature as quickly as possible? What is\nthe rate of change of temperature in this direction?\n\\begin{sol}\n$\\langle -1,-1-\\cos1,-\\cos1\\rangle$, $-\\sqrt{2+2\\cos1+2\\cos^21}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose the temperature at $(x,y,z)$ is given by \n$\\ds T=xyz$. In what direction can you go from the point \n$(1,1,1)$ to maintain the same temperature?\n\\begin{sol}\nAny direction perpendicular to $\\nabla T=\\langle\n1,1,1\\rangle$,\nfor example, $\\langle -1,1,0\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane tangent to \n$\\ds x^2-3y^2+z^2=7$ at $(1,1,3)$.\n\\begin{sol}\n$2(x-1)-6(y-1)+6(z-3)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the plane tangent to \n$\\ds xyz=6$ at $(1,2,3)$.\n\\begin{sol}\n$6(x-1)+3(y-2)+2(z-3)=0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the line normal to \n$\\ds x^2+2y^2+4z^2=26 $ at $(2,-3,-1)$.\n\\begin{sol}\n$\\langle 2+4t,-3-12t,-1-8t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the line normal to \n$\\ds x^2+y^2+9z^2=56$ at $(4,2,-2)$.\n\\begin{sol}\n$\\langle 4+8t,2+4t,-2-36t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind an equation for the line normal to \n$\\ds x^2+5y^2-z^2=0$ at $(4,2,6)$.\n\\begin{sol}\n$\\langle 4+8t,2+20t,6-12t\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the directions in which the directional derivative of\n$f(x,y)=x^2+\\sin(xy)$ at the point $(1,0)$ has the value 1.\n\\begin{sol}\n$\\langle 0,1\\rangle$, $\\langle 4/5,-3/5\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nShow that the curve \n$\\vect{r}(t) = \\langle\\ln(t),t\\ln(t),t\\rangle$\nis tangent to the surface $xz^2-yz+\\cos(xy) = 1$ at the point\n$(0,0,1)$.\n\\end{ex}\n\n\\begin{ex}\nA bug is crawling on the surface of a hot plate, the\ntemperature of which at the point $x$ units to the right of the lower\nleft corner and $y$ units up from the lower left corner is given by\n$T(x,y)=100-x^2-3y^3$.\n\n\\begin{enumerate}\n\t\\item If the bug is at the point $(2,1)$, in what direction should it\n\t  move to cool off the fastest?  How fast will the temperature drop in\n\t  this direction?\n\t\\item If the bug is at the point $(1,3)$, in what direction should it\n\t  move in order to maintain its temperature?\n\\end{enumerate}\n\\begin{sol}\n\\begin{enumerate}\n\t\\item\t$\\langle 4,9\\rangle$\n\t\\item\t$\\langle -81,2\\rangle$ or $\\langle 81,-2\\rangle$\n\\end{enumerate}\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe elevation on a portion of a hill is given by $f(x,y) =\n100 -4x^2 - 2y$.  From the location above $(2,1)$, in which direction will\nwater run?\n\\begin{sol}\nin the direction of $\\langle 8,1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSuppose that $g(x,y)=y-x^2$.  Find the gradient at the point\n$(-1, 3)$.  Sketch the level curve to the graph of $g$ when\n$g(x,y)=2$, and plot both the tangent line and the gradient vector at\nthe point $(-1,3)$. (Make your sketch large).  What do you notice,\ngeometrically?\n\\begin{sol}\n$\\ds \\nabla g(-1,3)=\\langle 2,1\\rangle$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nThe gradient $\\nabla f$ is a vector\nvalued function of two variables.  Prove the following gradient rules.\nAssume $f(x,y)$ and $g(x,y)$ are differentiable functions.\n\n\\begin{enumerate}\n\t\\item $\\nabla(fg)=f\\nabla(g)+g\\nabla(f)$\n\t\\item $\\nabla(f/g)=(g\\nabla f - f \\nabla g)/g^2$\n\t\\item $\\nabla((f(x,y))^n)=nf(x,y)^{n-1}\\nabla f$\n\\end{enumerate}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "ed1aac007881f5f748ae1ec1a20ab2a0b499473a", "size": 14672, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14-partial-differentiation/14-5-directional-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-5-directional-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-5-directional-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": 36.9571788413, "max_line_length": 90, "alphanum_fraction": 0.7014721919, "num_tokens": 5076, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970904940926, "lm_q2_score": 0.8670357580842941, "lm_q1q2_score": 0.7636825730749862}}
{"text": "\n\\subsection{Dirac delta}\n\n\\subsubsection{Kronecker delta}\n\nThe function is: \\(\\delta_{ij} \\)\n\nIf \\(i=j\\) this is \\(1\\). Otherwise it is \\(0\\).\n\nWe introduced this in linear algebra.\n\n\\subsubsection{Dirac delta}\n\nThe Dirac delta replaces the Kronecker delta for continuous functions.\n\nThat is, we want:\n\n\\begin{itemize}\n\\item \\(\\delta (x\\ne 0)=0\\)\n\\item \\(\\delta (0)=+\\infty\\)\n\\item \\(\\int_{-\\infty }^{\\infty}\\delta (x)dx=1\\)\n\\end{itemize}\n\n", "meta": {"hexsha": "8f1ef0338f18b08f1e91230e90ab5ccadda9a5b6", "size": 441, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/functionalAnalysis/07-01-delta.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/07-01-delta.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/07-01-delta.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.375, "max_line_length": 70, "alphanum_fraction": 0.6734693878, "num_tokens": 146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970842359876, "lm_q2_score": 0.867035758084294, "lm_q1q2_score": 0.7636825676489852}}
{"text": "\\subsection{Basic Properties}\r\nAll of these properties should look familiar from properties of limits and continuity.\r\nLet $f$ and $g$ be differentiable functions of $x$.\r\nLet $c$ be some real constant.\r\n\\begin{align*}\r\n\t\\textbf{Sum and Difference Rule: }& (f \\pm g)^\\prime = f^\\prime \\pm g^\\prime \\\\\r\n\t\\textbf{Constant Multiple Rule: }& (cf)^\\prime = cf^\\prime \\\\\r\n\t\\textbf{Constant Rule: }& (c)^\\prime = 0\r\n\\end{align*}\r\n\\footnotetext{This follows from using the sum and difference rule with the power rule.}\r\n", "meta": {"hexsha": "ee56a237ed8da1a27653ab12ab5e5209b05e0bf3", "size": 512, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/derivatives/derivative_rules/basic_properties.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "calc/derivatives/derivative_rules/basic_properties.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "calc/derivatives/derivative_rules/basic_properties.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 46.5454545455, "max_line_length": 88, "alphanum_fraction": 0.701171875, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.8902942363098472, "lm_q1q2_score": 0.763665999963109}}
{"text": "\\section{CAPM}\n\nFor the market porfolio to be optional the RRR of all risky assets must be the same\n\n$RRR_i = \\frac{\\bar{r}_i-r_F}{\\sigma_{iM}/ \\sigma_M} = SR_M = \\frac{\\bar{r}_M-r_F}{\\sigma_M}$\n\nthen\n\n$ \\bar{r}_i-r_F = \\frac{\\sigma_{iM}}{\\sigma_M^2} (\\bar{r}_M-r_F)  = \\beta_{iM} (\\bar{r}_M-r_F) $\n\n$\\beta_{iM}$ is a measure of asset it's systematic risk: exposure to the market.\n$\\bar{r}_M-r_F$ gives the premium per unit of systematic risk.\n\n\\subsection*{Risk and return in CAPM}\nWe can decompose an asset’s return into three pieces:\n\n\n$ \\tilde{r}_i-r_F = \\alpha_i + \\beta_{iM} (\\tilde{r}_M-r_F) + \\tilde{\\epsilon}_i$\n\n$E[\\tilde{\\epsilon}_i]=0$, $Cov[\\tilde{r}_M-r_F) , \\tilde{\\epsilon}_i]=0$\n\nThree characteristics of an asset: Alpha, according to CAPM, alpha should be zero for all assets. Beta: measures an asset’s systematic risk. SD[$\\tilde{\\epsilon}_i$] measures non-systematic risk.\n\n\\subsection*{Leverage: equity beta vs asset betas}\n\nThe assets of the firm serve to pay all investors, and so:\n$A=E+D$\n\n$\\beta_A = \\frac{E}{E+D} \\beta_E + \\frac{D}{E+D} \\beta_D$\n\n\n\\subsection*{R15Q1}\ninputs: $E[r_M]=14\\%$, $E[r_P]=16\\%$, $r_f=6\\%$, $\\sigma_M=25\\%$\n\n$E[r_P] = r_F + \\beta_P (E[r_M]-r_f) = 16\\% = 6\\% + \\beta_P (14\\% - 6\\%) =1.25$\n\nto make a portfolio to be located in the capital line, one must use the risk-free asset with weight $w$:\n $E[r_P]=w r_f + (1-w) E[r_M] = 6\\%w+14\\%(1-w) \\implies w=\\frac{E[r_P]-r_M}{r_F-r_M}=-0.25$\n \n$VaR[r_P] = Var[w r_f + (1-w) E[r_M]] = (1-w)^2 Var[r_M] \\implies \\sigma_P = 31.25\\% $ \n\nto find correlation use: \n$\\beta_P = \\frac{Cov(r_P, r_M)}{Var(r_M)}=\\frac{\\rho_{P,M} \\sigma_M \\sigma_P }{\\sigma_M^2} \\implies \\rho_{P,M}=\\frac{\\beta_P \\sigma_M}{\\sigma_P} = 1$\n\n\\subsection*{R15Q5}\nEmpirically estimating CAPM.  $r_i-r_f = \\alpha + \\beta_{MKT}^i (r_{MKT}-r_f) + \\epsilon_i$  In Excel : \\texttt{LINEST($r_i-r_f$, $r_{MKT}-r_f$,1,0)} this yields $\\beta_{MKT}$ and $\\alpha$ in that order.", "meta": {"hexsha": "4f26dd507d52b49d93776fbbb4ee45b9b818d3b5", "size": 1929, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15.415.2x/assets/week_15.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_15.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_15.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": 41.9347826087, "max_line_length": 203, "alphanum_fraction": 0.6526697771, "num_tokens": 760, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942261220292, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7636659944613824}}
{"text": "\\section{Examples of CW-complexes}\n\\subsection{Bringing you up-to-speed on CW-complexes}\n\\begin{definition}\n    A \\emph{relative CW-complex} is a pair $(X,A)$, together with a filtration\n    $$A=X_{-1}\\subseteq X_0\\subseteq X_1\\subseteq\\cdots\\subseteq X,$$\n    such that for all $n$, the space $X_n$ sits in a pushout square:\n    $$\n    \\xymatrix{\n\t\\coprod_{\\alpha\\in \\Sigma_n}S^{n-1}\\ar[r]\\ar[d]_{\\text{attaching maps}} & \\coprod_{\\alpha\\in \\Sigma_n}D^n\\ar[d]^{\\text{characteristic maps}}\\\\\n\tX_{n-1}\\ar[r] & X_n,\n    }\n    $$\n    and $X=\\varinjlim X_n$.\n\\end{definition}\nIf $A=\\emptyset$, this is just the definition of a CW-complex.\nIn this case, $X$ is also compactly generated.\n(This is one of the reasons for defining compactly generated spaces.)\nOften, $X$ will be a CW-complex, and $A$ will be a subcomplex.\nIf $A$ is Hausdorff, then so is $X$.\n\nIf $X$ and $Y$ are both CW-complexes, define\n$$(X\\times^k Y)_n = \\bigcup_{i+j = n}X_i\\times Y_j;$$\nthis gives a CW-structure on the product $X\\times^k Y$.\nAny closed smooth manifold admits a CW-structure. \n\n\\begin{example}[Complex projective space]\n    The complex projective $n$-space $\\CP^n$ is a CW-complex, with skeleta $\\CP^0\\subseteq\\CP^1\\subseteq\\cdots\\subseteq \\CP^n$.\n    Indeed, any complex line through the origin meets the hemisphere defined by\n    $\\begin{pmatrix}z_0\\\\\\vdots\\\\z_n\\end{pmatrix}$ with $||z||=1$, $\\Im(z_n) = 0$, and $\\Re(z_n)\\geq 0$.\n\tSuch a line meets this hemisphere (which is just $D^{2n}$) at one point --- unless it's on the equator;\n\tthis gives the desired pushout diagram:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    S^{2n-1}\\ar[r]\\ar[d] & D^{2n}\\ar[d]\\\\\n\t    \\CP^{n-1}\\ar[r] & \\CP^n.\n\t    }\n    \\end{equation*}\n\\end{example}\n\\begin{example}[Grassmannians]\n    Let $V=\\RR^n$ or $\\cC^n$ or $\\mathbf{H}^n$, for some fixed $n$.\n    Define the Grassmannian $\\Gra_k(\\RR^n)$ to be the collection of $k$-dimensional subspaces of $V$.\n    This is equivalent to specifying a $k\\times n$ rank $k$ matrix.\n\n    %just linalg here, nothing to see\n    %The span of rows of $A$ is the row space $V_A$. This is the span of the rows of the reduced reduced echelon form of $A$. An entry is a \\emph{pivot} if its leftmost nonzero is in its row. A column is \\emph{pivotal} if it contains a pivot. Any matrix is reduced echelon if the $i$th pivotal column is $e_i$.\n\n    For instance, $\\Gra_2(\\RR^4)$ is, as a set, the disjoint union of:\n    \\begin{equation*}\n\t\\begin{pmatrix}& 1 & \\\\ & & 1\\end{pmatrix},\\begin{pmatrix}&1&\\ast\\\\&&1\\end{pmatrix},\\begin{pmatrix}1&\\ast&\\ast\\\\&&1\\end{pmatrix},\\begin{pmatrix}&1&\\ast\\\\&1&\\ast\\end{pmatrix},\\begin{pmatrix}1&\\ast&\\ast\\\\&1&\\ast\\end{pmatrix},\\begin{pmatrix}1&\\ast&\\ast\\\\1&\\ast&\\ast\\end{pmatrix}.\n    \\end{equation*}\n    Motivated by this, define:\n    \\begin{definition}\n\tThe $j$-skeleton of $\\Gra(V)$ is\n\t$$\\mathrm{sk}_j\\Gra_k(V) = \\{A:\\text{row echelon representation with at most $j$ free entries}\\}.$$\n    \\end{definition}\n    For a proof that this is indeed a CW-structure, see \\cite[\\S 6]{milnorstasheff}.\n    %They don't know it in 18.06, but they're constructing a CW-structure for the Grassmannian.\n\\end{example}\nThe top-dimensional cell tells us that\n$$\\dim\\Gra_k(\\RR^n) = k(n-k).$$\nThe complex Grassmannian has cells in only even dimensions.\nWe know the homology of Grassmannians: Poincar\\'e duality is visible if we count the number of cells.\n(Consider, for instance, in $\\Gra_2(\\RR^4)$).\n", "meta": {"hexsha": "42194d1c9c72be90e927611335d594425bd19061", "size": 3404, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-48-examples-cw-complexes.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "906/lec-48-examples-cw-complexes.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "906/lec-48-examples-cw-complexes.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 53.1875, "max_line_length": 310, "alphanum_fraction": 0.6768507638, "num_tokens": 1181, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942290328344, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7636659937211198}}
{"text": "\\section{Method of Steepest Descent}\nThis is a method of approximating complex line integrals.\nLet us first consider the simpler case of a real integral.\nWe look for an approximation to the Gamma function\n$\\Gamma(x + 1)$\nwhen $x$ is large,\nstarting from its definition as an integral\n\\begin{align}\n    \\Gamma(x + 1)\n    &=\n    \\int_{0}^{\\infty} t^x e^{-t}\\, dt\n\\end{align}\nWe want to get an approximate integral in the limit that $x$ is very large.\nOK so how do we begin?\n\nThe first thing is note that the integrand has a maximum when\n$t=x$.\nTo see this, note the integrand is extreme when\n\\begin{align}\n    \\frac{d}{dt}\\left(\n        t^x e^{-t}\n    \\right) = 0\n\\end{align}\nat $t=t_0$.\nSolving $t_0=x$,\nfor large $x$,\nthe integrand is very highly peaked around $t=t_0$.\n\nSo to a good approximation,\nthe value of the integral is dominated by they region around the peak.\nFor large $x$,\nthe contribution of the integral is dominated by the region around the peak.\nFor a first pass,\nwe can just consider the region around the peak and discard everything else.\nThat's the approximation we make.\nIt's similar to what we do when we look at the method of steepest descent.\n\nThe first thing to do is to write the integrand in an exponential form,\nlike $e^{f(t)}$\nand expand $f(t)$ in a Taylor series\nabout the maximum.\n\nFor example,\n\\begin{align}\n    e^{f(t)} &=\n    t^{x} e^{-t}\n    = e^{x \\log t - t}\n\\end{align}\nThen\n\\begin{align}\n    f(t) &= x\\log t - t\\\\\n    f'(t) &= \\frac{x}{t} - 1\\\\\n    f''(t) &= -\\frac{x}{t^2}\n\\end{align}\nThen,\nexpanding about $t=x$,\nwe have\n\\begin{align}\n    f(t) &=\n    (x \\log x - x)\n    - \\frac{1}{2}\n    \\frac{1}{x} {(t - x)}^2 + \\cdots\n\\end{align}\nNow we approximate the integral by contribution from the region around the\nmaximum,\n\\begin{align}\n    \\Gamma(x + 1) &\\approx\n    \\int_{0}^{\\infty} dt\\,\n    \\exp\\left\\{\n    x\\log x - x \\frac{1}{2x}{(t - x)}^2\n    \\right\\}\\\\\n    &\\approx\n    e^{x\\log x - x}\\int_{-\\infty}^{\\infty}\\exp\\left\\{\n    -\\frac{1}{2x}{(t - x)}^2\n    \\right\\}\n\\end{align}\nThe error in changing the integral lower bound from 0 to $\\infty$\nis negligible\nand it's a Gaussian integral so you get\n\\begin{align}\n    \\Gamma(x + 1) \\approx\n    e^{x \\log x - x}\\sqrt{2\\pi x} = \\sqrt{2\\pi x} x^x e^{-x}\n\\end{align}\nThis is the first term in Stirling's formula.\n\nThe method of steepest descent is generally applied to integrals of the form\n\\begin{align}\n    I(s) &=\n    \\int_C g(z) e^{s f(z)} dz\n\\end{align}\nwhere $s$ is real, large and positive\nand $f(z)$ and $g(z)$ are analytic functions.\nThis restriction on $s$ being real is not important because if it were \ncomplex,\nyou can pull out the imaginary part and sign\nand absorb it into $g$ and $f$.\nAssume you've already done that.\n\nFor $f(z)=u& + iv$\nwe expect most of the contribution to the integral to come from the region\nwhere $u$ is large.\nBut by Cauchy's theorem,\nwe have to freedom to move the contour,\nso the idea is the move the contour to pass through where the value is\npeaked.\n\nThe idea behind the method of steepest descent it to choose the contour $C$\nso that it runs over a region where $u$ is large and highly peaked\nso that $I(s)$ is dominated by the contribution from this region.\n\nNow we come to the complication.\nRemember, you had to prove that neither $u$ nor $v$\ncan have a maximum or a minimum in that region.\nAll you have are saddle points.\nBut actually this turns out not to matter.\nThe question is not what is the global maximum of this function.\nAll we have to do is choose a path such that it has a maximum\n\\emph{along} that path.\nWhen going along a path,\nyou approach a point from only one direction.\nSo choose your path such that the path has a maximum along the path,\nand the integral is dominated by the contribution from that peak.\nOn the real line,\nthere's only one path of integral,\neither you have a peak or you don't.\nIn the complex plane,\nthere is no maximum,\nbut you have the flexibility to choose the path,\nso choose the path so that along that path you have a maximum,\nand the integral will be dominated by the region around that maximum\non the path.\n\nSo let's write that down.\n\nHowever, because $f(z)$ is an analytic function,\nneighbour $u$ nor $v$ can have a maximum or a minimum\n\nAny extrema of $u(x, y)$ where\n\\begin{align}\n    \\frac{\\partial u}{\\partial x}\n    &=\n    \\frac{\\partial u}{\\partial y} = 0\n\\end{align}\nmust be a saddle point,\nwhere the surface looks like a saddle or a mountain pass.\nAt any such point,\nwe also have\n\\begin{align}\n    \\frac{\\partial v}{\\partial x}\n    =\n    \\frac{\\partial v}{\\partial y} = 0\n\\end{align}\nbecause of the Cauchy-Riemann conditions.\n\nAt the saddle point, we have\n$f'(z) = 0$.\nThen we can approximate $f(z)$ near the saddle point,\n\\begin{align}\n    f(z) &=\n    f(z_0)\n    + \\frac{1}{2} f''(z_0){(z - z_0)}^2.\n\\end{align}\nHere $z=z_0$ is the saddle point.\n\n\\begin{align}\n    f''(z_0) &= |f''(z_0)| e^{i\\theta}\\\\\n    z - z_0 &= |z - z_0| e^{i\\alpha}\n\\end{align}\nand so approximate\n\\begin{align}\n    u(x, y) &\\approx\n    u(x_0, y_0) + \\frac{1}{2}|f''(z_0)|\n    |z - z_0|^2 \\cos(\\theta + 2\\alpha)\\\\\n    v(x, y) &\\approx\n    v(x_0, y_0) + \\frac{1}{2}|f''(z_0)|\n    |z - z_0|^2 \\sin(\\theta + 2\\alpha)\\\\\n\\end{align}\nSo this $\\alpha$ controls the direction that you're approaching the saddle\npoint.\nYou can choose $\\alpha$ such that as you leave the saddle point,\n$u$ is increasing,\nor you can choose $\\alpha$ such that as you leave the saddle point\n$u$ is decreasing.\nI think that's clear.\n\nOn the surface $u(x, y)$,\nthe part of paths of steepest decent from the saddle point\ninto the valleys are those for which $\\cos(\\theta + 2\\alpha)=-1$,\nso that\n\\begin{align}\n    \\alpha &= - \\frac{\\theta}{2} \\pm \\frac{\\pi}{2}\n\\end{align}\nWe can pick a path that rises very fast and falls very fast.\nWhy do we approach along this direction?\nWe want the path of steepest descent.\n\nAlong these directions,\n$\\sin(\\theta + 2\\alpha)=0$\nso $v(x, y)$ is constant.\nThen the oscillating factor $e^{isv}$\nin the integrand will not produce large cancellations\nalong that line.\nThis is pretty important.\nThis $e^{isv}$ is a phase factor,\nand this phase can be positive or negative,\nso it doesn't help if $u$ is huge and this phase factor is\noscillating like crazy.\n\nIt's very important that  there are no large oscillations in this phase as we\nintegrate along this saddle point.\nEverything is working out just the way we want.\n$e^{u}$ is large about that specific point,\nand there are no large cancellations coming from that phase.\n\nIn contrast,\nthe paths for which\n$\\cos(\\theta + 2\\alpha)=1$\nare the paths of steepest ascent.\nThose are the directions along which $u$ is growing as opposed to falling\nmost quickly as you leave the saddle point.\nAlong those directions,\nit's like you are going along a mountain ridge.\nThese paths are at right angles with respect to path of steepest descent.\n\nWe now deform the contour of integration so as to pass over the saddle point\nalong the path of steepest descent.\nSince the saddle point is a maximum of $u(x, y)$\n\\emph{along this path},\nfor large $s$ we expect that the contribution to the integral will be dominated\nby the region around the saddle point.\n\nWriting $z = z_0 + l e^{i\\alpha}$,\n\\begin{align}\n    I(s) &= \\int_{C'}\n    g\\left( z_0 + l e^{i\\alpha} \\right)\n    \\exp\\left[\n        s f(z_0 + l e^{i\\alpha})\n    \\right]\n    e^{i\\alpha}\\, dl\n\\end{align}\nSo now we approximate by Taylor expanding $f$ and $g$ around the point.\n\\begin{align}\n    f\\left( z_0 + l e^{i\\alpha} \\right) &\\approx\n    f(z_0) + \\frac{1}{2}f''\\left( z_0 \\right) l^2 e^{2i\\alpha}\n    + \\cdots\\\\\n    g\\left( z_0 + l e^{i\\alpha} \\right) &\\approx\n    g(z_0) + \\frac{1}{2}g''\\left( z_0 \\right) l e^{i\\alpha}\n    + \\cdots\\\\\n\\end{align}\nAssuming $g(z)$ is slowly varying,\nwe can approximate\n\\begin{align}\n    I(s) &\\approx\n    g\\left( z_0 \\right)\n    e^{s f\\left(z_0 \\right)}\n    e^{i\\alpha}\n    \\int_{-\\infty}^{\\infty}\n    e^{-\\frac{1}{2}\\left|f''\\left( z_0 \\right)\\right| sl^2}\n    \\,dl\n\\end{align}\nNow this is a Gaussian integral,\nand we changed the limits to $(-\\infty, \\infty)$,\nbut it's not going to change the answer significantly.\nAnd when the dust settles\n\\begin{align}\n    I(s) &\\approx\n    \\frac{%\n        \\sqrt{2\\pi} g(z_0) e^{sf(z_0)} e^{i\\alpha}\n    }{%\n        \\sqrt{s |f''(z_0)|}\n    }\n\\end{align}\nThis is the one big formula you're going to have to remember when you take the\nexam,\nbecause you're not going to be allowed to bring cheatsheets.\n\nYou have to remember $\\alpha$ is related to $\\theta$ in that way\nand $\\theta$ is the phase of $f''$.\n\nNow there is one complication,\nwhich applies in the real world,\nbut probably not your homework problems.\n\nRecall that there are 2 possible values of the angle $\\alpha$,\nwhich differ by $\\pi$.\nWhich value of $\\alpha$ should we choose?\n\\begin{align}\n    \\alpha &= -\\frac{\\theta}{2} \\pm \\frac{\\pi}{2}\n\\end{align}\nThat depends on the direction we cross the saddle point.\nIf the direction is reversed,\nthe value of the integral will flip sign.\n\nLet me explain what I mean.\nLet's say you have to integrate from $A$ to $B$.\nLet's say the saddle point is somewhere in the middle.\nYou want to cross the saddle point along that direction from $A$ to $B$.\nAnd so this would be the angle $\\alpha$.\n\n[picture]\n\nBut suppose $B$ is here and $A$ is here.\n\n[picture]\n\nNow you have to go in the opposite direction.\nThe angle $\\alpha$ is this angle,\nwhich is different from the original $\\alpha$ by $\\pi$.\nDepending on where you're starting or ending,\nyou're going through the saddle point in a different direction,\nin which case you get a different value of $\\alpha$.\nSo it's either you can go this way or that way,\nand it's just a minus sign difference.\nYou just reverse the direction you're integration.\n\nSo that ambiguity is hidden here:\n$\\alpha = -\\frac{\\theta}{2} \\pm\n\\frac{\\pi}{2}$.\n\nSometimes you can have weird contours.\nIn the real world,\nyou need to create the full ridge.\nMake sure you only cross it once over the direction you chose.\nRemember if you're signing a paper,\nyou're putting your reputation on the line,\nand these subtleties do show up.\nThis is not going to be in the homework of course.\n\nI have 2 examples in the notes,\nbut I don't have time to go other both of them.\nLet's do the shorter example because we don't have a whole bunch of time.\nMost of what I talk about is based on Matthews and Walker.\n\n\\begin{example}\n    The Hankel function of the first kind,\n    which is a solution of the Bessel equation,\n    may be represented by the contour integral\n    \\begin{align}\n        H_{\\nu}^{(1)}(s) &=\n        \\frac{1}{\\pi i}\n        \\int_{\\epsilon}^{\\infty e^{i\\pi}}\n        e^{\\frac{s}{2}\\left( z - \\frac{1}{z} \\right)}\n        \\frac{dz}{z^{\\nu + 1}}\n    \\end{align}\n    where the $(1)$ means first kind.\n    Here $\\epsilon\\to 0$, and the contour is shown in the figure.\n    There is a branch cut because of the $1/z^{\\nu + 1}$,\n    and you choose the branch cut to go along the negative real axis.\n    The contour to integrate over looks like this:\n    Start from $\\epsilon$ then spiral anticlockwise around to negative\n    $-\\infty$ staying above the branch cut.\n\\end{example}\nThis is a solution to the Bessel equation,\nbecause if you substitute it in,\nthe integrand doesn't satsify it,\nbut inside the integral,\nyou take a total derivative and these limits are cunningly chosen so that at the\nlimits the derivative piece once you do the integration vanishes.\nWe won't have to discuss that,\nsince this course doesn't cover special functions at all.\nWe won't have time to discuss,\nbut I can just outline.\nThe thing you're left with is a total derivative,\nand since it's sitting on a derivative,\nthe endpoints you're left with are 0 at the end points.\nThere is an extended discussion Arfken.\n\nOur problem is just to find an approximation to this integral in the region of\nlarge $s$.\n\nThe integrand has a branch cut along the negative $x$-axis\nand the contour is to be taken from $\\epsilon$ to $-\\infty$\nabove this branch cut.\n\nWe want to approximate this integral,\nso we have a formula for the method of steepest descent.\nThe integral we began from is this integral\n\\begin{align}\n    I(s) &=\n    \\int_C g(z) e^{s f(z)} dz\n    \\approx\n    \\frac{%\n        \\sqrt{2\\pi} g(z_0) e^{sf(z_0)} e^{i\\alpha}\n    }{%\n        \\sqrt{s |f''(z_0)|}\n    }\n\\end{align}\nSo we choose\n\\begin{align}\n    g(z) &= \\frac{1}{z^{\\nu + 1}}\\\\\n    f(z) &= \\frac{1}{2}\\left( z - \\frac{1}{z} \\right)\n\\end{align}\nTake derivatives\n\\begin{align}\n    f'(z) &= \\frac{1}{2}\\left( 1 + \\frac{1}{z^2} \\right)\\\\\n    f''(z) &= -\\frac{i}{z^3}\n\\end{align}\nSo there are saddle points at $z = \\pm i$,\nbut we want $z_0 = +i$\nbecause that's above the branch cut.\n\n\\begin{align}\n    f(z_0) &= \\frac{1}{2}\\left( i - \\frac{1}{i} \\right) = 1\\\\\n    f''(z_0) &= -\\frac{1}{i^3} = -i\n\\end{align}\nThen\n\\begin{align}\n    f''(z_0) &= |f''(z_0)| e^{i\\pi/2}\n\\end{align}\nso\n\\begin{align}\n    \\theta = - \\frac{\\pi}{2}\n\\end{align}\nso we get\n\\begin{align}\n    \\alpha &= - \\frac{\\theta}{2} \\pm \\frac{\\pi}{2}\\\\\n    &= \\frac{3\\pi}{4} \\quad \\text{or} -\\frac{\\pi}{4}\n\\end{align}\nBecause of the direction we're going,\nthe correct angle is\n\\begin{align}\n    \\alpha=\\frac{3\\pi}{4}.\n\\end{align}\nThen,\n\\begin{align}\n    I(s) &\\approx\n    \\frac{%\n        \\sqrt{2\\pi} g(z_0) e^{sf(z_0)} e^{i\\alpha}\n    }{%\n        \\sqrt{s |f''(z_0)|}\n    }\\\\\n    &=\n    \\sqrt{\\frac{2}{\\pi s}}\n    e^{i\\left(\n        s - \\nu \\frac{\\pi}{2} + \\frac{\\pi}{4}\n    \\right)}\n\\end{align}\nSo, any questions?\n\nWe're done for the mathematical methods part of the course.\n\nNext lecture,\nwe're back to in person,\nand we will begin the classical mechanics part of the course.\n\nI'll see you next week.\n", "meta": {"hexsha": "4c5f303a2d9a76b88f1bd05074892f635c680aea", "size": 13617, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "phys610/lecture10.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/lecture10.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/lecture10.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.4630872483, "max_line_length": 80, "alphanum_fraction": 0.6762135566, "num_tokens": 4192, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681013541613, "lm_q2_score": 0.8902942319436397, "lm_q1q2_score": 0.763665992980857}}
{"text": "\\documentclass{notes}\n\n  \\title{Example Turing Machine}\n  \\author{ian.mcloughlin@gmit.ie}\n  \\date{\\today}\n\n\\begin{document}\n\n  \n\n  \\subsection*{Language}\n  \\begin{align*}\n      A    &= \\{ 0, 1 \\} \\\\\n      A^*  &= \\{ \\epsilon, 0, 1, 00, 01, 10, 11, 000, \\ldots \\} \\\\\n      L    &= \\{ \\epsilon, 01, 0011, 000111, \\ldots \\} \\\\\n      A^* \\setminus L &= \\{ 0, 1, 00, 10, \\ldots \\} \\\\[2mm]\n    \\mathbb{N}_0 &= \\{ 0 , 1 , 2 , 3 , \\ldots \\} \\\\\n      L &= \\{ 0^i 1^i | i \\in \\mathbb{N}_0 \\} \\\\\n  \\end{align*}\n  \n  \\section*{Turing machine}\n  \\begin{center}\n    \\begin{tabular}{x{1cm}x{1cm}x{1cm}x{1cm}x{1cm}}\n      \\toprule\n      State & Input & Write & Move & Next \\\\\n      \\midrule\n      \\(q_0\\) & \\bl & \\bl & R & \\(q_a\\) \\\\\n      \\(q_0\\) &   0 & \\bl & R & \\(q_1\\) \\\\\n      \\(q_0\\) &   1 &   1 & R & \\(q_f\\) \\\\\n      \\midrule\n      \\(q_1\\) & \\bl & \\bl & L & \\(q_2\\) \\\\\n      \\(q_1\\) &   0 &   0 & R & \\(q_1\\) \\\\\n      \\(q_1\\) &   1 &   1 & R & \\(q_1\\) \\\\\n      \\midrule\n      \\(q_2\\) & \\bl & \\bl & R & \\(q_f\\) \\\\\n      \\(q_2\\) &   0 &   0 & R & \\(q_f\\) \\\\\n      \\(q_2\\) &   1 & \\bl & L & \\(q_3\\) \\\\\n      \\midrule\n      \\(q_3\\) & \\bl & \\bl & R & \\(q_0\\) \\\\\n      \\(q_3\\) &   0 &   0 & L & \\(q_3\\) \\\\\n      \\(q_3\\) &   1 &   1 & L & \\(q_3\\) \\\\\n      \\bottomrule\n    \\end{tabular}\n  \\end{center}\n\n  \\section*{Example input}\n  \n  \\begin{align*}\n    &\\           q_0 000111    \\rightarrow  q_1 00111  \\rightarrow 0 q_1 0111 \\rightarrow 00 q_1 111 \\\\\n    &\\rightarrow 001 q_1 11    \\rightarrow 0011 q_1 1  \\rightarrow 00111 q_1  \\rightarrow 0011 q_2 1 \\\\\n    &\\rightarrow 001 q_3 1     \\rightarrow 00 q_3 11   \\rightarrow 0 q_3 011  \\rightarrow q_3 0011   \\\\\n    &\\rightarrow q_3 \\blm 0011 \\rightarrow q_0 0011    \\rightarrow q_1 011    \\rightarrow 0 q_1 11   \\\\\n    &\\rightarrow 01 q_1 1      \\rightarrow 011 q_1     \\rightarrow 01 q_2 1   \\rightarrow 0 q_3 1    \\\\\n    &\\rightarrow q_3 01        \\rightarrow q_3 \\blm 01 \\rightarrow q_0 01     \\rightarrow q_1 1      \\\\\n    &\\rightarrow 1 q_1         \\rightarrow q_2 1       \\rightarrow q_3        \\rightarrow q_1 \\rightarrow q_a \\\\\n  \\end{align*}\n\n  \\subsection*{Steps}\n  \\begin{align*}\n    &q_0 000111 \\rightarrow \\ldots 13 \\textrm{ steps} \\ldots \\rightarrow q_0 0011 \\\\\n    &\\rightarrow \\ldots 9 \\textrm{ steps} \\ldots \\rightarrow q_0 01 \\rightarrow \\ldots 5 \\textrm{ steps} \\ldots\\\\\n    & \\rightarrow q_0 \\rightarrow \\ldots 1 \\textrm{ step} \\ldots \\rightarrow q_a \\qquad (28 \\textrm{ total})\n  \\end{align*}\n  \n  \n    \\subsection*{Simulation}\n    \n    \\begin{center}\n    \\begin{tabular}{crrrrrrrr}\n      \\toprule\n      $n$   & 0 &  2 &  4 &  6 &  8 & 10 & 12 &  14 \\\\\n      \\midrule\n      $f(n)$ & 1 &  6 & 15 & 28 & 45 & 66 & 91 & 120 \\\\\n      \\bottomrule\n    \\end{tabular}\n    \\end{center}\n    \n    \\subsection*{Sequence}\n    OEIS~\\cite{oeisA000384} gives sequence formula:\n    \\[ a(i):\\mathbb{N} \\rightarrow \\mathbb{N}_0 = i (2i - 1) \\]\n\n    So, \\(a(1)=1\\), \\(a(2)=6\\), \\(a(3)=15\\), and so on.\n    We index as \\(2\\mathbb{N} = \\{ 0,2,4,6,8,10,\\ldots \\} \\). Transform:\n    \\[ h(n):2\\mathbb{N}_0 \\rightarrow \\mathbb{N} = \\frac{n}{2} + 1. \\]\n    So, \\(h(0)=1\\), \\(h(2)=2\\), \\(h(4)=3\\), and so on.\n\n    \\begin{align*}\n    f(n):2\\mathbb{N}_0 \\rightarrow \\mathbb{N}_0 &= a(h(n)) \\\\\n         &= \\left(\\frac{n}{2} + 1\\right) \\left(2 \\left(\\frac{n}{2} + 1\\right) - 1 \\right) \\\\\n         &= \\left(\\frac{n}{2} + 1\\right) \\left(n + 2 - 1\\right) \\\\\n         &= \\frac{1}{2} \\left(n + 2\\right) \\left(n + 1\\right) \\\\\n         &= \\frac{1}{2} \\left(n^2 + 3n + 2 \\right) \\\\\n    \\end{align*}\n    \n    So, $f(n)$ is $O(n^2)$.\n    \n    \\subsection*{Justification}\n    Is \\( f(n) \\) the correct formula for the number of steps taken for an accepted input of length \\(n\\)?\n    \n    Each pass right and left across the \\(j\\) non-blank tape cells, the machine takes \\(j+1\\) steps right, followed by \\(j\\) steps left.\n    \\begin{center}\n    \\begin{tabular}{llrr}\n    \\toprule\n        \\textbf{Start} & \\textbf{End} & \\textbf{Right} & \\textbf{Left} \\\\\n        \\midrule\n        000111       & 0011         & 7 & 6 \\\\\n        0011         & 01           & 5 & 4 \\\\\n        01           & \\(\\epsilon\\) & 3 & 2 \\\\\n        \\(\\epsilon\\) & \\(q_a\\)     & 1 & 0 \\\\\n    \\bottomrule\n    \\end{tabular}\n    \\end{center}\n    \n    \\begin{align*}\n       f(n) &= (n+1) + n + \\ldots + 2 + 1 + 0 \\\\\n            &= \\left((n+1) + 0\\right) + \\left((n) + 1\\right) + \\ldots \\\\\n            &= \\left(\\frac{n}{2} + 1\\right)(n+1) \\\\\n    \\end{align*}\n    \n    \\subsection*{Decider}\n    Does the Turing Machine always halt and if so, does it reject in \\(O(n^2)\\)?\n    Is \\(L \\in \\mathbf{P}\\)?\n\n  \\bibliography{bibliography}\n\\end{document}", "meta": {"hexsha": "cc9f1baeb95b032e32c31c920ee9cc675efeda74", "size": 4623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "i-zeros-ones.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": "i-zeros-ones.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": "i-zeros-ones.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": 36.984, "max_line_length": 136, "alphanum_fraction": 0.4966471988, "num_tokens": 1890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297914570319, "lm_q2_score": 0.8479677660619633, "lm_q1q2_score": 0.7636202355340651}}
{"text": "\\subsection{Numerical Approximation and Analysis}\\label{sec:sample-algorithm}\n\nThe numerical approximation of the updated density can be achieved by following Algorithm~\\ref{alg:updated_density}, which involves approximating a push-forward distribution using a finite set of samples drawn from the initial density and mapped forward by $\\qoi$.\nOnce an approximation of the predicted density is formed, it can be evaluated alongside the initial and observed density at any other point so long as evaluation through $\\qoi$ is available.\n\n\n\n\\begin{algorithm}[hbtp]\n\\DontPrintSemicolon\nDraw $\\nsamps$ samples from the initial density to construct the set $\\set{\\param^{(\\iparam)}}_{\\iparam=1}^{\\nsamps} \\subset \\pspace$.\n\t\\For{$\\iparam = 1, \\hdots, \\nsamps$}{\n\tCompute $\\qoi_\\iparam = \\qoi(\\param^{(\\iparam)})$.\\\\\n\t}\n\tApproximate $\\predicted\\Q$, the push-forward of $\\initial$, by some method such as kernel density estimation.\n  \\For{$\\iparam = 1, \\hdots, \\nsamps$}{\n\tCompute $\\updated\\lami = \\initial\\Qi \\frac{\\observed\\Qi}{\\predicted\\Qi}$.\\\\\n\t}\n\n \\caption{Numerical Approximation of the Inverse Density using the Sample-Based Approach}\n \\label{alg:updated_density}\n\\end{algorithm}\n\nTK -\npicture of pushforward given different number of samples, overview of KDE\n", "meta": {"hexsha": "a0b08f23cde57a2a852634818cf7167b592d997d", "size": 1260, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch02/sample_algorithm.tex", "max_stars_repo_name": "mathematicalmichael/thesis", "max_stars_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2019-04-24T08:05:49.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-28T20:34:29.000Z", "max_issues_repo_path": "ch02/sample_algorithm.tex", "max_issues_repo_name": "mathematicalmichael/thesis", "max_issues_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 59, "max_issues_repo_issues_event_min_datetime": "2019-12-27T23:15:05.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-24T17:52:57.000Z", "max_forks_repo_path": "ch02/sample_algorithm.tex", "max_forks_repo_name": "mathematicalmichael/thesis", "max_forks_repo_head_hexsha": "2906b10f94960c3e75bdb48e5b8b583f59b9441e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 50.4, "max_line_length": 264, "alphanum_fraction": 0.7579365079, "num_tokens": 326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8479677545357568, "lm_q1q2_score": 0.7636202274180816}}
{"text": "\\chapter{Manifolds and differentiable structures}\n\n\\begin{problem}{1}\nShow that every (differentiable) manifold possesses a countable (differentiable) atlas.\n\\end{problem}\n\\begin{proof}\nLet $\\mathcal{A} = \\{(U_\\alpha, h_\\alpha) \\mid \\alpha \\in A \\}$ be an atlas for $M.$ Since $M$ is second countable, there exists a countable basis $B = \\{V_n \\mid n \\in \\N \\}.$ For each $p \\in M$ there exist $V_k \\in B$ and $(U_\\beta, h_\\beta) \\in \\mathcal A$ such that $p \\in V_k \\subset U_\\beta.$ Since $B$ is countable, there is a sequence $\\{\\alpha_{k}\\}_{k}^\\infty \\subset A$ such that $\\bigcup_k U_{\\alpha_k} = M$. It follows that $\\{(U_{\\alpha_k}), h_{\\alpha_l} \\mid k \\in \\N \\}$ is a countable atlas of $M.$\n\\end{proof}\n\n\\begin{problem}{2}\nShow that the sphere $S^n$ possesses a differentiable atlas with precisely two charts. Also, one with only one chart?\n\\end{problem}\n\\begin{proof}\nLet $p_1 = (0, \\ldots, 0, 1) \\in S^n$ and $p_2 = (0,\\ldots,0, -1) \\in S^n$. Then the sets $U_ 1 = S^n - {p_1}$ and $U_2 = S^n - \\{p_2\\}$ are open. Define $h_1: U_1 \\rightarrow \\R^n$ and $h_2: U_2 \\rightarrow \\R^n$ by \n$$\nh_1(x_1, \\ldots, x_{n+1}) = \\left(\\frac{x_1}{1-x_{n+1}}, \\ldots, \\frac{x_n}{1-x_{n+1}}\\right),\n$$\n$$\nh_2(x_1, \\ldots, x_{n+1}) = \\left(\\frac{x_1}{1+x_{n+1}}, \\ldots, \\frac{x_n}{1+x_{n+1}}\\right).\n$$\n\nA direct argument shows that these functions are homeomorphisms from $U_1, U_2$ onto $\\R^{n}.$ Their inverses, $h_1^{-1}, h_2^{-1}$, are defined in the following way:\n$$\nh_1^{-1}(x_1, \\ldots, x_n) = \\left( \\frac{2x_1}{1 + r^2}, \\ldots,  \\frac{2 x_n}{1+r^2}, \\frac{r^2-1}{1+r^2} \\right),\n$$\n$$\nh_2^{-1}(x_1, \\ldots, x_n) = \\left( \\frac{2x_1}{1 - r^2}, \\ldots,  \\frac{2 x_n}{1-r^2}, \\frac{r^2}{1-r^2} \\right).\n$$\n\nwith $r^2 = \\sum_{k=1}^n x_k^2.$ Then $h_2 \\circ h_1^{-1}: \\R^n \\rightarrow \\R^n$ is defined \n$$ (h_2 \\circ h_1^{-1}) (x_1, \\ldots, x_n) = h_2 \\left( \\frac{2x_1}{1 + r^2}, \\ldots,  \\frac{2 x_n}{1+r^2}, \\frac{r^2-1}{1+r^2} \\right) = \\frac{1}{r^2}(x_1, \\ldots, x_n).$$\n\nHence $h_2 \\circ h_1^{-1}$ is differentiable. In a similar way, $h_1 \\circ h_2^{-1}$ is differentiable. Therefore, the atlas $\\{(U_1, h_1), (U_2, h_2)\\}$ defines a differentiable structure.\n\n\\end{proof}\n\n\n\\begin{problem}{3}\nDescribe the chart transformation for the atlas $\\R P^n$ in (1.5(c)), and show that it is differentiable.\n\\end{problem}\n\n\n\\begin{problem}{4}\nLet $M$ be a differentiable manifold and $\\tau: M \\rightarrow M$ a fixed point free involution, that is, $\\tau$ is a diffeomorphism with $\\tau \\circ \\tau = Id_M$ and $\\tau(x) \\neq x$ for all $x.$ \n\nShow that the quotient space $M/\\tau$, which is obtained from $M$ by identification of points corresponding to each other under $\\tau$, is a topological manifold which possesses exactly one differentiable structure with respect to which the projection $M \\rightarrow M/\\tau$ is locally diffeomorphic.\n\\end{problem}\n\\begin{proof}\nLet $p: M \\rightarrow M/\\tau$ be the canonical projection and let $\\mathcal A$ be a maximal atlas of $M$. Since $M$ is Hausdorff, for each $x \\in M$ there exist open sets $U, V$ such that $x\\in U$, $\\tau(x) \\in V$ and $U \\cap V = \\varnothing.$ Since $\\tau$ is continuous, $W = U \\cap \\tau^{-1}(V)$ is a non-empty open set. This open set satisfies $W \\cap \\tau(W) = \\varnothing$; then the set $\\mathcal B = \\{(W, k) \\in \\mathcal A \\mid W \\cap \\tau(W) \\}$ is non-empty.\n\nFor each $(W, k)\\in \\mathcal B$, the function $p$ is injective in $W$. Let $x, y \\in W$ with $p(x) = p(y)$, that is, $x,y$ belong to the same equivalence class. But $W \\cap \\tau(W) = \\varnothing$, hence $x=y.$ Since by definition $p$ is surjective, we have shown that $p$ is bijective in $W.$\n\nA direct argument shows that the set $\\mathcal C = \\{(p(W), k \\circ p^{-1}) \\mid (W, k) \\in \\mathcal B \\}$ induces a differentiable structure in $M/\\tau$. To show that $p$ is locally diffeomorphic with respect to these differentiable structures, let $x \\in M$ and $(W, k)\\in \\mathcal B$ with $x\\in W$. The composition $(k \\circ p^{-1}) \\circ p \\circ k^{-1} = Id_{\\R^n}$ is differentiable. The inverse $p^{-1}: p(W) \\rightarrow W$ of $p$ is also differentiable, since the composition $k \\circ p^{-1}\\circ (k \\circ p^{-1})^{-1} = k \\circ p^{-1} \\circ (p \\circ k^{-1}) = Id_{\\R^n}$ is differentiable.\n\nUNIQUENESS\n\\end{proof}\n\n\\begin{problem}{5}\nShow that $\\R P^1 \\cong S^1.$\n\\end{problem}\n\\begin{proof}\n\n\\end{proof}\n\n\\begin{problem}{6}\nProvide the surface of a cube $\\{x\\in \\R^{n+1} \\mid \\max \\{\\lvert x_i \\rvert\\ = 1 \\}$ with the structure of a differentiable manifold. \n\\end{problem}\n\n\\begin{problem}{7}\nLet $M$ be a differentiable manifold and $f: N \\rightarrow M$ a homeomorphism. Prove that $N$ possesses exactly one structure as a differentiable manifold, so that $f$ is diffeomorphic.\n\\end{problem}\n\n\\begin{problem}{8}\nProvide the complex projective sapce $\\C P^n$ with the structure of a $2n-$dimensional differentiable manifold. This space is defined as follows: on the complex vector space $\\C^{n+1},$ one has the equivalence relation $x \\sim y$ if and only if there is a number $\\lambda \\in \\C$, $\\lambda \\neq 0$, so that $\\lambda x = y$. The quotient space $(\\C - \\{0\\}) / \\sim $ is defined to be $\\C P^n$. \n\\end{problem}\n\n\\begin{problem}{9}\nProve that if $M$ is a non-empty, $n-$dimensional manifold and $k \\leq n$, then tere is an embedding $\\R^k \\rightarrow M.$\n\\end{problem}\n\n\\begin{problem}{10}\nLet $N$ be a compact, $M$ a connected manifold, both of dimension $n$ and non-empty. Let $f: N \\rightarrow M$ be an embedding. Show that $f$ is a diffeomorphism.\n\\end{problem}\n\n\n\\begin{problem}{11}\nShow that $S^n$ is a submanifold of $\\R^{n+1}.$\n\\end{problem}\n\n\n\\begin{problem}{12}\nDescribe an embedding $S^1 \\times S^1 \\rightarrow \\R^3$ by means of elementary functions.\n\\end{problem}\n\n\n\\begin{problem}{13}\nShow that the composition of two embeddings is again an embedding and the Cartesian product $f_1 \\times f_2: N_1 \\times N_2 \\rightarrow M_1 \\times M_2$, of two embeddings $f_1, f_2$, is again an embedding. \n\\end{problem}\n\n\n\\begin{problem}{14}\nShow that if the $n-$dimensional manifold $M$ is a product of spheres, then there exists an embedding $M\\rightarrow \\R^{n+1}.$\n\\end{problem}\n\n\n\\begin{problem}{15}\nThe points of $\\C P^k$ are described by the homogeneous coordinates $x = [x_0, \\ldots, x_k]:= \\text{ class of} (x_0, \\ldots, x_k)$ under $\\sim$. Show that the mapping \n$$\nf: \\C P^m \\times \\C P^n \\rightarrow \\C P^{mn + m + n}\n$$\n$$\n(x, y) \\mapsto [x_0y_0, x_0 y_1, \\ldots, x_v y_\\mu, \\ldots, x_m y_n ]\n$$\nis an embedding. Show the same for the real projective spaces. \n\\end{problem}\n\n\n\\begin{problem}{16}\nLet $M(m \\times n)$ be the vector space of real $(m\\times n)-$matrices, and $M_r(m \\times n)$ the subset of matrices of rank $r$. Then $M_r(m \\times n)$ is a submanifold of $M(m \\times n)$ of codimension $(n-r)(m-r)$ for $r \\leq \\min \\{m,n\\}.$\n\\end{problem}\n\n\n\\begin{problem}{17}\nThe inclusion $\\R^{n+1} \\subset \\R^{n+2}$ induces an embedding $\\R P^n \\subset \\R P^n{n+1}$ and $\\R P^{n+1} - \\R P^{n} \\cong \\R^{n+1}.$\n\\end{problem}\n\n\n\\begin{problem}{18}\nLet $\\R^{n+1} = \\{(x, a_0, \\ldots, a_{n-1}) \\mid x, a_i \\in \\R \\}$. The set of points such that $x^n + a_{n-1}x^{n-1}+ \\ldots + a_0 = 0$ is a submanifold of codimension $1$ of $\\R^{n+1}$, and is diffeomorphic to $\\R^n.$\n\\end{problem}\n\n\n\\begin{problem}{19}\nThe set $C^\\infty(M)$ is an algebra under the natural addition and multiplication of functions. A differentiable mapping $f: M \\rightarrow N$ defines an algebra homomorphism\n$$\nf^\\ast: C^\\infty(N) \\rightarrow C^\\infty(M), \\ \\ \\phi \\mapsto \\phi \\circ f\n$$\nwith the functorial properties: $Id^\\ast_M = Id;$ $(f \\circ g)^\\ast = g^\\ast \\circ f^\\ast.$\n\\end{problem}\n\n\\begin{problem}{20}\nNotation as in 19. For a point $p\\in M$ let \n$$\n\\mathrm{M}_p = \\{\\phi \\in C^\\infty(M) \\mid \\phi(p) = 0 \\}.\n$$\nShow:\n\\begin{itemize}\n\\item[(a)] $\\mathrm{M}_p$ is a maximal ideal of $C^\\infty(M).$\n\\item[(b)] If $M$ is compact and $\\mathrm{M} \\in C^\\infty(M)$ is a maximal ideal, then tehere exists some $p \\in \\mathrm{M}$ such that $\\mathrm{M} = \\mathrm{M}_p.$\n\\end{itemize}\n\\end{problem}", "meta": {"hexsha": "2302f9aae8a0738a08335d49ce511c27f6bb53a7", "size": 8039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diff-top-broker/chapter1.tex", "max_stars_repo_name": "luisgrivas/simplemath", "max_stars_repo_head_hexsha": "0f5a2e7fe9ffb54554ecce78b8f8b4670a64522e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diff-top-broker/chapter1.tex", "max_issues_repo_name": "luisgrivas/simplemath", "max_issues_repo_head_hexsha": "0f5a2e7fe9ffb54554ecce78b8f8b4670a64522e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diff-top-broker/chapter1.tex", "max_forks_repo_name": "luisgrivas/simplemath", "max_forks_repo_head_hexsha": "0f5a2e7fe9ffb54554ecce78b8f8b4670a64522e", "max_forks_repo_licenses": ["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.238410596, "max_line_length": 597, "alphanum_fraction": 0.6559273541, "num_tokens": 2917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336202, "lm_q2_score": 0.8519528038477824, "lm_q1q2_score": 0.7635638702936128}}
{"text": "\\textbf{Consider the numerical solution of the wave equation with Dirichlet boundary condition:\n\\begin{align*}\nu_{tt} = u_{xx},~~~ x\\in (−1, 1),~~~ u(t, −1) = u(t, 1) = 0,~~~ u(0, x) = e^{-32x^2},~~~ u_t(0, x) = 0.\n\\end{align*}\nAssuming sufficient smoothness in u and appropriate initial conditions, show that solving (1) is equivalent to solving the acoustic equations\n\\begin{align*}\nu_t = p_x,\\\\\np_t = u_x,\n\\end{align*}\nwith boundary conditions $u(t, −1) = u(t, 1) = 0$. Find the appropriate initial condition for p.}\n\n\\textbf{Solve this problem using second order centered finite differences in space and $ode45$ in time. Use a staggered equispaced grid. That is, discretize $u$ at the gridpoints $x_j = −1 + jh$ and $p$ at the nodes $x_{\\frac{j+1}{2}}= −1 + (j+\\frac{1}{2})h$. Notice that boundary conditions for $p$ are not required in this case. Plot your solution ($u$ and $p$ on the same figure) for $t = 0.5, 1, 1.5, 2$.}\n\n\\textbf{Estimate the accuracy of your answer at $t = 4$, notice that $u(4, x) = u(0, x)$.}\n\n\\vspace{0.3in}\n\nFor the first part note that\n\\begin{align*}\nu_{tt}=\\frac{\\partial}{\\partial t}p_x=p_{xt},\n\\end{align*}\nand\n\\begin{align*}\nu_{xx}=\\frac{\\partial}{\\partial x}p_t=p_{tx}.\n\\end{align*}\n\nSince $u$ is sufficiently smooth, both $p_{xt}$ and $p_{tx}$ are continuous. Therefore they must be equal and\n\\begin{align*}\nu_{tt}=p_{xt}=p_{tx}=u_{xx}.\n\\end{align*}\nTo find the initial condition for $p$ we simply use the initial conditions for $u$,\n\\begin{align*}\np_t(0,x)=u_x(0,x)=-64xe^{-32x^2}.\n\\end{align*}\nand\n\\begin{align*}\np_x(0,x)=u_t(0,x)=0.\n\\end{align*}\n\nFor the second part of the problem, let us express the acoustic equations in matrix form\n\\begin{align*}\n\\frac{d}{dt}\\begin{bmatrix} u \\\\ p \\end{bmatrix}=\\begin{bmatrix} 0 & \\frac{\\partial}{\\partial x}\\\\ \\frac{\\partial}{\\partial x} & 0\\end{bmatrix}\\begin{bmatrix} u \\\\ p \\end{bmatrix}.\n\\end{align*}\nWe are using staggered meshes so the space derivative operator for $u$ and $p$ are going to be different, letting the previous equation in matrix form be like\n\\begin{align*}\n\\frac{d}{dt}\\begin{bmatrix} u \\\\ p \\end{bmatrix}=\\begin{bmatrix} 0 & D_p\\\\ D_u & 0\\end{bmatrix}\\begin{bmatrix} u \\\\ p \\end{bmatrix},\n\\end{align*}\nor\n\\begin{align*}\n\\frac{d}{dt}\\textbf{V}=M\\textbf{V},\n\\end{align*}\nwhere $\\textbf{V}=\\begin{bmatrix} u \\\\ p \\end{bmatrix}$ and $M$ is the matrix composed by $D_u$, $D_p$ and zeros. Since we have $N+1$ nodes of $u$ and we only solve for the interior, our matrix  $D_u$ will only have $N-1$ columns. However, we want to evaluate $u_x$ in the $N$ nodes for $p$, therefore $D_u$ will have $N$ rows. Thus, $D_u$ is $N\\times N-1$. We are going to use central finite differences to evaluate the first derivative of $u$, but since we are going to evaluate the result in the staggered $p$ nodes we have\n\\begin{align*}\n\\frac{\\partial}{\\partial t}p_j=\\frac{\\partial}{\\partial x}u_{j+\\frac{1}{2}}=\\frac{u_{j+1}-u_{j}}{h},\n\\end{align*}\nwhere $j=1,...N$, since we are using \\textsl{Matlab} indices. Since we are only solving the interior for $u$ there is going to be a shift in the matrix and the real system we are going to solve is the following\n\\begin{align*}\n\\frac{\\partial}{\\partial t}\\begin{bmatrix} u \\\\ p \\end{bmatrix}=\\begin{bmatrix} 0 & D_p\\\\ \\tilde{D}_u & 0\\end{bmatrix}\\begin{bmatrix} u \\\\ p \\end{bmatrix},\n\\end{align*}\nor\n\\begin{align*}\n\\frac{\\partial}{\\partial t}\\textbf{V}=\\tilde{M}\\textbf{V}.\n\\end{align*}\nTherefore, the discretization yields\n\\begin{align*}\n\\frac{\\partial}{\\partial t}p_j=\\frac{\\partial}{\\partial x}\\tilde{u}_{j-\\frac{1}{2}}=\\frac{\\tilde{u}_{j}-\\tilde{u}_{j-1}}{h}.\n\\end{align*}\nNote that $\\tilde{u}_j=u_{j+1}$. For the first and last points we include the boundary conditions,\n\\begin{align*}\n\\frac{\\partial}{\\partial t}p_1=\\frac{\\partial}{\\partial x}\\tilde{u}_{-\\frac{1}{2}}=\\frac{\\tilde{u}_{1}-\\tilde{u}_{0}}{h}=\\frac{u_{2}-u_{1}}{h}=\\frac{u_2}{h}=\\frac{\\tilde{u_1}}{h},\n\\end{align*}\nand\n\\begin{align*}\n\\frac{\\partial}{\\partial t}p_N=\\frac{\\partial}{\\partial x}\\tilde{u}_{N-\\frac{1}{2}}=\\frac{\\tilde{u}_{N}-\\tilde{u}_{N-1}}{h}=\\frac{u_{N+1}-u_{N}}{h}=\\frac{-u_{N}}{h}=-\\frac{\\tilde{u}_{N-1}}{h}.\n\\end{align*}\nFrom the previous equations we obtain\n\\begin{align*}\n\\frac{\\partial}{\\partial t}\\begin{bmatrix} p_1 \\\\ p_2 \\\\p_3\\\\ \\vdots \\\\p_{N-1}\\\\p_N \\end{bmatrix}=\\frac{1}{h}\\begin{bmatrix}\n1 & 0 & 0 & \\cdots & 0\\\\\n-1 & 1 & 0 & \\cdots & 0\\\\\n0 & -1 & 1 & \\cdots & 0\\\\\n\\vdots & \\ddots & \\ddots & \\ddots  & \\vdots\\\\\n0 & & 0 & -1 & 1 \\\\\n0 & \\cdots & 0 & 0 & 1\\\\\n\\end{bmatrix} \\begin{bmatrix} \\tilde{u}_1 \\\\ \\tilde{u}_2 \\\\\\tilde{u}_3\\\\ \\vdots \\\\\\tilde{u}_{N-2}\\\\\\tilde{u}_{N-1} \\end{bmatrix}.\n\\end{align*}\nTherefore,\n\\begin{align*}\nD_u=\\frac{1}{h}\\begin{bmatrix}\n1 & 0 & 0 & \\cdots & 0\\\\\n-1 & 1 & 0 & \\cdots & 0\\\\\n0 & -1 & 1 & \\cdots & 0\\\\\n\\vdots & \\ddots & \\ddots & \\ddots  & \\vdots\\\\\n0 & \\cdots & 0 & -1 & 1 \\\\\n0 & \\cdots & 0 & 0 & 1\\\\\n\\end{bmatrix}.\n\\end{align*}\nWe repeat the process now for $D_p$,\n\\begin{align*}\n\\frac{\\partial}{\\partial t}\\tilde{u}_j=\\frac{\\partial}{\\partial x}p_{j+\\frac{1}{2}}=\\frac{p_{j+1}-p_{j}}{h},\n\\end{align*}\nwhere we are only solving for the interior of $u$ which involves all the nodes of $p$ and we don't have to impose any boundary conditions. Thus, according to the previous discretization, the matrix\n\\begin{align*}\nD_p=\\frac{1}{h}\\begin{bmatrix}\n-1 & 1 & 0 & \\cdots & 0\\\\\n0 & -1 & 1 & \\cdots & 0\\\\\n\\vdots & \\ddots & \\ddots & \\ddots  & \\vdots\\\\\n0 & \\cdots & 0 & -1 & 1\n\\end{bmatrix},\n\\end{align*}\nwhich has dimension $N-1\\times N$. With this two matices and we can complete $M$ and solve the acoustic equations.\n\nThe solution is shown in the next figure, where we can see the velocity and pressure waves at different values of time.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[$t=0.5$ s.]{\\includegraphics[scale=0.6]{P4_05}}\n\\hfill\n\\subfigure[$t=1.0$ s.]{\\includegraphics[scale=0.6]{P4_1}}\n\\hspace*{\\fill}\n\n\\hspace*{\\fill}\n\\subfigure[$t=1.5$ s.]{\\includegraphics[scale=0.6]{P4_15}}\n\\hfill\n\\subfigure[$t=2.0$ s.]{\\includegraphics[scale=0.6]{P4_2}}\n\\hspace*{\\fill}\n\\caption{Solution of acoustic equations at different times.}\n\\end{figure}\n\nIn the next figure we can see the contour plot of the solutions. Note that in fact after four seconds the velocity profile is the same, allowing us to assume a period of four seconds. In the movies generated in \\textsl{Matlab} but not shown in this document we could see how the velocity and pressure waves would travel together sometimes in phase and sometimes with a phase shift of $\\pi$ radians. We can also observe this in the contours by \"superposing\" the images.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Velocity contours.]{\\includegraphics[scale=0.5]{P4_contour1.eps}}\n\\hfill\n\\subfigure[Pressure contours.]{\\includegraphics[scale=0.5]{P4_contour2.eps}}\n\\hspace*{\\fill}\n\\caption{Solution of the acoustic equations.}\n\\end{figure}\n\nFor the last part of the problem we estimate the accuracy of the solution. In the following figure we can see the initial condition and the solution after one period. Using $N=80$ the accuracy seems to be good enough. The $L_1$-norm of the difference between the two is\n\\begin{align*}\ne_{L1}=1.839686\\cdot 10^{-2}.\n\\end{align*}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{P4_periodic.eps}}\n\\caption{Comparison of the solution after 1 period, $N=80$.}\n\\end{figure}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 4\nclear all;close all;format long;clc\nlegendfontsize=14;\naxisfontsize=14;\nlabelfontsize=16;\nN = 80;\nL=2;\nh=L/N;\nxu=linspace(-1,1,N+1);\nxp=linspace(-1+h/2,1-h/2,N);\n\nDu = gallery('tridiag',N,-1,1,0); % In sparse form.\nDu(:,end)=[];\nDu=Du/h;\nDp = gallery('tridiag',N,0,-1,1); % In sparse form.\nDp(end,:)=[];\nDp=Dp/h;\nZ1 = zeros(N-1,N-1);\nZ2 = zeros(N,N);\nM = [Z1 Dp ; Du Z2];\n\n% initial condition\nu0 = exp(-32*xu.^2)';\np0 = zeros(N,1);\nv0 = [u0(2:end-1) ; p0];\n\nt = 0:0.01:4;\n\n[T,V] = ode45(@(t,v) M*v, t, v0);\nfor k = 2:length(t)\n    plot(xu(2:end-1),V(k,1:N-1)','b*-',xp,V(k,N:2*N-1)','r*-')\n    grid on\n    ylim([-1 1])\n    shg\n    drawnow\nend\n%%\n\n[T,X] = meshgrid(t,xu(2:end-1));\nfigure\ncontourf(T,X,round(V(:,2:N)',3))\nxlabel('$t$','fontsize',labelfontsize,...\n            'interpreter','latex')\nylabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_contour1';\nsaveas(gcf,txt,'epsc')\n\n[T,X] = meshgrid(t,xp);\nfigure\ncontourf(T,X,round(V(:,N:end)',3))\nxlabel('$t$','fontsize',labelfontsize,...\n            'interpreter','latex')\nylabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_contour2';\nsaveas(gcf,txt,'epsc')\n%%\nfigure\nplot(xu(2:end-1),V(find(t==0.5),1:N-1),'b*')\nhold on\nplot(xp,V(find(t==0.5),N:2*N-1),'r*')\ngrid on\naxis([-1 1 -1 1])\nxlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nlegend({'$u(0.5,x)$','$p(0.5,x)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_05';\nsaveas(gcf,txt,'epsc')\n\nfigure\nplot(xu(2:end-1),V(find(t==1),1:N-1),'b*')\nhold on\nplot(xp,V(find(t==1),N:2*N-1),'r*')\ngrid on\naxis([-1 1 -1 1])\nxlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nlegend({'$u(1,x)$','$p(1,x)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_1';\nsaveas(gcf,txt,'epsc')\n\nfigure\nplot(xu(2:end-1),V(find(t==1.5),1:N-1),'b*')\nhold on\nplot(xp,V(find(t==1.5),N:2*N-1),'r*')\ngrid on\naxis([-1 1 -1 1])\nxlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nlegend({'$u(1.5,x)$','$p(1.5,x)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_15';\nsaveas(gcf,txt,'epsc')\n\nfigure\nplot(xu(2:end-1),V(find(t==2),1:N-1),'b*')\nhold on\nplot(xp,V(find(t==2),N:2*N-1),'r*')\ngrid on\naxis([-1 1 -1 1])\nxlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nlegend({'$u(2,x)$','$p(2,x)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_2';\nsaveas(gcf,txt,'epsc')\n\n\nu4=V(length(t),1:N-1)';\nfigure\nplot(xu(2:end-1),u0(2:end-1),'b',xu(2:end-1),u4,'r*')\ngrid on\naxis([-1 1 -0.3 1.3])\nxlabel('$x$','fontsize',labelfontsize,...\n            'interpreter','latex')\nlegend({'$u(0,x)$','$u(4,x)$'},...\n        'Interpreter','latex','fontsize',legendfontsize)\nset(gca,'fontsize',axisfontsize)\ntxt='Latex/FIGURES/P4_periodic';\nsaveas(gcf,txt,'epsc')\nerr=norm(u0(2:end-1)-u4,inf)\n\\end{verbatim}", "meta": {"hexsha": "5eb50a65f8d931679ed10cea14c631afcefe79b8", "size": 10673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 3/Latex/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 3/Latex/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 3/Latex/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": 37.3181818182, "max_line_length": 526, "alphanum_fraction": 0.6527686686, "num_tokens": 3917, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8824278664544911, "lm_q1q2_score": 0.7634978473268894}}
{"text": "\\section{A very simple example - polynomial curve fitting}\\label{sec:simple}\n\\subsection{The first program in C++}\n{\\em Example file polyfit0.cpp in the directory doc/tutorial/code/polyfit.}\\\\\nLet us start with the very simple inverse problem of fitting a polynomial curve of degree $P$\n\\[ f(x) = p_0 +p_1 x + \\ldots + p_P x^P= \\sum\\limits_{i=0}^{P} p_i x^i \\]\nto some existing data $y$. The unknown model is the coefficient vector $\\m=[p_0,\\ldots,p_P]$.\nThe vectorized function for a vector $\\x=[x_1,\\ldots,x_N]^T$ can be written as matrix-vector product\n\\begin{equation}\\label{eq:yAx}\n  \\f(\\x) = \\A \\x \\quad\\mbox{with}\\quad \\A=\\left[ \\begin{array}{cccc}\n  1 & x_1 & \\ldots & x_1^P \\\\ \\vdots & \\vdots & \\ddots & \\vdots \\\\ 1 & x_N & \\ldots & x_N^P\n  \\end{array} \\right] = [ \\textbf{1}\\quad \\x \\quad \\x^2 \\ldots \\x^P ] \\quad.\n\\end{equation}\n\nWe set up the modelling operator, i.e. to return $\\f(\\x)$ for given $p_i$, as a class derived from the modelling base class. The latter holds the main mimic of generating jacobian, gradients by brute force. The only function to overwrite is \\cw{response()}.\n\n\\begin{lstlisting}[language=C++,morekeywords={RVector,ModellingBase}]\nclass FunctionModelling : public ModellingBase {\npublic:\n    /*! constructor, nc: number of coefficients, xvec: abscissae */\n    FunctionModelling( int nc, const RVector & xvec, bool verbose=false )\n        : ModellingBase( verbose ), x_( xvec ), nc_( nc ){\n        regionManager_->setParameterCount( nc ); //! instead of a mesh\n    }\n    /*! the main thing - the forward operator: returns f(x) */\n    RVector response( const RVector & par ){\n        RVector y( x_.size(), par[ 0 ] );   //!constant vector of p0\n        for ( size_t i = 1; i < nc_; i ++ ) //! p1 to pP\n            y += pow( x_, i ) * par[ i ];   //! add pi*x^i\n        return y;                           //! return sum\n    }\n    /*! define the startmodel */\n    RVector startModel( ){ return RVector( nc_, 0.5 ); }\nprotected:\n    RVector x_; //! abscissa vector x\n    int nc_; //! number of coefficients\n};\n\\end{lstlisting}\n\nIn the constructor the $\\x$ vector and the number of coefficients are saved as protected variables\\footnote{Usually all variables are denoted with an underscore and declared as protected. Instead of accessing the values directly, we use set and get functions that control the validity of the arguments.}.\nThe function \\cw{setParameterCount} setups the parameterisation as a 0d mesh of \\cw{nc} unknowns.\nThe main type used is \\cw{RVector}, a vector of real (\\cw{double}) values.\n\nWe now want to apply the function to the real inversion of data and write a main program.\n\\begin{lstlisting}[language=C++,morekeywords={RVector,RMatrix,RInversion,EXIT_SUCCESS}]\nint main( int argc, char *argv [] ){\n    int np = 1; /*! maximum polynomial degree fixed to 1 */\n    RMatrix xy; //! two-column matrix from file holding x and y\n    loadMatrixCol( xy, \"datafile.dat\" );\n    /*! initialise modelling operator */\n    FunctionModelling f( np + 1, xy[ 0 ] ); //! first data column\n    /*! initialise inversion with data and forward operator */\n    RInversion inv( xy[ 1 ], f );\n     /*! the problem is well-posed and does not need regularization */\n    inv.setLambda( 0 );\n    /*! actual inversion run yielding coefficient model */\n    RVector coeff( inv.run() );\n    /*! save coefficient vector to file */\n    save( coeff, \"out.vec\" );\n    /*! exit programm legally */\n    return EXIT_SUCCESS;\n}\n\\end{lstlisting}\n\nThe data in the two-column data file is read into a real matrix (\\lstinline|RMatrix xy;|) whose columns can be assessed by \\lstinline|xy[i]|. We initialise the forward class as defined and the inversion by specifying data and forward operator.\nThen any options of the inversion can be set, such as the regularization parameter being zero.\n\nInstead of using a fixed polynomial degree and a pre-defined file name we might specify this by the command line in order to have a user-friendly tool.\nFor this, an option map is applied reading the last argument and the optionally defined -n switch.\n\\begin{lstlisting}[language=C++,morekeywords={OptionMap,RMatrix,loadMatrixCol}]\n    int np = 1;\n    std::string datafile;\n    OptionMap oMap;\n    oMap.setDescription(\"Polyfit - fits two-column data with polynomials\");\n    oMap.addLastArg( datafile, \"Datafile\" );\n    oMap.add( np, \"n:\", \"np\", \"Number of polynomials\" );\n    oMap.parse( argc, argv );\n    RMatrix xy; \n    loadMatrixCol( xy, datafile );\n\\end{lstlisting}\n\nThe provided datafile \\verb|y_2.1x+1.1.dat| holds synthetic noisified data for a linear function.\nA call \\verb|curvefit -n1 y_2.1x+1.1.dat| yields values close to the synthetic ones.\n\n\\subsection{A first Python program}\n{\\em Example file polyfit.py in the directory doc/tutorial/code/polyfit.}\\\\\nPython is a very flexible language for programming and scripting and has many packages for numerical computing and graphical visualization.\nFor this reason, we built Python bindings and compiled the library pygimli.\nAs a main advantage, all classes can be used and derived.\nThis makes the use of GIMLi very easy for non-programmers.\nAll existing modelling classes can be used, but it is also easy to create new modelling classes.\n\nWe exemplify this by the preceding example.\nFirst, the library must be imported.\nTo avoid name clashes with other libraries we suggest to import it to an easy name, e.g. by using \\lstinline|import pygimli as pg|.\nAs a result, all gimli objects (classes and functions) can be referred to with a preceding \\lstinline|pg.|, e.g. \\lstinline|pg.RVector| is the real vector \\lstinline|RVector|.\nNext, the modelling class is derived from ModellingBase, a constructor is defined and the response function is defined.\n\\begin{lstlisting}[language=python]\nimport pygimli as pg\nclass FunctionModelling( pg.ModellingBase ):\n    # constructor\n    def __init__( self, nc, xvec, verbose = False  ):\n        pg.ModellingBase.__init__( self, verbose )\n        self.x_ = xvec\n        self.nc_ = nc\n        self.regionManager().setParameterCount( nc )\n    # response function\n    def response( self, par ):\n        y = pg.RVector( self.x_.size(), par[ 0 ] )\n        for i in range( 1, self.nc_ + 1 ):\n            y += pg.pow( self.x_, i ) * par[ i ];\n        return y;\n    # start model\n    def startModel( self ):\n        return pg.RVector( self.nc_, 0.5 )\n\\end{lstlisting}\n\nThe pygimli library must once be imported (in this case under the name g) and all classes (e.g. modelling operators) can be used by pg.classname, e.g. pg.RVector is the already known vector of real (double) values.\n\nThe main program is very easy then and the code is very similar to C++.\nData are loaded, both forward operator and inversion are created.\nInversion options are set and it the result of run is save to a file.\nThat's it.\n\n\\begin{lstlisting}[language=python]\n    xy = pg.RMatrix()\n    pg.loadMatrixCol( xy, datafile );\n    # two coefficients and x-vector (first data column)\n    f = FunctionModelling( options.np + 1, xy[ 0 ] )\n    # initialize inversion with data and forward operator and set options\n    inv = pg.RInversion( xy[ 1 ], f );\n    # constant absolute error of 0.01 (not necessary, only for chi^2)\n    inv.setAbsoluteError( 0.01 );\n    # the problem is well-posed and does not need regularization\n    inv.setLambda( 0 );\n    # actual inversion run yielding coefficient model\n    coeff = inv.run();\n    pg.save( coeff, \"out.vec\" );\n\\end{lstlisting}\n\nAs a main advantage of Python, the actual computations can be easily combined with post-processing or visualization, even building graphical user-interfaces. \nIn this code example we use matplotlib, a plotting library inside of pylab, a compound of different routines for numerics and plotting, very much comparable to MatLab.\n\n\\begin{lstlisting}[language=python]\nimport pylab as P\nP.plot( xy[0], xy[1], 'rx', xy[0], inv.response(), 'b-' )\nP.show()\n\\end{lstlisting}\n\nSimilar to C++, command line options can be parsed using the class OptionParser, see the code file.\nThe output is illustrated for two a synthetic function $y=2.1x+1.1$ noisified with Gaussian noise for two different orders in Figure \\ref{fig:polyfit}.\n\n\\begin{figure}[hbt]%\n\\includegraphics[width=0.5\\columnwidth]{polyfit-n1}\\hfill\n\\includegraphics[width=0.5\\columnwidth]{polyfit-n3}%\n\\caption{Polynomial fit for noisified synthetic data using first order (left) and third order (right) polynomials.}%\n\\label{fig:polyfit}%\n\\end{figure}\n\nIn the following we continue the description with C++ but all are provided as well in Python without significant code changes.\nMain exception is the non-existence of declarations, e.g. the C++ declaration \\lstinline|GIMLi::RTransLogLU mytrans( lower, upper );| in Python would be written \\lstinline|mytrans = pg.RTransLogLU( lower, upper)|.\nWhereas it is common to work in name spaces in C++, in python function conflicts easily appear due to lack of declaration.\nTo avoid that, we recommend importing modules as such, e.g. \\lstinline|import pylab as P| and \\lstinline|import pygimli as g|.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{An own Jacobian}\n{\\em Example file polyfit1.cpp in the directory doc/tutorial/code/polyfit.}\\\\\nFor the latter example, the underlying Gauss-Newton scheme creates a Jacobian matrix by brute force (perturbation).\nIf we want to apply an own algorithm we overwrite the function createJacobian() in the modelling class by using the matrix $\\A$ from (\\ref{eq:yAx}):\n\\begin{lstlisting}[language=C++,morekeywords={RMatrix,RVector,size_t}]\n    void createJacobian( RMatrix & jacobian, const RVector & model ) {\n        jacobian.resize( x_.size(), nc_ );\n        for ( size_t i = 0 ; i < nc_ ; i++ )\n            for ( size_t j = 0 ; j < x_.size() ; j++ )\n                jacobian[ j ][ i ] = pow( x_[ j ], i );\n    }\n\\end{lstlisting}\n\nThe result of the inversion is of course the same as before.\nNote that the resize function checks for the right size and allocates space if necessary.\n\nAlternatively we might to use other minimisation methods even though it is not necessary for this example.\n\\sperre (Steepest descent, NLCG, Quasi-Newton)\n\nNote that \\lstinline|RInversion| is an instance of the template class \\lstinline|Inversion< ValueType >| with the value type \\lstinline|double| and the matrix type \\lstinline|RMatrix|\\footnote{RMatrix is a full matrix of real (double) values.}.\nOne can, of course, use other types, e.g. float-precision or a complex vector \\lstinline|CVector|.\nIn the latter case, the appropriate matrix type \\lstinline|CMatrix| should be used in the forward class. \nFor other problems sparse Jacobian matrices or block matrices are more efficient.\nSee also the appendix \\ref{app:matrix} for matrix types.\n%For other problems the Jacobian matrix has only few entries and can be approximated by a sparse matrix.\n%Therefore the matrix type \\lstinline|RSparseMapMatrix| exists, which is itself an instance of a template type with \\lstinline|long int| index and double values. \n%See also the appendix \\ref{app:matrix} for matrix types.\n", "meta": {"hexsha": "d84c2454c796e3ac931d88b1cf61230b0e30861c", "size": 11063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tutorial/firstexample.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/firstexample.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/firstexample.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": 57.6197916667, "max_line_length": 304, "alphanum_fraction": 0.7135496701, "num_tokens": 2863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7634301495868169}}
{"text": "%\n% Chapter 4.3\n%\n\n\\section*{4.3 Fundamental Theorem of Calculus}\n\n\\subsection*{FTC Part 1}\n\nIf \\(f\\) is continuous on \\([a, b]\\), then the function \\(g\\) defined by \n$$ g(x) = \\int_a^x f(t)dt \\quad a \\leq x \\leq b $$\nis continuous on \\([a, b]\\) and differentiable on \\((a, b)\\), and \\(g'(x)=f(x)\\).\n\n\\subsection*{FTC Part 2}\n\nIf \\(f\\) is continuous on \\([a, b]\\), then \n$$ \\int_a^b f(x)dx = F(b)- F(a) $$\nwhere \\(F\\) is any antiderivative of \\(f\\), that is, a function \\(F\\) such that \\(F'=f\\).\n", "meta": {"hexsha": "e52c5b2d882192c37e816dc065b573c19fcd4c55", "size": 496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4-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/4-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/4-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": 27.5555555556, "max_line_length": 89, "alphanum_fraction": 0.5766129032, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7633884731260937}}
{"text": "\\subsubsection{Electric Fields}\r\n\\noindent\r\nGauss's Law of Electricity is an important application of Divergence Theorem in physics. It says that $\\Phi_{E} = \\frac{Q_{in}}{\\epsilon_{0}}$. That is, the electric flux through a closed surface (real or hypothetical) is proportional to the charge contained within that surface. Rewritten more formally, \r\n\\begin{equation*}\r\n\t\\oint\\limits_{S}\\oint{\\vec{E} \\cdot \\mathrm{d}\\vec{s}} = \\iiint\\limits_{V}{\\frac{Q_{in}}{\\epsilon_{0}}\\mathrm{d}V}.\r\n\\end{equation*}\r\nSo, \r\n\\begin{equation*}\r\n\t\\iiint\\limits_{V}{\\nabla\\cdot\\vec{E}\\mathrm{d}V} = \\iiint\\limits_{V}{\\frac{\\sigma}{\\epsilon_{0}}\\mathrm{d}V}\r\n\\end{equation*}\r\nwhere $\\sigma$ is the charge density.\r\nIf we let $V \\to 0$, \r\n\\begin{equation*}\r\n\t\\nabla \\cdot \\vec{E} = \\frac{\\sigma}{\\epsilon_{0}}.\r\n\\end{equation*}\r\nThis is the differential form of Gauss's Law and the 1st of Maxwell's Equations.", "meta": {"hexsha": "a2ab058becb1b506ff1600a089931fdda8b59d61", "size": 890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/electricFields.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/electricFields.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/electricFields.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 55.625, "max_line_length": 306, "alphanum_fraction": 0.704494382, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765187126079, "lm_q2_score": 0.8354835452961425, "lm_q1q2_score": 0.763361697107847}}
{"text": "\\section{Geometric view of systems of equations}\n\\label{sec:systems-geometric}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Relate the types of solution sets of a system of two (three)\n    variables to the intersections of lines in a plane (the\n    intersection of planes in $3$-dimensional space)\n  \\end{enumerate}\n\\end{outcome}\n\nAs you may remember, linear equations like $2x+3y=6$ can be graphed as\nstraight lines in the coordinate plane. We say that this equation is\nin two variables, in this case $x$ and $y$.  Suppose you have two such\nequations, each of which can be graphed as a straight line, and consider\nthe resulting graph of two lines. What would it mean if there exists a\npoint of intersection between the two lines? This point, which lies on\n{\\em both} graphs, gives $x$ and $y$ values for which both\nequations are true. In other words, this point gives the ordered pair\n($x,y$) that satisfies both equations.  If the point $(x, y\n)$ is a point of intersection, we say that $(x, y)$\nis a \\textbf{solution} to the two equations. In linear algebra, we\noften are concerned with finding the solution(s) to a system of\nequations, if such solutions exist.  First, we consider graphical\nrepresentations of solutions and later we will consider the algebraic\nmethods for finding solutions.\n\nWhen looking for the intersection of two lines in the plane, several\nsituations may arise. The following picture demonstrates the possible\nsituations when considering two equations (two lines in the plane)\ninvolving two variables.\n\\begin{equation*}\n  \\begin{tikzpicture}[scale=0.9]\n    \\draw[thick, <->](0,2)--(0,0)--(2,0);\n    \\draw[thick, red](0,1.5)--(1.5,0);\n    \\draw[thick, blue](0,0)--(1.5,1.5);\n    \\draw[fill, purple](0.75,0.75) circle [radius=2pt];\n    \\node[below right] at (2,0){$x$};\n    \\node[left] at (0,2){$y$};\n    \\node[below] at (1,-0.5){One solution};\n\n    \\draw[thick, <->](5,2)--(5,0)--(7,0);\n    \\draw[thick, red](5,0.5)--(6.5, 1.5);\n    \\draw[thick, blue](5,0)--(6.5,1);\n    \\node[below right] at (7,0){$x$};\n    \\node[left] at (5,2){$y$};\n    \\node[below] at (6,-0.5){No solutions};\n\n    \\draw[thick, <->](10,2)--(10,0)--(12,0);\n    \\draw[thick, purple](10,0)--(11.5, 1.5);\n    \\node[below right] at (12,0){$x$};\n    \\node[left] at (10,2){$y$};\n    \\node[below] at (12,-0.5){Infinitely many solutions};\n  \\end{tikzpicture}\n\\end{equation*}\nIn the first diagram, there is a unique point of intersection, which\nmeans that there is only one (unique) solution to the two equations.\nIn the second, there are no points of intersection and no\nsolution. There is no solution because the two lines are parallel and\nthey never intersect.  The third situation that can occur, as\ndemonstrated in diagram three, is that the two lines are really the\nsame line. For example, $x+y=1$ and $2x+2y=2$ are two equations that\nyield the same line when graphed. In this case there are infinitely\nmany points that are solutions of these two equations, as every\nordered pair which is on the graph of the line satisfies both\nequations.\n\nWhen considering linear systems of equations, there are always three\npossibilities for the number of solutions: there is exactly one\nsolution, there are infinitely many solutions, or there is no\nsolution.  When we speak of {\\em solving} a system of equations, we\nusually mean finding {\\em all} of its solutions. This can mean finding\none solution (if the solution is unique), finding infinitely many\nsolutions, or finding that there is no solution.\n\n\\begin{example}{A graphical solution}{graphical-solution}\n  Use a graph to solve the following system of equations:\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x+y&=&3 \\\\\n      y-x&=&5.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  Through graphing the above equations and identifying the point of\n  intersection, we can find the solution(s). Remember that we must\n  have either one solution, infinitely many, or no solutions at all.\n  The following graph shows the two equations, as well as the\n  intersection. Remember, the point of intersection represents the\n  solution of the two equations, or the $(x,y)$ which satisfy both\n  equations. In this case, there is one point of intersection at\n  $(-1, 4)$ which means we have one unique solution, $x = -1$,\n  $y = 4$.\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.75]\n      \\draw[thick, ->](-4.5,0) -- (2.5,0);\n      \\draw[thick, ->](0,-1) -- (0,7);\n      \\draw(-4,-0.2) -- (-4,0.2);\n      \\draw(-3,-0.2) -- (-3,0.2);\n      \\draw(-2,-0.2) -- (-2,0.2);\n      \\draw(-1,-0.2) -- (-1,0.2);\n      \\draw(1,-0.2) -- (1,0.2);\n      \\draw(-0.2,1) -- (0.2,1);\n      \\draw(-0.2,2) -- (0.2,2);\n      \\draw(-0.2,4) -- (0.2,4);\n      \\draw(-0.2,6) -- (0.2,6);\n      \\draw[green!60!black, ultra thick, domain=-3.5:2] plot (\\x, {3-\\x});\n      \\draw[blue, ultra thick, domain=-3.5:2] plot (\\x, {\\x+5});\n      \\node[right] at (1.2,2){$x+y=3$};\n      \\node[right] at (1.2,6){$y-x=5$};\n      \\draw[help lines,dashed](-1,0)--(-1,4)--(0,4);\n      \\node[below] at (-4,-0.5){$-4$};\n      \\node[below] at (-3,-0.5){$-3$};\n      \\node[below] at (-2,-0.5){$-2$};\n      \\node[below] at (-1,-0.5){$-1$};\n      \\node[below] at (1,-0.5){$1$};\n      \\node[left] at (-0.25,1){$1$};\n      \\node[left] at (-0.25,2){$2$};\n      \\node[left] at (-0.25,3){$3$};\n      \\node[left] at (-0.25,4){$4$};\n      \\node[left] at (-0.25,5){$5$};\n      \\node[left] at (-0.25,6){$6$};\n      \\node[below right] at (2,0){$x$};\n      \\node[left] at (0,7){$y$};\n      \\node[left=1ex] at (-1,4){$(x,y) = (-1,4)$};\n    \\end{tikzpicture}\n    \\vspace{-2ex}\n  \\end{center}\n\\end{solution}\n\nIn the above example, we investigated the intersection point of two\nequations in two variables, $x$ and $y$. Now we will consider the\ngraphical solutions of three equations in two variables.\n\nConsider a system of three equations in two variables. Again, these\nequations can be graphed as straight lines in the plane, so that the\nresulting graph contains three straight lines. Recall the three\npossibilities for the number of solutions: no solution, one solution,\nand infinitely many solutions.  With three lines, there are more\ncomplex ways of achieving these situations. For example, you can\nimagine the case of three intersecting lines having no common point of\nintersection. Perhaps you can also imagine three intersecting lines\nwhich do intersect at a single point. These two situations are\nillustrated below.\n\n\\begin{center}\n  \\begin{tikzpicture}\n    \\draw[thick, <->](0,2)--(0,0)--(2,0);\n    \\draw[thick, green!60!black](0,1.5)--(1.5,0);\n    \\draw[thick, blue](0,0)--(1.5,1.5);\n    \\draw[thick, red](0.5,0)--(0.5,1.5);\n    \\node[below right] at (2,0){$x$};\n    \\node[left] at (0,2){$y$};\n    \\node[below] at (1,-0.5){No solution};\n\n    \\draw[thick, <->](5,2)--(5,0)--(7,0);\n    \\draw[thick, green!60!black](5,1.5)--(6.5,0);\n    \\draw[thick, blue](5,0)--(6.5,1.5);\n    \\draw[thick, red](5.75,0)--(5.75,1.5);\n    \\draw[fill](5.75,0.75) circle [radius=2pt];\n    \\node[below right] at (7,0){$x$};\n    \\node[left] at (5,2){$y$};\n    \\node[below] at (6,-0.5){One solution};\n  \\end{tikzpicture}\n\\end{center}\n\nConsider the first picture above. While all three lines intersect with\none another, there is no common point of intersection where all three\nlines meet at one point. Hence, there is no solution to the three\nequations. Remember, a solution is a point $(x, y)$ which satisfies\n\\textbf{all} three equations.  In the case of the second picture, the\nlines intersect at a common point. This means that there is one\nsolution to the three equations whose graphs are the given lines.  You\nshould take a moment now to draw the graph of a system which results\nin three parallel lines. Next, try the graph of three identical lines.\nWhich type of solution is represented in each of these graphs?\n\nWe have now considered the graphical solutions of systems of two\nequations in two variables, as well as three equations in two\nvariables. However, there is no reason to limit our investigation to\nequations in two variables. We will now consider equations in three\nvariables.\n\nYou may recall that equations in three variables, such as\n$2x+4y-5z=8$, form a plane. Above, we were looking for intersections\nof lines in order to identify any possible solutions. When graphically\nsolving systems of equations in three variables, we look for\nintersections of planes. These points of intersection give the\n$(x, y, z)$ that satisfy all the equations in the system.  What types\nof solutions are possible when working with three variables?  Consider\nthe following picture involving two planes, which are given by two\nequations in three variables.\n\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.6,z={(-0.55,-0.45)}]\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (-3,0,2) -- (-3,0,-4) -- cycle;\n    \\draw[fill=blue!25] (0,0,-4) -- (1.5,-2,-4) -- (1.5,-2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (3,0,2) -- (3,0,-4) -- cycle;\n    \\draw[fill=blue!25] (0,0,-4) -- (-1.5,2,-4) -- (-1.5,2,2) -- (0,0,2) -- cycle;\n  \\end{tikzpicture}\n\\end{center}\n\nNotice how these two planes intersect in a line. This means that the\npoints $(x,y,z)$ on this line satisfy both equations in the\nsystem. Since the line contains infinitely many points, this system\nhas infinitely many solutions.\n\nIt could also happen that the two planes fail to intersect. However,\nis it possible to have two planes intersect at a single point? Take a\nmoment to attempt drawing this situation, and convince yourself that\nit is not possible! This means that when we have only two equations in\nthree variables, there is no way to have a unique solution! Hence, the\nonly possibilities for the number of solutions of two equations in\nthree variables are no solution or infinitely many solutions.\n\nNow imagine adding a third plane. In other words, consider three equations in three variables. What types of solutions are now possible? Consider the following diagram.\n\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.6,z={(-0.55,-0.45)}]\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (-3,0,2) -- (-3,0,-4) -- cycle;\n    \\draw[fill=red!25] (-0.75,1,-4) -- (-0.75,1,2) -- (-2.5,1,2) -- (-2.5,1,-4) -- cycle;\n    \\draw[fill=blue!30] (0,0,-4) -- (1.5,-2,-4) -- (1.5,-2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (3,0,2) -- (3,0,-4) -- cycle;\n    \\draw[fill=blue!30] (0,0,-4) -- (-1.5,2,-4) -- (-1.5,2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=red!25] (0.75,1,-4) -- (0.75,1,2) -- (-0.75,1,2) -- (-0.75,1,-4) -- cycle;\n  \\end{tikzpicture}\n\\end{center}\n\nIn this diagram, there is no point which lies in all three\nplanes. There is no intersection between \\textbf{all} three planes so\nthere is no solution. The picture illustrates the situation in which\nthe line of intersection of the new plane with one of the original\nplanes forms a line parallel to the line of intersection of the first\ntwo planes. However, in three dimensions, it is possible for two lines\nto fail to intersect even though they are not parallel. Such lines are\ncalled \\textbf{skew lines}%\n\\index{skew lines}.\n\nRecall that when working with two equations in three variables, it was\nnot possible to have a unique solution. Is it possible when\nconsidering three equations in three variables? In fact, it is\npossible, and we demonstrate this situation in the following picture.\n\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.6,z={(-0.55,-0.45)}]\n    \\draw[fill=blue!10] (0,0,0) -- (0,0,-4) -- (-3,0,-4) -- (-3,0,0) -- cycle;\n    \\draw[fill=blue!30] (0,0,0) -- (1.5,-2,0) -- (1.5,-2,-4) -- (0,0,-4) -- cycle;\n    \\draw[fill=blue!10] (0,0,0) -- (0,0,-4) -- (3,0,-4) -- (3,0,0) -- cycle;\n    \\draw[fill=blue!30] (0,0,0) -- (-1.5,2,0) -- (-1.5,2,-4) -- (0,0,-4) -- cycle;\n    \\draw[fill=red!25] (-3,0,0) -- (3,0,0) -- (3,-2,0) -- (-3,-2,0) -- cycle;\n    \\draw[fill=blue!10] (0,0,0) -- (0,0,2) -- (-3,0,2) -- (-3,0,0) -- cycle;\n    \\draw[fill=blue!30] (0,0,0) -- (1.5,-2,0) -- (1.5,-2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=blue!10] (0,0,0) -- (0,0,2) -- (3,0,2) -- (3,0,0) -- cycle;\n    \\draw[fill=red!25] (-3,0,0) -- (3,0,0) -- (3,2,0) -- (-3,2,0) -- cycle;\n    \\draw[fill=blue!30] (0,0,0) -- (-1.5,2,0) -- (-1.5,2,2) -- (0,0,2) -- cycle;\n  \\end{tikzpicture}\n\\end{center}\n\nIn this case, the three planes have a single point of intersection.\nCan you think of other possibilities? Another is that the three planes\ncould intersect in a line, resulting in infinitely many solutions, as\nin the following diagram.\n\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.6,z={(-0.55,-0.45)}]\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (-3,0,2) -- (-3,0,-4) -- cycle;\n    \\draw[fill=red!25] (-1.5,-2,-4) -- (-1.5,-2,2) -- (0,0,2) -- (0,0,-4) -- cycle;\n    \\draw[fill=blue!30] (0,0,-4) -- (1.5,-2,-4) -- (1.5,-2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=blue!10] (0,0,-4) -- (0,0,2) -- (3,0,2) -- (3,0,-4) -- cycle;\n    \\draw[fill=blue!30] (0,0,-4) -- (-1.5,2,-4) -- (-1.5,2,2) -- (0,0,2) -- cycle;\n    \\draw[fill=red!25] (1.5,2,-4) -- (1.5,2,2) -- (0,0,2) -- (0,0,-4) -- cycle;\n  \\end{tikzpicture}\n\\end{center}\n\nWe have now seen how three equations in three variables can have no\nsolution, a unique solution, or intersect in a line resulting in\ninfinitely many solutions.  It is also possible that all three\nequations describe the same plane, which also leads to infinitely many\nsolutions.\n\nYou can see that when working with equations in three variables, there\nare many more possibilities for achieving solutions (or no solutions)\nthan when working with two variables. It may prove enlightening to\nspend time imagining (and drawing) many possible scenarios, and you\nshould take some time to try a few.\n\nYou should also take some time to imagine (and draw) graphs of systems\nin more than three variables.  Equations like $x+y-2z+4w=8$ with more\nthan three variables are often called \\textbf{hyperplanes}%\n\\index{hyperplane}%\n\\index{plane!hyperplane}.  You may soon realize that it is tricky to\ndraw the graphs of hyperplanes! In fact, most people cannot visualize\nmore than three dimensions. Fortunately, through the tools of linear\nalgebra, we can examine systems of equations in four variables, five\nvariables, or even hundreds or thousands of variables, without ever\nneeding to graph them. Instead we will use {\\em algebra} to manipulate\nand solve these systems of equations. We will introduce these\nalgebraic tools in the following sections.\n", "meta": {"hexsha": "c94cef837ccc3fcab4a658821cd07d81a3c1a99c", "size": 14369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/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/content/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/content/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": 47.7375415282, "max_line_length": 168, "alphanum_fraction": 0.6633725381, "num_tokens": 4798, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891392358014, "lm_q2_score": 0.9284087951081423, "lm_q1q2_score": 0.7633276281089111}}
{"text": "\n\n\\subsection{Disks}\n\nWe defined an open disk at \\((a,b)\\) of radius \\(r\\) as:\n\n\\(\\{(x,y)\\in \\mathbb R^2:(x-a)^2+(y-b)^2 < r^2\\}\\)\n\nFor a closed disk it is:\n\n\\(\\{(x,y)\\in \\mathbb R^2:(x-a)^2+(y-b)^2 \\le r^2\\}\\)\n\n\\subsection{Annulus}\n\nAn annulus is a disk, which excludes a smaller disk inside the disk\n\n\\subsection{Punctured disk}\n\nIf the interior disk is just a point, it is a punctured disk.\n\n", "meta": {"hexsha": "c9f8badd98a4e3676a0c84b62f05b0dbf85f9b10", "size": 395, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/complex/03-04-annulus.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/complex/03-04-annulus.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/complex/03-04-annulus.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.8095238095, "max_line_length": 67, "alphanum_fraction": 0.6329113924, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284087926320944, "lm_q2_score": 0.8221891261650247, "lm_q1q2_score": 0.7633276139381073}}
{"text": "\\section*{Problem 3: Ridge Regression [40 pts] (Hyun-Ah \\& Petar)}\n\n\\subsection* {3.1 MLE (Petar)}\n\n\n% \\subsection*{Problem 1: MLE [10 pts]}\n\n% \\textbf{NOTE: Do not submit your code for this portion of the assignment, submit the plots only.  Plots should be submitted with the rest of the assignment in Gradescope.}\n\nWe are given covariates $\\mathbf{X} \\in \\mathbb{R}^{n \\times d}$ and responses $\\mathbf{y} \\in \\mathbb{R}^{n \\times 1}$, such that: \n\\begin{align}   \n        \\mathbf{y} = \\mathbf{X}\\mathbf{\\beta} + \\mathbf{\\epsilon} \n\\end{align} \nwhere $\\mathbf{\\beta} \\in \\mathbb{R}^{{\\color{red}d} \\times 1}$ is a vector of predictors and $\\mathbf{\\epsilon}$ a vector of Gaussian noise components given by: $\\epsilon_i \\sim \\mathcal{N}(0, \\sigma^2)$. \\\\ \\\\\na) Derive the conditional probability $p(y_i | \\mathbf{x_i}, \\mathbf{\\beta}, {\\color{red}\\sigma})$, where $y_i$ is the $i$-th component of $\\mathbf{y}$,  and $\\mathbf{x_i}$ is the $i$-th row of $\\mathbf{X}$. \\\\ \\\\ \nb) Assume we have $n$ i.i.d samples. Derive the log-likelihood of the data $\\ell(\\mathbf{y} | \\mathbf{\\beta})$. \\\\ \\\\ \nc) Show that maximizing the log-likelihood is equivalent to the following criterion: \n\\begin{align} \n    \\min_{\\mathbf{\\beta}} ||\\mathbf{y} - \\mathbf{X}\\mathbf{\\beta}||_2^2 \n\\end{align}\nd) Derive the MLE $\\hat{\\mathbf{\\beta}}$.\n\n\nWe have worked through the linear regression problem. Now, we will explore linear regression problem with regularization.\n\n\\subsection*{3.2 Ridge regression}\nContinued from Problem 1, we are given a matrix of $n$ training samples with $p$ dimensions, $\\mathbf{X}\\in \\mathbb{R}^{n \\times p}$, a parameter vector $\\mathbf{\\beta}\\in\\mathbb{R}^{p}$, and a output vector $\\mathbf{y}\\in\\mathbb{R}^{n}$.\nL2 penalized linear regression problem shown below penalizes the L2 norm of the parameter vector. This is also known as the ridge regression problem.\n\\begin{align*} \n    \\min_{\\mathbf{\\beta}} \\frac{1}{2}||\\mathbf{y} - \\mathbf{X}\\mathbf{\\beta}||_2^2 + \\frac{\\lambda}{2} ||\\mathbf{\\beta}||_2^2\n\\end{align*}\n\na) Show that the solution to the ridge regression problem is $\\beta^*= (\\mathbf{X}^T\\mathbf{X} +\\lambda \\mathbf{I})^{-1}\\mathbf{X}^T\\mathbf{y}$.\n\nb) How does the solution differ from the solution to the ordinary linear regression problem? Explain how the solution changes as $\\lambda \\rightarrow 0$, and $\\lambda \\rightarrow \\infty$.\n\n\\newpage\n\n", "meta": {"hexsha": "0efe259d6dccf8fec8b18de9fcb155d336dd6a23", "size": 2371, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem3.tex", "max_stars_repo_name": "DylanFrank/Learn", "max_stars_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-24T09:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T12:55:26.000Z", "max_issues_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem3.tex", "max_issues_repo_name": "DylanFrank/Learn", "max_issues_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "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": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem3.tex", "max_forks_repo_name": "DylanFrank/Learn", "max_forks_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-10T02:18:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T07:45:23.000Z", "avg_line_length": 60.7948717949, "max_line_length": 238, "alphanum_fraction": 0.6878954028, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8152324983301568, "lm_q2_score": 0.936285002192296, "lm_q1q2_score": 0.7632899614862818}}
{"text": "\\subsection{Hausdorff distance}\\label{subsec:hausdorff_distance}\n\nLet \\( (X, \\mu) \\) be a \\hyperref[def:complete_metric_space]{complete metric space}.\n\n\\begin{definition}\\label{def:hausdorff_distance}\\mcite[144]{DontchevRockafellar2014}\n  Fix two sets \\( E \\subseteq X \\) and \\( F \\subseteq X \\).\n\n  The \\term{excess} of \\( E \\) beyond \\( F \\) is defined as\n  \\begin{balign*}\n     & e: \\pow X \\times \\pow X \\to \\BbbR \\cup \\{ \\infty \\} \\\\\n     & e(E, F) \\coloneqq \\begin{cases}\n      +\\infty,                                                                                    & E = \\varnothing, D = \\varnothing                      \\\\\n      0,                                                                                          & E = \\varnothing, D \\neq \\varnothing                   \\\\\n      \\sup_{x \\in E} \\op{dist}(x, F) \\reloset{*}{=} \\inf \\{\\delta > 0 \\colon E \\subseteq F_\\delta \\}, & E \\neq \\varnothing \\nonumber\\refstepcounter{equation}\n    \\end{cases}\n  \\end{balign*}\n  where \\( F_\\delta \\coloneqq \\{ y \\in X \\colon \\op{dist}(y, F) \\leq \\delta \\} \\).\n\n  The \\term{Pompeiu-Hausdorff distance} or simply \\term{Hausdorff} distance between them is then defined as\n  \\begin{equation*}\n    h(E, F) \\coloneqq \\max\\{ e(E, F), e(F, E) \\} = \\inf \\{\\delta > 0 \\colon E \\subseteq F_\\delta, F \\subseteq E_\\delta \\}.\n  \\end{equation*}\n\\end{definition}\n\\begin{proof}(of the equality \\( * \\))\n  Note that the set\n  \\begin{equation*}\n    F_{e(E, F)} = \\{ x \\in X \\colon \\op{dist}(x, F) \\leq \\sup_{x \\in E} \\op{dist}(x, F) \\}\n  \\end{equation*}\n  obviously includes \\( E \\).\n\n  Now let \\( \\delta > 0 \\) be any real number that satisfies \\( E \\subseteq F_\\delta \\), i.e.\n  \\begin{equation*}\n    E \\subseteq F_\\delta = \\{ x \\in X \\colon \\op{dist}(x, F) \\leq \\delta \\},\n  \\end{equation*}\n  which implies that\n  \\begin{equation*}\n    e(E, F) = \\sup_{x \\in E} \\op{dist}(x, F) \\leq \\delta.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{proposition}\\label{thm:hausdorff_distance_is_metric}\n  The Hausdorff distance is a metric on the nonempty compact subsets of \\( X \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( E \\), \\( F \\) and \\( G \\) be nonempty compact subsets of \\( X \\).\n\n  The function \\( h \\) is nonnegative. Since we exclude empty and unbounded sets, We do not care about infinite values.\n\n  \\SubProofOf{def:metric_space/M1} Obviously \\( h(E, E) = 0 \\). If \\( h(E, F) = 0 \\), then there exists no point of \\( E \\) outside \\( F \\) and vice versa, hence \\( E = F \\).\n\n  \\SubProofOf{def:metric_space/M2} This follows from the symmetry of the \\( \\max \\) function.\n\n  \\SubProofOf{def:metric_space/M3} For any point \\( y \\in X \\), we have\n  \\begin{balign*}\n    \\op{dist}(x, G)\n    =\n    \\inf_{z \\in G} \\mu(x, z)\n    \\leq\n    \\mu(x, y) + \\inf_{y \\in G} \\mu(y, z)\n    =\n    \\mu(x, y) + \\op{dist}(y, G).\n  \\end{balign*}\n\n  Select \\( y \\in F \\) that minimizes the distance \\( \\mu(x, y) \\) over \\( F \\) (compactness allows us), so that \\todo{Prove \\hyperref[thm:weierstrass_extreme_value_theorem]{Weierstrass' theorem}}\n  \\begin{balign*}\n    \\op{dist}(x, G)\n    \\leq\n    \\mu(x, y) + \\op{dist}(y, G)\n    =\n    \\op{dist}(x, F) + \\op{dist}(y, G)\n    \\leq\n    \\op{dist}(x, F) + e(F, G).\n  \\end{balign*}\n\n  It now follows that\n  \\begin{balign*}\n    e(E, G)\n     & =\n    \\inf \\{\\delta > 0 \\colon E \\subseteq G_\\delta \\}\n    =    \\\\ &=\n    \\inf \\{\\delta > 0 \\colon E \\subseteq \\{ x \\in X \\colon \\op{dist}(x, G) \\leq \\delta \\}\n    \\leq \\\\ &\\leq\n    \\inf \\{\\delta > 0 \\colon E \\subseteq \\{ x \\in X \\colon \\op{dist}(x, F) + e(F, G) \\leq \\delta, y \\in X \\}\n    =    \\\\ &=\n    e(F, G) + \\inf \\{\\delta > 0 \\colon E \\subseteq F_\\delta \\}\n    =    \\\\ &=\n    e(F, G) + e(E, F).\n  \\end{balign*}\n\\end{proof}\n", "meta": {"hexsha": "5842a3170cc72a19694597ca6abd77b4ba939288", "size": 3668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/hausdorff_distance.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/hausdorff_distance.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/hausdorff_distance.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": 40.7555555556, "max_line_length": 196, "alphanum_fraction": 0.5501635769, "num_tokens": 1328, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805823, "lm_q2_score": 0.8633916205190225, "lm_q1q2_score": 0.7632721001558068}}
{"text": "%!TEX root = ../thesis.tex\n\n\\chapter{The title of chapter two}\n\n\nThe integers, along with the two operations of addition and\nmultiplication, form the prototypical example of a ring.  In\nmathematics, a ring is one of the fundamental algebraic structures\nused in abstract algebra. It consists of a set equipped with two\nbinary operations that generalize the arithmetic operations of\naddition and multiplication. Through this generalization, theorems\nfrom arithmetic are extended to non-numerical objects such as\npolynomials, series, matrices and functions.\n\nA ring is an abelian group with a second binary operation that is\nassociative, is distributive over the abelian group operation, and has\nan identity element (this last property is not required by some\nauthors, see § Notes on the definition). By extension from the\nintegers, the abelian group operation is called addition and the\nsecond binary operation is called multiplication.\n\nWhether a ring is commutative or not (that is, whether the order in which two elements are multiplied changes the result or not) has profound implications on its behavior as an abstract object. As a result, commutative ring theory, commonly known as commutative algebra, is a key topic in ring theory. Its development has been greatly influenced by problems and ideas occurring naturally in algebraic number theory and algebraic geometry. Examples of commutative rings include the set of integers equipped with the addition and multiplication operations, the set of polynomials equipped with their addition and multiplication, the coordinate ring of an affine algebraic variety, and the ring of integers of a number field. Examples of noncommutative rings include the ring of \\(n \\times n\\) real square matrices with \\(n \\geq 2\\), group rings in representation theory, operator algebras in functional analysis, rings of differential operators in the theory of differential operators, and the cohomology ring of a topological space in topology.", "meta": {"hexsha": "58adc343127de6ee40dd24e2c19168d9fe80adf5", "size": 1979, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/chapter2.tex", "max_stars_repo_name": "rdholkar/math-thesis-template-master", "max_stars_repo_head_hexsha": "a5a3cf85144bdfd8dd9cffbfb1c235d51b7ae28e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapters/chapter2.tex", "max_issues_repo_name": "rdholkar/math-thesis-template-master", "max_issues_repo_head_hexsha": "a5a3cf85144bdfd8dd9cffbfb1c235d51b7ae28e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapters/chapter2.tex", "max_forks_repo_name": "rdholkar/math-thesis-template-master", "max_forks_repo_head_hexsha": "a5a3cf85144bdfd8dd9cffbfb1c235d51b7ae28e", "max_forks_repo_licenses": ["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.9545454545, "max_line_length": 1043, "alphanum_fraction": 0.8160687216, "num_tokens": 403, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8376199552262967, "lm_q1q2_score": 0.7632223119437884}}
{"text": "In this problem we start by plotting the lagrange polynomials\n\\begin{align*}\nl(x)=\\prod_{j=0}^N(x-x_j),\n\\end{align*}\nfor equispaced nodes (figure 1), for Chebishev's nodes of the first kind (figure 2) and for Chebishev's nodes of the second kind (figure 3). The nodes are placed on the zeroes of the functions and represented by the red asterisk. We see how the Chebishev's nodes are more concentrated towards the boundaries, being very useful for boundary conditions.\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.6]{Lagrange.eps}}\n\\caption{Equispaced nodes.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.6]{Chebishev1.eps}}\n\\caption{First kind Chebishev's nodes.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.6]{Chebishev2.eps}}\n\\caption{Second kind Chebishev's nodes.}\n\\end{figure}\n\nUsing those nodes we compute approximations to the function $f(x)=\\cos(3x)$. In the following plots we show the error and the upper bound of the error given by the Cauchy interpolation error formula\n\\begin{align*}\nf(x)-p_n(x)=\\frac{f^{(n+1)}(\\xi)}{(n+1)!}l(x),\n\\end{align*}\nwhere $p_n(x)$ represents the approximation. Given the function to approximate, we can then find the upper bound\n\\begin{align*}\nf(x)-p_n(x)=\\frac{f^{(n+1)}(\\xi)}{(n+1)!}l(x)\\leq\\frac{3^{n+1}}{(n+1)!}l(x):=e_{Cauchy}.\n\\end{align*}\nIn the following figures we can see how Cauchy error formula gives us the upper bound for equispaced nodes (figure 7), Chebishev nodes of the first kind (figure 8), Chebishev nodes of the second kind (figure 9). As in problem 2, the drops in the error are due to the fact that the error must be zero at those points used to run the interpolation and, since we are using logarithmic scale, are seen as these sudden drops in the error plot. \n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{Cauchy_equi.eps}}\n\\caption{Error of equispaced nodes.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{Cauchy_cheb1.eps}}\n\\caption{Error of Chebishev's nodes of first kind.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering     %%% not \\center\n{\\includegraphics[scale=0.75]{Cauchy_cheb2.eps}}\n\\caption{Error of Chebishev's nodes of second kind.}\n\\end{figure}\n\nTo finish, we also compute the $L_2$ norm of the error and check that in fact we obtain an over all upper bound for the different methdos (see table 1). As we can check, Cauchy's interpolation formula gives us a good upper bound of the error for each distribution of the nodes. Note that the error of the Chebishev's methods is smaller. As we saw in class, equispaced nodes have high errors at the boundaries.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|c c c }\n%\\hline\n%\\multicolumn{3}{|c|}{Datos}\\\\\n  & Equispaced & First kind Chebishev & Second kind Chebishev\\\\\n\\hline\n$e_{Cauchy}$ & $     3.54887848499\\cdot 10^{-4}$ & $9.68648228641\\cdot 10^{-5}$ & $1.58167667439\\cdot 10^{-4}$\\\\\n$e_{Interpolation}$ & $7.05156144371\\cdot 10^{-5}$ & $1.18371532261\\cdot 10^{-5}$ & $1.49100947533\\cdot 10^{-5}$\\\\\n\\end{tabular}\n\\caption{$L_2$ error norm of different methods.}\n\\end{table}\n\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 4\nN=10;\nf = @(x) cos(3*x);\nxx=linspace(-1,1,1000);\nxk0=linspace(-1,1,N+1)';\nxk1=chebpts(N+1,1);\nxk2=chebpts(N+1,2);\nl0 = @(x) prod(x-xk0);\nl1 = @(x) prod(x-xk1);\nl2 = @(x) prod(x-xk2);\n%\nfigure\nplot(xk0,l0(xk0),'r*')\nhold on\nplot(xx,l0(xx))\ngrid on\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Lagrange','epsc')\nsaveas(gcf,'Latex/FIGURES/Lagrange','fig')\n\n%\nfigure\nplot(xk1,l1(xk1),'r*')\nhold on\nplot(xx,l1(xx))\ngrid on\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Chebishev1','epsc')\nsaveas(gcf,'Latex/FIGURES/Chebishev1','fig')\n\n%\nfigure\nplot(xx,l2(xx))\nhold on\nplot(xk2,l2(xk2),'r*')\ngrid on\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Chebishev2','epsc')\nsaveas(gcf,'Latex/FIGURES/Chebishev2','fig')\n\nw0 = baryWeights(xk0);\np0 = @(x) bary(x,f(xk0),xk0,w0);\nerr_bound0 = 3^(N+1)*l0(xx)/factorial(N+1);\nfigure\nsemilogy(xx,abs(err_bound0))\nhold on\nsemilogy(xx,abs(f(xx)-p0(xx)))\ngrid on\naxis([-1 1 1e-10 1e-4])\nlegend({'$e_{Cauchy}$','$e_{equi}$'},...\n'fontsize',legendfontsize,'interpreter','latex','Location','north')\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nylabel('$e(x)$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Cauchy_equi','epsc')\nsaveas(gcf,'Latex/FIGURES/Cauchy_equi','fig')\n\nw1 = baryWeights(xk1);\np1 = @(x) bary(x,f(xk1),xk1,w1);\nerr_bound1 = 3^(N+1)*l1(xx)/factorial(N+1);\nfigure\nsemilogy(xx,abs(err_bound1))\nhold on\nsemilogy(xx,abs(f(xx)-p1(xx)))\ngrid on\naxis([-1 1 1e-10 1e-4])\nlegend({'$e_{Cauchy}$','$e_{Cheb1}$'},...\n'fontsize',legendfontsize,'interpreter','latex','location','north')\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nylabel('$e(x)$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Cauchy_cheb1','epsc')\nsaveas(gcf,'Latex/FIGURES/Cauchy_cheb1','fig')\n\nw2 = baryWeights(xk2);\np2 = @(x) bary(x,f(xk2),xk2,w2);\nerr_bound2 = 3^(N+1)*l2(xx)/factorial(N+1);\nfigure\nsemilogy(xx,abs(err_bound2))\nhold on\nsemilogy(xx,abs(f(xx)-p2(xx)))\ngrid on\naxis([-1 1 1e-10 1e-4])\nlegend({'$e_{Cauchy}$','$e_{Cheb2}$'},...\n'fontsize',legendfontsize,'interpreter','latex','location','north')\nxlabel('$x$','fontsize',labelfontsize,'interpreter','latex')\nylabel('$e(x)$','fontsize',labelfontsize,'interpreter','latex')\nsaveas(gcf,'Latex/FIGURES/Cauchy_cheb2','epsc')\nsaveas(gcf,'Latex/FIGURES/Cauchy_cheb2','fig')\n\nE_equi=norm(f(xx)-p0(xx),2)\nE_Cauchy_equi=norm(err_bound0,2)\nE_Chebishev1=norm(f(xx)-p1(xx),2)\nE_Cauchy_cheb1=norm(err_bound1,2)\nE_Chebishev2=norm(f(xx)-p2(xx),2)\nE_Cauchy_cheb2=norm(err_bound2,2)\n\n\\end{verbatim}", "meta": {"hexsha": "26daaa4f5201c4b676ecc4a241607305a70fa056", "size": 5930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 2/Latex/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 2/Latex/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 2/Latex/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": 36.1585365854, "max_line_length": 439, "alphanum_fraction": 0.7086003373, "num_tokens": 2060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199633332891, "lm_q2_score": 0.9111797003640645, "lm_q1q2_score": 0.7632223072089851}}
{"text": "\\chapter{Finding the $\\mathbf{k}$-th Smallest Number}\nThe objective of this challenge is to find the $k$-th smallest number in an\nunsorted array. Some elements may be of equal value.\n\n\\section{Sort-and-Find}\nThis solution sorts the unsorted array and returning the value at index $k$. As\nseen before, time complexity analysis indicates that this approach requires more\nthan $O(n\\log n)$ amount of time. Since the sorting algorithm has already been\npresented before, it will not be features again.\n\n\\section{Quick Select}\nThis solution is modeled after the Quicksort algorithm. Unlike Quicksort, this\nalgorithm only focuses on one side of the partition, and therefore its expected\nrunning time is $T(n)=\\Theta(n)$.\n\\imb[3][15]{\\alg/kthsmall.cpp}\n\\imb[17][24]{\\alg/kthsmall.cpp}\n", "meta": {"hexsha": "77741d349a53f9e0a87cb1f16efb5768cabf0bf1", "size": 777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/05_kthsmall.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/05_kthsmall.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/05_kthsmall.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.7058823529, "max_line_length": 80, "alphanum_fraction": 0.7747747748, "num_tokens": 196, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.76322230166879}}
{"text": "\\section{Probability}\r\n\\subsection{General Probability}\r\n{\\bf Definitions:}\r\n$\\mu_X=E(X)$,\r\n${\\sigma_X}^2=Var[X] =  E[(X - E[X])^2]$.\r\n\\emph{Covariance:} $\\mu_{XY}=E((X-\\mu_X)(Y-\\mu_Y))$.\r\n\\emph{Correlation:} $\\rho(X,Y)= {\\frac {E((X-\\mu_X)(Y-\\mu_Y))}\r\n{\\sigma(X) \\sigma(Y)}}$.\r\n\\emph{Moment generating function:}\r\n$G(e^t) = \\sum_{k \\geq 0} \\Pr[X = k] e^{tk} = E[e^{tX}]$.\r\n\\emph{Example:} The moment generating function for Poisson distribution \r\n($f(x)= e^{-\\lambda x}$) is\r\n$\\phi(t)= E(e^{tx})= \\int^{\\infty}_0 e^{tx} \\lambda e^{- \\lambda x} dx=\r\n{\\frac {\\lambda} {\\lambda - t}}$.  \r\n$E(X^2)= {\\frac d {dt}} \\phi(t) = {\\frac 2 {\\lambda^2}}$.\r\n$Var(X)= {\\frac 1 {\\lambda^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem(Stirling approximation):}\r\n$n! \\approx {\\sqrt {2 \\pi n}} ({\\frac {n} {e}})^{n}$.\r\n\\begin{quote}\r\n\\emph{Proof:} $M_n= ln(n!)= \\sum_{i=1}^n ln(i)$. \r\n$\\int_0^n ln(x) dx < M_n < \\int_1^{n+1} ln(x) dx$. So\r\n$(n) ln(n) - n < M_n < (n+1) ln(n+1) - n$.  \r\nSet $d_n= ln(n!)-(n+{\\frac 1 2})ln(n)+n$.\r\n$d_n-d_{n+1}=(n+{\\frac 1 2})ln({\\frac {n+1} n})-1$.  Writing\r\n${\\frac {n+1} n}= {\\frac {1+{\\frac 1 {2n+1}}} {1-{\\frac 1 {2n+1}}}}$,\r\nexpanding the log, and comparing to the geometric series in \r\n$2n+1$, we find $d_n-d_{n+1}= \r\n{\\frac 1 {3(2n+1)^2}} +\r\n{\\frac 1 {5(2n+1)^4}} + \\ldots < {\\frac 1 3} {\\frac 1 {(2n+1)^2-1}} = {\\frac 1 {12}} \r\n({\\frac 1 n} - {\\frac 1 {n+1}})$.  \r\nSo, $0 < d_n-d_{n+1} < {\\frac 1 {12n}}- {\\frac 1 {12(n+1)}} $ and\r\n$\\langle d_n \\rangle$ is decreasing while\r\n$\\langle d_n - {\\frac 1 {12n}} \\rangle$ is increasing.\r\nThus, $d_n$ converges to, say, $C$.  So,\r\n$n! \\approx e^C n^{n+{\\frac 1 2}} e^{-n}$.  To find $e^C = {\\sqrt {2 \\pi}}$, \r\nuse Wallis' formula:\r\n$lim_{n \\rightarrow \\infty} {\\frac {(n!)^2 2^{2n}} {(2n)! {\\sqrt n}}}= {\\sqrt {\\pi}}$.  \r\nTo get this, show\r\n$\\int_{0}^{\\frac \\pi 2} sin^n (x)= {\\frac {n-1} n}\r\n\\int_{0}^{\\frac \\pi 2} sin^{n-2} (x)$.\r\n\\end{quote}\r\n{\\bf Bayes Theorem:} $ P(B_{i}|A)= {\\frac {P(A|B_{i})P(B_{i})} {\\sum\r\nP(A|B_{j})P(B_{j})}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Normal Distribution:} $N(x) = {\\frac {1} {\\sigma {\\sqrt {2 \\pi }}} }\r\ne^{-{\\frac {{(x- \\mu)}^{2}} {2 \\sigma^{2}}}}$,\r\n$Z={\\frac {(X-np)} {\\sqrt {npq}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Binomial Distribution:} $B(N, n, p) = {N \\choose n} p^{n}(1-p)^{N-n}$,\r\n$E(B)=Np, \\sigma^2= Np(1-p)$.\r\n\\\\\r\n\\\\\r\n{\\bf Poisson Distribution:} $P(x)= e^{- \\lambda} {\\frac {\\lambda^{x}} {x!}}$, \r\n$\\mu= \\lambda, \\sigma^2= \\lambda$, probability of count in time $\\Delta t$ is\r\n$\\lambda \\Delta t$.  \r\n$$f(x,y)= {\\frac 1 {2 \\pi \\sigma_1 \\sigma_2 {\\sqrt {1- \\rho^2}}}}\r\ne^{- ({\\frac {(x-\\mu_1)^2} {\\sigma_1^2}} +\r\n(2 \\rho){\\frac {(x-\\mu_1)(y- \\mu_2)} {\\sigma_1 \\sigma_2}} +\r\n{\\frac {(y-\\mu_2)^2} {\\sigma_2^2}})/(2 {\\sqrt {1-\\rho^2}})}$$ \r\n$\\rho$ is the cross correlation between $x$ and $y$.\r\n\\\\\r\n\\\\\r\n{\\bf Poisson approximation to binomial distribution:}  \r\nWhen $p<<1$ Poisson approximates binomial with\r\n$np= \\lambda$, $E(X)= \\lambda$.\r\n\\\\\r\n\\\\\r\n{\\bf Binomial test:}  If we have an experiment with two outcomes and we want to test the hypothesis that the\r\ndistribution of outcomes is $p, q=1-p$.  We perform $n$ experiments.  We expect about $np$ observations of the\r\nfirst outcome.  Suppose there are $r$ observation of the first value.  The \\emph{binomial} test with significance $\\alpha$,\r\ntests the hypothesis that the proposed distribution is correct.  To do it, let the random variable\r\n$x$ represent the number of \"successes\".  Compute $P(x \\geq r) = \\sum_{j=r}^n {n \\choose j} p^j (1-p)^{n-j}$.\r\nIf $P(x \\geq r) < \\alpha$, reject the hypothesis.\r\n\\\\\r\n\\\\\r\n{\\bf Zipf distribution:}  $P(k)= {\\frac c {k^{1+\\alpha}}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Central Limit Theorem:}  If $X_i$ are independent, identically distributed\r\nrandom variables with mean $\\mu$ and\r\n$S_{n}= X_{1}+ \\ldots + X_{n}$, then $\\lim_{n \\rightarrow \\infty}\r\nP(a \\leq  {\\frac {(S_{n}-n \\mu)} {\\sigma {\\sqrt n}}} \\leq b) =\r\n{\\frac {1} {\\sqrt {(2 \\pi)}}} \\int_{a}^{b} e^{-(u^{2}/2)}$.\r\n\\begin{quote}\r\n\\emph{Proof:} $E(S_n)= n \\mu$, $\\sigma^2=Var(S_n)= n\\sigma_{X_i}$.  Define\r\n$S^*_n= {\\frac {S_n -n\\mu} {\\sigma {\\sqrt n}}}$.  So\r\n$E[e^{tS^*_n}]=E[\r\ne^{\\frac {t(X_1-\\mu)} {\\sigma {\\sqrt n}}}\r\ne^{\\frac {t(X_2-\\mu)} {\\sigma {\\sqrt n}}} \\ldots\r\ne^{\\frac {t(X_n-\\mu)} {\\sigma {\\sqrt n}}}]=\r\nE[e^{\\frac {t(X_1-\\mu)} {\\sigma {\\sqrt n}}}]^n$.\r\nExpanding the exponential in the taylor series, we get\r\n$E[e^{tS^*_n}]=E[1+\r\n{\\frac {t(X-\\mu)} {1! {\\sqrt n} \\sigma}}+\r\n{\\frac {(t(X-\\mu))^2} {2! {({\\sqrt n} \\sigma})^2}}+\r\n\\ldots]^n = e^{\\frac {-t^2} 2}$.  This is the same moment generating function\r\nas the normal distribution, so were done.  \\\\\r\n\\\\\r\n$\\chi^{2}= {\\frac {(Y_{2}- n p_{2})^{2}} {( n p_{2})}} +...+\r\n{\\frac {(Y_{12}- n p_{12})^{2}} {(n p_{12})}},$\r\n$P(\\chi^{2} \\leq x)= {\\frac {1} {2^{\\frac {\\nu} {2}} \\Gamma({\\frac {\\nu}\r\n{2}})}} \\int_{0}^{x} u^{{\\frac {\\nu} {2}}-1} e^{-{\\frac {u} {2}}} du$.\r\n\\end{quote}\r\n{\\bf Markov Inequality:} Let $X$ be a random variable assuming only non-negative values, and\r\nwith expected value $E[X]$ convergent.  Then\r\nfor any $t>0$,\r\n$ \\Pr[X \\geq t] \\leq \\frac{E[X]}{t}.$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $f(x)$ be the density function. Let $I_E$ be the indicator function of the\r\nset of events $E$ ($I_E(e)= 1$, if $e \\in E$, $0$ otherwise).\r\n$E(aI_{|X| \\geq a}) \\leq E(|X|)$, so $aPr(|X| \\geq a) \\leq E(|X|)$.\r\n\\end{quote}\r\n{\\bf Chebyshev Inequality:} Let $Y$ be a random variable\r\nwith expected value $\\mu = E[Y]$ and variance, $Var(Y)$.  Then\r\nfor any $t>0$,\r\n$\\Pr[| Y - \\mu | \\geq t] \\leq {\\frac {Var(Y)}{t^2}}.$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $g(y)$ be the density function. \r\n$Var(Y)= \\int_{-\\infty}^{\\infty} (Y-E(Y))^2 g(y) dy$.\r\n$Var(Y) \\geq \r\n\\int_{|Y-E(Y)| \\geq \\epsilon} (Y-E(Y))^2 g(y) dy \\geq \\epsilon^2 \r\n\\int_{|Y-E(Y)| \\geq \\epsilon} g(y) dy = \\epsilon^2 P(|Y-E(Y)| \\geq \\epsilon)$.\r\n\\end{quote}\r\n{\\bf Chernoff:} Let $T_1 , T_2 , \\ldots , T_N$ be mutually independent Bernoulli\r\nvariables\r\n$T= \\sum_i^N T_i$.  Then $\\forall c \\geq 0$,\r\n$Pr( T \\geq c E(T)) \\leq e^{\\alpha E(T)}$ where\r\n$\\alpha = ln(c) + {\\frac 1 c} -1$.\r\n\\\\\r\n\\\\\r\n{\\bf Wald:} Let Q be a random variable that takes on only non-negative integer\r\nvalues such\r\nthat $E(Q) < \\infty$.  Let $R_1 , R_2 , \\ldots$ be a sequence of random\r\nvariables\r\nwith the same distribution and let $T= R_1 + R_2 + \\ldots + R_Q$.  Suppose\r\n$R_k$ is independent of the event that it is included in the sum, that is\r\n$\\forall\r\nk \\geq 1$, $R_k$ is independent of an indicator variable for the event\r\n$Q \\geq k$ then $E(T)= E(Q) E(R_1 )$.\r\n\\\\\r\n\\\\\r\n{\\bf Occupancy:} Let $X_i$ be an indicator for a ball falling into $i$. $E(X_i ) =\r\n1$.\r\nLet $Z_i$ be the probability that the bin is empty. $E(Z_i )= {\\frac {n}\r\n{e}}$.\r\nLet $p_m (r, n)$ be the probability of finding $r$ balls in $n$ cells with exactly\r\n$m$ empty cells.\r\n$p_m (r, n)= {n \\choose m} (1- {\\frac m n})^r p_0 (r, n-m)$.  Further,\r\n$p_0 (r, n)= \\sum_{i=0}^{n} (-1)^i {n \\choose i} (1- {\\frac i n})^r$.\r\n\\\\\r\n\\\\\r\n{\\bf Lovasz Local Lemma:}  Let $G= (V,E)$ be a dependency graph for events $e_1 ,\r\ne_2 , ... , e_n$\r\nin a probability space.  Suppose $\\exists x_i \\in\r\n[0, 1]$ for $1 \\leq i \\leq n$, such that\r\n$Pr[e_i ] \\leq x_i \\Pi_{(i, j) \\in E} (1 - x_j )$.  Then\r\n$Pr[\\cap {\\overline {e_i}}] \\geq  \\Pi_{i}^{n} (1- x_i )$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $\\{p_i \\}$ and $\\{ q_i \\}$ are probability distributions and\r\n$G(q_1 , q_2 , \\ldots , q_n ) = - \\sum p_i ln(q_i )$. Then $G$ is minimum\r\nwhen\r\n$p_i = q_i$.\r\n\\subsection {Statistical Inference and Hidden Markov Models}\r\n{\\bf Sample statistics:} Suppose a population has mean $\\mu$ and variance $\\sigma$. \r\nIf we\r\ntake a sample of size $n$ consisting of observations $\\langle X_1 , \\ldots , X_n \\rangle$ and\r\nlet $\\mu_{\\overline X}$ denote the sample mean, then \r\n$E((\\mu_{\\overline X} - \\mu)^2) = {\\frac {\\sigma^2} n}$.  \r\nThe \\emph{chi-squared}\r\nrandom variable for normally distributed random variables $\\langle X_1, \\ldots , X_n \\rangle$\r\nwith mean $0$ and variance $1$ is\r\nis defined as $\\chi^2(\\langle X_1, \\ldots , X_n \\rangle )= X_1^2 + \\ldots + X_n^2$;\r\n$P(\\chi^2 \\leq x) = {\\frac {1} {2^{\\frac {\\nu} {2}} \\Gamma({\\frac {\\nu} {2}})}} \\int_0^x u^{{\\frac {\\nu} {2}} -1} e^{-{\\frac {u} {2}}} du$ where $\\nu$ is the number of degrees of freedom.\r\nNow let $S^2= {\\frac {(X_1 - \\mu_{\\overline X})^2 + \\ldots + (X_n - \\mu_{\\overline X})^2} {n}}$.\r\nIf the distributions are normal, the distribution of $S^2$ is \\emph{chi-squared} with $n-1$\r\ndegrees of freedom. \r\n$\\chi^2= {\\frac {nS^2} {\\sigma^2}}$.  Thus if $H_0$ is a hypothesis from a normal distribution,\r\nwe accept at $.05$ level if $\\chi^2(.025) \\leq {\\frac {n s^2} {\\sigma^2}} \\leq \\chi^2(.975)$.\r\nFinally, put $T= {\\frac {\\mu_{\\overline X} - \\mu} {{\\frac {S} {\\sqrt {n-1}}}}}$.  This is\r\nStudent $t$-distributed with $n-1$ degrees of freedom.\r\n\\\\\r\n\\\\\r\nLet $Y=Pred(L)$, $\\sigma^2(Y,L)= E((Y-L)^2)$.  Value of predictor:\r\n$W(Y,L)= {\\frac {\\sigma^2(Y,L) -E(L-Y)^2} {\\sigma^2(Y,L)}}$. \r\n$0=W(E(L),L) \\le W(Y,L) \\le W(L,L)=1$.  $E((X-t)^2)$ is minimized $t=E(Y)$.\r\nLet $cov(X,Y)= E(XY)=E(X)E(Y)$.\r\nBest linear predictor: $Y=aX+b$, $a= {\\frac {cov(X,Y)} {cov(X,X)}}$ (and solve for $b$).\r\nWorth of best predictor (using mean square error) is\r\n$\\rho(X,Y)^2= {\\frac {cov(X,Y)^2} {cov(X,X) cov(Y,Y)}}$.  Posterior models.\r\n$P(|Y- \\mu| \\ge t) \\le {\\frac {var(Y)} {t^2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Maximum likelihood re-estimation:}\r\nLet $S= \\{ 1,2,3, \\ldots, n\\}$ be the $n$ possible\r\nstates of a hidden markov process with $T-1$ transitions and $T$ outputs.\r\nSuppose the output vector of the process\r\nis ${\\vec O} \\in ({\\mathbb Z}_m)^{(T)}$.  Finally, suppose the following distributions\r\nare given:\r\ninitial state distribution - $\\pi(i), i \\in {\\mathbb Z}_m$;\r\noutput distribution - $q_{ij}= q(j|i)= Pr(O_t=j | {\\vec S_t}= i), \\forall t$;\r\nstate transition distribution: \r\n$p_{ij}=P(j|i)= Pr({\\vec S}_t=j | {\\vec S}_{t-1}= i), \\forall t$.\r\n\\begin {itemize}\r\n\\item \\emph{Problem 1:} Given\r\n$O= O_0, O_1, O_2, ..., O_{T-1}$, $\\lambda=(P, q, \\pi)$, how do we compute $Pr(O| \\lambda)$\r\nefficiently?\r\n\\item \\emph{Problem 2:} Given\r\n${\\vec O}= O_0, O_1, O_2, ..., O_{T-1}$ and $\\lambda$, how do we choose an\r\n${\\vec q}$ which is optimal?\r\n\\item \\emph{Problem 3:} How do we adjust the model parameters $\\lambda=(P, q, \\pi)$, \r\nto optimize $Pr({\\vec O} | \\lambda)$, given the observed sequence: ${\\vec O}$?\r\n\\end {itemize}\r\n{\\bf Solution to Problem 1:}\r\nAssuming the foregoing, the probability of the output ${\\vec O}$ is:\r\n$$\r\nPr[{\\vec O} | \\lambda] = \r\n\\sum_{{\\vec s} \\in {\\vec S}^{(T)}}\r\n\\pi({\\vec s}_0) q(O_0 | {\\vec s}_0)\r\n\\prod_{i=1}^T P({\\vec s}_{i}|{\\vec s}_{i-1}) \r\n\\prod_{i=1}^T q(O_{i}|{\\vec s}_{i})\r\n$$\r\nThe following recursion greatly improves the calculation cost.\r\nLet $\\alpha_0(i)= \\pi(i) q(O_0 | i), \\forall i$ and \r\n$\\alpha_t(i)= (\\sum_{j=1}^n \\alpha_{t-1} (j) P(S_t=i | S_{t-1}=j)) q(O_t|i), \\forall i$.\r\nThis is called the ``forward recursion''.\r\nThen $\\alpha_t(i) =\r\n\\sum_{{\\vec s} \\in {\\vec S}^t, {\\vec s}_t=i}\r\n\\pi({\\vec s}_0) q(O_0 | {\\vec s}_0)\r\n\\prod_{j=1}^t P({\\vec s}_{j}|{\\vec s}_{j-1}) \r\n\\prod_{j=1}^t q(O_{j}|{\\vec s}_{j})$,\r\nthe probability of the observation of\r\nthe sequence up to time $t$ given ${\\vec s}_t=i$.\r\n$Pr({\\vec O} | \\lambda) = \\sum_{i=1}^n \\alpha_{T-1}(i)$;\r\ncomputing $\\{ \\alpha_T(i) \\}$ takes \r\n$O(n^2(T))$ rather than $O(2(T)n^{T})$.  This solves problem 1.\r\n\\\\\r\n\\\\\r\n{\\bf Solution to Problem 2:}\r\nSlightly abusing the notation from above define\r\n$\\beta_t(i) = Pr(O_{t+1}, \\ldots, O_T | S_t=i, \\lambda)$.  The ``backwards\r\nrecursion'' is: $\\beta_T(i)=1, \\forall i$, \r\n$\\beta_t(i)= \\sum_{j=1}^n P(S_t=i|S_{t+1}=j) \\beta_{t+1}(j)q(O_{t+1}|j)$.\r\nNow define \r\n$\\gamma_t(j)=P(s_t=1| {\\vec O}, \\lambda)$ so\r\n$\\gamma_t(j)= {\\frac {\\alpha_t(j) \\beta_t(j)} {P({\\vec O}| \\lambda)}}$.  \r\nThe most likely state at time $t$ is the one that maximizes\r\n$\\gamma_t(i)$.\r\n\\\\\r\n\\\\\r\n{\\bf Solution of Problem 3:}\r\nDefine $\\gamma_t(i,j)= P(S_t=i, S_{t+1}=j| {\\vec O}, \\lambda)$ so\r\n$\\gamma_t(i,j)= {\\frac {\\alpha_t(i) P(S_t=j | S_{t+1}=i) q(O_{t+1}|j) \\beta_{t+1}(j)}\r\n{P({\\vec O} | \\lambda)}}$ and $\\gamma_t(i)= \\sum_{j=1}^n \\gamma_t(i,j)$.  $\\gamma_t(i,j)$\r\nis the probability of being in state $i$ at $t$ and transitioning to state $j$.\r\nNow, suppose the model, $\\lambda= (\\pi, P, q)$, is unknown, the MLE of the\r\nmodel, given observations ${\\vec O}$ is determined by:\r\n\\begin {itemize}\r\n\\item\r\n$0= {\\frac {\\partial} {\\partial \\pi(i)}}\r\n[Pr({\\vec O}=(O_0, \\ldots, O_T))-\\lambda_1(\\sum_{k=0}^{m-1} \\pi(k) -1)]$.\r\n\\item\r\n$0= {\\frac {\\partial} {\\partial P(j|i)}}\r\n[Pr({\\vec O}=(O_0, \\ldots, O_T))-\\lambda_2(\\sum_{k=0}^{m-1} P(k|i)-1)]$.\r\n\\item\r\n$0= {\\frac {\\partial} {\\partial q(j|i)}}\r\n[Pr( {\\vec O}=(O_0, \\ldots, O_T))-\\lambda_3(\\sum_{k=0}^{m-1} q(k|i)-1)]$.\r\n\\end {itemize}\r\nSolving gives the following \\emph{re-estimation formulas:}\r\n\\begin {itemize}\r\n\\item\r\n${\\hat {\\pi}}(i) = \\gamma_0(i)\r\n= {\\frac {\\alpha_0(i) \\beta_0(i)} {\\sum_{k=1}^{n} \\alpha_0(k) \\beta_0(k)}}$, \r\n$\\sum \\pi(i)=1$.\r\n\\item\r\n${\\hat {P}}(j|i)= \r\n{\\frac {\\sum_{t=0}^{T-1} \\gamma_t(i,j)} {\\sum_{t=0}^{T-1} \\gamma_t(i)}}=\r\n{\\frac {\\sum_{t=0}^{T-1} \\alpha_t(i) q(O_{t+1}|j) P(j|i) \\beta_t(j)} \r\n{\\sum_{t=0}^{T} \\alpha_t(i) \\beta_t(i)}}$,\r\n$\\sum_j P(j|i)=1$.\r\n\\item\r\n${\\hat {q}}(j|i)=  \r\n{\\frac {\\sum_{t \\in \\{0,1,\\ldots, T-1 \\}, O_t=j} \\gamma_t(i)} \r\n{\\sum_{t=0}^{T-1} \\gamma_t(i)}}=\r\n{\\frac {\\sum_{t=0, O_t=j}^{T-1} \\alpha_t(i) \\beta_t(i)} \r\n{\\sum_{t=1}^{T} \\alpha_t(i) \\beta_t(i)}}$,\r\n$\\sum_j q(j|i)=1$.\r\n\\end {itemize}\r\nBaum showed that if $Q(\\lambda, {\\overline {\\lambda}})= \r\n\\sum_{s \\in S} P_{\\lambda}(O,s) log(P_{\\overline {\\lambda}}(O,s)$ and\r\n$Q(\\lambda, {\\overline {\\lambda}}) >\r\nQ(\\lambda, \\lambda)$  then $P_{\\overline {\\lambda}}(O,s)> P_{\\lambda}(O,s)$.\r\nOptimizing $Q$ instead of $P$ gives the Baum EM algorithm.  Note that optimizing\r\nusing dynamic programming may give a different result: $\\delta_0(i)= \\pi(i) q(i|O_0)$,\r\n$\\delta_t(i)= max_{j \\in \\{1, \\ldots, n\\}} (\\delta_{t-1}(j) p_{ji} q_{i O_t})$ since\r\nit optimizes the overall path.  You can deal with underflow by taking logs or (in the\r\nHMM case) scaling in a way that maintains the re-estimation result.\r\n\\\\\r\n\\\\\r\n{\\bf Scaling:} \r\n$\\alpha_t(i)= \\sum_{j=1}^{n} \\alpha_{t-1}(j) a_{ji}b_i(o_t)$.\r\n$\\tilde{\\alpha}_0(i)= \\alpha_0(i), 0 \\le i <n$, \r\n$c_0= (\\sum_{j=0}^{n} \\tilde{\\alpha}_0(j))^{-1}$ and\r\n$\\hat{\\alpha}_0(i)= c_0 \\tilde{\\alpha}_0(i)$.  Recursively,\r\n$\\tilde{\\alpha}_t(i)= \\sum_{j=1}^{n} \\hat{\\alpha}_{t-1}(j) a_{ji}b_i(o_t),\r\n0 \\le i <n$,\r\n$c_t= (\\sum_{j=1}^{n} \\tilde{\\alpha}_0(j))^{-1}$ and\r\n$\\hat{\\alpha}_t(i)= c_t \\tilde{\\alpha}_0(i)$.\r\nUsing the above, $\\hat{\\alpha}_t(i)= c_0 c_1 \\ldots c_t \\alpha_t(i)= {\\frac {\\alpha_t(i)}\r\n{\\sum_{j=1}^{n} \\alpha_t(j)}}$ and $P(O|\\lambda)= (\\prod_{j=0}^{T-1} c_j)^{-1}$,\r\nthe $\\beta$ scale the same way.\r\n\\\\\r\n\\\\\r\n{\\bf EM as Gaussian mixture problem:}\r\n$p({\\vec x})= \\sum_{k=1}^K N({\\vec x} | {\\vec {\\mu_k}}, {\\vec {\\Sigma_k}})$,\r\nlet ${\\vec z}$ be a $K$ dimensional random variable from the\r\nsample space all of whose components are $0$ but a single one which is 1 (i.e.- $z_k=1$) under\r\nthe Gaussian model $(\\pi_k, \\mu_k, \\Sigma_k)$.\r\n$p({\\vec x}| z_k=1)= N({\\vec x} | {\\vec {\\mu_k}}, {\\vec {\\Sigma_k}})$, $p(z_k=1)= \\pi_k$ and\r\n$p({\\vec x})=\r\np({\\vec x} | {\\vec z}) p({\\vec z})$.  $\\pi_k$ is the prior estimate of\r\n$z_k=1$ and $\\gamma(z_k)$ is the posterior estimate.\r\n$\\gamma(z_k)= p(z_k=1| {\\vec x})= {\\frac {p(z_k=1) p({\\vec x} | z_k=1)}\r\n{\\sum_j p(z_j=1) p({\\vec x}| z_j=1)}}$.  For mixing, let \r\n$\\langle {\\vec {x_1}}, \\ldots , {\\vec {x_N}} \\rangle$ be a sample.\r\nThe log likelihood is\r\n$p({\\vec x} | {\\vec {\\pi}}, {\\vec {\\mu}}, {\\vec {\\Sigma}}) =\r\n\\sum_{n=1}^N ln( \\sum_{k=1}^K \\pi_k N({\\vec {x_n}}| \\mu_k, \\Sigma_k))$ and EM\r\nmaximizes this.  Maximizing equations come from taking derivatives with\r\nrespect to $\\mu_k$ and setting them to $0$ --- \r\n$0= - \\sum_{n=1}^N  {\\frac {\\pi_k N({\\vec {x_n}}| \\mu_k, \\Sigma_k}\r\n{\\sum_j \\pi_j N({\\vec {x_j}}| \\mu_j, \\Sigma_j)}} \\cdot \r\n\\Sigma_k ({\\vec {x_n}}- \\mu_k)$.  The term in the denominator is \r\n$\\gamma(z_{nk})$, $N_k= \\sum_{n=1}^N \\gamma(z_{n,k})$ and \r\n$\\mu_k = {\\frac 1 {N_k}} \\sum_{n=1}^N \\gamma(z_{n,k})$.  Taking the derivatives with respect\r\nto $\\Sigma_k$ give the remaining equations (Note: $\\mu_k= {\\frac {N_k} {N}}$).\r\nAn alternative (Bayesian) \r\nview is to regard ${\\vec z}$ as latent, $\\Theta$ as the model parameters\r\nand $ln(p({\\vec X} | \\Theta))= ln(\\sum_z p({\\vec X} | {\\vec Z}, \\Theta))$.  We use\r\nthis to estimate the likelihood from $\\Theta^{old}$ for general $\\Theta$:\r\n${\\cal Q}(\\Theta, \\Theta^{old})= \\sum_z p(Z| X, \\Theta^{old}) ln(p(X,Z| \\Theta))$; the\r\n``M'' step corresponds to finding \r\n$\\Theta^{new}= arg \\; max_{\\Theta} ({\\cal Q} (\\Theta, \\Theta^{old})$.\r\n\\\\\r\n\\\\\r\n{\\bf Dichotomy problem:} ${\\vec x}= (x_1 , x_2 , \\ldots, x_n)$ is observed stream generated\r\nby process with underlying model $P(0)= \\theta_0$.  Suppose $a$ $0$'s are observed and $b$ $1$'s,\r\n$P({\\vec x}| \\theta) = \\theta^a (1-\\theta)^b$.  The inverse problem in it's simplest form is\r\nchoose between two sources of ${\\vec x}$ with probabilities $\\theta_0 , \\theta_1$, where\r\n$P(\\theta_0)+P(\\theta_1)=1$.  \r\n$P(\\theta_i | {\\vec x})= {\\frac {P({\\vec x} | \\theta_i) P(\\theta_i)} {P({\\vec x})}}$ and thus\r\n$P(\\theta_i | {\\vec x})= {\\frac {\\theta_i^a (1- \\theta_i)^b P(\\theta_i)} {P({\\vec x})}}$.\r\nNote that\r\n$P({\\vec x})= P({\\vec x}|\\theta_0) P(\\theta_0)+ P({\\vec x}|\\theta_1) P(\\theta_1)$.\r\nThe posterior odds ratio is\r\n${\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}}=\r\n({\\frac {\\theta_1} {\\theta_0}})^a \r\n({\\frac {(1-\\theta_1)} {(1-\\theta_0)}})^b \r\n({\\frac {P(\\theta_1)} {P(\\theta_0)}})$.  Let the ``benefit'' of guessing $\\theta_i$ if the\r\ncorrect answer is $\\theta_j$ be $m_{ji}$ (negative if $i \\ne j$).  We maximixe \r\nthe mean outcome by picking $\\theta_1$ iff \r\n${\\frac {P({\\vec x}|\\theta_1)} {P({\\vec x}|\\theta_0)} } \\ge {\\frac {m_{00}-m_{01}} {m_{11}-m_{10}}}$.\r\nThe log posterior odds is\r\n$log({\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}})=\r\nlog({\\frac {P({\\vec x}|\\theta_1)} {P({\\vec x}|\\theta_0)}})+\r\nlog({\\frac {\\theta_1} {\\theta_0}})\r\n$.  What is PDF for\r\n$log({\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}})$?\r\n$E_{\\theta_i}(\r\nlog({\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}})\r\n= n( \\theta_i log({\\frac {\\theta_i} {\\theta_0}}) + \r\n(1-\\theta_i)\r\nlog({\\frac {1-\\theta_i} {1-\\theta_0}})) + c$. \r\nCall $\\mu= \\theta_i log({\\frac {\\theta_i} {\\theta_0}}) + (1-\\theta_i)\r\nlog({\\frac {1-\\theta_i} {1-\\theta_0}})\r\n$ the {\\emph scoring or information rate}.  Note that this is irrelevant once ${\\vec x}$ is\r\nevaluated.\r\nGiven two distributions \r\n$\\{p_i \\}$\r\n$\\{q_i \\}$, define $H({\\vec p}, {\\vec q})= \\sum_{j=1}^n p_j log({\\frac {p_i} {q_i}})$.\r\n$H({\\vec p}, {\\vec q}) \\ge 0$ and\r\n$H({\\vec p}, {\\vec q}) = 0$ iff \r\n$\\{p_i \\}= \\{q_i \\}$.  \r\nUsing a Taylor expansion if $\\theta_0 \\approx \\theta_1 \\approx {\\frac 1 2}$,\r\n$ H(\\theta_1:\\theta_0) \\approx H(\\theta_0:\\theta_1)$.\r\nClaim: For large $n$, \r\n$log({\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}})$ is approximately \r\nGaussian distributed.  Apply CLT:\r\n$\r\n{\\frac 1 {\\sqrt n}} (log({\\frac {P(\\theta_1|{\\vec x})} {P(\\theta_0|{\\vec x})}})- \\mu n)=\r\n\\sum_{j=1}^n {\\frac 1 {\\sqrt n}} (log({\\frac {P(\\theta_1|{\\vec x}_j)} {P(\\theta_0|{\\vec x}_j)}})= \\mu$.\r\n$\\mu$ is the scoring or information rate.\r\n\\\\\r\n\\\\\r\n{\\bf Data analysis:} \\emph{$k$-means}: put $\\mu_j=x_n$, for $k$ random $x_n$.  \r\nRepeat until $S_1 , S_2 , \\ldots , S_k$ don't change.  Put $x_i$ in the \r\n$S_j$ where $x_i$ is closest to $\\mu_j$.  For $j= 1, \\ldots, k$,\r\n$\\mu_j= |S_j|^{-1} \\sum_{x \\in S_j} x$. \\emph{Naive Bayes for spam:} Get training set\r\n$S$, $H$ of spam and ham messages.  $w_i$, a word is $i$-th feature.  Get \r\n$P(\\textnormal{spam})$ and $P(\\textnormal{ham})$ from training set.  \r\nCalculate $P(w_1, w_2, \\ldots, w_m|\\textnormal{spam})$.  Now use Bayes theorem to get\r\nestimator.\r\n\\\\\r\n\\\\\r\n{\\bf Cryptographic application:}\r\nModel incorrect decipherments as random stream $P(0)=P(1)= {\\frac 1 2}$ while correct decipher\r\n$P(0)=\\theta_1 \\ne  {\\frac 1 2}$.  For one time pad, we want to distinguish between\r\n$P(\\cdot | {\\frac 1 2})$ and\r\n$P(\\cdot | \\theta_1)$.  We compute \r\n${\\frac \r\n{P(\\theta_1| {\\vec z} \\oplus {\\vec y})}\r\n{P( {\\frac 1 2} | {\\vec z} \\oplus {\\vec y})}}$ using prior \r\n$P({\\frac 1 2})= {\\frac {K-1} {K}}$ and\r\n$P(\\theta_1)= {\\frac 1 2}$.  \r\nConsider an $l-$gram, $P({\\vec y})= 2^{-l}$ for small $l$ but this cannot be true for\r\n$l \\approx n$.  Define\r\n$L({\\vec x})= log({\\frac {P({\\vec x}|\\theta_1)} {P({\\vec x}|\\theta_0)}})$.  \r\n``Type I'' errors reject $\\theta_0$ when it is correct.\r\n``Type II'' errors accept $\\theta_0$ when it is incorrect.\r\n\\\\\r\n\\\\\r\n{\\bf Principal Component Analysis:}\r\nSuppose $x_1 , x_2 , \\ldots , x_N \\in {\\mathbb R}^D$ and\r\nwe project this space onto\\\\\r\n$\\langle u_1 , u_2, \\ldots , u_M \\rangle$ where $u_k \\in {\\mathbb R}^D$\r\nand $u_i u_i^T =1$.  For example, for $M=1$, the\r\nvariance of the projection is\r\n${\\frac 1 N} \\sum_{n=1}^N (u_1^T x_n -u_1^T {\\overline x})= u_1^T S u_1$ where\r\n${\\overline x} = {\\frac 1 N} \\sum_{i=1}^N x_i$ and $S$ is the co-variance matrix.  \r\nFinding the first principal component requires us to\r\nto maximize $u_1^T S u_1$ subject to  $u_1^t u_1 =1$.  Using Lagrange multipliers,\r\nthis is equivalent to maximizing $f(u_1)= u_1^T S u_1 + \\lambda_1 (1- u_1^T u_1)$.  Taking\r\nderivative, we get $S(u_1) = \\lambda_1 u_1$ with $\\lambda_1$ the largest eigenvalue\r\nof $S$.  Can also find $\\lambda_1$ with EM.  For general $M$,\r\n$u_i^T u_j= \\delta_{ij}$, ${\\vec {x_n}}= \\sum_{i=1}^D \\alpha_{ni} u_i$,\r\n$\\alpha_{nj}= (x_n^T u_j)$, \r\n$x_n= \\sum_{i=1}^D (x_i^Tu_i \\cdot u_i)$ and\r\nwe want to minimize $J= {\\frac 1 N} \\sum_{n=1}^N ||x_n-{\\overline x}||^2$\r\nwhich reduces to an eigenvalue problem.\r\n\\subsection{Information and Coding Theory}\r\n{\\bf Shannon conditions for entropy:} (a) continuous in probability,\r\n(b) monotonically increasing in\r\nnumber of messages, additive with respect to refinement:\r\n$H(\\frac {1} {2}, \\frac {1} {4}, \\frac {1} {4})=\r\nH(\\frac {1} {2}, \\frac {1} {2} ) +\r\n\\frac {1} {2} H(\\frac {1} {2}, \\frac {1} {2})$.\r\nNumber of bits of information obtained in observing event that occurs\r\nwith probability $p$ is $lg(p)$.\r\n$H(P) = \\sum - p_{i} lg ( p_{i})$, $lg(|X|) \\ge H(X) \\ge 0$.\r\n$I(X, Y)= H(X)-H(X | Y )= H(X)+H(Y)-H(X,Y)$.\r\n$H(X,Y) \\leq H(X) + H(Y)$.  $H(U|V)= 0$ iff $U=g(V)$.\r\n\\\\\r\n\\\\\r\n{\\bf Notation:}\r\n$D(p||q)= \\sum_x p(x) lg({\\frac {p(x)} {q(x)}}) \\ge 0$.  Markov chain\r\ndenoted by $X \\rightarrow Y \\rightarrow Z$.\r\nIf $X \\rightarrow Y \\rightarrow Z$ then $I(X;Y) \\le I(X;Z)$.  Let $T(X)$ be\r\nany statistic and $F= \\langle f_{\\theta}(x) \\rangle$ and $X$ a sample from $F$ then\r\n$I(\\theta; T(X)) \\le I(\\theta; X)$.  $T$ is a {\\bf sufficient statistic} if equality\r\nholds.  $T(X)$ is a minimal sufficient statistic relative to $F$ if\r\nit is a statistic of every other sufficient statistic $U(X)$.\r\n$\\theta \\rightarrow T(X) \\rightarrow U(X) \\rightarrow X$.  A stochastic\r\nprocess $X= \\langle X_1 , X_2 , \\ldots \\rangle$ is {\\bf stationary} if the\r\njoint distribution of any subsequence is invariant with respect to time shifts.\r\nThe \\emph{entropy} of a stochastic process is \r\n$H(X)= \\lim_{n \\rightarrow \\infty} {\\frac 1 n} H(X_1 , X_2 , \\ldots , X_n)$.  For\r\na stationary Markov chain, the entropy rate is given by $H(X)= H(X_2 | X_1)$.\r\nIf $X$ is a stationary markov chain then so is the process \r\n$\\langle Y_i= \\phi(X_i) \\rangle$ and \r\n$ H(Y_n | Y_{n-1}, \\ldots, Y_1, X_1) \\le H(Y) \\le H(Y_n | Y_{n-1}, \\ldots, Y_1)$\r\nequality holds by taking the limit across the inequalities.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem on Asymptotic Equipartition:} \r\n$H_{\\delta}(X)= lg( min \\{ |T|: T \\subseteq A_X, Pr(x \\in T ) \\geq (1- \\delta ) \\}$\r\nand $n$, independent identically distributed random variables $X_i$,\r\nif $X^{n}=(X_1 , X_2 , \\ldots , X_n )$ is almost certain to belong to\r\n$B \\subseteq A^{n}_X $ having about $2^{NH}$ members, each with\r\nprobability ``close'' to $2^{-NH}$.  This is equivalent to \r\n{\\bf Shannon's Source coding Theorem:} \r\nThe $n$ r.v.'s can be encoded by $NH$ bits with negligible\r\ninformation loss.\r\nTo show this, show for any $\\delta$ there's an $n$ such that $H_{\\delta}\r\n(X^{(n)}) \\approx NH$.\r\nHint: Define $Y = {\\frac {1} {n}} lg({\\frac {1} {p(x)}})$.  Let\r\n$T_{n, \\beta}= \\{ y \\in A^{n}_X :\r\n{[{\\frac {1} {n}} lg({\\frac {1} {p(x)}}) -H]}^2 < \\beta^2 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nThe \\emph{channel capacity} is $C= max_{P(x)} (H(I|J)-H(I))$.  For a DMC, BSC with error\r\nrate $p$, this implies $C_{BSC}(p)= 1+p lg(p) + q lg(q)$.  So for BSC\r\n$R=1-H(P)$.\r\n\\\\\r\n\\\\\r\n{\\bf Observations:}\r\nTo \\emph{detect} $t$ errors $d(C) \\geq t+1$.\r\nTo \\emph{correct} $t$ errors $d(C) \\geq 2t+1$.\r\nA \\emph{perfect code} satisfies $M (\\sum_k^t {n \\choose k} (q-1)^k)= q^n$.\r\n\\\\\r\n\\\\\r\n{\\bf Shannon Source Coding:}  If a memoryless source has entropy $H$ then any\r\nuniquely decipherable\r\ncode over an alphabet $\\Sigma$ with $D$ symbols must have length $\\geq\r\n{\\frac H {lg(D)}}$.  Further,\r\n$\\exists$ a uniquely decipherable code with average length $\\leq 1+ {\\frac H\r\n{lg(D)}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Shannon's Theorem Channel Coding:}\r\nIf $0 \\leq R \\leq 1+ p lg(p)+ q lg(q)$, $M_n = 2^{\\lceil Rn \\rceil}$,\r\nthen $P^{*} (M_n , n, p) \\rightarrow 0$ as $n \\rightarrow \\infty$.\r\nNotation: Each codeword has $n$ bits.\r\nLet $P_i$ be the probability of making an error in\r\ndecoding if $x_i$ is transmitted. Then\r\n$P_C = {\\frac 1 M} \\sum_i P_i$ is the probability of making a decoding error\r\nif a randomly chosen codeword is transmitted and\r\nevery codeword is equiprobable.\r\n$P^{*} (M_n , n, p) = min_{C} (P_C )$, with\r\n$BlockLength(C)=n$,  $R= {\\frac {lg(|C|)} {n}}$\r\nand $M_n= 2^{\\lfloor Rn \\rfloor}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nDefine the following terms: $f(u, v) = 0$, if $d(u,x) > \\rho$ and\r\n$f(u, v) = 1$, if $d(u,x) \\leq \\rho$,\r\n$g_{i}(y)= 1- f(y, x_{i} ) + \\sum_{i \\ne j} f(y, x_{i})$. Then\r\n$P_{i}= \\sum_{y} P(y | x_{i}) g_{i}(y) =\r\n\\sum_{y} P(y|x_i ) [1- f(y, x_{i} )] + \\sum_{y} \\sum_{i \\ne j}\r\nP(y | x_i ) f(y, x_{i})$. So,\r\n$P_{C}= min_{C} [{\\frac {1} {M}}  \\sum_{i} (\\sum_{y}\r\n\\sum_{y} P(y|x_i ) [1- f(y, x_{i} )] + \\sum_{y} \\sum_{i \\ne j}\r\nP(y | x_i ) f(y, x_{i}))]$. Now,\r\ntaking expectations over all eligible $C$\r\nand using the fact that at least one particular $C$ must have $P_C \\leq$\r\nthe expected value of $P_C$  over all $C$, we get\r\n$P_{C} \\leq  [{\\frac {1} {M}} \\sum_{i}\r\n\\sum_{y} E(P(y|x_i ) [1- f(y, x_{i})]) + \\sum_{y} \\sum_{i \\ne j}\r\nE(P(y | x_i )) E(f(y, x_{i}))]$. Now,\r\nlet $N_e$ be the number of received bits in error in\r\na string of length $n$,\r\nthen $E(N_{e})= np$ and $Var(N_{e})= {\\sqrt {npq}}$.  Set\r\n$b= {\\sqrt {\\frac {npq} {\\frac \\epsilon 2}}}$ then\r\n$P(n_e > np + b ) \\leq {\\frac \\epsilon 2}$ by Chebychev. If $B_{\\rho}(x)$\r\nis the set of words of distance $\\leq \\rho$.  So, we get\r\n$ P_C \\leq {\\frac {\\epsilon} 2} + M^{-1} \\sum_i \\sum_y \\sum_{i \\ne j}\r\nE(P(y | x_i )) E(f(y, x_i )) \\leq {\\frac {\\epsilon} {2}} +\r\n(M-1) 2^{-n} {|B_{\\rho})|}$.\r\nNow $\\rho = pn$ and $B_{\\rho}(x)= \\sum_{i \\leq \\rho} { n \\choose i}$.  But\r\n$1= [\\lambda +( 1- \\lambda )]^{n}= \\sum_{k=0}^{pn} {n \\choose k} \\leq\r\n\\lambda^{pn} (1-\\lambda)^{n(1-p)} \\sum_{k=0}^{pn} {n \\choose k}$.  So,\r\n$2^{-nH(p)} \\geq \\sum_{k=0}^{pn} {n \\choose k}$.  Putting this back in the\r\nequation for $P_C$\r\nwe get\r\n$P_C \\leq {\\frac \\epsilon 2} + (M-1) 2^{-n(1+H(p))} \\leq\r\n2^{n(R-1-H(p))}$ which goes to 0 if $R < 1+H(p)$.\r\n\\end{quote}\r\n{\\bf Definitions:} $(n,M,d)$ \\emph{codes} $M$ is number of codewords, $d$ is minimum distance,\r\n$n$ is dimension.\r\nAn $[n,k,d]$ \\emph{linear code} is an $k-$subspace of an\r\n$n-$ space over $F$ with minimum distance $d$.  The \\emph{standard form for a generator} is\r\n$G= (I_k | A)$ with\r\n$k$ message bits, $n$ codeword bits.  Codeword $c=mG$ and\r\n$d=min_{u \\ne 0, u \\in C} \\{ wt(u) \\}$.\r\nThe \\emph{parity check matrix}, $H$, of\r\na code is the generator of its dual code. $C^{\\perp} = \\{x: (x,y)))= 0,\r\n\\forall y \\in C \\}$.  \r\nNote that $GH=0$.\r\nIf $C$ is a code, $C^{\\perp}$ is a code (the \\emph{dual code}).  \r\n$H=(-A^T, I_{n-k})$, $GH^T=0$.  Consider a table with the codewords forming the first\r\nrow, subsequent rows add error $e$ until all $2^n$ blocks are in the table.  \r\nEach row is a coset and the element of minimum weight in each row is called the\r\ncoset leader. To decode received word $r=c+e$: (1) compute syndrome $s(r)= rH^T$,\r\n(2) find coset leader with $s(r)$ and locate the codeword, $c_0$ in that column,\r\n(3) decode as $r-c_0$.\r\n\\\\\r\n\\\\\r\nDefine $V(n,r)= \\sum_{j=1}^r {n \\choose j}$.\r\n{\\bf Hamming Bound:} $| C | \\leq {\\frac {2^n} {V(n,e)}}$.\r\n{\\bf Sphere Packing Bound:} If $d=2e+1$, $A_{q}(n,d) \\sum_{k=0}^e {n \\choose k}\r\n(q-1)^{k} \\leq q^{n}$.\r\n{\\bf GSV Bound:} $A(n,d) \\geq {\\frac {2^n} {V(n, d-1)}}$, where\r\n$A(n,d)$ is the largest code with minimum distance $d$.\r\n\\\\\r\n\\\\\r\n{\\bf Hamming Codes:}\r\nA \\emph{Hamming code} is a $[n,k,d]$ linear code with\r\n$n= 2^m -1$, $k= 2^m -1 -m$ and $d=3$.  To decode, if $r=c+e$ is received\r\n(1) calculate $s(r)= rH^T$, (2) find $j$ which is the column of $H$ with syndrome\r\n$s(r)$, correct position $j$.  The $[7,4]$ code has encoding matrix\r\n$$\r\nC=\r\n\\left(\r\n\\begin{array}{ccccccc}\r\n1 & 0 & 0 & 0 & 0 & 1 & 1\\\\\r\n0 & 1 & 0 & 0 & 1 & 0 & 1\\\\\r\n0 & 0 & 1 & 0 & 1 & 1 & 0\\\\\r\n0 & 0 & 0 & 1 & 1 & 1 & 1\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nwith check equations\r\n$y_1+y_3+y_5+y_6 =0$,\r\n$y_2+y_3+y_6+y_7 =0$,\r\n$y_4+y_5+y_6+y_7 =0$.\r\nFor Hamming, $n= 2^m -1$, $m$ parity checks identify error position.  Motivation\r\nfor BCH is to use another $m$ parity checks which identify $f(j)= j^3$ positions.\r\nRows of Hadamard matrix $H H^{T}=nI$ forms a $(n, 2n, {\\frac n 2})$ code.\r\nLet $A_{i}$ be the number of codewords of weight $i$ for a code $C$, then\r\n$A(z)= \\sum_i A_{i} z^{i}$ is the weight enumerator.\r\n\\\\\r\n\\\\\r\n{\\bf Cyclic Codes:}\r\nA \\emph{cyclic code,} $C$, has the property that \r\n$(c_1, c_2, \\ldots , c_n) \\in C \\rightarrow\r\n(c_n, c_1, \\ldots , c_{n-1}) \\in C$.  Denoting $U_n(x)= x^n -1$ we have the following \r\ntheorem:  $C$ is a cyclic code of length $n$ iff its generator \r\n$g(x)= a_0 + a_1 x + \\ldots + a_{n-1}x^{n-1} \\mid U_n(x)$ where codewords $c(x)$\r\nhave the form $m(x) g(x)$.  Further, if $U_n(x)= h(x) g(x)$, $c(x) \\in C$ iff\r\n$h(x)c(x) = 0 \\jmod{U_n(x)}$.\r\n\\emph{Example:} $g(x)= 1+x^2+x^3$ generates $(7,4)$ code.\r\n$g(x)m(x)=c(x)$, $a=(1010), a(x)= 1+x^2$; $g(x) a(x) = c(x)= x^5 + x^4 + x^3 +1$,\r\n$c= (1001110)$.  In shift register implementations, bits come out of $0$-degree\r\nterm, recurrence is shifted into high-degree.\r\nCyclic codes ideals in ${\\mathbb Z}_2 / (x^n - 1)$.  Codewords are multiples\r\nof the generator polynomial $g(x)$. Let $\\alpha$ be a primitive element\r\nof $GF(2^m )$.  $[n=2^m -1, k= n-m, d=3]$ hamming code has parity check\r\n$H= (1, \\alpha , \\alpha^2 , \\alpha^3 , \\ldots , \\alpha^{2^m - 2})$.\r\nIf $g(x)$ is the generator for $\\alpha$, generator matrix is\r\n$$\r\nC=\r\n\\left(\r\n\\begin{array}{ccc}\r\ng(x) & 0 & 0\\\\\r\n0 & xg(x) & 0\\\\\r\n0 & 0 & x^2 g(x)\\\\\r\n...\\\\\r\n\\end{array}\r\n\\right)\r\n$$\r\nFor BCH with $[n=2^m -1, k= n-2m, d\\geq 5]$, $g(x)= M^{(1)}(x)M^{(3)}(x)$\r\nwhere $M^{(3)}(x)$, is the minimum polynomial for $\\alpha^3$.\r\n\\\\\r\n\\\\\r\n{\\bf BCH codes:}\r\nIf $g(x) | x^n - 1$, the ideal generated by $g(x)$ is a cyclic code.\r\nIf $g(x)$ factors into linear factors in $GF(2^n)$ with roots\r\n$A= \\{ \\alpha_1 , \\ldots , \\alpha_r \\}$,  the\r\nset $C$ defined by $f(x)  \\in\r\nC$ iff $f(\\alpha)= 0, \\forall \\alpha \\in A$ is a\r\ncyclic code.  For BCH, pick $g(x)= m_1 (x) m_2 (x) \\ldots m_r (x)$ of degree\r\n$d$ with each factor irreducible. Let $n-d$ message bits be the high order\r\ncoefficients $C_I (x)$ of an $n-1$ degree polynomial whose remaining terms\r\nare $C_R (x)$ with $C_I (x)= g(x) q(x) + C_R (x)$.  For\r\na 2-ECC, pick $g(x)=  m_1 (x) m_2 (x)$ with\r\n$m_1 (x)$ the irreducible monic polynomial\r\nfor a primitive $n$th root of 1, $\\alpha$ and\r\n$m_2 (x)$ the irreducible monic polynomial for $\\alpha^3$. Alternatively,\r\nsuppose $g(x)$ is a cyclic code and\r\n$\\alpha$ is a primitive $n$th root of $g(x)$ and \r\n$g(\\alpha^l)= g(\\alpha^{l+1})= \\ldots = g(\\alpha^{l+\\delta})=0$ then\r\n$d \\ge \\delta+2$ and the resulting BCH code has weight $d$.  Decoding\r\nBCH for $r=c+e$: (1) compute $(s_1 , s_2)= rH^T$, (2) if $s_1=0$, no error,\r\n(3) if $s_1 \\ne 0$ put ${\\frac {s_2} {s_1}} = \\alpha^{j-1}$, error is in\r\nposition $j$ (of $p \\ne 2, e_j = {\\frac {s_1} {\\alpha^{(j-1)(k+1)}}}$), \r\n(3) $c=r-e$.\r\n\\\\\r\n\\\\\r\n{\\bf Reed-Solomon} code is BCH code over $F_q$ with $n= q-1$. Let $\\alpha$ be a\r\nprimitive root of 1 and choose $d: 1 \\le d < n$ with\r\n$g(x)= (x- \\alpha) (x-\\alpha^2) \\ldots (x- \\alpha^{d-1})$.  The BCH code\r\ngenerated by $g(x)$ is a Reed Solomon code (an MDS code too).\r\n\\\\\r\n\\\\\r\n{\\bf Building codes and Reed Muller:} If $C_1 : (n, M_1, d_1 )$ and\r\n$C_2 : (n, M_2, d_2 )$, $C_3 = C_1 * C_2$ denotes the code where codewords\r\nin $C_3$ are $(u, u+v),\r\nu \\in  C_1 , v \\in  C_2 $.  It is a\r\n$(2n, M_1 M_2 , min(2 d_1 , d_2 ))$ code.\r\n$RM(0,m)= \\{ 0 , 1 \\}$, $RM(r+1, m+1)=  RM(r+1, m) * R(r, m)$. $R(r, m)$ is\r\na $(n_r , M_r , d_r )$ code, with $n_r = 2^m$, $d_r = 2^{m-r}$ and\r\n$M_r = 2^a$, $a= 1 + {m \\choose 1} + \\ldots + {m \\choose r}$.  $R(r,m)$\r\nhas parameters\r\n$[n=2^m , k= 1 + {m \\choose 1} + \\ldots + {m \\choose r}, d=2^{m-r}]$,\r\nit consists of boolean functions\r\nwhose polynomials are of degree \r\n$\\leq m$. $RM(r,m)^{\\perp} = RM(m-r-1,\r\nm)$.\r\n\\\\\r\n\\\\\r\n$R= \\frac {1-H_2 (p)} {1- H_2 (p_e )}$ (4,7) code.\r\n$ U= {\\frac {H(K)} {D}}$, $2^{RN}$ messages $2^{rN}$ meaningful ones,\r\n$2^{H(K)}$ keys.  $2^{H(K)}-1$ keys have probability, q, of spurious\r\ndecryption $R-r=D$. $F$= number of false ones.\r\n$F=(2^{H(K)}-1)q= 2^{(H(K)-D)N}$.  The correct key maps cipher into\r\nmeaningful class always.  False keys map cipher into meaningful/meaningless\r\nrandomly.  After how many message is the expected number of spurious keys\r\nwhich map all the samples into meaningful less than 1?\r\nShannon: $M_{C}$: total message length, $M$: meaningful part,\r\n$p$: probability of error.  $p M_{C}= k$, $2^{M_{C}-M} \\geq\r\n{{M_{C}} \\choose {k}}.$\\\\\r\n\\\\\r\n{\\bf Hadamard Code:}  Let $h_{ij}= (-1)^{a_0 b_0 + \\ldots + a_4 b_4}$,\r\nwhere $a$ and $b$ index the rows and columns respectively.  This gives a\r\n$32 \\times 32$ entry matrix, $H$.  Let generators be $G= [H |  -H]^T$.\r\nFor each of the $0 \\le i <2^6$ possible messages, send the row corresponding to \r\n$i$.\r\nTo \\emph {decode Hadamard}, for the $32$ bit received word, $r$, compute $d_i= r \\cdot R_i$,\r\nwhere $R_i$ is the $32$ bit row $i$.  If there are no errors, the correct row will\r\nhave $d_i=32$ and all other rows will have $d_i=0$.  If one error, $d_i=30$, etc.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} The\r\n\\emph{Golay Code} ${\\cal G}_{24}$ is a $[24, 12,8]$ linear code. \r\n$G= [I_{12} | C_0 | N] = [I | B]$ \r\nwhere $C_0= (1,1,1,1,1,1,1,1,1,1,1,0)^T$\r\nand $N$ is formed by circulating $(1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0)$\r\n$11$ times and appending an row of $11$ 1's.\r\nThe first row of $N$ corresponds to the quadratic residues $\\jmod{11}$.\r\nNote that $wt(r_1 + r_2) = wt(r_1) + wt(r_2) - 2 [r_1 \\cdot r_2]$,\r\nall codewords have weight divisible by $4$ and $d(C)=8$.  \r\n${\\cal G}_{24} = {\\cal G}_{24}^{\\perp}$.\r\n\\\\\r\n\\\\\r\n{\\bf Decoding the Golay code:} Let\r\n$G=[I_{12} | B]$ and $B^T= (b_1 , b_2 , \\ldots, b_{12})$ with $b_i$ a column vector.\r\nSuppose $r=c+e$ is received and $wt(e) \\le 3$.  Put $s= rG^T$ and compute\r\n$sB$, $s+c_i^T$, $1 \\le i \\le 24$ and $sB+b_j^T$, $1 \\le j \\le 12$. If\r\n$wt(sB) \\le 3$, there is a non-zero entry in the $k$-th position of $sB$ if\r\nthe $k+12$-th position of $e$ is non-zero.   If $wt(s) \\le 3$ a non-zero entry in\r\n$s$ at position $k$ corresponds to a non-zero entry in position $k$ of $e$.  \r\nIf $wt(s+c_j^T) \\le 2$, for some $j$, $13 \\le j \\le 24$ then $e_j=1$ and non-zero\r\nentries of $s+e_j^T$ are in the same positions as non-zero entries of $e$.\r\nIf $wt(sB+b_j^T) \\le 2$, for some $j$, $1 \\le j \\le 12$ then $e_j=1$ and non-zero\r\nentries of $sB+b_j^T$ at position $k$ correspond to non-zero entries of $e_{k+12}$.\r\n\\\\\r\n\\\\\r\n{\\bf Reed-Solomon construction:} \r\nFix $n$ elements, $\\langle \\alpha_1 , ..., \\alpha_n \\rangle$, \r\n$|F| \\geq n$, $E(m)= \\langle M\\alpha_1 , ..., M\\alpha_n \\rangle$, $d(E(m_1,m_2)) \\leq n+k-1$.\r\n\\subsection{The Leech Lattice and the Conway groups}\r\n{\\bf Background:} \r\nVolume of $n$-sphere is $V_n r^n$ where $V_n= {\\frac {\\pi^{n/2}} {\\Gamma({\\frac n 2}+1)}}$.\r\n\\emph{Rogers Bound} is obtained by forming convex hull of $n+1$-simplex with spheres on\r\nvertices; volume interior to simplex and spheres forms upper bound.\r\n$RB(n)=\r\n{\\frac {{\\sqrt {(n+1)}} (n!)^2 \\pi^{\\frac n 2}} {2^{\\frac {3n} {2}} \\Gamma({\\frac n 2}+1)}}\r\nf_n(n)$,\r\n$F_{n+1}(\\alpha) = \r\n{\\frac 2 {\\pi}} \\int^{\\alpha}_{\\frac {arcsec(n)} 2} F_{n-1}(\\beta) d \\theta$,\r\n$sec(2 \\beta) = sec( 2 \\theta ) - 2$, $F_1(\\alpha) = F_0 ( \\alpha ) = 1$, \r\n$f_n (sec (2 \\alpha))=\r\nF_n(\\alpha)$.  $RB(3)= .7404$.  $A_1 = 0$, $A_{2n}=\r\n\\left( \\begin{array}{cc}\r\nA_n & A_n \\\\\r\nA_n & {\\overline {A_n}}\r\n\\end{array}\r\n\\right)$.\r\n\\\\\r\n\\\\\r\n$L_8$:  $v \\in L_8$ iff $v \\in {\\mathbb Z}^8$ and $v_i = a_i \\jmod{2}$ or\r\n$v_i = {\\overline a_i} \\jmod{2}$.\\\\\r\nGenerator matrix:\r\n$\\left(\r\n\\begin{array}{cccccccc}\r\n1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\\\\r\n2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n0 & 2 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\r\n\\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots & \\ldots \\\\\r\n0 & 0 & 0 & 0 & 0 & 0 & 2 & 0 \\\\\r\n\\end{array}\r\n\\right)$.\r\n\\\\\r\n\\\\\r\n$L_8 \\rightarrow \\Lambda_8$:  $v \\in \\Gamma_8$ iff\r\n$v \\in L_8$ and $\\sum_{i=1}^{8} v_i = 4m$.  Contact number: $112+128=240$, radius: ${\\sqrt 2}$.\r\n\\emph{Alternate definition} of $\\Lambda_8$: $8$-tuples whose spheres are congruent $\\jmod{2}$ to\r\nrows of $A_8$ or ${\\overline {A_8}}$.\r\nDensity is ${\\frac {\\pi^4}{4!2^4}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nLet $R(C)$ be the row space of ${\\cal G}_{24}$ over $GF(2)$.  \r\nDefine the \\emph{Leech Lattice}, $\\Lambda_{24}$,\r\nas the vectors that satisfy the following conditions:\r\nExpress coordinates in $E_{24}$ in binary and retain the ones that satisfy\r\nthe following conditions (a) the $24$ $1$'s bits are either all $0$ or all $1$, (b)\r\nthe $2$'s bits form a row in $R(C)$, (c) $4$'s bits rows have even parity for points\r\nwith $1$'s bits that are all $0$ and odd otherwise. This is equivalent to the following:\r\nSuppose ${\\vec c} \\in R(C)$ and for $m \\in {\\mathbb Z}$, define\r\n${\\vec c}(m)= \\{  \r\nv \\in {\\mathbb Z}^{24}:  \\sum_i v_i = 4m, \r\nc_i = 0 \\rightarrow v_i = m \\jmod{4},\r\nc_i = 1 \\rightarrow v_i = m+2 \\jmod{4}\r\n\\}$,\r\n$\\Lambda = \\Lambda_{24}= \\cup_m {\\vec c}(m)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}   In $\\Lambda$, lattice points are seperated by a minimum\r\ndistance of $4 {\\sqrt 2}$.  Lattice points a minumum distance from the origin\r\nhave shapes: $(0^{16}, (\\pm 2)^8)$, $(0^{22}, (\\pm 4)^2)$, $((\\pm 1)^{23}, (\\pm 3))$.  \r\nHence the contact number is $98256$ (lattice point with even parity) + $98304$ \r\n(lattice point with odd parity) $= 196,560$;  \r\nthe density is $.001929$.  Each pair of adjacent lattice points is adjacent to $4600$\r\nothers. \\emph{Example:} $(4,4, 0, \\ldots, 0)$\r\nis adjacent to $(4,0, \\ldots , 0)$ - there are $88$ of these,\r\n$(2,2, \\ldots , 0)$ - there are $77 \\times 2^7$ of these and\r\n$(1,3, \\ldots , 0)$ - there are $2048$ of these.\r\nFor the first Leech packing,\r\nthe density is ${\\frac {2^{24}} { 2 \\times 2^{12}}}= 2^{-11}$, \r\nfirst factor of $2$ in \r\ndenominator is from condition that the sum of the\r\ncoordinates $= 0 \\jmod{4}$ and so the packing density is $.0009647$.  The\r\nLeech lattice doubles this which is about $.8$ of the Rogers bound.\r\n\\\\\r\n\\\\\r\nNoting that there must be an even number of $-2$'s,\r\nfor the Leech packing, lattice points with even coordinates are:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$0^{16}, (-2)^8$ & $759$ \\\\\r\n$0^{16}, (-2)^6, 2^2$ & $759 \\cdot {8 \\choose 2}=21252$ \\\\\r\n$0^{16}, (-2)^4, 2^4$ & $759 \\cdot {8 \\choose 4}=53130$ \\\\\r\n$0^{16}, (-2)^2, 2^6$ & $759 \\cdot {8 \\choose 2}=21252$ \\\\\r\n$0^{16}, 2^8$ & $759$ \\\\\r\n$0^{22}, (-2)^2$ & ${24 \\choose 2}=276$ \\\\\r\n$0^{22}, -2, 2$ & $ 24 \\cdot 23 =552$ \\\\\r\n$0^{22}, 2^2$ & ${24 \\choose 2}=276$ \\\\\r\n\\hline\r\n{\\bf Total} & $98256$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThe lattice points with odd coordinates are:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|}\r\n\\hline\r\n{\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$(-1)^{23}, 3$ & $24$ \\\\\r\n$(-1)^{16}, (1)^{7}, -3$ & $759 \\cdot 8= 6,072$ \\\\\r\n$(-1)^{15}, (1)^{8}, 3$ & $759 \\cdot 16= 12,144$ \\\\\r\n$(-1)^{12}, (1)^{11}, -3$ & $2576 \\cdot 12= 30,912$ \\\\\r\n$(-1)^{11}, (1)^{12}, 3$ & $2576 \\cdot 12= 30,912$ \\\\\r\n$(-1)^{8}, (1)^{15}, -3$ & $759 \\cdot 16= 12,144$ \\\\\r\n$(-1)^{7}, (1)^{16}, 3$ & $759 \\cdot 8= 6,072$ \\\\\r\n$(1)^{23}, -3$ & $24$ \\\\\r\n\\hline\r\n{\\bf Total} & $98304$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\nThere are \r\n$4600$ vertices adjacent to $2$ adjacent simplex,\r\n$891$ vertices adjacent to $3$ adjacent simplex,\r\n$336$ vertices adjacent to $4$ adjacent simplex and\r\n$170$ vertices adjacent to $5$ adjacent simplex.  \r\nThis gives a dihedral like estimate on the size of the symmetry group.\r\n\\\\\r\n\\\\\r\n{\\bf Definition of\r\nConway's group:} ${\\bf .O}$ is the set of rotations in ${\\mathbb R}^{24}$ fixing $O$ \r\npointwise and $\\Lambda$ setwise.\r\n\\\\\r\n\\\\\r\n{\\bf Notation:}\r\n$v_S= \\sum_{i \\in S} v_i$. \r\n$Q= \\{ x^2: x \\in F_{23} \\}, N= \\Omega \\setminus Q$.\r\n$A+B= A \\setminus B \\cup B \\setminus A$.  $N_i= \\{ n-i, n \\in N \\}$.  Golay code,\r\n${\\cal C}$, is\r\ngenerated by $N_i, N_{\\Omega}$.  $N_A = \\sum_{a \\in A} N_a$.  $C \\in {\\cal C}$ iff $N_C=0$.\r\n$\\Omega= PL(23)$, $\\alpha: x \\mapsto x+1$, $\\beta: x \\mapsto 2x$,\r\n$\\gamma: x \\mapsto {\\frac {-1} x}$, \r\n$\\delta: x \\mapsto 9 x^3, x \\notin Q$ and\r\n$\\delta: x \\mapsto {\\frac {x^3} 9}, x \\in Q$.  \r\n$L_2(23)= PSL_2(23)= \\langle \\alpha, \\gamma \\rangle$,\r\n$M_{24}= \\langle \\alpha, \\gamma, \\delta \\rangle$.  If $\\pi \\in S_{\\Omega}$, define\r\n$(v_i)^{\\pi} = v_{\\pi(i)}$.  \r\n$\\epsilon_S(v_i) = -v_i, i \\in S$ and\r\n$\\epsilon_S(v_i) = v_i, i \\notin S$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nThe set $G \\Lambda = \\{ 2 v_K, K \\in R(C) \\} \\cup\r\n\\{ v_{\\Omega} - 4 v_{\\infty} \\}$ generates $\\Lambda$.  If $v, w \\in G \\Lambda$, then\r\n$v \\cdot v= 16n$ and $v \\cdot w = 0 \\jmod{8}$.  \r\n$\\Lambda_n= \\{ x  \\in \\Lambda, x \\cdot x = 16n \\}$.  $\\Lambda_1 = \\emptyset$,\r\n$\\Lambda_2$ consists of \r\n$\\Lambda_2^2$ of shape $(0^{16}, (\\pm 2)^8)$ - there are $97152$ of these,\r\n$\\Lambda_2^3$ of shape $((\\pm 1)^{23}, (\\pm 3)^1)$ - there are $98,304$ of these,\r\n$\\Lambda_2^4$ of shape $(0^{22}, (\\pm 4)^2)$ - there are $1104$ of these.\r\nIn tabular form:\r\n\\begin{center}\r\n\\begin{tabular} {|r|r|r|}\r\n\\hline\r\n{\\bf Name} & {\\bf Shape} & {\\bf Number} \\\\\r\n\\hline\r\n$\\Lambda_2^2$ & $0^{16}, \\pm 2^8$ & $759 \\cdot 2^7$\\\\\r\n\\hline\r\n$\\Lambda_2^3$ & $\\pm 1^{23}, \\pm 3$ & $24 \\cdot 2^{12}$\\\\\r\n\\hline\r\n$\\Lambda_2^4$ & $0^{22}, \\pm 4^2$ & ${24 \\choose 2} \\cdot 2^2$\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{center}\r\n{\\bf Notation:}\r\nIf $S \\in R(C)$, $\\epsilon_S \\in .O$.\r\n$E= \\langle \\epsilon_S \\rangle_{S \\in R(C)}$, $M= M_{24}$.  $N= EM$.\r\n$T_0= \\{0, 3, 15, \\infty \\}$,\r\n$T_1= \\{ 1,12,21,22 \\}$,\r\n$T_2= \\{ 2,7,11,13 \\}$,\r\n$T_3= \\{ 4,10,16,17 \\}$,\r\n$T_4= \\{ 5,6,9,19 \\}$,\r\n$T_5= \\{ 8, 14,18,20 \\}$,\r\n$B= \\{ T_0, T_1, T_2, T_3, T_4, T_5 \\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\n$\\lambda \\in .O$ and $\\lambda$ fixes $v_i$ (some $i$) iff $\\lambda \\in N$.\r\n\\begin{quote}\r\n\\emph{Proof of $\\rightarrow$:}\r\nSuppose $\\lambda \\in .O$ and $\\lambda(v_i)= v_i$.  If $\\lambda(v_j)= w_j, i \\ne j$ then\r\n$(v_i, w_j)= 0$.  Since $4 v_i + 4 v_j \\in \\Lambda_2$,\r\n$4 v_i + 4 w_j \\in \\Lambda_2$.  Examining the elements of $\\Lambda_2$, we see\r\n$w_j= \\pm v_k$ for some $k \\in \\Omega$ since $8w_j \\in \\Lambda$ and $4w_j \\notin \\Lambda$.\r\nDistinct values of $j$ yield distinct values of $k$.  Thus $\\lambda= \\pi \\epsilon_S$,\r\n$S \\subseteq \\Omega, \\pi \\in S_{24}$.  The non-zero coordinates of\r\n$\\lambda( 2 v_K ), K $ an octet are in the coordinate postions $\\pi(K)$, so\r\n$\\pi(K)$ is an octet and  $\\pi \\in M_{24}=M$.  $\\lambda( v_{\\Omega} - 4 v_{\\infty})$ is\r\na lattice point of the same shape and the coordinates are $=1 \\jmod{4}$.\r\n$\\epsilon_S: v_i \\mapsto -v_i, i \\in S$ so the coordinates of\r\n$\\lambda( v_{\\Omega} - 4 v_{\\infty})$ which are $= 3 \\jmod{4}$ are in the places\r\n$\\pi(S)$ and so $S \\in R(C)$.  So $\\lambda = \\pi \\epsilon_S \\in N$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $\\lambda(\\Lambda_2^4)= \\Lambda_2^4$ then\r\n$\\lambda \\in N$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe use the following lemma:\r\n\\\\\r\n\\emph{Lemma:} If $\\lambda \\in .O$ and $|\\lambda|= p$, a prime then $p \\le 23$ further,\r\nno element of $.O$ has order $13 \\cdot 23$.\r\n\\\\\r\n\\\\\r\nLet $H$ be the symmetries fixing $\\Lambda_2^4$ as a whole and $x= 4v_i +4v_j$\r\nand $N_x$ is the subgroup fixing $x$.  $N$ only changes signs and permutes\r\ncoordinates so $N: \\Lambda_2^4 \\rightarrow \\Lambda_2^4$ and fixes\r\n$\\Lambda_2^4(x)$ as a whole.  There are $2^2 {22 \\choose 2}= 924$ vectors\r\nof the form $\\pm 4 v_h \\pm 4 v_k$ are perpendicular to \r\n$\\pm(4 v_i - 4 v_j)$ with\r\n$h, i, j,k$ distinct and so are\r\n$\\pm(4 v_i - 4 v_j)$.  These $926$ vectors form\r\n$\\Lambda_2^4(x)$.  $N_x$ is $2$-transitive so $\\exists \\sigma: \r\n(4 v_i - 4 v_j) \\mapsto \\pm (4 v_i - 4 v_j) $ and no other elements are in this orbit.\r\nThus $\\{ (4 v_i - 4 v_j), -(4 v_i - 4 v_j) \\} $ form a single orbit.\r\n$N_x \\subseteq H_x$ and the orbits of $H_x$ are a union of $N_x$ orbits.  As a result,\r\nit is either all $926$ orbits or the $N_x$ orbits.  In the latter case,\r\n$|H_x: H_{x,y}| = 926= 2 \\cdot 463$ which contradicts the lemma.\r\nSo we know $H_x$ has $2$ orbits on $\\Lambda_2^4(x)$ and maps \r\n$(4 v_i - 4 v_j)$ to itself or it's negative.  In the first case, $\\lambda(v_i)= v_i$ and\r\n$\\lambda \\in N$ by the\r\nprevious theorem.  In the second case, $\\lambda( v_i)= v_j$ and hence\r\n$ (4 v_i + 4 v_h)  \\mapsto (\\pm 4 v_j \\pm 4 v_k) , h \\ne j $ and again $\\lambda \\in N$.  Thus\r\n$H_x \\subseteq N$ and $H_x \\subseteq N_x$ and therefore $H \\subseteq N$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nThere is a subgroup isomorphic to $L_2(23)$ which is\r\ntransitive on octads. \r\n\\begin{quote}\r\n\\emph{Proof:} \r\nThere is a copy of $L_2(23)$ in $M_{24}$.\r\n\\end{quote}\r\n{\\bf Definition:} $\\epsilon(v_i) = \r\nv_i \\textnormal{ if } i \\notin Q \\textnormal{ and } -v_i \\textnormal{ if } i \\in Q $.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $N= \\langle \\alpha, \\beta, \\gamma, \\delta, \\epsilon \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nApplying permutations from the right, note $\\epsilon_K= \r\n\\epsilon \\alpha  \\delta \\alpha  \\epsilon \\alpha^{-1} \\delta^{-1} \\alpha^{-1}$, \r\n$K= \\{ 0,1,4,5,11,12,14,22 \\}$.  If $L$ is another $8$-set and $\\theta: K \\rightarrow L$ then\r\n$\\epsilon_L = \\theta^{-1} \\epsilon_K \\theta$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$N$ is a proper subgroup of $.O$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $T=T_0$ be any $4$-set of $\\Omega$.  $T$ lies in $5$, $8$ sets\r\n$ T+T_1, T+T_2, \\ldots, T+T_5$, where $T_i$ is the complement of\r\n$T$ in the $i$-th $8$-set.  $\\Omega$ is the disjoint union of\r\n$6$, $4$-sets.  $B= \\{ T_0 , T_1 , \\ldots , T_5 \\}$.\r\n$\\eta= \\eta_B: v_i \\mapsto v_i- {\\frac 1 2} v_{T_j}$ and\r\n$\\zeta_T= \\eta \\epsilon_T$.  $\\zeta_T^2=1$.  $\\zeta_T \\in .O$ and\r\n$\\zeta_T \\notin N$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$H_x$ is transitive on $\\Lambda_2(x)$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nLet $x= v_{\\Omega}- v_{\\infty}$.  The order of each orbit of $H_x$ on $\\Lambda_2(x)$\r\nhas order divisible by $23$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $H>N$, $H$ is transitive on $\\Lambda_2$ and $H=.O$.  $|.O|=\r\n2^{22} \\cdot 3^{9} \\cdot 5^4 \\cdot 7^2 \\cdot 11 \\cdot 13 \\cdot 23= 8,315,553,613,086,720,000$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n(1) $\\Lambda_2^2$, $\\Lambda_2^3$, $\\Lambda_2^4$ are all $N$-orbits.  \r\nA counting argument shows that the union of two\r\nof them can't be an $H$ orbit (otherwise, $p \\mid |.O|$ for $p>23$).  Now define\r\n$\\Lambda_2 (x)= \\{ y: y \\in \\Lambda_2, y \\perp x \\}$.\r\nRecall $H_x$ is transitive on $\\Lambda_2(x)$.\r\nSince $M_{24}$ is $5-$transitive $|H_x : H_{x,y}|= 926$ and\r\n$|.O|= |H| = 196560 \\cdot |H_x|$; further,  $H_x$ is transitive on \r\n$\\Lambda_2 (x)= \\{ y: y \\perp x \\}$.  An orbit of $H_x$ has $93150$ elements so\r\n$|H_x|= (93150) |H_{x,y}|$ and $H_{x,y} = E_{10} M_{22}$.  This gives the order of\r\n$H$ and shows $H=.O$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nFor $x \\in \\Lambda_2$, define $\\{ x , -x \\}$ is called a diameter.\r\n${\\overline {\\Lambda_2}}$ is the set of $98280$ diameters.\r\n$.1= .O_d, d= \\{x, -x \\}, x \\in \\Lambda_2$ \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} $N$ is maximal in $.O$.  $.O= \\langle N, \\zeta \\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nBy the theorem, if $H>N$, $H=.O$.  The second statement follows from $\\zeta \\notin N$ and $\\zeta \\in .O$.\r\n\\end{quote}\r\n{\\bf Theorem:} \r\n$.O$ is transitive on ordered pairs of points of vectors of $\\Lambda_2$ with a\r\ngiven scalar product.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$\\Lambda_2= \\{ v \\in \\Lambda: v \\cdot v= 16 \\cdot 2 \\}$.  By looking at products of\r\nvectors of standard type, the possible products are\r\n$0, \\pm 8, \\pm 16, \\pm 32$.  Put $\\Lambda_2(x,m)= \\{y: (x,y)= m \\}$.\r\nWe find orbits of $N_x$ on $\\Lambda_2(x,16)$ and show \r\n$\\Lambda_2(x,16)$ is a single orbit of $.O_x$.\r\n\\end{quote}\r\n{\\bf Observation:}\r\nLet $\\varphi$ be an octad, say $\\{ 0,1,2,3,4,7,10,12 \\}$,\r\nand $i \\notin \\varphi$; suppose $K$ is the subgroup fixing $\\varphi$,\r\nsetwise and $H= K_i$.  The subset fixed is of codimension $8$ so it has dimension $4$.  $K$\r\nacts naturally on this $4$-dimensional subspace.  $K \\approx 2^4 L_4(2)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} \r\n$.1 \\cong .O/{\\mathbb Z}(.O)$ and\r\n$|{\\mathbb Z}(.O)|= 2$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose $\\lambda \\notin \\{\\pm1\\} \\in {\\mathbb Z}(.O)$.\r\n$\\theta_i= \\alpha^{23-i} \\gamma \\alpha  \\gamma \\alpha^i $ fixes $i$ and moves all other\r\npoints of $\\Omega$.  \r\n(1) $\\lambda$ cannot send $v_j \\mapsto \\pm v_j, \\forall j$ since\r\n$(v_j)\\lambda \\alpha = - v_{j+1}$ and\r\n$(v_j)\\alpha \\lambda= v_{j+1}$.  \r\n(2) $\\lambda$ cannot map $v_i \\mapsto \\pm v_j, i \\ne j$, \r\n$(v_i) \\lambda \\theta_i= \\pm (v_j) \\theta_i= \\pm v_k \\ne \\pm  v_j$, but\r\n$(v_i) \\theta_i \\lambda= \\pm (v_j)$.\r\n(3) Remaining case, namely, $\\lambda: v_i \\mapsto w \\ne \\pm v_j, j \\in \\Omega$ is impossible too.\r\nIf $(v_j)\\lambda = w \\ne \\pm v_k$, any $k$.  $(8v_i)\\lambda \\in \\Lambda_4$ and has one of the following\r\nform $(0^{23},\\pm 8^{1})$, $(\\pm 0^{20},\\pm 4^{4})$, $(\\pm 0^{16},\\pm 2^{7}, \\pm 6^{1})$,\r\n$(\\pm 0^{14},\\pm 2^{8}, \\pm 4^{2})$, $(\\pm 0^{11},\\pm 2^{12}, \\pm 4^{1})$, $(\\pm 0^{8},\\pm 2^{16})$,\r\n$(\\pm 1^{21},\\pm 3^{2}, \\pm 5^{1})$, $(\\pm 1^{19},\\pm 3^{5})$.  The only one fixed by $\\theta_i$ is\r\n$8v_i$.  Thus\r\n$(v_i) \\lambda \\theta_i = (w)\\theta_i \\ne w$ but\r\n$(v_i) \\theta_i \\lambda= w$ and the theorem holds.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$.1$ acts primitively on ${\\overline {\\Lambda_2}}$.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nEach element of $.1$ permutes $98280$ diameters.  Since $.O$ is transitive on\r\n$\\Lambda_2$, $.1$ is transitive for diameters.  Suppose\r\n$.1$ is imprimitive.  $|S_1| \\mid 98280$.  Let ${\\overline x} \\in S_1$.\r\nSince $|S_1| \\ge 1, \\exists y \\in S_1$ whose orbit under $.1_{\\overline x}$\r\nhas order $4600, 47104, 46575$.  Since $.1$ fixes ${\\overline x}$,\r\n$.1: S_1 \\rightarrow S_1$ and $|S_1| \\ge 4601$.  None divide\r\n$98280$ so $\\exists {\\overline z} \\ne {\\overline x}$ outside $S_1$.\r\nBut then $S_1$ which has at least $1+4600+46575=51176$ and thus must be all of\r\n${\\overline {\\Lambda_2}}$.  This contradicts the assumed imprimitivity of $.1$.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\n$.1= .O/{\\mathbb Z}(.O)$ is simple.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nSuppose ${\\mathbb Z}(H) \\subsetneq H \\subsetneq .O$.  \r\n(1) $H$ is transitive on ${\\overline {\\Lambda_2}}$.\r\nIf not $\\exists {\\overline x}= \\{x, -x\\}$\r\nand $y \\in \\Lambda_2: \\eta(x)= y, \\eta \\in H$.  $.O$ is transitive on\r\n${\\overline {\\Lambda}}_2$.  Orbits of $H$ in ${\\overline {\\Lambda}}_2$ are of\r\nequal size.\r\n(2) $N$ is not normal in $.0$.  This is proved by looking at $B$, the $4$-subsets defined above.\r\n(3) $H=N$.  $|H:H_x|= 13 \\cdot 7560$.  Let $P \\in S_{13}$.  Since $H$ is normal, all the sylow $13$\r\nsubgroups of $.O$ are in $H$ so\r\n$|>O:N_{.O}(P)= |ccl_{.O}(P)|=\r\n|ccl_{H}(P)|= |H:N_H(P)|$ and $|.O:H|= |N_{.O}(P):N_H(P)|$ with $N_H(P)= N_{,O}(P) \\cap H$.\r\nThus $|.O|= |N_{.O}(P)H|= {\\frac\r\n{|N_{.O}(P)| \\cdot |H|}\r\n{|N_{.O}(P) \\cap H|}}$ and\r\n$23 \\mid |N_{.O}(P)|$ or $23 \\mid |H|$.  In the former case, put\r\n$K= \\langle \\lambda \\rangle$,\r\n$P= \\langle \\mu \\rangle$, $|\\lambda|= 13$, but then $|PK|=13 \\cdot 23$ which contradicts an\r\nearlier lemma.  In the latter case,  $23 \\mid |H|$ so $H \\cap N = N$ but $N$ is maximal so\r\n$H=N$.\r\nNow we have $H \\lhd .O$ and $H=N$ but $N$ is not normal and this establishes the result.\r\n$\\zeta \\in .1: x \\mapsto z$,\r\n$\\lambda \\in H: x \\mapsto w$.\r\n$\\zeta(w)= \\zeta(\\lambda(x))= \\zeta \\lambda \\zeta^{-1}(z)$ is in orbit of $z$\r\nsince $\\zeta \\lambda \\zeta^{-1} \\in H$.  $.1$ preserves orbits in\r\n$\\Lambda_2$ and the orbits are sets of imprimitivity for $.1$ on\r\n${\\overline {\\Lambda}}_2$ which contradicts the previous result.\r\nFor $x \\in {\\overline {\\Lambda}}_2$, \r\n$|H:H_x|=|{\\overline {\\Lambda}}_2| = 98280= 13 \\cdot 7560$.\r\nLet $P \\in S_{13}(H)$ all such are $H$ conjugate and\r\n$|.O:N_{.O}(P)|= |H:N_H(P)|$.\r\n\\end{quote}\r\n{\\bf Conway's other simple groups:} \r\n$.2= \\{ x \\in .O$, $x$ stabilizes\r\n$2$ points $v,w \\in \\Lambda_2: |v-w|= 4 {\\sqrt 2} \\}$.\r\n$.3= \\{ x \\in .O$, where $x$ stabilizes\r\n$2$ points $v,w \\in \\Lambda_2: |v-w|= 4 {\\sqrt 3} \\}$.\r\n", "meta": {"hexsha": "1642b0fbd8eac77d2d3508644c2f4ae85942018b", "size": 53131, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math5.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/math5.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/math5.tex", "max_forks_repo_name": "jlmucb/class_notes", "max_forks_repo_head_hexsha": "b8571df2dca933f6594a16eb02b581d38ca4ccfd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.7702464789, "max_line_length": 188, "alphanum_fraction": 0.5813931603, "num_tokens": 21728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9416541610257063, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7631908303070365}}
{"text": "\\section*{Ex.3.1}\n\\subsection*{what is it to be $k$-independence}\nDefine $k$-independence as: Given $k$ distinct keys $x_1,\\ldots,x_k\\in{U}$ and $k$ possibly non--distinct hash values $q_1,\\ldots,q_k\\in[m]$, then it must hold that \n$$\nP(\\bigcap_{i=1}^k (h(x_i)=q_i)) = \\frac{1}{m^k}.\n$$\n\nTo show 3-independece, set $k=3$ in above and \n$$\nP(h(x_1)=q_1 \\land h(x_2)=q_2 \\land h(x_3)=q_3) = \\frac{1}{m^3}.\n$$", "meta": {"hexsha": "6068f44ca57ddb7a3080486941eb0139d1c65d4a", "size": 405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.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": "Uge3/Ex.3.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": "Uge3/Ex.3.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": 36.8181818182, "max_line_length": 165, "alphanum_fraction": 0.6395061728, "num_tokens": 179, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9591542840900508, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.7631588799940577}}
{"text": "\\section{Topological data analysis}\n\\label{sec:topological-data-analysis}\n\\textit{Topological data analysis} (TDA) is a fast-growing field of mathematics, providing a set of tools from topology to infer underlying features from data \\cite{chazal2021introduction}. In this section, we will introduce relevant concepts from TDA. In particular, we will introduce the simplicial complex in \\cref{sec:simplicial-complex} and persistence diagrams in \\cref{sec:persistence diagram}. Furthermore, we will introduce a method for vectorizing persistence diagrams, namely the persistence image in \\cref{sec:persistence-image}, and a commonly used distance metric for persistence diagrams, namely the $p$-Wasserstein distance in \\cref{sec:wasserstein-distance}. Finally, we will introduce two algorithms that uses concepts from TDA to identify singular words (or data points), namely topological polysemy in \\cref{sec:topological-polysemy} and Geometric Anomaly Detection in \\cref{sec:geometric-anomaly-detection}. This section is based on \\cite{Edelsbrunner2010,chazal2021introduction}, if not stated otherwise.\n\n\\subsection{Simplicial complex}\n\\label{sec:simplicial-complex}\nIn computer science, a \\textit{graph} is a datatype for describing possibly non-linear and complex relationships between data points. In particular, graphs consist of vertices and edges, where the edges connect the vertices. Edges can also have metadata such as weight and direction. A common graph to use (in the context of computer science) is the $k$-nearest neighbour graph, where vertices are data points and edges represent neighbouring relationships, with distance as weight. A \\textit{simplicial complex} is a generalization of graphs and we see its particular usage in TDA, due to its topological properties. Simplicial complexes consist of \\textit{$n$-simplices}, where $0$-simplices are similar to vertices, $1$-simplices are similar to edges. The difference between graphs and simplicial complexes occur when we look at $n$-simplices for $n \\geq 2$. For example, $2$-simplices form triangles and $3$-simplices form tetrahedrons (i.e. triangular pyramids). We show examples of $n$-simplices in \\cref{fig:n-simplices-example}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.9\\textwidth]{thesis/figures/n-simplices_cropped.pdf}\n    \\caption{Building blocks of simplicial complexes, consisting of $n$-simplices.}\n    \\label{fig:n-simplices-example}\n\\end{figure}\nBy combining one or more $n$-simplices, we form simplicial complexes. We illustrate an example of a simplicial complex in \\cref{fig:simplicial-complex}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.5\\textwidth]{thesis/figures/simplicial-complex_cropped.pdf}\n    \\caption{Simplicial complex consisting of $0$-, $1$-, $2$- and $3$-simplices.}\n    \\label{fig:simplicial-complex}\n\\end{figure}\nThere exist several methods for creating simplicial complexes from data. In particular, we look at one such simplicial complex in the next sub-subsection, namely the Vietoris–Rips complex.\n\n\\subsubsection{Vietoris–Rips complex}\n\\label{sec:vietoris-rips-complex}\nThe \\textit{Vietoris–Rips complex} is a simplicial complex that we create from data points using any distance metric. Let $\\alpha$ be a \\textit{proximity diameter}. We build the Vietoris–Rips complex by forming a simplex for every set of $k$ data points with distance less than or equal to $\\alpha$. That is, if $k$ data points satisfy $d(x_i, x_j) \\leq \\alpha$ (where $d(x_i, x_j)$ computes the distance between two data points $i$ and $j$), we create a $(k-1)$ simplex for that particular data point (1-simplex for two data points, 2-simplex for three data points, etc.). We illustrate with an example of a Vietoris–Rips complex in \\cref{fig:simplicial-complex-rips}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{thesis/figures/simplicial-complex-rips_cropped.pdf}\n    \\caption{A Vietoris–Rips complex on 2-dimensional data with proximity diameter $\\alpha$.}\n    \\label{fig:simplicial-complex-rips}\n\\end{figure}\nBy carefully studying the $n$-simplices of a Vietoris–Rips complex, we can observe topological structures such as \\textit{loops} (i.e. $2$-simplices) or \\textit{holes}  (i.e. $3$-simplices). We show an example of a loop in \\cref{fig:simplicial-complex-rips}, where the rightmost data points at the bottom form a 2-simplex. To study the topological properties of data, it is common to look at varying values of $\\alpha$, starting at zero and increasing to infinity. In particular, we use what we call \\textit{persistent homology}, which is the study of observing how the topology changes once a threshold (e.g. $\\alpha$) increases. To easily present and visualize persistent homology, we use persistence diagrams. We look at persistence diagrams in the next subsection.\n\n\\subsection{Persistence diagram}\n\\label{sec:persistence diagram}\nTo present persistent homology of a simplicial complex, we use \\textit{persistence diagrams}. In persistence diagrams, we look at a range of proximity diameters over multiple persistent \\textit{homology dimensions} (or \\textit{homology degrees}), where the dimension refer to which $n$-simplices we want to look at (0-dimensional persistent homology observe changes of $0$-simplices, 1-dimensional observe changes of $1$-simplices, etc.). A persistence diagram is 2-dimensional, where the x-axis denotes the birth time and the y-axis the death time. Assuming that we want to create a persistence diagram of data points, we let the proximity diameter $\\alpha$ start at zero. By gradually increasing $\\alpha$, new topological properties appear and old topological properties merge into other properties. In particular, once a topological property is \"birthed\" (e.g. 1-simplex between two data points), the birth time is noted for the particular data point. A point in the persistence diagram appears once $n$-simplices merge into new $m$-simplices (e.g. three 1-simplex becoming a 2-simplex).\n\nTo motivate the use of persistence diagrams, we illustrate with a simple example in \\cref{fig:persistence-diagram-example}, where we study the change of 0-dimensional persistent homology. In \\cref{fig:persistence-diagram-example}, we see how the persistence diagram changes once we increase the proximity diameter $\\alpha$, on a data set consisting of two blobs. In \\cref{fig:persistence-diagram-example} (a), we let $\\alpha=0.2$ and we observe that there are only two data points intersecting, thus leading to a single point in the persistence diagram. In \\cref{fig:persistence-diagram-example} (b), we let $\\alpha=1.5$ and we observe how the data points in each blob connect, thus leading to several entries in the persistence diagram. In \\cref{fig:persistence-diagram-example} (c), we let $\\alpha=4.5$, and we observe that there is a single point and several points on the bottom in the persistence diagram. By looking at the plot on the left, we see how the two blobs intersect and all data points have connections to other data points with distance less or equal to $\\alpha$. In addition to this, \\cref{fig:persistence-diagram-example} (c) indicates that we have two clusters in our data, although our data is rather noisy and could be more compact.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{thesis/figures/persistence-diagram-example.pdf}\n    \\caption{Persistence diagrams computed of a data set of two blobs. We vary the levels of $\\alpha$, showing how the topological properties form in the persistence diagrams.}\n    \\label{fig:persistence-diagram-example}\n\\end{figure}\nAn important aspect of machine learning is to predict some quantity given some features. If we want to use the persistence diagrams as features in a model, for instance, a typical approach would be to perform some feature extraction or vectorization first. An example of vectorization of persistence diagrams is persistence images, which we introduce in the next subsection.\n\n\\subsection{Persistence image}\n\\label{sec:persistence-image}\nMany machine learning tasks require valuable features to yield good results. \\textit{Persistence images} \\cite{adams2016persistence} are vector representations of persistence diagrams. When explaining persistence images, we refer to \\cite{adams2016persistence}. Furthermore, we explain the use of persistence images for the analysis of word embeddings in \\cref{sec:analysis-of-embeddings-geometric-anomaly-detection} and when discussing future work in \\cref{chap:future-work}.\n\nLet $B = \\enclc{\\enclp{b_1, d_1}, \\enclp{b_2, d_2}, \\ldots, \\enclp{b_m, d_m}} \\in \\R^{m \\times 2}$ be a persistence diagram in birth-death coordinates. First, we transform $B$ into birth-persistence coordinates, where \\textit{persistence} is the difference between death and birth. That is, let $T(B) = \\enclc{\\enclp{b_1, p_1}, \\enclp{b_2, p_2}, \\ldots, \\enclp{b_m, p_m}} \\in \\R^{m \\times 2}$, where $p_i = b_i - d_i$ for $1 \\leq i \\leq m$. Following, for each of the point in the the $T(B)$ persistence diagram, we place a probability distribution. A common choice is to use the Gaussian distribution, which we center at each data point respectively. By placing probability distributions on each point, we are able to differentiate between dense and sparse areas. In addition to placing probability distributions on each point, we weight the distributions by the persistence of the point, making more persistent areas more prominent than others. Using the weighted probability distributions, for a particular persistence diagram $B$ we define the persistence surface of $\\rho_B$ as\n\\begin{align}\n    \\rho_B(z) = \\sumlim{u \\in T(B)}{} f(u) \\phi_u(z),\n\\end{align}\nwhere $f(u)$ is the persistence weighing function and $\\phi_u(z)$ is the probability distribution which we evaluate at point $z$ (e.g. if Gaussian, then we centre it at point $u$). Finally, we reduce the persistence surface $\\rho_B(z)$ to a discretized representation. In particular, we form an $N \\times M$ grid, and for each cell in the grid, we compute the integral of $\\rho_B(z)$ over that region and use the result from the integral as value. In other words, this discretization allows us to summarize the persistence surface using less information and we are left with an $N \\times M$ matrix which we can for machine learning tasks more easily. Following, we illustrate the use of persistence images in \\cref{fig:persistence-image-example}, where we apply it to a 2-dimensional data set consisting of two circles. In \\cref{fig:persistence-image-example}, we see how the data is transformed into a persistence diagram $B$, following by the transformed persistence diagram $T(B)$ and finally the persistence image of $B$. In \\cref{fig:persistence-image-example} (d), we see a 66 by 35 pixels image, representing the vectorization of persistence diagram $B$.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=\\textwidth]{thesis/figures/persistence-image-example.pdf}\n    \\caption{Persistence image pipeline when applied to a 2-dimensional circles data set.}\n    \\label{fig:persistence-image-example}\n\\end{figure}\n\n\\subsection{Wasserstein distance}\n\\label{sec:wasserstein-distance}\nWhen we compare distances between data points, we commonly use distance metrics (e.g. Euclidean distance). To compare differences between any two persistence diagrams $A$ and $B$, however, we use the $p$\\textit{-Wasserstein distance}, which we define as\n\\begin{align}\n    W_p(A, B) = \\inf_{\\gamma: A \\rightarrow B} \\enclp{\\sumlim{u \\in A}{} ||u - \\gamma(u)||_{\\infty}^{p}}^{1/p},\n    \\label{eqn:wasserstein-distance}\n\\end{align}\nwhere $1 \\leq p < \\infty$ and $\\gamma$ ranges over bijections between $A$ and $B$, and $\\inf$ is the infimum (i.e. greatest lower bound; similar to \"minimum\"). We further visualize the idea behind the $p$-Wasserstein distance in \\cref{fig:wasserstein-distance-example}, where we see how the points in each persistence diagram $A$ and $B$ get paired up. We match points to the diagonal if we find no matches for the particular point.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{thesis/figures/wasserstein-distance_cropped.pdf}\n    \\caption{$p$-Wasserstein distance between two persistence diagrams $A$ and $B$.}\n    \\label{fig:wasserstein-distance-example}\n\\end{figure}\nFinally, if we let $p=\\infty$, i.e $W_\\infty(A, B)$, we get what we call the \\textit{bottleneck distance}. We use the bottleneck distance to compare persistence diagrams as well. However, we note that the bottleneck distance has the disadvantage of only using the maximum distance between any two points over the bijections between $A$ and $B$.\n\n\\subsection{Topological polysemy}\n\\label{sec:topological-polysemy}\nRecall the manifold hypothesis, which states that, in general, real-life high-dimensional data tends to live on a low-dimensional submanifold embedded within the high-dimensional space \\cite[p. 16]{bengio2014representation}. To give an example, imagine that we some data about weight and height of humans. Naturally, we see that as the height increases, the weight increases as well. That is, we have a strong linear relationship (or correlation) between height and weight. We can therefore argue that the manifold dimension of the data is 1, even though the original data has dimension 2. The hypothesis should, in theory, also apply to word embeddings, but the authors of \\cite{jakubowski2020topology} argue that word embeddings, should instead, live on a \\textit{punched manifold}. By a pinched manifold, we mean a manifold where we \"glue\" together particular points that are equal in some sense, creating \\textit{singular} areas in the manifold. We show an example in \\cref{fig:pinched-manifold}, where we see an ideal pinched manifold for the word \"solution\" and four of its meanings as \\textit{submanifolds}. For word embeddings, \\cite{jakubowski2020topology} claim that these singular areas in the manifold represent polysemous words and that the neighbours of polysemous words share some relation to the polysemous word. To identify such polysemous words from word embeddings, \\cite{jakubowski2020topology} introduce a topological measure of polysemy (using concepts from persistent homology) that correlates well with the true number of meanings of a word. To explain the topological measure of polysemy, we refer to \\cite{jakubowski2020topology}.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.7\\textwidth]{thesis/figures/pinched-manifold_cropped.pdf}\n    \\caption{A pinched manifold of the word \"solution\", showing four of its meanings as submanifolds. This figure is inspired by \\cite[Figure 5]{jakubowski2020topology}.}\n    \\label{fig:pinched-manifold}\n\\end{figure}\n\nDetermining the number of word meanings is a non-trivial task. Consider the word \\textit{solution}, which has multiple meanings. In some contexts, the word \\textit{solution} can relate to problem-solving (e.g. solving a problem in a handbook), while in other contexts, it can relate to chemistry (e.g. a mixture of two or more substances). We call such words \\textit{polysemous}, meaning that the word has multiple meanings which can relate to one another. The opposite of a polysemous word is a \\textit{monosemous} word, meaning that the word only has one meaning. The motivation behind the topological measure of polysemy, as introduced by \\cite{jakubowski2020topology}, stamps from the fact that the number of components of a \\textit{punctured neighbourhood} around a word $w$ should reflect the number of word meanings of the word $w$. A punctured neighbourhood of $w$ is the neighbouring words of $w$ excluding the word $w$ itself.\n\nLet $W \\in \\R^{|V| \\times d}$ be word embeddings, where $|V|$ is the number of words in the vocabulary and $d$ is the word embedding dimension. We compute the \\textit{topological polysemy} $\\text{TPS}_n(w)$ by fixing a target word $w$ and a neighbourhood size $n$. We denote the word embedding of $w$ as $v_w \\in \\R^{d}$. To compute $\\text{TPS}_n(w)$, we first normalize the word embeddings $W$ such that they are of unit length. We denote the normalized word embeddings as $W_\\text{norm}$ and the normalized word embedding of the target word $w$ as $v_{w_{\\text{norm}}}$. Following, we compute the punctured neighbourhood $N_n(w)$, that is, the neighbouring $n$ normalized word embeddings around $v_{w_{\\text{norm}}}$, excluding $w$ itself. Furthermore, we project the word embeddings of $N_n(w)$ to lie at the unit sphere, with $v_{w_{\\text{norm}}}$ as the center. We denote this normalized punctured neighbourhood as $N'_n(w)$. In other words, we make the word embedding of $w$ to be the origin of a $d$-dimensional sphere and project the neighbouring words of $w$ to lie around it. Finally, we compute the 0-degree persistence diagram of $N'_n(w)$ and denote it as $PD_n(w)$. $\\text{TPS}_n(w)$ is then the 1-Wasserstein distance (see \\cref{sec:wasserstein-distance}) between $PD_n(w)$ and the empty persistence diagram, also known as the Wasserstein norm. Furthermore, we will use topological polysemy later when analysing word embeddings in \\cref{sec:analysis-of-embeddings-topological-polysemy} and for prediction of polysemous words in \\cref{sec:analysis-of-embeddings-supervised-polysemy-prediction}.\n\n\\subsection{Geometric Anomaly Detection}\n\\label{sec:geometric-anomaly-detection}\nThe manifold hypothesis forms a foundation of modern data science. Many manifold learning and dimensionality reduction algorithms rely on this assumption to find meaningful low-dimensional representations of high-dimensional data. Examples of such algorithms include PCA and UMAP (see \\cref{sec:pca} and \\cref{sec:umap}). \\textit{Geometric Anomaly Detection} (GAD) \\cite{stolz2020geometric} is an algorithm for identifying possible points in data that fail to satisfy the manifold hypothesis. Following, we describe the motivation behind the GAD algorithm and describe how it works. We refer to \\cite{stolz2020geometric} when explaining the GAD algorithm.\n\nWe first introduce the motivation behind the GAD algorithm to deepen our understanding of how it works. Imagine that we have some data that lies on two submanifolds $P$ and $Q$. We illustrate such a situation in \\cref{fig:gad-motivation}. Here we assume that the two submanifolds $P$ and $Q$ are planes that intersect, which we mark by the dotted red line. We place an \\textit{annulus} around each data point and infer its topological structure. An annulus is a region between two circles, where the first circle is contained in the other, and both circles share a centre point. Annuli can also remind us of rings. Formally, each annulus around its respective data point has an inner radius $r$ and outer radius $s$. Depending on where points are on either of the submanifolds, we observe that they can have one of three states as seen in \\cref{fig:gad-motivation} (a), (b) and (c). If a point is at the boundary of either submanifold, i.e. in \\cref{fig:gad-motivation} (a), we observe that the points falling into the annulus around the data point forms a half-circle, as half of the circle does not have any data points in them. If we count the number of topological loops we get zero. If the data point falls nicely into either submanifold, i.e. in \\cref{fig:gad-motivation} (b), we observe that we get a nice annulus where neighbouring points falling into the annulus around the data point forms a circle. In other words, if a point is on the submanifold, we expect to get exactly one topological loop. In the last situation, i.e. \\cref{fig:gad-motivation} (c), we have a data point that falls between $P$ and $Q$, creating a singularity (or anomaly) in the data. This stamps from the fact that it is harder to distinguish which submanifold the particular data point should belong to. If we look at the data points in the annulus around the data point in \\cref{fig:gad-motivation} (c), we observe that we get two or more topological loops.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=0.8\\textwidth]{thesis/figures/geometric-anomaly-detection-motivation_cropped.pdf}\n    \\caption{The motivation behind the GAD algorithm, illustrated. Data points belonging to two submanifolds $P$ and $Q$, and depending on where the data points are on the submanifolds, it can have three different states: (a), (b) or (c). The GAD algorithm is particularly interested in finding singular (c) data points between $k$ submanifolds (here: $k=2$). This figure is inspired by \\cite[Figure 1]{stolz2020geometric}.}\n    \\label{fig:gad-motivation}\n\\end{figure}\n\nLet $X \\in R^{n \\times d}$ be data points. The GAD algorithm works as follows: fix two parameters $0 < r < s$, and for each data point $x_i \\in X$ place an annulus around it, with inner radius $r$ and outer radius $s$. We determine the data points that fall into the \\textit{annular neighbourhood} of $x_i$ and denote this set as $A_y = \\enclc{a_1, a_2, \\ldots, a_m} \\subset X$. That is, the set $A_y$ consists of those points $a_j$ that satisfies $r \\leq d(x_i, g_j) \\leq s$, where $d(\\cdot, \\cdot)$ measures the distance between two points (e.g. using Euclidean distance). Then, select a manifold dimension $k$ we would like to investigate, as the GAD algorithm discovers intersections of $(k-1)$ submanifolds. To find intersections of $(k-1)$ submanifolds of the annular neighbourhood $A_y$ of $x_i$, we compute the $(k-1)$-dimensional Vietoris–Rips complex of $A_y$, which we denote $VR_{k-1}(A_y)$. Then, for each birth-death coordinate $(b_{k-1}, d_{k-1}) \\in VR_{k-1}(A_y)$, we count the number of points that persist longer than the annulus width. We denote this count as $N_y$. Recall that the persistence of points in persistence diagrams can be computed by transforming the persistence diagram into birth-persistence coordinates, where persistence $p_{k-1} = d_{k-1} - b_{k-1}$. We define the annulus width to be the difference between the outer and inner radius, i.e. $w_{A_y} = s - r$. To count $N_y$, we iterate over the points in the persistence diagram and count the number of points that satisfies\n\\begin{align}\n    p_{k-1} > w_{A_y}.\n    \\label{eqn:gad-ny-condition}\n\\end{align}\nThe count $N_y$ is analogous to the number of topological loops that occur in $A_y$, for a particular homology dimension $(k-1)$. If no points satisfy \\cref{eqn:gad-ny-condition}, i.e. $N_y=0$, then we classify $x_i$ as a boundary point, similar to the situation in \\cref{fig:gad-motivation} (a). If we have exactly one point that satisfies \\cref{eqn:gad-ny-condition}, i.e $N_y=1$, then we classify the point as a boundary point, similar to the situation in \\cref{fig:gad-motivation} (b). If two or more points satisfy \\cref{eqn:gad-ny-condition}, i.e. $N_y>1$, then we classify the point as a singular point, similar to the situation in \\cref{fig:gad-motivation} (c). Furthermore, we will use GAD for later analysis of word embeddings in \\cref{sec:analysis-of-embeddings-geometric-anomaly-detection} and for prediction of polysemous words in \\cref{sec:analysis-of-embeddings-supervised-polysemy-prediction}. ", "meta": {"hexsha": "c59209cd0aac681ed6c5445506905d93da031552", "size": 23056, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/chapters/background/topological_data_analysis.tex", "max_stars_repo_name": "JonasTriki/masters-thesis-ml", "max_stars_repo_head_hexsha": "78b3c971e4ffd51875d19bb2cb4b75e9d7be905c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2021-05-24T08:05:12.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-31T03:51:32.000Z", "max_issues_repo_path": "thesis/chapters/background/topological_data_analysis.tex", "max_issues_repo_name": "JonasTriki/masters-thesis-ml", "max_issues_repo_head_hexsha": "78b3c971e4ffd51875d19bb2cb4b75e9d7be905c", "max_issues_repo_licenses": ["MIT"], "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/background/topological_data_analysis.tex", "max_forks_repo_name": "JonasTriki/masters-thesis-ml", "max_forks_repo_head_hexsha": "78b3c971e4ffd51875d19bb2cb4b75e9d7be905c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-02-05T18:05:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-05T18:05:56.000Z", "avg_line_length": 209.6, "max_line_length": 1943, "alphanum_fraction": 0.7759368494, "num_tokens": 5898, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7631492156420232}}
{"text": "\\section{Global definitions}\n\\label{sec:formalisations:global_definitions}\n\nThis section defines a multiplicity, which is a two tuple consisting of a lower and upper bound. In Ecore, the notion of a multiplicity is used within a field signature (\\cref{defin:formalisations:ecore_formalisation:type_models:type_model}) in order to specify a limit on the allowed amount of values for a field. In GROOVE, multiplicities are used to bound the number of incoming and outgoing edges for each node type via multiplicity pairs (\\cref{defin:formalisations:groove_formalisation:type_graphs:multiplicity_pair}).\n\n\\begin{defin}[Multiplicity]\n\\label{defin:formalisations:global_definitions:multiplicity}\nA multiplicity is a two tuple consisting of a lower bound (which is any natural number) and an upper bound (which is possibly unbounded).\n\\begin{equation*}\n\\mathbb{M} \\subseteq (\\mathbb{N} \\times \\mathbb{N^+} \\cup {\\mstar})\\ \\cap \\leq\n\\end{equation*}\nThe first value represents the lower bound, the second value of the tuple represents the upper bound. The set of multiplicities $\\mathbb{M}$ is formally defined as\n\\begin{equation*}\n\\mathbb{M} = \\{ (l, u) \\mid l \\in \\mathbb{N} \\land u \\in (\\mathbb{N^+} \\cup {\\mstar}) \\land l \\leq u \\}\n\\end{equation*}\nIt holds that $\\mstar$ is larger than each natural number, so $\\forall n \\in \\mathbb{N}: n < \\mstar$. Furthermore, the notation $l..u$ is used to denote $(l, u) \\in \\mathbb{M}$.\n\nFinally, any natural number $n$ is said to be part of a multiplicity if it is within bounds, meaning:\n\\begin{equation*}\n\\forall m = l..u \\in \\mathbb{M}, n \\in \\mathbb{N} : n \\in m \\Leftrightarrow l \\leq n \\leq u\n\\end{equation*}\n\\isabellelref{multiplicity}{Ecore.Multiplicity}\n\\end{defin}", "meta": {"hexsha": "47f4254fe2a9f693e657e8793d4f5bb411a57e2d", "size": 1710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "thesis/tex/03_formalisations/01_global_definitions.tex", "max_stars_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_stars_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_stars_repo_licenses": ["AFL-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "thesis/tex/03_formalisations/01_global_definitions.tex", "max_issues_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_issues_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_issues_repo_licenses": ["AFL-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "thesis/tex/03_formalisations/01_global_definitions.tex", "max_forks_repo_name": "RemcodM/thesis-ecore-groove-formalisation", "max_forks_repo_head_hexsha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "max_forks_repo_licenses": ["AFL-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.347826087, "max_line_length": 524, "alphanum_fraction": 0.7520467836, "num_tokens": 512, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331957, "lm_q2_score": 0.8175744761936437, "lm_q1q2_score": 0.7631492094184985}}
{"text": "\\input doc/format\n\\notespagesize\n\n\\def\\loss{{\\rm Loss}}\n\\def\\dv{{\\rm d}}\n\n% {{{1 Section Problem\n\\section{Problem}\n\nGiven predictions ${\\bf p} = [p_1, p_2, \\ldots, p_n]$ and targets\n${\\bf y} = [y_1, y_2, \\ldots, y_n]$, the cross entropy loss is defined as\n%\n$$\n    \\loss = - \\sum_{i} y_i \\log p_i,\n$$\nwith gradient:\n%\n$$\n    {\\dv \\loss \\over \\dv p_i} = - {\\dv y_i \\log p_i \\over \\dv p_i} = - {y_i \\over p_i }.\n$$\n\nHowever, this gradient is not numerical stable, as for any super small $p_i$,\ni.e., $p_i \\to 0$, the gradient is \\symbol{NaN}.\n\n\\section{Solution}\n\nA common trick to solve this is calculating the gradient from loss $\\loss$\nw.r.t.~the logits $o_i$  directly, where\n%\n$$\n    p_i = {\\exp^{o_i} \\over \\sum_k \\exp^{o_k}}.\n$$\n\nThe gradient, w.r.t.~logits, is\n%\n$$\n    {\\dv \\loss \\over \\dv o_i} =\n         - \\sum_k {\\dv \\loss \\over \\dv p_k} {\\dv p_k \\over \\dv o_i}.\n$$\nwhere\n%\n$$\n    {\\dv \\loss \\over \\dv p_k} = - {y_k \\over p_k},\n$$\nand\n%\n$$\n    {\\dv p_k \\over \\dv o_i} =\n        \\cases { p_i (1-p_i), & if $k=i$; \\cr\n                 -p_k p_i & if $k\\neq i$. \\cr }\n$$\n\nSubstituting everything into the loss gradient, we get\n%\n$$\n    \\eqalign{{\\dv \\loss \\over \\dv o_i}\n        & = (\\dots) \\cr\n        & = \\left( p_i \\sum_k { y_k} \\right) - y_i \\cr\n        & = p_i - y_i \\cr\n    }\n$$\nwhere $\\sum_k { y_k} = 1$ given ${\\bf y}$ is target probability.\n\n\\section{Numerical Stable}\n\nNow let's revisit the loss function with respect to the logits.\n%\n$$\n    \\eqalign{\n      \\loss & = - \\sum_{i} y_i \\log p_i, \\cr\n            & = - \\sum_{i} \\left(\n                y_i \\log {\\exp^{o_i} \\over \\sum_k \\exp^{o_k}}\n              \\right)\\cr\n    }\n$$\nFor any large logit $o_k$, the $\\exp$ is $\\inf$, so unstable. The common trick\nis to find the max item $o_{max}=\\max_k o_k$, and subtract it from all $o_k$s,\ni.e.,\n$$\n    \\eqalign{\n      \\loss & = - \\sum_{i} \\left(\n                y_i \\log {\\exp^{o_i} \\over \\sum_k \\exp^{o_k}}\n                \\right)\\cr\n            & = - \\sum_{i} \\left(\n                y_i \\log {\\exp^{o_i-o_{max}} \\over \\sum_k \\exp^{o_k-o_{max}}}\n                \\right)\\cr\n            & = -\n                \\left(\n                   \\sum_{i} y_i (o_i-o_{max})\n                \\right)\n                + \\log\\left(\n                    \\sum_k \\exp^{o_k-o_{max}}\n                 \\right)\n              \\cr\n    }\n$$\n\n\\vfill\n\\bye\n", "meta": {"hexsha": "c5087ea809d3148f58519289702ceb634c0a3f62", "size": 2337, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/loss_softmax_crossentropy.tex", "max_stars_repo_name": "xiejw/mlvm", "max_stars_repo_head_hexsha": "6aa2f2619d8fc9e91464d51d99a6965db9e0bf6f", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-09-22T14:28:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-22T14:28:26.000Z", "max_issues_repo_path": "doc/loss_softmax_crossentropy.tex", "max_issues_repo_name": "xiejw/mlvm", "max_issues_repo_head_hexsha": "6aa2f2619d8fc9e91464d51d99a6965db9e0bf6f", "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/loss_softmax_crossentropy.tex", "max_forks_repo_name": "xiejw/mlvm", "max_forks_repo_head_hexsha": "6aa2f2619d8fc9e91464d51d99a6965db9e0bf6f", "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.37, "max_line_length": 88, "alphanum_fraction": 0.5053487377, "num_tokens": 823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391600697869, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7630873560778995}}
{"text": "\\chapter{Binary Search Trees}\n\nSearching for an internal node in a binary tree can be costly because,\nin the worst case, the whole tree must be traversed, for example, in\npreorder or level\\hyp{}order. To improve upon this, two situations are\ndesirable: the binary tree should be as balanced\\index{binary\n  tree!balanced $\\sim$} as possible and the choice of visiting\n\\begin{wrapfigure}[7]{r}[0pt]{0pt}\n\\centering\n\\includegraphics{bst_ex}\n\\caption{\\label{fig:bst_ex}}\n\\end{wrapfigure}\nthe left or right subtree should be taken only upon examining the\ncontents in the root, called \\emph{key}\\index{key}.\n\nThe simplest solution consists in satisfying the latter condition and\nlater see how it fits the former. A \\emph{binary search tree}\n\\citep{Mahmoud_1992}\\index{binary search tree} \\(\\fun{bst}(x, t_1,\nt_2)\\)\\index{bst@\\fun{bst/3}} is a binary tree such that the key~\\(x\\)\nis greater than the keys in~\\(t_1\\) and smaller than the keys\nin~\\(t_2\\). (The external node \\(\\fun{ext}()\\) is a trivial search\ntree.) The comparison function depends on the nature of the keys, but\nhas to be \\emph{total}, that is, any key can be compared to any other\nkey. An example is given in \\fig~\\vref{fig:bst_ex}. An immediate\nconsequence of the definition is that the inorder\\index{binary\n  tree!inorder} traversal of a binary search tree yields an\nincreasingly sorted stack, for example, \\([3,5,11,13,17,29]\\) from the\ntree in \\fig~\\ref{fig:bst_ex}.\n\nThis property enables checking simply that a binary tree is a search\ntree: perform an inorder traversal and then check the order of the\nresulting stack. The corresponding function,\n\\fun{bst\\(_0\\)/1}\\index{bst0@\\fun{bst\\(_0\\)/1}}, is legible in\n\\fig~\\vref{fig:bst0},\n\\begin{figure}[t]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{bst}_0(t) & \\rightarrow & \\fun{ord}(\\fun{in}_2(t,\\el)).\\\\\n\\\\\n\\fun{in}_2(\\fun{ext}(),s) & \\rightarrow & s;\\\\\n\\fun{in}_2(\\fun{bst}(x,t_1,t_2),s) & \\rightarrow\n  & \\fun{in}_2(t_1,\\cons{x}{\\fun{in}_2(t_2,s)}).\\\\\n\\\\\n\\fun{ord}(\\cons{x,y}{s}) & \\rightarrow & \\fun{ord}(\\cons{y}{s}),\n\\;\\text{if \\(y \\succ x\\)};\\\\\n\\fun{ord}(\\cons{x,y}{s}) & \\rightarrow & \\fun{false}();\\\\\n\\fun{ord}(s) & \\rightarrow & \\fun{true}().\n\\end{array}}\n\\end{equation*}\n\\caption{Na\\\"{\\i}vely checking a binary search tree\\label{fig:bst0}}\n\\end{figure}\nwhere \\fun{in\\(_2\\)/2}\\index{in2@\\fun{in\\(_2\\)/2}} is just a\nredefinition of \\fun{in/2}\\index{in@\\fun{in/2}} in\n\\fig~\\vref{fig:in}. Thus, the cost of \\(\\fun{in}_2(t)\\), when\n\\(t\\)~has size~\\(n\\), is \\(\\C{\\fun{in}_2}{n} = \\C{\\fun{in}}{n} = 2n +\n2\\). The worst case for \\fun{ord/1}\\index{ord@\\fun{ord/1}} occurs when\nthe stack is sorted increasingly, so the maximum cost is\n\\(\\W{\\fun{ord}}{n} = n\\), if \\(n > 0\\). The best case is manifest when\nthe first key is greater than the second, so the minimum cost is\n\\(\\B{\\fun{ord}}{n} = 1\\). Summing up: \\(\\B{\\fun{bst}_0}{n} = 1 +\n(2n+2) + 1 = 2n + 4\\) and \\(\\W{\\fun{bst}_0}{n} = 1 + (2n+2) + n = 3n +\n3\\).\n\nA better design consists in not constructing the inorder stack and\nonly \\emph{keeping the smallest key so far}, assuming the traversal is\nfrom right to left, and compare it with the current key. But this is a\nproblem at the beginning, as we have not visited any node yet. A\ncommon trick to deal with exceptional values is to use a\n\\emph{sentinel}\\index{sentinel}, which is a dummy. Here, we would like\nto set the sentinel to \\(+\\infty\\), as any key would be smaller, in\nparticular the largest key, which is \\emph{unknown}. (Would it be\nknown, we could use it as a sentinel.) It is actually easy to model\nthis infinite value in our functional language: let us simply use a\nconstant data constructor \\fun{infty/0}\\index{infty@\\fun{infty/0}}\n(\\emph{infinity}) and make sure that we handle its comparison\nseparately from the others. Actually,\n\\(\\fun{infty}()\\)\\index{infty@\\fun{infty/0}} is compared only once,\nwith the largest key, but we will not try to optimise this, lest the\ndesign is obscured.\n\nThe program is displayed in\n\\fig~\\vref{fig:bst}.\\index{bst@\\fun{bst/1}}\\index{bst1@\\fun{bst\\(_1\\)/2}}\n\\begin{figure}[t]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n  \\fun{bst}(t) & \\rightarrow & \\fun{norm}(\\fun{bst}_1(t,\\fun{infty}())).\\\\\n  \\\\\n  \\fun{bst}_1(\\fun{ext}(),m) & \\rightarrow & m;\\\\\n  \\fun{bst}_1(\\fun{bst}(x,t_1,t_2),m) & \\rightarrow & \n  \\fun{cmp}(x,t_1,\\fun{bst}_1(t_2,m)).\\\\\n\\\\\n\\fun{cmp}(x,t_1,\\fun{infty}()) & \\rightarrow & \\fun{bst}_1(t_1,x);\\\\\n\\fun{cmp}(x,t_1,m) & \\rightarrow &\n  \\fun{bst}_1(t_1,x), \\,\\text{if \\(m \\succ x\\)};\\\\\n\\fun{cmp}(x,t_1,m) & \\rightarrow & \\fun{false}().\\\\\n\\\\\n\\fun{norm}(\\fun{false}()) & \\rightarrow & \\fun{false}();\\\\\n\\fun{norm}(m) & \\rightarrow & \\fun{true}().\n\\end{array}}\n\\end{equation*}\n\\caption{Checking a binary search tree\\label{fig:bst}}\n\\end{figure}\nThe parameter~\\(m\\) stands for the \\emph{minimum} key so far. The sole\npurpose of \\fun{norm/1}\\index{norm@\\fun{norm/1}} is to get rid of the\nsmallest key~\\(m\\) in the tree and instead terminate with\n\\(\\fun{true}()\\), but, if the tree is not empty, we could as well end\nwith \\(\\fun{true}(m)\\), or even \\(\\fun{false}(x)\\), if more\ninformation were deemed useful.\\index{true@\\fun{true/1}}\n\nIn the worst case, the original tree is a binary search tree, hence it\nhas to be traversed in its entirety. If there are \\(n\\)~internal\nnodes, the maximum cost is \\(\\W{\\fun{bst}}{n} = 1 + 2n + (n+1) + 1 =\n3n + 3\\)\\index{bst@$\\W{\\fun{bst}}{n}$} because each internal node\ntriggers one call to \\fun{bst\\(_1\\)/2}\\index{bst1@\\fun{bst\\(_1\\)/2}} and, in\nturn, one call to \\fun{cmp/3}\\index{cmp@\\fun{cmp/3}}; also, all the\n\\(n+1\\) external nodes are visited. Consequently, \\(\\W{\\fun{bst}_0}{n}\n= \\W{\\fun{bst}}{n}\\),\\index{bst0@$\\W{\\fun{bst}_0}{n}$} if \\(n > 0\\),\nwhich is not an improvement. Nevertheless, here, we do not build a\nstack with all the keys, which is a definite gain in terms of memory\nallocation.\n\nMemory is not the only advantage, though, as the minimum cost of\n\\fun{bst/1}\\index{bst@\\fun{bst/1}} is lower than for\n\\fun{bst\\(_0\\)/1}.\\index{bst0@\\fun{bst\\(_0\\)/1}} Indeed, the best case\nfor both occurs when the tree is not a binary search tree, but this is\ndiscovered the sooner in \\fun{bst/1} at the second comparison, because\nthe first one always succeeds by design (\\(+\\infty \\succ\nx\\)). Obviously, for the second comparison to occur as soon as\npossible, we need the first comparison to happen as soon as possible\ntoo. Two configurations work:\n\\begin{align*}\n\\fun{bst}(\\fun{bst}(x,t_1,\\fun{bst}(y,\\fun{ext}(),\\fun{ext}())))\n& \\xrightarrow{\\smash{8}} \\fun{false}(),\\\\\n\\fun{bst}(\\fun{bst}(y,\\fun{bst}(x,t_1,\\fun{ext}()),\\fun{ext}()))\n& \\xrightarrow{\\smash{8}} \\fun{false}(),\n\\end{align*}\nwhere \\(x \\succcurlyeq y\\). (The second tree is the left rotation of\nthe first. We have seen \\vpageref{par:rotation} that inorder\ntraversals are invariant through rotations.) The minimum cost in both\ncases is \\(\\B{\\fun{bst}}{n} = 8\\),\\index{bst@$\\B{\\fun{bst}}{n}$} to be\ncontrasted with the linear cost \\(\\B{\\fun{bst}_0}{n} = 2n +\n4\\)\\index{bst0@$\\B{\\fun{bst}_0}{n}$} due to the inevitable complete\ninorder traversal.\n\n\\section{Search}\n\nWe now must find out whether searching for a key is faster than with\nan ordinary binary tree, which was our initial motivation. Given the\nsearch tree \\(\\fun{bst}(x,t_1,t_2)\\), if the key~\\(y\\) we are\nsearching for is such that \\(y \\succ x\\), then we search recursively\nfor it in~\\(t_2\\); otherwise, if \\(x \\succ y\\), we look in~\\(t_1\\);\nfinally, if \\(y = x\\), we just found it at the root of the given\ntree. The definition of \\fun{mem/2} (\\emph{membership}) is shown in\n\\fig~\\vref{fig:mem}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mem}(y,\\fun{ext}()) & \\rightarrow & \\fun{false}();\\\\\n\\fun{mem}(x,\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \\fun{true}();\\\\\n\\fun{mem}(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \n  \\fun{mem}(y,t_1), \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mem}(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{mem}(y,t_2).\n\\end{array}}\n\\end{equation*}\n\\caption{Searching in a binary search tree\\label{fig:mem}}\n\\end{figure}\nThe crucial point is that we may not need to visit all the nodes. More\nprecisely, if all nodes are visited, then the tree is\ndegenerate\\index{binary tree!degenerate $\\sim$}, to wit, it is\nisomorphic to a stack, like the trees in \\fig~\\vref{fig:tree_stack}\nand \\fig~\\vref{fig:zigzag}. Clearly, the minimum cost of a successful\nsearch occurs when the key is at the root, so\n\\(\\B{\\fun{mem}}{n{\\scriptscriptstyle (+)}} =\n1\\),\\index{mem@$\\B{\\fun{mem}}{n{\\scriptscriptstyle (+)}}$} and the\nminimum cost of an unsuccessful search happens when the root has an\nexternal node as a child and \\fun{mem/2} visits it:\n\\(\\B{\\fun{mem}}{n{\\scriptscriptstyle (-)}} =\n2\\).\\index{mem@$\\B{\\fun{mem}}{n{\\scriptscriptstyle (-)}}$} The maximum\ncost of a successful search occurs when the tree is degenerate and the\nkey we are looking for is at the only leaf\\index{binary tree!leaf}, so\n\\(\\W{\\fun{mem}}{n{\\scriptscriptstyle (+)}} =\nn\\),\\index{mem@$\\W{\\fun{mem}}{n{\\scriptscriptstyle (+)}}$} and the\nmaximum cost of an unsuccessful search happens when visiting one of\nthe children of the leaf of a degenerate\\index{binary tree!degenerate\n  $\\sim$} tree: \\(\\W{\\fun{mem}}{n{\\scriptscriptstyle (-)}} =\nn+1\\).\\index{mem@$\\W{\\fun{mem}}{n{\\scriptscriptstyle (-)}}$}\nTherefore,\n\\begin{equation*}\n\\B{\\fun{mem}}{n} = 1\\quad\\text{and}\\quad \\W{\\fun{mem}}{n} = n + 1.\n\\index{mem@$\\B{\\fun{mem}}{n}$}\\index{mem@$\\W{\\fun{mem}}{n}$}\n\\end{equation*}\nThese extremal costs are the same as for a linear search\\index{linear\n  search} by \\fun{ls/2}\\index{ls@\\fun{ls/2}}:\n\\begin{equation*}\n\\fun{ls}(x,\\el)          \\rightarrow  \\fun{false}();\\quad\n\\fun{ls}(x,\\cons{x}{s})  \\rightarrow  \\fun{true}();\\quad\n\\fun{ls}(x,\\cons{y}{s})  \\rightarrow  \\fun{ls}(x,s).\n\\end{equation*}\nThe cost of a successful linear search is \\(\\C{\\fun{ls}}{n,k} = k\\),\nif the sought key is at position~\\(k\\), where the first key is at\nposition~\\(1\\). Therefore, the average cost of a successful linear\nsearch, assuming that each distinct key is equally likely to be sought\nis \\(\\M{\\fun{ls}}{n} = \\frac{1}{n}\\sum_{k=1}^{n}\\C{\\fun{ls}}{n,k} =\n\\tfrac{1}{2}(n+1)\\).\\index{linear search}\\index{ls@$\\M{\\fun{ls}}{n}$}\nThis raises the question of the average cost of\n\\fun{mem/2}.\\index{mem@\\fun{mem/2}}\n\n\\mypar{Average cost}\n\nIt is clear from the definition that a search path starts at the root\nand either ends at an internal node in case of success, or at an\nexternal node in case of failure; moreover, each node on these paths\ncorresponds to one function call. Therefore, the average cost of\n\\fun{mem/2}\\index{mem@\\fun{mem/2}} is directly related to the average\ninternal\\index{binary search tree!average internal path length} and\nexternal\\index{binary search tree!average external path length} path\nlengths. To clearly see how, let us consider a binary search tree of\nsize~\\(n\\) containing distinct keys. The total cost of searching all\nof these keys is \\(n+I_n\\), where \\(I_n\\)~is the internal path length\n(we add~\\(n\\) to~\\(I_n\\) because we count the nodes on the paths, not\nthe edges, as one internal node is associated with one function\ncall). In other words, a random key chosen amongst those in a given\ntree of size~\\(n\\) is found by \\fun{mem/2} with an average cost of\n\\(1+I_n/n\\). Dually, the total cost of reaching all the external nodes\nof a given binary search tree is \\((n+1)+E_n\\), where \\(E_n\\)~is the\nexternal path length (there are \\(n+1\\) external nodes in a tree\nwith \\(n\\)~internal nodes; see theorem~\\ref{thm:int_ext}\n\\vpageref{thm:int_ext}). In other words, the average cost of a failed\nsearch by \\fun{mem/2}\\index{mem@\\fun{mem/2}} is \\(1 + E_n/(n+1)\\).\n\nAt this point, we should realise that we are dealing with a double\nrandomness, or, equivalently, an average of averages. Indeed, the\nprevious discussion assumed the search tree was given, but the key was\nrandom. The general case is when both are chosen randomly, that is,\nwhen the previous results are averaged over all possible trees of the\nsame size~\\(n\\). Let \\(\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}\\)\n\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}$} be the average\ncost of the successful search of a random key in a random tree of\nsize~\\(n\\) (any of the \\(n\\)~keys being sought with same probability);\nmoreover, let \\(\\M{\\fun{mem}}{n{\\scriptscriptstyle\n    (-)}}\\)\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle\n    (-)}}$} be the average cost of the unsuccessful search of a random\nkey in a random tree (any of the \\(n+1\\) intervals whose end points\nare the \\(n\\)~keys being equally likely to be searched). Then\n\\begin{equation}\n  \\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}\n  = 1 + \\frac{1}{n}\\Expected{I_n}\n\\quad\\text{and}\\quad\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\n  = 1 + \\frac{1}{n+1}\\Expected{E_n},\n\\label{eq:Mmems}\n\\end{equation}\nwhere \\(\\Expected{I_n}\\) and \\(\\Expected{E_n}\\) are, respectively, the\naverage (or \\emph{expected}) internal\\index{binary search tree!average\n  internal path\n  length} path length and the average external\\index{binary search\n  tree!average external path length} path length. Reusing\nequation~\\eqref{eq:EI}, page~\\pageref{eq:EI} (\\(E_n = I_n + 2n\\)), we\ndeduce \\(\\Expected{E_n} = \\Expected{I_n} + 2n\\) and we can now relate\nthe average costs of searching by eliminating the average path\nlengths:\n\\begin{equation}\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} = \\left(1 + \\frac{1}{n}\\right)\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} - \\frac{1}{n} - 2.\n\\label{eq:Mmem}\n\\end{equation}\nImportantly, this equation holds for all binary search trees,\n\\emph{independently of how they are built}. In the next section, we\nshall envisage two methods for making search trees and we will be able\nto determine \\(\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}\\)\n\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}$} and\n\\(\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\\)\n\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}$} with the help\nof equation~\\eqref{eq:Mmem}.\n\nBut before that, we could perhaps notice that in \\fig~\\vref{fig:mem}\nwe did not follow the order of the comparisons as we wrote it down.\nIn the case of a successful search, the comparison \\(y = x\\) holds\nexactly once, at the very end; therefore, checking it before the\nothers, as we did in the second rule in \\fig~\\vref{fig:mem}, means\nthat it fails for every key on the search path, except for the\nlast. If we measure the cost as the number of function calls, we would\nnot care, but, if we are interested in minimising the number of\ncomparisons involved in a search, it is best to move that rule\n\\emph{after} the other inequality tests, as in \\fig~\\vref{fig:mem0}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mem}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \n  \\fun{mem}_0(y,t_1), \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mem}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{mem}_0(y,t_2),\\; \\text{if \\(y \\succ x\\)};\\\\\n\\fun{mem}_0(y,\\fun{ext}()) & \\rightarrow & \\fun{false}();\\\\\n\\fun{mem}_0(y,t) & \\rightarrow & \\fun{true}().\n\\end{array}}\n\\end{equation*}\n\\caption{Searching with fewer 2-way comparisons\\label{fig:mem0}}\n\\end{figure}\n(We assume that an equality is checked as fast as an inequality.) With\n\\fun{mem\\(_0\\)/2}\\index{mem0@\\fun{mem\\(_0\\)/2}}, the number of\ncomparisons for each search path is different because of the asymmetry\nbetween left and right: visiting~\\(t_1\\) yields one comparison (\\(x\n\\succ y\\)), whilst \\(t_2\\)~begets two comparisons (\\(x \\nsucc y\\) and\n\\(y \\succ x\\)). Moreover, we also moved the pattern for the external\nnode after the rules with comparisons, because each search path\ncontains exactly one external node at the end, so it is likely more\nefficient to check it last. By the way, all textbooks we are aware of\nsuppose that exactly one atomic comparison with three possible\noutcomes (\\emph{3-way comparison}) occurs, despite the programs they\nprovide clearly employing the \\emph{2-way comparisons} \\((=)\\) and\n\\((\\succ)\\). This widespread blind spot renders the theoretical\nanalysis based on the number of comparisons less pertinent, because\nmost high\\hyp{}level programming languages simply do not feature\nnative 3-way comparisons.\n\n\\mypar{Andersson's variant}\n\n\\cite{Andersson_1991} proposed a variant for searching which fully\nacknowledges the use of 2-way comparisons and reduces their number to\na minimum, at the expense of more function calls. The design consists\nin threading a candidate key while descending in the tree and always\nending a search at an external node: if the candidate then equals the\nsought key, the search is successful, otherwise it is not. Therefore,\nthe cost in terms of function calls of an unsuccessful search is the\nsame as with \\fun{mem/2}\\index{mem@\\fun{mem/2}} or\n\\fun{mem\\(_0\\)/2}\\index{mem0@\\fun{mem\\(_0\\)/2}}, and the ending\nexternal node is the same, but the cost for a successful search is\nhigher.  Nevertheless, the advantage is that \\emph{equality is not\n  tested on the way down}, only when the external node is reached, so\nonly one comparison per node is required. The program is shown in\n\\fig~\\vref{fig:mem1}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{mem}_1(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{mem}_2(y,\\fun{bst}(x,t_1,t_2),x);\\\\\n\\fun{mem}_1(y,\\fun{ext}()) & \\rightarrow & \\fun{false}().\\\\\n\\\\\n\\fun{mem}_2(y,\\fun{bst}(x,t_1,t_2),c) & \\rightarrow &\n  \\fun{mem}_2(y,t_1,c),\\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mem}_2(y,\\fun{bst}(x,t_1,t_2),c) & \\rightarrow &\n  \\fun{mem}_2(y,t_2,x);\\\\\n\\fun{mem}_2(y,\\fun{ext}(),y) & \\rightarrow & \\fun{true}();\\\\\n\\fun{mem}_2(y,\\fun{ext}(),c) & \\rightarrow & \\fun{false}().\n\\end{array}}\n\\end{equation*}\n\\caption{Andersson's search (key candidate)\\label{fig:mem1}}\n\\end{figure}\nThe candidate is the third argument to\n\\fun{mem\\(_2\\)/2}\\index{mem2@\\fun{mem\\(_2\\)/2}} and its first instance\nis the root of the tree itself, as seen in the first rule of\n\\fun{mem\\(_1\\)/2}\\index{mem1@\\fun{mem\\(_1\\)/2}}. The only conceptual\ndifference with \\fun{mem\\(_0\\)/2}\\index{mem0@\\fun{mem\\(_0\\)/2}} is how\na successful search is acknowledged: if, somewhere along the search\npath, \\(x=y\\), then \\(x\\)~becomes the candidate and it will be\nthreaded down to an external node where \\(x=x\\) is checked.\n\nThe worst case happens when the tree is degenerate\\index{binary\n  tree!degenerate $\\sim$} and \\fun{mem\\(_1\\)/2} performs \\(n+1\\) 2-way\ncomparisons, which we write as \\(\\OW{\\fun{mem}_1}{n} = n +\n1\\),\\index{mem1@$\\OW{\\fun{mem}_1}{n}$} after the notations we used in\nthe analysis of merge sort\\index{merge sort}, back in\nchapter~\\ref{chap:merge_sort} \\vpageref{chap:merge_sort}.\n\nIn the case of \\fun{mem\\(_0\\)/2}, the recursive call to the right\nsubtree incurs twice as much comparisons as in the left subtree, thus\nthe worst case is a right\\hyp{}leaning degenerate tree, like in\n\\fig~\\vref{fig:min_pre0}, and all internal nodes are visited:\n\\(\\OW{\\fun{mem}_0}{n} = 2n\\).\\index{mem0@$\\OW{\\fun{mem}_0}{n}$}\n\nIn the case of \\fun{mem/2}, the number of comparisons is symmetric\nbecause equality is tested first, so the worst case is a degenerate\ntree in which an unsuccessful search leads to the visit of all\ninternal nodes and one external node: \\(\\OW{\\fun{mem}}{n} = 2n +\n1\\).\\index{mem@$\\OW{\\fun{mem}}{n}$} Asymptotically, we have\n\\begin{equation*}\n\\OW{\\fun{mem}}{n} \\sim \\OW{\\fun{mem}_0}{n} \n\\sim 2 \\cdot \\OW{\\fun{mem}_1}{n}.\n\\end{equation*}\n\nIn the case of Andersson's search, there is no difference between the\ncost, in terms of function calls, of a successful search and an\nunsuccessful one, so, for \\(n > 0\\), we have\n\\begin{equation}\n\\M{\\fun{mem}_3}{n} = 1 + \\M{\\fun{mem}_2}{n}\\quad\\text{and}\\quad\n\\M{\\fun{mem}_2}{n} = \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}.\n\\label{eq:Andersson_average}\n\\index{mem3@$\\M{\\fun{mem}_3}{n}$}\\index{mem2@$\\M{\\fun{mem}_2}{n}$}\n\\end{equation}\nChoosing between \\fun{mem\\(_0\\)/2} and \\fun{mem\\(_1\\)/2} depends on\nthe compiler or interpreter of the programming language chosen for the\nimplementation. If a 2-way comparison is slower than an indirection\n(following a pointer, or, at the assembly level, jumping\nunconditionally), it is probably best to opt for Andersson's\nvariant. But the final judgement requires a benchmark.\n\nAs a last note, we may simplify Andersson's program by getting rid of\nthe initial emptiness test in \\fun{mem\\(_1\\)/2}.\\index{mem1@\\fun{mem\\(_1\\)/2}} What we need to do is\nsimply have a candidate be the subtree whose root is the candidate in\nthe original program. See \\fig~\\vref{fig:mem3}\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n  \\fun{mem}_3(y,t) & \\rightarrow & \\fun{mem}_4(y,t,t).\\\\\n  \\\\\n  \\fun{mem}_4(y,\\fun{bst}(x,t_1,t_2),t) & \\rightarrow &\n  \\fun{mem}_4(y,t_1,t),\\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{mem}_4(y,\\fun{bst}(x,t_1,t_2),t) & \\rightarrow &\n  \\fun{mem}_4(y,t_2,\\fun{bst}(x,t_1,t_2));\\\\\n\\fun{mem}_4(y,\\fun{ext}(),\\fun{bst}(y,t_1,t_2)) & \\rightarrow & \\fun{true}();\\\\\n\\fun{mem}_4(y,\\fun{ext}(),t) & \\rightarrow & \\fun{false}().\n\\end{array}}\n\\end{equation*}\n\\caption{Andersson's search (tree candidate)\\label{fig:mem3}}\n\\end{figure}\nwhere we have \\(\\OW{\\fun{mem}_3}{n} = \\OW{\\fun{mem}_1}{n} = n + 1\\).\nThis version may be preferred only if the programming language used\nfor the implementation features \\emph{aliases}\\index{memory!aliasing}\nin patterns or, equivalently, if the compiler can detect that the term\n\\(\\fun{bst}(x,t_1,t_2)\\) can be shared instead of being duplicated in\nthe second rule of \\fun{mem\\(_4\\)/3} (here, we assume that sharing is\nimplicit and maximum within a rule).\\index{mem4@\\fun{mem\\(_4\\)/3}} For\nadditional information on Andersson's variant, read\n\\cite{Spuler_1992}.\n\n\n\\section{Insertion}\n\\label{sec:bst:insertion}\n\n\\mypar{Leaf insertion}\\index{binary search tree!leaf insertion|(}\n\nSince all unsuccessful searches end at an external node, it is\nextremely tempting to start the insertion of a unique key by a\n(failing) search and then grow a leaf with the new key at the external\nnode we reached. \\Fig~\\vref{fig:insl} displays the program for\n\\fun{insl/2}\\index{insl@\\fun{insl/2}} (\\emph{insert a leaf}). Note\nthat it allows duplicates in the binary search tree, which hinders the\ncost analysis \\citep{Burge_1976,ArchibaldClement_2006,Pasanen_2010}.\n\\Fig~\\vref{fig:insl0} shows a variant which maintains the unicity of\nthe keys, based on the definition of\n\\fun{mem\\(_0\\)/2}\\index{mem0@\\fun{mem\\(_0\\)/2}} in\n\\fig~\\vref{fig:mem0}. Alternatively, we can reuse Andersson's lookup,\nas shown in \\fig~\\vref{fig:insl1}.\\index{insl1@\\fun{insl/1}}\n\n\\bigskip\n\n\\begin{figure}[h]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{insl}(y,\\fun{bst}(x,t_1,t_2)) & \\xrightarrow{\\smash{\\tau}} &\n  \\fun{bst}(x,\\fun{insl}(y,t_1),t_2), \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{insl}(y,\\fun{bst}(x,t_1,t_2)) & \\xrightarrow{\\smash{\\upsilon}} &\n  \\fun{bst}(x,t_1,\\fun{insl}(y,t_2));\\\\\n\\fun{insl}(y,\\fun{ext}()) & \\xrightarrow{\\smash{\\phi}} & \\fun{bst}(y,\\fun{ext}(),\\fun{ext}()).\n\\end{array}}\n\\end{equation*}\n\\caption{Leaf insertion with possible duplicates\\label{fig:insl}}\n\\end{figure}\n\n\\bigskip\n\n\\begin{figure}[h]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{insl}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,\\fun{insl}_0(y,t_1),t_2), \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{insl}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,t_1,\\fun{insl}_0(y,t_2)) , \\; \\text{if \\(y \\succ x\\)};\\\\\n\\fun{insl}_0(y,\\fun{ext}()) & \\rightarrow &\n\\fun{bst}(y,\\fun{ext}(),\\fun{ext}());\\\\\n\\fun{insl}_0(y,t) & \\rightarrow & t.\n\\end{array}}\n\\end{equation*}\n\\caption{Leaf insertion without duplicates\\label{fig:insl0}}\n\\end{figure}\n\n\\bigskip\n\n\\begin{figure}[h]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{insl}_1(y,t) & \\rightarrow & \\fun{insl}_2(y,t,t).\\\\\n\\\\\n\\fun{insl}_2(y,\\fun{bst}(x,t_1,t_2),t) & \\rightarrow &\n  \\fun{bst}(x,\\fun{insl}_2(y,t_1,t),t_2), \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{insl}_2(y,\\fun{bst}(x,t_1,t_2),t) & \\rightarrow &\n  \\fun{bst}(x,t_1,\\fun{insl}_2(y,t_2,\\fun{bst}(x,t_1,t_2)));\\\\\n\\fun{insl}_2(y,\\fun{ext}(),\\fun{bst}(y,t_1,t_2)) & \\rightarrow & \\fun{ext}();\\\\\n\\fun{insl}_2(y,\\fun{ext}(),t) & \\rightarrow & \\fun{bst}(y,\\fun{ext}(),\\fun{ext}()).\n\\end{array}}\n\\end{equation*}\n\\caption{Andersson's insertion\\label{fig:insl1}}\n\\end{figure}\n\n\\mypar{Average cost}\n\nIn order to carry out the average case analysis of leaf insertion, we\nmust assume that all inserted keys are distinct; equivalently, we\nconsider all the search trees resulting from the insertion into\noriginally empty trees of all the keys of each permutation of\n\\((1,2,\\dots,n)\\). Because the number of permutations is greater than\nthe number of binary trees of same size, to wit, \\(n! > C_n\\) if \\(n >\n2\\) (see equation~\\eqref{eq:Cn} \\vpageref{eq:Cn}), we expect some tree\nshapes to correspond to many permutations. As we will see in the\nsection about the average height, degenerate and wildly unbalanced\ntrees are rare in average \\citep{Fill_1996}, making binary search\ntrees a good random data structure as long as only leaf insertions are\nperformed. Because we assume the unicity of the inserted keys, we\nshall only consider \\fun{insl/2} in the following. (Andersson's\ninsertion is only worth using if duplicate keys are possible inputs\nthat must be detected, leaving the search tree invariant.)\n\nLet us define a function \\fun{mkl/1}\\index{mkl@\\fun{mkl/1}}\n\\index{mkl@\\fun{mkl/2}} (\\emph{make leaves}) in \\fig~\\vref{fig:mkl}\n\\begin{figure}\n\\begin{equation*}\n\\boxed{\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n  \\fun{mkl}(s) & \\xrightarrow{\\smash{\\xi}} & \\fun{mkl}(s,\\fun{ext}()).\n& \\fun{mkl}(\\el,t) & \\xrightarrow{\\smash{\\psi}} & t;\\\\\n& & & \\fun{mkl}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\omega}} & \\fun{mkl}(s,\\fun{insl}(x,t)).\n\\end{array}}\n\\end{equation*}\n\\caption{Making a binary search tree with leaf insertions\n\\label{fig:mkl}}\n\\end{figure}\nwhich builds a binary search tree by inserting as leaves all the keys\nin a given stack. Note that we could also define a function\n\\fun{mklR/1}\\index{mklR@\\fun{mklR/1}} (\\emph{make leaves in reverse order}) such that\n\\(\\fun{mklR}(s) \\equiv \\fun{mkl}(\\fun{rev}(s))\\) in a compact manner:\n\\begin{equation}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n  \\fun{mklR}(\\el) \\rightarrow \\fun{ext}();\n  \\quad\n  \\fun{mklR}(\\cons{x}{s}) \\rightarrow \\fun{insl}(x,\\fun{mklR}(s)).\n\\label{eq:mklR}\n\\end{equation}\nThe cost of \\(\\fun{insl}(x,t)\\) depends on~\\(x\\) and the shape\nof~\\(t\\), but, because all shapes are obtained by \\(\\fun{mkl}(s)\n\\twoheadrightarrow t\\) for a given length of~\\(s\\), and all external\nnodes of~\\(t\\) are equally likely to grow a leaf containing~\\(x\\), the\naverage cost \\(\\M{\\fun{insl}}{k}\\)\\index{insl@$\\M{\\fun{insl}}{k}$} of\n\\(\\fun{insl}(x,t)\\) only depends on the size~\\(k\\) of the trees:\n\\begin{equation}\n\\abovedisplayskip=2pt\n\\abovedisplayshortskip=2pt\n\\belowdisplayskip=4pt\n\\M{\\fun{mkl}}{n} = 2 + \\sum_{k=0}^{n-1}\\M{\\fun{insl}}{k}.\n\\label{eq:Mmkl0}\n\\end{equation}\nOne salient feature of leaf insertion is that internal nodes do not\nmove, hence the internal\\index{binary search tree!internal path\n  length} path length of the nodes is invariant and the cost of\nsearching all keys in a tree of size~\\(n\\) is the cost of inserting\nthem in the first place. We already noticed that the former cost is,\nin average, \\(n + \\Expected{I_n}\\); the latter cost is\n\\(\\sum_{k=0}^{n-1}\\M{\\fun{insl}}{k}\\). From equation~\\eqref{eq:Mmkl0}\nthen comes\n\\begin{equation}\n%\\abovedisplayskip=2pt\n%\\belowdisplayskip=4pt\nn + \\Expected{I_n} = \\M{\\fun{mkl}}{n} - 2\n\\label{eq:n_EIn}\n\\end{equation}\n(The subtraction of~\\(2\\) is to account for rules~\\(\\smash{\\xi}\\)\nand~\\(\\smash{\\psi}\\), which perform no insertion.) The cost of a leaf\ninsertion is that of an unsuccessful search:\n\\begin{equation}\n%\\abovedisplayskip=4pt\n%\\belowdisplayskip=4pt\n\\M{\\fun{insl}}{k} = \\M{\\fun{mem}}{k{\\scriptscriptstyle (-)}}.\n\\label{eq:n_plus_EIn}\n\\end{equation}\nRecalling equation~\\eqref{eq:Mmems} \\vpageref{eq:Mmems},\nequations~\\eqref{eq:Mmkl0}, \\eqref{eq:n_EIn} and~\\eqref{eq:n_plus_EIn}:\n\\begin{equation*}\n\\abovedisplayskip=2pt\n\\belowdisplayskip=0pt\n\\M{\\fun{mem}}{n{\\scriptscriptstyle(+)}}\n= 1 + \\frac{1}{n}\\Expected{I_n}\n= \\frac{1}{n}(\\M{\\fun{mkl}}{n} - 2)\n= \\frac{1}{n}\\sum_{k=0}^{n-1}\\M{\\fun{insl}}{k}\n= \\frac{1}{n}\\sum_{k=0}^{n-1}\\M{\\fun{mem}}{k{\\scriptscriptstyle (-)}}.\n\\end{equation*}\nFinally, using equation~\\eqref{eq:Mmem} \\vpageref{eq:Mmem}, we deduce\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\frac{1}{n}\\sum_{k=0}^{n-1}\\M{\\fun{mem}}{k{\\scriptscriptstyle (-)}}\n=\n\\left(1 + \\frac{1}{n}\\right)\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} - \\frac{1}{n} - 2.\n\\end{equation*}\nEquivalently,\n\\begin{equation*}\n\\abovedisplayskip=-7pt\n\\abovedisplayshortskip=-7pt\n2n + 1 + \\sum_{k=0}^{n-1}\\M{\\fun{mem}}{k{\\scriptscriptstyle (-)}}\n= (n+1) \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}.\n\\end{equation*}\nThis recurrence is easy to solve if we subtract its instance when\n\\(n-1\\):\n\\begin{equation*}\n\\abovedisplayskip=6pt\n\\belowdisplayskip=6pt\n2 + \\M{\\fun{mem}}{n-1{\\scriptscriptstyle(-)}} = \n(n+1) \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\n- n \\M{\\fun{mem}}{n-1{\\scriptscriptstyle (-)}}.\n\\end{equation*}\nNoting that \\(\\M{\\fun{mem}}{0{\\scriptscriptstyle (-)}} = 1\\), the\nequation becomes\n\\begin{equation*}\n\\abovedisplayskip=0pt\n\\belowdisplayskip=0pt\n\\M{\\fun{mem}}{0{\\scriptscriptstyle (-)}} = 1,\\quad\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\n= \\M{\\fun{mem}}{n-1{\\scriptscriptstyle (-)}} + \\frac{2}{n+1},\n\\end{equation*}\nthus\n\\begin{equation}\n\\abovedisplayskip=-6pt\n\\abovedisplayshortskip=-6pt\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} =\n1 + 2 \\sum_{k=2}^{n+1}\\frac{1}{k} = 2H_{n+1} - 1,\n\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}$}\n\\label{eq:Mmem_fail}\n\\end{equation}\nwhere \\(H_n := \\sum_{k=1}^{n}1/k\\)~is the \\(n\\)th harmonic\nnumber\\index{harmonic number}. Replacing\n\\(\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\\) back into\nequation~\\eqref{eq:Mmem} and using \\(H_{n+1} = H_n + 1/(n+1)\\) yields\n\\begin{equation}\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} =\n2\\left(1+\\frac{1}{n}\\right)H_n - 3.\n\\index{mem@$\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}$}\n\\label{eq:Mmem_ok}\n\\end{equation}\nFrom inequations~\\eqref{ineq:Hn} \\vpageref{ineq:Hn} and\nequations~\\eqref{eq:Mmem_fail} and~\\eqref{eq:Mmem_ok}:\n\\begin{equation*}\n\\M{\\fun{insl}}{n}\n\\sim \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}}\n\\sim \\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} \\sim 2 \\ln n.\n\\end{equation*}\nWe obtain more information about the relative asymptotic behaviours of\n\\(\\M{\\fun{mem}}{n{\\scriptscriptstyle(-)}}\\) and\n\\(\\M{\\fun{mem}}{n{\\scriptscriptstyle(+)}}\\) by looking at their\ndifference instead of their ratio:\n\\begin{equation*}\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} -\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} = \n\\frac{2}{n}(n + 1 - H_{n+1}) \\sim 2\n\\quad\\text{and}\\quad\n1 \\leqslant \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} -\n\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} < 2.\n\\end{equation*}\nThe average difference between an unsuccessful search and a successful\none tends slowly to~\\(2\\) for large values of~\\(n\\), which may not be\nintuitive. We can use this result to compare the average difference of\nthe costs of a successful search with \\fun{mem/2} and\n\\fun{mem\\(_3\\)/2} (Andersson). Recalling\nequation~\\eqref{eq:Andersson_average} \\vpageref{eq:Andersson_average},\nwe draw \\(1 + \\M{\\fun{mem}}{n{\\scriptscriptstyle (-)}} =\n\\M{\\fun{mem}_3}{n{\\scriptscriptstyle (+)}}\\). The previous result now\nyields\n\\begin{equation*}\n  \\M{\\fun{mem}_3}{n{\\scriptscriptstyle (+)}} -\n  \\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}} \\sim 3.\n\\index{mem3@$\\M{\\fun{mem}_3}{n{\\scriptscriptstyle (+)}}$}\n\\end{equation*}\nTherefore, the extra cost of Andersson's variant in case of a\nsuccessful search is asymptotically~\\(3\\), in average.\n\nFurthermore, replacing \\(\\M{\\fun{mem}}{n{\\scriptscriptstyle\n    (-)}}\\) and \\(\\M{\\fun{mem}}{n{\\scriptscriptstyle (+)}}\\) into\nequations~\\eqref{eq:Mmems} leads to\n\\begin{equation}\n\\Expected{I_n} = 2(n+1)H_n - 4n\n\\quad\\text{and}\\quad\n\\Expected{E_n} = 2(n+1)H_n - 2n.\n\\label{eq:IEn}\n\\end{equation}\nThus \\(\\Expected{I_n} \\sim \\Expected{E_n} \\sim 2n\\ln n\\). Note how\neasier it is to find~\\(\\Expected{I_n}\\) for binary search trees,\ncompared to simple binary trees.\n\nIf we are interested in slightly more theoretical results, we may like\nto know the average number of comparisons involved in a search and an\ninsertion. A glance back at \\fig~\\vref{fig:mem} uncovers that two\n2-way comparisons are done when going down and one 2-way comparison\n(equality) is checked when finding the key, otherwise none:\n\\begin{equation}\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(+)}}\n  = 1 + \\frac{2}{n}\\Expected{I_n}\n\\quad\\text{and}\\quad\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}}\n  = \\frac{2}{n+1}\\Expected{E_n}.\n\\label{eq:Mmem_cmp1}\n\\end{equation}\nReusing equations~\\eqref{eq:IEn}, we conclude that\n\\begin{equation}\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(+)}}\n  = 4\\left(1+\\frac{1}{n}\\right)H_n - 7\n\\quad\\text{and}\\quad\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}}\n  = 4H_n + \\frac{4}{n+1} - 4.\n\\index{mem@$\\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}}$}\n\\index{mem@$\\OM{\\fun{mem}}{n{\\scriptscriptstyle(+)}}$}\n\\label{eq:Mmem_cmp2}\n\\end{equation}\nClearly, we have \\(\\OM{\\fun{mem}}{n{\\scriptscriptstyle(+)}} \\sim\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}} \\sim 4\\ln n\\). Furthermore,\n\\begin{equation*}\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle (-)}} -\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle (+)}} = \n\\frac{4}{n+1} - \\frac{4}{n}H_n + 3 \\sim 3\n\\quad\\text{and}\\quad\n1 \\leqslant \\OM{\\fun{mem}}{n{\\scriptscriptstyle (-)}} -\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle (+)}} < 3.\n\\end{equation*}\n\nThe average costs for Andersson's search and insertions are easy to\ndeduce as well, from equation~\\eqref{eq:Andersson_average}\n\\vpageref{eq:Andersson_average} and~\\eqref{eq:Mmem_fail} on\npage~\\pageref{eq:Mmem_fail}: \\(\\M{\\fun{mem}_3}{n} = 2H_{n+1} \\sim 2\n\\ln n\\).\\index{mem3@$\\M{\\fun{mem}_3}{n}$} A glimpse back at\n\\fig~\\vref{fig:mem3} brings to the fore that one 2-way comparison (\\(x\n\\succ y\\)) is performed when descending in the tree and one more when\nstopping at an external node, whether the search is successful or not:\n\\begin{equation*}\n  \\OM{\\fun{mem}_3}{n} = \\frac{1}{n+1}\\Expected{E_n} =\n  2H_n + \\frac{2}{n+1} - 2 \\sim 2\\ln n.\n\\end{equation*}\nWe can now finally compare the average number of comparisons between\n\\fun{mem/2} and \\fun{mem\\(_3\\)/2} (Andersson):\n\\begin{align*}\n  \\OM{\\fun{mem}}{n{\\scriptscriptstyle(+)}} - \\OM{\\fun{mem}_3}{n}\n&= 2\\left(1 + \\frac{2}{n}\\right)H_n - \\frac{2}{n+1} - 5 \\sim 2\\ln n,\\\\\n  \\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}} - \\OM{\\fun{mem}_3}{n}\n&= 2H_n + \\frac{2}{n+1} - 2 \\sim 2\\ln n.\n\\end{align*}\nAs far as leaf insertion itself is concerned,\n\\fun{insl/2}\\index{insl@\\fun{insl/2}} behaves as\n\\fun{mem\\(_3\\)/2}\\index{mem3@\\fun{mem\\(_3\\)/2}}, except that no\ncomparison occurs at the external nodes. Also, from\nequations~\\eqref{eq:n_plus_EIn} and~\\eqref{eq:Mmem_fail}, we finish\nthe average case analysis of \\(\\fun{insl/2}\\):\n\\begin{equation*}\n  \\OM{\\fun{insl}}{n} =\n  \\OM{\\fun{mem}_3}{n} - 1 = 2H_n + \\frac{2}{n+1} -\n  3\\quad\\text{and}\\quad \\M{\\fun{insl}}{n} = 2H_{n+1} - 1.\n\\index{insl@$\\OM{\\fun{insl}}{n}$}\n\\index{mem3@$\\OM{\\fun{mem}_3}{n}$}\n\\end{equation*}\nFinally, from equation~\\eqref{eq:n_EIn} and~\\eqref{eq:IEn}, we deduce\n\\begin{equation}\n\\M{\\fun{mkl}}{n} = n + \\Expected{I_n} + 2 = 2(n+1)H_n - n + 2\n\\sim 2n\\ln n.\n\\index{mkl@$\\M{\\fun{mkl}}{n}$}\n\\label{eq:Mmkl}\n\\end{equation}\n\n\\mypar{Amortised cost}\n\nThe worst case for leaf insertion occurs when the search tree is\ndegenerate\\index{binary tree!degenerate $\\sim$} and the key to be\ninserted becomes the deepest leaf. If the tree has size~\\(n\\), then\n\\(n+1\\) calls are performed, as seen in \\fig~\\vref{fig:insl}, so\n\\(\\W{\\fun{insl}}{n} = n + 1\\)\\index{insl@$\\W{\\fun{insl}}{n}$} and\n\\(\\OW{\\fun{insl}}{n} = n\\).\\index{insl@$\\OW{\\fun{insl}}{n}$} In the\ncase of Andersson's insertion in \\fig~\\vref{fig:insl1}, the worst case\nis identical but there is a supplementary call to set the candidate\nkey, so \\(\\W{\\fun{insl}_1}{n} = n +\n2\\).\\index{insl1@$\\W{\\fun{insl}_1}{n}$} Moreover, the number of\ncomparisons is symmetric and equals~\\(1\\) per internal node, so\n\\(\\OW{\\fun{insl}_1}{n} = n\\)\\index{insl1@$\\OW{\\fun{insl}_1}{n}$} and\nany degenerate tree is the worst configuration.\n\nThe best case for leaf insertion with \\(\\fun{insl/2}\\) and\n\\(\\fun{insl\\(_1\\)/2}\\) happens when the key has to be inserted as the\nleft or right child of the root, to wit, the root is the minimum or\nmaximum key in inorder, so \\(\\B{\\fun{insl}}{n} =\n2\\)\\index{insl@$\\B{\\fun{insl}}{n}$} and \\(\\B{\\fun{insl}_1}{n} =\n3\\).\\index{insl@$\\B{\\fun{insl}_1}{n}$} As far as comparisons are\nconcerned: \\(\\OB{\\fun{insl}}{n} = 1\\)\\index{insl@$\\OB{\\fun{insl}}{n}$}\nand \\(\\OB{\\fun{insl}_1}{n} = 2\\).\\index{insl1@$\\OB{\\fun{insl}_1}{n}$}\n\nWhile turning our attention to the extremal costs of\n\\fun{mkl/1}\\index{mkl@\\fun{mkl/1}} and\n\\fun{mkr/1}\\index{mkr@\\fun{mkr/1}}, we need to realise that we cannot\nsimply sum minimum or maximum costs of \\fun{insl/2} because, as\nmentioned earlier, the call \\(\\fun{insl}(x,t)\\) depends on~\\(x\\) and\nthe shape of~\\(t\\). For instance, after three keys have been inserted\ninto an empty tree, the root has no more empty children, so the best\ncase we determined previously is not pertinent anymore.\n\nLet \\(\\OB{\\fun{mkl}}{n}\\)\\index{mkl@$\\OB{\\fun{mkl}}{n}$} be the\nminimum number of comparisons needed to construct a binary search tree\nof size~\\(n\\) using leaf insertions. If we want to minimise the cost\nat each insertion, then the path length for each new node must be as\nsmall as possible and this is achieved if the tree continuously grows\nas a perfect \\index{binary tree!perfect $\\sim$} or almost\nperfect\\index{binary\n  tree!almost perfect $\\sim$} tree. The former is a tree whose\nexternal nodes all belong to the same level, a configuration we have\nseen \\vpageref{par:perfection} (the tree fits tightly inside an\nisosceles triangle); the latter is a tree whose external nodes lie on\ntwo consecutive levels and we have seen this kind of tree in the\nparagraph devoted to comparison trees and the minimean of sorting\n\\vpageref{par:opt_sort:minimean}.\n\nLet us assume first that the tree is perfect, with size~\\(n\\) and\nheight~\\(h\\).\\index{binary tree!height} The height is the length,\ncounted in number of edges, of the longest path from the root to an\nexternal node. The total path length for a level~\\(k\\) made only of\ninternal nodes is~\\(k2^k\\). Therefore, summing all levels yields\n\\begin{equation}\n\\OB{\\fun{mkl}}{n} = \\sum_{k=1}^{h-1}k2^k = (h-2)2^h + 2,\n\\label{eq:OBmkl_tmp1}\n\\end{equation}\nby reusing equation~\\eqref{eq:Sj} \\vpageref{eq:Sj}. Moreover, summing\nthe number of internal nodes by levels: \\(n = \\sum_{k=0}^{h-1}2^k =\n2^{h} - 1\\), hence \\(h = \\lg(n+1)\\), which we can replace in\nequation~\\eqref{eq:OBmkl_tmp1} to obtain\n\\begin{equation*}\n\\OB{\\fun{mkl}}{n} = (n+1)\\lg(n+1) - 2n.\n\\end{equation*}\nWe proved \\(1 + \\floor{\\lg n} = \\ceiling{\\lg(n+1)}\\) when establishing\nthe maximum number of comparisons of top\\hyp{}down merge sort in\nequation~\\eqref{eq:top} \\vpageref{eq:top}, so we can proceed\nconclusively:\n\\begin{equation}\n\\OB{\\fun{mkl}}{n} = (n+1)\\floor{\\lg n} - n + 1.\n\\index{mkl@$\\OB{\\fun{mkl}}{n}$}\n\\label{eq:OBmkl_perfect}\n\\end{equation}\n\nLet us assume now that the tree is almost perfect, with the\npenultimate level \\(h-1\\) containing \\(q \\neq 0\\)~internal nodes, so\n\\begin{equation}\n\\OB{\\fun{mkl}}{n} = \\sum_{k=1}^{h-2}k2^k + (h-1)q\n= (h-3)2^{h-1} + 2 + (h-1)q.\n\\label{eq:OBmkl_tmp2}\n\\end{equation}\nMoreover, the total number~\\(n\\) of internal nodes, when summed level\nby level, satisfies \\(n = \\sum_{k=0}^{h-2}2^k + q = 2^{h-1} - 1 + q\\),\nhence \\(q = n - 2^{h-1} + 1\\). By definition, we have \\(0 < q\n\\leqslant 2^{h-1}\\), hence \\(0 < n - 2^{h-1} + 1 \\leqslant 2^{h-1}\\),\nwhich yields \\(h - 1 < \\lg(n+1) \\leqslant h\\), then \\(h =\n\\ceiling{\\lg(n+1)} = \\floor{\\lg n} + 1\\), whence \\(q = n -\n2^{\\floor{\\lg n}} + 1\\). We can now substitute \\(h\\)~and~\\(q\\) by\ntheir newly found values in terms of~\\(n\\) back into\nequation~\\eqref{eq:OBmkl_tmp2}:\n\\begin{equation}\n\\OB{\\fun{mkl}}{n} = (n+1)\\floor{\\lg n} - 2^{\\floor{\\lg n}} + 2.\n\\label{eq:OBmkl_almost_perfect}\n\\end{equation}\nComparing equations~\\eqref{eq:OBmkl_perfect}\nand~\\eqref{eq:OBmkl_almost_perfect}, we see that the number of\ncomparisons is minimised when the tree is perfect, so \\(n = 2^p -\n1\\). The asymptotic approximation of \\(\\OB{\\fun{mkl}}{n}\\) is not\ndifficult to find, as long as we avoid the pitfall \\(2^{\\floor{\\lg n}}\n\\sim n\\). Indeed, consider the function \\(x(p) := 2^p - 1\\) ranging\nover the positive integers. First, let us notice that, for all\n\\(p>0\\),\n\\begin{equation*}\n2^{p-1} \\leqslant 2^p - 1 < 2^p \\Rightarrow p-1 \\leqslant \\lg(2^p-1) <\np \\Rightarrow \\floor{\\lg(2^p-1)} = p-1.\n\\end{equation*}\nTherefore, \\(2^{\\floor{\\lg(x(p))}} = 2^{p-1} = (x(p)+1)/2 \\sim x(p)/2\n\\nsim x(p)\\), which proves that \\(2^{\\floor{\\lg(n)}} \\nsim n\\) when\n\\(n=2^p-1 \\rightarrow \\infty\\). Instead, in the case of\nequation~\\eqref{eq:OBmkl_perfect}, let us use the standard\ninequalities \\(x - 1 < \\floor{x} \\leqslant x\\):\n\\begin{equation*}\n(n+1)\\lg n - 2n < \\OB{\\fun{mkl}}{n} \\leqslant (n+1)\\lg n - n + 1.\n\\end{equation*}\nIn the case of equation~\\eqref{eq:OBmkl_almost_perfect}, let us use\nthe definition of the fractional part\\index{fractional part} \\(\\{x\\}\n:= x - \\floor{x}\\). Obviously, \\(0 \\leqslant \\{x\\} < 1\\). Then\n\\begin{equation*}\n\\OB{\\fun{mkl}}{n} = (n+1)\\lg n - n \\cdot \\theta(\\{\\lg n\\})\n                    + 2 - \\{\\lg n\\},\n\\end{equation*}\nwhere \\(\\theta(x) := 1 + 2^{-x}\\). Let us minimise and maximise the\nlinear term: we have \\(\\min_{0 \\leqslant x <\n  1}\\theta(x) = \\theta(1) = 3/2\\) and \\(\\max_{0 \\leqslant x <\n  1}\\theta(x) = \\theta(0) = 2\\). Keeping in mind that \\(x=\\{\\lg n\\}\\),\nwe have\n\\begin{equation*}\n(n+1)\\lg n - 2n + 2 < \\OB{\\fun{mkl}}{n} < (n+1)\\lg n - \\tfrac{3}{2}n + 1.\n\\end{equation*}\nIn any case, it is now clearly established that \\(\\OB{\\fun{mkl}}{n}\n\\sim n\\lg n\\).\\index{mkl@$\\OB{\\fun{mkl}}{n}$}\n\nLet \\(\\OW{\\fun{mkl}}{n}\\)\\index{mkl@$\\OW{\\fun{mkl}}{n}$} be the\nmaximum number of comparisons to build a binary search tree of\nsize~\\(n\\) by leaf insertions. If we maximise each insertion, we need\nto grow a degenerate tree and insert at one external node of maximal\npath length: \\(\\OW{\\fun{mkl}}{n} = \\sum_{k=1}^{n-1}k =\n\\tfrac{1}{2}n(n-1) \\sim \\tfrac{1}{2}n^2\\).\\index{binary search\n  tree!leaf insertion|)}\n\n\\mypar{Root insertion}\n\\index{binary search tree!root insertion|(}\n\nIf recently inserted keys are looked up, the cost is relatively high\nbecause these keys are leaves or close to a leaf. In this scenario,\ninstead of inserting a key as a leaf, it is better to insert it as a\nroot \\citep{Stephenson_1980}. The idea is to perform a leaf insertion\nand, on the way back to the root (that is to say, after the recursive\ncalls are evaluated, one after the other), we perform rotations to\nbring the inserted node up to the root. More precisely, if the node\nwas inserted in a left subtree, then a right rotation brings it one\nlevel up, otherwise a left rotation has the same effect. The\ncomposition of these rotations brings the leaf to the root. Right\nrotation, \\fun{rotr/1}\\index{rotr@\\fun{rotr/1}} (\\emph{rotate right})\nand left rotation, \\fun{rotl/1}\\index{rotl@\\fun{rotl/1}} (\\emph{rotate\n  left}),\\index{binary tree!rotation} were discussed in\nsection~\\ref{sec:traversals} \\vpageref{par:rotation} and are defined\nin \\fig~\\vref{fig:rotations}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{rotr}(\\fun{bst}(y,\\fun{bst}(x,t_1,t_2),t_3))\n& \\xrightarrow{\\smash{\\epsilon}} & \\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3)).\\\\\n\\fun{rotl}(\\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3)))\n& \\xrightarrow{\\smash{\\zeta}} & \\fun{bst}(y,\\fun{bst}(x,t_1,t_2),t_3).\n\\end{array}}\n\\end{equation*}\n\\caption{Right (\\(\\smash{\\epsilon}\\)) and left (\\(\\smash{\\zeta}\\)) rotations\\label{fig:rotations}}\n\\end{figure}\nObviously, they commute and are inverses of each other:\n\\begin{equation*}\n\\abovedisplayskip=5pt\n\\belowdisplayskip=5pt\n\\fun{rotl}(\\fun{rotr}(t)) \\equiv \\fun{rotr}(\\fun{rotl}(t)) \\equiv t.\n\\end{equation*}\nMoreover, and less trivially, they preserve inorder traversals:\n\\begin{equation*}\n  \\abovedisplayskip=5pt\n  \\belowdisplayskip=5pt\n  \\fun{in}_3(\\fun{rotl}(t)) \\equiv \\fun{in}_3(\\fun{rotr}(t)) \\equiv\n  \\fun{in}_3(t),\n\\end{equation*}\nwhere \\fun{in\\(_3\\)/1}\\index{in3@\\fun{in\\(_3\\)/1}} computes the\ninorder traversal of a tree: \\(\\fun{in}_3(t) \\rightarrow\n\\fun{in}_2(t,\\el)\\), with \\fun{in\\(_2\\)/2}\\index{in2@\\fun{in\\(_2\\)/2}}\nbeing defined in \\fig~\\vref{fig:bst0}. This theorem is inherently\nconnected to\n\\(\\pred{Rot}{x,y,t_1,t_2,t_3}\\)\\index{Rot@\\predName{Rot}},\n\\vpageref{def:Rot}, and it is easy to prove, without recourse to\ninduction. First, we could remark that if \\(\\fun{in}_3(t) \\equiv\n\\fun{in}_3(\\fun{rotl}(t))\\), then, replacing \\(t\\) by\n\\(\\fun{rotr}(t)\\) yields the equivalence \\(\\fun{in}_3(\\fun{rotr}(t))\n\\equiv \\fun{in}_3(\\fun{rotl}(\\fun{rotr}(t))) \\equiv \\fun{in}_3(t)\\),\nso we only need to prove \\(\\fun{in}_3(\\fun{rotl}(t)) \\equiv\n\\fun{in}_3(t)\\).  Since the left\\hyp{}hand side is larger, we should\ntry to rewrite it into the right\\hyp{}hand side. Because a left\nrotation requires the tree to have the shape\n\\(t=\\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3))\\), we have the rewrites of\n\\fig~\\vref{fig:in_rotr}.\n\\begin{figure}\n  \\begin{equation*}\n    \\boxed{\n      \\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n  \\fun{in}_3(\\fun{rotl}(t))\n  & \\rightarrow & \\fun{in}_2(\\fun{rotl}(t),\\el)\\\\\n  & = & \\fun{in}_2(\\fun{rotl}(\\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3))),\\el)\\\\\n  & \\xrightarrow{\\smash{\\epsilon}} &\n  \\fun{in}_2(\\fun{bst}(y,\\fun{bst}(x,t_1,t_2),t_3),\\el)\\\\\n  & \\rightarrow &\n  \\fun{in}_2(\\fun{bst}(x,t_1,t_2),\\cons{y}{\\fun{in}_2(t_3,\\el)})\\\\\n  & \\Rrightarrow &\n \\fun{in}_2(t_1,\\cons{x}{\\fun{in}_2(t_2,\\cons{y}{\\fun{in}_2(t_3,\\el)})})\\\\\n  & \\leftarrow &\n  \\fun{in}_2(t_1,\\cons{x}{\\fun{in}_2(\\fun{bst}(y,t_2,t_3),\\el)})\\\\\n  & \\leftarrow &\n  \\fun{in}_2(\\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3)),\\el)\\\\\n  & = &\n  \\fun{in}_2(t,\\el)\\\\\n  & \\leftarrow &\n  \\fun{in}_3(t).\\hfill\\Box\n\\end{array}\n}\n\\end{equation*}\n\\caption{Proof of \\(\\fun{in}_3(\\fun{rotl}(t)) \\equiv\n  \\fun{in}_3(t)\\)\\label{fig:in_rotr}}\n\\end{figure}\nIf we rotate subtrees, as we did, for example, in \\fig~\\vref{fig:rot},\nthe same theorem implies that the inorder traversal of the whole tree\nis invariant.\n\nA corollary is that rotations keep invariant the property of being a\nbinary search tree (\\fig~\\vref{fig:bst}):\n\\begin{equation*}\n\\abovedisplayskip=5pt\n\\belowdisplayskip=5pt\n\\fun{bst}(\\fun{rotl}(t)) \\equiv \\fun{bst}(\\fun{rotr}(t)) \\equiv \\fun{bst}(t).\n\\end{equation*}\nIndeed, assuming that \\fun{bst/1} is the specification of\n\\fun{bst\\(_0\\)/1} in \\fig~\\vref{fig:bst0}, and that the latter is\ncorrect, that is, \\(\\fun{bst}(t) \\equiv \\fun{bst}_0(t)\\), it is quite\neasy to prove our theorem, with the help of the previous theorem\n\\(\\fun{in}_3(\\fun{rotl}(t)) \\equiv \\fun{in}_3(t)\\), which is\nequivalent to \\(\\fun{in}_2(\\fun{rotl}(t),\\el) \\equiv\n\\fun{in}_2(t,\\el)\\), and noticing that it is sufficient to prove\n\\(\\fun{bst}_0(\\fun{rotl}(t)) \\equiv \\fun{bst}_0(t)\\). We conclude:\n\\begin{equation*}\n\\fun{bst}_0(\\fun{rotl}(t))\n\\Rrightarrow \\fun{ord}(\\fun{in}_2(\\fun{rotl}(t),\\el))\n\\equiv \\fun{ord}(\\fun{in}_2(t,\\el))\n\\leftarrow \\fun{bst}_0(t).\n\\end{equation*}\n\nLet us consider now an example of root insertion in\n\\fig~\\vref{fig:insr_ex}, where the tree of \\fig~\\vref{fig:bst_ex} is\naugmented with~\\(7\\).\n\\begin{figure}[b]\n\\centering\n\\includegraphics[bb=71 641 406 724]{insr_ex}%[bb=71 645 406 718]\n\\caption{Root insertion of \\(7\\) into \\fig~\\vref{fig:bst_ex}\n\\label{fig:insr_ex}}\n\\end{figure}\nRemark that the transitive closure \\;\\((\\twoheadrightarrow)\\) captures\nthe preliminary leaf insertion, \\((\\xrightarrow{\\smash{\\epsilon}})\\)\nis a right rotation and \\((\\xrightarrow{\\smash{\\zeta}})\\) is a left\nrotation. It is now a simple matter to modify the definition of\n\\fun{insl/2} so it becomes root insertion as \\fun{insr/2}, in\n\\fig~\\vref{fig:insr}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{insr}(y,\\fun{bst}(x,t_1,t_2)) & \\xrightarrow{\\smash{\\eta}} &\n  \\fun{rotr}(\\fun{bst}(x,\\fun{insr}(y,t_1),t_2)),\n  \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{insr}(y,\\fun{bst}(x,t_1,t_2)) & \\xrightarrow{\\smash{\\theta}} &\n  \\fun{rotl}(\\fun{bst}(x,t_1,\\fun{insr}(y,t_2)));\\\\\n\\fun{insr}(y,\\fun{ext}()) & \\xrightarrow{\\smash{\\iota}} & \\fun{bst}(y,\\fun{ext}(),\\fun{ext}()).\n\\end{array}}\n\\end{equation*}\n\\caption{Root insertion with possible duplicates\\label{fig:insr}}\n\\end{figure}\nNote that we can avoid creating the temporary internal nodes\n\\(\\fun{bst}(x,\\dots,t_2)\\) and \\(\\fun{bst}(x,t_1,\\dots)\\) by modifying\n\\fun{rotl/1} and \\fun{rotr/1} so that they take three arguments\n(\\fun{rotl\\(_0\\)/3} and \\fun{rotr\\(_0\\)/3}), as shown along the new\nversion \\fun{insr\\(_0\\)/2} in \\fig~\\ref{fig:insr0}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n\\fun{insr}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{rotr}_0(x,\\fun{insr}_0(y,t_1),t_2),\n  \\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{insr}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{rotl}_0(x,t_1,\\fun{insr}_0(y,t_2));\\\\\n\\fun{insr}_0(y,\\fun{ext}()) & \\rightarrow &\n\\fun{bst}(y,\\fun{ext}(),\\fun{ext}()).\\\\\n\\\\\n\\fun{rotr}_0(y,\\fun{bst}(x,t_1,t_2),t_3)\n& \\rightarrow & \\fun{bst}(x,t_1,\\fun{bst}(y,t_2,t_3)).\\\\\n\\fun{rotl}_0(x,t_1,\\fun{bst}(y,t_2,t_3))\n& \\rightarrow & \\fun{bst}(y,\\fun{bst}(x,t_1,t_2),t_3).\n\\end{array}}\n\\end{equation*}\n\\caption{Root insertion with possible duplicates (bis)\\label{fig:insr0}}\n\\end{figure}\n\nA comparison between leaf and root insertions reveals interesting\nfacts. For instance, because leaf insertion does not displace any\nnode, making the same tree from two permutations of the keys bears the\nsame cost, for example, \\((1,3,2,4)\\) and \\((1,3,4,2)\\). On the other\nhand, as noted by \\cite{GeldenhuysVanderMerwe_2009}, making the same\nsearch tree using different root insertions may yield different costs,\nlike \\((1,2,4,3)\\) and \\((1,4,2,3)\\). They also prove that all the\ntrees of a given size can either be created by leaf or root insertions\nbecause\n\\begin{equation}\n\\pred{RootLeaf}{s} \\colon \\fun{mkr}(s) \\equiv \\fun{mkl}(\\fun{rev}(s)),\n\\label{thm:RootLeaf}\n\\index{RootLeaf@\\predName{RootLeaf}}\n\\end{equation}\nwhere \\fun{mkr/1}\\index{mkr@\\fun{mkr/1}} \\index{mkr@\\fun{mkr/2}}\n(\\emph{make roots}) is easily defined in \\fig~\\vref{fig:mkr}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{\n\\begin{array}{@{}r@{\\;}l@{\\;}lr@{\\;}l@{\\;}l@{}}\n\\fun{mkr}(s) & \\xrightarrow{\\smash{\\kappa}} &\n\\fun{mkr}(s,\\fun{ext}()).\n& \\fun{mkr}(\\el,t) & \\xrightarrow{\\smash{\\lambda}} & t;\\\\\n&&&\\fun{mkr}(\\cons{x}{s},t) & \\xrightarrow{\\smash{\\mu}} & \\fun{mkr}(s,\\fun{insr}(x,t)).\n\\end{array}}\n\\end{equation*}\n\\caption{Making a binary search tree with root insertions\n\\label{fig:mkr}}\n\\end{figure}\nNotice that this is equivalent to claim \\(\\fun{mkr}(s) \\equiv\n\\fun{mklR}(s)\\), where \\fun{mklR/1} is defined in\nequation~\\eqref{eq:mklR} \\vpageref{eq:mklR}. It is worth proving\n\\(\\pred{RootLeaf}{s}\\) here because, contrary to\n\\cite{GeldenhuysVanderMerwe_2009}, we want to use structural induction\nto exactly follow the syntax of the function definitions, instead of\ninduction on sizes, an adventitious concept, and we want to avoid\nusing ellipses when describing the data. Furthermore, our logical\nframework is not separated from our actual function definitions (the\nabstract program): the rewrites themselves, that is, the computational\nsteps, give birth to a logical interpretation as classes of equivalent\nterms.\n\nWe start by remarking that \\(\\pred{RootLeaf}{s}\\) is equivalent to\n\\begin{equation*}\n\\pred{RootLeaf\\(_0\\)}{s} \\colon \\fun{mkr}(s) \\equiv\n  \\fun{mkl}(\\fun{rev}_0(s)),\n\\index{RootLeaf0@\\predName{RootLeaf\\(_0\\)}}\n\\end{equation*}\nwhere\n\\fun{rev\\(_0\\)/1} is defined at the start of\nsection~\\vref{sec:reversal}, where we prove \\(\\pred{EqRev}{s} \\colon\n\\fun{rev}_0(s) \\equiv \\fun{rev}(s)\\).\\index{EqRev@\\predName{EqRev}} It\nis often a good idea to use \\fun{rev\\(_0\\)/1} in inductive proofs\nbecause of rule~\\(\\smash{\\delta}\\) defining\n\\(\\fun{rev}_0(\\cons{x}{s})\\) directly in terms of \\(\\fun{rev}_0(s)\\).\nLet us recall the relevant definitions:\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*}\nOf course, \\fun{rev\\(_0\\)/1}\\index{rev0@\\fun{rev\\(_0\\)/1}} is\nworthless as a program because of its quadratic cost, which cannot\ncompete with the linear cost of \\fun{rev/1}\\index{rev@\\fun{rev/1}},\nbut, as far as theorem proving is concerned, it is a valuable\nspecification and lemma \\(\\pred{EqRev}{s}\\) allows us to transfer any\nequivalence depending upon \\fun{rev\\(_0\\)/1} into an equivalence\nemploying \\fun{rev/1}.\n\nLet us proceed by induction on the structure of the\nstack~\\(s\\). First, we need to prove directly (without induction)\n\\(\\pred{RootLeaf\\(_0\\)}{\\el}\\). We have\n\\begin{equation*}\n\\fun{mkr}(\\el) \\!\\xrightarrow{\\smash{\\kappa}}\\! \\fun{mkr}(\\el,\\fun{ext}())\n\\!\\xrightarrow{\\smash{\\lambda}}\\! \\fun{ext}()\n\\!\\xleftarrow{\\smash{\\psi}}\\! \\fun{mkl}(\\el,\\fun{ext}())\n\\!\\xleftarrow{\\smash{\\xi}}\\! \\fun{mkl}(\\el)\n\\!\\xleftarrow{\\smash{\\gamma}}\\! \\fun{mkl}(\\fun{rev}_0(\\el)\\!).\n\\end{equation*}\nSecond, we set the inductive hypothesis to be\n\\(\\pred{RootLeaf\\(_0\\)}{s}\\) and we proceed to prove\n\\(\\pred{RootLeaf\\(_0\\)}{\\cons{x}{s}}\\), for any~\\(x\\). Since the\nright\\hyp{}hand side is larger, we start rewriting it and whenever we\nfeel astray, we rewrite the other side, aiming at their\nconvergence. On the way, there will be steps, in the form of\nequivalences, which constitute lemmas (subgoals) that will need\ndemonstration later.\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\qquad}r@{}}\n\\fun{mkl}(\\fun{rev}_0(\\cons{x}{s}))\n& \\xrightarrow{\\smash{\\delta}} &\n  \\fun{mkl}(\\fun{cat}(\\fun{rev}_0(s),[x]))\\\\\n& \\Rra{\\xi} &\n  \\fun{mkl}(\\fun{cat}(\\fun{rev}_0(s),[x]),\\fun{ext}())\\\\\n& \\equiv_0 & \\fun{mkl}([x],\\fun{mkl}(\\fun{rev}_0(s),\\fun{ext}()))\n& (\\text{Lemma})\\\\\n& \\Rra{\\omega} &\n  \\fun{mkl}(\\el,\\fun{insl}(x,\\fun{mkl}(\\fun{rev}_0(s),\\fun{ext}())))\\\\\n& \\Rra{\\psi} &\n  \\fun{insl}(x,\\fun{mkl}(\\fun{rev}_0(s),\\fun{ext}()))\\\\\n& \\Lla{\\xi} &\n  \\fun{insl}(x,\\fun{mkl}(\\fun{rev}_0(s)))\\\\\n& \\equiv & \\fun{insl}(x,\\fun{mkr}(s)) & (\\pred{RootLeaf\\(_0\\)}{s}\\!)\\\\\n& \\xrightarrow{\\smash{\\xi}} &\n  \\fun{insl}(x,\\fun{mkr}(s,\\fun{ext}()))\\\\\n& \\equiv_1 & \\fun{mkr}(s,\\fun{insl}(x,\\fun{ext}()))\n& (\\text{Lemma})\\\\\n& \\xrightarrow{\\smash{\\phi}} & \n  \\fun{mkr}(s,\\fun{bst}(x,\\fun{ext}(),\\fun{ext}()))\\\\\n& \\xleftarrow{\\smash{\\iota}} &\n  \\fun{mkr}(s,\\fun{insr}(x,\\fun{ext}()))\\\\\n& \\xleftarrow{\\smash{\\mu}} & \\fun{mkr}(\\cons{x}{s},\\fun{ext}())\\\\\n& \\xleftarrow{\\smash{\\kappa}} & \\fun{mkr}(\\cons{x}{s}).\n& \\hfill\\Box\n\\end{array}\n\\end{equation*}\n\nNow, we have to prove the two lemmas that we identified with our proof\nsketch. The first one, in the instance of \\((\\equiv_0)\\), looks like a\ncorollary of\\index{MklCat@\\predName{MklCat}} \\(\\pred{MklCat}{u,v,t}\n\\colon \\fun{mkl}(\\fun{cat}(u,v),t) \\equiv_0\n\\fun{mkl}(v,\\fun{mkl}(u,t))\\). The first action to be undertaken when\nfacing a new proposition is to try to disprove it by some pertinent or\ntricky choice of variables. In this case, though, the truth of this\nlemma can be intuitively ascertained without effort, which gives us\nmore confidence for working out a formal proof, instead of dispensing\nwith one. It is enough to reason by induction on the structure of the\nstack~\\(u\\). First, we verify \\(\\pred{MklCat}{\\el,v,t}\\):\n\\begin{equation*}\n\\fun{mkl}(\\fun{cat}(\\el,v),t)\n  \\xrightarrow{\\smash{\\alpha}} \\fun{mkl}(v,t)\n  \\xleftarrow{\\smash{\\psi}} \\fun{mkl}(v,\\fun{mkl}(\\el,t)).\n\\end{equation*}\nSecond, we assume \\(\\pred{MklCat}{u,v,t}\\), for all~\\(v\\) and~\\(t\\),\nwhich is thus the inductive hypothesis, and we prove\n\\(\\pred{MklCat}{\\cons{x}{u},v,t}\\):\n\\begin{equation*}\n  \\begin{array}{@{}r@{\\;}l@{\\;}l@{\\quad}r@{}}\n      \\fun{mkl}(\\fun{cat}(\\cons{x}{u},v),t)\n& \\xrightarrow{\\smash{\\beta}} &\n  \\fun{mkl}(\\cons{x}{\\fun{cat}(u,v)},t)\\\\\n& \\Rra{\\omega} &\n  \\fun{mkl}(\\fun{cat}(u,v),\\fun{insl}(x,t))\\\\\n& \\equiv_0 & \\fun{mkl}(v,\\fun{mkl}(u,\\fun{insl}(x,t)))\n         & \\!\\!(\\pred{MklCat}{u,v,\\fun{inst}(x,t)}\\!)\\\\\n& \\xleftarrow{\\smash{\\omega}} &\n  \\fun{mkl}(v,\\fun{mkl}(\\cons{x}{u},t)). & \\hfill\\Box\n\\end{array}\n\\end{equation*}\n\nLet us formally define the second lemma whose instance we identified\nas \\((\\equiv_1)\\) in the proof of \\(\\pred{RootLeaf\\(_0\\)}{s}\\). Let\n\\begin{equation*}\n  \\pred{MkrInsr}{x,s,t} \\colon\n  \\fun{insl}(x,\\fun{mkr}(s,t)) \\equiv_1 \\fun{mkr}(s,\\fun{insl}(x,t)).\n\\end{equation*}\nThis proposition, despite its pleasurable symbolic symmetry, is not\ntrivial and may require some examples to be better grasped. It means\nthat a leaf insertion can be performed before or after a series of\nroot insertions, yielding in both cases the same tree. We approach the\nproof by induction on the structure of the stack~\\(s\\) only. (The\nother parameters are unlikely to be inductively relevant because\n\\(x\\)~is a key, so we can assume nothing about its internal structure,\nif any, and~\\(t\\) is the second parameter of both\n\\fun{mkr/2}\\index{mkr@\\fun{mkr/2}} and\n\\fun{insl/2}\\index{insl@\\fun{insl/2}}, so we do not know anything\nabout its shape nor contents.) We start, as usual, with a verification\n(A verification, by definition, does not involve the use of any\ninductive argument.) of the basis\\index{MkInsr@\\predName{MkInsr}}\n\\(\\pred{MkInsr}{x,\\el,t}\\):\n\\begin{equation*}\n  \\fun{insl}(x,\\fun{mkr}(\\el,t))\n\\xrightarrow{\\smash{\\lambda}} \\fun{insl}(x,t)\n\\Lla{\\lambda} \\fun{mkr}(\\el,\\fun{insl}(x,t)).\n\\end{equation*}\nWe now assume \\(\\pred{MkrInsr}{x,s,t}\\) for all~\\(x\\) and~\\(t\\), and\nwe try to prove \\(\\pred{MkrInsr}{x,\\cons{y}{s},t}\\), for all\nkeys~\\(y\\), by rewriting both sides of the equivalence and aiming at\nthe same term:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\;\\;\\,}r@{}}\n  \\fun{insl}(x,\\fun{mkr}(\\cons{y}{s},t))\n& \\xrightarrow{\\smash{\\mu}} &\n  \\fun{insl}(x,\\fun{mkr}(s,\\fun{insr}(y,t)))\\\\\n& \\equiv_1 & \\fun{mkr}(s,\\fun{insl}(x,\\fun{insr}(y,t)))\n           & (\\pred{MkrInsr}{x,s,\\fun{insr}(y,t)}\\!)\\\\\n& \\equiv_2 & \\fun{mkr}(s,\\fun{insr}(y,\\fun{insl}(x,t)))\n           & (\\text{Lemma})\\\\\n& \\Lla{\\mu} & \n  \\fun{mkr}(\\cons{y}{s},\\fun{insl}(x,t)).\n& \\hfill\\Box\n\\end{array}\n\\end{equation*}\nNote that we have found that we need a lemma in the guise of its\ninstance \\((\\equiv_2)\\), which states that a root insertion commutes\nwith a leaf insertion. This is not obvious and probably needs to be\nseen on some examples to be believed. The process of inductive\ndemonstration itself has brought us to the important concept on which\nour initial proposition hinges. Let the lemma in question be formally\ndefined as follows:\n\\begin{equation*}\n\\pred{Ins}{x,y,t} \\colon \\fun{insl}(x,\\fun{insr}(y,t))\n\\equiv_2 \\fun{insr}(y,\\fun{insl}(x,t)).\n\\index{Ins@\\predName{Ins}}\n\\end{equation*}\nWe will use induction on the structure of the tree~\\(t\\), because the\nother variables are keys, hence are atomic. The verification of\n\\(\\pred{Ins}{x,y,\\fun{ext}()}\\), the basis, happens to be rather\nlengthy, compared to earlier related proofs:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\quad}r@{}}\n  \\fun{insl}(x,\\fun{insr}(y,\\fun{ext}()))\n& \\xrightarrow{\\smash{\\iota}} &\n  \\fun{insl}(x,\\fun{bst}(y,\\fun{ext}(),\\fun{ext}())) & \\otimes\n\\end{array}\n\\end{equation*}\nThe symbol \\(\\otimes\\) is a tag from which different rewrites are\npossible, depending on some condition, and we will need to resume from\nthat mark. Here, two cases present themselves to us: either \\(x \\succ\ny\\) or \\(y \\succ x\\). We have\n\\begin{itemize}\n\n  \\item If \\(x \\succ y\\), then\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\quad}r@{}}\n\\otimes\n& \\xrightarrow{\\smash{\\upsilon}} & \n  \\fun{bst}(y,\\fun{ext}(),\\fun{insl}(x,\\fun{ext}()))\n& (x \\succ y)\\\\\n& \\xrightarrow{\\smash{\\phi}} &\n  \\fun{bst}(y,\\fun{ext}(),\\fun{bst}(x,\\fun{ext}(),\\fun{ext}()))\\\\\n& \\xleftarrow{\\smash{\\epsilon}} &\n\\fun{rotr}(\\fun{bst}(x,\\fun{bst}(y,\\fun{ext}(),\\fun{ext}()),\\fun{ext}()))\\\\\n& \\xleftarrow{\\smash{\\iota}} &\n  \\fun{rotr}(\\fun{bst}(x,\\fun{insr}(y,\\fun{ext}()),\\fun{ext}()))\\\\\n& \\xleftarrow{\\smash{\\eta}} &\n  \\fun{insr}(y,\\fun{bst}(x,\\fun{ext}(),\\fun{ext}()))\n& (x \\succ y)\\\\\n& \\xleftarrow{\\smash{\\phi}} &\n  \\fun{insr}(y,\\fun{insl}(x,\\fun{ext}())).\n\\end{array}\n\\end{equation*}\n\n  \\item If \\(y \\succ x\\), then\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\qquad}r@{}}\n\\otimes & \\xrightarrow{\\smash{\\tau}} &\n  \\fun{bst}(y,\\fun{insl}(x,\\fun{ext}()),\\fun{ext}())\n& (y \\succ x)\\\\\n& \\xrightarrow{\\smash{\\phi}} &\n  \\fun{bst}(y,\\fun{bst}(x,\\fun{ext}(),\\fun{ext}()),\\fun{ext}())\\\\\n& \\xleftarrow{\\smash{\\xi}} &\n\\fun{rotl}(\\fun{bst}(x,\\fun{ext}(),\\fun{bst}(y,\\fun{ext}(),\\fun{ext}())))\\\\\n& \\xleftarrow{\\smash{\\iota}} &\n  \\fun{rotl}(\\fun{bst}(x,\\fun{ext}(),\\fun{insr}(y,\\fun{ext}())))\\\\\n& \\xleftarrow{\\smash{\\theta}} &\n  \\fun{insr}(y,\\fun{bst}(x,\\fun{ext}(),\\fun{ext}()))\n& (y \\succ x)\\\\\n& \\xleftarrow{\\smash{\\phi}} &\n  \\fun{insr}(y,\\fun{insl}(x,\\fun{ext}())).\n\\end{array}\n\\end{equation*}\n\\end{itemize}\n\nNow, let us assume \\(\\pred{Ins}{x,y,t_1}\\) and \\(\\pred{Ins}{x,y,t_2}\\)\nand proceed to prove \\(\\pred{Ins}{x,y,t}\\), with\n\\(t=\\fun{bst}(a,t_1,t_2)\\), for all keys~\\(a\\). We start arbitrarily\nwith the right\\hyp{}hand side as follows:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\quad}r@{}}\n  \\fun{insr}(y,\\fun{insl}(x,t))\n& = & \\fun{insr}(y,\\fun{insl}(x,\\fun{bst}(a,t_1,t_2))) & \\otimes\n\\end{array}\n\\end{equation*}\nTwo cases arise: either \\(a \\succ x\\) or \\(x \\succ a\\).\n\\begin{itemize}\n\n\\item If \\(a \\succ x\\), then \\(\\otimes \\xrightarrow{\\smash{\\tau}}\n  \\fun{insr}(y,\\fun{bst}(a,\\fun{insl}(x,t_1),t_2)) \\; \\otimes\\). Two\n  subcases reveal themselves: either \\(a \\succ y\\) or \\(y \\succ a\\).\n  \\begin{itemize}\n\n    \\item If \\(a \\succ y\\), then \n      \\begin{equation*}\n      \\begin{array}{@{}r@{\\;}l@{\\;}l@{\\hspace{-8mm}}r@{}}\n        \\otimes & \\Rra{\\eta} &\n        \\fun{rotr}(\\fun{bst}(a,\\fun{insr}(y,\\fun{insl}(x,t_1)),t_2))\n        & (a \\succ y)\\\\\n        & \\equiv_2 & \\fun{rotr}(\\fun{bst}(a,\\fun{insl}(x,  \n        \\fun{insr}(y,t_1)),t_2)) & (\\pred{Ins}{x,y,t_1})\\\\\n        & \\Lla{\\tau} & \\fun{rotr}(\\fun{insl}(x,\n        \\fun{bst}(a,\\fun{insr}(y,t_1),t_2)))\\\\\n        & \\equiv & \\fun{rotr}(\\fun{insl}(x,\n        \\fun{rotl}(\\fun{rotr}(\\fun{bst}(a,\\fun{insr}(y,t_1),t_2)))))\\\\\n        & \\xleftarrow{\\smash{\\eta}} &\n        \\fun{rotr}(\\fun{insl}(x,\\fun{rotl}(\\fun{insr}(y, \n        \\fun{bst}(a,t_1,t_2)))))\\\\\n        & = & \\fun{rotr}(\\fun{insl}(x,\\fun{rotl}(\\fun{insr}(y,t))))\n        & (t=\\fun{bst}(a,t_1,t_2))\\\\\n        & \\equiv_3 & \\fun{rotr}(\\fun{rotl}(\\fun{insl}(x, \n        \\fun{insr}(y,t)))) & (\\text{Lemma})\\\\\n        & \\equiv & \\fun{insl}(x,\\fun{insr}(y,t)).\n        & (\\fun{rotr}(\\fun{rotl}(z)) \\equiv z)\n      \\end{array}\n      \\end{equation*}\n      What makes this case of the proof work is that \\(a \\succ x\\) and\n      \\(a \\succ y\\) allow us to move the calls to the rotations down\n      into the term so that they are composed on the subtree~\\(t_1\\),\n      enabling the application of the inductive hypothesis\n      \\(\\pred{Ins}{x,y,t_1}\\). Then we bring back up the commuted\n      calls, using the fact that composing a left and right rotation,\n      and vice\\hyp{}versa, is the identity. Note how, in the process,\n      we found a new lemma we need to prove later in the instance of\n      \\((\\equiv_3)\\). The interpretation of this subgoal is that left\n      rotation and leaf insertion commute, shedding more light on the\n      matter.\n\n    \\item If \\(y \\succ a\\), then\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\hspace{-8mm}}r@{}}\n  \\otimes & \\xrightarrow{\\smash{\\theta}} &\n  \\fun{rotl}(\\fun{bst}(a,\\fun{insl}(x,t_1),\\fun{insr}(y,t_2)))\n  & (y \\succ a)\\\\\n  & \\Lla{\\tau} &\n  \\fun{rotl}(\\fun{insl}(x,\\fun{bst}(a,t_1,\\fun{insr}(y,t_2))))\\\\\n  & \\equiv &\n  \\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(\\fun{rotl}(\\fun{bst}(a,t_1,    \n  \\fun{insr}(y,t_2))))))\\\\\n  & \\xleftarrow{\\smash{\\theta}} &\n  \\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(\\fun{insr}(y, \n  \\fun{bst}(a,t_1,t_2)))))\\\\\n  & = & \\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(\\fun{insr}(y,t))))\n  & (t=\\fun{bst}(a,t_1,t_2))\\\\\n  & \\equiv_4 & \\fun{rotl}(\\fun{rotr}(\\fun{insl}(x,\\fun{insr}(y,t))))\n  & (\\text{Lemma})\\\\\n  & \\equiv & \\fun{insl}(x,\\fun{insr}(y,t)).\n  & (\\fun{rotl}(\\fun{rotr}(z)) \\equiv z)\n\\end{array}\n\\end{equation*}\nHere, there was no need for the inductive hypothesis, because \\(a\n\\succ x\\) and \\(y \\succ a\\) imply \\(y \\succ x\\), hence the leaf and\nroot insertions are not composed and apply to two different subtrees,\n\\(t_1\\) and~\\(t_2\\). All we have to do then is to get them up in the\nsame order we got them down (as in a queue). We discovered another\nsubgoal that needs proving later, in the instance of \\((\\equiv_4)\\),\nand which is the dual of \\((\\equiv_3)\\) because it states that right\nrotation and leaf insertion commute. Together, they mean that\nrotations commute with leaf insertion.\n  \\end{itemize}\n\n\\item If \\(x \\succ a\\), then \\(\\otimes \\xrightarrow{\\smash{\\upsilon}}\n  \\fun{insr}(y, \\fun{bst}(a, t_1, \\fun{insl}(y,t_2))) \\;\n  \\otimes\\). Two subcases become apparent: either \\(a \\succ y\\) or \\(y\n  \\succ a\\).\n  \\begin{itemize}\n\n    \\item If \\(a \\succ y\\), then\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\hspace{-9mm}}r@{}}\n  \\otimes & \\Rra{\\eta} & \\fun{rotr}(\\fun{bst}(a,\n  \\fun{bst}(a,\\fun{insr}(y,t_1),\\fun{insl}(x,t_2))))\n  & (a \\succ y)\\\\\n  & \\Lla{\\upsilon} &\n  \\fun{rotr}(\\fun{insl}(x,\\fun{bst}(a,\\fun{insr}(y,t_1),t_2)))\\\\\n  & \\equiv & \\fun{rotr}(\\fun{insl}(x, \n  \\fun{rotl}(\\fun{rotr}(\\fun{bst}(a,\\fun{insr}(y,t_1),t_2)))))\\\\\n  & \\xleftarrow{\\smash{\\eta}} &\n  \\fun{rotr}(\\fun{insl}(x,\\fun{rotl}(\\fun{insr}(y, \n  \\fun{bst}(a,t_1,t_2)))))\\\\\n  & = & \\fun{rotr}(\\fun{insl}(x,\\fun{rotl}(\\fun{insr}(y,t))))\n  & (t=\\fun{bst}(a,t_1,t_2))\\\\\n  & \\equiv_3 &\n  \\fun{rotr}(\\fun{rotl}(\\fun{insl}(x,\\fun{insr}(y,t))))\\\\\n  & \\equiv & \\fun{insl}(x,\\fun{insr}(y,t)).\n  & (\\fun{rotr}(\\fun{rotl}(z)) \\equiv z)\n\\end{array}\n\\end{equation*}\nThis subcase is similar to the previous one in the sense that the\ninsertions apply to different subtrees, thus there is no need for the\ninductive hypothesis. The difference is that, here, \\((\\equiv_3)\\) is\nrequired in stead of \\((\\equiv_4)\\).\n\n  \\item If \\(y \\succ a\\), then\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{\\qquad}r@{}}\n  \\otimes & \\Rra{\\theta} & \n  \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{insr}(y,\\fun{insl}(x,t_2))))\\\\\n  & \\equiv_2 & \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{insl}(x,\n  \\fun{insr}(y,t_2)))) & (\\pred{Ins}{x,y,t_2})\\\\\n  & \\Lla{\\upsilon} &\n  \\fun{rotl}(\\fun{insl}(x,\\fun{bst}(a,t_1,\\fun{insr}(y,t_2))))\\\\\n  & \\equiv_3 & \\fun{insl}(x,\\fun{rotl}(\\fun{bst}(a,t_1,\n  \\fun{insr}(y,t_2))))\\\\\n  & \\xleftarrow{\\smash{\\theta}} & \\fun{insl}(x,\\fun{insr}(y,\n  \\fun{bst}(a,t_1,t_2)))\\\\\n  & = & \\fun{insl}(x,\\fun{insr}(y,t)). & (t=\\fun{bst}(a,t_1,t_2))\n\\end{array}\n\\end{equation*}\nThis is the last subcase. It is similar to the first one, because the\ninsertions are composed, albeit on~\\(t_2\\) instead of~\\(t_1\\),\ntherefore calling for the inductive hypothesis to be applied. Then,\ninsertions are brought up in the same order they were moved down,\n\\emph{e.g.,} \\fun{insl/2} was pushed down before \\fun{insr/2} and is\nlifted up before \\fun{insr/2}.\\hfill\\(\\Box\\)\n  \\end{itemize}\n\n\\end{itemize}\n\nWe now have to prove two remaining lemmas, dual of each other and\nmeaning together that rotations commute with leaf insertions. Let us\nconsider the first:\n\\begin{equation*}\n\\fun{insl}(x,\\fun{rotl}(t)) \\equiv_3 \\fun{rotl}(\\fun{insl}(x,t)).\n\\end{equation*}\nImplicitly, this proposition makes sense only if \\(t=\\fun{bst}(a, t_1,\n\\fun{bst}(b,t_2,t_3))\\) is a binary search tree, which implies \\(b\n\\succ a\\). The proof is technical in nature, which means that it\nrequires many cases and does not bring new insights, which the lack of\ninduction underlies. We start as follows:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n  \\fun{insl}(x,\\fun{rotl}(t))\n& = & \\fun{insl}(x,\\fun{rotl}(\\fun{bst}(a, t_1,\n\\fun{bst}(b,t_2,t_3))))\\\\\n& \\xrightarrow{\\smash{\\zeta}} &\n\\fun{insl}(x,\\fun{bst}(b,\\fun{bst}(a,t_1,t_2),t_3)) \\quad \\otimes\n\\end{array}\n\\end{equation*}\nTwo cases arise: either \\(b \\succ x\\) or \\(x \\succ b\\).\n\\begin{itemize}\n\n  \\item If \\(b \\succ x\\), then \\(\\otimes \\xrightarrow{\\smash{\\tau}}\n  \\fun{bst}(b,\\fun{insl}(x,\\fun{bst}(a,t_1,t_2)),t_3) \\; \\otimes\\).\n  Two subcases surface: either \\(a \\succ x\\) or \\(x \\succ a\\).\n \n  \\(\\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n      \\text{\\;-- If \\(a \\succ x\\), then \\(\\otimes\\)} &       \n      \\xrightarrow{\\smash{\\tau}} &\n      \\fun{bst}(b,\\fun{bst}(a,\\fun{insl}(x,t_1),t_2),t_3)\\\\\n      & \\Lla{\\zeta} &\n      \\fun{rotl}(\\fun{bst}(a,\\fun{insl}(x,t_1),\n      \\fun{bst}(b,t_2,t_3)))\\\\\n      & \\xleftarrow{\\smash{\\tau}} &\n      \\fun{rotl}(\\fun{insl}(x,\\fun{bst}(a,t_1,\n      \\fun{bst}(b,t_2,t_3))))\\\\\n      & = & \\fun{rotl}(\\fun{insl}(x,t)).\n    \\end{array}\\)\n\n    \\(\\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n      \\text{\\;-- If \\(x \\succ a\\), then \\(\\otimes\\)} &\n      \\xrightarrow{\\smash{\\upsilon}} &\n      \\fun{bst}(b,\\fun{bst}(a,t_1,\\fun{insl}(x,t_2)),t_3)\\\\\n      & \\Lla{\\zeta} & \n      \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{bst}(b,\\fun{insl}(x,t_2),t_3)))\\\\\n      & \\xleftarrow{\\smash{\\tau}} &\n      \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{insl}(x,\\fun{bst}(b,t_2,t_3))))\\\\\n      & \\xleftarrow{\\smash{\\upsilon}} &\n      \\fun{rotl}(\\fun{insl}(x,\\fun{bst}(a,t_1,\\fun{bst}(b,t_2,t_3))))\\\\\n      & = & \\fun{rotl}(\\fun{insl}(x,t)).\n      \\end{array}\\)\n\n  \\item If \\(x \\succ b\\), then the assumption \\(b \\succ a\\) implies\n    \\(x \\succ a\\). We have\n  \\begin{equation*}\n  \\begin{array}{@{}r@{\\;}l@{\\;}l@{\\qquad}r@{}}\n    \\otimes & \\xrightarrow{\\smash{\\upsilon}} &\n    \\fun{bst}(b,\\fun{bst}(a,t_1,t_2),\\fun{insl}(x,t_3))\\\\\n    & \\Lla{\\zeta} &\n    \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{bst}(b,t_2,\\fun{insl}(x,t_3))))\\\\\n    & \\xleftarrow{\\smash{\\upsilon}} &\n    \\fun{rotl}(\\fun{bst}(a,t_1,\\fun{insl}(x,\\fun{bst}(b,t_2,t_3))))\n    & (x \\succ b)\\\\\n    & \\xleftarrow{\\smash{\\upsilon}} &\n    \\fun{rotl}(\\fun{insl}(x,\\fun{bst}(a,t_1,\\fun{bst}(b,t_2,t_3))))\n    & (x \\succ a)\\\\\n    & = & \\fun{rotl}(\\fun{insl}(x,t)). & \\hfill\\Box\n  \\end{array}\n  \\end{equation*}\n\n\\end{itemize}\n\nThe last remaining lemma is \\(\\fun{insl}(x,\\fun{rotr}(t)) \\equiv_4\n\\fun{rotr}(\\fun{insl}(x,t))\\). In fact, it is a simple algebraic\nmatter to show that it is equivalent to \\(\\fun{insl}(x,\\fun{rotl}(t))\n\\equiv_3 \\fun{rotl}(\\fun{insl}(x,t))\\). Indeed, we have the following\nequivalent equations:\n\\begin{equation*}\n\\begin{array}{@{}r@{\\;}l@{\\;}l@{}}\n\\fun{insl}(x,\\fun{rotl}(t)) & \\equiv_3 & \\fun{rotl}(\\fun{insl}(x,t))\\\\\n\\fun{insl}(x,\\fun{rotl}(\\fun{rotr}(t))) & \\equiv &\n\\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(t)))\\\\\n\\fun{insl}(x,t) & \\equiv & \\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(t)))\\\\\n\\fun{rotr}(\\fun{insl}(x,t)) & \\equiv &\n\\fun{rotr}(\\fun{rotl}(\\fun{insl}(x,\\fun{rotr}(t))))\\\\\n\\fun{rotr}(\\fun{insl}(x,t)) & \\equiv_4 &\n\\fun{insl}(x,\\fun{rotr}(t)).\\hfill\\Box\n\\end{array}\n\\end{equation*}\n\n\n\\mypar{Average cost}\n\nThe average number of comparisons of root insertion is the same as\nwith leaf insertion, because rotations do not involve any comparison:\n\\begin{equation*}\n\\OM{\\fun{insr}}{n} = \\OM{\\fun{insr}_0}{n} = \\OM{\\fun{insl}}{n}\n= 2H_n + \\frac{2}{n+1} - 3 \\sim 2\\ln n.\n\\index{insr@$\\OM{\\fun{insr}}{n}$}\n\\index{insr0@$\\OM{\\fun{insr}_0}{n}$}\n\\end{equation*}\nRotations double the cost of a step down in the tree, though, and we\nhave, recalling equations~\\eqref{eq:Mmem_cmp1}\nand~\\eqref{eq:Mmem_cmp2} \\vpageref{eq:Mmem_cmp2},\n\\begin{equation*}\n\\M{\\fun{insr}}{n} = 1 + \\frac{2}{n+1}\\Expected{E_n} = 1 +\n\\OM{\\fun{mem}}{n{\\scriptscriptstyle(-)}} = 4H_n + \\frac{4}{n+1} - 3\n\\sim 4\\ln n.\n\\index{insr@$\\M{\\fun{insr}}{n}$}\n\\end{equation*}\nAs a consequence of theorem~\\eqref{thm:RootLeaf}\n\\vpageref{thm:RootLeaf}, all permutations of a given size yield the\nsame set of binary search trees under \\fun{mkl/1} and\n\\fun{mkr/1}. Therefore, inserting another key will incur the same\naverage number of comparisons by \\fun{insl/1} and \\fun{insr/1} since\n\\(\\OM{\\fun{insr}}{n} = \\OM{\\fun{insr}_0}{n} = \\OM{\\fun{insl}}{n}\\). By\ninduction on the size, we conclude that the average number of\ncomparisons for \\fun{mkl/1} and \\fun{mkr/1} is the same:\n\\begin{equation*}\n\\OM{\\fun{mkr}}{n} = \\OM{\\fun{mkl}}{n} = \\Expected{I_n}\n= 2(n+1)H_n - 4n.\n\\index{mkr@$\\OM{\\fun{mkr}}{n}$}\n\\end{equation*}\nConsidering that the only difference between \\fun{insl/1} and\n\\fun{insr/1} is the additional cost of one rotation per edge down, we\nquickly realise, by recalling equations~\\eqref{eq:Mmkl}\nand~\\eqref{eq:IEn}, that\n\\begin{equation*}\n\\M{\\fun{mkr}}{n} = \\M{\\fun{mkl}}{n} + \\Expected{I_n}\n= n + 2 \\cdot \\Expected{I_n} + 2 = 4(n+1)H_n - 7n + 2.\n\\index{mkr@$\\M{\\fun{mkr}}{n}$}\n\\end{equation*}\n\n\\mypar{Amortised cost}\n\\index{cost!amortised $\\sim$|(}\n\nSince the first phase of root insertion is a leaf insertion, the\nprevious analyses of the extremal costs of \\fun{insl/2} and\n\\fun{insl\\(_1\\)/2} apply as well to \\fun{insr/2}. Let us consider now\nthe amortised costs of \\fun{insr/2}, namely, the extremal costs of\n\\fun{mkr/1}.\n\nLet \\(\\OB{\\fun{mkr}}{n}\\)\\index{mkr@$\\OB{\\fun{mkr}}{n}$} the minimum\nnumber of comparisons to build a binary search tree of size~\\(n\\)\nusing root insertions. We saw that the best case with leaf insertion\n(\\fun{insl/2}) happens when the key is inserted as a child of the\nroot. While this cannot lead to the best amortised cost (\\fun{mkl/1}),\nit yields the best amortised cost when using root insertions\n(\\fun{mkr/1}) because the newly inserted key becomes the root with\nexactly one rotation (a left rotation if it was the right child, and a\nright rotation if it was the left child of the root), leaving the spot\nempty again for another efficient insertion (\\fun{insr/2}). In the\nend, the search tree is degenerate, in fact, there are exactly two\nminimum\\hyp{}cost trees, whose shapes are those of\n\\fig~\\vref{fig:tree_stack}. Interestingly, these trees correspond to\nmaximum\\hyp{}cost trees built using leaf insertions. The first key is\nnot compared, so we have \\(\\OB{\\fun{mkr}}{n} = n - 1 \\sim\n\\OB{\\fun{mkl}}{n}/\\lg n\\).\n\nPerhaps surprisingly, it turns out that finding the maximum number of\ncomparisons \\(\\OW{\\fun{mkr}}{n}\\)\\index{mkr@$\\OW{\\fun{mkr}}{n}$} \nto make a search tree of size~\\(n\\) with \\fun{mkr/1}, that is to say,  \nthe maximum amortised number of comparisons of \\fun{insr/2}, happens\nto be substantially more challenging than making out its average or\nminimum cost. \\cite{GeldenhuysVanderMerwe_2009} show that\n\\begin{equation*}\n\\OW{\\fun{mkr}}{n} = \\tfrac{1}{4}n^2 + n - 2 - c,\n\\end{equation*}\nwhere \\(c = 0\\) for \\(n\\)~even, and \\(c=\\myfrac{1}/{4}\\) for\n\\(n\\)~odd. This implies\n\\begin{equation*}\n\\OW{\\fun{mkr}}{n} = \\tfrac{1}{2}\\OW{\\fun{mkl}}{n} + \\tfrac{5}{4}n - 2 -\nc \\sim \\tfrac{1}{2}\\OW{\\fun{mkl}}{n}.\n\\end{equation*}\n\\index{cost!amortised $\\sim$|)}\n\n\n\\paragraph{Exercises}\n\n\\begin{enumerate}\n\n  \\item Prove \\(\\fun{bst}_0(t) \\equiv \\fun{bst}(t)\\). See definitions of\n  \\fun{bst\\(_0\\)/1}\\index{bst0@\\fun{bst\\(_0\\)/1}} and\n  \\fun{bst/1}\\index{bst@\\fun{bst/1}}, respectively, in\n  \\fig~\\vref{fig:bst0} and \\fig~\\vref{fig:bst}.\n\n  \\item Prove \\(\\fun{mem}(y,t) \\equiv \\fun{mem}_3(y,t)\\), that is to\n  say, the correctness of Andersson's search. See definitions of\n  \\fun{mem/2}\\index{mem@\\fun{mem/2}} and\n  \\fun{mem\\(_3\\)/2}\\index{mem3@\\fun{mem\\(_3\\)/2}}, respectively, in\n  \\fig~\\vref{fig:mem} and \\fig~\\vref{fig:mem3}.\n\n  \\item Prove \\(\\fun{insr}(x,t) \\equiv \\fun{bst}(x,t_1,t_2)\\).\n  \\index{insr@\\fun{insr/2}} In\n    other words, root insertion is really doing what it says it does.\n\n  \\item Prove \\(\\fun{mklR}(s) \\equiv \\fun{mkl}(\\fun{rev}(s))\\).\n    \\index{mklR@\\fun{mklR/1}} \\index{mkl@\\fun{mkl/1}}\n    \\index{rev@\\fun{rev/1}}\n\n  \\item Prove \\(\\fun{bst}(t) \\equiv \\fun{true}() \\Rightarrow\n    \\fun{mkl}(\\fun{pre}(t)) \\equiv t\\). See definition of \\fun{pre/1}\n    \\index{pre@\\fun{pre/1}} in \\fig~\\vref{fig:pre}. Is the converse\n    true as well?\n\n\\end{enumerate}\n\\index{binary search tree!root insertion|)}\n\n\\section{Deletion}\n\\index{binary search tree!deletion|(}\n\nThe removal of a key in a binary search tree is a bit tricky, in\ncontrast with leaf insertion. Of course, `removal' is a convenient\nfigure of speech in the context of functional programming, where data\nstructures are persistent, hence removal means that we have to rebuild\na new search tree without the key in question. As with insertion, we\ncould simply start with a search for the key: if absent, there is\nnothing else to be done, otherwise we replace the key with its\nimmediate successor or predecessor in inorder, that is, the minimum of\nthe right subtree or the maximum of the left subtree. \n\nThe definitions for these two phases are found in \\fig~\\vref{fig:del}.\n\\begin{figure}\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n  \\fun{del}(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,\\fun{del}(y,t_1),t_2),\\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{del}(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,t_1,\\fun{del}(y,t_2)),\\; \\text{if \\(y \\succ x\\)};\\\\\n\\fun{del}(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \n   \\fun{aux}_0(x,t_1,\\fun{min}(t_2));\\\\\n\\fun{del}(y,\\fun{ext}()) & \\rightarrow & \\fun{ext}().\\\\\n\\\\\n\\fun{min}(\\fun{bst}(x,\\fun{ext}(),t_2)) & \\rightarrow & \\pair{x}{t_2};\\\\\n\\fun{min}(\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \n  \\fun{aux}_1(x,\\fun{min}(t_1),t_2).\\\\\n\\\\\n\\fun{aux}_1(x,\\pair{m}{t'_1},t_2) & \\rightarrow & \n  \\pair{m}{\\fun{bst}(x,t'_1,t_2)}.\\\\\n\\\\\n\\fun{aux}_0(x,t_1,\\pair{m}{t'_2}) & \\rightarrow & \\fun{bst}(m,t_1,t'_2).\n\\end{array}}\n\\end{equation*}\n\\caption{Deletion of a key in a binary search tree\\label{fig:del}}\n\\end{figure}\nWe have \\(\\fun{min}(t_2) \\twoheadrightarrow\n\\pair{m}{t'_2}\\),\\index{min@\\fun{min/1}} where \\(m\\)~is the minimum\nkey of the tree~\\(t_2\\) and \\(t'_2\\)~is the reconstruction of~\\(t_2\\)\nwithout~\\(m\\); in other words, the leftmost internal node of~\\(t_2\\)\ncontains the key~\\(m\\) and that node has been replaced by an external\nnode. The call to \\fun{aux\\(_0\\)/3} simply substitutes the key~\\(x\\)\nto be deleted by its immediate successor~\\(m\\). The purpose of the\nauxiliary function \\fun{aux\\(_1\\)/3} is to rebuild the tree in which\nthe minimum has been removed. Note that the pattern of the third rule\nis not \\(\\fun{del}(y, \\fun{bst}(y,t_1,t_2))\\),\\index{del@\\fun{del/2}}\nbecause we already know that \\(x=y\\) and we want to avoid a useless\nequality test.\n\nOf course, we could also have taken the maximum of the left subtree\nand this arbitrary asymmetry actually leads deletions followed by at\nleast two insertions to trees which are less balanced, in average,\nthan if they had been constructed directly only with insertions. This\nphenomenon is difficult to understand and examples are needed to see\nit at work\n\\citep{Eppinger_1983,CulbersonMunro_1989,CulbersonEvans_1994,Knuth_1998a,Heyer_2009}.\n\nAnother kind of asymmetry is that deletion is much more complicated to\nprogram than insertion. This fact has lead some researchers to propose\na common framework for insertion and deletion\n\\citep{Andersson_1991,Hinze_2002}. In particular, when Andersson's\nsearch with a tree candidate is modified into deletion, the program is\nquite short if the programming language is imperative.\n\nAnother approach to deletion consists in marking the targeted nodes as\ndeleted without actually removing them. They are still needed for\nfuture comparisons but they are not to be considered part of the\ncollection of keys implemented by the search tree. As such they are\nalike zombies, neither alive nor dead, or we could talk of lazy\ndeletion. More seriously, this requires two kinds of internal nodes,\n\\fun{bst/3} and \\fun{del/3}.\\index{del@\\fun{del/3}} This alternative\ndesign is shown in \\fig~\\vref{fig:del0}.\n\\begin{figure}[b]\n\\begin{equation*}\n\\boxed{\n\\begin{array}{r@{\\;}l@{\\;}l}\n  \\fun{del}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,\\fun{del}_0(y,t_1),t_2),\\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{del}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{bst}(x,t_1,\\fun{del}_0(y,t_2)),\\; \\text{if \\(y \\succ x\\)};\\\\\n\\fun{del}_0(y,\\fun{bst}(x,t_1,t_2)) & \\rightarrow & \n  \\fun{del}(x,t_1,t_2);\\\\\n\\fun{del}_0(y,\\fun{del}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{del}(x,\\fun{del}_0(y,t_1),t_2),\\; \\text{if \\(x \\succ y\\)};\\\\\n\\fun{del}_0(y,\\fun{del}(x,t_1,t_2)) & \\rightarrow &\n  \\fun{del}(x,t_1,\\fun{del}_0(y,t_2)),\\; \\text{if \\(y \\succ x\\)};\\\\\n\\fun{del}_0(y,t) & \\rightarrow & t.\\\\\n\\end{array}}\n\\end{equation*}\n\\caption{Lazy deletion of a key in a binary search tree\\label{fig:del0}}\n\\end{figure}\nNote that the insertion of a key which happens to have been lazily\ndeleted does not need to be performed at an external node: the\nconstructor \\fun{del/3} would simply be changed into \\fun{bst/3}, the\nmark of normal internal nodes.\n\n\\paragraph{Exercise}\n\nDefine the usual insertions on this new kind of search tree.\n\n\\index{binary search tree!deletion|)}\n\n%\\section{Merging}\n%% Brown & Tarjan Merging\n\n\\section{Average parameters}\n\nThe average height~\\(h_n\\) of a binary search tree of size~\\(n\\) has\nbeen intensively studied \\citep{Devroye_1986, Devroye_1987,\n  Mahmoud_1992, KnesslSpankowski_2002}, but the methods, mostly of\nanalytic nature, are beyond the scope of this book. \\cite{Reed_2003}\nproved that\n\\begin{equation*}\nh_n = \\alpha \\ln n - \\frac{3\\alpha}{2\\alpha - 2} \\ln\\ln n + \\mathcal{O}(1),\n\\end{equation*}\nwhere \\(\\alpha\\)~is the unique solution on \\([2,+\\infty[\\) to the\nequation \\(\\alpha\\ln(2e/\\alpha) = 1\\), an approximation being \\(\\alpha\n\\simeq 4.31107\\), and \\(\\mathcal{O}(1)\\) is an unknown function whose\nabsolute value is bounded from above by an unknown\nconstant. Particularly noteworthy is a rough logarithmic upper bound\nby \\cite{Aslam_2001}, expressed in a probabilistic model and\nrepublished by \\cite{CLRS_2009} in section~12.4.\n\n\\cite{ChauvinDrmotaJabbour-Hattab_2001} studied the average width of\nbinary search trees.\n\n", "meta": {"hexsha": "064d4eeb2f11b90a079636ea136a38671349d663", "size": 81804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "bst.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": "bst.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": "bst.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.5798365123, "max_line_length": 100, "alphanum_fraction": 0.665676495, "num_tokens": 30510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711642563823, "lm_q2_score": 0.8976953023710936, "lm_q1q2_score": 0.7630151213038436}}
{"text": "\\chapter{Analytical Trigonometry}\n\\section{Fundamental Identities}\n\\subsection{Reciprocal Identities}\n\\begin{itemize}\n  \\item{$sin(\\theta)=\\frac{1}{csc(\\theta)}$}\n  \\item{$cos(\\theta)=\\frac{1}{sec(\\theta)}$}\n  \\item{$tan(\\theta)=\\frac{1}{cot(\\theta)}$}\n  \\item{$csc(\\theta)=\\frac{1}{sin(\\theta)}$}\n  \\item{$sec(\\theta)=\\frac{1}{cos(\\theta)}$}\n  \\item{$cot(\\theta)=\\frac{1}{tan(\\theta)}$}\n\\end{itemize}\n\n\\subsection{Quotient Identities}\n\\begin{itemize}\n  \\item{$tan(\\theta)=\\frac{sin(\\theta)}{cos(\\theta)}$}\n  \\item{$cot(\\theta)=\\frac{cos(\\theta)}{sin(\\theta)}$}\n\\end{itemize}\n\n\\subsection{Pythagorean Identities}\n\\begin{itemize}\n  \\item{$sin^2(u)+cos^(u)=1$}\n  \\item{$1+tan^2(u)=sec^2(u)$}\n  \\item{$1+cot^2(u)=csc^2(u)$}\n\\end{itemize}\n\n\\subsection{Cofunction Identities}\n\\begin{itemize}\n  \\item{$sin(\\frac{\\pi}{2}-u)=cos(u)$}\n  \\item{$cos(\\frac{\\pi}{2}-u)=sin(u)$}\n  \\item{$tan(\\frac{\\pi}{2}-u)=cot(u)$}\n  \\item{$cot(\\frac{\\pi}{2}-u)=tan(u)$}\n  \\item{$sec(\\frac{\\pi}{2}-u)=csc(u)$}\n  \\item{$csc(\\frac{\\pi}{2}-u)=sec(u)$}\n\\end{itemize}\n\n\\section{Sum and Difference Formulae}\n\\begin{itemize}\n  \\item{$\\sin(u \\pm v)=\\sin(u)\\cos(v) \\pm \\cos(u)\\sin(v)$}\n  \\item{$\\cos(u \\pm v)=\\cos(u)\\cos(v) \\mp \\sin(u)\\sin(v)$}\n  \\item{$\\tan(u \\pm v)=\\frac{\\tan(u) \\pm \\tan(v)}{1 \\mp \\tan(u)\\tan(v)}$}\n\\end{itemize}\n\n\\section{Double Angle Formulae}\n\\begin{itemize}\n  \\item{$\\sin2u=2\\sin u\\cos u$}\n  \\item{$\\cos2u=$ ...}\n    \\begin{enumerate}\n      \\item{$\\cos^2u-\\sin^2u$}\n      \\item{$2\\cos^2u-1$}\n      \\item{$1-2\\sin^2u$}\n    \\end{enumerate}\n  \\item{$\\tan2u=\\frac{2\\tan u}{1-\\tan^2y}$}\n\\end{itemize}\n\n\\section{Power Reducing Formulae}\n\\begin{itemize}\n  \\item{$\\sin^2u=\\frac{1-\\cos 2u}{2}$}\n  \\item{$\\cos^2u=\\frac{1+\\cos 2u}{2}$}\n  \\item{$\\tan^2u=\\frac{1-\\cos 2u}{1+\\cos 2u}$}\n\\end{itemize}\n\n\\section{Half Angle Formulae}\n\\begin{itemize}\n  \\item{$\\sin(\\frac{u}{2})=\\pm\\sqrt{\\frac{1-\\cos u}{2}}$}\n  \\item{$\\cos(\\frac{u}{2})=\\pm\\sqrt{\\frac{1+\\cos u}{2}}$}\n  \\item{$\\tan(\\frac{u}{2})=\\frac{1-\\cos u}{\\sin u}=\\frac{\\sin u}{1+\\cos u}$}\n\\end{itemize}\n\n\\section{Notes on these Formulae}\nTo use these formulas, it is important to know them well.  Look for patterns and\nbe able to expand them into simpler ones.  Once you have broken them down far\nenough, it will be easy to solve for them, since you can evaluate expressions\ninside of the functions easily.\n\n\\section{Law of Sines and Cosines}\nConsider any triangle with sides $a$, $b$, and $c$, and angles opposite to their\nrespective sides, $A$, $B$, and $C$.  Given this triangle, we can make two\ngeneralizations about it, both of which are supersets of the Pythagorean\nFormula:\n\n\\subsection{The Law of Sines}\n\\begin{equation}\n  \\frac{\\sin A}{a}=\\frac{\\sin B}{b}=\\frac{\\sin C}{c}\n\\end{equation}\n\n\\subsection{The Law of Cosines}\n\\begin{itemize}\n  \\item{$c^2=a^2+b^2-2ab\\cos C$}\n  \\item{$a^2=b^2+c^2-2bc\\cos A$}\n  \\item{$b^2=a^2+c^2-2ac\\cos B$}\n\\end{itemize}\n", "meta": {"hexsha": "6bdeeb5442c832ce35e3752ab5c1cad4f88beb66", "size": 2883, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pre_calculus_h/chapters/5_analytical_trig.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/5_analytical_trig.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/5_analytical_trig.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": 31.3369565217, "max_line_length": 80, "alphanum_fraction": 0.6298994103, "num_tokens": 1146, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7629973233897039}}
{"text": "%qna\n\\section{Topological basisc}\nWe are going to repeat some basic concepts from topology for the sake for coherence. A topological space is the pair of an object in the category of sets $X \\in \\mrm{Set}$ and a family of subsets $\\tau \\subset \\mathcal{P}(X)$, called topology, fulfilling\n\\bn\n\\item $\\emptyset, X \\in \\tau$,\n\\item at least one of\n\\bd\n\\item[Open] arbitrary unions and any finite intersection are elements in $\\tau$:\n$$U_i \\in \\tau \\forall i \\in I \\Rightarrow \\bigcup_{i \\in I} U_i \\in \\tau,\\ F_i \\in \\tau\\ \\forall i \\in I' \\subset I \\wedge |I'| < \\infty \\Rightarrow \\bigcap_{i \\in I'} U_i \\in \\tau\\ $$\nfor any given indexing set $I$.\n\\item[Closed] arbitrary intersections and any finite union are elements in $\\tau$:\n$$F_i \\in \\tau \\forall i \\in I \\Rightarrow \\bigcap_{i \\in I} F_i \\in \\tau,\\ \\bigcup_{i \\in I'} F_i \\in \\tau\\ \\forall I' \\subset I \\wedge |I'| < \\infty$$\nfor any given indexing set $I$.\n\\ed\n\\en\nA topology $\\tau$ whose elements are open and closed at the same time is called clopen.\n\\exmpl For any object $X \\in \\mrm{Set}$ we get\n\\bd\n\\item[Lump topology] $(X,\\{\\emptyset,X\\})$ is a topological space, with $\\tau$ called the lump topology.\n\\item[Discrete topology] $(X,\\mathcal{P}(X))$ with the power set $\\mathcal{P}(X) = \\{A \\subset X\\}$.\n\\item[Standard topology] on the real number line:\n$$U = \\bigcap_{i \\in I} \\bigcup_{j \\in J} U_{ij} \\in \\mathcal{O}(\\tau_{\\mrm{std}}),\\ U_{ij} := (a_{ij},b_{ij})\\ \\forall (i,j) \\in I \\times J$$\n$$F = \\bigcap_{i \\in I} \\bigcup_{j \\in J} F_{ij} \\in \\mathcal{F}(\\tau_{\\mrm{std}}),\\ F_{ij} := [a_{ij},b_{ij}]\\ \\forall (i,j) \\in I \\times J$$\n\\ed\nNote that both topologies are examples of clopen topologies - each element is closed and open. If $X = \\emptyset$ then both topologies collide.\nWe denote\n$$\\mathcal{O}(\\tau) := \\{U \\in \\tau: U\\ \\mrm{open}\\}$$\nas the open (sub) topology on $\\tau$ and\n$$\\mathcal{F}(\\tau) := \\{F \\in \\tau: F\\ \\mrm{closed}\\}$$\n\\begin{defi}\nLet $(X, \\tau_X)$ and $(Y,\\tau_Y)$ be two topological spaces. We call a map $f : X \\longrightarrow Y$ a continous map if either\n\\bn\n\\item if $V \\in \\mathcal{O}(\\tau_Y) \\Rightarrow f^{-1}(V) \\in \\mathcal{O}(\\tau_X)$,\n\\item if $G \\in \\mathcal{F}(\\tau_Y) \\Rightarrow f^{-1}(G) \\in \\mathcal{F}(\\tau_X)$,\n\\en\nholds.\nWe call $f$ open if the images of open sets in $\\tau_X$ are open in $\\tau_Y$:\n$$U \\in \\mathcal{O}(\\tau_X) \\Rightarrow f(U) \\in \\mathcal{O}(\\tau_Y).$$\n\\end{defi}\n\\begin{prop}\nThe class of all topological spaces forms a category with continuous maps as morphisms and open, continous bijections (= homeomorphis) as automorphisms.\n\\end{prop}\n\\subsection{Filters and basis}\n\\begin{defi}\nLet $(X,\\tau)$ be a topological space. We call a family $\\mathcal{F} \\subset \\tau$ of elements $F \\in \\mathcal{F}$ a filter if\n\\bn\n\\item $F \\neq \\emptyset \\forall F \\in \\mathcal{F}$,\n\\item $F \\subset F' \\vee F' \\subset F, \\forall F, F' \\in \\mathcal{F}$.\n\\en\nWe call a family of elements $U \\in \\tau$ a basis if \n\\end{defi}\n\\section{Topological groups}\nIn parlance with category theory, a topological group is the group object of the category of topological spaces.\n\n\\subsection{Noetherian groups}\nRepeating the definition for noetherian spaces:\n\\begin{defi}\nA topological space $(X,\\tau_X)$ is called noetherian if\n\\bn\n\\item each strictly ascending chain of open subspaces $\\emptyset \\subset \\ldots \\subset U \\subset U' \\subset \\ldots \\subset X$ is stationary after finitely many steps, or\n\\item each strictly descending chain of closed subspaces $X \\supset \\ldots \\supset F \\supset F' \\supset \\ldots \\supset \\emptyset$ is stationary after finitely many steps.\n\\en\n\\end{defi}\nWe get immediately\n\\begin{coro}\nThe following statements are equivalent:\n\\bn\n\\item a topological group $(G, m, e, S, \\tau_G)$ is noetherian,\n\\item each strictly ascending chain of open subgroups is finite (stationary after finitely many steps),\n\\item each strictly descending chain of closed subgroups is finite (stationary after finitely many steps),\n\\item each set of generators of $G$ has a finite subset.\n\\en\n\\end{coro}\nNote, that noetherianicity is indeed a topological property - it only relies upon open/closed-ness and the subgroup property.\n\n\\subsection{Modules and topological spaces}\nLet $R$ be a ring and $M$ an $R$ module. Following our convention from category theory, the class of submodules $N$ contained in $M$ is denoted by\n$$\\mrm{Mod}_R(M).$$\nLet $F$ be an arbitrary family of submodules $N$, we get\n$$\\bigcup_{\\substack{N \\in F'\\\\F' \\subset F\\\\|F'| < \\infty}} N \\subseteq \\sum_{\\substack{N \\in F'\\\\F' \\subset F\\\\|F'| < \\infty}} N,\\ \\bigcap_{\\substack{N \\in F'\\\\F' \\subset F\\\\}} N \\in \\mrm{Mod}_R(M).$$\nThe first part says that any finite union of submodules is a subset of the finite sum of the same modules. However, the union is in general not a module. The arbitrary intersection of submodules is, nevertheless, a submodule of $M$ and therefore, we get:\n$$\\mathcal{F}(M) := \\left\\{F \\in \\mathcal{P}(M) : F := \\bigcup_{\\substack{\\mathcal{N} \\subset \\mathcal{N'}\\\\|\\{\\mathcal{N}\\}| < \\infty\\\\}} \\bigcap_{N \\in \\mathcal{N}} N,\\ \\mathcal{N'} \\subset \\mrm{Mod}_R(M)\\right\\}$$\na closed topology by adding the empty set.\n\\subsubsection{Filters and neighbourhoods}\nGiven a topological space $(X, \\tau)$ and a non-empty subset $Y \\in \\tau$, we call a class of subspaces $F(Y) := \\{X_I : X_I \\in \\tau,\\ \\forall I \\in \\mathcal{I}\\}$\n\\begin{defi}{Filter} of $Y$ if all of the following conditions hold:\n\\bn\n\\item $$X' \\in \\mathcal{F}(Y) \\Rightarrow X' \\neq \\emptyset,$$\n\\item $$\\forall X', X'' \\in \\mathcal{F}(Y)\\ \\Rightarrow X' \\subset X'' \\vee X'' \\subset X'.$$\n\\en\n$$$$\n\\end{defi}\nNote that only the empty set as a topological space has no filters. Having at least one element provides us with at least one filter\n$$\\exists x_0 \\in X:\\ X\\backslash \\{x_0\\} = \\emptyset \\Rightarrow \\mathcal{F}(x_0) = \\{X\\}.$$\nAlso note that each ascending chain of open subsets forms an open filter and equivalently, a descending chain of closed subsets forms a closed filfter.\n\\paragraph{Example} Let $(\\rz, \\tau_{\\mrm{std}})$ where $\\tau_{\\mrm{std}}$ is the standard topology induced by the metric $d = \\left[(x,y) \\longmapsto |x - y|\\right]$.\n\\section{Group objects}\nGiven a category $\\catc$ with terminal object $\\ast$ we call an object $G \\in \\catc$ a group object of $\\catc$ if $\\grpobj$ is a functor of type\n$$\\catc \\longrightarrow \\mathrm{Grp}.$$\nTo specify, we say $G$ is a group object if and only if\\\\\n\\begin{enumerate}\n\\item $m : \\grpobj \\times \\grpobj \\longrightarrow \\grpobj$\n\\end{enumerate}", "meta": {"hexsha": "4a05817392dfa43d46a7f1feb7d926ff75674539", "size": 6500, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "grp_scheme/qna.tex", "max_stars_repo_name": "gmuel/texlib", "max_stars_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "grp_scheme/qna.tex", "max_issues_repo_name": "gmuel/texlib", "max_issues_repo_head_hexsha": "1a3fab54f2e03d9ce656f9b8a5b58e26c3c93a02", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "grp_scheme/qna.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": 63.1067961165, "max_line_length": 254, "alphanum_fraction": 0.6946153846, "num_tokens": 2165, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564152, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7629973233897037}}
{"text": "\\subsection{Matrix Multiplication}\nMatrix multiplication is a critical operation in many machine learning algorithms, particularly in the domain of deep learning. Training parameters (weights) of a deep neural network in a vectorized fashion essentially involves multiplication of matrices with various sizes. \n\nFully-Connected (FC) layers (Fig.~\\ref{fig:fc}) and convolutional (Conv) layers (Fig.~\\ref{fig:cnn}) are building blocks of feed-forward and convolutional neural networks~\\cite{Warden15}. It is straightforward to identify matrix multiplication in computing output value of a FC layer: each input has $k$ elements, and FC layer has $n$ neurons each with $k$ weights. An FC layer is the multiplication of a $m \\times k$ matrix ($m$ is sample size) and a $k\\times n$ matrix. A Conv layer appears to be a specialized operation, but it can be computed with matrix multiplication after rearranging data in a matrix format: each depth-wise (channel) slice of input can be added into an input matrix as a row; similarly each kernel can be added into a kernel matrix as a column. Convolution operation becomes multiplication of those two matrices. When using AlexNet on image classification with ImageNet dataset, vast majority of computation time on forward pass (94.7\\% on GPU, and 88.7\\% on CPU) is consumed by Conv and FC layers~\\cite{Jia14}.\n\n\\begin{figure}[t]\n    \\centering\n    \\begin{subfigure}[b]{0.2\\textwidth}\n    \\includegraphics[width=\\linewidth]{3_GEMM_backgrounds/fc.png}\n    \\caption{Fully-Connected Layer}\n    \\label{fig:fc}\n    \\end{subfigure}\n    \\hspace{0.2in}\n    \\begin{subfigure}[b]{0.2\\textwidth}\n    \\includegraphics[width=\\linewidth]{3_GEMM_backgrounds/cnn.png}\n    \\caption{Convolutional Layer}\n    \\label{fig:cnn}\n    \\end{subfigure}\n    \\caption{Illustration of deep neural network layers}\n    \\label{fig:layers}\n\\end{figure}\n\n\n% \\begin{figure}[h]\n%     \\vspace{-0.5in}\n%     \\centering\n%     \\includegraphics[width=3.2in]{3_GEMM_backgrounds/cnn_time_distribution.pdf}\n%     \\vspace{-0.5in}\n%     \\caption{Breakdown of CNN computation time}\n%     \\label{fig:cnn_time}\n% \\end{figure}\n\n\\subsection{GEMM and Matrix Tiling}\n%GEneral Matrix Multiplication (GEMM) is initially part of the BLAS (Basic Linear Algebra Subprograms) library \\cite{BLAS2002}. It has the following iterative form:\n%\\begin{equation}\n%    C \\Leftarrow \\alpha AB + \\beta C \\nonumber.\n%\\end{equation}\n\nGEMM is a general procedure ubiquitously used in linear algebra, machine learning, statistics, and many other areas and is implemented in the BLAS (Basic Linear Algebra Subprograms) library \\cite{BLAS2002}. It multiplies two input matrices to produce an output matrix. The key difference between GEMM in deep learning and regular matrix multiplication is that the input matrices handled in deep learning are normally much larger. For example, a single layer in a typical convolution neural network may require multiplication of a $256 \\times 1024$ matrix by a $1024\\times 128$ matrix to produce a $256 \\times 128$ matrix. Regular three-for-loop (Fig.~\\ref{fig:three}) computation requires 34 million ($256 \\times 1024 \\times 128$) floating point operations (FLOPs). Modern deep neural networks may have hundreds of convolutional layers (e.g. ResNet152~\\cite{He15}), and such networks may need several billions of FLOPs to finish operations in all layers for an input image. \n\n\\begin{figure}[h]\n    \\centering\n    \\vspace{-0.1in}\n    \\includegraphics[width=2in]{3_GEMM_backgrounds/three_for_loop.png}\n    \\vspace{-0.1in}\n    \\caption{Computing matrix multiplication}\n    \\label{fig:three}\n\\end{figure}\n\nHigh cache hit rate of memory access is critical for complex numerical computation, such as GEMM. The large sizes of matrices usually forbid the entire matrices being loaded into memory or cache, however, GEMM can optimize memory access by iteratively splitting computation into smaller tiles, often referred to as the \\emph{tiling process}.\n% Large matrices cannot be loaded into memory or cache, so tiling matrices into blocks with GEMM is required to compute large matrix multiplication iteratively.\nA resulted matrix is initialized with zeros. GEMM uses outer products to compute part of a tile of the result and accumulates it on top of what has been stored in that tile. A tile is loaded from memory into cache and accumulates a new result on top of that. Fig.~\\ref{fig:tiling}~\\cite{Matthes17} illustrates a tiling strategy of GEMM.\n \n\\begin{figure}[t]\n  \\vspace{-0.5in}\n    \\centering\n    \\includegraphics[width=3in]{3_GEMM_backgrounds/tiling.pdf}\n    \\vspace{-0.5in}\n    \\caption{An Example of Tiling Strategy}\n    \\label{fig:tiling}\n\\end{figure}\n\nOriginal memory access patterns need to be transformed to adapt to the cache policy of a particular hardware. It is not straightforward to decide an optimal tiling strategy because it requires accurate estimate of accessed array regions in loops to match with cache size of target hardware and meet other constraints. Optimal tiling chooses a tile size for each loop to collectively achieve lowest running time on target hardware.", "meta": {"hexsha": "a4514fc1c577a092aadd73b28ab9dd573b9c018c", "size": 5090, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3_GEMM_backgrounds/problem_statement.tex", "max_stars_repo_name": "markjunior/icml2019_gemm", "max_stars_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "3_GEMM_backgrounds/problem_statement.tex", "max_issues_repo_name": "markjunior/icml2019_gemm", "max_issues_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "3_GEMM_backgrounds/problem_statement.tex", "max_forks_repo_name": "markjunior/icml2019_gemm", "max_forks_repo_head_hexsha": "67cf41f02fba4f8d638e47ab6407a7579f757679", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 80.7936507937, "max_line_length": 1037, "alphanum_fraction": 0.7713163065, "num_tokens": 1280, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206844384594, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7629729838043426}}
{"text": "% !TEX root = hw1.tex\n\n\\section{Link Analysis [25 points]}\n\n\\subsection{Personalized PageRank I [12 points]}\nPersonalizing PageRank is a very important real-world problem: different users\nfind different pages relevant, so search engines can provide better results if\nthey tailor their page relevance estimates to the users they are serving. Recall\nfrom class that PageRank can be specialized with clever modifications of the\nteleport vector. In this question, we will explore how this can be applied to\npersonalize the PageRank algorithm.\n\nAssume that people's interests are represented by a set of representative\npages. For example, if Zuzanna is interested in sports and food, then we could\nrepresent her interests with the set of pages $\\{$\\texttt{www.espn.com},\n\\texttt{www.epicurious.com}$\\}$. For notational convenience, we will use\nintegers as names for webpages.\n\nSuppose you have already computed the personalized PageRank vectors for the following users:\n\\vspace{-0.25cm}\n\\begin{itemize}\\setlength\\itemsep{0pt}\n\\item Agatha, whose interests are represented by the teleport set $\\{1,2,3\\}$\n\\item Bertha, whose interests are represented by the teleport set $\\{3,4,5\\}$\n\\item Clementine, whose interests are represented by the teleport set $\\{1,4,5\\}$\n\\item Dolo, whose interests are represented by the teleport set $\\{1\\}$\n\\end{itemize}\n\nAssume that the weights for each node in a teleport set are uniform.  Without\nlooking at the graph, can you compute the personalized PageRank vectors for the\nfollowing users? If so, how? If not, why not? Assume a fixed teleport parameter\n$\\beta$.\n\n\\vspace{-0.25cm}\n\\begin{enumerate}[i.]\n\\item \\textbf{[4 points]} Eloise, whose interests are represented by the teleport set $\\{2\\}$.\n\n\\item \\textbf{[4 points]} Felicity, whose interests are represented by the teleport set $\\{5\\}$.\n\n\\item \\textbf{[4 points]} Glynnis, whose interests are represented by the teleport set $\\{1,2,3,4,5\\}$ with weights 0.1, 0.2, 0.3, 0.2, 0.2, respectively.\n\\end{enumerate}\n\n\\subsection{Personalized PageRank II [5 points]}\n\nSuppose that you've already computed the personalized PageRank vectors of a set\nof users (denote the computed vectors $V$). What is the set of all personalized\nPageRank vectors that you can compute from $V$ without accessing the web graph?\n\n\\subsection{A different equation for PageRank [8 points]}\nIn class you that the PageRank equation can be written in different ways. You will prove this in this question.\nRecall that the PageRank equation is:\n\\begin{align}\n\\label{equation:PageRank}\n    \\mathbf{r} = \\mathbf{A} \\mathbf{r},\n\\end{align}\nwhere $\\mathbf{r} \\in \\mathbb{R}^N$ is the PageRank vector, i.e. the vector of PageRank scores for each of the $N$ nodes, and (where $\\mathbf{1}$ is the all-ones column vector of length $N$):\n\\begin{align}\n    \\mathbf{A} = \\beta \\mathbf{M} + \\frac{1-\\beta}{N}\\mathbf{1}\\mathbf{1}^\\top.\n\\end{align}\nRecall that here, $\\mathbf{M}$ is the stochastic adjacency matrix, defined as\n\\begin{align}\n    \\mathbf{M}_{ij} = \\left\\{\\begin{array}{lr}\n        \\frac{1}{d_j} , & \\text{if (j,i) is an edge}\\\\\n        0               & \\text{otherwise}\n        \\end{array}\\right\\}\n\\end{align}\nwhere $d_j$ is the degree of node $j$. Assume every node has degree at least 1.\n\nProve that (\\ref{equation:PageRank}) is equivalent to\n\\begin{align}\n    \\mathbf{r} = \\beta\\mathbf{M} \\mathbf{r}  + \\frac{1-\\beta}{N}\\mathbf{1}.\n\\end{align}\n\nHint: Recall that $\\mathbf{r}$ is normalized, i.e. $\\sum_{i=1}^N \\mathbf{r}_i = 1$.\n\n\\subsection*{What to submit}\n\\begin{enumerate}[2.1:]\n\\setcounter{enumi}{0}\n\\item\n  \\begin{itemize} \\item  For each of $(i)$,$(ii)$, and $(iii)$, `yes' or `no' and a brief explanation of why or why not. \\end{itemize}\n  \n\\item\n  \\begin{itemize} \\item A mathematical expression for the set in terms of $V$ and a brief explanation. \\end{itemize}\n  \n\\item\n  \\begin{itemize} \n  \\item Proof that the two PageRank equations are equivalent.\n  \\end{itemize}\n\n\\end{enumerate}\n", "meta": {"hexsha": "3c5b6634e93f260eaf122fc7c1ed243ea29a3dc8", "size": 3953, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw3-bundle/hw3_source/hw3_q2.tex", "max_stars_repo_name": "zlpure/cs224w", "max_stars_repo_head_hexsha": "03fc4d179e430454632e1eeaf457626b3ba18a4e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 9, "max_stars_repo_stars_event_min_datetime": "2020-09-02T15:40:33.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-24T05:22:33.000Z", "max_issues_repo_path": "H3/bundle/hw3_source/hw3_q2.tex", "max_issues_repo_name": "Cauchemare/CS224W_2020_Solutions", "max_issues_repo_head_hexsha": "0a37c06e804a0600a505229008e78557a663eabb", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "H3/bundle/hw3_source/hw3_q2.tex", "max_forks_repo_name": "Cauchemare/CS224W_2020_Solutions", "max_forks_repo_head_hexsha": "0a37c06e804a0600a505229008e78557a663eabb", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2021-07-22T16:37:17.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-10T16:05:32.000Z", "avg_line_length": 43.9222222222, "max_line_length": 191, "alphanum_fraction": 0.7267897799, "num_tokens": 1158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8459424411924673, "lm_q2_score": 0.9019206798249232, "lm_q1q2_score": 0.7629729816530653}}
{"text": "\\section{Hamiltonian Monte Carlo}%\n\\label{sec:l2hmc_hmc}\nWe can improve upon the random-walk guess and check strategy of the generic\nMarkov Chain Monte Carlo algorithm by ``guiding'' the simulation according to\nthe systems natural dynamics using a method known as Hamiltonian (Hybrid)\nMonte Carlo (HMC).\n\nIn HMC, model samples can be obtained by simulating a physical system\ngoverned by a Hamiltonian comprised of kinetic and potential energy functions\nthat govern a particles dynamics.\n%\nBy transforming the density function to a potential energy function and\nintroducing the auxiliary momentum variable $v$, HMC lifts the target\ndistribution onto a joint probability distribution in phase space $(x, v)$,\nwhere $x$ is the original variable of interest (e.g.\\ position in Euclidean\nspace).\n%\nA new state is then obtained by solving the equations of motion for a fixed\nperiod of time using a volume-preserving integrator (most commonly the\n\\emph{leapfrog integrator}).\n%\nThe addition of random (typically normally distributed) momenta encourages\nlong-distance jumps in state space with a single Metropolis-Hastings (MH)\nstep.\n\nLet the `position' of the physical state be denoted by a vector $x\n\\in\\mathbb{R}^{n}$ and the conjugate momenta of the physical state be denoted\nby a vector $v \\in\\mathbb{R}^{n}$.\n%\nThen the Hamiltonian reads\n%\n\\begin{align}\n  H(x, v) &= U(x) + K(v)\\\\\n                    & = U(x) + \\frac{1}{2} v^{T} \\,v,\n  \\label{eq:hamiltonian}\n\\end{align}\n%\nwhere $U(x)$ is the potential energy, and $K(v)=\\frac{1}{2}v^{T}v$ the\nkinetic energy.%\n%\nWe assume without loss of generality that the position and momentum variables\nare independently distributed.\n%\nThat is, we assume the target distribution of the system can be written as\n$\\pi(x, v) = \\pi(x) \\pi(v)$.\n%\nFurther, instead of sampling $\\pi(x)$ directly, HMC operates by sampling from the\ncanonical distribution $\\pi(x, v) = \\frac{1}{Z} \\exp(-H(x, v)) = \\pi(x)\n\\pi(v)$, for some partition function $Z$ that provides a normalization factor.\n%\nAdditionally, we assume the momentum is distributed according to an\nidentity-covariance Gaussian given by $\\pi(v) \\propto \\exp{(-\\frac{1}{2} v^{T} \\,\nv)}$ For convenience, we will denote the combined state of the system by $\\xi\n\\equiv (x, v)$.\n%\nFrom this augmented state $\\xi$, HMC produces a proposed state $\\xi^{\\prime} =\n(x^{\\prime}, v^{\\prime})$ by approximately integrating Hamiltonian dynamics\njointly on $x$ and $v$.\n%\nThis integration is performed along approximate iso-probability contours of\n$\\pi(x, v) = \\pi(x) \\pi(v)$ due to the Hamiltonians energy conservation.\n%\n\\subsection{Hamiltonian Dynamics}%\n\\label{subsec:mcmc_hamiltonian_dynamics}\nOne of the characteristic properties of Hamilton's equations is that they\nconserve the value of the Hamiltonian.\n%\nBecause of this, every Hamiltonian trajectory is confined to an energy\n\\emph{level set},\n%\n\\begin{equation}\nH^{(-1)}(E) = \\{x, v | H(x, v) = E\\}.\n\\end{equation}\n%\nOur state $\\xi = (x, v)$ then proceeds to explore this level set by integrating\nHamilton's equations, which are shown as a system of differential equations in\nEq.~\\ref{eq:hamiltons_equations}.\n% along wich the state $\\xi = (x, v)$\n% The state $\\xi$ is modified in such a way that $H(\\xi)$ remains constant thorughout the simulation.\n%\n% The differential equations governing the motion through state space are given by\n%\n\\begin{align}\n  \\dot x_i &= \\frac{\\partial H}{\\partial v_i} = v_i\\\\\n  \\dot v_i &= -\\frac{\\partial H}{\\partial x_i} = - \\frac{\\partial\n      U}{\\partial x_i}\n\\label{eq:hamiltons_equations}\n\\end{align}\n%\nIt can be shown~\\cite{Neal_2012} that the above transformation is\nvolume-preserving and reversible, two necessary factors to guarantee asymptotic\nconvergence of the simulation to the target distribution.\n%\nThe dynamics are simulated using the leapfrog integrator, which for a single\ntime step consists of:\n%\n\\begin{align}\n  v^{\\frac{1}{2}} &= v - \\frac{\\eps}{2} \\partial_x U(x)\\\\\n  x^{\\prime} &= x + \\eps v^{\\frac{1}{2}}\\\\\n  v^{\\prime} &= v - \\frac{\\eps}{2} \\partial_x U(x^{\\prime}).\n  \\label{eq:generic_leapfrog}\n\\end{align}\n%\nWe write the action of the leapfrog integrator in terms of an operator\n$\\mathbf{L}: \\mathbf{L}\\xi \\equiv \\mathbf{L}(x, v) \\equiv (x^{\\prime},\nv^{\\prime})$, and introduce a momentum flip operator $\\mathbf{F}: \\mathbf{F}(x,\nv) \\equiv (x, -v)$.\n%\nThe Metropolis-Hastings acceptance probability for the HMC proposal is given\nby:\n%\n\\begin{equation}\n  A(\\mathbf{F}\\mathbf{L} \\xi | \\xi) = \\min\\left(1,\n      \\frac{\\pi(\\mathbf{F}\\mathbf{L}\\xi)}{\\pi(\\xi)}\\left|\n      \\frac{\\partial\\left[\\mathbf{F}\\mathbf{L}\\xi\\right]}\n      {\\partial\\xi^{T}}\\right|\\right),\n\\label{eq:metropolis_hastings}\n\\end{equation}\n%\nWhere $\\left|\\frac{\\partial\\left[\\mathbf{F}\\mathbf{L}\\xi\\right]}\n{\\partial\\xi^{T}}\\right|$ denotes the determinant of the Jacobian describing\nthe transformation, and is equal to $1$ for traditional HMC.\\@\n%\nIn order to utilize these Hamiltonian trajectories to construct an efficient\nMarkov transition, we need a mechanism for introducing momentum to a given\npoint in the target parameter space.\n\nFortunately, this can be done by exploiting the probabilistic structure of the\nsystem~\\cite{Betancourt_2017}.\n%\nTo lift an initial point in parameter space into one on phase space, we simply\nsample from the conditional distribution over the momentum,\n%\n\\begin{equation}\nv \\sim \\pi(x | v).\n\\end{equation}\n%\nSampling the momentum directly from the conditional distribution ensures that\nthis lift will fall into the typical set in phase space.\n%\nWe can then proceed to explore the joint typical set by integrating Hamilton's\nequations as demonstrated above to obtain a new configuration $\\xi \\rightarrow\n\\xip$.\n%\nWe can then return to the target parameter space by simply projecting away the\nmomentum,\n%\n\\begin{equation}\n(x, v) \\rightarrow x\n\\end{equation}\n%\nThese three steps when performed in series gives a complete Hamiltonian Markov\ntransition composed of random trajectories that rapidly explore the target\ndistribution, as desired.\n%\nAn example of this process can be seen in Fig~\\ref{fig:hmc_phase_space}.\n%\n\\begin{figure}[htpb]\n\\includegraphics[width=\\textwidth]{new_figures/hmc_phase_space11}\n\\caption{\\emph{Visualizing HMC for a $1D$ Gaussian} (example\n  from~\\cite{Betancourt_2017}, figure adapted with permission\n  from~\\cite{joeyl2hmc}). Each Hamiltonian Markov transition lifts the\n  initial state onto a \\color{gray}{random level set of the Hamiltonian,\n  }\\color{black} $H^{(-1)}(E)$, which can then be explored with a\n  \\color{blue}{Hamiltonian trajectory }\\color{black} before\n  \\color{red}{projecting back down }\\color{black} to the \\color{green}{target\n  parameter space}\\color{black}.}%\n\\label{fig:hmc_phase_space}\n\\end{figure}\n%\n\\vspace{-10pt}\n\\subsubsection{Properties of Hamiltonian Dynamics}\n%\nThere are three fundamental properties of Hamiltonian dynamics which are\ncrucial to its use in constructing Markov Chain Monte Carlo updates.\n%\n\\begin{enumerate}\n  \\item \\textbf{Reversibility:} Hamiltonian dynamics are \\textit{reversible}\n      --- the mapping from $\\mathbf{L}: \\xi(t) \\rightarrow \\xi^{\\prime} =\n      \\xi(t + s)$ is one-to-one, and consequently has an inverse\n      $\\mathbf{L}^{-1}$, obtained by negating the time derivatives in\n      Eq.~\\ref{eq:hamiltons_equations}.\n  \\item \\textbf{Conservation of the Hamiltonian:} Moreover, the dynamics\n      \\textit{keeps the Hamiltonian invariant}.\n  \\item \\textbf{Volume preservation:} The final property of Hamiltonian\n      dynamics is that it \\textit{preserves volume} in $(x, v)$ phase space\n      (i.e. Liouville's Theorem).\n\\end{enumerate}\n%\nAll in all, HMC offers noticeable improvements compared to the `random-walk'\napproach of generic MCMC, but tends to perform poorly on high-dimensional\ndistributions.\n%\nThis becomes immediately apparent when it is used for simulations in lattice\ngauge theory and lattice QCD, where large autocorrelations and slow `burn-in'\ncan become prohibitively expensive.\n%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "meta": {"hexsha": "1768bb3bd6abfe2c8fb3ac915b561d092b0d5ced", "size": 8058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/hmc/hmc.tex", "max_stars_repo_name": "saforem2/l2hmc-qcd", "max_stars_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 32, "max_stars_repo_stars_event_min_datetime": "2019-04-18T18:50:28.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:30:48.000Z", "max_issues_repo_path": "doc/hmc/hmc.tex", "max_issues_repo_name": "saforem2/l2hmc-qcd", "max_issues_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 21, "max_issues_repo_issues_event_min_datetime": "2019-09-09T21:10:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:43:51.000Z", "max_forks_repo_path": "doc/hmc/hmc.tex", "max_forks_repo_name": "saforem2/l2hmc-qcd", "max_forks_repo_head_hexsha": "b5fe06243fae663607b6c88e71373b68b19558fc", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2020-10-31T02:25:04.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-25T00:49:14.000Z", "avg_line_length": 40.4924623116, "max_line_length": 101, "alphanum_fraction": 0.7314470092, "num_tokens": 2199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.824461928533133, "lm_q1q2_score": 0.7628168730609293}}
{"text": "\n\\subsection{Mean and variance of predictions}\n\n\\subsubsection{Bias}\n\n\\(\\hat y =\\theta x\\)\n\n\\(E[\\hat y-y]=E[\\theta x-y]\\) \n\n\\(y=\\hat y + \\epsilon \\)\n\n\\(E[y-\\hat y |X]\\)\n\n\\(E[\\epsilon |X]\\)\n\nUnbiased so long as independent of error term.\n\n\\subsubsection{Variance}\n\n\\(Var [\\hat y-y]=Var [\\theta x-y]\\)\n\n\\(Var[y-\\hat y |X]\\)\n\n\\(Var[\\epsilon |X]\\)\n\n", "meta": {"hexsha": "ac2a844dc2939bed87afbd74194801b8c4bc1d5e", "size": 345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/ols/02-02-prediction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/ols/02-02-prediction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/ols/02-02-prediction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 13.2692307692, "max_line_length": 46, "alphanum_fraction": 0.5913043478, "num_tokens": 118, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9648551495568569, "lm_q2_score": 0.7905303285397349, "lm_q1q2_score": 0.7627472583724372}}
{"text": "\\section{Logic Circuits}\n\n\\subsection*{A Half Adder}\n\nA \\emph{half adder} demonstrates the way in which computer logic gates can correctly add (binary) numbers, though here it can add only two \\emph{binary digits} (``bits''). Thus, each half adder can only count to \\emph{two}, but that is enough!  Long cascades of half adders and \\emph{full adders} enable computers to count large numbers. Below, see two examples of half adders. The second example replaces the XOR gate with a series of simpler gates, but the results are the same. Each half adder takes two bits and adds them, passing on the bits for further work or as an answer itself.\n\n\\bigskip\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\begin{tabular}{m{3.25in} m{2.0in}}\n\n\\input{./include/halfadder1.tex}\n\n&\n\n\\begin{tabular}{ll | cc | c}\n\\multicolumn{5}{c}{\\textbf{Truth Table}}\\\\\n\\hline\\\\[\\negsep]\n\\textbf{A} & \\textbf{B} & \\textbf{Sum} & \\textbf{Carry} & \\textbf{Decimal}\\\\\n\\hline\n0 & 0 & 0 & 0 & 0 \\\\\n1 & 0 & 1  & 0 & 1 \\\\\n0 & 1 & 1  & 0 & 1 \\\\\n1 & 1 & 0  & 1 & 2 \\\\\n\\hline\n\\end{tabular}\n\n\\\\\n\n\\end{tabular}\n\n\\caption{A half-adder circuit. It adds two bits together. If the result is larger than 1, the ``carry\" signal is high.}\n\\end{center}\n\\end{figure}\n\nFigure \\ref{fig:threehalfadders} shows each of the three possible outcomes of a half adder. Make sure you understand how each result happens.\n\n\\begin{figure}[!hb]\n\\begin{center}\n\n\\input{./include/halfadder2.tex}\n\n\\caption{Another half-adder circuit. The exclusive-OR gate has been replaced by an equivalent circuit made up of five simpler gates. You can see why XOR requires so many transistors!}\n\\end{center}\n\\end{figure}\n\n\\input{./include/three-half-adder-outputs.tex}\n\n\\clearpage\n\n\\subsection*{Full Adder}\n\nThis type of adder is a little more difficult to implement than a half-adder. The main difference between a half-adder and a full-adder is that the full-adder has \\emph{three} inputs and two outputs. The first two inputs are A and B, just like with every half-adder, and the third input is an input carry, designated as $C_{in}$. Enabling the circuit to handle a carry \\emph{in} from another adder makes it possible to add many binary orders of magnitude, since many carry-outs and carry-ins will be needed to add numbers larger than 1. Once we implement a full adder, we can string eight of them together to create a byte-wide adder and cascade the carry bit from one adder to the next.\n\\bigskip\n\n\\begin{figure}[!hb]\n\\begin{center}\n\\input{./include/fulladder1.tex}\n\\caption{A full-adder circuit, made up of two half-adder circuits. A full-adder enables carry-in as well as carry-out. This means that the full adder can add \\emph{three} inputs together, and keep track of all of them. If the sum is two or three, the carry-out signal goes high. These units can be linked together to make binary addition work even for very large numbers.}\n\\end{center}\n\\end{figure}\n\nSince full adders can accept three inputs, the truth table is pretty big.\n\n\\begin{center}\n\\begin{tabular}{ccc  cc  c}\n\\multicolumn{6}{c}{\\textbf{Full Adder Truth Table}}\\\\\n\\hline\\\\[\\negsep]\n &  & \\textbf{Carry} &  & \\textbf{Carry} & \\\\\n\\textbf{A} & \\textbf{B} & \\textbf{In} & \\textbf{Sum} & \\textbf{Out} & \\textbf{Decimal}\\\\\n\\hline\n0 & 0 & 0 & 0  & 0 & 0 \\\\\n\\grr\n1 & 0 & 0 & 1  & 0 & 1 \\\\\n0 & 1 & 0 & 1  & 0 & 1 \\\\\n\\grr\n1 & 1 & 0 & 0  & 1 & 2 \\\\[\\sep]\n\\hline\\\\[\\negsep]\n0 & 0 & 1 & 0  & 0 & 1 \\\\\n\\grr\n1 & 0 & 1 & 0  & 1 & 2 \\\\\n0 & 1 & 1 & 0  & 1 & 2 \\\\\n\\grr\n1 & 1 & 1 & 1  & 1 & 3 \\\\\n\n\\hline\n\\end{tabular}\n\\end{center}\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\input{./include/fulladder1_example001.tex}\n\\caption{One of the possible input conditions for a full adder. Here, only the carry-in bit is 1. The inputs for A and B are 0. Since both A and B are the same, $XOR_1$ outputs 0 (no voltage). Since the carry-in bit (signal) is 1, and the output from $XOR_1$ is 0, the inputs to $XOR_2$ are different: so $XOR_2$ outputs 1. The inputs to $AND_2$ are not both 1, so $AND_2$ outputs 0. A and B are both 0, so $AND_1$ outputs 0. Since both $AND_1$ and $AND_2$ output 0, the OR gate outputs 0. Here, the value from the carry-out signal from another full adder is the only input. So at \\emph{this} digit (``order of magnitude''), the sum is 1, and there is no value to carry out. }\n\\end{center}\n\\end{figure}\n\n\n\\begin{figure}[!ht]\n\\begin{center}\n\\includegraphics[scale=0.19]{FullAdderboard.png}\n\\caption{A single full-adder circuit for adding two bits plus a carry-in digit, implemented on a small circuit board using individual integrated circuit gates instead of discrete transistors. You can see the gates easily, but the board is much simpler to work with, compared to forming up a full adder from five of the single-gate boards.}\n\\end{center}\n\\end{figure}\n\n\n\n\n\\clearpage\n\n\\subsection*{Equality}\n\nComparing two one-bit numbers to see if they are identical is done with XNOR gates. These gates are the same as an XOR gate passing output into a NOT gate. \n\n\\begin{center}\n\n\\begin{tabular}{p{2.5in} p{3.5in} }\n\\hline\\\\[\\negsep]\n\nThe symbol for an XNOR gate is:\n\n\\vspace{0.25in}\n\n\\begin{circuitikz}\n\\draw\n\t(0,0) node[xnor port](xnorGate) {}\n\t(xnorGate.in 1) node[left] {{\\color{red}$INPUT~A$}}\n\t(xnorGate.in 2) node[left] {{\\color{red}$INPUT~B$}}\n\t(xnorGate.out) node[right] {{\\color{red}$OUT$}}\n;\n\\end{circuitikz}\n\n&\n\n\\centering\n\nThe ``Truth Table\" (how they behave) is: \n\\vspace{0.15in}\n\n\\begin{tabular}{ll | c}\n\\multicolumn{3}{c}{\\textbf{XNOR Gate }}\\\\\n\\multicolumn{3}{c}{\\textbf{Truth Table}}\\\\\n\\hline\\\\[\\negsep]\n\\textbf{A} & \\textbf{B} & \\textbf{OUT}\\\\\n\\hline\n0 & 0 & 1  \\\\\n1 & 0 & 0  \\\\\n0 & 1 & 0  \\\\\n1 & 1 & 1  \\\\\n\\hline\n\\end{tabular}\n\\\\\n\\tabularnewline\n\n\\hline\\\\[\\negsep]\n\n\\end{tabular}\n\\end{center}\n\n\\begin{figure}[hb!]\n\\begin{center}\n\\includegraphics[scale=0.17]{XNOR1.jpg}\n\\caption{A discrete-transistor XNOR gate made up of one XOR and one NOT gate. Tying the output of the XOR gate to the input of the NOT gate makes the result of the NOT gate an XNOR of the original two XOR gate inputs---answering the question ``are the two inputs equal?\"}\n\\end{center}\n\\end{figure}\n\nTo compare large numbers, the circuit requires an XNOR gate for each binary digit (bit) in the numbers being compared. If any XNOR gate returns zero, the numbers are not equivalent. To build all of the XNOR gates into a single yes or no answer, each XNOR output could go into a series of AND gates -- that is, since AND returns a ``yes'' only if both inputs are one, a single ``no'' prevents the AND gate from returning ``yes''. \n\n\n\\begin{figure}[h!]\n\\begin{center}\n\\input{./include/andcascade.tex}\n\\caption{A circuit to provide a yes/no answer to the question, ``are  two four-bit numbers, A and B, equal?\" Each XNOR gate compares the bits in each position of each number, and passes the answer to an AND gate input. The AND results ripple forward to a final answer.}\n\\end{center}\n\\end{figure}\n\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics[scale=0.16, clip=TRUE, trim=0 0 500 0]{4bitxnor.jpg}\n\\caption{Testing for equality with four XNOR gates. Here, XNOR gates are created with XOR gates that pass the output (green wires) to a NOT gate. An XOR gate only goes logic high if the inputs are different. Thus, NOT XOR means both inputs are the same! Each XNOR output (blue wires) passes to a NAND gate. Recall that NAND gates only return zero if both inputs are 1. The output of each NAND gate (purple wires) passes to one input of a NOR gate. So if both inputs to a given NAND gate are ``1'', the NAND gate will show ``0\" as its result. NOR gates only return 1 if both inputs are zero. The result: the NOR gate lights up an LED if all inputs are equal. It is no different than the AND-gate cascade shown above in its result, it just uses negative logic to get there. Here, both inputs are equal to 1, so the LED is lit.}\n\\end{center}\n\\end{figure}\n\n\n\n\n\n\n\n\\clearpage\n\n\n", "meta": {"hexsha": "f16c0600fb6f3006afae370072b44c86a64f8ad8", "size": 7836, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/logiccircuits.tex", "max_stars_repo_name": "jessehamner/TechMillForKids", "max_stars_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2017-11-13T21:45:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-25T09:31:54.000Z", "max_issues_repo_path": "chapters/logiccircuits.tex", "max_issues_repo_name": "jessehamner/TechMillForKids", "max_issues_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2017-03-10T21:46:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-25T19:21:58.000Z", "max_forks_repo_path": "chapters/logiccircuits.tex", "max_forks_repo_name": "jessehamner/TechMillForKids", "max_forks_repo_head_hexsha": "f064bf1408537f71e4e7dc14f02a8e7e20c2af3a", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2017-11-14T04:40:14.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-17T05:31:36.000Z", "avg_line_length": 40.3917525773, "max_line_length": 825, "alphanum_fraction": 0.7132465544, "num_tokens": 2468, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8872046041554922, "lm_q1q2_score": 0.7626976438577074}}
{"text": "\\section{Multivariable Equations}\r\n\\subsection{Functions of Multiple Independent Variables}\r\nConsider $f(x,y)$ and a small vector displacement $\\underline{\\mathrm ds}=(\\mathrm dx,\\mathrm dy)$, so the change along $\\underline{\\mathrm ds}$ is\r\n$$\\mathrm df=\\frac{\\partial f}{\\partial x}\\mathrm dx+\\frac{\\partial f}{\\partial y}\\mathrm dy=\\underline{\\mathrm ds}\\cdot(\\nabla f)$$\r\nby the multivariate chain rule.\r\nHere, $\\nabla f=(f_x,f_y)$ is called the gradient of $f$.\r\nIf we write $\\underline{\\mathrm ds}=\\mathrm ds\\underline{\\hat{s}}$ with $|\\underline{\\hat{s}}|=1$, so $\\mathrm df=\\mathrm ds(\\underline{\\hat{s}}\\cdot\\nabla f)$\r\n\\begin{definition}\r\n    The directional derivative is defined as\r\n    $$\\frac{\\mathrm df}{\\mathrm ds}=\\underline{\\hat{s}}\\cdot\\nabla f$$\r\n\\end{definition}\r\n\\begin{proposition}\r\n    1. The magnitude of $\\nabla f$ is the maximum rate of change of $f$, that is\r\n    $$|\\nabla f|=\\sup_{\\underline{\\hat{s}},|\\underline{\\hat{s}}|=1}\\frac{\\mathrm df}{\\mathrm ds}$$\r\n    And the supremum can be attained.\\\\\r\n    2. The direction of $\\nabla f$ is the direction where $f$ increases most rapidly.\\\\\r\n    3. If $\\underline{\\hat{s}}$ is parallel to the contour of $f$, then $\\mathrm df/\\mathrm ds=0$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    1. Cauchy-Schwarz and take $\\underline{\\hat{s}}=\\nabla{f}/|\\nabla f|$.\\\\\r\n    2,3. Obvious.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    There is always one direction where $\\mathrm df/\\mathrm ds=0$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    Local extrema of $f$ have $\\mathrm df/\\mathrm ds=0$ for any direction.\r\n    Hence $\\nabla f=\\underline{0}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\nHowever, if $\\nabla f=\\underline{0}$ at some point, it does \\textit{not} follow that the point is an local extremum, since it could be a saddle point.\r\nNear local extrema, the contour of $f$ is elliptical while it is hyperboly near saddle points.\r\nAlso, contours of $f$ can only cross at saddle point.\r\n\\subsection{Taylor Series for Multivariate Functions}\r\nConsider $f(x,y)$ near a point $\\underline{s_0}\\in\\mathbb R^2$ and a displacement $\\delta s$ along the line $\\underline{\\delta s}$, so\r\n\\begin{align*}\r\n    f(s_0+\\delta s)&=f(s_0)+\\delta s\\frac{\\mathrm df}{\\mathrm ds}+\\frac{(\\delta s)^2}{2}\\frac{\\mathrm d^2f}{\\mathrm ds^2}+\\cdots\\\\\r\n    &=f(s_0)+\\delta s(\\underline{\\hat s}\\cdot\\nabla f)+\\frac{(\\delta s)^2}{2}(\\underline{\\hat{s}}\\cdot\\nabla)(\\underline{\\hat s}\\cdot\\nabla)f+\\cdots\r\n\\end{align*}\r\nTo write it out in coordinate form,\r\n\\begin{definition}\r\n    The Hessian matrix is defined by\r\n    $$H=\r\n    \\begin{pmatrix}\r\n        f_{xx}&f_{xy}\\\\\r\n        f_{yx}&f_{yy}\r\n    \\end{pmatrix}=\\nabla(\\nabla f)$$\r\n    Note that $H$ is symmetric whenever $f$ is nice enough (e.g. $C^2$) to have $f_{yx}=f_{xy}$.\r\n\\end{definition}\r\nWe have, by this notation,\r\n\\begin{align*}\r\n    f(\\underline{x})&=f(x,y)\\\\\r\n    &=f(x_0,y_0)+(x-x_0)f_x+(y-y_0)f_y\\\\\r\n    &\\quad+\\frac{1}{2}((x-x_0)^2f_{xx}+2(x-x_0)(y-y_0)f_{xy}+(y-y_0)^2f_{yy})+\\cdots\\\\\r\n    &=f(\\underline{x_0})+\\nabla f(\\underline{x_0})(\\underline{x}-\\underline{x_0})^\\top+\\frac{1}{2}(\\underline{x}-\\underline{x_0}) H(x_0)(\\underline{x}-\\underline{x_0})^\\top+\\cdots\r\n\\end{align*}\r\n\\subsection{Classification of Stationary Points}\r\nWhen $\\nabla f=\\underline{0}$ at some $\\underline{x_0}$, we have\r\n$$f(\\underline{x_0}+\\underline{\\delta x})\\approx f(\\underline{x_0})+\\frac{1}{2}\\underline{\\delta x} H(x_0)\\underline{\\delta x}^\\top$$\r\nNote that this can extend analogously to $n$ dimensions.\r\n\\begin{definition}\r\n    The Hessian in $n$ dimensions is defined by\r\n    $$H=\r\n    \\begin{pmatrix}\r\n        f_{x_1x_1}&f_{x_1x_2}&\\dots&f_{x_1x_n}\\\\\r\n        f_{x_2x_1}&f_{x_2x_2}&\\dots&f_{x_2x_n}\\\\\r\n        \\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n        f_{x_nx_1}&f_{x_nx_2}&\\dots&f_{x_nx_n}\r\n    \\end{pmatrix}$$\r\n\\end{definition}\r\nIf $f$ is nice enough to allow change of order of partial derivatives, then $H(x_0)$ is real and symmetric, hence diagonalizable by Spectral Theorem.\r\nSo we can choose the basis to be the eigenbasis (which can be chosen to be orthonormal), therefore\r\n$$\\underline{\\delta x}H(x_0)\\underline{\\delta x}^\\top=\\sum_{i=1}^n\\lambda_i(\\delta x_i)^2$$\r\nWith this, we can classify the stationary points in $3$ cases.\\\\\r\nCase 1: $\\forall\\underline{\\delta x}\\in\\mathbb R^n\\setminus\\{\\underline{0}\\},\\underline{\\delta x}H(x_0)\\underline{\\delta x}^\\top>0$.\r\nThis happens iff $\\lambda_i>0$ for each $i$, that is, $H$ is positive definite.\\\\\r\nCase 2: $\\forall\\underline{\\delta x}\\in\\mathbb R^n\\setminus\\{\\underline{0}\\},\\underline{\\delta x}H(x_0)\\underline{\\delta x}^\\top<0$.\r\nThis happens iff $\\lambda_i<0$ for each $i$, that is, $H$ is negative definite.\\\\\r\nCase 3: Otherwise, $H$ is indefinite.\r\n\\begin{definition}\r\n    The signature of $H$ is the pattern of signs of its subdeterminant.\r\n\\end{definition}\r\nFor example, for $f(x_1,x_2,\\ldots x_n)$, the subdeterminants are\r\n$$H_k=\r\n\\begin{pmatrix}\r\n    f_{x_1x_1}&f_{x_1x_2}&\\dots&f_{x_1x_k}\\\\\r\n    f_{x_2x_1}&f_{x_2x_2}&\\dots&f_{x_2x_k}\\\\\r\n    \\vdots&\\vdots&\\ddots&\\vdots\\\\\r\n    f_{x_kx_1}&f_{x_kx_2}&\\dots&f_{x_kx_k}\r\n\\end{pmatrix}$$\r\nThen the sign is the signs of $|H_1|,|H_2|,\\ldots,|H_n|$.\r\n\\begin{theorem}\r\n    If $H$ is positive (negative) definite, so is all of $H_i$.\r\n\\end{theorem}\r\nTherefore a minimum (maximum) point of a real function in $\\mathbb R^n$ is also a minimum (maximum) point in any subspace of $\\mathbb R^n$ that includes the point.\r\n\\begin{center}\r\n    \\begin{tabular}{c|c}\r\n        Type of S.P.&Signature\\\\\r\n        \\hline\r\n        Minimum&$+,+,+,+,\\ldots$\\\\\r\n        Maximum&$-,+,-,+,\\ldots$\r\n    \\end{tabular}\r\n\\end{center}\r\nSometimes $|H|=0$, in which case this stationary point is called degenerate, so we need to look at higher order terms in the Taylor series.\r\nThe helps us in sketching the contour of a two dimensional function.\r\nConsider the coordinate system aligned with the (orthonormal) eigenbasis of $H$, so $\\underline{\\delta x}=\\underline{x}-\\underline{x_0}=(\\xi_1,\\xi_2)$, where $\\underline{x_0}$ is a stationary point.\r\nIn a small region near $x_0$, contour of $f$ satisfies\r\n$$\\text{const}=f\\approx f(\\underline{x_0})+\\frac{1}{2}\\underline{\\delta x}H\\underline{\\delta x}^\\top\\implies \\lambda_1\\xi_1^2+\\lambda_2\\xi_2^2=\\text{const}$$\r\nNear min/max, $\\lambda_1,\\lambda_2$ have the same sign, so the contour looks like an ellipse.\r\nNear saddles, they have the different sign and the contour looks like a hyperbola.\r\n\\begin{example}\r\n    We want to find and classify the stationary points of\r\n    $$f(x,y)=4x^3-12xy+y^2+10y+6$$\r\n    and sketch its contour.\\\\\r\n    We have $f_x=12x^2-12y,f_y=-12x+2y+10$, so at the stationary point, we have $(x,y)=(1,1),(5,25)$.\r\n    Now $f_{xx}=24x,f_{xy}=f_{yx}=-12,f_{yy}=2$.\r\n    So at $(1,1)$,\r\n    $$H=\\begin{pmatrix}\r\n        24&-12\\\\\r\n        -12&2\r\n    \\end{pmatrix}\\implies |H_1|>0,|H_2|<0$$\r\n    So it is neither a maximum nor a minimum, hence it is a saddle point.\\\\\r\n    As for $(5,25)$,\r\n    $$H=\\begin{pmatrix}\r\n        120&-12\\\\\r\n        -12&2\r\n    \\end{pmatrix}\\implies |H_1|>0,|H_2|>0$$\r\n    so it is a minimum.\r\n    We can then sketch the contour by drawing ellipses near $(5,25)$ and hyperbolic curves near $(1,1)$.\r\n\\end{example}\r\n\\subsection{System of Linear ODEs}\r\nConsider a few dependent variables $y_1(t),y_2(t),\\ldots$ which satisfies system of coupled ODEs.\r\n\\begin{example}\r\n    Consider\r\n    $$\r\n    \\begin{cases}\r\n        \\dot{y_1}=ay_1+by_2+f_1(t)\\\\\r\n        \\dot{y_2}=cy_1+dy_2+f_2(t)\r\n    \\end{cases}\r\n    $$\r\n    So in vector form\r\n    $$\\underline{\\dot{y}}=M\\underline{y}+\\underline{f}$$\r\n\\end{example}\r\nAny $n^{th}$ order ODE can be written as a system of $n$ first-order ODEs.\r\n\\begin{example}\r\n    Consider $\\ddot{y}+a\\dot{y}+by=f$, so let $y_1=y,y_2=y^\\prime$, then we have\r\n    $$\\frac{\\mathrm d}{\\mathrm dt}\\begin{pmatrix}\r\n        y_1\\\\\r\n        y_2\r\n    \\end{pmatrix}=\r\n    \\begin{pmatrix}\r\n        0&1\\\\\r\n        -b&-a\r\n    \\end{pmatrix}\r\n    \\begin{pmatrix}\r\n        y_1\\\\\r\n        y_2\r\n    \\end{pmatrix}+\r\n    \\begin{pmatrix}\r\n        0\\\\\r\n        f\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\nOne way to solve it is to use matrix methods.\r\nConsider\r\n$$\\underline{\\dot{y}}=M\\underline{y}+\\underline{f}$$\r\nFirst, we find the general solution $\\underline{y_c}$ to\r\n$$\\underline{\\dot{y}_c}-M\\underline{y_c}=0$$\r\nThen we find a particular solution $\\underline{y_p}$ to the system, so by the superposition principle the general solution is $\\underline{y_p}+\\underline{y_c}$.\\\\\r\nTo find solution to the homogeneous equation, we try $\\underline{y_c}=\\underline{v}e^{\\lambda t}$ which leads us to the conclusion that $\\lambda$ must be an eigenvalue of $M$ with eigenvector $\\underline{v}$.\r\n\\begin{example}\r\n    Consider\r\n    $$\\underline{\\dot{y}}-\\begin{pmatrix}\r\n        -4&24\\\\\r\n        1&-2\r\n    \\end{pmatrix}\\underline{y}=\\begin{pmatrix}\r\n        4\\\\\r\n        1\r\n    \\end{pmatrix}e^t$$\r\n    We can find the eigenvalues and eigenvectors of $M$ and find that $\\lambda_1=2,\\underline{v_1}=(4,1)^\\top,\\lambda_2=-8,\\underline{v_2}=(-6,1)^\\top$\r\n    So we have\r\n    $$\\underline{y_c}(t)=A\\begin{pmatrix}\r\n        4\\\\\r\n        1\r\n    \\end{pmatrix}e^{2t}+B\\begin{pmatrix}\r\n        -6\\\\\r\n        1\r\n    \\end{pmatrix}e^{-8t}$$\r\n    We can sketch the phase portrait of $y_2$ against $y_1$ to find a hyperbola-like path of $(y_1,y_2)$.\\\\\r\n    To find the particular integral, we can try\r\n    $$\\underline{y_p}=\\begin{pmatrix}\r\n        u_1\\\\\r\n        u_2\r\n    \\end{pmatrix}e^t$$\r\n    and find that $(u_1,u_2)=(-4,-1)$ solves the system, therefore the general solution is\r\n    $$\r\n    \\underline{y}=\r\n    \\begin{pmatrix}\r\n        -4\\\\\r\n        -1\r\n    \\end{pmatrix}e^t+\r\n    A\\begin{pmatrix}\r\n        4\\\\\r\n        1\r\n    \\end{pmatrix}e^{2t}+B\\begin{pmatrix}\r\n        -6\\\\\r\n        1\r\n    \\end{pmatrix}e^{-8t}\r\n    $$\r\n    where $A,B$ are constants.\r\n\\end{example}\r\nIf the forcing matches the eigenvalue and eigenvector, we can try multiplying a polynomial in $t$ (mostly just $t^k$ will work).\\\\\r\nFrom a linear system of $n$ first-order ODEs, we can construct $n$ uncoupled $n^{th}$ order ODEs.\r\n\\begin{example}\r\n    Consider the same equation\r\n    $$\\underline{\\dot{y}}=\\begin{pmatrix}\r\n        -4&24\\\\\r\n        1&-2\r\n    \\end{pmatrix}\\underline{y}+\\begin{pmatrix}\r\n        4\\\\\r\n        1\r\n    \\end{pmatrix}e^t$$\r\n    We can differentiate the first component to get $\\ddot{y_1}=-4\\dot{y_1}+24\\dot{y_2}+4e^t=-6\\dot{y_1}+16y_1+36e^t$, which we know how to solve.\r\n    Similar way works for $y_2$.\r\n    One can check that this essentially gives the same solution.\r\n\\end{example}\r\nWe can discuss the concept of Phase Portrait in a more general way.\r\nFor complementary function $\\underline{y_c}$ satisfying $\\underline{\\dot{y}_c}=M\\underline{y_c}$, then $y_c=\\underline{v_1}e^{\\lambda_1 t}+\\underline{v_2}e^{\\lambda_2 t}$\\\\\r\nCase 1: $\\lambda_1,\\lambda_2$ are real and $\\lambda_1\\lambda_2<0$, WLOG $\\lambda_1>0>\\lambda_2$, then the Phase Portrait is hyperbolic and converging towards the direction of $\\underline{v_1}$.\\\\\r\nCase 2: $\\lambda_1,\\lambda_2$ are real and $\\lambda_1\\lambda_2>0$.\r\nIf $\\lambda_1<\\lambda_2<0$, the phase portrait converge to $0$.\r\nThis is called the stable node.\r\nIf $\\lambda_1>\\lambda_2>0$, the phase portrait diverge from $0$.\r\nthis is called the unstable node.\\\\\r\nCase 3: They are both complex.\\\\\r\nCase 3(a): The real parts are both negative, then the amplitude will decrease in time, so it produces a spiral-like phase portrait converging to $0$ (stable spiral).\\\\\r\nCase 3(b): They are both positive, so the amplitude grows in time, so it produces a spiral-like curve spiraling out of $0$, then it is an unstable spiral.\\\\\r\nCase 3(c): They are both zero, then the amplitudes does not change and it is purely oscillating (i.e. circles centering at $0$).\r\nWe can find the direction of the oscillation by evaluating the equation at a given point and find the sign of $\\dot{y}_2$.\r\n\\subsection{Nonlinear Systems}\r\nConsider a nonlinear autonomous system\r\n$$\\begin{cases}\r\n    \\dot{x}=f(x,y)\\\\\r\n    \\dot{y}=g(x,y)\r\n\\end{cases}$$\r\nWe want to find equilibrium (fixed) point, so for $\\dot{x}=\\dot{y}=0$, we have $f(x_0,y_0)=0=g(x_0,y_0)$\r\nWe can do perturbation analysis by a small displacement $(x,y)=(x_0+\\xi(t),y_0+\\eta(t))$ around the fixed point, so\r\n$$\\dot{\\xi}=f(x_0+\\xi,y_0+\\eta)=f(x_0,y_0)+\\xi f_x(x_0,y_0)+\\eta f_y(x_0,y_0)+\\cdots$$\r\n$$\\dot{\\eta}=g(x_0+\\xi,y_0+\\eta)=g(x_0,y_0)+\\xi g_x(x_0,y_0)+\\eta g_y(x_0,y_0)+\\cdots$$\r\nBut $f,g$ are $0$ at $(x_0,y_0)$, so\r\n$$\\begin{pmatrix}\r\n    \\dot{\\xi}\\\\\r\n    \\dot{\\eta}\r\n\\end{pmatrix}\\approx\r\n\\left.\\begin{pmatrix}\r\n    f_x&f_y\\\\\r\n    g_x&g_y\r\n\\end{pmatrix}\\right|_{(x_0,y_0)}\\begin{pmatrix}\r\n    \\xi\\\\\r\n    \\eta\r\n\\end{pmatrix}$$\r\n\\begin{example}\r\n    Lotka-Volterra Model of predator and prey.\r\n    $$\\begin{cases}\r\n        \\dot{x}=\\alpha x-\\beta xy=f(x,y)\\\\\r\n        \\dot{y}=\\delta xy-\\gamma y=g(x,y)\r\n    \\end{cases}$$\r\n    where $\\alpha,\\beta,\\gamma,\\delta>0$.\r\n    The fixed point is $(0,0)$ and $(\\gamma/\\delta,\\alpha/\\beta)$.\r\n    Note that we have\r\n    $$\\begin{pmatrix}\r\n        f_x&f_y\\\\\r\n        g_x&g_y\r\n    \\end{pmatrix}=\\begin{pmatrix}\r\n        \\alpha-\\beta y&-\\beta x\\\\\r\n        \\delta y&\\delta x-\\gamma\r\n    \\end{pmatrix}$$\r\n    At $(0,0)$, we have\r\n    $$\\begin{pmatrix}\r\n        \\dot{\\xi}\\\\\r\n        \\dot{\\eta}\r\n    \\end{pmatrix}\\approx\r\n    \\begin{pmatrix}\r\n        \\alpha&0\\\\\r\n        0&-\\gamma\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        \\xi\\\\\r\n        \\eta\r\n    \\end{pmatrix}$$\r\n    So the eigenvalues are $\\alpha,-\\gamma$, thus it is a saddle point.\r\n    For the other fixed point,\r\n    $$\\begin{pmatrix}\r\n        \\dot{\\xi}\\\\\r\n        \\dot{\\eta}\r\n    \\end{pmatrix}\\approx\r\n    \\begin{pmatrix}\r\n        0&\\frac{-\\beta\\gamma}{\\delta}\\\\\r\n        \\frac{\\alpha\\delta}{\\beta}&0\r\n    \\end{pmatrix}\\begin{pmatrix}\r\n        \\xi\\\\\r\n        \\eta\r\n    \\end{pmatrix}$$\r\n    So it has a pair of purely imaginary eigenvalues, so it a center.\r\n    The direction of rotation is counterclockwise.\r\n    Indeed, we have\r\n    $$\\dot{\\xi}=\\frac{-\\beta\\gamma}{\\delta}\\eta<0$$\r\n    for $\\eta>0$.\r\n    We can sketch the solutions.\r\n\\end{example}\r\n\\subsection{Partial Differential Equations}\r\n\\begin{definition}\r\n    A PDE is a DE with partial derivatives.\r\n\\end{definition}\r\nHere, we will only consider three examples.\r\n\\subsubsection{First Order Wave Equation}\r\nThis is the PDE\r\n$$\\frac{\\partial y}{\\partial t}-c\\frac{\\partial y}{\\partial x}=0$$\r\nwhere $y=y(x,t)$ and $c$ is a constant.\r\nWe can solve it with the method of characteristics.\r\nImagine the contour of $y$ in the $x-t$ plane, then we can start at some point and move it back and forth along a path.\r\nSo along a path $x(t)$, if we have $y(x(t),t)$, then plugging it in our equation by the multivariate chain rule,\r\n$$\\frac{\\mathrm dy}{\\mathrm dt}=\\frac{\\partial y}{\\partial t}+\\frac{\\partial y}{\\partial x}\\frac{\\mathrm dx}{\\mathrm dt}$$\r\nSo we can take the path where $\\dot{x}=-c$ thus $\\dot{y}=0$ (so $x=x_0-ct$), hence $y$ will be constant along that line.\r\nThese paths are called characteristics.\r\nIf $y(x,t=0)=f(x)$, then $y=f(x_0)$ along the characteristic.\r\nTherefore the general solution is\r\n$$y=f(x+ct)$$ for some differentiable $f$.\r\n\\begin{example}\r\n    With the initial condition $y(x,0)=x^2-3$, since we have $y=f(x+ct)$, $y(x,t)=(x+ct)^2-3$.\r\n\\end{example}\r\nIf we add some forcing,\r\n\\begin{example}\r\n    Consider\r\n    $$\\frac{\\partial y}{\\partial t}+5\\frac{\\partial y}{\\partial x}=e^{-t}$$\r\n    with $y(x,0)=e^{-x^2}$.\r\n    So $\\mathrm dy/\\mathrm dt$ along the path with $\\mathrm dx/\\mathrm dt=5$, so $y=A-e^{-t}$ along a path.\r\n    Note that $A$ depends on $x(0)=x_0$, the initial point of the path.\r\n    We know $y(x,0)=A-1=e^{-x_0^2}$, so $A=1+e^{-x_0^2}$.\r\n    Hence $y=1+e^{-(x-5t)^2}-e^{-t}$.\r\n\\end{example}\r\n\\subsubsection{Second Order Wave Equation}\r\nWe want to solve\r\n$$\\frac{\\partial^2 y}{\\partial t^2}-c^2\\frac{\\partial^2 y}{\\partial x^2}=0$$\r\nSo we can ``factorize'' it to have\r\n$$\\left( \\frac{\\partial}{\\partial t}-c\\frac{\\partial}{\\partial x} \\right)\\left( \\frac{\\partial}{\\partial t}+c\\frac{\\partial}{\\partial x} \\right)y=0$$\r\nHence solutions can have $y_t\\pm cy_x=0$, so the solution is in the form $f(x+ct)+g(x-ct)$.\r\n\\begin{example}\r\n    Suppose we want to solve $y_{tt}-c^2y_{xx}=0$ and $y=1/(1+x^2),y_t=0$ at $t=0$ and $y\\to 0$ as $x\\to\\infty$.\r\n    So\r\n    $$\\begin{cases}\r\n        f(x)+g(x)=1/(1+x^2)\\\\\r\n        cf^\\prime(x)-cg^\\prime(x)=0\\implies f=g+A\r\n    \\end{cases}$$\r\n    for some constant $A$.\r\n    So we can solve to get\r\n    $$g(x)=\\frac{1}{2(1+x^2)}-\\frac{A}{2},f(x)=\\frac{1}{2(1+x^2)}+\\frac{A}{2}$$\r\n    So\r\n    $$y=\\frac{1}{2(1+(x+ct)^2)}+\\frac{1}{2(1+(x-ct)^2)}$$\r\n    We can sketch the solution to find that this gives two waves moving to the two ends.\r\n\\end{example}\r\n\\subsubsection{Diffusion Equation}\r\nWe consider\r\n$$\\frac{\\partial y}{\\partial t}=\\kappa\\frac{\\partial^2 y}{\\partial x^2}$$\r\nwhere $\\kappa$ is a constant.\r\nTypical cases where diffusion occurs are pollution transport, heat conduction and movement of microles.\r\nIntegrate the equation over $\\mathbb R$ to get\r\n$$\\frac{\\partial}{\\partial t}\\int_{-\\infty}^\\infty y\\,\\mathrm dx=\\kappa [y_x]^\\infty_{-\\infty}$$\r\nSo if $y_x\\to 0$ as $x\\to\\pm\\infty$, the integeral of $y$ over $\\mathbb R$ will be constant.\\\\\r\nWe can solve by the use of similarity variable.\r\n\\begin{example}\r\n    Consider $y_t=\\kappa y_{xx}$ where $y(x,0)=\\delta (x)$ and $y\\to 0$ when $x\\to\\pm\\infty$.\r\n    Define $\\eta=x^2/(4\\kappa t)$.\r\n    \\footnote{Obtained from dimensional analysis}\r\n    We can try solutions of the form $y=t^{-\\alpha}f(\\eta)$ to get\r\n    $$-\\frac{\\alpha}{t}+f^\\prime\\eta_t=\\kappa f^{\\prime\\prime}(\\eta_x)^2+\\kappa f^\\prime\\eta_{xx}$$\r\n    But note that $\\eta_t=-\\eta/t,\\eta_x=\\eta/(\\kappa t),\\eta_{xx}=2/(4\\kappa t)$.\r\n    All of the terms then have a factor of $1/t$, so we can remove the time dependence and get\r\n    $$\\alpha f+f^\\prime \\eta+f^{\\prime\\prime}\\eta+f^\\prime/2=0$$\r\n    Let $\\alpha=1/2$, we have $\\eta F^\\prime+F/2=0$ where $F=f+f^\\prime$.\r\n    If $F=0$ (which is a solution) then $f(\\eta)=Ae^{-\\eta}$.\r\n    Then $y=At^{-1/2}e^{-x^2/(4\\kappa t)}$, then from the delta function condition we have $A=1/\\sqrt{4\\pi\\kappa}$, hence\r\n    $$y(x,t)=\\frac{1}{\\sqrt{4\\pi\\kappa}}t^{-1/2}e^{-x^2/(4\\kappa t)}$$\r\n    is a solution.\r\n\\end{example}\r\n", "meta": {"hexsha": "51d002e759e9c92f62167993989b34dc444a77da", "size": 18287, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/multide.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": "6/multide.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": "6/multide.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": 46.8897435897, "max_line_length": 209, "alphanum_fraction": 0.634111664, "num_tokens": 6358, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256512199033, "lm_q2_score": 0.9059898248255074, "lm_q1q2_score": 0.7626854742823388}}
{"text": "\n\\subsection{Commutation}\n\nWe define a function, the commuter, between two objects \\(a\\) and \\(b\\) as:\n\n\\([a,b]=ab-ba\\)\n\nFor numbers, \\(ab-ba=0\\), however for matrices this is not generally true.\n\n\\subsection{Commutators and eigenvectors}\n\nConsider two matrices which share an eigenvector \\(v\\).\n\n\\(Av=\\lambda_A v\\)\n\n\\(Bv=\\lambda_B v\\)\n\nNow consider:\n\n\\(ABv=A\\lambda_B v\\)\n\n\\(ABv=\\lambda_A\\lambda_B v\\)\n\n\\(BAv=\\lambda_A\\lambda_B v\\)\n\nIf the matrices share all the same eigenvectors, then the matrices commute, and \\(AB=BA\\).\n\n", "meta": {"hexsha": "d905f38cafe1ed8c46ab099be19a3ecd3c1c3fae", "size": 526, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/linearSystems/04-01-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/algebra/linearSystems/04-01-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/algebra/linearSystemsOperations/04-01-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": 18.7857142857, "max_line_length": 90, "alphanum_fraction": 0.6996197719, "num_tokens": 158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7625703469967966}}
{"text": "\n\n\n\\section{Entropy from Noise Modeling}\n\\index{multiscale entropy}\n\\subsection{Information and wavelet coefficient}\nIn the case of signal restoration, the noise is the main problem. This \nmeans that we should not consider the probability of appearance of \na pixel value in an image, but rather its probability of being due to the\nsignal (or to the noise). \nIf we consider a variable $x$ which follows a probability distribution \n$p(x)$, we\ncan define the information in $x$ by $- \\ln(p(x))$, and a signal $S$ can\nbe considered as a set of individual variables $x_k$ (pixels), each of which \nfollows the same probability distribution. \nThen the information contained in the data \ncan be measured by $- \\sum_{k=1}^N \\ln(p(x_k))$. If $X$ follows a Gaussian \ndistribution with zero mean, we have\n\\begin{eqnarray}\nH(X) = \\sum_{k=1}^N \\frac{x_k^2}{2 \\sigma^2} + \\rm{Cst}\n\\end{eqnarray}\nThe energy gives a good measurement of information. But many of the required\ncriteria are not fulfilled by using such an entropy (correlation between \npixels, background-independence, etc.). It seems difficult to derive\na good probability distribution from the pixel values which fulfill the \nentropy requirements.\n\nThis is not so for transformed data, especially when using  \nthe wavelet transform. \nThis has  already been done, in fact,\nfor finding threshold levels in filtering \nmethods by means of wavelet coefficient thresholding \n\\cite{starck:sta95_1,rest:moulin99,rest:donoho93_1,rest:krim92,wave:chipman97,wave:amato97}. \nThus we must introduce the concept of multiresolution into our entropy.\nWe will now consider that the information contained in some dataset\nis the sum of the information at different resolution levels $j$.\nThe wavelet transform $W$ of a signal by a fast algorithm contains a set\nof coefficients $w_{j,k}$ ($j$ being the scale index), and a set \nof coefficients $c_{k}$ representing the signal at a very low resolution \n(see \\cite{ima:mallat98,starck:book98} for more information about the\nwavelet transform). If the number of scales is enough large,\nwe can assume that the coefficients $c_{k}$ furnish information only\nabout the background, and not on the signal of interest. The entropy of $X$\nmust be measured only from the\nwavelet coefficients $w_{j,k}$.\n\n% Choosing the \\`a trous wavelet transform (see \\cite{starck:sta95_1} \n% for a description of this wavelet transform algorithm), a signal $X$ can \n% be represented by:\n% \\begin{eqnarray}\n% X_k = \\sum_{j=1}^{l} w_{j,k} + c_{l,k}\n% \\end{eqnarray}\n% where $k$ is the pixel index, $w_j$ are the wavelet coefficients of $S$, \n% $j$ the resolution\n% level, and $c_l$ is smoothed version of $S$. \nDue to the properties of\nthe wavelet transform, the set $w_{j}$ for all $j$ has a zero mean. From \nnoise modeling, we can derive the probability distribution in the \nwavelet space of a wavelet coefficient, assuming it is due to the noise. \nThe entropy becomes\n\\begin{eqnarray}\nH(X) = \\sum_{j=1}^{l} \\sum_{k=1}^{N_j}  h(w_{j,k}) \n\\end{eqnarray}\nwith $h(w_{j,k})  = - \\ln p(w_{j,k})$. We will note in the following \n$h$ for the entropy (or information) relative to a wavelet coefficient, \nand $H$ for the multiscale entropy (MSE) of a signal or an image.\nFor Gaussian noise, we get\n\\begin{eqnarray}\nH(X) =  \\sum_{j=1}^{l}  \\sum_{k=1}^{N_j} \\frac{w_{j,k}^2}{2 \\sigma_j^2}+ \\rm{Cst}\n\\end{eqnarray}\nwhere $\\sigma_j$ is the noise at scale $j$. We see that \nthe information is proportional\nto the energy of the wavelet coefficients.\nThe higher a wavelet coefficient, then the lower will be the  probability, and the \nhigher will\nbe the information furnished by this wavelet coefficient. As the constant\nhas no effect in the solution calculation in restoration problems, \nwe take the liberty to remove it in the following. \n \nWe can see\neasily that this entropy fulfills all the requirements of \nsection~\\ref{sect_entr}.\nIf we consider two signals $S_1$, $S_2$, derived from a third one $S_0$ by \nadding noise:\n\\begin{eqnarray}\nS_1 & = & S_0 + N_1(\\sigma_1) \\nonumber \\\\ \nS_2 & = & S_0 + N_2(\\sigma_2)\n\\end{eqnarray}\nthen we have:\n\\begin{eqnarray}\n\\mbox{if } \\sigma_1 < \\sigma_2 \\mbox{ then } H(S_1) > H(S_2)\n\\end{eqnarray}\nand a flat image has zero entropy. \n\nOur entropy definition is completely dependent on the noise modeling.\nIf we consider a signal $S$, and we assume that the noise is Gaussian, with \na  standard deviation equal to $\\sigma$, we won't measure the same\ninformation compared to  the case when we consider that the noise has \nanother standard deviation\nvalue, or if the noise follows another distribution.\nAs for the Shannon\nentropy, the information increases with the entropy, and using such an\nentropy leads to a Minimum Entropy Method.\n\n\\begin{figure}[htb]\n\\centerline{\n\\hbox{\n\\psfig{figure=fig_multi_memscale.ps,bbllx=2.5cm,bblly=13cm,bburx=19.5cm,bbury=25.5cm,width=14cm,height=7cm,clip=}\n}}\n\\caption{Multiscale entropy of the saturn image (continuous curve), \nand multiscale\nentropy of the scrambled image (dashed curve).}\n\\label{fig_multi_memscale}\n\\end{figure}\nFigure~\\ref{fig_multi_memscale} shows the information measure at each\nscale for both the saturn image and its scrambled version. The global \ninformation is the addition of the information at each scale. We see\nthat for the scrambled image (dashed curve), the \ninformation-versus-scale \ncurve is flat, while for the unscrambled saturn image,\nit increases with the scale.  \n\n\\subsection{Signal information and noise information}\n\nIn the previous section, we have seen how it was possible to measure\nthe information $H$ related to a wavelet coefficient. \nAssuming the signal $X$ is still composed of the three elements $S$,$B$,$N$ \n(X=$S+F+B$, signal of interest, background, and noise),\n$H$ is independent of $B$. But some of this information \nis spurious and undesirable and has been introduced via the noise $N$. \nTo get the useful information, we must subtract out this spurious portion.\nTrying to decompose our information measure\ninto two components, one ($H_S$) corresponding to the non-corrupted part, and\nanother  ($H_N$) to the corrupted part, we have\n\\begin{eqnarray}\nH(X) = H_S(X) + H_N(X)\n\\end{eqnarray}\nWe will define in the following $H_S$ as the signal information, and $H_N$\nas the noise information. It must be clear that noise does not \ncontain any information, and what we call noise information is a quantity\nwhich is measured as information by the multiscale entropy, and which is \nprobably not informative to us.\n\nIf a wavelet coefficient is small, its value can be due to noise, \nand the information $h$ relative to this single wavelet coefficient\nshould be assigned to $H_N$.\nIf the wavelet coefficient is high, compared to the noise standard\ndeviation, its value cannot be due to the noise, and $h$ should be assigned to $H_S$.\n$h$ can be distributed as $H_N$ or $H_S$ based on  the probability $P_n(w_{j,k})$\nthat the wavelet coefficient is due to noise, or the probability \n$P_s(w_{j,k})$ that it is due to \nsignal.  We have $P_s(w_{j,k}) = 1 - P_n(w_{j,k})$. \nFor the Gaussian noise case, we estimate $P_n(w_{j,k})$ that a wavelet \ncoefficient is due to the noise by\n\\begin{eqnarray*}\nP_n(w_{j,k}) = \\mathrm{Prob}(W > \\mid w_{j,k} \\mid)  & =  & \\frac{2}{\\sqrt{2 \\pi} \n\\sigma_j} \\int_{\\mid w_{j,k} \\mid}^{+\\infty} \\exp(-W^2/2\\sigma^2_j) dW \\nonumber \\\\ \n & = & \\mbox{erfc}(\\frac{\\mid w_{j,k} \\mid }{\\sqrt{2}\\sigma_j})\n\\end{eqnarray*}\nFor each wavelet coefficient $w_{j,k}$, we have to estimate now the fractions\n$h_n$ and $h_s$ of $h$ which should be assigned to $H_n$ and $H_s$.\nHence  signal information and  noise information are defined by\n\\begin{eqnarray}\nH_s(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_s(w_{j,k})   \\nonumber  \\\\  \nH_n(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_n(w_{j,k})     \n\\label{eq_entrop_result_2}\n\\end{eqnarray}\nNote that $H_s(X) + H_n(X)$ is always equal to $H(X)$. \n\n\n\\subsubsection{N1-MSE}\nA first approach for deriving $h_s$ and $h_n$ from $P_s$ and $P_n$ is to\njust consider $P_s$ and $P_n$ as weights on the information $h$. Then we\nhave:\n\\begin{eqnarray}\nh_s( w_{j,k}) & = & P_s(w_{j,k})  h(w_{j,k})    \\nonumber \\\\  \nh_n( w_{j,k}) & = & P_n(w_{j,k})  h(w_{j,k})     \n\\label{eq_mse1}\n\\end{eqnarray}\nand the noise and signal information in a signal are\n\\begin{eqnarray}\nH_s(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_s(w_{j,k})    \\nonumber \\\\  \nH_n(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_n(w_{j,k})     \n\\label{eq_entrop_result_1}\n\\end{eqnarray}\nwhich leads for a Gaussian noise to:\n\\begin{eqnarray}\nH_s(X) &= & \\sum_{j=1}^{l}  \\sum_{k=1}^{N_j}  \\frac{w_{j,k}^2}{2\\sigma_j^2} \n\\mbox{erf}(\\frac{\\mid w_{j,k} \\mid }{\\sqrt{2}\\sigma_j}) \\nonumber \\\\ \nH_n(X) &= & \\sum_{j=1}^{l}  \\sum_{k=1}^{N_j}  \\frac{w_{j,k}^2}{2\\sigma_j^2} \n\\mbox{erfc}(\\frac{\\mid w_{j,k} \\mid }{\\sqrt{2}\\sigma_j}) \n\\label{eq_entrop_gauss_result_1} \n\\end{eqnarray}\nWe will refer to these functions by the name N1-MSE in the following.\n\n\\subsubsection{N2-MSE}\n\nBy the previous  entropy measure, information relative to high wavelet coefficients is  \ncompletely assigned to the signal. For a restoration, this allows us \nalso to exclude\nwavelet coefficients with high signal-to-noise ratio (SNR)\nfrom the regularization.\nIt leads to perfect fit of the solution with the data at scales and\n positions with high SNR. If we want to consider the information due\nto noise, even for significant wavelet coefficients, the noise information\nrelative to a wavelet coefficient must be estimated differently.\n The idea for deriving $h_s$ and $h_n$ is the following: we imagine that  the\ninformation $h$ relative to a wavelet coefficient \nis a sum of small information components $dh$, each of them\nhaving a probability of being noise information, or signal \ninformation \\cite{starck:sta98_2}. \nFor example, \nfor two coefficients  $u$ and  $w$ ($w > u$), with a Gaussian noise\n($\\sigma=1$), the information relative to $w$ is $h(w)=w^2$, and by\nvarying  $u$ from $0$  to $w$ with a step $du$, the information $h(u)$ \nincreases until it is equal to $h(w)$. \n When $u$ becomes closer to $w$,\nthe difference $w - u$ can be due to the noise, and the added information  \n$dh(u) = h(u+du) - h(u)$ is contaminated by the noise. The idea is to weight\n$dh(u)$ with the probability that $w - u$ is due to the noise.\nHence, $h_n$ and $h_n$ are calculated by:\n\\begin{eqnarray}\nh_n(w_{j,k}) =  \\int_{0}^{\\mid w_{j,k} \\mid } P_n(\\mid w_{j,k} \\mid - u) (\\frac{\\partial h(x)}{\\partial x})_{x=u} du\n\\end{eqnarray}\nis the noise information relative to a single wavelet coefficient, and \n\\begin{eqnarray}\nh_s(w_{j,k}) =  \\int_{0}^{\\mid w_{j,k} \\mid } P_s(\\mid w_{j,k} \\mid - u) \n                                   (\\frac{\\partial h(x)}{\\partial x})_{x=u} du\n\\end{eqnarray}\nis the signal information relative to a single wavelet coefficient. \nFor Gaussian noise, we have\n\\begin{eqnarray}\nh_n(w_{j,k}) & = &  \\frac{1}{\\sigma_j^2} \\int_{0}^{\\mid w_{j,k} \\mid} u \n         \\mbox{ erfc}(\\frac{\\mid w_{j,k} \\mid -u}{\\sqrt{2} \\sigma_j}) du \\nonumber \\\\\nh_s(w_{j,k}) & = &  \\frac{1}{\\sigma_j^2} \\int_{0}^{\\mid w_{j,k} \\mid} u \n         \\mbox{ erf}(\\frac{\\mid w_{j,k} \\mid -u}{\\sqrt{2} \\sigma_j})\n\\label{eqn_hn2}\n\\end{eqnarray}\nand the noise and signal information in a signal are\n\\begin{eqnarray}\nH_s(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_s(w_{j,k})   \\nonumber \\\\  \nH_n(X) & = & \\sum_{j=1}^{l} \\sum_{k=1}^{N_j} h_n(w_{j,k})     \n\\label{eq_entrop_gauss_result_2}\n\\end{eqnarray}\nWe will refer to these functions by the name N2-MSE in the following.\n\nEquations~\\ref{eq_mse1} and  %\\ref{eq_entrop_result_2} \n\\ref{eq_entrop_result_2}\nlead to two\ndifferent ways to regularize a signal. The first requires that we use\nall the information which is furnished in high wavelet coefficients, and \nleads to an exact preservation of the flux in a structure. If the signal\npresents high discontinuities, artifacts can appear in the solution \ndue to the fact that the wavelet coefficients located at the discontinuities\nare not noisy, but have been modified like noise. The second equation \ndoesn't have this drawback, but a part of the flux of a structure\n(compatible with noise amplitude) can be lost in the restoration process. \nIt is however not as effective as in the standard maximum entropy methods.\n\n\\subsubsection{LOG-MSE}\nThe multiscale entropy function used in \\cite{starck:pan96} (we call it LOG-MSE\nin the following) can be considered in our framework if $h$ is defined by:\n\\begin{eqnarray}\nh(w_{j,k}) = {\\sigma_j \\over \\sigma_X^2} [w_{j,k} - M_j - \n       \\mid w_{j,k} \\mid \\log( {\\mid w_{j,k} \\mid \\over K_m \\sigma_j})]\n\\label{eqn_logmse}\n\\end{eqnarray}\nwhere $\\sigma_X$ is the noise standard deviation in the data.\nAnd $h_n$ is defined by:\n\\begin{eqnarray}\nh_n(w_{j,k}) = A(p_n(w_{j,k})) h(w_{j,k})\n\\end{eqnarray}\nwhere $A$ is a function which takes the values 0 or 1 depending on $p_n(w_{j,k})$:\n\\begin{eqnarray}\nA(p_n(w_{j,k}))  = \\left\\{\n  \\begin{array}{ll}\n  \\mbox{ 1 } & \\mbox{ if }  p_n(w_{j,k}) > \\epsilon   \\\\\n  \\mbox{ 0 } & \\mbox{ if }  p_n(w_{j,k}) \\leq \\epsilon\n  \\end{array}\n  \\right.\n\\label{eqn_mressupp}\n\\end{eqnarray}\n\nWavelet coefficients which are significant will impose $A(p_n(w_{j,k}))$ to\nbe equal to 0 (because    their probabilities of being due to noise is \nvery small), and do not contribute to $H_n$. This means that using $H_n$ in\na regularization process will have an effect only on scales and positions\nwhere no significant wavelet coefficient is detected.\n\nIn practice we prefer N1-MSE and N2-MSE for several reasons. First the way\nthe model is used in equation~\\ref{eqn_logmse} is a bit artificial, and  \nthere is an undetermination when the wavelet coefficient is equal to 0.\nFurthermore, LOG-MSE seems difficult to generalize to other classes of noise,\nwhich is not the case for N1-MSE and N2-MSE. N2-MSE has the advantage of \nestimating the corrupted part in the measured information $h$, even for large\nwavelet coefficients.\n\n\n\\subsection{Conclusion}\n\nIn practice we prefer N1-MSE and N2-MSE for several reasons. First the way\nthe model is used in equation~\\ref{eqn_logmse} is a bit artificial, and  \nthere is an undetermination when the wavelet coefficient is equal to 0.\nFurthermore, LOG-MSE seems difficult to generalize to other classes of noise,\nwhich is not the case for N1-MSE and N2-MSE. N2-MSE has the advantage of \nestimating the corrupted part in the measured information $h$, even for large\nwavelet coefficients.\nConcerning the five points, cited in section~\\ref{sect_5pt}:\n\\begin{enumerate}\n\\item {\\em The information in a flat signal is zero}: \\\\\n It is true for N1-MSE and N2-MSE. IN the case of LOG-MSE, it is true\nif we take $\\sigma=0$.\n\\item {\\em The amount of information in a signal is independent \nof the background}: \\\\\nIt is always true because the last scale of the wavelet transform is\nnever taken into account in the entropy calculation.\n\\item {\\em The amount of information is dependent on the noise}: \\\\\nWhatever the method, it is normalized coefficients which are used, so it\nis always true.\n\\item {\\em The entropy must work in the same way for a pixel which\nhas a value $B + \\epsilon$, and\nfor a pixel which has a value $B - \\epsilon$}: \\\\\nFor N1-MSE and N2-MSE, it is true because the entropy is calculated\nfrom the absolute values or the square of the wavelet coefficients.\nFor LOG-MSE, this point is not verified because a $w_{j,k}$ appears.\nBut it has no effect on the solution, because it is the \nderivated of the entropy which is used in the calculations,\nand this term becomes constant.\n\\item {\\em The amount of information is dependent on the correlation in the signal.\nIf the signal $S$  presents large features above the noise, it contains\na lot of information}: \\\\\nAs the entropy is calculated from the wavelet coefficients, this point \nis always verified.\n\\end{enumerate}\n", "meta": {"hexsha": "614ca6ebdb56941a5c14798aa4eed96fae084d27", "size": 15787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/doc/doc_mra/doc_mr2/concept.tex", "max_stars_repo_name": "sfarrens/cosmostat", "max_stars_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/doc/doc_mra/doc_mr2/concept.tex", "max_issues_repo_name": "sfarrens/cosmostat", "max_issues_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/doc/doc_mra/doc_mr2/concept.tex", "max_forks_repo_name": "sfarrens/cosmostat", "max_forks_repo_head_hexsha": "a475315cda06dca346095a1e83cb6ad23979acae", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 47.1253731343, "max_line_length": 116, "alphanum_fraction": 0.7266738456, "num_tokens": 4765, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9381240194661944, "lm_q2_score": 0.8128673087708699, "lm_q1q2_score": 0.7625703469967966}}
{"text": "\\section{Unitary and hermitian matrices}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether a complex linear transformation is an\n    isometry and/or unitary.\n  \\item Determine whether a complex matrix is unitary.\n  \\item Determine whether a complex matrix is hermitian.\n  \\item Calculate the eigenvalues and eigenvectors of a hermitian\n    matrix.\n  \\item Compute an orthogonal basis of eigenvectors for a hermitian\n    matrix.\n  \\item Unitarily diagonalize a hermitian matrix. \n  \\end{enumerate}\n\\end{outcome}\n\nIn the context of real inner product spaces, we studied orthogonal\nfunctions, orthogonal matrices, and symmetric matrices. The\ncorresponding concepts in the context of complex inner product spaces\nare unitary functions, unitary matrices, and hermitian matrices. We\nwill introduce these concepts in this section. Since the proofs are\nsimilar to those in Section~\\ref{sec:orthogonal-matrices}, we omit\nmost of them.\n\n\\begin{definition}{Isometries and unitary maps of complex inner product spaces}{complex-isometries-unitary}\n  Let $V,W$ be complex inner product spaces. A linear transformation\n  $T:V\\to W$ is called an \\textbf{isometry}%\n  \\index{isometry}%\n  \\index{linear transformation!isometry} if for all\n  $\\vect{u},\\vect{v}\\in V$,\n  \\begin{equation*}\n    \\iprod{T(\\vect{u}),T(\\vect{v})} = \\iprod{\\vect{u},\\vect{v}}.\n  \\end{equation*}\n  An isometry that is also invertible is called a \\textbf{unitary\n    transformation}%\n  \\index{unitary transformation}%\n  \\index{linear transformation!unitary}, or simply \\textbf{unitary}.\n\\end{definition}\n\nIn the case of real inner product spaces, we found in\nProposition~\\ref{prop:matrix-orthogonal} that a square matrix $P$ is\nthe matrix of an orthogonal transformation (with respect to\northonormal bases) if and only if $P^TP=I$. In the complex case, we\nhave an analogous property, except that we must use the adjoint\ninstead of the transpose.\n\n\\begin{proposition}{The matrix of a unitary transformation}{matrix-unitary}\n  Let $T:V\\to W$ be a linear transformation between finite-dimensional\n  complex inner product spaces $V$ and $W$. Let $B$ and $C$ be\n  orthonormal bases of $V$ and $W$, respectively, and let\n  $P=\\coord{T}_{C,B}$ be the matrix of $T$ with respect to the bases\n  $B$ and $C$. Then\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $T$ is an isometry if and only if $P^{\\adjoint}P = I$.\n    \\item $T$ is unitary if and only if $P^{\\adjoint}P = I$ and\n      $\\dim V=\\dim W$.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\nThis motivates the following definition.  We therefore define a\n\\textbf{unitary}%\n\\index{unitary matrix} matrix to be an $n\\times n$-matrix satisfying\n$P^{\\adjoint}P=I$.\n\n\\begin{definition}{Unitary matrix}{unitary-matrix}\n  An $n\\times n$-matrix $P$ is called \\textbf{unitary}%\n  \\index{unitary matrix}%\n  \\index{matrix!unitary} if $P^{\\adjoint}P=I$.\n\\end{definition}\n\nWe have the following analogue of\nProposition~\\ref{prop:conditions-orthogonal-matrix}:\n\n\\begin{proposition}{Conditions for unitary matrices}{conditions-unitary-matrix}\n  The following are equivalent for a complex $n\\times n$-matrix $P$:\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item $P$ is unitary.\n    \\item $P^{\\adjoint}P=I$.\n    \\item $P$ is invertible and $P^{-1}=P^{\\adjoint}$.\n    \\item $PP^{\\adjoint}=I$.\n    \\item $P^{\\adjoint}$ is unitary.\n    \\item The columns of $P$ form an orthonormal set of vectors.\n    \\item The rows of $P$ form an orthonormal set of vectors.\n    \\end{enumerate}\n  \\end{enumialphparenastyle}\n\\end{proposition}\n\n\\begin{example}{Unitary matrices}{unitary-matrices}\n  Determine which of the following matrices are unitary.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & i \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\frac{1}{\\sqrt{2}}\n    \\begin{mymatrix}{rr}\n      1 & i \\\\\n      i & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\frac{1}{\\sqrt{2}}\n    \\begin{mymatrix}{rr}\n      1 & i \\\\\n      -i & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We have\n  \\begin{equation*}\n    A^{\\adjoint}A =\n    \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & -i \\\\\n    \\end{mymatrix}\\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & i \\\\\n    \\end{mymatrix}\n    = \\begin{mymatrix}{cc}\n      1 & 0 \\\\\n      0 & 1 \\\\\n    \\end{mymatrix}\n    = I,\n  \\end{equation*}\n  so $A$ is unitary. Similarly, we have\n  \\begin{equation*}\n    B^{\\adjoint}B =\n    \\frac{1}{2}\n    \\begin{mymatrix}{rr}\n      1 & i \\\\\n      i & 1 \\\\\n    \\end{mymatrix}\\begin{mymatrix}{rr}\n      1 & -i \\\\\n      -i & 1 \\\\\n    \\end{mymatrix}\n    = \\frac{1}{2}\n    \\begin{mymatrix}{rr}\n      2 & 0 \\\\\n      0 & 2 \\\\\n    \\end{mymatrix}\n    = I,\n  \\end{equation*}\n  so $B$ is unitary as well. On the other hand,\n  \\begin{equation*}\n    C^{\\adjoint}C =\n    \\frac{1}{2}\n    \\begin{mymatrix}{rr}\n      1 & i \\\\\n      -i & 1 \\\\\n    \\end{mymatrix}\\begin{mymatrix}{rr}\n      1 & i \\\\\n      -i & 1 \\\\\n    \\end{mymatrix}\n    = \\frac{1}{2}\n    \\begin{mymatrix}{rr}\n      2 & 2i \\\\\n      -2i & 2 \\\\\n    \\end{mymatrix}\n    \\neq I,\n  \\end{equation*}\n  so $C$ is not unitary. Equivalently, we could have checked whether\n  the columns of $A$, $B$, and $C$ form an orthonormal set of vectors\n  (they do, in the case of $A$ and $B$, but don't, in the case of\n  $C$. See also Example~\\ref{exa:orthogonal-vectors-complex}).\n\\end{solution}\n\nOf course, if $P$ happens to be a matrix with real entries, then $P$\nis unitary if and only if it is orthogonal, because in that case\n$P^{\\adjoint}=\\conjugate{P}^T = P^T$.\n\nRecall that a matrix $A$ is called \\textbf{symmetric} if $A=A^T$. In\nthe complex world, we are more often interested in the property\n$A=A^{\\adjoint}$. A matrix with this property is called\n\\textbf{hermitian} (after the French mathematician Charles Hermite,\n1822--1901).\n\n\\begin{definition}{Hermitian matrix}{hermitian-matrix}\n  A complex $n\\times n$-matrix $A$ is called \\textbf{hermitian}%\n  \\index{hermitian matrix}%\n  \\index{matrix!hermitian}\n  if $A=A^{\\adjoint}$.\n\\end{definition}\n\n\\begin{example}{Hermitian vs. symmetric matrices}{hermitian-matrix}\n  Which of the following matrices are hermitian? Which ones are\n  symmetric?\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc} 1 & 2 \\\\ 2 & 1 \\end{mymatrix}, \\quad\n    B = \\begin{mymatrix}{cc} 1 & 2i \\\\ 2i & 1 \\end{mymatrix}, \\quad\n    C = \\begin{mymatrix}{cc} 1 & 2i \\\\ -2i & 1 \\end{mymatrix}, \\quad\n    D = \\begin{mymatrix}{cc} i & 2 \\\\ 2 & i \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The matrix $A$ is symmetric and also hermitian. The matrix $B$ is\n  symmetric but not hermitian. In fact, we have\n  \\begin{equation*}\n    B^{\\adjoint} = \\begin{mymatrix}{cc} 1 & -2i \\\\ -2i & 1 \\end{mymatrix} \\neq B.\n  \\end{equation*}\n  The matrix $C$ is hermitian but not symmetric. The matrix $D$ is\n  symmetric but not hermitian.\n\\end{solution}\n\nA matrix $A=\\mat{a_{ij}}$ is hermitian if and only if\n$a_{ij} = \\conjugate{a_{ji}}$, for all $i,j$. In particular, the\ndiagonal entries of a hermitian matrix are always real, and the\noff-diagonal entries come in complex conjugate pairs. If all of the\nentries in a matrix $A$ are real, then $A$ is hermitian if and only if\nit is symmetric.\n\nHermitian matrices are of interest, among other things, because their\neigenvalues are always real. Moreover, eigenvectors for distinct\neigenvalues are orthogonal. The following proposition is analogous to\nProposition~\\ref{prop:eigenvalues-symmetric}.\n\n\\begin{proposition}{Eigenvalues and eigenvectors of hermitian matrices}{eigenvalues-hermitian}\n  Let $A$ be a hermitian matrix. Then\n  \\begin{enumialphparenastyle}\n    \\begin{enumerate}\n    \\item All eigenvalues of $A$ are real.\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 an eigenvalue of $A$, with eigenvector\n  $\\vect{v}$. We will evaluate $\\vect{v}^{\\adjoint}A\\vect{v}$ in two\n  different ways:\n  \\begin{eqnarray*}\n    \\vect{v}^{\\adjoint}A\\vect{v}\n    &=& \\vect{v}^{\\adjoint}(A\\vect{v})\n        = \\vect{v}^{\\adjoint}(\\eigenvar\\vect{v})\n        = \\eigenvar\\vect{v}^{\\adjoint}\\vect{v}, \\\\\n    \\vect{v}^{\\adjoint}A\\vect{v}\n    &=& (\\vect{v}^{\\adjoint}A)\\vect{v}\n        = (\\vect{v}^{\\adjoint}A^{\\adjoint})\\vect{v}\n        = (A\\vect{v})^{\\adjoint}\\vect{v}\n        = (\\eigenvar\\vect{v})^{\\adjoint}\\vect{v}\n        = \\conjugate{\\eigenvar}\\vect{v}^{\\adjoint}\\vect{v}.\n  \\end{eqnarray*}\n  Therefore,\n  $\\eigenvar\\vect{v}^{\\adjoint}\\vect{v} =\n  \\conjugate{\\eigenvar}\\vect{v}^{\\adjoint}\\vect{v}$. Since\n  $\\vect{v}^{\\adjoint}\\vect{v}$ is non-zero, this implies\n  $\\eigenvar=\\conjugate{\\eigenvar}$, i.e., $\\eigenvar$ is real.\n\n  \\noindent\n  (b) Suppose $\\vect{v}$ and $\\vect{w}$ are eigenvectors for\n  eigenvalues $\\eigenvarA$ and $\\eigenvarB$, respectively, and\n  $\\eigenvarA\\neq\\eigenvarB$. From part (a), we know that both\n  $\\eigenvarA$ and $\\eigenvarB$ are real.  By evaluating\n  $\\vect{v}^{\\adjoint}A\\vect{w}$ in two different ways, we find that\n  \\begin{eqnarray*}\n    \\vect{v}^{\\adjoint}A\\vect{w}\n    &=& \\vect{v}^{\\adjoint}(A\\vect{w})\n    = \\vect{v}^{\\adjoint}(\\eigenvarB\\vect{w})\n    = \\eigenvarB \\vect{v}^{\\adjoint}\\vect{w}, \\\\\n    \\vect{v}^{\\adjoint}A\\vect{w}\n    &=& (\\vect{v}^{\\adjoint}A)\\vect{w}\n    = (A^{\\adjoint}\\vect{v})^{\\adjoint}\\vect{w}\n    = (A\\vect{v})^{\\adjoint}\\vect{w}\n    = (\\eigenvarA\\vect{v})^{\\adjoint}\\vect{w}\n    = \\eigenvarA\\vect{v}^{\\adjoint}\\vect{w}.\n  \\end{eqnarray*}\n  Therefore,\n  $\\eigenvarB\\vect{v}^{\\adjoint}\\vect{w} = \\eigenvarA\\vect{v}^{\\adjoint}\\vect{w}$, or\n  equivalently $(\\eigenvarA - \\eigenvarB)\\vect{v}^{\\adjoint}\\vect{w} =\n  0$. Since by assumption, $\\eigenvarA - \\eigenvarB\\neq 0$, we must\n  have $\\vect{v}^{\\adjoint}\\vect{w} = 0$, i.e., $\\vect{v}\\orth\\vect{w}$.\n\\end{proof}\n\nWe say that a matrix $A$ is \\textbf{unitarily diagonalizable}%\n\\index{unitarily diagonalizable matrix}%\n\\index{diagonalizable matrix!unitarily diagonalizable}%\n\\index{diagonalization!unitary diagonalization}%\n\\index{matrix!unitarily diagonalizable}%\n\\index{matrix!diagonalizable!unitarily} if there exists a unitary\nmatrix $P$ and a diagonal matrix $D$ such that $D = P^{-1}AP$.  The\nfollowing is the main theorem about the diagonalization of hermitian\nmatrices. It is analogous to\nTheorem~\\ref{thm:diagonalization-symmetric} in the real case.\n\n\\begin{theorem}{Diagonalization of hermitian matrices}{diagonalization-hermitian}\n  Every hermitian matrix $A$ is unitarily diagonalizable as\n  $D = P^{-1}AP$. Moreover, the entries of $D$ are real.\n\\end{theorem}\n\n\\begin{example}{Diagonalization of hermitian matrices}{diagonalization-hermitian}\n  The matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{cc}  3 & -2i \\\\ 2i & 6 \\end{mymatrix}\n  \\end{equation*}\n  is hermitian. Unitarily diagonalize $A$, i.e., find a unitary matrix\n  $P$ and a real diagonal matrix $D$ such that $D = P^{-1}AP$.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is\n  \\begin{equation*}\n    \\det(A-\\eigenvar I)\n    = \\begin{absmatrix}{cc} 3-\\eigenvar & -2i \\\\ 2i & 6-\\eigenvar \\end{absmatrix}\n    = (3-\\eigenvar)(6-\\eigenvar) + 4i\\,^2\n    = \\eigenvar^2 - 9\\eigenvar + 14.\n  \\end{equation*}\n  Its roots are $\\eigenvar_1=2$ and $\\eigenvar_2=7$. For the eigenvalue\n  $\\eigenvar_1=2$, we find the normalized eigenvector\n  \\begin{equation*}\n    \\vect{v}_1 = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{c} 2i \\\\ 1 \\end{mymatrix}.\n  \\end{equation*}\n  For the eigenvalue\n  $\\eigenvar_2=7$, we find the normalized eigenvector\n  \\begin{equation*}\n    \\vect{v}_2 = \\frac{1}{\\sqrt{5}}\\begin{mymatrix}{c} 1 \\\\ 2i \\end{mymatrix}.\n  \\end{equation*}\n  Note that these eigenvectors are orthogonal to each other,\n  confirming Proposition~\\ref{prop:eigenvalues-hermitian}. We\n  therefore have $D=P^{-1}AP$, where\n  \\begin{equation*}\n    D = \\begin{mymatrix}{cc} 2 & 0 \\\\ 0 & 7 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    P = \\frac{1}{\\sqrt{5}} \\begin{mymatrix}{cc} 2i & 1 \\\\ 1 & 2i \\end{mymatrix}.\n  \\end{equation*}\n  Note that $P$ is unitary and $D$ is real diagonal.\n\\end{solution}\n", "meta": {"hexsha": "6d67a3bfb6cfd3187fc2c0477bbf6e47520cbcfa", "size": 12058, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/InnerProductSpaces-Unitary.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-Unitary.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-Unitary.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 36.3192771084, "max_line_length": 107, "alphanum_fraction": 0.6665284458, "num_tokens": 4241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473846343394, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7624989943567355}}
{"text": "\\section{Complex Functions}\n\n\\subsection{Analytic Functions}\n\n\\subsubsection{Exercise 4}\nLet $f(z) = u(z) + iv(z)$ with $\\abs{f(z)} = c$. Then we have that\n\\begin{align*}\n        &u^2(z) + v^2(z) = c^2 \\\\\n        \\implies &u(z) (\\pdv{u}{x} - \\pdv{u}{y}) + v(z) (\\pdv{v}{x} - \\pdv{v}{y}) = 0.\n\\end{align*}\nIf $u(z) = 0$ or $v(z) = 0$, then $f(z)$ is clearly a constant. Otherwise, both differences of partial \nderivatives must be 0. Applying Cauchy-Riemann then gives that $\\pdv{u}{x} = -\\pdv{u}{x}$ (and similar for\n$v(z)$), so $f(z)$ must also be constant in this case. \n\n\\subsubsection{Exercise 5}\nLet $f(z) = u(z) + iv(z)$. Then $\\overline{f(\\bar{z})} = u(\\bar{z}) - iv(\\bar{z})$, which we can write as\n$u(x, -y) - iv(x, -y)$. Differentiating with respect to $x$ and $y$, it is straightforward to check that\n$\\overline{f(\\bar{z})}$ satisfies Cauchy-Riemann and is therefore analytic if $f(z)$ is analytic.\n\n\\subsubsection{Exercise 6}\nSince $\\pdv{u}{y} \\pdv{y}{-y} = -\\pdv{u}{y}$, we have that $u'(x, y) = u(x, -y)$ satisfies $\\Delta u' = 0$ and\nis thus harmonic as well.\n\n\\subsubsection{Exercise 7}\nCan be shown by following the procedure outlined in the text; let $x = \\frac{1}{2} (z + \\bar{z})$ and\n$y = \\frac{-i}{2} (z - \\bar{z})$ and differentiate.\n\n\n", "meta": {"hexsha": "1430e765835997a533105346b4adfe9912aceb01", "size": 1258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Complex_Analysis_Ahlfors/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": "Complex_Analysis_Ahlfors/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": "Complex_Analysis_Ahlfors/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": 43.3793103448, "max_line_length": 110, "alphanum_fraction": 0.6144674086, "num_tokens": 476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772351648678, "lm_q2_score": 0.8723473813156294, "lm_q1q2_score": 0.762498987163678}}
{"text": "\\lab{Method of Mean Weighted Residuals}{Method of Mean Weighted Residuals}\n\\label{lab:pseudospectral1_revision}\n\\objective{We introduce the method of mean weighted residuals (MWR) and use it to derive a pseudospectral method. This method will then be used to solve several boundary value problems.}\n\nConsider a linear differential equation\n\\[Lu = f, \\]\ndefined on the interval $[-1,1]$, together with associated boundary conditions.\nWe will approximate the solution $u(x)$ by a linear combination of $N+1$ basis functions $\\phi_i$, so that\n\\[\nu(x) \\approx u_N(x) = \\sum_{i=0}^N a_i \\phi_i(x).\n\\]\nTo determine appropriate constants $a_i$, we then minimize the residual function\n\\[\nR(x,u_N) = Lu_N - f.\n\\]\nNote that $R(x,u) = Lu - f = 0$ for the true solution $u(x)$.\n\nThis general strategy is often called the method of mean weighted residuals (MWR method). The MWR method is a general framework that describes many other, more specific methods. These more specific methods come from differing approaches to minimizing the residual $R(x,u_N)$, and the choice of basis functions $\\phi_i$.\n\n\n\\section*{The Pseudospectral Method}\nThe pseudospectral or collocation method is obtained from the MWR method by forcing the residual function $R(x,u_N)$ to equal zero at $N+1$ points in $[-1,1]$, called collocation points.\nWhen done correctly, the pseudospectral method gives high accuracy and converges rapidly.\n\nWe will let the basis functions $\\phi_i$ be the Chebyshev polynomials, and the collocation points will be the Gauss-Lobatto points, $x_i = \\cos(\\pi i /N)$, $ i = 0, \\ldots, N$.\nThe appropriate solution $u_N$ may be represented with two equivalent forms.\nFirst, $u_N$ can be described with the first $N+1$ coefficients  $\\{a_i\\}_{i=0}^N$ of its expansion in the Chebyshev polynomials.\nSince $u_N$ is a polynomial of order $N$, it may be uniquely described by its values at the collocation points, that is, the unknown values  $\\{u_N(x_i)\\}_{i=0}^N$.\n\nThese equivalent forms satisfy\n\\begin{align}\n\tMA = F \\label{spectral1b:chebychev_expansion}\n\\end{align}\nand\n\\begin{align}\n\tLU &= F \\label{spectral1b:grid_point}\n\\end{align}\nwhere\n\\begin{align*}\n\tU_i &= u(x_i),\\\\\n\tA_i &= a_i,\\\\\n\tF_i &= f(x_i),\\\\\n\tL_{ij} &= \\left.(LC_j(x))\\right|_{x=x_i},\\\\\n\tM_{ij} &= \\left.(L\\phi_j(x))\\right|_{x=x_i}.\n\\end{align*}\n\nThe functions $C_j$ above are the 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*}\nThus, $u_N$ can also be expanded in the basis of the cardinal functions:\n\\begin{align*}\n\tu_N(x) &= \\sum_{j=0}^N u_N(x_j)C_j(x).\n\\end{align*}\n\nWhen $L = d/dx$, the matrix corresponding to equation \\eqref{spectral1b:grid_point} is given by\n\\begin{align*}\nL_{ij} &= \\frac{dC_j}{dx}(x_i) =\n\\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{align*}\nwhere $\\alpha_0 = \\alpha_N = 2,$ and $\\alpha_j = 1$ otherwise.\n\nThis matrix is often called the differentiation matrix ($D$), and can be used to piece together the matrix $L$ for more complicated differential operators.\nA stable, vectorized function to build the differentiation matrix is given below.\n\n\n\\begin{lstlisting}\nimport numpy as np\n\ndef cheb(N):\n\tx =  np.cos((np.pi/N)*np.linspace(0,N,N+1))\n\tx.shape = (N+1,1)\n\tlin = np.linspace(0,N,N+1)\n\tlin.shape = (N+1,1)\n\t\n\tc = np.ones((N+1,1))\n\tc[0], c[-1] = 2., 2.\n\tc = c*(-1.)**lin\n\tX = x*np.ones(N+1) # broadcast along 2nd dimension (columns)\n\t\n\tdX = X - X.T\n\t\n\tD = (c*(1./c).T)/(dX + np.eye(N+1))\n\tD  = D - np.diag(np.sum(D.T,axis=0))\n\tx.shape = (N+1,)\n\t# Here we return the differentiation matrix and the Chebyshev points,\n\t# numbered from x_0 = 1 to x_N = -1\n\treturn D, x\n\n\\end{lstlisting}\n\n\n\n\\section*{Using the Differentiation Matrix}\n\n\n\\begin{problem}\nUse the differentiation matrix to numerically approximate the derivative of $u(x) = e^{x}\\cos(6x)$ on a grid of $N$ Chebychev points where $N=6, 8,$ and $10.$\n(Use the linear system $D U \\approx U'$.)\nThen use barycentric interpolation to approximate $u'$ on a grid of 100 evenly spaced points.\n\nGraphically compare your approximation to the exact derivative.\nNote that this convergence would not be occurring if the collocation points were equally spaced.\n\\end{problem}\n\nTo approximate $u''(x)$ on the grid $\\{x_i\\}$, we use\n\\[U'' \\approx D^2 U.\\]\nThe BVP\n\\begin{align*}\n&{ }u'' = f(x), \\quad x \\in [-1,1],\\\\\n&{ }u(-1) = 0, \\quad u(1) = 0,\n\\end{align*}\ncan be discretized by the linear system\n\\begin{align}\n\tD^2 U &= F, \\label{spectral1b:discretization}\n\\end{align}\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$.\nThis is done by replacing the first and last equations in \\eqref{spectral1b:discretization} by the boundary conditions.\n% This 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},\\]\n% where $\\tilde{D} = D[1:N,1:N]$, $\\tilde{U} = U[1:N]$, and $\\tilde{F} = F[1:N]$.\n\n\n\\begin{problem}\nUse the pseudospectral method to solve the boundary value problem\n\\begin{align*}\n&{ } u'' = e^{2x}, \\quad x \\in [-1,1], \\\\\n&{ } u(-1) = 0, \\quad u(1) = 0.\n\\end{align*}\nCompare your numerical solution with the exact solution,\n\\[\nu(x) = \\frac{- \\cosh(2) - \\sinh(2)x + e^{2x}}{4}.\n\\]\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*}\n&{ } u'' + u' = e^{3x}, \\quad x \\in [-1,1], \\\\\n&{ } u(-1) = 2, \\quad u(1) = -1.\n\\end{align*}\n% Check that your numerical solution is converging.\n% How many subintervals are required to find the solution correct to three decimal places?\n% See Figure \\ref{fig:nonzeroDirichlet}.\n\t\n% Hint: 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\n\n\n\n\\section*{Minimizing the Area of a Surface of Revolution}\nA surface of revolution that minimizes its area is an example of a larger class of surfaces called minimal surfaces. A famous example of a minimal surface is a soap bubble. Soap bubbles minimize their surface area while containing a fixed volume of air. This behavior extends to merged bubbles, and a soap film whose boundary is a wire frame. Minimal surfaces have applications in molecular engineering and material science, and general relativity, where they describe the apparent horizon of a black hole.\n\nConsider a function $y(x)$ defined on $[-1,1]$ satisfying $y(-1) = a $, $y(1) = b. $ The area of the surface obtained by revolving the graph of $y(x)$ about the $x$-axis is given by\n\\[T[y(x)] = \\int_{-1}^1 2 \\pi y(x) \\sqrt{1 + (y'(x))^2}\\, dx .\\]\nTo find the function $y(x)$ whose surface of revolution minimizes surface area, we must minimize the functional $T[y]$.\nThis is a classical problem from a branch of mathematics called the calculus of variations.\nStandard derivatives allow us to find the minimum values of functions defined on $\\mathbb{R}^n$, and where they occur.\nThe calculus of variations allows us to find the minimum values of functions whose input are other functions.\n\nFrom the calculus of variations we know that a necessary condition for $y(x)$ to minimize $T[y]$ is that the Euler-Lagrange equation must be satisfied:\n\\begin{align*}\n\tL_y - \\frac{d}{dx}L_{y'} = 0,\n\\end{align*}\nwhere $L(x,y,y') = 2 \\pi y \\sqrt{1 + (y')^2}$.\nSimplifying the Euler-Lagrange equation for our problem results in the ODE\n\\[y y'' - (y')^2 -1 = 0.\\]\nDiscretizing this ODE using the pseudospectral method results in the (nonlinear) system of equations\n\\[\nY \\cdot (D^2 Y) - (DY) \\cdot (DY) = I,\n\\]\nwhere $I$ is a vector of ones.\n\n\\begin{problem}\nFind the function $y(x)$ that satisfies $y(-1) = 1$, $y(1) = 7$, and whose surface of revolution (about the $x$-axis) minimizes surface area.\nCompute the surface area, and plot the surface. \\label{prob:pseudospectral1_revision:minimal_surface}\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{minimal_surface.pdf}\n\\caption{The minimal surface corresponding to Problem  \\ref{prob:pseudospectral1_revision:minimal_surface}.}\n\\label{fig:pseudospectral1_revision:minimal_surface}\n\\end{figure}\n\n\n\n\n\n\n\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}\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "4b99a967f80175fbebdb834de2427c065bdaf622", "size": 11075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Spectral1/Spectral1b.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/Spectral1/Spectral1b.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/Spectral1/Spectral1b.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": 43.6023622047, "max_line_length": 506, "alphanum_fraction": 0.7097968397, "num_tokens": 3394, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7624989769518816}}
{"text": "\n\\subsection{Rings}\n\nConsider an abelian group \\((S,+)\\).\n\nA ring takes this and adds a multiplicative function which satisfies the distributive property.\n\nGroups have an identity element for their function. Rings must have identity elements for both their functions.\n\nThe multiplicative function does not have to be a bijection. For example the set of integers, addition and multiplication form a ring.\n\n", "meta": {"hexsha": "ed88bca2756945fc0c018028fb14af87a5b077c6", "size": 405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/rings/01-01-rings.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/01-01-rings.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/01-01-rings.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.75, "max_line_length": 134, "alphanum_fraction": 0.7950617284, "num_tokens": 81, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7624680140145174}}
{"text": "%\n% CMPT 310: Artificial Intelligence - A Course Overview\n% Section: Probability\n%\n% Author: Jeffrey Leung\n%\n\n\\section{Probability}\n\t\\label{sec:probability}\n\\subsection{Fundamentals of Probability}\n\t\\label{subsec:probability-fundamentals}\n\\begin{easylist}\n\n& Fundamentals:\n\t&& Continuous variable: Variable which can be any continuous value between two given points defining the domain\n\t\t&&& Uniform distribution: Variable which has a equal possibility of being any value in the domain\n\t&& Inverse of a probability: $P(a) = 1 - P(\\lnot a)$\n\t&& Probability of at least one of two events: $P(a \\lor b) = P(a) + P(b) - P(a \\land b)$\n\t&& Probability of both events: $P(a \\land b) = P(a, b) = P(a) + P(b) - P(a \\lor b)$\n\n& \\textbf{Factor/probability table:} Set of probabilities of all possible values of a specific set of random variables\n\t&& May not sum to 1 (in contrast with a probability table)\n\t\t&&& \\textbf{Normalization constant:} Value equaling the sum of the probabilities, by which every probability is divided by in order to reduce a probability function to a total probability of 1\n\t&& E.g. See figure~\\ref{sec:prob-table}.\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Example Probability Table}\n\t\\label{sec:prob-table}\n\t\\centering\n\t\\begin{tabular}{ r | c | c | c | c }\n\t\t& \\multicolumn{2}{ | c | }{Toothache} & \\multicolumn{2}{ | c }{$\\lnot$ Toothache} \\\\\n\t\t& Rough & $\\lnot$ Rough & Rough & $\\lnot$ Rough \\\\\n\t\t\\hline\n\t\tCavity & 0.108 & 0.012 & 0.072 & 0.008 \\\\\n\t\t\\hline\n\t\t$\\lnot$ Cavity & 0.016 & 0.064 & 0.144 & 0.578\n\t\\end{tabular}\n\\end{figure}\n\\begin{easylist}\n\n& \\textbf{Probabilistic inference:} Using previous information to compute specific probabilities\n\n& \\textbf{Conditional probability:} Probability of one event occurring given the guarantee of another event happening\n\t&& Notation: Probability of $a$ given $b = P(a|b) = \\frac{P(a, b)}{P(b)}$\n\t&& Inverted: $P(a \\land b) = P(a | b) \\times P(b)$\n\t&& \\textbf{Conditional Probability Table (CPT):} Probability table showing the probability of the query variable being true given all possible combinations of values of the condition variables\n\t\t&&& E.g. See figure~\\ref{fig:cpt-example}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Example of a Conditional Probability Table}\n\t\\label{fig:cpt-example}\n\t\\centering\n\t\\begin{tabular}{ c | c || c }\n\t\tA & B & P(C $\\vert$ A, B) \\\\\n\t\t\\hline\n\t\tT & T & 0.5 \\\\\n\t\tT & F & 0.14 \\\\\n\t\tF & T & 0.29 \\\\\n\t\tF & F & 0.001\n\t\\end{tabular}\n\\end{figure}\n\\begin{easylist}\n\n\t&& \\textbf{Query variable:} Variable for which the value is sought\n\t\t&&& E.g. For variables $A, B, C, D$ and the conditional probability $P(a|b, c)$, the query variable is $a$\n\t&& \\textbf{Evidence/condition variable:} Variable which is known\n\t\t&&& E.g. For variables $A, B, C, D$ and the conditional probability $P(a|b, c)$, the condition variables are $b, c$\n\t&& \\textbf{Hidden variable:} Variable which is unrelated and not included\n\t\t&&& E.g. For variables $A, B, C, D$ and the conditional probability $P(a|b, c)$, the hidden variable is $d$\n\n& \\textbf{Chain rule:} Derivation of the probability of two events:\n\n\t\\end{easylist}\n\t\\begin{align*}\n\tP(a, b) &= P(a) P(b|a) = P(b) P(a|b) \\\\\n\tP(x_1, \\dotsc, x_n) &= \\prod_{i=1}^n P(x_i | x_1, \\dotsc, x_{i-1})\n\t\\end{align*}\n\t\\begin{easylist}\n\n\t&& When conditional dependence is added:\n\t\\[\n\t\tP(a, b | c) &= P(a | c) P(b | a, c)\n\t\\]\n\n\t&& Derived from the formula for conditional probability\n\n& \\textbf{Bayes' Rule:} Equation which allows conditional probability calculation given the independent probabilities and inverse conditional probability\n\t\\[\n\t\tP(B | A) = \\frac{P(A | B) \\times P(B)}{P(A)}\n\t\\]\n\n\t&& $P(A | B)$: Causal probability (e.g. probability that symptoms occur given a disease is present)\n\t&& $P(B | A)$: Diagnostic probability (e.g. probability that a disease is present given the symptoms)\n\n\\end{easylist}\n\\begin{align*}\n\tP(A \\land B) &= P(A | B) \\times P(B) = P(B | A) \\times P(A) \\\\\n\tP(B | A) \\times P(B) &= P(A | B) \\times P(A) \\\\\n\tP(B | A) &= \\frac{P(A | B) \\times P(B)}{P(A)}\n\\end{align*}\n\\begin{easylist}\n\n& \\textbf{Joint probability distribution:} Probability model consisting of all the possible variables in a model\n\t&& Size: $d^n-1$ where $d$ = size of the domain, $n$ = number of variables\n\t&& Runtime: $O(d^n)$ where $d$ = size of the domain, $n$ = number of variables\n\t&& Requires all data (amount proportional to $d^n$) to create parameters beforehand\n\n& \\textbf{Marginalization/summing out:} Determining the probability of a variable from a joint probability distribution by adding up the probabilities for all values of other variables, effectively eliminating the other variables\n\t&& E.g. For variables $A, B, C$, $P(a, b) = P(a, b, c) + P(a, b, \\lnot c)$\n\n& \\textbf{Independence:} Property of two variables which do not rely on each other (i.e. knowing if one event occurred has no effect on the probability of the other event)\n\t&& Definition: $A, B$ are independent iff $P(A | B) = P(A)$ or $P(A, B) = P(A) P(B)$\n\t&& In a Bayesian network, two variables are dependent if they share a parent nodes (including themselves)\n& \\textbf{Conditional independence:} Property of two variables given a third variable where, if the third variable is known, then knowing if one event occurred has no effect on the probability of the other event\n\t&& Definition: $A, B$ are conditionally independent given C if $P(A, B|C) = P(A|C) P(B|C)$\n\t&& In a Bayesian network, two variables are conditiionally dependent if they share a child node (including themselves)\n\n\\end{easylist}\n\\subsection{Bayesian Networks}\n\t\\label{subsec:bayesian-networks}\n\\begin{easylist}\n\n& \\href{https://www.youtube.com/watch?v=VfyxPtlqZh4}{\\textbf{Bayesian Network:}} Acyclic digraph where each node (representing a variable) has a probability conditional on its parents\n\t&& Nodes represent random variables, directed edges represent conditional dependence\n\t&& Each node is independent of all nodes which do not share a child node with the original node\n\t&& Each node is conditionally independent of all nodes which are not its descendents\n\t&& Runtime: $O(n d^p (d-1))$ where $n$ = number of variables, $d$ = values in the domain, and $p$ = number of parents\n\t&& For an example, see figure~\\ref{fig:bay-net-example}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Example of a Bayesian Network}\n\t\\label{fig:bay-net-example}\n\t\\centering\n\t\\begin{tikzpicture}[\n\t\tnode distance=1cm and 0cm,\n\t\tbaynetnode/.style={draw, ellipse, text width=2cm, align=center}\n\t]\n\t\t\\node[baynetnode] (a) {Alarm};\n\t\t\\node[right=0.5cm of a]{\n\t\t\t\\begin{tabular}{ c | c || c }\n\t\t\t\tB & E & P(A $\\vert$ B, E) \\\\\n\t\t\t\t\\hline\n\t\t\t\tT & T & 0.95 \\\\\n\t\t\t\tT & F & 0.94 \\\\\n\t\t\t\tF & T & 0.29 \\\\\n\t\t\t\tF & F & 0.001\n\t\t\t\\end{tabular}\n\t\t};\n\t\t%\n\t\t\\node[baynetnode, above left=2.5cm of a] (b) {Burglary}\n\t\t\tedge [-latex] (a)\n\t\t\t;\n\t\t\\node[above=0.5cm of b]{\n\t\t\t\\begin{tabular}{ c }\n\t\t\t\tP(B) \\\\\n\t\t\t\t\\hline\n\t\t\t\t0.001\n\t\t\t\\end{tabular}\n\t\t};\n\t\t%\n\t\t\\node[baynetnode, above right=2.5cm of a] (e) {Earthquake}\n\t\t\tedge [-latex] (a)\n\t\t\t;\n\t\t\\node[above=0.5cm of e]{\n\t\t\t\\begin{tabular}{ c }\n\t\t\t\tP(E) \\\\\n\t\t\t\t\\hline\n\t\t\t\t0.002\n\t\t\t\\end{tabular}\n\t\t};\n\t\t%\n\t\t\\node[baynetnode, below left=2.5cm of a] (jc) {John calls}\n\t\t\tedge [latex-] (a)\n\t\t\t;\n\t\t\\node[below=0.5cm of jc]{\n\t\t\t\\begin{tabular}{ c || c }\n\t\t\t\tA & P(J $\\vert$ A) \\\\\n\t\t\t\t\\hline\n\t\t\t\tT & 0.9 \\\\\n\t\t\t\tF & 0.05\n\t\t\t\\end{tabular}\n\t\t};\n\t\t%\n\t\t\\node[baynetnode, below right=2.5cm of a] (mc) {Mary calls}\n\t\t\tedge [latex-] (a)\n\t\t\t;\n\t\t\\node[below=0.5cm of mc]{\n\t\t\t\\begin{tabular}{ c || c }\n\t\t\t\tA & P(M $\\vert$ A) \\\\\n\t\t\t\t\\hline\n\t\t\t\tT & 0.7 \\\\\n\t\t\t\tF & 0.01\n\t\t\t\\end{tabular}\n\t\t};\n\t\\end{tikzpicture}\n\\end{figure}\n\\begin{easylist}\n\n\\end{easylist}\n\\subsection{Exact Inference}\n\t\\label{subsec:exact-inference}\n\\begin{easylist}\n\n& \\textbf{Exact inference:} Methods of finding the exact probabilities of a specific solution to specific variables, through application of the chain rule to a probability distribution\n\t&& Runtime: Exponential\n\t&& Methods: Joint probability table, enumeration\n\t&& Equation:\n\t\\[\n\t\tP(x_1, \\dotsc, x_n) = \\prod_{i=1}^n P(x_i | parents(x_i))\n\t\\]\n\n& \\textbf{Factor multiplication:} Determining the probability of a specific solution to specific variables by multiplying together the probabilities of the relevant relationships in the Bayesian network\n\t&& E.g. Given the network in figure~\\ref{fig:bay-net-example}, to find the probabilities of the conditionally dependent variables $M, A, B, E$, see figure~\\ref{tab:factor-mult}\n\n\\end{easylist}\n\\begin{figure}[!htb]\n\t\\caption{Factor multiplication example}\n\t\\label{tab:factor-mult}\n\t\\centering\n\t\\begin{math}\n\t\t\\begin{array}{ c | c | c | c || c }\n\t\t\tM & A & B & E & \\textrm{Probability} \\\\\n\t\t\t\\hline\n\t\t\tm & a & b & e & P(m|a) P(a, b|e) \\\\\n\t\t\tm & a & b & \\lnot e & P(m|a) P(a, b|\\lnot e) \\\\\n\t\t\tm & a & \\lnot b & e & P(m|a) P(a, \\lnot b|e) \\\\\n\t\t\t\\vdots & \\vdots & \\vdots & \\vdots & \\vdots\n\t\t\\end{array}\n\t\\end{math}\n\\end{figure}\n\\begin{easylist}\n\n\t&& \\textbf{Inference by enumeration:} Determining the probability of a specific solution to all variables by multiplying together the probabilities of all relationships in the Bayesian network\n\t\t&&& E.g. Given the network in figure~\\ref{fig:bay-net-example}:\n\n\t\t\\end{easylist}\n\t\t\\begin{align*}\n\t\t\tP(b, \\lnot e, \\lnot a, j, \\lnot m)\n\t\t\t&= P(b) P(\\lnot e) P(\\lnot a \\vert b, \\lnot e) P(j \\vert \\lnot a) P(\\lnot m \\vert \\lnot a) \\\\\n\t\t\tP(B | j, m)\n\t\t\t&= \\alpha P(B) \\sum_e P(e) \\sum_a P(a | B, e) P(j|a) P(m|a) \\\\\n\t\t\t&= \\alpha P(B) \\sum_e P(e) \\bigg[\n\t\t\t\tP(a|B,e) P(j|a) P(m|a) +\n\t\t\t\tP(\\lnot a|B,e) P(j|\\lnot a) P(m|\\lnot a)\n\t\t\t\\bigg] \\\\\n\t\t\t&= \\alpha P(B) \\bigg[\n\t\t\t\tP(a|B,e) P(j|a) P(m|a) +\n\t\t\t\tP(\\lnot a|B,e) P(j|\\lnot a) P(m|\\lnot a) \\\\\n\t\t\t&+ \tP(a|B,\\lnot e) P(j|a) P(m|a) +\n\t\t\t\tP(\\lnot a|B,\\lnot e) P(j|\\lnot a) P(m|\\lnot a)\n\t\t\t\\bigg]\n\t\t\\end{align*}\n\t\t\\begin{easylist}\n\n\t&& Runtime: $O(n d^n)$ ($n$ probability tables, $d^n$ entries in the probability tables)\n\n& \\textbf{Inference by variable elimination:} Algorithm for efficiently executing inference by enumeration which combines relationships between probabilities and marginalizes out hidden variables to reduce factor size\n\t&& Order can affect runtime; prefer starting from nodes which have no parents\n\t&& Runtime: Exponential (worst-case) but often better than creating the entire table\n\t&& E.g. Given variables $A, B, C$, query and condition variables $A, B$, and factors $(C), (A,B,C)$, all factors involving hidden variable $C$ are collected and combined in the first iteration of the algorithm and $C$ is marginalized out to create the factor $A, B$\n\t&& E.g. Given the network in figure~\\ref{fig:bay-net-example}: (warning: expanded version is not actually correct)\n\n\t\\end{easylist}\n\t\\begin{align*}\n\t\tP(B | j, m)\n\t\t&= \\alpha P(B) \\sum_e P(e) \\sum_a P(a | B, e) P(j|a) P(m|a) \\\\[.5cm]\n\t\t\\textrm{Let } f_1(B, E, j, m)\n\t\t&= \\sum_a P(a | B, e) P(j|a) P(m|a) \\\\\n\t\t&= P(a | B, e) P(j|a) P(m|a) + P(\\lnot a | B, e) P(j|\\lnot a) P(m|\\lnot a) \\\\[.5cm]\n\t\tP(B | j, m)\n\t\t&= \\alpha P(B) \\sum_e P(e) f_1(B, E, j, m) \\\\[.5cm]\n\t\t\\textrm{Let } f_2(B, j, m)\n\t\t&= \\sum_e P(e) f_1(B, E, j, m) \\\\\n\t\t&= P(e) f_1(B, e, j, m) + P(\\lnot e) f_1(B, \\lnot e, j, m) \\\\[.5cm]\n\t\tP(B | j, m)\n\t\t&= \\alpha P(B) f_2(B, j, m) \\\\[1cm]\n\t\t\\textrm{Expanded: } P(B | j, m)\n\t\t&= P(B) f_2 (B, j, m) \\\\\n\t\t&= \\alpha P(B) \\Big[ P(e) f_1(B, e, j, m) + P(\\lnot e) f_1(B, \\lnot e, j, m) \\Big] \\\\\n\t\t&= \\alpha P(B) \\bigg\\{\n\t\t\tP(e) \\Big[\n\t\t\t\tP(a | B, e) P(j|a) P(m|a) +\n\t\t\t\tP(\\lnot a | B, e) P(j|\\lnot a) P(m|\\lnot a)\n\t\t\t\\Big] \\\\\n\t\t&+\tP(\\lnot e) \\Big[\n\t\t\t\tP(a | B, \\lnot e) P(j|a) P(m|a) +\n\t\t\t\tP(\\lnot a | B, \\lnot e) P(j|\\lnot a) P(m|\\lnot a)\n\t\t\t\\Big]\n\t\t\\bigg\\} \\\\\n\t\t&= \\alpha \\cdot 0.001 \\bigg\\{\n\t\t\t0.002 \\cdot \\Big[\n\t\t\t\t0.95 \\cdot 0.90 \\cdot 0.7 +\n\t\t\t\t0.05 \\cdot 0.05 \\cdot 0.01\n\t\t\t\\Big] \\\\\n\t\t&+\t0.998 \\Big[\n\t\t\t\t0.94 \\cdot 0.90 \\cdot 0.7 +\n\t\t\t\t0.06 \\cdot 0.05 \\cdot 0.01\n\t\t\t\\Big]\n\t\t\\bigg\\} \\\\\n\t\t&= \\begin{pmatrix} 0.284 \\\\ 0.716 \\end{pmatrix}\n\t\\end{align*}\n\t\\begin{easylist}\n\n\t&& Algorithm:\n\n\\begin{Verbatim}\nFUNCTION order(vars)\n\tRETURN vars in a specific order\nEND FUNCTION\n\nSET baynet to bayesian_network\nSET hidden to baynet.hidden_vars\nSET factors to baynet.factors_of_relationships\nFOR each var in order(hidden)\n\tSET current_factors to factors.find(f WHERE f contains var)\n\tREMOVE current_factors from factors\n\tSET combined_factors to product_of(current_factors)\n\tSET combined_factors to marginalize(combined_factors, var)\n\t# var no longer appears in any factor\n\tADD combined_factors to factors\n\tEND IF\nEND FOR\nRETURN factors\n\\end{Verbatim}\n\n\\end{easylist}\n\\subsection{Approximate Inference}\n\t\\label{subsec:approximate-inference}\n\\begin{easylist}\n\n& \\textbf{Approximate/sampling-based inference:} Methods of inferring the probabilities of a specific solution to specific variables by sampling to create an approximate solution\n\n& \\textbf{Rejection sampling:} Determining the approximate solution to specific variables by iterating through variables and for each, sampling the result of a probability multiple times (given all previous probabilities) and dividing the number of preferred results by the number of all results\n\t&& Parents must be processed before their children (i.e. topological ordering)\n\t&& Runtime: $O(NVD)$ where $N$ = number of samples, $V$ = number of variables, and $D$ = size of the domain\n\n& \\textbf{Gibbs sampling:} Determining the approximate solution to specific variables by fixing evidence variables, randomly assigning values to non-evidence variables, taking a non-evidence variable, sampling given the other assigned values, assigning the result, and repeating with another non-evidence variable\n\t&& Results converge to the probability\n\t&& \\textbf{Markov blanket:} The parents, children, and all parents of the children of a node, which the node is dependent on, and so the node is independent of all other variables\n\t&& \\textbf{Markov Chain Monte Carlo (MCMC) algorithm:} Algorithm which alters a solution, uses the solution to create a next state, and repeats\n\n\\end{easylist}\n\\subsection{Temporal Bayesian Networks}\n\t\\label{subsec:temporal-bayesian-networks}\n\\begin{easylist}\n\n& \\textbf{Temporal Bayesian Network:} Bayesian network where nodes represent the value of a variable at a specific time, and where each node may be a repeat of an antecedent node which represents the variable at a later time\n\t&& \\textbf{Tree width:} Number of edges crossed by a cut of the graph\n\n\\end{easylist}\n\\subsection{Markov Models}\n\t\\label{subsec:markov-models}\n\\begin{easylist}\n\n& \\textbf{Markov model:} State-change model which uses probabilities based on previous states\n\t&& Notation: $e_t: e_1, e_2, \\dotsc, e_n$ where $e_t$ = known evidence of the state of the model at time $t$\n\t&& \\textbf{First-order Markov model:} Markov model which depends only on the previous state (i.e. $P(x_t | x_{t-1})$)\n\t&& \\textbf{$n$\\textsuperscript{th}-order Markov model:} Markov model which depends on the previous $n$ states (i.e. \\\\ $P(x_t | x_{t-1}, \\dotsc, x_{t-n})$)\n\t&& \\textbf{Hidden Markov model:} Markov model which contains hidden states which are conditional upon evidence states\n\t\t&&& Notation: $P(x_t | e_{t-1}, e_{t-2}, \\dotsc)$ where $x_t =$ unknown state of the model at time $t$;\n\t\t\t&&&& \\textbf{Initial distribution:} $P(e_1)$\n\t\t\t&&&& \\textbf{Transition distribution:} $P(x_t | x_{t-1})$\n\t\t\t&&&& \\textbf{Emission distribution/corrector:} $P(e_t | x_t)$\n\t\t&&& For a diagram, see figure~\\ref{fig:hidden-markov-model}\n\n\t\t\\end{easylist}\n\t\t\\begin{figure}[!htb]\n\t\t\t\\caption{Diagram of a Hidden Markov Model}\n\t\t\t\\label{fig:hidden-markov-model}\n\t\t\t\\centering\n\t\t\t\\begin{tikzpicture}[\n\t\t\t\tnode distance=1cm and 0cm,\n\t\t\t\thmmnode/.style={draw, circle, minimum size=1cm, align=center}\n\t\t\t]\n\t\t\t\t\\node[hmmnode] (x1) {$x_1$};\n\t\t\t\t\\node[hmmnode, ->, below=1cm of x1] (e1) {$e_1$} edge [latex-] (x1);\n\t\t\t\t\\node[hmmnode, ->, right=1cm of x1] (x2) {$x_2$} edge [latex-] (x1);\n\t\t\t\t\\node[hmmnode, ->, below=1cm of x2] (e2) {$e_2$} edge [latex-] (x2);\n\t\t\t\t\\node[hmmnode, ->, right=1cm of x2] (ellipses) {$\\dotso$} edge [latex-] (x2);\n\t\t\t\t\\node[hmmnode, ->, right=1cm of ellipses] (xt-1) {$x_{t-1}$} edge [latex-] (ellipses);\n\t\t\t\t\\node[hmmnode, ->, below=1cm of xt-1] (et-1) {$e_{t-1}$} edge [latex-] (xt-1);\n\t\t\t\t\\node[hmmnode, ->, right=1cm of xt-1] (xt) {$x_t$} edge [latex-] (xt-1);\n\t\t\t\t\\node[hmmnode, ->, below=1cm of xt] (et) {$e_t$} edge [latex-] (xt);\n\t\t\t\\end{tikzpicture}\n\t\t\\end{figure}\n\t\t\\begin{easylist}\n\n& \\textbf{Filtering:} Method of hidden Markov model inference which finds an approximate hidden probability given evidences of all previous probabilities (i.e. finding $x_t$ given $e_{1:t}$)\n\t&& Derivation: Given $P(x_{t-1} | e_{1:t-1})$, find $P(x_t|e_{1:t})$. (See equation~\\ref{eq:filtering-deriv}.)\n\t\\end{easylist}\n\n\\begin{landscape}\n\t\\begin{figure}[!htb]\n\t\t\\caption{Derivation of Calculation for Filtering}\n\t\t\\label{eq:filtering-deriv}\n\t\t\\begin{align*}\n\t\t\tP(x_t | e_{1:t})\n\t\t\t&= P(x_t | e_{1:t-1}, e_t ) \\\\\n\t\t\t&= \\frac{1}{z} P(x_t, e_t | e_{1:t-1}) & \\textrm{Move } e_t \\textrm{ out of condition} \\\\\n\t\t\t&= \\frac{1}{z} \\sum_{x_{t-1}} P(x_{t-1}, x_t, e_t | e_{1:t-1}) & \\textrm{Reverse marginalization} \\\\\n\t\t\t&= \\frac{1}{z} \\sum_{x_{t-1}} P(x_{t-1}, x_t | e_{1:t-1}) \\cdot P(e_t | x_{t-1}, x_t, e_{1:t-1}) & \\textrm{Chain rule} \\\\\n\t\t\t&= \\frac{1}{z} \\sum_{x_{t-1}} P(x_{t-1} | e_{1:t-1}) \\cdot P(x_t | x_{t-1}, e_{1:t-1}) \\cdot P(e_t | x_{t-1}, x_t, e_{1:t-1}) & \\textrm{Chain rule} \\\\\n\t\t\t&= \\frac{1}{z} \\sum_{x_{t-1}} P(x_{t-1} | e_{1:t-1}) \\cdot P(x_t | x_{t-1}) \\cdot P(e_t | x_t) & \\textrm{Conditional independence} \\\\\n\t\t\t&= P(e_t | x_t) \\cdot \\frac{1}{z} \\sum_{x_{t-1}} P(x_{t-1} | e_{1:t-1}) \\cdot P(x_t | x_{t-1}) \\\\\n\t\t\t\\textrm{where } & P(e_t | x_t) \\textrm{ is the emission distribution,} \\\\\n\t\t\t& P(x_{t-1} | e_{1:t-1}) \\textrm{ is the provided probability and evidence, and} \\\\\n\t\t\t& P(x_t | x_{t-1}) \\textrm{ is the transition distribution.}\n\t\t\\end{align*}\n\t\\end{figure}\n\\end{landscape}\n\n\t\\begin{easylist}\n\n\t&& Runtime: $O(T D^2)$ where $T =$ number of time periods and $D =$ degree of the hidden variable\n\t&& Space complexity: $O(D)$ where $D =$ degree of the hidden variable\n\t\t&&& Only the last two time periods of probabilities of each degree is necessary\n\n& \\textbf{Smoothing (forward/backward algorithm):} Method of hidden Markov model inference which finds the approximated previous hidden probabilities given evidence of previous and future probabilities (i.e. finding $x_t$ given $e_{1:T}$ where $1 \\leq t < T$)\n\t&& Derivation: Given $e_{1:t}$, find $P(x_k | e_{1:t})$. (See equation~\\ref{eq:smoothing-deriv}.)\n\t\\end{easylist}\n\n\\begin{landscape}\n\t\\begin{figure}[!htb]\n\t\t\\caption{Derivation of Calculation for Smoothing}\n\t\t\\label{eq:smoothing-deriv}\n\t\t\\begin{align*}\n\t\t\tP(x_k | e_{1:t})\n\t\t\t&= \\frac{1}{z} P(x_k, e_{k+1:t} | e_{1:k}) & \\textrm{Chain rule} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot P(e_{k+1:t} | x_k, e_{1:k}) & \\textrm{Chain rule} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot P(e_{k+1:t} | x_k) & \\textrm{(Step 3) Conditional \tindependence} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot \\sum_{x_{k+1}} P(x_{k+1}, e_{k+1:t} | x_k) & \\textrm{Reverse marginalization} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot \\sum_{x_{k+1}} P(x_{k+1} | x_k) \\cdot P(e_{k+1:t} | x_{k+1}, x_k) & \\textrm{Chain rule} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot \\sum_{x_{k+1}} P(x_{k+1} | x_k) \\cdot P(e_{k+1:t} | x_{k+1}) & \\textrm{Conditional independence} \\\\\n\t\t\t&= \\frac{1}{z} P(x_k | e_{1:k}) \\cdot \\sum_{x_{k+1}} P(x_{k+1} | x_k) \\cdot P(e_{k+1} | x_{k+1}) \\cdot P(e_{k+2:t} | x_{k+1}) & \\textrm{Separating multiplied probabilities} \\\\\n\t\t\t\\textrm{where } & P(x_k | e_{1:k}) \\textrm{ can be found as the result of filtering,} \\\\\n\t\t\t& P(x_{k+1} | x_k) \\textrm{ is the transition distribution,} \\\\\n\t\t\t& P(e_{k+1} | x_{k+1}) \\textrm{ is the emission distribution, and} \\\\\n\t\t\t& P(e_{k+2:t} | x_{k+1}) \\textrm{ is recursively solved from Step 3.} \\\\\n\t\t\\end{align*}\n\t\\end{figure}\n\\end{landscape}\n\n\t\\begin{easylist}\n\n& \\textbf{Prediction:} Method of hidden Markov model inference which finds the approximated future hidden probabilities given evidence of all previous probabilities (i.e. finding $x_t$ given $e_{1:t-\\delta}$)\n\n& \\textbf{Most likely sequence of states:} Method of hidden Markov model inference which finds the most likely sequence of states given evidence of their probabilities (i.e. finding $\\underset{x_{1:t}}{arg \\, max} \\; P(x_{1:t} | e_{1:t})$, the most likely states $x_{1:t}$ given $e_{1:t}$)\n\t&& \\textbf{Viterbi algorithm:} Algorithm which finds the most likely sequence of states\n\t\t&&& Algorithm:\n\n\\begin{lstlisting}[breaklines=true, mathescape=true]\n# Initialize arrays\nSET vitr[num_observ][num_states] to [][]\nSET prev[num_observ][num_states] to [][]\n\nFOR each state from 1 to n\n\tSET vitr[0][state] to original_prob[state] × emission(state i, observation 0)\n\tSET prev[0][state] to 0\nEND FOR\n\n# For each observation and state\nFOR each observation current_observ from 1 to num_observ-1\n\tFOR each state current_state from 0 to num_states-1\n\n\t\t# Calculate all possible probabilities towards current state\n\t\tSET max_prob to 0\n\t\tFOR each prev_state from 0 to n-1\n\t\t\tSET prob to vitr[current_observ-1][prev_state] $\\times$ transition(prev_state, current_state) $\\times$ emission(current_state, current_observ)\n\t\t\tIF prob $>$ max_prob THEN\n\t\t\t\tSET max_prob to prob\n\t\t\tEND IF\n\t\tEND FOR\n\n\t\t# Set the max and argmax\n\t\tSET vitr[current_observ][current_state] to max_prob\n\t\tSET prev[current_observ][current_state] to vitr[current_observ].index(max_prob)\n\tEND FOR\nEND FOR\n\n# Trace back to find most likely sequence\nSET sequence to []\nSET current_state to vitr[current_observ].index(max(vitr[current_observ]))\nFOR each observation current_observ from t-1 to -1\n\tSET sequence to [current_state] + sequence\n\tSET current_state to prev[current_observ][current_state]\nEND FOR\n\nRETURN sequence\n\\end{lstlisting}\n\n\\end{easylist}\n\\clearpage\n", "meta": {"hexsha": "6479c964b00ce6c309fb34dbb16b8240d168a887", "size": 21783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cmpt-310-artificial-intelligence-survey/course-overview/tex/probability.tex", "max_stars_repo_name": "AmirNaghibi/notes", "max_stars_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 25, "max_stars_repo_stars_event_min_datetime": "2019-08-11T08:45:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-09T02:37:39.000Z", "max_issues_repo_path": "cmpt-310-artificial-intelligence-survey/course-overview/tex/probability.tex", "max_issues_repo_name": "AmirNaghibi/notes", "max_issues_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cmpt-310-artificial-intelligence-survey/course-overview/tex/probability.tex", "max_forks_repo_name": "AmirNaghibi/notes", "max_forks_repo_head_hexsha": "c4640bbcb65c94b8756ccc3e4c1bbc7d5c3f8e92", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-18T09:17:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-27T21:44:56.000Z", "avg_line_length": 43.9173387097, "max_line_length": 313, "alphanum_fraction": 0.6643253914, "num_tokens": 7580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899666, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.7624577757502411}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n \\ln n}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\r\n\\subsection*{Solution}\r\n\r\nThe function $f(x)=\\frac{1}{x \\ln x}$ is continuous, positive, and decreasing on $[3,\\infty)$. We consider the integral\r\n\\[ \\int_3^\\infty \\frac{1}{x \\ln x}\\,dx = \\lim_{t \\to \\infty} \\int_3^t \\frac{1}{x \\ln x}\\,dx.\\]\r\nWe do the indefinite integral using the substitution $u= \\ln x$, so $du = \\frac1x\\,dx$:\r\n\\[\r\n\\int \\frac{1}{x \\ln x}\\,dx\r\n= \\int \\frac1u\\,du = \\ln |u| + C = \\ln | \\ln (x) | + C\r\n\\]\r\nso, back to the improper integral,\r\n\\begin{align*}\r\n\\int_3^\\infty \\frac1{x \\ln x}\\,dx \r\n&= \\lim_{t \\to \\infty} \\int_3^t \\frac1{x\\ln x}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty}\\left[   \\ln | \\ln (t) |  -  \\ln | \\ln (3) |  \\right] \\\\\r\n&= \\infty.\r\n\\end{align*}\r\nSince the integral $\\displaystyle  \\int_3^\\infty \\frac{1}{x \\ln x}\\,dx$ diverges, the series  $\\displaystyle \\sum_{n=3}^\\infty \\frac{1}{n \\ln n}$ diverges by the Integral Test. So the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{1}{n \\ln n}$ diverges as well.\r\n\r\n\r\n\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\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": "ea9089fccb15953252bd281a9c6a7d0111963f0b", "size": 1748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/e2.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/e2.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/e2.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.6153846154, "max_line_length": 261, "alphanum_fraction": 0.6172768879, "num_tokens": 645, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757869948899665, "lm_q2_score": 0.8705972717658209, "lm_q1q2_score": 0.7624577683991918}}
{"text": "\\section{Cylindrical and Spherical Coordinates}\\label{sec:CylSphCoords}\n\nWe have seen that sometimes double integrals are simplified by doing\nthem in polar coordinates; not surprisingly, triple integrals are\nsometimes simpler in cylindrical coordinates or spherical coordinates.\nTo set up integrals in polar coordinates, we had to understand the\nshape and area of a typical small region into which the region of\nintegration was divided. We need to do the same thing here, for three\ndimensional regions.\\index{cylindrical coordinates!triple integral}\\index{spherical coordinates!triple integral}\n\nThe cylindrical coordinate system is the simplest, since it is just\nthe polar coordinate system plus a $z$ coordinate. A typical small\nunit of volume is the shape shown in Figure~\\ref{fig:polarcoordinatesregions}\n``fattened up'' in the $z$ direction, so its\nvolume is $r\\Delta r\\Delta \\theta\\Delta z$, or in the limit, \n$r\\,dr\\,d\\theta\\,dz$. \n\n\\begin{example}{Finding Volume}{FindVolumeExample}\nFind the volume under $z=\\sqrt{4-r^2}$ \nabove the quarter circle inside $x^2+y^2=4$\nin the first quadrant.\n\\end{example}\n\\begin{solution}\nWe could of course do this with a double integral, but we'll use a\ntriple integral:\n$$\\int_0^{\\pi/2}\\int_0^2\\int_0^{\\sqrt{4-r^2}} r\\,dz\\,dr\\,d\\theta=\n\\int_0^{\\pi/2}\\int_0^2 \\sqrt{4-r^2}\\; r\\,dr\\,d\\theta=\n{4\\pi\\over3}.$$\nCompare this to Example~\\ref{exa:integrationinpolarcoordinates}.\n\\end{solution}\n\n\\begin{example}{Mass using Cylindrical Coordinates}{MassCylCoords}\nAn object occupies the space inside both the cylinder\n$x^2+y^2=1$ and the sphere $x^2+y^2+z^2=4$, and has density $x^2$ at\n$(x,y,z)$. Find the total mass.\n\\end{example}\n\\begin{solution}\nWe set this up in cylindrical coordinates, recalling that\n$x=r\\cos\\theta$: \n\\begin{align*}\n\\int_0^{2\\pi}\\int_0^1\\int_{-\\sqrt{4-r^2}}^{\\sqrt{4-r^2}}\nr^3\\cos^2(\\theta)\\,dz\\,dr\\,d\\theta\n&=\\int_0^{2\\pi}\\int_0^1 2\\sqrt{4-r^2}\\;r^3\\cos^2(\\theta)\\,dr\\,d\\theta\t\\\\\n&=\\int_0^{2\\pi}\\left({128\\over15}-{22\\over5}\\sqrt3\\right)\\cos^2(\\theta)\\,d\\theta\t\\\\\n&=\\left({128\\over15}-{22\\over5}\\sqrt3\\right)\\pi\n\\end{align*}\n\\end{solution}\n\nSpherical coordinates are somewhat more difficult to understand. The\nsmall volume we want will be defined by $\\Delta\\rho$, $\\Delta\\phi$,\nand $\\Delta\\theta$, as pictured in Figure~\\ref{fig:sphericalvolumeunit}.\nThe small volume is nearly box shaped, with 4 flat sides and two sides\nformed from bits of concentric spheres. When $\\Delta\\rho$, $\\Delta\\phi$,\nand $\\Delta\\theta$ are all very small, the volume of this little\nregion will be nearly the volume we get by treating it as a box.\nOne dimension of the box is simply $\\Delta\\rho$, the change in distance\nfrom the origin. The other two dimensions are the lengths of small\ncircular arcs, so they are $r\\Delta\\alpha$ for some suitable\n$r$ and $\\alpha$, just as in the polar coordinates case.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1.5truecm,1.5truecm>\n\\setplotarea x from 0 to 2.1, y from -1.1 to 1.1\n\\put {\\hbox{\\epsfxsize9cm\\epsfbox{images/spherical_volume_unit.eps}}} at 0 0\n\\endpicture}}\n\\caption{A small unit of volume for spherical coordinates.}\n\\label{fig:sphericalvolumeunit}\n\\end{figure}\n\nThe easiest of these to understand is the arc corresponding to a\nchange in $\\phi$, which is nearly identical to the derivation for\npolar coordinates, as shown in the left graph in Figure~\\ref{fig:intspherical}.\nIn that graph we are looking ``face on'' at the side of\nthe box we are interested in, so the small angle pictured is\nprecisely $\\Delta\\phi$, the vertical axis really is the $z$ axis, but\nthe horizontal axis is \\emph{not} a real axis---it is just some line\nin the $x$-$y$ plane.\nBecause the other arc is governed by $\\theta$, we need\nto imagine looking straight down the $z$ axis, so that the apparent\nangle we see is $\\Delta\\theta$. In this view, the axes really are the\n$x$ and $y$ axes.\nIn this graph, the apparent distance from the\norigin is not $\\rho$ but $\\rho\\sin\\phi$, as indicated in the left\ngraph. \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 3.5, y from 0 to 3\n\\axis left  /\n\\axis bottom  /\n\\circulararc 15 degrees from 3.17 1.48 center at 0 0\n\\circulararc 15 degrees from 2.266 1.057 center at 0 0\n\\setlinear\n\\plot 3.17 1.48 0 0 2.68 2.25 /\n\\betweenarrows {$\\rho\\sin\\phi$} [t] <0pt,-3pt> from 0 0 to 3.17 0\n\\setdashes\n\\plot 3.17 1.48 3.17 0 /\n\\put {$z$} [b] <0pt,3pt> at 0 3\n\\put {$\\Delta \\rho$} [tl] <0pt,-3pt> at 2.72 1.27\n\\put {$\\rho\\Delta \\phi$} [bl] <2pt,2pt> at 2.95 1.88\n\\put {$\\Delta\\phi$} at 1.01 0.645\n\\setsolid\n\\setcoordinatesystem units <1.5truecm,1.5truecm> point at -5 0\n\\setplotarea x from 0 to 3.5, y from 0 to 3\n\\axis left  /\n\\axis bottom  /\n\\circulararc 15 degrees from 2.87 1.34 center at 0 0\n\\circulararc 15 degrees from 2.05 0.955 center at 0 0\n\\setlinear\n\\plot 2.87 1.34 0 0 2.43 2.04 /\n\\put {$x$} [l] <3pt,0pt> at 3.5 0\n\\put {$y$} [b] <0pt,3pt> at 0 3\n\\put {$\\rho\\sin\\phi\\Delta \\theta$} [bl] <2pt,2pt> at 2.67 1.7\n\\put {$\\Delta\\theta$} at 1.01 0.645\n\\endpicture}}\n\\caption{Setting up integration in spherical coordinates.}\n\\label{fig:intspherical}\n\\end{figure}\n\nThe upshot is that the volume of the little box is approximately\n$\\Delta\\rho(\\rho\\Delta\\phi)(\\rho\\sin\\phi\\Delta\\theta)\n=\\rho^2\\sin\\phi\\Delta\\rho\\Delta\\phi\\Delta\\theta$, or in the limit\n$\\rho^2\\sin\\phi\\,d\\rho\\,d\\phi\\,d\\theta$.\n\n\\begin{example}{Average Temperature in a Unit Sphere}{AvgTempUnitSphere}\nSuppose the temperature at $(x,y,z)$ is\n$T=1/(1+x^2+y^2+z^2)$. Find the average temperature in the unit sphere\ncentered at the origin.\n\\end{example}\n\\begin{solution}\nIn two dimensions we add up the temperature at ``each'' point and\ndivide by the area; here we add up the temperatures and divide by the\nvolume, $(4/3)\\pi$:\n\\[{3\\over4\\pi}\\int_{-1}^1\\int_{-\\sqrt{1-x^2}}^{\\sqrt{1-x^2}}\n\\int_{-\\sqrt{1-x^2-y^2}}^{\\sqrt{1-x^2-y^2}}\n{1\\over1+x^2+y^2+z^2}\\,dz\\,dy\\,dx\\]\nThis looks quite messy; since everything in the problem is closely\nrelated to a sphere, we'll convert to spherical coordinates.\n\\[{3\\over4\\pi}\\int_0^{2\\pi}\\int_0^\\pi\\int_0^1{1\\over1+\\rho^2}\\,\\rho^2\\sin\\phi\\,d\\rho\\,d\\phi\\,d\\theta\n={3\\over4\\pi}(4\\pi -\\pi^2)=3-{3\\pi\\over4}.\\]\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:CylSphCoords}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{0}^{1}\\int_{0}^{x}\\int_{0}^{\\sqrt{x^2+y^2}}\n{(x^2+y^2)^{3/2}\\over x^2+y^2+z^2}\\,dz\\,dy\\,dx$.\n\\begin{sol}\n$\\pi/12$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int_{-1}^{1}\\int_{0}^{\\sqrt{1-x^2}}\n\\int_{\\sqrt{x^2+y^2}}^{\\sqrt{2-x^2-y^2}}\\sqrt{x^2+y^2+z^2}\\,dz\\,dy\\,dx$.\n\\begin{sol}\n$\\pi(1-\\sqrt2/2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int x^2\\,dV$\nover the interior of the cylinder $x^2+y^2=1$ between $z=0$ and $z=5$.\n\\begin{sol}\n$5\\pi/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int xy\\,dV$\nover the interior of the cylinder $x^2+y^2=1$ between $z=0$ and $z=5$.\n\\begin{sol}\n$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int z\\,dV$\nover the region above the $x$-$y$ plane, inside $x^2+y^2-2x=0$ and\nunder $x^2+y^2+z^2=4$.\n\\begin{sol}\n$5\\pi/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int yz\\,dV$\nover the region in the first octant, inside $x^2+y^2-2x=0$ and \nunder $x^2+y^2+z^2=4$.\n\\begin{sol}\n$4/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int x^2+y^2\\,dV$\nover the interior of $x^2+y^2+z^2=4$.\n\\begin{sol}\n$256\\pi/15$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\int\\int\\int \\sqrt{x^2+y^2}\\,dV$\nover the interior of $x^2+y^2+z^2=4$.\n\\begin{sol}\n$4\\pi^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute $\\ds\\int\\int\\int\nx+y+z\\,dV$ over the region inside\n$x^2+y^2+z^2 = 1$ in the first octant.\n\\begin{sol}\n$\\ds {3\\pi\\over16}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the mass of a right circular cone of height $h$ and\nbase radius $a$ if the density is proportional to the distance from\nthe base.\n\\begin{sol}\n$\\pi kh^2a^2/12$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the mass of a right circular cone of height $h$ and\nbase radius $a$ if the density is proportional to the distance from\nits axis of symmetry.\n\\begin{sol}\n$\\pi kha^3/6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the region inside the unit sphere at the\norigin, and has density equal to the distance from the $x$-axis. Find\nthe mass.\n\\begin{sol}\n$\\pi^2/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the region inside the unit sphere at the\norigin, and has density equal to the square of the distance from the\norigin. Find the mass.\n\\begin{sol}\n$4\\pi/5$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the region between the unit sphere at the\norigin and a sphere of radius 2 with center at the origin, and has\ndensity equal to the distance from the origin. Find the mass.\n\\begin{sol}\n$15\\pi$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nAn object occupies the region in the first octant bounded by\nthe cones $\\phi = \\pi/4$ and $\\phi = \\arctan 2$, and the sphere $\\rho\n= \\sqrt{6}$, and has density proportional to the distance from the\norigin. Find the mass.\n\\begin{sol}\n$9k\\pi(5\\sqrt2-2\\sqrt5)/20$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "68c469379813d9cb5bb8327c8c6d81e5e8143e1d", "size": 9205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-6-cyl-sph-coords.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-6-cyl-sph-coords.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-6-cyl-sph-coords.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.0731707317, "max_line_length": 112, "alphanum_fraction": 0.7025529603, "num_tokens": 3356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.847967769904032, "lm_q2_score": 0.8991213813246445, "lm_q1q2_score": 0.7624259525948915}}
{"text": "\\subsection{Real convergence}\\label{subsec:real_convergence}\n\n\\begin{theorem}[Bolzano-Weierstrass]\\label{def:bolzano_weierstrass}\n  Every bounded sequence in \\( \\BbbR \\) has a \\hyperref[def:net_convergence/limit]{convergent} \\hyperref[def:sequence]{subsequence}.\n\\end{theorem}\n\\begin{proof}\n  Let \\( \\{ x_k \\}_{k=1}^\\infty \\) be a bounded sequence in \\( \\BbbR \\) and let \\( a \\leq b \\) be a lower and upper \\hyperref[def:partially_ordered_set_extremal_points/upper_and_lower_bounds]{bound}, respectively. Construct the sequence \\( \\{ F_k \\}_{k=1}^\\infty \\) of closed intervals as follows: define \\( \\alpha_1 \\coloneqq a \\) and \\( \\beta_1 \\coloneqq b \\) and, at step \\( k = 1, 2, \\ldots \\), put\n  \\begin{balign*}\n    F_k \\coloneqq \\begin{cases}\n      [\\alpha_k, \\tfrac{\\alpha_k+\\beta_k} 2], & [\\alpha_k, \\tfrac{\\alpha_k+\\beta_k} 2]\\text{ contains infinitely many sequence members}, \\\\\n      [\\tfrac{\\alpha_k+\\beta_k} 2, \\beta_k],  & \\text{otherwise}.\n    \\end{cases}\n  \\end{balign*}\n\n  Then put \\( \\alpha_{k+1} \\) and \\( \\beta_{k+1} \\) to be the endpoints of the interval \\( F_k \\) and repeat with \\( k+1 \\) instead of \\( k \\). Note that for any \\( k = 1, 2, \\ldots \\), \\( \\diam(F_k) = \\tfrac 1 2 \\diam(F_{k-1}) \\), thus \\( \\diam(F_k) \\xrightarrow[k \\to \\infty]{} 0 \\). As in \\fullref{thm:cantors_nested_compact_theorem}, it follows that if we choose a sequence\n  \\begin{equation*}\n    x_k \\in F_k, k = 1, 2, \\ldots,\n  \\end{equation*}\n  it will be a fundamental sequence. Since the space is complete, this fundamental sequence necessarily converges.\n\\end{proof}\n\n\\begin{theorem}\\label{def:set_of_real_numbers_complete_metric_space}\n  The metric space \\( \\BbbR \\) is complete.\n\\end{theorem}\n\\begin{proof}\n  Let \\( \\{ x_k \\}_{k=1}^\\infty \\) be a fundamental sequence of real numbers. By \\fullref{thm:fundamental_sequence_is_bounded}, the sequence is bounded. By \\fullref{def:bolzano_weierstrass}, it has a convergent subsequence\n  \\begin{equation*}\n    \\{ x_{k_m} \\}_{m=1}^\\infty \\to x.\n  \\end{equation*}\n\n  By \\fullref{thm:fundamental_subsequence_convergence}, the sequence itself has the same limit \\( \\lim_{k \\to \\infty} x_k = x \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:one_sided_squeeze_lemma}\n  Fix two convergent sequences \\( \\{ x_k \\}_{k=1}^\\infty \\) and \\( \\{ y_k \\}_{k=1}^\\infty \\) of real numbers.\n\n  If \\( x_k \\leq y_k \\) for all \\( k = 1, 2, \\ldots \\), then\n  \\begin{equation*}\n    \\lim_{k \\to \\infty} x_k \\leq \\lim_{k \\to \\infty} y_k.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Denote the respective limits by \\( x \\) and \\( y \\).\n\n  Fix \\( \\varepsilon > 0 \\). Then by \\fullref{def:net_convergence/limit}, there exist indices \\( k_0 \\) and \\( m_0 \\) such that\n  \\begin{balign*}\n     & \\abs{x - x_k} < \\frac \\varepsilon 2 \\quad\\forall k \\geq k_0 \\\\\n     & \\abs{y - y_m} < \\frac \\varepsilon 2 \\quad\\forall m \\geq m_0\n  \\end{balign*}\n\n  Take \\( k \\geq \\max \\{ k_0, m_0 \\} \\). Then \\( y_k \\geq x_k \\) and\n  \\begin{balign*}\n    y - x\n     & =\n    (y - y_k) + (y_k - x_k) + (x_k - x)\n    \\geq \\\\ &\\geq\n    (y - y_k) + (x - x_k)\n    >    \\\\ &>\n    - \\frac \\varepsilon 2 - \\frac \\varepsilon 2\n    =\n    - \\varepsilon.\n  \\end{balign*}\n\n  Since \\( \\varepsilon \\) was chosen arbitrary, \\( y - x \\) cannot equal any negative number, because otherwise we could choose another \\( \\varepsilon \\) smaller than the magnitude of the negative number and obtain a contradiction.\n\n  Thus, \\( y \\geq x \\).\n\\end{proof}\n\n\\begin{lemma}[Squeeze lemma]\\label{thm:squeeze_lemma}\n  Let \\( I \\) be a closed \\hyperref[def:partially_ordered_set_interval/closed]{interval} in \\( \\BbbR \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:squeeze_lemma/sequences} Let \\( \\{ x_k \\}_{k=1}^\\infty, \\{ x_k^- \\}_{k=1}^\\infty, \\{ x_k^+ \\}_{k=1}^\\infty \\) be three sequences in \\( I \\). If both \\( \\{ x_k^- \\}_{k=1}^\\infty \\) and \\( \\{ x_k^+ \\}_{k=1}^\\infty \\) converge to the same value \\( \\overline x \\in I \\) and if the following inequalities\n    \\begin{equation*}\n      x_k^- \\leq x_k \\leq x_k^+\n    \\end{equation*}\n    hold for all \\( k = 1, 2, \\ldots \\), then the \\enquote{squeezed in} sequence \\( \\{ x_k \\}_{k=1}^\\infty \\) also converges to \\( \\overline x \\).\n\n    \\thmitem{thm:squeeze_lemma/functions} Let \\( f, f_-, f_+: I \\to \\BbbR \\) be three functions and let \\( \\overline x \\in I \\). If both limits \\( \\lim_{x \\to \\overline x} f_-(x) \\) and \\( \\lim_{x \\to \\overline x} f_+(x) \\) converge to the same value \\( \\overline y \\in \\BbbR \\) and if the following inequalities\n    \\begin{equation*}\n      f_-(x) \\leq f(x) \\leq f_+(x)\n    \\end{equation*}\n    hold for all \\( x \\in I \\), then the \\enquote{squeezed in} function \\( f \\) also converges to \\( \\overline y \\) at \\( \\overline x \\).\n  \\end{thmenum}\n\\end{lemma}\n\\begin{proof}\n  \\SubProofOf{thm:squeeze_lemma/sequences} Fix \\( \\varepsilon > 0 \\). Then by \\fullref{def:net_convergence/limit}, there exist indices \\( k^- \\) and \\( k^+ \\) such that\n  \\begin{balign*}\n     & \\abs{\\overline x - x_k^-} < \\frac \\varepsilon 3 \\quad\\forall k \\geq k^- \\\\\n     & \\abs{\\overline x - x_k^+} < \\frac \\varepsilon 3 \\quad\\forall k \\geq k^+\n  \\end{balign*}\n\n  By taking \\( k \\geq \\max \\{ k^-, k^+ \\} \\), we obtain\n  \\begin{equation*}\n    \\abs{x_k^+ - x_k^-} \\leq \\abs{x_k^+ - \\overline x} + \\abs{\\overline x - x_k^-} < \\frac 2 3 \\varepsilon.\n  \\end{equation*}\n\n  Since \\( \\abs{x_k^+ - x_k} \\leq \\abs{x_k^+ - x_k^-} \\), it follows that \\( \\abs{x_k^+ - x_k} < \\frac 2 3 \\varepsilon \\).\n\n  Thus,\n  \\begin{equation*}\n    \\abs{\\overline x - x_k} \\leq \\abs{\\overline x - x_k^+} + \\abs{x_k^+ - x_k} < \\varepsilon.\n  \\end{equation*}\n\n  \\Fullref{def:net_convergence/limit} is satisfied, hence \\( \\{ x_k \\} \\) converges to \\( \\overline x \\).\n\n  \\SubProofOf{thm:squeeze_lemma/functions} The proof is analogous to that of \\fullref{thm:squeeze_lemma/sequences}, but the machinery is different. Fix \\( \\varepsilon > 0 \\). Then by \\fullref{def:local_convergence/neighborhoods}, there exist radii \\( \\delta^- \\) and \\( \\delta^+ \\) such that\n  \\begin{balign*}\n     & f_-(I \\cap B(\\overline x, \\delta^-)) \\subseteq B(\\overline y, \\tfrac \\varepsilon 3) \\\\\n     & f_+(I \\cap B(\\overline x, \\delta^+)) \\subseteq B(\\overline y, \\tfrac \\varepsilon 3)\n  \\end{balign*}\n\n  Take \\( \\delta < \\min \\{ \\delta^-, \\delta^+ \\} \\) and \\( x \\in I \\cap B(\\overline x, \\delta) \\). Analogously to the proof of \\fullref{thm:squeeze_lemma/sequences}, we obtain the inequality\n  \\begin{equation*}\n    \\abs{f(x) - \\overline x} \\leq \\abs{f(x) - f^-(x)} + \\abs{f^-(x) - \\overline x} < \\varepsilon.\n  \\end{equation*}\n\n  We conclude that\n  \\begin{equation*}\n    f(I \\cap B(\\overline x, \\delta)) \\subseteq B(\\overline y, \\varepsilon)\n  \\end{equation*}\n  holds and thus by \\fullref{def:local_convergence/neighborhoods}, the function \\( f \\) converges to \\( \\overline y \\) at \\( \\overline x \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:real_monotone_sequence_converges_iff_bounded}\n  A \\hyperref[def:partially_ordered_set/homomorphism]{monotone} sequence of real numbers \\hyperref[def:net_convergence/limit]{converges} if and only if it is \\hyperref[def:metric_space/bounded_sequence]{bounded}.\n\\end{proposition}\n\\begin{proof}\n  \\SufficiencySubProof Let \\( \\{ x_k \\}_{k=1}^\\infty \\) be a convergent monotone sequence. Denote its limit by \\( x \\). Fix \\( \\varepsilon > 0 \\). By \\fullref{def:net_convergence/limit}, there exists \\( k_0 \\) such that\n  \\begin{equation*}\n    \\abs{x - x_k} < \\varepsilon \\quad\\forall k \\geq k_0.\n  \\end{equation*}\n\n  Thus, \\( \\{ x_k \\colon k \\geq k_0 \\} \\subseteq B(x, \\varepsilon) \\).\n\n  Also note that\n  \\begin{equation*}\n    \\{ x_k \\colon k < k_0 \\} \\subseteq B(x, \\max_{i < k_0} \\{ \\abs{x - x_k} \\}).\n  \\end{equation*}\n\n  We obtained that the entire sequence\n  \\begin{equation*}\n    \\{ x_k \\colon k \\geq 1 \\} = \\{ x_k \\colon k < k_0 \\} \\cup \\{ x_k \\colon k \\geq k_0 \\}\n  \\end{equation*}\n  is contained in a union of two balls and is therefore bounded.\n\n  \\NecessitySubProof Now let \\( \\{ x_k \\}_{k=1}^\\infty \\) be a bounded monotone sequence. Denote its supremum by \\( \\alpha \\). Note that\n  \\begin{equation*}\n    \\abs{x_n - x_m} = x_n - x_m \\leq \\alpha \\quad\\forall n \\geq m.\n  \\end{equation*}\n\n  Fix \\( \\varepsilon > 0 \\). Then there exists at least one element \\( x_{m_0} > \\alpha - \\varepsilon \\) because otherwise \\( \\alpha \\) would not be a supremum.\n\n  Then for any index \\( n \\geq m_0 \\) we have\n  \\begin{equation*}\n    \\abs{x_n - x_{m_0}} = x_n - x_{m_0} < \\alpha - (\\alpha - \\varepsilon) = \\varepsilon.\n  \\end{equation*}\n\n  Thus, \\fullref{def:net_convergence/limit} is satisfied and the sequence \\( \\{ x_k \\}_{k=1}^\\infty \\) converges.\n\\end{proof}\n", "meta": {"hexsha": "68d0079f7d950b202103b6497b1e4ed58eaacadc", "size": 8559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/real_convergence.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/real_convergence.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/real_convergence.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.1614906832, "max_line_length": 402, "alphanum_fraction": 0.6382754995, "num_tokens": 3155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677430095496, "lm_q2_score": 0.89912137659416, "lm_q1q2_score": 0.7624259244021891}}
{"text": "\\subsection{Green's Theorem for Flux}\r\n\\begin{theorem}[Green's Theorem from Flux]\r\n\tLet $C$ be a closed, counter-clockwise oriented curve in $\\mathbb{R}^2$ and let $D$ be the region contained within $C$. For any differentiable vector field $\\vec{F}(x,y)$,\r\n\t\\begin{equation*}\r\n\t\t\\iint\\limits_{D}{\\nabla \\cdot \\vec{f}\\mathrm{d}A} = \\oint\\limits_{C}{\\vec{F} \\cdot \\hat{n}\\mathrm{d}s}\r\n\t\\end{equation*}\r\n\\end{theorem}\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nThis is saying that the sum of the divergence within $D$ is equal to the flux through $C$.\\\\\r\nOur intuition for this is that divergence is the tendency for integral curves of $\\vec{F}$ to spread out, and flux would then be these integral curves crossing the boundary curve $C$.\\\\\r\n\r\n\\noindent\r\nThis ability to convert between a line integral and surface integral often makes flux problems easier to solve. For example, one would have to calculate four integrals to find the flux through a rectangular region, but only a single double integral over the simple interior region.", "meta": {"hexsha": "fd0d96e473708d94706e0c33b01e205c656874f8", "size": 1022, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/greensTheoremFlux.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/greensTheoremFlux.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/greensTheoremFlux.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 63.875, "max_line_length": 281, "alphanum_fraction": 0.7397260274, "num_tokens": 273, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026528034426, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7624097226595726}}
{"text": "\\section{Methodology}\n\\label{sec:methodology}\n\n\\subsection{Fundamentals of magnetic equivalent layer and the positive magnetic-moment distribution}\n\\label{subsec:mag_eqlayer}\n\nLet $\\Delta T(x, y, z)$ be the total-field anomaly produced by a set of magnetic\nsources at a point $(x, y, z)$ referred to a topocentric Cartesian coordinate system \nwith $x$-, $y$- and $z$-axis being oriented to north, east and down, respectively.\nConsider that the main geomagnetic field has a constant inclination $I_{0}$ and declination\n$D_{0}$ throughout the study area, so that its direction can be defined by the unit vector\n\\begin{equation}\n\\hat{\\mathbf{F}}_{0} = \\begin{bmatrix}\n\\cos I_{0} \\cos D_{0} \\\\\n\\cos I_{0} \\sin D_{0} \\\\\n\\sin I_{0}\n\\end{bmatrix} \\: .\n\\label{eq:main_field}\n\\end{equation}\nAdditionally, consider that the magnetic sources have a constant total magnetization \ndirection defined by the unit vector\n\\begin{equation}\n\\hat{\\mathbf{m}}(\\mathbf{q}) = \\begin{bmatrix}\n\\cos {I} \\cos {D} \\\\\n\\cos {I} \\sin {D} \\\\\n\\sin {I}\n\\end{bmatrix} \\: ,\n\\label{eq:mag_vec}\n\\end{equation}\nwhere the constants $I$ and $D$ represent its inclination and declination, respectively,\nand $\\mathbf{q}$ is a $2 \\times 1$ vector given by:\n\\begin{equation}\n\\mathbf{q} = \\begin{bmatrix}\nI \\\\ \nD\n\\end{bmatrix} \\: .\n\\label{eq:q_vector}\n\\end{equation}\nFor convenience, we call $\\mathbf{q}$ as magnetization direction vector.\nIn this case, the total-field anomaly $\\Delta T(x, y, z)$ can be written as follows:\n\\begin{equation}\n\\Delta T(x, y, z) = \\hat{\\mathbf{F}}_{0}^{\\top} \\mathbf{M}(x, y, z) \\: \n\\hat{\\mathbf{m}}(\\mathbf{q}) \\: ,\n\\label{eq:tfanomaly}\n\\end{equation}\nwhere $\\mathbf{M}(x, y, z)$ is a matrix given by\n\\begin{equation}\n\t\\mathbf{M}(x, y, z) = \\begin{bmatrix}\n\t\t\\partial_{xx} \\Gamma(x, y, z) & \n\t\t\\partial_{xy} \\Gamma(x, y, z) &\n\t\t\\partial_{xz} \\Gamma(x, y, z) \\\\\n\t\t\\partial_{xy} \\Gamma(x, y, z) & \n\t\t\\partial_{yy} \\Gamma(x, y, z) &\n\t\t\\partial_{yz} \\Gamma(x, y, z) \\\\\n\t\t\\partial_{xz} \\Gamma(x, y, z) & \n\t\t\\partial_{yz} \\Gamma(x, y, z) &\n\t\t\\partial_{zz} \\Gamma(x, y, z)\n\t\\end{bmatrix} \\: ,\n\t\\label{eq:M-matrix}\n\\end{equation}\nwith elements\n$\\partial_{\\alpha\\beta} \\Gamma(x, y, z) \\equiv \n\\frac{\\partial^{2} \\Gamma(x, y, z)}{\\partial \\alpha \\partial \\beta}$, \n$\\alpha, \\beta = x, y, z$, representing the second derivatives of the harmonic\nfunction\n\\begin{equation}\n\\Gamma(x, y, z) = \\gamma_{m} \\, \\iiint\\limits_{\\upsilon} \n\\frac{m(x^{\\prime}, y^{\\prime}, z^{\\prime}) \\: d\\upsilon^{\\prime}}\n{\\left[ (x-x^{\\prime})^2 + (y-y^{\\prime})^2 + (z-z^{\\prime})^2 \\right]^{\\frac{1}{2}}} \\: .\n\\label{eq:Gamma-volume-integral}\n\\end{equation}\nIn this equation, $\\gamma_{m} = 10^{-9} \\frac{\\mu_{0}}{4 \\pi}$ (in H/m), \n$\\mu_{0}$ is the vacuum magnetic permeability and \n$x^{\\prime}$, $y^{\\prime}$ and $z^{\\prime}$ are the coordinates \nof the volume element $d \\upsilon^{\\prime}$, which has total-magnetization intensity\n$m(x^{\\prime}, y^{\\prime}, z^{\\prime})$ (in A/m) and is located within the \nvolume $\\upsilon$ of the magnetic sources.\nWe consider that the total-magnetization intensity $m(x^{\\prime}, y^{\\prime}, z^{\\prime})$\nis strictly positive at all points within the magnetic sources. Consequently,\n$\\Gamma(x, y, z)$ is positive at all points located outside the magnetic sources.\nFrom the mathematical point of view, $\\mathbf{M}(x, y, z)$ (equation \\ref{eq:M-matrix})\nand $\\Gamma(x, y, z)$ (equation \\ref{eq:Gamma-volume-integral}) resemble, respectively, \nthe gradient tensor and the corresponding pseudo-gravitational potential that would be produced by the magnetic sources, at the point $(x, y, z)$, if they had a density distribution proportional \nto $m(x^{\\prime}, y^{\\prime}, z^{\\prime})$.\nNotice that $\\mathbf{M}(x, y, z)$ is symmetric, its trace is identically zero at all points \n$(x, y, z)$ outside the magnetic sources and it has five independent components that are \nthemselves harmonic functions \\citep{pedersen_rasmussen1990}.\nBy exploring these properties, we can conveniently rewrite the \ntotal-field anomaly $\\Delta T(x, y, z)$ (equation \\ref{eq:tfanomaly}) as a linear combination \nof five independent harmonic functions as follows:\n\\begin{equation}\n\t\\begin{split}\n\t\t\\Delta T(x, y, z) = \\:\n\t\t& a_{xx} \\, \\partial_{xx} \\Gamma(x, y, z) + \n\t\ta_{xy} \\, \\partial_{xy} \\Gamma(x, y, z) + \n\t\ta_{xz} \\, \\partial_{xz} \\Gamma(x, y, z) + \\\\\n\t\t& a_{yy} \\, \\partial_{yy} \\Gamma(x, y, z) + \n\t\ta_{yz} \\, \\partial_{yz} \\Gamma(x, y, z)\n\t\\end{split} \\quad ,\n\t\\label{eq:tfanomaly-alternative}\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\begin{split}\n\t\ta_{xx} &= m_{x} F_{x} - m_{z} F_{z} \\\\\n\t\ta_{xy} &= m_{x} F_{y} + m_{y} F_{x} \\\\\n\t\ta_{xz} &= m_{x} F_{z} + m_{z} F_{x} \\\\\n\t\ta_{yy} &= m_{y} F_{y} - m_{z} F_{z} \\\\\n\t\ta_{yz} &= m_{y} F_{z} + m_{z} F_{y}\n\t\\end{split}\n\\label{eq:a-coefficients}\n\\end{equation}\nare constants defined by the elements $F_{\\alpha}$ and $m_{\\beta}$, \n$\\alpha = x, y, z$, $\\beta = x, y, z$, \nof the vectors $\\hat{\\mathbf{F}}_{0}$ (equation \\ref{eq:main_field}) and\n$\\hat{\\mathbf{m}}(\\mathbf{q})$ (equation \\ref{eq:mag_vec}), respectively.\nFor simplicity, we have omitted the dependence on the \nparameters $I_{0}$ and $D_{0}$ (equation \\ref{eq:main_field}) and \n$I$ and $D$ (equation \\ref{eq:mag_vec}).\n\nLet $\\Delta \\tilde{T}(x, y, z)$ be the total-field anomaly produced by a \ncontinuous layer of dipoles that have constant magnetization direction defined by\nthe unit vector $\\hat{\\mathbf{m}}(\\mathbf{q})$ (equation \\ref{eq:q_vector})\nand are located at the constant depth $z_{c}$. The total-field anomaly produced\nby this fictitious layer may be defined as\n\\begin{equation}\n\t\\Delta \\tilde{T}(x, y, z) = \\hat{\\mathbf{F}}_{0}^{\\top} \n\t\\tilde{\\mathbf{M}}(x, y, z) \\: \\hat{\\mathbf{m}}(\\mathbf{q}) \\: ,\n\t\\label{eq:tfanomaly-eqlayer}\n\\end{equation}\nwhere $\\tilde{\\mathbf{M}}(x, y, z)$ is a matrix given by\n\\begin{equation}\n\t\\tilde{\\mathbf{M}}(x, y, z) = \\begin{bmatrix}\n\t\t\\partial_{xx} \\Phi(x, y, z) & \n\t\t\\partial_{xy} \\Phi(x, y, z) &\n\t\t\\partial_{xz} \\Phi(x, y, z) \\\\\n\t\t\\partial_{xy} \\Phi(x, y, z) & \n\t\t\\partial_{yy} \\Phi(x, y, z) &\n\t\t\\partial_{yz} \\Phi(x, y, z) \\\\\n\t\t\\partial_{xz} \\Phi(x, y, z) & \n\t\t\\partial_{yz} \\Phi(x, y, z) &\n\t\t\\partial_{zz} \\Phi(x, y, z)\n\t\\end{bmatrix} \\quad ,\n\t\\label{eq:M-matrix-eqlayer}\n\\end{equation}\nwith elements\n$\\partial_{\\alpha\\beta} \\Phi(x, y, z) \\equiv \n\\frac{\\partial^{2} \\Phi(x, y, z)}{\\partial \\alpha \\partial \\beta}$, \n$\\alpha, \\beta = x, y, z$, representing the second derivatives of the harmonic\nfunction\n\\begin{equation}\n\t\\Phi(x, y, z) = \\gamma_{m} \\, \n\t\\int\\limits_{-\\infty}^{+\\infty}\\int\\limits_{-\\infty}^{+\\infty}\n\t\\frac{p(x'', y'', z_{c}) \\: dS''}\n\t{\\left[ (x-x'')^2 + (y-y'')^2 + (z-z_{c})^2 \\right]^{\\frac{1}{2}}} \\: ,\n\t\\quad z_{c} > z \\: .\n\t\\label{eq:Phi-surface-integral}\n\\end{equation}\nIn this equation, $x''$, $y''$ and $z_{c}$ are the coordinates \nof the area element $dS''$, which has magnetic moment per unit area\ndefined by the function $p(x'', y'', z_{c})$ (in $A$).\nNote that $\\tilde{\\mathbf{M}}(x, y, z)$ (equation \\ref{eq:M-matrix-eqlayer}) also represents\na gradient tensor \\citep{pedersen_rasmussen1990} and, consequently, it is symmetric, \nits trace is identically zero at all points $(x, y, z)$ above the layer (with $z < z_{c}$), \nand it has five independent components that are themselves harmonic functions.\nThese properties also permit rewrite $\\Delta \\tilde{T}(x, y, z)$ \n(equation \\ref{eq:tfanomaly-eqlayer}) as a linear combination of independent\nharmonic functions given by\n\\begin{equation}\n\t\\begin{split}\n\t\t\\Delta \\tilde{T}(x, y, z) = \\:\n\t\t& a_{xx} \\, \\partial_{xx} \\Phi(x, y, z) + \n\t\ta_{xy} \\, \\partial_{xy} \\Phi(x, y, z) + \n\t\ta_{xz} \\, \\partial_{xz} \\Phi(x, y, z) + \\\\\n\t\t& a_{yy} \\, \\partial_{yy} \\Phi(x, y, z) + \n\t\ta_{yz} \\, \\partial_{yz} \\Phi(x, y, z)\n\t\t\\end{split} \\quad ,\n\t\\label{eq:tfanomaly-eqlayer-alternative}\n\\end{equation}\nwith coefficients $a_{\\alpha\\beta}$, $\\alpha = x, y$, $\\beta = x, y, z$, defined by\nequation \\ref{eq:a-coefficients}.\n\n% Impose that the equivalent layer fit the total-field anomaly data\nWe know from potential theory that it is possible to find a function $p(x'', y'', z_{c})$\n(equation \\ref{eq:Phi-surface-integral}) so that the condition\n$\\Delta T(x, y, z) = \\Delta \\tilde{T}(x, y, z)$ holds true for all points $(x, y, z)$\nlocated above the fictitious layer of dipoles. \nIn this case, the layer is called \\textit{equivalent layer}.\nTo investigate the properties of $p(x'', y'', z_{c})$, we must first \nobserve that, by imposing the aforementioned condition and using equations \\ref{eq:tfanomaly-alternative} and \\ref{eq:tfanomaly-eqlayer-alternative}, we obtain\n\\begin{equation}\n\\begin{split}\na_{xx} \\, &\\left[\\partial_{xx} \\Phi(x, y, z) - \\partial_{xx} \\Gamma(x, y, z) \\right] + \\\\\na_{xy} \\, &\\left[\\partial_{xy} \\Phi(x, y, z) - \\partial_{xy} \\Gamma(x, y, z) \\right] + \\\\\na_{xz} \\, &\\left[\\partial_{xz} \\Phi(x, y, z) - \\partial_{xz} \\Gamma(x, y, z) \\right] + \\\\\na_{yy} \\, &\\left[\\partial_{yy} \\Phi(x, y, z) - \\partial_{yy} \\Gamma(x, y, z) \\right] + \\\\\na_{yz} \\, &\\left[\\partial_{yz} \\Phi(x, y, z) - \\partial_{yz} \\Gamma(x, y, z) \\right] = 0\n\\: , \\quad z < z_{c} \\: ,\n\\end{split}\n\\label{eq:tfanomaly-alternative-equality}\n\\end{equation}\nwhere the coefficients $a_{\\alpha\\beta}$ (equation \\ref{eq:a-coefficients}), \n$\\alpha = x, y$, $\\beta = x, y, z$, are defined by arbitrary values of \n$I_{0}$ and $D_{0}$ (equation \\ref{eq:main_field}) and \n$I$ and $D$ (equation \\ref{eq:mag_vec}).\nBecause equation \\ref{eq:tfanomaly-alternative-equality} is valid \nfor any possible values of $a_{\\alpha\\beta}$, which are defined for any \nvalues of $I_{0}$, $D_{0}$, $I$ and $D$, the five linearly independent \nharmonic functions in brackets must be identically zero for all points \n$(x, y, z)$ above the equivalent layer, where $z < z_{c}$.\nBy equating each independent function to zero and rewriting the \nsecond derivatives of the surface \nintegral $\\Phi(x, y, z)$ (equation \\ref{eq:Phi-surface-integral}), we get\n\\begin{equation}\n\\partial_{\\alpha\\beta} \\Gamma(x, y, z) = \n\\int\\limits_{-\\infty}^{+\\infty}\\int\\limits_{-\\infty}^{+\\infty}\np(x'', y'', z_{c}) \\: \\partial_{\\alpha\\beta} \\frac{1}{r} \\:\\: dS'' \\: ,\n\\quad z_{c} > z \\: ,\n\\label{eq:D_alpha_beta_Gamma}\n\\end{equation}\nwhere $(x'', y'', z_{c})$ is a point on the equivalent layer and \n$\\partial_{\\alpha\\beta} \\frac{1}{r} \\equiv \n\\frac{\\partial^{2}}{\\partial \\alpha \\partial \\beta} \\frac{1}{r}$ \nrepresents the second derivative,\nwith respect to $\\alpha = x, y$ and $\\beta = x, y, z$, of the inverse distance \nfunction\n\\begin{equation}\n\\frac{1}{r} \\equiv \n\\frac{1}{\\left[ (x-x'')^2 + (y-y'')^2 + (z-z_{c})^2 \\right]^{\\frac{1}{2}}} \\: .\n\\label{eq:inverse-distance}\n\\end{equation}\nA possible solution for equation \\ref{eq:D_alpha_beta_Gamma} can be obtained \nby deriving both sides of\n\\begin{equation}\n\\Gamma(x, y, z) = \n\\int\\limits_{-\\infty}^{+\\infty}\\int\\limits_{-\\infty}^{+\\infty}\np(x'', y'', z_{c}) \\: \\frac{1}{r} \\:\\: dS'' \\: ,\n\\quad z_{c} > z \\: .\n\\label{eq:Gamma_integral_equation}\n\\end{equation}\nNotice that the function $p(x'', y'', z_{c})$ that solves this \nintegral equation for $\\Gamma(x, y, z)$ (equation \\ref{eq:Gamma_integral_equation})\nalso solves the integral equations for the second derivatives \n$\\partial_{\\alpha\\beta} \\Gamma(x, y, z)$ (equation \\ref{eq:D_alpha_beta_Gamma}). \nIt can be shown (see Appendix A) that equation \\ref{eq:Gamma_integral_equation} \nhas a solution\n\\begin{equation}\np(x'', y'', z_{c}) = \\frac{1}{2\\pi} \\partial_{z} \\Gamma(x'', y'', z_{c}) \\: ,\n\\label{eq:positivity_prop}\n\\end{equation}\nwhere, according to equation \\ref{eq:Gamma-volume-integral},\n\\begin{equation}\n\\partial_{z} \\Gamma(x'', y'', z_{c}) = \\gamma_{m} \\, \\iiint\\limits_{\\upsilon} \n\\frac{m(x^{\\prime}, y^{\\prime}, z^{\\prime}) (z^{\\prime} - z_{c}) \\: \n\td\\upsilon^{\\prime}}\n{\\left[ (x''-x^{\\prime})^2 + (y''-y^{\\prime})^2 + (z_{c}-z^{\\prime})^2 \\right]^{\\frac{3}{2}}} \\: , \\quad z^{\\prime} > z_{c} \\: .\n\\label{eq:DzGamma-volume-integral}\n\\end{equation}\nFrom the physical point of view, equation \\ref{eq:DzGamma-volume-integral} \nrepresents the vertical component of the gravitational attraction \n(or the pseudogravity anomaly) that would be produced by the magnetic sources,\non the equivalent layer, if they had a density distribution proportional to \n$m(x^{\\prime}, y^{\\prime}, z^{\\prime})$.\nSince $m(x^{\\prime}, y^{\\prime}, z^{\\prime})$ is strictly positive\nat all points $(x^{\\prime}, y^{\\prime}, z^{\\prime})$ within the magnetic sources,\n$\\partial_{z} \\Gamma(x'', y'', z_{c})$ is positive at all points \n$(x'', y'', z_{c})$ located on the equivalent layer.\n\nThe most interesting aspect of magnetic-moment distribution $p(x'', y'', z_{c})$\n(equation \\ref{eq:positivity_prop}) is that it is defined as the product of a\npositive constant $\\frac{1}{2\\pi}$ and the \nfunction $\\partial_{z} \\Gamma(x'',y'',z_{c})$, which is strictly  \npositive at all points $(x'',y'',z_{c})$ on the equivalent layer. \nHence, $p(x'', y'', z_{c})$ is strictly positive at all points on the\nequivalent layer as well.\nThis relation is similar to that presented by \\cite{pedersen1991} and \n\\cite{li_etal_2014}. They determine, in the wavenumber domain, the \nmagnetic-moment distribution within a continuous equivalent layer \nvertically magnetized by induction. \nThey also consider a planar equivalent layer located below and parallel to a \nhorizontal plane containing the observed total-field anomaly data. \nUnder these assumptions, \\cite{pedersen1991} and \\cite{li_etal_2014} \nconclude that the magnetic-moment distribution within the continuous equivalent \nlayer is all positive and proportional to the pseudogravity anomaly produced by \nthe source on the plane of the equivalent layer.\nHere, we do not follow the same wavenumber-domain \nreasoning used by those authors. Moreover, equation \\ref{eq:positivity_prop} \ngeneralizes this positivity condition because (1) it holds true for all cases \nin which the magnetization of the equivalent layer has the same direction as \nthe true total-magnetization of the sources, whether it is purely induced or not, \nand (2) it does not require that the observed total-field anomaly data be on \na plane. \n\n\n%% Discretizing layer\n\\subsection{Parametrization and forward problem}\n\nIn practical situations, it is not possible to determine a continuous magnetic-moment\ndistribution $p(x'',y'',z_{c})$ (equation \\ref{eq:positivity_prop}) over the \nequivalent layer. \nFor this reason, the layer has to be approximated by a discrete set of dipoles \n(the equivalent sources) with unit volume located at the constant depth $z = z_c$.\nThe total-field anomaly produced by this discrete layer (the predicted total-field anomaly) \nat a given point $(x_{i}, y_{i}, z_{i})$, $i = 1, \\dots, N$ (Figure \\ref{fig:eqlayer_figure}), \nis given by\n\\begin{equation}\n\\Delta T_{i}(\\mathbf{s}) = \\mathbf{g}_{i}(\\mathbf{q})^{\\top} \\mathbf{p},\n\\label{eq:tfa_pred_i}\n\\end{equation}\nwhere $\\mathbf{s}$ is an $(M + 2) \\times 1$ partitioned vector (the parameter vector) given by \n\\begin{equation}\n\t\\mathbf{s} = \\begin{bmatrix}\n\t\t\\mathbf{p} \\\\\n\t\t\\mathbf{q}\n\t\\end{bmatrix} \\: ,\n\t\\label{eq:parameter-vector}\n\\end{equation}\n$\\mathbf{q}$ is the magnetization direction vector (equation \\ref{eq:q_vector}), $\\mathbf{p}$ is an \n$M \\times 1$ vector (the magnetic-moment vector) whose $j$th element, $j = 1, \\dots, M$, is the \nmagnetic moment intensity $p_{j}$ (in A~m$^{2}$) of the $j$th dipole and \n$\\mathbf{g}_{i} (\\mathbf{q})$ is another $M \\times 1$ vector whose $j$th element is defined \nby the harmonic function\n\\begin{equation}\ng_{ij} (\\mathbf{q})  = \\gamma_m \\hat{\\mathbf{F}}_{0}^T \\, \n\\mathbf{M}_{ij} \\, \\hat{\\mathbf{m}}(\\mathbf{q}) \\: .\n\\label{eq:g_ij}\n\\end{equation}\nIn this equation, $\\mathbf{M}_{ij}$ is a $3 \\times 3$ matrix given by\n\\begin{equation}\n\\mathbf{M}_{ij} = \\begin{bmatrix}\n\\partial_{xx} \\frac{1}{r} & \n\\partial_{xy} \\frac{1}{r} &\n\\partial_{xz} \\frac{1}{r} \\\\\n\\partial_{xy} \\frac{1}{r} & \n\\partial_{yy} \\frac{1}{r} &\n\\partial_{yz} \\frac{1}{r} \\\\\n\\partial_{xz} \\frac{1}{r} & \n\\partial_{yz} \\frac{1}{r} &\n\\partial_{zz} \\frac{1}{r}\n\\end{bmatrix} \\quad ,\n\\label{eq:Mij-matrix}\n\\end{equation}\nwhere $\\partial_{\\alpha\\beta} \\frac{1}{r} \\equiv \n\\frac{\\partial^{2}}{\\partial \\alpha \\partial \\beta} \\frac{1}{r}$ \nrepresent the second derivatives,\nwith respect to $\\alpha = x, y, z$ and $\\beta = x, y, z$, of the inverse distance \n$\\frac{1}{r}$ (equation \\ref{eq:inverse-distance}) between the coordinates of the \nobservation points $(x, y, z) = (x_{i}, y_{i}, z_{i})$ and the coordinates of the \nequivalent sources $(x'', y'', z_{c}) = (x_{j}, y_{j}, z_{c})$ \n(Figure \\ref{fig:eqlayer_figure}).\nEquations $\\ref{eq:tfa_pred_i}$-$\\ref{eq:Mij-matrix}$ show that the predicted total-field anomaly \n$\\Delta T_{i}(\\mathbf{s})$ has a linear relation with the magnetic-moment vector $\\mathbf{p}$ \nand a nonlinear relation with the magnetization direction vector $\\mathbf{q}$ \n(equation \\ref{eq:q_vector}).\n\n\n\\subsection{Inverse problem}\n\n%%%% Defining the objective function\nLet $\\mathbf{\\Delta T}^{o}$ be the observed-data vector whose $i$th element $\\Delta T_{i}^{o}$\nis the observed total-field anomaly produced by the magnetic sources at the point \n$(x_{i},y_{i},z_{i})$, $i = 1, \\dots, N$ (Figure \\ref{fig:eqlayer_figure}). \nSimilarly, let $\\mathbf{\\Delta T} (\\mathbf{s})$ be the predicted-data vector whose $i$th element \n$\\Delta T_{i}(\\mathbf{s})$ (equation \\ref{eq:tfa_pred_i}) is the predicted total-field anomaly  \nproduced by the discrete equivalent layer at the same point $(x_{i},y_{i},z_{i})$. \nTo estimate the parameter vector $\\mathbf{s}$ (equation \\ref{eq:parameter-vector})\nminimizing the difference between $\\mathbf{\\Delta T}^{o}$ and \n$\\mathbf{\\Delta T}(\\mathbf{s})$, we solve the following inverse problem:\n\\begin{subequations}\n\t\\begin{align}\n\t& \\text{minimizing}\n\t& &\\Psi(\\mathbf{s}) =\\lVert \\mathbf{\\Delta T}^{o} - \\mathbf{\\Delta T} (\\mathbf{s}) \n\t\\rVert_{2}^{2} + \\, \\mu f_0 \\parallel \\mathbf{p} \\parallel_{2}^{2} \\: , \\\\\n\t& \\text{subject to}\n\t& & \\mathbf{p} \\geqslant \\mathbf{0} \\: .\n\t\\end{align}\n\t\\label{eq:positivity_goal_function}\n\\end{subequations}\nOn the right side of equation \\ref{eq:positivity_goal_function}a, the first \nand second terms are \nthe data-misfit function and the zeroth-order Tikhonov regularization \nfunction, $\\mu$ is the regularizing parameter, $\\| \\cdot \\|_{2}^{2}$ represents \nthe squared Euclidean norm and $f_0$ is a normalizing factor. \nThis factor makes a trade-off \nbetween the data-misfit and zeroth-order Tikhonov regularization functions.\nIn the inequality \\ref{eq:positivity_goal_function}b, $\\mathbf{0}$ is an \n$M \\times 1$ vector with all elements equal to zero and the inequality sign \nis applied element \nby element. This positivity constraint on the magnetic-moment vector $\\mathbf{p}$ \nis incorporated by using the nonnegative least squares (NNLS) proposed by \n\\cite{lawson_hanson_1974}. \n\n%% Deducing the equations\nTo solve this constrained inverse problem, let us first consider the following \nsecond-order expansion of the goal function (equation \\ref{eq:positivity_goal_function}a)\naround $\\mathbf{s} = \\mathbf{s}^{k}$ (equation \\ref{eq:parameter-vector}):\n\\begin{equation}\n\\Psi(\\mathbf{s}^{k} + \\mathbf{\\Delta s}^{k}) \\approx \\Psi(\\mathbf{s}^{k}) + \n{\\mathbf{J}^{k}}^{\\top} \\mathbf{\\Delta s}^{k} + \n\\frac{1}{2} {\\mathbf{\\Delta s}^{k}}^{\\top} \\mathbf{H}^{k} \\mathbf{\\Delta s}^{k}  \\: ,\n\\label{eq:sec_ord_goal}\n\\end{equation}\nwhere $\\mathbf{\\Delta s}^{k}$ is a perturbation on the parameter vector \nand the terms $\\mathbf{J}^{k}$ and $\\mathbf{H}^{k}$ are, respectively, the gradient vector \nand the Hessian matrix evaluated at $\\mathbf{s}^{k}$.\nThen, we estimate the perturbation vector $\\bar{\\mathbf{\\Delta s}}^k$ that minimizes the \nexpanded function (equation \\ref{eq:sec_ord_goal}) by taking the gradient with respect \nto $\\mathbf{\\Delta s}^k$ and setting the result equal to the null vector.\nThis procedure leads to the linear system\n\\begin{equation}\n\\mathbf{H}^{k} \\bar{\\mathbf{\\Delta s}}^{k} = - \\mathbf{J}^{k} \\: ,\n\\label{eq:linear_sys_GN}\n\\end{equation}\nwhich represents the $k$th step of the Gauss-Newton method \\citep{aster2005} for minimizing \nour goal function (equation \\ref{eq:positivity_goal_function}a).\nWe rewrite this linear system by neglecting the cross-derivatives in the Hessian matrix \nas follows:\n\\begin{equation}\n\\left[\n\\begin{array}{c|c}\n\\mathbf{H}_{pp}^{k} & \\mathbf{0} \\\\\n\\hline\n\\mathbf{0}^{\\top} & \\mathbf{H}_{qq}^{k}\n\\end{array}\n\\right] \\left[ \\begin{array}{c}\n\\bar{\\mathbf{\\Delta p}}^{k} \\\\ \n\\bar{\\mathbf{\\Delta q}}^{k} \n\\end{array} \\right] \\approx -\\left[ \\begin{array}{c}\n\\mathbf{J}_{p}^{k} \\\\ \n\\mathbf{J}_{q}^{k} \n\\end{array} \\right] ,\n\\label{eq:linear_sys_GN_block}\n\\end{equation}\nin which $\\mathbf{0}$ is an $M \\times 2$ matrix containing all elements equal to zero, \n$\\bar{\\mathbf{\\Delta p}}^{k} = \\bar{\\mathbf{p}}^{k+1} - \\bar{\\mathbf{p}}^{k}$ \nis a correction on the magnetic-moment vector $\\mathbf{p}$,\n$\\bar{\\mathbf{\\Delta q}}^{k} = \\bar{\\mathbf{q}}^{k+1} - \\bar{\\mathbf{q}}^{k}$ \nis a correction on the magnetization direction $\\mathbf{q}$ and the terms \n$\\mathbf{J}_{\\alpha}^{k}$ and $\\mathbf{H}_{\\alpha \\alpha}^{k}$, $\\alpha = p,q$, \nare the gradient vector and the Hessian matrix calculated with respect to the elements of \n$\\mathbf{p}$ and $\\mathbf{q}$, respectively. \nThe gradient vector $\\mathbf{J}_{p}^{k}$ and the Hessian matrix $\\mathbf{H}_{pp}^{k}$ \n(equation \\ref{eq:linear_sys_GN_block}) related to the magnetic-moment vector \n$\\mathbf{p}$ (equation \\ref{eq:parameter-vector}) are, respectively,\n\\begin{equation}\n\\mathbf{J}_{p}^{k} = -2 {\\mathbf{G}_{p}^{k}}^{\\top} \n\\left[ \\mathbf{\\Delta T}^{o} - \\mathbf{\\Delta T} (\\bar{\\mathbf{s}}^{k}) \\right] + \n2\\mu f_{0}^{k} \\bar{\\mathbf{p}}^{k} \n\\label{eq:grad_p}\n\\end{equation}   \nand   \n\\begin{equation}\n\\mathbf{H}_{pp}^{k} = 2 {\\mathbf{G}_{p}^{k}}^{\\top} \\mathbf{G}_{p}^{k} + \n2 \\mu f_{0}^{k} \\mathbf{I} \\: ,\n\\label{eq:hess_p}\n\\end{equation}\nwhere $\\mathbf{G}_p^{k}$ is an $N \\times M$ matrix whose $ij$th element is given by the harmonic \nfunction $g_{ij}(\\bar{\\mathbf{q}}^{k})$ (equation \\ref{eq:g_ij}) evaluated at the \nmagnetization direction $\\bar{\\mathbf{q}}^{k}$, $\\mathbf{I}$ is the $M \\times M$ identity matrix and \n$f_{0}^{k}$ is a  normalizing factor equal to\n\\begin{equation}\nf_{0}^{k} = \\dfrac{trace \\left({\\mathbf{G}_{p}^{k}}^{\\top} \\mathbf{G}_{p}^{k} \\right)}{M} \\, .\n\\label{eq:norm_factor}\n\\end{equation}\nThis factor is used with the purpose of making a trade-off between the terms \nforming the gradient vector $\\mathbf{J}_{p}^{k}$ (equation \\ref{eq:grad_p}) and \nthe Hessian matrix $\\mathbf{H}_{pp}^{k}$ (equation \\ref{eq:hess_p}) \nalong the iterative process. The gradient vector $\\mathbf{J}_{q}^{k}$ and \nthe Hessian matrix $\\mathbf{H}_{qq}^{k}$ \n(equation \\ref{eq:linear_sys_GN_block}) related to the magnetization direction \n$\\mathbf{q}$ (equation \\ref{eq:q_vector}) are, respectively,\n\\begin{equation}\n\\mathbf{J}_{q}^{k} = -2 {\\mathbf{G}_{q}^{k}}^{\\top} \n\\left[ \\mathbf{\\Delta T}^{o} - \\mathbf{\\Delta T} (\\bar{\\mathbf{s}}^{k}) \\right]\n\\label{eq:grad_q}\n\\end{equation}   \nand   \n\\begin{equation}\n\\mathbf{H}_{qq}^{k} \\approx 2 {\\mathbf{G}_{q}^{k}}{^\\top} \\mathbf{G}_{q}^{k} \\: ,\n\\label{eq:hess_q}\n\\end{equation}\nin which $\\mathbf{G}_{q}^{k}$ is a $N \\times 2$ matrix given by \n\\begin{equation}\n\\mathbf{G}_{q}^{k} = \\begin{bmatrix}\n\\partial_{I} \\mathbf{g}_{1}(\\bar{\\mathbf{q}}^{k})^{\\top} \\bar{\\mathbf{p}}^{k} & \n\\partial_{D} \\mathbf{g}_{1}(\\bar{\\mathbf{q}}^{k})^{\\top} \\bar{\\mathbf{p}}^{k} \\\\\n\\vdots & \\vdots  \\\\\n\\partial_{I} \\mathbf{g}_{N}(\\bar{\\mathbf{q}}^{k})^{\\top} \\bar{\\mathbf{p}}^{k} & \n\\partial_{D} \\mathbf{g}_{N}(\\bar{\\mathbf{q}}^{k})^{\\top} \\bar{\\mathbf{p}}^{k} \n\\end{bmatrix} \\: ,\n\\label{eq:Gq}\n\\end{equation}\nwhere \n$\\partial_{\\alpha} \\mathbf{g}_{i}(\\bar{\\mathbf{q}}^{k}) \\equiv \n\\frac{\\partial \\mathbf{g}_{i}(\\bar{\\mathbf{q}}^{k})}{\\partial \\alpha}$, $\\alpha= I, D$, \nrepresent the first derivatives of vector \n$\\mathbf{g}_{i}(\\bar{\\mathbf{q}}^{k})$ (equation \\ref{eq:tfa_pred_i}) with respect to the \ninclination $I$ and the declination $D$ of the total magnetization of the sources.\n\n\\subsection{Iterative algorithm for solving the inverse problem}\n\nThe iteration $k = 0$ of our algorithm starts with an initial guess \n$\\bar{\\mathbf{q}}^{k} = \\bar{\\mathbf{q}}^{0}$ for the direction vector $\\mathbf{q}$ \n(equation \\ref{eq:q_vector}).\nBy using this $\\bar{\\mathbf{q}}^{k}$, the upper part of equation \n\\ref{eq:linear_sys_GN_block} leads to the following linear system for the magnetic-moment \nvector:\n\\begin{equation}\n\\left[ {\\mathbf{G}_{p}^{k}}^{\\top} \\mathbf{G}_{p}^{k} + \n\\mu f_{0}^{k} \\mathbf{I} \\right] \\bar{\\mathbf{p}}^{k} = {\\mathbf{G}_{p}^{k}}^{\\top} \\mathbf{\\Delta T}^{o} \\: .\n\\label{eq:linear_sys_p}\n\\end{equation}\nTo impose the positivity constraint (equation \\ref{eq:positivity_goal_function}b) on the \nmagnetic-moment distribution $\\bar{\\mathbf{p}}^{k+1}$ within the equivalent layer, \nwe solve this linear system (equation \\ref{eq:linear_sys_p}) by using the nonnegative least \nsquares (NNLS) method \\citep{lawson_hanson_1974, silvadias_etal_2007}.\nThis positive magnetic-moment distribution is then used to estimate a correction \n$\\bar{\\mathbf{\\Delta q}}^{k}$ on the magnetization direction by solving the following \nunconstrained nonlinear system via Levenberg-Marquardt method \\citep{aster2005}:\n\\begin{equation}\n\\left[ {\\mathbf{G}_{q}^{k}}^{\\top} \\mathbf{G}_{q}^{k} + \\lambda \\, \\mathbf{I} \\right] \n\\bar{\\mathbf{\\Delta q}}^{k} = {\\mathbf{G}_{q}^{k}}^{\\top} \n\\left[ \\mathbf{\\Delta T}^{o} - \\mathbf{\\Delta T} (\\mathbf{s}^{k}) \\right] \\: ,\n\\label{eq:linear_sys_q}\n\\end{equation}\nwhere $\\lambda$ is the Marquardt parameter and $\\mathbf{I}$ is the identity matrix. \nAfter estimating the correction $\\bar{\\mathbf{\\Delta q}}^{k}$ \nat the $k$th iteration, we update the magnetization direction as follows\n\\begin{equation}\n\\bar{\\mathbf{q}}^{k+1} = \\bar{\\mathbf{q}}^{k} + \\bar{\\mathbf{\\Delta q}}^{k} \\: ,\n\\label{eq:q_next}\n\\end{equation}\nuse it as input for estimating a new positive magnetic-moment distribution \nwith equation \\ref{eq:linear_sys_p} and so on.\nThe iterative process stops when the goal function (equation \\ref{eq:positivity_goal_function}a) \nis invariant along successive iterations. \nWe show in Appendix B that our method fails if the sources are vertically magnetized.\n\n\\subsection{The choice of layer depth $\\mathbf{z_{c}}$ and regularization parameter $\\mathbf{\\mu}$}\n\nThe procedure for the use of our methodology for estimating the total magnetization \nrequire the choice of two main parameters. The first one is the layer depth $z_c$ \n(Figure \\ref{fig:eqlayer_figure}) and the second is the regularization parameter \n$\\mu$ (equation \\ref{eq:linear_sys_p}).\n\nThere is a classical criterion proposed by \\cite{dampney1969} to define the layer \ndepth based on the horizontal data sampling. This criterion states that the \ndistance between the plane containing the data and the  \nplane defining the layer should vary from $2.5$ to $6.0$ times the horizontal \ndata sampling. This criterion, however, is valid for evenly spaced data. \nHere, we define the layer depth $z_c$ by using the horizontal space between \nadjacent flight lines of an airborne survey. We found empirically that $z_c$ \ncan vary from $2$ to $3$ times the spacing between adjacent flight lines.\nNotice that the range we found empirically is smaller than that proposed by \nDampney. Apparently, this is due to the fact that, in an airborne survey, \nthe data sampling along lines is smaller than the space between lines.\n\nTo solve the equation \\ref{eq:linear_sys_p} we have to choose a reliable \nregularization parameter $\\mu$. For this purpose, we use the L-curve method \n\\citep{hansen1992}. This approach is widely used in the literature to find a \nregularizing parameter, which filters out enough noise without losing too much \ninformation in the final solution. The procedure of finding the parameter plot a \ncurve of optimal values between the solution and residual norms. The corner of \nthe curve is the optimal regularization parameter which establishes a trade-off \nbetween the regularizing and data-misfit functions. \n", "meta": {"hexsha": "678b11008bd4c0b3eae61ab72e1e5f906ccc15eb", "size": 28045, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manuscript/methodology.tex", "max_stars_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_stars_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-09-03T03:00:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-10T10:33:08.000Z", "max_issues_repo_path": "manuscript/methodology.tex", "max_issues_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_issues_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "manuscript/methodology.tex", "max_forks_repo_name": "pinga-lab/eqlayer-magnetization-direction", "max_forks_repo_head_hexsha": "dd929120b22bbd8d638c8bc5924d15f41831dce2", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-17T15:32:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-17T15:32:29.000Z", "avg_line_length": 49.5494699647, "max_line_length": 195, "alphanum_fraction": 0.6829381351, "num_tokens": 9513, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009457116781, "lm_q2_score": 0.8333245932423309, "lm_q1q2_score": 0.762409458442208}}
{"text": "%&LaTeX\n\n\\section{To Infinity and Response!}\n\nBy the end of this lab you should feel comfortable manipulating and\nusing feedback filters for simple problems. You should also be\ncomfortable with the concept of a filter with an infinite impulse\nresponse. All feedback filters have an infinite impulse response\nand are also known as IIR filters. Feedback filters use the previous\noutputs of the filter, feeding them back to compute the output for the\ncurrent sample. The ``fed back'' outputs are weighted by coefficients,\n$a_\\ell$.\n\n\\subsection{A Note About Matlab Filter Coefficients}\n\nNote that the Matlab \\verb|filter| function uses \\emph{negative}\nvalues for the $a_\\ell$ (feedback) coefficients, from the transfer\nfunction. In other words, in the text, a second-order feedback\nfilter's defining equation might be:\n\\begin{align}\n  y[n] &= a_1 y[n-1] + a_2 y[n-2] + b_0 x[n] \\label{eq:def} \\\\\n  y[n] -a_1 y[n-1] - a_2 y[n-2]&=   b_0 x[n]\n\\end{align}\nThis yields the transfer function:\n\\begin{align}\n  Y(z)(1 - a_1 z^{-1} - a_2 z^{-2}) &= b_0X(z) \\\\\n  Y(z)/X(z) &= \\frac{b_0}{1 - a_1 z^{-1} - a_2 z^{-2}} \\\\\n  H(z) &= \\frac{b_0}{1 - a_1 z^{-1} - a_2 z^{-2}} \\label{eq:trans} \n\\end{align}\nThe coefficients used by \\verb|filter|, rather than being the $a_\\ell$\nfrom the defining equation~(\\ref{eq:def}) are the \\emph{negative}\n$a_\\ell$ from the transfer function~(\\ref{eq:trans}) --- the ratio of\ntwo polynomials. In other words, to properly compute the above filter\nin Matlab, you will need to use:\n\\begin{lstlisting}[style=Matlab-editor,basicstyle=\\mlttfamily\\small]\na = [1.0 -a1 -a2];\nb = [b0];\ny = filter(b, a, x);\n\\end{lstlisting}\nNote also that in this example the filter includes the $a[0]$\ncoefficient (of course, per Matlab one-based indices, as \\verb|a(1)|),\nwhich we will always leave as 1.0 (it's the first ``1'' in the\ndenominator of the transfer function).\n\nAnd finally, note that one form of the \\verb|filter| function takes a\nfourth argument, which is the initial conditions for the feedback\ndelays (used in computing the output values that have delay terms\nwhich come before the first value in the $x$ vector). These default to\nall zero if not specified. \n\n\\subsection{Feedback Filters as Recurrence Relations}\n\nYou may notice that the defining equation for a feedback filter is in\nthe form of a recurrence relation. In fact, we can use a feedback\nfilter to implement a recurrence relation if we set the input to be\nan impulse, $x[n] = C \\delta[n]$, with amplitude $C$ being the initial\nvalue for the iteration. Let's start out with the Fibonacci sequence,\nwhich you'll remember to be:\n\\begin{equation}\n  F[n] = \\left\\{ \\begin{array}{ll}\n      1 & n < 2 \\\\\n      F[n-1] + F[n-2] & n \\geq 2\n    \\end{array} \\right.\n\\end{equation}\n\nWe can rewrite this recurrence relation as:\n\\begin{equation}\n  y[n] = y[n-1] + y[n-2] + x[n]\n  \\label{eq:fib}\n\\end{equation}\nand we will get the Fibonacci sequence \\emph{if} we input an impulse\n(hence, the appearance of the $x[n]$ on the right hand side, which\nserves only to initialize the filter). In Matlab, this can be done\ntrivially by taking a vector of all zeros --- let's call this vector\n\\verb|x| --- and setting its first value only (\\verb|x(1)|) to\n$C$. This is also a very good demonstration of the first ``I'' in the\nacronym ``IIR'': the impulse response of this filter has infinite\nduration.\n\n\\paragraph{Step 1.1} If we set $x[n]=\\delta[n]$ in~(\\ref{eq:fib}), we\nshould see that the impulse response of this filter is indeed the\nFibonacci sequence. Implement this filter in Matlab and verify that its\nimpulse response is the Fibonacci sequence. What are the values of the\ncoefficients that you used?\n\n\n\\paragraph{Step 1.2} What is the value for $n=19$ (\\verb|y(20)| in\nMatlab)?\n\n\n\\paragraph{Step 1.3} Is this filter stable?\n\n\n\\paragraph{Step 1.4} Let's do something similar with the recurrence\nrelation for computing the series $y[n] = 1/3^n$ in the text (as\nalways, remember that Matlab indices start at 1). Set the\ncoefficients for a feedback filter to implement equation~(5-43) in the\ntext, $y[n] = 1/3 y[n-1] + x[n]$. What are the filter coefficients?\n\n\n\\paragraph{Step 1.5} What are the pole location(s) for this filter?\n\n\n\\paragraph{Step 1.6} Now use Matlab to calculate the impulse repsonse.\nSet the amplitude of the input impulse to be 0.99996. Is this filter\nstable?  Is its impulse response consistent with the result of\niterating equation~(5-43) in the textbook?\n\n\n\\subsection{Telephone Touch Tone Dialing}\nTelephone touch pads generate dual tone multi frequency (DTMF) signals\nto dial a telephone. When any key is pressed, the tones of the\ncorresponding column and row in the table below are generated, hence\nit is a ``dual tone'' code. As an example, pressing the 5 button\ngenerates the tones 770Hz and 1336Hz summed together.\n\n\\begin{center}\n  \\begin{tabular}{l|ccc}\n    & 1209Hz & 1336Hz & 1477Hz \\\\ \\hline\n    697Hz &   1    &   2    &   3    \\\\\n    770Hz &   4    &   5    &   6    \\\\\n    852Hz &   7    &   8    &   9    \\\\\n    941Hz &   $\\ast $    &   0    &   \\#    \n  \\end{tabular}\n\\end{center}\n\nThe frequencies in the table above were chosen to avoid harmonics. No\nfrequency is a multiple of another, the difference between any two\nfrequencies does not equal any of the frequencies, and the sum of any\ntwo frequencies does not equal any of the frequencies.\\footnote{More\n  information can be found at:\n  \\url{http://en.wikipedia.org/wiki/DTMF}} This makes it easier to\ndetect exactly which tones are present in the dial signal in the\npresence of line distortions.\n\nIt is possible to decode such a signal by first using a \\emph{filter\n  bank} composed of seven bandpass filters, one for each of the\nfrequencies above. When a button is pressed, it will produce a\ncombination of two tones, and thus, at the decoder end, two of the\nbandpass filters will produce significantly higher outputs than the\nothers. A good measure of the output levels is the average power at\nthe filter outputs. This is calculated by squaring the filter outputs\nand averaging over a short time interval.\n\n\\paragraph{Step 2.1} First of all, please write a Matlab\n\\verb|DTMFCoder| function. This function should take in one argument\n--- a telephone key number --- and return a digital waveform\ncontaining the appropriate summed tones. Internally, it should do this\nby generating AnalogSignals, summing them, and then sampling them at\n8kHz and quantizing them at 16 bits. DTMF signal duration should be\n1s. For each of the seven tone frequencies in Hz, what is the\ncorresponding digital frequency in the range $[0, \\pi]$?\n\n\\paragraph{Step 2.2} In this step, please construct a bandpass filter\nfor the 697Hz tone. Use a feedback filter with complex conjugate\npoles. Locate these complex conjugate poles at the correct location\nfor $\\pm$697Hz. Use equation~(5-38) of section~5.1.4 of the text to\nset the radius of those poles so that the closest other tone\nfrequency, 770Hz, lies outside the passband (in other words, to set\nthe bandwidth so that it is significantly smaller than twice the\ndifference between 697Hz and 770Hz). What were your pole locations?\n\nCompute the corresponding filter coefficients. You can verify your\nfilter performance by plotting its frequency response.\n\nVerify that the filter output for \\verb|DTMFCoder| output for keys 1,\n2, and 3 are pretty much identical, and that all other buttons produce\nmuch lower amplitude output.  In your report, include a plot of the\nfilter output for one of the buttons 1, 2, or 3 and a plot for one of\nthe buttons 4, 5, or 6.\n\n\n\\paragraph{Step 2.3} Now we are ready to decide whether a particular\nfrequency is present. Write a Matlab \\verb|RMS| function that takes a\nvector as input and returns a scalar root mean squared value for it\n--- this function should square each value of the vector, take the\nmean of those squares, and then take the square root of that\nmean. Determine the RMS filter output for telephone buttons 1, 2, and\n3 and compare them to the other phone buttons. You should see a much\nhigher value for 1, 2, and 3 than the other buttons; additionally, the\nRMS values for those three buttons should be almost identical. What\nare the RMS values you get for pressing 1 versus 4?\n\n\n\\paragraph{Step 2.4} Now we will assemble a filter bank. Implement\nfilters in Matlab for each of the six other DTMF frequencies and\nverify that they work as expected. Now, write a Matlab function\n\\verb|DTMFDecoder| that takes a single input --- a vector (for which\nyou will use the \\verb|DTMFCoder| output).  \\verb|DTMFDecoder| should\ncompute the RMS value of the output of each of the seven filters in\nthe filter bank. It should output (to the Matlab console) these RMS\nvalues, and then detect the two highest values. It should use a lookup\ntable or equivalent logic to decode which button was ``pressed,'' and\noutput (to the Matlab console) that button.\n\n\n% LocalWords:  WebQ MATLAB DSP\n", "meta": {"hexsha": "36999369ce31980ee11f3ab8458f465bb8884598", "size": 8890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Matlab Labs/lab6/lab6.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/lab6/lab6.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/lab6/lab6.tex", "max_forks_repo_name": "stiber/Signal-Computing", "max_forks_repo_head_hexsha": "cb5c7825e0cc80ca2ecd3e324fcf6231c320a721", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.898989899, "max_line_length": 71, "alphanum_fraction": 0.7427446569, "num_tokens": 2437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8688267677469951, "lm_q1q2_score": 0.7623753321760458}}
{"text": "\n\\subsection{The Metropolis-Hastings algorithm}\n\n\\subsubsection{The Metropolis-Hastings algorithm}\n\nThe Metropolis-Hastings algorithm creates a set of samples \\(x\\) such that the distribution of the samples approaches the goal distribution.\n\n\\subsubsection{Initialisation}\n\nThe algorithm takes an arbitrary starting sample \\(x_0\\). It then must decide which sample to consider next.\n\n\\subsubsection{Generation}\n\nIt does this using a Markov chain. That is, there is a map \\(g(x_j, x_i)\\).\n\nThis distribution is generally a normal distribution around \\(x_i\\), making the process a random walk.\n\n\\subsubsection{Acceptance}\n\nNow we have a considered sample, we can either accept or reject it. It is this step that makes the end distribution approximage the function.\n\nWe accept if \\(\\dfrac{f(x_j)}{f(x_i)}>u\\), where \\(u\\) is a random variable between \\(0\\) and \\(1\\), generated each time.\n\nWe can calculate this because we know this function.\n\n\\subsubsection{Properties}\n\n\n", "meta": {"hexsha": "7b0b1748d3bf31a16e6521e3204e1b83b36a2392", "size": 970, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/samplingMCMC/02-02-metropolisHastings.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/samplingMCMC/02-02-metropolisHastings.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/samplingMCMC/02-02-metropolisHastings.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.4482758621, "max_line_length": 141, "alphanum_fraction": 0.7690721649, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832974, "lm_q2_score": 0.8175744806385542, "lm_q1q2_score": 0.7623500281765717}}
{"text": "%================================\n\\section{Compactness}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[compactness]\n\t\\label{def: compactness}\n\tA topological space $(X, \\mathcal T)$ is said to be \\textit{compact} iff every open cover of $X$ has a finite subcover. That is,\n\t$$\n\t\\forall \\mathcal C \\subseteq \\mathcal T : \\bigcup \\mathcal C = X : \\exists \\mathcal S \\subseteq \\mathcal C : \\bigcup \\mathcal S = X : |\\mathcal S| < \\aleph_0.\n\t$$\n\\end{definition}\n%--------------------------------", "meta": {"hexsha": "d508163be99fcbbe66edb4e57250ab93336cce6d", "size": 534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/compactness.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/compactness.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/compactness.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": 35.6, "max_line_length": 159, "alphanum_fraction": 0.5131086142, "num_tokens": 145, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587905460026, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7623489484071547}}
{"text": "\n\\subsection{L'Hôpital's rule}\n\n\\subsubsection{L'Hôpital's rule}\n\nIf there are two functions which are both tend to \\(0\\) at a limit, calculating the limit of their divisor is hard. We can use L'Hopital's rule.\n\nWe want to calculate:\n\n\\(\\lim_{x\\rightarrow c}\\dfrac{f(x)}{g(x)}\\)\n\nThis is:\n\n\\(\\lim_{x\\rightarrow c}\\dfrac{f(x)}{g(x)}=\\lim_{x\\rightarrow c}\\dfrac{\\dfrac{f(x)-0}{\\delta}}{\\dfrac{g(x)-0}{\\delta}}\\)\n\nIf:\n\n\\(\\lim_{x\\rightarrow c}f(x)=\\lim_{x\\rightarrow c}g(x)=0\\)\n\nThen\n\n\\(\\lim_{x\\rightarrow c}\\dfrac{f(x)}{g(x)}=\\lim_{x\\rightarrow c}\\dfrac{\\dfrac{f(x)-f(c)}{\\delta}}{\\dfrac{g(x)-f(c)}{\\delta}}\\)\n\n\\(\\lim_{x\\rightarrow c}\\dfrac{f(x)}{g(x)}=\\dfrac{f'(x)}{g'(x)}\\)\n\n", "meta": {"hexsha": "055f0123631e1bb7142492feb28d2964473764f7", "size": 674, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/calculus/01-06-lhopital.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/calculus/01-06-lhopital.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/calculus/01-06-lhopital.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.9230769231, "max_line_length": 144, "alphanum_fraction": 0.6364985163, "num_tokens": 265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361557147438, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7623253923641071}}
{"text": "\\section{Classification of Some Small Finite Groups}\r\nConsider\r\n$$\\underline{1}=\r\n\\begin{pmatrix}\r\n    1&0\\\\\r\n    0&1\r\n\\end{pmatrix}\r\n\\underline{i}=\r\n\\begin{pmatrix}\r\n    i&0\\\\\r\n    0&-i\r\n\\end{pmatrix}\r\n\\underline{j}=\r\n\\begin{pmatrix}\r\n    0&1\\\\\r\n    -1&0\r\n\\end{pmatrix}\r\n\\underline{k}=\r\n\\begin{pmatrix}\r\n    0&i\\\\\r\n    i&0\r\n\\end{pmatrix}\r\n$$\r\nOne can check that\r\n$Q_8=\\{\\pm\\underline{1},\\pm\\underline{i},\\pm\\underline{j},\\pm\\underline{k}\\}$ is a group under matrix multiplication, we also have $\\underline{i}^2=\\underline{j}^2=\\underline{k}^2=\\underline{1},\\underline{i}\\underline{j}=\\underline{k}=-\\underline{j}\\underline{i},\\underline{j}\\underline{k}=\\underline{i}=-\\underline{k}\\underline{j},\\underline{k}\\underline{i}=\\underline{j}=-\\underline{i}\\underline{k}$\r\n\\begin{definition}\r\n    If $G,H$ are groups, then we can have the product group $G\\times H$ under the group operation\r\n    $$(g_1,h_1)(g_2,h_2)=(g_1g_2,h_1h_2)$$\r\n\\end{definition}\r\nOne can check that $(G\\times H)\\times K\\cong G\\times (H\\times K)$.\r\n\\begin{theorem}[Chinese Remainder Theorem]\\label{crt}\r\n    If $m,n\\in\\mathbb N$ such that $m,n\\ge 2$ and $(m,n)=1$, then the following function $\\phi: \\mathbb Z_{mn}\\to\\mathbb Z_m\\times\\mathbb Z_n$ defined by\r\n    $$a\\mapsto (a\\bmod m,a\\bmod n)$$\r\n    is an isomorphism.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    It is trivial that $\\phi$ is well-defined and is a homomorphism.\r\n    Both groups has the same size, so it suffices to show that injectivity.\r\n    To see it, consider $\\ker\\phi$.\r\n    If $a\\in\\ker\\phi$, then $a\\equiv 0\\pmod{m}$ and $a\\equiv 0\\pmod{n}$, so $a\\equiv 0\\pmod{mn}$.\r\n    So the kernel of $\\phi$ is trivial, hence it is injective.\r\n\\end{proof}\r\n\\begin{theorem}\\label{direct_product_thm}\r\n    Let $H_1,H_2\\le G$, then if\\\\\r\n    1. $H_1\\cap H_2=\\{e\\}$\\\\\r\n    2. $h_1h_2=h_2h_1$ for any $h_1\\in H_1,h_2\\in H_2$.\\\\\r\n    3. $\\forall g\\in G,\\exists h_1\\in H_1, h_2\\in H_2, h_1h_2=g$.\\\\\r\n    Then $G\\cong H_1\\times H_2$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the map $\\phi:H_1\\times H_2\\to G$ such that $\\phi:(h_1,h_2)\\mapsto h_1h_2$.\r\n    It is a homomorphism by 2, indeed, if $h_1,h_1'\\in H_1, h_2,h_2'=H_2$, then\r\n    \\begin{align*}\r\n        \\phi(h_1,h_2)\\phi(h_1',h_2')=h_1h_2h_1'h_2'=h_1h_1'h_2h_2'\\\\\r\n        =\\phi(h_1h_1',h_2h_2')=\\phi((h_1,h_2)(h_1',h_2'))\r\n    \\end{align*}\r\n    Its surjectivity is implied by 3.\r\n    If $\\phi(h_1,h_2)=e$, then $h_1h_2=e\\implies H_1\\ni h_1=h_2^{-1}\\in H_2$, so $h_1=h_2=e$, so $\\ker\\phi=\\{e\\}$, thus it is injective.\r\n    Therefore it is a isomorphism.\r\n\\end{proof}\r\nwe now wish to classify finite groups of order at most $8$.\r\nFor $|G|=1,2,3,5,7$, we already know that $G$ would be cyclic, so it remains to find those in $4,6,8$.\r\n\\begin{theorem}\r\n    For a finite group $G$ such that each element is with order $2$, then we know that $|G|$ is even, also it is isomorphic to the direct product of $C_2$'s.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    We know that $G$ is abelian.\r\n    \\footnote{Proved a long time ago in example sheet.}\r\n    So it is done by Theorem \\ref{direct_product_thm} and the associativity of group direct products (up to isomorphism).\r\n\\end{proof}\r\nThus, for $|G|=4$, either there is an element of order $4$, in which case $G\\cong C_4$, or every element has order $2$, where we have $G\\cong K_4:=(C_2)^2=C_2\\times C_2$.\r\nFor $|G|=6$, then if there is an element of order $6$, then $G\\cong C_6$, otherwise there is an element $r$ of order $3$ and $s$ of order $2$ (by Theorem \\ref{cauchy}) such that $sr\\neq rs$ (since if so them $G\\cong C_2\\times C_3\\cong C_6$ by Theorem \\ref{direct_product_thm} and Theorem \\ref{crt}).\r\nBut the elements $\\{e,s,r,r^2,rs,r^2s\\}$ are distinct, by inspection we must have $sr=r^2s$, but this would give the full definition of the group operation which is identical to that of the Dihedral group on a $3$-gon (aka equilateral triangle), so $G\\cong D_6\\cong S_3$.\\\\\r\nGroups of order $8$ is a little bit more complicated.\r\n\\begin{claim}\r\n    There are only $5$ groups of order $8$, and they are\r\n    $$C_8,C_4\\times C_2,(C_2)^3,D_8,Q_8$$\r\n    up to isomorphism.\r\n\\end{claim}\r\n\\begin{proof}\r\n    $C_8,C_4\\times C_2, C_2\\times C_2\\times C_2$ are Abelian, and $D_8,Q_8$ are not.\r\n    Furthermore, by looking at the order of elements, $C_8,C_4\\times C_2, C_2\\times C_2\\times C_2$ are all distinct.\r\n    And by essentially the same method, $D_8,Q_8$ are distinct as well, as $Q_8$ has only one element of order $2$ but $D_8$ has more.\\\\\r\n    So it remains to show that every group of order $8$ is one of them.\\\\\r\n    Let $G$ be the group.\r\n    Since $|G|=8$, any element of $G$ must have orders $1,2,4,8$.\r\n    If it has element of order $8$, then $G\\cong C_8$; if all its elements are of order $2$, then $G\\cong (C_2)^3$.\r\n    Assume henceforth that $G$ has at least one element $f$ of order $4$ but none of order $8$.\r\n    Let $g\\notin\\langle f\\rangle$, so $G=\\langle f\\rangle\\cup g\\langle f\\rangle$, in order words\r\n    $$G=\\{e,f,f^2,f^3,g,gf,gf^2,gf^3\\}$$\r\n    Note that $g^2\\notin g\\langle f\\rangle$, thus $g^2=e$ or $g^2=f^2$ since $g$ does not have order $8$.\\\\\r\n    If $g^2=e$, then $fg=gf\\implies G\\cong C_4\\times C_2$ by Theorem \\ref{direct_product_thm}, otherwise we have $fg=g^3f$, which means that $G\\cong D_8$\\\\\r\n    Otherwise $g^2=f^2$, then $fg\\neq e,f,f^2,f^3$ by inspection.\r\n    Now if $g$ is abelian then $g^2f^{-2}=e\\implies (gf^{-1})^2=e$, $gf^{-1}\\notin\\langle f\\rangle\\implies G\\cong C_4\\times C_2$.\r\n    Otherwise, by inspection $fg=gf^3$, therefore we have defined the group action completely, so it can only be isomorphic to $Q_8$, which is not in any of the preceding cases.\r\n    \\footnote{Alternatively we can easily construct an explicit isomorphism.}\r\n    So the claim is proved.\r\n\\end{proof}\r\n", "meta": {"hexsha": "574bd1ae9256711a7db9c14fc088f7a18cdd9dcc", "size": 5740, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/small.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": "7/small.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": "7/small.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": 57.9797979798, "max_line_length": 402, "alphanum_fraction": 0.6597560976, "num_tokens": 2151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8354835411997897, "lm_q2_score": 0.9124361527383703, "lm_q1q2_score": 0.7623253880085659}}
{"text": "\\section{Vector bundles, principal bundles}\nLet $X$ be a topological space. A point in $X$ can be viewed as a map $\\ast\\to\nX$; this is a cross section of the canonical map $X\\to \\ast$. Motivated by\nthis, we will define a vector space over $B$ to be a space $E\\to B$ over $B$\nwith the following extra data:\n\\begin{itemize}\n    \\item a multiplication $\\mu:E\\times_B E\\to E$, compatible with the maps\n\tdown to $B$;\n    \\item a ``zero'' section $s:B\\to E$ such that the composite $B\\xar{s}E\\to\n\tB$ is the identity;\n    \\item an inverse $\\chi:E\\to E$, compatible with the map down to $B$; and\n    \\item an action of $\\RR$:\n\t\\begin{equation*}\n\t    \\xymatrix{\n\t\t\\RR\\times E\\ar[dr]_{p\\circ \\pr_2}\\ar@{=}[r] &\n\t\t(B\\times\\RR)\\times_B E\\ar[r]\\ar[d] & E\\ar[dl]^p\\\\\n\t\t& B &\n\t    }\n\t\\end{equation*}\n\\end{itemize}\nBecause $\\RR$ is a field, the last piece of data shows that $p^{-1}(b)$ is a\n$\\RR$-vector space for any point $b\\in B$.\n\\begin{example}\\label{trivialvectorbundle}\n    A rather silly example of a vector space over $B$ is the projection\n    $B\\times V\\to B$ where $V$ is a (real) vector space, which we will always\n    assume to be finite-dimensional.\n\\end{example}\n\\begin{example}\n    Consider the map\n    $$\\RR\\times\\RR\\xrightarrow{(s,t)\\mapsto(s,st)}\\RR\\times\\RR,$$\n    over $\\RR$ (the structure maps are given by projecting onto the first\n    factor). It is an isomorphism on all fibers, but is zero everywhere else.\n    The kernel is therefore $0$ everywhere, except over the point $0\\in\\RR$.\n    This the ``skyscraper'' vector bundle over $B$.\n\\end{example}\nSheaf theory accommodates examples like this.\n\nOne can only go so far you can go with this simplistic notion of a ``vector\nspace'' over $B$. Most interesting and naturally arising examples have a little\nmore structure, which is exemplified in the following definition.\n\\begin{definition}\n    A \\emph{vector bundle} over $B$ is a vector space over $B$ that is locally\n    trivial (in the sense of Definition \\ref{fiberbundle}).\n\\end{definition}\n\\begin{remark}\n    We will always assume that the space $B$ admits a numerable open cover (see\n    Definition \\ref{numerable}) which trivializes the vector bundle. Moreover,\n    the dimension of the fiber will always be finite.\n\\end{remark}\nIf $p:E\\to B$ is a vector bundle, then $E$ is called the \\emph{total space},\n$p$ is called the \\emph{projection map}, and $B$ is called the \\emph{base\nspace}. We will always use a Greek letter like $\\xi$ or $\\zeta$ to denote a\nvector bundle, and $E(\\xi)\\to B(\\xi)$ denotes the actual projection map from\nthe total space to the base space. The phrase ``$\\xi$ is a vector bundle over\n$B$'' will also be shortened to $\\xi\\downarrow B$.\n\\begin{example}\\label{grassmannianvb}\n\\begin{enumerate}\n    \\item Following Example \\ref{trivialvectorbundle}, one example of a vector\n\tbundle is the trivial bundle $B\\times\\RR^n\\to B$, denoted by\n\t$n\\epsilon$.\n    \\item In contrast to this silly example, one gets extremely interesting\n\texamples from the Grassmannians $\\Gra_k(\\RR^n)$, $\\Gra_k(\\cC^n)$, and\n\t$\\Gra_k(\\HH^n)$. For simplicity, let $K$ denote $\\RR,\\cC$, or $\\HH$.\n\tOver $\\Gra_k(K^n)$ lies the \\emph{tautological bundle} $\\gamma$. This\n\tis a sub-bundle of $n\\epsilon$ (i.e., the fiber over any point $x\\in\n\t\\Gra_k(K^n)$ is a subspace of the fiber of $n\\epsilon$ over $x$). The\n\ttotal space of $\\gamma$ is defined as:\n\t\\begin{equation*}\n\t    E(\\gamma) = \\{(V,x)\\in\\Gra_k(K^n)\\times K^n:x\\in V\\}\n\t\\end{equation*}\n\tThis projection map down to $\\Gra_k(K^n)$ is the literal projection map\n\t$$(V,x)\\mapsto V.$$\n\t\\begin{exercise}\n\t    Prove that $\\gamma$, as defined above, is locally trivial; so\n\t    $\\gamma$ defines a vector bundle over $\\Gra_k(K^n)$.\n\t\\end{exercise}\n\t    For instance, when $k=1$, we have $\\Gra_1(\\RR^n) = \\RP^{n-1}$. In\n\t    this case, $\\gamma$ is one-dimensional (i.e., the fibers are all of\n\t    dimension $1$); this is called a \\emph{line bundle}. In fact, it is\n\t    the ``canonical line bundle'' over $\\RP^{n-1}$.\n    \\item Let $M$ be a smooth manifold. Define $\\tau_M$ to be the tangent\n\tbundle $TM\\to M$ over $M$. For example, if $M = S^{n-1}$, then\n\t$$TS^{n-1} = \\{(x,v)\\in S^{n-1}\\times\\RR^n:v\\cdot x = 0\\}.$$\n\\end{enumerate}\n\\end{example}\n\\subsection{Constructions with vector bundles}\nOne cannot take the kernels of a map of vector bundles; but just about\nanything which can be done for vector spaces can also be done for vector\nbundles:\n\\begin{enumerate}\n    \\item Pullbacks are legal: if $p^\\prime:E^\\prime\\to B^\\prime$, then the\n\tleftmost map in the diagram below is also a vector bundle.\n\t\\begin{equation*}\n\t    \\xymatrix{\n\t\tE\\ar[r]\\ar[d] & E^\\prime\\ar[d]^{p^\\prime}\\\\\n\t\tB\\ar[r]_f & B^\\prime\n\t\t}\n\t\\end{equation*}\n\tFor instance, if $B=\\ast$, the pullback is just the fiber of $E^\\prime$\n\tover the point $\\ast\\to B^\\prime$. If $\\xi$ is the bundle $E^\\prime\\to\n\tB^\\prime$, we denote the pullback $E\\to B$ as $f^\\ast \\xi$.\n    \\item If $p:E\\to B$ and $p^\\prime:E^\\prime\\to B^\\prime$, then we can take\n\tthe product $E\\times E^\\prime\\xrightarrow{p\\times p^\\prime}B\\times\n\tB^\\prime$.\n    \\item If $B=B^\\prime$, we can form the pullback:\n\t\\begin{equation*}\n\t    \\xymatrix{\n\t\tE\\oplus E^\\prime\\ar[r]\\ar[d] & E\\times E^\\prime\\ar[d]\\\\\n\t\tB\\ar[r]_{\\Delta} & B\\times B\n\t\t}\n\t\\end{equation*}\n\tThe bundle $E\\oplus E^\\prime$ is called the \\emph{Whitney sum}. For\n\tinstance, it is an easy exercise to see that\n\t$$n\\epsilon = \\epsilon\\oplus\\cdots\\oplus\\epsilon.$$\n    \\item If $E,E^\\prime\\to B$ are two vector bundles over $B$, we can form\n\tanother vector bundle $E\\otimes_\\RR E^\\prime\\to B$ by taking the\n\tfiberwise tensor product. Likewise, taking the fiberwise Hom begets a\n\tvector bundle $\\Hom_\\RR(E,E^\\prime)\\to B$.\n\\end{enumerate}\n\\begin{example}\n    Recall from Example \\ref{grassmannianvb}(2) that the tautological bundle\n    $\\gamma$ lives over $\\RP^{n-1}$; we will write $L = E(\\gamma)$. The tangent\n    bundle $\\tau_{\\RP^{n-1}}$ also lives over $\\RP^{n-1}$. As this is the first\n    explicit pair of vector bundles over the same space, it is natural to\n    wonder what is the relationship between these two bundles.\n    \n    At first glance, one might guess that $\\tau_{\\RP^{n-1}} = \\gamma^\\perp$;\n    but this is false! Instead,\n    $$\\tau_{\\RP^{n-1}} = \\Hom(\\gamma,\\gamma^\\perp).$$\n    To see this, note that we have a $2$-fold covering map $S^{n-1}\\to\n    \\RP^{n-1}$; therefore, $T_x(\\RP^{n-1})$ is a quotient of $T(S^n)$ by the\n    map sending $(x,v)\\mapsto (-x,-v)$, where $v\\in T_x(S^n)$. Therefore,\n    $$T_x\\RP^{n-1} = \\{(x,v)\\in S^{n-1}\\times\\RR^n:v\\cdot x =\n    0\\}/((x,v)\\sim(-x,-v)).$$\n    This is exactly the fiber of $\\Hom(\\gamma,\\gamma^\\perp)$ over $x\\in\n    \\RP^{n-1}$, since the line through $x$ can be mapped to the line through\n    $\\pm v$.\n\\end{example}\n\\begin{exercise}\n    Prove that if $\\gamma$ is the tautological vector bundle over\n    $\\Gra_k(K^n)$, for $K=\\RR,\\cC,\\HH$, then\n    $$\\tau_{\\Gra_k(K^n)} = \\Hom(\\gamma,\\gamma^\\perp).$$\n\\end{exercise}\n\\subsection{Metrics and splitting exact sequences}\nA \\emph{metric} on a vector bundle is a continuous choice of inner products on\nfibers.\n\\begin{lemma}\n    Any vector bundle $\\xi$ over $X$ admits a metric.\n\\end{lemma}\nIntuitively speaking, this is true because if $g,g^\\prime$ are both inner\nproducts on $V$, then $tg+(1-t)g^\\prime$ is another. Said differently, the\nspace of metrics forms a real affine space.\n\\begin{proof}\n    Pick a trivializing open cover of $X$, and a subordinate partition of\n    unity. This means that we have a map $\\phi_U:U\\to [0,1]$, such that the\n    preimage of the complement of $0$ is $U$. Moreover,\n    $$\\sum_{x\\in U} \\phi_U(x) = 1.$$\n    Over each one of these trivial pieces, pick a metric $g_U$ on $E|_{U}$.\n    Let\n    $$g \\coloneqq \\sum_{U}\\phi_U g_U;$$\n    this is the desired metric on $\\xi$.\n\\end{proof}\nWe remark that, in general, one cannot pick metrics for vector bundles. For\ninstance, this is the case for vector bundles which arise in algebraic\ngeometry.\n\\begin{definition}\n    Suppose $E,E^\\prime\\to B$ are vector bundles over $B$. An\n    \\emph{isomorphism} is a map $\\alpha:E\\to E^\\prime$ over $B$ that is a\n    linear isomorphism on each fiber.\n\\end{definition}\nIn particular, the map $\\alpha$ admits an inverse (over $B$).\n\\begin{corollary}\\label{split}\n    Any exact\\footnote{This is the obvious definition.} sequence $0\\to\n    E^\\prime\\to E\\to E^{\\prime\\prime}\\to 0$ of vector bundles (over the same\n    base) splits.\n\\end{corollary}\n\\begin{proof}[Proof sketch]\n    Pick a metric for $E$. Consider the composite\n    $${E^\\prime}^\\perp\\subseteq E\\to E^{\\prime\\prime}.$$\n    This is an isomorphism: the dimensions of the fibers are the same. It\n    follows that\n    $$E\\cong E^\\prime\\oplus {E^\\prime}^{\\perp}\\cong E^\\prime\\oplus\n    E^{\\prime\\prime},$$\n    as desired.\n\\end{proof}\nNote that this splitting is not natural.\n", "meta": {"hexsha": "57887e5143f85722d627b3c3f1ff3380eda53d0b", "size": 8808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-52-vector-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-52-vector-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-52-vector-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": 47.1016042781, "max_line_length": 79, "alphanum_fraction": 0.6737057221, "num_tokens": 2851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032941988938413, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7622855488392555}}
{"text": "\\subsection{Infinite plate with a circular hole}\n\\paragraph{}\nIn this example, an infinite plate with a traction free hole under uniaxial tension $(\\sigma = \\SI{1}{\\newton \\per \\square \\meter} )$\nalong x-axis (see Fig.~\\ref{iso_fig:circular_hole_geo_bc}) is considered.\n%\n    \\begin{figure}[h!]\n        \\centering\n        \\scalebox{0.5}{\n            \\includegraphics{isogeometric_sbfem/images/circular_hole_geo_bc.eps}\n        }\n        \\caption{ Infinite plate with a circular hole: geometry and boundary conditions}\n        \\label{iso_fig:circular_hole_geo_bc}\n    \\end{figure}\n%\nThe exact solution of the stresses in polar coordinate $(r,\\theta)$ is given by \\citep{Sukumar2001}:\n    \\begin{subequations}\n        \\begin{align}\n            \\sigma_{x}(r,\\theta) &= 1 - \\frac{a^2}{r^2} \\left(\n                \\frac{3}{2} \\cos2\\theta +\n                \\cos4\\theta\n            \\right) +\n            \\frac{3a^4}{2r^4} \\cos4\\theta\\\\\n            \\sigma_{y}(r,\\theta) &= -\\frac{a^2}{r^2} \\left(\n                \\frac{1}{2} \\cos2\\theta -\n                \\cos4\\theta\n            \\right) -\n            \\frac{3a^4}{2r^4} \\cos4\\theta\\\\\n            \\gamma_{xy}(r,\\theta) &= -\\frac{a^2}{r^2} \\left(\n                \\frac{1}{2} \\sin2\\theta +\n                \\sin4\\theta\n            \\right) -\n            \\frac{3a^4}{2r^4} \\sin4\\theta\n        \\end{align}\n        \\label{iso_eq:ex_chole_stress_sol}\n    \\end{subequations}\n%\nwhere $a$ is the radius of the hole.\nOwing to symmetry, only one quarter of the plate is modeled.\n% Fig. 10 shows a typical control net used for the study.\nThe material properties are: Young’s modulus $E = \\SI{100}{\\newton \\per \\square \\meter}$ and Poisson’s ratio $\\nu = 0.3$.\nThe closed form displacement in Cartesian coordinate is given as\n    \\begin{subequations}\n        \\begin{align}\n            u_x(r,\\theta) = \\frac{R}{8G} \\left[\n                \\frac{r}{R} (\\kappa + 1) \\cos\\theta +\n                2 \\frac{R}{r} \\left(\n                    (1+ \\kappa ) \\cos\\theta +\n                    \\cos3\\theta\n                \\right) -\n                2 \\frac{R^3}{r^3}\\cos3\\theta\n            \\right] \\\\\n            u_y(r,\\theta) = \\frac{R}{8G} \\left[\n                \\frac{r}{R} (\\kappa -3) \\sin\\theta +\n                2 \\frac{R}{r} \\left(\n                    (1 - \\kappa) \\sin\\theta +\n                    \\sin3\\theta\n                \\right) -\n                2 \\frac{R^3}{r^3}\\sin3\\theta\n            \\right]\n        \\end{align}\n    \\label{iso_eq:ex_chole_disp_sol}\n    \\end{subequations}\n%\nwhere $G$ is the shear modulus and $\\kappa$ (Kolosov constant) is defined as\n    \\begin{equation}\n        \\kappa = \\left\\{\n            \\begin{aligned}   \n                3-4 \\nu \\\\\n                \\frac{3- \\nu }{1+ \\nu }    \n            \\end{aligned}\n        \\right.\n    \\label{iso_eq:kolosov_constant}\n    \\end{equation}\n%\nIn this example, analytical tractions in Eq.~\\ref{iso_eq:ex_chole_stress_sol} are applied on the boundary.\nThe left and bottom boundaries are constrained with a roller boundary condition. $u_x=0$ where $y=0$ and $u_y=0$ where $x=0$.\n\n\\paragraph{}\n% result analysis\nThe convergence rate in terms of the displacement norm is shown in Fig.~\\ref{iso_fig:circular_hole_convergence}\nIt is observed that the error decreases as the order of the shape functions is increased.\nAnother unique feature of the proposed method is that the method allows different type or order of shape functions to be employed for different segments of the boundary.\nFor example, in Fig.~\\ref{iso_fig:circular_hole_mesh}, the arc A–B and the line segment B–C can be represented by different basis functions, i.e., the arc can be represented by NURBS and the line segment can be represented by conventional Lagrange basis functions.\nFig.~\\ref{iso_fig:circular_hole_basis} shows the plot of the NURBS basis and Lagrange basis functions.\nIt can be seen that at point B, the shape function is continuous.\nIn order to assess the behavior, we represent the arc with quadratic NURBS and the straight lines with conventional Lagrange shape functions.\nSince the NURBS are interpolatory at the ends, the compatibility requirement is automatically satisfied (see Fig.~\\ref{iso_fig:circular_hole_shape_function_convergence}).\n% The convergence of the relative error in the L 2 and H 1 is shown in Fig. 13.\nThe results from both the approaches converge with mesh refinement\n\n    \\begin{figure}\n        \\begin{subfigure}[b]{0.5\\linewidth}\n            \\centering\n            \\scalebox{1}{\n                \\input{isogeometric_sbfem/images/circular_hole_mesh_1.tikz}\n            }            \n        \\end{subfigure}\n        \\begin{subfigure}[b]{0.5\\linewidth}\n            \\centering\n            \\scalebox{1}{\n                \\input{isogeometric_sbfem/images/circular_hole_mesh_2.tikz}\n            }\n        \\end{subfigure}\n        \\caption[Plate with circular hole: mesh]{\n            Plate with circular hole: control net for two different discretizations.\n            Control points ( \n                \\tikz\\draw[blue,fill=blue] (0,0) circle (.7ex);\n            ), Boundary lines (\n                \\tikz[baseline=-0.5ex]\\draw[blue,thick] (0,0) -- (0.5,0);\n            ), Control polygon (\n                \\begin{tikzpicture}[baseline=-0.5ex]\n                    \\draw[blue,thick,dashed] (0,0) -- (1,0);\n                    \\draw[blue,fill=blue] (0.5,0) circle (.7ex);\n                \\end{tikzpicture}\n            ),\n            Scaling center (\n                \\tikz[baseline=-0.5ex]\\draw[blue] (0,0) circle (0.7ex);\n            ).\n        }\n    \\label{iso_fig:circular_hole_mesh}\n    \\end{figure}\n\n    \\begin{figure}\n        \\begin{subfigure}[b]{1\\linewidth}\n            \\centering\n            \\scalebox{0.7}{\n                \\input{isogeometric_sbfem/images/circular_hole_displacement_convergence.tikz}\n            }\n            \\label{iso_fig:circular_hole_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/circular_hole_energy_convergence.tikz}\n            }\n            \\label{iso_fig:circular_hole_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:circular_hole_convergence}\n    \\end{figure}\n\n    \\begin{figure}\n        \\centering\n        \\scalebox{0.5}{\n            \\includegraphics{isogeometric_sbfem/images/circular_hole_basis.png}\n        }\n        \\caption[NURBS basis functions and Lagrange basis functions]{NURBS basis functions and Lagrange basis functions. It can be seen that at Point $B$, the shape functions are continuous}\n        \\label{iso_fig:circular_hole_basis}\n    \\end{figure}\n\n    \\begin{figure}\n        \\centering\n        \\scalebox{0.5}{\n            \\includegraphics{isogeometric_sbfem/images/circular_hole_shape_function_convergence.png}\n        }\n        \\caption[Infinite plate with a circular hole: Convergence results]{\n            Infinite plate with a circular hole: Convergence results for the relative error in the displacement norm ($L^2$) and\n                the relative error in the energy norm. In this case, the arc is represented with NURBS and Lagrange shape functions.\n        }\n        \\label{iso_fig:circular_hole_shape_function_convergence}\n    \\end{figure}\n\n", "meta": {"hexsha": "7138fd7839c30de489cd7acc2ce602f1cbef2942", "size": 7449, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "isogeometric_sbfem/ex_circular_hole.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_circular_hole.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_circular_hole.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": 44.8734939759, "max_line_length": 264, "alphanum_fraction": 0.6102832595, "num_tokens": 2045, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7622516822495913}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the cofactor matrix and the adjugate of each of the following\n  matrices.\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{rr}\n      1 & 0 \\\\\n      3 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    B =\n    \\begin{mymatrix}{rrr}\n      1  & 0  & 1  \\\\\n      -1 & 1  & -2 \\\\\n      2  & -1 & 3  \\\\\n    \\end{mymatrix},\n    \\quad\n    C =\n    \\begin{mymatrix}{rrr}\n      1 &  1 & 3 \\\\\n      2 &  3 & 1 \\\\\n      1 & -1 & 1 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{ex}\n\n\\begin{ex}\n  For each of the following matrices, determine whether it is\n  invertible by checking whether the determinant is non-zero. If the\n  determinant is non-zero, use the adjugate formula to find the\n  inverse.\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      0 & 2 & 1 \\\\\n      3 & 1 & 0 \\\\\n    \\end{mymatrix},\n    \\quad\n    B =\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 0 \\\\\n      0 & 2 & 1 \\\\\n      3 & 1 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C =\n    \\begin{mymatrix}{rrr}\n      1 & 3 & 3 \\\\\n      2 & 4 & 1 \\\\\n      0 & 1 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    D =\n    \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      0 & 2 & 1 \\\\\n      2 & 6 & 7 \\\\\n    \\end{mymatrix},\n    \\quad\n    E =\n    \\begin{mymatrix}{rrr}\n      1 & 0 & 3 \\\\\n      1 & 0 & 1 \\\\\n      3 & 1 & 0 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\det(A) = -13$ and so $A$ is invertible. This inverse is\n      \\begin{eqnarray*}\n        \\frac{1}{-13}\\begin{mymatrix}{rrr}\n          \\begin{absmatrix}{cc}\n            2 & 1 \\\\\n            1 & 0 \\\\\n          \\end{absmatrix} & -\\begin{absmatrix}{cc}\n            0 & 1 \\\\\n            3 & 0 \\\\\n          \\end{absmatrix} & \\begin{absmatrix}{cc}\n            0 & 2 \\\\\n            3 & 1 \\\\\n          \\end{absmatrix} \\\\\\\\[-1ex]\n          -\\begin{absmatrix}{cc}\n            2 & 3 \\\\\n            1 & 0 \\\\\n          \\end{absmatrix} & \\begin{absmatrix}{cc}\n            1 & 3 \\\\\n            3 & 0 \\\\\n          \\end{absmatrix} & -\\begin{absmatrix}{cc}\n            1 & 2 \\\\\n            3 & 1 \\\\\n          \\end{absmatrix} \\\\\\\\[-1ex]\n          \\begin{absmatrix}{cc}\n            2 & 3 \\\\\n            2 & 1 \\\\\n          \\end{absmatrix} & -\\begin{absmatrix}{cc}\n            1 & 3 \\\\\n            0 & 1 \\\\\n          \\end{absmatrix} & \\begin{absmatrix}{cc}\n            1 & 2 \\\\\n            0 & 2 \\\\\n          \\end{absmatrix}\\end{mymatrix}^T &=&\\frac{1}{-13}\\begin{mymatrix}{rrr}\n          -1 & 3  & -6 \\\\\n          3  & -9 & 5  \\\\\n          -4 & -1 & 2  \\\\\n        \\end{mymatrix}^T\n        \\\\\n              &=& \\def\\arraystretch{1.3}\n                  \\begin{mymatrix}{rrr}\n                    \\frac{1}{13} & -\\frac{3}{13} & \\frac{4}{13} \\\\\n                    -\\frac{3}{13} & \\frac{9}{13} & \\frac{1}{13} \\\\\n                    \\frac{6}{13} & -\\frac{5}{13} & -\\frac{2}{13} \\\\\n                  \\end{mymatrix}.\n      \\end{eqnarray*}\n    \\item $\\det(B) = 7$, so $B$ is invertible. The inverse is\n      $\\displaystyle\n      \\def\\arraystretch{1.3}\n      \\frac{1}{7}\n      \\begin{mymatrix}{rrr}\n        1 & 3 & -6 \\\\\n        -2 & 1 & 5 \\\\\n        2 & -1 & 2 \\\\\n      \\end{mymatrix}^T = \\begin{mymatrix}{rrr}\n        \\frac{1}{7} & -\\frac{2}{7} & \\frac{2}{7} \\\\\n        \\frac{3}{7} & \\frac{1}{7} & -\\frac{1}{7} \\\\\n        -\\frac{6}{7} & \\frac{5}{7} & \\frac{2}{7} \\\\\n      \\end{mymatrix}.$\n    \\item $\\det(C) = 3$, so $C$ is invertible. The inverse is\n      $\\def\\arraystretch{1.3}\n      \\begin{mymatrix}{rrr}\n        1 & 0 & -3 \\\\\n        -\\frac{2}{3} & \\frac{1}{3} & \\frac{5}{3} \\\\\n        \\frac{2}{3} & -\\frac{1}{3} & -\\frac{2}{3} \\\\\n      \\end{mymatrix}$.\n    \\item $\\det(D) = 0$, so $D$ is not invertible.\n    \\item $\\det(E) = 2$, and so $E$ is invertible. The inverse is\n      $\\def\\arraystretch{1.3}\n      \\begin{mymatrix}{rrr}\n        -\\frac{1}{2} & \\frac{3}{2} & 0 \\\\\n        \\frac{3}{2} & -\\frac{9}{2} & 1 \\\\\n        \\frac{1}{2} & -\\frac{1}{2} & 0 \\\\\n      \\end{mymatrix}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Determine whether each of the following matrices is invertible. If\n  so, use the adjugate formula to find the inverse. If the inverse\n  does not exist, explain why.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 1 \\\\\n      1 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      0 & 2 & 1 \\\\\n      4 & 1 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rrr}\n      1 & 2 & 1 \\\\\n      2 & 3 & 0 \\\\\n      0 & 1 & 2 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item $\\det(A) = 1$, so $A$ is invertible. The inverse is\n      $A^{-1} = \\begin{mymatrix}{rr}\n        2 & -1 \\\\\n        -1 & 1 \\\\\n      \\end{mymatrix}$.\n    \\item $\\det(B) = -15$, so $B$ is invertible. The inverse is\n      $\\displaystyle B^{-1} = \\frac{1}{15}\\begin{mymatrix}{rrr}\n        -1 & -1 &  4 \\\\\n        -4 & 11 &  1 \\\\\n        8  & -7 & -2 \\\\\n      \\end{mymatrix}$.\n    \\item $\\det(C) = 0$, so $C$ is not invertible.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the adjugate formula to find the inverse of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      3 & 0 & 3 \\\\\n      -1 & 2 & -3 \\\\\n      -5 & 4 & -3\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    We have\n    \\begin{equation*}\n      \\det(A)=36,\n      \\quad\n      \\cof(A)\n      ~=~ \\begin{mymatrix}{rrr}\n        6  & 12 & 6   \\\\\n        12 & 6  & -12 \\\\\n        -6 & 6  & 6   \\\\\n      \\end{mymatrix},\n      \\quad\n      \\adj(A)\n      ~=~ \\begin{mymatrix}{rrr}\n        6  &  12 & -6 \\\\\n        12 &   6 &  6 \\\\\n        6  & -12 &  6 \\\\\n      \\end{mymatrix},\n    \\end{equation*}\n    and therefore\n    \\begin{equation*}\n      \\def\\arraystretch{1.4}\n      A^{-1}\n      ~=~\n      \\frac{1}{36}\n      \\begin{mymatrix}{rrr}\n        6  &  12 & -6 \\\\\n        12 &   6 &  6 \\\\\n        6  & -12 &  6 \\\\\n      \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{rrr}\n        \\frac{1}{6}  &  \\frac{1}{3} & -\\frac{1}{6} \\\\\n        \\frac{1}{3} &   \\frac{1}{6} &  \\frac{1}{6} \\\\\n        \\frac{1}{6}  & -\\frac{1}{3} &  \\frac{1}{6} \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the adjugate formula to find the inverse of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      1 &  1 & 0 \\\\\n      3 &  1 & 2 \\\\\n      2 & -2 & 5 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    We have\n    \\begin{equation*}\n      \\det(A)\n      ~=~ 2,\n      \\quad\n      \\cof(A)\n      ~=~ \\begin{mymatrix}{rrr}\n        -9 & 11 &  8  \\\\\n        -2 &  2 &  2  \\\\\n        5  & -5 & -4 \\\\\n      \\end{mymatrix},\n      \\quad\n      \\adj(A)\n      ~=~ \\begin{mymatrix}{rrr}\n        -9 & -2 &  5 \\\\\n        11 &  2 & -5 \\\\\n        8  &  2 & -4 \\\\\n      \\end{mymatrix},\n    \\end{equation*}\n    and therefore\n    \\begin{equation*}\n      \\def\\arraystretch{1.4}\n      A^{-1}\n      ~=~\n      \\frac{1}{2}\n      \\begin{mymatrix}{rrr}\n        -9 & -2 &  5 \\\\\n        11 &  2 & -5 \\\\\n        8  &  2 & -4 \\\\\n      \\end{mymatrix}\n      ~=~\n      \\begin{mymatrix}{rrr}\n        -\\frac{9}{2} & -1 & \\frac{5}{2} \\\\\n        \\frac{11}{2} &  1 & -\\frac{5}{2} \\\\\n        4  &  1 & -2 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{ccc}\n      1 & 0 & 0 \\\\\n      0 & \\cos t & -\\sin t \\\\\n      0 & \\sin t & \\cos t \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  Does there exist a value of $t$ for which this matrix fails to be\n  invertible? Explain.\n  \\begin{sol}\n    No. It has non-zero determinant $\\det(A)=\\cos^2 t+\\sin^2 t = 1$ for\n    all $t$, so it is invertible for all $t$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{rrr}\n      1 & t & t^2 \\\\\n      0 & 1 & 2t \\\\\n      t & 0 & 2\n    \\end{mymatrix}.\n  \\end{equation*}\n  Does there exist a value of $t$ for which this matrix fails to be\n  invertible? Explain.\n  \\begin{sol}\n    $\\det(A) = \\begin{absmatrix}{ccc}\n      1 & t & t^2 \\\\\n      0 & 1 & 2t \\\\\n      t & 0 & 2\n    \\end{absmatrix} = t^3+2$,\n    and so $A$ has no inverse when $t=-\\sqrt[3]{2}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{ccc}\n      e^{t} & \\cosh t & \\sinh t \\\\\n      e^{t} & \\sinh t & \\cosh t \\\\\n      e^{t} & \\cosh t & \\sinh t\n    \\end{mymatrix}.\n  \\end{equation*}\n  Does there exist a value of $t$ for which this matrix fails to be\n  invertible? Explain.\n  \\begin{sol}\n    Since the matrix $A$ has two identical rows, we have $\\det(A)=0$\n    for all $t$. So this matrix is non-invertible for all $t$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{ccc}\n      e^{t} & e^{-t}\\cos t & e^{-t}\\sin t \\\\\n      e^{t} & -e^{-t}\\cos t-e^{-t}\\sin t & -e^{-t}\\sin t+e^{-t}\\cos t \\\\\n      e^{t} & 2e^{-t}\\sin t & -2e^{-t}\\cos t\n    \\end{mymatrix}.\n  \\end{equation*}\n  Does there exist a value of $t$ for which this matrix fails to be\n  invertible? Explain.\n  \\begin{sol}\n    \\begin{equation*}\n      \\det \\begin{mymatrix}{ccc}\n        e^{t} & e^{-t}\\cos t & e^{-t}\\sin t \\\\\n        e^{t} & -e^{-t}\\cos t-e^{-t}\\sin t & -e^{-t}\\sin t+e^{-t}\\cos t \\\\\n        e^{t} & 2e^{-t}\\sin t & -2e^{-t}\\cos t%\n      \\end{mymatrix} = 5e^{-t} \\neq 0\n    \\end{equation*}\n    and so this matrix is always invertible.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Use the adjugate formula to find the inverse of the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{ccc}\n      e^{t} & 0 & 0 \\\\\n      0 & \\cos t & \\sin t \\\\\n      0 & \\cos t-\\sin t & \\cos t+\\sin t\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\det \\begin{mymatrix}{ccc}\n        e^{t} & 0 & 0 \\\\\n        0 & \\cos t & \\sin t \\\\\n        0 & \\cos t-\\sin t & \\cos t+\\sin t\n      \\end{mymatrix} = e^{t}.\n    \\end{equation*}\n    Hence the inverse is\n    \\begin{equation*}\n      e^{-t}\\begin{mymatrix}{ccc}\n        1 & 0 & 0 \\\\\n        0 & e^{t}\\cos t+e^{t}\\sin t & -e^t(\\cos t-\\sin t) \\\\\n        0 & -e^{t}\\sin t & e^{t}\\cos t\n      \\end{mymatrix}^T \\\\\n      ~=~ \\begin{mymatrix}{ccc}\n        e^{-t} & 0 & 0 \\\\\n        0 & \\cos t+\\sin t  & -\\sin t \\\\\n        0 & \\sin t-\\cos t  & \\cos t\n      \\end{mymatrix}.\n    \\end{equation*}\n    \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Find the inverse, if it exists, of the matrix\n  \\begin{equation*}\n    A =\n    \\begin{mymatrix}{ccc}\n      e^{t} & \\cos t & \\sin t \\\\\n      e^{t} & -\\sin t & \\cos t \\\\\n      e^{t} & -\\cos t & -\\sin t\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{equation*}\n      \\def\\arraystretch{1.3}\n      \\begin{mymatrix}{ccc}\n        e^{t} & \\cos t & \\sin t \\\\\n        e^{t} & -\\sin t & \\cos t \\\\\n        e^{t} & -\\cos t & -\\sin t\n      \\end{mymatrix}^{-1} \\\\\n      ~=~\\begin{mymatrix}{ccc}\n        \\frac{1}{2}e^{-t} & 0 & \\frac{1}{2}e^{-t} \\\\\n        \\frac{1}{2}\\cos t+\\frac{1}{2}\\sin t & -\\sin t & \\frac{1}{2}\\sin t-\\frac{1}{2}\n        \\cos t \\\\\n        \\frac{1}{2}\\sin t-\\frac{1}{2}\\cos t & \\cos t & -\\frac{1}{2}\\cos t-\\frac{1}{2}\n        \\sin t\n      \\end{mymatrix}.\n    \\end{equation*}\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "25b4dd7b2cffc2942e1097ba4ffdb4d1d77fe676", "size": 11094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Determinants-Applications-Inverse.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Determinants-Applications-Inverse.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Determinants-Applications-Inverse.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.6212471132, "max_line_length": 85, "alphanum_fraction": 0.4484405985, "num_tokens": 4448, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8791467659263148, "lm_q1q2_score": 0.7622516781314805}}
{"text": "\\section{Logarithms}\nThese rules apply to all positive numbers $a$ and $c$ and all $n \\neq 0$. $b$ and $d$ denote the logarithm base and is above 1.\n\\begin{center}\n    \\begin{longtable}{lr}\n        $\\log_b(a \\cdot c) = \\log_b(a) + \\log_b(c)$\n        &\n        $\\log_b\\left(\\frac{a}{c}\\right) = \\log_b(a) - \\log_b(c)$\n        \\\\\n        $\\log_b\\left(a^n\\right) = n \\cdot \\log_b(a)$\n        &\n        $\\log_b\\left(\\sqrt[n]{a}\\right) = \\frac{\\log_b(a)}{n}$\n        \\\\\n        $b^{\\log_b(a)} = a$\n        &\n        $\\log_b{(b^a)} = a$\n        \\\\\n        $\\log_b(b) = 1$\n        &\n        $\\log_b(1) = 0$\n        \\\\\n        $\\log_b(a) = \\frac{\\log_d(a)}{\\log_d(b)}$\n    \\end{longtable}\n\\end{center}\n", "meta": {"hexsha": "fcf68158520cea4644771f01d9b0433a28758c49", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/logarithms.tex", "max_stars_repo_name": "KongBorup/algebraic-tricks", "max_stars_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sections/logarithms.tex", "max_issues_repo_name": "KongBorup/algebraic-tricks", "max_issues_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/logarithms.tex", "max_forks_repo_name": "KongBorup/algebraic-tricks", "max_forks_repo_head_hexsha": "ea3e187203fffdaf03b3bc64994dcf95cf6f80c8", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-01-22T21:54:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-22T21:54:51.000Z", "avg_line_length": 28.9166666667, "max_line_length": 127, "alphanum_fraction": 0.4596541787, "num_tokens": 253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9579122768904644, "lm_q2_score": 0.7956581049086031, "lm_q1q2_score": 0.762170666899352}}
{"text": "\\section{Random Walks}\r\n\\begin{definition}\r\n    A random (or stochastic) process is a sequence of random variables.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A random walk is a stochastic process $(X_n)_{n\\in\\mathbb N}$ such that $X_0=x,X_n=x+Y_1+\\cdots +Y_n$ where $x\\in\\mathbb R$ and $Y_i$ are i.i.d. random variables.\r\n\\end{definition}\r\nNow we focus on the case where $Y_i$ is $1$ with probability $p$ and $-1$ with probability $1-p$ and $x$ is an integer.\r\nWe think of $X_n$ as the fortune of a gambler, and he gets it go up by $1$ with probability $p$ and lose with probability $q=1-p$.\r\nHis objective is to get to $a\\in\\mathbb Z$ before he get to $0$.\r\nWe say this is the event $A$.\r\nLet $h_x=\\mathbb P(A|X_0=x)$, then $h_x=ph_{x+1}+(1-p)h_{x-1},p_a=1,p_0=0$.\r\nFor $p=1/2=1-p$, we get $h_x=x/a$ which is perhaps not surprising.\\\\\r\nFor general $p$, by trying solutions of the form $\\lambda^x$, we get $p\\lambda^2-\\lambda+q=0$, which has solutions $\\lambda=1,q/p$, and plugging in the boundary conditions yield\r\n$$h_x=\\frac{(q/p)^x-1}{(q/p)^a-1}$$\r\nNow we want to estimate the expected time to absorption, that is the smallest $T$ with $X_T\\in\\{0,a\\}$.\r\nWe write $\\tau_x$ for such $T$ with $X_0=x$.\r\nwe have $\\tau_x=1+p\\tau_{x+1}+q\\tau_{x-1},0<x<a,\\tau_0=\\tau_a=0$.\r\nFor $p=1/2=1-p$, we get the solution $\\tau_x=x(a-x)$.\r\nFor general $p$, we get the solution\r\n$$\\tau_x=\\frac{1}{q-p}x-\\frac{a}{q-p}\\frac{(q/p)^x-1}{(q/p)^a-1}$$", "meta": {"hexsha": "08fbf233ad19e9e55003af05b26989d74a652e68", "size": 1431, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "7/walk.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": "7/walk.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": "7/walk.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": 68.1428571429, "max_line_length": 178, "alphanum_fraction": 0.6638714186, "num_tokens": 528, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218391455085, "lm_q2_score": 0.8267118026095991, "lm_q1q2_score": 0.7621636655051403}}
{"text": "\\chapter{Code Snippets}\n\\renewcommand\\thesection{\\thechapter.\\arabic{section}}\n\n\\section{Mass-spring system (Section \\ref{sec:massSpringSystem})}\\label{app:massSpringCode}\n\n\\setlstMAT\n\\begin{lstlisting}\n%% Initialise variables\nfs = 44100;             % sample rate [Hz]\nk = 1 / fs;             % time step [s]\nlengthSound = fs;       % length of the simulation (1 second) [samples]\n\nf0 = 440;               % fundamental frequency [Hz]\nomega0 = 2 * pi * f0;   % angular (fundamental) frequency [Hz]\nM = 1;                  % mass [kg]\nK = omega0^2 * M;       % spring constant [N/m]\n\n%% initial conditions (u0 = 1, d/dt u0 = 0)\nu = 1;                  \nuPrev = 1;\n\n% initialise output vector\nout = zeros(lengthSound, 1);\n\n%% Simulation loop\nfor n = 1:lengthSound\n    \n    % Update equation Eq. %*\\eqrefMatlab[eq:massSpringUpdate] *)\n    uNext = (2 - K * k^2 / M) * u - uPrev; \n    \n    out(n) = u;\n    \n    % Update system states\n    uPrev = u;\n    u = uNext;\nend    \n\\end{lstlisting}\n\n\\section{1D wave equation (Section \\ref{sec:1DWave})}\n\\label{app:1DWave}\n\\begin{lstlisting}\n%% Initialise variables\nfs = 44100;         % Sample rate [Hz]\nk = 1 / fs;         % Time step [s]\nlengthSound = fs;   % Length of the simulation (1 second) [samples]             \n\nc = 300;            % Wave speed [m/s]\nL = 1;              % Length [m]\nh = c * k;          % Grid spacing [m] (from CFL condition)\nN = floor(L/h);     % Number of intervals between grid points\nh = L / N;          % Recalculation of grid spacing based on integer N\n\nlambdaSq = c^2 * k^2 / h^2; % Courant number squared\n\n% Boundary conditions ([D]irichlet or [N]eumann)\nbcLeft = \"D\";            \nbcRight = \"D\"; \n\n%% Initialise state vectors (one more grid point than the number of intervals)\nuNext = zeros(N+1, 1); \nu = zeros(N+1, 1);\n\n%% Initial conditions (raised cosine)\nloc = round(0.8 * N);       % Center location\nhalfWidth = round(N/10);    % Half-width of raised cosine\nwidth = 2 * halfWidth;      % Full width\nrcX = 0:width;              % x-locations for raised cosine\n\nrc = 0.5 - 0.5 * cos(2 * pi * rcX / width); % raised cosine\nu(loc-halfWidth : loc+halfWidth) = rc; % initialise current state  \n\n% Set initial velocity to zero\nuPrev = u;\n\n% Range of calculation \nrange = 2:N;\n\n% Output location\noutLoc = round(0.3 * N);\n\n%% Simulation loop\nfor n = 1:lengthSound\n    \n    % Update equation Eq. %*\\eqrefMatlab[eq:1DwaveUpdate]*)\n    uNext(range) = (2 - 2 * lambdaSq) * u(range) ...\n        + lambdaSq * (u(range+1) + u(range-1)) - uPrev(range); \n    \n    % boundary updates Eq. %*\\eqrefMatlab[eq:1DWaveLeftBound]*)\n    if bcLeft == \"N\"\n        uNext(1) = (2 - 2 * lambdaSq) * u(1) - uPrev(1) ...\n        + 2 * lambdaSq * u(2); \n    end\n\n    % Eq. %*\\eqrefMatlab[eq:1DWaveRightBound]*)\n    if bcRight == \"N\"\n        uNext(N+1) = (2 - 2 * lambdaSq) * u(N+1) - uPrev(N+1) ...\n        + 2 * lambdaSq * u(N); \n    end\n    \n    out(n) = u(outLoc);\n    \n    % Update system states\n    uPrev = u;\n    u = uNext;\nend\n\\end{lstlisting}\n\n\n\\section{2D wave equation (Section \\ref{sec:2Dwave})}\n\\label{app:2DWave}\n\\begin{lstlisting}\n\n%% Initialise variables\nfs = 44100;         % Sample rate [Hz]\nk = 1 / fs;         % Time step [s]\nlengthSound = fs;   % Length of the simulation (1 second) [samples]             \n\nrho = 7850;                     % Material density [kg/m^3]\nH =  0.0005;                    % Thickness [m]\nT = 1000000;                    % Tension per unit length [N/m]\nc = sqrt(T / (rho * H));        % Wave speed [m/s]\n\nLx = 1;                         % Length in x direction [m]\nLy = 2;                         % Length in y direction [m]\n\nh = sqrt(2) * c * k;            % Grid spacing [m]\nNx = floor(Lx/h);               % Number of intervals in x direction\nNy = floor(Ly/h);               % Number of intervals in y direction\nh = min(Lx/Nx, Ly/Ny);          % Recalculation of grid spacing\n\nlambdaSq = c^2 * k^2 / h^2;     % Courant number squared\nh = max(Lx/Nx, Ly/Ny);          % Recalculation of grid spacing\n\n%% Create scheme matrices with Dirichlet boundary conditions \nNxu = Nx - 1;\nNyu = Ny - 1;\nDxx = toeplitz([-2, 1, zeros(1, Nxu-2)]);\nDyy = toeplitz([-2, 1, zeros(1, Nyu-2)]);\n\n% Kronecker sum\nD = kron(speye(Nxu), Dyy) + kron(Dxx, speye(Nyu));\nD = D / h^2;\n\n% Total number of grid points\nNu = Nxu * Nyu;\n    \n%% Initialise state vectors (one more grid point than the number of intervals)\nuNext = zeros(Nu, 1); \nu = zeros(Nu, 1);\n\n%% Initial conditions (2D raised cosine)\nhalfWidth = floor(min(Nx, Ny) / 5);\nwidth = 2 * halfWidth + 1;\nxLoc = floor(0.3 * Nx);\nyLoc = floor(0.6 * Ny);\nxRange = xLoc-halfWidth : xLoc+halfWidth;\nyRange = yLoc-halfWidth : yLoc+halfWidth;\n\nrcMat = zeros(Nyu, Nxu);\nrcMat(yRange, xRange) = hann(width) * hann(width)';\n\n% initialise current state  \nu = reshape(rcMat, Nu, 1); \n\n% Set initial velocity to zero\nuPrev = u;\n\n% Output location\nxOut = 0.45;\nyOut = 0.25;\noutLoc = round((xOut + yOut * Nyu) * Nxu);\nout = zeros(lengthSound, 1);\n\n%% Simulation loop\nfor n = 1:lengthSound\n    \n    %% Update equation Eq. %*\\eqrefMatlab[eq:matrixUpdate2Dwave] *)\n    uNext = (2 * eye(Nu) + c^2 * k^2 * D) * u - uPrev;\n    \n    % Update system states\n    uPrev = u;\n    u = uNext;\n    \nend\n\\end{lstlisting}\n", "meta": {"hexsha": "2042e9ec941f7c620a6597de14fab7328e2a343b", "size": 5209, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "aauPhdCollectionThesis/appendices/codeSnippets.tex", "max_stars_repo_name": "SilvinWillemsen/phdThesis", "max_stars_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "aauPhdCollectionThesis/appendices/codeSnippets.tex", "max_issues_repo_name": "SilvinWillemsen/phdThesis", "max_issues_repo_head_hexsha": "b0a59790e12d0c308a065958c6dc47c8763d8c34", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "aauPhdCollectionThesis/appendices/codeSnippets.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": 28.0053763441, "max_line_length": 91, "alphanum_fraction": 0.578421962, "num_tokens": 1694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9219218348550491, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7621636580220558}}
{"text": "\\chapter{Number theory}\n\n\\section{Modular arithmetic}\n\t\\kactlimport{ModularArithmetic.h}\n\t\\kactlimport{ModInverse.h}\n\t\\kactlimport{ModPow.h}\n\t\\kactlimport{ModSum.h}\n\t\\kactlimport{ModMulLL.h}\n\t\\kactlimport{ModSqrt.h}\n\n\\section{Primality}\n\t\\kactlimport{eratosthenes.h}\n\t\\kactlimport{MillerRabin.h}\n\t\\kactlimport{factor.h}\n\n\\section{Divisibility}\n\t\\kactlimport{euclid.h}\n\t\\kactlimport{Euclid.java}\n\n\t%\\subsection{Bézout's identity}\n\t%For $a \\neq $, $b \\neq 0$, then $d=gcd(a,b)$ is the smallest positive integer for which there are integer solutions to\n\t%$$ax+by=d$$\n\t%If $(x,y)$ is one solution, then all solutions are given by\n\t%$$\\left(x+\\frac{kb}{\\gcd(a,b)}, y-\\frac{ka}{\\gcd(a,b)}\\right), \\quad k\\in\\mathbb{Z}$$\n\n\t%\\kactlimport{phiFunction.h}\n\n\\section{Fractions}\n\t\\kactlimport{ContinuedFractions.h}\n\t\\kactlimport{FracBinarySearch.h}\n\n\\section{Chinese remainder theorem}\n\t\\kactlimport{chinese.h}\n\n\\section{Pythagorean Triples}\n The Pythagorean triples are uniquely generated by\n \\[ a=k\\cdot (m^{2}-n^{2}),\\ \\,b=k\\cdot (2mn),\\ \\,c=k\\cdot (m^{2}+n^{2}), \\]\n with $m > n > 0$, $k > 0$, $m \\bot n$, and either $m$ or $n$ even.\n\n\\section{Primes}\n\t$p=962592769$ is such that $2^{21} \\mid p-1$, which may be useful. For hashing\n\tuse 970592641 (31-bit number), 31443539979727 (45-bit), 3006703054056749\n\t(52-bit). There are 78498 primes less than 1\\,000\\,000.\n\n\tPrimitive roots exist modulo any prime power $p^a$, except for $p = 2, a > 2$, and there are $\\phi(\\phi(p^a))$ many.\n\tFor $p = 2, a > 2$, the group $\\mathbb Z_{2^a}^\\times$ is instead isomorphic to $\\mathbb Z_2 \\times \\mathbb Z_{2^{a-2}}$.\n\n\\section{Estimates}\n\t$\\sum_{d|n} d = O(n \\log \\log n)$.\n\n\tThe number of divisors of $n$ is at most around 100 for $n < 5e4$, 500 for $n < 1e7$, 2000 for $n < 1e10$, 200\\,000 for $n < 1e19$.\n", "meta": {"hexsha": "fa95a2018213690b1f73fe43482ec02d46c85f18", "size": 1787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/number-theory/chapter.tex", "max_stars_repo_name": "deadpool2794/Cp", "max_stars_repo_head_hexsha": "26eab96ef8ea336615fa8d6fadaa8e4d7d6f3a3c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 152, "max_stars_repo_stars_event_min_datetime": "2019-04-09T18:26:41.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T23:19:41.000Z", "max_issues_repo_path": "content/number-theory/chapter.tex", "max_issues_repo_name": "deadpool2794/Cp", "max_issues_repo_head_hexsha": "26eab96ef8ea336615fa8d6fadaa8e4d7d6f3a3c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2020-12-29T03:02:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-29T03:02:22.000Z", "max_forks_repo_path": "content/number-theory/chapter.tex", "max_forks_repo_name": "deadpool2794/Cp", "max_forks_repo_head_hexsha": "26eab96ef8ea336615fa8d6fadaa8e4d7d6f3a3c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 36, "max_forks_repo_forks_event_min_datetime": "2019-11-28T09:27:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-10T18:22:13.000Z", "avg_line_length": 34.3653846154, "max_line_length": 132, "alphanum_fraction": 0.6804700616, "num_tokens": 696, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218370002787, "lm_q2_score": 0.8267117898012105, "lm_q1q2_score": 0.7621636519233203}}
{"text": "%             %\n%%           %%\n%%% CHAPTER %%%\n%%           %%\n%             %\n\n\n\\chapter{Mathematics -- Matrices}\n\n\t\\label{cha::maths:matrix}\n\t\n\nEngineers and scientists use many matrices to describe physical phenomena.\nHence the frequently asked question: \\enquote{how can I write a matrix with \\LaTeX{}}?\nThis chapter answer the question.\n\n\n\n\\section{Packages for matrices}\n\n\n\tAs for the mathematics basics (cf. \\cref{cha::maths:basics}), the \\emph{mathtools} package, which is an upgrade of the well-known and widely used \\emph{amsmath} package, provides everything that is necessary to write matrix computations.\n\t\n\tIn addition, the \\emph{physics} package provides very useful commands to facilitate the creation of specific matrices such as an identity matrix or a zero matrix.\n\t\n\tSo the following lines should be written in the preamble of the document:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\usepackage{mathtools}\n\\usepackage{physics}\n\\end{lstlisting}\n\n\n\n\\section{Writing matrices}\n\n\n\tMatrices can be generated thanks to the \\texttt{matrix} environment which must be used inside a mathematical equation environment.\n\tThe simplest \\LaTeX{} code which generates a matrix is\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\begin{matrix}\n\t\tx_{11} & x_{12} \\\\\n\t\tx_{21} & x_{22}\n\t\\end{matrix} \n\\end{equation*}\n\\end{lstlisting}\n\tand results in\n\t\\begin{equation*}\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\\end{equation*}\n\t\n\t\n\tThere are several variants of \\texttt{matrix} which produce different delimiters surrounding the matrix.\n\tThey are presented here below, with the corresponding environment's name on top of each 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\t\n\t\n\tThe \\emph{mathtools} package offers starred versions of the \\texttt{matrix} environments which allow to pass an optional argument to specify the alignment within the matrix's columns.\n\tA \\LaTeX{} example is shown here below:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{align*}\n\t\\begin{pmatrix}\n\t\t2  & -3 \\\\\n\t\t42 & 0\n\t\\end{pmatrix}\t&& \\text{VS} &&\n\t\\begin{pmatrix*}[r]\n\t\t2  & -3 \\\\\n\t\t42 & 0\n\t\\end{pmatrix*}\n\\end{align*}.\n\\end{lstlisting}\n\tObserve the difference in alignment between \\texttt{pmatrix} (left) and \\texttt{pmatrix*} (right):\n\t\\begin{align*}\n\t\t\\begin{pmatrix}\n\t\t2  & -3 \\\\\n\t\t42 & 0\n\t\t\\end{pmatrix}\t&& \\text{VS} &&\n\t\t\\begin{pmatrix*}[r]\n\t\t2  & -3 \\\\\n\t\t42 & 0\n\t\t\\end{pmatrix*}.\n\t\\end{align*}\n\n\n\n\\section{Facilities for specific matrices}\n\n\n\tThe \\emph{physics} package proposes many commands that make the \\LaTeX{}'s life of scientists and engineers easier.\n\tAmong them, there are commands aiming the easy generation of specific matrices.\n\t\n\t\n\t\n\t\\subsection{Matrices with specific patterns}\n\t\n\t\t\n\t\tIn mathematics, there are specific matrices that are commonly used.\n\t\tThese matrices are specific because they matches a pattern that is immediately recognised.\n\t\tThe most known are the zero matrix, the identity matrix and the diagonal matrix.\n\t\t\n\t\tThe \\emph{physics} package provides commands to automatically generate the desired pattern for an $n \\times m$ matrix, $n$ and $m$ being adapted according to the arguments passed to the commands.\n\t\tAll commands must be placed inside a \\texttt{matrix}-like environment, itself place within an \\texttt{equation}-like environment.\n\t\t\n\t\t\n\t\t\n\t\t\\subsubsection{Zero matrix}\n\t\t\n\t\t\n\t\t\tThe zero matrix is generated with the \\texttt{zeromatrix} command, or the shorter form \\texttt{zmat}.\n\t\t\tThe first argument is the dimension $n$, second argument is the dimension $m$ of the $n \\times m$ matrix.\n\t\t\tIf $m$ is omitted, the command generates a square zero matrix.\n\t\t\t\n\t\t\tA comparison of the equivalent \\LaTeX{} codes\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{align*}\n\t% 3x3 matrix\n\t\\begin{pmatrix} % based on physics\n\t\t\\zmat{3}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix} % regular way\n\t\t0 & 0 & 0 \\\\\n\t\t0 & 0 & 0 \\\\\n\t\t0 & 0 & 0\n\t\\end{pmatrix}\t&& \\text{and} &&\n\t% 3x5 matrix\n\t\\begin{pmatrix} % based on physics\n\t\t\\zmat{3}{5}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix} % regular way\n\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t0 & 0 & 0 & 0 & 0\n\t\\end{pmatrix} \n\\end{align*}\n\\end{lstlisting}\n\t\t\tgenerating\n\t\t\t\\begin{align*}\n\t\t\t\t% 3x3 matrix\n\t\t\t\t\\begin{pmatrix} % based on physics\n\t\t\t\t\t\\zmat{3}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix} % regular way\n\t\t\t\t\t0 & 0 & 0 \\\\\n\t\t\t\t\t0 & 0 & 0 \\\\\n\t\t\t\t\t0 & 0 & 0\n\t\t\t\t\\end{pmatrix}\t&& \\text{and} &&\n\t\t\t\t% 3x5 matrix\n\t\t\t\t\\begin{pmatrix} % based on physics\n\t\t\t\t\t\\zmat{3}{5}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix} % regular way\n\t\t\t\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t\t\t0 & 0 & 0 & 0 & 0 \\\\\n\t\t\t\t\t0 & 0 & 0 & 0 & 0\n\t\t\t\t\\end{pmatrix}.\n\t\t\t\\end{align*}\n\t\t\tshows that using the \\emph{physics} package avoids a fastidious copy-paste work.\n\t\t\n\t\t\n\t\t\n\t\t\\subsubsection{Identity matrix}\n\t\t\n\t\t\n\t\t\tThe identity matrix is generated with the \\texttt{identitymatrix} command, or the shorter form \\texttt{imat}.\n\t\t\tThe argument is the dimension $n$ of the square matrix.\n\t\t\t\n\t\t\t\n\t\t\tComparing the \\enquote{regular} \\LaTeX{} with the code based on \\emph{physics}\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\begin{pmatrix} % based on physics\n\t\t\\imat{3}\n\t\\end{pmatrix}\t\\quad\n\t\\begin{pmatrix} % regular way\n\t\t1 & 0 & 0 \\\\\n\t\t0 & 1 & 0 \\\\\n\t\t0 & 0 & 1\n\t\\end{pmatrix}\n\\end{equation*}\n\\end{lstlisting}\n\t\t\twhile both result in the same display\n\t\t\t\\begin{equation*}\n\t\t\t\t\\begin{pmatrix} % based on physics\n\t\t\t\t\t\\imat{3}\n\t\t\t\t\\end{pmatrix}\t\\quad\n\t\t\t\t\\begin{pmatrix} % regular way\n\t\t\t\t\t1 & 0 & 0 \\\\\n\t\t\t\t\t0 & 1 & 0 \\\\\n\t\t\t\t\t0 & 0 & 1\n\t\t\t\t\\end{pmatrix}\n\t\t\t\\end{equation*}\n\t\t\thighligthts the time saved in this case, especially because the copy-paste is not as efficient as with the zero matrix.\n\t\t\t\n\t\t\n\t\t\n\t\t\\subsubsection{Diagonal matrix}\n\t\t\n\t\t\t\n\t\t\tA diagonal matrix is generated with the \\texttt{diagonalmatrix} command, or the shorter form \\texttt{dmat}.\n\t\t\tThe argument is a list of comma-separated values, the first one being $x_{11}$, the second one being $x_{22}$, and so forth.\n\t\t\tBy default, only the values on the diagonal are printed and the rest is filled with white spaces.\n\t\t\tAn optional argument allows to fill the spaces.\n\t\t\t\n\t\t\tFor instance, the following code\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{align*}\n\t% based on physics\n\t\\begin{pmatrix}\n\t\t\\dmat{a,b,c}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\dmat{1,2,3}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\dmat[0]{1,2,3}\n\t\\end{pmatrix}\t\\\\\n\t% regular way\n\t\\begin{pmatrix}\n\t\ta &   &   \\\\\n\t\t  & b &   \\\\\n\t\t  &   & c\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t1 &   &   \\\\\n\t\t  & 2 &   \\\\\n\t\t  &   & 3\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t1 & 0 & 0 \\\\\n\t\t0 & 2 & 0 \\\\\n\t\t0 & 0 & 3\n\t\\end{pmatrix}\n\\end{align*}\n\\end{lstlisting}\n\t\t\tgenerates\n\t\t\t\\begin{align*}\n\t\t\t\t% based on physics\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\dmat{a,b,c}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\dmat{1,2,3}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\dmat[0]{1,2,3}\n\t\t\t\t\\end{pmatrix},\t\\\\\n\t\t\t\t% regular way\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\ta &   &   \\\\\n\t\t\t\t\t  & b &   \\\\\n\t\t\t\t\t  &   & c\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t1 &   &   \\\\\n\t\t\t\t\t  & 2 &   \\\\\n\t\t\t\t\t  &   & 3\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t1 & 0 & 0 \\\\\n\t\t\t\t\t0 & 2 & 0 \\\\\n\t\t\t\t\t0 & 0 & 3\n\t\t\t\t\\end{pmatrix}.\n\t\t\t\\end{align*}\n\t\t\tThe above example also shows that literal values can be used as well as numerical values.\n\t\t\t\n\t\t\t\n\t\t\tSimilarly to the diagonal matrix, an anti-diagonal matrix can be created with the \\texttt{antidiagonalmatrix} command, or the shorter form \\texttt{admat}.\n\t\t\n\t\t\n\t\t\n\t\t\\subsubsection{Generalised pattern}\n\t\t\n\t\t\n\t\t\tAn $n \\times m$ matrix can be filled with a specific element thanks to the \\texttt{xmatrix} command, or the shorter form \\texttt{xmat}.\n\t\t\tA starred version adds automatic indices.\n\t\t\t\n\t\t\tAs an example, the\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{align*}\n\t% based on physics\n\t\\begin{pmatrix}\n\t\t\\xmat{1}{2}{3}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\xmat*{x}{3}{3}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\xmat*{a}{3}{1}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\xmat*{\\alpha}{1}{3}\n\t\\end{pmatrix}\t\\\\\n\t% regular way\n\t\\begin{pmatrix}\n\t\t1 & 1 & 1 \\\\\n\t\t1 & 1 & 1\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\tx_{11} & x_{12} & x_{13} \\\\\n\t\tx_{21} & x_{22} & x_{23} \\\\\n\t\tx_{31} & x_{32} & x_{33}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\ta_{1} \\\\\n\t\ta_{2} \\\\\n\t\ta_{3}\n\t\\end{pmatrix}\t&&\n\t\\begin{pmatrix}\n\t\t\\alpha_{1} & \\alpha_{2} & \\alpha_{3}\n\t\\end{pmatrix}\n\\end{align*}\n\\end{lstlisting}\n\t\t\t\\LaTeX{} codes produces\n\t\t\t\\begin{align*}\n\t\t\t\t% based on physics\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\xmat{1}{2}{3}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\xmat*{x}{3}{3}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\xmat*{a}{3}{1}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\xmat*{\\alpha}{1}{3}\n\t\t\t\t\\end{pmatrix},\t\\\\\n\t\t\t\t% regular way\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t1 & 1 & 1 \\\\\n\t\t\t\t\t1 & 1 & 1\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\tx_{11} & x_{12} & x_{13} \\\\\n\t\t\t\t\tx_{21} & x_{22} & x_{23} \\\\\n\t\t\t\t\tx_{31} & x_{32} & x_{33}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\ta_{1} \\\\\n\t\t\t\t\ta_{2} \\\\\n\t\t\t\t\ta_{3}\n\t\t\t\t\\end{pmatrix}\t&&\n\t\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\\alpha_{1} & \\alpha_{2} & \\alpha_{3}\n\t\t\t\t\\end{pmatrix}.\n\t\t\t\\end{align*}\n\t\t\tAs observed, the automatic indexing takes the number of lines and columns into account.\n\t\t\tAutomatic indexing is especially useful for general formulae and demonstrations.\n\t\t\tFinally, like for the diagonal matrix, literal (including Greek letters) values can be used.\n\t\t\t\n\t\t\tAt this point, the author believes that the reader is convinced by the power of the \\emph{physics} package to create matrices which match a specific pattern.\n\t\t\t\n\t\n\t\n\t\\subsection{Combinations of patterns}\n\t\n\t\n\t\tEven though the aforementioned commands are usually sufficient for most cases, it is sometimes required to combine patterns together to obtain the desired result.\n\t\tThe \\emph{physics} allow to do so \\footnote{This section can be considered as intended for \\enquote{advanced} users. However, the author thinks that separate it from the rest of the explanations about matrices is non-sense.}.\n\t\t\n\t\t\n\t\tA first possibility consists in creating the pattern and then adding the other elements around.\n\t\tThe\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t\\imat{2} \\\\\n\t\ta & b\n\t\\end{pmatrix}\t\\quad\n\t\\begin{pmatrix}\n\t\ta & b & c \\\\\n\t\t\\zmat{2}{3}\n\t\\end{pmatrix}\n\\end{equation*}\n\\end{lstlisting}\n\t\texample code outputs\n\t\t\\begin{equation*}\n\t\t\t\\begin{pmatrix}\n\t\t\t\t\\imat{2} \\\\\n\t\t\t\ta & b\n\t\t\t\\end{pmatrix}\t\\quad\n\t\t\t\\begin{pmatrix}\n\t\t\t\ta & b & c \\\\\n\t\t\t\t\\zmat{2}{3}\n\t\t\t\\end{pmatrix}.\n\t\t\\end{equation*}\n\t\t\n\t\tHowever, if an element is added on the right or on the left of a pattern, the result is not the one expected, as depicted by the following code:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t\\imat{2} & a \\\\\n\t\t         & b\n\t\\end{pmatrix}\t\\quad\n\t\\begin{pmatrix}\n\t\t         & a \\\\\n\t\t\\imat{2} & b\n\t\\end{pmatrix}\t\\quad\n\t\\begin{pmatrix}\n\t\ta & \\\\\n\t\tb & \\zmat{2}{3}\n\t\\end{pmatrix}.\n\\end{equation*}\n\\end{lstlisting}\n\t\t\\begin{equation*}\n\t\t\t\\begin{pmatrix}\n\t\t\t\t\\imat{2} & a \\\\\n\t\t\t\t         & b\n\t\t\t\\end{pmatrix}\t\\quad\n\t\t\t\\begin{pmatrix}\n\t\t\t\t\t\t & a \\\\\n\t\t\t\t\\imat{2} & b\n\t\t\t\\end{pmatrix}\t\\quad\n\t\t\t\\begin{pmatrix}\n\t\t\t\ta & \\\\\n\t\t\t\tb & \\zmat{2}{3}\n\t\t\t\\end{pmatrix}.\n\t\t\\end{equation*}\n\t\t\n\t\t\n\t\tTo overcome this issue, the \\texttt{matrixquantity} command, or the shorter form \\texttt{mqty}, can be used.\n\t\tIt creates a matrix as a single element.\n\t\t\n\t\tHere follows an example that is explained below:\n\\begin{lstlisting}[language={[LaTeX]TeX}]\n\\begin{equation*}\n\t\\begin{pmatrix}\n\t\t\\mqty{\\imat{2}} & \\mqty{a\\\\b} \\\\\n\t\t\\mqty{c & d}    & e\n\t\\end{pmatrix}\n\\end{equation*}\n\\end{lstlisting}\n\t\t\\begin{equation*}\n\t\t\t\\begin{pmatrix}\n\t\t\t\t\\mqty{\\imat{2}} & \\mqty{a\\\\b} \\\\\n\t\t\t\t\\mqty{c & d}    & e\n\t\t\t\\end{pmatrix}.\n\t\t\\end{equation*}\n\t\tFirstly, the identity matrix is created and embedded in \\texttt{mqty} to be considered as a single element.\n\t\tSecondly, we can add a $2 \\times 1$ vector on the right but he must also be encapsulated in \\texttt{mqty} as the identity matrix is a single element.\n\t\tAt this step, \\LaTeX{} sees a $1 \\times 2$ matrix, even though the displayed result is a $2 \\times 3$ matrix.\n\t\tHence $c$ and $d$ that are embedded in \\texttt{mqty} whereas $e$ is a \\enquote{regular} single element.\n\t\t\n\n% *** End of chapter ***", "meta": {"hexsha": "de601d16e4c900bee342e0405efff6da07987a64", "size": 12907, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tutorials/C101__Maths_Matrices/Mini_guide__maths_matrices.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/Mini_guide__maths_matrices.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/Mini_guide__maths_matrices.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": 26.612371134, "max_line_length": 238, "alphanum_fraction": 0.6309754397, "num_tokens": 4572, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8376199754937772, "lm_q2_score": 0.9099070072595894, "lm_q1q2_score": 0.7621562851223934}}
{"text": "\\section{Introduction to Kernels}\nIn this section, we present the basic definitions and concepts concerning kernels. We begin with the most basic definition of a pre-kernel.\n\\begin{definition}\nLet $V$ be a Hilbert space, and $\\Omega\\subset V$. A \\textbf{pre-kernel} is a continuous function $k:\\Omega\\times \\Omega \\rightarrow \\mathbb{R}$ which is symmetric, i.e. for which\n\\begin{equation}\n k(x,y) = k(y,x).\n\\end{equation}\n\n\\end{definition}\nBelow are some common examples:\n\\begin{itemize}\n \\item Radial-basis functions $k(x,y) = g(\\|x-y\\|_V)$, where $g:[0,\\infty)\\rightarrow \\mathbb{R}$ is a given function. Some simple examples are:\n \\begin{itemize}\n \\item Identity $g(t) = t$\n \\item Exponential $g(t) = e^{-ct}$\n \\item Gaussian $g(t) = e^{-ct^2}$\n \\end{itemize}\n \\item Shift-invariant kernels $k(x,y) = \\phi(x-y)$, where $\\phi(x) = \\phi(-x)$ is an even function.\n \\item Functions of the inner product, i.e. $k(x,y) = g(\\langle x, y\\rangle_V)$.\n\\end{itemize}\n\n\\subsection{Interpolation}\nGiven a collection of datapoints $\\xi_1,...,\\xi_n\\in \\Omega$, we form the prekernel space\n\\begin{equation}\n I_k(\\{\\xi_1,...,\\xi_n\\}) = \\text{span}\\{k(\\cdot, \\xi_i),~i=1,...,n\\}.\n\\end{equation}\nThis is a linear space of real-valued functions on $\\Omega$, spanned by the kernels `centered' at each of the datapoints $\\xi_1,...,\\xi_n$.\n\nGiven function values $f_i = f(\\xi_i)$, a major question is whether we can interpolate the values $f_i$ in $I_k(\\{\\xi_1,...,\\xi_n\\})$, i.e. whether we can find coefficients $a_k$ such that\n\\begin{equation}\n \\sum_{j=1}^n a_jk(x_i,x_j) = f_i\n\\end{equation}\nfor $i=1,...,n$. This of course means that the function\n$$f_n(x) = \\sum_{j=1}^n a_jk(x,x_j)\\in I_k(\\{\\xi_1,...,\\xi_n\\})$$\nmatches $f$ at the datapoints $\\xi_i$.\n\nEvidently, this will always be possible as long as the matrix $(k(\\xi_i,\\xi_j))^n_{i,j = 1}$ is invertible. This leads us to the following two definitions.\n\\begin{definition}\n A pre-kernel $k$ is called an \\textbf{invertible kernel} if the matrix $(k(\\xi_i,\\xi_j))^n_{i,j = 1}$ is non-singular for any $n$ and $\\xi_1,...,\\xi_n\\in \\Omega$.\n\\end{definition}\n\\begin{definition}\n A pre-kernel $k$ is called a \\textbf{positive-definite kernel} or just a \\textbf{kernel} if the matrix $(k(\\xi_i,\\xi_j))^n_{i,j = 1}$ is positive definite for any $n$ and $\\xi_1,...,\\xi_n\\in \\Omega$.\n\\end{definition}\n\nIn either of these cases, the interpolation problem can always we uniquely solved.\n\n\\subsection{Shift-invariant Kernels on $\\mathbb{R}^d$}\nWe now turn to the question of how to determine whether a pre-kernel is invertible or positive-definite. We first consider the case of shift invariant kernels $k(x,y) = \\phi(x-y)$ on $\\Omega = \\mathbb{R}^n$. In this case we determine exactly when a kernel is positive definite in terms of the Fourier transform of $\\phi$. We begin with a lemma (where we aren't being completely rigorous).\n\n\\begin{lemma}\n A kernel is positive definite iff the bilinear form\n \\begin{equation}\n  K(f,g) = \\int_\\Omega\\int_\\Omega f(x)k(x,y)g(y)dxdy\n \\end{equation}\n is positive definite on $L^2(\\Omega)$. Another way of saying this is that the operator $K:L^2(\\Omega)\\rightarrow L^2(\\Omega)$ defined by\n \\begin{equation}\n  K(g)(x) = \\int_\\Omega k(x,y)g(y)dx\n \\end{equation}\n is positive definite.\n\n\\end{lemma}\nHere we have brushed over the technical issue that this map may not be well-defined on $L^2(\\Omega)$ if $\\Omega$ is not compact. Technically, this only holds if the map $K$ above is well-defined on $L^2(\\Omega)$.\n\nSince the kernel $k(x,y) = \\phi(x-y)$ on $\\Omega = \\mathbb{R}^d$ is shift invariant, the above map $K$ is a convolution $K(g) = \\phi*g$. Thus it is diagonalized by the Fourier transform, in particular $\\widehat{K(g)} = \\hat{\\phi}\\hat{g}$. This leads us to the following theorem.\n\\begin{theorem}\n Suppose that $\\phi\\in L^1(\\mathbb{R}^d)$. Then the shift invariant kernel $k(x,y) = \\phi(x-y)$ is positive definite iff $\\hat{\\phi} > 0$.\n\\end{theorem}\n\\begin{proof}\n If $\\phi\\in L^1$, then the map $K:L^2(\\mathbb{R}^d)\\rightarrow L^2(\\mathbb{R}^d)$,\n \\begin{equation}\n  K(g) = \\int_{\\mathbb{R}^d} \\phi(x-y)g(y)dx = \\phi*g\n \\end{equation}\n is well-defined by Young's inequality. Moreover the Fourier transform $\\hat{\\phi}\\in L^\\infty(\\mathbb{R}^d)$. This means that the equation\n \\begin{equation}\n  \\widehat{K(g)} = \\hat{\\phi}\\hat{g}\n \\end{equation}\n holds rigorously. Thus we see that $K$ is positive definite (and thus we have a positive definite kernel) iff $\\hat{\\phi} > 0$.\n\\end{proof}\nNext we give an important corollary, which forms the building block of the radial basis function theory.\n\\begin{corollary}\\label{gaussian-corollary}\n The Gaussian kernel $k_c(x,y) = e^{-c\\|x-y\\|^2}$ is positive definite for any $c > 0$.\n\\end{corollary}\n\\begin{proof}\n This follows since the Gaussian is integrable and it's Fourier transform is another Gaussian (and thus is positive).\n\\end{proof}\n\n\n\\subsection{Radial Basis Functions}\nWe now consider the case of kernels defined via radial basis functions, i.e. $k(x,y) = g(\\|x-y\\|_V)$, for which useful sufficient conditions can be derived. We first consider when we can say that a radial basis kernel is positive definite.\nWe begin with a definition and classical result.\n\n\\begin{definition}\n A smooth function $f:\\mathbb{R}_{\\geq 0}\\rightarrow \\mathbb{R}$ is called \\textbf{completely monotonic} if $(-1)^nf^{(n)}(x) \\geq 0$ for all $x > 0$.\n\\end{definition}\n\nWe have the following characterization of completely monotonic functions.\n\\begin{theorem}[Bernstein-Widder]\n $f$ is completely monotonic iff there exists a positive measure $\\mu$ on $[0,\\infty)$ such that\n \\begin{equation}\n  f(x) = \\int_0^\\infty e^{-cx} d\\mu(c).\n \\end{equation}\n In other words, $f$ is completely monotonic iff it lies in the cone generated by the exponentials $e^{-cx}$ for $c \\geq 0$.\n\\end{theorem}\n\nThis gives us the following fundamental result.\n\n\\begin{theorem}\n If $f$ is completely monotonic and not constant, then the radial basis function $k(x,y) = g(\\|x-y\\|_V) = f(\\|x-y\\|_V^2)$ for $g(x) = f(x^2)$ is positive definite.\n\\end{theorem}\n\\begin{proof}\n Note first that since the number of points $\\xi_1,...,\\xi_n$ is always finite, these datapoints lie in a finite dimensional subspace and we can assume without loss of generality that $\\Omega = \\mathbb{R}^d$ for some finite $d$.\n \n Now we use the Bernstein-Widder theorem to write our kernel $k(x,y)$ as a positive combination of Gaussian kernels, as follows\n \\begin{equation}\n  k(x,y) = f(\\|x-y\\|^2) = \\int_0^\\infty e^{-c\\|x-y\\|^2} d\\mu(c).\n \\end{equation}\n Now since $f$ is non-constant, $\\mu$ is not entirely supported at $0$. Thus $k$ is a positive combination of Gaussians, with at least some weight on $c > 0$. Since the Gaussians are all positive semi-definite (and positive definite for $c > 0$, by corollary \\ref{gaussian-corollary}), we see that $k$ must be positive-definite as well.\n\n\\end{proof}\n\nLet us now give some examples of completely monotonic functions and the associated kernels to which this theorem applies.\n\\begin{itemize}\n \\item Gaussian: $f(x) = e^{-cx}$, $k(x,y) = e^{-c\\|x-y\\|^2}$.\n \\item Multi-quadric: $f(x) = (x^2 + r^2)^{-\\frac{1}{2}}$, $k(x,y) = (x^2 + r^2)^{-1}$\n\\end{itemize}\n\n\\section{Positive-Definite Kernels and Feature Maps}\nIn this section we consider positive definite kernels, their associated reproducting kernel Hilbert spaces, and their feature maps. We begin with the definition of a feature map.\n\\begin{definition}\n A feature map for a kernel $k$ is a Hilbert space $V$ together with a map $\\Phi:\\Omega\\rightarrow V$ such that\n \\begin{equation}\n  k(x,y) = \\langle\\Phi(x), \\Phi(y)\\rangle_V.\n \\end{equation}\n\n\\end{definition}\nIt is clear that if a kernel has a feature map, then it must be positive semi-definite.\n\\begin{lemma}\n If a kernel $k$ has a feature map, then it must be positive semi-definite.\n\\end{lemma}\n\\begin{proof}\n Note that the matrix $(k(x_i,x_j))_{i,j=1}^n$ is the Gram matrix of the vectors $\\Phi(x_1),...,\\Phi(x_n)$ which is positive semi-definite.\n\\end{proof}\n\nNext we address the converse question, i.e. whether a positive semi-definite kernel always has a feature map. For simplicity we consider the case of positive definite kernel $k$.\n\n\\begin{theorem}\n Suppose that $k$ is a positive definite kernel. Then there exists a feature map $\\Phi$ for the kernel $k$.\n\\end{theorem}\n\\begin{proof}\n The proof proceeds by constructing the \\textit{reproducing kernel Hilbert space} $H_k$ corresponding to $k$ and explicitly exhibiting a feature map $\\Phi:\\Omega\\rightarrow H_k$.\n \n We define $H_k$ as follows. Let $S_k = \\text{span}\\{k(\\cdot,x):~x\\in\\Omega\\} \\subset C(\\Omega)$ be the vector space spanned by the kernels centered at each of the points $x\\in\\Omega$. Define a norm on this space by extending the inner product\n \\begin{equation}\n  \\langle k(\\cdot,x), k(\\cdot,y)\\rangle_{H_k} = k(x,y)\n \\end{equation}\n to all finite linear combinations of the kernels. Since $k$ is positive definite, this corresponds to a positive definite norm on $S_k$. Taking the completion of $S_k$ with respect to this norm we obtain the reproducing kernel Hilbert space $H_k$.\n \n It is now easy to check (essentially follows by definition) that the map $\\Phi:\\Omega\\rightarrow H_k$ given by\n \\begin{equation}\n  \\Phi(x) = k(\\cdot,x)\\in H_k\n \\end{equation}\n is a feature map.\n \n\\end{proof}\nWe collect the following definition from the previous proof.\n\\begin{definition}\n Let $k$ be a positive definite kernel. The space $H_k$ in the above proof is called the \\textbf{reproducing kernel Hilbert space} associated to $k$. \n\\end{definition}\n\nWe conclude with a lemma showing that $H_k\\subset C(\\Omega)$ under mild conditions on $k$.\n\n\\begin{lemma}\n Suppose that $k(x,x) < C$ is bounded for all $x\\in \\Omega$. Then $H_k\\subset C(\\Omega)$ and we have the bound\n \\begin{equation}\n  \\|f\\|_{L^\\infty} \\leq \\sqrt{C}\\|f\\|_{H_k}.\n \\end{equation}\n for all $f\\in H_k$.\n\n\\end{lemma}\n\\begin{proof}\n Since $H_k$ is the completion of a subspace of $C(\\Omega)$ with respect to the $H_k$-norm, $\\|f\\|_{L^\\infty} \\leq C\\|f\\|_{H_k}$ implies that $H_k\\subset C(\\Omega)$. To this end, we see that since\n \\begin{equation}\n  \\langle k(\\cdot, x), k(\\cdot, y)\\rangle_{H_k} = k(y,x)\n \\end{equation}\n holds for every $y\\in \\Omega$ and $k(\\cdot, x)$ is a Riesz basis for $H_k$, we have\n \\begin{equation}\n  \\langle f, k(\\cdot, y)\\rangle_{H_k} = f(y)\n \\end{equation}\n holds for every $f\\in H_k$. Thus,\n \\begin{equation}\n  |f(y)| = |\\langle f, k(\\cdot, y)\\rangle_{H_k}| \\leq \\|k(\\cdot, y)\\|_{H_k}\\|f\\|_{H_k}.\n \\end{equation}\n Finally,\n \\begin{equation}\n  \\langle k(\\cdot, y),k(\\cdot, y)\\rangle_{H_k} = k(y,y),\n \\end{equation}\n so that $\\|k(\\cdot, y)\\|_{H_k} \\leq \\sqrt{k(y,y)} \\leq \\sqrt{C}$ as desired.\n\n\n\\end{proof}\n\n\\section{Reproducing Kernel Hilbert Spaces}\nFrom the above discussion, a natural question to ask is which Hilbert spaces can arise as reproducing kernel Hilbert spaces for a given kernel $k$.\n\nA complete answer is given by the following theorem.\n\n\\begin{theorem}\n A Hilbert space $H$ of functions on $\\Omega$ is a reproducing Hilbert space for some kernel $k$ iff the evaluation maps\n \\begin{equation}\n  \\delta_x(f) = f(x),\n \\end{equation}\n are continuous with respect to $\\|\\cdot\\|_H$ for all $x\\in \\Omega$.\n\n\\end{theorem}\n\\begin{proof}\n The proof follows from the Riesz representation theorem. Since the evaluation maps $\\delta_x$ are continuous linear functionals, there exist elements $k(\\cdot, x)\\in H$ such that $\\delta_x(f) = f(x) = \\langle f, k(\\cdot x)\\rangle_H$. These functions $k$ are exactly the kernel of the reproducing Hilbert space.\n\\end{proof}\n\nNote for instance that this theorem tells us that Sobolev spaces of sufficient regularity are reproducing kernel Hilbert spaces. \n\n\\section{Mercer's Theorem}\nIn this section we give Mercer's construction. When $\\Omega$ is compact, this gives a useful feature map which helps elucidate the approximation properties of the kernel.\n\nSuppose that $\\Omega\\subset \\mathbb{R}^d$ is compact and $k$ is positive definite. Then the map $T_k:L^2(\\Omega)\\rightarrow L^2(\\Omega)$ given by\n\\begin{equation}\n T_k(f)(x) = \\int_\\Omega k(x,y)f(y)dy\n\\end{equation}\nis a positive definite, symmetric, compact operator on $L^2(\\Omega)$. Thus it can be diagonalized and has a discrete set of eigenvalues $\\lambda_i\\rightarrow 0$ and corresponding orthonormal eigenfunctions $\\phi_i(x)$. Additionally the kernel can be represented as\n\\begin{equation}\n k(x,y) = \\sum_{i=1}^\\infty \\lambda_i\\phi_i(x)\\phi_i(y).\n\\end{equation}\n\nThis provides the corresponding feature map\n\\begin{equation}\n \\Phi(x) = \\begin{pmatrix}\n            \\sqrt{\\lambda_1}\\phi_1(x) \\\\\n            \\sqrt{\\lambda_2}\\phi_2(x) \\\\\n            \\vdots\n           \\end{pmatrix}\\in \\ell^2(\\mathbb{N}).\n\\end{equation}\n\n\n\\section{Universality}\nNow we come the question of univerality, i.e. when is the reproducing kernel Hilbert space corresponding to a kernel $k$ dense in the space of continuous functions.\n\nThe important lemma is the following.\n\\begin{lemma}\n Let $k$ be a kernel with feature map $\\Phi:\\Omega\\rightarrow V$. Then $k$ is a universal kernel iff\n \\begin{equation}\n  \\overline{\\text{span}}(\\{\\langle \\Phi(x), v\\rangle_V:~v\\in V\\}) = C(\\Omega).\n \\end{equation}\n I.e. if the feature map is dense in $C(\\Omega)$.\n\\end{lemma}\n\n\n\\subsection{Shift-invariant Kernels}\n\n\\subsection{Neural Network Kernels}\nIn this section we consider a deep neural network randomly with randomly initialized weights (appropriately scaled). It turns out the the random function represented by such a network is drawn from a Gaussian process with covariance given by a certain kernel $k$.\n\nConsider a neural network $f(x,\\Theta)$ with input $x\\in \\mathbb{R}^{d_0}$ and output $f(x,\\Theta)\\in \\mathbb{R}^{d_n}$. Here $f$ is defined recursively by \n\\begin{equation}\n\\begin{split}\n f_0(x) &= x \\\\\n f_i(x) &= \\sigma(W_if_{i-1}(x) + b_i) \\\\\n f(x,\\Theta) &= W_nf_{n-1}(x) + b_n,\n \\end{split}\n\\end{equation}\nwhere $\\Theta = W_i\\in \\mathbb{R}^{d_i\\times d_{i-1}}, b_i\\in \\mathbb{R}^{d_i}$ are parameters and $\\sigma$ is an activation functions. \n\nWe now consider the random initialization. Suppose that each entry of the weights $W_i$ are chosen at random with variance $\\frac{c_{i-1}}{d_{i-1}}$ and the bias $b$ is initialized at $0$. This gives us a random function $f(x,\\Theta_0)$ drawn from a distribution on the space of functions $f:\\mathbb{R}^{d_0}\\rightarrow \\mathbb{R}^{d_n}$. Our goal is to analyze this distribution.\n\nBefore we consider the general case, let us consider shallow linear networks, i.e. $\\sigma_i = \\text{id}$ and $n=2$. In this case $\\Theta = W_1, W_2, b_1, b_2$ and \n\\begin{equation}\n f(x,\\Theta_0) = W_2W_1x,\n\\end{equation}\nwhere $W_1\\in \\mathbb{R}^{d_1\\times d_0}$ is chosen uniformly at random with variance $\\frac{c_0}{d_0}$ and $W_2\\in \\mathbb{R}^{d_2\\times d_1}$ independently with variance $\\frac{c_1}{d_1}$. Now let $x,y\\in \\mathbb{R}^{d_0}$ and consider the joint distribution of $f(x,\\Theta_0)\\in \\mathbb{R}^{d_2}$ and $f(y,\\Theta_0)\\in \\mathbb{R}^{d_2}$. We begin by calculating the covariance of the values at $x$ and $y$\n\\begin{equation}\n \\mathbb{E}(f(x,\\Theta_0)f(y,\\Theta_0)^T) = \\mathbb{E}_{W_2}(W_2\\mathbb{E}_{W_1}(W_1xy^TW_1^T)W_2^T).\n\\end{equation}\nWe now easily calculate\n\\begin{equation}\n \\mathbb{E}_{W_1}(W_1xy^TW_1^T) = \\frac{c_0(x^Ty)}{d_0}I_{d_1},\n\\end{equation}\nand so, since $\\mathbb{E}_{W_2}(W_2W_2^T) = c_1I_{d_2}$, we get\n\\begin{equation}\n \\mathbb{E}(f(x,\\Theta_0)f(y,\\Theta_0)^T) = \\frac{c_0c_1(x^Ty)}{d_0}I_{d_2}.\n\\end{equation}\nOne can also easily calculate that this is the same covariance which would be obtained if the hidden layer were removed or if more hidden layers were added. One can also show that as $d_1\\rightarrow \\infty$, the random function $f(x,\\Theta_0)$ converges in distribution to a Gaussian process with the given convariance\n\\begin{equation}\n K(x,y) = \\frac{c_0c_1(x^Ty)}{d_0}I_{d_2}.\n\\end{equation}\n\nAdding in an activation function $\\sigma$ simply changes the covariance, which now becomes\n\\begin{equation}\n \\mathbb{E}(f(x,\\Theta_0)f(y,\\Theta_0)^T) = \\mathbb{E}_{W_2}(W_2\\mathbb{E}_{W_1}(\\sigma(W_1x)\\sigma(y^TW_1^T))W_2^T),\n\\end{equation}\nwhich generally won't have a closed form expression.\n\nNote that if $\\sigma$ is a positively homogeneous function such as the ReLU, then the relative scaling of the $W_i$ doesn't matter, i.e. only the product of their variance is important. However, for non-ReLU activation functions it may be important to give the correct scale for each $W_i$ and the correct initialization schemes are potentially not known. We now summarize this discussion in the following result.\n\\begin{theorem}\n In the limit $d_1,...,d_{n-1}\\rightarrow \\infty$, the randomly initialized function $f(x,\\Theta)$ converges in distribution to a Gaussian process on $\\mathbb{R}^{d_0}$ with covariance\n \\begin{equation}\n  K(x,y) = \\lim_{d_1,...,d_{n-1}\\rightarrow \\infty} \\mathbb{E}(f(x,\\Theta_0)f(y,\\Theta_0)^T).\n \\end{equation}\n This (multidimensional) kernel $K$ cannot in general be computed explicitly except in the linear case, in which case it is given by\n \\begin{equation}\n  K(x,y) = \\left(\\prod_{i=0}^{n-1} c_i\\right)\\frac{x^Ty}{d_0}I_{d_n}.\n \\end{equation}\n\n\\end{theorem}\nFinally, we note that for positively homogenous $\\sigma$ (i.e. a piecewise linear function with discontinuous derivative only at $0$), we can explicitly calculate the diagonal of the kernel $K$. We get\n\\begin{equation}\n K(x,x) = \\left(\\frac{s_l^2 + s_r^2}{2}\\right)^{n-1}\\left(\\prod_{i=0}^{n-1} c_i\\right)\\frac{\\|x\\|^2}{d_0}I_{d_n},\n\\end{equation}\nwhere $s_l$ and $s_r$ are the slopes to the left and right of $0$, respectively. Choosing the $c_i$ appropriately so that this quantity is constant independent of the depth $n$ is exactly He's initialization scheme.\n\n\\subsection{Neural Tangent Kernel}\nWe now proceed to describe the neural tangent kernel, which describes the behavior of the function $f(x,\\Theta_t)$ under a gradient flow on the parameters $\\Theta$ with loss function $L(f)$. Specifically, we consider the gradient flow dynamics\n\\begin{equation}\n \\frac{d}{dt}\\Theta_t = -D_\\Theta\\nabla_\\Theta L(f(\\cdot, \\Theta_t)),\n\\end{equation}\nwhere $D_\\Theta$ is a diagonal preconditioner with diagonal weight $\\frac{1}{d_{i-1}}$ for the weights in $W_i$ and weight $1$ for the biases.\n\nWe consider the network $f(\\cdot, \\Theta_t)$ as a curve in the space of functions $f:\\mathbb{R}^{d_0}\\rightarrow \\mathbb{R}^{d_n}$. The neural tangent kernel (NTK) describes this curve in the infinite width limit ($d_1,...,d_{n-1}\\rightarrow \\infty$). \n\nWe begin with an abstract description of the idea. The object we want to calculate is $\\frac{d}{dt}f(x,\\Theta_t)\\in C(\\mathbb{R}^{d_0}\\rightarrow \\mathbb{R}^{d_n})$ (here $C(\\mathbb{R}^{d_0}\\rightarrow \\mathbb{R}^{d_n})$ is the space of continuous functions from $\\mathbb{R}^{d_0}$ to $\\mathbb{R}^{d_n}$). We want to relate this to the loss function derivative $\\partial_fL\\in C^\\prime(\\mathbb{R}^{d_0}\\rightarrow \\mathbb{R}^{d_n})$, which is the space of $\\mathbb{R}^{d_n}$ valued measures on $\\mathbb{R}^{d_0}$. The chain rule implies that\n\\begin{equation}\n \\left(\\frac{d}{dt}f(\\cdot,\\Theta_t)\\right)(y) = -\\int_{\\mathbb{R}^{d_0}} \\sum_{\\theta\\in \\Theta}D_\\theta \\left(\\frac{d}{d\\theta} f(y, \\Theta_t)\\right)\n \\left(\\frac{d}{d\\theta} f(x, \\Theta_t)\\right)^T \\partial_fL(x) dx.\n\\end{equation}\nHere the neural tangent kernel at $\\Theta_t$ is defined by\n\\begin{equation}\n K^{NT}_t(x,y) = \\sum_{\\theta\\in \\Theta} D_\\theta\\left(\\frac{d}{d\\theta} f(y, \\Theta_t)\\right)\n \\left(\\frac{d}{d\\theta} f(x, \\Theta_t)\\right)^T,\n\\end{equation}\nwhere $D_\\theta$ denotes the diagonal elements of the preconditioner $D_\\Theta$.\n\nAt this point we proceed by considering the case of shallow linear networks and calculate the above quantity. We obtain, using Einstein notation,\n\\begin{equation}\n f(x, \\Theta_t)_i = w^2_{ik}w^1_{kj}x_j + w^2_{ik}b^1_k + b^2_i.\n\\end{equation}\nThis enables us to calculate\n\\begin{equation}\n\\begin{split}\n K^{NT}_t(x,y) = &\\left(\\sum_{k=1}^{d_1} \\frac{1}{d_1}(w^1_{kj}x_j)(w^1_{kl}y_l) + \\frac{b^1_k}{d_1} + 1\\right)I_{d_n} + \\left(\\frac{1}{d_0}x_jy_j + 1\\right) w^2_{ik}w^2_{lk} \\\\\n = &~\\left(\\frac{1}{d_1}(W_1x)^T(W_1y) + b_1^T\\frac{1}{d_1} + 1\\right)I_{d_n} + \\left(\\frac{1}{d_0}x^Ty + 1\\right) W_2W_2^T.\n \\end{split}\n\\end{equation}\n\nThere are now two key observations made. The first is that as $d_1\\rightarrow \\infty$, the initial neural tangent kernel converges almost surely (under the previously considered initialization) to\n\\begin{equation}\n\\begin{split}\n K^{NT}_0(x,y) \\rightarrow &\\left(\\frac{c_0}{d_0}x^Ty + 1\\right)I_{d_n} + \\left(\\frac{1}{d_0}x^Ty + 1\\right) c_1I_{d_n} \\\\\n &= \\left(\\frac{1}{d_0}\\left(c_0 + c_1\\right)x^Ty + c_1 + 1\\right)I_{d_n}\n \\end{split}\n\\end{equation}\n\nThe second, much more subtle observation is that as $d_1\\rightarrow \\infty$, the kernel at time $t$ converges almost surely to the same thing\n\\begin{equation}\n K^{NT}_t(x,y) \\rightarrow K^{NT}_0(x,y) \\rightarrow \\left(\\frac{1}{d_0}\\left(c_0 + c_1\\right)x^Ty + c_1 + 1\\right)I_{d_n}.\n\\end{equation}\n\nThis means that in the infinite width limit the gradient flow in function space is the gradient flow of the functional $L$ with respect to the inner product (on the function space) defined by the neural tangent kernel (which is asymptotically constant)\n\\begin{equation}\n \\langle f, g\\rangle_{NT} = \\int_{\\mathbb{R}^n}\\int_{\\mathbb{R}^n} f(x)K^{NT}_0(x,y)g(y) dx dy.\n\\end{equation}\nIn other words, the flow in function space is given by\n\\begin{equation}\n \\left(\\frac{d}{dt}f(\\cdot,\\Theta_t)\\right)(y) = -\\int_{\\mathbb{R}^{d_0}} \\left(\\frac{1}{d_0}\\left(c_0 + c_1\\right)x^Ty + c_1 + 1\\right)I_{d_n}\\partial_fL(x) dx.\n\\end{equation}\nNotice that for the linear networks, the neural tangent kernel is positive semi-definite and not positive definite. This corresponds to the fact that the linear networks can only represent linear functions, a very small subspace of all continuous functions.\n\nThe neural tangent kernel observation is that essentially the same analysis can be carried out for arbitrarily deep neural networks with more complicated activation functions. In this case the neural tangent kernel $K^{NT}_0(x,y)$ is much more complicated and can't be given in closed form. Nevertheless, it is shown in the original paper that the kernel is positive definite as long as $\\sigma$ is not a polynomial.\n\n\\includepdf[pages=-,pagecommand={},width=\\textwidth]{6DL/HandWrittenNotes/KernelNotes.pdf}\n\\includepdf[pages=-,pagecommand={},width=\\textwidth]{6DL/HandWrittenNotes/Kernels2.pdf}\n", "meta": {"hexsha": "84e58215ddc8faea83b278846448ded78157b138", "size": 22462, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/kernels.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/kernels.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/kernels.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": 59.4232804233, "max_line_length": 541, "alphanum_fraction": 0.7128928858, "num_tokens": 7161, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7621562711901405}}
{"text": "%\\chapter{Connection of 1D CNN and DNN}\n\\section{1D CNN as DNN}\nFirst let us consider a CNN model for 1D date i.e. $x \\in \\mathbb{R}^d$ as:\n$$\n(v\\ast x)_i = \\sum_{k=1}^d w_{i-k+1}x_k, \\quad \\forall i = 1:d+s,\n$$\nwith \n$$\nv \\in \\mathbb{R}^s.\n$$\nThis lead to a $(d+s)\\times d$ Toeplitz type convolutional matrix $T^v$ defined by\n$$\n(T^v)_{i,j} = v_{i-k+1}, \\quad i=1:d+s, k = 1:d.\n$$\n\nThis kind of convolution can be think as ``padding\" for not only data but also kernel.\nSo, this will lead to an increasing of dimensional for output.\n\nHere, we consider ``restriction-activation'' functions as only activation functions,\nand alway only have one channel, so we have the CNN model  as:\n\\begin{equation}\\label{CNN_iteration_vector}\nf^j(x,\\Theta^j) = v^j \\ast( g \\circ f^{j-1})(x,\\Theta^{j-1}) + b^j \\in \\mathbb{R}^{d + (j+1) \\times s }\n\\end{equation}\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},v^j), \\quad \\Theta^0=(v^0, b^0) \n\\end{equation}\nwith \n\\begin{equation}\nf^0(x)=v^0 \\ast x + b^0,\n\\end{equation}\nand \n\\begin{equation}\\label{CNN_finallayer}\nf(x; \\Theta) = f^J.\n\\end{equation}\n\nThen we say that, use CNN to approximate function is in the class:\n$$\n\\mathcal{H} = \\{ \\sum_{i= 1}^{d_J} c_i f^J_i(x): c \\in \\mathbb{R}^{d_J}\\},\n$$\nhere $d_j = d + (j+1)\\times s$, is the dimension of $f^j$. \n\nNow let us consider, we have a one hidden layer DNN model as:\n$$\nf_{DNN} = \\sum_{i=1}^m \\alpha_k g( w_i x + b_k),\n$$ \nthen we can construct \n$$\nW = [w_1, w_2, \\cdots, w_m], \\in \\mathbb{R}^{1\\times(md)},\n$$\nthen we have the next decomposition as\n$$\nW\\ast x = w^{\\hat J-1} \\cdots w^1\\ast w^0 \\ast x,\n$$\nfor \n$$\n\\hat J \\le \\frac{md}{s-1} +2.\n$$\n\nNow, we have a new CNN model as:\n\\begin{equation}\\label{CNN_iteration_vector}\nf^j(x,\\Theta^j) = v^j \\ast \\circ f^{j-1}(x,\\Theta^{j-1}) + b^j \\in \\mathbb{R}^{d + (j+1) \\times s }\n\\end{equation}\nand \n$$\nf^J(x,\\Theta^J) = w^J \\ast ( g\\circ f^{J-1})(x,\\Theta^{J-1}) \\in \\mathbb{R}^{d + (J+1) \\times s },\n$$\nwhere\n\\begin{equation}\n\\Theta^j=(\\Theta^{j-1},v^j), \\quad \\Theta^0=(v^0, b^0) \n\\end{equation}\nwith \n\\begin{equation}\nf^0(x)=v^0 \\ast x + b^0,\n\\end{equation}\nand \n\\begin{equation}\\label{CNN_finallayer}\nf(x; \\Theta) = f^J.\n\\end{equation}\nThen we can choose $w^j$ as delta i.e identity map for $j \\ge \\hat J$, and for the last model\n$$\nf_{CNN} = \\sum_{i= 1}^{d_J} c_i f^J_i(x),\n$$\nwe can have\n$$\nf_{CNN} = f_{DNN},\n$$\nby choosing $c$ coefficients and $b^j$ carefully. [As homework.]\nSo all approximation properties for one hidden layer DNN can be reconstructed for CNN.\n\n\\begin{theorem}\n\tFor one dimensional kernel, we have the decomposition as\n\t$$\n\tW\\ast x = w^{\\hat J-1} \\cdots w^1\\ast w^0 \\ast x.\n\t$$\n\\end{theorem}\n\\begin{proof}\n\tThis proof is in the literature of Daubechies 1992.  Let us define the symbol $\\tilde w$ as a polynomial on $\\mathbb{C}$ by \n\t$$\n\t\\tilde w (z) = \\sum_{i=1}^s w_{i}z^{i-1}.\n\t$$\n\tThe most important result is that\n\t$$\n\t\\tilde w(z) \\tilde v(z) = \\widetilde{(w\\ast v)}(z).\n\t$$\n\tThen we know that for any polynomial with real coefficients it can be decomposed as \n\t$$\n\t\\tilde W(z) = W_M \\Pi_{k=1}^K\\{z^2 - 2\\alpha_kz + (\\alpha_k^2 + \\beta_k^2)\\} \\Pi_{2K+1}^{M-1}(z - \\alpha_k).\n\t$$\n\tThis means that, for $s \\le 2$, we can combine the above decomposition with every $\\tilde w^j(z)$ is a $s-1$-degree of polynomial ans\n\t$$\n\t\\tilde W(z) = \\tilde w^{\\hat J-1}(z)\\cdots \\tilde w^{1}(z)\\tilde w^{0}(z).\n\t$$\n\\end{proof}", "meta": {"hexsha": "d183528b225cc13dda0685a66d4cbaa16ad451d8", "size": 3374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/ReLUDNN-CNN.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/ReLUDNN-CNN.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/ReLUDNN-CNN.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.5964912281, "max_line_length": 134, "alphanum_fraction": 0.632780083, "num_tokens": 1372, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970779778824, "lm_q2_score": 0.8652240947405564, "lm_q1q2_score": 0.7620868544435406}}
{"text": "\\section{Group Actions}\r\n\\begin{definition}\r\n    Let $X$ be a set and let $\\operatorname{Sym}X$ be the group of all bijections $X\\to X$ under composition.\r\n\\end{definition}\r\n\\begin{definition}\r\n    A group $G$ is a permutation group if it is a subgroup of $\\operatorname{Sym}X$ for some set $X$.\r\n    We say it is a permutation group of degree $n$ if $X$ is finite and $|X|=n$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. $S_n=\\operatorname{Sym}\\{1,2,\\ldots,n\\}$ is a permutation group of degree $n$.\r\n    So is $A_n$.\\\\\r\n    2. The group $D_{2n}$ is a permutation group of degree $n$ by thinking about the way it transforms the vertices of a regular $n$-gon.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $G$ be a group and $X$ be a set.\r\n    An action of $G$ on $X$ is a function $\\star:G\\times X\\to X$ satisfying:\\\\\r\n    1. $\\forall x\\in X,1\\star x=x$.\\\\\r\n    2, $\\forall g,h\\in G,x\\in X,(gh)\\star x=g\\star (h\\star x)$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    An action $\\star:G\\times X\\to X$ is equivalent to a homomorphism $\\phi:G\\to\\operatorname{Sym}X$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Take $\\phi(g)(x)=g\\star x$.\r\n\\end{proof}\r\n\\begin{definition}\r\n    We say such a homomorphism $\\phi$ a permutation representation of $G$.\r\n\\end{definition}\r\nIn particular, if $\\phi$ is injective, then $G$ is isomorphic to a subgroup of $\\operatorname{Sym}X$.\r\n\\begin{definition}\r\n    Let $\\star:G\\times X\\to X$ be a group action, then the orbit of an element $x\\in X$ is defined by\r\n    $$\\operatorname{Orb}_G(x)=\\{g\\star x:g\\in G\\}$$\r\n    The stabiliser of it is defined by\r\n    $$G_x=\\{g\\in G:g\\star x=x\\}$$\r\n\\end{definition}\r\n\\begin{theorem}\r\n    Let $\\star:G\\times X\\to X$ be a group action, then for any $x\\in X$ there is a bijection $\\operatorname{Orb}_G(x)\\to G/G_x$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Take $g\\star x\\mapsto gG_x$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    If $G$ is finite, then $|\\operatorname{Orb}_G(x)||G_x|=|G|$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Follows directly.\r\n\\end{proof}\r\n\\begin{remark}\r\n    1. $\\ker\\phi=\\bigcap_{x\\in X}G_x$ is called the kernel of the action.\\\\\r\n    2. The orbits partition $X$.\r\n    If there is only one orbit, then we say the action is transitive.\\\\\r\n    3. The stabilisers of $x,y$ in the same orbit are conjugate subgroups of each other.\r\n    That is, $G_{g\\star x}=gG_xg^{-1}$.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. Given a group $G$, it can act on itself by left multiplication.\r\n    This is called the left regular action.\r\n    The kernel of the action is obviously just the identity.\r\n    So the induced permutation representation makes $G$ isomorphic to a subgroup of $\\operatorname{Sym}G$.\r\n    In particular, if $|G|=n$, then $G$ is isomorphic to a subgroup of the symmetric group $S_n$.\r\n    This is known as Cayley's Theorem.\\\\\r\n    2. Consider a group $G$ and a subgroup $H\\le G$, then $G$ can act on $G/H$ by left multiplication.\r\n    This action is transitive.\r\n    Also the stabiliser of $xH$ is $xHx^{-1}$, so the kernel of the action becomes $\\bigcap_{x\\in X}xHx^{-1}$, the largest normal subgroup of $G$ contained in $H$.\\\\\r\n    3. Let $G$ acts on itself by conjugation, so $g\\star x=gxg^{-1}$.\r\n    In this case, the orbit containing $x$ is called the conjugacy class containing $x$, $\\operatorname{ccl}_G(x)$, and the stabiliser of $x$ is called the centraliser $C_G(x)$ of $x$.\r\n    The kernel $Z(G)$ of the action is called the centre of $G$.\r\n    Note that $G$ can also act by conjugation on any of its normal subgroup.\\\\\r\n    4. Let $X$ be the set of subgroups of the group $G$, then $G$ acts on $X$ by conjugation: $g\\star H=gHg^{-1}$.\r\n    So the stabiliser of $H$ is called the normalizer $N_G(H)$ of $H$.\r\n    It is the largest subgroup of $G$ to contain $H$ as a normal subgroup.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Let $G$ be a nonabelian simple group, and $H<G$ has index $n>1$, then $n\\ge 5$ and $G$ is isomorphic to a subgroup of $A_n$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Consider the action of $G$ acting on the set of left cosets of $H$ by left multiplication.\r\n    This gives a homomorphism $\\phi:G\\to S_n$.\r\n    But $\\ker\\phi$ is normal in $G$.\r\n    It is obviously not the entire group, so $\\phi$ has to be injective, so $G$ is isomorphic to a subgroup of $S_n$.\r\n    We know that $A_n\\lhd S_n$, so $A_n\\cap G\\lhd G$, so either $G\\subset A_n$ or $G\\cap A_n=1$ since $G$ is simple.\r\n    If $G\\cap A_n=1$, we have $G\\cong G/(G\\cap A_n)\\cong GA_n/A_n\\le S_n/A_n\\cong C_2$ by Second Isomorphism Theorem, contradiction.\\\\\r\n    Therefore $G\\le A_n$.\r\n    Finally if $n\\le 4$, $A_n$ does not have a nonabelian simple subgroup by simple exhaustion.\r\n    So $n\\ge 5$.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider the group of rotational symmetries of the icosahedron with $20$ faces, $12$ vertices and $30$ edges with each face an equilateral triangle.\r\n    We have the following table\r\n    \\begin{center}\r\n        \\begin{tabular}{c|c}\r\n            order&number\\\\\r\n            \\hline\r\n            $1$&$41$\\\\\r\n            $2$&$15$\\\\\r\n            $3$&$20$\\\\\r\n            $5$&$24$\\\\\r\n            \\hline\r\n            total&$60$\r\n        \\end{tabular}\r\n    \\end{center}\r\n    Note that $G$ acts on the set of vertices transitively, so $|G|=12\\times 5=60$, hence these are all.\\\\\r\n    The elements of order $2$ are all conjugates, same for elements of order $3$.\r\n    The elements of order $5$ splits into two conjugacy classes, each of size $12$.\\\\\r\n    If $H\\lhd G$, then it must be a union of conjugacy classes including the identity one, but they must have a sum that divides $60$.\r\n    One can check that it can happen iff $H$ is trivial.\r\n    Thus $G$ is simple.\\\\\r\n    We want to show that $G$ is isomorphic to $A_5$.\r\n    We claim that the set of subgroups $H$ of order $4$ removing the identity partitions the $16$ elements of order at most $2$.\r\n    Note that we must have $H\\cong C_2\\times C_2$ since $G$ does not have element of order $4$, so each such subgroups contains $3$ involutions.\r\n    If $g\\in G$ has order $2$, then $g\\in C_G(g)$, so $|C_G(g)|=|G|/|\\operatorname{ccl}_G(g)|=4$, so every involution is contained in a subgroup of order $4$.\\\\\r\n    Suppose $1\\neq g\\in H\\cap K$ where $H,K$ are subgroups of order $4$.\r\n    But the centralizer of $g$ has order $4$ and contains both $H$ and $K$ since $H,K$ are abelian, but they all have size $4$, hence $H=K$.\\\\\r\n    Let $G$ act on the $5$ subgroups of order $4$ by conjugation.\r\n    This gives a homomorphism $\\phi:G\\to\\operatorname{Sym}(X)\\cong S_5$, but since $G$ is simple, $\\phi$ is injective.\r\n    So $G\\le S_5$.\r\n    But again $G\\cap A_5$ can only be $A_5$ by exactly the same trick as the proof of the preceding theorem.\r\n    Since $|G|=|A_5|=60$, we have $G=A_5$.\r\n \\end{example}\r\n ", "meta": {"hexsha": "2edb9e2f43014542f27545212ae19889881bf872", "size": 6737, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2/action.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": "2/action.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": "2/action.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": 56.1416666667, "max_line_length": 185, "alphanum_fraction": 0.648062936, "num_tokens": 2198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.7620868335469061}}
{"text": "\n\\subsection{Bayesian CART}\n\n\\subsubsection{Our prior}\n\nCall the collective parameters of the tree \\(\\Theta =(T, k, r)\\) and \\(\\theta \\).\n\nCollectively our prior is defined by \\(P(\\Theta )\\) and \\(P(\\theta )\\)\n\n\\subsubsection{Bayes' theorem}\n\nWe want to know the posterior given our data \\(X\\).\n\n\\(P(\\Theta | X)=\\dfrac{P(X|\\Theta )P(\\Theta )}{P(X)}\\)\n\n\\(P(\\Theta | X)\\propto P(X|\\Theta )P(\\Theta )\\)\n\n\\subsubsection{Expanded posterior}\n\nWe know explore \\(P(X|\\Theta )\\)\n\n\\(P(X|\\Theta )=\\int P(X| \\theta , \\Theta)P(\\theta)d\\theta \\)\n\nThis means our posterior is:\n\n\\(P(\\Theta | X)\\propto P(\\Theta )\\int P(X| \\theta , \\Theta)P(\\theta)d\\theta \\)\n\n\\subsubsection{Estimation}\n\nThis can be estimated with MCMC.\n\n", "meta": {"hexsha": "8c49f7e7a7e198fd3616b1625c09d9c213bcd71f", "size": 705, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/treesBayesian/01-04-bcart.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/treesBayesian/01-04-bcart.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/treesBayesian/01-04-bcart.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.03125, "max_line_length": 81, "alphanum_fraction": 0.6496453901, "num_tokens": 225, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9546474181553805, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7619869419919193}}
{"text": "\\chapter{DT systems as linear constant coefficient difference equations}\n\nA \\emph{difference equation} is a relation among combinations of two DT functions and shifted versions of them. Similar to differential equations where the solution is a CT function, the solution to a difference equation is a DT function. For example:\n\\[                         \ny[n+1] + \\frac{1}{2}y[n] = x[n] \n\\]\nis a first order, linear, constant-coefficient difference equation. Given $x[n]$ the solution is a function $y[n]$. We can view this as a representation of a DT system, where $x[n]$ is the input signal and $y[n]$ is the output.\n\nThere is a parallel theory to differential equations for solving difference equations. However in this lecture we will focus specifically on the iterative solution of linear, constant-coefficient difference equations and the case when the input is a delta function, as this is all we need for this course.\n\n\\section{Definition of linear constant coefficient difference equation}\n\nA \\emph{linear}, \\emph{constant-coefficient}, difference equation (LCCDE) comes in one of two forms.\n\n\\begin{itemize}\n  \\item Delay form. \n  \\[    \n  \\sum\\limits_{k = 0}^N a_k y[n-k] = \\sum\\limits_{k = 0}^M b_k x[n-k]\n  \\]\n  or\n  \\[\n  a_0y[n] + a_1y[n-1] + \\cdots a_N y[n-N] = b_0 x[n] + \\cdots b_Mx[n-M]\n  \\]\n  \n\\item Advance form. Let $n\\rightarrow n+N$, then the delay form becomes\n  \\[    \n  \\sum\\limits_{k = 0}^N a_k y[n+N-k] = \\sum\\limits_{k = 0}^M b_k x[n+N-k]\n  \\]\n  or \n  \\[\n  a_0y[n+N] + a_1y[n+N-1] + \\cdots a_N y[n] = b_0 x[n+N] + \\cdots b_Mx[n+N-M]\n  \\]\n\\end{itemize}\n\nThe {\\it order} of the system is given by $N$. The delay and advance forms are equivalent because the equation holds for any $n$, and we can move back and forth between them as needed by a constant index-shift.\n\n\\begin{example}[$N=2$, $M=1$]\n  The delay form is\n  \\[\n  a_0y[n] + a_1 y[n-1] + a_2 y[n-2] = b_0 x[n] + b_1 x[n-1]\n  \\]\n  Replacing $n \\rightarrow n+2$, the advance form is\n  \\[\n  a_0 y[n+2] + a_1 y[n+1] + a_2 y[n] = b+0 x[n+2] + b_1 x[n+1]\n  \\]\n  $\\blacksquare$\n\\end{example}\n\nIt will be convenient to define the operator $E^m$ as shifting a DT function by positive $m$, i.e. $E^m x[n] = x[n+m]$, and the operator $D^m$ as shifting a DT function by negative $m$, i.e. $D^m x[n] = x[n-m]$. These are called the advance and delay operators respectively. Then, the advance form of the difference equation using this operator notation is\n\\[\na_0y[n+N] + a_1y[n+N-1] + \\cdots a_N y[n] = b_0 x[n+N] + \\cdots b_Mx[n+N-M]\n\\]\n\\[\na_0 E^Ny + a_1E^{N-1}y + \\cdots a_N y = b_0 E^{N}x + \\cdots b_M E^{N-M}x\n\\]\nFactoring out the advance operators gives\n\\[\n\\underbrace{\\left(a_0E^N + a_1E^{N-1} + \\cdots a_N\\right)}_{Q(E)} y = \\underbrace{\\left(b_M E^{N} + \\cdots b_M E^{N-M}\\right)}_{P(E)} x\n\\]\nor\n\\[\nQ(E)y[n] = P(E)x[n]\n\\]\n\nSimilarly, the delay form of the difference equation using this operator notation is\n\\[\na_0y[n] + a_1y[n-1] + \\cdots a_N y[n-N] = b_0 x[n] + \\cdots b_Mx[n-M]\n\\]\n\\[\na_0y[n] + a_1 Dy + \\cdots a_N D^N y = b_0 x + \\cdots b_MD^M x\n\\]\nNote: The DT delay operator $D$ is similar, but \\emph{not} identical to the derivative operator $D$ in CT.\n\n\\begin{example}\n  Consider the difference equation\n  \\[\n  2y[n+1] + 5y[n] + 2y[n-1] = 2x[n+1]\n  \\]\n  The advance form would be:\n  \\[\n  2y[n+2] + 5y[n+1] + 2y[n] = 2x[n+2]\n  \\]\n  or using the advance operator\n  \\[\n  \\left(2E^2 + 5E + 2\\right)y = 2E^2x\n  \\]\n  with $Q(E) = 2E^2 + 5E + 2$ and $P(E) = 2E^2$.\\\\[1em]\n  The delay form would be:\n  \\[\n  2y[n] + 5y[n-1] + 2y[n-2] = 2x[n]\n  \\]\n  or using the delay operator\n  \\[\n  \\left(2D^2 + 5D + 2\\right)y = 2x\n  \\]\n$\\blacksquare$\n\\end{example}\n\n\\section{Iterative solution of LCCDEs}\n\nDifference equations are different (pun!) from differential equations in that they can be solved by manually running the equation forward using previous values of the output and current and previous values of the input, given some initial conditions. This is called an \\emph{iterative} solution for this reason.\n\nTo perform an iterative solution we need the difference equation in delay form\n\\[\na_0y[n] + a_1y[n-1] + \\cdots a_N y[n-N] = b_0 x[n] + \\cdots b_Mx[n-M]\n\\]\nWe then solve for the current output $y[n]$\n\\[\ny[n] =  - \\left(\\frac{a_1}{a_0}y[n-1] + \\cdots \\frac{a_N}{a_0} y[n-N]\\right) + \\frac{b_0}{a_0} x[n] + \\cdots \\frac{b_M}{a_0}x[n-M]\n\\]\n\nNow lets examine what this expression says in words. To compute the current output $y[n]$ we need the value of the \\emph{previous} $N-1$ outputs, the value of the \\emph{current} input $x[n]$ and $M-1$ \\emph{previous} inputs (and the coefficients). Then we can compute the next output $y[n+1]$ by adding the previous computation result for $y[n]$ to our list of things to remember, and forgetting one previous value of $y$. This can continue as long as we like.\n\n\\begin{example}\n  Consider the first-order difference equation\n  \\[\n  y[n+1] + y[n] = x[n+1]\n  \\]\n  where $y[-1] = 1$ and $x[n] = u[n]$. We first convert this to delay form\n  \\[\n  y[n] = -y[n-1] + x[n]\\; .\n  \\]\n  Then we can compute $y[0]$ as\n  \\[\n  y[0] = -y[-1] + x[0] = -1 + 1 = 0\n  \\]\n  and continuing\n  \\begin{align*}\n  y[1] &= -y[0] + x[1] = 0 + 1 = 1\\\\\n  y[2] &= -y[1] + x[2] = -1 + 1 = 0\\\\\n  y[3] &= -y[2] + x[3] = 0 + 1 = 1\\\\\n  \\mbox{etc.}\n  \\end{align*}\n  We can see that this will continue to give the alternating sequence $1,0,1,0,1,\\cdots$.\n$\\blacksquare$\n\\end{example}\n\n\\section{Solution of the homogeneous LCCDE}\n\nNote the iterative solution does not give us (directly) and analytical expression for the output at arbitrary $n$. We have to start at the initial conditions and compute our way up to $n$. We now consider an analytical solution when the input is zero, the solution to the \\emph{homogeneous} difference equation\n\\[\nQ(E)\\, y = a_0y[n+N] + a_1y[n+N-1] + \\cdots a_N y[n] = 0 \\; .\n\\]\ngiven $N$ sequential auxiliary conditions on $y$.\n\nSimilar to differential equations, the homogeneous solution depends on the roots of the characteristic equation $Q(E)=0$ whose roots are either real or occur in complex conjugate pairs. Let $\\lambda_i$ be the i-th root of $Q(E) = 0$, then the solution is of the form\n\\[\ny[n] = \\sum\\limits_{i=1}^N C_i \\lambda_i^{n}\n\\]\nwhere the parameters $C_i$ are determined from the auxiliary conditions.\n\nFor a real system (when the coefficients of the difference equation are real) and when the roots are complex $\\lambda_{1,2} = |\\lambda|e^{\\pm j\\beta}$, it is cleaner to assume a form for those terms as\n\\[\ny[n] = C |\\lambda|^n\\cos(\\beta n + \\theta)\n\\]\nfor constants $C$ and $\\theta$.\n\n\\begin{example}[First-Order]\n  Find the solution to the first-order homogeneous LCCDE\n  \\[\n  y[n+1] + \\frac{1}{2}y[n] = 0 \\mbox{ with } y[0] = 5 \\; .\n  \\]\n  Note $Q(E) = E + \\frac{1}{2}$ has a single root $\\lambda_1 = -\\frac{1}{2}$. Thus the solution is of the form\n  \\[\n  y[n] = C\\left( -\\frac{1}{2}\\right)^n\n  \\]\n  where the parameter $C$ is found using\n  \\[\n  y[0] = C = 5\n  \\]\n  to give the final solution\n  \\[\n  y[n] = 5\\left( -\\frac{1}{2}\\right)^n\n  \\]\n  $\\blacksquare$  \n\\end{example}\n\n\\begin{example}[Second-Order, Complex Roots]\n  Find the solution to the second-order homogeneous LCCDE\n  \\[\n  y[n+2] + y[n+1] + \\frac{1}{2}y[n] = 0 \\mbox{ with } y[0] = 1 \\mbox{ and } y[1] = 0\\; .\n  \\]\n  Note $Q(E) = E^2 + E + \\frac{1}{2}$ has a pair of complex roots $\\lambda_{1,2} = -\\frac{1}{2} \\pm j\\frac{1}{2}$. Thus the solution is of the form\n  \\[\n  y[n] = C \\left|\\frac{1}{\\sqrt{2}}\\right|^n\\cos\\left(\\frac{3\\pi}{4} n + \\theta\\right)\n  \\]\n  where the parameters are found using\n  \\[\n  y[0] = C\\cos\\left(\\theta\\right) = 1\n  \\]\n  \\[\n  y[1] = C\\frac{1}{\\sqrt{2}}\\cos\\left(\\frac{3\\pi}{4} + \\theta\\right) = 0\n  \\]\n  This is true when\n  \\[\n  C = -\\sqrt{2} \\mbox{ and } \\theta = -\\frac{\\pi}{4} + 2\\pi m\n  \\]\n  or\n  \\[      \n  C = -\\sqrt{2} \\mbox{ and } \\theta = \\frac{3\\pi}{4} + 2\\pi m\n  \\]\n  for any $m\\in \\mathbb{Z}$ since $\\cos$ is periodic in $2\\pi$. A final solution is then\n  \\[\n  y[n] = -\\sqrt{2} \\left|\\frac{1}{\\sqrt{2}}\\right|^n\\cos\\left(\\frac{3\\pi}{4} n - \\frac{\\pi}{4}\\right)\n  \\]\n  $\\blacksquare$\n\\end{example}\n\n\\section{Impulse response from LCCDE}\n\nToday our goal is to find the solution to $Q(E)y=P(E)x$ when $x[n] = \\delta[n]$ assuming $y[n] = 0$ for $n < 0$, giving the \\emph{impulse response} $y[n] = h[n]$. We skip the derivation here and just give a procedure.\n\n\\textbf{Step 1:} Let $y_h$ be the homogeneous solution to $Q(E)y_h=0$ for $n > N$.\n\n\\textbf{Step 2:} Assume a form for $h[n]$ given by\n\\[\nh[n] = \\frac{b_N}{a_N}\\delta[n] + y_h[n]u[n]\n\\]\n\n\\textbf{Step 3:} Using the iterative procedure above find the $N$ auxiliary conditions we need by,\n\n\\begin{itemize}\n\\item first, rewrite the equation in delay form and solving for $y[n]$,\n\\item then let $x[n] = \\delta[n]$ and manually compute $h[0]$ assuming $h[n] = 0$ for $n < 0$,\n\\item repeating the previous step for $h[1]$, continuing up to $h[N-1]$.\n\\end{itemize}\n\n\\textbf{Step 4:} Using the auxillary conditions in step 3, solve for the constants in the solution $h[n]$ from step 2.\n\n\\begin{example}\n\n  Find the impulse response of the system given by\n  \\[\n  y[n+2] -\\frac{1}{4}y[n+1] -\\frac{1}{8}y[n]= 2x[n+1]\n  \\]\n\n  For step 1 we solve the equation\n  \\[\n  y_h[n+2] -\\frac{1}{4}y_h[n+1] -\\frac{1}{8}y_h[n] = 0\n  \\]\n  which is of the form\n  \\[\n  y_h[n] = C_1 \\left( -\\frac{1}{4}\\right)^n + C_2 \\left( \\frac{1}{2}\\right)^n\n  \\]\n  since the roots of $Q(E) = E^2 - \\frac{1}{4}E - \\frac{1}{8}$ are $-\\frac{1}{4}$ and $\\frac{1}{2}$.\n\n  For step 3, we find the auxiliary conditions needed to find $C_1$ and $C_2$ by rewriting the original equation in delay form and solving for $y[0]$ and $y[1]$ when $x[n] = \\delta[n]$.\n  \\[\n  y[n] = \\frac{1}{4}y[n-1] + \\frac{1}{8}y[n-2] + 2x[n-1]\n  \\]    \n  Let $x[n] = \\delta[n]$ and manually compute $y[0]$ assuming $y[n] = 0$ for $n < 0$\n  \\[\n  y[0] = \\frac{1}{4}\\underbrace{y[0-1]}_{0} + \\frac{1}{8}\\underbrace{y[0-2]}_{0} + 2\\underbrace{\\delta[0-1]}_{0} = 0\n  \\]\n  Repeat for $y[1]$\n  \\[\n  y[1] = \\frac{1}{4}\\underbrace{y[1-1]}_{0} + \\frac{1}{8}\\underbrace{y[1-2]}_{0} + 2\\underbrace{\\delta[1-1]}_{1} = 2\n  \\]  \n  Now we find the constants using step 4\n  \\[\n  h[0] = C_1  + C_2  = 0\n  \\]\n  \\[\n  h[1] = C_1 \\left( -\\frac{1}{4}\\right) + C_2 \\left( \\frac{1}{2}\\right) = 2\n  \\]\n  which gives $C_1 = -\\frac{8}{3}$ and $C_2 = \\frac{8}{3}$. Thus the final impulse response is\n  \\[\n  h[n] = \\frac{b_N}{a_N}\\delta[n] + y_h[n]u[n] = -\\frac{8}{3}\\left( -\\frac{1}{4}\\right)^nu[n] + \\frac{8}{3}\\left( \\frac{1}{2}\\right)^n u[n]\n  \\]\n  since $b_N = 0$.\n$\\blacksquare$\n\\end{example}\n\n  Note we can confirm our closed-form result in the previous example, for a few values of $n$, by iteratively solving the difference equation\n  \\[\n    h[0] = \\frac{1}{4}\\underbrace{h[0-1]}_{0} + \\frac{1}{8}\\underbrace{h[0-2]}_{0} + 2\\underbrace{\\delta[0-1]}_{0} = 0\n  \\]\n  \\[\n      h[1] = \\frac{1}{4}\\underbrace{h[1-1]}_{0} + \\frac{1}{8}\\underbrace{h[1-2]}_{0} + 2\\underbrace{\\delta[1-1]}_{1} = 2\n    \\]\n    \\[\n      h[2] = \\frac{1}{4}\\underbrace{h[2-1]}_{2} + \\frac{1}{8}\\underbrace{h[2-2]}_{0} + 2\\underbrace{\\delta[2-1]}_{0} = \\frac{1}{2}\n    \\]\n    \\[\n      h[3] = \\frac{1}{4}\\underbrace{h[3-1]}_{\\frac{1}{2}} + \\frac{1}{8}\\underbrace{h[3-2]}_{2} + 2\\underbrace{\\delta[2-1]}_{0} = \\frac{3}{8}\n    \\]\n    and comparing to our closed-form solution a the same values of $n$\n    \\[\n    h[0] = -\\frac{8}{3} + \\frac{8}{3} = 0\n    \\]\n    \\[\n    h[1] = -\\frac{8}{3}\\left( -\\frac{1}{4}\\right) + \\frac{8}{3}\\left( \\frac{1}{2}\\right) = 2\n    \\]\n    \\[\n    h[2] = -\\frac{8}{3}\\left( -\\frac{1}{4}\\right)^2 + \\frac{8}{3}\\left( \\frac{1}{2}\\right)^2 = \\frac{1}{2}\n    \\]\n    \\[\n    h[3] = -\\frac{8}{3}\\left( -\\frac{1}{4}\\right)^3 + \\frac{8}{3}\\left( \\frac{1}{2}\\right)^3 = \\frac{3}{8}\n    \\]\n\n\\begin{example}\n  Find the impulse response of the system given by\n  \\[\n  y[n+1] - \\frac{1}{2}y[n] = x[n+1] + x[n]\n  \\]\n\n  In step 1 we note the solution to $Q(E)y[n] = 0$ is of the form\n  \\[\n  y_h[n] = C\\left( \\frac{1}{2}\\right)^n\n  \\]\n  From step 2 we note $b_N = 1$ and $a_N = -\\frac{1}{2}$, so that\n  \\[\n  h[n] = -2\\delta[n]  +  C\\left( \\frac{1}{2}\\right)^n\\, u[n]\n  \\]\n  In step 3 we manually find $h[0]$\n  \\begin{align*}\n    y[n] &= \\frac{1}{2}y[n-1] + x[n] + x[n-1]\\\\\n    h[n] &= \\frac{1}{2}y[n-1] + \\delta[n] + \\delta[n-1]\\\\\n    h[0] &= 0 + 1 + 0 = 1\n  \\end{align*}\n  And in step 4 we solve for $C$\n  \\[\n  h[0] = -2  +  C = 1 \\mbox{ implies } C = 3\n  \\]\n  to give\n  \\[\n  h[n] = -2\\delta[n]  +  3\\left( \\frac{1}{2}\\right)^n\\, u[n]\n  \\]\n  $\\blacksquare$\n\\end{example}\n\n", "meta": {"hexsha": "9b3e053a64f5b0decdce4981db634fccc6028540", "size": 12447, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "05-dt-lccde.tex", "max_stars_repo_name": "clwyatt/notes-2714", "max_stars_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "05-dt-lccde.tex", "max_issues_repo_name": "clwyatt/notes-2714", "max_issues_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "05-dt-lccde.tex", "max_forks_repo_name": "clwyatt/notes-2714", "max_forks_repo_head_hexsha": "4715455db62b5455a05e274f25c5b9fb21ed7573", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4909638554, "max_line_length": 460, "alphanum_fraction": 0.607857315, "num_tokens": 4920, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7619593411839767}}
{"text": "\\section{Multivariable Functions}\r\n\\noindent\r\nMultivariable functions take several values as an input and return a single value as an output.\\\\\r\nFor example, $ z =x^2 + y^2$ takes $\\mathbb{R}^2 \\to \\mathrm{R}$.\\\\\r\nAlthough we can only graph and fully visualize up to $\\mathbb{R}^2 \\to \\mathbb{R}$ as a surface, we can imagine a multivariable function with 3 inputs ($\\mathbb{R}^3 \\to \\mathbb{R}$) as a heatmap in 3D space. However, most of the mathematics we will discuss applies to functions with any number of inputs.\\\\\r\n\r\n\\noindent\r\nThe domain of a multivariable function $f: \\mathbb{R}^n \\to \\mathbb{R}$ is the largest set of points on which $f$ is defined.\\\\\r\nFor example, if $f(x,y) = \\ln{\\left(9-x^2-y^2\\right)}$, the domain of $f(x,y)$ is $\\left\\{ (x,y) | x^2+y^2<9 \\right\\}$.", "meta": {"hexsha": "04136e60289dc918579d26ce96d1f2638109bc3a", "size": 784, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/multivariableFunctions.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/multivariableFunctions.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/multivariableFunctions.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": 87.1111111111, "max_line_length": 308, "alphanum_fraction": 0.6951530612, "num_tokens": 259, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122113355091, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7619008795031732}}
{"text": "% !TeX root = ../main.tex\r\n\\documentclass[../main.tex]{subfiles}\r\n\\begin{document}\r\n\\section{Preliminary}\r\n\\subsection{Tensor}\r\n\\begin{equation}\\label{Tensor:Sum}\r\n\\tensor{\\left(A+B\\right)}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n=\r\n\\tensor{A}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n+\r\n\\tensor{B}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n\\end{equation}\r\n\\begin{equation}\\label{Tensor:Product:Scalar}\r\n\\tensor{\\left(\\alpha A\\right)}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n=\r\n\\alpha\r\n\\tensor{A}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n\\end{equation}\r\n\\begin{equation}\\label{Tensor:Product:Tensor}\r\n\\tensor{\\left(A\\otimes B\\right)}{\r\n^{i_1}^{\\dots}^{i_l}^{i_{l+1}}^{\\dots}^{i_{l+n}}\r\n_{j_1}_{\\dots}_{j_k}_{j_{k+1}}_{\\dots}_{j_{k+m}}\r\n}\r\n=\r\n\\tensor{A}{\r\n^{i_1}^{\\dots}^{i_l}\r\n_{j_1}_{\\dots}_{j_k}\r\n}\r\n\\tensor{B}{\r\n^{i_{l+1}}^{\\dots}^{i_{l+n}}\r\n_{j_{k+1}}_{\\dots}_{j_{k+m}}\r\n}\r\n\\end{equation}\r\n\\begin{equation}\\label{Tensor:Contraction}\r\n\\tensor{\\left(\\contr{\\tensor{T}{}}\\right)}{\r\n^{i_1}^{\\dots}^{i_n}\r\n_{j_1}_{\\dots}_{j_m}\r\n}\r\n=\r\n\\sum_a{\\tensor{T}{\r\n^{i_1}^{\\dots}^{i_n}^a\r\n_a_{j_1}_{\\dots}_{j_m}\r\n}}\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Product}\r\n\\tensor{\\left(AB\\right)}{^i_j}\r\n=\\contr{\\left(A\\otimes B\\right)}\r\n=\\sum_k\\tensor{A}{^i_k}\\tensor{B}{^k_j}\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Product:Block}\r\n\\left(\\begin{bmatrix}\r\nA_{11}&A_{12} \\\\\r\nA_{21}&A_{22} \\\\\r\n\\end{bmatrix}\r\n\\begin{bmatrix}\r\nB_{11}&B_{12} \\\\\r\nB_{21}&B_{22} \\\\\r\n\\end{bmatrix}\\right)_{ij}\r\n=\r\n\\sum_k A_{ik} B_{kj}\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Identity}\r\nIA = A = AI\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Identity:Value}\r\nI_n=\\diag{\\left(1,1,\\dots,1\\right)}\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Identity:Block}\r\nI_{a+b}=\r\n\\begin{bmatrix}\r\nI_a&0_{a\\times b} \\\\\r\n0_{b\\times a}&I_b           \\\\\r\n\\end{bmatrix}\r\n\\end{equation}\r\n\\begin{equation}\\label{Matrix:Permutation:Square}\r\nT_{a,b} T_{a,b}= I\r\n\\end{equation}\r\n\\subsection{Differential}\r\n\\begin{equation}\r\nJ_xF = \\left(\\left.\\frac{\\partial F_i}{\\partial x_j}\\right|_x\\right)_{i,j}\r\n\\end{equation}\r\n\\begin{equation}\r\n\\left.Df\\right|_x\r\n: T_x\\R^k\\to T_{f(x)}\\R^n\r\n= \\left(x,v\\right) \\mapsto \\left(f(x),J_xf(v)\\right)\r\n\\end{equation}\r\n\\subsection{Group}\r\n\\begin{definition}[Lie group {\\autocite[][Chapter~7]{lee_2013}}]\\label{Group:Lie}\r\nA \\textit{Lie group} is a smooth manifold \\(G\\) (without boundary)\r\nthat is also a group in the algebraic sense,\r\nwith the property that\r\nthe multiplication map \\(m\\colon G\\times G\\to G\\)\r\nand the inversion map \\(i\\colon G\\to G\\), given by\r\n\\[\r\nm\\left(g,h\\right)=gh\\text{,}\r\n\\quad\\quad\r\ni\\left(g\\right)=g^{-1}\r\n\\]\r\nare both smooth.\r\n\\end{definition}\r\n\\begin{proposition}[Lie group {\\autocite[][Chapter~7]{lee_2013}}]\\label{Group:Lie:Assertion}\r\nIf \\(G\\) is a smooth manifold with a group structure such that the map \\(G\\times G\\to G\\) given by \\(\\left(g,h\\right)\\mapsto gh^{-1}\\) is smooth, then \\(G\\) is a Lie group.\r\n\\end{proposition}\r\n\\begin{definition}[Semidirect product]\\label{Group:SemidirectProduct}\r\nSuppose \\(H\\) and \\(N\\) are groups,\r\nand \\(\\theta\\colon H\\times N\\to N\\) is a smooth left action of \\(H\\) on \\(N\\).\r\nIt is said to be an \\textit{action by automorphisms}\r\nif for each \\(h\\in H\\), the map \\(\\theta_h\\colon N\\to N\\) is a group automorphism of \\(N\\) (i.e., an isomorphism from \\(N\\) to itself).\r\nGiven such action, we define a new group \\(N\\rtimes_\\theta H\\),\r\ncalled a \\textit{semidirect product} of \\(H\\) and \\(N\\), as follows.\r\n\\(N\\rtimes_\\theta H\\) is just the Cartesian product \\(N\\times H\\);\r\nbut the group multiplication is defined by\r\n\\[\\left(n,h\\right)\\left(n^\\prime,h^\\prime\\right)=\\left(n\\theta_h\\left(n^\\prime\\right),hh^\\prime\\right)\\text{.}\\]\r\n\\end{definition}\r\n\\begin{definition}\\label{OrthogonalGroup}\r\nAn orthogonal group \\(O\\left(n\\right)\\) is a group of orthogonal matrix \\(M\\) where \\(M^{-1}=M^T\\) with matrix multiplication.\r\n\\end{definition}\r\n\\begin{definition}\\label{SpecialOrthogonalGroup}\r\nAn special orthogonal group \\(SO\\left(n\\right)\\) is a subgroup of the orthogonal group \\(O\\left(n\\right)\\) whose element \\(M\\) have the property that \\(\\det{M}=1\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{IndefiniteOrthogonalGroup}\r\nAn indefinite orthogonal group \\(O\\left(m,n\\right)\\) is a group of indefinite orthogonal matrix \\(M\\) where \\(M^{-1}=gM^Tg\\) for \\(g=\\diag{\\left(-1,\\dots,-1,1,\\dots,1\\right)}\\) with matrix multiplication.\r\n\\end{definition}\r\n\\begin{definition}\\label{OrthochronusIndefiniteOrthogonalGroup}\r\nAn orthochronus indefinite orthogonal group \\(O^{+}\\left(m,n\\right)\\) is a subgroup of the indefinite orthogonal group \\(O\\left(m,n\\right)\\) whose element \\(M\\) have the property that \\(\\tensor{M}{^1_1}>0\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{SpecialOrthochronusIndefiniteOrthogonalGroup}\r\nAn special orthochronus indefinite orthogonal group \\(SO^{+}\\left(m,n\\right)\\) is a subgroup of the orthochronus indefinite orthogonal group \\(O^{+}\\left(m,n\\right)\\) whose element \\(M\\) have the property that \\(\\det{M}=1\\).\r\n\\end{definition}\r\n\\begin{definition}\\label{TranslationGroup}\r\nAn translation group \\(T\\left(n\\right)\\) is a group of vectors in \\(\\R^n\\) with vector addition.\r\n\\end{definition}\r\n\\begin{definition}\\label{EuclideanGroup}\r\nAn euclidean group \\(E\\left(n\\right)\\) is a semidirect product of orthogonal group \\(O\\left(n\\right)\\) extended by translation group \\(T\\left(n\\right)\\).\r\n\\end{definition}\r\n\\subsection{Manifold}\r\n\\begin{definition}[Abstract differentiable manifold {\\autocite[][Chapter~5A]{kuhnelwolfgang_2006}}]\\label{Manifold}\r\nA \\textit{\\(k\\)-dimensional differentiable manifold} (briefly: a \\(k\\)-manifold)\r\nis a set \\(M\\) together with a family \\(\\left(M_i\\right)_{i\\in I}\\) of subsets such that\r\n\\begin{APAenumerate}\r\n\\item \\(M=\\bigcup_{i\\in I} M_i\\) (union),\r\n\\item for every \\(i\\in I\\) there is an injective map \\(\\varphi_i\\colon M_i\\to\\R^k\\) so that \\(\\phi_i\\left(M_i\\right)\\) is open in \\(\\R^k\\), and\r\n\\item for \\(M_i\\cap M_j\\ne\\emptyset\\), \\(\\varphi_i\\left(M_i\\cap M_j\\right)\\) is open in \\(\\R^k\\).\r\n\\end{APAenumerate}\r\n\\end{definition}\r\n\\begin{definition}[Structures on a manifold {\\autocite[][Chapter~5A]{kuhnelwolfgang_2006}}]\\label{Manifold:Extended}\r\nGiven a \\(k\\)-dimensional differentiable manifold,\r\none gets additional structure\r\nby replacing aditional requirements on the transformation functions \\(\\varphi_j\\circ\\varphi_i^{-1}\\),\r\nwhich belong to the atlas of the manifold;\r\nif all \\(\\varphi_j\\circ\\varphi_i^{-1}\\) are (left-hand side),\r\nthen one speaks of (right-hand side) as follows:\r\n\\begin{center}\r\n\\begin{tabular}{ r c l }\r\ncontinuous&\\(\\iff\\)&topological manifold                                 \\\\\r\ndifferentiable&\\(\\iff\\)&differentiable manifold                              \\\\\r\n\\(C^1\\)-differentiable&\\(\\iff\\)&\\(C^1\\)-manifold                                       \\\\\r\n\\(C^r\\)-differentiable&\\(\\iff\\)&\\(C^r\\)-manifold                                       \\\\\r\n\\(C^\\infty\\)-differentiable&\\(\\iff\\)&\\(C^\\infty\\)-manifold                                  \\\\\r\nreal analytic&\\(\\iff\\)&real analytic manifold                               \\\\\r\ncomplex analytic&\\(\\iff\\)&complex analytic manifold of dimension \\(\\frac{k}{2}\\) \\\\\r\naffine&\\(\\iff\\)&affine manifold                                      \\\\\r\nprojective&\\(\\iff\\)&projective manifold                                  \\\\\r\nconformal&\\(\\iff\\)&manifold with a conformal structure                  \\\\\r\norienatation-preserving&\\(\\iff\\)&orientable manifold                                  \\\\\r\n\\end{tabular}\r\n\\end{center}\r\n\\end{definition}\r\n\\begin{definition}[Tangent vector {\\autocite[][Chapter~5B]{kuhnelwolfgang_2006}}]\\label{Manifold:TangentVector}\r\nA \\textit{tangent vector} \\(X\\) at \\(p\\)\r\nis a derivation (derivative operator) defined on the set of \\textit{germs of functions}\r\n\\[\\mathcal{F}_p\\left(M\\right)\\coloneqq\\Set{f\\colon M\\to\\R|f\\text{ differentiable}}/\\sim\\text{,}\\]\r\nwhere the equivalence relation \\(\\sim\\) is defined by\r\ndeclaring \\(f\\sim f^\\ast\\) if and only if\r\n\\(f\\) and \\(f^\\ast\\) coincide in a neighborhood of \\(p\\).\r\nThe value \\(X\\left(f\\right)\\) is also referred to as the \\textit{directional derivative} of \\(f\\) in the direction \\(X\\).\r\nThis definition means more precisely the following.\r\n\\(X\\) is a map \\(X\\colon\\mathcal{F}_p\\left(M\\right)\\to\\R\\)\r\nwith the two following properties:\r\n\\begin{APAenumerate}\r\n\\item \\(X\\left(\\alpha f+\\beta g\\right)=\\alpha X\\left(f\\right)+\\beta\\left(g\\right)\\), \\(f,g\\in\\mathcal{F}_p\\left(M\\right)\\) (\\textit{\\(\\R\\)-linearity});\r\n\\item \\(X\\left(f\\cdot g\\right)=X\\left(f\\right)\\cdot g\\left(p\\right)+f\\left(p\\right)\\cdot X\\left(g\\right)\\) for \\(f,g\\in\\mathcal{F}_p\\left(M\\right)\\) (\\textit{product rule}).\r\n\\end{APAenumerate}\r\n(For this to make sense, both \\(f\\) and \\(g\\) have to be defined in a neighborhood of \\(p\\).)\r\nBriefly: \\textit{tangent vectors are derivations acting on scalar functions.}\r\n\\end{definition}\r\n\\begin{corollary}[Tangent space {\\autocite[][Chapter~5B]{kuhnelwolfgang_2006}}]\\label{Manifold:TangentSpace}\r\nThe \\textit{tangent space} \\(T_pM\\) of \\(M\\) at \\(p\\)\r\nis defined in all cases as\r\nthe set of all tangent vectors at the point \\(p\\).\r\nBy definition \\(T_pM\\) and \\(T_qM\\) are disjoint if \\(p\\ne q\\).\r\n\\end{corollary}\r\n\\begin{definition}[Riemannian metric {\\autocite[][Chapter~5C]{kuhnelwolfgang_2006}}]\\label{Manifold:RiemannianMetric}\r\nA \\textit{Riemannian metric} \\(g\\) on \\(M\\)\r\nis an association \\(p\\mapsto g_p\\in L^2\\left(T_pM;\\R\\right)\\)\r\nsuch that the following conditins are satisfied:\r\n\\begin{APAenumerate}\r\n\\item \\(g_p\\left(X,Y\\right)=g_p\\left(Y,X\\right)\\) for all \\(X\\), \\(Y\\), \\hfill (\\textit{symmetry})\r\n\\item \\(g_p\\left(X,X\\right)>0\\) for all \\(X\\ne0\\), \\hfill (\\textit{positive definiteness})\r\n\\item The coefficient \\(\\tensor{g}{_i_j}\\) in every local representation (i.e., in every chart) \\[g_p=\\sum_{i,j}\\tensor{g}{_i_j}\\left(p\\right)\\cdot \\left.d\\tensor{x}{^i}\\right|_p \\otimes\\left.d\\tensor{x}{^j}\\right|_p\\] are differentiable functions. \\hfill (\\textit{differentiability})\r\n\\end{APAenumerate}\r\n\\end{definition}\r\n\\begin{remark}\\label{Manifold:Riemannian}\r\nThe pair \\(\\left(M,g\\right)\\) is then called \\textit{Riemannian manifold}.\r\nOne also refers to the Riemannian metric as the \\textit{metric tensor}.\r\nIn local coordinates the metric tensor is given by the matrix (\\(\\tensor{g}{_i_j}\\)) of functions.\r\nIn Ricci calculus this is simply written as \\(\\tensor{g}{_i_j}\\).\r\n{\\autocite[][Chapter~5C]{kuhnelwolfgang_2006}}\r\n\\end{remark}\r\n\\begin{remark}\\label{Manifold:InnerProduct}\r\nA Riemannian metric \\(g\\) defines at every point \\(p\\)\r\nan \\textit{inner product} \\(g_p\\) on the tangent space \\(T_pM\\),\r\nand therefore the notation \\(\\inner{X}{Y}\\) instead of \\(g_p\\left(X,Y\\right)\\) is also used.\r\nThe notions of angles and lengths are determined by this inner product,\r\njust as these notions are determined by the first fundamental form on surface elements.\r\nThe length or norm of vector \\(X\\) is given by \\(\\norm{X}\\coloneqq\\sqrt{g\\left(X,X\\right)}\\),\r\nand the angle \\(\\beta\\) between two tangent vectors \\(X\\) and \\(Y\\)\r\ncan be defined by the validity of the equation \\(\\cos\\beta\\cdot\\norm{X}\\cdot\\norm{Y}=g\\left(X,Y\\right)\\).\r\n{\\autocite[][Chapter~5C]{kuhnelwolfgang_2006}}\r\n\\end{remark}\r\n\\subsection{Curvature}\r\n\\begin{definition}[The Lie bracket {\\autocite[][Chapter~5D]{kuhnelwolfgang_2006}}]\\label{Manifold:LieBracket}\r\nLet \\(X\\), \\(Y\\) be (differentiable) vector fields on \\(M\\),\r\nand let \\(f\\colon M\\to\\R\\) be a differentiable function.\r\nThrough the relation\r\n\\[\r\n\\left[X,Y\\right]\\left(f\\right)\r\n\\coloneqq\r\nX\\left(Y\\left(f\\right)\\right)\r\n- Y\\left(X\\left(f\\right)\\right)\r\n\\]\r\nwe define a vector field \\(\\left[X,Y\\right]\\),\r\nwhich is referred to as the \\textit{Lie bracket} of \\(X\\), \\(Y\\)\r\n(also called the \\textit{Lie derivative} \\(\\mathcal{L}_XY\\) of \\(Y\\) in the direction \\(X\\)).\r\nAt a point \\(p\\in M\\) we have \\(\\left[X,Y\\right]_p\\left(f\\right)=X_p\\left(Yf\\right)-Y_p\\left(Xf\\right)\\).\r\n\\end{definition}\r\n\\begin{lemma}[Properties of the Lie bracket {\\autocite[][Chapter~5D]{kuhnelwolfgang_2006}}]\\label{Manifold:LieBracket:Property}\r\nLet \\(X\\), \\(Y\\), \\(Z\\) be vector fields,\r\nlet \\(\\alpha\\), \\(\\beta\\) be real constants,\r\nand let \\(f, h\\colon M\\to\\R\\) be differentiable functions.\r\nThen the Lie bracket has the following properties:\r\n\\begin{APAenumerate}\r\n\\item \\(\\left[\\alpha X+\\beta Y, Z\\right]=\\alpha\\left[X,Z\\right]+\\beta\\left[Y,Z\\right]\\);\r\n\\item \\(\\left[X,Y\\right]=-\\left[Y,X\\right]\\);\r\n\\item \\(\\left[fX,hY\\right]=f\\cdot h\\cdot\\left[X,Y\\right]+f\\cdot\\left(Xh\\right)\\cdot Y-h\\cdot\\left(Yf\\right)\\cdot X\\);\r\n\\item \\(\\left[X,\\left[Y,Z\\right]\\right]+\\left[Y,\\left[Z,X\\right]\\right]+\\left[Z,\\left[X,Y\\right]\\right] = 0\\); (\\textit{Jacobi identity})\r\n\\item \\(\\left[\\frac{\\partial}{\\partial\\tensor{x}{^i}}, \\frac{\\partial}{\\partial\\tensor{x}{^j}}\\right]=0\\) for every chart with coordinates (\\(\\tensor{x}{^1},\\dots,\\tensor{x}{^n}\\));\r\n\\item \\(\\left[\\sum_i\\tensor{\\xi}{^i}\\frac{\\partial}{\\partial\\tensor{x}{^i}},\\sum_j\\tensor{\\eta}{^j}\\frac{\\partial}{\\partial\\tensor{x}{^j}}\\right]=\\sum_{i,j}\\left(\\tensor{\\xi}{^i}\\frac{\\partial\\tensor{\\eta}{^j}}{\\partial\\tensor{x}{^i}}-\\tensor{\\eta}{^i}\\frac{\\partial\\tensor{\\xi}{^j}}{\\partial\\tensor{x}{^i}}\\right)\\frac{\\partial}{\\partial\\tensor{x}{^j}}\\) (\\textit{representation in local coordinates}).\r\n\\end{APAenumerate}\r\n\\end{lemma}\r\n\\begin{definition}[Riemannian connection {\\autocite[][Chapter~5D]{kuhnelwolfgang_2006}}]\\label{Manifold:Connection}\r\nA \\textit{Riemannian connection} \\(\\nabla\\) (pronounced \"nabla\")\r\non a Riemannian manifold \\(\\left(M,g\\right)\\) is a map\r\n\\[\\left(X,Y\\right)\\mapsto\\nabla_XY\\text{,}\\]\r\nwhich associates to two given differentiable vector fields \\(X\\), \\(Y\\)\r\na third differentiable vector field \\(\\nabla_XY\\),\r\nsuch that the following conditions are satisfied: (\\(f\\colon M\\to\\R\\) denotes a differentiable function):\r\n\\begin{APAenumerate}\r\n\\item \\(\\nabla_{X_1+X_2}Y=\\nabla_{X_1}Y+\\nabla_{X_2}Y\\); (\\textit{additivity in the subscript})\r\n\\item \\(\\nabla_{fX}Y=f\\cdot\\nabla_{X}Y\\); (\\textit{linearity in the subscript})\r\n\\item \\(\\nabla_X\\left(Y_1+Y_2\\right)=\\nabla_XY_1+\\nabla_XY_2\\); (\\textit{additivity in the argument})\r\n\\item \\(\\nabla_X\\left(fY\\right)=f\\cdot\\nabla_XY+\\left(X\\left(f\\right)\\right)\\cdot Y\\); (\\textit{product rule in the argument})\r\n\\item \\(X\\left(g\\left(Y,Z\\right)\\right)=g\\left(\\nabla_XY,Z\\right)+g\\left(Y,\\nabla_XZ\\right)\\); (\\textit{compatibility with the metric})\r\n\\item \\(\\nabla_XY-\\nabla_YX-\\left[X,Y\\right]=0\\). (\\textit{symmetry or torsion-freeness})\r\n\\end{APAenumerate}\r\n\\end{definition}\r\n\\begin{remark}\r\nWe get the following expression for \\(\\nabla_XY\\), in local coordinates, provided \\(X=\\sum_i\\tensor{\\xi}{^i}\\frac{\\partial}{\\partial\\tensor{x}{^i}}\\) and \\(Y=\\sum_j\\tensor{\\eta}{^j}\\frac{\\partial}{\\partial\\tensor{x}{^j}}\\):\r\n\\[\r\n\\nabla_XY=\\sum_k\\left(\\sum_i\\tensor{\\xi}{^i}\\frac{\\partial\\tensor{\\eta}{^k}}{\\partial\\tensor{x}{^i}}+\\sum_{i,j}\\tensor{\\Gamma}{^k_i_j}\\tensor{\\xi}{^i}\\tensor{\\eta}{^j}\\right)\\frac{\\partial}{\\partial\\tensor{x}{^k}}\\text{.}\r\n\\]\r\nEspecially for \\(X=\\frac{\\partial}{\\partial\\tensor{x}{^i}}\\) we obtain\r\n\\[\r\n\\nabla_XY=\\sum_k\\left(\\frac{\\partial\\tensor{\\eta}{^k}}{\\partial\\tensor{x}{^i}}+\\sum_j\\tensor{\\Gamma}{^k_i_j}\\tensor{\\eta}{^j}\\right)\\frac{\\partial}{\\partial\\tensor{x}{^k}}\\text{.}\r\n\\]\r\nConsequently, in Ricci calculus the notation for this formular is\r\n\\[\r\n\\nabla_i\\tensor{\\eta}{^k}=\\frac{\\partial\\tensor{\\eta}{^k}}{\\partial\\tensor{x}{^i}}+\\tensor{\\Gamma}{^k_i_j}\\tensor{\\eta}{^j}\\text{.}\r\n\\]\r\n\\end{remark}\r\n\\begin{definition}[Christoffel symbols {\\autocite[][Chapter~4A]{kuhnelwolfgang_2006}}]\\label{Manifold:ChristoffelSymbol}\r\n\\;\\newline\r\n\\begin{APAenumerate}\r\n\\item The quantities \\(\\partial_k\\tensor{\\Gamma}{_i_j}\\) defined by the expressions\r\n\\[\r\n\\partial_k\\tensor{\\Gamma}{_i_j}\r\n\\coloneqq\r\n\\inner{\\nabla_{\\frac{\\partial f}{\\partial\\tensor{u}{^i}}}\\frac{\\partial f}{\\partial\\tensor{u}{^j}}}{\\frac{\\partial f}{\\partial\\tensor{u}{^k}}}\r\n\\]\r\nare called the \\textit{Christoffel symbols of the first kind}.\r\n\\item The quantities \\(\\tensor{\\Gamma}{^k_i_j}\\) defined by the expressions\r\n\\[\r\n\\nabla_{\\frac{\\partial f}{\\partial\\tensor{u}{^i}}}\\frac{\\partial f}{\\partial\\tensor{u}{^j}}\r\n=\r\n\\sum_k{\\tensor{\\Gamma}{^k_i_j}\\frac{\\partial f}{\\partial\\tensor{u}{^k}}}\r\n\\]\r\nare called the \\textit{Christoffel symbols of the second kind}.\r\n\\item By definition one has \\(\\partial_k\\tensor{\\Gamma}{_i_j}=\\partial_k\\tensor{\\Gamma}{_j_i}\\), \\(\\tensor{\\Gamma}{^k_i_j}=\\tensor{\\Gamma}{^k_j_i}\\)\r\nas well as \\(\\partial_k\\tensor{\\Gamma}{_i_j}=\\sum_{m}\\tensor{\\Gamma}{^m_i_j}\\tensor{g}{_m_k}\\).\r\n\\end{APAenumerate}\r\n\\end{definition}\r\n\\begin{definition}[Curvature tensor {\\autocite[][Chapter~4C]{kuhnelwolfgang_2006}}]\\label{Manifold:CurvatureTensor}\r\n\\[\r\nR\\left(X,Y\\right)Z\r\n\\coloneqq\r\n\\nabla_X\\nabla_YZ - \\nabla_Y\\nabla_XZ - \\nabla_{\\lie{X}{Y}}Z\r\n\\]\r\nis a tensor field, which is called the \\textit{curvature tensor} of the surface.\r\n\\end{definition}\r\n\\begin{remark}[Curvature tensor {\\autocite[][Chapter~4C]{kuhnelwolfgang_2006}}]\\label{Manifold:CurvatureTensor:ChristoffelSymbol}\r\nThe left-hand side of the Gauss equation is called the \\textit{curvature tensor}\r\nand is in general expressed in the form\r\n\\[\r\n\\tensor{R}{^s_i_k_j}\r\n\\coloneqq\r\n\\frac{\\partial}{\\partial\\tensor{u}{^k}}\\tensor{\\Gamma}{^s_i_j}\r\n- \\frac{\\partial}{\\partial\\tensor{u}{^j}}\\tensor{\\Gamma}{^s_i_k}\r\n+ \\sum_{r}\\left(\\tensor{\\Gamma}{^r_i_j}\\tensor{\\Gamma}{^s_r_k}-\\tensor{\\Gamma}{^r_i_k}\\tensor{\\Gamma}{^s_r_j}\\right) \\text{.}\r\n\\]\r\n\\end{remark}\r\n\\begin{definition}[ {\\autocite[][Chapter~6B]{kuhnelwolfgang_2006}}]\r\nWith respect to a given Riemannian metric \\(\\inner{}{}\\),\r\nthe \\textit{standard curvature tensor} \\(\\tensor{{R_1}}{}\\) is defined by the relation\r\n\\(R_1\\left(X,Y\\right)Z\\coloneqq\\inner{Y}{Z}X-\\inner{X}{Z}Y\\).\r\nWe then set\r\n\\begin{align*}\r\n\\kappa_1\\left(X,Y\\right)\r\n\\coloneqq\\inner{R_1\\left(X,Y\\right)Y}{X}\r\n=\\inner{X}{X}\\inner{Y}{Y}-\\inner{X}{Y}^2\\text{,}\\\\\r\n\\kappa\\left(X,Y\\right)\r\n\\coloneqq\\inner{R\\left(X,Y\\right)Y}{X}\\text{.}\r\n\\end{align*}\r\nLet \\(\\sigma\\subset T_pM\\) be a two-dimensional subspace, spanned by \\(X\\), \\(Y\\).\r\nThen the quantity\r\n\\[\r\nK_\\sigma\r\n\\coloneqq\r\n\\frac{\\kappa\\left(X,Y\\right)}{\\kappa_1\\left(X,Y\\right)}\r\n\\]\r\nis called the \\textit{sectional curvature} of the Riemannian manifold with respect to the plane \\(\\sigma\\).\r\n\\end{definition}\r\n\\begin{definition}[Space of constant curvature {\\autocite[][Chapter~6B]{kuhnelwolfgang_2006}}]\\label{Manifold:Spaceform}\r\nIf on a Riemannian manifold \\(K_\\sigma\\) is constant\r\nor, equalently,\r\nif \\(R=K\\cdot R_1\\) with \\(K\\in\\R\\),\r\nthe manifold is called a \\textit{space of constant curvature}.\r\n\\end{definition}\r\n\\begin{remark}\r\nBy \\textit{scaling} one means the process of\r\nreplacing a metric \\(g\\) by \\(\\tilde{g}]\\coloneqq\\lambda^2g\\), where \\(\\lambda\\ne0\\) is a constant.\r\nIn this case one has \\(\\tilde{R_1}\\left(X,Y\\right)Z=\\lambda^2R_1\\left(X,Y\\right)Z\\).\r\nOn the other hand we have\r\n\\(\\tilde{\\tensor{\\Gamma}{^k_i_j}}=\\tensor{\\Gamma}{^k_i_j}\\),\r\n\\(\\tilde{\\nabla}_XY=\\nabla_XY\\) and, consequently,\r\n\\(\\tilde{R}\\left(X,Y\\right)Z=R\\left(X,Y\\right)Z\\)\r\nas well as \\(\\tilde{K}=K\\lambda^{-2}\\).\r\nHence in \\cref{Manifold:Spaceform} there are (up to scaling) only three possible curvature tensor with constant curvature:\r\n\\begin{align*}\r\nR=R_1&\\text{(with \\(K=1\\)),}\\\\\r\nR=0&\\text{(with \\(K=0\\)),}\\\\\r\nR=R_{-1}\\coloneqq-R_1&\\text{(with \\(K=-1\\)).}\r\n\\end{align*}\r\nModel spaces for these are the sphere \\(S^n\\), the euclidean space \\(E^n\\) and the hyperbolic space \\(H^n\\)\r\n\\end{remark}\r\n\\subsection{Space of Constant Curvature}\r\n\\begin{definition}(Pseudo-Euclidean space \\(\\R^n_k\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\r\nThe so-called \\textit{pseudo-Euclidean} metric (or pseudo-Euclidean inner product)\r\n\\[\r\ng\\left(X,X\\right)\r\n=\\inner{X}{X}_k\r\n=-\\sum_{i=1}^{k}x_i^2+\\sum_{i=k+1}^{n}x_i^2\r\n\\]\r\nfor a vector \\(X\\) with components \\(s_1,\\dots,x_n\\),\r\nwhere \\(0\\le k\\le n\\) is a fixed number which is called the \\textit{index} or the \\textit{signature} of the inner produce.\r\nThe pair \\(\\left(\\R^n,g\\right)\\) is then called a \\textit{pesudo-Euclidean space}\r\nand is denoted by \\(\\R^n_k\\) or \\(E^n_k\\).\r\nIn particular, \\(E^n=R^n_0\\) is the usual Euclidean space.\r\n\\end{definition}\r\n\\begin{definition}(The sphere \\(S^n\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\r\nThe sphere with its spherical metric is most easily defined as a hypersurface in Euclidean space with the associated first fundamental form, that is,\r\n\\[\r\nS^n\\coloneqq\\Set{X\\in\\R^{n+1}|\\inner{X}{X}=\\sum_ix_i^2=1}\\text{.}\r\n\\]\r\nThe Gauss equation then implies the sectional curvature to be \\(K_\\sigma=+1\\) at every point \\(p\\) and every plane \\(\\sigma\\subseteq T_pS^n\\).\r\n\\end{definition}\r\n\\begin{definition}(Hyperbolic space \\(H^n\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\r\nWe defined the \\(n\\)-dimensional \\textit{hyperbolic space} \\(H^n\\)\r\nas the component of \\(\\Set{X\\in\\R^{n+1}_1|\\inner{X}{X}_1=-1}\\)\r\nwhich contains the point \\(\\left(+1,0,\\dots,0\\right)\\),\r\nthat is, the upper component of the two-sheeted hyperboloid.\r\nThe sectional curvature of hyperbolic space defined in this manner is constant: \\(K=-1\\).\r\n\\end{definition}\r\n\\begin{definition}(Symmetries of the space \\(E^n\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\\label{Group:Euclidean}\r\nThe group \\(E\\left(n\\right)\\) of Euclidean motions\r\n(the so-called \\textit{Euclidean group})\r\nacts on \\(E^n\\).\r\nThis group contains in particular all transpations\r\n(these form a subgroup which is isomorphic to \\(\\R^n\\), in fact a normal subgroup of \\(E\\left(n\\right)\\))\r\nas well as the rotation group \\(O\\left(n\\right)\\),\r\nconsisting of symmetries which leave a point invariant.\r\nIn fact, \\(E\\left(n\\right)\\) is a semi-direct product of these two subgroups.\r\n\\end{definition}\r\n\\begin{definition}(Symmetries of the space \\(S^n\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\\label{Group:Sphere}\r\nThe \\textit{orthogonal group}\r\n\\[\r\nO\\left(n+1\\right)\r\n=\r\n\\Set{A\\colon\\R^{n+1}\\to\\R^{n+1}|\\text{\\(A\\) preserves the Euclidean inner product}}\r\n\\]\r\nacts on the sphere \\(S^n\\).\r\nHere, \\(A\\) denotes a linear map.\r\nAs is well-known, \\(A\\in O\\left(n+1\\right)\\) holds if and only if \\(A^T=A^{-1}\\).\r\nAs a matter of fact, the orthogonal group acts on the entire space \\(\\R^{n+1}\\),\r\nbut we can consider its action when restricted to the sphere and denote the group in the same way.\r\n\\end{definition}\r\n\\begin{definition}(Symmetries of the space \\(H^n\\) {\\autocite[][Chapter~7A]{kuhnelwolfgang_2006}})\\label{Group:Hyperbolic}\r\nThe \\textit{Lorentz group}\r\n\\[\r\nO\\left(n,1\\right)\r\n=\r\n\\Set{A\\colon\\R^{n+1}_1\\to\\R^{n+1}_1|\\text{\\(A\\) preserves the pseudo-Euclidean inner product}}\r\n\\]\r\nacts on \\textit{Lorentz space} or on \\textit{Minkowski space} \\(\\R^{n+1}_1\\)\r\nand preserves the set \\(\\tilde{H}=\\Set{X|\\inner{X}{X}_1=-1}\\).\r\nThe \"positive\" part of this set,\r\n\\[\r\nO_{+}\\left(n,1\\right)\r\n=\r\n\\Set{A\\colon O\\left(n,1\\right)|\\text{\\(A\\) preserves \\(\\tilde{H}\\cap\\Set{x_0>0}\\)}}\r\n\\]\r\nthen acts on hyperbolic space \\(H^n\\) and preserves its metric.\r\n\\end{definition}\r\n\\end{document}", "meta": {"hexsha": "4296813ae9cc206591a238539f56de421e28969e", "size": 22990, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/preliminary.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/preliminary.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/preliminary.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": 51.3169642857, "max_line_length": 404, "alphanum_fraction": 0.677337973, "num_tokens": 7809, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8459424295406088, "lm_q1q2_score": 0.7617963506256508}}
{"text": "\\subsubsection{Adiabatic Processes}\nAdiabatic processes are compression/expansion processes in which the gas has no heat flow ($Q=0$). These processes tend to be either fast, or occur under insulated conditions; for example, consider the same gas cylinder with the piston we discussed in the isothermal section. If instead of pushing in the piston very slowly, we push down forcefully, the compression will occur so quickly that there wouldn't be time for heat to flow out of the gas. This would be an adiabatic compression. As another example, if we had a cylinder of gas surrounded with thermal insulation, then even if we were to compress the piston or let the gas expand, there would be no heat flow and again we would have an adiabatic process.Let's consider some mathematical consequences of adiabatic processes. As a consequence of zero heat flow, by the first law of thermodynamics we have that:\n\\begin{equation}\n    \\Delta E = W\n\\end{equation}\nSo then for an adiabatic process, we can get that:\n\\begin{equation}\n    W = \\frac{\\chi}{2}N{k_b}\\Delta T\n\\end{equation}\nI'm also going to show the derivation for the other relation relevant to adiabatic processes. The derivation is beyond the scope of this course, so if you don't want to read it just skip to the final equations we obtain at the end end\\footnote{My disappointment will be immeasurable and my day ruined if you do}. This derivation first takes the relation in (20) for an infinitesimal step, then runs some rearrangement before integrating:\n\\begin{align*}\n    dE &= \\delta W \\\\\n    \\frac{\\chi}{2}N{k_b}dT &= -PdV\n\\end{align*}\nLike in the isothermal case, we make a substitution with ideal gas law, namely\n\\begin{equation*}\n    N{k_b}dT = d(PV)\n\\end{equation*}\nI also use the approximation $d(PV) = VdP + PdV$\\footnote{As for why, play around with $d(PV) = (P+dP)(V+dV) - PV$... or just consider the product rule.}. Making all of these substitutions gives\n\\begin{equation*}\n    \\frac{\\chi}{2}(VdP + PdV) = -PdV\n\\end{equation*}\nAt this point you have all the parts necessary to rearrange this equation into\n\\begin{equation*}\n    \\frac{\\chi}{2}\\frac{dP}{P} = -\\Big(\\frac{\\chi}{2} + 1\\Big)\\frac{dV}{V}\n\\end{equation*}\nIf you guessed that we integrate both sides of this equation, then you're right! This may seem a bit strange, since we're integrating the two sides of the equation against two different variables, but it is in fact perfectly legal. By integrating, we're taking a sum on both sides of all the infinitesimal steps from the initial to final state. Since both sides are using the same initial and final state, it makes sense that taking small steps between them should always yield the same result. Anyways, integrating this equation gives:\n\\begin{equation*}\n    \\int_{P_1}^{P_2} \\frac{\\chi}{2}\\frac{dP}{P} = \\int_{V_1}^{V_2} -\\Big(\\frac{\\chi}{2} + 1\\Big)\\frac{dV}{V}\n\\end{equation*}\nAgain, we can factor out the constant terms to get:\n\\begin{equation*}\n    \\frac{\\chi}{2}\\int_{P_1}^{P_2} \\frac{dP}{P} = -\\Big(\\frac{\\chi}{2} + 1\\Big)\\int_{V_1}^{V_2} \\frac{dV}{V}\n\\end{equation*}\nAt this point the integral on each side evaluates in the exact same way as when we integrated to get isothermal work done:\n\\begin{equation*}\n    \\frac{\\chi}{2}\\ln{\\Big(\\frac{P_2}{P_1}\\Big)} = -\\Big(\\frac{\\chi}{2} + 1\\Big)\\ln{\\Big(\\frac{V_2}{V_1}\\Big)}\n\\end{equation*}\nMultiplying both sides of this equation by $\\frac{2}{\\chi}$ yields:\n\\begin{equation*}\n    \\ln{\\Big(\\frac{P_2}{P_1}\\Big)} = -\\Big(\\frac{\\chi+2}{\\chi}\\Big)\\ln{\\Big(\\frac{V_2}{V_1}\\Big)}\n\\end{equation*}\nWe then take the natural exponent of both sides of the equation to get:\n\\begin{align*}\n    e^{\\ln{\\big(\\frac{P_2}{P_1}\\big)}} &= e^{-\\big(\\frac{\\chi+2}{\\chi}\\big)\\ln{\\big(\\frac{V_2}{V_1}\\big)}} \\\\\n    \\frac{P_2}{P_1} &= e^{\\ln{\\Big(\\big(\\frac{V_2}{V_1}\\big)^{-\\big(\\frac{\\chi+2}{\\chi}\\big)}\\Big)}} \\\\\n    \\frac{P_2}{P_1} &= \\Big(\\frac{V_2}{V_1}\\Big)^{-\\big(\\frac{\\chi+2}{\\chi}\\big)}\n\\end{align*}\nRaise both sides to the exponent -1, rearrange a bit, and you get:\n\\begin{equation}\n    {P_1}{V_1}^{\\frac{\\chi+2}{\\chi}} = {P_2}{V_2}^{\\frac{\\chi+2}{\\chi}}\n\\end{equation}\nSometimes the quantity $\\frac{\\chi+2}{\\chi}$ is called $\\gamma$ as well. Note that this identity we have discovered can take some alternative forms (which can be useful for exams); for example, making the subtitution $P = \\frac{nRT}{V}$, we get:\n\\[ \\frac{nRT_1}{V_1}V_1^\\gamma = \\frac{nRT_2}{V_2}V_2^\\gamma \\]\nAnd cancelling out $nR$ on both sides and grouping like terms, we obtain the formula:\n\\begin{equation}\n    T_1V_1^{\\gamma-1} = T_2V_2^{\\gamma-1}\n\\end{equation}\nFinally, we again consider what an adiabatic process looks like on a PV diagram; the visual answer is that it looks quite a bit like the isothermal curve, but is steeper/lies above it. You can see both curves pictured below for comparison. The adiabatic compression is pictured in black, and the isothermal curve is dashed and red:\n\\begin{center}\n    \\begin{tikzpicture}\n    \\begin{axis}[\n        axis x line=bottom,\n        axis y line=left,\n        xmin=0, xmax=10,\n        ymin=0, ymax=10,\n%        % (made labels more common)\n%        % (because of the \"sketch\" type of the plot these should not be needed)\n%        xlabel={Volume $(\\mathrm{m}^3)$},\n%        ylabel={Pressure (Pa)},\n        % (changed ticks + labels to normal ticks instead of extra ticks)\n        xtick={3.75,6},\n        xticklabels={$V_1$,$V_2$},\n        ytick={1.5,6},\n        yticklabels={$P_2$,$P_1$},  % <-- (changed order of entries)\n    ]\n        % fill the area below the curve\n        % (draw it first, so it is below everything else)\n\n\n        % draw the dashed lines\n        % (using two different approaches)\n        \\addplot [dashed,domain=0:3.75,samples=2] {6};\n        \\addplot [dashed,domain=0:6,samples=2] {1.5};\n\n        \\draw [dashed,thin] (axis cs:6,1.5) -- (axis cs:6,0);\n        \\draw [dashed,thin] (axis cs:3.75,6)   -- (axis cs:3.75,0);\n\n        % now draw the curve\n        \\draw [\n            dotted,red             % <-- added\n        ] (axis cs:3,6) to [bend right=30]\n            % store start and end coordinates\n            coordinate [pos=1] (start)\n            coordinate [pos=0] (end)\n        (axis cs:6,1.5);\n        \n        \\draw [\n            fleche={0.6:black}            % <-- added\n        ] (axis cs:3.75,6) to [bend right=30]\n            % store start and end coordinates\n            coordinate [pos=1] (start)\n            coordinate [pos=0] (end)\n        (axis cs:6,1.5);\n        \n        \n        % draw start and end point\n        \\fill [radius=2pt]\n            (start) circle[]\n            (end)   circle[];\n        \\node[right] at (axis cs:6,1.5) {$T_2$};\n        \\node[right] at (axis cs:3.75,6) {$T_1$};\n    \\end{axis}\n        \\node[below] at (6.5,0) {$V$};\n        \\node[left] at (0,5.5) {$P$};\n\n\\end{tikzpicture}\n\\end{center}", "meta": {"hexsha": "33768bb689dae61d3c1479eaec7c2cf5e5f73183", "size": 6813, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "OneLaw/adiabatic.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/adiabatic.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/adiabatic.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": 57.7372881356, "max_line_length": 867, "alphanum_fraction": 0.6559518567, "num_tokens": 2142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513842182775, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.761787837619571}}
{"text": "% !TEX root =  manual.tex\n\n\\section{Covariance Functions Recognized by the Emulator}\n\\label{sec:CovarianceFunctions}\n\n$u$ and $v$ are zero-indexed vectors that represent a point in parameter space.  $P$ is the number of parameters. $\\Theta=(\\theta_0, \\theta_1,\\theta_2,\\ldots)$ is a list of $P+2$ or $P+3$ hyperparameters. $\\theta_0$ is called \\emph{amplitude}; $\\theta_1$ is called the \\emph{nugget}.  $\\Vert\\,\\cdotp\\Vert{}_\\Theta$ is a distance function parametrized by $\\Theta$.  $\\epsilon$ is $10^{-5}$. $c_\\Theta{}(u, v)$ is the covariance between $u$ and $v$, as parametrized by $\\Theta$.\n\n\n\\begin{figure}[b]\n\\includegraphics[width=4in]{figs/kernel_functions.pdf}\n\\parbox[b]{2.5in}\n{\\caption{\\label{fig:kernelfunctions}\n$C_\\Theta{}(0, x)$ for a one-dimensional parameter space with each covariance function type. The amplitude is 1, the nugget is 0, and the length scale is 1.\n\\vspace*{30pt}\n}}\n\\end{figure}\n\n%% FIGURE SOURCE CODE:\n%%\n%% #!/usr/bin/env python\n%% import matplotlib.pyplot\n%% import numpy\n%% x = numpy.arange(-4,4,0.01)\n%% SE = numpy.exp(-0.5 * (x ** 2))\n%% alpha = 1.75\n%% PE = numpy.exp(-0.5 * (numpy.power(numpy.abs(x),alpha)))\n%% M52 = (1 + numpy.sqrt(5) * numpy.abs(x) + 5/3.0 * (\n%%     (numpy.abs(x))**2) ) * numpy.exp(- numpy.sqrt(5) *\n%%     numpy.abs(x))\n%% M32 = (1 + numpy.sqrt(3) * numpy.abs(x) ) * numpy.exp(\n%%     - numpy.sqrt(3) * numpy.abs(x))\n%% matplotlib.pyplot.plot(x, SE,  '-',  label=u'Squared\\nExponential')\n%% matplotlib.pyplot.plot(x, M32, '--', label=u'Mat\\u00e9rn 3/2')\n%% matplotlib.pyplot.plot(x, M52, '-.', label=u'Mat\\u00e9rn 5/2')\n%% matplotlib.pyplot.plot(x, PE, ':',\n%%     label=u'Power\\nExponential\\n(\\u03b1=%g)'%alpha)\n%% matplotlib.pyplot.legend()\n%% matplotlib.pyplot.axes().set_aspect(3)\n%% matplotlib.pyplot.savefig('kernel_functions.pdf',\n%%     bbox_inches='tight')\n\n\n\\begin{itemize}\n\\item Squared-Exponential [\\variable{SQUARE\\_EXPONENTIAL\\_FUNCTION}]\n\\[ \\Vert{}u-v\\Vert{}_\\Theta{} = \\sqrt{\\sum_{i=0}^{P-1} \\frac{(u_i - v_i)^2}{(\\theta{}_{2+i})^2}} \\qquad\n \\delta{}_{uv} = 1 \\text{ if } (\\Vert{}u-v\\Vert{}_\\Theta{} < \\epsilon{}) \\textrm{ else } \\delta{}_{uv} = 0 \\]\n\\[ c_\\Theta{}(u, v) = \\theta{}_0 \\exp\\left({-\\tfrac{1}{2} \\Vert{}u-v\\Vert{}_\\Theta{}^2}\\right) + \\theta{}_1\\delta{}_{uv} \\]\n\n\\item {Power-Exponential}\n[\\variable{POWER\\_EXPONENTIAL\\_FUNCTION}]\n\\[ \\Vert{}u-v\\Vert{}_\\Theta{} = \\sqrt{\\sum_{i=0}^{P-1} \\frac{(u_i - v_i)^2}{(\\theta{}_{3+i})^2}} \\qquad\n \\delta{}_{uv} = 1 \\text{ if } (\\Vert{}u-v\\Vert{}_\\Theta{} < \\epsilon{}) \\textrm{ else } \\delta{}_{uv} = 0 \\]\n\\[ c_\\Theta{}(u, v) = \\theta{}_0 \\exp\\left({-\\tfrac{1}{2} \\Vert{}u-v\\Vert{}_\\Theta{}^{\\theta{}_2}}\\right) + \\theta{}_1\\delta{}_{uv} \\]\n\n\\item {Mat\\'{e}rn 3/2}\n[\\variable{MATERN\\_32\\_FUNCTION}]\n\\[ \\Vert{}u-v\\Vert{}_\\Theta{} = \\sqrt{\\sum_{i=0}^{P-1} \\frac{(u_i - v_i)^2}{(\\theta{}_{2+i})^2}} \\qquad\n \\delta{}_{uv} = 1 \\text{ if } (\\Vert{}u-v\\Vert{}_\\Theta{} < \\epsilon{}) \\textrm{ else } \\delta{}_{uv} = 0 \\]\n\\[ c_\\Theta{}(u, v) = {\\theta{}_0} \\left({ 1 + \\sqrt{3} \\Vert{}u-v\\Vert{}_\\Theta{} }\\right)\n\\exp \\left({ - \\sqrt{3} \\Vert{}u-v\\Vert{}_\\Theta{} }\\right) + \\theta{}_1\\delta{}_{uv} \\]\n\n\n\\item {Mat\\'{e}rn 5/2}\n[\\variable{MATERN\\_52\\_FUNCTION}]\n\\[ \\Vert{}u-v\\Vert{}_\\Theta{} = \\sqrt{\\sum_{i=0}^{P-1} \\frac{(u_i - v_i)^2}{(\\theta{}_{2+i})^2}} \\qquad\n \\delta{}_{uv} = 1 \\text{ if } (\\Vert{}u-v\\Vert{}_\\Theta{} < \\epsilon{}) \\textrm{ else } \\delta{}_{uv} = 0 \\]\n\\[ c_\\Theta{}(u, v) = {\\theta{}_0} \\left({ 1 + \\sqrt{5} \\Vert{}u-v\\Vert{}_\\Theta{}\n + \\tfrac{5}{3} \\left({\\Vert{}u-v\\Vert{}_\\Theta{}}\\right)^2  }\\right) + \\theta{}_1\\delta{}_{uv} \\]\n\\end{itemize}\n\n%%  LocalWords:  hyperparameters\n", "meta": {"hexsha": "7ded66804f1f0f7e6b75fb06e9b689d5d06c30e5", "size": 3631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/manual/covariancefunctions.tex", "max_stars_repo_name": "scottedwardpratt/MADAI", "max_stars_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2015-04-02T17:37:35.000Z", "max_stars_repo_stars_event_max_datetime": "2017-03-28T20:14:23.000Z", "max_issues_repo_path": "doc/manual/covariancefunctions.tex", "max_issues_repo_name": "scottedwardpratt/MADAI", "max_issues_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/manual/covariancefunctions.tex", "max_forks_repo_name": "scottedwardpratt/MADAI", "max_forks_repo_head_hexsha": "9f9ee0dac704d77492d9905b4d90a57746201912", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-08-20T14:07:41.000Z", "max_forks_repo_forks_event_max_datetime": "2017-03-28T20:15:23.000Z", "avg_line_length": 50.4305555556, "max_line_length": 476, "alphanum_fraction": 0.6094739741, "num_tokens": 1377, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7617878367132105}}
{"text": "\\chapter{Foundation}\n\nIf you are already familiar with the things here,\nplease at least skim this chapter to verify that\nwe are speaking the same language.\n\n\\section{Type}\n\n\\index{type}%\n\\index{inhabitant}%\n\\(x : T\\) means that the \\emph{type} of \\(x\\) is \\(T\\).\nWe also say that \\(x\\) \\emph{inhabits} \\(T\\) and that \\(x\\) is an \\emph{inhabitant} of \\(T\\).\n\\index{function type}%\n\\index{type!function}%\nA \\emph{function type} looks like \\(a \\to b\\).\n\nFunction application:\nIff \\(x:A\\) and \\(f:A\\to B\\), then \\(f(x):B\\).\n\nThe arrow in a function type associates to the right.\nThe type \\(a \\to b \\to c\\) means \\(a \\to (b \\to c)\\).\n\nTypes and sets are different:\n\\(x \\in A\\) and \\(x : A\\) are different.\n\n\\section{Logic}\n\n\\index{iff}%\n\\index{if and only if}%\n``Iff'' is ``if and only if''.\nIt is bi-implication.\n\n\\index{connectives}%\n\\index{logical connectives}%\nLogical connectives:\n\\index{conjunction}%\n\\index{and}%\n\\emph{Conjunction} is \\(a \\wedge b\\) (\\(a\\) and \\(b\\)).\n\\index{disjunction}%\n\\index{or}%\n\\emph{Disjunction} is \\(a \\vee b\\) (\\(a\\) or \\(b\\)).\n\\index{implication}%\n\\emph{Implication} is \\(a \\implies b\\) (if \\(a\\) then \\(b\\)).\n\\index{bi-implication}%\n\\emph{Bi-implication} is \\(a \\iff b\\) (iff \\(a\\) then \\(b\\)).\n\\index{negation}%\n\\index{not}%\n\\emph{Negation} is \\(\\neg a\\) (not \\(a\\)).\n\n\\section{Set}\n\n\\index{set}%\nPractically, a \\emph{set} is an unordered collection of unique things.%\n\\index{Russell's paradox}%\n\\footnote{Theoretically, a set cannot be defined this way due to Russell's paradox.}\nIf \\(a \\neq b\\), then the notations \\(\\{a,b\\}\\), \\(\\{b,a\\}\\), and \\(\\{a,a,b\\}\\)\nall describe the same set of \\emph{two} elements.\nThe \\emph{cardinality} of a set \\(A\\), written \\(|A|\\),\nis the number of elements of \\(A\\).\n\n\\index{set builder notation}%\n\\index{notation!set builder}%\n\\paragraph{Set builder notation}\n\\( \\{ M ~|~ F \\} \\)\ndescribes the set of every \\(M\\) where \\(F\\) is true\nwhere \\(M\\) is an expression and \\(F\\) is a logic formula.\nFor example, \\(\\{ x^2 ~|~ x \\in \\Nat \\}\\) is \\(\\{ 0^2, 1^2, 2^2, \\ldots \\}\\).\nThe ellipsis (\\ldots) is not an element of the set;\nthere are just too many things to write.\n\n\\paragraph{Set relationships}\n\\index{subset}%\n\\(A \\subseteq B\\)\n(\\(A\\) is a \\emph{subset} of \\(B\\))\niff \\(\\forall x (x \\in A \\implies x \\in B)\\).\n\\index{disjoint sets}%\n\\index{sets!disjoint}%\nTwo sets \\(a\\) and \\(b\\) are \\emph{disjoint} iff \\(a \\cap b = \\emptyset\\).\n\n\\paragraph{Set operations}\n\\index{intersection}%\n\\index{intersection  (set theory)}%\nThe \\emph{intersection of \\(A\\) and \\(B\\)} is\n\\(A \\cap B = \\{ x ~|~ x \\in A \\wedge x \\in B \\}\\).\n\\index{union}%\n\\index{union (set theory)}%\nThe \\emph{union of \\(A\\) and \\(B\\)} is\n\\(A \\cup B = \\{ x ~|~ x \\in A \\vee x \\in B \\}\\).\n\\index{subtraction (set theory)}%\n\\index{sets!subtraction}%\nThe \\emph{subtraction of \\(A\\) and \\(B\\)} is\n\\(A - B = \\{ x ~|~ x \\in A \\wedge x \\not\\in B \\}\\).\n\\index{Cartesian product}%\nThe \\emph{Cartesian product of \\(A\\) and \\(B\\)} is \\(A \\times B = \\{ (a,b) ~|~ a \\in A, b \\in B \\}\\).\nThe \\emph{Cartesian product of \\(A_1,\\ldots,A_n\\)} is\n\\(\\prod_{k=1}^n A_k = A_1 \\times \\ldots \\times A_n = \\{ (a_1,\\ldots,a_n) ~|~ a_1 \\in A_1, ~\\ldots, ~a_n \\in A_n \\}\\).\n\\index{power set}%\n\\index{set!power}%\nThe \\emph{power set} of \\(A\\) is \\(2^A = \\{ X ~|~ X \\subseteq A \\}\\),\nthe set of all subsets of \\(A\\).\n\n\\paragraph{Closed under binary operation}\n\\index{closed under binary operation}%\nLet \\(S\\) be a set and \\(f\\) be a \\emph{binary operation} (a two-argument function).\n\\emph{\\(S\\) is closed under \\(f\\)} iff\n\\(\\forall a, b \\in S : f(a,b) \\in S\\).\n\n\\paragraph{Partitioning}\n\\(A_1,\\ldots,A_n\\) is a \\emph{partitioning of \\(A\\)} if and only if\n\\(\\bigcup_{k=1}^n A_k = A\\) and\n\\(\\forall i \\neq j (A_i \\cap A_j = \\emptyset)\\).\n\n\\section{Relation}\n\n\\index{relation}%\nA \\emph{relation} is a subset of a Cartesian product.\n\\index{binary relation}%\n\\index{relation!binary}%\n\\(R\\) is a \\emph{binary relation} between \\(A\\) and \\(B\\) iff \\(R \\subseteq A \\times B\\).\nIff \\(A = B\\), then \\(R\\) is an \\emph{endorelation}.\n\n\\paragraph{Notation}\nWe write \\(a R b\\) or \\(R(a,b)\\) to mean \\((a,b) \\in R\\).\nWe write \\(\\neg (a R b)\\) or \\(\\neg R(a,b)\\) to mean \\((a,b) \\not\\in R\\).\n\nProperties of an endorelation:\n\\index{reflexive relation}%\n\\index{relation!reflexive}%\nAn endorelation \\(R \\subseteq A \\times A\\) is \\emph{reflexive} iff\n\\(\\forall x \\in A : (x,x) \\in R\\),\n\\index{symmetric relation}%\n\\index{relation!symmetric}%\nis \\emph{symmetric} iff\n\\(\\forall x,y: (x,y) \\in R \\iff (y,x) \\in R\\),\n\\index{antisymmetric relation}%\n\\index{relation!antisymmetric}%\nis \\emph{antisymmetric} iff\n\\(\\forall x,y: (x,y) \\in R \\wedge (y,x) \\in R \\implies x = y\\),\n\\index{transitive relation}%\n\\index{relation!transitive}%\nis \\emph{transitive} iff\n\\(\\forall x,y,z: (x,y) \\in R \\wedge (y,z) \\in R \\implies (x,z) \\in R\\),\n\\index{total relation}%\n\\index{relation!total}%\nis \\emph{total} iff\n\\(\\forall x \\in A , y \\in A : (x,y) \\in R \\vee (y,x) \\in R\\).\n\n\\index{equivalence relation}%\n\\index{relation!equivalence}%\nAn \\emph{equivalence relation} is a symmetric transitive reflexive relation.\n\\index{partial order}%\n\\index{total order}%\n\\index{order!partial}%\n\\index{order!total}%\nA \\emph{partial order} is a antisymmetric transitive reflexive relation.\nA \\emph{total order} is an antisymmetric transitive total relation.\n\nThe\n\\index{composition}%\n\\index{composition!of two relations}%\n\\index{relation!composition}%\n\\emph{composition} of \\(f\\) and \\(g\\) is\n\\(f \\circ g = \\{ (a,c) ~|~ (a,b) \\in g \\wedge (b,c) \\in f \\}\\).\nRepeated composition: \\(f^{n+1} = f \\circ f^n\\).\n\n\\(R\\) is \\emph{transitive} iff \\(\\forall a,b,c : a R b \\wedge b R c \\implies a R c\\).\n\nThe \\emph{inverse} of \\(R\\) is \\(R^{-1} = \\{ (b,a) ~|~ a R b \\}\\).\n\nThe\n\\index{symmetric closure}%\n\\emph{symmetric closure} of \\(R\\)\nis the smallest symmetric relation that is also a superset of \\(R\\).\nThe symmetric closure of \\(R\\) is \\(R \\cup R^{-1}\\).\nThe\n\\index{transitive closure}%\n\\emph{transitive closure} of \\(R\\)\nis the smallest transitive relation that is also a superset of \\(R\\).\n\n\\section{Function}\n\n\\index{function}%\nA \\emph{function} \\(f\\) is a relation such that\n\\(\\forall a, b, c : (a,b) \\in f \\wedge (a,c) \\in f \\implies b = c\\).\nThe type of a function is \\(a \\to b\\).\nIf \\(f\\) is a function, then \\(f(a) = b\\) iff \\((a,b) \\in f\\).\nThe type of a relation between \\(a\\) and \\(b\\) is \\(a \\to 2^b\\).\nIf $(a,b) \\in f$ and $(a,c) \\in f$, then $b = c$.\n\n\\index{endofunction}%\nThe type of an \\emph{endofunction} is \\(a \\to a\\).\nAn endofunction is a function whose input type is equal to its output type.\n\n\\index{Iverson bracket}%\n\\paragraph{Iverson bracket}\n\\([E]\\) is \\(1\\) iff \\(E\\) is true\nand \\(0\\) iff \\(E\\) is false.\n\n\\index{indicator function}%\n\\paragraph{Indicator function}\n\\(1_A(x) = [x \\in A]\\).\n\n\\index{unnamed function}%\n\\paragraph{Unnamed function}\n\\(f(x) = x + 1\\) and \\(f = x \\to x+1\\) describe the same function.\nWhen an expression is expected, the notation \\(X \\to Y\\)\nmeans a function that evaluates to \\(Y\\) if given \\(X\\).\nWhen a type is expected, the notation \\(X \\to Y\\) describes a function type.\nExpressions like \\(x \\to x + 1\\) are called \\emph{unnamed functions}.\n\nThe\n\\index{image!of relation}%\n\\emph{\\(R\\)-image} of \\(A\\) is \\(\\{ y ~|~ (x,y) \\in R, ~ x \\in A \\}\\).\n\nThe\n\\index{preimage!of relation}%\n\\emph{\\(R\\)-preimage} of \\(A\\) is \\(\\{ x ~|~ (x,y) \\in R, ~ y \\in A \\}\\).\n\nThe\n\\index{image!of function}%\n\\emph{\\(f\\)-image} of \\(A\\) is \\(\\{ f(x) ~|~ x \\in A \\}\\).\n\nThe\n\\index{preimage!of function}%\n\\emph{\\(f\\)-preimage} of \\(A\\) is \\(\\{ x ~|~ f(x) \\in A \\}\\).\n\nFor all function \\(f\\):\nif \\(A \\subset B\\) then \\(F(A) \\subseteq F(B)\\)\nwhere \\(F(A) = \\{ f(x) ~|~ x \\in A \\}\\).\n\nFor all function \\(f\\):\nif \\(A \\subset B\\) then \\(G(A) \\subseteq G(B)\\)\nwhere \\(G(A) = \\{ x ~|~ f(x) \\in A \\}\\).\n\nThe function type operator associates to the right: \\(a \\to b \\to c = a \\to (b \\to c)\\).\n\n\\paragraph{Currying}\n\\index{curry}%\n\\index{currying}%\n\\emph{Currying} turns every function that takes \\(n\\) arguments\nto an equivalent function that takes one argument.\nCurrying \\(f : (a_1,\\ldots,a_n) \\to b\\) turns it into \\(f' : a_1 \\to \\ldots \\to a_n \\to b\\)\nsuch that \\(f(x_1,\\ldots,x_n)\n= f'~x_1~\\ldots~x_n\n= (((f'~x_1)~x_2)\\ldots)~x_n\\).\n\nIf it is clear from context that \\(f\\) can take 3 arguments (and not one 3-tuple argument),\nthen we abuse the notation \\(f(a,b,c)\\) to mean \\(((f~a)~b)~c\\).\n\n\\section{Polynomial}\n\nA \\emph{polynomial of \\(x\\)} is an expression of the form \\(\\sum_{k=0}^n a_k x^k\\)\nwhere \\(n\\) is the \\emph{degree} of the polynomial.\n\nA\n\\index{polynomial}%\n\\emph{polynomial function of degree \\(n\\)} is a function of the form\n\\(f(x) = \\sum_{k=0}^n a_k x^k\\) where each \\(a_k\\) is constant.\n\nA \\emph{polynomial function of degree \\(n\\)} is a function of the form\n\\(f(x) = \\prod_{k=1}^n (x - r_k)\\) where each \\(r_k\\) is constant.\nEach \\(r_k\\) is a \\emph{root} of the polynomial.\n\n\\section{Limit}\n\nInformally, \\(\\lim_{x \\to a} f(x) = b\\)\niff \\(f(x)\\) approaches \\(b\\) as \\(x\\) approaches \\(a\\).\n\n\\section{Sequence}\n\n\\index{sequence}%\nA \\emph{sequence} \\(x\\) is a list of things \\(x_0, x_1, x_2\\), and so on.\n\nAn\n\\index{arithmetic sequence}%\n\\index{sequence!arithmetic}%\n\\emph{arithmetic sequence} is a sequence of the form \\(x_k = x_0 + a k\\).\n\nA\n\\index{geometric sequence}%\n\\index{sequence!geometric}%\n\\emph{geometric sequence} is a sequence of the form \\(x_k = r^k x_0\\).\n\n\\section{Series}\n\n\\index{series}%\nIf \\(x\\) is a sequence, then \\(\\sum_k x_k\\) is a \\emph{series}.\nThe series \\emph{converges} iff it is a number.\n\nThe\n\\index{sequence of partial sums}%\n\\index{partial sum}%\n\\emph{sequence of partial sums} of the sequence \\(x\\) is\nthe sequence \\(y\\)\nwhere \\(y_n = \\sum_{k=0}^n x_k\\).\nThe series is \\(\\lim_{n \\to \\infty} y_n\\).\n\nThe\n\\index{geometric series}%\n\\index{series!geometric}%\n\\emph{geometric series} with ratio \\(r\\) is \\(g(r) = \\sum_{k=0}^\\infty r^k\\).\nIf \\(0 < \\abs{r} < 1\\) then \\(g(r) = \\frac{1}{1-r}\\).\n", "meta": {"hexsha": "3529c09e067230277bde8c186f644b7ca68cc0b9", "size": 9901, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/foundation.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/foundation.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/foundation.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.6765676568, "max_line_length": 117, "alphanum_fraction": 0.6317543682, "num_tokens": 3634, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471134, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7617878352641614}}
{"text": " \\section{$k$-Means Clustering Problem}\n\t$k$-Means clustering problem is an unsupervised problem that can be described as follow.\n\n\\begin{definition}[$k$-Means Clustering Problem\\footnote{High frequency definition.}]\n    \\label{alo: def1}\n Given an observation set \n        \\begin{equation}\n        X=\\{x_{1}, x_{2}, \\dots, x_{N} | x_{i} \\in\\mathbb{R}^n\\}\n        \\end{equation}\n\n\tThe goal is to arrange the $N$ observation instances into $k$ sets, $\\mathcal{S} = \\{S^{1}, S^{2}, \\dots, S^{k}\\}$, and choose one cluster, $\\mathcal{C} = \\{c^{1}, c^{2}, \\dots, c^{k}\\}$. So as to minimize the \\textbf{Objective Function}:\n\t\n        \\begin{equation}\n        \\phi_{X}(\\mathcal{C}) = \\sum_{i = 1}^{N} d^{2}(x_{i}, \\mathcal{C})\n        \\end{equation}\t\n        \n        where \n \n         \\begin{equation}\n        d^{2}(x_{i}, \\mathcal{C}) = \\min_{l = 1, \\dots, k} ||x_{i} - c^{l}||_{2}^{2}\n        \\end{equation}\t       \n        \n        Noting that $\\phi_{X}$ has the additivity about $X$, i.e., if $X = X_{1}\\cup X_{2}$, then $\\phi_{X} = \\phi_{X_{1}} + \\phi_{X_{2}}$.  There is also one equivalent optimization version of $k$-Means problem.\n\\end{definition}\n    \\begin{definition}[$k$-Means Clustering Problem\\footnote{Optimization form.}]\n    \\label{alo: def2}\n\tMinimizing the \\textbf{Objective Function}:\n\t\n\t\\begin{equation}{\\label{eq:1}}\n\t\\phi(W, c) = {\\sum_{l=1}^{k}\\sum_{i=1}^{N}} w_{li} \\cdot ||x_{i} - c^{l}||^{2}_{2}\n\t\\end{equation}\n\n\twhere\n\t\\begin{equation}{\\label{eq:2}}\n\tc = (c^{1}, c^{2}, \\dots, c^{k}), c^{l} \\in\\mathbb{R}\n\t\\end{equation}\n\t\\begin{equation}\n        W =(w_{li}) \\in M_{k\\times N}(\\mathbb{R})\n\t\\end{equation}\t\n\t\\begin{equation}\n\tw_{li} = \\begin{cases} 1,&\\text{$x_{i} \\to S^{l}$},\\\\\n\t0,&\\text{otherwise}.\n\t\\end{cases}\t\n\t\\end{equation}\n\ts. t.\n\n\t\\begin{equation}\n\t\\sum_{l=1}^{k} w_{li} = 1, i = 1, 2, \\dots, N; \\sum_{i=1}^{N}w_{li}\\geq 1, l = 1, 2, \\dots, k.\n\t\\end{equation}\n\n\t\\begin{equation}{\\label{eq:3}}\n\tw_{li} \\in \\{0, 1\\}, i = 1, 2, \\ldots, N, l = 1, 2, \\dots, k.\n\t\\end{equation}\n    \\end{definition}\n    \n        For convenience, we named $W$ as \\textbf{assignment matrix}. By the format of Definition \\ref{alo: def1}, we have transformed $k$-means Problem into one \\textbf{Optimization Problem} consists of \\textbf{Objective Function} (\\ref{eq:1}) and \\textbf{Constraints} (\\ref{eq:2}-\\ref{eq:3}). \n            \n       \\begin{theorem}[Definition \\ref{alo: def1} is equivalent to \\ref{alo: def2}]\n        \\begin{proof}\n        Firstly, the formula (\\ref{eq:1}) can be rewritten as $\\phi(W, c) = {\\sum_{i=1}^{N}\\sum_{l=1}^{k}} w_{li} \\cdot ||x_{i} - c^{l}||^{2}_{2}$. It's trivial that given $x_{i}$,\n        $$\\min_{l = 1, \\dots, k} ||x_{i} - c^{l}||_{2}^{2} \\leq \\sum_{l=1}^{k} w_{li} \\cdot ||x_{i} - c^{l}||^{2}_{2}$$\n         where $\\sum_{l=1}^{k} w_{li} = 1$. \n         \n         Besides, the best optimizer of definition \\ref{alo: def1} has the corresponding assignment matrix, $\\hat{W}$ of definition \\ref{alo: def2}, here it goes,\n         $$\\sum_{i = 1}^{N}\\min{||x_{i} - c^{l}||} = {\\sum_{i=1}^{N}\\sum_{l=1}^{k}} \\hat{w}_{li} \\cdot ||x_{i} - c^{l}||^{2}_{2}\\geq \\min{\\sum_{l=1}^{k}\\sum_{i=1}^{N}} w_{li} \\cdot ||x_{i} - c^{l}||^{2}_{2}$$\n        \\end{proof}\n        \\end{theorem}\n        \\begin{remark}\n        $k$-means problem is one optimization problem with nonlinear, non-convex objective function and discrete constraints. More directly, it can be written as follow,\n        \n        \\begin{equation}\n        \\min \\phi(W, c) \\quad s.t. (\\ref{eq:2})-(\\ref{eq:3}).\n        \\end{equation}\n        \\end{remark}\n    \n      \tThen, we give one theorem from Shokri and M. A. in 1984\\cite{ref01}.\n\n\t\\begin{theorem}{\\label{alo:convergence}}\n\t$k$-means Problem has local minimum points.\n\t\\end{theorem}\n\n\tFor completeness, We rewrite the proof here by giving some definitions and lemmas and add some details based on the previous proof.\n\n\t\\begin{definition}\n\tConsider the set $\\Omega$ given by\n\t\\begin{equation}\n\t\\Omega = \\{W \\in M_{k\\times N}(\\mathbb{R}) : \\sum_{l=1}^{k} w_{li} = 1, i = 1, 2, \\dots, N; \\sum_{i=1}^{N}w_{li}\\geq 1; w_{li} \\geq 0 \\}.\n\t\\end{equation}\n\t\\end{definition}\n\n\t\\begin{lemma} \\label{alo:lem1}\n\tThe set $\\Omega$ is convex, and the extreme points of $\\Omega$ satisfy constraints\n\n\t$$w_{li} \\in \\{0, 1\\}, i = 1, 2, \\dots, N, l = 1, 2, \\dots, k.$$\n\t\\end{lemma}\n\n\t\\begin{proof}\n\t$\\forall W^{1}, W^{2}$, and $0 \\leq \\lambda \\leq 1$,\n\t\\begin{equation}\n\t\\sum_{l=1}^{k} [\\lambda w_{li}^{1}+(1-\\lambda)w_{li}^{2}] = \\lambda\\sum_{l=1}^{k} w_{li}^{1}+(1-\\lambda)\\sum_{l=1}^{k}w_{li}^{2} = 1.\n\t\\end{equation}\n\t\n\t\\begin{equation}\n\t\\sum_{i=1}^{N} [\\lambda w_{li}^{1}+(1-\\lambda)w_{li}^{2}] = \\lambda\\sum_{i=1}^{N} w_{li}^{1}+(1-\\lambda)\\sum_{i=1}^{N}w_{li}^{2} \\geq 1.\n\t\\end{equation}\n\n\tOn the one hand, $\\forall W$ satisfies constraint $w_{ki} = 0$ or $1$, if $\\exists W^{l_{1}}, W^{l_{2}} \\in \\Omega$, s.t.\n\n\t\\[W = \\lambda_{0}W^{l_{1}}+(1-\\lambda_{0})W^{l_{2}}, 0 < \\lambda_{0} <1\\]\n\tor\n\t\\[w_{li}=\\lambda_{0} w_{li}^{l_{1}}+(1-\\lambda_{0})w_{li}^{l_{2}}\\]\n\t\n\t\\begin{itemize}\n\t\\item If $w_{li} = 0$, then \n\t\\[w_{li}^{l_{1}}=w_{li}^{l_{2}}=0\\]\n\t\\item if $w_{li} = 1$, then\n\t\\[w_{li}^{l_{1}}=w_{li}^{l_{2}}=1.\\]\n\t\\end{itemize}\n\tThat is to say, $W^{l_{1}}= W^{l_{2}}$. The points satisfy $w_{li} \\in \\{0, 1\\}$ must be extreme points of  $\\Omega$.\n\n\t On the other hand, each extreme point of $\\Omega$ is associated with a basis of the constraints in $\\Omega$. Hence, each basic variable will have value $1$ and nonbasic variables will be zeros. Then we have completed the proof.\n\t\\end{proof}\n\t\n        \\begin{remark}\n\tWith the principle of combination, there are at most $M$ extreme points of $\\Omega$,\n\t\\[M := k^{N} - \\sum_{i=1}^{k-1} \\binom{k}{i} \\cdot (k-i)^{N} \\]\n\n        and denote the extreme points of $\\Omega$ as $\\{W^{1}, W^{2}, \\dots, W^{M}\\}$.\n        \\end{remark}\n\n\t\\begin{definition}[Reduced Problem of $k$-means Problem]\\label{alo: reduce}\n\tThe reduced problem of $k$-means problem is given by minimizing $\\Phi(W)$, \n\t\\begin{equation}\n\t\\Phi (W) = \\min_{c \\in \\mathbb{R}^{nk}} \\phi(W, c),  \\quad s.t. W \\in \\Omega\n\t\\end{equation}\t\n\t\\end{definition}\n\n\t\\begin{lemma}\n\tThe function $\\Phi(W)$ is a concave function, which subjects to $W\\in\\Omega$. Reduced problem gets local minimum value at the extreme point of $\\Omega$.\n\t\\end{lemma}\n\n\t\\begin{proof}\n\tFirst, we prove that $\\Phi$ is concave. $\\forall W^{{l}_{1}}, W^{{l}_{2}}\\in \\Omega$ and $0 \\leq \\gamma \\leq 1$,\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\Phi(\\gamma W^{{l}_{1}}+(1-\\gamma)W^{{l}_{2}}) & =\\min_{c \\in\\mathbb{R}^{nk}} \\phi(\\gamma W^{{l}_{1}}+(1-\\gamma) W^{{l}_{2}}, c)\\\\\n\t&= \\min_{c \\in \\mathbb{R}^{nk}} [\\gamma\\phi(W^{{l}_{1}}, c)+(1-\\gamma)\\phi (W^{{l}_{2}}, c)]\\\\\n\t&\\geq \\gamma \\min_{c \\in \\mathbb{R}^{nk}} \\phi(W^{{l}_{1}}, c)+\\min_{c \\in \\mathbb{R}^{nk}}(1-\\gamma) \\phi(W^{{l}_{2}}, c)\\\\\n\t&=\\gamma \\Phi(W^{{l}_{1}})+(1-\\gamma)\\Phi(W^{{l}_{2}}).\n\t\\end{aligned}\n\t\\end{equation}\n\t\n\tSecond, We illustrate $\\Phi(W)$ has smaller value at extreme points.\n\tFix one $\\hat W \\in \\Omega$, which is not one extreme point but near one extreme point. We denote all extreme points of $\\Omega$ as above. So here exists one constant vector $\\alpha=(\\alpha_{1}, \\alpha_{2}, \\dots, \\alpha_{M})$, s.t.\n\t\\begin{equation}\n\t{\\hat W}= \\sum_{j=1}^{M} \\alpha_{j} W^{j}, \\quad where \\sum_{j=1}^{M}\\alpha_{j}=1; 0 \\leq \\alpha <1\n\t\\end{equation}\n\n\t\\begin{equation}\n\t\\begin{aligned}\n\t\\Phi({\\hat W}) &= \\Phi(\\sum_{l=1}^{m} \\alpha_{l} W^{l}) \\geq \\sum_{l=1}^{m} \\alpha_{l}\\Phi(W^{l})\n\t\\end{aligned}\n\t\\end{equation}\n\tThen the local minimum of $\\Phi(W)$ must be obtained at the extreme point of $\\Omega$.\n\t\\end{proof}\n\t\n\t\\begin{lemma}\n\tThe reduced problem of $k$-means problem and $k$-means problem are equivalent.\n\t\\end{lemma}\n\t\n\t\\begin{proof}\n\tIt equals to prove that \n\t\\begin{equation}\\label{eq: 4}\n\t{\\arg\\min} \\phi(W, c) \\iff \\arg\\min_{W \\in \\Omega} \\Phi(W)\n\t\\end{equation}\n\tSuppose  $(W^{*}, c^{*}) = {\\arg\\min} \\phi(W, c)$ and $W_{*} = \\arg\\min_{W \\in \\Omega} \\Phi(W)$.\n\t\n\tAt first, given $\\tilde W \\in \\Omega$, we denote or find the $c_{*}= (c_{*}^{1}, \\dots, c_{*}^{k})$ in reduced problem.\n\t \t\n\t\\begin{equation}\n\t\\min_{c \\in \\mathbb{R}^{nk}} \\phi(\\tilde W, c) = \\min_{c \\in \\mathbb{R}^{nk}} {\\sum_{l=1}^{k}\\sum_{i=1}^{N}} \\tilde{w_{li}} \\cdot ||x_{i} - c^{l}||^{2}_{2}\n\t\\end{equation}\n\tIt's obvious that\n\t\\begin{equation}\n\tc_{*}^{l} = \\frac{\\sum_{i=1}^{N} \\tilde{w_{li}}\\cdot x_{i}}{\\sum_{i=1}^{N} \\tilde{w_{li}}} \n        \\end{equation} \t\n\tDenote that \n\t\\[\\Phi(W_{*}, c_{*}) = \\Phi(W_{*})\\]\n\tThen, we prove that $\\phi (W^{*}, c^{*}) = \\Phi(W_{*}, c_{*})$.\n\t\n\t``$\\phi (W^{*}, c^{*}) \\leq \\Phi(W_{*}, c_{*})$'' can be gotten by the definition and Lemma of concave function $\\Phi(W)$ easily.\n\t\t\n\t``$\\phi (W^{*}, c^{*}) \\geq \\Phi(W_{*}, c_{*})$'':\n\t\n\t$\\forall c \\in \\mathbb{R}^{nk}$, $\\phi(W^{*}, c^{*}) \\leq \\phi(W^{*}, c)$, and fix $W^{*}$, \n\t\\[\\phi(W^{*}, c_{*}) \\leq \\phi(W^{*}, c)\\]\n\t\n\tOr directly, $\\phi(W^{*}, c_{*}) = \\phi(W^{*}, c^{*})$. But $\\phi(W^{*}, c_{*}) \\geq \\phi(W_{*}, c_{*})$, so we conclude that \n\t\\[\\phi(W^{*}, c^{*}) \\geq \\phi(W_{*}, c_{*})\\] \n\t\n\tFurther, we can prove there exists $(W^{*}, c^{*}) = (W_{*}, c_{*})$.\n\t\t\n\t\\end{proof}\n\t\n\tNow we complete the proof of the \\textbf{Theorem \\ref{alo:convergence}}.\n\t\n\t$k$-means problem is one mixed integer programming with nonlinear objective, which is NP-hard. Here is difficulty consist of two part. First, the constraints are discrete. Secondly, the objective function is nonlinear and non-convex. However, next part we will list heuristic algorithms of $k$-means problem and analyze the pros and cons for each.\n\n\n\t\\section{Heuristic Algorithm of $k$-Means Problem}\\label{alo:Heuristic}\n\tThough the $k$-Means problem is NP-hard, there are many efficient heuristic algorithm to solve it. The most common one is the standard $k$-Means algorithm. To estimate different algorithms, we import some definition of validation entry of $k$-Means.\n\t\\begin{definition}[$\\alpha-approximation$]\n\tLet $\\phi^{*}$ be the objective of optimal $k$-Means clustering, a set of centers, $\\mathcal{C}$ is $\\alpha-approximation$, if \n\t\\begin{equation}\n\t\\phi_{X}(\\mathcal{C}) \\leq \\alpha \\phi^{*}\n\t\\end{equation}\n\t\\end{definition}\n\t\n\t\\subsection{Basic Knowledge}\n\t\\begin{lemma}\n\t\\label{sum}\n\tLet $S$ be a set of points with center of $x^{*}$, and let $z$ be an arbitrary point. Then, \n\t\\begin{equation}\n\t\\sum_{x \\in S}||x - z||^{2} = \\sum_{x \\in S} ||x - x^{*}||^{2} + |S|\\cdot ||z - x^{*}||^{2}\n\t\\end{equation}\n\t\\end{lemma}\n\t\n\t\\begin{lemma}[Power-mean Inequality]\n\tLet $a_{1}, \\dots, a_{m}\\in\\mathbb{R}$, then \n\t\\begin{equation}\n\t\\sum_{i = 1}^{m} a_{i}^{2} \\geq \\frac{1}{m} \\left(\\sum_{i = 1}^{m}a_{i}\\right)^{2}\n\t\\end{equation}\n\t\\label{powermean}\n\t\n\t\\end{lemma}\n\t\t\t\n\t\\begin{lemma}\n\t\\label{optle}\n\tLet $S$ be an arbitrary clustering set in optimal clustering, and $\\mathcal{C}$ be the clustering with just one center, which is chosen uniformly at random from $S$, then \n\t\\begin{equation}\n\tE[\\phi_{S}(\\mathcal{C})] = 2 \\phi^{opt}_{S} \n\t\\end{equation}\n\t\\label{powermean}\n\t\n\t\\end{lemma}\n\n\t\\subsection{The Standard $k$-Means Algorithm/Lloyd's Algorithm}\n\tThe Standard $k$-Means algorithm can be written in Algorithm \\ref{alo:kmeans}. Lloyd's Algorithm is not a good clustering algorithm in terms of efficiency or quality, whose running time can be exponential in the worst case and solution is locally optimal. Nevertheless, the unbeatable speed and simplicity of $k$-Means make its good reputation in industry.\n\t\n\t\n%%%%%%%\n\t\\begin{algorithm}\n\t\t\\caption{The Standard $k$-Means/Lloyd's Algorithm}\n\t\t\\label{alo:kmeans}\n\t\t\\textbf{Input:}  $X=\\lbrace x_{1},...,x_{N}| x_{i}\\in\\mathbb{R}^n\\rbrace$ and $k$\\\\\n\t\t\\textbf{Output:} The cluster centers $\\mathbf c_1,...,\\mathbf c^{k}\\in\\mathbb{R}^n$\\\\\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\State Arbitrarily choose the initial centers, $c^{1},c^{2},...,c^{k}$.\n\t\t\t\\State \\textbf{Repeat} for $1\\leq l \\leq k$,\n\t\t\t\t$$\n\t\t\t\tS^{l} = \\{x: ||x-c^{l}||^{2} \\leq ||x-c^{j}||^{2}, \\forall 1\\leq j \\leq k\\}\n\t\t\t\t$$\n\t\t\t\tUpdate\n\t\t\t\t$$\n\t\t\t\tc^{l}=\\cfrac{\\sum_{x\\in S^{l}}x}{|S^{l}|}.\n\t\t\t\t$$\n\t\t\t\\textbf{Until} $S^{l}$ don't change, for $\\forall l=1,2,\\dots,k$.\n\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\n\n\tFrom the figure \\ref{alo:kmeans basic} below, we can clearly see the processes of the standard $k$-Means($k$ = 2) algorithm in $\\mathbb{R}^{2}$. Figure $(a)$ scans the data set $X$. We initialize two cluster centers, which are marked by red and blue in figure $(b)$. Figure $(c), (d), (e)$ show the iteration of above algorithm. We stoped at the state of figure $(f)$.\n\n\t\\begin{figure}[htbp]\n\t\\centering{\\includegraphics[width=10cm]{cluster4.png}}\n\t\\caption{A concrete $k$-Means clustering process}\n\t\\label{alo:kmeans basic}\n\\end{figure}\n\n         Shokri, etc. put forward the partial convergence of  the standard $k$-Means algorithm. And they also described how to obtain a local minimum of the $k$-Means clustering problem under certain given conditions with Minkowsky metric. But how to find the global minimum is still a open problem.\n\n         \\begin{theorem}[Partial Convergence]\n         The standard $k$-Means algorithm converges to a partial optimal solution of $k$-Means clustering problem in a finite number of iterations.\n         \\end{theorem}\n\n         Here we give no specific proof but the definition of partial optimal solution of $k$-Means clustering problem.\n         \\begin{definition}\n         A point $(W^{*}, c^{*})$ is partial optimal solution of $k$-Means clustering problem if it satisfies the following:\n         \\begin{equation}\n         \\phi(W^{*}, c^{*}) \\leq \\phi(W^{*}, c), \\forall c \\in \\mathbb{R}^{nk};\n         \\end{equation}\n         and\n         \\begin{equation}\n         \\phi(W^{*}, c^{*}) \\leq \\phi(W, c^{*}), \\forall W \\in M_{k \\times N}(R).\n         \\end{equation}\n         \\end{definition}\n\n         We give another form of the standard $k$-Means algorithm, which can give proof of theorem \\textbf{Partial Convergence}.\n\n\t \\begin{algorithm}\n\t\t\\caption{The Standard $k$-means(another form)}\n\t         \\label{alo:kmeans2}\n\t\t\\textbf{Input:}  Data set $X=\\lbrace x_{1},...,x_{N}| x_{i}\\in\\mathbb{R}^n\\rbrace$ and $k$(and Tol)\n\t\t\n\t\t\\textbf{Output:} The cluster centers $c = ( c^{1},..., c^{k})$\n\t\t\n\t\t\\begin{algorithmic}[1]\n\t\t\\State Choose the \\textbf{initial} centers arbitrarily, $c_{0}=(c_{0}^{1},c_{0}^{2},...,c_{0}^{k})$.\n\t\t\\State \\textbf{Repeat:} for $j \\geq 0$\n                                  $$\n\t\t\tw_{li}^{j+1} = I(l = \\arg\\min_{1 \\leq l \\leq k} ||x_{i}-c_{j}^{l}||_{2}^{2})\n\t\t\t\t$$\n\t\t\t\tUpdate\n\t\t\t\t$$\n\t\t\tc_{j+1}^{l} = \\frac{\\sum_{i=1}^{N} w_{li}^{j+1} \\cdot x_{i}}{\\sum_{i=1}^{N} w_{li}^{j+1} }\n\t\t\t\t$$\n\t\t\t\\textbf{Stop} criterion $$ W^{j+1} = W^{j}$$ or ($||c_{j+1}-c_{j}|| \\leq Tol$)\n\t\t\\State \\textbf{Output} $$c = c_{j}$$ \n\t   \\end{algorithmic}\n\t   \\end{algorithm}\n\n\t\\subsection{The $k$-Means++ Algorithm}\n\tThe standard $k$-Means algorithm is highly sensitive to the initialization of cluster centers. It is easy to construct situations in which the standard $k$-Means algorithm converges to a local minimum that is arbitrarily bad compared to the optimal solution. Such an example is shown in figure \\ref{alo:algorithm ratio} for $k=3$ and where $x<y<z$.\n\n\t\t \\begin{figure}[htbp]\n\t\t \t\\centering{\\includegraphics[width=10cm]{algo.png}}\n\t\t \t\\caption{High approximation ratio}\n\t\t \t\\label{alo:algorithm ratio}\n\t\t \\end{figure}\n\n\t       If we initialize cluster centers $(1, 2, 3)$, we can get the optimal centers shown at the middle with the standard $k$-Means algorithm.\n\t        \\begin{equation}\n\t        \\phi^{opt} = (\\frac{x}{2})^{2}+(\\frac{x}{2})^{2}=(\\frac{x^{2}}{2})\n\t        \\end{equation}\n\n\t        Unfortunately, if we initialize centers $(2, 3 ,4)$, it is easy to verify that the centers shown at the bottom is the solution, a bad solution.\n\t         \\begin{equation}\n\t          \\phi_{heu} = (\\frac{y}{2})^{2}+(\\frac{y}{2})^{2}=(\\frac{y^{2}}{2})\n\t        \\end{equation}\n\t        We can see the two different initialization such that the algorithm converges to very different solutions.\n\n\t The following advanced algorithm provides a better initialization of the clustering and gives the $O(\\log k)-approximation$ solution.\n\t \\begin{theorem}\n\t \\label{competitive}\n\t If $\\mathcal{C}$ is the cluster result of $k$-Means ++, then the corresponding potential function $\\phi$ satisfies that \n\t \\begin{equation}\n\t E[\\phi] \\leq 8(\\ln k + 2)\\phi^{*}\n\t \\end{equation}\n\t \\end{theorem}\n\n\tThe k-means++ algorithm addresses the second of these obstacles above by specifying a procedure to initialize the cluster centers before proceeding with the standard k-means optimization iterations. With the k-means++ initialization, the algorithm is guaranteed to find a solution that is $ O(\\log k) $ competitive to the optimal k-means solution. It improves the running time of the standard $k$-Means algorithm (i.e. Lloyd's algorithm), and the quality of the final solution.\n\n\tThis algorithm is written in Algorithm \\ref{alo:kmean++}.\n\n\t\\begin{algorithm}[H]\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\caption{$k$-Means++}\n\t\t\t\\label{alo:kmean++}\n\t\t\t\\State $\\mathcal{C}\\leftarrow$ Choose $c_1$ with a uniform distribution among the data points ($c_1$ is the first center).\n\t\t\t%均匀分布\n\t\t\t\\State \\textbf{For $l \\leq k$},\n\n\t\tSample $x$ from $X$ with probability $\\frac{d^{2}(x, \\mathcal{C})}{\\phi_{X}(\\mathcal{C})}$.\n\t\t    \n\t\t    $\\mathcal{C} \\leftarrow \\mathcal{C}\\cup\\{x\\}$\n\t\t    \n\t\t    \\State Use the standard $k$-Means algorithm.\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\n         Here we import the definition of probability sampling. These days, we tend to use computers as the mechanism for generating random numbers as the basis for selection. One popular way to pick $x$ in the above algorithm is to:\n         \\begin{enumerate} [1.]\n         \\item Random one number $r \\in [0, \\phi_{X}(\\mathcal{C})]$; \n         \\item Do subtraction $r = r - d^{2}(x, \\mathcal{C})$ until $r \\leq 0$;\n         \\item Choose the above $x$ as the next seed.\n         \\end{enumerate}\n         \n         Next we give the proof of theorem \\ref{competitive} according to its creator's idea\\cite{kmeansplus}.\n         \n         \\begin{lemma}\n         \\label{corele}\n         Let $\\mathcal{C}$ be an arbitrary cluster, and $\\mathcal{C}^{*}$ be one cluster of the optimal clustering. Choose $u$ centers from $\\mathcal{C}^{*} \\setminus \\mathcal{C}$ and the union of clustering be $X^{u}$. Define $X^{c}$ as $X - X^{u}$. If adding $t \\leq u$ randomly centers to $\\mathcal{C}$ as the above algorithm \\ref{alo:kmean++}'s step $\\textbf{1}$ and $\\textbf{2}$, let $\\tilde{\\mathcal{C}}$ denote the result set, and $\\tilde{\\phi}$ denote the corresponding potential function. Then, \n         \\begin{equation}\n         E[\\phi_{X}(\\tilde{\\mathcal{C}})] \\leq \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\\right)\\cdot (1+H_{t}) + \\frac{u-t}{u}\\cdot \\phi_{X^{u}}(\\mathcal{C})         \n         \\end{equation}\n         where \n         \\begin{equation}\n         H_{t} = \\begin{cases}& 1 + \\frac{1}{2} + \\cdots + \\frac{1}{t}, \\ \\text{$t > 0$}\\\\\n         & 0,\\  \\text{ $t = 0$}\n         \\end{cases}\n         \\end{equation}\n         %proof\n         \\begin{proof}\n         \n         For convenience, we define probability events as follows.\n         \\begin{equation}\n         \\begin{cases}\n        & \\mathscr{A} = \\{\\text{add the first center from $X$}\\}\\\\\n         & \\mathscr{A}_{1} = \\{\\text{add the first center from $X^{u}$}\\}\\\\\n         &\\mathscr{A}_{2}= \\{\\text{add the first center from $X^{c}$}\\}\\\\\n         &\\mathscr{A}_{1} \\cap \\mathscr{A}_{2} = \\empty, \\mathscr{A}_{1} \\cup  \\mathscr{A }_{2} = \\mathscr{A}\n         \\end{cases}\n         \\end{equation}\n         \n         One can split the whole expectation into two branches.\n         \\begin{equation}\n         E[\\phi_{X}(\\tilde{\\mathcal{C}})] = Prob_{\\mathscr{A}_{1}} \\cdot E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}] + Prob_{\\mathscr{A}_{1}} \\cdot E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{2}]\n         \\end{equation}         \n\n         \n         Firstly, when $t = 0$ and $u > 0$, i.e. $\\phi_{X}(\\mathcal{C}^{'}) = \\phi_{X}(\\mathcal{C})$. it following $1 + H_{t} = 1$ naturally has  \n         \\begin{equation}\n         E[\\phi_{X}(\\tilde{\\mathcal{C}})] \\leq \\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}} + \\phi_{X^{u}}(\\mathcal{C})         \n         \\end{equation}\n         \n         If $t = u = 1$, there has \n           \\begin{equation}\n           \\label{eqlemma}\n           \\begin{aligned}\n        E[\\phi_{X^{u}}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}]   = &\\sum_{x_{0} \\in X^{u}} \\frac{d^{2}(x_{0}, \\mathcal{C})}{\\sum_{x \\in X^{u}} d^{2}(x, \\mathcal{C})} \\sum_{x \\in X^{u}} \\min \\{d^{2}(x, \\mathcal{C}), ||x - x_{0}||^{2}\\} & \\tilde{\\mathcal{C}} = \\mathcal{C} \\cup \\{x_{0}\\} \\\\\n          \\leq &   \\sum_{x_{0} \\in X^{u}}\\frac{ \\left(\\frac{2}{|X^{u}|} \\sum_{x \\in X^{u}}  d^{2}(x, \\mathcal{C}) + \\frac{2}{|X^{u}|} \\sum_{x\\in X^{u}} ||x - x_{0}||^{2} \\right)}{\\sum_{x \\in X^{u}} d^{2}(x, \\mathcal{C})} \\cdot & Lemma\\  \\ref{powermean}\\\\\n         &\\sum_{x \\in X^{u}} \\min \\{d^{2}(x, \\mathcal{C}), ||x - x_{0}||^{2}\\} \\\\\n         \\leq &  \\frac{4}{|X^{u}|} \\sum_{x_{0} \\in X^{u}}  \\sum_{x\\in X^{u}} ||x-x_{0}||^{2} \\\\\n          = & 4\\cdot \\frac{1}{|X^{u}|}  \\sum_{x_{0} \\in X^{u}} \\left(\\sum_{x\\in X^{u}} ||x - c^{u}||^{2} + |X^{u}|\\cdot ||x_{0} - c^{u}||^{2}\\right)& Lemma \\ \\ref{sum}\\\\\n          = & 8\\phi^{opt}_{X^{u}} & Lemma \\ref{optle}\n         \\end{aligned}   \n         \\end{equation}\n         where $c^{u}$ is the true center of $X^{u}$ in optimal cluster.\n         Then \n         \n         \\begin{equation}\\begin{aligned}\n          E[\\phi_{X}(\\tilde{\\mathcal{C}})] = &\\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}] + \\frac{\\phi_{X^{c}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{2}]\\\\     \n          \\leq &\\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\left(8\\phi^{opt}_{X^{u}} +\\phi_{X^{c}}(\\mathcal{C}) \\right) + \\frac{\\phi_{X^{c}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\phi_{X}(\\mathcal{C})\\\\    \n          \\leq &  2\\phi_{X}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\n          \\end{aligned}\n         \\end{equation}\n         \n          \n         %%%%induction\n         By using induction method, it is sufficient to suppose that the result holds for the cases that $(t-1, u)$ and $(t-1, u-1)$. With similar analysis method as the case of $t = u =1$, if the event $\\mathscr{A}_{2}$ happen with probability, $\\frac{\\phi_{X^{c}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})}$, then we still need choose $t-1$ centers with $u$ being unchanged, i.e., \n         \\begin{equation}\n         E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{2}] \\leq \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\\right)\\cdot (1+H_{t-1}) + \\frac{u-t + 1}{u}\\cdot \\phi_{X^{u}}(\\mathcal{C})\n         \\end{equation}\n         \n         Supposed that $\\mathscr{A}_{1}$ happened, more specifically, let the first center be chosen from one clustering set $S \\subseteq X^{u}$ and $Prob_{x}$ denote the probability of choosing $x \\in S$ as the first center. Besides, we define the event $\\mathscr{A}_{1}^{s} = \\{\\text{add the first center from $S$}\\}$ and we have its probability of $\\frac{\\phi_{S}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})}$. We can conclude similar conclusion as the equation \\ref{eqlemma}.\n         $$ \\sum_{x \\in S} Prob_{x} \\cdot \\phi_{S}(\\mathcal{C}) \\leq 8\\phi^{opt}_{S} $$ \n         \n          \\begin{equation}\n          \\begin{aligned}\n         &E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}^{s}] \\\\\n         = & \\sum_{x \\in S} Prob_{x} \\cdot \\left( \\left(\\phi_{X^{c}}(\\mathcal{C}) + \\phi_{S}(\\mathcal{C})\n         + 8\\phi^{opt}_{X^{u} - S}\\right)\\cdot (1+H_{t-1}) + \\frac{u-t}{u-1}\\cdot \\phi_{X^{u}-S}(\\mathcal{C})\\right)\\\\\n           \\leq & \\left(\\phi_{X^{c}}(\\mathcal{C})\n         + 8\\phi^{opt}_{X^{u} }\\right)\\cdot (1+H_{t-1}) + \\frac{u-t}{u-1}\\cdot \\phi_{X^{u}-S}(\\mathcal{C}) \n           \\end{aligned}\n         \\end{equation}\n         \n         \\begin{equation}\n         \\begin{aligned}\n         &\\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\cdot E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}] \\\\\n        = & \\sum_{S \\subseteq X^{u}} \\frac{\\phi_{S}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}^{s}]\\\\ \n         = & \\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\cdot \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u} }\\right)\\cdot (1+H_{t-1}) + \\frac{u-t}{u-1}\\cdot \\sum_{S \\subseteq X^{u}} \\frac{\\phi_{S}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})}\\cdot \\phi_{X^{u} - S}(\\mathcal{C})\\\\\n         \\leq &  \\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\cdot \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u} }\\right)\\cdot (1+H_{t-1})  \\\\\n         & + \\frac{u-t}{u-1}\\cdot \\frac{1}{\\phi_{X}(\\mathcal{C})} \\left(\\phi_{X^{u}}^{2}(\\mathcal{C}) - \\frac{1}{u} \\cdot \\phi_{X^{u}}^{2}(\\mathcal{C}) \\right) \\\\\n         = & \\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\cdot \\left(\\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u} }\\right)\\cdot (1+H_{t-1}) + \\frac{u - t}{u} \\cdot \\phi_{X^{u}}(\\mathcal{C}) \\right) \\\\\n         \\end{aligned}     \n         \\end{equation}\n         \n         Then \n         \\begin{equation}\n         \\begin{aligned}\n         E[\\phi_{X}(\\tilde{\\mathcal{C}})] = &\\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{1}] + \\frac{\\phi_{X^{c}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} E[\\phi_{X}(\\tilde{\\mathcal{C}})|\\mathscr{A}_{2}] \\\\\n         \\leq &   \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\\right)\\cdot (1+H_{t-1}) + \\frac{u-t }{u}\\cdot \\phi_{X^{u}}(\\mathcal{C}) + \\frac{\\phi_{X^{c}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\cdot \\frac{\\phi_{X^{u}}(\\mathcal{C})}{\\phi_{X}(\\mathcal{C})} \\\\\n         \\leq &  \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\\right)\\cdot (1+H_{t-1} + \\frac{1}{u}) + \\frac{u-t }{u}\\cdot \\phi_{X^{u}}(\\mathcal{C})\\\\\n           \\leq &  \\left(\\phi_{X^{c}}(\\mathcal{C}) + 8\\phi^{opt}_{X^{u}}\\right)\\cdot (1+H_{t}) + \\frac{u-t }{u}\\cdot \\phi_{X^{u}}(\\mathcal{C})\\\\\n         \\end{aligned}     \n         \\end{equation}\n         \\end{proof}  \n         \\end{lemma}\n         Considering the cluster $\\mathcal{C}$ that just cover the first clustering set $S$ in optimal clustering, after algorithm \\ref{alo:kmean++}'s step $\\textbf{1}$ and $\\textbf{2}$, we get the initial seeding and clustering $\\tilde{\\mathcal{C}}$, which means applying lemma \\ref{corele} with $t = u = k-1$, i.e., we choose $X^{c} = S$, then \n\t\n\t\\begin{equation}\n\t\\begin{aligned}\n\tE[\\phi_{X}(\\tilde{\\mathcal{C}})]  \\leq &\\sum_{x \\in S} Prob_{x} \\cdot\\left(\\phi_{S}(\\mathcal{C}) + 8\\phi^{opt}_{X} - 8\\phi_{S}^{opt}\\right)\\cdot (1+H_{k-1}) &\\text{Lemma \\ref{optle}} \\\\\n\t\\leq &8\\phi^{opt}_{X}\\cdot (1+\\ln k) & H_{k-1} \\leq 1+\\ln k\\\\\n\t\\end{aligned}     \n\t\\end{equation}\n         \n         \n         \n         \n         \n         \n         \\subsection{Scalable $k$-Means++}\n         \\newcommand{\\RNum}[1]{\\uppercase\\expandafter{\\romannumeral #1}}\n         $k$-Means$\\RNum{2}$ uses an oversampling factor $l = \\Omega(k)$, which is inspired by $k$-Means++. As we will see,\n         \t\\begin{algorithm}[H]\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\caption{$k$-Means$\\RNum{2}$}\n\t\t\t\\label{alo:kmean2}\n\t\t\t\\State $\\mathcal{C}\\leftarrow$ Choose $c_1$ uniformly at random among the data points ($c_1$ is the first center).\n\t\t\t%均匀分布\n\t\t\t\\State $\\psi \\leftarrow \\phi_{X}(\\mathcal{C})$\n\t\t\t \\State For $O(\\log \\psi)$ times do \n\n\t\t$\\mathcal{C}^{'} \\leftarrow $sample independently $x$ from $X$ with probability $\\frac{l \\cdot d^{2}(x, \\mathcal{C})}{\\phi_{X}(\\mathcal{C})}$.\n\t\t    \n\t\t    $\\mathcal{C} \\leftarrow \\mathcal{C}\\cup\\{x\\}$\n\t\t    \n\t\t    end\n\t\t    \n\t\t    \\State For $x \\in \\mathcal{C}$, set $\\omega_{x}$ to be the number of points in $X$ cluster to $x$ than any other point in $\\mathcal{C}$\n\t\t    \\State Recluster the weighted points in $\\mathcal{C}$ into $k$ clusters.\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\t\n          \\begin{theorem}\n          \\label{alo:the}\n\t If an $\\alpha-approximation$ algorithm is used in Step 5, the Algorithm $\\ref{alo:kmean2}$ obtains a solution that is an $O(\\alpha)-approximation$ to $k$-Means.\n\t \\end{theorem}\n\t \n\t More mathematically, there has \n\t  \\begin{theorem}\n\t Let $\\alpha = exp(-(1- e^{-l/(2k)})) \\approx e^{-\\frac{l}{2k}}$. In Algorithm $\\ref{alo:kmeans2}$, \n\t \\begin{equation}\n\t E[\\phi_{X}(\\mathcal{C}\\cup \\mathcal{C}^{'})] \\leq 8 \\phi^{*} + \\frac{1+\\alpha}{2} \\phi_{X}(\\mathcal{C})\n\t \\end{equation}\n\t \\end{theorem}\n\t \n\t \\begin{corollary}\\label{alo:cor1}\n\tIf $\\phi^{(i)}$ is the objective of the clustering after the $i$-th round of Algorithm $\\ref{alo:kmeans2}$, then \n\t\\begin{equation}\n\t E[\\phi^{(i)}] \\leq \\frac{16}{1 - \\alpha} \\phi^{*} + \\left(\\frac{1+\\alpha}{2}\\right)^{i} \\psi\n\t \\end{equation}\n\t \\end{corollary}\n\t Corollary $\\ref{alo:cor1}$ implies that after $O(\\log \\psi)$ rounds, the result can touch $O(\\phi^{*})$. Then the Theorem is an immediate consequence.\n\t \n\\section{The Choice of $k$}\n         In general, we don't know the optimal number of clusters, $k$ in the practical probems. Here we give one method named ``elbow''.\n         Elbow method has two step can be written as following:\n         \\begin{enumerate}\n         \\item Compute the sum of squared error $(SSE)$ for some values of $l$ (for example $2, 4, 6, 8,$ etc.):\n         \\begin{equation}\n         SSE={\\sum_{l=1}^{k}\\sum_{x \\in S_{l}}} ||x-c_{l}||^{2}\n         \\end{equation}\n         \\item Plot $l$ against the SSE, and choose the $k$ at which the $SSE$ decreases abruptly.\n\\end{enumerate}\n\n         For one example as the figure shown, we will understand how elbow method works.\n\n          \\begin{figure}[htbp]\n\t\t \t\\centering{\\includegraphics[width=10cm]{cluster_numbers.png}}\n\t\t \t\\caption{Using the Elbow Method to Determine the Optimal Number of Clusters}\n\t\t \\end{figure}\n\n         We note Dataset A on the left. At the top we see a number line plotting each point in the dataset, and below we see an elbow chart showing the SSE after running $k$-Means clustering for $k$ going from $1$ to $10$. We see a pretty clear elbow at $k = 3$, indicating that $3$ is the best number of clusters.\n\n         However, the elbow method doesn't always work well; especially if the data is not very clustered. Notice how the elbow chart for Dataset B does not have a clear elbow. Instead, we see a fairly smooth curve, and it's unclear what is the best value of $k$ to choose.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Other Contents}\n$k$-Means is one type of $k$-Partition clustering, which is about that given a set of $N$ points in Euclidean space and an integer $k$, find a partition of these points into $k$ subsets, each with a center. There are three common formulations of $k$-partition clustering depending on the particular objective used. \n\\begin{enumerate}[a.]\n\\item $k$-Center use the objective to minimize the maximum distance between a point and its nearest cluster center.\n\\item $k$-Median's objective is to minimize the sum of the distance of each point and its center.\n\\end{enumerate}\n\\subsection{Convolutional $k$-Means Clustering}\n\tConvolutional $k$-Means clustering is another type of algorithms for different problems, because CNN is in general a supervised learning algorithm. We mentioned it here just for complementary.\n\n\tConvolutional $k$-Means clustering proposed to train a deep convolutional network based on an enhanced version of the $k$-Means clustering algorithm, which reduces the number of correlated parameters in the form of similar filters, and thus increases test categorization accuracy.\n\n\tGenerally speaking, this algorithm uses $k$-Means to cluster the parameters of CNN.\n", "meta": {"hexsha": "1547227e140c44c4c51077239a83cd59546fdabb", "size": 31694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/Kmeans.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/Kmeans.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/Kmeans.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 55.312390925, "max_line_length": 504, "alphanum_fraction": 0.5949075535, "num_tokens": 11434, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8499711794579723, "lm_q1q2_score": 0.7617878343578005}}
{"text": "%---------------------------Distortion---------------------------\n\\section{Distortion} \n\nGiven a set of Gauss points $G=\\{g_k\\}$ for a hexahedron, let\n\\[\n|J| = \\min_{g_k}\\left\\{\\det\\left(J_{g_k}\\right)\\right\\}\n\\]\nbe the minimum determinant of the Jacobian when evaluated at each Gauss point $g_k$.\nThen the distortion is\n\\[\nq = \\frac{|J| V_m}{V}  \n\\]\nwhere $V_m = 8$ is the volume of a ``master'' hexahedron defined by the vertices\n\\[\n\\begin{array}{lcrcrcrl}\n  \\vec P_0 &= (&-1&,&-1&,& -1&)\\\\\n  \\vec P_1 &= (& 1&,&-1&,& -1&)\\\\\n  \\vec P_2 &= (& 1&,& 1&,& -1&)\\\\\n  \\vec P_3 &= (&-1&,& 1&,& -1&)\n\\end{array}\\rule{5em}{0pt}\n\\begin{array}{lcrcrcrl}\n  \\vec P_4 &= (&-1&,&-1&,&  1&)\\\\\n  \\vec P_5 &= (& 1&,&-1&,&  1&)\\\\\n  \\vec P_6 &= (& 1&,& 1&,&  1&)\\\\\n  \\vec P_7 &= (&-1&,& 1&,&  1&)\n\\end{array}\n\\]\nand $V$ is the volume of the hexahedron being evaluated.\nSee \\S\\ref{s:hex-volume} for details on computing the hex volume $V$.\n\n\\hexmetrictable{distortion}%\n{$L^3$}%                                      Dimension\n{$[0.5,1]$}%                                  Acceptable range\n{$[0,1]$}%                                    Normal range\n{$[-DBL\\_MAX,DBL\\_MAX]$}%                     Full range\n{$1$}%                                        Cube\n{Adapted from \\cite{ideas:xx}}%               Citation\n{v\\_hex\\_distortion}%                         Verdict function name\n", "meta": {"hexsha": "f3ebfbcb10379cb8657e1aaf38665ee53280b761", "size": 1359, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexDistortion.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/HexDistortion.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/HexDistortion.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 34.8461538462, "max_line_length": 84, "alphanum_fraction": 0.4768211921, "num_tokens": 478, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.934395168021653, "lm_q2_score": 0.8152324871074608, "lm_q1q2_score": 0.7617492967674859}}
{"text": "\\label{seq_method_characteristics}\n\\section{Method of the characteristics}\n\n\\manuelComment{based on this video: https://www.youtube.com/watch?v=LpHqrlrU5pM}\n\nThe method of the characteristics is a powerful method to solve PDE. This method enable us to solve a wide range of problems including:\n\\begin{enumerate}\n  \\item Linear:\n  \\begin{equation}\n  a(x, y) \\frac{\\partial u}{\\partial x}\n  + b(x, y) \\frac{\\partial u}{\\partial y}\n  + c(x, y) u\n  = f(x, y)\n  \\end{equation}\n  \\item Semi-linear:\n  \\begin{equation}\n  a(x, y) \\frac{\\partial u}{\\partial x}\n  + b(x, y) \\frac{\\partial u}{\\partial y}\n  + c(x, y) u\n  = f(x, y, u)\n  \\end{equation}\n  \\item  Quasi-linear:\n  \\begin{equation}\n  a(x, y) \\frac{\\partial u}{\\partial x}\n  + b(x, y) \\frac{\\partial u}{\\partial y}\n  = f(x, y, u)\n  \\end{equation}\n\\end{enumerate}\n\nIn this introduction  we will focus on semi-linear problems that also include\nthe linear ones. Let us consider a PDE of the form\n\\begin{equation}\n  a(x, y) \\frac{\\partial u}{\\partial x}\n  + b(x, y) \\frac{\\partial u}{\\partial y}\n  = f(x, y, u),\n  \\label{eq_semi_linear}\n\\end{equation}\nwhich is a semi-linear PDE. Semi-linear equations include equations of the form\n\\begin{equation}\n  a(x, y) \\frac{\\partial u}{\\partial x}\n  + b(x, y) \\frac{\\partial u}{\\partial y}\n  + c(x, y) u\n  = g(x, y),\n\\end{equation}\nwith $f(x, y, u) = g(x, y) - c(x, y) u$.\n\nThis PDE must have an initial condition associated with it. This initial\ncondition can be of the form\n\\begin{equation}\n  u(x, 0) = u_0(x),\n\\end{equation}\nor\n\\begin{equation}\n  u(0, y) = u_1(x).\n\\end{equation}\nThe pair of a PDE like \\eref[eq_semi_linear] and an initial condition is\nsometimes called a semi-linear Cauchy problem.\n\nAny solution to these Cauchy problems can be represented by a surface $u \\equiv\nu(x, y)$ in a 3D space as schematically shown in \\fref[fig_integral_surface]\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[scale=.75]{fig/fig1_method_characteristics.png}\n\t\\caption{\\captionStroke{Schematic integral surface.}}\n\t\\label{fig_integral_surface}\n\\end{figure}\n\nA surface $u = u(x, y)$ that solves a Cauchy problem is known as an integral\nsurface since integration is used to solve these problems. We can write down the\nequation of this integral surface as\n\\begin{equation}\n  F(x, y, u) \\equiv u(x, y) - u = 0.\n\\end{equation}\nNote that the first $u(x, y)$ is a function, while the second $u$ is a\nvariable. So for example if\n\\begin{equation}\n  u(x, y) = x - y^2,\n\\end{equation}\nthen\n\\begin{equation}\n  F(x, y, u) = x - y^2 - u.\n\\end{equation}\n\nFrom vector calculus we know that any vector $\\mathbf{n}$ normal to the surface $F = 0$ is given by the gradient\n\\begin{equation}\n  \\mathbf{n} = \\nabla F =\n  \\frac{\\partial u}{\\partial x} \\mathbf{i}\n  + \\frac{\\partial u}{\\partial y} \\mathbf{j}\n  - \\mathbf{k}.\n\\end{equation}\n\n\\fref[fig_normal_vector] shows a schematic representation of this vector. The\nvector is represented pointing downwards since $F = u(x, y) - u$.\n\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[scale=.75]{fig/fig2_method_characteristics.png}\n\t\\caption{\\captionStroke{Schematic integral surface with normal vector.}}\n\t\\label{fig_normal_vector}\n\\end{figure}\n\nWe can rewrite the PDE as a dot product of the form\n\\begin{equation}\n  \\left\\langle a(x, y), b(x, y), f(x, y, u) \\right\\rangle \\cdot \\mathbf{n} = 0.\n\\end{equation}\n\nThis implies that since the dot product is zero, the vector $\\left\\langle a(x,\ny), b(x, y), f(x, y, u) \\right\\rangle$ must be normal to $\\mathbf{n}$. Since we\nstated that the vector $\\mathbf{n}$ is normal to the surface $F(x, y, u) = 0$,\nany vector $\\mathbf{v}$ normal to $\\mathbf{n}$ must lie in the tangential plane\nto $F = 0$ at every point as depicted in \\fref[fig_tangential_vector]\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[scale=.75]{fig/fig3_method_characteristics.png}\n\t\\caption{\\captionStroke{Schematic integral surface with normal vector\n  $\\mathbf{n}$ and tangential vector $\\mathbf{v}$.}}\n\t\\label{fig_tangential_vector}\n\\end{figure}\n\nBut what do all these details mean? This means that the PDE requires for any\nintegral surface that solves the equation to be tangential to the vector\n\\begin{equation}\n  \\mathbf{v} = a(x,y) \\mathbf{i} +\n  b(x, y) \\mathbf{j} +\n  f(x, y, u) \\mathbf{k}.\n\\end{equation}\nThat is, if we start at some point set by the initial condition and we move in\nthe direction of the vector $\\mathbf{v}$ (which we can determine just by looking\nat the PDE) then we move along a curve that lies entirely within the surface\n$F = 0$. This curve, depicted in \\fref[fig_characteristic_curve] is called a\n\\textit{characteristic curve}. And by finding the collection of these\ncharacteristic curves we can therefore reconstruct the entire integral surface,\nsolving therefore the PDE.\n\\begin{figure}[h!]\n\t\\centering \\includegraphics[scale=.75]{fig/fig4_method_characteristics.png}\n\t\\caption{\\captionStroke{Schematic of a characteristic curve on an integral\n  surface.}}\n\t\\label{fig_characteristic_curve}\n\\end{figure}\n\nIn other words, so far we have shown that given an initial condition\n$u(x, 0) = u_0(x)$ as long as we move along the direction given by the vector\n$\\mathbf{v} = \\left\\langle a(x,y), b(x,y), f(x,y,u) \\right\\rangle$ we are\nguaranteed to lay on the integral surface. So the process to reconstruct the\nentire surface would be to choose a value for $x$, then start at $u_0(x)$ and\nmove along $\\mathbf{v}$; then we would choose a new value of $x$ and repeat the\nprocess. At the end, the union of all these paths along the integral surface\nwill determine entirely the solution of the PDE. The advantage of the method as\nwe will show is that walking along the characteristic curve is equivalent to\nsolving an ODE, which for many cases we know how to do.\n\nWe can describe all the points on a characteristic curve by parametrizing\nthe curve with a vector function\n\\begin{equation}\n  \\mathbf{p}(t) = x(t) \\mathbf{i} + y(t) \\mathbf{j} + u(t) \\mathbf{k}.\n\\end{equation}\nFurthermore, we can obtain a vector tangential to this curve $\\mathbf{p}(t)$ by\ndifferentiating with respect to the parametrization variable $t$, i.e.\n\\begin{equation}\n  \\mathbf{p}'(t) = x'(t) \\mathbf{i}+ y'(t) \\mathbf{j} + u'(t) \\mathbf{k}.\n\\end{equation}\n\nSince the curve $\\mathbf{p}(t)$ lays on the integral surface $F = 0$, and\n$\\mathbf{p}'(t)$ is tangential to this curve, that means that $\\mathbf{p}'(t)$\nalso lies on the surface.\n\nWe stated earlier that if we move along the direction of $\\mathbf{v}$ we will\nreconstruct the path of the characteristic curve which we now parametrized as\n$\\mathbf{p}(t)$. That implies that $\\mathbf{v}$ and $\\mathbf{p}'(t)$ must be\npointing in the same direction, i.e.\n\\begin{equation}\n  \\mathbf{p}'(t) = \\lambda \\mathbf{v},\n\\end{equation}\nwhere $\\lambda$ is a scalar. This can also be written as\n\\begin{equation}\n  x'(t)\\mathbf{i} + y'(t)\\mathbf{j} + u'(t)\\mathbf{k} =\n  \\lambda a(x,y) + \\lambda b(x,y) + \\lambda f(x,y,u).\n\\end{equation}\nin other words\n\\begin{align}\n  x'(t) = \\lambda a(x,y),\\\\\n  y'(t) = \\lambda b(x,y), \\\\\n  u'(t) = \\lambda f(x,y,u).\n\\end{align}\nWe can now solve for $\\lambda$ and equate all of the solutions, obtaining\n\\begin{equation}\n  {{dx \\over dt} \\over a(x,y)} =\n  {{dy \\over dt} \\over b(x,y)} =\n  {{du \\over dt} \\over f(x,y,u)},\n  \\label{eq_char_eq}\n\\end{equation}\nor simply in a compact differential form\n\\begin{equation}\n  {dx \\over a} = {dy \\over b} = {du \\over f}.\n\\end{equation}\nThese are the characteristic equations that are the key to the method. From\n\\eref[eq_char_eq] we can form two pairs of ODE as follows\n\\begin{equation}\n  {dy \\over dx} = {b(x,y) \\over a(x,y)}; \\;\n  {du \\over dx} = {f(x,y,u)\\over a(x,y)},\n\\end{equation}\nor\n\\begin{equation}\n  {dx \\over dy} = {a(x,y) \\over b(x,y)}; \\;\n  {du \\over dy} = {f(x,y,u)\\over b(x,y)}.\n\\end{equation}\nSolving this system of ODEs determines the characteristic of the PDE, giving\na clear path to the PDE solution.\n\n\\subsection{Example}\n\nSolve for $x > 0$\n\\begin{equation}\n  x {\\partial u \\over \\partial x} + y {\\partial u \\over \\partial y} = x e^{-u},\n\\end{equation}\nwith boundary condition\n\\begin{equation}\n  u(x, x^2) = x.\n  \\label{eq_boundary_cond}\n\\end{equation}\n\nFirst we set the system of ODEs for this semilinear problem. We have\n\\begin{equation}\n  {dx \\over a} = {dy \\over b} = {du \\over f}.\n\\end{equation}\nsubstituting $f \\equiv x e^{-u}$ we have\n\\begin{equation}\n  {dx \\over a} = {dy \\over b} = {du \\over x e^{-u}}.\n\\end{equation}\n\nWe now write the pair of ODEs\n\\begin{equation}\n  {dy \\over dx} = {y \\over x},\n  \\label{eq_char_eq_one}\n\\end{equation}\nand\n\\begin{equation}\n  {dy \\over dx} = e^{-u} {x \\over x}.\n  \\label{eq_char_eq_two}\n\\end{equation}\n\n\\eref[eq_char_eq_one] can be solved using the integrating factor method. The\nsolution is given by\n\\begin{equation}\n  y = C_1 \\exp \\left\\{ \\int {1 \\over x} dx \\right\\} = C_1 e^{\\ln x} = C_1 x,\n\\end{equation}\nthus $C_1 = y / x$. \\eref[eq_char_eq_two] can be simply solved by separation of\nvariables giving\n\\begin{equation}\n  e^u = C_2 + x \\rightarrow C_2 = e^u - x.\n\\end{equation}\n\nWe now need to find a functional relationship between these constants $C_1$ and\n$C_2$. That is because usually after solving the \\eref[eq_char_eq_one] we would\nhave to substitute the solution into \\eref[eq_char_eq_two]. So let's combine\nboth constants via $C_2 = G(C_1)$, i.e.\n\\begin{equation}\n  e^u - x = G\\left( {y \\over x} \\right).\n\\end{equation}\nNow to find $G$ we use the boundary condition on \\eref[eq_boundary_cond]. This\ngives\n\\begin{equation}\n  e^x = x + G \\left( {x^2 \\over x} \\right) = x = G(x).\n\\end{equation}\nTherefore\n\\begin{equation}\n  G(x) = e^x - x.\n  \\label{eq_sol_ODE}\n\\end{equation}\n\nHence we substitute \\eref[eq_sol_ODE] into the solution, obtaining\n\\begin{equation}\n  e^u = x + e^{y/x} - {y \\over x}.\n\\end{equation}\n\nThe reason $C_1$ and $C_2$ have to be functionally related is because we are\nsolving the ODEs along the characteristic curves. Therefore to get to the value\nof $u$ we need to solve along every characteristic curve, and each time we solve\nit we obtain an undetermined constant $C_2$. This constant $C_2$ can vary\nbetween characteristics, but it must be the same along a particular\ncharacteristic. The particular characteristic curve that we are considering is\ndetermined by the constant $C_1$. Hence, there must be a functional relation\nbetween $C_1$ and $C_2$.\n", "meta": {"hexsha": "dbbb984e2cd5774e9d08d826fe0c27d43834e77f", "size": 10280, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/appendix_method_characteristics.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_method_characteristics.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_method_characteristics.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": 36.5836298932, "max_line_length": 135, "alphanum_fraction": 0.7016536965, "num_tokens": 3330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114836, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.761633627758562}}
{"text": "\\section{Brief Derivation for equation (\\ref{Equ_ori})}\n\\par\\noindent\n\nFor convenience, here name $\\angle CAB $ as $\\alpha$ in figure \\ref{vectorG}. Then it has\n$$|AD| = |\\vec{r^{'}}| \\cos(\\alpha - \\theta)$$\n$$|B^{'}D| = |\\vec{r^{'}}| \\sin(\\alpha - \\theta)$$\n\nBy applying angle sum identities,\n$$|AD| = |\\vec{r^{'}}| (\\cos(\\alpha)\\cos(-\\theta) - \\sin(\\alpha)\\sin(-\\theta))$$\n$$|B^{'}D| = |\\vec{r^{'}}| (\\sin(\\alpha)\\cos(-\\theta) + \\sin(-\\theta)\\cos(\\alpha))$$\n\nBecause $|r^{'}| = |r|$, $\\sin(\\theta) = - \\sin(-\\theta)$ for $\\theta \\in [0, \\pi/2)$ and $\\cos(\\theta) = \\cos(-\\theta)$ for $\\theta \\in [0, \\pi/2)$,\n$$|AD| = |\\vec{r}| (\\cos(\\alpha)\\cos(\\theta) + \\sin(\\alpha)\\sin(\\theta))$$\n$$|B^{'}D| = |\\vec{r}| (\\sin(\\alpha)\\cos(\\theta) - \\sin(\\theta)\\cos(\\alpha))$$\n\nThen,\n$$|AD| = (|\\vec{r}|\\cos(\\alpha))\\cos(\\theta) + (|\\vec{r}|\\sin(\\alpha))\\sin(\\theta)$$\n$$|B^{'}D| = (|\\vec{r}|\\sin(\\alpha))\\cos(\\theta) - (|\\vec{r}|\\cos(\\alpha))\\sin(\\theta)$$\n\nHence,\n$$|AD| = |AC|\\cos(\\theta) + |BC|\\sin(\\theta)$$\n$$|B^{'}D| = |BC|\\cos(\\theta) - |AC|\\sin(\\theta)$$\n\nFinally,\n$$|x^{'}| = |x|\\cos(\\theta) + |y|\\sin(\\theta)$$\n$$|y^{'}| = |x|(- \\sin(\\theta)) + |y|\\cos(\\theta)$$\n\nFor $\\theta \\in [0, \\pi/2)$, the equations can be written simply as\n$$ x^{'} = x\\cos\\theta + y\\sin\\theta$$\n$$ y^{'} = x(- \\sin\\theta) + y\\cos\\theta$$\n\nwhich can be easily extended to $\\theta \\in [ 0, 2\\pi + 2k\\pi)$ via discussion under different cases, given that $k \\in Integer$.\\\\\n\nThe two equations can be written in matrix form :\n\\begin{equation*}\n  \\begin{bmatrix}\n   x^{'} \\\\ y^{'}\n   \\end{bmatrix} =   \\begin{bmatrix}\n      \\cos\\theta & \\sin\\theta \\\\\n      -\\sin\\theta & \\cos\\theta\n    \\end{bmatrix} \\begin{bmatrix}\n      x \\\\ y\n     \\end{bmatrix}\n\\end{equation*}\n\\section{Brief Derivation for equation (\\ref{Equ_aff})}\n\\par\\noindent\nThe equation \\ref{Equ_anycen} can be transformed to:\n\\begin{equation*}\n  \\begin{split}\n  \\begin{bmatrix}\n   x^{'} \\\\ y^{'}\n   \\end{bmatrix} &= \\begin{bmatrix} \\cos\\theta & \\sin\\theta \\\\ -\\sin\\theta & \\cos\\theta \\end{bmatrix} \\left(\\begin{bmatrix} x \\\\ y \\end{bmatrix} - \\begin{bmatrix} c_{x} \\\\ c_{y} \\end{bmatrix}\\right) + \\begin{bmatrix} c_{x} \\\\ c_{y} \\end{bmatrix} \\\\\n                 &= \\begin{bmatrix}\n          \\cos\\theta & \\sin\\theta \\\\\n          -\\sin\\theta & \\cos\\theta\n        \\end{bmatrix}\n        \\begin{bmatrix}\n          x \\\\ y\n         \\end{bmatrix} - \\begin{bmatrix}\n            \\cos\\theta & \\sin\\theta \\\\\n            -\\sin\\theta & \\cos\\theta\n          \\end{bmatrix}\\begin{bmatrix}\n            c_{x} \\\\ c_{y}\n          \\end{bmatrix} + \\begin{bmatrix}\n            c_{x} \\\\ c_{y}\n          \\end{bmatrix} \\\\\n          &= \\begin{bmatrix} \\cos\\theta & \\sin\\theta \\\\ -\\sin\\theta & \\cos\\theta \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n          - \\begin{bmatrix} c_{x}\\cos\\theta + c_{y}\\sin\\theta \\\\ -c_{x}\\sin\\theta + c_{y}\\cos\\theta \\end{bmatrix} +\n           \\begin{bmatrix} c_{x} \\\\ c_{y} \\end{bmatrix} \\\\\n          &= \\begin{bmatrix} \\cos\\theta & \\sin\\theta \\\\ -\\sin\\theta & \\cos\\theta \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\end{bmatrix}\n          + \\begin{bmatrix} c_{x}(1 - \\cos\\theta) - c_{y}\\sin\\theta \\\\ c_{y}(1 - \\cos\\theta) + c_{x}\\sin\\theta \\end{bmatrix}\n\\end{split}\n\\end{equation*}\n\n\\section{List of Implemented Protocol}\n\\begin{itemize}\n  \\item Population Protocol\n        \\begin{itemize}\n          \\item Dancing Protocol\n          \\item Sum modulo 4\n        \\end{itemize}\n  \\item Network Constructor\n        \\begin{itemize}\n          \\item Cycle Cover\n          \\item Global Star\n          \\item Simple Global Line (5 states)\n        \\end{itemize}\n  \\item Terminating Grid Network Constructor\n        \\begin{itemize}\n          \\item Square Grid Network\n        \\end{itemize}\n\\end{itemize}\n\\section{Open source libraries used in the simulator}\nCredits to:\n\\begin{itemize}\n  \\item Koma, A scientific computing library, under Apache 2.0, http://koma.kyonifer.com/\n  \\item TornadoFX, JavaFX Framework for Kotlin, under Apache 2.0, https://github.com/edvin/tornadofx\n  \\item GraphStream, A Dynamic Graph Library, under LGPLv3, http://graphstream-project.org/\n  \\item JUnit, A Unit test framework, under Eclipse Public License 1.0, https://junit.org/junit4/\n\\end{itemize}\nAdditionally, credit to NETCS, A Java implementation for non-grid dynamic network, under 3-Clause BSD, https://github.com/amaxilat/netcs,\nthis is not used in the simulator but give an some inspiration to author of the simulator.\n", "meta": {"hexsha": "cbd753443c7feb8f010118212c17bb2efb823021", "size": 4433, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "context/appendix.tex", "max_stars_repo_name": "billweasley/Bsc-dissertation", "max_stars_repo_head_hexsha": "c34f1489441298ef91e08f431b32884ae548edfe", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-10-25T02:56:50.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-25T02:56:50.000Z", "max_issues_repo_path": "context/appendix.tex", "max_issues_repo_name": "billweasley/Bsc-thesis", "max_issues_repo_head_hexsha": "c34f1489441298ef91e08f431b32884ae548edfe", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "context/appendix.tex", "max_forks_repo_name": "billweasley/Bsc-thesis", "max_forks_repo_head_hexsha": "c34f1489441298ef91e08f431b32884ae548edfe", "max_forks_repo_licenses": ["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.0388349515, "max_line_length": 248, "alphanum_fraction": 0.5862846831, "num_tokens": 1553, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392817460332, "lm_q2_score": 0.8615382147637196, "lm_q1q2_score": 0.7616336245764783}}
{"text": "% -*- root: Main.tex -*-\n\\section{Essentials}\n\\subsection*{Matrix/Vector}\n\\begin{compactdesc}\n\t\\item $A\\cdot B = C \\Leftrightarrow c_{ik}=\\sum_{j=1}^{m} a_{ij} \\cdot b_{jk}, c=\\sum_{i} a_i b_i^\\top$\n\t\\item $A^\\top\\cdot B = C \\Leftrightarrow c_{ik}=a_i^\\top \\cdot b_k$\n\t\\item $z=Ax\\Leftrightarrow z_i=\\sum_k a_{ik} x_k$\n\t\\item $z^\\top = y^\\top A \\Leftrightarrow z_i = \\sum_k a_{ki} y_k$\n\t\\item $A\\cdot B=(A B^{(1)}\\hspace{1pt} AB^{(2)}\\hspace{1pt} \\dots)=(A^{[1]}B\\hspace{3pt}A^{[2]}B\\hspace{3pt}\\dots)^\\top$\n\t\\item $\\mathbf{Ker}(A)=\\{x|Ax=0\\}$, $\\mathbf{Im}(A)=\\{y|\\exists x.Ax=y\\}$\n\t\\item $\\mathbf{Rank}(A) := dim(\\mathbf{Im}(A))$\n\t\\item $\\mathbf{Rank}(A\\cdot B) \\leq min(\\mathbf{Rank}(A), \\mathbf{Rank}(B))$\n\t\\item $dim(A)=\\mathbf{Rank}(A) + dim(\\mathbf{Ker}(A))$\n\t\\item[Tr:] $\\mathbf{Tr}(A) := \\sum_i a_{ii}$, $\\mathbf{Tr}(rA+sB)=r\\mathbf{Tr}(A)+s\\mathbf{Tr}(B)$, $\\mathbf{Tr}(ABC)=\\mathbf{Tr}(CAB)=\\mathbf{Tr}(BCA)$\n\t\\item[Vec(A):] Column by col. forming a new vector\n\t\\item[det(A)=0:] $\\exists$ linear dependent cols/rows\n\t\\item[det(A)!=0:] $A$ regular, $Ax=b$ has 1 sol., $\\exists A^{-1}$, $im(A)=\\mathbb{M}^n, ker(A)=0$, 0 is not EW of $A$\n\t\\item[Orthogonal:] cols. orthonormal, $\\mathbf{A}^{-1} = \\mathbf{A}^\\top$, $\\mathbf{A} \\mathbf{A}^\\top = \\mathbf{A}^\\top \\mathbf{A} = \\mathbf{I}$, $\\operatorname{det}(\\mathbf{A}) \\in \\{+1, -1\\}$, $\\operatorname{det}(\\mathbf{A}^\\top \\mathbf{A}) = 1$, $(t\\cdot A)^{-1}=1/t\\cdot A^{-1}$, $A, B: orth \\implies A\\cdot B: orth$, Preserves norm ($||Ax||=x$), inner prod., dist., angle, EWs are on unit circle, EVs are unitary\n\t\\item[Positive semi-definite:] $\\forall x, x^\\top A x \\geq 0$, $Tr(A)\\geq 0$, $A^{-1}$ psd., $\\exists B . A=BB^\\top$ with $\\mathbf{Rank}(A)=\\mathbf{Rank}(B)$, $x^\\top A x = 0 \\Rightarrow A x = 0$ $X\\in \\mathbb{R}^{n,r}, n\\leq r, rank(X)=n \\Rightarrow XX^\\top$ psd.\n\t\\item[Idempot.:] $A^2 = A$, $I-A$ idp. and $A(I-A)=0$, $rank(A)=tr(A)$, $CD$ idp. $\\Rightarrow$ $CD=DC$, $f(sI+tA)=(I-A)f(s)+A f(s+t)$\n\t\\item[Pseudo-Inverse:] $A\\cdot A^+\\cdot A = A$\n\t\\item[Inner Product:] $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\mathbf{x}^\\top \\mathbf{y} = \\sum_{i=1}^{N} \\mathbf{x}_i \\mathbf{y}_i$.\n\t\\begin{inparaitem}\n\t\t\\item $\\langle \\mathbf{x} \\pm \\mathbf{y}, \\mathbf{x} \\pm \\mathbf{y} \\rangle = \\langle \\mathbf{x}, \\mathbf{x} \\rangle \\pm 2 \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{y}, \\mathbf{y} \\rangle$\n\t\t\\item $\\langle \\mathbf{x}, \\mathbf{y} + \\mathbf{z} \\rangle = \\langle \\mathbf{x}, \\mathbf{y} \\rangle + \\langle \\mathbf{x}, \\mathbf{z} \\rangle$\n\t\t\\item $\\langle \\mathbf{x} + \\mathbf{y}, \\mathbf{z} \\rangle = \\langle \\mathbf{x}, \\mathbf{z} \\rangle + \\langle \\mathbf{y}, \\mathbf{z} \\rangle$\n\t\t\\item $\\langle \\mathbf{x}, \\mathbf{y} \\rangle = \\|\\mathbf{x}\\|_2 \\cdot \\|\\mathbf{y}\\|_2 \\cdot \\cos(\\theta)$\n\t\t\\item If $\\mathbf{y}$ is a unit vector then $\\langle \\mathbf{x}, \\mathbf{y} \\rangle$ projects $\\mathbf{x}$ onto $\\mathbf{y}$\n\t\\end{inparaitem}\n\t\\item[Outer Product:] $\\mathbf{u} \\mathbf{v}^\\top$, $(\\mathbf{u} \\mathbf{v}^\\top)_{i, j} = \\mathbf{u}_i \\mathbf{v}_j$\n\t\\item[Transp. + Inv.:] $(\\mathbf{A}^\\top)^{-1} = (\\mathbf{A}^{-1})^\\top$\n\t\\item[Orth. proj.:] $P_y(x)=y y^\\top x / ||y||^2_2 = <x,y>y$\n\t\\item[Proj. to orth. compl.:] $v-<u,v>u$\n\t\\item[Householder-Refl.:] $H_u=I-2uu^\\top$ sym.+orth.\n\t\\item[Jacobian:] $D f(x)=(\\frac{\\partial f_i(x)}{\\partial x_j})_{i=1..m, j=1..n} \\in \\mathbb{R}^{m\\cdot n}$\n\\end{compactdesc}\n\n\\subsection*{Norms}\n$\\|\\mathbf{x}\\|_0 = |\\{i | x_i \\neq 0\\}|$ \\qquad $\\|\\mathbf{x}\\|_2 = \\sqrt{\\sum_{i=1}^{N} \\mathbf{x}_i^2} = \\sqrt{\\langle \\mathbf{x}, \\mathbf{x} \\rangle}$\\\\\n$\\|\\mathbf{x}\\|_p = \\left( \\sum_{i=1}^{N} |x_i|^p \\right)^{\\frac{1}{p}}$\\\\\n$\\|\\mathbf{M}\\|_F =\\allowbreak \\sqrt{\\sum_{i=1}^{m} \\sum_{j=1}^{n}\\mathbf{m}_{i,j}^2} =\\allowbreak \\sqrt{\\sum_{i=1}^{\\min\\{m, n\\}} \\sigma_i^2} = \\sqrt{trace(A^\\top A)}$\\\\\n$\\|\\mathbf{M}\\|_1 = \\sum_{i,j} | m_{i,j}|$ \\qquad $\\|\\mathbf{M}\\|_2 = \\sigma_{\\text{max}}(\\mathbf{M})$\\\\\n$\\|\\mathbf{M}\\|_p = \\max_{\\mathbf{v} \\neq 0} \\frac{\\|\\mathbf{M}\\mathbf{v}\\|_p}{\\|\\mathbf{v}\\|_p}$ \\qquad $\\|\\mathbf{M}\\|_\\star = \\sum_{i=1}^{\\min(m, n)} \\sigma_i$ \\qquad $\\|\\mathbf{M}\\|_G = \\sqrt{\\sum_{i,j} \\mathbf{g}_{ij} \\mathbf{m}_{ij}^2}$\n\n\\subsection*{Sums}\n$\\sum_{n=a}^b f(n) = \\sum_{n=0}^b f(n) - \\sum_{n=0}^{n-1} f(n)$\\\\\n$\\sum_{n=s}^{t} f(n)=\\sum_{n=s+p}^{t+p}f(n-p)$\\\\\n$\\sum_{n\\in B} f(n) = \\sum_{m\\in A} f(\\sigma (m))$ for $\\sigma : A\\rightarrow B$ bij.\\\\\n$\\sum_{k\\leq j \\leq i \\leq n}a_{ij} = \\sum_{i=k}^n \\sum_{j=k}^i a_{ij} = \\sum_{j=0}^{n-k}\\sum_{i=k}^{n-j} a_{i+j, i}$\\\\\n$\\sum_{i=s}^m \\sum_{j=t}^n a_i c_j = (\\sum_{i=s}^m a_i)(\\sum_{j=t}^n c_j)$\\\\\n$\\sum_{i=1}^n i = n(n+1)/2$ \\qquad $\\sum_{i=1}^n 2i-1 = n^2$\\\\\n$\\sum_{i=0}^n log(i) = log(n!)$\\qquad $\\sum_{i=0}^{n-1} a^i=\\frac{1-a^n}{1-a}$\n\n\\subsection*{Derivatives}\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{x}) = \\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{b}) = \\mathbf{b}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(f(\\mathbf{x})^\\top\\cdot g(\\mathbf{x})) = f(\\mathbf{x})^\\top \\frac{\\partial g(\\mathbf{x})}{\\partial \\mathbf{x}} + g(\\mathbf{x})^\\top \\frac{\\partial f(\\mathbf{x})}{\\partial \\mathbf{x}}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{x}^\\top \\mathbf{A}\\mathbf{x}) = (\\mathbf{A}^\\top + \\mathbf{A})\\mathbf{x}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\mathbf{b}^\\top \\mathbf{A}\\mathbf{x}) = \\mathbf{A}^\\top \\mathbf{b}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X} \\mathbf{b}) = \\mathbf{c}\\mathbf{b}^\\top$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\mathbf{c}^\\top \\mathbf{X}^\\top \\mathbf{b}) = \\mathbf{b}\\mathbf{c}^\\top$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\| \\mathbf{x}-\\mathbf{b} \\|_2) = \\frac{\\mathbf{x}-\\mathbf{b}}{\\|\\mathbf{x}-\\mathbf{b}\\|_2}$ \\quad\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\|\\mathbf{x}\\|^2_2) = \\frac{\\partial}{\\partial \\mathbf{x}} (\\mathbf{x}^\\top \\mathbf{x}) = 2\\mathbf{x}$\\\\\n$\\frac{\\partial}{\\partial \\mathbf{X}}(\\|\\mathbf{X}\\|_F^2) = 2\\mathbf{X}$\\quad\n$\\frac{\\partial}{\\partial \\mathbf{X}} \\mathbf{Tr}(\\mathbf{X})=\\mathbf{I}$ \\\\\n$\\frac{\\partial}{\\partial \\mathbf{x}}(\\|\\mathbf{Ax - b}\\|_2^2) = \\mathbf{2(A^\\top Ax-A^\\top b)}$\n\n\\subsection*{Eigenvalue / -vectors}\nEigenvalue Problem: $\\mathbf{Ax} = \\lambda \\mathbf{x}$\\\\\n1. solve $\\operatorname{det}(\\mathbf{A} - \\lambda \\mathbf{I}) \\overset{!}{=} 0$ resulting in $diag(\\lambda_i)$\\\\\n2. $\\forall \\lambda_i$:\nsolve $(\\mathbf{A} - \\lambda_i \\mathbf{I}) \\mathbf{x}_i = \\mathbf{0}$, for $\\mathbf{x}_i$.\n\n\\subsection*{Eigendecomposition}\n$\\mathbf{A} \\in \\mathbb{R}^{N \\times N}$ then $\\mathbf{A} = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q}^{-1}$ with $\\mathbf{Q} \\in \\mathbb{R}^{N \\times N}$.\\\\\nif fullrank: $\\mathbf{A}^{-1} = \\mathbf{Q} \\boldsymbol{\\Lambda}^{-1} \\mathbf{Q}^{-1}$ and $(\\boldsymbol{\\Lambda}^{-1})_{i,i} = \\frac{1}{\\lambda_i}$.\\\\\nif $\\mathbf{A}$ symmetric: $A = \\mathbf{Q} \\boldsymbol{\\Lambda} \\mathbf{Q^\\top}$ ($\\mathbf{Q}$ orthogonal).\n\n\\subsection*{Probability / Statistics}\n\\begin{inparaitem}\n\t\\item $P(x) := Pr[X = x] := \\sum_{y \\in Y} P(x, y)$\n\t\\item $P(x|y) := Pr[X = x | Y = y] := \\frac{P(x,y)}{P(y)},\\quad \\text{if } P(y) > 0$\n\t\\item $\\forall y \\in Y: \\sum_{x \\in X} P(x|y) = 1$ (for any fixed $y$)\n\t\\item Bayes: $P(x|y) = \\frac{P(y|x)P(x)}{P(y)}$\n\t\\item ($x_i$ partition) $\\Rightarrow P(y) = \\sum_{i=1}^n P(y|x_i)\\cdot P(x_i)$\n\t\\item $P(x|y) = P(x) \\Leftrightarrow P(y|x) = P(y)$ (iff $X$, $Y$ ind.)\n\t\\item $P(x_1, \\ldots, x_n) = \\prod_{i=1}^n P(x_i)$ (iff IID)\n\t\\item $P(x \\cup y)=P(x)+P(y)-P(x,y)$ (mut. excl: rm last term)\n\t\\item $P(x)=\\sum_i P(x,y_i)$\n\\end{inparaitem}", "meta": {"hexsha": "101da1f1f2fb43825e81e747fdbba466b8e2bbc0", "size": 7630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Essentials.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": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Essentials.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": "Essentials.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": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 84.7777777778, "max_line_length": 419, "alphanum_fraction": 0.5817824377, "num_tokens": 3501, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392756357327, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.761633616169353}}
{"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\nProve that the language $\\{ a^n b^{n^2} \\}$ is not context-free.\n\n\\subsection*{Solution}\n\nQuestion is solved by proof of contradiction, taking advantage of \\textit{The Pumping Lemma}.\nAssume $L$ is a context-free language.\nBased on the Pumping Lemma, there exists a number $n_G \\in \\mathbb{N}$ such that if $w \\in L(G)$ and $|w| \\geq n_G$, then we can write $w = xyzut$ such that $|y| \\geq 1$ or $|u| \\geq 1$, $|yzu| \\leq n_G$ and $xy^nzu^nt \\in L(G)$ for all $n \\in \\mathbb{N}$.\nLet $w = a^nb^{n^2}$.\nLet also $n_a$ and $n_b$ be defined as number of $a$s and $b$s in $w$ respectively, causing $n_b(w)$ = $n_a^2(w)$.\nWe show that no matter how we define $y$ and $u$, we break the shape of the language and therefore $L$ cannot be context-free.\n\n\\begin{enumerate}\n\n\t\\item\n\tIt is clear $y$ cannot contain both $a$s and $b$s simultaneously, for by pumping $y$, $a$s appear in the middle of $b$s and $w$ would no longer be in $L$.\n\n\t\\item\n\tIf $y$ contains only $b$s, it is inevitable that $u$ would contain only $b$s.\n\tIn consequence, by pumping $y$ and $u$, $n_a$ increases while $n_b$ stays unchanged.\n\tTherefore, $n_a^2 \\ge n_b$ thus shape of the language would break.\n\tSimilarly, it can be shown that $y$ and $u$ cannot both contain only $a$s.\n\n\t\\item\n\tIf $y$ contains only $a$s and $u$ contains only $bs$, let $n_a(y) = s$ and $n_b(u) = s^\\prime$.\n\tBy pumping $y$ and $u$ to $y^j$ and $u^j$, it is possible that $(s^\\prime j)^2 = (sj)$ by choosing proper $y$ and $u$.\n\tYet, by re-pumping $y$ and $u$ once more to $y^{j+1}$ and $u^{j+1}$, $(s^\\prime(j+1))^2 \\neq (s(j+1))$ and this would break the form of the language.\n\n\\end{enumerate}\n\nTherefore, assuming $L$ is context-free is shown to lead to contradicting the pumping lemma.\nHence, the assumption is invalid and $L$ cannot be context-free.\n", "meta": {"hexsha": "2fec8791e9230fea7ea04c24b8f1cc8e57518293", "size": 2178, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/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-cs622-2015f/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-cs622-2015f/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": 53.1219512195, "max_line_length": 256, "alphanum_fraction": 0.6377410468, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615381952105441, "lm_q2_score": 0.8840392725805823, "lm_q1q2_score": 0.7616335993943172}}
{"text": "\\documentclass{article}\n\\usepackage{color}\n\\usepackage{bigints}\n\\usepackage{amssymb}\n\\usepackage[italicdiff]{physics}\n\\color{white}\n\\definecolor{Blue}{RGB}{0,33,72}\n\\begin{document}\n\\pagecolor{Blue}\n\\title{Solution to Integral Fun\\textsc{\\char13}s Problem}\n\\author{Jose Bedoya}\n\\maketitle\n\\section{Question}\n{\\LARGE\n$$I(\\alpha,n)=\\bigintss_{0}^{\\infty} \\frac{\\cos \\alpha t}{t^n}\\,dt$$\nwith $\\mid n \\mid<1$\n}\n\\section{Solution}\n{\\Large\nKnowing,\n$$\\bigintsss_{0}^{\\infty}f(t)g(t)\\,dt=\\bigintsss_{0}^{\\infty}\\mathcal{L}\\{f(t)\\}(s)\\mathcal{L}^{-1}\\{g(t)\\}(s)\\,ds$$\n\n\\vspace{5mm}\nAnd by choosing\n$$f(t)=\\cos(\\alpha t)$$\n$$g(t)=\\frac{1}{t^n}$$\nwe have\n$$\\mathcal{L}\\{f(t)\\}(s)=\\frac{s}{s^2+\\alpha^2}$$\n$$\\mathcal{L}^{-1}\\{g(t)\\}(s)=\\frac{s^{n-1}}{\\Gamma(n)}$$\n\\newpage\nSubstituting on our integral\n$$I(\\alpha,n)=\\frac{1}{\\Gamma(n)}\\bigintsss_{0}^{\\infty}\\frac{s^n}{s^2+\\alpha^2}\\,ds$$\n\n\\vspace{3mm}\nLet $s=\\alpha\\tan(\\theta)$\n$$I(\\alpha,n)=\\frac{\\alpha^{n-1}}{\\Gamma(n)}\\bigintsss_{0}^{\\frac{\\pi}{2}}\\tan^n(\\theta)\\,d\\theta$$\n$$=\\frac{\\alpha^{n-1}}{\\Gamma(n)}\\bigintsss_{0}^{\\frac{\\pi}{2}}\\sin^n(\\theta)\\cos^{-n}(\\theta)\\,d\\theta$$\n\n\\vspace{5mm}\nRecall the definition of the Beta Function\n$$B(x,y)=2\\bigintsss_{0}^{\\frac{\\pi}{2}}\\sin^{2x-1}(\\theta)\\cos^{2y-1}(\\theta)\\,d\\theta$$\n$$=\\frac{\\Gamma(x)\\Gamma(y)}{\\Gamma(x+y)}$$\nwhere $\\Gamma(n)=(n-1)$!.\n\n\\vspace{5mm}\nNotice, in our integral:\n$$x=\\frac{n+1}{2}$$\n$$y=\\frac{1-n}{2}$$\n\n\\vspace{3mm}\nTherefore,\n$$I(\\alpha,n)=\\frac{\\alpha^{n-1}}{2\\Gamma(n)}\\Gamma\\left(\\frac{n+1}{2}\\right)\\Gamma\\left(\\frac{1-n}{2}\\right)$$\n\n\\vspace{3mm}\nHere we can simplify the expression using the reflection property of the Gamma Function\n$$\\Gamma(z)\\Gamma(1-z)=\\frac{\\pi}{\\sin(\\pi z)}$$\nfor $z$ not integer.\n\n\\vspace{3mm}\nIf we let $z=\\frac{n+1}{2}$\n$$\\Gamma\\left(\\frac{n+1}{2}\\right)\\Gamma\\left(\\frac{1-n}{2}\\right)=\\frac{\\pi}{\\sin\\left(\\frac{\\pi(n+1)}{2}\\right)}$$\n$$=\\pi\\sec\\left(\\frac{\\pi n}{2}\\right)$$\n\n\\vspace{2mm}\nwe get\n}\n{\\LARGE\n$$I(\\alpha,n)=\\frac{\\pi}{2}\\frac{\\alpha^{n-1}}{\\Gamma(n)}\\sec\\left(\\frac{\\pi n}{2}\\right)$$\n}\n\\end{document}", "meta": {"hexsha": "d5c42723f237987a944c374910bb52d3181f9d66", "size": 2070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/Jose Bedoya's questions/Integral with Beta Function (1).tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/Jose Bedoya's questions/Integral with Beta Function (1).tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/Jose Bedoya's questions/Integral with Beta Function (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": 29.5714285714, "max_line_length": 116, "alphanum_fraction": 0.6212560386, "num_tokens": 863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037302939516, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7615968586096233}}
{"text": "\\chapter{Basic Classification Models}\n\\newpage\n\n\n\\section{k Nearest Neighbours}\n    kNN is a classical non-parametrized lazy-learning algorithm.\n\n    \\subsection{Distance}\n        A distance function $d(x,y)$ is a function that satisfies\n        \\begin{itemize}\n            \\item Positive Definite. $d(x,y)>0$ and $d(x,y)=0$ iff $x=y$.\n            \\item Symmetric.\n            \\item Triangle Inequality. $d(x,y) \\le d(x,z) + d(z,y)$.\n        \\end{itemize}\n        Common distance functions include\n        \\begin{itemize}\n            \\item $l_2$ distance (Euclidean). $\\|x-y\\|_2 = \\sqrt{\\sum(x_i - y_i)^2}$.\n            \\item $l_1$ distance (Manhattan). $\\|x-y\\|_2 = \\sum |x_i-y_i|$.\n            \\item $l_{\\infty}$ distance. $\\|x-y\\|_{\\infty} = \\max\\{|x_i-y_i|\\}$.\n        \\end{itemize}\n\n    \\subsection{A general form of Euclidean Distance}\n        Let $P$ be a projection matrix, we can generalize $l_2$ distance by\n        \\[\\|Px-Py\\|_2^2 = (P(x-y))^T(P(x-y)) = (x-y)^TP^TP(x-y)\\]\n        \\[\\Rightarrow Dist(x,y) = (x-y)^TA(x-y)\\]\n        \\begin{remark}\n            Actually $A$ can be learned.\n        \\end{remark}\n\n    \\subsection{kNN Algorithm}\n        Given a dataset $\\mathcal{D}$ and an input $x$, the kNN algorithm\n        \\begin{enumerate}\n            \\item Computes the distance between $x$ and each $y$ in $\\mathcal{D}$.\n            \\item Finds the nearest $k$ neighbours of $x$ in $\\mathcal{D}$.\n            \\item Determines the class of $x$ by the label of neighbours.\n        \\end{enumerate}\n\n    \\subsection{Choosing k}\n        \\begin{itemize}\n            \\item For a binary classification task, $k$ should be an odd number.\n            \\item $k$ should not be too large or too small.\n            \\item Parameter tuning techniques can be used to choose a proper $k$.\n        \\end{itemize}\n\n    \\subsection{More on kNN}\n        \\paragraph{Complexity.}\n        kNN requires\n        \\begin{itemize}\n            \\item An $O(n)$ time to calculate distances.\n            \\item An $O(n\\log n)$ time to sort and find nearest neighbours.\n        \\end{itemize}\n        \\paragraph{Can it be faster?}\n        Yes if we use parallelism.\n\n\n\\section{Naive Bayes Classifer}\n\n    \\subsection{Posterior, Prior, Likelihood and Evidence}\n        Recall Bayes' Rule\n        \\[ p(w_j|x) = \\frac{p(x|w_j) \\cdot p(w_j)}{p(x)} \\]\n        \\begin{itemize}\n            \\item $p(w_j|x)$ is called the \\textbf{posterior}.\n            \\item $p(w_j)$ is called the \\textbf{prior}.\n            \\item $p(x|w_j)$ is called the \\textbf{likelihood}.\n            \\item $p(x)$ is called the \\textbf{evidence}.\n        \\end{itemize}\n        \\[ Posterior = (Likelihood \\cdot Prior) / Evidence \\]\n        Optimizing w.r.t. $w$ is independent of $p(x)$,\n        \\[ Posterior \\sim (Likelihood \\cdot Prior) \\]\n\n    \\subsection{Bayesian Decision Theory}\n        Suppose there are $N$ classes $c_1,c_2,\\dots,c_N$. Let $\\lambda_{ij}$ be the cost of (mistankenly) classifying a sample in $c_i$ into $c_j$.\n        \\begin{remark}\n            In a more general sense, $c_1, c_2, \\dots, c_N$ is more than just a set of classes. It can be seen as a set of ``actions''.\n        \\end{remark}\n\n        \\begin{definition}[Conditional Risk]\n            The \\textbf{expected loss}, or the \\textbf{conditional risk} is defined as\n            \\[ R(c_i|x) = \\sum_{j=1}^N \\lambda_{ij}p(c_j|x) \\]\n        \\end{definition}\n        Our goal is to find a minimizer $h(x)$ of the general conditional risk $R(h) = \\mathbb{E}[R(h(x)|x)]$.\n\n        For each $x$, if $h(x)$ minimizes $R(h(x)|x)$, then obviously $h(x)$ also minimizes $R(h)$. The minimizing $h^*(x)$ is called the \\textbf{Bayes optimal classifier}, and $R(h^*)$ is called the \\textbf{Bayes risk}.\n\n        If\n        \\[\n        \\lambda_{ij} = \n        \\begin{cases}\n            0 \\quad & i = j\\\\\n            1 \\quad & otherwise\n        \\end{cases}    \n        \\]\n        Then\n        \\[ R(c|x) = 1 - p(c|x) \\]\n        minimizing this risk is equivalent to maximizing $p(c|x)$ and\n        \\[ h^*(x) = \\arg \\max_{c_i} p(c_i|x) = \\arg \\max_{c_i} \\frac{p(x|c_i)p(c_i)}{p(x)} = \\arg\\max_{c_i} p(x|c_i)p(c_i)\\]\n        So we choose the $x$ that \\emph{maximizes posterior}.\n\n        \\begin{remark}\n            A \\textbf{discriminative model} directly models likelihood $p(c|x)$, while a \\textbf{generative model} models joint distribution $p(x,c)$ by modeling $p(c) \\cdot p(x|c)$.\n        \\end{remark}\n\n        \\subsubsection{Example.}\n        For a binary classification (decision-making), if\n        \\[ R(c_1|x) < R(c_2|x) \\]\n        then we take $c_1$.\n\n        This is equivalent to taking $c_1$ if\n        \\[ (\\lambda_{21}-\\lambda_{11})p(x|c_1)p(c_1) > (\\lambda_{12}-\\lambda_{22})p(x|c_2)p(c_2) \\]\n        or\n        \\[ \\frac{p(x|c_1)}{p(x|c_2)} > \\frac{\\lambda_{12} - \\lambda_{22}}{\\lambda_{21} - \\lambda_{11}} \\cdot \\frac{p(c_2)}{p(c_1)} \\]\n\n        If we further assume that $p(x|C_1)$ and $p(x|c_2)$ have Gaussian distributions with the same variance, then we test whether\n        \\[ \\exp\\left\\{ -\\frac{1}{2}(x-\\mu_1)^2/\\sigma^2 + \\frac{1}{2}(x-\\mu_2)^2/\\sigma^2 \\right\\} \\ge \\lambda \\]\n        where $\\lambda$ is a threshold.\n        Taking logarithm and simplifying\n        \\[ (\\mu_1/\\sigma^2 - \\mu_2/\\sigma^2)x + constant \\ge \\log\\lambda \\]\n        i.e.\n        \\[ ax+b > c \\]\n        or in higher dimensions\n        \\[ w^Tx > b \\]\n        It is a linear classifier.\n\n    \\subsection{Parameter Estimation}\n    \\subsubsection{Maximum Likelihood Estimation}\n    Let $D$ be a dataset with $n$ i.i.d. samples $x_i$, MLE maximizes\n    \\[ p(D|\\theta) = \\prod_{i=1}^n p(x_i|\\theta) \\]\n    to avoid underflow of floating point operations, we take the log likelihood\n    \\[ l(\\theta) = \\log(p(D|\\theta)) = \\sum_{i=1}^n \\log(p(x_i|\\theta)) \\]\n    \n    \\subsubsection{Example of MLE}\n    Consider the multivariate Gaussian distribution with dimension $p$\n    \\[ f(x) = \\frac{1}{(2\\pi)^{p/2}|\\Sigma|^{1/2}}\\cdot \\exp \\left\\{ -\\frac{1}{2}(x-\\mu)^T\\Sigma^{-1}(x-\\mu) \\right\\} \\]\n    The log likelihood is\n    \\[ \\log\\left( p(x_i|\\theta) = -\\frac{1}{2}\\log\\left[(2\\pi)^p|\\Sigma|\\right] - \\frac{1}{2}(x_i - \\mu)^T\\Sigma^{-1}(x_i - \\mu)  \\right) \\]\n    Taking gradient w.r.t. $\\mu$\n    \\[ \\nabla_{\\mu} = \\Sigma^{-1}(x_i-\\mu) \\]\n    And the MLE estimator is\n    \\[ \\hat{\\mu} = \\frac{1}{n}\\sum_{i=1}^n x_i \\]\n    The covariance matrix can be estimated similarly.\n\n    \\subsubsection{Maximum-A-Posterior}\n    Beyond the scope.\n\n    \\subsection{Naive Bayes}\n        \\paragraph{Notations.}\n            \\begin{itemize}\n                \\item $X$: $N \\times d$ training set. \n                \\item $x$: a $d$-dim data sample.\n                \\item $x^{(i)}$: the $i$-th sample in $X$.\n                \\item $y^{(i)}$: the label of $x^{(i)}$.\n                \\item $x_j$: the $j$-th feature in $x$.\n                \\item $c_i$'s: classes.\n            \\end{itemize}\n        The naives Bayes classifier makes the attribute conditinoal independence assumption, aka. the naive Bayes assumption: \\emph{all features of x are independent}.\n        \\[ p(x_1, x_2,\\dots,x_d | y) = \\prod_{i=1}^d p(x_i|y) \\]\n        Then we can compute the optimal classifier by\n        \\[ h_{nb}(x) = \\arg\\max_{c}p(c)\\prod_{j=1}^d p(x_j|c) \\]\n        Therefore a naive Bayes classifier estimates $p(c)$ and $p(x_j|c)$.\n\n        If we assume $p(x^{(i)}|c) \\sim \\mathcal{N}(\\mu_{c,i}, \\sigma^2_{c,i})$, then\n        \\[ p(c) = \\frac{\\sum_{i=1}^N\\mathbb{I}[y^{(i)}=c]}{N} \\]\n        i.e. the frequency of $x$ with label $c$ in $X$.\n        \\[ p(x_j|c) = \\frac{\\sum_{i=1}^N\\mathbb{I}[x^{(i)}_j = 1, y^{(i)}=c]}{\\sum_{i=1}^N\\mathbb{I}[y^{(i)}=c]} \\]\n        i.e. the frequency of those $x$ with feature $x_j$ in all $x$ with label $c$.\n\n    \\subsection{Laplace Smoothing}\n        If an attribute value has never appeared in the training set, the output will either be $0$ or $\\frac{0}{0}$.\n\n        To fix this, we introduce \\textbf{Laplace smoothing}.\n        \\[ p(y=i) = \\frac{\\sum_{j=1}^N\\mathbb{I}[y^{(j)=i}] + 1}{N + k} \\]\n        where $k$ is the number of classes.\n\n\n\\section{Decision Trees and Ensembling}\n    A decision tree is a tree-based classifier. It has a root, several leaf nodes and several internal nodes. Each leaf is a decision and in each internal node we perform a test on one or more attributes of input.\n\n    \\subsection{Entropy and Information Gain}\n    \\begin{definition}[Entropy]\n        Given a dataset $D$ with $k$ classes, suppose the proportion of the $i$-th class in $D$ is $p_i$. The entropy is defined by\n        \\[ H(D) = -\\sum_{i=1}^k p_i \\log_2 p_i \\]\n    \\end{definition}\n    \\begin{remark}\n            The larger $H(D)$ is, the more information $D$ contains.\n    \\end{remark}\n\n    \\begin{definition}[Conditional Entropy]\n        Suppose an attribute $a$ has $V$ possible values. If we split $D$ based on the value of $a$, we will have $V$ branches.\n        \\[ H(Y|X) = \\sum_{v=1}^V \\mathbb{P}[X=x_v]\\sum_{i=1}^k\\mathbb{P}[Y=y_i|X=x_v]\\log_2\\mathbb{P}[Y=y_i|X=x_v] \\]\n        or\n        \\[ H(Y|X) = \\sum_{v=1}^V\\frac{|D_v|}{|D|}H(D_v) \\]\n    \\end{definition}\n    \\begin{remark}\n        Conditional Entropy is a weighted sum.\n    \\end{remark}\n\n    \\begin{definition}[Information Gain]\n        Given a dataset $D$ and an attribute $a$, the information gain of splitting $D$ by $a$ is defined by\n        \\[ IG(D,a) = H(D) - \\sum_{v=1}^V\\frac{|D_v|}{|D|}H(D_v) \\]\n    \\end{definition}\n    \\begin{remark}\n        Larger information gain usually means splitting $D$ by $a$ results in more ``pure'' subsets. So choosing $a_* = \\arg\\max IG(D,a)$ is a common way of choosing attributes when training decision trees.\n    \\end{remark}\n\n    \\begin{definition}[Gain Ratio]\n        The \\textbf{gain ratio} is defined by\n        \\[ GainRatio(D,a) = \\frac{Gain(D,a)}{IV(a)} \\]\n        where $IV(a)$ is the \\textbf{intrinstic value} of attribute $a$,\n        \\[ IV(a) = -\\sum_{v=1}^V \\frac{|D^v|}{|D|}\\log_2\\frac{|D^v|}{|D|} \\]\n    \\end{definition}\n    \\begin{remark}\n        Information gain prefers attributes with more values, and gain ratio is proposed to mitigate the negative effects. Gain ratio is used in the famous C4.5 algorithm.\n\n        However, gain ratio prefers attributes with fewer possible values, and the C4.5 algorithm actually uses a heuristic approach: choose those attributes whose information gains are above the average, and then choose the one with the highest gain ratio.\n    \\end{remark}\n\n    \\subsection{Gini Index}\n        \\begin{definition}[Gini]\n            \\[ Gini(D) = \\sum_{i=1}^{k}\\sum_{i' \\neq i} p_ip_{i'} = 1 - \\sum_{i=1}^k p_i^2 \\]\n        \\end{definition}\n\n        \\begin{definition}[Gini Index]\n            The \\textbf{Gini index} is defined by\n            \\[ GiniIndex(D, a) = \\sum_{v=1}^V\\frac{|D^v|}{|D|}Gini(D) \\]\n        \\end{definition}\n\n    \\subsection{Generating a Decision Tree}\n        A decision tree is generated recursively, and there are three return conditions\n        \\begin{enumerate}\n            \\item All samples in current data set belongs to the same class.\n            \\item No available attributes exist for splitting (the attribute set is empty, or all samples take the same value on all atrributes)\n            \\item No samples exist in current data set.\n        \\end{enumerate}\n\n    \\subsection{Ensemble Learning}\n        Ensemble learning constructs multiple weak individual classifiers and combines their prediction outputs.\n\n        Suppose the final prediction is determined by voting (the output will be $1$ if more than half classifiers output $1$), when there are $T$ base classifiers,\n        \\[ H(x) = \\mathrm{sign}\\left( \\sum_{i=1}^T h_i(x) \\right) \\]\n\n        Suppose the error rates of individual classifiers are independent, by Heoffding Inequality,\n        \\[ P(H(x) \\neq f(x)) = \\sum_{k=0}^{T/2}C_T^k(1-\\epsilon)^k\\epsilon^{T-k} \\le \\exp\\left( -\\frac{1}{2}T(1-2\\epsilon)^2 \\right) \\]\n\n        Therefore as we increase the number of base classifiers, the error rate drops exponentially. However, notice that this conclusion is based on the assumption that all classifiers are independent, which in practice is barely possible.\n\n        \\subsubsection{Bagging}\n        While it is practically difficult to make each individual classifier independent of each other, it is still possbile to maximize their variances.\n        \\begin{enumerate}\n            \\item Construct $T$ datasets, each containing $m$ samples, with bootstrapping.\n            \\item Train $T$ models with the datasets.\n            \\item Ensemble by voting or taking means.\n        \\end{enumerate}\n        \\begin{remark}\n            From the perspective of bias-variance decomposition, bagging reduces the variance term in the error.\n        \\end{remark}\n\n        \\subsubsection{Random Forests}\n        Random forests uses decision trees in bagging. Furthermore, it adds randomness in attribute selection.\n\n        For each node, instead of choosing the best attribute from all attributes, RF first sample a subset of $k$ attributes, and then choose the best attribute from this subset. This further increases the diversity of base classifiers.", "meta": {"hexsha": "6ea7861275119ac482bbd1e01d184f2b6e9f2b58", "size": 13070, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Machine Learning/Classification.tex", "max_stars_repo_name": "YBRua/CourseNotes", "max_stars_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 8, "max_stars_repo_stars_event_min_datetime": "2021-03-20T10:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T08:15:15.000Z", "max_issues_repo_path": "Machine Learning/Classification.tex", "max_issues_repo_name": "YBRua/CourseNotes", "max_issues_repo_head_hexsha": "58a4ccb6b8f8d1de9ec10b627a45442519855dfc", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Machine Learning/Classification.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": 50.2692307692, "max_line_length": 257, "alphanum_fraction": 0.6029839327, "num_tokens": 4003, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8418256432832333, "lm_q1q2_score": 0.7615580164937581}}
{"text": "\\lab{Algorithms}{Eigenvalue Solvers}{Eigenvalue Solvers}\n\\label{Ch:EigSolve}\n\n\\objective{Implement the $QR$ algorithm for finding eigenvalues.}\n\n\\section*{Eigenvalues are hard to find}\n\nFinding the eigenvalues of $n \\times n$ matrix $A$ means solving the following equation, where $x$ is a nonzero vector and $\\lambda$ is a scalar.\n\\begin{align} \n A x                       &=  \\lambda x  \\notag \\\\\nA x - \\lambda x &= 0 \\notag \\\\\n(A - \\lambda I)x  &= 0 \\label{eq:singularity}\n\\end{align}\nSince $x$ is nonzero, \\eqref{eq:singularity} means $A-\\lambda I$ must be singular. Thus $det(A-\\lambda I) = 0$.  This determinant is often notated $det(A-\\lambda I) = p(\\lambda)$ and is called the \\emph{characteristic polynomial} of $A$. The roots of the characteristic polynomial are the eigenvalues of $A$.\n\nIf $A$ is $n \\times n$, the degree of $p(\\lambda) = n$.   Finding the roots is easy for small $n$, but it becomes difficult or impossible as $n$ increases.  Abel's Theorem  outlines the problem.\n\n\\begin{theorem}\n\\label{Theorem:Abel}\n{\\bf Abel's Impossibility Theorem:} There is no general algebraic solution for solving a polynomial equation of degree $n>4$.\n\\end{theorem}\n\nTherefore, there is no method that will exactly find the eigenvalues of an arbitrary matrix. This is a significant result. In practice it means that we often rely on iterative methods, which converge to the eigenvalues. \n\n\\section*{The $QR$ algorithm}\n\nThere are many such iterative methods for finding eigenvalues. We will explore one of the simplest: the $QR$ algorithm. The following recurrence describes the $QR$ Algorithm in its most basic form. \n\n\\begin{equation*}\nA_0 = A, \\quad A_k = Q_k R_k, \\quad A_{k+1} = R_k Q_k\n\\end{equation*}\n\nwhere $Q_k, R_k$ is the $QR$ decomposition of $A_k$. Yes, it's as easy as it looks. All this algorithm does at each step is find the $QR$ decomposition of $A_k$ and multiply $Q_k$ and $R_k$ together again but in the opposite order. How does this simple algorithm find the eigenvalues of $A$? \n\n  \n\n\\begin{comment}\n\\begin{problem}\n\\label{problem:similarity proof}\nProve that $A_{k+1} \\sim A_k$ (where $\\sim$ denotes matrix similarity). Then prove that $A_n \\sim A$ for all $n$.  \n\\end{problem}\n\\end{comment}\n\n$A_{k+1} \\sim A_k$ (where $\\sim$ denotes matrix similarity). Then $A_n \\sim A$ for all $n$. This statement shows that $A_n$ has the same eigenvalues as $A$. Preservation of eigenvalues is the first important feature that makes the algorithm work. The other important feature is that each iteration of the algorithm effectively transfers some of the``mass\" from the lower to the upper triangle. Under very general conditions, $A_n$ will converge to a matrix of the form\n\n\\begin{equation*}\n\\label{eq:Schur form}\nS = \n     \\begin{pmatrix}\n          S_1 &* & \\cdots & * \\\\\n           0     &S_2  &  \\ddots & \\vdots \\\\\n           \\vdots  & \\ddots & \\ddots & *  \\\\\n           0 & \\cdots & 0 & S_m\n    \\end{pmatrix}\n\\end{equation*}\nwhere $S_i$ is either a $1 \\times 1$ or a $2 \\times 2$ matrix. For most matrices $A$, all the $S_i$ will be $1 \\times 1$, so $S$ will be an upper triangular matrix. In this case, $S$ is called the \\emph{Schur form} of $A$. The eigenvalues of $A$ are on the main diagonal of $S$.\n\nThe only case where $S$ is not upper triangular is when $A$ is a real but not symmetric matrix. In this case, though $A$ is real, it may have complex eigenvalues. These eigenvalues occur in complex conjugate pairs. Each of these pairs corresponds to a $2 \\times 2$ block in $S$, where the eigenvalues of the $2 \\times 2$ block are the complex conjugate pair of eigenvalues of $A$. In this case, $S$ is called the \\emph{real Schur form} of $A$.\n\n\\subsection*{Hessenberg preconditioning}\n\nRecall from Lab \\ref{Ch:Householder reflections} that an upper Hessenberg matrix looks like\n\\[\n\\begin{pmatrix}\n*           & * & \\ast & \\cdots   & *\\\\\n*           & * & * & \\cdots   & * \\\\\n0          & * & * &  \\cdots&* \\\\\n\\vdots &  & \\ddots    & \\ddots & \\vdots \\\\\n0 & \\cdots & 0 & * & *\\\\\n\\end{pmatrix} \n\\]\nand that every matrix is similar to an upper Hessenberg matrix. Hessenberg reduction also preserves eigenvalues. It is a good idea to reduce to Hessenberg form before continuing with the $QR$ algorithm. You'll converge to the Schur form faster this way, since Hessenberg matrices are already close to upper triangular.\n\n\\begin{problem}\nCode the $QR$ algorithm. Have your function accept an $n \\times n$ matrix $A$ and a number of iterations, and return all the eigenvalues of $A$. Note that you will need to find the eigenvalues of the $2 \\times 2$ $S_i$ directly, if there are any. Since your own implementations of $QR$ decomposition and Hessenberg reduction may not handle complex matrices, you should use the ones in \\li{scipy.linalg}.\n\\end{problem}\n\n\\begin{comment}\n\n\\begin{problem}\nIf $A$ is normal, its Schur form is diagonal. For normal $A$, have your function additionally output the eigenvector corresponding to each eigenvalue. Hint 1: Test your function on Hermitian and real symmetric matrices; they are both normal. Hint 2: Your work in Problem \\ref{problem:similarity proof} will help. You have already made all the necessary calculations, you just need to store the information correctly.\n\\end{problem}\n\n\\end{comment}\n\n\\begin{problem}\nTest your implementation with random matrices. Try real, complex, symmetric, and Hermitian matrices. Compare your output to the output from the eigenvalue solver. How many iterations are necessary? How large can $A$ be?\n\\end{problem}\n\nThe $QR$ algorithm is not the only iterative method used to find eigenvalues. Arnoldi iteration is similar to the $QR$ algorithm but exploits sparsity. Other methods include the Jacobi method and the Rayleigh quotient method.\n\nIt is important to remember that eigenvalue solvers can be wrong, particularly for matrices that are ill-conditioned. ", "meta": {"hexsha": "6295e8efeb58ed12f62b3bf3bb79af727586111d", "size": 5854, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/EigSolver/Eig_C.tex", "max_stars_repo_name": "abefrandsen/numerical_computing", "max_stars_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Algorithms/EigSolver/Eig_C.tex", "max_issues_repo_name": "abefrandsen/numerical_computing", "max_issues_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Algorithms/EigSolver/Eig_C.tex", "max_forks_repo_name": "abefrandsen/numerical_computing", "max_forks_repo_head_hexsha": "90559f7c4f387885eb44ea7b1fa19bb602f496cb", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.6304347826, "max_line_length": 468, "alphanum_fraction": 0.722412026, "num_tokens": 1607, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127455162773, "lm_q2_score": 0.8918110368115781, "lm_q1q2_score": 0.7615288109254925}}
{"text": "\\chapter{Monte Carlo Estimation}\\label{S:MCEstim}\nVarious problems can be solved by taking advantage of randomness and random number generators.  Such an approach yields a Monte Carlo solution.  %We focus on Monte Carlo integration here.\n\n\\section{Monte Carlo Integral Estimation}\\label{S:BMC}\nSuppose we want to estimate the integral\n\\[\n\\vartheta^* = \\int_{A} h(x) \\, dx \\ , \\text{where, } h(x): \\Rz^k \\to \\Rz, A \\subset \\Rz^k \\ .\n\\]\nIf the integrand function $h$ is simple enough, eg.~polynomial, simple transcendal or trigonometric, then we can evaluate $\\vartheta^*$ {\\bf analytically by hand}.  When this is not the case, then a closed form expression for $\\vartheta^*$ may not exist and we may approximate it by {\\bf numerical quadrature}, eg.~Mid-point rectangles rule ({\\tt QuadMR}), or adaptive Simpson's quadrature rule ({\\tt quad}) or adaptive Lobatto's quadrature rule ({\\tt quadl}).  Numerical quadratures are inefficient in higher dimensions since the number of samples or grid-points grow exponentially with the dimension $k$ of the domain $A$.\n\n{\\bf Basic Monte Carlo (BMC) integral estimation} or {\\bf Basic Monte Carlo integration} is a stochastic method to estimate the integral $\\vartheta^*$ by its point estimate $\\widehat{\\varTheta}_n$ based on $n$ samples drawn at random from the domain $A$.  BMC integration is renowned for its {\\bf simplicity}, {\\bf generality} (class of integrands) and {\\bf scalability} (dimension of the  integration domain).\n\nLet the domain be a $k$-dimensional box or hyper-cuboid $A=([\\underline{a}_1,\\overline{a}_1], [\\underline{a}_2,\\overline{a}_2] , \\ldots, [\\underline{a}_k,\\overline{a}_k] )$.  We can rewrite the integral as:\n\\begin{equation}\\label{E:BMCI}\n\\vartheta^* = \\int_A h(x)\\, dx = \\int_A w(x) f(x)\\, dx \\ ,\n\\end{equation}\nwhere the functions $w(x)$ and $f(x)$ are:\n\\[\nw(x)= h(x) \\prod_{j=1}^k (\\overline{a}_j - \\underline{a}_j) , \\qquad f(x)=\\frac{1}{\\prod_{j=1}^k (\\overline{a}_j - \\underline{a}_j) } \\ .\n\\]\nThe PDF of the RV $X \\sim \\uniform(A) = \\uniform(\\underline{a}_1,\\overline{a}_1) \\times  \\uniform(\\underline{a}_2,\\overline{a}_2) \\times \\cdots \\times  \\uniform(\\underline{a}_k,\\overline{a}_k)$ is $f(x)$ over the box $A$.  Therefore: \n\\[\n\\vartheta^* =  \\int_A w(x) f(x)\\, dx = \\E_f(w(X)) = \\E(w(X)) \\ .\n\\]\nWe subscript the expectation $E$ by $f$ to emphasize the PDF with respect to which we integrate.  Thus, if we generate $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} \\uniform(A)$, then by the WLLN:\n\\[\n\\widehat{\\varTheta}_n := \\frac{1}{n} \\sum_{i=1}^n w(X_i) \\overset{P}{\\longrightarrow} \\E(w(X_1)) = \\vartheta^* \\ .\n\\]\nThe standard error:\n\\[\n\\mathsf{se}_n := \\sqrt{\\V(\\widehat{\\varTheta}_n)} = \\sqrt{\\V(\\frac{1}{n} \\sum_{i=1}^n w(X_i))} = \\sqrt{\\frac{1}{n^2} \\sum_{i=1}^n \\V( w(X_i))} = \\sqrt{\\frac{1}{n^2} n \\V( w(X_1))} = \\frac{1}{\\sqrt{n}} \\sqrt{\\V( w(X_1))} \\ .\n\\]\nWe can get the estimated standard error $\\widehat{\\mathsf{se}}_n$ of the integral estimate $\\widehat{\\varTheta}_n$ from the sample standard deviation $s_n$:\n\\[\n\\widehat{\\mathsf{se}}_n = \\frac{s_n}{\\sqrt{n}}, \\qquad \ns_n^2 = S_n^2((y_1,y_2,\\ldots,y_n)) = \\frac{1}{n-1} \\sum_{i=1}^n \\left( y_i - \\widehat{\\varTheta}_n \\right)^2 \\ , \n\\]\nwhere, $Y_i = w(X_i)$.  A Normal-based $1-\\alpha$ confidence interval (CI) for $\\vartheta^*$ is $\\widehat{\\varTheta}_n \\pm z_{\\alpha/2} \\widehat{\\mathsf{se}}_n$.  Therefore, we can take $n$ as large as we want and thereby shrink the width of the confidence interval as small as we want.  Our recipe for estimating $\\vartheta^*$ is simply summarized in \\hyperref[A:BMCI]{Algorithm \\ref*{A:BMCI}}.  \n\\begin{algorithm}\n\\caption{Basic Monte Carlo Integral Estimation for $\\vartheta^*= \\int_A h(x) dx$\\label{A:BMCI}}\n\\begin{algorithmic}[1]\n\\STATE{\n{\\it input:} \n\\begin{enumerate}\n\\item $n \\gets$ the number of samples.\n\\item $h(x) \\gets$ the integrand function over $\\Rz$\n\\item $[\\underline{a}_j,\\overline{a}_j] \\gets$ lower and upper bounds of integration for each $j=1,2,\\ldots,k$\n\\item capability to draw $nk$ IID samples from $\\uniform(0,1)$ RV\n\\end{enumerate}\n}\n\\STATE{{\\it output:} a point estimate $\\widehat{\\vartheta}_n$ of $\\vartheta^*$ and the estimated standard error $\\widehat{\\mathsf{se}}_n$}\n\\STATE{{\\it initialize:} $y \\gets (0,0,\\ldots,0)$, initialize $y$ as a zero vector of length $n$}\n\\WHILE{$i \\leq n$}\n\\STATE{\n\\begin{enumerate}\n\\item $i \\gets i+1$, \n\\item $x_i = (x_{i,1},x_{i,2},\\ldots,x_{i,k})$, with $x_{i,j} \\gets u_j$, $u_j \\sim \\uniform(\\underline{a}_j,\\overline{a}_j)$, for $j=1,2,\\ldots,k$, \n\\item $y_i \\gets w(x_i)= h(x_i) \\prod_{j=1}^k (\\overline{a}_j-\\underline{a}_j) $\n\\end{enumerate}\n}\n\\ENDWHILE\n\\STATE{{\\it compute:}\n\\begin{enumerate}\n\\item $\\widehat{\\vartheta}_n \\gets \\overline{y}_n$, the sample mean of $y=(y_1,y_2,\\ldots,y_n)$\n\\item $\\widehat{\\mathsf{se}}_n = s_n(y) / \\sqrt{n}$, where $s_n(y)$ is the sample standard deviation of $y$\n\\end{enumerate}\n}\n\\STATE{{\\it return:} $\\widehat{\\vartheta}_n$ and $\\widehat{\\mathsf{se}}_n$}\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{labwork}[1D integral over an interval]\\label{LW:1DintegralOverInterval}\nEstimate $\\vartheta^* := \\int^{0.5}_0x(1-x^2)^{3/2}dx$ using \\hyperref[A:BMCI]{Algorithm \\ref*{A:BMCI}}.  We use IID samples $x_1,x_2,\\ldots,x_n$ from $\\uniform(0,0.5)$ RV to estimate $\\vartheta^*$ as follows:\n\\[\n\\widehat{\\vartheta}_n = \\frac{1}{n} \\sum_{i=1}^n w(x_i) = \\frac{1}{n} \\sum_{i=1}^n h(x_i) (0.5-0), \\quad \\text{where, } h(x_i)= x_i(1-x_i^2)^{3/2} \\enspace .\n\\]\nThe estimation procedure may be implemented as follows:\n\\begin{VrbM}\n>> rand('twister',189783)% initialise the fundamental sampler\n>> N=1000000; % estimate from 1000000 samples\n>> Xs=0.5*rand(1,N); % save 1 million samples from Uniform(0,0.5) in array Xs\n>> Ws=(Xs .* ((1 - (Xs .^ 2)) .^ 1.5)) * 0.5; % h(Xs)* 1/f, f is density of Uniform(0,0.5)\n>> MCEst=mean(Ws(1:N)) % point estimate of the integral\nMCEst =    0.1026\n>> StdErr=std(Ws(1:N))/sqrt(N) % estimated standard error\nStdErr =   5.0026e-05\n>> % approximate 95% confiednce interval of the estimate\n>> [MCEst-2*StdErr MCEst+2*StdErr]\nans =\n    0.1025    0.1027\n\\end{VrbM}\n\nThe estimates and the associated confidence intervals for different sample sizes  are:\n$$\n\\begin{array}{ccc}\n\\hline\nn\t\t&\\widehat{\\vartheta}_n\t\t&\\approx 95\\%\\textrm{~C.I.}\\\\ \\hline\n10^2&\t\t0.1087\t\t\t&\t(0.0985, 0.1189)\\\\\n10^3\t&\t\t0.1055\t\t\t&\t(0.1023, 0.1086)\\\\\n10^4\t&\t\t0.1028\t\t\t&\t(0.1018, 0.1038)\\\\\n10^5\t&\t\t0.1023\t\t\t&\t(0.1020, 0.1027)\\\\\n10^6\t&\t\t0.1026\t\t\t&\t(0.1025, 0.1027)\\\\ \\hline\n\\end{array}\n$$\nThe exact answer is:\n$$\\int^{0.5}_0x(1-x^2)^{3/2}dx=\\left( -\\frac{(1-x^2)^{5/2}}{5} \\right]^{0.5}_0=0.10257.$$\n\\end{labwork}\n\n\\begin{labwork}[2D integral over a rectangle]\\label{LW:2DintegralOverRectangle}\nLet us estimate the area of a circle $C:=\\{(x,y): \\sqrt{x^2+y^2} \\leq 1\\}$ centred at the origin with unit radius using IID uniform samples from a unit square $[-1,1]^2 := [-1,1] \\times [-1,1]$ that contains $C$.  Therefore, the integral of interest:\n$$\n\\vartheta^*:=\\int_{-1}^{1} \\int_{-1}^1 \\BB{1}_C (u_1,u_2) d u_1 d u_2 =\\int_{-1}^{1} \\int_{-1}^1 \\left( 4 \\ \\BB{1}_C (u_1,u_2) \\right) \\frac{1}{4} \\ d u_1 d u_2 \\ ,\n$$ where $ \\frac{1}{4} \\ \\BB{1}_{[-1,1]^2} (u_1,u_2)$ is the joint PDF of $\\uniform([-1,1]^2)$ RV, and the Monte Carlo estimate of $\\vartheta^*$ based on $n$ samples from $\\uniform([-1,1]^2)$ is:\n\\[\n\\widehat{\\vartheta}_n = \\frac{1}{n} \\sum_{i=1}^n 4 \\ \\BB{1}_{C} (u_1,u_2) \n\\]\nWe know that our integral, namely the area of the unit circle, is $\\pi ({\\rm radius})^2=\\pi 1^2=\\pi=3.1416\\ldots$.\n\\begin{VrbM}\n>> rand('twister',188);%Initialise the fundamental sampler\n>> N=10000; % sample size of ten thousand\n>> Ws=zeros(1,N); % initialise a vector of zeros\n>> % produce N pairs of Uniform(0,1) numbers and set to 4 if they fall inside a unit circle\n>> Ws(find( sqrt(sum(rand(2,N) .^ 2)) <= 1.0 ))=4; \n>> MCEst=mean(Ws(1:N)); % MC estimate\n>> StdErr=std(Ws(1:N))/sqrt(N); % estimated standard error\n>> disp([MCEst StdErr MCEst-2*StdErr MCEst+2*StdErr])% display estimate, std error, and approx 95% CI\n    3.1476    0.0164    3.1148    3.1804\n\n>> % with N=10^7 samples we get a better approximation\n>> rand('twister',188); N=10000000; Ws=zeros(1,N); Ws(find( sqrt(sum(rand(2,N) .^ 2)) <= 1.0 ))=4;\n>> MCEst=mean(Ws(1:N)); StdErr=std(Ws(1:N))/sqrt(N);\n>> disp([MCEst StdErr MCEst-2*StdErr MCEst+2*StdErr])\n    3.1420    0.0005    3.1409    3.1430\n>> pi % correct value of pi\nans =    3.1416\n\\end{VrbM}\n\\end{labwork}\n\nWe can also estimate the integral of functions over unbounded domain by first transforming them to one over a bounded domain.\nFor the integral:\n$$\\vartheta^* :=\\int^{\\infty}_0h(x)dx \\ ,$$\nthe substitution $y=1/(x+1)$ will change the interval of integration to a bounded one:\n$$\\vartheta^*=\\int^{\\infty}_0h(x)dx=\\int^0_1 h \\left( \\frac{1}{y}-1 \\right) \\frac{-1}{y^2}dy=\\int^1_0 h \\left( \\frac{1}{y}-1 \\right) \\frac{1}{y^2}dy.$$\nTherefore, with $y_1,\\ldots,y_n \\overset{IID}{\\sim} \\uniform(0,1)$, the integral can be estimated by:\n$$\n\\widehat{\\vartheta}_n=\\frac{1}{n}\\sum^n_{i=1} h \\left(\\frac{1}{y_i}-1\\right) \\frac{1}{y_i^2} \\ .\n$$\nSimilarly, we can estimate the integral:\n$$\n\\vartheta^* := \\int^{\\infty}_{-\\infty}h(x)dx=\\int^{0}_{-\\infty}h(x)dx+\\int^{\\infty}_{0}h(x)dx=\\int^{\\infty}_{0} \\left( h(-x)+h(x) \\right) dx \\ ,\n$$\ncan be estimated by:\n$$\\widehat{\\vartheta}_n=\\frac{1}{n}\\sum^n_{i=1} \\left( h \\left(1-\\frac{1}{y_i} \\right)+h\\left( \\frac{1}{y_i}-1 \\right) \\right) \\frac{1}{y_i^2} \\ .\n$$\n\n\\begin{labwork}[1D Integral with Unbounded Domain]\\label{LW:1DintegralOverUnboundedDomain}\nEstimate $\\vartheta^* = \\int^{\\infty}_{-\\infty}e^{-x^2}dx$ by the Monte Carlo estimate $\\widehat{\\vartheta}_n = \\frac{1}{n}\\sum_{i=1}^n e^{-x_i}, \\ x_i \\overset{IID}{\\sim} \\uniform(0,1)$\n\\Matlab code:\n\\begin{VrbM}\n>> y=rand(1,1000000);\n>> Hy = (exp(- ((1 - (1./y)).^2)) + exp(- (( (1./y) - 1).^2))) ./ (y .* y);\n>> mean(Hy)\nans =    1.7722\n>> disp([mean(Hy)- 1.96*std(Hy)/sqrt(1000000), mean(Hy)+ 1.96*std(Hy)/sqrt(1000000)])\n    1.7694    1.7749\n\\end{VrbM}\nThe Monte Carlo estimates $\\widehat{\\vartheta}_n$ of $\\vartheta^*$ for different sample sizes $n$ are:\n$$\\begin{array}{ccc} \n\\hline\nn\t&\\widehat{\\vartheta}_n\t&\t\\approx~ 95\\% \\textrm{~C.I.}\\\\ \\hline\n\t\t10^2\t\t&  1.7062\t\t\t&(1.4, 2.0)\\\\\n\t\t10^4\t\t&1.7849  \t\t\t&(1.75, 1.81)\\\\\n\t\t10^6\t\t& 1.7717\t\t\t&(1.769, 1.775)\\\\ \\hline\n\\end{array}$$\nThe exact answer is:\n$$\\int^{\\infty}_{-\\infty}e^{-x^2}dx=\\sqrt{\\pi}=1.7725  \\textrm{(  4 decimal places)},$$\nwhich can be obtained by noting that $e^{-x^2}$ is the un-normalised $\\normal(0,0.5^2)$ density.\n\\end{labwork}\n\n\\section{Variance Reduction via Importance Sampling}\\label{S:IS}\n\nConsider the problem of estimating the integral $\\vartheta^* = \\int h(x) f(x) dx$, where $f(x)$ is a PDF.  In basic Monte Carlo method, we can simulate from the RV $X$ with PDF $f$.  However, there are situations where we may not be able to draw samples from $X$.  {\\bf Importance sampling} overcomes this problem by generalising the basic Monte Carlo method.   Suppose $g(x)$ is a PDF from which we can draw samples, then\n\\[\n\\vartheta^* = \\int h(x) f(x) dx = \\int \\frac{h(x) f(x)}{g(x)} g(x) dx = \\E_{g}(Y) \\ ,\n\\]\nwhere, $Y=h(X)f(X)/g(X)$ and the expectation $\\E_g(Y)$ is taken with respect to the PDF $g$.  Therefore, we can simulate $x_1,x_2,\\ldots,x_n \\overset{IID}{\\sim} g$ and estimate $\\vartheta^*$ by:\n\\[\n\\widehat{\\vartheta}_n = \\frac{1}{n} \\sum_{i=1}^n y_i =  \\frac{1}{n} \\sum_{i=1}^n \\frac{h(x_i) f(x_i)}{g(x_i)} \\ .\n\\]\nBy the law of large numbers, $\\widehat{\\varTheta}_n \\overset{P}{\\to} \\vartheta^*$, however $\\widehat{\\varTheta}_n$ may have an infinite standard error if $g(x)$ is chosen poorly.  Since the estimator $\\widehat{\\varTheta}_n$ of $\\vartheta^*$ is the mean of $w(X) = h(X)f(X)/g(X)$ and the second moment of $W(X)$, given by:\n\\[\n\\E_g(w^2(X)) = \\int \\left(w(x)\\right)^2 g(x) dx = \\int \\left( \\frac{h(x) f(x)}{g(x)} \\right)^2 g(x) dx = \\int \\frac{h^2(x) f^2(x)}{g(x)} dx\n\\]\nmay be infinite if $g$ has thinner tails than $f$.  Moreover, $\\E_g(w^2(X))$ may be large if $g(x)$ is small over some set $A$ where $f(x)$ is large, since the ratio $f/g$ over $A$ could become large.  Therefore, we want the {\\bf importance sampling density} $g$ to have thicker tails than $f$ and also be of similar shape to $f$ to minimise the ratio $f/g$.  In fact, the optimal choice of the importance sampling density $g$ is given by the following proposition.\n\n\\begin{prop}[Optimal Importance Sampling Density]\nThe optimal choice for the importance sampling density $g$ that minimises the variance of the importance sampling estimator \n$$\n\\widehat{\\varTheta}_n = \\frac{1}{n} \\sum_{i=1}^n \\frac{h(X_i) f(X_i)}{g(X_i)}, \\quad X_1,X_2,\\ldots,X_n \\overset{IID}{\\sim} g\n$$\nof the integral:\n\\[\n\\vartheta^* = \\int h(x) f(x) dx \\ ,\n\\]\nis \n\\[\ng^*(x) = \\frac{|h(x)| f(x)}{\\int |h(t)| f(t) dt} \\ .\n\\]\n\\begin{proof}\nLet $w(X) := \\frac{f(X)h(X)}{g(X)}$.  The variance of $w(X)$ is:\n\\begin{flalign*}\n\\V_g(w(X)) \n&= \\E_g(w^2(X)) - (\\E_g(w(X)))^2 \\\\\n&= \\int w^2(x) g(x) dx  - \\left( \\int w(x) g(x) dx \\right)^2 \\\\\n&= \\int \\frac{h^2(x) f^2(x)}{g^2(x)} g(x) dx  - \\left( \\int \\frac{h(x)f(x)}{g(x)} g(x) dx \\right)^2 \\\\\n&= \\int \\frac{h^2(x) f^2(x)}{g^2(x)} g(x) dx  - \\left( \\int h(x)f(x) dx \\right)^2 \\\\\n\\end{flalign*} \nNote that $\\left( \\int h(x)f(x) dx \\right)^2$ does not depend on $g$, therefore, minimisation of \n\\[\n\\V_g(\\widehat{\\varTheta}_n) = \\V_g \\left( \\frac{1}{n} \\sum_{i=1}^n \\frac{h(X_i) f(X_i)}{g(X_i)} \\right) = \\V_g \\left( \\sum_{i=1}^n  \\frac{1}{n} w(X_i) \\right) =  n \\frac{1}{n^2} \\V_g(w(X_1)) = \\frac{1}{n} \\V_g(w(X_1))\n\\]\nover all possible densities $g$, is equivalent to minimisation of $\\E_g(w^2(X)) = \\int \\frac{h^2(x) f^2(x)}{g^2(x)} g(x) dx$, where $X \\sim g$.  Due to Jensen's inequality:\n\\begin{flalign*}\n\\E_g(w^2(X)) \n& \\geq \\left( \\E_g(|w(X)|) \\right)^2 \\\\\n& = \\left( \\int \\frac{|h(x) f(x)|}{|g(x)|} g(x) dx \\right)^2\n= \\left( \\int \\frac{|h(x)| f(x)}{g(x)} g(x) dx \\right)^2\n= \\left( \\int |h(x)| f(x) dx \\right)^2\n\\end{flalign*}\nThis establishes a lower bound on $\\E_g(w^2(X))$ and thereby on $\\V_g(\\widehat{\\varTheta}_n)$.  This lower bound is achieved when $g(x)=g^*(x)=\\frac{|h(x)|f(x)}{\\int |h(t)| f(t) dt}$:\n\\begin{flalign*}\n\\E_{g^*}(w^2(X))  \n&= \\int \\frac{h^2(x)f^2(x)}{{g^*}^2(x)} g^*(x) dx \n= \\int \\frac{|h(x)|^2f^2(x)}{\\frac{|h(x)|^2f^2(x)}{\\left(\\int |h(t)| f(t) dt \\right)^2}} \\frac{|h(x)|f(x)}{\\int |h(t)| f(t) dt} dx \\\\\n&= \\int \\left(\\int |h(t)| f(t) dt \\right)^2 \\frac{|h(x)|f(x)}{\\int |h(t)| f(t) dt} dx \n= \\left(\\int |h(t)| f(t) dt \\right) \\int |h(x)|f(x) dx \\\\\n&= \\left( \\int |h(x)| f(x) dx \\right)^2 \n\\end{flalign*}\n\\end{proof}\n\\end{prop} \nThere is no free lunch.  If we can't sample from $f(x)$, then we probably can't sample from the more complicated optimal importance sampling density $g(x)^*=|h(x)|f(x)/\\int |h(t)| f(t) dt$ either.  In practice, we sample from a thick-tailed density $g$ that is as close a possible to $g^*=|h|f$.\n\n\\begin{labwork}[Estimating $\\P(Z>\\pi)$]\\label{LW:GaussianTailProbs}\nCompare the estimates and standard errors of the following estimators of the Gaussian tail probability: \n$$\n\\vartheta^* = \\P(Z>\\pi) = \\int_{-\\infty}^{\\infty} \\BB{1}_{(\\pi,\\infty)}(x) \\phi(x) dx, \\quad \\text{where, $Z \\sim \\normal(0,1)$, $\\phi(x)$ is PDF of $Z$} \\ ,\n$$\nfor different sample sizes $n=\\{10^2,10^4, 10^6\\}$, based on four different importance sampling densities:\n\\begin{enumerate}\n\\item $g^{(1)}=\\phi$, the PDF of $\\normal(0,1)$ (simulate $x_1,x_2,\\ldots,x_n$ from $\\normal(0,1)$ via {\\tt randn(1,n)}), \n\\item $g^{(2)}$, the PDF of $\\normal(\\mu=4.4,\\sigma^2=1)$ (simulate $x_1,x_2,\\ldots,x_n$ from $\\normal(\\mu,\\sigma^2)$ by $x_i \\gets \\mu + \\sigma z_i, z_i \\sim \\normal(0,1)$, i.e.~via {\\tt 4.4 + 1.*randn(1,n);}),\n\\item $g^{(3)} = \\exp(\\pi - x)$, the PDF of a $\\pi$-translated $\\exponential(\\lambda=1)$ RV $X$ with support $[\\pi,\\infty)$ (simulate $x_1,x_2,\\ldots,x_n \\sim X$ by $x_i \\gets \\pi + -\\log(u_i), u_i \\sim \\uniform(0,1)$) and\n\\item $g^{(4)}$, the PDF of $|X|$, where $X \\sim \\normal(\\pi,1)$.\n\\end{enumerate}\n\nThe Monte Carlo estimate based on $g^{(1)}=\\phi \\sim \\normal(0,1)$:\n\\[\n\\widehat{\\vartheta}^{(1)}_n \n= \\frac{1}{n} \\sum_{i=1}^n \\frac{\\BB{1}_{(\\pi,\\infty)}(x_i) \\phi(x_i)}{g^{(1)}(x_i)}\n= \\frac{1}{n} \\sum_{i=1}^n \\BB{1}_{(\\pi,\\infty)}(x_i), \\qquad x_1,\\ldots,x_n \\overset{IID}{\\sim} g^{(1)} = \\phi \\sim \\normal(0,1) \\ .\n\\] \n\nThe Monte Carlo estimate based on $g^{(2)} \\sim \\normal(4.4,1)$:\n\\[\n\\widehat{\\vartheta}^{(1)}_n \n= \\frac{1}{n} \\sum_{i=1}^n \\frac{\\BB{1}_{(\\pi,\\infty)}(x_i) \\phi(x_i)}{g^{(2)}(x_i)}\n= \\frac{1}{n} \\sum_{i=1}^n \\BB{1}_{(\\pi,\\infty)}(x_i)\\frac{\\phi(x_i)}{g^{(2)}(x_i)}, \\qquad x_1,\\ldots,x_n \\overset{IID}{\\sim} g^{(2)} \\sim \\normal(4.4,1) \\ .\n\\] \n\nThe Monte Carlo estimate based on $g^{(3)}$:\n\\[\n\\widehat{\\vartheta}^{(1)}_n \n= \\frac{1}{n} \\sum_{i=1}^n \\frac{\\BB{1}_{(\\pi,\\infty)}(x_i) \\phi(x_i)}{g^{(3)}(x_i)}\n= \\frac{1}{n} \\sum_{i=1}^n \\BB{1}_{(\\pi,\\infty)}(x_i)\\frac{\\phi(x_i)}{g^{(3)}(x_i)}, \\qquad x_1,\\ldots,x_n \\overset{IID}{\\sim} g^{(3)} \\ .\n\\] \n\nThe Monte Carlo estimate based on $g^{(4)}$:\n\\[\n\\widehat{\\vartheta}^{(1)}_n \n= \\frac{1}{n} \\sum_{i=1}^n \\frac{\\BB{1}_{(\\pi,\\infty)}(x_i) \\phi(x_i)}{g^{(4)}(x_i)}\n= \\frac{1}{n} \\sum_{i=1}^n \\BB{1}_{(\\pi,\\infty)}(x_i)\\frac{\\phi(x_i)}{g^{(4)}(x_i)}, \\qquad x_1,\\ldots,x_n \\overset{IID}{\\sim} g^{(4)} \\ .\n\\] \n\n\\end{labwork}\n\n\\section{Sequential Monte Carlo Methods}\n\\work\n\n\\subsection{Sequential Importance Sampling}\n\n\\subsection{Population MCMC}\n\n\\subsection{Genetic Monte Carlo Algorithms}\n\n\\section{Monte Carlo Optimisation}\n\\work\n\n\n", "meta": {"hexsha": "d4039be170b7cf1a214cb24e208febd52e608ff3", "size": 17424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/MonteCarloIntegralEstim.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/MonteCarloIntegralEstim.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/MonteCarloIntegralEstim.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": 58.2742474916, "max_line_length": 624, "alphanum_fraction": 0.6327479339, "num_tokens": 6983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430353105598, "lm_q2_score": 0.9161096158798117, "lm_q1q2_score": 0.7614181268195377}}
{"text": "\\section{Analysis, Geometry and Topology}\r\n\\subsection{Geometry and Topology}\r\n$[{\\vec a}, {\\vec b}, {\\vec c}]= {\\vec a} \\cdot ({\\vec b} \\times {\\vec c})$.\r\nPlane $\\Pi$, perpendicular to unit vector ${\\vec n}$ and containing ${\\vec a}$:\r\n${\\vec x} \\cdot {\\vec n}= {\\vec a} \\cdot {\\vec n} = d$.  Distance from ${\\vec y}$ to $\\Pi$ is\r\n$| d - {\\vec y} \\cdot {\\vec n}|$.  \r\n${\\vec x} \\times {\\vec y}= (x_2 y_3 - y_2 x_3) {\\vec i} +\r\n(x_3 y_1 - y_3 x_1) {\\vec j} + (x_1 y_2 - y_1 x_2) {\\vec k}$.\r\nDenote $[{\\vec a}, {\\vec b}]$ as the line from ${\\vec a}$ to ${\\vec b}$;\r\n$[{\\vec {x_0}}, {\\vec {x_0}} + {\\vec {a}}]= \r\n\\{ {\\vec x}: ({\\vec x} - {\\vec {x_0}}) \\times {\\vec a} = 0 \\}$.  So the line\r\nthat includes ${\\vec {x_0}}$ and ${\\vec {x_1}}$ is\r\n$\\{ {\\vec x}: ({\\vec x} - {\\vec {x_0}}) \\times ( {\\vec {x_1}} - {\\vec {x_0}} ) = 0 \\}$.  \r\nDenote $[{\\vec a}, {\\vec b}, {\\vec c}]$ as the plane containing ${\\vec a}$, ${\\vec b}$ and\r\n${\\vec c}$. ${\\vec a} \\times ({\\vec b} \\times {\\vec c})= \r\n({\\vec a} \\cdot {\\vec c}) {\\vec b} - ({\\vec a} \\cdot {\\vec b}) {\\vec c}$.\r\nLet $\\theta$ be the angle (measured counterclockwise) between $[0,u]$ and\r\n$[0, v]$ then\r\n$\\Delta(u,v)= u_1 v_2 - u_2 v_1= |u| |v| sin( \\theta)$.\r\n$\\Delta(u,v,w)= [u,v,w]=\r\ndet \\left(\r\n\\begin{array}{ccc}\r\nu_1 & u_2 & u_3 \\\\\r\nv_1 & v_2 & v_3 \\\\\r\nw_1 & w_2 & w_3 \\\\\r\n\\end{array}\r\n\\right)$.  Distance between\r\n$ ({\\vec x}- {\\vec {x_0}}) \\times {\\vec a} = 0$ and\r\n$ ({\\vec x}- {\\vec {x_1}}) \\times {\\vec b} = 0$ is\r\n${\\frac {({\\vec {x_0}} - {\\vec {x_1}}) \\cdot ({\\vec a} - {\\vec b})}\r\n{||{\\vec a} \\times {\\vec b}||}}$.  Rotation through $\\theta$:\r\n$x' = x cos( \\theta ) + y sin( \\theta )$, \r\n$y' = y cos( \\theta ) - x sin( \\theta )$.\r\n\\\\\r\n\\\\\r\n{\\bf Moebius Transformations:} \r\n${\\mathbb C}_{\\infty}= {\\mathbb C} \\cup \\{ \\infty \\}$.  ${\\cal M}= \\{\r\n\\tau_{a,b,c,d}(z):\r\n\\tau_{a,b,c,d}(z) = {\\frac {az+b} {cz+d}}\\}$.  If\r\n$\\tau_{a,b,c,d}(z)= \\tau_{\\alpha, \\beta, \\gamma, \\delta}(z)$, $\\exists \\lambda \\in {\\mathbb C}$\r\nsuch that \r\n$\\left(\r\n\\begin{array}{cc}\r\na & b \\\\\r\nc & d \\\\\r\n\\end{array}\r\n\\right) = \\lambda\r\n\\left(\r\n\\begin{array}{cc}\r\n\\alpha & \\beta \\\\\r\n\\gamma & \\delta \\\\\r\n\\end{array}\r\n\\right)$.  If $\\tau \\in {\\cal M}$, $\\tau: {\\mathbb C}_{\\infty} \\rightarrow {\\mathbb C}_{\\infty}$\r\nand $\\tau$ is a product of maps of the following type:\r\n$z \\mapsto a z$, $z \\mapsto z + b$ and $z \\mapsto {\\frac 1 z}$.  \r\nFor all ordered points,\r\n$\\langle z_1, z_2 , z_3 \\rangle, \r\n\\langle w_1, w_2 , w_3 \\rangle$ in \r\n${\\mathbb C}_{\\infty}$, there is a unique $\\tau \\in {\\cal M}$ such that\r\n$\\tau(z_i)= w_i$.\r\nFor ordered points,\r\n$\\langle z_1, z_2 , z_3, z_4 \\rangle, \r\n\\langle w_1, w_2 , w_3, w_4 \\rangle$ in ${\\mathbb C}_{\\infty}$, \r\nthere is a $\\tau \\in {\\cal M}$ such that\r\n$\\tau(z_i)= w_i$ iff the cross-ratio of \r\n$[z_1, z_2,z_3,z_4]$ equals the cross ratio of $[w_1, w_2,w_3,w_4]$. \r\n$\\Phi: GL_2({\\mathbb C}) \\rightarrow {\\cal M}$ is a surjective homomorphism given by\r\n$\\Phi(\r\n\\left(\r\n\\begin{array}{cc}\r\na & b \\\\\r\nc & d \\\\\r\n\\end{array}\r\n\\right) \r\n)= {\\frac {az+b} {cz+d}}$;\r\nthe kernel of the homomorphism is $\\lambda I, \\lambda \\in {\\mathbb C}$.  The\r\nrestriction of $\\Phi$ to $SL_2({\\mathbb C})$ is also a surjection with kernel $\\pm I$.\r\nThe \\emph{modular group} $SL_2$ is the subset of ${\\cal M}$ with $ad-bc=1$ \r\nwith the obvious identification and is generated by \r\n$\\tau \\mapsto \\tau +1, \\tau \\mapsto -{\\frac 1 {\\tau}}$.  Note fundamental region.\r\nSet\r\n$S=\r\n\\left(\r\n\\begin{array}{cc}\r\n0 & -1\\\\\r\n1 & 0\r\n\\end{array}\r\n\\right)\r\n$  and\r\n$T=\r\n\\left(\r\n\\begin{array}{cc}\r\n1 & 1\\\\\r\n0 & 1\r\n\\end{array}\r\n\\right)\r\n$; these correspond to\r\n$S(z)= {\\frac {-1} {z}}$ and $T(z)= z+1$.\r\nDefine \r\n$H= \\{ z: Im(z)>0 \\}$ and\r\n$D= \\{ z:  - {\\frac 1 2} \\leq Re(z) \\leq 0, |z|=1 \\vee\r\n- {\\frac 1 2} \\leq Re(z) < {\\frac 1 2}, |z|>1 \\}$. \r\n${\\cal M}$ maps $H$ into itself and $D$ is a fundamental domain for $SL_2$.\r\n\\\\\r\n\\\\\r\n{\\bf Spherical triangles:}\r\n$cos(a) = sin(b) sin(c) cos(A) + cos(b) cos(c)$,\r\n${\\frac {sin(a)} {sin(A)}}  =  {\\frac {sin(b)} {sin(B)}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Some identities:} \r\n$cos(Y) - cos(X) = 2 sin({\\frac {X+Y} {2}}) sin({\\frac {X-Y} {2}})$.\r\n$cos(Y) + cos(X) = 2 cos({\\frac {X+Y} {2}}) cos({\\frac {X-Y} {2}})$.\r\n$sin(Y) + sin(X) = 2 sin({\\frac {X+Y} {2}}) cos({\\frac {X-Y} {2}})$.\r\n$sin(X) - sin(Y) = 2 cos({\\frac {X+Y} {2}}) sin({\\frac {X-Y} {2}})$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nThe \\emph{circumcenter} is the common intersection of the 3 perpendicular bisectors of\r\neach side of a triangle.\r\nThe \\emph{incenter} is the common intersection of the 3 angle bisectors of each side\r\nof a triangle.\r\nThe \\emph{orthocenter} is the intersection of the altitudes.\r\nAngle bisector divides opposite side in proportion to adjacent sides.\r\nThe \\emph{centroid} is the intersection of the medians.\r\n\\\\\r\n\\\\\r\n{\\bf Theorems:}  A triangle is divided into six triangles of equal area by the\r\nmedians.  The medians of a triangle divide one another in the ratio $2:1$.\r\nThe orthocenter, centroid, and circumcenter are collinear.  The centroid divides\r\nthe distance from the orthocenter to the circumcenter by the ration of $2:1$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe medians are concurrent by Ceva's theorem below.  In triangle $ABC$, numbering the sub-trangles\r\n$I, II, III, IV, V, VI$ starting from $A$ and going clockwise. ${\\cal A}(I) = {\\cal A}(II)$,\r\n${\\cal A}(III) = {\\cal A}(IV)$, and ${\\cal A}(V) = {\\cal A}(VI)$.  Also,\r\n${\\cal A}(I) + {\\cal A}(II) + {\\cal A}(III)= {\\cal A}(IV) +  {\\cal A}(V) + {\\cal A}(VI)$, so\r\n${\\cal A}(I) = {\\cal A}(VI)$.  A similar argument shows ${\\cal A}(I) = {\\cal A}(III)$.\r\n\\end{quote}\r\n{\\bf Theorems:}  In triangle $ABC$, (1) let $O$ be the circumcenter, then $OA = OB = OC$;\r\n(2) let $P$ be the incenter, the $d(AB, P) = d(BC, P) = d(AC, P)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nAgain, the altitudes are concurrent by Ceva.  Draw the diagram and use Pythagoras and similar triangles.\r\n\\end{quote}\r\n{\\bf Pick's Theorem:}  Let $B$ be a polygon which contains\r\n$n_i$ interior lattice points and\r\n$n_b$ lattice points on its boundary. $A(B)= n_i+{\\frac {n_b-2} 2}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe theorem is true for all right triangles with no interior points in the lattice. \r\nIf the theorem is true for a polygon $P$ and $T$ is a triangle with a single point not in $T$,\r\nthe theorem holds for $T \\cup P$.\r\n\\end{quote}\r\n{\\bf Two theorems on triangles:} In triangle $ABC$, suppose $D$ lies on $BC$, $BD=p$,\r\n$CD=q$, then $AD^2= {\\frac {pb^2-qc^2} {p+q}} - pq$.  In triangle, $ABC$ suppose the\r\nangle bisector of $A$ meets $BC$ at $D$, $BD=p$ and $CD=q$, then ${\\frac {p}{c}}= {\\frac {q}{b}}$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:}\r\nA \\emph{flex} is a non-singular point intersecting P with multiplicity three.  \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Every irreducible cubic\r\nin the plane has a singular point or a flex.  $H= det([F_{xx}, F_{yx}, F_{zx}]^T, ...)$.\r\nFlex or singular if $H=0$.\r\n\\begin{quote}\r\n\\end{quote}\r\nProjective points as one dimensional subspaces.  Projective lines are 1 dimensional.\r\n$n_{p \\; on \\; l} n_l= n_{l \\; on \\; p} n_p$.\r\n\\\\\r\n\\\\\r\n{\\bf Fundamental Theorem of Projective Geometry:}  Given three distinct collinear points on each of \r\ntwo distinct lines there is a projective transform \r\nthat maps the two sets of points in the specified order.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nDefine $X = [1,0,0], Y = [0,1,0], Z = [0,0,1], U = [1,1,1]$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma:}\r\nIf $L =(P,Q,R,S)$ is a list of points of $RP^2$, with no three collinear, then \r\nthere is a unique element of $P(2)$ mapping $(X,Y,Z,U)$ to $L$.\r\n\\\\\r\n\\\\\r\nProof of lemma: Let $P, Q, R, S$ be the $p$-points $[p]$, $[q]$, $[r]$, $[s]$ respectively.\r\nNo three of $P,Q,R,S$ are collinear, no three of $p,q,r,s$ are linearly dependent.\r\nSuppose that $t$ is defined by the matrix $A$. \r\nThen $t(U) = S$ if and only if $[Au] = [s]$, i.e. $Au = \\lambda s, \\lambda \\ne 0$ \r\nIf we replace $A$ by ${\\frac 1 {\\lambda}}A$, we get the same $t$, so we may assume that $Au = s$\r\nNow, $Ax, Ay, Az$ are just the columns of $A$ (in order), so\r\n$t$ maps $X, Y, Z$ to $P, Q, R$ if and only if the columns of $A$ are \r\nof the form $\\alpha p, \\beta q, \\gamma r$, with $\\alpha, \\beta, \\gamma \\ne 0$.\r\nAlso $Au$ is the sum of the columns of $A$ so that $t$ has the required images \r\nif and only if $\\alpha p + \\beta q + \\gamma r = s$.\r\nSince $p, q, r$ are linearly independent, this has a unique solution $\\alpha, \\beta, \\gamma$.\r\nSince $s$ is not dependent on any two of $p, q, r, \\alpha, \\beta, \\gamma$  are non-zero.\r\nThus the matrix $A$ with columns $\\alpha p, \\beta q, \\gamma r$ is invertible, so defines an element \r\nof $P(2)$. From the above argument, $A$ is unique up to scaling, so $t$ is unique.\r\n\\\\\r\n\\\\\r\nBy the lemma, there exist elements $r, s \\in  P(2) $\r\nsuch that $r$ maps $(X,Y,Z,U)$ to $L$ and $s$ maps $(X,Y,Z,U)$ to $L'$.\r\nThen $t = sr^{-1}$ maps $L$ to $L'$.\r\nSuppose that $u$ also maps $L$ to $L'$. Then $ur$ maps $(X,Y,Z,U)$ to $L'$.\r\nBy the uniqueness clause of the Theorem, only $s$ maps $(X,Y,Z,U)$ to $L'$.\r\nThus $ur = s$, so $u = sr^{-1} = t$, i.e. $t$ is unique.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nThe \\emph{cross ratio} of four points is\r\n$r= {\\frac {(x_{1}y_{3}-x_{3}y_{1}) (x_{2}y_{4}-x_{4}y_{2})}\r\n{ (x_{1}y_{4}-x_{4}y_{1}) (x_{2}y_{3}-x_{3}y_{2})}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  Let $ABC$ be a triangle.  The medians are concurrent and divide themselves in\r\nthe ratio $1:2$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $ABC$ be a triangle and let $F$ be the median from $A$ to $BC$ and\r\n$E$ be the median from $C$ to $AB$; let the medians meet at $G$.\r\nThe line $EF$ is parallel to $AC$ $EBF \\sim ABC$ and $FEG \\sim CGA$ so\r\n$EG:CG = FG : GA = 1:2$.\r\n\\end{quote}\r\n{\\bf Facts:}\r\nIn triangle $ABC$, $AB + BC > AC$; if $A > B$ then $BC > AC$.  A quadrilateral\r\nis cyclic if $ABCD$ lie on a circle. $ABCD$ is concyclic iff $ABC=ADB$.\r\n\\\\\r\n\\\\\r\n{\\bf Cross ratio from central projection:} Let $O$ be the center \r\nof a projection onto\r\na line with projecting lines $OA$, $OB$, $OC$ and $OD$ with $ABCD$ on the line. $r=\r\n{\\frac {(CA)(DB)} {(CB)(DA)}}$ is invariant (i.e., if $A', B', C', D'$ are colinear and\r\n$A'$, $B'$, $C'$, $D'$ lie on $OA$, $OB$, $OC$, $OD$, respectively then\r\n$r= {\\frac {(C'A')(D'B')} {(C'B')(D'A')}}$).\r\n\\begin{quote}\r\n\\emph{Proof:} \r\n$Area(OAC) = {\\frac {1} {2}} h CA = {\\frac 1 2} (OA)(OC)sin(COA)$,\r\n$Area(OBC) = {\\frac {1} {2}} h CB = {\\frac 1 2} (OB)(OC)sin(COB)$,\r\n$Area(ODA) = {\\frac {1} {2}} h AD = {\\frac 1 2} (OA)(OD)sin(AOD)$,\r\n$Area(ODB) = {\\frac {1} {2}} h DB = {\\frac 1 2} (OB)(OD)sin(BOD)$.\r\nDividing, we get\r\n${\\frac {(CA)(DB)} {(CB)(DA)}} = {\\frac {sin(COA) sin(BOD)} {sin(BOC) sin(AOD)}}$.\r\n\\end{quote}\r\n{\\bf Desargues:} If $ABC$ and $A'B'C'$ are perspective from a point $X$, then\r\n$AB \\cap A'B' = P$, $AC \\cap A'C' = Q$, $BC \\cap B'C' = R$\r\nare collinear.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $ABC$ and $abc$ are the two triangles with $Aa$, $Bb$, $Cc$ concurrent.\r\n$A, B, a, b$ are co-planar so $AB$ and $ab$ intersect.  If both triangles\r\nare on different planes, $(AB) \\cap (ab)$ is in both planes and so are\r\n$(AC) \\cap (ac)$ and $(BC) \\cap (bc)$  and $(BC) \\cap (bc)$.  These planes\r\nintersect in a line, proving the theorem.\r\n\\end{quote}\r\n{\\bf Pappus:} If $ABC$ is on $L$ and $A'B'C$' is on $L'$, then\r\n$AB' \\cap A'B = P$, $AC' \\cap A'C = Q$, $CB' \\cap C'B = R$ are collinear. \r\n\\begin{quote}\r\n\\emph{Proof:} See proof below.\r\n\\end{quote}\r\n{\\bf Ptolemy's Theorem:} Let $ABCD$ be a cyclic quadrilateral (vertices lie\r\non a circle).  Then $AB \\cdot CD + AD \\cdot BC = AC \\cdot BD$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$CAB = BDC$ and $ADB = BCA$.  Draw a line from point $K$ to the line $AC$ so that $ABK = DBC$.\r\n$\\Delta ABK \\cong \\Delta DBC$ and $\\Delta ABD \\cong \\Delta KBC$,\r\n${\\frac {AK} {AB}} = {\\frac {CD} {BD}}$ and ${\\frac {CK} {BC}} = {\\frac {AD} {BD}}$.\r\nThus $(AC)(BD) = (AK)(BD) +(CK)(BD) = (AB)(CD) + (BD)(DA)$.\r\n\\end{quote}\r\n{\\bf Pascal:}\r\nSuppose a hexagon is inscribed in a conic section,  \r\nand opposite pairs of sides are extended until they meet in 5 points. Then if \r\n4 of those points lie on a common line, the last point will be on that line, too. \r\n\\begin{quote}\r\nSee proof below.\r\n\\end{quote}\r\n{\\bf Menelaus and Ceva:} (1) If points $X, Y, Z$ on $BC, CA, AB$ (suitably extended) are collinear\r\nthen $\\frac {AZ} {ZB} \\frac {BX} {XC} \\frac {CY} {YA}  = 1$.  Similarly, (2)\r\n$ABC$ with $X$ opposite $A$. $AX, BY, CZ$ are concurrent iff\r\n$\\frac {AZ} {ZB} \\frac {BX} {XC} \\frac {CY} {YA}  = 1 $.\r\n\\begin{quote}\r\n\\emph{Proof:} \r\nRotate so that the line $XYZ$ is horizontal.  Drop perpendiculars from $A, B, C$ respectively to this\r\nline with heights $h_1, h_2, h_3$, respectively.  By similar triangles,\r\n${\\frac {AY}{CY}} = {\\frac {h_1} {h_3}}$,\r\n${\\frac {BZ}{AZ}} = {\\frac {h_2} {h_1}}$, and\r\n${\\frac {CX}{BX}} = {\\frac {h_3} {h_2}}$.  Multiply them together to get (1).\r\nFor (2), note that\r\n${\\frac {AZ}{BZ}}= {\\frac {|APZ|} {|BPZ|}}$,\r\n${\\frac {CY}{AY}}= {\\frac {|CPY|} {|APY|}}$, and\r\n${\\frac {BX}{CX}}= {\\frac {|BPX|} {|CPX|}}$.\r\nAlso,\r\n${\\frac {AZ}{BZ}}= {\\frac {|AZC|} {|BZC|}}$,\r\n${\\frac {CY}{AY}}= {\\frac {|CYB|} {|AYB|}}$, and\r\n${\\frac {BX}{CX}}= {\\frac {|AXB|} {|AXC|}}$.\r\nThus,\r\n${\\frac {BX} {CX}}= {\\frac {|ABX|-|BPX|}{|ACX|-|CPX|}}= {\\frac {|APB|} {|APC|}}$,\r\n${\\frac {CY} {AY}}= {\\frac {|BPC|} {|BPA|}}$, and\r\n${\\frac {AZ} {BZ}}= {\\frac {|APC|} {|BPC|}}$.\r\nMultiplying these together we get the result.\r\n\\end{quote}\r\n{\\bf Projective geometry with complex numbers:}  Points are $z \\in {\\mathbb C}$ and $\\infty$.  Cross ratio is \r\n$C(z_1, z_2; z_3, z_4) = {\\frac {(z_1 - z_3)(z_2 - z_4)}{(z_1-z_4)(z_2-z_3)}}$.  Four points lie on a line (or circle) iff their\r\ncross ratio is a real number.  Moebius Transformation: $f_{a,b,c,d}(z) = {\\frac {az+b} {cz+d}}$, $ad-bc \\ne 0$.\r\nIf a moebius transformation takes four points $(z_1, z_2, z_3, z_4) \\mapsto (u_1, u_2, u_3, u_4)$ then\r\n$C(z_1, z_2; z_3, z_4) = C(u_1, u_2; u_3, u_4)$.\r\nUse the fact that $f_{a,b,c,d}(z) - f_{a,b,c,d}(w) = {\\frac {(ad-bc)(z-w)}{(cz+d)(cw+d)}}$.\r\nIf $C(z_1, z_2; z_3, z_4) = C(u_1, u_2; u_3, u_4)$, there is a moebius transformation that maps $(z_1, z_2, z_3, z_4) \\mapsto (u_1, u_2, u_3, u_4)$.\r\n\\\\\r\n\\\\\r\n{\\bf Spherical Geometry:}  Let $PQR$ be a spherical triangle with subtended angles\r\n$p, q, r$ on a sphere of radius $R$.  The area of $PQR$ is $R^2(p+q+r-\\pi)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Let $P', Q', R'$ be the antipodal points of $P, Q, R$ respectively and\r\n$C_P, C_Q, C_R$ be the great circles containing $PP'$, $QQ'$ and $RR'$ respectively.\r\nLet $\\Delta_C$ be the common area of the three great circles in the hemisphere containing\r\n$P, Q, R$ which forms the spherical triangle.  If $\\Lambda(C_P, C_Q)$ \r\nis the lune formed by the intersection of the great circles, set \r\n$\\Delta_1= \\Lambda(C_P, C_Q) - \\Delta_C$,\r\n$\\Delta_2= \\Lambda(C_P, C_R) - \\Delta_C$,\r\n$\\Delta_3= \\Lambda(C_R, C_Q) - \\Delta_C$, and let\r\n$\\Delta_C'$, $\\Delta_1'$, $\\Delta_2'$, and\r\n$\\Delta_3'$ be the corresponding antipodal areas.  \r\n$\\Delta_C+ \\Delta_1+ \\Delta_2+ \\Delta_3= \\Delta_C'+ \\Delta_1'+ \\Delta_2'+ \\Delta_3'$,\r\nand\r\n$\\Delta_C+ \\Delta_1+ \\Delta_2+ \\Delta_3+\\Delta_C'+ \\Delta_1'+ \\Delta_2'+ \\Delta_3'\r\n=4 \\pi R^2$ (``EQ 1''), so\r\n$\\Delta_C+ \\Delta_1+ \\Delta_2+ \\Delta_3= 2 \\pi R^2$.  Further,\r\n$\\Delta_C + \\Delta_1= 2 R^2 p$, $\\Delta_C + \\Delta_2= 2 R^2 r$, and\r\n$\\Delta_C + \\Delta_3= 2 R^2 q$ so\r\n$3\\Delta_C+ \\Delta_1+ \\Delta_2+ \\Delta_3 = 2 R^2 (p+q+r)$, \r\nsubtracting EQ 1 from this and dividing by $2$ gives the desired result.\r\n\\end{quote}\r\n{\\bf Euler's Formula}: $V-E+F= \\chi$. For a sphere, $\\chi=2$.\r\nLet $n_i$: number of vertices with valence $i$, $2e \\geq 3F$, $\\sum in_i = 2E$.\r\n\\\\\r\n\\\\\r\n{\\bf Differential Geometry:}\r\nLet ${\\cal U} ({\\vec x}) = {\\frac {\\vec {x}} {|{\\vec {x}}|}}$.  \r\nCurve length: $s(t)= \\int_{t_0}^t | \\gamma'(t)| dt$.\r\n${\\vec T} (t)=  {\\cal U} (\\gamma'(t))$,\r\n${\\vec {N}}(t)= {\\cal U} (\\gamma''(t)) - \\langle \\gamma''(t), {\\vec {T}}(t) \\rangle {\\vec T}(t)$.\r\nAlternatively, ${\\vec T}(s)= {\\cal U}(\\gamma'(s))$, \r\n${\\vec N} (s)= {\\cal U}({\\vec T}'(s))$.\r\n$\\kappa(t)= {\\frac {\\langle {\\vec {T}}'(t), {\\vec {N}}(t) \\rangle} {\\gamma'(t)}}$, \r\n${\\vec B}(t)= {\\vec {T}}(t) \\times {\\vec {N}}(t)$,\r\n$\\tau(t)= {\\frac {\\langle {\\vec {N}}'(t) , {\\vec B}(t) \\rangle} {|\\gamma'(t)|}}$.\r\nFirst Fundamental Form: \r\nIf $E= {\\vec {x_u}} \\cdot {\\vec {x_u}}$,\r\n$F= {\\vec {x_u}} \\cdot {\\vec {x_v}}$ and\r\n$G= {\\vec {x_v}} \\cdot {\\vec {x_v}}$ then $I(du, dv)= E du^2 + 2F du dv + G dv^2$.\r\nIf ${\\vec N}= {\\frac { {\\vec {x_u}} \\times {\\vec {x_v}} }\r\n{| {\\vec {x_u}} \\times {\\vec {x_v}} |} }$ then\r\n$L= -{\\vec {x_u}} \\cdot {\\vec {N_u}}$,\r\n$M= -{\\frac 1 2}(\r\n{\\vec {x_u}} \\cdot {\\vec {N_v}} + {\\vec {x_v}} \\cdot {\\vec {N_u}})$,\r\n$N= -{\\vec {x_v}} \\cdot {\\vec {N_v}}$ and $II(du,dv)= L du^2 + 2M du dv +N dv^2$.\r\n$\\kappa_n= {\\frac {II} {I}}$.  $\\kappa$ is a principal curvature iff\r\n$det \\left(\r\n\\begin{array}{cc}\r\nL- \\kappa E &  M - \\kappa F \\\\\r\nM - \\kappa F &  N - \\kappa G\r\n\\end{array}\r\n\\right) =0$.  \r\nIf $f(x)=0$ defines surface, $H(f)= ({\\frac {\\partial^2 f} {\\partial x_i \\partial x_j}})$.\r\n\\emph{Gaussian curvature}: $det(H(f))$.\r\nIf a surface is represented by ${\\vec r}(u,v)$ for $(u,v) \\in {\\cal R}$ then\r\n$A(S)= \\int_{{\\cal R}} \r\n|{\\frac {\\partial {\\vec r}} {\\partial u}} \\times\r\n{\\frac {\\partial {\\vec r}} {\\partial v}}| \\thinspace du \\thinspace dv\r\n$.  \\emph{Torus:} ${\\vec r}( \\theta, \\phi)= (\r\n(R+r cos(\\phi)) cos(\\theta),\r\n(R+r cos(\\phi)) sin(\\theta), R sin(\\phi)) $.  $A(S)= 4 \\pi^2 rR$.\r\n\\\\\r\n\\\\\r\n{\\bf Model for Hyperbolic Geometry:}\r\n${\\cal H}= \\{ x+yi: y>0 \\}$ is the \\emph{hyperbolic plane}.  \\emph{Hyperbolic lines} are\r\nsemicircles with centers on the real axis.  Mobieus transformations fix ${\\cal H}$ and\r\nmap hyperbolic lines to hyperbolic lines. If $[a,b,c,d]$ is the cross ratio, the hyperbolic distance between\r\n$z_1$ and $z_2$ is $log([u,z_1, z_2, v])$ where $u$ and $v$ are the endpoints on the real line of\r\nthe hyperbolic line joining $z_1$ and $z_2$.  If a hyperbolic right trainagle consists of lines\r\nof length $a, b, c$, $cosh(c)= cosh(a) \\cdot cosh(b)$.  Any bijection mapping circles into cirlces is\r\na Mobieus transformation on $z$ or ${\\overline z}$.\r\n\\\\\r\n\\\\\r\n{\\bf Gaussian curvature:} If $k_1$ and $k_2$ are the maximum and minimum values\r\nof the curvature at a point on a surface, the Gaussian curvature is $K= k_1 k_2$;\r\n$\\chi=2-2g$ is the Euler characteristic, where $g$ is the genus.  $k_1$ and $k_2$ are\r\nalso eigenvalues of the \\emph{Hessian}.\r\nThe \\emph{genus} of a connected, orientable surface is an \r\ninteger representing the maximum number of cuttings along closed simple curves without \r\nrendering the resultant manifold disconnected and it is equal to the number \r\nof handles on it. \r\n\\\\\r\n\\\\\r\n{\\bf Gauss-Bonnet:}  If X is a compact, hypersurface in ${\\mathbb R}^{k+1}$, then\r\n$\\int_X K = Vol( S^k ){\\frac {\\chi (X)} {2}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Eight Point Theorem:}\r\nSuppose $C$ is a curve in ${\\mathbb P}^2_K$ defined by \r\nhomogeneous cubic polynomial $C(x,y,z)=0$.\r\nLet $l_1, l_2, l_3$ and $m_1, m_2, m_3$ be lines in ${\\mathbb P}^2_K$ with \r\n$l_i \\ne m_j, \\forall i,j$ and $P_{ij}= l_i \\cap m_j$.  Suppose further that $C$ is not\r\nsingular at $P_{ij}, \\forall i,j \\ne 3,3$.  Then $P_{33} \\in C$.\r\nThis is proved in a series of lemmas. \\emph{Lemma 1:} Let $P_{i1}=(u_i : v_i)$ \r\nand $m_j : a_j x +b_j y +c_j z=0$, \r\n${\\overline {m_j}} (u_i, v_i) = 0$ and\r\n${\\overline {m_j}}$ vanishes only at $P_{ij}$.\r\n${\\overline {m_1}} (u,v) {\\overline {m_2}} (u,v) {\\overline {m_3}} (u,v)$\r\nis a homogeneous cubic polynomial.   \r\n\\emph{Lemma 2:} If $R(u,v), S(u,v)$ are homogeneous of\r\ndegree $3$ and is not identically $0$ and they both vanish at $(u_i:v_i)$ then \r\n$\\exists  \\alpha \\in K, \\alpha \\ne 0$: $R = \\alpha S$.  \r\n\\emph{Lemma 3:}\r\n${\\overline C}= \\alpha {\\overline {m_1}} (u,v) {\\overline {m_2}} (u,v) {\\overline {m_3}} (u,v)$\r\nand\r\n${\\overline C}= \\alpha {\\overline {l_1}} (u,v) {\\overline {l_2}} (u,v) {\\overline {l_3}} (u,v)$.\r\n\\emph{Lemma 4:}  $l_i \\mid (C - \\alpha m_1 (u,v) m_2 (u,v) m_3 (u,v))$,\r\n$m_j \\mid (C - \\beta l_1(u,v) l_2 (u,v) l_3 (u,v))$ and\r\nif $D= C - \\alpha m_1 (u,v) m_2 (u,v) m_3 (u,v) - \\beta l_1 (u,v) l_2 (u,v) l_3 (u,v)$, then\r\n$l_i m_ j \\mid D$.  \r\n\\emph{Lemma 5:} $D = l_1 m_1 l(u,v)$ and\r\n$l(P_{22})= l(P_{23})= l(P_{32})=0$, so $D=0$.  To conclude the proof of the\r\neight point theorem, observe, since $D=0$, \r\n$C= \\alpha m_1 (u,v) m_2 (u,v) m_3 (u,v) + \\beta l_1 (u,v) l_2 (u,v) l_3 (u,v)$ and\r\n$l_3 (P_{33})= m_3 (P_{33}) =0$ thus $C (P_{33})=0$.\r\n\\\\\r\n\\\\\r\n{\\bf The eight point theorem proves associativity of elliptic curve addition:}\r\nLet $P, Q, R$ be points\r\non $C$ and consider\r\n$l_1= {\\overline {P,Q}}$,\r\n$l_2= {\\overline {\\infty,Q+R}}$,\r\n$l_3= {\\overline {R,P+Q}}$,\r\n$m_1= {\\overline {Q,R}}$,\r\n$m_2= {\\overline {\\infty,P+Q}}$,\r\n$m_3= {\\overline {P,R+Q}}$.\r\n$l_1 \\cap m_1= Q$,\r\n$l_1 \\cap m_2= -(P+Q)$,\r\n$l_1 \\cap m_3= P$,\r\n$l_2 \\cap m_1= -(Q+R)$,\r\n$l_2 \\cap m_2= \\infty$,\r\n$l_2 \\cap m_3= Q+R$,\r\n$l_3 \\cap m_1= R$,\r\n$l_3 \\cap m_2= (P+Q)$,\r\n$l_3 \\cap m_3= X$. $X$ is $-((P+Q)+R)$ (from the definition of $l_3$) and $-(P+(Q+R))$ \r\n(from the definition of $m_3$) by the definition of addition.  Now\r\napply the eight point theorem to get the result.\r\n\\\\\r\n\\\\\r\nThe eight point theorem also proves {\\bf Pascal's Theorem:}\r\nLet $ABCDEF$ be a hexagon inscribed in a\r\nconic section whose equation is $Q(x,y,z)=0$.  If \r\n$X= {\\overline {AB}} \\cap  {\\overline {DE}}$,\r\n$Y= {\\overline {BC}} \\cap  {\\overline {EF}}$,\r\n$Z= {\\overline {CD}} \\cap  {\\overline {FA}}$, then $X, Y, Z$ are collinear.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nPut\r\n$l_1 = {\\overline {EF}}$,\r\n$l_2 = {\\overline {AB}}$,\r\n$l_3 = {\\overline {CD}}$,\r\n$m_1 = {\\overline {BC}}$,\r\n$m_2 = {\\overline {DE}}$,\r\n$m_3 = {\\overline {FA}}$, $C(x,y,z)= Q(x,y,z)l(x,y,z)$ and apply the theorem. \r\n\\end{quote}\r\nThis also proves {\\bf Pappus's Theorem:} Let $l, m$ be two distinct lines $A,B,C$ on $l$ and\r\n$A', B', C'$ on $m$ none of which are on $l \\cap m$.  If\r\n$X= {\\overline {AB'}} \\cap  {\\overline {A' B}}$,\r\n$Y= {\\overline {BC'}} \\cap  {\\overline {B'C}}$,\r\n$Z= {\\overline {CA'}} \\cap  {\\overline {C'A}}$, then $X, Y, Z$ are collinear.  \\emph{Proof:}\r\nUse Pascal with hexagon $AB'CA'BC'$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nLet $\\Phi: Q \\rightarrow P$ be a \\emph{homotopy} of $\\varphi_0$ into $\\varphi_1$ as closed\r\ncurves and let $y \\notin \\Phi(Q)$.  Then the \\emph{winding number}\r\n$W(\\varphi_r, y)$ is constant\r\nfor $0 \\le r \\le 1$.  Let $\\varphi$ be a closed curve $\\varphi: [a,b] \\rightarrow P$ and\r\nsuppose $y_0 , y_1$ can be joined by a curve which does not intersect $\\varphi$, then\r\n$W(\\varphi, y_0 )= W(\\varphi , y_1)$.  Let $f: D \\rightarrow P$ be a mapping of\r\nthe disk onto the plane and let $C= \\partial D$ and let $y \\notin f(C)$;\r\nif the winding number\r\nof $f|C$ about $y$ is not zero, then $y \\in f(D)$ such that $f(x)=y$.\r\nLet $f: D \\rightarrow P$ be a mapping of a disk onto a plane, $P$ and $C= \\partial D$\r\nthat fixes all of $C$ then $D \\subseteq f(D)$.  No mapping of a disk onto its boundary\r\nfixes each point of the boundary.  If $f$ is a mapping of a disk onto itself, it has\r\na fixed point. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nA finite group of transformations over ${\\mathbb R}^3$ has fixed points. $|G|= v_p n_p$,\r\n$2(|G| -1) = \\sum_p (v_p - 1)$.\r\n\\subsection {Real Analysis and Manifolds}\r\n{\\bf Definition:} A metric space, $R$, is a vector space with a distance\r\n$d: R \\times R \\rightarrow {\\mathbb R}^{\\ge 0}$,\r\nsuch that $d(x,x) = 0$ iff $x = 0$ and $\\forall x, y, z \\in R$, $d(x,z) \\leq d(x, y) + d(y, z)$.\r\n$B_r(c) = \\{ x: d(x,c) \\leq r \\}$\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A set $S \\subseteq R$ in a metric space $R$ is open if $\\forall x \\in R, \\exists \\epsilon > 0:\r\nB_{\\epsilon} \\subseteq S$.  $T$ is a closed set if $R \\setminus S$ is open.  A subset $S \\subseteq R$ if every\r\nopen cover of $S$ contains a finite subcover of $S$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} (a) $S$ is compact iff $S$ is closed and bounded; (b) $[a, b]$ is compact;\r\n(c) if $f$ is continuous, $f([a,b])$ is compact; (d) if $S$ is closed and\r\n$lim_{n \\rightarrow \\infty} x_n = a, x_n \\in S$ then $a \\in S$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n(a, $\\rightarrow$) Suppose $S$ is a compact set and suppose ${\\overline S}$ is not open.  There is a point\r\n$X \\in {\\overline S}$ which contains no open ball, $B_r(X)$.  Let $R_x = \\{y \\in S: d(x,y) < {\\frac \r\n{d(x, X)} 2}$ then $\\{R_x, x \\in S \\}$ is an open cover of $S$ with no finite subcover, so\r\nno such $X$ exists and ${\\overline S}$ is open so $S$ is closed.  If $S$ is not bounded then\r\n$R_{x, n} = \\{ y \\in S: d(x,y) < n \\}$, $\\{R_{x, n}, x \\in S n \\in {\\mathbb Z} \\}$\r\nis an open cover with no finite subcover so $S$ must be bounded. (a, $\\leftarrow$) Suppose $S$\r\nis a closed, bounded set which is not compact and let $U$ be an open cover of $S$.  Since\r\n$S$ is bounded there are a finite number of closed balls ${\\overline {B_{\\frac 1 2}(a_i)}}, a =\r\n1, 2, \\ldots, k$.  At least one of $S_1 = S \\cap {\\overline {B_{\\frac 1 2}(a_i)}}$, say\r\n${\\overline {B_{\\frac 1 2}(a_j)}}$, which does not have a finite subcover.  Repeating this argument,\r\nwith $S_2 = {\\overline {B_{\\frac 1 4}(a_j)}},  \\ldots , S_k{\\overline {B_{\\frac 1 {2^k}}(a_j)}}, \\ldots ,$.\r\n$S_1 \\supseteq S_2 \\supseteq \\ldots$.  The common interesection contains a point $p \\in S$.  Since\r\n$U$ contains an open subset $T$, $p \\in T$, the chain of subsets terminates after finitely many\r\nterms contradicting the assumption that no finite subcover exists.\r\n(b) $[a,b]$ is closed and bounded and the result follows from (a). (c) If $U$ is a cover of\r\n$f([a,b])$; then $W = \\{f^{-1}(X), X \\in U \\}$ is a cover of $[a,b]$, so there is a finite \r\nsubcover $W_1 \\subseteq W$ but then $\\{f(Y), Y \\in W_1 \\}$ is a finite cover of $f([a,b])$.\r\n(d) If $lim_{n \\rightarrow \\infty} x_n = a, x_n \\in S$ then any open set containing $a$\r\nhas a non trivial intersection with $S$ and so ${\\overline S}$ is not open if $a \\in {\\overline S}$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $f$ is continuous on $[a,b]$ and $f(a)=f(b)$ then $f$ attains a maximum (minimum) at some point,\r\n$c: a<c<b$ and if $f$ is differentiable, $f'(c)=0$.\r\n$\\exists \\xi, a < \\xi < b$ such that $f'(\\xi)= {\\frac {f(b)-f(a)} {b-a}}$.\r\n\\begin{quote}\r\n\\emph{Proof:} Set $g(x)= f(x)-[({\\frac {f(b)-f(a)}{b-a}}) (x-a) + f(a)]$.  $g(a)=g(b)=0$ and there is a\r\n$a<\\xi<b$ on which $g$ attains a maximum or minimum. $g'(\\xi)= 0 = f'(\\xi) - {\\frac {f(b)-f(a)}{b-a}}$.\r\n\\end{quote}\r\n{\\bf Definition:} $f$ is \\emph{convex upwards} (resp \\emph{convex downwards}) on $[a,b]$ if \r\n$f(at+(1-t)b) \\leq tf(a)+(1-t)f(b)$ for $0 \\leq t \\leq 1$\r\n(resp.  $f(at+(1-t)b) \\geq tf(a)+(1-t)f(b)$ for $0 \\leq t \\leq 1$).\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $f''(x) > 0$ (resp $f''(x)<0$, $a \\leq x \\leq b$) then $f$ is \r\nconvex upwards (resp convex downwards).\r\n\\begin{quote}\r\n\\emph{Proof (convex backwards):} Put $g(t)= f(ta+(1-t)b)-tf(a)+(x-1)f(b)$.  $g(0)=g(1)=0$.\r\n$g''(t)= (a-b)^2f''(ta+(1-t)b)$.  If $g$ has a local minumum at $t_0$,\r\n$g(t_0)= 0$ and $g''(t_0)>0$.  This is a contradiction so the minumum of $g, 0 \\leq t \\leq 1$\r\noccurs at the endpoints and the result holds.\r\n\\end{quote}\r\n{\\bf Definition} A space is connected iff it cannot be written as a disjoint union of\r\nrelatively open sets.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If $f$ is continuous and $E$ is a connected space, so is $f(E)$.\r\n\\begin{quote}\r\n\\emph{Proof:} Suppose $f(E)= X \\cup Y$, then $f^{-1}(X) \\cup f^{-1}(Y) = f(E)$ and they\r\nare disjoint, relatively open sets.\r\n\\end{quote}\r\n{\\bf Theorem:} If $\\varphi$ is strictly increasing and $\\varphi: [A,B] \\rightarrow [a,b]$ and $\\alpha$ is also\r\nincreasing on $[a,b]$, set $\\beta(y)= \\alpha(\\varphi(y))$ and $g(y)= f(\\varphi(y))$ then\r\n$\\int_A^B g \\; d \\beta = \\int_a^b f \\; d \\alpha$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Fundamental Theorem of Calculus:}   Suppose $f$ is integrable on $[a,b]$ and define\r\n$F(x)= \\int_a^x f(t) \\; dt$ \r\nthen for $a \\leq c \\leq b$, we have $F'(c)= f(c)$ and $\\int_a^b f(t) \\; dt = F(b)-F(a)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$F(x+h) - F(x) = \\int_{x}^{x + h} f(x) dx$, $\\exists c: x \\leq c \\leq x+h: \\int_{x}^{x + h} f(x) dx =h f(c)$.\r\nSo $lim_{h \\rightarrow 0} {\\frac {F(x+h) - F(x)} {h}} = f'(x)$.\r\n\\end{quote}\r\n{\\bf Definition:} \r\nA sequence $\\{ f_n \\}$ converges \\emph{uniformly} on $E$ to $f$ if $\\forall \\epsilon >0, \\exists N: n>N,\r\n|f(x) - f_n(x)| < \\epsilon$.\r\nA family ${\\cal F}$ is \\emph{equicontinuous} on $E$ if $\\forall \\epsilon > 0, \\exists \\delta >0:\r\n|f(x)-f(y)| < \\epsilon$ if $|x-y| < \\delta, \\forall f \\in {\\cal F}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:} If a sequence of continuous functions $\\{ f_n \\}$ converges uniformly to $f$ on $E$ then\r\n$f$ is continuous on $E$.\r\n\\begin{quote}\r\n\\emph{Proof:} Choose $N: \\forall n \\geq N, |f_n(x) - f(x)| < {\\frac {\\epsilon} {3}}$ and choose \r\n$\\delta > 0: |f_n(x+h) - f_n(x)| < {\\frac {\\epsilon} {3}}$.\r\n$|f(x+h) - f(x)| \\leq |f_n(x + h) - f(x + h)| + |f_n(x) - f(x)| + |f_n(x+h) - f_n(x)| < \\epsilon$ for\r\nthe chosen $\\delta$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $K$ is compact and a sequence of continuous functions $\\{ f_n \\}$\r\nconverges pointwise to $f$ on $K$\r\nand if $f_n(x) \\geq f_{n+1}(x)$ then $\\{ f_n \\}$ converges \\emph{uniformly} on $K$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} If $K$ is compact and $\\{ f_n \\}$ converges uniformly then $\\{ f_n \\}$ is equicontinuous.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:} If $K$ is compact and $\\{ f_n \\}$ converges pointwise on $K$ then $\\{ f_n \\}$ is uniformly\r\nbounded and $\\{ f_n \\}$ contains a uniformly convergent subsequence.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Stone Weierstrauss Theorem:} If $f$ is continuous on $K$, compact, $\\exists P_n \\in {\\mathbb R}[x]$ such that\r\n$\\textnormal{lim}_{n \\rightarrow \\infty} P_n(x)= f(x)$.\r\n\\\\\r\n\\\\\r\n{\\bf Lemma:} The Stone Weierstauss Theorem holds if \r\n$f, g \\in {\\overline {{\\mathbb R}[x]}} \\rightarrow max(f,g), min(f,g) \\in {\\overline {{\\mathbb R}[x]}}$.\r\n\\begin{quote}\r\n\\emph{Proof of Lemma:} $\\forall \\alpha, \\beta$, if $x_1 \\ne x_2$, $\\exists h \\in {\\overline {{\\mathbb R}[x]}}$ such that\r\n$h(x_1) = \\alpha$ and $h(x_2) = \\beta$.  To show this, pick $\\phi \\in {\\mathbb R}[x]: \\phi(x_1) \\ne \\phi(x_2)$ then put\r\n$h(x) = \\alpha + \\beta {\\frac {\\phi(x) - \\phi (x_1)} {\\phi(x_2) - \\phi (x_1)}}$.\r\nNext we show that if $f$ is continuous on $S$ then, $\\forall \\epsilon > 0, \\forall z \\in {\\overline {{\\mathbb R}[x]}},\r\n\\exists g \\in {\\overline {{\\mathbb R}[x]}}: f(z) - \\epsilon < g(z) < f(z) + \\epsilon$.  Let $h_{x,y}(z)$ be a function\r\nwith $h_{x,y}(x) = f(x)$ and $h_{x,y}(y) = f(y)$.  Such a function exists by the first part of this proof.\r\nLet $U_x$ be a open neighborhood of $x$ in which $h_{x,y}(z) < f(z) + \\epsilon$ which exists by continuity.\r\nThere is a finite subcover of $U_x$, $U_{x_1}, \\ldots , U_{x_n}$.  Put $g = min(h_{x_1, y}, \\ldots, h_{x_n, y})$.\r\nLet $V_y$ be a open neighborhood of $y$ in which $f(z) - \\epsilon < h_{x,y}(z)$, again we can find a finite\r\nsubcover and putting $g = max(h_{x,y_1}(z), \\ldots, h_{x,y_m}(z))$, we get $f(z) < g(z) - \\epsilon$.\r\n$f(z) - \\epsilon < g(z) < f(z) + \\epsilon$, proving the lemma.\r\nNote that $\\sum_{i=0}^n {n \\choose i} f({\\frac {i}{n}}) x^i (1-x)^{n-i}$ is a good approximation of $f$.\r\n\\end{quote}\r\n\\begin{quote}\r\n\\emph{Proof of Stone Weierstrauss:} \r\nSince \r\n$max(f,g) = |f| + |g| + |f - g|$ \r\nand\r\n$mix(f,g) = |f| + |g| - |f - g|$, it suffices to show $h(x) = |x| \\in {\\overline {{\\mathbb R}[x]}}$.\r\nThen $\\forall \\epsilon > 0, \\exists P : |P(t) - |t|| < \\epsilon$ and so $|P(f(x)) - |f(x)|| < \\epsilon$.\r\nThus, $P(f(x)) \\in {\\overline {{\\mathbb R}[x]}}$.\r\n\\end{quote}\r\n{\\bf Theorem:} Let ${\\cal A}$ be an algebra of real continuous functions on a compact set $K$.   If\r\n${\\cal A}$ separates points and vanishes at no point then the uniform closure of ${\\cal A}$ consists of all\r\nreal continuous functions.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Taylor's Theorem:} $f(x)= \\sum_{k=0}^n{\\frac {f^{(k)}(a)} {k!}} (x-a)^k\r\n+ {\\frac {f^{(n+1)}(c)} {(n+1)!}}(x-a)^{n+1}$ for some $c: a<c<x$.\r\n\\begin{quote}\r\n\\emph{Proof:} Set $F(t)= \\sum_{k=0}^n{\\frac {f^{(k)}(t)} {k!}} (x-t)^k$ and let\r\n$E_n(x)= f(x)-\\sum_{k=0}^n{\\frac {f^{(k)}(a)} {k!}} (x-a)^k$.  Note\r\n$F(x)-F(a)=E_n (x)$ and\r\n$F'(t)= {\\frac {f^{(n+1)}(t)} {n!}}(x-t)^n$.  Put $G(t)= (x-t)^{n+1}$ and\r\n$H(t)= G(t)[F(x)-F(a)]-F(t)[G[x]-G(a)]$.  $H(a)= H(x)$ so\r\n$\\exists c: a<c<x$ with $H'(c)=0$.  So\r\n$E_n(x)=F(x)-F(a)= {\\frac {F'(c)} {G'(c)}} [G(x)-G(a)]$.  Substituting gives\r\nthe desired result.\r\n\\\\\r\n\\\\\r\n\\emph{Another proof:}  $b= a+h$,\r\n$f(b)= f(a)+ {\\frac {(b-a)} {1!}} f^{(1)}(a)+ \\ldots + \r\n{\\frac {(b-a)^n} {n!}} f^{(n)}(a) + R_n(a)$.  Regard $b$ as constant and differentiate with respect to \r\n$a$.  By repeated application of the product rule, we get\r\n$0= R_n'(a) + {\\frac {(b-a)^{n}} {n!}} f^{(n+1)}(a)$.  Integrating (and switching limits), we get\r\n$R_n(a)= \\int^b_a {\\frac {(b-t)^n} {n!}} f^{(n+1)}(t) dt$.  Applying the generalized mean value theorem\r\n($p(x)>0 \\rightarrow \\int^b_a f(x)p(x) dx = f(\\xi) \\int^b_a p(x) dx, a \\leq \\xi \\leq b$), we get\r\n$R_n(a)= {\\frac 1 {n!}} f^{(n+1)}(\\xi) \\int_b^a (b-t)^n dt ={\\frac 1 {(n+1)!}} f^{(n+1)}(\\xi) (b-a)^{n+1}$.\r\n\\\\\r\n\\\\\r\n\\emph{A third proof}:\r\nWe proceed by induction.  We want to show $f(a+h) = f(a) + \\sum_{i=1}^{n} {\\frac {h^i} {i!}} f^{(i)}(a) + R_n$,\r\nwhere $R_n= \\int_{a}^{a+h} f^{(n+1)}(t) {\\frac {(a + h -t)^n}  {n!}} dt$.\r\nFor $n=0$, $f(a+h) - f(a) = \\int_{a}^{a+h} f'(t) dt$ is just the FTOC.\r\nFor step $n+1$, we have from step $n$ that \r\n$f(a+h) -f(a) -\\sum_{i=1}^{n} {\\frac {h^i} {i!}} f^{(i)}(a) = \\int_{a}^{a+h} f^{(n+1)}(t) {\\frac {(a + h -t)^n} {n!}}dt$. \r\nIntegrate by parts with\r\n$u= f^{(n+1)}(t)$ and $v= -{\\frac {(a+h -t)^{n+1}} {(n+1)!}}$. This gives\r\n$f(a+h) - f(a) - \\sum_{i=0}^{n+1} f^{(i)}(a) {\\frac {h^i} {i!}} =\r\n\\int_{a}^{a+h} {\\frac {(a+h-t)^{n+1}}{(n+1)!}}f^{(n+2)}(t) dt$ which is the result for $n+1$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\n$X$ separates if $\\exists A, B, A \\ne X, \\emptyset, \\exists B \\ne X, \\emptyset$ \r\nboth open with $A \\cup B = X$ and $A \\cap B = \\emptyset$.\r\n$X$ is connected iff there is no separation.\r\nSuppose $f: X \\rightarrow Y$ is \\emph{continuous.}  If $X$ is compact so is $f(X)$.  If\r\n$X$ is connected, so is $f(X)$. If $X$ compact, \\emph{connected}\r\nset in ${\\mathbb R}$ then $X=[a,b]$.\r\n\\\\\r\n\\\\\r\n{\\bf Some identities:}\r\n$\\int_{-\\pi}^{\\pi} cos(mx) cos(nx) dx = \r\n\\int_{-\\pi}^{\\pi} sin(mx) sin(nx) dx=  \\delta_{mn} \\pi$.  \r\n\\emph{Bernoulli:} $\\phi_n'(x)=\\phi_{n-1}(x), \\phi_0(x)=1, \\int_0^1 \\phi_n(x) dx = 1$.\r\n$\\Gamma (x) = \\int_{0}^{\\infty} u^{x-1} e^{-u} du$.\r\n\\\\\r\n\\\\\r\n{\\bf Optimization:}\r\n$f$ has a global minimum if it is \\emph{convex}.  $f$ is convex iff its \\emph{Hessian} is\r\npositive semi-definite.  An optimization problem is convex if the objective function and\r\nthe constraints are convex.  Convex optimization problems have global minimums.\r\n\\\\\r\n\\\\\r\n{\\bf Fixed Point Theorem:} \r\nLet $E$ be a complete metric space and $f: E \\rightarrow E$.  Suppose\r\n$\\exists k<1: \\forall p,q \\in E, ||f(p)-f(q)|| \\le k ||p-q||$.  Then there is a unique\r\n$P \\in E: f(P)=P$.  \r\n\\begin{quote}\r\n\\emph{Proof:} Let $p_{n+1}= f(p_n )$.\r\n$||f(p_{n+1})-f(p_n)|| \\le k ||p_n - p_{n-1}||\\le k^n ||p_1-p_0||$.  This is a Cauchy\r\nsequence and converges.  Set $p= lim_{n \\rightarrow \\infty} p_n$,\r\n$f(p)=p$.  Uniqueness:  if $q$ is another such point:\r\n$||f(p)-f(q)||= ||p-q|| \\le k||p-q||$ so $||p-q||=0$.\r\n\\end{quote}\r\n{\\bf Simple Implicit Function Theorem:}  \r\nLet $f$ be a real valued continuous function on an\r\nopen set $E \\subset {\\mathbb R}^2, (a,b) \\in E$ with continuous partial\r\n${\\frac {\\partial f} {\\partial y}} (a,b) \\ne 0$.  There are open sets $U,V$ with\r\n$a \\in U, b \\in V$ and a continuous function $\\varphi: U \\rightarrow V$ such that\r\n$f(x,\\varphi(x))=0, x \\in U$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nDefine $F(x,y)= y-f(x,y) ({\\frac {\\partial f} {\\partial y}})^{-1}$.  $F(a,b)=b,\r\n{\\frac {\\partial F}{\\partial y}} (a,b)=0$ and $F(x,y)=y$ iff $f(x,y)=0$.  Pick $r$\r\nsmall enough so that in the ball $B_r(a,b):\r\n|{\\frac {\\partial F}{\\partial y}}|< {\\frac 1 2}$.  Choose $k: 0<k<r$ then choose \r\n$h:0<h<{\\sqrt {r^2-k^2}}$ such that\r\n$|F(x,b)-b| < {\\frac k 2}$ when $|x-a|<h$.\r\nPut $U=(a-h,a+h), V=(b-k,b+k)$.\r\nFix $x \\in U$ and $|y-b| \\le k$ and suppose\r\n$||(x,y)-(a,b)||^2<h^2+k^2<r^2$ and\r\n$||(x,y')-(a,b)||^2<h^2+k^2<r^2$.  $\\exists y'': |F(x,y)-F(x,y')| \\le \r\n{\\frac {\\partial F} {\\partial y}} (x, y'') |y-y'| \\le\r\n{\\frac 1 2 } |y-y'|$ \r\nand $|F(x,y)-b| \\le |F(x,y) - F(x,b)| + |F(x,b)-b| < k$.\r\nApply Fixed Point Theorem to get ${\\overline y}= f(x, {\\overline y})$.\r\nThis is unique.  Define $\\varphi(x)= {\\overline y}$.  A simple argument shows\r\n$\\varphi$ is continuous.\r\n\\end{quote}\r\n{\\bf Simple Inverse Function:} Let $g$ be a real valued function \r\non an open set $E \\subset {\\mathbb R}$ and suppose $g'$ exists and is continuous in $E$\r\nand $g'(b) \\ne 0$.  There are open sets $U, V \\subset {\\mathbb R}$ with $b \\in V: g_{|V}$\r\nis 1-1 and $g^{-1}: U \\rightarrow V$ is differentiable.  \\emph{Proof:}  Put\r\n$f(x,y)=x-g(y)$ and apply the implicit function theorem.\r\n\\\\\r\n\\\\\r\n{\\bf Existence of solution to ordinary differential equation:}  Let $f$ be a continuous\r\nreal valued function in an open set $E \\subset {\\mathbb R}^2$ containing $(a,b)$\r\nand suppose $\\exists M: |f(x,y)-f(x,z)|< M|y-z|, (x,y), (x,z) \\in E$ then\r\n$\\exists h>0$ and $\\varphi: (a-h, a+h) \\rightarrow (b-M, b+M): \\varphi'(x)= f(x,\\varphi(x))$\r\non $(a-h, a+h)$ and $\\varphi(a)=b$.  \r\n\\begin{quote}\r\nProof:  This is equivalent to\r\n$\\varphi(x)= \\int_a^x f(t, \\varphi(t)) dt +b$.  Suppose $\\psi$ is a function and\r\ndefine $F: \\psi \\mapsto \\int_a^x f(t, \\psi(t)) dt +b$.  $F$ maps the complete\r\nmetric space of functions on a closed interval of $E$ itself.  A fixed point in\r\nthis metric space would satisfy the theorem; we show such a fixed point exists.\r\nChoose $N > |f(a,b)|, \\exists r: ||(x,y)-(a,b)|| <r \\rightarrow\r\n|f(x,y)| < N$.  Choose $h>0: h < {\\frac r {2N}}, h < {\\frac 1 2}, hM < 1$ \r\nand consider the complete metric\r\nspace of continuous functions on $[a-h, a+h]$ denoted by\r\n${\\cal C}([a-h, a+h])$; define \r\n$R= \\{ (x,y) \\in E: |a-x| \\le h, |y-b| \\le Nh\\}$ and\r\n$B= \\{ \\psi: [a-h, a+h] \\rightarrow [b-Nh, b+Nh] \\}$, finally, Let\r\n$B_{Nh}(b)$ be the ball in\r\n${\\cal C}([a-h, a+h])$ of functions within $Nh$ of the constant function $b$.\r\nFor $\\psi, \\omega \\in B_{Nh}(b)$ note that $|\\psi(x)-b| < Nh$ and $f(t,\\psi(t))<N$\r\nso $|F \\psi (x)-b| < Nh$.\r\nFor $\\psi, \\omega \\in B_{Nh}(b): |F \\psi (x) - F \\omega (x)| \\le hM || \\psi - \\omega ||$.\r\nThis satisfies the conditions of the fixed point theorem and the fixed point\r\nsatisfies the conclusion of the theorem.\r\n\\end{quote}\r\n{\\bf Implicit Function Theorem:} Let \r\n$a \\in E^m \\subset {\\mathbb R}^m$ and\r\n$b \\in E^n \\subset {\\mathbb R}^n$ with $(a,b) \\subset E^{m+n}$, and open set.  Suppose\r\n$f_1(a,b)= \\ldots = f_n(a,b)=0$ and ${\\frac {\\partial f_i} {\\partial y_j}}$\r\nexist and are continuous in $E^{m+n}$ and \r\n$det({\\frac {\\partial f_i} {\\partial y_j}}(a,b)) \\ne 0$ then \r\n$\\exists U^{open} \\subset E^m, a \\in U,\r\nV^{open} \\subset E^n, b \\in V, \\varphi: U \\rightarrow V$ such that $f_i(x, \\varphi(x))=0$\r\nfor $i= 1,2, \\ldots, n$.  \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nDefine $x={\\vec x}= (x_1, \\ldots, x_m)$,\r\n$y={\\vec y}= (y_1, \\ldots, y_n)$ and $F= {\\vec F}= (\r\nF_1({\\vec x}, {\\vec y}) , \\ldots,\r\nF_n({\\vec x}, {\\vec y}))$.  Define $F_i(x,y)= y_i- \\sum_j c_{ij} f_j (x,y)$ with each\r\npartial continuous. (1) The $F_i$ are continuously differentiable; (2) $F_i(a,b)=b$;\r\n(3) ${\\frac {\\partial F_i} {\\partial y_j}}(a,b) = 0$; (4) $f_i(x,y)= 0$ iff\r\n$F_i(x,y)= y_i$.  For 3 to hold $(c_{ij})$ must be the inverse of the Jacobian.  For\r\n4 to hold, the determinant of the Jacobian must be $\\ne 0$.  Choose $r>0$ such that\r\nfor $(x,y) \\in B_r(a,b) \\subset E^{m+n}$, \r\n$|{\\frac {\\partial F_i} {\\partial y_j}}| < {\\frac 1 {2n^2}}$ and\r\n$det({\\frac {\\partial F_i} {\\partial y_j}}) \\ne 0$.  Choose $k: 0 < k < r$ and\r\nchoose $h$ so that $0 < h < {\\sqrt {r^2 - k^2}}$ and\r\n$||F(x,b) - b|| < {\\frac k 2}$ if $||x-a|| < h$.  Fix $x \\in U$ with\r\n$||(x,y)-(a,b)||<r$.  If $y' \\in E^n , ||y'-b|| \\le k, \\exists y'':\r\nF(x,y)-F(x,y') = (y-y') \\cdot \r\n({\\frac {\\partial F_1(x,y'')} {\\partial y_1}}, \\ldots , \r\n{\\frac {\\partial F_n(x,y'')} {\\partial y_n}}) \\le\r\n{\\frac 1 {2n^2}}(|y_1-y_1'| + \\ldots + |y_n-y_n'|) \\le {\\frac 1 {2n}} ||y-y'||$.\r\nSo $||F(x,y)-F(x,y')||<k$ and the fixed point theorem applies.\r\n\\end{quote}\r\n{\\bf Extended Inverse Function Theorem:} $f_i(x,y)= x_i - g_i(y), a= g(b)$.  Same deal.\r\n\\\\\r\n\\\\\r\n{\\bf Inverse Function Theorem:}\r\nSuppose $f: {\\mathbb R}^n \\rightarrow {\\mathbb R}^n$ is continuously differentiable\r\nand $|det(f'(a)| \\ne 0$.  \r\n$\\exists V^{open}, W^{open}, f^{-1}, a \\in V, f(a) \\in W $ with\r\n$f^{-1}: W \\rightarrow V$ and $f^{-1}(f(x)=x$.  Further \r\n$f'^{-1}(y)= {\\frac 1 {f'(f^{-1}(y))}}$.\r\n\\\\\r\nNotes:  Let $\\lambda =D(f(a))$.  May assume $\\lambda= I$.  Can show\r\n$|x_1 - x_2 | \\leq |f(x_1 ) - f(x_2 )|$.\r\n\\\\\r\n\\\\\r\n{\\bf Implicit Function Theorem:}  If $f: {\\mathbb R}^n \\times {\\mathbb R}^m  \r\n\\rightarrow {\\mathbb R}^m$ is continuously\r\ndifferentiable in an open set containing \r\n$(a,b), f(a,b)=0$ with $M= (D_{n+j}(f^i (a)))$ with\r\n$1 \\leq i,j \\leq m$.  If $det(M) \\ne 0, \\exists A^{open} \\subseteq {\\mathbb R}^n$ \r\nand $B^{open} \\subseteq {\\mathbb R}^m, a \\in A, b \\in B: \\forall x \\in A$ \r\nthere is a unique $g(x) \\in B, f(x,g(x))=0$.\r\nFurther, $g$ is differentiable.\r\n\\\\\r\nNotes:  Look at $F(x,y)=(x,f(x,y))$ and apply Inverse Function Theorem.\r\n\\\\\r\n\\\\\r\n{\\bf Partitions of unity:}\r\n$A^{open} \\subseteq {\\mathbb R}^n$ and ${\\cal O}$ and open cover of $A$.\r\n$\\exists \\Phi \\in {\\mathbb C}^{\\infty}$ such that $\\forall \\varphi \\in \\Phi$: \r\n(1) $0 \\leq \\varphi(x) \\leq 1$ and $\\forall x \\in A$,\r\n(2) $\\forall x, \\varphi(x) = 0$ for all but finitely many $\\varphi \\in \\Phi$,\r\n(3) $\\sum_{\\varphi \\in \\Phi} \\varphi(x) =1$.\r\n(4) $\\forall \\varphi \\in \\Phi, \\exists U^{open} \\in {\\cal O}: \\phi(x) = 0$ for $x \\notin \r\n{\\overline U}$\r\nwhere ${\\overline U}$ is some closed subset of $U$.\r\n\\\\\r\n\\\\\r\n{\\bf Direct proof of inverse function theorem:}\r\nSuppose $f$ is a ${\\cal C}'$ mapping\r\n$f: E \\rightarrow {\\mathbb R}^n$, $a \\in E^{open} \\subseteq {\\mathbb R}^n$ with \r\n$f'(a)$ invertible\r\nand $f(a)=b$, then (a) $\\exists U^{open}, V^{open} \\subseteq {\\mathbb R}^n :\r\na \\in U, b \\in V$ such that $f$ is 1-1 on $U$; $f(U)=V$. (b) If $g= f^{-1}$ then\r\n$g \\in {\\cal C}'(V)$.\\\\\r\n\\emph{Proof of a:}\r\nPut $f'(a)=A$ and choose $\\lambda: 2 \\lambda ||A^{-1}||=1$, \r\nset $U= B_{\\lambda}(a) \\subseteq E$: $||f'(x)-A|| < \\lambda, \\forall x \\in U$.  Set\r\n$\\varphi_y(x)= x+ A^{-1} (y-f(x)), \\forall y \\in {\\mathbb R}^n$.\r\n$||\\varphi_{y}'(x) || = || A^{-1} (A-f'(x)) || < {\\frac 1 2}$.\r\n$|| \\varphi_y(x_1)- \\varphi_y(x_2)|| < {\\frac 1 2}, \\forall x_1, x_2 \\in U$ [Equation 1]\r\nby the mean value\r\ntheorem.  $\\varphi_y$ is a contraction map so it has a unique fixed point $x: y=f(x)$.\r\nPut $V=f(U)$ and suppose $y_0 \\in V$, there is a $x_0 \\in U: y_0=f(x_0)$.  Pick\r\n$r>0: {\\overline {B_r(x_0)}} \\subseteq U$.\r\nFix $y: |y-y_0|<\\lambda r$.  For \r\n$x \\in {\\overline {B_r(x_0)}}$,\r\n$| \\varphi(x_0) - x_0 | \\le \r\n|\\varphi(x)-\\varphi(x_0)| +\r\n|\\varphi(x_0)-x_0|< {\\frac 1 2} |x-x_0| + {\\frac r 2} \\le r$ so $\\varphi(x) \\in\r\n{\\overline {B_r(x_0)}}$ and again\r\n$\\varphi_y$ is a contraction map.  Its fixed point $x$ satisfies\r\n$f(x)=y, y \\in \r\n{\\overline {B_r(x_0)}} \r\n\\subseteq f(U)=V$, so $V$ is open.\r\n\\\\\r\n\\emph{Proof of b:}\r\nPick $y \\in V$, $y+k \\in V, \\exists x, x+h \\in U:\r\ny=f(x), y+k= f(x + h)$.  Now $\\varphi(x+h) - \\varphi(x) = h + A^{-1}(f(x+h)-f(x)) =\r\nh- A^{-1}(f(x+h)-f(x))= h- A^{-1}k \\le {\\frac 1 2} h$ by equation 1, so\r\n$||A^{-1}k|| \\ge {\\frac {||h|||} 2}$ and \r\n$ ||h|| \\le 2 ||A^{-1} k||= \\lambda^{-1} ||k||$.  $f'(x)$ has an inverse $T$ and\r\n$g(y+k)-g(y)-Tk=h-Tk= -T[f(x+h)-f(x) -f'(x)h]$ and\r\n${\\frac {||g(y+k)-g(y)-Tk||} {||k||}} ={\\frac {||T||} {\\lambda}} \r\n{\\frac {||f(x+h)-f(x) -f'(x)h||} {||h||}}$. Now $h \\rightarrow 0$ as \r\n$k \\rightarrow 0$.  Since the right hand side goes to $0$, the left hand side goes to\r\n$0$ and we get $g'(y)= T$.\r\n\\\\\r\n\\\\\r\n{\\bf Fubini's Theorem:}\r\n$\\int \\int_{I^2} f(x,y) dy dx = \\int_0^1 (\\int_0^1 f(x,y) dy) dx$.  In\r\na simply connected region of the plane, $S$ for $a \\leq x \\leq b$ bounded by\r\n$b_1(x) \\leq y \\leq b_2(x)$,\r\n$\\int \\int_{S} f(x,y) dy dx = \\int_a^b (\\int_{b_1(x)}^{b_2(x)} f(x,y) dy) dx$.\r\n\\begin{quote}\r\n\\emph{Proof:}  Partition the region in steps of $\\Delta x$ and $\\Delta y$.  Summing over\r\nrectangles in the $y$ direction moving and then moving in the positive $x$ direction gives the result.\r\n\\end{quote}\r\n{\\bf Change of variables:}\r\nLet $A \\subseteq {\\mathbb R}^n$ be an open set, $g:A \\rightarrow R$ \r\ncontinuously differentiable and\r\n$det(g'(x)) \\ne 0, \\forall x \\in A$.  If $f: g(A) \\rightarrow R$ is integrable\r\nthen $\\int_{g(A)} f = \\int_A f \\circ g |\\det(g')|$.\r\n\\begin{quote}\r\n\\emph{Proof:} If $A$ is an $n \\times n$ matrix. $det(A)$ is the volume of the \r\nimage of the unit $n$-cube\r\nunder $A$.  Todo.\r\n\\end{quote}\r\nLet ${\\cal T}^k (V)= \\{ T:V \\rightarrow {\\mathbb R} \\}, V \\subseteq \r\n{\\mathbb R}^n $\r\nwhere $\\forall i$: \r\n$T(v_1, ..., v_{i-1}, u+w, v_{i+1},...,v_k)= T(v_1, ..., v_{i-1}, u, v_{i+1},...,v_k)+\r\nT(v_1, ..., v_{i-1}, w, v_{i+1},...,v_k )$ and\r\n$T(v_1, ..., v_{i-1}, au, v_{i+1},...,v_k)= aT(v_1, ..., v_{i-1}, u, v_{i+1},...,v_k)$.\r\n${\\cal T}^n(V)$ are called the $n-$tensors $V$.\r\nIf $f: V \\rightarrow W$ with $V, W \\subseteq {\\mathbb R}^n$ then \r\n$f^*: {\\cal T}^n (W) \\rightarrow {\\cal T}^n (V)$ by \r\n$f^* (T( v_1 , ... , v_n ))=\r\nT(f(v_1) , ... , f(v_n ))$.\r\nIf $T \\in {\\cal T}^k, S \\in {\\cal T}^s$ define\r\n$T \\otimes S = T(x_1) S(x_2 )$.  ${\\cal T}^1(V)$ is just the dual space $V^*$.\r\nIf $e_1 , ... , e_n$ is a basis for $V$ and\r\n$\\varphi_j \\in V^*$ such that $\\varphi_j (e_i)= \\delta_{ij}$ then\r\nthe set of all $k-fold$ tensor products\r\n$ \\varphi_{i_1} \\otimes  \\varphi_{i_2}\\otimes ... \\otimes \\varphi_{i_k}$ \r\nis a basis ${\\cal T}^k(V)$\r\nwhich thus has dimension $n^k$.  \\\\\r\n\\\\\r\n{\\bf Definition:}\r\nAn \\emph{alternating form} is a multilinear function,\r\n$\\Lambda^k(V)= \\{T \\in {\\cal T}^k(V)\\}$ such that $T(...v...w...)= -T(...w...v...)$.\r\n$\\forall T \\in {\\cal T}^n(V), Alt(T)= {\\frac 1 {k!}} \\sum_{\\sigma} sgn(\\sigma ) T(\r\nv_{\\sigma (1)},..., v_{\\sigma (n))} \r\n\\in \\Lambda^k(V)$. If\r\n$\\omega \\in \\Lambda^k(V)$, $Alt( \\omega) = \\omega$.\r\nIf $\\omega, \\eta \\in \\Lambda^k , \\Lambda^l$, $\\omega \\wedge \\eta =\r\n{\\frac {(l+k)!} {k! l!}} Alt( \\omega \\otimes \\eta )$. $\\wedge$ is multilinear and\r\n$\\omega \\wedge \\eta= (-1)^{kl} \\eta \\wedge \\omega$; $f^*(\\omega \\wedge \\eta) =\r\nf^*(\\omega) \\wedge f^*(\\eta)$. \r\n$\r\n(\\omega \\wedge \\eta ) \\wedge \\theta =\r\n\\omega \\wedge (\\eta \\wedge \\theta)=\r\n{\\frac {(k+l+m)} {k!l!m!}} Alt(\\omega \\otimes \\eta \\otimes \\theta)$.\r\nIf $\\omega = \\sum  w_{{i_1} , ... {i_k}} dx^{i_1} \\wedge ... \\wedge x^{i_k}$ then\r\n$d \\omega = \\sum dw_{{i_1}  ... {i_k}} \\wedge dx^{i_1} \\wedge ... \\wedge x^{i_k}$.\r\n$dim(\\phi_{i_1} \\wedge ... \\wedge \\phi_{i_k}) = {n \\choose k}$.\r\norientation: $[e_1 , ... , e_n]$.\r\n\\emph{Volume elements:}\r\n$w_i= \\sum_j a_{ij} v_j$ then $\\omega (w_1 ,..., w_n)= det(a_{ij})\r\n\\omega (v_1 , ... , v_n )$ for $\\omega \\in \\Lambda^k$.\r\n\\\\\r\n\\\\\r\n{\\bf Forms:} Let $p, v \\in {\\mathbb R}^n$, define the tangent space of ${\\mathbb R}^n$ \r\nat $p$, ${{\\mathbb R}^n}_p$, as the $(p,v)$ with \r\n$(p,v)+(p,w)= (p, v+w)$ and $(p,av)= a(p, v)$.\r\n\\\\\r\n\\\\\r\n{\\bf Vector field:}\r\n$F(p)= F^1 (p) (e_1)p + ... + F^n (p) (e_n)p$ with the usual rules $(F+G)(p)= F(p)+G(p)$\r\n$(f \\cdot g)(p)= f(p) \\cdot g(p)$. $\\nabla= \\sum D_i \\cdot e_i$.\r\n\\\\\r\n\\\\\r\n{\\bf Differentials:}\r\n$\\omega(p) \\in \\Lambda^k ({{\\mathbb R}^n}_p)$:  If $\\varphi_i(p)$ is the dual basis for\r\n$(e_1)_p , (e_2)_p , ..., (e_n)_p$ then\r\n$\\omega (p) = \\sum\r\n\\omega_{{i_1} , ... {i_k}} \\varphi^{i_1} \\wedge ... \\wedge \\varphi^{i_k}$ is\r\na differential form and $df(p)(v_p)=Df(p) (v)$. $df= \\sum_i^n D_i f dx^i$.\r\n\\\\\r\n\\\\\r\n{\\bf Results on forms:} If \r\n$f: {\\mathbb R}^n \\rightarrow {\\mathbb R}^m$,\r\n$f_*: {{\\mathbb R}^n}_p \\rightarrow {{\\mathbb R}^m}_p$ by\r\n$f_* (v_p)= (Df(p)(v))_{f(p)}$.  \r\nThus $f_*: \\Lambda^k({{\\mathbb R}^m}_{f(p)}) \\rightarrow \\Lambda^k({{\\mathbb R}^n}_p)$.  So if\r\n$\\omega$ is a $k-$form on ${\\mathbb R}^m$, $f^* \\omega (p) = f^*(\\omega(p))$ is a $k-$form on ${\\mathbb R}^n$.\r\n$f^* (dx^i) = \\sum_j D_j f^i \\cdot dx^j$, \r\n$f^* (\\omega_1 + \\omega_2 )= f^* (\\omega_1 ) + f^*(\\omega_2 )$, \r\n$f^* (g \\cdot \\omega)= g \\circ f f^* \\omega$ and\r\n$f^* (\\omega + \\eta )= f^* \\omega + f^* \\eta$.\r\nIf $f: {\\mathbb R}^n \\rightarrow R$, $Df(p) \\in \\Lambda^1 ({\\mathbb R}^n)$.\r\n$df(p) (v_p )= Df(p)(v)$.  $f_* (v_p )= (Df(p)(v))_{f(p)}$.\r\n$f: {\\mathbb R}^n \\rightarrow {\\mathbb R}^m$, $f_*: {{\\mathbb R}^n}_p \\rightarrow {{\\mathbb R}^m}_{f(p)}$.\r\n$f_* : \\Lambda^k ({{\\mathbb R}^m}_{f(p)}) \\rightarrow \\Lambda^k({{\\mathbb R}^n}_p )$.\r\n$f^*(dx^i) = \\sum_{j=1}^n D_j f^i dx^j$.  $f^* (g \\circ \\omega ) = g \\circ f \\circ \r\nf^* \\omega$. \\emph{Example:} Suppose\r\n$\\omega= f_1 dx_1 + f_2 dx_2 + f_3 dx_3 $ then\r\n$d\\omega= (\\nabla f_1) \\cdot (dx_1, dx_2, dx_3) \\wedge dx_1 +\r\n(\\nabla \\cdot f_2) (dx_1, dx_2, dx_3) \\wedge dx_2 +\r\n(\\nabla \\cdot f_3) (dx_1, dx_2, dx_3) \\wedge dx_3$.\r\n\\\\\r\n\\\\\r\n{\\bf Definitions:}\r\n$\\omega$ is a \\emph{closed form} if $d \\omega = 0$.\r\n$\\omega$ is an \\emph{exact form} if $\\exists \\eta: d \\eta = \\omega$.\r\nNote that $d^2 \\omega = 0$.\r\n\\\\\r\n\\\\\r\n{\\bf Poincare:}  If $A^{open} \\subseteq {\\mathbb R}^n$ is a star \r\nshaped region then every closed form in $A$ is exact.\r\n$\\partial I^n= \\sum_{i=1}^n \\sum_{\\alpha = 0,1} (-1)^{i+ \\alpha} {I^n}_{(i, \\alpha)}$ where\r\n${I^n}_{(i, \\alpha)}= I^n(x^1 , ... , , x^{i-1}, \\alpha , x^{i+1} , ... x^n )$.\r\nNote that $\\partial^2 I^n = 0$.\r\nIf $A^{open} \\subseteq {\\mathbb R}^n$ and $g: A \\rightarrow {\\mathbb R}^p$ \r\nis differentiable and $g'(x)$ has\r\nrank $p$ whenever $g(x)= 0$ then $g^{-1}(0)$ is an $n-p$ dimensional manifold.\r\nAn $n$-dimensional differentiable manifold is called \\emph{orientable}\r\nif it has a differential form $\\omega$ \r\nof degree $n$ which is nonzero at every point on the manifold.\r\n\\\\\r\n\\\\\r\n{\\bf Lagrange Multipliers:} Maximize \r\n$F({\\vec x})$ subject to\r\n$\\phi_1({\\vec x})=0, \\phi_2({\\vec x})=0, \\ldots , \\phi_m({\\vec x})=0$;\r\nform \r\n$G({\\vec x})= F({\\vec x})+ \\lambda_1 \\phi_1({\\vec x}) + \\lambda_2 \\phi_2({\\vec x}) + \r\n\\ldots + \\lambda_m \\phi_m({\\vec x})$ and  solve\r\n${\\frac {\\partial G} {\\partial x_j}}=0$.  Motivation: all curves, $s(t)$ that satisfy constraints\r\nmust satisfy $\\nabla \\phi_j(s(t)) \\cdot \\dot{s}(t) = 0$.  Similarly, if $s(t)$ is a curve,\r\n${\\frac {df(s(t))} {dt}} = 0 = \\nabla f(s(t)) \\cdot \\dot{s}(t)$.\r\n\\\\\r\n\\\\\r\n{\\bf Vectors:} \r\n(a) If $\\nabla \\times f = 0$, $f= \\nabla g$.\r\n(b) If $\\nabla \\cdot f = 0$, $f= \\nabla \\times g$.\r\n\\begin{quote}\r\n\\emph{Proof of a:}  Put $g(x,y,z)= \\int_{x_0}^x f_1(x,y,z)$,\r\n$\\partial_x g= f_1$ by fundamental theorem of calculus.\r\n$\\partial_y g= \\partial_y \\int_{x_0}^x f_1(x,y,z)=\r\n\\int_{x_0}^x \\partial_y f_1(x,y,z)= \\int_{x_0}^x \\partial_x f_2(x,y,z)= f_2$, etc.\r\n\\\\\r\n\\emph{Proof of b:}  \r\nPut $g_1(x,y,z)= 0$,\r\n$g_2(x,y,z)= \\int_{x_0}^x f_3(t,y,z) dt - \\int_{z_0}^z f_1(x_0, y, u) du$,\r\n$g_3(x,y,z)= - \\int_{x_0}^x f_2(t,y,z) dt$.  Using the fact that $\\nabla \\cdot (f_1, f_2, f_3)=0$,\r\nwe get $\\nabla \\times (g_1, g_2, g_3) = (f_1, f_2, f_3)$.\r\n\\end{quote}\r\n{\\bf Change of variables:} \r\nLet ${\\vec x}= (x_1 , x_2 , \\ldots , x_n)$.\r\nSuppose \r\n${\\cal R} \\subseteq {\\mathbb R}^n$\r\n${\\cal R}' \\subseteq {\\mathbb R}^n$ and the bijection\r\n$f: {\\cal R} \\rightarrow {\\cal R}'$ is continuously differentiable\r\nthen $\\int_{{\\cal R}'} F({\\vec x}) d {\\vec x}\r\n= \\int_{{\\cal R}} F(f({\\vec u})) |J_f({\\vec u})| d {\\vec u}$ where\r\n$J_f({\\vec u}) = | det(f')|$.\r\n\\\\\r\n\\\\\r\n{\\bf Singular cube and boundaries:} Given a singular cube $I^n(x_1 , \\ldots , x_n)$, the boundary of $I^n$\r\nis $\\partial I^n = \\sum_{j=1}^n \\sum_{\\alpha = 0, 1} I^n_{[j, \\alpha]}$ where \r\n$^n_{[j, \\alpha]} = I^n(x_1, \\ldots, x_{j-1}, \\alpha , x_{j}, \\ldots , x_{n-1})$.\r\n\\\\\r\n\\\\\r\n{\\bf Green:} \r\nIf $C$ surrounds ${\\cal R}$, a simply connected\r\nregion of the plane then $\\int_C P dx + Q dy= \\int_{\\cal R}\r\n({\\frac {\\partial Q} {\\partial x}} -\r\n{\\frac {\\partial P} {\\partial y}}) dx dy $.  \r\n\\begin{quote}\r\n\\emph{Proof:} Just apply Fubini with bounding curves.\r\n\\end{quote}\r\n{\\bf Gauss:} If ${\\cal S}$ is a surface enclosing\r\na convex region ${\\cal V}$ and ${\\vec F}$ is continuously differentiable then\r\n$\\int_{\\cal V} \\nabla \\cdot {\\vec F} ({\\vec x}) d{\\vec x}\r\n= \\int_{\\vec S} {\\vec F}({\\vec x}) \\cdot dS$.\r\n\\begin{quote}\r\n\\emph{Proof:} Apply Fubini and the Fundamental Theorem of Calculus.\r\n\\end{quote}\r\n{\\bf Stokes:} If ${\\cal S}$ with boundary\r\n${\\cal C}$ and ${\\vec F}$ is continuously differentiable then\r\n$\\int_{\\cal S} \\nabla \\times {\\vec F} ({\\vec x}) \\cdot dS\r\n= \\int_{\\vec C} {\\vec F}({\\vec x}) \\cdot d{\\vec l}$.\r\n\\begin{quote}\r\n\\emph{Proof:} Apply Fubini and the Fundamental Theorem of Calculus.\r\n\\end{quote}\r\n{\\bf Modern formulation of Stokes:} If $M$ is a compact oriented $k-$dimensional manifold with boundary\r\nand $\\omega$ is a $k-1$ form on $M$ then $\\int_c d \\omega = \\int_{\\partial c} \\omega$.\r\n\\\\\r\n\\\\\r\n{\\bf Fourier:}\r\n$F(x)= {\\frac 1 {\\sqrt {2 \\pi}}} \\int_{-\\infty}^{\\infty} f(u) e^{i u x} du$ and\r\n$f(u)= {\\frac 1 {\\sqrt {2 \\pi}}} \\int_{-\\infty}^{\\infty} F(x) e^{-i u x} dx$.\r\n\\begin{quote}\r\n{\\bf Proof:} First show that if $\\psi(t)$ is bounded and continuous on\r\n$(a,b)$ then $\\textnormal{lim}_{A \\rightarrow \\infty} \\int^b_a \\psi(t) sin(At) dt = 0$.\r\nLook at $I_A= {\\frac 1 {\\pi}} \\int^A_0 d \\tau \\int^{\\infty}_{-\\infty} dt f(t) cos( \\tau (t-x))$.\r\nAlso note that $\\int^{\\infty}_0 {\\frac {sin(At)} {t}} dt = {\\frac {\\pi} {2}}$\r\n\\end{quote}\r\n{\\bf Fourier:} Let $f(x)$ be defined for $-L \\leq x \\leq L$ with $f(x+2L)=f(x)$ then\r\n$f(x)= {\\frac {a_0} 2} + \\sum_{n=1}^{\\infty} (a_n cos({\\frac {n \\pi x} L}) +\r\nb_n sin({\\frac {n \\pi x} L} ))$ with\r\n$a_n= \\int_{-L}^L f(x) cos({\\frac {n \\pi x} L}) dx$ and\r\n$b_n= \\int_{-L}^L f(x) sin({\\frac {n \\pi x} L}) dx$.  Parseval: \r\n$\\int_{-L}^L f(x)^2= {\\frac {{a_0}^2} 2} + \\sum_{n=1}^{\\infty} {a_n}^2 + {b_n}^2$. If\r\n$F(x)= {\\frac 1 {\\sqrt {2 \\pi}}} \\int_{-\\infty}^{\\infty} f(u) e^{i u x} du$,\r\n$\\int_{-\\infty}^{\\infty} F(\\alpha) G(\\alpha) e^{i \\alpha u} du=\r\n\\int_{-\\infty}^{\\infty} f(u) g(x-u) du $.\r\n\\\\\r\n\\\\\r\n{\\bf Calculus of variations:}  Let $I= \\int_{x_1}^{x_2} L(x, y, y') dx$ and $f(x)$ be the\r\nfunction that minimizes $I$ ($\\delta I = 0$), then\r\n$ -{\\frac {d} {dx}} {\\frac {\\partial L} {\\partial y'}} +\r\n{\\frac {\\partial L} {\\partial y}}= 0 $.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\eta(x)$ be a small functional variation with $\\eta(x_1)=\\eta(x_2)=0$.\r\n$\\delta I= \\int_{x_1}^{x_2} L(x, y+ \\eta, y' + \\eta') dx -\r\n\\int_{x_1}^{x_2} L(x, y, y') dx$.\r\n$\\delta I= \\int_{x_1}^{x_2} ({\\frac {\\partial L(x, y, y' + \\eta')}{\\partial y}} \\eta(x)+\r\n{\\frac {\\partial L(x, y, y')}{\\partial y'}} \\eta(x)') dx$.  Integrating by parts and using\r\n$\\eta(x_1)=\\eta(x_2)=0$,\r\n$\\delta I= \\int_{x_1}^{x_2} \r\n({\\frac {\\partial L(x, y, y')}{\\partial y}} -\r\n{\\frac {d} {dx}}{\\frac {\\partial L(x, y, y')}{\\partial y'}}) \\eta(x)\r\ndx$.   Since $\\delta I= 0$ and $\\eta$ was arbitrary,\r\n${\\frac {\\partial L(x, y, y')}{\\partial y}} -\r\n{\\frac {d} {dx}}{\\frac {\\partial L(x, y, y')}{\\partial y'}} = 0$.  This is the \r\nEuler-Lagrange equation.  In physics, $L= KE-PE$.\r\n\\end{quote}\r\n\\subsection{Complex Analysis}\r\n{\\bf Stereographic projection:}\r\nLet $S= \\{ (x_1 , x_2 , x_3 ) \\in {\\mathbb R}^3: x_1^2 + x_2^2 + x_3^2 = 1 \\}$.\r\nConsider the bijective correspondence $S - \\{(0,0,1)\\} \\leftrightarrow {\\mathbb C}$ given by\r\n$(x_1, x_2, x_3) \\mapsto {\\frac {x_1 + i x_2} {1-x_3}}$.  $S$ is called the \\emph{Riemann sphere} and\r\n$(0,0,1) \\mapsto \\infty$.  \r\n$x_1= {\\frac {z + {\\overline z}}{1+|z|^2}}$,\r\n$x_3= {\\frac {z - {\\overline z}}{1+|z|^2}}$\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If all zeros of $P \\in {\\mathbb C}[z]$ lie in a half plane so do the zeros of $P'(z)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If $R(z)= {\\frac {a_0 + a_1 z + a_2 z^2 + \\ldots + a_n z^n}\r\n{b_0 + b_1 z + b_2 z^2 + \\ldots + b_m z^m}\r\n}$, the number of poles is $max(m,n)$ and so is the number of zeros; the common value is called the\r\norder of $R$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If $f(z)= a_0 + a_1 z + a_2 z^2 + \\ldots + a_n z^n + \\ldots $, the \\emph{radius of convergence} is\r\n$R$.  The function is analytic if $|Z| <R$ and\r\n${\\frac 1 R}= \\textnormal{lim sup}_{n \\rightarrow \\infty} |a_n|^{1/n}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  If $a_0 + a_1  + a_2  + \\ldots + a_n + \\ldots $ converges then\r\n$f(z)= a_0 + a_1 z + a_2 z^2 + \\ldots + a_n z^n + \\ldots $ tends to $f(1)$ as $z \\rightarrow 1$ and\r\n${\\frac {|1-z|}{1-|z|}}$ remains unbounded.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  A cross-ratio is real iff all four points lie on a circle or a straight line.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A function is \\emph{analytic} in $\\Omega$ if it is differentiable.\r\nA function that is analytic on all of ${\\mathbb C}$ is called \\emph{entire}.  A function that\r\nis analytic on all of ${\\mathbb C}$ except at a finite number of poles is called \\emph{meromorphic}.\r\nOver ${\\mathbb C}$, the unimodular transformations are of the form $z \\mapsto {\\frac {az+b} {cz+d}}$.\r\n$log(w)= log(|w|)+iarg(w)$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} $Im({\\frac {z-a} {b}})<0$ is a \\emph{half-plane}.  A set is connected if\r\nit cannot be be written as a union of non-empty disjoint open sets.  A space is \\emph{Hausdorff} if\r\n$\\forall x, y$ there are open subsets $O_1, O_2$ such that\r\n$x \\in O_1, y \\notin O_1$ and\r\n$y \\in O_2, x \\notin O_2$.\r\nA \\emph{region} is a connected open set.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}\r\nIf $f(x+iy)= u(x,y)+ i v(x,y)$ is analytic in a region ${\\cal R}$ then\r\n${\\frac {\\partial u} {\\partial x}}= {\\frac {\\partial v} {\\partial y}}$\r\nand ${\\frac {\\partial u} {\\partial y}}= -{\\frac {\\partial v} {\\partial x}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$f'(z) = lim_{\\Delta x \\rightarrow 0} \r\n{\\frac {u(x+\\Delta x, y)-u(x,y)}{\\Delta x}} + i {\\frac {v(x+\\Delta x, y)-v(x,y)}{\\Delta x}}=\r\n{\\frac {\\partial u} {\\partial x}} + i {\\frac {\\partial v} {\\partial x}}$.  Similarly,\r\n$f'(z) = lim_{\\Delta y \\rightarrow 0} \r\n{\\frac {u(x, y + \\Delta y)-u(x,y)}{i \\Delta y}} + \r\ni {\\frac {v(x, y+ \\Delta y)-v(x,y)}{i \\Delta y}}=\r\n-i {\\frac {\\partial u} {\\partial y}} + {\\frac {\\partial v} {\\partial y}}$. \r\n\\end{quote}\r\n{\\bf Cauchy's Theorem:} If $f(z)$ is analytic in a region ${\\cal R}$ and\r\nits boundary is ${\\cal C}$ then $\\int_{\\cal C} f(z) dz = 0$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $f(x+yi)= u(x,y)+ i v(x,y)$.  $\r\n\\int_{\\cal C} (u+vi)(dx+idy)=\r\n\\int_{\\cal C} (udx-vdy) + i(v dx + u dy)$.  By Green's theorem,\r\n$\\int_{\\cal C} (udx-vdy) + i(v dx + u dy)= \\int \\int_{\\cal R}  [\r\n({\\frac {\\partial (-v)} {\\partial x}} - {\\frac {\\partial u} {\\partial y}}) +\r\ni({\\frac {\\partial (u)} {\\partial x}} - {\\frac {\\partial v} {\\partial y}}) ]\r\ndx dy$.  Each parenthesized term is $0$ by the previous theorem.\r\n\\end{quote}\r\n{\\bf Theorem:}  \r\nThe line integral $\\int_{\\gamma} p \\thinspace dx + q \\thinspace dy$ in $\\Omega$ depends only on the\r\nendpoints iff \r\n$\\exists U: p= {\\frac {\\partial U}{\\partial x}}, q= {\\frac {\\partial U}{\\partial y}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$\\leftarrow$: $\\int_{\\gamma(t), a \\leq t \\leq b} p \\cdot dx + q \\cdot dy =\r\n\\int_a^b {\\frac {dU} {dt}} dt = U(\\gamma(b)) - U(\\gamma(a))$.\r\n$\\rightarrow$: Define $U(x,y) = \\int_{(\\alpha, \\beta)}^{(x, y)} p \\cdot dx + q \\cdot dy$,\r\nwhich is well defined since the integral only depends on endpoints.\r\n$p = {\\frac {\\partial U} {\\partial x}}$ and \r\n$q = {\\frac {\\partial U} {\\partial y}}$.\r\n\\end{quote}\r\n{\\bf Theorem:}  \r\nIf $f$ is analytic in and on $R- \\{ a_1 , \\ldots , a_k \\}$, where\r\n$\\textnormal{lim}_{z \\rightarrow a_i} f(z)(z-z_i)= 0$ then $\\int_{\\partial R} f(z) = 0$\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Definition:} \r\nIf $\\gamma$ is a closed curve containing $a$, define  $n(\\gamma, a)= {\\frac 1 {2 \\pi i}} \r\n\\int_{\\gamma} {\\frac {dz}{z-a}}$. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  \r\nIf $f$ is analytic \r\nand $\\gamma$ is a closed curve containing $a$, $f(a)= {\\frac 1 {2 \\pi i n(\\gamma, a)}} \\int_{\\gamma}\r\n{\\frac {f(z)} {z-a}} dz$.\r\n\\begin{quote}\r\n\\emph{Proof:} Put $z = a + re^{i \\theta}$ and perform the integrations with $r$ small.\r\nNow apply Cauchy's theorem in the annular region when $r$ is large.\r\n\\end{quote}\r\n{\\bf Theorem:}  \r\nIf $\\varphi$ is continuous on $\\gamma$ then $F_n(z)=\r\n\\int_{\\gamma} {\\frac {\\varphi(w)} {(w-z)^n}} dw$ is analytic and $F_n'(z)= n F_{n+1}(z)$.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $f(z)$ is analytic inside and on a circle ${\\cal C}$ of\r\nradius $r$ and center at $z=a$ then $f(a)= {\\frac 1 {2 \\pi}} \\int_0^{2 \\pi} \r\nf(a+ r e^{i \\theta}) d \\theta$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBecause $f$ is analytic,\r\n$ {\\frac 1 {2 \\pi}} \\int_0^{2 \\pi} f(a+r_1 e^{i \\theta}) d \\theta\r\n= {\\frac 1 {2 \\pi}} \\int_0^{2 \\pi} f(a+r_2 e^{i \\theta}) d \\theta$\r\nif $r_1, r_2>0$; so by continuity,\r\n$ {\\frac 1 {2 \\pi}} \\int_0^{2 \\pi} f(a+r_1 e^{i \\theta}) d \\theta=\r\nlim_{r \\rightarrow 0} {\\frac 1 {2 \\pi}} \\int_0^{2 \\pi} f(a+r_1 e^{i \\theta}) d \\theta =\r\nf(a) $.\r\n\\end{quote}\r\n{\\bf Cauchy Integral Formula:}\r\nIf $f(z)$ is analytic inside and on a closed curve ${\\cal C}$ and $a$ is any\r\npoint inside ${\\cal C}$ \r\nthen  $f^{(n)}(a)= {\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f(z)} {(z-a)^{n+1}}} dz$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy induction.  For $n=0$, put $z= a+r e^{i \\theta}$ then\r\n${\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f(z)} {(z-a)}} dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{0}^{2\\pi} i f(a+re^{i \\theta}) d \\theta = f(a)$.  Now\r\nby the $n=0$ result, ${\\frac {g(a+h)-g(a)} {h}}= \r\n{\\frac 1 {2 \\pi i h}} \\int_{\\cal C}\r\n({\\frac {g(z)} {(z-a-h)}}- {\\frac {g(z)} {(z-a)}}) dz= \r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {g(z)} {(z-a)(z-a-h)}} dz$ provided ${\\cal C}$\r\nencloses both $a$ and $a+h$.  Taking the limit as $h \\rightarrow 0$, we get\r\n$g'(a)= {\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {g(z)} {(z-a)^2}} dz$ \r\nand the result follows by induction.\r\n\\end{quote}\r\n{\\bf Morrera's Theorem:}\r\nIf $f(z)$ is continuous in a simply connected region ${\\cal R}$ and\r\n$\\int_{\\cal C} f(z) dz = 0$ around every simple closed curve\r\n${\\cal C}$ in ${\\cal R}$, then $f(z)$ is analytic in ${\\cal R}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy contunuity, the integral exists and by Cauchy's integral formula, the derivative exists.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $f(z)$ is analytic inside and on a circle ${\\cal C}$ of\r\nradius $r$ and center at $z=a$ then $|f^{(n)}(a)| \\leq {\\frac {M} {r^n}}$ where\r\n$|f(z)| \\leq M$ on ${\\cal C}$ in ${\\cal R}$.  If an analytic function is bounded in the\r\nplane it is constant.  If $a_n$ is the coefficient of $z^n$ in the Taylor expansion of\r\n$f(z)$ about $a$, and $f$ is bounded as above, \r\n$|a_n|= |{\\frac {f^{(n)}(a)} {n!}}| \\leq {\\frac {M n!} {r^n}}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet ${\\cal C}(r)$ be a circle of radius $r$ then by Cauchy's integral formula,\r\n$f^{(n)}(a)= \r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} {\\frac {f(z)} {(z-a)^{n+1}}} dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{0}^{2 \\pi} \r\n{\\frac {f(a+re^{i \\theta})} {(re^{i \\theta})^{n+1}}} r e^{i \\theta} d \\theta$.\r\nSo $|f^{(n)}(a)|= {\\frac {|M|} {r^n}}$.  The two subsequent statements follow easily.\r\n\\end{quote}\r\n{\\bf Theorem:}\r\nIf $f(z)$ is analytic inside and on a closed curve ${\\cal C}$ except at\r\na finite number of pole\r\nthen  ${\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f'(z)} {f(z)}} =\r\nN-P$ where $N$ and $P$ are, respectively, the number of zeros and poles of\r\n$f(z)$ inside ${\\cal C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $f(z)= p(z) g(z)$ so $f'(z)= p'(z)g(z)+p(z)g'(z)$.  Thus\r\n$\\int_{\\cal C} {\\frac {f'(z)} {f(z)}} dz= \r\n\\int_{\\cal C} {\\frac {p'(z)} {p(z)}} + {\\frac {g'(z)} {g(z)}} dz $.  So by induction,\r\nit suffices to consider $p(z)= (z-a)$ and $p(z)= (z-a)^{-1}$.  In the first case, \r\nsetting $z=re^{i \\theta}$\r\n$\\int_{\\cal C} {\\frac {p'(z)} {p(z)}} dz= \r\n\\int_{\\cal C} {\\frac {1} {(z-a)}} dz= {\\frac 1 {2 \\pi i}} \\int_0^{2 \\pi} i d \\theta = 1$\r\nand in the second case, again setting $z=re^{i \\theta}$\r\n$\\int_{\\cal C} {\\frac {p'(z)} {p(z)}} dz= \r\n\\int_{\\cal C} {\\frac {-1} {(z-a)}} dz= {\\frac {-1} {2 \\pi i}} \\int_0^{2 \\pi} i d \\theta = -1$.\r\n\\end{quote}\r\n{\\bf Theorem:} If $f(z)$ is analytic in and on a ball centered at $a$ of radius $r$, $B_r(a)$, then\r\n$|f^{(n)}(a)| \\leq {\\frac {M n!} {r^n}}$, where  $|f(z)| \\leq M, z \\in B_r(a)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nUse the Cauchy integral formula.\r\n\\end{quote}\r\n{\\bf Theorem:} If $f(z)$ is bounded and analytic in the plane, $f(z)$ is a constant.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$f(b) - f(a) = {\\frac {b-a} {2 \\pi i}} \\int_{B_r(a)} {\\frac {f(z)} {(z-a)(z-b)}} dz$.\r\nSo $|f(b) - f(a)| \\leq {\\frac {2|b-a| M} {r}}$; let $r \\rightarrow \\infty$.\r\n\\end{quote}\r\n{\\bf Rouche's Theorem:} If $f(z), g(z)$ are analytic \r\nin and on a simple closed curve $C$\r\nand $|f(z)|>|g(z)|$ on $C$ then\r\n$f(z)$ and $f(z)+g(z)$ have the same number of zeros in $C$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $g(z)= F(z)f(z)$ so $|F(z)|<1$.\r\n$\\Delta N= \r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f'(z)+g'(z)} {f(z)+g(z)}} dz -\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f'(z)} {f(z)}} dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f'(z)+F'(z)f(z)+F(z)f'(z))} {f(z)(1+F(z))}} dz-\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {f'(z)} {f(z)}} dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {F'(z)} {(1+F(z))}} dz$.  Since\r\n$|F(z)|<1$, $(1+F(z))(1-F(z)+F^2(z)-F^3(z)+ \\ldots $,\r\n$\\Delta N= \r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} {\\frac {F'(z)} {(1+F(z))}} dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} F'(z) (1-F(z)+F^2(z)- \\ldots) dz=\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} F'(z)  dz-\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} F'(z) F(z) dz+\r\n{\\frac 1 {2 \\pi i}} \\int_{\\cal C} F'(z) F^2(z) dz- \\ldots\r\n$ and each of these integrals is $0$.  Thus $\\Delta N= 0$ and the theorem holds by\r\nthe previous result.\r\n\\end{quote}\r\n{\\bf Definition:}  A complex function, $f(z)$, is \\emph{holomorphic} if it is\r\ndifferentiable everywhere on ${\\mathbb C}$.\r\nA complex function, $f(z)$, has a \\emph{removeable singularity} at\r\n$a$ if $f(a)$ is undefined but there is a choice $b=f(a)$ which makes $f$ holomorphic.\r\nA complex function, $f(z)$, has an \\emph{essential singularity} at $a$ if $f(a)$ is neither\r\na pole nor a removeable singularity.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem:}  \r\nAn analytic function comes arbitrarily close to any value in ${\\mathbb C}$ in every neighborhood of an\r\nessential singularity.\r\n\\begin{quote}\r\n\\end{quote}\r\n{\\bf Maximum Modulus Theorem:} If $f(z)$ is analytic inside and on a region enclosed by a curve\r\n${\\cal C}$ then the point with maximum modulus lies on ${\\cal C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose $|f|$ achieved its maximum at $a$ inside ${\\cal C}$ and $f(a) = M$. If $f$ is not\r\nconstant, we can choose a $B_r(a)$ for which $|f(x)| < M$ for some $x \\in B_r(a)$.\r\n${\\frac 1 {2 \\pi i}} \\int_{B_r(a)} {\\frac {f(z)}{z-a}} dz = f(a) = M$\r\n${\\frac 1 {2 \\pi}} |\\int_{B_r(a)} {\\frac {f(z)}{z-a}} dz| = |f(a)| = M$. So,\r\n${\\frac 1 {2 \\pi}} \\int_{0}^{2 \\pi} |{\\frac {f(z)}{z-a}} dz| \\geq  M$. This is impossible,\r\nsince $|f(x)| < M$ for some $x$.\r\n\\end{quote}\r\n{\\bf Laurent's Theorem:} If $f(z)$ is analytic inside an annular region (but\r\nnot necessarily in the whole disk) ${\\cal A} = \\{ r \\leq {z-a} \\leq R \\}$ \r\nthen  $f(z)= \\sum_{n= - \\infty}^{\\infty} c_n (z-a)^n$ and\r\n$c_n= {\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(z)}{(z-a)^{n+1}}} dz, n \\geq 0$ while\r\n$c_n= {\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} f(z) (z-a)^{n-1} dz, n < 0$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy Cauchy,\r\n$f(z)= {\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)}{w-z)}} dz -\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} {\\frac {f(w)}{w-z)}} dz$.\r\n${\\frac 1 {w-z}}=\r\n{\\frac 1 {w-a} } +\r\n{\\frac {(z-a)} {(w-a)^2}}+\r\n{\\frac {(z-a)^2} {(w-a)^3}}+ \\ldots +\r\n{\\frac {(z-a)^n} {(w-a)^{n}}} {\\frac 1 {w-z}}$ and\r\n$-{\\frac 1 {w-z}}=\r\n{\\frac 1 {z-a} } (1 +\r\n{\\frac {(w-a)} {(z-a)}}+\r\n({\\frac {(w-a)} {(z-a)}})^2+ \\ldots +\r\n({\\frac {(w-a)} {(z-a)}})^{n-1})+ \r\n({\\frac {(w-a)} {(z-a)}})^{n} {\\frac 1 {z-w}}$.  Further,\r\n$|{\\frac {w-a}{z-a}}|= \\kappa < 1$.  So\r\n$\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)} {w-z}} dw=\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)} {w-a}} dw +\r\n{\\frac {z-a} {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)} {w-a}} dw +\r\n{\\frac {(z-a)^2} {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)} {(w-a)^2}} dw + \\ldots +\r\n{\\frac {(z-a)^n} {2 \\pi i}} \\int_{{\\cal C}(R)} {\\frac {f(w)} {(w-a)^n}} dw + U_n$  where\r\n$U_n= {\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(R)} ({\\frac {z-a} {w-a}})^n{\\frac {f(w)} {(w-z)}} dw$\r\nand\r\n$\r\n-{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} {\\frac {f(w)} {w-z}} dw=\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} {\\frac {f(w)} {z-a}} dw +\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} f(w) {\\frac {(w-a)} {(z-a)^2}} +\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} f(w) {\\frac {(w-a)^2} {(z-a)^3}} + \\ldots +\r\n{\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} f(w) {\\frac {(w-a)^{n-1}} {(z-a)^n}} + \\ldots +\r\n+ V_n$  \r\nwhere\r\n$V_n= {\\frac 1 {2 \\pi i}} \\int_{{\\cal C}(r)} ({\\frac {w-a} {z-a}})^n{\\frac {f(w)} {(z-w)}} dw$.\r\n$|U_n| \\leq  {\\frac {\\kappa^n M R} {R- |z-a|}}$ and\r\n$|V_n| \\leq  {\\frac {\\kappa^n M r} {|z-a|-r}}$.\r\n\\end{quote}\r\n{\\bf Residue Theorem:}\r\n$\\int_{\\cal C} f(z) dz = 2 \\pi i (a_{-1} + b_{-1} + ... )$.\r\n\\begin{quote}\r\n\\end{quote}\r\n", "meta": {"hexsha": "259ab6e7623d9a13cd24ec737059d8e9e084cb9d", "size": 68948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "science/math4.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/math4.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/math4.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.7819494585, "max_line_length": 149, "alphanum_fraction": 0.5665719093, "num_tokens": 28183, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802440252812, "lm_q2_score": 0.828938806208442, "lm_q1q2_score": 0.761363917008355}}
{"text": "% http://www.seas.ucla.edu/~vandenbe/236C/lectures/gradient.pdf\n\n\\section{Optimization Methods}\n\nIn order to explain the \\emph{convergence rates} of the following optimization methods, we need to introduce some preliminary definitions about \\emph{convexity} and the \\emph{Lipschitz continuity} of a function~\\cite{boyd2004convex}.\n\n\\begin{definition}[Convexity] \\label{def:convexity}\n\t\\hfill\n\t\\begin{enumerate}[(i)]\n\t\t\\item We say that a function $f: \\Re^m \\rightarrow \\Re$ is convex if: \n\t\t$$ \n\t\t\t(\\lambda x + (1 - \\lambda) y ) \\leq \\lambda f(x) + (1 - \\lambda) f(y) \\ \\forall \\ x, y \\in \\Re^m, \\lambda \\in [0,1] \n\t\t$$\n\t\t\\item We say that a differentiable function $f: \\Re^m \\rightarrow \\Re$ is convex if: \n\t\t$$ \n\t\t\tf(y) \\geq f(x) + \\langle \\nabla f(x), y - x \\rangle \\ \\forall \\ x, y \\in \\Re^m \n\t\t$$\n\t\t\\item We say that a twice differentiable function $f: \\Re^m \\rightarrow \\Re$ is convex iff: \n\t\t$$ \n\t\t\t\\nabla^2 f(x) \\succeq 0 \\ \\forall \\ x \\in \\Re^m \n\t\t$$ i.e., the Hessian matix is \\emph{positive semidefinite}.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Strict Convexity] \\label{def:strict_convexity}\n\t\\hfill\n\t\\begin{enumerate}[(i)]\n\t\t\\item We say that a function $f: \\Re^m \\rightarrow \\Re$ is strictly convex if: \n\t\t$$ \n\t\t\t(\\lambda x + (1 - \\lambda) y ) < \\lambda f(x) + (1 - \\lambda) f(y) \\ \\forall \\ x, y \\in \\Re^m, x \\neq y, \\lambda \\in (0,1) \n\t\t$$\n\t\t\\item We say that a differentiable function $f: \\Re^m \\rightarrow \\Re$ is strictly convex if: \n\t\t$$ \n\t\t\tf(y) > f(x) + \\langle \\nabla f(x), y - x \\rangle \\ \\forall \\ x, y \\in \\Re^m, x \\neq y\n\t\t$$\n\t\t\\item We say that a twice differentiable function $f: \\Re^m \\rightarrow \\Re$ is strictly convex iff: \n\t\t$$ \n\t\t\t\\nabla^2 f(x) \\succ 0 \\ \\forall \\ x \\in \\Re^m \n\t\t$$ i.e., the Hessian matix is \\emph{positive definite}.\n\t\\end{enumerate}\n\\end{definition}\n\n% http://xingyuzhou.org/blog/notes/strong-convexity\n\n\\begin{definition}[Strong Convexity] \\label{def:strong_convexity}\nWe say that a function $f: \\Re^m \\rightarrow \\Re$ is $\\mu$-strongly convex if the function:\n$$\ng(x) = f(x) - \\frac{\\mu}{2} \\| x \\|^2\n$$\nis convex for any $\\mu > 0$. \nIf $f$ is differentiable this is also equivalent to:\n$$\nf(y) \\geq f(x) + \\langle \\nabla f(x), y - x \\rangle + \\frac{\\mu}{2} \\| y - x \\|^2 \\ \\forall \\ x, y \\in \\Re^m\n$$\nand, if $f$ is a twice differentiable function then $f$ is $\\mu$-strongly convex iff:\n$$\n\\nabla^2 g(x) \\succ 0 \\ \\forall \\ x \\in \\Re^m\n$$\ni.e., the Hessian matix is \\emph{positive definite}, which is:\n$$\n\\nabla^2 f(x) \\succeq \\mu I \\ \\forall \\ x \\in \\Re^m\n$$\ni.e., all the eigenvalues of the Hessian matrix are lowerbounded by $\\mu I$.\n\\end{definition}\n\n% https://angms.science/doc/CVX/CVX_alphabeta.pdf\n% https://xingyuzhou.org/blog/notes/Lipschitz-gradient\n\n\\begin{definition}[$L_f$-Lipschitz continuity] \\label{def:l_f_lipschitz_continuity}\nWe say that a function $f: \\Re^m \\rightarrow \\Re$ is $L_f$-Lipschitz continuous if:\n$$\n| f(x) - f(y) | \\leq L_f \\| x - y \\| \\ \\forall \\ x, y \\in \\Re^m\n$$\nmeaning that $f$ is bounded above and below by a linear function.\n\nIntuitively, $L$ is a measure of how fast the function can change.\n\nFinally, we say that a function $f: \\Re^m \\rightarrow \\Re$ is locally $L_f$-Lipschitz continuous if for every $x$ in $\\Re^m$ there exists a neighborhood $U$ of $x$ such that $f$ restricted to $U$ is $L_f$-Lipschitz continuous.\nEvery convex function is locally $L_f$-Lipschitz continuous.\n\\end{definition}\n\n\\begin{definition}[L-Lipschitz continuity] \\label{def:l_lipschitz_continuity}\nWe say that a function $f: \\Re^m \\rightarrow \\Re$ is L-Lipschitz gradient continuous if $f$ is differentiable and:\n$$\n\\| \\nabla f(x) - \\nabla f(y) \\| \\leq L \\| x - y \\| \\ \\forall \\ x, y \\in \\Re^m\n$$\nthat is equivalent to:\n$$\n| f(y) - f(x) - \\langle \\nabla f(x), y - x \\rangle | \\leq \\frac{L}{2} \\| y - x \\|^2 \\ \\forall \\ x, y \\in \\Re^m\n$$\nmeaning that $f$ is bounded above and below by a quadratic function.\n\nAlso, if $f$ is a twice differentiable function this is equivalent to:\n$$\n\\nabla^2 f(x) \\preceq L I \\ \\forall \\ x \\in \\Re^m\n$$\ni.e., all the eigenvalues of the Hessian matrix are upperbounded by $L$.\n\nNote that if $f$ is a $\\mu$-strongly convex function, we give the following Hessian bounds:\n$$\n0 \\prec \\mu I \\preceq \\nabla^2 f(x) \\preceq L I \\ \\forall \\ x \\in \\Re^m\n$$\ni.e., all the eigenvalues of the Hessian matrix are lowerbounded by $\\mu I$ and upperbounded by $L$.\n\nFinally, we say that a function $f: \\Re^m \\rightarrow \\Re$ is locally L-Lipschitz gradient continuous if for every $x$ in $\\Re^m$ there exists a neighborhood $U$ of $x$ such that $f$ restricted to $U$ is L-Lipschitz gradient continuous.\n\\end{definition}\n\n\\begin{definition}[Subgradient] \\label{def:subgradient}\nGiven a function $f: \\Re^m \\rightarrow \\Re$ and $x \\in \\Re^m$, we define a subgradient $g \\in \\Re^m$ at $x$ to be any point satisfying:\n$$\n\tf(y) \\geq f(x) + \\langle g, y - x \\rangle \\ \\forall \\ y \\in \\Re^m\n$$\nSubgradients always exist for convex function.\n\\end{definition}\n\n% https://www-ljk.imag.fr/membres/Anatoli.Iouditski/cours/convex/chapitre_3.pdf\n\n\\begin{theorem}[\\href{http://web.mit.edu/dimitrib/www/Convex_Theory_Entire_Book.pdf\\#page=196}{$L_f$-Lipschitz continuity for convex functions}] \\label{def:l_f_lipschitz_convex}\nLet $f: \\Re^m \\rightarrow \\Re$ be a convex function and let $K$ be a closed and bounded set contained in the relative interior of the domain of $f$, i.e., $K \\subset \\Re^m$. Then $f$ is $L_f$-Lipschitz continuous on $K$, i.e.,:\n$$\n| f(x) - f(y) | \\leq L_f \\| x - y \\| \\ \\forall \\ x, y \\in K\n$$\nIn particular, $f$ is bounded on $K$.\n\\end{theorem}\n\n% http://www.athenasc.com/convexsol4.pdf#page=7\n\n\\begin{proof}\nLet $x$ and $y$ be any two points in the set $K$. Since $\\partial f(x)$ is nonempty, by using the subgradient inequality~\\ref{def:subgradient}, it follows that:\n$$\n\tf(y) \\geq f(x) + \\langle g, y - x \\rangle \\ \\forall \\ g \\in \\partial f(x)\n$$\nimplying that:\n$$\n\tf(x) - f(y) \\leq \\|g\\| \\|x-y\\| \\ \\forall \\ g \\in \\partial f(x)\n$$\nBy definition, the set $\\cup_{x \\in K} \\partial f(x)$ is nonempty and bounded, so that for some constant $L > 0$, we have:\n$$\n\t\\|g\\| \\leq L_f \\ \\ \\ \\forall g \\in \\partial f(x) \\ \\ \\ \\forall x \\in K\n$$\nand therefore:\n$$\n\tf(x) - f(y) \\leq L_f \\|x-y\\|\n$$\nBy exchanging the roles of $x$ ad $y$, we similarly obtain:\n$$\n\tf(y) - f(x) \\leq L_f \\|x-y\\|\n$$\nand by combining the preceding two relations, we see that:\n$$\n\t|f(x) - f(y)| \\leq L_f \\|x-y\\|\n$$\nshowing that $f$ is $L_f$-Lipschitz continuous over $K$.\n\\end{proof}\n\nNote that this proof shows how to determine the Lipschitz constant $L_f$: it is the maximum subgradient norm, over all subgradients in $\\cup_{x \\in K} \\partial f(x)$.\n\nStrong convexity and L-Lipschitz continuity are related by Fenchel duality according to the following theorem, which proof is given in~\\cite{zhou2018fenchel}.\n\n% https://arxiv.org/pdf/1803.06573.pdf\n% https://www.stat.purdue.edu/~vishy/introml/notes/Optimization.pdf#page=8\n\n\\begin{theorem}[\\href{https://arxiv.org/pdf/1803.06573.pdf}{$\\mu$-strong convexity and L-Lipschitz continuity for convex functions}]\\label{def:strong_cvx_l_lipschitz_convex}\nA function $f$ and its Fenchel dual $f^*$ satisfy the following assertions:\n\\begin{enumerate}[(i)]\n\t\t\\item if $f$ is $\\mu$-strongly convex, then $f^*$ is $\\displaystyle \\frac{1}{\\mu}$-Lipschitz continuous.\n\t\t\\item if $f$ is convex and L-Lipschitz continuous, then $f^*$ is $\\displaystyle \\frac{1}{L}$-strongly convex.\n\\end{enumerate}\n\\end{theorem}\n\nNote that since $f$ is convex and its epigraph is a closed convex set, $f^* = f$.\n\n\\pagebreak\n\n\\subsection{Gradient Descent for primal formulations}\n\nThe Gradient Descent algorithm is the simplest \\emph{first-order optimization} method that exploits the orthogonality of the gradient wrt the level sets to take a descent direction. In particular, it performs the following iterations:\n\n\\begin{algorithm}[H]\n\t\\caption{Gradient Descent}\n\t\\label{alg:gd}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Function{GradientDescent}{$f,\\alpha$}\n\t\t\t\\State Initialize weight vector $x_0$\n\t\t\t\\State $t = 0$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $x_{t+1} = x_t - \\alpha \\partial f(x_t)$ \\Comment if $f$ is differentiable then $\\partial f(x_t) = \\nabla f(x_t)$\n\t\t\t\t\\State $t = t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nGradient Descent is based on full gradients, since at each iteration we compute the average gradient on the whole dataset:\n$$\n\\partial f(x) = \\frac{1}{n} \\sum_{i=1}^n \\partial f_i(x)\n$$\nThe downside is that every step is very computationally expensive, $\\mathcal{O}(nm)$ per iteration, where $n$ is the number of samples in our dataset and $m$ is the number of dimensions.\n\nSince \\emph{Gradient Descent} becomes impractical when dealing with large datasets we introduce a stochastic version, called \\emph{Stochastic Gradient Descent}, which does not use the whole set of examples to compute the gradient at every step. By doing so, we can reduce computation all the way down to $\\mathcal{O}(m)$ per iteration.\n\n\\begin{algorithm}[H]\n\t\\caption{Stochastic Gradient Descent}\n\t\\label{alg:sgd}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Batch size $k$}\n\t\t\\Function{StochasticGradientDescent}{$f,\\alpha,k$}\n\t\t\t\\State Initialize weight vector $x_0$\n\t\t\t\\State $t \\gets 0$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State Sample $(i_1,\\dots,i_k) \\sim \\mathcal{U}^k(1,\\dots,n)$ \n\t\t\t\t\\State $\\displaystyle x_{t+1} \\gets x_t - \\alpha \\frac{1}{k} \\sum_{j=1}^k \\partial f_{i_j}(x_t)$ \\Comment if $f$ is differentiable then $\\partial f_{i_j}(x_t) = \\nabla f_{i_j}(x_t)$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nNote that in expectation, we converge like GD, since $\\displaystyle \\mathbb{E}_{i \\sim \\mathcal{U}(1,\\dots,n)}[\\partial f_i(x_t)] = \\partial f(x_t)$, therefore, the expected iterate of SGD converges to the optimum.\n\n% https://erwanscornet.github.io/teaching/Optimization.pdf\n% https://www.math.univ-toulouse.fr/~agarivie/sites/default/files/8_optimization.pdf\n\nNow, consider the SGD algorithm introduced previously but where each iteration is projected into the ball $\\mathcal{B}(0, R)$ with radius $R > 0$ fixed. So, the following lower bounds on convergence rates are given.\n\n\\begin{theorem}[\\href{https://erwanscornet.github.io/teaching/Optimization.pdf\\#page=62}{Stochastic Gradient Descent convergence for convex functions}] \\label{thm:cvx_sgd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous convex function and assume that exists $b > 0$ satisfying:\n$$\n\\| f_i(x) \\| \\leq b \\ \\forall \\ x \\in \\mathcal{B}(0, R)\n$$\nBesides, assume that all minima of $f$ belong to $\\mathcal{B}(0, R)$. Then the Stochastic Gradient Descent with step size $\\displaystyle \\alpha = \\frac{2R}{b\\sqrt{k}}$ satisfies:\n$$\n\\mathbb{E}\\Bigg[f\\Bigg(\\frac{1}{k} \\sum_{t=1}^k x_t\\Bigg)\\Bigg] - f(x^*) \\leq \\frac{3Rb}{\\sqrt{k}}\n$$\n\\end{theorem}\n\n\\begin{theorem}[\\href{https://erwanscornet.github.io/teaching/Optimization.pdf\\#page=63}{Stochastic Gradient Descent convergence for strongly convex functions}] \\label{thm:str_cvx_sgd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous, $\\mu$-strongly convex function and assume that exists $b > 0$ satisfying:\n$$\n\\| f_i(x) \\| \\leq b \\ \\forall \\ x \\in \\mathcal{B}(0, R)\n$$\nBesides, assume that all minima of $f$ belong to $\\mathcal{B}(0, R)$. Then the Stochastic Gradient Descent with step size $\\displaystyle \\alpha = \\frac{2}{\\mu(k+1)}$ satisfies:\n$$\n\\mathbb{E}\\Bigg[f\\Bigg(\\frac{2}{k(k+1)} \\sum_{t=1}^k t x_{t-1}\\Bigg)\\Bigg] - f(x^*) \\leq \\frac{2b^2}{\\mu(k+1)}\n$$\n\\end{theorem}\n\nSGD’s \\emph{convergence rate} for L-Lipschitz continuous convex functions is $\\displaystyle \\mathcal{O}\\bigg(\\frac{1}{\\sqrt{t}}\\bigg)$ and $\\displaystyle \\mathcal{O}\\bigg(\\frac{1}{t}\\bigg)$ for L-Lipschitz continuous and strongly convex functions. More iterations are needed to reach the same accuracy as GD, but the iterations are far cheaper.\n\n% http://www.princeton.edu/~yc5/ele522_optimization/lectures/subgradient_methods.pdf\n\n\\subsubsection{Nonsmooth}\n\nFirst, consider a nonsmooth, i.e., nondifferentiable, convex function. So, the following lower bounds on convergence rates are given.\n\n\\begin{theorem}[\\href{http://www.princeton.edu/~yc5/ele522_optimization/lectures/subgradient_methods.pdf\\#page=34}{Subgradient Descent convergence for convex functions with Polyak's stepsize}] \\label{thm:cvx_polyak_subgd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a $L_f$-Lipschitz continuous convex function. Then the Subgradient Descent with Polyak's step size $\\displaystyle \\alpha_t = \\frac{f(x_t) - f(x^*)}{\\| g_t \\|^2}$ satisfies:\n$$\nf(x_t) - f(x^*) \\leq \\frac{L \\| x_0 - x^* \\|^2}{\\sqrt{t+1}}\n$$\n\\end{theorem}\n\nUnfortunately, Polyak’s stepsize rule requires knowledge of $f(x^*)$, which is often unknown a priori, so we might often need simpler rule for setting stepsizes.\n\n\\begin{theorem}[\\href{http://www.princeton.edu/~yc5/ele522_optimization/lectures/subgradient_methods.pdf\\#page=39}{Subgradient Descent convergence for convex functions}] \\label{thm:cvx_subgd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a $L_f$-Lipschitz continuous convex function. Then the Subgradient Descent with step size $\\displaystyle \\alpha_t = \\frac{1}{\\sqrt{t}}$ satisfies:\n$$\nf(x_t) - f(x^*) \\leq \\frac{\\| x_0 - x^* \\|^2 + L^2 \\log t}{\\sqrt{t}}\n$$\n\\end{theorem}\n\n\\begin{theorem}[\\href{http://www.princeton.edu/~yc5/ele522_optimization/lectures/subgradient_methods.pdf\\#page=41}{Subgradient Descent convergence for strongly convex functions}] \\label{thm:str_cvx_subgd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a $L_f$-Lipschitz continuous and $\\mu$-strongly convex function. Then the Subgradient Descent with step size $\\displaystyle \\alpha_t = \\frac{2}{\\mu(t+1)}$ satisfies:\n$$\nf(x_t) - f(x^*) \\leq \\frac{2L^2}{\\mu} \\frac{1}{t+1}\n$$\n\\end{theorem}\n\nIn summary, the following \\emph{convergence rates} and \\emph{iterations complexities} are given:\n\n\\begin{table}[H]\n\\centering\n\\caption{Subgradient Descent convergence rates and iterations complexities}\n\\label{subgradient_rates}\n\\begin{tabular}{lrrr}\n\\toprule\n\t& stepsize rule & convergence rate & iteration complexity \\\\\n \t& \t\t& \t\t& \t\t\\\\\n\\midrule\nconvex and $L_f$-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{\\sqrt{t}}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{\\sqrt{t}}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{\\epsilon^2}\\Bigg)$ \\\\\nstrongly convex and $L_f$-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{t}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{t}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{\\epsilon}\\Bigg)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\nAmong algorithms that only use subgradient, these \\emph{convergence rates} cannot be futher improved.\n\n% http://www.princeton.edu/~yc5/ele522_optimization/lectures/grad_descent_unconstrained.pdf\n% http://www.stat.cmu.edu/~larry/=sml/optrates.pdf\n\n\\subsubsection{Smooth}\n\nNow, consider a smooth, i.e., differentiable, convex function. So, the following lower bounds on convergence rates are given.\n\n\\begin{theorem}[\\href{https://erwanscornet.github.io/teaching/Optimization.pdf\\#page=44}{Gradient Descent convergence for convex functions}] \\label{thm:cvx_gd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous convex function. Then the Gradient Descent with step size $\\alpha = 1/L$ satisfies:\n$$\nf(x_t) - f(x^*) \\leq \\frac{L \\| x_0 - x^* \\|^2}{2 t}\n$$\n\\end{theorem}\n\n\\begin{theorem}[\\href{https://erwanscornet.github.io/teaching/Optimization.pdf\\#page=47}{Gradient Descent convergence for strongly convex functions}] \\label{thm:str_cvx_gd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous and $\\mu$-strongly convex function. Then the Gradient Descent with step size $\\alpha = 1/L$ satisfies:\n$$\n\\begin{aligned}\n\tf(x_t) - f(x^*) \\leq & \\bigg(1 - \\frac{\\mu}{L}\\bigg)^t \\| f(x_0) - f(x^*) \\|^2 \\\\\n\t\t\t\t\t\t= & \\bigg(1 - \\frac{1}{\\kappa}\\bigg)^t \\| f(x_0) - f(x^*) \\|^2\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\n\\begin{theorem}[\\href{https://angms.science/doc/CVX/CVX_HBM.pdf\\#page=5}{Gradient Descent convergence for convex quadratic functions}] \\label{thm:quad_gd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous and $\\mu$-strongly convex quadratic function. Then the Gradient Descent with step size $\\alpha = \\displaystyle \\frac{2}{L + \\mu}$ and momentum $\\beta = \\max{\\{|1 - \\alpha \\mu|, |1 - \\alpha L|\\}}$ satisfies:\n$$\n\\begin{aligned}\n\t\\| x_t - x^* \\| = \\bigg(\\frac{\\kappa-1}{\\kappa+1}\\bigg)^t \\| x_0 - x^* \\|\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\nIn summary, the following \\emph{convergence rates} and \\emph{iterations complexities} are given:\n\n\\begin{table}[H]\n\\centering\n\\caption{Gradient Descent convergence rates and iterations complexities}\n\\label{gradient_rates}\n\\begin{tabular}{lrrr}\n\\toprule\n\t& stepsize rule & convergence rate & iteration complexity \\\\\n \t& \t\t& \t\t& \t\t\\\\\n\\midrule\nconvex and L-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{L}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{t}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{\\epsilon}\\Bigg)$ \\\\\nstrongly convex and L-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{L}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\Bigg(1 - \\frac{1}{\\kappa}\\Bigg)^t\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\kappa \\log \\frac{1}{\\epsilon}\\Bigg)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\n% http://www.princeton.edu/~yc5/ele522_optimization/lectures/accelerated_gradient.pdf\n\n\\subsubsection{Momentum}\n\nTo mitigate the pathological zig-zagging by speeding up the \\emph{convergence rate} of the SGD method, we introduce two accelerated methods~\\cite{polyak1964some} and~\\cite{nesterov1998introductory, nesterov1983method} that exploits information from the history, i.e., past iterates, to add some inertia, i.e., the momentum, to yield smoother trajectory.\n\nIn the Polyak's method~\\cite{polyak1964some} the velocity vector $v_t$ is calculated by applying the $\\beta$ momentum to the previous $v_{t-1}$ displacement, and subtracting the gradient step to $x_t$.\n\n% http://mitliagkas.github.io/ift6085-2019/ift-6085-lecture-6-notes.pdf\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.5]{img/momentum}\n  \t\\caption{Polyak's and Nesterov's momentum}\n  \t\\label{fig:momentum}\n\\end{figure}\n\n\\begin{algorithm}[H]\n\t\\caption{Polyak's Accelerated Gradient Descent or Polyak Heavy-Ball method}\n\t\\label{alg:pag}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Momentum $\\beta \\in [0,1)$}\n\t\t\\Function{PolyakAcceleratedGradientDescent}{$f,\\alpha,\\beta$}\n\t\t\t\\State Initialize weight vector $x_1 \\gets x_0$ and velocity vector $v_0 \\gets 0$\n\t\t\t\\State $t \\gets 1$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $v_t = \\beta v_{t-1} + \\alpha \\nabla f(x_t)$\n\t\t\t\t\\State $x_{t+1} = x_t - v_t$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\n% https://angms.science/doc/CVX/CVX_HBM.pdf\n\n\\begin{theorem}[\\href{https://angms.science/doc/CVX/CVX_HBM.pdf\\#page=21}{Polyak's Accelerated Gradient Descent convergence for convex quadratic functions}] \\label{thm:quad_pag_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous and $\\mu$-strongly convex quadratic function. Then the Polyak's Accelerated Gradient Descent with step size $\\alpha = \\displaystyle \\frac{4}{(\\sqrt{L} + \\sqrt{\\mu})^2}$ and momentum $\\beta = \\max{\\{|1 - \\sqrt{\\alpha \\mu}|, |1 - \\sqrt{\\alpha L}|\\}^2}$ satisfies:\n$$\n\\begin{aligned}\n\t\\| x_t - x^* \\| = \\bigg(\\frac{\\sqrt{\\kappa}-1}{\\sqrt{\\kappa}+1}\\bigg)^t \\| x_0 - x^* \\|\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\nLeveraging the idea of momentum introduced by Polyak, Nesterov introduced a slightly altered update rule that has been shown to converge not only for quadratic functions, but for general convex functions. In the Nesterov's method~\\cite{nesterov1998introductory}, instead, the velocity vector $v_t$ is calculated by applying the $\\beta$ momentum to the previous $v_{t-1}$ displacement, and subtracting the gradient step to $x_t + \\beta v_{t-1}$, which is the point where the momentum term leads from $x_t$.\n\n\\begin{algorithm}[H]\n\t\\caption{Nesterov's Accelerated Gradient Descent or Nesterov Heavy-Ball method}\n\t\\label{alg:nag}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate $\\alpha > 0$}\n\t\t\\Require{Momentum $\\beta \\in [0,1)$}\n\t\t\\Function{NesterovAcceleratedGradientDescent}{$f,\\alpha,\\beta$}\n\t\t\t\\State Initialize weight vector $x_1 \\gets x_0$ and velocity vector $v_0 \\gets 0$\n\t\t\t\\State $t \\gets 1$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $\\hat{x}_t \\gets x_t + \\beta v_{t-1}$\n\t\t\t\t\\State $v_t \\gets \\beta v_{t-1} + \\alpha \\nabla f(\\hat{x}_t)$\n\t\t\t\t\\State $x_{t+1} \\gets x_t - v_t$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nComparing the algorithm~\\ref{alg:pag} with the algorithm~\\ref{alg:nag}, we can see that Polyak’s method evaluates the gradient before adding momentum, whereas Nesterov’s algorithm evaluates it after applying momentum, which intuitively brings us closer to the minimum $x^*$, as shown in figure~\\ref{fig:momentum}.\n\n\\begin{theorem}[\\href{http://www.princeton.edu/~yc5/ele522_optimization/lectures/accelerated_gradient.pdf\\#page=31}{Nesterov's Accelerated Gradient Descent convergence for convex functions}] \\label{thm:cvx_nag_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous convex function. Then the Nesterov's Accelerated Gradient Descent with step size $\\alpha = 1/L$ and momentum $\\beta_{t+1} = t / (t+3)$ satisfies:\n$$\nf(x_t) - f(x^*) \\leq \\frac{2L \\| x_0 - x^* \\|^2}{(t+1)^2}\n$$\n\\end{theorem}\n\n\\begin{theorem}[\\href{http://www.princeton.edu/~yc5/ele522_optimization/lectures/accelerated_gradient.pdf\\#page=38}{Nesterov's Accelerated Gradient Descent convergence for strongly convex functions}] \\label{thm:str_cvx_nag_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-Lipschitz continuous and $\\mu$-strongly convex function. Then the Nesterov's Accelerated Gradient Descent with step size $\\alpha = 1/L$ and momentum $\\beta = \\displaystyle \\frac{\\sqrt{\\kappa}-1}{\\sqrt{\\kappa}+1}$ satisfies:\n$$\n\\begin{aligned}\n\tf(x_t) - f(x^*) \\leq & \\Bigg(1 - \\sqrt{\\frac{\\mu}{L}}\\Bigg)^t \\Bigg(f(x_0) - f(x^*) + \\frac{\\mu \\| x_0 - x^* \\|^2}{2}\\Bigg) \\\\\n\t\t\t\t\t\t= & \\Bigg(1 - \\frac{1}{\\sqrt{\\kappa}}\\Bigg)^t \\Bigg(f(x_0) - f(x^*) + \\frac{\\mu \\| x_0 - x^* \\|^2}{2}\\Bigg)\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\n% https://blogs.princeton.edu/imabandit/2014/03/06/nesterovs-accelerated-gradient-descent-for-smooth-and-strongly-convex-optimization/\n\nIn summary, the following \\emph{convergence rates} and \\emph{iterations complexities} are given:\n\n\\begin{table}[H]\n\\centering\n\\caption{Nesterov's Accelerated Gradient Descent convergence rates and iterations complexities}\n\\label{nesterov_gradient_rates}\n\\begin{tabular}{lrrr}\n\\toprule\n\t& stepsize rule & convergence rate & iteration complexity \\\\\n \t& \t\t& \t\t& \t\t\\\\\n\\midrule\nconvex and L-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{L}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{t^2}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{1}{\\sqrt{\\epsilon}}\\Bigg)$ \\\\\nstrongly convex and L-Lipschitz & $\\displaystyle \\alpha = \\frac{1}{L}$ & $\\displaystyle \\mathcal{O}\\Bigg(\\Bigg(1 - \\frac{1}{\\sqrt{\\kappa}}\\Bigg)^t\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\sqrt{\\kappa}\\log \\frac{1}{\\epsilon}\\Bigg)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\nNote that in case of L-Lipschitz continuous and strongly convex functions, Nesterov's momentum gives the acceleration that we had with Polyak’s momentum for quadratic functions. This is great because we get the guarantee for a more general class of functions, but these \\emph{convergence rates} cannot be futher improved only using first-order information.\n\n\\pagebreak\n\n\\subsection{Sequential Minimal Optimization for Wolfe dual formulations}\n\nThe \\emph{Sequential Minimal Optimization (SMO)}~\\cite{platt1998sequential} method is the most popular approach for solving the SVM QP problem without any extra $Q$ matrix storage required by common QP methods. The advantage of SMO lies in the fact that it performs a series of two-point optimizations since we deal with just one equality constraint, so the Lagrange multipliers can be solved analitically.\n\n\\subsubsection{Classification}\n\nAt each iteration, SMO chooses two $\\alpha_i$ to jointly optimize, let $\\alpha_1$ and $\\alpha_2$, finds the optimal values for these multipliers and update the SVM to reflect these new values. In order to solve for two Lagrange multipliers, SMO first computes the constraints over these and then solves for the constrained minimum. Since there are only two multipliers, the box-constraints cause the Lagrange multipliers to lie within a box, while the linear equality constraint causes the Lagrange multipliers to lie on a diagonal line inside the box. So, the constrained minimum must lie there as shown in~\\ref{fig:smo_lagrange_multipliers}.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.5]{img/smo_multipliers}\n\t\\caption{SMO for two Lagrange multipliers}\n\t\\label{fig:smo_lagrange_multipliers}\n\\end{figure}\n\nIn case of classification the ends of the diagonal line segment, i.e., the lower and upper bounds, can be espressed as follow if the target $y_1 \\ne y_2$:\n\n\\begin{equation} \\label{eq:smo_svc_bounds_update1}\n\t\\begin{aligned}\n\t\t& L = max(0, \\alpha_2 - \\alpha_1) \\\\\n\t\t& H = min(C, C + \\alpha_2 - \\alpha_1)\n\t\\end{aligned}\n\\end{equation}\n\nor, alternatively, if the target $y_1 = y_2$:\n\n\\begin{equation} \\label{eq:smo_svc_bounds_update2}\n\t\\begin{aligned}\n\t\t& L = max(0, \\alpha_2 + \\alpha_1 - C) \\\\\n\t\t& H = min(C, \\alpha_2 + \\alpha_1)\n\t\\end{aligned}\n\\end{equation}\n\nThe second derivative of the objective quadratic function along the diagonl line can be expressed as:\n\n\\begin{equation} \\label{eq:smo_eta}\n\t\\eta = K(x_1, x_1) + K(x_2, x_2) - 2K(x_1, x_2)\n\\end{equation}\n\nthat will be grather than zero if the kernel matrix will be positive definite, so there will be a minimum along the linear equality constraints that will be:\n\n\\begin{equation} \\label{eq:smo_svc_a2_new}\n\t\\alpha_2^{new} = \\alpha_2 + \\frac{y_2(E_1 - E_2)}{\\eta}\n\\end{equation}\n\nwhere $E_i = y_i - y'_i$ is the error on the $i$-th training example and $y'_i$ is the output of the SVC for the same.\n\nThen, the box-constrained minimum is found by clipping the unconstrained minimum to the ends of the line segment:\n\n\\begin{equation} \\label{eq:smo_svc_a2_new_clipped}\n    \\alpha_2^{new,clipped} =\n        \\begin{cases}\n            H & \\text{if} \\ \\alpha_2^{new} \\geq H \\\\\n            \\alpha_2^{new} & \\text{if} \\ L < \\alpha_2^{new} < H \\\\\n            L & \\text{if} \\ \\alpha_2^{new} \\leq L \\\\\n        \\end{cases}\n\\end{equation}\n\nFinally, the value of $\\alpha_1$ is computed from the new clipped $\\alpha_2$ as:\n\n\\begin{equation} \\label{eq:smo_svc_a1_new}\n\t\\alpha_1^{new} = \\alpha_1 + s (\\alpha_2 - \\alpha_2^{new,clipped})\n\\end{equation}\n\nwhere $s = y_1 y_2$.\n\nSince the \\emph{Karush-Kuhn-Tucker} conditions are necessary and sufficient conditions for optimality of a positive definite QP problem and the KKT conditions for the classification problem~\\eqref{eq:svc_min_wolfe_dual} are:\n\n\\begin{equation} \\label{eq:svc_smo_kkt}\n\t\\begin{aligned}\n\t\t\\alpha_i = 0 & \\Leftrightarrow y_i y'_i \\geq 1 \\\\\n\t\t0 < \\alpha_i < C & \\Leftrightarrow y_i y'_i = 1 \\\\\n\t\t\\alpha_i = C & \\Leftrightarrow y_i y'_i \\leq 1\n\t\\end{aligned}\n\\end{equation}\n\nthe steps described above will be iterate as long as there will be an example that violates them.\n\nAfter optimizing $\\alpha_1$ and $\\alpha_2$, we select the threshold $b$ such that the KKT conditions are satisfied for $x_1$ and $x_2$. If, after optimization, $\\alpha_1$ is not at the bounds, i.e., $0 < \\alpha_1 < C$, then the following threshold $b_{up}$ is valid, since it forces the SVC to output $y_1$ when the input is $x_1$:\n\n\\begin{equation} \\label{eq:smo_svc_b1}\n\tb_{up} = E_1 + y_1 (\\alpha_1^{new} - \\alpha_1) K(x_1,x_1) + y_2 (\\alpha_2^{new,clipped} - \\alpha_2) K(x_1,x_2) + b\n\\end{equation}\n\nsimilarly, the following threshold $b_{low}$ is valid if $0 < \\alpha_2 < C$:\n\n\\begin{equation} \\label{eq:smo_svc_b2}\n\tb_{low} = E_2 + y_1 (\\alpha_1^{new} - \\alpha_1) K(x_1,x_2) + y_2 (\\alpha_2^{new,clipped} - \\alpha_2) K(x_2,x_2) + b\n\\end{equation}\n\nIf, after optimization, both $0 < \\alpha_1 < C$ and $0 < \\alpha_2 < C$ then both these thresholds are valid, and they will be equal; else, if both $\\alpha_1$ and $\\alpha_2$ are at the bounds, i.e., $\\alpha_1 = 0$ or $\\alpha_1 = C$ and $\\alpha_2 = 0$ or $\\alpha_2 = C$, then all the thresholds between $b_{up}$ and $b_{low}$ satisfy the KKT conditions, so we choose the threshold to be halfway in between $b_{up}$ and $b_{low}$. This gives the complete equation for $b$:\n\n\\begin{equation} \\label{eq:smo_svc_b}\n\tb =\n        \\begin{cases}\n            b_{up} & \\text{if} \\ 0 < \\alpha_1 < C \\\\\n            b_{low} & \\text{if} \\ 0 < \\alpha_2 < C \\\\\n            \\displaystyle \\frac{b_{up}+b_{low}}{2} & \\text{otherwise} \\\\\n        \\end{cases}\n\\end{equation}\n\n\\newpage\n\n\\begin{breakablealgorithm}\n\t\\caption{Sequential Minimal Optimization for Classification}\n\t\\label{alg:smo_classifier}\n\t\\begin{algorithmic}\n\t\t\\Require{Training examples matrix $X \\in \\Re^{n \\times m}$}\n\t\t\\Require{Training target vector $y \\in \\pm1^n$}\n\t\t\\Require{Kernel matrix $K \\in \\Re^{n \\times n}$}\n\t\t\\Require{Regularization parameter $C > 0$}\n\t\t\\Require{Tolerance value $tol$ for stopping criterion}\n\t\t\\Function{SMOClassifier}{$X,y,K,C,tol$}\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha \\in \\Re^n, \\alpha \\gets 0$\n\t\t\t\\State Initialize the empty set $I0 \\gets \\{i : 0 < \\alpha_i < C\\}$\n\t\t\t\\State Initialize the set $I1 \\gets \\{i : y_i = +1, \\alpha_i = 0\\}$ to contain all the indices of the training examples of class $+1$\n\t\t\t\\State Initialize the empty set $I2 \\gets \\{i : y_i = -1,\t \\alpha_i = C\\}$\n\t\t\t\\State Initialize the empty set $I3 \\gets \\{i :  y_i = +1,\t \\alpha_i = C\\}$\n\t\t\t\\State Initialize the set $I4 \\gets \\{i : y_i = -1, \\alpha_i = 0\\}$ to contain all the indices of the training examples of class $-1$\n\t\t\t\\State Initialize $b_{up} \\gets -1$\n\t\t\t\\State Initialize $b_{low} \\gets +1$\n\t\t\t\\State Initialize the error cache vector $errors \\in \\Re^n, errors \\gets 0$\n\t\t\t\\While {$num\\_changed > 0$ \\OR $examine\\_all = True$}\n\t\t\t\t\\State $num\\_changed \\gets 0$\n\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\For {$i \\gets 0$ to $n$} \\Comment loop over all training examples\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\Else\n\t\t\t\t\t\\For {$i$ in $I0$} \\Comment loop over examples where $\\alpha_i$ are not already at their bounds\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\t\\If {$b_{up} > b_{low} - 2 tol$} \\Comment check if optimality on $I0$ is attained\n\t\t\t\t\t\t\t\\State {$num\\_changed \\gets 0$}\n\t\t\t\t\t\t\t\\Break\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\State $examine\\_all \\gets False$\n\t\t\t\t\\ElsIf {$num\\_changed = 0$}\n\t\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\State Compute $b$ by~\\eqref{eq:smo_svc_b}\n\t\t\t\\State \\Return $\\alpha,b$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{ExamineExample}{$i2$}\n\t\t\t\\If {$i2$ in $I0$}\n\t\t\t\t\\State $E_2 \\gets errors_{i2}$\n\t\t\t\\Else \n\t\t\t\t\\State Compute $E_2$\n\t\t\t\t\\State $errors_{i2} \\gets E_2$\n\t\t\t\t\\State Update $(b_{low}, i_{low})$ or $(b_{up}, i_{up})$ using $(E_2, i2)$\n\t\t\t\\EndIf\n\t\t\t\\If {optimality is attained using current $b_{low}$ and $b_{up}$}\n\t\t\t\t\\State \\Return 0\n\t\t\t\\Else\n\t\t\t\t\\State Find an index $i1$ to do joint optimization with $i2$\n\t\t\t\t\\If {$\\Call{TakeStep}{i1,i2}$ = True}\n\t\t\t\t\t\\State \\Return 1\n\t\t\t\t\\Else\n\t\t\t\t\t\\State \\Return 0\n\t\t\t\t\\EndIf\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i1$-th Lagrange multiplier}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{TakeStep}{$i1,i2$}\n\t\t\t\\If {$i1 = i2$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State Compute $L$ and $H$ using~\\eqref{eq:smo_svc_bounds_update1} or~\\eqref{eq:smo_svc_bounds_update2}\n\t\t\t\\If {$L = H$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State Compute $\\eta$ by~\\eqref{eq:smo_eta} \\Comment we assume that $\\eta > 0$, i.e., the kernel matrix $K$ is positive definite\n\t\t\t\\If {$\\eta < 0$}\n\t\t\t\t\\State Choose $\\alpha_2^{new,clipped}$ between $L$ and $H$ according to the largest value of the objective function at these points\n\t\t\t\\Else\n\t\t\t\t\\State Compute $\\alpha_2^{new}$ by~\\eqref{eq:smo_svc_a2_new}\n\t\t\t\t\\State Compute $\\alpha_2^{new,clipped}$ by~\\eqref{eq:smo_svc_a2_new_clipped}\n\t\t\t\\EndIf\n\t\t\t\\If {changes in $\\alpha_2^{new,clipped}$ are larger than some eps}\n\t\t\t\t\\State Compute $\\alpha_1^{new}$ by~\\eqref{eq:smo_svc_a1_new}\n\t\t\t\t\\State Update $\\alpha_2^{new,clipped}$ and $\\alpha_1^{new}$\n\t\t\t\t\\For {$i$ in $I0$}\n\t\t\t\t\t\\State Update $errors_i$ using new Lagrange multipliers\n\t\t\t\t\\EndFor\n\t\t\t\t\\State Update $\\alpha$ using new Lagrange multipliers\n\t\t\t\t\\State Update $I0, I1, I2, I3$ and $I4$\n\t\t\t\t\\State Update $errors_{i1}$ and $errors_{i2}$\n\t\t\t\t\\For {$i$ in $I0 \\cup \\{i1,i2\\}$}\n\t\t\t\t\t\\State Compute $(i_{low}, b_{low})$ by $b_{low} = \\max\\{errors_i : i \\in I0 \\cup I3 \\cup I4\\}$\n\t\t\t\t\t\\State Compute $(i_{up}, b_{up})$ by $b_{up} = \\min\\{errors_i : i \\in I0 \\cup I1 \\cup I2\\}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\State \\Return True\n\t\t\t\\Else\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\newpage\n\n\\subsubsection{Regression}\n\nIn case of regression the bounds and the new multipliers $\\alpha_1^{+,new}$ and $\\alpha_2^{+,new}$ can be expressed as follows if ($\\alpha_1^+ > 0$ or ($\\alpha_1^- = 0$ and $ E_1 - E_2 > 0$)) and ($\\alpha_2^+ > 0$ or ($\\alpha_2^- = 0$ and $ E_1 - E_2 < 0$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update1}\n\t\\begin{aligned}\n\t\t& L = max(0, \\gamma - C) \\\\\n\t\t& H = min(C, \\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new1}\n\t\\alpha_2^{+,new} = \\alpha_2^+ - \\frac{E_1 - E_2}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new1}\n\t\\alpha_1^{+,new} = \\alpha_1^+ - (\\alpha_2^{+,new,clipped} - \\alpha_2^+)\n\\end{equation}\n\nor, if ($\\alpha_1^+ > 0$ or ($\\alpha_1^- = 0$ and $ E_1 - E_2 > 2 \\epsilon$)) and ($\\alpha_2^- > 0$ or ($\\alpha_2^+ = 0$ and $ E_1 - E_2 > 2 \\epsilon$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update2}\n\t\\begin{aligned}\n\t\t& L = max(0, -\\gamma) \\\\\n\t\t& H = min(C, -\\gamma + C)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new2}\n\t\\alpha_2^{-,new} = \\alpha_2^- + \\frac{(E_1 - E_2) - 2 \\epsilon}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new2}\n\t\\alpha_1^{+,new} = \\alpha_1^+ + (\\alpha_2^{-,new,clipped} - \\alpha_2^-)\n\\end{equation}\n\nor, if ($\\alpha_1^- > 0$ or ($\\alpha_1^+ = 0$ and $ E_1 - E_2 < - 2 \\epsilon$)) and ($\\alpha_2^+ > 0$ or ($\\alpha_2^- = 0$ and $ E_1 - E_2 < - 2 \\epsilon$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update3}\n\t\\begin{aligned}\n\t\t& L = max(0, \\gamma) \\\\\n\t\t& H = min(C, C + \\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new3}\n\t\\alpha_2^{+,new} = \\alpha_2^+ - \\frac{(E_1 - E_2) + 2 \\epsilon}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new3}\n\t\\alpha_1^{-,new} = \\alpha_1^- + (\\alpha_2^{+,new,clipped} - \\alpha_2^+)\n\\end{equation}\n\nor, finally, if ($\\alpha_1^- > 0$ or ($\\alpha_1^+ = 0$ and $ E_1 - E_2 < 0$)) and ($\\alpha_2^- > 0$ or ($\\alpha_2^+ = 0$ and $ E_1 - E_2 > 0$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update4}\n\t\\begin{aligned}\n\t\t& L = max(0, -\\gamma - C) \\\\\n\t\t& H = min(C, -\\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new4}\n\t\\alpha_2^{-,new} = \\alpha_2^- + \\frac{E_1 - E_2}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new4}\n\t\\alpha_1^{-,new} = \\alpha_1^- - (\\alpha_2^{-,new,clipped} - \\alpha_2^-)\n\\end{equation}\n\nwhere $\\gamma = \\alpha_1^+ - \\alpha_1^- + \\alpha_2^+ - \\alpha_2^-$. Note that $\\eta$ and $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ are identical to~\\eqref{eq:smo_eta} and~\\eqref{eq:smo_svc_a2_new_clipped} respectively.\n\nThe KKT conditions for the regression problem~\\eqref{eq:svr_min_wolfe_dual} are:\n\n\\begin{equation} \\label{eq:svr_smo_kkt}\n\t\\begin{aligned}\n\t\t\\alpha_i^+ - \\alpha_i^- = 0 & \\Leftrightarrow | y_i - y'_i | < \\epsilon \\\\\n\t\t-C < \\alpha_i^+ - \\alpha_i^- < C & \\Leftrightarrow | y_i - y'_i | = \\epsilon \\\\\n\t\t\\alpha_i^+ + \\alpha_i^- = C & \\Leftrightarrow | y_i - y'_i | > \\epsilon\t\n\t\\end{aligned}\n\\end{equation}\n\nso, the steps described above will be iterate as long as there will be an example that violates them.\n\nIn case of regression we select the threshold $b$ as follows:\n\n\\begin{equation} \\label{eq:smo_svr_b1}\n\tb_{up} = E_1 + ((\\alpha_1^+ - \\alpha_1^-) - (\\alpha_1^{+,new} - \\alpha_1^{-,new})) K(x_1,x_1) + ((\\alpha_2^+ - \\alpha_2^-) - (\\alpha_2^{+,new,clipped} - \\alpha_2^{-,new,clipped})) K(x_1,x_2) + b\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_b2}\n\tb_{low} = E_2 + ((\\alpha_1^+ - \\alpha_1^-) - (\\alpha_1^{+,new} - \\alpha_1^{-,new})) K(x_1,x_2) + ((\\alpha_2^+ - \\alpha_2^-) - (\\alpha_2^{+,new,clipped} - \\alpha_2^{-,new,clipped})) K(x_2,x_2) + b\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_b}\n\tb =\n        \\begin{cases}\n            b_{up} & \\text{if} \\ 0 < \\alpha_1^+, \\alpha_1^- < C \\\\\n            b_{low} & \\text{if} \\ 0 < \\alpha_2^+, \\alpha_2^- < C \\\\\n            \\displaystyle \\frac{b_{up}+b_{low}}{2} & \\text{otherwise} \\\\\n        \\end{cases}\n\\end{equation}\n\n\\bigskip\n\\bigskip\n\nThe improvements described in~\\cite{keerthi2001improvements, shevade1999improvements} for classification and regression respectively are about the definition of subsets of multipliers to efficiently update them at each iteration by separating the multipliers at the bounds from those who can be further minimized.\n\n\\newpage\n\n\\begin{breakablealgorithm}\n\t\\caption{Sequential Minimal Optimization for Regression}\n\t\\label{alg:smo_regression}\n\t\\begin{algorithmic}\n\t\t\\Require{Training examples matrix $X \\in \\Re^{n \\times m}$}\n\t\t\\Require{Training target vector $y \\in \\Re^n$}\n\t\t\\Require{Kernel matrix $K \\in \\Re^{n \\times n}$}\n\t\t\\Require{Regularization parameter $C > 0$}\n\t\t\\Require{Epsilon-tube value $\\epsilon \\geq 0$ within which no penalty is associated in the epsilon-insensitive loss function}\n\t\t\\Require{Tolerance value $tol$ for stopping criterion}\n\t\t\\Function{SMORegression}{$X,y,K,C,\\epsilon,tol$}\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha^+ \\in \\Re^n, \\alpha^+ \\gets 0$\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha^- \\in \\Re^n, \\alpha^- \\gets 0$\n\t\t\t\\State Initialize the empty set $I0 \\gets \\{i : 0 < \\alpha^+_i, \\alpha^-_i < C\\}$\n\t\t\t\\State Initialize the set $I1 \\gets \\{i : \\alpha^+_i = 0, \\alpha^-_i = 0\\}$ to contain all the indices of the training examples\n\t\t\t\\State Initialize the empty set $I2 \\gets \\{i : \\alpha^+_i = 0, \\alpha^-_i = C\\}$\n\t\t\t\\State Initialize the empty set $I3 \\gets \\{i : \\alpha^+_i = C, \\alpha^-_i = 0\\}$\n\t\t\t\\State Initialize $i_{up} \\gets 0$ \\Comment or any other target index $i_{up}$ from the training examples\n\t\t\t\\State Initialize $i_{low} \\gets 0$ \\Comment or any other target index $i_{low}$ from the training examples\n\t\t\t\\State Initialize $b_{up} \\gets y_{i_{up}} + \\epsilon$\n\t\t\t\\State Initialize $b_{low} \\gets y_{i_{low}} - \\epsilon$\n\t\t\t\\State Initialize the error cache vector $errors \\in \\Re^n, errors \\gets 0$\n\t\t\t\\While {$num\\_changed > 0$ \\OR $examine\\_all = True$}\n\t\t\t\t\\State $num\\_changed \\gets 0$\n\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\For {$i \\gets 0$ to $n$} \\Comment loop over all training examples\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\Else\n\t\t\t\t\t\\For {$i$ in $I0$} \\Comment loop over examples where $\\alpha^+_i$ and $\\alpha^-_i$ are not already at their bounds\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\t\\If {$b_{up} > b_{low} - 2 tol$} \\Comment check if optimality on $I0$ is attained\n\t\t\t\t\t\t\t\\State {$num\\_changed \\gets 0$}\n\t\t\t\t\t\t\t\\Break\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\State $examine\\_all \\gets False$\n\t\t\t\t\\ElsIf {$num\\_changed = 0$}\n\t\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\State Compute $b$ by~\\eqref{eq:smo_svr_b}\n\t\t\t\\State \\Return $\\alpha^+,\\alpha^-,b$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i1$-th Lagrange multiplier}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{TakeStep}{$i1,i2$}\n\t\t\t\\If {$i1 = i2$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State $finished = False$\n\t\t\t\\While {\\NOT $finished$}\n\t\t\t\t\\State Compute $L$ and $H$ using~\\eqref{eq:smo_svr_bounds_update1},~\\eqref{eq:smo_svr_bounds_update2},~\\eqref{eq:smo_svr_bounds_update3} or~\\eqref{eq:smo_svr_bounds_update4}\n\t\t\t\t\\If {$L < H$}\n\t\t\t\t\t\\State Compute $\\eta$ by~\\eqref{eq:smo_eta} \\Comment we assume that $\\eta > 0$, i.e., the kernel matrix $K$ is positive definite\n\t\t\t\t\t\\If {$\\eta < 0$}\n\t\t\t\t\t\t\\State Choose $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ between $L$ and $H$ according to the largest value of the objective function at these points\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State Compute $\\alpha_2^{+,new}$ or $\\alpha_2^{-,new}$ using~\\eqref{eq:smo_svr_a2_new1},~\\eqref{eq:smo_svr_a2_new3} or~\\eqref{eq:smo_svr_a2_new2},~\\eqref{eq:smo_svr_a2_new4} respectively\n\t\t\t\t\t\t\\State Compute $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ by~\\eqref{eq:smo_svc_a2_new_clipped}\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\State Compute $\\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ using~\\eqref{eq:smo_svr_a1_new1},~\\eqref{eq:smo_svr_a1_new2} or~\\eqref{eq:smo_svr_a1_new3},~\\eqref{eq:smo_svr_a1_new4} respectively\n\t\t\t\t\t\\If {changes in $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ are larger than some eps}\n\t\t\t\t\t\t\\State Update $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\Else\n\t\t\t\t\t\\State $finished = True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\If {changes in $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ are larger than some eps}\n\t\t\t\t\\For {$i$ in $I0$}\n\t\t\t\t\t\\State Update $errors_i$ using new Lagrange multipliers\n\t\t\t\t\\EndFor\n\t\t\t\t\\State Update $\\alpha^+$ and $\\alpha^-$ using new Lagrange multipliers\n\t\t\t\t\\State Update $I0, I1, I2$ and $I3$\n\t\t\t\t\\State Update $errors_{i1}$ and $errors_{i2}$\n\t\t\t\t\\For {$i$ in $I0 \\cup \\{i1,i2\\}$}\n\t\t\t\t\t\\State Compute $(i_{low}, b_{low})$ by $b_{low} = \\max\\{errors_i : i \\in I0 \\cup I1 \\cup I2\\}$\n\t\t\t\t\t\\State Compute and $(i_{up}, b_{up})$ by $b_{up} = \\min\\{errors_i : i \\in I0 \\cup I1 \\cup I3\\}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\State \\Return True\n\t\t\t\\Else\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\pagebreak\n\n\\subsection{AdaGrad for Lagrangian dual formulations}\n\nDue to the sparsity of the weight vector of the \\emph{Lagrangian dual}, i.e., the Lagrange multipliers, we might end up in a situation where some components of the gradient are very small and others large. This, in terms of \\emph{conditioning number}, i.e., $\\kappa = L/\\mu \\gg 1$, means that the level sets of $f$ are ellipsoid, i.e., we are dealing with an ill-conditioned problem. So, given a learning rate, a standard gradient descent approach might end up in a situation where it decreases too quickly the small weights or too slowly the large ones.\n\nAnother method, that is usually deprecated in ML applications due to its increased computational complexity, is Newton’s method. Newton’s method favors a much faster \\emph{convergence rate}, i.e., number of iterations, at the cost of being more expensive per iteration. For convex problems, the recursion is similar to the gradient descent algorithm:\n\n$$\nx_{t+1} = x_t - \\alpha H^{-1} \\nabla f(x_t)\n$$\n\nwhere $\\alpha$ is often close to one (damped-Newton) or one, and $H^{-1}$ denotes the Hessian of $f$ at the current point, i.e., $\\nabla^2 f(x_t)$.\n\nThe above suggest a general rule in optimization: find any preconditioner, in convex optimization it has to be positive semidefinite, that improves the performance of gradient descent in terms of iterations, but without wasting too much time to compute that precoditioner. The above result into:\n\n$$\nx_{t+1} = x_t - \\alpha P^{-1} \\nabla f(x_t)\n$$\n\nwhere $P$ is the preconditioner. This idea is the basis of the BFGS quasi-Newton method.\n\nThe \\emph{AdaGrad}~\\cite{duchi2011adaptive} algorithm is just a variant of preconditioned gradient descent, where $P$ is selected to be a diagonal preconditioner matrix and is updated using the gradient information, in particular it is the diagonal approximation of the inverse of the square roots of gradient outer products, until the $k$-th iteration. The above lead to the algorithm:\n\n\\begin{algorithm}[H]\n\t\\caption{AdaGrad}\n\t\\label{alg:adagrad}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Offset $\\epsilon > 0$ to ensures not divide by 0}\n\t\t\\Function{AdaGrad}{$f,\\alpha,\\epsilon$}\n\t\t\t\\State Initialize weight vector $x_0$ and the squared accumulated gradients vector $s_t \\gets 0$\n\t\t\t\\State $t = 1$\n\t\t\t\\While {$not\\_convergence$}\n\t\t\t\t\\State $g_t \\gets \\partial f(x_t)$ \\Comment if $f$ is differentiable then $\\partial f(x_t) = \\nabla f(x_t)$\n\t\t\t\t\\State $s_t \\gets s_{t-1} + g_t^2$\n\t\t\t\t\\State $x_{t+1} \\gets x_t - \\alpha P_t^{-1} g_t = x_t - \\displaystyle \\frac{\\alpha}{\\sqrt{s_t + \\epsilon}} \\odot g_t \\ \\text{where} \\ P_t \\gets diag(s_t + \\epsilon)^{1/2}$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nIn practical terms, \\emph{AdaGrad} addresses the problem of the sparse optimal by adaptively scaling the learning rate for each dimension with the magnitude of the gradients. Coordinates that routinely correspond to large gradients are scaled down significantly, whereas others with small gradients receive a much more gentle treatment.\n\n\\pagebreak\n\n\\subsection{Losses properties}\n\nSeveral losses and objectives have been presented in section~\\ref{section:svc} and~\\ref{section:svr}. In our experiments, we will consider the following.\n\nFor what about the loss functions, two of them are nonsmooth convex functions, i.e., the \\emph{hinge} and the \\emph{epsilon-insensitive} losses for \\emph{classification} and \\emph{regression} tasks respectively, and linearly penalizes the misclassified points, i.e., $\\mathcal{L}_1$-SVM, meanwhile, their two \\emph{squared} versions are smooth, i.e., $\\mathcal{L}_2$-SVM, and quadratically penalizes the misclassified points.\n\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/distance/#LPDistLoss-1\n\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/margin/#L1HingeLoss-1\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/margin/#SmoothedL1HingeLoss-1\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/margin/#ModifiedHuberLoss-1\n\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/distance/#L1EpsilonInsLoss-1\n% http://juliaml.github.io/LossFunctions.jl/stable/losses/distance/#L2EpsilonInsLoss-1\n\nAlso, both the \\emph{margin-based} losses, i.e., the \\emph{hinge} and the \\emph{squared hinge} losses, are $L_f$-Lipschitz continuous; meanwhile, among the \\emph{distance-based} losses, the \\emph{epsilon-insensitive} loss is $L_f$-Lipschitz continuous but the \\emph{squared epsilon-insensitive} is not $L_f$-Lipschitz continuous, however it is convex and for this reason is locally $L_f$-Lipschitz continuous. \n\nAlso the regularization term, i.e., $\\displaystyle \\frac{1}{2} \\| w \\|^2$, is not $L_f$-Lipschitz continuous since it becomes arbitrarily steep as $w$ approaches infinity, but it is strictly convex and for this reason is locally $L_f$-Lipschitz continuous. Clearly, its gradient, i.e., $w$, is not bounded since, again, they go to infinity as $w$ goes to infinity, so this function is not $L$-Lipschitz continuous.\n\nSince for our purposes, we need to show that our $\\mathcal{L}_1$-SVM objectives are $L_f$-Lipschitz continuous and the $\\mathcal{L}_2$-SVM objectives are $L$-Lipschitz continuous for the applicability of the convergence theorems, we will use the theorem~\\ref{def:l_f_lipschitz_convex} and~\\ref{def:strong_cvx_l_lipschitz_convex} respectively.\n\nIn general, if the objective function of a quadratic programming problem is strictly convex, i.e., the associated Hessian matrix is positive definite, the solution is unique. Meanwhile, if the objective function is convex, there may be cases where the solution is nonunique.\n\nAssume that the hard margin SVM has a solution, i.e., the given problem is separable in the feature space. Then, since the objective function of the primal problem is $\\displaystyle \\frac{1}{2} \\| w \\|^2$, which is strongly convex, the primal problem has a unique solution for $w$ and $b$.\n\nSince the $\\mathcal{L}_1$-SVM linearly penalizes the misclassified points, the primal objective function is convex. Likewise, the Hessian matrix of the dual objective function is positive semidefinite. Thus the primal and dual solutions may be nonunique. Meanwhile, the objective function of the primal problem for the $\\mathcal{L}_2$-SVM is strictly convex, due to the quadratic penalization of the misclassified points. Therefore, $w$ and $b$ are uniquely determined if we solve the primal or dual problem. \n\nIn summary, the following properties for the SVM's objectives are given:\n\n% http://www.lib.kobe-u.ac.jp/repository/90000231.pdf\n% https://hal.archives-ouvertes.fr/hal-00708243v1/file/appendixMNBCI.pdf\n\n\\begin{table}[H]\n\\centering\n\\caption{SVM's objectives properties for primal formulations}\n\\label{primal_svm_objectives_props}\n\\begin{tabular}{lrrr}\n\\toprule\n\t& smooth & \\vtop{\\hbox{\\strut Lipschitz}\\hbox{\\strut continuous}} & convexity \\\\\nobjective & \t\t& \t\t& \t\t\\\\\n\\midrule\n$\\mathcal{L}_1$-SVC~\\eqref{eq:reg_bias_primal_l1_svc} & no & $L_f$-Lipschitz & convex \\\\\n$\\mathcal{L}_2$-SVC~\\eqref{eq:reg_bias_primal_l2_svc} & yes & L-Lipschitz & \\vtop{\\hbox{\\strut 1-strongly}\\hbox{\\strut convex}} \\\\\n\\midrule\n$\\mathcal{L}_1$-SVR~\\eqref{eq:reg_bias_primal_l1_svr} & no & $L_f$-Lipschitz & convex \\\\\n$\\mathcal{L}_2$-SVR~\\eqref{eq:reg_bias_primal_l2_svr} & yes & L-Lipschitz & \\vtop{\\hbox{\\strut 1-strongly}\\hbox{\\strut convex}} \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\nAnd, according to the theoretical analysis, the following \\emph{convergence rates} are given for the primal and \\emph{Lagrangian dual} formulations respectively: \n\n% https://homepage.cs.uiowa.edu/~tyng/acml15-tutorial.pdf\n\n\\begin{table}[H]\n\\centering\n\\caption{SVM's objectives convergence rates for primal formulations}\n\\label{primal_svm_objectives_rates}\n\\begin{tabular}{lrrr}\n\\toprule\n\t& \\vtop{\\hbox{\\strut SGD}\\hbox{\\strut convergence rate}} & \\vtop{\\hbox{\\strut Polyak SGD}\\hbox{\\strut convergence rate}} & \\vtop{\\hbox{\\strut Nesterov SGD}\\hbox{\\strut convergence rate}} \\\\\nobjective & \t\t& \t\t& \t\t\\\\\n\\midrule\n$\\mathcal{L}_1$-SVM~(\\ref{eq:reg_bias_primal_l1_svc},~\\ref{eq:reg_bias_primal_l1_svr}) & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{\\sqrt{t}}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{\\sqrt{t}}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{\\sqrt{t}}\\Bigg)$ \\\\\n$\\mathcal{L}_2$-SVM~(\\ref{eq:reg_bias_primal_l2_svc},~\\ref{eq:reg_bias_primal_l2_svr}) & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{t}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{t}\\Bigg)$ & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{m}{t^2}\\Bigg)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\caption{SVM's objectives convergence rate for Lagrangian dual formulations}\n\\label{dual_svm_objectives_props}\n\\begin{tabular}{lr}\n\\toprule\n\t& \\vtop{\\hbox{\\strut AdaGrad}\\hbox{\\strut convergence rate}} \\\\\nobjective & \t\t\\\\\n\\midrule\n$\\mathcal{L}_1$-SVM~(\\ref{eq:l1_svc_aug_lagrangian_dual},~\\ref{eq:l1_svr_aug_lagrangian_dual}) or~(\\ref{eq:l1_svc_bcqp_aug_lagrangian_dual},~\\ref{eq:l1_svr_bcqp_aug_lagrangian_dual}) & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{nm}{\\sqrt{t}}\\Bigg)$ \\\\\n$\\mathcal{L}_2$-SVM~(\\ref{eq:l2_svc_aug_lagrangian_dual},~\\ref{eq:l2_svr_aug_lagrangian_dual}) or~(\\ref{eq:l2_svc_lb_aug_lagrangian_dual},~\\ref{eq:l2_svr_lb_aug_lagrangian_dual}) & $\\displaystyle \\mathcal{O}\\Bigg(\\frac{nm}{t}\\Bigg)$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}", "meta": {"hexsha": "d3f3968fcfff9558df61d69f4d223dce81cc13d7", "size": 52468, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/methods.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/methods.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/methods.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": 51.1882926829, "max_line_length": 643, "alphanum_fraction": 0.6958908287, "num_tokens": 18021, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314738181874, "lm_q2_score": 0.8596637505099168, "lm_q1q2_score": 0.7613452743521683}}
{"text": "% Copyright (C) He Guanyuming 2020\n% The file is licensed under the MIT license.\n\n\\section{Mathematical Logic}\n\n\\subsection{Mathematical Statements}\n\n\\declareexercise{a.1.1}\nIt is ( (both $X, Y$ are false) or (both $X, Y$ are true) ).\n\n\\declareexercise{a.1.2}\nIt is ( ($Y$ can be true even if $X$ is false) or ($Y$ can be false even if $X$ is true) ).\n\n\\declareexercise{a.1.3}\nYes. That's the definition of logical equivalent.\n\n\\declareexercise{a.1.4}\nNo. It is still possible that (even if $X$ is false, $Y$ is still true).\n\nConsider a statement $Y$ that satisfies:\n\\begin{enumerate}\n\\item If $X$, then $Y$.\n\\item If $X$ is false, then $Y$ or (exclusively) $Y$ is false.\n\\end{enumerate}\n\n$X,Y$ satisfy the description in the exercise, but they are not logical equivalent.\n\n\\declareexercise{a.1.5}\nYes. (Now I'm using the symbols defined in the A.2 for the sake of simplification)\n$X \\Longleftrightarrow Y$ means $X \\Longrightarrow Y \\wedge \\neg X \\Longrightarrow \\neg Y$. So does $Y$ and \n$Z$. So \n\\begin{align*}\n(X \\Longrightarrow Y \\Longrightarrow Z \\wedge \\neg X \\Longrightarrow \\neg Y \\Longrightarrow \\neg Z)\n&\\Longrightarrow \\\\\n(X \\Longrightarrow Z \\wedge \\neg X \\Longrightarrow \\neg Z)\n\\end{align*}\n, which means $X$ and $Z$ are logical equivalent.\n\n(Note that $A \\Longrightarrow B$ can also be interpreted as a statement, meaning ``If $A$ is true, then $B$ \nis true'', just like we did in this example.)\n\n\\declareexercise{a.1.6}\nYes. $(X \\Longrightarrow Y \\Longrightarrow Z) \\Longrightarrow (X \\Longrightarrow Z)$. \n\nNow we are proving that \n$Z \\Longrightarrow X \\equiv \\neg X \\Longrightarrow \\neg Z$. Assume that $\\neg X \\wedge Z$. Since \n$Z \\Longrightarrow X$, we have a contradiction: $X \\wedge \\neg X$.\n\nSo $X \\Longrightarrow Z \\wedge \\neg X \\Longrightarrow \\neg Z$. Therefore, $X,Z$ are logical equivalent. \nBesides, we can conclude that $Y \\Longrightarrow X$. Thus $X,Y$ are also logical equivalent.\n\n\\subsection{Implication}\nWhy did Tao say\n\\begin{quotation}\nIf $X$, then $Y$ can also be written as ``$X$ can only be true when $Y$ is true''\n\\end{quotation}?\n\nAssume the $X \\wedge \\neg Y$, but $X \\Longrightarrow Y$. So we have a contradiction \n$Y \\wedge \\neg Y$.\n\nDefine ``when $x \\neq 2$, $X:x=2 \\Longrightarrow x^2=4$ is vacuously true'' to ensure that $X$ is \nalways true regardless of the value of $x$.\n\n\\paragraph{My Own Exercise}\nMost of the time, rules of implication are intuitive. But they can be confusing some times. So hereby I \nintroduce an example which I encountered, and which has confused me for a short time.\n\n\\begin{prop}\nLet $P,Q,R$ be statements, thus\n\\[\nP \\Longrightarrow (Q \\Longrightarrow R) \\equiv (P \\wedge Q) \\Longrightarrow R\n\\]\n\\end{prop}\n\\begin{proof}\nIn order to ascertain that two statements in the form of implication are logically equivalent, we must \ndeeply understand what they are. At one time (that is, when all variables have definite value), a \nstatement can only be either true or false, not both. And for a statement in the form of implication: \n$X \\Longrightarrow Y$, it is true iff (\\emph{If} $X$, then $Y$). We do not need to check it if $X$ is \nnot true.\n\nNow back to the subject. To prove that the two are logically equivalent, we need to show that both \n(if the former is true, then the latter is true) and (if the latter is true, then the former is true).\n\nNow suppose that $P \\Longrightarrow (Q \\Longrightarrow R)$ is true. That is, if $P$, then \n(if $Q$, then $R$). To show that under this condition the latter is true, we need to show that if $P,Q$ \nare both true, then $R$ is true. Suppose that $P \\wedge Q$. Since $P$ is true, (if $Q$, then $R$) is \ntrue. And we know that $Q$ is true, so $R$ is true. so the latter is true.\n\nNow suppose that the latter is true. We need to verify that the former is also true under this \ncondition. Suppose $P$ is true, then we need to show $Q \\Longrightarrow R$ is true, that is, if $Q$, \nthen $R$, and we furthermore suppose that $Q$ is true. Now $P \\wedge Q$ is true, so we have $R$ is true.\n\\end{proof}\n\n\\subsection{Nested Quantifiers}\n\\declareexercise{a.5.1}\n\\textbf{(a)} Let $P$ be $y^2=x$ is true for each positive number $y$. And this statement means $P$ is \ntrue for each positive number $x$. \n\n\\emph{Gaming metaphor}: Me and my friend each randomly pick up a positive, say $x$ and $y$, and check \nif $y^2=x$.\n\nThe statement is false.\n\n\\textbf{(b)} There is at least one positive number $x$ such that for every positive number $y$, \n$y^2=x$.\n\n\\emph{Gaming metaphor}: I have to pick up a positive number $x$ such that whatever positive number $y$ \nmy friend picks up, $y^2=x$ is always true.\n\nThe statement is false.\n\n\\textbf{(c)} There is at least two positive numbers $x,y$ such that $y^2=x$.\n\n\\emph{Gaming metaphor}: Me and my friend each have to pick up a positive number, say $x$ and $y$, such \nthat $y^2=x$.\n\nThe statement is true. For example, $1^2=1$.\n\n\\textbf{(d)} The statement $\\exists x > 0, y^2=x$ is true for every $y>0$.\n\n\\emph{Gaming metaphor}: For each positive number $y$ my friend picks up, I have to pick up a positive \nnumber $x$ such that $y^2=x$.\n\nThe statement is true, because $y^2$ is also positive.\n\n\\textbf{(e)} There is at least one positive number $y$ such that for every positive number $x$, $y^2=x$ \nis always true.\n\n\\emph{Gaming metaphor}: I have to find a number $y>0$ such that regardless of what number $x$ my friend \npicks up, $y^2=x$ is always true.\n\nThe statement is false.\n\n\\subsection{Equality}\n\\declareexercise{a.7.1}\n\\begin{proof}\nLet $F(x) := x+c$. By axiom 4, $F(a)=F(b)$. That is, $a+c=b+c$. Similarly, by letting $G(x) := a+x$, \nwe have $a+c=a+d$, which, according to axiom 2, becomes $a+d=a+c$. Now we have $a+d=a+c, a+c=b+c$. \nAccording to axiom 3, we can conclude that $a+d=b+c$.\n\\end{proof}", "meta": {"hexsha": "19f724ddd88ad6d2f346cd1b39441803eeb8f122", "size": 5752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematical Logic.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": "Mathematical Logic.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": "Mathematical Logic.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": 41.0857142857, "max_line_length": 108, "alphanum_fraction": 0.702364395, "num_tokens": 1722, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797148356995, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7612756548203448}}
{"text": "\\chapter{Integral}\n\n\\section{Measure}\n\nA \\emph{Jordan content} is...\n\n\\index{content (measure theory)}%\nA \\emph{content} \\(m : 2^A \\to \\Real\\) satisfies\n\\begin{enumerate*}[label={(\\arabic*)}]\n    \\item \\(\\forall x \\in A : m~x \\ge 0\\),\n    \\item \\(m~\\emptyset = 0\\), and\n    \\item \\(\\forall X \\subseteq A, Y \\subseteq A, X \\cap Y = \\emptyset : m~(X \\cup Y) = m~X + m~Y\\).\n\\end{enumerate*}\n\n\\index{measure}%\n\\index{countably additive}%\n\\index{countable additivity}%\nA \\emph{measure} \\(m\\) on a set \\(A\\) is a content that is \\emph{countably additive}.\n\n\\index{Lebesgue measure}%\n\\index{measure!Lebesgue}%\nA \\emph{Lebesgue measure} for \\(\\Real\\) is\n\\(m~(a,b) = m~[a,b) = m~(a,b] = m~[a,b] = |b-a|\\).\nFrom a measure \\(m : \\Real \\to \\Real\\)\nwe can define a measure \\(\\mu : \\Real^n \\to \\Real\\)\nwhere\n\\(\\mu \\left( \\prod_{i=1}^n X_i \\right) = \\prod_{i=1}^n m(X_i)\\).\n\\index{measure space}%\n\\index{measure!space}%\n\\index{space!measure}%\nA \\emph{measure space} is a set and a measure on that set.\n\n\\index{measurable function}%\n\\index{function!measurable}%\nA \\emph{measurable function} is ...\n\n\\section{Integral}\n\n\\index{integral}%\n\\index{integral!Lebesgue}%\n\\index{integral!Riemann}%\n\\index{Lebesgue integral}%\n\\index{Riemann integral}%\nLet \\((\\Real,m)\\) be a measure space and \\(f\\) be a function.\nLet \\(X \\subseteq \\Real\\) and \\(Y = \\{ f(x) ~|~ x \\in X\\}\\).\nLet \\(X_1,\\ldots,X_n\\) be a partitioning of \\(X\\) and \\(Y_1,\\ldots,Y_n\\) be a partitioning of \\(Y\\).\nFor each \\(k\\), let \\(x_k \\in X_k\\) and \\(y_k \\in Y_k\\).\nAn \\emph{integral of \\(f\\) in \\(X\\)}\nis \\(\\int_X f = \\lim_{n\\to\\infty} \\sum_{k=1}^{n} a_k\\)\nwhere each \\(a_k = m(X_k) \\cdot m(Y_k)\\) is a rectangular part of the total area.\nSee Table \\ref{tab:integral}.\n\n\\begin{table}[h]\n    \\caption{How integrals partition spaces}\n    \\label{tab:integral}\n    \\centering\n\\begin{tabular}{lll}\n    Name & \\(X_k\\) & \\(Y_k\\)\n    \\\\\n    \\hline\n    Riemann integral & \\( [x_k,x_{k+1}]\\) & \\( [0,f(x_k)]\\)\n    \\\\\n    Stieltjes integral with respect to \\(g\\) & \\( [g(x_k),g(x_{k+1})]\\) & \\( [0,f(x_k)]\\)\n    \\\\\n    Lebesgue integral & \\( \\{x ~|~ f(x) \\in Y_k\\}\\) & \\( [y_k,y_{k+1}]\\)\n\\end{tabular}\n\\end{table}\n\n\\section{Calculus}\n\n\\index{fundamental theorem of calculus}%\n\\emph{Fundamental theorem of calculus}:\nIff \\(D(F) = f\\), then \\(I(f) = F + c\\) where \\(c\\) is a constant function,\n\\(D\\) is the derivative operator, \\(I\\) is the antiderivative operator.\n", "meta": {"hexsha": "937d0c79200b146b564feee8940b3842c7683749", "size": 2396, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "research/integral.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/integral.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/integral.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.9466666667, "max_line_length": 100, "alphanum_fraction": 0.6156093489, "num_tokens": 901, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797124237604, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7612756490726957}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Encrypt the message ``Rendezvous at dawn'' using the Hill cipher with\n  block size 3 and encryption matrix\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{ccc}\n      2 & 1 & 1 \\\\\n      1 & 3 & 1 \\\\\n      1 & 1 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    Ciphertext: $\\q{ZRUJPZVAEJTWOXGJZV}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Decrypt the message $\\q{ERM DXYBJUWW.JWQLD,HL}$ using the Hill\n  cipher with block size $3$ and encryption matrix\n  \\begin{equation*}\n    A ~=~ \\begin{mymatrix}{ccc}\n      2 & 1 & 1 \\\\\n      1 & 3 & 1 \\\\\n      1 & 1 & 4 \\\\\n    \\end{mymatrix}.\n  \\end{equation*}\n  \\begin{sol}\n    The decryption matrix is\n    \\begin{equation*}\n      A^{-1} ~=~ \\begin{mymatrix}{ccc}\n        16 & 22 &  5 \\\\\n        22 & 26 & 17 \\\\\n        5  & 17 &  2 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    Plaintext: ``Spies are at the gate''.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Eve intercepts the following encrypted message sent by Bob:\n  \\begin{center}\n    \\q{TGVXKHGSW,JU,JHYJSCDSBQIRPEV}\n  \\end{center}\n  Eve knows that Alice uses a Hill cipher with block length 2, but she\n  does not know the secret encryption matrix. Eve also knows that\n  Bob begins all of his letters with ``Hello''. Decrypt the message.\n  \\begin{sol}\n    The first two plaintext blocks are $(8,5),(12,12)$ and the first\n    two ciphertext blocks are $(20,7),(22,24)$. Eve solves the equation\n    \\begin{equation*}\n      A^{-1} \\begin{mymatrix}{cc} 20 & 22 \\\\ 7 & 24 \\end{mymatrix}\n      = \\begin{mymatrix}{cc} 8 & 12 \\\\ 5 & 12 \\end{mymatrix}\n    \\end{equation*}\n    to find the secret decryption matrix\n    \\begin{equation*}\n      A^{-1} = \\begin{mymatrix}{cc} 3 & 5 \\\\ 1 & 2 \\end{mymatrix}.\n    \\end{equation*}\n    The plaintext is ``Hello, password is kiwifruit''.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Encrypt the message ``Lost contact'' using the block cipher of\n  Definition~\\ref{def:toy-block-cipher} and the key\n  $2,3,4,1,1,1,5,5,5,4,3,2$.\n  \\begin{sol}\n    Ciphertext: $\\q{VXUAJYY,AFJE}$.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Decrypt the message $\\q{NRQEUAPOM GLFN}$, using the block cipher of\n  Definition~\\ref{def:toy-block-cipher} and the key\n  $1,1,1,2,2,2,3,3,3,4,4,4$. \\textbf{Hint:} To decrypt, we must\n  perform all the encryption steps in reverse. To undo a key mixing\n  step, we subtract the relevant key components. To undo an S-box\n  application, we apply the S-box in reverse. To undo a diffusion\n  step, multiply by the inverse of the diffusion matrix.\n  \\begin{sol}\n    The inverse of the diffusion matrix is\n    \\begin{equation*}\n      A^{-1} = \\begin{mymatrix}{ccc}\n        11 & 2 & 21 \\\\\n        21 & 11 & 2 \\\\\n        2 & 21 & 11 \\\\\n      \\end{mymatrix}.\n    \\end{equation*}\n    The plaintext is: ``Eat more fruit''.\n  \\end{sol}\n\\end{ex}\n", "meta": {"hexsha": "8b4da2124ee2bdfeb444d1c3d4eb11ff74d6ffe2", "size": 2796, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-Application-Cryptography.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-Application-Cryptography.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-Application-Cryptography.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.064516129, "max_line_length": 71, "alphanum_fraction": 0.6151645207, "num_tokens": 1010, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797100118214, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7612756451913035}}
{"text": "\\subsection{Partial fraction decomposition}\n\nWe have:\n\\(\\dfrac{1}{A.B}\\)\n\nWe want this in the form of:\n\n\\(\\dfrac{a}{A}+\\dfrac{b}{B}\\)\n\nFirst, lets define \\(M\\) as the mean of these two numbers, and define \\(\\delta=M-B\\). Then:\n\n\\(\\dfrac{1}{AB}=\\dfrac{1}{(M+\\delta)(M-\\delta)}=\\dfrac{a}{M+\\delta}+\\dfrac{b}{M-\\delta}\\)\n\nWe can rearrange the latter two to find:\n\n\\(1=a(M-\\delta)+b(M+\\delta)\\)\n\nNow we need to find values of \\(a\\) and \\(b\\) to choose.\n\nLet's examine \\(a\\).\n\n\\(a=\\dfrac{1-b(M+\\delta)}{M-\\delta}\\)\n\n\\(a=-\\dfrac{bM+b\\delta -1}{M-\\delta}\\)\n\n\\(a=-\\dfrac{bM+b\\delta -1}{M-\\delta}\\)\n\nFor this to divide neatly we need both the numerator to be a constant multiplier of the denominator. This means the ratio the multiplier for the left hand side of the denominator is equal to the right:\n\n\\(\\dfrac{bM}{M}=\\dfrac{b\\delta -1}{-\\delta}\\)\n\n\\(b=\\dfrac{b\\delta -1}{-\\delta}\\)\n\n\\(b=\\dfrac{1}{2\\delta}\\)\n\nWe can do the same for \\(a\\).\n\n\\(a=-\\dfrac{1}{2\\delta}\\)\n\nWe can plug these back into our original formula:\n\n\\(\\dfrac{1}{(M+\\delta)(M-\\delta)}=\\dfrac{-\\dfrac{1}{2\\delta}}{M+\\delta}+\\dfrac{\\dfrac{1}{2\\delta}}{M-\\delta}\\)\n\n\\(\\dfrac{1}{(M+\\delta)(M-\\delta)}=\\dfrac{1}{2\\delta}[\\dfrac{1}{M-\\delta}-\\dfrac{1}{M+\\delta}]\\)\n\n", "meta": {"hexsha": "db244e0a882dec8e1c1e8d3f0a811263fc7b0f06", "size": 1220, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/algebra/rational/01-06-PFD.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/algebra/rational/01-06-PFD.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/algebra/rational/01-06-PFD.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.5217391304, "max_line_length": 201, "alphanum_fraction": 0.6262295082, "num_tokens": 451, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9284088084787998, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.7611961950751944}}
{"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}{n!}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\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| \\frac{n+1}{(n+1)!} \\cdot\\frac{n!}{n} \\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\frac{n+1}{(n+1) \\cdot n!} \\cdot\\frac{n!}{n} \\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\frac1n \\right|\\\\\r\n&= \\lim_{n \\to \\infty}  \\frac1n \\\\\r\n&= 0\r\n\\end{align*}\r\nSince $L < 1$, by the Ratio Test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n}{n!}$ converges absolutely.\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": "0d8d8caa3d93bb40cdb4a4eb7232458af601e764", "size": 1504, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/m5.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/m5.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/m5.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": 28.3773584906, "max_line_length": 114, "alphanum_fraction": 0.6050531915, "num_tokens": 583, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.7611264351416597}}
{"text": "\\lab{Eigenvalue Solvers And Markov Chains}{Eigenvalue Solvers And Markov Chains}\n\\objective{Implement the power method and QR algorithm for finding eigenvalues, and use the power method to find the stationary distributions of Markov chains.}\n\\label{lab:EigSolve}\n\n\\section*{Computing eigenvalues}\nThe eigenvalues of a matrix are the roots of its characteristic polynomial. \nThus, to find the eigenvalues of an $n \\times n$ matrix, we must compute the roots of a degree-$n$ polynomial. \nThis is easy for small $n$. \nFor example, if $n=2$ the quadratic equation can be used to find the eigenvalues. \nHowever, Abel's Impossibility Theorem says that no such formula exists for the roots of a polynomial of degree 5 or larger.\n\n\\begin{theorem}[Abel's Impossibility Theorem]\nThere is no general algebraic solution for solving a polynomial equation of degree $n\\geq5$.\n\\label{thm:Abel}\n\\end{theorem}\n\nThus, it is impossible to write an algorithm that will exactly find the eigenvalues of an arbitrary matrix. \n(If we could write such an algorithm, we could also use it to find the roots of polynomials, contradicting Abel's theorem.) \nThis is a significant result. \nIt means that we must find eigenvalues with \\emph{iterative methods}, methods that generate sequences of approximate values converging to the true value.\n\n\\subsection*{The power method}\nThere are many iterative methods for finding eigenvalues. \nThe power method finds an eigenvector corresponding to the \\emph{dominant} eigenvalue of a matrix, if such an eigenvalue exists.\nThe dominant eigenvalue of a matrix is the unique eigenvalue of greatest magnitude.\n\nTo use the power method on a matrix $A$, begin by choosing a vector $\\x_0$ such that $\\|\\x_0\\|=1$. Then recursively define\n\\[\nx_{k+1}=\\frac{Ax_k}{\\norm{Ax_k}}.\n\\]\nIf \n\\begin{itemize}\n\\item $A$ has a dominant eigenvalue $\\lambda$, and\n\\item the projection of $\\x_0$ into the subspace spanned by the eigenvectors corresponding to $\\lambda$ is nonzero,\n\\end{itemize}\nthen the vectors $\\x_0, \\x_1, \\x_2, \\ldots$ will converge to an eigenvector of $A$ corresponding to $\\lambda$. \n(See [TODO: ref textbook] for a proof when $A$ is semisimple, or [TODO: ref something else] for a proof in the general case.)\n\nIf all entries of $A$ are positive, then $A$ will always have a dominant eigenvalue (see [TODO: ref something!] for a proof). \nThere is no way to guarantee that the second condition is met, but if we choose $\\x_0$ randomly, it will almost always satisfy this condition.\n\nOnce you know that $\\x$ is an eigenvector of $A$, the corresponding eigenvalue is equal to the \\emph{Raleigh quotient}\n\\[\n\\lambda = \\frac{\\langle Ax, x \\rangle}{\\|\\x\\|^2}.\n\\]\n\n\n\n\\begin{problem}\nWrite a function that implements the power method to compute an eigenvector. Your function should\n\\begin{enumerate}\n\\item Accept a matrix and a tolerance \\li{tol}.\n\\item Start with a random vector.\n\\item Use the 2-norm wherever a norm is needed (use \\li{la.norm()}).\n\\item Repeat the power method until the vector changes by less than the tolerance. In mathematical notation, you are defining $x_0, x_1, \\ldots x_k$, and your function should stop when $\\|x_{k+1}-x_k\\| < \\text{tol}$.\n\\item Return the found eigenvector and the corresponding eigenvalue (use \\li{np.inner()}).\n\\end{enumerate} \nTest your function on positive matrices.\n\\end{problem}\n\n\\begin{comment}\nAn overview of the proof of the method is that you can write a matrix in Jordan Conical form $A=VJV^{-1}$ where $V$ is the matrix of the generalized eigenspaces. \nBut the first column is is the eigenvector corresponding to largest eigenvalue and $J$ is a upper trianglar matrix of eigenvalues and ones.\nNote that $A^k=VJ^kV^{-1}$. The limit as $k \\rightarrow \\infty$ of $(\\frac{1}{\\lambda_1}J)^k$ is a matrix of all zeros except for a one in the upper right hand corner. \nSo $(\\frac{A}{\\norm{A}})^k \\approx VJ^kV^{-1}$ So the largest eigenvalue dominates.\n\\end{comment}\n\n\\subsection*{The QR algorithm}\nThe disadvantage of the power method is that it only finds the largest eigenvector and a corresponding eigenvalue. \nTo use the QR algorithm, let $A_0=A$. Then let $Q_kR_k$ be the QR decomposition of $A_k$, and recursively define \n\\[\nA_{k+1}=R_kQ_k.\n\\] \nThen $A_0, A_1, A_2, \\ldots $ will converge to a matrix of the form\n\\begin{equation*}\n\\label{eq:Schur form}\nS =\n     \\begin{pmatrix}\n          S_1 &* & \\cdots & * \\\\\n           0     &S_2  &  \\ddots & \\vdots \\\\\n           \\vdots  & \\ddots & \\ddots & *  \\\\\n           0 & \\cdots & 0 & S_m\n    \\end{pmatrix}\n\\end{equation*}\nwhere $S_i$ is a $1\\times1$ or $2\\times2$ matrix.\\footnote{If $S$ is upper triangular (i.e., all $S_i$ are $1\\times1$ matrices), then $S$ is the \\emph{Schur form} of $A$. \nIf some $S_i$ are $2\\times2$ matrices, then $S$ is the \\emph{real Schur form} of $A$.} \nThe eigenvalues of $A$ are the eigenvalues of the $S_i$.\n\nThis algorithm works for three reasons. First, \n\\[\nQ_k^{-1}A_kQ_k = Q_k^{-1}(Q_kR_k)Q_k = (Q_k^{-1}Q_k)(R_kQ_k) = A_{k+1},\n\\]\nso $A_k$ is similar to $A_{k+1}$. \nBecause similar matrices have the same eigenvalues, $A_k$ has the same eigenvalues as $A$. \nSecond, each iteration of the algorithm transfers some of the ``mass'' from the lower to the upper triangle. \nThis is what makes $A_0, A_1, A_2, \\ldots$ converge to a matrix $S$ which has the described form. \nFinally, since $S$ is block upper triangular, its eigenvalues are just the eigenvalues of its diagonal blocks (the $S_i$).\n\nA $2 \\times 2$ block will occur in $S$ when $A$ is real but has complex eigenvalues. \nIn this case, the complex eigenvalues occur in conjugate pairs, each pair corresponding to a $2 \\times 2$ block on the diagonal of $S$.\n\n\n\\subsubsection*{Hessenberg preconditioning}\nOften, we ``precondition'' a matrix by putting it in upper Hessenberg form before passing it to the QR algorithm. \nThis is always possible because every matrix is similar to an upper Hessenberg matrix (see Lab \\ref{}). \nHessenberg preconditioning is done for two reasons.\n\nFirst, the QR algorithm converges much faster on upper Hessenberg matrices because they are already close to triangular matrices. \n\nSecond, an iteration of the QR algorithm can be computed in $\\mathcal{O}(n^2)$ time on an upper Hessenberg matrix, as opposed to $\\mathcal{O}(n^3)$ time on a regular matrix. \nThis is because so many entries of an upper Hessenberg matrix are 0.\nIf we apply the QR algorithm to an upper Hessenberg matrix $H$, then this speed-up happens in each iteration of the algorithm, since if $H = QR$ is the QR decomposition of $H$ then $RQ$ is also upper Hessenberg.\n\n\n\\begin{problem}\nWrite a function that implements the QR algorithm with Hessenberg preconditioning as described above. \nDo this as follows.\n\\begin{enumerate}\n\\item Accept a matrix \\li{A}, a number of iterations \\li{niter}, and a tolerance \\li{tol}\n\\item Put \\li{A} in Hessenberg form using \\li{la.hessenberg()}.\n\\item Compute the matrix $S$ by performing the QR algorithm \\li{niter} times. \nUse the function \\li{la.qr()} to compute the QR decomposition.\n\\item Iterate through the diagonal of $S$ from top to bottom to compute its eigenvalues. \nFor each diagonal entry,\n\\begin{enumerate}\n\\item If this is the last diagonal entry, then it is an eigenvalue.\n\\item If the entry below this one has absolute value less than \\li{tol}, assume this is a $1\\times 1$ block. \nThen the current entry is an eigenvalue.\n\\item Otherwise, the current entry is at the top left corner of a $2 \\times 2$ block. \nCalculate the eigenvalues of this block. \nUse the \\li{sqrt} function from the scimath library to find the square root of a negative number. \nYou can import this library with the line \\li{from numpy.lib import scimath}.\n\\end{enumerate}\n\\item Return the (approximate) eigenvalues of \\li{A}.\n\\end{enumerate}\nYou can check your function on the matrix\n\\[\n\\begin{pmatrix}\n 4 &  12 & 17 &  -2 \\\\\n-5.5& -30.5 & -45.5 &  9.5\\\\\n 3. &  20. & 30. &  -6. \\\\\n1.5 &  1.5&   1.5&   1.5\n       \\end{pmatrix},\n\\]\nwhich has eigenvalues $1+2i, 1-2i, 3$, and 0. You can also check your function on random matrices against \\li{la.eig()}.\n\\label{prob:qr_solver}\n\\end{problem}\n\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:QR_eig_hessenberg}\nWrite a version of the QR algorithm that performs the QR algorithm by computing the Hessenberg form of a matrix, then computing various QR decompositions of the Hessenberg form of the matrix.\nUse your solutions to \\ref{prob:hessenberg} (where you computed the Hessenberg form of a matrix) and Problem \\ref{prob:givens_hessenberg_modified} to do the necessary computations (where you computed the QR decomposition of a Hessenberg matrix and wrote code for multiplication by $Q$ that works in $\\mathcal{O} \\left( n^2 \\right)$ time).\nThe solution to Problem \\ref{prob:givens_hessenberg_modified} is especially important because it allows the compution of each QR decomposition and each $R Q = \\left( Q^T R^T \\right)$ in $\\mathcal{O} \\left( n^2 \\right)$ time.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nIf $A$ is normal, its Schur form is diagonal.\nFor normal $A$, have your function additionally output the eigenvector corresponding to each eigenvalue.\nHint 1: Test your function on Hermitian and real symmetric matrices; they are both normal.\nHint 2: Your work in Problem \\ref{problem:similarity proof} will help.\nYou have already made all the necessary calculations, you just need to store the information correctly.\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\begin{problem}\nTest your implementation with random matrices.\nTry real-valued and symmetric matrices.\nCompare your output to the output from the eigenvalue solver.\nHow many iterations are necessary?\nHow large can $A$ be?\n\\end{problem}\n\\end{comment}\n\nThe QR algorithm as described in this lab is not often used. \nInstead, modern computer packages use the implicit QR algorithm, which is an improved version of the QR algorithm.\n\nLastly, iterative methods besides the power method and QR method are often used to find eigenvalues.\nArnoldi iteration is similar to the QR algorithm but exploits sparsity.\nOther methods include the Jacobi method and the Rayleigh quotient method.\n\n\\section*{Markov chains (application of the power method)}\nA Markov chain is a collection of states with specified probabilities for transitioning from one state to another.\nMarkov chains are characterized by the fact that future behavior of the system depends only on its current state.\n\nThis lab is a very brief introduction to Markov chains. To learn more, see [TODO: ref something].\n\n\\subsection*{An example}\nSuppose Fredo the frog is jumping between the three lily pads 1, 2, and 3.\nThese three pads are the \\emph{possible states} of the system, and the lily pad on which Fredo is presently sitting is the \\emph{current state}.\nIf Fredo is on lily pad 1 and jumps, there is a 25\\% chance that it will land back on lily pad 1, a 25\\% chance that it will land on lily pad 2, and a 50\\% chance that it will land on lily pad 3.\nThese probabilities are the \\emph{transition probabilities}.\nFigure \\ref{fig:markov1} is a \\emph{transition diagram} that depicts all transition probabilities.\n\n\\begin{figure}\n\\begin{tikzpicture}[normalcircle/.style={draw, circle, minimum size=1cm, fill=shadecolor, thick, node distance=1.5cm} ]\n\n\\node[normalcircle](circle1)[]{};\n\\node[draw=none](one)[]{1};\n\n\\node[draw=none, node distance=2.5cm](dummy)\n\t[below of=circle1]{};\n\n\\node[normalcircle](circle2)[left of=dummy]{};\n\\node[draw=none, node distance= 1.5cm](two)[left \n\tof=dummy]{2};\n\\node[normalcircle](circle3)[right of=dummy]{};\n\\node[draw=none, node distance= 1.5cm](three)\n\t[right of=dummy]{3};\n\n\\foreach \\s /\\t in {circle2/circle1, circle1/circle3, circle3/circle2}\n\t{\\path[draw,bend left=20, thick, ->, >=stealth'] (\\s)edge(\\t);}\n\\foreach \\s /\\t in {circle1/circle2, circle3/circle1, circle2/circle3}\n\t{\\path[draw,bend left=20, thick, ->, >=stealth'] (\\s)edge(\\t);}\n\n\\draw[thick,->, >=stealth'](-1.9,-2.8) arc (325:40:.4 and .5); \n\\draw[thick,->, >=stealth'](1.9,-2.2) arc (500:215:.4 and .5); \n\\draw[thick,->, >=stealth'](-.4,.3) arc (220:-35:.5 and .4); \n\n\\node[draw=none, node distance=1.6cm](dummy2)\n\t[below of=circle1]{};\n\\node[draw= none, node distance=.3cm](midvalues)\n\t[above left of=dummy2]{$\\frac{1}{4}$};\n\\node[draw= none, node distance=.3cm](midvalues2)\n\t[above right of=dummy2]{$\\frac{1}{2}$};\n\\node[draw= none, node distance=.25cm](midvalues3)\n\t[below of=dummy2]{$\\frac{1}{3}$};\n\\node[draw=none, node distance=1.6cm](outsidevalue)\n\t[above left of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.6cm](outsidevalue2)\n\t[above right of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.35cm](outsidevalue3)\n\t[below of=midvalues3]{$\\frac{1}{2}$};\n\\node[draw=none, node distance=1.25cm](circlevalue)\n\t[above of=circle1]{$\\frac{1}{4}$};\n\\node[draw=none, node distance=2.8cm](circlevalue2)\n\t[left of=dummy]{$\\frac{1}{6}$};\n\\node[draw=none, node distance=2.8cm](circlevalue3)\n\t[right of=dummy]{$0$};\n\n\\end{tikzpicture}\n\\caption{Transition diagram for Fredo the Frog.}\n\\label{fig:markov1}\n\\end{figure}\n\nWe can convert our transition diagram into a \\emph{transition matrix} The $(i,j)$-entry of the transition matrix is the probability that Fredo jumps from lily pad $j$ to lily pad $i$.\nFredo's transition matrix is\n\\[\nA = \\begin{pmatrix}\n1/4 & 1/2 & 1/2\\\\\n1/4 & 1/6 & 1/2\\\\\n1/2 & 1/3 & 0\n\\end{pmatrix}.\n\\]\n\nAt any time, the chances that Fredo is on each lily pad is encoded by a \\emph{state distribution vector} $\\x = (x_1, x_2, x_3)^T$, where $x_i$ is the probability that Fredo is on lily pad $i$. \nFor $\\x$ to be a state distribution vector, we require $x_i\\geq 0$ and $\\|\\x\\|_1=1$ (recall that the 1-norm of a column vector is the sum of the magnitudes of its entries). \nThen $A\\x$ will be another state distribution vector, which tells us the probability that Fredo is on each lily pad after one jump.\n\nThus, we can use Fredo's transition matrix to find where he will be after $k$ jumps. In fact, the $(i,j)$-entry of $A^k$ is the probability that Fredo goes from lily pad $j$ to lily pad $i$ in $k$ jumps. \nIn our case,\n\n\\[\nA^2 \\approx \\begin{pmatrix}\n0.4375 & 0.3750 & 0.3750\\\\\n0.3542 & 0.3194 & 0.2083\\\\\n0.2083 & 0.3056 & 0.4167\n\\end{pmatrix}.\n\\]\nTherefore, if Fredo starts on lily pad 1, there is a 43.75\\% chance it will still be on lily pad 1 after two jumps.\nMaybe Fredo jumped from 1 to 1 to 1, denoted $1 \\rightarrow 1 \\rightarrow 1$, or perhaps it jumped to one of the other lily pads and then back again, that is, either $1 \\rightarrow 2 \\rightarrow 1$ or $1 \\rightarrow 3 \\rightarrow 1$.\n\nIn addition, there is a 35.42\\% chance Fredo will be on lily pad 2 and a 20.83\\% chance that it will be on lily pad 3.\nWe can type our transition matrix into Python and see where Fredo is likely to be after any number of jumps.\n\n\\begin{lstlisting}\n# The 1.'s in the numerator force floating point division.\n>>> A = np.array([[1./4,1./2,1./2],[1./4,1./6,1./2],[1./2,1./3,0]])\n>>> np.linalg.matrix_power(A,10)\narray([[ 0.40000057,  0.39999962,  0.39999962],\n       [ 0.30002369,  0.29999268,  0.29997574],\n       [ 0.29997574,  0.3000077 ,  0.30002464]])\n\\end{lstlisting}\n\nIn fact, as we take higher and higher powers of $A$, it appears that \n\\[\n\\lim_{k \\rightarrow \\infty} A^k = \\begin{pmatrix}\n0.4 & 0.4 & 0.4\\\\\n0.3 & 0.3 & 0.3\\\\\n0.3 & 0.3 & 0.3\n\\end{pmatrix}.\n\\]\nThis means that Fredo's state distribution approaches $(0.4, 0.3, 0.3)^T$ after many jumps, regardless of his initial state distribution.\n\nMoreover, suppose Fredo's initial state distribution is $(0.4, 0.3, 0.3)^T$. \nWe can use Python to compute his state distribution after 1 jump.\n\\begin{lstlisting}\n>>> A.dot(np.array([0.4,0.3,0.3]))\narray([ 0.4,  0.3,  0.3])\n\\end{lstlisting} \nFredo's state distribution after a jump stays ``fixed.'' We call the vector $(0.4, 0.3, 0.3)^T$ a \\emph{stable fixed point} for Fredo.\n\n\n\\subsection*{General Markov chains}\nLet us generalize this example. A Markov chain is a collection of states with the probabilities that we will move from one state to another. \nThese transition probabilities are encoded in a transition matrix, whose $(i-j)$-entry is the probability of moving from state $j$ to state $i$. \nEach column of such a matrix will necessarily have entries that sum to 1. \n\n%When we have a Markov chain, we want to know what the state distribution is after our system has been running for some time. We are especially interested if the state distributions converge to something that is independent of the initial state, as was the case for Fredo. That is, we want to know about stable fixed points.\n\nLet $A$ be the transition matrix of a Markov chain. \nThen a state distribution vector $\\x$ is a \\emph{stable fixed point} if $A\\x=\\x$. \nSo $\\x$ is a stable fixed point if and only if $\\x$ is a positive unit eigenvector of $A$ corresponding to the eigenvalue 1. \n\n\nEvery Markov chain has at least one stable fixed point. \nIf in addition we assume some power $A^k$ of $A$ has all positive (nonzero) entries, then the stable fixed point is unique. \nIn this case, $A^k$ will converge to a matrix whose columns are all equal to the unique stable fixed point.\n\nNote that Fredo's transition matrix does not have positive entries, but its square does. \nSo Fredo has the unique stable fixed point $(0.4, 0.3, 0.3)^T$.\n\n\\subsection*{Finding stable fixed points}\nCalculating stable fixed points is an important problem in Markov chain analysis. \nSuppose a Markov chain has a transition matrix $A$ such that $A^k$ has strictly positive entries for some $k$. \nThen the \\emph{Perron-Frobenius theorem} says that 1 is the unique eigenvalue of $A$ of largest magnitude, and the corresponding eigenvector is unique. \nThis means that we can use the power method to find the unique stable fixed point of $A$.\n\nLet us look at what the power method is doing in the example of Fredo the frog. \nWe will use the 1-norm. \n\nSuppose we know Fredo starts on lily pad 1. Then we begin with the state distribution vector\n\\[\n\\x_0 = \\begin{bmatrix}\n1\\\\\n0\\\\\n0\n\\end{bmatrix}\n\\]\nbecause we know for certainty (100\\%) that Fredo is in the first state.\nThe next iteration of the power method is $\\x_1=A\\x_0/\\|A\\x_0\\|_1$. But since $\\|A\\x_0\\|_1=1$, this is just\n\\[\n\\x_1 = A \\x_0 = \\begin{bmatrix}\n0.25\\\\\n0.25\\\\\n0.50\n\\end{bmatrix},\n\\]\nwhich is exactly Fredo's state distribution after 1 jump.\nAfter two jumps, Fredo's state distribution is\n\\[\n\\x_2 = A \\x_1 = A^2 \\x_0 = \\begin{bmatrix}\n0.4375\\\\\n0.3542\\\\\n0.2083\n\\end{bmatrix},\n\\]\nwhich is also the second iteration of the power method.\nAfter a large number of jumps, we have\n\\[\n\\x_n = A \\x_{n-1} = \\dots = A^n \\x_0 \\approx \\begin{bmatrix}\n0.4\\\\\n0.3\\\\\n0.3\n\\end{bmatrix}.\n\\]\nThus, the limiting vector of the power method is exactly the unique stable fixed point of the Markov chain. \n\n\\subsection*{A final example}\nConsider the Markov chain with transition matrix\n\\[\nA = \\begin{pmatrix}\n0.5 & 0.3 & 0.4\\\\\n0.2 & 0.2 & 0.3\\\\\n0.3 & 0.5 & 0.3\n\\end{pmatrix}.\n\\]\n\nBecause all entries of $A$ are positive, the Markov chain has a unique stable fixed point. \nWe could find this fixed point with the power method as outlined above, or we can do it by computing eigenvalues and eigenvectors in Python, as shown below.\n\\begin{lstlisting}\n>>> from scipy import linalg as la\n>>> A = np.array([[.5,.3,.4],[.2,.2,.3],[.3,.5,.3]])\n>>> evals, evecs = la.eig(A)\n>>> evals\narray([ 1.        ,  0.14142136, -0.14142136])\n\\end{lstlisting}\nWe are interested in the eigenvalue 1, which is the first one outputted in this case. \nThe corresponding eigenvector is the first column of \\li{evecs}; let us call it \\li{x}.\n\\begin{lstlisting}\n>>> x = evecs[:,0]\n\\end{lstlisting}\nNow, the one-norm of \\li{x} will probably not be 1. To make it 1, we divide by the one-norm of \\li{x}.\n\\begin{lstlisting}\n>>>x = x/np.sum(x)\n\\end{lstlisting}\nFinally, let us check that \\li{x} is a stable fixed point of $A$. There are two things to check.\n\\begin{lstlisting}\n# Check Ax = x\n>>> np.allclose(A.dot(x),  x)\nTrue\n\n# Check ||x||_1 = 1\n>>> np.sum(x)==1\nTrue\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that accepts as input a transition matrix, a vector representing the initial state, and a number of iterations \\li{niter}. Your function should\n\\begin{enumerate}\n\\item Assume that the input matrix has a unique stable fixed point.\n\\item Calculate the unique stable fixed point by computing eigenvectors and eigenvalues in Python.\n\\item Return the current state of the Markov chain after \\li{niter} iterations and the stable fixed point.\n\\end{enumerate}\n\\label{prob:markov}\n\\end{problem}\n\n\\begin{problem}\nSuppose a basketball player's success at shooting free throws can be described with the following Markov chain\n\\[\nA = \\begin{pmatrix}.75&.50\\\\.25&.50\\end{pmatrix}\n\\]\nwhere the first state corresponds to success and the second state to failure. Use the function you wrote in Problem \\ref{prob:markov} to answer the following questions.\n\\begin{enumerate}\n\\item If the player makes his first free throw, what is the probability that he also makes his third one? \n(That is, what is the probability that this system starts in state 1 and is still in state 1 after 3 steps?)\n\\item What is the player's average free throw percentage? \n(This is equal to the success-component of the stable fixed point.)\n\\end{enumerate}\n\\label{prob:markov_freethrow}\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\nConsider the Markov process given by the transition diagram in Figure \\ref{fig:markov2}.\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{markov2}\n\\caption{Transition diagram}\n\\label{fig:markov2}\n\\end{figure}\n\n\\begin{enumerate}\n\\item Find the transition matrix.\n\\item If the Markov process is in state 1 initially, find the probability that it is in state 2 after two transitions.\n\\item Find the stable fixed point if it exists.\n\\end{enumerate}\n\\label{prob:markov_stablept}\n\\end{problem}\n\\end{comment}", "meta": {"hexsha": "51cdf1f26d8e274d79538fa3ce6ccc7dfb214e5c", "size": 21834, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/EigenvaluesMarkovChains/Eig.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 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/EigenvaluesMarkovChains/Eig.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/EigenvaluesMarkovChains/Eig.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 48.1986754967, "max_line_length": 338, "alphanum_fraction": 0.7313822479, "num_tokens": 6504, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.851952809486198, "lm_q2_score": 0.8933094110250331, "lm_q1q2_score": 0.7610574624632378}}
{"text": "\n\\section{Spherical Bessel Functions}\n\n\\label{sphericalbess}\nMatlab does not have built-in routines for spherical Bessel functions. Below are several variants of spherical Bessel functions and derivatives encountered in scattering problems.\n\n%Log derivatives. \n\n%\\bgroup\n%\\def\\arraystretch{3}\n%\\begin{table}[htdp]\n%\\caption{default}\n%\\begin{center}\n%\\begin{tabular}{|c|c|c|}\n%\\hline\n%Function & Equation & Comments \\\\\n%\\hline\n%\\texttt{jinc(x)}& $\\textrm{jinc}(x) = \\dfrac{J_1(x)}{x}$ & $\\lim_{x\\rightarrow0} \\textrm{jinc}(x) = \\dfrac{1}{2}$ \\\\\n%\\hline\n%\\texttt{sbesselj(n,x)} & $j_n(x) = \\sqrt{\\dfrac{\\pi}{2x}}J_{n+1/2}(x)$ & $\\lim_{x\\rightarrow0}j_n(x) = \\left\\{ \\begin{array}{c} 1, \\quad n=0 \\\\ 0, \\quad n \\ge 1\\end{array}  \\right.$  \\\\\n%\\hline\n%\\end{tabular}\n%\\end{center}\n%\\label{default}\n%\\end{table}\n%\\egroup\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Sombrero function: $\\textrm{jinc}(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe \\textrm{jinc}(x) function, or Sombrero function, is defined:\n\\begin{equation}\n\\textrm{jinc}(x) = \\dfrac{J_1(x)}{x}\n\\end{equation}\n%\n%\\noindent where\n%\\begin{equation}\n%\\lim_{z\\rightarrow0} \\textrm{jinc}(z) = \\dfrac{1}{2}\n%\\end{equation}\n\n\\noindent where small arguments are computed with the Taylor series \n\\eq{ \\textrm{jinc}(x) \\approx \\dfrac{1}{2} - \\dfrac{x^2}{16} + O(x^4)}\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/jinc.m}\n}\n\n%This is slow in Matlab and we'd like to avoid the division.  Start with the series representation for the Bessel function of complex argument\n%\\eq{J_{\\nu}(z) = \\left(\\dfrac{z}{2}\\right)^\\nu \\sum_{k=0}^{\\infty} \\dfrac{ (-1)^k \\left( \\dfrac{z}{2}\\right)^{2k} }{ k! \\Gamma(\\nu + k + 1)}}\n%\n%Evaluating $\\nu =1$, and dividing by $z$, \n%\\eq{\\textrm{jinc}(z) = \\dfrac{1}{2} \\sum_{k=0}^{\\infty}(-1)^k a_k }\n%\\eq{a_k = \\dfrac{  \\left( \\dfrac{z}{2}\\right)^{2k} }{ k! \\Gamma(k + 2)} }\n%\n%The log transform is used to avoid multiplying and dividing by large and small numbers, facilitate fast recursive of the factorials, and take care of the limit when $z = 0$.  \n%\\eq{a_k = e^{\\ln a_k}}\n%\n%where, using $\\Gamma(n) = (n-1)!$, \n%\\ea{\\ln a_k &=& 2k (\\ln z - \\ln 2) - \\ln k! - \\ln (k + 1)! }\n%\n%Evaluating at $k+1$, separating a factor of $\\ln a_k$, and shifting the index down by 1, we get the recursion for the $k$th term of the series\n%\\ea{\\ln a_{0} &=& 0 \\\\\n%\\ln a_{k} &=& \\ln a_{k-1} + 2 (\\ln z - \\ln 2) - \\ln k - \\ln (k + 1) }\n%\n%%\\ea{\\ln a_{k+1} &=& 2(k+1) (\\ln z - \\ln 2) - \\ln (k+1)! - \\ln (k + 2)! \\\\\n%%\\ &=& 2k (\\ln z - \\ln 2) + 2 (\\ln z - \\ln 2) - (\\ln k! + \\ln (k+1)) - ( \\ln (k + 1)!  + \\ln (k + 2) ) \\\\\n%%\\ &=& \\ln a_k + 2 (\\ln z - \\ln 2) - \\ln (k+1) - \\ln (k + 2) }\n%\n%The code is as follows.  \n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Bessel function: $j_n(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe spherical Bessel function is \n\n\\begin{equation}\nj_n(x) = \\sqrt{\\dfrac{\\pi}{2x}}J_{n+1/2}(x)\n\\end{equation}\n\n\\noindent where\n\n\\begin{equation}\n\\lim_{x\\rightarrow0}j_n(x) = \\left\\{ \\begin{array}{c} 1 - \\dfrac{x^2}{6} + O(x^4) \\quad n=0 \\\\ 0, \\quad n \\ge 1\\end{array}  \\right.\n\\end{equation}\n\nThe routine \\texttt{sbesselj} returns the spherical Bessel function for matching arrays of $n$ and $x$ in the format of \\texttt{besselj}. It uses the Taylor series near $x = 0$ for $n=0$, and substitutes 0 when $x=0$ for $n>1$.  \n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesselj.m}\n}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Bessel function: $j_n(x)/x$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\n\nThis variant of the spherical Bessel function has $j_n(x)$ divided by $x$: \n\\begin{equation}\n\\dfrac{j_n(x)}{x} = \\dfrac{1}{x^{3/2}}\\sqrt{\\dfrac{\\pi}{2}}J_{n+1/2}(x)\n\\end{equation}\n\n\\noindent where\n\\begin{equation}\n\\lim_{x\\rightarrow0}j_n(x) = \\left\\{ \\begin{array}{c} \\infty, \\quad n=0 \\\\ \\dfrac{1}{3} - \\dfrac{x^2}{30} + O(x^4), \\quad n = 1 \\\\ 0, \\quad n \\ge 2\\end{array}  \\right.\n\\end{equation}\n\nThis is computed in the routine \\texttt{sbesselj2}, which takes the same inputs as \\texttt{sbesselj}.  We let the routine return \\texttt{Inf} for $x=0$ when $n=0$.  This variant is found in electromagnetic scattering when usually the monopole term ($n=0$) is not needed.\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesselj2.m}\n}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Bessel function derivative: $j_n'(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe derivative of the spherical Bessel function with respect to $x$ is given by the recurrence relation\n\\begin{equation}\nj_n'(x) = -j_{n+1}(x) + \\dfrac{n}{x}j_n(x)\n\\end{equation}\n\nThis is computed in \\texttt{sbesseljp} with \\texttt{sbesselj} and \\texttt{sbesselj2}, which takes care of $x=0$. \n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesseljp.m}\n}\n\n\\clearpage\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Bessel function derivative: $[xj_n(x)]'$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThis variant occurs often enough in scattering to have its own function, \\texttt{sbesseljp2}, \n\\ea{[xj_n(x)]' &=& j_n(x) + x j'_n(x) \\\\\n\\ &=&  (1+n)j_n(x) - x j_{n+1}(x)}\n\nThis variant is found in the Mie scattering solution for spheres.\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesseljp2.m}\n}\n\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Hankel function: $h_n^{(1)}(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe spherical Hankel function is given by \n\\begin{equation}\nh_n^{(1)}(x) = \\sqrt{\\dfrac{\\pi}{2x}}H_{n+1/2}(x)\n\\end{equation}\n\nThis is always irregular at the origin, and computed in the routine \\texttt{sbesselh}\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesselh.m}\n}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Hankel function derivative: ${h'}_n^{(1)}(x)$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nThe spherical Hankel derivative is computed in the routine \\texttt{sbesselhp}\n\\begin{equation}\n{h'}_n^{(1)}(x) = -h_{n+1}^{(1)}(x) + \\dfrac{n}{x}h_n^{(1)}(x)\n\\end{equation}\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesselhp.m}\n}\n\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{1}}\n\\subsection{Spherical Hankel function derivative: $[xh_n^{(1)}(x)]'$}\n\\addtocontents{toc}{\\protect\\setcounter{tocdepth}{2}}\n\nSimilar to before, this variant is computed in the routine \\texttt{sbesselhp2}\n\\ea{[xh_n^{(1)}(x)]' &=& h_n^{(1)}(x) + x {h'}_n^{(1)}(x) \\\\\n\\ &=&  (1+n)h_n^{(1)}(x) - x h_{n+1}^{(1)}(x)}\n\nThis variant is found in the Mie scattering solution for spheres.\n\n\n{\\footnotesize\n\\VerbatimInput{\\code/BesselFunctions/sbesselhp2.m}\n}\n\n", "meta": {"hexsha": "df27eca6f53a6426fac3a4bf91a76bf9e812ff3d", "size": 6766, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/Utilities/BesselFunctions.tex", "max_stars_repo_name": "nasa-jpl/Waveport", "max_stars_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2021-08-29T13:29:21.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-18T20:09:47.000Z", "max_issues_repo_path": "Tex/Utilities/BesselFunctions.tex", "max_issues_repo_name": "ruzakb/Waveport", "max_issues_repo_head_hexsha": "caeb9540693185e000e08d826bc2ccabb6aa82bd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/Utilities/BesselFunctions.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": 35.6105263158, "max_line_length": 270, "alphanum_fraction": 0.6732190364, "num_tokens": 2510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094174159127, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.761057457834266}}
{"text": "\\subsection{Numerical Solutions for Burgers' Equation without Viscosity}\n\t\n\tTo finish the section, we will study the problem (\\ref{IVP_Burgers}) without viscosity, that is, when $\\alpha = 0$. So the problem is the following\n\t\\begin{align}\n\t\\label{IVP_Inviscid}\n\t\t\\left \\lbrace \\begin{array}{ll}\n\t\t\t\\frac{\\partial u}{\\partial t} + \\frac{1}{2} (u^2)_x = 0, \\hspace{2mm} 0 < t \\leq T, \\hspace{2mm} x \\in \\mathcal{D} \\\\\n\t\t\t\\\\\n\t\t\tu(x, 0) = u_0(x), \\hspace{2mm} x \\in \\mathcal{D}\n\t\t\\end{array}  \\right .\n\t\\end{align}\n\n\tThis problem, which seems much simpler, turns out to be very interesting, because it presents relevant characteristics regarding the physical interpretation of the problem in general, that is, the case with non-zero viscosity. \\\\\n\t\n\tThe previous equation interprets the conservation of energy and is considered as a non-linear conservation law. We can understand this if we consider the function $ u $ as the speed of a fluid that conserves its energy with a flow density given by $f(u) = \\frac{u^2} {2}$. \\\\\n\t\n\tThe above can be shown considering that $u \\in H^1_p [\\mathcal{D}]$, and multiplying by $u$ and integrating both sides of the equation on the domain $\\mathcal{D}$ to prove that $\\| u \\|$ does not change over time, that is,\n\t\\begin{align*}\n\t\t\\frac{1}{2} \\frac{d}{dt} \\displaystyle \\int_{0}^{2 \\pi} u^2(x, t) dx = - \\int_{0}^{2 \\pi} u^2(x, t) \\frac{\\partial u(x, t)}{\\partial x} dx = - \\frac{1}{3} u^3(x, t) \\Big|^{2 \\pi}_{0}.\n\t\\end{align*}\n\tand because $u$ is periodic, we have to\n\t\\begin{align*}\n\t\t\\frac{1}{2} \\frac{d}{dt} \\| u(x, t) \\|^2 = 0.\n\t\\end{align*}\n\tThis means that the energy is conserved with the same initial energy since we must bear in mind that this represents the kinetic energy of a fluid that travels with a velocity given by $u_0$. \\\\\n\t\t\n\tIn any problem, these characteristics are of utmost importance, this is because we must consider the behavior of the solutions when they must be approached with some numerical method. In the literature, when a solution remains bounded in time, the problem is said to be well defined. In the analysis context, this assures us the existence of a continuously differentiable solution $u$, and that besides being unique, it is possible to approximate it. \\\\\n\t\n\tHowever, approximating the solutions to this problem using spectral methods can be more complicated if its characteristics are not well understood. Next, we will see that under a certain condition it is possible to find a single analytical solution and that otherwise, it may lose its uniqueness when developing discontinuities. \\\\\n\t\t\t\n\tFirst, let's define the curves $x = x(t)$ that start at a point $x_0 \\in \\mathbb{R}$, and satisfy the following problem\n\t\\begin{align*}\n\t\t\\left \\lbrace \\begin{array}{ll}\n\t\t\tx' (t) = u(x(t), t), \\hspace{2mm} t > 0, \\\\\n\t\t\t\\\\\n\t\t\tx(0) = x_0.\n\t\t\\end{array} \\right .  \n\t\\end{align*}\n\t\n\tThe solutions for each $x_0$ are known as characteristic curves, which pass through the solution $u = u (x (t), t)$. It is well known in the theory of differential equations that when $u(x, t)$ is locally Lipschitz in the variable $x$, and continues in the variable $t$, the above equation admits a single solution $x(t)$ for each $x_0 \\in \\mathbb{R}$. So, assuming the above we have that for a solution $ x (t) $ corresponding to a fixed $x_0 \\in \\mathbb{R}$, it satisfies the following\n\t\\begin{align*}\n\t\t\\frac{d}{dt} [u(x(t), t)] &= x' (t) u_x (x(t), t) + u_t (x(t), t) \\\\\n\t\t&= u(x(t), t) u_x (x(t), t) - u(x(t), t) u_x (x(t), t) = 0\n\t\\end{align*}\n\twhich tells us that the function $u(x (t), t)$ is independent of the variable $t$, remaining constant along the characteristic curve. Therefore, we have to\n\t\\begin{align*}\n\t\tu(x(t), t) = u (x(0), 0) = u_0 (x_0)\n\t\\end{align*}\n\t\n\tFurthermore, we have that the solution $ x (t) $ will be given by the following curve\n\t\\begin{align*}\n\t\tx(t) = x_0 + u_0 (x_0) t, \\hspace{2mm} t > 0.\n\t\\end{align*}\n\twhich allows us to write the solution $ u(x, t)$ as follows\n\t\\begin{align}\n\t\\label{Exact_Inviscid}\t\n\t\tu(x, t) = u_0(x_0), \\hspace{2mm} x_0 = x - u_0(x_0) t\n\t\\end{align}\n\t\n\tNote that the Lipschitz condition is necessary for the uniqueness of the above solution, since, conversely, if we set two different starting points $x_0, x_1$ such that $x_0 <x_1$, then its curves characteristics intersect for some $t$, that is,\n\t\\begin{align*}\n\t\tx_0 + u_0(x_0) t = x_1 + u_0 (x_1) t,\n\t\\end{align*}\n\tand using the mean value theorem we have that for some $c \\in (x_0, x_1)$ the time $t$ is given by\n\t\\begin{align*}\n\t\tt = \\frac{x_1 - x_0}{u_0 (x_0) - u_0 (x_1)} = - \\frac{1}{u'_0(c)},\n\t\\end{align*}\n\t\n\tThe above tells us that when these two curves intersect, the solution $u (x, t)$ cannot be continuous in the time $ t $ given by the previous equation. This is because $u_0 (x_0) \\neq u_0 (x_1)$, and since the solution is constant over time we would have that $u (x, t) = u_0 (x_0) = u_0 (x_1)$, which is impossible. \\\\\n\t\t\n\tTherefore, the time $t$ for which two curves intersect represents a discontinuity, and that can be calculated by\n\t\\begin{align}\n\t\\label{shock_time}\t\n\t\t\tTc = \\min_{x \\in \\mathbb{R}} \\left[  \\frac{-1}{u'_0 (x)} \\right]\n\t\\end{align}\n\tand we can observe that the continuity of the solution $u$ is assured if $T_c < 0$, which depends only on the initial condition $u_0$. \\\\\n\t\n\tThis type of information allows us to know the criteria that must be considered when implementing numerical methods, but also the physical interpretation of the problem can be useful. For example, the solution to this problem can be considered to simulate the evolution of the profile of a sea wave that deforms as it approaches the coast until it breaks. But when this occurs, the deformation of the wave stops precisely at the time $T_c$. \\\\\n\t\n\tWe must consider that the problem without viscosity supposes that the fluid behaves in an ideal or perfect way, traveling as if they were separate sheets without rubbing. But in real life, fluids always have a certain degree of viscosity, that is, the fluid sheets can rub and cause energy dissipation, and for these cases, we could consider the problem with sufficiently small values ​​of $\\alpha$. So a question that naturally arises is what the behavior of the solutions looks like when $\\alpha$ approaches zero. \\\\\n\t\n\tIn chapter \\ref{Introduction} we obtained the solution of the problem (\\ref{IVP_Burgers}), which is given by (\\ref{Exact_Solution}), and from this equation we can see that the solutions are infinitely differentiable for any value of $\\alpha> 0$. Instinctively, we can notice that the solution approaches the solution of the equation without viscosity when $\\alpha$ approaches zero. In fact, the solution obtained as a limit when $\\alpha$ approaches zero is known as the entropy solution, which has been studied in \\cite{Tadmor1989}, \\cite{Maday1989} and in \\cite{Kruzkov1970} has been proved that this solution is unique. \\\\\n\t\n\tIn order to illustrate what we have previously discussed, we will consider the problem (\\ref{IVP_Inviscid}) with the following initial condition function\n\t\\begin{align}\n\t\\label{IC_Inviscid}\t\n\t\tu_0 (x) = e^{-0.005x^2}, \\hspace{3mm} x \\in \\mathcal{D}\n\t\\end{align}\n\twhere $\\mathcal{D} = [x_L, x_R]$, and considering the interval $I = [0, T_c]$ for a value of $T_c$ given by (\\ref{shock_time}). \\\\\n\t\n\tIn the following simulations, we will use the Fourier-Galerkin method given in (\\ref{Galerkin_Euler}) to obtain approximations with different values of $\\alpha$, and we will see how they approximate the exact solution of the problem (\\ref{IC_Inviscid} ) which was given in (\\ref {Exact_Inviscid}).\n\t\n\t\\newpage\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/inviscid/figures/small_alpha.png}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) with $\\alpha = 1.0 \\times 10^{-5}$, $N=256$, and $\\Delta t = 1.0 \\times 10^{-3}$.}\n\t\t\\vspace{2mm}\n\t\t\\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/inviscid/figures/small_alpha_T.png}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) at the time $T_c$ with $\\alpha = 1.0 \\times 10^{-5}$, and $\\Delta t = 1.0 \\times 10^{-3}$. (b) Point-wise error of approximation.}\n\t\\end{figure}\n\t\\newpage\n\t\\begin{figure}[H]\n\t\t\\centering\t\n\t\t\\includegraphics[width=13cm]{burgers_equation/deterministic/numerical_experiments/inviscid/figures/Numerical_Solution_Inviscid_T.png}\n\t\t\\caption{(a) Exact solution for (\\ref{IVP_Burgers}), and its approximations using (\\ref{Galerkin_Euler}) at the time $Tc$ with initial condition $u_0(x) = e^{-0.005x^2}$, $x \\in [-60, 60]$. (b) Pointwise error of approximation.}\n\t\t\\label{convection_aprox_T}\n\t\t\\includegraphics[width=11cm]{burgers_equation/deterministic/numerical_experiments/inviscid/figures/Numerical_Solution_Inviscid.png}\n\t\t\\caption{Numerical approximation for  \\ref{IVP_Burgers} using (\\ref{Galerkin_Euler}) with $N=512$, $u_0(x) = e^{-0.005x^2}$, $x \\in [-60, 60]$, and $t \\in [0, Tc]$.}\n\t\\end{figure}\n\t\\newpage\n\t\\begin{table}[H]\n\t\t\\centering\n\t\t\\begin{tabular}{lccc}\n\t\t\t\\toprule\n\t\t\t\\multicolumn{1}{c}{\\hspace{6mm}\\textbf{Expansion}} & \\multicolumn{3}{c}{\\textbf{Distance}} \\\\\n\t\t\t\\hspace{12mm} $N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{12mm} 16 & 0.285531 & 0.285732 & 0.285752 \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{12mm} 32 & 0.222737 & 0.223260 & 0.223312 \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{12mm} 64 & 0.160385 & 0.162782 & 0.163025 \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{12mm} 128 & 0.129297 & 0.133322 & 0.133733 \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{12mm} 256 & 0.083291 & 0.091449 & 0.092320 \\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\\caption{Distance between exact solution for (\\ref{IVP_Inviscid}) and the approximation for (\\ref{IVP_Burgers}) with $\\alpha = 1.0 \\times 10^{-5}$.}\n\t\\end{table}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/inviscid/figures/varios_alphas.png}\n\t\t\\caption{Exact solution for (\\ref{IVP_Inviscid}) and different approximations using (\\ref{Galerkin_Euler}) with $N=256$, and $\\Delta t = 1.0 \\times 10^{-3}$.}\n\t\\end{figure}", "meta": {"hexsha": "b0204ff91f999634bee8bca5ef551a13444872c3", "size": 10175, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/inviscid/Inviscid.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/inviscid/Inviscid.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/inviscid/Inviscid.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": 74.8161764706, "max_line_length": 625, "alphanum_fraction": 0.7110565111, "num_tokens": 3246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8933094103149355, "lm_q1q2_score": 0.7610574517845685}}
{"text": "%!TEX root =  ../main.tex\n\\subsection{Properties of Lines}\n\n\\objective{Classify linear and linear-like functions, and explain relationships of slopes.}\n\n\nAll non-vertical lines have slope, which is defined as rise over run, $\\frac{\\Delta x}{\\Delta y}$ \nor $m$.  The initial value\nof a linear equation might not be zero, but an ordered pair of the form $(0,b)$.  The variable\n$b$ is called the $y-$intercept.  All together, this is the famous $y=mx+b$ form of lines.\n\n\\marginfig[-0.1in]{\\chapdir/pics/ceiling_function}{The ceiling function.}\nHowever, that formula only makes sense when the origin is within view and we might become \nconcerned with the output-value when the input is 0. In calculus and other areas of mathematics, \nwe are more\noften simply interested in the slope and some arbitrary point, $(x_1,y_1)$.  Hence we find a majority\nof time from here on out, the point-slope form of \\index{linear!point-slope form}\nlinear equation is most helpful, $y-y_1=m(x-x_1)$,\na form which allows us to see the slope, and a (random?) point on the line very easily.\nThis form is nearly as easy to put in your TI-8* as your old friend slope-intercept: simply add $y_1$\nto the other side, and you have a $y=$ form ready to be entered in your grapher.\n\n\\subsection{Parallel vs. Perpendicular}\nIf a line has slope expressed via the fraction in lowest terms $\\frac{a}{b}$, \nthen any other fraction that reduces to the same ratio will produce a line parallel to the first.  \nConsider the sketch of how to make a line rotated $90^\\circ$ clockwise or counterclockwise \nto the first.  They will have slopes of $\\frac{-b}{a}$ or $\\frac{b}{-a}$, which are the same\nthings.  In short, perpendicular lines have opposite reciprocal slope.\\index{linear!parallel}\n\\index{linear!perpendicular}\n\n\\subsection{Linear-like}\nSeveral functions are linear in pieces, and are used in computer programming and other\nsystems of functions\n\n\\subsubsection{Ceiling, Floor, and Round}\nVarious forms of rounding are present in computer systems and your TI-8*.  Rounding down\nin all cases, rounding up in call cases, and the familiar rounding to the closest.\n\n\\marginfig[-1.0in]{\\chapdir/pics/floor_function}{The floor function}\n\\subsubsection{Modulus}\nThe most used function in this respect, and the foundation of an entire species of mathematics\n(called Modular Arithmetic) is the modulus function.  It can be thought of as taking two arguments,\none is what to divide by, and the other is what to divide.  The function returns the remainder.  For\nexample, 10 mod 3 is 1, and 49 mod 7 is 0.  Consider the graph of y=x mod 5.\n\n\\subsubsection{Rates of Change}\nA constant function is one that never changes (by definition).  \\index{constant!derivative}\nAlgebraically, that means it is\nof the form $y=c$, where $c$ is some numbers.  The slope is always zero and the graph\nis always a horizontal line.  A vertical line is not a function and its slope is undefined.  Every\nother line has a constant rate of change, it's slope.  In calculus terminology,\nit's derivative is a constant.\n\n\n\n\n\n\n", "meta": {"hexsha": "e17402aa008ac45a40e4faca65a99e43a77c0d2e", "size": 3051, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch03/0301.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/0301.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/0301.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.7118644068, "max_line_length": 101, "alphanum_fraction": 0.7617174697, "num_tokens": 777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8519528019683106, "lm_q1q2_score": 0.7610574466728913}}
{"text": "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\\title{Hidden Golden Ratio Integral (@solvingtogether)}\n\\author{Shreenabh Agrawal}\n\\date{\\today}\n\\usepackage{amsmath}\n\\usepackage{geometry}\n\\geometry{a4paper, portrait, margin=1in}\n\\usepackage{natbib}\n\\usepackage{graphicx}\n\\usepackage{amssymb}\n\\usepackage{relsize}\n\\usepackage[makeroom]{cancel}\n\\begin{document}\n\\maketitle\n\n\\section{Question}\n\nIf $I$ = $$\\mathlarger{\\LARGE{{\\int\\limits_{0}^{1}}\\frac{1-x^{2}}{x^{2}+\\left(x^{2}+1\\right)^{2}}\\: dx}} $$\nThen find $tan(I) + sec(I)$\n\n\\section{Solution}\n\nLet us take substitution $x = tan \\theta$ so that $dx\\ =\\ \\sec^{2}\\theta\\ d\\theta$, thus our integral becomes,\n$$\\mathlarger{\\LARGE{\\int\\limits_{0}^{\\pi/4}}\\frac{1-\\tan^{2}\\theta}{\\tan^{2}\\theta\\ +\\ \\sec^{4}\\theta}\\sec^{2}\\theta\\: d\\theta\\ } $$\nNow converting $tan \\theta$ and $sec \\theta$ to respective $sin$ and $cos$ functions, the integral becomes,\n$$\\mathlarger{\\LARGE{\\int\\limits_{0}^{\\pi/4}\\frac{\\cos^{2}\\theta-\\sin^{2}\\theta}{\\sin^{2}\\theta\\ \\cos^{2}\\theta\\ +\\ 1}\\ d\\theta}} $$\nUsing double angle properties, the integral can be rewritten as:\n$$\\mathlarger{\\LARGE{\\int\\limits_{0}^{\\pi/4}\\frac{\\cos2\\theta}{\\frac{\\sin^{2}2\\theta}{4}+1} d\\theta}} $$\nTaking a final substitution $\\sin2\\theta=u$ so that $2\\cos2\\theta\\ d\\theta=du$,\n$$\\mathlarger{\\LARGE{\\int\\limits_{0}^{1}\\frac{2}{4+u^{2}}\\ du}} $$\nPlugging in the limits, we get,\n$${I =\\tan^{-1}\\left(\\frac{1}{2}\\right)}$$\nFor the final answer,\n$$\\tan I+\\sec I=\\frac{1}{2}+\\frac{\\sqrt{5}}{2}$$\n$$\\boxed{\\tan I+\\sec I= \\phi}$$\nWhere $\\phi$ is the Golden Ratio.\n\n\\end{document}\n", "meta": {"hexsha": "959d4c5d33dc59e465575f0d94a50ed72dcbd195", "size": 1584, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Calculus/solvingtogether's questions/Hidden Golden Ratio Integral.tex", "max_stars_repo_name": "Nanu00/LaTeX", "max_stars_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2020-05-29T17:22:47.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:47:05.000Z", "max_issues_repo_path": "Calculus/solvingtogether's questions/Hidden Golden Ratio Integral.tex", "max_issues_repo_name": "Nanu00/LaTeX", "max_issues_repo_head_hexsha": "0f08a90c4e9ef78af42797670903636059ca0df2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2020-06-26T07:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-11T12:14:49.000Z", "max_forks_repo_path": "Calculus/solvingtogether's questions/Hidden Golden Ratio Integral.tex", "max_forks_repo_name": "Shreenabh664/LaTeX", "max_forks_repo_head_hexsha": "675e03f3ec555456b9a2cc714825ec75317848c2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 6, "max_forks_repo_forks_event_min_datetime": "2020-06-22T07:50:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-08T05:11:14.000Z", "avg_line_length": 39.6, "max_line_length": 133, "alphanum_fraction": 0.6654040404, "num_tokens": 594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.8933094025038598, "lm_q1q2_score": 0.7610574350562006}}
{"text": "%!TEX root=ClassNotes.tex\n\n\\section{Differentiation}\n\\begin{remark}\n\tWe'll now exclusively work with {\\it continuous} functions. As such, we can compute the various limits in this section without requiring any $\\epsilon, \\delta$ arguments. We'll get back to the $\\epsilon, \\delta$'s much later. For now, we'll repeated use the following identities,\n\t\\begin{align*}\n\t\t\\lim \\limits_{x \\rightarrow a} f(x) + g(x)     & = \\lim \\limits_{x \\rightarrow a} f(x) + \\lim \\limits_{x \\rightarrow a} g(x)                                                                   \\\\\n\t\t\\lim \\limits_{x \\rightarrow a} f(x) \\cdot g(x) & = \\lim \\limits_{x \\rightarrow a} f(x) \\cdot \\lim \\limits_{x \\rightarrow a} g(x)                                                               \\\\\n\t\t\\lim \\limits_{x \\rightarrow a} f(x) / g(x)     & = \\lim \\limits_{x \\rightarrow a} f(x) / \\lim \\limits_{x \\rightarrow a} g(x)     & \\mbox{ assuming }\\lim \\limits_{x \\rightarrow a} g(x) \\neq 0\n\t\\end{align*}\n\twherever the appropriate limits exist.\n\\end{remark}\n\n\\subsection{Derivative}\n\nThe derivative of a function measures the {\\it instantaneous rate of change} of the function. Several quantities in physics can be naturally expressed as derivatives, which was the original motivation for defining them.\n\\begin{center}\n\t\\begin{tabular}{l|l}\n\t\tFunction  & Derivative   \\\\ \\hline\n\t\tPosition  & Velocity     \\\\\n\t\tVelocity  & Acceleration \\\\\n\t\tPotential & Force\n\t\\end{tabular}\n\\end{center}\n\n\\begin{definition}\n\tThe {\\bf derivative} of $f(x)$ with respect to $x$, at $x=a$, is defined to be the limit\n\t\\begin{align}\n\t\t\\label{eq:def_derivative}\n\t\tf'(a)\n\t\t & :=\n\t\t\\lim \\limits_{h \\rightarrow 0}\n\t\t\\dfrac{f(a+h) - f(a)}{h}\n\t\\end{align}\n\tIf $f'(a)$ exists then we say that $f(x)$ is {\\bf differentiable} at $a$.\n\\end{definition}\nOne can rewrite Equation \\eqref{eq:def_derivative} as\n\\begin{align}\n\t\\label{eq:def_derivative2}\n\tf'(a)\n\t & =\n\t\\lim \\limits_{x \\rightarrow a}\n\t\\dfrac{f(x) - f(a)}{x - a}\n\\end{align}\nby making the substitution $h = x - a$.\n\nIn this form, it is more explicit that derivative is computing the {\\it instantaneous rate of change}, as the numerator $f(x) - f(a)$ is the change in $f$ and the denominator $x - a$ is the change in $x$, so their ratio is the rate of change of $f(x)$ with respect to $x$. Taking the limit $x \\rightarrow a$ makes this rate of change {\\it instantaneous}. When we want to make the ``free variable'' more explicit, we write the derivative as\n\\begin{align*}\n\t\\left.\\dfrac{df}{dx}\\right|_{x = a}\n\\end{align*}\nThis notation becomes more relevant in multivariable calculus when there are multiple variables with respect to which one can differentiate the function.\n\n\\begin{exercise}\n\t\\label{q:derivatives_1}\n\tUsing the definition, compute the derivatives of the following functions.\n\t\\begin{enumerate}\n\t\t\\item $f(x) = c$, where $c$ is a real number.\n\t\t\\item $f(x) = x$.\n\t\t\\item $f(x) = x^2$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tProve that if $f(x)$ is differentiable at $a$ then $f(x)$ is continuous at $x = a$.\n\\end{exercise}\n\n\\begin{theorem}\n\t\\label{thm:derivative_rules}\n\tIf $f$ and $g$ are differentiable at $a$ then\\\\\n\t\\begin{align*}\n\t\t(f+g)'(a)                     & = f'(a) + g'(a)                                                                     \\\\\\\\\n\t\t(f\\cdot g)'(a)                & = f'(a) \\cdot g(a) + f(a) \\cdot g'(a)                 &  & \\mbox{\\bf Product Rule}  \\\\\\\\\n\t\t\\left(\\dfrac{1}{g}\\right)'(a) & = -\\dfrac{g'(a)}{g(a)^2}                                                            \\\\\\\\\n\t\t\\left(\\dfrac{f}{g}\\right)'(a) & = \\dfrac{g(a) \\cdot f'(a) - g'(a) \\cdot f(a)}{g(a)^2} &  & \\mbox{\\bf Quotient Rule} \\\\\\\\\n\t\t(f\\circ g)'(a)\n\t\t                              & = f'(g(a)) \\cdot g'(a)                                &  & \\mbox{\\bf Chain Rule}    \\\\\n\t\\end{align*}\n\twhere we assume that $g(a) \\neq 0$ wherever it is in the denominator.\\\\\n\\end{theorem}\n\n\\begin{exercise}\n\tProve Theorem \\ref{thm:derivative_rules}.\n\n\tThe proof of the Product Rule requires a trick: add and subtract $f(a+h) g(a)$ to the numerator.\n\n\tFor proving the Quotient Rule notice that $f/g = f \\cdot (1/g)$.\n\n\tFeel free to read the proof of the Chain Rule from the book.\n\\end{exercise}\n\nBecause of these rules, once we know the derivatives of standard functions like trig functions, exponential functions etc., derivatives are fairly easy to compute. However, computing these standard derivatives is not easy using simply the definition (give it a try!).\n\nPolynomials are the only functions whose derivatives we can compute right now. We'll get back to computing more complicated derivatives once we learn integration and the Fundamental Theorem of Calculus.\n\n\n\\begin{exercise} In this exercise we'll (almost) prove that\n\t\\begin{align}\n\t\t\\label{eq:polynomial_derivative}\n\t\t(x^n)' = n x^{n -1}\n\t\\end{align}\n\twhere $n$ is any real number.\n\n\tNote that Exercise \\ref{q:derivatives_1} proves this for the cases $n = 0, 1, 2$.\n\t\\begin{enumerate}\n\t\t\\item Use the identity $(x^{n}) \\cdot x = x^{n + 1}$ to prove \\eqref{eq:polynomial_derivative} for all positive integers.\\footnote{{\\bf Optional:} Read about {\\bf Mathematical Induction} and use it to write a rigorous proof of this statement.}\n\t\t\\item Use the identity $\\frac{1}{x^m} = x^{-m}$ to prove \\eqref{eq:polynomial_derivative} for all negative integers.\n\t\t\\item Use the $\\left( x^{\\frac{p}{q}}\\right)^q = x^p$ to prove \\eqref{eq:polynomial_derivative} for all rational numbers.\n\t\\end{enumerate}\n\tThis proves \\eqref{eq:polynomial_derivative} for all rational numbers. We do not yet know enough to extend this proof to irrationals.\n\t\\begin{enumerate}[resume]\n\t\t\\item Can you think of a way to prove \\eqref{eq:polynomial_derivative} for all real numbers? What fact {\\it should} be true for your proof to work?\n\t\\end{enumerate}\n\\end{exercise}\n\n\n\\subsection{Inverse Functions}\nWe say that functions $f$ and $g$ are {\\bf inverses} of each other if the following identities hold:\n\\begin{align*}\n\tf (g(x)) & = x \\\\\n\tg(f(x))  & = x\n\\end{align*}\n\n\\begin{exercise}\n\tVerify that if $f$ and $g$ are inverses of each other and $f(x) = y$ then $x = g(y)$. (Hence the name inverse.)\n\\end{exercise}\nThis exercise is saying that to find the inverse of $f(x)$ we simply solve $f(x) = y$ for $x$ in terms of $y$, which then gives us $g$.\n\n\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Verify that $f(x) = 2x + 1$ and $g(x) = (x-1)/2$ are inverses of each other. Draw their graphs.\n\t\t\\item Verify that $f(x) = x^2$ and $g(x) = \\sqrt{x}$ are inverses of each other. Draw their graphs.\n\t\t\\item Verify that $f(x) = e^x$ and $g(x) = \\ln x$ are inverses of each other.\n\t\t      Draw their graphs.\n\t\t\\item What relation do you see between the graphs of inverses?\n\t\t\\item What are the domains of these functions i.e. what is the set of real numbers where the these functions are defined? Why do you think some of the inverses are not defined everywhere?\n\t\\end{enumerate}\n\\end{exercise}\n\nThe inverses of $\\sin x$ and $ \\cos x$ are denoted $\\sin^{-1} (x)$ and $\\cos^{-1} (x)$, respectively. More generally, the inverse of a function $f(x)$ is denoted by $f^{-1}(x)$ (which is different from $(f(x))^{-1}$). Note that if $f = g^{-1}(x)$ then $g = f^{-1}(x)$.\n\n\\begin{exercise}\n\tUsing the Chain Rule show that\n\t\\begin{align*}\n\t\t\\left(f^{-1}(a)\\right)'= \\dfrac{1}{f'(f^{-1}(a))}\n\t\\end{align*}\n\tVerify this explicitly for $f(x) = 2x+1$ and for $f(x) = x^2$.\n\\end{exercise}\nWe'll interpret this geometrically in the next section. We'll later on see that the derivatives of $\\sin^{-1}(x)$ and $\\ln x$ can expressed in terms of polynomials and radicals. This fact along with the above formula will then allow us to compute the derivatives of $\\sin x$ and $e^x$.\n\n\n\n\n\n\n\n\n\\subsection{Mean Value Theorems}\nDerivatives have several physical and geometric interpretations which make then widely applicable in all branches of science. We'll see a few of these interpretations in the next few sections.\n\nIn this section, we'll prove the analogues of Intermediate Value Theorem for differentiable functions.\n\n\\begin{definition}\n\tA number $c$ is an {\\bf absolute maximum} of a function $f$ in the interval $[a,b]$ if $f(c) \\ge f(x)$ for all $x \\in [a,b]$.\n\\end{definition}\nTo prove the Mean Value Theorems we'll need the following {\\bf Extreme Value Theorem}. We'll assume it without proof. As for the IVT, the proof of the Extreme Value Theorem fundamentally uses the Completeness of the Real Numbers.\n\n\\begin{theorem}[Extreme Value Theorem]\n\t\\label{thm:extreme_value_theorem}\n\tFor every continuous function $f$ and every closed interval $[a,b]$, there exists a real number $c \\in [a,b]$ such that $c$ is the absolute maximum of $f$ on $[a,b]$.\n\\end{theorem}\n\n\\begin{remark}\n\tThis theorem is false if we use open intervals. For example, $f(x) = 1/x$ has no absolute maximum on the interval $(0,1)$ even though it is continuous on it.\n\\end{remark}\n\n\\begin{exercise}\n\tDefine an absolute minimum and state the corresponding Extreme Value Theorem.\n\\end{exercise}\n\n% \\begin{exercise}\n% \tLet $f$ be a differentiable (and hence also continuous) function. On an interval $[a,b]$, by the Extremal Value Theorem, $f$ has an absolute maxima. Let $c$ be the absolute maximum. Assume that $a < c <b$.\n% \t\\begin{enumerate}\n% \t\t\\item Argue that the function $g(x) = \\dfrac{f(x) - f(c)}{x - c}$ is $\\ge 0$ for $ a < x < c$ and is $\\le 0$ for $c < x < b$.\n% \t\t\\item Argue that $\\lim \\limits_{x \\rightarrow c^-}g(x) \\ge 0$ and $\\lim \\limits_{x \\rightarrow c^+}g(x) \\le 0$.\n% \t\t\\item Conclude that $f'(c) = 0$.\n% \t\\end{enumerate}\n% \\end{exercise}\n%\n% Thus we've proven the following theorem\n% \\begin{theorem}\n% \t\\label{thm:max_derivative}\n% \tLet $f$ be a differentiable function. If $c$ is an absolute maximum for $f$ on the interval $[a,b]$ with $a < c < b$ then $f'(c) = 0$. Similar statement is true for an absolute minimum.\n% \\end{theorem}\n\nNote that by our definitions an {\\it absolute} max/min $c$ of $f$ over $[a,b]$ is also a {\\it local} max/min if $a < c < b$. We've already shown that the derivative vanishes at a local max/min, so we have\n\\begin{theorem}\n\t\\label{thm:max_derivative}\n\tLet $f$ be a differentiable function. If $c$ is an absolute max/min for $f$ on the interval $[a,b]$ with $a < c < b$ then $f'(c) = 0$.\n\\end{theorem}\n\nThis is all we'll be needing to prove the various Mean Value Theorems.\n\n\\begin{theorem}[Rolle's Theorem]\n\tLet $f$ be a differentiable function. For an interval $[a,b]$, if\n\t\\begin{align*}\n\t\tf(a) = f(b)\n\t\\end{align*}\n\tthen there exists a real number $c \\in (a,b)$ such that\n\t\\begin{align*}\n\t\tf'(c) = 0\n\t\\end{align*}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{RollesTheorem.png}\n\t\\end{figure}\n\\end{theorem}\n\\begin{proof}[Proof of Rolle's Theorem]\n\tThis theorem almost immediately follows from Theorem \\ref{thm:extreme_value_theorem} and Theorem \\ref{thm:max_derivative}. The only issue is that for Theorem \\ref{thm:max_derivative} we need $a < c < b$ but the Extreme Value Theorem only guarantees $a \\le c \\le b$. So we need a small argument to fill this gap.\n\n\tBy the Extremal Value Theorem, $f$ has an absolute maximum $c_{\\max}$ and an absolute minimum $c_{\\min}$ on the interval $[a,b]$.\n\n\t\\begin{exercise}$ $\n\t\t\\begin{enumerate}\n\t\t\t\\item Argue that if $f(c_{\\max}) = f(c_{\\min})$ then $f$ is a constant function on $[a,b]$.\n\t\t\\end{enumerate}\n\t\tWe've already shown that for a constant function, $f'(x)$ equals 0, hence for every $c \\in (a,b)$, $f'(c) = 0$ and we're done.\n\n\t\tSo now we'll assume that $f(c_{\\max}) \\neq f(c_{\\min})$.\n\n\t\t\\begin{enumerate}[resume]\n\t\t\t\\item \t\tArgue that in this case either $a < c_{\\max} < b$ or $a < c_{\\min}< b$ (possibly both).\n\t\t\t\\item \t\tFinish the proof of Rolle's Theorem.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\\end{proof}\n\n\\begin{theorem}[Mean Value Theorem]\n\tLet $f$ be a differentiable function. For any interval $[a,b]$ there exists a real number $c \\in (a,b)$ such that\n\t\\begin{align*}\n\t\tf'(c) = \\dfrac{f(b) - f(a)}{b - a}\n\t\\end{align*}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{MeanValueTheorem.jpg}\n\t\\end{figure}\n\\end{theorem}\n\\begin{proof}[Proof of Mean Value Theorem]\n\tMean Value Theorem follows from the Rolle's theorem by an algebraic trick.\n\tWe'll construct a new function $g(x)$ that satisfies the hypotheses of Rolle's theorem.\n\t\\begin{exercise}$ $\n\t\t\\begin{enumerate}\n\t\t\t\\item Find a real number $r$ such that $f(a) - r a = f(b) - r b$.\n\t\t\\end{enumerate}\n\t\tFor this value of $r$ define\n\t\t\\begin{align*}\n\t\t\tg(x) = f(x) - r x\n\t\t\\end{align*}\n\t\tBy construction, $g$ is differentiable and satisfies $g(a) = g(b)$ and hence satisfies the hypotheses for Rolle's theorem. So, there exists some real number $ a < c < b$ such that\n\t\t\\begin{align*}\n\t\t\tg'(c) = 0\n\t\t\\end{align*}\n\t\t\\begin{enumerate}[resume]\n\t\t\t\\item Show that for this $c$, $f'(c) = \\dfrac{f(b) - f(a)}{b - a}$, thereby completing the proof of Mean Value Theorem.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\\end{proof}\n\nWe'll see later on that the Mean Value Theorem is a key ingredient in the proof of Taylor series approximation. In fact, Taylor series approximations can be thought of as a generalization of MVT for higher order derivatives.\n\n\n\n\n\\subsection{L'Hopital's Rule}\nWe'll now (almost) provide a proof of L'Hopital's Rule using a stronger version of the Mean Value Theorem.\n\\begin{theorem}[Easy L'Hopital's Rule]\n\tLet $f$, $g$ be differentiable functions. Assume that\n\t\\begin{align*}\n\t\tf(a) = 0 = g(a) \\mbox{ \\quad and \\quad } g'(a) \\neq 0,\n\t\\end{align*}\n\twhere $a$ is a real number. Then\n\t\\begin{align*}\n\t\t\\lim \\limits_{x \\rightarrow a} \\dfrac{f(x)}{g(x)} = \\dfrac{f'(a)}{g'(a)}\n\t\\end{align*}\n\\end{theorem}\n\\begin{exercise}\n\tNotice that $\\dfrac{f(x)}{g(x)} = \\dfrac{f(x) - f(a)}{g(x) - g(a)}$. Use this to prove the easy version of L'Hopital's Rule. \\hint{Divide the numerator and denominator by $x - a$ and take $\\lim \\limits_{x \\rightarrow a}$.}\n\\end{exercise}\n\n\\begin{theorem}[Strong Mean Value Theorem]\n\tLet $f$, $g$ be differentiable functions. Assume that $g(a) \\neq g(b)$ for some real numbers $a$ and $b$. Then there exists a real number $c \\in (a,b)$ such that\n\t\\begin{align*}\n\t\t\\dfrac{f'(c)}{g'(c)} = \\dfrac{f(b) - f(a)}{g(b) - g(a)}\n\t\\end{align*}\n\\end{theorem}\n\\begin{proof}[Proof of Strong Mean Value Theorem]\n\tThe Strong Mean Value Theorem follows from the Rolle's theorem by the same algebraic trick. We'll construct a new function $h(x)$ that satisfies the hypotheses of Rolle's theorem.\n\t\\begin{exercise}$ $\n\t\t\\begin{enumerate}\n\t\t\t\\item Find a real number $r$ such that $f(a) - r g(a) = f(b) - r g(b)$.\n\t\t\\end{enumerate}\n\t\tFor this value of $r$ define\n\t\t\\begin{align*}\n\t\t\th(x) = f(x) - r g(x)\n\t\t\\end{align*}\n\t\tBy construction, $h$ is differentiable and satisfies $h(a) = h(b)$ and hence satisfies the hypotheses for Rolle's theorem. So, there exists some real number $ a < c < b$ such that\n\t\t\\begin{align*}\n\t\t\th'(c) = 0\n\t\t\\end{align*}\n\t\t\\begin{enumerate}[resume]\n\t\t\t\\item Show that for this $c$, $\\dfrac{f'(c)}{g'(c)} = \\dfrac{f(b) - f(a)}{g(b) - g(a)}$, thereby completing the proof of the Strong Mean Value Theorem.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\\end{proof}\n\n\\begin{exercise}\n\tExplain how the Mean Value Theorem is a special case of the Strong Mean Value Theorem and how the Rolle's theorem is a special case of the Mean Value Theorem.\n\\end{exercise}\n\\begin{theorem}[L'Hopital's Rule]\n\tLet $f$, $g$ be differentiable functions. Assume that\n\t\\begin{align*}\n\t\tf(a) = 0 = g(a)\n\t\\end{align*}\n\twhere $a$ is a real number. Then\n\t\\begin{align*}\n\t\t\\lim \\limits_{x \\rightarrow a} \\dfrac{f(x)}{g(x)} = \\lim \\limits_{x \\rightarrow a} \\dfrac{f'(x)}{g'(x)}\n\t\\end{align*}\n\\end{theorem}\n\n\\begin{proof}[Idea of the proof]\n\tFor any $b$, by the Strong Mean Value Theorem, there exists a $c \\in (a,b)$ such that\n\t\\begin{align*}\n\t\t\\dfrac{f'(c)}{g'(c)}          & = \\dfrac{f(b) - f(a)}{g(b) - g(a)}                                \\\\\n\t\t\\implies \\dfrac{f'(c)}{g'(c)} & = \\dfrac{f(b)}{g(b)}               & (\\mbox{as } f(a) = 0 = g(a))\n\t\\end{align*}\n\tAs $c$ has to lie between $a$ and $b$, when we take the limit $b \\rightarrow a$ we must also have $c \\rightarrow a$. Taking limits of both sides we get the required result.\n\t\\begin{align*}\n\t\t\\lim \\limits_{c \\rightarrow a} \\dfrac{f'(c)}{g'(c)} = \\lim \\limits_{b \\rightarrow a}  \\dfrac{f(b)}{g(b)}\n\t\\end{align*}\n\\end{proof}\n\n\\begin{remark}\n\tThe last argument in the above proof is not rigorous. While the idea is correct, to make it rigorous we need generalized notions of limits called {\\bf limit superior} ($\\lim \\sup$) and {\\bf limit inferior} ($\\lim \\inf$). This is unfortunately beyond the scope of this class.\n\\end{remark}\n\nThere are many more variants of L'Hopital's Rule: for one-sided limits, for $a = \\infty$, for $ \\lim \\limits_{x \\rightarrow a} f(a)= \\infty =\\lim \\limits_{x \\rightarrow a} g(a) $ etc. They can all be proven using similar techniques.\n\n\n\n\n\n\n\n\n\n\n\\subsection{First Derivative Test}\nIn this section, we'll prove the First Derivative Test for differentiable functions.\n\n\\begin{definition}\n\tWe say that a function $f$ is {\\bf increasing} on an interval $[a,b]$, if for all $x$, $y$ in $[a,b]$ if $x < y$ then $f(x) \\le f(y)$.\n\t\tWe say that $f$ is {\\bf strictly increasing} on $[a,b]$, if for all $x$, $y$ in $[a,b]$ if $x < y$ then $f(x) < f(y)$.\n\\end{definition}\n\\begin{exercise}\n\tCome up with a definition for when a function is {\\bf decreasing}, {\\bf strictly decreasing} on an interval.\n\\end{exercise}\n\\begin{exercise}\n\tFind the interval(s) on which the function $x^2$ is increasing/decreasing? What about the function $x^3$?\n\\end{exercise}\n\nFor differentiable functions, we can determine if a function is increasing or decreasing by calculating it's first derivative.\n\\begin{exercise}$ $\n\t\\label{q:increasing_decreasing_derivative}\n\t\\begin{enumerate}\n\t\t\\item {\\bf Optional:} Let $g(x)$ be a function such that $\\lim \\limits_{x\\rightarrow c} g(x)$ exists for some real number $c$ in the interval $(a,b)$. Prove that if $g(x) \\ge 0$ for all $x$ in $[a,b]$, then $\\lim \\limits_{x\\rightarrow c} g(x)$ is also $\\ge 0$.\\hint{Proof by Contradiction.}\\\\ {\\it (You can assume this part to be true if you choose not to prove it.)}\n\t\t\\item Let $f(x)$ be an increasing function on $[a,b]$ and let $c \\in (a,b)$. Prove that $g(x) \\ge 0$ on the interval $[a,b]$ where $g(x)$ is the function\n\t\t      \\begin{align*}\n\t\t\t      g(x) = \\dfrac{f(x) - f(c)}{x - c}\n\t\t      \\end{align*}\n\t\t\\item Let $f(x)$ be a differentiable function that is increasing on the interval $[a,b]$. Prove that all $c \\in (a,b)$, $f'(c) \\ge 0$. Similarly, for decreasing functions.\n\t\\end{enumerate}\n\\end{exercise}\nNote that this agrees with the interpretation of a derivative as the {\\it instantaneous} rate of change of a function: an increasing function should have a positive {instantaneous} rate of change and a decreasing function should have a negative {instantaneous} rate of change. The converse of the above statement is almost true, but for this we need an extra assumption on $f$ and the proof is a bit more intricate.\n\n\\begin{prop}\n\t\\label{thm:increasing_positive_derivative}\n\tIf $f'(x) > 0$ for all $c \\in (a,b)$ then $f$ is strictly increasing on $(a,b)$. Similarly, for $f'(c) < 0$.\n\\end{prop}\n\n\\begin{exercise}\n\tLet $f'(x) > 0$ for all $c \\in (a,b)$. Prove by Contradiction, that for all $x$, $y \\in (a,b)$, if $x < y$ then $f(x) < f(y)$.\\hint{Use the Mean Value Theorem.}\n\\end{exercise}\n\n\\begin{exercise}\n\tUse the above Proposition to find the range in which the function $x^n$ is increasing/decreasing, where $n$ is a positive integer.\n\\end{exercise}\n\n\\begin{definition}A real number $c$ is said to be a {\\bf local maximum} of a function $f$ if there is some interval $(a,b)$ containing $c$ such that if $a < x < b$ then $f(c) \\ge f(x)$.\n\\end{definition}\n\\begin{exercise}\n\tCome up with a definition for {\\bf local minimum}.\n\\end{exercise}\n\\begin{exercise} Assume that the function $f(x)$ is differentiable and it's derivative $f'(x)$ is continuous. Using Proposition \\ref{thm:increasing_positive_derivative} prove that if $c$ is a local maximum of $f(x)$ then $f'(c) = 0$.\\hint{Proof by Contradiction.} Similarly for a local minimum.\n\\end{exercise}\n\\begin{remark}\n\tWe need $f'(x)$ to be continuous to ensure that if $f'(c) > 0$ then $f'(x) > 0$ for every $ x \\in (a,b)$, where $(a,b)$ is some interval containing $c$.\n\\end{remark}\n\n\n\nCombining everything in this section we have proven the following Theorem, also called the {\\bf First Derivative Test}.\n\\begin{theorem}[First Derivative Test]\n\tLet $f(x)$ be a differentiable function whose derivative $f'(x)$ is a continuous function.\n\n\tFor a real number $c$,\n\t\\begin{align*}\n\t\tf\t\\mbox{ has a local max/min at } c & \\implies f'(c) = 0   \\\\\n\t\tf \\mbox{ is increasing near } c    & \\implies f'(c) \\ge 0 \\\\\n\t\tf \\mbox{ is decreasing near } c    & \\implies f'(c) \\le 0\n\t\\end{align*}\n\tConversely,\n\t\\begin{align*}\n\t\tf'(c) > 0 & \\implies f \\mbox{ is increasing near } c \\\\\n\t\tf'(c) < 0 & \\implies f \\mbox{ is decreasing near } c\n\t\\end{align*}\n\twhere by ``near $c$'' means for some interval $(a,b)$ containing $c$.\n\\end{theorem}\n\nA real number $c$ satisfying $f'(c) = 0$ is called a {\\bf critical point} of $f$. The First Derivative Test says that a local max/min has to be a critical point, but it does not say that a critical point has to be a local max/min. A standard example of this failure is $c=0$ for the function $f(x) = x^3$.\n\\begin{align*}\n\t\\mbox{Local min/max}  & \\Rightarrow \\mbox{Critical point}    \\\\\n\t\\mbox{Critical point} & \\not\\Rightarrow \\mbox{Local min/max}\n\\end{align*}\nThere are ways to fix this using higher derivatives. We'll do this later using Taylor Series approximations.\n\n\n\n\\subsubsection*{Optional Problems}\nThere are multiple ways of proving Proposition \\ref{thm:increasing_positive_derivative}. However, all the methods require some additional techniques which we have not yet developed.\n\n\\begin{exercise}\n\tTry to write down a rigorous proof of Proposition \\ref{thm:increasing_positive_derivative}. What statement {\\it should} be true for your proof to work?\n\\end{exercise}\n\n\n\n\n\n\n\n\n\n\\subsection{Convexity and Concavity}\nThe second derivative of a function $f(x)$ is defined as\n\\begin{align*}\n\tf''(x) = \\left(f'(x)\\right)'\n\\end{align*}\nIf the second derivative exists then we say that a function is {\\bf twice differentiable}.\nMore generally, the $n^{th}$ derivative $f^{(n)}(x)$ is defined as\n\\begin{align*}\n\tf^{(n)}(x) = \\left(f^{(n-1)}(x)\\right)'\n\\end{align*} If all derivatives exist then we say that the function is {\\bf smooth} or {\\bf infinitely differentiable}. The standard functions like polynomials, trig functions, exponentials, and logarithms are all smooth wherever they're defined.\\\\\n\nIf a function $f$ is twice differentiable, then the second derivative of $f$ measures it's convexity/concavity.\n\\begin{definition}\n\tA function $f$ is said to be {\\bf convex} (or {\\bf concave upwards}) on an interval, if for every real numbers $a$, $b$ in the interval, the graph of $f(x)$ lies below the line joining $(a,f(a))$ to $(b,f(b))$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.6\\textwidth]{ConvexFunction.png}\n\t\\end{figure}\n\\end{definition}\nConvex functions play an important role in many areas of mathematics, especially in the study of optimization problems.\\\\\n\nThe following theorem establishes the connection between convexity and the second derivative.\n\\begin{theorem}\n\t\\label{thm:convex_functions}\n\tLet $f$ be a twice differential function.\n\n\tIf $f$ is convex on an interval then $f''(x) \\ge 0$ on that interval. Conversely, if for every real number $x$ in some interval, $f''(x) > 0$, then $f$ is convex on that interval.\n\\end{theorem}\n\n\\begin{remark}\n\tTo avoid clutter, we'll often drop the terms {\\it on an interval, in some interval} etc. in the following proof. Just keep in mind that there is an ambient interval and all our variables belong to that interval.\n\\end{remark}\n\n\\noindent \\begin{tabular}{|p{\\textwidth}|}\n  \\hline \\\\{\\it Once you have solved all the exercises below, submit your final solutions as one single logically coherent proof. Also include all the text that is in between the exercises, so that you yourself see how all the pieces fit together. As before, this is to practice writing complex proofs.}\\\\\\\\\n  \\hline\n\\end{tabular}\n\n\\begin{proof}\n\tLet $f$ be a twice differential function.\n\t\\begin{exercise}\n\t\tFor real numbers $a$, $b$ denote by $m_{a,b}$ the slope of the line joining the points $(a,f(a))$ and $(b,f(b))$.\n\t\tFind a formula for $m_{a,b}$.\n\t\\end{exercise}\n\n\t\\noindent We'll first prove the forward direction.\\\\\n\t\\noindent {\\bf Claim:} {\\it \tIf $f$ is convex on an interval then $f''(x) \\ge 0$ on that interval.}\n\n\tWe'll prove that $f'(x)$ is an increasing function which will then imply that $f''(x) \\ge 0$ (as the derivative of an increasing function is $\\ge 0$).\\\\\n\n\tLet $f$ be a convex function. Let $a < b$ be two real numbers.\n\t\\begin{exercise}\n\t\tLet $a < x < y$ be real numbers.\n\t\t\\begin{enumerate}\n\t\t\t\\item {\\it Geometrically} argue that $m_{a,x} < m_{a,y}$.\n\t\t\t\\begin{figure}[H]\n\t\t\t\t\\centering\n\t\t\t\t\\includegraphics[width=0.6\\textwidth]{ConvexFunctionProof1.png}\n\t\t\t\\end{figure}\n\t\t\t\\item Using the formula for $m_{a,x}$, $m_{a,y}$ and the above inequality argue that $$f'(a) \\le m_{a,y}$$ for real numbers $a < y$.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\n\t\\begin{exercise}\n\t\tLet $x < y < b$ be real numbers.\n\t\t\\begin{enumerate}\n\t\t\t\\item {\\it Geometrically} argue that $m_{x,b} < m_{y,b}$.\n\t\t\t\\item Using the formula for $m_{y,b}$, $m_{x,b}$ and the above inequality argue that $$m_{x,b} \\le f'(b) $$ for real numbers $x < b$.\n\t\t\\end{enumerate}\n\t\\end{exercise}\n\n\t\\begin{exercise}\n\t\tCombine the results from the previous two exercises to conclude that $f'(a) \\le f'(b)$.\n\t\\end{exercise}\n\tHence $f'(x)$ is an increasing function and hence $f''(x) \\ge 0$.\\\\\n\n\t\\noindent We'll next prove the other direction. \\\\\n\t\\noindent {\\bf Claim:} {\\it If for every real number $x$ in some interval, $f''(x) > 0$, then $f$ is convex on that interval.}\n\n\tWe'll prove this by {\\it contradiction}. Let $f$ be a function such that $f''(x) > 0$ on some interval. This implies that $f'(x)$ is an increasing function on that interval. This is the statement that we'll contradict.\\\\\n\n\tAssume on the contrary that $f$ is not convex. This means that for some real numbers $a < b$, there exists a number $c$ with $a < c < b$ such that the point $(c,f(c))$ lies above the line joining $(a,f(a))$ and $(b,f(b))$.\n\n\t\\begin{exercise}\n\t\tDraw a picture.\n\t\\end{exercise}\n\tApplying the Mean Value Theorem to the intervals $[a,c]$ and $[c,b]$ gives us real numbers $d_1 \\in (a,c)$ and $d_2 \\in (c,b)$ such that\n\t\\begin{align*}\n\t\tf'(d_1) = m_{a,c} \\mbox{ and } f'(d_2) = m_{c,b}\n\t\\end{align*}\n\n\t\\begin{exercise} $ $\n\t\t\\begin{enumerate}\n\t\t\t\\item Draw a picture.\n\t\t\t\\item {\\it Geometrically} argue that $f'(d_1) > f'(d_2)$.\n\t\t\t\\item Why is this a contradiction?\n\t\t\\end{enumerate}\n\tThis completes a proof of the other direction, and hence of the main theorem.\n\t\\end{exercise}\n\\end{proof}\n\n\\subsubsection{Second Derivative Test}\nLet $f(x)$ be a twice differentiable function. If a real number $c$ is a local minimum of $f$ then $f$ is convex on some interval containing $c$. A similar statement is true when $c$ is a local maximum. Combining this observation with the previous Theorem and the First Derivative Test, we get the {\\bf Second Derivative Test}.\n\n\\begin{theorem}[Second Derivative Test]\n\tLet $f(x)$ be a twice differentiable function whose second derivative $f''(x)$ is a continuous function.\n\t\\begin{align*}\n\t\tf\t\\mbox{ has a local min at } c &\\implies f'(c) = 0 \\mbox{ and } f''(c) \\ge 0 \\\\\n\t\t\tf\t\\mbox{ has a local max at } c &\\implies f'(c) = 0 \\mbox{ and } f''(c) \\le 0\n\t\\end{align*}\n\tConversely,\n\t\\begin{align*}\n\t\tf'(c) = 0 \\mbox{ and } f''(c) > 0 & \\implies f\t\\mbox{ has a local min at } c  \\\\\n\t\tf'(c) = 0 \\mbox{ and } f''(c) < 0 & \\implies f\t\\mbox{ has a local max at } c\n\t\\end{align*}\n\\end{theorem}\nWe need continuity of $f''(x)$ so that $f''(c) > 0$ implies $f''(x)>0$ on some interval containing $c$.\n\n\n\\subsubsection*{Optional Problems}\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Find an example of a function which is convex but $f''(x)$ is not always $> 0$.\n\t\t\\item Why does the proof of Theorem \\ref{thm:convex_functions} only proves  that {\\it if $f$ is convex then $f''(x) \\ge 0$} (instead of $f''(x) > 0$)?\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tSeveral times in this section we used {\\it geometric} arguments. This is less preferable than algebraic arguments as geometric arguments are not rigorous and hence susceptible to being incorrect.\n\t\\begin{enumerate}\n\t\t\\item Convert the definition of a convex function into an algebraic equation involving inequalities.\n\t\t\\item Use this equation to rigorously prove that, say, $m_{a,x} < m_{a,y}$ if $a < x < y$.\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tLet $f$ be a convex function on an interval containing the real numbers $a$, $b$. Show that for all $ t \\in [0,1]$,\n\t\\begin{align*}\n\t\tf(t a + (1-t) b) \\le t f(a) + (1- t) f(b)\n\t\\end{align*}\n\tThis inequality is called {\\bf Jensen's inequality} for convex functions.\n\\end{exercise}\n", "meta": {"hexsha": "4459f092285513994e191d334592554f8704e371", "size": 29075, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/05Derivative.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/05Derivative.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/05Derivative.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": 48.8655462185, "max_line_length": 439, "alphanum_fraction": 0.6747033534, "num_tokens": 9089, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681195338728, "lm_q2_score": 0.8872045892435128, "lm_q1q2_score": 0.7610158121572299}}
{"text": "\\chapter{Optimization methods}\n\\label{chap:Optimization-methods}\n\n\n\\section{Convexity}\n\\label{sec:Convexity}\n\n\\begin{definition}\n(\\textbf{Convex set}) We say aset $\\mathcal{S}$ is convex if for any $\\vec{x}_1, \\vec{x}_2 \\in \\mathcal{S}$, we have\n\\begin{equation}\n\\lambda\\vec{x}_1+(1-\\lambda)\\vec{x}_2 \\in \\mathcal{S}, \\forall \\lambda \\in [0,1]\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\n(\\textbf{Convex function}) A function $f(\\vec{x})$ is called convex if its \\textbf{epigraph}(the set of points above the function) defines a convex set. Equivalently, a function $f(\\vec{x})$ is called convex if it is defined on a convex set and if, for any $\\vec{x}_1, \\vec{x}_2 \\in \\mathcal{S}$, and any $\\lambda \\in [0,1]$, we have\n\\begin{equation}\nf(\\lambda\\vec{x}_1+(1-\\lambda)\\vec{x}_2) \\leq \\lambda f(\\vec{x}_1)+(1-\\lambda)f(\\vec{x}_2)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nA function $f(\\vec{x})$ is said to be \\textbf{strictly convex} if the inequality is strict\n\\begin{equation}\nf(\\lambda \\vec{x}_1 + (1 - \\lambda)\\vec{x}_2) < \\lambda f(\\vec{x}_1) + (1 - \\lambda)f(\\vec{x}_2)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nA function $f(\\vec{x})$ is said to be (strictly) \\textbf{concave} if $-f(\\vec{x})$ is (strictly) convex.\n\\end{definition}\n\n\\begin{theorem}\nIf $f(x)$ is twice differentiable on $[a, b]$ and $f''(x) \\geq 0$ on $[a, b]$ then $f(x)$ is convex on $[a, b]$.\n\\end{theorem}\n\n\\begin{proposition}\n$\\log(x)$ is strictly convex on $(0, \\infty)$.\n\\end{proposition}\n\nIntuitively, a (strictly) convex function has a “bowl shape”, and hence has a unique global minimum $x^*$ corresponding to the bottom of the bowl. Hence its second derivative must be positive everywhere, $\\frac{\\mathrm{d}^2}{\\mathrm{d}x^2}f(x)>0$. A twice-continuously differentiable, multivariate function $f$ is convex iff its Hessian is positive definite for all $\\vec{x}$. In the machine learning context, the function $f$ often corresponds to the NLL.\n\nModels where the NLL is convex are desirable, since this means we can always find the globally optimal MLE. We will see many examples of this later in the book. However, many models of interest will not have concave likelihoods. In such cases, we will discuss ways to derive locally optimal parameter estimates.\n\n\n\\section{Gradient descent}\n\\label{sec:Gradient-descent}\n\n\n\\subsection{Stochastic gradient descent}\n\n\\begin{algorithm}[htbp]\n\t\\SetKwInOut{Input}{input}\\SetKwInOut{Output}{output}\n\t\n    \\Input{Training data $\\mathcal{D}=\\left\\{(\\vec{x}_i,y_i) | i=1:N\\right\\}$}\n\t\\Output{A linear model: $y_i=\\vec{\\theta}^T\\vec{x}$}\n    $\\vec{w} \\leftarrow 0;\\; b \\leftarrow 0;\\; k \\leftarrow 0$\\;\n    \\While{no mistakes made within the for loop}{\n        \\For{$i\\leftarrow 1$ \\KwTo $N$}{\n\t\t\t\\If{$y_i(\\vec{w} \\cdot \\vec{x}_i+b) \\leq 0$}{\n\t\t\t\t$\\vec{w} \\leftarrow \\vec{w}+\\eta y_i \\vec{x}_i$\\;\n\t\t\t\t$b \\leftarrow b+\\eta y_i$\\;\n\t\t\t\t$k \\leftarrow k+1$\\;\n\t\t\t}\n\t\t}\n    }\n\\caption{Stochastic gradient descent}\n\\end{algorithm}\n\n\n\\subsection{Batch gradient descent}\n\n\n\\subsection{Line search}\nThe \\textbf{line search}\\footnote{\\url{http://en.wikipedia.org/wiki/Line_search}} approach first finds a descent direction along which the objective function $f$ will be reduced and then computes a step size that determines how far $\\vec{x}$ should move along that direction. The descent direction can be computed by various methods, such as gradient descent(Section \\ref{sec:Gradient-descent}), Newton's method(Section \\ref{sec:Newtons-method}) and Quasi-Newton method(Section \\ref{sec:Quasi-Newton-method}). The step size can be determined either exactly or inexactly.\n\n\n\\subsection{Momentum term}\n\n\n\\section{Lagrange duality}\n\n\n\\subsection{Primal form}\nConsider the following, which we'll call the \\textbf{primal} optimization problem:\n\\begin{eqnarray}\nxyz\n\\end{eqnarray}\n\n\n\\subsection{Dual form}\n\n\n\\section{Newton's method}\n\\label{sec:Newtons-method}\n\\begin{align}\nf(\\vec{x})& \\approx f(\\vec{x}_k)+\\vec{g}_k^T(\\vec{x}-\\vec{x}_k)+\\dfrac{1}{2}(\\vec{x}-\\vec{x}_k)^T\\vec{H}_k(\\vec{x}-\\vec{x}_k) \\nonumber \\\\\n\\text{where } & \\vec{g}_k \\triangleq \\vec{g}(\\vec{x}_k)=f'(\\vec{x}_k), \\vec{H}_k \\triangleq \\vec{H}(\\vec{x}_k), \\nonumber \\\\\n              & \\vec{H}(\\vec{x}) \\triangleq \\left[\\dfrac{\\partial^2 f}{\\partial x_i \\partial x_j}\\right]_{D \\times D} \\quad \\text{(Hessian matrix)} \\nonumber \\\\\nf'(\\vec{x})& = \\vec{g}_k+\\vec{H}_k(\\vec{x}-\\vec{x}_k)=0 \\Rightarrow  \\label{eqn:newton-stationary-point} \\\\\n\\vec{x}_{k+1}& = \\vec{x}_k-\\vec{H}_k^{-1}\\vec{g}_k\n\\end{align}\n\n\\begin{algorithm}[htbp]\n    Initialize $\\vec{x}_0$ \\\\\n\t\n\t\\While{(!convergency)} {\n        Evaluate $\\vec{g}_k=\\nabla f(\\vec{x}_k)$ \\\\\n        Evaluate $\\vec{H}_k=\\nabla^2 f(\\vec{x}_k)$ \\\\\n        $\\vec{d}_k=-\\vec{H}_k^{-1}\\vec{g}_k$ \\\\\n        Use line search to find step size $\\eta_k$ along $\\vec{d}_k$ \\\\\n        $\\vec{x}_{k+1}=\\vec{x}_k+\\eta_k\\vec{d}_k$\n\t}\n\t\n\\caption{Newton’s method for minimizing a strictly convex function}\n\\end{algorithm}\n\n\n\\section{Quasi-Newton method}\n\\label{sec:Quasi-Newton-method}\nFrom Equation \\ref{eqn:newton-stationary-point} we can infer out the \\textbf{quasi-Newton condition} as follows:\n\\begin{align}\nf'(\\vec{x})-\\vec{g}_k & = \\vec{H}_k(\\vec{x}-\\vec{x}_k) \\nonumber \\\\\n\\vec{g}_{k-1}-\\vec{g}_k & = \\vec{H}_k(\\vec{x}_{k-1}-\\vec{x}_k) \\Rightarrow \\nonumber \\\\\n\\vec{g}_k- \\vec{g}_{k-1} & = \\vec{H}_k(\\vec{x}_k-\\vec{x}_{k-1}) \\nonumber \\\\\n\\vec{g}_{k+1}- \\vec{g}_k & = \\vec{H}_{k+1}(\\vec{x}_{k+1}-\\vec{x}_k) \\quad \\text{(quasi-Newton condition)} \\label{eqn:quasi-Newton-condition}\n\\end{align}\n\nThe idea is to replace $\\vec{H}_k^{-1}$ with a approximation $\\vec{B}_k$, which satisfies the following properties:\n\\begin{enumerate}\n\\item{$\\vec{B}_k$ must be symmetric}\n\\item{$\\vec{B}_k$ must satisfies the quasi-Newton condition, i.e., $\\vec{g}_{k+1} - \\vec{g}_k= \\vec{B}_{k+1}(\\vec{x}_{k+1}-\\vec{x}_k)$. \\\\\nLet $\\vec{y}_k=\\vec{g}_{k+1}- \\vec{g}_k$, $\\vec{\\delta}_k=\\vec{x}_{k+1}-\\vec{x}_k$, then\n\\begin{equation}\n\\vec{B}_{k+1}\\vec{y}_k=\\vec{\\delta}_k \\label{eqn:secant-equation}\n\\end{equation}\n}\n\\item{Subject to the above, $\\vec{B}_k$ should be as close as possible to $\\vec{B_{k-1}}$.}\n\\end{enumerate}\n\nNote that we did not require that $\\vec{B}_k$ be positive definite. That is because we can show that it must be \npositive definite if $\\vec{B_{k-1}}$ is. Therefore, as long as the initial Hessian approximation $\\vec{B}_0$ is positive definite, \nall $\\vec{B}_k$ are, by induction. \n\n\n\\subsection{DFP}\nUpdating rule:\n\\begin{equation}\n\\vec{B}_{k+1}=\\vec{B}_k+\\vec{P}_k+\\vec{Q}_k\n\\end{equation}\n\nFrom Equation \\ref{eqn:secant-equation} we can get\n\\begin{equation*}\n\\vec{B}_{k+1}\\vec{y}_k=\\vec{B}_k\\vec{y}_k+\\vec{P}_k\\vec{y}_k+\\vec{Q}_k\\vec{y}_k=\\vec{\\delta}_k\n\\end{equation*}\n\nTo make the equation above establish, just let\n\\begin{align*}\n\\vec{P}_k\\vec{y}_k & = \\vec{\\delta}_k \\\\\n\\vec{Q}_k\\vec{y}_k & = -\\vec{B}_k\\vec{y}_k\n\\end{align*}\n\nIn DFP algorithm, $\\vec{P}_k$ and $\\vec{Q}_k$ are\n\\begin{align}\n\\vec{P}_k &= \\dfrac{\\vec{\\delta}_k\\vec{\\delta}_k^T}{\\vec{\\delta}_k^T\\vec{y}_k} \\\\\n\\vec{Q}_k &= -\\dfrac{\\vec{B}_k\\vec{y}_k\\vec{y}_k^T\\vec{B}_k}{\\vec{y}_k^T\\vec{B}_k\\vec{y}_k}\n\\end{align}\n\n\n\\subsection{BFGS}\nUse $\\vec{B}_k$ as a approximation to $\\vec{H}_k$, then the quasi-Newton condition becomes\n\\begin{equation}\n\\vec{B}_{k+1}\\vec{\\delta}_k=\\vec{y}_k\n\\end{equation}\n\nThe updating rule is similar to DFP, but $\\vec{P}_k$ and $\\vec{Q}_k$ are different. Let \n\\begin{align*}\n\\vec{P}_k\\vec{\\delta}_k & = \\vec{y}_k \\\\\n\\vec{Q}_k\\vec{\\delta}_k & = -\\vec{B}_k\\vec{\\delta}_k\n\\end{align*}\n\nThen\n\\begin{align}\n\\vec{P}_k &= \\dfrac{\\vec{y}_k\\vec{y}_k^T}{\\vec{y}_k^T\\vec{\\delta}_k} \\\\\n\\vec{Q}_k &= -\\dfrac{\\vec{B}_k\\vec{\\delta}_k\\vec{\\delta}_k^T\\vec{B}_k}{\\vec{\\delta}_k^T\\vec{B}_k\\vec{\\delta}_k}\n\\end{align}\n\n\n\\subsection{Broyden}\nBroyden's algorithm is a linear combination of DFP and BFGS.\n", "meta": {"hexsha": "d357f7dcda942c6ef78d903fb260bdf4f3ef5eb6", "size": 7810, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Optimization.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/Optimization.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/Optimization.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": 40.890052356, "max_line_length": 570, "alphanum_fraction": 0.6758002561, "num_tokens": 2835, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045966995027, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7610158088752664}}
{"text": "\\subsection{Taylor Series}\r\n\\noindent\r\nA Taylor series as a way of approximating a function about a point $x=a$ using polynomials. The first approximation just keeps the same value at $x=a$, the second approximation keep the same value and first derivative, etc.\r\n\\begin{definition}\r\n\t\\begin{equation*}\r\n\t\tf(x) = f(a)+f'(a)(x-a) + \\frac{f''(a)}{2!}(x-a)^2 + \\ldots +  \\frac{f^{(n)}(a)}{n!}(x-a)^n + \\ldots\r\n\t\\end{equation*}\r\n\\end{definition}\r\n\\noindent\r\nIf we approximate a function about $x=0$, we call this a Maclaurin series. Below are some common Maclaurin series, and their radii of convergence if applicable.\r\n\\begin{enumerate}[label=]\r\n\t\\item \\begin{equation*}\r\n\t\te^x = 1 + x + \\frac{x^2}{2!} + \\frac{x^3}{3!} + \\ldots\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\sin{x} = x - \\frac{x^3}{3!} + \\frac{x^5}{5!} - \\ldots\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\cos{x} = 1 - \\frac{x^2}{2!} + \\frac{x^4}{4!} - \\ldots\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\frac{1}{1+x} = 1 - x + x^2 - \\ldots \\text{, where } \\abs{x} < 1\r\n\t\\end{equation*}\r\n\t\\item \\begin{equation*}\r\n\t\t\\ln{(1+x)} = x - \\frac{x^2}{2} + \\frac{x^3}{3} - \\ldots \\text{, where } \\abs{x} < 1\r\n\t\\end{equation*}\r\n\\end{enumerate}\r\n\r\n\\input{./backgroundReview/singleVariableCalc/eulersIdentity.tex}", "meta": {"hexsha": "797b14aab08deb63dca6f211568fe9404a2073b3", "size": 1275, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/backgroundReview/singleVariableCalc/taylorSeries.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/singleVariableCalc/taylorSeries.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/singleVariableCalc/taylorSeries.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.9655172414, "max_line_length": 224, "alphanum_fraction": 0.6274509804, "num_tokens": 491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045937171068, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7610157998654127}}
{"text": "\\documentclass{ximera}\n\\input{../preamble}\n\\title{Exercises: ODE Applications}\n%%%%%\\author{Philip T. Gressman}\n\n\\begin{document}\n\\begin{abstract}\nExercises relating to the application of ODEs to solve problems.\n\\end{abstract}\n\\maketitle\n\n\n\n\\begin{exercise}\nFind the orthogonal trajectories of the given family (represented by the purple curves in the plot below):\n\\[ y = C e^{-x}. \\]\nWrite your answer as $f(y) = g(x) + C$, where both $f(y)$ and $g(x)$ vanish at the origin. Moreover, you should multiply by constants if necessary so that $f(1) = 1/2$ and $g(1) = 1$. \n\\[ \\answer{\\frac{1}{2} y^2} = \\answer{x} + C. \\]\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{images/ortho01.png}\n\\end{image}\n\\end{center}\n\n\\end{exercise}\n\n\\begin{exercise}\nFind the orthogonal trajectories of the given family (represented by the purple curves in the plot below):\n\\[ y = x - \\frac{x^3}{3} + C. \\]\nWrite your answer as $y = f(x) + C$, where $f(0) = 0$\n\\[ y = \\answer{\\frac{1}{2} \\ln \\left| \\frac{1-x}{1+x} \\right|} + C. \\]\n\\begin{center}\n\\begin{image}\n\\includegraphics[width=4in]{images/ortho02.png}\n\\end{image}\n\\end{center}\n\n\\end{exercise}\n\n\\begin{exercise}\nFind the orthogonal trajectories of the given family:\n\\[ y = \\tan \\left( C + x + \\frac{x^3}{3} \\right) \\]\nWrite your answer as $f(y) = g(x) + C$, where both $f(y)$ and $g(x)$ vanish at the origin. Moreover, you should multiply by constants if necessary so that $f(1) = 4/3$ and $g(1) = -\\pi/4$.\n\\[ \\answer{y + \\frac{y^3}{3}} = \\answer{- \\arctan x} + C \\]\n\\end{exercise}\n\n\n\n\\begin{exercise}\nIt takes about three days to defrost a 10 pound imitation frozen turkey in a home refrigerator. Suppose that the initial temperature is $-16^\\circ$C and the ambient temperature is $2^\\circ$C inside the refrigerator. If after exactly two days, the temperature of the frozen turkey is $0^\\circ$C, find a formula for the temperature $y(t)$ (in degrees Celsius) as a function of time for all $t > 0$, where $t$ is measured in days\n\\[ y = \\answer{ -18 e^{-t \\ln 3} + 2}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nAt time $t = 0$, a cup of tea has temperature $46^\\circ$C. Ten minutes later, its temperature is $34^\\circ$C. Ten minutes after that, the temperature is then $28^\\circ$C. Assuming the temperature obeys Newton's Law of cooling, what is the temperature (in degrees Celsius) as a function of time $y(t)$ for all $t > 0$, where $t$ is measured in minutes?\n\\[ y(t) = \\answer{24 e^{-t \\ln(2)/10} + 22}  \\]\n\\begin{hint}\nSuppose $A$ is the ambient temperature. We know that\n\\[ \\frac{48-A}{34 - A} = \\frac{34 - A}{28 - A} \\]\nbecause every ten minutes, the \\textit{difference} between tea temperature and room temperature decreases by the same factor.\n\\end{hint}\n\\end{exercise}\n\n\n\\begin{exercise}\nA 1000 liter tank is filled with a sugar solution: 200 kilograms of sugar dissolved in 1000 liters of pure water. The solution in the tank is kept thoroughly mixed at all times. At time $t = 0$, the attendants begin adding 1 liter per minute of dissolved sugar at a concentration of 0.1 kilograms per liter. At the same time, One liter per minute is drained from the tank to keep the overall volume of solution in the tank at 1000 liters. Find a function $S(t)$ for the total amount of sugar in the tank (in kilograms) a time $t > 0$, where $t$ is measured in minutes.\n\\[ S(t) = \\answer{ 100 + 100 e^{-t/1000}}. \\]\n\\end{exercise}\n\n\\begin{exercise}\nA small flask contains 10mL of solvent in which 1 gram of substance X is initially dissolved. The solution is slowly drained at a rate of 3mL per hour while 4mL per hour of pure solvent is added (with the whole solution being kept thoroughly mixed). Find a formula $X(t)$ for the amount of substance $X$ (in grams) sill in the beaker at time $t$, where $t$ is measured in hours.\n\\[ X(t) = \\answer{ \\frac{1000}{(t+10)^3}}. \\]\n\\end{exercise}\n\n\n\n\\section*{Sample Exam Questions}\n\n\\begin{question}%%%%%[2016C.15]\n\nA tank contains 100 gallons of water in which 300 pounds of salt are dissolved. At some initial time, workers begin pumping in fresh water, i.e., containing no salt, at a rate of 10 gallons per minute. During the process, the tank is kept well-mixed and 20 gallons per minute of the resulting saltwater are pumped out of the tank (in particular, note that the tank will be empty after 10 minutes). Find the total amount of salt in the tank (measured in pounds) which remains 9 minutes after the process starts.\n\\begin{multiplechoice}\n\\choice{\\(1\\)}\n\\choice{\\(2\\)}\n\\choice[correct]{\\(3\\)}\n\\choice{\\(4\\)}\n\\choice{\\(5\\)}\n\\choice{\\(6\\)}\n\\end{multiplechoice}\n\n\\end{question}\n\n\n\\end{document}\n", "meta": {"hexsha": "3b82050b213599efc751823b93f144baa84739be", "size": 4580, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "odes/31applypractice.tex", "max_stars_repo_name": "ptgressman/math104", "max_stars_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "odes/31applypractice.tex", "max_issues_repo_name": "ptgressman/math104", "max_issues_repo_head_hexsha": "3b797f5622f6c7b93239a9a2059bd9e7e1f1c7c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "odes/31applypractice.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": 48.2105263158, "max_line_length": 568, "alphanum_fraction": 0.7045851528, "num_tokens": 1363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045847699186, "lm_q2_score": 0.8577681049901037, "lm_q1q2_score": 0.7610157954166249}}
{"text": "\\subsection{Dentable sets}\\label{subsec:dentable_sets}\n\n\\begin{definition}\\label{def:dentability}\\mcite[def. 5.1]{Phelps1993}\n  A subset \\( A \\) of a Banach space \\( X \\) is called \\term{dentable} if it admits slices of arbitrarily small diameter, i.e. for every \\( \\varepsilon > 0 \\) there exist a functional \\( x^* \\in X^* \\) and a diameter \\( \\alpha > 0 \\), such that \\( \\diam S(x^*, A, \\alpha) < \\varepsilon \\).\n\n  Weak* dentability is defined in an obvious way.\n\\end{definition}\n\n\\begin{definition}\\label{def:radon-nikodym-property}\\mcite[def. 5.2]{Phelps1993}\n  The space \\( X \\) is said to have the \\term{Radon-Nikodym property (RNP)} if every nonempty bounded set \\( A \\) of \\( X \\) is dentable.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:weak_dentable_sets_are_dentable}\n  Let \\( X \\) be a Banach space and \\( A^* \\subseteq X^* \\) be a weak*-dentable set. Then \\( A^* \\) is dentable in \\( X^* \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( \\varepsilon > 0 \\) and let \\( x \\in X \\) and \\( \\alpha > 0 \\) be such that \\( \\diam S^*(x, A^*, \\alpha) < \\varepsilon \\).\n  We denote by \\( J(x) \\) the embedding of \\( x \\in X \\) into the double-dual \\( X^{**} \\) and by \\( T(J(x), A^*, \\alpha) \\) the slice of \\( A^* \\) in \\( X^* \\). We have that\n  \\begin{balign*}\n    S^*(x, A^*, \\alpha)\n     & =\n    \\{ x^* \\in A^* \\colon \\inprod {x^*} x > \\sigma_{A^*}(x) - \\alpha \\}\n    =    \\\\ &=\n    \\{ x^* \\in A^* \\colon \\inprod {x^*} x > \\sup \\{ \\inprod {y^*} x \\colon y^* \\in A^* \\} - \\alpha \\}\n    =    \\\\ &=\n    \\{ x^* \\in A^* \\colon \\inprod {J(x)} {x^*} > \\sup \\{ \\inprod {J(x)} {y^*} \\colon y^* \\in A^* \\} - \\alpha \\}\n    =\n    T(J(x), A^*, \\alpha),\n  \\end{balign*}\n\n  Since \\( J \\) is an isometry, this equality implies that\n  \\begin{equation*}\n    \\diam T(J(x), A^*, \\alpha) = \\diam S(x, A^*, \\alpha) < \\varepsilon.\n  \\end{equation*}\n\n  Hence, \\( A^* \\) admits arbitrarily small slices in \\( X^* \\), i.e. it is dentable in \\( X^* \\).\n\\end{proof}\n", "meta": {"hexsha": "e1591af1b425b132c317588d6c0d995e42b50371", "size": 1946, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/dentable_sets.tex", "max_stars_repo_name": "v--/anthology", "max_stars_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/dentable_sets.tex", "max_issues_repo_name": "v--/anthology", "max_issues_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/dentable_sets.tex", "max_forks_repo_name": "v--/anthology", "max_forks_repo_head_hexsha": "89a91b5182f187bc1aa37a2054762dd0078a7b56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.2105263158, "max_line_length": 289, "alphanum_fraction": 0.569373073, "num_tokens": 750, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.7609899334227597}}
{"text": "\\section{Camera Model}\n\\subsection{Camera Matrix}\n\\subsubsection{Pinhole camera model}\n\\includegraphics[width=\\columnwidth]{pictures/pinholecamera}\nProjection on image plane\n$$\\begin{pmatrix}\nfX\\\\\nfY\\\\\nZ\\\\\n\\end{pmatrix} = \n\\underbrace{\\begin{bmatrix}\n\tf&0&0&0\\\\\n\t0&f&0&0\\\\\n\t0&0&1&0\\\\\n\t\\end{bmatrix} }_{= diag(f,f,1)[I|0]} \\begin{pmatrix}\nX\\\\\nY\\\\\nZ\\\\\n1\\\\\n\\end{pmatrix} $$\nBy dividing $(fX,fY,Z)^\\top$ by $Z$ we get $(x,y,1)^\\top$\n\n\\subsubsection{Principal Point offset}\nMoving the point into the middle of the picture\n\n$$\\begin{pmatrix}\nfX+Zp_x\\\\\nfY+Zp_y\\\\\nZ\\\\\n\\end{pmatrix} = \\begin{bmatrix}\nf&0&p_x&0\\\\\n0&f&p_y&0\\\\\n0&0&1&0\\\\\n\\end{bmatrix} \\begin{pmatrix}\nX\\\\\nY\\\\\nZ\\\\\n1\\\\\n\\end{pmatrix} $$\nBy dividing $(fX+Zp_x,fY+Zp_y,Z)^\\top$ by $Z$ we get $(x+p_x,y+p_y,1)^\\top$\n\n\\subsubsection{Kalibration matrix K}\nIntrinsic camera parameters\n\n$$ \\underbrace{K = \\begin{bmatrix}\nf&0&p_x\\\\\n0&f&p_y\\\\\n0&0&1\\\\\n\\end{bmatrix}}_{simple: a=1 \\text{ and } s=0}  \\qquad \\underbrace{K = \\begin{bmatrix}\nf&s&p_x\\\\\n0&af&p_y\\\\\n0&0&1\\\\\n\\end{bmatrix}}_{general}$$\n\n$f$: focal length\\\\\n$s$: skew between the sensor axes due to the sensor not being mounted perpendicular to the optical axis\\\\\n$a$: aspect ratio between $f_x$ \\& $f_y$\n\n\\subsubsection{Camera Rotation + Shift}\nExtrinsic camera parameters\n$$ [R|t] $$\n$R$: 3x3 Rotation matrix\\\\\n$t$: 3x1 Translation vector\n\n\\subsubsection{Camera Matrix / Projective Camera}\n$$ P = K[R|t] $$\n\n$$ \\lambda \\begin{bmatrix}\nu\\\\\nv\\\\\n1\\\\\n\\end{bmatrix} = P \\begin{bmatrix}\nX\\\\\nY\\\\\nZ\\\\\nW\\\\\n\\end{bmatrix} = K[R|t] \\begin{bmatrix}\nX\\\\\nY\\\\\nZ\\\\\nW\\\\\n\\end{bmatrix} $$\n\nFull matrix has 11 DOF (5 intrinsic +3 rot +3 trans)\n\n3x4 matrix\n\n$$ \\tilde{P} = \\begin{bmatrix}\nK&0\\\\\n0&1\\\\\n\\end{bmatrix} \\begin{bmatrix}\nR&t\\\\\n0^T&1\\\\\n\\end{bmatrix} $$\n4x4 matrix\n\n$$P = K[R|-RC]$$\n\n\\subsection{Camera Calibration with Direct Linear Transform (DLT)}\nThe DLT method uses a set  of  control  points  whose  object  space/plane  coordinates  are  already  known.  The  control  points  are  normally  fixed  to  a  rigid  frame,  known  as  the  calibration  frame.    The  problem  is  essentially  to  calculate  the  mapping  between  the  2D  image  space  coordinates  (x,y)  and  the  3D  object  space  coordinates  (X,Y,Z).  For this 3D $\\leftrightarrow$ 2D correspondence the mapping should take the form of a 3x4 projection matrix (P) such that $x = PX$.\n\n$$ x = PX \\rightarrow [x]_xPX = 0 $$\n\nDenoting the rows of $P$ with $P^1, P^2, P^3$ we can rewrite above equation to\n\n\\includegraphics[width=0.7\\columnwidth]{pictures/dlt}\n\nSince the third equation is dependant on the first two, it can be discounted. So for every point X we get two equations.\n\nThe bracket is denoted with $A$ (2nx12) and the camera matrix with P (3x4)\n  \n$$ A P = 0 $$\n\nP has 11 DOF $\\rightarrow$ 5.5 points are needed for the minimal solution.\nFor $n \\geq 6$ it is over-determined and is solved with SVD.\n\n\\subsubsection{Gold Standard algorithm}\nObjective:\\\\\nGiven $n \\geq 6$ 2D to 3D point correspondences, determine the Maximum Likelihood Estimation of the camera projection matrix P.\\\\\n\nAlgorithm:\n\\begin{enumerate}\n\t\\item Linear Solution: Compute an initial estimate of P using a linear method.\n\t\t\\begin{enumerate}\n\t\t\t\\item Normalization $\\tilde{X} = UX$, $\\tilde{x} = Tx$\n\t\t\t\\item DLT\n\t\t\\end{enumerate}\n\t\\item Minimization of geometric error: using the linear estimate as a starting point minimize the geometric error: $\\min_P \\sum_{i}d(\\tilde{x}_i,\\tilde{P}\\tilde{X}_i)^2$\n\t\\item Denormalization $P = T^{-1}\\tilde{P}U$\n\\end{enumerate}", "meta": {"hexsha": "f6cf4227bd2077fe753410f8bcaacea5fd7a44bd", "size": 3511, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/2_Camera_Model.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/2_Camera_Model.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/2_Camera_Model.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": 27.0076923077, "max_line_length": 511, "alphanum_fraction": 0.6866989462, "num_tokens": 1254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473614033683, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7609899290801574}}
{"text": "\\subsection{Tangent Planes}\r\n\\noindent\r\nAlthough the tangent lines at a point on a surface can all be different depending on from which direction one approaches a point, all of these tangent lines lie in the same plane, defining the tangent plane.\r\nThis means that the tangent plane to $z = f(x, y)$ at $(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\r\n\\begin{equation*}\r\n\tP(x,y) = A(x-x_0) + B(y-y_0) + z_0.\r\n\\end{equation*}\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,\r\n\\begin{equation*}\r\n\tP(x,y) = f_x(x-x0) + f_y(y-y_0) + z_0.\r\n\\end{equation*} \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\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.5\\textwidth]{./Images/differentialMultivariableCalculus/tangent_plane.png}\r\n\t\\caption{Tangent plane}\r\n\\end{figure}\r\n", "meta": {"hexsha": "08d286b3b4403dded3dd122750144b9069feccad", "size": 1322, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/tangentPlanes.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/tangentPlanes.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/tangentPlanes.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": 41.3125, "max_line_length": 208, "alphanum_fraction": 0.6883509834, "num_tokens": 457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232808, "lm_q2_score": 0.8740772269642949, "lm_q1q2_score": 0.7609692520424286}}
{"text": "%================================\n\\section{Cover and Basis}\n%================================\n\n\n%--------------------------------\n\\begin{definition}\n\t[cover]\n\t\\label{def: cover}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $U \\subseteq X$, then a family $\\mathcal C \\subseteq \\mathcal P(X)$ is called a \\textit{cover} of $U$ iff the union of all sets in $\\mathcal C$ is a superset of $U$. That is,\n\t$$\n\tU \\subseteq \\bigcup \\mathcal C.\n\t$$\n\t\n\tIf $\\mathcal C \\subseteq \\mathcal T$, then we call $\\mathcal C$ an \\textit{open cover} of $U$.\n\t\n\tLet $\\mathcal S \\subseteq \\mathcal C$, iff the union of $\\mathcal S$ is still a superset of $U$, then we call $\\mathcal S$ a \\textit{subcover} of $\\mathcal C$.\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{definition}\n\t[basis]\n\t\\label{def: basis}\n\t\\label{theorem: alt def of basis}\n\tLet $(X, \\mathcal T)$ be a topological space, and let $\\mathcal B\\subseteq \\mathcal T$. $\\mathcal B$ is a \\textit{base} for $\\mathcal T$ iff it satisfies the following properties.\n\t\\begin{enumerate}[(i)]\n\t\t\\item For each $x \\in X$, there exists $B \\in \\mathcal B$ such that $x \\in B$, i.e., $\\bigcup \\mathcal B = X$.\n\t\t\\item For each $x \\in B_1 \\cap B_2$ where $B_1, B_2 \\in \\mathcal B$, there exists $B_3 \\ni x$ such that $B_3 \\subseteq B_1 \\cap B_2$.\n\t\\end{enumerate}\n\\end{definition}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{note}\n\tA base for a topology is not necessarily closed under finite intersections. For example, let\n\t$$\n\t\\mathcal I = \\left\\{ (a,b) : 0 < b - a < 1 \\right\\} \\in \\mathcal P(\\mathbb R),\n\t$$\n\tand let\n\t$$\n\t\\mathcal J = \\left\\{ (-\\infty, 2), (-2, \\infty) \\right\\} \\in \\mathcal P(\\mathbb R).\n\t$$\n\t$\\mathcal I \\cup \\mathcal J$ is a basis for the Euclidean topology on $\\mathbb R$, but $\\mathcal I \\cup \\mathcal J$ is not closed under finite intersection, for $\\bigcap \\mathcal J = (-2, 2)$ is not a member of $\\mathcal I \\cup \\mathcal J$.\n\\end{note}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{corollary}\n\t\\label{coro: alt def of basis}\n\tLet $(X, \\mathcal T)$ be a topological space and let $\\mathcal B$ be a basis for $\\mathcal T$. For all $U \\in \\mathcal T$, there exists $\\mathcal I, \\mathcal J \\subseteq \\mathcal B$ ($\\mathcal J$ finite) such that\n\t$$\n\tU = \\bigcup \\mathcal I = \\bigcap \\mathcal J.\n\t$$\n\t% todo: POOF\n\\end{corollary}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{example}\n\tLet $(\\mathbb R, \\mathcal T)$ be a topological space where $\\mathcal T$ is induce from the standard Euclidean metric, and let $\\mathcal B$ be the family of all open proper intervals in $\\mathbb R$. $\\mathcal B$ is a base for $\\mathcal T$.\n\t\n\tHowever, if $\\mathcal T$ is a discrete topology on $\\mathbb R$, $\\mathcal B$ is not a base for $\\mathcal T$, for some open subsets of $\\mathbb R$, such as $\\{0\\}$, is neither any arbitrary union nor any finite intersection of $\\mathcal B$-sets.\n\\end{example}\n%--------------------------------\n\n\n%--------------------------------\n\\begin{theorem}\n\tLet $(X, \\mathcal T)$ and $(X, \\mathcal T')$ be topological spaces, and let $\\mathcal B$ and $\\mathcal B'$ be the basis for $\\mathcal T$ and $\\mathcal T'$ respectively. $\\mathcal T'$ is finer than $\\mathcal T$ iff for any $x \\in X$ and for any $B \\in \\mathcal B'$ with $B \\ni x$, there exists $B' \\in \\mathcal B'$ such that $x \\in B' \\subseteq B$.\n\t\n\t\\begin{proof}\t\n\t\tFor $\\implies$. Let $B \\in \\mathcal B$. Clearly, $B \\in \\mathcal T$. Also, $B \\in \\mathcal T'$ for $\\mathcal T \\subseteq \\mathcal T'$. By Corollary \\ref{coro: alt def of basis}, there exists $\\mathcal I' \\subseteq \\mathcal B'$ such that $B = \\bigcup \\mathcal I'$. Clearly, all $\\mathcal I'$-sets are subsets of $B$.\n\t\t\n\t\tFor $\\impliedby$. For all $B \\in \\mathcal B$ and for all $x \\in B$, there exists $B' \\in \\mathcal B'$ with $x \\in B' \\subseteq B$. Let $\\mathcal J'$ denote all such $B'$, then we have $B = \\bigcup \\mathcal J'$. By Definition \\ref{def: basis}, we have $B \\in \\mathcal B \\subseteq \\mathcal T'$. Above all, $\\mathcal T \\subseteq \\mathcal T$.\n\t\\end{proof}\n\\end{theorem}\n%--------------------------------\n\n\n\n\n\n%--------------------------------\n\\begin{note}\n\tIn this theorem, it is not necessary that $\\mathcal B \\subseteq \\mathcal B'$. For example, let \n\t$$\n\t\\begin{aligned}\n\t\t& \\mathcal B = \\left\\{ (a, b) \\subseteq \\mathbb R : b - a = 1 \\right\\}, \\\\\n\t\t& \\mathcal B' = \\left\\{ (a, b) \\subseteq \\mathbb R : b - a = 2 \\right\\}.\n\t\\end{aligned}\n\t$$\n\tObviously, $\\mathcal B \\not \\subseteq \\mathcal B'$ and $\\mathcal B' \\not \\subseteq \\mathcal B$, but they generate exactly the same topologies on $\\mathbb R$.\n\n\tFor another example, let\n\t$$\n\t\\begin{aligned}\n\t\t& \\mathcal B = \\left\\{ \\text{all open intervals in $\\mathbb R$}\\right\\}, \\text{ and} \\\\\n\t\t& \\mathcal B' = \\left\\{ \\text{all singletons in $\\mathbb R$} \\right\\}.\n\t\\end{aligned}\n\t$$\n\tIn this case, also, $\\mathcal B \\not \\subseteq \\mathcal B'$ and $\\mathcal B' \\not \\subseteq \\mathcal B$, but $\\mathcal B'$ generates the discrete topology which is the finest topology on $\\mathbb R$.\n\\end{note}\n%--------------------------------\n\n\n%%--------------------------------\n%\\begin{theorem}\n%\tLet $(X, \\mathcal T)$ be a topological space be genrated by a base $\\mathcal B$. For all $U \\in \\mathcal T$, there is a $B \\in \\mathcal B$ such that $U \\subseteq \\mathcal B$.\n%\t\n%\t\\begin{proof}\n%\t\tBy Definition \\ref{def: generated by basis}, if $\\mathcal T$ is generated by $\\mathcal B$, then for all $U \\in \\mathcal T$, there is an finite set $I$, such that\n%\t\t$$\n%\t\tU = \\bigcap_{i \\in I} B_i, \\quad B_i \\in \\mathcal B.\n%\t\t$$\n%\t\tThus, for at least one $k \\in I$, $U \\subseteq B_k$.\n%\t\\end{proof}\n%\\end{theorem}\n%%--------------------------------\n%\n%\n%%--------------------------------\n%\\begin{proposition}\n%\tLet $X$ be any set, and let $\\mathcal T$ and $\\mathcal T'$ be its topologies generated by basis $\\mathcal B$ and $\\mathcal B'$ respectively. Then $\\mathcal T'$ is finer than $\\mathcal T$ iff for any $B \\in \\mathcal B$, there is a $B' \\in \\mathcal B'$ such that $B' \\subseteq B$.\n%\t\n%\t\\begin{proof}\n%\t\tIf $\\mathcal T$ is generated by $\\mathcal B$, then for all $U' \\in \\mathcal T'$,\n%\t\t$$\n%\t\tU' = \\bigcup_{j \\in J} B_j',\n%\t\t$$\n%\t\twhere $B_j \\in \\mathcal B$.\n%\t\t\n%\t\tAs $\\mathcal T$ is generated by $\\mathcal B$, then, certainly, $\\mathcal B \\subseteq \\mathcal T$.\n%\n%\t\tBy the conditions we have, $\\mathcal T \\subseteq \\mathcal T'$ iff for all $B \\in \\mathcal B$, there is $W' \\in \\mathcal T$ such that\n%\t\t$$\n%\t\tB = W' = \\bigcup_{i \\in I} B_i',\n%\t\t$$\n%\t\twhere $B_i' \\in \\mathcal B'$. Certainly, all such $B_i'$ are contained in $B$.\n%\t\\end{proof}\n%\\end{proposition}\n%%--------------------------------\n%\n%\n%%--------------------------------\n%\\begin{proposition}\n%\tLet $X$ be any set, and let $\\mathcal T \\subseteq \\mathcal P(X)$. $\\mathcal T$ is a topology on $X$ iff it generates itself.\n%\t\n%\t\\begin{proof}\n%\t\tIf $\\mathcal T$ is a topology on $X$, then, by Definition \\ref{def: generated by basis}, any open set generated by $\\mathcal T$ is still a member of $\\mathcal T$. On the other hand, if $\\mathcal T$ generates itself, then, $\\emptyset$ and $X$ must be members of $\\mathcal T$, and, by Definition \\ref{def: generated by basis}, $\\mathcal T$ is a topology on $X$.\n%\t\\end{proof}\n%\\end{proposition}\n%%--------------------------------\n\n\n% todo: check this link to fill the propositions.\n% \n% https://en.wikipedia.org/wiki/Base_(topology)#Theorems\n% \n% check the \"local base\" theorem in this link.\n\n\n\n\n\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": "9c6f6358825ce00d5b97fce8dcf132dfebb80654", "size": 7538, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/notes-for-general-topology-v0/cover-and-basis.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/cover-and-basis.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/cover-and-basis.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": 39.0569948187, "max_line_length": 362, "alphanum_fraction": 0.5835765455, "num_tokens": 2417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.8740772318846386, "lm_q1q2_score": 0.7609692416526694}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{datetime}\n\\usepackage{lipsum}\n\\graphicspath{{images/}}\n\n\\setlength\\parindent{0pt}\t% no indent for entire document\n\\setcounter{MaxMatrixCols}{20}\n\n\\title{Convolution and Deconvolution}\n\n \n\\begin{document}\n\n\\begin{titlepage}\n\\author{Hao Huang}\n\\date{\\today}\n\\maketitle\n\\end{titlepage}\n\n\\tableofcontents\n\\newpage\n\n\\section{2D Convolution}\n\\begin{center}\n\\includegraphics[scale=0.7]{conv}\n\\end{center}\nThe blue grid is input image ($4\\times 4$), and the green grid is output image ($2\\times 2$). The kernel size is $3\\times 3$. Stride is 1 and padding is 0. The weight of the kernel at the localization $(i, j)$ is donated as $w_{i, j}$. The value of the image at the location $(i, j)$ is donated as $x_{i,j}$.\nThe kernel is:\n\\[\nw=\n\\begin{bmatrix}\nw_{0,0} & w_{0,1} & w_{0,0} \\\\ \nw_{1,0} & w_{1,1} & w_{1,2} \\\\\nw_{2,0} & w_{2,1} & w_{2,2} \n\\end{bmatrix}\n\\]\nRewrite image $X$ as a vector:\n$\n\\begin{bmatrix}\nx_{0,0} & x_{0,1} & \\dots & x_{3,2} & x_{3,3} \n\\end{bmatrix}^T\n$.Therefore, convolution can be written as matrix multiplication:\n\\[\nY=w*X=WX=\n\\]\n\\[\n\\setlength{\\arraycolsep}{2pt}\n\\renewcommand{\\arraystretch}{1}\n\\begin{bmatrix}\nw_{0,0} & w_{0,1} & w_{0,2} & 0 & w_{1,0} & w_{1,1} & w_{1,2} & 0 & w_{2,0} & w_{2,1} & w_{2,2} & 0 & 0 & 0 & 0 & 0\\\\\n0 & w_{0,0} & w_{0,1} & w_{0,2} & 0 & w_{1,0} & w_{1,1} & w_{1,2} & 0 & w_{2,0} & w_{2,1} & w_{2,2} & 0 & 0 & 0 & 0\\\\\n0 & 0 & 0 & 0 & w_{0,0} & w_{0,1} & w_{0,2} & 0 & w_{1,0} & w_{1,1} & w_{1,2} & 0  & w_{2,0} & w_{2,1} & w_{2,2} & 0\\\\\n0 & 0 & 0 & 0 & 0 & w_{0,0} & w_{0,1} & w_{0,2} & 0 & w_{1,0} & w_{1,1} & w_{1,2} & 0 & w_{2,0} & w_{2,1} & w_{2,2}\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\nx_{0,0}\\\\ x_{0,1}\\\\ x_{0,2} \\\\ x_{0,3} \\\\ x_{1,0} \\\\x_{1,1} \\\\ x_{1,2} \\\\x_{1,3} \\\\ x_{2,0}\\\\ x_{2,1}\\\\ x_{2,2} \\\\ x_{2,3} \\\\ x_{3,0} \\\\x_{3,1} \\\\ x_{3,2} \\\\x_{3,3}\n\\end{bmatrix}\n\\]\n$W$ is a doubly block circulant matrix (a special case of Toeplitz matrix).\nHere we define:\n\\[\nW_0=\n\\begin{bmatrix}\nw_{0,0} & w_{0,1} & w_{0,2} & 0 \\\\ 0 & w_{0,0} & w_{0,1} & w_{0,2}\n\\end{bmatrix} \\;\nW_1=\n\\begin{bmatrix}\nw_{1,0} & w_{1,1} & w_{1,2} & 0 \\\\ 0 & w_{1,0} & w_{1,1} & w_{1,2}\n\\end{bmatrix}\n\\]\n\\[\nW_3=\n\\begin{bmatrix}\nw_{2,0} & w_{2,1} & w_{2,2} & 0 \\\\ 0 & w_{2,0} & w_{2,1} & w_{2,2}\n\\end{bmatrix} \\;\n\\bf{0}=\n\\begin{bmatrix}\n0 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 0\n\\end{bmatrix}\n\\]\n$W_0$,$W_1$,$W_2$, and $\\bf{0}$ are all Toeplitz matrix. $W$ can be written as:\n\\[\nW=\n\\begin{bmatrix}\nW_0 & W_1 & W_2 & \\bf{0} \\\\ \\bf{0} & W_0 & W_1 & W_2\n\\end{bmatrix}\n\\]\nTherefore, $W$ is a doubly block circulant matrix.\n\n\\section{2D Deconvolution}\nIn the above example, the size of $X$ is $16\\times 1$ and the size of $Y$ is $4\\times 1$. The dimension of $W$ is $4\\times 16$. In order to recover the size of $Y$ to the size of $X$, we just need $W^TY$ (We cannot recover the value of $X$, but just size):\n\\[\nY^\\prime = W^TY = W^T(WX)\n\\]\nIf we donate $Y$ as:$\n\\begin{bmatrix}\ny_{0,0} & y_{0,1} & y_{1,0} & y_{1,1}\n\\end{bmatrix}^T\n$, the deconvolution can be written as:\n\\[\nY^\\prime = W^TY = \n\\begin{bmatrix}\nw_{0,0} & 0 & 0 & 0 \\\\ w_{0,1} & w_{0,0} & 0 & 0 \\\\\nw_{0,2} & w_{0,1} & 0 & 0 \\\\ 0 & w_{0,2} & 0 & 0 \\\\\nw_{1,0} & 0 & w_{0,0} & 0 \\\\ w_{1,1} & w_{1,0} & w_{0,1} & w_{0,0}\\\\\nw_{1,2} & w_{1,1} & w_{0,2} & w_{0,1} \\\\ 0 & w_{1,2} & 0 & w_{0,2}\\\\\nw_{2,0} & 0 & w_{1,0} & 0 \\\\ w_{2,1} & w_{2,0} & w_{1,1} & w_{1,0}\\\\\nw_{2,2} & w_{2,1} & w_{1,2} & w_{1,1} \\\\ 0 & w_{2,2} & 0 & w_{1,2}\\\\\n0 & 0 & w_{2,0} & 0 \\\\ 0 & 0 & w_{2,1} & w_{2,0} \\\\\n0 & 0 & w_{2,2} & w_{2,1} \\\\ 0 & 0 & 0 & w_{2,2}\n\\end{bmatrix}\n\\begin{bmatrix}\ny_{0,0} \\\\ y_{0,1} \\\\ y_{1,0} \\\\ y_{1,1}\n\\end{bmatrix}\n\\]\nIf we rewrite it in convolution format $Y^\\prime=w^\\prime*Y$, where $w^\\prime$ is the top-bottom AND left-right flip of the original filter $w$.\n\\begin{center}\n\\includegraphics[scale=0.5]{deconv}\n\\end{center}\nIn the above image, the blue grid is $Y$, and the green grid is $Y^\\prime$. Stride is 1 and padding is 2.\n\nWe can write this process as:\n\\[\nX -> Y = conv(X) -> deconv(Y) -> Y^\\prime\n\\]\nTo keep $Y^\\prime$ has the same size as $X$, we need to add paddings to $conv(X)$. Usually we add 0 paddings to $conv(X)$. There are two common padding strategries:\n\\begin{enumerate}\n\\item{Add paddings around an image}\n\\begin{center}\n\\includegraphics[scale=0.5]{spad}\n\\end{center}\n\\item{Add paddings inside an image}\n\\begin{center}\n\\includegraphics[scale=0.5]{ipad}\n\\end{center}\n\\end{enumerate}\n\nThese two strategies yield different results. How to choose this two strategies depends on which one can keep the image size.\n\n\\end{document}", "meta": {"hexsha": "e71f73c0903a23d18b6f40948e85c9a1e4dc7438", "size": 4631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Deconvolution/Backpropagation.tex", "max_stars_repo_name": "huanghao-code/Notes", "max_stars_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Deconvolution/Backpropagation.tex", "max_issues_repo_name": "huanghao-code/Notes", "max_issues_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Deconvolution/Backpropagation.tex", "max_forks_repo_name": "huanghao-code/Notes", "max_forks_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_forks_repo_licenses": ["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.1597222222, "max_line_length": 308, "alphanum_fraction": 0.591017059, "num_tokens": 2140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972583359806, "lm_q2_score": 0.8740772253241802, "lm_q1q2_score": 0.7609692359411524}}
{"text": "\\section{Integration along Lines, Surfaces, and Volumes}\r\n\\subsection{Line Integrals}\r\n\\begin{definition}\r\n    For a vector field $\\underline{F}(\\underline{x})$ and a curve $C$ where $\\underline{x}(t)$ travels through for $t\\in [a,b]$, we define the line integral\r\n    $$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}=\\int_a^b\\underline{F}(\\underline{x}(t))\\cdot\\frac{\\mathrm d\\underline{x}}{\\mathrm dt}\\,\\mathrm dt$$\r\n\\end{definition}\r\n\\begin{example}\r\n    Let\r\n    $$\\underline{F}=\\begin{pmatrix}\r\n        x^2y\\\\\r\n        yz\\\\\r\n        2zx\r\n    \\end{pmatrix},C_1:[0,1]\\ni t\\mapsto\\begin{pmatrix}\r\n        t\\\\\r\n        t\\\\\r\n        t\r\n    \\end{pmatrix},C_2:[0,1]\\ni t\\mapsto\\begin{pmatrix}\r\n        t\\\\\r\n        t\\\\\r\n        t^2\r\n    \\end{pmatrix}$$\r\n    ...\r\n    We have\r\n    $$\\int_{C_1}\\underline{F}\\cdot\\mathrm d\\underline{x}=\\frac{5}{4},\\int_{C_2}\\underline{F}\\cdot\\mathrm d\\underline{x}=\\frac{13}{10}$$\r\n    Hence in general line integrals between two points depends on path.\r\n\\end{example}\r\n\\begin{example}\r\n    In cylindral polars $(\\rho,\\phi,z)$, we consider $\\underline{F}=\\rho z\\underline{e_{\\phi}}$.\r\n    Consider the line $C:[0,2\\pi]\\ni t\\mapsto (a\\cos t,a\\sin t,t)^\\top$.\r\n    So $\\rho=a,\\phi=z=t$\r\n    We have $\\underline{F}\\cdot\\mathrm d\\underline{x}=\\rho^2 z\\mathrm d\\phi$, therefore\r\n    $$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}=\\int_0^{2\\pi}a^2t\\,\\mathrm dt=2a^2\\pi^2$$\r\n\\end{example}\r\nIn those cases where $C$ is closed, we write\r\n$$\\oint_C\\underline{F}\\cdot\\mathrm d\\underline{x}=\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}$$\r\nThis is sometimes called the circulation of $\\underline{F}$ over $C$.\r\n\\subsection{Conservative Forces and Exact Differentials}\r\n$\\underline{F}\\cdot\\mathrm d\\underline{x}$ is an example of a differential form.\r\n\\begin{definition}\r\n    We say $\\underline{F}\\cdot\\mathrm d\\underline{x}$ is exact if $\\underline{F}\\cdot\\mathrm d\\underline{x}=\\mathrm df$ for some scalar function $f$.\r\n    Equivalently, the differential form is exact iff $\\underline{F}=\\nabla f$ for a scalar function $f$.\r\n    In this case, we say $\\underline{F}$ is conservative.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    If $\\underline{F}\\cdot\\mathrm d\\underline{x}$ is exact, then\r\n    $$\\oint_C\\underline{F}\\cdot\\mathrm d\\underline{x}=0$$\r\n    for any closed $C$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    By exactness, $\\underline{F}=\\nabla f$ for a scalar function $f$.\r\n    Suppose $C: [a,b]\\ni t\\mapsto\\underline{x}(t)$.\r\n    $$\\oint_C\\underline{F}\\cdot\\mathrm d\\underline{x}=\\int_a^b\\nabla f(\\underline{x}(t))\\cdot\\underline{x}^\\prime(t)\\,\\mathrm dt=\\int_a^b\\frac{\\mathrm d}{\\mathrm dt}f(\\underline{x}(t))\\,\\mathrm dt=f(\\underline{x}(b))-f(\\underline{x}(a))=0$$\r\n    since $\\underline{x}(b)=\\underline{x}(a)$.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Consider the cylindral coordinate $(\\rho,\\phi,z)$, suppose $\\underline{F}\\cdot\\mathrm d\\underline{x}=\\mathrm d\\phi$ and $C:[0,2\\pi]\\ni t\\mapsto (\\cos t,\\sin t,0)^\\top$, then by calculation we have\r\n    $$\\oint_C \\underline{F}\\cdot\\mathrm d\\underline{x}=2\\pi\\neq 0$$\r\n    It does not work!\r\n    The reason for this is that $\\phi\\in\\mathbb R/2\\pi\\mathbb Z$.\r\n    So we are doing here is taking $\\phi$ as a multivalued function instead of an actual function.\r\n\\end{remark}\r\nSuppose we have a set of curvilinear coordinate $(u,v,w)=(u_1,u_2,u_3)$, and we have $\\underline{F}\\cdot\\mathrm d\\underline{x}=\\theta_i\\,\\mathrm du_i$ where $\\theta_i=\\underline{F}\\cdot\\mathrm d\\underline{x}/\\mathrm du_i$.\r\nIf $\\underline{F}\\cdot\\mathrm d\\underline{x}$ is exact and is the differential $\\mathrm df$, then $\\theta_i=\\partial f/\\partial u_i$, and\r\n$$\\frac{\\partial \\theta_i}{\\partial u_j}=\\frac{\\partial^2 f}{\\partial u_i\\partial u_j}=\\frac{\\partial^2 f}{\\partial u_j\\partial u_i}=\\frac{\\partial \\theta_j}{\\partial u_i}$$\r\n\\begin{definition}\r\n    If the above condition is met, we say the differential form $\\underline{F}\\cdot\\mathrm d\\underline{x}$ is closed.\r\n\\end{definition}\r\nSo exact differentials are all closed.\r\n\\begin{theorem}\r\n    If the domain of the vector field is simply connected, then any closed differential is exact.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Not gonna do it.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The differential $y\\,\\mathrm dx-x\\,\\mathrm dy$ is not closed hence not exact.\\\\\r\n    2. Consider $C:[t_1,t_2]\\ni t\\mapsto (f,g,h)$ where $f,g,h$ are completely unintelligible functions such that $(f,g,h)(t_1)=(f,g,h)(t_2)$, then whatever they are, we always have\r\n    $$\\oint_C 3x^2y\\,\\mathrm dx+x^3\\,\\mathrm dy=0$$\r\n    As the integrand is exact.\r\n\\end{example}\r\n\\begin{theorem}\r\n    Suppose $\\underline{F}\\cdot\\mathrm\\underline{x}=\\mathrm df$, then consider $C$ from $\\underline{a}$ from $\\underline{b}$, then we have\r\n    $$\\int_C\\underline{F}\\cdot\\mathrm\\underline{x}=f(\\underline{b})-f(\\underline{a})$$\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Obvious.\r\n\\end{proof}\r\n\\begin{example}\r\n    Suppose $\\underline{F}=m\\underline{\\ddot{x}}$ and $C:[a,b]\\ni t\\mapsto\\underline{x}(t)$, we have\r\n    $$\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}=m\\int_a^b\\underline{\\ddot{x}}\\cdot\\underline{\\dot{x}}\\,\\mathrm dt=\\left.\\frac{1}{2}m|\\underline{\\dot{x}}|^2\\right|_a^b$$\r\n    If $\\underline{F}=-\\nabla V$, then we have the conservation of energy:\r\n    $$\\left.\\frac{1}{2}m|\\underline{\\dot{x}}|^2\\right|_a^b=\\int_C\\underline{F}\\cdot\\mathrm d\\underline{x}=-\\left.V(\\underline{x}(t))\\right|^b_a$$\r\n    So $V(\\underline{x})+m|\\underline{\\dot{x}}|^2/2$ conserves.\r\n\\end{example}\r\n\\subsection{Integration over Areas}\r\nWe want to extend our definition of Riemannian integrals to $\\mathbb R^2$.\r\nTo do it, we partition our region $D$ into small cells $A_{ij}$ with area $\\delta A_{ij}$ diameter at most $\\epsilon$ and pick points $(x_i,y_j)\\in A_{ij}$.\r\n\\begin{definition}\r\n    We thus define the area integral by\r\n    $$\\int_Df\\,\\mathrm dA=\\lim_{\\epsilon\\to 0}\\sum_{i,j}f(x_i,y_j)\\delta A_{ij}$$\r\n    We say this integral exists if this limit is independent of the choice of the partition $A_{ij}$.\r\n\\end{definition}\r\nWhen the integral exists, the obivous choice is to split $D$ into rectangular cells and set $x_{i+1}=x_i+\\delta x,y_{j+1}=y_j+\\delta y$ such that $0<\\delta x,\\delta y<<\\epsilon$.\r\nThen we may fix $y$ first and take $\\delta x\\to 0$, and then do $\\delta y\\to 0$.\r\nThat is, we split the horizontal region by $\\epsilon$-thin stripes and sum over the Riemann integrals in each stripe.\r\nIf we do this, then\r\n$$\\int_Df\\,\\mathrm dA=\\int_Y\\int_{x_y}f(x,y)\\,\\mathrm dx\\,\\mathrm dy$$\r\nwhere $x_y=\\{x:(x,y)\\in D\\}$.\r\nIf we do vertical stripes first, then we get stuff like\r\n$$\\int_Df\\,\\mathrm dA=\\int_X\\int_{y_x}f(x,y)\\,\\mathrm dy\\,\\mathrm dx$$\r\nwhere $y_x=\\{y:(x,y)\\in D\\}$.\r\nIn short, we seems to have $\\mathrm dA=\\mathrm dx\\,\\mathrm dy=\\mathrm dy\\,\\mathrm dx$\r\n\\begin{theorem}[Fubini's Theorem]\r\n    If the integral exists (or under suitable conditions), then\r\n    $$\\int_Df\\,\\mathrm dA=\\int_Y\\int_{x_y}f(x,y)\\,\\mathrm dx\\,\\mathrm dy=\\int_X\\int_{y_x}f(x,y)\\,\\mathrm dy\\,\\mathrm dx$$\r\n\\end{theorem}\r\n\\begin{example}\r\n    $f(x)=xy^2$ and $D$ is the triangle joining $(0,0),(0,1),(1,0)$.\r\n    Then we have\r\n    $$\\int_Df\\,\\mathrm dA=\\int_0^1\\int_{0}^{1-y}xy^2\\,\\mathrm dx\\,\\mathrm dy=\\int_0^1\\frac{(1-y)^2y^2}{2}\\,\\mathrm dy=\\frac{1}{60}$$\r\n    If we do $y$ (vertical slices) first,\r\n    $$\\int_Df\\,\\mathrm dA=\\int_0^1\\int_0^{1-x}xy^2\\,\\mathrm dy\\,\\mathrm dx=\\int_0^1\\frac{x(1-x)^3}{3}\\,\\mathrm dx=\\frac{1}{60}$$\r\n\\end{example}\r\nRecall that in the one dimensional case, we can do integrations by some magical substitutions.\r\nObviously we will wish to extend this technique to integrations over higher dimensions.\r\n\\begin{proposition}[Change of Variable]\r\n    Let $x=x(u,v),y=y(u,v)$ be a smooth bijection $D\\to D'$ with smooth inverse, then\r\n    $$\\iint_D f(x,y)\\,\\mathrm dx\\,\\mathrm dy=\\iint_{D'}f(x(u,v),y(u,v))|J|\\,\\mathrm du\\,\\mathrm dv$$\r\n    where\r\n    $$J=\\frac{\\partial (x,y)}{\\partial (u,v)}=\\begin{vmatrix}\r\n        x_u&x_v\\\\\r\n        y_u&y_v\r\n    \\end{vmatrix}$$\r\n    is the Jacobian.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Partition $D$ using image of rectangular partition of $D'$.\r\n    Then we have\r\n    $$\\int_Af\\,\\mathrm dA=\\lim_{\\epsilon\\to 0}\\sum_{i,j}f(x(u_i,v_j),y(u_i.y_j))\\delta A_{ij}^{x,y}$$\r\n    But $\\delta A_{ij}^{x,y}\\approx |J|\\delta A_{ij}^{u,v}$ by considering the area as local parallelograms and expanding the Taylor series to first order.\r\n    So we have this formula.\r\n\\end{proof}\r\n\\begin{example}\r\n    Consider $x=\\rho\\cos\\phi,y=\\rho\\sin\\phi$ for $\\rho\\ge 0$, then $|J|=\\rho$, hence $\\mathrm dx\\,\\mathrm dy=\\rho\\,\\mathrm d\\rho\\,\\mathrm d\\phi$.\r\n    Take $D$ to be the region $x>0,y>0$, then this region is mapped to the region $\\phi\\in (0,\\pi/2)$.\r\n    So let\r\n    $$I=\\int_0^\\infty e^{-x^2}\\,\\mathrm dx$$\r\n    then\r\n    $$I^2=\\int_0^\\infty\\int_0^\\infty e^{-x^2-y^2}\\rho\\,\\mathrm dx\\,\\mathrm dy=\\int_0^{\\pi/2}\\int_0^\\infty e^{-\\rho^2}\\rho\\,\\mathrm d\\rho\\,\\mathrm d\\phi=\\frac{\\pi}{4}\\implies I=\\frac{\\sqrt\\pi}{2}$$\r\n\\end{example}\r\n\\subsection{Integration over Volumes}\r\nFor a bounded volume $V$ in $\\mathbb R^3$, define sets $V_{ijk}$ having volume $\\delta V_{ijk}$ which partition $V$ and each is contained in a ball of radius at most $\\epsilon$.\r\nThen we pick some $(x_i,y_j,z_k)$ in each cell $V_{ijk}$ and define the integral over the region $V$ as\r\n$$\\lim_{\\epsilon\\to 0^+}\\sum_{i,j,k}f(x_i,y_j.z_k)\\delta V_{ijk}$$\r\nIf we use a rectangular parallelopiped partition, we find that $\\mathrm dV=\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz$ in any order (by Fubini).\r\n\\begin{example}\r\n    1. Consider the domain to be the tetrahedron $V=\\{(x,y,z)\\in\\mathbb R_{\\ge 0}^3:x+y+z\\le 1\\}$.\r\n    So\r\n    $$\\int_V\\mathrm dV=\\int_0^1\\int_0^{1-x}\\int_0^{1-x-y}\\mathrm dz\\,\\mathrm dy\\,\\mathrm dx=\\frac{1}{6}$$\r\n    2. For a volumn $V$, we define the center of mass $\\Delta_{\\rm COM}$ by\r\n    $$\\Delta_{\\rm COM}=\\frac{1}{M}\\int_V\\rho\\underline{x}\\,\\mathrm dV$$\r\n    where $\\rho$ is the density, $M=\\rho V$ is the mass and the integral is by component.\r\n    Consider the same tetrahedron as above and suppose $\\rho=1$.\r\n    Hence $M=1/6$, so\r\n    $$\\Delta_{\\rm COM}=6\\int_V1\\begin{pmatrix}\r\n        x\\\\\r\n        y\\\\\r\n        z\r\n    \\end{pmatrix}\\,\\mathrm dV=\\frac{1}{4}\\begin{pmatrix}\r\n        1\\\\\r\n        1\\\\\r\n        1\r\n    \\end{pmatrix}$$\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $\\underline{x}=\\underline{x}(u,v,w)$ (where $\\underline{x}=(x,y,z)$), denote the smooth bijection with smooth inverse which connects the region $V$ in the $xyz$ space and $V'$ in the $uvw$ space, then\r\n    $$\\iiint_Vf(x,y,z)\\,\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz=\\iiint_{V'}f(x(u,v,w),y(u,v,w),z(u,v,w))|J|\\,\\mathrm du\\,\\mathrm dv\\,\\mathrm dw$$\r\n    where\r\n    $$J=\\begin{vmatrix}\r\n        x_u&x_v&x_w\\\\\r\n        y_u&y_v&y_w\\\\\r\n        z_u&z_v&z_w\r\n    \\end{vmatrix}$$\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Same (imprecise) idea.\r\n\\end{proof}\r\n\\begin{example}\r\n    If we use cylindral polars, we find $\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz=\\rho\\,\\mathrm d\\rho\\,\\mathrm d\\phi\\,\\mathrm dz$, and if we use spherical polars, we have $\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz=r^2\\sin\\theta\\,\\mathrm dr\\,\\mathrm d\\theta\\,\\mathrm d\\phi$.\r\n\\end{example}\r\n\\begin{example}\r\n    1. Consider a sphere with radius $R$, we want to find its volume.\r\n    If we do it with Cartesians, then\r\n    $$\\int_{-R}^R\\int_{-\\sqrt{R^2-z^2}}^{\\sqrt{R^2-z^2}}\\int_{-\\sqrt{R^2-z^2-y^2}}^{\\sqrt{R^2-z^2-y^2}}\\mathrm dx\\,\\mathrm dy\\,\\mathrm dz=\\frac{4}{3}\\pi R^3$$\r\n    after a lot of useless effort.\\\\\r\n    So obviously we choose to use spherical polars, hence the volume is\r\n    $$\\int_0^{2\\pi}\\int_0^\\pi\\int_0^{R}r^2\\sin\\theta\\,\\mathrm dr\\,\\mathrm d\\theta\\,\\mathrm d\\phi=\\frac{4}{3}\\pi R^2$$\r\n    after minimal effort.\\\\\r\n    2. A ball of radius $b>0$ with cylinder with radius $a>0$ (and infinite length) with $a>0$ removed.\r\n    So maybe we will use some cylindral polars, so the volume is\r\n    $$\\int_0^{2\\pi}\\int_a^b\\int_{-\\sqrt{b^2-\\rho^2}}^{\\sqrt{b^2-\\rho^2}}\\rho\\,\\mathrm dz\\,\\mathrm d\\rho\\,\\mathrm d\\phi=\\frac{4}{3}\\pi(b^2-a^2)^{3/2}$$\r\n    which was easy.\r\n\\end{example}", "meta": {"hexsha": "e38257131527cadae11827bfcef842b6cf9d9f42", "size": 12017, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/int.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/int.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/int.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": 59.197044335, "max_line_length": 261, "alphanum_fraction": 0.6483315303, "num_tokens": 4194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267864276108, "lm_q2_score": 0.8757870029950159, "lm_q1q2_score": 0.7609072074072281}}
{"text": "\\section{Fundamental class}\nNote that if $M$ is a compact manifold, then $H_q(M;R)=0$ for $q\\gg 0$, and if $R$ is a PID, then for all $q$, $H_q(M;R)$ is finitely-generated. This follows from:\n\\begin{claim}\nSuppose $X$ admits an open cover $\\{U_i\\}_{i=1}^n$ such that all intersections are either empty or contractible (this is what you get for a good cover on a manifold). Then $H_q(X;R)=0$ for $q\\geq n$, and if $R$ is a PID, then for all $q$, $H_q(X;R)$ is finitely-generated.\n\\end{claim}\n\\begin{proof}\nInduct. Certainly true for $n=1$. Let $Y=\\bigcup^{n-1}_{i=1}U_i$, then this statement is true by induction -- and similarly for $Y\\cap U_n$. Now use Mayer-Vietoris. You have $\\cdots\\to H_q(Y\\cap U_n)\\to H_q(Y)\\oplus H_q(U_n)\\to H_q(X)\\to H_{q-1}(Y\\cap U_n)\\to\\cdots$. When $q=n-1$, $H_q(Y\\cap U_n)$ could be nonzero, and so you might get something nontrivial (???). Also, you'll get a sexseq by unsplicing the lexseq: $0\\to H_q(Y)\\oplus H_q(U_n)/\\text{something}\\to H_q(X)\\to \\text{submodule of }H_{q-1}(Y\\cap U_n)\\to 0$, where you use $R$ being a PID to conclude that $\\text{submodule of }H_{q-1}(Y\\cap U_n)$ is finitely generated.\n\\end{proof}\nLet $M$ be an $n$-manifold. We had a map $j:H_n(M)\\to \\Gamma(M;o_M)$. Here $\\Gamma(M;o_M)$ is the collection of compatible elements of $H_n(M,M-x)$ for $x\\in M$. This map $j:H_n(M)\\to \\Gamma(M;o_M)$ sends $c\\mapsto(x\\mapsto j_x c)$ where $j_x:H_n(M,\\emptyset)\\to H_n(M,M-x)$. I want to make two refinements.\n\nYou can't expect $j$ to be surjective, except maybe when $M$ is compact. Here's why. Let $c\\in Z_n(M)$. It's a sum of simplices, and each simplex is compact, and so the union of the images is compact, and hence there's a compact subset $K\\subseteq M$ such that $c\\in Z_n(K)$. Now if I take $x\\not\\in K$, then the map $H_n(K)\\to H_n(M)$ splits as $H_n(K)\\to H_n(M-x)\\to H_n(M)$. In the relative homology, $H_n(M,M-x)$, the map $H_n(K)\\to H_n(M)\\to H_n(M,M-x)$ sends $c$ to zero.\n\\begin{definition}\nLet $\\sigma$ be a section of $p:E\\to B$ (local system). Then the support of $\\sigma$ is defined as $\\mathrm{supp}(\\sigma)=\\overline{\\{x\\in B|\\sigma(x)\\neq 0\\}}$. The collection of all sections with compact support is $\\Gamma_c(B;E)$, and it's a submodule of $\\Gamma(B;E)$.\n\\end{definition}\nThe first refinement is that $j:H_n(M)\\to \\Gamma(M;o_M)$ lands in $\\Gamma_c(M;o_M)$, because homology is compactly supported.\n\nThe second refinement seems a little artificial but is part of the inductive process. Let $A\\subseteq M$ be closed. Then you have a restriction map $H_n(M,M-A)\\xrightarrow{j_x}H_n(M,M-x)$ for $x\\in A$. Thus you get a map $j:H_n(M,M-A)\\to \\Gamma_c(A;o_M|_{A})$, the latter of which we'll just denote $\\Gamma_c(A;o_M)$.\n\\begin{theorem}\nThe map $j:H_n(M,M-A)\\to \\Gamma_c(A;o_M|_{A})$ is an isomorphism and $H_q(M,M-A)=0$ for $q>n$. (If $A=M$ then $j:H_n(M)\\to \\Gamma_c(M;o_M)$ is an isomorphism.)\n\\end{theorem}\n\\begin{proof}\nFor $X=\\RR^n$ and $A=D^n$. Well, $o_{\\RR^n}=\\RR^n\\times H_n(\\RR^n,\\RR^n-0)$ is trivial (i.e., a product projection), so $\\Gamma(D^n;o_{\\RR^n})=\\Hom_{\\mathbf{Top}}(D^n,H_n(\\RR^n,\\RR^n-0))$ where $H_n(\\RR^n,\\RR^n-0)$ is discrete, and this is therefore just a map from $\\pi_0$ into this, and thus $\\Gamma(D^n;o_{\\RR^n})=R$ (your coefficient). But also, $H_n(\\RR^n,\\RR^n-D^n)\\cong R$, so you have that $j$ gives $H_n(\\RR^n,\\RR^n-D^n)\\to \\Gamma_c(D^n;o_{\\RR^n}|_{D^n})$.\n\nSay that this is true for $A,B,A\\cap B$ -- we'll prove this for $A\\cup B$. Obviously, use Mayer-Vietoris. I have a restriction $\\Gamma_c(A\\cup B;o_M)\\to \\Gamma_c(A;o_M)\\oplus \\Gamma_c(B;o_M)$ that sits in an exact sequence $0\\to \\Gamma_c(A\\cup B;o_M)\\xrightarrow{\\text{inclusion, determined by }A,B} \\Gamma_c(A;o_M)\\oplus \\Gamma_c(B;o_M)\\to \\Gamma_c(A\\cap B;o_M)$. This is a gluing lemma. We also have a relative Mayer-Vietoris $H_n(M,M-A\\cup B)\\to H_n(M,M-A)\\oplus H_n(M,M-B)\\to H_n(M,M-A\\cap B)$, so we have:\n\\begin{align*}\n\\xymatrix@C=10pt{\n\t0\\ar[r] & \\Gamma_c(A\\cup B;o_M)\\ar[r]^{\\text{inclusion }A,B\\to A\\cup B} & \\Gamma_c(A;o_M)\\oplus \\Gamma_c(B;o_M)\\ar[r] & \\Gamma_c(A\\cap B;o_M)\\\\\n\tH_{n+1}(M,M-A\\cap B)=0\\ar[r]^0 & H_n(M,M-A\\cup B)\\ar[r]\\ar[u] & H_n(M,M-A)\\oplus H_n(M,M-B)\\ar[r]\\ar[u]^{j_\\ast}_{\\cong} & H_n(M,M-A\\cap B)\\ar[u]^{j_\\ast}_{\\cong}\n}\n\\end{align*}\nThis is a ``local-to-global'' argument. ``I don't feel like going through the point-set topology -- the rest of the proof is just annoyance.'' See Bredon's book for the conclusion of the proof.\n\\end{proof}\n\\begin{corollary}\n$j:H_n(M)\\to \\Gamma_c(M;o_M)$ is an isomorphism.\n\\end{corollary}\n\\begin{definition}\nAn $R$-orientation for $M$ is a section $\\sigma$ of $\\Gamma(M;o_M^\\times)$ where $o_M^\\times$ is the covering space of $M$ given by the generators (as $R$-modules) of the fibers of $o_M$.\n\\end{definition}\nIf $M$ is compact, then $j:H_n(M)\\to \\Gamma(M;o_M)$, and you get $[M]\\leftrightarrow \\sigma$. When does that exist?\n\n\\underline{Over $\\Z$:} $o_M^\\times\\to M$ is a double cover of $M$ (over every element you have two possible elements given by the two possible orientations ($\\pm 1$)). If $M$ is an $n$-manifold and $f:N\\to M$ is a covering space, then $N$ is also locally Euclidean. I have the orientation local system to get a pullback local system:\n\\begin{equation*}\n\\xymatrix{\n\tf^\\ast o_M=N\\times_M o_M\\ar[r]\\ar[d] & o_M\\ar[d]\\\\\n\tN\\ar[r] & M\n}\n\\end{equation*}\nBecause $N\\to M$ is a covering space, the fibers of $f^\\ast o_M$ are the same as the fibers of $o_N$, so actually, $f^\\ast o_M\\cong o_N$. For example, suppose $N=o_M^\\times$. What happens if I consider:\n\\begin{equation*}\n\\xymatrix{\n\to_N=N\\times_M N\\ar[r]\\ar[d] & N\\ar[d]\\\\\n\tN\\ar[r] & M\n}\n\\end{equation*}\nBut now, I have the identity $N\\to N$ that sits compatibly as:\n\\begin{equation*}\n\\xymatrix{\n\tN\\ar[r]^{\\mathrm{id}}\\ar[d] ^{\\mathrm{id}} & N\\ar[d]\\\\\n\tN\\ar[r] & M\n}\n\\end{equation*}\nAnd hence you get $N\\to o_N^\\times$, which is a section of $o_N^\\times\\to N$. The conclusion is that $N=o_M^\\times$ is canonically oriented (even if $M$ is not oriented!). If $M$ is oriented, then the local system is trivial and you have the trivial double cover.\n\nThe overarching conclusion is: if $M$ is an $n$-manifold, then:\n\\begin{enumerate}\n\\item $H_q(M)=0$ for $q>n$.\n\\item If $M$ is compact, then $H_n(M)\\xrightarrow{\\cong}\\Gamma(M,o_M)$.\n\\item If $M$ is connected and compact, then:\n\t\\begin{enumerate}\n\t\\item if $M$ is oriented with respect to $R$, then $H_n(M)\\cong \\Gamma(M,o_M)\\cong R$.\n\t\\item (I have no idea what was happening here, we didn't reach to a conclusion for a while.) if $M$ is not orientable, then $o_M^\\times$ is nontrivial. If $o_M^\\times$ has a section, then it's trivial (and so is $o_M$) because if it has a section $\\sigma:M\\to o^\\times_M$, define $M\\times R^\\times\\xrightarrow{\\cong} o_M^\\times$ by sending $(x,r)\\mapsto r\\sigma(x)\\in o_M^\\times$ (and the same thing $M\\times R\\xrightarrow{\\cong} o_M$ for the orientation local system itself). I don't see an argument to conclude that if $M$ is nonorientable, then there aren't any section of $o_M$. In particular, if $R=\\Z$, then $H_n(M;\\Z)=0$. I'm going to leave this as a statement without proof, unless any of you can help me.\n\t\\end{enumerate}\n\\end{enumerate}\nIf a section $\\sigma(x)=0$ for some $x$, then $\\sigma=0$.\n\\begin{remark}\nProf. Miller talked with me about this after class. If I recall correctly, one way to think about this is as follows. If you have a local system $p:E\\to B$, this can be viewed as a representation of $\\pi_1(B)\\to R^\\times$, and the $\\Gamma(B;E)=(E_x)^{\\pi_1(B)}$ where $\\pi_1(B)$ acts on the fibers by multiplication. Thus $(E_x)^{\\pi_1(B)}=R^{\\pi_1(B)}$. If $R=\\Z$, then $R^\\times=\\{\\pm 1\\}$, so $R^{\\pi_1(B)}=\\{r|ar=r,a\\in\\pi_1(B)\\}$, so that $\\Z^{\\pi_1(B)}=0$. Hence there are no sections of $o_M$, as desired. For a ring $R$, $o_{M,R}=o_{M,\\Z}\\otimes R$. Something else for $\\Z/2\\Z$. A higher homotopy theoretic perspective is that if you have a fibration $E\\to B$, then $E=PB\\times_{\\Omega B}F$ where $F$ is the fiber of the fibration, so that $\\Gamma(B;E)=\\Map_{\\Omega B}(PB,F)=F^{h\\Omega B}$. In the case of a covering space you recover what you have above since $\\pi_0(\\Omega B)=\\pi_1(B)$.\n\\end{remark}\n", "meta": {"hexsha": "64c4c7f1c6f2185d54bc80fc7a9da1168690a95c", "size": 8119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-36-fundamental-classes.tex", "max_stars_repo_name": "ichung/algtop-notes", "max_stars_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2017-04-26T15:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T22:47:06.000Z", "max_issues_repo_path": "old-905/lec-36-fundamental-classes.tex", "max_issues_repo_name": "ichung/algtop-notes", "max_issues_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2018-03-13T17:54:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-03-13T17:59:46.000Z", "max_forks_repo_path": "old-905/lec-36-fundamental-classes.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 104.0897435897, "max_line_length": 896, "alphanum_fraction": 0.6780391674, "num_tokens": 2864, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767906859264, "lm_q2_score": 0.8670357649558007, "lm_q1q2_score": 0.7608037604433332}}
{"text": "% -*- root: Main.tex -*-\n\\section{Principle Component Analysis}\n$\\mathbf{X} \\in \\mathbb{R}^{D \\times N}$. $N$ observations.\\\\\n1. Empirical Mean: $\\overline{\\mathbf{x}} = \\frac{1}{N} \\sum_{n=1}^N \\mathbf{x}_n$.\\\\\n2. Center Data: $\\overline{\\mathbf{X}} = \\mathbf{X} - [\\overline{\\mathbf{x}}, \\ldots, \\overline{\\mathbf{x}}] = \\mathbf{X} - \\mathbf{M}$.\\\\\n3. Cov.: $\\boldsymbol{\\Sigma} = \\frac{1}{N\t} \\sum_{n=1}^N (\\mathbf{x}_n - \\overline{\\mathbf{x}}) (\\mathbf{x}_n - \\overline{\\mathbf{x}})^\\top = \\frac{1}{N} \\overline{\\mathbf{X}}\\overline{\\mathbf{X}}^\\top$.\\\\\n4. Eigenvalue Decomposition: $\\boldsymbol{\\Sigma} = \\mathbf{U} \\boldsymbol{\\Lambda} \\mathbf{U}^\\top$.\\\\\n5. Select $K < D$, only keep $\\mathbf{U}_K = [u_1,...,u_{K}]$.\\\\\n6. Transform data onto new Basis: $\\overline{\\mathbf{Z}}_K = \\mathbf{U}_K^\\top \\overline{\\mathbf{X}}$.\\\\\n7. Reconstruct to original Basis: $\\tilde{\\overline{\\mathbf{X}}} = \\mathbf{U}_k \\overline{\\mathbf{Z}}_K$.\\\\\n8. Reverse centering: $\\tilde{\\mathbf{X}} = \\tilde{\\overline{\\mathbf{X}}} + \\mathbf{M}$.\\\\\nFor compression save $\\mathbf{U}_k, \\overline{\\mathbf{Z}}_K, \\overline{\\mathbf{x}}$.\\\\\n$\\mathbf{U}_k \\in \\mathbb{R}^{D \\times K}, \\boldsymbol{\\Sigma} \\in \\mathbb{R}^{D \\times D}, \\overline{\\mathbf{Z}}_K \\in \\mathbb{R}^{K \\times N}, \\overline{\\mathbf{X}} \\in \\mathbb{R}^{D \\times N}$ \\\\\n$\\bullet$ Reconstruction error = sum of discarded eigenvalues. \\\\\n$\\bullet$ The transformed dataset $\\overline{\\mathbf{Z}}_K$ has diagonal covariance matrix.\n\n\\subsection*{Iterative View}\nResiduals $r_i = x_i - \\tilde{x}_i = (\\mathbb{1} - uu^T)x_i$\\\\\nCov. matrix of residuals: $\\frac{1}{n} \\sum_{i=1}^n r_ir_i^\\top = \\frac{1}{n} \\sum_{i=1}^n (\\mathbb{1}-uu^T)x_i x_i^T (\\mathbb{1}-uu^T)^T = ... = \\Sigma - \\lambda uu^T$ \\\\\n1. Find principal eigenvector of $(\\Sigma - \\lambda u u^T)$\\\\\n2. which is the 2nd principal eigenvector of $\\Sigma$\\\\\n3. iterating to get $d$ principal eigenvector of $\\Sigma$ \\\\\n$\\bullet$ the principal eigenvector of $\\Sigma$ points in the direction with largest variance of the data ($argmax_{\\|u\\|=1} u^\\top \\Sigma u$).\n\n\\subsection*{Power iteration}\nfind principal eigenvector of A: $v_{t+1} = \\frac{Av_t}{||Av_t||}$, $\\lim_{t \\rightarrow \\infty} v_t = u_1$\\\\\n\n", "meta": {"hexsha": "d803f8ce2f305368352eac22694497b6ecab3e1e", "size": 2205, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "DimensionalityReduction.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": "DimensionalityReduction.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": "DimensionalityReduction.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": 78.75, "max_line_length": 206, "alphanum_fraction": 0.641723356, "num_tokens": 860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7607904222781889}}
{"text": "\\newpage\n\\section{CNN for Darcy equation}\n\\begin{breakablealgorithm}\n\t\\caption{$u={\\rm DarcyCNN}(\\kappa; f_d, coarse\\_grid\\_size,)$}\n\t\\label{alg:mgnet}\n\t\\begin{algorithmic}\n\t\t\\State Initialization:  $\\kappa$\n\t\t%\t\t\\State Initialization $u^{1,0}$\n%\t\t\\For{$ = 1:N_{epoch}$}\n%\t\t\\For{$i = 1:\\nu_$}\n\t\t\\State Encode\n\t\t\\begin{equation}\n\t\tu^{} = K^{3}  \\ast_2 \\sigma \\circ K^{ 2}\\ast \\sigma (K^{ 1}\\ast \\kappa).\n\t\t\\end{equation}\n\t\n%\t\t\\EndFor\n\t\t\\State Restriction to the coarse grid\n\t\t\\begin{equation}\n\t\tu^{} = \\sigma \\circ \\theta^{. 1} \\circ u^{}\n\t\t\\end{equation}\n\t\t\\State\n\t\tConvolution on the coarse grid\n\t\t\\begin{equation}\n\t\tu^{} =  \\sigma \\circ K^{ 5}\\ast \\sigma (K^{ 4}\\ast u^{}).\n\t\t\\end{equation}\n\t\t\\State Decode\n\t\t\\begin{equation}\n\t\tu^{} =  \\sigma \\circ \\theta^{ 3}\\circ \\sigma (\\theta^{ 2}\\circ u^{}).\n\t\t\\end{equation}\n%\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\twhere $K^{3}  \\ast_2$ is the average pooling with kernel size $2  \\times 2$ and stride 2, $K^{1}$, $K^{2} $, $K^{4} $ and $K^{5}  $ are multi-channel kernels with kernel size $3  \\times 3$ and the size of these kernel matrices are $(1 \\times f_d/2)$, $ (f_d/2 \\times f_d)$, $(1,f_d/2)$ and $(f_d/2, f_d)$ respectively.\n\t\nThe loss function is \n$$\nL = \\frac{1}{N} \\sum_{i=1}^{N} \\frac{\\| u_{pred} - u_{test}\\|_{L^2}^2}{\\| u_{test}\\|_{L^2}^2}\n$$\n\nFor this problem, we have a comparison for the results with and without nonlinear activation functon.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.65\\textwidth]{figures/Darcy_CNN/Darcy_CNN_2000.png}\n\t\\includegraphics[width=0.65\\textwidth]{figures/Darcy_CNN/Darcy_CNN_2000_nonlinear.png}\n\t\\caption{Comparison of the solutions obtained by CNN with and without activation function by SGD (Top: without activation, Bottom:  with activation, 8,2 million parameters).}\n\\end{figure}\n\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=0.65\\textwidth]{figures/Darcy_CNN/Darcy_CNN_Adam_2000.png}\n\t\\includegraphics[width=0.65\\textwidth]{figures/Darcy_CNN/Darcy_CNN_2000__Adam_nonlinear.png}\n\t\\caption{Comparison of the solutions obtained by CNN with and without activation function by Adam method (Top: without activation, Bottom:  with activation).}\n\\end{figure}\n\n\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/darcy_loss_2000_adam.png}\n\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/darcy_loss_2000_adam_nonlinear.png}\n\t\\caption{Training curves  with and without activation function by Adam method (Left: without activation, Right:  with activation).}\n\\end{figure}\n\n\t\\begin{figure}[!htbp]\n\t\\centering\n\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/darcy_loss_2000_SGD.png}\n\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/darcy_loss_2000_SGD_nonlinear.png}\n\t\\caption{Training curves  with and without activation function by SGD method (Left: without activation, Right:  with activation).}\n\\end{figure}\n\nBelow we consider the decoding process as the transpose of the encoding process.\n\\begin{breakablealgorithm}\n\t\\caption{$u={\\rm DarcyCNN_{transpose}}(\\kappa; f_d, coarse\\_grid\\_size,)$}\n\t\\label{alg:mgnet}\n\t\\begin{algorithmic}\n\t\t\\State Initialization:  $\\kappa$\n\t\t%\t\t\\State Initialization $u^{1,0}$\n\t\t%\t\t\\For{$ = 1:N_{epoch}$}\n\t\t%\t\t\\For{$i = 1:\\nu_$}\n\t\t\\State Encode\n\t\t\\begin{equation}\n\t\tu^{} = K^{3}  \\ast_2   K^{ 2}\\ast  (K^{ 1}\\ast \\kappa).\n\t\t\\end{equation}\n\t\t\n\t\t%\t\t\\EndFor\n\t\t\\State Restriction to the coarse grid\n\t\t\\begin{equation}\n\t\tu^{} =   W u^{}\n\t\t\\end{equation}\n\t\t\\State\n\t\tConvolution on the coarse grid\n\t\t\\begin{equation}\n\t\tu^{} =   K^{ 5}\\ast K^{ 4}\\ast u^{}.\n\t\t\\end{equation}\n\t\t\\State Decode\n\t\t\\begin{equation}\n\t\tu^{} =  K^{ 1,T} \\ast K^{ 2,T}\\ast K^{3}  \\ast_2^T (W^{ T}  K^{ 4,T}\\ast K^{ 5,T}\\ast u^{}).\n\t\t\\end{equation}\n\t\t%\t\t\\EndFor\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nWhere $K^T$ is the transpose of kernel $K$. For a kernel with size of $3 \\times 3$ without padding, its transpose is the central symmetry of itself with 2 paddings.\\\\\n\nIn this network, the parameters are 13 million and 6.5 million respectively.\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/Darcy_transpose_value_mean.png}\n\t\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/Darcy_transpose_novalue_mean.png}\n\t\t\\caption{Comparison of solutions obationed by FEM and neural network including transpose(Left: Transposed parameters untrained, Right: Transposed parameters trained) with zero-mean input.}\n\t\\end{figure}\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/Darcy_transpose_value.png}\n\t\t\\includegraphics[width=0.45\\textwidth]{figures/Darcy_CNN/Darcy_transpose_novalue.png}\n\t\t\\caption{Comparison of solutions obationed by FEM and neural network including transpose(Left:  Transposed parameters untrained, Right: Transposed parameters trained) with original input.}\n\t\\end{figure}\n\n\nThe problem we feel confused is that unlike the process in PCA method, what we need to do is to solve a darcy equation, where the input data and output data are in two different fields. Therefore, whether it makes sense that using the encode transpose-encode process to solve this problem.\n\n\\newpage\n\\subsection{PCA and POD}\nFor the differnence between PCA and POD, here we consider following linear problem\n$$\nA_i x_i = b_i, \\quad i = 1,\\cdots,N\n$$\nConsider the solutions $x_i $ are in a hyperplane $y_i = W\\tilde{x}_i+\\mu$ where $W \\in \\mathbb{R}^{d\\times d'}, d'\\ll d $ and $y_i$ is an approximation of $x_i$. To approximate $x_i$ as closely as possible, i.e. minimize loss function\n\\begin{equation}\\label{lossPOD}\nL = \\sum_{i}^{N}=\\| y_i - x_i\\|^2 =  \\sum_{i}^{N}=\\| W\\tilde{x}_i +\\mu - x_i\\|^2\n\\end{equation}\nThen, the best choice of $\\tilde{x}_i $ and $\\mu$ is\n$$\n\\mu = \\frac{1}{N}\\sum_{i}^{N}x_i = \\bar{x}, \\quad\n\\tilde{x}_i = W^T(x_i-\\bar{x})\n$$\nThen \\ref{lossPOD} can rewritten as\n$$\nL =  \\sum_{i}^{N}=\\| WW^T(x_i-\\bar{x}) +\\bar{x} - x_i\\|^2 .\n$$\nThe choice of $W$ is the same as PCA method.\\\\\n\nFor the linear problem $Ax=b$, we consider $x = W\\tilde{x}+\\bar{x}$ and premultiplicate $W^T$ on the eqauation, we get\n$$\nW^TAW\\tilde{x} = W^T(b-A\\bar{x}).\n$$\nSolve the equation above and with the decoder, we can get the approximation of the solution as\n$$\nx \\approx W\\tilde{x} + \\bar{x}.\n$$\nIn the POD, we consier the solution in the specific hyperplane $y_i = W\\tilde{x}_i$, then the low-dimension solution $\\tilde{x}$ satisfies\n$$\nW^TAW\\tilde{x} = W^Tb\n$$\nApply the decoded to get the approximation solution as\n$$\nx = W\\tilde{x}\n$$\nFor the construction of CNN to solve this problem, the matrix A is associated with $\\kappa$ and can be regarded as a linear mapping of $\\kappa$, and the right side term $b$ is fixed.\n\n%Here for a input $\\kappa$, I wonder the encoded is processed on $\\kappa$, or on a linear  mapping of $\\kappa$ which approximate the solution $x$. As we all know, the traditional encode-decode process is all about $x$. However, here we need to apply the encoder on $\\kappa$ and have some extra computation to solve the equation in a lower dimension. Finally we apply the decoder to get the approximation of the solution.\n\\subsection{Mgnet-encoder}\nIn order to make the distance between the approximate solution and true solution  as small as possible, i.e. minimize loss function\n$$\nL = \\sum_{i}^{N} \\| g  \\circ f(x_i) - x_i \\|\n$$\nIf we fix the decoder as a linear function, i.e.\n$$\ng(y) = Wy + b\n$$\nHdre, we use the following MgNet as the encoder\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$\\mu^J = {\\text{MgNet}}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash11d}\n\t\\begin{algorithmic}\n\t\t\\State Set up\n\t\t$$\n\t\tf^1 = {\\color{red} \\theta\\ast} f, \\quad \\mu^{1}=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\t\\mu^{\\ell} \\leftarrow \\mu^{\\ell} + S^\\ell \\ast (f^\\ell - A_\\ell \\ast \\mu^{\\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\t\\mu^{\\ell+1} \\leftarrow \\Pi_{\\ell}^{\\ell+1}\\mu^\\ell , \\quad\n\t\tf^{\\ell+1} \\leftarrow R^\\ell \\ast_2 (f^\\ell -  A_\\ell \\ast\n\t\t\\mu^{\\ell}) + A_{\\ell+1}\\ast \t\\mu^{\\ell+1} ,    %A_{\\ell+1} = R       \\ast_2 A_\\ell \\ast (R\\ast_2^\\top).\n\t\t$$\n\t\t\\EndFor\n\t\t\\State\n\t\tFinally, we ultilize the Adaptive average pooling to let the number of element in every channel of $\\nu^J$ be 1.\n\t\t$$\\nu^J = Avg \\ast \\nu^J$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nHere, $\\mu_J$ is the reduced vector. For the decoder, we denote $(u^l,f^l)$ as a new variable.\nThen we can induce that\n$$\\mu^{l+1}=\\phi^{l+1}\\mu^l + \\xi^{l+1}f^{l+1}$$\n$$f^{l+1} = R^l f^l + M^l \\mu^l $$\nwhere $\\phi^{l+1}= (N^{l+1})^{v_{l+1}}\\Pi_l^{l+1}, N^{l+1}= I - S^{l+1}A^{l+1} $, $\\xi^{l+1}=\\big(\\sum_{i=1}^{v_{l+1}-1}(N^{l+1})^i\\big)S^{l+1}$ and $M^l = A^{l+1}\\Pi_l^{l+1} - R^lA^l$.\n\nWe can also rewritten the equation above as\n\\[\n\\left( \\begin{array}{l}\nf^{l+1} \\\\\n\\mu^{l+1}\n\\end{array} \\right) = \\left( {\\begin{array}{*{20}{c}}\n\tR^l & M^l\\\\\n\t\\xi^{l+1}R^l&\\phi^{l+1}+\\xi^{l+1}M^l\n\t\\end{array}} \\right)\\left( \\begin{array}{l}\nf^{l}\\\\\n\\mu^{l}\n\\end{array} \\right), \\quad\n\\left( \\begin{array}{l}\nf^{1} \\\\\n\\mu^{1}\n\\end{array} \\right) = \\left( {\\begin{array}{{c}}\n\t\\theta \\\\\n\t\\xi^{1}\\theta\n\t\\end{array}} \\right)\\left( \\begin{array}{l}\nf\\\\\n\\end{array} \\right)\n\\]\nWe can then define the mgnet-decoder as\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$f = {{\\rm MgNet_{transpose}}}(u^J; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\begin{algorithmic}\n\t\t\\State Transpose of Adapative Average pooling\n\t\t$$\\mu^J = Avg^T \\ast \\nu^J $$\n\t\t\\State Prolongation back to the fine level \n\t\t\\State \n\t\t$$\n\t\tf^{J-1} = R^{J-1, T}\\xi^{J, T}\\mu^J,  \\qquad \\mu^{J-1} = (M^{J-1,T}\\xi^{J, T} + \\phi^{J-1, T})\\mu^{J}\n\t\t$$\n\t\t\\For{$\\ell = J-2:1$}\n\t\t\\State\n\t\t\\begin{equation}\n\t\t\\mu^{\\ell}= M^{\\ell,T}f^{\\ell+1} + (M^{\\ell,T}\\xi^{\\ell+1, T} + \\phi^{\\ell, T})\\mu^{\\ell+1}.\n\t\t\\end{equation}\n\t\t\\State\n\t\t\\begin{equation}\n\t\tf^{\\ell} = R^{\\ell, T}f^{\\ell+1} + R^{\\ell, T}\\xi^{\\ell+1, T}\\mu^{\\ell+1}\n\t\t\\end{equation}\n\t\t\\EndFor\n\t\t\\State Transpose of pre-convolution:\n\t\t$$\n\t\tf = \\theta^T \\ast f^1 + \\theta^T \\ast \\xi^{1,T} \\mu^1\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\subsection{Numerical results}\nThen we have the some results for the following test.\n\n\\begin{itemize}\n\t\\item Model equations\n\t\\begin{align*}\n\t- \\nabla \\cdot (\\kappa \\nabla p) & = 0  \\qquad \\text{in}~~ \\Omega \\\\\n\t\\kappa \\nabla p \\cdot n &= 0 \\qquad \\text{on} ~~ \\Gamma_\\text{N} \\\\\n\tp  &= 0 \\qquad \\text{on} ~~\\Gamma_{\\text{D}1} \\\\\n\tp  &= 1 \\qquad \\text{on}~~ \\Gamma_{\\text{D}2} \\\\\n\t\\end{align*}\n\t\\begin{center}\n\t\t\\vskip -20pt\n\t\t\\includegraphics[height=5cm]{figures/Darcy_CNN/Darcy_domain.png}\n\t\\end{center}\n\\end{itemize}\nThe loss fucntion is\n$$\nL = \\sum_{i}^{N} \\| g  \\circ f(x_i) - x_i \\|\n$$\nwhere $x_i$ is the FEM solution given the permeability $\\kappa_i$, $f$ is the Mgnet encoder and $g$ is the Mgnet-Transpose decoder.\n\n\\begin{itemize}\n\t\\item Uniformly generate 2000 training samples: $\\kappa_1 \\sim \\mathcal{U}(2.5,7,5), \\kappa_2 \\sim \\mathcal{U}(1,3)$ and $\\kappa_3 \\sim \\mathcal{U}(0.5,1.5)$\n\t\\item Grid size: $33*33 ~ (d=1089)$\n\t\\item Number of training samples: 2000\n\t\\item Number of epochs: 2000\n\t\\item Number of test samples: 500\n\t\\item Mgnet learning rate: $10^{-3}$\n\t\\item DNN learning rate: 0.1\n\\end{itemize}\nHere, we give the results of DNN and MgNet:\n\n\\subsubsection{Case 1: Fix J, change $\\nu_i$}\nLet $J=4,$, number of $\\mu$'s channel equals to 10, number of $f$'s channel equals to 1, we test the cases when $\\nu_i=1,2,3,4$.\n\\begin{table}\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& $\\nu_i$=1 & $\\nu_i$=2 & $\\nu_i$=3& $\\nu_i$=4 \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 1.1861 $\\times 10^{-2}$ & 1.197 $\\times 10^{-2}$& 1.0793 $\\times 10^{-2}$ & 1.0795 $\\times 10^{-2}$\\\\\n\t\t\t\\hline\n\t\t\tMean rel. errors & 6.358 $\\times 10^{-3}$ &6.199 $\\times 10^{-3}$ &5.947 $\\times 10^{-3}$ &6.010 $\\times 10^{-3}$ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors and test errors(3456 parameters).}\n\t\\end{center}\n\\end{table}\n\n\\subsubsection{Case 2: Fix $\\nu_i$, change J}\nLet $\\nu_i$=2, number of $\\mu$'s channel equals to 10, number of $f$'s channel equals to 1, we test the cases when $J=3,4,5,6$\n.\\begin{table}\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& $J=3$ & $J=4$ & $J=5$& $J=6$ \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 1.3235 $\\times 10^{-2}$ & 1.1197 $\\times 10^{-2}$& 1.0760 $\\times 10^{-2}$ & 1.0663 $\\times 10^{-2}$\\\\\n\t\t\t\\hline\n\t\t\tMean rel. errors & 6.613 $\\times 10^{-3}$ &6.199 $\\times 10^{-3}$ &6.022 $\\times 10^{-3}$ &5.956 $\\times 10^{-3}$ \\\\\n\t\t\t\\hline\n\t\t\tNumber of Para & 2367& 3456& 4545 & 5634\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors and test errors for various J.}\n\t\\end{center}\n\\end{table}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{figures/Darcy_CNN/loss_J.png}\n\t\\caption{Training curves for various J=3,4,5,6.}\n\\end{figure}\n\\subsubsection{Case 3: Change number of $u$'s channel}\nLet $\\nu_i$=2, number of $f$'s channel equals to 1, $J=4$, we test the cases when the number of $\\mu$'s channel equals to $10,20,30,40$\n.\\begin{table}\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& $n_u=10$ & $n_u=20$ & $n_u=30$& $n_u=40$ \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 1.1197 $\\times 10^{-2}$ & 1.0772 $\\times 10^{-2}$& 0.9634 $\\times 10^{-2}$ & 0.8550 $\\times 10^{-2}$\\\\\n\t\t\t\\hline\n\t\t\tMean rel. errors & 6.199$\\times 10^{-3}$ & 6.091 $\\times 10^{-3}$ &5.796 $\\times 10^{-3}$ &5.574$\\times 10^{-3}$ \\\\\n\t\t\t\\hline\n\t\t\tNumber of Para & 3456& 12276& 26496 & 71136\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors and test errors for various number of $u$'s channel.}\n\t\\end{center}\n\\end{table}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{figures/Darcy_CNN/loss_u_channel.png}\n\t\\caption{Training curves for various number of $u$'s channel.}\n\\end{figure}\n\n\\subsubsection{Case 4: DNN results}\nFor the one-layer DNN, we test the cases when the number of reduced dimension is $10, 20, 30 ,40$.\n.\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& 10 & 20 & 30& 40 \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 1.0584 $\\times 10^{-2}$ & 0.8902 $\\times 10^{-2}$& 0.7296$\\times 10^{-2}$ & 0.6819 $\\times 10^{-2}$\\\\\n\t\t\t\\hline\n\t\t\tMean rel. errors & 6.110$\\times 10^{-3}$ & 5.852 $\\times 10^{-3}$ &5.571$\\times 10^{-3}$ &5.470$\\times 10^{-3}$ \\\\\n\t\t\t\\hline\n\t\t\tNumber of Para & 10890& 21780& 32670 & 54450\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors and test errors for various reduced dimension.}\n\t\\end{center}\n\\end{table}\n\\textbf{In this test, we noticed that the weight obtained by DNN almost satisfies the orthogonality, and the weight obtained by MgNet also has the trendency to satisfy the orthogonality where the elements on the diagnol close to 1 and the non-diagol elements close to 0.}\n\n\\subsubsection{Case 5: POD results}\nFor the POD method, we test the cases when the number of reduced basis is $10, 20, 30 ,40$\n.\\begin{table}\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& 10 & 20 & 30& 40 \\\\\n\t\t\t\\hline\n\t\t\tMean rel. errors & 6.345$\\times 10^{-3}$ & 6.111 $\\times 10^{-3}$ &5.918$\\times 10^{-3}$ &5.788$\\times 10^{-3}$ \\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Test results for various reduced basis number.}\n\t\\end{center}\n\\end{table}\n\nHowever, there exists a problem for this numerical test because the variance of every entry  of the solution is actually verly small ($10^-5$). From the results above, we can only infer that CNN can use less paramters to obtain the weight than DNN does. To illustrate this conclusion, we consider further numerical tests.\n\n\\subsection{Extend tests}\nHere we let the source term of the equation be 1, i.e., \n\\begin{itemize}\n\t\\item Model equations\n\t\\begin{align*}\n\t\t- \\nabla \\cdot (\\kappa \\nabla p) & = 1  \\qquad \\text{in}~~ \\Omega \\\\\n\t\t\\kappa \\nabla p \\cdot n &= 0 \\qquad \\text{on} ~~ \\Gamma_\\text{N} \\\\\n\t\tp  &= 0 \\qquad \\text{on} ~~\\Gamma_{\\text{D}1} \\\\\n\t\tp  &= 1 \\qquad \\text{on}~~ \\Gamma_{\\text{D}2} \\\\\n\t\\end{align*}\n\t\\begin{center}\n\t\t\\vskip -20pt\n\t\t\\includegraphics[height=5cm]{figures/Darcy_CNN/Darcy_domain.png}\n\t\\end{center}\n\\end{itemize}\n\nThen the variance of every entry is about 0.11, which is lager than the previous case. Fix the number of $u$'s channel as 1, we have the following results.\n\n\\subsubsection{Case 1: Change $\\nu_i$}\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t$\\nu_i$& 1& 2 & 3& 4 \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 53.4168 & 55.3550 & 53.3935 & 53.8467\\\\\n\t\t\t\\hline\n\t\t\t%\t\t\tMean rel. errors & 6.110$\\times 10^{-3}$ & 5.852 $\\times 10^{-3}$ &5.571$\\times 10^{-3}$ &5.470$\\times 10^{-3}$ \\\\\n\t\t\t%\t\t\t\\hline\n\t\t\tNumber of Para & 135 & 135 & 135 & 135\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors for various reduced dimension(lr = $10^{-2}$).}\n\t\\end{center}\n\\end{table}\n\\subsubsection{Case 2: Change $J$}\n\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\tJ& 3& 4 & 5& 6 \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 44.7566 & 55.3550 & 66.2886& 78.9738\\\\\n\t\t\t\\hline\n\t\t\t%\t\t\tMean rel. errors & 6.110$\\times 10^{-3}$ & 5.852 $\\times 10^{-3}$ &5.571$\\times 10^{-3}$ &5.470$\\times 10^{-3}$ \\\\\n\t\t\t%\t\t\t\\hline\n\t\t\tNumber of Para & 99 & 135 & 171 & 207\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors for various reduced dimension(lr = $10^{-2}$).}\n\t\\end{center}\n\\end{table}\n\\subsubsection{Case 3: DNN results}\n.\\begin{table}[H]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|c|c|}\n\t\t\t\\hline\n\t\t\t& 10 & 20 & 30& 40 \\\\\n\t\t\t\\hline\n\t\t\tTrain loss & 60.4035  & 50.5609 & 45.3879 & 42.3671 \\\\\n\t\t\t\\hline\n%\t\t\tMean rel. errors & 6.110$\\times 10^{-3}$ & 5.852 $\\times 10^{-3}$ &5.571$\\times 10^{-3}$ &5.470$\\times 10^{-3}$ \\\\\n%\t\t\t\\hline\n\t\t\tNumber of Para & 10890& 21780& 32670 & 54450\\\\\n\t\t\t\\hline\n\t\t\\end{tabular}\\caption{Training errors for various reduced dimension(lr = $10^{-5}$).}\n\t\\end{center}\n\\end{table}\n\\subsection{Some disscusion about the orthogonality}\nReview that the loss function is \n$$\nL = \\Sigma_{i=1}^N \\| WW^Tx_i  -x_i \\| ^2\n$$\nwhere $W\\in \\mathbb{R}^{d\\times k}, k \\ll d$. Here the matrix $A=WW^T$ is a symmetric positive semi-definite matrix, which have the following decomposition\n$$\nQ^TAQ  = \\Lambda\n$$\nwhere Q is a orthogonal matrix and $\\Lambda = diag(x_k, 0)$ is a diagnoal matrix, $x_k$ ia a strictly positive  $k$ element vector.\n\nThen the loss function can be written as\n$$\n\\begin{aligned}\nL&= \\sum x_i^TA^TAx_i - 2x_i^TAx_i +x_i^Tx_i^T\\\\\n&= \\sum x_i^TQ \\Lambda^2 Q^Tx_i - 2x_i^TQ\\Lambda Q^Tx_i\n\\end{aligned}\n$$\nTo minimize the loss function, for each element of $x_k=(\\lambda_i)$, we need to minimize the following problem for each $\\lambda_i, i = 1,\\cdots, k$\n$$\nM \\lambda_i^2 - 2M \\lambda_i\n$$\nwhere $M=M(Q,x_i)$ is  positive and depends on $x_i$ and Q. Therefore, $\\lambda_i$ should be 1 for the purpose.\n\nThen the original problem is equivalent to maximize the following problem\n$$\n\\begin{aligned}\nL & = \\sum_{i=1}^{N}x_i^TQ \\Lambda Q^T x_i\\\\\n& = \\sum_{i=1}^N \\sum_{j=1}^k x_i q_j q_j^T x_i\\\\\n& = \\sum_{j=1}^k q_j^TXX^T q_j\n\\end{aligned}\n$$\nwhere $X = (x_1,\\cdots,x_N)$, $\\{q_j\\}, j=1,\\cdots k$ is the first $k$ columns of orthogonal matrix $Q$.\n\nThen the problem is equivalent to the PCA method which requires the orthogonality, i.e., the orthogonality is a necessary condition to unique the minimizer.\n\nOn the other hand, if we consider $A = WW^T$. From above we know that the eigenvalues of $A$ is 1 and 0, and $A$ has a decomposition as $A = WW^T$ where $W$ is not unique.\n\nWithout the constaint of orthogonality, this weight $W$ is not unique. Therefore, CNN can generate one of the weight matrix $W_{CNN}$, if this weight matrix is orthogonal, then CNN has no difference from POD method. If not, CNN may be better than POD method.\n\n\\subsection{Othogonality is necessary and sufficient}\nIn the following part, I will prove that the weight matrix must satisfy the orthogonality.\n\nFirstly, for the matrix $A = WW^T$ where $A\\in \\mathbb{R}^{n\\times n}, W \\in \\mathbb{R}^{n\\times r}, r\\ll n$. There exists an orthogonal matrix $Q$ and a diagnoal matrix $\\Lambda$ such that\n$$\nA = Q^T \\Lambda Q\n$$\nThen we have $\\Lambda = QWW^TQ^T$. Consider the decomposition of $\\Lambda$, since the eigenvalues of $A$ is 1 and 0, $\\Lambda$ can be written as $diag(e_r, 0)$ where $e_r$ is a r-dim vector of all ones. We have\n$$\n\\Lambda= \\left( \\begin{array}{c}\n\tA_r \\\\\n\tA_{n-r}\n\t\\end{array}\\right) (A_r^T \\ A_{n-r}^T) = \\left(\\begin{array}{c c}\n\tA_rA_r^T & A_rA_{n-r}^T \\\\\n\tA_{n-r}A_r^T & A_{n-r}A_{n-r}^T\n\\end{array}\\right)\n= \\left(\\begin{array}{c c}\n\tI_r & 0 \\\\\n\t0 & 0\n\\end{array}\\right)\n$$\nSince $ A_{n-r}A_{n-r}^T$ is a zero matrix, we can induce that $A_{n-r}$ is a zero matrix and $A_r$ is an orthogonal matrix due to $A_rA_r^T= I_r$. Using these results leads to\n$$\n\\left( \\begin{array}{c}\n\tQ_r \\\\\n\t0\n\\end{array}\\right) = QW\n$$\ni.e.,\n$$\nW = Q^T\\left( \\begin{array}{c}\n\tQ_r \\\\\n\t0\n\\end{array}\\right) \n$$\nwhere $Q_r$ is an arbitary orthogonal matrix. Then we have\n$$\nW^TW = (Q_r^T \\ 0) QQ^T \\left(\\begin{aligned}\n\tQ_r \\\\\n\t0\n\\end{aligned}\\right) = (Q_r^T \\ 0) \\left(\\begin{aligned}\nQ_r \\\\\n0\n\\end{aligned}\\right) = I_r\n$$\nTherefore, orthogonality is a sufficient and necessary conditon for the weight matrix. For any two weight matrices $W_1$ and $W_2$, there exists a unique orthgonal matrix $Q_r$ such that $W_1 = W_2Q_r$.", "meta": {"hexsha": "4d0c721765cf898708168444e02a5b1cbee66a88", "size": 21213, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/jindong.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/jindong.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/jindong.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.5027932961, "max_line_length": 420, "alphanum_fraction": 0.6597369538, "num_tokens": 8116, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582593509315, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.760718930212593}}
{"text": "\\section{The effect of pixelization on point-source models}\n\nSince \\climax\\ constructs its models in the image plane, point source\nmodels are necessarily pixelized with a resolution of $dx$.  Here we\nconsider the effect this has on the minimum \\math{\\chisq}\\ achievable in\n\\climax.\n\nConsider a source at a true location $x$.  In general, the best-fit\npixelized model will be for a source located at $x + \\delx$, where\n$\\delx < \\mdx/2$, with Fourier transform \n\n\\begin{equation}\nV_j = Se^{-2\\pi i u_j\\delx} = S(\\cos{2\\pi u_j\\delx} - \\sin{2\\pi u_j\\delx})\n\\end{equation}\n\nThe best-fit \\math{\\chisq}\\ will then be:\n\n\\begin{eqnarray}\\nonumber\n  \\chisq = {1\\over{2N}}\\{&\\sum_j&{(R_j - S\\cos{2\\pi u_j(x + \\delx)})^2/\\sigma_j^2} + \\\\\\nonumber\n                         &\\sum_j&{(I_j + S\\sin{2\\pi u_j(x + \\delx)})^2/\\sigma_j^2}\\} \n\\end{eqnarray}\n\nNow $R_j = N^R_j + S\\cos{2\\pi u_j x}$ and $I_j = N^I_j - S\\sin{2\\pi u_j x}$ so that:\n\n\\begin{eqnarray}\\nonumber\n  \\chisq = {1\\over{2N\\sigma^2}}\\{&\\sum_j&{(N^R_j + S\\cos{2\\pi u_j x} - S\\cos{2\\pi u_j(x + \\delx)})^2} + \\\\\\nonumber\n                                 &\\sum_j&{(N^I_j - S\\sin{2\\pi u_j x} + S\\sin{2\\pi u_j(x + \\delx)})^2}\\} \n\\end{eqnarray}\n\nif we take the weights to be equal $\\sigma_j \\equiv \\sigma$.  Ignoring\ncross terms with $N^R_j$ and $N^I_j$, which will average to zero, and\nwriting $\\cos(x + \\delx) = \\cos{x}\\cos{\\delx} - \\sin{x}\\sin{\\delx}$ and \n$\\sin(x + \\delx) = \\sin{x}\\cos{\\delx} + \\cos{x}\\sin{\\delx}$, we have:\n\n\\begin{eqnarray}\\nonumber\n  \\chisq = 1 + {S^2\\over{2N\\sigma^2}}\\{&\\sum_j&{( cx - cx\\,c\\delx + sx\\,s\\delx})^2 + \\\\\\nonumber\n                                     &\\sum_j&{(-sx + sx\\,c\\delx + cx\\,s\\delx)^2}\n\\end{eqnarray}\n\nor \n\n\\begin{eqnarray}\\nonumber\n  \\chisq = 1 + {\\snr^2\\over{2N}}\\{&\\sum_j&{( cx^2 - 2cx^2\\,c\\delx + 2cx\\,sx\\,s\\delx + cx^2\\,c\\delx^2 - 2cx\\,sx\\,c\\delx\\,s\\delx  + sx^2\\,s\\delx^2}) + \\\\\\nonumber\n                                  &\\sum_j&{(sx^2 - 2sx^2\\,c\\delx - 2sx\\,cx\\,s\\delx + sx^2\\,c\\delx^2 + 2cx\\,sx\\,c\\delx\\,s\\delx + cx^2\\,s\\delx^2)}\n\\end{eqnarray}\n\nor \n\n\\begin{equation}\n  \\chisq = 1 + {\\snr^2\\over{N}}\\sum_j{(1 - \\cos{2\\pi u_j\\delx})}.\n\\end{equation}\n\nClearly, if $\\delx\\sim 0$, the sum converges to 1.  In general though, we have in the continuous limit:\n\n\\begin{eqnarray}\\nonumber\n  \\sum_j{(\\cos{2\\pi u_j\\delx})} &\\sim& {1\\over{\\Delta u^\\prime}}\\int^{u^\\prime_{max}}_{u^\\prime_{min}}{\\cos{u^\\prime}du^\\prime} \\\\\\nonumber\n  &=& {1\\over{\\Delta u^\\prime}}\\{\\sin{u^\\prime_{max}} - \\sin{u^\\prime_{min}}\\} \\\\\\nonumber\n  &=& {1\\over{2\\pi\\Delta u\\delx}}\\{\\sin{2\\pi\\delx u_{max}} - \\sin{2\\pi\\delx u_{min}}\\}.\n\\end{eqnarray}\n\nIn the worst-case scenario, \n\n\\begin{eqnarray}\\nonumber\n\\delx \\sim {{\\Delta x}\\over{2}} = {1\\over{4u_{max}}}\\\\\\nonumber\n\\Delta u = {1\\over{N\\Delta x}} = {{2u_{max}}\\over{N}}\n\\end{eqnarray}\n\nand we have\n\n\\begin{eqnarray}\\nonumber\n  {1\\over{2\\pi\\Delta u\\delx}}\\{\\sin{2\\pi\\delx u_{max}} - \\sin{2\\pi\\delx u_{min}}\\}\n  &=&  {N\\over{\\pi}}\\{1 - \\sin{{\\pi\\over{2}}{r}}\\}\n\\end{eqnarray}\n\nwhere $r = u_{min}/u_{max}$, and \n\n\\begin{eqnarray}\\nonumber\n  \\chisq &=& 1 + {\\snr^2\\over{N}}\\{N - {N\\over{\\pi}}\\{1 - \\sin{{\\pi\\over{2}}{r}}\\}\\} \\\\\\nonumber\n         &=& 1 + \\snr^2\\{1 - {1\\over{\\pi}}\\{1 - \\sin{{\\pi\\over{2}}{r}}\\}\\},\n\\end{eqnarray}\n\nwhich ranges between $\\chisq = 1 + \\snr^2$ and $\\chisq \\simeq 1 + {2\\over{3}}\\snr^2$, depending on the dynamic range $r$ of the data.\n\nLet's take a typical SZA observation: say we have a 6 hour track,\nsplit into 40-second integrations, for $n_{vis} = 28 \\times 6 \\times\n3600/40 \\sim 15000$ band-averaged visibilities per frequency channel.\nIf the visibility data are binned into a $128\\times128 = 16384$ cell\narray, then we have on order one visibility per uv cell.  If the map\nnoise is $0.2$~mJy/beam, then the noise on each cell is of order\n$\\sigma \\sim 0.2 \\sqrt{16384} = 26~$mJy.  This means that for a\n$1$~mJy source, the contribution to $\\chisq$ will be $(1/26)^2 \\sim 1.5e-3$.\n\n", "meta": {"hexsha": "1a02a73ee63874f0eb45c9f90c589eeacd8460a2", "size": 3928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/pixelization.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/pixelization.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/pixelization.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": 42.2365591398, "max_line_length": 160, "alphanum_fraction": 0.6069246436, "num_tokens": 1682, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9304582554941719, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.760718922923601}}
{"text": "\\documentclass[a4paper,10pt]{article}\n\\usepackage[utf8]{inputenc}\n\n\\begin{document}\n\n\\section{singular 1/r}\nWe want to compute by quadrature:\n\\begin{equation}\n  \\int_a^b f(r) \\,\\mathrm{d}r \\quad \\mathrm{with} \\quad f(r) = \\frac{1}{r} \\quad .\n\\end{equation}\nFor $a=10^{-3}$ and $b=1.0$, the analytical result is $\\mathrm{log}(b)-\\mathrm{log}(a) \\approx 6.91$.\nStandard trapezoidal quadrature on 100 points leads to\n\\begin{equation}\n  \\sum_{i=0}^{99} \\frac{1/x_i + 1/x_{i+q}}{2} \\Delta x \\approx 10.1\n\\end{equation}\nwhere\n\\begin{equation}\n  x_i = a+\\frac{i}{100-1}\\Delta x ~ \\mathrm{and} ~ \\Delta x = \\frac{b-a}{100-1} \\quad .\n\\end{equation}\n\n\nThis specific quadrature can be made much more accurate by a substitution that leads to \n\\begin{equation}\n  \\int_{s(a)}^{s(b)} \\frac{1}{r} r\\,\\mathrm{d}s = \\left[ s \\right]_{s(a)}^{s(b)} \\quad ,\n\\end{equation}\nfor which we need\n\\begin{equation}\n  \\mathrm{d}r = r \\, \\mathrm{d}s \\quad .\n\\end{equation}\nRephrase:\n\\begin{equation}\n  \\frac{\\mathrm{d}r}{r} = \\mathrm{d}s \\Leftrightarrow \\int \\frac{\\mathrm{d}r}{r} = \\int \\mathrm{d}s \\Leftrightarrow\n  \\mathrm{log}(r) = s \\quad .\n\\end{equation}\nThe quadrature for the substituded integral is then:\n\\begin{equation}\n  \\sum_{i=0}^{99} ...\n\\end{equation}\n\n\n\\section{nearly-singular 1/(r+eps)}\nWe want to compute:\n\\begin{equation}\n  \\int_a^b f(r) \\,\\mathrm{d}r ~ \\mathrm{where} ~ f(r) \\propto \\frac{1}{\\sqrt{r^2 + \\epsilon^2}} \\quad .\n\\end{equation}\nIf we take $f$ to be the pure kernel function, an analytical solution to this can be found:\n\\begin{equation}\n  \\int_a^b \\frac{1}{\\sqrt{r^2 + \\epsilon^2}} \\,\\mathrm{d}r = \\mathrm{log}\\left( b + \\sqrt{b^2 + \\epsilon^2} \\right) - \\mathrm{log}\\left( a + \\sqrt{a^2 + \\epsilon^2} \\right) \\quad .\n\\end{equation}\nAgain do the substitution trick:\n\\begin{equation}\n  \\int_a^b f(r) \\,\\mathrm{d}r = \\int_{s(a)}^{s(b)} f(r) \\left(\\sqrt{r^2 + \\epsilon^2}\\right) \\,\\mathrm{d}s \\quad ,\n\\end{equation}\nwhere we used\n\\begin{equation}\n  \\mathrm{d}r = \\left(\\sqrt{r^2 + \\epsilon^2}\\right) \\,\\mathrm{d}s \\quad .\n\\end{equation}\nThe substitution is therefore\n\\begin{equation}\n  s = \\mathrm{log}\\left(r + \\sqrt{r^2 + \\epsilon^2}\\right) \\quad .\n\\end{equation}\n\n\n\n\\end{document}\n", "meta": {"hexsha": "ee2e0765abd29741a6a5faf8cf76512ea70215fe", "size": 2185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "nsq.tex", "max_stars_repo_name": "jonathanschilling/nsq", "max_stars_repo_head_hexsha": "f860b2455d3fde339eaab96fa65922b18ac929cd", "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": "nsq.tex", "max_issues_repo_name": "jonathanschilling/nsq", "max_issues_repo_head_hexsha": "f860b2455d3fde339eaab96fa65922b18ac929cd", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "nsq.tex", "max_forks_repo_name": "jonathanschilling/nsq", "max_forks_repo_head_hexsha": "f860b2455d3fde339eaab96fa65922b18ac929cd", "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.1060606061, "max_line_length": 180, "alphanum_fraction": 0.6562929062, "num_tokens": 844, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.822189123986562, "lm_q1q2_score": 0.7607140062125126}}
{"text": "\n\\subsection{General linear groups \\(GL(n, F)\\)}\n\nThe general linear group, \\(GL(n, F)\\), contains all \\(n\\odot n\\) invertible matrices \\(M\\) over field \\(F\\).\n\nThe binary operation is multiplication.\n\n", "meta": {"hexsha": "c45fefaa87ac92400308ffaf165b3cee516bc15b", "size": 202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/endomorphisms/04-01-GL.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/endomorphisms/04-01-GL.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/endomorphisms/04-01-GL.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.25, "max_line_length": 109, "alphanum_fraction": 0.6831683168, "num_tokens": 53, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768541530197, "lm_q2_score": 0.8056321936479701, "lm_q1q2_score": 0.7606592702029368}}
{"text": "\\section{Intermediate Value Theorem}\r\n\\begin{theorem}[Intermediate Value Theorem (IVT)]\r\n\tIf $f$ is continuous on the closed interval $[a,b]$, then for all $c \\in [f(a), f(b)]$, there exists $x \\in [a,b]$ such that $f(x) = c$.\r\n\\end{theorem}\r\n\r\nThat is, if $f$ is continuous on $[a,b]$, then $f$ must take on every value between $f(a)$ and $f(b)$.\r\nThis encapsulates the idea that if a function is continuous on some interval, then it is \"connected\" on that interval.\r\n\r\n\\begin{example}\r\n\tUse the IVT to show that $e^{-x} = x$ has at least one solution.\r\n\\end{example}\r\n\\begin{answer}\r\n\tLet $f(x) = e^{-x} - x$.\r\n\tWe are looking for $x$ where $f(x) = 0$.\r\n\t$f(0) = 1$ and $f(1) = \\frac{1}{e} - 1$.\r\n\tSince $f$ is continuous on the closed interval $[0,1]$, it must take on every value between $1$ and $\\frac{1}{e} - 1$.\r\n\tSince $1$ is positive and $\\frac{1}{e} - 1$ is negative, 0 is between these two values.\r\n\tThus, by the IVT, there must exist a solution between $x=0$ and $x=1$.\r\n\\end{answer}", "meta": {"hexsha": "c499c5b0a1da7ef7f80920b76727f7905b7a984b", "size": 995, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/limits_continuity/intermediate_value_theorem.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/limits_continuity/intermediate_value_theorem.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/limits_continuity/intermediate_value_theorem.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": 52.3684210526, "max_line_length": 138, "alphanum_fraction": 0.6422110553, "num_tokens": 337, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7606452412408068}}
{"text": "% based on\n% https://github.com/sympy/sympy/wiki/Quick-examples\n\n\\documentclass[12pt]{pylatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Visible Python code}\n\nThis is the first of two-part example. In this first part the Python code and tags are made visible using {\\tt\\small\\verb|\\PySetup{action=show}|} (this is the default). In the second part the Python code will be hidden using {\\tt\\small\\verb|\\PySetup{action=hide}|}. In both cases the Python output is identical (apart from the different tag names).\n\n\\vspace{12pt}\n\n\\PySetup{action=show}\n\n\\begin{python}\n   from sympy import *\n\n   x, y = symbols('x y')\n\n   ans = limit((sin(x)-x)/x**3, x, 0)               # py(ans.101,ans)\n   ans = (1/cos(x)).series(x, 0, 6)                 # py(ans.102,ans)\n   ans = diff(cos(x**2)**2 / (1+x), x)              # py(ans.103,ans)\n   ans = integrate(x**2 * cos(x), x)                # py(ans.104,ans)\n   ans = integrate(x**2 * cos(x), (x, 0, pi/2))     # py(ans.105,ans)\n\n   f = Function('f')\n\n   eqn = Eq(Derivative(f(x),x,x) + 9*f(x), 1)       # py(ans.106,eqn)\n   sol = dsolve(eqn, f(x))                          # py(ans.107,sol)\n\n   eqn = Eq(f(x).diff(x, x) + 9*f(x), 1)            # py(ans.108,eqn)\n   sol = dsolve(eqn, f(x))                          # py(ans.109,sol)\n\n   my_int = Integral(cos(x),(x,0,2))                # py(ans.110,my_int)\n   my_ans = my_int.doit()                           # py(ans.111,my_ans)\n\\end{python}\n\n\\clearpage\n\n\\section*{Visible Python code output}\n\nHere is the output from the above Python code. This line of text is here for no other reason than to fill out the line so that we have two lines of text before the Python output. This makes it easier to compare the vertical spacing between this and the next example.\n% ----------------------------------------------------------------------------------\n% Note\n% ----------------------------------------------------------------------------------\n% For perfect alignment of the py(ans.101) and py(ans.201) tags in the pdf file, the\n% following \\begin{align*} and \\begin{python} environments must be in vertical mode.\n% The easiest way to ensure this is to precede each environment by a blank line.\n% ----------------------------------------------------------------------------------\n\n\\vspace{-10pt}\n\n\\begin{align*}\n   &\\py*{ans.101}\\\\\n   &\\py*{ans.102}\\\\\n   &\\py*{ans.103}\\\\\n   &\\py*{ans.104}\\\\\n   &\\py*{ans.105}\\\\\n   &\\py*{ans.106}\\\\\n   &\\py*{ans.107}\\\\\n   &\\py*{ans.108}\\\\\n   &\\py*{ans.109}\\\\\n   &\\py*{ans.110}\\\\\n   &\\py*{ans.111}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Hidden Python code and output}\n\n\\PySetup{action=hide}\n\nIn this example the Python code is hidden and consumes no vertical space on the page. Compare the gap between this pair of lines and the following output text against that seen on the previous page.\n\n\\begin{python}\n   from sympy import *\n\n   x, y = symbols('x y')\n\n   ans = limit((sin(x)-x)/x**3, x, 0)               # py(ans.201,ans)\n   ans = (1/cos(x)).series(x, 0, 6)                 # py(ans.202,ans)\n   ans = diff(cos(x**2)**2 / (1+x), x)              # py(ans.203,ans)\n   ans = integrate(x**2 * cos(x), x)                # py(ans.204,ans)\n   ans = integrate(x**2 * cos(x), (x, 0, pi/2))     # py(ans.205,ans)\n\n   f = Function('f')\n\n   eqn = Eq(Derivative(f(x),x,x) + 9*f(x), 1)       # py(ans.206,eqn)\n   sol = dsolve(eqn, f(x))                          # py(ans.207,sol)\n\n   eqn = Eq(f(x).diff(x, x) + 9*f(x), 1)            # py(ans.208,eqn)\n   sol = dsolve(eqn, f(x))                          # py(ans.209,sol)\n\n   my_int = Integral(cos(x),(x,0,2))                # py(ans.210,my_int)\n   my_ans = my_int.doit()                           # py(ans.211,my_ans)\n\\end{python}\n\n\\vspace{-10pt}\n\n\\begin{align*}\n   &\\py*{ans.201}\\\\\n   &\\py*{ans.202}\\\\\n   &\\py*{ans.203}\\\\\n   &\\py*{ans.204}\\\\\n   &\\py*{ans.205}\\\\\n   &\\py*{ans.206}\\\\\n   &\\py*{ans.207}\\\\\n   &\\py*{ans.208}\\\\\n   &\\py*{ans.209}\\\\\n   &\\py*{ans.210}\\\\\n   &\\py*{ans.211}\n\\end{align*}\n\n\\clearpage\n\n\\section*{Visible Python markup}\n\nThere is nothing special in this particular example. Its purpose is to provide a contrast with the following example where the tags have been hidden from view.\n\n\\vspace{5pt}\n\n\\PySetup{action=show}\n\n\\begin{python}\n   from sympy import *\n\n   x = Symbol('x')\n\n   ans = diff(cos(x)**2, x)                         # py(ans.301,ans)\n   ans = integrate(2*sin(x)*exp(-x), x)             # py(ans.302,ans)\n\\end{python}\n\n\\begin{align*}\n   &\\py*{ans.301}\\\\\n   &\\py*{ans.302}\n\\end{align*}\n\n\\section*{Hidden Python markup}\nThis example creates the impression that there are no tags in the following block. But looks can be deceptive, the truth is revealed on the following page.\n\n\\vspace{5pt}\n\n\\PySetup{action=hide}\n\n\\begin{python}\n   from sympy import *\n\n   x = Symbol('x')\n\n   ans = diff(cos(x)**2, x)                         # py(ans.401,ans)\n   ans = integrate(2*sin(x)*exp(-x), x)             # py(ans.402,ans)\n\\end{python}\n\n\\PySetup{action=verbatim}\n\n\\begin{python}\n   from sympy import *\n\n   x = Symbol('x')\n\n   ans = diff(cos(x)**2, x)\n   ans = integrate(sin(x)*exp(-x), x)\n\\end{python}\n\n\\begin{align*}\n   &\\py*{ans.401}\\\\\n   &\\py*{ans.402}\n\\end{align*}\n\n\\clearpage\n\n\\section*{How to hide the tags}\nThe easiest way to hide the tags from view is to include two blocks, one containing the tags but hidden from view using {\\tt\\small\\verb|\\PySetup{action=hide}|}, the other block is a copy of the first but with all tags stripped out. That second block is made visible using {\\tt\\small\\verb|\\PySetup{action=verbatim}|}. This is a bit cumbersome and prone to errors (the second block must be a faithful copy of the first block). Better solutions could be devised but they all appear to require significant changes to the current preprocessors -- so much so that the this cloning trick was deemed a reasonable compromise.\n\nHere is the LaTeX code from the previous example.\n\n\\vspace{-5pt}\n\n\\begin{minipage}[t]{0.65\\textwidth}\n\\bgcolour{white}\n\\latexstyle\n\\begin{latex}\n*  \\PySetup{action=hide}\n*\n*  \\begin{python}\n\\end{latex}\n\\pythonstyle\n\\begin{python}\n*     from sympy import *\n*\n*     x = Symbol('x')\n*\n*     ans = diff(cos(x)**2, x)                         # py(ans.401,ans)\n*     ans = integrate(2*sin(x)*exp(-x), x)             # py(ans.402,ans)\n\\end{python}\n\\latexstyle\n\\begin{latex}\n*  \\end{python}\n*\n*  \\PySetup{action=verbatim}\n*\n*  \\begin{python}\n\\end{latex}\n\\pythonstyle\n\\begin{python}\n*     from sympy import *\n*\n*     x = Symbol('x')\n*\n*     ans = diff(cos(x)**2, x)\n*     ans = integrate(sin(x)*exp(-x), x)\n\\end{python}\n\\latexstyle\n\\begin{latex}\n*  \\end{python}\n*\n*  \\begin{align*}\n*     &\\py*{ans.401}\\\\\n*     &\\py*{ans.402}\n*  \\end{align*}\n\\end{latex}\n\\end{minipage}\n\n\\end{document}\n", "meta": {"hexsha": "62546fce1dc6967f1c857f6c4711f4a39454be02", "size": 6685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "python/examples/example-08.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-08.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-08.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.449339207, "max_line_length": 616, "alphanum_fraction": 0.5736724009, "num_tokens": 2086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672595, "lm_q2_score": 0.8887587875995482, "lm_q1q2_score": 0.7606452277443043}}
{"text": "\\subsection{Rings}\\label{subsec:rings}\n\n\\begin{definition}\\label{def:semiring}\n  A \\term{semiring} \\( (R, +, \\cdot) \\) is an algebraic structure with two binary operations:\n  \\begin{thmenum}[series=def:semiring]\n    \\thmitem{def:semiring/addition} The \\term{addition} \\( + \\) is \\hyperref[def:magma/associative]{associative}, \\hyperref[def:unital_magma]{unital} and \\hyperref[def:magma/commutative]{commutative}, i.e. \\( (R, +) \\) is a commutative \\hyperref[def:unital_magma/monoid]{monoid}. The additive identity is usually denoted by \\( 0 \\). We denote this monoid by \\( R^+ \\).\n\n    \\thmitem{def:semiring/multiplication} The \\term{multiplication} \\( \\cdot \\) (usually written using juxtaposition) is \\hyperref[def:magma/associative]{associative}, i.e. \\( (R, \\cdot) \\) a \\hyperref[def:magma/associative]{semigroup}. We denote this semigroup by \\( R^\\times \\).\n\n    \\thmitem{def:semiring/distributivity} We require that \\( \\cdot \\) \\term{distributes} over \\( + \\), i.e.\n    \\begin{align}\\label{eq:def:semiring/distributivity}\n      (x + y)z = xz + yz\n      &&\n      x(y + z) = xy + xz\n    \\end{align}\n  \\end{thmenum}\n\n  The \\term{trivial semiring} consists only of the additive identity \\( \\{ 0 \\} \\).\n\n  We say that \\( x \\) is \\term{nilpotent} if \\( x^n = 0 \\) for some nonnegative integer \\( n \\).\n\n  The following are special kinds of semirings:\n  \\begin{thmenum}[resume=def:semiring]\n    \\thmitem{def:semiring/dioid} \\term{Dioids} are unital semirings, that is, both \\( (R, +) \\) and \\( (R, \\cdot) \\) are monoids. The term \\enquote{semiring} is sometimes reserved for dioids while \\enquote{hemiring} is used for what we call semirings.\n\n    We define integer exponentiation as a shorthand for iterated multiplication. That is, if multiplication is invertible, for \\( r \\in R \\) and \\( n \\in \\BbbZ \\) we define\n    \\begin{equation*}\n      r^n \\coloneqq \\begin{cases}\n        1,                      & n = 0  \\\\\n        r^{n - 1} \\cdot r,      & n > 0  \\\\\n        r^{n + 1} \\cdot r^{-1}, & n < 0.\n      \\end{cases}\n    \\end{equation*}\n\n    If multiplication is not invertible, we skip defining negative exponents.\n\n    \\thmitem{def:semiring/no_zero_divisor} If \\( xy = 0 \\) whenever \\( x \\) and \\( y \\) are nonzero, we say that the semiring has \\term{no zero divisors}.\n\n    \\thmitem{def:semiring/ring} \\term{Rings} are semirings with invertible addition, i.e. \\( (R, +) \\) forms an \\hyperref[def:abelian_group]{abelian group}. The category of rings is denoted by \\( \\cat{Ring} \\).\n\n    \\thmitem{def:semiring/unital_ring} \\term{Unital rings} are \\hyperref[def:semiring/ring]{rings} in which multiplication is unital, i.e. \\( R, \\cdot \\) is a \\hyperref[def:unital_magma/monoid]{monoid} with identity \\( 1 \\). Some authors define all rings to be unital. Invertible elements under multiplication are called \\term{units} (see \\fullref{rem:units_in_rings_etymology}) and the operation itself is called \\term{division}.\n\n    We may additionally require that the ring is nontrivial, so that \\( 0 \\neq 1 \\) (see \\fullref{thm:def:semiring/properties/identities_are_equal_iff_trivial_ring}).\n\n    \\thmitem{def:semiring/commutative_ring} \\term{Commutative rings} are \\hyperref[def:semiring/ring]{rings} in which multiplication is \\hyperref[def:magma/commutative]{commutative}, i.e. \\( R, \\cdot \\) is a commutative semigroup.\n\n    \\thmitem{def:semiring/commutative_unital_ring} \\term{Commutative unital rings} are (obviously) both commutative and unital and as usually assumed to be nontrivial. Despite being ubiquitous, they do not have an established one-word name.\n\n    We are mostly interested in these rings because if \\( R \\) is a commutative unital ring, so is its polynomial \\hyperref[def:algebra_of_polynomials]{ring} \\( R[X] \\) and, by induction, multivariate polynomial \\hyperref[def:multivariate_polynomial]{rings} (\\( R[X, Y] = R[X][Y] \\)). So we are interested in properties of \\( R \\) that are preserves by \\( R[X] \\). This is the reason, so many types of commutative rings and ideals are studied. We are interested in integral domains when we speak of divisibility and factorization and since zero is absorbing, it does not interact nicely with factorization. Refer to \\fullref{sec:commutative_algebra}.\n\n    \\thmitem{def:semiring/integral_domain} \\term{Integral domains} are nontrivial commutative unital \\hyperref[def:semiring/commutative_unital_ring]{rings} with no zero \\hyperref[def:commutative_ring_division]{divisors}. This implies that \\( 1 \\neq 0 \\) because otherwise \\( 1 \\cdot 1 = 0 \\) and \\( 1 \\) would be a zero divisor. This in turn implies that \\fullref{thm:def:semiring/properties/identities_are_equal_iff_trivial_ring}.\n\n    \\Fullref{thm:def:semiring/properties/cancellable_iff_not_zero_divisor} shows that a commutative unital ring \\( R \\) is an integral domain if and only if its multiplication is cancellable.\n\n    \\thmitem{def:semiring/unique_factorization_domain} \\term{Unique factorization domains} are integral domains in which every element has unique \\hyperref[def:factorization_in_ring]{factorization} exists.\n\n    \\thmitem{def:semiring/principal_ideal_domain} \\term{Principal ideal domains} are integral \\hyperref[def:semiring/integral_domain]{domains} in which every \\hyperref[def:semiring_ideal]{ideal} is \\hyperref[def:principal_ideal]{principal}.\n\n    By \\fullref{thm:pid_is_ufd}, every principal ideal domain is a unique factorization domain.\n\n    \\thmitem{def:semiring/euclidean_domain} \\term{Euclidean domains} are integral \\hyperref[def:semiring/integral_domain]{domains} which allow division with remainders (see \\fullref{def:euclidean_domain}).\n\n    By \\fullref{thm:euclidean_domain_is_pid}, every Euclidean domain is a principal ideal domain.\n\n    \\thmitem{def:semiring/division_ring} \\term{Division rings} are nontrivial unital \\hyperref[def:semiring/unital_ring]{rings} in which all nonzero elements are units, i.e. \\( (F \\setminus \\{ 0 \\}, \\cdot) \\) is a \\hyperref[def:group]{group}. The nontriviality is a requirement because we want \\( 1 \\) not to be a zero divisor (see discussion in \\fullref{def:semiring/integral_domain}).\n\n    The multiplicative inverse of an element in a division ring is called its \\term{reciprocal}.\n\n    In order to fit multiplicative invertibility as an axiom, we can use the following formula:\n    \\begin{equation*}\n      \\forall \\xi ((\\xi \\doteq 0) \\lor \\exists \\eta (\\xi \\cdot \\eta \\doteq 1))\n    \\end{equation*}\n    or add an additional operation \\( (\\cdot)^{-1} \\) that inverts all nonzero elements and fixes zero, that is,\n    \\begin{equation*}\n      \\forall \\xi (\\xi \\cdot \\xi^{-1} \\doteq 1),\n    \\end{equation*}\n    where we define \\( 0^{-1} = 0 \\). This is only a formalism since \\( 0 \\) is not actually \\enquote{invertible}, but it is required if we wish to avoid existential quantifiers.\n\n    \\thmitem{def:semiring/field} \\term{Fields} are \\hyperref[def:magma/commutative]{commutative} division \\hyperref[def:semiring/division_ring]{rings}, i.e. \\( (F \\setminus \\{ 0 \\}, \\cdot) \\) is an \\hyperref[def:abelian_group]{abelian group}. The category of fields is denoted by \\( \\cat{Field} \\).\n  \\end{thmenum}\n\\end{definition}\n\n\\begin{example}\\label{ex:semirings}\n  We give examples and counterexamples of semirings. Note that the order of definitions in \\fullref{def:semiring} is not preserved.\n\n  \\begin{refenum}\n    \\refitem{def:semiring/euclidean_domain} The base building block for the examples will be the ring \\( (\\BbbZ, +, \\cdot) \\) of \\hyperref[def:set_of_integers]{integers}, which itself is an Euclidean domain (see \\fullref{def:set_of_integers}).\n\n    Another example of Euclidean domains are the polynomial rings over a field (see \\fullref{thm:polynomials_over_field_are_euclidean_domain}).\n\n    \\refitem{def:semiring/dioid} By removing additive inverses from the integers, we obtain the dioid \\( (\\BbbN, +, \\cdot) \\) of \\hyperref[def:set_of_natural_numbers]{natural numbers}.\n\n    Take only the commutative monoid \\( (\\BbbN, +) \\) of \\hyperref[def:set_of_natural_numbers]{natural numbers} with addition. The endomorphism semiring\n    \\begin{equation*}\n      \\End(\\BbbN)\n    \\end{equation*}\n    is a noncommutative dioid.\n\n    Tropical \\hyperref[def:tropical_semiring]{semirings} are another example noncommutative dioids.\n\n    \\refitem{def:semiring} Simple examples of semirings (but not rings) without unity are proper semiring ideals. For example, the ideal \\( 2\\BbbN \\) of positive even numbers is a non-unital semiring.\n\n    Another example can be given by taking a subsemiring, but not a unital subsemiring of the endomorphism dioid \\( \\End(\\BbbN, \\oplus) \\), for example the functions\n    \\begin{balign*}\n       & f_n: \\BbbN \\to \\BbbN        \\\\\n       & f_n(x) \\coloneqq x + n,\n    \\end{balign*}\n    where \\( n > 0 \\). They are closed under composition and thus form a semiring themselves, but they do not contain the identity function, so the semiring is not unital.\n\n    \\refitem{def:semiring/unital_ring} The endomorphism rings \\( \\End(G) \\) for any abelian group \\( G \\) are unital, but non-commutative rings. This includes the matrix space \\( R^{n \\times n} \\) (see \\fullref{thm:finite_dimensional_operators_are_isomorphic_to_matrices}).\n\n    \\refitem{def:semiring/ring} Consider the Banach space \\( C_0(\\BbbC) \\) of complex functions vanishing at \\hyperref[def:function_spaces/c0]{infinity}. If we take addition to be pointwise addition and multiplication to be composition, then \\( C_0(\\co) \\) becomes a non-commutative ring with no multiplicative identity because \\( C_0(\\co) \\) does not contain the identity function.\n\n    \\refitem{def:semiring/commutative_ring} For an example of a commutative ring without unit, consider again the Banach space \\( C_0(\\co) \\), however define multiplication as pointwise function multiplication rather than by composition. The constant function \\( f(x) = 1 \\) does not vanish at infinity, hence \\( (C_0(\\co), +, \\cdot) \\) is a commutative, but not unital ring.\n\n    \\refitem{def:semiring/commutative_unital_ring} We are mostly interested in different types of commutative unital rings since the polynomials over well-behaved commutative rings preserve this behavior. This is important because multivariate \\hyperref[def:multivariate_polynomial]{polynomials} are defined inductively as polynomials over polynomial rings. See \\fullref{thm:geometric_nullstellensatz} for an application.\n\n    An example of a nontrivial commutative unital ring that has zero divisors is the matrix algebra \\( \\BbbZ^{n \\times n} \\) over the integers. It is a ring under addition and matrix multiplication. We have\n    \\begin{equation*}\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{equation*}\n    thus there are zero divisors in \\( \\BbbZ^{n \\times n} \\).\n\n    \\refitem{def:semiring/integral_domain}\\cite[388]{Knapp2016BasicAlgebra} The integral domain \\( \\BbbZ[\\sqrt{-5}] \\) is not a unique factorization domain because\n    \\begin{equation*}\n      6 = (1 + \\sqrt{-5}) (1 - \\sqrt{-5}) = 2 \\cdot 3.\n    \\end{equation*}\n\n    Note that \\( \\BbbZ[\\sqrt{-5}] \\) is an integral domain by \\fullref{thm:polynomials_over_integral_domain_are_integral_domain}.\n\n    \\refitem{def:semiring/unique_factorization_domain}\\cite{ProofWiki:polynomials_in_integers_is_not_principal_ideal_domain} The unique factorization domain \\( \\BbbZ[X] \\) is not a principal ideal domain.\n\n    Note that \\( \\BbbZ[X] \\) is a unique factorization domain by \\fullref{thm:polynomials_over_integral_domain_are_integral_domain}.\n\n    Consider the ideal \\( I \\) of polynomials with an even constant term.\n\n    Assume that \\( I \\) is generated by the polynomial \\( p(X) \\in \\BbbZ[X] \\). Since \\( 2 \\in I \\), then \\( p(X) \\) divides \\( 2 \\), so \\( p(X) \\in \\{ -2, -1, 1, 2 \\} \\), that is \\( p(X) \\) is a unit of \\( \\BbbZ[X] \\). But then \\( I = \\braket{p(X)} = \\BbbZ[X] \\), which contradicts the definition of \\( I \\).\n\n    The obtained contradiction proves that \\( \\BbbZ[X] \\) is not a principal ideal domain.\n\n    \\refitem{def:semiring/principal_ideal_domain} Principal ideal domains are not Euclidean domains in general. Such domains are discussed in \\cite{Anderson1988}.\n\n    \\refitem{def:semiring/division_ring} The \\hyperref[def:ring_localization]{localization} of a noncommutative ring over its nonzero cancellative elements (characterized by \\fullref{thm:ring_localization_universal_property}), if it exists, forms a division ring.\n\n    \\refitem{def:semiring/field} The canonical examples of fields include the rational \\hyperref[def:set_of_rational_numbers]{numbers} \\( \\BbbQ \\), the \\hyperref[def:set_of_real_numbers]{real numbers} \\( \\BbbR \\) and the \\hyperref[def:set_of_complex_numbers]{complex numbers} \\( \\BbbC \\).\n\n    More generally, any nontrivial commutative unital can be embedded in a field by \\fullref{def:field_of_fractions}.\n  \\end{refenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:def:semiring/properties}\n  Any semiring \\( R \\) has the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:semiring/properties/zero_is_absorbing} Multiplication by \\( 0 \\) is \\term{absorbing}, that is, \\( x0 = 0x = 0 \\) for any \\( x \\in R \\).\n    \\thmitem{thm:def:semiring/properties/one_exponents} For any integer \\( n \\), \\( 1^n = 1 \\).\n    \\thmitem{thm:def:semiring/properties/identities_are_equal_iff_trivial_ring} In a unital \\hyperref[def:semiring/unital_ring]{ring}, the additive and multiplicative identities are equal if and only if the ring is trivial.\n    \\thmitem{thm:def:semiring/properties/cancellable_iff_not_zero_divisor} An element \\( x \\in R \\) of a commutative ring is a zero divisor if and only if it is cancellable (with respect to multiplication).\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:semiring/properties/zero_is_absorbing} Follows from \\fullref{thm:def:left_module/properties/ring_zero_is_absorbing} and \\fullref{thm:def:left_module/properties/module_zero_is_absorbing}.\n  \\SubProofOf{thm:def:semiring/properties/one_exponents} By definition, \\( r \\cdot 1 = r \\) for any \\( r \\in R \\). Hence, for \\( 1 \\cdot 1 = 1 \\). Proceeding by induction, we can show that for \\( 1^n = 1 \\) for positive \\( n \\). For negative \\( n \\), since \\( 1 \\) is its own inverse, we also have \\( 1^n = 1 \\).\n\n  \\SubProofOf{thm:def:semiring/properties/identities_are_equal_iff_trivial_ring}\n  Let \\( 0 = 1 \\) in a unital ring \\( R \\). Let \\( r \\in R \\). Then, by \\fullref{thm:def:semiring/properties/zero_is_absorbing},\n  \\begin{equation*}\n    r = 1r = 0r = 0.\n  \\end{equation*}\n\n  Thus, \\( r = 0 \\). Since \\( r \\) was arbitrary, we conclude that \\( R = \\{ 0 \\} \\) is the trivial ring.\n\n  \\SubProofOf{thm:def:semiring/properties/zero_is_absorbing} Follows from \\fullref{thm:def:left_module/properties/ring_zero_is_absorbing} and \\fullref{thm:def:left_module/properties/module_zero_is_absorbing}.\n\n  \\SubProofOf{thm:def:semiring/properties/one_exponents} By definition, \\( r \\cdot 1 = r \\) for any \\( r \\in R \\). Hence, for \\( 1 \\cdot 1 = 1 \\). Proceeding by induction, we can show that for \\( 1^n = 1 \\) for positive \\( n \\). For negative \\( n \\), since \\( 1 \\) is its own inverse, we also have \\( 1^n = 1 \\).\n\n  \\SubProofOf{thm:def:semiring/properties/identities_are_equal_iff_trivial_ring} The trivial ring only has one element, hence \\( 0 = 1 \\).\n\n  \\SufficiencySubProofOf{thm:def:semiring/properties/cancellable_iff_not_zero_divisor}\n  Suppose that \\( x \\in R \\) is not cancellable. Then there exist \\( y \\neq z \\) for which \\( xy = xz \\). We have \\( y - z \\neq 0 \\) and\n  \\begin{equation*}\n    x(y - z) = xy - xz = 0.\n  \\end{equation*}\n\n  Thus, \\( x \\) is a zero divisor.\n\n  \\NecessitySubProofOf{thm:def:semiring/properties/cancellable_iff_not_zero_divisor} If \\( x \\) is a zero divisor, fix \\( y \\in R \\) such that \\( xy = 0 \\). For any \\( z \\in R \\) we have\n  \\begin{equation*}\n    xy = 0 = x(yz)\n  \\end{equation*}\n , but \\( y \\neq yz \\) in general.\n\n  Thus, \\( x \\) is not cancellable.\n\\end{proof}\n\n\\begin{definition}\\label{def:semiring_characteristic}\n  Fix a nontrivial unital semiring \\( R \\) (the nontrivial condition is essential because of \\fullref{thm:embedding_preserves_characteristic}). We define its \\term{characteristic} \\( \\op{char}(R) \\) via any of the equivalent definitions:\n  \\begin{thmenum}\n    \\thmitem{def:semiring_characteristic/direct} \\( \\op{char}(R) \\) is the smallest number of times \\( 1_R \\) must be added to itself in order to obtain \\( 0_R \\) and zero if \\( 0_R \\) cannot be obtained in this way.\n\n    \\thmitem{def:semiring_characteristic/homomorphism} The semiring \\( \\BbbZ_{\\geq 0} \\) of nonnegative integers can be embedded into \\( R \\) via the unique homomorphism\n    \\begin{balign*}\n       & \\iota: \\BbbZ_{\\geq 0} \\to R                     \\\\\n       & \\iota(k) \\coloneqq \\begin{cases}\n        0_R,                & k = 0 \\\\\n        \\iota(k - 1) + 1_R, & k > 1\n      \\end{cases}\n    \\end{balign*}\n    that adds the identity \\( 1_R \\) to itself \\( n \\) times. This allows us to use the positive integers in any semiring. Note that if addition in \\( R \\) is invertible (that is, if \\( R \\) is a ring), we can embed all integers by defining \\( \\iota(n) \\coloneqq -\\iota(-n) \\) for \\( n < 0 \\).\n\n    We define \\( \\op{char}(R) \\) as the positive integer \\( n \\) such that\n    \\begin{equation*}\n      n\\BbbZ_{\\geq 0} \\cong \\ker\\iota.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  We will show that \\( \\iota \\) is unique. Let \\( \\varphi: \\BbbZ_{\\geq 0} \\to R \\) be another embedding. Obviously\n  \\begin{equation*}\n    \\iota(1_{\\BbbZ}) = 1_R = \\varphi(1_{\\BbbZ}).\n  \\end{equation*}\n\n  Then by induction on \\( k \\) we can show that\n  \\begin{equation*}\n    \\iota(k) = \\underbrace{1_R + \\cdots + 1_R}_{k \\text{ times }} = \\varphi(k).\n  \\end{equation*}\n\n  Hence, \\( \\iota = \\varphi \\).\n\\end{proof}\n\n\\begin{proposition}\\label{thm:embedding_preserves_characteristic}\n  If \\( R \\) is a nontrivial unital semiring and \\( T \\) is a unital supersemiring of \\( R \\), then\n  \\begin{equation*}\n    \\op{char}(T) = \\op{char}(R).\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Note that if \\( R \\) was the trivial unital semiring, its characteristic would be \\( 1 \\) and yet the characteristic of \\( T \\) could be nonzero. So the theorem would not hold if \\( R \\) was trivial.\n\n  Now assume that \\( R \\) is nontrivial and let \\( \\iota: \\BbbZ_{\\geq 0} \\to R \\) be the embedding defining \\( \\op{char}(R) \\). Then it is obviously also an embedding of \\( \\BbbZ_{\\geq 0} \\) into \\( T \\). Since \\( 0_R = 0_T \\), then \\( \\ker \\iota = \\ker \\varphi = n\\BbbZ_{\\geq 0} \\), where \\( n = \\op{char}(R) \\).\n\\end{proof}\n\n\\begin{example}\\label{ex:semiring_characteristic}\n  We find examples of semiring characteristics via the embedding \\( \\iota \\) defined in \\fullref{def:semiring_characteristic}:\n\n  \\begin{thmenum}\n    \\thmitem{ex:semiring_characteristic/nonnegative_integers} The zero-based \\hyperref[def:set_of_natural_numbers]{natural numbers} \\( \\BbbN \\) have characteristic \\( \\op{char}(\\BbbN) = 0 \\) because \\( \\iota \\) is an isomorphism. Consequently, any supersemiring of \\( \\BbbN \\) has characteristic zero, most notably the integers \\( \\BbbZ \\) and the fields \\( \\BbbQ \\), \\( \\BbbR \\), \\( \\BbbC \\).\n\n    \\thmitem{ex:semiring_characteristic/integers_modulo} The integers modulo \\( n \\) (see \\fullref{def:ring_of_integers_modulo}) have characteristic \\( \\op{char}(\\BbbZ_n) = n \\) because of \\fullref{thm:integers_modulo_isomorphic_to_quotient_group}.\n\n    \\thmitem{ex:semiring_characteristic/polynomial_ring} An \\hyperref[def:algebra_over_ring]{algebra} \\( A \\) over a nontrivial commutative unital ring \\( R \\) has characteristic \\( \\op{char}(A) = R \\) because of the canonical embedding of \\( R \\) in \\( A \\). In particular, polynomial \\hyperref[def:algebra_of_polynomials]{rings} \\( R[X] \\) have the same characteristic as their ring.\n\n    \\thmitem{ex:semiring_characteristic/galois_fields} The \\hyperref[thm:galois_field_existence]{Galois field} \\( \\BbbF_{p^n} \\) has characteristic \\( p \\) because it is a field extension of \\( \\BbbF_p \\).\n  \\end{thmenum}\n\\end{example}\n\n\\begin{definition}\\label{def:semiring_kernel}\n  The \\term{kernel} \\( \\ker(f) \\) of a semiring homomorphism \\( f: R \\to S \\) is the \\hyperref[def:zero_locus]{zero locus} of \\( f \\), that is, \\hyperref[thm:def:function/properties/preimage]{preimage} \\( f^{-1}(0_S) \\).\n\n  It is an instance of \\fullref{def:zero_morphisms/kernel}.\n\\end{definition}\n\n\\begin{definition}\\label{def:quotient_semiring}\n  Let \\( R \\) be a ring and \\( I \\) be an ideal of \\( M \\). Define the \\term{quotient ring} to be the quotient \\hyperref[def:quotient_left_module]{module} when considering \\( R \\) as a module over itself.\n\\end{definition}\n\n\\begin{theorem}\\label{thm:homomorphism_theorem_for_rings}\n  Let \\( \\varphi: R \\to T \\) be a homomorphism of rings. We have the isomorphism\n  \\begin{equation*}\n    R / \\ker \\varphi \\cong \\img \\varphi.\n  \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n  Special case of \\fullref{thm:homomorphism_theorem_for_left_modules}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:ring_homomorphism_simpler_conditions}\n  A function \\( f: R \\to S \\) between the rings \\( R \\) and \\( S \\) is a homomorphism in the sense of \\fullref{def:first_order_homomorphism} if and only if for any \\( x, y \\in R \\) it satisfies\n  \\begin{equation}\\label{thm:ring_homomorphism_simpler_conditions/condition}\n    \\begin{dcases}\n      f(x + y) & = f(x) + f(y), \\\\\n      f(xy)    & = f(x) f(y),   \\\\\n      f(1_R)   & = 1_S.\n    \\end{dcases}\n  \\end{equation}\n\n  Note that the last condition is only for unital rings.\n\n  In other words, if a function satisfies \\fullref{thm:ring_homomorphism_simpler_conditions/condition}, the following are automatically satisfied:\n  \\begin{itemize}\n    \\item \\( f(0_R) = 0_S \\)\n    \\item for all \\( x \\in R \\), we have \\( f(-x) = -f(x) \\)\n    \\item for all units \\( x \\in R \\), we have \\( f(x^{-1}) = f(x)^{-1} \\)\n  \\end{itemize}\n\\end{proposition}\n\\begin{proof}\n  Since \\( (R, +) \\) and \\( (S, +) \\) are groups, the first two equalities from \\fullref{thm:group_homomorphism_single_condition}.\n\n  The proof of \\( f(x^{-1}) = f(x)^{-1} \\) is analogous to \\fullref{thm:group_homomorphism_single_condition}.\n\\end{proof}\n\n\\begin{definition}\\label{def:ring_of_integers_modulo}\n  The \\hyperref[def:set_of_integers]{integers} \\( \\BbbZ \\) form a ring under addition and multiplication. Fix a positive integer \\( n > 1 \\). We extend the group \\( \\BbbZ_n \\) of integers modulo \\( n \\) (see \\fullref{def:group_of_integers_modulo}) with the operation\n  \\begin{equation*}\n    x \\odot y \\coloneqq \\rem(xy, n).\n  \\end{equation*}\n\n  The ring \\( \\BbbZ_n \\) is called the \\term{ring of integers modulo} \\( n \\).\n\\end{definition}\n\\begin{proof}\n  Note that\n  \\begin{balign*}\n     & \\phantom{\\cong}\\thickspace \\rem(x, n) \\rem(y, n)\n     & \\pmod n \\cong                           \\\\ &\\cong\n    (x - n \\quot(x, n)) (y - n \\quot(y, n))\n     & \\pmod n \\cong                           \\\\ &\\cong\n    xy - n \\quot(x, n) - n \\quot(y, n) + n^2 \\quot(x, n) \\quot(y, n)\n     & \\pmod n \\cong                           \\\\ &\\cong\n    xy\n     & \\pmod n. \\phantom{\\cong}\n  \\end{balign*}\n\n  The proof that multiplication in \\( \\BbbZ_n \\) is associative, unital and commutative becomes trivial.\n\n  We will prove that multiplication distributes over addition. Fix \\( x, y, z \\in \\BbbZ_n \\). We have\n  \\begin{balign*}\n    (x \\oplus y) \\odot z\n     & =\n    \\rem((x \\oplus y) z, n)\n    =    \\\\ &=\n    \\rem(\\rem(x + y, n) z, n)\n    =    \\\\ &=\n    \\rem((x + y - n \\quot(x + y, n)) z, n)\n    =    \\\\ &=\n    \\rem((x + y)z, n).\n  \\end{balign*}\n  and\n  \\begin{balign*}\n    (x \\odot z) \\oplus (y \\odot z)\n     & =\n    \\rem([(x \\odot z) + (y \\odot z)], n)\n    =    \\\\ &=\n    \\rem([xz - n \\quot(xz, n) + yz - n \\quot(yz, n)], n)\n    =    \\\\ &=\n    \\rem(xz + yz, n)\n    =    \\\\ &=\n    \\rem((x + y)z, n).\n  \\end{balign*}\n\n  Hence,\n  \\begin{equation*}\n    (x \\oplus y) \\odot z = (x \\odot z) \\oplus (y \\odot z).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{definition}\\label{def:tropical_semiring}\\mcite{nLab:tropical_semiring}\n  Fix a partially \\hyperref[def:partially_ordered_set]{ordered} \\hyperref[def:abelian_group]{abelian group} \\( (M, +, \\leq) \\). Let \\( \\infty \\) be a sentinel symbol not in \\( M \\). Define\n  \\begin{equation*}\n    T \\coloneqq M \\cup \\{ \\infty \\}\n  \\end{equation*}\n  with operations\n  \\begin{balign*}\n     & \\oplus: T \\times T \\to T                        \\\\\n     & x \\oplus y \\coloneqq \\begin{cases}\n      \\min \\{ x, y \\}, & x \\neq \\infty \\text{ and } y \\neq \\infty \\text{ and they are comparable}, \\\\\n      \\infty,          & x = \\infty \\text{ or } y = \\infty\n    \\end{cases} \\\\\n    \\\\\n     & \\odot: T \\times T \\to T                         \\\\\n     & x \\odot y \\begin{cases}\n      x + y,  & x \\neq \\infty \\text{ and } y \\neq \\infty, \\\\\n      \\infty, & x = \\infty \\text{ or } y = \\infty\n    \\end{cases}\n  \\end{balign*}\n\n  This makes \\( (T, \\oplus, \\odot) \\) into a \\hyperref[def:semiring/dioid]{dioid} with additive identity \\( \\infty \\) and multiplicative identity \\( 0 \\). We call \\( (T, \\oplus, \\odot) \\) the \\( \\min \\)-\\term{tropical semiring} or simply the \\term{tropical semiring} over \\( M \\). We define the \\( \\max \\)-\\term{tropical semiring} analogously by simply replacing \\( \\min \\) with \\( \\max \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:semiring_direct_product}\n  Let \\( \\{ X_k \\}_{k \\in \\mscrK} \\) be a nonempty family of rings.\n\n  Analogously to \\fullref{def:group_direct_product}, we define their \\term{direct product} as the ring \\( \\prod_{k \\in \\mscrK} X_k \\), the operations defined componentwise as\n  \\begin{balign*}\n     & \\{ x_k \\}_{k \\in \\mscrK} + \\{ y_k \\}_{k \\in \\mscrK}\n    \\coloneqq\n    \\{ x_k + y_k \\}_{k \\in \\mscrK},                         \\\\\n     & \\{ x_k \\}_{k \\in \\mscrK} \\cdot \\{ y_k \\}_{k \\in \\mscrK}\n    \\coloneqq\n    \\{ x_k \\cdot y_k \\}_{k \\in \\mscrK}.\n  \\end{balign*}\n\n  We define their \\term{direct sum} as the subring of \\( \\prod_{k \\in \\mscrK} X_k \\) (see \\fullref{def:semiring_direct_product}) where only finitely many components of any ring element are different from zero.\n\\end{definition}\n\n\\begin{proposition}\\label{thm:ring_categorical_limits}\n  We are interested in \\hyperref[def:category_of_cones/limit]{categorical limits} and \\hyperref[def:category_of_cones/colimit]{colimits} in \\( \\cat{Ring} \\). Fix an indexed family  \\( \\{ X_k \\}_{k \\in \\mscrK} \\) of rings.\n  \\begin{thmenum}\n    \\thmitem{thm:ring_categorical_limits/product} Their \\hyperref[def:discrete_category_limits]{categorical product} is their direct \\hyperref[def:semiring_direct_product]{product} \\( \\prod_{k \\in \\mscrK} X_k \\), the projection morphisms being inherited from \\fullref{thm:discrete_category_limits_in_set}.\n  \\end{thmenum}\n\\end{proposition}\n\n\\begin{definition}\\label{def:opposite_ring}\\mcite[555]{Knapp2016BasicAlgebra}\n  The opposite ring \\( R^{-1} \\) of \\( R \\) is defined as the same abelian group with the order of multiplication reversed. They are obviously isomorphic for commutative rings.\n\\end{definition}\n\n\\begin{definition}\\label{def:ring_commutator}\n  Let \\( R \\) be a ring. The commutator of \\( x, y \\in R \\) is defined as\n  \\begin{equation*}\n    [x, y] \\coloneqq xy - yx.\n  \\end{equation*}\n\n  The commutator ideal of \\( R \\) is the ideal \\hyperref[def:generated_ring_ideal]{generated} by all the commutators in \\( G \\).\n\\end{definition}\n\n\\begin{proposition}\\label{thm:quotient_by_commutator_ideal}\n  The quotient \\( R / I \\) of any unital \\hyperref[def:semiring/unital_ring]{ring} \\( R \\) by its commutator ideal \\( I \\) is \\hyperref[def:semiring/commutative_ring]{commutative}.\n\\end{proposition}\n\n\\begin{definition}\\label{def:endomorphism_dioid}\n  Let \\( (X, +) \\) be an monoid and let \\( \\End(X) \\) be set of endomorphism over \\( X \\). We define two operations:\n  \\begin{itemize}\n    \\item Pointwise addition \\( [f + g](x) \\coloneqq f(x) + g(x) \\).\n    \\item Multiplication by composition \\( [fg](x) \\coloneqq f(g(x)) \\).\n  \\end{itemize}\n\n  These operations make \\( \\End(X) \\) into a dioid. If \\( X \\) is a group, then \\( \\End(X) \\) is a ring.\n\n  If \\( X \\) is a dioid, we define \\( \\End(X) \\) to be a set of dioid endomorphisms (that is, we want the additive group homomorphisms to preserve multiplication and units). Then \\( \\End(X) \\) is again a dioid and, if \\( X \\) is a unital ring, so is \\( \\End(X) \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:function_support}\n  The \\term{support} of a function \\( f: S \\to R \\) from a set \\( S \\) to a semiring \\( R \\) is the set\n  \\begin{equation*}\n    \\supp(f) \\coloneqq \\{ x \\in S \\colon f(x) \\neq 0_R \\}.\n  \\end{equation*}\n\\end{definition}\n\n\\begin{definition}\\label{def:functions_vanish_nowhere}\n  Let \\( \\mathcal{F} \\) be a family of functions from a set \\( S \\) to a ring \\( R \\). We say that \\( \\mathcal{F} \\) \\term{vanishes nowhere} if for every \\( x \\in S \\) there exists a function \\( f \\in \\mathcal{F} \\) such that \\( f(x) \\neq 0_R \\).\n\\end{definition}\n\n\\begin{definition}\\label{def:ordered_semiring}\n  Extending \\fullref{def:preordered_magma} to (semi)rings, we define a \\term{preordered semiring} to be a semiring \\( \\BbbR \\) with a magma preorder \\( \\leq \\) that additionally satisfies\n  \\begin{equation}\\label{eq:def:ordered_semiring/nonnegativity}\n    0 \\leq y \\T{and} 0 \\leq y \\T{implies} 0 \\leq xy.\n  \\end{equation}\n\\end{definition}\n", "meta": {"hexsha": "72ffe99d7f3c0376f87e6ea67ef9324155df39a7", "size": 29365, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/rings.tex", "max_stars_repo_name": "v--/notebook", "max_stars_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/rings.tex", "max_issues_repo_name": "v--/notebook", "max_issues_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/rings.tex", "max_forks_repo_name": "v--/notebook", "max_forks_repo_head_hexsha": "d9bdfbab9f35095db2721f991a3418f58f997a56", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.9760348584, "max_line_length": 650, "alphanum_fraction": 0.682274817, "num_tokens": 9417, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7606452268564325}}
{"text": "% !TEX root = index.tex\n\\section{Rank \\& Nullity}\n  We saw that matrices encode linear transformations between Euclidean spaces.\n  A matrix of size $\\ell \\times k$ ( having $\\ell$ rows and $k$ columns ) can multiply a vector of size $k$ to get a vector of size $\\ell$.\n\n  \\begin{align*}\n    A : \\bbr^k &\\longrightarrow \\bbr^\\ell \\\\\n    \\vec{v} &\\longmapsto A \\vec{v}\n  \\end{align*}\n\n  \\begin{align}\n    \\label{equation:matrixMult}\n    \\begin{bmatrix}\n      A_{11} & A_{12} & \\cdots & A_{1k} \\\\\n      A_{21} & A_{22} & \\cdots & A_{2k} \\\\\\\\\n      \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n      A_{\\ell 1} & A_{\\ell 2} & \\cdots & A_{\\ell k}\n    \\end{bmatrix}\n    \\begin{bmatrix} v_1 \\\\ v_2 \\\\ \\vdots \\\\ v_k \\end{bmatrix}\n      &=\n      v_1 \\begin{bmatrix}\n        A_{11} \\\\\n        A_{21} \\\\\\\\\n        \\vdots \\\\\\\\\n        A_{\\ell 1}\n      \\end{bmatrix}\n      + v_2 \\begin{bmatrix}\n        A_{12} \\\\\n        A_{22} \\\\\\\\\n        \\vdots \\\\\\\\\n        A_{\\ell 2}\n      \\end{bmatrix}\n      + \\dots +\n      v_k \\begin{bmatrix}\n        A_{1k} \\\\\n        A_{2k} \\\\\\\\\n        \\vdots \\\\\\\\\n        A_{\\ell k}\n      \\end{bmatrix}\n      \\\\\\nonumber\\\\\\nonumber\n      &=\n      \\begin{bmatrix}\n        A_{11} v_1  + A_{12} v_2 + \\cdots + A_{1k} v_k \\\\\n        A_{21} v_1 + A_{22} v_2 + \\cdots + A_{2k} v_k \\\\\\\\\n        \\vdots \\\\\\\\\n        A_{\\ell 1} v_1 + A_{\\ell 2} v_2+ \\cdots + A_{\\ell k} v_k\n      \\end{bmatrix}\\\\\\nonumber\\\\\n      \\nonumber\n      \\left[\\mbox{size }\\ell \\times k \\right]\n      \\cdot \\left[\\mbox{size } k \\right]\n      &=\n      \\left[\\mbox{size } \\ell \\right] \\\\\\nonumber\n  \\end{align}\n\n  % Another way to visualize the same formula is by taking the ``dot'' product of the $i^{th}$ column of the matrix $A$ with the vector $\\vec{v}$.\n  % \\begin{equation}\\label{eq:appendrow}\n  %   \\left[ \\begin{array}{cccc}\n  %         A_{11} & A_{12} & \\cdots & A_{1n} \\\\\n  %         \\colorbox{green}{$A_{21}$} & \\colorbox{green}{$A_{22}$} & \\cdots & \\colorbox{green}{$A_{2n}$} \\\\\n  %         \\vdots & \\vdots & \\ddots & \\vdots \\\\\n  %         A_{m1} & A_{m2} & \\cdots & A_{mn}\n  %       \\end{array}\\right]\n  %   \\left[  \\begin{array}{c}\n  %             \\colorbox{green}{$v_1$} \\\\\n  %             \\colorbox{green}{$v_2$} \\\\\\\\\n  %             \\vdots \\\\\\\\\n  %             \\colorbox{green}{$v_n$}\n  %           \\end{array} \\right]\n  %         =\n  %   \\left[      \\begin{array}{c}\n  %               A_{11} v_1 + A_{12} v_2 + \\dots + A_{1n} v_n \\\\\n  %               \\colorbox{green}{$A_{21} v_1 + A_{22} v_2 + \\dots + A_{2n} v_n$} \\\\\n  %               \\vdots \\\\\n  %               A_{m1} v_1 + A_{m2} v_2 + \\dots + A_{mn} v_n\n  %             \\end{array} \\right]\n  % \\end{equation}\n\n\\begin{qbox}\n  Using equation \\eqref{equation:matrixMult}, check that the $i^{th}$ column of the matrix $A$ is exactly the vector $A\\vec{e}_i$.\n\\end{qbox}\n\n\\begin{qbox}[Practice problems]\n  Compute $A \\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}$ for each of the following matrices.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 1 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 1 & 1 & 0\\end{bmatrix}$\n      \\item $\\begin{bmatrix} 1 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 1 & 1 & 1\\end{bmatrix}$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\\subsection{Linear systems}\nA \\emph{linear system} (of $\\ell$ equations in $k$ variables) is a collection of linear\\footnote{Linear = degree 1 = only addition and scalar multiplication.} equations.\n\\begin{align}\n  \\label{equation:generalLinearSystem}\n  \\begin{split}\n    A_{11} x_1  + A_{12} x_2 + \\cdots + A_{1k} x_k &= \\alpha_1 \\\\\n    A_{21} x_1  + A_{22} x_2 + \\cdots + A_{2k} x_k &= \\alpha_2 \\\\\n    \\vdots \\\\\n    A_{\\ell 1} x_1 + A_{\\ell 2} x_2+ \\cdots + A_{\\ell k} x_k &= \\alpha_\\ell\n  \\end{split}\n\\end{align}\nwhere $A_{ij}$'s and $\\alpha_i$'s are real numbers, and $x_i$'s are the variables we are solving for.\nBy equation \\eqref{equation:matrixMult} this is the same as\n\\begin{align*}\n  \\begin{bmatrix}\n    A_{11} & A_{12} & \\cdots & A_{1k} \\\\\n    A_{21} & A_{22} & \\cdots & A_{2k} \\\\\\\\\n    \\vdots & \\vdots & \\ddots & \\vdots \\\\\\\\\n    A_{\\ell 1} & A_{\\ell 2} & \\cdots & A_{\\ell k}\n  \\end{bmatrix}\n  \\begin{bmatrix} x_1 \\\\ x_2 \\\\ \\vdots \\\\ x_k \\end{bmatrix}\n    &=\n  \\begin{bmatrix} \\alpha_1 \\\\ \\alpha_2 \\\\\\\\ \\vdots \\\\\\\\ \\alpha_\\ell \\end{bmatrix}\n    \\\\\\\\\n  A \\vec{x}\n  &= \\vec{\\alpha}\n\\end{align*}\n\nThus matrices encode not only the linear transformations but also linear systems. This observation allows us to study linear systems using techniques from linear algebra.\n\n\n\\subsubsection{Image}\n\\begin{definition}\n  Let $A$ be a matrix of size $\\ell \\times k$.\n  The \\emph{image} of a matrix $A$ is simply the image of the corresponding linear transformation $A:\\bbr^k \\rightarrow \\bbr^\\ell$ i.e. it is the set of all vectors $\\vec{y} \\in \\bbr^\\ell$ such that $A \\vec{x} = \\vec{y} $ for some $\\vec{x} \\in \\bbr^k$.\n  \\begin{align*}\n    \\im(A) = \\{ A \\vec{x} \\mid \\vec{x} \\in \\bbr^k \\}\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}\n  Show that the $\\im(A)$ is a subspace of $\\bbr^\\ell$.\n\\end{qbox}\n\n\\begin{definition}\n  The dimension of $\\im(A)$ is called the \\emph{rank} of $A$.\n  \\begin{align*}\n    \\rank A := \\dim \\im (A)\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}\n  Check that equation \\eqref{equation:generalLinearSystem} having a solution is the same as saying that $\\vec{\\alpha}$ is in the image of $A$.\n\\end{qbox}\n\n\\begin{qbox}\n  Using \\eqref{equation:matrixMult}, show that $\\im(A)$ is precisely the span of the column vectors of $A$.\n\\end{qbox}\n\nCombining all the above statements we get,\n\\begin{theorem}\n  The equation \\eqref{equation:generalLinearSystem} has a solution if and only if the vector $\\vec{\\alpha}$ is in the vector space spanned by the column vectors of $A$.\n\\end{theorem}\n\nFinding the image i.e. the span of column vectors in general is non-trivial. However, there is a very fast algorithm called Gaussian elimination for computing it.\n\n\\begin{qbox}\n  \\label{q:rankComputation1}\n  Find rank of each of the following matrices.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 1 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 1 & 1 & 0\\end{bmatrix}$\n      \\item $\\begin{bmatrix} 1 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 1 & 1 & 1\\end{bmatrix}$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\\begin{qbox}(Do this problem if you have done the section on linear transformations.)\n  \\label{q:rankComputation2}\n  Using geometry, find rank of each of the following matrices.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $[\\id_{\\bbr^2}]$\n      \\item $[\\rot]$\n      \\item $[\\refl]$\n      \\item $[\\proj]$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\n\n\n\n\n\n\n\n\n\n\\subsubsection{Kernel}\nOnce we know a solution exists, we can ask - what is the number of solutions? In general, there can be infinitely many solutions, but the dimension of the solution space is finite. This dimension is called the nullity.\n\\begin{definition}\n  The \\emph{kernel} of a matrix $A$ is the set of vector $\\vec{x} \\in \\bbr^k$ such that $A \\vec{x} = 0$.\n  \\begin{align*}\n    \\ker A := \\{ \\vec{x} \\mid A \\vec{x} = \\vec{0} \\} \\subseteq \\bbr^k\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}\n  Prove that $\\ker A$ is a subspace of $\\bbr^k$.\n\\end{qbox}\n\n\\begin{definition}\n  The \\emph{nullity} of $A$ is the dimension of $\\ker A$.\n  \\begin{align*}\n    \\nul A := \\dim \\ker (A)\n  \\end{align*}\n\\end{definition}\n\n\\begin{qbox}\n  \\label{q:nullityComputation1}\n  Find nullity of each of the following matrices.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 1 & 1 \\\\ 1 & 1 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 1 & 1 & 0\\end{bmatrix}$\n      \\item $\\begin{bmatrix} 1 & 0 & 1 \\end{bmatrix}$\n      \\item $ \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 1 & 1 & 1\\end{bmatrix}$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\\begin{qbox}(Do this problem if you have done the section on linear transformations.)\n  \\label{q:nullityComputation2}\n  Using geometry, find nullity of each of the following matrices.\n  \\begin{multicols}{2}\n    \\begin{enumerate}\n      \\item $[\\id_{\\bbr^2}]$\n      \\item $[\\rot]$\n      \\item $[\\refl]$\n      \\item $[\\proj]$\n    \\end{enumerate}\n  \\end{multicols}\n\\end{qbox}\n\n\\begin{qbox}\n  Consider a matrix $A$ of size $\\ell \\times k$ and a vector $\\vec{\\alpha} \\in \\bbr^\\ell$.\n  \\begin{enumerate}\n    \\item Show that if $\\vec{x}_1$, $\\vec{x}_2$ are solutions of $A \\vec{x} = \\vec{\\alpha}$ then $\\vec{x}_1 - \\vec{x}_2$ is a solution of $A \\vec{x} = \\vec{0}$.\n    \\item Show that if $\\vec{x}_1$ is a solution of $A \\vec{x} = \\vec{\\alpha}$ and $\\vec{x}_0$ is a solution of $A \\vec{x} = \\vec{0}$ then $\\vec{x}_1 + \\vec{x}_0$ is also a solution of $A \\vec{x} = \\vec{\\alpha}$.\n  \\end{enumerate}\n\\end{qbox}\n\n\nCombining everything above we have the following fundamental theorem about the solution space of the system of equations.\n\\begin{theorem}\n  \\label{theorem:dimensionSolutionSpace}\n  Let $A$ be a matrix of size $\\ell \\times k$ and let $\\vec{\\alpha}$ be a vector in $\\bbr^\\ell$.\n  \\begin{enumerate}\n    \\item The linear system $A \\vec{x} = \\vec{\\alpha}$ has a solution if an only if $\\vec{\\alpha}$ is in $\\im A$.\n    \\item If a solution exists, then the space of solutions has dimension\\footnote{This is not strictly correct as the space of solutions of $A \\vec{x} = \\vec{\\alpha}$ is not a vector space if $\\alpha \\neq 0$. Instead, we need to shift the space of solutions to the origin to make it a vector space. This is analogous to the fact that a line not passing through the origin is not a vector space, but we can shift it to the origin to make it one. Once shifted, the space of solutions becomes $\\ker A$.} $\\nul A$.\n  \\end{enumerate}\n\\end{theorem}\n\n\\begin{corollary}\n  If $\\nul A = 0$ then $A \\vec{x} = \\vec{\\alpha}$ has either a unique solution or no solution.\n  If $\\nul A > 0$ then $A \\vec{x} = \\vec{\\alpha}$ has either infinitely many solutions or no solution.\n\\end{corollary}\n\nOnce we know that we are looking for vector spaces we can use standard algorithms in linear algebra to find the solutions.\n\n\\begin{qbox}\n  For your computations in Questions \\ref{q:rankComputation1}, \\ref{q:rankComputation2}, \\ref{q:nullityComputation1}, and \\ref{q:nullityComputation2} what is $\\rank A + \\nul A$?\n  \\begin{align*}\n    \\rank A + \\nul A = ?\n  \\end{align*}\n\\end{qbox}\n", "meta": {"hexsha": "bc7b3aa9731e7988dcca162dd6a2d0f080ef21d9", "size": 10985, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "04.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": "04.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": "04.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": 37.3639455782, "max_line_length": 511, "alphanum_fraction": 0.5955393719, "num_tokens": 4018, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699436, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7606049310699969}}
{"text": "\\chapter{DT Fourier Series}\n\nRecall the complex exponential $z^n$ is the Eigenfunction of DT 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 DT \\emph{Fourier Series} (DTFS). The DTFS is similar, but not identical to the CTFS. Notably, the approximation requires only a finite number of terms, there are no convergence issues, and the resulting spectrum is a periodic function.\n\nRecall a DT signal $x[n]$ is periodic, with fundamental frequency $\\omega_0 = \\frac{2\\pi}{N}$ rad/sec, if $x[n] = x[n+kN]$ for integer multiple $k$ and fundamental period $N \\in \\mathbb{Z}$. As we shall see, in this case the complex base of the Eigenfunction becomes $z_k = e^{jk\\omega_0}$, and the decomposition is a finite sum. This gives the input-output relationship for a stable DT LTI system as \n\\[\nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n} \\;\\longrightarrow\\;  y[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} H\\left(e^{j k\\omega_0}\\right) a_k e^{jk\\omega_0 n} \n\\]\nwhere $H\\left(e^{j k\\omega_0}\\right)$ are the Eigenvalues or DT frequency response. We now turn to how to find the coefficients $a_k$.\n\n\\section{Synthesis and Analysis Equation}\n\nSimilar to the CTFS we wish to show that any periodic DT signal can be represented by the sum of complex exponentials whose frequencies are harmonics of the fundamental. This differs from the CTFS in that there are only $N$ distinct harmonics, so that the sum is over a finite range\n\\[  \n\\boxed{x[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n} }\n\\]\nwhere $N$ is the period and $N_0$ is any starting index for the sum. Note the course text defines $<N> = \\{ N_0, N_0 + 1,  \\cdots (N_0 + N-1) \\}$. This is called the \\emph{synthesis equation} of the DT Fourier series.\n\nOne approach to find the coefficients $a_k$ is to note that there are a finite number of terms in the summation and the signal has a finite number of values over one period. This gives a system of $N$ linear equations in $N$ unknowns (the $a_k$'s)\n\\begin{align*}\n  x[N_0] &= \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0N_0}\\\\\n  x[N_0+1] &= \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0(N_0+1)}\\\\\n  \\vdots\\hspace{2em} &= \\hspace{2em}\\vdots\\\\\n  x[N_0+N-1] &= \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0(N_0+N-1)}\\\\\n\\end{align*}\nwhich can be solved to find the coefficients using linear algebra.\n\n\\begin{example}\n  Consider the periodic DT signal $x[n] = \\cdots -1, 1, -1, 1, -1, 1, \\cdots$ where $x[0] = 1$. The period is $N=2$ so that $\\omega_0 = \\pi$. If we let $N_0 = 0$, the system of equations is\n  \\begin{align*}\n    x[0] &= \\sum\\limits_{k = 0}^{1} a_k = a_0 + a_1 = 1\\\\\n    x[1] &= \\sum\\limits_{k = 0}^{1} a_k e^{jk\\pi} = a_0 - a_1 = -1\n  \\end{align*}\n  which has the solution $a_0 = 0$ and $a_1 = 1$ and $x[n] = e^{j\\pi n}$.\\\\\n  $\\blacksquare$\n\\end{example}\n\nAnother approach is similar to that taken when deriving the CT Fourier Series. Beginning with the synthesis equation\n\\[  \nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n}\n\\]\nwe multiply both sides by $e^{-j\\frac{2\\pi r}{N} n}$ for $r \\in \\mathbb{Z}$ and sum over $N$ terms\n\\[  \n\\sum\\limits_{n = N_0}^{N_0 + N-1} x[n]e^{-j\\frac{2\\pi r}{N} n} = \\sum\\limits_{n = N_0}^{N_0 + N-1} \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n}e^{-j\\frac{2\\pi r}{N} n}\n\\]\nWe then interchange to order of summation on the right-hand-side\n\\[  \n\\sum\\limits_{n = N_0}^{N_0 + N-1} x[n]e^{-j\\frac{2\\pi r}{N} n} =  \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k \\underbrace{\\sum\\limits_{n = N_0}^{N_0 + N-1} e^{jk\\omega_0n}e^{-j\\frac{2\\pi r}{N} n}}\n\\]\nSince $\\omega_0 = \\frac{2\\pi}{N}$, the bracketed term is\n\\[\n\\sum\\limits_{n = N_0}^{N_0 + N-1} e^{j(k-r)\\frac{2\\pi}{N} n} = \\begin{cases}\n  N & \\mbox{ if } k-r = 0, \\pm N, \\pm 2N, \\cdots\\\\\n  0 & \\mbox{ else }\n\\end{cases}\n= N\\delta[(k-r) + mN] \\mbox{ for arbitrary } m \\in \\mathbb{Z}\n\\]\nand the right-hand side is\n\\[\n\\sum\\limits_{k = N_0}^{N_0 + N-1} a_k N \\delta[(k-r) + mN] = Na_r \n\\]\nsince $N_0 < mN < N_0 + 1$ for some $m$. Solving for $a_r$ gives the \\emph{analysis equation} of the DT Fourier series:\n\\[\n\\boxed{a_r = \\frac{1}{N} \\sum\\limits_{n = N_0}^{N_0+N-1} x[n]e^{-j\\frac{2\\pi}{N} r n }}\n\\]\nwhere the summation can be over any interval of length $N$ and the symbol for the subscript (integer $r$) is arbitrary. The DT Fourier Series coefficients are also called the \\emph{spectrum} of the signal. In general the $a_k$ are complex. \\emph{Note the spectrum is periodic in $N$}. 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 over a single interval of length $N$ (since it is periodic).\n\n\\begin{example}\n  A simple way to construct a DT periodic signal is to use the modulus $\\%$ operator. For example,\n  \\[\n  x[n] = \\gamma^{n \\% N} \\mbox{ for any } \\gamma \\in \\mathbb{C}\n  \\]\n  is periodic in $N$, e.g. $x[n] = \\left(\\frac{1}{2}\\right)^{n \\% 4}$\n  \\begin{center}\n    \\includegraphics[scale=1]{graphics/dtfs_example1.pdf}\n  \\end{center}\n\n  The synthesis equation is given by\n  \\[\n  x[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n}\n  \\]\n  Where the coefficients are found using the analysis equation. Let $N_0 = 0$ arbitrarily, then\n  \\begin{align*}\n    a_k &= \\frac{1}{N} \\sum\\limits_{n = 0}^{N-1} x[n]e^{-j\\frac{2\\pi}{N} k n }\\\\\n    &= \\frac{1}{N} \\sum\\limits_{n = 0}^{N-1} \\gamma^n e^{-j\\frac{2\\pi}{N} k n }\\\\\n    &= \\frac{1}{N} \\sum\\limits_{n = 0}^{N-1} \\left(\\gamma e^{-j\\frac{2\\pi}{N} k}\\right)^n\\\\\n    a_k &= \\frac{1}{N} \\frac{1-\\left(\\gamma e^{-j\\frac{2\\pi}{N} k}\\right)^N}{1-\\left(\\gamma e^{-j\\frac{2\\pi}{N} k}\\right)}\n  \\end{align*}\n\nWe can plot the spectrum of this signal (using for example Matlab)\n\\begin{verbatim}\ngamma = 0.5;\nN = 4;\nk = -10:10;\na = (1-(gamma*exp(-j*2*pi*k/N)).^N)./(N*(1-gamma*exp(-j*2*pi*k/N)));\n\nh0 = subplot(2,1,1);\nh1 = stem(k, abs(a));\nh2 = xlabel('k');\nh3 = ylabel('|a(k)|');\nh4 = title('Amplitude Spectrum');\nh5 = subplot(2,1,2);\nh6 = stem(k, angle(a));\nh7 = xlabel('k');\nh8 = ylabel('Angle a(k)');\nh9 = title('Phase Spectrum');\n\\end{verbatim}\nGiving the amplitude and phase spectrum plot\n\\begin{center}\n\\includegraphics[scale=0.7]{graphics/dtfs_example1.png}\n\\end{center}\n$\\blacksquare$\n\\end{example}\n\n\\begin{example}\n  Find the DTFS of $x[n] = \\cos[\\tfrac{\\pi}{4}n]$. Note $N=8$ and $\\omega_0 = \\tfrac{\\pi}{4}$. Using Euler's formula\n  \\[\n  x[n] = \\frac{1}{2}e^{j\\frac{\\pi}{4}n} + \\frac{1}{2}e^{-j\\frac{\\pi}{4}n}\n  \\]\n  The synthesis equation is\n  \\[\n  x[n] = \\sum\\limits_{k = 0}^{N-1} a_k e^{jk\\omega_0n} = a_0 + a_1e^{j\\frac{\\pi}{4}n}+ a_2e^{j\\frac{2\\pi}{4}n} + \\cdots + a_7e^{j\\frac{7\\pi}{4}n}  \n  \\]\n  Comparing to the expansion above and noting that $e^{-j\\frac{\\pi}{4}n} = e^{j\\frac{7\\pi}{4}n}$ we see that\n  \\[\n  a_k = \\begin{cases}\n    \\frac{1}{2} & k=1\\\\\n    \\frac{1}{2} & k=7\\\\\n    0 & \\mbox{else}\n  \\end{cases}\n  \\]\n  for $k \\in [0,7]$ and $a_k = a_{k\\%8}$ for all $k$.\\\\\n  $\\blacksquare$\n\\end{example}\n\n\\section{Properties of the DT Fourier Series}\n\nGiven two signals $x[n]$ and $y[n]$ periodic in $N$ with $\\omega_0 = \\frac{2\\pi}{N}$, having DT Fourier coefficients\n$a_k$ and $b_k$ respectively.\n\n\\begin{itemize}\n\\item Linearity. The coefficients of the signal\n  \\[\n  z[n] = Ax[n] + By[n] \\mbox{ for constants } A,B \n  \\]\n  are $Aa_k + Bb_k$\n\\item Index Shifting. The coefficients of\n  \\[\n  z[n] = x[n-n_0] \\mbox{ are } e^{-jk\\omega_0 n_0}a_k\n  \\]\n  that is, it adds a phase shift.\n\\item Frequency Shift. The coefficients of\n  \\[\n  z[n] = x[n]e^{jm\\omega_0n} \\mbox{ are } a_{k-m}\n  \\]\n\\item Index Reversal. The coefficients of\n  \\[\n  z[n] = x[-n] \\mbox{ are } a_{-k}\n  \\]\n\\item Multiplication. The coefficients of\n  \\[\n  z[n] = x[n] \\cdot y[n] \\mbox{ are } \\sum\\limits_{m = N_0}^{N_0 + N -1} a_m\\cdot b_{k-m}\n  \\]\n  the discrete convolution of the individual signals' coefficients.\n\\item Convolution. The coefficients of\n  \\[\n  z[n] = x[n] * y[n] \\mbox{ are } N a_k b_k\n  \\] \n\\item Conjugate Symmetry. The coefficients of\n  \\[\n  z[n] = x^*[n] = \\Re{x[n]} - j\\Im{x[n]} \\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$. Thus if $x[n]$ is real  $|a_k|$ is an even periodic function of $k$ and $\\angle a_k$ is an odd periodic function of $k$. \n\\item Parseval's Relation. The power of the signal with Fourier series coefficients is\n  \\[\n  \\frac{1}{N} \\sum\\limits_{n = N_0}^{N_0 + N -1} |x[n]|^2\\;dt = \\sum\\limits_{k = N_0}^{N_0+N-1} |a_k|^2\n  \\]\n\\end{itemize}\n\n\n\\section{Comparison of CT and DT Fourier Series}\nA summary of the CT and DT Fourier Series is as follows.\\\\\n\nIn CT, a periodic signal $x(t)$ can be decomposed as a countably infinite combination of complex sinusoids at harmonic frequencies of the fundamental. The Fourier series coefficients are a discrete signal that is a-periodic.\n\n\\[\nx(t) \\approx \\sum\\limits_{k = -\\infty}^{\\infty} a_k \\, e^{j k\\omega_0 t}\n\\hspace{2em}\na_k = \\frac{1}{T_0} \\int\\limits_{0}^{T_0} x(t)e^{-jk\\omega_0 t} \\; dt\n\\]\n\nIn DT, a periodic signal $x[n]$ can be decomposed as a finite combination of complex sinusoids at harmonic frequencies of the fundamental. The Fourier series coefficients are a discrete signal that is periodic.\n\n\\[  \nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N-1} a_k e^{jk\\omega_0n}\n\\hspace{2em}\na_k = \\frac{1}{N} \\sum\\limits_{n = N_0}^{N_0+N-1} x[n]e^{-j\\frac{2\\pi}{N} k n }\n\\]\n", "meta": {"hexsha": "4946d457a4d61394bddc8e31d29592f557fdeb53", "size": 9641, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-dtfs.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": "15-dtfs.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": "15-dtfs.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": 48.4472361809, "max_line_length": 580, "alphanum_fraction": 0.6477543823, "num_tokens": 3648, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.8807970764133561, "lm_q1q2_score": 0.7604728182490176}}
{"text": "\\documentclass[./main.tex]{subfiles}\n\n\\usepackage{amsmath}\n\\usepackage{mathtools}\n\n\\begin{document}\n\n\\chapter{Algebraic solution to the multilateration problem}\n\n\\section{Solution based on three reference point}\nGiven are the three reference points $P_1(x_1, y_1, z_1)$, $P_2(x_2, y_2, z_2)$, $P_3(x_3, y_3, z_3)$ and the range measurements $s_1$, $s_2$, $s_3$ to point $N(x,y,z)$, the location $(x,y,z)$ of $N$ is the solutions of the following system of quadratic equations:\n\n\\begin{equation}\n    \\begin{dcases*}\n        (x-x_1)^2 + (y-y_1)^2 + (z-z_1)^2 = s_1^2 \\\\\n        (x-x_2)^2 + (y-y_2)^2 + (z-z_2)^2 = s_2^2 \\\\\n        (x-x_3)^2 + (y-y_3)^2 + (z-z_3)^2 = s_3^2 \n    \\end{dcases*}\n    \\label{eqn:three_ref_point_localization}\n\\end{equation}\n\n\\ref{eqn:three_ref_point_localization} can be arranged as:\n\n\\begin{equation}\n    \\begin{dcases*}\n        (x^2 + y^2 + z^2) -2x_1x - 2y_1y - 2z_1z = s_1^2 - x_1^2 - y_1^2 - z_1^2 \\\\\n        (x^2 + y^2 + z^2) -2x_2x - 2y_2y - 2z_2z = s_2^2 - x_2^2 - y_2^2 - z_2^2 \\\\\n        (x^2 + y^2 + z^2) -2x_3x - 2y_3y - 2z_3z = s_1^2 - x_3^2 - y_3^2 - z_3^2\n    \\end{dcases*}\n    \\label{eqn:three_ref_point_localization}\n\\end{equation}\nOr in the matrix representation:\n\n\\begin{equation}\n    \\begin{bmatrix}\n        1 & -2x_1 & -2y_1 & -2z_1\\\\\n        1 & -2x_2 & -2y_2 & -2z_2\\\\\n        1 & -2x_3 & -2y_3 & -2z_3\n    \\end{bmatrix}\n    \\begin{bmatrix}\n        x^2 + y^2 + z^2\\\\\n        x\\\\\n        y\\\\\n        z\\\\\n    \\end{bmatrix}\n    =\n    \\begin{bmatrix}\n        s_1^2 - x_1^2 - y_1^2 - z_1^2\\\\\n        s_2^2 - x_2^2 - y_2^2 - z_2^2\\\\\n        s_1^2 - x_3^2 - y_3^2 - z_3^2\\\\\n    \\end{bmatrix}\n    \\label{eqn:three_ref_point_localization_matrix}\n\\end{equation}\nThus, \\ref{eqn:three_ref_point_localization_matrix} is represented in the known form:\n\\begin{equation}\n    \\mathbf{A}_0 \\mathbf{x}=\\mathbf{b}_0\n    \\label{eqn:three_ref_point_localization_general_form}\n\\end{equation}\nWith the constraint: $\\mathbf{x} \\in \\mathbf{E}$\\\\\nWhere $\\mathbf{E}=\\{(x_0, x_1, x_2, x_3)^T / x_0 = x_1^2 + x_2^2 + x_3^2 \\}$\n\\subsection{Solution of equation \\ref{eqn:three_ref_point_localization_general_form}}\n\n\\end{document}", "meta": {"hexsha": "53c1e56b858043c196200c84524d5b7e076b5bf6", "size": 2147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/trash/algebraic_solution_mutilateration_problem.tex", "max_stars_repo_name": "tuannv0898/uwb-ips", "max_stars_repo_head_hexsha": "656725bfbb45eae48127733b7c4a96736bfacf84", "max_stars_repo_licenses": ["MIT"], "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/trash/algebraic_solution_mutilateration_problem.tex", "max_issues_repo_name": "tuannv0898/uwb-ips", "max_issues_repo_head_hexsha": "656725bfbb45eae48127733b7c4a96736bfacf84", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-13T16:22:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-13T16:22:55.000Z", "max_forks_repo_path": "reports/trash/algebraic_solution_mutilateration_problem.tex", "max_forks_repo_name": "tuannv0898/uwb-ips", "max_forks_repo_head_hexsha": "656725bfbb45eae48127733b7c4a96736bfacf84", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-14T02:31:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-14T02:31:16.000Z", "avg_line_length": 34.0793650794, "max_line_length": 264, "alphanum_fraction": 0.6110852352, "num_tokens": 944, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8418256432832332, "lm_q1q2_score": 0.7604162266325102}}
{"text": "\\subsection{Probabilistic modelling} \\label{section:probabilistic_modelling}\n\nA scientific model is a simple theoretical representation of a complex natural phenomenon to allow the systematic study of its behaviour. The general idea is that if a model is able to explain some observations, it might be capturing its true underlying laws and can therefore be used to make future predictions.\nIn particular, statistical models are a powerful abstraction of nature. They consist of a set of observed variables and a set of (hidden) parameters. The procedure of fitting the parameters using a set of observations is called inference or learning.\n\nOne of the major challenges of inference when dealing with real datasets is the distinction between signal and noise. An ideal model should learn only the information relevant to gain explanatory power while disregarding the noise. However, this is a non-trivial task in most practical situations. Very complex models will tend to overfit the training data, capturing large amounts of noise and consequently leading to a bad generalisation performance to independent datasets. On the other hand, simplistic models will fit the data poorly, resulting in low explanatory power.\n\nThe ideas above can be formalised using the framework of probability and statistics.\n\n\\subsection{Maximum likelihood inference} \\label{section:maximum_likelihood}\n\nA common approach is to define a statistical model of the data $\\bfY$ with a set of parameters $\\btheta$ that define a probability distribution $p(\\bfY|\\btheta)$, called the likelihood function. A simple approach to fit a model is to estimate the parameters $\\hat{\\btheta}$ that maximise the likelihood:\n\\[\n\t\\hat{\\btheta} = \\argmax_{\\btheta} p(\\bfY|\\btheta)\n\\]\nThis process is called maximum likelihood learning \\cite{Stigler2008,Bishop2006,Murphy}. However, in this setting there is no penalisation for model complexity, making maximum likelihood solutions can overfit when the data is relatively sparse. Generalisations that account for model complexity have been proposed that include regularising terms that shrink parameters to small values. However, these are often particular cases of the more general framework of Bayesian statistics \\cite{Hastie,Bishop2006,Murphy}.\n\n\\subsection{Bayesian inference}  \\label{section:bayesian_inference}\nIn the Bayesian framework, the parameters themselves are treated as random unobserved variables and we aim to obtain probability distributions for $\\btheta$, rather than a single point estimate. To do so, prior beliefs are introduced into the model by specifying a prior probability distribution $p(\\btheta)$. Then, using Bayes' theorem \\cite{Bayes1763}, the prior hypothesis is updated based on the observed data $\\bfY$ by means of the likelihood $p(\\bfY|\\btheta)$ function, which yields a posterior distribution over the parameters:\n\\[\n\tp(\\btheta|\\bfY) = \\frac{p(\\bfY|\\btheta) p(\\btheta)}{p(\\bfY)}\n\\]\nwhere $p(\\bfY)$ is a constant term called the marginal likelihood, or model evidence \\cite{Bishop2006,Murphy}.\\\\\nThe choice of the prior distribution is a key part of Bayesian inference and captures beliefs about the distribution of a variable before the data is taken into account. With asymptotically large sample sizes, the choice of prior has negligible effects on the posterior estimates, but it becomes critical with sparse data \\cite{Bishop2006,Murphy,Gelman2013}.\n\nThere are two common considerations when defining the prior distributions. The first relates to the incorporation of subjective information, or predefined assumptions, into the model. For example, one could adapt the prior distribution to match the results from previous experiments (i.e. an informative prior). Alternatively, if no prior information is available one could set set uninformative priors by following maximum entropy principles \\cite{Jaynes1968}.\n\nThe second strategy is based on convenient mathematical properties to make inference tractable. If the likelihood and the prior distributions do not belong to the same family of probability distributions (they are not conjugate) then inference becomes more problematic \\cite{Raiffa1961,Bishop2006,Murphy,Gelman2013}. The existence of conjugate priors is one of the major reasons that justify the widespread use of exponential family distributions in Bayesian models \\cite{Gelman2013}.\n\nAgain, the essential point of Bayesian inference is that an entire posterior probability distribution is obtained for each unobserved variable. This has the clear advantage of naturally handling uncertainity in the estimation of parameters. For instance, when making predictions, a fully Bayesian approach attempts to integrate over all possible values of all unobserved varaibles, effectively propagating uncertainity across multiple layers of the model. Nevertheless, this calculation is sometimes intractable and one has to resort to point estimates \\cite{Bishop2006,Murphy,Gelman2013}. The simplest approximation to the posterior distribution is to use its mode, which leads to the maximum a posteriori (MAP) estimate:\n\\[\n\t\\hat{\\btheta} = \\argmax_{\\btheta} p(\\btheta) p(\\bfY|\\btheta) \n\\]\nThis is similar to the maximum likelihood objective function, but with the addition of a term $p(\\btheta)$. When the prior distribution is well chosen, this term penalises for model complexity. Therefore, in contrast to standard (non-penalised) maximum likelihood inference, Bayesian approaches naturally handle the problem of model complexity and overfitting \\cite{Bishop2006,Murphy,Gelman2013}. At the limit of infinite observations, the influence of the prior to the posterior is negligible and the MAP estimate converges towards the Maximum likelihood estimate, hence providing a rational link between the two inference frameworks.\n\n\\subsubsection{Deterministic approaches for Bayesian inference} \\label{section:deterministic_bayesian_inference}\nThe central task in Bayesian inference is the direct evaluation of the posterior distributions and/or the computation of expectations with respect to the posterior distributions. In sufficiently complex models, closed-form solutions are not available and one has to resort to approximation schemes, which broadly fall into two classes: stochastic or deterministic \\cite{Gelman2013,Blei2016}. \n\nStochastic approaches hinge on the generation of samples from the posterior distribution via a Markov Chain Monte Carlo (MCMC) framework. Such techniques have the appealing property of generating exact results at the asymptotic limit of infinite computational resources. However, in practice, sampling approaches are computationally demanding and suffer from limited scalability to large datasets \\cite{Blei2016}. \\\\\nIn contrast, deterministic approaches are based on analytical approximations to the posterior distribution, which often lead to biased results. Yet, given the appropriate settings, these approaches are potentially much faster and scalable to large applications \\cite{Bishop2006,Murphy,Blei2016}.\n\n% \\paragraph{Laplace approximation}% \\label{section:laplace_approximation}\n% The Laplace approximation is probably the simplest of the deterministic tecniques, where the aim is to construct a Gaussian approximation around the mode of the true posterior distribution using a second-order Taylor expansion \\cite{Bishop2006,Murphy}.\\\\\n% Suppose $\\bfX$ contains all unobserved variables. The true posterior distribution can be written as:\n% \\[\n% p(\\bfX) = \\frac{f(\\bfX)}{Z}\n% \\]\n% where $f(\\bfX)$ is a function that depends on the unobserved variables and $Z$ is an unknown normalisation constant to ensure that $\\int p(\\bfX) d\\bfX = 1$.\n\n% The second-order Taylor expansion of $\\log f(\\bfX)$ centered around its (known) mode $\\hat{\\bfX}$ is: \n% \\[\n% \t\\log f(\\bfX) \\approx \\log f(\\hat{\\bfX}) - \\frac{1}{2} (\\bfX-\\hat{\\bfX})^T \\bfA (\\bfX-\\hat{\\bfX})\n% \\]\n% where $\\bfA = \\nabla^2 \\log f(\\hat{\\bfX})$ is the Hessian matrix of $\\log f(\\bfX)$ evaluated at $\\hat{\\bfX}$.\\\\\n% Notice three things. First, the first-order term of the Taylor expansion is zero because $\\hat{\\bfX}$ is a stationary point. Second, the $\\log$ function is monotonically increasing and therefore a maximum of $\\log f(\\bfX)$ is also a maximum of $f(\\bfX)$. Third, the mode of the posterior $p(\\bfX)$ must be known, which requires the use of (complex) optimisation algorithms.\\\\\n% Taking the exponential in both sides:\n% \\[\n% \tf(\\bfX) \\approx f(\\hat{\\bfX}) \\exp\\{ -\\frac{1}{2} (\\bfX-\\hat{\\bfX})^T \\bfA (\\bfX-\\hat{\\bfX}) \\}\n% \\]\n% which leads to the following multivariate Gaussian distribution approximation $q(\\bfX) = \\Ndist{\\bfX}{\\hat{\\bfX},\\bfA}$:\n% \\[\n% \tq(\\bfX) = \\frac{\\mid A \\mid^{1/2}}{(2\\pi^{d/2})} \\exp\\{ -\\frac{1}{2} (\\bfX-\\hat{\\bfX})^T \\bfA (\\bfX-\\hat{\\bfX}) \\}\n% \\]\n% where $d$ is the number of unobserved variables. \\\\\n% Despite its simplicity, the Laplace approximation is a useful strategy that has been successfully applied in practice. Nonetheless, this approximation has notable caveats: first, is limited by its own local definition, ignoring all the density beyond the mode of the posterior. Second, it does not apply to discrete variables. Third, the inversion of the Hessian is very expensive in high-dimensional settings.\n% \t% More sophisticated generalisations of the Laplace approximation have also been proposed \\cite{Rue2009}\n% \t% To-do: check where does the inverse appear\n\n\\subsection{Variational inference}  \\label{section:variational_inference}\n\nVariational inference is a deterministic family of methods that have been receiving widespread attention due to a positive balance between accuracy, speed, and ease of use \\cite{Blei2016, Zhang2017}. The core framework is derived below.\n\nIn variational inference the true (but intractable) posterior distribution $p(\\bfX|\\bfY)$ is approximated by a simpler (variational) distribution $q(\\bfX|\\bTheta)$ where $\\bTheta$ are the corresponding parameters. The parameters, which we will omit from the notation, need to be tuned to obtain the closest approximation to the true posterior.\\\\\nThe distance between the true distribution and the variational distribution is calculated using the KL divergence:\n\\[\n\\KL(q(\\bfX)||p(\\bfX|\\bfY)) = - \\int q(\\bfX) \\log \\frac{p(\\bfX|\\bfY)}{q(\\bfX)} d\\bfX\n\\]\nNote that the KL divergence is not a proper distance metric, as it is not symmetric. In fact, using the reverse KL divergence $\\KL(q(\\bfX)||p(\\bfY|\\bfX))$ defines a different inference framework called expectation propagation \\cite{Minka2001}.\n\nIf we allow any possible choice of $q(\\bfX)$, then the minimum of this function occurs when $q(\\bfX)$ equals the true posterior distribution $p(\\bfX|\\bfY)$. Nevertheless, since the true posterior is intractable to compute, this does not lead to any simplification of the problem. Instead, it is necessary to consider a restricted family of distributions $q(\\bfX)$ that are tractable to compute and subsequently seek the member of this family for which the KL divergence is minimised.\n\nDoing some calculus it can be shown (see \\cite{Bishop2006,Murphy}) that the KL divergence $\\KL(q(\\bfX)||p(\\bfX|\\bfY))$ is the difference between the log of the marginal probability of the observations $\\log(\\bfY)$ and a term $\\Lagr(\\bfX)$ that is typically called the Evidence Lower Bound (ELBO):\n\\[\n\t\\KL(q(\\bfX)||p(\\bfX|\\bfY)) = \\log p(\\bfY) - \\Lagr(\\bfX)\n\\]\nHence, minimising the KL divergence is equivalent to maximising $\\Lagr(\\bfX)$ (\\Cref{fig:ELBO}):\n\\begin{align} \\label{eq_elbo1} \\begin{split}\n\t\\Lagr(\\bfX) &= \\int q(\\bfX) \\Big( \\log \\frac{p(\\bfX|\\bfY)}{q(\\bfX)} + \\log p(\\bfY) \\Big) d\\bfX \\\\\n\t%&= \\int \\Big( q(\\bfX) \\log \\frac{p(\\bfX|\\bfY)}{q(\\bfX)} + q(\\bfX)\\log p(\\bfY) \\Big) d\\bfX\\\\\n\t%&= \\E_q [\\log p(\\bfX|\\bfY)] - \\E_q [\\log q(\\bfX)] + \\E_q [\\log p(\\bfY)] \\\\\n\t&= \\E_q [\\log p(\\bfX,\\bfY)] - \\E_q [\\log q(\\bfX)]\n\\end{split} \\end{align}\nThe first term is the expectation of the log joint probability distribution with respect to the variational distribution. The second term is the entropy of the variational distribution.\nImportantly, given a simple parametric form of $q(\\bfX)$, each of the terms in \\Cref{eq_elbo1} can be computed in closed form. In some occasions, we will use the following form for the ELBO:\n\\begin{equation} \\label{eq_elbo2}\n\t\\Lagr(\\bfX) = \\E_q [\\log p(\\bfY|\\bfX)] + (\\E_q [\\log p(\\bfX)] - \\E_q [\\log q(\\bfX)])\n\\end{equation}\nwhere the first term is the expectation of the log likelihood and the second term is the difference in the expectations of the $p$ and $q$ distributions of each hidden variable.\n\nIn conclusion, variational learning involves minimising the KL divergence between $q(\\bfX)$ and $p(\\bfX|\\bfY)$ by instead maximising $\\Lagr(\\bfX)$ with respect to the distribution $q(\\bfX)$.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.35\\linewidth]{lower_bound}\n\t\\caption{The quantity $\\Lagr(\\bfX)$ provides a lower bound on the true log marginal likelihood $\\log p(\\bfY)$, with the difference being given by the Kullback-Leibler divergence $\\KL(q||p)$ between the variational distribution $q(\\bfX)$ and the true posterior $p(\\bfX|\\bfY)$}\n\t\\label{fig:ELBO}\n\\end{figure}\n\nThere are several approaches to define $q(\\bfX)$, the two most commonly used are called (unparametric) mean-field and (parametric) fixed-form \\cite{Zhang2017,Blei2016}.\n\n\\subsubsection{Mean-field variational inference}  \\label{section:mean_field}\n\nThe most common type of variational Bayes, known as the mean-field approach, assumes that the variational distribution factorises over M disjoint groups of unobserved variables \\cite{Saul1996}:\n\\begin{equation} \\label{eq:mean_field}\n\tq(\\bfX) = \\prod_{i=1}^{M} q(\\bfx_i)\n\\end{equation}\nwhere typically all unobserved variables are assumed to be independent. Importantly, notice that no parametric assumptions were placed regarding the nature of $q(\\bfx_i)$.\n\nEvidently, in sufficiently complex models where the unobserved variables have dependencies this family of distributions do not contain the true posterior (\\Cref{fig:mean_field}). Yet, this is a key assumption to obtain an analytical inference scheme that yields surprisingly accurate results \\cite{Blei2006,Faes2011,Braun2007}.\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{mean_field}\n\t\\caption{Illustrative example of sampling from a true posterior distribution (blue) versus a fitted mean-field varaitional distribution (red) in a model with two (correlated) unobserved variables. The mean-field approximation wrongly assumes that the unobserved variables are independent.}\n\t\\label{fig:mean_field}\n\\end{figure}\n\nUsing calculus of variations (derivations can be found in \\cite{Bishop2006,Murphy}), it follows that the optimal distribution $q(\\bfX)$ that maximises the lower bound $\\Lagr(\\bfX)$ is\n\\begin{equation} \\label{eq:optimal}\n\t\\log \\hat{q}_i(\\bfx_i) = \\E_{-i} [\\log p(\\bfY,\\bfX)] + \\mathrm{const}\n\\end{equation}\nwhere $\\E_{-i}$ denotes an expectation with respect to the $q$ distributions over all variables $\\bfx_j$ except for $\\bfx_i$.\\\\\nThe additive constant is set by normalising the distribution $\\hat{q}_i(\\bfz_i)$:\n\\[\n\t\\hat{q}(\\bfx_i) = \\frac{\\exp(\\E_{-i}[\\log p(\\bfY,\\bfX)])}{\\int \\exp(\\E_{-i}[\\log p(\\bfY,\\bfX)]) d\\bfX}\n\\]\nWhile the form of $\\hat{q}(\\bfx_i)$ is not restricted to a specific parametric form, it can be shown that when using conjugate priors, the distributions $\\hat{q}_i(\\bfx_i)$ have the same functional form as the priors $\\hat{p}(\\bfx_i)$. \n%An example is shown in Appendix X, but a detailed mathematical treatment with derivations of multiple examples can be found in \\cite{Bishop2006,Murphy,Zhao2009}.\n\n\n\\subsubsection{Fixed-form variational inference}  \\label{section:fixed_form}\n\nAn alternative straightforward strategy is to directly define a parametric form for the distribution $q(\\bfX)$ with some parameters $\\bTheta$. Once the choice of $q(\\bfX)$ is made, the parameters $\\bTheta$ are optimised to minimise $\\KL(q(\\bfX)||p(\\bfX|\\bfY))$ (the variational problem):\n\\begin{align}\n\t\\hat{\\bTheta} &= \\argmin_{\\bTheta} \\KL(q(\\bfX)||p(\\bfX|\\bfY)) \\\\\n\t&= \\E[\\log(q(\\bfX)) - \\log(p(\\bfX,\\bfY))]\n\\end{align}\nNumerically optimising this function requires the evaluation of expectations with respect to $q(\\bfX)$. In closed form, this is only feasable for a limited group of variational distributions. Alternatively, one can attempt Monte Carlo approximations, but in practice this turns to be slow and leads to high-variance estimates \\cite{Braun2007,Ranganath2014,Braun2007}.\n\nTypically, one would choose this distribution to factorise over parameters and to be of the same (exponential) family as the prior $p(\\bfX)$. In such case there is a closed form coordinate-ascent scheme available, and it turns out that the fixed-form formulation is equivalent to the (non-parametric) mean-field derivation when using conjugate priors.\\\\\nUnfortunately, for generic models with arbitrary families of distributions, no closed-form variational distributions exist \\cite{Zhang2017,Blei2016}. \n\nHowever, while the parametric assumption certainly limits the flexibility of variational distributions, the advantage of this formulation is that it opens the possibility to use fast gradient-based methods for the inference procedure \\cite{Hoffman2012,Ranganath2014}.\n\n%\\paragraph{Black box variational inference}\n\n\\subsection{Expectation Propagation}  \\label{section:expectation_propagation}\n\nExpectation Propagation (EP) is another deterministic strategy with a similar philosophy as the Variational approach. It is also based on minimising the KL divergence between a variational distribution $q(\\bfX)$ and the true posterior $p(\\bfX|\\bfY)$, but while variational inference minimises $KL(p||q)$, EP maximises the reverse KL-divergence $KL(q||p)$.\n\nInterestingly, this simple difference leads to an inference scheme with strikingly different properties. This can be understood by inspecting the differences between the two KL divergence formulas:\n\nVariational inference:\n\\begin{equation} \\label{eq:kl_vb}\n\t\\KL(q(\\bfX)||p(\\bfX|\\bfY)) = - \\int q(\\bfX) \\log \\frac{p(\\bfX|\\bfY)}{q(\\bfX)}\n\\end{equation}\nExpectation propagation:\n\\begin{equation} \\label{eq:kl_ep}\n\t\\KL(p(\\bfX|\\bfY)||q(\\bfX)) = - \\int p(\\bfX|\\bfY) \\log \\frac{q(\\bfX)}{p(\\bfX|\\bfY)}\n\\end{equation}\nIn regions of $\\bfX$ where the true posterior density $p(\\bfX|\\bfY)$ is small, setting a large density for $q(\\bfX)$ has a much stronger penalisation in \\Cref{eq:kl_ep} than in \\Cref{eq:kl_vb}. Hence, EP tends to avoid areas where the density $p(\\bfX|\\bfY)$ is very low, even if it does not correspond to areas of very high-density in $p(\\bfX|\\bfY)$. In contrast, in \\Cref{eq:kl_vb} there is a strong penalty for having low-density $q(\\bfX)$ values.\\\\\nAs discussed in \\cite{Bishop2006}, the practical consequences of this duality can be observed when the posterior is multi-modal. In VI, $q(\\bfX)$ converges towards areas of high-density in $p(\\bfX|\\bfY)$, namely local optima. In contrast, EP tends to capture as much non-zero density regions from $p(\\bfX|\\bfY)$ as possible, thereby averaging across all optima. In the context of doing predictions, the VI solution is much more desirable than the EP solution, as the average of two good parameter values is not necessarily a good value itself.\\\\\nA detailed mathematical treatment of EP, including derivations for specific examples, can be found in \\cite{Bishop2006,Murphy,Minka2001}\n\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=1.0\\linewidth]{VB_vs_EP}\n\t\\caption{Illustrative comparison of Variational inference and Expectation Propagation. Shown is the (a) Density and (b) Variance of the true posterior distribution $p(\\bfX|\\bfY)$ (grey), the variational distribution (orange) and the expectation propagation distribution (green).}\n\t\\label{}\n\\end{figure}\n\n\\subsection{Conclusions}\n\nIn this section we have introduced Bayesian modelling and variational inference methods, which will be used later in this chapter.\\\\\nMore generally, variational inference is growing in popularity for the analysis of big datasets and it has been applied to a myriad of different problems, including genome-wide association studies \\cite{Carbonetto2012}, population genetics, \\cite{Raj2014}, network analysis \\cite{Sanguinetti2006} and natural language processing \\cite{Blei2003}.\n\nYet, despite its increasing success, there is significant room for improvement. First and foremost, the theoretical guarantees of variational inference are not as developed as in sampling-based MCMC schemes \\cite{Blei2016,Zhang2017,Nakajima2007}. As an example, the mean-field setting makes strong independence assumptions about the parameters.  Although it tends to be surprisingly effective, it is not clear in which applications the dependencies between the parameters are important enough that the mean-field approximation could potentially break.\\\\\nMore generally, an open research problem is understanding what are the statistical properties of the variational posterior with respect to the exact posterior \\cite{Blei2016,Zhang2017}.\n\nAs we shall demonstrate later, alternative strategies have been considered to allow some dependencies between the variables, resulting in \\textit{structured} mean-field approximations \\cite{Hoffman2014,Titsias2011}. However, they often lead to very complex (if not intractable) inference frameworks. \n\nFinally, another area of extensive research is how to extend the applicability of VI to non-conjugate models. As discussed in \\Cref{section:deterministic_bayesian_inference}, the ELBO of non-conjugate models contains intractable integrals, and setting up an inference scheme requires the use of either stochastic Monte Carlo approximations or deterministic approximations that introduce additional lower bounds \\cite{Zhang2017,Seeger2012,Khan2017}. In this thesis we follow this rationale to derive an inference framework for a model with non-Gaussian likelihoods.\n", "meta": {"hexsha": "ea809936d6b3686be8b32b4ab8034768973ba76d", "size": 21827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapter2/bayes.tex", "max_stars_repo_name": "rargelaguet/thesis", "max_stars_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 15, "max_stars_repo_stars_event_min_datetime": "2021-01-08T13:01:16.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T07:24:40.000Z", "max_issues_repo_path": "Chapter2/bayes.tex", "max_issues_repo_name": "rargelaguet/thesis", "max_issues_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Chapter2/bayes.tex", "max_forks_repo_name": "rargelaguet/thesis", "max_forks_repo_head_hexsha": "ff3f7b996710c06d6924b7e780a4a9531651a3a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-01-09T04:47:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-04T08:25:50.000Z", "avg_line_length": 113.0932642487, "max_line_length": 722, "alphanum_fraction": 0.7778897696, "num_tokens": 5439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8311430499496096, "lm_q1q2_score": 0.7604135759202423}}
{"text": "\\subsection{Fourier transform of polynomials}\nWe begin by noting that an activation\nfunction $\\sigma$, which satisfies a polynomial growth condition\n$|\\sigma(x)| \\leq C(1 + |x|)^n$ for some constants $C$ and $n$, is a\ntempered distribution. As a result, we make this assumption on our\nactivation functions in the following theorems. We briefly note that\nthis condition is sufficient, but not necessary (for instance an\nintegrable function need not satisfy a pointwise polynomial growth\nbound) for $\\sigma$ to be represent a tempered distribution.\n\n We begin by studying the convolution of $\\sigma$ with a Gaussian mollifier. Let $\\eta$ be a Gaussian mollifier\n \\begin{equation}\n  \\eta(x) = \\frac{1}{\\sqrt{\\pi}}e^{-x^2}.\n \\end{equation}\nSet $\\eta_\\epsilon=\\frac{1}{\\epsilon}\\eta(\\frac{x}{\\epsilon})$. Then consider \n\\begin{equation}\n\\label{sigma-epsilon}\n\\sigma_{\\epsilon}(x):=\\sigma\\ast{\\eta_\\epsilon}(x)=\\int_{\\mathbb{R}}\\sigma(x-y){\\eta_\\epsilon}(y)dy\n\\end{equation}\nfor a given activation function $\\sigma$.\nIt is clear that $\\sigma_{\\epsilon}\\in C^\\infty(\\mathbb{R})$. Moreover, by considering the Fourier transform (as a tempered\ndistribution) we see that\n\\begin{equation}\\label{eq_278}\n \\hat{\\sigma}_{\\epsilon} = \\hat{\\sigma}\\hat{\\eta}_{\\epsilon} = \\hat{\\sigma}\\eta_{\\epsilon^{-1}}.\n\\end{equation} \n\n\nWe begin by stating a lemma which characterizes the set of polynomials in terms of their\n Fourier transform.\n\\begin{lemma}\\label{polynomial_lemma} Given a tempered distribution\n  $\\sigma$,  the following statements are equivalent:\n\\begin{enumerate}\n\\item $\\sigma$ is a polynomial \n\\item $\\sigma_\\epsilon$ given by \\eqref{sigma-epsilon} is a polynomial for any\n  $\\epsilon>0$. \n\\item $\\text{\\normalfont supp}(\\hat{\\sigma})\\subset \\{0\\}$. \n\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n  We begin by proving that (3) and (1) are equivalent.  This follows\n  from a characterization of distributions supported at a single point\n  (see \\cite{strichartz2003guide}, section 6.3). In particular, a\n  distribution supported at $0$ must be a finite linear combination of\n  Dirac masses and their derivatives.  In particular, if\n  $\\hat{\\sigma}$ is supported at $0$, then\n  \\begin{equation}\n   \\hat{\\sigma} = \\displaystyle\\sum_{i=1}^n a_i\\delta^{(i)}.\n  \\end{equation}\n  Taking the inverse Fourier transform and noting that the inverse\n  Fourier transform of $\\delta^{(i)}$ is $c_ix^i$, we see that\n  $\\sigma$ is a polynomial. This shows that (3) implies (1), for the\n  converse we simply take the Fourier transform of a polynomial and\n  note that it is a finite linear combination of Dirac masses and\n  their derivatives.\n  \n  Finally, we prove the equivalence of (2) and (3). For this it\n  suffices to show that $\\hat{\\sigma}$ is supported at $0$ iff\n  $\\hat{\\sigma}_\\epsilon$ is supported at $0$. This follows from\n  equation \\ref{eq_278} and the fact that $\\eta_{\\epsilon^{-1}}$ is\n  nowhere vanishing.\n\\end{proof}\n\nAs an application of Lemma \\ref{polynomial_lemma}, we give a\nsimple proof of the result in the next section.   \n", "meta": {"hexsha": "fd3aaa3bdf3228bf6d36636433322a289aff38ec", "size": 3024, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/7 Deep Neural network Functions/7.4-DNN_Qualitative.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/7 Deep Neural network Functions/7.4-DNN_Qualitative.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/7 Deep Neural network Functions/7.4-DNN_Qualitative.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": 46.5230769231, "max_line_length": 123, "alphanum_fraction": 0.7294973545, "num_tokens": 856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430394931457, "lm_q2_score": 0.9149009526726545, "lm_q1q2_score": 0.7604135586395248}}
{"text": "\n\\subsection{Subgroups}\n\nA subgroup of a group is a subset of a group, which also forms a group with the same element.\n\nFor example all even numbers are a subgroup of the addition group of integers.\n\n", "meta": {"hexsha": "ee03b85468bd3369b77a491f2bf1b522f3396662", "size": 200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/groups/01-03-subgroup.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-03-subgroup.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-03-subgroup.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.0, "max_line_length": 93, "alphanum_fraction": 0.775, "num_tokens": 44, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9273632936392131, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.760338976263232}}
{"text": "\n\\subsection{The Naive Bayes classifier}\n\n\\subsubsection{Calculating the Naive Bayes estimator}\n\nWith the Naive Bayes assumption we have:\n\n\\(P(y|x_1,x_2,...,x_n)\\propto P(x_1|y)P(x_2|y)...P(x_n|y)P(y)\\)\n\nWe now choose \\(y\\) which maximises this.\n\nThis is easier to calculate, as there is less of a sample restriction.\n\nThis is used when evidence is also in classes, as the chance of any individual outcome on a continuous probability is \\(0\\).\n\n\\subsubsection{Estimating \\(P(y)\\)}\n\nWe can easily calculate \\(P(y)\\), by looking at the frequency across the sample.\n\n\\subsubsection{Estimating \\(P(x_1|y)\\)}\n\nNormally, \\(P(x_1|y)=\\dfrac{n_c}{n_y}\\), where:\n\n\\begin{itemize}\n\\item \\(n_c\\) is the number of instances where the evidence is \\(c\\) and the label is \\(y\\).\n\\item \\(n_y\\) is the number of instances where the label is \\(y\\).\n\\end{itemize}\n\n\\subsubsection{Regularising the Naive Bayes estimator}\n\nTo reduce the risk of specific probabilities being zero, we can adjust them, so that:\n\n\\(P(x_1|y)=\\dfrac{n_c+mp}{n_y+m}\\), where:\n\n\\begin{itemize}\n\\item \\(p\\) is the prior probability. If this is unknown, use \\(\\dfrac{1}{k}\\), where \\(k\\) is the number of classes.\n\\item \\(m\\) is a parameter called the equivilant sample size.\n\\end{itemize}\n\n", "meta": {"hexsha": "87e79fa7c3505dc68809222dc60cb6e9f2de8a00", "size": 1243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/supervisedNaiveBayes/01-02-naiveBayes.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/supervisedNaiveBayes/01-02-naiveBayes.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/supervisedNaiveBayes/01-02-naiveBayes.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.075, "max_line_length": 124, "alphanum_fraction": 0.7111826227, "num_tokens": 367, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8615382094310357, "lm_q1q2_score": 0.7602453240172513}}
{"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 any two nodes $x$ and $y$ in a rooted tree have a unique \\textbf{least common ancestor} $z$.\nThis simply means that there is a path $P_1$ from $z$ to $x$, and a path $P_2$ from $z$ to $y$, and that the only vertex those two paths have in common is $z$.\n(And further that there is exactly one node $z$ with this property.)\n\n\\subsection*{Solution}\n\nProof is given in two steps.\nFirst we show that any two distinct non-root nodes $x$ and $y$ in a tree have a least common ancestor $z$.\nThen, we will show that this least common ancestor is unique.\n\\begin{enumerate}\n\\item[] If $x$ and $y$ are two distinct non-root nodes, there exists paths of the form $r \\rightarrow \\cdots \\rightarrow x$ and $r \\rightarrow \\cdots \\rightarrow y$ where $r$ is the root of the tree.\nEven if there are no node in common between the two paths, node $r$ would be a common ancestor to $x$ and $y$.\nOn the other hand if the two paths have a node $z$ in common, paths $P_1$ and $P_2$ would exists from $z$ to $x$ and $y$ respectively where $P_1$ and $P_2$ have no nodes in common except $z$.\nIn this case $z$ would be the least common ancestor of $x$ and $y$.\n\\item[] Now we prove by contradiction that there is exactly one least common ancestor for nodes $x$ and $y$.\nAssume there are moer than one least common ancestors.\nThen there are at least two distinct nodes $z_1$ and $z_2$ with descendants $x$ and $y$.\nThis immediately leads to a simple loop $z_1 \\rightarrow \\cdots \\rightarrow x \\rightarrow \\cdots \\rightarrow z_2 \\rightarrow \\cdots \\rightarrow y \\rightarrow \\cdots \\rightarrow z_1$ which contradicts the definition of the tree.\nTherefore the assumption is false and least common ancestor is unique.\n\\end{enumerate}\n", "meta": {"hexsha": "89e478930b8ddebc2a85e4e95dafdb410f1fffef", "size": 2091, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw03/hw03q08.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/hw03q08.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/hw03q08.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": 69.7, "max_line_length": 227, "alphanum_fraction": 0.6948828312, "num_tokens": 558, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382094310357, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.760245322685331}}
{"text": "\\chapter{Matrix-Chain Multiplication Algorithm}\nThe objective of this challenge is to calculate the minimum amount of scalar\nmultiplications a group of matrices needs to return the complete and correct\nmatrix product. Consider three matrices $\\mathbf{A}[10][100]$, $\\mathbf{B}[100]\n[5]$, and $\\mathbf{C}[5][50]$. There are two ways to multiply these matrices:\n\\begin{enumerate}\n\\item $(\\mathbf{A}\\times\\mathbf{B})\\times\\mathbf{C}$: $\\mathbf{A}\\times\n    \\mathbf{B}$ requires $10\\times100\\times5=5000$ scalar multiplications.\n    $\\mathbf{AB}\\times\\mathbf{C}$ requires $10\\times5\\times50=2500$. Therefore\n    the total amount of scalar multiplications is $5000+2500=7500$.\n\\item $\\mathbf{A}\\times(\\mathbf{B}\\times\\mathbf{C})$: $\\mathbf{B}\\times\n    \\mathbf{C}$ requires $100\\times5\\times50=25000$ scalar multiplications.\n    $\\mathbf{A}\\times\\mathbf{BC}$ requires $10\\times100\\times50=50000$.\n    Therefore the total amount of scalar multiplications is $25000+50000=75000$.\n\\end{enumerate}\n\nGiven a chain of $n$ matrices and an integer array of $n+1$ elements where each\nmatrix $\\mathbf{A_i}$ shows the dimesion of $\\left(p_{i-1},~p_i\\right)$, the\nfollowing solutions are algorithms that minimise scalar multiplication amounts.\n\n\\section{Optimal Solution}\n\\imb[4][26]{\\alg/matrixchain.cpp}\n\nMatrix chain multiplication has $T(n)=\\Theta\\left(n^2\\right)$ subproblems, each\nfeaturing no more than $n-1$ choices. Therefore the time complexity of this\nalgorithm is: \\[ T(n)=\\Theta\\left(n^3\\right) \\]\n", "meta": {"hexsha": "95bc43706d6a340cb38081b877838786047b8f0c", "size": 1494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/09_matrixchain.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/09_matrixchain.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/09_matrixchain.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": 55.3333333333, "max_line_length": 80, "alphanum_fraction": 0.7416331995, "num_tokens": 454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942348544447, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7602336043314489}}
{"text": "\\chapter{The Basics of Maximum Likelihood Estimation \\label{chapter:mlebasics}}\n\nBeneath our discussions of classification, regression, and probability distributions in Chapters~\\ref{chapter:classification}, \\ref{chapter:regression}, and \\ref{chapter:probabilitydistributions} lies the tricky problem of \\textbf{model fitting}. We've seen what classification and regression models look like, but we still haven't addressed how to fit these models using training data.\n\nLinear and logistic regression models are fit using a technique called \\textbf{maximum likelihood (ML) estimation}, in which the model parameters are adjusted to maximize the joint probability of the observed data, or likelihood, given the model. \n\nFor example, consider the five different datasets from Question~\\ref{question:likexamples}. In each case, you have some data and an assumption about which probability distribution the data are drawn from. The job of maximum likelihood estimation is to use the data to identify the correct distributional parameters, such as $\\mu$ and $\\sigma$ (in the case of the normal distribution) or $\\lambda$ (in the case of the Poisson distribution). This process is a type of \\textbf{statistical inference}. \n\n\\section{The Likelihood and Log-Likelihood}\n\nLet $p(x|\\theta)$ be the probability distribution that governs our data. Here, $\\theta$ stands in for all of the parameters we want to fit. \n\nIf we draw independent\\footnote{Independent sampling just means that the values of different samples do not depend on each other. When the samples are drawn independently from the same distribution, their joint probability density is just the product of the individual probability densities (which are all the same).} samples from $p(x|\\theta)$, the {\\bf joint probability density function} for all $n$ observations is:\n$$ p(x^{(1)}, x^{(2)}, \\dots, x^{(n)}|\\theta) = \\prod_{i=1}^n p(x^{(i)}|\\theta). $$\nSince the data are known but the parameter(s) $\\theta$ are unknown, we will view this quantity as a function of $\\theta$. This is just a change in notation:\n$$ \\mathcal{L}(\\theta) = \\prod_{i=1}^n p(x^{(i)}|\\theta). $$\n\nThe higher the joint probability of the data (the more ``likely'' the data are) given $\\theta$, the higher the value of this function. We call $\\mathcal{L}(\\theta)$ the \\textbf{likelihood}\\footnote{The distributions we have discussed so far are from a broad family of probability distributions called the {\\bf exponential family}. One of the properties of this family is that the log-likelihood is concave. Practically speaking, this means that if we maximize the log-likelihood by setting derivatives equal to zero, we are guaranteed to (a) get only one solution, and (b) find a maximum (not a minimum or an inflection point).}. Frequently we will want to work with the logarithm of the likelihood, which we call the \\textbf{log-likelihood}, because it has some nice properties, including allowing us to manipulate sums instead of products\\footnote{Note that if the function $f(z)$ has a maximum at $z'$, the function $\\log f(z)$ will also have a maximum at $z'$, because the logarithmic function is monotonically increasing. So we will get the same parameter estimate(s) either way.}:\n$$ \\log \\mathcal{L}(\\theta) = \\sum_{i=1}^n \\log p(x^{(i)}|\\theta). $$\n\nIn maximum likelihood estimation, we seek to find the $\\theta$ for which the likelihood (or log-likelihood) is maximized. We do this by taking derivatives of the log-likelihood with respect to the various parameters and setting them equal to zero. The best-fit parameter estimates obtained in this way are called the \\textbf{maximum likelihood estimates (MLEs)}. \n\\vspace{5mm}\n\n\\begin{question}{}\nWhat are some reasons why we might want to fit data to a probability distribution?\n% Data summarization (don't need to keep entire dataset around)\n% Sampling\n% Many common models and hypothesis tests rely on parametric assumptions (T-tests, etc.)\n% We are less likely to overfit to particularities of our own datasets, such as outliers (KNN, etc.)\n% Detecting outliers or faulty assumptions\n\\end{question}\n\n\\section{Example: Fitting Data to a Normal Distribution}\n\nImagine you have some data from a lab test that measures the concentration of a particular biomarker. You have data from $100$ different subjects. A histogram of the raw data looks like this:\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/normal-likelihood-example-data.png}\n\\end{center}\n\nYou want to find the normal distribution that best describes these data so you can create a reference distribution for this lab test. To do this, think about trying out several distributions with different values of $\\mu$ and $\\sigma$ and choosing the one that maximizes the log-likelihood. For example, here are three different normal distributions with different values of $\\mu$ and $\\sigma=0.7$: \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/normal-likelihood-example-data-normal.png}\n\\end{center}\nHere is what happens to the log-likelihood as you vary $\\mu$. The log-likelihoods of the three distributions shown in the plot above are shown as dots with their corresponding colors, and the maximum likelihood estimate is shown as a vertical dotted line.\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/normal-likelihood-example-vary-mu.png}\n\\end{center}\nNow, here's what happens to the log-likelihood when we vary $\\sigma$, keeping $\\mu$ fixed at its maximum likelihood estimate from the graph above. Again, the maximum likelihood estimate is shown as a vertical dotted line. \n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{img/normal-likelihood-example-vary-sigma.png}\n\\end{center}\nFor the record, I simulated these data from a normal distribution with $\\mu=2.5$ and $\\sigma=0.75$. The maximum likelihood estimates obtained from this dataset are $\\hat{\\mu} = 2.45$ and $\\hat{\\sigma} = 0.74$. \n\n\\section{Analytical Calculations of MLEs}\n\nIn some simple cases, the MLEs can be calculated analytically. We will now go through a bunch of examples of how to find the MLEs of the probability distributions we saw in Chapter~\\ref{chapter:probabilitydistributions}. \n\n\\subsection{Bernoulli Distribution}\n\nThe Bernoulli distribution is described in Section~\\ref{sect:bernoulli}. Our goal is to find the parameter, $\\mu$, of this distribution, given some observed data, $x^{(1)}, \\dots, x^{(n)}$. The data will consist of a list of 1s and 0s, since Bernoulli random variables can only take the values 0 or 1.\n\nTo find $\\hat{\\mu}$, our MLE for $\\mu$, we first write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\mu) &= \\sum_{i=1}^n \\log p(x^{(i)}|\\mu) \\\\\n&= \\sum_{i=1}^n \\log \\left( \\mu^{x^{(i)}}(1-\\mu)^{1-x^{(i)}} \\right) \\\\\n&= \\sum_{i=1}^n \\left[ x^{(i)} \\log(\\mu) + (1-x^{(i)}) \\log(1-\\mu) \\right] \\end{align*}\nThen we take the derivative of the log-likelihood with respect to $\\mu$:\n\\begin{align*}\n\\frac{d}{d \\mu} \\log \\mathcal{L}(\\mu) = \\sum_{i=1}^n \\left[ \\frac{x^{(i)}}{\\mu} - \\frac{1-x^{(i)}}{1-\\mu} \\right]\n\\end{align*}\nThe MLE of $\\mu$ will occur when the likelihood is maximized, which happens when the first derivative equals zero. So to solve for $\\hat{\\mu}$, we set the derivative equal to zero and rearrange:\n\\begin{align*} \\sum_{i=1}^n \\left[ \\frac{x^{(i)}}{\\hat{\\mu}} - \\frac{1-x^{(i)}}{1-\\hat{\\mu}} \\right] = 0 & \\implies (1 - \\hat{\\mu}) \\sum_{i=1}^n x^{(i)} = \\hat{\\mu} \\sum_{i=1}^n (1 - x^{(i)}) \\\\\n& \\implies \\boxed{\\hat{\\mu} = \\frac{1}{n} \\sum_{i=1}^n x^{(i)}} \\end{align*}\nWe see that the MLE, $\\hat{\\mu}$, is simply the sum of our data -- i.e. the number of data points where the outcome is 1 -- divided by the total number of observations. \n\nThis makes sense: if you want to know the probability that a coin will come up heads, a good way to estimate it is to flip the coin a bunch of times and calculate the fraction of observations in which the coin comes up heads. \n\n\\subsection{Binomial Distribution}\n\nThe binomial distribution is described in Section~\\ref{sect:binomial}. We will make one notational change from that section, which is to call the number of Bernoulli trials $m$ instead of $n$, since we are using $n$ to refer to the number of data samples. To keep things simple, we will assume that $m$ is a known quantity. As before, we first write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\mu) &= \\sum_{i=1}^n \\log p(x^{(i)}|m,\\mu) \\\\\n&= \\sum_{i=1}^n \\log \\left[ {m\\choose x} \\mu^x (1 - \\mu) ^ {m-x} \\right] \\\\\n&= \\sum_{i=1}^n \\left[\\log(m!) - \\log(x!) - \\log((m-x)!) + x^{(i)} \\log(\\mu) + (m-x^{(i)}) \\log(1-\\mu) \\right] \\end{align*}\nThen we take the derivative of the log-likelihood with respect to $\\mu$:\n\\begin{align*}\n\\frac{d}{d \\mu} \\log \\mathcal{L}(\\mu) = \\sum_{i=1}^n \\left[ \\frac{x^{(i)}}{\\mu} - \\frac{m-x^{(i)}}{1-\\mu} \\right]\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\mu}$ (the maximum likelihood estimate of $\\mu$):\n\\begin{align*} \\sum_{i=1}^n \\left[ \\frac{x^{(i)}}{\\hat{\\mu}} - \\frac{m-x^{(i)}}{1-\\hat{\\mu}} \\right] = 0 & \\implies (1 - \\hat{\\mu}) \\sum_{i=1}^n x^{(i)} = \\hat{\\mu} \\sum_{i=1}^n (m - x^{(i)}) \\\\\n& \\implies \\boxed{\\hat{\\mu} = \\frac{1}{nm} \\sum_{i=1}^n x^{(i)}} \\end{align*}\n\n\\begin{question}{}\nInterpret the MLE for the parameter, $\\mu$, of a binomial distribution, assuming fixed $m$ (number of trials). Does the MLE for $\\mu$ make intuitive sense to you? Think through a few of your examples from Question~\\ref{question:binomialex}. \n\\end{question}\n\n\\subsection{Normal Distribution \\label{sect:mlenormal}}\n\nThe normal distribution is described in Section~\\ref{sect:normal}. We will follow the same procedure as in the previous two sections, except that now we have two parameters to solve for, $\\mu$ and $\\sigma$, instead of one. First, we write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\mu, \\sigma) &= \\sum_{i=1}^n \\log p(x^{(i)}|\\mu, \\sigma) \\\\\n&= \\sum_{i=1}^n \\log \\left( \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{(x^{(i)}-\\mu)^2}{2 \\sigma^2}} \\right) \\\\\n&= -\\frac{n}{2} \\log (2 \\pi) - \\frac{n}{2} \\log \\sigma^2 - \\frac{1}{2 \\sigma^2} \\sum_{i=1}^n \\left( x^{(i)} - \\mu \\right)^2 \\\\\n\\end{align*}\nTo find the MLE for $\\mu$, we take the derivative of the log-likelihood with respect to $\\mu$:\n\\begin{align*}\n\\frac{\\partial}{\\partial \\mu} \\log \\mathcal{L}(\\mu, \\sigma) = \\frac{1}{\\sigma^2} \\sum_{i=1}^n \\left( x^{(i)} - \\mu \\right)\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\mu}$ (the maximum likelihood estimate of $\\mu$):\n\\begin{align*} \\frac{1}{\\sigma^2} \\sum_{i=1}^n \\left( x^{(i)} - \\mu \\right) = 0 & \\implies \\boxed{\\hat{\\mu} = \\frac{1}{n} \\sum_{i=1}^n x^{(i)}} \\end{align*}\nTo find the MLE for $\\sigma$, we then take the derivative of the log-likelihood with respect to $\\sigma$:\n\\begin{align*} \\frac{\\partial}{\\partial \\sigma} \\log \\mathcal{L}(\\mu, \\sigma) &= -\\frac{n}{\\sigma} + \\frac{1}{\\sigma^3} \\sum_{i=1}^n \\left( x^{(i)} - \\mu \\right)^2\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\sigma}$ (the maximum likelihood estimate of $\\sigma$)\\footnote{One detail: it turns out this estimate is biased because it depends on the MLE for $\\mu$. An unbiased version has $n-1$ in the denominator instead of $n$. The effect of this is minimal unless $n$ is small.}. Note that the answer depends on our previously calculated MLE for $\\mu$:\n\\begin{align*}\n-\\frac{n}{\\hat{\\sigma}} + \\frac{1}{\\hat{\\sigma}^3} \\sum_{i=1}^n \\left( x^{(i)} - \\mu \\right)^2 = 0  & \\implies \\boxed{\\hat{\\sigma} = \\sqrt{\\frac{1}{n} \\sum_{i=1}^n \\left( x^{(i)} - \\hat{\\mu} \\right)^2}}\n\\end{align*}\n\n\\begin{question}{}\nInterpret the MLEs for the parameters, $\\mu$ and $\\sigma$, of a normal distribution. Do these results make intuitive sense to you? Think through a few of your examples from Question~\\ref{question:normalex}. \n\\end{question}\n\n\\subsection{Poisson Distribution}\n\nThe Poisson distribution is described in Section~\\ref{sect:poisson}. To find the MLE for $\\lambda$, its mean, we first (as usual) write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\lambda) &= \\sum_{i=1}^n \\log p(x^{(i)}|\\lambda) \\\\\n&= \\sum_{i=1}^n \\log \\left( \\frac{e^{-\\lambda} \\lambda^{x^{(i)}}}{x^{(i)}!} \\right) \\\\\n&= \\sum_{i=1}^n \\left[ -\\lambda + x^{(i)} \\log(\\lambda) - \\log(x^{(i)}!) \\right] \\end{align*}\nNow we take the derivative of the log-likelihood with respect to $\\lambda$:\n\\begin{align*}\n\\frac{d}{d \\lambda} \\log \\mathcal{L}(\\lambda) = \\sum_{i=1}^n \\left[ -1 + \\frac{x^{(i)}}{\\lambda} \\right]\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\lambda}$ (the maximum likelihood estimate of $\\lambda$):\n\\begin{align*} \\sum_{i=1}^n \\left[ -1 + \\frac{x^{(i)}}{\\hat{\\lambda}} \\right] = 0 & \\implies \\boxed{\\hat{\\lambda} = \\frac{1}{n} \\sum_{i=1}^n x^{(i)}} \\end{align*}\n\n\\begin{question}{}\nInterpret the MLE for the parameter, $\\lambda$, of a Poisson distribution. Does this result make intuitive sense to you? Think through a few of your examples from Question~\\ref{question:poissonex}. \n\\end{question}\n\n\\subsection{Geometric Distribution}\n\nThe geometric distribution is described in Section~\\ref{sect:geometric}. To find the MLE for $\\mu$, we first write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\mu) &= \\sum_{i=1}^n \\log p(x^{(i)}|\\mu) \\\\\n&= \\sum_{i=1}^n \\log \\left( (1-\\mu)^{x^{(i)}} \\mu \\right) \\\\\n&= \\sum_{i=1}^n \\left[ x^{(i)} \\log(1-\\mu) + \\log(\\mu) \\right] \\end{align*}\nNow we take the derivative of the log-likelihood with respect to $\\mu$:\n\\begin{align*}\n\\frac{d}{d \\mu} \\log \\mathcal{L}(\\mu) = \\sum_{i=1}^n \\left[ -\\frac{x^{(i)}}{1-\\mu} + \\frac{1}{\\mu} \\right]\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\mu}$ (the maximum likelihood estimate of $\\mu$):\n\\begin{align*} \\sum_{i=1}^n \\left[ -\\frac{x^{(i)}}{1-\\hat{\\mu}} + \\frac{1}{\\hat{\\mu}} \\right] = 0 & \\implies \\frac{n}{\\hat{\\mu}} = \\frac{1}{1 - \\hat{\\mu}} \\sum_{i=1}^n x^{(i)} \\\\\n& \\implies \\boxed{\\hat{\\mu} = \\frac{n}{\\sum_{i=1}^n (x^{(i)}+1)} }\\end{align*}\n\n\\begin{question}{}\nInterpret the MLE for the parameter, $\\mu$, of a geometric distribution. Does this result make intuitive sense to you? Think through a few of your examples from Question~\\ref{question:geometricex}. \n\\end{question}\n\n\\subsection{Exponential Distribution}\n\nThe exponential distribution is described in Section~\\ref{sect:exponential}. To find the MLE for $\\lambda$, we first write down the log-likelihood:\n\\begin{align*}\n\\log \\mathcal{L}(\\lambda) &= \\sum_{i=1}^n \\log p(x^{(i)}|\\lambda) \\\\\n&= \\sum_{i=1}^n \\log \\left( \\lambda e^{-\\lambda x^{(i)}} \\right) \\\\\n&= \\sum_{i=1}^n \\left[\\log(\\lambda) - \\lambda x^{(i)} \\right] \\end{align*}\nNow we take the derivative of the log-likelihood with respect to $\\lambda$:\n\\begin{align*}\n\\frac{d}{d \\lambda} \\log \\mathcal{L}(\\lambda) = \\sum_{i=1}^n \\left[ \\frac{1}{\\lambda} - x^{(i)} \\right]\n\\end{align*}\nWe set this equal to zero and solve for $\\hat{\\lambda}$ (the maximum likelihood estimate of $\\lambda$):\n\\begin{align*} \\sum_{i=1}^n \\left[ \\frac{1}{\\hat{\\lambda}} - x^{(i)} \\right] = 0 & \\implies \\boxed{\\hat{\\lambda} = \\frac{n}{\\sum_{i=1}^n x^{(i)}}} \\end{align*}\n\n\\begin{question}{}\nInterpret the MLE for the parameter, $\\lambda$, of an exponential distribution. Does this result make intuitive sense to you? Think through a few of your examples from Question~\\ref{question:exponentialex}. \n\\end{question}\n\n\\section{Summary of MLEs for Common Distributions}\n\nThe table below contains a summary of the MLEs of various parameters from some common probability distributions.\n\n\\begin{center} {\\small\n\\begin{tabular}{lccc}\n\\toprule\nDistribution & Parameter & ML Estimate & Domain of $x^{(i)}$ \\\\\n\\midrule\nUnivariate Normal & $\\mu$ & $\\displaystyle \\cfrac{1}{n} \\sum_{i=1}^n x^{(i)}$  & $\\mathbb{R}$ \\\\\n& $\\sigma$ & $\\displaystyle \\frac{1}{n} \\sum_{i=1}^n \\left(x^{(i)} - \\hat{\\mu}\\right)^2 $ & $\\mathbb{R}$ \\\\\nMultivariate Normal & $\\mu$ & $\\displaystyle \\frac{1}{n} \\sum_{i=1}^n x^{(i)}$ & $\\mathbb{R}^m$ \\\\\n& $\\boldsymbol\\Sigma$ & $\\displaystyle \\frac{1}{n} \\sum_{i=1}^n (x^{(i)}-\\hat{\\mu})(x^{(i)}-\\hat{\\mu})^T$ & $\\mathbb{R}^m$ \\\\\nBernoulli & $\\mu$ & $\\displaystyle \\frac{1}{n} \\sum_{i=1}^n x^{(i)}$ & $\\{0, 1\\}$ \\\\\nBinomial (fixed $m$) & $\\mu$ & $\\displaystyle \\frac{1}{nm} \\sum_{i=1}^n x^{(i)}$ & $\\left\\{ 0, 1, \\dots, m \\right\\}$ \\\\\nPoisson & $\\lambda$ & $\\displaystyle \\frac{1}{n} \\sum_{i=1}^n x^{(i)}$ & $\\left\\{ 0, 1, \\dots \\right\\}$\\\\\nGeometric & $\\mu$ & $\\displaystyle \\cfrac{n}{\\sum_{i=1}^n (x^{(i)} + 1)} $ & $\\left\\{ 0, 1, \\dots \\right\\}$ \\\\\nExponential & $\\lambda$ & $\\displaystyle \\cfrac{n}{\\sum_{i=1}^n x^{(i)}} $ & $\\mathbb{R}^+$ \\\\\n\\bottomrule\n\\end{tabular}}\n\\end{center}\n\n\\begin{question}{}\nIn Question~\\ref{question:likexamples}, we examined several examples of experimental conditions and datasets and discussed which probability distribution best modeled each one. Using the formulas above and the actual datasets from Question~\\ref{question:likexamples}, calculate the MLEs for the parameter(s) of your chosen probability distributions. \n\\end{question}\n", "meta": {"hexsha": "7bca7c2ee7576b81594488b10fa52d34b052c58b", "size": 16892, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/mcds-maximum-likelihood.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-maximum-likelihood.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-maximum-likelihood.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": 83.2118226601, "max_line_length": 1086, "alphanum_fraction": 0.6919251717, "num_tokens": 5323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8902942224835226, "lm_q1q2_score": 0.7602335970776195}}
{"text": "\\chapter{Generalised Spherical Harmonics Formalism}\\label{app_gsh}\n\n\\section{Formalism}\nA general formalism to describe complex tensor fields on the surface of a 2-sphere is that of Generalised Spherical Harmonics. A generalisation of the spherical harmonic given by $Y_{lm}^N$, with an added index $N$, is used to decompose tensor fields of arbitrary rank \\cite{phinney_gsh}. It reduces to the spherical harmonic when $N=0$.\n\\begin{equation}\nY_{lm}^0(\\theta,\\phi) = Y_l^m(\\theta,\\phi)\n\\end{equation}\nThese functions couple with the GSH unit vectors given by\n\\begin{equation}\n\\begin{array}{ccc} \\ev{-} = \\frac{1}{\\sqrt{2}}(\\ev{\\theta} - i \\ev{\\phi}), & \\ev0 = \\ev{r}, & \\ev{+} = -\\frac{1}{\\sqrt{2}}(\\ev{\\theta} + i \\ev{\\phi}) \\\\ \\end{array}\n\\end{equation}\nto form tensor spherical harmonics\n\\begin{equation}\n\\Yv_{lm}^{N} \\equiv Y_{lm}^{N} \\ev{\\alpha_1}\\ev{\\alpha_2} \\ldots \\ev{\\alpha_q}\n\\end{equation}\nwhere $\\alpha_1 + \\alpha_2 +\\ldots + \\alpha_q = N$. These tensor functions by construction are eigenfunctions of the total angular momentum operator $\\hat{\\mathbf{J}} = \\hat{\\mathbf{L}} + \\hat{\\mathbf{s}}$, where the first part $\\hat{\\mathbf{L}}$ is the rotational generator for the scalar part of a field and the latter part $\\hat{\\mathbf{s}}$ generates rotation of the vector basis. Explicit expressions for $Y_{lm}^{N}$ can be found in \\cite{DT98}. Eigenvalue equations are as below\n\\begin{equation}\n\\hat{J}_{z} \\mathbf{Y}_{lm}^N = m\\mathbf{Y}_{lm}^N\n\\end{equation}\n\\begin{equation}\n\\hat{J}^2 \\mathbf{Y}_{lm}^N = l(l+1) \\mathbf{Y}_{lm}^N\n\\end{equation}\nThe set of all tensor GSHs of a particular rank form a complete basis for tensor fields of the same rank in 3D space. Hence, a tensor field $F(\\mathbf{r})$ of rank $M$ can be decomposed as \n\n\\begin{equation}\n\\mathbf{F}(\\mathbf{r}) = \\sum_{s=0}^{\\infty} \\sum_{t=-s}^{s}\\sum_{\\mu=-M}^{M} F_{st}^{\\mu}(r) \\mathbf{Y}_{st}^{\\mu}\n\\end{equation}\nwhere $F_{st}^{\\mu}(r)$ are its purely radially dependent GSH components.\n\\section{Conventions}\\label{app_conventions}\n\\begin{equation}\n\\gam{l} \\equiv \\sqrt{\\frac{2l+1}{4\\pi}}\n\\end{equation}\n\n\\begin{equation}\n\\om{l}{N} \\equiv \\sqrt{\\frac{(l+N)(l-N+1)}{2}}\n\\end{equation}\nNote that $\\om{l}{-N} = \\om{l}{N+1}$.\n\n\\begin{equation}\ng_{\\mu\\nu} \\equiv \\ev{\\mu}\\cdot \\ev{\\nu} = \\left( \\begin{matrix}\n0 & 0 & -1 \\\\\n0 & 1& 0  \\\\\n-1 & 0 & 0\n\\end{matrix} \\right)\n\\end{equation}\nwhere indices in the matrix run as $(-,0,+)$.\n\\begin{equation}\n\\ev{\\mu}^* \\cdot \\ev{\\nu} = \\delta_{\\mu\\nu}\n\\end{equation}\n\n\\section{Spherical triple integral}\n\\begin{equation}\n\\int_0^{2\\pi} d\\phi \\int_{0}^{\\pi} d\\theta\\sin\\theta Y_{l_1m_1}^{N_1}Y_{l_2m_2}^{N_2}Y_{l_3m_3}^{N_3} = 4\\pi \\gam{l_1}\\gam{l_2}\\gam{l_3} \\wigfull{l_1}{l_2}{l_3}{N_1}{N_2}{N_3} \\wigfull{l_1}{l_2}{l_3}{m_1}{m_2}{m_3}\n\\end{equation}\nExplicit expressions for $\\wigfull{l_1}{l_2}{l_3}{m_1}{m_2}{m_3}$ can be found in \\cite{DT98}. The property $\\enc{Y_{lm}^{N}}^* = (-1)^{m+N}Y_{l\\bar{m}}^{\\bar{N}}$ makes it useful while taking inner products of tensor fields in our analysis.\nNote that works like \\cite{lavely92}, \\cite{hanasoge17} etc. use a slighlty different convention defining $Y_{lm}^{N}$ as $Y_{lm}^{N}/\\gam{l}$ as in our convention. In this work, we have followed the convention of \\cite{DT98}.\n\\section{Rotation}\n\nTensor GSH functions $\\mathbf{Y}_{lm}^N$ obey the same rotation laws as spherical harmonics $Y_{l}^{m}$. Consider two coordinates systems on a sphere $(\\theta,\\phi)$ and $(\\theta',\\phi')$ such that $\\phi=0$ and $\\phi'=0$ planes coincide. Also, for all points on this plane, let $\\theta' = \\theta-\\beta$. This transformation law corresponds to the primed axis being tilted with respect to the unprimed axis by an angle $\\beta$. Tensor GSH functions in the two coordinates are related as follows\n\\begin{equation}\n\\mathbf{Y}_{lm}^{N}(\\theta',\\phi') = \\sum_{m'=-l}^{l} d_{mm'}^{(l)}(\\beta) \\mathbf{Y}_{lm'}^{N}(\\theta,\\phi)\n\\end{equation}\nwhere $d_{mm'}^{(l)}$ is a $(2l+1)\\times (2l+1)$ real matrix. Explicit form of $d^{(l)}_{mm'}$ can be found in \\cite{DT98} and a python subroutine for calculating this can be  found in \\textit{functions.py} in the Github repository \\cite{main_repo}. Above relation holds for all points on the entire sphere.\n\n", "meta": {"hexsha": "67585bbf3e059798d5bb27a811a109de1466e9d1", "size": 4202, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Appendix1/appendix1.tex", "max_stars_repo_name": "tuneerch/masters_thesis", "max_stars_repo_head_hexsha": "487646d71dc5f1f2bfbb8e29ee4878d14825c344", "max_stars_repo_licenses": ["MIT"], "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": "tuneerch/masters_thesis", "max_issues_repo_head_hexsha": "487646d71dc5f1f2bfbb8e29ee4878d14825c344", "max_issues_repo_licenses": ["MIT"], "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": "tuneerch/masters_thesis", "max_forks_repo_head_hexsha": "487646d71dc5f1f2bfbb8e29ee4878d14825c344", "max_forks_repo_licenses": ["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.6461538462, "max_line_length": 493, "alphanum_fraction": 0.6877677297, "num_tokens": 1523, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.909907001151883, "lm_q2_score": 0.8354835371034368, "lm_q1q2_score": 0.7602123197575562}}
{"text": "\\section{Math I - Algebra}\r\n  \\subsection{Generating Function Manager}\r\n    \\code{math/algebra/generating_function_manager.cpp}\r\n  \\subsection{Fast Fourier Transform}\r\n    Compute the Discrete Fourier Transform (DFT) of a polynomial in $O(n \\log n)$ time.\r\n    \\code{math/algebra/fft.cpp}\r\n  \\subsection{FFT Polynomial Multiplication}\r\n    Multiply integer polynomials $a, b$ of size $an, bn$ using FFT in $O(n \\log n)$. Stores answer in an array $c$, rounded to the nearest integer (or double).\r\n    \\code{math/algebra/fft-poly-mul.cpp}\r\n  \\subsection{Number Theoretic Transform}\r\n    Other possible moduli: $2 113 929 217 (2^{25}), 2 013 265 920 268 435 457 (2^{28}, with g = 5)$\r\n    \\code{math/algebra/ntt.cpp}\r\n  \\subsection{Polynomial Long Division}\r\n    Divide two polynomials $A$ and $B$ to get $Q$ and $R$, where $\\frac{A}{B} = Q + \\frac{R}{B}$.\r\n    \\code{math/algebra/poly-long-div.cpp}\r\n  \\subsection{Matrix Multiplication}\r\n    Multiplies matrices $A_{p\\times q}$ and $B_{q\\times r}$ in $O(n^3)$ time, modulo \\texttt{MOD}.\r\n    \\code{math/algebra/matmul.java}\r\n  \\subsection{Matrix Power}\r\n    Computes for $B^e$ in $O(n^3 \\log e)$ time. Refer to Matrix Multiplication.\r\n    \\code{math/algebra/matpow.java}\r\n  \\subsection{Fibonacci Matrix}\r\n    Fast computation for $n$th Fibonacci $\\left\\{F_1,F_2,\\ldots,F_n \\right\\}$ in $O(\\log n)$:\r\n    \\[\r\n    \\begin{bmatrix}\r\n        F_n \\\\\r\n        F_{n-1}\r\n    \\end{bmatrix}\r\n    =\r\n    \\begin{bmatrix}\r\n        1 & 1 \\\\\r\n        1 & 0\r\n    \\end{bmatrix}^n\r\n    \\times\r\n    \\begin{bmatrix}\r\n        F_2 \\\\\r\n        F_1\r\n    \\end{bmatrix}\r\n    \\]\r\n  \\subsection{Gauss-Jordan/Matrix Determinant}\r\n    Row reduce matrix $A$ in $O(n^3)$ time. Returns \\texttt{true} if a solution exists.\r\n    \\code{math/algebra/gauss-jordan.java}\r\n", "meta": {"hexsha": "b09ea50efba64ff6e3c88324cf217104c1913733", "size": 1781, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/algebra.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/algebra.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/algebra.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": 41.4186046512, "max_line_length": 160, "alphanum_fraction": 0.6367209433, "num_tokens": 566, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533144915912, "lm_q2_score": 0.8152324848629214, "lm_q1q2_score": 0.7601662325916471}}
{"text": "\\section{Maximum likelihood estimation of the free energies of states}\n\nWe start with the likelihood function, which defines the likelihood of\nseeing our measured results given a set of free energy values for the\nstates in our network:\n\n\\begin{equation}\n  L(\\{\\bar{\\Delta}_{ij}\\} | \\{g_i\\}) = \\prod_{ij} \\exp \\left(\n  \\frac{-1}{2 \\sigma^2_{ij}} ((g_j - g_i) - \\bar{\\Delta}_{ij})^2 \\right)\n  \\label{likelihood}\n\\end{equation}\n\nWe want to use this function to find the most likely $\\{g_i\\}$ that\nfits our data. We can do this by taking the gradient in g-space,\n$\\boldsymbol{\\nabla}_g$, and setting it equal to the null\nvector. Since the likelihood function is monotonic, we can maximize\nthe natural logarithm of (\\ref{likelihood}), as this is will greatly\nsimplify the mathematics. The log-likelihood is given by:\n\n\\begin{equation}\n  \\ln{L} = \\sum_{ij} \\frac{-1}{2\\sigma^2_{ij}} ((g_j - g_i) -\n  \\bar{\\Delta}_{ij})^2\n  \\label{logl}\n\\end{equation}\n\nWe define the gradient operator as:\n\n\\begin{equation}\n  \\boldsymbol \\nabla_g \\equiv \\sum_k \\boldsymbol{\\hat{g}_k}\n  \\frac{\\partial}{\\partial g_k}\n\\end{equation}\n\nTaking the gradient of (\\ref{logl}) and setting equal to the null\nvector, we find:\n\n\\begin{align}\n  \\boldsymbol{0} = \\boldsymbol \\nabla_g \\ln L &= \\sum_{ij}\n  \\frac{-1}{2\\sigma^2_{ij}} \\boldsymbol \\nabla_g ((g_j - g_i) -\n  \\bar{\\Delta}_{ij})^2 \\\\\n  &= \\sum_{ij} \\frac{-1}{\\sigma^2_{ij}}\n  ((g_j - g_i) - \\bar{\\Delta}_{ij})\\left[ \\boldsymbol{\\hat g_j}  -\n    \\boldsymbol{\\hat g_i} \\right]  \\\\\n   &= \\sum_{ij} \\frac{1}{\\sigma^2_{ij}}\n  ((g_j - g_i) - \\bar{\\Delta}_{ij})\\left[ \\boldsymbol{\\hat g_i}  -\n    \\boldsymbol{\\hat g_j} \\right] \n\\end{align}\n\nFrom here, we can compute $\\{g_i\\}$ numerically using\n\\verb|scipy.optimize.root|, which uses the hybrid Powell method to\nfind the roots of $\\boldsymbol \\nabla_g \\ln L$. We provide the root\nfunction the jacobian, whose elements are:\n\n\\begin{align}\n  J_{nm} = \\frac{\\partial}{\\partial g_n} \\left( \\boldsymbol \\nabla _{g}\n  \\ln L \\right)_m &= \\frac{\\partial}{\\partial g_n} \\sum_{ij}\n  \\frac{1}{\\sigma^2_{ij}} \\left[ (g_j - g_i ) -\n    \\boldsymbol{\\bar{\\Delta}_{ij}}\\right](\\delta_{mi} - \\delta_{mj})\n  \\\\ \n  &= \\sum_{ij} \\frac{1}{\\sigma^2_{ij}} ( \\delta_{nj} - \\delta_{ni}\n  )(\\delta_{mi} - \\delta_{mj}) \\\\\n  &= \\sum_{ij} \\frac{1}{\\sigma^2_{ij}} \\left[ \\delta_{nj} \\delta_{mi}\n    - \\delta_{nj}\\delta_{mj} - \\delta_{ni}\\delta_{mi} + \\delta_{ni}\n    \\delta_{mj} \\right] \\\\\n\\end{align}\n", "meta": {"hexsha": "9b9b07f5b1cfadbabf5a87bfe9c133d2a3ccdfea", "size": 2436, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/tex/mle.tex", "max_stars_repo_name": "Becksteinlab/multibind", "max_stars_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-06T05:40:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T18:54:31.000Z", "max_issues_repo_path": "docs/tex/mle.tex", "max_issues_repo_name": "Becksteinlab/multibind", "max_issues_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 13, "max_issues_repo_issues_event_min_datetime": "2021-03-04T15:17:18.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T16:45:56.000Z", "max_forks_repo_path": "docs/tex/mle.tex", "max_forks_repo_name": "Becksteinlab/multibind", "max_forks_repo_head_hexsha": "fe6dd2c048c3e734fd32fc293d98c1c8df41baa1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.4769230769, "max_line_length": 72, "alphanum_fraction": 0.6568144499, "num_tokens": 853, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338079816758, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7601216323806183}}
{"text": "\\subsection{Trig Identities}\r\n\r\nAs we could see in Figure \\ref{unitCircle}, $\\sin$ and $\\cos$ form a right triangle with a hypotenuse of length 1.\r\nSo, using the Pythagorean Theorem,\r\n\\begin{equation*}\r\n\t\\sin^2{\\theta} + \\cos^2{\\theta} = 1.\r\n\\end{equation*}\r\nBy dividing by $\\sin^2$ or $\\cos^2$, we can also get\r\n\\begin{equation*}\r\n\t1 + \\cot^2{\\theta} = \\csc^2{\\theta} \\text{ and } \\tan^2{\\theta} + 1 = \\sec^2{\\theta}.\r\n\\end{equation*}\r\nTogether, these 3 identities are called the Pythagorean Identities.\\\\\r\n\r\n\r\nWe can also relate functions and co-functions.\r\n\\begin{equation*}\r\n\t\\text{xxx}(\\theta) = \\text{cxx}\\left(\\frac{\\pi}{2} - \\theta\\right)\r\n\\end{equation*}\r\n\r\n\r\nSome of the most useful and used identities are the sum and difference.\r\n\\begin{equation*}\r\n\t\\sin{\\left(\\alpha \\pm \\beta\\right)} = \\sin{\\alpha}\\cos{\\beta} \\pm \\cos{\\alpha}\\sin{\\beta}\r\n\\end{equation*} \\begin{equation*}\r\n\t\\cos{\\left(\\alpha \\pm \\beta\\right)} = \\cos{\\alpha}\\cos{\\beta} \\mp \\sin{\\alpha}\\sin{\\beta}\r\n\\end{equation*} \\begin{equation*}\r\n\t\\tan{\\left(\\alpha \\pm \\beta\\right)} = \\frac{\\tan{\\alpha} \\pm \\tan{\\beta}}{1 \\mp \\tan{\\alpha}\\tan{\\beta}}\r\n\\end{equation*} \\begin{equation*}\r\n\t\\sin{\\alpha} \\pm \\sin{\\beta} = 2\\sin{\\left(\\frac{\\alpha \\pm \\beta}{2}\\right)}\\cos{\\left(\\frac{\\alpha \\mp \\beta}{2}\\right)}\r\n\\end{equation*} \\begin{equation*}\r\n\t\\cos{\\alpha} + \\cos{\\beta} = 2\\cos{\\left(\\frac{\\alpha + \\beta}{2}\\right)}\\cos{\\left(\\frac{\\alpha - \\beta}{2}\\right)}\r\n\\end{equation*} \\begin{equation*}\r\n\t\\cos{\\alpha} - \\cos{\\beta} = -2\\sin{\\left(\\frac{\\alpha + \\beta}{2}\\right)}\\sin{\\left(\\frac{\\alpha - \\beta}{2}\\right)}\r\n\\end{equation*}", "meta": {"hexsha": "676bb34acccd485115d7923dc93655e282eb94a6", "size": 1606, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/backgroundReview/algebraPreCalc/trigIdentites.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "calc/backgroundReview/algebraPreCalc/trigIdentites.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "calc/backgroundReview/algebraPreCalc/trigIdentites.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": 47.2352941176, "max_line_length": 124, "alphanum_fraction": 0.6382316314, "num_tokens": 585, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218305645895, "lm_q2_score": 0.8244619263765707, "lm_q1q2_score": 0.7600894483958959}}
{"text": "\\chapter{Power Series Solution and Special Functions}\n\\section{Series Solution Method}\nSeries expansion is a  method of obtaining one solution of the linear, second-order, homogeneous ODE. The method, will always work, provided the point of expansion is no worse than a regular singular point. In physics this very gentle condition is almost always satisfied. \nA linear, second-order, homogeneous ODE can be written in the form\n\\begin{equation}\n\\frac{d^{2} y}{d x^{2}}+P(x) \\frac{d y}{d x}+Q(x) y=0 \\label{DE002}\n\\end{equation}\nThe most general solution of the equation \\ref{DE002} may be written as,\n\\begin{equation}\ny(x)=c_{1} y_{1}(x)+c_{2} y_{2}(x)\n\\end{equation}\nBut a physical problem may lead to a nonhomogeneous, linear, second-order ODE\n\\begin{equation}\n\\frac{d^{2} y}{d x^{2}}+P(x) \\frac{d y}{d x}+Q(x) y=F(x)\\label{DE003}\n\\end{equation}\nHence the most general solution to the equation \\label{DE003} will be of the form,\n\\begin{equation}\ny(x)=c_{1} y_{1}(x)+c_{2} y_{2}(x)+y_{p}(x)\n\\end{equation}\nThe constants $c_{1}$ and $c_{2}$ will eventually be fixed by boundary conditions.\\\\\\\\\nThere are two series solution method  for differential equation,\n\\begin{enumerate}\n\t\\item \\textbf{Simple series expansion method}\n\t\\item \\textbf{Frobenious Method}\n\\end{enumerate}\n\\subsection{Simple Power Series Expansion Method}\nThe simple series expansion method works for differential equations whose solutions are well-behaved at the expansion point $x = 0$.\nWe illustrate the method of series solution by solving the following simple equation (which you can easily solve by elementary methods also!).\n\\begin{align}\ny^{\\prime}&=2 x y\\label{SP-05}\n\\intertext{We assume a solution of this differential equation in the form of a power series, namely}\ny&=a_{0}+a_{1} x+a_{2} x^{2}+a_{3} x^{3}+\\cdots+a_{n} x^{n}+\\cdots\\notag\\\\\n&=\\sum_{n=0}^{\\infty} a_{n} x^{n}\\label{SP-06}\n\\intertext{where the $a$ 's are to be found. Differentiating $(1.2)$ term by term, we get}\n y^{\\prime} &=a_{1}+2 a_{2} x+3 a_{3} x^{2}+\\cdots+n a_{n} x^{n-1}+\\cdots \\notag\\\\ &=\\sum_{n=1}^{\\infty} n a_{n} x^{n-1} \\label{SP-07}\n \\intertext{We substitute (\\ref{SP-06}) and (\\ref{DE007}) into the differential equation (\\ref{SP-05}); we then have two power series equal to each other. Now the original differential equation is to be satisfied for all values of $x$, that is, $y^{\\prime}$ and $2 x y$ are to be the same function of $x$. Since a given function has only one series expansion in powers of $x$ (see Chapter 1 , Section 11), the two series must be identical, that is, the coefficients of corresponding powers of $x$ must be equal. We get the following set of equations for the $a$ 's:}\n a_{1}&=0, \\quad a_{2}=a_{0}, \\quad a_{3}=\\frac{2}{3} a_{1}=0, \\quad a_{4}=\\frac{1}{2} a_{0}\n \\intertext{or in general:}\n n a_{n}&=2 a_{n-2}, \\quad a_{n}= \\begin{cases}0, & \\text { odd } n, \\\\ \\frac{2}{n} a_{n-2}, & \\text { even } n .\\end{cases}\\\\\n\\text{ Putting }n&=2 m\\text{ (since only even terms appear in this series), we get}\\notag\\\\\na_{2 m}&=\\frac{2}{2 m} a_{2 m-2}=\\frac{1}{m} a_{2 m-2}=\\frac{1}{m} \\frac{1}{m-1} a_{2 m-4}=\\cdots=\\frac{1}{m !} a_{0}\n\\intertext{Substituting these values of the coefficients into the assumed solution (\\ref{SP-06}) gives the solution}\ny&=a_{0}+a_{0} x^{2}+\\frac{1}{2 !} a_{0} x^{4}+\\cdots+\\frac{1}{m !} a_{0} x^{2 m}+\\cdots=a_{0} \\sum_{m=0}^{\\infty} \\frac{x^{2 m}}{m !}\n\\end{align}\n\\subsection{Classical Linear Oscillator}\n\\begin{align}\n\\frac{d^{2} y}{d x^{2}}+\\omega^{2} y&=0 \\label{DE003}\\\\\n\\text{with known solutions} \\ y&=\\sin \\omega x, \\cos \\omega x\\\\\n\\text{We try}\\ y(x) &=x^{k}\\left(a_{0}+a_{1} x+a_{2} x^{2}+a_{3} x^{3}+\\cdots\\right) \\\\\n&=\\sum_{\\lambda=0}^{\\infty} a_{\\lambda} x^{k+\\lambda}, \\quad a_{0} \\neq 0 \\label{DE004}\\\\\n\\intertext{with the exponent $k$ and all the coefficients $a_{\\lambda}$ still undetermined. Note that $k$ need not be an integer. By differentiating twice, we obtain}\n\\frac{d y}{d x} &=\\sum_{\\lambda=0}^{\\infty} a_{\\lambda}(k+\\lambda) x^{k+\\lambda-1} \\\\\n\\frac{d^{2} y}{d x^{2}} &=\\sum_{\\lambda=0}^{\\infty} a_{\\lambda}(k+\\lambda)(k+\\lambda-1) x^{k+\\lambda-2}\n\\intertext{By substituting into equation.\\ref{DE003}, we have}\n\\sum_{\\lambda=0}^{\\infty} a_{\\lambda}(k+\\lambda)(k+\\lambda-1) x^{k+\\lambda-2}+\\omega^{2} \\sum_{\\lambda=0}^{\\infty} a_{\\lambda} x^{k+\\lambda}&=0 \\label{DE005}\n\\intertext{The coefficients of each power of $x$ on the left-hand side of equation.\\ref{DE005} must vanish individually.The lowest power of $x$ appearing in equation.\\ref{DE005} is $x^{k-2}$, for $\\lambda=0$ in the first summation. The requirement that the coefficient vanish  yields,}\na_{0} k(k-1)&=0\n\\intertext{We had chosen $a_{0}$ as the coefficient of the lowest nonvanishing terms of the series \\ref{DE004}, hence, by definition, $a_{0} \\neq 0$. Therefore we have,}\nk(k-1)&=0 \\label{DE006}\n\\end{align}\n\\textbf{This equation, coming from the coefficient of the lowest power of $x$, we call the {indicial equation}.} The indicial equation and its roots are of critical importance to our analysis.\n\\\\From equation.\\ref{DE006}, \\qquad $k=0 $ or $k=1$\\\\\nThe only way a power series can be zero is, it's coefficients must be equal to zero. But here the power of $x$ in the equation do not match up. The Coefficent of $x$ in the first term is,${k+\\lambda-2} $ and for the second term it is,$k+\\lambda$, to make them equal, we can replace $\\lambda$ by $\\lambda+2$ in the first term. Then we get,\n\\begin{align}\n\\sum_{\\lambda=2}^{\\infty} a_{\\lambda+2}(k+\\lambda+2)(k+\\lambda+1) x^{k+\\lambda}+\\omega^{2} \\sum_{\\lambda=0}^{\\infty} a_{\\lambda} x^{k+\\lambda}&=0\\\\\n\\sum_{\\lambda=2}^{\\infty} a_{\\lambda+2}(k+\\lambda+2)(k+\\lambda+1) +\\omega^{2} \\sum_{\\lambda=0}^{\\infty} a_{\\lambda} &=0\n\\intertext{Here the coefficients  are independent summations and $\\lambda $ is a dummy index. Then we get,}\na_{\\lambda+2}(k+\\lambda+2)(k+\\lambda+1) +\\omega^{2} a_{\\lambda} &=0\\\\\na_{\\lambda+2}&=-a_{\\lambda} \\frac{\\omega^{2}}{(k+\\lambda+2)(k+\\lambda+1)}\\label{DE007}\n\\end{align}\nFor this example, if we start with $a_{0}$, Equation.\\ref{DE007} leads to the even coefficients $a_{2}, a_{4}$, and so on, and ignores $a_{1}, a_{3}, a_{5}$, and so on. Since $a_{1}$ is arbitrary if $k=0$ and necessarily zero if $k=1$, \n$$\na_{3}=a_{5}=a_{7}=\\cdots=0\n$$\nand all the odd-numbered coefficients vanish. The odd powers of $x$ will actually reappear when the second root of the indicial equation is used.\n\\begin{align}\na_{\\lambda+2}&=-a_{\\lambda} \\frac{\\omega^{2}}{(\\lambda+2)(\\lambda+1)}\n\\intertext{which leads to}\na_{2}&=-a_{0} \\frac{\\omega^{2}}{1 \\cdot 2}=-\\frac{\\omega^{2}}{2 !} a_{0} \\\\\na_{4}&=-a_{2} \\frac{\\omega^{2}}{3 \\cdot 4}=+\\frac{\\omega^{4}}{4 !} a_{0} \\\\\na_{6}&=-a_{4} \\frac{\\omega^{2}}{5 \\cdot 6}=-\\frac{\\omega^{6}}{6 !} a_{0}, \\quad \\text { and so on. }\n\\intertext{By inspection (and mathematical induction),}\na_{2 n}&=(-1)^{n} \\frac{\\omega^{2 n}}{(2 n) !} a_{0}\n\\intertext{and our solution is}\ny(x)_{k=0}&=a_{0}\\left[1-\\frac{(\\omega x)^{2}}{2 !}+\\frac{(\\omega x)^{4}}{4 !}-\\frac{(\\omega x)^{6}}{6 !}+\\cdots\\right]\\\\&=a_{0} \\cos \\omega x\\\\\n\\intertext{If we choose the indicial equation root $k=1$ Equation.\\ref{DE007}, the recurrence relation becomes}\na_{j+2}&=-a_{j} \\frac{\\omega^{2}}{(j+3)(j+2)}\\\\\n\\intertext{Substituting in $j=0,2,4$, successively, we obtain}\na_{2}=-a_{0} \\frac{\\omega^{2}}{2 \\cdot 3}&=-\\frac{\\omega^{2}}{3 !} a_{0} \\\\\na_{4}=-a_{2} \\frac{\\omega^{2}}{4 \\cdot 5}&=+\\frac{\\omega^{4}}{5 !} a_{0} \\\\\na_{6}=-a_{4} \\frac{\\omega^{2}}{6 \\cdot 7}&=-\\frac{\\omega^{6}}{7 !} a_{0}, \\quad \\text { and so on. }\n\\intertext{Again, by inspection and mathematical induction,}\na_{2 n}&=(-1)^{n} \\frac{\\omega^{2 n}}{(2 n+1) !} a_{0}\\\\\n\\intertext{For this choice, $k=1$, we obtain}\ny(x)_{k=1} &=a_{0} x\\left[1-\\frac{(\\omega x)^{2}}{3 !}+\\frac{(\\omega x)^{4}}{5 !}-\\frac{(\\omega x)^{6}}{7 !}+\\cdots\\right] \\\\\n&=\\frac{a_{0}}{\\omega}\\left[(\\omega x)-\\frac{(\\omega x)^{3}}{3 !}+\\frac{(\\omega x)^{5}}{5 !}-\\frac{(\\omega x)^{7}}{7 !}+\\cdots\\right] \\\\\n&=\\frac{a_{0}}{\\omega} \\sin \\omega x\n\\end{align}\n\\subsubsection{Power Series Solution (About an Ordinary Point)}\nFind the power series solution of $\\left(1-x^{2}\\right) y^{\\prime \\prime}-2 x y^{\\prime}+2 y=0$ about $x=0$\\\\\\\\\nSince $x=0$ is an ordinary point of the given differential equation, the solution can be written as\n\\begin{align*}\ny&=\\sum_{k=0}^{\\infty} a_{k} x^{k} \\\\ \\frac{d y}{d x}&=\\sum_{k=0}^{\\infty} k a_{k} x^{k-1} \\\\ \\frac{d^{2} y}{d x^{2}}&=\\sum_{k=0}^{\\infty} a_{k} k(k-1) x^{k-2}\n\\intertext{Substituting these values in the given equation we get,}\n\\left(1-x^{2}\\right) \\sum_{k} a_{k} k(k-1) x^{k-2}&-2 x \\sum_{k} a_{k}(k) x^{k-1}+2 \\sum_{k} a_{k} x^{k}=0 \\\\\n\\sum_{k=2} a_{k} k(k-1) x^{k-2}&-\\sum\\left(k^{2}+k-2\\right) a_{k} x^{k}=0\n\\intertext{now equating the coefficient of $x^{k}$ then}\n(k+2)(k+1) a_{k+2}-\\left(k^{2}+k-2\\right) a_{k}&=0 \\\\a_{k+2}&=\\frac{k-1}{(k+1)} a_{k}\\\\\n\\text{For} \\ k&=0 \\Rightarrow a_{2}=-a_{0} \\\\ k&=1 \\Rightarrow a_{3}=0 \\\\\nk&=2 \\Rightarrow a_{4}=\\frac{a_{2}}{3}=\\frac{-a_{0}}{3}  \\\\ k&=3 \\Rightarrow a_{5}=\\frac{2}{4} a_{3}=0\\\\\n\\text{Therefore, solution}\\ y&=a_{0}+a_{1} x+a_{2} x^{2}+\\ldots \\ldots\\\\&=a_{0}\\left[1-x^{2}-\\frac{x^{4}}{3} \\ldots . .\\right]+a_{1} x\n\\end{align*}\n%\\subsection{Frobenious Method}\n%Even though the simple power series expansion method works for many functions there are some whose behaviour  precludes the simple series method like the Bessel's function. The need of Frobenious method  lies under the fact that, \\textbf{any functions involving negative or fractional powers would not be amenable to power series solution method}. The Frobenious method extends the simple power series solution method to include negative and fractional powers, and it also allows a natural extension involving logarithm terms.\\\\\n%The basic idea of the Frobenius method is to look for solutions of the form\n%\\begin{align*}\n%y(x) &=a_{0} x^{\\lambda}+a_{1} x^{\\lambda+1}+a_{2} x^{\\lambda+2}+a_{3} x^{\\lambda+3}+\\ldots \\\\\n%&=x^{\\lambda}\\left(a_{0}+a_{1} x+a_{2} x^{2}+a_{3} x^{3}+\\ldots\\right) \\\\\n%&=x^{\\lambda} \\sum_{k=0}^{\\infty} a_{k} x^{k} \\\\\n%&= \\sum_{k=0}^{\\infty} a_{k} x^{k+\\lambda}\n%\\end{align*}\n%The extension of the simple power series method is all in the factor $x^{\\lambda}$. The power $c$ must now be determined, as well as the coefficients $a_{k}$. Since $\\lambda$ may be negative, positive, and possibly non-integral, this extends considerably the range of functions which may be treated. Note that $a_{0}$ is the lowest non-zero coefficient, so by definition it cannot be zero.\n\\section{Singularity}\nConsider differential equation,\n\\begin{equation}\n\\frac{d^2y}{dx^2} +P(x)\\frac{dy}{dx}+Q(x)y=0\n\\end{equation}\n\\begin{enumerate}\n\t\\item If $P(x)$ and $Q(x)$ remain finite at $x=x_0$ then it is ordinary point\n\t\\item If either $P(x)/Q(x)$ or both tends to $\\infty$ at $x=x_0$\n\tthen it is singular point.\n\\end{enumerate}\n\\subsection{Kinds of singular points}\n\\begin{enumerate}\n\t\\item \\textbf{Regular singularity}\\\\\\\\\n\tIF $P(x), Q(x)\\text{ diverges but } (x-x_0) P(x) \\text{ and }(x-x_0)^2Q(x)$ remain finite at $x\\rightarrow x_0$ then $x=x_0$ is called regular or non essencial singular points\n\t\\item \\textbf{Irregular singularity}\\\\\\\\\n\t$P(x), Q(x)$ diverges and either $(x-x_0)P(x)$ or $(x-x_0)^2Q(x)$ or both  remain infinite at $x\\rightarrow x_0$ then $x=x_0$ is called irregular or essential singular points\n\\end{enumerate}\n\\textbf{Little bit review of Ordinary Differential Equations}\n\\begin{equation*}\n\\frac{d^2y }{dx^2}+P(x)\\frac{dy}{dx}+Q(x)y=R(x)\n\\end{equation*}\nUsing Tailor series expansion method. If a function was continues and differentable you could express it as an infinite series of polynomial terms being added.\n\\begin{align*}\ny(x)&=\\sum\\limits_{n=0}^{\\infty}a_n(x-x_0)^n\\\\\ny^\\prime(x)&=\\sum\\limits_{n=0}^{\\infty}na_n(x-x_0)^{n-1}\\\\\ny^{\\prime\\prime}(x)&=\\sum\\limits_{n=0}^{\\infty}n(n-1)a_n(x-x_0)^{n-2}      \\intertext{Plugging this value into the differential equation we can express as}\n\\sum\\limits_{n=0}^{\\infty}n(a-1)a_n(x-x_0)^{n-2}&+\\sum\\limits_{n=0}^{\\infty}na_n(x-x_0)^{n-1}P(x)+Q(x)\\sum\\limits_{n=0}^{\\infty}a_n(x-x_0)^n=R(x)\n\\intertext{$P(x),Q(x)$ and $R(x)$ are also functions of $x$. It's also possible to express them as power series} \nP(x)=\\sum\\limits_{n=0}^{\\infty}b_n(x-x_0)^n\\quad Q(x)&=\\sum\\limits_{n=0}^{\\infty}c_n(x-x_0)^n,R(x)=\\sum\\limits_{n=0}^{\\infty}d_n(x-x_0)^n\\\\\n\\intertext{$\\sum\\limits_{n=0}^{\\infty}n(n-1)a_n(x-x_0)^{n-2}+\\sum\\limits_{n=0}^{\\infty}b_n(x-x_0)^n \\sum\\limits_{n=0}^{\\infty}na_n(x-x_0)^{n-1}+\\sum\\limits_{n=0}^{\\infty}c_n(x-x_0)^n  \\sum\\limits_{n=0}^{\\infty}a_n(x-x_0)^n    $}\n&=\\sum\\limits_{n=0}^{\\infty}d_n(x-x_0)^n\n\\end{align*}\n To find $a_n$,\n we should properly expand $P(x),Q(x)$ and $R(x)$ abt $x=x_0$ If any one of function is undefined at $x_0$ then we would not be able to do it.\\\\\\\\\n\\textbf{Example:}\\\\\n\\begin{equation*}\n\\frac{d^2y}{dx^2}-4y=0, \\ y(x)=\\sum\\limits_{n=0}^{\\infty}a_n(x-x_0)^n\n\\end{equation*}\n\nIt will always continuos and differentiable about $x_0=0$, So we will have a valid tylor series expansion about this point and we can proceed with a power series expansion method.\n\\begin{align*}\ny(x)&=\\sum\\limits_{n=0}^{\\infty}a_nx^n\\qquad\\ y^\\prime(x)=\\sum\\limits_{n=0}^{\\infty}na_n x^{n-1}\\qquad\ny^{\\prime\\prime}(x)=\\sum\\limits_{n=0}^{\\infty}n(n-1)a_nx^{n-2}\n\\end{align*}\nsubstituting into differential equation\n\\begin{align*}\n\\sum\\limits_{n=0}^{\\infty}n(n-1)a_nx^{n-2}-4\\sum\\limits_{n=0}^{\\infty}a_n x^n&=0\\\\\n\\sum\\limits_{n=0}^{\\infty}n(n-1)a_n x^{n-2}-4 \\sum\\limits_{n=2}^{\\infty}a_{n-2}x^{n-2}=0&\\\\\\text{ expanding  first two terms of the }\n\\sum\\limits_{n=0}^{\\infty}n(n-1)a_n x^{n-2} &\\text{we can express as }\\\\\n\\sum\\limits_{n=2}^{\\infty}n(n-1)a_nx^{n-2}-4\\sum\\limits_{n=2}^{\\infty}a_{n-2}x^{n-2}&=0\\\\\n\\text{\tcombining }\\sum\\limits_{n=2}^{\\infty}\\left[n(n-1)a_n-4a_{n-2} \\right] x^{n-2}&=0\\\\\n\\text{\tsince  RHS }=0 \\text{}\\\\\n\\implies n(n-1)a_n-4a_{n-2}&=0\n\\intertext{If relates the $n^{th}$ term in the sequence of coefficient to terms that occured  previously in that sequence}\na_n=\\frac{4a_{n-2}}{n(n-1)}&\n\\end{align*} \n$n^{th}$ coefficient is related to two terms back in the sequence\\\\\nwe have two solutions for differential equations, even part and odd part\n\\begin{align*}\n\\intertext{\\textbf{Case$\\ 1$}\\quad $\\rightarrow n=$\\text{Even}}\na_2&=\\frac{4a_0}{2.1}\\quad\na_4=\\frac{4a_2}{4.3}\\\\\n&=\\frac{4.4 \\ a_0}{4.3\\  2.1}\\\\\n&\\text{A pattern is developing}\\\\\na_4&=\\frac{2^4\\ a_0}{4!}\\quad \\text{it follows that}\\\\\na_n&=\\frac{2^2 a_0}{n!}\\\\\n&\\text{Since a is even}\\\\\na_{2k}&=\\frac{2^{2k\\ a_0}}{(2k)!}\\\\\n&\\text{any even number can represent as multiple of $2$}\\\\\n\\text{here }&k=0,1,2,3 \n\\intertext{\\textbf{Case$\\ 2$}\\quad $\\rightarrow n=$\\text{Odd}}\na_3&=\\frac{4\\ a_1}{3.2.1},\\ a_5=\\frac{4\\ a_3}{5.4}=\\frac{4.4.a_1}{5.4.3.2.1}\\\\\na_5&=\\frac{2^4\\ a_1}{5!}\\quad \\therefore a_n=\\frac{2^{n-1}\\ a_1}{n!}\\\\\n&\\text{It can be expressed as}\\\\\na_{2k+1}&=\\frac{2^{2k}\\ a_1}{(2k+1)!}\\\\\n\\intertext{ substituting in $y(x)=\\sum\\limits_{n=0}^{\\infty}a_nx^n$ and expanding,}\n&=a_0+a_1x+a_2x^2+a_3x^3+\\dots a_{2k}x^{2k}+a_{2k+1}x^{2k+1}+\\dots\\\\\n&=a_0+a_1x+\\frac{2^2\\ a_0}{2!}x^2+\\frac{2^2\\ a_1}{3!}x^3+\\dots+\\frac{2^{2k}\\ a_0}{(2k)!}+\\frac{2^{2k}\\ a_1}{(2k+1)!}+\\dots\\\\\n&\\text{ By seperating even and odd solutions we can express as}\\\\\ny(x)&=\\sum\\limits_{k=0}^{\\infty}\\frac{2^{2k}\\ a_0}{(2k)!}x^{2k}+\\sum\\limits_{k=0}^{\\infty}\\frac{2^{2k}\\ a_1}{(2k+1)!}x^{2k+1}\n\\end{align*}\nHere we discuss series solution and how to use power series to solve differential equations.Now we can check how to use this methode to solve one of the important problems in maths and physics, The legendre diffrential equation problem.\n\\section{Legendre Function}\n\\begin{align*}\n(1-x^2)\\frac{d^2y}{dx^2}&-2x\\frac{dy}{dx}+k(k+1)y=0\\\\\n&\\text{to expand it in } \nx_0=0\\\\\n\\frac{d^2y}{dx^2}&+\\frac{P(x)dy}{dx}+Q(x)y=R(x)\\text{(General form)}\n\\intertext{To compare our equation with General form we can express as }\n\\frac{d^2y}{dx^2}&-\\frac{2x}{(1-x^2)}\\frac{dy}{dx}+\\frac{k(k+1)}{1-x^2}y=0\\\\\\\n&\\text{ $P(x),Q(x)$ and $R(x)$ are all defined at $x=0$, So it is possible for regular series solution at $x_0=0$}\\\\\n\\end{align*}\n\\begin{align*}\ny(x)&=\\sum\\limits_{n=0}^{\\infty}a_nx^n\\\\\ny^{\\prime}(x)&=\\sum\\limits_{n=0}^{\\infty}na_nx^{n-1}\\\\\ny^{\\prime\\prime}(x)&=\\sum\\limits_{n=0}^{\\infty}n(n-1)a_nx^{n-2}\\\\\n(1-x^2)\\sum\\limits_{n=0}^{\\infty}n(n-1)&a_nx^{n-2}-2x\\sum\\limits_{n=0}^{\\infty}na_nx^{n-1}+k(k+1)\\sum\\limits_{n=0}^{\\infty}a_nx^{n}=0\\\\\n\\sum\\limits_{n=0}^{\\infty}n(n-1)&a_nx^{n-2}-\\sum\\limits_{n=0}^{\\infty}n(n-1)a_nx^{n}-\\sum\\limits_{n=0}^{\\infty}2na_nx^n+\\sum\\limits_{n=0}^{\\infty}k(k+1)a_nx^{n}=0\\\\\n\\intertext{To combain the terms, we have to make power of $x$ and limits same, after necessary steps we can express as}\n\\sum\\limits_{n=0}^{\\infty}&a_{n+2}(n+2)(n+1)x^n-\\sum\\limits_{n=0}^{\\infty}n(n-1)a_nx^n-\\sum\\limits_{n=0}^{\\infty}2na_nx^n+\\sum\\limits_{n=0}^{\\infty}k(k+1)a_nx^n=0\\\\\n\\sum\\limits_{n=0}^{\\infty}&\\left[ a_{n+2}(n+2)(n+1)-a_nn(n-1)-2na_n+k(k+1)a_n\\right] x^n=0\\\\\na_{n+2}&(n+2)(n+1)-a_nn(n-1)-2na_n+k(k+1)a_n=0\\\\\na_{n+2}&=\\frac{a_{n}[(n-k)(n+k)+(n-k)] }{(n+2)(n+1)}=\\frac{a_{n}(n-k)(n+k+1)}{(n+2)(n+1)}\n\\intertext{\\textbf{Case$\\ 1$}\\quad $\\rightarrow n=$\\text{Even}}\na_2&=\\frac{a_{0} \\cdot(-k)(x+1)}{2 \\cdot 1}\\\\\na_4&=\\frac{a_{2}(2-k)(3+k)}{4\\cdot 3}=\\frac{(k-2) k(k+1)(k+3) a_{0}}{4!}\n\\intertext{\\textbf{Case$\\ 2$}\\quad $\\rightarrow n=$\\text{Odd}}\na_3&=\\frac{a_{1}(1-k)(2+k)}{3\\cdot2}\\\\\na_5&=\\frac{9_{3}(3-k)(4+k)}{5.4}=\\frac{a_{1}(k-3)(k-1)(k+2)(k+4)}{5!}\n\\end{align*}\n1.\\quad What if $k=1$ \n\\begin{align*}\n a_3&=0\\\\\n\\text{all coefficients come later on }a_3&=0 \n\\text{ since they depend on }a_3\\\\\n\\text{so solution},\\ \n&y_{odd}=a_1x=a_1P_1(x)\\\\\nP_1(x)\\text{ is just a function of $x$}\n\\text{, even series }&\\text{doesnot terminate}\\end{align*}\n2.\\quad What if $k=2$\n\\begin{align*}\na_2&=a_{0} \\frac{(-2)(3)}{2}=-3 a_{0}, \\ a_{4}=0\\\\\ny_{\\text {even }}&=a_{0}-3 a_{0} x^{2}=a_{0}\\left(1-3 x^{2}\\right)\\\\\n&=\\cdot 5\\left(3 x^{2}-1\\right)=P_{2}(x) \\text{ for }a_0=\\frac{-1}{2}\\\\\n\\text{for }k&=2,\\text{ odd series doesnot terminate}\\\\\nk&=3\\\\\ny_ {odd} &=-\\frac{5}{3} a_1 x^{3}+a_{1} x\\\\\n&=\\frac{1}{2}\\left(5 x^{3}-3 x\\right)=P_{3}(x)\\text{ for }a_{1}=-3 / 2\\\\\n\\text{even series }&\\text{doesnot terminate for odd value of $k$}\n\\end{align*}\nwe can repeat this for different value of $k$, for even $k$, even series terminates and \nfor odd $k$, odd series terminates\\\\\n$P_1, P_2, P_3$ they result from series terminating are not like just other polynomial they are special polynomial.\\\\\n$P_1, P_2, P_3$ are called legendre polynomials, they are solutions to legendre diffrential equations they come up in electromagnetism and quantum mechanics. Bunch of techniques already developed to calculate legendre polynomials more easily and one of these techniques is rodrigues formula\n$P_{k}(x)=\\frac{1}{2^{k} k !} \\frac{d^{k}}{d x^{k}}\\left[\\left(x^{2}-1\\right)^{k}\\right]$\\\\\n\\section{Frobenius Method}\nFor power series solution, \\  $y^{\\prime\\prime}+P(x)y^\\prime +Q(x)y=R(x)$\\ only have valid series solution about $x=x_0$ if $P(x),Q(x)$ and $R(x)$ have valid tylor series at $x_0$. We want them to be continues and differentiable at that point. What if $P(x),Q(x),R(x)$ did not have valid tylor expansions about $x_0$ but still wanted series solution about $x_0$? We could do it by using a slightly modified version. All is to do include $r$ to the regular series solution. $r$ is a real number. This is called Frobenius method. Using Frobenius method still can have  solution to be power series solution at singular point. But point has to be regular singular point. \n\\begin{align*}\n&2(x-1)^2y^{\\prime\\prime}-(x-1)y^\\prime+y=0\\\\\n&2 y^{\\prime \\prime}-\\frac{1}{(x-1)} y^{\\prime}+\\frac{1}{(x-1)^{2}} y=0\n\\intertext{x=1 makes this undefined, but point 1 is a regular singular point. So we can express using frobenius method as}\n&y=\\sum_{k=0}^{\\infty} a_{k}(x-1)^{k+\\lambda}\\\\\n&y^{\\prime}=\\sum_{k=0}^{\\infty}(n+\\lambda) a_{k}(x-1)^{k+\\lambda-1}\n\\quad y^{\\prime \\prime}=\\sum_{k=0}^{\\infty}(k+\\lambda-1)(k+\\lambda) a_{k}(x-1)^{k+\\lambda-2}\\\\\n&2 \\sum_{k=0}^{\\infty}(k+\\lambda-1)(k+\\lambda) a_{k}(x-1)^{k+\\lambda-2}-\\frac{1}{x-1}\n\\sum_{k=0}^{\\infty}(k+\\lambda) a_{k}(x-1)^{k+\\lambda-1}+\\frac{1}{(x-1)^{2}}\\sum_{k=0}^{\\infty} a_{k}(x-1)^{k+\\lambda}=0\\\\\n&2 \\sum_{k=0}^{\\infty}(k+\\lambda-1)(k+\\lambda) a_{k}(x-1)^{k+\\lambda-2}-\n\\sum_{k=0}^{\\infty}(k+\\lambda) a_{k}(x-1)^{k+\\lambda-2}+\\sum_{k=0}^{\\infty} a_{k}(x-1)^{k+\\lambda-2}=0\\\\\n&\\sum_{k=0}^{\\infty}\\left[2(k+\\lambda)(k+\\lambda-1) a_{k}\\right.\\left.-(k+\\lambda) a_{k}+a_{k}\\right](x-1)^{k+\\lambda-2}=0\n\\intertext{expanding few terms}\n&\\left[ 2 \\lambda(\\lambda-1)-\\lambda+1\\right] a_0(x-1)^{\\lambda-2}+[2 \\lambda(\\lambda+1)-(\\lambda+1)+1]a_1(x-1)^{\\lambda-1}+...+=0\\\\\n\\intertext{equating coefficients of $(x-1)^{\\lambda-2}$}\n&2 \\lambda^{2}-3 \\lambda+1=0\\\\\n\\intertext{This is a quadratic equation and we call it as indicial equation.}\n&\\lambda_{1}=1 \\quad \\lambda_{2}=0.5\n\\end{align*}\n\n$\\therefore$ For equality to hold $a_1,a_2.....a_k,..=0$, what does this mean for final answer?\\\\\n$y=\\sum_{k=0}^{\\infty} a_{k}(x-1)^{k+\\lambda}=a_{0}(x-1)^{\\lambda}$only first term correspond to $k=0$ is in the final expression, because of two vaues of $r$. \\\\ $y_1=a_{0}(x-1), y_{2}=a_{0}(x-1)^{.5}$.\\\\ General solution is : $y=c_{1}(x-1)+c_{2} \\sqrt{x-1}$\n\\section{Bessel Function}\nBessel’s equation in the usual standard form is,\n\\begin{equation}\nx^{2} \\frac{d^{2} y}{d x^{2}}+x \\frac{d y}{d x}+\\left(x^{2}-n^{2}\\right) y=0 \\label{Bessel 1}\n\\end{equation}\nWhere $n$ is a constant (not necessarily an integer) called the order of the Bessel function $'y'$ which is the solution of equation.\\ref{Bessel 1}. $x=0$ is a regular singular point of the Bessel differential equation.\n\n\\subsection{The solution of Bessel's function}\n\\begin{align*}\nx^{2} y^{\\prime\\prime }+x y^\\prime+\\left(x^{2}-n^{2}\\right) y&=0\n\\intertext{ $x_0=0$ is a regular singular point, so we can expand about $x_0=0$ using Frobenius method}\ny=\\sum_{k=0}^{\\infty} a_{k} x^{k+\\lambda}\\quad y^{\\prime}&=\\sum_{k=0}^{\\infty}(k+\\lambda) a_{k} x^{k+\\lambda-1}\\quad y^{\\prime \\prime}=\\sum_{k=0}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{k}x^{k+\\lambda-2}\\\\\n\\sum_{k=0}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{k} x^{k+\\lambda-2} &+\\frac{1}{x} \\sum_{k=0}^{\\infty}(k+\\lambda) a_{k}x^{k+\\lambda-1}+\\left(1-\\frac{n^{2}}{x^{2}}\\right) \\sum_{k=0}^{\\infty} a_{k} x^{k+\\lambda}=0\\\\\n\\sum_{k=0}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{k} x^{k+\\lambda-2} &+\\sum_{k=0}^{\\infty}(k+\\lambda) a_{k} x^{k+\\lambda-2}+\\sum_{n=0}^{\\infty} a_{k} x^{k+\\lambda}-n^{2}\\sum_{k=0}^{\\infty} a_{k}x^{k+\\lambda-2} =0\\\\\n\\sum_{k=0}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{k} x^{k+\\lambda-2} &+\\sum_{k=0}^{\\infty}(k+\\lambda) a_{k} x^{k+\\lambda-2}+ \\sum_{k=2}^{\\infty} a_{k-2} x^{k+\\lambda-2}-n^{2}\\sum_{k=0}^{\\infty} a_{k}x^{k+\\lambda-2} =0\\\\\n\\sum_{k=2}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{n} x^{k+\\lambda-2}&+\\sum_{k=2}^{\\infty}(k+\\lambda) a_{k} x^{k+\\lambda-2}+\\sum_{k=2}^{\\infty}a_{k-2}x^{k+\\lambda-2}-n^{2} \\sum_{k=2}^{\\infty} a_{k}  x^{k+\\lambda-2}\\\\\n+\\lambda(\\lambda-1) a_{0} x^{\\lambda-2}+\\lambda(\\lambda+1) a_{1} x^{\\lambda-1}&+\\lambda a_{0} x^{\\lambda-2}+(\\lambda+1) a_{1} x^{\\lambda-1}-n^2{a_{0}} x^{\\lambda-2}-n^{2} a_1 x^{\\lambda-1}=0\n\\intertext{ right hand side is 0, so each term of left hand side should be equal to 0 and we can express like this}\n\\text{for} x^{\\lambda-2}, \\lambda(\\lambda-1) a_{0}+\\lambda a_{0}-n^{2} a_{0}&=0, \\text{we want }a_{0} \\neq 0 \\text{, so we can write as,}\\\\\n\\lambda(\\lambda-1)+\\lambda-n^{2}=0\\quad \\lambda^{2}-n^{2}&=0 \\quad \\lambda=\\pm n\n\\text{,this is our indicial equations}\n\\intertext{Plugging the values of $\\lambda$ in   $ x^{\\lambda-1}$We can show  $a_{1}=0$ , and what left with the equation is} \\\\\n\\sum_{k=2}^{\\infty}(k+\\lambda)(k+\\lambda-1) a_{k} x^{k+\\lambda-2}&+\\sum_{n=2}^{\\infty}(k+\\lambda) a_{k} x^{k+\\lambda-2}+\\sum_{k=2}^{\\infty}a_{k-2}x^{k+\\lambda-2}-n^{2} \\sum_{k=2}^{\\infty} a_{k}  x^{k+\\lambda-2}=0\\\\\n\\sum_{k=2}^{\\infty}(((k+\\lambda)(k+ \\lambda-1)&+(k+\\lambda) n^2) a_{k}+\\left.a_{k-2}\\right) x^{k+\\lambda-2}=0\\\\\n\\left[(k+\\lambda)(k+\\lambda-1)+(k+\\lambda)-n^{2}\\right] &a_{k}+a_{k-2}=0\\\\\na_{k}&=\\frac{-a_{k-2}}{\\left[(k+\\lambda)^{2}-n^{2}\\right]}\\\\\n\\text{substitute }\\lambda_1&=n\\\\\na_{k}=\\frac{-a_{k-2}}{k(k+2 n)}\\implies &\\text{recursion}\\\\\n\\text{since }a_1 =0, \\ &\na_{3},\\  a_{5}, \\ a_{7},....=0\n\\intertext{For even intiger coefficients, $k=2r$}\na_{2 r}&=-\\frac{a_{2 r-2}}{4 r(r+n)}\\\\\na_{2}&=\\frac{-a_{0}}{4 \\cdot 1 (1+n)}\\\\a_{4}&=-\\frac{-a_{2}}{4 \\cdot 2(2+n)}=\\frac{(-1)^{2} a_{0}}{4^{2}(2 \\cdot 1)(2+n)(1+n)}\\\\\n\\therefore a_{2 r}&=\\frac{(-1)^{r}}{4{r}}\\frac{a_{0}}{r !(n+r) \\cdots(n+1)}\\\\\ny_{1}&=x^{n}\\sum_{r=0}^{\\infty} \\frac{(-1)^{r}}{4 r}\\frac{a_{0}}{r !(n+r) . .(n+1)} x^{2 r}\n\\end{align*}\nFor particular value of $a_0$ this solution is given a special name, $ J_n(x)$, Bessel function of $I$ kind and $n$ is order of Bessel function.\nThe solution of Bessel's function, $J_{n}(x)$ is defined to be a Bessel function of the first kind, of integral order $r$.\n\\begin{align}\n\\mathrm{J}_{\\mathrm{n}}(\\mathrm{x})&=y=a_{0} \\sum_{r=0}^{\\infty} \\frac{(-1)^{r}}{r !(n+r) !}\\left(\\frac{x}{2}\\right)^{n+2 r}\\label{Bessel 2} \\\\ \\text { Where } \\mathrm{a}_{0}&=\\frac{1}{2^{n} \\Gamma (n+1)} \\notag\\\\\n\\mathrm{n}=0 \\quad \\Rightarrow \\quad \\mathrm{J}_{0}(\\mathrm{x})&=\\sum_{r=0}^{\\infty} \\frac{(-1)^{r}}{(r !)^{2}}\\left(\\frac{x}{2}\\right)^{2 r}=1-\\frac{x^{2}}{2^{2}}+\\frac{x^{4}}{2^{2} \\cdot 4^{2}}-\\frac{x^{6}}{2^{2} \\cdot 4^{2} \\cdot 6^{2}}+\\ldots . .\\\\\n\\mathrm{n}=1 \\quad \\Rightarrow \\quad \\mathrm{J}_{1}(x)&=\\frac{x}{2}-\\frac{x^{3}}{2^{2} 4}+\\frac{x^{5}}{2^{2} \\cdot 4^{2} \\cdot 6}-\\ldots .\n\\end{align}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=7cm]{SF-03}\n\\end{figure}\n\\subsubsection{The second solution of Bessel's function}\nWe have found just one of the two solutions of Bessel’s equation, that is, the one\nwhen $n>0$; we must next ﬁnd the solution when $n<0$.  We can just replace $n$ by $-n$ in equation.\\ref{Bessel 2}. \nThe solution in $-n$ is usually written as $J_{-n}(x)$\n\\begin{equation}\nJ_{-n}(x)=\\sum_{r=0}^{\\infty} \\frac{(-1)^{r}}{r !(r-n) !}\\left(\\frac{x}{2}\\right)^{2 r-n} .\n\\end{equation}\nAnd, \n\\begin{equation}\nJ_{-n}(x)=(-1)^{n} J_{n}(x) \\quad \\text { for integral } n\n\\end{equation}\n\\subsubsection{Properties of Bessel's function.}\n\\begin{enumerate}\n\t\\item Bessel functions are oscillatory function with varying period and decreasing amplitude.\n\t\\item $J_{n}(x)$ is an even function when $n$ is even and $J_{n}(x)$ is an odd function when $n$ is odd.\n\t\\item $\\mathrm{J}_{0}(\\mathrm{x})$ has nodes at $x=2.408,5.5201$......and $J_{1}(x)$ has nodes at $x=3.8317,7.015$.......\n\\end{enumerate}\n\\begin{note}$\\left. \\right. $\\ The Bessel's functions for $n=\\pm \\frac{1}{2}$,\n\t\\begin{align*}\n\tJ_{1 / 2}(x)&=\\sqrt{\\frac{2}{\\pi x}} \\sin x \\\\ J_{-1 / 2}(x)&=\\sqrt{\\frac{2}{\\pi x}} \\cos x\n\t\\end{align*}\n\\end{note}\n\n\\subsection{Generating function of Bessel's function:}\n\\begin{align*}\ne^{\\frac{x}{2}\\left(z-\\frac{1}{z}\\right)}=\\sum_{n=-\\infty}^{\\infty} z^{n} J_{n}(x)\n\\intertext{The coefficient of $z^{n}$ in the expansion of the generating tünction is the Bessel function of order $1 .$}\n\\end{align*}\n\\subsection{Orthogonal condition of Bessel Function:}\n\\begin{align*}\n\\int_{0}^{1} x_{n} \\cdot(\\alpha x) J_{n}(\\beta x) d x=\\frac{\\delta_{\\alpha \\beta}}{2} \\cdot\\left[J_{n+1}(\\alpha)\\right]^{2}\n\\end{align*}\n\\subsection{Recurrencé relations for $J_{n}(x)$ :}\n\\begin{enumerate}\n\t\\item $\\frac{d}{d x}\\left[x^{n} J_{n}(x)\\right]=x^{n} J_{n-1}(x)$\n\t\\item $\\frac{d}{d x}\\left[x^{-n} J_{n}(x)\\right]=-x^{-n} J_{n+1}(x)$\n\t\\item $J_{n-1}(x)+J_{n+1}(x)=\\frac{2 n}{x} J_{n}(x)$\n\t\\item $J_{n-1}(x)-J_{n+1}(x)=2 J_{n}^{\\prime}(x)$\n\t\\item $J_{n}^{\\prime}(x)=-\\frac{n}{x} J_{n}(x)+J_{n-1}(x)=\\frac{n}{x} J_{n}(x)-J_{n+1}(x)$\n\\end{enumerate}\n\n\\begin{exercise}\n\tShow that $\\sqrt{\\frac{\\pi x}{2}} J_{3 / 2}(x)=\\frac{\\sin x}{x}-\\cos x$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Using recurrence relation, }2 n J_{n}&=x\\left[J_{n+1}+J_{n-1}\\right]\\\\\n\t\\text{putting}\\mathrm{n}&=1 / 2,\\text{ we get, }J_{1 / 2}=x\\left[J_{3 / 2}+J_{-1 / 2}\\right]\\\\\n\tx J_{3 / 2}&=J_{1 / 2}-x J_{-1 / 2} \\\\ \\sqrt{\\frac{\\pi x}{2}} J_{3 / 2}&=\\frac{\\sin x}{x}-\\cos x \\text { (using the expressions of } J_{1 / 2} \\& J_{-1 / 2} \\text { ) }\n\t\\end{align*}\n\\end{answer}\n\\section{Legendre Differential Equation}\n\\subsection{Rodrigue's Formula for Legendre's Polynomial $P_{n}(x)$ :}\n\\begin{align*}\n\\text { Legendre polynomial of order ' } n \\text { ' : } P_{n}(x)&=\\frac{1}{2^{n} n !} \\frac{d^{n}}{d x^{n}}\\left(x^{2}-1\\right)^{n}\\\\\nP_{0}(x)=1 ; \\quad P_{1}(x)=x ; \\quad P_{2}(x)&=\\frac{1}{2}\\left(3 x^{2}-1\\right) ; \\quad P_{3}(x)=\\frac{1}{2}\\left(5 x^{3}-3 x\\right)\n\\end{align*}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.8cm,width=6cm]{SF-02}\n\\end{figure}\n\\subsection{Properties of Legendre's Polynomial}\n\\begin{enumerate}\n\t\\item $P_{n}(1)=1$\n\t\\item $P_{n}(-1)=(-1)^{n}$\n\t\\item $\\left. \\right.$\\ $\\begin{aligned}\n\tP_{n}(x)&=\\text { even function, if } \\mathrm{n}=\\text { even }\\\\\n\t        &=\\text { odd function, if } \\mathrm{n}=\\text { odd }\n\t\\end{aligned}$\n\t\\item $P_{n}(-x)=(-1)^{n} P_{n}(x)$\n\\end{enumerate}\n\n\\subsection{Generating function of Legendre's polynomial:}\n$\\left(1-2 x z+z^{2}\\right)^{-1 / 2}$ is the generating function for legendre's polynomials i.e. $$\\left(1-2 x z+z^{2}\\right)^{-1 / 2}=\\sum_{n=0}^{\\infty} z^{n} P_{n}(x)$$\nThe co-efficient of $z^{n}$ in the exapansion of the generating function is the Legendre's polynomial of order $n$.\n\\subsection{Orthogonal properties of Legendre's polynomial:}\n\\begin{align*}\n\\int_{-1}^{+1} P_{m}(x) P_{n}(x) d x=\\frac{2}{2 n+1} \\delta_{m n} \\text { where } \\delta_{m n}=\\text { Kronecker delta }&=1 \\quad \\text { if } \\mathrm{m}=\\mathrm{n}\\\\\n&=0 \\quad \\text { if } m \\neq n\n\\end{align*}\n\\subsection{Recurrence relations for $P_{n}(x)$ }\n\\begin{enumerate}\n\t\\item $n P_{n}=(2 n-1) x P_{n-1}-(n-1) P_{n-2}$\n\t\\item $n P_{n}=x P_{n}^{\\prime}-P_{n-1}^{\\prime}$\n\t\\item $(2 n+1) P_{n}=P_{n+1}^{\\prime}-P_{n-1}^{\\prime}$\n\t\\item $(n+1) P_{n}=P_{n+1}^{\\prime}-x P_{n}^{\\prime}$\n\t\\item $\\left(1-x^{2}\\right) P_{n}^{\\prime}=n\\left(P_{n-1}-x P_{n}\\right)$\n\t\\item $\\left(1-x^{2}\\right) P_{n}^{\\prime}=(n+1)\\left(x P_{n}-P_{n+1}\\right)$\n\\end{enumerate}\n\n\\begin{exercise}\n\tExpress $4 x^{3}+6 x^{2}+7 x+2$ in terms of Legendre Polynomials.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Let, } 4 x^{3}+6 x^{2}+7 x+2&=a_{3} P_{3}(x)+a_{2} P_{2}(x)+a_{1} P_{1}(x)+a_{0} P_{0}(x)\\\\\n\t&=\\frac{a_{3}}{2}\\left(5 x^{3}-3 x\\right)+\\frac{a_{2}}{2}\\left(3 x^{2}-1\\right)+a_{1} x+a_{0}\\\\\n\t\\text { Comparing the co-efficient of } &\\mathrm{x}^{3}: \\frac{5 a_{3}}{2}=4 \\Rightarrow a_{3}=\\frac{8}{5}\\\\\n\t\\text { Comparing the co-efficient of }& x^{2}: \\frac{3 a_{2}}{2}=6 \\Rightarrow a_{2}=4\\\\\n\t\\text { Comparing the co-efficient of }& x^{1}:-\\frac{3 a_{3}}{2}+a_{1}=7 \\Rightarrow a_{1}=\\frac{47}{5}\\\\\n\t\\text { Comparing the co-efficient of }& \\mathrm{x}^{0}:-\\frac{a_{2}}{2}+a_{0}=2 \\Rightarrow a_{0}=4\\\\\n\t\\text { Therefore, } 4 x^{3}+6 x^{2}+7 x+2&=\\frac{8}{5} P_{3}(x)+4 P_{2}(x)+\\frac{47}{5} P_{1}(x)+4 P_{0}(x)\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tShow that, $\\int_{-1}^{1} x^{2} P_{n+1} P_{n-1} d x=\\frac{2 n(n+1)}{(2 n-1)(2 n+1)(2 n+3)}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{Using the relation: }&(2 n+1) x P_{n}=(n+1) P_{n+1}+n P_{n-1}\\\\\n\t\\text{Putting $(\\mathrm{n}+1)$ in place of }&\\mathrm{n} \\Rightarrow(2 n+3) x P_{n+1}=(n+2) P_{n+2}+(n+1) P_{\\mathrm{n}}\\\\\n\t\\text{Putting $(\\mathrm{n}-1)$ in place of }&\\mathrm{n} \\Rightarrow(2 n-1) x P_{n-1}=n P_{n}+(n-1) P_{n-2}\\\\\n\t\\int_{-1}^{1}(2 n+3)(2 n-1) x^{2} P_{n+1} P_{n-1} d x&=n(n+2) \\int_{-1}^{1} P_{n+2} P_{n} d x+n(n+1) \\int_{-1}^{1} P_{n} P_{n} d x+\\\\\n\t&(n-1)(n+2) \\int_{-1}^{1} P_{n-2} P_{n+2} d x+\\int_{-1}^{1} P_{n} P_{n-2} d x\\\\\n\t \\int_{-1}^{1} x^{2} P_{n-1} P_{n+1} d x&=\\frac{2 n(n+1)}{(2 n-1)(2 n+1)(2 n+3)}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tShow that $\\sum_{n} P_{n}(x)=\\frac{1}{\\sqrt{2-2 x}}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\left(1-2 x z+z^{2}\\right)^{-1 / 2}&=\\sum_{n} z^{n} P_{n}(x)\\\\\n\t\\text { Putting } z&=1 \\text { in equation, }(1-2 x+1)^{-1 / 2}=\\sum_{n} P_{n}(x) \\\\ \\sum_{n} P_{n}(x)&=\\frac{1}{\\sqrt{2-2 x}}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tProve that $P_{n+1}^{\\prime}(x)+P_{n}^{\\prime}(x)=P_{0}+3 P_{1}+5 P_{2}+\\ldots . .+(2 n+1) P_{n}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Using the relation }&(2 n+1) P_{n}(x)=P_{n+1}^{\\prime}(x)-P_{n-1}^{\\prime}(\\dot{x})\\\\\n\t\\text { putting } \\mathrm{n}&=1 \\quad \\Rightarrow 3 P_{1}(x)=P_{2}^{\\prime}(x)-P_{0}^{\\prime}(x)\\\\\n\t\\text { putting } \\mathrm{n}&=2 \\quad \\Rightarrow 5 P_{2}(x)=P_{3}^{\\prime}(x)-P_{1}^{\\prime}(x)\\\\\n\t\\text { putting } \\mathrm{n}&=3 \\quad \\Rightarrow 7 P_{3}(x)=P_{4}^{\\prime}(x)-P_{2}^{\\prime}(x) \\text { and so on. }\\\\\n\t\\text{Adding all}&\\text{ the equations we get,}\\\\\n\t3 P_{1}(x)+5 P_{2}(x)+7 P_{3}(x)+\\ldots \\ldots(2 n+1) P_{n}(x)\n\t&=-P_{0}^{\\prime}(x)-P_{1}^{\\prime}(x)+P_{n}^{\\prime}(x)+P_{n+1}^{\\prime}(x)\\\\&=0-P_{0}(x)+P_{n}^{\\prime}(x)+P_{n+1}^{\\prime}(x)\\\\\n\t P_{n+1}^{\\prime}(x)+P_{n}^{\\prime}(x)&=P_{0}+3 P_{1}+5 P_{2}+\\ldots . .+(2 n+1) P_{n}\n\t\\end{align*}\n\\end{answer}\n\n\\section{Hermite Differentiation Equation}\nThe diﬀerential equation for Hermite functions is,\n\\begin{align*}\n\\frac{d^{2} y}{d x^{2}}-2 x \\frac{d y}{d x}+2 n y&=0,(\\mathrm{n}=0,1 \\ldots . .)\\\\\n\\text{$x=0$ is an ordinary point of the }&\\text{Hermite differential equation}\\\\\n\\intertext{The solution of the Hermite differential equation is a terminating series, so it is called Hermite polynomial of}\n\\intertext{order $n$, i.e. $\\mathrm{H}_{\\mathrm{n}}(\\mathrm{x})$}\nH_{n}(x)&=\\sum_{r=0}^{P} \\frac{(-1)^{r} n !(2 x)^{n-2 r}}{r !(n-2 r) !} \\quad \\Rightarrow\\left[\\begin{array}{ll}\nP&=\\frac{n}{2}\\quad \\text { if } n=\\text { even } \\\\\n&=\\frac{n-1}{2}  \\text { if } \\mathrm{n}= \\text {  odd }\n\\end{array}\\right]\n\\end{align*}\n\\subsection{Rodrigue formula for $H_{n}(x)$ :}\n\\begin{enumerate}\n\t\\item $H_{n}(x)=(-1)^{n} e^{x^{2}} \\frac{d^{n}}{d x^{n}}\\left(e^{-x^{2}}\\right) $\n\t\\item $ H_{0}(x)=1  $\n\t\\item $ H_{1}(x)=2 x  $\n\t\\item $ H_{2}(x)=4 x^{2}-2 $\n\t\\item $ H_{3}(x)=8 x^{3}-12 x$\n\t\\item $ H_{4}(x)=16 x^{4}-48 x^{2}+12$\n\\end{enumerate}\n$H_{\\mathrm{n}}(x)$ will be even function if $n$ is even and will be odd function if $n$ is odd.\nThe Hermite polynomial of different order differ from the legendre polynomials with respect to the coefficient.\n So, the nature of the graphs of $\\mathrm{H}_{\\mathrm{n}}(\\mathrm{x})$ will be same as Legendre polynomial $P_{\\mathrm{n}}(x)$.\n\\subsection{Generating function for Hermite polynomial:}\n\\begin{align*}\n\\intertext{$\\mathrm{e}^{2 {zx}-{z}^{2}}$ is the generating function of hemite polynomial i.e.}\ne^{2 z x-z^{2}}&=\\sum_{n=0}^{\\infty} \\frac{H_{n}(x)}{n !} z^{n}\\\\\n\\text{The coefficient of $z^{n}$ in the expansion of }e^{2 z x-z^{2}}&\\text{ is } \\frac{H_{n}(x)}{n !}\n\\end{align*}\n\\subsection{Orthogonal property of $H_{n}(x)$ :}\n\\begin{align*}\n\\int_{-\\infty}^{\\infty} e^{-x^{2}} H_{n}(x) H_{m}(x) d x=2^{n} n ! \\sqrt{\\pi} \\delta_{m n}\n\\end{align*}\n\\subsection{Recurrence relation for $\\mathrm{H}_{\\mathrm{n}}(\\mathbf{x})$ :}\n\\begin{enumerate}\n\t\\item $ H_{n}^{\\prime}(x)=2 n H_{n-1}(x)$\n\t\\item $ 2 x H_{n}(x)=2 n H_{n-1}(x)+H_{n+1}(x)$\n\t\\item $H_{n}^{\\prime}(x)=2 x H_{n}(x)-H_{n+1}(x)$\n\t\\item $ H_{n}^{\\prime \\prime}(x)-2 x H_{n}^{\\prime}(x)+2 n H_{n}(x)=0$\n\t\\item $  H_{n}(-x)=(-1)^{n} H_{n}(x)$\n\\end{enumerate}\n\n\\section{Laguerre Differential Equation}\n\\begin{align*}\nx \\frac{d^{2} y}{d x^{2}}+(1-x) \\frac{d y}{d x}+n y&=0\\\\\n\\text{$x=0$ is a regular singular point of the Laguerre differential }& \\text{equation.}\\\\\\\\\n\\intertext{The solution of Laguerre differentialequation is known as Laguerre polynomial of order n ,i.e. $L_{n}(x)$}\nL_{n}(x)=\\sum \\frac{(-1)^{r} n ! x^{r}}{(r !)^{2}(n-r) !}&\n\\end{align*}\n\\subsection{Rodrigue formula for $L_{n}(x)$ :}\n\\begin{enumerate}\n\t\\item $L_{n}(x)=\\frac{e^{x}}{n !} \\frac{d^{n}}{d x^{n}}\\left(x^{n} e^{-x}\\right)$ \n\t\\item $ L_{0}(x)=1 $ \n\t\\item $L_{1}(x)=1-x$\n\t\\item $L_{2}(x)=\\frac{1}{2}\\left(x^{2}-4 x+2\\right)$\n    \\item $L_{3}(x)=\\frac{1}{6}\\left(-x^{3}+9 x^{2}-18 x+6\\right)$\n\\end{enumerate}\n{Laguerre polynomials are neither even nor odd.}\n\n\n\\subsection{Generating function for Laguerre polynomial:}\n\\begin{align*}\n\\frac{e^{-x z /(1-z)}}{(1-z)}=\\sum_{n=0}^{\\infty} z^{n} L_{n}(x)\n\\end{align*}\n\\subsection{Orthogonal property of Laguerre's polynomial:}\n\\begin{align*}\n\\int_{0}^{\\infty} e^{-x} L_{n}(x) L_{m}(x) d x=\\delta_{m n}\n\\end{align*}\n\n\n\n\\newpage\n\\begin{abox}\n\tProblem Set -1\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  Let $p_{n}(x)$ (where $n=0,1,2, \\ldots \\ldots$ ) be a polynomial of degree $n$ with real coefficients, defined in the interval $2 \\leq n \\leq 4$. If $\\int_{2}^{4} p_{n}(x) p_{m}(x) d x=\\delta_{n m}$, then\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $p_{0}(x)=\\frac{1}{\\sqrt{2}}$ and $p_{1}(x)=\\sqrt{\\frac{3}{2}}(-3-x)$\n\t\t\\task[\\textbf{B.}]  $p_{0}(x)=\\frac{1}{\\sqrt{2}}$ and $p_{1}(x)=\\sqrt{3}(3+x)$\n\t\t\\task[\\textbf{C.}] $p_{0}(x)=\\frac{1}{2}$ and $p_{1}(x)=\\sqrt{\\frac{3}{2}}(3-x)$\n\t\t\\task[\\textbf{D.}] $p_{0}(x)=\\frac{1}{\\sqrt{2}}$ and $p_{1}(x)=\\sqrt{\\frac{3}{2}}(3-x)$\n\t\\end{tasks}\n\t\\item  The generating function $F(x, t)=\\sum_{n=0}^{\\infty} P_{n}(x) t^{n}$ for the Legendre polynomials $P_{n}(x)$ is $F(x, t)=\\left(1-2 x t+t^{2}\\right)^{-1 / 2}$. The value of $P_{3}(-1)$ is\n\t{\\exyear{NET/JRF(DEC-2011)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $5 / 2$\n\t\t\\task[\\textbf{B.}] $3 / 2$\n\t\t\\task[\\textbf{C.}] $+1$\n\t\t\\task[\\textbf{D.}] $-1$\n\t\\end{tasks}\n\t\\item  The graph of the function $f(x)$ shown below is best described by\n\t{\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=6cm,width=8cm]{diagram-20211005(12)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}]  The Bessel function $J_{0}(x)$\n\t\t\\task[\\textbf{B.}] $\\cos x$\n\t\t\\task[\\textbf{C.}] $e^{-x} \\cos x$\n\t\t\\task[\\textbf{D.}] $\\frac{1}{x} \\cos x$\n\t\\end{tasks}\n\t\\item Given that $\\sum_{n=0}^{\\infty} H_{n}(x) \\frac{t^{n}}{n !}=e^{-t^{2}+2 t x}$ the value of $H_{4}(0)$ is\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 12\n\t\t\\task[\\textbf{B.}] 6\n\t\t\\task[\\textbf{C.}] 24\n\t\t\\task[\\textbf{D.}] $-6$\n\t\\end{tasks}\n\t\\item   Given $\\sum_{n=0}^{\\infty} P_{n}(x) t^{n}=\\left(1-2 x t+t^{2}\\right)^{-1 / 2}$, for $|t|<1$, the value of $P_{5}(-1)$ is\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $0.26$\n\t\t\\task[\\textbf{B.}] 1\n\t\t\\task[\\textbf{C.}] $0.5$\n\t\t\\task[\\textbf{D.}] $-1$\n\t\\end{tasks}\n\t\\item The function $f(x)=\\sum_{n=0}^{\\infty} \\frac{(-1)^{n}}{n !(n+1) !}\\left(\\frac{x}{2}\\right)^{2 n+1}$, satisfies the differential equation\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}]  $x^{2} \\frac{d^{2} f}{d x^{2}}+x \\frac{d f}{d x}+\\left(x^{2}+1\\right) f=0$\n\t\t\\task[\\textbf{B.}]  $x^{2} \\frac{d^{2} f}{d x^{2}}+2 x \\frac{d f}{d x}+\\left(x^{2}-1\\right) f=0$\n\t\t\\task[\\textbf{C.}] $x^{2} \\frac{d^{2} f}{d x^{2}}+x \\frac{d f}{d x}+\\left(x^{2}-1\\right) f=0$\n\t\t\\task[\\textbf{D.}] $x^{2} \\frac{d^{2} f}{d x^{2}}-x \\frac{d f}{d x}+\\left(x^{2}-1\\right) f=0$\n\t\\end{tasks}\n\t\\item\n\t The Hermite polynomial $H_{n}(x)$, satisfies the differential equation\n\t$$\n\t\\frac{d^{2} H_{n}}{d x^{2}}-2 x \\frac{d H_{n}}{d x}+2 n H_{n}(x)=0\n\t$$\n\tThe corresponding generating function $G(t, x)=\\sum_{n=0}^{\\infty} \\frac{1}{n !} H_{n}(x) t^{n}$, satisfies the equation\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\frac{\\partial^{2} G}{\\partial x^{2}}-2 x \\frac{\\partial G}{\\partial x}+2 t \\frac{\\partial G}{\\partial t}=0$\n\t\t\\task[\\textbf{B.}] $\\frac{\\partial^{2} G}{\\partial x^{2}}-2 x \\frac{\\partial G}{\\partial x}-2 t^{2} \\frac{\\partial G}{\\partial t}=0$\n\t\t\\task[\\textbf{C.}] $\\frac{\\partial^{2} G}{\\partial x^{2}}-2 x \\frac{\\partial G}{\\partial x}+2 \\frac{\\partial G}{\\partial t}=0$\n\t\t\\task[\\textbf{D.}]  $\\frac{\\partial^{2} G}{\\partial x^{2}}-2 x \\frac{\\partial G}{\\partial x}+2 \\frac{\\partial^{2} G}{\\partial x \\partial t}=0$\n\t\\end{tasks}\n\t\\item A stable asymptotic solution of the equation $x_{n+1}=1+\\frac{3}{1+x_{n}}$ is $x=2$. If we take $x_{n}=2+\\epsilon_{n}$ and $x_{n+1}=2+\\epsilon_{n+1}$, where $\\epsilon_{n}$ and $\\epsilon_{n+1}$ are both small, the ratio $\\frac{\\epsilon_{n+1}}{\\epsilon_{n}}$ is approximately\n\t{\\exyear{NET/JRF(DEC-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-\\frac{1}{2}$\n\t\t\\task[\\textbf{B.}] $-\\frac{1}{4}$\n\t\t\\task[\\textbf{C.}]  $-\\frac{1}{3}$\n\t\t\\task[\\textbf{D.}] $-\\frac{2}{3}$\n\t\\end{tasks}\n\\item  The generating function $G(t, x)$ for the Legendre polynomials $P_{n}(t)$ is\n$$\nG(t, x)=\\frac{1}{\\sqrt{1-2 x t+x^{2}}}=\\sum_{n=0}^{\\infty} x^{n} P_{n}(t), \\text { for }|x|<1\n$$\nIf the function $f(x)$ is defined by the integral equation $\\int_{0}^{x} f\\left(x^{\\prime}\\right) d x^{\\prime}=x G(1, x)$, it can be expressed as\n{\\exyear{NET/JRF(DEC-2017)}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{A.}] $\\sum_{n, m=0}^{\\infty} x^{n+m} P_{n}(1) P_{m}\\left(\\frac{1}{2}\\right)$\n\t\\task[\\textbf{B.}] $\\sum_{n, m=0}^{\\infty} x^{n+m} P_{n}(1) P_{m}(1)$\n\t\\task[\\textbf{C.}] $\\sum_{n, m=0}^{\\infty} x^{n-m} P_{n}(1) P_{m}(1)$\n\t\\task[\\textbf{D.}] $\\sum_{n, m=0}^{\\infty} x^{n-m} P_{n}(0) P_{m}(1)$\n\\end{tasks}\n\t\\item In the function $P_{n}(x) e^{-x^{2}}$ of a real variable $x, P_{n}(x)$ is polynomial of degree $n$. The maximum number of extrema that this function can have is\n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $n+2$\n\t\t\\task[\\textbf{B.}]  $n-1$\n\t\t\\task[\\textbf{C.}] $n+1$\n\t\t\\task[\\textbf{D.}] $n$\n\t\\end{tasks}\n\t\\item The polynomial $f(x)=1+5 x+3 x^{2}$ is written as linear combination of the Legendre polynomials\n\t$\\left(P_{0}(x)=1, P_{1}(x), P_{2}(x)=\\frac{1}{2}\\left(3 x^{2}-1\\right)\\right)$ as $f(x)=\\sum_{n} c_{n} P_{n}(x)$. The value of $c_{0}$ is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{4}$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{2}$\n\t\t\\task[\\textbf{C.}]  2\n\t\t\\task[\\textbf{D.}]  4\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\t1&\\textbf{D} &2&\\textbf{D}\\\\\\hline \n\t3&\\textbf{A} &4&\\textbf{A} \\\\\\hline\n\t5&\\textbf{D} &6&\\textbf{C} \\\\\\hline\n\t7&\\textbf{A}&8&\\textbf{C}\\\\\\hline\n\t9&\\textbf{B}&10&\\textbf{C}\\\\\\hline\n\t11&\\textbf{C} &&\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\\newpage \n\\begin{abox}\n\tProblem Set -2\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item What is the maximum number of extrema of the function $f(x)=P_{k}(x) e^{-\\left(\\frac{x^{4}}{4}+\\frac{x^{2}}{2}\\right)}$, where\\\\\n\t$x \\in(-\\infty, \\infty)$ and $P_{k}(x)$ is an arbitrary polynomial of degree $k$ ?\n{\t\\exyear{JEST 2015}}\n\n\\begin{tasks}(4)\n\\task[\\textbf{A.}]  $k+2$\n\\task[\\textbf{B.}]$k+6$\n\\task[\\textbf{C.}] $k+3$\n\\task[\\textbf{D.}]$k$\n\\end{tasks}\n\\item The Bernoulli polynominals $B_{n}(s)$ are defined by, $\\frac{x e^{x s}}{e^{x}-1}=\\sum B_{n}(s) \\frac{x^{n}}{n !} .$ Which one of the following relations is true?\n{\\exyear{JEST 2015}}\n\n\\begin{tasks}(2)\n\\task[\\textbf{A.}] $\\frac{x e^{x(1-s)}}{e^{x}-1}=\\sum B_{n}(s) \\frac{x^{n}}{(n+1) !}$\n\\task[\\textbf{B.}]$\\frac{x e^{x(1-s)}}{e^{x}-1}=\\sum B_{n}(s)(-1)^{n} \\frac{x^{n}}{(n+1) !}$\n\\task[\\textbf{C.}]$\\frac{x e^{x(1-s)}}{e^{x}-1}=\\sum B_{n}(-s)(-1)^{n} \\frac{x^{n}}{n !}$\n\\task[\\textbf{D.}]$\\frac{x e^{x(1-s)}}{e^{x}-1}=\\sum B_{n}(s)(-1)^{n} \\frac{x^{n}}{n !}$\n\\end{tasks}\n\\item For which of the following conditions does the integral $\\int_{0}^{1} P_{m}(x) P_{n}(x) d x$ vanish for $m \\neq n$, where $P_{m}(x)$ and $P_{n}(x)$ are the Legendre polynomials of order $m$ and $n$ respectively?\n{\\exyear{JEST 2018}}\n\n\\begin{tasks}(2)\n\\task[\\textbf{A.}] all $m, m \\neq n$\n\\task[\\textbf{B.}]$m-n$ is an odd integer\n\\task[\\textbf{C.}]$m-n$ is a nonzero even integer\n\\task[\\textbf{D.}]$n=m \\pm 1$\n\\end{tasks}\n\\item The Euler polynomials are defined by $\\frac{2 e^{x s}}{e^{x}+1}=\\sum_{n=0}^{\\infty} E_{n}(s) \\frac{x^{n}}{n !}$What is the value of $E_{5}(2)+E_{5}(3) ?$\n{\\exyear{JEST 2019}}\n\\item If $F(x, y)=x^{2}+y^{2}+x y$, its Legendre transformed function $G(u, v)$, upto a multiplicative constant, is\n{\\exyear{JEST 2018}}\n\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $u^{2}+v^{2}+u v$\n\\task[\\textbf{B.}] $u^{2}+v^{2}-u v$\n\\task[\\textbf{C.}]$u^{2}+v^{2}$\n\\task[\\textbf{D.}]$(u+v)^{2}$\n\\end{tasks}\n\\item  Consider a function $f(x)=P_{k}(x) e^{-\\left(x^{4}+2 x^{2}\\right)}$ in the domain $x \\in(-\\infty, \\infty)$, where $P_{k}$ is any polynomial of degree $k$. What is the maximum possible number of extrema of the function?\n{\\exyear{JEST 2019}}\n\n\\begin{tasks}(4)\n\\task[\\textbf{A.}] $k+3$\n\\task[\\textbf{B.}] $k-3$\n\\task[\\textbf{C.}]$k+2$\n\\task[\\textbf{D.}]$k+1$\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{C} &2&\\textbf{D}\\\\\\hline \n\t\t3&\\textbf{A} &4&\\textbf{64} \\\\\\hline\n\t\t5&\\textbf{B} &6&\\textbf{D} \\\\\\hline\n\t\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage \n\\begin{abox}\n\tProblem Set -3\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\\item For real $n$ the cylindrical Bessel function is $J_{n}(x)$ of order $n$ then $J_{n}(x)$ will satisfied differential equation\n \\begin{tasks}(1)\n\t\\task[\\textbf{a.}]$\\frac{d^{2} J_{n}}{d x^{2}}+\\frac{1}{x}\\left(\\frac{d J_{n}}{d x}\\right)+\\left(1+\\frac{n^{2}}{x^{2}}\\right) J_{n}=0$\n\t\\task[\\textbf{b.}] $\\frac{d^{2} J_{n}}{d x^{2}}+\\frac{1}{x}\\left(\\frac{d J_{n}}{d x}\\right)+\\left(1-\\frac{n^{2}}{x^{2}}\\right) J_{n}=0$\n\t\\task[\\textbf{c.}] $\\frac{d^{2} J_{n}}{d x^{2}}+x\\left(\\frac{d J_{n}}{d x}\\right)+\\left(1+\\frac{n^{2}}{x^{2}}\\right) J_{n}=0$\n\t\\task[\\textbf{d.}] $\\frac{d^{2} J_{n}}{d x^{2}}+x\\left(\\frac{d J_{n}}{d x}\\right)+\\left(1-\\frac{n^{2}}{x^{2}}\\right) J_{n}=0$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\\text{The Bessel function is given by }\\frac{d^{2} J_{n}}{d x^{2}}+\\frac{1}{x}\\left(\\frac{d J_{n}}{d x}\\right)+\\left(1-\\frac{n^{2}}{x^{2}}\\right) J_{n}=0\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\\item For real $n$ the cylindrical Bessel function is $J_{n}(x)$ of order $n$ then value of $\\frac{d J_{0}}{d x}$ is equivalent to \n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}] $J_{1}$\n\t\\task[\\textbf{b.}]$-J_{1}$\n\t\\task[\\textbf{c.}]$2 J_{1}$\n\t\\task[\\textbf{d.}]$-2 J_{1}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\nJ_{n+1}(x)=-J_{n}^{\\prime}(x)+\\frac{n}{x} J_{n}\\text{. for }n=0, J_{1}=-J_{0}^{\\prime}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\\item  The differential equation $x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}+\\left[x^{2}-\\lambda\\right] y(x)=0$ is spherical Bessel's differential equation of order $n$ then value of $\\lambda$ is given by\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$n$\n\t\\task[\\textbf{b.}]$n(n+1)$\n\t\\task[\\textbf{c.}] $n(n-1)$\n\t\\task[\\textbf{d.}]  $n^{2}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\\text{Spherical Bessel's differential equation }x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}+\\left[x^{2}-n(n+1)\\right] y(x)=0\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\\item If $J_{n}(x)$ is spherical Bessel function of order $n$ then $j_{0}^{\\prime}(x)$ is equivalent to\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$j_{1}(x)$\n\t\\task[\\textbf{b.}]$-j_{1}(x)$\n\t\\task[\\textbf{c.}]$\\frac{j_{1}(x)}{2}$\n\t\\task[\\textbf{d.}]$-\\frac{j_{1}(x)}{2}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{d}{d x}\\left(j_{0}(x)\\right)&=\\frac{d}{d x}\\left(\\frac{\\sin x}{x}\\right)=\\frac{\\cos x}{x}-\\frac{\\sin x}{x^{2}}=-J_{1}(x)\\\\\n\t\\text{Where }j_{1}(x)&=-\\frac{\\cos x}{x}+\\frac{\\sin x}{x^{2}}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\\item The solution of the differential equation $x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}+x^{2} y(x)=0$ subjected to the condition is given by $y(0)=1$.\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}] $\\frac{\\sin x}{x}$\n\t\\task[\\textbf{b.}] $\\frac{\\cos x}{x}$\n\t\\task[\\textbf{c.}]$\\frac{\\exp (-i x)}{x}$\n\t\\task[\\textbf{d.}] $\\frac{\\exp i x}{x}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n \\text{Spherical Bessel's differential equation }&x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}+\\left[x^{2}-n(n+1)\\right] y(x)=0\\\\\n \\text{ then }x^{2} \\frac{d^{2} y}{d x^{2}}+2 x \\frac{d y}{d x}+x^{2} y(x)=0 &\\text{ is spherical Bessel's differential equation for order}\\\\\n n&=0\\\\\n\t\\text{then solution is }J_{0}(x)&=\\frac{\\sin x}{x}\\text{ with boundary condition }y(0)=1.\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item $H_{n}(x)$ is Hermite polynomials of order $n$ then $H_{n}(x)=(-1)^{n} f(x) \\frac{d^{n}(W(x))}{d x^{n}}$, then $f(x)$ and $W(x)$ are respectively\n \\begin{tasks}(1)\n\t\\task[\\textbf{a.}]$f(x)=\\exp \\left(x^{2}\\right), W(x)=\\exp \\left(-x^{2}\\right)$\n\t\\task[\\textbf{b.}]$f(x)=\\exp \\left(-x^{2}\\right), W=\\exp \\left(x^{2}\\right)$\n\t\\task[\\textbf{c.}] $f(x)=W(x)=\\exp \\left(x^{2}\\right)$\n\t\\task[\\textbf{d.}] $f(x)=W(x)=\\exp \\left(-x^{2}\\right)$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tH_{n}(x)&=(-1)^{n} \\exp \\left(x^{2}\\right) \\frac{d^{n}\\left(\\exp \\left(-x^{2}\\right)\\right)}{d x^{n}}\\\\\n\t\\text{So after comparing }H_{n}(x)&=(-1)^{n} f(x) \\frac{d^{n}(W(x))}{d x^{n}}\\\\\n\tf(x)&=\\exp \\left(x^{2}\\right), W(x)=\\exp \\left(-x^{2}\\right)\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item The solution of differential equation $\\frac{d^{2} y}{d x^{2}}-2 x \\frac{d y}{d x}+\\lambda y(x)=0$ is Hermilte polynomial of order $n$ then value of $\\lambda$ is\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$n$\n\t\\task[\\textbf{b.}] $-n$\n\t\\task[\\textbf{c.}]$2 n$\n\t\\task[\\textbf{d.}] $-2 n$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{d^{2} y}{d x^{2}}-2 x \\frac{d y}{d x}+2 n y(x)=0\\text{ is Hermite differential equation}\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item The Rodrigues formula for Laguerre polunomial is given by\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$L_n(x)=\\frac{e^{-x}}{n !}\\left(\\frac{d}{d x}\\right)^{n}\\left(x^{n} e^{-x}\\right)$\n\t\\task[\\textbf{b.}]$L_{n}(x)=\\frac{e^{x}}{n !}\\left(\\frac{d}{d x}\\right)^{n}\\left(x^{n} e^{x}\\right)$\n\t\\task[\\textbf{c.}]$L_n(x)=\\frac{e^{-x}}{n !}\\left(\\frac{d}{d x}\\right)^{n}\\left(x^{n} e^{x}\\right)$\n\t\\task[\\textbf{d.}] $L_{n}(x)=\\frac{e^{x}}{n !}\\left(\\frac{d}{d x}\\right)^{n}\\left(x^{n} e^{-x}\\right)$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tL_{n}(x)=\\frac{e^{x}}{n !}\\left(\\frac{d}{d x}\\right)^{n}\\left(x^{n} e^{-x}\\right)\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\\item It is given that operator $x-\\frac{d}{d x}=-\\exp \\left(\\frac{x^{2}}{2}\\right) \\frac{d}{d x} \\exp \\left(-\\frac{x^{2}}{2}\\right)$\nIf then the normalized wave function for harmonic oscillation is $\\psi(x)=\\left(\\pi^{1 / 2} 2^{n}\\lfloor n)^{-1 / 2} \\exp \\left(-\\frac{x^{2}}{2}\\right) H_{n}(x)\\right.$, then $\\psi_n(x)$ is equivalent to \n \\begin{tasks}(1)\n\t\\task[\\textbf{a.}]$\\psi_{n}(x)=\\left(\\pi^{1 / 2} 2^{n}\\lfloor n)^{-1 / 2}\\left(x-\\frac{d}{d x}\\right)^{n} \\exp \\left(-\\frac{x^{2}}{2}\\right)\\right.$\n\t\\task[\\textbf{b.}] $\\psi_{n}(x)=\\left(\\pi^{1 / 2} 2^{n}\\lfloor n)^{-1 / 2}\\left(x-\\frac{d}{d x}\\right)^{2 n} \\exp \\left(\\frac{x^{2}}{2}\\right)\\right.$\n\t\\task[\\textbf{c.}] $\\psi_{n}(x)=\\left(\\pi^{1 / 2} 2^{n}\\lfloor n)^{-1 / 2}\\left(x-\\frac{d}{d x}\\right)^{n} \\exp \\left(-x^{2}\\right)\\right.$\n\t\\task[\\textbf{d.}] $\\psi_{n}(x)=\\left(\\pi^{k / 2} 2^{n}\\lfloor n)^{-1 / 2}\\left(x-\\frac{d}{d x}\\right)^{2 n} \\operatorname{cxp}\\left(-x^{2}\\right)\\right.$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tH_{n}(x)&=(-1)^{n} \\exp \\left(x^{2}\\right) \\frac{d^{n}\\left(\\exp \\left(-x^{2}\\right)\\right)}{d x^{n}}\\\\\n\tx-\\frac{d}{d x} &=-\\exp \\left(\\frac{x^{2}}{2}\\right) \\frac{d}{d x} \\exp \\left(-\\frac{x^{2}}{2}\\right) \\Rightarrow\\left(x-\\frac{d}{d x}\\right) \\exp \\left(-\\frac{x^{2}}{2}\\right) \\\\ &\\left.=-\\exp \\left(\\frac{x^{2}}{2}\\right) \\frac{d}{d x} \\exp \\left(-\\frac{x^{2}}{2}\\right)\\right) \\exp \\left(-\\frac{x^{2}}{2}\\right)\\\\\n\tx \\exp \\left(-\\frac{x^{2}}{2}\\right)-\\frac{d \\exp \\left(-\\frac{x^{2}}{2}\\right)}{d x}&=-\\exp \\left(\\frac{x^{2}}{2}\\right) \\frac{d}{d x} \\exp \\left(-x^{2}\\right)\\\\\n\t\\Rightarrow\\left(x-\\frac{d}{d x}\\right) \\exp \\left(-\\frac{x^{2}}{2}\\right)&=\\exp \\left(\\frac{x^{2}}{2}\\right)\\left(-2 x \\exp \\left(-x^{2}\\right)\\right)=2 x \\exp -\\frac{x^{2}}{2}=H_{1}\\left(\\exp -\\frac{x^{2}}{2}\\right)\\\\\n\t\\text{where }2 x&=H_{1}(x)\\\\\n\t\\text{Similarly }\\left(x-\\frac{d}{d x}\\right)^{n} \\exp \\left(-\\frac{x^{2}}{2}\\right)&=H_{n} \\exp \\left(-\\frac{x^{2}}{2}\\right)\\\\\n\t\\psi_{n}(x)&=\\left(\\pi^{1 / 2} 2^{n}\\lfloor n)^{-1 / 2}\\left(x-\\frac{d}{d x}\\right)^{n} \\exp \\left(-\\frac{x^{2}}{-2}\\right)\\right.\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item The solution of differential equation $x \\frac{d^{2} y}{d x^{2}}+(1-x) \\frac{d y}{d x}+\\lambda y(x)=0$ is Laguerre polynomials of order $n$ then value of $\\lambda$ is\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$n$\n\t\\task[\\textbf{b.}]$-n$\n\t\\task[\\textbf{c.}] $2 n$\n\t\\task[\\textbf{d.}] $-2 n$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tx \\frac{d^{2} y}{d x^{2}}+(1-x) \\frac{d y}{d x}+n y(x)=0\\text{ is Laguerre differential equation.}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item The generating function $F(x, t)=\\sum_{n=0}^{\\infty} P_{n}(x) t^{n}$ for the Legendre polynomials $P_{n}(x)$ is $F(x, t)=\\left(1-2 x t+t^{2}\\right)^{-1 / 2}$. The value of $P_{2}(-1)$ is\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}]$5 / 2$\n\t\\task[\\textbf{b.}]$3 / 2$\n\t\\task[\\textbf{c.}] $+1$\n\t\\task[\\textbf{d.}] $-1$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{The generating function for Legendre polynomial is }F(x, t)&=\\left(1-2 x t+t^{2}\\right)^{-1 / 2}.\\text{ Thus}\\\\P_{2}(x)=\\frac{1}{2}\\left(3 x^{2}-1\\right) \\Rightarrow P_{2}(-1)=\\frac{1}{2}(3-1)=1\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item If we observe plot of Bessel functions $J_{0}(x), J_{1}(x)$, and $J_{2}(x)$ we find their maxima at $x_{0}, x_{1}$ and $x_{2}$ respectively. Then which of the following is true\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$x_{0}<x_{1}<x_{2}$\n\t\\task[\\textbf{b.}]$x_{0}>x_{1}>x_{2}$\n\t\\task[\\textbf{c.}]$x_{0}<x_{1}=x_{2}$\n\t\\task[\\textbf{d.}] $x_{0}=x_{1}<x_{2}$\n\\end{tasks}\n\\begin{answer}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item Which one of the following is correctly matched?\\\\\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.5cm,width=6.5cm]{SF-01}\n\\end{figure}\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}](1) $J_{0}$,\n\t(2) $J_{2}$, (3) $J_{1}$\n\t\\task[\\textbf{b.}]$(1) J_{0}$,\n\t(2) $J_{1}, \\quad(3) J_{2}$\n\t\\task[\\textbf{c.}](1) $J_{2}$,\n\t(2) $J_{1}$,\n\t(3) $J_{0}$\n\t\\task[\\textbf{d.}] None of the above\n\\end{tasks}\n\\begin{answer}\n\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\\item If the generating function of Legendre polynomial is $\\frac{1}{\\sqrt{1-6 t+t^{2}}}$, then coefficient of $t^{2}$ is\n \\begin{tasks}(4)\n\t\\task[\\textbf{a.}] 11\n\t\\task[\\textbf{b.}]$-11$\n\t\\task[\\textbf{c.}]13\n\t\\task[\\textbf{d.}] $-13$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\\intertext{The generating function for the polynomial solutions of the Legendre ODE is given by}\n\tg(x, t)&=\\frac{1}{\\sqrt{1-2 x t+t^{2}}}=\\sum_{n=0}^{\\infty} P_{n}(x) t^{n}\\\\\n\t\\text{Thus }x&=3\\text{ and }n=2.\\\\\n\tP_{2}(x)&=\\frac{1}{2}\\left(3 x^{2}-1\\right) \\Rightarrow P_{2}(3)=\\frac{1}{2}\\left(3 \\times 3^{2}-1\\right)=13\n\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\item Which of the following relation is true for Bessel's differential equation?\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$J_{0}^{\\prime}(x)=J_{1}(x)$\n\t\\task[\\textbf{b.}]$J_{0}^{\\prime}(x)=-J_{2}(x)$\n\t\\task[\\textbf{c.}]$J_{0}^{\\prime}(x)=J_{2}(x)$\n\t\\task[\\textbf{d.}] $J_{0}^{\\prime}(x)=-J_{1}(x)$\n\\end{tasks}\n\\begin{answer}\n\tSo the correct answer is \\textbf{Option (d)}\n\\end{answer}\n\\end{enumerate}", "meta": {"hexsha": "932fe724fd80716c21bc6f264620c78f30b9e8b2", "size": 56093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Special functions.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/Special functions.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/Special functions.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 58.7361256545, "max_line_length": 667, "alphanum_fraction": 0.61321377, "num_tokens": 24473, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7599922689127657}}
{"text": "\n\\subsection{Continous functions}\n\nA function is continuous if:\n\n\\(\\lim_{x\\rightarrow c} f(x)=f(c)\\)\n\nFor example a function \\(\\dfrac{1}{x}\\) is not continuous as the limit towards \\(0\\) is negative infinity. A function like \\(y=x\\) is continous.\n\nMore strictly, for any \\(\\epsilon >0\\) there exists\n\n\\(\\delta >0 \\)\n\n\\(c-\\delta < x< c +\\delta \\)\n\nSuch that\n\n\\(f(c)-\\epsilon < f(x) < f(c)+\\epsilon \\)\n\nThis means that our function is continuous at our limit \\(c\\), if for any tiny range around \\(f(c)\\), that is \\(f(c)-\\epsilon\\) and \\(f(c)+\\epsilon\\), there is a range around \\(c\\), that is \\(c-\\delta \\) and \\(c+ \\delta \\) such that all the value of \\(f(x)\\) at all of these points is within the other range.\n\n\\subsubsection{Limits}\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": "3e14d9834ba1b1d66fa2f3bf7b8d0173402d3152", "size": 1009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/propertiesFunctionsLimits/02-01-analysisContinuity.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-01-analysisContinuity.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-01-analysisContinuity.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.6764705882, "max_line_length": 308, "alphanum_fraction": 0.6709613479, "num_tokens": 296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7599828343073798}}
{"text": "\\section{Geometric interpretation of eigenvectors}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Visualize the effect of a linear transformation by\n    considering its eigenvectors and eigenvalues.\n  \\end{enumerate}\n\\end{outcome}\n\nConsider the matrix\n\\begin{equation*}\n  A = \\begin{mymatrix}{rr}\n    2 & 1 \\\\\n    1 & 2 \\\\\n  \\end{mymatrix}.\n\\end{equation*}\nIn Chapter~\\ref{cha:linear-transformation}, we saw that this matrix\ncorresponds to a linear transformation $T : \\R^2\\to\\R^2$ defined by\n$T(\\vect{x}) = A\\vect{x}$. We also saw how to visualize this linear\ntransformation as a before-and-after picture. For this, we\nconsidered the images of the first and second standard basis vectors:\n\\begin{align*}\n  T(\\vect{e}_1) &= A\\vect{e}_1 = \\begin{mymatrix}{r} 2 \\\\ 1 \\end{mymatrix}, \\\\\n  T(\\vect{e}_2) &= A\\vect{e}_2 = \\begin{mymatrix}{r} 1 \\\\ 2 \\end{mymatrix}.\n\\end{align*}\nHere is the before-and-after picture for this transformation:\n\\vspace{-2cm}\n\\begin{center}\n  \\begin{tikzpicture}\n    \\begin{scope}[scale=0.4]\n      \\draw[red,thick,fill=red!15]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n      \\draw[red,thick]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n      \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n      \\draw[blue,thick,->] (0,0) -- node[below] {$\\vect{e}_1$} (5,0);\n      \\draw[blue,thick,->] (0,0) -- node[left] {$\\vect{e}_2$} (0,5);\n    \\end{scope}\n    \\begin{scope}[xshift=3.6cm]\n      \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n    \\end{scope}\n    \\begin{scope}[xshift=7.2cm,scale=0.4]\n      \\draw[red,thick,fill=red!15,cm={2,1,1,2,(0,0)}]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n      \\draw[red,thick,cm={2,1,1,2,(0,0)}]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n      \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n      \\draw[blue,thick,->,cm={2,1,1,2,(0,0)}] (0,0) --\n      node[below right]\n      {$T(\\vect{e}_1) = \\begin{mysmallmatrix}{r}2\\\\1\\end{mysmallmatrix}$}\n      (5,0);\n      \\draw[blue,thick,->,cm={2,1,1,2,(0,0)}] (0,0) --\n      node[left,xshift=-0.1cm,pos=0.8]\n      {$T(\\vect{e}_2) = \\begin{mysmallmatrix}{c}1\\\\2\\end{mysmallmatrix}$}\n      (0,5);\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{center}\nAlthough we can see from this picture that the letter ``F'' is being\ndistorted somehow, it is perhaps not very obvious what exactly this\nlinear transformation does.\n\nWe can get a much better idea by computing the eigenvectors and\neigenvalues of $A$. A short calculation shows that the basic\neigenvectors are\n\\begin{equation*}\n  \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n  \\quad\\mbox{and}\\quad\n  \\vect{v}_2 = \\begin{mymatrix}{r} -1 \\\\ 1 \\end{mymatrix},\n\\end{equation*}\nwith corresponding eigenvalues $\\eigenvar_1=3$ and $\\eigenvar_2=1$.\nConsider the effect of the linear transformation $T$ on the\neigenvectors:\n\\begin{align*}\n  T(\\vect{v}_1) &= \\begin{mymatrix}{rr}\n    2 & 1 \\\\\n    1 & 2 \\\\\n  \\end{mymatrix} \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n  = \\begin{mymatrix}{r} 3 \\\\ 3 \\end{mymatrix}\n  = 3\\vect{v}_1, \\\\\n  T(\\vect{v}_2) &= \\begin{mymatrix}{rr}\n    2 & 1 \\\\\n    1 & 2 \\\\\n  \\end{mymatrix} \\begin{mymatrix}{r} -1 \\\\ 1 \\end{mymatrix}\n  = \\begin{mymatrix}{r} -1 \\\\ 1 \\end{mymatrix}\n  = \\vect{v}_2.\n\\end{align*}\nSo each eigenvector is mapped to a scalar multiple of itself. This\ngives us a hint for how to draw a more useful before-and-after\npicture. Rather than tracking the movement of the standard basis\nvectors $\\vect{e}_1$ and $\\vec{e}_2$, let us track the movement of the\neigenvectors $\\vect{v}_1$ and $\\vect{v}_2$ instead:\n\\vspace{-0.8cm}\n\\begin{center}\n  \\begin{tikzpicture}\n    \\begin{scope}[scale=0.4]\n      \\draw[red!20,thick,fill=red!8,rotate=45]\n      (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n      \\draw[red,thick,fill=red!15,rotate=45]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n      \\draw[red,thick,rotate=45]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n      \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n      \\draw[blue,thick,->] (0,0) -- node[below right] {$\\vect{v}_1$} (5,5);\n      \\draw[blue,thick,->] (0,0) -- node[below left] {$\\vect{v}_2$} (-5,5);\n    \\end{scope}\n    \\begin{scope}[xshift=3.6cm]\n      \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n    \\end{scope}\n    \\begin{scope}[xshift=7.2cm,scale=0.4]\n      \\draw[red!20,thick,fill=red!8,rotate=45,xscale=3]\n      (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n      \\draw[red,thick,fill=red!15,rotate=45,xscale=3]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n      \\draw[red,thick,rotate=45,xscale=3]\n      (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n      (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n      \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n      \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n      \\draw[blue,thick,->,cm={2,1,1,2,(0,0)}] (0,0) --\n      node[below right]\n      {$T(\\vect{v}_1) = 3\\vect{v}_1$}\n      (5,5);\n      \\draw[blue,thick,->,cm={2,1,1,2,(0,0)}] (0,0) --\n      node[below left,pos=0.6]\n      {$T(\\vect{v}_2) = \\vect{v}_2$}\n      (-5,5);\n    \\end{scope}\n  \\end{tikzpicture}\n\\end{center}\nThus, the linear transformation described by the matrix $A$ is\nrevealed to be just a scaling by a factor of $3$ along the direction of\n\\begin{equation*}\n  \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}.\n\\end{equation*}\nIn summary, the geometric meaning of an eigenvector is that it is\nmapped to a multiple of itself. Thus, when viewed from the point of\nview of its action on the eigenvectors, a linear transformation\nbehaves like a scaling of each eigenvector. We can say that each\neigenvector describes a direction of scaling, and each corresponding\neigenvalue giving the corresponding (positive or negative) scaling\nfactor.\n\n\\begin{example}{Visualize a linear transformation}{visualize-eigenvectors-1}\n  Visualize the linear transformation $T:\\R^2\\to\\R^2$ that is\n  described by the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      0 & 1 \\\\\n      1 & 0 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  by considering the eigenvectors and eigenvalues.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is $\\eigenvar^2-1$, and so the\n  eigenvalues are $\\eigenvar_1=1$ and $\\eigenvar_2=-1$. By solving each\n  equation $(A-\\eigenvar I)\\vect{v}=\\vect{0}$, we find that the\n  corresponding basic eigenvectors are\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} -1 \\\\ 1 \\end{mymatrix}\n  \\end{equation*}\n (check this!). We get the following before-and-after\n  picture:\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[scale=0.5]\n        \\draw[red!20,thick,fill=red!8,rotate=45]\n        (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n        \\draw[red,thick,fill=red!15,rotate=45]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[red,thick,rotate=45]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->] (0,0) -- node[below right] {$\\vect{v}_1$} (5,5);\n        \\draw[blue,thick,->] (0,0) -- node[below left] {$\\vect{v}_2$} (-5,5);\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=9cm,scale=0.5]\n        \\draw[red!20,thick,fill=red!8,rotate=45,yscale=-1]\n        (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n        \\draw[red,thick,fill=red!15,rotate=45,yscale=-1]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[red,thick,rotate=45,yscale=-1]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->,cm={0,1,1,0,(0,0)}] (0,0) --\n        node[above left,pos=0.4]\n        {$T(\\vect{v}_1) = \\vect{v}_1$}\n        (5,5);\n        \\draw[blue,thick,->,cm={0,1,1,0,(0,0)}] (0,0) --\n        node[below left,pos=0.5]\n        {$T(\\vect{v}_2) = -\\vect{v}_2$}\n        (-5,5);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  We see that this linear transformation is a reflection about the\n  vector $\\vect{v}_1$.\n\\end{solution}\n\n\\begin{example}{Visualize a linear transformation}{visualize-eigenvectors-2}\n  Visualize the linear transformation $T:\\R^2\\to\\R^2$ that is\n  described by the matrix\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      -2 & 3 \\\\\n      0 &  1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  by considering the eigenvectors and eigenvalues.\n\\end{example}\n\n\\begin{solution}\n  The characteristic polynomial is $(-2-\\eigenvar)(1-\\eigenvar)$, and\n  therefore, the eigenvalues are $\\eigenvar_1=-2$ and $\\eigenvar_2=1$.\n  We find that the corresponding basic eigenvectors are\n  \\begin{equation*}\n    \\vect{v}_1 = \\begin{mymatrix}{r} 1 \\\\ 0 \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}_2 = \\begin{mymatrix}{r} 1 \\\\ 1 \\end{mymatrix},\n  \\end{equation*}\n  respectively. We get the following before-and-after picture:\n  \\begin{center}\n    \\begin{tikzpicture}\n      \\begin{scope}[scale=0.5]\n        \\draw[red!20,thick,fill=red!8,cm={1,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n        \\draw[red,thick,fill=red!15,cm={1,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[red,thick,cm={1,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->,cm={1,0,1,1,(0,0)}] (0,0) -- node[below,yshift=-.1cm] {$\\vect{v}_1$} (5,0);\n        \\draw[blue,thick,->,cm={1,0,1,1,(0,0)}] (0,0) -- node[above left] {$\\vect{v}_2$} (0,5);\n      \\end{scope}\n      \\begin{scope}[xshift=4.5cm]\n        \\path (0,0) node {$\\stackrel{T}{\\longmapsto}$};\n      \\end{scope}\n      \\begin{scope}[xshift=10.5cm,scale=0.5]\n        \\draw[red!20,thick,fill=red!8,cm={-2,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (5,5) -- (5,0) -- cycle;\n        \\draw[red,thick,fill=red!15,cm={-2,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[step=1cm, gray!50, very thin] (-5.8,-5.8) grid (5.8,5.8);\n        \\draw[red,thick,cm={-2,0,1,1,(0,0)}]\n        (0,0) -- (0,5) -- (3,5) -- (3,4) -- (1,4) --\n        (1,3) -- (2,3) -- (2,2) -- (1,2) -- (1,0) -- cycle;\n        \\draw[semithick,->] (-6.5,0) -- (6.5,0);\n        \\draw[semithick,->] (0,-6.5) -- (0,6.5);\n        \\draw[blue,thick,->,cm={-2,0,1,1,(0,0)}] (0,0) --\n        node[below]\n        {$T(\\vect{v}_1) = -2\\vect{v}_1$}\n        (5,0);\n        \\draw[blue,thick,->,cm={-2,0,1,1,(0,0)}] (0,0) --\n        node[below right,pos=0.5]\n        {$T(\\vect{v}_2) = \\vect{v}_2$}\n        (0,5);\n      \\end{scope}\n    \\end{tikzpicture}\n  \\end{center}\n  This particular linear transformation keeps the vector $\\vect{v}_2$\n  fixed, while scaling by a factor of $-2$ in the direction of\n  $\\vect{v}_1$. It could be described as a kind of slanted reflection\n  with scaling.\n\\end{solution}\n", "meta": {"hexsha": "16633c8a9416037ca7ac9a1681845c8e9ec589c2", "size": 12374, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Eigenvalues-Geometric.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Eigenvalues-Geometric.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Eigenvalues-Geometric.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 41.3846153846, "max_line_length": 103, "alphanum_fraction": 0.537417165, "num_tokens": 5326, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.843895106480586, "lm_q2_score": 0.9005297907896396, "lm_q1q2_score": 0.7599526836873627}}
{"text": "\\subsection{An Algebraic Relation}\r\nAlthough $\\wp_\\Lambda$ is so far just an example of an elliptic function, it will be the key to classify all of them.\r\nFirst, we relate $\\wp_\\Lambda^\\prime$ to $\\wp_\\Lambda$ algebraically.\r\n\\begin{proposition}\\label{elliptic_wp}\r\n    There exists constant $g_2,g_3\\in\\mathbb C$, depending only on $\\Lambda$, such that\r\n    $$(\\wp^\\prime)^2=4\\wp^3-g_2\\wp-g_3$$\r\n    where $\\wp=\\wp_\\Lambda$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Near $0$, we have $\\wp(z)=z^{-2}+az^2+o(z^4)$ for some constant $a$ as $\\wp$ is even and looks like $z^{-2}$ near $0$.\r\n    So $\\wp(z)^3=z^{-6}+f(z)$ for some analytic $f$.\r\n    Differentiating this Laurent series gives $\\wp^\\prime(z)=-2z^{-3}+2az+o(z^3)$, therefore $\\wp^\\prime(z)^2=4z^{-6}-8az^{-2}+g(z)$ for some analytic $g$.\r\n    These would give\r\n    $$\\wp^\\prime(z)^2=4\\wp(z)^3-8az^{-2}-h(z)$$\r\n    where $h$ is analytic.\r\n    Setting $g_2=8a$ gives $(\\wp^\\prime)^2-4\\wp^3+g_2\\wp$ is analytic, has no poles, and doubly periodic, hence constant.\r\n    Setting this constant as $-g_3$ completes the proof.\r\n\\end{proof}\r\nThese constants $g_2,g_3$ actually relates to the branch points $e_1,e_2,e_3$.\r\n\\begin{remark}\r\n    When $z\\in (1/2)\\Lambda\\setminus\\Lambda$, we have $\\wp^\\prime(z)=0$ and $\\wp(z)=e_i$ for some $i$.\r\n    Then the preceding proposition means that $0=4e_i^3-g_2e_i-g_3$, so $e_1,e_2,e_3$ are exactly the three roots of $4z^3-g_2z-g_3$.\r\n    In particular, $e_1+e_2+e_3=0$.\r\n    Conversely, we can rewrite the relation as\r\n    $$\\wp^\\prime=4(\\wp-e_1)(\\wp-e_2)(\\wp-e_3)$$\r\n\\end{remark}", "meta": {"hexsha": "2867ef9a58fcde3d572d38430e7e33658aed8bd3", "size": 1570, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/alg.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/alg.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/alg.tex", "max_forks_repo_name": "david-bai-notes/II-Riemann-Surfaces", "max_forks_repo_head_hexsha": "cbda76f7189c679c4aaccf030b70d310823ead3f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.3846153846, "max_line_length": 156, "alphanum_fraction": 0.6477707006, "num_tokens": 573, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297887874625, "lm_q2_score": 0.8438951005915208, "lm_q1q2_score": 0.7599526766944567}}
{"text": "\\subsubsection{Potential Functions}\r\n\\noindent\r\nNote that the FTC for line integrals doesn't care about the specific path taken between two points, but only the starting and ending points. Any paths that started and ended at the same points would have the same values, and paths that start and end at the same point would have a value of 0.\\\\\r\nSo, \r\n\\begin{equation*}\r\n\t\\oint\\limits_{C}{\\nabla f \\cdot \\mathrm{d}\\vec{r}} = 0.\r\n\\end{equation*}\r\nSo, by our theorem that says all $\\vec{F}$ such that $\\oint\\limits_{C}{\\vec{F} \\cdot \\mathrm{d}\\vec{r}} = 0$ are conservative, all vector fields $\\vec{F} = \\nabla f$ are conservative. $f$ is called the potential function of $\\vec{F}$.\\\\\r\n\r\n\\noindent\r\nYou might recognize potential functions from physics. All conservative forces, like the force of gravity, have a potential energy function. For gravitational force, $U(r) = -\\frac{GMm}{r}$ and $\\vec{F_g}(r) = \\frac{GMm}{r^2}\\hat{r}$ where $\\hat{r}$ is a radial unit vector pointing away from the object to which the force is applied.", "meta": {"hexsha": "a7537deef1626b813e642ea5776fedab48e00d53", "size": 1028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/lineSurfaceIntegrals/potentialFunctions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/lineSurfaceIntegrals/potentialFunctions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/lineSurfaceIntegrals/potentialFunctions.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": 93.4545454545, "max_line_length": 333, "alphanum_fraction": 0.7256809339, "num_tokens": 293, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9005297754396142, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7599526636625134}}
{"text": "\n\\subsection{Entropy}\n\n\\subsubsection{Introduction}\n\nEntropy measures the expected amount of information produced by a source.\n\n\\(H(P(x))=E(I(P(x))\\)\n\nEntropy is similar to variance, is the sense that both measure uncertainty.\n\nEntropy, however, has no references to specific values of \\(x\\). If all values were multiplied by 100, or if parts of the distribution were cut up and swapped, entropy would be unaffected.\n\nFor a probability function \\(p(z)\\), its entropy is :\n\n\\(H(p)=-\\int p(z)\\ln p(z)dz\\).\n\nThis is a measure of the spread of a distribution.\n\nNegative infinity means no uncertainty\n\nFor a multivariate gaussian \\(H=d/2 ln(2\\pi e|\\Sigma)\\).\n\n", "meta": {"hexsha": "238931e93353bb33f43addbaa4cb1b5a60cfc91c", "size": 655, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/entropy/01-02-entropy.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/entropy/01-02-entropy.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/entropy/01-02-entropy.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.2916666667, "max_line_length": 188, "alphanum_fraction": 0.7358778626, "num_tokens": 159, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9294403959948494, "lm_q2_score": 0.8175744828610095, "lm_q1q2_score": 0.7598867511056209}}
{"text": "\\subsection{Polynomial interpolation}\n\nIn studying a set of data that relates variables $x$ and $y$, it may be the case that we can use a polynomial to ``fit'' to the data. If such a polynomial can be established, it can be used to estimate values of $x$ and $y$ which have not been provided.\n\nConsider the following example.\n\n\\begin{example}{Polynomial interpolation}{polynomial-interpolation}\nGiven data points $(1,4), (2,9), (3,12)$, find an interpolating polynomial $p(x)$ of degree at most $2$ and then estimate the value corresponding to $x = \\frac{1}{2}$.\n\\end{example}\n\n\\begin{solution}\nWe want to find a polynomial given by\n\\[\np(x) = r_0 + r_1x_1 + r_2x_2^2\n\\]\nsuch that $p(1)=4, p(2)=9$ and $p(3)=12$.\nTo find this polynomial, substitute the known values in for $x$ and solve for $r_0, r_1$, and $r_2$.\n\\begin{eqnarray*}\np(1) &=& r_0 + r_1 + r_2 = 4\\\\\np(2) &=& r_0 + 2r_1 + 4r_2 = 9\\\\\np(3) &=& r_0 + 3r_1 + 9r_2 = 12\n\\end{eqnarray*}\n\nWriting the augmented matrix, we have\n\\[\n\\begin{mymatrix}{rrr|r}\n1 & 1 & 1 & 4 \\\\\n1 & 2 & 4 & 9  \\\\\n1 & 3 & 9 & 12\n\\end{mymatrix}\n\\]\n\nAfter row operations, the resulting matrix is\n\\[\n\\begin{mymatrix}{rrr|r}\n1 & 0 & 0 & -3 \\\\\n0 & 1 & 0 & 8 \\\\\n0 & 0 & 1 & -1\n\\end{mymatrix}\n\\]\n\nTherefore the solution to the system is $r_0 = -3, r_1 = 8, r_2 = -1$ and the required interpolating polynomial is\n\\[\np(x) = -3 + 8x - x^2\n\\]\n\nTo estimate the value for $x = \\frac{1}{2}$, we calculate $p(\\frac{1}{2})$:\n\\begin{eqnarray*}\np(\\frac{1}{2}) &=& -3 + 8(\\frac{1}{2}) - (\\frac{1}{2})^2\\\\\n&=& -3 + 4 - \\frac{1}{4} \\\\\n&=& \\frac{3}{4}\n\\end{eqnarray*}\n\\end{solution}\n\nThis procedure can be used for any number of data points, and any degree of polynomial. The steps are outlined below.\n\n\\begin{procedure}{Finding an interpolating polynomial}{finding-inter-polynomial}\nSuppose that values of $x$ and corresponding values of $y$ are given, such that the actual relationship between $x$ and $y$ is unknown. Then, values of $y$ can be estimated using an \\textbf{interpolating polynomial $p(x)$}. If given $x_1, ..., x_n$ and the corresponding $y_1, ..., y_n$, the procedure to find $p(x)$ is as follows:\n\\begin{enumerate}\n\\item The desired polynomial $p(x)$ is given by\n\\[\np(x) = r_0 + r_1 x + r_2 x^2 + ... + r_{n-1}x^{n-1}\n\\]\n\\item $p(x_i) = y_i$ for all $i = 1, 2, ...,n$ so that\n\\[\n\\begin{array}{c}\nr_0 + r_1x_1 + r_2 x_1^2 + ... + r_{n-1}x_1^{n-1} = y_1 \\\\\nr_0 + r_1x_2 + r_2 x_2^2 + ... + r_{n-1}x_2^{n-1} = y_2 \\\\\n\\vdots \\\\\nr_0 + r_1x_n + r_2 x_n^2 + ... + r_{n-1}x_n^{n-1} = y_n\n\\end{array}\n\\]\n\\item Set up the augmented matrix of this system of equations\n\\[\n\\begin{mymatrix}{rrrrr|r}\n1 & x_1 & x_1^2 & \\cdots & x_1^{n-1} & y_1 \\\\\n1 & x_2 & x_2^2 & \\cdots & x_2^{n-1} & y_2 \\\\\n\\vdots & \\vdots & \\vdots & &\\vdots & \\vdots \\\\\n1 & x_n & x_n^2 & \\cdots & x_n^{n-1} & y_n \\\\\n\\end{mymatrix}\n\\]\n\n\\item Solving this system will result in a unique solution $r_0, r_1,\\ldots, r_{n-1}$. Use these values to construct $p(x)$, and estimate the value of $p(a)$ for any $x=a$.\n\\end{enumerate}\n\n\\end{procedure}\n\nThis procedure motivates the following theorem.\n\n\\begin{theorem}{Polynomial interpolation}{polynomial-interpolation}\nGiven $n$ data points $(x_1, y_1), (x_2, y_2),\\ldots, (x_n, y_n)$ with the $x_i$ distinct, there is a unique polynomial $p(x) = r_0 + r_1x + r_2x^2 + \\ldots + r_{n-1}x^{n-1}$ such that $p(x_i) = y_i$ for $i=1,2,\\ldots, n$. The resulting polynomial $p(x)$ is called the \\textbf{interpolating polynomial} for the data points.\n\\end{theorem}\n\nWe conclude this section with another example.\n\n\\begin{example}{Polynomial interpolation}{polynomial-interpolation2}\nConsider the data points $(0,1), (1,2), (3,22), (5,66)$. Find an interpolating polynomial $p(x)$ of degree at most three, and estimate the value of $p(2)$.\n\\end{example}\n\n\\begin{solution}\nThe desired polynomial $p(x)$ is given by:\n\\[\np(x) = r_0 + r_1 x + r_2x^2 + r_3x^3\n\\]\n\nUsing the given points, the system of equations is\n\\begin{eqnarray*}\np(0) &=& r_0 = 1 \\\\\np(1) &=& r_0 + r_1 + r_2 + r_3 = 2 \\\\\np(3) &=& r_0 + 3r_1 + 9r_2 + 27r_3 = 22 \\\\\np(5) &=& r_0 + 5r_1 + 25r_2 + 125r_3 = 66\n\\end{eqnarray*}\n\nThe augmented matrix is given by:\n\\[\n\\begin{mymatrix}{rrrr|r}\n1 & 0 & 0 & 0 & 1 \\\\\n1 & 1 & 1 & 1 & 2 \\\\\n1 & 3 & 9 & 27 & 22 \\\\\n1 & 5 & 25 & 125 & 66\n\\end{mymatrix}\n\\]\n\nThe resulting matrix is\n\\[\n\\begin{mymatrix}{rrrr|r}\n1 & 0 & 0 & 0 & 1 \\\\\n0 & 1 & 0 & 0 & -2 \\\\\n0 & 0 & 1 & 0 & 3 \\\\\n0 & 0 & 0 & 1 & 0\n\\end{mymatrix}\n\\]\n\nTherefore, $r_0 = 1, r_1 = -2, r_2 = 3, r_3 = 0$ and $p(x) = 1 -2x + 3x^2$. To estimate the value of $p(2)$, we compute $p(2) = 1 -2(2) + 3(2^2) = 1 - 4 + 12 = 9$.\n\\end{solution}", "meta": {"hexsha": "8674a1c3ccd15f998629e1744e14955a8f1acf14", "size": 4600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/determinantsApplicationsPolynomialInterpolation.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/determinantsApplicationsPolynomialInterpolation.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/determinantsApplicationsPolynomialInterpolation.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.0740740741, "max_line_length": 331, "alphanum_fraction": 0.6284782609, "num_tokens": 1876, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8175744673038222, "lm_q2_score": 0.9294403969720817, "lm_q1q2_score": 0.7598867374451027}}
{"text": "\\subsection{The Likelihood of Fitting Parameters}\n\\label{subsec:likelihood}\n\nFor our fit, we assume a $9^{\\rm th}$ degree polynomial, and use a smoothing prior to prevent over-fitting. We fit this model to the points from the histogram rate, $r(x)$, obtained in \\S\\ref{sec:density}. The data likelihood is\n%\n\\begin{align}\n  \\ln p( &\\qty{r(x_k)}_k | \\lambda ) = \\notag\n  \\\\ &\n -\\frac{1}{2}\n  \\sum_k\n  \\qty{\\frac{[r(x_k) - F_\\alpha(x_k) \\lambda_\\alpha]^2}{\\sigma_{r(x_k)}^2}},\n%\n  \\label{likelihood}\n\\end{align}\n%\nwhere $F_\\alpha(x) = x^\\alpha$.\n\n$\\ln p_{\\rm smooth}$ is the smoothing prior, defined to be:\n\n\\begin{equation}\n  \\ln p_{\\rm smooth}(\\lambda) =\n -\\gamma \\int_{x_{\\min}}^{x_{\\max}}\n  \\qty[ \\dv[n]{F_\\alpha(x)}{x} \\lambda_\\alpha ]^2 \\dd{x}\n%\n  \\label{smoothing_prior}\n\\end{equation}\n\nIn theory, $p_{\\rm smooth}$ can be any $n^{\\rm th}$ derivative. To make our code robust, we define a function that takes n as an argument. The function then calls \\texttt{numpy.polynomial.polynomial.polyder()} to find the $n^{\\rm th}$ derivative. Next, we square the $n^{\\rm th}$ derivative and integrate it between the minimum and maximum of $x$. Here we choose $n = 3$, and let $\\gamma = 0.5$.", "meta": {"hexsha": "b4918f23fd2825a79af81145f6b27aac191c3ebd", "size": 1187, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "subsec_likelihood.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_likelihood.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_likelihood.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": 42.3928571429, "max_line_length": 395, "alphanum_fraction": 0.6739679865, "num_tokens": 393, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9489172644875642, "lm_q2_score": 0.8006919949619793, "lm_q1q2_score": 0.759790457556412}}
{"text": "\\documentclass[12pt]{amsart}\n\n\\title{First Order Autonomous Differential Equations}\n\n\\begin{document}\n\\maketitle\n\n\\section{Introduction}\nA first order, autonomous differential equation is of the form:\n$$\ny'=f(y)\n$$\n\\begin{enumerate}\n\\item A direction field is a plot of local slopes where the axes\nare $t$ and $y$.  A {\\it phase plot} is a plot of $y'$ versus $y$.\n\\item An {\\it equilibrium solution} is a constant solution,\n$y(t)=c$ so that $f(c)=0$.  These solutions are also called {\\it\nfixed points} or {\\it critical points}.\n\\item An equilibrium solution is said to be an {\\it attracting}\nsolution if there is an interval of initial values about $y=c$ so\nthat all solutions tend to $c$ as $t\\rightarrow \\infty$.\n\\item An equilibrium solution is said to be a {\\it repelling}\nsolution if there is an interval about $y=c$ so that all solutions\ntend away from $y=c$.\n\\end{enumerate}\n\n\\section{Goal of the Lab}\nThe goal of this lab is to explore first order autonomous\ndifferential equations, learn some vocabulary associated with\nthem, and to do graphical analysis of the solutions.\n\n\\section{Lab Questions}\n\\begin{enumerate}\n\\item From your last lab, you discussed the direction field for\nDEs of the form $y'=f(y)$.  Use your conclusions to discuss the\nfollowing observation:\n\n\\begin{quote}\n``No solution to $y'=f(y)$ can oscillate.  All solutions will\neither be constant, monotone increasing, or monotone decreasing.''\n\\end{quote}\n\n\\item The relationship of the phase plot to the direction field:\nSuppose we are given the differential equation:\n$$\ny'=f(y)=\\frac{1}{10}y(3-y)(y+1)^2\n$$\n\\begin{enumerate}\n\\item Graph $f(y)$ versus $y$ and compare this to the direction\nfield.  Is it possible to predict the long term behavior of a\nparticular solution by its position in the phase plot?\n\\item What are the equilibrium solutions?  Classify each as {\\it\nattracting, repelling,} or {\\it neither}.  For each equilibrium,\nwas it possible to predict this based only on the phase plot?\nHint:  Consider $\\frac{df}{dy}$ at each equilibrium.\n\\item Comment on the following observation for autonomous, first\norder equations:\n\\begin{quote}\n``The behavior of all solutions to $y'=f(y)$ is organized around\nthe equilibrium solutions''\n\\end{quote}\n\\end{enumerate}\n\\item Consider the family of differential equations of the form:\n$$\ny'=ky-y^3\n$$\nwhere $k$ is a constant.\n\\begin{enumerate}\n\\item Solve for the equilibrium solutions in terms of $k$ (you can\ndo this by hand).\n\\item Perform a phase plot for different values of $k$, and state\nin words the effect that $k$ has on the graph of $ky-y^3$.\nConsider the following situations:\n\\begin{itemize}\n\\item If $k<0$, how many equilibria are there, and what type are\nthey?\n\\item If $k=0$, answer the same question.\n\\item If $k>0$, answer the same question.\n\\end{itemize}\n\\end{enumerate}\n\n{\\it Side Remark:  The phenomena you are talking about is called a\n{\\bf bifurcation}- that is, changing a parameter results in the\ncreation/destruction of equilibrium solutions!  In fact, this\nparticular situation is called a {\\bf pitchfork bifurcation}.}\n\\item Some general questions:\n\\begin{enumerate}\n\\item Is it possible to have two attracting equilibria with no\nrepelling equilibrium in between?  To answer this, consider the\nphase plot of $f(y)$ versus $y$.\n\\item Construct your own autonomous, first order differential\nequation modeling population, that would have the correspond to\nthe following behavior:\n\n``If the population falls below 2, the population dies off.  If\nthe population is above 2 and less than 20, the population will\ntend to 20.  If the population is greater than 20, there is not\nenough food so the population will tend back towards 20.''\n\nVerify the behavior by providing a phase plot and direction field.\n\n\n\\end{enumerate}\n\\end{enumerate}\n\n\\end{document}\n", "meta": {"hexsha": "76b51fe2fbc88ec9150d7c3772feed2afa2880a4", "size": 3804, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lab2.tex", "max_stars_repo_name": "perfectbark/LaTex2Docx", "max_stars_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2019-06-16T06:00:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T14:44:32.000Z", "max_issues_repo_path": "lab2.tex", "max_issues_repo_name": "hao-han/LaTex2Docx", "max_issues_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lab2.tex", "max_forks_repo_name": "hao-han/LaTex2Docx", "max_forks_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2019-05-27T06:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T10:22:07.000Z", "avg_line_length": 35.5514018692, "max_line_length": 66, "alphanum_fraction": 0.7555205047, "num_tokens": 981, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528019683105, "lm_q2_score": 0.8918110526265555, "lm_q1q2_score": 0.7597809251115023}}
{"text": "\\chapter{Representations}\r\n\\section {${\\mathbb C}G$-modules}\r\n{\\bf Definition:} A \\emph{representation} of $G$ is a group\r\nhomomorphism $\\rho: G \\rightarrow GL_n({\\mathbb C})$, \r\n$n$ is called the \\emph{degree} of $\\rho$.\r\nThe representation $\\rho: G \\rightarrow GL_n({\\mathbb C})$ is\r\ncalled \\emph{faithful} if $ker(\\rho) =\\{1\\}$.\r\nThus $\\rho$ is faithful if the only element $g\\in G$ with $\\rho(g)=I_n$ is the\r\nidentity of $G$. \r\n\\\\\r\n\\\\\r\n{\\bf Theorem 1:} A representation $\\rho$ of $G$ is faithful if\r\nand only if $im(\\rho) \\cong G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe have $G/ker(\\rho) \\cong im(\\rho)$ so if $ker(\\rho)=\\{1\\}$, the\r\nisomorphism theorem gives \r\n$G \\cong im(\\rho)$.\r\nConversely if $G \\cong im(\\rho)$ then these two finite groups\r\nhave the same order, and so $|ker(\\rho)|=1$.\r\n\\end{quote}\r\n{\\bf Definition:} A finite-dimensional vector space $V$ over ${\\mathbb C}$ is a\r\n\\emph{${\\mathbb C}G$-module} if a multiplication $gv$ (for all $g\\in G$ and $v\\in V$) is\r\ndefined, satisfying the following conditions for all\r\n$u,v\\in V$, $\\lambda \\in {\\mathbb C}$ and $g \\in G$:\r\n\\begin{itemize}\r\n\\item[(i)] $gv\\in V$;\r\n\\item[(ii)] $(gh)v=g(hv)$;\r\n\\item[(iii)] $1v=v$;\r\n\\item[(iv)] $g(\\lambda v)=\\lambda(gv)$;\r\n\\item[(v)] $g(u+v)=gu+gv$.\r\n\\end{itemize}\r\n{\\bf Definition:}\r\nIf $V$ is a ${\\mathbb C}G$-module, $g$ induces a linear map\r\n$\\rho(g): V \\rightarrow V$;\r\nif ${\\cal B}$ is a basis of $V$, the matrix for the matrix representing the linear\r\nmap $\\rho(g)$ is denoted by $[g]_{\\cal B}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 2:} Let $G$ be a finite group.\r\n\\begin{itemize}\r\n\\item[(i)] Given a representation\r\n$\\rho: G \\rightarrow GL_n({\\mathbb C})$, the vector space $V= {\\mathbb C}^n$ is a\r\n${\\mathbb C}G$-module\r\nif we define the multiplication by $gv=\\rho(g)v$ for all $g\\in G$ and\r\n$v \\in V$. Moreover, there is a basis ${\\cal B}$ of $V$ such that\r\n$\\rho(g)=[g]_{\\cal B}$ for all $g\\in G$.\r\n\\item[(ii)] Given a ${\\mathbb C}G$-module $V$ of dimension $n>0$ with basis ${\\cal B}$, the\r\nfunction $\\rho: G \\rightarrow GL_n({\\mathbb C})$ defined by $\\rho(g)=[g]_{\\cal B}$ is a\r\nrepresentation of $G$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n(i) For all $u,v\\in {\\mathbb C}^n$, $\\lambda\\in{\\mathbb C}$ and\r\n$g,h\\in G$ we have\r\n\\begin{eqnarray*}\r\n\\rho(g)v\\!\\!\\!\\!&\\in&\\!\\!\\!\\!{\\mathbb C}^n,\\\\\r\n\\rho(gh)v\\!\\!\\!\\!&=&\\!\\!\\!\\!\\rho(g)\\rho(h)v,\\\\\r\n\\rho(1)v\\!\\!\\!\\!&=&\\!\\!\\!\\!v,\\\\\r\n\\rho(g)(\\lambda v)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\lambda\\rho(g)v,\\\\\r\n\\rho(g)(u+v)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\rho(g)u+\\rho(g)v.\r\n\\end{eqnarray*}\r\nDefining $gv=\\rho(g)v$ for all $g\\in G$ and $v\\in {\\mathbb C}^n$ makes\r\n${\\mathbb C}^n$ into a ${\\mathbb C}G$-module. Moreover, if we let ${\\cal B}$ be the basis\r\n$$\\begin{matrix}1\\\\0\\\\0\\\\\\vdots\\\\0\\end{matrix},\\qquad\r\n\\begin{matrix}0\\\\1\\\\0\\\\\\vdots\\\\0\\end{matrix},\\qquad\\cdots,\\qquad\r\n\\begin{matrix}0\\\\0\\\\0\\\\\\vdots\\\\1\\end{matrix}$$\r\nof ${\\mathbb C}^n$, then we have $\\rho(g)=[g]_{\\cal B}$ for all $g\\in G$.\r\n\\\\\r\n\\\\\r\n(ii) Let $V$ be a ${\\mathbb C}G$-module with basis ${\\cal B}$. Since\r\n$(gh)v=g(hv)$ for all $g,h\\in G$ and all $v$ in the basis ${\\cal B}$, it follows that\r\n$[gh]_{\\cal B}=[g]_{\\cal B}[h]_{\\cal B}$. In particular, \r\n$[1]_{\\cal B}=[g]_{\\cal B}[g^{-1}]_{\\cal B}$ for all\r\n$g\\in G$. Now we have $1v=v$ for all $v\\in V$, so $[1]_{\\cal B}$ is the identity\r\nmatrix $I_n$; thus each matrix $[g]_{\\mathbb B}$ is invertible (with inverse\r\n$[g^{-1}]_{\\cal B}$). Hence the function $g\\mapsto [g]_{\\cal B}$ is a homomorphism from\r\n$G$ to $GL_n({\\mathbb C})$, i.e., a representation of $G$.\r\n\\end{quote}\r\n{\\bf Theorem 3:} Let $V$ be a ${\\mathbb C}G$-module with basis ${\\cal B}$, and\r\nlet $\\rho$ be the representation of $G$ defined by $\\rho(g)=[g]_{\\cal B}$ for all\r\n$g\\in G$. Then\r\n\\begin{itemize}\r\n\\item[(i)] if ${\\cal B}'$ is a basis of $V$, the representation $\\phi$ of\r\n$G$ defined by $\\phi(g)=[g]_{{\\cal B}'}$ for all $g\\in G$ is equivalent to $\\rho$;\r\n\\item[(ii)] if $\\sigma$ is a representation of $G$ which is equivalent to\r\n$\\rho$, there is a basis ${\\cal B}''$ of $V$ such that $\\sigma(g)=[g]_{{\\cal B}''}$ for all\r\n$g\\in G$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n(i) Let $T$ be the change of basis matrix from ${\\cal B}$ to ${\\cal B}'$; then\r\n$$\\phi(g)=[g]_{{\\cal B}'}=T^{-1}[g]_{\\cal B} T=T^{-1}\\rho(g)T\\qquad\\hbox{for all }g\\in G,$$\r\nand so $\\phi$ is equivalent to $\\rho$.\r\n\\\\\r\n\\\\\r\n(ii) If $\\sigma$ is equivalent to $\\rho$, then there is an\r\ninvertible matrix $T$ such that we have $\\sigma(g)=T^{-1}\\rho(g)T$ for all\r\n$g\\in G$. If we let ${\\cal B}''$ be the basis of $V$ such that the change of basis\r\nmatrix from ${\\cal B}$ to ${\\cal B}''$ is $T$, then\r\n$$\\sigma(g)=T^{-1}\\rho(g)T=T^{-1}[g]_{\\cal B} T=[g]_{{\\cal B}''}\r\n\\qquad\\hbox{for all }g\\in G$$\r\nas required.\r\n\\end{quote}\r\n{\\bf Lemma:} If $V$ and $W$ are ${\\mathbb C}G$-modules, then\r\n$V\\cong W$ if and only if there exist bases ${\\cal B}_1$ of $V$ and ${\\cal B}_2$ of\r\n$W$ such that $[g]_{{\\cal B}_1}=[g]_{{\\cal B}_2}$ for all $g\\in G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose that $\\theta: V\\rightarrow W$ is a ${\\mathbb C}G$-isomorphism, and let\r\n$v_1,\\dots,v_n$ be a basis ${\\cal B}_1$ of $V$; then\r\n$\\theta(v_1),\\dots,\\theta(v_n)$ is a basis ${\\cal B}_2$ of $W$. Given\r\n$g\\in G$, write $gv_i=\\sum a_{ji}v_j$; then\r\n$$g\\theta(v_i)=\\theta(gv_i)=\\theta\\biggl(\\sum a_{ji}v_j\\biggr)\r\n=\\sum a_{ji}\\theta(v_j),$$\r\nand so $[g]_{{\\cal B}_2}=(a_{ij})=[g]_{{\\cal B}_1}$. Conversely, if $v_1,\\dots,v_n$ and\r\n$w_1,\\dots,w_n$ are bases ${\\cal B}_1$ of $V$ and ${\\cal B}_2$ of $W$ such that\r\n$[g]_{{\\cal B}_1}=[g]_{{\\cal B}_2}$ for all $g\\in G$, let $\\theta:V\\rightarrow W$ be the\r\ninvertible linear map given by $\\theta(v_i)=w_i$ for all $i$. Given\r\n$g\\in G$, let $[g]_{{\\cal B}_1}=(a_{ij})$, so that $gv_i=\\sum a_{ji}v_j$; then\r\nbecause $[g]_{{\\cal B}_2}=(a_{ij})$ as well, for all $i$  we have\r\n$$g\\theta(v_i)=gw_i=\\sum a_{ji}w_j=\\sum a_{ji}\\theta(v_j)\r\n=\\theta\\biggl(\\sum a_{ji}v_j\\biggr)=\\theta(gv_i),$$\r\nand so $\\theta$ is a ${\\mathbb C}G$-isomorphism.\r\n\\end{quote}\r\n{\\bf Theorem 4:} Let $V$ and $W$ be ${\\mathbb C}G$-modules with bases\r\n${\\cal B}$ and ${\\cal B}'$; let $\\rho$ and $\\sigma$ be the representations of $G$ given by\r\n$\\rho(g)=[g]_{\\cal B}$ and $\\sigma(g)=[g]_{{\\cal B}'}$ for all $g\\in G$. Then $V\\cong W$ if\r\nand only if $\\rho$ and $\\sigma$ are equivalent.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nAssume that $V$ and $W$ are isomorphic ${\\mathbb C}G$-modules. By the Lemma,\r\nthere exist bases ${\\cal B}_1$ of $V$ and ${\\cal B}_2$ of $W$ such that\r\n$[g]_{{\\cal B}_1}=[g]_{{\\cal B}_2}$ for all $g\\in G$. Define a representation $\\tau$ of\r\n$G$ by $\\tau(g)=[g]_{{\\cal B}_1}$; then by the Theorem (i), $\\tau$ is equivalent to\r\nboth $\\rho$ and $\\sigma$, and so $\\rho$ and $\\sigma$ are equivalent. Conversely,\r\nif $\\rho$ and $\\sigma$ are equivalent, by the Theorem (ii) there is a basis\r\n${\\cal B}''$ of $V$ such that $\\sigma(g)=[g]_{{\\cal B}''}$ for all $g\\in G$, i.e.,\r\n$[g]_{{\\cal B}'}=[g]_{{\\cal B}''}$ for all $g\\in G$; thus $V\\cong W$ by the Lemma.\r\n\\end{quote}\r\n\\section {${\\mathbb C}G$-submodules}\r\n{\\bf Definition:} Let $V$ be a ${\\mathbb C}G$-module. A subset $U$ of\r\n$V$ is a \\emph{${\\mathbb C}G$-submodule} of $V$ if $U$ is a subspace of the vector\r\nspace $V$ which satisfies $gu\\in U$ for all $g\\in G$ and $u\\in U$.\r\nThus a ${\\mathbb C}G$-submodule of the ${\\mathbb C}G$-module $V$ is a subspace $U$ of $V$ such\r\nthat $U$ is itself a ${\\mathbb C}G$-module.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:}\r\nA non-zero ${\\mathbb C}G$-module $V$ is called\r\n\\emph{irreducible} if it has no ${\\mathbb C}G$-submodules apart from\r\n$\\{0\\}$ and $V$, and\r\n\\emph{reducible} otherwise. A representation $\\rho:G\\rightarrow GL_n({\\mathbb C})$ is\r\ncalled \\emph{irreducible} if the corresponding ${\\mathbb C}G$-module ${\\mathbb C}^n$, given by\r\n$gv=\\rho(g)v$ for $g\\in G$ and $v \\in {\\mathbb C}^n$, is \\emph{irreducible}, and is\r\n\\emph{reducible} otherwise.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 5:} If $U$ is a subspace of the complex vector\r\nspace $V$ with complex inner product $(\\ ,\\ )$, then $U^\\perp$ is a subspace of\r\n$V$, and $U\\oplus U^\\perp=V$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $v,w \\in U^\\perp$ and $\\lambda \\in {\\mathbb C}$, then for all $u \\in U$ we have\r\n$(v,u)=(w,u)=0$, so\r\n$$(v+w,u)=(v,u)+(w,u)=0+0=0,\\qquad (\\lambda v,u)=\\lambda(v,u)=\\lambda.0=0;$$\r\nthus $v+w,\\lambda v\\in U^\\perp$, and so $U^\\perp$ is a subspace of $V$.\r\n\\\\\r\n\\\\\r\nIf $u \\in U \\cap U^\\perp$, then $(u,u)=0$, so \r\n$u=0$ -- thus the sum $U+U^\\perp$ is direct. To show that $U+U^\\perp=V$,\r\ntake a basis $v_1,\\dots,v_r$ of $U$, and extend to a basis\r\n$v_1,\\dots,v_r,v_{r+1},\\dots,v_n$ of $V$. Apply the Gram-Schmidt process to\r\nobtain an orthonormal basis $e_1,\\dots,e_r,e_{r+1},\\dots,e_n$ of $V$; then\r\n$e_1,\\dots,e_r$ form an orthonormal basis of $U$, and so\r\n$e_{r+1},\\dots,e_n\\in U^\\perp$ -- given $v\\in V$ we may write\r\n$$v=\\sum_{i=1}^n\\lambda_ie_i\r\n=\\sum_{i=1}^r\\lambda_ie_i+\\sum_{i=r+1}^n\\lambda_ie_i\\in U+U^\\perp.$$\r\n\\end{quote}\r\n{\\bf Maschke's Theorem:}  If $V$ is a ${\\mathbb C}G$-module and\r\n$U$ is a ${\\mathbb C}G$-submodule, there is a \r\n${\\mathbb C}G$-submodule, $W$, of $V$ such that $V= U \\oplus W$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\langle\\ ,\\ \\rangle$ be the inner product on $V$ \r\nand take the orthogonal complement $U^\\perp$ with respect to it then\r\n$V=U\\oplus U^\\perp$.\r\nGiven $g\\in G$ and $v\\in U^\\perp$, for all $u\\in U$ we have $g^{-1}u\\in U$\r\nas $U$ is a ${\\mathbb C}G$-submodule, so that\r\n$$\\langle gv,u\\rangle=\\langle gv,g(g^{-1}u)\\rangle=\\langle v,g^{-1}u\\rangle=0;$$\r\nthus $gv\\in U^\\perp$. This shows that $U^\\perp$ is a ${\\mathbb C}G$-submodule of $V$; so\r\ntaking $W=U^\\perp$ gives the ${\\mathbb C}G$-module direct sum $V=U\\oplus W$ as\r\nrequired.\r\n\\\\\r\n\\\\\r\n\\emph{Alternate Proof:} $V= U \\oplus W_0$ where $W_0$ is some\r\nnot necessarily ${\\mathbb C}G$-invariant subspace.\r\nLet $\\pi_U$ be the projection operator onto $U$ so $\\pi_U(u + w)= u$.\r\nPut $\\varphi(x)= {\\frac 1 {|G|}} \\sum_{g \\in G} g^{-1} \\pi_U g (x)$.\r\n$U = \\varphi(U)$ and $\\varphi$ is a ${\\mathbb C}G$-invariant projection.\r\n$V= im( \\varphi ) \\oplus ker( \\varphi )$.  But $im(\\varphi)= U$ so\r\n$V= U \\oplus W$ where $W= ker( \\varphi )$.\r\n\\end{quote}\r\n{\\bf Definition:} A ${\\mathbb C}G$-module $V$ is called\r\n\\emph{completely reducible} if $V=U_1\\oplus\\cdots\\oplus U_r$ where\r\neach $U_i$ is an irreducible ${\\mathbb C}G$-submodule of $V$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 6:} If $V$ is a non-zero ${\\mathbb C}G$-module, then $V$ is\r\ncompletely reducible.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe use induction on $n= dim(V)$: the result is clear if $n=1$, as then\r\n$V$ is itself irreducible, so assume $n>1$. The result holds if $V$ is\r\nirreducible, so assume $V$ is reducible; then $V$ has a ${\\mathbb C}G$-submodule\r\n$U \\neq \\{0\\},V$.  Theorem a previous result, $V$ has a\r\n${\\mathbb C}G$-submodule $W$ with $V=U\\oplus W$; as $dim(U),dim(W)<n$, by\r\ninduction we have\r\n$$U= U_1 \\oplus \\cdots \\oplus U_r,\\qquad W= W_1 \\oplus \\cdots \\oplus W_s,$$\r\nwhere each $U_i$ and $W_j$ is an irreducible ${\\mathbb C}G$-module. It follows that\r\n$$V= U_1 \\oplus \\cdots \\oplus U_r \\oplus W_1 \\oplus \\cdots \\oplus W_s$$\r\nas required.\r\n\\end{quote}\r\n{\\bf Schur's Theorem:}  \r\nIf $V, W$ are irreducible ${\\mathbb C}G$-modules and $\\theta: V \\rightarrow W$ is a \r\n${\\mathbb C}G$ homomorphism then either $\\theta=0$ or $\\theta$ is an isomorphism.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n(i) Suppose there exists $v\\in V$ with $\\theta(v)\\neq0$. Then\r\n$im(\\theta) \\neq \\{0\\}$; because $im(\\theta)$ is a ${\\mathbb C}G$-submodule of $W$, which\r\nis irreducible, we must have $im(\\theta)=W$. Also $ker(\\theta) \\neq V$; as\r\n$ker(\\theta)$ is a ${\\mathbb C}G$-submodule of $V$, which is irreducible, we must have\r\n$ker(\\theta)=\\{0\\}$. Thus $\\theta$ is invertible, and so it is a\r\n${\\mathbb C}G$-isomorphism.\r\n\\\\\r\n\\\\\r\n(ii) Because $V$ is a vector space over ${\\mathbb C}$, the endomorphism\r\n$\\theta$ has an eigenvalue $\\lambda\\in{\\mathbb C}$, and so\r\n$ker(\\theta-\\lambda1_V) \\neq \\{0\\}$. Since $\\theta-\\lambda1_V$ is clearly a\r\n${\\mathbb C}G$-homomorphism, $ker(\\theta-\\lambda1_V)$ is a ${\\mathbb C}G$-submodule of\r\n$V$; because $V$ is irreducible, we must have $ker(\\theta-\\lambda1_V)=V$. Thus\r\n$(\\theta-\\lambda1_V)(v)=0$ for all $v\\in V$, and so $\\theta-\\lambda1_V=0$,\r\ni.e., $\\theta=\\lambda1_V$ as required.\r\n\\end{quote}\r\n{\\bf Theorem 7:} If $V$ is a non-zero ${\\mathbb C}G$-module such that\r\nevery ${\\mathbb C}G$-homomorphism from $V$ to $V$ is a scalar multiple of $1_V$, then\r\n$V$ is irreducible.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSuppose that $V$ is reducible; then it has a ${\\mathbb C}G$-submodule $U$ not equal\r\nto $\\{0\\}$ or $V$. There is a ${\\mathbb C}G$-submodule $W$ of $V$ with\r\n$V=U\\oplus W$. The map $\\pi:V\\rightarrow V$ defined by\r\n$\\pi(u+w)=u$ for all $u\\in U$ and $w\\in W$ is a ${\\mathbb C}G$-homomorphism; since it is\r\nnot a scalar multiple of $1_V$, this is a contradiction. Thus $V$ must be\r\nirreducible.\r\n\\end{quote}\r\n{\\bf Corollary:} Let $\\rho: G\\rightarrow GL_n({\\mathbb C})$ be a\r\nrepresentation of $G$; then $\\rho$ is irreducible if and only if every\r\n$n\\times n$ matrix $A$ with complex entries which satisfies\r\n$$A\\rho(g)=\\rho(g)A\\qquad\\hbox{for all }g\\in G$$\r\nhas the form $A=\\lambda I_n$ with $\\lambda\\in{\\mathbb C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nRegard ${\\mathbb C}^n$ as a ${\\mathbb C}G$-module by defining\r\n$gv=\\rho(g)v$ for all $g\\in G$ and $v\\in{\\mathbb C}^n$. Let $A$ be an $n\\times n$ matrix\r\nover ${\\mathbb C}$. The endomorphism $v\\mapsto Av$ of \r\n${\\mathbb C}^n$ is a ${\\mathbb C}G$-homomorphism\r\nif and only if\r\n$$A(gv)=g(Av)\\qquad\\hbox{for all }g\\in G,\\ v\\in{\\mathbb C}^n;$$\r\ni.e., if and only if\r\n$$A\\rho(g)=\\rho(g)A\\qquad\\hbox{for all }g\\in G.$$\r\nThe result now follows from the Lemma and an earlier theorem.\r\n\\end{quote}\r\n{\\bf Theorem 8:} If $V, W$ are ${\\mathbb C}G$-module and\r\n$\\varphi: V \\rightarrow W$ is a ${\\mathbb C}G$-homomorphism\r\nthen $ker(\\varphi)$ and $im(\\varphi)$ are \r\n${\\mathbb C}G$-modules. \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nStraightforward.\r\n\\end{quote}\r\n{\\bf Theorem 9:} If $V$ is a non-zero ${\\mathbb C}G$-module \r\nand $\\theta: V \\rightarrow W$ is a ${\\mathbb C}G$ module\r\nhomomorphism, $\\exists U$, \r\na ${\\mathbb C}G$-submodule of $V$ such that $V= ker(\\theta) \\oplus U$.\r\n$Hom_{{\\mathbb C}G}(V,W)$ is a vector space over ${\\mathbb C}$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$ker(\\theta)$ is a ${\\mathbb C}G$-module, so by \r\nMaschke, there is a ${\\mathbb C}G$-module, $U$ such that $V= ker(\\theta) \\oplus U$.\r\nThe map ${\\overline  \\theta}(u) = \\theta(u)$ is a ${\\mathbb C}G$-isomorphism from $U$ into $IM(\\theta)$.\r\nIf $u \\in ker({\\overline \\theta})$, $u \\in ker(\\theta) \\cap U$.  If $v \\in V$ and $\\theta(v)= w$, $v = k + u$,\r\n$k \\in ker(\\theta), u \\in U$.  $w= \\theta(v)= \\theta(k) + {\\overline \\theta}(u) = \\theta(u)$ and $Im(\\theta)= Im({\\overline \\theta})$.\r\n$U \\cong Im(\\theta)$.\r\n\\end{quote}\r\n\\section {${\\mathbb C}G$-homomorphisms}\r\n{\\bf Definition:}\r\nLet $V$ and $W$ be ${\\mathbb C}G$ modules.  $\\theta$ is a ${\\mathbb C}G$ homomorphism if $\\theta$ is a ${\\mathbb C}$ linear map $\\theta: V \\rightarrow W$\r\nwith $\\theta(gv) = g \\theta(v), \\forall v \\in V$.  The set (group) of ${\\mathbb C}G$ homomorphisms \r\nfrom $V$ into $W$ is denoted $Hom_{{\\mathbb C}G}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 10:} If $V$ and $W$ are ${\\mathbb C}G$-modules,\r\n$\\theta,\\phi: V \\rightarrow W$ are ${\\mathbb C}G$-homomorphisms and $\\lambda \\in {\\mathbb C}$, then\r\n$\\theta+\\phi,\\lambda\\theta: V \\rightarrow W$ are also ${\\mathbb C}G$-homomorphisms.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe know that $\\theta+\\phi$ and $\\lambda\\theta$ are linear maps; and for\r\nall $g\\in G$ and $v\\in V$ we have\r\n\\begin{eqnarray*}\r\n(\\theta+\\phi)(gv)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\theta(gv)+\\phi(gv)=g\\theta(v)+g\\phi(v)\r\n=g(\\theta(v)+\\phi(v))=g((\\theta+\\phi)(v)),\\\\\r\n(\\lambda\\theta)(gv)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\lambda.\\theta(gv)\r\n=\\lambda.g\\theta(v)=g(\\lambda.\\theta(v))=g(\\lambda\\theta)(v)\r\n\\end{eqnarray*}\r\nas required.\r\n\\end{quote}\r\n{\\bf Definition:} If $V$ and $W$ are ${\\mathbb C}G$-modules, the vector space\r\nof all ${\\mathbb C}G$-homomorphisms $\\theta:V\\rightarrow W$ is written\r\n$Hom_{{\\mathbb C}G}({\\mathbb C}G(V,W))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 11:} If $V$ and $W$ are irreducible\r\n${\\mathbb C}G$-modules, then\r\n$dim(Hom_{{\\mathbb C}G}(V,W)) = 1$, if $V \\cong W$, and\r\n$dim(Hom_{{\\mathbb C}G}(V,W)) = 0$, if $V \\ncong W$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $V \\not \\cong W$ this is immediate from Schur's Lemma. If $V \\cong W$,\r\nlet $\\theta: V \\rightarrow W$ be a ${\\mathbb C}G$-isomorphism; if $\\phi\\in Hom_{{\\mathbb C}G}(V,W)$,\r\nthen $\\theta^{-1}\\phi\\in Hom_{{\\mathbb C}G}(V,V)$. There exists\r\n$\\lambda \\in {\\mathbb C}$ with $\\theta^{-1}\\phi=\\lambda1_V$; thus $\\phi=\\lambda\\theta$,\r\nand so we have $Hom_{{\\mathbb C}G}(V,W)=\\{\\lambda\\theta: \\lambda \\in {\\mathbb C}\\}$,\r\nwhich is a $1$-dimensional vector space.\r\n\\end{quote}\r\n{\\bf Theorem 12:} Let $V$, $V_1$, $V_2$, $W$, $W_1$ and\r\n$W_2$ be ${\\mathbb C}G$-modules: then\r\n\\begin{itemize}\r\n\\item[(i)] $dim(Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2))\r\n=dim(Hom_{{\\mathbb C}G}(V,W_1))+dim(Hom_{{\\mathbb C}G}(V,W_2))$;\r\n\\item[(ii)] $dim(Hom_{{\\mathbb C}G}(V_1\\oplus V_2,W))\r\n=dim(Hom_{{\\mathbb C}G}(V_1,W))+dim(Hom_{{\\mathbb C}G}(V_2,W))$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n(i) Define the maps $\\pi_1:W_1\\oplus W_2\\rightarrow W_1$ and\r\n$\\pi_2:W_1\\oplus W_2\\rightarrow W_2$ by\r\n$$\\pi_1(w_1+w_2)=w_1,\\qquad\\pi_2(w_1+w_2)=w_2\\qquad\\hbox{for all }w_1\\in W_1,\\\r\nw_2\\in W_2;$$\r\nthen we see that $\\pi_1$ and $\\pi_2$ are\r\n${\\mathbb C}G$-homomorphisms. Given\r\n$\\theta\\in Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2)$, it is easy to see that\r\n$\\pi_i\\theta\\in Hom_{{\\mathbb C}G}(V,W_i)$ for $i=1,2$. We may\r\nthus define a map $f$ from the vector space\r\n$Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2)$ to the vector space direct sum\r\n$Hom_{{\\mathbb C}G}(V,W_1)\\oplus Hom_{{\\mathbb C}G}(V,W_2)$ by\r\n$$f(\\theta)=(\\pi_1\\theta,\\pi_2\\theta)\\qquad\\hbox{for all }\\theta\\in\r\n Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2).$$\r\nIt is clear that $f$ is a linear map; we shall show that it is bijective.\r\n\\\\\r\n\\\\\r\nGiven $\\phi_i\\in Hom_{{\\mathbb C}G}(V,W_i)$ for $i=1,2$, the map\r\n$\\phi: V\\rightarrow W_1\\oplus W_2$ defined by\r\n$\\phi(v)=\\phi_1(v)+\\phi_2(v)$ for all $v\\in V$ lies in\r\n$Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2)$, and satisfies\r\n$f(\\phi)=(\\phi_1,\\phi_2)$; thus $f$ is surjective. If $f(\\theta)=0$, then\r\n$\\pi_1\\theta=0$ and $\\pi_2\\theta=0$, so for all $v\\in V$ we have\r\n$\\theta(v)=\\pi_1\\theta(v)+\\pi_2\\theta(v)=0$; thus $\\theta=0$, and so\r\n$f$ is injective. Thus $f$ is an invertible linear map from\r\n$Hom_{{\\mathbb C}G}(V,W_1\\oplus W_2)$ to the vector space direct sum\r\n$Hom_{{\\mathbb C}G}(V,W_1)\\oplus Hom_{{\\mathbb C}G}(V,W_2)$, and so these two spaces have the same\r\ndimension as required.\r\n\\\\\r\n\\\\\r\n(ii) Given $\\theta\\in Hom_{{\\mathbb C}G}(V_1\\oplus V_2,W)$, define\r\n$\\theta_i: V_i \\rightarrow W$ for $i=1,2$ to be the restriction of\r\n$\\theta$ to $V_i$, i.e., the map defined by $\\theta_i(v)= \\theta(v)$ for all\r\n$v \\in V_i$; then $\\theta_i \\in Hom_{{\\mathbb C}G}(V_i,W)$ for $i=1,2$. Now define a\r\nmap $h$ from the vector space $Hom_{{\\mathbb C}G}(V_1\\oplus V_2,W)$ to the vector space\r\n$Hom_{{\\mathbb C}G}(V_1,W) \\oplus Hom_{{\\mathbb C}G}(V_2,W)$ by\r\n$$h(\\theta)=(\\theta_1,\\theta_2)\\qquad\\hbox{for all }\\theta\\in\r\nHom_{{\\mathbb C}G}(V_1\\oplus V_2,W).$$\r\nClearly $h$ is a linear map, and is injective. Given\r\n$\\phi_i\\in Hom_{{\\mathbb C}G}(V_i,W)$ for $i=1,2$, the map \r\n$\\phi: V_1 \\oplus V_2 \\rightarrow W$ defined by\r\n$\\phi(v_1+v_2)= \\phi_1(v_1)+\\phi_2(v_2)$ for all\r\n$v_1\\in V_1$, $v_2\\in V_2$ lies in $Hom_{{\\mathbb C}G}(V_1\\oplus V_2,W)$, and\r\n$h(\\phi)=(\\phi_1,\\phi_2)$; thus $h$ is surjective. Thus $h$ is a\r\nbijective linear map from $Hom_{{\\mathbb C}G}(V_1\\oplus V_2,W)$ to the vector space\r\ndirect sum $Hom_{{\\mathbb C}G}(V_1,W)\\oplus Hom_{{\\mathbb C}G}(V_2,W)$, and so these two spaces\r\nhave the same dimension as required.\r\n\\end{quote}\r\n{\\bf Corollary:} If $V_1,\\dots,V_r,W_1,\\dots W_s$ are\r\n${\\mathbb C}G$-modules, then\r\n$$dim(Hom_{{\\mathbb C}G}(V_1\\oplus\\cdots\\oplus V_r,W_1\\oplus\\cdots\\oplus W_s))\r\n=\\sum_{i=1}^r\\sum_{j=1}^s dim(Hom_{{\\mathbb C}G}(V_i,W_j)).$$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nFor convenience write $W=W_1\\oplus\\cdots\\oplus W_s$; then by induction,\r\nwe have\r\n\\begin{eqnarray*}\r\ndim(Hom_{{\\mathbb C}G}(V_1\\oplus\\cdots\\oplus V_r,W))\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^r dim(Hom_{{\\mathbb C}G}(V_i,W))\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^r dim(Hom_{{\\mathbb C}G}(V_i,W_1\\oplus\\cdots\\oplus W_s))\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^r\\sum_{j=1}^s dim(Hom_{{\\mathbb C}G}(V_i,W_j))\r\n\\end{eqnarray*}\r\nas required.\r\n\\end{quote}\r\n{\\bf Corollary:} Let $V$ be a ${\\mathbb C}G$-module with\r\n$V=U_1\\oplus\\cdots\\oplus U_r$ where each $U_i$ is irreducible, and $W$ be any\r\nirreducible ${\\mathbb C}G$-module; then both $ dim(Hom_{{\\mathbb C}G}(V,W))$ and\r\n$ dim(Hom_{{\\mathbb C}G}(W,V))$ are equal to the number of terms $U_i$ with $U_i\\cong W$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nBy the Corollary, we have\r\n\\begin{eqnarray*}\r\n dim(Hom_{{\\mathbb C}G}(V,W))\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^r dim(Hom_{{\\mathbb C}G}(U_i,W)),\\\\\r\n dim(Hom_{{\\mathbb C}G}(W,V))\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^r dim(Hom_{{\\mathbb C}G}(W,U_i));\r\n\\end{eqnarray*}\r\nwe have\r\n$$ dim(Hom_{{\\mathbb C}G}(U_i,W))= dim(Hom_{{\\mathbb C}G}(W,U_i))=\r\n1,  \\textnormal { if } U_i \\cong W;\r\n0  \\textnormal{ if } U_i \\ncong W.\r\n$$\r\nThe result follows.\r\n\\end{quote}\r\n{\\bf Theorem 13:} Let $V$ be a ${\\mathbb C}G$-module, and write\r\n$V=U_1\\oplus\\cdots\\oplus U_r$ where each $U_i$ is an irreducible\r\n${\\mathbb C}G$-submodule of $V$. If $U$ is any irreducible ${\\mathbb C}G$-submodule of $V$, then\r\n$U \\cong U_i$ for some $i$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nGiven $u\\in U$ we may write $u=u_1+\\cdots+u_r$ for unique vectors\r\n$u_i\\in U_i$. Define $\\pi_i:U\\rightarrow U_i$ by $\\pi_i(u)=u_i$ for\r\n$1\\leq i\\leq r$; then each $\\pi_i$ is a\r\n${\\mathbb C}G$-homomorphism. If we choose $i$ such that $u_i\\neq0$ for some\r\n$u\\in U$, we have $\\pi_i\\neq0$. $\\pi_i$ is a\r\n${\\mathbb C}G$-isomorphism, and so $U\\cong U_i$.\r\n\\end{quote}\r\n\\section {Decomposition of ${\\mathbb C}G$}\r\n{\\bf Definition:} If $V$ is a ${\\mathbb C}G$-module and $U$ is an irreducible\r\n${\\mathbb C}G$-module, we say that $U$ is a \\emph{composition factor} of $V$ if $V$ has\r\na ${\\mathbb C}G$-submodule which is isomorphic to $U$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} Two ${\\mathbb C}G$-modules $V$ and $W$ are said to have a\r\n\\emph{common composition factor} if there is an irreducible ${\\mathbb C}G$-module which\r\nis a composition factor of both $V$ and $W$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 14:} The ${\\mathbb C}G$-modules $V$ and $W$ have a common\r\ncomposition factor if and only if $ Hom_{{\\mathbb C}G}(V,W)\\neq\\{0\\}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWrite $V=V_1\\oplus\\cdots\\oplus V_r$, $W=W_1\\oplus\\cdots\\oplus W_s$ with\r\neach $V_i$ and $W_j$ irreducible. By the corollary,\r\n$\\dim( Hom_{{\\mathbb C}G}(V,W))=\\sum\\sum\\dim( Hom_{{\\mathbb C}G}(V_i,W_j))$, and, \r\n$\\dim( Hom_{{\\mathbb C}G}(V_i,W_j))$ is $1$ if $V_i\\cong W_j$, and $0$ if\r\n$V_i \\not\\cong W_j$. Thus $ Hom_{{\\mathbb C}G}(V,W) \\neq \\{0\\}$ if and only if some $V_i$ is\r\nisomorphic to some $W_j$.\r\n\\end{quote}\r\n{\\bf Definition:} The vector space ${\\mathbb C}G$, with multiplication defined\r\nby\r\n$$\\biggl(\\sum_{g\\in G}\\lambda_gg\\biggr)\\biggl(\\sum_{h\\in G}\\mu_hh\\biggr)\r\n=\\sum_{g,h\\in G}\\lambda_g\\mu_h(gh)\\qquad\\hbox{for all }\\lambda_g,\\mu_h\\in{\\mathbb C},$$\r\nis called the  \\emph{group algebra} of $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 15:} For all $r,s,t\\in{\\mathbb C}G$ and $\\lambda\\in{\\mathbb C}$, we\r\nhave the following:\r\n\\begin{itemize}\r\n\\item[(i)] $rs\\in{\\mathbb C}G$;\r\n\\item[(ii)] $r(st)=(rs)t$;\r\n\\item[(iii)] $r1=1r=r$;\r\n\\item[(iv)] $(\\lambda r)s=\\lambda(rs)=r(\\lambda s)$;\r\n\\item[(v)] $r(s+t)=rs+rt$;\r\n\\item[(vi)] $(r+s)t=rt+st$;\r\n\\item[(vii)] $r0=0r=0$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe prove (ii).  Let\r\n$$r=\\sum_{g\\in G}\\lambda_gg,\\qquad s=\\sum_{h\\in G}\\mu_hh,\\qquad\r\nt=\\sum_{k\\in G}\\nu_kk,$$\r\nwhere $\\lambda_g,\\mu_h,\\nu_k\\in{\\mathbb C}$ for all $g,h,k\\in G$; then\r\n$$(rs)t=\\sum_{g,h,k\\in G}\\lambda_g\\mu_h\\nu_k(gh)k\r\n=\\sum_{g,h,k\\in G}\\lambda_g\\mu_h\\nu_kg(hk)=r(st).$$\r\n\\end{quote}\r\n{\\bf Definition:}\r\nWe now define a ${\\mathbb C}G$-module using the group algebra. Let $V={\\mathbb C}G$, so that\r\n$V$ is a vector space of dimension $n=|G|$ over ${\\mathbb C}$. Given $g\\in G$, we may\r\nregard $g$ as an element of ${\\mathbb C}G$, and so may form the product $gv$ for any\r\n$v \\in V$; by properties (i), (ii), (iii), (iv) and (v) of an earlier result,\r\nfor all $g,h \\in G$, $\\lambda \\in {\\mathbb C}$ and $u,v \\in V$ we have\r\n$$gv \\in V,\\quad (gh)v=g(hv),\\quad 1v=v,\\quad g(\\lambda v)=\\lambda gv,\\quad\r\ng(u+v)=gu+gv.$$\r\nThus $V$ is a ${\\mathbb C}G$-module.\r\nThe ${\\mathbb C}G$-module ${\\mathbb C}G$ is called the \\emph{regular}\r\n${\\mathbb C}G$-module. The corresponding representation $g\\mapsto[g]_{\\cal B}$, where ${\\cal B}$ is\r\nthe natural basis of ${\\mathbb C}G$, is called the {\\emph{regular representation} of\r\n$G$.\r\nNote that the regular ${\\mathbb C}G$-module has dimension $|G|$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 16:} The regular ${\\mathbb C}G$-module is faithful.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $g\\in G$ with $gv=v$ for all $v\\in{\\mathbb C}G$, then $g1=1$, and so $g=1$; \r\nthus ${\\mathbb C}G$ is faithful.\r\n\\end{quote}\r\n{\\bf Theorem 17:} If $V$ is a ${\\mathbb C}G$-module, the following\r\nproperties hold for all $r,s\\in{\\mathbb C}G$, $\\lambda\\in{\\mathbb C}$ and $u,v\\in V$:\r\n\\begin{itemize}\r\n\\item[(i)] $rv\\in V$;\r\n\\item[(ii)] $(rs)v=r(sv)$;\r\n\\item[(iii)] $1v=v$;\r\n\\item[(iv)] $r(\\lambda v)=\\lambda(rv)=(\\lambda r)v$;\r\n\\item[(v)] $r(u+v)=ru+rv$;\r\n\\item[(vi)] $(r+s)v=rv+sv$;\r\n\\item[(vii)] $r0=0v=0$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe prove only (ii), leaving the rest as easy\r\nexercises (some of whose results we shall assume). Let $r,s\\in{\\mathbb C}G$ and\r\n$v\\in V$, and set\r\n$$r=\\sum_{g\\in G}\\lambda_gg,\\qquad s=\\sum_{h\\in G}\\mu_hh\\qquad\\hbox{with }\r\n\\lambda_g,\\mu_h\\in{\\mathbb C}\\hbox{ for all }g,h\\in G.$$\r\nWe then have\r\n\r\n\\begin{eqnarray*}\r\n(rs)v\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\left(\\sum_{g,h}\\lambda_g\\mu_h(gh)\\right)v\r\n\\qquad\\hbox{by definition of the multiplication in }{\\mathbb C}G\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{g,h}\\lambda_g\\mu_h((gh)v)\r\n\\qquad\\hbox{by (iv) and (vi)}\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{g,h}\\lambda_g\\mu_h(g(hv))\r\n\\qquad\\hbox{by definition of a ${\\mathbb C}G$-module}\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\left(\\sum_g\\lambda_gg\\right)\\left(\\sum_h\\mu_h(hv)\\right)\r\n\\qquad\\hbox{by (iv), (v) and (vi)}\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!r(sv)\\qquad\\hbox{by (iv) and (vi)}\r\n\\end{eqnarray*}\r\nas required.\r\n\\end{quote}\r\n{\\bf Theorem 18:} Write the regular ${\\mathbb C}G$-module as\r\n$${\\mathbb C}G=U_1 \\oplus \\cdots \\oplus U_r,$$\r\na direct sum of irreducible ${\\mathbb C}G$-submodules; then any irreducible\r\n${\\mathbb C}G$-module is isomorphic to one of the $U_i$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $W$ be an irreducible ${\\mathbb C}G$-module, and choose a non-zero vector\r\n$w\\in W$. Define $\\theta:{\\mathbb C}G\\rightarrow W$ by\r\n$$\\theta(r)=rw\\qquad\\hbox{for all }r\\in{\\mathbb C}G;$$\r\nthen clearly $\\theta$ is a linear map. For all $g\\in G$ and $r\\in{\\mathbb C}G$ we have\r\n$$\\theta(gr)=(gr)w=g(rw)=g\\theta(r);$$\r\nthus $\\theta$ is a ${\\mathbb C}G$-homomorphism. We know that\r\n$im(\\theta)$ is a ${\\mathbb C}G$-submodule of $W$; since\r\n$0\\neq w=1w=\\theta(1)\\in im(\\theta)$ and $W$ is irreducible, we must have\r\n$im(\\theta)=W$. There is a ${\\mathbb C}G$-submodule $U$ of\r\n${\\mathbb C}G$ with\r\n$${\\mathbb C}G=ker(\\theta) \\oplus U\\qquad\\hbox{and}\\qquad U \\cong im(\\theta)=W.$$\r\nWe have $U\\cong U_i$ for some $i$, and so it follows that\r\n$W\\cong U_i$ as required.\\\r\n\\end{quote}\r\n{\\bf Corollary:} Up to isomorphism, there are only finitely many\r\nirreducible ${\\mathbb C}G$-modules.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nFollows immediately from previous result. \r\n\\end{quote}\r\n{\\bf Theorem 19:} If $U$ is a ${\\mathbb C}G$-module, then\r\n$ dim(Hom_{{\\mathbb C}G}({\\mathbb C}G,U))= dim(U)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $dim(U)=d$, and choose a basis $u_1,\\dots,u_d$ of $U$. For\r\n$1\\leq i\\leq d$ define $\\phi_i:{\\mathbb C}G\\rightarrow U$ by $\\phi_i(r)=ru_i$ for all\r\n$r\\in{\\mathbb C}G$. Clearly each $\\phi_i$ is a linear map, and for all $g\\in G$ and\r\n$r\\in{\\mathbb C}G$ we have\r\n$$\\phi_i(gr)=(gr)u_i=g(ru_i)=g\\phi_i(r),$$\r\nso that $\\phi_i\\in Hom_{{\\mathbb C}G}({\\mathbb C}G,U)$. We shall prove that $\\phi_1,\\dots,\\phi_d$ is\r\na basis of $Hom_{{\\mathbb C}G}({\\mathbb C}G,U)$. Given $\\phi\\in Hom_{{\\mathbb C}G}({\\mathbb C}G,U)$, write\r\n$\\phi(1)=\\lambda_1u_1+\\cdots+\\lambda_du_d$ for some $\\lambda_i\\in{\\mathbb C}$. For all\r\n$r\\in{\\mathbb C}G$ we then have\r\n\r\n\\begin{eqnarray*}\r\n\\phi(r)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\phi(r1)=r\\phi(1)=r\\lambda_1u_1+\\cdots+r\\lambda_du_d\r\n=\\lambda_1\\phi_1(r)+\\cdots+\\lambda_d\\phi_d(r)\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!(\\lambda_1\\phi_1+\\cdots+\\lambda_d\\phi_d)(r);\r\n\\end{eqnarray*}\r\n\r\nthus $\\phi=\\lambda_1\\phi_1+\\cdots+\\lambda_d\\phi_d$. Hence\r\n$\\phi_1,\\dots,\\phi_d$ span $Hom_{{\\mathbb C}G}({\\mathbb C}G,U)$. Now if\r\n$\\lambda_1\\phi_1+\\cdots+\\lambda_d\\phi_d=0$ for some $\\lambda_i\\in{\\mathbb C}$, we have\r\n$$0=(\\lambda_1\\phi_1+\\cdots+\\lambda_d\\phi_d)(1)\r\n=\\lambda_1u_1+\\cdots+\\lambda_du_d,$$\r\nso $\\lambda_i=0$ for all $i$. Thus $\\phi_1,\\dots,\\phi_d$ is\r\na basis of $Hom_{{\\mathbb C}G}({\\mathbb C}G,U)$; it follows that $dim(Hom_{{\\mathbb C}G}({\\mathbb C}G,U))=d$.\r\n\\end{quote}\r\n{\\bf Theorem 20:} Suppose that ${\\mathbb C}G=U_1 \\oplus \\cdots \\oplus U_r$ is a\r\ndirect sum of irreducible ${\\mathbb C}G$-submodules. If $U$ is any irreducible\r\n${\\mathbb C}G$-module, then the number of terms $U_i$ isomorphic to $U$ is equal to\r\n$dim(U)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$ dim(U)= dim(Hom_{{\\mathbb C}G}({\\mathbb C}G,U))$, and by the last theorem,\r\nthis is equal to the number of terms $U_i$ with $U_i\\cong U$.\r\n\\end{quote}\r\n{\\bf Definition:} If $V_1,\\dots,V_k$ are irreducible ${\\mathbb C}G$-modules\r\nsuch that no two are isomorphic and any irreducible ${\\mathbb C}G$-module is isomorphic\r\nto some $V_i$, we say that the $V_i$ form a \\emph{complete set of\r\nnon-isomorphic irreducible ${\\mathbb C}G$-modules\\/}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 21:} If $V_1,\\dots,V_k$ form a complete set of\r\nnon-isomorphic irreducible ${\\mathbb C}G$-modules, then\r\n$$\\sum_{i=1}^k( dim V_i)^2=|G|.$$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet ${\\mathbb C}G=U_1\\oplus\\cdots\\oplus U_r$, a direct sum of irreducible\r\n${\\mathbb C}G$-modules; set $dim(V_i) =d_i$ for $1 \\leq i \\leq k$. For\r\neach $i$ the number of terms $U_j$ isomorphic to $V_i$ is equal to $d_i$. Thus\r\n$$dim({\\mathbb C}G)= dim(U_1)+\\cdots+ dim(U_r) =\\sum_{i=1}^k d_i( dim(V_i))\r\n= \\sum_{i=1}^k {d_i}^2.$$\r\nAs $ dim({\\mathbb C}G)=|G|$, the result follows.\r\n\\end{quote}\r\n{\\bf Theorem 22:}\r\n$dim(Hom_{{\\mathbb C}G}(U_1 \\oplus \\ldots \\oplus U_r, W_1 \\oplus \\ldots \\oplus W_s))=\r\n\\sum_{i=1, j=1}^{r,s} dim(Hom_{{\\mathbb C}G}(V_i , W_j))$. Suppose $U$ is an irreducible\r\n${\\mathbb C}G$-module then \r\n$dim(Hom_{{\\mathbb C}G}({\\mathbb C}G, U))= dim(U)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $d=dim(U)$ and $u_1, u_2, \\ldots, u_d$ be a basis for $U$.  Define\r\n$r \\phi_i=u_i r$.  The $\\phi_i$ are a basis for $Hom_{{\\mathbb C}G}({\\mathbb C}G, U)$.\r\n\\end{quote}\r\n{\\bf Theorem 23:}\r\nLet $V$ be an ${\\mathbb C}G$ module, \r\n$V= U_1 \\oplus U_2 \\oplus \\ldots \\oplus U_r$ with $U_i$ irreducible; (a) if\r\n$W$ is an irreducible ${\\mathbb C} G$ module then \r\n$dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(V, W))= dim_{{\\mathbb C}}(Hom_{{\\mathbb C}G}(W, V))$ is\r\nthe number of $U_i \\cong W$;\r\n(b) each $U_i$ is a composition factor in the Jordan Holder series.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$dim(Hom_{{\\mathbb C}G}(U_1 \\oplus \\ldots \\oplus U_r, W)\r\n\\sum_{i=1}^{r} dim(Hom_{{\\mathbb C}G}(V_i , W))$. \r\n$dim(Hom_{{\\mathbb C}G}(V_i , W))= 1$ when $U_i \\cong W$ and is $0$ otherwise.  So the\r\nsum is just the number of $U_i \\cong W$ so is the sum where the $U_i$ and $W$ are reversed.\r\n\\end{quote}\r\n\\section{Representations of Abelian Groups}\r\n{\\bf Theorem 24:} If $G$ is abelian, then every irreducible\r\n${\\mathbb C}G$-module has dimension $1$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $V$ be an irreducible ${\\mathbb C}G$-module, and take any $x\\in G$.\r\nBecause $G$ is abelian, we have\r\n$$x(gv)=g(xv)\\qquad\\hbox{for all }g\\in G,\\ v\\in V,$$\r\nand hence the endomorphism $v\\mapsto xv$ of $V$ is a ${\\mathbb C}G$-homomorphism. \r\nThis endomorphism must be a scalar multiple of the identity map\r\n$1_V$, say $\\lambda_x1_V$; thus $xv=\\lambda_xv$ for all $v\\in V$. Since this is\r\ntrue for all $x\\in G$, we see that every subspace of $V$ is a ${\\mathbb C}G$-submodule;\r\nso as $V$ is irreducible we must have $ dim(V)=1$.\r\n\\end{quote}\r\n{\\bf Theorem 25:} Let $G$ be the abelian group\r\n$C_{n_1}\\times\\cdots\\times C_{n_r}$. There are $|G|$ irreducible\r\nrepresentations of $G$, and any such is of the form\r\n$\\rho_{\\lambda_1,\\dots,\\lambda_r}$; no two of these representations are\r\nequivalent.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe above has shown that any irreducible representation of $G$ must be of\r\nthe form $\\rho_{\\lambda_1,\\dots,\\lambda_r}$; conversely if $\\lambda_i$ is an\r\n$n_i$th root of unity for $1\\leq i\\leq r$, the map\r\n$\\rho:G\\rightarrow GL_1({\\mathbb C})$ given by\r\n$$\\rho({g_1}^{i_1}\\dots{g_r}^{i_r})=\r\n({\\lambda_1}^{i_1}\\dots{\\lambda_r}^{i_r})$$\r\nis clearly an irreducible\r\nrepresentation. Since there are $n_i$ choices for each $\\lambda_i$, the number\r\nof representations of the form $\\rho_{\\lambda_1,\\dots,\\lambda_r}$ is\r\n$n_1\\dots n_r=|G|$; no two are equivalent, as\r\n$T^{-1}AT=A$ for any $1\\times 1$ invertible matrices $A$ and $T$.\r\n\\end{quote}\r\n{\\bf Theorem 26:} If every irreducible ${\\mathbb C}G$-module has\r\ndimension $1$, then $G$ is abelian.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $V$ be a faithful ${\\mathbb C}G$-module. We can write\r\n$V=V_1\\oplus\\cdots\\oplus V_r$ with each $V_i$ irreducible. By assumption,\r\n$\\dim(V_i) =1$ for all $i$; let $V_i=\\langle v_i\\rangle$, so that\r\n$v_1,\\dots,v_r$ is a\r\nbasis ${\\cal B}$ of $V$. Since each $V_i$ is a ${\\mathbb C}G$-submodule, we have\r\n$gv_i\\in V_i$ for all $g\\in G$; thus each matrix $[g]_{\\cal B}$ is diagonal. As\r\ndiagonal matrices commute, for all $g,h\\in G$ we have\r\n$$[gh]_{\\cal B}=[g]_{\\cal B}[h]_{\\cal B}=[h]_{\\cal B}[g]_{\\cal B}=[hg]_{\\cal B},$$\r\nand so as the representation is faithful we have $gh=hg$ -- so $G$ is\r\nabelian.\r\n\\end{quote}\r\n\\section{Characters}\r\n{\\bf Definition:} Let $\\rho:G\\rightarrow GL_n({\\mathbb C})$ be a representation\r\nof $G$; then the \\emph{character} of $\\rho$ is the function\r\n$\\chi:G\\rightarrow{\\mathbb C}$ given by $\\chi(g)=Tr(\\rho(g))$ for all $g\\in G$.\r\n\\\\\r\n\\\\\r\n{\\bf Remark:}\r\nClearly the character of a representation $\\rho$ of degree $n$ is ``simpler''\r\nthan $\\rho$ itself, in that it involves only $|G|$ values rather than\r\n$n^2|G|$ matrix entries. Our next result shows that this ``loss of detail''\r\nmeans that we fail to distinguish between equivalent representations.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 27:} Equivalent representations of $G$ have the\r\nsame character.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\rho,\\sigma: G \\rightarrow GL_n({\\mathbb C})$ be equivalent representations of\r\n$G$; then there is an invertible matrix $T$ such that for all $g\\in G$ we have\r\n$\\sigma(g)=T^{-1}\\rho(g)T$. Thus by the corollary, we have\r\n$Tr(\\sigma(g))=Tr((T^{-1}\\rho(g)T)=Tr(\\rho(g))$.\r\n\\end{quote}\r\n{\\bf Definition:} Let $V$ be a ${\\mathbb C}G$-module, with basis ${\\cal B}$; then the\r\n\\emph{character} of $V$ is the function $\\chi:G\\rightarrow{\\mathbb C}$ given by\r\n$\\chi(g)=Tr([g]_{\\cal B})$ for all $g\\in G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 28:} Isomorphic ${\\mathbb C}G$-modules have the same\r\ncharacter.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nCombine the two previous results.\r\n\\end{quote}\r\n{\\bf Definition:} A function $\\chi: G \\rightarrow {\\mathbb C}$ is called a\r\n\\emph{character} if it is the character of some ${\\mathbb C}G$-module. A character is\r\ncalled \\emph{irreducible} if it is the character of an\r\nirreducible ${\\mathbb C}G$-module, and \\emph{reducible} otherwise.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 29:} If $\\chi$ is the character of a\r\n${\\mathbb C}G$-module $V$, then $\\chi(1)= dim(V)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $n= dim (V)$; then the matrix $[1]_{\\cal B}$ is the identity matrix $I_n$, and\r\nso we have $\\chi(1)=Tr([1]_{\\cal B})=Tr( I_n)=n$ as required.\r\n\\end{quote}\r\n{\\bf Definition:} If $\\chi$ is the character of the ${\\mathbb C}G$-module $V$,\r\nthe dimension of $V$ is called the \\emph{degree} of $\\chi$.\r\n\\\\\r\n\\\\\r\n{\\bf Example:} (a) $G = D_8 = \\langle a, b| a^4=b^2=1, a^b = a^{-1}\\rangle$.\r\n$\\rho(a) =\r\n\\left(\r\n\\begin{array}{cc}\r\n0&1\\\\\r\n-1&0\\\\\r\n\\end{array}\r\n\\right)$,\r\n$\\rho(b) =\r\n\\left(\r\n\\begin{array}{cc}\r\n1&0\\\\\r\n0&-1\\\\\r\n\\end{array}\r\n\\right)$.\\\\\r\n(b) $G = D_6 = S_3 = \\langle a, b| a^3=b^2=1, a^b = a^{-1}\\rangle$.  Basis is\r\n$v_0 = 1 + a + a^2$, $w_0= b v_0$,\r\n$v_1 = 1 + \\omega^2a + \\omega a^2$, $w_1= b v_1$,\r\n$v_2 = 1 + \\omega a + \\omega^2 a^2$, $w_2= b v_2$.\r\n$sp(v_0, w_0)$ is reducible as $sp(v_0 + w_0) \\oplus sp(v_0 - w_0)$.\r\n$sp(v_1, w_2) \\cong sp(v_2, w_1)$ and they are irreducible.\r\nThe characters of $D_8$ have degree $1$, $1$, $1$, $1$, and $2$.\r\nThe characters of $S_3$\r\nhave degrees $1$, $1$ and $2$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 30:} If $\\chi$ is a character of $G$, and\r\n$g,h\\in G$ are conjugate, then $\\chi(g)=\\chi(h)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $g$ and $h$ are conjugate, we have $h=x^{-1}gx$ for some $x\\in G$;\r\nthus if $\\chi$ is the character of\r\nthe ${\\mathbb C}G$-module $V$ and ${\\cal B}$ is a basis for $V$, we have\r\n$$[h]_{\\cal B}=[x^{-1}gx]_{\\cal B}=[x^{-1}]_{\\cal B}[g]_{\\cal B}[x]_{\\cal B}=([x]_{\\cal B})^{-1}[g]_{\\cal B}[x]_{\\cal B}.$$\r\nBy the corollary,\r\nwe then have $\\chi(h)=Tr([h]_{\\cal B})=Tr([g]_{\\cal B})=\\chi(g)$ as\r\nrequired.\r\n\\end{quote}\r\n{\\bf Theorem 31:} If $V$ is a ${\\mathbb C}G$-module, then for each\r\n$g\\in G$ there is a basis ${\\cal B}$ of $V$ such that the matrix $[g]_{\\cal B}$ is\r\ndiagonal; if $g$ has order $m$, the diagonal entries of $[g]_{\\cal B}$ are $m$th\r\nroots of unity.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nGiven $g\\in G$, let $H=\\langle g\\rangle$; then $H$ is a cyclic subgroup of\r\n$G$. By restricting the multiplication on $V$ to the elements of $H$, we may\r\nconsider $V$ as a ${\\mathbb C} H$-module. We may write\r\n$$V=U_1\\oplus\\cdots\\oplus U_n,$$\r\nwhere each $U_j$ is an irreducible ${\\mathbb C} H$-submodule of $V$.\r\nEach $U_j$ has dimension $1$; let $u_j$ be a vector spanning $U_j$.\r\nIf we set $\\omega=e^{2\\pi i/m}$, then for all $j$ there is an integer\r\n$r_j$ with $gu_j=\\omega^{r_j}u_j$. Thus if we let ${\\cal B}$ be the basis\r\n$u_1,\\dots,u_n$ of $V$, we have\r\n$[g]_{\\cal B}=\\left(\\begin{array} {ccc}\r\n\\omega^{r_1} & \\ldots & 0\\\\\r\n\\ldots & \\ldots & \\ldots\\\\\r\n0 & \\ldots & \\omega^{r_n}\\\\\r\n\\end{array}\\right)$\r\nas required.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=S_3$, and $g=(1\\;2\\;3)\\in G$, so that $g$ has\r\norder $3$; take $V$ to be the permutation module. We have seen that the\r\nmatrix of $g$ with respect to the natural basis $v_1,v_2,v_3$ is not diagonal.\r\nHowever, if we write $\\omega=e^{2\\pi i/3}$ and set\r\n$$w_1=v_1+v_2+v_3,\\qquad w_2=v_1+\\omega^2v_2+\\omega v_3,\\qquad\r\nw_3=v_1+\\omega v_2+\\omega^2v_3,$$\r\nthen $w_1,w_2,w_3$ is a basis ${\\cal B}$ of $V$, and we have\r\n$$[g]_{\\cal B}=\\left(\\begin{array}{ccc}\r\n1&0&0\\\\0&\\omega&0\\\\0&0&\\omega^2\\end{array}\\right).$$\r\n{\\bf Theorem 32:} If $\\chi$ is a character of $G$ of degree\r\n$n$, and $g\\in G$ has order $m$, then:\r\n\\begin{itemize}\r\n\\item[(i)] $\\chi(g)$ is a sum of $n$ $m$th roots of unity;\r\n\\item[(ii)] $|\\chi(g)|\\leq n$;\r\n\\item[(iii)] $\\chi(g^{-1})=\\overline{\\chi(g)}$;\r\n\\item[(iv)] if $g$ is conjugate to $g^{-1}$ then $\\chi(g)  \\in {\\mathbb R}$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $V$ be a ${\\mathbb C}G$-module having $\\chi$ as character.\r\nThere is a basis ${\\cal B}$ of $V$ such that\r\n$$[g]_{\\cal B}=\\left(\\begin{array}{ccc}\\omega_1&\\cdots&0\\\\\r\n\\vdots&\\ddots&\\vdots\\\\0&\\cdots&\\omega_n\\end{array}\\right)$$\r\nwhere each $\\omega_j$ is an $m$th root of unity; this proves (i). The\r\ntriangle inequality gives\r\n$$|\\chi(g)|=|\\omega_1+\\cdots+\\omega_n|\\leq|\\omega_1|+\\cdots+|\\omega_n|\r\n=1+\\cdots+1=n,$$\r\nwhich proves (ii). Also we have\r\n$$[g^{-1}]_{\\cal B}=\\left(\\begin{array}{ccc}\\omega_1^{-1}&\\cdots&0\\\\\r\n\\vdots&\\ddots&\\vdots\\\\0&\\cdots&{\\omega_n}^{-1}\\end{array}\\right),$$\r\nand so $\\chi(g^{-1})={\\omega_1}^{-1}+\\cdots+{\\omega_n}^{-1}$. As\r\n$\\overline{\\omega}=\\omega^{-1}$ for each root of unity $\\omega$, we have\r\n$\\chi(g^{-1})=\\overline{\\omega_1}+\\cdots+\\overline{\\omega_n}\r\n=\\overline{\\chi(g)}$, giving (iii). Finally if $g$ is conjugate to\r\n$g^{-1}$ then by Theorem 30 we have\r\n$\\chi(g)=\\chi(g^{-1})=\\overline{\\chi(g)}$; thus $\\chi(g)\\in{\\mathbb R}$, giving (iv).\r\n\\end{quote}\r\n{\\bf Corollary:} If $g\\in G$ has order $2$, and $\\chi$ is a\r\ncharacter of $G$, then $\\chi(g) \\in {\\mathbb Z}$, and $\\chi(g)\\equiv\\chi(1)\\jmod{2}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$$\\chi(g)=\\omega_1+\\cdots+\\omega_n,$$\r\nwhere $n=\\chi(1)$ and each $\\omega_j$ is a square root of unity. Suppose\r\n$r$ terms $\\omega_j$ are equal to $-1$; then the remaining $n-r$ are equal to\r\n$1$, and so\r\n$$\\chi(g)=(n-r)-r=n-2r.$$\r\nHence $\\chi(g)\\in{\\mathbb Z}$, and $\\chi(g)\\equiv\\chi(1)\\jmod{2}$ as required.\r\n\\end{quote}\r\n{\\bf Theorem 33:} Let $\\rho:G\\rightarrow GL_n({\\mathbb C})$ be a\r\nrepresentation with character $\\chi$. Then:\r\n\\begin{itemize}\r\n\\item[(i)] for $g\\in G$ we have $|\\chi(g)|=\\chi(1)$ if and only if\r\n$\\rho(g)=\\lambda I_n$ for some $\\lambda\\in{\\mathbb C}$;\r\n\\item[(ii)] $ker(\\rho)=\\{g\\in G:\\chi(g)=\\chi(1)\\}$.\r\n\\end{itemize}\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n(i) Let $g\\in G$ have order $m$. If $\\rho(g)=\\lambda I_n$ with\r\n$\\lambda\\in{\\mathbb C}$, then $\\lambda$ is an $m$th root of unity, and\r\n$\\chi(g)=n\\lambda$; thus $|\\chi(g)|=n=\\chi(1)$. Conversely, suppose that\r\n$|\\chi(g)|=\\chi(1)$. We know by Theorem 31 that there is a basis ${\\cal B}$ of\r\n${\\mathbb C}^n$ such that\r\n$$[g]_{\\cal B}=\\left(\\begin{array}{ccc}\\omega_1&\\cdots&0\\\\\r\n\\vdots&\\ddots&\\vdots\\\\0&\\cdots&\\omega_n\\end{array}\\right),$$\r\nwhere each $\\omega_i$ is an $m$th root of unity; thus\r\n$\\chi(g)=\\omega_1+\\cdots+\\omega_n$. Since by assumption we have\r\n$$|\\omega_1+\\cdots+\\omega_n|=|\\chi(g)|=\\chi(1)=n\r\n=|\\omega_1|+\\cdots+|\\omega_n|,$$\r\neach term must have the same argument; so $\\omega_i=\\omega_j$ for\r\nall $i,j$, and thus\r\n$$[g]_{\\cal B}=\\left(\\begin{array}{ccc}\\omega_1&\\cdots&0\\\\\r\n\\vdots&\\ddots&\\vdots\\\\0&\\cdots&\\omega_1\\end{array}\\right)= \\omega_1I_n.$$\r\nHence if ${\\cal B}'$ is any basis of ${\\mathbb C}^n$, there is a change of basis matrix\r\n$T$ such that $[g]_{{\\cal B}'}=T^{-1}[g]_{\\cal B} T=T^{-1}\\omega_1 I_n T=\\omega_1 I_n$; so\r\n$\\rho(g)=\\omega_1I_n$ as required.\r\n\\\\\r\n\\\\\r\n(ii) Clearly if $g\\in ker(\\rho)$ then $\\rho(g)=I_n$ so that\r\n$\\chi(g)=n=\\chi(1)$. Conversely if $g\\in G$ satisfies $\\chi(g)=\\chi(1)$, then\r\nby (i) we have $\\rho(g)=\\lambda I_n$ for some $\\lambda\\in{\\mathbb C}$; hence\r\n$\\chi(g)=\\lambda\\chi(1)$, and so $\\lambda=1$, giving $\\rho(g)=I_n$ and so\r\n$g \\in ker(\\rho)$ as required.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=D_8$, and let $\\chi$ be the character given\r\nabove, with values as follows.\r\n$$\r\n\\begin{array}{|c|cccccccc|}\r\n\\hline\r\ng&1&a&a^2&a^3&b&ba&ba^2&ba^3\\\\\r\n\\hline\r\n\\chi(g)&2&0&-2&0&0&0&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n{\\bf Definition:} The \\emph{kernel} of the character $\\chi$ of\r\n$G$ is the set $ker(\\chi)=\\{g\\in G:\\chi(g)=\\chi(1)\\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 34:} If $\\chi$ is a character of $G$ then so is\r\n$\\bar\\chi$; if $\\chi$ is irreducible then so is $\\bar\\chi$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\chi$ be the character of a representation\r\n$\\rho:G\\rightarrow GL_n({\\mathbb C})$; thus $\\chi(g)=Tr((\\rho(g))$ for all $g\\in G$.\r\nNow given an $n\\times n$ matrix $A=(a_{ij})$ over ${\\mathbb C}$, we set\r\n$\\bar A=(\\overline{a_{ij}})$; then if $A=(a_{ij})$ and $B=(b_{ij})$ are\r\n$n\\times n$ matrices over ${\\mathbb C}$ we have\r\n$\\overline{AB}=\\overline{A}.\\overline{B}$, because\r\n$$(\\overline{A}.\\overline{B})_{ij}\r\n=\\sum_{k=1}^n\\bar a_{ik}\\bar b_{kj}=\\sum_{k=1}^n\\overline{a_{ik}b_{kj}}\r\n=\\overline{\\sum_{k=1}^na_{ik}b_{kj}}=(\\overline{AB})_{ij}.$$\r\nThus the function $\\bar\\rho:G\\rightarrow GL_n({\\mathbb C})$ defined by\r\n$\\bar\\rho(g)=\\overline{\\rho(g)}$ for all $g\\in G$ is a representation of $G$;\r\nas $$Tr((\\bar\\rho(g))=Tr((\\overline{\\rho(g)})=\\overline{Tr((\\rho(g))}\r\n=\\overline{\\chi(g)}=\\bar\\chi(g)\\qquad\\hbox{for all }g\\in G,$$\r\nthe character of the representation $\\bar\\rho$ is $\\bar\\chi$. Clearly if\r\n$\\rho$ is reducible then so is $\\bar\\rho$; thus $\\chi$ is irreducible if and\r\nonly if $\\bar\\chi$ is.\r\n\\end{quote}\r\n{\\bf Theorem 35:} If $V$ is a ${\\mathbb C}G$-module and we have\r\n$V=U_1\\oplus\\cdots\\oplus U_r$ with the $U_i$ ${\\mathbb C}G$-submodules of $V$, then the\r\ncharacter of $V$ is the sum of the characters of the $U_i$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet ${\\cal B}_i$ be a basis of $U_i$ for $1\\leq i\\leq r$, and amalgamate the\r\nbases ${\\cal B}_i$ to form a basis ${\\cal B}$ of $V$; then for all $g\\in G$ we have\r\n$$[g]_{\\cal B}=\\left(\\begin{array}{ccc}[g]_{{\\cal B}_1}&\\cdots&0\\\\\r\n\\vdots&\\ddots&\\vdots\\\\0&\\cdots&[g]_{{\\cal B}_r}\\end{array}\\right).$$\r\nThus $Tr([g]_{\\cal B}) =Tr([g]_{{\\cal B}_1}) +\\cdots+Tr([g]_{{\\cal B}_r}) $, i.e., the character of\r\n$V$ is the sum of those of the $U_i$ as required.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=S_3$, and $V$ be the permutation module, with\r\ncharacter $\\chi$. We saw in section 1.4 that $V=U_1\\oplus U_2$, where\r\n$U_1=\\langle v_1+v_2+v_3\\rangle$ and $U_2=\\langle v_1-v_2,v_2-v_3\\rangle$.\r\nIf we let ${\\cal B}_1$ and ${\\cal B}_2$ be the bases $v_1+v_2+v_3$ of $U_1$ and\r\n$v_1-v_2,v_2-v_3$ of $U_2$, then the matrices $[g]_{{\\cal B}_i}$ are as follows.\r\n\r\n$$\r\n\\begin{array}{|c|c|c|c|c|c|c|}\r\n\\hline\r\ng&1&(1\\;2)&(1\\;3)&(2\\;3)&(1\\;2\\;3)&(1\\;3\\;2)\\\\\r\n\\hline\r\n[g]_{{\\cal B}_1}&(1)&(1)&(1)&(1)&(1)&(1)\\\\\r\n\\hline\r\n[g]_{{\\cal B}_2}&\r\n\\left(\\begin{array}{cc}1&0\\\\0&1\\end{array}\\right)&\r\n\\left(\\begin{array}{cc}-1&1\\\\0&1\\end{array}\\right)&\r\n\\left(\\begin{array}{cc}0&-1\\\\-1&0\\end{array}\\right)&\r\n\\left(\\begin{array}{cc}1&0\\\\1&-1\\end{array}\\right)&\r\n\\left(\\begin{array}{cc}0&-1\\\\1&-1\\end{array}\\right)&\r\n\\left(\\begin{array}{cc}-1&1\\\\-1&0\\end{array}\\right)\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nThus if we write $\\chi_i$ for the\r\ncharacter of $U_i$ for $i=1,2$, the character values are as follows.\r\n$$\r\n\\begin{array}{|c|cccccc|}\r\n\\hline\r\ng&1&(1\\;2)&(1\\;3)&(2\\;3)&(1\\;2\\;3)&(1\\;3\\;2)\\\\\r\n\\hline\r\n\\chi_1(g)&1&1&1&1&1&1\\\\\r\n\\chi_2(g)&2&0&0&0&-1&-1\\\\\r\n\\hline\r\n\\chi(g)&3&1&1&1&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nBy applying this result when each $U_i$ is irreducible, we see that any\r\ncharacter is a sum of irreducible ones. As with representations and\r\n${\\mathbb C}G$-modules, this concentrates attention on the irreducible characters.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} A character of degree $1$ is called a \\emph{linear\r\ncharacter}.\r\n\\\\\r\n\\\\\r\n{\\bf Examples:}\r\n\\begin{itemize}\r\n\\item[(i)] The three irreducible characters of $C_3$ are all linear.\r\n\\item[(ii)] Of the three irreducible characters of $D_6$, the first two are\r\nlinear but the third is not, since it has degree $2$.\r\n\\end{itemize}\r\n{\\bf Remark:}\r\nIf $V$ is a $1$-dimensional ${\\mathbb C}G$-module, then for all $g\\in G$ there exists\r\n$\\lambda_g\\in{\\mathbb C}$ such that $gv=\\lambda_gv$ for all $v\\in V$; the linear\r\ncharacter $\\chi$ of $V$ is given by $\\chi(g)=\\lambda_g$ for all $g\\in G$.\r\nAny irreducible character of an abelian group is linear.\r\nNote that a linear character of any group is certainly irreducible; also a\r\nlinear character is in fact a homomorphism from $G$ to the multiplicative\r\ngroup of non-zero complex numbers. (It is easy to see that the only characters\r\nwhich are homomorphisms in this way are the linear ones: if $\\chi$ is a\r\ncharacter of degree $d$ which is a homomorphism, we must have\r\n$\\chi(1)\\chi(1)=\\chi(1)$, i.e., $d^2=d$, and so $d=1$.)\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} The character of the trivial representation of\r\n$G$ is called the \\emph{trivial character} of $G$, and is written $1_G$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} The character $\\chi$ is called \\emph{faithful} if\r\n$ker(\\chi)=\\{1\\}$.\r\n\\\\\r\n\\\\\r\n{\\bf Examples:}\r\n\\begin{itemize}\r\n\\item[(i)] The irreducible characters of degree $2$ of $D_6$ and\r\n$D_8$ above are both faithful.\r\n\\item[(ii)] The two linear characters of $D_6$ are not faithful, since their\r\nkernels are $D_6$ and $\\langle a\\rangle\\cong C_3$ respectively.\r\n\\end{itemize}\r\n{\\bf Definition:} The character of the regular ${\\mathbb C}G$-module ${\\mathbb C}G$ is\r\ncalled the \\emph{regular character} of $G$, and is written $\\chi_{reg}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 36:} Let $V_1,\\dots,V_k$ be a complete set of\r\nnon-isomorphic irreducible ${\\mathbb C}G$-modules, and for $1\\leq i\\leq k$ let\r\n$\\chi_i$ be the character of $V_i$ and $d_i$ the dimension of $V_i$; then\r\n$\\chi_{reg}=d_1\\chi_1+\\cdots+d_k\\chi_k$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n$${\\mathbb C}G=\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{d_1\\ \\mathrm{terms}}\\oplus\r\n\\cdots\\oplus\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{d_k\\ \\mathrm{terms}};$$\r\nthe result now follows.\r\n\\end{quote}\r\n{\\bf Theorem 37:} $\\chi_{reg}(1)=|G|$, while $\\chi_{reg}(g)=0$ if\r\n$1\\neq g \\in G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $G=\\{g_1,\\dots,g_n\\}$, and let ${\\cal B}$ be the natural basis of ${\\mathbb C}G$.\r\nWe have $\\chi_{reg}(1)=n=|G|$. Given $1\\neq g\\in G$, for all\r\n$1\\leq i\\leq n$ we have $gg_i=g_j$ for some $j\\neq i$; thus the $i$th column of\r\n$[g]_{\\cal B}$ has zero everywhere except in the $j$th row, and in particular the\r\n$(i,i)$-entry of $[g]_{\\cal B}$ is zero for all $i$. Thus\r\n$\\chi_{reg}(g)=Tr([g]_{\\cal B}=0$ as required.\r\n\\end{quote}\r\n{\\bf Example:} \r\nConsider $G=D_6$. The irreducible characters are\r\n$\\chi_1$, $\\chi_2$ and $\\chi_3$, of degrees $1$, $1$ and $2$.\r\nCalculating the values of $\\chi_1+\\chi_2+2\\chi_3$, we get:\r\n$$\r\n\\begin{array}{|c|cccccc|}\r\n\\hline\r\ng&1&a&a^2&b&ba&ba^2\\\\\r\n\\hline\r\n\\chi_1(g)&1&1&1&1&1&1\\\\\r\n\\chi_2(g)&1&1&1&-1&-1&-1\\\\\r\n\\chi_3(g)&2&-1&-1&0&0&0\\\\\r\n\\hline\r\n(\\chi_1+\\chi_2+2\\chi_3)(g)&6&0&0&0&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n$\\chi_{reg}=\\chi_1+\\chi_2+2\\chi_3$ and\r\n$\\chi_{reg}$ takes the value $|G|$ at the element $1$ and $0$ elsewhere.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} If $G$ is a subgroup of $S_n$, the character of the\r\npermutation module for $G$ is called the \\emph{permutation character} of $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 38:} If $G$ is a subgroup of $S_n$, the function\r\n$\\nu:G\\rightarrow{\\mathbb C}$ defined by $\\nu(g)=|Fix(g)|-1$ is a character of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $V$ be the permutation module for $G$, and let $v_1,\\dots,v_n$ be the\r\nnatural basis of $V$; set $u=v_1+\\cdots+v_n$, and let $U$ be the\r\n$1$-dimensional subspace of $V$ spanned by $u$. Since $gu=u$ for all $g\\in G$,\r\nwe see that $U$ is a trivial ${\\mathbb C}G$-submodule of $V$, with character $1_G$.\r\nThere is a ${\\mathbb C}G$-submodule $W$ of $V$ such that $V=U\\oplus W$;\r\nlet $\\nu$ be the character of $W$. We have\r\n$$\\pi=1_G+\\nu,$$\r\nand so $|Fix(g)|=1+\\nu(g)$ for all $g\\in G$; thus $\\nu(g)=|Fix(g)|-1$ for all\r\n$g\\in G$.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=A_4$, a subgroup of $S_4$; then\r\n$G$ has four conjugacy classes, represented by $1$, $(1\\;2)(3\\;4)$,\r\n$(1\\;2\\;3)$ and $(1\\;3\\;2)$. The values of the character $\\nu$ are as follows.\r\n$$\r\n\\begin{array}{|c|cccc|}\r\n\\hline\r\ng&1&(1\\;2)(3\\;4)&(1\\;2\\;3)&(1\\;3\\;2)\\\\\r\n\\hline\r\n\\nu(g)&3&-1&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n\\section{The space of functions $G \\rightarrow {\\mathbb C}$}\r\n{\\bf Definition:} Given $\\theta:G\\rightarrow{\\mathbb C}$ and\r\n$\\phi: G \\rightarrow {\\mathbb C}$, we define\r\n$$\\langle\\theta,\\phi\\rangle\r\n=\\frac{1}{|G|}\\sum_{g \\in G} \\theta(g) \\overline{\\phi(g)}.$$\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 39:} If $G$ has precisely $\\ell$ conjugacy\r\nclasses $C_1,\\dots,C_\\ell$, with representatives $g_1,\\dots,g_\\ell$, and\r\n$\\chi$ and $\\psi$ are characters of $G$, then\r\n$$\\!\\langle\\chi,\\psi\\rangle=\\langle\\psi,\\chi\\rangle\r\n=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g)\\psi(g^{-1})\r\n=\\frac{1}{|G|}\\sum_{i=1}^\\ell|C_i|\\chi(g_i)\\overline{\\psi(g_i)}\r\n=\\sum_{i=1}^\\ell\\frac{\\chi(g_i)\\overline{\\psi(g_i)}}{|C_G(g_i)|}\\in{\\mathbb R}.\\!$$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe have five things to prove. First note that because\r\n$\\overline{\\psi(g)}=\\psi(g^{-1})$ for all $g\\in G$ by Theorem 32 (iii),\r\nwe have\r\n$$\\langle\\chi,\\psi\\rangle=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g)\\psi(g^{-1}).$$\r\nBecause $g^{-1}$ runs through $G$ as $g$ does, we also have\r\n$$\\langle\\chi,\\psi\\rangle=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g^{-1})\\psi(g)\r\n=\\langle\\psi,\\chi\\rangle.$$\r\nSince $\\langle\\chi,\\psi\\rangle=\\langle\\psi,\\chi\\rangle\r\n=\\overline{\\langle\\chi,\\psi\\rangle}$, we must have\r\n$\\langle\\chi,\\psi\\rangle\\in{\\mathbb R}$. Next, because characters are constant on\r\nconjugacy classes, we have\r\n$$\\sum_{g\\in C_i}\\chi(g)\\overline{\\psi(g)}\r\n=|C_i|\\chi(g_i)\\overline{\\psi(g_i)};$$\r\nthus as $G$ is the disjoint union of the conjugacy classes $C_i$, we have\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g)\\overline{\\psi(g)}\r\n=\\frac{1}{|G|}\\sum_{i=1}^\\ell\\sum_{g\\in C_i}\\chi(g)\\overline{\\psi(g)}\r\n=\\frac{1}{|G|}\\sum_{i=1}^\\ell|C_i|\\chi(g_i)\\overline{\\psi(g_i)}.$$\r\nFinally, as $|C_i|=|G|/|C_G(g_i)|$, we have\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\sum_{i=1}^\\ell\\frac{|C_i|}{|G|}\\chi(g_i)\\overline{\\psi(g_i)}\r\n=\\sum_{i=1}^\\ell\\frac{1}{|C_G(g_i)|}\\chi(g_i)\\overline{\\psi(g_i)}$$\r\nas required.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=A_4$ then \r\n$G$ has four conjugacy classes, with\r\nrepresentatives \r\n$$g_1=1,\\qquad g_2=(1\\;2)(3\\;4),\\qquad g_3=(1\\;2\\;3),\\qquad g_4=(1\\;3\\;2).$$\r\nThe conjugacy class sizes $|C_i|$ are as follows:\r\n$$\r\n\\begin{array}{rlrl}\r\nC_G(g_1)\\!\\!\\!\\!&=G&\\quad |C_1|\\!\\!\\!\\!&=|G|/|C_G(g_1)|=1,\\\\\r\nC_G(g_2)\\!\\!\\!\\!&=\\{1,(1\\;2)(3\\;4),(1\\;3)(2\\;4),(1\\;4)(2\\;3)\\},&\r\n|C_2|\\!\\!\\!\\!&=|G|/|C_G(g_2)|=3,\\\\\r\nC_G(g_3)\\!\\!\\!\\!&=\\{1,(1\\;2\\;3),(1\\;3\\;2)\\},&|C_3|\\!\\!\\!\\!&=|G|/|C_G(g_3)|=4,\\\\\r\nC_G(g_4)\\!\\!\\!\\!&=\\{1,(1\\;3\\;2),(1\\;2\\;3)\\},&|C_4|\\!\\!\\!\\!&=|G|/|C_G(g_4)|=4.\r\n\\end{array}\r\n$$\r\nLet $\\omega=e^{2\\pi i/3}$, then $G$ has characters $\\chi$ and\r\n$\\psi$ and:\r\n$$\r\n\\begin{array}{|c|cccc|}\r\n\\hline\r\ng&g_1&g_2&g_3&g_4\\\\\r\n\\hline\r\n|C_G(g)|&12&4&3&3\\\\\r\n\\hline\r\n|C_g|&1&3&4&4\\\\\r\n\\hline\r\n\\chi&1&1&\\omega&\\omega^2\\\\\r\n\\psi&4&0&\\omega^2&\\omega\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nSince $g_2$ has a total of $3$ conjugates, and $g_3$ and $g_4$ have\r\n$4$ each, we may calculate\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\frac{1}{12}(1.4+1.0+1.0+1.0+\\omega.\\overline{\\omega^2}\r\n+\\omega.\\overline{\\omega^2}+\\omega.\\overline{\\omega^2}\r\n+\\omega.\\overline{\\omega^2}+\\omega^2.\\overline{\\omega}\r\n+\\omega^2.\\overline{\\omega}+\\omega^2.\\overline{\\omega}\r\n+\\omega^2.\\overline{\\omega})=0;$$\r\nhowever, it is simpler to compute\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\sum_{i=1}^\\ell\\frac{\\chi(g_i)\\overline{\\psi(g_i)}}{|C_G(g_i)|}\r\n=\\frac{1.4}{12}+\\frac{1.0}{4}+\\frac{\\omega.\\overline{\\omega^2}}{3}\r\n+\\frac{\\omega^2.\\overline{\\omega}}{3}=0.$$\r\nNote that we also have\r\n$$\\langle\\psi,\\chi\\rangle\r\n=\\sum_{i=1}^\\ell\\frac{\\psi(g_i)\\overline{\\chi(g_i)}}{|C_G(g_i)|}\r\n=\\frac{4.1}{12}+\\frac{0.1}{4}\r\n+\\frac{\\omega^2.\\overline{\\omega}}{3}+\\frac{\\omega.\\overline{\\omega^2}}{3}=0,$$\r\nso that $\\langle\\chi,\\psi\\rangle=\\langle\\psi,\\chi\\rangle\\in{\\mathbb R}$. Similarly we\r\nfind that\r\n\\begin{eqnarray*}\r\n&\\langle\\chi,\\chi\\rangle\r\n=\\frac{1.1}{12}+\\frac{1.1}{4}+\\frac{\\omega.\\overline{\\omega}}{3}\r\n+\\frac{\\omega^2.\\overline{\\omega^2}}{3}=1,&\\\\\r\n&\\langle\\psi,\\psi\\rangle\r\n=\\frac{4.4}{12}+\\frac{0.0}{4}+\\frac{\\omega^2.\\overline{\\omega^2}}{3}\r\n+\\frac{\\omega.\\overline{\\omega}}{3}=2.&\r\n\\end{eqnarray*}\r\n\\\\\r\n\\\\\r\n{\\bf Remark:} \r\nSometimes it is possible to obtain information about\r\nclass sizes from knowledge of characters and their inner products. Here it\r\ntends to be more convenient to use the inner product formula in the form\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\frac{1}{|G|}\\sum_{i=1}^\\ell c_i\\chi(g_i)\\overline{\\psi(g_i)},$$\r\nwhere $g_1,\\dots,g_\\ell$ are representatives of the conjugacy classes, and\r\n$c_i=|C_i|$ for $1\\leq i\\leq\\ell$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 40:}\r\nIf $G \\lhd N$ and $\\chi$ is a character of $G/N$,\r\ndefine $\\tilde{\\chi}(g)= \\chi(gN)$.  $\\tilde{\\chi}$ is a character of $G$ and is irreducile iff\r\n$\\chi$ is irreducible.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis follows from the natural homomorphism $G \\rightarrow G/N$.\r\n\\end{quote}\r\n\\subsection{Orthonormality}\r\n{\\bf Theorem 41:} For all $w_1\\in W_1$ and\r\n$w_2\\in W_2$ we have\r\n$$e_1w_1=w_1,\\qquad e_1w_2=0,\\qquad\\qquad e_2w_1=0,\\qquad\r\ne_2w_2=w_2.$$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nGiven $w_2\\in W_2$, the map $\\theta:W_1\\rightarrow W_2$ defined by\r\n$\\theta(w_1)=w_1w_2$ for all $w_1\\in W_1$ is clearly a ${\\mathbb C}G$-homomorphism. \r\nSince $W_1$ and $W_2$ have no common composition factor we\r\nhave $ Hom_{{\\mathbb C}G}(W_1,W_2)=\\{0\\}$, and so $\\theta=0$. Thus $w_1w_2=0$ for all\r\n$w_1\\in W_1$ and $w_2\\in W_2$; in particular, $e_1w_2=0$ for all $w_2\\in W_2$.\r\nSimilarly $e_2w_1=0$ for all $w_1\\in W_1$. Since we then have\r\n\\begin{eqnarray*}\r\n&w_1=1w_1=(e_1+e_2)w_1=e_1w_1\\qquad\\hbox{for all }w_1\\in W_1,&\\\\\r\n&w_2=1w_2=(e_1+e_2)w_2=e_2w_2\\qquad\\hbox{for all }w_2\\in W_2,&\r\n\\end{eqnarray*}\r\nthe result follows.\r\n\\end{quote}\r\n{\\bf Corollary:} ${e_1}^2=e_1$, ${e_2}^2=e_2$ and\r\n$e_1e_2=e_2e_1=0$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nTake $w_1=e_1$ and $w_2=e_2$ in the previous result.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nAn element $e$ with $e^2=e$ is called an \\emph{idempotent},\r\nfrom the Latin for ``same power''.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 42:} If $\\chi$ is the character of $W_1$, then\r\n$$e_1=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g^{-1})g.$$\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $x \\in G$; then the map $\\theta: {\\mathbb C}G \\rightarrow {\\mathbb C}G$ given by\r\n$\\theta(w)=x^{-1}e_1w$ is linear. We shall calculate the trace of\r\n$\\theta$ (i.e., the trace of the matrix of $\\theta$ with respect to\r\nany basis of ${\\mathbb C}G$) in two ways; comparing the two answers will give the\r\nresult.\r\n\\\\\r\n\\\\\r\nFirst, for any $w_1\\in W_1$ and $w_2\\in W_2$ we have\r\n$$\\theta(w_1)=x^{-1}e_1w_1=x^{-1}w_1,\\qquad\\theta(w_2)=x^{-1}e_1w_2=0$$.\r\nWriting elements of $W_1\\oplus W_2$ as\r\nordered pairs $(w_1,w_2)$, we have\r\n$\\theta(w_1,w_2)=(\\theta_1(w_1),\\theta_2(w_2))$ where\r\n$\\theta_1(w_1)=x^{-1}w_1$ and $\\theta_2=0$. Hence\r\n$$Tr(\\theta=Tr(\\theta_1+Tr(\\theta_2=Tr(\\theta_1=\\chi(x^{-1}).$$\r\nSecondly, write $e_1=\\sum_{g\\in G}\\lambda_gg$. \r\nThe endomorphism of ${\\mathbb C}G$ which sends any element $w$ to $x^{-1}gw$ has trace\r\n$|G|$ if $x^{-1}g=1$, i.e., if $g=x$, and $0$ otherwise. Thus as\r\n$\\theta(w)=\\sum_{g\\in G}\\lambda_gx^{-1}gw$ for all $w\\in{\\mathbb C}G$, we see that\r\n$$Tr(\\theta)=\\lambda_x|G|.$$\r\nComparing the two expressions gives $\\lambda_x=\\frac{1}{|G|}\\chi(x^{-1})$,\r\nand so\r\n$$e_1=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g^{-1})g.$$\r\n\\end{quote}\r\n{\\bf Example:} With $G=C_3$ and $W_1$, $e_1$ as above, the character\r\n$\\chi$ of $W_1$ is given by $\\chi(1)=1$, $\\chi(a)=\\omega$ and\r\n$\\chi(a^2)=\\omega^2$; thus $\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g^{-1})g\r\n=\\frac{1}{3}(1+\\omega^2a+\\omega a^2)=e_1$.\r\n\\\\\r\n\\\\\r\n{\\bf Corollary:} If $\\chi$ is the character of $W_1$, then\r\n$\\langle\\chi,\\chi\\rangle=\\chi(1)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe calculate the coefficient of the basis element $1$ in ${e_1}^2$.\r\nWe have\r\n$${e_1}^2=\\frac{1}{|G|^2}\\sum_{g,h\\in G}\\chi(g^{-1})\\chi(h^{-1})gh$$\r\nand so the coefficient of $1$ is\r\n$$\\frac{1}{|G|^2}\\sum_{g\\in G}\\chi(g^{-1})\\chi(g)\r\n=\\frac{1}{|G|}\\langle\\chi,\\chi\\rangle.$$\r\nOn the other hand, we have ${e_1}^2=e_1$ \r\nand again the coefficient of $1$ in $e_1$ is $\\frac{1}{|G|}\\chi(1)$. Thus\r\n$\\langle\\chi,\\chi\\rangle=\\chi(1)$ as required.\r\n\\end{quote}\r\n{\\bf Theorem 43:} Let $U$ and $V$ be non-isomorphic irreducible\r\n${\\mathbb C}G$-modules, with characters $\\chi$ and $\\psi$; then\r\n$\\langle\\chi,\\chi\\rangle=1$ and $\\langle\\chi,\\psi\\rangle=0$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe know that ${\\mathbb C}G=U_1\\oplus\\cdots\\oplus U_r$ with the $U_i$ irreducible\r\n${\\mathbb C}G$-submodules of ${\\mathbb C}G$; let $dim (U)=m$ and $dim(V)=n$, so \r\nthere are precisely $m$ terms $U_i$ which are isomorphic to $U$ and\r\n$n$ which are isomorphic to $V$. We shall apply the corollary to two different\r\ndecompositions ${\\mathbb C}G=W_1\\oplus W_2$ in which $W_1$ and $W_2$ have no\r\ncommon composition factor.\r\n\\\\\r\n\\\\\r\nFirst, let $W_1$ be the sum of the $U_i$ which are isomorphic to\r\n$U$, and $W_2$ be the sum of the rest. The character of $W_1$ is\r\n$m\\chi$, since $W_1$ is the direct sum of $m$ ${\\mathbb C}G$-submodules each having\r\ncharacter $\\chi$. Thus by the corollary,  we have\r\n$$m\\chi(1)=\\langle m\\chi,m\\chi\\rangle=m^2\\langle\\chi,\\chi\\rangle;$$\r\nsince $\\chi(1)=dim(U) =m$ we have $\\langle\\chi,\\chi\\rangle=1$.\r\n\\\\\r\n\\\\\r\nNext, let $W_1$ be the sum of the $U_i$ which are isomorphic\r\nto either $U$ or $V$, and $W_2$ be the sum of the rest. The\r\ncharacter of $W_1$ is $m\\chi+n\\psi$. The corollary gives\r\n$$m\\chi(1)+n\\psi(1)=\\langle m\\chi+n\\psi,m\\chi+n\\psi\\rangle\r\n=m^2\\langle\\chi,\\chi\\rangle+n^2\\langle\\psi,\\psi\\rangle\r\n+mn(\\langle\\chi,\\psi\\rangle+\\langle\\psi,\\chi\\rangle).$$\r\nSince $\\langle\\chi,\\chi\\rangle=\\langle\\psi,\\psi\\rangle=1$ by the above, and\r\n$\\chi(1)=m$ and $\\psi(1)=n$, we have\r\n$$\\langle\\chi,\\psi\\rangle+\\langle\\psi,\\chi\\rangle=0;$$\r\nas $\\langle\\chi,\\psi\\rangle=\\langle\\psi,\\chi\\rangle$,\r\nwe must have $\\langle\\chi,\\psi\\rangle=0$.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=D_6$, so that the irreducible characters \r\n$\\chi_1,\\chi_2,\\chi_3$ are as follows.\r\n$$\r\n\\begin{array}{|c|ccc|}\r\n\\hline\r\ng&1&a&b\\\\\r\n\\hline\r\n|C_G(g)|&6&3&2\\\\\r\n\\hline\r\n\\chi_1&1&1&1\\\\\r\n\\chi_2&1&1&-1\\\\\r\n\\chi_3&2&-1&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nThus we have\r\n$$\r\n\\begin{array}{ll}\r\n\\langle\\chi_1,\\chi_1\\rangle=\\frac{1.1}{6}+\\frac{1.1}{3}+\\frac{1.1}{2}=1,\r\n&\\langle\\chi_1,\\chi_2\\rangle=\\frac{1.1}{6}+\\frac{1.1}{3}+\\frac{1.(-1)}{2}=0,\\\\\r\n\\langle\\chi_2,\\chi_2\\rangle=\\frac{1.1}{6}+\\frac{1.1}{3}+\\frac{(-1).(-1)}{2}=1,\r\n&\\langle\\chi_1,\\chi_3\\rangle=\\frac{1.2}{6}+\\frac{1.(-1)}{3}+\\frac{1.0}{2}=0,\\\\\r\n\\langle\\chi_3,\\chi_3\\rangle=\\frac{2.2}{6}+\\frac{(-1).(-1)}{3}+\\frac{0.0}{2}=1,\r\n&\\langle\\chi_2,\\chi_3\\rangle=\\frac{1.2}{6}+\\frac{1.(-1)}{3}+\\frac{(-1).0}{2}=0.\r\n\\end{array}\r\n$$\r\n{\\bf Theorem 44:} If $\\chi$ is any character of $G$, then\r\n$\\chi=d_1\\chi_1+\\cdots+d_k\\chi_k$ for some non-negative integers\r\n$d_1,\\dots,d_k$; moreover $d_i=\\langle\\chi,\\chi_i\\rangle$ for $1\\leq i\\leq k$,\r\nand $\\langle\\chi,\\chi\\rangle=\\sum_{i=1}^k{d_i}^2$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $V$ be a ${\\mathbb C}G$-module with character $\\chi$.\r\n$V$ is a\r\ndirect sum of irreducible ${\\mathbb C}G$-submodules, each of which is isomorphic to some\r\n$V_i$; thus there exist non-negative integers $d_1,\\dots,d_k$ such that\r\n$$V\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{d_1\\ \\mathrm{terms}}\\oplus\r\n\\cdots\\oplus\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{d_k\\ \\mathrm{terms}}.$$\r\nThus the character $\\chi$ is given by $\\chi=d_1\\chi_1+\\cdots+d_k\\chi_k$. Taking\r\ninner products now gives\r\n\\begin{eqnarray*}\r\n\\langle\\chi,\\chi_i\\rangle\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\langle d_1\\chi_1+\\cdots+d_k\\chi_k,\\chi_i\\rangle\r\n=\\sum_{j=1}^kd_j\\langle\\chi_j,\\chi_i\\rangle=d_i,\\\\\r\n\\langle\\chi,\\chi\\rangle\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\langle d_1\\chi_1+\\cdots+d_k\\chi_k,\r\nd_1\\chi_1+\\cdots+d_k\\chi_k\\rangle\r\n=\\sum_{i=1}^k\\sum_{j=1}^kd_id_j\\langle\\chi_i,\\chi_j\\rangle\r\n=\\sum_{i=1}^k{d_i}^2\r\n\\end{eqnarray*}\r\nas required.\r\n\\end{quote}\r\n{\\bf Remark:}\r\nThus if we are given any character $\\chi$, we can write it as a linear\r\ncombination of the irreducible characters, and the coefficients can be found\r\nsimply by calculating inner products. This result motivates the following\r\ndefinition.\r\n\\\\\r\n\\\\\r\n{\\bf Burnside's Algorithm:} Let the conjugacy classes of a finite group $G$ be\r\n$C_1, C_2, \\ldots , C_r$. $C_i C_j = \\sum_{s=1}^r c_{ijs} C_s$.  Thus\r\n$({\\frac {|C_i| \\chi_k(g_i)} {\\chi_k(1)}}) ({\\frac {|C_j| \\chi_k(g_j)} {\\chi_k(1)}}) =\r\n\\sum_{s=1}^r c_{ijs} ({\\frac {|C_s| \\chi_k(g_s)} {\\chi_k(1)}})$.  Multiply this\r\nequation by $a_{ki}$ and sum over $i$ to get:\r\n$(\\sum_{i=1}^r a_{ki} {\\frac {|C_i| \\chi_k(g_i)} {\\chi_k(1)}})\r\n({\\frac {|C_j| \\chi_k(g_j)} {\\chi_k(1)}}) =\r\n\\sum_{s=1}^r (\\sum_{i=1}^r a_{ki} c_{ijs}) {\\frac {|C_s| \\chi_k(g_s)} {\\chi_k(1)}}$\r\nPut $Y_{ki} = {\\frac {|C_i| \\chi_k(g_i)} {\\chi_k(1)}}$,\r\n$A_k = \\sum_{i=1}^r a_{ki} Y_{ki}$ and\r\n$B_{js}^{(k)} = \\sum_{i=1}^r c_{ijs} a_{ki}$, for $k = 1,2, \\ldots, r$.\r\nThen, \r\n\\\\\r\n$\r\n\\left(\\begin{array} {ccc}\r\nB_{11}^{(k)} & \\ldots  &  B_{1r}^{(k)}\\\\\r\n\\ldots & \\ldots & \\ldots \\\\\r\nB_{r1}^{(k)} & \\ldots  &  B_{rr}^{(k)}\\\\\r\n\\end{array}\\right) \r\n\\left(\\begin{array} {c}\r\nY_{k1} \\\\\r\nY_{k2} \\\\\r\n\\ldots \\\\\r\nY_{kr} \\\\\r\n\\end{array}\\right) =\r\nA_k\r\n\\left(\\begin{array} {c}\r\nY_{k1} \\\\\r\nY_{k2} \\\\\r\n\\ldots \\\\\r\nY_{kr} \\\\\r\n\\end{array}\\right)$\\\\\r\nSo, we can solve for the $Y_{kj}$ by computing the eigenvalues of \r\n$det(B_{is}^{(k)} - \\lambda I)$ and finding the corresponding eigenvectors.\r\n\\\\\r\n\\\\\r\n\\emph{Example, $S_3$}:\\\\\r\n\\\\\r\nLet $C_1 = (1)$, $C_2 = (123) + (132)$ and $C_3 = (12) + (13) + (23)$.\r\n$C_1 C_1 = C_1$,\r\n$C_1 C_2 = C_2 C_1 = C_2$,\r\n$C_1 C_3 = C_3 C_1 = C_3$,\r\n$C_2 C_3 = C_3 C_2 = 2 C_3$,\r\n$C_2 C_2 = C_2 C_2 = 2 C_1 + C_2$, and\r\n$C_3 C_3 = C_3 C_3 = 3 C_1 + 3C_3$.\r\n\\\\\r\nThe matricies $m_1 = (C_{1ij})$, $m_2 = (C_{2ij})$, and\r\n$m_3 = (C_{3ij})$ are:\\\\\r\n$m_1 = \\left(\\begin{array} {ccc}\r\n1 & 0 & 0 \\\\\r\n0 & 1 & 0 \\\\\r\n0 & 0 & 1 \\\\\r\n\\end{array}\\right)$\\\\\\\\\r\n$m_2 = \\left(\\begin{array} {ccc}\r\n0 & 1 & 0 \\\\\r\n2 & 1 & 0 \\\\\r\n0 & 0 & 2 \\\\\r\n\\end{array}\\right)$\\\\\r\n\\\\\r\n$m_3 = \\left(\\begin{array} {ccc}\r\n0 & 0 & 1 \\\\\r\n0 & 0 & 2 \\\\\r\n3 & 3 & 0 \\\\\r\n\\end{array}\\right)$\\\\\r\n\\\\\r\n$S_3$ character table is\r\n$\\left(\\begin{array} {ccc}\r\n1 & 1 & 1 \\\\\r\n1 & 1 & -1 \\\\\r\n2 & -1 & 0 \\\\\r\n\\end{array}\\right)$\\\\\r\n\\\\\r\nThis is computed as follows:  The eigenvalues of the respective matrix are $1$; $2, 1, -1$; and\r\n$3, -3, 0$.  The respective eigenvectors are\r\n$\\left(\\begin{array} {c}\r\n1 \\\\\r\n0 \\\\\r\n0 \\\\\r\n\\end{array}\\right)$,\r\n$\\left(\\begin{array} {c}\r\n0 \\\\\r\n1 \\\\\r\n0 \\\\\r\n\\end{array}\\right)$, and\r\n$\\left(\\begin{array} {c}\r\n0\\\\\r\n0\\\\\r\n1\\\\\r\n\\end{array}\\right)$;\r\n$\\left(\\begin{array} {c}\r\n0\\\\\r\n0\\\\\r\n1\\\\\r\n\\end{array}\\right)$,\r\n$\\left(\\begin{array} {c}\r\n1\\\\\r\n-1\\\\\r\n0\\\\\r\n\\end{array}\\right)$, and,\r\n$\\left(\\begin{array} {c}\r\n1\\\\\r\n2\\\\\r\n0\\\\\r\n\\end{array}\\right)$; and, finally,\r\n$\\left(\\begin{array} {c}\r\n1\\\\\r\n2\\\\\r\n3\\\\\r\n\\end{array}\\right)$,\r\n$\\left(\\begin{array} {c}\r\n1\\\\\r\n2\\\\\r\n-3\\\\\r\n\\end{array}\\right)$.\\\\\r\nConsider three of the eigenvalues\r\n$\r\n\\left(\\begin{array} {c}\r\n{\\frac {|C_1| \\chi_1(1)} {\\chi_1(1)}}\\\\\r\n{\\frac {|C_2| \\chi_1((123))} {\\chi_1(1)}}\\\\\r\n{\\frac {|C_3| \\chi_1((12))} {\\chi_1(1)}}\\\\\r\n\\end{array}\\right) =\r\n\\left(\\begin{array} {c}\r\n1\\\\\r\n2\\\\\r\n3\\\\\r\n\\end{array}\\right)\r\n$,\r\n$\r\n\\left(\\begin{array} {c}\r\n{\\frac {|C_1| \\chi_2(1)} {\\chi_2(1)}}\\\\\r\n{\\frac {|C_2| \\chi_2((123))} {\\chi_2(1)}}\\\\\r\n{\\frac {|C_3| \\chi_2((12))} {\\chi_2(1)}}\\\\\r\n\\end{array}\\right) =\r\n\\left(\\begin{array} {c}\r\n1\\\\\r\n2\\\\\r\n-3\\\\\r\n\\end{array}\\right)\r\n$, and,\r\n$\r\n\\left(\\begin{array} {c}\r\n{\\frac {|C_1| \\chi_3(1)} {\\chi_3(1)}}\\\\\r\n{\\frac {|C_2| \\chi_3((123))} {\\chi_3(1)}}\\\\\r\n{\\frac {|C_3| \\chi_3((12))} {\\chi_3(1)}}\\\\\r\n\\end{array}\\right) =\r\n\\left(\\begin{array} {c}\r\n1\\\\\r\n-1\\\\\r\n0\\\\\r\n\\end{array}\\right)\r\n$.  Remembering \r\n$|C_1| = 1$,\r\n$|C_2| = 2$, and\r\n$|C_3| = 3$, we can\r\nsolve for the $\\chi_k(g_i)$ giving the character table entries.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} If $\\chi$ is a character of $G$ and we write\r\n$\\chi=d_1\\chi_1+\\cdots+d_k\\chi_k$, then we call the irreducible character\r\n$\\chi_i$ a \\emph{constituent} of $\\chi$ if the coefficient $d_i$ is\r\nnon-zero.\r\nThus $\\chi_i$ is a constituent of $\\chi$ if and only if\r\n$\\langle\\chi,\\chi_i\\rangle>0$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 45:} If $V$ is a ${\\mathbb C}G$-module with character $\\chi$,\r\nthen $V$ is irreducible if and only if $\\langle\\chi,\\chi\\rangle=1$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $V$ is irreducible, then $\\langle\\chi,\\chi\\rangle=1$.\r\nConversely, assume that $\\langle\\chi,\\chi\\rangle=1$; write\r\n$$V\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{d_1\\ \\mathrm{terms}}\\oplus\r\n\\cdots\\oplus\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{d_k\\ \\mathrm{terms}},$$\r\nso that $\\chi=d_1\\chi_1+\\cdots+d_k\\chi_k$, and then we have\r\n$$1=\\langle\\chi,\\chi\\rangle={d_1}^2+\\cdots+{d_k}^2.$$\r\nAs the $d_i$ are non-negative integers, one (say $d_j$) must be $1$ and the\r\nremainder $0$; then $V\\cong V_j$ and so $V$ is irreducible.\r\n\\end{quote}\r\n{\\bf Theorem 46:} If $V$ and $W$ are ${\\mathbb C}G$-modules, with\r\ncharacters $\\chi$ and $\\psi$ respectively, then $V\\cong W$ if and only if\r\n$\\chi=\\psi$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe know that if $V\\cong W$ then\r\n$\\chi=\\psi$; it is the converse which we must show. Thus we assume that\r\n$\\chi=\\psi$, and seek to show that $V\\cong W$. There are non-negative integers\r\n$c_1,\\dots,c_k$ such that\r\n$$V\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{c_1\\ \\mathrm{terms}}\\oplus\r\n\\cdots\\oplus\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{c_k\\ \\mathrm{terms}},$$\r\nand similarly $d_1,\\dots,d_k$ such that\r\n$$W\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{d_1\\ \\mathrm{terms}}\\oplus\r\n\\cdots\\oplus\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{d_k\\ \\mathrm{terms}}.$$\r\nSince $\\chi=\\psi$, for $1\\leq i\\leq k$ we have\r\n$$c_i=\\langle\\chi,\\chi_i\\rangle=\\langle\\psi,\\chi_i\\rangle=d_i,$$\r\nand so $V\\cong W$ as required.\r\n\\end{quote}\r\n{\\bf Theorem 47:} The irreducible characters\r\n$\\chi_1,\\dots,\\chi_k$ are linearly independent vectors in the vector\r\nspace of functions $G\\rightarrow{\\mathbb C}$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nAssume that $\\lambda_1,\\dots,\\lambda_k\\in{\\mathbb C}$ with\r\n$$\\lambda_1\\chi_1+\\dots+\\lambda_k\\chi_k=0.$$\r\nTaking inner products with $\\chi_i$ gives\r\n$$0=\\langle\\lambda_1\\chi_1+\\dots+\\lambda_k\\chi_k,\\chi_i\\rangle=\\lambda_i;$$\r\nsince this is true for all $1\\leq i\\leq k$, we see that the $\\chi_i$ are\r\nlinearly independent.\r\n\\end{quote}\r\n{\\bf Theorem 48:} If $V$ and $W$ are ${\\mathbb C}G$-modules with characters\r\n$\\chi$ and $\\psi$, then we have\r\n$dim( Hom_{{\\mathbb C}G}(V,W))=\\langle\\chi,\\psi\\rangle$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nAs before there exist non-negative integers $c_1,\\dots,c_k$ and\r\n$d_1,\\dots,d_k$ such that\r\n\r\n\\begin{eqnarray*}\r\n&V\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{c_1\\ \\mathrm{terms}}\r\n\\oplus\\cdots\\oplus\r\n\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{c_k\\ \\mathrm{terms}},&\\\\\r\n&W\\cong\\underbrace{(V_1\\oplus\\cdots\\oplus V_1)}_{d_1\\ \\mathrm{terms}}\r\n\\oplus\\cdots\\oplus\r\n\\underbrace{(V_k\\oplus\\cdots\\oplus V_k)}_{d_k\\ \\mathrm{terms}}.&\r\n\\end{eqnarray*}\r\nSo\r\n\\begin{eqnarray*}\r\ndim( Hom_{{\\mathbb C}G}(V,W))\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^k\\sum_{j=1}^kc_id_j dim( Hom_{{\\mathbb C}G}(V_i,V_j))\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\sum_{i=1}^k\\sum_{j=1}^kc_id_j\\delta_{ij}\r\n=\\sum_{i=1}^kc_id_i.\r\n\\end{eqnarray*}\r\n\r\nOn the other hand, we have $\\chi=\\sum_{i=1}^kc_i\\chi_i$ and\r\n$\\psi=\\sum_{j=1}^kd_j\\chi_j$, and so\r\n$$\\langle\\chi,\\psi\\rangle\r\n=\\sum_{i=1}^k\\sum_{j=1}^kc_id_j\\langle\\chi_i,\\chi_j\\rangle\r\n=\\sum_{i=1}^k\\sum_{j=1}^kc_id_j\\delta_{ij}=\\sum_{i=1}^kc_id_i.$$\r\nThe result follows.\r\n\\end{quote}\r\n\r\n\\subsection{Center of the group algebra}\r\n{\\bf Definition:} The \\emph{center} of the group algebra ${\\mathbb C}G$ is the\r\nsubspace\r\n$${\\mathbb Z}({\\mathbb C}G)=\\{z\\in{\\mathbb C}G:zr=rz\\hbox{ for all }r\\in{\\mathbb C}G\\}.$$\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} Let $C_1,\\dots,C_\\ell$ be the distinct conjugacy\r\nclasses of $G$, and for $1\\leq i\\leq\\ell$ define\r\n$$\\bar C_i=\\sum_{g\\in C_i}g\\in{\\mathbb C}G;$$\r\nthe elements $\\bar C_1,\\dots,\\bar C_\\ell$ of ${\\mathbb C}G$ are called the \\emph{class\r\nsums}.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 49:} The class sums\r\n$\\bar C_1,\\dots,\\bar C_\\ell$ form a basis of ${\\mathbb Z}({\\mathbb C}G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe first show that each $\\bar C_i$ lies in ${\\mathbb Z}({\\mathbb C}G)$. Let $g\\in C_i$, and\r\nset $|C_i|=r$; write\r\n$$C_i=\\{{y_1}^{-1}gy_1,{y_2}^{-1}gy_2,\\dots,{y_r}^{-1}gy_r\\}$$\r\nfor some $y_1,\\dots,y_r\\in G$, so that\r\n$\\bar C_i=\\sum_{j=1}^r{y_j}^{-1}gy_j$. For all $h\\in G$, we have\r\n$$h^{-1}\\bar C_ih=\\sum_{j=1}^rh^{-1}{y_j}^{-1}gy_jh\r\n=\\sum_{j=1}^r(y_jh)^{-1}g(y_jh).$$\r\nThis is a sum of $r$ conjugates of $g$; and they are distinct, since\r\n$$h^{-1}{y_j}^{-1}gy_jh=h^{-1}{y_k}^{-1}gy_kh\r\n\\iff{y_j}^{-1}gy_j={y_k}^{-1}gy_k.$$\r\nThus $h^{-1}\\bar C_ih=\\bar C_i$, and so $\\bar C_ih=h\\bar C_i$; since this is\r\ntrue for all $h\\in G$, we see that $\\bar C_i$ commutes with all $r\\in{\\mathbb C}G$,\r\ni.e., $\\bar C_i\\in {\\mathbb Z}({\\mathbb C}G)$.\r\n\\\\\r\n\\\\\r\nNow for $1\\leq i\\leq\\ell$ let $g_i$ be a representative of $C_i$.\r\nIt is clear that the $\\bar C_i$ are linearly independent,\r\nsince if $\\sum_{i=1}^\\ell\\lambda_i\\bar C_i=0$ then considering the\r\ncoefficient of $g_i$ shows that $\\lambda_i=0$ for all $i$. Thus we must\r\nshow that the $\\bar C_i$ span ${\\mathbb Z}({\\mathbb C}G)$. Let\r\n$z=\\sum_{g\\in G}\\lambda_gg\\in {\\mathbb Z}({\\mathbb C}G)$. For\r\nall $h\\in G$ we have $zh=hz$, and so $h^{-1}zh=z$, i.e.,\r\n$$\\sum_{g\\in G}\\lambda_gh^{-1}gh=\\sum_{g\\in G}\\lambda_gg.$$\r\nSince the coefficient of $g$ in the sum on the left is $\\lambda_{hgh^{-1}}$,\r\nwe must have\r\n$$\\lambda_{hgh^{-1}}=\\lambda_g\\qquad\\hbox{for all }g,h\\in G;$$\r\ni.e., the coefficients in $z$ of two conjugate elements $g$ and $hgh^{-1}$ are\r\nequal. Thus we have $z=\\sum_{i=1}^\\ell\\lambda_{g_i}\\bar C_i$; so the\r\n$\\bar C_i$ do indeed span ${\\mathbb Z}({\\mathbb C}G)$ as required.\r\n\\end{quote}\r\n{\\bf Examples:}\r\n\\begin{itemize}\r\n\\item[(i)] Let $G=S_3$, then a basis of ${\\mathbb Z}({\\mathbb C}G)$ is\r\n$$1,\\qquad(1\\;2)+(1\\;3)+(2\\;3),\\qquad(1\\;2\\;3)+(1\\;3\\;2).$$\r\n\\item[(ii)] Let $G=D_8$, then a basis of ${\\mathbb Z}({\\mathbb C}G)$ is\r\n$$1,\\qquad a^2,\\qquad a+a^3,\\qquad b+ba^2,\\qquad ba+ba^3.$$\r\n\\end{itemize}\r\n{\\bf Theorem 50:} If $V$ is an irreducible ${\\mathbb C}G$-module\r\nand $z\\in {\\mathbb Z}({\\mathbb C}G)$, then there exists $\\lambda\\in{\\mathbb C}$ such that\r\n$zv=\\lambda v$ for all $v\\in V$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nFor all $r\\in{\\mathbb C}G$ and $v\\in V$, we have\r\n$$z(rv)=r(zv);$$\r\nthus the map $\\theta:V\\rightarrow V$ defined by $\\theta(v)=zv$ is a\r\n${\\mathbb C}G$-homomorphism. By a previous Lemma (ii), $\\theta=\\lambda1_V$ for some\r\n$\\lambda\\in{\\mathbb C}$, i.e., $zv=\\lambda v$ for all $v\\in V$.\r\n\\end{quote}\r\n{\\bf Observation:}\r\nWe may now give our second basis of ${\\mathbb Z}({\\mathbb C}G)$.\r\nRecall that we have the complete set of non-isomorphic\r\nirreducible ${\\mathbb C}G$-modules $V_1,\\dots,V_k$. We write\r\n$${\\mathbb C}G=W_1\\oplus\\cdots\\oplus W_k,$$\r\nwhere each $W_i$ is isomorphic to a direct sum of copies of $V_i$; the summands\r\n$W_i$ are called the \\emph{homogeneous components} of ${\\mathbb C}G$. We set\r\n$$1=e_1+\\cdots+e_k,$$\r\nwhere $e_i\\in W_i$ for $1\\leq i\\leq k$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 51:} The elements $e_1,\\dots,e_k$ form a basis\r\nof ${\\mathbb Z}({\\mathbb C}G)$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe begin by showing that each $e_i\\in {\\mathbb Z}({\\mathbb C}G)$; it clearly suffices to\r\nconsider the case $i=1$. If we set $X=W_2\\oplus\\cdots\\oplus W_k$, we have\r\n$${\\mathbb C}G=W_1\\oplus X,$$\r\nand $W_1$ and $X$ have no common composition factor; thus,\r\nwe see that $w_1x=0=xw_1$ for all $w_1\\in W_1$ and $x\\in X$.\r\nThus if we set $e=e_2+\\cdots+e_k\\in X$, for all $w_1\\in W_1$ we have\r\n$$w_1=w_11=w_1(e_1+e)=w_1e_1+w_1e=w_1e_1.$$\r\nIt follows that we have $e_1w_1=w_1=w_1e_1$ for all $w_1\\in W_1$, and\r\n$e_1x=0=xe_1$ for all $x\\in X$;\r\nsince ${\\mathbb C}G=W_1\\oplus X$ we see that $e_1\\in {\\mathbb Z}({\\mathbb C}G)$ as required.\r\n\\\\\r\n\\\\\r\nNow the $e_i$ are certainly linearly independent, as the sum\r\nof the $W_i$ is direct. To show that they span ${\\mathbb Z}({\\mathbb C}G)$, take\r\n$z\\in {\\mathbb Z}({\\mathbb C}G)$; then for $1\\leq i\\leq k$ there\r\nexists $\\lambda_i\\in{\\mathbb C}$ such that\r\n$$zv=\\lambda_iv\\qquad\\hbox{for all }v\\in V_i.$$\r\nHence $zw=\\lambda_iw$ for all $w\\in W_i$, and in particular\r\n$ze_i=\\lambda_ie_i$, for $1\\leq i\\leq k$; thus\r\n$$z=z1=z(e_1+\\cdots+e_k)=ze_1+\\cdots+ze_k=\\lambda_1e_1+\\cdots+\\lambda_ke_k.$$\r\nTherefore $z$ is a linear combination of the $e_i$, so $e_1,\\dots,e_k$ do\r\nindeed span ${\\mathbb {\\mathbb {\\mathbb {\\mathbb Z}}}}({\\mathbb C}G)$; \r\nthus they form a basis of ${\\mathbb Z}({\\mathbb C}G)$ as required.\r\n\\end{quote}\r\n{\\bf Corollary:} The number of irreducible characters of $G$ is\r\nequal to the number of conjugacy classes of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe have $k= dim({\\mathbb Z}({\\mathbb C}G))= \\ell$.\r\n\\end{quote}\r\n{\\bf Example:} Let $G=D_6$; we have\r\n${\\mathbb C}G=U_1\\oplus U_2\\oplus U_3\\oplus U_4$ with $U_1$ the trivial ${\\mathbb C}G$-module,\r\n$U_2$ the other $1$-dimensional ${\\mathbb C}G$-module, and $U_3\\cong U_4$ with\r\n$dim (U_3)= dim(U_4) = 2$. We therefore have $W_1=U_1$, $W_2=U_2$ and\r\n$W_3=U_3\\oplus U_4$; the elements $e_i$ are\r\n$$e_1={\\ts\\frac{1}{6}}(1+a+a^2+b+ba+ba^2),\\quad\r\ne_2={\\ts\\frac{1}{6}}(1+a+a^2-b-ba-ba^2),\\quad\r\ne_3={\\ts\\frac{1}{3}}(2.1-a-a^2).$$\r\nIf we consider $e_3$, we have\r\n$$e_3a={\\ts\\frac{1}{3}}(2a-a^2-1)=ae_3,\\qquad\r\ne_3b={\\ts\\frac{1}{3}}(2b-ab-a^2b)={\\ts\\frac{1}{3}}(2b-ba^2-ba)=be_3;$$\r\nas $a$ and $b$ generate $G$ we see that $e_3\\in {\\mathbb Z}({\\mathbb C}G)$.\r\n\\subsection{The space of class functions}\r\n{\\bf Definition:} A \\emph{class function} on $G$ is a function\r\n$\\psi:G\\rightarrow{\\mathbb C}$ with the property that $\\psi(g)=\\psi(h)$ if\r\n$g,h\\in G$ are conjugate.  The set of class functions on $G$ is written $ cl$. \r\nIt is clear that $ cl$ is\r\na subspace of the vector space of all functions $G\\rightarrow{\\mathbb C}$. Moreover, it\r\nis easy to provide a basis of $ cl$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} If $C$ is a conjugacy class of $G$, the function\r\n$\\psi_C:G\\rightarrow{\\mathbb C}$ defined by\r\n$\\psi_C(g)=1, g\\in C$,\r\n$\\psi_C(g)=0, g \\notin C$\r\nis called the \\emph{characteristic function} of the class $C$.\r\n\\\\\r\n\\\\\r\n{\\bf Example:} Let $G=D_6$, and write $C_1=\\{1\\}$,\r\n$C_2=\\{a,a^2\\}$ and $C_3=\\{b,ba,ba^2\\}$ as before; then the\r\ncharacteristic functions $\\psi_{C_i}$ are as follows.\r\n$$\r\n\\begin{array}{|c|cccccc|}\r\n\\hline\r\n&1&a&a^2&b&ba&ba^2\\\\\r\n\\hline\r\n\\psi_{C_1}&1&0&0&0&0&0\\\\\r\n\\psi_{C_2}&0&1&1&0&0&0\\\\\r\n\\psi_{C_3}&0&0&0&1&1&1\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 52:} The characteristic functions\r\n$\\psi_{C_1},\\dots,\\psi_{C_\\ell}$ form a basis of $ cl$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIt is clear that $\\psi_{C_i}\\in cl$ for $1\\leq i\\leq\\ell$. If\r\n$\\lambda_1\\psi_{C_1}+\\cdots+\\lambda_\\ell\\psi_{C_\\ell}=0$, evaluating at\r\n$g_j$ gives $\\lambda_j=0$; as this is true for all $1\\leq j\\leq\\ell$, the\r\n$\\psi_{C_i}$ are linearly independent. Given $\\psi\\in cl$, set\r\n$\\lambda_i=\\psi(g_i)$ for all $i$; then\r\n$\\sum_{i=1}^\\ell\\lambda_i\\psi_{C_i}$ is a class function agreeing\r\nwith $\\psi$ on all $g_i$, so it must be equal to it. Thus the\r\n$\\psi_{C_i}$ span $ cl$; so they form a basis as required.\r\n\\end{quote}\r\n{\\bf Example:} If $G=D_6$ as above, the class function\r\n$\\psi$ given by $\\psi(1)=3$, $\\psi(a)=\\psi(a^2)=1$ and\r\n$\\psi(b)=\\psi(ba)=\\psi(ba^2)=0$ is equal to $3\\psi_{C_1}+\\psi_{C_2}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 53:} The irreducible characters\r\n$\\chi_1,\\dots,\\chi_k$ form a basis of $ cl$; indeed if\r\n$\\psi$ is a class function then $\\psi=\\sum_{i=1}^k\\lambda_i\\chi_i$, where\r\n$\\lambda_i=\\langle\\psi,\\chi_i\\rangle$ for $1\\leq i\\leq k$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe $\\chi_i$ are linearly independent, so they\r\nspan a subspace of $ cl$ of dimension $k$; since $dim(cl) = \\ell =k$,\r\nthey form a basis of $ cl$. Given $\\psi\\in cl$ we may therefore write\r\n$\\psi=\\sum_{i=1}^k\\lambda_i\\chi_i$ for some $\\lambda_i\\in{\\mathbb C}$; since\r\n$\\langle\\chi_i,\\chi_j\\rangle=\\delta_{ij}$, taking inner products with\r\n$\\chi_i$ gives $\\langle\\psi,\\chi_i\\rangle=\\lambda_i$ as required.\r\n\\end{quote}\r\n{\\bf Corollary:} If $g,h\\in G$, then $g$ is conjugate\r\nto $h$ if and only if $\\chi(g)=\\chi(h)$ for all characters $\\chi$ of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $g$ is conjugate to $h$ then $\\chi(g)=\\chi(h)$ for\r\nall characters $\\chi$ of $G$. Conversely, if $\\chi(g)=\\chi(h)$ for all\r\ncharacters $\\chi$, then by the Theorem, we have $\\psi(g)=\\psi(h)$ for all\r\n$\\psi\\in cl$. In particular, this is true for the characteristic function\r\n$\\psi_C$ of the class $C$ containing $g$; thus $\\psi_C(h)=\\psi_C(g)=1$, and so\r\n$h\\in C$, i.e., $h$ lies in the same conjugacy class as $g$.\r\n\\end{quote}\r\n{\\bf Corollary:} If $g\\in G$, then $g$ is conjugate to\r\n$g^{-1}$ if and only if $\\chi(g)\\in {\\mathbb R}$ for all characters $\\chi$ of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nSince $\\chi(g)\\in {\\mathbb R}$ if and only if\r\n$\\chi(g)=\\overline{\\chi(g)}=\\chi(g^{-1})$, the\r\nresult follows immediately from the corollary.\r\n\\end{quote}\r\n\\subsection{Character tables and orthogonality relations}\r\n{\\bf Definition:} The $k\\times k$ matrix with $(i,j)$-entry\r\n$\\chi_i(g_j)$ is called the \\emph{character table} of $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} The relations\r\n$$\\sum_{i=1}^k\\frac{\\chi_r(g_i)\\overline{\\chi_s(g_i)}}{|C_G(g_i)|}=\\delta_{rs}$$\r\nare called the \\emph{row orthogonality relations} for $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Definition:} The relations\r\n$$\\sum_{i=1}^k\\chi_i(g_r)\\overline{\\chi_i(g_s)}=\\delta_{rs}|C_G(g_r)|$$\r\nare called the \\emph{column orthogonality relations} for $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 54:} The character table for $G$ satisfies the row\r\nand column orthogonality relations.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nWe already know that the row orthogonality relations hold. For\r\n$1\\leq s\\leq k$, we may write the characteristic function $\\psi_{C_s}$ as a\r\nlinear combination of $\\chi_1,\\dots,\\chi_k$; say\r\n$\\psi_{C_s}=\\lambda_1\\chi_1+\\cdots+\\lambda_k\\chi_k$.\r\nTaking inner products with $\\chi_i$ gives\r\n$$\\lambda_i=\\langle\\psi_{C_s},\\chi_i\\rangle\r\n=\\frac{1}{|G|}\\sum_{g\\in G}\\psi_{C_s}(g)\\overline{\\chi_i(g)}.$$\r\nNow the only elements $g$ for which $\\psi_{C_s}(g)\\neq0$ are those lying in the\r\nconjugacy class $C_s$; since there are $|G|/|C_G(g_s)|$ of\r\nthem, each having $\\psi_{C_s}(g)=1$, we have\r\n$$\\lambda_i=\\frac{1}{|G|}\\sum_{g\\in C_s}\\psi_{C_s}(g)\\overline{\\chi_i(g)}\r\n=\\frac{\\overline{\\chi_i(g_s)}}{|C_G(g_s)|}.$$\r\nThus\r\n$$\\delta_{rs}=\\psi_{C_s}(g_r)=\\sum_{i=1}^k\\lambda_i\\chi_i(g_r)\r\n=\\sum_{i=1}^k\\frac{\\chi_i(g_r)\\overline{\\chi_i(g_s)}}{|C_G(g_r)|}.$$\r\n\\end{quote}\r\n{\\bf Examples:}\r\n\\begin{itemize}\r\n\\item[(i)] Let $G=D_6$.\r\n$$\\sum_{i=1}^3\\chi_i(g_1)\\overline{\\chi_i(g_1)}=1.1+1.1+2.2=6,\\quad\r\n\\sum_{i=1}^3\\chi_i(g_1)\\overline{\\chi_i(g_2)}=1.1+1.1+2.(-1)=0.$$\r\n\\item[(ii)] Suppose $G$ is a group of order $12$ with four conjugacy classes,\r\nand we are given the following part of the character table, in which\r\n$\\omega=e^{2\\pi i/3}$.\r\n$$\r\n\\begin{array}{|c|cccc|}\r\n\\hline\r\ng&g_1&g_2&g_3&g_4\\\\\r\n\\hline\r\n|C_G(g)|&12&4&3&3\\\\\r\n\\hline\r\n\\chi_1&1&1&1&1\\\\\r\n\\chi_2&1&1&\\omega&\\omega^2\\\\\r\n\\chi_3&1&1&\\omega^2&\\omega\\\\\r\n\\chi_4&&&&\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nWe use the column orthogonality relations to determine the\r\nfinal row of the table. The entries in the first column are the degrees of\r\nthe $\\chi_i$, so they are all positive integers.  The relation\r\nwith $r=s=1$ implies that the sum of the squares of these entries is $12$, and\r\nso $\\chi_4(g_1)=3$. Next, the relation with $r=1$ and $s=2$ yields\r\n$$0=1.1+1.1+1.1+3\\overline{\\chi_4(g_2)};$$\r\nso $\\chi_4(g_2)=-1$. Similarly, those with $r=1$ and $s=3$ or $4$ give\r\n$\\chi_4(g_3)=0=\\chi_4(g_4)$. Thus the full character table is:\r\n$$\r\n\\begin{array}{|c|cccc|}\r\n\\hline\r\ng&g_1&g_2&g_3&g_4\\\\\r\n\\hline\r\n|C_G(g)|&12&4&3&3\\\\\r\n\\hline\r\n\\chi_1&1&1&1&1\\\\\r\n\\chi_2&1&1&\\omega&\\omega^2\\\\\r\n\\chi_3&1&1&\\omega^2&\\omega\\\\\r\n\\chi_4&3&-1&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n\\end{itemize}\r\n{\\bf Theorem 55:} If $N\\norm G$ and $\\tilde\\chi$ is a character\r\nof $G/N$, then the function $\\chi:G\\rightarrow{\\mathbb C}$ defined by\r\n$\\chi(g)=\\tilde\\chi(gN)$ for all $g\\in G$ is a character of $G$; the characters\r\n$\\chi$ and $\\tilde\\chi$ have the same degree, and $\\chi$ is irreducible if and\r\nonly if $\\tilde\\chi$ is.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\tilde\\rho:G/N\\rightarrow GL_n({\\mathbb C})$ be a representation of $G/N$ with\r\ncharacter $\\tilde\\chi$. Define a function $\\rho:G\\rightarrow GL_n({\\mathbb C})$ by\r\n$$\\rho(g)=\\tilde\\rho(gN)\\qquad\\hbox{for all }g\\in G;$$\r\nthen $\\rho(g)\\rho(h)=\\tilde\\rho(gN)\\tilde\\rho(hN)=\\tilde\\rho(gN.hN)\r\n=\\tilde\\rho(ghN)=\\rho(gh)$, so $\\rho$ is a homomorphism, i.e., a representation\r\nof $G$. The character $\\chi$ of $\\rho$ is given by\r\n$$\\chi(g)=Tr(\\rho(g)=Tr((\\tilde\\rho(gN))=\\tilde\\chi(gN)\\qquad\\hbox{for all }\r\ng\\in G;$$\r\nmoreover $\\chi(1)=\\tilde\\chi(N)$ so that $\\chi$ and $\\tilde\\chi$ have the\r\nsame degree. Finally, let $U$ be a subspace of the vector space ${\\mathbb C}^n$; then by\r\ndefinition of $\\rho$ we have $\\rho(g)u=\\tilde\\rho(gN)u$ for all $g\\in G$ and\r\n$u\\in U$. Thus\r\n\\begin{eqnarray*}\r\nU\\hbox{ is a ${\\mathbb C}G$-submodule of }{\\mathbb C}^n\r\n\\!\\!\\!\\!&\\iff&\\!\\!\\!\\!\\rho(g)u\\in U\\hbox{ for all }g\\in G,\\ u\\in U\\\\\r\n\\!\\!\\!\\!&\\iff&\\!\\!\\!\\!\\tilde\\rho(gN)u\\in U\\hbox{ for all }g\\in G,\\ u\\in U\\\\\r\n\\!\\!\\!\\!&\\iff&\\!\\!\\!\\! U\\hbox{ is a ${\\mathbb C}(G/N)$-submodule of }{\\mathbb C}^n;\r\n\\end{eqnarray*}\r\nso the representation $\\rho$ is reducible if and only if\r\n$\\tilde\\rho$ is, and thus $\\chi$ is irreducible if and only if\r\n$\\tilde\\chi$ is.\r\n\\end{quote}\r\n{\\bf Definition:} If $N\\norm G$ and $\\tilde\\chi$ is a character of\r\n$G/N$, then the character $\\chi$ of $G$ defined by\r\n$$\\chi(g)=\\tilde\\chi(gN)\\qquad\\hbox{for all }g\\in G$$\r\nis called the \\emph{lift} of $\\tilde\\chi$ to $G$.\r\n\\\\\r\n\\\\\r\n{\\bf Example:} Let $G=S_4$; then if we write $v_{ij}$ for\r\n$v_{\\{i,j\\}}$, the second permutation module for $G$ has basis\r\n$v_{12},v_{13},v_{14},v_{23},v_{24},v_{34}$. If we take conjugacy class\r\nrepresentatives $1$, $(1\\;2)$, $(1\\;2)(3\\;4)$, $(1\\;2\\;3)$ and $(1\\;2\\;3\\;4)$,\r\nthen $1$ fixes all six basis elements, $(1\\;2)$ and $(1\\;2)(3\\;4)$ each fix\r\njust $v_{12}$ and $v_{34}$, while $(1\\;2\\;3)$ and $(1\\;2\\;3\\;4)$ both fail to\r\nfix any basis elements. Thus the values of the second permutation character\r\nare as follows.\r\n\r\n$$\r\n\\begin{array}{|c|ccccc|}\r\n\\hline\r\n&1&(1\\;2)&(1\\;2)(3\\;4)&(1\\;2\\;3)&(1\\;2\\;3\\;4)\\\\\r\n\\hline\r\n\\pi_2&6&2&2&0&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n\r\n Together with the first permutation character, lifts from the\r\nquotient $S_4/A_4\\cong C_2$ and the orthogonality relations, this enables us\r\nto obtain the full character table of $G$.\r\n\r\n$$\r\n\\begin{array}{|c|ccccc|}\r\n\\hline\r\n&1&(1\\;2)&(1\\;2)(3\\;4)&(1\\;2\\;3)&(1\\;2\\;3\\;4)\\\\\r\n\\hline\r\n\\chi_1&1&1&1&1&1\\\\\r\n\\chi_2&1&-1&1&1&-1\\\\\r\n\\chi_3&2&0&2&-1&0\\\\\r\n\\chi_4&3&1&-1&0&-1\\\\\r\n\\chi_5&3&-1&-1&0&1\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nWe may also define the \\emph{third permutation character} of $G$ by\r\nconsidering unordered triples, and so on.\r\n\\\\\r\n\\\\\r\nThe third method applies when we have a non-trivial linear character of\r\n$G$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 56:} If $\\chi$ and $\\lambda$ are characters of\r\n$G$ and $\\lambda$ is linear, then the function\r\n$\\lambda\\chi:G\\rightarrow{\\mathbb C}$ defined by\r\n$\\lambda\\chi(g)=\\lambda(g)\\chi(g)$ for all $g\\in G$ is a character of $G$;\r\nif $\\chi$ is irreducible, so is $\\lambda\\chi$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nLet $\\rho:G\\rightarrow GL_n({\\mathbb C})$ be a representation of $G$ with character\r\n$\\chi$, and define a map $\\lambda\\rho: G \\rightarrow GL_n({\\mathbb C})$ by\r\n$$(\\lambda\\rho)(g)=\\lambda(g)\\rho(g)\\qquad\\hbox{for all }g \\in G;$$\r\nthus $(\\lambda\\rho)(g)$ is the matrix obtained by multiplying $\\rho(g)$ by the\r\ncomplex number $\\lambda(g)$. For all $g,h\\in G$ we have\r\n\r\n\\begin{eqnarray*}\r\n(\\lambda\\rho)(gh)\\!\\!\\!\\!&=&\\!\\!\\!\\!\\lambda(gh)\\rho(gh)\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\lambda(g)\\lambda(h)\\rho(g)\\rho(h)\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!\\lambda(g)\\rho(g)\\lambda(h)\\rho(h)\\\\\r\n\\!\\!\\!\\!&=&\\!\\!\\!\\!(\\lambda\\rho)(g)(\\lambda\\rho)(h),\r\n\\end{eqnarray*}\r\n\r\n and so $\\lambda\\rho$ is a homomorphism, i.e., a\r\nrepresentation of $G$. The trace\r\nof the matrix $(\\lambda\\rho)(g)$ is $\\lambda(g)Tr(\\rho(g)=\\lambda(g)\\chi(g)$;\r\nthus $\\lambda\\chi$ is the character of the representation $\\lambda\\rho$. For\r\nirreducibility, we note that for all $g\\in G$ the complex number\r\n$\\lambda(g)$ is a root of unity, and so\r\n$\\lambda(g)\\overline{\\lambda(g)}=1$; thus\r\n$$\\langle\\lambda\\chi,\\lambda\\chi\\rangle\r\n=\\frac{1}{|G|}\\sum_{g\\in G}\\lambda(g)\\chi(g)\\overline{\\lambda(g)\\chi(g)}\r\n=\\frac{1}{|G|}\\sum_{g\\in G}\\chi(g)\\overline{\\chi(g)}\r\n=\\langle\\chi,\\chi\\rangle,$$\r\nso $\\chi$ is irreducible if and only if $\\lambda\\chi$ is.\r\n\\end{quote}\r\n{\\bf Examples:}\r\n\\begin{itemize}\r\n\\item[(i)] Let $G=S_4$. We\r\nobtain a non-trivial linear character of $G$ by lifting from the quotient\r\n$S_4/A_4\\cong C_2$; this gives the character $\\chi_2$ (which corresponds to\r\nthe sign homomorphism). If we write $\\lambda=\\chi_2$, we see that\r\n$$\\lambda\\chi_1=\\chi_2,\\quad\\lambda\\chi_2=\\chi_1,\\quad\r\n\\lambda\\chi_3=\\chi_3,\\quad\\lambda\\chi_4=\\chi_5,\\quad\r\n\\lambda\\chi_5=\\chi_4.$$\r\n\\item[(ii)] Let $G=A_4$, we have two non-trivial linear characters,\r\n$\\chi_2$ and $\\chi_3$. If we set $\\lambda=\\chi_2$, we have\r\n$$\\lambda\\chi_1=\\chi_2,\\quad\\lambda\\chi_2=\\chi_3,\\quad\r\n\\lambda\\chi_3=\\chi_1,\\quad\\lambda\\chi_4=\\chi_4.$$\r\n\\end{itemize}\r\n{\\bf Example:} Let $G=S_5$; then $G$ has seven conjugacy classes,\r\nwith representatives\r\n$$1,\\quad(1\\;2),\\quad(1\\;2)(3\\;4),\\quad(1\\;2\\;3),\\quad(1\\;2\\;3\\;4),\r\n\\quad(1\\;2\\;3\\;4\\;5),\\quad(1\\;2\\;3)(4\\;5),$$\r\nand centralizer sizes $120$, $12$, $8$, $6$, $4$, $5$ and\r\n$6$ respectively. We have the trivial character $1_G$ and\r\nwe have the normal subgroup $A_5$ with quotient $S_5/A_5 \\cong C_2$, so we may\r\nlift the non-trivial irreducible character of $C_2$ to $G$ to obtain a second\r\nlinear character $\\lambda$ (which again corresponds to the sign homomorphism).\r\nWe also have the first and second permutation characters $\\pi_1$ and $\\pi_2$;\r\nthe values of the characters found so far are as follows.\r\n$$\r\n\\begin{array}{|c|ccccccc|}\r\n\\hline\r\n&1&(1\\;2)&(1\\;2)(3\\;4)&(1\\;2\\;3)&(1\\;2\\;3\\;4)&(1\\;2\\;3\\;4\\;5)&(1\\;2\\;3)(4\\;5)\\\\\r\n\\hline\r\n1_G&1&1&1&1&1&1&1\\\\\r\n\\lambda&1&-1&1&1&-1&1&-1\\\\\r\n\\pi_1&5&3&1&2&1&0&0\\\\\r\n\\pi_2&10&4&2&1&0&0&1\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\nOf these, $1_G$ and $\\lambda$ are irreducible, and shall be called\r\n$\\chi_1$ and $\\chi_2$ respectively. We find that\r\n$\\langle\\pi_1,\\chi_1\\rangle=1$, and so $\\nu_1=\\pi_1-\\chi_1$ is a\r\ncharacter; then $\\langle\\nu_1,\\nu_1\\rangle=1$, so\r\nthat $\\nu_1$ is a third irreducible character $\\chi_3$. Since\r\n$\\lambda\\nu_1 \\neq \\nu_1$, we have a fourth irreducible character\r\n$\\chi_4=\\lambda\\nu_1$. We then find that \r\n$$\\langle\\pi_2,\\chi_1\\rangle=\\langle\\pi_2,\\chi_3\\rangle=1,$$\r\nand so $\\nu_2=\\pi_2-\\chi_1-\\chi_3$ is a character; as\r\n$\\langle\\nu_2,\\nu_2\\rangle=1$, we see that $\\nu_2$ is a fifth irreducible\r\ncharacter $\\chi_5$. Again, $\\lambda\\nu_2\\neq\\nu_2$, so we have a sixth\r\nirreducible character $\\chi_6=\\lambda\\nu_2$. Finally, the seventh irreducible\r\ncharacter may be determined using the orthogonality relations; the full\r\ncharacter table is as follows.\r\n$$\r\n\\begin{array}{|c|ccccccc|}\r\n\\hline\r\n&1&(1\\;2)&(1\\;2)(3\\;4)&(1\\;2\\;3)&(1\\;2\\;3\\;4)&(1\\;2\\;3\\;4\\;5)&(1\\;2\\;3)(4\\;5)\\\\\r\n\\hline\r\n\\chi_1&1&1&1&1&1&1&1\\\\\r\n\\chi_2&1&-1&1&1&-1&1&-1\\\\\r\n\\chi_3&4&2&0&1&0&-1&-1\\\\\r\n\\chi_4&4&-2&0&1&0&-1&1\\\\\r\n\\chi_5&5&1&1&-1&-1&0&1\\\\\r\n\\chi_6&5&-1&1&-1&1&0&-1\\\\\r\n\\chi_7&6&0&-2&0&0&1&0\\\\\r\n\\hline\r\n\\end{array}\r\n$$\r\n\\section {Characters and group structure}\r\n{\\bf Observation:}\r\nThe character table determines the normal subgroups and the nilpotent groups.\r\nGeneral procedure for calculating characters: (1) Derive a faithful representation,\r\n(2) generate group elements, (3) determine conjugacy classes, (4) determine structure\r\nconstants ($|C_i||C_j|= \\sum_k \\alpha_{ijk} |C_k|$), (5) get characters from structure\r\nconstants.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 57:}\r\nIf $\\chi$ is an irreducible character, $\\chi(1) \\mid |G|$ \r\n\\begin{quote}\r\n\\emph{Proof:}\r\nIf $g_i$ is in the $i$-th conjugacy class,\r\n${\\frac {|G|} {|C_G(g_i)|}} {\\frac {\\chi(g_i)} {\\chi(1)}}$ and ${\\overline {\\chi(g)}}$\r\nare algebraic integers so\r\n$\\sum_{i=1}^k {\\frac {|G|} {|C_G(g_i)|}} {\\frac {\\chi(g_i)} {\\chi(1)}}{\\overline {\\chi(g)}}\r\n={\\frac {|G|} {\\chi(1)}}$ is and algebraic integer.  Since it is rational, it must be in\r\n${\\mathbb Z}$.\r\n\\end{quote}\r\n{\\bf Theorem 58:}\r\nIf $G \\subseteq S_n$, $\\alpha: G \\rightarrow {\\mathbb C}$ by $\\alpha(g)= |Fix(g)|-1$,\r\nthen $\\alpha$ is a character of $G$. Define $ker(\\rho)= \\{g: \\chi_{\\rho}(g)= \\chi_{\\rho}(1) \\}$.\r\n$\\rho$ is faithful iff $ker(\\rho)=1$.  $N= \\{n: |\\chi(n)|= \\chi(1) \\} \\lhd G$. \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nThis is easy.\r\n\\end{quote}\r\n{\\bf Theorem 59:}\r\n$N \\lhd G, \\exists \\chi_i: \\bigcap_{i=1}^r ker(\\chi_i) =N$.  \r\n$g \\sim h$ iff $\\chi(g) = \\chi(h), \\forall  \\chi$.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $g, h$ are conjugate, it's clear $\\chi(g) = \\chi(h), \\forall  \\chi$.\r\nIf $\\chi(g) = \\chi(h), \\forall  \\chi$, it's also true for any class function.  Pick the class\r\nfunction which is $1$ in $ccl_G(g)$ and $0$ elsewhere and the result follows.\r\n\\end{quote}\r\n{\\bf Theorem 60:}\r\n$ccl_{A_n}(x)=ccl_{S_n}(x)$ otherwise\r\n$ccl_{S_n}(x)$ splits into two conjugacy classes in $A_n$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$S_n = A_n \\cup A_n (12)$ and the result follows.\r\n\\end{quote}\r\n{\\bf Theorem 61:}\r\nLet $C_i= \\sum_{x \\in ccl(y)} x$ then the $C_i$ form a basis for ${\\mathbb Z}(FG)$.\r\nThere are $|G/G'|$ inequivalent linear representations (characters) of $G$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $A$ is abelian, there are $|A|$ inequivalent linear representations (characters) of $G$\r\nby the decomposition results.  Each gives rise to an inequivalent linear representation of $G/G'$.\r\nSo $G/G'$ has at least $|G/G'|$ inequivalent linear representations.\r\n\\end{quote}\r\n{\\bf Theorem 62:}\r\n$\\chi(g)$ is real iff\r\n$\\chi(g)= \\chi(g^{-1}), \\forall \\chi$.  $N \\lhd G$ iff $\\exists \\chi_i, i= 1, \\ldots, k$\r\nsuch that $\\bigcap_{i=1}^k ker(\\chi_i)=N$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIn ${\\mathbb C}$, $\\chi(g^{-1}) = {\\overline {\\chi(g)}}$.\r\n\\end{quote}\r\n{\\bf Theorem 63:}\r\n$G$ is not simple iff $\\exists \\chi, g \\ne 1:\r\n\\chi(g)= \\chi(1)$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf such a $g$ exists, it is in the kernel of $\\chi$.\r\n\\end{quote}\r\n{\\bf Theorem 64:}\r\n$G$ has $|G/G'|$ linear characters.\r\nIf all irreducible representations of $G$ have dimension $1$, $G$ is abelian.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nEvery linear character, $\\chi$, has $G' \\subseteq ker(\\chi)$.  Further, if $N \\lhd G$,\r\n$G' \\subseteq N$ means $G/N$ is abelian.  Further, every linear character of $G$ is a\r\nlift of linear character of $G/G'$.\r\n\\end{quote}\r\n{\\bf Theorem 65:}\r\nLet $H$ be the kernel of $\\theta$ then (i) $|\\theta(g)| \\leq \\theta(1)$,\r\n(ii) $\\theta(g) = \\theta(1)$, iff $g \\in H$,\r\n(iii) $|\\theta(g)| = \\theta(1)$, iff $gH$ is in the center of $G/H$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\theta(g)$ is the sum of $\\theta(1)$ roots of unity showing (i).\r\n(ii) is the definition.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nDefine $(\\theta , \\eta)= {\\frac 1 {|G|}} \\sum_g \\theta(g) {\\overline {\\eta(g)}}$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 66:}\r\nIf $U = U_{1} \\otimes ... \\otimes U_{s}$, the number of these similar to $U_{1}$\r\nis ${\\frac {(\\theta, \\eta)} {(\\eta, \\eta)}}$.\r\n$(\\theta, \\rho_{G})= \\theta(1)$,\r\n$(\\chi_{i}, \\chi_{j})= \\delta_{ij}$,\r\n$\\sum_{g} \\chi(g) = |G| \\delta_{i1}$,\r\n$\\sum_{i} \\chi_{i}^{2}(1) = |G| $.\r\n$\\omega_{i}(R_{j})= |r_{j}|\\chi_{i}(g)/\\chi_{i}(1)$,\r\n$\\omega_{t}(R_{i}) \\omega_{t}(R_{j})= \\sum_{s} a_{ijs} \\omega_{t}(R_{s})$.\r\n$\\sum_{t} \\chi_{t}(g_{i}) {\\overline \\chi_{t}(g_{j})} =\r\n{\\frac {|G|}{|R_{j}|}} \\delta_{ij}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nCalculations based on the decomposition theorem.\r\n\\end{quote}\r\n{\\bf Theorem 67:}\r\nThe number of conjugacy classes = number of irreducible representations.\r\n$\\omega_{i}(R_{j})$ is an algebraic integer.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nEach element of the representation affording each $\\omega$ is an algebraic integer and a\r\ncharacter is just field operations of these elements.\r\n\\end{quote}\r\n\\section {Some applications of character theory}\r\n{\\bf Theorem 70:}\r\nSuppose $\\chi$ is a character of a ${\\mathbb C}G$-module, $V$, and $g \\in G$ has order\r\n$m$ then (1) $\\chi(1)=dim(V)$, (2) $\\chi(g)$ is a sum of $m$-th roots of unity,\r\n(3) $\\chi(g^{-1})= {\\overline {\\chi(g)}}$ and (4) $\\chi(g)$ is real iff $g \\sim g^{-1}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n(a) is trivial.\r\nFor (b), put the matrix affording $\\chi$ into Jordan form (maybe by extending the field).  Raising\r\nthe matrix to the $n$-th power (where $g^n = 1$), we get the identity.  The character of $g$ is thus\r\nthe sum of roots of $1$.\r\n\\end{quote}\r\n{\\bf Burnside's Lemma:} \r\n$|{\\frac {\\chi(g)} {\\chi(1)}}| \\le 1$.  If\r\n$|{\\frac {\\chi(g)} {\\chi(1)}}| \\ne 1$ it is not an algebraic integer.  \r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\chi(g)$ is the sum of $\\chi(1)$ roots of unity.\r\n\\end{quote}\r\n{\\bf Theorem 71:}\r\nLet $\\chi$ be an irreducible character and $R$ a conjugacy class.\r\nIf $(\\chi(1), |R|)=1$ then either $|\\chi(g)|= \\chi(1)$ (equivalently, \r\n$R \\subseteq {\\mathbb Z}(\\chi)$) or $\\chi(g)=0$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$\\exists s, t \\in {\\mathbb Z}: s|R|+ t \\chi(1) =1$, so,\r\n$s|R| \\chi(g) + t \\chi(1) \\chi(g)  = \\chi(g)$.  \r\n$a_1= {\\frac {\\chi(g)} {\\chi(1)}}$ is an algebraic integer.  Let its\r\nconjugates be $a_2 , \\ldots a_m$.  For each $a_1$, $|a_i| \\le 1$ and\r\n$\\prod_{i=1}^m |a_i| \\le 1$ is a rational integer so\r\n$\\prod_{i=1}^m |a_i| = 0$ or\r\n$\\prod_{i=1}^m |a_i| = 1$.  In the former case, $\\chi(g)= 0$ and in the latter\r\ncase, $|\\chi(g)|= \\chi(1)$.\r\n\\end{quote}\r\n{\\bf Theorem 72:}\r\nLet $p$ be a prime and $G$ a finite\r\ngroup with conjugacy class of size $p^r, r \\ge 1$, then $G$ is not a non-abelian simple group.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $g \\in R$.  Every non-principal irreducible character $\\chi_i, i>1$ of $G$ is faithful.\r\n$\\sum_{i=2}^k \\chi_i(1) \\chi_i(g) + 1 = 0$ so $\\exists i: \\chi_i(g) \\chi_i(g) \\ne 0 \\jmod{p}$.\r\nThus $(|R|, \\chi_i(1)) =1$ and since $\\chi_i(g) \\ne 0$, applying the previous result,\r\nwe have $g \\in {\\mathbb Z}(G)$.\r\n\\end{quote}\r\n{\\bf Burnside's Theorem:} Every group of order $p^a q^b$ is solvable.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $G$ be a minimal counterexample.  If $G$ is abelian, the theorem is true.  \r\nIf not, some element of\r\n$G$ has a conjugacy class of prime power order.  This contradicts the previous result.\r\n\\end{quote}\r\n{\\bf Theorem 73:} The number of real irreducible characters of $G$ is the number of real conjugacy\r\nclasses in $G$,\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $X$ be the character table of $G$.  Since ${\\overline X}$ is also a matrix of irreducible\r\ncharacters so $P X = {\\overline X}$, where $P$ is a permutation matrix.  Similarly,\r\n$X Q = {\\overline X}$ and $Q= X^{-1}PX$.  The number of irreducible real characters of $G$\r\nis $tr(X)$ and the number of irreducible conjugacy classes is $tr(Q)$, and the result holds.\r\n\\end{quote}\r\n{\\bf Corollary:}\r\n$G$ has a non-trivial real irreducible character iff $G$ has even order.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nStraightforward.\r\n\\end{quote}\r\n\\section {Feit's moduleless treatment}\r\n{\\bf Maschke:} If $char(F)$ does not divide $|G|$, then $F$-representations of $G$\r\nare completely reducible.  For $\\phi$ irreducible,\r\nif $\\exists S: \\forall g, S \\phi(g) = \\phi(g) S$ then S is non-singular.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 74:}\r\nIf $A(g), B(g)$ are $k$-irreducible then (i) if $A$ is not similar to $B$,\r\nand,\r\n$\\sum_{g} a_{is}(g) b_{tj}(g^{-1}) = 0$; or,\r\n(ii) $A$, $B$ are absolutely irreducible and\r\n$\\sum_{g} a_{is}(g^{-1}) a_{tj}(g) =\r\n{\\frac {|G|} {n}} \\delta_{ij} \\delta_{st}$, where $n \\times n$ is the\r\ndimension of $(a_{is}(g))$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 75:}\r\nIf $A^{s}$ is absolutely irreducible then $a^{s}_{ij}(g)$ are linearly\r\nindependent and $\\sum_{s=1}^k n_{s}^{2} \\leq |G|$.\r\n\\section{Induced Representations and Characters}\r\n{\\bf Theorem 76:}\r\nLet $U$ be a ${\\mathbb C}H$ submodule then the map $\\theta(x) = xr, r \\in {\\mathbb C}G$ is\r\na ${\\mathbb C}H$-homomorphism from $U$ into ${\\mathbb C}G$.  Any ${\\mathbb C}H$\r\nhomomorphism into ${\\mathbb C}G$ can be represented this way.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\nThe first statement is obvious.  If $\\theta$ is a ${\\mathbb C}H$ homomorphism into\r\n${\\mathbb C}G$, ${\\mathbb C}H= U \\oplus W$ for some ${\\mathbb C}H$ invariant, $W$.\r\nDefine \r\n$\\varphi(u+w)= \\theta(u)$ then\r\n$\\varphi(u)= \\theta(u), u \\in U$.  If $r= \\varphi(1)$, \r\n$\\varphi(u)= \\varphi(u \\cdot 1)=\r\nu \\varphi(1)= ur $.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nIf $X \\subseteq {\\mathbb C}G$, define $X({\\mathbb C}G)= span \\{ xg, g \\in G, x \\in X \\}$.\r\nIf $H \\le G$ and $U$ is a ${\\mathbb C}H$ module,\r\nfurther define the induced representation $U^G= U({\\mathbb C}G)$.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 77:}\r\nIf $U, V$ are isomorphic ${\\mathbb C}H$ modules, $U^G, V^G$ are isomorphic  ${\\mathbb C}G$\r\nmodules.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nStraightforward.\r\n\\end{quote}\r\n{\\bf Theorem 78:}\r\nIf $U, V$ are ${\\mathbb C}H$ modules and $U \\cap V= \\{ 0 \\}$, then $U^G \\cap V^G = \\{ 0 \\}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nLet $\\theta: U \\rightarrow W$ be a ${\\mathbb C}H$-homomorphism.  \r\n$\\exists r \\in {\\mathbb C}G: \\theta(u)= ru$ and\r\n$\\exists s \\in {\\mathbb C}G: \\theta^{-1}(v)= sv$.  If $a \\in U^G$, $a$ is a linear combination of\r\nthe elements $ug$.  So $ra$ is a linear combination of elements $rug$ and $ra \\in V^G$.  Moreover,\r\n$\\phi \\in Hom_{{\\mathbb C} G}$, $a\\phi(g)= \\phi(ag)$.  $sra=a$ and $rsb=b$ so $b \\mapsto sb$ is $\\phi^{-1}$.\r\nSo $\\phi$ is a ${\\mathbb C} G$ isomorphism.\r\n\\end{quote}\r\n{\\bf Theorem 79:}\r\nIf $U$ is a ${\\mathbb C}H$ module of ${\\mathbb C}H$ and\r\nIf $V$ is a ${\\mathbb C}G$ module of ${\\mathbb C}G$ then\r\n$ dim(Hom_{{\\mathbb C}G}(U^G, V))= dim(Hom_{{\\mathbb C}H}(U, V_{|H}))$\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nIf $\\theta \\in\r\nHom_{{\\mathbb C}G}(U^G, V)) $, \r\n$\\exists r \\in {\\mathbb C}G$: $\\theta(s)= sr, s \\in U^G$.  Define\r\n${\\overline \\theta}= \\theta_{|H}$.   The map $\\theta \\mapsto {\\overline \\theta}$\r\nis a linear transformation from\r\n$ Hom_{{\\mathbb C}G}(U^G, V)$ to $Hom_{{\\mathbb C}H}(U, V_{|H})$.  First we show it\r\nis invertible: \r\nIf $\\varphi \\in Hom_{{\\mathbb C}H}(U, V_{|H})$,\r\n$\\exists r \\in {\\mathbb C}G: \\varphi(u)= ur$.  Define $\\theta: U^G \\rightarrow {\\mathbb C}G$\r\nby $\\theta(s)= sr, s \\in U^G$ then\r\n$\\theta \\in Hom_{{\\mathbb C}G}(U^G, V) $ and ${\\overline \\theta}= \\varphi$.  Now\r\nthe transformation is injective because if\r\n$r_1 , r_2 \\in {\\mathbb C}G$ and  $u r_1 = u r_2, \\forall u \\in U$, then\r\n$r_1 s = r_2 s, \\forall s \\in U^G$.\r\n\\end{quote}\r\n{\\bf Definition:}\r\nIf $H \\le G$ and $\\varphi$ a class function on $H$, \r\n$\\varphi^G(g)= {\\frac 1 {|H|}} \\sum_{x \\in G} \\varphi^* (x^{-1}gx)$ is called an\r\n\\emph{induced character}, where $\\varphi^*(x)= 0, x \\notin H$ and\r\n$\\varphi^*(x)= \\varphi(x), x \\in H$.  It actually is a character.\r\n\\\\\r\n\\\\\r\n{\\bf Frobenius Reciprocity Theorem:} \r\n$(\\varphi^G , \\theta)= (\\varphi, \\theta_{|H})$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\nSuppose first that \r\n$(\\varphi$ and $\\theta$ are irreducible with underlying representation modules\r\n$U$ and $V$.  Then\r\n$(\\varphi^G , \\theta)_G = dim(Hom_{{\\mathbb C}G}(U^G, V))$ and\r\n$(\\varphi , \\theta_{|H})_H = dim(Hom_{{\\mathbb C}H}(U, V_{|H})$ and the result follows from\r\nthe earlier theorem.  Since any character is the linear combination of irreducible characters,\r\nthe result follows from the bilinarity of the form.\r\n\\end{quote}\r\n{\\bf Remark:}  Note that $deg(\\phi^G)= \\phi^G(1)= {\\frac {|G|} {|H|}} \\phi(1)$.\r\nWe define  $f^G_x(y) = 1$, if $y \\in x^G$ and\r\n$f^G_x(y) = 0$, otherwise.\r\n\\\\\r\n\\\\\r\n{\\bf Theorem 80:}\r\n$(\\chi, f^G_x) = {\\frac {\\chi(x)} {|C_G(x)|}}$.\r\nIf no element of $g^G$ lies in $H$ then $\\phi^G(g)= 0$.\r\nIf some element of $g^G$ lies in $H$ then \r\n$\\phi^G(g)= \r\n|C_G(g)|(\r\n{\\frac {\\phi(x_1 )} {|C_H(x_1)|}} + \\ldots +\r\n{\\frac {\\phi(x_m )} {|C_H(x_m)|}} ) $ where $(f^G_g)_{|H}= \r\nf^H_{x_1} + \\ldots +\r\nf^H_{x_m}$.\r\n\\begin{quote}\r\n\\emph{Proof:}  \r\n$(\\chi , {f_x}^G) = {\\frac 1 {|G|}} \\sum_{g \\in G} \\chi(g) {f_x}^G(g)= $\r\n${\\frac 1 {|G|}} \\sum_{g \\in G} \\chi(g) {f_x}^G(g)= {\\frac {|x^G|} {|G|}} \\chi(x) = {\\frac {\\chi(g)} {|C_G(x)|}}$.\r\n\\end{quote}\r\n{\\bf Brauer's Characterization of Characters:} $p$-elementary groups are the products of\r\na cyclic $p'$ group and $p$ group.  Every irreducible character is an induced character\r\nof a linear character of a $p$ elementary subgroup for some $p$.\r\n\\begin{quote}\r\n\\emph{Proof:}\r\n\\\\\r\n\\\\\r\n\\emph{Step 1:}  \r\nLet $\\chi_1 , \\ldots , \\chi_h$ be the irreducible characters of $G$\r\nover ${\\mathbb C}$ and let $X_R(G)= \\{ \\sum a_i \\chi_i \\}$,\r\n$V_R(G) = \\{ \\sum r_i \\phi_1 , \\phi_i $ and irreducible character of an\r\nelementary abelian subgroup of $G \\}$, $U_R(G)= \\{ \\chi: G \\rightarrow {\\mathbb C} \\}$ where\r\n$\\chi$ is a class function of an elementary abelian subgroup $E$ of $G$, $\\chi_{|E} \\in X_R(E)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 2:}  \r\n$V_R(G) \\subseteq X_R(G) \\subseteq U_R(G)$ and $V_R(G)$ is an ideal in $U_R(G)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 3:}  \r\nLet $E= A \\times B$ be elementary with $(|A|, |B|)= 1$.  $\\exists \\psi = \\psi_a \\in V_S(G)$\r\nsuch that (1) $\\psi(g) \\in {\\mathbb Z}, \\forall g \\in G$,\r\n(2) if $g$ is not conjugate to an element of $gB$ then $\\psi(g)= 0$ and\r\n(3) $\\psi(a)= |C(a):B|$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 4:} Let $ {\\cal C_1}, {\\cal C_1}, \\ldots, {\\cal C_k} $\r\nbe the conjugacy classes of $G$ which consist of $p'$-elements then $\\forall i, 1 \\le i \\le k$,\r\n$\\exists \\tau_i \\in V_S(G):$\r\n(1) $\\tau_i(g) \\in Z, g \\in G$,\r\n(2) $\\tau_i(g) = 0$ if the $p'$ part of $g$ is not in ${\\cal C}_i$,\r\n(3) $\\tau_i(g) = 1 \\jmod{p} $ if the $p'$ part of $g \\in {\\cal C}_i$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 5:} \r\nIf $p$ is prime, $\\exists \\phi \\in V_S(G)$ such that $\\forall g \\in G, \\phi(g) \\in Z$ and\r\n$\\phi(g)= 1 \\jmod{p}$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 6:} \r\nIf $\\alpha: G \\rightarrow {\\mathbb C}$ is a class function and $\\alpha(g) \\in |G|S,\r\n\\forall g \\in G$ then $\\alpha \\in V_S(G)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 7:} \r\n$|G|= p^n g_0$, $p \\nmid g_0$ then $\\alpha(x)= g_0 \\in V_S(G)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 8:} \r\n$1 \\in V_S(G)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 9:} \r\n$1 \\in V_Z(G)$.\r\n\\\\\r\n\\\\\r\n\\emph{Step 10:}  $1 \\in V_Z(G) \\le V_R(G)$ so by step $2$,\r\n$V_R(G) = X_R(G)= U_R(G)$.\r\n\\end{quote}\r\n{\\bf RSK correspondence} for representations\r\nof the symmetric group: $\\exists$ bijection between $S_n$ and the set of ordered\r\ntableau of the same shape $g \\leftrightarrow (S,T)$, further\r\n$g^{-1} \\leftrightarrow (T,S)$.\r\n\\\\\r\n\\\\\r\n{\\bf Young's diagram:} $D(\\lambda )$, $n= n_1 + n_2 + \\ldots + n_k$,\r\n$n_1 \\geq n_2 \\geq \\ldots \\geq n_k$.\r\nNumber of tableaus with shape $\\lambda$:\r\n$f_{ \\lambda } = \\frac { n!} {\\prod_{i,j \\in D(\\lambda )} {h(i, j)}}$, where\r\n$h(i, j)$ = number of cells in hook $H_{i,j}$.\r\n", "meta": {"hexsha": "d64187ccbfd64cb0fc367aa54f2b37eadb091bd7", "size": 105308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groups/gtRepresentations.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/gtRepresentations.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/gtRepresentations.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": 42.8255388369, "max_line_length": 154, "alphanum_fraction": 0.6194211266, "num_tokens": 43262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8519528076067262, "lm_q1q2_score": 0.7597809240155339}}
{"text": "\\chapter{Singular cohomology}\nHere's one way to motivate this chapter. It turns out that:\n\\begin{itemize}\n\t\\ii $H_n(\\CP^2) \\cong H_n(S^2 \\vee S^4)$ for every $n$.\n\t\\ii $H_n(\\CP^3) \\cong H_n(S^2 \\times S^4)$ for every $n$.\n\\end{itemize}\nThis is unfortunate, because if possible we would like\nto be able to tell these spaces apart (as they are\nin fact not homotopy equivalent), but the homology groups \ncannot tell the difference between them.\n\nIn this chapter, we'll define a \\emph{cohomology group} $H^n(X)$ and $H^n(Y)$.\nIn fact, the $H^n$'s are completely determined by the $H_n$'s\nby the so-called \\emph{universal coefficient theorem}.\nHowever, it turns out that one can take all the cohomology groups and put\nthem together to form a \\emph{cohomology ring} $H^\\bullet$.\nWe will then see that $H^\\bullet(X) \\not\\cong H^\\bullet(Y)$ as rings.\n\n\\section{Cochain complexes}\n\\begin{definition}\nA \\vocab{cochain complex} $A^\\bullet$ is algebraically the same as a chain complex, except that the indices increase.\nSo it is a sequence of abelian groups\n\\[ \\dots \\taking{\\delta} A^{n-1} \\taking\\delta A^n \\taking\\delta A^{n+1} \\taking\\delta \\dots. \\]\nsuch that $\\delta^2 = 0$.\nNotation-wise, we're now using subscripts, and use $\\delta$ rather $\\partial$.\nWe define the \\vocab{cohomology groups} by\n\\[ H^n(A^\\bullet) = \\ker\\left( A^n \\taking\\delta A^{n+1} \\right)\n\t/ \\img\\left( A^{n-1} \\taking\\delta A^n \\right). \\]\n\\end{definition}\n\n\\begin{example}[de Rham cohomology]\n\tWe have already met one example of a cochain complex:\n\tlet $M$ be a smooth manifold and $\\Omega^k(M)$ be the\n\tadditive group of $k$-forms on $M$.\n\tThen we have a cochain complex\n\t\\[ 0 \\taking d \\Omega^0(M)\n\t\t\\taking d \\Omega^1(M) \\taking d \\Omega^2(M)\n\t\t\\taking d \\dots. \\]\n\tThe resulting cohomology is called \\vocab{de Rham cohomology},\n\tdescribed later.\n\\end{example}\n\nAside from de Rham's cochain complex,\n\\textbf{the most common way to get a cochain complex\nis to \\emph{dualize} a chain complex.}\nSpecifically, pick an abelian group $G$;\nnote that $\\Hom(-, G)$ is a contravariant functor,\nand thus takes every chain complex\n\\[ \\dots \\taking\\partial A_{n+1} \\taking\\partial\n\tA_n \\taking\\partial A_{n-1} \\taking\\partial \\dots \\]\ninto a cochain complex: letting $A^n = \\Hom(A_n, G)$ we obtain\n\\[ \\dots \\taking\\delta A^{n-1} \\taking\\delta\n\tA^n \\taking\\delta A^{n+1} \\taking\\delta \\dots. \\]\nwhere $\\delta(A_n \\taking{f} G) = A_{n+1} \\taking\\partial A \\taking{f} G$.\n\nThese are the cohomology groups we study most in algebraic topology,\nso we give a special notation to them.\n\\begin{definition}\n\tGiven a chain complex $A_\\bullet$ of abelian groups and another group $G$,\n\twe let \\[ H^n(A_\\bullet; G) \\] denote the cohomology groups\n\tof the dual cochain complex $A^\\bullet$ obtained by applying $\\Hom(-,G)$.\n\tIn other words, $H^n(A_\\bullet; G) = H^n(A^\\bullet)$.\n\\end{definition}\n\n\\section{Cohomology of spaces}\n\\prototype{$C^0(X;G)$ all functions $X \\to G$ while $H^0(X)$ are those functions $X \\to G$\nconstant on path components.}\n\nThe case of interest is our usual geometric situation, with $C_\\bullet(X)$.\n\\begin{definition}\n\tFor a space $X$ and abelian group $G$,\n\twe define $C^\\bullet(X;G)$ to be the dual to the\n\tsingular chain complex $C_\\bullet(X)$,\n\tcalled the \\vocab{singular cochain complex} of $X$;\n\tits elements are called \\vocab{cochains}.\n\n\tThen we define the \\vocab{cohomology groups}\n\tof the space $X$ as \n\t\\[ H^n(X; G) \\defeq H^n(C_\\bullet(X); G) = H_n(C^\\bullet(X;G)). \\]\n\\end{definition}\n\\begin{remark}\n\tNote that if $G$ is also a ring (like $\\ZZ$ or $\\RR$),\n\tthen $H^n(X; G)$ is not only an abelian group but actually a $G$-module.\n\\end{remark}\n\n\\begin{example}\n\t[$C^0(X; G)$, $C^1(X; G)$, and $H^0(X;G)$]\n\tLet $X$ be a topological space and consider $C^\\bullet(X)$.\n\t\\begin{itemize}\n\t\t\\ii $C_0(X)$ is the free abelian group on $X$,\n\t\tand $C^0(X) = \\Hom(C_0(X), G)$.\n\t\tSo a $0$-cochain is a function that\n\t\ttakes every point of $X$ to an element of $G$.\n\t\t\\ii $C_1(X)$ is the free abelian group on $1$-simplices in $X$.\n\t\tSo $C^1(X)$ needs to take every $1$-simplex to an element of $G$.\n\t\\end{itemize}\n\tLet's now try to understand $\\delta : C^0(X) \\to C^1(X)$.\n\tGiven a $0$-cochain $\\phi \\in C^0(X)$,\n\ti.e.\\ a homomorphism $\\phi : C^0(X) \\to G$,\n\twhat is $\\delta\\phi : C^1(X) \\to G$?\n\tAnswer: \n\t\\[ \\delta\\phi : [v_0, v_1] \\mapsto \\phi([v_0]) - \\phi([v_1]). \\]\n\tHence, elements of \n\t$\\ker(C^0 \\taking\\delta C^1) \\cong H^0(X;G)$\n\tare those cochains\n\tthat are \\emph{constant on path-connected components}.\n\\end{example}\nIn particular, much like $H_0(X)$, we have \\[ H^0(X) \\cong G^{\\oplus r} \\]\nif $X$ has $r$ path-connected components (where $r$ is finite\\footnote{%\n\tSomething funny happens if $X$ has \\emph{infinitely} many path-connected components:\n\tsay $X = \\coprod_\\alpha X_\\alpha$ over an infinite indexing set.\n\tIn this case we have\n\t$H_0(X) = \\bigoplus_\\alpha G$ while $H^0(X) = \\prod_\\alpha G$.\n\tFor homology we get a \\emph{direct sum} while\n\tfor cohomology we get a \\emph{direct product}.\n\n\tThese are actually different for infinite indexing sets.\n\tFor general modules $\\bigoplus_\\alpha M_\\alpha$ is \\emph{defined} to only allow\n\tto have \\emph{finitely many} zero terms.\n\t(This was never mentioned earlier in the Napkin,\n\tsince I only ever defined $M \\oplus N$ and extended it to finite direct sums.)\n\tNo such restriction holds for $\\prod_\\alpha G_\\alpha$ a product of groups.\n\tThis corresponds to the fact that $C_0(X)$ is formal linear sums of $0$-chains\n\t(which, like all formal sums, are finite)\n\tfrom the path-connected components of $G$.\n\tBut a cochain of $C^0(X)$ is a \\emph{function}\n\tfrom each path-connected component of $X$ to $G$,\n\twhere there is no restriction.\n}).\n\nTo the best of my knowledge, the higher cohomology groups $H^n(X; G)$\n(or even the cochain groups $C^n(X; G) = \\Hom(C_n(X), G)$) are harder to describe concretely.\n\n\\begin{abuse}\n\tIn this chapter the only cochain complexes\n\twe will consider are dual complexes as above.\n\tSo, any time we write a chain complex $A^\\bullet$ it is implicitly given\n\tby applying $\\Hom(-,G)$ to $A_\\bullet$.\n\\end{abuse}\n\n\\section{Cohomology of spaces is functorial}\nWe now check that the cohomology groups still exhibit the same nice functorial behavior.\nFirst, let's categorize the previous results we had:\n\n\\begin{ques}\n\tDefine $\\catname{CoCmplx}$\n\tthe category of cochain complexes.\n\\end{ques}\n\n\\begin{exercise}\n\tInterpret $\\Hom(-,G)$ as a contravariant functor\n\tfrom \\[ \\Hom(-,G) : \\catname{Cmplx}\\op \\to \\catname{CoCmplx}. \\]\n\tThis means in particular that given a chain map $f : A_\\bullet \\to B_\\bullet$,\n\twe naturally obtain a dual map $f^\\vee : B^\\bullet \\to A^\\bullet$.\n\\end{exercise}\n\n\\begin{ques}\n\tInterpret $H^n : \\catname{CoCmplx} \\to \\catname{Grp}$ as a functor.\n\tCompose these to get a contravariant functor\n\t$H^n(-;G) : \\catname{Cmplx}\\op \\to \\catname{Grp}$.\n\\end{ques}\n\nThen in exact analog to our result that $H_n : \\catname{hTop} \\to \\catname{Grp}$ we have:\n\\begin{theorem}[$H^n (-;G): \\catname{hTop}\\op \\to \\catname{Grp}$]\n\tFor every $n$, $H^n(-;G)$ is a contravariant functor\n\tfrom $\\catname{hTop}\\op$ to $\\catname{Grp}$.\n\\end{theorem}\n\\begin{proof}\n\tThe idea is to leverage the work we already did in constructing\n\tthe prism operator earlier.\n\tFirst, we construct the entire sequence of functors\n\tfrom $\\catname{Top}\\op \\to \\catname{Grp}$:\n\t\\begin{diagram}\n\t\t\\catname{Top}\\op & \\rTo^{C_\\bullet} & \\catname{Cmplx}\\op & \\rTo^{\\Hom(-;G)}\n\t\t& \\catname{CoCmplx} & \\rTo^{H^n} & \\catname{Grp} \\\\\n\t\tX && C_\\bullet(X) && C^\\bullet(X;G) && H^n(X;G) \\\\\n\t\t\\dTo^f &\\rMapsto& \\dTo^{f_\\sharp} &\\rMapsto&\n\t\t\\uTo^{f^\\sharp} &\\rMapsto& \\uTo^{f^\\ast} \\\\\n\t\tY && C_\\bullet(Y) && C^\\bullet(Y;G) && H^n(Y;G).\n\t\\end{diagram}\n\tHere $f^\\sharp = (f_\\sharp)^\\vee$, and $f^\\ast$\n\tis the resulting induced map on homology groups of the cochain complex.\n\n\tSo as before all we have to show is that $f \\simeq g$,\n\tthen $f^\\ast = g^\\ast$.\n\tRecall now that there is a prism operator such that\n\t$f_\\sharp - g_\\sharp = P \\partial + \\partial P$.\n\tIf we apply the entire functor $\\Hom(-;G)$ we get that\n\t$f^\\sharp - g^\\sharp = \\delta P^\\vee + P^\\vee \\delta$\n\twhere $P^\\vee : C^{n+1}(Y;G) \\to C^n(X;G)$.\n\tSo $f^\\sharp$ and $g^\\sharp$ are chain homotopic thus $f^\\ast = g^\\ast$.\n\\end{proof}\n\n\n\\section{Universal coefficient theorem}\nWe now wish to show that the cohomology groups are determined up to isomorphism\nby the homology groups: given $H_n(A_\\bullet)$, we can extract $H^n(A_\\bullet; G)$.\nThis is achieved by the \\emph{universal coefficient theorem}.\n\\begin{theorem}\n\t[Universal coefficient theorem]\n\tLet $A_\\bullet$ be a chain complex of \\emph{free} abelian groups,\n\tand let $G$ be another abelian group.\n\tThen there is a natural short exact sequence\n\t\\[\n\t\t0 \\to \\Ext(H_{n-1}(A_\\bullet), G) \\to H^n(A_\\bullet; G)\n\t\t\\taking{h} \\Hom(H_n(A_\\bullet), G) \\to 0. \\]\n\tIn addition, this exact sequence is \\emph{split}\n\tso in particular\n\t\\[ H^n(C_\\bullet; G) \\cong \\Ext(H_{n-1}(A_\\bullet, G))\n\t\t\\oplus \\Hom(H_n(A_\\bullet), G). \\]\n\\end{theorem}\nFortunately, in our case of interest, $A_\\bullet$ is $C_\\bullet(X)$\nwhich is by definition free.\n\nThere are two things we need to explain, what the map $h$ is and the map $\\Ext$ is.\n\nIt's not too hard to guess how \\[ h : H^n(A_\\bullet; G) \\to \\Hom(H_n(A_\\bullet), G) \\] is defined.\nAn element of $H^n(A_\\bullet;G)$ is represented by a function which sends a cycle\nin $A_n$ to an element of $G$.\nThe content of the theorem is to show that $h$ is surjective with kernel $\\Ext(H_{n-1}(A_\\bullet), G)$.\n\nWhat about $\\Ext$?\nIt turns out that $\\Ext(-,G)$ is the so-called \\vocab{Ext functor}, defined as follows.\nLet $H$ be an abelian group, and consider a \\vocab{free resolution} of $H$,\nby which we mean an exact sequence\n\\[ \\dots \\taking{f_2} F_1 \\taking{f_1} F_0 \\taking{f_0} H \\to 0 \\]\nwith each $F_i$ free.\nThen we can apply $\\Hom(-,G)$ to get a cochain complex\n\\[ \\dots \\xleftarrow{f_2^\\vee} \\Hom(F_1, G) \\xleftarrow{f_1^\\vee}\n\t\\Hom(F_0, G) \\xleftarrow{f_0^\\vee} \\Hom(H,G) \\leftarrow 0. \\]\nbut \\emph{this cochain complex need not be exact}\n(in categorical terms, $\\Hom(-,G)$ does not preserve exactness).\nWe define \\[ \\Ext(H,G) \\defeq \\ker(f_2^\\vee) / \\img(f_1^\\vee) \\]\nand it's a theorem that this doesn't depend on the choice of the free resolution.\nThere's a lot of homological algebra that goes into this,\nwhich I won't take the time to discuss;\nbut the upshot of the little bit that I did include is that the $\\Ext$\nfunctor is very easy to compute in practice, since\nyou can pick any free resolution you want and compute the above.\n\n%By ``natural'', we mean that if $f : A_\\bullet \\to B_\\bullet$ is a chain map,\n%then we obtain a commutative diagram\n%\\begin{diagram}\n%\t0 & \\rTo & \\Ext(H_{n-1}(A_\\bullet), G) & \\rTo\n%\t\t& H^n(A_\\bullet;G) & \\rTo & \\Hom(H_n(A_\\bullet), G) & \\rTo & 0 \\\\\n%\t& & \\uTo^{ \\Ext(f_\\ast, G) } & & \\uTo^{f^\\ast} & & \\uTo^{\\Hom(f_\\ast, G)} & & \\\\\n%\t0 & \\rTo & \\Ext(H_{n-1}(B_\\bullet), G) & \\rTo\n%\t\t& H^n(A_\\bullet;G) & \\rTo & \\Hom(H_n(B_\\bullet), G) & \\rTo & 0 \\\\\n%\\end{diagram}\n%where $f_\\ast$ is the induced arrow $H_n(A_\\bullet) \\to H_n(B_\\bullet)$.\n\n\\begin{lemma}\n\t[Computing the $\\Ext$ functor]\n\tFor any abelian groups $G$, $H$, $H'$ we have\n\t\\begin{enumerate}[(a)]\n\t\t\\ii $\\Ext(H \\oplus H', G) = \\Ext(H, G) \\oplus \\Ext(H', G)$.\n\t\t\\ii $\\Ext(H,G) = 0$ for $H$ free, and\n\t\t\\ii $\\Ext(\\Zc n, G) = G / nG$.\n\t\\end{enumerate}\n\\end{lemma}\n\\begin{proof}\n\tFor (a), note that if $\\dots \\to F_1 \\to F_0 \\to H \\to 0$\n\tand $\\dots \\to F_1' \\to F_0' \\to F_0' \\to H' \\to 0$ are free resolutions,\n\tthen so is $F_1 \\oplus F_1' \\to F_0 \\oplus F_0' \\to H \\oplus H' \\to 0$.\n\n\tFor (b), note that $0 \\to H \\to H \\to 0$ is a free resolution.\n\t\n\tPart (c) follows by taking the free resolution\n\t\\[ 0 \\to \\ZZ \\taking{\\times n} \\ZZ \\to \\Zc n \\to 0 \\]\n\tand applying $\\Hom(-,G)$ to it.\n\t\\begin{ques}\n\t\tFinish the proof of (c) from here. \\qedhere\n\t\\end{ques}\n\\end{proof}\n\n\\begin{ques}\n\tSome $\\Ext$ practice: compute\n\t$\\Ext(\\ZZ^{\\oplus 2015}, G)$ and $\\Ext(\\Zc{30}, \\Zc 4)$.\n\\end{ques}\n\n\\section{Example computation of cohomology groups}\n\\prototype{Possibly $H^n(S^m)$.}\n\nThe universal coefficient theorem gives us a direct way to compute\nany cohomology groups, provided we know the homology ones.\n\n\\begin{example}\n\t[Cohomolgy groups of $S^m$]\n\tIt is straightforward to compute $H^n(S^m)$ now:\n\tall the $\\Ext$ terms vanish since $H_n(S^m)$ is always free,\n\tand hence we obtain that \n\t\\[ H^n(S^m) \\cong \\Hom(H_n(S^m), G) \\cong\n\t\t\\begin{cases}\n\t\t\tG & n=m, n=0 \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n%\tBy UCT for reduced groups, we also have\n%\t\\[ \\wt H^n(S^m) \\cong \\Hom(\\wt H_n(S^m), G) \\cong\n%\t\t\\begin{cases}\n%\t\t\tG & n=m \\\\\n%\t\t\t0 & \\text{otherwise}.\n%\t\t\\end{cases}\n%\t\\]\n%\tsince $\\Hom(\\ZZ, G)$.\n\\end{example}\n\n\\begin{example}\n\t[Cohomolgy groups of torus]\n\tThis example has no nonzero $\\Ext$ terms either,\n\tsince this time $H^n(S^1 \\times S^1)$ is always free.\n\tSo we obtain\n\t\\[ H^n(S^1 \\times S^1) \\cong \\Hom(H_n(S^1 \\times S^1), G). \\]\n\tSince $H_n(S^1 \\times S^1)$ is $\\ZZ$, $\\ZZ^{\\oplus 2}$, $\\ZZ$\n\tin dimensions $n=1,2,1$ we derive that\n\t\\[\n\t\tH^n(S^1 \\times S^1)\n\t\t\\cong\n\t\t\\begin{cases}\n\t\t\tG & n = 0,2 \\\\\n\t\t\tG^{\\oplus 2} & n = 1.\n\t\t\\end{cases}\n\t\\]\n\\end{example}\n\nFrom these examples one might notice that:\n\\begin{lemma}\n\t[$0$th homology groups are just duals]\n\tFor $n = 0$ and $n = 1$, we have\n\t\\[ H^n(X;G) \\cong \\Hom(H_n(X), G). \\]\n\\end{lemma}\n\\begin{proof}\n\tIt's already been shown for $n=0$.\n\tFor $n=1$, notice that $H_0(X)$ is free,\n\tso the $\\Ext$ term vanishes.\n\\end{proof}\n\n\\begin{example}\n\t[Cohomolgy groups of Klein bottle]\n\tThis example will actually have $\\Ext$ term.\n\tRecall that if $K$ is a Klein Bottle then its homology groups are\n\t$\\ZZ$ in dimension $n=0$ and $\\ZZ \\oplus \\Zc 2$ in $n=1$, and $0$ elsewhere.\n\n\tFor $n=0$, we again just have $H^0(K;G) \\cong \\Hom(\\ZZ, G) \\cong G$.\n\tFor $n=1$, the $\\Ext$ term is $\\Ext(H_0(K), G) \\cong \\Ext(\\ZZ, G) = 0$\n\tso \\[ H^1(K;G) \\cong \\Hom(\\ZZ \\oplus \\Zc2, G) \\cong G \\oplus \\Hom(\\Zc2, G). \\]\n\tWe have that $\\Hom(\\Zc2,G)$ is the subgroup\n\tof elements of order $2$ in $G$ (and $0 \\in G$).\n\n\tBut for $n=2$, we have our first interesting $\\Ext$ group:\n\tthe exact sequence is\n\t\\[ 0 \\to \\Ext(\\ZZ \\oplus \\Zc 2, G) \\to H^2(X;G) \\to \\underbrace{H_2(X)}_{=0} \\to 0. \\]\n\tThus, we have\n\t\\[ H^2(X;G) \\cong \\left( \\Ext(\\ZZ,G) \\oplus \\Ext(\\Zc2,G) \\right) \\oplus 0\n\t\t\\cong G/2G. \\]\n\tAll the higher groups vanish.\n\tIn summary:\n\t\\[\n\t\tH^n(X;G) \\cong\n\t\t\\begin{cases}\n\t\t\tG & n = 0 \\\\\n\t\t\tG \\oplus \\Hom(\\Zc2, G) & n = 1 \\\\\n\t\t\tG/2G & n = 2 \\\\\n\t\t\t0 & n \\ge 3. \n\t\t\\end{cases}\n\t\\]\n\\end{example}\n\n\n\\section{Relative cohomology groups}\nOne can also define relative cohomology groups in the obvious way:\ndualize the chain complex\n\\[ \\dots \\taking\\partial C_1(X,A) \\taking\\partial C_0(X,A) \\to 0 \\]\nto obtain a cochain complex\n\\[\n\t\\dots \\xleftarrow\\delta C^1(X,A;G) \\xleftarrow\\delta C^0(X,A;G)\n\t\\leftarrow 0.\n\\]\nWe can take the cohomology groups ofthis.\n\\begin{definition}\n\tThe groups thus obtained are the \\vocab{relative cohomology groups}\n\tare denoted $H^n(X,A;G)$.\n\\end{definition}\n\nIn addition, we can define reduced cohomology groups as well.\nOne way to do it is to take the augmented singular chain complex\n\\[ \\dots \\taking\\partial C_1(X) \\taking\\partial C_0(X) \\taking\\eps \\ZZ \\to 0 \\]\nand dualize it to obtain\n\\[\n\t\\dots \\xleftarrow\\delta C^1(X;G) \\xleftarrow\\delta C^0(X;G)\n\t\\xleftarrow{\\eps^\\vee} \\underbrace{\\Hom(\\ZZ, G)}_{\\cong G}\n\t\\leftarrow 0.\n\\]\nSince the $\\ZZ$ we add is also free,\nthe universal coefficient theorem still applies.\nSo this will give us reduced cohomology groups.\n\nHowever, since we already defined the relative cohomology groups,\nit is easiest to simply define:\n\\begin{definition}\n\tThe \\vocab{reduced cohomology groups} of a nonempty space $X$,\n\tdenoted $\\wt H^n(X; G)$,\n\tare defined to be $H^n(X, \\{\\ast\\} ; G)$\n\tfor some point $\\ast \\in X$.\n\\end{definition}\n\n\n\\section\\problemhead\n\\begin{sproblem}\n\t[Wedge product cohomology]\n\tFor any $G$ and $n$ we have\n\t\\[\n\t\t\\wt H^n(X \\vee Y; G)\n\t\t\\cong\n\t\t\\wt H^n(X; G) \\oplus \\wt H^n(Y; G).\n\t\\]\t\n\\end{sproblem}\n\n\\begin{dproblem}\n\tProve that for a field $F$ of characteristic zero and a space $X$\n\twith finitely generated homology groups:\n\t\\[ H^k(X, F) \\cong \\left( H_k(X) \\right)^\\vee.  \\]\n\tThus over fields cohomology is the dual of homology.\n\\end{dproblem}\n\n\\begin{problem}[$\\Zc2$-cohomology of $\\RP^n$]\n\tProve that\n\t\\[\n\t\tH^m(\\RP^n, \\Zc2)\n\t\t\\cong\n\t\t\\begin{cases}\n\t\t\t\\ZZ & \\text{$m=0$, or $m$ is odd and $m=n$} \\\\\n\t\t\t\\Zc2 & \\text{$0 < m < n$ and $m$ is odd} \\\\\n\t\t\t0 & \\text{otherwise}.\n\t\t\\end{cases}\n\t\\]\n\\end{problem}\n", "meta": {"hexsha": "e78aadd46837e72f4098cfc24205697c85cc7dec", "size": 16494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "corpus/napkin/tex/homology/cohomology.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/cohomology.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/cohomology.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.6575342466, "max_line_length": 117, "alphanum_fraction": 0.6653328483, "num_tokens": 5925, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901036, "lm_q2_score": 0.8856314828740728, "lm_q1q2_score": 0.7596664387844688}}
{"text": "\\section{Introduction}\r\n\\subsection{Motivation and Examples}\r\nWe start by asking a natural question that appears frequently in the study of topology:\r\n\\begin{problem}\\label{homeo}\r\n    How can we tell if two topological space are different (i.e. not homoeomorphic)?\r\n\\end{problem}\r\nFor example, if we let $X$ to be the donut-like surface in $\\mathbb R^3$, and $Y$ be a similar donut but with two holes instead.\r\nOur intuition tells us they are not homeomorphic because, well, $X$ has one hole and $Y$ has two -- but this is not much a proof.\\\\\r\nOur basic strategy of coping with problems like these in algebraic topology is to associate each topological space $X$ (often, in a specific class) with a group $H(X)$ and associate each continuous map $f:X\\to Y$ a homomorphism of groups $H(f):H(X)\\to H(Y)$.\r\nWe obviously want $H$ to preserve compositions of functions and identities as well.\r\n\\footnote{In short, we just want $H$ to be a functor from a subcategory of $\\mathbf{Top}$ to an abelian category, preferably $\\mathbf{Grp}$.}\r\nWith certain constructions, if $X\\cong Y$ as topological spaces, we can ensure that $H(X)\\cong H(Y)$ as groups.\r\nIn other words, $H$ exists as an algebraic invariant.\r\nAs it is much easier to show two groups are not isomorphic, we can solve some cases of Problem \\ref{homeo} where $H(X)$ can be shown not to isomorphic to $H(Y)$.\r\nThe study of algebraic topology is basically the hunt of such algebraic invariants.\\\\\r\nAnother application of this idea is to solve the Extension Problem:\r\n\\begin{problem}[The Extension Problem]\r\n    Let $X$ be a topological space and $A\\subset X$ a subspace.\r\n    If we have $f:A\\to Y$ is a continuous map, how do we know if there is a continuous map $F:X\\to Y$ with $F|_A=f$?\r\n\\end{problem}\r\nThat is, we want to know if there exists $F$ such that the diagram\r\n\\[\r\n    \\begin{tikzcd}\r\n        A \\arrow[hookrightarrow]{d} \\arrow{r}{f} & Y\\\\\r\n        X \\arrow[dashed,swap]{ur}{F}&\r\n    \\end{tikzcd}\r\n\\]\r\ncommutes.\r\nAn example of this is the following theorem:\r\n\\begin{theorem}\r\n    There is no continuous function $F:D^n\\to S^{n-1}$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            S^{n-1} \\arrow[hookrightarrow]{d} \\arrow{r}{\\operatorname{id}} & S^{n-1}\\\\\r\n            D^n \\arrow[swap]{ur}{F}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{theorem}\r\nHere, $D^n$ is the $n$-disk while $S^{n-1}$ is the $(n-1)$-sphere, which is simply the hypersurface enclosing $D^n$.\r\nHow does the idea of the algebraic invariant come in handy on this problem?\r\nObviously we do not yet have the correct tool to do it now that the course has just started, but we can take a glimpse of the idea involved.\r\n\\begin{proof}\r\n    Construct an invariant $H$ such that $H(S^{n-1})\\cong\\mathbb Z$ and $H(D^n)\\cong 0$.\r\n    Then the diagram in the statement of the theorem will implies that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\mathbb Z\\arrow{d} \\arrow{r}{\\operatorname{id}} & \\mathbb Z\\\\\r\n            0 \\arrow{ur}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commute.\r\n    But this is absurd.\r\n\\end{proof}\r\nAll these seems nice, right?\r\nBut first, we really need a clever construction of such a nontrivial algebraic invariants bearing such nice properties.\r\n\\subsection{Conventions}\r\nUnless otherwise stated, we adopt the following conventions:\\\\\r\nWhen we mention ``space'', we always mean a topological space.\r\nAnd when we say a ``map'' between two spaces, we always mean a continuous one.\r\nBy $I$, we mean the unit interval $[0,1]$.", "meta": {"hexsha": "d7b7f2766abc6886b9e27d2ff76d4a9c8b08e4ba", "size": 3480, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/intro.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": "0/intro.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": "0/intro.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": 57.0491803279, "max_line_length": 259, "alphanum_fraction": 0.6902298851, "num_tokens": 978, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.885631470799559, "lm_q2_score": 0.8577681068080749, "lm_q1q2_score": 0.7596664300373885}}
{"text": "\\chapter{Appendix}\n%\\addcontentsline{toc}{chapter}{Appendix}\n\\section{Code}\n\\begin{labwork}[PDF and DF of a $\\normal(\\mu,\\sigma^2)$ RV]\\label{Mf: NormalCdfPdf}\nHere are the functions to evaluate the PDF and DF of a $\\normal(\\mu,\\sigma^2)$ RV $X$ at a given $x$.\n{\\VrbMf[label=NormalPdf.m]{scripts/NormalPdf.m}}\n{\\VrbMf[label=NormalCdf.m]{scripts/NormalCdf.m}}\nPlots of the PDF and DF of several Normally distributed RVs depicted in \\hyperref[F:plotPdfCdfNormals]{Figure~\\ref*{F:plotPdfCdfNormals}} were generated using the following script file:\n{\\VrbMf[label=PlotPdfCdfNormal.m]{scripts/PlotPdfCdfNormal.m}}\n\\end{labwork}\n\n\\begin{labwork}[PDF and DF of an $\\exponential(\\lambda)$ RV $X$]\\label{Mf:ExponentialPdfCdf}\nHere are the functions to evaluate the PDF and DF of an $\\exponential(\\lambda)$ RV $X$ at a  given $x$ (point or a vector).\n{\\VrbMf[label=ExponentialPdf.m]{scripts/ExponentialPdf.m}}\n{\\VrbMf[label=ExponentialCdf.m]{scripts/ExponentialCdf.m}}\nPlots of the PDF and DF of several Exponentially distributed RVs at four axes scales that are depicted in \\hyperref[F:plotPdfCdfExponentials]{Figure \\ref*{F:plotPdfCdfExponentials}} were generated using the following script file:\n{\\VrbMf[label=PlotPdfCdfExponential.m]{scripts/PlotPdfCdfExponential.m}}\n\\end{labwork}\n\n%\\begin{labwork}\\label{Mf:ECDF}\n%A {\\sc Matlab} function to plot the empirical DF \\eqref{E:ECDF} of $n$ user-specified samples.  Read the following M-file for the algorithm:\n%{\\VrbMf[label=ECDF.m]{scripts/ECDF.m}}\n%Ideally, this function needs to be rewritten using primitives such as {\\sc Matlab}'s {\\tt line} commands.\n%\\end{labwork}\n\n\\begin{labwork}[Plotting the empirical DF]\\label{Mf:ECDF}\nA {\\sc Matlab} function to plot the empirical DF \\eqref{E:ECDF} of $n$ user-specified samples efficiently for massive number of samples.  Read the following M-file for the algorithm:\n{\\VrbMf[label=ECDF.m]{scripts/ECDF.m}}\nIdeally, this function needs to be rewritten using primitives such as {\\sc Matlab}'s {\\tt line} commands.\n\\end{labwork}\n\n\\begin{labwork}[q-th sample quantile]\\label{Mf:qthSampleQuantile}\nLet us implement \\hyperref[A:qthSampleQuantile]{Algorithm \\ref*{A:qthSampleQuantile}} as the following {\\sc Matlab} function:\n{\\VrbMf[label=qthSampleQuantile.m]{scripts/qthSampleQuantile.m}}\n\\end{labwork}\n\n\\begin{labwork}[Loading ]\\label{Mf:NZEQChCch20110222}\nLet us save all the steps done in \\hyperref[LW:NZEQChCch20110222]{Labwork~\\ref*{LW:NZEQChCch20110222}} into the following script M-file:\n{\\VrbMf[label=NZEQChCch20110222.m]{scripts/NZEQChCch20110222.m}}\n\\end{labwork}\n\n\\remove{\n\\begin{labwork}[Importance Resampler Demo]\\label{Mf:ImpResamplerCauchyViaNormal}\nVisualisation of the Importance Resampler of \\hyperref[A:ImpReSampler]{Algorithm~\\ref*{A:ImpReSampler}} by producing approximate samples from $\\cauchy$ using samples from $\\normal(0,1)$.\n%\\hyperref[F:LevyDensityPlot]{Figure \\ref*{F:LevyDensityPlot}} was made with the following script file.\n{\\VrbMf[label=ImpResamplerCauchyViaNormal.m]{scripts/ImpResamplerCauchyViaNormal.m}}\n\\end{labwork}\n\n\\begin{labwork}[Levy density plot]\\label{Mf:LevyDensityPlot}\n\\hyperref[F:LevyDensityPlot]{Figure \\ref*{F:LevyDensityPlot}} was made with the following script file.\n{\\VrbMf[label=LevyDensityPlot.m]{scripts/LevyDensityPlot.m}}\n\\end{labwork}\n\n\\begin{labwork}[Negative of the Levy density]\\label{Mf:NegLevyDensity}\nThe negative of the Levy density \\eqref{E:LevyDensity} is encoded in the following M-file as a function to be passed to {\\sc Matlab}'s {\\tt fminsearch}.\n{\\VrbMf[label=NegLevyDensity.m]{scripts/NegLevyDensity.m}}\n\\end{labwork}\n\n\\begin{labwork}[Log-likelihood of $\\lognormal$]\\label{Mf:LogNormalLogLklPlot}\n\\hyperref[F:LogNormalLogLklPlot]{Figure \\ref*{F:LogNormalLogLklPlot}} was made with the following script file.\n{\\VrbMf[label=LogNormalLogLklPlot.m]{scripts/LogNormalLogLklPlot.m}}\n\\end{labwork}\n}\n\n\\begin{labwork}[Consistency of MLE in Bernoulli experiment]\\label{Mf:BernoulliMLEConsistency}\n\\hyperref[F:BernoulliMLEConsistency]{Figure~\\ref*{F:BernoulliMLEConsistency}} was made with the following script file.\n{\\VrbMf[label=BernoulliMLEConsistency.m]{scripts/BernoulliMLEConsistency.m}}\n\\end{labwork}\n\n\\begin{labwork}[Gilvenko-Cantelli Lemma for $\\uniform(0,1)$]\\label{Mf:GilvenkoCantelliUnif01n10n100n100ECDFs}\nThe following script was used to generate the \\hyperref[F:GilvenkoCantelliUnif01n10n100n100ECDFs]{Figure \\ref*{F:GilvenkoCantelliUnif01n10n100n100ECDFs}}.\n{\\VrbMf[label=GilvenkoCantelliUnif01.m]{scripts/GilvenkoCantelliUnif01.m}}\n\\end{labwork}\n\n\\section{Data}\\label{S:Data}\n%\\addcontentsline{toc}{chapter}{Data Appendix}\n\nHere we describe some of the data sets we analyze.\n\\begin{data}[Our Maths \\& Stats Dept. Web Logs]\\label{DA:WebLogs}\nWe assume access to a {\\tt Unix} terminal ({\\tt Linux, Mas OS X, Sun Solaris}, etc).  We show how to get your hands dirty with web logs that track among others, every {\\tt IP} address and its time of login to our department web server over the world-wide-web.  The raw text files of web logs may be manipulated but they are typically huge files and need some {\\tt Unix} command-line utilities.\n\\begin{VrbM}\nrsa64@mathopt03:~> cd October010203WebLogs/\nrsa64@mathopt03:~/October010203WebLogs> ls -al\n-rw-r--r--+  1 rsa64 math 7527169 2007-10-04 09:38 access-07_log.2\n-rw-r--r--+  1 rsa64 math 7727745 2007-10-04 09:38 access-07_log.3\n\\end{VrbM}\nThe files are quite large over 7.5 MB each.  So we need to compress it.  We use the {\\tt gzip} and {\\tt gunzip} utility in any {\\tt Unix} environment to compress and decompress these large text files of web logs.  After compression the file sizes are more reasonable.\n\\begin{VrbM}\nrsa64@mathopt03:~/October010203WebLogs> gzip access-07_log.3 \nrsa64@mathopt03:~/October010203WebLogs> gzip access-07_log.2 \nrsa64@mathopt03:~/October010203WebLogs> zcat access-07_log.2.gz | grep ' 200 ' \n| awk '{ print \\$4}'| sed -e 's/\\[\\([0-9]\\{2\\}\\)\\/\\([a-Z]\\{3\\}\\)\\/\\([0-9]\\{4\\}\\)\n:\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\):\\([0-9]\\{2\\}\\)/\\3 10 \\1 \\4 \\5 \\6/'\n2007 10 02 03 57 48\n2007 10 02 03 58 31\n.\n.\n.\n2007 10 03 03 56 21\n2007 10 03 03 56 52\n\\end{VrbM}\nFinally, there are $56485$ and $53966$ logins for the two 24-hour cycles, starting {\\tt 01/Oct} and {\\tt 01/Oct}, respectively.  We can easily get these counts by further piping the previous output into the line counting utility {\\tt wc} with the {-l} option.  All the {\\tt Unix} command-line tools mentioned earlier can be learned by typing {\\tt man } followed by the tool-name, for eg.~type {\\tt man sed} to learn about the usage of {\\tt sed} ata  {\\tt Unix} command shell.  We further pipe the output of login times for the two 24-hour cycles starting {\\tt 01/Oct} and {\\tt 02/Oct} in format {\\tt YYYY MM DD HH MM SS} to \n{\\tt | sed -e 's/2007 10 //' > WebLogTimes20071001035730.dat} and \n{\\tt ... > WebLogTimes20071002035730.dat}, respectively to strip away the redundant information on {\\tt YYYY MM }, namely {\\tt 2007 10 }, and only save the relevant information of {\\tt DD HH MM SS} in files named \n{\\tt WebLogTimes20071001035730.dat} and {\\tt WebLogTimes20071002035730.dat}, respectively.  These two files have the data of interest to us.  Note that the size of these two uncompressed final data files in plain text are smaller than the compressed raw web log files we started out from. \n\\begin{VrbM}\nrsa64@mathopt03:~/October010203WebLogs> ls -al\n-rw-r--r--+  1 rsa64 math 677820 2007-10-05 15:36 WebLogTimes20071001035730.dat\n-rw-r--r--+  1 rsa64 math 647592 2007-10-05 15:36 WebLogTimes20071002035730.dat\n-rw-r--r--+  1 rsa64 math 657913 2007-10-04 09:38 access-07_log.2.gz\n-rw-r--r--+  1 rsa64 math 700320 2007-10-04 09:38 access-07_log.3.gz\n\\end{VrbM}\nNow that we have been familiarized with the data of login times to our web-server over 2 24-hour cycles, let us do some statistics.  The log files and basic scripts are courtesy of the Department's computer systems administrators Paul Brouwers and Steve Gourdie.  This data processing activity was shared in such detail to show you that statistics is only meaningful when the data and the process that generated it are clear to the experimenter.  Let us process the data and visualize the empirical distribution functions using the following script:\n{\\VrbMf[label=WebLogDataProc.m]{scripts/WebLogDataProc.m}}\n\\end{data}\n\n", "meta": {"hexsha": "722ca14b58fd985622441faaa183052a24159fce", "size": 8264, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/CodeAppendix.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/CodeAppendix.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/CodeAppendix.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": 70.6324786325, "max_line_length": 624, "alphanum_fraction": 0.7623426912, "num_tokens": 2639, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.885631470799559, "lm_q1q2_score": 0.7596664187670206}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\chapter{Optimization}\n\\label{chap:opt}\n% TODO\n% TODO many types of optimizers, two main classes of gradient and non-gradient methods.\n% TODO A greedy optimizer finds the local optimum at each iteration, which may or may not converge to a global optimum.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Maximum Likelihood Estimation (MLE)}\n\\label{opt:MLE}\n\nMaximum likelihood estimation (MLE) is a method\nof choosing the optimal parameters of a probability distribution\nto match some set of observed data.\nAs the name suggests, MLE works by maximizing the likelihood of observing the given data.\nNote that the terms likelihood and probability are closely related, but different, in this context.\nHere probability refers to the probability of observing $x$ given parameters $\\vb*{\\beta}$, $P\\left(x \\mid \\vb*{\\beta}\\right)$,\nwhile likelihood refers to the likelihood of the distribution having parameters $\\vb*{\\beta}$ given an observation $x$, $L\\left(\\vb*{\\beta} \\mid x\\right)$.\n$L$ and $P$ are both equal to relevant probability distribution,\nsuch as \\cref{eq:stats:gaus:P} for the Gaussian distribution,\nbut which variables are independent and dependent changes.\n\nAs we wish to maximize the likelihood with respect to $\\vb*{\\beta}$,\nwe will be taking partial derivatives and finding where they equal zero, $\\partial_{\\vb*{\\beta}} L = 0$.\nIn practice, likelihood functions are complicated\\footnote{The value of $L$\nis often close to $0$, making lack of precision an issue when doing computations.\n$\\log\\left(L\\right)$ is larger and also helps address this problem.} and\nit is easier to maximize the log-likelihood $\\log\\left(L\\right)$,\nwhich has the same maximum as the original likelihood $L$,\nbut removes exponents and turns multiplication in to addition.\nGenerally there are $m$ points $\\vb{x}_{i}$, each with $n$ dimensions, in a given dataset,\nthus we are solving \\cref{eq:MLE} for $\\vb*{\\beta} = \\hat{\\vb*{\\beta}}_{\\text{MLE}}$:\n\n\\begin{subequations}\\label{eq:MLE}\n\\begin{align}\n0 &= \\partial_{\\vb*{\\beta}} \\, L\\left(\\vb*{\\beta} \\mid \\vb{x}\\right) \\label{eq:MLE:L} \\\\\n\\implies 0 &= \\partial_{\\vb*{\\beta}} \\log\\left(L\\left(\\vb*{\\beta} \\mid \\mathbf{X}\\right)\\right) = \\partial_{\\vb*{\\beta}} \\, \\log\\left(\\prod_{i=1}^{m} \\, P\\left(\\vb{x}_{i} \\mid \\vb*{\\beta}\\right)\\right) \\label{eq:MLE:log_L} \\\\\n&= \\sum_{i=1}^{m} \\, \\partial_{\\vb*{\\beta}} \\log\\left(P\\left(\\vb{x}_{i} \\mid \\vb*{\\beta}\\right)\\right) \\label{eq:MLE:log_L_sum}\n\\end{align}\n\\end{subequations}\n\nIn practice, it is unlikely that a closed form solution for $\\hat{\\vb*{\\beta}}_{\\text{MLE}}$ can be found\nand numerical optimizers, such as gradient descent, are used instead.\nUnder certain conditions it can be shown that as $n \\to \\infty$ the MLE converges to $\\hat{\\vb*{\\beta}}$,\n\\ie in the limit $n \\to \\infty$ no consistent estimator\nhas a lower MSE\\footnote{More formally, the MLE achieves the Cram\\'er--Rao lower bound.}.\nLastly, while the MLE is usually a biased estimator, see \\cref{stats:bias},\nthe bias is also reduced as $n \\to \\infty$.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Exponential Distribution Example}\n\\label{opt:MLE:exp_ex}\n\nWe can use MLE to find the optimal $\\hat{\\lambda}_{\\text{MLE}}$ of\nthe exponential distribution \\cref{eq:stats:exp:P}\ngiven a dataset of $m$ points, $x_{i}$, in 1 dimension:\n\n\\begin{subequations}\\label{eq:MLE:exp_ex}\n\\begin{align}\n0 &= \\sum_{i=1}^{m} \\partial_{\\lambda} \\log\\left(P\\left(x_{i} \\mid \\lambda\\right)\\right) = \\sum_{i=1}^{m} \\partial_{\\lambda} \\log\\left(\\lambda e^{-\\lambda x_{i}}\\right), \\label{eq:MLE:exp_ex:log_L_sum} \\\\\n&= \\sum_{i=1}^{m}\\partial_{\\lambda} \\left( \\log\\left(\\lambda\\right) -\\lambda x_{i}\\right) = \\sum_{i=1}^{m} \\frac{1}{\\lambda} - x_{i} = \\frac{m}{\\lambda} - \\sum_{i=1}^{m} x_{i}, \\label{eq:MLE:exp_ex:solve} \\\\\n\\implies \\hat{\\lambda}_{\\text{MLE}} &= \\frac{m}{\\sum_{i=1}^{m} x_{i}} = \\frac{1}{\\expval{x}}. \\label{eq:MLE:exp_ex:lambda}\n\\end{align}\n\\end{subequations}\n\nFor another example of MLE see logistic regression \\cref{eq:logistic:L_Pr}.\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Maximum A Posteriori (MAP)}\n\\label{opt:MAP}\n% TODO In maximum \\aposteriori (MAP) estimation\n% TODO MLE is a special case of MAP with a uniform prior\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Gradient Descent}\n\\label{opt:grad_descent}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Stochastic Gradient Descent (SGD)}\n\\label{opt:grad_descent:stochastic}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Lagrange Multipliers}\n\\label{opt:lagrange_mult}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Newton's Method}\n\\label{opt:newton}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Exploration-Exploitation Tradeoff}\n\\label{opt:EE_tradeoff}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bayesian Bandits}\n\\label{opt:BB}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Evolutionary \\& Genetic Algorithms}\n\\label{opt:evo}\n% TODO\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Bayesian Optimization}\n\\label{opt:BO}\n\nFrequently we are fortunate enough to have a fairly explicit form of\nthe objective function $S\\left(\\vb*{\\beta}\\right)$ to be optimized in order to solve a problem.\nHowever, when $S\\left(\\vb*{\\beta}\\right)$ is not well-known,\nis expensive to compute\\footnote{The performance of a machine learning model as a function of its hyperparameters is a classic example of this.\nIn that case, evaluating $S$ amounts to training the model with a particular set of hyperparameters $\\vb*{\\beta}$,\nthen determining it's performance on a metric such as ROC AUC.}, or is non-differentiable,\nthe usual gradient based approaches, such as SGD and Newton's method, break down.\nIn these cases ``black box''\\footnote{Black box as in\nwe do not have a closed-form expression for $S$, or know $\\grad S$.} methods\\footnote{Other examples of black box optimizers include\nTree-Structured Parzen Estimators (TPE),\ngenetic algorithms,\nand some additional tree based methods described in \\cite{Hutter2011,Hutter2014}.\nA TPE is a close relative of Bayesian optimization, making use of the opposite side of Bayes' theorem by\nestimating $P\\left(\\vb*{\\beta} \\mid S\\right)$ and $P\\left(S\\right)$ rather than $P\\left(S \\mid \\vb*{\\beta}\\right)$.\nTPEs can accommodate categorical $\\beta_{i}$ in a hierarchical manner,\nhowever they can not model interactions between the $\\beta_{i}$ \\cite{bissuel_2019,NIPS2011_4443}.},\nsuch as Bayesian optimization, may be used instead.\n\nIn Bayesian optimization\\footnote{Generalized\nformally as Sequential Model-Based Optimization (SMBO) \\cite{NIPS2011_4443}.} \\cite{Brochu2010,1301.1942,Borisyak,NIPS2011_4443},\n$S$ is approximated by a well-known surrogate function\\footnote{Also known as a response surface.}.\nThe surrogate typically is a Gaussian process (GP),\nbut can be any well-behaved regressor such as\na Random Forest or Boosted Decision Tree (BDT).\nGPs \\cref{eq:GP} are\nextensions of Gaussian distributions which return a Gaussian at any point along their domain.\nThey are parameterized by a mean function\\footnote{For convenience,\nthe prior $m\\left(\\vb{x}\\right)$ is usually assumed to be zero, $m\\left(\\vb{x}\\right)=0$.}, $m\\left(\\vb{x}\\right)$,\nand covariance function, $k\\left(\\vb{x}_{i}, \\vb{x}_{j}\\right)$,\n\\ie kernel\\footnote{The kernel of the GP is a hyperparameter to be chosen in advance.\nStandard kernel choices include\nthe radial basis function kernel $k\\left(\\vb{x}_{i}, \\vb{x}_{j}\\right) = \\exp\\left(-\\frac{1}{2\\sigma^{2}}\\norm{\\vb{x}_{i}-\\vb{x}{j}}^{2}\\right)$,\nMat\\'{e}rn kernel,\nand white noise kernel $k\\left(\\vb{x}_{i}, \\vb{x}_{j}\\right) \\propto \\delta_{ij}$.},\ninstead of a constant mean $\\mu$ and variance $\\sigma^{2}$.\nAn illustration of a GP is provided in \\cref{fig:GP_ex}.\n\n\\begin{equation}\\label{eq:GP}\nf\\left(\\vb{x}\\right) \\sim \\mathcal{GP}\\left(m\\left(\\vb{x}\\right), k\\left(\\vb{x}_{i}, \\vb{x}_{j}\\right)\\right).\n\\end{equation}\n\n\\begin{figure}[H] % TODo might want to eventually remove\n\\centering\n\\includegraphics[width=0.85\\textwidth]{figures/ml/gp}\n\\caption{\nIllustration of a Gaussian process (GP) in 1D \\cite{Brochu2010}.\nNote that at any point $\\vb{x}_{1}$, $\\vb{x}_{2}$, $\\vb{x}_{3}$ the GP\nreturns a Gaussian distribution characterizing the estimated mean and uncertainty on the\nunknown true function, \\ie the objective function $S\\left(\\vb*{\\beta}\\right)$ in the case of Bayesian optimization.\n}\n\\label{fig:GP_ex}\n\\end{figure}\n\nThe surrogate function is initially fit to\na random sample of $\\vb*{\\beta}$, $S\\left(\\vb*{\\beta}\\right)$ points.\nFrom this prior, Bayesian optimization\noperates by iteratively sampling $S\\left(\\vb*{\\beta}\\right)$ and updating\nthe posterior surrogate function as each new piece of information is gained.\nAn acquisition function, $u\\left(\\cdot\\right)$, directs the sampling,\nestimating where $S\\left(\\vb*{\\beta}\\right)$ may be large\ndue to a high predicted value, large uncertainty, or some combination of the two.\nThe exploration-exploitation tradeoff inherent in $u\\left(\\cdot\\right)$\ncan be tuned in various ways, see Section 2.3 of \\cite{Brochu2010} for a full description\\footnote{Common types of acquisition function include the\nExpected Improvement (EI);\n$\\text{EI}\\left(\\vb*{\\beta}\\right) = \\expvalE{\\max\\left(0,\\,S\\big(\\vb*{\\beta}\\big) - S\\big(\\hat{\\vb*{\\beta}}\\big)\\right)}$\nwhere $S\\big(\\hat{\\vb*{\\beta}}\\big)$ is the current optimal value of $S$,\nUpper Confidence Bound (UCB);\n$\\text{UCB}\\left(\\vb*{\\beta}\\right) = E_{\\text{GP}} \\left(\\vb*{\\beta}\\right) + \\kappa\\,\\text{var}_{\\text{GP}} \\left(\\vb*{\\beta}\\right)$ where the mean and variance are of the GP and $\\kappa$ sets the exploration-exploitation tradeoff,\nand Maximum Probability of Improvement (MPI).}.\nThe iterative nature of Bayesian optimization is illustrated in \\cref{fig:BO_ex}.\nAn accessible implementation of Bayesian optimization is available in \\skopt \\cite{scikit-optimize,Borisyak}.\n\n\\begin{figure}[H] % TODo might want to eventually remove\n\\centering\n\\includegraphics[width=0.85\\textwidth]{figures/ml/toyGPtext3}\n\\caption{\nIllustration of Bayesian optimization over three iterations in a toy 1D maximization problem \\cite{Brochu2010}.\nNote that the maximum of the acquisition function $u\\left(\\cdot\\right)$\nlocates where $S\\left(\\vb*{\\beta}\\right)$ should be sampled next.\nThe GP estimated posterior distribution of $S\\left(\\vb*{\\beta}\\right)$\nand $u\\left(\\cdot\\right)$ are then updated.\nThis iterative process is repeated until the estimated maximum is satisfactory.\n}\n\\label{fig:BO_ex}\n\\end{figure}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Minimum Mean Square Error (MMSE) Estimator}\n\\label{opt:BO:MMSE}\n% TODO\n", "meta": {"hexsha": "ad000b5b30070d973ee1c974eff6f95c522b36c6", "size": 11547, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/opt.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/opt.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/opt.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": 53.7069767442, "max_line_length": 234, "alphanum_fraction": 0.6453624318, "num_tokens": 3091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.83973396967765, "lm_q1q2_score": 0.759665778535201}}
{"text": "\\section{Operation Research}\n\\begin{definition}[Corner point feasible solution(CPF]\nA solution that lies at the corner of a feasible region (solution space)\nIf a solution has only one feasible solution, it must be a CPF\n\\end{definition}\n\n\\begin{definition}[KKT-conditions]\n\\begin{enumerate}\n    \\item $\\frac{\\partial{f}}{\\partial{x_{j}}} - \\sum\\limits_{i=1}^{m} u_i\n        \\frac{\\partial{g_i}}{\\partial{x_j}} \\leq 0 $\n    \\item $x_j^{*}(\\frac{\\partial{f}}{\\partial{x_{j}}} - \\sum\\limits_{i=1}^{m} u_i\n        \\frac{\\partial{g_i}}{\\partial{x_j}}) = 0 $\n    \\item $g_i(x^{*}) - b_i \\leq 0$\n    \\item $u_i(g_i(x^{*}) - b_i) \\leq 0$\n    \\item $x_j^{*} \\geq 0$\n    \\item $u_j^{*} \\geq 0$\n\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Feasile region]\n    Aka solution space. The set of all valid solutions, i.e. those that do not\n    violate constraints.\n\\end{definition}\n\n\\begin{definition}[Slope-intercept form]\n    Instead of expressing an objective function, show it as\n    an expression of your parameters. (e.g. $x_{1}, c_{i,j}$)\n\\end{definition}\n", "meta": {"hexsha": "f92631e862bd9a2c95cd8198887d37c0c6eb63fd", "size": 1055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/def/OR.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/OR.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/OR.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.3793103448, "max_line_length": 82, "alphanum_fraction": 0.6597156398, "num_tokens": 348, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9399133447766224, "lm_q2_score": 0.8080672112416736, "lm_q1q2_score": 0.7595131553224789}}
{"text": "\\documentclass[11pt]{amsbook}\n\\usepackage{../HBSuerDemir}\n\\begin{document}\n    \\hPage{b2p2/414}\n    \\section{GEOMETRIC AND PHYSICAL APPLICATIONS}\n    \\subsection{GEOMETRIC APPLICATION (Area of a surface): }\n    Let S: F(x, y, z) = 0 be a surface over the region R\nin xy-plane (i.e. R is the projection of S on xy-planes). Then\nthe area of S is\n    \\begin{equation*}\n        \\hAbs{S}=\\iint_S \\,d\\sigma \n    \\end{equation*}    \n    and we have\\\\\n    \\begin{equation*}\n        \\iint_S \\,d\\sigma= \\iint_R \\sec \\gamma \\overline {\\,dx \\,dy}\n    \\end{equation*}    \t\n\\begin {figure}[ htbp ]\n\\begin {center}\n\\includegraphics[width=0.4\\columnwidth]{images/b2p1-130.pdf}\n\n\n\\label {fig: image}\n\\end{center}\n\\end{figure}\n\n    where $d\\sigma$ is the elementary area of S and y is the acute angle between the normal line to S at a point in $d\\sigma$ and z-axis.\\\\\n    Then,\n    \\begin{align*}       \n    &\\cos \\gamma= \\hAbs{\\vec{n}.k}\\\\\n    \\Longrightarrow&\\sec \\gamma= \\frac{1}{\\hAbs{\\vec{n}.k}}=\n    \\begin{cases}\n        \\sqrt{1+z_{x}^{2}+z_{y}^{2}}\\quad if \\quad z=f(x,y)\\\\\n        \\frac{\\sqrt{F_{x}^{2}}+\\sqrt{F_{y}^{2}}+\\sqrt{F_{z}^{2}}}{\\hAbs{F_{z}}}\\quad if \\quad f(x,y,z)=0\n    \\end{cases}\n    \\end{align*}\n\n    \n\n    and\n    \\begin{equation*}\n        \\hAbs{S}= \\iint_R \\sqrt{1+z_{x}^{2}+z_{y}^{2}}\\ \\overline {\\,dx \\,dy}\\quad (or \\iint_R \\frac{\\sqrt{F_{x}^{2}}+\\sqrt{F_{y}^{2}}+\\sqrt{F_{z}^{2}}}{\\hAbs{F_{z}}}\\ \\overline {\\,dx \\,dy})\n    \\end{equation*}\n    Similarly\n        \\begin{equation*}\n        \\hAbs{S}= \\iint_R \\sqrt{1+x_{x}^{2}+x_{z}^{2}}\\ \\overline {\\,dx \\,dz}\\quad (or \\iint_R \\frac{\\sqrt{F_{x}^{2}}+\\sqrt{F_{y}^{2}}+\\sqrt{F_{z}^{2}}}{\\hAbs{F_{x}}}\\ \\overline {\\,dy \\,dz})\n    \\end{equation*}\n        \\begin{equation*}\n        \\hAbs{S}= \\iint_R \\sqrt{1+y_{x}^{2}+y_{z}^{2}}\\ \\overline {\\,dx \\,dz}\\quad (or \\iint_R \\frac{\\sqrt{F_{x}^{2}}+\\sqrt{F_{y}^{2}}+\\sqrt{F_{z}^{2}}}{\\hAbs{F_{y}}}\\ \\overline {\\,dx \\,dz})\n    \\end{equation*}\n    To obtain a simpler region R or a simpler integrand, one\nprojects S onto a convenient coordinate plane. \n\\end{document}", "meta": {"hexsha": "177db97e35c7985831d165ca06daff21eb4bb967", "size": 2061, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw2/non-merged/BERKAY KOZAN_38242_assignsubmission_file_/homework2/pages/b2p2-414.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/BERKAY KOZAN_38242_assignsubmission_file_/homework2/pages/b2p2-414.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/BERKAY KOZAN_38242_assignsubmission_file_/homework2/pages/b2p2-414.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": 39.6346153846, "max_line_length": 190, "alphanum_fraction": 0.5788452208, "num_tokens": 833, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473779969194, "lm_q2_score": 0.8705972801594707, "lm_q1q2_score": 0.7594632546383637}}
{"text": "\\chapter{Array}\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 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$.\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: assuming there is a majority number $x$, if at the index $i$, the current count is $j$ and the current counter does not capture the majority number, there are less than $\\frac{i-j}{2}$ $x$, thus there are more than $\\frac{n-i+j}{2}$ $x$ after the index $i$. The $j$ $x$ beats against the counter and $\\frac{n-i-j}{2}$ $x$ will make it counted by counter. \n\nIf the counter captures the majority number, two cases will happen. The one is that the counter continue to capture the majority number till the end; then the counter will captures the correct majority number. The other case is that the majority number counter is beaten by other numbers, which will in turn fall back to the case that the counter does not capture the majority number.\n \nThis 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        while neg < n and A[neg] > 0: neg += 1\n        while pos < n and A[pos] < 0: pos += 1\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", "meta": {"hexsha": "a91d0042cfc6a877d15be354260755527d7e1208", "size": 6026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterArray.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": "chapterArray.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": "chapterArray.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": 38.3821656051, "max_line_length": 384, "alphanum_fraction": 0.6739130435, "num_tokens": 1623, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8705972801594706, "lm_q1q2_score": 0.7594632459705836}}
{"text": "\\sec{The Method of Variation of Parameters}\n\\subsection{Introduction}\nThis is a powerful method to find a particular solution to a linear ODE when the general solution of the associated homogeneous equation is known.\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tConsider the second order ODE \n\t\\begin{equation} \\label{eq:mvp}\n\t\ty'' + P(x)y' + Q(x)y = R(x).\n\t\\end{equation}\n\tAssume that the general solution $y_g(x)$ of the associated homogeneous equation\n\t\\begin{equation} \\label{eq:mvphomo}\n\t\ty'' + P(x)y' + Q(x)y = 0\n\t\\end{equation}\n\tis known.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle2, frametitle={The Solution - derivation. (Can be ignored.)}]\n\tLet $y_1$ and $y_2$ be two linearly independent solutions of (\\ref{eq:mvphomo}).\\\\\n\tWe seek to find a particular solution $y_p(x)$ of (\\ref{eq:mvp}) of the form\n\t\\begin{equation} \\label{eq:ypform}\n\t\ty_p(x) = v_1(x)y_1(x) + v_2(x)y_2(x).\n\t\\end{equation}\n\t(It is our \\emph{assumption - I} that we would have a solution of this form.)\\\\\n\tNow, we place the following restriction\n\t\\begin{equation} \\label{eq:mvpcond1}\n\t\tv_1'y_1 + v_2'y_2 \\equiv 0.\n\t\\end{equation}\n\t(This is \\emph{assumption - II}.)\\\\\n\tUnder this assumption, we get \n\t\\begin{align*} \n\t\ty_p' &= v_1y_1' + v_2y_2',\\\\\n\t\ty_p'' &= v_1y_1'' + v_1'y_1' + v_2y_2''+ v_2'y_2'.\n\t\\end{align*}\n\tSubstituting this back into (\\ref{eq:mvp}) and using the fact that $y_1$ and $y_2$ are solutions of (\\ref{eq:mvphomo}) gives us that\n\t\\begin{equation} \\label{eq:mvpcond2}\n\t\tv_1'y_1' + v_2'y_2' = R(x).\n\t\\end{equation}\n\tNow, note that the system of equations (\\ref{eq:mvpcond1}) and (\\ref{eq:mvpcond2}) can be uniquely solved for $v_1'$ and $v_2'$. (Since $\\{y_1, y_2\\}$ is linearly independent and hence, the Wronskian is always nonzero. Recall Corollary \\ref{cor:wronskian}.)\\\\\n\tIntegrate to obtain $v_1$ and $v_2$ and finally, a particular solution $y_p$ is given by (\\ref{eq:ypform}). The general solution is, as usual, $y_g + y_p.$\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={The Solution}]\n\tLet $y_1$ and $y_2$ be two linearly independent solutions of (\\ref{eq:mvphomo}).\\\\\n\tSolve the following system of equations for functions $v_1'(x)$ and $v_2'(x)$:\n\t\\begin{align*} \n\t\tv_1'y_1 + v_2'y_2 &= 0,\\\\\n\t\tv_1'y_1' + v_2'y_2' &= R(x).\n\t\\end{align*}\n\tIntegrate $v_1'$ and $v_2'$ to get $v_1$ and $v_2.$ Then, a particular solution of (\\ref{eq:mvp}) is:\n\t\\begin{equation*} \n\t\ty_p(x) = v_1(x)y_1(x) + v_2(x)y_2(x).\n\t\\end{equation*}\n\tThe general solution of (\\ref{eq:mvp}) is then $y_g + y_p.$\n\\end{mdframed}\n\\exercise{%\nSolve $y'' + y = \\tan x.$\n}", "meta": {"hexsha": "3ba7448f14a7d97ec0746d893ef23eb411ce6d8e", "size": 2571, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/varparam.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/varparam.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/varparam.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 47.6111111111, "max_line_length": 260, "alphanum_fraction": 0.6849474912, "num_tokens": 973, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8705972751232809, "lm_q1q2_score": 0.7594632415772767}}
{"text": "\\chapter{Bayesian statistics}\n\\label{chap:Bayesian statistics}\n\n\\section{Introduction}\nUsing the posterior distribution to summarize everything we know about a set of unknown variables is at the core of Bayesian statistics. In this chapter, we discuss this approach to statistics in more detail.\n\n\n\\section{Summarizing posterior distributions}\nThe posterior $p(\\vec{\\theta}|\\mathcal{D})$ summarizes everything we know about the unknown quantities $\\vec{\\theta}$. In this section, we discuss some simple quantities that can be derived from a probability distribution, such as a posterior. These summary statistics are often easier to understand and visualize than the full joint.\n\n\n\\subsection{MAP estimation}\nWe can easily compute a \\textbf{point estimate} of an unknown quantity by computing the posterior mean, median or mode. In Section \\ref{sec:Bayesian-decision-theory}, we discuss how to use decision theory to choose between these methods. Typically the posterior mean or median is the most appropriate choice for a realvalued quantity, and the vector of posterior marginals is the best choice for a discrete quantity. However, the posterior mode, aka the MAP estimate, is the most popular choice because it reduces to an optimization problem, for which efficient algorithms often exist. Futhermore, MAP estimation can be interpreted in non-Bayesian terms, by thinking of the log prior as a regularizer (see Section TODO for more details).\n\nAlthough this approach is computationally appealing, it is important to point out that there are various drawbacks to MAP estimation, which we briefly discuss below. This will provide motivation for the more thoroughly Bayesian approach which we will study later in this chapter(and elsewhere in this book).\n\n\n\\subsubsection{No measure of uncertainty}\nThe most obvious drawback of MAP estimation, and indeed of any other \\emph{point estimate} such as the posterior mean or median, is that it does not provide any measure of uncertainty. In many applications, it is important to know how much one can trust a given estimate. We can derive such confidence measures from the posterior, as we discuss in Section \\ref{sec:Credible-intervals}.\n\n\\subsubsection{Plugging in the MAP estimate can result in overfitting}\nIf we don’t model the uncertainty in our parameters, then our predictive distribution will be overconfident. Overconfidence in predictions is particularly problematic in situations where we may be risk averse; see Section \\ref{sec:Bayesian-decision-theory} for details.\n\n\\subsubsection{The mode is an untypical point}\nChoosing the mode as a summary of a posterior distribution is often a very poor choice, since the mode is usually quite untypical of the distribution, unlike the mean or median. The basic problem is that the mode is a point of measure zero, whereas the mean and median take the volume of the space into account. See Figure \\ref{fig:untypical-point}.\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat[]{\\includegraphics[scale=.50]{untypical-point-a.png}} \\\\\n\\subfloat[]{\\includegraphics[scale=.50]{untypical-point-b.png}}\n\\caption{(a) A bimodal distribution in which the mode is very untypical of the distribution. The thin blue vertical line is the mean, which is arguably a better summary of the distribution, since it is near the majority of the probability mass. (b) A skewed distribution in which the mode is quite different from the mean.}\n\\label{fig:untypical-point} \n\\end{figure}\n\nHow should we summarize a posterior if the mode is not a good choice? The answer is to use decision theory, which we discuss in Section \\ref{sec:Bayesian-decision-theory}. The basic idea is to specify a loss function, where $L(\\theta,\\hat{\\theta})$ is the loss you incur if the truth is $\\theta$ and your estimate is $\\hat{\\theta}$. If we use 0-1 loss $L(\\theta,\\hat{\\theta})=\\mathbb{I}(\\theta \\neq \\hat{\\theta})$(see section \\ref{sec:Loss-function-and-risk-function}), then the optimal estimate is the posterior mode. 0-1 loss means you only get “points” if you make no errors, otherwise you get nothing: there is no “partial credit” under this loss function! For continuous-valued quantities, we often prefer to use squared error loss, $L(\\theta,\\hat{\\theta})=(\\theta-\\hat{\\theta})^2$ ; the corresponding optimal estimator is then the posterior mean, as we show in Section \\ref{sec:Bayesian-decision-theory}. Or we can use a more robust loss function, $L(\\theta,\\hat{\\theta})=|\\theta-\\hat{\\theta}|$, which gives rise to the posterior median.\n\n\\subsubsection{MAP estimation is not invariant to reparameterization *}\nA more subtle problem with MAP estimation is that the result we get depends on how we parameterize the probability distribution. Changing from one representation to another equivalent representation changes the result, which is not very desirable, since the units of measurement are arbitrary (e.g., when measuring distance, we can use centimetres or inches).\n\nTo understand the problem, suppose we compute the posterior forx. If we define y=f(x), the distribution for yis given by Equation \\ref{eqn:General-transformations}. The $\\frac{\\mathrm{d}x}{\\mathrm{d}y}$ term is called the Jacobian, and it measures the change in size of a unit volume passed\nthrough $f$. Let $\\hat{x}=\\arg\\max_x p_x(x)$ be the MAP estimate for $x$. In general it is not the case that $\\hat{x}=\\arg\\max_x p_x(x)$ is given by $f(\\hat{x})$. For example, let $X \\sim \\mathcal{N}(6,1)$ and $y=f(x)$, where $f(x)=1/(1+\\exp(-x+5))$. \n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.70]{mode-reparameterization.png}\n\\caption{Example of the transformation of a density under a nonlinear transform. Note how the mode of the transformed distribution is not the transform of the original mode. Based on Exercise 1.4 of (Bishop 2006b).}\n\\label{fig:mode-reparameterization} \n\\end{figure}\n\nWe can derive the distribution of $y$ using Monte Carlo simulation (see Section \\ref{sec:Monte-Carlo-approximation}). The result is shown in Figure \\ref{sec:mode-reparameterization}. We see that the original Gaussian has become “squashed” by the sigmoid nonlinearity. In particular, we see that the mode of the transformed distribution is not equal to the transform of the original mode.\n\nThe MLE does not suffer from this since the likelihood is a function, not a probability density. Bayesian inference does not suffer from this problem either, since the change of measure is taken into account when integrating over the parameter space.\n\n\n\\subsection{Credible intervals}\n\\label{sec:Credible-intervals}\nIn addition to point estimates, we often want a measure of confidence. A standard measure of confidence in some (scalar) quantity $\\theta$ is the “width” of its posterior distribution. This can be measured using a $100(1−\\alpha)\\%$ credible interval, which is a (contiguous) region $C=(\\ell,u)$(standing for lower and upper) which contains $1−\\alpha$ of the posterior probability mass, i.e.,\n\\begin{equation}\nC_{\\alpha}(\\mathcal{D}) \\quad \\text{where } P(\\ell \\leq \\theta \\leq u)=1-\\alpha\n\\end{equation}\n\nThere may be many such intervals, so we choose one such that there is $(1−\\alpha)/2$ mass in each tail; this is called a \\textbf{central interval}.\n\nIf the posterior has a known functional form, we can compute the posterior central interval using $\\ell=F^{-1}(\\alpha/2)$ and $u=F^{-1}(1-\\alpha/2)$, where $F$ is the cdf of the posterior. \n\nIf we don’t know the functional form, but we can draw samples from the posterior, then we can use a Monte Carlo approximation to the posterior quantiles: we simply sort the $\\mathcal{S}$ samples, and find the one that occurs at location $\\alpha/\\mathcal{S}$ along the sorted list. As $\\mathcal{S} \\rightarrow \\infty$, this converges to the true quantile. \n\nPeople often confuse Bayesian credible intervals with frequentist confidence intervals. However, they are not the same thing, as we discuss in Section TODO. In general, credible intervals are usually what people want to compute, but confidence intervals are usually what they actually compute, because most people are taught frequentist statistics but not Bayesian statistics. Fortunately, the mechanics of computing a credible interval is just as easy as computing a confidence interval. \n\n\n\\subsection{Inference for a difference in proportions}\nSometimes we have multiple parameters, and we are interested in computing the posterior distribution of some function of these parameters. For example, suppose you are about to buy something from Amazon.com, and there are two sellers offering it for the same price. Seller 1 has 90 positive reviews and 10 negative reviews. Seller 2 has 2 positive reviews and 0 negative reviews. Who should you buy from?\\footnote{This example is from \\url{http://www.johndcook.com/blog/2011/09/27/bayesian-amazon/}}.\n\nOn the face of it, you should pick seller 2, but we cannot be very confident that seller 2 is better since it has had so few reviews. In this section, we sketch a Bayesian analysis of this problem. Similar methodology can be used to compare rates or proportions across groups for a variety of other settings.\n\nLet $\\theta_1$ and $\\theta_2$ be the unknown reliabilities of the two sellers. Since we don’t know much about them, we’ll endow them both with uniform priors, $\\theta_i \\sim \\text{Beta}(1,1)$. The posteriors are $p(\\theta_1|\\mathcal{D}_1)=\\text{Beta}(91,11)$ and $p(\\theta_2|\\mathcal{D}_2)=\\text{Beta}(3,1)$.\n\nWe want to compute $p(\\theta_1 >\\theta_2|\\mathcal{D})$. For convenience, let us define $\\delta=\\theta_1-\\theta_2$ as the difference in the rates. (Alternatively we might want to work in terms of the log-odds ratio.) We can compute the desired quantity using numerical integration\n\\begin{equation}\n\\begin{split}\np(\\delta>0|\\mathcal{D}) & = \\int_0^1\\int_0^1 \\mathbb{I}(\\theta_1>\\theta_2)\\text{Beta}(\\theta_1|91,11) \\\\\n                        & \\quad \\text{Beta}(\\theta_2|3,1)\\mathrm{d}\\theta_1\\mathrm{d}\\theta_2\n\\end{split}\n\\end{equation}\n\nWe find $p(\\delta>0|\\mathcal{D})=0.710$, which means you are better off buying from seller 1! \n\n\n\\section{Bayesian model selection}\n\\label{sec:Bayesian-model-selection}\n\nIn general, when faced with a set of models (i.e., families of parametric distributions) of different complexity, how should we choose the best one? This is called the \\textbf{model selection} problem.\n\nOne approach is to use cross-validation to estimate the generalization error of all the candidate models, and then to pick the model that seems the best. However, this requires fitting each model $K$ times, where $K$ is the number of CV folds. A more efficient approach is to compute the posterior over models,\n\\begin{equation}\np(m|\\mathcal{D})=\\dfrac{p(\\mathcal{D}|m)p(m)}{\\sum_{m'}p(\\mathcal{D}|m')p(m')}\n\\end{equation}\n\nFrom this, we can easily compute the MAP model, $\\hat{m}=\\arg\\max_m{p(m|\\mathcal{D})}$. This is called \\textbf{Bayesian model selection}.\n\nIf we use a uniform prior over models, this amounts to picking the model which maximizes\n\\begin{equation}\\label{eqn:marginal-likelihood}\np(\\mathcal{D}|m)=\\int{p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}|m)}\\mathrm{d}\\vec{\\theta}\n\\end{equation}\n\nThis quantity is called the \\textbf{marginal likelihood}, the \\textbf{integrated likelihood}, or the \\textbf{evidence} for model $m$. The details on how to perform this integral will be discussed in Section \\ref{sec:Computing-the-marginal-likelihood}. But first we give an intuitive interpretation of what this quantity means.\n\n\n\\subsection{Bayesian Occam's razor}\nOne might think that using $p(\\mathcal{D}|m)$ to select models would always favour the model with the most parameters. This is true if we use $p(\\mathcal{D}|\\hat{\\vec{\\theta}}_m)$ to select models, where $\\hat{\\vec{\\theta}}_m)$ is the MLE or MAP estimate of the parameters for model $m$, because models with more parameters will fit the data better, and hence achieve higher likelihood. However, if we integrate out the parameters, rather than maximizing them, we are automatically protected from overfitting: models with more parameters do not necessarily have higher \\emph{marginal likelihood}. This is called the \\textbf{Bayesian Occam’s razor} effect (MacKay 1995b; Murray and Ghahramani 2005), named after the principle known as \\textbf{Occam’s razor}, which says one should pick the simplest model that adequately explains the data.\n\nOne way to understand the Bayesian Occam’s razor is to notice that the marginal likelihood can be rewritten as follows, based on the chain rule of probability (Equation \\ref{eqn:product-rule}):\n\\begin{equation}\\begin{split}\np(D) & =p((\\vec{x}_1,y_1))p((\\vec{x}_2,y_2)|(\\vec{x}_1,y_1)) \\\\\n     & \\quad p((\\vec{x}_3,y_3)|(\\vec{x}_1,y_1):(\\vec{x}_2,y_2))\\cdots \\\\\n\t & \\quad p((\\vec{x}_N,y_N)|(\\vec{x}_1,y_1):(\\vec{x}_{N-1},y_{N-1}))\n\\end{split}\\end{equation}\n\nThis is similar to a leave-one-out cross-validation estimate (Section \\ref{sec:Cross-validation}) of the likelihood, since we predict each future point given all the previous ones. (Of course, the order of the data does not matter in the above expression.) If a model is too complex, it will overfit the “early” examples and will then predict the remaining ones poorly.\n\nAnother way to understand the Bayesian Occam’s razor effect is to note that probabilities must sum to one. Hence $\\sum_{p(\\mathcal{D}')} p(m|\\mathcal{D}')=1$, where the sum is over all possible data sets. Complex models, which can predict many things, must spread their probability mass thinly, and hence will not obtain as large a probability for any given data set as simpler models. This is sometimes called the \\textbf{conservation of probability mass} principle, and is illustrated in Figure \\ref{fig:Bayesian-Occams-razor}.\n\n\\begin{figure}[hbtp]\n\\centering\n    \\includegraphics[scale=.80]{Bayesian-Occams-razor.png}\n\\caption{A schematic illustration of the Bayesian Occam’s razor. The broad (green) curve corresponds to a complex model, the narrow (blue) curve to a simple model, and the middle (red) curve is just right. Based on Figure 3.13 of (Bishop 2006a). }\n\\label{fig:Bayesian-Occams-razor} \n\\end{figure}\n\nWhen using the Bayesian approach, we are not restricted to evaluating the evidence at a finite grid of values. Instead, we can use numerical optimization to find $\\lambda^*=\\arg\\max_{\\lambda}p(\\mathcal{D}|\\lambda)$. This technique is called \\textbf{empirical Bayes} or \\textbf{type II maximum likelihood} (see Section \\ref{sec:Empirical-Bayes} for details). An example is shown in Figure TODO(b): we see that the curve has a similar shape to the CV estimate, but it can be computed more efficiently.\n\n\n\\subsection{Computing the marginal likelihood (evidence)}\n\\label{sec:Computing-the-marginal-likelihood}\nWhen discussing parameter inference for a fixed model, we often wrote\n\\begin{equation}\np(\\vec{\\theta}|\\mathcal{D},m) \\propto p(\\vec{\\theta}|m)p(\\mathcal{D}|\\vec{\\theta},m)\n\\end{equation}\nthus ignoring the normalization constant $p(\\mathcal{D}|m)$. This is valid since $p(\\mathcal{D}|m)$is constant wrt $\\vec{\\theta}$. However, when comparing models, we need to know how to compute the marginal likelihood, $p(\\mathcal{D}|m)$. In general, this can be quite hard, since we have to integrate over all possible parameter values, but when we have a conjugate prior, it is easy to compute, as we now show.\n\nLet $p(\\vec{\\theta})=q(\\vec{\\theta})/Z_0$ be our prior, where $q(\\vec{\\theta})$ is an unnormalized distribution, and $Z_0$ is the normalization constant of the prior. Let $p(\\mathcal{D}|\\vec{\\theta})=q(\\mathcal{D}|\\vec{\\theta})/Z_{\\ell}$ be the likelihood, where $Z_{\\ell}$ contains any constant factors in the likelihood. Finally let $p(\\vec{\\theta}|\\mathcal{D})=q(\\vec{\\theta}|\\mathcal{D})/Z_N$ be our posterior , where $q(\\vec{\\theta}|\\mathcal{D})=q(\\mathcal{D}|\\vec{\\theta})q(\\vec{\\theta})$ is the unnormalized posterior, and $Z_N$ is the normalization constant of the posterior. We have\n\\begin{align}\np(\\vec{\\theta}|\\mathcal{D})& =\\dfrac{p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta})}{p(\\mathcal{D})} \\\\\n\\dfrac{q(\\vec{\\theta}|\\mathcal{D})}{Z_N}& =\\dfrac{q(\\mathcal{D}|\\vec{\\theta})q(\\vec{\\theta})}{Z_{\\ell}Z_0p(\\mathcal{D})} \\\\\np(\\mathcal{D})& = \\dfrac{Z_N}{Z_0Z_{\\ell}}\n\\end{align}\n\nSo assuming the relevant normalization constants are tractable, we have an easy way to compute the marginal likelihood. We give some examples below.\n\n\\subsubsection{Beta-binomial model}\nLet us apply the above result to the Beta-binomial model. Since we know $p(\\vec{\\theta}|\\mathcal{D})=\\mathrm{Beta}(\\vec{\\theta}|a',b')$, where $a'=a+N_1$, $b'=b+N_0$, we know the normalization constant of the posterior is $B(a',b')$. Hence\n\\begin{align}\np(\\theta|\\mathcal{D})& =\\dfrac{p(\\mathcal{D}|\\theta)p(\\theta)}{p(\\mathcal{D})} \\\\\n    & =\\dfrac{1}{p(\\mathcal{D})}\\left[\\dfrac{1}{B(a,b)}\\theta^{a-1}(1-\\theta)^{b-1}\\right] \\nonumber \\\\\n\t& \\quad \\left[\\dbinom{N}{N_1}\\theta^{N_1}(1-\\theta)^{N_0}\\right] \\\\\n\t& =\\dbinom{N}{N_1}\\dfrac{1}{p(\\mathcal{D})}\\dfrac{1}{B(a,b)}\\left[\\theta^{a+N_1-1}(1-\\theta)^{b+N_0-1}\\right]\n\\end{align}\n\nSo\n\\begin{align}\n\\dfrac{1}{B(a+N_1,b+N_0)} & = \\dbinom{N}{N_1}\\dfrac{1}{p(\\mathcal{D})}\\dfrac{1}{B(a,b)} \\\\\np(\\mathcal{D}) & = \\dbinom{N}{N_1}\\dfrac{B(a+N_1,b+N_0)}{B(a,b)}\n\\end{align}\n\nThe marginal likelihood for the Beta-Bernoulli model is the same as above, except it is missingthe $\\binom{N}{N_1}$ term.\n\n\\subsubsection{Dirichlet-multinoulli model}\nBy the same reasoning as the Beta-Bernoulli case, one can show that the marginal likelihood for the Dirichlet-multinoulli model is given by\n\\begin{align}\np(\\mathcal{D}) & =\\dfrac{B(\\vec{N}+\\vec{\\alpha})}{B(\\vec{\\alpha})} \\\\\n   & = \\dfrac{\\Gamma(\\sum_k \\alpha_k)}{\\Gamma(N+\\sum_k \\alpha_k)}\\prod\\limits_k \\dfrac{\\Gamma(N_k+\\alpha_k)}{\\Gamma(\\alpha_k)}\n\\end{align}\n\n\\subsubsection{Gaussian-Gaussian-Wishart model}\nConsider the case of an MVN with a conjugate NIW prior. Let $Z_0$ be the normalizer for the prior, $Z_N$ be normalizer for the posterior, and let $Z_{\\ell}(2\\pi)^{ND/2}=$ be the normalizer for the likelihood. Then it is easy to see that\n\\begin{align}\np(\\mathcal{D})& =\\dfrac{Z_N}{Z_0Z_{\\ell}} \\\\\n   & = \\dfrac{1}{(2\\pi)^{ND/2}}\\dfrac{\\left(\\frac{2\\pi}{\\kappa_N}\\right)^{D/2}|\\vec{S}_N|^{-\\nu_N/2}2^{(\\nu_0+N)D/2}\\Gamma_D(\\nu_N/2)}{\\left(\\frac{2\\pi}{\\kappa_0}\\right)^{D/2}|\\vec{S}_0|^{-\\nu_0/2}2^{\\nu_0D/2}\\Gamma_D(\\nu_0/2)} \\\\\n   & = \\dfrac{1}{\\pi^{ND/2}}\\left(\\dfrac{\\kappa_0}{\\kappa_N}\\right)^{D/2}\\dfrac{|\\vec{S}_0|^{\\nu_0/2}}{|\\vec{S}_N|^{\\nu_N/2}}\\dfrac{\\Gamma_D(\\nu_N/2)}{\\Gamma_D(\\nu_0/2)}\n\\end{align}\n\n\\subsubsection{BIC approximation to log marginal likelihood}\nIn general, computing the integral in Equation \\ref{eqn:marginal-likelihood} can be quite difficult. One simple but popular approximation is known as the \\textbf{Bayesian information criterion} or \\textbf{BIC}, which has the following form (Schwarz 1978):\n\\begin{equation}\n\\mathrm{BIC} \\triangleq \\log p(\\mathcal{D}|\\hat{\\vec{\\theta}})-\\dfrac{\\mathrm{dof}(\\hat{\\vec{\\theta}})}{2}\\log{N}\n\\end{equation}\nwhere $\\mathrm{dof}(\\hat{\\vec{\\theta}})$ is the number of \\textbf{degrees of freedom} in the model, and $\\hat{\\vec{\\theta}}$ is the MLE for the model. We see that this has the form of a \\textbf{penalized log likelihood}, where the penalty term depends on the model’s complexity. See Section TODO for the derivation of the BIC score.\n\nAs an example, consider linear regression. As we show in Section TODO, the MLE is given by $\\hat{\\vec{w}}=(\\vec{X}^T\\vec{X})^{-1}\\vec{X}^T\\vec{y}$ and $\\sigma^2=\\frac{1}{N}\\sum_{i=1}^N (y_i-\\hat{\\vec{w}}^T\\vec{x}_i)$. The corresponding log likelihood is given by\n\\begin{equation}\n\\log p(\\mathcal{D}|\\hat{\\vec{\\theta}}) = -\\dfrac{N}{2}\\log(2\\pi\\hat{\\sigma}^2)-\\dfrac{N}{2}\n\\end{equation}\n\nHence the BIC score is as follows (dropping constant terms)\n\\begin{equation}\n\\mathrm{BIC}=-\\dfrac{N}{2}\\log(\\hat{\\sigma}^2)-\\dfrac{D}{2}\\log{N}\n\\end{equation}\nwhere $D$ is the number of variables in the model. In the statistics literature, it is common to use an alternative definition of BIC, which we call the BIC \\emph{cost}(since we want to minimize it):\n\\begin{equation}\n\\mathrm{BIC\\text{-}cost} \\triangleq -2\\log p(\\mathcal{D}|\\hat{\\vec{\\theta}})-\\mathrm{dof}(\\hat{\\vec{\\theta}})\\log{N} \\approx -2\\log{p(\\mathcal{D})}\n\\end{equation}\n\nIn the context of linear regression, this becomes\n\\begin{equation}\n\\mathrm{BIC\\text{-}cost} = N\\log(\\hat{\\sigma}^2)+D\\log{N}\n\\end{equation}\n\nThe BIC method is very closely related to the \\textbf{minimum description length} or \\textbf{MDL} principle, which characterizes the score for a model in terms of how well it fits the data, minus how complex the model is to define. See (Hansen and Yu 2001) for details.\n\nThere is a very similar expression to BIC/ MDL called the \\textbf{Akaike information criterion} or \\textbf{AIC}, defined as\n\\begin{equation}\n\\mathrm{AIC}(m,\\mathcal{D}) = \\log{p(\\mathcal{D}|\\hat{\\vec{\\theta}}_{MLE})}-\\mathrm{dof}(m)\n\\end{equation}\n\nThis is derived from a frequentist framework, and cannot be interpreted as an approximation to the marginal likelihood. Nevertheless, the form of this expression is very similar to BIC. We see that the penalty for AIC is less than for BIC. This causes AIC to pick more complex models. However, this can result in better predictive accuracy. See e.g., (Clarke et al. 2009, sec 10.2) for further discussion on such information criteria.\n\n\\subsubsection{Effect of the prior}\nSometimes it is not clear how to set the prior. When we are performing posterior inference, the details of the prior may not matter too much, since the likelihood often overwhelms the prior anyway. But when computing the marginal likelihood, the prior plays a much more important role, since we are averaging the likelihood over all possible parameter settings, as weighted by the prior.\n\nIf the prior is unknown, the correct Bayesian procedure is to put a prior on the prior. If the prior is unknown, the correct Bayesian procedure is to put a prior on the prior. \n\n\n\\subsection{Bayes factors}\nSuppose our prior on models is uniform, $p(m) \\propto 1$. Then model selection is equivalent to picking the model with the highest marginal likelihood. Now suppose we just have two models we are considering, call them the \\textbf{null hypothesis}, $M_0$, and the \\textbf{alternative hypothesis}, $M_1$. Define the \\textbf{Bayes factor} as the ratio of marginal likelihoods:\n\\begin{equation}\n\\mathrm{BF}_{1,0} \\triangleq \\dfrac{p(\\mathcal{D}|M_1)}{p(\\mathcal{D}|M_0)}=\\dfrac{p(M_1|\\mathcal{D})}{p(M_2|\\mathcal{D})}/\\dfrac{p(M_1)}{p(M_0)}\n\\end{equation}\n\n\n\\section{Priors}\nThe most controversial aspect of Bayesian statistics is its reliance on priors. Bayesians argue this is unavoidable, since nobody is a \\textbf{tabula rasa} or \\textbf{blank slate}: all inference must be done conditional on certain assumptions about the world. Nevertheless, one might be interested in minimizing the impact of one’s prior assumptions. We briefly discuss some ways to do this below.\n\n\n\\subsection{Uninformative priors}\nIf we don’t have strong beliefs about what $\\theta$ should be, it is common to use an \\textbf{uninformative} or \\textbf{non-informative} prior, and to “let the data speak for itself”.\n\n\n\\subsection{Robust priors}\nIn many cases, we are not very confident in our prior, so we want to make sure it does not have an undue influence on the result. This can be done by using \\textbf{robust priors}(Insua and Ruggeri 2000), which typically have heavy tails, which avoids forcing things to be too close to the prior mean.\n\n\n\\subsection{Mixtures of conjugate priors}\nRobust priors are useful, but can be computationally expensive to use. Conjugate priors simplify the computation, but are often not robust, and not flexible enough to encode our prior knowledge. However, it turns out that a \\textbf{mixture of conjugate priors} is also conjugate, and can approximate any kind of prior (Dallal and Hall 1983; Diaconis and Ylvisaker 1985). Thus such priors provide a good compromise between computational convenience and flexibility.\n\n\n\\section{Hierarchical Bayes}\nA key requirement for computing the posterior $p(\\vec{\\theta}|\\mathcal{D})$ is the specification of a prior $p(\\vec{\\theta}|\\vec{\\eta})$, where $\\vec{\\eta}$ are the hyper-parameters. What if we don’t know how to set $\\vec{\\eta}$? In some cases, we can use uninformative priors, we we discussed above. A more Bayesian approach is to put a prior on our priors! In terms of graphical models (Chapter TODO), we can represent the situation as follows:\n\\begin{equation}\n\\vec{\\eta} \\rightarrow \\vec{\\theta} \\rightarrow \\mathcal{D}\n\\end{equation}\n\nThis is an example of a \\textbf{hierarchical Bayesian model}, also called a \\textbf{multi-level} model, since there are multiple levels of unknown quantities. \n\n\n\\section{Empirical Bayes}\n\\label{sec:Empirical-Bayes}\n\n\\begin{table}\n\\normalsize\t\n\\centering\n\\begin{tabular}{ll}\n\\hline\\noalign{\\smallskip}\n\\textbf{Method} & \\textbf{Definition} \\\\\n\\noalign{\\smallskip}\\svhline\\noalign{\\smallskip}\nMaximum likelihood & $\\hat{\\vec{\\theta}}=\\arg\\max_{\\vec{\\theta}} p(\\mathcal{D}|\\vec{\\theta})$ \\\\\nMAP estimation & $\\hat{\\vec{\\theta}}=\\arg\\max_{\\vec{\\theta}} p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}|\\vec{\\eta})$ \\\\\n\\multirow{2}{*}{ML-II (\\textbf{Empirical Bayes})} & $\\hat{\\vec{\\eta}}=\\arg\\max_{\\vec{\\eta}} \\int p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}|\\vec{\\eta})\\mathrm{d}\\vec{\\theta}$ \\\\\n                                                  & $\\quad =\\arg\\max_{\\vec{\\eta}}p(\\mathcal{D}|\\vec{\\eta})$ \\\\\n\\multirow{2}{*}{MAP-II} & $\\hat{\\vec{\\eta}}=\\arg\\max_{\\vec{\\eta}} \\int p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}|\\vec{\\eta})p(\\vec{\\eta})\\mathrm{d}\\vec{\\theta}$ \\\\\n                        & $\\quad =\\arg\\max_{\\vec{\\eta}}p(\\mathcal{D}|\\vec{\\eta})p(\\vec{\\eta})$ \\\\\nFull Bayes & $p(\\vec{\\theta},\\vec{\\eta}|\\mathcal{D}) \\propto p(\\mathcal{D}|\\vec{\\theta})p(\\vec{\\theta}|\\vec{\\eta})$ \\\\\n\\noalign{\\smallskip}\\hline\n\\end{tabular}\n\\end{table}\n\n\n\\section{Bayesian decision theory}\n\\label{sec:Bayesian-decision-theory}\nWe have seen how probability theory can be used to represent and updates our beliefs about the state of the world. However, ultimately our goal is to convert our beliefs into actions. In this section, we discuss the optimal way to do this.\n\nOur goal is to devise a \\textbf{decision procedure} or \\textbf{policy}, $f(\\vec{x}) : \\mathcal{X} \\rightarrow \\mathcal{Y}$, which minimizes the \\textbf{expected loss} $R_{\\mathrm{exp}}(f)$(see Equation \\ref{eqn:expected-loss}).\n\nIn the Bayesian approach to decision theory, the optimal output, having observed $\\vec{x}$, is defined as the output $a$ that minimizes the \\textbf{posterior expected loss}:\n\\begin{equation}\n\\rho(f)=\\mathbb{E}_{p(y|\\vec{x})}[L(y,f(\\vec{x}))]=\\begin{cases}\n\\sum\\limits_y L[y,f(\\vec{x})]p(y|\\vec{x}) \\\\\n\\int\\limits_y L[y,f(\\vec{x})]p(y|\\vec{x})\\mathrm{d}y\n\\end{cases}\n\\end{equation}\n\nHence the \\textbf{Bayes estimator}, also called the \\textbf{Bayes decision rule}, is given by\n\\begin{equation}\n\\delta(\\vec{x})=\\arg\\min\\limits_{f \\in \\mathcal{H}} \\rho(f)\n\\end{equation}\n\n\n\\subsection{Bayes estimators for common loss functions}\n\n\n\\subsubsection{MAP estimate minimizes 0-1 loss}\nWhen $L(y,f(x))$ is \\textbf{0-1 loss}(Section \\ref{sec:Loss-function-and-risk-function}), we can proof that MAP estimate minimizes 0-1 loss, \n\\begin{align*}\n\\arg\\min\\limits_{f \\in \\mathcal{H}} \\rho(f)& =\\arg\\min\\limits_{f \\in \\mathcal{H}} \\sum\\limits_{i=1}^K{L[C_k,f(\\vec{x})]p(C_k|\\vec{x})} \\\\\n         & =\\arg\\min\\limits_{f \\in \\mathcal{H}} \\sum\\limits_{i=1}^K{\\mathbb{I}(f(\\vec{x}) \\neq C_k)p(C_k|\\vec{x})} \\\\\n\t\t & =\\arg\\min\\limits_{f \\in \\mathcal{H}} \\sum\\limits_{i=1}^K{p(f(\\vec{x}) \\neq C_k|\\vec{x})} \\\\\n\t\t & =\\arg\\min\\limits_{f \\in \\mathcal{H}} \\left[1-{p(f(\\vec{x}) = C_k|\\vec{x})}\\right] \\\\\n\t\t & =\\arg\\max\\limits_{f \\in \\mathcal{H}} p(f(\\vec{x}) = C_k|\\vec{x})\n\\end{align*}\n\n\n\\subsubsection{Posterior mean minimizes\t$\\ell_2$(quadratic) loss}\nFor continuous parameters, a more appropriate loss function is \\textbf{squared error}, \\textbf{$\\ell_2$ loss}, or \\textbf{quadratic loss}, defined as $L(y,f(\\vec{x}))=\\left[y-f(\\vec{x})\\right]^2$.\n\nThe posterior expected loss is given by\n\\begin{equation}\\begin{split}\n\\rho(f) & =\\int\\limits_y L[y,f(\\vec{x})]p(y|\\vec{x})\\mathrm{d}y \\\\\n        & =\\int\\limits_y \\left[y-f(\\vec{x})\\right]^2p(y|\\vec{x})\\mathrm{d}y \\\\\n        & =\\int\\limits_y \\left[y^2-2yf(\\vec{x})+f(\\vec{x})^2\\right]p(y|\\vec{x})\\mathrm{d}y\n\\end{split}\\end{equation}\n\nHence the optimal estimate is the posterior mean:\n\\begin{align}\n& \\dfrac{\\partial \\rho}{\\partial f} =\\int\\limits_y [-2y+2f(\\vec{x})]p(y|\\vec{x})\\mathrm{d}y=0 \\Rightarrow \\nonumber \\\\\n& \\int\\limits_y f(\\vec{x})p(y|\\vec{x})\\mathrm{d}y = \\int\\limits_y yp(y|\\vec{x})\\mathrm{d}y \\nonumber \\\\\n& f(\\vec{x}) \\int\\limits_y p(y|\\vec{x})\\mathrm{d}y = \\mathbb{E}_{p(y|\\vec{x})}[y] \\nonumber \\\\\n& f(\\vec{x}) = \\mathbb{E}_{p(y|\\vec{x})}[y]\n\\end{align}\n\nThis is often called the \\textbf{minimum mean squared error} estimate or \\textbf{MMSE} estimate.\n\n\n\\subsubsection{Posterior median minimizes $\\ell_1$(absolute) loss}\nThe $\\ell_2$ loss penalizes deviations from the truth quadratically, and thus is sensitive to outliers. A more robust alternative is the absolute or $\\ell_1$ loss. The optimal estimate is the posterior median, i.e., a value $a$ such that $P(y<a|\\vec{x})=P(y \\geq a|\\vec{x})=0.5$.\n\n\\begin{proof}\n\\begin{align*}\n\\rho(f)& =\\int\\limits_y L[y,f(\\vec{x})]p(y|\\vec{x})\\mathrm{d}y=\\int\\limits_y |y-f(\\vec{x})|p(y|\\vec{x})\\mathrm{d}y \\\\\n       & =\\int\\limits_y [f(\\vec{x})-y]p(y<f(\\vec{x})|\\vec{x})+ \\\\\n\t   & \\quad [y-f(\\vec{x})]p(y \\geq f(\\vec{x})|\\vec{x})\\mathrm{d}y \\\\\n& \\dfrac{\\partial \\rho}{\\partial f}=\\int\\limits_y \\left[p(y<f(\\vec{x})|\\vec{x})-p(y \\geq f(\\vec{x})|\\vec{x})\\right]\\mathrm{d}y=0 \\Rightarrow \\\\\n& p(y<f(\\vec{x})|\\vec{x})=p(y \\geq f(\\vec{x})|\\vec{x})=0.5 \\\\\n& \\therefore f(\\vec{x})=\\text{median}\n\\end{align*}\n\\end{proof}\n\n\n\\subsubsection{Reject option}\nIn classification problems where $p(y|\\vec{x})$ is very uncertain, we may prefer to choose a reject action, in which we refuse to classify the example as any of the specified classes, and instead say “don’t know”. Such ambiguous cases can be handled by e.g., a human expert. This is useful in \\textbf{risk averse} domains such as medicine and finance.\n\nWe can formalize the reject option as follows. Let choosing $f(\\vec{x})=c_{K+1}$ correspond to picking the reject action, and choosing $f(\\vec{x}) \\in \\{C_1,...,C_k\\}$ correspond to picking one of the classes. Suppose we define the loss function as\n\\begin{equation}\nL(f(\\vec{x}), y)=\\begin{cases} \n0 & \\text{if } f(\\vec{x})=y \\text{ and } f(\\vec{x}),y \\in \\{C_1,...,C_k\\} \\\\\n\\lambda_s & \\text{if } f(\\vec{x}) \\neq y \\text{ and } f(\\vec{x}),y \\in \\{C_1,...,C_k\\} \\\\\n\\lambda_r & \\text{if } f(\\vec{x})=C_{K+1}\n\\end{cases}\n\\end{equation}\nwhere $\\lambda_s$ is the cost of a substitution error, and $\\lambda_r$ is the cost of the reject action. \n\n\n\\subsubsection{Supervised learning}\nWe can define the loss incurred by $f(\\vec{x})$ (i.e., using this predictor) when the unknown state of nature is $\\vec{\\theta}$(the parameters of the data generating mechanism) as follows:\n\\begin{equation}\nL(\\vec{\\theta},f) \\triangleq \\mathbb{E}_{p(\\vec{x},y|\\vec{\\theta})}[\\ell(y-f(\\vec{x}))]\n\\end{equation}\n\nThis is known as the \\textbf{generalization error}. Our goal is to minimize the posterior expected loss, given by\n\\begin{equation}\n\\rho(f|\\mathcal{D}) = \\int{p(\\vec{\\theta}|\\mathcal{D})L(\\vec{\\theta},f)}\\mathrm{d}\\vec{\\theta}\n\\end{equation}\n\nThis should be contrasted with the frequentist risk which is defined in Equation TODO.\n\n\n\\subsection{The false positive vs false negative tradeoff}\nIn this section, we focus on binary decision problems, such as hypothesis testing, two-class classification, object/ event detection, etc. There are two types of error we can make: a \\textbf{false positive}(aka \\textbf{false alarm}), or a \\textbf{false negative}(aka \\textbf{missed detection}). The 0-1 loss treats these two kinds of errors equivalently. However, we can consider the following more general loss matrix:\n\nTODO\n", "meta": {"hexsha": "25061cf33feb68372f4642b50bf90184b5699665", "size": 31981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/BayesianStatistics.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/BayesianStatistics.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/BayesianStatistics.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": 84.382585752, "max_line_length": 1043, "alphanum_fraction": 0.7322785404, "num_tokens": 9362, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972751232809, "lm_q2_score": 0.8723473630627235, "lm_q1q2_score": 0.7594632372433865}}
{"text": "\\section{Exercises in Expectations of Random Variables}\\label{S:xsExpectationsOfRVs} %S:xsMultivariateRVs\n\\begin{ExerciseList}\n\\Exercise\nLet $X$ be the number of air\n  conditioners a  store  sells each day, and assume that $X$ has\n  probability mass function $f(10)=0.1$, $f(11)=0.3$,\n  $f(12)=0.4$, $f(13)=0.2$.\n\\be\n\\item  Find the expected number of conditioners that the store sells\n  each day.\n\\item If the profit per conditioner is $\\$55$, what is the expected daily profit?\n\\ee\n\\Answer\n\\be\n\\item\nThe expected number of conditioners that the store sells daily  is\n\\ba{\\E(X)&=\\;\\sum_{i=1}^{n}x_ip_{x_i}\\\\[6pt]\n&=(10\\times0.1+11\\times0.3+12\\times0.4+13\\times0.2)\\\\[6pt]\n&=1+3.3+4.8+2.6\\\\[6pt]\n&=11.7\\enspace . }\n\\item\nThe profit per conditioner is $\\$55$, and so the expected daily profit given by\n\\[E( 55 \\,X)\\;=\\; 55 E(X) \\;=\\; 55 \\times 11.7 \\;=\\; 643.50\\, ,\\]\nis $\\$643.50$.\n\\ee\n\n\\Exercise\nA small petrol station is supplied with fuel  every Saturday\n  afternoon. Assume that its volume of sales $X$, in ten thousands of\n  litres, has density\n$$f(x)\\;=\\;\\begin{cases}6x(1-x)&0\\leq x \\leq\n  1\\\\0&\\textrm{otherwise}\\end{cases}\\,.$$\nDetermine the mean and  variance of $X$.\n\\Answer\nThe expected value $\\E(X)$ is\n\\ba{\\E(X)&=\\int^1_0 6x(1-x)x\\,dx\\\\\n&=\\;\\int^1_0 (6x^2-6x^3)\\,dx\\\\[3pt]\n&=\\;\\left. 2x^3-\\frac{6}{4}x^4\\right]^1_0\\\\\n&=\\;2(1^3-0)-\\frac{6}{4}(1^4-0)\\\\\n&=\\;0.5}\n\n\\ba{\\E(X^2)&=\\int^1_0 6x(1-x)x^2\\,dx\\\\[3pt]\n&=\\;\\int^1_0 6x^3-6x^4\\,dx\\\\[3pt]\n&=\\;\\left.\\frac{6}{4}x^4-\\frac{6}{5}x^5\\right]^1_0\\\\\n&=\\;\\frac{6}{4}(1^4-0)-\\frac{6}{5}(1^5-0)\\\\\n&=0.3  \n}\nthe variance is $\\V(X)\\;=\\;\\E(X^2)-(\\E(X))^2\\;=\\;0.3-0.5^2\\;=\\;0.05$\n\n\\Exercise\nStarting from the definition of the variance of a random variable (Definition~\\ref{D:VarianceofX}) show that\n\\[\\V(X) = \\E(X^2) - \\left(\\E(X)\\right)^2 \\enspace .\\]\n\\Answer\nThis was already done in Sec.~\\ref{S:PropOfEs} on Properties of Expectation. Make sure you understand each step.\n\n\\Exercise\nShow that $V(aX+b) = a^2 V(X)$ for constants $a$ and $b$ and a random variable $X$.\n\\Answer\nUsing the definition of variance, expectations and by completing the square, we get:\n\\begin{multline*}\nV(aX+b) = E ((aX+b)^2) - (E(aX+b))^2 = E \\left( (aX)^2 + 2aXb + b^2 \\right) - \\left( aE(X)+b\\right)^2 \\\\\n= a^2 E \\left(X^2\\right) + 2ab E(X) + b^2 - a^2(E(X))^2 - 2abE(X) - b^2\n= a^2 \\left( E \\left(X^2\\right) - (E(X))^2 \\right) = a^2 V(X) \\, .\n\\end{multline*}\n\n\\Exercise\n{**}Let $X$ be a discrete random variable with PMF given by\n\\[\nf(x) = \n\\begin{cases}\n\\frac{x}{10} & \\text{ if } x \\in \\{1,2,3,4\\} ,\\\\\n0 & \\text{ otherwise.}\n\\end{cases}\n\\]\n\\begin{itemize}\n\\item[(a)] Find:\n\\begin{itemize}\n\\item[(i)] $\\P(X=0)$\n\\item[(ii)] $\\P(2.5 < X < 5)$\n\\item[(iii)] $\\E(X)$\n\\item[(iv)] $\\V(X)$\n\\end{itemize}\n\\item[(b)] Write down the DF (or CDF) of $X$.\n\\item[(c)] Plot the PMF and CDF of $X$.\n\\end{itemize}\n\n\\Exercise\nFind the mean and the variance of the following  random variables.\n\\be\n\\item $X$ a discrete uniform random variable on $\\{1,2,3,4,5,6\\}$, i.e., \\textit{the number a fair die turns up}.\n \\item $X$ is a $\\uniform(0,8)$ random variable, i.e., \\textit{a continuous uniform random variable from the interval} $[0,8]$.\n\n\\item $X$ has a density function\n$$\nf(x)\\,=\\, \n\\begin{cases} \n2e^{-2x} & \\text{ if }  x \\geq 0\\\\ \n0 & \\text{ otherwise} \\, . \n\\end{cases}\n$$\n\\ee\n\\Answer\n\\be\n\\item\nThe probability mass function of $X$ is\n$$f(x)=\\begin{cases}\\frac{1}{6}&x=1\\\\\n\\frac{1}{6}&x=2\\\\\n\\frac{1}{6}&x=3\\\\\n\\frac{1}{6}&x=4\\\\\n\\frac{1}{6}&x=5\\\\\n\\frac{1}{6}&x=6\n\\end{cases}$$\nand so\n$$\\E(X)\\;=\\;\\sum_{i=1}^6\nx_if(x_i)\\;=\\;\\frac{1}{6}+\\frac{2}{6}+\\frac{3}{6}+\\frac{4}{6}+\\frac{5}{6}+\\frac{6}{6}\\;=\\;3.5\\,.$$\nNow,\n$$\\E(X^2)\\;=\\;\\sum_{i=1}^6 x^2_if(x_i)\\;=\\;\\frac{1}{6}+\\frac{4}{6}+\\frac{9}{6}+\\frac{16}{6}+\\frac{25}{6}+\\frac{36}{6}\\;=\\;\\frac{91}{6}\\;=\\;15.1667$$\nand so  the variance is\n\\[V(X)\\; =\\; \\E(X^2) - (\\E(X))^2 \\;=\\; 15.1667-3.5^2\\;=\\;2.9167\\,.\\] \n  \n\\item The density function of the uniform distribution, $X$,  on $[0,8]$ is  $$f(x)=\\begin{cases}\\frac{1}{8}&0<x<8\\\\0&\\textrm{otherwise}\\end{cases}$$\nTherefore, $$\\E(X)\\;=\\;\\frac{8+0}{2}\\;=\\;4\\enspace,$$\nand $$\\V(X)\\;=\\;\\frac{(8-0)^2}{12}\\;=\\;\\frac{16}{3}$$\n\n\\item Since $f(x)$ is the density function of an $\\exponential(\\lambda)$ random variable with parameter $\\lambda=2$, we can use earlier results to get\n$$\\E(X)\\;=\\;\\frac{1}{2}\\quad \\text{and}\\quad\n\\V(X)\\;=\\;\\frac{1}{4}\\enspace.$$\n\n(You should also be able to do this by integration!)\n\\ee\n\n\\end{ExerciseList}\n\n", "meta": {"hexsha": "34e0e72d24579c207baafd3065dba64434fb6d84", "size": 4445, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInExpectations.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/ExsInExpectations.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/ExsInExpectations.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 33.171641791, "max_line_length": 150, "alphanum_fraction": 0.6038245219, "num_tokens": 1929, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934406, "lm_q2_score": 0.8723473713594992, "lm_q1q2_score": 0.759463232751051}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS622: Theory of Formal Languages\n% Copyright 2014 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 3}\n\nConsider the \\textit{dfa} $\\mathcal{M} = \\left( \\{a,b\\}, \\{q_0,q_1,q_2\\}, \\delta, q_0, \\{q_1\\} \\right) $ whose graph is given in Figure \\ref{fig:DR4}. Determine the language accepted by the automaton $\\mathcal{M}$.\n\n\\begin{figure}[H]\\centering\n\t\\begin{tikzpicture}[->, >=stealth', shorten >=1pt, auto, node distance=3cm, semithick]\n\t\t\\tikzstyle{final}=[circle,thick,draw=black,fill=gray!40,text=black]\n\t\t\\node[state, initial]\t(0) \t  \t\t\t\t{$q_0$};\n\t\t\\node[state] \t\t\t(2)\t[above right of=0]\t  \t{$q_2$};\n\t\t\\node[state, final]   (1) [below right of=2] \t  \t{$q_1$};\n\t\t\\path\n\t\t\t(0) edge [bend left]\tnode {b} (2)\n\t\t\t\tedge [bend right]\tnode {a} (1)\n\t\t\t(1) edge [loop right] \tnode {b} (1)\n\t\t\t\tedge [bend left]  \tnode {a} (2)\n\t\t\t(2) edge [bend left]  \tnode {b} (1)\n\t\t\t\tedge [loop above] \tnode {a} (2);\n\t\\end{tikzpicture}\n\t\\caption{Graph of the Deterministic Finite Automaton $\\mathcal{M}$}\n\t\\label{fig:DR4}\n\\end{figure}\n\n\\subsection*{Solution}\n\nBy definition, the language accepted by the given Deterministic Finite Automaton (\\textit{dfa}) is the set $ L \\left( \\mathcal{M} \\right) = \\{ x \\in \\{a\\}^*\\{b\\}^* | \\delta ^* \\left( q_0,x \\right) \\in \\{q1\\} \\}$.\nThe final state $q_1$ can be reached from initial state $q_0$ either directly or through $q_2$.\nFinal state can be reached directly from state $q_0$ using the symbol $a$ or indirectly by state $q_1$ using words of the form $b\\{a\\}^*b$.\nOnce $q_1$ is reached, we can stay in $q_1$ by any arbitrary number of $b$ and/or any arbitrary number of loops of the form $a\\{a\\}^*b$.\nTherefore, the language $L(\\mathcal{M})$ accepted by the \\textit{dfa} $\\mathcal{M}$ would be\n\n\\begin{equation}\n\tL(\\mathcal{M}) = \\{a \\cup b\\{a\\}^*b\\}\\{b\\}^*\\{a\\{a\\}^*b\\}^*\\{b\\}^*\n\\end{equation}\n", "meta": {"hexsha": "1084bdae0d563e02ad7ae1860fe17b0ef7fd301a", "size": 2095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs622-2015f/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-cs622-2015f/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-cs622-2015f/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": 51.0975609756, "max_line_length": 214, "alphanum_fraction": 0.6109785203, "num_tokens": 762, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473680407889, "lm_q2_score": 0.8705972566572503, "lm_q1q2_score": 0.7594632254684835}}
{"text": "%!TEX root = ceres-solver.tex\n\\chapter{Non-linear Least Squares}\n\\label{chapter:tutorial:nonlinsq}\nLet $x \\in \\reals^n$ be an $n$-dimensional vector of variables, and\n$F(x) = \\left[f_1(x); \\hdots ; f_k(x)\\right]$ be a vector of residuals $f_i(x)$. \nThe function $f_i(x)$ can be a scalar or a vector valued\nfunction.  Then, \n\\begin{equation}\n\t\\arg \\min_x \\frac{1}{2} \\sum_{i=1}^k \\|f_i(x)\\|^2.\n\\end{equation}\nis a Non-linear least squares problem~\\footnote{Ceres can solve a more general version of this problem, but for pedagogical reasons, we will restrict ourselves to this class of problems for now. See section~\\ref{chapter:overview} for a full description of the problems that Ceres can solve}. Here $\\|\\cdot\\|$ denotes the Euclidean norm of a vector. \n\nSuch optimization problems arise in almost every area of science and engineering. Whenever there is data to be analyzed, curves to be fitted, there is usually a linear or a non-linear least squares problem lurking in there somewhere. \n\nPerhaps the simplest example of such a problem is the problem of Ordinary Linear Regression, where given observations $(x_1,y_1),\\hdots, (x_k,y_k)$, we wish to find the line $y = mx + c$, that best explains $y$ as a function of $x$. One way to solve this problem is to find the solution to the following optimization problem\n\\begin{equation}\n\t\t\\arg\\min_{m,c} \\sum_{i=1}^k (y_i - m x_i - c)^2.\n\\end{equation}\nWith a little bit of calculus, this problem can be solved easily by hand. But what if, instead of a line we were interested in a more complicated relationship between $x$ and $y$, say for example $y = e^{mx + c}$. Then the optimization problem becomes\n\\begin{equation}\n\t\t\\arg\\min_{m,c} \\sum_{i=1}^k \\left(y_i - e^{m x_i + c}\\right)^2.\n\\end{equation}\nThis is a  non-linear regression problem and solving it by hand is much more tedious.  Ceres is designed to help you model and solve problems like this easily and efficiently.", "meta": {"hexsha": "02d6b9e476df98c11d840843ba41526e82040a87", "size": 1928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/nnlsq.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/nnlsq.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/nnlsq.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.8260869565, "max_line_length": 349, "alphanum_fraction": 0.7406639004, "num_tokens": 546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772384450967, "lm_q2_score": 0.8688267779364222, "lm_q1q2_score": 0.7594217107458191}}
{"text": "\\section{Linear Maps and Matrices}\r\nThe set of linear maps from $V$ to $W$ is a vector space over the same field $F$.\r\n\\begin{definition}\r\n    Let $V,W$ be vector spaces over $F$.\r\n    We define\r\n    $$L(V,W)=\\{\\alpha:V\\to W\\text{, linear}\\}$$\r\n    to be the vector space of linear maps from $V$ to $W$ under the operations $(\\alpha+\\beta)(v)=\\alpha(v)+\\beta(v)$ and $(\\lambda\\alpha)(v)=\\lambda\\alpha(v)$.\r\n\\end{definition}\r\nIt is easy to verify that this is indeed a vector space.\r\nThere is a very important theorem\r\n\\begin{proposition}\\label{linear_map_matrices}\r\n    If $V,W$ are finite dimensional, so is $L(V,W)$ and we have $\\dim L(V,W)=(\\dim V)(\\dim W)$.\r\n\\end{proposition}\r\n\\begin{definition}\r\n    An $m\\times n$ matrix over $F$ is an array with $m$ rows and $n$ columns with entries in $F$.\r\n    As a convention, for a matrix $A$ we write $A=(a_{ij})_{1\\le i\\le m,1\\le j\\le n}=(A_{ij})_{1\\le i\\le m,1\\le j\\le n}$ where $i$ refers to the row number and $j$ the column number.\r\n    We write $M_{m,n}(F)$ to denote the set of $m\\times n$ matrices over $F$.\r\n\\end{definition}\r\nNote that we can (and often) identify vectors in $\\mathbb R^m$ as $m\\times 1$ matrices.\r\n\\begin{proposition}\r\n    $M_{m,n}(F)$ is a vector space over $F$ under $(a_{ij})+(b_{ij})=(a_{ij}+b_{ij})$ and $\\lambda(a_{ij})=(\\lambda a_{ij})$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    $\\dim M_{m,n}(F)=mn$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    The set $\\{(\\delta_{ia}\\delta_{jb}):1\\le a\\le m,1\\le b\\le n\\}$ with size $mn$ is a basis of $M_{m,n}(F)$.\r\n\\end{proof}\r\nWe want to represent linear maps by matrices.\r\nFor $V,W$ vector spaces over $F$ of finite dimensions $n,m$, we choose ordered bases $B=(v_1,\\ldots,v_n),C=(w_1,\\ldots,w_m)$ for $V,W$ respectively.\r\nFor $v\\in V$, its coordinate under $B$ is $[v]_B=(v_1,\\ldots,v_n)$ where $v=\\sum_{i}v_ib_i$ is the unique decomposition of $v$ in this basis.\r\nSimilarly, the coordinate of $w\\in W$ under $C$ is $[w]_C=(w_1,\\ldots,w_m)$ where $w=\\sum_{i}w_ic_i$ is the unique decomposition of $w$ under $C$.\r\n\\begin{definition}\r\n    The matrix of $\\alpha:V\\to W$ in the bases $B,C$ is the matrix\r\n    $$([\\alpha]_{B,C})_{ij}=(\\alpha(v_j))_i\\in M_{m\\times n}(F)$$\r\n\\end{definition}\r\nIf the bases are understood, we often write $([\\alpha]_{B,C})_{ij}$ as $\\alpha_{ij}$.\r\n\\begin{definition}\r\n    For matrices $M\\in M_{m\\times n}(F)$ and $N\\in M_{n\\times l}(F)$, their matrix product is the $m\\times l$ matrix defined by $(MN)_{ij}=(\\sum_kM_{ik}N_{kj})_{ij}$.\r\n\\end{definition}\r\nThe particular case where $N$ is a column vector exhibits how $m\\times n$ matrices induce linear maps $F^n\\to F^m$.\r\n\\begin{lemma}\r\n    For any $v\\in V$,\r\n    $$[\\alpha(v)]_C=[\\alpha]_{B,C}[v]_B$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Linearity.\r\n\\end{proof}\r\nWe already know that composition of linear maps is linear, what's more is\r\n\\begin{lemma}\r\n    Let $U,V,W$ be finite dimensional vector spaces over $F$ with chosen bases $A,B,C$ respectively.\r\n    Let $\\beta:U\\to V$ and $\\alpha:V\\to W$ be linear maps, then\r\n    $$[\\alpha\\circ\\beta]_{A,C}=[\\alpha]_{B,C}[\\beta]_{A,B}$$\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Linearity again.\r\n\\end{proof}\r\n\\begin{proposition}\r\n    We have $L(V,W)\\cong M_{m\\times n}(F)$ via $\\alpha\\mapsto[\\alpha]_{B,C}$ where $B$ is a basis of $V$ and $C$ is a basis of $W$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Just check.\r\n\\end{proof}\r\n\\begin{proof}[Proof of Proposition \\ref{linear_map_matrices}]\r\n    Simple corollary of the preceding proposition.\r\n\\end{proof}\r\n\\begin{remark}\r\n    Let $\\alpha:V\\to W$ be linear.\r\n    The diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            V\\arrow{r}{\\alpha}\\arrow[swap]{d}{v\\mapsto [v]_B}&W\\arrow{d}{w\\mapsto [w]_C}\\\\\r\n            F^n\\arrow[swap]{r}{[\\alpha]_{B,C}}&F^m\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{remark}\r\n\\begin{example}\r\n    Let $\\alpha:V\\to W$ be linear and $Y\\le V$ a subspace.\r\n    Let $B$ be a basis of $V$ extending a basis $B'$ of $Y$ and $C$ a basis of $W$ extending a basis $C'$ of $Z\\ge\\alpha(Y)$.\r\n    Then the entries of $[\\alpha]_{B,C}$ that are relevant to $B'\\subset B,C'\\subset C$ are exactly $[\\alpha|_{Y\\to Z}]_{B',C'}$.\r\n    So if we rearrange the bases so that $B'$ are in the front of $B$ and $C'$ in the front of $C$, then the matrix will look like\r\n    $$[\\alpha]_{B,C}=\\left(\\begin{array}{c|c}\r\n        [\\alpha|_{Y\\to Z}]_{B',C'}&\\ast\\\\\r\n        \\hline\r\n        0&\\ast\r\n    \\end{array}\\right)$$\r\n\\end{example}\r\n\\begin{proposition}\r\n    Let $\\alpha:V\\to W$ be linear and $\\alpha(Y)\\le Z\\le W$, then $\\alpha$ induces a map $\\bar\\alpha:V/Y\\to W/Z$ via $v+Y\\mapsto\\alpha(v)+Z$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}", "meta": {"hexsha": "d43469efccea046201d425238ba9e8d1be153687", "size": 4680, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/matrix.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": "5/matrix.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": "5/matrix.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": 48.2474226804, "max_line_length": 183, "alphanum_fraction": 0.6275641026, "num_tokens": 1647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.868826769445233, "lm_q2_score": 0.8740772384450967, "lm_q1q2_score": 0.7594217033238639}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Maximum subsequence}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Maximum subsequence}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Maximum subsequence}\n\n\\vspace{10 mm}\n\\begin{problem}\nGiven a sequence  of integer numbers $x_0, x_1, \\dots, x_{N-1}$ (not necessarily positive) find a subsequence $x_i,\\dots,x_{j - 1}$ such that the sum of numbers in it is maximum over all subsequences of consecutive elements.\n\\end{problem}\n\nWe adopt the same notation used in \\textit{Programming in the 1990s} \\cite{Cohen90} and \\textit{Programming, The Derivation of Algorithms}\\cite{Kaldewaij90}: The notation of function application is the \"dot\" notation with name of function, followed by arguments, each separated by a dot. The notation of quantified expressions has the operator followed by the bounded variables, then a colon followed by the range for the bounded variables and ended with a colon and the actual expression. So\n\n\\begin{equation*}\t \n\t(\\sum k : i \\leq k < j : x_k)\n\\end{equation*}\n\n\\noindent corresponds to the more classical mathematical notation $\\sum_{k = i}^{ j - 1}x_k$. \n\n\\noindent For our derivation steps in predicate calculus we will use the following notation:\n\n\\begin{equation*}\n\\begin{array}{lcl}\n\t\t&&A \\\\\n\t      &=& \\{  \\mbox{reason why A equals B} \\} \\\\      \n                  &&B \\\\\n                &\\leq& \\{ \\mbox{reason why B is less than C} \\} \\\\\n                  && C  \n   \\end{array}\n\\end{equation*}\n\nIf all the numbers are positive then the maximum sum is the sum of the whole initial sequence. If all the numbers are negative then the maximum sum is 0 (by definition 0 is the sum over an empty range). So the interesting case is a sequence with positive and negative numbers in it.\n\nWe hope to find an algorithm that visits every number in the sequence only once, so with runtime $O(n)$. Let's introduce some notation:\nLet's introduce some notation\\footnote{Our problem can be stated as finding $f.N$ given $x_i \\in \\mathbb{Z}, 0 \\leq i < N, N \\in \\mathbb{N}$.}\n:\n\n\\[\n\tf.n = (MAX i, j : 0 \\leq i \\leq j \\leq n : s.i.j) \n\\]\nwith \n\\[\t \n\ts.i.j = (\\sum k : i \\leq k < j : x_k).\n\\]\n\nWe will use properties of quantified expressions as covered in Chapter 3 of \\textit{Programming in the 1990s}\\cite{Cohen90}.\n\n\\[\n\\begin{array}{lcl}\n\t\t&&f.N \\\\\n\t      &=& { < \\mbox{definition of f } >} \\\\      \n                  && (MAX i, j : 0 \\leq i \\leq j \\leq N : s.i.j)\\\\\n                &=& { < \\mbox{range nesting} >} \\\\\n                  && (MAX j : 0 \\leq j \\leq N : (MAX i:  0 \\leq i \\leq j : s.i.j)) \\\\\n                &=& { < \\mbox{defining}\\  p.j =  (MAX i:  0 \\leq i \\leq j : s.i.j) >} \\\\ \n                   && (MAX j : 0 \\leq j \\leq N : p.j) \\\\\n                &=& { < \\mbox{range split, 1-point rule} >} \\\\\n                \t && (MAX j : 0 \\leq j < N : p.j) \\ max \\ p.N \\\\\n\t       &=& { < \\mbox{definition of f } >} \\\\\n\t       \t&& f.(N - 1) \\ max \\ p.N \t   \n   \\end{array}\n\\]\n\nWe now have a recursive expression for $f$, which still depends on a newly introduced function p. Let's see if we can get a recursive expression for p too:\n\n\\[\n\\begin{array}{lcl}\n\t\t&&p.N \\\\\n\t\t&=& { < \\mbox{definition of p } >} \\\\\n\t\t && (MAX i:  0 \\leq i \\leq N : s.i.N) \\\\\n\t\t &=& { < \\mbox{range split, 1-point rule} >} \\\\\n\t\t && (MAX i:  0 \\leq i < N : s.i.N)\\ max \\ s.N.N \\\\\n\t\t &=& { < \\mbox{definition of s and s.N.N = 0 by definition of sum over empty range} >} \\\\\n\t\t && (MAX i:  0 \\leq i < N : (\\sum k : i \\leq k < N : x_k))\\ max \\ 0 \\\\\n\t\t &=& { < \\mbox{range split in sum} >} \\\\\n\t\t && (MAX i:  0 \\leq i < N : (\\sum k : i \\leq k < N - 1 : x_k) + x_{N - 1})\\ max \\ 0 \\\\\n\t\t &=& { < \\mbox{+ distributes over max} >} \\\\\n\t\t && (x_{N - 1} + (MAX i:  0 \\leq i < N : (\\sum k : i \\leq k < N - 1 : x_k))\\ max \\ 0 \\\\\n\t\t &=& { < \\mbox{definition of p } >} \\\\\n\t\t && (x_{N - 1} + p.(N - 1))\\ max \\ 0\n   \\end{array}\n\\]\n\nSo $f.N = f.(N - 1)\\ max\\ p.N$ and $p.N = (x_{N - 1} + p.(N - 1))\\ max\\ 0$. The base cases are $f.0 = 0$ and $p.0 = 0$.\n\nArmed with these recursive relations we can provide a Haskell program that solves the problem:\n\n\\lstinputlisting[language=Haskell, basicstyle=\\small, frame=trBL, caption={Haskell code}]{maxSum.hs}\n\nThe maxSum function calculates the tuple $(f.N, p.N)$.\n\n\\bibliographystyle{plainnat}\n\\bibliography{../common/math}\n\n\\end{document}\n\n", "meta": {"hexsha": "4c2fe334b0476e1621a9beefe079ea69a977be09", "size": 4343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maxsum/maxsum.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": "maxsum/maxsum.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": "maxsum/maxsum.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": 42.5784313725, "max_line_length": 492, "alphanum_fraction": 0.5963619618, "num_tokens": 1447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.828938820999257, "lm_q2_score": 0.916109606718245, "lm_q1q2_score": 0.7593988172991151}}
{"text": "\n\\subsection{Depth-first search}\n\nA depth-first search operates Last-in First-out (LiFo). That is, it selects the newest frontier node. This results in a deep, rather than a broad search. Once the maximum depth has been reached, the algorithm will move towards breadth. Path cost is not considered in this algorithm.\n\nMay not find optimal solution, but is linear in space\n\nInformed: No\n\nTime: \\(O(b^m)\\)\n\nSpace: \\(O(bm)\\)\n\nComplete: Yes\n\nOptimal: No\n\n", "meta": {"hexsha": "ac17f83d02ea723b53280d9d04ee0d6c8bfc6be6", "size": 451, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/nodes/02-02-DFS.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-02-DFS.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-02-DFS.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.0555555556, "max_line_length": 282, "alphanum_fraction": 0.7494456763, "num_tokens": 110, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952866333484, "lm_q2_score": 0.845942439250491, "lm_q1q2_score": 0.7593985404782834}}
{"text": "\\documentclass[10pt,a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb} % Proper number set rendering\n\\usepackage{mathtools}\n\n\\title{Differentiating the \\textbf{tangent} function}\n\\author{Michal Špano}\n\\date{March 2022}\n\n\\begin{document}\n\n\\maketitle\n\n% \\section{Total area of a graph}\n% $S_T = \\sum \\int x f(x), x \\in D(f) \\subset \\mathbb{R}$ - denotes the total area of the graph as $S_T$.\n\n\\section{The first derivative of the tangent function}\n\nLet $f$ be $f = tan(x)$. Then differentiate $f(x)$ with the respect to $x$, such that $f'(x)$: \\\\\n\n$f'(x) = \\Bigg [ \\dfrac{sin(x)}{cos(x)} \\Bigg ] ' =\n\\dfrac{[sin(x)]'cos(x) - [cos(x)]'sin(x)}{cos^{2}(x)} =\n\\dfrac{cos^{2}(x) + sin^{2}(x)}{cos^{2}(x)} =$ \n$\\dfrac{1}{cos^{2}(x)} = sec^{2}(x)$, $\\implies f'(x)=sec^{2}(x)$, where:\n\n $\\forall x \\in \\mathbb{R}: sin^{2}(x) + cos^{2}(x) = 1 \n \\land \\dfrac{1}{cos(x)} = sec(x) \n \\land \\dfrac{sin(x)}{cos(x)} = tan(x)$. \n \n The proposed steps are based on the principle of the \\textbf{Quotient rule} (and shall be used in the consecutive sections) which states:\n\\[\nf'(x) = \\dfrac{P(x)}{Q(x)} = \\dfrac{P'(x)Q(x)-Q'(x)P(x)}{Q^{2}(x)}.\n\\]\n\n\\section{The second derivative of the tangent function}\nDifferentiate $f(x)$ with the respect to $x$, such that $f''(x)$: \\\\\n\n$f''(x) = [sec^{2}(x)]' = \n\\Big[ \\dfrac{1}{cos^{2}(x)} \\Big]' = \n\\dfrac{0-(-2sin(x)cos(x))}{cos^{4}(x)} = \n\\dfrac{2sin(x)cos(x)}{cos^{4}(x)} = $\n\n$2 \\Bigg( \\dfrac{sin(x)}{cos(x)} \\dfrac{1}{cos^{2}(x)} \\Bigg) = \n2 tan(x) sec^{2}(x)$, $\\implies f''(x) = \n2 tan(x) sec^{2}(x)$\n\nThe proposed steps are based on the principle of the \\textbf{Product rule} (and shall be used in the consecutive section) which states:\n\\[\nf'(x) = P(x) Q(x) = P'(x) Q(x) + Q'(x) P(x).\n\\]\n\n\\section{The third derivative of the tangent function}\nDifferentiate $f(x)$ with the respect to $x$, such that $f'''(x)$: \\\\\n\n$f'''(x) = \\big[ 2 tan(x) sec^{2}(x) \\big]' = \n2 \\big[tan(x) sec^{2}(x) \\big]' = \n2 \\big[[tan(x)]'sec^{2}(x) + [sec^{2}(x)]'tan(x) \\big] =$\n\n$2 \\big[ sec^4(x) + 2 tan^{2}(x) sec^{2}(x) \\big] =\n2 \\Big[ sec^{2}(x) \\big[ sec^{2}(x) + 2 tan^{2}(x) \\big] \\Big] = \n2 sec^{2}(x) \\big[ sec^{2}(x) + 2 tan^{2}(x) \\big]$, $\\implies f'''(x) = 2 sec^{2}(x) \\big[ sec^{2}(x) + 2 tan^{2}(x) \\big]$\n\n\\end{document}\n", "meta": {"hexsha": "f843b8037ef2352d61d87e1aeb96900c7a26808a", "size": 2258, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study-materials/Mathematics/tangent-differentiation/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/tangent-differentiation/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/tangent-differentiation/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": 35.28125, "max_line_length": 138, "alphanum_fraction": 0.5779450841, "num_tokens": 928, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765257642905, "lm_q2_score": 0.831143045767024, "lm_q1q2_score": 0.7593958904695652}}
{"text": "% Lin will add things here.\n\\section{I.E. Lagaris, A. Likas and D.I.Fotiadis's Works 1997}\n\nArtificial Neural Networks for Solving Ordinary and Partial Differential Equations\n\nThey present a method to solve initial and boundary value problems using artificial neural networks. A trial solution of the differential equation is written as a sum of two parts. The applicability of this approach ranges from single ODE's, to systems of coupled ODE's and also to PDE's. \n\nUse neural networks for solving the differential equation\n\\begin{equation}\nG(\\vec x,\\Psi(\\vec x),\\nabla \\Psi(\\vec x),\\nabla^2 \\Psi(\\vec x)) = 0,\\quad \\vec x\\in D\n\\end{equation}\nsubject to certain boundary conditions, where $\\vec x = (x_1,x_2,...,x_n)\\in R^n, D\\subset R^n$. $\\Psi(\\vec x)$ is the solution to be computed. \n\nAssumes a discretization of the domain $D$ and its boundary $S$ into a set points $\\hat D$ and $\\hat S$ respectively. The problem is then transformed into the following system:\n\\begin{equation}\nG(\\vec x_i,\\Psi(\\vec x_i),\\nabla \\Psi(\\vec x_i),\\nabla^2 \\Psi(\\vec x_i)) = 0,\\quad\\forall \\vec x_i\\in \\hat D\n\\end{equation}\nsubject to the constraints imposed by the B.Cs.\n\nIf $\\Psi_t(\\vec x,\\vec p)$ donotes a trial solution with parameters $\\vec p$, the problem is transformed to:\n\\begin{equation}\n\\min_{\\vec p} \\sum_{\\vec x_i\\in \\hat D} G(\\vec x_i,\\Psi(\\vec x_i),\\nabla \\Psi(\\vec x_i),\\nabla^2 \\Psi(\\vec x_i)) ^2\n\\end{equation} \nsubject to the constraints imposed by the B.Cs.\n\nChoose a form for the trial function $\\Psi_t(\\vec x)$. This is achieved by\n\\begin{equation}\n \\Psi_t(\\vec x) = A(\\vec x) + F(\\vec x, N(\\vec x,\\vec p))\n\\end{equation} \nwhere $N(\\vec x,\\vec p)$ is a single-output feedforward neural network with parameters $\\vec p$ and $n$ input units fed with the input vector $\\vec x$.\n\nConsider a multilayer perceptron with $n$ input units, one hidden layer with $H$ sigmoid units and a linear output unit. For a given input vector $\\vec x = (x_1,x_2,...,x_n)$ the output of the network is \n\\begin{equation}\nN = \\sum_{i=1}^H v_i\\sigma(z_i)\n\\end{equation}\nwhere $z_i = \\sum_{j = 1}^n w_{ij}x_j+u_i$, $w_{ij}$ denotes the weight from the input unit $j$ to the hidden unit $i$, $v_i$ denotes the weight from the hidden unit $i$ to the output, $u_i$ denotes the bias of hidden unit $i$ and $\\sigma(z)$ is the sigmoid transfer function.\n\nIn their experiments, they use BFGS method to solve all examples.\n\n\\section{Modjtaba Baymani, Asghar Kerayechian, Sohrab Effati's Work 2010}\nThey transform the mixed Stokes problem into three independent Poisson problems which by solving them the solution of the Stokes problem is obtained. \n\nThe incompressible fluids stocks equations are\n\\begin{equation}\n\\left\\{\n \\begin{split}\n  -\\Delta u_1 + \\frac{\\partial p}{\\partial x} = f_1 &\\quad \\mbox{in}\\ \\Omega\\\\\n  -\\Delta u_2 + \\frac{\\partial p}{\\partial y} = f_2 &\\quad \\mbox{in}\\ \\Omega \\\\\n  \\frac{\\partial u_1}{\\partial x} + \\frac{\\partial u_2}{\\partial y} = 0&\\quad \\mbox{in}\\ \\Omega \n \\end{split}\\right.\n\\end{equation} \n\nTo solve the problem with $\\Omega = [0,1]\\times [0,1]$, they apply the operators $\\frac{\\partial}{\\partial x}$ and $\\frac{\\partial}{\\partial y}$ on the first and second equations respectively. Then\n\\begin{equation}\n\\frac{\\partial p^2}{\\partial x^2}+\\frac{\\partial p^2}{\\partial y^2} = (f_1)_x+(f_2)_y\n\\end{equation}\n\nUse artificial neural network to get a trial solution $p_t$, by substituting the trial solution $p_t$ in the first and second equation\n\\begin{equation}\n \\left\\{\n \\begin{split}\n  \\Delta u_1 = \\frac{\\partial p_t}{\\partial x} - f_1\\\\\n  \\Delta u_2 = \\frac{\\partial p_t}{\\partial y} - f_2\\\\\n \\end{split}\\right.\n\\end{equation}\n\n\\section{Weinan E, Bing Yu's Work 2017}\n\nThey build a trial function space \n\\begin{equation}\n u(x;\\theta) = a\\cdot z_{\\theta}(x) + b \n\\end{equation}\nwhere $z_\\theta = f_n\\circ ...\\circ f_1(x)$, and the $f_i$ is defined as \n\\begin{equation}\nt = f_i(s) = \\phi(W_{i,2}\\cdot \\phi(W_{i,1}+b_{i,1})+b_{i,2}) + s\n\\end{equation}\nwhere $W_{i,1},W_{i,2}\\in R^{m\\times m},b_{i,1},b_{i,2}\\in R^m$. $\\phi$ is the activation function\n\\begin{equation}\n\\phi(x) = \\max\\{x^3,0\\}\n\\end{equation}\nTo finish describing the algorithm, they use the stochastic gradient descent algorithm.\n\nThey solve the Poisson equation\n\\begin{equation}\n \\begin{split}\n  -\\Delta u(x) = 1, &\\qquad x\\in \\Omega\\\\\n  u(x) = 0,&\\qquad x\\in \\partial \\Omega\n \\end{split}\n\\end{equation}\n\nThey minimize the functional\n\\begin{equation}\n I(u) = \\int_{\\Omega} (\\frac{1}{2}|\\nabla_x u(x)|^2-f(x)u(x))dx+\\beta\\int_{\\partial \\Omega} u^2(x)ds\n\\end{equation}\n\nThey solve the eigenvalue problems\n\\begin{equation}\n \\begin{split}\n  - \\Delta u + v\\cdot u = \\lambda u,& \\qquad x\\in \\Omega\\\\\n  u = 0 & \\qquad x \\in \\partial \\Omega\n \\end{split}\n\\end{equation}\nThey  minimize the\n\\begin{equation}\n L(u(x,\\theta)) = \\frac{\\int_\\Omega |\\nabla u|^2dx+\\int_\\Omega vu^2dx}{\\int_\\Omega u^2dx} + \\beta\\int_{\\partial \\Omega u^2(x)dx} + \\gamma(\\int_{\\Omega}u^2 - 1)^2\n\\end{equation}\n\n\\section{Pratik Chaudhari, Adam Oberman, Stanley Osher, Stefano Soatto, Guillaume Carlier's Work 2017 }\nThey solve the viscous Hamilton-Jacobi PDE\n\\begin{equation}\n \\frac{\\partial u}{\\partial t} = -\\frac{1}{2}|\\nabla u|^2 + \\frac{\\beta^{-1}}{2}\\Delta u, \\qquad \\mbox{for} \\quad 0<t\\le \\gamma\n\\end{equation}\nTheir starting point point is the continuous time stochastic gradient descent equation\n\\begin{equation}\n dx(t) = -\\nabla f(x(t))dt +  \\beta^{-\\frac{1}{2}}dW(t)\n\\end{equation}\n\nThey define the neural network\n\\begin{equation}\n y(x;\\xi) = \\sigma'(x^{p}\\sigma(x^{p-1}...\\sigma(x^2\\xi))...)\n\\end{equation}\nwhere $x^1,...,x^{p-1}\\in R^{d\\times d}$ and $x^p\\in R^{d\\times K}$. $\\sigma(z) = \\max(0,z)$ and the last non-linearity is set to $\\sigma'(z) = 1_{z\\ge0}$.\nThey minimize the empirical loss\n\\begin{equation}\n f(x):=\\frac{1}{N}\\sum_{i=1}^{N}f_i(x)\n\\end{equation}\nwhere $f_i$ is\n\\begin{equation}\n f_i(x):=1_{\\{y(x,\\xi^i)\\neq y^i\\}}\n\\end{equation}\n\nThey use the SGD method.\n\n", "meta": {"hexsha": "4e08761e5a5b51f827aa62db0e1706ffb3515820", "size": 5930, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DL-PDE.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-PDE.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-PDE.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.2537313433, "max_line_length": 289, "alphanum_fraction": 0.6922428331, "num_tokens": 2056, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625012602593, "lm_q2_score": 0.8152324938410784, "lm_q1q2_score": 0.7593584978218498}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\arctan n}{n^2+1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\nThe function $f(x)=\\frac{\\arctan x}{x^2+1}$ is continuous, positive, and decreasing. We find the following indefinite integral using the substitution $u = \\arctan x$, so $du = \\frac1{x^2+1}\\,dx$:\r\n\\begin{align*}\r\n\\int \\frac{\\arctan x}{x^2+1}\\,dx\r\n&= \\int u \\,du\\\\\r\n&= \\frac12u^2 + C \\\\\r\n&= \\frac12(\\arctan x)^2+C\r\n\\end{align*}\r\nSo the definite, improper integral evaluates:\r\n\\begin{align*}\r\n\\int_2^\\infty \\frac{\\arctan x}{x^2+1}\\,dx\r\n&= \\lim_{t \\to \\infty} \\int_2^t \\frac{\\arctan x}{x^2+1}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty} \\left(  \\frac12(\\arctan t)^2 -   \\frac12(\\arctan 2)^2 \\right)\\\\\r\n&= \\left(  \\frac12 \\left( \\frac{\\pi}{2} \\right)^2 -   \\frac12(\\arctan 2)^2 \\right)\\\\\r\n\\end{align*}\r\nwhich converges. Since the integral $\\displaystyle \\int_2^\\infty \\frac{\\arctan x}{x^2+1}\\,dx$ converges, the series $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\arctan n}{n^2+1}$ converges.\r\nSince all terms of the series are positive, the series  $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\arctan n}{n^2+1}$ converges absolutely.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nNote that $\\arctan n \\leq \\frac{\\pi}{2}$ for all positive $n$. In fact, since $\\pi$ is just a little bigger than three and we divide by $2$, we could just state\r\n\\[ \\arctan n \\leq 1.6\\]\r\nBy dividing both sides by $n^2+1$, we have\r\n\\[ \\frac{\\arctan n}{n^2+1} \\leq \\frac{1.6}{n^2+1}\\]\r\nand in fact, we also have\r\n\\[ \\frac{\\arctan n}{n^2+1} \\leq \\frac{1.6}{n^2+1} \\leq \\frac{1.6}{n^2}\\]\r\nso taking the outside two expressions (and skipping the expression in the middle), we have\r\n\\[ \\frac{\\arctan n}{n^2+1} \\leq \\frac{1.6}{n^2}\\]\r\n\r\nSince the series $\\sum \\frac{1.6}{n^2} = 1.6 \\sum \\frac1{n^2}$ converges by the $p$-test, the series $\\sum \\frac{\\arctan n}{n^2+1}$ converges by the Direct Comparison Test.\r\nSince all terms of the series are positive, the series  $\\displaystyle \\sum_{n=2}^\\infty \\frac{\\arctan n}{n^2+1}$ converges absolutely.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\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": "c0e670b16e878da75197bdca4d1060073e205587", "size": 2935, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/h7.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/h7.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/h7.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": 40.2054794521, "max_line_length": 196, "alphanum_fraction": 0.6395229983, "num_tokens": 1113, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357666736772, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.7593386499627315}}
{"text": "\\section{First Order Differential Equations}\\label{sec:first order differential equations}\nWe start by considering equations in which only the first derivative\nof the function appears. \n\n\\begin{definition}{First Order Differential Equation}{First Order Differential Equation}\\label{First Order Differential Equation}\nA \\deffont{first order differential equation} is an equation of\nthe form $F(t, y, y')=0$.\nA solution of a first order differential equation is a\nfunction $f(t)$ that makes $\\ds F(t,f(t),f'(t))=0$ for every value of $t$.\n\\end{definition}\n\nHere, $F$ is a function of three\nvariables which we label $t$, $y$, and $y'$. It is understood\nthat $y' $ will explicitly appear in the equation although $t$\nand $y$ need not. The term ``first order'' means that the first\nderivative of $y$ appears, but no higher order derivatives do.\n\n\\begin{example}{Newton's Law of Cooling}{Newton's Law of Cooling}\\label{Newton's Law of Cooling}\n The equation from Newton's law of cooling,\n$y'=k(y-T)$ is a first order\ndifferential equation; $F(t,y,y')=k(y-T)-y'$.\n\\end{example}\n\n\\begin{example}{A First Order Differential Equation}{A First Order Differential Equation}\\label{A First Order Differential Equation}\n $\\ds y'=t^2+1$ is a first order differential\nequation; $\\ds F(t,y,y')= y'-t^2-1$. All solutions to this\nequation are of the form $\\ds t^3/3+t+C$. \n\\end{example}\n\n\\begin{definition}{First Order Initial Value Problem}{First Order Initial Value Problem}\\label{First Order Initial Value Problem}\nA \\deffont{first order initial value problem} is a system of\nequations of the form\n$F(t, y, y')=0$, $y(t_0)=y_0$. Here $t_0 $ is a fixed time\nand $y_0$ is a number.\nA solution of an initial value problem is a solution $f(t)$ of\nthe differential equation that also satisfies the \n\\deffont{initial condition} $f(t_0) = y_0$.\n\\end{definition}\n\n\\begin{example}{An Initial Value Problem}{An Initial Value Problem}\\label{An Initial Value Problem}\nVerify that the initial value problem $\\ds y'=t^2+1$, $y(1)=4$\nhas solution $\\ds f(t)=t^3/3+t+8/3$.\n\\end{example}\n\n\\begin{solution}\nObserve that $f'(t)=t^2+1$ and $f(1)=1^3/2+1+8/3=4$ as required.\n\\end{solution}\n\nThe general first order equation is too general, so\nwe can't describe methods that will work on them all, or even a large\nportion of them. We can make progress with specific kinds of\nfirst order differential equations.\nFor example, much can be said about equations of the form\n$\\ds y' = \\phi (t, y)$ where $\\phi $\nis a function of the two variables $t$ and $y$.\nUnder reasonable conditions on $\\phi$, such an\nequation has a solution and the corresponding \ninitial value problem has a unique solution.\nHowever, in general, these equations can be very difficult or\nimpossible to solve explicitly.\n\nA special case for which we do have a well defined method is that of separable differential equations.\n\n\\subsection{Separable Differential Equations}\n\n\n\n\n\\begin{definition}{Separable Differential Equations}{Separable Differential Equations}\\label{Separable Differential Equations}\nA first order differential equation is \n\\deffont{separable} if it can be written in the form\n$$y' = f(t) g(y) \\;\\;\\text{ or, }\\;\\;\\frac{dy}{dt} = f(t) g(y).$$\n\\end{definition}\n\nFor example, the differential equation \n\\[\n  \\frac{\\; d y}{\\; d x} = \\sin(x) \\bigl(1+y^2\\bigr)\n\\]\nis separable, and one has $F(x) = \\sin x$ and $G(y) = 1+y^2$.\nOn the other hand, the differential equation\n\\[\n  \\frac{\\; d y}{\\; d x} = x+y\n\\]\nis not separable.\n\n\nThe general approach to separable equations is as follows:\n\nSuppose we wish to solve $y' =\nf(t) g(y) $ where $f$ and $g$ are continuous functions. If $g(a)=0$\nfor some $a$ then $y(t)=a$ is a constant solution of the equation,\nsince in this case $y' = 0 = f(t)g(a)$.  For example, $y'\n=y^2 -1$ has constant solutions $y(t)=1$ and $y(t)=-1$.\n\nSuch constant solutions to a differential equation are called \\textit{equilibrium solutions}. To find the nonconstant solutions, we divide by $g(y)$ to get\n\\begin{equation}\n  \\label{eq:separated}\n  \\frac{1}{ g(y)} \\frac{\\; d y}{\\; d t} = f(t). \n\\end{equation}\nNext find a function $H(y)$ whose derivative with respect to $y$ is\n\\begin{equation}\\label{eq:separable-3}\n  H'(y) = \\frac{1}{g(y)}\n  \\quad\\left(\\text{solution: } H(y) = \\int {\\frac{dy}{g(y)}}.\\right)\n\\end{equation}\nThen the chain rule implies that the left hand side in (\\ref{eq:separated}) can be written as\n\\[\n  \\frac{1}{ g(y)} \\frac{\\; d y}{\\; d t} = H'(y) \\frac{\\; d y}{\\; d t} =\n  \\frac{\\; d H(y)}{\\; d t}.\n\\]\nThus \\eqref{eq:separated} is equivalent with\n\\[\n\\frac{\\; d H(y)}{\\; d t} = f(t).\n\\]\nIn words: $H(y)$ is an antiderivative of $f(t)$, which means we can find $H(y)$\nby integrating $f(t)$:\n\\begin{equation}\n  \\label{eq:separable-solution}\n  H(y) = \\int f(t) dt +C. \n\\end{equation}\nOnce we have found the integral of $f(t)$ this gives us $y(t)$ in implicit form: the\nequation (\\ref{eq:separable-solution}) gives us $y(t)$ as an \\textit{implicit\n  function} of $t$.  To get $y(t)$ itself we must solve the equation\n(\\ref{eq:separable-solution}) for $y(t)$.\n\nA quick way of organizing the calculation goes like this:\n\\begin{quote}\n  To solve \\( \\ds \\frac{dy}{ dt} = f(t)g(y)\\) we first \\textit{separate the\n    variables},\n  \\[\n  \\frac{d y}{g(y)} = f(t)\\,d t,\n  \\]\n  and then integrate,\n  \\[\n  \\int\\frac{d y}{g(y)} = \\int f(t)\\, dt.\n  \\]\n  The result is an implicit equation for the solution $y$ with one undetermined\n  integration constant.\n\\end{quote}\n\nThis technique is called \\dfont{separation of variables}. \n\nAs we have seen so far, a differential equation typically has an infinite number of solutions. Such a solution is called a \\dfont{general solution}.  A corresponding initial value problem will give rise to just one\nsolution. Such a solution in which there are no unknown constants remaining is called a \\dfont{particular solution}.\n\n\n\\begin{example}{}{}\nFind all functions $y$ that are solutions to the differential equation \n$$\\frac{dy}{dt}= \\frac{t}{y^2}.$$\n\\end{example}\n\n\n\\begin{solution}\nWe begin by separating the variables and writing\n    $$\n    y^2 dy  = t\\; dt.\n    $$\nIntegrating both sides of the equation with respect to the independent\n    variable $t$ shows that\n    $$\n    \\int y^2\\frac{dy}{dt}~dt = \\int t~dt.\n    $$\nNext, we notice that the left-hand side allows us to change\n    the variable of antidifferentiation\\footnote{This is why we required that the left-hand side be written as a\n    product in which $dy/dt$ is one of the terms.} from $t$ to $y$.  In\n    particular,\n    $dy = \\frac{dy}{dt}~dt$, so we now have\n    $$\n    \\int y^2 ~dy = \\int t~dt.\n    $$\n   This most recent equation says that two families of antiderivatives are\n    equal to one another.  Therefore, when we find representative\n    antiderivatives of both sides, we know they must differ by\n    arbitrary constant $C$.  Antidifferentiating and including the integration constant $C$ on the right, we find that\n    $$\n    \\frac{y^3}{3} = \\frac{t^2}{2} + C.\n    $$\n    Again, note that it is not necessary to include an arbitrary constant on both sides \n    of the equation;  we know that $y^3/3$ and $t^2/2$ are in the same\n    family of antiderivatives and must therefore differ by a single\n    constant.\n\nFinally, we may now solve the last equation above for $y$ as a function of $t$, which gives\n    $$\n    y(t) = \\sqrt[3]{\\frac 32 \\thinspace t^2 + 3C}.\n    $$\n    Of course, the term $3C$ on the right-hand side represents\n    3 times an unknown constant.  It is, therefore, still an unknown\n    constant, which we will rewrite as $C$.  We thus conclude that the funtion\n    $$\n    y(t) = \\sqrt[3]{\\frac 32 \\thinspace t^2 + C}\n    $$\nis a solution to the original differential equation for any value of $C$.\n\\end{solution}\n\n\n\nNotice that because this solution depends on the arbitrary constant $C$, we have found an infinite family of\nsolutions.  This makes sense because we expect to find a unique solution that corresponds to any given\n initial value.\n\nFor example, if we want to solve the initial value problem\n$$\n  \\frac{dy}{dt} = \\frac{t}{y^2}, \\\n  y(0) = 2,\n$$\nwe know that the solution has the form $y(t) = \\sqrt[3]{\\frac32\\thinspace\n  t^2 + C}$ for some constant $C$.  We therefore must find the appropriate\nvalue for $C$ that gives the initial value $y(0)=2$.  Hence,\n$$\n  2 = y(0)  \\sqrt[3]{\\frac 32 \\thinspace 0^2 + C} = \\sqrt[3]{C},\n  $$\nwhich shows that $C = 2^3 = 8$.  The solution to the initial value problem is then\n$$\ny(t) = \\sqrt[3]{\\frac32\\thinspace t^2+8}.\n$$\n\n\n\n\n\n\\begin{example}{Solving an IVP}{Solving an IVP}\\label{Solving an IVP}\n Solve the IVP: $\\ds y' = 2t(25-y)$, $ y(0)= 20 $.\n\\end{example}\n \n\\begin{solution}\nWe begin by finding the general solution to the differential equation. \nThis is almost identical to the previous example. As before, $y(t)=25$\nis a solution. If $y\\not=25$,\n\\begin{eqnarray}\n\\int {1\\over 25-y}\\,dy &=& \\int 2t\\,dt\\cr\n(-1)\\ln|25-y| &=& t^2+C_0\\cr\n\\ln|25-y| &=& -t^2 - C_0 = -t^2 + C\\cr\n|25-y| &=& e^{-t^2+C}=e^{-t^2} e^C\\cr\ny-25 &=& \\pm\\, e^C e^{-t^2} \\cr\ny &=& 25 \\pm e^C e^{-t^2} =25+Ae^{-t^2}. \\label{eqn:solveIVP}\n\\end{eqnarray}\nAs before, all solutions are represented by $\\ds y=25+Ae^{-t^2}$,\nallowing $A$ to be zero.\n\nTo solve the IVP, we let $ y= 20$, and $ t=0 $ in Equation \\ref{eq:solveIVP} to get\n$$\n20=25+A\n$$\nwhich immediately gives $ A=-20 $. So the particular solution to the IVP is\n\\[\ny=25-20e^{-t^2}\n\\]\n\\end{solution}\n\n\nOne application often discussed when introducing Separable Equations is that of \\textbf{mixing problems}.\nA typical mixing problems involves: A tank of fixed capacity; a completely mixed solution of some substance in the tank; a solution of a certain concentration entering the tank at a (usually) fixed rate; the solution immediately becomes completely stirred; and the mixture leaves at the other end at a (usually fixed) rate. We illustrate with an example.\n\n\\begin{example}\nA tank contains 20 kg of salt dissolved in 5000 L of water.  Brine that contains 0.03 kg of salt per liter of water enters the tank at a rate of 25 L/min.  The solution is kept thoroughly mixed and drains from the tank at the same rate. {How much salt is in the tank after half an hour?}\n\\end{example}\n\n\n\\begin{solution}\nLet $y(t)$ denote the amount of salt (kg) in the tank after $t$ minutes.\n\n{Given: $y(0) =  {20.}$} {We want to know: $ {y(30).}$}\n\n \n\\[\n\\frac{d  y}{d t} = \\textrm{(rate in) $-$ (rate out)}%\n\\]\n\n\n\\[\n\\textrm{rate in} = \\textrm{( {concentration in})( {rate of volume in})}%\n=\\left( { {0.03\\; \\frac{\\textrm{kg}}{\\textrm{L}}}}\\right)\\left( { {25\\; \\frac{\\textrm{L}}{\\textrm{min}}}}\\right)%\n { = }  \n0.75\\;\\; \\frac{\\textrm{kg}}{\\textrm{min}}%\n\\]\n\n\\[\n\\textrm{rate out}%\n  = \\textrm{( {concentration out})( {rate of volume out})}%\n=\\left( { {\\frac{y(t)}{5000}\\; \\frac{\\textrm{kg}}{\\textrm{L}}}}\\right)\\left( { {25\\; \\frac{\\textrm{L}}{\\textrm{min}}}}\\right)%\n =\\frac{y(t)}{200} \\;\\; \\frac{\\textrm{kg}}{\\textrm{min}}%\n\\]\n\nTherefore we have \n\n\\[\n\\frac{dy}{dt}= \\frac{150 - y(t)}{200} \n\\]\n\nSeparating variables we get\n\n\\[\n\\int \\frac{1}{150-y} \\; dy =\\int \\frac{1}{200}\\; dt \n\\]\n\nwhich gives\n\n\\[\n-\\ln |150 - y| = t /200 {+ C}%\n\\]\n $ y(0) = 20 $,  so   $ C = {-\\ln 130} $. Also observe that since $ y<150 (= 0.3\\cdot 5000)$, so $ |150-y|=150-y$,  so after simplification we get\n\n\n\\[\ny=150 - 130e^{-t/200}\n\\]\n\nand therefore $ y(30)=150 - 130e^{-30/200} \\approx 38.1 $kg.\n\\end{solution}\n\n\n\n\n\n\n\n\n\\begin{example}{}{}\nSolve the differential equation\n$$\\frac{dy}{dt} =3y.$$\n\\end{example}\n\n\n\\begin{solution}\nFollowing the same strategy as in Example~\\ref{Ex:7.4.1}, we have\n$$  \\frac 1y \\frac{dy}{dt} = 3. $$\nIntegrating both sides with respect to $t$,\n$$  \\int \\frac 1y\\frac{dy}{dt}~dt = \\int 3~dt,$$\nand thus \n$$ \\int \\frac 1y~dy =  \\int 3~dt.$$\nAntidifferentiating and including the integration constant, we find that\n$$  \\ln|y| = 3t + C_1$$\nwhere $ C_1 $ is an arbitrary constant. Finally, we need to solve for $y$.  Here, one point deserves careful\nattention.  By the definition of the natural logarithm function, it follows that\n$$\n|y| = e^{3t+C_1} = e^{3t}e^{C_1}.\n$$\nSince $C$ is an unknown constant, $e^C$ is as well, though we do know\nthat it is positive (because $e^x$ is positive for any $x$).\nWhen we remove the absolute value in order to solve for $y$ we obtain \n$$\ny = \\pm e^{C_1} e^{3t}.\n$$\nAs $ \\pm e^{C_1} $ may be either positive or\nnegative, we will denote this  by $C$ to obtain\n$$\ny(t) = Ce^{3t}.\n$$\n\nThere is one technical point to make here.  Notice that $y=0$\nis an equilibrium  solution to this differential equation.  In solving\nthe equation above, we begin by dividing both sides by $y$, which\nis not allowed if $y=0$.  To be perfectly careful, therefore, we will typically\nconsider these equilibrium solutions separately.  In this case, notice that the final\nform of our solution captures the equilibrium solution by allowing\n$C=0$.\n\\end{solution}\n\n\n\\subsection{Exponential Growth and Decay}\n\nThe differential equation in the previous example ($ y'=3y $) describes a quantity $ y $ whose rate of change is directly proportional to the quantity itself. Such a differential equation is said to model exponential growth. \n\n\n\n\n\n\n\\begin{example}{Population Growth and Radioactive Decay}{Population Growth and Radioactive Decay}\\label{Population Growth and Radioactive Decay}\nAnalyze the differential equation $y'=ky$.\n\\end{example}\n\n\\begin{solution}\nWhen $k>0$, this describes certain simple cases of (exponential) population growth:\nIt says that the change in the population $y$ is proportional to the\npopulation. The underlying assumption is that each organism in the\ncurrent population reproduces at a fixed rate, so the larger the\npopulation the more new organisms are produced. While this is too\nsimple to model most real populations, it is useful in some cases over\na limited time.  The parameter $ k $ is called the \\textit{proportionality constant}. \nWhen $k<0$, the differential equation describes a\nquantity that decreases in proportion to the current value (exponential decay); this can\nbe used to model radioactive decay.\n\nThe constant solution is $y(t)=0$; of course this will not be the\nsolution to any interesting initial value problem. \nFor the non-constant solutions, we proceed much as before:\n\\begin{eqnarray*}\n\\int {1\\over y}\\,dy&=&\\int k\\,dt\\cr\n\\ln|y| &=& kt+C\\cr\n|y| &=& e^{kt} e^C\\cr\ny &=& \\pm \\,e^C e^{kt} \\cr\ny&=& Ae^{kt}.\n\\end{eqnarray*}\nAgain, if we allow $A=0$ this includes the equilibrium solution, and we\ncan simply say that $\\ds y=Ae^{kt}$ is the general solution. With an\ninitial value we can easily solve for $A$ to get the solution of the\ninitial value problem. In particular, if the initial value is\ngiven for time $t=0$, $y(0)=y_0$, then $A=y_0$ and the solution\nis $\\ds y= y_0 e^{kt}$.\n\\end{solution}\n\nIn general, the work in the previous example shows the following to hold true.\n\n\\begin{formulabox}[\\label{expDE} ]\nThe solution of the initial value problem\n\\[\n\\frac{dy}{dt}=ky,\\;\\;\\;\\;y(0)=y_0\n\\]\nis $ \\ds y=y_0e^{kt} $\n\\end{formulabox}\n\n\n\\begin{example}{Global Population Growth}{}\nAssuming that the growth rate is proportional to population size,\n use the fact the world population in 1900 is 1650 million and the 1910 is 1750\n million to estimate population in the year 2000.\n\\end{example}\n\n\n\\begin{solution}\nSince growth rate is proportional to population, we \nknow that the population  $P(t)$ will be given by a function of the form:\n\\[\nP=P_0e^{kt}\n\\] \ntaking $t$ to be the number of years after 1900.  \nWe are asked to find the population in the year 2000, in other words, find $P(100)$.  We know $P_0=1650$ (in millions), so \n\\begin{equation} \\label{eq:pop}\nP=1650e^{kt}\n\\end{equation}\n\n\nSo we must solve for the growth constant $k$. In 1910, (when $t=10$) the population was 1750 (million), so  $ P(10)=1750 $:\n\\[\n1750=1650e^{10k}\n\\]\nwhich gives\n\n\\[\nk=\\frac{1}{10}\\ln\\left(\\frac{175}{165}\\right)\n\\]\nSubstituting into equation \\ref{eq:pop} and simplifying gives \n\\[\nP=1650\\left(\\frac{175}{165}\\right)^{\\frac{t}{10}}\n\\]\n\nTherefore, after 100 years, the population will be\n\\[\nP(100)=1650\\left(\\frac{175}{165}\\right)^{10}\n\\approx 2972 \\textrm{ million.}\n\\]\n\n\\end{solution}\n\nAs mentioned previously, radioactive decay also follows an exponential model, $ y=y_0e^{kt} $ (where $ k<0 $). The   \\textit{half-life} of a material  is the time required for half of a given amount to decay. That is, the time for which $ \\frac12y_0 = y_0e^{kt} $. Solving for $ t $ gives $ t=-\\frac{\\ln(2)}{k} $.\n\n \\begin{formulabox}[\\label{halflife}Half Life ]\n Radioactive decay of a material with decay constant $ k$ is modelled by $ y=y_0e^{kt} $, and has a half-life of $ \\ds -\\frac{ln(2)}{k} $    \n \\end{formulabox} \n\n\n\\begin{example}{}{}\nThe half-life of radium-226 is 1590 years.  A sample of radium has a mass of 100 mg.\n\\begin{enumerate}\n\\item Find a formula for the mass of radium after $ t $ years. \n\\item Find the mass after 1000 years.\n\n\\item When will the mass be reduced to 30mg?\n\\end{enumerate}\n\n\\end{example}\n\n\n\\begin{solution}\n\\begin{enumerate}\n\\item As this model is one of exponential decay, we know the formula for the mass after $t$ years will have the form:\n\\[\ny=y_0e^{kt},\n\\]\nwhere $k<0$. We are told $100$mg are initially present, so $ y_0=100$. To determine the decay constant, we use the given half-life with the formula in Key Idea \\ref{halflife}:\n\\[\nk =  -\\frac{ln(2)}{1590}.\n\\] \nTherefore, after simplifications we have\n\\[\ny=100e^{t\\cdot -\\frac{ln(2)}{1590}} = 100\\cdot \\left(\\frac12\\right)^\\frac{t}{1590}.\n\\]\n\\item From part (a) we see that after $ 1000 $  years the amount remaining will be\n\\[\ny(1000)=100\\cdot \\left(\\frac12\\right)^{\\frac{1000}{1590}}\\approx 64.67\\textrm{mg}.\n\\]\n \n\\item  We wish to find $t$ when $y=30$, so we solve: $\\ds 30=100\\cdot \\left(\\frac12\\right)^{\\frac{t}{1590}}$. Dividing by $ 100 $, taking the natural logarithm of both sides, and solving for $ t $ gives\n\\[\n\\ln\\left(\\frac{3}{10}\\right)= \\frac{t}{1590} \\ln\\left(\\frac12\\right)\n\\to\\;t= 1590\\cdot\\frac{\\ln\\left(\\frac{3}{10}\\right)}{\\ln\\left(\\frac12\\right)}\\approx 2762 \\textrm{ years.}\n\\]\n\n\\end{enumerate}\n\n\\end{solution}\n\nMore generally, a quantity $y$ may grow (or shrink) with rate of change proportional to a difference $y-b$. Such is the case with Newton's Law of Cooling. \n\n\\begin{formulabox}[\\label{NLC} Newton's Law of Cooling ]\nThe rate of cooling of an object is directly proportional to the difference between the temperature $y(t)$ of the object and the ambient temperature $T$ ( i.e. the temperature $T$ of its surroundings.)\n  \\[\n  \\frac{dy}{dt}=k(y-T)\n  \\]                  \nwhere $ k $ is called the cooling constant (in units of $ (\\text{time})^{-1} $), and depends on the physical properties of the materials involved. This differential equation may be solved in the same manner as in Example \\ref{exa:Population Growth and Radioactive Decay} to give\n\\[\ny= T+y_0e^{kt}\n\\]                   \n\\end{formulabox}\n\n\nMore generally, if $\\frac{dy}{dt} = k(y-b) $ for some constant $ b $, then $ y=b+Ce^{kt} $, where $ C=y(0)$.\n\n\n\\begin{example}{IVP for Newton's Law of Cooling}{IVP for Newton's Law of Cooling}\\label{IVP for Newton's Law of Cooling}\n Consider this specific example of an initial value problem\nfor Newton's law of cooling: $y' = -2(y-25)$, $y(0)=40$.\nDiscuss the solutions for this initial value problem.\n\\end{example}\n\n\\begin{solution}\nWe first note the zero of the equation: If $y = 25$, the right hand side of the differential\nequation is zero, and so the constant function $y(t)=25$ is a solution\nto the differential equation. It is not a solution to the initial\nvalue problem, since $y(0)\\neq 25$.  (The physical interpretation of\nthis constant solution is that if a liquid is at the same temperature\nas its surroundings, then the liquid will stay at that temperature.)\n\nAt this point we may appeal to the key idea \\ref{Newton's Law of Cooling}, taking $ T=25 $, and $ k=-2 $ to solve the differential equation.  However, just for practice we will derive the result directly. \n\nSeparating variables, so long as $y\\ne 25$,  we can rewrite the differential equation as\n\\begin{eqnarray*}\n{dy\\over dt}{1\\over 25-y}&=&2\\cr\n{1\\over 25-y}\\,dy&=&2\\,dt,\n\\end{eqnarray*}\nso \n$$\\int {1\\over 25-y}\\,dy = \\int 2\\,dt,$$\nWe can calculate these anti-derivatives and \nrearrange the results:\n\\begin{eqnarray*}\n\\int {1\\over 25-y}\\,dy &=& \\int 2\\,dt\\cr\n(-1)\\ln|25-y| &=& 2t+C_0\\cr\n\\ln|25-y| &=& -2t - C_0 = -2t + C_1\\cr\n|25-y| &=& e^{-2t+C_1}=e^{-2t} e^{C_1}\\cr\ny-25 &=& \\pm\\, e^{C_1} e^{-2t} \\cr\ny &=& 25 \\pm e^{C_1} e^{-2t} =25+Ce^{-2t}.\n\\end{eqnarray*}\nHere $\\ds C = \\pm\\, e^{C_1} = \\pm\\, e^{-C_0}$ \nis some non-zero constant. Note that this agrees with the solution we would have obtained directly from Key Idea \\ref{Newton's Law of Cooling}.\n\nSince we require $y(0)=40$, we substitute and solve for $C$:\n\\begin{eqnarray*}\n40&=&25+Ce^0\\cr\n15&=&C,\n\\end{eqnarray*}\nand so $\\ds y=25+15 e^{-2t}$ is a solution to the initial value\nproblem. \n\nNote that $y$ is never $ 25 $, so this makes sense for all values\nof $t$. However, if we allow $C=0$ we get the solution\n$y=25$ to the differential equation, which would be the solution to\nthe initial value problem if we were to require $y(0)=25$. Thus, \n$\\ds y=25+Ce^{-2t}$ describes all solutions to the differential\nequation $\\ds y' = 2(25-y)$, and all solutions to the associated\ninitial value problems. \n\\end{solution}\n\n\n \n\\begin{example}{}{}\nIf an object takes $ 40 $ minutes to cool from $ 30 $ degrees to $ 24 $ degrees in a $ 20 $\ndegree room, how long will it take the object to cool to $ 21 $ degrees?                                   \n\\end{example}\n\n\n\\begin{solution}\nFrom the above discussion we know that the model for the temperature $ y $, $ t $ minutes after the first temperature measurement is given by\n\\[\ny=20+10e^{kt}.\n\\]\nTo solve for $ k $ we use the fact that $ y(40) =24$. Substituting $ t=40, $ and $ y=24 $ into the last equation, and simplifying gives\n\\[\n24=20 10e^{40k}\\;\\;\\to\\;\\; k= \\ln\\left[\\left(\\frac{2}{5}\\right)^{\\frac{1}{40}}\\right]\n\\]\nTherefore, \n\\[\ny=10e^{t\\cdot \\ln\\left[\\left(\\frac{2}{5}\\right)^{\\frac{1}{40}}\\right]}+20 =10e^{\\ln\\left[\\left(\\frac{2}{5}\\right)^{\\frac{t}{40}}\\right]}+20=10\\left(\\frac{2}{5}\\right)^{\\frac{t}{40}}+20\n\\]\n\nSo when the temperature is $ 21 $ degrees, we have\n\\[\n21=10\\left(\\frac{2}{5}\\right)^{\\frac{t}{40}}+20\\Rightarrow \nt= \\frac{-40\\ln(10)}{\\ln\\left( \\frac{2}{5} \\right)} \\approx 100.52 \\text{min.}\n\\]\nTherefore, even though it took only $ 40 $ minutes to cool from $ 30 $ degrees to $ 24 $ degrees \n(a difference of $ 6 $ degrees),  it will take over $ 100 $ minutes to cool to $ 21 $ degrees\n (the last $ 3 $ degrees add more than an hour to the time required!).\n\n\\end{solution}\n\n\n\n\n                                   \n\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:first order differential equations}}\n\n\\begin{enumialphparenastyle}\n\n%%%%%%%%%%\n\\begin{ex}\n Which of the following equations are separable?\n\n\\begin{enumerate}\n\t\\item $\\ds y' = \\sin (ty)$\n\t\\item $\\ds y' = e^t e^y $\n\t\\item $\\ds yy' = t $\n\t\\item $\\ds y' = (t^3 -t) \\arcsin(y)$\n\t\\item $\\ds y' = t^2 \\ln y + 4t^3 \\ln y $\n\\end{enumerate}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve $\\ds y' = 1/(1+t^2)$.\n\\begin{sol}\n $\\ds y=\\arctan t + C$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the initial value problem $y' = t^n$ with\n$y(0)=1$ and $n\\ge 0$.\n\\begin{sol}\n $\\ds y={t^{n+1}\\over n+1}+1$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve $y' = \\ln t$. \n\\begin{sol}\n $\\ds y=t\\ln t-t+C$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Identify the constant solutions (if any) of $y' =t\\sin y$.\n\\begin{sol}\n $y=n\\pi$, for any integer $n$.\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Identify the constant solutions (if any) of $\\ds y'=te^y$.\n\\begin{sol}\n none\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve $y' = t/y$.\n\\begin{sol}\n $\\ds y=\\pm\\sqrt{t^2+C}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve $\\ds y' = y^2 -1$.\n\\begin{sol}\n $\\ds y=\\pm 1$, $\\ds y=(1+Ae^{2t})/(1-Ae^{2t})$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve $\\ds y' = t/(y^3 - 5)$. You may leave\nyour solution in implicit form: that is, you may stop once you have\ndone the integration, without solving for $y$.\n\\begin{sol}\n $\\ds y^4/4-5y=t^2/2+C$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Find a non-constant solution of the initial value problem \n$y' = y^{1/3}$, $y(0)=0$, using\n separation of variables. Note that the constant function $y(t)=0 $\n also solves the initial value problem. This shows that an initial value\n problem can have more than one solution.\n\\begin{sol}\n $\\ds y=(2t/3)^{3/2}$\n\\end{sol}\n\\end{ex}\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the equation for Newton's law of cooling leaving $M$\nand $k$ unknown.\n\\begin{sol}\n $\\ds y=M+Ae^{-kt}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n After 10 minutes in Jean-Luc's room, his tea has\ncooled to $40^\\circ $ Celsius from $100^\\circ$ Celsius. \nThe room temperature is $25^\\circ$\nCelsius. How much longer will it take to cool to $35^\\circ$?\n\\begin{sol}\n $\\ds {10\\ln(15/2)\\over\\ln 5}\\approx 2.52$ minutes\n\\end{sol}\n\\end{ex} \n\n\n%%%%%%%%%%\n\\begin{ex}\n Solve the \\dfont{logistic equation} $y' = ky(M-y)$. (This is a somewhat more\nreasonable population model in most cases than the simpler\n$y'=ky$.) Sketch the\ngraph of the solution to this equation when \n$M=1000$, $k=0.002$, $y(0)=1$.\n\\begin{sol}\n $\\ds y={M\\over 1+Ae^{-Mkt}}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Suppose that $y' = ky$, $y(0)=2$, and $y'(0)=3$. \nWhat is $y$?\n\\begin{sol}\n $\\ds y=2e^{3t/2}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A radioactive substance obeys the equation\n$y' =ky$ where $k< 0 $ and $y$ is the mass of the\nsubstance at time $t$. Suppose that initially, the mass of the\nsubstance is $y(0)=M>0$. At what time does half of the mass remain?\n(This is known as the half life. Note that the half life depends on\n$k$ but not on $M$.)\n\\begin{sol}\n $\\ds t=-{\\ln 2\\over k}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n Bismuth-210 has a half life of five days. If there is\ninitially 600 milligrams, how much is left after 6 days? When will\nthere be only 2 milligrams left?\n\\begin{sol}\n $\\ds 600e^{-6\\ln 2/5}\\approx 261$ mg; $\\ds {5\\ln\n  300\\over\\ln2}\\approx 41$ days\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n The half life of carbon-14 is 5730 years. If one starts\nwith 100 milligrams of carbon-14, how much is left after 6000\nyears? How long do we have to wait before there is less than 2\nmilligrams?\n\\begin{sol}\n $\\ds 100e^{-200\\ln 2/191}\\approx 48$ mg; $\\ds {5730\\ln\n  50\\over\\ln2}\\approx 32339$ years\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n A certain species of bacteria doubles its population\n(or its mass)\nevery hour in the lab. \nThe differential equation that models this phenomenon\nis $y' =ky$, where $k>0 $ and $y$\nis the population of bacteria at time $t$. What is $y$?\n\\begin{sol}\n $\\ds y=y_0e^{t\\ln 2}$\n\\end{sol}\n\\end{ex}\n\n\n%%%%%%%%%%\n\\begin{ex}\n If a certain microbe doubles its population every 4\nhours and after 5 hours the total population has mass 500 grams,\nwhat was the initial mass?\n\\begin{sol}\n $\\ds 500e^{-5\\ln2/4}\\approx 210$ g\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "7e17de43e52efd88bd30319908cd56b09f731dfa", "size": 27074, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10-differential-equations/10-1-first-order-de.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-1-first-order-de.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-1-first-order-de.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.9768574909, "max_line_length": 354, "alphanum_fraction": 0.6732289281, "num_tokens": 8817, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.867035763237924, "lm_q2_score": 0.8757869981319862, "lm_q1q2_score": 0.7593386483592169}}
{"text": "\\chapter{Finite Markov Chains}\n\nWhen a stochastic process $\\left(X_{\\alpha} \\right)_{\\alpha \\in \\Az}$ is not independent it is said to be dependent.  \nSo far we have mostly concerned ourselves with independent processes.  \nIn this chapter we introduce finite Markov chains and their  simulation methods.\nFinit Markov chains are among the simplest stochastic processes with a `first-order' dependence called Markov dependence.\n\n\\section{Introduction}\\label{S:FiniteMCIntro}\nA finite Markov chain is a stochastic process that moves among elements in a finite set $\\Xz$ as follows: when at $x \\in \\Xz$ the next position is chosen at random according to a fixed probability distribution $P(\\cdot | x)$.  We define such a process more formally below.\n\n\\begin{definition}[Finite Markov Chain]\\label{D:TimeHomFiniteMC}\nA stochastic sequence, $$\\left(X_n\\right)_{n \\in \\Zz_+} := (X_0,X_1,\\ldots),$$ is a homogeneous {\\bf Markov chain} with {\\bf state space} $\\Xz$ and {\\bf transition matrix} $P:=\\left(P(x,y)\\right)_{(x,y)\\in \\Xz^2}$ if for all pair of {\\bf states} ${(x,y)\\in \\Xz^2 := \\Xz \\times \\Xz}$, all integers $t \\geq 1$, and all probable historical events $H_{t-1} := \\bigcap_{n=0}^{t-1} \\{ X_n = x_n \\}$ with $\\P \\left(H_{t-1} \\cap \\{X_t = x\\} \\right) > 0$, the following {\\bf Markov property} is satisfied: \n\\begin{equation}\\label{E:FiniteMarkovProperty}\n\\P\\left(X_{t+1} = y | H_{t-1} \\cap \\{X_t = x\\} \\right)=\\P\\left(X_{t+1} = y | X_t = x \\right) =: P(x,y) \\enspace .\n\\end{equation}\n\\end{definition}\nThe Markov property means that the conditional probability of going to state $y$ at time $t+1$ from state $x$ at current time $t$ is always given by the $(x,y)$-th entry $P(x,y)$ of the transition matrix $P$, no matter what sequence of states $(x_0,x_1,\\ldots,x_{t-1})$ preceded the current state $x$.  Thus, the $|\\Xz| \\times |\\Xz|$ matrix $P$ is enough to obtain the state transitions since the $x$-th row of $P$ is the probability distribution $P(x,\\cdot) := \\left( P(x,y) \\right)_{y \\in \\Xz}$.  For this reason $P$ is called a {\\bf stochastic matrix}, i.e.,\n\\begin{equation}\\label{E:StochasticMatrixConds}\nP(x,y) \\geq 0 \\quad \\text{for all } (x,y) \\in \\Xz^2 \\qquad \\text{and} \\quad \\sum_{y \\in \\Xz} P(x,y) = 1 \\quad \\text{for all } x \\in \\Xz \\enspace .\n\\end{equation}\nThus, for a Markov chain $\\left(X_n\\right)_{n \\in \\Zz_+}$, the distribution of $X_{t+1}$ given $X_0,\\ldots,X_t$  depends on $X_t$ alone. Because of this dependence on the previous state, the stochastic sequence, $(X_0,X_1,\\ldots)$, are {\\it not} independent.  We introduce the most important concepts using a simple example.\n\n\\begin{example}[Flippant Freddy]\\label{EX:FlippantFreddy}\nFreddy the flippant frog lives in an enchanted pond with only two lily pads, {\\em rollopia} and {\\em flipopia}.  A wizard gave a  die and a silver coin to help flippant Freddy decide where to jump next.  Freddy left the die on rollopia and the coin on flipopia.  When Freddy got restless in rollopia he would roll the die and if the die landed odd he would leave the die behind and jump to flipopia, otherwise he would stay put.  When Freddy got restless in flipopia he would flip the coin and if it landed Heads he would leave the coin behind and jump to rollopia, otherwise he would stay put.\n\nLet the state space $\\Xz=\\{r,f\\}$, and let $(X_0, X_1,\\ldots)$ be the sequence of lily pads occupied by Freddy after his restless moments.  Say the die on rollopia $r$ has probability $p$ of turning up odd and the coin on flipopia $f$ has probability $q$ of turning up heads.  We can visualise the rules of Freddy's jumps by the following {\\bf transition diagram}:\n\\begin{figure}[htpb]\n\\caption{Transition Diagram of Flippant Freddy's Jumps.\\label{F:FlippantFreddyTransDiag}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/FlippantFreddyTransDiag}}\n\\end{figure}\n\nThen Freddy's sequence of jumps $(X_0, X_1,\\ldots)$ is a Markov chain on $\\Xz$ with transition matrix:\n\\begin{equation}\\label{E:FlippantFreddyP}\nP \n= \\bordermatrix{~ & r & f \\cr \nr & P(r,r) & P(r,f)\\cr \nf & P(f,r) & P(f,f) }\n= \\bordermatrix{~ & r & f \\cr \nr & 1-p & p \\cr\nf & q & 1-q } \\enspace .\n\\end{equation}\nSuppose we first see Freddy in rollopia, i.e., $X_0=r$.  When he gets restless for the first time we know from the first row of $P$ that he will leave to flippopia with probability $p$ and stay with probability $1-p$, i.e.,\n\\begin{equation}\\label{E:Freddy1Step}\n\\P(X_1=f | X_0=r) = p, \\quad \\P(X_1=r | X_0=r) = 1-p \\enspace .\n\\end{equation}\nWhat happens when he is restless for the second time?  By considering the two possibilities for $X_1$, Definition of conditional probability and the Markov property, we see that,\n\\begin{eqnarray}\n\\P(X_2 = f | X_0 = r) \n&=& \\P(X_2=f, X_1=f | X_0=r) + \\P(X_2=f, X_1=r | X_0=r) \\notag \\\\\n&=& \\frac{\\P(X_2=f, X_1=f , X_0=r)}{\\P(X_0=r)} + \\frac{\\P(X_2=f, X_1=r , X_0=r)}{\\P(X_0=r)} \\notag \\\\\n&=& \\P(X_2=f | X_1=f , X_0=r)\\frac{\\P(X_1=f , X_0=r)}{\\P(X_0=r)} \\notag \\\\\n&& \\qquad + \\P(X_2=f | X_1=r , X_0=r) \\frac{\\P(X_1=r , X_0=r)}{\\P(X_0=r)} \\notag \\\\\n%&=& \\frac{\\P(X_2=f | X_1=f , X_0=r)\\P(X_1=f | X_0=r)\\P(X_0=r)}{\\P(X_0=r)} \\\\\n%&& \\qquad + \\frac{\\P(X_2=f | X_1=r , X_0=r) \\P(X_1=r | X_0=r)\\P(X_0=r)}{\\P(X_0=r)} \\\\\n&=&{\\P(X_2=f | X_1=f , X_0=r)\\P(X_1=f | X_0=r)} \\notag \\\\\n&& \\qquad +{\\P(X_2=f | X_1=r , X_0=r) \\P(X_1=r | X_0=r)} \\notag \\\\\n&=& \\P(X_2=f | X_1=f) \\P(X_1=f | X_0=r) \\notag \\\\\n&& \\qquad+ \\P(X_2=f | X_1=r) \\P(X_1=r | X_0=r) \\notag \\\\\n&=& P(f,f) P(r,f) + P(r,f) P(r,r) \\notag \\\\\n&=& (1-q) p + p (1-p) \\label{E:Freddy2Stepa}\n\\end{eqnarray}\nSimilarly, \n\\begin{equation} \\label{E:Freddy2Stepb}\n\\P(X_2=r | X_0 =r) = P(f,r) P(r,f) + P(r,r) P(r,r) = q p + (1-p)(1-p)\n\\end{equation}\nInstead of elaborate computations of the probabilities of being in a given state after Freddy's $t$-th restless moment, we can store the state probabilities at time $t$ in a row vector:\n\\[\n\\mu_t := \\left(  \\P(X_t = r | X_0 = r), \\P(X_t=f | X_0=r) \\right) \\enspace ,\n\\]\nNow, we can conveniently represent Freddy starting in rollopia by the {\\bf initial distribution} $\\mu_0 = (1,0)$ and obtain the 1-step {\\bf state probability vector} in \\eqref{E:Freddy1Step} from $\\mu_1 = \\mu_0 P$ and the 2-step state probabilities in \\eqref{E:Freddy2Stepa} and \\eqref{E:Freddy2Stepb} by $\\mu_2 = \\mu_1 P = \\mu_0 P P = \\mu_0 P^2$.  In general, multiplying $\\mu_t$, the state probability vector at time $t$, by the transition matrix $P$ on the right updates the state probabilities by another step:\n\\[\n\\mu_{t} = \\mu_{t-1} P \\qquad \\text{for all } t \\geq 1 \\enspace .\n\\]\nAnd for any initial distribution $\\mu_0$,\n\\[\n\\mu_{t} = \\mu_0 P^t  \\qquad \\text{for all } t \\geq 0 \\enspace .\n\\]\nThis can be easily implemented in \\Matlab as follows:\n%\\begin{VrbM}\n%>> p=0.5; q=0.5; P = [1-p p; q 1-q] % assume a fair coin and a fair die\n%P =\n%    0.5000    0.5000\n%    0.5000    0.5000\n%\n%>> mu0 = [1, 0] % inital state vector since Freddy started in rollopia\n%mu0 =     1     0\n%\n%>> mu0*P^0    % intial state distribution at t=0 is just mu0\n%ans =     1     0\n%\n%>> mu0*P^1    % state distribution at t=1\n%ans =    0.5000    0.5000\n%\n%>> mu0*P^2    % state distribution at t=2\n%ans =    0.5000    0.5000\n%\\end{VrbM}\n%Thus for a fair coin and die we get equal probabilities of being in the two states right after the first jump.  Let us see what happens for an unfair coin and die:\n\\begin{VrbM}\n>> p=0.85; q=0.35; P = [1-p p; q 1-q] % assume an unfair coin and an unfair die\nP =\n    0.1500    0.8500\n    0.3500    0.6500\n>> mu0 = [1, 0] % inital state vector since Freddy started in rollopia\nmu0 =     1     0\n>> mu0*P^0    % intial state distribution at t=0 is just mu0\nans =     1     0\n>> mu0*P^1    % state distribution at t=1\nans =    0.1500    0.8500\n>> mu0*P^2    % state distribution at t=2\nans =    0.3200    0.6800\n>> mu0*P^3    % state distribution at t=3\nans =    0.2860    0.7140\n\\end{VrbM}\nNow, let us compute and look at the probability of being in rollopia after having started there for three values of $p$ and $q$ according to the following script: \n\\VrbMf[label=FlippantFreddyRollopiaProbs.m]{scripts/FlippantFreddyRollopiaProbs.m}\n\n\\begin{figure}[htpb]\n\\caption{The probability of being back in rollopia in $t$ time steps after having started there under transition matrix $P$ with (i) $p=q=0.5$ (blue line with asterisks), (ii) $p=0.85$, $q=0.35$ (black line with dots) and (iii) $p=0.15$, $q=0.95$ (red line with pluses).\\label{F:FlippantFreddyRollopiaProbs}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/FlippantFreddyRollopiaProbs}}\n\\end{figure}\n\nIt is evident from \\hyperref[F:FlippantFreddyRollopiaProbs]{Figure~\\ref*{F:FlippantFreddyRollopiaProbs}} that as $t \\to \\infty$, $\\mu_t$ approaches a distribution, say $\\pi$, that depends on $p$ and $q$ in $P$.  Such a limit distribution is called the {\\bf stationary distribution} and must satisfy the fixed point condition:\n\\[\n\\pi P = \\pi \\enspace ,\n\\]\nthat gives the solution:\n\\[\n\\pi(r) = \\frac{q}{p+q}, \\qquad \\pi(f) = \\frac{p}{p+q} \\enspace .\n\\]\nIn \\hyperref[F:FlippantFreddyRollopiaProbs]{Figure~\\ref*{F:FlippantFreddyRollopiaProbs}} we see that $\\P(X_t=r)$ approaches $\\pi(r) = \\frac{q}{p+q}$ for the three cases of $p$ and $q$:\n\\begin{align*}\n\\text{(i)}& \\ p=0.50, q=0.50, & \\P(X_t=r) & \\to \\pi(r) = \\frac{q}{p+q} =  \\frac{0.50}{0.50+0.50} = 0.5000,\\\\\n\\text{(ii)}& \\  p=0.85, q=0.35, & \\P(X_t=r) & \\to \\pi(r) = \\frac{q}{p+q} =  \\frac{0.35}{0.85+0.35} = 0.2917, \\\\\n\\text{(iii)}& \\ p=0.15, q=0.95, & \\P(X_t=r) & \\to \\pi(r) = \\frac{q}{p+q} = \\frac{0.95}{0.15+0.95} = 0.8636.\n\\end{align*}\n\\end{example}\n\nNow let us generalise the lessons learned from \\hyperref[EX:FlippantFreddy]{Example~\\ref*{EX:FlippantFreddy}}.\n\n\\begin{prop}\\label{P:FiniteMCProbsAtTimet}\nFor a finite Markov chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$, initial distribution $$\\mu_0 := \\left( \\mu_0(s_1), \\mu_0(s_2), \\ldots, \\mu_0(s_k) \\right),$$ where $\\mu_0(s_i) = \\P(X_0=s_i)$, and transition matrix $$P := \\left(P(s_i,s_j)\\right)_{(s_i,s_j)\\in \\Xz^2},$$ we have for any $t \\in \\Zz_+$ that the distribution at time $t$ given by:\n$$\\mu_t := \\left( \\mu_t(s_1), \\mu_t(s_2), \\ldots, \\mu_t(s_k) \\right),$$\nwhere $\\mu_t(s_i) = \\P(X_t=s_i)$, satisfies:\n\\begin{equation}\\label{E:mutismu0Pt}\n\\mu_t = \\mu_0 P^t \\enspace .\n\\end{equation}\n\\begin{proof}\nWe will prove this by induction on $\\Z_+:=\\{0,1,2,\\ldots\\}$.  First consider the case when $t=0$.  Since $P^0$ is the identity matrix $I$, we get the desired equality:\n\\[\n\\mu_0 P^0 = \\mu_0 I = \\mu_0 \\enspace .\n\\]\nNext consider the case when $t=1$.  We get for each $j \\in \\{1,2,\\ldots,k\\}$, that\n\\begin{align*}\n\\mu_1(s_j) &= \\P(X_1 = s_j) = \\sum_{i=1}^k \\P(X_1=s_j,X_0=s_i)\\\\\n&= \\sum_{i=1}^k \\P(X_1=s_j | X_0=s_i) \\P(X_0=s_i) \\\\\n&= \\sum_{i=1}^k P(s_i,s_j) \\mu_0(s_i)\\\\\n&= (\\mu_0 P)(s_j), \\quad \\text{the $j$-th entry of the row vector $(\\mu_0 P)$} \\enspace .\n\\end{align*}\nHence, $\\mu_1=\\mu_0 P$.  Now, we will fix $m$ and suppose that \\eqref{E:mutismu0Pt} holds for $t=m$ and prove that \\eqref{E:mutismu0Pt} also holds for $t=m+1$.  \nFor each $j \\in \\{1,2,\\ldots,k\\}$, we get\n\\begin{align*}\n\\mu_{m+1}(s_j) &= \\P(X_{m+1} = s_j) = \\sum_{i=1}^k \\P(X_{m+1}=s_j,X_m=s_i)\\\\\n&= \\sum_{i=1}^k \\P(X_{m+1}=s_j | X_m=s_i) \\P(X_m=s_i) \\\\\n&= \\sum_{i=1}^k P(s_i,s_j) \\mu_m(s_i)\\\\\n&= (\\mu_m P)(s_j), \\quad \\text{the $j$-th entry of the row vector $(\\mu_m P)$} \\enspace .\n\\end{align*}\nHence, $\\mu_{m+1}=\\mu_m P$.  But $\\mu_{m}=\\mu_0 P^m$ by the induction hypothesis, and therefore:\n\\[\n\\mu_{m+1} = \\mu_m P = \\mu_0 P^m P = \\mu_0 P^{m+1} \\enspace .\n\\]\nThus by the principle of mathematical induction we have proved the proposition.\n\\end{proof}\n\\end{prop}\nThus, multiplying a row vector $\\mu_0$ by $P^t$ on the right takes you from current distribution over the state space to the distribution in $t$ steps of the chain.  \n\nSince we will be interested in Markov chains on $\\Xz =\\{s_1,s_2,\\ldots,s_k\\}$ with the same transition matrix $P$ but different initial distributions, we introduce $\\P_{\\mu}$ and $\\E_{\\mu}$ for probabilities and expectations  given that the initial distribution is $\\mu$, respectively.  When the initial distribution is concentrated at a single initial state $x$ given by:\n$$\\BB{1}_{\\{x\\}}(y) := \\begin{cases} 1 & \\text{if } y=x\\\\ 0 & \\text{if } y \\neq x \\end{cases}$$ \nwe represent it by $e_x$, the $1 \\times k$ ortho-normal basis row vector with a $1$ in the $x$-th entry and a $0$ elsewhere.  \nWe simply write $\\P_x$ for $\\P_{\\BB{1}_{\\{x\\}}}$ or $\\P_{e_x}$ and $\\E_x$ for $\\E_{\\BB{1}_{\\{x\\}}}$ or $\\E_{e_x}$.  Thus, \\hyperref[P:FiniteMCProbsAtTimet]{Proposition~\\ref*{P:FiniteMCProbsAtTimet}} along with our new notations means that:\n\\[\n\\P_x (X_t = y)  = (e_x P^t)(y) = P^t(x,y) \\enspace .\n\\]\nIn words, the probability of going to $y$ from $x$ in $t$ steps is given by the $(x,y)$-th entry of $P^t$, the {\\bf $t$-step transition matrix}.  We refer to the $x$-th row and the $x$-th column of $P$ by $P(x,\\cdot)$ and $P(\\cdot,x)$, respectively.\n\nLet the function $f(x): \\Xz\\to \\Rz$ be represented by the column vector $f := (f(s_1),f(s_2),\\ldots,f(s_k)) \\in \\Rz^{k \\times 1}$.  Then the $x$-th entry of $P^t f$ is:\n\\[\nP^t f(x) = \\sum_{y} P^t(x,y) f(y) = \\sum_{y} f(y) \\P_x (X_t = y) = \\E_x (f(X_t)) \\enspace .\n\\] \nThis is the expected value of $f$ under the distribution of states in $t$ steps given that we start at state $x$.  \nThus multiplying a column vector $f$ by $P^t$ from the left takes you from a function on the state space to its expected value in $t$ steps of the chain. \n\n%Let us look at some more examples of Markov chains.\n\\begin{example}[Dry-Wet Christchurch Weather]\\label{EX:DryWetChain}\nConsider a toy weather model for dry or wet days in Christchurch using a Markov chain with state space $\\{d,w\\}$.  Let the transition diagram in \\hyperref[F:DryWetTransDiag]{Figure~\\ref*{F:DryWetTransDiag}} give the transition matrix $P$ for our dry-wet Markov chain.  \n\\begin{figure}[htpb]\n\\caption{Transition Diagram of Dry and Wet Days in Christchurch.\\label{F:DryWetTransDiag}}\n\\centering   \\makebox{\\includegraphics[width=3.5in]{figures/DryWetTransDiag}}\n\\end{figure}\nUsing \\eqref{E:mutismu0Pt} we can find that the probability of being dry on the day after tomorrow is $0.625$ given that it is wet today as follows:\n\\begin{VrbM}\n>> P=[0.75 0.25; 0.5 0.5] % Transition Probability Matrix\nP =\n    0.7500    0.2500\n    0.5000    0.5000\n>> mu0=[0 1] % it is wet today gives the initial distribution\nmu0 =     0     1\n>> mu0 * P^2 % the distribution in 2 days from today\nans =    0.6250    0.3750\n\\end{VrbM}\nSuppose you sell \\$100 of lemonade at a road-side stand on a hot day but only \\$50 on a cold day.  Then we can compute your expected sales tomorrow if today is dry as follows:\n\\begin{VrbM}\n>> P=[0.75 0.25; 0.5 0.5] % Transition Probability Matrix\nP =\n    0.7500    0.2500\n    0.5000    0.5000\n>> f = [100; 50] % sales of lemonade in dollars on a dry and wet day\nf =\n   100\n    50\n>> P*f % expected sales tomorrow\nans =\n   87.5000\n   75.0000 \n>> mu0 = [1 0] % today is dry\nmu0 =     1     0\n>> mu0*P*f % expected sales tomorrow if today is dry\nans =   87.5000\n\\end{VrbM}\n\\end{example}\n\n\\begin{exercise}[Freddy discovers a gold coin]\\label{EXR:FreddyGoldCoin}\nFlippant Freddy of \\hyperref[EX:FlippantFreddy]{Example~\\ref*{EX:FlippantFreddy}} found a gold coin at the bottom of the pond.  Since this discovery he  jumps around differently in the enchanted pond.  He can be found now in one of three states: flipopia, rollopia and hydropia (when he dives into the pond). His state space is $\\Xz=\\{r,f,h\\}$ now and his transition mechanism is as follows: If he rolls an odd number with his fair die in rollopia he will jump to flipopia but if he rolls an even number then he will stay in rollopia only if the outcome is $2$ otherwise he will dive into hydropia.  If the fair gold coin toss at the bottom of hydropia is Heads then Freddy will swim to flipopia otherwise he will remain in hydropia. Finally, if he is in flipopia he will remain there if the silver coin lands Heads otherwise he will jump to rollopia.\n\nMake a Markov chain model of the new jumping mechanism adopted by Freddy.  Draw the transition diagram, produce the transition matrix $P$ and compute using \\Matlab the probability that Freddy will be in hydropia after one, two, three, four and five jumps given that he starts in hydropia.\n\\end{exercise}\n\n\\begin{exercise}\\label{Exr:NonMarkovProjection1}\nLet $(X_t)_{t\\in\\Zz_+}$ be a Markov chain with state space $\\{a,b,c\\}$, initial distribution $\\mu_0=(1/3,1/3,1/3)$ and transition matrix \n$$P = \n\\bordermatrix{~ & a & b & c \\cr\na & 0 & 1 & 0\\cr\nb & 0 & 0 & 1\\cr\nc & 1 & 0 & 0} \\enspace .\n$$\nFor each $t$, define $Y_t = \\BB{1}_{\\{b,c\\}}(X_t)$.  Show that $(Y_t)_{t\\in\\Zz_+}$ is not a Markov chain.\n\\end{exercise}\n\n\\begin{exercise}\\label{Exr:RegularSampledChainIsMarkov}\nLet $(X_t)_{t\\in\\Zz_+}$ be a (homogeneous) Markov chain on $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$ with transition matrix $P$ and initial distribution $\\mu_0$.  For a given $m \\in \\Nz$, let $(Y_t)_{t\\in\\Zz_+}$ be a stochastic sequence with $Y_t = X_{mt}$.  Show that $(Y_t)_{t\\in\\Zz_+}$ is a Markov chain with transition matrix $P^m$.  This establishes that Markov chains that are sampled at regular time steps are also Markov chains.\n\\end{exercise}\n\n\nUntil now our Markov chains have been {\\bf  homogeneous} in time according to \\hyperref[D:TimeHomFiniteMC]{Definition~\\ref*{D:TimeHomFiniteMC}}, i.e., the transition matrix $P$ does not change with time.  We define inhomogeneous Markov chains that allow their transition matrices to possibly change with time.  Such Markov chains are more realistic as models in some situations and more flexible as algorithms in the sequel.\n\n\\begin{definition}[Inhomogeneous finite Markov chain]\\label{D:TimeInhomFiniteMC}\nLet $P_1,P_2,\\ldots$ be a sequence of $k \\times k$ stochastic matrices satisfying the conditions in \\hyperref[E:StochasticMatrixConds]{Equation~\\ref*{E:StochasticMatrixConds}}.  Then, the stochastic sequence $\\left( X_t \\right)_{t \\in \\Z_+} := (X_0,X_1,\\ldots)$ with finite state space $\\Xz := \\{s_1,s_2,\\ldots,s_k\\}$ is called an inhomogeneous Markov chain with transition matrices $P_1,P_2,\\ldots$, if for all pairs of states $(x,y) \\in \\Xz \\times \\Xz$, all integers $t \\geq 1$, and all probable historical events $H_{t-1} := \\bigcap_{n=0}^{t-1} \\{ X_n = x_n \\}$ with $\\P\\left(H_{t-1} \\cap \\{X_t = x\\} \\right) > 0$, the following {\\bf Markov property} is satisfied: \n\\begin{equation}\\label{E:InHomFiniteMarkovProperty}\n\\P\\left(X_{t+1} = y | H_{t-1} \\cap \\{X_t = x\\} \\right)=\\P\\left(X_{t+1} = y | X_t = x \\right) =: P_{t+1}(x,y) \\enspace .\n\\end{equation}\n\\end{definition}\n\n\\begin{prop}\\label{P:FiniteInHomMCProbsAtTimet}\nFor a finite inhomogeneous Markov chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$, initial distribution $$\\mu_0 := \\left( \\mu_0(s_1), \\mu_0(s_2), \\ldots, \\mu_0(s_k) \\right),$$ where $\\mu_0(s_i) = \\P(X_0=s_i)$, and transition matrices \n$$\\left(P_1,P_2,\\ldots\\right), \\quad P_t := \\left(P_t(s_i,s_j)\\right)_{(s_i,s_j)\\in \\Xz\\times \\Xz}, \\ t \\in \\{1,2,\\ldots\\}$$ we have for any $t \\in \\Zz_+$ that the distribution at time $t$ given by:\n$$\\mu_t := \\left( \\mu_t(s_1), \\mu_t(s_2), \\ldots, \\mu_t(s_k) \\right),$$\nwhere $\\mu_t(s_i) = \\P(X_t=s_i)$, satisfies:\n\\begin{equation}\\label{E:InhomMutismu0Pt}\n\\mu_t = \\mu_0 P_1 P_2 \\cdots P_t \\enspace .\n\\end{equation}\n\\begin{proof}\nLeft as \\hyperref[Exr:ProveInHomMultismu0Pt]{Exercise~\\ref*{Exr:ProveInHomMultismu0Pt}}.\n\\end{proof}\n\\end{prop}\n\n\\begin{exercise}\\label{Exr:ProveInHomMultismu0Pt}\nProve \\hyperref[P:FiniteInHomMCProbsAtTimet]{Proposition~\\ref*{P:FiniteInHomMCProbsAtTimet}} using induction as done for \\hyperref[P:FiniteMCProbsAtTimet]{Proposition~\\ref*{P:FiniteMCProbsAtTimet}}.\n\\end{exercise}\n\n\n\\begin{example}[a more sophisticated dry-wet chain]\\label{EX:DryWetChainHotCold}\nLet us make a more sophisticated version of the dry-wet chain of \\hyperref[EX:DryWetChain]{Example~\\ref*{EX:DryWetChain}} with state space $\\{d,w\\}$ .  In order to take some seasonality into account in our weather model for dry and wet days in Christchurch, let us have two transition matrices for hot and cold days:\n\\[\nP_{\\text{hot}} = \n\\bordermatrix{~ & d & w \\cr\nd & 0.95 & 0.05 \\cr\nw & 0.75 & 0.25},\n\\qquad\nP_{\\text{cold}} = \n\\bordermatrix{~ & d & w \\cr\nd & 0.65 & 0.35 \\cr\nw & 0.45 & 0.55} \\enspace .\n\\]\nWe say that a day is hot if its  maximum temperature is more than $20^{\\circ}$ Celsius, otherwise it is cold.  We use the transition matrix for today to obtain the state probabilities for tomorrow.  If today is dry and hot and tomorrow is supposed to be cold then what is the probability that the day after tomorrow will be wet?  We can use \\eqref{E:InhomMutismu0Pt} to obtain the answer as $0.36$: \n\\begin{VrbM}\n>> Phot = [0.95 0.05; 0.75 0.25] % Transition Probability Matrix for hot day\nPhot =\n    0.9500    0.0500\n    0.7500    0.2500\n>> Pcold = [0.65 0.35; 0.45 0.55] % Transition Probability Matrix for cold day\nPcold =\n    0.6500    0.3500\n    0.4500    0.5500\n>> mu0 = [1 0] % today is dry\nmu0 =     1     0\n>> mu1 = mu0 * Phot % distribution for tomorrow since today is hot\nmu1 =    0.9500    0.0500\n>> mu2 = mu1 * Pcold % distribution for day after tomorrow since tomorrow is supposed to be cold\nmu2 =    0.6400    0.3600\n>> mu2 = mu0 * Phot * Pcold % we can also get the distribution for day after tomorrow directly\nmu2 =    0.6400    0.3600\n\\end{VrbM}\n\\end{example}\n\n\\begin{exercise}\\label{Exr:DryWetChainHotCold}\nFor the Markov chain in \\hyperref[EX:DryWetChainHotCold]{Example~\\ref*{EX:DryWetChainHotCold}}  compute the probability that the day after tomorrow is wet if today is dry and hot but tomorrow is supposed to be cold.\n\\end{exercise}\n\n\\section{Random Mapping Representation and Simulation}\\label{S:FiniteMCRMRandSim}\n\nIn order to simulate $(x_0,x_1,\\ldots,x_n)$, a sequential realisation or sequence of states visited by a Markov chain, say the sequence of lily pads that Flippant Freddy visits on his jumps, we need a random mapping representation of a Markov chain and its computer implementation.  \n\n\\begin{definition}[Random mapping representation (RMR)]\\label{D:RMR}\nA {\\bf random mapping representation} (RMR) of a transition matrix $P := \\left(P(x,y)\\right)_{(x,y)\\in\\Xz^2}$ is a function \n\\begin{equation}\\label{E:RMRrho}\n\\rho(x,w): \\Xz \\times \\Wz \\to \\Xz \\enspace ,\n\\end{equation}\nalong with the auxiliary $\\Wz$-valued random variable $W$, satisfying\n\\begin{equation}\\label{E:RMRProbrho}\n\\P \\left( \\{ \\rho \\left( x,W \\right) = y  \\} \\right) = P(x,y), \\quad \\text{for each } (x,y) \\in \\Xz^2 \\enspace .\n\\end{equation}\n\\end{definition}\n\n\\begin{prop}[Markov chain from RMR]\\label{P:MCFromRMR}\nIf $W_1,W_2,\\ldots \\overset{IID}{\\sim} W$, the auxiliary RV in  a RMR of a transition matrix $P := \\left(P(x,y)\\right)_{(x,y)\\in\\Xz^2}$, and  $X_0 \\sim \\mu_0$, then $\\left(X_t\\right)_{t\\in\\Zz_+}$ defined by\n\\[\nX_t = \\rho \\left(X_{t-1},W_t\\right), \\quad \\text{for all } t \\geq 1\n\\]\nis a Markov chain with transition matrix $P$ and initial distribution $\\mu_0$ on state space $\\Xz$.\n\\begin{proof}\nLeft as \\hyperref[EXR:ProofofMCFromRMR]{Exercise~\\ref*{EXR:ProofofMCFromRMR}}.\n\\end{proof}\n\\end{prop}\n\n\\begin{exercise}\\label{EXR:ProofofMCFromRMR}\nDo the proof of \\hyperref[P:MCFromRMR]{Proposition~\\ref*{P:MCFromRMR}} by using the necessary Definitions.\n\\end{exercise}\n\n\n\\begin{example}[An RMR for Flippant Freddy]\\label{EX:RMRFreddy}\nReconsider the Markov chain of Flippant Freddy with fair dice and fair coin on state space $\\Xz=\\{r,f\\}$ with transition matrix \n$$P=\\bordermatrix{~ & r & f \\cr\nr & 1/2 & 1/2\\cr\nf & 1/2 &1/2}\\enspace .$$\nLet the auxiliary RV $W$ have sample space $\\Wz=\\{0,1\\}$.  Then an RMR $\\rho: \\Xz \\times \\Wz \\to \\Xz$ for this $P$ is given by \n\\[\n\\rho (x,w) : \\{r,f\\} \\times \\{0,1\\} \\to \\{r,f\\},\n\\quad \\rho(r,0)=r, \\quad \\rho(r,1)=f, \\quad \\rho(f,0)=f,  \\quad \\rho(f,1)=r ,\n\\]\nwith $\\P(W=0)=\\P(W=1)=1/2$.  Now let us check that our $\\rho$ and $W$ satisfy \\hyperref[E:RMRProbrho]{Equation~\\ref*{E:RMRProbrho}}:\n\\begin{eqnarray*}\n\\bordermatrix{~ & r & f \\cr\nr & \\P \\left( \\{ \\rho (r,W) = r \\} \\right) & \\P \\left( \\{ \\rho (r,W) = f \\} \\right) \\cr\nf & \\P \\left( \\{ \\rho (f,W) = r \\} \\right) & \\P \\left( \\{ \\rho (f,W) = f \\} \\right) }\n&=&\n\\bordermatrix{~ & r & f \\cr\nr & \\P \\left( W=0 \\right) & \\P \\left( W=1 \\right) \\cr\nf & \\P \\left( W=1 \\right) & \\P \\left( W=0 \\right)} \\\\\n&=&\n\\bordermatrix{~ & r & f \\cr\nr & 1/2 & 1/2\\cr\nf & 1/2 &1/2}\n=\nP \\enspace .\n\\end{eqnarray*}\nThus, by \\hyperref[P:MCFromRMR]{Proposition~\\ref*{P:MCFromRMR}} we can obtain Freddy's Markov chain $\\left(X_t\\right)_{t\\in \\Zz_+}$ by initialising $X_0 \\sim \\mu_0=(1,0)$, i.e., setting $X_0=r$ since Freddy starts at $r$, and defining\n\\[\nX_t = \\rho(X_{t-1},W_t), \\quad \\text{for all } t \\geq 1, \\text{ where, } W_1,W_2,\\ldots \\overset{IID}{\\sim} \\bernoulli(1/2) \\text{ RV} \\enspace .\n\\]\nIn other words, we can simulate a sequence of states or lily pads visited by Freddy by merely doing independent $\\bernoulli(1/2)$ trials and use the mapping $\\rho$.  A \\Matlab implementation of this RMR $\\rho$ as a \\Matlab function is:\n\\VrbMf[label=RMR1OfFairFreddy.m]{scripts/RMR1OfFairFreddy.m}\nWe can simulate one realisation of the first two states $(x_0,x_1)$ visited by $(X_0,X_1)$ as follows:\n\\begin{VrbM}\n>> % set PRNG to be twister with seed 19731511\n>> RandStream.setDefaultStream(RandStream('mt19937ar','seed',19731511));\n>> x0 = 'r' % set x_0 = 'r'\nx0 = r\n>> w1 = floor( rand + 0.5 ) % a Bernoulli(0.5) trial\nw1 =     0\n>> x1 = RMR1OfFairFreddy(x0,w1) % x_1 = rho(x_0,w1) is the state at time t=1\nx1 = r\n\\end{VrbM}\nWe can simulate one realisation of the first 10 states $(x_0,x_1,\\ldots,x_9)$ visited by $(X_0,X_1,\\ldots, X_9)$ using a for loop as follows:\n\\begin{VrbM}\n>> % set PRNG to be twister with seed 19731511\n>> RandStream.setDefaultStream(RandStream('mt19937ar','seed',19731511));\n>> x0 = 'r' % set x_0 = 'r'\nx0 = r\n>> xt = x0; % current state x_t is x_0\n>> Visited = x0; % initialise the variable Visited to hold the visited states\n>> for t = 1:9 % start a for loop for t = 1,2,...,9\nxt = RMR1OfFairFreddy(xt, floor(rand+0.5) ); % update the current state at t\nVisited = strcat(Visited,',',xt); % store the visited state in string Visited\nend\n>> Visited % disclose the string of visited state separated by commas\nVisited = r,r,f,f,r,r,f,f,f,r\n\\end{VrbM}\nIf we change the seed to some other number and repeat the code above, we will get another realisation of visits $(x_0,x_1,\\ldots,x_9)$ of $(X_0,X_1,\\ldots,X_9)$.  However, there are many distinct RMRs of the same transition matrix $P$.  For example, we can define a new RMR $\\rho^\\prime$ from our first RMR $\\rho$ for $P$ by $\\rho^\\prime(x,w)=\\rho(x,1-w)$.  The reader should check that $\\rho^\\prime$ also satisfies \\hyperref[E:RMRProbrho]{Equation~\\ref*{E:RMRProbrho}} with $W \\sim Bernoulli(1/2)$. But note that even for the same seed and the same PRNG the sequence of states $(x_0,x_1,\\ldots,x_9)$ visited by $(X_0,X_1,\\ldots,X_9)$ under the new RMR $\\rho^\\prime$ is different from that of the original RMR $\\rho$:\n\\begin{VrbM}\n>> % set PRNG to be twister with seed 19731511\n>> RandStream.setDefaultStream(RandStream('mt19937ar','seed',19731511));\n>> x0 = 'r' % set x_0 = 'r'\nx0 = r\n>> xt = x0; % current state x_t is x_0\n>> Visited = x0; % initialise the variable Visited to hold the visited states\n>> for t = 1:9 % start a for loop for t = 1,2,...,9\nxt = RMR1OfFairFreddy(xt, 1-floor(rand+0.5) ); % update the current state at t with new RMR rho'\nVisited = strcat(Visited,',',xt); % store the visited state in string Visited\nend\n>> Visited % disclose the string of visited state separated by commas under new RMR rho'\nVisited = r,f,f,r,r,f,f,r,f,f\n\\end{VrbM}\t\n\\end{example}\n\n\\begin{prop}[Existence and non-uniqueness of RMR]\nEvery transition matrix $P$ on a finite state space $\\Xz$ has a random mapping representation (RMR) that is not necessarily unique.\n\\begin{proof}\nLet $\\Xz = \\{s_1,s_2,\\ldots,s_k\\}$ be sequentially accessible by $\\psi(i)=s_i :  \\{1,2,\\ldots,k\\} \\to \\Xz)$.   We will prove the proposition constructively via the inversion sampler for $\\Xz$-valued family of $\\psi$-transformed $\\demoivre$ RVs.  Let the auxiliary RV $W$ be $\\uniform(0,1)$ with $\\Wz=[0,1]$ and let $\\rho(x,w): \\Xz \\times \\Wz \\to \\Xz$ be given by $F^{[-1]}(u;\\theta_1,\\theta_2,\\ldots,\\theta_k)$ of \\hyperref[E:deMoivreInverseDF]{Equation~\\ref*{E:deMoivreInverseDF}}, the inverse DF of the $\\demoivre(\\theta_1,\\theta_2,\\ldots,\\theta_k)$ RV, as follows:\n\\[\n\\rho(x,w) = \\psi \\left( F^{[-1]}\\left(w; P(x,s_1), P(x,s_2), \\ldots, P(x,s_k) \\right) \\right), \\quad \\text{for each } x \\in \\Xz \\enspace .\n\\]\nThen, by construction, this $\\rho$ is indeed an RMR of $P$ since\n\\[\n\\P \\left( \\{ \\rho(x,W)=y \\} \\right) = P(x,y) \\quad \\text{for each } (x,y) \\in \\Xz^2 \\enspace .\n\\]\nNon-uniqueness is established by constructing another RMR for $P$ as $\\rho^\\prime(x,w) = \\rho(x,1-w)$.\n\\end{proof}\n\\end{prop}\n\n\\begin{labwork}[Markov chain from $\\{\\demoivre(P(x,.))\\}_{x\\in\\Xz}$ RVs]\\label{LW:MCSimBydeMoivre}\nLet us implement a function that will take a transition matrix $P$ as input and produce a sequence of $n$ states $(x_0,x_1,\\ldots,x_{n-1})$ visited by the corresponding Markov chain $(X_0,X_1,\\ldots, X_n)$ using the function in the following M-file.\n\\VrbMf[label=MCSimBydeMoivre.m]{scripts/MCSimBydeMoivre.m}\n\\end{labwork}\n\n\\begin{simulation}[Another simulation of Freddy's jumps]\\label{SIM:FlippantFreddyByMCSimBydeMoivre}\nLet us simulate a sequence of 10 jumps of Flippant Freddy with fair dice and coin by using the function {\\tt MCSimBydeMoivre} defined in \\hyperref[LW:MCSimBydeMoivre]{Labwork~\\ref*{LW:MCSimBydeMoivre}} as follows:\n\\begin{VrbM}\n>> % set PRNG to be twister with seed 19731511\n>> RandStream.setDefaultStream(RandStream('mt19937ar','seed',19731511));\n>> MCSimBydeMoivre(1,[0.5 0.5; 0.5 0.5], 10)\nans =     1     1     2     1     2     1     2     1     1     2\n\\end{VrbM}\nHere we need to further transform the output by $\\psi: \\{1,2\\} \\to \\{r,f\\}$ with $\\psi(1)=r$ and $\\psi(2)=f$.\n\\end{simulation}\n\n\\begin{labwork}[Markov chain from $\\{\\demoivre(P(x,.))\\}_{x\\in\\Xz}$ RVs by Recursion]\\label{LW:MCSimBydeMoivreRecurse}\nLet us implement a recursive function that will take a transition matrix $P$ as input and produce a sequence of $n$ states $(x_0,x_1,\\ldots,x_{n-1})$ visited by the corresponding Markov chain $(X_0,X_1,\\ldots, X_n)$ using the function in the following M-file.\n\\VrbMf[label=MCSimBydeMoivreRecurse.m]{scripts/MCSimBydeMoivreRecurse.m}\nNow, let us compare this recursive function to the function {\\tt MCSimBydeMoivre} defined in \\hyperref[LW:MCSimBydeMoivre]{Labwork~\\ref*{LW:MCSimBydeMoivre}} as follows:\n\\VrbMf[label=CompareMCSimBydeMoivreMethods.m]{scripts/CompareMCSimBydeMoivreMethods.m}\n\\begin{VrbM}\n>> CompareMCSimBydeMoivreMethods\nP =\n    0.3333    0.6667\n    0.2500    0.8000\ninitial =\n     2\nVisitByMethod1 =\n     2     2     2     1     2     2     1     1     2     2     2     1\nVisitByMethod2 =\n     2     2     2     1     2     2     1     1     2     2     2     1\n\\end{VrbM}\nTherefore, both methods produce the same output.  The recursive version of the function is more versatile and useful in the sequel.\n\\end{labwork}\n\n\\begin{simulation}\\label{SIM:FreddyGoldCoinRMR}\nUsing the function {\\tt MCSimBydeMoivre} of \\hyperref[LW:MCSimBydeMoivre]{Labwork~\\ref*{LW:MCSimBydeMoivre}} simulate twenty states visited by the Markov chain in \\hyperref[EXR:FreddyGoldCoin]{Exercise~\\ref*{EXR:FreddyGoldCoin}}.\n\\end{simulation}\n\n\\begin{simulation}[Drunkard's walk around the block]\\label{SIM:DrunkardsWalkBlock}\nConsider the Markov chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ on $\\Xz=\\{0,1,2,3\\}$ with initial distribution $\\BB{1}_{\\{3\\}}(x)$ and transition matrix \n$$P = \n\\bordermatrix{~ & 0 & 1 & 2 & 3 \\cr \n0 & 0 & 1/2 & 0 & 1/2\\cr\n1 & 1/2 & 0 & 1/2 & 0\\cr\n2 & 0 & 1/2 & 0 & 1/2\\cr\n3 & 1/2 & 0 & 1/2 & 0 } \\enspace .\n$$\nDraw the transition diagram for this Markov chain.  Do you see why this chain can be called the ``drunkard's walk around the block''? Using the function {\\tt MCSimBydeMoivre} of \\hyperref[LW:MCSimBydeMoivre]{Labwork~\\ref*{LW:MCSimBydeMoivre}} simulate a sequence of ten states visited by the drunkard (don't forget to subtract $1$ from the output of {\\tt MCSimBydeMoivre} since $\\psi(i)=i-1$ here). \n\\end{simulation}\n\nThere are many distinct and interesting RMRs of any given transition matrix $P$ beyond that constructed in the proof above.  Good RMRs will typically simplify the simulation of a Markov chain.\nLet us consider examples of Markov chains that can be simulated by simpler methods.\n\n\\begin{example}[Jukes \\& Cantor Model of DNA mutation]  The ``blueprint'' of organisms on earth are typically given by a long sequence of deoxyribonucleic acid or DNA.  A DNA sequence of length $n$ can be thought of as a string made up of $n$ alphabets from the set of four nucleotides $\\{a,c,g,t\\}$.  For example a DNA sequence of length $3$ is $agg$ and another is $act$.  When an organism goes through time to ``stay alive'' it has to copy its DNA.  This copying process is not perfect and mistakes or mutations are made.  We can look at a particular position of a DNA sequence and keep track of its mutations using a simple Markov chain due to Jukes and Cantor [Jukes TH and Cantor CR (1969) Evolution of protein molecules. In Munro HN, editor, Mammalian Protein Metabolism, pp. 21-132, Academic Press, New York.] with the following transition probability matrix:\n\\[\nP = \n\\bordermatrix{~ & a & c & g & t \\cr\na & 0 & \\frac{1}{3} & \\frac{1}{3} & \\frac{1}{3} \\cr\nc & \\frac{1}{3} & 0 & \\frac{1}{3} & \\frac{1}{3} \\cr\ng & \\frac{1}{3} & \\frac{1}{3} & 0 & \\frac{1}{3} \\cr\nt & \\frac{1}{3}  & \\frac{1}{3} & \\frac{1}{3} & 0} \\enspace .\n\\]\nSuppose you initially observe the particular position of a DNA sequence at state $c$ and want to simulate a sequence of states  visited due to mutation under this Markov chain model.   We can achieve this by improvising the inversion sampler for the equi-probable $\\demoivre(1/3,1/3,1/3)$ RV (\\hyperref[A:SimdeMoivreEqui]{Algorithm~\\ref*{A:SimdeMoivreEqui}}) in the following RMR:\n\\[\n\\rho(x,U): \\{a,c,g,t\\} \\times [0,1] \\to \\{a,c,g,t\\}, \\quad\n\\rho(x,U) = \\psi_x \\left( \\lceil 3 U \\rceil \\right), \\quad \nU \\sim \\uniform(0,1) \\enspace ,\n\\] \nwith any fixed bijection $\\psi_x(i) : \\{1,2,3\\} \\to  \\{a,c,g,t\\} \\setminus \\{x\\}$ for each $x \\in \\{a,c,g,t\\}$.  \nThen we can produce a sequence of visited states as follows:\n\\[\nX_0 \\gets c, \\quad X_i \\gets \\rho\\left( X_{i-1}, U_i \\right), \\quad i=1,2,\\ldots \\enspace .\n\\]\n\\end{example}\n\n\\begin{example}[Six Lounges]\\label{EX:SixLounges}  Suppose there are six lounges with  doors that allow you to go only in one direction.  These lounges are labelled by $1$, $2$, $3$, $4$, $5$ and $6$ and form our state space $\\Xz$ with one-way-doors as shown in \\hyperref[F:SixLounges]{Figure~\\ref*{F:SixLounges}}.  \n\\begin{figure}[htbp]\n\\caption{Transition diagram over six lounges (without edge probabilities).\\label{F:SixLounges}}\n\\centering \\mbox{\\includegraphics[width=4.5in]{figures/SixLounges}} \n\\end{figure}\nEvery hour an alarm rings and it can be heard in all six lounges.  In each lounge $i \\in \\{1,2,3,4,5\\}$ there is a fair $i$-sided polyhedral cylinder whose $i$ faces are marked with lounge numbers $1,2,\\ldots,i$ but in lounge $6$ there is a hexagonal cylinder with all six faces marked by $6$.  Suppose you start from lounge number $1$.  When the hourly alarm rings you toss the ployhedral cylinder in the current lounge over the floor.  When the cylinder comes to rest, you note the number on the face that touches the floor and go to the lounge labelled by this number.  \nThis scheme of lounge hopping can be formalised as a Markov chain starting at lounge number $1$ and evolving according to the  transition matrix $P$:\n$$P = \n\\bordermatrix{ ~ & 1 & 2 & 3 &  4 & 5 & 6 \\cr \n1 & \\frac{1}{2} & \\frac{1}{2} & 0 & 0 & 0 & 0 \\cr\n2 & \\frac{1}{3} & \\frac{1}{3} & \\frac{1}{3} & 0 & 0 & 0 \\cr\n3 & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} & \\frac{1}{4} & 0 & 0 \\cr\n4 & \\frac{1}{5} & \\frac{1}{5} & \\frac{1}{5} & \\frac{1}{5} & \\frac{1}{5} & 0 \\cr\n5 & \\frac{1}{6} & \\frac{1}{6} & \\frac{1}{6} & \\frac{1}{6} & \\frac{1}{6} & \\frac{1}{6} \\cr\n6 & 0 & 0 & 0 & 0 & 0 & 1 } \\enspace .\n$$\nThe inversion samplers for the family of equi-probable $\\{\\demoivre(1/i,1/i,\\ldots,1/i)\\}_{i \\in \\{1,2,\\ldots,5\\}}$ RVs (\\hyperref[A:SimdeMoivreEqui]{Algorithm~\\ref*{A:SimdeMoivreEqui}}) and the $\\pointmass(6)$ RV (\\hyperref[SIM:PointMass]{Simulation~\\ref*{SIM:PointMass}}) can be combined in the random mapping representation:\n$$\n \\rho(i,U): \\Xz \\times [0,1] \\to \\Xz, \\quad \\rho(i,U) = \\lceil i U \\rceil \\, \\BB{1}_{\\{1,2,3,4,5\\}} (i) + 6 \\, \\BB{1}_{\\{6\\}}(i), \\quad U \\sim \\uniform(0,1) \\enspace ,$$\nin order to simulate a sequence of states from this markov chain as follows:\n\\begin{equation}\\label{E:SimulateSixLounges}\nX_0 \\gets 1, \\quad X_i \\gets \\rho(X_{i-1},U_i), \\quad i=1,2,\\ldots \\enspace .\n\\end{equation}\n\\end{example}\n\n\\begin{simulation}[Trapped in lounge $6$]\\label{SIM:TrappedinLounge6}\nImplement the Algorithm described in \\hyperref[E:SimulateSixLounges]{Equation~\\ref*{E:SimulateSixLounges}} in a \\Matlab program to simulate the first ten states visited by the Markov chain in \\hyperref[EX:SixLounges]{Example~\\ref*{EX:SixLounges}}.  Recall the ``Hotel California'' character of  lounge $6$ -- {\\em  you can check out anytime you like, but you can never leave}!  Repeat this simulation $1000$ times and find the fraction of times your are not trapped in lounge $6$ by the  tenth time step. \n\\end{simulation}\n\n\\begin{exercise}[Drunkard's walk around a polygonal block with $k$ corners]\\label{EXR:DrunkardWalkOnKGon}\nCan you think of another way to simulate the ``drunkard's walk around a polygonal block with $k$ corners'' labelled by $0,1,\\ldots, k-1$ that is more efficient than using the {\\tt MCSimBydeMoivre} function which  relies on the {\\tt SimdeMoivreOnce} function that implements \\hyperref[A:SimdeMoivre]{Algorithm~\\ref*{A:SimdeMoivre}} with an average-case efficiency that is linear in $k$?\\\\  {\\scriptsize Hint: think of the drunkard tossing a fair coin to make his decision of where to go next from each corner and arithmetic mod $k$.}\n\\end{exercise}\n\n\\section{Irreducibility and Aperiodicity}\\label{S:IrredAperiod}\nThe utility of our mathematical constructions with Markov chains depends on a delicate balance between generality and specificity.  We introduce two specific conditions called irreducibility and aperiodicity that make Markov chains more useful to model real-word phenomena.\n\n\n\\begin{definition}[Communication between states]\\label{D:Communication} Let $(X_t)_{t\\in\\Zz_+}$ be a homogeneous Markov chain with transition matrix $P$ on state space $\\Xz:=\\{s_1,s_2,\\ldots,s_k\\}$.  \nWe say that a state $s_i$ {\\bf communicates} with a state $s_j$ and write $s_i \\rightarrow s_j$ or $s_j \\leftarrow s_i$ if there exists an $\\eta(s_i,s_j) \\in \\Nz$ such that:\n\\[\n\\P \\left( X_{t+\\eta(s_i,s_j)} = s_j | X_t = s_i \\right) = P^{\\eta(s_i,s_j)} (s_i, s_j) > 0 \\enspace .\n\\] \nIn words, $s_i$ communicates with $s_j$ if you can eventually reach $s_j$ from $s_i$.  If $P^{\\eta} (s_i, s_j)=0$ for every $\\eta \\in \\Nz$ then we say that $s_i$ {\\bf does not communicate} with $s_j$ and write $s_i  \\nrightarrow s_j$ or $s_j  \\nleftarrow s_i$.\n\nWe say that two states $s_i$ and $s_j$ {\\bf intercommunicate} and write $s_i \\leftrightarrow s_j$ if $s_i \\rightarrow s_j$ and $s_j \\rightarrow s_i$.  In words, two states intercommunicate if you can eventually reach one from another and vice versa.  When $s_i$ and $s_j$ do not intercommunicate we write $s_i \\nleftrightarrow s_j$.\n\\end{definition}\n\n\\begin{definition}[Irreducible]\\label{D:Irreducible}\nA homogeneous Markov chain $(X_t)_{t\\in\\Zz_+}$ with transition matrix $P$ on state space $\\Xz:=\\{s_1,s_2,\\ldots,s_k\\}$ is said to be {\\bf irreducible} if $s_i \\leftrightarrow s_j$ for each $(s_i,s_j) \\in \\Xz^2$.  Otherwise the chain is said to be {\\bf reducible}.\n\\end{definition}\n\nWe have already seen examples of reducible and irreducible Markov chains.  For example, Flippant Freddy's family of Markov chains with the $(p,q)$-parametric family of transition matrices, $\\{P_{(p,q)} : (p,q) \\in [0,1]^2\\}$, where each $P_{(p,q)}$ is given by \\hyperref[E:FlippantFreddyP]{Equation~\\ref*{E:FlippantFreddyP}}.  If $(p,q) \\in (0,1)^2$, then the corresponding Markov chain is irreducible because we can go from rollopia to flippopia or vice versa in just one step with a positive probability.  Thus, the Markov chains with transition matrices in $\\{P_{(p,q)} : (p,q) \\in (0,1)^2\\}$ are irreducible.  But if $p$ or $q$ take probability values at the boundary of $[0,1]$, i.e., $p \\in \\{0,1\\}$ or $q \\in \\{0,1\\}$ then we have to be more careful because we may  never get from at least one state to the other and the corresponding Markov chains may be reducible.   For instance, if $p=0$ or $q=0$ then we will be stuck in either rollopia or flippopia, respectively.  However, if $p=1$ and $q \\neq 0$ or $q=1$ and $p \\neq 0$ then we can get from each  state to the other.  Therefore,  only the transition matrices in $\\left\\{P_{(p,q)} : p \\in \\{0\\} \\text{ or } q \\in \\{0\\}\\right\\}$ are reducible.\n\nThe simplest way to verify whether a Markov chain is irreducible is by looking at its transition diagram (without the positive edge probabilities) and checking that from each state there is a sequence of arrows leading to any other state.  For instance, from the transition diagram in \\hyperref[F:SixLounges]{Figure~\\ref*{F:SixLounges}} of the lounge-hopping Markov chain of \\hyperref[EX:SixLounges]{Example~\\ref*{EX:SixLounges}}, it is clear that if you start at state $6$ you cannot find any arrow going to any other state.  Therefore, the chain is reducible since $6 \\nrightarrow i$ for any $i \\in \\{1,2,3,4,5\\}$.\n\n\\begin{exercise}\\label{EXR:ExsIrreducibleOrNot}\nRevisit all the Markov chains we have considered up to now and determine whether they are reducible or irreducible by checking that from each state there is a sequence of arrows leading to any other state in their transition graphs.\n\\end{exercise}\n\n\\begin{definition}[Return times and period]\nLet $\\Tz(x) := \\{t \\in \\Nz : P^t(x,x)>0\\}$ be the set of {\\bf possible return times} to the starting state $x$.  The {\\bf period} of state $x$ is defined to be $\\gcd(\\Tz(x))$, the greatest common divisor of $\\Tz(x)$.  When the period of a state $x$ is $1$, i.e., $\\gcd(\\Tz(x))=1$, then $x$ is said to be an {\\bf aperiodic state}.\n\\end{definition}\n\n\\begin{prop}\nIf the Markov chain $(X_t)_{t\\in\\Zz_+}$ with transition matrix $P$ on state space $\\Xz$ is irreducible then $\\gcd(\\Tz(x)) = \\gcd(\\Tz(y))$ for any $(x,y) \\in \\Xz^2$.\n\\begin{proof}\nFix any pair of states $(x,y) \\in \\Xz^2$.  Since, $P$ is irreducible, $x \\leftrightarrow y$ and therefore there exists natural numbers $\\eta(x,y)$ and $\\eta(y,x)$ such that $P^{\\eta(x,y)}(x,y)>0$ and $P^{\\eta(y,x)}(y,x)>0$.  Let $\\eta' = \\eta(x,y)+\\eta(y,x)$ and observe that $\\eta' \\in \\Tz(x) \\cap \\Tz(y)$, $\\Tz(x) \\subset \\Tz(y) - \\eta' := \\{t-\\eta' : t \\in \\Tz(y)\\}$ and $\\gcd(\\Tz(y))$ divides all elements in $\\Tz(x)$.  Thus, $\\gcd(\\Tz(y)) \\leq \\gcd(\\Tz(x))$.  By a similar argument we can also conclude that $\\gcd(\\Tz(x)) \\leq \\gcd(\\Tz(y))$.  Therefore $\\gcd(\\Tz(x))=\\gcd(\\Tz(y))$.\n\\end{proof}\n\\end{prop}\n\n\\begin{definition}[Aperiodic]\nA Markov chain $(X_t)_{t\\in\\Zz_+}$ with transition matrix $P$ on state space $\\Xz$ is said to be {aperiodic} if all of its states are aperiodic, i.e., $\\gcd(\\Tz(x))=1$ for every $x \\in \\Xz$.  If a chain is not aperiodic, we call it {\\bf periodic}.\n\\end{definition}\n\nWe have already seen example of irreducible Markov chains that  were either periodic or aperiodic.  For instance, Freddy's Markov chain with $(p,q) \\in (0,1)^2$ is aperiodic since the period of either of its two states is given by $\\gcd(\\{1,2,3,\\ldots\\})=1$.  However, the Markov chain model for a drunkard's walk around a block over the state space $\\{0,1,2,3\\}$ (\\hyperref[SIM:DrunkardsWalkBlock]{Simulation~\\ref*{SIM:DrunkardsWalkBlock}}) is periodic because you can only return to the starting state in an even number of time steps and \n$$\n\\gcd(\\Tz(0))=\\gcd(\\Tz(1))=\\gcd(\\Tz(2))=\\gcd(\\Tz(3))= \\gcd \\left( \\{2,4,6,\\ldots\\} \\right) =2 \\neq 1 \\enspace .\n$$\n\n\\begin{exercise}\\label{EXR:DrunkardsWalkOnKGonIrredAperiod}\nShow that the Markov chain corresponding to a drunkard's walk around a polygonal block with $k$ corners is irreducible for any integer $k>1$.  Show that it is aperiodic only when $k$ is odd and has period $2$ when $k$ is even.\n\\end{exercise}\n\n\\begin{prop}\\label{P:AdditionNonlattice} Let $A=\\{a_1,a_2,\\ldots\\} \\subset \\Nz$ that satisfies the following two conditions:\n\\begin{enumerate}\n\\item $A$ is a {\\bf nonlattice}, meaning that $\\gcd(A)=1$ and\n\\item $A$ is closed undur addition, meaning that if $(a,a') \\in A^2$ then $a+a' \\in A$.\n\\end{enumerate}\nThen there exists a positive integer $\\eta < \\infty$ such that $n \\in A$ for all $n \\geq \\eta$.\n\\begin{proof}\nSee Proofs of Lemma 1.1, Lemma 1.2 and Theorem 1.1 in Appendix of {\\em Pierre Br\\'emaud, Markov Chains, Gibbs Fields, Monte Carlo Simulation, and Queues, Springer, 1999}.\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf the Markov chain $(X_t)_{t\\in\\Zz_+}$ with transition matrix $P$ on state space $\\Xz$ is irreducible and aperiodic then there is an integer $\\tau$ such that $P^t(x,x)>0$ for all $t \\geq \\tau$ and all $x \\in \\Xz$.\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}\nIf the Markov chain $(X_t)_{t\\in\\Zz_+}$ with transition matrix $P$ on state space $\\Xz$ is irreducible and aperiodic then there is an integer $\\tau$ such that $P^t(x,y)>0$ for all $t \\geq \\tau$ and all $(x,y) \\in \\Xz^2$.\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{prop}\n\n\\begin{exercise}[King's random walk on a chessboard]\\label{EXR:KingRWChessBoard}\nConsider the squares in the chessboard as the state space $\\Xz = \\{ 0,1,2,\\ldots,7\\}^2$ with a randomly walking black king, i.e., for each move from current state $(u,v) \\in \\Xz$ the king chooses one of his $k(u,v)$ possible moves uniformly at random.  \nIs the Markov chain corresponding to the randomly walking black king on the chessboard irredicible and/or aperiodic?  \n%Write a \\Matlab script to simulate a sequence of $n$ states visited by the king if he started from $(0,0)$, the most south-west state on the chessboard.\n\\end{exercise}\n\n\\begin{exercise}[King's random walk on a chesstorus]\\label{EXR:KingRWChessTorus}\nWe can obtain a chesstorus from a pliable chessboard by identifying the eastern edge with the western edge (roll the chessboard into a cylinder) and then identifying the northern edge with the southern edge (gluing the top and bottom end of the cylinder together by turning into a doughnut or torus).  Consider the squares in the chesstorus as the state space $\\Xz = \\{ 0,1,2,\\ldots,7\\}^2$ with a randomly walking black king, i.e., for each move from current state $(x,y) \\in \\Xz$ the king chooses one of his $8$ possible moves uniformly at random according to the scheme: $X_t \\gets X_{t-1}+ W_t$, where $W_t$ is independent and identically distributed as follows:\n\\[ \n\\P(W_t = w) = \n\\begin{cases}\n\\frac{1}{8} & \\text{if } w \\in \\left\\{ (1,1), (1,0), (1,-1), (0,-1), (-1,-1), (-1,0), (-1,1), (0,1) \\right\\} , \\\\\n0 & \\text{ otherwise}.\n\\end{cases}\n\\]\nIs the Markov chain corresponding to the randomly walking black king on the chesstorus irredicible and/or aperiodic?  Write a \\Matlab script to simulate a sequence of $n$ states visited by the king if he started from $(0,0)$ on the chesstorus.\n\\end{exercise}\n\n\\section{Stationarity}\\label{S:Stationarity}\n\nWe are interested in statements about a Markov chain that has been running for a long time.  \nFor any nontrivial Markov chain $(X_0,X_1,\\ldots)$ the value of $X_t$ will keep fluctuating in the state space $\\Xz$ as $t \\to \\infty$ and we cannot hope for convergence to a fixed point state $x^* \\in \\Xz$ or to a $k$-cycle of states $\\{x_1,x_2,\\ldots,x_k\\} \\subset \\Xz$.  However, we can look one level up into the space of probability distributions over $\\Xz$ that give the probability of the Markov chain visiting each state $x \\in \\Xz$ at time $t$, and hope that the distribution of $X_t$ over $\\Xz$ settles down as $t \\to \\infty$.  The Markov chain convergence theorem indeed sattes that the distribution of $X_t$ over $\\Xz$ settles down as $t \\to \\infty$, provided the Markov chain is irreducible and aperiodic.\n\n\\begin{definition}[Stationary distribution]\nLet $\\left( X_t \\right)_{t \\in \\Zz_+}$ be a Markov chain with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$ and transition matrix $P = \\left( P(x,y) \\right)_{(x,y) \\in \\Xz^2}$.  A row vector $$\\pi = \\left( \\pi(s_1), \\pi(s_2), \\ldots, \\pi(s_k) \\right) \\in \\Rz^{1\\times k}$$ is said to be a {\\bf stationary distribution} for the Markov chain, if it satisfies the conditions of being:\n\\begin{enumerate}\n\\item {\\em a probability distribution}: $\\pi(x) \\geq 0$ for each $x \\in \\Xz$ and $\\sum_{x \\in \\Xz} \\pi(x) = 1$, and\n\\item {\\em a fixed point}: $\\pi P = \\pi$, i.e., $\\sum_{x \\in \\Xz} \\pi(x) P(x,y) = \\pi(y)$ for each $y \\in \\Xz$.\n\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Hitting times]\nIf a Markov chain $\\left( X_t \\right)_{t \\in \\Zz_+}$ with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$ and transition matrix $P = \\left( P(x,y) \\right)_{(x,y) \\in \\Xz^2}$ starts at state $x$, then we can define the {\\bf hitting time}\n\\[\nT(x,y) = \\min \\{ t \\geq 1: X_t = y \\} \\enspace .\n\\]\nand let $T(x,y) = \\min \\{\\} = \\infty$ if the Markov chain never visits $y$ after having started from $x$.  Let the {\\bf  mean hitting time} \n\\[\n\\tau(x,y) := \\E(T(x,y)) ,\n\\]\nbe the expected time taken to reach $y$ after having started at $x$.  Note that $\\tau(x,x)$ is the {\\bf mean return time} to state $x$.\n\\end{definition}\n\n\\begin{prop}[Hitting times of irreducible aperiodic Markov chains]  \nIf  $\\left( X_t \\right)_{t \\in \\Zz_+}$ is an irreducible aperiodic Markov chain with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$, transition matrix $P = \\left( P(x,y) \\right)_{(x,y) \\in \\Xz^2}$ then for any pair of states ${(x,y) \\in \\Xz^2}$,\n\\[\n\\P\\left( T(x,y) < \\infty \\right) = 1 \\enspace ,\n\\]\nand the mean hitting time is finite, i.e.,\n\\[\n\\tau(x,y) < \\infty \\enspace .\n\\]\n\\end{prop}\n\n\\begin{prop}[Existence of Stationary distribution]\nFor any irreducible and aperiodic Markov chain there exists at least one stationary distribution.\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{prop}\n\n\\begin{definition}[Total variation distance]\\label{D:TotVarDist}\nIf $\\nu_1:=\\left(\\nu_1(x)\\right)_{x\\in \\Xz}$ and $\\nu_2 := \\left(\\nu_2(x)\\right)_{x\\in \\Xz}$ are elements of $\\mathcal{P}(\\Xz)$, the set of all probability distributions on $\\Xz:=\\{s_1,s_2,\\ldots,s_k\\}$, then we define the {\\bf total variation distance} between $\\nu_1$ and $\\nu_2$ as\n\\begin{equation}\\label{E:TotVarDist}\n\\dtv \\left( \\nu_1, \\nu_2 \\right) := \\frac{1}{2} \\sum_{x \\Xz} \\abs \\left( \\nu_1(x) - \\nu_2(x) \\right), \\quad \\dtv : \\mathcal{P}(\\Xz) \\times \\mathcal{P}(\\Xz)  \\to [0,1] \\enspace .\n\\end{equation}\nIf $\\nu_1, \\nu_2, \\ldots$ and $\\nu$ are probability distributions on $\\Xz$, then we say that $\\nu_t$ {\\bf converges in total variation} to $\\nu$ as $n \\to \\infty$ and write $\\nu_t  \\overset{\\mathsf{TV}}{\\longrightarrow} \\nu$, if\n\\[\n\\lim_{t \\to \\infty} \\dtv \\left( \\nu_t, \\nu \\right) = 0 \\enspace .\n\\]\nObserve that if $\\dtv(\\nu_1,\\nu_2)=0$ then $\\nu_1=\\nu_2$. The constant $1/2$ in \\hyperref[E:TotVarDist]{Equation~\\ref*{E:TotVarDist}} ensures that the range of $\\dtv$ is in $[0,1]$.  If $\\dtv(\\nu_1,\\nu_2)=1$ then $\\nu_1$ and $\\nu_2$ have disjoint  supports, i.e., we can partition $\\Xz$ into $\\Xz_1$ and $\\Xz_2$, i.e., $\\Xz=\\Xz_1 \\cup \\Xz_2$ and $\\Xz_1 \\cap \\Xz_2 = \\emptyset$, such that $\\sum_{x \\in \\Xz_1} \\nu_1(x)=1$ and  $\\sum_{x \\in \\Xz_2} \\nu_2(x)=1$.  The total variation distance gets its name from the following natural interpretation:\n\\[\n\\dtv \\left( \\nu_1, \\nu_2 \\right) = \\max_{A \\subset \\Xz} \\abs \\left( \\nu_1(A) - \\nu_2(A) \\right) \\enspace .\n\\]\nThis interpretation means that the total variation distance between $\\nu_1$ and $\\nu_2$ is the maximal difference in probabilities that the two distributions assign to any one event $A \\in \\sigma(\\Xz) = 2^{\\Xz}$. \n\\end{definition}\n\nIn words, \\hyperref[P:MCConvergence]{Proposition~\\ref*{P:MCConvergence}} says that if you run the chain for a sufficiently long enough time $t$, then, regardless of the initial distribution $\\mu_0$, the distribution at time $t$ will be close to the stationary distribution $\\pi$.  This is referred to as the Markov chain {\\bf approaching equilibrium} or {\\bf stationarity} as $t \\to \\infty$.  \n\n\\begin{prop}[Markov chain convergence theorem]\\label{P:MCConvergence}\nLet $\\left( X_t \\right)_{t \\in \\Zz_+}$ be an irreducible aperiodic Markov chain with state space $\\Xz=\\{s_1,s_2,\\ldots,s_k\\}$, transition matrix $P = \\left( P(x,y) \\right)_{(x,y) \\in \\Xz^2}$ and initial distribution $\\mu_0$.  Then for any distribution $\\pi$ which is stationary for the transition matrix $P$, we have\n\\begin{equation}\n\\mu_t \\overset{\\mathsf{TV}}{\\longrightarrow} \\pi  \\enspace .\n\\end{equation}\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{prop}\n\n\\begin{prop}[Uniqueness of stationary distribution]\\label{P:UniqueStationaryDistrn}\nAny irreducible aperiodic Markov chain has a unique stationary distribution.\n\\begin{proof}\nTBD\n\\end{proof}\n\\end{prop}\n\n\n\\begin{exercise}\\label{EXR:SixStatesWith3Blockof2}\nConsider the Markov chain on $\\{1,2,3,4,5,6\\}$ with the following transition matrix:\n\\[\nP = \n\\bordermatrix{ ~ & 1 & 2 & 3 &  4 & 5 & 6 \\cr \n1 & \\frac{1}{2} & \\frac{1}{2} & 0 & 0 & 0 & 0 \\cr\n2 & \\frac{1}{2} & \\frac{1}{2} & 0 & 0 & 0 & 0 \\cr\n3 & 0 & 0 &  \\frac{1}{4} & \\frac{3}{4} & 0 & 0  \\cr\n4 & 0 & 0 &  \\frac{3}{4} & \\frac{1}{4} & 0 & 0  \\cr\n5 & 0 & 0 &  0 & 0 & \\frac{3}{4} & \\frac{1}{4}  \\cr\n6 & 0 & 0 &  0 & 0 & \\frac{1}{4} & \\frac{3}{4}  } \\enspace .\n\\]\nShow that this chain is reducible and it has three stationary distributions:\n\\[\n(1/2,1/2,0,0,0,0), \\quad (0,0,1/2,1/2,0,0), \\quad (0,0,0,0,1/2,1/2) \\enspace .\n\\]\n\\end{exercise}\n\n\\begin{exercise}\\label{EXR:ConvexCombof2StationaryDistrns}\nIf there are two stationary distributions $\\pi$ and $\\pi'$ then show that there is a infinite family of stationary distributions $\\{\\pi_p : p \\in [0,1] \\}$, called the convex combinations of $\\pi$ and $\\pi'$.\n\\end{exercise}\n\n\\begin{exercise}\\label{EXR:ConvergengeinTVFailsforPeriodicDrunkardWalk}\nShow that for a drunkard's walk chain started at state $0$ around a polygonal block with $k$ corners labelled $\\{0,1,2,\\ldots,k-1\\}$, the state probability vector at time step $t$\n\\[\n\\mu_t \\overset{\\mathsf{TV}}{\\longrightarrow} \\pi   \n\\]\nif and only if $k$ is odd.  Explain what happens to $\\mu_t$ when $k$ is even.\n\\end{exercise}\n\n\\section{Reversibility}\n\nWe introduce another specific property called reversibility.  \nThis property will assist in conjuring Markov chains with a desired stationary distibution.\n\n\\begin{definition}[Reversible]\\label{D:Reversible}\nA probability distribution $\\pi$ on $\\Xz = \\{s_1,s_2,\\ldots,s_k\\}$ is said to be a {\\bf reversible distribution} for a Markov chain $\\left(X_t\\right)_{t\\in \\Zz}$ on $\\Xz$ with transition matrix $P$ if for every pair of states $(x,y) \\in \\Xz^2$:\n\\begin{equation}\\label{E:ReversibilityCondition}\n\\pi(x) P(x,y) = \\pi(y) P(y,x) \\enspace .\n\\end{equation}\nA Markov chain that has a reversible distribution is said to be a reversible Markov chain.\n\\end{definition}\n\nIn words, $\\pi(x) P(x,y) = \\pi(y) P(y,x)$ says that if you start the chain at the reversible distribution $\\pi$, i.e., $\\mu_0 = \\pi$, then the probability of going from $x$ to $y$ is the same as that of going from $y$ to $x$.\n\n\\begin{prop}[A reversible $\\pi$ is a stationary $\\pi$]\\label{P:ReversibleIsStationary}\nLet $\\left(X_t\\right)_{t \\in \\Zz_+}$ be a Markov chain on $\\Xz = \\{s_1,s_2,\\ldots,s_k\\}$ with transition matrix $P$.  \nIf $\\pi$ is a reversible distribution for $\\left(X_t\\right)_{t \\in \\Zz_+}$ then $\\pi$ is a stationary distribution for $\\left(X_t\\right)_{t \\in \\Zz_+}$.\n\\begin{proof}\nSuppose $\\pi$ is a reversible distribution for $\\left(X_t\\right)_{t \\in \\Zz_+}$ then $\\pi$ is a probability distribution on $\\Xz$ and $\\pi(x) P(x,y) = \\pi(y) P(y,x)$ for each $(x,y)\\in \\Xz^2$.  \nWe need to show that for any $y \\in \\Xz$ we have $$\\pi(y)=\\sum_{x\\in\\Xz}\\pi(y) P(y,x) \\enspace .$$ \nFix a $y \\in \\Xz$,\n\\begin{eqnarray*}\nLHS \n&=& \\pi(y)= \\pi(y) \\, 1 = \\pi(y) \\, \\sum_{x \\in \\Xz} P(y,x) \\text{, since $P$ is a stochastic matrix} \\\\\\\\\n&=& \\sum_{x \\in \\Xz} \\pi(y) P(y,x) = \\sum_{x \\in \\Xz} \\pi(x) P(x,y) \\text{,  by reversibility} \\\\\n&=& RHS \\enspace .\n\\end{eqnarray*}\n\\end{proof}\n\\end{prop}\n\n\n%\\section{Classical Examples}\n%\\work\n%\\subsection{Random Walks on Graphs}\n\n\\begin{definition}[Graph]\\label{D:Graph}\nA {\\bf Graph} $\\Gz := (\\Vz,\\Ez)$ consists of a {\\bf vertex set} $\\Vz := \\{v_1,v_2,\\ldots,v_k\\}$ together with an {\\bf edge set} $\\Ez := \\{e_1,e_2,\\ldots,e_l\\}$.  Each edge connects two of the vertices in $\\Vz$.  An edge $e_h$ connecting vertices $v_i$ and $v_j$ is denoted by $\\langle v_i, v_j \\rangle$.  Two vertices are {\\bf neighbours} if they share an edge.  \nThe {\\bf negihbourhood} of a vertex $v_i$ denoted by $\\nbhd(v_i):=\\left\\{v_j : \\langle v_i,v_j\\rangle \\in \\Ez \\right\\}$ is the set of neighbouring vertices of $v_i$.  \nThe number of neighbours of a vertex $v_i$ in an undirected graph is called its {\\bf degree} and is denoted by $\\deg(v_i)$.  \nNote that $\\deg(v_i) = \\# \\nbhd(v_i)$.  \nIn a graph we only allow one edge per pair of vertices but in a {\\bf multigraph} we allow more than one edge per pair of vertices.  \nAn edge can be {\\bf directed} to preserve  the order of the pair of vertices they connect or they can be {\\bf undirected}.  \nAn edge can be {\\bf weighted} by being associated with a real number called its weight.  \nWe can represent a directed graph by its {\\bf adjacency matrix} given by:\n\\[\nA := \\left( A(v_i,v_j) \\right)_{(v_i,v_j) \\in \\Vz \\times \\Vz}, \\quad \nA(v_i,v_j) = \n\\begin{cases} \n1 & \\text{if } \\  \\langle v_i, v_j \\rangle \\in \\Ez \\\\\n0 & \\text{otherwise} \\enspace .\n\\end{cases}\n\\]\nThus the adjacency matrix of an undirected graph is symmetric.  \nIn a directed graph, each vertex $v_i$ has {\\bf in-edges} that come into it and {\\bf out-edges} that go out of it.  \nThe number of in-edges and out-edges of $v_i$ is denoted by $\\ideg(v_i)$ and $\\odeg(v_i)$ respectively.  \nNote that a transition diagram of a Markov chain is a weighted directed graph and is represented by the transition probability matrix.\n\\end{definition}\n\n\\begin{model}[Random Walk on an Undirected Graph]\\label{M:RWGraph}\nA random walk on an undirected graph $\\Gz=(\\Vz,\\Ez)$ is a Markov chain with state space $\\Vz:= \\{v_1,v_2,\\ldots,v_k\\}$ and the following transition rules: if the chain is at vertex $v_i$ at time $t$ then it moves uniformly at random to one of the neighbours of $v_i$ at time $t+1$.  If $\\deg(v_i)$ is the degree of $v_i$ then the transition probabilities of this Markov chain is\n\\[\nP(v_i,v_j) = \n\\begin{cases}\n\\frac{1}{\\deg(v_i)} & \\text{if $\\langle v_i, v_j \\rangle \\in \\Ez$}\\\\\n0 & \\text{otherwise} ,\n\\end{cases}\n\\]\n\\end{model}\n\n\\begin{prop}\\label{P:RWUGpi}\nThe random walk on an undirected graph $\\Gz=(\\Vz,\\Ez)$, with vertex set $\\Vz:= \\{v_1,v_2,\\ldots,v_k\\}$ and degree sum $d = \\sum_{i=1}^k{\\deg(v_i)}$ is a reversible Markov chain with the reversible distribution $\\pi$ given by:\n\\[\n\\pi = \\left( \\frac{\\deg(v_1)}{d}, \\frac{\\deg(v_2)}{d}, \\ldots, \\frac{\\deg(v_k)}{d}  \\right) \\enspace .\n\\]\n\\begin{proof}\nFirst note that $\\pi$ is a probability distribution provided that $d > 0$.  \nTo show that $\\pi$ is reversible we need to verify \\hyperref[E:ReversibilityCondition]{Equation~\\ref*{E:ReversibilityCondition}} for each $(v_i,v_j) \\in \\Vz^2$.  \nFix a pair of states $(v_i,v_j) \\in \\Vz^2$, then\n\\begin{eqnarray*}\n\\pi(v_i) P(v_i,v_j) = \n\\begin{cases}\n\\frac{\\deg(v_i)}{d}\\frac{1}{\\deg(v_i)}=\\frac{1}{d}=\\frac{\\deg(v_j)}{d}\\frac{1}{\\deg(v_j)}=\\pi(v_j) P(v_j,v_i) & \\text{ if } \\langle v_i, v_j \\rangle \\in \\Ez\\\\\n0 = \\pi(v_j) P(v_j,v_i) & \\text{ otherwise}.\n\\end{cases}\n\\end{eqnarray*} \nBy \\hyperref[P:ReversibleIsStationary]{Proposition~\\ref*{P:ReversibleIsStationary}} $\\pi$ is also the stationary distribution.\n\\end{proof}\n\\end{prop}\n\n\\begin{exercise}\\label{EXR:DirectlyProveRWUGpi}\nProve \\hyperref[P:RWUGpi]{Proposition~\\ref*{P:RWUGpi}} by directly showing that $\\pi P = \\pi$, i.e., for each $v_i \\in \\Vz$, $\\sum_{i=1}^k \\pi(v_i) P(v_i, v_j) = \\pi(v_j)$.\n\\end{exercise}\n\n\\begin{example}[Random Walk on a regular graph]\\label{EX:RWRegGraph}\nA graph $\\Gz=(\\Vz,\\Ez)$ is called regular if every vertex in $\\Vz=\\{v_1,v_2,\\ldots,v_k\\}$ has the same degree $\\delta$, i.e., $\\deg(v_i)=\\delta$ for every $v_i \\in \\Vz$.  \nConsider the random walk on a regular graph with symmetric transition matrix \n\\[\nQ(v_i,v_j) = \n\\begin{cases} \n\\frac{1}{\\delta} & \\text{ if } \\langle v_i,v_j \\rangle \\in \\Ez \\\\\n0 & \\text{ otherwise}\n\\end{cases} \\enspace .\n\\]\nBy \\hyperref[P:RWUGpi]{Proposition~\\ref*{P:RWUGpi}}, the stationary distribution of the random walk on $\\Gz$ is the uniform distribution on $\\Vz$ given by\n\\[\n\\pi \n= \\left( \\frac{\\delta}{\\delta \\#\\Vz }, \\ldots , \\frac{\\delta}{\\delta \\#\\Vz}  \\right) \n= \\left( \\frac{1}{\\#\\Vz}, \\ldots , \\frac{1}{\\#\\Vz} \\right) \n\\enspace .\n\\]\n\\end{example}\n\n\n\\begin{example}[Triangulated Quadrangle]\\label{EX:TriangulatedQuadrangle}\nThe random walk on the undirected graph \n$$\\Gz=(\\{1,2,3,4\\}, \\{\\langle 1,2 \\rangle, \\langle 3,1 \\rangle, \\langle 2,3 \\rangle, \\langle 2,4 \\rangle, \\langle 4,3\\rangle\\})$$ depicted below with adjacency matrix $A$ is a Markov chain on $\\{1,2,3,4\\}$ with transition matrix $P$:\n$$ \nA = \n\\bordermatrix{~ & 1 & 2 & 3 & 4 \\cr\n1 & 0 & 1 & 1 & 0 \\cr\n2 & 1 & 0 & 1 & 1\\cr\n3 & 1 & 1 & 0 & 1\\cr\n4 & 0 & 1 & 1 & 0} ,\n\\quad\nP = \n\\bordermatrix{~ & 1 & 2 & 3 & 4 \\cr\n1 & 0 & \\frac{1}{2} &  \\frac{1}{2} & 0 \\cr\n2 & \\frac{1}{3} & 0 &  \\frac{1}{3} &  \\frac{1}{3} \\cr\n3 & \\frac{1}{3} &  \\frac{1}{3} & 0 &  \\frac{1}{3} \\cr\n4 & 0 &  \\frac{1}{2} &  \\frac{1}{2} & 0 } ,\n\\quad\n\\makebox{\\includegraphics[width=2.5in]{figures/TriQuadrangle}}\n\\enspace .$$ \nBy \\hyperref[P:RWUGpi]{Proposition~\\ref*{P:RWUGpi}}, the stationary distribution of the random walk on $\\Gz$ is\n\\[\n\\pi = \\left( \\frac{\\deg(v_1)}{d}, \\frac{\\deg(v_2)}{d}, \\frac{\\deg(v_3)}{d}, \\frac{\\deg(v_4)}{d} \\right) \n= \\left( \\frac{2}{10}, \\frac{3}{10}, \\frac{3}{10}, \\frac{2}{10} \\right) \\enspace .\n\\] \n\\end{example}\n\n\\begin{exercise}\\label{EXR:DrunkardAroundBlockFairReversible}\nShow that the Drunkard's walk around the block from \\hyperref[SIM:DrunkardsWalkBlock]{Simulation~\\ref*{SIM:DrunkardsWalkBlock}} is a random walk on the undirected graph $\\Gz=(\\Vz,\\Ez)$ with $\\Vz=\\{0,1,2,3\\}$ and $\\Ez=\\{\\langle 0,1 \\rangle,\\langle 1,2 \\rangle,\\langle 2,3 \\rangle,\\langle 0,3 \\rangle \\}$.  What is its reversible distribution?\n\\end{exercise}\n\n\\begin{example}[Drunkard's biased walk around the block]\\label{SIM:DrunkardsBiasedWalkBlock}\nConsider the Markov chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ on $\\Xz=\\{0,1,2,3\\}$ with initial distribution $\\BB{1}_{\\{3\\}}(x)$ and transition matrix \n$$P = \n\\bordermatrix{~ & 0 & 1 & 2 & 3 \\cr \n0 & 0 & 1/3 & 0 & 2/3\\cr\n1 & 1/3 & 0 & 2/3 & 0\\cr\n2 & 0 & 1/3 & 0 & 2/3\\cr\n3 & 1/3 & 0 & 2/3 & 0 } \\enspace .\n$$\nDraw the transition diagram for this Markov chain that corresponds to a drunkard who flips a biased coin to make his next move at each corner.  The stationary distribution is $\\pi = (1/4,1/4,1/4,1/4)$ (verify $\\pi P= \\pi$).  \n\nWe will show that $\\left(X_t\\right)_{t \\in \\Zz_+}$ is not a reversible Markov chain.  \nSine $\\left(X_t\\right)_{t \\in \\Zz_+}$ is irreducible (aperiodicity is not necessary for uniqueness of $\\pi$) $\\pi$ is the unique stationary distribution.  \nDue to \\hyperref[P:ReversibleIsStationary]{Proposition~\\ref*{P:ReversibleIsStationary}}, $\\pi$ has to be a reversible distribution in order for $\\left(X_t\\right)_{t \\in \\Zz_+}$ to be a reversible Markov chain.  \nBut reversibility fails for $\\pi$ since,\n\\[\n\\pi(0) P(0,1) = \\frac{1}{4} \\times \\frac{1}{3} = \\frac{1}{12} < \\frac{1}{6} = \\frac{1}{4} \\times \\frac{2}{3} = \\pi(1)P(1,0) \\enspace .\n\\]\n\\end{example}\n\n\\begin{exercise}\\label{EXR:PiKingRWChessTorus}\nFind the stationary distribution of the Markov chain in \\hyperref[EXR:KingRWChessTorus]{Exercise~\\ref*{EXR:KingRWChessTorus}}.\n\\end{exercise}\n\n\\begin{model}[Random Walk on a Directed Graph]\\label{M:RWDGraph}\nA random walk on a directed graph $\\Gz=(\\Vz,\\Ez)$ is a Markov chain with state space $\\Vz:= \\{v_1,v_2,\\ldots,v_k\\}$ and transition matrix given by:\n\\[\nP(v_i,v_j) = \n\\begin{cases}\n\\frac{1}{\\odeg(v_i)} & \\text{if $\\langle v_i, v_j \\rangle \\in \\Ez$}\\\\\n0 & \\text{otherwise} ,\n\\end{cases}\n\\]\n\\end{model}\n\n\\begin{example}[Directed Triangulated Quadrangle]\\label{EX:DirectedTriangulatedQuadrangle}\nThe random walk on the directed graph \n$$\\Gz=(\\{1,2,3,4\\}, \\{\\langle 1,2 \\rangle, \\langle 3,1 \\rangle, \\langle 2,3 \\rangle, \\langle 2,4 \\rangle, \\langle 4,3\\rangle\\})$$ depicted below with adjacency matrix $A$ is a Markov chain on $\\{1,2,3,4\\}$ with transition matrix $P$:\n$$ \nA = \n\\bordermatrix{~ & 1 & 2 & 3 & 4 \\cr\n1 & 0 & 1 & 0 & 0 \\cr\n2 & 0 & 0 & 1 & 1 \\cr\n3 & 1 & 0 & 0 & 0 \\cr\n4 & 0 & 0 & 1 & 0},\n\\quad\nP = \n\\bordermatrix{~ & 1 & 2 & 3 & 4 \\cr\n1 & 0 & 1 & 0 & 0 \\cr\n2 & 0 & 0 & \\frac{1}{2} & \\frac{1}{2} \\cr\n3 & 1 & 0 & 0 & 0 \\cr\n4 & 0 & 0 & 1 & 0},\n\\quad\n\\makebox{\\includegraphics[width=2.5in]{figures/DirTriQuadrangle}}\n\\enspace .$$ \n\\end{example}\n\n\\begin{exercise}\\label{EXR:DirectedTriangulatedQuadrangleNoReversiblePi}\nShow that the there is no reversible distibution for the Markov chain in \\hyperref[EX:DirectedTriangulatedQuadrangle]{Example~\\ref*{EX:DirectedTriangulatedQuadrangle}}. \n\\end{exercise}\n\n\\begin{example}[Random surf on the word wide web]\\label{EX:RandomSurferwww}\nConsider the huge graph with vertices as webpages and hyper-links as undirected edges.  \nThen \\hyperref[M:RWGraph]{Model~\\ref*{M:RWGraph}} gives a random walk on this graph.  \nHowever if a page has no links to other pages, it becomes a sink and therefore terminates the random walk.  \nLet us modify this random walk into a {\\bf random surf} to avoid getting stuck.  \nIf the random surfer arrives at a sink page, she picks another page at random and continues surfing at random again.  \nGoogle's PageRank formula uses a random surfer model who gets bored after several clicks and switches to a random page.  \nThe PageRank value of a page reflects the chance that the random surfer will land on that page by clicking on a link.  \nThe stationary distribution of the random surfer on the world wide web is a very successful model for ranking pages.\n\\end{example}\n\n\\begin{model}[Lazy Random Walk]\nYou can convert a random walk on an undirected graph $\\Gz=(\\Vz,\\Ez)$ into a {\\bf lazy random walk} on $\\Gz$ by the following steps:\n\\begin{itemize}\n\\item Add loops to each vertex in $\\Vz = \\{v_1,v_2,\\ldots,v_k\\}$ to obtain a new set of edges $\\Ez' = \\Ez \\cup \\{\\langle v_1,v_1 \\rangle, \\langle v_2,v_2 \\rangle, \\ldots, \\langle v_k,v_k \\rangle, \\}$.\n\\item Construct the lazy graph $\\Gz'=(\\Vz,\\Ez')$.\n\\item Do a random walk on the undirected graph $\\Gz'$.\n\\end{itemize} \nThe lazy random walk allows us to introduce aperiodicity quite easily.\n\\end{model}\n\n\\begin{exercise}[Lazy Random Walk on the Triangulated Quadrangle]\\label{EXR:LazyWalkTriangulatedQuadrangle}\nConsider the random walk of \\hyperref[EX:TriangulatedQuadrangle]{Example~\\ref*{EX:TriangulatedQuadrangle}} on the undirected graph \n$$\\Gz=(\\{1,2,3,4\\}, \\{\\langle 1,2 \\rangle, \\langle 3,1 \\rangle, \\langle 2,3 \\rangle, \\langle 2,4 \\rangle, \\langle 4,3\\rangle\\}) \\enspace .$$ \nConstruct the lazy random walk on $\\Gz$, obtain its transition probability matrix and state transition diagram.  \nShow that the stationary distribution of this lazy random walk on $\\Gz$ is\n\\[\n\\pi  \n= \\left( \\frac{3}{14}, \\frac{4}{14}, \\frac{4}{14}, \\frac{3}{14} \\right) \\enspace .\n\\] \n\\end{exercise}\n\n\\begin{model}[Random Walks on Groups]\nUnder \\work\n\\end{model}\n\n\\begin{model}[Birth-Death chains]\nUnder \\work\n\\end{model}\n\n%\\subsection{Gambler's Ruin}\n%\\work\n%\\subsection{Cupon Collection}\n%\\work\n%\\subsection{Projection of random walk on hypercube to Ehrenfest's Urn}\n%\\work\n%\\work\n\n%\\section{State Classification}\n%This Section is under \\work.\n\n\n% Estimation\n\\section{Metropolis-Hastings Markov chain}\n\n\\begin{definition}[Metropolis-Hastings Markov chain]\\label{D:M-HChain}\nIf we are given an irreducible Markov chain $\\left(Y_t\\right)_{t\\in \\Zz_+}$ called the {\\bf base chain} or the {\\bf proposal chain} on a finite state space $\\Xz = \\{s_1,s_2,\\ldots,s_k\\}$ with transition probability matrix $Q = \\left(Q(x,y)\\right)_{(x,y)\\in \\Xz^2}$ and some probability distribution $\\pi$ on $\\Xz$ of interest that may only be known up to a normalizing constant as $\\tilde{\\pi}$, i.e., $\\pi(x) = \\left(\\sum_{z \\in \\Xz}{\\tilde{\\pi}(z)}\\right)^{-1} \\tilde{\\pi}(x)$ for each $x \\in \\Xz$, then we can construct a new Markov chain $\\left(X_t\\right)_{t\\in \\Zz_+}$ called the {\\bf Metropolis-Hastings} chain on $\\Xz$ with the following transition probabilities:\n\\begin{equation}\\label{E:M-HPs}\nP(x,y) = \n\\begin{cases}\nQ(x,y) a(x,y) & \\text{ if } x \\neq y\\\\\n1 - \\sum_{z \\in \\{z \\in \\Xz : z \\neq x\\}} Q(x,z) a(x,z) & \\text{ if } x = y \n\\end{cases} \\enspace ,\n\\end{equation}\nwhere the acceptance probability is\n\\begin{equation}\\label{E:M-Ha}\na(x,y) := \\min\\left\\{ 1, \\frac{\\pi(y)}{\\pi(x)}\\frac{Q(y,x)}{Q(x,y)} \\right\\} \\enspace .\n\\end{equation}\nNote that we only need to know $\\pi$ up to ratios.  Thus, ${\\pi(y)}/{\\pi(x)}$ in $a(x,y)$ can be replaced by ${\\tilde{\\pi}(y)}/{\\tilde{\\pi}(x)}$ since\n\\[\n\\frac{\\pi(y)}{\\pi(x)}  \n= \\frac{\\left(\\sum_{z \\in \\Xz}{\\tilde{\\pi}(z)}\\right)^{-1} \\tilde{\\pi}(y)}{\\left(\\sum_{z \\in \\Xz}{\\tilde{\\pi}(z)}\\right)^{-1} \\tilde{\\pi}(x)} \n= \\frac{\\tilde{\\pi}(y)}{\\tilde{\\pi}(x)} \\enspace .\n\\]\n\\hyperref[A:MHSamplerFiniteMC]{Algorithm~\\ref*{A:MHSamplerFiniteMC}} describes how to simulate samples from a Metropolis-Hastings Markov chain.  \n\\end{definition}\n\n\\begin{prop}[Stationarity of the Metropolis-Hastings chain]\\label{P:M-HChainStationary}\nThe Metropolis-Hastings chain constructed according to \\hyperref[D:M-HChain]{Definition~\\ref*{D:M-HChain}} has $\\pi$ as its stationary distribution.  \n\\begin{proof}\nIt suffices to show that $\\pi$ is the reversible distribution for $\\left(X_t\\right)_{t\\in \\Z_+}$, i.e., for each $(x,y) \\in \\Xz^2$, $\\pi(x)P(x,y) = \\pi(y) P(y,x)$.  \nFix a pair $(x,y) \\in \\Xz^2$ and suppose $x\\neq y$.  \nThen,\n\\begin{eqnarray*}\n\\pi(x)P(x,y) \n&=& \\pi(x) Q(x,y)a(x,y) \\\\\n&=& \\pi(x) Q(x,y) \\min\\left\\{ 1, \\frac{\\pi(y)}{\\pi(x)}\\frac{Q(y,x)}{Q(x,y)} \\right\\} \\\\\n&=& \\min\\left\\{ \\pi(x) Q(x,y), \\pi(x) Q(x,y) \\frac{\\pi(y)}{\\pi(x)}\\frac{Q(y,x)}{Q(x,y)} \\right\\}\\\\\n&=& \\min\\left\\{ \\pi(x) Q(x,y), \\pi(y) Q(y,x) \\right\\}\\\\\n&=& \\min\\left\\{ \\pi(y) Q(y,x), \\pi(x) Q(x,y) \\right\\}\\\\\n&=& \\min\\left\\{ \\pi(y) Q(y,x), \\pi(y) Q(y,x) \\frac{\\pi(x)}{\\pi(y)} \\frac{Q(x,y)}{Q(y,x)} \\right\\}\\\\\n&=& \\pi(y) Q(y,x) \\min\\left\\{ 1, \\frac{\\pi(x)}{\\pi(y)} \\frac{Q(x,y)}{Q(y,x)} \\right\\}\\\\\n&=& \\pi(y) P(y,x) \\enspace .\n\\end{eqnarray*}\nWhen $x=y$, reversibility is trivially satisfied since $\\pi(x)P(x,y) = \\pi(y) P(y,x)=\\pi(x)P(x,x)$.\n\\end{proof}\n\\end{prop}\n\n\\begin{definition}\\label{M:MetropolisChain}\nIf the base chain $\\left(Y_t\\right)_{t \\in \\Zz_+}$ in the Metropolis-Hastings Markov chain of \\hyperref[D:M-HChain]{Definition~\\ref*{D:M-HChain}} has a symmetric transition matrix $Q$ with $Q(x,y)=Q(y,x)$ for each $(x,y)\\in \\Xz^2$ then the acceptance probability in \\hyperref[E:M-Ha]{Equation~\\ref*{E:M-Ha}} simplifies to\n\\[\na(x,y) =  \\min\\left\\{1, \\frac{\\pi(y)}{\\pi(x)} \\right\\} \\enspace ,\n\\]\nand the corresponding Metropolis-Hastings chain $\\left(X_t\\right)_{t\\in Zz_+}$ is called the {\\bf Metropolis chain}.\n\\end{definition}\n\n\\begin{algorithm}%WORK rewrite\n\\caption{Metropolis-Hastings Markov chain}\n\\label{A:MHSamplerFiniteMC}\n\\begin{algorithmic}[1]\n\\STATE {\n{\\it input:} \n\\begin{itemize}\n\\item[(1)] shape of a target density $\\tilde{\\pi}(x) = \\left({\\sum_{x \\in \\Xz} \\tilde{\\pi}(x)}\\right) \\pi(x)$,\n\\item[(2)] sampler for the base chain that can produce samples $y \\sim Q(x,\\cdot)$.\n\\end{itemize}\n}\n\\STATE {\\it output:} a sequence of samples $x_0,x_1, \\ldots, x_n$ from the Metropolis-Hastings Markov chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ with stationary distribution $\\pi$\n\\STATE Choose initial state $x_0 \\in \\Xz$ according to $\\mu_0$\n\\REPEAT\n\\STATE At iteration $t$,\n\\STATE Generate $y \\sim Q(x_{t-1},\\cdot)$ and $u \\sim \\uniform(0,1)$,\n\\STATE Compute {\\it acceptance probability}\n\\[\na(x_{t-1},y)=\\min\\left\\{1,\\frac{\\tilde{\\pi}(y)}{\\tilde{\\pi}(x_{t-1})}\\frac{Q(y,x_{t-1})}{Q(x_{t-1}),y} \\right\\},\n\\]\n\\STATE\n{\\bf If} $u \\leq a(x_{t-1},y)$\n{\\bf then} $x_t \\gets y$, \n{\\bf else} $x_t \\gets x_{t-1}$\n\\UNTIL desired number of samples $n$ are obtained from $\\left(X_t\\right)_{t \\in \\Zz_+}$\n\\end{algorithmic}\n\\end{algorithm}\n\nSuppose you know neither the vertex set $\\Vz$ nor the edge set $\\Ez$ entirely for an undirected graph $\\Gz=(\\Vz,\\Ez)$ but you are capable of walking locally on $\\Gz$.  \nIn other words, if you are currently at vertex $x$ you are able to make a move to one of the neighbouring vertices of $x$.  \nHowever, you do not know every single vertex in $\\Vz$ or the entire set of edges $\\Ez$ as an adjacency matrix for instance.  \nSeveral real-world problems fall in this class.  \nSome examples include the random surfer on www to rank web pages (\\hyperref[EX:RandomSurferwww]{Example~\\ref*{EX:RandomSurferwww}}), social network analyses in facebook or twitter, exact tests for contingency tables, etc.\n\n\\begin{model}[Metropolis-Hastings Random Walk on Graph]  \nLet $\\Gz=(\\Vz,\\Ez)$ be an undirected graph and let $\\left(Y_t\\right)_{t \\in \\Zz_+}$ with transition matrix $Q$ be an irreducible random walk on $\\Gz$ and let $\\pi$ be a probability distribution on $\\Vz=\\{v_1,v_2,\\ldots,v_k\\}$ that is known upto a normalizing constant as $\\tilde{\\pi}$.  \nThe {\\bf Metropolis-Hastings random walk} on $\\Gz$ is the Metropolis-Hasting Markov chain $\\left(X_t\\right)_{t\\in \\Zz_+}$ on $\\Vz$ with base chain $\\left(Y_t\\right)_{t\\in \\Zz_+}$ and the following transition probabilities:\n\\[\nP(x,y) = \n\\begin{cases}\n\\frac{1}{\\deg(v_i)}\\min \\left\\{ 1, \\frac{\\tilde{\\pi}(v_j)}{\\tilde{\\pi}(v_i)} \\frac{\\deg(v_i)}{\\deg(v_j)} \\right\\} & \\text{ if } \\langle v_i,v_j \\rangle \\in \\Ez \\\\\n1 - \\sum_{v_l \\in \\nbhd(v_i)} \\left( \\frac{1}{\\deg(v_i)} \\min \\left\\{ 1, \\frac{\\tilde{\\pi}(v_l)}{\\tilde{\\pi}(v_i)} \\frac{\\deg(v_i)}{\\deg(v_l)} \\right\\} \\right) & \\text{ if } v_i=v_j\\\\\n0 & \\text{ otherwise }\n\\end{cases} \\enspace .\n\\]\nBy \\hyperref[P:M-HChainStationary]{Proposition~\\ref*{P:M-HChainStationary}}, $\\left(X_t\\right)_{t\\in \\Zz_+}$ has $\\pi$ as its stationary distribution.\nThis Markov chain can be simulated as follows:\n\\begin{itemize}\n\\item Suppose $x_t = v_i$ at time $t$\n\\item Propose $v_j$ uniformly at random from $\\nbhd(v_i)$\n\\item Sample $u$ from $\\uniform(0,1)$\n\\item If $u < \\min \\{1, \\pi(v_j)\\deg(v_i)/\\pi(v_i)\\deg(v_j)\\}$ then $x_{t+1}=v_j$ else $x_{t+1}=x_t$\n\\end{itemize}\n\\end{model}\n\n\\begin{model}[Metropolis chain on a regular graph]\\label{M:MetropolisChainRWRegGraph}\nConsider the random walk $\\left(Y_t \\right)_{t \\in \\Zz_+}$ on a regular graph $\\Gz=(\\Vz,\\Ez)$ with $\\deg(v_i)=\\delta$ for every vertex $v_i \\in \\Vz=\\{v_1,v_2,\\ldots,v_k\\}$ and the symmetric transition matrix \n\\[\nQ(v_i,v_j) = \n\\begin{cases} \n\\frac{1}{\\delta} & \\text{ if } \\langle v_i,v_j \\rangle \\in \\Ez \\\\\n0 & \\text{ otherwise}\n\\end{cases} \\enspace .\n\\]\nYou can sample from a given distribution $\\pi$ on $\\Vz$ by constructing the Metropolis chain with stationary distribution $\\pi$ from the base chain given by $\\left(Y_t \\right)_{t \\in \\Zz_+}$.\n\\end{model}\n\n\\begin{model}[sampling from a uniform distribution over an irregular graph]\nA graph $\\Gz=(\\Vz,\\Ez)$ that is not regular is said to be irregular.  Clearly, the stationary distribution of a random walk on $\\Gz$ is not uniform.  \nSuppose you want to sample uniformly from $\\Vz$ according to $\\pi(v_i)=(\\#\\Vz)^{-1}$ for each $v_i \\in \\Vz$.  \nWe can accomplish this by constructing a Metropolis-Hastings Markov chain with the random walk on $\\Gz$ as the base chain and the following transition probabilities:\n\\[\nP(v_i,v_j) = \n\\begin{cases}\n\\frac{1}{\\deg(v_i)}\\min \\left\\{ 1, \\frac{\\deg(v_i)}{\\deg(v_j)} \\right\\} & \\text{ if } \\langle v_i,v_j \\rangle \\in \\Ez \\\\\n1 - \\sum_{v_l \\in \\nbhd(v_i)} \\left( \\frac{1}{\\deg(v_i)} \\min \\left\\{ 1, \\frac{\\deg(v_i)}{\\deg(v_l)} \\right\\} \\right) & \\text{ if } v_i=v_j\\\\\n0 & \\text{ otherwise }\n\\end{cases} \\enspace .\n\\]\nThus the Metropolis-Hastings walk on $\\Gz$ is biased against visiting higher degree vertices and thereby samples unifromly from $\\Vz$ at stationarity.\n\\end{model}\n\n\\begin{example}[Stochastic Optimization]\nLef $f: \\Vz \\to \\Rz$ and $\\Gz=(\\Vz,\\Ez)$ be an undirected graph.  Let the global maximum be\n\\[\nf^* := \\max_{y \\in \\Vz} f(y) \\enspace ,\n\\]\nand the set of maximizers of $f$ be\n\\[\n\\Vz^* := \\argmax_{x \\in \\Vz} f(x) = \\{ x \\in \\Vz : f(x) = f^* \\} \\enspace .\n\\]\nIn many problems such as maximum likelihood estimation, minimizing a cost function by maximizing its negative, etc, one is interested in $\\Vz^* \\subset \\Vz$.  \nThis global maximization problem is difficult when $\\# \\Vz$ is huge.  \nA deterministic hill-climbing or gradient ascent algorithm that iteratively moves from the current state $v_i$ to a neighbouring state $v_j$ if $f(v_j) > f(v_i)$ can easily get trapped in a local peak of $f$ and thereby miss the global peak attained by elements in $\\Vz^*$.\n\n\\begin{figure}[htpb]\n\\caption{Stochatic Optimization with Metropolis chain.\\label{F:StochasticOptimMetropolisChain}}\n\\centering   \\makebox{\\includegraphics[width=6.5in]{figures/StochasticOptimMetropolisChain}}\n\\end{figure}\nFor example consider the global maximization problem shown in \\hyperref[F:StochasticOptimMetropolisChain]{Figure~\\ref*{F:StochasticOptimMetropolisChain}} with \n$$ f^* = 7 \\text{ and } \\Vz^* = \\{4,10\\} \\subset \\Vz = \\{-20,-19,\\ldots,19,20\\} \\enspace . $$\nThe deterministic hill-climbing algorithm will clearly miss $\\Vz^*$ and terminate at the local maximum of $3$ at $-12$ if initialised at any element in $\\{-20,-19,\\ldots,-8,-7\\}$.  \nAlso, this algorithm will not find both elements in $\\Vz^*$ even when initialised more appropriately.\n\nWe will construct a Markov chain to solve this global maximization problem.  \nFor a fixed parameter $\\lambda \\in \\Rz_{>0}$, let \n$$\\pi_{\\lambda}(x) = \\frac{\\lambda^{f(x)}}{\\sum_{z \\in \\Vz} \\lambda^{f(z)}} \\enspace .$$\nSince $\\pi_{\\lambda}(x)$ is increasing in $f(x)$, $\\pi_{\\lambda}(x)$ favours vertices with large $f(x)$.    \nFirst form a graph $\\Gz=(\\Vz,\\Ez)$ by adding edges between the vertices in $\\Vz$ so that you can get from any vertex to any other vertex in $\\Vz$ by following a sequence of edges in $\\Ez$.  \nNow using the random walk on $\\Gz$ as the base chain let us construct a Metropolis-Hastings chain $\\left(X_t\\right)_{t \\in \\Zz_+}$ on $\\Gz$ with $\\pi_{\\lambda}$ on $\\Vz$ as its stationary distribution.  \n\nFor simplicity, let us suppose that $\\Gz$ is a regular graph with a symmetric transition matrix $Q$ for the base chain and thereby making $\\left(X_t\\right)_{t \\in \\Zz_+}$ a Metropolis chain.  \nFor instance, in the Example from \\hyperref[F:StochasticOptimMetropolisChain]{Figure~\\ref*{F:StochasticOptimMetropolisChain}} with $\\Vz = \\{-20,-19,\\ldots,19,20\\}$, we can obtain a Metropolis chain on $\\Vz$ with stationary distribution $\\pi_{\\lambda}$ by taking $\\Ez$ in $\\Gz=(\\Vz,\\Ez)$ to be \n\\[\n\\Ez = \\left\\{ \\langle -20,-19\\rangle, \\langle -19,-18\\rangle, \\langle -18,-17\\rangle, \\ldots, \\langle 17,18\\rangle, \\langle 18,19\\rangle, \\langle 19,20\\rangle \\right\\} \\enspace .\n\\]\nThen, if $f(y) < f(x)$, the Metropolis chain accepts a transition from $x$ to $y$ with probability \n$$\\frac{\\pi_{\\lambda}(y)}{\\pi_{\\lambda}(x)} = \\frac{\\lambda^{f(y)}}{\\lambda^{f(x)}}  = \\lambda^{f(y)-f(x)} = \\lambda^{-(f(x)-f(y))} \\enspace .$$\nAs $\\lambda \\to \\infty$, the Metropolis chain approaches the deterministic hill-climbing algorithm and yields a uniform distribution over $\\Vz^*$ as follows:\n\\[\n\\lim_{\\lambda \\to \\infty} \\pi_{\\lambda} (x) = \\lim_{\\lambda \\to \\infty} \\frac{\\lambda^{f(x)} / \\lambda^{f^*}}{\\#\\Vz^* + \\sum_{z \\in \\Vz \\setminus \\Vz^*}{\\lambda^{f(x)}/\\lambda^{f^*}}} = \\frac{\\BBs{1}_{\\Vz^*}(x)}{\\#\\Vz^*} \\enspace .\n\\]\n\\end{example}\n\n\\section{Glauber Dynamics}\nLet $\\Sz$ be a finite set of states. \nLet $\\Vz$ be a set of vertices.  \nTypically, $\\Sz$ contains characters or colours that can be taken by each site or vertex in $\\Vz$.  \nLet $x \\in \\Sz^{\\Vz}$ be a configuration, i.e., a function from $\\Vz$ to $\\Sz$.  \nA configuration can be thought of as a labelling of vertices in $\\Vz$ with elements in $\\Sz$.\n\n\\begin{definition}[Glauber dynamics for $\\pi$]\nLet $\\Vz$ and $\\Sz$ be finite sets and let $\\Xz \\subset \\Sz^{\\Vz}$ which forms the support of the probability distribution $\\pi$ on $\\Sz^{\\Vz}$, i.e.,\n\\[\n\\Xz = \\{x \\in \\Sz^{\\Vz} : \\pi(x)>0 \\} \\enspace .\n\\]\nThe {\\bf Glauber dynamics} or {\\bf Gibbs sampler} for $\\pi$ is a reversible Markov chain on $\\Xz$ with stationary distribution $\\pi$ under the following transition mechanism.  \nLet the current state at time $t$ be $x$.  \nTo obtain the state at time $t+1$ first choose a vertex $v$ uniformly at random from $\\Vz$ and then choose a new state according to $\\pi$ conditioned on the set of states equal to $x$ at all vertices other than $v$.  \nWe give the details of this transition mechanism next.  \n\nFor $x \\in \\Xz$ and $v \\in \\Vz$, define the set of states identical to $x$ everywhere except possibly at $v$ as\n\\[\n\\Xz(x,v) := \\left\\{ y \\in \\Xz : y(w) = x(w) \\text{ for all } w \\neq v \\right\\} \\enspace .\n\\]\nNow let \n\\[\n\\pi^{x,v}(y) := \\pi(y | \\Xz(x,v)) = \n\\begin{cases}\n\\left( \\sum_{z \\in \\Xz(x,v)}{\\pi(z)}\\right)^{-1}{\\pi(y)} & \\text{ if } y \\in \\Xz(x,v) \\\\\n0 & \\text{ if } y \\notin \\Xz(x,v)\n\\end{cases}\n\\]\nbe the distribution $\\pi$ conditioned on $\\Xz(x,v)$.  Therefore the rule for updating the current state $x$ is:\n\\begin{itemize}\n\\item pick a vertex $v$ uniformly at random from $\\Vz$,\n\\item choose a new configuration by sampling from $\\pi^{x,v}$.\n\\end{itemize}\n\\end{definition}\n\n\\begin{prop}[Stationarity of Glauber dynamics]\nThe Glauber dynamics for $\\pi$ on $\\Xz \\subset \\Sz^{\\Vz}$ has $\\pi$ as its reversible and stationary distribution.\n\\begin{proof}\nExercise.\n\\end{proof}\n\\end{prop}\n\n\\begin{model}[Hard-core model]\\label{M:GlauberDynamicsHardcore}\nLet $\\Gz = (\\Vz,\\Ez)$ be an undirected graph.  \nAn assignment of elements of $\\Sz=\\{0,1\\}$ to vertices in $\\Vz$ is called a configuration.  \nThus, the configuration $x$ is a function $x: \\Vz \\to \\Sz$ and $x \\in \\Sz^{\\Vz}$. \nThe vertices $v$ of a configuration $x$ with $x(v)=1$ are said to be occupied and those with $x(v)=0$ are said to be vacant.  \nThus a configuration models a placement of particles on the vertices of $\\Vz$.  \nA hard-core configuration is a configuration in which no two neighbouring vertices are occupied.  \nMore formally, a configuration $x$ is called hard-core if $\\sum_{\\langle v_i ,v_j \\rangle \\in \\Ez} x(v_i) x(v_j)=0$.  \nLet the set of hard-core configurations be $\\Xz$ and let $\\pi$ be the uniform distribution on $\\Xz$, given by\n\\[\n\\pi(x) = \n\\begin{cases}\n\\frac{1}{\\# \\Xz} & \\text{ if } x \\in \\Xz \\\\\n0 & \\text{ otherwise}\n\\end{cases} \\enspace .\n\\] \nThe Glauber dynamics $\\left(X_t\\right)_{t \\in \\Zz_+}$ for the uniform distribution $\\pi$ on hard-core configurations can be simulated as follows: \n\\begin{itemize}\n\\item initialize with vacant vertices, i.e., $X_0(w)=0$ for each $x \\in \\Vz$,\n\\item let the current hard-core configuration be $x_t: \\Vz \\to \\{0,1\\}$ at time $t$,\n\\item choose a vertex $v$ uniformly at random from $\\Vz$,\n\\item if any neighbour of $v$ is occupied then $v$ is left vacant, i.e., $x_{t+1}(v)=0$\n\\item if every neighbour of $v$ is vacant then $v$ is occupied with probability $1/2$, i.e., $x_{t+1}(v)=1$, \n\\item leave the values at all other vertices unchanged, i.e., $x_{t+1}(w)=x_t(w)$ for each $w \\neq v$, \n\\item the possibly modified configuration $x_{t+1}$ is the updated hard-core configuration at time $t+1$.\n\\end{itemize}\n\\end{model}\n\n\\begin{prop}\nIhe Glauber dynamics of \\hyperref[M:GlauberDynamicsHardcore]{Model~\\ref*{M:GlauberDynamicsHardcore}} does indeed have $\\pi$ as its stationary distribution.\n\\begin{proof}\nFirst we need to verify that $\\left( X_t \\right)_{t \\in \\Zz_+}$, the Markov chain given by the Glauber dynamics for $\\pi$ in \\hyperref[M:GlauberDynamicsHardcore]{Model~\\ref*{M:GlauberDynamicsHardcore}}, is irreducible and aperiodic.  \nClearly $\\left( X_t \\right)_{t \\in \\Zz_+}$ is aperiodic since we can get from any hard-core configuration $x \\in \\Xz$ to itself in one time step by choosing a vertex with at least one occupied neighbour and leaving the chosen vertex unchanged or by choosing a vertex with no occupied neighbours and leaving the chosen vertex unchanged with probability $1/2$.  \nNext we need to establish irreducibility, i.e., we need to show that we can get from any hardcore configuration $x$ to any other hardcore configuration $x'$ in finitely many steps.  \nLet the vacant configuration be $\\tilde{x}$, i.e., $\\tilde{x}(v)=0$ for every vertex $v \\in \\Vz$.  \nIn finitely many steps, we can go from any $x$ to $\\tilde{x}$ and from $\\tilde{x}$ to $x'$.  \nIf $x$ has $s(x):=\\sum_{v \\in \\Vz}x(v)$ occupied sites or vertices then we can go to the vacant configuration $\\tilde{x}$ with $s(\\tilde{x})=0$ in $s(x)$ time steps by picking one of the currently occupied sites and making it vacant as follows:\n\\[\n\\P(X_{t+s(x)} = \\tilde{x} | X_t = x) = \\prod_{i=0}^{s(x)-1} \\frac{(s(x)-i)}{\\#\\Vz}\\frac{1}{2} > 0 \\enspace .\n\\]\nSimilarly, we can go from $\\tilde{x}$ to any other configuration $x'$ with $s(x')$ many occupied sites in $s(x')$ time steps with the following positive probability:\n\\[\n\\P(X_{t+s(x')} = x' | X_t = \\tilde{x}) = \\prod_{i=0}^{s(x')-1} \\frac{(s(x')-i)}{\\#\\Vz}\\frac{1}{2} > 0 \\enspace .\n\\]\nNote that this is not the shortest possible number of steps to go from $x$ to $x'$ but just a finite number of steps.  \nThus we have established that $x \\leftrightarrow x'$ for every $(x,x') \\in \\Xz$ and thereby established irreducibility of the chain $\\left( X_t \\right)_{t \\in \\Zz_+}$.  \n\nIf we now show that $\\pi$ is reversible for $\\left( X_t \\right)_{t \\in \\Zz_+}$ then by \\hyperref[P:ReversibleIsStationary]{Proposition~\\ref*{P:ReversibleIsStationary}} $\\pi$ is also stationary for $\\left( X_t \\right)_{t \\in \\Zz_+}$ and finally $\\pi$ is the unique stationary distribution due to irreducibility and aperiodicity.  \nLet $P(x,y)$ be the probability of going from $x$ to $y$ in one time step of $\\left( X_t \\right)_{t \\in \\Zz_+}$.  \nWe need to show that for any pair of hardcore configurations $(x,y) \\in \\Xz^2$ the following equality holds:\n\\[\n\\pi(x) P(x,y) = \\pi(y) P(y,x), \\quad \\pi(x) = \\frac{1}{\\#\\Xz} \\enspace .\n\\]\nLet the number of vertices at which $x$ and $y$ differ be $d(x,y):= \\sum_{v \\in \\Vz} \\abs(x(v)-y(v))$.  \nLet us consider three cases of $(x,y) \\in \\Xz^2$.\\\\  \n{\\bf Case i:} When $d(x,y)=0$ the two configurations are identical, i.e., $x=y$, and therefore we have the trivial equality:\n\\[\n\\pi(x) P(x,y) =\\pi(x) P(x,x)= \\pi(y) P(y,x) \\enspace .\n\\]\n{\\bf Case ii:} When $d(x,y)>1$ the two configurations differ at more than one vertex and therefore $P(x,y)=0$ and we have the trivial equality:\n\\[\n\\pi(x) P(x,y) =\\pi(x) 0 = 0 = \\pi(y) P(y,x) \\enspace .\n\\]\n{\\bf Case iii:} When $d(x,y)=1$ the two configurations differ at exactly one vertex $v$ and therefore all neighbouring vertices of $v$ must be vacant, i.e., take the value $0$, in both $x$ and $y$ with $P(x,y)=P(y,x)=\\frac{1}{\\#\\Vz}\\frac{1}{2}$.  Thus,\n\\[\n\\pi(x) P(x,y) = \\frac{1}{\\#\\Xz} \\left(\\frac{1}{\\#\\Vz}\\frac{1}{2} \\right) = \\pi(y) P(y,x) \\enspace .\n\\] \nWe have established that $pi(x) = 1/\\#\\Xz$ for each $x \\in \\Xz$ is the reversible distribution and thereby also the unique stationarity distribution for $\\left( X_t \\right)_{t \\in \\Zz_+}$, the Markov chain given by the Glauber dynamics for $\\pi$ in \\hyperref[M:GlauberDynamicsHardcore]{Model~\\ref*{M:GlauberDynamicsHardcore}}. \n\\end{proof}\n\\end{prop}\n\n\\begin{exercise}[1-D hardcore model]\nLet $\\Xz_n$ be the set of hardcore configurations on a path graph with $n$ vertices.  \nRecall that a path graph $\\Gz_n=(\\Vz_n,\\Ez_n)$ has $n$ vertices and $n-1$ edges, as follows: \n\\[\n\\Vz_n = \\{v_1,v_2,\\ldots,v_n \\}, \\qquad \\Ez_n = \\{ \\langle v_1, v_2 \\rangle, \\langle v_2, v_3 \\rangle, \\ldots, \\langle v_{n-1}, v_n \\rangle \\} \\enspace .\n\\]\nDraw all five hardcore configurations in $\\Xz_3$.  Show that for any positive integer $n$, \n\\[\n\\# \\Xz_n = \\mathsf{fibo}(n+1) \\enspace ,\n\\]\nthe $(n+1)$-th Fibonacci number, that is defined recursively as follows:\n\\[\n\\mathsf{fibo}(0) := \\mathsf{fibo}(1) := 1, \\quad \\mathsf{fibo}(n) = \\mathsf{fibo}(n-1)+\\mathsf{fibo}(n-2), \\quad n \\geq 1 \\enspace .\n\\]\n\\end{exercise}\n\n\\begin{figure}[htpb]\n\\caption{The sample at time step $10^6$ from the Glauber dynamics for the hardcore model on $100\\times 100$ regular torus grid.  A red site is occupied while a blue site is vacant.\\label{F:HardCore2D100x100Torus}}\n\\centering   \\makebox{\\includegraphics[width=5.5in]{figures/HardCore2D100x100Torus}}\n\\end{figure}\n\n\\begin{simulation}[Glauber dynamics for the hardcore model on a 2D regular torus]\nLet us implement a program in \\Matlab that will simulate Glauber dynamics to sample uniformly from the harcore configurations on the undirected regular torus graph. \nWe can report the sample mean of the fraction of occupied sites on this graph from the simulated sequence and make a movie of the simulaitons (last frame is shown in \\hyperref[F:HardCore2D100x100Torus]{Figure~\\ref*{F:HardCore2D100x100Torus}}).\n\\begin{VrbM}\n>> HardCore2D\nAvg1s =    0.1128\n\\end{VrbM}\nThe simulation was implemented in the following M-file:\n\\VrbMf[label=HardCore2D.m]{scripts/HardCore2D.m}\n\\end{simulation}\n\n\n\\begin{model}[Ising model]\\label{M:GlauberDynamicsIsing}\nLet $\\Gz = (\\Vz,\\Ez)$ be an undirected graph.  \nThe Ising model is a probability distribution on $\\Xz = \\{-1,+1\\}^{\\Vz}$, i.e., a way of randomly assigning elements from the set $\\{-1,+1\\}$ to vertices of $\\Gz$.  \nThe physical interpretation of the model is that each vertex is the position of an atom in a ferromagnetic material and $+1$'s or $-1$'s denote the two possible spin orientations of the atoms.  \nThere is a parameter $\\beta$ in the model called inverse temperature and $\\beta \\in [0,\\infty)$.  \nAssociated with each spin configuration $x \\in \\Xz$ is its energy\n\\[\nH(x) = - \\sum_{\\langle u, v \\rangle \\in \\Ez} x(u) x(v) \n\\]\nwhere $x(u)$ and $x(v)$ give the spin orientations of the atoms at vertices $u$ and $v$, respectively.  \nSo, each edge $\\langle u, v \\rangle$ adds $1$ to the energy $H(x)$ if its neighbouring vertices have opposite spins and subtracts $1$ from $H(x)$ otherwise.  \nThus, lower energy is equivalent to a higher egreement in spins between neighbouring vertices.  \n\nThe Ising model on $\\Gz$ at inverse temperature $\\beta$ means a random spin configuration $X$ with\n\\[\n\\P(X=x) = \\pi_{\\Gz,\\beta}(x) = \\frac{1}{\\mathcal{Z}_{\\Gz,\\beta}} \\exp{\\left(- \\beta H(x)\\right)} \n=  \\frac{1}{\\mathcal{Z}_{\\Gz,\\beta}} \\exp{\\left(\\beta \\sum_{\\langle u, v \\rangle \\in \\Ez} x(u) x(v)  \\right)} \\enspace , \n\\]\nwhere $\\mathcal{Z}_{\\Gz,\\beta}= \\sum_{x \\in \\Xz}\\exp{\\left(- \\beta H(x)\\right)}$ is the normalising constant.\n\\end{model}\n\n\\begin{labwork}[Glauber dynamics for the Ising model on a 2D regular torus]\nImplement a program in \\Matlab to simulate from the Ising model on the undirected regular torus graph. \n\\end{labwork}\n\nLet us explore the physical interpretation of the Ising model further.  \nIf the inverse temperature $\\beta=0$ then we are at infinite temperature and therefore every configuration in $\\Xz$ is equally likely, i.e., $\\pi_{\\Gz,0} = 1/\\# \\Xz$.  \nAt the other extreme, if $\\beta \\to \\infty$ then we are approaching zero temperature and the probability over $\\Xz$ under $\\pi_{\\Gz,\\infty}$ is equally split between ``all $+1$'' configuration and ``all $-1$'' configuration.  \nHowever, if $\\beta > 0$, then we are at some temperature $1/\\beta$ that is neither absolutely hot or absolutely cold and therefore the model will favour configurations with lower energy as opposed to higher energy.  Such favourable low energy configurations tend to have neighbouring clumps of identical spins.  \nWe say that there is a phase transition in $\\beta$ since the Ising model's qualitative behaviour depends on whether $\\beta$ is above or below a critical threshold $\\beta_c$. \n\n\\begin{model}[Proper $q$-colourings]\nA proper $q$-colouring of an undirected graph $\\Gz=(\\Vz,\\Ez)$ is an assignment of of $q$ colours labelled $\\{1,2,\\ldots,q\\}$ to vertices in $\\Vz$, subject to the constraint that neighbouring vertices do not receive the same colour.  \nLet $\\Xz$ denote the set of all proper $q$-colourings of $\\Gz$.  \nIf $\\Vz$ is large then $\\Xz$ can be a large and complicated subset of of $\\{1,2,\\ldots,q\\}^{\\Vz}$.  \nNote that proper $q$ colourings are a natural generalisation of the hardcore model.\n\\end{model}\n\n\n\\subsection{Random Walks on $\\Zz$ and the reflection principle}\n\\work\n\n\\section{Coupling from the past}\n\n\n\nMCMC algorithms make it easy to implement a Markov chain that has a given distribution as its stationary distribution. When used on their own, however, MCMC algorithms can only provide sample values that approximate a desired distribution. To obtain sample values that have a desired distribution {\\it exactly} or {\\it perfectly}, MCMC algorithms must be used in conjunction with ideas that make clever use of coupling.\n\nMCMC convergence diagnostics based on {\\it multiple} independent or {\\it coupled} Markov chains running {\\it forward} in time have been suggested, but are not completely reliable. The chains are coupled if the same sequence of random numbers is used to propagate all of them. By adopting a different perspective - running multiple coupled chains from the past or {\\it backward coupling} - Propp \\& Wilson (1996) developed the {\\it coupling from the past (CFTP)} algorithm, which allowed exact sample values to be obtained from the stationary distribution of an ergodic Markov chain with {\\it finite} state space.\n\nLet us first appreciate the trouble with MCMC algorithms such as Metropolis-Hastings chain, Metropolis chain and Glauber dynamics.  \nFirstly, no matter how large we make time $t$ to be we cannot avoid the discrepancy between the $t$-step distribution $\\mu_t$ and the stationary distribution$\\pi$.  \nConsider the following transition probability matrix:\n\\[\nP = \n\\bordermatrix{~ & s_1 & s_2 \\cr\ns_1 & \\frac{3}{4} & \\frac{1}{4}  \\cr\ns_2 & \\frac{1}{4} & \\frac{3}{4} }\n\\]\nWe can prove by induction that \n$$\\mu_t=\\left(\\frac{1}{2}\\left(1+2^{-t}\\right), \\frac{1}{2}\\left(1-2^{-t}\\right)\\right)$$\nfor every $t \\in \\mathbb{Z}_+$.  \nThe stationary distribution is $\\pi=(1/2,1/2)$.  \nSo, as $t$ approaches infinity $\\mu_t \\overset{\\mathsf{TV}}{\\longrightarrow} \\pi$, however for any $t$ the total variation distance between $\\dtv(\\mu_t,\\pi) = 2^{-t}$ is strictly positive.  \nEven in this simple example $\\mu_t$ may never equal $\\pi$ for any finite $t$, however large.\nThus, we have to settle for an approximation to $\\pi$ with some acceptable error $\\epsilon$.  \nSecondly, to make the approximation error measured by $\\dtv(\\mu_t,\\pi)$ smaller than $\\epsilon$ we have to find the $\\epsilon$-burnin time $\\tau_{\\epsilon}$ by which $\\dtv \\left(\\mu_{\\tau_{\\epsilon}},\\pi\\right) < \\epsilon$.  \nDetermining $\\tau_{\\epsilon}$ is nontrivial except in special cases and constitutes an active field of research.  \n\n\n\n\nThe following material is under \\work.\n\\begin{demo}[Applet -- Perfect sampling.]\nThe CFTP algorithm starts multiple Markov chains, one for each possible state, at some time $t_0<0$ in the past, and uses coupled transitions to propagate them to time 0. If all the chains {\\it coalesce}, (i.e. end up having the same state, at or before time 0), then they will have \\textquotedblleft forgotten\\textquotedblright their starting values and will evolve as a single chain from that point onwards. The common state at time zero $(X^{(0)})$ is an exact sample value from the stationary distribution. Intuitively, if coalescence occurs at some finite time,$t^{*}<0$, then if the chains had been started in the infinite past, coupling with the same sequence of random numbers will ensure that they coalesce at $t^*$ , and the common chain at time 0 must be stationary because it had been running for an infinitely long time. Thus, the existence of a finite coalescence time can give a stationary sample value in finite time. The use of coupling is essential to induce coalescence in a finite length of time.\n\nConsider a Markov chain with finite state space, $S = {1, 2,\\ldots, K}$. The CFTP algorithm starts K Markov chains, one from each state in $S$, at some time $t_0<0$ in the past. A sequence of $t_0$ random vectors, $R^{t+1},R^{t+2},\\ldots,R^{0},$, is generated and used to propagate all $K$ Markov chains to time 0. Let $X^{t,k(t_0)}$ represent the state of the Markov chain at time $t$, starting from state $k\\in S$ at time $t_0<t$, and let $\\phi$ be the update function of the Markov chain, such that:\n\n\\begin{equation}\nX^{(t+1,k(t_0))}=\\phi(X^{(t,k(t_0))},R^{(t+1)})\n\\end{equation}\n\\subsection{\\alg --{\\it Coupling from the past.}}\n\n\\begin{tabbing}\nSet $t_0=0$.\\\\\n\\=Repeat\\=\\\\\n\t\t\\>\\>Set  $t_0=$ $t_0-1$, (take 1 time-step back)\\\\\n\t\t\\>\\>Generate $R^{(t_0+1)}$ ,\\\\\n\t\t\\>\\>For $k$\\=$=1, 2,\\ldots, K$, (for each state)\\\\\n\t\t\t\t\\>\\>\\>Set $X^{(t_0,k(t_0))}=k$, (start chain in that state)\\\\\n\t\t\t\t\\>\\>\\>For $t$\\= $=t_0,t_0+1,\\ldots,-1$, (propagate chain to time 0)\\\\\n\t\t\t\t\t\t\\>\\>\\>\\>Set $X^{(t+1,k(t_0))}=\\phi(X^{(t,k(t_0))},R^{(t+1)})$.\\\\\nUntil $X^{(0,1(t_0))}=X^{(0,2(t_0))}=\\Lambda=X^{(0,K(t_0))}$.(check for coalescence at time 0)\\\\\nReturn $X^{(0)}$.\\\\\n\\end{tabbing}\n%\\begin{flushright}   $\\boxbox$ \\end{flushright}\n\\end{demo}\n\n\\begin{example}\nSuppose that the Markov chain has the state space, $S = {0, 1, 2}$, and a transition matrix:\n$$Q=\\left( \\begin{array}{ccc}\n0.6&0.3&0.1\\\\\n0.4&0.4&0.2\\\\\n0.3&0.4&0.3\\\\\n\\end{array}\\right)$$\n\nwhere the $(i, j)$-element is the conditional probability, $P(X^{(t+1)}=j|X^{(t)}=i)$. The matrix of conditional cumulative probabilities is\n$$C=\\left( \\begin{array}{ccc}\n0.6&0.9&1\\\\\n0.4&0.8&1\\\\\n0.3&0.7&1\\\\\n\\end{array}\\right)$$\n\n\nwhere the $(i, j)$-element is the probability,  $P(X^{(t+1)}=j|X^{(t)}=i)$. Beginning at $t_0=-1$, three chains are started at 0, 1 and 2. A uniform $(0, 1)$ random number, $U^{(0)}$, is generated (in this example, $R^{(0)}=U^{(0)}$) and used to propagate all three chains to time 0. Suppose that $U^{(0)}\\in(0.8,0.9)$. Then the three chains are updated as shown:\n\\begin{center}\n\\begin{picture}(60,60)\n\\put(35,50){$U^{(0)}$}\n\\put(25,40){2}\n\\put(55,40){2}\n\\put(32,45){\\vector(1,0){20}}\n\\put(25,30){1}\n\\put(55,30){1}\n\\put(32,35){\\vector(2,1){20}}\n\\put(25,20){0}\n\\put(55,20){0}\n\\put(32,25){\\vector(2,1){20}}\n\\put(22,10){-1}\n\\put(55,10){0}\n\\put(5,10){$t=$}\n\\end{picture}\n\\end{center}\nThe chains have not coalesced at $t = 0$, so we need to move one time-step back to $t_0=-2$, start three chains at 0, 1 and 2, generate a second uniform $(0, 1)$ random number, $U^{(-1)}$ and use it along with the previous $U^{(0)}$ to propagate the chains to time 0. Suppose that $U^{(-1)}\\in(0.3,0.4)$. The three chains then evolve as shown:\n\n\\begin{center}\n\\begin{picture}(100,60)\n\\put(32,50){$U^{(-1)}$}\n\\put(25,40){2}\n\\put(55,40){2}\n\\put(32,45){\\vector(2,-1){20}}\n\\put(25,30){1}\n\\put(55,30){1}\n\\put(32,35){\\vector(2,-1){20}}\n\\put(25,20){0}\n\\put(55,20){0}\n\\put(32,25){\\vector(1,0){20}}\n\\put(22,10){-2}\n\\put(52,10){-1}\n\\put(65,50){$U^{(0)}$}\n\\put(85,40){2}\n\\put(85,30){1}\n\\put(62,35){\\vector(2,1){20}}\n\\put(85,20){0}\n\\put(62,25){\\vector(2,1){20}}\n\\put(85,10){0}\n\\put(5,10){$t=$}\n\\end{picture}\n\\end{center}\n\nThe chains have still not coalesced at $t = 0$, so we must move another time-step back to $t_0=-3$ and start again, generating a third uniform $(0, 1)$ random number, $U^{(-2)}$. Suppose that  $U^{(-2)}\\in(0.3,0.4)$. This is used with  $U^{(-1)}$ and  $U^{(0)}$ from before, giving the following transitions:\n\n\\begin{center}\n\\begin{picture}(130,60)\n\\put(32,50){$U^{(-2)}$}\n\\put(25,40){2}\n\\put(55,40){2}\n\\put(32,45){\\vector(2,-1){20}}\n\\put(25,30){1}\n\\put(55,30){1}\n\\put(32,35){\\vector(2,-1){20}}\n\\put(25,20){0}\n\\put(55,20){0}\n\\put(32,25){\\vector(1,0){20}}\n\\put(22,10){-3}\n\\put(52,10){-2}\n\\put(62,50){$U^{(-1)}$}\n\\put(85,40){2}\n\\put(85,30){1}\n\\put(62,35){\\vector(2,-1){20}}\n\\put(85,20){0}\n\\put(62,25){\\vector(1,0){20}}\n\\put(82,10){-1}\n\\put(95,50){$U^{(0)}$}\n\\put(115,40){2}\n\\put(115,30){1}\n\\put(115,20){0}\n\\put(92,25){\\vector(2,1){20}}\n\\put(115,10){0}\n\\put(5,10){$t=$}\n\\end{picture}\n\\end{center}\nAll three chains have now coalesced at $t = 0$ and so $X^{(0)}=1$ is accepted as a sample value from the stationary distribution. The whole process is repeated to get another independent sample value. It is important to note that even though the chains have coalesced at $t =  1$, with the common value $X^{(-1)}=0$; this value at the time of coalescence is not accepted as being from the stationary distribution. This is because the time of coalescence is a random time that depends only on the sequence of random numbers, $U^{(0)},U^{(-1)},\\ldots$; while the time at which a coalesced state has the required stationary distribution must be a fixed time. In the CFTP algorithm, this {\\it fixed} time has been arbitrarily specified to be $t = 0$.\n\\end{example}\n\n\\begin{example}\nTo see that the state at the time of coalescence does not have the stationary distribution, suppose that the state space is $S = {1, 2}$ and the transition matrix is:\n$$Q=\\left(\n\\begin{array}{cc}\n0.5 &0.5 \\\\\n1 &0 \\\\ \n\\end{array}\\right).$$\n\n\nSince $Q(2, 1) = 1$, the two coupled chains must be in state 1 at the time of coalescence. However, the stationary distribution of this Markov chain is $f(1) = 2/3$ and $f(2) = 1/3$, and so the state at the time of coalescence cannot be from the stationary distribution.\n\\end{example}\n\nInstead of taking a single step back when the two bounding chains fail to coalesce, any decreasing sequence of time-steps may be used. The \\textquotedblleft double-until-overshoot\" choice of $t_0=-2^0,-2^1,-2^2,\\ldots$ is optimal in the sense that it minimises the worst-case number of steps and almost minimises the expected number of steps for coalescence.\n\n\n\\begin{exercise}\nImplement the CFTP algorithm for the Markov chain in Example 2.5.3 and use it to generate 1000 sample points from the stationary distribution of the chain. The stationary distribution can be shown to be:\n$$\\begin{array}{|c|c|c|c|}\\hline\nx\t&0&\t1&\t2\\\\ \\hline\nf(x)\t&0.4789\t&0.3521\t&0.1690\\\\ \\hline\n\\end{array}$$\nCompare the relative frequencies of the generated sample with the true stationary probabilities.\n\n\\end{exercise}\n\n\\begin{exercise}\n2.6.19\tConsider a Markov chain with a state space $S = {0, 1, 2, 3}$ and the transition matrix:\n$$Q=\\left( \\begin{array}{cccc}\n0.6&0.4&0&0\\\\\n0.4&0.2&0.4&0\\\\\n0.2&0.4&0&0.4\\\\\n0&0.2&0.4&0.4\\\\\n\\end{array}\\right).$$\n\nLet $f=(f_0,f_1,f_2,f_3)$ be a row vector containing the stationary probabilities of the chain.\n\\begin{asparaenum}[(a)]\n\\item By solving $fQ=f$ and $f_0+f_1+f_2+f_3=1$ simultaneously, show that the stationary distribution of the chain is $f=(14/35,11/35,6/35,4/35)$.\n\n\\item Implement the \\textquotedblleft double-until-overshoot\" version of the CFTP algorithm to generate from the stationary distribution, and use it to obtain 1000 sample points. Compare the relative frequencies of the generated sample with the true stationary probabilities.\n\\end{asparaenum}\n\\end{exercise}\n\n~\n", "meta": {"hexsha": "42ce27a405f58cb58de5008831fe8f1ccdc9d3db", "size": 103388, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/MarkovChains.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/MarkovChains.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/MarkovChains.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": 65.8103119032, "max_line_length": 1206, "alphanum_fraction": 0.6843927729, "num_tokens": 36285, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8757870013740061, "lm_q2_score": 0.8670357529306639, "lm_q1q2_score": 0.7593386421431998}}
{"text": "\\documentclass{article}\r\n\\usepackage{amsmath}\r\n\\usepackage[margin=1.0in]{geometry}\r\n\\usepackage{xcolor}\r\n\r\n\\begin{document}\r\n\r\n\\noindent\r\nDoes $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{3n^5+n^4+n^3+n^2+n+1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\r\n\r\nNote that $3n^5 \\geq n^5$. In fact, it is even further the case that\r\n\\[3n^5+n^4+n^3+n^2+n+1 \\geq n^5\\]\r\nand dividing both sides by $(n^5)(3n^5+n^4+n^3+n^2+n+1)$, we get\r\n\\[ \\frac1{n^5} \\geq \\frac{1}{3n^5+n^4+n^3+n^2+n+1}.\\]\r\nSince the series $\\displaystyle \\sum_{n=1}^\\infty \\frac1{n^5}$ converges by the $p$-series test, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{3n^5+n^4+n^3+n^2+n+1}$ converges by the Direct Comparison Test.\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{1}{3n^5+n^4+n^3+n^2+n+1}$ converges absolutely.\r\n\r\n\\subsection*{Comment}\r\n\r\nThis series can be studied using the Limit Comparison Test as well, but this is much more convenient using the Direct Comparison Test.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "7248057222e4dea1c811ea29b6d6c808b41df751", "size": 1797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/i2.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/i2.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/i2.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.2777777778, "max_line_length": 214, "alphanum_fraction": 0.6421814135, "num_tokens": 662, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591568, "lm_q2_score": 0.8757869981319863, "lm_q1q2_score": 0.7593386333142761}}
{"text": "%---------------------------Relative Size-Squared-----------------------------\n\\section{Relative Size Squared\\label{s:tri-rel-size-squared}}\n\nLet $R$ be ratio of the triangle area $A$ to the average area $\\overline{A}$ of an ensemble of triangles\n\\[\n  R = \\frac{A}{\\overline{A}}\n\\]\nThe relative size is the minimum of $R$ and its inverse and the relative size squared is\n\\[\n  q = \\left( \\min\\left\\{R,\\frac{1}{R}\\right\\} \\right)^2.\n\\]\n\nNote that if $R = 0$, we take $q = 0$.\n\n\\trimetrictable{relative size squared}%\n{$1$}%                                                Dimension\n{$[0.25,1]$}%                                         Acceptable range\n{$[0,1]$}%                                            Normal range\n{$[0,1]$}%                                            Full range\n{Dependent on $\\overline{A}$}%                        Unit equilateral triangle value\n{\\cite{knu:03}}%                                      Reference(s)                   \n{v\\_tri\\_relative\\_size\\_squared}%                            Verdict function name\n\n", "meta": {"hexsha": "1b9eba86deaf6fcd3da51d9bf34c061a5548c927", "size": 1039, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/TriRelativeSizeSquared.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/TriRelativeSizeSquared.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/TriRelativeSizeSquared.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 43.2916666667, "max_line_length": 104, "alphanum_fraction": 0.4610202117, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9184802484881361, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7593184560068137}}
{"text": "\\section{Probability} \n\n\\subsection*{Unit 6: Derived distributions}\n$Z = X+Y$ (independent)\\\\\n$p_Z(z) = \\sum_x p_X(x) p_Y(z-x)$\\\\\n$f_Z(z) = \\int_{-\\infty}^{\\infty} f_X(x) f_Y(z-x) dx$\\\\\nSum of independent normals is normal.\\\\\n\nMonotonic transformation: $Y = g(X)$\\\\\n$F_Y(y) = f_X(h(y))\\left|\\frac{dh}{dy}(y)\\right|, h(y) = g^{-1}(x)$\n\n\\subsection*{Unit 6: Deeper view of conditioning}\n\nLaw of iterated expectations $\\mathbf{E}[X] = \\mathbf{E}\\left[\\mathbf{E}[X|Y] \\right]$.\n\nLaw of total variance $Var(X) = \\mathbf{E}\\left[Var(X|Y)\\right] + Var(\\mathbf{E}[X|Y])$\n\nSum of a random number of independent r.v.'s: $Y = X_1 + \\ldots + X_N$\n\n$\\mathbf{E}[Y] = \\mathbf{E}[N] \\cdot \\mathbf{E}[X]$\n\n$Var(Y) = \\mathbf{E}[N]\\,Var(X) + (\\mathbf{E}[X])^2\\,Var(N)$\n\n\n\\subsection*{Unit 8: Limit theorems and classical statistics}\n\nMarkov inequality: $X \\geq 0$ and $a > 0$, then $\\mathbf{P}(X \\geq a) \\leq \\frac{\\mathbf{E}[X]}{a}$\n\nChebyshev inequality: $c > 0$, then $\\mathbf{P}(|X - \\mathbf{E}[X]| \\geq c) \\leq \\frac{Var(X)}{c^2}$\n\nConvergence in probability: for every $\\epsilon > 0$, $\\mathbf{P}(|X_n - a| \\geq \\epsilon) \\rightarrow 0$\n\nWeak law of large numbers: $X_i$ (i.i.d.), $M_n = \\frac{X_1 + \\ldots + X_n}{n} \\rightarrow \\mathbf{E}[X]$\n\nCentral limit theorem: $X_i$ (i.i.d.), $\\text{CDF of }\\frac{X_1 + \\ldots + X_n - n\\mathbf{E}[X]}{\\sqrt{n}\\sigma_X} \\rightarrow \\text{ standard normal CDF}$\n\n\n\\subsection*{Unit 9: The Bernoulli and Poisson processes}\n\n% \\begin{table}[h!]\n%     \\begin{tabular}{lll}\n%     ~                        & Poisson             & Bernoulli     \\\\\n%     Times of arrival         & Continuous          & Discrete      \\\\\n%     Arrival Rate             & $\\lambda$/unit time & $p$/per trial \\\\\n%     PMF of \\# of Arrivals    & Poisson             & Binomial      \\\\\n%     Interarrival Time Distr. & Exponential         & Geometric     \\\\\n%     Time to $k$-th arrival   & Erlang              & Pascal       \n%     \\end{tabular}\n% \\end{table}\n\n\\subsubsection*{Bernoulli process} \n\nNumber of successes/arrivals $S$ in $n$ time slots:\\\\\n$S = X_1 + \\ldots + X_n$ (Binomial)\\\\\n$\\mathbf{P}(S=k) = {n \\choose k} p^k (1-p)^(n-k), k=0,\\ldots,n$\\\\\n$\\mathbf{E}[S] = np$\\\\\n$Var(S) = np(1-p)$\\\\\n\nTime until the first sucess/arrival $T_1$\\\\\n$T_1 = \\min\\lbrace i: X_i = 1\\rbrace$ (Geometric)\\\\\n$\\mathbf{P}(T_1=k) = (1-p)^(k-1)p, k=1,2,\\ldots$\\\\\n$\\mathbf{E}[T_1] = \\frac{1}{p}$\\\\\n$Var(T_1) = \\frac{1-p}{p^2}$\\\\\n\nTime of the $k$-th sucess/arrival\\\\\n$Y_k = T_1 + \\ldots + T_k$ (Pascal), $T_i$ are iid Geometric($p$)\\\\\n$p_{Y_k}(t) = {t-1 \\choose k-1} p^k (1-p)^{t-k}, t=k, k+1, \\ldots$\\\\\n$\\mathbf{E}[Y_k] = \\frac{k}{p}$\\\\\n$Var(Y_k) = \\frac{k(1-p)}{p^2}$\\\\\n\nMerged process\\\\\n$\\text{Bernoulli}(p) + \\text{Bernoulli}(q) = \\text{Bernoulli}(p+q-pq)$\\\\\n$\\mathbf{P}(\\text{arrival in first process} | \\text{arrival}) = \\frac{p}{p+q-pq}$\\\\\n\nSplitting process\\\\\nSplit arrivalssuccesses into two streams, using independent coin flips of a coin with bias $q$:\\\\\nResulting streams are Bernoulli, successes rates are $pq$ and $p(1-q)$.\\\\\nThe two streams are not independent\\\\\n\n\\subsubsection*{Poisson Process}\n\nNumber of arrivals in interval $\\tau$: $N_\\tau$ (Poisson)\\\\\n$P(N_\\tau = k, \\tau) = \\frac{(\\lambda \\tau)^k e^{-\\lambda \\tau}}{k!}, k=0, 1, \\ldots$\\\\\n$\\mathbf{E}[N_\\tau] = \\lambda\\tau$\\\\\n$Var(N_\\tau) = \\lambda\\tau$\\\\\n\nTime until the first sucess/arrival $T_1$ (Exponential($\\lambda$))\\\\\n$T_1 = \\min\\lbrace i: X_i = 1\\rbrace$ (Geometric)\\\\\n$f_{T_1}(t) = \\lambda e^{-\\lambda t}, t \\geq 0$\\\\\n$\\mathbf{E}[T_1] = \\frac{1}{\\lambda}$\\\\\n$Var(T_1) = \\frac{1}{\\lambda^2}$\\\\\n\nTime of the $k$-th sucess/arrival:\\\\\n$Y_k = T_1 + \\ldots + T_k$ (Erlang), $T_i$ are iid Exponentials($\\lambda$)\\\\\n$f_{Y_k}(y) = \\frac{\\lambda^k y^{k-1} e^{-\\lambda y}}{(k-1)!}, y \\geq 0$\\\\\n$\\mathbf{E}[Y_k] = \\frac{k}{\\lambda}$\\\\\n$Var(Y_k) = \\frac{k}{\\lambda^2}$\\\\\n\nMerged process\\\\\n$\\text{Poisson}(\\lambda_1) + \\text{Poisson}(\\lambda_2) = \\text{Poisson}(\\lambda_1+\\lambda_2)$\\\\\n$\\mathbf{P}(k\\text{-th arrival comes from first process}) = \\frac{\\lambda_1}{\\lambda_1+\\lambda_2}$\\\\\nIndependence for different arrivals\\\\\n\nSplitting process\\\\\nSplit arrivals into two streams, using independent coin flips of a coin with bias $q$:\\\\\nResulting streams are Poisson, rates $\\lambda q$ and $\\lambda (1-q)$.\\\\\nResulting streams are independent!", "meta": {"hexsha": "9029c7285e9824590cc5915a312e23cc8376a44a", "size": 4291, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Content_Probability.tex", "max_stars_repo_name": "r2cp/MITx_capstone_1", "max_stars_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_stars_repo_licenses": ["MIT"], "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/Content_Probability.tex", "max_issues_repo_name": "r2cp/MITx_capstone_1", "max_issues_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_issues_repo_licenses": ["MIT"], "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/Content_Probability.tex", "max_forks_repo_name": "r2cp/MITx_capstone_1", "max_forks_repo_head_hexsha": "ca58a5fda25c78afdb27a77b6d6abd02d5579513", "max_forks_repo_licenses": ["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.1028037383, "max_line_length": 155, "alphanum_fraction": 0.6019575856, "num_tokens": 1691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802462567087, "lm_q2_score": 0.8267117898012104, "lm_q1q2_score": 0.7593184482799401}}
{"text": "\\lab{Python}{Polynomial Interpolation Using Chebyshev Polynomials}{Polynomial Interpolation Using Chebyshev Polynomials}\n\\label{lab:cheb_interp}\n\n\\objective{Explore basic uses of polynomial interpolation using Chebyshev polynomials.}\n\n\\section*{Chebyshev nodes}\n\nIn previous labs we have explored ways to compute interpolating polynomials given sets of points.\nWe have also noted that such interpolation may still be a very poor approximation to a function depending on the function itself and the choice of interpolating points.\nThe question then arises, \"when can polynomial interpolation be a good approximation to a given function?\"\nYou may recall that equally spaced points provided a very poor approximation to a given function around the edge of the interval where we are performing the interpolation.\nThis weakness in interpolation using equispaced points is called Runge's Phenomenon.\nWe can avoid Runge's Phenomenon by choosing to interpolate our function with a different set of points.\nSince there is an increased amount of instability toward the edges of the interval where we are interpolating we will choose more points toward the edges of the interval so that the approximation remains accurate throughout the whole interval.\n\nIt can be shown that, when forming an interpolating polynomial of degree $n$, the ideal points to use for interpolation on the interval $[-1, 1]$ are the points $\\cos{\\frac{\\pi k}{n}}$ for $k\\in\\mathbb{Z}$, $0 \\leq k \\leq n$.\nThese points are called the Chebyshev nodes.\nThese points can also be viewed as the projection of equispaced points along the half-circle in the complex plane projected onto the real axis.\nThis interpretation is shown in Figure \\ref{fig:cheb_nodes_projection}.\nThey can be shifted and scaled appropriately for use on any interval.\nAs we have presented them here they are on the interval $[-1, 1]$.\nThese nodes provide for much more stable interpolation of functions as can be seen in Figure \\ref{fig:runge_chebyshev}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{node_project.pdf}\n\\caption{The Chebyshev nodes are the projection of equispaced points on the upper half-circle onto the horizontal axis.\nIn Complex Analysis these points are known as the roots of unity.}\n\\label{fig:cheb_nodes_projection}\n\\end{figure}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{runge_chebyshev.pdf}\n\\caption{Different polynomial interpolants for the Runge function $\\frac{1}{1 + 25 x^2}$ constructed by sampling at the Chebyshev nodes.}\n\\label{fig:runge_chebyshev}\n\\end{figure}\n\n\\begin{problem}\nWrite a function that, given the endpoints $a$ and $b$ of an interval and the order of the desired interpolating polynomial returns the $k+1$ Chebyshev nodes on the interval $[ a, b ]$.\n\\end{problem}\n\n\\section*{Chebyshev Polynomials}\nThis sort of interpolation is also related to what are called the Chebyshev polynomials.\nChebyshev Polynomials can be used very nicely to approximate functions on $[ -1, 1 ]$ and, with proper scaling, can be used to approximate reasonably well-behaved functions on any interval.\nThe $k$'th Chebyshev polynomial is commonly written $T_k \\left( x \\right)$.\nOne way to define the Chebyshev Polynomials is that the $k$'th Chebyshev polynomial on the unit circle is the real part of the function $z^k$ on the unit circle.\nMore precisely, let $z(x) = t + i \\sqrt{1 - x^2}$, then the $k$'th Chebyshev polynomial on $[-1, 1]$ is the real part of the polynomial $x^k$.\nWe can write this real part explicitly as\n\\[T_k \\left( x \\right) = \\frac{1}{2} \\left( z^k + z^{-k} \\right) = \\cos \\left( k \\cos^{-1} \\left( x \\right) \\right)\\]\nNotice that, as this function has been defined, the Chebyshev polynomial of order $k$ on an interval takes values of $1$ and $-1$ at the $k+1$ chebyshev points corresponding to interpolation with a polynomial of order $k$ on that interval.\nThe first few Chebyshev polynomials are shown in Figure \\ref{fig:cheb_polys}.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{cheb_polys.pdf}\n\\caption{The first few Chebyshev Polynomials.}\n\\label{fig:cheb_polys}\n\\end{figure}\n\nThese polynomials are orthogonal with respect to the integral inner product\n\\[\\langle f, g \\rangle = \\int_{-1}^1 \\frac{1}{\\sqrt{1 - x^2}} f\\left( x \\right) g\\left( x \\right) dx\\]\nThis inner product allows us to write many functions as an infinite series of Chebyshev polynomials.\nIn particular, we can write any polynomial as a finite series of Chebyshev polynomials.\nAs it turns out, it is relatively easy to compute the Chebyshev series representation of an interpolating polynomial for a function on a given interval.\nThese approximations converge to the function we are approximating nearly as well as the partial sums of the infinite series formed using the inner product above, so, in practice, we will use them instead.\n\nIt can be shown that the Chebyshev polynomials follow the following recurrence relation: $ T_{k+1} \\left( x \\right) = 2 x T_k \\left( x \\right) - T_{k-1}$.\n$T_0 \\left( x \\right)$ is equal $1$ and $T_1 \\left( x \\right)$ is equal to $x$ (still working on the interval $[-1, 1]$.)\nThis recurrence relation forms the basis for what is known as Clenshaw's Algorithm.\nClensaw's Algorithm says that, given a polynomial of degree $n$ represented as a sum of Chebyshev polynomials:\n\\[p\\left(x\\right) = \\sum_{k=0}^{n} a_k T_k\\left(x\\right)\\]\n$p(x)$ can be evaluated by the recursion process outlined in Algorithm \\ref{alg:clenshaw_recursion}.\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\Procedure{ClenshawRecursion}{$X, c$}\n\t\\State $u_{n+1} \\gets 0$\n\t\\State $u_{n} \\gets a_{n}$\n\t\\State $k \\gets n-1$\n\t\\While{$k \\geq -1$}\n\t\t\\State $u_k \\gets 2 x u_{k+1} - u_{k+2} + a_k$\n\t\t\\State $k \\gets k-1$\n\t\\EndWhile\n\t\\State \\pseudoli{return} $\\frac{1}{2} \\left( a_0 + u_0 - u_2 \\right)$\n\\EndProcedure\n\\end{algorithmic}\n\\caption{Clenshaw Recursion}\n\\label{alg:clenshaw_recursion}\n\\end{algorithm}\n\nThe following recursion is equivalent to Algorithm \\ref{alg:clenshaw_recursion}.\nLet $u_{n+1} = 0$ and $u_{n} = a_n$ and $u_k = 2 x u_{k+1} - u_{k+2} + a_k$ for $k = n-1, n-2, \\dots, 0$, then $p(x) = \\frac{1}{2} \\left( a_0 + u_0 - u_2 \\right)$.\n\n\\begin{problem}\nWrite a Python function that performs Clenshaw's algorithm to evaluate a series of Chebyshev polynomials for an array of points in the interval $[-1, 1]$.\nUse it to plot the first $5$ Chebyshev polynomials on that interval.\n\\end{problem}\n\n\\section*{Chebyshev Polynomials and Fourier Series}\nIn looking at the plots of the Chebyshev polynomials you may have noticed that the Chebyshev polynomials take alternating values of $1$ and $-1$ at the Chebyshev points on the interval $[-1,1]$ similar to how the functions $\\cos\\left(k x \\right)$ change between $-1$ and $1$ on equispaced points in the interval $[ 0 , \\pi ]$.\nRecall that, as mentioned above, $T_k \\left( x \\right) = \\cos \\left( k \\cos^{-1} \\left( x \\right) \\right)$.\nFor discrete samples, this means that the Chebyshev coefficients for the interpolating polynomial through a function at the Chebyshev nodes has the same coefficients as the discrete cosine series would at the points $\\cos^{-1} x$ where $x$ is a chebyshev node.\nIn practice this means we can compute an array of samples of a function at the Chebyshev nodes of the interval $[-1, 1]$, then compute the discrete cosine transform to get the corresponding coefficients to the Chebyshev interpolation.\nThis is very helpful since the discrete cosine transform is a close relative of the discrete Fourier transform.\n\\li{scipy.fftpack} and \\li{pyfftw} both include discrete cosine transforms as \\li{scipy.fftpack.dct} and \\li{pyfftw.interfaces.scipy_fftpack.dct} respectively.\nThe discrete cosine transform is defined a little differently than the coefficients we need here.\nTo get the coefficients, follow these steps:\n\n\\begin{itemize}\n\n\\item Sample the function you desire to approximate at the Chebyshev nodes.\n\n\\item Compute the discrete cosine transform of the data.\nUse the option \\li{type=1} to tell either scipy or pyfftw the version of the discrete cosine transform you want to use. (this one is the closest to the version we want).\n\n\\item Divide all the coefficients by $\\left( N - 1 \\right)$ where $N$ is the number of nodes used.\n\n\\item Divide the first and last coefficient by $2$.\n\n\\item Multiply all the odd indices by $-1$.\n\n\\end{itemize}\n\n\\begin{problem}\nWrite a function that, given the samples for a function at the chebyshev nodes for a funciton on an interval computes the coefficients for the Chebyshev representation of the interpolating polynomial through the samples at the Chebyshev nodes.\n\\end{problem}\n\n\\section*{NumPy's Chebyshev Module}\n\nNumPy includes a module for working with Chebyshev polynomials and Chebyshev series alongside its polynomials module.\nIt does not include all of the functions we had you write today, but it does include many other useful things.\nThis module includes a Python class for Chebyshev polynomials.\nIt works much like the poly1d class that is used for polynomials.\nHere are a few lines of code that use NumPy's Chebyshev class to evaluate the 20'th Chebyshev polynomial.\nWe will plot the corresponding function using Matplotlib.\n\\begin{lstlisting}\nimport numpy as np\nfrom numpy.random import rand\nimport numpy.polynomial.chebyshev as ch\nfrom matplotlib import pyplot as plt\ncoefficients = np.zeros(20)\ncoefficients[-1] = 1\npoly = ch.Chebyshev(coefficients)\nX = np.linspace(-1, 1, 2001)\nY = poly(X)\nplt.plot(X, Y)\nplt.show()\n\\end{lstlisting}\n\nHere we used the Chebyshev class to evaluate a Chebyshev series.\nIt also includes other methods that allow you to multiply, divide, differentiate, and integrate Chebyshev series.\nWe will discuss integration and differentiation later on.\nThere are also functions that allow you to convert back and forth between Chebyshev series and standard polynomials.\n\n\\begin{problem}\n\\label{prob:cheb_interpolations}\nWe will briefly consider the rate of convergence of these polynomial approximations.\nCompute the coefficients for the interpolating Chebyshev series for the function $\\cos x$ on the interval $[-1, 1]$.\nThis approximation converges very rapidly, so the first $20$ terms or so should be more than enough.\nHow many of these coefficients have absolute value greater than $10^{-14}$?\nHow close does your series approximate the actual function?\n\nNow compute the coefficients for a degree $100000$ polynomial approximating the function\n\\[\\sin \\left( \\frac{1}{x} \\right) \\sin \\left( \\frac{1}{\\sin \\left( \\frac{1}{x} \\right)} \\right) \\]\non the interval $[-1, 1]$.\nHow large are the last $10$ coefficients in the series?\nUse NumPy's Chebyshev class to plot this function at $100001$ equispaced points on the interval $[-1, 1]$.\nPlot it with the original function.\nCompare the two.\nHow close are they?\nNotice how the interpolating polynomial is able to approximate the original function about as well as the discrete sample of the original function.\n\\end{problem}\n\nProblem \\ref{prob:cheb_interpolations} also illustrates an interesting principle.\nThese series converge more quickly when a function is infinitely differentiable everywhere in the complex plane (the proper term for a function like this is \"entire\").\nFor functions that do not satisfy this property, it can be shown (roughly speaking) that the rate of convergence depends on how many times differentiable the function is on the interval of interpolation.\nFor a less well-behaved function like the one considered in the second half of Problem \\ref{prob:cheb_interpolations} the coefficients converge much more slowly.\nThe last $10$ coefficients for the interpolant of degree $2^{23} - 1$ are still\n\\begin{lstlisting}\n[9.52973125e-08,  -1.89451973e-09,  -7.42182166e-08,\n 1.89319137e-09,   5.26564839e-08,  -1.89451836e-09,\n -3.13050802e-08,   1.89319005e-09,   1.03700608e-08,\n -9.47258778e-10]\n\\end{lstlisting}\n\n% We could add in a problem where they interpolate the PDF of the standard normal distribution and use it to estimate the CDF at different values.\n% Given a proper setup, such an approximation gives correct answers to machine precision in about the same amount of time as the version in Scipy.stats.\n% The only limitation is that the interpolant is limited to a specific interval instead of allowing approximation anywhere.\n% That isn't much of an issue though since the PDF is practically 0 outside a reasonably-sized interval anyway.\n", "meta": {"hexsha": "caaf1404c01f5f27f59b88fae83755073c2b0a3e", "size": 12368, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/chebyshev/chebyshev_interp.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/chebyshev/chebyshev_interp.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/chebyshev/chebyshev_interp.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": 65.7872340426, "max_line_length": 326, "alphanum_fraction": 0.7711028461, "num_tokens": 3300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973932, "lm_q2_score": 0.8872046026642944, "lm_q1q2_score": 0.7593150865708534}}
{"text": "\\section{Multidimensional Gaussian}\r\nA random variable $X$ in $\\mathbb R$ is called Gaussian if $X\\sim\\mu+\\sigma Z$ for $Z\\sim\\mathcal N(0,1)$.\r\nIt has density, as we have seen,\r\n$$f_X(x)=\\frac{1}{\\sqrt{2\\pi\\sigma^2}}e^{-(x-\\mu)^2/(2\\sigma^2)}$$\r\nand we denote this by $X\\sim\\mathcal N(\\mu,\\sigma^2)$.\r\nWe want to generalize this to higher dimensions.\r\n\\begin{definition}\r\n    A random variable $X=(X_1,\\ldots,X_n)$ is Gaussian if for any $u\\in\\mathbb R^n$, $u^\\top X$ is Gaussian in $\\mathbb R$.\\\\\r\n    We call $X$ a Gaussian vector.\r\n\\end{definition}\r\nSuppose now that we have an $n\\times n$ matrix $A$ and $b\\in\\mathbb R^n$, then $AX+b$ is also Gaussian.\r\nThis is obvious from definition.\\\\\r\nSet\r\n$$\\mu=\\mathbb E[X]=\\begin{pmatrix}\r\n    \\mathbb E[X_1]\\\\\r\n    \\vdots\\\\\r\n    \\mathbb E[X_n]\r\n\\end{pmatrix},V=\\operatorname{Var}(X)=\\mathbb E[(X-\\mu)(X^\\top-\\mu)]=(\\operatorname{Cov}(X_i,X_j))_{i,j}$$\r\nLet $u\\in\\mathbb R^n$, then $\\mathbb E[u^\\top X]=u^\\top\\mu$ and the variance is $\\operatorname{Var}(u^\\top X)=u^\\top Vu$, so $u^\\top X\\sim\\mathcal N(u^\\top\\mu,u^\\top Vu)$.\r\n$V$ is symmetric as $\\operatorname{Cov}$ is, also by above $u^\\top Vu$ is always nonegative, so $V$ is nonnegative definite.\r\nWe want to know the MGF of $X$.\r\nLet $\\lambda\\in\\mathbb R^n$, then $m(\\lambda)=\\mathbb E[e^{\\lambda^\\top X}]$, but we know the distribution of $\\lambda^\\top X$ which is $\\mathcal N(u^\\top\\mu,u^\\top Vu)$, therefore $m(\\lambda)=e^{\\lambda^\\top\\mu+\\lambda^\\top V\\lambda/2}$.\r\nSo by uniqueness of MGFs, we see that the distribution of a Gaussian vector is uniquely characterized by its mean $\\mu$ and variance $V$, so we write $X\\sim\\mathcal N(\\mu,V)$.\\\\\r\nAs $V$ is real symmetric and nonnegative definite, we can write $V=U^\\top DU$ where $U$ is real orthogonal and $D=\\operatorname{diag}(\\lambda_1,\\ldots,\\lambda_n)$ where $\\lambda_i\\ge 0$ for all $i$.\r\nSo we define the square root matrix of $V$ to be\r\n$$\\sigma=U^\\top \\sqrt{D}U,\\sqrt{D}=\\operatorname{diag}(\\sqrt{\\lambda_1},\\ldots,\\sqrt{\\lambda_n})$$\r\nSo $\\sigma^2=V$, therefore we can write $X\\sim\\mathcal N(\\mu,\\sigma^2)$.\\\\\r\nLet $Z_1,\\ldots,Z_n$ be i.i.d. $\\mathcal N(0,1)$ and $Z=(Z_1,\\ldots,Z_n)^\\top$, then $Z$ is Gaussian (by e.g. looking at its MGF) and $Z\\sim\\mathcal N(0,I)$.\r\nLet $X=\\mu+\\sigma Z$ where $\\mu\\in\\mathbb R^n$ and $\\sigma$ is real symmetric and nonnegative definite, then $X$ is Gaussian since $x\\mapsto \\mu+\\sigma x$ is linear.\r\nAlso $\\mathbb E[X]=\\mu$ and\r\n$$\\operatorname{Var}(X)=\\mathbb E[(X-\\mu)(X-\\mu)^\\top]=\\sigma\\mathbb E[ZZ^\\top]\\sigma=\\sigma I\\sigma=\\sigma^2$$\r\nSo $X\\sim\\mathcal N(\\mu,\\sigma^2)$.\\\\\r\nWe want to find the density function of a multivariate normal.\r\nAssuming that $V$ is positive definite and $X\\sim\\mathcal N(\\mu,V)$, then $\\det V=\\prod_i\\lambda_i>0$.\r\nAlso since $X=\\mu+\\sigma Z$, we can invert to get $Z=\\sigma^{-1}(X-\\mu)$, hence\r\n\\begin{align*}\r\n    f_X(x)&=f_Z(z)|J|\\\\\r\n    &=\\prod_{i=1}^n\\frac{e^{-z_i^2/2}}{\\sqrt{2\\pi}}\\det(\\sigma^{-1})=\\frac{1}{\\sqrt{(2\\pi)^n\\det V}}e^{-z^\\top z/2}\\\\\r\n    &=\\frac{1}{\\sqrt{(2\\pi)^n\\det V}}e^{-(x-\\mu)^\\top V^{-1}(x-\\mu)/2}\r\n\\end{align*}\r\nIf we only assume $V$ is nonnegative definite, then we can have $0$ eigenvalues hence $0$ determinant.\r\nIn this case, we can change the basis to get something of the form\r\n$$\\begin{pmatrix}\r\n    U&0\\\\\r\n    0&0\r\n\\end{pmatrix}$$\r\nwhere $U$ is positive definite $m\\times m$ matrix and $\\mu=(\\lambda^\\top,\\nu^\\top)^\\top$ where $\\lambda\\in\\mathbb R^m,\\nu\\in\\mathbb R^n$, then we write $X=(Y^\\top,\\nu^\\top)^\\top$ where $Y$ has\r\n$$f_Y(y)=\\frac{1}{\\sqrt{(2\\pi)^n\\det U}}e^{-(y-\\lambda)^\\top U^{-1}(y-\\lambda)/2}$$\r\n\\begin{proposition}\r\n    Let $X=(X_1,\\ldots,X_n)$ be Gaussian, and suppose that $\\operatorname{Cov}(X_i,X_j)=0$ when $i\\neq j$, then $X_i$ are independent Gaussians.\r\n\\end{proposition}\r\nNote that the converse is obviously true.\r\n\\begin{proof}\r\n    The covariant matrix is diagonal, so the density factorizes.\r\n\\end{proof}\r\nAnother way to see it is by simply looking at the MGF.\\\\\r\nNow we consider the bivariate Gaussians.\r\nSuppose $X=(X_1,X_2)$ is Gaussian and we set $\\mu_k=\\mathbb E[X_k],\\sigma_k=\\sqrt{\\operatorname{Var}(X_k)}$ and suppose $\\sigma_k>0$, we define\r\n$$\\rho=\\operatorname{corr}(X_1,X_2)=\\frac{\\operatorname{Cov}(X_1,X_2)}{\\sqrt{\\operatorname{Var}(X_1)\\operatorname{Var}(X_2)}}$$\r\nHence we have\r\n$$V=\\operatorname{Var}(X)=\\begin{pmatrix}\r\n    \\sigma_1^2&\\rho\\sigma_1\\sigma_2\\\\\r\n    \\rho\\sigma_1\\sigma_2&\\sigma_2^2\r\n\\end{pmatrix}$$\r\nWe want to show that $V$ is nonnegative definite for any $\\rho$.\r\nIndeed, for any $x=(x_1,x_2)^\\top$, we have $x^\\top Vx\\ge 0$ by calculation.\r\nin particular, if $\\rho=0$ and $\\sigma_k>0$, then $f_{X_1,X_2}(x_1,x_2)$ can be found by multiplying the $\\mathcal N(\\mu_k,\\sigma_k)$ since $X_1,X_2$ are independent as we have seen before.\\\\\r\nLet $a\\in\\mathbb R$, then $\\operatorname{Cov}(X_2-aX_1,X_1)=\\operatorname{Cov}(X_1,X_2)-a\\operatorname{Var}(X_1)=\\rho\\sigma_1\\sigma_2-a\\sigma_1^2$.\r\nTake $a=\\rho\\sigma_1/\\sigma_2$ and $Y=X_2-aX_1$, then $\\operatorname{Cov}(X_1,Y)=0$ and we can write\r\n$$\\begin{pmatrix}\r\n    X_1\\\\\r\n    Y\r\n\\end{pmatrix}=\\begin{pmatrix}\r\n    1&0\\\\\r\n    -a&1\r\n\\end{pmatrix}\\begin{pmatrix}\r\n    X_1\\\\\r\n    X_2\r\n\\end{pmatrix}$$\r\nSo $(X_1,Y)^\\top$ is also Gaussian.\r\n$X_1,Y$ are independent and we can write $X_2=Y+aX_1$ and $\\mathbb E[X_2|X_1]=\\mathbb E[Y]+aX_2$.\r\n\\begin{theorem}\r\n    Let $X$ be a Gaussian vector in $\\mathbb R^k$ with finite variance.\r\n    Suppose $X$ has covariance matrix $\\Sigma$.\r\n    Let $X_1,\\ldots$ be i.i.d. copies of $X$, then\r\n    $$S_n=\\frac{1}{\\sqrt{n}}\\sum_{i=1}^n(X_i-\\mathbb E[X_i])\\to\\mathcal N(0,\\Sigma)$$\r\n    in the sense that for any (measurable) $B\\in\\mathbb R^k$, $\\mathbb P(S_n\\in B)\\to \\mathbb P(\\mathcal N(0,\\Sigma)\\in B)$.\r\n\\end{theorem}", "meta": {"hexsha": "302a99fd9e36437b23ccf53d19a1dd06e9a8bb85", "size": 5731, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15/gaussian.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": "15/gaussian.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": "15/gaussian.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": 65.125, "max_line_length": 239, "alphanum_fraction": 0.6553830047, "num_tokens": 2158, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672593, "lm_q2_score": 0.8872045877523147, "lm_q1q2_score": 0.759315064022433}}
{"text": "\\section{Uniqueness of the {\\rref}}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Determine whether two systems of equations are row equivalent,\n    by comparing their {\\rref}.\n  \\item For two homogeneous systems of equations that are not row\n    equivalent, find a solution to one system that is not a solution\n    to the other.\n  \\end{enumerate}\n\\end{outcome}\n\nWe have seen in earlier sections that every matrix can be brought into\n{\\rref} by a sequence of elementary row operations. Here we will prove\nthat the resulting matrix is unique; in other words, the resulting\nmatrix in {\\rref} does not depend upon the particular sequence of\nelementary row operations or the order in which they were performed.\n\nLet $A$ be the augmented matrix of a homogeneous system of linear\nequations in the variables $x_1, x_2,\\ldots, x_n$ which is also in\n{\\rref}. Recall that the matrix $A$ divides the set of variables in\ntwo different types: $x_i$ is a {\\em pivot variable}%\n\\index{variable!pivot} when column $i$ is a pivot column, and a {\\em\n  free variable}%\n\\index{variable!free} otherwise.\n\n\\begin{example}{Pivot and free variables}{pivot-free}\n  Find the pivot and free variables in the following system, and find\n  the general solution.\n  \\begin{equation*}\n    \\begin{array}{c}\n      x+2y-z+w=0 \\\\\n      x+y-z+w=0 \\\\\n      x+3y-z+w=0\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The {\\rref} of the augmented matrix is\n  \\begin{equation*}\n    \\begin{mymatrix}{rrrr|r}\n      \\circled{1} & 0 & -1 & 1 & 0 \\\\\n      0 & \\circled{1} & 0 & 0 & 0 \\\\\n      0 & 0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  From this, we see that columns $1$ and $2$ are pivot\n  columns. Therefore, $x$ and $y$ are pivot variables and $z$ and $w$\n  are free variables. We can write the solution to this system as\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x &=& s-t \\\\\n      y &=& 0 \\\\\n      z &=& s \\\\\n      w &=& t.\n    \\end{array}\n  \\end{equation*}\n\\end{solution}\n\nIn general, all solutions can be written in terms of the free\nvariables. In such a description, the free variables are written as\nparameters, while the pivot variables are written as functions of\nthese parameters. Indeed, a pivot variable $x_i$ is a function of {\\em\n  only} those free variables $x_j$ with $j>i$. This leads to the\nfollowing observation.\n\n\\begin{proposition}{Pivot and free variables}{pivot-free}\n  If $x_i$ is a pivot variable of a homogeneous system of linear\n  equations, then any solution of the system with $x_j=0$ for all\n  those free variables $x_j$ with $j>i$ must also have $x_i=0$.\n\\end{proposition}\n\nUsing this proposition, we prove a lemma which will be used in the\nproof of the main result of this section.\n\n\\begin{lemma}{Solutions and the {\\rref} of a matrix}{rref-solutions}\n  Let $A$ and $B$ be two augmented matrices for two homogeneous\n  systems of $m$ equations in $n$ variables, such that $A$ and $B$ are\n  each in {\\rref}. If $A$ and $B$ are different, then the two systems\n  do not have exactly the same solutions.\n\\end{lemma}\n\n\\begin{proof}\n  With respect to the linear systems associated with the matrices $A$ and $B$, there are two cases to consider:\n  \\begin{itemize}\n  \\item Case $1$: the two systems have the same pivot variables\n  \\item Case $2$: the two systems do not have the same pivot variables\n  \\end{itemize}\n  In case $1$, the two matrices will have exactly the same pivot\n  positions. However, since $A$ and $B$ are not identical, there is\n  some row of $A$ which is different from the corresponding row of $B$\n  and yet the rows each have a pivot in the same column position. Let\n  $i$ be the index of this column position. Since the matrices are in\n  {\\rref}, the two rows must differ at some entry in a column\n  $j>i$. Let these entries be $a$ in $A$ and $b$ in $B$, where\n  $a \\neq b$. Since $A$ is in {\\rref}, if $x_j$ were a pivot variable\n  for its linear system, we would have $a=0$. Similarly, if $x_j$ were\n  a pivot variable for the linear system of the matrix $B$, we would\n  have $b=0$. Since $a$ and $b$ are unequal, they cannot both be equal\n  to $0$, and hence $x_j$ cannot be a pivot variable for both linear\n  systems. However, since the systems have the same pivot variables,\n  $x_j$ must then be a free variable for each system. We now look at\n  the solutions of the systems in which $x_j$ is set equal to $1$ and\n  all other free variables are set equal to $0$. For this choice of\n  parameters, the solution of the system for matrix $A$ has $x_i=-a$,\n  while the solution of the system for matrix $B$ has $x_i=-b$, so\n  that the two systems have different solutions.\n\n  In case $2$, there is a variable $x_i$ which is a pivot variable for\n  one matrix, let's say $A$, and a free variable for the other matrix\n  $B$. The system for matrix $B$ has a solution in which $x_i=1$ and\n  $x_j=0$ for all other free variables $x_j$. However, by\n  Proposition~\\ref{prop:pivot-free} this cannot be a solution of the\n  system for the matrix $A$. This completes the proof of case $2$.\n\\end{proof}\n\nNow, we say that the matrix $B$ is \\textbf{row equivalent}%\n\\index{matrix!row equivalence}%\n\\index{row equivalence}%\n\\index{equivalence!row equivalence}\nto the matrix $A$ if $B$ can be obtained from\n$A$ by performing a sequence of elementary row operations. By\nTheorem~\\ref{thm:elementary-operations-and-solutions}, we know that row\nequivalent systems have exactly the same solutions. Now, we can use\nLemma~\\ref{lem:rref-solutions} to prove the main result of this\nsection, which is that each matrix $A$ has a unique {\\rref}.\n\n\\begin{theorem}{Uniqueness of the {\\rref}}{unique-rref}\n  Every matrix $A$ is row equivalent to a unique matrix in {\\rref}.\n\\end{theorem}\n\n\\begin{proof}\n  By Gauss-Jordan elimination, we already know that every matrix is\n  row equivalent to some {\\rref}. What we must show is that the\n  resulting {\\rref} is unique, i.e., does not depend on the order in\n  which row operations are performed.\n\n  Therefore, let $A$ be an $m \\times n$-matrix and let $B$ and $C$ be\n  matrices in {\\rref}, each row equivalent to $A$. We have to show\n  that $B=C$.\n\n  Let $A^{+}$ be the matrix $A$ augmented with a new rightmost column\n  consisting entirely of zeros. Similarly, augment matrices $B$ and\n  $C$ each with a rightmost column of zeros to obtain $B^{+}$ and\n  $C^{+}$. Note that $B^{+}$ and $C^{+}$ are augmented matrices in\n  {\\rref}, and that both $B^{+}$ and $C^{+}$ are row equivalent to\n  $A^{+}$, because the addition of a column of zeros does not change\n  the effect of any row operations.\n\n  Now, $A^{+}$, $B^{+}$, and $C^{+}$ can all be considered as\n  augmented matrices of homogeneous linear systems in the variables\n  $x_1, x_2,\\ldots, x_n$. Because all three systems are row\n  equivalent, they have exactly the same solutions. By\n  Lemma~\\ref{lem:rref-solutions}, we conclude that $B^{+}=C^{+}$.\n  Omitting the final column of zeros, we must also have $B=C$.\n\\end{proof}\n\n\\begin{example}{Row equivalent systems}{determinant-row-equivalent}\n  Determine whether the following two systems of equations are row\n  equivalent.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      2x + 3y + z &=& 12 \\\\\n      x - 2y + 4z &=& -1 \\\\\n      x + 2z &=& 3,\n    \\end{array}\n    \\quad\\quad\n    \\begin{array}{r@{~}c@{~}l}\n      x + 2y &=& 7 \\\\\n      3x - y + 7z &=& 7 \\\\\n      y - z &=& 2.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The augmented matrices for the two systems are:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      2 & 3 & 1 & 12 \\\\\n      1 & -2 & 4 & -1 \\\\\n      1 & 0 & 2 & 3\n    \\end{mymatrix},\n    \\quad\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 & 2 & 0 & 7 \\\\\n      3 & -1 & 7 & 7 \\\\\n      0 & 1 & -1 & 2\n    \\end{mymatrix}.\n  \\end{equation*}\n  The {\\rref}s of the two augmented matrices are:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 2 & 3 \\\\\n      0 & 1 & -1 & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix},\n    \\quad\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 2 & 3 \\\\\n      0 & 1 & -1 & 2 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since both systems have the same {\\rref}, they are row equivalent.\n\\end{solution}\n\n\\begin{example}{Non-row equivalent systems}{non-row-equivalent}\n  Determine whether the following two systems of equations are row\n  equivalent. If they are not row equivalent, find a solution to one\n  system that is not a solution to the other.\n  \\begin{equation*}\n    \\begin{array}{r@{~}c@{~}l}\n      x - 2y - 5z &=& 0 \\\\\n      x + z &=& 0 \\\\\n      x + y + 4z &=& 0,\n    \\end{array}\n    \\quad\\quad\n    \\begin{array}{r@{~}c@{~}l}\n      2x + 2y + z &=& 0 \\\\\n      x + y + 3z &=& 0 \\\\\n      -x - y + 2z &=& 0.\n    \\end{array}\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  The augmented matrices for the two systems are:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & -2 & -5 & 0 \\\\\n      1 & 0 & 1 & 0 \\\\\n      1 & 1 & 4 & 0\n    \\end{mymatrix},\n    \\quad\\quad\n    \\begin{mymatrix}{rrr|r}\n      2 & 2 & 1 & 0 \\\\\n      1 & 1 & 3 & 0 \\\\\n      -1 & -1 & 2 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  The {\\rref}s of the two augmented matrices are:\n  \\begin{equation*}\n    \\begin{mymatrix}{rrr|r}\n      1 & 0 & 1 & 0 \\\\\n      0 & 1 & 3 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix},\n    \\quad\\quad\n    \\begin{mymatrix}{rrr|r}\n      1 & 1 & 0 & 0 \\\\\n      0 & 0 & 1 & 0 \\\\\n      0 & 0 & 0 & 0\n    \\end{mymatrix}.\n  \\end{equation*}\n  Since the two systems have different {\\rref}s, they are not row\n  equivalent.  Following the proof of Lemma~\\ref{lem:rref-solutions},\n  we see that $z$ is a free variable for the first system, but a pivot\n  variable for the second system. Therefore, there exists a solution\n  of the first system with $z=1$, namely $(x,y,z) = (-1,-3,1)$. But\n  there exists no solution for the second system with $z=1$, and in\n  particular, $(x,y,z) = (-1,-3,1)$ is not a solution of the second\n  system.\n\\end{solution}\n\nWe finish this section by pointing out an important consequence of\nTheorem~\\ref{thm:unique-rref}, namely that the rank%\n\\index{rank} of a matrix is well-defined. Recall that in\nDefinition~\\ref{def:rank}, we defined the rank of a matrix $A$ to be\nthe number of pivot entries of ``any'' {\\ef} of $A$. It was not clear,\nhowever, why different {\\ef}s of $A$ could not have different numbers\nof pivot entries. Now we can answer this question. By the Gauss-Jordan\nalgorithm, we know that every {\\ef} can be converted to a {\\rref}\nwithout changing the number or position of the pivots. Since the\n{\\rref} is unique, it follows that all {\\ef}s of $A$ have the same\nnumber of pivot entries (and in fact the same pivot\ncolumns). Therefore, the rank of $A$ is a well-defined quantity.\n", "meta": {"hexsha": "efb543bea285995162da7c762fb5d02d23836f07", "size": 10691, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/SystemsofEquations-UniquenessRREF.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-UniquenessRREF.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-UniquenessRREF.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.3189964158, "max_line_length": 111, "alphanum_fraction": 0.6587784117, "num_tokens": 3404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120234, "lm_q2_score": 0.9111796979521253, "lm_q1q2_score": 0.7593084530524865}}
{"text": "\\section{Periodic Scheduling}\nPeriodic scheduling is always preemptive.\n\\begin{center}\n\t{\\renewcommand{\\arraystretch}{2}\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\hline\n\t\t\t\t\t\t\t& Deadline = Period\t& Deadline $\\leq$ Period\t\\tabularnewline\\hline\n\t\tStatic Priority\t\t& Rate Monotonic\t& Deadline Monotonic\t\t\\tabularnewline\\hline\n\t\tDynamic Priority\t& EDF\t\t\t\t& EDF*\t\t\t\t\t\t\\tabularnewline\\hline\n\t\\end{tabular}}\n\\end{center}\n\n\\subsection{Definitions}\n\\begin{itemize}\n\t\\item $\\Gamma = \\set{\\tau_1, \\tau_2, \\dots \\tau_n}$\tis set of periodic tasks.\n\t\\item $\\tau_{i,j}$ is the $j$-th instance of task $\\tau_i$.\n\t\\item $a_{i,j}, r_{i,j}, d_{i,j}, s_{i,j}, f_{i,j}$ are the same as for aperiodic tasks.\n\t\\item $\\Phi_i$ is the phase of task $i$ (release time of the first instance).\n\t\\item $D_i$ is the relative deadline of task $i$.\n\t\\item $T_i$ is the period of the task (time between 2 releases).\n\\end{itemize}\n\nThe following hypotheses are assumed\n\\begin{itemize}\n\t\\item $r_{i,j} = \\Phi_i + (j - 1) T_i$\n\t\\item $C_i$ is constant.\n\t\\item $d_{i,j} = \\Phi_i + (j - 1) T_i + D_i$\n\t\\item The tasks are independent\n\\end{itemize}\n\n\\subsection{Rate Monotonic}\nAlways schedule the task that has the shortest period.\nSufficient (but not necessary) schedulability test:\n\\begin{equation*}\n\t\\sum_{i = 1}^n \\frac{C_i}{T_i} \\leq n \\left( 2^{\\frac{1}{n}} - 1 \\right)\n\\end{equation*}\n\n\\subsection{Deadline Monotonic}\nAlways schedule the task that has the shortest relative deadline.\nSufficient (but not necessary) schedulability test:\n\\begin{equation*}\n\t\\sum_{i = 1}^n \\frac{C_i}{D_i} \\leq n \\left( 2^{\\frac{1}{n}} - 1 \\right)\n\\end{equation*}\n\n\\subsection{Necessary and sufficient schedulability test}\nWe define the interference $I_i$ for task $i$ as\n\\begin{equation*}\n\tI_i(t) = \\sum_{j = 1}^{i - 1} \\ceil{\\frac{t}{T_j}} C_j\n\\end{equation*}\nwhere the tasks are ordered such that $m < n \\iff D_m < D_n$\n\n\\subsubsection{Algorithm}\nThe tasks are ordered as described above.\n\\begin{lstlisting}[escapeinside={(*}{*)}]\nforeach ((*$\\tau_i$*) (*$\\in$*) (*$\\Gamma$*)) {\n\tI = 0;\n\tdo {\n\t\tR = I + (*$C_i$*);\n\t\tif (R > (*$D_i$*)) return false; // unschedulable\n\t\tI = (*$\\sum\\limits_{j = 1}^{i - 1} \\ceil{\\frac{\\mathrm{R}}{T_j}} C_j$*);\n\t} while (I + (*$C_i$*) > R);\n}\nreturn true;\n\\end{lstlisting}\nThe final values \\texttt{R} are the longest response times.\n\n\\subsection{EDF}\nAlways schedule the task with the earliest deadline.\nFor $D_i = T_i$ the tasks are schedulable with EDF iff\n$\\sum\\limits_{i = 1}^{n} \\frac{C_i}{T_i} = U \\leq 1$.\n\nIf $D_i \\leq T_i$, then the test\n$\\sum\\limits_{i = 1}^{n} \\frac{C_i}{D_i} \\leq 1$ is sufficient but not\nneccesary.\n", "meta": {"hexsha": "1e5dfe1d1c4c5111e2009afa7656d832ee924f72", "size": 2597, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "embedded systems/sections/periodic.tex", "max_stars_repo_name": "ntruessel/eth-summaries", "max_stars_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "embedded systems/sections/periodic.tex", "max_issues_repo_name": "ntruessel/eth-summaries", "max_issues_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "embedded systems/sections/periodic.tex", "max_forks_repo_name": "ntruessel/eth-summaries", "max_forks_repo_head_hexsha": "dbfa4c206b441868a6ab55331c42daa96abd42bf", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6266666667, "max_line_length": 89, "alphanum_fraction": 0.6715440893, "num_tokens": 937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206791658465, "lm_q2_score": 0.8418256512199033, "lm_q1q2_score": 0.7592599630874862}}
{"text": "\\documentclass[../../main.tex]{subfiles}\n\\begin{document}\n\\section{Definitions and preliminaries}\n\nIn the course of this thesis, we will among others need the following definitions.\n\n%%%%%%%%%%%%%%%%   Partition  %%%%%%%%%%%%%%%%\n\n\\begin{definition}\nA partition of a set $A$, is a family, $\\{A_{i}\\}_{i\\in \\N}$ of subsets of $A$, satisfying:\n\\begin{itemize}\n\\item $A_{i} \\cap A_{j} = \\emptyset$ for all $i, j\\in \\N$ with $i \\neq j$,\n\\item $\\bigcup_{i\\in \\N} A_{i}=A$.\n\\end{itemize}\n\\end{definition}\n\n%%%%%%%%%%%%%%%%   Sigma-algebra, measurable space, and measures  %%%%%%%%%%%%%%%%\n\n\\begin{definition}\nA $\\sigma$-algebra, $\\m{A}$, on a set $X$, is a family of subsets of $X$ satisfying\n\\begin{itemize}\n\\item $X\\in \\m{A}$,\n\\item $A \\in \\m{A} \\Rightarrow A^{c}\\in \\m{A}$,\n\\item $A_{1}, A_{2}, \\dots \\in \\m{A} \\Rightarrow \\bigcup_{i\\in \\N} A_{i} \\in \\m{A}$.\n\\end{itemize}\n\\end{definition}\n\nIf $\\m{A}$ is a $\\sigma$-algebra on $X$, we call $(X, \\m{A})$ a measurable space.\n\n\\begin{definition}\nLet $(X,\\m{A})$ be a measurable space. A (positive) measure is a set function $\\mu:\\m{A} \\to [0,\\infty]$ satisfying:\n\\begin{itemize}\n\\item $\\mu(\\emptyset) = 0$,\n\\item For all collections $\\{A_{i}\\}_{i\\in N}$ of pairwise disjoint sets,\n\\begin{align*}\n\t\\mu\\left(\\bigcup_{i\\in \\N} A_{i}\\right) = \\sum_{i\\in \\N} \\mu(A_{i})\n\\end{align*}\n\\end{itemize}\nThe last property is called \\textbf{countable additivity} or $\\textbf{$\\mathbf{\\sigma}$-additivity}$.\n\\end{definition}\n\nIf $\\mu:(X,\\m{A})\\to [0, \\infty]$ is a measure, we call $(X, \\m{A}, \\mu)$ a measure space. However this notation is at times cumbersome, so often we will just denote the measure(-able) space: $\\m{A}$ when the set and measure in question is obvious or subordinate.\n\nWe can generalize the notion of a positive measure by the following\n\n\\begin{definition}\nA real (or signed) measure on a $\\sigma$-algebra $\\m{A}$, is a set function $\\mu: \\m{A} \\to [-\\infty, \\infty]$ which is countably additive, and where $\\mu(\\emptyset)=0$. Since a real measure is countably additive, it can take on the value $+\\infty$ or $-\\infty$ but not both.\n\\end{definition}\n\n\n\\begin{definition}\nLet $(X, \\m{A})$ be a measurable space, and $Y$ a topological space. A mapping $f: X \\to Y$ is said to be measurable if $f^{-1}(U)\\in \\m{A}$ for all open sets $U$ in $Y$.\n\\end{definition}\n\n\\begin{definition}\nA subset $A$ of a set $X$ is called convex if for any $x,y \\in A$, and all $\\alpha \\in (0,1)$ we have\n\\begin{align*}\n\t\\alpha x + (1-\\alpha)y \\in A\n\\end{align*}\n\\end{definition}\n\n\\begin{theorem}\\label{thm: average lies in S}\nSuppose $\\mu$ is a finite positive measure on a measurable space $(X, \\m{A})$, $f\\in L^{1}(\\mu)$, $S$ is a closed set in $\\C$, and the averages\n\\begin{align*}\n\tA_{B}(f)=\\frac{1}{\\mu(B)}\\int_{B}fd\\mu\n\\end{align*}\nlie in $S$ for every $B\\in \\m{A}$ with $\\mu(B)>0$. Then $f(x)\\in S$ for $\\mu$ almost all $x \\in X$.\n\\end{theorem}\n\\begin{proof}\nFor $r>0$, let $\\Delta=\\overline{B(\\alpha, r)}\\subseteq S^{c}$. Since $S^{c}$ is the union of countably many such discs, it is enough to prove that $\\mu(B)=0$, where $B=f^{-1}(\\Delta)$.\n\nIf $\\mu(B)>0$, we would have\n\\begin{align*}\n\t|A_{B}(f)-\\alpha| = \\frac{1}{\\mu(B)} \\left| \\int_{B}(f-\\alpha)d\\mu \\right| \\le \\frac{1}{\\mu(B)} \\int_{B}|f-\\alpha|d\\mu \\le r,\n\\end{align*}\nwhich is impossible, since $A_{B}(f)\\in S$ by assumption. Hence $\\mu(B)=0$.\n\\end{proof}\n\n\\begin{definition}\\label{def: regular}\nA Borel measure $\\mu$ on a topological space $(X, \\tau)$, is a measure defined on all open sets, $U\\in \\tau$, hence defined on all the Borel sets. A non-negative Borel measure on a locally compact Hausdorff space $X$ is called regular if\n\\begin{enumerate}\n\\item $\\mu(K)<\\infty$ for every compact $K$,\n\\item (Outer regularity) For every Borel set $A$\n\\begin{align*}\n\t\\mu(A)=\\inf\\{ \\mu(U) | A\\subseteq U, U \\text{ open} \\}\n\\end{align*}\n\\item (Inner regularity) For every open set $A$, or measurable set $A\\in \\m{A}$ with $\\mu(A)<\\infty$\n\\begin{align*}\n\t\\mu(A)=\\sup\\{ \\mu(K) | K\\subseteq A, K \\text{ compact} \\}.\n\\end{align*}\n\\end{enumerate}\n\\end{definition}\n\nWe state without proof the following theorem, which we prove in a more general case in \\cref{thm: Riesz-markov}.\n\n\\begin{theorem}[Riesz-Markov-Kakutani representation theorem]\\label{thm: Riesz-Markov-Kakutani representation theorem}\nLet $X$ be a locally compact Hausdorff space, and let $T$ be a positive linear functional on $C_{c}(X)$. Then there exists a $\\sigma$-algebra $\\m{A}$ in $X$ which contains all Borel sets in $X$, and there exists a unique regular positive measure $\\mu$ on $\\m{A}$ satisfying\n\\begin{align*}\n\tTf=\\int_{X}fd\\mu\n\\end{align*}\nfor every $f\\in C_{c}(X)$.\n\\end{theorem}\n\nTo clarify, a positive linear functional, $T$, is a linear functional satisfying that if $f(X)\\subseteq [0,\\infty)$, then $T(f)\\in [0,\\infty)$.\n\n\\end{document}\n\n", "meta": {"hexsha": "888a70e3a1fb6d0edc7965ecf4cee504f25bcd91", "size": 4807, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tex/VectorMeasures/Sections/DefsAndPrereq.tex", "max_stars_repo_name": "TheTextbook/MeasureTheory", "max_stars_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Tex/VectorMeasures/Sections/DefsAndPrereq.tex", "max_issues_repo_name": "TheTextbook/MeasureTheory", "max_issues_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Tex/VectorMeasures/Sections/DefsAndPrereq.tex", "max_forks_repo_name": "TheTextbook/MeasureTheory", "max_forks_repo_head_hexsha": "46aa1391b7c51a21ed6d3c80d030b0d9e188f483", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.5092592593, "max_line_length": 275, "alphanum_fraction": 0.6565425421, "num_tokens": 1677, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8774767954920548, "lm_q1q2_score": 0.7592140614612287}}
{"text": "\\lesson{2}{Oct 12 2021 Tue (09:23:42)}{Factoring by Grouping}{Unit 2}\n\n\\subsubsection*{Factoring by Grouping (Four-Term Polynomials) }\n\nLet's just jump into an example:\n\n\\begin{example}[Factor $30c^3 - 20c^2 - 15c + 10$]\n    \\begin{align}\n        30c^2 - 20c^2 -15c + 10 &= 5(6c^3 - 4c^2 - 3c + 2) \\\\\n                                &= 5[2c^2 (3c - 2) - 1 (3c - 2)] \\\\\n                                &= 5[2c^2 (3c - 2) - 1 = (3c - 2)] \\\\\n                                &= 5(3c - 2)(2c^2 - 1)\n    \\end{align}\n\\end{example}\n\n\\newpage\n", "meta": {"hexsha": "fda951e84f50813a7818b93fb79cc18d050c3380", "size": 534, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Grade-10/semester-1/hs-algebra-2/unit-2/lesson-2.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-2.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-2.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": 31.4117647059, "max_line_length": 69, "alphanum_fraction": 0.456928839, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896824119662, "lm_q2_score": 0.8244619220634456, "lm_q1q2_score": 0.7591560313775594}}
{"text": "% jam 2004-08-28\n\n\\section{Simplex Volume}\n\\label{sec:simplex_volume}\n\n\\nocite{graphics-gems-4-1994}\n\\nocite{goodman-orourke-hdcg-2004}\n\nThis section describes how to compute\nthe volume of a $m$-simplex in $\\Reals^n$ (with $m \\le n$)\nand its derivatives with respect to the vertex positions.\nIn what follows, let $S$ be the geometric $m$-simplex\nspanned by the $m+1$ points $\\{\\p_0  \\ldots  \\p_m\\}$,\nwhere $\\p_i \\in \\Reals^n$.\nAs in \\autoref{sec:barycentric-coordinates},\nlet $\\v_i = (\\p_i - \\p_m); i = 0 \\ldots (m-1)$\nand ${\\mathbf V} = \\sum_{i=0}^{m-1} \\v_i \\otimes \\e_i$\n(which can be represented by a matrix whose columns are the $\\v_i$).\n\nTo simplify the discussion, I will describe computing the\nvalue of the volume form: $\\rho(S) = m! \\volume(S)$,\nwhich is the volume of the parallelpiped with sides $\\v_i$.\n\nMost discussions of simplex volume consider\nonly the case of a $n$-simplex in $\\Reals^n$.\nIn that case, the $\\rho(S) = \\det({\\mathbf V)}$\n\\cite{henk-richter-gebet-ziegler-hdcg-16-2004}.\n\nWhen $m < n$, ${\\mathbf V}$ is no longer square,\nso $\\det({\\mathbf V})$ doesn't work.\nHanson \\cite{hanson-1994} suggests:\n\\begin{equation}\n\\rho(S)^2 = \\det({\\mathbf V}^{\\dagger} {\\mathbf V})\n\\end{equation}\n\n", "meta": {"hexsha": "789118da15767de95f1c2f60206f916a9f86a010", "size": 1210, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fosm/volume.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/volume.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/volume.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": 33.6111111111, "max_line_length": 68, "alphanum_fraction": 0.6884297521, "num_tokens": 431, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896693699845, "lm_q2_score": 0.824461932846258, "lm_q1q2_score": 0.7591560305536443}}
{"text": "\\subsubsection{Toy Example}\r\n\\noindent\r\nSay we wish to maximize $f(x,y) = x+y$ subject to the constraint $g(x,y) = x^2 + y^2 = 1$.\r\nWe can do this y finding the C-level curve that is tangent to our constraint, as this curve will have the extrema.\\\\\r\nAt this point, $\\nabla f$ will be in the same direction as $\\nabla g$.\r\nThat is,\r\n\\begin{equation*}\r\n\t\\begin{cases} \r\n\t\tf_x = \\lambda g_x \\\\ \r\n\t\tf_y = \\lambda g_y\r\n\t\\end{cases}.\r\n\\end{equation*}\r\nWe also add the constraint itself, $g(x,y)$ equals some constant $k$, giving us a system of equations\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tf_x = \\lambda g_x \\\\ \r\n\t\tf_y = \\lambda g_y \\\\ \r\n\t\tg(x,y)=k \r\n\t\\end{cases}.\r\n\\end{equation*}\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./differentialMultivariableCalculus/lagrange_slice.png}\r\n\t\\includegraphics[width=0.33\\textwidth]{./differentialMultivariableCalculus/lagrange_curves.png}\r\n\t\\caption{Extremas when the constraints (black) are tangent to the level curves.}\r\n\\end{figure}", "meta": {"hexsha": "5ad8069266d9f0452a517de3f4c6dfb61795ee5a", "size": 1003, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/toyExample.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/toyExample.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/toyExample.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": 37.1481481481, "max_line_length": 117, "alphanum_fraction": 0.6989032901, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896715436483, "lm_q2_score": 0.824461919906883, "lm_q1q2_score": 0.7591560204313045}}
{"text": "\n%\n% Chapter Two\n%\n\n\n\\chapter{STELLAR REACTION RATES}\n\n\\section{Introduction}\nConsider a nuclear reaction A(a,b)B, with number densities $n_A$ and $n_a$ in units of particles per volume, respectively. The flux $j$ of particles $a$ with a relative velocity $v$ will be\n \\begin{equation}\n    \\label{j_a}\n    \\begin{aligned}\n        j = n_a v\n    \\end{aligned}\n\\end{equation}\nin units of particles per unit area per unit time. So the scatterings per unit time will be the product of $j$ and the cross-section $\\sigma$ i.e. $j \\sigma=\\sigma n_a v$ for one target nucleus. Therefore, the total reaction rate per second per unit volume $r_{Aa}$ can be expressed as\n \\begin{equation}\n    \\label{r12}\n    \\begin{aligned}\n    r_{Aa}=n_a n_A \\sigma v\n    \\end{aligned}\n\\end{equation}\n\nIn the stellar plasma, the relative velocity between interacting particles $v$ is represented by a velocity distribution $\\varphi(v)$  normalized by $\\int_{0}^{\\infty}\\varphi(v)dv=1$. Then the average scattering rate will be\n \\begin{equation}\n    \\label{sigmav_0}\n    \\begin{aligned}\n    \\langle \\sigma v\\rangle = \\int_{0}^{\\infty}\\sigma(E) \\varphi(v) v dv\n    \\end{aligned}\n\\end{equation}\nwhich is also known as the reaction rate per particle pair.\n%%%%%%%%%%%%%%%\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\nIn a normal stellar environment, the plasma is in thermodynamic equilibrium and particles are interacting under non-relativistic mechanics. The velocity distribution of nuclei, therefore, can be described by the Maxwell-Boltzmann velocity distribution given by\n\\begin{equation}\n    \\label{MB}\n    \\begin{aligned}\n        \\varphi(v)= 4 \\pi v^2 (\\frac{m}{2\\pi kT})^{3/2} \\exp(-\\frac{mv^2}{2kT})\n    \\end{aligned}\n\\end{equation}\nwhere $T$ refers to the plasma temperature, $m$ to the mass of the nucleus and $k$ to the Boltzmann constant.\n\nThe reaction rate per pair of particles, $\\langle \\sigma v \\rangle$, as defined, is the double integral over two velocity distributions:\n\\begin{equation}\n    \\label{reactionrate1}\n    \\begin{aligned}\n         \\langle \\sigma v \\rangle=\\iint \\sigma(v)v\\varphi(v_a)\\varphi(v_A)dv_adv_A\n    \\end{aligned}\n\\end{equation}\nwhere $v_a$ and $v_A$ are the velocity of the projectile and the target, respectively. These individual velocities can be represented in terms of $v$ and $V$(the center of mass velocity of particles a and A) using the kinematic relations:\n\\begin{equation}\n    \\label{kinematics}\n    \\begin{aligned}\n        v_a = V + \\dfrac{m_A}{m_a + m_A}  v  \\\\\n        v_A = V - \\dfrac{m_a}{m_a + m_A}  v\n    \\end{aligned}\n\\end{equation}\nThe reaction rate then becomes\n\\begin{equation}\n    \\label{reactionrate_cm}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle=\\iint \\sigma(v)v\\varphi(V)\\varphi(v)dVdv\n    \\end{aligned}\n\\end{equation}\nwhere the transformed velocity distributions $\\varphi(V)$ and $\\varphi(v)$ are\n\\begin{equation}\n    \\label{V}\n    \\begin{aligned}\n        \\varphi(V)=4\\pi V^2 (\\frac{M}{2\\pi kT})^{3/2} \\exp(-\\frac{MV^2}{2kT})\n    \\end{aligned}\n\\end{equation}\n\\begin{equation}\n    \\label{v}\n    \\begin{aligned}\n        \\varphi(v)=4\\pi v^2 (\\frac{\\mu}{2\\pi kT})^{3/2} \\exp(-\\frac{\\mu v^2}{2kT})\n    \\end{aligned}\n\\end{equation}\nwhere $M=m_a+m_A$, $\\mu=m_a m_A/(m_a + m_A)$ and $m_i$  refer to the total mass, the reduced mass of the reacting particles and the masses of the particle $i$, respectively. Notice that Eq.~\\ref{reactionrate_cm} is the integral of two independent Maxwell-Boltzmann distributions and the cross-section $\\sigma$ should only depend on the relative velocity $v$. Along with the normalized velocity $\\int_{0}^{\\infty} \\varphi(V)dV=1$, Eq.~\\ref{reactionrate_cm} can be reduced to:\n \\begin{equation}\n    \\label{reactionrate3}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle =\\int_{0}^{\\infty} \\sigma(v)v\\varphi(v)dv\n    \\end{aligned}\n\\end{equation}\nInserting Eq.~\\ref{v} one gets\n\\begin{equation}\n    \\label{reactionrate4}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle = 4\\pi (\\frac{\\mu}{2\\pi kT})^{3/2} \\int_{0}^{\\infty}v^3 \\sigma(v) \\exp(\\frac{\\mu v^2}{2kT})dv\n    \\end{aligned}\n\\end{equation}\nConverting the relative velocity $v$ to the center of mass energy $E$ by $E=\\dfrac{1}{2}\\mu v^2$ and substituting it into Eq.~\\ref{reactionrate4} one can obtain the energy-dependent reaction rate:\n\\begin{equation}\n    \\label{crosssection_1}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle = (\\frac{8}{\\pi \\mu})^{1/2}(\\frac{1}{kT})^{3/2} \\int_{0}^{\\infty} \\sigma(E) E \\exp(-E/kT)dE\n    \\end{aligned}\n\\end{equation}\nThe integrand $E\\sigma(E)\\exp(-E/kT)$ is called the Gamow distribution function, which shows how the energy dependence of the cross-section is weighted by the thermal distribution of energies in the reaction rate.\n\n\nThe mathematical methods for determining reaction rates by Eq.~\\ref{crosssection_1} depends on the energy-dependent cross-section $\\sigma(E)$, which can be nonresonant or resonant. Cross-sections of the nonresonance part vary slowly with relative energies $E$, while the resonant parts of the cross-sections are sharply peaked. Both contributions will be discussed in the following sections.\n\n\n\\subsection{Charged-Particle Nonresonance Reaction}\n\n%decreb\nFor charged-particle reactions, the Coulomb potential and the nuclear potential are equally important so that both need to be taken into consideration.\nAt astrophysically interesting low energy region, there are two approximations of  $\\sigma(E)$ that are non-nuclear energy-dependent.  The first approximation is\n\\begin{equation}\n    \\begin{aligned}\n        \\sigma(E) \\propto \\pi \\lambda^2  \\propto \\frac{1}{E}\n    \\end{aligned}\n\\end{equation}\nwhere the de Broglie wavelength $\\lambda$ indicates the fact that  the  cross-section depends on the physical size of the particle.\n\nThe second approximation is about the Coulomb penetrability. The cross-section for charged-particle-induced nuclear reactions drops rapidly below the Coulomb barrier as the tunneling probability drops exponentially with decreasing energy:\n\\begin{equation}\n    \\begin{aligned}\n        \\sigma(E) \\propto \\exp(-2\\pi z_a Z_A e^2\\hbar v) = \\exp (-2\\pi \\eta)\n    \\end{aligned}\n\\end{equation}\nwhere $z_a$ and $Z_A$ are the nuclear charges of projectile and target respectively, $\\eta = \\dfrac{Z_a Z_A e^2}{\\hbar v}$ is called the Sommerfeld parameter and the term $\\exp(-2\\pi\\eta)$ is referred as the Gamow factor.\n\nCombining both relations, the cross-section can be written as\n\\begin{equation}\n    \\label{eq:Sfactor}\n    \\begin{aligned}\n        \\sigma(E) = \\dfrac{1}{E}\\exp(-2\\pi\\eta)S(E)\n    \\end{aligned}\n\\end{equation}\nwhere the function $S(E)$, referred to as the nuclear S-factor, contains all   nuclear effects of the cross-section.\nInserting Eq.~\\ref{eq:Sfactor} into Eq.~\\ref{crosssection_1}, the cross-section can be expressed as\n\\begin{equation}\n    \\label{crosssection_S}\n    \\begin{aligned}\n     \\langle\\sigma v \\rangle =(\\frac{1}{\\pi \\mu})^{1/2} (\\frac{1}{kT})^{3/2} \\int_0^\\infty S(E) \\exp(-bE^{-1/2}-\\frac{E}{kT})dE\n    \\end{aligned}\n\\end{equation}\nwhere $b=(2\\mu)^{1/2}\\pi e^2 Z_1 Z_2/\\hbar$ and $b^2$ is known as the Gamow energy $E_0$. Since the S-factor varies smoothly with the energy for nonresonance reactions, the integrand of Eq.\\ref{crosssection_S} is dominated by the Coulomb penetrability $\\exp(-bE^{-1/2})$\nand the Boltzmann factor $\\exp(-E/kT)$. The former increases with energy as $\\exp(E^{-1/2})$ while the latter decreases as $\\exp(-E)$. The product of the two terms produces the Gamow peak near the Gamow energy $E_0$, which determines the energy window at which reactions will take place for a given stellar temperature $T$ (See Fig. ~\\ref{fig:gamow_window} ).\n\\begin{figure}[tpb]\n  \\begin{center}\n    \\centerline{\\includegraphics[scale=0.6]{graph/ch2/Gamow_window}}\n    \\caption{The schematic diagram of the Gamow peak. The hatched area is the product of Maxwell-Boltzmann distribution term and the  Coulomb penetrability term. $E_0$ shows the position of the maximum and $\\Delta E_0$ indicates the Gamow window.}\n    \\label{fig:gamow_window}\n  \\end{center}\n\\end{figure}\n\nThe S-factor in the Gamow window can be considered as constant:\n\\begin{equation}\n    \\begin{aligned}\n       S(E)=S(E_0)\n    \\end{aligned}\n\\end{equation}\nTherefore, Eq.\\ref{crosssection_S} reduces to\n\\begin{equation}\n    \\label{crosssection_S0}\n    \\begin{aligned}\n     \\langle\\sigma v \\rangle =(\\frac{1}{\\pi \\mu})^{1/2} (\\frac{1}{kT})^{3/2} S(E_0)\\int_0^\\infty  \\exp(-\\frac{E}{kT}-bE^{-1/2})dE\n    \\end{aligned}\n\\end{equation}\n\nBy calculating the maximum value of the integrand of Eq.\\ref{crosssection_S0} one can get the effective burning energy\n\\begin{equation}\n    \\label{E_0}\n    \\begin{aligned}\n       E_0=(\\frac{bkT}{2})^{2/3}=1.22(Z_a^2 Z_A^2  \\mu T_6^2)^{1/3}\n    \\end{aligned}\n\\end{equation}\nwhere $\\mu$ is in units of amu,  the stellar temperature $T_6$ is in units of $10^6$K and $E_0$  is in units of keV.\n\nSubstituting Eq.\\ref{E_0} back into Eq.\\ref{crosssection_S0}, one obtains the maximum of the reaction rate:\n\\begin{equation}\n    \\label{I_max}\n    \\begin{aligned}\n        I_{max} = \\exp(-\\frac{3E_0}{kT})\n    \\end{aligned}\n\\end{equation}\nand the exponential term in the integrand of Eq.\\ref{crosssection_S0} can be approximated by a Gaussian function:\n\\begin{equation}\n    \\label{exp_gaus}\n    \\begin{aligned}\n        \\exp{(-\\frac{E}{kT}-bE^{-1/2})} = I_{max}\\exp[-(\\frac{E-E_0}{\\Delta /2})^2]\n    \\end{aligned}\n\\end{equation}\nwhere $\\Delta$ is the effective width of the energy window at  $1/e$ of the height of the Gamow peak and can be expressed by:\n\\begin{equation}\n    \\label{delta}\n    \\begin{aligned}\n        \\Delta = (4/3)^{1/2}(E_0kT)^{1/2}=0.749(z_a^2 Z_A^2 \\mu T_6^5)^{1/6} \\ keV\n    \\end{aligned}\n\\end{equation}\n\n\nThe energy region that contributes the most to the integrand falls into the Gamow window $(E_0\\pm \\Delta/2)$. Applying this approximation to Eq.\\ref{exp_gaus}, the reaction rate becomes\n\\begin{equation}\n    \\label{crosssection_E0}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle  =  (\\frac{2}{\\mu})^{1/2} \\frac{\\Delta}{(kT)^{3/2}}S(E_0)\\exp(-\\frac{3E_0}{kT})\n    \\end{aligned}\n\\end{equation}\n\n\n\n\\subsection{Resonant Reaction Rates}\n\nUnlike the one-step direct capture (nonresonant) reaction described above, the resonance reaction is a two-step process that is characterized by the strongly varying S-factor caused by a resonance. For an isolated resonance the cross-section is described by the Breit-Wigner formula (all quantities are in the center of mass system):\n\\begin{equation}\n    \\label{crosssection_BW}\n    \\begin{aligned}\n        \\sigma_{BW}(E) = \\pi (\\lambda/2\\pi)^2 \\frac{2J+1}{(2J_a+1)(2J_A+1)} \\frac{\\Gamma_a(E) \\Gamma_b(E)}{(E-E_R)^2+(\\Gamma(E)/2)^2}\n    \\end{aligned}\n\\end{equation}\nwhere $\\lambda$ is the de Broglie wavelength of the projectile defined by $\\dfrac{\\lambda^2}{2}=\\dfrac{(\\pi \\hbar)^2}{\\mu E}$, $E_R$ is the resonance energy and   $\\Gamma_a(E)$, $\\Gamma_b(E)$ and $\\Gamma(E)$ are the energy-dependent partial widths of particle $a$, $b$ and the total resonance width, respectively. One can define the statistical factor  $\\omega$ by the spins of the projectile $J_a$, target $J_A$ and resonant state $J$:\n\\begin{equation}\n    \\label{statistial_factor}\n    \\begin{aligned}\n        \\omega = \\frac{2J+1}{(2J_a+1)(2J_A+1)}\n    \\end{aligned}\n\\end{equation}\n\nSubstituting Eq.\\ref{crosssection_BW} and Eq.\\ref{statistial_factor} into Eq.\\ref{crosssection_1} the reaction rate per particle pair becomes:\n\\begin{equation}\n    \\label{crosssection_gamma}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle = \\hbar^2 \\omega \\frac{\\sqrt{2\\pi}}{(\\mu kT)^{3/2}} \\int_0^\\infty \\frac{\\Gamma_a(E) \\Gamma_b(E)}{(E-E_R)^2 + (\\Gamma(E)/2)^2} \\exp(-E/kT)dE\n    \\end{aligned}\n\\end{equation}\n\n\nIf the partial width $\\Gamma_i \\ll E_R$, the resonance is considered to be narrow. In this case, the  Boltzmann factor $\\exp(-E/kT)$ does not change significantly over the resonance region. Therefore, one can make the approximation that the partial widths and the exponential term in the integrand in Eq.\\ref{crosssection_gamma} are independent of the energy $E$. Integrating Eq.\\ref{crosssection_gamma} one gets\n\\begin{equation}\n    \\label{crosssection_width}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle = (\\frac{2 \\pi}{\\mu k T})^{3/2} \\hbar^2 (\\omega \\gamma)_R \\exp(-E_R/kT)\n    \\end{aligned}\n\\end{equation}\nwhere the width ratio is $\\gamma = \\Gamma_a\\Gamma_b/\\Gamma$. The strength of a resonance is defined by the product of these two terms $(\\omega \\gamma)_R$, as it refers to the integrated cross-section.\n\n\nEq.\\ref{crosssection_width} is the stellar reaction rate per particle for a single narrow resonance. In the event of several narrow resonances, their contributions to the reaction rate are simply summed as\n\\begin{equation}\n    \\label{crosssection_sum}\n    \\begin{aligned}\n        \\langle \\sigma v \\rangle = (\\frac{2 \\pi}{\\mu k T})^{3/2} \\hbar^2 \\sum_i(\\omega \\gamma)_i \\exp(-E_i/kT)\n    \\end{aligned}\n\\end{equation}\nor numerically, the reaction rate is given as\n\\begin{equation}\n    \\begin{aligned}\n        N_A\\langle \\sigma v \\rangle = 1.54\\times10^5(\\mu T_9)^{-3/2} \\sum_i(\\omega \\gamma)_i \\exp(-11.605E_i/T_9)\n    \\end{aligned}\n\\end{equation}\nin units of cm$^{-3}$s$^{-1}$mol$^{-1}$. Here $T_9$ is the stellar temperature in units of $10^9$K, the resonance strength of the $i_{th}$ resonance $(\\omega \\gamma)_i$ and the $i_{th}$ resonate energy in the center of mass frame $E_i$ are in units of eV and MeV respectively.\n\n\n\\section{Indirect Measurement: Direct Reaction as a Spectroscopic Tool}\n\nMany reaction rates of direct reactions involving charged particles are relevant for astrophysics at low energies where the Coulomb repulsion makes the cross-section very small and, therefore, extremely difficult to measure by  direct methods. Therefore, indirect methods are used to extract required information such as spectroscopic coefficients.\n\nThe Coulomb barrier can be associated with the penetrability which refers to the ability of particles that are trapped inside the potential barrier to tunnel through the barrier and escape from the nucleus. One can relate the partial widths  $\\Gamma_{\\lambda l}$ directly to the nuclear structure of the states of interest by treating the penetrability separately.\n\nThe wavefunction for a partial wave $l$ can be written as\n\\begin{equation}\n    \\label{wave_function}\n    \\begin{aligned}\n        \\Phi_{lm}(r,\\theta, \\varphi)=\\frac{u_l(r)}{r} Y_{lm}(\\theta, \\varphi)\n    \\end{aligned}\n\\end{equation}\nthen the radial component of the solution of the Schrodinger equation for $u_l(r)$ becomes\n\\begin{equation}\n    \\label{ul}\n    \\begin{aligned}\n        -\\frac{\\hbar^2}{2 \\mu} \\frac{d^2 u_l(r)}{dr^2} + [l(l+1)\\frac{\\hbar^2}{2\\mu r^2}+ V(r) -E]u_l(r) =0\n    \\end{aligned}\n\\end{equation}\nwhere the potential $V(r)$ has the form\n\\begin{equation}\n    \\label{Vr}\n    V(r)=\\left\\{\n    \\begin{aligned}\n    &V_{Coulomb} = z_1 Z_1 e^2/r, \\ &r>R_n  \\\\\n    &V_C + V_{nuc}, \\  &r<R_n\n    \\end{aligned}\n    \\right.\n\\end{equation}\nand $R_n$ refers to the radius of the nuclear part of the interaction potential between $a$ and $A$.\n\nTo relate the nuclear structure to the partial wave, one can assume that the actual wavefunction, in general, involves many configurations:\n\\begin{equation}\n    \\label{configuration}\n    \\begin{aligned}\n    u_l = \\sum_j \\Theta_{ij} u_{lj}\n    \\end{aligned}\n\\end{equation}\nwhere ${u_{ij}}$ could be the states in the particle-core coupling model. The coefficients $\\Theta_{lj}$ ($0<\\Theta_{lj}<1$) indicate the amplitudes of each of the configuration in the wavefunction. $\\Theta^2_{lj}$ results in the probability of the configuration $u_{lj}$, as well as the probability of decay of each compound nuclear state to each state in the residual nucleus. In other words, they represent the spectroscopic strength of their specific wavefunction configuration. For example, in the particle-core coupling model, this  represents the decay to a continuum proton plus the core states indicated in $u_{ij}$. In some cases some of $u_{ij}$ might have the same core states. (For example, a $d_{3/2}$, $d_{5/2}$ and $s_{1/2}$ neutron coupled to a $2^+$ core state could form $J^{\\pi}$ = 3/2${^+}$ or 5/2$^{+}$ states.) Then all such states could decay to that core state. This approach does allow us to develop a relationship between the width of the state $\\Gamma_{lj}$ and the coefficients in the wavefunction, the $\\Theta{ij}$\n\\begin{equation}\n    \\label{spectroscopic_relation}\n    \\begin{aligned}\n    \\Gamma_p = C^2S \\Gamma_{sp}\n    \\end{aligned}\n\\end{equation}\nwhere $\\Gamma_{sp}$ denotes the partial width of a single-particle resonance located at the same energy as the resonance of interest. $C$ is the Clebsch-Gordan coefficient.\n\n\nTypically the spectroscopic factor $S$ are extracted in transfer reactions by a comparison of experimental cross-sections and the result of DWBA calculations by appropriately choosing the optical-model potential. Considering a transfer reaction A$+$c $\\rightarrow$ B$+$b (c$=$a$+$b), the reaction process can be divided into two steps. Firstly, particle c breaks up into a and b near the core A (c$\\rightarrow$ a$+$b). Secondly, a is captured by core A thus generates core B (a$+$A $\\rightarrow$ B), as  shown schematically in Fig.~\\ref{fig:transfer}\n\nThe transfer reaction A$+$c$\\rightarrow$ B$+$b is composed by the capture reaction a$+$A $\\rightarrow$ B$+$b and the inverse process a$+$b $\\rightarrow$ c$+$$\\gamma$. Therefore, the cross-section should be associated with  two spectroscopic factors $S_{ab}$ and $S_{Aa}$ by\n\\begin{equation}\n    \\label{transfer_crosssection}\n    \\begin{aligned}\n    \\sigma  = \\sum_{j_B j_c} S_{A a l_B j_B} S_{a b l_c j_c} \\sigma^{DWBA}_{l_B j_B l_c j_c}\n    \\end{aligned}\n\\end{equation}\n where $\\sigma^{DWBA}_{l_B j_B l_c j_c}$ is the cross-section calculated by DWBA. By experimentally measuring the cross-sections of the transfer reaction $A+c \\rightarrow B+b$ and theoretically  calculating $\\sigma^{DWBA}_{l_B j_B l_c j_c}$,  the  spectroscopic  factor $S_{Aa}$ can be obtained if $S_{ab}$ is known.\n\n\\begin{figure}[tpb]\n  \\begin{center}\n    \\centerline{\\includegraphics[scale=0.6]{graph/ch2/transfer}}\n    \\caption{The process of the transfer reaction  $A+c \\rightarrow B+b$}\n    \\label{fig:transfer}\n  \\end{center}\n\\end{figure}\n\n As  mentioned above, $S_{Aa}$ is sensitive to the optical model potentials. However, in terms of particle widths of unbound states, it is shown that the experimentally measured particle width $\\Gamma_p$ does not critically depend on the selected potential. This is a consequence of the fact that $\\Gamma_{sp}$ also depends on the potential resulting from Eq.~\\ref{spectroscopic_relation}. This cancels most of the potential dependence as long as both values are extracted with the same potential.  Thus the particle width can be determined in the same theoretical framework in which the spectroscopic factor is determined.\n\n\n\n\n% To subtract the spectroscopic factor $S$, $\\Gamma_p$ is obtained by the experimental data and $\\Gamma_{sp}$ can be computed numerically by solving Schrodinger equation for the elastic scattering\n\n\n% The spectroscopic factor is a tool to get the cross section of the direct measurement.\n% \\begin{equation}\n%     \\begin{aligned}\n%         \\sigma = \\lambda \\dot |M|^2\n%     \\end{aligned}\n% \\end{equation}\n% where $\\lambda$ is the kinematic factor, $M$ is the transition amplitude of the reaction,\n% \\begin{equation}\n%     \\begin{aligned}\n%         M=\\langle \\varphi_B(\\zeta_A,\\zeta_a,\\textbf{r})|\\hat{O}(\\textbf{r})|\\varphi_A(\\zeta_A)\\zeta_a (\\xi_a)\\phi^{(+)}_{k_i}(\\textbf{r}) \\rangle\n%     \\end{aligned}\n% \\end{equation}\n% where $\\varphi_i$, $\\zeta_i$ are the wave function of the bound state and the intrinsic coordinates\n%  the nuclei $i$, respectively; $\\textbf{r}$ is the relative distance between $a$ and $A$; $\\hat{O}$ is the electronic transition operator; $\\phi^{(+)}_{k_i}$ is the wave function of the incoming wave. Integral to the intrinsic coordinate to get the stacked wave function.\n%  \\begin{equation}\n%     \\begin{aligned}\n%         I_{Aa}^B(\\textbf{r}) = (A+a)^{1/2}\\langle\\varphi_A(\\zeta_A)\\varphi_a(\\zeta_a)|\\varphi_B(\\zeta_A, \\zeta_a,\\textbf{r})\\rangle\n%     \\end{aligned}\n% \\end{equation}\n\n% The physics meaning of $I_{Aa}^B(\\textbf{r})$ is the wave function of the bound state of $B=A+a$  $\\varphi_B$ , project to\n\n%  \\begin{equation}\n%     \\begin{aligned}\n%         M=\\langle I_{Aa}^b(\\textbf{r})|\\hat{O}| \\phi^{(+)}_{k_i}(\\textbf{r}) \\rangle\n%     \\end{aligned}\n% \\end{equation}\n\n%  $I_{Aa}^b(\\textbf{r})$ is not the bound state B.\n\n%   \\begin{equation}\n%     \\begin{aligned}\n%         S_{Aa}^B = \\int_{0}^{\\infty} (I_{Aa}^B(\\textbf{r}))^2 d{\\textbf{r}}\n%     \\end{aligned}\n% \\end{equation}\n\n% is the spectroscopic factor.\n% \\begin{equation}\n%     \\begin{aligned}\n%         I_{Aa}^B(\\textbf{r}) =& (A+a)^{1/2} \\langle \\varphi_A(\\zeta_A) \\varphi_B(\\zeta_A, \\zeta_a, \\textbf{r})\\rangle \\\\\n%                              =& \\sum_{l_B m_{l_B} j_B m_{j_B}} \\langle J_A M_A j_B m_{jB}|J_B M_B \\rangle \\\\\n%                               &\\times \\langle J_a M_a l_B m_{j_B}|j_B m_{l_B}\\rangle i^{l_B} Y_{l_B m_B}(\\hat{\\textbf{r}}) I^B_{Aal_B J_B}(r)\n%     \\end{aligned}\n% \\end{equation}\n\n% where $J_i$, $M_i$ is the spin and projection of the nuclei $i$, $\\langle J_a M_a l_B m_{l_B} | j_B m_{j_B}\\rangle$ is the C-G coefficient, $Y_{l_B m_B}(\\hat{\\textbf{r}})$ is the Spherical Harmonic Function, $I^B_{Aal_BJ_B}(r)$ is the radius integral of the dieji wave function.\n\n% In the model of the single particle, the dieji wave function $I^B_{Aal_BJ_B}(r)$ can be considered as the production of the spectroscopic factor and the bound state wave function of the particle.\n\n%   \\begin{equation}\n%     \\begin{aligned}\n%         I^B_{Aal_BJ_B(r)} \\approx (S_{l_B j_B})^{1/2} \\varphi_{n_B l_B j_B}(r)\n%     \\end{aligned}\n% \\end{equation}\n% where  $\\varphi_{n_B l_B j_B}(r)$ is the normalized jingxiang  wave function of $B=A+a$, which can be solve from the bound state Schrodinger function. As a  result, calculating the $ I^B_{Aal_BJ_B}(r)$ became calculating the spectroscopic factor $S_{l_B j_B}$.\n\n% The spectroscopic factor can be obtained by calculating the cross section of the transferred reaction. For the transfer reaction $A+c \\rightarrow B+b(c=a+b)$ the reaction can be considered as two steps: The first step is the breakup of $c$ to $a$ and $b$ near core $A$ ($c \\rightarrow a+b$). The second step is $a$ is captured by core $A$ and produce $B$ ($a+A \\rightarrow B$).\n\n\n% The transfer reaction $A+c \\rightarrow B+b$ can be considered as the radiation capture reaction $a+A \\rightarrow B+\\gamma$ and the inverse process $a+b \\rightarrow c + \\gamma$.\n\n\n\n\n\n\n\n\n% % uncomment the following lines,\n% if using chapter-wise bibliography\n%\n% \\bibliographystyle{ndnatbib}\n% \\bibliography{example}\n", "meta": {"hexsha": "2b4f67dce5c3850431a76a8017c2b22a79e16c15", "size": 22812, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.tex", "max_stars_repo_name": "silverashashash/ND_thesis", "max_stars_repo_head_hexsha": "77e1b9ccf672450958be40c8d01d112cc46747f4", "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": "chapter2.tex", "max_issues_repo_name": "silverashashash/ND_thesis", "max_issues_repo_head_hexsha": "77e1b9ccf672450958be40c8d01d112cc46747f4", "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": "chapter2.tex", "max_forks_repo_name": "silverashashash/ND_thesis", "max_forks_repo_head_hexsha": "77e1b9ccf672450958be40c8d01d112cc46747f4", "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": 55.6390243902, "max_line_length": 1044, "alphanum_fraction": 0.7035770647, "num_tokens": 6922, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564152, "lm_q2_score": 0.8354835391516132, "lm_q1q2_score": 0.7591353024682198}}
{"text": "\r\n\\documentclass{article}\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\usepackage{amsfonts}\r\n\\usepackage{amsmath}\r\n\r\n\\setcounter{MaxMatrixCols}{10}\r\n%TCIDATA{OutputFilter=LATEX.DLL}\r\n%TCIDATA{Version=5.50.0.2960}\r\n%TCIDATA{<META NAME=\"SaveForMode\" CONTENT=\"1\">}\r\n%TCIDATA{BibliographyScheme=Manual}\r\n%TCIDATA{Created=Sunday, December 09, 2012 07:04:33}\r\n%TCIDATA{LastRevised=Monday, January 07, 2013 12:45:42}\r\n%TCIDATA{<META NAME=\"GraphicsSave\" CONTENT=\"32\">}\r\n%TCIDATA{<META NAME=\"DocumentShell\" CONTENT=\"Standard LaTeX\\Standard LaTeX Article\">}\r\n%TCIDATA{CSTFile=USTDC-BriefReport.cst}\r\n\r\n\\newtheorem{theorem}{Theorem}\r\n\\newtheorem{acknowledgement}[theorem]{Acknowledgement}\r\n\\newtheorem{algorithm}[theorem]{Algorithm}\r\n\\newtheorem{axiom}[theorem]{Axiom}\r\n\\newtheorem{case}[theorem]{Case}\r\n\\newtheorem{claim}[theorem]{Claim}\r\n\\newtheorem{conclusion}[theorem]{Conclusion}\r\n\\newtheorem{condition}[theorem]{Condition}\r\n\\newtheorem{conjecture}[theorem]{Conjecture}\r\n\\newtheorem{corollary}[theorem]{Corollary}\r\n\\newtheorem{criterion}[theorem]{Criterion}\r\n\\newtheorem{definition}[theorem]{Definition}\r\n\\newtheorem{example}[theorem]{Example}\r\n\\newtheorem{exercise}[theorem]{Exercise}\r\n\\newtheorem{lemma}[theorem]{Lemma}\r\n\\newtheorem{notation}[theorem]{Notation}\r\n\\newtheorem{problem}[theorem]{Problem}\r\n\\newtheorem{proposition}[theorem]{Proposition}\r\n\\newtheorem{remark}[theorem]{Remark}\r\n\\newtheorem{solution}[theorem]{Solution}\r\n\\newtheorem{summary}[theorem]{Summary}\r\n\\newenvironment{proof}[1][Proof]{\\noindent\\textbf{#1.} }{\\ \\rule{0.5em}{0.5em}}\r\n\\input{tcilatex}\r\n\\begin{document}\r\n\r\n\\title{Standard \r\n%TCIMACRO{\\TeXButton{LaTeX}{\\LaTeX{}} }%\r\n%BeginExpansion\r\n\\LaTeX{}\r\n%EndExpansion\r\nArticle}\r\n\\author{A. U. Thor \\\\\r\n%EndAName\r\nThe University of Stewart Island}\r\n\\maketitle\r\n\r\n\\begin{abstract}\r\nWe study the effects of warm water on the local penguin population. The\r\nmajor finding is that it is extremely difficult to induce penguins to drink\r\nwarm water. The success factor is approximately $-e^{-i\\pi }-1$.\r\n\\end{abstract}\r\n\r\n\\section{Nonlinear least square fitting}\r\n\r\nI define a test function and data for which I can obtain the residual, its\r\nsquare, and its partial derivatives in closed form.\r\n\r\n\\subsection{Example data and test function}\r\n\r\nFor the data I consider the exact function \r\n\\begin{equation}\r\ny_{i}=ae^{-bi}  \\label{def:y_i}\r\n\\end{equation}%\r\nwith \r\n\\begin{equation}\r\ni=0,1,\\ldots ,9  \\label{def:i:0-9}\r\n\\end{equation}%\r\nmodeled by the two parameter curve%\r\n\\begin{equation}\r\ny=Ae^{-Bi}  \\label{def:y(i)}\r\n\\end{equation}\r\n\r\n\\subsection{Residual and its derivative}\r\n\r\nThe residual is%\r\n\\begin{eqnarray}\r\nr_{i} &=&y_{i}-y\\left( i\\right) \\\\\r\n&=&ae^{-bi}-Ae^{-Bi}  \\label{eq:r_i^2}\r\n\\end{eqnarray}%\r\nIts residual with respect to $A$ and $B$ is calculated next. For $A$,%\r\n\\begin{eqnarray}\r\n\\frac{\\partial r_{i}}{\\partial A} &=&-\\frac{\\partial y}{\\partial A} \\\\\r\n&=&-e^{-Bi}\r\n\\end{eqnarray}%\r\nand for $B$%\r\n\\begin{eqnarray}\r\n\\frac{\\partial r_{i}}{\\partial B} &=&-\\frac{\\partial y}{\\partial B} \\\\\r\n&=&Aie^{-Bi}\r\n\\end{eqnarray}\r\n\r\nThe residual squared is%\r\n\\begin{eqnarray}\r\nr_{i}^{2} &=&\\left( ae^{-bi}-Ae^{-Bi}\\right) ^{2} \\\\\r\n&=&a^{2}e^{-2bi}-2aAe^{-\\left( b+B\\right) i}+A^{2}e^{-2Bi}\r\n\\end{eqnarray}%\r\nwhich is written as%\r\n\\begin{equation}\r\nr_{i}^{2}=a^{2}\\left( e^{-2b}\\right) ^{i}-2aA\\left( e^{-\\left( b+B\\right)\r\n}\\right) ^{i}+A^{2}\\left( e^{-2B}\\right) ^{i}\r\n\\end{equation}\r\n\r\nIntroducint%\r\n\\begin{eqnarray}\r\n\\alpha &=&e^{-2b}  \\label{def:alpha} \\\\\r\n\\beta &=&e^{-\\left( b+B\\right) }  \\label{def:beta} \\\\\r\n\\gamma &=&e^{-2B}  \\label{def:gamma}\r\n\\end{eqnarray}%\r\nthe residual squared is%\r\n\\begin{equation}\r\nr_{i}^{2}=a^{2}\\alpha ^{i}-2aA\\beta ^{i}+A^{2}\\gamma ^{i}\r\n\\label{eq:r_i^2(alpha,beta,gamma)}\r\n\\end{equation}%\r\nand their sum is%\r\n\\begin{eqnarray}\r\nS &=&\\sum r_{i}^{2} \\\\\r\n&=&a^{2}\\sum \\alpha ^{i}-2aA\\sum \\beta ^{i}+A^{2}\\sum \\gamma ^{i}\r\n\\label{eq:S}\r\n\\end{eqnarray}\r\n\r\n\\subsection{Summation function}\r\n\r\nI will be using the summation identity%\r\n\\begin{eqnarray}\r\n\\sum_{i=0}^{n}c^{i} &=&\\frac{1-c^{n+1}}{1-c} \\\\\r\n&=&\\sigma _{n}\\left( c\\right)  \\label{def:sigma-fun}\r\n\\end{eqnarray}%\r\nand its derivativeThe derivative of $\\sigma $ is%\r\n\\begin{eqnarray}\r\n\\frac{d\\sigma }{dc} &=&\\frac{d}{dc}\\left( \\frac{1-c^{n+1}}{1-c}\\right) \\\\\r\n&=&\\frac{\\left( 1-c\\right) \\left( -\\left( n+1\\right) c^{n}\\right) -\\left(\r\n1-c^{n+1}\\right) \\left( -1\\right) }{1-c^{2}} \\\\\r\n&=&\\frac{cc^{n}n-c^{n}-c^{n}n+1}{1-c^{2}} \\\\\r\n&=&\\frac{nc^{n+1}-\\left( n+1\\right) c^{n}+1}{1-c^{2}} \\\\\r\n&=&\\frac{c^{n}\\left( n\\left( c-1\\right) -1\\right) +1}{1-c^{2}}\r\n\\label{eq:sigma'}\r\n\\end{eqnarray}\r\n\r\nUsing $\\sigma $, the sum of residual squared is%\r\n\\begin{equation}\r\nS=a^{2}\\sigma _{n}\\left( \\alpha \\right) -2aA\\sigma \\left( \\beta \\right)\r\n+A^{2}\\sigma \\left( \\gamma \\right)  \\label{eq:S(sigma,alpha,beta,gamma)}\r\n\\end{equation}\r\n\r\n\\subsection{Partial derivatives of $S$}\r\n\r\nI\\ now derive the partial derivatives of $S$. I make sure that at match%\r\n\\begin{eqnarray}\r\nA &=&a  \\label{def:match} \\\\\r\nB &=&b\r\n\\end{eqnarray}%\r\nthe partial derivative is zero.\r\n\r\nThe derivative of $S$ with respect to $A$ is%\r\n\\begin{equation}\r\n\\frac{\\partial S}{\\partial A}=-2a\\sigma \\left( \\beta \\right) +2A\\sigma\r\n\\left( \\gamma \\right)\r\n\\end{equation}%\r\nAt match, this becomes%\r\n\\begin{eqnarray}\r\n\\frac{\\partial S}{\\partial A} &=&a\\sigma \\left( \\beta \\right) +2a\\sigma\r\n\\left( \\beta \\right) \\\\\r\n&=&0\r\n\\end{eqnarray}\r\n\r\nThe derivative of $S$ with respect to $B$ is%\r\n\\begin{equation}\r\n\\frac{\\partial S}{\\partial B}=-2aA\\frac{d\\sigma \\left( \\beta \\right) }{%\r\nd\\beta }\\frac{\\partial \\beta }{\\partial B}+A^{2}\\frac{d\\sigma \\left( \\gamma\r\n\\right) }{d\\gamma }\\frac{\\partial \\gamma }{\\partial B}\r\n\\end{equation}\r\n\r\nThe derivatives of $\\beta $ and $\\gamma $ are%\r\n\\begin{eqnarray}\r\n\\frac{\\partial \\beta }{\\partial B} &=&-\\beta \\\\\r\n&=&-\\gamma \\\\\r\n\\frac{\\partial \\gamma }{\\partial B} &=&-2\\gamma\r\n\\end{eqnarray}%\r\nThe partial derivative is%\r\n\\begin{equation}\r\n\\frac{\\partial S}{\\partial B}=2aA\\gamma \\frac{d\\sigma \\left( \\beta \\right) }{%\r\nd\\beta }-2A^{2}\\gamma \\frac{d\\sigma \\left( \\gamma \\right) }{d\\gamma }\r\n\\end{equation}\r\n\r\nAt match this becomes%\r\n\\begin{eqnarray}\r\n\\frac{\\partial S}{\\partial A} &=&2a^{2}\\gamma \\frac{d\\sigma \\left( \\beta\r\n\\right) }{d\\beta }-2a^{2}\\gamma \\frac{d\\sigma \\left( \\beta \\right) }{d\\beta }\r\n\\\\\r\n&=&0\r\n\\end{eqnarray}\r\n\r\n\\section{Another function}\r\n\r\n\\begin{equation}\r\ny=A10^{B\\left( x-1650\\right) }\r\n\\end{equation}%\r\nthe Jacobian is%\r\n\\begin{eqnarray}\r\n\\frac{d}{dA}\\left( A10^{B\\left( x-1650\\right) }\\right)  &=&10^{B\\left(\r\nx-1650\\right) } \\\\\r\n\\frac{d}{dB}\\left( A10^{B\\left( x-1650\\right) }\\right)  &=&10^{B\\left(\r\nx-1650\\right) }A\\left( \\ln 10\\right) \\left( x-1650\\right)  \\\\\r\n&=&\\left( \\ln 10\\right) A\\left( x-1650\\right) 10^{B\\left( x-1650\\right) }\r\n\\end{eqnarray}%\r\nDerivative \r\n\\begin{equation}\r\n\\log _{10}y=\\log _{10}A+Bx\r\n\\end{equation}\r\n\r\n\\end{document}\r\n", "meta": {"hexsha": "1f1be7dc8926c52d0b35d50929fd8705f43b9cd6", "size": 7071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/developer/nonlinear-squares-test-problem.tex", "max_stars_repo_name": "mirkov/data-table", "max_stars_repo_head_hexsha": "9da9162f73a8d99e698c954358f79af43261ae52", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2020-07-09T02:15:12.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-09T02:15:12.000Z", "max_issues_repo_path": "doc/developer/nonlinear-squares-test-problem.tex", "max_issues_repo_name": "mirkov/data-table", "max_issues_repo_head_hexsha": "9da9162f73a8d99e698c954358f79af43261ae52", "max_issues_repo_licenses": ["MIT"], "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/developer/nonlinear-squares-test-problem.tex", "max_forks_repo_name": "mirkov/data-table", "max_forks_repo_head_hexsha": "9da9162f73a8d99e698c954358f79af43261ae52", "max_forks_repo_licenses": ["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.4357798165, "max_line_length": 253, "alphanum_fraction": 0.6330080611, "num_tokens": 2526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7591352927503343}}
{"text": "\\chapter[Differential Equations]{Differential Equations}\n\n% Introduction\n\\chapterinitial{S}{ystems} often change in a way that depends on their current\nstate. For example, the speed at which a cup of coffee cools down depends on its\ncurrent temperature. These types of systems are called dynamical systems and are\nmodelled mathematically using differential equations. This chapter will\nconsider a direct solution approach using symbolic mathematics.\n\n\\section{Problem}\\label{sec:differential_equations_problem}\n\nConsider the following situation: the entire population of a small rural town\nhas caught a cold. All 100 individuals will recover at an average rate of 2 per\nday. The town leadership have noticed that being ill costs approximately\n\\(\\pounds10\\) per day, this is due to general lack of productivity, poorer mood and\nother intangible aspects. They need to decide whether or not to order cold\nmedicine which would \\textbf{double} the recovery rate. The cost of of the cold\nmedicine is a one off cost of \\(\\pounds5\\) per person.\n\n\\section{Theory}\\label{sec:differential_equations_theory}\n\nIn the case of this town, the overall rate at which people get better is\ndependent on the number of people who are ill. This can be represented\nmathematically using a differential equation which is a way of relating the rate\nof change of a system to the state of the system itself.\n\nIn general the objects of interest are the variable \\(x\\) over time \\(t\\), and\nthe rate at which \\(x\\) changes with \\(t\\), its derivative\\index{derivative}\n\\(\\frac{dx}{dt}\\).\nThe differential equation\\index{differential equation} describing this will be\nof the form:\n\n\\begin{equation}\n    \\frac{dx}{dt} = f(x)\n\\end{equation}\n\nfor some function \\(f\\).\nIn this case,\nthe number of infected individuals will be denoted as \\(I\\), which will\nimplicitly mean that \\(I\\) is a function of time: \\(I=I(t)\\), and the rate at\nwhich individuals recover will be denoted by \\(\\alpha\\), then the\ndifferential equation that describes the above situation is:\n\n\\begin{equation}\n    \\frac{dI}{dt} = -\\alpha I\n\\end{equation}\n\nFinding a solution to this differential equation means finding an expression for\n\\(I\\) that when differentiated gives \\(- \\alpha I\\).\n\nIn this particular case, one such function is:\n\n\\begin{equation}\n    I(t) = e ^ {-\\alpha t}\n\\end{equation}\n\nThis is a solution because:\n\\(\\frac{dI}{dt} = -\\alpha e ^ {-\\alpha y} = -\\alpha I\\).\n\nHowever here \\(I(0) = 1\\), whereas for this problem we know that at time \\(t=0\\)\nthere are 100 infected individuals. In general there are many such functions\nthat can satisfy a differential equation, known as a family of solutions. To\nknow which particular solution is relevant to the situation, some sort of\ninitial condition is required. Here this would\nbe:\n\n\\begin{equation}\n    I(t) = 100e ^ {-\\alpha t}\n\\end{equation}\n\nTo evaluate the cost the sum of the values of that function over time is needed.\nIntegration\\index{integration} gives exactly this, so the cost would be:\n\n\\begin{equation}\n    K \\int_{0}^{\\infty}I(t)dt\n\\end{equation}\n\nwhere \\(K\\) is the cost per person per unit time.\nTherefore the overall cost would be the cost of being unproductive, plus the cost\nof the medicine, \\(M\\), and is given by:\n\n\\begin{equation}\nK \\int_{0}^{\\infty}I(t)dt + M I(0)\n\\end{equation}\n\nIn the upcoming sections code will be used to confirm to carry out the above\nefficiently so as to answer the original question.\n\n\\section{Solving with Python}\\label{sec:differential_equations_solving-with-python}\n\nThe first step is to define the symbolic variables that will be used. The\nPython library SymPy\\index{SymPy}~\\cite{meurer2017sympy} is used.\n\n\\begin{pyin}\nimport sympy as sym\n\nt = sym.Symbol(\"t\")\nalpha = sym.Symbol(\"alpha\")\nI_0 = sym.Symbol(\"I_0\")\nI = sym.Function(\"I\")\n\\end{pyin}\n\nNow write a function to obtain the differential equation.\n\n\\begin{pyin}\ndef get_equation(alpha=alpha):\n    \"\"\"Return the differential equation.\n\n    Args:\n        alpha: a float (default: symbolic alpha)\n\n    Returns:\n        A symbolic equation\n    \"\"\"\n    return sym.Eq(sym.Derivative(I(t), t), -alpha * I(t))\n\\end{pyin}\n\nThis gives an equation that defines the population change over time:\n\n\\begin{pyin}\neq = get_equation()\nprint(eq)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\nEq(Derivative(I(t), t), -alpha*I(t))\n\\end{pyout}\n\nNote that if Jupyter\\index{Jupyter}~\\cite{kluyver2016jupyter} notebooks are used\nthen output will actually be a well rendered mathematical equation:\n\n\\[\n\\frac{d}{d t} I{\\left(t \\right)} = - \\alpha I{\\left(t \\right)}\n\\]\n\nA value of \\(\\alpha\\) can be passed if required:\n\n\\begin{pyin}\neq = get_equation(alpha=1)\nprint(eq)\n\\end{pyin}\n\n\\begin{pyout}\nEq(Derivative(I(t), t), -I(t))\n\\end{pyout}\n\nNow a function will be written to obtain the solution to this differential\nequation with initial condition \\(I(0) = I_0\\):\n\n\\begin{pyin}\ndef get_solution(I_0=I_0, alpha=alpha):\n    \"\"\"Return the solution to the differential equation.\n\n    Args:\n        I_0: a float (default: symbolic I_0)\n        alpha: a float (default: symbolic alpha)\n\n    Returns:\n        A symbolic equation\n    \"\"\"\n    eq = get_equation(alpha=alpha)\n    return sym.dsolve(eq, I(t), ics={I(0): I_0})\n\\end{pyin}\n\nThis can verify the solution discussed previously:\n\n\\begin{pyin}\nsol = get_solution()\nprint(sol)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\nEq(I(t), I_0*exp(-alpha*t))\n\\end{pyout}\n\n\\[I(t) = I_0 e ^{-\\alpha t}\\]\n\nSymPy itself can be used to verify the result, by taking the derivative of the\nright hand side of our solution.\n\n\\begin{pyin}\nprint(sym.diff(sol.rhs, t) == -alpha * sol.rhs)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\nTrue\n\\end{pyout}\n\nAll of the above has given the general solution in terms of \\(I(0)=I_0\\) and\n\\(\\alpha\\), however the code is written in such a way as we can pass the actual\nparameters:\n\n\\begin{pyin}\nsol = get_solution(alpha=2, I_0=100)\nprint(sol)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\nEq(I(t), 100*exp(-2*t))\n\\end{pyout}\n\nNow, to calculate the cost write a function to integrate the result:\n\n\\begin{pyin}\ndef get_cost(\n    I_0=I_0,\n    alpha=alpha,\n    per_person_cost=10,\n    cure_cost=0,\n):\n    \"\"\"Return the cost.\n\n    Args:\n        I_0: a float (default: symbolic I_0)\n        alpha: a float (default: symbolic alpha)\n        per_person_cost: a float (default: 10)\n        cure_cost: a float (default: 0)\n\n    Returns:\n        A symbolic expression\n    \"\"\"\n    I_sol = get_solution(I_0=I_0, alpha=alpha)\n    area = sym.integrate(I_sol.rhs, (t, 0, sym.oo))\n    productivity_cost = area * per_person_cost\n    total_cost_of_cure = cure_cost * I_0\n    return productivity_cost + total_cost_of_cure\n\\end{pyin}\n\nThe cost without purchasing the cure is:\n\n\\begin{pyin}\nalpha = 2\ncost_without_cure = get_cost(I_0=100, alpha=alpha)\nprint(cost_without_cure)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n500\n\\end{pyout}\n\n\nThe cost with cure can use the above with a modified \\(\\alpha\\) and a non zero\ncost of the cure itself:\n\n\\begin{pyin}\ncost_with_cure = get_cost(I_0=100, alpha=2 * alpha, cure_cost=5)\nprint(cost_with_cure)\n\\end{pyin}\n\nwhich gives:\n\n\\begin{pyout}\n750\n\\end{pyout}\n\nSo given the current parameters it is not worth purchasing the cure.\n\n\\section{Solving with R}\\label{sec:differential_equations_solving-with-R}\n\nR has some capability for symbolic mathematics, however at the time of writing\nthe options available are somewhat limited and/or not reliable. As such, in R\nthe problem will be solved using a numerical integration approach. For an\noutline of the theory behind this approach see Chapter\n\\ref{chp:system_dynamics}.\n\nFirst a function to give the derivative for a given value of \\(I\\) is needed:\n\n\\begin{Rin}\n#' Returns the numerical value of the derivative.\n#'\n#' @param t a set of time points\n#' @param y a function\n#' @param parameters the set of all parameters passed to y\n\n#' @return a float\nderivative <- function(t, y, parameters) {\n  with(\n    as.list(c(y, parameters)), {\n      dIdt <- -alpha * I  # nolint\n      list(dIdt)  # nolint\n    }\n  )\n}\n\\end{Rin}\n\nFor example, to see the value of the derivative when \\(I=0\\):\n\n\\begin{Rin}\ndv <- derivative(t = 0, y = c(I = 100), parameters = c(alpha = 2))\nprint(dv)\n\\end{Rin}\n\nThis gives:\n\n\\begin{Rout}\n[[1]]\n[1] -200\n\n\\end{Rout}\n\nNow the deSolve\\index{deSolve}~\\cite{soetaert2010solving} library will be used\nfor solving differential equations numerically:\n\n\\begin{Rin}\nlibrary(deSolve)  # nolint\n#' Return the solution to the differential equation.\n#'\n#' @param times: a vector of time points\n#' @param y_0: a float (default: 100)\n#' @param alpha: a float (default: 2)\n\n#' @return A vector of numerical values\nget_solution <- function(times,\n                         y0 = c(I = 100),\n                         alpha = 2) {\n  params <- c(alpha = alpha)\n  ode(y = y0, times = times, func = derivative, parms = params)\n}\n\\end{Rin}\n\nThis will return a sequence of time point and values of \\(I\\) at those time\npoints. Using this we can compute the cost.\n\n\\begin{Rin}\n#' Return the cost.\n#'\n#' @param I_0: a float (default: symbolic I_0)\n#' @param alpha: a float (default: symbolic alpha)\n#' @param per_person_cost: a float (default: 10)\n#' @param cure_cost: a float (default: 0)\n#' @param step_size: a float (default: 0.0001)\n#' @param max_time: an integer (default: 10)\n\n#' @return A numeric value\nget_cost <- function(I_0 = 100,\n                     alpha = 2,\n                     per_person_cost = 10,\n                     cure_cost = 0,\n                     step_size = 0.0001,\n                     max_time = 10) {\n  times <- seq(0, max_time, by = step_size)\n  out <- get_solution(times, y0 = c(I = I_0), alpha = alpha)\n  number_of_observations <- length(out[, \"I\"])\n  time_intervals <- diff(out[, \"time\"])\n  area <- sum(time_intervals * out[-number_of_observations, \"I\"])\n  productivity_cost <- area * per_person_cost\n  total_cost_of_cure <- cure_cost * I_0\n  productivity_cost + total_cost_of_cure\n}\n\\end{Rin}\n\nThe cost without purchasing the cure is:\n\n\\begin{Rin}\nalpha <- 2\ncost_without_cure <- get_cost(alpha = alpha)\nprint(round(cost_without_cure))\n\\end{Rin}\n\n\nwhich gives:\n\n\\begin{Rout}\n[1] 500\n\\end{Rout}\n\nThe cost with cure can use the above with a modified \\(\\alpha\\) and a non zero\ncost of the cure itself:\n\n\\begin{Rin}\ncost_with_cure <- get_cost(alpha = 2 * alpha, cure_cost = 5)\nprint(round(cost_with_cure))\n\\end{Rin}\n\nwhich gives:\n\n\\begin{Rout}\n[1] 750\n\\end{Rout}\n\nSo given the current parameters it is not worth purchasing the cure.\n\n\\section{Wider context}\\label{sec:differential_equations_wider_context}\n\nThere are a number of further areas related to the study of as well as the use\nof differential equations. Topics omitted here include the actual solution\napproaches which in this chapter are taken\ncare of using open-source software. Chapters 9, 14 and 16\nof~\\cite{stewart2009calculus} provide a good introduction to some of\nthese concepts as well as a general discussion of the area of mathematics in\nwhich they sit: \\index{calculus}.\n\nDifferential equations have been applied in many settings.\nIn~\\cite{lanchester1916aircraft} differential equations were used to model\nattrition in warfare\\index{warfare}, the insights from these differential\nequations are referred to as Lanchester's square\nlaw\\index{Lanchester's square law}. This has been historically fitted to a\nnumber of battles with varying levels of success.\n\nIn~\\cite{syms2015dynamic} differential equations are used to build a\ngeneric model of regime change. A detailed analysis of the\nstability\\index{stability} of the system is included. The model offers some\nexplanation of why oppressive regimes can follow an overthrow of a similarly\noppressive regime: the underlying mathematical system is a stable cycle from\nwhich it is difficult to escape.\n\n\\cite{vandergraft1983fluid} uses differential equations as a framework for\nmodelling queueing\\index{queueing} networks. This is interesting in its\ninception as differential equations are models for continuous quantities whereas\nqueues are discrete type events (see Chapter~\\ref{chp:markov_chains}\nand~\\ref{chp:discrete_event_simulation} for more on this). The advantages of\nusing differential equations are mainly in the computational efficiency.\n\nThe model presented in this chapter is deterministic: there is a single solution\nthat remains the same. This is not always a precise model of reality: often\nsystems are stochastic so that the inputs are not constant parameters but follow\nsome random distribution. This is where stochastic differential\nequations\\index{stochastic differential equation} are applied, which is the\nsubject of~\\cite{sarkka2019applied}.\n", "meta": {"hexsha": "20950c13b1666f549f5c669dd4167d30cec56970", "size": 12585, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/chapters/04/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/04/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/04/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": 29.2674418605, "max_line_length": 83, "alphanum_fraction": 0.7267381804, "num_tokens": 3411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.879146761176671, "lm_q2_score": 0.8633916082162403, "lm_q1q2_score": 0.7590479359904249}}
{"text": "\n\\subsection{Linear forms}\n\nA linear form is a linear map from a vector space to a scalar from the vector space's underlying field.\n\n\\(\\hom (V, F)\\)\n\n\\subsubsection{Matrix operators}\n\nLinear forms can be represented as matrix operators.\n\n\\(v^TM=f\\)\n\nWhere \\(M\\) has only one column.\n\n\\subsubsection{Stuff}\n\n\\(f(M)=f(v)\\)\n\nWe introduce \\(e_i\\), the element vector. This is \\(0\\) for all entries except for \\(i\\) where it is \\(1\\). Any vector can be shown as a sum of these vectors multiplied by a scalar.\n\n\\(f(M)=f(\\sum^m_{i=1}a_{i}e_i)\\)\n\n\\(f(M)=\\sum_{i=1}^mf(a_{i}e_i)\\)\n\n\\(f(M)=\\sum_{i=1}^ma_if(e_i)\\)\n\n\\(f(M)=\\sum_{i=1}^ma_if(e_i)\\)\n\n\\subsubsection{Orthonormal basis}\n\n\\(f(M)=\\sum_{i=1}^ma_i\\)\n\n", "meta": {"hexsha": "97e00d3cbf61ad4bda68850376e7794ec96d1176", "size": 698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/forms/01-01-linearForm.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/geometry/forms/01-01-linearForm.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/geometry/forms/01-01-linearForm.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.5294117647, "max_line_length": 181, "alphanum_fraction": 0.6604584527, "num_tokens": 235, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9539660949832346, "lm_q2_score": 0.7956580903722561, "lm_q1q2_score": 0.7590308414142387}}
{"text": "\n\\subsection{Utility functions}\n\nGiven that an agent chooses a selection from a set, how can we model this?\n\nAs the outcome of the function is one of the options available to the agent, we can model it by putting a value number on each choice, and where the choice is the selection with the largest value. We can do this by applying a function to each element in the choice set.\n\nThis holds only if the agent is rational, that is, if they prefer A to B, they do not switch to B if C is offered. This is due to the transitive properties of real numbers. That is, if \\(a\\ge b\\) and \\(b\\ge c\\) then \\(a\\ge c\\).\n\nIf there are multiple elements with the largest value, then the agent would be indifferent between these choices.\n\nA simple example would be choosing the number of apples to consume.\n\nIf the agent always prefers more apples, we can have a function which is always increasing when the number of apples increases.\n\nThis could be modelled by:\n\n\\(f=x\\)\n\n\\(f=(x-1)^2+1\\)\n\n\\(f=2(x-1)^2-10\\)\n\n\\(f=cos(x)\\)\n\n\\(f=c\\)\n\nThese correspond to different preferences. In the first the agent prefers more and more apples. In the second and third the agent prefers one apple. These two formulas are monotonic transformations of each other and so are identical for describing preferences. The fourth describes an infinite number of optimal numbers of apples, but is unlikely to correspond to any real preferences, and the fifth shows that agent doesn’t care about apples.\n\nThe last gives a real number as output, but doesn’t necessarily take in a real number. Utility functions generally take real numbers, and always give out real numbers.\n\n\\subsubsection{Solving}\n\nOption which maximises utility\n\n", "meta": {"hexsha": "9e9c2ad1785cf616391af02c3fc4c4c4701dc159", "size": 1689, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/ai/singleAgent/02-03-rationalUtilityFunctions.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/02-03-rationalUtilityFunctions.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/02-03-rationalUtilityFunctions.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": 46.9166666667, "max_line_length": 443, "alphanum_fraction": 0.7685020722, "num_tokens": 380, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995482, "lm_q2_score": 0.8539127510928476, "lm_q1q2_score": 0.758922461377074}}
{"text": "\\newpage\n\n\\appendix\n\n\n\n\n%\\end{figure}\n\n\n\n\\section{Condensing to One Point in Linear Time}\\label{app:onepoint}\n\n\nIn this section, we present an algorithm to reduce two claims about $\\tV_{i+1}$ to one in linear time. Recall that as described in Section~\\ref{subsec::GKR}, in the $i$-th layer, after the sumcheck, the verifier receives two claims $\\tV(u), \\tV(v)$. (Again we omit the superscript and subscript of $i$ for the ease of interpretation.) She then defines a line $\\gamma(x): \\mathbb{F}\\rightarrow\\mathbb{F}^{s}$ such that $\\gamma(0) = u, \\gamma(1)=v$ and the prover needs to provide $\\tV(\\gamma(x))$, a degree $s$ univariate polynomial, to $\\V$. If the prover computes it naively, which was done in all prior papers, it incurs $O(s2^{s})$ time, as it is equivalent to evaluating $\\tV()$ at $s+1$ points. \n\n\\begin{figure}[H]\n\t\\begin{algorithm}[H]\n\t\t\n\t\t\\caption{Compute $\\tV(\\gamma(x)) = \\sum_{y\\in\\binary^s}I(\\gamma(x), y)\\tV(y)$}\\label{alg::comb}\n\t\t\\begin{algorithmic}[1]\n\t\t\t\\State Initialize a binary tree $T$ with $s$ levels. We use $T_j[b]$ to denote the $b$-th node at level $j$.\n\t\t\t\\For{$b\\in\\binary^s$}\n\t\t\t\t\\State $T_s[b] = \\tV(b)$.\n\t\t\t\t\\State Multiply $T_s[b]$ with $b_s(c_s x+ d_s)+(1-b_s)(1-c_s x- d_s)$.\n\t\t\t\\EndFor\n\t\t\t\\For{$j = s-1, \\ldots, 1$} \n\t\t\t\t\\For{$b\\in\\binary^{j}$}\n\t\t\t\t\t\\State $T_j[b] = T_{j+1}[b,0]+T_{j+1}[b,1]$.\n\t\t\t\t\t\\State $T_j[b] = T_j[b] \\cdot (b_j(c_j x+ d_j)+(1-b_j)(1-c_j x- d_j))$. \n\t\t\t\t\\EndFor\n\t\t\t\\EndFor\n\t\t\t\\State Output $T_1[0]$.\n\t\t\\end{algorithmic}\n\t\\end{algorithm}\n\\end{figure}\n\n\nIn our new algorithm, we write $\\tV(\\gamma(x)) = \\sum_{y\\in\\binary^s}I(\\gamma(x), y)\\tV(y)$, where $I(a,b)$ is an identity polynomial $I(a,b)=0$ iff $a=b$. This holds by inspection of both sides on the Boolean hypercube. We then evaluate the right side in linear time with a binary tree structure. The key observation is that the identity polynomial can be written as $I(a,b) = \\prod_{j=1}^s (a_jb_j+(1-a_j)(1-b_j))$, and we can process one variable ($a_j,b_j$) at a time and multiply them together to get the final result. \n\nWe construct a binary tree with $2^s$ leaves and initialize each leaf $b\\in\\binary^s$ with $\\tV(b)$. As $\\gamma(x)$ is a linear polynomial, we write it as $\\gamma(x) = [c_1, \\ldots, c_s]^T x+ [d_1, \\ldots, d_s]^T$. At the leaf level, we only consider the last variable of $I(\\gamma(x), y)$. For each leaf $b\\in\\binary^s$, we multiply the value with $b_s(c_s x+ d_s)+(1-b_s)(1-c_s x- d_s)$, the result of which is a linear polynomial. For a node $b\\in\\binary^j$ in the intermediate level $j$, we add the polynomials from its two children, and multiply it with $b_j(c_j x+ d_j)+(1-b_j)(1-c_j x- d_j)$, the part in $I$ that corresponds to the $j$-th variable. In this way, each node in the $j$-th level stores a degree $j$ polynomial. Eventually, the root is the polynomial on the right side of degree $s$, which equals to $\\tV(\\gamma(x))$. The algorithm is given in Algorithm~\\ref{alg::comb}. \n\nTo see the complexity of Algorithm~\\ref{alg::comb}, both the storage and the polynomial multiplication at level $j$ is $O(s-j+1)$ in each node. So the total time is $O(\\sum_{j=1}^s 2^j (s-j+1)) = O(2^s)$, which is linear to the number of gates in the layer.\n\nAn alternative way to interpret this result is to add an additional layer for each layer of the circuit in GKR relaying the values. That is, $$\\tV_{i}(g) = \\sum_{x\\in\\binary^{s_i}}I(g,x)\\tV_{i+1}(x),$$ where $\\tV_i = \\tV_{i+1}$. Then when using the random linear combination approach, the sumcheck is executed on $$\\alpha\\tV_{i}(u)+\\beta\\tV_i(v) = \\sum_{x\\in\\binary^{s_i}}(\\alpha I(u,x)+\\beta I(v,x))\\tV_{i+1}(x).$$\nAt the end of the sumcheck, the verifier receives a single claim on $\\tV_{i+1} = \\tV_{i}$. The sumcheck can obviously run in linear time, and the relay layers do not change the result of the circuit. This approach is actually the same as the condensing to one point in linear time above conceptually. \n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "842054ad0713f88204703d6286a1e7b593848694", "size": 3928, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/eprint/appendix.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/eprint/appendix.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/eprint/appendix.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": 68.9122807018, "max_line_length": 891, "alphanum_fraction": 0.6787169043, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587846530938, "lm_q2_score": 0.8539127529517043, "lm_q1q2_score": 0.7589224605131343}}
{"text": "\\section{Maps}\n\n\\begin{frame}{Maps}\n\n  \\begin{alertblock}{Definition of map}\n    A map from a set $A$ to a set $B$ is a subset $M$ of $A \\times B$ where each element of $A$ appears as the first element of a tuple in $M$ exactly once.\n  \\end{alertblock}\n\n  \\begin{topdisp}\n    $$A = \\{a,b,c\\} \\qquad B = \\{x,y,z\\}$$\n  \\end{topdisp}\n\n  \\begin{minipage}[t]{0.48\\linewidth}\n  \\begin{exampleblock}{Maps}\n    \\begin{itemize}\n      \\item $\\{(a,x),(b,x),(c,x)\\}$\n      \\item $\\{(a,x),(b,y),(c,z)\\}$\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{minipage}\n\\begin{minipage}[t]{0.48\\linewidth}\n  \\begin{exampleblock}{Not maps}\n    \\begin{itemize}\n      \\item $\\{(a,x),(a,y),(b,x),(c,x)\\}$\n      \\item $\\{(a,x),(b,y)\\}$\n    \\end{itemize}\n  \\end{exampleblock}\n\\end{minipage}\n\\end{frame}\n\n\n\\begin{frame}{One-to-one map}\n  \\begin{topdisp}\n    $$ A = \\{1,2,3\\} \\quad  B = \\{a,b,c,d\\} \\quad  M = \\{ (1,a), (2,b), (3,d) \\} $$\n  \\end{topdisp}\n  \\begin{itemize}\n    \\setlength\\itemsep{3mm}\n    \\item In a map, $M \\subseteq A \\times B$, two or more distinct elements of $A$ can be mapped to the same element of $B$.\n    \\item A map where this does not happen is described as \\textbf{one-to-one}.\n    \\item So, a map in which distinct elements of $A$ go to distinct elements of $B$ is one-to-one.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Onto map}\n  \\begin{topdisp}\n    $$ A = \\{1,2,3\\} \\quad  B = \\{a,b,c,d\\} \\quad  M = \\{ (1,a), (2,a), (3,b) \\} $$\n  \\end{topdisp}\n  \\begin{itemize}\n    \\setlength\\itemsep{3mm}\n    \\item In a map, not all of the elements of $B$ need to be involved in the map.\n    \\item A map in which they are all involved is described as \\textbf{onto}.\n    \\item So, a map in which each element of $B$ is paired with an element of $A$ is onto.\n  \\end{itemize}\n\\end{frame}\n\n\\begin{frame}{Bijections}\n  \\begin{topdisp}\n    $$ A = \\{1,2,3\\} \\quad  B = \\{a,b,c\\} \\quad  M = \\{ (1,a), (2,c), (3,b) \\} $$\n  \\end{topdisp}\n  \\begin{itemize}\n    \\setlength\\itemsep{3mm}\n    \\item Maps can be neither one-to-one nor onto, one or the other, or both.\n    \\item A \\textbf{bijection} is map that is both one-to-one and onto.\n    \\item Both $A$ and $B$ must have the same size in a bijection.\n  \\end{itemize}\n\\end{frame}\n\n\n\\begin{frame}{Partial maps}\n  \\begin{topdisp}\n    $$ A = \\{1,2,3\\} \\quad  B = \\{a,b,c\\} \\quad  P = \\{ (1,a), (3,c) \\} $$\n  \\end{topdisp}\n  \\begin{itemize}\n    \\setlength\\itemsep{3mm}\n    \\item A map $M$ from a set $A$ to a set $B$ must involve every element of $A$.\n    \\item A partial map is like a map, but with that condition relaxed.\n    \\item A partial map from a set $A$ to a set $B$ is a subset of $A \\times B$ where any element of $A$ that appears as the first element in a tuple does so exactly once.\n    \\item The term \\emph{partial map} is a bit of a misnomer, as a partial map is not necessarily a map, but a map is a partial map.\n  \\end{itemize}\n\\end{frame}", "meta": {"hexsha": "64a80bd973e54365f68bd4fc029966906434f140", "size": 2876, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content.tex", "max_stars_repo_name": "ianmcloughlin/slides-maps", "max_stars_repo_head_hexsha": "b8ce4767d3a47a7728c41d5907dcd170fe80f392", "max_stars_repo_licenses": ["MIT"], "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-maps", "max_issues_repo_head_hexsha": "b8ce4767d3a47a7728c41d5907dcd170fe80f392", "max_issues_repo_licenses": ["MIT"], "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-maps", "max_forks_repo_head_hexsha": "b8ce4767d3a47a7728c41d5907dcd170fe80f392", "max_forks_repo_licenses": ["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.95, "max_line_length": 171, "alphanum_fraction": 0.6091794159, "num_tokens": 1051, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039739, "lm_q2_score": 0.8221891327004132, "lm_q1q2_score": 0.7589127699475985}}
{"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 7 for Bayesian Data Analysis}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Importance Resampling}\n{\n    Suppose you want to estimate $\\expec_f h(\\theta)$, with $f$ being some posterior distribution $P(\\theta|y)$. Further suppose that you choose a proposal distribution $g(\\theta)$, and get a sample $(x_1, \\cdots, x_m)$ by importance resampling. Please prove that the average of $(h(x_1), \\cdots, h(x_m))$ can be used as an estimator of $\\expec_f h(\\theta)$.\n\n    \\textbf{Proof:}\\quad Note that the probability density for $x_i$ is $w(x_i) g(x_i)$ for any $i$, which does not depend on the order in the sampling with replacement. It follows that \n    $$\\expec_g {(h(x_i))} = \\int{ h(x_i) w(x_i) g(x_i) \\deriv{x_i} }$$\n    $$ = \\int{ h(x_i) \\frac{P(x_i|y)}{g(x_i)} g(x_i) \\deriv{x_i} } = \\int{ h(x_i) P(x_i|y) \\deriv{x_i} } = \\expec_f h(\\theta)$$ for any $i$. Therefore, the average of $(h(x_1), \\cdots, h(x_m))$ is an unbiased estimator of $\\expec_f h(\\theta)$:\n    $$\\expec_g {\\frac{1}{m} \\sum_{i=1}^{m}{(h(x_i))}} = \\frac{1}{m} \\sum_{i=1}^{m} {\\expec_g {h(x_i)}} = \\frac{1}{m} \\sum_{i=1}^{m} {\\expec_f h(\\theta)} = \\expec_f h(\\theta).$$\n}\n\n\\section*{Question 10.6d}\n{\n    $$p(\\theta|y) = f(\\theta) = N(0, 3) = \\frac{1}{\\sqrt{6\\pi}} \\exp{\\left( -\\frac{\\theta^2}{3} \\right)}.$$\n\n    $$g(\\theta) = t_3 = \\frac{2}{\\pi \\sqrt{3}} \\left( 1+\\frac{\\theta^2}{3} \\right) ^{-2}.$$\n\n    It follows that \n    $$\\expec_g{\\left[ (\\frac{f(\\theta)}{g(\\theta)})^2 \\right]} = \\int {(\\frac{f(\\theta)}{g(\\theta)})^2 g(\\theta) \\deriv{\\theta}}$$\n    $$= \\int {\\frac{1}{6\\pi} \\exp{\\left( -\\frac{2\\theta^2}{3} \\right)} \\cdot \\frac{\\pi \\sqrt{3}}{2} \\left( 1+\\frac{\\theta^2}{3} \\right)^2 \\deriv{\\theta}}$$\n    $$= \\frac{\\sqrt{3}}{12} \\int { \\exp{\\left( -\\frac{2\\theta^2}{3} \\right)} \\cdot \\left( 1+\\frac{\\theta^2}{3} \\right)^2 \\deriv{\\theta}}$$\n    $$= \\frac{\\sqrt{2}}{12} \\int { \\exp{\\left( -t^2 \\right)} \\cdot \\left( 1+\\frac{t^2}{2} \\right)^2 \\deriv{t}}$$\n    $$= \\frac{\\sqrt{2}}{12} \\left[ \\int { \\exp{\\left( -t^2 \\right)} \\deriv{t}} + \\int { t^2 \\cdot \\exp{\\left( -t^2 \\right)} \\deriv{t}} + \\frac{1}{4} \\int { t^4 \\cdot \\exp{\\left( -t^2 \\right)} \\deriv{t}} \\right] $$\n    $$= \\frac{\\sqrt{2}}{12} \\left[ \\sqrt{\\pi} + \\frac{1}{2}\\sqrt{\\pi} + \\frac{3}{16}\\sqrt{\\pi} \\right] = \\frac{9\\sqrt{2\\pi}}{64} \\approx 0.3525.$$\n\n    The effective sample size for $n=10000$ is\n    $$n_\\mathrm{eff} = \\frac{n}{\\expec_g{\\left[ (\\frac{f(\\theta)}{g(\\theta)})^2 \\right]}} = 10000 / \\frac{9\\sqrt{2\\pi}}{64} \\approx 28369.$$\n}\n\n\\section*{Question 11.1}\n{\n    \\textbf{Lemma: (Detailed Balance condition)}\\quad If a Markov chain with transition probability $p(\\cdot|\\cdot)$ that satisfies\n    $$\\pi(\\theta_a) \\cdot p(\\theta_b|\\theta_a) = \\pi(\\theta_b) \\cdot p(\\theta_a|\\theta_b)$$ for some distribution $\\pi(\\cdot)$, then $\\pi(\\cdot)$ is the stationary distribution of this Markov chain.\n\n    Using the lemma above, we only need to verify that the Detailed Balance condition is satisfied when $\\pi(\\cdot) = p(\\cdot|y)$.\n\n    Note that $r(\\theta_a, \\theta_b) \\cdot r(\\theta_b, \\theta_a) = 1$, for\n    $$r(\\theta_a, \\theta_b) = \\frac{ p(\\theta_b|y) \\cdot g(\\theta_a|\\theta_b) }{ p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a) }$$ and\n    $$r(\\theta_b, \\theta_a) = \\frac{ p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a) }{ p(\\theta_b|y) \\cdot g(\\theta_a|\\theta_b) },$$\n    which means it is safe to assume that $r(\\theta_a, \\theta_b) \\geq 1$ \\emph{without loss of generality}. Thus, $\\theta_b$ is always accepted after generated from the previous value $\\theta_a$, with the probability of $1$. On the contrary, $\\theta_a$ is accepted after generated from $\\theta_b$ with the probability of $r(\\theta_b, \\theta_a)$. It follows that\n    $$p(\\theta_b|\\theta_a) = g(\\theta_b|\\theta_a) \\cdot 1$$ and \n    $$p(\\theta_a|\\theta_b) = g(\\theta_a|\\theta_b) \\cdot r(\\theta_b, \\theta_a).$$\n\n    Plug them all in, and we obtain\n    $$\\mathrm{LHS} = p(\\theta_a|y) \\cdot p(\\theta_b|\\theta_a) = p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a) \\cdot 1$$\n    $$= p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a),$$ and\n    $$\\mathrm{RHS} = p(\\theta_b|y) \\cdot p(\\theta_a|\\theta_b) = p(\\theta_b|y) \\cdot g(\\theta_a|\\theta_b) \\cdot r(\\theta_b, \\theta_a)$$\n    $$= p(\\theta_b|y) \\cdot g(\\theta_a|\\theta_b) \\cdot \\frac{ p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a) }{ p(\\theta_b|y) \\cdot g(\\theta_a|\\theta_b) }$$\n    $$= p(\\theta_a|y) \\cdot g(\\theta_b|\\theta_a),$$\n    which gives $\\mathrm{LHS} = \\mathrm{RHS}$ and proves the Detailed Balance condition. Q.E.D.\n}\n\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "7b6e6082fc5daab6bca2250cf4cbf3aa736e0c8c", "size": 5157, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW7/Homework7.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": "HW7/Homework7.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": "HW7/Homework7.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": 62.8902439024, "max_line_length": 361, "alphanum_fraction": 0.6358347877, "num_tokens": 1940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8807970732843033, "lm_q1q2_score": 0.7588403396521386}}
{"text": "\\section{Counting Principles}\\label{mod2:section:CountingPrinciples}\n\n\\begin{defn}\\label{mod2:defn:MultiplicationRule}\n\tIf event $K_i$ can occur in $p$ ways and event $K_j$ can occur in $q$ ways, the number of ways that $K_i$ \\textbf{and} $K_j$ can occur is,\n\t\\begin{equation}\n\t\tp \\times q.\n\t\\end{equation}\n\tThis can be extended to any number of events. This is known as the \\textbf{Multiplication Rule}.\n\\end{defn}\n\n\n\\begin{defn}\\label{mod2:defn:AdditionRule}\n\tIf event $K_i$ can occur in $p$ ways and event $K_j$ can occur in $q$ ways, the number of ways that $K_i$ \\textbf{or} $K_j$ can occur is,\n\t\\begin{equation}\n\t\tp + q.\n\t\\end{equation}\n\tThis can be extended to any number of events. This is known as the \\textbf{Addition Rule}.\n\\end{defn}\n\n\n\\begin{defn} \\label{mod2:defn:Combination}\n\tA \\textbf{combination} is a group of elements chosen from a set of objects. The order of the elements does not matter.\n\\end{defn}\n\n\n\\begin{defn} \\label{mod2:defn:CombinationEqn}\n\tThe number of combinations of $r$ elements from a set of $n$ \\textbf{distinct} elements is defined as,\n\t\\begin{equation}\n\t\t^nC_r = \\frac{n!}{r!~(n-r)!} \\,.\n\t\\end{equation}\n\\end{defn}\n\n\n\\begin{defn}\\label{mod2:defn:Permutation}\n\tA \\textbf{permutation} is a group of elements chosen from a set of objects where the order of the elements \\textbf{does} matter.\t\n\\end{defn}\n\n\n\\begin{defn}\\label{mod2:defn:PermutationEqn}\n\tThe number of permutations of $r$ elements from a set of $n$ \\textbf{distinct} elements is defined as,\n\t\\begin{equation}\n\t\t^nP_r = \\frac{n!}{(n-r)!} \\,.\n\t\\end{equation}\n\\end{defn}\n\n\n\\begin{defn}\\label{mod2:defn:PermutationEqn2}\n\tThe number of permutations of $n$ elements, not all distinct, is defined as,\n\t\\begin{equation}\n\t\t\\frac{n!}{{k_1}!\\,{k_2}!\\,...\\,{k_r}!} \\,,\n\t\\end{equation}\n\twhere  $\\sum_{i=1}^{r} k_i = n$, and $k_i$ is the number of non-distinct elements of type $i$.\n\\end{defn}\n\n\n\\begin{defn}\\label{mod2:defn:PermutationEqn3}\n\tThe number of permutations of size $r$ out of $n$ elements, with repetition, is defined as,\n\t\\begin{equation}\n\t\tn^r\n\t\\end{equation}\n\\end{defn}\n\n\n\n\n\\section{Probability Theory}\\label{mod2:section:ProbabilityTheory}\n\n\n\\begin{axiom}  \\label{mod2:axiom:ProbabilityAxioms}\n\tConsider an experiment whose sample space is $S$. The \\textbf{probability of the event $E$}, denoted as $P(E)$, is a number that satisfies the following three axioms\t\n\t\\begin{enumerate}[label = \\bfseries (\\arabic*)]\n\t\t\\item \t$0 \\leq P(E) \\leq 1 , $ \\label{mod2:axiom:ProbabilityAxiom:1}\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t\\item \t$\tP(S) = 1, $ \\label{mod2:axiom:ProbabilityAxiom:2}\n\t\t\t\t\n\t\t\t\n\t\t\n\t\t\\item \tFor any sequence of mutually exclusive events $E_1, E_2, ... , E_n$.\n\t\t\n\t\t\t\n\t\t\t\t\t$P\\left( \\cup_{i=1}^n E_i \\right) = \\sum_{i=1}^n P(E_i), $ \\label{mod2:axiom:ProbabilityAxiom:3}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\tEg. $P(E_1 \\cup E_2) = P(E_1)+P(E_2)$.\n\t\t\n\t\t\n\t\\end{enumerate}\n\\end{axiom}\n\n\n\\begin{defn} \\label{mod2:defn:Probability}\n\tFurthermore, we define,\n\t\\begin{equation}\n\t\tP(\\text{event E occurs}) = \\frac{\\text{no. of times A can occur}}{\\text{total number of outcomes}}. \n\t\\end{equation}\n\\end{defn}\n\n\n\n\\begin{defn} \\label{mod2:defn:Complement}\n\tThe probability of the \\textbf{complement} of event $A$, denoted as $P(A^c)$ or $P(\\bar{A})$ or $P(A^\\prime)$, is defined as\n\t\\begin{equation}\n\t\tP(\\bar{A}) = 1 - P(A).\n\t\\end{equation}\n\\end{defn}\n\n\n\\begin{prop} \\label{mod2:prop:SetPropositions}\nSome useful propositions can be easily derived using the above and drawing your own diagrams\n\\begin{align}\nP(A \\cup B) &= P(A) + P(B) - P(A \\cap B), \\label{mod2:eq:SetProp:1}  \\\\ \nP(A^c \\cap B) &= P(B) - P(A \\cap B), \\label{mod2:eq:SetProp:2} \\\\ \nP(A^c \\cap B^c) &=  P(A \\cup B)^c ,\\label{mod2:eq:SetProp:3} \\\\ \nP(A^c \\cup B^c) &= P (A \\cap B) ^c .\\label{mod2:eq:SetProp:4} \\ \n\\end{align}\n\\end{prop}\n\n\n\\begin{defn} \\label{mod2:defn:MutuallyExclusive}\nTwo events $A$ and $B$ are said to be \\textbf{mutually exclusive} if and only if\n\\begin{equation}\t\n\tP ( A \\cap B) = 0. \\label{mod2:eq:MutuallyExclusive:1} \\ \n\\end{equation}\nApplying Eq~[\\ref{mod2:eq:SetProp:1}], this implies \n\\begin{equation}\n\tP(A \\cup B) = P(A) + P(B).\\  \\label{mod2:eq:MutuallyExclusive:2}\n\\end{equation}\n\\end{defn}\n\n\n\\begin{defn} \\label{mod2:defn:Independent}\nTwo events $A$ and $B$ are said to be \\textbf{independent} if and only if\n\\begin{equation}\nP(A \\cap B) = P (A) \\times P(B). \\label{mod2:eq:Independent} \\ \n\\end{equation}\n\\end{defn}\n\n\\begin{defn} \\label{mod2:defn:Conditional}\nFor events $A$ and $B$, the \\textbf{conditional probability} of $A$ given $B$ has occurred, denoted by $P(A|B)$, is defined by\n\\begin{equation}\nP(A|B) = \\frac{P(A\\cap B)}{P(B)}. \\label{mod2:eq:ConditionalProbability} \\ \n\\end{equation}\n\\end{defn}\n\n\n\n\n\\section{Discrete Random Variables} \\label{mod2:section:DiscreteRandomVariables}\n\n\n\\begin{defn} \\label{mod2:defn:DiscreteRandomVar}\n\tA \\textbf{discrete random variable}, $X$, can take on at most a countable number of possible values. We define its \\textit{probability mass} function, $P(x)$ by\n\t\\begin{equation}\n\tP(x) =P(X = x).\n\t\\end{equation}\n\\end{defn}\n\n\\begin{prop}\\label{mod2:prop:Discrete:Properties}\n\tIf $X$ is a discrete random variable with probability mass function $P(x)$, then we know from Axiom~[\\ref{mod2:axiom:ProbabilityAxiom:1}] that\n\t\\begin{equation}\n\t0 \\leq P(X=x) \\leq 1 \\: \\forall x.\n\t\\end{equation}\n\tand from Axiom~[\\ref{mod2:axiom:ProbabilityAxiom:2}] and Axiom~[\\ref{mod2:axiom:ProbabilityAxiom:3}] that\n\t\\begin{equation}\n\t\\sum_{\\forall x}P(X=x) = 1 .\n\t\\end{equation}\n\\end{prop}\n\n\\begin{defn} \\label{mod2:defn:Discrete:Expectation}\n\tIf $X$ is a discrete random variable, the \\textbf{expectation value}, \\textbf{mean} or \\textbf{first moment of $X$}, $E[X]$, is defined by\n\t\\begin{equation}\n\tE[X]= \\sum_{\\forall i} x_i P(X=x_i). \\label{mod2:eq:Discrete:Expectation}\\ \n\t\\end{equation}\n\\end{defn}\n\n\\begin{defn} \\label{mod2:defn:Discrete:SecondMoment}\n\tIf $X$ is a discrete random variable, the \\textbf{second moment of $X$} is defined by\n\t\\begin{equation}\n\tE[X^2] = \\sum_{\\forall i} x_i^2 P(X=x_i). \\label{mod2:eq:Discrete:SecondMoment} \\ \n\t\\end{equation}\n\\end{defn}\n\n\\begin{defn}\\label{mod2:defn:Discrete:Variance}\n\tIf $X$ is a random variable with mean $\\mu$, then the \\textbf{variance}, $Var[X]$, is defined by\n\t\\begin{align}\n\tVar[X] &= E[(X-\\mu)^2],  \\label{mod2:eq:Discrete:Variance:1}  \\\\\n\t&= E[X^2] - (E[X])^2  = E[X^2] - \\mu^2 . \\label{mod2:eq:Discrete:Variance:2} \\\n\t\\end{align}\n\\end{defn}\n\n\n\n\\section{Discrete Uniform Distribution} \\label{mo2:section:DiscreteUniform}\n\n\\begin{defn} \\label{mod2:defn:DiscreteUniform}\n\tA discrete random variable $X$ is said to follow a \\textbf{discrete uniform distribution} if $X$ can take a finite number of values which are observed with equal probabilities. Therefore, the probability mass function, $P$, of $X$ which can take $n$ possible values,  is given by\n\t\\begin{equation}\n\t\tP(X = x_i) = \\frac{1}{n} \\label{mod2:eq:DiscreteUniform}.\n\t\\end{equation}\n\\end{defn}\n\n\\begin{note}\\label{mod2:note:DiscreteUniform}\n\tIn the discrete case, the notation $X \\sim \\text{Unif}(a, b)$ or $X \\sim \\text{U}(a, b)$ implies that $X$ can take \\textbf{integer} values $x$ such that $a \\leq x \\leq b$. Here, the total numer of values $X$ can take is given by\n\t\\begin{equation}\n\t\tn = b - a + 1,\n\t\\end{equation}\n\tTherefore the p.m.f of $X$ can be given by\n\t\\begin{equation}\n\tP(X = x)= \\frac{1}{b - a + 1}\\ \\quad a \\leq x \\leq b.\n\t\\end{equation}\n\t\tThe \\textit{expected value (mean)} and \\textit{variance} of $X \\sim \\text{U}(a,b)$ are given by:\n\t\\begin{align}\n\tE[X] &= \\frac{a+b}{2}, \\label{mod2:eq:DiscreteUniform:Mean} \\\\\n\tVar[X] &= \\frac{(b-a+1)^2 - 1}{12}. \\label{mod2:eq:DiscreteUniform:Variance} \n\t\\end{align}\n\\end{note}\n\n\n\n\n\\section{Binomial Distribution} \\label{mod2:section:Binomial}\n\\begin{defn} \\label{mod2:defn:Binomial}\n\tA discrete random variable $X$ is said to follow a \\textbf{binomial distribution} with parameters $n$ and $p$, $X \\sim \\text{Bin}(n,p)$, if its probability mass function, $P$, is given by\n\t\\begin{equation}\n\tP(X = x) = { n \\choose x} p^x (1-p)^{n-x} \\quad x \\in ( 0, 1, 2, ... , n). \\label{mod2:eq:BinomialDist} \\ \n\t\\end{equation} \n\\end{defn}\n\n\\begin{note}\n\tThe \\textit{expected value (mean)} and \\textit{variance} of $X$ are given by:\n\t\\begin{align}\n\tE[X] &= np,  \\label{mod2:eq:Binomial:Mean} \\\\ \n\tVar[X] &= np(1-p), \\label{mod2:eq:Binomial:Variance} \\\\\n\t&= npq  \\: \\text{ where } q = (1-p).\\ \n\t\\end{align}\n\\end{note}\n\n\\begin{note} \\label{mod2:note:Binomial:Conditions}\n\tThere are four conditions that describe a binomial distribution\n\t\\begin{enumerate}[label = (\\roman*)]\n\t\t\\item The experiment consist of a fixed number of trials, $n$.\n\t\t\\item The trials are independent.\n\t\t\\item Each trial can be classified as a success or failure.\n\t\t\\item The probability of success, $p$, is constant\n\t\\end{enumerate}\n\\end{note}\n\n\n\n\\section{Geometric Distribution} \\label{mod2:section:Geometric}\n\\begin{defn}\\label{mod2:defn:Geomtric}\n\tA discrete random variable $X$ is said to follow a \\textbf{geomteric distribution} with parameter $p$, $X \\sim \\text{Geo}(p)$, if its probability mass function, $P$, is given by\n\\begin{equation}\nP(X = x) = p(1-p)^{x-1} \\quad x \\in (1, 2, ...). \\label{mod2:eq:GeometricDist} \\ \n\\end{equation} \n\\end{defn}\n\n\\begin{note}\n\tThe \\textit{expected value (mean)} and \\textit{variance} of $X$ are given by:\n\t\\begin{align}\n\tE[X] &= \\frac{1}{p},  \\label{mod2:eq:Geometric:Mean} \\\\ \n\tVar[X] &= \\frac{1-p}{p^2}, \\label{mod2:eq:Geomtric:Variance} \\\\\n\t&= \\frac{q}{p^2}  \\: \\text{ where } q = (1-p).\\ \n\t\\end{align}\n\\end{note}\n\n\\begin{note} \\label{mod2:eq:Geometric:Prop}\n\tThe probability of $X>k$ is given as\n\t\\begin{equation}\n\t\tP(X>k)=q^k\n\t\\end{equation}\n\\end{note}\n\\begin{note} \\label{mod2:note:Geometric:Conditions}\n\tThere are three conditions that describe a geometric distribution\n\t\\begin{enumerate}[label = (\\roman*)]\n\t\t\\item The trials are independent.\n\t\t\\item Each trial can be classified as a success or failure.\n\t\t\\item The probability of success, $p$, is constant\n\t\\end{enumerate}\n\\end{note}\n\n\n\n\\section{Poisson Distribution}\\label{mod2:section:Poisson}\n\\begin{defn} \\label{mod2:defn:Poisson}\n\tA discrete random variable $X$ is said to follow a \\textbf{poisson distribution} with parameter $\\lambda$, $X \\sim \\text{Pois}(\\lambda)$, if its probability mass function, $P$, is given by\n\\begin{equation}\nP(X = x) =\\frac{ \\lambda ^ x e^{-\\lambda}}{x!} \\quad x \\in (0, 1, 2, ...). \\label{mod2:eq:PoissonDist} \\ \n\\end{equation} \n\\end{defn}\n\n\n\\begin{note}\n\tThe \\textit{expected value (mean)} and \\textit{variance} of $X$ are given by:\n\t\\begin{align}\n\tE[X] &= \\lambda,  \\label{mod2:eq:Poisson:Mean} \\\\ \n\tVar[X] &= \\lambda. \\label{mod2:eq:Poisson:Variance} \n\t\\end{align}\n\\end{note}\n\n\n\\begin{note} \\label{mod2:note:Poisson:Conditions}\n\tThe Poisson distribution is popular for modeling the number of times an event occurs in an interval of time. There are two conditions that describe a poisson distribution\n\t\\begin{enumerate}[label = (\\roman*)]\n\t\t\\item Events are independent of each other.\n\t\t\\item The average rate at which events occur, $\\lambda$, is independent of any occurrences.\n\t\\end{enumerate}\n\\end{note}\n\n\n\\section {Poisson Approximation to the Binomial Distribution} \\label{mod2:section:PoissonApproxBinomial}\n \n \\begin{defn} \\label{mod2:defn:PoissonApproxBinomial}\nThe \\textbf{Poisson limit theorem} states that a binomially distributed random variable $X \\sim \\text{Bin}\\{n, p\\}$ can be approximated by a poisson distribution if the following hold;\n\\begin{enumerate}[label = (\\roman*)]\n\t\\item $n > 50$,\n\t\\item $np < 5$.\n\\end{enumerate}\n\nUnder the above conditions, $X \\sim \\text{Bin}(n, p)$ can be approximated by $X \\sim \\text{Pois}(np)$, $\\lambda = E[X]$.\n\n\\end{defn}\n\t\n\n\n\\section{Continuous Random Varibales} \\label{mod2:section:ContinuousRandomVar}\n\n\\begin{defn} \\label{mod2:defn:ContinuousRandomVar}\n\tWe say that $X$ is a \\textbf{continuous random variable}, if there exists a non-negative function $f$, defined for all real $x \\in (-\\infty,\\infty)$, having the property that, for any set of real numbers $B$,\n\t\\begin{equation}\n\tP(X \\in B) = \\int_B f(x).dx. \\\n\t\\end{equation}\n\tThe function $f$ is called the \\textit{probability density function} of the random variable $X$.\n\\end{defn}\n\n\n\\begin{prop} \\label{mod2:prop:ContinuousRV:1}\n\tSince $X$ must assume some value, $f$ must satisfy,\n\t\\begin{equation}\n\t1 = P(X \\in (-\\infty,\\infty)) = \\int_{-\\infty}^{\\infty} f(x).dx.  \\\n\t\\end{equation}\n\\end{prop}\n\n\\begin{note} \\label{mod2:note:ContinuousRV:Note1}\n\tIf $B=[a,b]$, then\n\t\\begin{align}\n\tP(X\\in B) &= P(a \\leq X \\leq b), \\\\\n\t&= \\int_a^b f(x) .dx. \\\n\t\\end{align}\n\\end{note}\n\n\\begin{prop} \\label{mod2:prop:ContinuousRV:2}\n\tFor any continuous random variable $X$ and real number $a$,\n\t\\begin{equation}\n\tP(X=a) = 0.\\\n\t\\end{equation}\n\\end{prop}\n\n\\begin{note} \n\tThis implies\n\t\\begin{equation}\n\tP( X \\leq a) = P(X<a). \\\n\t\\end{equation}\n\\end{note}\n\n\\begin{defn} \\label{mod2:defn:ContinuousRV:Expectation}\n\tIf $X$ is a continuous random variable, the \\textbf{expectation (mean)} of $X$ is given by,\n\t\\begin{equation}\n\tE[X] = \\int_{-\\infty}^{\\infty}x f(x).dx. \\label{mod2:eq:ContinuousRV:Expectation} \\\n\t\\end{equation}\n\\end{defn}\n\n\\begin{defn} \\label{mod2:defn:ContinuousRV:Variance}\n\tIf $X$ is a continuous random variable, the \\textbf{variance} of $X$ is given by,\n\t\\begin{align}\n\tVar[X] &= E[X^2] - {E[X]}^2, \\\\\n\t &= \\int_{-\\infty}^{\\infty}x^2 f(x).dx - {(\\int_{-\\infty}^{\\infty}x f(x).dx)} ^ 2. \\label{mod2:eq:ContinuousRV:Variance} \\\n\t\\end{align}\n\\end{defn}\n\n\\begin{law} \\label{mod2:law:UnconsciousStat}\n\tIn the above formula for variance of a continuous random variable,  the \\textbf{Law of the Unconscious Statiscian (LOTUS)} is used. This law states that if $X$ is a continuous randon varibale with probability density function $f$, then for any function g,\n\t\\begin{equation}\n\t\tE[g(X)] = \\int_{-\\infty}^{\\infty}g(x) f(x).dx. \\label{mod2:eq:LOTUS:ContinuousRV}\n\t\\end{equation}\n\t\n\tThe law also extends to the discrete case. If $X$ is a discrete random variable, then by \\textbf{LOTUS}, \n\t\n\t\\begin{equation}\n\tE[g(X)] =  \\sum_{\\forall i} g(x_i) P(X=x_i). \\label{mod2:eq:LOTUS:DiscreteRV}\n\t\\end{equation}\n\\end{law}\t\n\n\n\\begin{defn} \\label{mod2:defn:ContinuousRV:CDF}\n\tFor a continuous random variable $X$ with p.d.f $f$,  the \\textbf{cumulative distribution function, F,} is defined as follows,\n\t\\begin{equation}\n\t\tF(x) = P(X \\leq x), \\\n\t\\end{equation}\n\t\n\tUsing Eq~[\\ref{mod2:note:ContinuousRV:Note1}], where $B = (-\\infty, x]$,\n\t\\begin{equation}\n\t\tF(x) = \\int_{-\\infty}^{x} f(x).dx, \\\n\t\\end{equation}\n\t\n\tUsing the \\textbf{Fundamental Law of Calculus}, then\n\t\\begin{equation}\n\tf(x) = \\frac{d}{dx}F(x)\n.\t\\end{equation}\n\t\n\t\n\\end{defn}\t\n\n\\begin{note} \\label{mod2:note:ContinuousRV:CDF}\n\tThis implies\n\t\\begin{equation}\n\t\tP( a \\leq X \\leq b) = F(b) - F(a).\n\t\\end{equation}\n\\end{note}\n\n\\begin{prop} \\label{mod2:prop:ContinuousRV:CDF}\n\tThe c.d.f can be used to calculate the median and quartiles of a distribution. If a continuous random variable $X$ has c.d.f $F$,  then \n\t\\begin{align}\n\tF(M) &= 0.5, \\\\\n\tF(LQ) &= 0.25, \\\\\n\tF(UQ) &= 0.75.\n\t\\end{align}\t\n\twhere $M$ denotes the median, $LQ$ denotes the lower quartile and $UQ$ denotes the upper quartile.\n\\end{prop}\n\t\t\n\n\n\n\n\\section{Normal Distribution}\\label{mod2:section:Normal}\n\n\\begin{defn}\\label{mod2:defn:Normal}\n\tA continuous random variable $X$ is said to follow a \\textbf{normal distribution} with parameters $\\mu$ and $\\sigma^2$, $X \\sim \\text{N}(\\mu,\\sigma^2)$, if its probability density function, $f$, is given by\n\t\\begin{equation}\n\tf(x) = \\frac{1}{\\sqrt{2 \\pi}\\sigma} e^{-(x-\\mu)^2/2\\sigma^2} \\quad -\\infty < x < \\infty  \\label{mod2:eq:Normal}\\\n\t\\end{equation}\n\tThe parameters $\\mu$ and $\\sigma^2$ represent the expected value (mean) and variance respectively.\n\\end{defn}\n\n\\begin{note} \\label{mod2:note:Normal:Properties}\n\tNormal random variables have important properties\n\t\\begin{enumerate}[label = (\\roman*)]\n\t\t\\item If $X$ is normally distributed with parameters $\\mu$ and $\\sigma^2$, then $Y = aX + b$ is normally distributed with parameters $a\\mu + b$ and $a^2\\sigma^2$ respectively. \\label{mod2:note:Normal:Property1}\n\t\t\\item The previous property implies that if $X$ is normally distributed with parameters $\\mu$ and $\\sigma^2$, then $Z=\\frac{(X-\\mu)}{\\sigma}$ is normally distributed with parameters $0$ and $1$. We call $Z$ a \\textit{standard} or \\textit{unit} normal random variable. \\label{mod2:note:Normal:Property2}\n\t\\end{enumerate}\n\\end{note}\n\n\n\\section{Normal Approximation to the Poisson Distribution} \\label{mod2:section:NormalApproxPois}\n\n\\begin{defn}\\label{mod2:def:NormalApproxToPois:Definition}\n\tA poisson distributions $X \\sim \\text{Pois}(\\lambda)$ where $\\lambda > 15$, can be approximated by a normal distribution, $X \\sim \\text{N}(\\lambda, \\sqrt{\\lambda})$.\n\\end{defn}\n\n\\begin{note}\\label{mod2:note:NormalApproxtoPois:Continuity}\n\tTo use this approximation, we must note that because the poisson is a discrete integer-valued random variable and the normal is a continuous random variable, we must write\n\t\\begin{align}\n\tP(X=a) &= P \\left( a -\\frac{1}{2} < X < a + \\frac{1}{2} \\right), \\\\\n\tP(X \\leq a) &= P \\left( X < a + \\frac{1}{2} \\right), \\\\\n\tP(X \\geq a) &= P \\left( X > a - \\frac{1}{2} \\right), \\\\\n\tP(X < a) &= P \\left( X < a - \\frac{1}{2} \\right), \\\\\n\tP(X > a) &= P \\left( X > a + \\frac{1}{2} \\right), \\\\\n\tP(a \\leq X < b) &= P \\left( a - \\frac{1}{2} < X < b - \\frac{1}{2} \\right), \\\\\n\tP(a < X \\leq  b) &= P \\left( a + \\frac{1}{2} < X < b + \\frac{1}{2} \\right), \\\\\n\tP(a  \\leq  X \\leq  b) &= P \\left( a - \\frac{1}{2} < X < b + \\frac{1}{2} \\right).\n\t\\end{align}\n\tThis is called the \\textbf{continuity correction}.\n\\end{note}\n\n\n\\section{Expectation and Variance} \\label{mod2:section:ExpectationVariance}\n\n\\begin{prop}\n\nDefine  functions $g$ and $f$ with $a, b, c \\in \\mathbb{R}$. For \\textbf{ANY} random variables (discrete or cotinuous) $X$ and $Y$, the following properties hold\n\\begin{align}\nE[aX + b] &= aE[X] + b, \\\\\nE[X + Y] &= E[X] + E[Y], \\\\\nE[ag(X) + bf(Y)  + c] &= aE[g(X) ]+ bE[f(Y)] + c, \\\\\nVar[ag(X) + b] &= a^2Var[g(X)].\n\\end{align}\n\nIf $X$ and $Y$ are \\textbf{independent} random variables, then the following properties also hold\n\\begin{align}\nE[XY] &= E[X] \\ E[Y], \\\\\nE[g(X)f(Y)] &= E[g(X)] \\ E[f(Y)], \\\\\nVar[X + Y] &= Var[X]+ Var[Y].\n\\end{align}\n\n\\end{prop}\n\n\\begin{note} \\label{mod2:note:Independence:Non-implication}\n\t\n\tIf $E[XY] = E[X] \\ E[Y]$ or $Var[X + Y] = Var[X]+ Var[Y]$, this does not imply $X$ and $Y$ are independent.\n\t\n\\end{note}\n\n\n\n\n\n\n\n\n\n\n", "meta": {"hexsha": "a30923a7904fdaed4c1caab3563ce8a6c293ae3d", "size": 18410, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "include/Notes/mod2.tex", "max_stars_repo_name": "BradBachu/Applied-Mathematics-Unit2", "max_stars_repo_head_hexsha": "26bb5ad81d6dd6d555bbbf1f329e39509ba4e355", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2018-06-04T03:45:26.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-04T03:45:26.000Z", "max_issues_repo_path": "include/Notes/mod2.tex", "max_issues_repo_name": "Varaunight/Applied-Mathematics-Unit2", "max_issues_repo_head_hexsha": "826947b9315922b3c8f23be272b82ca45e1caf11", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 12, "max_issues_repo_issues_event_min_datetime": "2018-06-03T21:43:55.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-19T04:04:31.000Z", "max_forks_repo_path": "include/Notes/mod2.tex", "max_forks_repo_name": "Varaunight/Applied-Mathematics-Unit2", "max_forks_repo_head_hexsha": "826947b9315922b3c8f23be272b82ca45e1caf11", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-06-03T19:11:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-16T21:14:24.000Z", "avg_line_length": 35.7475728155, "max_line_length": 304, "alphanum_fraction": 0.6764801738, "num_tokens": 6609, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7588403324770991}}
{"text": "% Document Head\n\\documentclass[11pt, oneside]{book}\n\\input{latex-classnotes-preamble.tex}\n\n% Main Body\n\\title{PMATH352W18 - Complex Analysis - Topical Exercises}\n\\author{Johnson Ng}\n\n\\begin{document}\n\\hypersetup{pageanchor=false}\n\\maketitle\n\\hypersetup{pageanchor=true}\n\\tableofcontents\n\n\\chapter{Complex Numbers}\n\t\\label{chapter:complex_numbers}\n\n\\section{Basic Algebraic Properties} % (fold)\n\\label{sec:basic_algebraic_properties}\n\n\\begin{enumerate}\n\t\\item Verify that\n\n\t\\begin{inlinelist}\n\t\t\\item $(\\sqrt{2} - i) - i (1 - \\sqrt{2}i) = -2i$;\n\t\t\\item $(2 - 3i)(-2 + i) = -1 + 8i$;\n\t\t\\item $(3 + i)(3 - i)(\\frac{1}{5} - \\frac{1}{10} i) = 2 + i$.\n\t\\end{inlinelist}\n\t\\item Find the complex numbers which are complex conjugates of\n\n\t\\begin{inlinelist}\n\t\t\\item Their own squares;\n\t\t\\item Their own cubes.\n\t\\end{inlinelist}\n\n\t\\item Caclulate the following quantities:\n\n\t\\begin{inlinelist}\n\t\t\\item $\\frac{1 + i \\tan \\theta}{1 - i \\tan \\theta}$;\n\t\t\\item $\\frac{(1 + 2i)^3 - (1 - i)^3}{(3 + 2i)^3 - (2 + i)^2}$;\n\t\t\\item $\\frac{(1 - i)^5 - 1}{(1 + i)^5 + 1}$;\n\t\t\\item $\\frac{(1 + i)^9}{(1 - i)^7}$. \n\t\\end{inlinelist}\n\n\t\\item Find the points $z = x + iy$ such that\n\n\t\\begin{inlinelist}\n\t\t\\item $\\abs{z} \\leq 2$;\n\t\t\\item $\\im z > 0$;\n\t\t\\item $\\re z \\leq \\frac{1}{2}$;\n\t\t\\item $\\re (z^2) = a$;\n\t\t\\item $\\abs{z^2 - 1} = a$;\n\t\t\\item $\\abs{\\frac{z-1}{z + 1}} \\leq 1$;\n\t\t\\item $\\abs{\\frac{z - \\alpha}{z - \\beta}} = 1$.\n\t\\end{inlinelist}\n\n\t\\item Derive the identity\n\t\\begin{equation*}\n\t\t\\left( \\frac{z_1}{z_3} \\right)\\left( \\frac{z_2}{z_4} \\right) = \\frac{z_1 z_2}{z_3 z_4} \\quad (z_3 \\neq 0, z_4 \\neq 0)\n\t\\end{equation*}\n\n\t\\item Using the above identity, derive the cancellation law\n\t\\begin{equation*}\n\t\t\\frac{z_1 z}{z_2 z} = \\frac{z_1}{z_2} \\quad (z_2 \\neq 0, z \\neq 0)\n\t\\end{equation*}\n\n\t\\item Using properties of moduli that has been introduced, show that when $\\abs{z_3} \\neq \\abs{z_4}$,\n\t\\begin{equation*}\n\t\t\\frac{\\re(z_1 + z_2)}{\\abs{z_3 + z_4}} \\leq \\frac{\\abs{z_1} + \\abs{z_2}}{\\abs{\\abs{z_3} - \\abs{z_4}}} \n\t\\end{equation*}\n\n\t\\item Verify that $\\sqrt{2}\\abs{z} \\geq \\abs{\\re z} + \\abs{\\im z}$. (Hint: Reduce this inequality to $(\\abs{x} - \\abs{y})^2 \\geq 0$.)\n\\end{enumerate}\n\n(Jump to \\hyperref[sub:basic_algebraic_properties]{solutions})\n\n% section basic_algebraic_properties (end)\n\n\\section{Polar Form} % (fold)\n\\label{sec:polar_form}\n\n\\begin{enumerate}\n\t\\item Represent the following complex numbers in polar form:\n\n\t\\begin{inlinelist}\n\t\t\\item $1 + i$;\n\t\t\\item $-1 + i$;\n\t\t\\item $-1 - i$;\n\t\t\\item $1 - i$;\n\t\t\\item $ 1 + \\sqrt{3} i$;\n\t\t\\item $-1 + \\sqrt{3} i$;\n\t\t\\item $-1 - \\sqrt{3} i$;\n\t\t\\item $ 1 - \\sqrt{3} i$;\n\t\t\\item $2 + \\sqrt{3} + i$.\n\t\\end{inlinelist}\n\n\t\\item Generalize the Triangle Inequality.\n\t\\item Prove the identity\n\t\\begin{equation*}\n\t\t\\abs{z_1 + z_2}^2 + \\abs{z_1 - z_2}^2 = 2(\\abs{z_1}^2 + \\abs{z_2}^2),\n\t\\end{equation*}\n\tfor arbitrary complex numbers $z_1, z_2, ..., z_n$.\n\n\t\\item When do three points $z_1, z_2, z_3 \\in \\mathbb{C}$ lie on a straight line in the complex plane?\n\n\t\\item Let $\\sigma$ be the line segment joining two points $z_1$ and $z_2$. Find the point $z$ dividign $\\sigma$ in the ratio $\\lambda_1 : \\lambda_2$.\n\n\t\\item Four points $z_1, z_2, z_3, z_4$ satisfy the conditions\n\t\\begin{equation*}\n\t\tz_1 + z_2 + z_3 + z_4 = 0, \\quad \\abs{z_1} = \\abs{z_2} = \\abs{z_3} = \\abs{z_4} = 1.\n\t\\end{equation*}\n\tShow that the points either lie ast the vertices of a square inscribed in the unit circle or else coincide in pairs.\n\n\t\\item Calculate the following quantities:\n\n\t\\begin{inlinelist}\n\t\t\\item $(1 + i)^{25}$;\n\t\t\\item $\\left(\\frac{1 + \\sqrt{3} i}{1 - i} \\right)^{30}$;\n\t\t\\item $\\left( 1 - \\frac{\\sqrt{3 - i}}{2} \\right)^24$;\n\t\t\\item $\\frac{(-1 + \\sqrt{3}i)^{15}}{(1 - i)^{30}} + \\frac{(-1-\\sqrt{3}i)^{15}}{(1 + i)^{20}}$.\n\t\\end{inlinelist}\n\n\t\\item Use De Moivre's theorem to express $\\cos nx$ and $\\sim nx$ in terms of powers of $\\cos x$ and $\\sin x$.\n\n\t\\item Express $\\tan 6x$ in terms of $\\tan x$.\n\n\t\\item Write $\\sqrt{1 + i}$ in polar form.\n\\end{enumerate}\n\n% section polar_form (end)\n\n\\section{Roots of a Complex Number} % (fold)\n\\label{sec:roots_of_a_complex_number}\n\n\\begin{enumerate}\n\t\\item Find all the values of the following roots:\n\n\t\\begin{inlinelist}\n\t\t\\item $\\sqrt[3]{1}$;\n\t\t\\item $\\sqrt[3]{i}$;\n\t\t\\item $\\sqrt[4]{-1}$;\n\t\t\\item $\\sqrt[6]{-8}$;\n\t\t\\item $\\sqrt[8]{1}$;\n\t\t\\item $\\sqrt{3 + 4i}$;\n\t\t\\item $\\sqrt[3]{-2 + 2i}$;\n\t\t\\item $\\sqrt[5]{-4 + 3i}$;\n\t\t\\item $\\sqrt[6]{\\frac{1 - i}{\\sqrt{3} + i}}$;\n\t\t\\item $\\sqrt[8]{\\frac{1 + i}{\\sqrt{3} - i}}$;\n\t\\end{inlinelist}\n\n\t\\item Prove that the sum of all the distinct $n$th roots of unity is zero. What geometric fact does this express?\n\n\t\\item Let $\\epsilon$ be any $n$th root of unity other than 1. prove that\n\t\\begin{equation*}\n\t\t1 + 2\\epsilon + 3 \\epsilon^2 + \\hdots + n\\epsilon^{n - 1} = \\frac{n}{\\epsilon - 1} \n\t\\end{equation*}\n\n\t\\item Prove that every complex number $\\alpha \\neq -1$ of unit modulus can be represented in the form\n\t\\begin{equation*}\n\t\t\\alpha = \\frac{1 + it}{1 - it},\n\t\\end{equation*}\n\twhere $t \\in \\mathbb{R}$.\n\\end{enumerate}\n\n% section roots_of_a_complex_number (end)\n\n\\section{Mash up} % (fold)\n\\label{sec:mash_up}\n\n\\begin{enumerate}\n\t\\item Express in the form $a + bi$:\n\t\\begin{enumerate}\n\t\t\\item $\\frac{1}{6 + 2i}$\n\t\t\\item $\\frac{(2 + i)(3 + 2i)}{1 - i}$\n\t\t\\item $\\left( - \\frac{1}{2} + i \\frac{\\sqrt{3}}{2} \\right)^4$\n\t\t\\item $i^2, i^3, i^4, i^5, ...$\n\t\\end{enumerate}\n\n\t\\item Solve the equation $z^2 + \\sqrt{32}iz - 6i = 0$\n\n\t\\item Suppose $P$ is a polynomial with real coefficients. Show that $P(z) = 0$ iff $P(\\bar{z}) = 0$ (i.e. zeroes of ``real'' polynomials come in conjugate pairs).\n\\end{enumerate}\n\n% section mash_up (end)\n\n% chapter complex_numbers (end)\n\n\\chapter{Complex Functions}\n\t\\label{chapter:complex_functions}\n\n\\section{Limits and Continuity} % (fold)\n\\label{sec:limits_and_continuity}\n\n\\begin{enumerate}\n\t\\item Let $f : \\Omega \\subseteq \\mathbb{C} \\to \\mathbb{C}$, $z_0 \\in \\Omega$. $\\forall z \\in \\Omega$, prove that\n\t\\begin{equation*}\n\t\t(z \\to z_0 \\implies f(z) \\to \\infty) \\iff (z \\to z_0 \\implies \\psi(z) = \\frac{1}{f(z)} \\to 0)\n\t\\end{equation*}\n\n\t\\item The \\hlnotea{Cauchy Convergence Criterion for sequences} states that a complex sequence $z_n$ is convergent iff\n\t\\begin{gather*}\n\t\t\\forall \\epsilon > 0 \\; \\exists N = N(\\epsilon) > 0 \\; \\forall m, n > N \\\\\n\t\t\\abs{z_m - z_n} < \\epsilon.\n\t\\end{gather*}\n\tProve the generalization of the criterion: The function $f(z)$ approaches a limit as $z \\to z_0$ iff\n\t\\begin{gather*}\n\t\t\\forall \\epsilon > 0 \\; \\exists \\delta = \\delta(\\epsilon) > 0 \\\\\n\t\t(0 < \\abs{z' - z_0} < \\delta \\; \\land \\; 0 < \\abs{z'' - z} < \\delta) \\implies \\abs{f(z') - f(z'')} < \\epsilon\n\t\\end{gather*}\n\n\t\\item Let $f(z)$ be a rational function, i.e., a ratio\n\t\\begin{equation}\\label{eq:1}\n\t\tf(z) = \\frac{a_0 + a_1 z + \\hdots a_m z^m}{b_0 + b_1z + \\hdots + b_n z^n} \\enspace (a_m \\neq 0, b_n \\neq 0)\n\t\\end{equation}\n\tof two polynomials. Discuss the possible values of $\\lim_{z \\to \\infty} f(z)$.\n\n\t\\item Where is the function \\cref{eq:1} continuous?\n\n\t\\item Prove that if $f(z)$ is continuous in a region $\\Omega$, then so is $\\abs{f(z)}$.\n\n\t\\item Is the function\n\t\\begin{equation*}\n\t\tf(zz) = \\frac{1}{1 - z}\n\t\\end{equation*}\n\tcontinuous in the open disk $\\abs{z} < 1$?\n\\end{enumerate}\n\n% section limits_and_continuity (end)\n\n% chapter complex_functions (end)\n\n\\chapter{Differentiation}\n\t\\label{chapter:differentiation}\n\n\\section{Others} % (fold)\n\\label{sec:others}\n\n\\begin{enumerate}\n\t\\item \\begin{enumerate}\n\t\t\\item Suppose $f(z)$ is real-valued and differentiable for all real $z$. Show that $f'(z)$ is also real-valued for real $z$.\n\t\t\\item Suppose $f(z)$ is real-valued and differentiable for all imaginary points $z$. Show that $f'(z)$ is imaginary for all imaginary points $z$.\n\t\\end{enumerate}\n\\end{enumerate}\n\n% section others (end)\n\n% chapter differentiation (end)\n\n\\chapter{Integration}\n\t\\label{chapter:integration}\n\n\\section{Analyticity} % (fold)\n\\label{sec:analyticity}\n\n\\begin{enumerate}\n\t\\item Prove that a nonconstant entire function cannot satisfy the two equations\n\t\t\\begin{enumerate}\n\t\t\t\\item $f(z + 1) = f(z)$\n\t\t\t\\item $f(z + i) = f(z)$\n\t\t\\end{enumerate}\n\t\tfor all $z$ [\\textit{Hint:} Show that a function satisfying both equalities would be bounded.]\n\\end{enumerate}\n\n% section analyticity (end)\n\n% chapter integration (end)\n\n\\chapter{Singularities}\n\t\\label{chapter:singularities}\n\n\n\n% chapter singularities (end)\n\n\\chapter*{Answers}\\label{chapter:answers}\n\\addcontentsline{toc}{chapter}{Answers}\n\n\\fontsize{9}{11}\\selectfont\n\n\\section*{Chapter 1} % (fold)\n\\label{sec:chapter_1}\n\n\\subsection*{Basic Algebraic Properties} % (fold)\n\\label{sub:basic_algebraic_properties}\n\n(Jump to: \\cref{sec:basic_algebraic_properties})\n\n\\begin{enumerate}\n\t\\item \n\t\\item \\begin{enumerate}\n\t\t\\item $(0, 0), (1, 0), (-\\frac{1}{2} , \\pm \\sqrt{\\frac{3}{4}})$\n\t\t\\item $(0, 0), (1, 0), (-1, 0), (0, i), (0, -i)$\n\t\\end{enumerate}\n\t\\item \\begin{enumerate}\n\t\t\\item $(\\cos \\theta - i \\sin \\theta)^2$\n\t\t\\item \n\t\t\\item $\\frac{9 - 40i}{41}$\n\t\t\\item $2$\n\t\\end{enumerate}\n\t\\item \\begin{enumerate}\n\t\t\\item $\\{(x, y) : x^2 + y^2 \\leq 4\\}$\n\t\t\\item $\\{(x, y) : y > 0\\}$\n\t\t\\item $\\{(x, y) : x \\leq \\frac{1}{2} \\}$\n\t\t\\item $x^2 - y^2 = a$. Also, refer to this graph on Desmos: \\url{https://www.desmos.com/calculator/buwtyobjrn}\n\t\t\\item Refer to graph on Desmos: \\url{https://www.desmos.com/calculator/a3pnbwueja}\n\t\\end{enumerate}\n\t\\item \\begin{align*}\n\t\t\\left( \\frac{z_1}{z_3} \\right) \\left( \\frac{z_2}{z_4} \\right)\n\t\t\t&= z_1 \\left( \\frac{\\bar{z_3}}{\\abs{z_3}^2} \\right) z_2 \\left( \\frac{\\bar{z_4}}{\\abs{z_4}^2} \\right) \\quad \\text{since } z\\bar{z} = \\abs{z}^2 \\\\\n\t\t\t&= z_1 z_2 \\left( \\frac{\\bar{z_3} \\bar{z_4}}{\\abs{z_3}^2 \\abs{z_4}^2} \\right) \\\\\n\t\t\t&= z_1 z_2 \\left( \\frac{\\bar{z_3 z_4}}{\\abs{z_3 z_4}^2} \\right) \\quad \\text{since } \\bar{z}\\bar{w} = \\bar{zw} \\text{ and } \\abs{z}\\abs{w} = \\abs{zw} \\\\\n\t\t\t&= \\frac{z_1 z_2}{z_3 z_4} \\quad \\text{since } z\\bar{z} = \\abs{z}^2\n\t\\end{align*}\n\t\\item $\\frac{z_1 z}{z_2 z} = \\left( \\frac{z_1}{z_2} \\right) \\left(\\frac{z}{z} \\right) = \\frac{z_1}{z_2}$\n\t\\item By the Triangle Inequality,\n\t\\begin{equation*}\n\t\t\\abs{z_1} + \\abs{z_2} \\geq \\abs{z_1 + z_2} \\geq \\sqrt{\\re(z_1 + z_2)^2 + \\im(z_1 + z_2)^2} \\geq \\sqrt{\\re(z_1 + z_2)} = \\re(z_1 + z_2)\n\t\\end{equation*}\n\tand by the Reversed Triangle Inequality,\n\t\\begin{gather*}\n\t\t\\abs{z_3 + z_4} \\geq \\abs{\\abs{z_3} - \\abs{z_4}} \\\\\n\t\t\\implies \\frac{1}{\\abs{z_3 + z_4}} \\leq \\frac{1}{\\abs{\\abs{z_3} - \\abs{z_4}}} \n\t\\end{gather*}\n\tThus\n\t\\begin{equation*}\n\t\t\\frac{\\re(z_1 + z_2)}{\\abs{z_3 + z_4}} \\leq \\frac{\\abs{z_1} + \\abs{z_2}}{\\abs{z_3 + z_4}} \\leq \\frac{\\abs{z_1} + \\abs{z_2}}{\\abs{\\abs{z_3} - \\abs{z_4}}}\n\t\\end{equation*}\n\\end{enumerate}\n\n% subsection basic_algebraic_properties (end)\n\n% section chapter_1 (end)\n\n% chapter answers (end)\n\n\\end{document}", "meta": {"hexsha": "e0270f0fc1aff048fe0878e1a81d82af5a0d7ff6", "size": 10773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PMATH352W18/topical-exercises/topical-exercises.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": "PMATH352W18/topical-exercises/topical-exercises.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": "PMATH352W18/topical-exercises/topical-exercises.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": 32.0625, "max_line_length": 163, "alphanum_fraction": 0.6290726817, "num_tokens": 4411, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.880797068590724, "lm_q1q2_score": 0.758840332477099}}
{"text": "\n\\subsection{Exterior (Grassman) algebra}\n\nThe exterior algebra is the algebra generated by the wedge product.\n\nThe term \\(u\\land v\\) can be interpreted as the area covered by the parallelogram generated by \\(u\\) and \\(v\\).\n\nAs \\(a\\mathbf u\\land b\\mathbf v=ab \\mathbf u\\land \\mathbf v\\), we can see that scaling the length of one of the vectors by a scalar, we also increase the exterior product by the same scalar.\n\n\\subsection{Orientation}\n\nWe can describe the exterior product of two vectors as \\(\\mathbf u\\land \\mathbf v\\) or \\(\\mathbf v \\land \\mathbf u\\).\n\n", "meta": {"hexsha": "ac4142f3e37990411e834de4eaf186c3cf645f2f", "size": 562, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/geometry/exteriorAlgebra/01-02-exteriorAlgebra.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/exteriorAlgebra/01-02-exteriorAlgebra.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/exteriorAlgebra/01-02-exteriorAlgebra.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1428571429, "max_line_length": 190, "alphanum_fraction": 0.7384341637, "num_tokens": 151, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850128595114, "lm_q2_score": 0.8104789018037399, "lm_q1q2_score": 0.7588392489976773}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{pgfplots}\n\\usepackage{algorithm}\n\\usepackage{placeins}\n\\usepackage{algorithmic}\n\\usepackage{booktabs}\n\n\\begin{document}\n\n\\title{THE PERCEPTRON}\n\\date{}\n\\maketitle\n\nThe perceptron is a learning algorithm for binary classification of real valued vectors. \n\n\\section{Introduction}\n\nThe perceptron binary classifier can be thought of as the following function,\n\n\\begin{align*}\n\tf(\\boldsymbol{x}) = \\left\\{                       \n\t\\begin{array}{ll}                                 \n\t1\\ \\text{if}\\ \\boldsymbol{w}^T \\boldsymbol{x} > 0 \\\\\n\t0\\ \\text{otherwise}                               \\\\\n\t\\end{array}                                       \n\t\\right.                                           \n\\end{align*}\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-3,0) -- (3,0) node[right]{$x_1$};\n\t\t\\draw[-latex] (0,-2) -- (0,2) node[left]{$x_2$};\t\n\t\t\t\t\t\t\t\t\t\t\t    \n\t\t\\draw[dashed] (-1, 2) -- (1, -2);\n\t\t\\draw (1, -2) node [below right] {Separating Plane};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[very thick,->, >=stealth] (0, 0) -- (1, 0.5);\n\t\t\\draw (1, 0.5) node [above right] {$\\vec{\\boldsymbol{w}}$};  \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw (-0.1, -0.3) node [below left] {$f(\\boldsymbol{x}) < 0$};   \n\t\t\\draw (0.5, 0) node [below right] {$f(\\boldsymbol{x}) > 0$};   \t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\nOne severe limitation of this formulation is that the separating hyperplane always passes through origin which might be undesirable in many cases. However, this limitation can be overcome in the following way,\n\n\\begin{align*}\n\tf(\\boldsymbol{x}) = \\left\\{                           \n\t\\begin{array}{ll}                                     \n\t1\\ \\text{if}\\ \\boldsymbol{w}^T \\boldsymbol{x} + b > 0 \\\\\n\t0\\ \\text{otherwise}                                   \\\\\n\t\\end{array}                                           \n\t\\right.                                               \n\\end{align*}\n\nThe bias term $b$ frees the separating hyperplane from origin. Additionally, we can employ a trick to simplify the expression as follows.\n\n\\begin{align*}\n\tf(\\boldsymbol{x}) = \\left\\{                                                                    \n\t\\begin{array}{ll}                                                                              \n\t1\\ \\text{if}\\ \\begin{pmatrix} \\boldsymbol{w}^T, b \\end{pmatrix} \\begin{pmatrix} \\boldsymbol{x} \\\\ \n\t1 \\end{pmatrix} > 0                                                                            \\\\\n\t0\\ \\text{otherwise}                                                                            \\\\\n\t\\end{array}                                                                                    \n\t\\right.                                                                                        \n\\end{align*}\n\nHence, by increasing the dimension of input by one and defaulting the intercept on the new dimension to 1 for every input vector, any separating hyperplane in the old dimensional space \nbecomes a hyperplane passing through origin in the new dimensional space. This simplifies the mathematics without constraining the classifier.\n\nThe vector $\\vec{\\boldsymbol{w}}$ is learned from training data as usual. The algorithm for learning the same is presented in the next section. \n\n\\section{Learning Algorithm}\n\nThe training data consists of $N$ pairs of $d$-dimensional real input vectors $\\boldsymbol{x}_i$s and the output binary labels $y_i$s. For mathematical convenience, positive output labels are denoted by $+1$ and negative output labels by {-1}. \nThe learning algorithm makes the following assumptions:\n\n\\begin{itemize}\n\t\\item It is assumed that the input vectors have already been extended to account for the bias term.\n\t\\item The training data is assumed to be linearly separable at origin. So, there exists a unit vector $\\boldsymbol{w}^*$ such that $y_i\\boldsymbol{w}^{*T}\\boldsymbol{x_i} > \\gamma \\ \\ \\forall i \\ \\ \\text{where}\\ \\ \\gamma > 0$.\n\t\\item It is assumed that all training input vectors are finite.\n\\end{itemize} \n\nThe algorithm is defined as follows.\n\n\\begin{algorithm}\n\t\\renewcommand{\\thealgorithm}{}\n\t\\caption{The Perceptron Learning Algorithm}\n\t\\begin{algorithmic} \n\t\t\\STATE $k \\leftarrow 1$\n\t\t\\STATE $\\boldsymbol{w}_k \\leftarrow 0$\n\t\t\t\t\t\t\n\t\t\\WHILE {there exists $j \\in \\{1, 2, .., N\\}$ such that $ y_j\\boldsymbol{w}^{*T}\\boldsymbol{x_j} <= 0$ }\n\t\t\\STATE {pick $i \\in \\{1, 2, .., N\\}$ such that $ y_i\\boldsymbol{w}^{*T}\\boldsymbol{x_i} <= 0$}\n\t\t\\STATE $\\boldsymbol{w}_{k+1} \\leftarrow \\boldsymbol{w}_k + y_i \\boldsymbol{\\boldsymbol{x}_i}$\n\t\t\\STATE $ k \\leftarrow k + 1$\n\t\t\\ENDWHILE\n\t\t\\RETURN $\\boldsymbol{w}_k$\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Example}\n\nThe algorithm is illustrated on a very simple example.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-4,0) -- (4,0) node[right]{$x_1$};\n\t\t\\draw[-latex] (0,-3) -- (0,3) node[left]{$x_2$};\n\t\t\t\t\t\t\t\t\t\n\t\t\\draw[help lines] (-3.5,-2.5) grid (3.5,2.5);\n\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.7,0) -- (-2.3,0);\n\t\t\\draw[point line] (-0.3,-2) -- (0.3,-2);      \n\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.7,2) -- (-2.3,2);\n\t\t\\draw[point line] (-2,1.7) -- (-2,2.3);  \n\t\t\t\t\t\t\n\t\t\\draw[point line] (1.7,2) -- (2.3,2);\n\t\t\\draw[point line] (2,1.7) -- (2,2.3); \t\n\t\t\t\t\t\t\n\t\t\\draw (-2, 2) node [below right] {(-2, 2)};\n\t\t\\draw (2, 2) node [below left] {(2, 2)};\n\t\t\\draw (-2, 0) node [below right] {(-2, 0)};\n\t\t\\draw (0, -2) node [below right] {(0, -2)};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\FloatBarrier\n\n\\subsection{Iteration 1}\n\n\\begin{align*}\n\t\\boldsymbol{w}_1 = \\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix}\n\\end{align*}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\toprule\n\t\t$\\boldsymbol{x}$    \\\\\n\t\t\\midrule\n\t\t$\\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}$ & -1 & 0 \\\\\n\t\t$\\begin{pmatrix} 0  \\\\ -2 \\end{pmatrix}$ & -1 & 0 \\\\\n\t\t$\\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}$ & 1 & 0 \\\\\n\t\t$\\begin{pmatrix} 2  \\\\ 2 \\end{pmatrix}$ & 1 & 0 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\subsection{Iteration 2}\n\n\\begin{align*}\n\t\\boldsymbol{w}_2 & = \\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix} + (-1)  \\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix} 2 \\\\ 0 \\end{pmatrix}\n\\end{align*}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\toprule\n\t\t$\\boldsymbol{x}$    \\\\\n\t\t\\midrule\n\t\t$\\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}$ & -1 & 4 \\\\\n\t\t$\\begin{pmatrix} 0  \\\\ -2 \\end{pmatrix}$ & -1 & 0 \\\\\n\t\t$\\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}$ & 1 & -4 \\\\\n\t\t$\\begin{pmatrix} 2  \\\\ 2 \\end{pmatrix}$ & 1 & 4 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\FloatBarrier\n\n\\subsection{Iteration 3}\n\n\\begin{align*}\n\t\\boldsymbol{w}_3 & = \\begin{pmatrix} 2 \\\\ 0 \\end{pmatrix} + (-1)  \\begin{pmatrix} 0 \\\\ -2 \\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix} 2 \\\\ 2 \\end{pmatrix}\n\\end{align*}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\toprule\n\t\t$\\boldsymbol{x}$    \\\\\n\t\t\\midrule\n\t\t$\\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}$ & -1 & 4 \\\\\n\t\t$\\begin{pmatrix} 0  \\\\ -2 \\end{pmatrix}$ & -1 & 4 \\\\\n\t\t$\\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}$ & 1 & 0 \\\\\n\t\t$\\begin{pmatrix} 2  \\\\ 2 \\end{pmatrix}$ & 1 & 8 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\FloatBarrier\n\n\\subsection{Iteration 4}\n\n\\begin{align*}\n\t\\boldsymbol{w}_4 & = \\begin{pmatrix} 2 \\\\ 2 \\end{pmatrix} + (1)  \\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix} 0 \\\\ 4 \\end{pmatrix}\n\\end{align*}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\toprule\n\t\t$\\boldsymbol{x}$    \\\\\n\t\t\\midrule\n\t\t$\\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}$ & -1 & 0 \\\\\n\t\t$\\begin{pmatrix} 0  \\\\ -2 \\end{pmatrix}$ & -1 & 8 \\\\\n\t\t$\\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}$ & 1 & 8 \\\\\n\t\t$\\begin{pmatrix} 2  \\\\ 2 \\end{pmatrix}$ & 1 & 8 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\FloatBarrier\n\n\\subsection{Iteration 5}\n\n\\begin{align*}\n\t\\boldsymbol{w}_5 & = \\begin{pmatrix} 0 \\\\ 4 \\end{pmatrix} + (-1)  \\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}  \\\\\n\t                 & = \\begin{pmatrix} 2 \\\\ 4 \\end{pmatrix}\n\\end{align*}\n\n\\begin{table}[htbp]\n\t\\centering\n\t\\begin{tabular}{|c|c|c|}\n\t\t\\toprule\n\t\t$\\boldsymbol{x}$    \\\\\n\t\t\\midrule\n\t\t$\\begin{pmatrix} -2 \\\\ 0 \\end{pmatrix}$ & -1 & 4 \\\\\n\t\t$\\begin{pmatrix} 0  \\\\ -2 \\end{pmatrix}$ & -1 & 8 \\\\\n\t\t$\\begin{pmatrix} -2 \\\\ 2 \\end{pmatrix}$ & 1 & 4 \\\\\n\t\t$\\begin{pmatrix} 2  \\\\ 2 \\end{pmatrix}$ & 1 & 12 \\\\\n\t\t\\hline\n\t\\end{tabular}\n\\end{table}\n\n\\FloatBarrier\n\nAll the points are correctly classified, hence the algorithm terminates. The algorithm converged in 5 iterations. In fact, as will be proved later, the algorithm is always guaranteed to converge in finite iterations.The resulting separating hyperplanes is shown below.\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\tikzstyle {point line} = [line width=0.15em]\n\t\t\t\t\t\t\t\t    \n\t\t\\draw[-latex] (-5,0) -- (5,0) node[right]{$x_1$};\n\t\t\\draw[-latex] (0,-5) -- (0,5) node[left]{$x_2$};\n\t\t\t\t\t\t\t\t\t\n\t\t\\draw[help lines] (-4.5,-4.5) grid (4.5,4.5);\n\t\t\t\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.7,0) -- (-2.3,0);\n\t\t\\draw[point line] (-0.3,-2) -- (0.3,-2);      \n\t\t\t\t\t\t\n\t\t\\draw[point line] (-1.7,2) -- (-2.3,2);\n\t\t\\draw[point line] (-2,1.7) -- (-2,2.3);  \n\t\t\t\t\t\t\n\t\t\\draw[point line] (1.7,2) -- (2.3,2);\n\t\t\\draw[point line] (2,1.7) -- (2,2.3); \t\n\t\t\t\t\t\t\n\t\t\\draw (-2, 2) node [below right] {(-2, 2)};\n\t\t\\draw (2, 2) node [below left] {(2, 2)};\n\t\t\\draw (-2, 0) node [below right] {(-2, 0)};\n\t\t\\draw (0, -2) node [below right] {(0, -2)};\n\t\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw [dashed] (-4, 2) -- (4, -2);\n\t\t\\draw (4, -2) node [below right] {Separating Plane};   \n\t\t\t\t\t\t\t\t\t\t\n\t\t\\draw[very thick,->, >=stealth] (0, 0) -- (2, 4);\n\t\t\\draw (2, 4) node [above right] {$\\vec{\\boldsymbol{w}_5}$};  \n\t\t\t\t\t\t\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\FloatBarrier\n\n\\section{Proof of Convergence}\n\nThe intention is to show that the perceptron learning algorithm always converges to a perfect classifier in finite iterations given that all the assumptions that the algorithm makes are met.\n\n \nAssume that after k+1 iterations, $\\vec{\\boldsymbol{w}_{k+1}}$ makes an angle $\\theta_{k+1}$ with $\\vec{\\boldsymbol{w}^*}$. \n \n\\begin{align*}\n\tcos(\\theta_{k+1}) = \\frac{\\vec{\\boldsymbol{w}_{k+1}}.\\vec{\\boldsymbol{w}^*}}{|\\vec{\\boldsymbol{w}_{k+1}}|\\ |\\vec{\\boldsymbol{w}^*}|} \n\\end{align*}\n \nSince $\\vec{\\boldsymbol{w}^*}$ is a unit vector,\n \n\\begin{align*}\n\tcos(\\theta_{k+1}) = \\frac{\\vec{\\boldsymbol{w}_{k+1}}.\\vec{\\boldsymbol{w}^*}}{|\\vec{\\boldsymbol{w}_{k+1}}|} \n\\end{align*}\n \nNow, bounds for numerator and denominator are established to proceed ahead.\n \n\\subsection{Bound for numerator}\n \nThe update rule for $\\vec{\\boldsymbol{w}_{k+1}}$ is,\n \n\\begin{align*}\n\t\\vec{\\boldsymbol{w}_{k+1}} = \\vec{\\boldsymbol{w}_k} + y_i \\vec{\\boldsymbol{\\boldsymbol{x}_i}} \n\\end{align*}\n \nTaking dot product with $\\vec{\\boldsymbol{w}^*}$ on both sides.\n \n\\begin{align*}\n\t\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k+1}} = \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_k} + y_i \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{\\boldsymbol{x}_i}} \n\\end{align*} \n \nSince $y_i \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{\\boldsymbol{x}_i}} > \\gamma$ as per the algorithm assumption.\n \n\\begin{align*}\n\t\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k+1}} > \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_k} + \\gamma      \\\\\n\t\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k+1}} > \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k-1}} + 2\\gamma \\\\\n\t\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k+1}} > \\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{1}} + k\\gamma   \n\\end{align*}   \n \nsince $\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{1}} = 0$.\n\n \n\\begin{align*}\n\t\\vec{\\boldsymbol{w}^*}.\\vec{\\boldsymbol{w}_{k+1}} >  k\\gamma \n\\end{align*}  \n \n\\subsection{Bound for denominator}\n \nAgain starting with the update rule for $\\vec{\\boldsymbol{w}_{k+1}}$,\n \n\\begin{align*}\n\t\\vec{\\boldsymbol{w}_{k+1}} = \\vec{\\boldsymbol{w}_k} + y_i \\vec{\\boldsymbol{\\boldsymbol{x}_i}} \n\\end{align*}\n \nTaking modulus on both sides,\n \n\\begin{align*}\n\t|\\vec{\\boldsymbol{w}_{k+1}}|^2 = |\\vec{\\boldsymbol{w}_k}|^2 + |y_i \\vec{\\boldsymbol{\\boldsymbol{x}_i}}|^2 + 2y_i \\vec{\\boldsymbol{w}_k}.\\vec{\\boldsymbol{\\boldsymbol{x}_i}} \n\\end{align*}\n \nSince $y_i \\vec{\\boldsymbol{w}_k}.\\vec{\\boldsymbol{\\boldsymbol{x}_i}} <= 0$ according to the algorithm specification.\n\n\\begin{align*}\n\t|\\vec{\\boldsymbol{w}_{k+1}}|^2 \\leq |\\vec{\\boldsymbol{w}_k}|^2 + |y_i \\vec{\\boldsymbol{\\boldsymbol{x}_i}}|^2 \n\\end{align*}\n \nAssuming that the largest input vector has length $R$.\n \n\\begin{align*}\n\t|\\vec{\\boldsymbol{w}_{k+1}}|^2 \\leq |\\vec{\\boldsymbol{w}_k}|^2 + R^2      \\\\\n\t|\\vec{\\boldsymbol{w}_{k+1}}|^2 \\leq |\\vec{\\boldsymbol{w}_{k-1}}|^2 + 2R^2 \\\\\n\t|\\vec{\\boldsymbol{w}_{k+1}}|^2 \\leq kR^2                                  \\\\\n\t|\\vec{\\boldsymbol{w}_{k+1}}| \\leq \\sqrt{k}R                               \n\\end{align*}\n \n\\subsection{Bound for Number of Iterations}\n \nUsing both the numerator and denominator bounds,\n\n\\begin{align*}\n\tcos(\\theta_{k+1}) > \\frac{k\\gamma}{\\sqrt{k}R} \\\\\n\tcos(\\theta_{k+1}) > \\sqrt{k} \\frac{\\gamma}{R} \n\\end{align*}\n \nThis shows that after each iteration, the lower bound of the angle between $\\vec{\\boldsymbol{w}} $ and $\\vec{\\boldsymbol{w}^*}$ increases. And since $cos(\\theta_{k+1})$ can never be greater than one, $\\sqrt{k} \\frac{\\gamma}{R} \\leq1$ must hold true yielding $k \\leq \\frac{R^2}{\\gamma^2}$.\n\n\\section{Conclusion}\n\nThe perceptron was one of the first algorithms indicating that computers could learn from data. And today, after half a century, it continues to be the basis of Artificial Neural Networks which are at the forefront of Artificial Intelligence. \n\n\\end{document}", "meta": {"hexsha": "244f71ebcef5c209cb82021766ae7c6a9d5a9662", "size": 13614, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "The Perceptron/The Perceptron.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": "The Perceptron/The Perceptron.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": "The Perceptron/The Perceptron.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": 35.7322834646, "max_line_length": 288, "alphanum_fraction": 0.5810195387, "num_tokens": 4860, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.8438951025545426, "lm_q1q2_score": 0.758764133723685}}
{"text": "\\textbf{Compute te solution to the systems for the given initial conditions using \\texttt{rk4.m}. Plot your results in the phase plane.}\n\\vskip.00005in\n\\noindent\\rule{\\textwidth}{1pt}\n\\vspace{0.1in}\n\\begin{enumerate}\n\\item[1.] \\textbf{Using initial data conditions with $x(0)^2+y(0)^2$ both smaller and larger than $1$, solve}\n\\begin{align*}\nx'(t)&=-4y+x(1-x^2-y^2),\\\\\ny'(t)&=4x+y(1-x^2-y^2),\n\\end{align*}\n\\textbf{over the interval $0\\leq t\\leq 10$}.\nGiven the system of ODEs, we see that when at the unit circle the parenthesis of the right hand side vanishes. Moreover, if we express the ODEs in polar coordinates, we see that, at the unit circle, we obtain $dr=0$ and $d\\theta=4$. This implies that the orbits, once they reach the unit circle, the stay indefinitely there since $dr=0$ and moving counterclockwise since $d\\theta=4$. Inside the unit circle the vector field is divergent, it points away from the origin. This implies that the orbits are gonna approach the unit circle if we place the initial condition inside it. We have the inverse situation outside the unit circle. Thus, the unit circle constitutes an $\\omega-limit$ set of this system of ODEs. In the next figure we can see the behaviour described and the vector field.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Vector field]{\\includegraphics[scale=0.75]{P1_1field.eps}}\n\\hspace*{\\fill}\n\\subfigure[Orbits]{\\includegraphics[scale=0.75]{P1_1.eps}}\n\\hspace*{\\fill}\n\\caption{Solutions of the system of ODEs.}\n\\end{figure}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 1a\nlegendfontsize=14;\naxisfontsize=16;\n\nF = @(t,V) [-4*V(2)+V(1).*(1-V(1).^2-V(2).^2);...\n                4*V(1)+V(2).*(1-V(1).^2-V(2).^2)];\ntheta=pi/4;\nR=[0.1; 2.4];\ntspan=[0 10];\n\nN=300;\na=2.5;\nfor i=1:length(R)\n    V0 = [R(i)*cos(theta); R(i)*sin(theta)];\n    [t,V] = rk4(F,tspan,V0,N);\n    figure(1)\n    l(1)=plot(V(:,1),V(:,2),'r');\n    hold on\n    l(2)=plot(V0(1),V0(2),'r*');\n    axis([-a a -a a])\n    grid on\nend\n% Plot orbits\nfigure(1)\nhold on\nl(3)=plot(cos(0:0.001:2*pi),sin(0:0.001:2*pi),'--b');\nxlabel('$x(t)$','interpreter','latex')\nylabel('$y(t)$','interpreter','latex')\npbaspect([1 1 1])\nset(gca,'fontsize',14)\nlegend([l(1) l(2) l(3)],{' Orbits',' Initial condtions',' Limit circle'},...\n 'Interpreter','latex','fontsize',legendfontsize,'location','SouthEast')\ntxt='Latex/FIGURES/P1_1';\nsaveas(gcf,txt,'epsc')\n\n% Plot vector field\nstep=0.2;\n[x,y] = meshgrid(-a:step:a,-a:step:a);\nu=-4*y+x.*(1-x.^2-y.^2);\nv=4*x+y.*(1-x.^2-y.^2);\nfigure(2)\nq=quiver(x,y,u,v,'r');\nhold on\nplot(cos(0:0.001:2*pi),sin(0:0.001:2*pi),'--b');\nxlabel('$x(t)$','interpreter','latex')\nylabel('$y(t)$','interpreter','latex')\npbaspect([1 1 1])\naxis([-a a -a a])\nset(gca,'fontsize',14)\nset(q,'AutoScale','on', 'AutoScaleFactor', 1.5)\ntxt='Latex/FIGURES/P1_1field';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}\n\\item[2.] \\textbf{Using initial data conditions with $x(0)^2+y(0)^2$ both inside and outside of the circles of radius $1$ and $2$, solve}\n\\begin{align*}\nx'(t)&=-4y+x(1-x^2-y^2)(4-x^2-y^2),\\\\\ny'(t)&=4x+y(1-x^2-y^2)(4-x^2-y^2),\n\\end{align*}\n\\textbf{over the interval $0\\leq t\\leq 10$}.\n\nGiven the system of ODEs, we see that when at the unit circle or at the circle of radius $2$, the second term of the right hand side cancels in both ODEs. This give us the same condition as before, once the orbits reach those circles, they stay there indefinitely. However, the addition of the extra factor makes the vector field divergent outside the outer circle, and changes the behaviour of the system. If the initial condition is outside the outter circl, the solutions are unstable. We can see the vector field and the orbits of the solutions in the next figure. Note that the initial conditions outisde the circle of radius $2$ are placed just very close to the limit.\n\\begin{figure}[H]\n\\centering     %%% not \\center\n\\hspace*{\\fill}\n\\subfigure[Vector field]{\\includegraphics[scale=0.75]{P1_2field.eps}}\n\\hspace*{\\fill}\n\\subfigure[Orbits]{\\includegraphics[scale=0.75]{P1_2.eps}}\n\\hspace*{\\fill}\n\\caption{Solutions of the system of ODEs.}\n\\end{figure}\n\\end{enumerate}\n\\subsection*{Matlab code for this problem}\n\\begin{verbatim}\n%% Problem 1b\nclose all\nF = @(t,V) [-4*V(2)+V(1).*(1-V(1).^2-V(2).^2).*(4-V(1).^2-V(2).^2);...\n                4*V(1)+V(2).*(1-V(1).^2-V(2).^2).*(4-V(1).^2-V(2).^2)];\ntheta=pi/5;\nR=[0.1; 1.2; 1.8];\ntspan=[0 10];\nN=300;\na=3;\nfor i=1:length(R)\n    V0 = [R(i)*cos(theta); R(i)*sin(theta)];\n    [t,V] = rk4(F,tspan,V0,N);\n    figure(1)\n    plot(V(:,1),V(:,2),'r')\n    hold on\n    plot(V0(1),V0(2),'r*')\n    axis([-a a -a a])\n    grid on\nend\nTheta=0:pi/4:2*pi;\nfor i=1:length(Theta)\n    V0 = [2*cos(Theta(i)); 2*sin(Theta(i))];\n    [t,V] = rk4(F,[0 1],V0,N);\n    figure(1)\n    l(1)=plot(V(:,1),V(:,2),'r');\n    hold on\n    l(2)=plot(V0(1),V0(2),'r*');\n    axis([-a a -a a])\n    grid on\nend\n\nfigure(1)\nhold on\nl(3)=plot(cos(0:0.001:2*pi),sin(0:0.001:2*pi),'--b');\nplot(2*cos(0:0.001:2*pi),2*sin(0:0.001:2*pi),'--b');\nxlabel('$x(t)$','interpreter','latex')\nylabel('$y(t)$','interpreter','latex')\npbaspect([1 1 1])\nset(gca,'fontsize',14)\n%legend([l(1) l(2) l(3)],{' Orbits',' Initial condtions',' Limit circle'},...\n% 'Interpreter','latex','fontsize',legendfontsize,'location','SouthEast')\ntxt='Latex/FIGURES/P1_2';\nsaveas(gcf,txt,'epsc')\n\n% Plot vector field\nstep=0.1;\nb=2;\n[x,y] = meshgrid(-b:step:b,-b:step:b);\nu=-4*y+x.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\nv=4*x+y.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\nfigure(2)\nq=quiver(x,y,u,v,'r');\nset(q,'AutoScale','on', 'AutoScaleFactor', 3)\nhold on\n% step=0.1;\n% b=2.1;\n% [x,y] = meshgrid(-b:step:b,-b:step:b);\n% u=-4*y+x.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\n% v=4*x+y.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\n% q=quiver(x,y,u,v,'r');\n% step=0.05;\n% b=1.2;\n% [x,y] = meshgrid(-b:step:b,-b:step:b);\n% u=-4*y+x.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\n% v=4*x+y.*(1-x.^2-y.^2).*(4-x.^2-y.^2);\n% q=quiver(x,y,u,v,'r');\n% set(q,'AutoScale','on', 'AutoScaleFactor', 0.5)\nplot(cos(0:0.001:2*pi),sin(0:0.001:2*pi),'--b');\nplot(2*cos(0:0.001:2*pi),2*sin(0:0.001:2*pi),'--b');\nxlabel('$x(t)$','interpreter','latex')\nylabel('$y(t)$','interpreter','latex')\npbaspect([1 1 1])\ngrid on\na=2.1;\naxis([-a a -a a])\nset(gca,'fontsize',14)\ntxt='Latex/FIGURES/P1_2field';\nsaveas(gcf,txt,'epsc')\n\\end{verbatim}", "meta": {"hexsha": "269365660797cc266353dbab042d76c6254f82df", "size": 6286, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem1.tex", "max_stars_repo_name": "fjcasti1/Courses", "max_stars_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem1.tex", "max_issues_repo_name": "fjcasti1/Courses", "max_issues_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Year_1/ComputationalMethods/Homework 5/Latex/problem1.tex", "max_forks_repo_name": "fjcasti1/Courses", "max_forks_repo_head_hexsha": "12ab3e86a4a44270877e09715eeab713da45519d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.92, "max_line_length": 789, "alphanum_fraction": 0.6331530385, "num_tokens": 2357, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8991213847035617, "lm_q1q2_score": 0.7587641260934151}}
{"text": "\\documentclass[a4paper]{scrartcl}\n\\usepackage[english]{babel}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amssymb,amsmath}\n\n\\newtheorem{theorem}{Theorem}\n\\newenvironment{proof}{\\paragraph{Proof:}}{\\hfill$\\square$}\n\\newcommand{\\Prob}{\\mathbb{P}}\n\n\\begin{document}\n    \\begin{theorem}\n    Let $Y \\sim \\mathcal{N}(\\mu, \\sigma^2)$ and $X \\sim e^Y$.\n    Then X has the density\n    \\[f_X(x) = \\begin{cases} \\frac{1}{x \\sigma \\sqrt{2 \\pi}}\\exp{- \\frac{(\\log x - \\mu)^2}{2 \\sigma^2}} &\\text{if } x > 0\\\\\n                             0 & \\text{otherwise}\\end{cases}\\]\n    \\end{theorem}\n\n\n    \\begin{proof}\n    \\begin{align}\n        \\Prob(X \\leq t) &= \\Prob(e^Y \\leq t)\\\\\n                        &= \\begin{cases}\\Prob(Y \\leq \\log(t)) &\\text{if } x > 0\\\\\n                                        0 &\\text{otherwise}\n                           \\end{cases}\n    \\end{align}\n\n    Obviously, the density $f_X(x) = 0$ for $x \\leq 0$. Now continue with\n    $t > 0$:\n\n    \\begin{align}\n        \\Prob(X \\leq t) &= \\Prob(Y \\leq \\log(t))\\\\\n                        &= \\Phi_{\\mu, \\sigma^2}(\\log(t))\\\\\n                        &= \\Phi_{0, 1} \\left (\\frac{\\log(t) - \\mu}{\\sigma} \\right)\\\\\n        f_X(x) &= \\frac{\\partial}{\\partial x} \\Phi_{0, 1} \\left (\\frac{\\log(x) - \\mu}{\\sigma} \\right)\\\\\n               &= \\left (\\frac{\\partial}{\\partial x} \\left (\\frac{\\log(x) - \\mu}{\\sigma} \\right) \\right) \\cdot \\varphi_{0, 1} \\left (\\frac{\\log(x) - \\mu}{\\sigma} \\right)\\\\\n               &= \\left (\\frac{\\sigma \\cdot \\frac{1}{x}}{\\sigma^2} \\right) \\cdot \\varphi_{0, 1} \\left (\\frac{\\log(x) - \\mu}{\\sigma} \\right)\\\\\n               &= \\frac{1}{x \\sigma} \\cdot \\varphi_{0, 1} \\left (\\frac{\\log(x) - \\mu}{\\sigma} \\right)\\\\\n               &= \\frac{1}{x \\sigma} \\cdot \\frac{1}{\\sqrt{2\\pi}} \\exp \\left (-\\frac{1}{2} \\cdot {\\left(\\frac{\\log(x) - \\mu}{\\sigma} \\right )}^2 \\right )\n    \\end{align}\n    \\end{proof}\n\\end{document}\n", "meta": {"hexsha": "2a005d7d7f351c1d93d14a4b3b16d59943bf8c54", "size": 1879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/prove-transform-random-variable-theorem/prove-transform-random-variable-theorem.tex", "max_stars_repo_name": "RalfGuder/LaTeX-examples", "max_stars_repo_head_hexsha": "a1bf9fe422969be1ca4674394ebd2170c07f7693", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1231, "max_stars_repo_stars_event_min_datetime": "2015-01-07T04:04:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T17:43:29.000Z", "max_issues_repo_path": "documents/prove-transform-random-variable-theorem/prove-transform-random-variable-theorem.tex", "max_issues_repo_name": "DoubleL61/LaTeX-examples", "max_issues_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2015-05-10T13:10:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-02T21:28:49.000Z", "max_forks_repo_path": "documents/prove-transform-random-variable-theorem/prove-transform-random-variable-theorem.tex", "max_forks_repo_name": "DoubleL61/LaTeX-examples", "max_forks_repo_head_hexsha": "cd0d97f85fadb59b7c6e9062b37a8bf7d725ba0c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 400, "max_forks_repo_forks_event_min_datetime": "2015-01-05T06:22:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T04:07:59.000Z", "avg_line_length": 44.7380952381, "max_line_length": 171, "alphanum_fraction": 0.500266099, "num_tokens": 691, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213691605411, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7587641218017104}}
{"text": "\\subsubsection{Improper Fractions}\r\n\\noindent\r\nIf the degree of the numerator is greater than or equal to the degree of the denominator, we have a case of improper fractions.\r\nIn this case, we have to do polynomial long division to get a quotient and remainder and then decompose the remainder if necessary.\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{P(x)}{Q(x)} = R(x) + \\frac{S(x)}{Q(x)}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the partial fraction decomposition of the following expression:\r\n\t\\begin{equation*}\r\n\t\t\\frac{x^3+3}{x^2-2x-3}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nFirst we do polynomial long division to find that\r\n\\begin{equation*}\r\n\t\\frac{x^3+3}{x^2-2x-3} = x + 2 + \\frac{7x+9}{x^2-2x-3}.\r\n\\end{equation*}\r\nNow that the numerator is of a lesser degree than the denominator, we can decompose it normally.\r\n\\begin{equation*}\r\n\tx^2-2x-3 = (x-3)(x+1).\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{7x+9}{x^2-2x-3} = \\frac{A_1}{x-3} + \\frac{A_2}{x+1}.\r\n\\end{equation*}\r\nMultiplying each side by the denominator,\r\n\\begin{equation*}\r\n\t7x+9 = A_1(x+1) + A_2(x-3).\r\n\\end{equation*}\r\nAt $x=-1$,\r\n\\begin{equation*}\r\n\t2 = -4A_2 \\implies A_2 = \\frac{-1}{2}.\r\n\\end{equation*}\r\nAt $x=3$,\r\n\\begin{equation*}\r\n\t30 = 4A_1 \\implies A_1 = \\frac{15}{2}.\r\n\\end{equation*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\frac{x^3+3}{x^2-2x-3} = x + 2 + \\frac{15/2}{x-3} + \\frac{-1/2}{x+1}.\r\n\\end{equation*}", "meta": {"hexsha": "d0aaa13fe7c6e821546b815b04229a5ea3ec9610", "size": 1382, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "common/algebraPreCalc/improperFractions.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "common/algebraPreCalc/improperFractions.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "common/algebraPreCalc/improperFractions.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": 31.4090909091, "max_line_length": 132, "alphanum_fraction": 0.6534008683, "num_tokens": 541, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7587526041767289}}
{"text": "%!TEX root = main.tex\n\\section{Deliverable 1}\n\\label{sec:deliverable-1}\n\n\\subsection{Math Equations}\nFor example, one can type the following equation:\n\\begin{equation}\n\\vt^W = \\MR_r^W \\vt^r = \\left[\\begin{array}{ccc}\n1 & 0 & 0 \\\\\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{array} \\right]\n\\left[\\begin{array}{c}\n1\\\\\n1 \\\\\n1\n\\end{array} \\right]\n= \n\\left[\\begin{array}{c}\n1\\\\\n1 \\\\\n1\n\\end{array} \\right].\n\\end{equation}\n\nLater in the course, you may want to type an optimization problem:\n\\begin{eqnarray}\nf^\\star = \\min_{\\vxx \\in \\mathbb{R}^n} & f(\\vxx), \\label{eq:optimization}\\\\\n\\text{subject to}  & \\vxx \\in \\calX,\n\\end{eqnarray}\nand refer to this optimization as problem~\\eqref{eq:optimization}. For mathematical symbols, it is suggested that you define shortcuts to commonly used symbols and formats.\n\n\\subsection{Lists}\nYou may also make your answers more organized by using \\emph{bulleted list}:\n\\begin{itemize}\n\t\\item Observation 1 ...\n\t\\item Observation 2 ...\n\\end{itemize}\nand \\emph{numbered list}:\n\\begin{enumerate}\n\t\\item Observation 1 ...\n\t\\item Observation 2 ...\n\\end{enumerate}\n\n\\subsection{Citations}\nYou can make a citation to a paper by~\\cite{horn87josa-registration}.\n\n\\subsection{Figures}\nYou can also include a plot in Fig.~\\ref{fig:simplefig}.\n\n\\input{fig-simplefig}", "meta": {"hexsha": "ead4fcc1d7782717954d29366b78b30084c2d836", "size": 1268, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "VNA2V_lab_latex_template/deliverable-1.tex", "max_stars_repo_name": "StevenHong/LaTeX-Workshop", "max_stars_repo_head_hexsha": "a3bbe3309d3d5bf87673341d045630e9d34659b4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "VNA2V_lab_latex_template/deliverable-1.tex", "max_issues_repo_name": "StevenHong/LaTeX-Workshop", "max_issues_repo_head_hexsha": "a3bbe3309d3d5bf87673341d045630e9d34659b4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "VNA2V_lab_latex_template/deliverable-1.tex", "max_forks_repo_name": "StevenHong/LaTeX-Workshop", "max_forks_repo_head_hexsha": "a3bbe3309d3d5bf87673341d045630e9d34659b4", "max_forks_repo_licenses": ["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.862745098, "max_line_length": 172, "alphanum_fraction": 0.7058359621, "num_tokens": 419, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637612961505, "lm_q2_score": 0.8824278664544911, "lm_q1q2_score": 0.7585912587488051}}
{"text": "\\section{Evaluation}\n\\label{sec:Evaluation}\nThis section contains the evaluation and the graphical representation of the measurements.\n\n\\subsection{Measuring the Magnetic Surface}\n\\label{subsec:Measuring_the_Magnetic_Surface}\nThe magnetic flux density was measured over a distance of about 1 m along the z-axis. The gaussmeter was zeroed at the position $z=0.6$ m. A measurement was taken every 8 cm.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1]{Magnetic_Surface}\n\t\\caption{Magnetic Surface}\n\t\\label{fig:Magnetic_Surface}\n\\end{figure}\nThe red line in figure \\ref{fig:Magnetic_Surface} shows the 4th order polynomial fit. A polynomial fit is able to represent the missing parts accurately, because the magnetic flux density can not jump. Every measuring point has the uncertainty of 0.3 \\% (gaussmeter and Hall sensor) drawn in blue. Since the uncertainty is extremely small, it is almost impossible to see it. The measured values are generally very small and are therefore not used for compensation.\n\nThe resulting parameters of the 4th order polynomial fit are shown in the following table:\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r|c|c|c|c|c}\n\t\t& \\textbf{a}$_0$ & \\textbf{a}$_1$ & \\textbf{a}$_2$ & \\textbf{a}$_3$ & \\textbf{a}$_4$ \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Value} & $2.031\\cdot 10^{-5}$ & $-8.534\\cdot 10^{-5}$ & $1.261\\cdot 10^{-4}$ & $-7.747\\cdot 10^{-5}$ & $1.702\\cdot 10^{-5}$ \\\\\n\t\\end{tabular}\n\t\\caption{Polynomial Parameters}\n\t\\label{tab:Polynomial_Parameters}\n\\end{table}\nUsing the polynomial parameters from the table \\ref{tab:Polynomial_Parameters} above, the magnetic flux density of the surface $B_z$ at a certain position $z$ can be calculated with the following equation:\n\\[\nB_z(z)=a_0+a_1z+a_2z^2+a_3z^3+a_4z^4\n\\]\n\n\\subsection{Measuring the Central Value $B_0(I)$}\n\\label{subsec:Measuring_the_Central_Value}\nThe magnetic flux density in the center of the cylindrical coil was measured in function of the current. The current ranges from 0 A to 1 A and the step size was chosen randomly.\n\\subsubsection{Short Cylindrical Coil}\n\\label{subsubsec:Short_Cylindrical_Coil}\nThe measured values are listed in appendix \\ref{sec:Measurements}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1]{Central_Value_Short}\n\t\\caption{Central Value Short Cylindrical Coil}\n\t\\label{fig:Central_Value_Short}\n\\end{figure}\nThe red fitted curve was creating by utilizing equation \\ref{eq:cylindrical_coil_b0}. All parameters except the vacuum permeability $\\mu_0$ were set to their according values and marked as constants. As seen in figure \\ref{fig:Central_Value_Short} above, the magnetic flux density $B_0$ is proportional to the applied current $I$. The absolute error (shown in blue) of 0.3 \\% is smaller than the size of a single data point and thus hard to see. The parameters of the fitted curve are listed in the following table:\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r|l}\n\t\t& \\textbf{Value} \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Vacuum Permeability} $\\mu_0$ & $(1.25396\\pm0.00019)\\cdot10^{-6}$\\ $\\,^\\text{Vs}\\!/_\\text{Am}$ \\\\\n\t\t\\textbf{Windings} $N$ & 240 (constant) \\\\\n\t\t\\textbf{Radius} $R$ & 0.0485 m (constant) \\\\\n\t\t\\textbf{Length} $l$ & 0.1 m (constant) \\\\\n\t\\end{tabular}\n\t\\caption{Fit Parameters (Central Value Short Cylindrical Coil)}\n\t\\label{tab:Central_Value_Short}\n\\end{table}\n\\subsubsection{Long Cylindrical Coil}\n\\label{subsubsec:Long_Cylindrical_Coil}\nThese measurements are also listed in appendix \\ref{sec:Measurements}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1]{Central_Value_Long}\n\t\\caption{Central Value Long Cylindrical Coil}\n\t\\label{fig:Central_Value_Long}\n\\end{figure}\nThe red fitted curve was again creating by utilizing equation \\ref{eq:cylindrical_coil_b0}. The plot with the fit was created the same way as in section \\ref{subsubsec:Short_Cylindrical_Coil}. The absolute error (shown in blue) of 0.3 \\% is again smaller than the size of a single data point. The parameters of the fitted curve are listed in the following table:\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r|l}\n\t\t& \\textbf{Value} \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Vacuum Permeability} $\\mu_0$ & $(1.24853\\pm0.00016)\\cdot10^{-6}$\\ $\\,^\\text{Vs}\\!/_\\text{Am}$ \\\\\n\t\t\\textbf{Windings} $N$ & 240 (constant) \\\\\n\t\t\\textbf{Radius} $R$ & 0.049 m (constant) \\\\\n\t\t\\textbf{Length} $l$ & 0.2 m (constant) \\\\\n\t\\end{tabular}\n\t\\caption{Fit Parameters (Central Value Long Cylindrical Coil)}\n\t\\label{tab:Central_Value_Long}\n\\end{table}\n\\newpage\n\\subsection{Measuring the Field Pattern $B_z(z)$}\n\\label{subsec:Measuring_the_Field_Pattern}\nTo measure the field pattern, the current was set to about 1 A. Then the cylindrical coil was moved along the z-axis and measurements were taken in dependence of how fast the magnetic flux density changed.\n\\subsubsection{Short Cylindrical Coil}\n\\label{subsubsec:Short_Cylindrical_Coil_Field}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1]{Field_Pattern_Short}\n\t\\caption{Field Pattern Short Cylindrical Coil}\n\t\\label{fig:Field_Pattern_Short}\n\\end{figure}\nThe fitted curve was created by using equation \\ref{eq:cylindrical_coil_bz}. All parameter except the vacuum permeability $\\mu_0$ and an offset $o$ were defined and set as constants. The offset $o$ is essential because the position of the Hall sensor is not exactly known. Furthermore, the ruler scale used to determine the $z$ values has an uncertainty of 1 mm. By using an offset, the fit is able to correct for those errors. The absolute error is shown in blue. The following parameter were obtained:\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r|l}\n\t\t& \\textbf{Value} \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Vacuum Permeability} $\\mu_0$ & $(1.25017\\pm0.00063)\\cdot10^{-6}$\\ $\\,^\\text{Vs}\\!/_\\text{Am}$ \\\\\n\t\t\\textbf{Offset} $o$ & $(0.26\\pm0.04)$ mm \\\\\n\t\t\\textbf{Windings} $N$ & 240 (constant) \\\\\n\t\t\\textbf{Current} $I$ & 1.002 A (constant) \\\\\n\t\t\\textbf{Radius} $R$ & 0.0485 m (constant) \\\\\n\t\t\\textbf{Length} $l$ & 0.1 m (constant) \\\\\n\t\\end{tabular}\n\t\\caption{Fit Parameters (Field Pattern Short Cylindrical Coil)}\n\t\\label{tab:Field_Pattern_Short}\n\\end{table}\n\\subsubsection{Long Cylindrical Coil}\n\\label{subsubsec:Long_Cylindrical_Coil_Field}\nAll measured values are listed in appendix \\ref{sec:Measurements}.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[scale=1]{Field_Pattern_Long}\n\t\\caption{Field Pattern Long Cylindrical Coil}\n\t\\label{fig:Field_Pattern_Long}\n\\end{figure}\nThe red fitted curve was again creating by utilizing equation \\ref{eq:cylindrical_coil_bz}. The plot with the fit was created the same way as in section \\ref{subsubsec:Short_Cylindrical_Coil_Field}. Since the uncertainty of the gaussmeter (combined with the Hall sensor) is so small, it is hard to see the error (shown in blue). The following parameters were obtained from the fit:\n\\begin{table}[H]\n\t\\centering\n\t\\renewcommand{\\arraystretch}{1.3}\n\t\\begin{tabular}{r|l}\n\t\t& \\textbf{Value} \\\\\n\t\t\\hline\\hline\n\t\t\\textbf{Vacuum Permeability} $\\mu_0$ & $(1.24867\\pm0.00036)\\cdot10^{-6}$\\ $\\,^\\text{Vs}\\!/_\\text{Am}$ \\\\\n\t\t\\textbf{Offset} $o$ & $(0.97\\pm0.03)$ mm \\\\\n\t\t\\textbf{Windings} $N$ & 240 (constant) \\\\\n\t\t\\textbf{Current} $I$ & 0.999 A (constant) \\\\\n\t\t\\textbf{Radius} $R$ & 0.049 m (constant) \\\\\n\t\t\\textbf{Length} $l$ & 0.2 m (constant) \\\\\n\t\\end{tabular}\n\t\\caption{Fit Parameters (Field Pattern Long Cylindrical Coil)}\n\t\\label{tab:Field_Pattern_Long}\n\\end{table}\n", "meta": {"hexsha": "c4112f67d2330cac0f34a08f07e78496b1e3e148", "size": 7485, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "glaL3_E_6_Magnetic_Fields/sections/evaluation.tex", "max_stars_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_stars_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "glaL3_E_6_Magnetic_Fields/sections/evaluation.tex", "max_issues_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_issues_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "glaL3_E_6_Magnetic_Fields/sections/evaluation.tex", "max_forks_repo_name": "MuellerDominik/Physics-Laboratory-Notebooks", "max_forks_repo_head_hexsha": "02836870e6d97a29b1857c956fbd58eb5933eede", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 53.8489208633, "max_line_length": 515, "alphanum_fraction": 0.7433533734, "num_tokens": 2363, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007394, "lm_q2_score": 0.8824278618165526, "lm_q1q2_score": 0.7585912515890465}}
{"text": "\\section{Gaussian Processes}\n\n% ===\n%\\textbf{Idea:} Introduce non-linearity in lin.-reg. setting.\n\n% ===\n\\subsection{Bayesian Linear Regression}\n\n\\emph{Model:}\\enskip\n$\\bm y = \\bm X^\\top \\beta + \\epsilon$,\\enskip\nwith $\\epsilon \\sim \\Gauss{\\epsilon\\mid 0, \\sigma^2 \\mathbb I}$\n\nLikelihood:\\enskip\n$P(\\bm y\\mid \\bm X, \\beta,\\sigma) = \\Gauss{\\bm y\\mid \\bm X^\\top \\beta, \\sigma^2 \\mathbb I}$\n\nPrior:\\enskip\n$P(\\beta\\mid\\bm\\Lambda) = \\Gauss[d]{\\beta\\mid 0, \\bm\\Lambda^{-1}}$\\\\\\enskip\n(Ridge regr. if $\\bm\\Lambda = \\lambda\\mathbb I$ and $\\sigma=1$)\n\nPosterior:\\enskip\n$P(\\beta\\mid \\bm X, \\bm y, \\bm\\Lambda) = \\Gauss{\\beta\\mid \\bm\\mu_\\beta, \\bm\\Sigma_\\beta}$\\\\\\enskip\nwith $\\bm\\mu_\\beta = (\\bm X^\\top \\bm X + \\sigma^2 \\bm\\Lambda)^{-1} \\bm X^\\top \\bm y$\\\\\\enskip\nand $\\bm\\Sigma_\\beta = \\sigma^2 (\\bm X^\\top \\bm X + \\sigma^2 \\bm\\Lambda)^{-1}$\n\n$\\implies$ $\\bm y \\sim \\Gauss{\\bm y \\mid 0, \\; \\bm{X\\Lambda}^{-1} \\bm X^\\top {+} \\sigma^2 \\mathbb I}$\n\\hfill {\\small using $\\E[\\beta,\\epsilon]{}$}\n%With all these assumptions, you can say that $\\bm y$ is Gaussian with $\\mu_y = \\E[\\beta,\\epsilon]{y} = 0$ and $\\sigma_y = \\Cov[\\beta,\\epsilon]{y} = \\bm{X\\Lambda}^{-1} \\bm X^\\top + \\sigma^2 \\mathbb I$.\n\\\\\\enskip\nkernel $k(x_i, x_j) \\coloneqq x_i^\\top \\bm\\Lambda^{-1} x_j$\n\n% ===\n\\subsection{Gaussian Process}\n\n$\\bm y \\sim \\Gauss{\\bm y \\mid m(\\bm X), K(\\bm X, \\bm X) + \\sigma^2 \\mathbb I}$\n\n\\begin{minipage}{\\linewidth}\n    \\centering\n    $\\begin{bsmallmatrix} \\bm y \\\\ y_{n+1} \\end{bsmallmatrix} \\sim\n    \\Gauss*{\n        \\begin{bsmallmatrix} \\bm y \\\\ y_{n+1} \\end{bsmallmatrix} \\mid\n        \\begin{bsmallmatrix} m(\\bm X) \\\\ m(x_{n+1}) \\end{bsmallmatrix},\n        \\begin{bsmallmatrix} \\bm C_n & \\bm k \\\\ \\bm k^\\top & c \\end{bsmallmatrix}\n    }$\n\\end{minipage}\n\n$p(y_{n+1} \\mid x_{n+1}, \\bm X, \\bm y) = \\Gauss{y_{n+1} \\mid \\mu_{n+1}, \\sigma_{n+1}^2}$\\\\\\enskip\nwith $\\mu_{n+1} = m(x_{n+1}) + \\bm k^\\top \\bm C_n^{-1} (\\bm y - m(\\bm X))$\\\\\\enskip\nand $\\sigma_{n+1}^2 = c - \\bm k^\\top \\bm C_n^{-1} \\bm k$\n\nwhere\n$\\bm K = k(\\bm X, \\bm X)$,\\enskip\n$\\bm k = k(x_{n+1}, \\bm X)$,\\\\\n\\phantom{where}\n$\\bm C_n = \\bm K + \\sigma^2 \\mathbb I$,\\enskip\n$c = k(x_{n+1}, x_{n+1}) + \\sigma^2$\n\n% ===\n\\subsection{Kernels \\normalfont\\sffamily\n\\quad scalar product\n\\quad $K_{ij} = k(\\bm x_i, \\bm x_j)$}\n\n\\emph{Valid kernel:}\nmust be\n\\textbf{symmetric}\n    %($\\bm K^\\top\\! {=} \\bm K$)\nand \\textbf{p.s.d.}\n    ($\\bm x^\\top \\bm{Kx} \\geq 0 \\; \\forall\\bm x$ \\textit{\\,or\\,}\n    pos. eigenvalues \\textit{\\,or\\,}\n    pos. principal minors).\\enskip\nMust have a (pot. $\\infty$-dim.) \\textbf{feature vector} $\\phi$ s.t. $k(\\bm x, \\bm x') = \\phi(\\bm x)^\\top \\phi(\\bm x')$.\n\n\\iffalse\n    Kernel $k(\\bm x, \\bm x')$ must be \\emph{symmetric} ($\\bm K^\\top {=} \\bm K$) and \\emph{p.s.d.} ($\\bm x^\\top \\bm{Kx} \\geq 0 \\; \\forall\\bm x$ \\textit{\\;or\\;} pos. eigenvalues).\n    \n    A valid kernel $k$ must have a (potent. $\\infty$-dim.) feature vector $\\phi(\\bm x)$ s.t. $k(\\bm x, \\bm x') = \\phi^\\top \\! (\\bm x) \\phi (\\bm x')$.\n\\fi\n\n\\emph{Common kernels:}\\\\\n\\begin{tabular}{@{}l @{:\\hfill\\enskip}l}\n    Linear & $\\bm x^\\top \\bm x'$ \\\\\n    Polynomial & $(\\bm x^\\top \\bm x' + 1)^p$,\\enskip $\\color{gray} p\\in\\mathbb N$ \\\\\n    RBF (Gaussian) & $\\exp(-\\norm{\\bm x - \\bm x'}_2^2 / h^2)$ \\\\\n    Sigmoid & $\\tanh(\\kappa \\cdot \\bm x^\\top \\bm x' - b)$\n\\end{tabular}\n\n\\emph{Kernel construction:}\n\\enskip\\textbullet~$k_1 {+} k_2$\n\\enskip\\textbullet~$c\\cdot k_1, \\; \\color{gray} c>0$\n\\enskip\\textbullet~$k_1\\cdot k_2$\n\\enskip\\textbullet~$f(\\bm x) k_1(\\bm x, \\bm x') f(\\bm x')$\n\\\\\\textbullet~$k(\\phi(\\bm x), \\phi(\\bm x'))$\n    \\enskip with $\\phi : \\mathcal X \\to \\mathbb R^d$\n\\\\\\textbullet~$g(k_1)$\n    \\enskip with $g :$ exp. \\textit{ or } polyn. w/ \\underline{all} pos. coeff.\n\n% ===\n", "meta": {"hexsha": "be9c6a625f23621944833690f98a9688ed6e3300", "size": 3709, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/AML20/sections/04_gaussian_process.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/04_gaussian_process.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/04_gaussian_process.tex", "max_forks_repo_name": "tstreule/eth-cheat-sheets", "max_forks_repo_head_hexsha": "c61f9fd3b13edf405f790581b4d5eacb50b4f1c3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.2371134021, "max_line_length": 201, "alphanum_fraction": 0.5791318415, "num_tokens": 1590, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299653388754, "lm_q2_score": 0.8198933381139645, "lm_q1q2_score": 0.7585898848047582}}
{"text": "\n\\subsection{Maximum A-Priori estimation (MAP) for generative models}\n\n\\subsubsection{Bayesian regression for generative models}\n\nWe know:\n\n\\(P(\\theta |y,X)=\\dfrac{P(y, \\theta, X )}{P(y, X)}\\)\n\n\\(P(\\theta |y,X)=\\dfrac{P(y, X |\\theta )P(\\theta )}{P(y, X)}\\)\n\nThe bottom bit is a normalisation factor, and so we can use:\n\n\\(P(\\theta |y,X)\\propto P(y, X| \\theta)P(\\theta)\\)\n\nWe have here:\n\n\\begin{itemize}\n\\item Our prior - \\(P(\\theta )\\)\n\\item Our posterior - \\(P(\\theta |y,X)\\)\n\\item Our likelihood function - \\(P(y, X| \\theta )\\)\n\\end{itemize}\n\n\n", "meta": {"hexsha": "9bf8e0c2048659844708cd86b7d0c9b9a9265976", "size": 546, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/parametric/04-03-MAP.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-03-MAP.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-03-MAP.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.84, "max_line_length": 68, "alphanum_fraction": 0.6373626374, "num_tokens": 189, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9473810481379379, "lm_q2_score": 0.8006919949619792, "lm_q1q2_score": 0.7585604214227363}}
{"text": "%% State Space Modelling of Dynamic Systems\r\n%% Lecture 18: General Solution of a State Space System\r\n\\def\\FileDate{10/02/01}\r\n\\def\\FileVersion{1.0}\r\n% ----------------------------------------------------------------\r\n% Notes pages *********************************************************\r\n% ----------------------------------------------------------------\r\n\r\nIn this lecture we conclude our introduction to state space systems by developing a method that can be used to solve any linear time invariant (LTI) system using the state space model. This will put on a formal mathematical footing the approach described in Lecture 15. To do this we need to derive the Taylor series for the state matrix and then use the results from the previous two lectures to formally derive the state transmission matrix $\\mathbf{\\phi}(t)$ from the resolvant matrix $\\mathbf{\\Phi}(\\lambda) = |\\lambda\\mathbf{I}-\\mathbf{A}|$. This will lead is to a general solution which we will illustrate with examples and compare with the solution developed in the last lecture and the solution obtained by inverting the system transfer function. As before, we will refer to Matlab where relevant.\r\n\r\nOnce we have completed this material, we will be in a position to move on to look at state-space methods for control system design.\r\n\r\n\\section*{The Matrix Exponential Function}\r\n\r\nIn mathematics, the Taylor series is a representation of a function as an infinite sum of terms calculated from the values of its derivatives at a single point. It is named after the English mathematician Brook Taylor. It is common practice to use a finite number of terms of the series to approximate a function. The Taylor series may be regarded as the limit of the Taylor polynomials.\\footnote{Definition from `Taylor Series', Wikipedia.}\r\n\r\nWe use Taylor series to approximate general functions, and here we adapt the Taylor series to discover the form of a function of a matrix.\r\n\r\n\\input{frag1}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Taylor series}\r\n   \\input{frag1}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\r\n\\input{frag2}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Using the Similarity Transform}\r\n   \\input{frag2}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\r\n\\input{frag3}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Matrix Function}\r\n   \\input{frag3}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\\input{frag4}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Transition Matrix}\r\n   \\input{frag4}\r\n\\end{slide}\r\n\\fi\r\n\r\n\r\n\\input{frag5}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\t\\heading{Forced Solution}\r\n   \\input{frag5}\r\n\\end{slide}\r\n\\fi\r\n\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\\heading{End of Pre-Class Presentation}\r\nIn the class we will work through a worked example of this approach\r\nand contrast it with two alternatives -- diagonalization by similarity transform\r\nand Laplace.\r\n\\end{slide}\r\n\\fi\r\n\r\n\\subsection*{Example 1}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\\heading{Example 1}\r\nFind the solution of:\r\n\\input{example1}\r\n{\\bf Note}: The solutions to this example and the remaining alternatives\r\n are available in the form of Matlab scripts and as Pencasts on Blackboard.\r\n\\end{slide}\r\n\\fi\r\n\\textbf{Problem}: Find the solution of:\r\n\\input{example1}\r\n\r\n\\textbf{SOLUTION}: The state matrix $\\mathbf{A}$ is the same as Example 4 from Lecture 17, so the transformation matrix is:\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCivaiabg2da9iabg2da9maadmaaba\r\n% qbamqabiGaaaqaaiaaigdaaeaacaaIXaaabaGaeyOeI0IaaGymaaqa\r\n% aiabgkHiTiaaicdacaGGUaGaaGynaaaaaiaawUfacaGLDbaaaaa!3935!\r\n\\[\r\n{\\bf{T}} = \\left[ {\\begin{array}{*{20}c}\r\n   1 & 1  \\\\\r\n   { - 1} & { - 0.5}  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\nwith an inverse:\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCivamaaCaaaleqabaGaeyOeI0IaaG\r\n% ymaaaakiabg2da9iabg2da9maadmaabaqbamqabiGaaaqaaiabgkHi\r\n% TiaaigdaaeaacqGHsislcaaIYaaabaGaaGOmaaqaaiaaikdaaaaaca\r\n% GLBbGaayzxaaaaaa!39A7!\r\n\\[\r\n{\\bf{T}}^{ - 1}  = \\left[ {\\begin{array}{*{20}c}\r\n   { - 1} & { - 2}  \\\\\r\n   2 & 2  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\nand with corresponding eigenvalues $\\lambda_1=-1$ and $\\lambda_2=-2$.\r\n\r\nTherefore the state transition matrix is:\r\n\\begin{eqnarray*}\r\n\\mathbf{\\phi}(t) & = & e^{\\mathbf{A}t}=\\mathbf{T}e^{\\mathbf{\\Lambda}t}\\mathbf{T}^{-1} \\\\\r\n\t             & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   1 & 1  \\\\\r\n\t   { - 1} & { - 0.5}  \\\\\r\n\t\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n\t   {e^{ - t} } & 0  \\\\\r\n\t   0 & {e^{ - 2t} }  \\\\\r\n\t\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n\t   { - 1} & { - 2}  \\\\\r\n\t   2 & 2  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t             & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   1 & 1  \\\\\r\n\t   { - 1} & { - 0.5}  \\\\\r\n\t\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n\t   {-e^{ - t} } & {-2e^{ - t} }  \\\\\r\n\t   {2e^{ - 2t} } & {2e^{ - 2t} }  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t             & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   \\left\\{ {-e^{ - t} + 2e^{-2t}} \\right\\} & \\left\\{ {-2e^{ - t} + 2e^{-2t}} \\right\\}  \\\\\r\n\t   \\left\\{ {e^{ - t} - e^{-2t}} \\right\\} & \\left\\{ {2e^{ - t} - e^{-2t}} \\right\\}  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\\end{eqnarray*}\r\n\r\n\r\nThe solution is:\r\n\\[\r\n\\mathbf{x}(t) = \\mathrm{term}_1+\\int_0^t\\mathrm{term}_2 d\\tau.\r\n\\]\r\nwhere $\\mathrm{term}_1=\\mathbf{\\phi}(t)\\mathbf{x}_0=e^{\\mathbf{A}t}\\mathbf{x}_0$.\r\n\\begin{eqnarray*}\r\n\\mathrm{term}_1 & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   \\left\\{ {-e^{ - t} + 2e^{-2t}} \\right\\} & \\left\\{ {-2e^{ - t} + 2e^{-2t}} \\right\\}  \\\\\r\n\t   \\left\\{ {e^{ - t} - e^{-2t}} \\right\\} & \\left\\{ {2e^{ - t} - e^{-2t}} \\right\\}  \\\\\r\n\t\\end{array}} \\right] \\left[ {\\begin{array}{*{20}c}\r\n\t   1  \\\\\r\n\t   1  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t& = & \\left[ {\\begin{array}{*{20}c}\r\n\t   {\\left\\{ {\\left. { - 3e^{ - t}  + 4e^{ - 2t} } \\right\\}} \\right.}  \\\\\r\n\t   {\\left\\{ {\\left. {3e^{ - t}  - 2e^{ - 2t} } \\right\\}} \\right.}  \\\\\r\n\t\\end{array}} \\right]\r\n\\end{eqnarray*}\r\nand\r\n\\begin{eqnarray*}\r\n\t{\\rm{term}}_2  & = & e^{{\\bf{A}}(t - \\tau )} {\\bf{B}}u = e^{{\\bf{A}}(t - \\tau )} \\left[ {\\begin{array}{*{20}c}\r\n\t   1  \\\\\r\n\t   0  \\\\\r\n\t\\end{array}} \\right] \\times 1 \\\\\r\n & = & \\left[ {\\begin{array}{*{20}c}\r\n   {\\left. {\\left\\{ { - e^{ - (t - \\tau )}  + 2e^{ - 2(t - \\tau )} } \\right.} \\right\\}}  \\\\\r\n   {\\left. {\\left\\{ {e^{ - (t - \\tau )}  - e^{ - 2(t - \\tau )} } \\right.} \\right\\}}  \\\\\r\n\\end{array}} \\right]\r\n\\end{eqnarray*}\r\n\r\n\\begin{eqnarray*}\r\n\t\\int_0^t {{\\rm{term}}_2 d\\tau }  & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   {\\int_0^t {\\left. {\\left\\{ { - e^{ - (t - \\tau )}  + 2e^{ - 2(t - \\tau )} } \\right.} \\right\\}d\\tau } }  \\\\\r\n\t   {\\int_0^t {\\left. {\\left\\{ {e^{ - (t - \\tau )}  - e^{ - 2(t - \\tau )} } \\right.} \\right\\}d\\tau } }  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t& = &\r\n\t  \\left[ {\\begin{array}{*{20}c}\r\n\t   {\\left. {\\left\\{ { - e^{ - (t - \\tau )}  + e^{ - 2(t - \\tau )} } \\right.} \\right\\}}  \\\\\r\n\t   {\\left. {\\left\\{ {e^{ - (t - \\tau )}  - 0.5e^{ - 2(t - \\tau )} } \\right.} \\right\\}}  \\\\\r\n\t\\end{array}} \\right]_{\\tau  = 0}^t  \\\\\r\n\t & = & \\left[ {\\begin{array}{*{20}c}\r\n\t   { - 1 + e^{ - t}  + 1 - e^{ - 2t} }  \\\\\r\n\t   { 1 - e^{ - t}  - 0.5 + 0.5e^{ - 2t} }  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t &  = & \\left[ {\\begin{array}{*{20}c}\r\n\t   {e^{ - t}  - e^{ - 2t} }  \\\\\r\n\t   {0.5 - e^{ - t}  + 0.5e^{ - 2t} }  \\\\\r\n\t\\end{array}} \\right]\r\n\\end{eqnarray*}\r\n\r\nCombining $\\mathrm{term}_1$ and $\\int_0^t \\mathrm{term}_2 d\\tau$ we find the total, forced, response:\r\n\\[\r\n{\\bf{x}}(t) = \\left[ {\\begin{array}{*{20}c}\r\n   { - 3e^{ - t}  + 4e^{ - 2t} }  \\\\\r\n   {3e^{ - t}  - 2e^{ - 2t} }  \\\\\r\n\\end{array}} \\right] + \\left[ {\\begin{array}{*{20}c}\r\n   {e^{ - t}  - e^{ - 2t} }  \\\\\r\n   {0.5 - e^{ - t}  + 0.5e^{ - 2t} }  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\nTherefore:\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCiEaiaacIcacaWG0bGaaiykaiabg2\r\n% da9maadmaabaqbamqabiqaaaqaaiabgkHiTiaaikdacaWGLbWaaWba\r\n% aSqabeaacqGHsislcaWG0baaaOGaey4kaSIaaG4maiaadwgadaahaa\r\n% WcbeqaaiabgkHiTiaaikdacaWG0baaaaGcbaGaaGimaiaac6cacaaI\r\n% 1aGaey4kaSIaaGOmaiaadwgadaahaaWcbeqaaiabgkHiTiaadshaaa\r\n% GccqGHsislcaaIXaGaaiOlaiaaiwdacaWGLbWaaWbaaSqabeaacqGH\r\n% sislcaaIYaGaamiDaaaaaaaakiaawUfacaGLDbaaaaa!4C2A!\r\n\\[\r\n{\\bf{x}}(t) = \\left[ {\\begin{array}{*{20}c}\r\n   { - 2e^{ - t}  + 3e^{ - 2t} }  \\\\\r\n   {0.5 + 2e^{ - t}  - 1.5e^{ - 2t} }  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\n\r\n\r\n\r\n\\subsection*{Alternative solution 1}\r\n\\ifslidesonly\r\n\\begin{slide}\r\n\\heading{Alternative solution 1}\r\nRepeat Example 1 using the transformation to normal canonical form:\r\n\\[\r\n\\frac{d\\mathbf{w}}{t}=\\mathbf{\\Lambda w}+ \\mathbf{T}^{-1}\\mathbf{B}u\r\n\\]\r\n\\end{slide}\r\n\\fi\r\nUsing the transformation to normal canonical form:\r\n\\[\r\n\\frac{d\\mathbf{w}}{t}=\\mathbf{\\Lambda w}+ \\mathbf{T}^{-1}\\mathbf{B}u\r\n\\]\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaWaaSaaaeaacaWGKbGaaC4Daaqaaiaads\r\n% gacaWG0baaaiabg2da9maadmaabaqbamqabiGaaaqaaiabgkHiTiaa\r\n% igdaaeaacaaIWaaabaGaaGimaaqaaiabgkHiTiaaikdaaaaacaGLBb\r\n% GaayzxaaGaaC4DaiabgUcaRmaadmaabaqbamqabiGaaaqaaiabgkHi\r\n% TiaaigdaaeaacqGHsislcaaIYaaabaGaaGOmaaqaaiaaikdaaaaaca\r\n% GLBbGaayzxaaWaamWaaeaafaWabeGabaaabaGaaGymaaqaaiaaicda\r\n% aaaacaGLBbGaayzxaaGaamyDaiaacUdacaaMf8UaamyDaiabg2da9i\r\n% aaigdaaaa!4BE3!\r\n\\[\r\n\\frac{{d{\\bf{w}}}}{{dt}} = \\left[ {\\begin{array}{*{20}c}\r\n   { - 1} & 0  \\\\\r\n   0 & { - 2}  \\\\\r\n\\end{array}} \\right]{\\bf{w}} + \\left[ {\\begin{array}{*{20}c}\r\n   { - 1} & { - 2}  \\\\\r\n   2 & 2  \\\\\r\n\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n   1  \\\\\r\n   0  \\\\\r\n\\end{array}} \\right]u;\\quad u = 1\r\n\\]\r\n\\[\r\n\\frac{dw_1}{dt}=-w_1-1\\ \\textrm{and}\\ \\frac{dw_2}{dt}=-2w_2 + 2\r\n\\]\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaC4DamaaBaaaleaacaaIWaaabeaaki\r\n% abg2da9iaahsfadaahaaWcbeqaaiabgkHiTiaaigdaaaGccaWH4bWa\r\n% aSbaaSqaaiaaicdaaeqaaOGaeyypa0ZaamWaaeaafaWabeGacaaaba\r\n% GaeyOeI0IaaGymaaqaaiabgkHiTiaaikdaaeaacaaIYaaabaGaaGOm\r\n% aaaaaiaawUfacaGLDbaadaWadaqaauaadeqaceaaaeaacaaIXaaaba\r\n% GaaGymaaaaaiaawUfacaGLDbaacqGH9aqpdaWadaqaauaadeqaceaa\r\n% aeaacqGHsislcaaIZaaabaGaaGinaaaaaiaawUfacaGLDbaaaaa!466E!\r\n\\[\r\n{\\bf{w}}_0  = {\\bf{T}}^{ - 1} {\\bf{x}}_0  = \\left[ {\\begin{array}{*{20}c}\r\n   { - 1} & { - 2}  \\\\\r\n   2 & 2  \\\\\r\n\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n   1  \\\\\r\n   1  \\\\\r\n\\end{array}} \\right] = \\left[ {\\begin{array}{*{20}c}\r\n   { - 3}  \\\\\r\n   4  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\n\r\n\\begin{eqnarray*}\r\n\tw_1 & = & w_{10}e^{-t}-\\int_0^t e^{-(t-\\tau)} d\\tau \\\\\r\n\t    & = & -3e^{-t}-\\left[e^{-(t-\\tau)}\\right]_0^t \\\\\r\n\t    & = & -3e^{-t}-\\left[1 - e^{-t}\\right] \\\\\r\n\t    & = & -1 -2e^{-t}\r\n\\end{eqnarray*}\r\n\r\n\\begin{eqnarray*}\r\n\tw_2 & = & w_{20}e^{-2t}+2\\int_0^t e^{-2(t-\\tau)} d\\tau \\\\\r\n\t    & = & 4e^{-2t}+2\\left[0.5e^{-2(t-\\tau)}\\right]_0^t \\\\\r\n\t    & = & 4e^{-2t}+\\left[1 - e^{-2t}\\right] \\\\\r\n\t    & = & 1 + 3e^{-2t}\r\n\\end{eqnarray*}\r\n\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCiEaiabg2da9iaahsfacaWH3bGaey\r\n% ypa0ZaamWaaeaafaWabeGacaaabaGaaGymaaqaaiaaigdaaeaacqGH\r\n% sislcaaIXaaabaGaeyOeI0IaaGimaiaac6cacaaI1aaaaaGaay5wai\r\n% aaw2faamaadmaabaqbamqabiqaaaqaaiabgkHiTiaaigdacqGHsisl\r\n% caaIYaGaamyzamaaCaaaleqabaGaeyOeI0IaamiDaaaaaOqaaiaaig\r\n% dacqGHRaWkcaaIZaGaamyzamaaCaaaleqabaGaeyOeI0IaaGOmaiaa\r\n% dshaaaaaaaGccaGLBbGaayzxaaaaaa!49AC!\r\n\\[\r\n{\\bf{x}} = {\\bf{Tw}} = \\left[ {\\begin{array}{*{20}c}\r\n   1 & 1  \\\\\r\n   { - 1} & { - 0.5}  \\\\\r\n\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n   { - 1 - 2e^{ - t} }  \\\\\r\n   {1 + 3e^{ - 2t} }  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\nTherefore\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCiEaiabg2da9maadmaabaqbamqabi\r\n% qaaaqaaiabgkHiTiaaikdacaWGLbWaaWbaaSqabeaacqGHsislcaWG\r\n% 0baaaOGaey4kaSIaaG4maiaadwgadaahaaWcbeqaaiabgkHiTiaaik\r\n% dacaWG0baaaaGcbaGaaGimaiaac6cacaaI1aGaey4kaSIaaGOmaiaa\r\n% dwgadaahaaWcbeqaaiabgkHiTiaadshaaaGccqGHsislcaaIXaGaai\r\n% OlaiaaiwdacaWGLbWaaWbaaSqabeaacqGHsislcaaIYaGaamiDaaaa\r\n% aaaakiaawUfacaGLDbaaaaa!49D8!\r\n\\[\r\n{\\bf{x}} = \\left[ {\\begin{array}{*{20}c}\r\n   { - 2e^{ - t}  + 3e^{ - 2t} }  \\\\\r\n   {0.5 + 2e^{ - t}  - 1.5e^{ - 2t} }  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\n\r\n\r\n\\subsection*{Alternative solution 2}\r\n \\ifslidesonly\r\n \\begin{slide}\r\n \\heading{Alternative solution 2}\r\n Solve the problem of example 1 using the Laplace transform method.\r\n \\end{slide}\r\n \\fi\r\nUsing the Laplace transform method.\r\n\r\nTaking Laplace transforms of the state equations, taking account of the initial conditions:\r\n\\[\r\ns\\mathbf{X}(s)-\\mathbf{x}_0=\\mathbf{A}\\mathbf{X}(s)+\\mathbf{B}U(s)\r\n\\]\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaiikaiaadohacaWHjbGaeyOeI0IaaC\r\n% yqaiaacMcacaWHybGaaiikaiaadohacaGGPaGaeyypa0JaaCiEamaa\r\n% BaaaleaacaaIWaaabeaakiabgUcaRiaahkeacaWGvbGaaiikaiaado\r\n% hacaGGPaGaeyypa0ZaamWaaeaafaWabeGabaaabaGaaGymaaqaaiaa\r\n% igdaaaaacaGLBbGaayzxaaGaey4kaSYaamWaaeaafaWabeGabaaaba\r\n% GaaGymaaqaaiaaicdaaaaacaGLBbGaayzxaaWaaSaaaeaacaaIXaaa\r\n% baGaam4Caaaaaaa!4885!\r\n\\[\r\n(s{\\bf{I}} - {\\bf{A}}){\\bf{X}}(s) = {\\bf{x}}_0  + {\\bf{B}}U(s) = \\left[ {\\begin{array}{*{20}c}\r\n   1  \\\\\r\n   1  \\\\\r\n\\end{array}} \\right] + \\left[ {\\begin{array}{*{20}c}\r\n   1  \\\\\r\n   0  \\\\\r\n\\end{array}} \\right]\\frac{1}{s}\r\n\\]\r\nTherefore\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaCiwaiaacIcacaWGZbGaaiykaiabg2\r\n% da9iaacIcacaWGZbGaaCysaiabgkHiTiaahgeacaGGPaWaaWbaaSqa\r\n% beaacqGHsislcaaIXaaaaOWaamWaaeaafaWabeGabaaabaGaaGymai\r\n% abgUcaRmaalaaabaGaaGymaaqaaiaadohaaaaabaGaaGymaaaaaiaa\r\n% wUfacaGLDbaaaaa!3F1F!\r\n\\[\r\n{\\bf{X}}(s) = (s{\\bf{I}} - {\\bf{A}})^{ - 1} \\left[ {\\begin{array}{*{20}c}\r\n   {1 + \\frac{1}{s}}  \\\\\r\n   1  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\n% MathType!MTEF!2!1!+-\r\n% faaagaart1ev2aaaKnaaaaWenf2ys9wBH5garuavP1wzZbqedmvETj\r\n% 2BSbqefm0B1jxALjharqqtubsr4rNCHbGeaGqiVu0Je9sqqrpepC0x\r\n% bbL8FesqqrFfpeea0xe9Lq-Jc9vqaqpepm0xbba9pwe9Q8fs0-yqaq\r\n% pepae9pg0FirpepeKkFr0xfr-xfr-xb9Gqpi0dc9adbaqaaeGaciGa\r\n% aiaabeqaamaabaabaaGcbaGaaeOtaiaab+gacaqG3bGaaeiiaiaacI\r\n% cacaWGZbGaaCysaiabgkHiTiaahgeacaGGPaWaaWbaaSqabeaacqGH\r\n% sislcaaIXaaaaOGaeyypa0ZaamWaaeaafaWabeGacaaabaGaam4Cai\r\n% abgUcaRiaaiodaaeaacaaIYaaabaGaeyOeI0IaaGymaaqaaiaadoha\r\n% aaaacaGLBbGaayzxaaWaaWbaaSqabeaacqGHsislcaaIXaaaaOGaey\r\n% ypa0ZaaSaaaeaacaaIXaaabaGaaiikaiaadohacqGHRaWkcaaIZaGa\r\n% aiykaiaadohacqGHRaWkcaaIYaaaamaadmaabaqbamqabiGaaaqaai\r\n% aadohaaeaacqGHsislcaaIYaaabaGaaGymaaqaaiaadohacqGHRaWk\r\n% caaIZaaaaaGaay5waiaaw2faaaaa!5355!\r\n\\[\r\n{\\rm{Now }}(s{\\bf{I}} - {\\bf{A}})^{ - 1}  = \\left[ {\\begin{array}{*{20}c}\r\n   {s + 3} & 2  \\\\\r\n   { - 1} & s  \\\\\r\n\\end{array}} \\right]^{ - 1}  = \\frac{1}{{(s + 3)s + 2}}\\left[ {\\begin{array}{*{20}c}\r\n   s & { - 2}  \\\\\r\n   1 & {s + 3}  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\nTherefore\r\n\\begin{eqnarray*}\r\n\t{\\bf{X}}(s) & = & \\frac{1}{{s^2  + 3s + 2}}\\left[ {\\begin{array}{*{20}c}\r\n\t   s & { - 2}  \\\\\r\n\t   1 & {s + 3}  \\\\\r\n\t\\end{array}} \\right]\\left[ {\\begin{array}{*{20}c}\r\n\t   {1 + \\frac{1}{s}}  \\\\\r\n\t   1  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t            & = & \\frac{1}{{(s + 1)(s + 2)}}\\left[ {\\begin{array}{*{20}c}\r\n\t   {s - 1}  \\\\\r\n\t   {\\frac{{s^2  + 4s + 1}}{s}}  \\\\\r\n\t\\end{array}} \\right] \\\\\r\n\t&  = & \\left[ {\\begin{array}{*{20}c}\r\n\t   {\\frac{{s - 1}}{{(s + 1)(s + 2)}}}  \\\\\r\n\t   {\\frac{{s^2  + 4s + 1}}{{s(s + 1)(s + 2)}}}  \\\\\r\n\t\\end{array}} \\right]\r\n\\end{eqnarray*}\r\n\r\nTaking partial fractions:\r\n\\[\r\n{\\bf{X}}(s) = \\left[ {\\begin{array}{*{20}c}\r\n   {\\frac{{ - 2}}{{s + 1}} + \\frac{3}{{s + 2}}}  \\\\\r\n   {\\frac{{0.5}}{s} + \\frac{2}{{s + 1}} + \\frac{{ - 1.5}}{{s + 2}}}  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\nFinally, taking inverse Laplace transforms:\r\n\\[\r\n{\\bf{x}}(t) = \\left[ {\\begin{array}{*{20}c}\r\n   { - 2e^{ - t}  + 3e^{ - 2t} }  \\\\\r\n   {0.5 + 2e^{ - t}  - 1.5e^{ - 2t} }  \\\\\r\n\\end{array}} \\right]\r\n\\]\r\n\r\n\r\n\r\n\r\n\r\n%----------------------------------------------------------------\r\n% The end of notes\r\n% ----------------------------------------------------------------\r\n\\endinput\r\n\r\n%%% Local Variables:\r\n%%% mode: latex\r\n%%% TeX-master: t\r\n%%% End:\r\n", "meta": {"hexsha": "cb7d8fc7a50270ffe20900d0b088f47db87d9950", "size": 17579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "StateSpaceModels/Lecture18/notes.tex", "max_stars_repo_name": "cpjobling/EGLM03-Resources", "max_stars_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "StateSpaceModels/Lecture18/notes.tex", "max_issues_repo_name": "cpjobling/EGLM03-Resources", "max_issues_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "StateSpaceModels/Lecture18/notes.tex", "max_forks_repo_name": "cpjobling/EGLM03-Resources", "max_forks_repo_head_hexsha": "70e5fd7b3e519cc3f327f348631b800d361bbb27", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6993736952, "max_line_length": 806, "alphanum_fraction": 0.6414471813, "num_tokens": 8188, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8902942319436397, "lm_q2_score": 0.8519527963298947, "lm_q1q2_score": 0.7584886604607597}}
{"text": "\\section{The kernel and image of a linear map}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Describe the kernel and image of a linear transformation.\n  \\item Use the kernel and image to determine if a linear\n    transformation is one to one or onto.\n  \\end{enumerate}\n\\end{outcome}\n\nHere we consider the case where the linear map is not necessarily an\nisomorphism. First here is a definition of what is meant by the image and\nkernel of a linear transformation.\n\n\\begin{definition}{Kernel and image}{}\nLet $V$ and $W$ be vector spaces and let $T:V\\rightarrow W$ be a linear transformation. Then the image of $T$\ndenoted as $\\func{im}(T) $ is defined to be the set\n\\begin{equation*}\n\\set{T(\\vect{v}):\\vect{v}\\in V}\n\\end{equation*}\nIn words, it consists of all vectors in $W$ which equal $T(\\vect{v})$ for some $\n\\vect{v}\\in V$. The kernel, $\\ker (T)$,\nconsists of all $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{0}$. That is,\n\\begin{equation*}\n\\ker (T) =\\set{\\vect{v}\\in V:T(\\vect{v})=\\vect{0}}\n\\end{equation*}\n\\end{definition}\n\nThen in fact, both $\\func{im}(T) $ and $\\ker (T) $\nare subspaces of $W$ and $V$ respectively.\n\n\\begin{proposition}{Kernel and image as subspaces}{kernel-image-vector-spaces}\nLet $V,W$ be vector spaces and let $T:V\\rightarrow W$ be a linear transformation. Then $\\ker (\nT) \\subseteq V$ and $\\func{im}(T) \\subseteq W$. In fact, they are both subspaces.\n\\end{proposition}\n\n\\begin{proof}\nFirst consider $\\ker (T)$. It is necessary to\nshow that if $\\vect{v}_{1},\\vect{v}_{2}$ are vectors in $\\ker (T) $\nand if $a,b$ are scalars, then $a\\vect{v}_{1}+b\\vect{v}_{2}$ is also in $\\ker\n(T)$. But\n\\begin{equation*}\nT(a\\vect{v}_{1}+b\\vect{v}_{2}) =aT(\\vect{v}_{1})+bT(\\vect{v}_{2})=a\\vect{0}+b\\vect{0}=\\vect{0}\n\\end{equation*}\nThus $\\ker (T) $ is a subspace of $V$.\n\nNext suppose $T(\\vect{v}_{1}),T(\\vect{v}_{2})$ are two vectors in $\\func{im}(\nT)$. Then if $a,b$ are scalars,\n\\begin{equation*}\naT(\\vect{v}_{2})+bT(\\vect{v}_{2})=T(a\\vect{v}_{1}+b\\vect{v}_{2})\n\\end{equation*}\nand this last vector is in $\\func{im}(T) $ by definition.\n\\end{proof}\n\nConsider the following example.\n\n\\begin{example}{Kernel and image of a transformation}{kernel-image}\nLet $T:\\Poly_1\\to\\R$ be the linear transformation defined by\n\\[ T(p(x))=p(1)\\mbox{ for all } p(x)\\in \\Poly_1.\\]\nFind the kernel and image of $T$.\n\\end{example}\n\n\\begin{solution}\nWe will first find the kernel of $T$. It consists of all polynomials in $\\Poly_1$ that have $1$ for a root.\n\\begin{eqnarray*}\n\\func{ker}(T) & = & \\set{p(x)\\in \\Poly_1 \\mid p(1)=0} \\\\\n& = & \\set{ax+b \\mid a,b\\in\\R \\mbox{ and }a+b=0} \\\\\n& = & \\set{ax-a \\mid a\\in\\R}\n\\end{eqnarray*}\nTherefore a basis for $\\func{ker}(T)$ is\n\\[\n\\set{x-1 }\n\\]\nNotice that this is a subspace of $\\Poly_1$.\n\nNow consider the image. It consists of all numbers which can be obtained by evaluating all polynomials in $\\Poly_1$ at $1$.\n\\begin{eqnarray*}\n\\func{im}(T) & = & \\set{p(1) \\mid p(x)\\in \\Poly_1} \\\\\n & = & \\set{a+b \\mid ax+b\\in \\Poly_1} \\\\\n & = & \\set{a+b \\mid a,b\\in\\R}\\\\\n & = & \\R\n\\end{eqnarray*}\nTherefore a basis for $\\func{im}(T)$ is\n\\[\n\\set{1 }\n\\]\nNotice that this is a subspace of $\\R$, and in fact is the space $\\R$ itself.\n\\end{solution}\n\n\\begin{example}{Kernel and image of a linear transformation}{finding-kernel-image}\nLet $T: \\Mat_{2,2} \\to \\R^2$ be defined by\n\\[\nT \\begin{mymatrix}{cc}\na & b \\\\\nc & d\n\\end{mymatrix}\n =\n\\begin{mymatrix}{c}\na - b \\\\\nc + d\n\\end{mymatrix}\n\\]\nThen $T$ is a linear transformation. Find a basis for $\\func{ker} (T)$ and $\\func{im}(T)$.\n\\end{example}\n\n\\begin{solution}\nYou can verify that $T$ represents a linear transformation.\n\nNow we want to find a way to describe all matrices $A$ such that $T(A) = \\vect{0}$, that is the matrices in $\\func{ker}(T)$.\nSuppose $A = \\begin{mymatrix}{cc}\na & b \\\\\nc & d\n\\end{mymatrix}$ is such a matrix.\nThen\n\\[\nT \\begin{mymatrix}{cc}\na & b \\\\\nc & d\n\\end{mymatrix}\n =\n\\begin{mymatrix}{c}\na - b \\\\\nc + d\n\\end{mymatrix}\n =\n\\begin{mymatrix}{c}\n0 \\\\\n0\n\\end{mymatrix}\n\\]\nThe values of $a, b, c, d$ that make this true are given by solutions to the system\n\\begin{eqnarray*}\na - b &=& 0 \\\\\nc + d &=& 0\n\\end{eqnarray*}\nThe solution is $a = s, b = s, c = t, d = -t$ where $s, t$ are scalars. We can describe $\\func{ker}(T)$ as follows.\n\\[\n\\func{ker}(T) =\n\\set{\n\\begin{mymatrix}{cc}\ns & s \\\\\nt & -t\n\\end{mymatrix}\n}\n=\n\\sspan\n\\set{\n\\begin{mymatrix}{cc}\n1 & 1 \\\\\n0 & 0\n\\end{mymatrix},\n\\begin{mymatrix}{cc}\n0 & 0 \\\\\n1 & -1\n\\end{mymatrix}\n}\n\\]\nIt is clear that this set is linearly independent and therefore forms a basis for $\\func{ker}(T)$.\n\nWe now wish to find a basis for $\\func{im}(T)$. We can write the image of $T$ as\n\\[\n\\func{im}(T) = \\set{\n\\begin{mymatrix}{c}\na - b  \\\\\nc + d\n\\end{mymatrix}\n}\n\\]\nNotice that this can be written as\n\\[\n\\sspan\n\\set{\n\\begin{mymatrix}{c}\n1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n-1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1\n\\end{mymatrix} }\n\\]\n\nHowever this is clearly not linearly independent. By removing vectors from the set to create an independent set gives a basis of $\\func{im}(T)$.\n\\[\n\\set{\n\\begin{mymatrix}{c}\n1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{c}\n0 \\\\\n1\n\\end{mymatrix}\n}\n\\]\n\nNotice that these vectors have the same span as the set above but are now linearly independent.\n\\end{solution}\n\nA major result is the relation between the dimension of the kernel and\ndimension of the image of a linear transformation. A special case was done\nearlier in the context of matrices. Recall that for an $m\\times n$-matrix $%\nA, $ it was the case that the dimension of the kernel of $A$ added to the\nrank of $A$ equals $n$.\n\n\\begin{theorem}{Dimension of kernel and image}{}\nLet $T:V\\rightarrow W$ be a linear transformation where $V,W$ are vector\nspaces. Suppose the dimension of $V$ is $n$.\nThen $n=\\dim (\\ker (T)) +\\dim (\\func{im}\n(T))$.\n\\end{theorem}\n\n\\begin{proof}\nFrom Proposition~\\ref{prop:kernel-image-vector-spaces}, $\\func{im}(T) $\nis a subspace of $W$. By Theorem~\\ref{thm:basis-vector-space}, there exists a basis for $\n\\func{im}(T) ,\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{r})}\n. $ Similarly, there is a basis for $\\ker (T) ,\\set{\\vect{u}\n_{1},\\ldots,\\vect{u}_{s}}$. Then if $\\vect{v}\\in V$, there exist\nscalars $c_{i}$ such that\n\\begin{equation*}\nT(\\vect{v})=\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})\n\\end{equation*}\nHence $T\\paren{\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}} =0$. It follows\nthat $\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}$ is in $\\ker (T)$.\nHence there are scalars $a_{i}$ such that\n\\begin{equation*}\n\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}=\\sum_{j=1}^{s}a_{j}\\vect{u}_{j}\n\\end{equation*}\nHence $\\vect{v}=\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}+\\sum_{j=1}^{s}a_{j}\\vect{u}\n_{j}. $ Since $\\vect{v}$ is arbitrary, it follows that\n\\begin{equation*}\nV=\\sspan\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}}\n\\end{equation*}\nIf the vectors $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}} $ are linearly independent, then it will follow that\nthis set is a basis. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}+\\sum_{j=1}^{s}a_{j}\\vect{u}_{j}=0\n\\end{equation*}\nApply $T$ to both sides to obtain\n\\begin{equation*}\n\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})+\\sum_{j=1}^{s}a_{j}T(\\vect{u}\n_{j})=\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})= \\vect{0}\n\\end{equation*}\nSince $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{r})} $ is linearly\nindependent, it follows that each $c_{i}=0$. Hence $\\sum_{j=1}^{s}a_{j}\\vect{u\n}_{j}=0$ and so, since the $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s}} $\nare linearly independent, it follows that each $a_{j}=0$ also. It follows\nthat $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\\vect{v}\n_{r}} $ is a basis for $V$ and so\n\\begin{equation*}\nn=s+r=\\dim (\\ker (T)) +\\dim (\\func{im}(\nT))\n\\end{equation*}\n\\end{proof}\n\nConsider the following definition.\n\n\\begin{definition}{Rank of linear transformation}{}\nLet $T:V\\rightarrow W$ be a linear transformation and suppose $V,W$ are finite-dimensional vector spaces. Then\nthe rank of $T$ denoted as $\\rank(T) $ is defined as the\ndimension of $\\func{im}(T)$. The nullity of $T$ is the\ndimension of $\\ker (T)$. Thus the above theorem says that $\n\\rank(T) +\\dim (\\ker (T)) =\\dim\n(V)$.\n\\end{definition}\n\nRecall the following important result.\n\n\\begin{theorem}{Subspace of same dimension}{subspace-vector-space}\nLet $V$ be a vector space of dimension $n$ and let $W$ be a\nsubspace. Then $W=V$ if and only if the dimension of $W$ is also $n$.\n\\end{theorem}\n\nFrom this theorem follows the next corollary.\n\n\\begin{corollary}{One to one and onto characterization}{one-one-onto-char}\nLet $T:V\\rightarrow W$ be a linear map where the dimension of $V$ is $n$ and\nthe dimension of $W$ is $m$. Then $T$ is one to one if and only if $\\ker\n(T) =\\set{\\vect{0}} $ and $T$ is onto if and only if $\n\\rank(T) =m$.\n\\end{corollary}\n\n\\begin{proof}\nThe statement $\\ker (T) =\\set{\\vect{0}} $\nis equivalent to saying if $T (\\vect{v})=\\vect{0}$, it follows that $\\vect{v}=\\vect{0}$\n. Thus by Lemma~\\ref{lem:one-to-one-abstract} $T$ is one to one. If $T$ is onto, then $\n\\func{im}(T) =W$ and so $\\rank(T) $ which is\ndefined as the dimension of $\\func{im}(T) $ is $m$. If $\\rank(T) =m$, then by Theorem~\\ref{thm:subspace-vector-space}, since $\\func{im}\n(T) $ is a subspace of $W$, it follows that $\\func{im}(\nT) =W$.\n\\end{proof}\n\n\\begin{example}{One to one transformation}{one-to-one-kernel}\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}\nYou may recall this example from earlier in Example~\\ref{exa:one-to-one-general}. Here we will determine that $S$ is one to one, but not onto, using the method provided in Corollary~\\ref{cor:one-one-onto-char}.\n\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\nSince the unique solution is $a=b=c=0$, $\\ker(S)=\\set{\\vect{0}}$, and thus\n$S$ is one-to-one by Corollary~\\ref{cor:one-one-onto-char}.\n\nSimilarly, by Corollary~\\ref{cor:one-one-onto-char}, if $S$ is onto it will have $\\rank(S) = \\dim(\\Mat_{2,2}) = 4$. The image of $S$ is given by\n\\[\n\\func{im}(S) = \\set{\\begin{mymatrix}{cc}\na+b & a+c \\\\ b-c & b+c \\end{mymatrix} } = \\sspan \\set{\\begin{mymatrix}{rr}\n1 & 1 \\\\\n0 & 0 \\end{mymatrix}, \\begin{mymatrix}{rr}\n1 & 0 \\\\\n1 & 1 \\end{mymatrix}, \\begin{mymatrix}{rr}\n0 & 1 \\\\\n-1 & 1 \\end{mymatrix} }\n\\]\nThese matrices are linearly independent which means this set forms a basis for $\\func{im}(S)$. Therefore the dimension of $\\func{im}(S)$, also called $\\rank(S)$, is equal to $3$. It follows that $S$ is not onto.\n\\end{solution}\n", "meta": {"hexsha": "4bf20b5a915d0295d4f1598280566dd816e48d12", "size": 11092, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/vectorspacesKernelImage.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/vectorspacesKernelImage.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/vectorspacesKernelImage.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.3333333333, "max_line_length": 211, "alphanum_fraction": 0.6504688063, "num_tokens": 4142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527982093666, "lm_q2_score": 0.8902942297605357, "lm_q1q2_score": 0.7584886602741412}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.02| in the Command Window, and type \\verb|edit lab_02_script| in the Command Window to edit \\verb|lab_02_script.m|.\n\n%---------------------------------------------\n\\section{1-D Array: Vector}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n  \\item Define two evenly spaced row vectors: \\verb|vec1| of which elements start from $1$ to $9$ with $9$ entries and \\verb|vec2| that is between $18$ and $1$ with step size $-2$ using \\verb|linspace| and \\verb|colon|, respectively. Then store lengths of \\verb|vec1| and \\verb|vec2| to \\verb|vec1Length| and \\verb|vec2Length|.\n  \\item Calculate the following products:\n    \\begin{itemize}\n      \\item Store the product of all elements of \\verb|vec1| to \\verb|vec1Product|.\n      \\item Calculate the elementwise product of \\verb|vec1| and \\verb|vec2|, then assign the result to \\verb|vecProduct|.\n      \\item Calculate the dot product of \\verb|vec1| and \\verb|vec2| in three ways using \\verb|dot|, matrix multiplication, and \\verb|sum| with elementwise multiplication. Store the results to \\verb|dotProduct1|, \\verb|dotProduct2|, and \\verb|dotProduct3|.\n    \\end{itemize}\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{2-D Array: Matrix}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n  \\item Verify that column sums, row sums, and main diagonal sum of a magic square matrix are equal. Define \\verb|mat1| to be a $3 \\times 3$ magic square matrix. Calculate the column sums \\verb|mat1ColSum|, row sums \\verb|mat1RowSum|, main diagonal sum \\verb|mat1DiagSum| using \\verb|sum|.\n  \\item Create a $3 \\times 3$ matrix \\verb|mat2| $= \\begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 & 9 \\end{bmatrix}$ by reshaping \\verb|vec1| using \\verb|reshape| and \\verb|transpose|. Then calculate \\verb|matProduct1| which is the product of \\verb|mat1| and \\verb|mat2| using matrix multiplication, and \\verb|matProduct2| using elementwise multiplication. Observe the difference between these two multiplications.\n  \\item Stack \\verb|matProduct1| and \\verb|matProduct2|, then assign it to \\verb|mat3| of which the size is $6 \\times 3$. Compute the sum \\verb|sumAll| of all elements of \\verb|mat3|, column minimums \\verb|mat3ColMin|, and row maximums \\verb|mat3RowMax| of \\verb|mat3|. Find the row indices \\verb|rowIndex| and column indices \\verb|colIndex| of entries that are \\emph{no greater than} $20$ in \\verb|mat3|.\n  \\item Add three new columns to \\verb|mat3|:\n    \\begin{itemize}\n      \\item Extract the second column of \\verb|mat3| and assign it as the fourth column of \\verb|mat3|.\n      \\item Append the vector \\verb|int8(rand(6, 1)) * 255)| to \\verb|mat3| by specifying the column index to be \\verb|end + 1|.\n      \\item Use bracket to append the vector \\verb|colon(0,36,200)| to \\verb|mat3| as the last column.\n      \\item Check the size of \\verb|mat3| and store it to \\verb|mat3Size|.\n    \\end{itemize}\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{Array: Char Array vs. String Array}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n  \\item Define \\verb|helloChar|, \\verb|worldChar|, \\verb|helloString|, \\verb|worldString| to be \\verb|'hello '|, \\verb|'world'|, \\verb|\"hello \"|, \\verb|\"world\"|, respectively. Concatenate the above strings as below:\n    \\begin{itemize}\n      \\item Use bracket to concatenate \\verb|helloChar| and \\verb|worldChar| horizontally and assign it to \\verb|helloWorldChar1|. Repeat this to \\verb|helloString| and \\verb|worldString|, then store the result to \\verb|helloWorldString1|.\n      \\item Now use \\verb|strcat| instead of bracket (use \\verb|help strcat| to check out the syntax) to repeat the above. Store the results to \\verb|helloWorldChar2| and \\verb|helloWorldString2|.\n    \\end{itemize}\n\\item Use \\verb|class| and \\verb|length| to determine the types and lengths of \\verb|helloWorldChar1|, \\verb|helloWorldChar2|, \\verb|helloWorldString1|, \\verb|helloWorldString2|. Create variables with suffix \\verb|Class| or \\verb|Length| to store the corresponding results. For example, the length of \\verb|helloWorldChar1| should be stored as \\verb|helloWorldChar1Length|.\n\\end{enumerate}\n\n%---------------------------------------------\n\\section{Application: Image Processing}\n%---------------------------------------------\nNext we will process Figure \\ref{fig:a} to produce Figure \\ref{fig:b} in MATLAB. For this portion, suppress the output if it is more than 10 lines by putting \\verb|;| at the end of the statement.\n\\begin{figure}[!hbtp]\n  \\centering\n  \\begin{subfigure}[b]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[width=80pt]{../pics/UW_gray.png}\n    \\caption{\\texttt{UW_gray.png}}\n    \\label{fig:a}\n  \\end{subfigure}\n  \\begin{subfigure}[b]{0.25\\textwidth}\n    \\centering\n    \\includegraphics[width=80pt]{../pics/UW_gray_new.png}\n    \\caption{\\texttt{UW_gray_new.png}}\n    \\label{fig:b}\n  \\end{subfigure}\n  \\caption{UWyo Logo}\n\\end{figure}\n\n\\begin{enumerate}[(a)]\n  \\item Read \\verb|UW_gray.png| and store it to \\verb|uwGray| using \\verb|imread|. Check the size of \\verb|uwGray| and store the size to \\verb|uwGraySize|. Find the maximal eigenvalue of the matrix \\verb|double(uwGray)| and store it to \\verb|maxEigenvalue|.\n  \\item Crop the Steamboat out of the logo by extracting a submatrix from \\verb|uwGray| which starts from row 1 to row 650 and from column 171 to column 650, and save it to \\verb|steamboatLeft|. Flip \\verb|steamboatLeft| and store it to \\verb|steamboatRight|. Then create \\verb|steamboat| by concatenating matrix \\verb|steamboatLeft| and \\verb|steamboatRight|.\n  \\item Extracting the name \\verb|uwName| from \\verb|uwGray| which starts from row 651 to row 960 (with all columns). Stack \\verb|steamboat| and \\verb|uwName| to create \\verb|uwGrayNew|. Check the size of \\verb|uwGrayNew| which should be $960 \\times 960$. If it is correct, write \\verb|uwGrayNew| to a file named \\verb|UW_gray_new.png| using \\verb|imwrite|. List all the variables in the workspace using \\verb|whos|.\n\\end{enumerate}\n\n% %---------------------------------------------\n% \\section{Defining Variables}\n% %---------------------------------------------\n% \\begin{enumerate}[(a)]\n%     \\item Define the variable \\verb|old_sin_pi = sin(pi)|, then define \\verb`pi = 1.25`, and compute \\verb`new_sin_pi = sin(pi)`. Compare \\verb|old_sin_pi| and \\verb|new_sin_pi|.\n%     \\item Now define \\verb`sin = 2.1`. Use \\verb`who` and then \\verb`whos` to display the list of your currently used variables. Then, evaluate \\verb`sin(pi)` in the \\verb|try-catch| block.\n%     \\item Assign \\verb`5 + i`, \\verb`6 + j` to \\verb`a`, \\verb`b`, respectively. Then perform summation to \\verb`a` and \\verb`b` and assign the result to \\verb`c`.\n% \\end{enumerate}\n% %---------------------------------------------\n% \\section{Arrays: Vectors \\& Matrices}\n% %---------------------------------------------\n% \\begin{enumerate}[(a)]\n%     \\item Use \\verb`clear` command to clear the variab:sp les in the Workspace.\n%     \\item Use \\verb`linspace` to create a vector $x$ with 10 entries ranging from $0$ to $2\\pi$, then assign the transpose of \\verb`x` to the variable named \\verb`x_transpose` using either \\verb`'` or \\verb`transpose`. Then use the function \\verb`length` to find the length to \\verb`x_transpose`.\n%     \\item Use either \\verb`:` or \\verb`colon` to create a column vector \\verb`v`, of which the range is from 2 to 25 with step size 2. Then use \\verb`reshape` to change \\verb`v` to a $3 \\times 4$ matrix \\verb`V`. Find the size of \\verb`V` using \\verb`size`.\n%     \\item Define the following two matrices,\n%         $$\n%         A =\n%         \\begin{bmatrix}\n%             1 & 2 \\\\\n%             3 & 4 \\\\\n%         \\end{bmatrix}, \\quad\n%         B =\n%         \\begin{bmatrix}\n%             5 & 6 \\\\\n%             7 & 8 \\\\\n%         \\end{bmatrix}.\n%         $$\n%         Then store the result of matrix multiplication \\verb`A * B` to \\verb`C` and the result of element-wise multiplication \\verb`A .* B` to \\verb`D`. Observe the difference between these two operations.\n%     \\item Create a $5 \\times 5$ magic square matrix \\verb`M`. Extract the submatrix of \\verb`M` (from row $2$ to row $4$ and from column $3$ to column $5$), and store the submatrix to \\verb`M_submatrix`. Then create a vector \\verb`M_last_col` by extracting the last column of \\verb|M|.\n%     \\item Create a $4 \\times 4$ identity matrix \\verb`I` using \\verb`eye`, a $6 \\times 3$ all-one matrix \\verb`N` using \\verb`ones`, a $3 \\times 4$ all-zero matrix \\verb`O` using \\verb`zeros`.\n% \\end{enumerate}\n\nIn the Command Window enter the command \\verb`diary('lab_02_output.txt')`, run the script file \\verb|lab_02_script.m|, then type \\verb`diary off` to store the output to \\verb`lab_02_output.txt`. Then upload the script file \\verb|lab_02_script.m|, output file \\verb|lab_02_output.txt|, and \\verb|UW_gray_new.png| to the folder \\verb|src| on Overleaf. Next open \\verb|body.tex| under the folder \\verb|LaTeX|. In the last section of the report, you will reproduce the following using \\LaTeX{}. Recompile, and submit the generated \\verb|.pdf| file to WyoCourses.\n%\n\\newpage\n\n\\section{Basics of \\LaTeX{}}\n\\label{sec:bol}\n\\subsection{Sine functions}\nFor given $x \\in [0, 2\\pi]$ with step size $\\pi/12$, we can obtain the evaluations of \\eqref{eq:sine} at $x$ (see Table \\ref{tab:sine}), and the corresponding plot (see Figure \\ref{fig:sine}).\n\n\\begin{equation}\n  \\label{eq:sine}\n  \\begin{cases}\n    y_1 = \\sin(x/2) \\\\\n    y_2 = \\sin(x)   \\\\\n    y_3 = \\sin(2x)\n  \\end{cases}\n\\end{equation}\n\\begin{table}[!hbtp]\n\\centering\n\\caption{Sine functions}\n\\label{tab:sine}\n\\begin{tabular}{ccrr}\n\\toprule\n        $x$ & $\\sin(x/2)$ &   $\\sin(x)$ &  $\\sin(2x)$ \\\\\n\\midrule\n$0$      & $0$          & $0$  & $0$ \\\\\n$\\pi/2$  & $\\sqrt{2}/2$ & $1$  & $0$ \\\\\n$\\pi$    & $1$          & $0$  & $0$ \\\\\n$3\\pi/2$ & $\\sqrt{2}/2$ & $-1$ & $0$ \\\\\n$2\\pi$   & $0$          & $0$  & $0$ \\\\\n\\bottomrule\n\\end{tabular}\n\\end{table}\n\\begin{figure}[!hbtp]\n  \\centering\n  \\includegraphics[width=0.3\\textheight]{./fig/sine.pdf}\n  \\caption{Sine functions}\n  \\label{fig:sine}\n\\end{figure}\n\n\\subsection{Goldbach's Conjecture}\nPursuing this type of analysis more carefully, Hardy and Littlewood in 1923 conjectured (as part of their famous \\textsl{Hardy–Littlewood prime tuple conjecture}) that for any fixed $c \\geq 2$, the number of representations of a large integer $n$ as the sum of $c$ primes $n = p_1 + \\cdots + p_{c}$ with $p_1 \\leq \\cdots \\leq p_c$ should be asymptotically equal to\n\\begin{equation}\n    \\label{eq:hardy}\n    \\left( \\prod_{p} \\frac{p \\gamma_{c,p} (n)}{(p - 1)^c}\\right) \\int_{2 \\leq x_1 \\leq \\cdots \\leq x_c: x_1 + \\cdots + x_c = n} \\frac{d x_1 \\cdots d x_{c - 1}}{\\ln{x_1} \\cdots \\ln{x_c}},\n\\end{equation}\nwhere the product is over all primes $p$, and $\\gamma_{c, p}(n)$ is the number of solutions to the equation $n = q_1 + \\cdots + q_c \\mod p$ in modular arithmetic, subject to the constraints $q_1, \\ldots, q_c \\ne 0 \\mod p$. This formula \\eqref{eq:hardy} has been rigorously proven to be asymptotically valid for $c \\geq 3$ from the work of Vinogradov, but is till only a conjecture when $c = 2$. In the latter case, the above formula simplifies to $0$ when $n$ is odd, and to\n$$\n2 \\Pi_2 \\left( \\prod_{p|n; p \\geq 3} \\frac{p - 1}{p - 2} \\right) \\int_{2}^{n} \\frac{dx}{(\\ln{x})^2} \\approx 2 \\Pi_2 \\left( \\prod_{p|n; p \\geq 3} \\frac{p - 1}{p - 2} \\right) \\frac{n}{(\\ln{n})^2},\n$$\nwhen $n$ is even, where $\\Pi_2$ is Hardy-Littlewood's twin prime constant\n$$\n\\Pi_2 := \\prod_{p \\geq 3} \\left( 1 - \\frac{1}{(p - 1)^2} \\right) = 0.6601618158\\ldots\n$$\nThis sometimes known as the \\textsf{extended Goldbach conjecture}.\n\n\\emph{Reference}: \\href{https://en.wikipedia.org/wiki/Goldbach's_conjecture}{Goldbach's conjecture}.\n", "meta": {"hexsha": "4911b4eaece82914a5d636be27616af30348e590", "size": 12028, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.02/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 74.7080745342, "max_line_length": 558, "alphanum_fraction": 0.6605420685, "num_tokens": 3768, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8519527906914788, "lm_q2_score": 0.8902942253943279, "lm_q1q2_score": 0.7584886498612061}}
{"text": "\\section{Problem Statement}\n\\label{sec:problem}\n\nThe goal of our algorithm is to detect errors in a relational, structured dataset~$D$ by letting the user progressively label attribute values as erroneous or correct.\nWe denote $D = \\{t_{1}, t_{2}, ..., t_{N}\\}$ as a dataset of size~$N$, where each $t_{i}$ represents a tuple. \nLet $A = \\{a_{1}, a_{2}, ..., a_{M}\\}$ be the schema with attributes~$a_{j}$. Then, $D[i, j]$ represents the cell value of the attribute~$a_{j}$ in the tuple~$t_{i}$.\nWe denote $D_{C}$ as the cleaned version of $D$ representing the ground truth. \nThus, we define an error as any cell value~$D[i, j]$ that deviates from its ground truth value~$D_{C}[i, j]$. \nThis error definition is common in error detection research \\cite{rekatsinas2017holoclean,abedjan2016detecting}.\n\nOur goal is to formulate the problem of error detection as a classification task. \nTherefore, the first problem is to identify the right feature representation $\\rho$, which maps each cell~$D[i, j]$ to a numerical feature vector.\nUsing this feature representation $\\rho$, for each column~$D[:,j]$, we train a model $\\phi_{j}$ that learns to classify whether a cell value~$D[i, j]$ is erroneous or correct.\nThe second problem that we want to solve is, given a user-defined labeling budget~$L$, to choose the optimal training set for each column~$D[:,j]$ to maximize the $F_{1}$-score on the whole dataset~$D$. The error detection $F_{1}$-score is defined as \n\n\\begin{equation} \\label{equation:problem2}\n\tF_1 = 2 \\times (P \\times R) /(P + R),\n\\end{equation}\n\nwhere the precision~(P) is the fraction of cells that are correctly detected as errors and the recall~(R) is the fraction of the actual errors that are discovered.\n\nTo address the two mentioned problems, we have to design a fitting sampling strategy and identify the appropriate set of features. Our approach does not require additional user-defined configuration, such as user-defined rules, patterns nor model-specific, manual hyperparameter tuning.\n", "meta": {"hexsha": "0dd27ab66ed2191da176c34675336f07907dd60c", "size": 2009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "documents/sections/problem.tex", "max_stars_repo_name": "BigDaMa/error-generator", "max_stars_repo_head_hexsha": "7d8949fc8fb00b6285c7c220dbda7451dc152e44", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2018-11-11T07:52:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-06-19T05:44:55.000Z", "max_issues_repo_path": "documents/sections/problem.tex", "max_issues_repo_name": "BigDaMa/error-generator", "max_issues_repo_head_hexsha": "7d8949fc8fb00b6285c7c220dbda7451dc152e44", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2018-07-20T15:08:23.000Z", "max_issues_repo_issues_event_max_datetime": "2018-11-21T13:18:01.000Z", "max_forks_repo_path": "documents/sections/problem.tex", "max_forks_repo_name": "BigDaMa/error-generator", "max_forks_repo_head_hexsha": "7d8949fc8fb00b6285c7c220dbda7451dc152e44", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-11-25T15:16:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-25T15:16:16.000Z", "avg_line_length": 87.347826087, "max_line_length": 286, "alphanum_fraction": 0.7441513191, "num_tokens": 524, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072386, "lm_q2_score": 0.8267117940706734, "lm_q1q2_score": 0.7583449311499035}}
{"text": "\\section{Fundamentals}\n\n \\subsection{Exercise 1}\n $x + z = x = x + z' \\implies z = z'$.\n\n \\subsection{Exercise 2}\n $0x + x = (0 + 1)x = x$.\n\n \\subsection{Exercise 3}\n Coefficients can be represented as row vectors.\n\n \\subsection{Exercise 4}\n Function can be represented as row vector by letting $a_i = f(s_i)$ for each $s_i \\in S$.\n\n \\subsection{Exercise 5}\n Follows from exercises 3 and 4.\n\n \\subsection{Exercise 6}\n $y_1 + z_1 + y_2 + z_2 = (y_1 + y_2) + (z_1 + z_2)$ and $k(y_1 + z_1) = ky_1 + kz_1$.\n\n \\subsection{Exercise 7}\n $a \\in Y \\cap Z \\implies ka \\in Y, ka \\in Z \\implies ka \\in Y \\cap Z$.\n\n \\subsection{Exercise 8}\n $k0 = 0, 0 + 0 =0$.\n\n \\subsection{Exercise 9}\n If $S$ contains $x_i$ then it must contain  $kx_i$.\n\n \\subsection{Exercise 10}\n If $x_i = 0$, $k_i$ can be anything.\n\n \\subsection{Exercise 11}\n $x = \\sum_{i=1}^{m} \\sum_{j=1}^{\\text{dim}Y_i} y_j^{(i)}$.\n\n \\subsection{Exercise 12}\n Complete basis for $W$ to  $U$ and  $V$. Use  $W$ basis vectors and additional  $U$ and $V$ basis vectors to get\n $\\text{dim}X = \\text{dim}U - \\text{dim}W + \\text{dim}V - \\text{dim}W + \\text{dim}W$.\n\n \\subsection{Exercise 13}\n Send $i^{\\text{th}}$ basis vector to $e_i$, where $e_i$ is vector of all zeroes except a one in the  $i^{\\text{th}}$ place.\n Can permute mapping to get different isomorphisms.\n\n \\subsection{Exercise 14}\n $x_1 - x_2 + x_2 - x_3 = x_1 - x_3$.\n\n \\subsection{Exercise 15}\n $x' = x + z_x, y' = y + z_y \\implies x' + y' = x + y + (z_x + z_y)$.\n\n \\subsection{Exercise 16}\n $x \\in X_1 \\bigoplus X_2 \\implies x = (x_1, x_2) = (x_1, 0) + (0, x_2)$.\n\n \\subsection{Exercise 17}\n Construct a basis for $X$ from  $Y$:\n $y_1, ..., y_j, x_{j+1}, ..., x_n$.\n \\\\ \n Then $X / Y = \\text{span}\\{x_{j+1}, ..., x_n\\}$.\n\n", "meta": {"hexsha": "49463238f6c59e4774e6872a75146d51c12cb729", "size": 1732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": "Linear_Algebra_Lax/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": 29.3559322034, "max_line_length": 124, "alphanum_fraction": 0.6137413395, "num_tokens": 690, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026595857203, "lm_q2_score": 0.8267117962054049, "lm_q1q2_score": 0.7583449293701059}}
{"text": "\\chapter{Dirac Delta Function}\nIn mathematical models of physical systems we often come across functions that have finite or infinite discontinuities (Potential barriers, Impulse functions). Even though they dont belongs to the generalm definition of functions we can represent them as generalised function or distributions. The most common among them are the step function and the dirac delta function.\n\\section{The Step Function}\nLet's start with the definition of the unit step function, $\\theta(x)$ :\n$$\n\\theta(x)=\\left\\{\\begin{array}{ll}\n0 & \\text { for } x<0 \\\\\n1 & \\text { for } x>0\n\\end{array}\\right.\n$$\nWe do not define $\\theta(x)$ at $x=0$. Rather, at $x=0$ we think of it as in transition between 0 and 1 .The function is called the unit step function because it takes a unit step at $x=0$. It is sometimes called the \\textbf{Heaviside function}. The graph of $\\theta(x)$ is simple.\nIt is obvious that $\\theta(x)$ has a finite jump at $x=0$. It is sometimes convenient to define $\\theta(0)$ to be the average value $\\frac{1}{2}$, but this is not always necessary.\n\\begin{align*}\n\\text{The sum } \\ \\theta(x)+\\theta(-x)&=1\\\\\n\\text{The difference}\\ \\theta(x)-\\theta(-x)&=\\varepsilon(x)\n\\end{align*}\nWhere, $\\varepsilon(x)$ is the signum function.\n\\begin{equation}\n\\varepsilon(x)=\\left\\{\\begin{array}{rr}\n+1 & \\text { for } x>0 \\\\\n-1 & \\text { for } x<0 \\\\\n0 & \\text { for } x=0\n\\end{array}\\right.\n\\end{equation} The function $\\varepsilon(x)$ looks like the limit of a tanh (or hyperbolic tangent) function as the 'kink' in the function becomes more and more steep, i.e., as the slope at the origin tends to infinity, as shown in Figure.\\ref{Dirac delta} In fact, we could define $\\varepsilon(x)$ as the limit of a continous sequence of functions $\\tanh(\\frac{x}{\\varepsilon(x)})$.\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=4cm,width=5cm]{unit step function}\n\t\\caption{The function of $ \\tanh{(x/\\epsilon)} $}\n\t\\label{Dirac delta}\n\\end{figure}\n\\section{Dirac Delta Function}\n\\subsection{Kronecker delta $\\delta$}\nlet us consider a sequence $\\left(a_{1}, a_{2}, \\ldots\\right)=\\left\\{a_{j} \\mid j=1,2, \\ldots\\right\\} .$ How do we select a particular member $a_{i}$ from the sequence? We do so by summing over all members of the sequence with a selector called the \\textbf{Kronecker delta}, denoted by $\\delta_{i j}$ and defined as\n$\\delta_{i j} \\stackrel{\\text { def. }}{=}\\left\\{\\begin{array}{ll}1 & \\text { if } i=j \\\\ 0 & \\text { if } i \\neq j\\end{array}\\right.$\nIt follows immediately that\n\\begin{align*}\n\\sum_{j} \\delta_{i j} a_{j}&=a_{i}\\\\\n\\sum_{j} \\delta_{i j}&=a_{i}\\qquad \\text{For each value of } \\ i\\\\\n\\delta_{i j}&=\\delta_{j i} \\qquad \\text{Symmetry property. }\n\\end{align*}\nNow if  we have a continuos function, we must replace the summation over  $j$ by an integration over $x$. The role of the specified index $i$ is played by the specified point $a$. The analog of the Kronecker delta is written like a function, retaining the same symbol $\\delta$ for it. So we seek a `function' $\\delta\\left(x-a\\right)$ such that\n\\begin{equation}\n\\int_{-\\infty}^{\\infty}  \\delta\\left(x-a\\right) f(x) d x=f\\left(a\\right)\n\\end{equation}\nExactly as in the discrete case of the Kronecker delta, we impose the normalization and symmetry properties,\n\\begin{equation}\n\\int_{-\\infty}^{\\infty} \\delta\\left(x-a\\right) d x=1 \\quad \\text { and } \\quad \\delta\\left(x-a\\right)=\\delta\\left(a-x\\right)\n\\end{equation}\n $\\delta\\left(x-a\\right)$ is more like the kernel of an integral\n \\begin{equation}\n \\int_{-\\infty}^{\\infty} \\delta\\left(x-a\\right) d x=0 \\quad \\text { if } \\quad x \\neq a \\quad \\text{Or the limit of integration excludes the point `$a$'} \n \\end{equation}\n \\section{Various representations of Delta function}\n The delta function may be approximated by the sequences of functions, \n $$\n \\begin{array}{l}\n \\delta_{n}(x)=\\left\\{\\begin{array}{ll}\n 0, & x<-\\frac{1}{2 n} \\\\\n n, & -\\frac{1}{2 n}<x<\\frac{1}{2 n} \\\\\n 0, & x>\\frac{1}{2 n}\n \\end{array}\\right. \\\\\\\\\n \\delta_{n}(x)=\\frac{n}{\\sqrt{\\pi}} \\exp \\left(-n^{2} x^{2}\\right) \\\\\\\\\n \\delta_{n}(x)=\\frac{n}{\\pi} \\cdot \\frac{1}{1+n^{2} x^{2}} \\\\\\\\\n \\delta_{n}(x)=\\frac{\\sin n x}{\\pi x}=\\frac{1}{2 \\pi} \\int_{-n}^{n} e^{i x t} d t\n \\end{array}\n $$\n These approximations have varying degrees of usefulness.\\\\\n \\begin{minipage}{0.45\\textwidth}\n \t\\begin{figure}[H]\n \t\t\\centering\n \t\t\\includegraphics[height=3cm,width=3cm]{Dirac delta 1}\n \t\\end{figure}\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=3cm,width=3cm]{Dirac delta 2}\n \\end{figure}\n \\end{minipage}\n\\begin{minipage}{0.45\\textwidth}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=3cm]{Dirac delta 3}\n\t\\end{figure}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3cm,width=3cm]{Dirac delta 4}\n\t\\end{figure}\n\\end{minipage}\n \n \\subsection{Rectangular Function}\n Let us consider a rectangular fuunction defined as,\n \\begin{equation}\nR_{\\varepsilon} =\\left\\{\\begin{array}{ll} \\frac{1}{2\\varepsilon} & a-\\varepsilon < x< a+\\varepsilon \\\\ 0 & \\text{Otherwise }\\end{array}\\right. \n \\end{equation} \n We can consider  this as a rectangular window of width $2\\varepsilon$ and height $\\frac{1}{2\\varepsilon}$ so that the area is unity. Let us plot the function as shown in the figure below,\n \\begin{figure}[H]\n \t\\centering\n \t\\includegraphics[height=4cm,width=6cm]{Rectangular}\n \t\\caption{Rectangular function}\n \t\\label{Rectangular function}\n \\end{figure}\nWhen the window is centred at the choosen point $x_{0}$, the integral of $f(x)$ multiplied by this window function is,\n\\begin{align*}\n\\frac{1}{2 \\varepsilon} \\int_{a-\\varepsilon}^{a+\\varepsilon} dx f(x)\n\\intertext{if we take the limit,$\\varepsilon \\rightarrow 0$ The window becomes vanishingly small and it's height become arbitrarily large such that the area under the curve remains the same.} \n\\intertext{Then in the limit, $\\varepsilon \\rightarrow 0 $}\n\\lim_{\\varepsilon \\to 0} R_{\\varepsilon} = \\delta(x-a)\n\\end{align*}\nAn explicit form of the dirac delta function make sense only when it occures in an integral like, \n\\begin{equation}\n\\int_{-\\infty}^{\\infty} \\delta(x-a)f(x)dx \\label{Dirac delta 001 }\n\\end{equation}\nwhen it acts on ordinary function like $f(x)$ and an integration over $x$ is carried out . Then the value of \\ref{Dirac delta 001 } \n\\begin{align}\n\\int_{-\\infty}^{\\infty} \\delta(x-a)f(x)dx &=\\int_{a-\\varepsilon}^{a+\\varepsilon} \\delta(x-a)f(x)dx\n\\intertext{in the range ${a-\\varepsilon} , {a+\\varepsilon}$ as $\\varepsilon \\rightarrow 0$ the function is almost constant }\n\\int_{-\\infty}^{\\infty} \\delta(x-a)f(x)dx &=f(a) \\lim_{\\varepsilon \\to 0} \\int_{a-\\varepsilon}^{a+\\varepsilon} R_{\\varepsilon} dx\\\\\n&=f(a)\n\\end{align}\n\\section{Integral Representations for the Delta Function}\nIntegral transforms, such as the Fourier integral\n\\begin{equation}\nF(\\omega)=\\int_{-\\infty}^{\\infty} f(t) \\exp (i \\omega t) d t\n\\end{equation}\nLead to the corresponding integral representations of Dirac's delta function. For example, take\n\\begin{equation}\n\\delta_{n}(t-x)=\\frac{\\sin n(t-x)}{\\pi(t-x)}=\\frac{1}{2 \\pi} \\int_{-n}^{n} \\exp (i \\omega(t-x)) d \\omega \\label{Dirac delta 007}\n\\end{equation}\nUsing Equation \\ref{Dirac delta 007}. We have\n$$\nf(x)=\\lim _{n \\rightarrow \\infty} \\int_{-\\infty}^{\\infty} f(t) \\delta_{n}(t-x) d t,\n$$\nwhere $\\delta_{n}(t-x)$ is the sequence in Eq. (1.192) defining the distribution $\\delta(t-x)$. Note that Eq. (1.193a) assumes that $f(t)$ is continuous at $t=x$. If we substitute Eq. (1.192) into Eq. (1.193a) we obtain\n$$\nf(x)=\\lim _{n \\rightarrow \\infty} \\frac{1}{2 \\pi} \\int_{-\\infty}^{\\infty} f(t) \\int_{-n}^{n} \\exp (i \\omega(t-x)) d \\omega d t .\n$$\nInterchanging the order of integration and then taking the limit as $n \\rightarrow \\infty$, we have the Fourier integral theorem, Eq. (15.20).\nWith the understanding that it belongs under an integral sign, as in Eq. (1.193a), the identification\n\\section{The derivative of the $\\delta$ function}\nConsider a bell shaped symmetric function peaked around $x=x_0$ and parametrized by $\\varepsilon$ as $\\varepsilon\\rightarrow0$ the function resembles a dirac delta and the derivative starts to oscillate between positive and negative values around $x=x_0$. So the derivative $\\delta^\\prime(n-n_0)$ is more singular than $8(x-x_0)$\n\\begin{align*}\n\\text{Finally }\\quad&\\frac{d^n}{dx^n}\\delta(n)\\text{ is odd $=n$ odd}\\\\\n\\delta^\\prime(-x)&=-\\delta^0(x)\\text{ even $=n$ even}\\\\\n\\text{and}\\quad \\delta^\\prime (x) &=\\frac{-\\delta(x)}{x}\\\\\n\\text{with} &\\int\\limits_{-\\propto}^{+\\propto}\\delta^\\prime (x)f(x)dx=-f^\\prime(a)\n\\end{align*}\nProof: $\\int\\limits_{-\\propto}^{+\\propto}\\delta^\\prime (x-a)f(x)dx=f(x)\\int\\limits_{-\\propto}^{+\\propto}\\delta^\\prime (x-a)-\\int\\limits_{-\\propto}^{+\\propto}(f^\\prime (x)\\delta^\\prime(x-a)dx)dx$\\\\\\\\\n$=0-\\int f^\\prime(x)\\delta(x-a)=-f^\\prime(a),$proved\n\\section{The occurance of $\\delta$-function in physical problems}\n\\begin{enumerate}\n\t\\item The dirac delta function models the density of a point source. Could be change density mass density etc.\\\\\n\teg:3$\\delta(x-x_0)$$\\rightarrow$ a charge $3c$ placed at $x=x_0$\n\t\\item Suppose $P(x)dx$ represent the probability distribution for age group of students than if we have a part probability say $N$ student has exactly age $x_g$ then $P(x)dx+N\\delta(x-x_g)$\n\t\\item An impulse function in 3-D\\\\\n\t\\begin{align*}\n\t\\delta^3(r)&=\\delta(x-x_0)\\delta(y-y_0)\\delta(z-z_0)\\\\\n\t&=\\frac{1}{(2\\pi)^3}\\int\\limits_{+\\propto}^{-\\propto}dk_1\\int\\limits_{+\\propto}^{-\\propto}dk_2\\int\\limits_{+\\propto}^{-\\propto}dk_3 e^{ikx_1+k_2y+k_3z}\\\\\n\t\\delta^3(r)&=\\frac{1}{(2\\pi)^3}\\int d^3ke^{ik\\cdot r}\n\t\\end{align*}\n\\end{enumerate}\nThe dimension of $\\delta(x)$will be the inverse $x$ \\\\\nif $x$ has a dimenssion $L$\\\\\nThen $ \\left[ \\delta(x)\\right]\\left[ L^{-1}\\right]  $\n", "meta": {"hexsha": "701b314e91e2b21a5954fc921967b438aca4eaea", "size": 9711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Dirac delta function.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/Dirac delta function.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/Dirac delta function.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.5766871166, "max_line_length": 383, "alphanum_fraction": 0.6942642364, "num_tokens": 3287, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392909114835, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7583007105162541}}
{"text": "\\chapter{Necessary theory}\nTo continue with the NHPP model, some more theory have to be introduced. This theory includes likelihood function and transformation of variables.\n\\section{Likelihood and estimators}\n\\label{chap:like}\nIn this section likelihood and its estimators are introduced.\nTo summarize data the likelihood function can be used. The theory presented here is from \\cite{casella2002statistical}. The likelihood function is defined in the following definiton.\n\\begin{defn}\nLet $f(\\boldsymbol{x}|\\Theta)$ denote the joint pdf or pmf of the sample $\\boldsymbol{X} = (X_1,...,X_n)$. Then, given that $\\boldsymbol{X} = \\boldsymbol{x}$ is observed, the function $\\Theta$ is defined by\n\\begin{equation}\nL(\\Theta | \\boldsymbol{x}) = f(\\boldsymbol{x}|\\Theta)\n\\label{eq:like}\n\\end{equation}\nis called the likelihood function.\n\\end{defn}\nBy using this function one can find estimators for $\\Theta$. These estimators are the ones that maximizes the likelihood function. Furthermore these estimators are most likely. Hence the they are given the name maximum likelihood estimators. The formal definition is as follows\n\\begin{defn} % side 316\nFor each sample point $\\boldsymbol{x}$, let $\\hat{\\Theta}(\\boldsymbol{x})$ be parameter value at which $L(\\Theta | \\boldsymbol{x})$ attains its maximum as a function of $\\Theta$, with $\\boldsymbol{x}$ held fixed. A maximum likelihood estimator(MLE) of the parameter $\\Theta$ based on a sample $\\boldsymbol{X}$ is $\\hat{\\Theta}(\\boldsymbol{X})$.\n\\end{defn}\nThe maximum of the likelihood can be found analytically or numerically. Analytically it is recommended to take the log of the likelihood function. This for easier differentiation. Hence it is recommended to solve\n\\begin{equation*}\n\\frac{\\partial \\log L(\\Theta | \\boldsymbol{x})}{\\partial \\Theta_i} = 0, \\quad i = 1,...,k.\n\\end{equation*}\nThis will give the MLE of $\\Theta$.\n\n\\section{Transformation of variables}\n\\label{sec:transvar}\nFor this section we will show tranformation of variables from a distribution to another distribution. From \\cite{casella2002statistical} we have a theorem for tranformation of variables. The theorem in one dimension is given as follows.\n\\begin{theorem}\n\\label{th:transvar}\nLet $X$ have pdf $f_X (x)$, let $Y=g(X)$, where $g$ is a monotone function. Let $\\mathcal{X} = \\{x: f_X (x) > 0\\}$ and $\\mathcal{Y} = \\{ y: y = g(x)$ for some $x \\in \\mathcal{X} \\}$. Suppose that $f_x(x)$ is continuous on $\\mathcal{X}$ and that $g^{-1}(y)$ has a continuous derivative on $\\mathcal{Y}$. Then the pdf of $Y$ is given by\n\\begin{equation*}\nf_Y (y) = \n\\begin{cases}\nf_X(g^{-1}(y)) \\left| \\frac{d}{dy} g^{-1}(y) \\right| & y \\in \\mathcal{Y} \\\\\n0 & \\text{otherwise.}\n\\end{cases}\n\\end{equation*}\n\\end{theorem}\nFor multivariate the pdf of $Y$ is given by\n\\begin{equation*}\nf_Y (y) = \n\\begin{cases}\nf_X(g^{-1}(y)) \\left| J(g^{-1}(y)) \\right| & y \\in \\mathcal{Y} \\\\\n0 & \\text{otherwise,}\n\\end{cases}\n\\end{equation*}\nwhere $J$ is the Jacobian matrix. For the multivariate the requirements for $g$ is that the inverse exists and is unique.", "meta": {"hexsha": "0aa6e187fd6c3f48e55e1325e7676ceb149ac523", "size": 3048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapters/nectheory.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/nectheory.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/nectheory.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": 64.8510638298, "max_line_length": 344, "alphanum_fraction": 0.7276902887, "num_tokens": 890, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392848011834, "lm_q2_score": 0.857768108626046, "lm_q1q2_score": 0.7583007052750336}}
{"text": "\\subsection{Group Actions}\n\nLet $G$ be a group acting on a topological space $X$ via $G\\times X\\to X$,\n$(g,x)\\mapsto g\\cdot x=g(x)$ such that\n\\begin{itemize}\n\\item each map $x\\mapsto g\\cdot x$ is continuous (as a fn $X\\to X$)\n\\item $e\\cdot x=x$\n\\item $g\\cdot(h\\cdot x)=(gh)\\cdot x$ $\\forall g,h\\in G,x\\in X,e=\\text{id}_{G}$.\n\\end{itemize}\nthen $x\\mapsto g\\cdot x=g(x)$ is a homeomorphism.\n\\begin{defn}\nThe \\emph{orbit} of a point $x$ is $G\\cdot x=\\{g\\cdot x\\mid g\\in G\\}$.\nThe \\emph{orbit space} $X\\backslash G$ (or $X/G$) is $X/\\sim$ where\n$x\\sim y\\Leftrightarrow y=g\\cdot x$ for some $g\\in G$.\n\\end{defn}\n\n\\begin{defn}\nThe free group $F(S)$ generated by $S$ is the set of all reduced\nwords in $S$ with multiplication defined by juxtaposition followed\nby reduction.\\end{defn}\n\\begin{prop}\nIf $G$ is a group generated by a subset $S$, and $F=F(S)$, then\n$G$ is a quotient of $F$.\\end{prop}\n\\begin{proof}\nThe inclusion $f:S\\hookrightarrow G$ extends to a homomorphism $\\bar{f}:F(S)\\to G$.\nThen $S=\\{\\text{set of generators}\\}$ so $\\bar{f}$ is onto. The\nFirst Isomorphism Theorem then says $G\\cong F/N$, $N=\\text{ker}(\\bar{f})=\\text{normal subgroup of F}.$\\end{proof}\n\\begin{defn}\nA group $G$ is defined by a set of generators $S$ and a set of relators\n$R$. $G\\cong F(S)/N(R)$ where $N(R)=\\{\\text{smallest normal subgroup containing \\ensuremath{R}}\\}=\\text{\"normal closure of \\ensuremath{R}\"}.$\nWe write $G=\\langle S\\mid R\\rangle$. A group is \\emph{finitely presented}\nif both sets are finite.\\end{defn}\n\\begin{prop}\nLet $G=\\langle S\\mid R\\rangle$, $H$ any group, and $f:S\\to H$ any\nfunction. Then $f$ extends to a homomorphism $\\tilde{f}:G\\to H$\niff $f(x_{i})^{\\epsilon_{1}}\\cdots f(x_{n})^{\\epsilon_{n}}=1$ for\nevery relator $x_{1}^{\\epsilon_{1}}\\cdots x_{n}^{\\epsilon_{n}}$.\n\\end{prop}\n\\textit{\\emph{Constrstructions}}\n\nDirect product: $G_{1}\\times G_{2}=\\langle S_{1},S_{2}\\mid R_{1},R_{2},[x,y]=1\\forall x\\in S_{1},\\forall y\\in S_{2}\\rangle.$\n\nFree product: $G_{1}*G_{2}=\\langle S_{1},S_{2}\\mid R_{1},R_{2}\\rangle$\n\nand Abelianisation: $G^{ab}=\\langle S\\mid R,[xy]=1\\forall x,y\\in S\\rangle$\n\nNote: Every finitely-generated Abelian group is isomorphic to a direct\nproduct of cyclic groups $A\\cong\\mathbb{Z}^{n}\\oplus\\mathbb{Z}_{d_{1}}\\oplus\\cdots\\oplus\\mathbb{Z}_{d_{k}}.$\n\\begin{lem}\n(Lebesgue number lemma) Let $(X,d)$ be a compact metrix space. Given\nany open cover $\\{U_{\\alpha}\\}$ of $X$, $\\exists\\delta>0$, the\nLebesgue number, such that any subset of $X$ with $\\text{diam}<\\delta$\nis contained in one of the $U_{\\alpha}$.\n\\end{lem}\nWe can use this to help prove Seifert-van Kampen.\n\\begin{thm}\n(Seifert-van Kampen Theorem)\n\nLet $X=U_{1}\\cup U_{2}$ with $U_{1},U_{2},U_{0}=U_{1}\\cap U_{2}$\nare all open, non-empty and path connected. Choose a basepoint $x_{0}\\in U_{0}$\nfor all fundamental groups that we will be looking at. We have the\ninclusion maps\n\n\\begin{align*}\n\\xymatrix{ & U_{1}\\ar[dr]_{j_{1}}\\\\\nU_{0}\\ar[ur]^{i_{1}}\\ar[dr]_{i_{2}} &  & X\\\\\n & U_{2}\\ar[ur]_{j_{2}}\n}\n\\end{align*}\n\n\nwhich induces the homomorphisms\n\n\\begin{align*}\n\\xymatrix{ & \\pi_{1}(U_{1})\\ar[dr]_{j_{1*}}\\\\\n\\pi_{1}(U_{0})\\ar[ur]^{i_{1*}}\\ar[dr]_{i_{2*}} &  & \\pi_{1}(X)\\\\\n & \\pi_{1}(U_{2})\\ar[ur]_{j_{2*}}\n}\n\\end{align*}\n\n\nthen, $\\pi_{1}(X)$ is obtained from the free product $\\pi_{1}(U_{1})*\\pi_{1}(U_{2})$\nby adding the ``amalgamation'' relations:\n\n\\begin{align*}\n(i_{1*})(u) & =(i_{2*})(u)\\forall u\\in\\pi_{1}(U_{0}).\n\\end{align*}\n\n\nMore explicitly: If $\\pi_{1}(U_{1})=\\langle S_{1}\\mid R_{1}\\rangle$,\n$\\pi_{1}(U_{2})=\\langle S_{2}\\mid R_{2}\\rangle$, $\\pi_{1}(U_{0})=\\langle S_{0}\\mid R_{0}\\rangle$\nthen $\\pi_{1}(X)=\\langle S_{1},S_{2}\\mid R_{1,}R_{2}(i_{1*})(u)=(i_{2*})(u)\\forall u\\in S_{0}\\rangle$.\n\nMore precisely, the homomorphisms $(j_{1*}):\\pi_{1}(U_{1})\\to\\pi_{1}(X),(j_{2*}):\\pi_{1}(U_{2})\\to\\pi_{1}(X)$\nextend to homomorphism $\\pi_{1}(U_{1})*\\pi_{1}(U_{2})\\to\\pi_{1}(X)$\nwith kernal generated by $\\{(i_{1*})(u)(i_{2*})(u)^{-1}\\mid u\\in\\pi_{1}(U_{0})\\}$.\n\\end{thm}\n\n", "meta": {"hexsha": "fca692e1d00122d6a5261cd806d5ee333a652aac", "size": 3962, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "group_actions.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": "group_actions.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": "group_actions.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": 40.0202020202, "max_line_length": 141, "alphanum_fraction": 0.6443715295, "num_tokens": 1612, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577681049901037, "lm_q2_score": 0.8840392878563336, "lm_q1q2_score": 0.758300704681328}}
{"text": "\\subsection{Lagrange polynomials}\\label{subsec:lagrange_polynomials}\n\n\\begin{definition}\\label{def:omega_polynomial}\n  Given distinct elements \\( x_0, \\ldots, x_n \\) of the field \\( \\BbbK \\), we form the polynomial\n  \\begin{equation*}\n    \\omega(X) \\coloneqq \\prod_{k=0}^n (X - x_j).\n  \\end{equation*}\n\\end{definition}\n\n\\begin{proposition}\\label{thm:omega_polynomial_derivative}\n  For the polynomial \\( \\omega \\) from \\fullref{def:omega_polynomial}, for \\( k = 0, \\ldots, n \\) we have\n  \\begin{equation*}\n    \\omega'(x_j) = \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (x_j - x_k),\n  \\end{equation*}\n  where \\( \\omega' \\) is the algebraic \\hyperref[def:algebraic_derivative]{derivative} of \\( \\omega \\).\n\\end{proposition}\n\\begin{proof}\n  Fix \\( k \\in \\{ 0, \\ldots, n \\} \\) and denote\n  \\begin{equation*}\n    q(X) \\coloneqq \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (X - x_j).\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    \\omega(X) = (X - x_k) q(X)\n  \\end{equation*}\n  so\n  \\begin{equation*}\n    \\omega'(X) = [q(X) + X q'(X)] - x_k q'(X) = q(X) + (X - x_k) q'(X).\n  \\end{equation*}\n\n  So for \\( x_k \\) we have\n  \\begin{equation*}\n    \\omega'(x_k) = q(x_k) = \\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n (x_k - x_j).\n  \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}[Lagrange interpolation]\\label{thm:lagrange_interpolation}\n  Let \\( x_0, x_1, \\ldots, x_n \\) be pairwise distinct elements of \\( \\BbbK \\) and \\( y_0, y_1, \\ldots, y_n \\) be arbitrary elements of \\( \\BbbK \\). Then there exists a unique \\hyperref[def:polynomial]{polynomial} \\( L_n(X) \\in \\pi_n \\) (where \\( \\pi_n \\) is the \\hyperref[def:polynomial_free_module]{\\( n \\)-dimensional polynomial vector space}) such that\n  \\begin{equation}\\label{eq:thm:lagrange_interpolation/condition}\n    L_n(x_k) = y_k, k = 0, 1, \\ldots, n.\n  \\end{equation}\n\\end{theorem}\n\\begin{proof}\n  We will first show uniqueness. Let \\( p, q \\in \\pi_n \\) both satisfy \\fullref{eq:thm:lagrange_interpolation/condition}. Their difference \\( p - q \\) is a polynomial of degree at most \\( n \\) that has \\( n + 1 \\) roots. By \\fullref{thm:integral_domain_polynomial_root_limit}, \\( p - q = 0 \\). This proves uniqueness.\n\n  We construct the polynomial explicitly. Define the Lagrange polynomial\n  \\begin{equation*}\n    L_n(X) = \\sum_{m=0}^n y_m \\prod_{\\substack{j = 0 \\\\ j \\neq m}}^n \\frac {(X - x_j)} {(x_m - x_j)}.\n  \\end{equation*}\n\n  For \\( k = 0, 1, \\ldots, n \\) we have\n  \\begin{equation*}\n    L_n(x_k) = y_k \\underbrace{\\prod_{\\substack{j = 0 \\\\ j \\neq k}}^n \\frac {(x_k - x_j)} {(x_k - x_j)}}_{=1} + \\sum_{\\substack{m = 0 \\\\ m \\neq k}}^n y_m \\overbrace{\\frac{(x_k - x_m)}{(x_k - x_m)}}^{=0} \\prod_{\\substack{j = 0 \\\\ j \\neq k \\\\ j \\neq m}}^n \\frac {(x_k - x_j)} {(x_m - x_j)} = y_k.\n  \\end{equation*}\n\n  Therefore, \\( L_n \\) satisfies \\eqref{eq:thm:lagrange_interpolation/condition}, which proves existence.\n\\end{proof}\n", "meta": {"hexsha": "80f31d1fc0cf1e1a645c0fef342022661a2290fb", "size": 2844, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lagrange_polynomials.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/lagrange_polynomials.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/lagrange_polynomials.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.2033898305, "max_line_length": 356, "alphanum_fraction": 0.6343178622, "num_tokens": 1084, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.884039278690883, "lm_q2_score": 0.8577680995361899, "lm_q1q2_score": 0.7583006919980229}}
{"text": "\\chapter{Positions in 2D}\n\\label{chapter:positions}\n\nPositions in 2D have an x- and a y- coordinate, just as a point in a graph. In Esenthel the zero point is the middle of the screen. Positive values on the X-axis are to the right, negative values to the left. Positive values on the Y-axis are in the upper half of the screen, negative values on the lower half.\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=0.7\\linewidth]{images/2Dpositions.png}\n\\caption[]{2D coordinates.}\n\\label{fig:pos2D}\n\\end{figure}\n\nThe class \\eeClass{Vec2} is used to represent a 2D coordinate. There are several ways to set the x and y values:\n\n\\begin{code}\nVec2 pos;\npos.x =  0.1;       // set the x value to  0.1\npos.y = -0.3;       // set the y value to -0.3\npos   =  0.5;       // both x and y are set to 0.5\npos.set(0.1, -0.3); // use the function set(float x, float y) \n                    // to assign both x and y\n\\end{code}\n\n\\begin{exercise}\nWhere would these positions be located on the screen?\n\\end{exercise}\n\n\\video{https://www.youtube.com/embed/fbmTzkUnv3E}\n\n\\section{Show a position on the screen}\n\nAlthough the class \\eeClass{Vec2} is mainly used to calculate positions, it is also possible to show it on the screen. This can be done with the function \\eeFunc{draw(Color)}. The argument should contain the color in which the coordinate must be drawn.\n\n\\begin{code}\nVec2 p1(0.2, 0.4); // Create a point p1, assigning x and y \n                   // with the constructor.\nVec2 p2;           // Create a point p2.\n\nvoid InitPre()\n{\n   EE_INIT();\n}\n\nbool Init()\n{\n   p2.set(-0.2, -0.5); // assign values to p2 with the set function\n   return true;\n}\n\nvoid Shut() {}\n\nbool Update()\n{\n   if(Kb.bp(KB_ESC)) return false;\n   \n   return true;\n}\n\nvoid Draw()\n{\n   D.clear(BLACK); // Clear the screen\n   p1.draw(RED  ); // draw p1 in red  \n   p2.draw(BLUE ); // draw p2 in blue\n   Vec2(0 ,0).draw(GREEN); // create a temporary object and draw \n\t                         // it in green\n}\n\n\\end{code}\n\n\\begin{exercise}\nWrite this code in the editor. Don't copy/paste it: you won't learn anything from copying code. Make sure it runs without error. If not, compare your code with this example. Learning to understand errors is very important. Try to understand what went wrong and why.\n\\end{exercise}\n\n\\section{Math}\nYou can do math with \\eeClass{Vec2}, just as you can with plain numbers. It is possible to assign x and y values directly, but you can also do math with the class itself. In this case the operator will be applied to x as well as y:\n\n\\begin{code}\nVec2 p1(0.1,  0.3);\nVec2 p2(0.3, -0.1);\nVec2 p3 = p1 + p2;  // x: 0.4 , y: 0.2\np3 -= 0.1;          // x: 0.3 , y: 0.1\np3 *= 2;            // x: 0.6 , y: 0.2\np3 = p1 / 2.f;      // x: 0.05, y: 0.15 \n\\end{code}\n\n\\section{Points to remember}\nThe position \\eeClass{Vec2(0,0)} always stands for the middle of the screen. But the borders are not always clear. Not every computer screen has the same size, but you probably want to know the border values are. For example, you want to draw something in the right corner of the screen. For this reason, Esenthel provides a few functions in the object \\texttt{D} (display). You can request the width of the screen with \\eeFunc{D.w()} and the height of the screen with the function \\eeFunc{D.h()}. This makes it very easy to calculate the next points:\n\n\\begin{code}\nVec2 middle(0,0);\nVec2 left(-D.w(), 0);\nVec2 right(D.w(), 0);\nVec2 rightUpperCorner(D.w(), D.h());\nVec2 leftUpperCorner(-D.w(), D.h());\n\\end{code}\n\nIf you'd like to draw a point at a distance of 0.1 from the left upper corner, you could do that like this:\n\n\\begin{code}\nVec2(-D.w() + 0.1, D.h() - 0.1).draw(PINK);\n\\end{code}\n\n\\section{Summary}\n\\begin{itemize}\n\\item Points in 2D have an x- and y-coordinate. In Esenthel you will use the class \\eeClass{Vec2} to store a point.\n\\item The class \\eeClass{Vec2} has a function \\eeFunc{draw(Color)} to draw a point on the screen.\n\\item You can do math with \\eeClass{Vec2}, just as with an ordinary number.\n\\item \\eeClass{Vec2(0,0)} will always be the middle of the screen.\n\\item The borders of the screen can be calculated with \\eeClass{D.w()} and \\eeClass{D.h()}.\n\\end{itemize}\n\n\\begin{exercise}\nCreate an application which draws these points:\n\\begin{enumerate}\n\t\\item A white point in the middle of the screen.\n\t\\item A red point on 0.1 units away from the left border of the screen.\n\t\\item A blue point on 0.2 units from the upper right corner.\n\t\\item A yellow dot on 0.35 units from the lower border of the screen, on 2/3 of the total screen width.\n\\end{enumerate}\n\\end{exercise}\n\n\\video{https://www.youtube.com/embed/a2k420oTySU}", "meta": {"hexsha": "457967008bdabc133e40e6070986989fe0f22482", "size": 4631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "course/en/2d/positions.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/2d/positions.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/2d/positions.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": 37.9590163934, "max_line_length": 551, "alphanum_fraction": 0.6905635932, "num_tokens": 1402, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070060380482, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7582478800453202}}
{"text": "\\section*{Neural Networks}\n\\textbf{Activation:} ReLU: $\\max(0,x)$ \\\\\n$\\tanh(x)=\\frac{e^x-e^{-x}}{e^x+e^{-x}}$, $\\tanh'(x) = 1 - \\tanh^2(x)$ \\\\\nsigmoid $s(x)= \\frac{1}{1+e^{-x}},s^{'}(x)=s(x)(1-s(x))$\\\\\n\\textbf{Output}: linear regression $\\mathbf{y} = \\mathbf{W}^L\\mathbf{x}^{L-1}$, \\\\binary (logistic) $y_1 = \\frac{1}{1 + \\exp(-\\mathbf{w}^T \\mathbf{x}^{L-1})}$, \\\\multiclass (soft-max) $y_k = \\frac{\\exp( \\mathbf{w}_k^T\\mathbf{x}^{L-1})}{\\sum_{m=1}^{K}{\\exp(\\mathbf{w}^T\\mathbf{x}^{L-1})}}$.\\\\\n\\textbf{Loss function:} $l(y, \\hat{y})$: squared loss $\\frac{1}{2}(y - \\hat{y})^2$, \\\\\ncross-entropy loss $-y \\log \\hat{y} - (1-y)\\log(1-\\hat{y})$\\\\\n$\\text{Conv}_{n,m}^{k\\times k}(\\mathbf{x};\\mathbf{w})=\\sigma \\left( b + \\sum_{i=-k}^k \\sum_{j=-k}^k w_{i,j}x_{n+i,m+j} \\right) $\\\\\n\\textbf{CNN:} weight sharing ($<<$ param), shift invar. filters\n\n\\subsection*{Backpropagation}\n$J_{ij} = \\frac{\\partial \\mathbf{x}_i^{out}}{\\partial \\mathbf{x}_j^{in}} = w_{ij}\\cdot\\sigma'(\\mathbf{w}_i^\\top\\mathbf{x}^{in})$. Across multiple layers: $\\frac{\\partial\\mathbf{x}^{(l)}}{\\partial\\mathbf{x}^{(l-n)}} = \\mathbf{J}^{(l)}\\cdot\\frac{\\partial\\mathbf{x}^{(l-1)}}{\\partial\\mathbf{x}^{(l-n)}}=\\mathbf{J}^{(l)}\\cdot\\mathbf{J}^{(l-1)}\\cdots\\mathbf{J}^{(l-n+1)}$ and then back prop. $ \\nabla_{\\mathbf{x}^{(l)}}^\\top\\ell=\\nabla_{\\mathbf{y}}^\\top\\ell\\cdot\\mathbf{J}^{(L)}\\cdots\\mathbf{J}^{(l+1)}$\\\\\n$\\frac{\\partial l}{\\partial w_{ij}^{(l)}} = \\frac{\\partial l}{\\partial x_i^{(l)}}\\frac{\\partial x_i^{(l)}}{\\partial w_{ij}^{(l)}}$, $\\frac{\\partial x_i^{l}}{\\partial w_{ij}^{l}} = \\sigma'([\\mathbf{w}_i^{(l)}]^T \\mathbf{x}^{(l-1)})\\cdot x_j^{(l-1)}$ ", "meta": {"hexsha": "3a70d780eb81c95159f8f1482626bb2a180af3b1", "size": 1619, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "NeuralNetworks.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": "NeuralNetworks.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": "NeuralNetworks.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": 124.5384615385, "max_line_length": 500, "alphanum_fraction": 0.5688696726, "num_tokens": 755, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.959154287592778, "lm_q2_score": 0.7905303236047049, "lm_q1q2_score": 0.7582405493575589}}
{"text": "\\mychapter{13}{Lesson 13} %181109\n\n\\section{Number theory}\n\n\\begin{theorem}[Fermat's last theorem]\n    \\[\n        \\forall x, y, z \\in \\integer, n > 2 \\implies x^n + y^n \\neq z^n\n    \\]\n\\end{theorem}\n\n\\begin{lemma}\n    \\[\n        \\forall a \\in \\integer_n : \\gcd(a, n) > 1 \\implies a \\notin \\integer_n^\\times\n    \\]\n\\end{lemma}\n\n\\begin{proof}\n    Assume there exists $b \\in \\integer_n$ such that $ab \\equiv_n 1$. Then, there exists a quotient for the division $by$ between a and b with remainder 1. Observe that $\\gcd(a, n)$ divides $ab + qn$, which is equal to 1. It entails that $\\gcd(a, n) = 1$, which is a contradiction.\n\\end{proof}\n\n\\begin{lemma}\n    \\[\n        \\forall a, b \\in \\nonneg : a \\geq b \\neq 0 \\implies \\gcd(a, b) = \\gcd(b, a \\mod b)\n    \\]\n\\end{lemma}\n\n\\begin{proof}\n    Not given.\n\\end{proof}\n\n\\begin{theorem}\n    Given two integers $a$ and $b$, their greatest common divisor can be computed efficiently with respect to their lengths. Additionally, two other numbers u and v can be efficiently computed in order to satisfy B\\'ezout's identity: $\\gcd(a, b) = au + bv$\n\\end{theorem}\n\n\\begin{proof}\n    Hint: Use previous lemma recursively; we stop at $r_{t + 1} = 0$ for some $t$, thus:\n    \\[\n        \\gcd(a, b) = \\dots = \\gcd(r_t, r_{t + 1}) = r_t\n    \\]\n\\end{proof}\n\n\\begin{claim}\n    $r_{i + 2} \\leq r_i/2 \\forall 0 \\leq i \\leq t - 2 \\implies \\#steps = \\lambda - 1 \\text{ if } |b| \\in \\binary^\\lambda$\n\\end{claim}\n\nThe hypothesis is a natural consequence of the repeated modulo operations.\n\n\\begin{observation}[Exponentiation mod n: Square and multiply]\n    Let $b \\in \\binary^l$, where by writing $b_i$ we denote b's i-th bit. Then:\n    \\[\n        a^b \\equiv_n a^{\\sum_{i = 0}^l 2^ib_i} \\equiv_n \\prod_{i = 0}^l a^{2^ib_i} \n    \\]\n\\end{observation}\n\n%AP190913 - Unproven, can't find it anywhere\n\\begin{theorem}\n    The number of primes lesser than or equal to $x$ is a number greater than or equal to $\\frac{x}{3\\log_2 x}$\n\\end{theorem}\n\nThere exist many algorithms that solve the problem of primality testing, with time complexity polynomial in the length of their numerical representation; of most relevance are those of Miller-Rabin, which is probabilistic, but consistently used in practice, and the completely deterministic Agrawal-Kayal-Saxena (\\textsc{aks}), which has a much greater polynomial rank, and has been deemed impractical for most uses.\n\nWhat remained as a conjecture is the intractability of determining the factors of a $\\lambda$-bit composite number, which is widely known as the \\emph{factorization hardness}; this in turn would imply that integer multiplication of two $\\lambda$-bit primes is a \\owf.\n\n\\begin{definition}\n    Given a group $G$, its order is the least $i$ such that $a^i \\equiv_n 1$ \n\\end{definition}\n\n\\begin{corollary}\n    \\[\n        \\forall a \\in \\integer_m^\\times \\implies a^{\\phi(n)} \\equiv_n 1 \\wedge a^b \\equiv_n a^{b \\mod \\phi(n)} \\wedge a^{p - 1} \\equiv_p 1\n    \\]\n\\end{corollary}\n\n\\begin{proof}\n    $(\\integer_n^\\times, \\cdot)$ is a group with $\\phi(n)$ elements. Take $\\left< a \\right> = \\{a^0, \\dots, a^{d + 1}\\}$, where $d$ is the order. We must have $\\phi(n) = kd$ for some $k$. Therefore, $a^{\\phi(n)} = a^{dk} \\equiv_n 1$.\n\n    Also, $a^b \\equiv_n a^{b\\phi(n) + b \\mod \\phi(n)} \\equiv_n 1 \\cdot 2^{b \\mod \\phi(n)}$\n\\end{proof}\n\n\\begin{theorem}\n    Let G, H be two groups such that $H < G$, meaning the order of H divides the order of G\n\\end{theorem}\n\n\\section{Standard model assumptions}\n\nWe now turn our attention to some conjectures that form the basis for most of the cryptographic schemes that will follow. We will start from the weakest, and go up to the strongest. For all our purposes, let $\\groupgen(1^\\lambda)$ be a ``group generator'' with security parameter $\\lambda$, and let a random sample $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ be a triplet composed of the group itself $G$, one of its generators $g$, and its order $q$.\n\n% CDH -> DDH -> DL\n\\subsubsection{Discrete logarithm}\n\nGiven $g$ and $g^x$ in a $\\lambda$-bit group, there is no efficient algorithm for computing $y$ such that $g^y = g^x$ without knowing $x$ beforehand:\n\\[\n    \\forall \\adversary \\in \\ppt \\implies \\Pr[\\cryptog{dl}(\\lambda) = 1] \\in \\negl(\\lambda)\n\\]\n\n\\begin{cryptogame}\n    {dlass}\n    {$\\cryptog{dl}(\\lambda)$}\n    {dl}\n\n    \\receive{\\shortstack[l]{\n        %AP190913: Actually, the adversary knows this!\n        $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ \\\\\n        $x \\pickUAR \\integer_q$\n    }}{$y = g^x$}{}\n\n    \\send{}{$x'$}{\\textsc{Output 1 iff} $y^{x'} \\equiv_G y$}\n    \n\\end{cryptogame}\n\nThis means that the \\dl{} for a generic group G yields a \\owf, whereas in a multiplicative group $\\integer_p^\\times$, we obtain a \\owp.\n\n\\subsubsection{Computational Diffie-Hellman}\n\n%AP190913: Probably it is not necessary to compute it directly, we may only need a congruent value\nGiven a group $G$ and two elements in it $g^x$, $g^y$, it is impractical to compute $g^{xy}$ without knowing $x$ or $y$.\n\n\\begin{cryptogame}\n    {cdhass}\n    {$\\cryptog{cdh}(\\lambda)$}\n    {cdh}\n\n    \\receive{\\shortstack[l]{\n        %AP190913: Actually, the adversary knows this!\n        $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ \\\\\n        $x, y \\pickUAR \\integer_q$\n    }}{$(g^x, g^y)$}{}\n\n    \\send{}{$h$}{\\textsc{Output 1 iff} $h = g^{xy}$}\n    \n\\end{cryptogame}\n\n\\subsubsection{Decisional Diffie-Hellman}\n\nGiven a group $G$ and three elements in it $g^x$, $g^y$, $g^z$, it is impractical to distinguish $g^{xy}$ from $g^z$ by only knowing $g^x$ and $g^y$, along with the originating triad $(G, g, q))$.\n\n\\begin{cryptogame}\n    {ddhass}\n    {$\\cryptog{ddh}(\\lambda)$}\n    {ddh}\n\n    \\cseqdelay\n\n    \\receive{\\shortstack[l]{\n        %AP190913: Actually, the adversary knows this!\n        $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ \\\\\n        $x, y, z_1 \\pickUAR \\integer_q$ \\\\\n        $z_0 = xy \\mod q$ \\\\\n        $b \\pickUAR \\binary$\n    }}{$(g^x, g^y, g^{z_b})$}{}\n\n    \\cseqdelay\n\n    \\send{}{$b'$}{\\textsc{Output 1 iff} $b' = b$}\n    \n\\end{cryptogame}\n\nAll these assumptions helped in constructing the \\emph{Diffie-Hellman key exchange} protocol, which is a way to establish a \\ske{} channel from an unsafe channel, with any adversary unable to efficiently break the channel's secrecy. Do note that authentication is left out of the picture here.\n\n\\begin{cryptosequence}\n    {dhkex}\n    {The Diffie-Hellman Key Exchange protocol}\n    \n    \\cseqentity{A}{Alice}\n    \\cseqentity[2.2]{B}{Bob}\n\n    \\cseqmessagel{B}{\\shortstack[l]{\n        $(G, g, q) \\pickUAR \\groupgen(1^\\lambda)$ \\\\\n        $x \\pickUAR G$ \n    }}{$(G, g, q, g^x)$}{A}{}\n\n    \\cseqdelay\n\n    \\cseqmessager{A}{\\shortstack[l]{\n        $y \\pickUAR G$ \\\\\n        $k = (g^x)^y$\n    }}{$g^y$}{B}{$k = (g^y)^x$}\n\n\\end{cryptosequence}\n\nSome relationships have been established between these assumptions: it is known that $\\ddh \\implies \\cdh \\implies \\dl$; and that $\\cdh \\notimplies \\ddh$.\n", "meta": {"hexsha": "a547f065401fb2acf53a2c60c9b4b8dc3d84d260", "size": 6894, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lessons/lesson_13.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_13.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_13.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": 37.8791208791, "max_line_length": 449, "alphanum_fraction": 0.6460690455, "num_tokens": 2262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.8175744695262777, "lm_q1q2_score": 0.758188559420353}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 6}\n\nAn expression is in disjunctive normal form if it is of the form $e = c_1 \\vee c_2 \\vee \\dots \\vee c_m$ where $c_k$ is a clause and of the form $c_k = (z_1^{(k)} \\wedge z_2^{(k)} \\wedge \\dots \\wedge z_{n_k}^{(k)})$ in which each $z_j^{(k)}$ is a literal.\nProve that the problem of satisfiability for expressions in disjunctive normal form is in $P$; that is, prove that there is an algorithm which takes as input an expression $e$ with $|e|$ number of symbols in disjunctive normal form and determines whether or not that expression is satisfiable in polynomial time.\n\n\\subsection*{Solution}\n\nAn expression in Disjunctive Normal Form (DNF) will be evaluated to true if and only if at least one of its clauses is evaluated to true.\nTherefore, a DNF expression is satisfiable if boolean assignments can be made to one of its clauses such that the clause is evaluated to true.\nIt is always possible to evaluate a conjunctive clause as long as a literal and its negation are not present in the clause at the same time.\nConsequently, satisfying a DNF expression can be translated to verifying whether there is a clause in that expression that does not contain a variable and its negation at the same time, a procedure which clearly has a runtime linear in the number of symbols $|e|$, thus polynomial time.\nConsequently, DNF-SAT is in P.\n", "meta": {"hexsha": "40eac845f52e5fd4ab9f8d2f73b974df8e249ae6", "size": 1711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/hw06/hw06q06.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/hw06q06.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/hw06q06.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": 85.55, "max_line_length": 312, "alphanum_fraction": 0.7095265926, "num_tokens": 424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8962513731336204, "lm_q2_score": 0.8459424314825852, "lm_q1q2_score": 0.7581770658082605}}
{"text": "% tex file for regression\n\\par \\indent A simple and straightforward way to model the voxel time courses \nfor each subject is to perform linear regression. Initially, we just used the \nconvolved predicted hemodynamic response (HR) and either all of the \nconditions together or each of conditions individually. After realizing that \nthe HRs themselves did not explain enough of the BOLD ratio, we attempted to \nadd features in order to reduce or explain the noise we observed. Additional \nfeatures that we examined included a linear drift and some of the time \ncourses' Fourier series and principal components.\n\n\\par Linear regression assumes a linear relationship between a response \nvector $y$ and a design matrix of predictors $X$. Each element of $y$ \nrepresents a single observed response, and each row of $X$ represents a \ncorresponding vector of predictor values. If one including the intercept as a \nterm (as we have elected to do), the first column of the $X$ design matrix \nshould be a vector of $1$s. The linear model can then be expressed as: \n\n\\begin{equation}\ny = X\\beta + \\epsilon\n\\end{equation}\n\n\\par It is further assumed that the errors $\\epsilon_i$ for each observation \n$i$ are independent and identically distributed with $N(0, \\sigma^2)$, and \nthat the errors are independent of $X$. The vector of coefficients $\\beta$ \nwith length equal to the number of predictors in $X$ can be estimated with \nthe closed-form solution:\n\n\\begin{equation}\n\\hat{\\beta} =(X^T X)^{-1} X^T y\n\\end{equation}\n\n\\par Even when $(X^T X)$ is not invertible, $\\hat{\\beta}$ can be estimated \nusing the pseudo-inverse of $(X^T X)$, represented as $(X^T X)^{-}$ to get a \nnon-unique value for $\\hat{\\beta}$.\n\n\\par To consider the strength of the effects of these predictors, we will use \nt-tests of the corresponding estimated coefficients for each voxel and \nsubject, as discussed under Section \\ref{hypothesis_testing}. The validity of \nthe model and of the ``p-values'' produced by performing these t-tests is \ndependent on whether or not the many assumptions of the linear model are \nactually met. In particular, we will discuss the assumption of normal errors \nby analyzing the residuals in Section \\ref{normality}. \n\n\\subsubsection{More about potential features:}\n\\par Other than the basic HR feature(s) and a column of $1$s (to account \nfor an ``intercept'' term or non-zero average value), we experimented with \nadditional predictors for our design matrix $X$. Among these were the \nfirst few principal components of the voxel $\\times$ time matrix of voxel time \ncourses and the first few functions of the Fourier series for the time courses. \nAs noted above these, additional features helped account for the noise in the \nobserved BOLD ratio fluctuation.\n\n\\vspace{2mm}\n\\noindent \\textbf{Principal Components}\n\\vspace{2mm}\n\\par One approach for reducing the noise in the linear model is to include \nprincipal components of the voxel $\\times$ time voxel time course matrix. \nInstead of using the entire matrix, it may be possible to just include the \nfirst few principal components as features that explain a great deal of the \nvariance in the entire matrix. To get the principal components, we obtained \nthe singular value decomposition (SVD) of the time $\\times$ time covariance \nmatrix. We tried this with and without first masking the voxels. To \nstandardize the voxels, we subtracted the column means (mean across voxels) \nfrom the voxel by time matrix. There is also a very strong effect of mean \nover time in the data that dominates other effects, so we subtracted the \nrow means (mean over time) as well.\n\nAs you can see in Figure \\ref{fig:pca10}, which compares the variance \nexplained by including up to ten components, with and without masking the \nvoxels, masking explains more variance at each component. This trend was \nobserved across all subjects. So, between the better performance and the \nlogical rationality of using the masked data (we are not actually interested \nin the behvavior of voxels outside the brain), we decided to only work with \nthe masked data's principal components. \n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.5\\linewidth]{../images/pcacumsumssub010.png}\n \t\\caption{Comparing proportion of variance explained by Subject 10's \nprincipal components, with and without masking the data.}\n \t\\label{fig:pca10}\n\\end{figure}\n\nAn important issue to consider is how many principal components to include in \nthe design matrix. Figure \\ref{fig:pcabox} compares the the amount of variance \nexplained by including successively more principal components across subjects. \nA few observations should be noted. First, there is considerable variation \nbetween subjects in how much variance the early principal components capture. \nSecond, by including only the first six components, it is possible for most \nsubjects' voxel time course matrix to capture at least 40\\% of the variance. \nMoving forward, we chose to include six principal components as additional \nfeatures when considering models that reduce noise. This cutoff of six \ncomponents or 40\\% of the variance explained was somewhat arbitrary, with the \nidea being we wanted to only include a few components without sacrificing too \nmuch of the variance explained and that we wanted to use the same number of \ncomponents for each subject. It will be seen later that the variation between \nsubjects in how much variance is captured by the first six components has strong \nramifications on the results. \n\n\\begin{figure}[ht]\n\t\\centering\n\t\\includegraphics[width=.5\\linewidth]{../images/pcaBOX.png}\n \t\\caption{Boxplots comparing the amount of variance captured by principal \ncomponents for each subject. The data was masked beforehand. All subjects are \nable to capture at least 40\\% of the variance when using just six principal \ncomponents.}\n \t\\label{fig:pcabox}\n\\end{figure}\n\n\n\\vspace{2mm}\n\\noindent \\textbf{Fourier Series}\n\\vspace{2mm}\n\\par We also considered including 6 features related to the first few \nfunctions of the Fourier series.\nA full Fourier series is represented as the following:\n\n\\begin{equation}\nf(x) = \\frac{1}{2} \\cdot a_0 + \\sum_{n=1}^{\\infty} a_n \\cdot cos(n x) + \\sum_{n=1}^{\\infty} b_n \\cdot  sin(n x)\n\\end{equation}\n\n\\noindent We wanted to represent low level sinesoidal fluctuations, which \nrequires a few periods over the full range of the time course \n$(0, \\text{num of TR})$. As such, we changed the Fourier series to:\n\n\\begin{equation}\nf(x) = \\frac{1}{2} \\cdot a_0 + \\sum_{n=1}^{\\infty} a_n \\cdot cos(\\frac{n}{\\text{num of TR}} x) + \\sum_{n=1}^{\\infty} b_n \\cdot sin(\\frac{n}{\\text{num of TR}} x)\n\\end{equation}\n\n\\noindent We used $ \\sum_{n=1}^{3} a_n \\cdot cos(\\frac{n}{\\text{num of TR}} x) + \n\\sum_{n=1}^{3} b_n \\cdot sin(\\frac{n}{\\text{num of TR}} x)$ to be 6 features to try \nto get a low order sinusoidal fluctuations.\n\n\\subsection{Model Selection} \\label{model_selection}\n\n\\par In order to select the best set of features for our $X$ matrix, and also \nto compare the use of a single condition feature vs. each of the three \ndifferent types of conditions as three separate features, we decided to \nutilize model comparison metrics; specifically, the AIC, BIC, and adjusted \n$R^2$. Using a small but expressive subset of the subjects ($002$, $003$, and \n$014$), we averaged the metrics across all voxels and people, an admittedly not \ntheoretically sound approach. We visualized values in Figures \\ref{fig:AIC}, \n\\ref{fig:BIC}, and \\ref{fig:adjr2}. \n\n\\par From these plots we can observe that \\textbf{(1)} separating the \nconditions into individual features to convolve the hemodynamic response did \nnot provide much gain in these metrics and \\textbf{(2)} the inclusion of the 6 \nprincipal components comparably tends to create better models than the \ninclusion of the 6 Fourier series features. We initially interpreted this as a \nvote to include the first 6 principal components and not the Fourier features. \nUnfortunately, including the 6 principal components lead to overfitting and \ncollinearity with the HRF features for some subjects. These problems tended to \narise when the proportion of variance explained by the first 6 principal \ncomponents was much greater that 40 \\%. Overall, we went with the 6 Fourier \nfeatures instead and observed similar t-statistics for the HRF feature in the \nmodels with those when using the first 6 principal components when the variance \nexplained was around 40 \\%.\n\n\n\\begin{figure}\n\\centering\n\t\\begin{minipage}[b]{0.33\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.8\\linewidth]{../images/aic_better}  \n\n\t\t\\caption{AIC}\n\t\t\\label{fig:AIC}\n\n\t\\end{minipage}\n\t\\quad\n\t\\begin{minipage}[b]{0.33\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.8\\linewidth]{../images/bic_better}  \n\t\t\\caption{BIC}\n\t\t\\label{fig:BIC}\n\n\t\\end{minipage}\n\t\t\n\t\\begin{minipage}[b]{0.33\\linewidth}\n\t\t\\centering\n\t\t\\includegraphics[width=.8\\linewidth]{../images/adjr2_better}  \n\t\t\\caption{Adjusted $R^2$}\n\t\t\\label{fig:adjr2}\n\n\t\\end{minipage}\n\n\\end{figure}\n\n\t\n\n", "meta": {"hexsha": "ac89ae2bb183b4e432a4892255dacaa8b31ae414", "size": 8992, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/main_sections/regression.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/regression.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/regression.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": 47.0785340314, "max_line_length": 160, "alphanum_fraction": 0.7661254448, "num_tokens": 2265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297941266014, "lm_q2_score": 0.8418256412990657, "lm_q1q2_score": 0.7580890714495419}}
{"text": "\n\\section{Convolutional autoencoder}\nA convolutional autoencoder(CAE) consists of two parts, namely the encoding part and decoding part. While the decoded output may not be the same as the input, the goal is to restore the input as much as possible. A sample CAE is shown in the graph. There is only a convolution layer in the encoder part and a de-convolution layer in the decoder part for this example.\n\n\\begin{figure}[htbp]\n\\centering{\n\\includegraphics[width=.5\\textwidth]{CAE.png}}\n\\caption{Convolutional autoencoder}\n\\end{figure}\n\n\n\\subsection{Encoder}\nWe can put convolution layers and pooling layers in the encoding part as the normal CNN to get the encoded output. For this specific CAE here, we use a convolution layer only.\nSuppose the input data is denoted as $X$, the kernel for the convolution layer is $K^1$. We can obtain the encoded output $Y$ by convolution as\n\\begin{align}\n    K^1 * X  = Y.\n\\end{align}\n%Then with the backpropagation, the input and the parameters can be updated as \n%\\begin{align}\n%   dY * (K^1)^T = dX,   \\\\\n%   dY * X      = dK^1 .\n%\\end{align}\nIf we rewrite the convolution in the form of matrix multiplication, it becomes\n\\begin{align}\n   Y = K^1 * X = T \\cdot X.\n\\end{align}\nFor the purpose of illustration, we take $K^1 \\in \\mathbb{R}^4$, $X \\in \\mathbb{R}^8$ with the stride to be 2. Then we have $Y \\in \\mathbb{R}^5$ and $T \\in \\mathbb{R}^{5*8}$.\n\nSuppose $K^1=(k_1, k_2, k_3, k_4)$ and $X=(x_1, x_2, ..., x_8)$. The corresponding coefficient matrix $T$ can be represented as \n\\begin{align}\n   T = P \\cdot \\tilde{T} &= \n%  \\begin{bmatrix}\n%    (1-2r)  & -r      & 0       & \\cdots  & 0  \\\\\n%    -r      & (1-2r)  & -r      & \\ddots  & \\vdots   \\\\\n%     0      &  \\ddots & \\ddots  & \\ddots  & 0  \\\\\n%    \\vdots  &         & -r      & (1-2r)  & -r  \\\\\n%     0      & \\cdots  & 0       & -r      & (1-2r)\n%  \\end{bmatrix}\n\\left(\n  \\begin{array}{ccccccccc}\n     1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\\\\n  \\end{array}\n\\right)_{5*9}\n\\left(\n  \\begin{array}{cccccccc}\n     k_3 & k_4 & 0 & 0 & 0 & 0 & 0 & 0  \\\\\n     k_2 & k_3 & k_4 & 0 & 0 & 0 & 0 &  0 \\\\\n     k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0 & 0  \\\\\n     0 & k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0  \\\\\n     0 & 0 & k_1 & k_2 & k_3 & k_4 & 0 & 0  \\\\\n     0 & 0 & 0 & k_1 & k_2 & k_3 & k_4 & 0  \\\\\n     0 & 0 & 0 & 0 & k_1 & k_2 & k_3 & k_4  \\\\\n     0 & 0 & 0 & 0 & 0 & k_1 & k_2 & k_3   \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & k_1 & k_2  \\\\\n  \\end{array}\n\\right)_{9*8}\\\\ \\notag \n&= \n\\left(\n  \\begin{array}{cccccccc}\n     k_3 & k_4 & 0 & 0 & 0 & 0 & 0 & 0  \\\\\n     k_1 & k_2 & k_3 & k_4 & 0 & 0 & 0 &  0 \\\\\n     0 & 0 & k_1 & k_2 & k_3 & k_4 & 0 &  0  \\\\\n     0 & 0 & 0 &0 & k_1 & k_2 & k_3 & k_4   \\\\\n     0 & 0 & 0 & 0 & 0 & 0 & k_1 & k_2    \\\\\n  \\end{array}\n\\right)_{5*8}.\n\\end{align}\nHere $P$ denote the operation of stride being 2 and $\\tilde{T}$ is the standard convolution operation.\n\nThe procedure can be illustrated as below.\n\\begin{figure}[htbp]\n\\centering{\n\\includegraphics[width=.6\\textwidth]{conv.jpeg}}\n\\caption{Depiction of usual convolution process with 1-d input}\n\\end{figure}\n\n\n\\subsection{Decoder}\nWe can put unpooling layers and deconvolution layers in the decoding part to get the decoded output. For this specific CAE here, we use a deconvolution layer only.\nSuppose the encoded data from the encoder is denoted as $Y$ and the restored output as $\\tilde{X}$. In TensorFlow, $\\tilde{X}$ is obtained from $Y$ with the function tf.nn.conv3d$\\_$transpose. \n\nHere is what tf.nn.conv3d$\\_$transpose does.\nIt construct another CNN with a convolution layer only, which takes $Y$ as the output and $\\tilde{X}$ as the input. Then  the input is updated with the backpropagation by the function gen$\\_$nn$\\_$ops.conv3d$\\_$backprop$\\_$input$\\_$v2. %This function does the following operation.\n\nIf we rewrite the deconvolution in the form of matrix multiplication, it becomes\n\\begin{align}\n   \\tilde{X} = K^2 * Y = T^T \\cdot Y.\n\\end{align}\n\n%Suppose $Y$ can be obtained by convolution as\n%\\begin{align}\n%    K^2 * \\tilde{X}  = Y.\n%\\end{align}\n%Then with the backpropagation, the input and the parameters can be updated as\n%\\begin{align}\n%   dY *(K^2)^T  = d\\tilde{X},   \\\\\n%   dY * \\tilde{X}      = dK^2.\n%\\end{align}\n%After $\\tilde{X}$ is updated, the $L^2$ loss function is used to compute the difference between $X$ and $\\tilde{X}$. \n\nWith the same notation as above, the corresponding coefficient matrix $T^T$ can be represented as \n\\begin{align}\n   T^T = \\tilde{T}^T\\cdot  P^T &= \n%  \\begin{bmatrix}\n%    (1-2r)  & -r      & 0       & \\cdots  & 0  \\\\\n%    -r      & (1-2r)  & -r      & \\ddots  & \\vdots   \\\\\n%     0      &  \\ddots & \\ddots  & \\ddots  & 0  \\\\\n%    \\vdots  &         & -r      & (1-2r)  & -r  \\\\\n%     0      & \\cdots  & 0       & -r      & (1-2r)\n%  \\end{bmatrix}\n\\left(\n  \\begin{array}{ccccccccc}\n     k_3 & k_2 & k_1 & 0 & 0 & 0 & 0 & 0  & 0\\\\\n     k_4 & k_3 & k_2 & k_1 & 0 & 0 & 0 &  0 & 0\\\\\n     0 & k_4 & k_3 & k_2 & k_1 & 0 & 0 & 0 & 0\\\\\n     0 & 0 & k_4 & k_3 & k_2 & k_1 & 0 & 0  & 0\\\\\n     0 & 0 & 0 & k_4 & k_3 & k_2 & k_1 & 0  & 0\\\\\n     0 & 0 & 0 & 0 & k_4 & k_3 & k_2 & k_1  & 0\\\\\n     0 & 0 & 0 & 0 & 0 & k_4 & k_3 & k_2 & k_1  \\\\\n     0 & 0 & 0 & 0 & 0 & 0  & k_4 & k_3 & k_2   \\\\\n  \\end{array}\n\\right)_{8*9}\n\\left(\n  \\begin{array}{ccccc}\n     1 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 1 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 1 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 1 & 0  \\\\\n     0 & 0 & 0 & 0 & 0  \\\\\n     0 & 0 & 0 & 0 & 1  \\\\\n  \\end{array}\n\\right)_{9*5}\n\\\\ \\notag \n&= \n\\left(\n  \\begin{array}{ccccc}\n     k_3 & k_1 & 0 & 0 & 0   \\\\\n     k_4 & k_2 & 0 & 0 & 0   \\\\\n     0 & k_3 & k_1 & 0 & 0  \\\\     \n     0 & k_4 & k_2 & 0 & 0  \\\\\n     0 & 0 & k_3 & k_1 & 0  \\\\\n     0 & 0 & k_4 & k_2 & 0  \\\\\n     0 & 0 & 0 & k_3 & k_1  \\\\\n     0 & 0 & 0 & k_4 & k_2  \\\\\n  \\end{array}\n\\right)_{8*5}.\n\\end{align}\nHere $P^T$ denote the operation of padding(adding zeros) and $\\tilde{T}$ is the standard deconvolution operation.\n\nThe procedure can be illustrated as below.\n\\begin{figure}[htbp]\n\\centering{\n\\includegraphics[width=.6\\textwidth]{deconv.jpeg}}\n\\caption{Deconvolution}\n\\end{figure}\n\n\\section{Denoising by Convolutional Autoencoder}\n\n\\paragraph{Autoencoder}\n    \\begin{itemize}\n        \\item An Autoencoder is a neural network that is trained to attempt to copy its input to its output.\n        \\item The network consists of two parts\n            \\begin{itemize}\n                \\item An encoder function\n                    \\begin{equation*}\n                        h=f(x).\n                    \\end{equation*}\n                \\item A decoder function that produce a reconstruct\n                    \\begin{equation*}\n                        y=g(h).\n                    \\end{equation*}\n            \\end{itemize}\n        \\item The goal for training the network is to minimize the difference between the output $y$ and  the input $x$\n            $$\n                \\min \\|g(f(x))-x\\|_{\\ell^2}.\n            $$\n    \\end{itemize}\n\n\nA convolutional autoencoder is an autoencoder consists of convolutional layers.  \n    \nA simple CAE with one hidden layer \n\\begin{itemize}\n\\item Convolution\n    $$h=f(x)=K\\circledast x+\\operatorname{diag}(b)I.$$\n\n\\item De-convolution\n\n    Inverse operation of the convolution to restore the input\n        $$y=g(h)=\\hat{K}\\circledast h+\\operatorname{diag}(\\hat b)I.$$\n\n\n\\item We train the model \n    $$y=g(f(x))$$\n   to solve the following minimization problem \n        $$\\min\\|y-x\\|_{\\ell^2}$$\n\\item Then we use $f$ as the encoder, and $g$ as the decoder.\n\n\\end{itemize}\n\n    \\begin{center}\n        \\includegraphics[width=0.8\\textwidth]{CAE}\n    \\end{center}\n\n\\paragraph{MNIST with noise}\n    \\begin{itemize}\n        \\item We add Gaussian noise to MNIST dataset\n            \\begin{equation*}\n                x_{ij} \\leftarrow x_{ij}+\\eta z,\n            \\end{equation*}\n            where $z$ is the Gaussian random variable given by \n            \\begin{equation*}\n                P(z)= \\frac{1}{\\sigma\\sqrt{2\\pi}}e^{-\\frac{(z-\\mu)^2}{2\\sigma^2}}\n            \\end{equation*}\n         \\item Then construct a CAE model such that given an image with noise, it will output the denoised image.\n\n             \\begin{center}\n                 \\includegraphics[width=0.8\\textwidth]{noise}\n             \\end{center}\n    \\end{itemize}\n    \\begin{center}\n        \\includegraphics[height=0.8\\textheight]{denoise}\n    \\end{center}\n\n\n    \\paragraph{Encoder:}\n    \\begin{itemize}\n    \\footnotesize\n    \\item  First convolutional layer:\n    \\begin{equation*}\n        f^0 = \\theta^0(x) \\in \\mathbb{R}^{16\\times 28\\times 28},\n    \\end{equation*}\n    with\n    \\begin{equation*}\n        \\theta^0(x) = K^0 \\circledast x + {\\rm{diag}(b^0) }\\cdot \\bm{1} \\quad, \\quad K^0 \\in R^{16 \\times 1 \\times 3 \\times 3}, \\quad b^0 \\in \\mathbb R^{16}\n    \\end{equation*}\n    \\item  Second convolutional layer:\n    \\begin{equation*}\n        f^1 = \\theta^1(r^1(\\sigma^1 (f^0)))\\in \\mathbb{R}^{8\\times 14\\times 14},\n    \\end{equation*}\n            where $\\sigma^1: \\mathbb{R}^{16\\times 28\\times 28}\\mapsto \\mathbb{R}^{16\\times 28\\times 28}$ is the ReLU activation function; $r^1:\\mathbb{R}^{16\\times 28\\times 28}\\mapsto \\mathbb{R}^{8\\times 14\\times 14}$ is the max-pooling function; and \n            \\begin{equation*}\n                \\theta^1(x) = K^1 \\circledast x + {\\rm{diag}(b^1) }\\cdot \\bm{1} \\quad, \\quad K^1 \\in \\mathbb R^{8 \\times 16 \\times 3 \\times 3}, \\quad b^1 \\in \\mathbb R^{8}.\n            \\end{equation*}\n    \\item  Third convolutional layer:\n    \\begin{equation*}\n        f^2 = \\theta^2(r^2(\\sigma^2 (f^1)))\\in \\mathbb{R}^{8\\times 7\\times 7},\n    \\end{equation*}\n            where $\\sigma^2: \\mathbb{R}^{8\\times 14\\times 14}\\mapsto \\mathbb{R}^{8\\times 14\\times 14}$ is the ReLU activation function; $r^2:\\mathbb{R}^{8\\times 14\\times 14}\\mapsto \\mathbb{R}^{8\\times 7\\times 7}$ is the max-pooling function; and \n            \\begin{equation*}\n                \\theta^2(x) = K^2 \\circledast x + {\\rm{diag}(b^2) }\\cdot \\bm{1} \\quad, \\quad K^1 \\in \\mathbb R^{8 \\times 8 \\times 3 \\times 3}, \\quad b^2 \\in \\mathbb R^{8}.\n            \\end{equation*}\n    \\end{itemize}\n\n    \\paragraph{Output of encoder:}\n        \\begin{equation*}\n            f = r^3(\\sigma^3(f^2))\\in \\mathbb{R}^{8\\times 4\\times 4},\n        \\end{equation*}\n            where $\\sigma^3: \\mathbb{R}^{8\\times 7\\times 7}\\mapsto \\mathbb{R}^{8\\times 7\\times 7}$ is the ReLU activation function; $r^3:\\mathbb{R}^{8\\times 7\\times 7}\\mapsto \\mathbb{R}^{8\\times 4\\times 4}$ is the max-pooling function. \n\n            \\begin{center}\n                \\includegraphics[width=0.5\\textwidth]{encoder}\n            \\end{center}\n\n    \\paragraph{Decoder:}\n    \\begin{itemize}\n        \\footnotesize\n        \\item First deconvolutional layer:\n            \\begin{equation*}\n                g^1=\\hat\\theta^1 (p^1(f))\\in \\mathbb{R}^{8\\times 7\\times 7},\n            \\end{equation*}\n            where $p^1: \\mathbb{R}^{8\\times 4\\times 4}\\mapsto \\mathbb{R}^{8\\times 7\\times 7}$ is the up-pooling function; and \n            \\begin{equation*}\n                \\hat\\theta^1(x) = \\hat K^1 \\circledast x + {\\rm{diag}(\\hat b^1) }\\cdot \\bm{1} \\quad, \\quad \\hat K^1 \\in \\mathbb R^{8 \\times 8 \\times 3 \\times 3}, \\quad \\hat b^1 \\in \\mathbb R^{8}.\n            \\end{equation*}\n        \\item Second deconvolutional layer:\n            \\begin{equation*}\n                g^2=\\hat\\theta^2 (p^2(\\hat\\sigma^2(g)))\\in \\mathbb{R}^{8\\times 14\\times 14},\n            \\end{equation*}\n            where $\\hat\\sigma^2: \\mathbb{R}^{8\\times 7\\times 7}\\mapsto \\mathbb{R}^{8\\times 7\\times 7}$ is the ReLU activation function; \n            $p^2: \\mathbb{R}^{8\\times 7\\times 7}\\mapsto \\mathbb{R}^{8\\times 14\\times 14}$ is the up-pooling function; and \n            \\begin{equation*}\n                \\hat\\theta^2(x) = \\hat K^2 \\circledast x + {\\rm{diag}(\\hat b^2) }\\cdot \\bm{1} \\quad, \\quad \\hat K^2 \\in \\mathbb R^{8 \\times 8 \\times 3 \\times 3}, \\quad \\hat b^2 \\in \\mathbb R^{8}.\n            \\end{equation*}\n        \\item Third deconvolutional layer:\n            \\begin{equation*}\n                g^3=\\hat\\theta^3(p^3(\\hat\\sigma^3(g)))\\in \\mathbb{R}^{16\\times 28\\times 28},\n            \\end{equation*}\n            where $\\hat\\sigma^3: \\mathbb{R}^{8\\times 14\\times 14}\\mapsto \\mathbb{R}^{8\\times 14\\times 14}$ is the ReLU activation function; \n            $p^3: \\mathbb{R}^{8\\times 14\\times 14}\\mapsto \\mathbb{R}^{16\\times 28\\times 28}$ is the up-pooling function; and\n            \\begin{equation*}\n                \\hat\\theta^3(x) = \\hat K^3 \\circledast x + {\\rm{diag}(\\hat b^3) }\\cdot \\bm{1} \\quad, \\quad \\hat K^3 \\in \\mathbb R^{16 \\times 8 \\times 3 \\times 3}, \\quad \\hat b^3 \\in \\mathbb R^{16}.\n            \\end{equation*}\n    \\end{itemize}\n\n\\paragraph{Output of decoder:}\n        \\begin{equation*}\n            f = \\hat\\theta^4 (\\hat\\sigma^4(f^2))\\in \\mathbb{R}^{1\\times 28\\times 28},\n        \\end{equation*}\n            where $\\hat\\sigma^4: \\mathbb{R}^{16\\times 28\\times 28}\\mapsto \\mathbb{R}^{16\\times 28\\times 28}$ is the ReLU activation function;  and\n            \\begin{equation*}\n                \\hat\\theta^4(x) = \\hat K^4 \\circledast x + {\\rm{diag}(\\hat b^4) }\\cdot \\bm{1} \\quad, \\quad \\hat K^4 \\in \\mathbb R^{1 \\times 16 \\times 3 \\times 3}, \\quad \\hat b^4 \\in \\mathbb R^{1}.\n            \\end{equation*}\n\n            \\begin{center}\n                \\includegraphics[width=0.5\\textwidth]{decoder}\n            \\end{center}\n   After training 100 epochs:\n\n    \\begin{center}\n        \\includegraphics[width=0.8\\textwidth]{result}\n    \\end{center}\n\n\\section{Linear encoder, nonlinear encoder and ``enhanced'' encoder}\nDeep Neural Network can naturally be viewed as nonlinear encoders. \n\nGiven the data $x\\in \\mathbb R^d$, we consider the nonlinear encoder\n\\begin{equation}\\label{nonlinear-encoder0}\nf(x)=\\sigma (W_1x+b_1),  \\quad W_1\\in \\mathbb R^{c\\times d}.  \n\\end{equation}\n\\begin{equation}\\label{nonlinear-encoder}\nf(x)=W_2\\sigma (W_1x+b_1)+b_2,  \\quad W_1\\in \\mathbb R^{c\\times d},\nW_2\\in\\mathbb R^{c\\times c}\n\\end{equation}\n\nWe now combine the nonlinear \\eqref{nonlinear-encoder} with a linear\nencoder to get the following ``enhanced'' encoder:\n\\begin{equation}\\label{enhanced-encoder}\n\\tilde f(x)=f(x)+\\tilde W_1x +\\tilde b_1\\quad \\tilde W_1\\in \\mathbb R^{c\\times d}.\n\\end{equation}\nwhere\n\\begin{equation}\n\\tilde b_1=0 \\mbox{ if } b_2=0 \\mbox{ or if $f(x)$ is given by \\eqref{nonlinear-encoder0}}\n\\end{equation}\n\n\\begin{lemma}\nThere exists .... such that  \n$$\nW_2\\sigma (W_1x+b_1)+b_2\\equiv x\n$$\n\\end{lemma}\n\\begin{theorem}\nNonlinear encoder recovers linear encoder if $d\\le c/2$(?) \n\\end{theorem}\nCan we make the following statement:\n\\begin{remark}\n  Nonlinear encoder can recover linear encoder in a smaller dimension?\n  or coarser grid?\n\\end{remark}\n", "meta": {"hexsha": "4be509deb3d8ea121eafcf5527ccf48fd85fedae", "size": 14886, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/autoencoder.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/autoencoder.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/autoencoder.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.6974789916, "max_line_length": 367, "alphanum_fraction": 0.5740292893, "num_tokens": 5629, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.907312221360624, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7580444295345571}}
{"text": "\\chapter{Elliptic Curve Commitments}\n\\label{chpr:ec-commitments}\nElliptic curve cryptography is used in Bitcoin and in similar systems to secure the transactions. \nWe will give a brief overview of this cryptosystem, then we show how an elliptic curve point can be a commitment, finally we describe the consequent practical timestamping applications with Bitcoin.  \n\n\\section{Elliptic Curve Public Key Cryptosystem}\nWe start with a general definition taken from \\cite{Koblitz1987}\\footnote{See Appendix \\ref{app:A} for a more basic approach.},\n\\begin{mydef}\n\tAn elliptic curve $E_K$ defined over a field $K$ of characteristic $\\neq 2, 3$ is the set of solutions $(x,y)\\in K^2$ to the equation\n\t\\begin{equation}\n\t\\label{ec-eq}\n\ty^2 = x^3 + ax + b, \\quad a,b \\in K\n\t\\end{equation}\n\ttogether with a \\textquotedblleft point at infinity\\textquotedblright $\\mathcal{O}$.\n\\end{mydef}\n$\\mathcal{O}$ is the projective closure of (\\ref{ec-eq}) and may not be described in terms of two coordinates in $K$.\nThe points on $E_K$ form a group with identity element the point at infinity. The negative point $P \\in E_K$ is the second point on $E_K$ having the same $x$-coordinate as $P$. Let $P_1=(x_1,y_1)$ and $P_2=(x_2,y_2)$ be two points on the curve, their sum $P_3=(x_3,y_3) = P_1 + P_2$ is given by:\n\\begin{equation}\nx_3 = -x_1 -x_2 + \\alpha^2, \\quad \ny_3 = -y_1 + \\alpha(x_1 - x_3),\n\\end{equation}\nwhere\n\\begin{equation}\n\\alpha = \\begin{cases}\n\t\t\t(y_2 - y_1)/(x_2 - x_1) & \\textrm{if } P_1 \\neq P_2, \\\\\n\t\t\t(3x_1^2 + a)/(2y_1) & \\textrm{if } P_1 = P_2.\n\\end{cases}\n\\end{equation}\nThis \\textit{addition} operation for elliptic curve points has a geometric interpretation for $K = \\mathbb{R}$, from which the above more general algebraic formulae can be derived.\n\nUsing these formulae, one can compute a multiple $mP$ of a given point $P$ in polynomial time by means of $O(\\log m)$ doubling and additions, e.g. $11P = P + 2(P + 2(2P))$. This operation is called \\textit{scalar multiplication}.\n\nIn cryptography most applications use finite fields, in particular a finite field contains $p^m$ elements with $p$ prime and $m \\geq 1$. We will confine ourselves to the case $m=1$. So let $K=GF(p)=\\mathbb{F}_p =\\mathbb{Z}_p  = \\{0, 1, ..., p-1\\}$, $K$ is a finite field, the points of $E_K$, together with the addition operation defined above, form a finite Abelian group. The elliptic curve becomes:\n%cyclic or product of two cyclic groups\n\\begin{equation}\nE_{\\mathbb{F}_p}=\\{(x,y)\\in \\mathbb{F}_p^2 \\quad \\textmd{s.t. }\ny^2 = x^3 + ax + b \\mod p, \\quad a,b \\in \\mathbb{F}_p \\} \\cup \\mathcal{O}\n\\end{equation}\nLet $G \\in E_{\\mathbb{F}_p}$ be a conventional element of order $n$, called $generator$. The subgroup generated by $G$ is:\n\\begin{equation}\n\t\\langle G \\rangle = \\{xG|x \\in \\mathbb{Z}_n\\} \\subseteq E_{\\mathbb{F}_p}\n\\end{equation}\nWhich is a cyclic group isomorphic to $\\mathbb{Z}_n$; in particular, if $n$ is prime, then $\\langle G \\rangle = E_{\\mathbb{F}_p}$.\n\nComputing the isomorphism from $\\mathbb{Z}_n$ to $\\langle G \\rangle$ is efficient, it takes $O(\\log n)$ group operations; while the opposite isomorphism is much harder to compute, at moment, the best algorithm known takes approximately $\\sqrt{n}$ operations. The latter procedure is called discrete logarithm and it stands at the base of the cryptosystem, more precisely:\n\\begin{mydef}\n\tElliptic Curve Discrete Logarithm Problem (ECDLP). Given an elliptic curve $E$ defined over $GF(q)$ and two points $P, Q \\in E$, find an integer $x$ such that $Q = xP$ if such $x$ exists.\n\\end{mydef}\nElliptic curve cryptography is based on the premise that ECDLP is hard, actually it appears to be more intractable than DLP in finite fields.\nThe ECDLP difficulty enables a Diffie-Hellmann key exchange which precedes the ElGamal signature scheme, these techniques are at the foundations of the public key cryptosystem.\nFixed a point $P \\in E_{\\mathbb{F}_p}$, a \\textit{public key} is a point $Q \\in E_{\\mathbb{F}_p}$ while its discrete logarithm $x$ w.r.t. $P$ ($xP=Q$) is the \\textit{private key}.\nGiven $x$ is easy and fast to compute $Q$, while given $Q$ is infeasible to find $x$.\n\nTo classify different curves the Standard for Efficient Cryptography (SEC) proposed a set of parameter for elliptic curves over $\\mathbb{F}_p$:\n\\begin{equation}\n(p, a, b, G, n, h)\n\\end{equation}\n\\begin{itemize}\n\t\\item $p$ prime defines the finite field $\\mathbb{F}_p$\n\t\\item $a, b \\in \\mathbb{F}_p$ define the curve $E_{\\mathbb{F}_p}$\n\t\\item $G\\in E_{\\mathbb{F}_p}\\backslash \\{\\mathcal{O}\\}$ is a generator of the group\n\t\\item $n = |\\langle G \\rangle|$ is the order of the group (smallest $n>0$ s.t. $nG = \\mathcal{O}$)\n\t\\item $h = |E_{\\mathbb{F}_p}| / n$ is the cofactor\n\\end{itemize}\nNote that if $n$ prime, then $\\langle G \\rangle = E_{\\mathbb{F}_p}$, thus $n = |E_{\\mathbb{F}_p}|$, $h=1$.\nBitcoin uses the curve named $secp256k1$ with parameters\n\\begin{verbatim}\np = 0x FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF \n       FFFFFFFE FFFFFC2F\na = 0\nb = 7\nG = (0x 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 \n        59F2815B 16F81798, \n     0x 483ADA77 26A3C465 5DA4FBFC 0E1108A8 FD17B448 A6855419 \n        9C47D08F FB10D4B8)\nn = 0x FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B \n       BFD25E8C D0364141\nh = 1\n\\end{verbatim}\nWith this curve some calculation becomes more efficient, like computing the modular square root ($\\sqrt{x}=x^{\\lfloor\\frac{p+1}{4}\\rfloor}\\textmd{ mod }p$, since $p= 3 \\textmd{ mod }4$) and the modular inverse ($x^{-1}=x^{p-2}\\textmd{ mod }p$, since $p$ prime).\n\nLooking at the generator above one may think that to store an elliptic curve point is necessary to use 32 bytes for the $x$-coordinate and 32 bytes for the $y$-coordinate. \nHowever it is not necessary to use all that space, infact it is possible to take advantage of the elliptic curve equation. Suppose $x \\in \\mathbb{F}_p$ is the $x$-coordinate of a point, then $y$ is given by $y^2 = x^3 + ax + b \\quad \\text{mod }p$, which, for $p$ prime, has exactly two solutions in $\\mathbb{F}_p$, $y$ and $p-y$, one is odd and the other is even.\nThe solutions are easily computable thanks to the above formula.\nHaving consider this, to store an elliptic curve point $P$ one can store $P_x$ and the parity of $P_y$. \nIn Bitcoin the compressed encoding of a point $P$ is given by a byte for the parity of $P_y$ ($02$ if even, $03$ if odd) followed by the bytes representing $P_x$, for instance the generator $G$ is encoded as follows:\n\\begin{verbatim}\nG = 02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 \n       59F2815B 16F81798\n\\end{verbatim}\n\n\\section{A New Commitment Operation}\n\nCombining conveniently elliptic curve points and hash functions, it is possible to create new commitment operations.\nA similar technique was used for the first time for deriving public keys in deterministic wallets \\cite{Max11},\nthen the concept of embedding a value in an elliptic curve point was exploited \\cite{journals/corr/abs-1212-3257, Sidechain},\nlater it was reformulated in a more refined way \\cite{PoePR, PoeIs}\nsuitable for the integration in OpenTimestamps.\nLet's analyse how this new commitment operations are structured.\n\n\\begin{myprop}\n\tLet $E_{\\mathbb{F}_p}$ be an elliptic curve defined on the finite field $\\mathbb{F}_p$ with $p$ prime, $G \\in E_{F_p}$ be the generator of the curve with order $n$ large prime. Let $h$ be a random oracle hash function, its input are somehow serialized in bits, its output are in $\\{0,1\\}^k$ and are interpreted as integers.\n\tLet $C$ be defined as follows:\n\t\\begin{equation}\n\t\\begin{split}\n\tC : \\{0,1\\}^* \\times E_{\\mathbb{F}_p}  & \\rightarrow E_{\\mathbb{F}_p} \\\\\n\t    m, P & \\mapsto h(P||m)G + P\n\t\\end{split}\n\t\\end{equation}\n\tIf $n$ is close to $2^k$, then $C$ is a commitment operation.\n\\end{myprop}\n\\begin{proof}\n\tFirst we show a direct proof that works when $P$ (or $P'$) is fixed, then we show the general proof. Actually, in the former case, it is enough requiring $h$ to be second-preimage resistant, while, in the latter, a stronger assumption is needed.\n\t\\\\\n\tLet $m,P$ and $C(m,P)$ be fixed.\n\t%Let $C(m,P)$ be a commitment to $m, P$.\n\t$\\forall P' \\in E_{\\mathbb{F}_p}$ fixed in advance, the problem is to find $m' \\in \\{0,1\\}^*$ s.t. $C(m,P)=C(m',P')$ and $(m', P') \\neq (m, P)$. \n\tWe want to show that such problem is infeasible.\n\t$m'$ satisfies $h(m'||P')G + P'=C(m,P)$.\n\t%The substitute value $m'$ needs to satisfy $h(m'||P')G + P'=C(m,P)$.\n\tLet $x$ be such that $xG = C(m,P) - P'$, with $0\\leq x<n$. \n\t%so $x=h(P'||m')\\textmd{ mod }n$. The problem to find a second preimage $m'$ of $x$.\n\tLet $h_{P'}$ be defined as follows:\n\t\\begin{equation*}\n\t\\begin{split}\n\th_{P'}:\\{0,1\\}^* & \\rightarrow \\{0,1\\}^k\\\\\n\tm' & \\mapsto h(m'||P')\n\t\\end{split}\n\t\\end{equation*}\n\tConsider the elements in $\\{0,1\\}^{k}$ equivalent to $x$ modulo $n$, namely $I_x=\\{h \\in \\{0,1\\}^k \\approx \\mathbb{Z}_{2^k} | h=x\\textmd{ mod }n\\}$.\n\t%Let $I_x=\\{h \\in \\{0,1\\}^k \\approx \\mathbb{Z}_{2^k} | h=x\\textmd{ mod }n\\}$ be the set of images of $h_{P'}$ suitable to find a second-preimage.\n\tNote that:\n\t\\begin{equation*}\n\t\t|I_x|=\\begin{cases}\n\t\t\t\t\\lceil\\frac{2^k}{n}\\rceil & \\textmd{if } x\\geq n \\\\\n\t\t\t\t\\lfloor\\frac{2^k}{n}\\rfloor & \\textmd{if } x< n\n\t\t      \\end{cases}\n\t\\end{equation*}\n\tThe problem is finding $h_{p'}(m')\\in I_x$.\n\tNote that $h_{p'}$ is second-preimage resistant, since it is the composition of two functions with that property, $prepend(P')$ and $h$.\n\tFinally, if $n \\approx 2^k$, the elements in $I_x$ are few (eventually a single one), thus finding $m'$ is infeasible because $h_{P'}$ is second-preimage resistant.\n\t%$I_x$ contains  $\\lceil\\frac{2^k}{n}\\rceil$ or $\\lfloor\\frac{2^k}{n}\\rfloor$ elements.\n\t%Hence to find a second-preimage one needs to find $m'$ s.t. $h_{P'}(m') \\in I_x$. Note that $h_{P'}$ is second-preimage resistant, since it is the composition of two function with that property, $prepend(P')$ and $h$. Finally, if $n \\approx 2^k$, the elements in $I_x$ are few (eventually a single one), thus finding $m'$ is unfeasible because $h_{P'}$ is second-preimage resistant.\n\t\\\\\n\tNow consider the case in which $P$ is not fixed.\n\tWe model the hash function $h$ as a random oracle $H$ with range $\\{0,1\\}^k\\approx \\mathbb{Z}_{2^k}$.\n\t$H$ initially has an empty table. \n\tWhen someone queries the oracle for a value $x \\in \\{0,1\\}^*$,\n\tthe oracle samples uniformly a random value $H(x)$ in $\\mathbb{Z}_{2^k}$ and associate it with $x$.\n\tThe oracle outputs $H(x)$ and annotate it on his table.\n\tIf someone calls again the oracle for $x$ he will answer with $H(x)$.\n\tThe oracle is queried by different entities for possibly different values.\n\tQueries for new values result in a new line in the table.\n\tThus before querying $H$ for $x \\in \\{0,1\\}^*$, we expect $H$ to output a uniform random value in $\\mathbb{Z}_{2^k}$.\n\t\\\\\n\tNow suppose the  discrete logarithm is broken, so anyone can run the map $x \\mapsto xG$ both ways.\n\tThe map:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\tilde{C} : \\{0,1\\}^* \\times E_{\\mathbb{F}_p}  & \\rightarrow E_{\\mathbb{F}_p} \\\\\n\tm, P & \\mapsto H(P||m)G + P\n\t\\end{split}\n\t\\end{equation*}\n\twhere $h$ is substituted by $H$. \n\tIf $P=xG$, it becomes:\n\t\\begin{equation*}\n\t\\begin{split}\n\t\\hat{C} : \\{0,1\\}^* \\times \\mathbb{Z}_n  & \\rightarrow \\mathbb{Z}_n \\\\\n\tm, x & \\mapsto (H(xG||m) + x)\\textmd{ mod }n\n\t\\end{split}\n\t\\end{equation*}\n\tWe show that $\\hat{C}$ can be used as a random oracle.\n\t$H$ is uniformly random and independent from its inputs, \n\tmoreover the offset $x$ cannot affect that.\n\tApplying $\\textmd{mod }n$ shrinks the range to $\\mathbb{Z}_n$,\n\tstill $\\hat{C}$ can be used as a random oracle.\n\tFinally the output of $\\hat{C}$, which is equivalent to $C$, is indistinguishable from the output of a random uniform distribution in $\\mathbb{Z}_n$.\n\tSince $n$ is close to $2^k$ finding a second-preimage to $C(m,P)$ is infeasible. \n\t%Now consider the case in which $P$ is not fixed.\n\t%Suppose we are able to find $x$ s.t. $P=xG$, the map $C$ can be seen as $m,x \\mapsto x + h(xG||m)$ which is basically $m,x \\mapsto x + \\tilde{h}(x,m)$ for an opportune $\\tilde{h}$.\n\t%If such map is a random oracle then we are done, since random oracles are second preimage resistant.\n\t%We assume $h$ is a random oracle, then also $\\tilde{h}$ has the same feature, since it is independent from its input, moreover the offset $x$ does not affect the property. \n\t%Hence we conclude that the map is a random oracle which gives second preimage resistance.\n\\end{proof}\n\nThe order $n$ has to be large so that $E_{\\mathbb{F}_p}$ is rich enough to make the ECDLP intractable and to avoid shrinking the hash function codomain. Fixed $n$ the choice of $k$ should be made properly: if it is too low $h$ by itself will be too weak, if it is too high, $|I_x|$ will increase, weakening $C$. Hence a good compromise is choosing $n$ the closest possible to $2^k$.\n\nThe security of the commitment is given by the security of the hash function, and does not rely on the intractability of the ECDLP. Being able to compute the private key from the commitment is not enough to compute a second input committing to the same point, to do so it is necessary to able to find a second-preimage to an hash value.\n\nWith this commitment an elliptic curve point used for one purpose can be tweaked with $h(P||m)$ and, while still serving for the previous purpose, it can be a commitment to a value $m$. In fact suppose $x$ is the private key of $P$, $P=xG$, then $C(m,P)=(h(P||m)+x)G$. So the new private key is $(h(P||m)+x) \\textmd{mod } n$ and, since $x$ is secret and $h(P||m)$ is a constant value, the resulting key is still secret.\nSo each time an elliptic curve point is written, we can encapsulate it in a commitment to an arbitrary value.\nThis technique may be extended to more general cases, but we will treat only the case of elliptic curves.\n\nSeveral hash functions and elliptic curves can be used, considering we want to use Bitcoin as notary, we will focus an a particular case with $h=$ SHA256 and $E_{\\mathbb{F}_p}=secp256k1$ since Bitcoin itself relies on the assumption that this hash function and this elliptic curve are not broken.\nMoreover, the order of the curve $n$ is extremely close\\footnote{Assuming that a generic output $x$ of SHA256 is indistinguishable from a sampling from an uniform distribution in $\\mathbb{Z}_{2^{256}}$, then $\\mathbb{P}(x\\geq n)=1-\\frac{n}{2^{256}}\\approx 10^{-33}$. So the chance to choose $(P||m)$ leading to $|I_x|=2$ is almost zero.} \nto the cardinality of the hash function codomain $2^{256}$. This commitment operation is called \\verb|OpSecp256k1Commitment|.\n\nFurthermore, to use this operation in as OpenTimestamp receipt, it has to be an unary operation, hence it will take as input $P||m$ and will return the $x$-coordinate of $C(m P)$ as output, both in bytes. More precisely it will operate as described in Algorithm \\ref{alg:opsecp256k1}.\n\\begin{algorithm}\n\t\\caption{Commitment to a $secp256k1$ point using SHA256}\n\t\\label{alg:opsecp256k1}\n\t\\begin{algorithmic}[1]\n\t\\Procedure{OpSecp256k1Commitment}{$c$}\\Comment{$c$ is $P||m$}\n\t\\State $P,m \\gets$ \\Call{decode}{$c$}\\Comment{for bad $c$  return error}\n\t\\State $tweak \\gets h(P||m)$\\Comment{interpreted as an int}\n\t\\State $Q \\gets tweak G + P$\n\t\\State \\textbf{return} \\Call{encode}{$Q_x$}\\Comment{output in bytes}\n\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\nIt can be used for several purposes, however, for this work, we focus only on timestamping.\n\n\\section{Timestamping Applications}\nOn the Bitcoin chain, elliptic curve points are used as public keys locking bitcoins or as part of the signature. The first case lead to the \\textit{pay-to-contract} technique, the second to \\textit{sign-to-contract}. We will analyse both uses and we will explain which one should be preferred.\n\nThese names owe their origin to the first application for which they were though: associate a \\textit{contract} to an elliptic curve point. \nThe term contract may seem misleading, but it turns out to be useful dealing with \\textit{sign-to-contract}, since it let us distinguish between the message signed and the contract committed.\n\n\\subsection{\\textit{pay-to-contract}}\nPublic keys are elliptic curve points, here we show how they could commit to a value while still maintaining the secrecy of the private key.\n\nWe illustrate it through an example. \nAlice needs to send Bob some bitcoins. \nBob has public key $P=xG$. \nBob wants to timestamp the message $m$. \nBob computes $Q=h(P||m)G+P$. \nBob tells Alice that his public key is $Q$.\nAlice broadcasts a transaction sending bitcoins to $Q$, for instance she uses a P2PK publishing on the chain:\n\\begin{verbatim}\nscript pubkey:\n<Q> OP_CHECKSIG\n\\end{verbatim}\nBob can spend the bitcoin locked in this script because he knows $P$, $m$ and $x$, so he can compute the private key corresponding to $Q$, that is $(h(P||m)+x) \\textmd{ mod } n$.\nTo create the timestamp proof he has to decompose the transaction including $Q$ and create a proof that will look like:\n\\begin{verbatim}\nprepend P\nsecp256k1commitment\nprepend TX_p\nappend TX_a\nsha256\n...\nsha256\nverify BitcoinBlockHeaderAttestation(block)\n\\end{verbatim} \nIn the case of P2PKH, the committed public key is hashed as shown in the following real example, where \\verb|b'Pay to contract!\\n'| is timestamped: \n\\begin{Verbatim}[frame=single]\nFile sha256: 47257ff8c07f55a2e697ab9d89e47b471f60ab3f6883ed05\n             44561b2a39a26140\nTimestamp:\nprepend 02a1e5aafa5082d035c659143660b2526a4ba60d4ab5b2e603905\n        0eae9444d56ee\nsecp256k1commitment\nprepend 02\nsha256\nripemd160\nprepend 01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1\n        bf933501a87986363464c000000006a47304402207724a6a96e91\n        a10821ee0c6db30a2f764ba8bd1dcdc82812fb958f6b91e97a4a0\n        22062db4df7205e6c97d9833f7ab0d597b7685e8320bb2031f57a\n        a6981cd2f626a40121030eb7a6c01ab07d3bfe598c295e9edfbeb\n        38e5d2df7320f16b4349fb89a975ab7fdffffff02e22000000000\n        00001976a914d8da7633fe644eb12617b2b1f0ba3f0461a2bc5e8\n        8ac10270000000000001976a914\nappend 88ac4ed90700\n# Bitcoin transaction id\n1b07d87e0f4e32d545932bf03e306d1532bc7d91f56e81dee81b7cd0b707a9\n9d\nsha256\nsha256\nprepend 9d12daa914a3d39cd25b36516383683aae3ac6f873b952bbab11cc\n        417650bb49\nsha256\nsha256\nprepend 0123f36690131b2416d32a7e6c3c63110d9d77873911f71ad22740\n        b398a13874\nsha256\nsha256\nappend 9f45bbc92ac4ef65b5e5bfad479da46c400f6e7ab96217a20b4e08d\n       bfab47a45\nsha256\nsha256\nprepend 949c83f6b502ec75c4647da6ed4e26d181de07b325eac75881de7b\n        b715a44c50\nsha256\nsha256\nprepend 2ef8ff1aad05e891215698fe237546c73347967419f33d08baf0d9\n        71ab00004d\nsha256\nsha256\nappend 9bf69359a440f6a15a2a11adb1f257c96089ad27ef66e57a19056e3\n       3ecc1795b\nsha256\nsha256\nprepend c1c9bb36792745df3967704dd5d15899bab47b0a9de35486eb339a\n        b4d00ff340\nsha256\nsha256\nappend c0b13e8aa4dc85a8256efb03272dea659e41fc67bc2f44add154111\n       c68f700be\nsha256\nsha256\nappend 1bf843d12afce2a7b02ebe1f083eb2c39a101a63474a622724f609a\n       3f08f8c7f\nsha256\nsha256\nappend a29eece3554c358e5df3901478c8670c71dbafe4e435cf660a18bb6\n       09d6d025d\nsha256\nsha256\nappend aa2c4696c3b75f73713345a7e4279805a9519fd067835769b41dcf7\n       88d6a7c96\nsha256\nsha256\nprepend f7290a75923a0c54e87a50bbeff75f614437ed799347a46053a633\n        8dba42b5c7\nsha256\nsha256\nverify BitcoinBlockHeaderAttestation(514394)\n# Bitcoin block merkle root\nbe6859c5093de84a06e495b6621054616ce5bf7a38f24374a225d0da0c0de8\n88\n\\end{Verbatim} \nThe raw transaction with the above TXID is \n\\begin{Verbatim}[commandchars=+\\[\\], frame=single]\n01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1bf933501a\n87986363464c000000006a47304402207724a6a96e91a10821ee0c6db30a2f\n764ba8bd1dcdc82812fb958f6b91e97a4a022062db4df7205e6c97d9833f7a\nb0d597b7685e8320bb2031f57aa6981cd2f626a40121030eb7a6c01ab07d3b\nfe598c295e9edfbeb38e5d2df7320f16b4349fb89a975ab7fdffffff02e220\n0000000000001976a914d8da7633fe644eb12617b2b1f0ba3f0461a2bc5e88\nac10270000000000001976a914+underline[57529515dc2e14701374eb65f0191b61ecfd]\n+underline[d0e3]88ac4ed90700\n\\end{Verbatim}\nWhere the commitment to the data is underlined.\n\nThis technique is completely viable, but it has a relevant issue.\nAlmost all bitcoin wallets (software to manage private keys) use a deterministic derivation for creating new keys \\cite{BIP32}. An initial value is generated at random using a cryptographically secure procedure, this value is called \\textit{seed} and sometimes encoded as a list of words from a given dictionary. The keys are obtained from the seed using the specifications given by BIP32 and they are something like $h(seed||number)$. This procedure make possible to completely recover a wallet from the seed only, so if a user wants to use his wallet from another device he just need to remember the seed and all his private keys will be reconstructed.\nUsing pay-to-contract actually Bob goes outside of the BIP32 derivation. So if he looses $m$ or $P$ he won't be able to spend the bitcoin locked by $Q$. For this reason the use of \\textit{pay-to-contract} for mere timestamping purposes should be limited.\n\nIn the case of a P2PKH, a timestamp made with \\textit{pay-to-contract} reveals the public key which is the preimage of the receiving address. \nThe public key will be revealed anyway when the corresponding output will be spent, but, if it is still unspent, such disclosure may be an undesired feature. \nIn addition, when spending that UTXO, the public key is actually written in the chain, giving another anchoring point to create a different timestamp; this timestamp is just another path from the data to the chain, but it is not really useful since it cannot precede the other timestamp.\n\n\\subsection{\\textit{sign-to-contract}}\nThe other place where elliptic curve points are published in the chain is the signature. Bitcoin uses the elliptic curve digital signature algorithm, ECDSA\\footnote{\\textit{sign-to-contract} works also with other signature schemes involving elliptic curves, like Schnorr signature.}, that works as detailed in Algorithm \\ref{alg:ecdsa-sign}.\n\\begin{algorithm}\n\t\\caption{ECDSA signature}\n\t\\label{alg:ecdsa-sign}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{ECDSAsig}{$x, m$}\\Comment{$x$ private key signing}\n\t\t\\Statex \\Comment{$m$ 32 bytes message to be signed}\n\t\t\\State $k \\in_R \\mathbb{Z}_n \\backslash \\{0\\}$ \\Comment{select $k$ at random in $\\{1,..., n-1\\}$}\n\t\t\\State $R \\gets k G$\n\t\t\\State $r \\gets R_x \\textmd{ mod }n$\\Comment{if $r=0$, fail}\n\t\t\\State $s \\gets k^{-1}(m + rx) \\textmd{ mod }n$\\Comment{if $s=0$, fail}\n\t\t\\State \\textbf{return} $(r,s)$\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\nThe value $k$ is called nonce or \\textit{ephemeral private key}, $R$ is called \\textit{ephemeral public key}.\n\nA signature is a couple of integers in $\\{1,...,n-1\\}$, the first one is the $x$-coordinate (mod $n$) of the ephemeral public key.\nThe idea of \\textit{sign-to-contract}, exploited in Algorithm \\ref{alg:ecdsa-s2c}, is to tweak $R$, so that the first part of the signature will be a commitment to (also) another message, the contract $c$.\n\\begin{algorithm}\n\t\\caption{ECDSA \\textit{sign-to-contract} (s2c)}\n\t\\label{alg:ecdsa-s2c}\n\t\\begin{algorithmic}[1]\n\t\t\\Procedure{ECDSAs2c}{$x, m, c$}\\Comment{$x$ private key signing}\n\t\t\\Statex \\Comment{$m$ 32 bytes message to be signed}\n\t\t\\Statex \\Comment{$c$ contract to commit}\n\t\t\\State $k \\in_R \\mathbb{Z}_n \\backslash \\{0\\}$ \\Comment{select $k$ at random in $\\{1,..., n-1\\}$}\n\t\t\\State $R \\gets k G$\n\t\t\\State $tweak \\gets h(R||c)$\\Comment{interpreted as an int}\n\t\t\\State $e \\gets (k + tweak) \\textmd{ mod }n$ \\Comment{if $e=0$, fail}\n\t\t\\State $Q \\gets tweak G + R$\n\t\t\\State $q \\gets Q_x \\textmd{ mod }n$\\Comment{if $q=0$, fail}\n\t\t\\Statex \\Comment{if $q \\neq Q_x$, commitment fail}\n\t\t\\State $s \\gets e^{-1}(m + qx) \\textmd{ mod }n$\\Comment{if $s=0$, fail}\n\t\t\\State \\textbf{return} $(q,s), R$\\Comment{$R$ is needed to prove the commitment}\n\t\t\\EndProcedure\n\t\\end{algorithmic}\n\\end{algorithm}\n\nLet's examine a real timestamp for the data \\verb|b'Sign to contract\\n'| made with the described technique.\n\\begin{Verbatim}[frame=single]\nFile sha256: dd60bcfecd023823efdcb8d8a5b04939111ef82dc1d674320\n             7e164e5aab08844\nTimestamp:\nappend eb7e45e783d98504b2e64342b0bea3f5\nsha256\nprepend 0372a1fb359a24eab552e8c588f84b7e08144bbb10e87bfa6db649\n        8c7df730e867\nsecp256k1commitment\nprepend 01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1b\n        f933501a87986363464c010000006a4730440220\nappend 022057db028ba602b467d09f67b6a6327d3219f2d9a264aae935873\n       146247a18008a0121027f4b59c84fbad07dec6cff8555214b1d3740\n       43bcdf47a35fbe08cf5a816b2a9ffdffffff02a6220000000000001\n       976a914c7a270de581a188f1decef735602cfd65a70607c88ac1027\n       0000000000001976a914ebc32f6f0a4d63da2d1a2f1f5cb762d0d89\n       824d488acf3d90700       \n# Bitcoin transaction id \n3b6b0f10729cd0d90087e8c8c9261a2b41afa4e26508591700ddd1790b5087\n05\nsha256\nsha256\nappend 8c6c3e7341ac6b64c17e4558a5279da1ccf5a0346abbcb1eed412db\n       103ff7cb5\nsha256\nsha256\nprepend 8446d10571b0a6c63a0fb9538531d846148c9465eff456cccbaf91\n        1a967bc74c\nsha256\nsha256\nprepend 66cdb8cf28763b45e195028566a0bd976afcf7ad072188e711e515\n        41f6867e43\nsha256\nsha256\nprepend 465585e6b3ff7dfc8d753acce6e60c1ccd246975641dd4ad8b95c3\n        803244aca7\nsha256\nsha256\nappend 93bcaa3a00534081d6f2230412cde7e59a73acb0d98c809174f630d\n       e3b07b89d\nsha256\nsha256\nappend 0f1b327e68d8700e9c4074d8b4b82b0e28a5a7933f29f643cb27bd5\n       6bf668ec6\nsha256\nsha256\nappend d8738b3726def527296f47a70e0ba6841e35932e2ac8a0832c25393\n       ee320d4fc\nsha256\nsha256\nappend 73694be809a1f8d8a81f55e812c47d388747e1d99003d5b5427ca41\n       1a5fd4408\nsha256\nsha256\nappend 816fb904a9d0678198e84f060aecca9383320bebfec2d23783c922b\n       cdcb58af2\nsha256\nsha256\nprepend f42214bc9a9c8e4b61a53e51c94ef9bbb2956202356054cd7a7677\n        858caae2de\nsha256\nsha256\nprepend 1d71d75ef769c40aec08c7ccda1a64a82ee6e858efb5f8598f5199\n        a093b512d1\nsha256\nsha256\nappend 00b4475e869c96c8c297fce9ea8494f0b8f5c74d7b4e6208ba8fc84\n       d103f61d2\nsha256\nsha256\nverify BitcoinBlockHeaderAttestation(514550)\n# Bitcoin block merkle root \n1d978e90baecf86c9b59ecad7d8e635da27aad41b39a1d4452c7654f9d5cd3\ndd\n\\end{Verbatim}\nThe raw transaction with the above TXID is \n\\begin{Verbatim}[commandchars=+\\[\\], frame=single]\n01000000018fccf63afda6cf748acfe946a344f417bd4a8994bc1bf933501a\n87986363464c010000006a4730440220+underline[280686720849bfd72a3c7793a45610]\n+underline[db2f0152422183bb1f7181ca003674aea5]022057db028ba602b467d09f67b6\na6327d3219f2d9a264aae935873146247a18008a0121027f4b59c84fbad07d\nec6cff8555214b1d374043bcdf47a35fbe08cf5a816b2a9ffdffffff02a622\n0000000000001976a914c7a270de581a188f1decef735602cfd65a70607c88\nac10270000000000001976a914ebc32f6f0a4d63da2d1a2f1f5cb762d0d898\n24d488acf3d90700\n\\end{Verbatim}\nWhere the commitment value is underlined.\n\nUsing \\textit{sign-to-contract} every signature can include a commitment to a certain value. Contrary to \\textit{pay-to-contract}, the loss of $c$ or $R$ leads to the impossibility of proving the commitment but not to a loss of funds. Indeed the signature published on the chain has already provided to its original purpose moving the coins to another owner. This makes \\textit{sign-to-contract} a preferable commitment scheme.\n\nIn Algorithm \\ref{alg:ecdsa-sign} and \\ref{alg:ecdsa-s2c} the nonce $k$ is generated at random, however often computers are poor sources of randomness which may lead to security issues, namely exposing the nonce $k$ actually reveals the private key $x$. \nTo reduce this problem, it is a common practice to avoid the random generation, instead, it is performed a deterministic derivation of the type $k \\gets h(x||m)$, the precise specification of $h$ is given by the RFC6979 standard \\cite{rfc6979}. With this technique,  in a signature, the private key is unique source of entropy used for security, indeed the message $m$ is public and the nonce $k$ is as secret as $x$, since, without $x$, it is not possible to guess $h(x||m)$.\nDeterministic nonce and \\textit{sign-to-contract} are completely independent techniques that can improve a signature scheme, it is possible to implement one without the other.\n\nIn addition, exposing two signature for the same message $m$, generated with the same private key $x$, but made using two different nonces $k_1, k_2$ reveals the private key.\nThis is a relevant issue when managing bitcoin, however signing with a deterministic nonce solves this problem.\nWith \\textit{sign-to-contract}, considering a message $m$, private $x$, a deterministic nonce, but two contracts $c_1, c_2$, such issue, despite the deterministic derivation, arises again. \nThus is important take care of this chance during the implementation.\n\nUsing a deterministic nonce also, in some sense\\footnote{To verify that the nonce is deterministic, it is necessary the knowledge of the private key, thus the verification cannot be performed by whoever. Moreover, in some cases, like bitcoin hardware wallets, extracting the secret key may be hard or unsafe.}, closes the subliminal channel in ECDSA signature. \nThe signer has some arbitrariness in choosing the nonce and could use it to transmit a certain message, as exploited in \\cite{DBLP:journals/jsac/Simmons98}. \nWith \\textit{sign-to-contract} the nonce is still deterministic, but is a function of $x,m$ and, in addition, $c$. \nThe technique could be seen as a particular use of the subliminal channel of ECDSA.\nConsider the case where Alice wants to secretly communicate a simple message $c$ to Bob. Alice produces a signature which is a commitment via \\textit{sign-to-contract} to a simple message $c$. Alice declares $P$ publicly. Bob knows that $c$ comes from a brute forceable set $S$. Bob sees the signature and tries all $c \\in S$ until he finds the one which generated the commitment. As a result, Alice sent to Bob a message without anyone noticing the communication using the subliminal channel that ECDSA leaves open.", "meta": {"hexsha": "3d1b26ec9b40f55d78e7270943769954b1b34bb0", "size": 29921, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Chapters/Elliptic_Curve_Commitments.tex", "max_stars_repo_name": "LeoComandini/Thesis", "max_stars_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2018-04-09T03:42:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-20T10:25:26.000Z", "max_issues_repo_path": "Chapters/Elliptic_Curve_Commitments.tex", "max_issues_repo_name": "LeoComandini/Thesis", "max_issues_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_issues_repo_licenses": ["MIT"], "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/Elliptic_Curve_Commitments.tex", "max_forks_repo_name": "LeoComandini/Thesis", "max_forks_repo_head_hexsha": "d5754ae5c05f110e1fba115dc011f240878933f3", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-04-06T17:48:54.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-19T09:36:36.000Z", "avg_line_length": 61.3135245902, "max_line_length": 654, "alphanum_fraction": 0.7551886635, "num_tokens": 10086, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122213606241, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.758044418384544}}
{"text": "\\lab{Givens rotations and Least squares}{Givens rotations and Least squares}\n\\objective{Use Givens rotations to find the QR decomposition and use least squares to fit curves to data.}\n\\label{lab:givens}\n\nIn Lab \\ref{lab:QRdecomp}, we found the QR decomposition of a matrix using Householder transformations, applying a series of these transformations to a matrix until it was in upper triangular form.\nWe can use the same strategy to compute the QR decomposition with rotations instead of reflections.\n\n\\section*{Givens rotations}\n\nLet us begin with Givens rotations in $\\mathbb{R}^2$. \nAn arbitrary vector $\\x = (a, b)\\trp$ can be rotated into the span of $e_1$ via an orthogonal transformation. \nIn fact, the matrix $T_{\\theta} = \\begin{pmatrix}\\cos \\theta & - \\sin \\theta \\\\ \\sin \\theta & \\cos \\theta \\end{pmatrix}$ rotates a vector counterclockwise by $\\theta$.\nThus, if $\\theta$ is the clockwise-angle between $\\x$ and $e_1$, the vector $T_{-\\theta}\\x$ will be in the span of $e_1$.\nWe can find $\\sin \\theta$ and $\\cos \\theta$ with the formulas $\\sin = \\frac{\\text{opp}}{\\text{hyp}}$ and $\\cos = \\frac{\\text{adj}}{\\text{hyp}}$, so $\\sin \\theta = \\frac{b}{\\sqrt{a^2+b^2}}$ and $\\cos \\theta =  \\frac{a}{\\sqrt{a^2+b^2}}$ (see Figure\\ref{fig:angle}).\nThen \n\\[\nT_{-\\theta}\\x = \\begin{pmatrix}\\cos \\theta &  \\sin \\theta \\\\ -\\sin \\theta & \\cos \\theta \\end{pmatrix} \\begin{pmatrix} a \\\\ b \\end{pmatrix} = \\begin{pmatrix}\\frac{a}{\\sqrt{a^2+b^2}} & \\frac{b}{\\sqrt{a^2+b^2}} \\\\ -\\frac{b}{\\sqrt{a^2+b^2}} & \\frac{a}{\\sqrt{a^2+b^2}} \\end{pmatrix}\\begin{pmatrix} a \\\\ b \\end{pmatrix} = \\begin{pmatrix} \\sqrt{a^2+b^2} \\\\ 0 \\end{pmatrix}.\n\\]\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[-, thick](-.5,0)--(3,0);\n\\draw[-, thick](0,-.5)--(0,1.5);\n\\draw[->, thick, >=stealth'](0,0)--(2.5,1);\n\\draw[-,thick](2.5,-.2)--(2.5,.2);\n\\draw[-, thick](-.2,1)--(.2,1);\n\\node[draw=none](point_b)at(2.5,-.4){$a$};\n\\node[draw=none](point_a)at(-.4,1){$b$};\n\\draw[-, thick] (.5,.2)arc [start angle=60, \n\tend angle=-20, radius=4.5pt];\n\\node[draw=none](theta)at(.8, .15){$\\theta$};\n\\end{tikzpicture}\n\\caption{Rotating clockwise by $\\theta$ will send the vector $(a,b)\\trp$ to the span of $e_1$.}\n\\label{fig:angle}\n\\end{center}\n\\end{figure}\n\n\n\nThe matrix $T_{\\theta}$ above is an example of a $2 \\times 2$ Givens rotation matrix. \nIn general, the Givens matrix $G(i,j,\\theta)$ represents the orthonormal transformation that rotates the 2-dimensional span of $e_i$ and $e_j$ by $\\theta$ radians. \nThe matrix for this transformation is\n\\begin{equation*}\nG(i,j,\\theta) = \\begin{pmatrix}\nI & 0 & 0 & 0 & 0 \\\\\n0 & c & 0 & -s & 0 \\\\\n0 & 0 & I & 0 & 0 \\\\\n0 & s & 0 & c & 0 \\\\\n0 & 0 & 0 & 0 & I\n\\end{pmatrix}.\n\\end{equation*}\nThis matrix is in block form with $I$ representing the identity matrix, $c=\\cos \\theta$, and $s=\\sin \\theta$. \nThe $c$'s appear on the $i^{th}$ and $j^{th}$ diagonal entries. \n\nAs before, we can choose $\\theta$ so that $G(i,j,\\theta)$ rotates a given vector so that its $e_j$-component is 0. \nSuch a transformation will only affect the $i^{th}$ and $j^{th}$ entries of any vector it acts on (and thus the $i^{th}$ and $j^{th}$ rows of any matrix it acts on). \n\n\n\nThis flexibility makes Givens rotations ideal for some problems.\nFor example, Givens rotations can be used to solve linear systems defined by sparse matrices by modifying only small parts of the array.\nAlso, Givens rotations can be used to solve systems of equations in parallel.\n\nThe advantages of Givens rotations are that they orthonormal and hence numerically stable (like Householder reflections), and they affect only a small part of the array (like Gaussian elimination).\nThe disadvantage is that they require a greater number of floating point operations than Householder reflections.\n% Accuracy and Stability of Numerical Algorithms, Nicholas J. Higham\nIn practice, the Givens algorithm is slower than the Householder algorithm, even when it is modified to decrease the number of floating point operations. \n% Fast Plane Rotations With Dynamic Scaling, Anda and Park, SIAM, 1994\nHowever, since Givens rotations can be parallelized, they can be much faster than the Householder algorithm when multiple processors are used.\n% Givens and Householder Reductions for Linear Least Squares on a Cluster of Workstations, Omer Egecioglu and Ashok Srinivasan\n\n\n\n\n\\subsection*{Givens triangularization}\nWe can apply Givens rotations to a matrix until it is in upper triangular form, producing a factorization $A = QR$ where $Q$ is a composition of Givens rotations and $R$ is upper triangular.\nThis is exactly the QR decomposition of $A$.\n\nThe idea is to iterate through the subdiagonal entries of $A$ in the order depicted by Figure \\ref{fig:givens}. \nWe zero out the $ij^{th}$ entry with a rotation in the plane spanned by $e_{i-1}$ and $e_i$. \nThis rotation is just multiplication by the Givens matrix $G(i-1,i,\\theta)$, which can be computed as in the example at the start of the previous section. \nWe just set $a=a_{i-1,j}$ and $b=a_{i,j}$, so $c = \\cos \\theta = a/\\sqrt{a^2+b^2}$ and $s = -b/\\sqrt{a^2+b^2}$.\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[xscale=.7, yscale=.7]\n\\draw[->, gray, thick](0,0)--(0,5.5);\n\\draw[->, gray, thick](1,0)--(1,4.5);\n\\draw[->, gray, thick](2,0)--(2,3.5);\n\\draw[->, gray, thick](3,0)--(3,2.5);\n\\draw[->, gray, thick](4,0)--(4,1.5);\n\\node[draw=none] at(0,-1){\\large 1};\n\\node[draw=none] at(1,-1){\\large 2};\n\\node[draw=none] at(2,-1){\\large 3};\n\\node[draw=none] at(3,-1){\\large 4};\n\\node[draw=none] at(4,-1){\\large 5};\n\n\\draw[-, ultra thick] (0,6)--(4,2);\n\n\\draw[-, thick](-1,-.5)--(-1,6.5);\n\\draw[-, thick](-1, -.5)--(-.5,-.5);\n\\draw[-, thick](-1,6.5)--(-.5,6.5);\n\n\\draw[-, thick](5,-.5)--(5,6.5);\n\\draw[-, thick](5,-.5)--(4.5,-.5);\n\\draw[-, thick](5,6.5)--(4.5,6.5);\n\n%\\draw[-, thick](-.5,0)--(3,0);\n%\\draw[-, thick](0,-.5)--(0,1.5);\n%\\draw[->, thick, >=stealth'](0,0)--(2.5,1);\n%\\draw[-,thick](2.5,-.2)--(2.5,.2);\n%\\draw[-, thick](-.2,1)--(.2,1);\n%\\node[draw=none](point_b)at(2.5,-.4){$a$};\n%\\node[draw=none](point_a)at(-.4,1){$b$};\n%\\draw[-, thick] (.5,.2)arc [start angle=60, \n%\tend angle=-20, radius=4.5pt];\n%\\node[draw=none](theta)at(.8, .15){$\\theta$};\n\\end{tikzpicture}\n\\caption{This figure illustrates the order in which to zero out subdiagonal entries in the Givens triangularization algorithm. \nThe heavy black line is the main diagonal of the matrix. \nEntries should be zeroed out from bottom to top in each column, beginning with the leftmost column.}\n\\label{fig:givens}\n\\end{center}\n\\end{figure}\n\n\nFor example, on a $2 \\times 3$ matrix we may perform the following operations:\n\n\\def\\mc#1{\\multicolumn{1}{c|}{#1}}\n\\def\\lc#1{\\multicolumn{1}{|c}{#1}}\n\\[\n\\begin{array}{ccccccc}\n\\begin{pmatrix}\n*&*\\\\\n*&*\\\\\n*&*\n\\end{pmatrix}\n&\n\\underrightarrow{G(2,3,\\theta_1)}\n&\\begin{pmatrix}\n&*&*&\\\\ \\cline{2-3}\n&\\lc{*}&\\mc{*}&\\\\\n&\\lc{0}&\\mc{*}& \\\\ \\cline{2-3}\n\\end{pmatrix}\n&\n\\underrightarrow{G(1,2,\\theta_2)}\n& \\begin{pmatrix} \\cline{2-3}\n&\\lc{*}&\\mc{*}&\\\\\n&\\lc{0}&\\mc{*}&\\\\ \\cline{2-3}\n&0&*&\n\\end{pmatrix}\n&\n\\underrightarrow{G(2,3,\\theta_3)}\n&\\begin{pmatrix}\n*&*&\\\\ \\cline{2-2}\n\\mc{0}&\\mc{*}&\\\\\n\\mc{0}&\\mc{0}&\\\\ \\cline{2-2}\n\\end{pmatrix}\n\\end{array}\n\\]\nAt each stage, the boxed entries are those modified by the previous transformation. \nThe final transformation $G(2,3,\\theta_3)$ operates on the bottom two rows, but since the first two entries are zero, they are unaffected. \nAssuming that at the $ij^{th}$ stage of the algorithm, $a_{ij}$ is nonzero, Algorithm \\ref{Alg:givens} computes the Givens triangularization of a matrix..\n\n\n\\begin{algorithm}\n\\begin{algorithmic}[1]\n\\caption{Givens triangularization. Return an orthogonal matrix $Q$ and an upper triangular matrix $R$ satisfying $A = QR$.}\n\\label{Alg:givens}\n\\Procedure{Givens Triangularization}{$A$}\n\\State $m, n \\gets \\shape{A}$\n\\State $R \\gets \\makecopy{A}$\n\\State $Q \\gets \\Id{m}$\n\\State $G \\gets \\allocate{2}{2}$\n\\For{$j=0\\ldots n-1$}\n    \\For{$i=m\\ldots j+1$}\n      \\State $a, b \\gets R[i-1,j], R[i,j]$\n      \\State $G \\gets [[a, b],[-b,a]]/\\sqrt{a^2+b^2}$\n      \\State $R[i-1:i+1, j:] \\gets GR[i-1:i+1, j:]$\n      \\State $Q[i-1:i+1,:] \\gets GQ[i-1:i+1,:]$\n    \\EndFor\n\\EndFor\n\\State \\pseudoli{return} $Q\\trp , R$\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\nNotice that in Algorithm \\ref{Alg:givens}, we \\emph{do not} actually create the matrices $G(i,j,\\theta)$ and multiply them by the original matrix.\nInstead we modify only those entries of the matrix that are affected by the transformation. As an additional way to save memory, it is possible to modify this algorithm so that $Q$ and $R$ are stored in the original matrix $A$.\n\\begin{comment}\nAn interesting side-note is that each Givens rotation can be represented as a single floating point number, so, when operating in place, $Q$ can be stored entirely in the lower triangular portion of the array on which we are operating by storing each rotation in the entry that it zeroes out.\nA similar approach would to store Householder reflectors in the columns they zero out.\nIn either case, we can represent the QR decomposition of an array using only the memory that was originally used to store the array itself.\nThis is similar to the approach  for computing the LU decomposition entirely in place.\nThese representations of $Q$ and $R$ can be used in various ways to perform matrix multiplication by $Q$, $Q\\trp$ and $R$ as needed.\n\\end{comment}\n\n\n\n\n\n\n\n\\begin{comment}\n\\begin{itemize}[$\\bullet$]\n\n\\item Make $R$ a copy of $A$ and $Q$ an identity array of the appropriate size.\n\n\\item Make an empty $2 \\times 2$ array $G$ that will be used to apply the Givens rotations.\n\n\\item For each column:\n\n  \\begin{itemize}[$\\bullet$]\n\n  \\item For each row below the main diagonal (starting at the bottom of the column):\n\n    \\begin{itemize}[$\\bullet$]\n\n    \\item If the leading entry of this row is not zero (i.e. if its absolute value is within a given tolerance):\n\n      \\begin{itemize}[$\\bullet$]\n\n      \\item Compute $c$ and $s$ using the entry in the current row and column and the entry immediately above it.\n\n      \\item Use $c$ and $s$ to construct the matrix $G$.\n\n      \\item Get a slice of $R$ of the current row and the row above it that includes the columns from the current column onward.\n      Multiply it in place by $G$ to zero out the leading nonzero entry of the current row.\n\n      \\item Get a slice of $Q$ of the current row and the row above it and apply $G$ to it as well. (Strictly speaking, you do not need to operate over these entire rows, but the slicing needed to avoid the extra computation is a little more involved, so we will not include that here.)\n\n      \\end{itemize}\n\n    \\end{itemize}\n\n  \\end{itemize}\n\n\\item Return $Q\\trp$ and $R$.\n\n\\end{itemize}\n\\end{comment}\n\n\n\\begin{problem}\n\\label{prob:Givens}\nWrite a function that computes the Givens triangularization of a matrix, using Algorithm \\ref{Alg:givens}. \nAssume that at the $ij^{th}$ stage of the algorithm, $a_{ij}$ will be nonzero.\n\\end{problem}\n\n\n\\begin{problem}\n\\label{prob:givens_hessenberg}\nModify your solution to Problem \\ref{prob:Givens} to compute the Givens triangularization of an upper Hessenberg matrix, making the following changes:\n\\begin{enumerate}\n\\item Iterate through the first subdiagonal from left to right. (These are the only entries that need to be zeroed out.)\n\\item Line 10 of Algorithm \\ref{Alg:givens} updates $Q$ with the current Givens rotation $G$. Decrease the number of entries of $Q$ that are modified in this line. Do this by replacing $Q[i-1:i+1, :]$ with $Q[i-1:i+1, :k_i]$ where $k_i$ is some appropriately chosen number (dependent on $i$) such that $Q[i-1:i+1, k_i:]=0$.\n\\end{enumerate}\nHint: Here is how to generate a random upper Hessenberg matrix on which to test your function.\nThe idea is to generate a random matrix and then zero out all entries below the first subdiagonal.\n\\begin{lstlisting}\nimport numpy as np\nimport scipy.linalg as la\nfrom math import sqrt\nA = np.random.rand(500, 500)\n\n# We do not need to modify the first row of A\n# la.triu(A[1:]) zeros out all entries below the diagonal of A[1:]\nA[1:] = la.triu(A[1:])\n\n# A is now upper Hessenberg\n\\end{lstlisting}\n\n\\begin{comment}\nWhat is the computational order of  complexity for this problem?\nApproximately for what $m$ is your implementation as fast as the general QR decomposition built in to \\li{scipy.linalg} for computing the QR decomposition of an upper Hessenberg matrix?\n\\end{comment}\n\\end{problem}\n\n\\begin{comment}\n\\begin{problem}\n\\label{prob:givens_hessenberg_modified}\nYou may have noticed that matrix multiplication by $Q$ is generally a $\\mathcal{O} \\left( n^3 \\right)$ algorithm, while the application of these individual Givens rotations is a $\\mathcal{O} \\left( n^2 \\right)$ algorithm.\nWrite a modified version of your solution to Problem \\ref{prob:givens_hessenberg} called \\li{givens2_mod} which returns \nan $(n-1) \\times 2 \\times 2$ array containing the computed values for $G$ at each step in the algorithm in the order in which they are applied to the upper Hessenberg array $H$.\n\nWrite two more functions \\li{apply_Q} and \\li{apply_QT} which, using the matrix of Givens rotations, perform left multiplication \nby $Q$ and $Q^{-1}$, respectively, on some other input array $B$.\nLeft multiplication by $Q^{-1}$ can be done by applying each of the Givens rotations to $B$ the same way you did to $H$ to compute its QR factorization.\nLeft multiplication by $Q$ can be done by applying the transpose of the Givens rotations to their corresponding portions of $B$, but in the reverse order.\nNotice that you will have to apply each Givens rotation across the full width of the rows it operates on since you do not know anything about the content of $B$.\n\nFor around what size of matrices is direct multiplication by $Q$ slower than this method of multiplying by $Q$?\nFor timing purposes, make a random upper Hessenberg matrix, compute its QR decomposition using the function you just wrote and your solution to Problem \\ref{prob:givens_hessenberg}, then time how long it takes to left multiply a random square array by $Q$ using the function you just wrote and the \\li{dot} method of NumPy arrays.\n\nNote: the functions you just wrote can be used to perform right multiplication as well since $B Q = \\left(Q\\trp B\\trp \\right)\\trp$ and $B Q\\trp = \\left( Q B\\trp \\right)\\trp$.\n\\end{problem}\n\\end{comment}\n\n\n\n\\section*{Least Squares}\n\nA linear system $A\\x=\\b$ is \\emph{overdetermined} if it has no solutions. \nIn this situation, the \\emph{least squares solution} is a vector $\\widehat{\\x}$ hat is ``closest'' to a solution. \nBy definition, $\\widehat{\\x}$ is the vector such that $A\\widehat{\\x}$ will equal the projection of $\\b$ onto the range of $A$. \nWe can compute $\\widehat{\\x}$ by solving the \\emph{Normal Equation} $A\\trp A\\widehat{\\x} = A\\trp \\b$ (see [TODO: ref textbook] for a derivation of the Normal Equation).\n\n\n\\subsection*{Solving the normal equation}\nIf $A$ is full rank, we can use its QR decomposition to solve the normal equation. \nIn many applications, $A$ is usually full rank, including when least squares is used to fit curves to data.\n\nLet $A=QR$ be the QR decomposition of $A$, so $R = \\left(\\begin{array}{c}R_0\\\\\n0\\\\ \\end{array} \\right)$\nwhere $R_0$ is $n \\times n$, nonsingular, and upper triangular. \nIt can be shown that $\\widehat{\\x}$ is the least squares solution to $A\\x=\\b$ if and only if $R_0\\widehat{\\x} = (Q\\trp \\b)[:n].$ \nHere, $(Q\\trp \\b)[:n]$ refers to the first $n$ rows of $Q\\trp \\b$.\nSince $R$ is upper triangular, we can solve this equation quickly with back substitution. \n\n\n\\begin{problem}\nWrite a function that accepts a matrix $A$ and a vector $b$ and returns the least squares solution to $Ax=b$.\nUse the QR decomposition as outlined above.\nYour function should use SciPy's functions for QR decomposition and for solving triangular systems, which are \\li{la.qr()} and \\li{la.solve_triangular()}, respectively.\n\\end{problem}\n\n\\subsection*{Using least squares to fit curves to data}\nThe least squares solution can be used to find the curve of a chosen type that best fits a set of points. \n\n\\subsubsection*{Example 1: Fitting a line}\nFor example, suppose we wish to fit a general line $y=mx+b$ to the data set $\\{(x_k, y_k)\\}_{k=1}^n$. \nWhen we plug the constants $(x_k, y_k)$ into the equation $y=mx+b$, we get a system of linear equations in the unknowns $m$ and $b$. \nThis system corresponds to the matrix equation\n\\[\n\\begin{pmatrix}\nx_1 & 1\\\\\nx_2 & 1\\\\\nx_3 & 1\\\\\n\\vdots & \\vdots\\\\\nx_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nm\\\\\nb\n\\end{pmatrix}=\n\\begin{pmatrix}\ny_1\\\\\ny_2\\\\\ny_3\\\\\n\\vdots\\\\\ny_n\n\\end{pmatrix}.\n\\]\nBecause this system has two unknowns, it is guaranteed a solution if it has two or fewer equations. \nIn applications, there will usually be more than two data points, and these will probably not lie in a straight line, due to measurement error. \nThen the system will be overdetermined. \nThe least squares solution to this equation will be a slope $\\widehat{m}$ and $y$-intercept $\\widehat{b}$ that produce a line $y = \\widehat{m}x+\\widehat{b}$ which best fits our data points.\n\n\n\n%DO: spring constant as an example of this\n% circle fit\n% mention in this situation A will usually be full rank.\n%todo: least squares and invertibiility.\n\n\n\n\n\n\n\nLet us do an example with some actual data. Imagine we place different loads on a spring and measure the displacement, recording our results in the table below.\n%TODO: get data points that are not so close to an actual line\n\\begin{table}\n\\begin{tabular}{c|c|c|c|c|c|c|c}\ndisplacement (cm)& 1.04  &2.03  &2.95  &3.92  &5.06  &6.00  &7.07  \\\\ \\hline\nload (dyne) & 3.11&  6.01&  9.07&  11.99 &  15.02&  17.91&  21.12\\\\\n\\end{tabular}\n\\end{table}\n\nHooke's law from physics says that the displacement $x$ should be proportional to the load $F$, or $F = kx$ for some constant $k$.\nThe equation $F=kx$ describes a line with slope $k$ and $F$-intercept 0.\nSo the setup is similar to the setup for the general line we discussed above, except we already know $b=0$\nWhen we plug our seven data points $(x,F)$ pairs into the equation $F=kx$, we get seven linear equations in $k$, corresponding to the matrix equation\n\\[\n\\begin{pmatrix}\n1.04\\\\\n2.03\\\\\n2.95\\\\\n3.92\\\\\n5.06\\\\\n6.00\\\\\n7.07\\\\\n\\end{pmatrix}\n\\begin{pmatrix}k\\end{pmatrix} =\n\\begin{pmatrix}\n3.11 \\\\\n6.01\\\\\n9.07\\\\\n11.99\\\\\n15.02\\\\\n17.91\\\\\n21.12\\\\\n\\end{pmatrix}.\n\\]\nWe expect such a linear system to be overdetermined, and in fact it is: the equation is $1.04k = 3.11$ which implies $k=2.99$, but the second equation is $2.03k = 6.01$ which implies $k=2.96$.\n\nWe can't solve this system, but its least squares solution is a ``best'' choice for $k$.\nWe can find the least squares solution with the SciPy function \\li{linalg.lstlsq()}. \nThis function returns a tuple of several values, the first of which is the least squares solution.\n\\begin{lstlisting}\n>>> A = np.vstack([1.04,2.03,2.95,3.92,5.06,6.00,7.07])\n>>> b = np.vstack([3.11,6.01,9.07,11.99,15.02,17.91,21.12])\n>>> k = la.lstsq(A, b)[0]\n>>> k\narray([[ 2.99568294]])\n\\end{lstlisting}\nHence, to two decimal places, $k = 3.00$.\nWe plot the data against the best-fit line with the following code, whose output is in Figure \\ref{fig:spring_fit}\n\n\n\\begin{lstlisting}\n>>> from matplotlib import pyplot as plt\n>>> x0 = np.linspace(0,8,100)\n>>> y0 = k[0]*x0\n>>> plt.plot(A,b,'*',x0,y0)\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{line_lstsq}\n\\caption{The graph of the spring data together with its linear fit.}\n\\label{fig:spring_fit}\n\\end{figure}\n\n%TODO: find more interesting data and make a sample plot\n\\begin{problem}\nLoad the \\li{linepts} array from the file \\texttt{data.npz}. The following code stores this array as \\li{linepts}.\n\\begin{lstlisting}\nlinepts = np.load('data.npz')['linepts']\n\\end{lstlisting}\nThe \\li{linepts} array has two columns corresponding to the $x$ and $y$ coordinates of some data points.\n\\begin{enumerate}\n\\item Use least squares to fit the line $y=mx+b$ to the data.\n\\item Plot the data and your line on the same graph.\n\\end{enumerate}\n\\end{problem}\n\n\n\n\n\n\n%\n%\\section*{General Line Fitting}\n%\n%Suppose that we wish to fit a general line, that is $y=m x+b$, to the data set\n%$\\{(x_k,y_k)\\}^n_{k=1}$.  Assume that the line does not cross through the origin,\n%as in the previous example.  Then we seek both a slope and a $y$-intercept.\n%In this case, we set up the following linear system $A x = b$, or more precisely\n%\\[\n%\\begin{pmatrix}\n%x_1 & 1\\\\\n%x_2 & 1\\\\\n%x_3 & 1\\\\\n%\\vdots & \\vdots\\\\\n%x_n & 1\n%\\end{pmatrix}\n%\\begin{pmatrix}\n%m\\\\\n%b\n%\\end{pmatrix}=\n%\\begin{pmatrix}\n%y_1\\\\\n%y_2\\\\\n%y_3\\\\\n%\\vdots\\\\\n%y_n\n%\\end{pmatrix}.\n%\\]\n%Note that $A$ has rank $2$ as long as not all of the $x_k$ values are the same.\n%Hence, the least squares solution\n%is given by\n%$$\n%\\widehat{x} = (A^HA)^{-1}A^Hb.\n%$$\n%In what sense does this solution give us the best fit line for the data? Recall that since $A$ is injective,\n%the matrix $A(A^HA)^{-1}A^H$ is an orthogonal projector onto the range of $A$, which means that\n%$A(A^HA)^{-1}A^Hb = A\\widehat{x}$ is the closest vector (with respect to the 2-norm) to $b$ that lies in the\n%range of $A$. That is, $\\widehat{x}$ minimizes the error between $Ax$ and $b$, where the error is given\n%by the distance between these vectors, $\\|b-Ax\\|_2$. Another way to say this is that $\\widehat{x}$ gives the\n%values $m$ and $b$ for which the sum of the squares of the distances from each data point $y_k$ to the value\n%$y = mx_k + b$ is as small as possible.\n\n\n\\subsubsection*{Example 2: Fitting a circle}\nNow suppose we wish to fit a general circle to a data set $\\{(x_k, y_k)\\}_{k=1}^n$. Recall that the equation of a circle with radius $r$ and center $(c_1,c_2)$ is\n\\begin{equation}\n\\label{circle}\n(x-c_1)^2 + (y-c_2)^2 = r^2.\n\\end{equation}\nWhat happens when we plug a data point into this equation? Suppose $(x_k, y_k)=(1,2)$.\n\\footnote{You don't have to plug in a point for this derivation, but it helps us remember which symbols are constants and which are variables.} Then\n\\begin{equation*}\\label{equ:example}\n5 = 2c_1+4c_2+(r^2-c_1^2-c_2^2).\n\\end{equation*}\nTo find $c_1$, $c_2$, and $r$ with least squares, we need \\emph{linear} equations. \nThen Equation \\ref{equ:example} above is not linear because of the $r^2$, $c_1^2$, and $c_2^2$ terms. \nWe can do a trick to make this equation linear: create a new variable $c_3$ defined by $c_3 = r^2-c_1^2-c_2^2$. \nThen Equation \\ref{equ:example} becomes\n\\[\n5=2c_1+4c_2+c_3,\n\\]\nwhich \\emph{is} linear in $c_1$, $c_2$, and $c_3$. Since $r^2 = c_3+c_1^2+c_2^2$, after solving for the new variable $c_3$ we can also find $r$.\n\nFor a general data point $(x_k, y_k)$, we get the linear equation\n\\[\n2c_1x_k+2c_2y_k+c_3=x_k^2+y_k^2.\n\\]\nThus, we can find the best-fit circle from the least squares solution to the matrix equation\n\n\\begin{equation}\\label{equ:circle_fit}\n\\begin{pmatrix}\n2 x_1 & 2 y_1 & 1\\\\\n2 x_2 & 2 y_2 & 1\\\\\n\\vdots & \\vdots & \\vdots \\\\\n2 x_n & 2 y_n & 1\n\\end{pmatrix}\n\\begin{pmatrix}\nc_1\\\\\nc_2\\\\\nc_3\n\\end{pmatrix}=\n\\begin{pmatrix}\nx_1^2 + y_1^2\\\\\nx_2^2 + y_2^2\\\\\n\\vdots\\\\\nx_n^2 + y_n^2\n\\end{pmatrix}.\n\\end{equation}\nIf the least squares solution is $\\widehat{c_1}, \\widehat{c_2}$, $\\widehat{c_3}$, then the best-fit circle is\n\\[\n(x-\\widehat{c_1})^2 + (y-\\widehat{c_2})^2 = \\widehat{c_3}+\\widehat{c_1}^2+\\widehat{c_2}^2.\n\\]\n\n\nLet us use least squares to find the circle that best fits the following nine points:\n%TODO: get data points that are not so close to an actual circle\n\\begin{table}\n\\begin{tabular}{c||c|c|c|c|c|c|c|c|c}\n$x$& 134  &104 &34  &-36  &-66  &-36  &34 &104 &  134  \\\\ \\hline\n$y$& 76&  146&  176&  146 &  76&  5& -24 & 5 & 76\\\\\n\\end{tabular}\n\\end{table}\n\n\nWe enter them into Python as a $9\\times 2$ array.\n\\begin{lstlisting}\n>>> P = np.array([[134,76],[104,146],[34,176],[-36,146],\n                  [-66,76],[-36,5],[34,-24],[104,5],[134,76]])\n\\end{lstlisting}\n\nWe compute $A$ and $b$ according to Equation \\ref{equ:circle_fit}.\n\\begin{lstlisting}\n>>> A = np.hstack((2*P, np.ones((9,1))))\n>>> b = (P**2).sum(axis=1)\n\\end{lstlisting}\n\nThen we use SciPy to find the least squares solution.\n\\begin{lstlisting}\n>>> c1, c2, c3 = la.lstsq(A, b)[0]\n\\end{lstlisting}\n\nWe can solve for $r$ using the relation $r^2 = c_3+c_1^2+c_2^2$.\n\\begin{lstlisting}\n>>> r = sqrt(c1**2 + c2**2 + c3)\n\\end{lstlisting}\n\nA good way to plot a circle is to use polar coordinates. \nUsing the same variables as before, the equation for a general circle is $x=r\\cos(\\theta)+c_1$ and $y=r\\sin(\\theta)+c_2$. \nWith the following code we plot the data points and our best-fit circle using polar coordinates. \nThe resulting image is Figure \\ref{fig:circle}.\n\\begin{lstlisting}\n# In the polar equations for a circle, theta goes from 0 to 2*pi.\n>>> theta = np.linspace(0,2*np.pi,200)\n>>> plt.plot(r*np.cos(theta)+c1,r*np.sin(theta)+c2,'-',P[:,0],P[:,1],'*')\n>>> plt.show()\n\\end{lstlisting}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{circle.pdf}\n\\caption{The graph of the some data and its best-fit circle.}\n\\label{fig:circle}\n\\end{figure}\n\n\\begin{comment}\n\\begin{problem}\nWrite a function \\li{fitCircle} that does the following.\nLoad the \\texttt{circlepts} array from \\texttt{data.npz}.\nThis consists of two columns corresponding to the $x$ and $y$ values of a given\ndata set.  Use least squares to find the center and radius of the circle that best\nfits the data.  Then plot the data points and the circle on the same graph.\nThe function should return nothing.\n\\end{problem}\n\\end{comment}\n\n%TODO: figure out how to plot this problem\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Load the \\texttt{ellipsepts} array from \\texttt{data.npz}. This array has two columns corresponding to the $x$ and $y$ coordinates of some data points.\n\\item Use least squares to fit an ellipse to the data. \nThe general equation for an ellipse is\n\\[\nax^2 + bx + cxy + dy + ey^2 = 1.\n\\]\nYou should get  $0.087$, $-0.141$,  $0.159$, $-0.316$, $0.366$ for $a, b, c, d,$ and $e$ respectively.\n%\\item Plot the data and your line on the same graph.\n\\end{enumerate}\n\\end{problem}\n\n%TODO: keep this?\n\\begin{comment}\nIn these Least Squares problems, we have found best fit lines and ellipses relative to the 2-norm.\nIt is possible to generalize the idea of best fit curves relative to other norms.\nSee Figure \\ref{Fig:ellipse} for an illustration of this.\n\n\\begin{figure}[h]\n\\label{ellipsefit}\n\\centering\n\\includegraphics[width=\\textwidth]{ellipsefit.pdf}\n\\caption{Fitting an ellipse using different norms.}\n\\label{Fig:ellipse}\n\\end{figure} \n\\end{comment}\n\n\\begin{comment}\n\\section*{Loading Data from .npz Files}\nFor Least Squares problems as well as in many other contexts, loading data is often a necessary step before\nproceeding with further analysis. Here we briefly review another data format in Python and the commands used\nto load the data.\n\nA \\li{.npz} file is a compressed binary file that contains an archive of NumPy data structures.\nA given file may therefore contain several arrays, each array associated with a unique string that identifies it.\nWhen you load a \\li{.npz} file in Python, a dictionary-like object is returned, and you can access the data by\nproviding the appropriate key. Note that when you load a \\li{.npz} file, you must also be sure to close it when\nyou are finished. This is taken care of automatically if you use the \\li{with ... as} keywords.\n\nAs an example, suppose that we have a file named \\li{grades.npz} that contains several arrays, each giving the\nhomework scores of a particular student in a particular class. Assuming that one of the arrays is associated with\nthe key \\li{'Abe'}, we can load this array in the following way:\n\n\\begin{lstlisting}\n>>> with np.load('grades.npz') as grades:\n>>>     abe_grades = grades['Abe']\n>>> abe_grades\narray([ 10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.,  10.])\n\\end{lstlisting}\n\nYou will need to apply this technique in the next problem.\n\n\\end{comment}\n", "meta": {"hexsha": "2a9661e5c01c3f96fe6e569548ed4392d93d771b", "size": 27870, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/GivensRotations/Givens.tex", "max_stars_repo_name": "marissa-graham/numerical_computing", "max_stars_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 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/GivensRotations/Givens.tex", "max_issues_repo_name": "marissa-graham/numerical_computing", "max_issues_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Labs/GivensRotations/Givens.tex", "max_forks_repo_name": "marissa-graham/numerical_computing", "max_forks_repo_head_hexsha": "25536d917ffac1abbb637b10c3bc8c9001f68ca8", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.9728915663, "max_line_length": 366, "alphanum_fraction": 0.7021528525, "num_tokens": 8937, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583696, "lm_q2_score": 0.8918110389681662, "lm_q1q2_score": 0.7580136840346482}}
{"text": "\\subsubsection{The Cholesky factorization}\n\nAnother important theorem is the existence of a specific factorization of positive definite matrices. It is called the Cholesky Factorization and factors the matrix into the product of an upper triangular matrix and its transpose.\n\n\\index{Cholesky factorization!positive definite}\n\\index{positive definite!Cholesky factorization}\n\\begin{theorem}{Cholesky factorization}{cholesky-factorization}\nLet $A$ be a positive definite matrix. Then\nthere exists an upper triangular matrix $U$ whose main diagonal entries are positive, such that $A$ can be written\n\n\\begin{equation*}\nA=\nU^TU\n\\end{equation*}\nThis factorization is unique.\n\\end{theorem}\n\nThe process for finding such a matrix $U$ relies on simple row operations.\n\n\\begin{procedure}{Finding the Cholesky factorization}{finding-cholesky}\nLet $A$ be a positive definite matrix. The matrix $U$ that creates the Cholesky Factorization can be found through two steps.\n\\begin{enumerate}\n\\item Using only type $3$ elementary row operations (multiples of rows added to other rows) put $A$ in upper triangular form. Call this matrix $\\hat{U}$. Then $\\hat{U}$ has positive entries on the main diagonal.\n\\item Divide each row of $\\hat{U}$ by the square root of the diagonal entry in that row. The result is the matrix $U$.\n\\end{enumerate}\n\\end{procedure}\n\nOf course you can always verify that your factorization is correct by multiplying $U$ and $U^T$ to ensure the result is the original matrix $A$.\n\nConsider the following example.\n\n\\begin{example}{Cholesky factorization}{cholesky}\nShow that\n$A=\\begin{mymatrix}{rrr}\n9 & -6 & 3 \\\\ -6 & 5 & -3 \\\\ 3 & -3 & 6\n\\end{mymatrix}$\nis positive definite, and find the Cholesky factorization of $A$.\n\\end{example}\n\n\\begin{solution}\nFirst we show that $A$ is positive definite. By Theorem~\\ref{thm:positive-matrix-determinant-Ak} it suffices to show that the determinant of each submatrix is positive.\n\\[ A_{1}=\\begin{mymatrix}{c} 9 \\end{mymatrix}\n\\mbox{ and }\nA_{2}=\\begin{mymatrix}{rr} 9 & -6 \\\\ -6 & 5 \\end{mymatrix},\\]\nso $\\det(A_{1})=9$ and $\\det(A_{2})=9$.\nSince $\\det(A)=36$, it follows that $A$ is positive definite.\n\nNow we use Procedure~\\ref{proc:finding-cholesky} to find the Cholesky Factorization. Row reduce (using only type $3$ row operations) until an upper triangular matrix is obtained.\n\\[ \\begin{mymatrix}{rrr}\n9 & -6 & 3 \\\\ -6 & 5 & -3 \\\\ 3 & -3 & 6\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr}\n9 & -6 & 3 \\\\ 0 & 1 & -1 \\\\ 0 & -1 & 5\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{rrr}\n9 & -6 & 3 \\\\ 0 & 1 & -1 \\\\ 0 & 0 & 4\n\\end{mymatrix}\n\\]\n\nNow divide the entries in each row by the square root of the diagonal\nentry in that row, to give\n\n\\[ U=\\begin{mymatrix}{rrr}\n3 & -2 & 1 \\\\ 0 & 1 & -1 \\\\ 0 & 0 & 2\n\\end{mymatrix}\n\\]\n\nYou can verify that $U^TU = A$.\n\\end{solution}\n\n\\begin{example}{Cholesky factorization}{cholesky}\nLet $A$ be a positive definite matrix given by\n\\begin{equation*}\n\\begin{mymatrix}{ccc}\n3 & 1 & 1 \\\\\n1 & 4 & 2 \\\\\n1 & 2 & 5\n\\end{mymatrix}\n\\end{equation*}\nDetermine its Cholesky factorization.\n\\end{example}\n\n\\begin{solution}\nYou can verify that $A$ is in fact positive definite.\n\nTo find the Cholesky factorization we first row reduce to an upper triangular matrix.\n\\[\n\\begin{mymatrix}{ccc}\n3 & 1 & 1 \\\\\n1 & 4 & 2 \\\\\n1 & 2 & 5\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{ccc}\n3 & 1 & 1 \\\\\n0 & \\vspace{0.05in}\\frac{11}{3} & \\vspace{0.05in}\\frac{5}{3} \\\\\n0 & \\vspace{0.05in}\\frac{5}{3}  & \\vspace{0.05in}\\frac{14}{5}\n\\end{mymatrix}\n\\rightarrow\n\\begin{mymatrix}{ccc}\n3 & 1 & 1 \\\\\n0 & \\vspace{0.05in}\\frac{11}{3} & \\vspace{0.05in}\\frac{5}{3} \\\\\n0 & 0 & \\vspace{0.05in}\\frac{43}{11}\n\\end{mymatrix}\n\\]\n\nNow divide the entries in each row by the square root of the diagonal entry in that row and simplify.\n\\[\nU = \\begin{mymatrix}{ccc}\n\\sqrt{3} & \\vspace{0.05in}\\frac{1}{3}\\sqrt{3} & \\vspace{0.05in}\\frac{1}{3}\\sqrt{3}  \\\\\n0  & \\vspace{0.05in}\\frac{1}{3}\\sqrt{3}\\sqrt{11} &  \\vspace{0.05in}\\frac{5}{33}\\sqrt{3}\\sqrt{11} \\\\\n\n0  & 0 & \\vspace{0.05in}\\frac{1}{11}\\sqrt{11}\\sqrt{43}\n\\end{mymatrix}\n\\]\n\\end{solution}", "meta": {"hexsha": "ab49df297eeb17fa18f62bd589e89dae9ab0fc5d", "size": 4072, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/spectraltheoryOrthogonalityPositiveDefiniteCholesky.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/spectraltheoryOrthogonalityPositiveDefiniteCholesky.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/spectraltheoryOrthogonalityPositiveDefiniteCholesky.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 34.5084745763, "max_line_length": 230, "alphanum_fraction": 0.6989194499, "num_tokens": 1400, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.849971175657575, "lm_q2_score": 0.8918110396870288, "lm_q1q2_score": 0.7580136778671881}}
{"text": "\\subsection{The Absolute Value}\r\n\r\n\\begin{definition}{Absolute Value}{Absolute Value}\r\n\t\\label{def:AbsoluteValue}\r\nThe \\dfont{absolute value} of a number $x$ is written as $|x|$ and represents \r\nthe \\ifont{distance} $x$ is from zero. Mathematically, we define it as follows:\r\n$$|x|=\\left\\{\\begin{array}{cl}\r\nx, & \\mbox{if $x\\geq 0$,}\\\\\r\n-x, & \\mbox{if $x<0$.}\\\\\r\n\\end{array}\\right.$$\r\n\\end{definition}\r\n\r\nThus, if $x$ is a negative real number, then $-x$ is a positive real number.\r\nThe absolute value does \\ifont{not} just turn minuses into pluses.\r\nThat is, $|2x-1|\\neq 2x+1$.\r\nYou should be familiar with the following properties.\\\\\r\n\r\n\\begin{formulabox}[Absolute Value Properties]\r\n\\begin{enumerate}\r\n\t\\item $|x|\\geq 0$.\r\n\t\\item $|xy|=|x||y|$.\r\n\t\\item $\\displaystyle{\\left|\\frac{1}{x} \\right|=\\frac{1}{|x|} }$ \\hspace{2mm} when $x\\neq 0$.\r\n\t\\item $|-x|=|x|$.\r\n\t\\item $|x+y|\\leq |x|+|y|$. This is called the \\dfont{triangle inequality}.\r\n\t\\item $\\sqrt{x^2}=|x|$.\r\n\\end{enumerate}\r\n\\end{formulabox}\r\n\r\n\\begin{example}{$\\sqrt{x^2}=|x|$}{sqrtabs}\r\nObserve that $\\sqrt{(-3)^2}$ gives an answer of $3$, not $-3$.\r\n\\end{example}\r\n\r\nWhen solving inequalities with absolute values, the following are helpful. %(here $a>0$ is a positive number):\r\n%\\begin{itemize}\r\n%\t\\item $|x|=a$ means $x=\\pm a$.\r\n%\t\\item $|x|\\leq a$ means $x\\geq -a$ \\ifont{and} $x\\leq a$  (that is, $-a\\leq x\\leq a$).\r\n%\t\\item $|x|\\geq a$ means $x\\leq -a$ \\ifont{or} $x\\geq a$.\r\n%\\end{itemize}\r\n%\r\n%In the above, we do require $a>0$, otherwise we end up with false expressions.\r\n%For example, $|x|=-1$ has no solutions because $|x|$ is always positive (or zero), \r\n%so it will never equal $-1$. On the other hand, $|x|=1$ has the solutions $x=\\pm 1$.\r\n \r\n\\medskip\r\n{\\bf Case 1: $a>0$.}\\vspace{-0.1cm}\r\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\r\n\\item $|x|=a$ has solutions $x=\\pm a$. \r\n\\item $|x|\\leq a$ means $x\\geq -a$ {\\bf and} $x\\leq a$  (that is, $-a\\leq x\\leq a$). \r\n\\item $|x|<a$ means $x< -a$ {\\bf and} $x< a$  (that is, $-a< x< a$). \r\n\\item $|x|\\geq a$ means $x\\leq -a$ {\\bf or} $x\\geq a$. \r\n\\item $|x|> a$ means $x< -a$ {\\bf or} $x> a$. \r\n\\end{itemize}\r\n\r\n{\\bf Case 2: $a<0$.}\\vspace{-0.1cm}\r\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\r\n\\item $|x|=a$ has no solutions. \r\n\\item Both $|x|\\leq a$ and $|x|<a$ have no solutions. \r\n\\item Both $|x|\\geq a$ and $|x|>a$ have solution set $\\{x|x\\in\\R\\}$. \r\n\\end{itemize}\r\n\r\n{\\bf Case 3: $a=0$.}\\vspace{-0.1cm}\r\n\\begin{itemize}\\setlength{\\itemsep}{0 in}\r\n\\item $|x|=0$ has solution $x=0$. \r\n\\item $|x|<0$ has no solutions. \r\n\\item $|x|\\leq 0$ has solution $x=0$. \r\n\\item $|x|>0$ has solution set $\\{x\\in\\R|x\\neq 0\\}$. \r\n\\item $|x|\\geq 0$ has solution set $\\{x|x\\in\\R\\}$.\r\n\\end{itemize}", "meta": {"hexsha": "c7411bb240a5ca9f845e9b815c118aad5843d504", "size": 2698, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-5-absolute-value.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-5-absolute-value.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-5-absolute-value.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.6764705882, "max_line_length": 111, "alphanum_fraction": 0.6045218681, "num_tokens": 1091, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9219218434359676, "lm_q2_score": 0.8221891239865619, "lm_q1q2_score": 0.7579941128386944}}
{"text": "\\section{Dirichlet eigenvalues and eigenfunctions on the annulus \\label{sec:annul_dir_exact}}\nIn this section, we compute some of the Dirichlet eigenvalues\ncorresponding to a subset of the radially symmetric eigenfunctions\non the annulus. \nIn polar coordinates $(r,\\theta)$, consider the annulus defined by \n$R_{1}<r<R_{2}$. \nSuppose that $\\bu$ is of the form \n\\begin{equation}\n\\bu = \\nabla^{\\perp}\\left( \\alpha H_{0}(kr) + \\beta J_{0}(kr) \\right) \\, ,\n\\label{eq:annulus_direig}\n\\end{equation}\nand $p=0$.\n\nClearly, this pair satisfies the osciallatory Stokes equation\nwith parameter $k$, since $J_{0}(kr)$ and $H_{0}(kr)$ \nsatisfy the Helmholtz equation on the annulus.\n\nLet $\\hat{r},\\hat{\\theta}$ denote the unit vectors in polar coordinates.\nA simple calculation shows that \n\\begin{equation}\n\\begin{aligned}\nu_{r} &= \\bu \\cdot \\hat{r}  = 0 \\, \\\\\nu_{\\theta} &= \\bu \\cdot \\hat{\\theta} = k(\\alpha  H_{0}'(kr) + \\beta J_{0}'(kr)) \\, .\n\\end{aligned}\n\\end{equation}\n\nThis in particular implies that on $r=R_{1}$,\n$u_{\\theta}$ takes on the constant value,\n$k(\\alpha H_{0}'(kR_{1}) + \\beta J_{0}'(kR_{1}))$.\nSimilarly, on $r=R_{2}$, \n$u_{\\theta}$ takes on the constant value,\n$k(\\alpha H_{0}'(kR_{2}) + \\beta J_{0}'(kR_{2}))$.\n\nThus, if $k$ satisfies, \n\\begin{equation}\nH_{0}'(kR_{1}) J_{0}'(kR_{2}) - H_{0}'(kR_{2})J_{0}'(kR_{1}) = 0 \\, ,\n\\end{equation}\nand for those values of $k$ if \n$\\alpha,\\beta$ are non-zero solutions to system of equations \n\\begin{equation}\n\\begin{bmatrix}\nH_{0}'(kR_1) & J_{0}'(kR_{1}) \\\\\nH_{0}'(kR_{2}) & J_{0}'(kR_{2}) \n\\end{bmatrix}\n\\begin{bmatrix}\n\\alpha \\\\\n\\beta\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n0 \\\\\n0\n\\end{bmatrix}\n\\, ,\n\\end{equation}\nthen $k$ is a Dirichlet eigenvalue and $\\bu$ \ndefined by~\\cref{eq:annulus_direig}\nis the corresponding eigenfunction.\n\n\\section{Neumann eigenvalues and eigenfunctions on the unit disk}\nIn this section, we derive an analytical expression which\ncan be used to compute some of the radially symmetric \nNeumann eigenvalues on the unit disk for the Stokes operator.\n\nSuppose that $\\bu$ is of the form\n\\begin{equation}\n\\bu = \\nabla^{\\perp} \\jkr \\, ,\n\\end{equation}\nand the pressure is given by $p=0$, as\n$\\bu$ satisfies $(\\Delta + k^2)\\bu = 0$.\n\nThen, the surface traction $\\bt$ on the disk of radius $r$ \nis given by\n\\begin{equation}\n\\bt = \n\\left( -\\frac{k}{r^2}\\jpkr  + \\frac{k^2}{r} \\jppkr\\right)\n\\begin{bmatrix}\n\\sint \\\\\n-\\cost\n\\end{bmatrix} \\, .\n\\end{equation}\n\nThus, $k$ which satisfies\n\\begin{equation}\n  \\label{eq:neu_roots}\n-k \\jpk + k^2 \\jppk = 0 \\, ,\n\\end{equation}\nare Neumann eigenvalues on the unit disk.\nThe first $4$ roots of the \\cref{eq:neu_roots} are\nin \\cref{tab:neu_roots}.\n\\begin{table}\n  \\centering\n  \\begin{tabular}{c}\n    k  \\\\ \\hline\n    5.135622301840683 \\\\\n    8.417244140399865 \\\\\n    11.61984117214906 \\\\\n    14.79595178235126 \n  \\end{tabular}\n  \\caption{Roots of \\cref{eq:neu_roots}.}\n  \\label{tab:neu_roots}\n\\end{table}\n\n", "meta": {"hexsha": "2b328900a090aae955dd7c3cb09e576139c7ef30", "size": 2907, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/draft-01-stokes/appendix.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/appendix.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/appendix.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": 27.9519230769, "max_line_length": 93, "alphanum_fraction": 0.6752665979, "num_tokens": 1075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314798554444, "lm_q2_score": 0.855851143290548, "lm_q1q2_score": 0.7579687145683821}}
{"text": "\\lab{Algorithm}{Line Sweep}{Line Sweep}\n\\label{lab:Alg_Linesweep}\n\n\\objective{Learn about and implement a basic line sweep algorithm}\n\n\\section*{General Line Sweep Algorithms}\n\nLine sweep algorithms are a significant group of algorithms with a variety of applications. \nIn the strictest sense, line sweep algorithms typically use a priority queue and binary tree to lower the temporal complexity associated with certain tasks. \nSome notable examples include Fortune's Algorithm for calculating Voronoi diagrams and Andrew's Algorithm for computing the convex hull of a set of points. \nIn this lab, we will explore a basic line sweep algorithm that allows efficient computation of the Closest Pair problem.  \nGiven a set of points, find the distance between the closest pair of points.\n\n\\section*{Na\\\"ive Implementation}\n\nThe obvious way of doing this is to simply compute the distance between each point and each of the other points.\nRoughly speaking, this requires some constant multiple of $n^2$ computations where $n$ is the number of points.\nThis can be coded as follows:\n\\begin{lstlisting}\ndef reallybadmindist(X):\n    r = ((X[0]-X[1])**2).sum()**.5\n    for i in range(len(X)):\n        for j in range(len(X)):\n            if i != j:\n                r = min(r,((X[i]-X[j])**2).sum()**.5)\n    return r\n\\end{lstlisting}\nSince distance is symmetrical, we can compare each point with the points that follow it in the list we are given (which will reduce\nthe total number of distances to be computed).\nThis is a slightly better implementation:\n\\begin{lstlisting}\ndef multidist(p0,p1):\n    l=len(p0)\n    return sum([(p0[i]-p1[i])**2 for i in range(l)])**.5\ndef badmindist(X):\n    l=len(X)\n    r=multidist(X[0],X[1])\n    for i in xrange(l):\n        for j in xrange(i+1,l):\n            d=multidist(X[i],X[j])\n            if d<r:\n                r=d\n    return r\n\\end{lstlisting}\n\nSince, on average, we iterate through about half of the list for each point added, this algorithm will have complexity $O(n^2)$ (we are only scaling by a constant factor).  \nIt is faster than the truly na\\\"ive method, but essentially just as inefficient.\nFor very small numbers of points, this algorithm works, but it quickly becomes inefficient as we increase the number of points processed.  \nWhat we would like to do is go from $O(n^2)$ to something better.  \nTo do this, we have to think about the problem differently.\nThis can be done by using one of the key techniques of computational geometry-a line sweep algorithm.\n\n\\section*{A Simplified Line Sweep Algorithm}\n\nThe concept behind a line sweep algorithm is breaking a global problem into a sequence of smaller problems that can be solved locally.\nWe sweep the domain space with a line.\nThis line divides the domain space into an explored region and an unexplored region.\nAs the line sweeps, events occur, be it whether the line encounters a point in the data set\nor some other type of event.  \nWe compute the solution at the very beginning of the line sweep and as new events happen, we compute the change that these events have on our current solution.\nWe only need to consider the events in the explored region or on the sweep line as they are the only events that affect the current solution.  \nSweep line algorithms typically exhibit a temporal complexity of $O(n \\log n)$, which is far better than $O(n^2)$.\n\nLine sweep algorithms are good for doing all sorts of proximity based computations.\nIn the example above, we took advantage of the fact that distance was symmetric ($d(a,b)=d(b,a)$).\nIn a line sweep version of this algorithm, we also take advantage of the fact that any points further than the current smallest minimum distance along a given axis do not need to be considered.\nThis is really just an application of the triangle inequality.\nThe secret to the line sweep solution for the closest pair problem is to actually have two sweep lines with a small distance between them.\nAs we process the points in our list, we can decrease the distance between the lines so that we only process points that could possibly give a smaller distance than the smallest distance we have already encountered.\nBy only processing the points between our two sweep lines, we avoid processing many points needlessly.\n\nFor a general line sweep algorithm, it is common to use a priority queue to order the items that need to be processed.\nA good priority queue can be found in the library \\li{Queue} that is included in Python. \nIn this case all we need to do is sort the points by $X$ value.\nThis means it will be easier to make a sorted copy of the array using Numpy's built in functions.\nSomething like \\li{X=Y.take(Y[:,0].argsort(),axis=0)} or \\li{Y[Y[:,0].argsort()]} will do this for you. \n\nWe track the points in the area between the two sweep lines with a list.\nEach time we advance the sweep lines, we update this list so it always contains the points between the sweep lines (adding or removing points where necessary).\nA point stays in the list if its distance from the leading sweep line is less than the current minimum distance.\nConceptually, this is how we place the second sweep line.\n\nAssuming we have already ordered all our points by $x$ coordinate, we can perform the line sweep algorithm as follows:\n\n\\vspace{5mm}\n\\begin{compactenum}[1.]\n\\item \nProcess the first two points and add them to the active list.\nSet current minimum distance to the distance between these two points.\n\\item \nGet the next point in the priority queue.\n\\item \nUpdate the active list so that it contains only the points between the two sweep lines.\n\\item \nCompute the distance between the current point and all the points in the active list.\n\\item \nCompare the smallest distance found with the current minimum distance. \nChange the current minimum distance if needed.\n\\item \nRepeat steps 2 to 5 for all remaining points in the priority queue\n\\end{compactenum}\n\\vspace{5mm}\n\nWhen the algorithm ends, the current minimum distance will be the distance between the closest pair of points.\n\nThis algorithm can be illustrated as follows:\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple0.pdf}\n\\caption{After processing the first two points, we process the third point and change the current minimum distance accordingly.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple1.pdf}\n\\caption{This change in the minimum thus far is reflected in how we form the actives list for the next point we process. \nWe remove the points from the top of the queue that are too far away in the $x$ direction to have a distance less than the current minimum. \nWe then process anything that is left.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple5.pdf}\n\\caption{A few points further in we actually hit the minimum distance.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{simple7.pdf}\n\\caption{After iterating over all the points in the set, we have the final minimum distance desired.}\n\\end{figure}\n\n\\begin{problem}\nWrite a Python function that implements the above algorithm.\nHave your code accept a metric function as a parameter.\nThis metric function should take a point and an array of points as arguments and return an array of distances from the point to each of the points in the array. \nTest your function's speed. \nHow does it scale as you increase the number of points? \nHow does it scale as you increase the number of dimensions?\n\\end{problem}\n\n\\section*{A Line Sweep Algorithm}\n\nYou may have noticed that we are not exploiting all the symmetry of the problem in the previous algorithm. \nIt would likely speed things up if we could also slice away the points that have $y$ values that could not possibly yield the minimum distance. \nThe simplest way to do this in this case is to take advantage of some algebraic symmetry.\nAs we compute the distance between two points, we have to calculate the difference between each of the coordinates of the points in question. \nIf at any time the difference has an absolute value greater than the minimum distance we have encountered thus far, we know we don't need to finish processing the point.\nThis is, theoretically, like slicing along the other axes in order to further reduce the ``active'' list of points.\nA similar result could be obtained by using a list, binary tree, or some other data structure to keep the list of active points sorted by $y$ value, but in this case the insertion and deletion operations involved are more costly.\n\nThis algorithm can be illustrated as follows:\n\nNote: in this case we sweep along the $x$ axis from right to left.\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep0.pdf}\n\\caption{In processing the first point, we find find that we must reduce the radius.\nNotice that we only need to consider the points that lie in the box formed by the red an blue lines.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep13.pdf}\n\\caption{This is where we actually hit the minimum distance.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\includegraphics[width = .8\\textwidth]{sweep22.pdf}\n\\caption{After processing through all the points, we are guaranteed to have hit the minimum distance already, so our minimum distance thus far is our final return value.}\n\\end{figure}\n\nSince this version of the algorithm depends so heavily on array lookups, it will be much faster if it is implemented in Cython.\n\n\\begin{problem}\nImplement the algorithm above in Cython. \nTime it against the naive implementation at the beginning of this lab and against the simplified version you coded above.\nThe new version should be faster, but speed depends heavily on how you have implemented it, so you may have some optimization left to do.\nTime how long it takes your new function to process ten million points in two dimensions. \nUsing benchmarks from the first implementation we gave you, estimate how long (in years) it would take that function to process that many points.\nHow many times faster is the good implementation?\n\\end{problem}\n", "meta": {"hexsha": "7d516302e778e1e7ba676fb9f8178a5b6c48e357", "size": 10025, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/linesweep/linesweep.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/linesweep/linesweep.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/linesweep/linesweep.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.3202247191, "max_line_length": 229, "alphanum_fraction": 0.7704738155, "num_tokens": 2263, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511579973931, "lm_q2_score": 0.8856314617436728, "lm_q1q2_score": 0.7579687120922463}}
{"text": "\n\\subsection{Multivariate Adaptive Regression Splines (MARS)}\n\nA linear model looks like:\n\n\\(\\hat y =c+\\sum_i x_i\\theta_i\\)\n\nMARS instead produces a linear model for subsets of X.\n\n\\(\\hat y =c+\\sum_i B_j(x_i,a_j)\\theta_i\\)\n\nWhere:\n\n\\begin{itemize}\n\\item \\(B_j=max(0, x_i-a_j)\\); or\n\\item \\(B_j=-max(0, a_j-x_i)\\)\n\\end{itemize}\n\nThis is trained using a forward pass and a backward pass.\n\n\\subsubsection{Forward pass}\n\n\\subsubsection{Backward pass}\n\n", "meta": {"hexsha": "d7e04c621cbfcda9156694c386f40ad5cdf29df5", "size": 448, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/MLregression/02-01-MARS.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/MLregression/02-01-MARS.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/MLregression/02-01-MARS.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.92, "max_line_length": 60, "alphanum_fraction": 0.7142857143, "num_tokens": 142, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9465966717067253, "lm_q2_score": 0.800691997339971, "lm_q1q2_score": 0.7579323797442267}}
{"text": "\\section{Types of Transformations}\n\n% Similarity\n\\subsection{Similarity Transformations}\n\\label{sec:similaritytrans}\n\nIf $\\mathbf{T}$ is a nonsingular matrix, then a similarity transformation is defined as:\n\n\\begin{equation}\n\\mathbf{A} = \\mathbf{TBT^{-1}}\n\\end{equation}\n\nAnd $\\mathbf{A}$ and $\\mathbf{B}$ are said to be \\textit{similar}.\n\n% Affine \n\\subsection{Affine Transformations}\n\\label{sec:affine}\n\nAffine transformations are the combination of a linear map and a translation, which has the form $f(\\mathbf{x}) = \\mathbf{A}\\mathbf{x} + \\mathbf{b}$. \n\n\\begin{equation}\nf: V \\rightarrow W\n\\end{equation}\n\nWhere $V$ and $W$ are vector spaces. Affine transformations can be expresses as matrices by adding an entry with a constant to the vectors that describe a point in space. For example, for $\\mathbf{x} \\in \\mathbb{R}^n$,  the affine transform $f(\\mathbf{x}) = \\mathbf{A}\\mathbf{x} + \\mathbf{b}$ with $A\\in\\mathbb{R}^{n,n}$ and $x,b \\in \\mathbb{R}^{n}$ can be expressed as the product of a rectangular matrix $\\mathbf{M}$ and a vector $\\mathbf{c}$ as:\n\n\\begin{equation}\n\\mathbf{A}\\mathbf{x} + \\mathbf{b} = \\underbrace{\\left[\\begin{array}{c|c} \\mathbf{A} & \\mathbf{b} \\end{array}\\right]}_{\\mathbf{M}} \\underbrace{\\left[\\begin{array}{c} \\mathbf{x} \\\\ 1\\end{array} \\right]}_{\\mathbf{c}}\n\\end{equation}\n\nWhere $\\mathbf{c}^T = \\left[x_1,x_2,x_3,...,x_n,1\\right]$ and $\\mathbf{M} \\in \\mathbb{R}^{n,n+1}$.\n\n\n\\subsection{Unitary Transformations}\nUnitary transformations are transformations that preserve the inner product, i.e. $\\hat{U}x \\cdot \\hat{U}y = x \\cdot y$. As linear transformations, they are represented by unitary matrices (cf. section \\ref{sec:unitary}). Unitary transformations include translations, reflections and rotations. \n\n\n\\subsection{Multilinear Maps}\n\nA multilinear map acts on several vectors in a way that is linear in each of its arguments. A $k$-linear map acts on $k$ vectors, where $k=2$ are bilinear maps and $k=1$ are linear maps.\n\n\\begin{equation}\t\nf: V_1 \\times V_2 \\times ... \\times V_n \\rightarrow W\n\\end{equation}\n\nWhere $V_1, V_2, ... , V_n$ and $W$ are vector spaces. An example would be the addition or subtraction of two or more vectors.\n\n\\subsection{Multilinear Forms}\nMultilinear forms are multilinear maps that have a scalar output. An example is the dot product between two vectors, or summing over the elements of one or more vectors.\n\n\\begin{equation}\nf: V_1 \\times V_2 \\times ... \\times V_n \\rightarrow K\n\\end{equation}\n\nWhere $V_1, V_2, ... , V_n$ and $K$ is a scalar field.\n\n", "meta": {"hexsha": "198d89eb5a24d3c97c605bba8a1d63732a439251", "size": 2523, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/linalg_transformations.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/linalg_transformations.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/linalg_transformations.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": 44.2631578947, "max_line_length": 448, "alphanum_fraction": 0.7193816885, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8688267813328977, "lm_q1q2_score": 0.7579187617458719}}
{"text": "\\chapter{k-Means Clustering}\n\\label{ch:kmeans-clustering}\n\n\\newthought{Hierarchical clustering is not suitable for larger data sets} due to the prohibitive size of the distance matrix: with 30 thousand objects, the distance matrix already has almost one billion elements. An alternative approach that avoids using the distance matrix is k-means clustering.\n\nK-means clustering randomly selects \\textit{k} centers (with k specified in advance). Then it alternates between two steps. In one step, it assigns each point to its closest center, thus forming k clusters. In the other, it recomputes the centers of the clusters. Repeating these two steps typically converges quite fast; even for big data sets with millions of data points it usually takes just a couple of ten or hundred iterations.\n\nOrange's Educational add-on provides a widget \\widget{Interactive k-Means}, which illustrates the algorithm.\n\nUse the \\widget{Paint Data} widget to paint some data - maybe five groups of points. Feed it to Interactive k-means and set the number of centroids to 5. You may get something like this.\n\n\\marginnote{Try rerunning the clustering from new random positions and observe how the centers conquer the territory. Exciting, isn't it?}\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{interactive-kmeans.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\nKeep pressing Recompute Centroids and Reassign Membership until the plot stops changing. With this simple, two-dimensional data it will take just a few iterations; with more points and features, it can take longer, but the principle is the same.\n\nHow do we set the initial number of clusters? That's simple: we choose the number that gives the optimal clustering.\n\n% This should likely go out as this is explained in silhouette.\nWell then, how do we define the optimal clustering? This one is a bit harder. We want small distances between points in the same cluster and large distances between points from different clusters. Pick one point, and let A be its average distance to the data points in the same cluster and let B represent the average distance to the points from the closest other cluster. (The closest cluster? Just compute B for all other clusters and take the lowest value.) The value (B - A) / max(A, B) is called silhouette; the higher the silhouette, the better the point fits into its cluster. The average silhouette across all points is the silhouette of the clustering. The higher the silhouette, the better the clustering.\n\nNow that we can assess the quality of clustering, we can run k-means with different values of parameter k (number of clusters) and select k which gives the largest silhouette.\n\nFor this, we abandon our educational toy and connect Paint Data to the widget k-Means. We tell it to find the optimal number of clusters between 2 and 8, as scored by the Silhouette.\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{kmeans-silhouette.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n\n\\newpage\n\nWorks like a charm.\n\nExcept that it often doesn't. First, the result of k-means clustering depends on the initial selection of centers. With unfortunate selection, it may get stuck in a local optimum. We solve this by re-running the clustering multiple times from random positions and using the best result. Second, the silhouette sometimes fails to correctly evaluate the clustering. Nobody's perfect.\n\nTime to experiment. Connect the Scatter Plot to k-Means. Change the number of clusters. See if the clusters make sense. Could you paint the data where k-Means fails? Or where it works really well?\n\n\\begin{figure}[h]\n    \\centering\n    \\includegraphics[width=\\linewidth]{smiley-face.png}\n    \\caption{$\\;$} % empty caption for proper pagesetting\n\\end{figure}\n", "meta": {"hexsha": "5d47044fddaade4c81bed36515380a98d868d0bc", "size": 3846, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/013-kmeans-clustering/kmeans-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/013-kmeans-clustering/kmeans-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/013-kmeans-clustering/kmeans-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": 76.92, "max_line_length": 715, "alphanum_fraction": 0.7852314093, "num_tokens": 841, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357529306639, "lm_q2_score": 0.8740772466456689, "lm_q1q2_score": 0.7578562236649892}}
{"text": "\\subsection{Paraboloids}\r\n\\noindent\r\nThe paraboloid looks like a parabola that has been rotated and extruded about its axis of symmetry.\r\nIt is radially symmetric, and its level curves are circles.\r\nParaboloids have the form $z = ax^2 + by^2$ where $a,b \\in \\mathbb{R}$.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width = 0.3\\textwidth]{./Images/differentialMultivariableCalculus/paraboloid.png}\r\n\t\\caption{A paraboloid}\r\n\\end{figure}", "meta": {"hexsha": "f1087f3e5c62d060dd93feaa788f77312a80efe7", "size": 444, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/paraboloids.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/paraboloids.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/paraboloids.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.3636363636, "max_line_length": 100, "alphanum_fraction": 0.7545045045, "num_tokens": 134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.7578562158484319}}
{"text": "\\section{Exercises in Limit Laws of Statistics}\\label{S:xsLimitLaws}% {S:xsCFs}% {S:xsExpectationsOfRVs} %S:xsMultivariateRVs\n\n\\begin{ExerciseList}\n\n\\Exercise\nSuppose you plan to obtain a simple random sequence (SRS) --- also known as independent and identically distributed (IID) sequence --- of $n$ measurements from an instrument.  \nThis instrument has been calibrated so that the distribution of measurements made with it have population variance of $1/4$.  \nYour boss wants you to make a point estimate of the unknown population mean from a SRS of sample size $n$.  \nHe also insists that the tolerance for error has to be $1/10$ and the probability of meeting this tolerance should be just above $95\\%$.  \nUse CLT to find how large should $n$ be to meet the specifications of your boss.\n\\Answer\n~\\\\\n%Using the CLT implied Equation (61) in the lecture notes and further noting from the Standard Normal Table that when $z_{\\alpha/2}=2$ we get the desired $1-\\alpha=0.9772>0.95$ we get\n%\\[\n%n = \\left( \\sqrt{(V(X_1)} z_{\\alpha/2}) / \\epsilon \\right)^2 = \\left( (\\sqrt{1/4}\\times 2) / (1/10) \\right)^2\n%= \\left( ((1/2)\\times 2) / (1/10) \\right)^2 = 10^2 = 100\n%\\]\nWe want $1-\\alpha = 0.95$, and from the standard Normal Table we know that the corresponding $z_{\\alpha/2}=1.96$.   \nThen we can get the right sample size $n$ from the CLT implied Equation (61) in the lecture notes, which is,\n\\[\nn = \\left( \\sqrt{(V(X_1)} z_{\\alpha/2}) / \\epsilon \\right)^2 \\enspace ,\n\\] \nas follows:\n\\begin{eqnarray*}\nn &= \\left( \\sqrt{(V(X_1)} z_{\\alpha/2}) / \\epsilon \\right)^2 = \\left( (\\sqrt{1/4}\\times 1.96) / (1/10) \\right)^2\\\\\n&= \\left( ((1/2)\\times 1.96) / (1/10) \\right)^2 = (0.98 \\times 10)^2 = 9.8^2 = 96.04\n\\end{eqnarray*}\nFinally, by rounding $96.04$ up to the next largest integer we need $n=97$ measurements to meet the specifications of your boss (at least up to the approximation provided by the CLT).\n\n\n\\Exercise \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 $\\textrm{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}_{125}$ 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 want to know how often our sample mean $\\overline{X}_{125}$ differs from the expectation of $5$ errors per program.  \nUsing the CLT find the $P(\\overline{X}_{125} < 5.5)$.\n\\Answer\n~\\\\\nBy CLT, $\\frac{\\sqrt{n}(\\overline{X}_n - \\E(X_1))}{\\sqrt{\\V(X_1)}} \\rightsquigarrow Z \\sim \\mathrm{Normal}(0,1)$.  \nSo we need to apply the ``standardization'' to both sides of the inequality that is defining the event of interest:\n$$\\{\\overline{X}_n < 5.5\\} \\enspace ,$$ \nin order to find its probability $\\P(\\overline{X}_n < 5.5)$.\n~\\\\\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 [\nsince we know/assume that $\\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) = 0.9938\\ . \\notag\n\\end{eqnarray}\n(source: Wasserman, {\\em All of Statistics}, Springer, p.~78, 2003)\n\n\n\\Exercise\nWhat is the distribution of $\\sum_{i=1}^n{X_i}/n$ as $n \\to \\infty$ when $X_i \\overset{IID}{\\sim} \\uniform(-10,10)$?\n\\Answer\nHINT: Use the LLN after finding the population mean of $X_i$.\n\\Exercise\nWhat is the distribution of $\\sum_{i=1}^n{X_i}/\\sqrt{\\V(X_i)n}$ as $n \\to \\infty$ when $X_i \\overset{IID}{\\sim} \\uniform(-10,10)$?\n\\Answer\nHINT: Use the CLT after finding the population mean and variance of $X_i$.\n\\end{ExerciseList}\n", "meta": {"hexsha": "072e91008d939148cfb12cb68fa0595415b4be61", "size": 4174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInLimitsOfRVs.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/ExsInLimitsOfRVs.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/ExsInLimitsOfRVs.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": 64.2153846154, "max_line_length": 370, "alphanum_fraction": 0.6792045999, "num_tokens": 1455, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7578562149737238}}
{"text": "\\section{The Seifert-van Kampen Theorem}\r\n\\subsection{Some Group Theory}\r\nRecall that we can sometimes represent groups using generators and relations, e.g. the dihedral group $D_{2n}$ can be written as $\\langle r,s|s^2=r^n=srsr=1\\rangle$ meaning it is the group generated by $r,s$ subject to the given relations $s^2=r^n=1,srs=r^{-1}$.\r\n\\begin{definition}\r\n    Let $A$ be a set.\r\n    The free group on $A$ is a group $F(A)$ such that there is a function $\\phi:A\\to F(A)$ satisfying the following universal property:\\\\\r\n    Whenever there is a group $G$ and a function $h:A\\to G$, there exists a unique homomorphism $f:F(A)\\to G$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            F(A)\\arrow[dashed]{dr}{f}&\\\\\r\n            A\\arrow{u}{\\phi} \\arrow[swap]{r}{h}&G\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{definition}\r\n\\begin{example}\r\n    Let $A=\\{\\alpha\\}$ and $\\phi:A\\to\\mathbb Z$ be the map $\\alpha\\mapsto 1$.\r\n    Then for any $h:A\\to G$ mapping $\\alpha$ to $g\\in G$, we necessarily have $f:\\mathbb Z\\to G$ via $n\\mapsto g^n$ such that $f\\circ\\phi=h$.\r\n    Hence $\\mathbb Z$ is the free group on $\\{a\\}$.\r\n\\end{example}\r\n\\begin{remark}\r\n    This definition, as a universal property, does not give an explicit construction of $F(A)$ but captured all of its group theorectical properties.\r\n    As such, if such an $F(A)$ exists it must be unique up to group isomorphism -- that's why we used ``the'' free group instead of ``a'' free group.\r\n\\end{remark}\r\n\\begin{proposition}\r\n    Let $A$ be a set and $F(A),F'(A)$ be both free groups on $A$, then $F(A)\\cong F'(A)$ as groups.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Suppose $\\phi:A\\to F(A),\\phi':A\\to F'(A)$ be the maps described in the definition.\r\n    Take $G=F'(A)$ gives a unique homomorphism $f:F(A)\\to F'(A)$ such that $f\\circ\\phi=\\phi'$ since $F(A)$ s a free group on $A$; $G=F(A)$ also gives a unique homomorphism $g:F'(A)\\to F(A)$ such that $g\\circ\\phi'=\\phi$.\r\n    We claim that $f,g$ are inverse to each other.\r\n    Now $f\\circ g$ makes the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            F'(A)\\arrow{dr}{f\\circ g}&\\\\\r\n            A\\arrow{u}{\\phi'}\\arrow[swap]{r}{\\phi'}&F'(A)\r\n        \\end{tikzcd}\r\n    \\]\r\n    commute.\r\n    But then since $F'(A)$ is free, $f\\circ g$ must equal to $\\operatorname{id}_{F'(A)}$ (which also makes the diagram commute when putting it in the place of $f\\circ g$) by uniqueness.\r\n    Similarly $g\\circ f=\\operatorname{id}_{F(A)}$.\r\n    Hence $f,g$ are indeed inverses of each other.\r\n    This shows $F(A)\\cong F'(A)$.\r\n\\end{proof}\r\nThe proof also shows that the isomorphism is uniquely determined if we ask it to be compatible with $\\phi,\\phi'$.\r\nIn other word, it is canonical with respect to this universal property.\r\n\\begin{definition}\r\n    If $A$ is a finite set of cardinality $r$, then we write $F_r=F(A)$ to be the free group of rank $r$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    The words in $A$ are the strings composed of elements in $A$ and their (symbolic) inverses.\r\n\\end{definition}\r\nFor example, $w=aba^{-1}bba^{-1}a^{-1}b$ is a word in $A$.\r\nWe can canonically identify a word in $A$ by an element of $F(A)$ by mapping it to the product (with the same order of elements) of the respective images, e.g. $abba^{-1}b$ can be identified with $\\phi(a)\\phi(b)^2\\phi(a)^{-1}\\phi(b)\\in F(A)$.\\\\\r\nIt is easy to check that $\\phi(A)$ also satisfies the same universal property of a free group on $A$, therefore by uniqueness we can assume $F(A)$ is generated by $\\phi(A)$.\r\nSo $F(A)$ can be seen as the set of words in $A$, possibly with some identifications (e.g. $aa^{-1}b=b$).\r\nAs a recreational exercise, one can precisely construct a free group on any given set in this way.\r\nAfter the construction, we can happily identify $A$ as a generating subset of $F(A)$.\r\n\\begin{definition}\r\n    A presentation is a set $A$ and a subset of relations $R\\subset F(A)$ which identifies the group\r\n    $$\\langle A|R\\rangle=F(A)/\\langle\\langle R\\rangle\\rangle$$\r\n    where $\\langle\\langle R\\rangle\\rangle$ is the smallest normal subgroup of $F(A)$ containing $R$ (i.e. intersection of all normal subgroups containing $R$).\r\n    The presentation is finite if both $A,R$ are.\r\n\\end{definition}\r\nEasily $\\langle\\langle R\\rangle\\rangle=\\langle\\{srs^{-1}:s\\in F(A),r\\in R\\}\\rangle$.\r\n\\begin{lemma}[Universal Property of Presentation]\r\n    Let $q:F(A)\\to\\langle A|R\\rangle$ be the quotient map.\r\n    Whenever $f:F(A)\\to G$ is a group homomorphism such that $R\\subset\\ker f$, there is a unique homomorphism $g:\\langle A|R\\rangle\\to G$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\langle A|R\\rangle\\arrow[dashed]{dr}{g}&\\\\\r\n            F(A)\\arrow{u}{q}\\arrow[swap]{r}{f}&G\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Necessarily $g(w\\langle\\langle R\\rangle\\rangle)=f(w)$ which works since $\\langle\\langle R\\rangle\\rangle\\le\\ker f$ by definition.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. We know that $F(\\{a\\})\\cong\\mathbb Z$ and every subgroup of $\\mathbb Z$ is normal, so $\\langle\\langle a^n\\rangle\\rangle=\\langle a^n\\rangle$ corresponds to $n\\mathbb Z$, so $\\langle a|a^n\\rangle\\cong\\mathbb Z/n\\mathbb Z$.\\\\\r\n    2. We claim that $G=\\langle r,s|r^n,s^2,rsrs\\rangle$ is isomorphic to $D_{2n}$.\r\n    Indeed, the homomorphism $F(\\{r,s\\})\\to D_{2n}$ sending $r$ to a rotation of $D_{2n}$ and $s$ to a reflection takes $R=\\{r^n,s^2,rsrs\\}$ to the identity.\r\n    Thus it factors through $G$ via $\\phi:G\\to D_{2n}$ by the universal property.\r\n    Now $\\phi$ is obviously surjective and injective since we can write $G=\\{1,r,\\ldots,r^{n-1},s,sr,\\ldots,sr^{n-1}\\}$ which has the correct size.\\\\\r\n    3. Every group has a presentation.\r\n    The identity map from $G$ as a set to $G$ as a group induces a group homomorphism $F(G)\\to G$ which is surjective.\r\n    Let $R$ be the kernel of this map, then $G=\\langle G|R\\rangle$.\r\n    (This is, however, not very useful since this is a very inefficient choice of generators and relations.)\r\n\\end{example}\r\n\\begin{definition}[Pushouts]\r\n    Consider a commutative square\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\Gamma&A\\arrow[swap]{l}{k}\\\\\r\n            B\\arrow{u}{l}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\r\n        \\end{tikzcd}\r\n    \\]\r\n    It is called a pushout if it satisfies the following universal property:\r\n    If $G$ is a group with homomorphism $f:A\\to G,g:B\\to G$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            G&A\\arrow[swap]{l}{f}\\\\\r\n            B\\arrow{u}{g}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes, then there is a unique $\\phi:\\Gamma\\to G$ such that\r\n    \\[\r\n        \\begin{tikzcd}\r\n            G&&\\\\\r\n            &\\Gamma\\arrow[swap,dashed]{ul}{\\exists!\\phi}&A\\arrow[swap]{l}{k}\\arrow[swap, bend right]{ull}{f}\\\\\r\n            &B\\arrow{u}{l}\\arrow[bend left]{uul}{g}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\\\\\r\n    If this is indeed the case, then we write $\\Gamma=A\\sqcup_CB$ (the arrows $i,j$ are equipped with $A,B$ and $k,l$ are equipped with $\\Gamma$).\r\n\\end{definition}\r\nGiven $A,B,C,i,j$, one can check that such a $\\Gamma$ is unique up to isomorphism.\r\n\\begin{definition}\r\n    If $C=\\{e\\}$ and $i,j$ be the unique homomorphisms from $C$ to $A,B$, then $A\\sqcup_CB$ is called the free product, denotes by $A\\star B$.\\\\\r\n    If $i,j$ are injective, then $A\\coprod_CB$ is called the amalgamated product and is written as $A\\star_CB$.\r\n\\end{definition}\r\n\\begin{lemma}\\label{pushout_onetrivial}\r\n    For $i:C\\to A,j:C\\to B=\\{e\\}$, we have $A\\sqcup_C\\{e\\}\\cong A/\\langle\\langle i(C)\\rangle\\rangle$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Take $q:A\\to A/\\langle\\langle i(C)\\rangle\\rangle$ to be the quotient map and $\\iota:\\{e\\}\\to A/\\langle\\langle i(C)\\rangle\\rangle$ the natural inclusion, then the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            A/\\langle\\langle i(C)\\rangle\\rangle&A\\arrow[swap]{l}{q}\\\\\r\n            \\{e\\}\\arrow{u}{\\iota}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\r\n        \\end{tikzcd}\r\n    \\]\r\n    does commute.\r\n    Now suppose that there are $f,g$ such that $j\\circ g=i\\circ f$, i.e. the bigger diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            G&&\\\\\r\n            &\\Gamma\\arrow[swap,dashed]{ul}{?}&A\\arrow[swap]{l}{q}\\arrow[swap, bend right]{ull}{f}\\\\\r\n            &\\{e\\}\\arrow{u}{\\iota}\\arrow[bend left]{uul}{g}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\r\n        \\end{tikzcd}\r\n    \\]\r\n    commutes.\r\n    Then by commutativity, $f\\circ i$ is the constant homomorphism since $g$ (hence $j\\circ g$) has to be, so $f(i(C))=\\{e\\}\\in G$, therefore $i(C)\\subset\\ker f$.\r\n    As $f$ is normal, necessarily $\\langle\\langle i(C)\\rangle\\rangle\\subset\\ker f$, so we necessarily have to choose\r\n    $$\\phi:A/\\langle\\langle i(C)\\rangle\\rangle\\to G,w\\langle\\langle i(C)\\rangle\\rangle\\mapsto f(w)$$\r\n    which works.\r\n\\end{proof}\r\nDo pushouts always exist?\r\n\\begin{lemma}\r\n    Let $A=\\langle S_1|R_1\\rangle$ and $B=\\langle S_2|R_2\\rangle$ and let $T\\subset C$ be a generating set for $C$.\r\n    Suppose $\\tilde\\imath:T\\to F(S_1)$ is a lift of a function $i|_T$ and $\\tilde\\jmath:T\\to F(S_2)$ is a lift of $j|_T$ (so $q_1\\circ\\tilde\\imath=i,q_2\\circ\\tilde\\jmath=j$ on $T$ where $q_1:F(S_1)\\to A,q_2:F(S_2)\\to B$ are the projections), then\r\n    $$\\Gamma=\\langle S_1\\sqcup S_2|R_1\\cup R_2\\cup \\{\\tilde\\imath(t)^{-1}\\tilde\\jmath(t):t\\in T\\}\\rangle$$\r\n    is a presentation of $A\\sqcup_CB$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Again we check the universal property.\r\n    Suppose there is a group $G$ with $f:A\\to G,g:B\\to G$ homomorphisms such that $j\\circ g=i\\circ f$, then we have the commutative diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            G&&&\\\\\r\n            &\\Gamma\\arrow[swap,dashed]{ul}{?}&A\\arrow[swap]{l}{k}\\arrow[swap, bend right]{ull}{f}&F(S_1)\\arrow[swap]{l}{q_1}\\\\\r\n            &B\\arrow{u}{l}\\arrow[bend left]{uul}{g}&C\\arrow{l}{j}\\arrow[swap]{u}{i}\\arrow[hookleftarrow]{dr}&\\\\\r\n            &F(S_2)\\arrow{u}{q_2}&&T\\arrow{ll}{\\tilde\\jmath}\\arrow[swap]{uu}{\\tilde\\imath}\r\n        \\end{tikzcd}\r\n    \\]\r\n    where $k,l$ are induced by the natural inclusions $S_1\\hookrightarrow S_1\\sqcup S_2,S_2\\hookrightarrow S_1\\sqcup S_2$ via the universal property of presentations.\r\n    Let $\\tilde{f}=f\\circ q_1$ and $\\tilde{g}=g\\circ q_2$.\r\n    Then $\\tilde{f}(R_1)=\\tilde{g}(R_2)=\\{e\\}\\subset G$ and $\\tilde{f}\\circ\\tilde\\imath=\\tilde{g}\\circ\\tilde\\jmath$.\r\n    Now let $\\phi:F(S_1\\sqcup S_2)\\to G$ induced by $\\tilde{f}$ on $S_1$ and $\\tilde{g}$ on $S_2$.\r\n    But then we have $\\phi(R_1\\cup R_2)=0$ by definiton and $\\phi(\\tilde\\imath(t)^{-1}\\tilde\\jmath(t))=e$ for any $t\\in T$ since $\\tilde{f}\\circ\\tilde\\imath=\\tilde{g}\\circ\\tilde\\jmath$.\r\n    So by the universal property of presentations, $\\phi$ induces the desired map.\r\n\\end{proof}\r\n\\subsection{The Seifert-van Kampen Theorem}\r\n\\begin{definition}\r\n    let $(X,x_0),(Y,y_0)$ be based spaces, then the wedge of $X,Y$ is $X\\vee Y=(X\\sqcup Y)/\\sim$ where $\\sim$ is the smallest equivalence relations such that $x_0\\sim y_0$.\r\n    The equivalence class $[x_0]=[y_0]$ is the wedge point.\r\n\\end{definition}\r\nSo we are basically just glueing $X,Y$ together by attaching $x_0$ to $y_0$.\r\n\\begin{theorem}[Seifert-van Kampen Theorem for Wedges]\\label{s-vk_wedge}\r\n    Suppose $X=Y_1\\vee Y_2$ where $Y_1,Y_2$ are path connected and let $x_0\\in X$ be the wedge point.\r\n    Then $\\pi_1(X,x_0)\\cong\\pi_1(Y_1,x_0)\\star\\pi_1(Y_2,x_0)$.\r\n\\end{theorem}\r\n\\begin{proof}[Sketch of proof]\r\n    Let $i_1:Y_1\\to X,i_2:Y_2\\to X$ be the natural inclusions which are continuous.\r\n    We shall attempt to show\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X,x_0)&\\pi_1(Y_1,x_0)\\arrow[swap]{l}{(i_1)_\\ast}\\\\\r\n            \\pi_1(Y_2,x_0)\\arrow{u}{(i_2)_\\ast}&\\{e\\}\\arrow{u}\\arrow{l}\r\n        \\end{tikzcd}\r\n    \\]\r\n    is a pushout.\r\n    Suppose we are given $f_1:\\pi_1(Y_1,x_0)\\to G$ and $f_2:\\pi_1(Y_2,x_0)\\to G$ for some group $G$.\r\n    We need to prove that there is a unique map $g:\\pi_1(X,x_0)\\to G$ such that $g\\circ (i_1)_\\ast=f_1,g\\circ (i_2)_\\ast=f_2$.\r\n    Given a loop in $X$, write it as a concatenation $\\gamma=\\alpha_1\\beta_1\\alpha_2\\beta_2\\cdots\\alpha_n\\beta_n$ with $\\alpha_i$ loops in $Y_1$ and $\\beta_i$ loops in $Y_2$.\r\n    We leave out the details of the proof that it is always possible.\r\n    Hence we necessarily have $g([\\gamma])=f_1([\\alpha_1])f_2([\\beta_1])\\cdots f_1([\\alpha_n])f_2([\\beta_n])$, which one can check is well-defined and works.\r\n\\end{proof}\r\n\\begin{example}\r\n    1. The figure 8 has fundamental group $\\pi_1(S^1\\vee S^1)\\cong\\pi_1(S^1)\\star\\pi_1(S^1)\\cong\\mathbb Z\\star\\mathbb Z\\cong F_2$.\r\n    Worth noting that this group is nonabelian.\\\\\r\n    2. Let $A$ be any finite set, then define $\\bigvee_AS^1=(A\\times S^1)/\\sim$ where $\\sim$ is the smallest equivalence relation such that $(a,1)\\sim (a',1)$ for any $a,a'\\in A$.\r\n    Then inductively $\\pi_1(\\bigvee_AS^1,1)\\cong F_{|A|}$.\r\n    In particular, there exists spaces whose fundamental group is $F_n$ for any positive integer $n$.\r\n\\end{example}\r\n\\begin{theorem}[Seifert-van Kampen Theorem]\\label{s-vk_open}\r\n    Suppose $Y_1,Y_2\\subset X$ are open, $X=Y_1\\cup Y_2$ and $Z=Y_1\\cap Y_2$ is nonempty.\r\n    Suppose also that they are all path-connected.\r\n    Let $i_k:Z\\hookrightarrow Y_k$ and $j_k:Y_k\\hookrightarrow X$ be the inclusions and fix $x_0\\in Z$.\r\n    Then the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X,x_0)&\\pi_1(Y_2,x_0)\\arrow[swap]{l}{(j_2)_\\ast}\\\\\r\n            \\pi_1(Y_1,x_0)\\arrow{u}{(j_1)_\\ast}&\\pi_1(Z,x_0)\\arrow[swap]{u}{(i_2)_\\ast}\\arrow{l}{(i_1)_\\ast}\r\n        \\end{tikzcd}\r\n    \\]\r\n    is a pushout.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\n\\begin{example}\r\n    We want to calculate the fundamental group of the $n$-sphere $S^n$ for $n\\ge 2$.\r\n    Let $x_\\pm=(\\pm 1,0,\\ldots,0)$ and $U_\\pm=S^n\\setminus\\{x_\\pm\\}$ and $V=U_+\\cap U_-$.\r\n    Now that $V=S^n\\setminus\\{x_+,x_-\\}\\cong S^{n-1}\\times (-1,1)$ via\r\n    $$(x_1,\\ldots,x_{n+1})\\mapsto\\left( \\frac{(x_2,\\ldots,x_{n+1})}{|(x_2,\\ldots,x_{n+1})|},x_1 \\right)$$\r\n    which is path-connected for $n\\ge 2$.\r\n    Also, $U_\\pm$ are both homeomorphic to $\\mathbb R^n$ via stereographic projection.\r\n    We know that $X=U_+\\cup U_-$, so by Seifert-van Kampen the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(S^n)&\\{e\\}\\arrow{l}\\\\\r\n            \\{e\\}\\arrow{u}&\\pi_1(V)\\arrow{u}\\arrow{l}\r\n        \\end{tikzcd}\r\n    \\]\r\n    is a pushout.\r\n    But then $\\pi_1(S^n)$ is necessarily the trivial group.\r\n    Therefore $S^n$ is simply connected for $n\\ge 2$.\r\n    Note that this argument breaks down for $n=1$ since $V$ is not path-connected in that case.\r\n\\end{example}\r\nNote that this version of Seifeit-van Kampen does not directly generalise Theorem \\ref{s-vk_wedge}.\r\nBut of course we want to have a version that generalises it, so here goes.\r\n\\begin{definition}\r\n    A subset $Y\\subset X$ is called a neighbourhood retract if there is some $V\\subset X$ open and contains $Y$ such that $Y$ is a deformation retract of $V$.\r\n\\end{definition}\r\n\\begin{theorem}[Seifert-van Kampen Theorem for Closed Sets]\\label{s-vk_closed}\r\n    Suppose $Y_1,Y_2\\subset X$ are closed and $Y_1\\cup Y_2=X$, $Y_1\\cap Y_2=Z\\neq\\varnothing$.\r\n    Assume everything is path-connected and $Z$ is a neighbourhood retract in both $Y_1$ and $Y_2$, then the diagram\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X,x_0)&\\pi_1(Y_2,x_0)\\arrow[swap]{l}{(j_2)_\\ast}\\\\\r\n            \\pi_1(Y_1,x_0)\\arrow{u}{(j_1)_\\ast}&\\pi_1(Z,x_0)\\arrow[swap]{u}{(i_2)_\\ast}\\arrow{l}{(i_1)_\\ast}\r\n        \\end{tikzcd}\r\n    \\]\r\n    is a pushout where as usual $i_k:Z\\hookrightarrow Y_k$ and $j_k:Y_k\\hookrightarrow X$ are the inclusions and $x_0\\in Z$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Also omitted.\r\n\\end{proof}\r\n\\subsection{Attaching Cells}\r\n\\begin{definition}\r\n    Let $X$ be a space and let $\\alpha:S^{n-1}\\to X$ be a map.\r\n    The space obtained by attaching an $n$-cell to $X$ is $X\\cup_\\alpha D^n=(X\\sqcup D^n)/\\sim$ where $\\sim$ is the smallest equivalence relation that identifies $x\\sim \\alpha(x)$ for $x\\in S^{n-1}$.\r\n\\end{definition}\r\n\\begin{example}\r\n    For $n=1$, we are just attaching a string to two (possibly one) points on $X$.\r\n    For $n=2$, things can get pretty complicated.\r\n    Although we are just identifying $S^1$ with a loop in $X$ and attach $D^n$ there accordingly, this can give many varieties as the loop can intersect and/or wind itself.\r\n\\end{example}\r\nWe want to study what happen to the fundamental group when we attach an $n$-cell.\r\n\\begin{lemma}\r\n    If $n\\ge 3$ and $i:X\\to X\\cup_\\alpha D^n$ be the natural inclusion.\r\n    The $i_\\ast$ is an isomorphism of fundamental groups.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    We are going to construct something called the mapping cylinder of $\\alpha$, which is the space\r\n    $$M_\\alpha=(X\\sqcup(S^{n-1}\\times I))/\\sim$$\r\n    where $\\sim$ is the smallest equivalence relation containing $(\\theta,0)\\sim\\alpha(\\theta)$ where $\\theta\\in S^{n-1}$.\r\n    Now identify $S^{n-1}$ with $S^{n-1}\\times \\{1\\}\\subset M_\\alpha$ which is now a neighbourhood retract of $M_\\alpha$.\r\n    Note that $X\\cup_\\alpha D^n\\cong M_\\alpha\\cup_{\\operatorname{id}_{S^{n-1}}}D^n$.\r\n    Also, $S^{n-1}$ is a neighbourhood retract in $D^n$.\r\n    Now by Theorem \\ref{s-vk_closed} with basepoint $x\\in S^{n-1}\\subset M_\\alpha\\cup_{\\operatorname{id}_{S^{n-1}}}D^n$ and take $Y_1=M_\\alpha$, $Y_2=D^n$ and $Z=Y_1\\cap Y_2=S^{n-1}$.\r\n    This gives us the pushout\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X\\cup_\\alpha D^n,x_0)&\\pi_1(M_\\alpha,x_0)\\arrow{l}\\\\\r\n            \\pi_1(D^n,x_0)\\arrow{u}&\\pi_1(S^{n-1},x_0)\\arrow{u}\\arrow{l}\r\n        \\end{tikzcd}\r\n    \\]\r\n    Now for $n\\ge 3$, $\\pi_1(S^{n-1},x_0)=\\pi_1(D^n,x_0)=\\{e\\}$.\r\n    which means that $\\pi_1(X\\cup_\\alpha D^n,x_0)\\cong\\pi_1(M_\\alpha,x_0)$.\r\n    But $X$ is obviously a deformation retract of $M_\\alpha$, therefore $\\pi_1(X,x_0')\\cong\\pi_1(M_\\alpha,x_0)\\cong\\pi_1(X\\cup_\\alpha D^n,x_0)$ where $x_0'$ is the image of $x_0$ under the deformation retract.\r\n\\end{proof}\r\nWhat if we attach a $2$-cell?\r\n\\begin{lemma}\r\n    Let $\\alpha:S^1\\to X$  be a map and $x_0=\\alpha(\\theta_0)$ for some $\\theta_0\\in S^1$.\r\n    Then\r\n    $$\\pi_1(X\\cup_\\alpha D^2,x_0)\\cong\\pi_1(X,x_0)/\\langle\\langle [\\alpha]\\rangle\\rangle$$\r\n    viewing $\\alpha$ as a loop based at $x_0$.\r\n    The quotient map, in particular, is induced by the inclusion map $i:X\\to X\\cup_\\alpha D^2$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    By the same procedure as above we obtain the pushout\r\n    \\[\r\n        \\begin{tikzcd}\r\n            \\pi_1(X\\cup_\\alpha D^n,x_0)&\\pi_1(X,x_0)\\arrow{l}\\\\\r\n            \\pi_1(D^2,\\theta_0)=\\{e\\}\\arrow{u}&\\pi_1(S^1,\\theta_0)=\\mathbb Z\\arrow{l}\\arrow[swap]{u}{1\\mapsto [\\alpha]}\r\n        \\end{tikzcd}\r\n    \\]\r\n    The result then follows from Lemma \\ref{pushout_onetrivial}.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    For any finitely presented group $G$, i.e. $G\\cong\\langle A|R\\rangle$ where $A,R$ are both finite, there exists a compact space $X$ with $\\pi_1(X,x_0)\\cong G$ for some $x_0\\in X$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Let $Y=\\bigvee_AS^1$ and let $y_0$ be the common wedge point.\r\n    We already know that $\\pi_1(Y,y_0)\\cong F(A)$.\r\n    Now for each relation $r\\in R$, we get a loop $\\alpha_r:S^1\\to Y$ representing it in the obvious way.\r\n    Then attach $D^2$ to $Y$ via $\\alpha_r$ for each $r\\in R$ gives a (necessarily compact) space with fundamental group isomorphic to $G$.\r\n\\end{proof}\r\n\\subsection{Classification of Surfaces}\r\n\\begin{definition}\r\n    An $n$ dimensional (topological) manifold (or $n$-manifold) is a Hausdorff space $M$ such that every point $x\\in M$ has a neighbourhood $U$ homeomorphic to an open set of $\\mathbb R^n$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. The $S^n$ is an $n$-manifold.\\\\\r\n    2. (non-example) The figure 8 is not a manifold since the wedge point does not have a neighbourhood that is locally homeomorphic to $\\mathbb R^n$.\\\\\r\n    3. Take $\\alpha:S^1\\to X=\\{\\ast\\}$, then $Y=X\\cup_\\alpha D^2\\cong S^2$ is a $2$-manifold.\r\n\\end{example}\r\nThere is a more interesting and influential example:\r\nLet $g$ be a positive integer and let\r\n$$\\Gamma_{2g}=\\bigvee_{i=1}^{2g}S^1_i$$\r\nbe the wedge product of $2g$ copies $S_i^1$ of the circle with a common wedge point $x_0$.\r\nLet $\\alpha_i:I\\to S_i^1,\\beta_i:I\\to S_{i+g}^1$ be simple loops with basepoint $x_0$ for $i=1,\\ldots,g$ and consider the loop\r\n$$\\rho_g=\\alpha_1\\beta_1\\bar\\alpha_1\\bar\\beta_1\\cdots\\alpha_g\\beta_g\\bar\\alpha_g\\bar\\beta_g$$\r\nIf we think of $\\rho_g$ as a map $S^1\\to \\Gamma_{2g}$ and define $\\Sigma_g=\\Gamma_{2g}\\cup_{\\rho_g}D^2$.\r\nWe claim that $\\Sigma=\\Sigma_g$ is a compact $2$-manifold.\r\nObviously any interior points of $D^2$ has an open neighbourhood homeomorphic to an open set in $\\mathbb R^2$.\r\nAt non-wedge point in $S_i^1$, the path $\\alpha_i$ (if $i\\le g$) or $\\beta_{i-g}$ (if $i>g$) appears with its inverse in $\\rho_g$, so we can obtain a neighbourhood we want near that point as well.\r\nAt wedge point, note that $g=1$ gives the standard identification of the torus on a square, in which case the wedge point is simply the corners (which are identified as the same point) which obviously has a neighbourhood homeomorphic to an open set in $\\mathbb R^2$.\r\nAn analogy works for higher $g$.\r\n$\\Sigma_g$ is called the orientable surface of genus $g$.\\\\\r\nNow easily $g=1$ just gives the torus.\r\nFor $g=2$, we can think of the disk as an octagon and do a little bit of imagination by gluing the respective edges, which will give a $2$-torus, i.e. a torus with two holes.\r\nA little bit more of imagination shows that $\\Sigma_n$ is the $n$-torus.\r\nTheir fundamental groups are clear by our previous discussion:\r\n$$\\pi_i(\\Sigma_g)=\\langle a_1,\\ldots,a_g,b_1,\\ldots b_g|a_1b_1a_1^{-1}b_1^{-1}\\cdots a_gb_ga_g^{-1}b_g^{-1}\\rangle$$\r\nNow take $\\Gamma_{g+1}=\\sum_{i=0}^gS_i^1$ as the wedge of $g+1$ circles and $\\alpha_i:I\\to S_i^1$ be the loop around the $i^{th}$ circle and $\\sigma_g=\\alpha_0\\alpha_0\\alpha_1\\alpha_1\\cdots\\alpha_g\\alpha_g$ viewed as a map $\\sigma_g:\\partial D^2\\to\\Gamma_{g+1}$.\r\nThen take $S_g=\\Gamma_{g+1}\\cup_{\\sigma_g}D^2$ which is a $2$=manifold called the non-orientable surface of genus $g$.\r\nAs one can see, $S_0$ is simply the real projective plane, and $S_1$ the Klein bottle.\r\n$S_g$ for $g>1$ would shaped like attaching some orientable surface to the Klein bottle.\r\nThe fundamental groups are\r\n$$\\pi_1(S_g)\\cong\\langle a_0,\\ldots,a_g|a_0^1a_1^2\\cdots a_g^2\\rangle$$\r\nSo for example $\\pi_1(S_0)\\cong\\mathbb Z/2\\mathbb Z$.\r\n\\begin{theorem}\r\n    Any compact surface $S$ is homeomorphic to $S_g$ or $\\Sigma_g$ for some $g$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Omitted.\r\n\\end{proof}\r\nBut how do we know that they are topologically distinct?\r\n\\begin{lemma}\r\n    Let $g\\in\\mathbb N$, then $\\pi_1(\\Sigma_g)$ surjects onto $\\mathbb Z^{2g}$ but not $\\mathbb Z^{2g}\\oplus(\\mathbb Z/2\\mathbb Z)$ and $\\pi_1(S_g)$ surjects onto $\\mathbb Z^g\\oplus(\\mathbb Z/2\\mathbb Z)$ but not $\\mathbb Z^{g+1}$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Let $\\{\\bar{a}_i,\\bar{b}_i\\}$ be the standard basis of $\\mathbb Z^{2g}$.\r\n    Then the map $a_i\\mapsto\\bar{a}_i,b_i\\mapsto \\bar{b}_i$ respects the relation, therefore by the universal property there is a surjective homomorphism from $\\pi_1(\\Sigma_g)$ to $\\mathbb Z^{2g}$.\r\n    Now suppose we have a surjective homomorphism $f:\\pi_1(\\Sigma_g)\\to\\mathbb Z^{2g}\\oplus(\\mathbb Z/2\\mathbb Z)$.\r\n    Compose it with the reduction $\\mathbb Z^{2g}\\oplus(\\mathbb Z/2\\mathbb Z)\\to(\\mathbb Z/2\\mathbb Z)^{2g+1}$ gives a surjective homomorphism $f':\\pi_1(\\Sigma_g)\\to(\\mathbb Z/2\\mathbb Z)^{2g+1}$.\r\n    Therefore $f'(a_1),\\ldots,f'(a_g),f'(b_1),\\ldots,f'(b_g)$ should generate $(\\mathbb Z/2\\mathbb Z)^{2g+1}$, which is impossible by viewing $(\\mathbb Z/2\\mathbb Z)^{2g+1}$ as a vector space over $\\mathbb Z/2\\mathbb Z$ with dimension $2g+1$.\\\\\r\n    For $\\pi_1(S_g)$, let $\\{\\bar{a}_i\\}$ be a basis for the $\\mathbb Z^g$ part of $\\mathbb Z^g\\oplus(\\mathbb Z/2\\mathbb Z)$ and let $\\bar{c}_0$ generate the $\\mathbb Z/2\\mathbb Z$ part.\r\n    Then the map $a_0\\mapsto \\bar{c}_0-\\sum_{i=1}^g\\bar{a}_i, a_i\\mapsto \\bar{a}_i$ respects the relation, hence induces the desired surjective homomorphism $\\pi_1(S_g)\\to\\mathbb Z^g\\oplus(\\mathbb Z/2\\mathbb Z)$ via the universal property.\r\n    Now if there is a surjective homomorphism $f:\\pi_1(S_g)\\to\\mathbb Z^{g+1}$, then $\\mathbb Z^{g+1}$ is generated by $f(a_0),\\ldots,f(a_g)$.\r\n    But then $0=f(\\sigma_g)=2f(a_0)+\\cdots+2f(a_g)$ which is a nontrivial relation between the generators $f(a_0),\\ldots,f(a_g)$.\r\n    This is a contradiction.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    $\\Sigma_g$ and $S_g$ have mutually distinct fundamental groups.\r\n\\end{corollary}\r\nIn particular, they are mutually distinct in terms of homotopy equivalence and hence in terms of homeomorphism.\r\n\\begin{proof}\r\n    If $\\Sigma_g$ and $\\Sigma_{g'}$ have the same fundamental group but $g<g'$, then by the preceding lemma, there is a surjection $\\pi_1(\\Sigma_g)=\\pi_1(\\Sigma_{g'})\\to\\mathbb Z^{g'}\\to\\mathbb Z^g\\oplus(\\mathbb Z/2\\mathbb Z)$, contradiction.\r\n    The other cases can be argued similarly.\r\n\\end{proof}\r\n\\begin{remark}\r\n    We can easily generalise the fundamental group $\\pi_1$ to higher dimension, which are known as the $n^{th}$ homotopy groups $\\pi_n$ which is the set of homotopy classes of maps from the $n$-sphere $S^n$ to a based space with a slightly more complicated but analogous concatenation law that induces a group operation.\r\n    Turns out, $\\pi_n$ is always abelian for $n>1$.\r\n    The problem, however, with this sort of groups is that they are hard to calculate.\r\n    Even $\\pi_n(S^m)$ for general $n,m$ are still unknown.\r\n    So they are not an effective algebraic invariant -- we need a different approach called homology (and cohomology).\r\n\\end{remark}", "meta": {"hexsha": "615a496b050aada417daf94cf2860f2de0adb243", "size": 25690, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/seifert.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": "3/seifert.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": "3/seifert.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": 65.5357142857, "max_line_length": 321, "alphanum_fraction": 0.6538341767, "num_tokens": 8938, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772417253256, "lm_q2_score": 0.8670357477770337, "lm_q1q2_score": 0.7578562148942047}}
{"text": "%\n% Chapter 2\n%\n\\chapter {Basics of Quantum Computing}\n\n\\section{Dirac Notation}\n\nAlso known as bra-ket notation, Dirac notation provides a convenient way of expressing the vectors used in quantum mechanics.\n\nDirac notation defines two elements:\n\n\\begin{itemize}\n    \\item The \\textit{ket} ($\\ket{\\psi}$), which denotes a column vector in a complex vector space that represents a quantum state.\n    $$\\ket{\\psi}=\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2} \\\\ \\cdots \\\\ \\psi_{n} \\end{array}\\right]$$\n    \\item The \\textit{bra} ($\\bra{\\psi}$), which denotes a row vector that is the conjugate transpose, or adjoint, of a corresponding \\textit{ket} ($\\ket{v}$).\n    $$\\bra{\\psi}=\\left[\\begin{array}{cccc}\\psi_{1}^{*} & \\psi_{2}^{*} & \\cdots & \\psi_{n}^{*}\\end{array}\\right]=\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2} \\\\ \\cdots \\\\ \\psi_{n} \\end{array}\\right]^{\\dagger}$$\n\\end{itemize}\n\nAn \\textit{operator} $\\bf{A}$, represented by a $n \\times n$ matrix, acting on a \\textit{ket} $\\ket{\\psi}$ produces another \\textit{ket} $\\ket{\\psi'}$ such that the produced \\textit{ket} can be computed by matrix multiplication:\n$$\\ket{\\psi'}=\\textbf{A}\\ket{\\psi}=\\left[\\begin{array}{cc}A_{11} & A_{12} \\\\ A_{21} & A_{22}\\end{array}\\right]\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2}\\end{array}\\right]=\\left[\\begin{array}{c}A_{11}\\psi_{1}+A_{12}\\psi_{2} \\\\ A_{21}\\psi_{1}+A_{22}\\psi_{2}\\end{array}\\right]$$\n\nThe \\textit{inner product} is denoted as a bra-ket pair $\\braket{\\phi}{\\psi}$ and represents the probability amplitude that a quantum state $\\psi$ would be subsequently found in state $\\phi$:\n$$\\braket{\\phi}{\\psi}=\\left[\\begin{array}{cc}\\phi_{1}^{*} & \\phi_{2}^{*} \\end{array}\\right]\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2} \\end{array}\\right]=\\phi_{1}^{*}\\psi_{1}+\\phi_{2}^{*}\\psi_{2}$$\n\nThis notation also provides a way to describe the state vector of $n$ uncorrelated quantum states, the \\textit{tensor product}:\n$$\\ket{\\phi}\\otimes\\ket{\\psi}=\\ket{\\phi}\\ket{\\psi}=\\ket{\\phi\\psi}=\\left[\\begin{array}{c}\\phi_{1} \\\\ \\phi_{2}\\end{array}\\right]\\otimes\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2}\\end{array}\\right]=\\left[\\begin{array}{c}\\phi_{1}\\psi_{1} \\\\ \\phi_{1}\\psi_{2} \\\\ \\phi_{2}\\psi_{1} \\\\ \\phi_{2}\\psi_{2}\\end{array}\\right]$$\n\nNote that $\\ket{\\psi}^{\\otimes n}$ represents the tensor product of $n$ $\\ket{\\psi}$ quantum states:\n$$\\ket{\\psi}^{\\otimes n}=\\ket{\\psi}\\otimes\\cdots\\otimes\\ket{\\psi}=\\ket{\\psi}\\cdots\\ket{\\psi}=\\ket{\\psi\\cdots\\psi}=\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2} \\end{array}\\right]\\otimes\\cdots\\otimes\\left[\\begin{array}{c}\\psi_{1} \\\\ \\psi_{2} \\end{array}\\right]$$\n\n\\section{Quantum Systems}\n\n\\todo{Explain the Schrodinger equation, describe what a quantum system is and mention basic postulates of quantum mechanics (similar to what Nielsen and Chuang explain).}\n\n\\todo{Add an introduction before explaining the postulates of quantum mechanics.}\n\nPostulate 1: The state of a physical system is fully described by a normalized vector $\\ket{\\psi}$ in Hilbert space.\n\nPostulate 2:\n\nPostulate 3:\n \nPostulate 4:\n\n\\todo{This is a good place to introduce the concept of coherence.}\n\n\\section{Qubits}\n\nIn classical information theory and classical computing, a bit is the fundamental building block.\nAnalogously, in quantum information theory and quantum computing, a quantum bit or qubit is the fundamental building block.\n\nPhysically, a quibit is a two-level quantum-mechanical system. The polarization of a single photon and the spin of the electron are examples of such systems.\n\nMathematically, a qubit is a linear combination of states $\\ket{\\psi}=\\alpha\\ket{0}+\\beta\\ket{1}$ where $\\alpha$ and $\\beta$ are complex numbers known as amplitudes, and $\\ket{0}$ and $\\ket{1}$ are the computational basis states.\n\nWhen a qubit is measured, the result is either $\\ket{0}$ with probability $|\\alpha|^2$ or $\\ket{1}$ with probability $|\\beta|^2$.\nSince the probabilities must sum to one, the qubit's state is normalized:\n$$|\\alpha|^2+|\\beta|^2=1$$\n\nThe computational basis states, which are analogous to the two values ($0$ and $1$) that a classical bit may take, form an orthonormal basis represented by the following vectors:\n$$\\ket{0}=\\left[\\begin{array}{c}1 \\\\ 0\\end{array}\\right]$$\n$$\\ket{1}=\\left[\\begin{array}{c}0 \\\\ 1\\end{array}\\right]$$\n\nUsing the previous definitions, we can see a qubit as a unit vector in two-dimensional complex vector space:\n\\[\\ket{\\psi}=\\left[\\begin{array}{c}\\alpha \\\\ \\beta\\end{array}\\right]\\]\n\n\\section{Multi-Qubit Systems}\n\n\\todo{Explain how multi-qubit systems are represented. Describe what a state vector is.}\n\n\\section{Superposition}\n\nThe principle of quantum superposition states that the most general state of a quantum-mechanical system is a linear combination of all distinct valid quantum states. A qubit is an example of a quantum superposition of the basis states $\\ket{0}$ and $\\ket{1}$.\n\nA concrete example of a qubit in superposition that has the same probability of being measured as $\\ket{0}$ or $\\ket{1}$ is the following:\n$$\\ket{\\psi}=\\frac{1}{\\sqrt{2}}\\left(\\ket{0}+\\ket{1}\\right)$$\n\n\\todo{Expand this section to show multi-qubit superposition.}\n\n\\section{Quantum Logic Gates}\n\nIn classical digital circuits, logic gates are the building blocks. Analogously, in the quantum circuit model of computation, quantum logic gates are the building blocks of quantum algorithms. Quantum gates act on qubits, transform them in different ways, and can be applied sequentially to perform complex quantum computations.\n\nQuantum gates are unitary operators represented as $2^n \\times 2^n$ unitary matrices where $n$ is the number of qubits the gate operates on. Unitary matrices are complex square matrices $\\bf{U}$ which have the property that its conjugate transpose or adjoint $\\bf{U^{\\dagger}}$ is also its inverse $\\bf{U^{-1}}$:\n$$\\bf{U^{\\dagger}U}=\\bf{UU^{\\dagger}}=\\bf{UU^{-1}}=I$$\n\nA quantum gate is applied to a qubit system by multiplying the gate's matrix representation by the qubits' state vector. This operation transforms the qubit system:\n$$\\ket{\\psi_1}=\\bf{U}\\ket{\\psi_0}$$\n\nApplying a sequence of quantum gates is equivalent to performing a series of these multiplications. For example, applying gate $\\bf{U_a}$ followed by a gate $\\bf{U_b}$ to a state vector $\\ket{\\psi}$ is represented by the follwing expression where the gates closest to the state vector are applied first:\n$$\\bf{U_b}\\bf{U_a}\\ket{\\psi}$$\n\nSince matrix multiplication is associative, multiplying $\\bf{U_a}$ by $\\bf{U_b}$ produces a compund gate $\\bf{U_{b}U_{a}}$ that is equivalent to applying $\\bf{U_a}$ followed by $\\bf{U_b}$:\n$$\\bf{U_b}\\bf{U_a}\\ket{\\psi}=\\bf{U_b}(\\bf{U_a}\\ket{\\psi})=(\\bf{U_b}\\bf{U_a})\\ket{\\psi}$$\n\nNote that all quantum gates are reversible since they are represented by unitary matrices. This means that for any gate, another gate exists that reverts the gate's transformation on a state vector:\n$$\\ket{\\psi}=\\bf{U^{\\dagger}}(\\bf{U}\\ket{\\psi})=\\bf{U^{\\dagger}}\\bf{U}\\ket{\\psi}=\\bf{I}\\ket{\\psi}$$\n\n\\todo{Describe and show how gates are represented in graphical circuits.}\n\n\\section{Single-Qubit Gates}\n\nSingle-qubit gates are represented by $2 \\times 2$ matrices.\n\n\\todo{List the most commonly used single-qubit gates and show how they transform a qubit.}\n\n\\section{Multi-Qubit Gates}\n\n\\todo{List the most commonly used multi-qubit gates and show how they transform the qubits they act upon.}\n\n\\section{Entanglement}\n\n\\todo{Define what entanglement is, describe why it is important, and show how qubits are entangled.}\n\n\\section{Interference}\n\n\\todo{Define what interference is, describe why it is important, and show an example of interference.}\n\n\\section{Measurement}\n\n\\todo{Define what it means to measure a qubit or a qubit system and show examples of measurements using different basis.}\n\n\\section{Quantum Advantage}\n\n\\todo{Explain how quantum computers can solve a problem that a classical computer can't efficiently by exploiting superposition, entanglement, and interference.}\n", "meta": {"hexsha": "658d09e7ee8d7826f367515c0fc9aaf3334618ad", "size": 7940, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/chapter02.tex", "max_stars_repo_name": "cesarzc/uw-master-in-physics-project", "max_stars_repo_head_hexsha": "2bdae208544595a6f65d5273e7462ffc70f7a694", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Thesis/chapter02.tex", "max_issues_repo_name": "cesarzc/uw-master-in-physics-project", "max_issues_repo_head_hexsha": "2bdae208544595a6f65d5273e7462ffc70f7a694", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Thesis/chapter02.tex", "max_forks_repo_name": "cesarzc/uw-master-in-physics-project", "max_forks_repo_head_hexsha": "2bdae208544595a6f65d5273e7462ffc70f7a694", "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.0158730159, "max_line_length": 328, "alphanum_fraction": 0.7231738035, "num_tokens": 2330, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8376199714402812, "lm_q1q2_score": 0.7577533510681252}}
{"text": "% Every Latex document starts with a documentclass command\n\\documentclass[a4paper, 11pt]{article}\n\n% Load some packages\n\\usepackage{graphicx} % This allows you to put figures in\n\\usepackage{natbib}   % This allows for relatively pain-free reference lists\n\\usepackage[left=3cm,top=3cm,right=3cm]{geometry} % The way I like the margins\n\\usepackage{dsfont}\n\\usepackage{amsmath}\n\n\n% This helps with figure placement\n\\renewcommand{\\topfraction}{0.85}\n\\renewcommand{\\textfraction}{0.1}\n\n% Set values so you can have a title\n\\title{New Paper}\n\\author{Me}\n\\date{\\today}\n\n\n\n% Document starts here\n\\begin{document}\n\n%% Actually put the title in\n%\\maketitle\n\n%\\abstract{This is the abstract}\n\n% Need this after the abstract\n\\setlength{\\parindent}{0pt}\n\\setlength{\\parskip}{8pt}\n\n\\section{Truncated Exponential Example}\nThis example is inspired by Steve Gull, via David MacKay.\nSuppose an astronomical transient\noccurs at time $t=0$, and has a brightness that\ndecays exponentially over time:\n\n\\begin{align}\n\\textnormal{Brightness}(t) &=\n\\left\\{\n\\begin{array}{lr}\nAe^{-\\frac{t}{L}}, & t \\geq 0\\\\\n0,                 & \\textnormal{otherwise}.\n\\end{array}\n\\right.\n\\end{align}\n\nSuppose we observe the object between times $t=t_{\\rm min}$ and\n$t=t_{\\rm max}$, and we want to know the value of $L$, but don't\nparticularly care about $A$. We observe $N$ photons, and their\narrival times $\\{t_1, t_2, ..., t_N\\}$.\nThe probability distribution for the arrival times\n$\\{t_i\\}$\ngiven $L$ (and $N$, which we consider to be prior information)\nis\n\\begin{align}\np(t_1, t_2, ..., t_N | L)\n&\\propto \\prod_{i=1}^N e^{-t_i/L}.\n\\end{align}\nThis is the probability distribution for the data given the\nparameters, which will give us the likelihood function once\nwe plug in the observed data. However, we need to normalise\nit first, as the observed photon arrival times must be between\n$t_{\\rm min}$ and $t_{\\rm max}$:\n\\begin{align}\np(t_1, t_2, ..., t_N | L)\n&= \\prod_{i=1}^N\n\\frac{e^{-t_i/L}}\n     {\\int_{t_{\\rm min}}^{t_{\\rm max}} e^{-t_i/L} dt_i}\\\\\n&= \\prod_{i=1}^N\n\\frac{e^{-t_i/L}}\n     {L\\left[e^{-t_{\\rm min}/L} - e^{-t_{\\rm max}/L}\\right]}\\\\\n&= L^{-N}\\left[e^{-t_{\\rm min}/L} - e^{-t_{\\rm max}/L}\\right]^{-N}\ne^{-\\frac{\\sum_{i=1}^N t_i}{L}}.\n\\end{align}\n\n\n\n\n\n\n\\bibliographystyle{plainnat}\n\\bibliography{references}{}\n\n\n\\end{document}\n\n", "meta": {"hexsha": "5ed5ff79a765a826349cdf1c24bf18f674f522ac", "size": 2307, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/truncated_exponential.tex", "max_stars_repo_name": "dhuppenkothen/mcmcfail", "max_stars_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tex/truncated_exponential.tex", "max_issues_repo_name": "dhuppenkothen/mcmcfail", "max_issues_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tex/truncated_exponential.tex", "max_forks_repo_name": "dhuppenkothen/mcmcfail", "max_forks_repo_head_hexsha": "d2f907082c26382564483a2c2fe86e30157b822c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.3516483516, "max_line_length": 78, "alphanum_fraction": 0.6896402254, "num_tokens": 753, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595163, "lm_q2_score": 0.8376199633332891, "lm_q1q2_score": 0.7577533437341306}}
{"text": "\\subsubsection{Toy Example}\r\n\\noindent\r\nSay we wish to maximize $f(x,y) = x+y$ subject to the constraint $g(x,y) = x^2 + y^2 = 1$. We can do this y finding the C-level curve that is tangent to our constraint, as this curve will have the extrema.\\\\\r\nAt this point, $\\nabla f$ will be in the same direction as $\\nabla g$. That is,\r\n\\begin{equation*}\r\n\t\\begin{cases} \r\n\t\tf_x = \\lambda g_x \\\\ \r\n\t\tf_y = \\lambda g_y\r\n\t\\end{cases}\t\r\n\\end{equation*}\r\nWe also add the constraint itself, $g(x,y) = k$, giving us a system of equations\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\tf_x = \\lambda g_x \\\\ \r\n\t\tf_y = \\lambda g_y \\\\ \r\n\t\tg(x,y)=k \r\n\t\\end{cases}\t\r\n\\end{equation*}\r\n\r\n[INSERT IMAGES]", "meta": {"hexsha": "d61194126110f95b015b7e89e9e0c8dd2c6d74c5", "size": 673, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/toyExample.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/toyExample.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/toyExample.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": 33.65, "max_line_length": 208, "alphanum_fraction": 0.6478454681, "num_tokens": 227, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505299595162, "lm_q2_score": 0.8376199592797929, "lm_q1q2_score": 0.7577533400671331}}
{"text": "\\section{Covariance Matrix}\nLet $X$  be a random vector of dimension $d \\times 1$ with expectation $\\mu _{X}$. \n\nMatrix outer products!\\\\ \n\n$\\Sigma =\\mathbb E[(X- \\mu _{X})(X- \\mu _{X})^ T] \\\\= \\mathbb {E}[XX^ T] - \\mathbb {E}[X]\\mathbb {E}[X]^ T\n\\\\= \\mathbb {E}[XX^ T] - \\mu _{X}\\mu _{X}^ T$", "meta": {"hexsha": "17a076273376fad0be60c1f232a6a450be969f00", "size": 292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/Covariance_Matrix.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/Covariance_Matrix.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/Covariance_Matrix.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": 41.7142857143, "max_line_length": 106, "alphanum_fraction": 0.5719178082, "num_tokens": 126, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9615338035725358, "lm_q2_score": 0.7879311981328135, "lm_q1q2_score": 0.7576224818941095}}
{"text": "\\sec{The Method of Undetermined Coefficients \\label{sec:undcoeff}}\n\\subsection{The first challenge} \\label{ssec:undcoeffhomo}\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tConsider a linear ODE of the form\n\t\\begin{equation}\\label{eq:const}\n\t\ty^{(n)} + a_{n-1}y^{(n - 1)} + \\cdots + a_0y = 0,\n\t\\end{equation}\n\twhere $a_0, \\ldots, a_{n-1}$ are constants. (Real or complex.)\\\\\n\tThis is a \\defin{constant coefficients ODE}.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Solving it}]\n\tWe plug the trial solution $y = e^{mx}.$ This gives us the polynomial equation:\n\t\\begin{equation}\\label{eq:char}\n\t\tm^n + a_{n-1}m^{n-1} + \\cdots + a_0 = 0\n\t\\end{equation}\n\tIf $m_1, \\ldots, m_n$ are \\emph{distinct} solutions to the above equation, then $e^{m_1x}, \\ldots, e^{m_nx}$ are $n$ linearly independent solutions of the ODE and thus, we are done.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Repeated roots}]\n\tSuppose $m_0$ is a repeated root of (\\ref{eq:char}). Suppose that it is repeated $k$ times. Then, one can show that the following $k$ functions are solutions of the original ODE:\n\t\\begin{equation*} \n\t\te^{m_0x}, xe^{m_0x}, \\ldots, x^{k-1}e^{m_0x}.\n\t\\end{equation*}\n\tThese are linearly independent as well.\\\\\n\tThus, we are now done for any case as the total number of roots is always going to be $n$ when counted with multiplicity. (This is assuming that we work in $\\mathbb{C},$ which we shall do.)\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Getting real}]\n\tSuppose we are in the case where each $a_i$ is real.\\\\\n\tIn this case, if $m = a + ib$ is a solution, then so is $m' = a - ib.$ Moreover, the ``amount of repetition'' will also be same.\\\\\n\tThus, we can replace solutions having $\\{e^{(a + ib)x}, e^{(a - ib)x}\\}$ with \\\\\n\t$\\{e^{ax}\\sin bx, e^{ax}\\cos bx\\}.$\\\\~\\\\\n\tSimilarly considerations apply to functions like $x^ke^{(a + ib)x}.$\n\\end{mdframed}\n\\exercise{%\nSolve the following ODEs.\n\\begin{enumerate}[leftmargin=*]\n\t\\item $y'' - 3y' + 2y = 0.$\n\t\\item $y^{(4)} + y = 0.$\n\t\\item $y^{(4)} + y^{(2)} + y = 0.$\n\\end{enumerate}}\n\\subsection{Annihilators}\nBefore going into the main problem, let us study annihilators. \\\\\nIn the following we shall use the following notation:\n\\begin{mdframed}[style=boxstyle, frametitle={Notation}]\n\tFrom here on, we shall write $D$ to mean $\\dfrac{d}{dx}.$\\\\\n\tSimilarly, we have $D^n = \\dfrac{d^n}{dx^n}.$ \\\\~\\\\\n\tNote that $D$ is an ``operator'' which ``acts'' on smooth\\footnote{Recall that a smooth function is a function that is infinitely differentiable.} functions to give another smooth function.\n\\end{mdframed}\n\t\n\\begin{mdframed}[style=boxstyle, frametitle={Some arithmetic}]\n\tThe operator follows the usual rules like $DD = D^2$ which is the same as saying\n\t\\begin{equation*} \n\t\t\\dfrac{d}{dx}\\left(\\dfrac{d}{dx}(f)\\right) = \\dfrac{d^2f}{dx^2}.\n\t\\end{equation*}\n\tWe also have things like\n\t\\begin{equation*} \n\t\t(D + 1)^2 = D^2 + 2D + 1.\n\t\\end{equation*}\n\tNote that the $1$ above is the operator $1,$ that is, $1f = f$ for any function $f.$\\\\\n\t(Don't make the mistake of thinking something like $D(D + 1) = D^2$ because $D1 = 0;$ the $1$ here is not the constant function.)\\\\\n\tThis also shows how the original ODE (\\ref{eq:const}) relates to the polynomial (\\ref{eq:char}). To make it clearer, note that the ODE can simply be written as\n\t\\begin{equation*} \n\t\t(D^n + a_{n-1}D^{n-1} + \\cdots + a_0)y = 0.\n\t\\end{equation*}\n\\end{mdframed}\n\\newpage\n\\begin{mdframed}[style=boxstyle, frametitle={Annihilators of special functions}]\n\tFrom the discussion in the previous section, we can already see annihilators of some special functions as follows:\n\t\\begin{center}\n\t\\bgroup\n\t\\def\\arraystretch{1.25}\n\t\\begin{tabular}{|l|l|}\n\t\t\\hline\n\t\tFunction & Annihilator\\\\\n\t\t\\hline\n\t\t$e^{mx}$ & $D - m$\\\\\n\t\t$x^{k}e^{mx}$ & $(D - m)^{k+1}$\\\\\n\t\t$\\sin bx, \\cos bx$ & $D^2 + b^2$\\\\\n\t\t$x^k\\sin bx, x^k\\cos bx$ & $(D^2 + b^2)^{k+1}$\\\\\n\t\t$e^{ax}\\sin bx, e^{ax}\\cos bx$ & $(D - a)^2 + b^2$\\\\\n\t\t$x^ke^{ax}\\sin bx, x^ke^{ax}\\cos bx$ & $((D - a)^2 + b^2)^{k+1}$\\\\\n\t\t\\hline\n\t\\end{tabular}\n\t\\egroup\n\t\\end{center}\n\\end{mdframed}\t\nNote that all the annihilators in the above table are polynomials in $D,$ we will usually write an arbitrary such operator as $P(D).$\\\\\nWith the above things in mind, we proceed to the next subsection. \n\n\\newpage\n\n\\subsection{The main problem}\n\\begin{mdframed}[style=boxstyle, frametitle={The Setup}]\n\tWe consider a linear ODE of the form\n\t\\begin{equation} \\label{eq:constQ}\n\t\t(D^n + a_{n-1}D^{n-1} + \\cdots + a_0)y = Q(x),\n\t\\end{equation}\n\twhere each $a_i$ is a constant and $Q(x)$ is one of the special functions listed in the table earlier.\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={The Solution}]\n\tWe do this quite systematically.\n\t\\begin{enumerate}[leftmargin=*, label = \\Roman*.]\n\t\t\\item First, we consider the associated homogeneous equation\n\t\t\\begin{equation*} \n\t\t\t(D^n + a_{n-1}D^{n-1} + \\cdots + a_0)y = 0.\n\t\t\\end{equation*}\n\t\tThis can be solved completely by the methods we saw in \\S\\S\\ref{ssec:undcoeffhomo}.\\\\\n\t\tLet the \\emph{general} solution of this be $y_g(x).$\n\t\t\\item As $Q(x)$ was a special function, we take its annihilator $P(D)$ from the table and apply it to both sides of (\\ref{eq:constQ}). This gives us an equation of the form\n\t\t\\begin{equation} \\label{eq:temp1}\n\t\t\tP(D)(D^n + a_{n-1}D^{n-1} + \\cdots + a_0)y = 0.\n\t\t\\end{equation}\n\t\tNote that (\\ref{eq:temp1}) is again a constant coefficients ODE (why? Recall the arithmetic.) and hence, we can solve it completely.\\\\\n\t\tLet this solution by $y_{g'}(x).$\n\t\t\\item This $y_{g'}$ will be a sum of special functions. It will have all $n$ of the original special functions in $y_g$ and $k$ more. ($k = \\deg P(D).$)\\\\\n\t\tThus,\n\t\t\\[y_{g'}(x) = y_g(x) + c_1y_1(x) + \\cdots + c_ky_k(x),\\]\n\t\twhere the $y_i$s are the $k$ new functions. We now solve for \\textbf{undetermined coefficients} $c_i$s by substituting the above solution back in (\\ref{eq:constQ}). (Note that $y_g$ will get completely annihilated and can be ignored for better calculations.)\\\\\n\t\tThus, once we solve for the $c_i$s, we are done and the final \\emph{general} solution is\n\t\t\\[y(x) = y_g(x) + c_1y_1(x) + \\cdots + c_ky_k(x).\\]\n\t\\end{enumerate}\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle, frametitle={Slightly more general}]\n\tNote that the original restriction that $Q(x)$ be a special function was unnecessary. Indeed, we can do better and allow $Q(x)$ to be a \\emph{linear combination} of the special functions.\\\\\n\tWe can solve the smaller equations individually and finally add them (with appropriate scaling) to get the final solution.\\\\\n\tTo be more explicit in terms of an example:\\\\\n\tConsider the ODE $(D^2 + 1)y = e^x + 2\\sin x.$\\\\\n\tWe shall first solve to get the general solution $y_g$ of $(D^2 + 1)y = 0.$\\\\\n\tThen, we get a particular solution $y_{p_1}$ of $(D^2 + 1)y = e^x$ using II and III from above.\\\\\n\tSimilarly, we get a particular solution $y_{p_2}$ of $(D^2 + 1)y = \\sin x.$\\\\ Then, the final solution is $y_g + y_{p_1} + 2y_{p_2}.$\n\\end{mdframed}\n\\begin{mdframed}[style=boxstyle2, frametitle={A note about calculations}]\n\tSometimes, it may be computationally easier to \\emph{not} break $Q(x)$ into all of its components.\\\\\n\tFor example, if $Q(x) = e^x + xe^x + e^{2x},$ it would be better to break the problem into that for $(e^x + xe^x)$ and that for $e^{2x}.$\\\\\n\tThe reason for this is that $(D - 1)^2$ is an annihilator for the former and would minimise repeated calculations.\\\\\n\t(Try some problems yourself, it's easier to just do it and realise what's best!)\n\\end{mdframed}", "meta": {"hexsha": "87b9b6d663dbe67bddfb6996062de25551c73216", "size": 7543, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tuts/ma-108/summary/undetcoeff.tex", "max_stars_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_stars_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2020-12-17T20:34:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-10T09:58:57.000Z", "max_issues_repo_path": "tuts/ma-108/summary/undetcoeff.tex", "max_issues_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_issues_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-03-04T10:23:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-28T10:29:01.000Z", "max_forks_repo_path": "tuts/ma-108/summary/undetcoeff.tex", "max_forks_repo_name": "siddhanttripathy/siddhanttripathy.github.io", "max_forks_repo_head_hexsha": "aa22ff5a198e9ede5d07001384fda67a4606f8ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 26, "max_forks_repo_forks_event_min_datetime": "2019-08-30T18:19:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-17T12:09:09.000Z", "avg_line_length": 55.4632352941, "max_line_length": 262, "alphanum_fraction": 0.6789075964, "num_tokens": 2658, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916134888614, "lm_q2_score": 0.8774767874818408, "lm_q1q2_score": 0.7576060993429692}}
{"text": "\n\\documentclass{article}\n\n% Importing settings from our file \"setup.sty\"\n\\usepackage{setup}\n\n% Beginning of document\n\\begin{document}\n\n% Inserting title page\n\\import{./}{title}\n\n% Defining front matter settings \n\\frontmatter\n\n% Inserting table of contents\n\\tableofcontents\n\n\n% Defining main matter settings \n\\mainmatter\n\n\\section{Number Theory}\n\n\\subsection{Euclidian algorithm}\n\n\\subsubsection{Normal}\n\nGoal is to find $d = gcd(a,b)$.\\\\\n$a = bq_1 + r_1$\\\\\n$b = r_1 q_2 + r_2$\\\\\n...\\\\\n$r_{k-1} = r_k q_{k+1}, r_{k+1}=0$\\\\\n$d = r_k = gcd(a,b)$.\n\n\\subsubsection{Extended}\n\nProceeds similarly, but adds sequences $(s_k)$ and $(t_k)$.\\\\\n$r_0 = a, r_1 = b$\\\\\n$s_0 = 1, s_1 = 0$\\\\\n$t_0 = 0, t_1 = 1$\\\\\n...\\\\\n$r_{i+1} = r_{i-1} - q_i r_i, 0 \\leq r_{i+1} < \\vert r_i \\vert$\\\\\n$s_{i+1} = s_{i-1} - q_i s_i$\\\\\n$t_{i+1} = t_{i-1} - q_i t_i$\\\\\nThe computation stops when $r_{k+1} = 0$ and gives:\n\\begin{itemize}\n    \\item $r_k = gcd(a,b)$\n    \\item $gcd(a,b) = r_k = a s_k + b t_k$\n    \\item $s_{k+1} = \\pm \\frac{b}{gcd(a,b)}$ and $t_{k+1} = \\pm \\frac{a}{gcd(a,b)}$\n\\end{itemize}\n\n\\subsection{Groups and fields}\n\n\\subsubsection{Groups}\n\nA group is a set $G$ with binary operation $\\cdot$ satisfying:\n\\begin{itemize}\n    \\item Closure: $a \\cdot b \\in G \\hspace{0.3cm} \\forall a,b \\in G$\n    \\item Identity: $\\exists 1$\n    \\item Inverse: $\\forall a \\in G, \\exists b $ s.t. $a\\cdot b = 1$\n    \\item Associative: $\\forall a,b,c \\in G, (a\\cdot b)\\cdot c = a\\cdot (b\\cdot c)$\n\\end{itemize}\nGroups can be commutative: $\\forall a,b \\in G, a\\cdot b = b\\cdot a$.\n\n\\textbf{Cyclic groups}\n\nThe order of a group $G$ is $\\vert G \\vert =$ nb of elements in $G$.\\\\\nThe order of an element $g \\in G$ is $\\vert g \\vert =$ smallest integer k s.t. $g^k = 1$.\\\\\nAn element $g$ is a generator for $G$ if $\\vert g \\vert = \\vert G \\vert$.\\\\\nA group is cyclic if it has a generator.\n\n\\subsubsection{$\\mathbb{Z}^*_p$}\n\nComplete set of residues modulo any prime p with 0 removed forms a group under multiplication.\\\\\nProperties:\n\\begin{itemize}\n    \\item $\\vert \\mathbb{Z}^*_p \\vert = p-1$\n    \\item $\\mathbb{Z}^*_p$ is cyclic\n    \\item $\\mathbb{Z}^*_p$ has many generators in general\n\\end{itemize}\n\n\\textbf{Finding a generator}\n\nChoose a value $g$ and test it as follows:\n\\begin{enumerate}\n    \\item Compute distinct prime factors of p-1 and call them $f_1, ..., f_r$\n    \\item $g$ is a generator as long as $g^{(p-1)/f_i} \\neq 1 $ mod $p \\hspace{0.3cm}\\forall i=1,2,...,r$ \n\\end{enumerate}\n\n\\subsubsection{$\\mathbb{Z}^*_n$}\n\nFor any n, prime or not, we can define $\\mathbb{Z}^*_n$ to be the group of residues which have an inverse under multiplication.\\\\\nThis is a group but generally not cyclic.\\\\\nFinding the order is difficult in general.\n\n\\subsubsection{Fields}\n\nSet $F$ with 2 binary operations $+$ and $\\cdot$ satisfying:\n\\begin{itemize}\n    \\item $F$ is commutative under $+$ with an identity element denoted $0$\n    \\item $F \\setminus \\{0\\}$ is a commutative group under $\\cdot$\n    \\item Distributive: $\\forall a,b,c \\in F, a\\cdot (b+c)= (a \\cdot b)+(a \\cdot c)$\n\\end{itemize}\n\n\\textbf{Finite Fields}\n\nFor secure communications we are usually only interested in fields with a finite number of elements.\\\\\nTheorem: finite fields exist of size $p^n$ for any prime $p$ and positive int $n$ and that no finite field exists of other size.\\\\\n\n\\textbf{Finite field GF(p)}\n\n$GF(p) = \\mathbb{Z}_p$\\\\\nMultiplication/addition are done modulo p.\\\\\nMultiplicative group is exactly $\\mathbb{Z}^*_p$.\n\n\\textbf{Finite field GF(2)}\n\nOnly 2 elements. Addition is binary addition modulo 2 (same as XOR).\\\\\nXOR is often used in cryptography, written $\\oplus$. For example, $101 \\oplus 011 = 110$.\n\n\\textbf{Finite field GF($2^n$)}\n\nArithmetic in these fields can be considered as polynomial arithmetic where the field elements are polynomials with binary coefficients.\\\\\nWe can equate any n-bit string with a polynomial: $00101101 \\leftrightarrow x^5+x^3+x^2+1$.\nGF($2^8$) is used for calculations in AES block cipher. To add 2 strings we add their coefficients modulo 2. Multiplication is done with respect to a generator polynomial which for AES is chose as $m(x)=x^8+x^4+x^3+x+1$. To multiply 2 strings we multiply them as polynomials and take their remainder after dividing by $m(x)$.\n\n\\subsection{Booleans}\n\nTakes value 0 or 1, reprensenting true or false.\\\\\nBoolean function maps to the set $\\{0,1\\}$.\\\\\nOperations:\n\\begin{itemize}\n    \\item logical AND\n    \\item logical OR\n    \\item negation NOT\n\\end{itemize}\n\n\\newpage \\section{Classical encryption}\n\n\\subsection{Cryptosystem}\n\nConsists of:\n\\begin{itemize}\n    \\item Set of plaintexts\n    \\item Set of ciphertexts\n    \\item Set of keys\n    \\item Function which transforms plaintext into ciphertext (encryption)\n    \\item Inverse function which transforms ciphertext into plaintext\n\\end{itemize}\nThe encrypted message is the ciphertext, sometimes called cryptogram.\n\n\\subsection{(A)symmetric cryptography}\n\n\\subsubsection{Symmetric}\n\nEncryption/decryption keys only known to sender and receiver.\\\\\nRequires secure channel for transmission of key.\\\\\nEncryption: $Y=E(K,X)$, where E is encryption function, X is plaintext, Y is ciphertext and K is shared secret key.\\\\\nDecryption: $X=D(K,Y)$, where D is decryption function.\n\n\\subsubsection{Asymmetric, public key}\n\nEach participant has private and public key.\n\n\\subsection{Cryptanalysis}\n\n\\subsubsection{Exhaustive key search}\n\nAlso called brute-force attack, any possible key is tried.\\\\\nDefense: have enough possible keys to make it computationally impossible.\n\n\\subsubsection{Attack classification}\n\n\\begin{itemize}\n    \\item Ciphertext only\n    \\item Known plaintext: attacker has some plaintext and the corresponding ciphertext.\n    \\item Chosen plaintext: attacker can obtain the ciphertext equivalent of some plaintext which can be selected by the attacker; i.e. the attacker has an “inside encryptor” available\n    \\item Chosen ciphertext: attacker can obtain the plaintext equivalent of some ciphertext which can be selected by the attacker; i.e. the attacker has an “inside decryptor” available\n\\end{itemize}\n\nModern standard: system should be secure against chosen plaintext and chosen ciphertext.\n\n\\subsubsection{Kerckhoffs' principle}\n\nAttacker has full knowledge of how the system works. Decryption key is the only thing missing.\n\n\\subsubsection{Transposition cipher}\n\nKey: pair $d$ and $f$.\\\\\nEach block of $d$ characters is re-ordered using permutation $f$.\\\\\n$d!$ permutations of length $d$.\\\\\n\n\\textbf{Cryptanalysing}\n\nFrequency distribution of the ciphertext characters is same as for the plaintext characters.\\\\\nIf d is small, you can find permutation using process of anagramming. Write ciphertext in columns so that there are $d$ colums and rearrange them to try and form words.\n\n\\subsubsection{Simple substitution cipher}\n\nUse of a substitution table to replace plaintext characters.\n\n\\textbf{Caesar}\n\nMoves the $i$th letter of an alphabet to the ($i+j$)th letter. Key is value $j$.\\\\\nExample: $j=1$ gives CIPHER $\\mapsto$ DJQIFS.\\\\\nCryptanalysis: find out where one of the most frequent characters is shifted to. \n\n\\textbf{Random simple substitution}\n\nRandom table mapping from alphabet to alphabet. If alphabet has 26 characters, there are $26!$ keys.\\\\\nCryptanalysis: Use frequency analysis on characters of the ciphertext and compare with frequency of characters in English (or other language).\n\n\\subsubsection{Polyalphabetic substitution}\n\nUses multiple mappings from plaintext to ciphertext: smoothes the frequency distribution so direct frequency analysis is no longer effective.\\\\\nGiven $d$ ciphertext alphabets $C_0, C_1, ..., C_{d-1}$, let $f_i: A \\rightarrow C_i$ be a mapping from the plaintext alphabet A to the $i$th cipher alphabet $C_i$.\\\\\nMessage $M = m_0 ... m_{d-1} m_d ... m_{2d-1} ...$ is enciphered to $E(K,M) = f_0 (m_0) --- f_{d-1} (m_{d-1}) f_0(m_d) ... f_{d-1} (m_{2d-1}) ...$\\\\\nKey generation: select block length $d$, generate $d$ random simple substitution tables.\\\\\nEncryption: to encrypt $i$th character, user substitution table number $j$ where $i = j mod d$.\\\\\nDecryption: same as encryption.\n\n\\subsubsection{Vigenère cipher}\n\nPopular form of periodic substitution cipher based on shifted alphabets.\\\\\nKey: sequence of characters $K=k_0 ... k_{d-1}$ where $k_i (i=0,...,d-1)$ gives the amount of shift in the $i$th alphabet, i.e. $f_i (p)= (p+k_i)$ mod $n$ where $p$ is the plaintext character.\\\\\nExample: M=AT$\\nabla$THE$\\nabla$TIME, K=LOCK $\\leftarrow$ E(K,M)=LGBCSSBCT$\\nabla$G, where $\\nabla$ is the whitespace character and A=0, B=1, ..., Z=25 and $\\nabla$=26.\n\n\\textbf{Cryptanalysis}\n\n\\begin{enumerate}\n    \\item Identify period length: Kasiski method, autocorrelation (Cryptool online), index of coincidence (JCryptool and Cyberchef)\n    \\item Attack separately $d$ different substitution tables. Since each substitution is just a shift (Caesar cipher), this is straightforward if there is sufficient ciphertext.\n\\end{enumerate}\n\n\\url{https://www.cryptool.org/en/cto/vigenerebreak}\n\n\n\\subsubsection{Affine cipher}\n\nHas the form $c_i=a p_i + b$ mod $n$ where $p_i, c_i$ are the plaintext, ciphertext characters respectively and $a, b$ are fixed constants.\n\n\\textbf{Cryptanalysis}\n\nNotice that this cipher is a substitution cipher - each plaintext character is always substituted with the same ciphertext character.  Therefore the plaintext and ciphertext statistics can be matched up to identify probable matches  between  plaintext  and  ciphertext  characters.   With  two  matches $(p_1, c_1)$ and $(p_2, c_2)$ we  have  two equations in two unknowns which can be solved to retrieve $a$ and $b$. If $c_1 = a p_1 + b$ mod $n$ and $c_2 = a p_2 + b$ mod $n$ then $a= (c_1 - c_2)(p_1 - p_2)^{-1}$ mod $n$ and $b=c_1 - a p_1$. If we are unlucky and $p_1 - p_2$ is not invertible then other pairs need to be tried.\n\n\\newpage \\section{Hill Cipher, Stream Ciphers and the One Time Pad}\n\n\\subsection{Hill Cipher}\n\n\\subsubsection{Definition and example}\n\nPerforms linear transformation on $d$ plaintext characters to get $d$vciphertext characters.\\\\\nEncryption involves multiplying $d$x$d$ matrix $K$ by the block of plaintext $P$: $C= KP$.\\\\\nDecryption: $P = K^{-1} C$.\n\n$d = 2$, $ K = \\begin{pmatrix}\n4 & 5\\\\\n1 & 7\n\\end{pmatrix}$, $K^{-1} = \\begin{pmatrix}\n15 & 19\\\\\n9 & 16\n\\end{pmatrix}$\\\\\nPlaintext: $(BC) \\rightarrow P = \\begin{pmatrix}\n1\\\\\n2\n\\end{pmatrix}$\\\\\nEncryption: $C = KP = \\begin{pmatrix}\n14\\\\\n15\n\\end{pmatrix} \\rightarrow (OP)$\\\\\nDecryption: $P = K^{-1}C = \\begin{pmatrix}\n1\\\\\n2\n\\end{pmatrix} \\rightarrow (BC)$\\\\\n\n\\subsubsection{Cryptanalysis}\n\nKnown plaintext attack is possible given $d$ plaintext-ciphertext matching blocks.\\\\\nSuppose we are given blocks (column vectors) $P_i, C_i$ for $i=0,1,...,d-1$. With $C=[C_0 C_1 ... C_{d-1} ], P = [P_0 P_1 ... P_{d-1} ]$, we can solve $C=KP$ for $K$ and compute $P = K^{-1}C$.\n\n\\url{https://www.dcode.fr/chiffre-hill}\n\n\n\\subsection{Stream ciphers}\n\nGeneration of a keystream of any required length. Each element of the keystream is used successively to encrypt one or more ciphertext characters. Stream ciphers are usually symmetric key ciphers: sender and receiver share the same key and can generate the same keystream given the same initialisation value. The keystream must have good randomness properties.\\\\\n\n\\subsubsection{Synchronous}\n\nKeystream generated independantly of the plaintext.\n\n\\subsubsection{Binary synchronous}\n\nFor each time interval $t$ each of the following are defined:\n\\begin{itemize}\n    \\item binary sequence $s(t)$ called keystream\n    \\item binary plaintext $p(t)$\n    \\item binary ciphertext $c(t)$\n\\end{itemize}\nEncryption: $c(t) = p(t) \\oplus s(t)$\\\\\nDecryption: $p(t) = c(t) \\oplus s(t)$\\\\\n\n\\subsection{One-time pad}\n\nKey = truly random sequence of characters, each characters used once only. Binary OTP is a (non-periodic) binary synchronous stream cipher. \\\\\nProvides perfect secrecy.\n\n\\subsubsection{Vernam (binary) OTP}\n\nPlaintext: binary sequence $b_1, b_2, ..., b_r$\\\\\nKeystream: random binary sequence $k_1, ..., k_r$++\nEncryption: $c_i = p_i \\oplus k_i$\\\\\nDecryption: $p_i = c_i \\oplus k_i$\\\\\nKeystream is same length as plaintext.\n\n\\subsubsection{Properties}\n\nAny cipher with perfect secrecy must have as many keys as there are message. This means OTP is only unbreakable cipher.\\\\\nMain prblem: how to deal with key management of completely random keys.\\\\\n\n\\subsubsection{Visual cryptography}\n\n\\textbf{Encrypting}\n\nTo encrypt image $I$, first generate otp $P$ (random string of bits) with length equal to number of pixels of $I$.\\\\\nGenerate image share $S_1$ by replacing each bit in P using sub-pixel pattern shown in next figure.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.65]{Images/subpixelpattern.png}\n\\label{fig:subpixel}\n\\caption{Sub-pixel pattern to generate image share $S_1$.}\n\\end{figure}\nGenerate the other image share $S_2$ with pixels as follows: same as $S_1$ for all the white pixels of $I$, the opposite (other sub-pixel pattern) of $S_1$ for all the black pixels of $I$.\n\n\\textbf{Decrypting}\n\nTo reveal hidden image the two shares are overlayed. Each black pixel of $I$ is black in the overlay, each white pixel of $I$ is half white in overlay.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.45]{Images/overlay.png}\n\\label{fig:subpixel}\n\\caption{Overlay of the two image shares.}\n\\end{figure}\n\n\n\\newpage \\section{Block Ciphers}\n\nBlock ciphers are the main bulk encryption algorithms used in commercial applications.\\\\\nStandardised block cipher AES and legacy cipher DES are widely deployed in real applications.\n\n\\subsection{Principles}\n\nSymmetric key ciphers in which each block of plaintext is encrypted with the same key.\\\\\nA block is a set of plaintext symbols of fixed size (typical: 64 to 256 bits).\\\\\nTwo important techniques: confusion (involves substitution to make relationship between the key and ciphertext as complex as possible) and diffusion (involves transformations that dissipate the statistical properties of the plaintext across the ciphertext). \\\\\n\n\\subsubsection{Product cipher}\n\nSystem in which the encryption function is formed by applying (or composing) several sub-encryption functions: composition of simple functions $f_i$ for $i=1,..., r$ where each $f_i$ has a different key $K_i$.\\\\\n$C = E(P,K) = f_r (...(f_2(f_1(P,K_1),K_2)...),K_r)$\n\n\\subsubsection{Iterated cipher}\n\nEncryption process dividen into $r$ similar rounds. Sub-encryption functions are all the same function $g$ (round function). Each key $K_i$ is derived from overall master key $K$ using a process called key schedule.\\\\\n\n\\textbf{Encryption}\n\n$W_0 = P$\\\\\n$W_1 = g(W_0, K_1)$\\\\\n$W_2 = g(W_1, K_2)$\\\\\n...\\\\\n$C = W_r = g(W_{t-1}, K_r)$.\n\n\\textbf{Decrypting}\n\n$g$ must have inverse $g^{-1}$ with $g^{-1}(g(W,K_i)-K_i) = W$. Decryption is then the reverse of encryption:\n$W_r = C$\\\\\n$W_{r-1} = g^{-1}(W_r,K_r)$\\\\\n$W_{r-2} = g^{-1}(W_{r-1},K_{r-1})$\\\\\n...\n$P = W_0 = g^{-1}(W_1,K_1)$\\\\\n\n\\subsubsection{Iterated cipher: Feistel cipher (DES)}\n\n\\textbf{Encryption}\n\n\\begin{enumerate}\n    \\item Split $P = W_0$ in 2 halves $W_0 = (L_0, R_0)$\n    \\item For each of the $r$ rounds perform: $L_i = R_{i-1}$, $R_i = L_{i-1} \\oplus f(R_{i-1}, K_i)$\n    \\item $C = W_r$ is defined by $C = (L_r, R_r)$\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.55]{Images/feistelladder.png}\n\\label{fig:feistelladder}\n\\caption{Feistel ladder diagram.}\n\\end{figure}\n\n\\textbf{Decryption}\n\n\\begin{enumerate}\n    \\item $C = (L_r, R_r)$\n    \\item For each of the $r$ rounds perform: $L_{i-1} = R_{i} \\oplus f(L_i, K_i)$, $R_{i-1} = L_{i}$\n    \\item $P = (L_0, R_0)$\n\\end{enumerate}\n\nWe never have to invert $f$ so we can always decrypt for any function $f$. Choice of $f$ is still important as it is the only non-linear part of the encryption function.\n\n\\subsubsection{Iterated cipher: Substitution-Permutation Networks (AES)}\n\nBlock length $n$ must allow each block to be split into $m$ sub-blocks of length $l$ so that $n=lm$. 2 permutations are defined.\\\\\nPermutation $\\Pi_S$ operates on sub-blocks of size $l$ bits: $\\Pi_S: \\{0,1\\}^l \\rightarrow \\{0,1\\}^l$\\\\\nPermutation $\\Pi_P$ swaps the inputs from $\\{1,...,n\\}$: $\\Pi_P: \\{1,...,n\\} \\rightarrow \\{1,...,n\\}$\n\n\\textbf{Steps in SPN round function}\n\n\\begin{enumerate}\n    \\item Round key $K_i$ is XORd with the current state block $W_i$\n    \\item Each sub-block is substituted by application of $\\Pi_S$\n    \\item Whole block is permuted using $\\Pi_P$\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.55]{Images/spnnetwork.png}\n\\label{fig:spnnetwoek}\n\\caption{SPN network.}\n\\end{figure}\n\n\\subsubsection{Differential and linear cryptanalysis}\n\nDifferential cryptanalysis is a chosen plaintex attack based on the idea that the difference between 2 input plaintexts can be correlated to the difference between two output cyphertexts.\\\\\nLinear cryptanalysis is a known plaintext attack (can theoretically be used to break DES).\n\n\\subsubsection{Avalanche effects}\n\nGood block ciphers should have avalanche effects with respect to both key and plaintext.\\\\\nKey avalanche: small change in key (with same plaintext) should result in large change in resulting ciphertext. Shannon's notion of confusion.\\\\\nPlaintext avalanche: small change in plaintext should result in large change in resulting ciphertext. Shannon's notion of diffusion.\n\n\\subsection{Data Encryption Standard (DES)}\n\nDES is a 16-round Feistel cipher with key length of 56 bits and data block length of 64 bits.\n\n\\subsubsection{Encryption}\n\nAn input block of 64 bits denoted by $P$.\n\n\\begin{enumerate}\n    \\item The 64 bits of $P$ are permuted according to an initial fixed permutation, denoted by $IP$.\n    \\item 16 rounds of a Feistel operation are applied, denoted by function$f$. A different 48 bit subkey is used for each round.\n    \\item A final fixed inverse permutation denoted by $IP^{-1}$ is applied.\n\\end{enumerate}\n\nFor each round the following steps are followed:\n\\begin{enumerate}\n    \\item Expand 32 bits to 48 bits\n    \\item Bitwise modulo two add 48 bits to 48 bit subkey\n    \\item Break 48 bits into 8 blocks of 6 bits each\n    \\item Put block $i$ into substitution table $i$ resulting in blobk of length 4\n    \\item Apply permutation to resulting 32 bits\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/feistelround.png}\n\\label{fig:fround}\n\\caption{Feistel $f$ function used in DES.}\n\\end{figure}\n\n\\subsubsection{Key schedule}\n\nEach of the sixteen rounds involves 48 bits of the 56 bitkey.Each 48-bit subkey is defined by a series of permutations and shifts on the full 56-bit key.\n\n\\subsubsection{Brute force attack}\n\nA brute force attack on a block cipher consists of testing all possible $2^k$ keys in order to find the key K.\\\\\nThe right key can be identified by using a small number of ciphertext blocks, or by looking for low entropy in the decrypted plaintext.\\\\\nIn the case of DES there are $2^{56}$ keys to test so, on average, it would take $2^{55}$ trial samples to find the right key.\\\\\nShort size of key is criticized.\n\n\\subsubsection{Double encryption}\n\nWith $K_1$ and $K_2$ two keys of the block cipher, defined by $C = E(E(P,K_1),K_2)$.\\\\\nIf key length of the original block cipher is $k$ then exhaustive key attack requires $2^{2k-1}$ trials on average.\n\n\\textbf{Meet-in-the-middle attack}\n\nSuppose we have ciphertext/plaintext (P,C) satisfying $C = E(E(P,K_1),K_2)$.\n\\begin{enumerate}\n    \\item For each key, store $C' = E(P,K)$ in memory\n    \\item Check if $D(C,K')=C'$ for any key $K'$\n    \\item K from step 1 is $K_1$ and $K'$ from step 2 is $K_2$\n    \\item Check if key values in step 3 work for other (P,C) pairs\n\\end{enumerate}\nRequires storage of one plaintext block for every possible key, a single encryption for every key and a single decryption for every key.\\\\\nApplied to DES, this would require storage of $2^{56}$ 64-bit blocks, $2^{56}$ encryption operations and $2^{56}$ decryption operations. Expensive but much easier than brute-force search through $2^{111}$ keys.\n\n\\subsubsection{Triple encryption}\n\nMuch better security.\\\\\n3 keys $K_1, K_2, K_3$ are used. Encryption defined by $C = E(E(E(P,K_1),K_2),K_3)$.\\\\\nSecure from meet-in-the-middle attack.\n\n\\subsubsection{Standardised options}\n\n\\begin{enumerate}\n    \\item Three independent keys, the most secure. Allowed until 2023 (after that only for legacy)\n    \\item Two keys with $K_1 = K_3$, still secure enough (only for legacy).\n    \\item One key with $K_1 = K_2 = K_3$, backward-compatible but vulnerable to brute-force.\n\\end{enumerate}\n\n\\subsection{Advanced Encryption Standard (AES)}\n\nDue to controversy over DES, AES was designed.\\\\\n\n\\subsubsection{Overview}\n\nSymmetric block key cipher.\\\\\n128-bit data block; 128-, 192- or 256-bit master key.\\\\\nNumber of rounds, NR, is 10, 12 or 14 (for 128-, 192-,256-bit keys).\\\\\nByte-based design.\\\\\nStructure is essentially a substitution-permutation network: initial round key addition, NR-1 rounds, final round.\n\n\\subsubsection{Round transformation}\n\nFour basic operations: ByteSub (non-linear substitution), ShiftRow (permutation), MixColumn (diffusion), AddRoundKey.\\\\\nEssentially a SPN with $n=128$ and $l=8$.\nS-box is look-up table but mathematically defined in $GF(2^8)$.\n\n\\subsubsection{Key schedule}\n\nMaster key input is 128 bits (or 192 or 256).\\\\\nEach of the 10 (or 12 or 14) encryption/decryption rounds uses a 128-bit subkey.\\\\\nNumber of subkeys required is one for each round (10 or 12 or 14) plus an initial subkey.\\\\\n\n\\subsubsection{Security}\n\nSome cracks but no significant breaks.\\\\\nAttacks exist on reduced-round versions.\\\\\nRelated key attacks exist. Such attacks require the attacker to obtain ciphertext encrypted with a key related to the actual key in a specified way.\\\\\nMost serious real attack so far reduces effective key size by around 2 bits.\n\n\\subsection{DES/AES comparison}\n\n\\begin{itemize}\n    \\item Data block size: DES: 64 bits; AES: 128 bits\n    \\item Key size: DES: 56 bits; AES: 128, 192 or 256 bits\n    \\item Design structure: DES: Feistel, bit-based; AES: SPN, byte-based, AES faster in both hardware and software\n\\end{itemize}\n\nAES is the choice of today fut triple-DES is still in use in older applications.\n\n\n\\newpage \\section{Modes of Operation and Random Numbers}\n\n\\subsection{Motivation}\n\n\\subsubsection{Why different modes ?}\n\nModes can provide confidentiality or authentication (and integrity) or both.\\\\\nSome modes can be used to generate pseudo-random numbers.\n\n\\subsubsection{Importance of randomised encryption}\n\nProblem when same plaintext block is always encrypted to same ciphertext block. \\\\\nRandomised encryption schemes can prevent this.\\\\\nUse of initialisation vector IV (unique or random).\\\\\nOR: include variable state which is updated with each block.\n\n\\subsection{Features}\n\n\\begin{itemize}\n    \\item Efficiency: some modes allow parallel processing (while encrypting or decrypting). Some modes result in error propagation (one bit error in ciphertext results in multiple bits error in decrypted plaintext).\n    \\item Padding: some modes (ex. ECB, CBC) require plaintext to consist of 1+ blocks. Padding method: append single '1' and pad with enough '0' to complete the last block. Alternative: ciphertext stealing.\n\\end{itemize}\n\n\\subsection{Electronic Code Book (ECB) mode}\n\nEncryption: $C_t = E(P_t, K)$. Blocks sent are $C_1, ..., C_n$.\\\\\nDecryption: $P_t = D(C_t, K)$. Blocks received are $C_1, ..., C_n$.\\\\\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/ecbencryption.png}\n\\label{fig:fround}\n\\caption{ECB mode encryption.}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/ecbdecryption.png}\n\\label{fig:fround}\n\\caption{ECB mode decryption.}\n\\end{figure}\n\n\\subsubsection{Properties}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | } \n\\hline\nRandomised & no \\\\\n\\hline\nPadding & Required \\\\ \n\\hline\nError propagation & Error propagates within blocks \\\\ \n\\hline\nIV & None \\\\ \n\\hline\nParallel encryption & Yes \\\\ \n\\hline\nParallel decryption & Yes \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nDeterministic: not normally used for bulk encryption.\n\n\\subsubsection{Ciphertext stealing}\n\nSuppose we want to encrypt more than one block of random bits using ECB mode with a block cipher, but without padding. This can be achieved with a technique known as ciphertext stealing.For example, suppose we encrypt a 200-bit random key using AES in ECB mode with key K.The plaintext is two blocks $M_1, M_2$ where $M_2$ is a 72-bit 'short' block.\n\nThen we compute\n\\begin{center}\n    $C_2 \\Vert J = E(M_1, K)$\\\\\n    $C_1 = E(M2 \\Vert J, K)$\n\\end{center}\nand send $(C_1, C_2)$ to the receiver. Here $J$ is a 56 bit random value which is never transmitted.\n\nTo decrypt we compute:\n\\begin{center}\n    $D(C_1, K) = M_2 \\Vert J$\\\\\n    $D(C_2 \\Vert J, K) = M_1$\n\\end{center}\n\n\\subsection{Cipher Block Chaining (CBC) mode}\n\nRandom IV is chosen and sent together with ciphertext blocks.\\\\\nEncryption: $C_t = E(P_t \\oplus C_{t-1}, K)$, where $C_0 = IV$. Blocks sent are $IV, C_1, ..., C_n$.\\\\\nDecryption: $P_t = D(C_t, K) \\oplus C_{t-1}$, where $C_0 = IV$. Blocks received are $IV, C_1, ..., C_n$.\\\\\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/cbcencryption.png}\n\\label{fig:fround}\n\\caption{CBC mode encryption.}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/cbcdecryption.png}\n\\label{fig:fround}\n\\caption{CBC mode decryption.}\n\\end{figure}\n\n\\subsubsection{Error propagation}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/cbcerrorpropagation.png}\n\\label{fig:fround}\n\\caption{CBC error propagation.}\n\\end{figure}\n\n\\subsubsection{Properties}\n\n\\begin{center}\n\\begin{tabular}{ | c | p{5cm} | } \n\\hline\nRandomised & Yes \\\\\n\\hline\nPadding & Required \\\\ \n\\hline\nError propagation & Error propagates within blocks and into specific bits of next block \\\\ \n\\hline\nIV & Must be random \\\\ \n\\hline\nParallel encryption & No \\\\ \n\\hline\nParallel decryption & Yes \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nCommonly used for bulk encryption.\\\\\nCommon choice for channel protection in all versions of TLS up to TLS 1.2.\n\n\\subsection{Counter (CTR) mode}\n\nCTR is asynchronous stream cipher. The keystream is generated by encrypting successive values of a \"counter\", initialised using a nonce (randomly chosen value) $N$: $O_t = E(T_t, K)$, where $T_t = N \\vert \\vert t$ is the concatenation of the nonce and the block number $t$.\\\\\nEncryption: $C_t = O_t \\oplus P_t$. Blocks sent are $C_1, ..., C_n$ and Nonce.\\\\\nDecryption: $P_t = O_t \\oplus C_t$. Blocks received are $C_1, ..., C_n$ and Nonce.\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/ctrencryption.png}\n\\label{fig:fround}\n\\caption{CTR mode encryption.}\n\\end{figure}\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/ctrdecryption.png}\n\\label{fig:fround}\n\\caption{CTR mode decryption.}\n\\end{figure}\n\n\\subsubsection{Properties}\n\n\\begin{center}\n\\begin{tabular}{ | c | p{5cm} | } \n\\hline\nRandomised & Yes \\\\\n\\hline\nPadding & Not required \\\\ \n\\hline\nError propagation & A one-bit change in the ciphertext produces a one-bit change in the plaintext at the same location \\\\ \n\\hline\nIV & Nonce must be unique \\\\ \n\\hline\nParallel encryption & Yes \\\\ \n\\hline\nParallel decryption & Yes \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\nSynchronous stream cipher mode.\\\\\nGood for access to specific plaintext blocks without decrypting the whole stream.\\\\\nBasis for authenticated encryption in TLS 1.2 and TLS 1.3.\n\n\\subsection{Random Numbers}\n\n\\subsubsection{TRNG}\n\nTrue Random NUmber Generator: physical process which outputs each valid string independently with equal probability.\\\\\nCan be used to provide a seed for a PRNG.\\\\\nFramework for design and validation of TRNG algorithms: entropy sources (physical noise source, digitization process and post-processing stages, output is any requested number of bits).\n\n\\subsubsection{PRNG}\n\nPseudo Random Number Generator: deterministic algorithm which approximates a TRNG.\\\\\nDeterministic Random Bit Generators (DRBG) algorithms based on: hash functions, specific MAC (HMAC) and block ciphers in CTR mode.\\\\\nEach generator takes seed (should be updated after some number of calls, can be generated by TRNG) as input and outputs a bit string before updating its state.\n\n\\textbf{Functions}\n\\begin{itemize}\n    \\item Instantiate: sets initial state using a seed\n    \\item Generate: provides output bit string\n    \\item Reseed: inputs new seed and updates state\n    \\item Test\n    \\item Uninstantiate: deletes state of DRBG\n\\end{itemize}\n\n\\textbf{Security}\n\n\\begin{itemize}\n    \\item Backtracking resistance: An attacker who obtains the current state of the DRBG should not be able to distinguish between the output of earlier calls to the DRBG generate function and random strings.\n    \\item Forward prediction resistance: An attacker who obtains the current state of the DRBG should not be able to distinguish between the output of later calls to the DRBG generate function and random strings.\n\\end{itemize}\n\n\n\\textbf{CTR\\_DRBG}\n\nUses a block cipher in CTR mode. AES with 128-bit key is one recommended option.\\\\\nDRBG initialised with seed (length = key length + block length, so 128+128=256bits for AES with 128-bit keys).\\\\\nFrom a high entropy seed a key $K$ and state (counter) value $V$ are derived. There is no separate nonce as in normal CTR mode.\\\\\nCounter mode encryption is then run iteratively (with no plaintext added) and the output blocks form the output\n\n\\newpage \\section{Hash Functions, MAC and authenticated encryption}\n\nPublic function that:\n\\begin{itemize}\n    \\item is simple and fast to compute\n    \\item takes as input a message $m$ of arbitrary length and outputs a message digest $H(m)$ of fixed length\n\\end{itemize}\n\n\\subsection{Properties}\n\n\\begin{itemize}\n    \\item Collision resistant: infeasible to find $x_1, x_2$ with $H(x_1)=H(x_2)$\n    \\item Second-preimage resistant: given value $x_1$ it should be infeasible to find $x_2 \\neq x_1$ with $H(x_1)=H(x_2)$\n    \\item One-way (or preimage resistant): given value $y$ it should be infeasible to find any $x$ such that $H(x)=y$\n\\end{itemize}\nBreaking second-preimage resistance $\\Rightarrow$ breaking collision resistance.\n\n\\subsection{Birthday Paradox}\n\nIn general if we choose around $\\sqrt{M}$ values from a set of size $M$ the probability of getting two values the same is around 0.5.\\\\\nSuppose hash function has output size of k bits. $2^{k/2}$ trials are enough to find a collision with probability around 0.5.\\\\\nToday, $2^{128}$ trials is considered infeasible. To satisfy collision resistance, functions should have output of at least 256 bits.\n\n\\subsection{Iterated hash functions}\n\nAn iterated hash function splits the input into blocks of fixed size and operates on each block sequentially using the same function with fixed size inputs.\\\\\nMerkle–Damgård construction: use a fixed-size compression function applied to multiple blocks of the message.\n\n\\subsubsection{Compression function}\n\nTakes two $n$-bit input strings $x_1, x_2$ and produces an $n$ bit output string $y$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/compressionfunction.png}\n\\label{fig:fround}\n\\caption{Compression function $h$.}\n\\end{figure}\n\n\\subsubsection{Merkle-Damgård construction}\n\n\\begin{enumerate}\n    \\item Break message $m$ into $n$-bit blocks $m_1, ..., m_l$\n    \\item Add padding and encoding of the length of $m$. May or may not add one block.\n    \\item Input each block into compression function along with chained output; use IV to get started.\n\\end{enumerate}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/derklamangard.png}\n\\label{fig:fround}\n\\caption{Merkle-Damgård construction.}\n\\end{figure}\n\n\\subsubsection{Security}\n\nIf compression function $h$ is collision-resistant, then $H$ is sollision-resistant.\\\\\nSome weaknesses: \n\\begin{itemize}\n    \\item Length extension attack: once you have one collision, easy to find more.\n    \\item Second-preimage attacks not as hard as they should be.\n    \\item Collisions for multiple messages can be found without much more difficulty than collisions for 2 messages.\n\\end{itemize}\n\nMany standard and former standard hash functions are Merkle-Damgård constructions: MD5, SHA-1, SHA-2 family.\n\n\\subsection{Standardized hash functions}\n\n\\subsubsection{MDx family}\n\nMD2, MD4 and MD5.\\\\\nOutput: 128-bit.\\\\\nAll of them are broken (2006: MD5 collisions found in 1 minute on a PC).\n\n\\subsubsection{SHA-0 and SHA-1}\n\nBased on MDx but more complex and larger output: 160-bit.\\\\\nSHA-0 broken (collisions found in 2004).\\\\\nSHA-1 broken (collision found in 2017).\n\n\\subsubsection{SHA-2 family}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | c | c | } \n\\hline\n & Hash size & Block size & Security match \\\\\n\\hline\nSHA-224 & 224 bits & 512 bits & 2 key 3DES \\\\ \n\\hline\nSHA-512/224 & 224 bits & 1024 bits & 2 key 3DES \\\\ \n\\hline\nSHA-256 & 256 bits & 512 bits & AES-128 \\\\ \n\\hline\nSHA-512/256 & 256 bits & 1024 bits & AES-128 \\\\ \n\\hline\nSHA-384 & 384 bits & 1024 bits & AES-192 \\\\ \n\\hline\nSHA-512 & 512 bits & 1024 bits & AES-256 \\\\ \n\\hline\n\\end{tabular}\n\\end{center}\n\n\\textbf{Padding}\n\nMessage length field is: 64 bits when block length is 512 bits; 128 bits when block length is 1024 bits.\\\\\nAlways at least one bit of padding. After the first '1', enough '0' bits are added so that after the length field is added there is an exact number of complete blocks.\\\\\n\n\\subsubsection{SHA-3}\n\nMDx and SHA family are all based on the same basic design and there have been several unexpected attacks on these in recent years.\\\\\nSHA-3 doesn’t use compression function as in Merkle–Damgård construction. Instead it uses a sponge construction.\\\\\nStandardized in August 2015.\n\n\\subsection{Use of hash functions}\n\nApplying hash function is NOT encryption (no key, not possible to go backwards).\\\\\nDo not provide data authentication alone but can help achieve it: authenticate hash of message to authenticate message, building block for message authentication and signatures.\n\n\\subsubsection{Storing passwords}\n\nUsual to store user passwords on servers using hash functions.\\\\\nStore salted hashes of passwords: pick random $salt$, compute $h=H(pw, salt)$, store $(salt,h)$.\\\\\nEasy to check entered password, hard to recover $pw$ from $h$. Attacker needs to store a different dictionary for each $salt$.\\\\\nUsing slower hash function slows down password guessing.\n\n\\subsection{Message Authentication Code (MAC)}\n\nCryptographic mechanism used for message integrity and authentication.\\\\\nOn input a secret key $K$ and an arbitrary length message $M$, a MAC algorithm outputs a fixed-length tag: $T=MAC(M,K)$.\\\\\nSymmetric key algorithm: sender and receiver both have secret key $K$.\\\\\nSender sends pair $(M,T)$ but $M$ may or may not be encrypted.\\\\\nRecipient recomputes tag $T' = MAC(M', K)$ on received message $M'$ and check $T'=T$.\n\n\\subsubsection{Properties}\n\n\\begin{itemize}\n    \\item Unforgeability: not feasible to produce $M$ and $T$ such that $T=MAC(M,K)$ without knowledge of $K$\n    \\item Unforgeability under chosen message attack: attacker is given access to forging oracle (on input any message $M$ of the attacker's choice the MAC tag $T=MAC(M,K)$ is returned). It is not feasible for the attacker to produce a valid $(M,T)$ pair that was not already asked to the oracle.\n\\end{itemize} \n\n\\subsubsection{HMAC}\n\nBuilt from any iterated cryptographic hash function $H4$, e.g.,MD5, SHA-1, SHA-256, ...\\\\\nStandardized and used in many applications including TLS and IPsec.\n\n\\textbf{Construction}\n\n$HMAC(M,K) = H((K \\oplus opad) \\Vert H (( K \\oplus ipad) \\Vert M))$ where $M$ = message to be authenticated, $K$ = key padded with zeros to the block size of $H$, $opad$ = fixed string 0x5c5c5c...5c, $ipad$ = fixed string 0x363636...36, $\\Vert$ denotes concatenation of bit strings.\n\n\\textbf{Security}\n\nSecure if $H$ is collision-resistant or pseudo-random.\\\\\nDesigned to resist length extension attacks (even of $H$ is Merkle-Damgård hash function).\\\\\nOften used as pseudorandom function for deriving keys in cryptographic protocols.\n\n\\subsubsection{Authenticated encryption}\n\nAlice and Bob have shared key K. Alice has message $M$ she wants to send to Bob with confidentiality and authenticity/integrity.\\\\\n2 options: split $K$ in 2 parts, encrypt with $K_1$ and use $K_2$ with a MAC; use dedicated algorithm which provides both properties (authenticated encryption).\n\n\\textbf{Combining encryption and authentication}\n\n\\begin{itemize}\n    \\item encrypt and MAC: encrypt $M$, apply MAC to $M$ and send two results.\n    \\item MAC then encrypt: apply MAC to $M$ to get tag $T$ then encrypt $M \\Vert T$ and send ciphertext\n    \\item encrypt then MAC: encrypt $M$ to get ciphertext $C$ then MAC $C$ and send 2 $C \\Vert T$.\n\\end{itemize}\n\nEncrypt-then-MAC is the safest approach.\n\n\\textbf{Authenticated encryption with associated data (AEAD)}\n\nAEAD algorithm: symmetric key cryptosystem.\\\\\nInputs: message $M$, associated data $A$, shared key $K$.\\\\\nOutput $O$ may contain different elements such as ciphertext and tag. Sender sends $O$ and $A$ to recipient.\\\\\nReceiver outputs either a message $M$ or reports fail.\\\\\nAny AEAD algorithm should provide confidentiality for $M$ and authentication for both $M$ and $A$.\n\n\\subsubsection{Galois counter Mode (GCM)}\n\nBlock cipher mode providing AEAD.\\\\\nMost commonly used mode in TLS.\\\\\nCombines CTR mode on a block-cipher (tipically AES) with a special keyed hash function GHASH.\\\\\nGCM using AES can be faster than using AES with HMAC.\n\n\\textbf{GCM algorithm}\n\nGHASH uses multiplication in finite field $GF(2^{128})$.\\\\\nInputs: plaintext $P$, authenticated data $A$ and nonce $N$.\\\\\nValues $u$ and $v$ are minimum number of 0s required to expand $A$ and $C$ to complete blocks.\\\\\nOutputs: ciphertext $C$ and tag $T$. (length of $A$, $len_A$ and length of $C$, $len_C$ are 64-bit values).\\\\\nTLS: length of $T$ is $t=128$ bits and $N$ is 96 bits. Initial block input to CTR mode of E (CTR in diagram) is $J_0 = N \\Vert 0^31 \\Vert 1$.\\\\\n$inc_{32}$ increments the right-most 32 bits of the input string by 1 modulo $2^{32}$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/gcmalgorithm.png}\n\\label{fig:fround}\n\\caption{GCM algorithm.}\n\\end{figure}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/ghash.png}\n\\label{fig:fround}\n\\caption{GHASH.}\n\\end{figure}\n\nFor GHASH: output is $Y_m=GHASH_{HK} (X_1,...,X_m)$, $\\bullet$ is multiplication in $GF(2^{128})$, $HK=E(0^128,K)$ is the hash subkey.\n\n\\textbf{GCM decryption}\n\nThe elements transmitted to the receiver are the ciphertext $C$, the nonce $N$, the tag $T$ and the authenticated data $A$.\\\\\nAll elements required to recompute the tag $T$ are available to the receiver who shares key $K$. The tag is recomputed and checked with received tag. If tags do not match then output is declared invalid.\\\\\nIf the tag is correct then the plaintext can be recomputed by generating the same key stream, from CTR mode, as is used for encryption.\n\n\n\\newpage \\section{Number Theory for Public Key Cryptography}\n\n\\subsection{Chinese remainder theorem}\n\nLet $d_1,..., d_r$ be pairwise relatively prime and $n= d_1 ... d_r$. Given any interegers $c_i$ there exists a unique integer $0 \\leq x < n$ such that $x=c_i$ mod $d_i$ for all $i \\leq r$.\\\\\nIn fact $x = \\sum (\\frac{n}{d_i})y_i c_i$ mod $n$ where $y_i = (\\frac{n}{d_i})^{-1}$ mod $d_i$.\n\n\\subsubsection{Example}\n\nSolve $x = 5$ mod 6, $x=33$ mod 35.\\\\\n6 and 35 are relatively prime so we can use CRT. Set $n = 6*35=210$.\\\\\n$\\frac{210}{6}y_1 = 1$ mod 6, \n$\\frac{210}{35}y_2 = 1$ mod 35\\\\\n$35 y_1 = 1$ mod 6, \n$6 y_2 = 1$ mod 35\\\\ \n$y_1 = 5$ mod 6, \n$y_2 = 6$ mod 35\\\\ \n$x = \\sum (\\frac{n}{d_i})y_i c_i$ mod n\\\\\n$x = (35*5*5)+(6*6*33)$ mod 210\\\\\n$x = 173$ mod 210\\\\\n\n\\subsection{Euler function $\\phi$}\n\nFor a positive integer $n$, the Euler function $\\phi (n)$ denotes the number of positive integers less than $n$ and relatively prime to $n$.\\\\\nThe set of positive integers less than $n$ and relatively prime to $n$ form the reduced residue class $\\mathbb{Z}^*_n$.\n\n\\subsubsection{Properties}\n\n\\begin{itemize}\n    \\item $\\phi (p) = p-1$ for $p$ prime\n    \\item $\\phi (pq) = (p-1)(q-1)$ for $p$ and $q$ distinct primes.\n    \\item Let $n = p_1^{e_1}...p_t^{e_t}$ where $p_i$ are distinct primes. Then $\\phi (n) = \\prod p_i^{e_i -1} (p_i -1)$.\n\\end{itemize}\n\n\\subsubsection{Theorems}\n\n\\begin{itemize}\n    \\item Fermat: Let $n$ be prime. Then $a^{p-1} = 1$ mod $p$ for all integers $1 < a < p-1$.\n    \\item Euler: $a^{\\phi(n)} = 1$ mod $n$ if $gcd(a,n) = 1$.\n\\end{itemize}\n\n\\subsection{Testing for primality}\n\nMethods used in practice are probabilistic.\n\n\\subsubsection{Fermat primality test}\n\nIf we examine $n$ and find that $a^{n-1} \\neq 1$ mod $n$ then we know $n$ is not prime.\\\\\nWe reduce failure probability by repeating test with different base values $a$.\\\\\n\nInputs: $n$ = number to test; $k$ = parameter determining number of times to test for primality.\\\\\nOutput: 'composite' if $n$ is composite, otherwise 'probable prime'.\\\\\n\n\\textbf{Effectiveness}\n\nIf the tests outputs 'composite' then $n$ is definitely composite. If the test outputs 'probable prime', $n$ is said to be pseudoprime.\\\\\nCarmichael numbers: the tet will always output 'probable prime' for every $a$ with $gcd(a,n) = 1$ (561, 1105, 1729, 2465, ...).\n\n\\subsubsection{Miller-Rabin test}\n\nSame idea as Fermat test. \\\\\nGuaranteed to detect composites if run sufficiently many times.\\\\\nMost widely used to generate large prime numbers.\n\n\\textbf{Square roots of 1}\n\nModular square root of 1 is a number $x$ with $x^2 = 1$ mod $n$.\\\\\nWhen $n=pq$ there are 4 square roots of 1. Two of these are 1 and -1 (trivial roots). The 2 others are the non-trivial roots.\\\\\nIf $x$ is a non-trivial square root of 1 then $gcd(x-1,n)$ is a non-trivial fator of $n$. Existence of non-trivial square root implies that $n$ is composite.\n\n\\textbf{Algorithm}\n\nAssume $n$ is odd. Define $u,v$ such that $n-1=2^v u$ where $u$ is odd.\n\\begin{enumerate}\n    \\item Pick $1 < a < n-1$ randomly.\n    \\item $b = a^u$ mod $n$\n    \\item If b == 1 then return 'probable prime'\n    \\item For $j = 0$ to $v-1$\n    \\begin{itemize}\n        \\item If b == -1 return 'probable prime'\n        \\item Else set $b=b^2$ mod $n$\n    \\end{itemize}\n    \\item Return 'composite'\n\\end{enumerate}\n\n\\textbf{Effectiveness}\n\nIf the test returns 'composite', $n$ is composite.\\\\\nIf the test returns 'probable prime', $n$ may be composite.\\\\\nIf $n$ is composite the test returns 'probable prime' with probability 1/4.\\\\\nTherefore we repeat algorithm $k$ times while output is 'probable prime'.\\\\\nThe k-times algorithm will output 'probable prime' when $n$ is composite with probability no more than $(1/4)^k$.\\\\\nNo composites less than 341,550,071,728,321 which pass the test for the seven bases $a=2,3,5,7,11,13,17$.\n\n\\textbf{Generating large primes}\\label{Generating large primes}\n\n\\begin{enumerate}\n    \\item Choose random odd integer $r$ of the same number of bits as the required prime.\n    \\item Test if $r$ is divisible by any of a list of small primes.\n    \\item Apply Miller-Rabin test with 5 (random or fixed) bases.\n    \\item If $r$ fails any test then set $r := r+2$ and return to step 2. (to have completely random primes start again at step 1)\n\\end{enumerate}\n\n\\subsection{Complexity theory}\n\n\\subsubsection{Definitions}\n\nThe computational complexity of an algorithm is measured by its time and space requirements as functions of the size of the input $m$.\\\\\nWe say $f(m) = \\mathcal{O} (g(m))$ if there exist constants $c>0$ and $m_0$ such that $f(m) \\leq c * g(m)$ for $m\\geq m_0$.\\\\\\\\\nPolynomial time function: $f(m)=\\mathcal{O} (m^t)$ where $t > 0$.\\\\\nExponential time function: $f(m)=\\mathcal{O} (b^m)$ where $b > 1$. Brute-force key search is exponential.\\\\\n\n\\subsubsection{Integer factorisation}\n\nGiven an integer, find its prime factor.\\\\\nFactorisation by trial division is an exponential time algorithm and is hopeless for numbers of a few hundred bits.\\\\\nBest current method: number field sieve (sub-exponential: better than exponential but worse than polynomial).\n\n\\subsubsection{Discrete logarithm problem (DLP)}\n\nLet $\\mathbb{G}$ be a cyclic group with generator $g$. The DEL in $\\mathbb{G}$ is given $y \\in \\mathbb{G}$, find $x$ such that $y=g^x$.\\\\\nBest method for solving DLP in $\\mathbb{Z}_p^*$: variant of number field sieve (sub-exponential).\\\\\nDLP can also be defined on elliptic curve groups (see later): best algorithms are exponential.\n\n\\newpage \\section{Public Key Cryptography and RSA}\n\n\\subsection{Public Key Cryptography (PKC)}\n\nPublic key cryptography is another name for asymmetric cryptography.\\\\\nThe encryption and decryption keys are different.\\\\\nThe encryption key is a public key which can be known to anybody.\\\\\nThe decryption key is a private key which should be known only to the owner of the key.\\\\\nFinding the private key from knowledge of the public key must be a hard computational problem.\n\n\\subsubsection{One-way functions}\n\n$f$ is a one-way function if it is easy to compute $f(x)$ given $x$ but it is hard to compute $f^{-1}(y)=x$ given $y$.\\\\\nTwo functions believed to be one-way functions:\n\\begin{itemize}\n    \\item Multiplication of large primes: inverse function is integer factorisation\n    \\item Exponentiation: inverse function is taking discrete logarithms\n\\end{itemize}\n\n\\subsubsection{Trapdoor one-way functions}\n\nOne-way function such that given additional information (the trapdoor) it is easy to compute $f^{-1}$.\\\\\nExample: modular squaring.\\\\\nLet $n=pq$ be the product of two large prime numbers $p$ and $q$ and define $f(x)=x^2$ mod $n$. Trapdoor is factorisation of $n$ - knowledge of $p$ and $q$ gives an efficient algorithm to find square roots (add exercise here).\n\n\\subsubsection{Why PKC ?}\n\nTwo advantages:\n\\begin{itemize}\n    \\item Key management is simplified: key do not need to be transported confidentially.\n    \\item Digital signatures can be obtained.\n\\end{itemize}\n\n\\subsubsection{Using PKC}\n\nEach user $A$ stores her public key in public directory. Anyone can obtain that key and use it to form an encrypted message for $A$.\\\\\nSince only $A$ has the private key, only $A$ can decrypt and recover the message.\n\n\\subsection{RSA}\n\n\\subsubsection{RSA key generation}\n\n\\begin{enumerate}\n    \\item Let $p, q$ be distinct primes randomly chosen from the set of all primes of a certain size.\n    \\item $n = pq$\n    \\item Select $e$ randomly with $gcd(e,\\phi(n))=1$\n    \\item $d = e^{-1}$ mod $\\phi(n)$\n    \\item Public key is the pair $n$ and $e$\n    \\item Private key consists of values $p$, $q$ and $d$.\n\\end{enumerate}\n\n\\subsubsection{RSA operations}\n\n\\textbf{Encryption}\n\nPublic key is $K_E = (n,e)$.\\\\\nInput: any value $0 < M < n$. Any message needs to be pre-processed (includes coding as a number and adding randomness - see later)\\\\\nCompute $C=E(M,K_E)=M^e$ mod $n$.\n\n\\textbf{Decryption}\n\nPrivate key for decryption is $K_D=d$.\\\\\nCompute $D(C,K_D)=C^d$ mod $n=M$.\n\n\\textbf{Example}\n\n\\begin{itemize}\n    \\item Key generation: Suppose $p=43, q=59$. Then $n=pq=2537$ and $\\phi(n)=(p-1)(q-1)=2436$.\\\\\n    Choose $e=5$ then $d=e^{-1}$ mod $\\phi(n)=5^{-1}$ mod $2436 = 1949$.\n    \\item Encryption: $M = 50 \\Rightarrow C = M^5 $mod $2537 = 2488$.\n    \\item Decryption: $M = C^{1949}$ mod $2537 = 50$.\n\\end{itemize}\n\n\\subsubsection{Correctness of RSA encryption}\n\nWe need to know that encryption followed by decryption gets back where we started from: $(M^e)^d$ mod $n = M$.\n\n\\newpage \\section{RSA: Implementation and Security}\n\n\\subsection{Implementing RSA}\n\n\\subsubsection{Generating $p$ and $q$}\n\nShould be random primes of chosen length (today: usually 1536 bits).\\\\\nUse of the Miller-Rabin test to generate random prime (see \\ref{Generating large primes}). \n\n\\textbf{Are there enough prime numbers ?}\n\nPrime number theorem: primes thin out as the numbers get larger.\\\\\n$\\pi(x)$ = nb of primes less than $x$. $\\pi(x)/(\\frac{x}{ln(x)}) \\longrightarrow 1 $. So proportion of primes up to $x$ is about $ln(x)$.\\\\\nWell over $2^{1500}$ 1536-bit primes: brute-force searching impossible.\n\n\\subsubsection{Selecting $e$}\n\nShould be random for max security.\\\\\nUsually small value for efficiency.\\\\\n$e=3$ is the smqllest vqlue qnd is sometimes used but not very secure, $e=2^{16}+1$ is a popular choice.\\\\\nA smaller than average $d$ value is also possible. However, to avoid known attacks $d$ should be at least $\\sqrt{n}$.\n\n\\subsubsection{Fast exponentiation: square-and-multiply}\n\nExponent $e$ writen in binary: $e=e_0 2^0 + e_1 2^1 + ... + e_k 2^k$ where $e_i$ are bits.\\\\\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.65]{Images/squareandmultiply.png}\n\\label{fig:fround}\n\\caption{Square-and-multiply algorithm.}\n\\end{figure}\n\n\\textbf{Cost}\n\nIf $2^k \\leq e < 2^{k+1}$ then the algorithm uses $k$ squarings.\\\\\nIf $b$ of the $e_i$ bits are 1 then the algorithm uses $b-1$ multiplications.\\\\\nIf $n$ is 3072-bit RSA modulus: private exponent $d$ is length at most 3072 bits, and computing $M^d$ mod $n$ requires at most 3072 modular squarings and 3072 modular multiplications (on average half of the bits of $d$ are '1's so only 1536 multiplications are needed).\n\n\\subsubsection{Faster decryption with CRT}\n\nFirst compute $M_p = C^{d mod p-1}$ mod $p$, $M_q = C^{d mod q-1}$ mod $q$.\\\\\nSolve for $M$ mod $n$ using CRT: $M=M_p$ mod $p$, $M=M_q$ mod $q$.\\\\\n$M = q * (q^{-1} mod p) * M_p + p * (p^{-1} mod q ) * M_q$ mod $n$.\n\n\\textbf{Example}\n\n$n=43*59=2537$. Ciphertext $C=2488$. Decryption exponent $d=1949$.\\\\\n$d$ mod $p-1 = 1949$ mod $42 = 17$\\\\\n$d$ mod $q-1 = 1949$ mod $58 = 35$\\\\\n$M_p = 2488^{17}$ mod $43 = 7$\\\\\n$M_q = 2488^{35}$ mod $59 = 50$\\\\\nUsing CRT solution is $M=50$.\n\n\\textbf{How much faster ?}\n\nExponents (d mod p-1) and (d mod q-1) are about half the length of $d$.\\\\\nComplexity of exponentiation increases with cube of input length $\\Rightarrow$ computing $M_p$ and $M_q$ each use 1/8 the computation of $M=C^d $ mod $n$. Can be done in parallel to be 8 times faster.\\\\\nGood idea to store $p$ and $q$ with private exponent $d$.\n\n\\subsubsection{RSA padding}\n\nUsing RSA directly on messages encoded as numbers is vulnerable to :\n\\begin{itemize}\n    \\item building up dictionary of known plaintexts\n    \\item guessing plaintext and checking to see if it encrypts to the ciphertext\n    \\item Håstad's attack (see \\ref{Håstad's attack})\n\\end{itemize}\nPadding mechanisms must be used to prepare messages for encryption: must include redundancy and randomness.\n\nRSA is often used for hybrid encryption:\n\\begin{enumerate}\n    \\item Encrypt random value $r$ using RSA public key.\n    \\item Use $r$ (after hashing) as the key in a symmetric-key encryption algorithm.\n\\end{enumerate}\n\n\\textbf{PKCS Number 1}\n\nEncryption block format is:\n\\begin{center}\n\\begin{tabular}{ | c | c | c | c | c | } \n\\hline\n00 & 02 & $PS$ & 00 & $M$ \\\\\n\\hline\n\\end{tabular}\n\\end{center}\nwhere 00 and 02 are bytes, $PS$ is a pseudo-random string on nonzero bytes (minimum 8 bytes) and $M$ is the data to be encrypted.\\\\\nThe length of the block is the same as the length of the modulus.\\\\\nThe byte 02 and padding ensure that even short messages result in a large integer value for encryption.\n\n\\textbf{Optimal Asymmetric Encryption Padding (OAEP)}\n\nHas security proof in a suitable model.\\\\\nEncoded message uses a $k$-bit random value $r$ and a $k$-bit constant $d$. Typical value for $k$ is 256.\\\\\nThe data to be encrypted $m$ is padded with at least one byte to make $\\vert n \\vert - 2k-8$ bits where $\\vert n \\vert$ = nb of bits in the RSA modulus $n$.\\\\\nTwo random hash functions G and H are used, derived from SHA-256.\\\\\nEncoding algorithm, can be easily inverted without any secret.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/oaepencoding.png}\n\\label{fig:fround}\n\\caption{OAEP encoding.}\n\\end{figure}\n\n\\subsubsection{Håstad's attack}\\label{Håstad's attack}\n\nSuppose the same message is encrypted without padding to three different recipients.\\\\\nSuppose the public exponent $e=3$ is used by all recipients.\\\\\nThe cryptanalyst has 3 ciphertexts $C_1 = M^3$ mod $n_1$, $C_2 = M^3$ mod $n_2$ and $C_3 = M^3$ mod $n_3$.\\\\\nThese equations can be solved by the CRT to obtain $M^3$ in the ordinary (non-modular) integers. Then $M$ can be found by taking a cube root.\n\n\\subsection{Security of RSA}\n\n\\subsubsection{Factorisation}\n\nAn adversary who can factorise $n$ into its prime factors $p$ and $q$ can recover private key $d$ and reveal all messages.\\\\\nBreaking RSA is not harder than the factorisation problem, it is unknown if it is as hard (also unknown whether factorisation is really computationally hard).\n\nTheorem (Miller): determining $d$ from $e$ and $n$ is as hard as factorising $n$.\n\n\\textbf{Miller's algorithm}\n\n\\begin{enumerate}\n    \\item Define $u,v$ such that $ed-1=2^v u$ where $u$ is odd.\n    \\item Consider sequence $a^u, a^{2u}, ..., a^{2^{v-1}u}, a^{2^{v}u}$ mod $n$.\n    \\item Notice tha $a^{2^vu}=a^{ed-1}=a^{ed}a^{-1}=aa^{-1}=1$ mod $n$ so there is a square root of 1 somewhere in his sequence.\n    \\item With probability at least 0.5 the sequence contains a non-trivial square root of 1 modulo $n$ thereby revealing the factors of $n$\n    \\item If not, choose a new $a$ and repeat.\n\\end{enumerate}\n\n\\textbf{Quantum computers}\n\nShor's algorithm can factorise in polynomial time on a quantum computer.\\\\\nNIST is running open competition to standardise public key cryptography secure against quantum computers.\n\n\\subsubsection{Side Channel Attacks on RSA}\n\nFirst made public in 1996 by Paul Kocher.\\\\\nAlso apply to most other public and symmetric key cryptosystems.\\\\\nMany different kinds of side-channels are known including timing attacks, power analysis, and fault analysis.\n\nTiming attacks: attacker measures distribution of timing of $a \\cdot b$ mod $n$ on target platform.\n\n\\textbf{Timing attack on square-and-multiply}\n\nRecall that square-and-multiply performs for each exponent bit $e_i$ either: a squaring only when $e_i=0$; or a squaring and a multiplication when $e_i=1$.\\\\\nMeasure correlations between the known distribution and the actual time used for different input.\\\\\nFind each bit $e_i$ of the private exponent before moving to the next.\n\n\\textbf{Timing attack on CRT}\n\nWhen the Chinese Remainder Theorem is used, a timing attack can be used to find one factor of $n$, say $p$.\\\\\nChoose different input $C$ values to change the timing of modular reduction $C$ mod $p$.\\\\\nIf $C_1$ and $C_2$ cause different timings then there is probably a multiple of $p$ between them.\\\\\nA binary search can be used to find $p$ and then $n$ can be factorised.\n\n\\textbf{Countermeasures}\n\nUsually degrade performance.\\\\\n\\begin{itemize}\n    \\item Computing in constant time - run 'dummy' multiplication when $e_i = 0$ in square-and-multiply algorithm\n    \\item Montgomery ladder - makes every operation depend on the key to avoid some default attacks\n    \\item Randomising RSA message, which can hide either which value is actually multiplied by exponent bit in square-and-multiply algorithm; or size of value used in CTR modular reduction.\n\\end{itemize}\n\n\\subsubsection{Summary}\n\n\\begin{itemize}\n    \\item Factorisation of the modulus is the best known attackagainst RSA in the case that standardised padding is used\n    \\item Finding the private key from the public key alone is as hard as factorising the modulus\n    \\item It is an open problem whether there is any way of breaking RSA encryption without factorising the modulus\n    \\item Side channels are an important threat to consider\n\\end{itemize} \n\n\\newpage \\section{Public Key Cryptosystems based on Discrete Logarithms}\n\n\\subsection{Diffie-Hellman Key Exchange}\n\n\\subsubsection{Protocol}\n\nAlice and Bob want to share a secret using only public communications.\\\\\nPublic knowledge: generator $g$ of a multiplicative group $G$ of order $t$ (originally $\\mathbb{Z}_p^*$ for large $p$, now elliptic curve group).\\\\\nAlice and Bob each select random values $a$ and $b$ where $0<a,b<t$.\\\\\nAlice sends $g^a$ to Bob (insecure channel).\\\\\nBob sends $g^b$ to Alice (insecure channel).\\\\\nAlice and Bob both compute secret key $Z=g^{ab}$. $Z$ can be used to compute a key for $AES$ for example (using key derivation function based on a public hash function).\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/diffiehellmanprotocol.png}\n\\label{fig:fround}\n\\caption{Diffie-Hellman protocol.}\n\\end{figure}\n\n\\subsubsection{Properties}\n\n\\textbf{Security}\n\nAn attacker who can find discrete logarithms in $G$ can break the protocol: intercept $g^a$ and take discrete log to find $a$, then compute $g^{ab}$ in the same way as Bob.\\\\\nUnknown whether there is better way to break the protocol.\\\\\nDiffie-Hellman problem: find $Z=g^{ab}$ from knowledge of $g^a$ and $g^b$.\n\n\\textbf{Authenticated Diffie-Hellman}\n\nIn the basic Diffie–Hellman protocol the messages between Alice and Bob are not authenticated.\\\\\nNeither Alice nor Bob knows who the secret $Z$ is shared with unless the messages are authenticated.\\\\\nThis allows a man-in-the-middle attack, where the adversary sets up two keys, one with Alice and one with Bob, and relays messages between the two.\\\\\nAuthentication can be added in different ways, for example by adding digital signatures (see next section).\n\n\\textbf{Static and ephemeral Diffie-Hellman}\n\nThe protocol above uses ephemeral keys: used once and then discarded.\\\\\nStatic D-H: Alice chooses long-term private key $x_A$ with corresponding public key $y_A=g^{x_A}$. Bob does the same with $x_b$ and $y_B$. Now Alice and Bob can find a shared secret $S=g^{x_A x_B}$ just by looking up (or knowing) each others' public keys. $S$ is static: it stays the same long-term until Alice and Bob change their public keys.\n\n\\subsection{Elgamal cryptosystem}\n\n\\subsubsection{Algorithm}\n\n\\textbf{Key generation}\n\n\\begin{itemize}\n    \\item Select prime $p$ and a generator $g$ of $\\mathbb{Z}_p^*$\n    \\item Select long term private key $0<x<p-1$\n    \\item $y= g^x$ mod $p$\n    \\item Public key is $(p,g,y)$\n    \\item Often $p$ and $g$ are shared between all users in some system.\n\\end{itemize}\n\n\\textbf{Encryption}\n\nPublic key is $K_E = (p,g,y)$.\n\\begin{enumerate}\n    \\item For any value $0<M<p$\n    \\item Choose $k$ at random and compute $g^k$ mod $p$\n    \\item $C=E(M,K_E)=(g^k$ mod $p, My^k$ mod $p)$\n\\end{enumerate}\n\n\\textbf{Decryption}\n\nPrivate key is $K_D=x$ with $y=g^x$ mod $p$\n\\begin{enumerate}\n    \\item $C=(C_1,C_2)$\n    \\item Compute $C_1^x$ mod $p$\n    \\item $D(C, K_D) = C_2 \\cdot (C_1^x)^{-1}$ mod $p = M$.\n\\end{enumerate}\n\n\\textbf{Example}\n\n\\begin{enumerate}\n    \\item Key generation: Choose prime $p=181$ and generator $g=2$.\\\\\n    Private key of $A$ is $x=50$.\\\\\n    Public key is $p=181, g=2, y=116$.\\\\\n    \\item Encryption: Sender wants to send $M = 97$.\\\\\n    Sender chooses random $k = 31$.\\\\\n    Ciphertext is $(98,173)=(C_1, C_2)$.\n    \\item Decryption: $A$ receives $(C_1, C_2)$ and recovers $M$ by:\\\\\n    $C_1^x = 98^{50}$ mod $p = 138$.\\\\\n    $M = C_2 * (C_1^x)^{-1}$ mod $p = 97$.\n\\end{enumerate}\n\n\\subsubsection{Security}\n\nIf an attacker can solve the discrete log problem, the system can be broken by determining the private key $x$ from $g^x$ mod $p$.\\\\\nPossible for many users to share the same $p$ and $g$ values.\\\\\nNo need for padding as in RSA - each ciphertext is already randomised.\n\n\\subsection{Elliptic curves}\n\nAlgebraic structures formed from cubuc equations.\\\\\nExample: set of all $(x,y)$ which satisfy $y^2= x^3+ax+b$ mod $p$. This is a curve over the field $\\mathbb{Z}_p$ but elliptic curves can be defined over any field.\\\\\nOnce an identity element is added, a binary operation can be defined on these points. With this operation the elliptic curve points form an elliptic curve group.\n\n\\subsubsection{Choosing elliptic curves}\n\nStandard application usually use standard curves.\\\\\nExample: NIST curve P-192.\n\n\\subsubsection{Discrete logarithms on elliptic curves}\n\nThe discrete logarithm can be defined on elliptic curves groups - if we denote the elliptic curve operation as multiplication then the definition is the same as in $\\mathbb{Z}_p^*$.\\\\\nBest known algorithms to solve elliptic curve discrete log problem: exponential. Consequently elliptic curve implementations use much smaller keys.\\\\\nCompared with RSA the relative advantage of elliptic curve cryptography will increase at higher security levels.\n\n\\subsubsection{Elliptic curve cryptography}\n\n\\begin{table}[H]\n\\begin{center}\n\\begin{tabular}{ | p{3.5cm} | p{3.5cm} | p{3.5cm} | }\n\\hline\nSymmetric key length  & RSA modulus length or length of $p$ in $\\mathbb{Z}_p^*$ & Elliptic curve group size \\\\\n\\hline\n80 & 1024 & 160\\\\\n\\hline\n128 & 3072 & 256\\\\\n\\hline\n192 & 7680 & 384\\\\\n\\hline\n256 & 15360 & 512\\\\\n\\hline\n\\end{tabular}\n\\caption{Comparing strength of elliptic curve cryptography.}\n\\end{center}\n\\end{table}\n\nBrute force search of 128-bit key for AES takes roughly same computational effort as for taking discrete logarithms in $\\mathbb{Z}_p^*$ with $p$ of 3072-bits or on an elliptic curve with elements of size 256 bits.\n\nMost cryptosystems based on discrete logarithms can be constructed with elliptic curves as well as in $\\mathbb{Z}_p^*$: Diffie-Hellman and Elgamal for example.\n\n\\subsection{Post-quantum cryptography}\n\nMost public key cryptography is use today will be broken if quantum computers become available due to Shor’s algorithm for factorisation, which can also be used to find discrete logarithms.\\\\\nSymmetric key cryptography can still be used but with double length keys due to Grover’s algorithm for searching.\\\\\nCurrently no post-quantum replacement for Diffie-Hellman: promising candidate is the use of isogenies on elliptic curves.\n\n\\newpage \\section{Digital Signatures and Certificates}\n\n\\subsection{Properties}\n\n\\subsubsection{Confidentiality and authentication}\n\nMessage AUthentication Codes (MACs) allow only ean entity with the shared secret to generate a valid MAC tag, providing data integrity and data authentication.\\\\\nDigital signatures use public key cryptography to provide the properties of a MAC and more: only the owner of the private key can generate a correct digital signature.\\\\\n\n\\subsubsection{Comparison to physical signatures}\n\n\\begin{center}\n\\begin{tabular}{ | c | c | }\n\\hline\nPhysical signatures & Digital signatures \\\\\n\\hline\nProduced by human & Produced by machine \\\\\n\\hline\nSame on all the documents & Function of message\\\\\n\\hline\nEasy to recognize & Requires computer to check\\\\\n\\hline\n\\end{tabular}\n\\end{center}\n\nBoth need to be difficult to forge.\n\n\\subsubsection{Elements}\n\nDigital signature scheme has 3 algorithms: key generation, signature generation, signature verification.\\\\\nKey generation outputs 2 keys: private signature generation key (or signing key) $K_S$; and a public signature verification key $K_V$.\n\n\\subsubsection{Signature generation}\n\nAlice wishes to generate signature on message $m$.\\\\\nInputs: Alice's private signing key $K_S$ and the message $m$.\\\\\nOutput: signature $\\sigma = Sig(m, K_S)$.\\\\\nOnly the owner of $K_S$ should be able to generate a valid signature.\n\n\\subsubsection{Signature verification}\n\nBob wishes to verify a claimed signature $\\sigma$ on the message $m$.\\\\\nInputs: Alice's public verification key $K_V$, the message $m$ and the claimed signature $\\sigma$.\\\\\nOutput: boolean $Ver(m,\\sigma,K_V)$.\\\\\nAnyone should be able to use $K_V$ to verify a signature.\n\n\\textbf{Required properties}\n\nCorrectness: $\\sigma = Sig(m,K_S) \\Rightarrow Ver(m,\\sigma,K_V) = $true.\\\\\nUnforgeability: computationally infeasible for anyone without $K_S$ to construct $m$ and $\\sigma$ such that $Ver(m,\\sigma,K_V) = $true.\\\\\nSig may be randomised so there are many possible signatures for a single message.\\\\\nStronger security definition: assume attacker has access to a chosen message oracle (forging (new) signature should be difficult even with access to signatures on chosen messages).\n\n\\subsubsection{Security goals}\n\nAttacks:\n\\begin{itemize}\n    \\item Key recovery: attacker attempts to recover $K_S$ from $K_V$ and some known signatures.\n    \\item Selective forgery: attacker chooses message and attempts to obtain a signature on that message.\n    \\item Existential forgery: attacker attempts to forge signature on any message not previously signed.\n\\end{itemize}\nModern digital signatures are considered secure only if they can resist existential forgery under a chosen message attack.\n\n\\subsection{RSA Signatures}\n\n\\subsubsection{Key generation}\n\nGenerated in the same way as RSA encryption keys.\n\\begin{itemize}\n    \\item Modulus $n=pq$ is computed from random large primes $p$ and $q$\n    \\item Two exponents $e$ and $d$ are generated with $ed$ mod $\\phi(n) = 1$\n    \\item Private signing key is $K_S = (d,p,q)$\n    \\item Public verification key is $K_S = (e,n)$\n    \\item A hash function $h$ is also required and should be a fixed public parameter of the signature scheme.\n\\end{itemize}\n\n\\subsubsection{Operations: signature generation and verification}\n\nGeneration: inputs are the message $m$, the modulus $n$ and the private exponent $d$.\\\\\n1. Compute signature $\\sigma = h(m)^d$ mod $n$.\n\nVerification: inputs are the message $m$, the claimed signature $\\sigma$ and the public key $(e,n)$.\\\\\n1. Compute $h' = h(m).$\\\\\n2. Check if $\\sigma^e$ mod $n = h'$ and if so output true, else false.\n\n\\subsubsection{Hash functions for RSA signatures}\n\nFollowing 2 choices can be proven secure with suitable assumptions:\n\\begin{itemize}\n    \\item Full domain hash: implementation of $h$ which can take values randomly in the range 1 to $n$.\n    \\item PSS: probabilistic hashing function similar to OAEP used for RSA encryption and is standardised in the PKCS #1 standard.\n\\end{itemize}\n\n\\subsection{Discrete Logarithm Signatures}\n\nRely on the difficulty of the discrete log problem.\n\n\\subsubsection{Elgamal in $\\mathbb{Z}_p^*$}\n\n\\textbf{Key genration}\n\nLet $p$ be a large prime with generator $g$. Private signing key is $0 < x < p-1$.\\\\\nPublic verification key: $y = g^x$ mod $p$. Values $p, g, y$ are public knowledge.\n\n\\textbf{Signature generation}\n\nTo sign message $m$ with signing key $x$:\n\\begin{itemize}\n    \\item Select random $0<k<p-1$ and compute $r = g^^k$ mod $p$\n    \\item Compute $s = k^{-1}(m-xr)$ mod $(p-1)$\n    \\item Signature is $\\sigma = (r,s)$\n\\end{itemize}\n\n\\textbf{Signature verification}\n\nGiven message $m$, claimed signature $\\sigma = (r,s)$ and verification key $y$:\\\\\nVerify $g^m = y^r r^s$ mod $p$.\n\n\\subsubsection{Standard: Digital signature algorithm (DSA)}\n\nBased on Elgamal signatures.\\\\\nSimpler calculations and shorter signatures by restriction calculations to a subgroup of $\\mathbb{Z}_p^*$ or to an elliptic curve group.\\\\\nUse with SHA family of hash functions.\n\n\\subsubsection{Parameters}\n\n\\begin{itemize}\n    \\item $p$: prime modulus of $L$ bits\n    \\item $q$: prime divisor of $p-1$ of $N$ bits\n    \\item Valid combinations of $L$ and $N$: $(L=1024, N=160)$ (not approved by NIST)$, (L=2048, N=224), (L=2048, N=256), (L=3072, N=256)$\n    \\item $g = h^{\\frac{p-1}{q}}$ mod $p$, where $h$ is any integer $1 < h < p-1$\n    \\item H, the SHA hash family variant which outputs an $N$-bit digest\n\\end{itemize}\n\n\\subsubsection{Key generation}\n\n\\begin{enumerate}\n    \\item Choose random integer $0<x<p$\n    \\item $x$ is the secret signing key.\n    \\item $y = g^x$ mod $p$ is the public verification key.\n\\end{enumerate}\n\n\\subsubsection{Signature generation}\n\n\\begin{enumerate}\n    \\item Choose random $0<k<q$ and set $r = (g^k$ mod $p)$ mod $q$.\n    \\item Set $s = k^{-1} ( H(m) - xr)$ mod $q$\n    \\item Signature is $\\sigma = (r,s)$.\n\\end{enumerate}\n\n\\subsubsection{Signature verification}\n\n\\begin{enumerate}\n    \\item Check that $0<r<q$ and $0<s<q$\n    \\item Compute $w = s^{-1}$ mod $q$ qnd let $u_1= H(m)w$ mod $q$ and $u_2 = rw$ mod $q$.\n    \\item Check if $(g^{u_1}y^{-u_2}$ mod $p)$ mod $q = r$\n \\end{enumerate}\n \n \\subsubsection{Comparison with Elgamal signatures}\n \n Verification equation is the same, except all exponents are reduced modulo $q$ and final result is also reduced modulo $q$.\\\\\n Complexity of signature generation: one exponentiation with short exponent (such as 224 or 256 bits).\\\\\n Signature verification requires 2 such short exponentiations.\\\\\n Signature size = $2N$ bits.\n \n \\subsection{Standard: ECDSA}\n \n Elliptic curve variant of DSA.\\\\\n Elliptic curve parameters are chosen from the NIST approved curves.\\\\\n Signature generation and verification is the same as DSA except that:\n \\begin{itemize}\n     \\item parameter $q$ becomes the order of the elliptic curve group\n     \\item multiplication modulo $p$ is replaced by the elliptic curve group operation\n     \\item after the operations on the group elements only the x-coordinate (an element in the underlying field) is kept.\n \\end{itemize}\n\n\\subsubsection{ECDSA vs DSA}\n\nSignatures using ECDSA are usually not shorter than signatures using DSA for the same security level (ECDSA signature size varies with the curve used: 326 $\\rightarrow$ 1142 bits).\\\\\nECDSA public keys are shorter than DSA public keys.\n\n\\subsection{Certificates and PKI}\n\n\\subsubsection{Digital certificates}\n\nWhen using a public key to encrypt a message or to verify a digital signature, it is essential to be confident of the correct binding between a public key and its owner.\\\\\nNormally this is achieved through use of digital certificates which contain the public key and owner identity, and usually other information such as signature algorithm and validity period.\\\\\nThe certificate is digitally signed by a party trusted by the certificate verifier, normally called a certification authority or CA.\\\\\nCertificates play a central role in key management for public key infrastructures.\n\n\\subsubsection{Public key infrastructure (PKI)}\n\nFramework that is established to issue, maintain and revoke public-key certificates.\n\n\\subsubsection{Certification Authority (CA)}\n\nCreate, issue and revoke certificates for subscribers and other CAs.\\\\\nHave a Certification Practice Statement (CPS) covering issues such as:\n\\begin{itemize}\n    \\item checks performed before certificate issue\n    \\item physical, personnel and procedural security controls for the CA\n    \\item technical and key pair protection and management controls\n    \\item certificate revocation management procedures\n    \\item audit procedures for the CA\n    \\item accreditation information\n    \\item legal and privacy issues and liability limitations\n\\end{itemize}\n\n\\subsubsection{X.509 standard}\n\nWidely used standard allowing flexible extensions.\\\\\nImportant fields are:\n\\begin{itemize}\n    \\item verison number\n    \\item serial number (set by CA)\n    \\item signature algorithm identifiers\n    \\item issuer (name of CA)\n    \\item subject (name of entity to which the certificate is issued)\n    \\item public key information\n    \\item validity period\n    \\item digital signature (of the certificate, signed by CA)\n\\end{itemize}\n\n\\subsubsection{Using certificate}\n\nVerified by checking that the CA signature is valid and that any conditions set in the certificate are correct.\\\\\nTo verify a certificate, the user of the cetificate must have the correct public key of the CA.\\\\\nCertificates may be stored in public directories and are often sent by the owner of the public key to the user.\n\n\\subsubsection{Certification paths}\n\nIf the public key of a CA $CA_0$ is not already known and trusted it can itself be certified by a different CA $CA_1$. The public key of $CA_1$ can also be certified by $CA_2$.\\\\\nThis way we can set up a chain of trust (certification path):\\\\\n\\begin{center}\n    $CA_n \\rightarrow CA_{n-1} \\rightarrow ... \\rightarrow CA_1 \\rightarrow CA_0$\n\\end{center}\nIf an entity has a trusted copy of the public key of $CA_n$, the chain of trust can be used with certificates for all the intermediate CAs to obtain a trusted copy of the public key of $CA_0$\n\n\\subsubsection{Hierarchical PKI}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/hierarchicalpki.png}\n\\label{fig:fround}\n\\caption{Hierarchical PKI.}\n\\end{figure}\n\nCAs certify the public key of the entity below.\n\n\\subsubsection{Revocation}\n\nSometimes it may be required to declare a certificate invalid even though its validity period is current.\\\\\nIn order to make this work the user must check to see which certificates have been revoked.\\\\\nTwo widely deployed mechanisms:\n\\begin{enumerate}\n    \\item Certificate revocation lists (CRL): each CA periodically issues a list of revoked certificates which can be downloaded and then checked by clients.\n    \\item Online certificate status protocol (OCSP): a server will maintain a current list of revoked certificates and respond to requests about specific certificates.\n\\end{enumerate}\n\n\\newpage \\section{Protocols for Key Establishment}\n\n\\subsection{Principles}\n\n\\subsubsection{Types of keys}\n\n\\begin{itemize}\n    \\item Long term keys (static keys): intended to be used for long period (few hours $\\rightarrow$ few years). Symmetric or asymmetric, depends on how they're used.\n    \\item Ephemeral keys: generated for single use and then deleted.\n    \\item Session keys: intended for use in one communication session (few seconds, few hours or a day), to protect communications in a session for example with authenticated encryption. Usually symmetric keys used with ciphers such as AES and MACs because of their better efficiency over public key algorithms.\n\\end{itemize}\nLong-term and ephemeral keys are used in establishment of sessions keys.\n\n\\subsubsection{Key establishment}\n\nWe need way to establish secret session keys among communication parties using long-term keys. 3 approaches:\n\\begin{enumerate}\n    \\item key pre-distribution where keys are set in advance\n    \\item key transport where one party chooses the key and distributes it\n    \\item key agreement where 2+ parties contribute to the session key.\n\\end{enumerate}\n\n\\subsubsection{Security}\n\nAdversary capabilities: we assume attacker can eavesdrop on all messages, alter all messages, re-route any message to any user, obtain the value of the session key $K_{AB}$ used in any previous run of the protocol.\n\n2 properties define security:\n\\begin{itemize}\n    \\item Authentication: if party $A$ completes the protocol and believes that sessions key $K_{AB}$ is shared with party $B$, then $K_{AB}$ should not be shared with a different party $C$.\\\\\n    Can be mutual (both parties achieve it) or unilateral ( only provided on one side).\n    \\item Confidentiality: an adversary is unable to obtain the session key accepted by a particular party.\n\\end{itemize}\n\n(Perfect) forward secrecy: compromise of long-term private keys does not reveal session keys previously agreed using those long-term keys.\n\n\\subsection{Types}\n\n\\subsubsection{Key pre-distribution (pre-shared keys)}\n\nTrusted authority (TA) generates and distributes long-term keys to all users when they join the system.\\\\\nSimplest scheme: secret key for each pair (poor scalability). More complex schemes give each user a set of keys so that each pair has a subset.\n\n\\subsubsection{Session key transport with an online server}\n\nTA shares a long-term shared key with each user.\\\\\nTA generates and sends session keys to users when requested and protected by the long-term keys.\\\\\nExample: Kerberos (see \\ref{Kerberos}).\\\\\nTA must be trusted and is single point of attack + problems of scalability.\n\n\\subsubsection{Key transport with asymmetric cryptography}\n\nOne user chooses key material and sends it encrypted with the other party's public key.\\\\\nTLS up to 1.2 includes options for this type of key establishment.\\\\\nNo forward secrecy.\n\n\\subsubsection{Key agreement - signed Diffie-Hellman}\n\n2 parties each provide input to the keying material.\\\\\nUsually provide authentication with public keys, for example by signing the exchanged messages.\\\\\nDiffie–Hellman protocol is a widely used key agreement protocol.\\\\\nTLS includes options for this type of key distribution.\n\n\\textbf{Signed Diffie-Hellman}\n\n$A$ and $B$ are two parties with identities $ID_A$, $ID_B$, who want to share a session key.\\\\\nComputation takes place in a group $G$ with generator $g$ .\\\\\n$a, b$ are random values chosen by $A$ and $B$ in the range up to the order of $G$.\\\\\n$Sig_A(m)$ is a digital signature on message $m$ by $A$.\\\\\n$Sig_B(m)$ is a digital signature on message $m$ by $B$.\\\\\nBoth parties need each other’s public signature verification keys.\\\\\nProvides forward secrecy because the long-term (signing) keys are only used for authentication.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.75]{Images/signeddiffiehellmanprotocol.png}\n\\label{fig:fround}\n\\caption{Signed Diffie-Hellman protocol.}\n\\end{figure}\n\n$A$ checks the signature received in flow 2 and if it is valid $A$ computes the shared secret : $Z= (g^b)^a=g^{ab}$.\\\\\nSimilarly $B$ checks the signature received in flow 3 and, if valid, computes the shared secret: Z=  $Z= (g^b)^a=g^{ab}$.\\\\\nThe session key can be $K_{AB}=H(Z,ID_A,ID_B)$.\n\n\\subsection{Session key transport using symmetric keys}\n\n\\subsubsection{Needham-Schroeder protocol}\n\n\\textbf{Protocol}\n\n\\noindent\\begin{minipage}{0.6\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/needhamschroederprotocol.png}\n\\label{fig:fround}\n\\caption{Needham-Schroeder protocol.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.35\\textwidth}\n\\begin{itemize}\n    \\item Parties $A, B$ want to establish session key.\n    \\item Party $S$ is the TA\n    \\item $A$ and $S$ share long-term key $K_{AS}$.\n    \\item $B$ and $S$ share long-term key $K_{BS}$.\n    \\item $K_{AS}$: new session key generated by $S$.\n    \\item Nonces $N_A, N_B$ randomly generated for one-time use.\n    \\item $\\{X\\}_K$: authenticated encryption of message $X$ using shared secret key $K$.\n\\end{itemize}\n\\end{minipage}\n\n\\textbf{Replay attack}\n\nAn attacker is able to replay old protocol messages and the honest party accepts an old session key.\\\\\nAssume an attacker $C$ obtains a sessions key $K'_{AB}$ previously established between $A$ and $B$.\\\\\nIn the attack, $C$ masquerades as $A$ and is thus able to persuade $B$ to use the old key $K'_{AB}$.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/replayattackneedham.png}\n\\label{fig:fround}\n\\caption{Replay attack on Needham-Schroeder protocol.}\n\\end{figure}\n\n\\textbf{Repaired Needham-Schroeder protocol: freshness}\n\nTo defend against replay attacks: critical that the key established be fresh (new) for each session.\\\\\nTo achieve freshness: random challenges (nonces), timestamps (string on the current time), counters (increased for each new message).\nExample with random challenges:\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.7]{Images/reparedneedhamschroeder.png}\n\\label{fig:fround}\n\\caption{Repaired Needham-Schroeder protocol - use of random challenges.}\n\\end{figure}\n\n\\textbf{Repaired Needham-Schroeder protocol: tickets}\n\nUse of key with validity period to fix protocol.\\\\\n\\noindent\\begin{minipage}{0.6\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.72]{Images/needhamschroedertickets.png}\n\\label{fig:fround}\n\\caption{Repaired Needham-Schroeder protocol - use of tickets.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.35\\textwidth}\n\\begin{itemize}\n    \\item Suppose $A$ wants to obtain access to server $B$.\n    \\item Authentication server$S$ issues a ticket to allow $A$ to obtain access.\n    \\item Ticket has the format $\\{K_{AB}, ID_A, ID_B, T_B\\}_{K_{BS}}$ where $T_B$ is a timestamp which we can also interpret as a validity period.\n    \\item $A$ can obtain the ticket and use it to gain access to $B$ at any time while $T_B$ is valid.\n\\end{itemize}\n\\end{minipage}\n\n\\subsubsection{Kerberos}\\label{Kerberos}\n\nSince Windows 2000, Kerberos V5 is the default Windows domain authentication method. \\\\\nA single sign-on (SSO) solution: users only need to enterusernames and passwords once for a session.\\\\\nProvide access selectively for a number of different online services using individual tickets. Establish session key to deliver confidentiality and integrity services for each service access.\n\n\\textbf{Three level protocol}\n\n\\begin{itemize}\n    \\item Level 1: Client $C$ interacts with authentication server $AS$ in order to obtain a ticket-granting ticket – happens once for a session (maybe a working day)\n    \\item Level 2: Client $C$ interacts with ticket-granting server $TGS$ in order to obtain a service ticket – happens once for each server during the session\n    \\item Level 3: Client $C$ interacts with application server $V$ in order to obtain a service – happens each time the client requires service during the session\n\\end{itemize}\n\n\\textbf{Level 1: interaction with authentication server}\n\n\\noindent\\begin{minipage}{0.6\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.72]{Images/kerberoslevel1.png}\n\\label{fig:fround}\n\\caption{Kerberos level 1 - interaction with authentication server.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.35\\textwidth}\n\\begin{itemize}\n    \\item $ticket_{tgs}=\\{K_{C,tgs},ID_C,T_1\\}_{K_{tgs}}$  for some validity period $T_1$\n    \\item Result: user has ticket-granting ticket which can be used to obtain different service-granting tickets.\n\\end{itemize}\n\\end{minipage}\n\\begin{itemize}\n    \\item $K_C$: symmetric key shared with authentication server $AS$ (typically generated by the workstation of $C$ from a password entered by $C$ at logon time)\n    \\item $K_{C,tgs}$: new symmetric key generated by $AS$ to share with the ticket-granting server $TGS$\n    \\item $N_1$: nonce used by $C$ to check that $K_{C,tgs}$ is fresh\n    \\item $K_{tgs}$: long-term key shared between $AS$ and $TGS$.\n\\end{itemize}\n\n\\textbf{Level 2: interaction with ticket-granting server}\n\n\\noindent\\begin{minipage}{0.6\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.72]{Images/kerberoslevel2.png}\n\\label{fig:fround}\n\\caption{Kerberos level 2 - interaction with ticket-granting server.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.38\\textwidth}\n\\begin{itemize}\n    \\item $ticket_{V}=\\{K_{C,V},ID_C,T_2\\}_{K_{V}}$  for some validity period $T_2$\n    \\item $authenticator_{TGS}=\\{ID_C,TS_1\\}_{K_{C,tgs}}$  for some timestamp $TS_1$\n    \\item Result: user has service-granting ticket which can be used to obtain access to a specific server.\n\\end{itemize}\n\\end{minipage}\n\\begin{itemize}\n    \\item $ticket_{tgs}$: same as sent in level 1\n    \\item $K_{C,V}$: session key to be used with server $V$ \n    \\item $N_2$: nonce used by $C$ to check that $K_{C,V}$ is fresh\n    \\item $TGS$ first obtains $K_{C,tgs}$ from $ticket_{tgs}$ and then checks if the fields in the authenticator are valid – includes checking that $TS_1$ is recent and that $C$ is authorized to access service $V$\n    \\item $AS$ and $TGS$ may be the same machine.\n\\end{itemize}\n\n\\textbf{Level 3: interaction with application server}\n\n\\noindent\\begin{minipage}{0.6\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.72]{Images/kerberoslevel3.png}\n\\label{fig:fround}\n\\caption{Kerberos level 3 - interaction with application server.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.38\\textwidth}\n\\begin{itemize}\n    \\item $authenticator_{V}=\\{ID_C,TS_2\\}_{K_{C,V}}$  for some timestamp $TS_2$\n    \\item Result: user has secure access to specific server $V$.\n\\end{itemize}\n\\end{minipage}\n\\begin{itemize}\n    \\item $ticket_{V}$: same as sent in level 2\n    \\item $K_{C,V}$ is contained in $ticket_V$ and was also sent to $C$ in the level 2 interaction\n    \\item The reply from $V$ is intended to provide mutual authentication so that $C$ can check it is using the right service $V$.\n\\end{itemize}\n\n\\textbf{Limitations}\n\nLimited scalability: even though different realms are supported, each realm needs to share a key with each other realm.\\\\\nSuited for corporate environments with shared trust (although public key variants exist).\\\\\nOffline password guessing is a possible attack when the client key $K_C$is derived from a human memorable password.\\\\\nKerberos standard does not specify how to use the session key once it is established.\n\n\\newpage\n\\section{Transport Layer Security (TLS) Protocol}\n\n\\subsection{Overview}\n\nMost widely used security protocol. Used to secure communications with banks, online shops, ...\\\\\nTLS 1.2 is currently the most popular version. For TLS 1.3 see \\ref{TLS1.3}.\\\\\nOften used to allow browsers to establish secure sessions with web servers.\\\\\nRuns primarly over TCP - variant DTLS runs over datagram protocols.\n\n\\subsubsection{Architecture}\n\n\\noindent\\begin{minipage}{0.54\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\centering\n\\includegraphics[scale=0.55]{Images/tlsprotocolstack.png}\n\\label{fig:fround}\n\\caption{TLS protocol stack.}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.55\\textwidth}\n3 higher level protocols:\n\\begin{itemize}\n    \\item TLS handshake protocol: set up sessions\n    \\item TLS alert protocol: signal events (3 types of alerts: warning alerts, 'close\\_notify' alerts, fatal alerts). Improper handling of alert messages can lead to truncation attacks.\n    \\item TLS change cipher spec protocol: change cryptographic algorithms. Normally used after the handshake protocol to indicate commencement of secure traffic.\n\\end{itemize}\n\\end{minipage}\n\n\\subsubsection{TLS ciphersuites}\n\nSpecify the public key algorithms used in the handshake protocol and the symmetric algorithms used in the record protocol.\\\\\n> 300 standardized suites, many weak and should not be used.\\\\\nExample: TLS\\_RSA\\_WITH\\_3DES\\_EDE\\_CBC\\_SHA.\n\nCommon TLS 1.2 ciphersuites:\n\\begin{itemize}\n    \\item Handshake algorithm (all use signed Diffie-Hellman):\n    \\begin{itemize}\n        \\item DHA-RSA: Ephemeral Siffie-Hellman with RSA signatures\n        \\item ECDHE-RSA: Elliptic curve DHE with RSA signatures\n        \\item DHE-DSS: DHE with DSS signatures\n    \\end{itemize}\n    \\item Record algorithms:\n    \\begin{itemize}\n        \\item AES-GCM: AES authenticated encryption with GCM mode\n        \\item AES-CBC-SHA256: AES in CBC mode with HMAC from SHA256\n        \\item CHACHA20-POLY1305: ChaCha stream cipher with Poly1305 MAC\n    \\end{itemize}\n\\end{itemize}\n\n\\subsection{TLS Record Protocol}\n\nProvides 2 services: message confidentiality and message integrity.\\\\\nServices can be provided by symmetric encryption and a MAC.\\\\\nFor TLS1.2+, theses services are often provided with authenticated encryption with associated data (AEAD) modes CCM or GCM.\\\\\nThe handshake protocol establishes symmetric keys(session keys) to use with these mechanisms.\n\n\\noindent\\begin{minipage}{0.54\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.55]{Images/tlsrecordprotocolformat.png}\n\\label{fig:fround}\n\\caption{TLS record protocol format.}\n\\end{center}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.42\\textwidth}\nRecord protocol header:\n\\begin{itemize}\n    \\item Content type: types are change-cipher-spec, alert, handshake, application-data\n    \\item Protocol version: major version (3 for TLS), minor version (1 for TLS v1.0, 2 for v1.1, 3 for v1.2)\n    \\item Length: length in octets of the data.\n\\end{itemize}\n\\end{minipage}\n\n\\subsubsection{Record protocol operation}\n\nFragmentation: Each application layer message is fragmented into blocks of 214 bytes or less.\\\\\nCompression: Optionally applied – default compression algorithm is null.\\\\\nAuthenticated data: consists of the (compressed) data, the header, and an implicit record sequence number.\\\\\nPlaintext: Compressed data and the MAC, if present.\\\\\nSession keys for the MAC and encryption algorithms, or AEAD algorithm, are established during the handshake protocol.\\\\\nThe encryption and MAC algorithms are specified in the negotiated ciphersuite.\n\n\\subsubsection{Cryptographic algorithms}\n\n\\begin{itemize}\n    \\item MAC:  The algorithm used is HMAC in all TLS versions using a negotiated hash function. SHA-2 is allowed only from TLS 1.2.\n    \\item Encryption:  Either a negotiated block cipher in CBC mode or a stream cipher. Most common block ciphers are AES and 3DES. RC4 originally supported in TLS1.2. For block ciphers, padding is applied after the MAC to make a multiple of the cipher block size.\n    \\item AEAD:  Allowed instead of encryption and MAC in TLS1.2. Usually AES in CCM or GCM modes. Authenticated additional data is the header and implicit record sequence number.\n\\end{itemize}\n\n\\subsection{TLS Handshake Protocol}\n\nNegotiates the version of TLS and the cryptographic algorithms to be used.\\\\\nEstablishes a shared session key for use in the record protocol.\\\\\nAuthenticates the server. Authenticates the client (optional).\\\\\nCompletes the session establishment.\\\\\nSeveral variations of the handshake: IRSA variant (still supported but not recommended), Diffie-Hellman variant (recommended), Pre-shared key variant, Mutual authentication or server-only authentication.\n\n\\subsubsection{Four phases}\n\n\\noindent\\begin{minipage}{0.54\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.7]{Images/tlshandshakephase12.png}\n\\label{fig:fround}\n\\end{center}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.42\\textwidth}\n\\begin{itemize}\n    \\item Phase 1: Client and server negotiation version, cipher suite and compression and exchange nonces.\n    \\item Phase 2: Server sends certificate and key exchange message (if needed).\n\\end{itemize}\n\\end{minipage}\n\n\\noindent\\begin{minipage}{0.54\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.7]{Images/tlshandshakephase34.png}\n\\label{fig:fround}\n\\end{center}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.42\\textwidth}\n\\begin{itemize}\n    \\item Phase 3: Client sends certificate and key exchange message.\n    \\item Phase 4: Client and server start secure communications.\n\\end{itemize}\nFinished messages include a check value (pseudo-random function) of all the previous messages.\n\\end{minipage}\n\nMain messages:\n\\begin{itemize}\n    \\item Client hello: States highest version of TLS available, advertises ciphersuites available to the client and sends client nonce $N_C$.\n    \\item Server hello: Returns the selected version and ciphersuite and sends server nonce $N_S$ \n    \\item Server key exchange: Server’s input to key exchange.\n    \\item Client key exchange: Client input to key exchange.\n    \\item Change-cipher-spec: Switch to newly negotiated ciphersuite for record .\n\\end{itemize}\n\n\\textbf{Generating session keys}\n\nThe master secret $ms$ is defined using the premaster secret $pms$: $ms=PRF(pms,“master secret”,N_C\\Vert N_S)$.\\\\\nAs much keying material is generated as is required by the ciphersuite using: $k=PRF(ms,“key expansion”,N_S\\Vert N_C)$.\\\\\nIndependent session keys are partitioned from $k$ in each direction (a write key and a read key on each side).\\\\\nDepending on ciphersuite, keying material may include: encryption key, MAC key, IV.\n\n\\textbf{Pseudorandom function PRF}\n\nThe PRF (pseudo-random function) is built from HMAC with a specified hash function: in TLS 1.0 and 1.1 based on a combination of MD5 and SHA-1; in TLS 1.2  based on SHA-2.\\\\\nFor example, in TLS 1.2: $PRF(K,label,r)  =HMAC(K,A(1) \\Vert label \\Vert r) \\Vert HMAC(K,A(2)\\Vert label \\Vert r)\\Vert...$ where $A(0) =r, A(i) =HMAC(K,A(i−1))$ and HMAC uses a specified SHA-2 variant, typically SHA256, as its hash function.\n\n\\subsubsection{Handshake variants}\n\n\\textbf{Ephemeral Diffie–Hellman handshake variant}\n\nServer key exchange: Diffie–Hellman generator and group parameters and server ephemeral Diffie-Hellman value, all signed by server.\\\\\nClient key exchange: Client ephemeral Diffie-Hellman value. This is optionally signed by the client if the client certificate is used.\\\\\nPre-master secret $pms$ is the shared Diffie–Hellman secret.\\\\\nProvides forward secrecy and therefore recommended today.\n\n\\textbf{RSA Handshake variant}\n\nServer key exchange: Not used.\\\\\nClient key exchange: Key transport of pre-master secret $pms$. Client selects a random pre-master secret $pms$. Client encrypts $pms$ with the server’s public key and sends the ciphertext to the server. Server decrypts using its private key to recover $pms$.\\\\\nNo forward secrecy and NOT recommended today.\n\n\\textbf{Diffie-Hellman (DH)}\n\nThe parties use static Diffie–Hellman with certified keys — if the client does not have a certificate (usual on the Internet) then the client uses an ephemeral Diffie-Hellman key.\n\n\\textbf{Anonymous Diffie-Hellman (DH\\_Anon)}\n\nThe ephemeral Diffie-Hellman keys are not signed at all, so only protects against passive eavesdropping.\n\n\\subsection{Attacks}\n\n\\subsubsection{TLS limitations}\n\nMany servers do not support the latest version of TLS and/or have not protected against known attacks.\\\\\n\\href{https://www.ssllabs.com/ssl-pulse/}{SSL Pulse Survey} gives an up-to-date picture of current attacks.\n\n\\subsubsection{BEAST}\n\nBrowser Exploit Against SSL/TLS: exploits non-standard use of IV in CBC mode encryption - IVs are chained from previous ciphertexts.\\\\\nAllows attacker to recover plaintext byte by byte.\\\\\nFrom TLS 1.1 only random IV is allowed.\\\\\nMitigation strategy (implemented in most browsers): splitting plaintext into first byte + remainder to force a randomised IV including a MAC computation.\\\\\nNo longer considered a realistic threat.\n\n\\subsubsection{CRIME and BREACH}\n\nSide channel attacks base on compression - different inputs result in different amounts of compression.\\\\\nCRIME (Compression Ratio Info-leak Made Easy) exploits compression in TLS, while BREACH (Browser Reconnaissance and Exfiltration via Adaptive Compression of Hypertext) exploits compression in HTTP.\\\\\nCommonly recommended to switch off compression in TLS but switching off in HTTP too results in big performance penalty.\n\n\\subsubsection{Padding oracles and POODLE}\n\nA padding oracle is a way for an attacker to know if a message in a ciphertext was correctly padded. Shown how in theory CBC mode encryption can provide a padding oracle due to its error propagation properties.\\\\\nPOODLE (Padding Oracle On Downgraded Legacy Encryption) published in October 2014 forces downgrade to SSL 3.0 and then runs padding oracle attack.\\\\\nMain mitigation: uniform error response, so that the attacker cannot distinguish padding errors from MAC errors.\n\n\\subsubsection{Heartbleed bug}\n\nAn implementation error in OpenSSL. Based on missing bounds check in heartbeat messages.\\\\\nAllows memory leakage from server which is likely to include session keys and long-term keys.\n\n\\subsubsection{Man-in-the-middle}\n\nMITM attacks: rely on issuing a new certificate and installing a root certificate in the browser.\n\n\\newpage\n\\section{TLS 1.3}\\label{TLS1.3}\n\nTLS 1.3 is the latest version of the Transport Layer Security protocol and has significant changes from earlier versions affecting both security and efficency.\n\n\\subsection{Development - Why was TLS 1.3 needed ?}\n\nEfficiency: TLS1.2- nneds at least 2 round trip times (RTT) before data can be sent.\\\\\nSecurity: problems in earlier version (too complex, support of old/weak ciphersuites).\n\n\\subsection{Differences}\n\n\\subsubsection{Protocols}\n\nHandshake: similar purpose but fewer rounds.\\\\\nRecord: similar to TLS 1.2.\\\\\nAlert: similar to TLS 1.2.\\\\\nNo TLS change cipher spec protocol.\n\n\\subsubsection{Some changes}\n\n\\noindent\\begin{minipage}{0.48\\textwidth}% adapt widths of minipages to your needs\nSome items removed:\n\\begin{itemize}\n    \\item static RSA and DH key exchange\n    \\item renegotiation\n    \\item SSL 3.0 negotiation\n    \\item DSA in finite fields\n    \\item data compression\n    \\item non-AEAD cipher suites\n\\end{itemize}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.48\\textwidth}\nSome items added:\n\\begin{itemize}\n    \\item encrypted content type\n    \\item 0-RTT mode (from pre-shared key)\n    \\item post-handshake client authentication through 'certificate verify' signature\n    \\item more AEAD ciphersuites\n\\end{itemize}\n\\end{minipage}\n\n\\subsubsection{TLS 1.3 handshake protocol}\n\n\\textbf{Hello messages}\nClient sends (optimistic) keyshare field in client hello for one or more anticipated ciphersuites.\\\\\nServer can obtain session key on receipt of client hello if: server accepts one of the clients ciphersuites, client keyshare matches the accepted ciphersuite.\\\\\nIf the above conditions fail then: server sends an optional Hello Retry Request, client responds if there is an acceptable alternative ciphersuite.\\\\\nUsually this results in saving a whole round trip of communication.\n\n\\textbf{Other messages}\n\nOnly client and server hello/keyshare messages are not cryptographically protected.\\\\\nKey calculation uses standard HKDF (hash key derivation function) to derive the individual keys.\\\\\nSeveral different key types derived from master secret: 'handshake traffic keys' to protect handshake protocol, 'application traffic keys' for client-server traffic, 'early data keys' for 0-RTT data.\n\n\\textbf{TLS 1.2 comparison}\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.7]{Images/handshakecomparison.png}\n\\label{fig:fround}\n\\caption{Handshake comparison - TLS 1.2 to TLS 1.3}\n\\end{center}\n\\end{figure}\n\n\\subsubsection{Client authentication}\n\nIn TLS 1.2 and 1.3 it is optional for the client to send a certificate and authenticate using a 'CertificateVerify' message. The 'CertificateVerify' message includes a signature which can be verified using the public key in the certificate.\\\\\nTLS 1.3 adds a 'post-handshake client authentication' extension; if this is used then the server may request client authentication at any time after the handshake completed. The client responds with its certificate and a signature in the form of 'CertificateVerify'.\n\n\\subsubsection{0-RTT in TLS 1.3}\n\n\\noindent\\begin{minipage}{0.48\\textwidth}% adapt widths of minipages to your needs\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.58]{Images/0rtttls13.png}\n\\label{fig:fround}\n\\caption{0-RTT in TLS 1.3.}\n\\end{center}\n\\end{figure}\n\\end{minipage}%\n\\hfill%\n\\begin{minipage}{0.48\\textwidth}\n\\begin{itemize}\n    \\item In a 0-RTT key establishment parties can start sending application data immediately, so-called early data\n    \\item Based on pre-shared key (PSK)\n    \\item PSK can either be agreed outside TLS or from an earlier TLS session\n    \\item At the end of the handshake protocol the server can send to the client one or more new session tickets as PSKs\n    \\item A client may start a new PSK session without negotiating version and ciphersuite.\n\\end{itemize}\n\\end{minipage}\n\n\\subsubsection{Ciphersuites}\n\nSame cipher suite coding as previous versions.\\\\\nTLS 1.2 and lower cipher suite values cannot be used with TLS 1.3 and vice versa.\\\\\nHandshake always uses Diffie-Hellman option so (ECDHE) not explicitly stated.\\\\\nMandatory to implement ciphersuite: TLS\\_AES\\_128\\_GCM\\_SHA256.\\\\\nRecommended ciphersuites: TLS\\_AES\\_256\\_GCM\\_SHA384, TLS\\_CHACHA20\\_POLY1305\\_SHA256, TLS\\_AES\\_128\\_CCM\\_SHA256, TLS\\_AES\\_128\\_CCM\\_8\\_SHA256.\n\n\\subsubsection{ChaCha algorithm}\n\nStream cipher defined in RFC 8439 together with a message authentication code (MAC) called Poly1305.\\\\\nFaster than AES, except for processors with AES hardware support (most modern desktop computers).\\\\\nCombines $\\oplus$, addition modulo $2^32$ and rotation operations over 20 rounds to produce 512 bits of keystream.\\\\\n256-bit key.\n\n\\subsubsection{Main improvements}\n\n\\begin{itemize}\n    \\item Efficiency:\n    \\begin{itemize}\n        \\item Saving of one RTT in handshake\n        \\item Can set up follow-up session with 0-RTT\n    \\end{itemize}\n    \\item Security:\n    \\begin{itemize}\n        \\item Only forward-secret key exchange allowed\n        \\item Many legacy ciphersuites no longer allowed\n        \\item Renegotiation option removed\n        \\item Formal security proofs\n    \\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Selfie attack}\n\nPublished 2019.\\\\\nBreaks mutual authentication in PSK mode.\\\\\nVictim party Alice must be prepared to act as a client and a server.\\\\\nSuppose Alice shares a PSK with Bob.\\\\\nAttacker reflects messages back to herself so client Alice believes she is talking to Bob while she is actually talking with server Alice.\\\\\nCase is not covered in formal analysis of TLS 1.3.\\\\\nCan be prevented by forbidding to share PSK between more than one server and one client.\n\n\\newpage\n\\section{IP Layer Security (IPsec)}\n\nProvides protection for any higher layer protocol, including arbitrary TCP and UDP sessions.\\\\\nUses encryption, authentication and key management algorithms.\\\\\nMost commonly used to provide Virtual Private Networks(VPNs).\\\\\nProvides a security architecture for both IPv4 and IPv6.\n\n\\subsection{Security services}\n\n\\begin{itemize}\n    \\item Message confidentiality: Protects against unauthorised data disclosure by the use of encryption.\n    \\item Message integrity: Detects if data has been changed by using a message authentication code (MAC) or authenticated encryption.\n    \\item Limited traffic analysis protection: Eavesdropper on network traffic should not know which parties communicate, how often, or how much data is sent.\n    \\item Message replay protection: The same data is not replayed and data is not delivered badly out of order.\n    \\item Peer authentication: Each IPsec endpoint confirms the identity of the other IPsec endpoint.\n\\end{itemize}\n\n\\subsection{Architectures}\n\n\\subsubsection{Gateway-to-gateway}\n\nProvides secure network communications between 2 networks.\\\\\nNetwork traffic is routed through the IPsec connection, protecting it appropriately.\\\\\nOnly protects data between the two gateways.\\\\\nMost often used when connecting two secured networks, such as linking a branch office to headquarters over the Internet.\\\\\nCan be less costly than private wide area network (WAN) circuits.\n\n\\subsubsection{Host-to-gateway}\n\nCommonly used to provide secure remote access.\\\\\nThe organization deploys a virtual private network (VPN) gateway onto their network.\\\\\nEach remote access user establishes a VPN connection between the local computer (host) and the gateway.\\\\\nVPN gateway may be a dedicated device or part of another network device.\\\\\nMost often used when connecting hosts on unsecured networks to resources on secured networks.\n\n\\subsubsection{Host-to-host}\n\nTypically used for special purpose needs, such as system administrators performing remote management of a single server.\\\\\nOnly model that provides protection for data throughout its transit (end-to-end).\\\\\nResource-intensive to implement and maintain in terms of user and host management.\\\\\nAll user systems and servers that will participate in VPNs need to have VPN software installed and/or configured.\\\\\nKey management is often accomplished through a manual process.\n\n\\subsection{Protocols}\n\n\\subsubsection{Types}\n\n\\begin{itemize}\n    \\item Encapsulating Security Payload (ESP): Can provide confidentiality, authentication, integrity and replay protection.\n    \\item Authentication Header (AH): Authentication, integrity and replay protection, but no confidentiality and is now deprecated.\n    \\item Internet Key Exchange (IKE): negotiate, create, and manage session keys in so-called 'security associations'.\n\\end{itemize}\n\n\\subsubsection{Setting up IsPsec connection}\n\nKey exchange uses IKEv2 protocol (uses Diffie-Hellman protocol authenticated with public keys in X.509 certificates).\\\\\nIncludes 'cookies' to mitigate denial-of-service attacks: client must return a time-dependent cookie value before the server proceeds; they provide proof of reachability before any expensive cryptographic processing is completed.\n\n\\subsubsection{Security associations}\n\nA security association (SA) contains info needed by an IPsec endpoint to support an IPSec connection.\\\\\nCan include cryptographic keys and algorithms, key lifetimes, security parameter index (SPI), and security protocol identifier (ESP or AH).\\\\\nSPI is included in the IPSec header to associate a packet with the appropriate SA.\\\\\nSA tells the endpoint how to process inbound IPSec packets or how to generate outbound packets.\\\\\nSAs are needed for each direction of connection.\\\\\nIKEv2 is used to establish keys to use in SAs.\n\n\\subsubsection{Cryptographic suites}\n\nSimilar to TLS ciphersuites: standardised suites (both public key and symmetric key algorithms).\\\\\nSpecific groups available for Diffie-Hellman, both in finite fields and on elliptic curves.\\\\\n3DES or AES can be used for encryption, either in CBC or GCM.\\\\\nHMAC or CMAC (variant) is used for integrity if GCM mode is not used.\n\n\\subsection{Modes}\n\nEach protocol (ESP or AH) can operate in transport or tunnel mode.\n\\begin{itemize}\n    \\item Transport mode: Maintains IP header of the original packet and protects payload — generally only used in host-to-host architectures.\n    \\item Tunnel mode: Original packet encapsulated into a new one, payload is original packet — typical use is gateway-to-gateway architecture\n\\end{itemize}\nWe show the pictures for IPv4 — there are slight differences for IPv6.\n\n\\subsubsection{Protocol components}\n\n\\begin{itemize}\n    \\item ESP header: contains security parameter index (SPI) identifying the SA and sequence numbers\n    \\item ESP trailer: contains padding and padding length - may also include extra padding to enhance traffic flow confidentiality\n    \\item ESP Auth: contains MAC of the encrypted data and ESP header - may not be required if an authenticated encryption mode is used.\n\\end{itemize}\n\n\\subsubsection{Transport mode ESP}\n\nOriginal IP packet:\n\\begin{center}\n\\begin{tabular}{ | c | c | }\n\\hline\nIP header & Data\n\\end{tabular}\n\\end{center}\nIP packet protected by Transport-ESP:\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.58]{Images/ippackettransportesp.png}\n\\label{fig:fround}\n\\end{center}\n\\end{figure}\n\nData after the original IP header is padded by adding an ESP trailer and result encrypted using the symmetric cipher and key in the SA.\\\\\nAn ESP header is prepended.\\\\\nIf an SA uses the authentication service, an ESP MAC is calculated over the data prepared so far and appended.\\\\\nOriginal IP header is prepended, but some fields in the original IP header must be changed: protocol field changes from TCP to ESP, total length field must be changed to reflect the addition of the ESP header, checksums must be recalculated.\n\n\\subsubsection{Tunnel mode ESP}\n\nOriginal IP packet:\n\\begin{center}\n\\begin{tabular}{ | c | c | }\n\\hline\nIP header & Data\n\\end{tabular}\n\\end{center}\nIP packet protected by Tunnel-ESP:\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.58]{Images/ippackettunnelesp.png}\n\\label{fig:fround}\n\\end{center}\n\\end{figure}\n\nEntire original packet is padded by adding an ESP trailer and the result encrypted using the symmetric cipher and key agreed in the SA.\\\\\nESP header is prepended.\\\\\nIf the SA uses the authentication service, an ESP MAC is calculated over the data prepared so far and appended.\\\\\nNew outer IP header is prepended.\\\\\nInner IP header of the original IP packet carries the ultimate source and destination addresses.\\\\\nOuter IP header may contain distinct IP addresses such as addresses of security gateways.\\\\\nOuter IP header protocol field is set to ESP.\n\n\\subsection{Security}\n\nActive attacks have been demonstrated for encryption-onlymode of ESP protocol — now widely understood that providing encryption without integrity is insecure.\\\\\nUnlike earlier versions of IPsec, the 2005 version does not require implementations to support encryption-only mode, but still allows it.\\\\\nESP applies encryption before MAC in normal usage.\\\\\nUsing AH, a MAC can be applied before encryption, as in TLS. Attacks have been demonstrated on such configurations.\\\\\nFormal analysis has shown that IPsec key exchange protocol (IKEv2) has no significant weaknesses.\n\n\\newpage\n\\section{Email Security and Secure Messaging}\n\n\\subsection{Email Security Requirements}\n\n\\subsubsection{Email architecture}\n\nMessage user agent (MUA) connects client to mail system. Uses SMTP to send mail to message submission agent(MSA) and POP or IMAP to retrieve mail from message store (MS).\\\\\nMessage handling system (MHS) transfers message from MSA to MS via one or more message transfer agent (MTA).\\\\\nSimple message transfer protocol (SMTP) is mail transmission protocol defined in RFC 5321.\n\n\\subsubsection{Threats}\n\nUsual 'CIA' categories.\\\\\nContent may require confidentiality/authentication.\\\\\nAvailability of the email service may be threatened.\\\\\nMetadata in header information is a significant source of attacker information.\n\n\\subsection{Email security}\n\n\\subsubsection{Link security}\n\n\\textbf{STARTTLS}\n\nExtensions to mail protocols SMTP, POP and IMAP to run over TLS connections.\\\\\nProvides link-by-link security, not end-to-end security.\\\\\nOpportunistic use of TLS security (encryption) — use it if possible $\\Rightarrow$ vulnerable to so-called STRIPTLS attacks – attacker interrupts TLS negotiation and connection falls back to plaintext transmission.\\\\\nDefined for IMAP and POP3 (RFC 2595) and for SMTP (RFC 3207) amongst other protocols.\\\\\nWidely used by prominent email providers including Gmail and Microsoft Outlook.\n\n\\textbf{DomainKeys Identified Mail (DKIM)}\n\nAllows sending mail domain to sign outgoing mail using RSA signatures (currently supported signature algorithm).\\\\\nReceiving domain can verify origin of mail.\\\\\nWidely used by prominent email providers including Gmail.\\\\\nHelps prevent email spoofing and hence reduce spam and phishing.\\\\\nPublic verification key of sending domain retrieved using DNS.\n\n\\begin{figure}[H]\n\\begin{center}\n\\includegraphics[scale=0.59]{Images/exampledkimsignature.png}\n\\label{fig:fround}\n\\caption{Example DKIM signature.}\n\\end{center}\n\\end{figure}\n\nThe ’d=’ and ’s=’ parts of the DKIM signature specify domain and selector.\\\\\nThe relevant public key is in the DNS record for the hostdefined by the host name: \\texttt{[selector].\\_domainkey.[domain]} where \\texttt{s=} value is the selector and \\texttt{d=} value is the domain.\\\\\nIn the example header above the nslookup would be: \\texttt{nslookup -type=txt 20161025.\\_domainkey.gmail.com}.\n\n\\subsubsection{End-to-end security}\n\n\\textbf{Email processing}\n\nProtection of email message contents.\\\\\nHybrid encryption — a new random “session key” is generated for each object (message) and the session key is encrypted with the long-term public key of recipient.\\\\\nSigning using RSA or DSA signatures.\\\\\nCompression using Zip.\\\\\nCoding using radix-64 to ensure that binary strings can be sent in email body.\n\n\\textbf{PGP encryption}\n\nSession keys are encrypted using asymmetric encryption. OpenPGP requires support for ElGamal encryption and recommends also to support RSA encryption.\\\\\nEncryption of message text using symmetric key encryption – OpenPGP requires support for 3DES with three keys (168 bits in total) and recommends also AES-128 and CAST5. Other algorithms are also defined.\\\\\nCompression is applied before encryption.\\\\\nEncryption can be applied independently of signing (no requirement for authenticated encryption).\n\n\\textbf{PGP signatures}\n\nPlaintext message is optionally signed with sender’s private key.\\\\\nOpenPGP standard requires support for RSA signatures.\\\\\nDSA signatures also defined.\\\\\nRSA signed messages are hashed with SHA1 (support required in standard) or other SHA2 hash functions.\n\n\\textbf{OpenPGP PKI}\n\nUsed in PGP email security.\\\\\nIncludes ID, public key, validity period and a self-signature.\\\\\nNo certification authorities — keys can be signed by anyone.\\\\\nVarious key servers used to store keys, such as \\href{https://keys.openpgp.org/about}{https://keys.openpgp.org/about}.\\\\\nOften known as the web of trust.\\\\\nAutocrypt is an attempt to automate key management by including key information in the mail header — does not protect against active attacks.\n\n\\textbf{Problems with PGP}\n\nComplicated for standard user to understand public key cryptography.\\\\\nTypical problems: generating new keys securely, moving keys between devices, renewing keys.\\\\\nNot available on iOS (although GnuPG exists now).\\\\\nOutdated cryptographic algorithms still used: SHA1, CAST,Blowfish, ...\\\\\nNo support for SHA3 or authenticated encryption such as GCM.\\\\\nA lot of metadata is available to an eavesdropper including: file length, encryption algorithm used, key identity of recipients.\\\\\nNo forward secrecy.\\\\\nDoes not support streaming mode or random access decryption.\n\n\\textbf{S/MIME}\n\nSimilar security features to PGP but different format for messages and not interoperable.\\\\\nRequires X.509 format certificates instead of web of trust.\\\\\nSupported natively by most popular mail clients.\n\n\\subsection{Secure Messaging}\n\n\\subsubsection{Differences with email}\n\nMost instant messages are part of an interactive conversation with many messages over a long time.\\\\\nProprietary servers used to manage accounts.\\\\\nOften (not necessarily) native applications are used.\n\n\\subsubsection{Security}\n\nStandard CIA security services important as usual.\\\\\nForward secrecy: important especially for long sessions (use of 'medium-term' public keys stored at the server).\\\\\nPost-compromise security (self-healing): an attacker who obtains a long-term key should b locked out again after communication resumes.\n\nNo 'standardized' security protocol.\\\\\nDifferent ways to do:\n\\begin{itemize}\n    \\item Instagram, Snapchat, ...: no Ent-to-End encryption\n    \\item (Facebook) Messenger: no End-to-End by default\n    \\item iMessage, Whatsapp, Telegram are (allegedly) quite secure\n    \\item Signal Messenger is considered to be the best option.\n\\end{itemize}\n\n\\subsubsection{Signal protocol}\n\nSignal server sets up initial authentication of user and registers initial public keys.\\\\\nPublic keys at the server are used to set up initial communication between users.\\\\\nKey exchange uses elliptic curve Diffie–Hellman.\\\\\nAES in CBC mode with HMAC (SHA256) used for message protection.\\\\\nProtocol is used in Signal app and claimed also to be in WhatsApp and Facebook Messenger (closed source).\n\n\\textbf{Ratcheting}\n\nA ratchet is a device which is easy to move forward but blocked from moving backward.\\\\\nSignal uses a new unique message key for every message exchanged.\\\\\nWhen successive messages sent in the same direction the message key is updated with a 'symmetric ratchet' by applying a function such as HMAC.\\\\\nWhen a new message is returned in the opposite direction a new Diffie-Hellman ephemeral key is used to compute the new message key: this is the 'Diffie-Hellman ratchet'.\\\\\nSee \\href{https://signal.org/docs/specifications/doubleratchet/}{https://signal.org/docs/specifications/doubleratchet/}\n\n\\subsubsection{Group messaging}\n\nNo good alternative for Diffie-Hellman is known in the multi-party case.\\\\\nSignal uses a simple key distribution method for group messaging.\\\\\nCurrently a research effort is under way to develop Messaging Layer Security (mls) standard: \\href{https://datatracker.ietf.org/wg/mls/about/}{https://datatracker.ietf.org/wg/mls/about/}.\n\n% Inserting bibliography\n\\newpage\n\\pagenumbering{alph}\n\\printbibliography\n\n% Inserting appendix with separate settings\n%\\addappendix\n%\\import{./Appendices/}{example_appendix}\n\n% End of document\n\\end{document}\n", "meta": {"hexsha": "3004b38134c60279de28484949d51124331b2ce6", "size": 115251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "main.tex", "max_stars_repo_name": "jona-sch/CryptographyCheatSheet", "max_stars_repo_head_hexsha": "4dde25c980180ca3d69c2be2426d20c8f89b74bc", "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": "main.tex", "max_issues_repo_name": "jona-sch/CryptographyCheatSheet", "max_issues_repo_head_hexsha": "4dde25c980180ca3d69c2be2426d20c8f89b74bc", "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": "main.tex", "max_forks_repo_name": "jona-sch/CryptographyCheatSheet", "max_forks_repo_head_hexsha": "4dde25c980180ca3d69c2be2426d20c8f89b74bc", "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.2137232846, "max_line_length": 630, "alphanum_fraction": 0.7459891888, "num_tokens": 31349, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391595913457, "lm_q2_score": 0.8774767810736693, "lm_q1q2_score": 0.7576060783881985}}
{"text": "\\input{../common/common.tex}\n\n\\title{Math notes - Groovy Numbers}\n\\author{Uwe Hoffmann}\n\\hypersetup{colorlinks, pdftitle={Math notes - Groovy Numbers}}\n\n\\begin{document}\n\n\\setcounter{chapter}{1}\n\\section*{Groovy Numbers}\n\n\\vspace{10 mm}\n\\begin{problem}\n$x \\in \\mathbb{R}$ is said to be a groovy number iff $\\exists\\  n \\in \\mathbb{N}$ such that $x = \\sqrt{n} + \\sqrt{n + 1}$. Prove that if $x$ is groovy, then $\\forall r \\in \\mathbb{N}:\\ x^r$ is groovy.\n\\end{problem}\n\n\\subsection{Binomial Expansion}\n\nIn this section we explore a property of the binomial power expansion\n\n\\begin{equation*}\n(a + b)^r = \\sum_{k = 0}^r \\binom{r}{k} a^{r - k} b^k\n\\end{equation*}\n\n\\noindent We define $\\mathbb{N}_r = \\{k \\in \\mathbb{N}_0: 0 \\leq k \\leq r\\}$ and its partition into two subsets \\mbox{$\\mathbb{N}_r = \\mathbb{E}_r \\cup \\mathbb{O}_r$}, with  \\mbox{$\\mathbb{E}_r = \\{k \\in \\mathbb{N}_r: k = 2 u, u \\in \\mathbb{N}_0 \\}$} and \\\\\n\\mbox{$\\mathbb{O}_r = \\{k \\in \\mathbb{N}_r: k  = 2 u + 1, u \\in \\mathbb{N}_0 \\}$}. We then partition the binomial power expansion into two sums:\n\n\\begin{equation*}\n(a + b)^r = \\sum_{k = 0}^r \\binom{r}{k} a^{r - k} b^k = \\sum_{k \\in \\mathbb{E}_r}  \\binom{r}{k} a^{r - k} b^k + \\sum_{k \\in \\mathbb{O}_r}  \\binom{r}{k} a^{r - k} b^k\n\\end{equation*}\n\n\\noindent Let \n\n\\begin{equation*}\nE(a, b, r) = \\sum_{k \\in \\mathbb{E}_r}  \\binom{r}{k} a^{r - k} b^k \\ \\text{and} \\ O(a, b, r) = \\sum_{k \\in \\mathbb{O}_r}  \\binom{r}{k} a^{r - k} b^k\n\\end{equation*}\n  \n\\noindent Then\n\n\\begin{align*}\n(a^2 - b^2)^r &= (a + b)^r (a - b)^r \\\\\n&= (E(a, b, r) + O(a, b, r)) (E(a, -b, r) + O(a, -b, r))\n\\end{align*}\n\n\\noindent But\n\n\\begin{equation*}\nE(a, -b, r) = E(a, b, r) \\ \\text{and}\\  O(a, -b, r) = - O(a, b, r) \n\\end{equation*}\n\n\\noindent so\n\n\\begin{align*}\n(a^2 - b^2)^r &= (a + b)^r (a - b)^r \\\\\n&= (E(a, b, r) + O(a, b, r)) (E(a, -b, r) + O(a, -b, r)) \\\\\n&= (E(a, b, r) + O(a, b, r)) (E(a, b, r) - O(a, b, r)) \\\\\n&= E(a, b, r)^2 - O(a, b, r)^2\n\\end{align*}\n\n\\noindent We therefore proved \n\n\\begin{lem}\\label{even_odd}\n\\begin{equation*}\n(a^2 - b^2)^r = E(a, b, r)^2 - O(a, b, r)^2\n\\end{equation*}  \n\\end{lem}\n\n\\subsection{Solution}\n\nUsing lemma \\ref{even_odd} with $a = \\sqrt{n}$ and $b = \\sqrt{n + 1}$, we get\n\n\\begin{equation}\n(-1)^r = E(\\sqrt{n}, \\sqrt{n + 1}, r)^2 - O(\\sqrt{n}, \\sqrt{n + 1}, r)^2\\tag{L}\n\\end{equation} \n\n\\begin{lem}\\label{squared}\n\\begin{gather*}\nE(\\sqrt{n}, \\sqrt{n + 1}, r)^2 \\in \\mathbb{N}, \\\\\nO(\\sqrt{n}, \\sqrt{n + 1}, r)^2 \\in \\mathbb{N}\n\\end{gather*}\n\\end{lem}\n \n\\begin{proof}\n\n\\noindent We will look at two cases: $r$ even and $r$ odd.\n\n\\noindent \\textbf{Case 1.} For $r = 2 u$ even we have\n\n\\begin{align*}\nE(\\sqrt{n}, \\sqrt{n + 1}, 2 u) &=  \\sum_{k = 0}^u  \\binom{2 u}{2 k} (\\sqrt{n})^{2 u - 2 k} (\\sqrt{n + 1})^{2 k} \\\\\n&=  \\sum_{k = 0}^u  \\binom{2 u}{2 k} (\\sqrt{n})^{2 (u - k)} (\\sqrt{n + 1})^{2 k} \\\\\n&=  \\sum_{k = 0}^u  \\binom{2 u}{2 k} n^{u - k} (n + 1)^k \\\\\n\\end{align*}\n\n\\noindent so $E(\\sqrt{n}, \\sqrt{n + 1}, r) \\in \\mathbb{N}$, and therefore $E(\\sqrt{n}, \\sqrt{n + 1}, r)^2 \\in \\mathbb{N}$.\n\n\\begin{align*}\nO(\\sqrt{n}, \\sqrt{n + 1}, 2 u) &=  \\sum_{k = 0}^{u - 1}  \\binom{2 u}{2 k + 1} (\\sqrt{n})^{2 u - 2 k - 1} (\\sqrt{n + 1})^{2 k + 1} \\\\\n&=  \\frac{\\sqrt{n + 1}}{\\sqrt{n}} \\sum_{k = 0}^{u - 1}  \\binom{2 u}{2 k + 1} (\\sqrt{n})^{2 (u - k)} (\\sqrt{n + 1})^{2 k} \\\\\n&=  \\frac{\\sqrt{n + 1}}{\\sqrt{n}} \\sum_{k = 0}^{u - 1}  \\binom{2 u}{2 k + 1} n^{2 (u - k)} (n + 1)^{k} \\\\\n&=  \\sqrt{n (n + 1)} \\sum_{k = 0}^{u - 1}  \\binom{2 u}{2 k + 1} n^{2 (u - k) - 1} (n + 1)^{k} \\\\\n\\end{align*}\n\n\\noindent so $O(\\sqrt{n}, \\sqrt{n + 1}, r)^2 \\in \\mathbb{N}$.\n\n\\noindent \\textbf{Case 2.}  $r = 2 u + 1$ is handled in a similar fashion by factoring out $\\sqrt{n}$ and $\\sqrt{n + 1}$ with the remainder $\\in \\mathbb{N}$.\n\n\\end{proof}\n\n\\noindent From lemma \\ref{squared} and equation (L) it follows that  $E(\\sqrt{n}, \\sqrt{n + 1}, r)^2$ and $O(\\sqrt{n}, \\sqrt{n + 1}, r)^2$ are consecutive natural numbers. Let\n\n\\begin{equation*}\nm = min(E(\\sqrt{n}, \\sqrt{n + 1}, r)^2, O(\\sqrt{n}, \\sqrt{n + 1}, r)^2) \\in \\mathbb{N}\n\\end{equation*}\n\n\\noindent Then\n\n\\begin{equation*}\nx^r = (\\sqrt{n} + \\sqrt{n + 1})^r = \\sqrt{m} + \\sqrt{m + 1}\n\\end{equation*}\n\n\\end{document}\n\n", "meta": {"hexsha": "3c0a3c1b3814ca6c7b0836d6d5adb09bc4c69178", "size": 4185, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "groovy/groovy.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": "groovy/groovy.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": "groovy/groovy.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": 33.75, "max_line_length": 257, "alphanum_fraction": 0.5407407407, "num_tokens": 1942, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.88720460564669, "lm_q2_score": 0.8539127566694178, "lm_q1q2_score": 0.7575953305375688}}
{"text": "\\chapter{Frequency Mismatch}\n\\section{Carrier frequency mismatch in single TX/RX}\nConsidering the transmitted In-phase signal $S_I(t)$, Quad-phase signal $S_Q(t)$ and the carrier frequency of\ntransmitter $f_{c1}$. The transmitted signal can be writted as $S(t)$\n\n\\begin{equation}\nS(t) = S_I(t) \\times cos(2\\pi \\times f_{c1} \\times t ) + S_Q(t) \\times sin(2\\pi \\times f_{c1} \\times f)\n\\end{equation}\n\nIgnoring the channel characteristic and absense of noice, the received signal $R(t) = S(t)$. If there is a\nmismatch in carrier frequency, the receiver carrier frequency $f_{c2} \\neq f_{c1}$. The received In-phase signal\ncan be expressed as \\\\\n$r_I(t) = R(t) \\times cos(2\\pi \\times f_{c2} \\times t)$.\n\n\\begin{eqnarray}\nr_I(t) = \\left[S_I(t) \\times cos(\\omega_{c1}t) + S_Q(t) \\times sin(\\omega_{c1}t)\\right] \\times cos(\\omega_{c2}t) \\\\\nr_I(t) = S_I(t) \\times cos(\\omega_{c1}t) \\times cos(\\omega_{c2}t) + S_Q(t) \\times sin(\\omega_{c1}t) \\times cos(\\omega_{c2}t)\n\\end{eqnarray}\n\nWhere $\\omega_{c1,2} = 2\\pi\\times f_{c1,2}$. Simplifying the equation by product to sum identities.\n\\begin{equation}\nr_I(t) = \n\\tfrac{1}{2}S_I(t)\\left[cos((\\omega_{c1}-\\omega_{c2})t) + cos((\\omega_{c1}+\\omega_{c2})t)\\right] + \n\\tfrac{1}{2}S_Q(t)\\left[sin((\\omega_{c1}-\\omega_{c2})t) + sin((\\omega_{c1}+\\omega_{c2})t)\\right]\n\\end{equation}\n\nBy removing high frequency components ($\\omega_{c1}+\\omega_{c2}$). In-phase baseband signal $r_{IB}(t)$ can be expressed\n\\begin{equation}\nr_{IB}(t) = \\tfrac{1}{2}S_I(t)\\times cos(\\Delta\\omega t) - \\tfrac{1}{2}S_Q(t)\\times sin(\\Delta\\omega t)\n\\end{equation}\n\nSimilarly, Quad-phase baseband signal $r_{QB}(t)$\n\\begin{equation}\nr_{QB}(t) = \\tfrac{1}{2}S_I(t)\\times sin(\\Delta\\omega t) + \\tfrac{1}{2}S_Q(t)\\times cos(\\Delta\\omega t)\n\\end{equation}\n\nwhere $\\Delta\\omega = \\omega_{c2} - \\omega_{c1}$. By Rearranging these queations, we can express the\nfollowing.\n\\[\n\\begin{bmatrix}\n\tr_{IB}(t) \\\\\n\tr_{QB}(t) \n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\tcos(\\Delta\\omega t) & -sin(\\Delta\\omega t) \\\\\n\tsin(\\Delta\\omega t) & cos(\\Delta\\omega t)\n\\end{bmatrix}\n\\times\n\\begin{bmatrix}\n\t{}^1/_2\\cdot S_I(t)\\\\\n\t{}^1/_2\\cdot S_Q(t)\\\\\n\\end{bmatrix}\n\\]\nWe can clearly see that the frequency mismatch is equivalent to the rotation \nof complex coordinate with angular velocity $\\Delta\\omega$. Hense, by \nmeasuring the rotation speed and direction, we can back calculate the \nfrequency offset between receiver and transmitter. In the O-QPSK modulation, \nI/Q signal at any given time map to a unit circle on constellation. \nMeasuring both clockwise and counter clockwise rotation angle at fixed \ninterval tells the receiver's carrier frequency is leading or legging. \nWith this information, radio is able to self-compensate the frequency \nmismatch and we called it \\textit{Automatic Frequency Compensation} or AFC. \n\n\\begin{table}\n\t\\centering\n\t\\begin{tabular}{|c|c|c|} \\hline\n\t\t\\rowcolor[gray]{0}\n\t\t  {\\sc {\\color{white} AGC mode}}\n\t\t& {\\sc {\\color{white} AFC mode}}\n\t\t& {\\sc {\\color{white} ARR}}\n\t\t\\\\ \\hline\n\t\tSFD-latch \t& Enable \t& 93.3\\%\t\\\\ \\hline\n\t\tContinuous\t& Enable\t& 95.5\\%\t\\\\ \\hline\n\t\tSFD-latch \t& Disable\t& 94.5\\%\t\\\\ \\hline\n\t\tContinuous\t& Disable\t& 95.1\\%\t\\\\ \\hline\n\t\\end{tabular}\n    \\caption{Acknowledgment reception rate (ARR) for two constructively\ninterfering transmitters with respect to different AGC modes and AFC mode. \nWe transmitted 10,000 ACKs per transmitter per experiment. With AFC disable,\ncarrier frequencies of TX and RX is off by 16.4KHz. In both case of AFC mode,\ncontinuous AGC works better. Enabling the AFC worsen the reception rate for\nSFD-Latch AGC simply because the baseband signal is attenuated by low-frequency\nenvelope.}\n\t\\label{tab:ARR_versus_agc_afc_mode}\n\\end{table}\n\nFrom table ~\\ref{tab:ARR_versus_agc_afc_mode}, data shows that the ARR decrease\nin SFD-Latch type AGC when AFC is enabled. Since the AFC tries to sompensate the\nfrequency difference between TX and RX, the duration of local minimum becomes\nlarger whereas no significant change on Continuous AGC mode. Continuous AGC with\nAFC could potentially increase the reception rate in longer identical packet \ncollision.\n\n\\subsection{Automatic Frequency Compensation}\nThe 802.15.4 uses O-QOSK modulation. At any given of time, the in-phase and quad-phase\nhave only 8 combinations which is listed in table~\\ref{tab:demux}. The key concept \nis that the in-phase and quad-phase signal vector is always on the unit circle of \ncomplex plane. Moreover, the signal vector is always rotating at angular velocity\n$\\omega = \\tfrac{\\pi/2}{0.5 \\mu s}$. However, if the frequency of transmitter\nand receiver doesn't match, the angular velocities toward clockwise and counter-clockwise\nare different. Thus, by sampling the vector at constant rate and calculate angle difference\ntoward two different direction, we are able to tell the frequency is leading or lagging.\nIn usdr, we implemented a simple cordic core to measure the angle of input vector with\nsampling rate $= 250 Ksps$. The delta angle should be $\\pm\\pi/4$ if frequencies are perfectly\nmatched. By comparing the delta angle with $\\pm\\pi/4$, radio is able to self-align\nits carrier frequency to the incoming packet.\n\\begin{figure}[h]\n\\centering\n\t\\includegraphics[width=0.6\\columnwidth]{frequency_compensate/freq_compensate}\n\t\\caption{}\n\t\\label{fig:afc_freq_error}\n\\end{figure}\n\nFigure~\\ref{fig:afc_freq_error} shows capability of AFC to correct the frequency \nmismatch. The original frequency mismatch is set to be 50 KHz. The figure shows how\nmuch frequency mismatch after automatic frequency compensation within a packet length.\nIn these simulations, the packet lengths are set to be 127 and 64 bytes. The frequency  \nstep size in both simulation is 300 Hz. Thus, if the RMS frequency error $<$ 300 Hz, \nthe AFC successfully compensated all frequency mismatch. We can clearly see that \nfor larger SNR, AFC works better. In addition, more opportunities to compensate the\nfrequency in longer packet. Hence, frequency error is smaller in 127 bytes packet.\n\n\n\\subsection{Demodulation with frequency mismatch}\n\\label{1tx1rx_mismatch}\nRecall the demodulation equation $d(t) = S_Q(t)\\times S_I(t-\\tau) - S_Q(t-\\tau)\\times S_I(t)$.\nUnder the frequency mismatch scenario, the recieved $r_{IB}(t)$ and $r_{QB}(t)$ can be substituded by $S_I(t)$ and $S_Q(t)$. \n$d_f(t)$ can be written in following:\n\\begin{align}\nd_f(t) = &\n\\left[-\\tfrac{1}{2}S_I(t)sin(\\Delta\\omega t)+\\tfrac{1}{2}S_Q(t)cos(\\Delta\\omega t)\\right] \\times\n\\left[\\tfrac{1}{2}S_I(t-\\tau)cos(\\Delta\\omega(t-\\tau))+\\tfrac{1}{2}S_Q(t-\\tau)sin(\\Delta\\omega(t-\\tau))\\right] \\nonumber \\\\\n&  -\\left[-\\tfrac{1}{2}S_I(t-\\tau)sin(\\Delta\\omega(t-\\tau))+\\tfrac{1}{2}S_Q(t-\\tau)cos(\\Delta\\omega(t-\\tau))\\right] \\times\n\\left[\\tfrac{1}{2}S_I(t)cos(\\Delta\\omega t) + \\tfrac{1}{2}S_Q(t)sin(\\Delta\\omega t)\\right]\n\\end{align}\n\nAssuming that the $\\Delta\\omega\\times\\tau$ is small enough.\n\\begin{align}\ncos(\\Delta\\omega(t-\\tau))& \\approx cos(\\Delta\\omega t) \\\\\nsin(\\Delta\\omega(t-\\tau))& \\approx sin(\\Delta\\omega t)\n\\end{align}\n\nThe equation can be further simplified.\n\\begin{align}\nd_f(t) \\approx &\n\\left[-\\tfrac{1}{2}S_I(t)sin(\\Delta\\omega t)+\\tfrac{1}{2}S_Q(t)cos(\\Delta\\omega t)\\right] \\times\n\\left[\\tfrac{1}{2}S_I(t-\\tau)cos(\\Delta\\omega t)+\\tfrac{1}{2}S_Q(t-\\tau)sin(\\Delta\\omega t)\\right] \\nonumber \\\\\n& -\\left[-\\tfrac{1}{2}S_I(t-\\tau)sin(\\Delta\\omega t)+\\tfrac{1}{2}S_Q(t-\\tau)cos(\\Delta\\omega t)\\right] \\times\n\\left[\\tfrac{1}{2}S_I(t)cos(\\Delta\\omega t) + \\tfrac{1}{2}S_Q(t)sin(\\Delta\\omega t)\\right]\\\\\n\\approx & \\left[-\\tfrac{1}{4}S_I(t)S_Q(t-\\tau)sin^2(\\Delta\\omega t) + \\tfrac{1}{4}S_I(t-\\tau)S_Q(t)cos^2(\\Delta\\omega t)\\right]\\nonumber\\\\\n& -\\left[\\tfrac{1}{4}S_I(t)S_Q(t-\\tau)cos^2(\\Delta\\omega t) -\\tfrac{1}{4}S_I(t-\\tau)S_Q(t)sin^2(\\Delta\\omega t)\\right]\\\\\n\\approx &\\tfrac{1}{2}\\left[S_Q(t)S_I(t-\\tau) - S_Q(t-\\tau)S_I(t)\\right]\n\\end{align}\n\nThe decoded equation $d_f(t)$ is linear scaling of $d(t)$. The sign of $d_f(t)$ and $d(t)$ are identical. Therefore, \nthe decoder scheme still function if there is a mismatch between transmitter and receiver.\n\n\n\\clearpage\n\\section{Carrier frequency mismatch in double TX, single RX}\n\\label{sec:2tx1rx}\nIn this scenario, two TX node transmit the identical baseband signal simultaneously. Assuming the TX nodes have different\ncarrier frequency $f_{c1}$ and $f_{c2}$, and receiver's frequency is $f_{cr}$. We simply assume that $R(t) = S(t)$.\n\\begin{equation}\nR(t) = S(t) = S_I(t)\\left[cos(\\omega_{c1}t) + cos(\\omega_{c2}t)\\right] + S_Q(t)\\left[sin(\\omega_{c1}t) + sin(\\omega_{c2}t)\\right]\n\\end{equation}\n\nSimplifying the equation by sum-to-product identities.\n\\begin{align}\nR(t)& = S_I(t)\\left[2cos(\\tfrac{\\omega_{c1}+\\omega_{c2}}{2}t)cos(\\tfrac{\\omega_{c1}-\\omega_{c2}}{2}t)\\right] +\nS_Q(t)\\left[2sin(\\tfrac{\\omega_{c1}+\\omega_{c2}}{2}t)cos(\\tfrac{\\omega_{c1}-\\omega_{c2}}{2}t)\\right] \\\\\n& = cos(\\tfrac{\\omega_{c1}-\\omega_{c2}}{2}t)\\left[\n2S_I(t)cos(\\tfrac{\\omega_{c1}+\\omega_{c2}}{2}t) + 2S_Q(t)sin(\\tfrac{\\omega_{c1}+\\omega_{c2}}{2}t) \\right]\n\\end{align}\n\nThe received In-phase signal $r_I(t)$ can be expressed as following:\n\\begin{equation}\nr_I(t) = R(t) \\times cos(\\omega_{cr}t) \\\\\n\\end{equation}\n\\begin{align}\nr_I(t) =  cos(\\tfrac{\\omega_{c1}-\\omega_{c2}}{2}t)\\{\n&S_I(t)\\left[cos(\\tfrac{\\omega_{c1}+\\omega_{c2}-2\\omega_{cr}}{2}t) + cos(\\tfrac{\\omega_{c1}+\\omega_{c2}+2\\omega_{cr}}{2}t)\\right] + \\nonumber \\\\\n&S_Q(t)\\left[sin(\\tfrac{\\omega_{c1}+\\omega_{c2}-2\\omega_{cr}}{2}t) + sin(\\tfrac{\\omega_{c1}+\\omega_{c2}+2\\omega_{cr}}{2}t)\\right] \n\\}\n\\end{align}\n\nLet $\\Delta\\omega_1 = (\\omega_{c1} - \\omega_{cr})$ and $\\Delta\\omega_2 = (\\omega_{c2} - \\omega_{cr})$. By removing \nhigh frequency tems, $r_{IB}(t)$ can be simplified.\n\\begin{equation}\nr_{IB}(t) = cos(\\tfrac{\\Delta\\omega_1-\\Delta\\omega_2}{2}t)\\left[\nS_I(t)cos(\\tfrac{\\Delta\\omega_1+\\Delta\\omega_2}{2}t) + S_Q(t)sin(\\tfrac{\\Delta\\omega_1+\\Delta\\omega_2}{2}t)\\right]\n\\end{equation}\n\nSimilarily, the received Quad-phase baseband signal $r_{QB}(t)$ can be derived from $R(t)\\times sin(\\omega_{cr}t)$.\n\\begin{equation}\nr_{QB}(t) = cos(\\tfrac{\\Delta\\omega_1-\\Delta\\omega_2}{2}t)\\left[\n-S_I(t)sin(\\tfrac{\\Delta\\omega_1+\\Delta\\omega_2}{2}t) + S_Q(t)cos(\\tfrac{\\Delta\\omega_1+\\Delta\\omega_2}{2}t)\\right]\n\\end{equation}\n\nFrom section~\\ref{1tx1rx_mismatch}, we can conclude that if $(\\Delta\\omega_1-\\Delta\\omega_2)t$ is small enough, the \ndecoding equation just simply scaling by $cos^2((\\Delta\\omega_1-\\Delta\\omega_2)t)$, which is always greater than zero. \nThe sign of decoding equation remains the same as no frequency mismatch.\n\n\\section{Envelop Modeling}\n\\subsection{Theoretical Method}\n\\label{sec:envelop_modeling}\nConsidering a simplified model, there are two transmitters and one receiver with their carrier frequency \n$f_{c1}$, $f_{c2}$ and $f_{cr}$ respectively. Assuming that $f_{cr} = f_{c1}$ and $S_Q(t) = 0$, the received\nin-phase baseband signal can be expressed as:\n\\begin{equation}\nr_I(t) = S_I(t)\\times cos^2((\\Delta\\omega_2/2)\\times t)\n\\label{eq:sec:envelop_modeling:1}\n\\end{equation}\nThus, from equation~\\ref{eq:sec:envelop_modeling:1}, the low-frequency envelop can be observed intuitively.\nThe period $T$ of the envelope is equal to $\\tfrac{1}{\\Delta f_2/2}\\times \\tfrac{1}{2} = \\tfrac{1}{\\Delta f_2}$.\nWhere $\\Delta f_2 = \\tfrac{\\Delta\\omega_2}{2\\pi}$. \nWe can define a threshold $\\alpha$ which the receiver makes false decision once the received signal's amplitude \nbelow $\\alpha$. The time ($t$) which the signal's amplitude is queal to threshold ($\\alpha$) can be expressed as:\n\\begin{eqnarray}\ncos^2(2\\pi\\tfrac{\\Delta\\omega_2}{2}\\times t) = \\alpha \\\\\n\\tfrac{\\Delta\\omega_2 t}{2} = cos^{-1}(\\sqrt{\\alpha}) \\\\\nt = \\tfrac{cos^{-1}(\\sqrt{\\alpha})}{\\Delta\\omega_2/2} \\\\\nt = \\tfrac{cos^{-1}(\\sqrt{\\alpha})}{\\pi\\Delta f_2} \\\\\n\\end{eqnarray}\n\nThus, we defined $\\gamma$, which is the proportion of signal below threshold ($\\alpha$) to the entire \nperiod ($T$) can be calculated as:\n\\begin{align}\n\\gamma \t&= \\tfrac{T/2-t}{T/2}\t\\\\\n\t\t&= \\tfrac{\\tfrac{1}{2\\Delta f_2} - \\tfrac{cos^{-1}(\\sqrt{\\alpha})}{\\pi\\Delta f_2}}{\\tfrac{1}{2\\Delta f_2}}\t\\\\\n\t\t&= 1 - \\tfrac{2}{\\pi}cos^{-1}(\\sqrt{\\alpha})\n\t\t\\label{eq:sec:envelop_modeling:alpha}\n\\end{align}\n\nFrom equation~\\ref{eq:sec:envelop_modeling:alpha}, we find that the proportion $\\gamma$ is a function\nof $\\alpha$ only. In other words, the proportion remains the same no matter what $\\Delta f_2$ is.\nThus, in this simplified model, assuming that all the false decoding comes from the amplitude\nattenuation by $cos^2(\\Delta\\omega_2/2)$. The time duration $D$ while signal below threshold ($\\alpha$)\ncan be expressed as:\n\\begin{align}\nD \t&= \\gamma \\times T\\\\\n\t&= \\left[1 - \\tfrac{2}{\\pi}cos^{-1}(\\sqrt{\\alpha})\\right]\\times\\tfrac{1}{\\Delta f_2} (s)\n\\end{align}\n\nIn 802.15.4, the period of each chip is 0.5$\\mu$s and each byte occupies 32$\\mu$s in time. Therefore, the\nrelationship between number of chips $n$ in each duration $D$ and total number of envelopes $m$ in \na given lengh packet $L$ bytes can be written as:\n\\begin{eqnarray}\nn = D/0.5\\mu s \\\\\nm = L\\times 32\\mu s/T\n\\end{eqnarray}\n\n\\begin{table}\n\\begin{center}\n\t\\begin{tabular}{c||c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c c} \n\t\t\t& 0& 1& 2& 3& 4& 5& 6& 7& 8& 9&10&11&12&13&14&15\t\\\\ \\hline\\hline\n\t\t0\t&  &14&15&14&16&13&15&13&31&17&16&17&15&18&16&18 \t\\\\ \\hline\n\t\t1\t&14&  &13&16&14&15&13&15&17&31&18&15&17&16&18&16 \t\\\\ \\hline\n\t\t2\t&15&13&  &13&15&14&16&14&16&18&31&18&16&17&15&17\t\\\\ \\hline\n\t\t3\t&14&16&13&  &14&15&13&15&17&15&18&31&17&16&18&16\t\\\\ \\hline\n\t\t4\t&16&14&15&14&  &13&15&13&15&17&16&17&31&18&16&18\t\\\\ \\hline\n\t\t5\t&13&15&14&15&13&  &14&16&18&16&17&16&18&31&17&15\t\\\\ \\hline\n\t\t6\t&15&13&16&13&15&14&  &14&16&18&15&18&16&17&31&17\t\\\\ \\hline\n\t\t7\t&13&15&14&15&13&16&14&  &18&16&17&16&18&15&17&31\t\\\\ \\hline\n\t\t8\t&31&17&16&17&15&18&16&18&  &14&15&14&16&13&15&13\t\\\\ \\hline\n\t\t9\t&17&31&18&15&17&16&18&16&14&  &13&16&14&15&13&15\t\\\\ \\hline\n\t\t10\t&16&18&31&18&16&17&15&17&15&13&  &13&15&14&16&14\t\\\\ \\hline\n\t\t11\t&17&15&18&31&17&16&18&16&14&16&13&  &14&15&13&15\t\\\\ \\hline\n\t\t12\t&15&17&16&17&31&18&16&18&16&14&15&14&  &13&15&13\t\\\\ \\hline\n\t\t13\t&18&16&17&16&18&31&17&15&13&15&14&15&13&  &14&16\t\\\\ \\hline\n\t\t14\t&16&18&15&18&16&17&31&17&15&13&16&13&15&14&  &14\t\\\\ \\hline\n\t\t15\t&18&16&17&16&18&15&17&31&13&15&14&15&13&16&14&  \t\n\t\\end{tabular}\n\t\\caption{Chip distance table. This table shows the distance between any two chip sequence\n\t\tin codebook. The minimum distance two sequences is 13 chips}\n\t\\label{tab:chip_distance}\n\\end{center}\n\\end{table}\n\nGiven $\\alpha, \\Delta f_2$ and $L$, we can calculate $n, m$. For example, $\\alpha = 0.05$, \n$\\Delta f_2 = 15$ KHz and $L = 127$ bytes. $n = 4.24, m = 60.96$. Decoding a 802.15.4 symbol\nrequires a distance calculation between a received sequence and 16 possible sequence in codebook.\nFrom table~\\ref{tab:chip_distance}, any chip sequence can be correctly decoded if the number of\nbit errors is less than 13. Furthermore, we define a probability $p_{single}$ which is the \nprobability that a single bit error while the amplitude is below threshold $\\alpha$. In the duration\n$D$, the number of bit errors should less than 13 for symbol to be able to decode correctly. We derive \na probability $p_{correct}$, which is the probability that the symbol is able to be decoded correctly.\n\\begin{equation}\np_{correct} = \\sum_{i=0}^{12} \\dbinom{n}{i}\\times(p_{single})^i\\times(1-p_{single})^{n-i}\n\\end{equation}\n\nThus, the packet error rate ($PER$) and be can be expressed by $p_{correct}$ and $m$.\n\\begin{equation}\n\tPER = 1 - (p_{correct})^m\n\t\\label{eq:sec:envelop_modeling:per}\n\\end{equation}\n\n\\begin{figure*}\n\\centering\n\t\\centering\n\t\t\\subfigure[Theoretical Modeling]{\n\t\t\t\\includegraphics[width=0.45\\columnwidth]{envelop_modeling/per_deltaf}\n\t\t\t\\label{fig:envelop_modeling_the}\n\t\t}\n\t\t\\subfigure[Simulated Modeling]{\n\t\t\t\\includegraphics[width=0.45\\columnwidth]{envelop_modeling_sim/per_deltaf_sim}\n\t\t\t\\label{fig:envelop_modeling_sim}\n\t\t}\n\t\\caption{Figure~\\ref{fig:envelop_modeling_the} simulates the PER using equation~\\ref{eq:sec:envelop_modeling:per}.\n\tWhereas the figure~\\ref{fig:envelop_modeling_sim} uses 802.15.4 transceiver architectural model. The parameters\n\tfor both plots are: $L = 127$ Bytes, $\\alpha = 0.05$, $\\Delta f_1 = 0, \\Delta f_2$ from 10 to 20 KHz. we can\n\tfind the trend that the PER drops while $\\Delta f_2$ increases in both plots. Since the number of consecutive \n\tcontaminated bits get shorter in larger frequency separation, the possibility for receiver to false decode a\n\tpacket become smaller.}\n\t\\label{fig:envelop_modeling}\n\\end{figure*}\n\nFigure~\\ref{fig:envelop_modeling_the} shows the simulation result of packet error rate (PER) versus\n$\\Delta f_2$. Parameters of this simulation are: $L = 127$ bytes, $\\alpha = 0.05$, $p_{single} = 0.2$\nand $\\Delta f_2$ from 100 to 20 KHz. Since number of chips $n$, which below threshold $\\alpha$ drops\nwhile increasing the frequency. Even number of evnelops $m$ increases but the correct probability \n$p_{correct}$ is close or equal to 1 (if $n$ $<$ chip distance, 13). In contrast, low frequency separation\ndramatically deteriorates the $p_{correct}$. The PER is much worse even if the number of envelop $m$ is small.\nHowever, the equations we derived above don't hold under a special case, which is the period of envelop ($T$)\nis somehow greater than packet length. Imaging when $m \\to \\infty$, the PER should be 0 instead of 1. Thus, if the\ncondition $(1-\\gamma)T + (6.5 \\mu s(chip distance)/p_{single}) > L\\times32 \\mu s$ meets, the PER can be written as:\n\\begin{align}\n\tPER &= 1 - p_{correct} \\\\\n\t\t&= 1 - \\tfrac{(1-\\gamma)T - L\\times32\\mu s + 6.5\\mu s/p_{single}}{T - L\\times32 \\mu s}\n\\end{align}\nWhere the $6.5 \\mu s/p_{single}$ is the expection value of numbers of error chip, and \n$(1-\\gamma)T - L\\times32 \\mu s + 6.5 \\mu s/p_{single}$ is the length for correct decoding. Namely,\nif the packet starts within the envelop any moment from 0 $\\sim$ numerator, the total error chips is less\nthan 13 (chip distance). The denominator is the total possible starting point.\n\n\n\n\\subsection{Architectural Method}\nFrom section~\\ref{sec:2tx1rx}, we derived the in-phase and quad-phase signal if the frequency present\nin two transmitters and one receiver. We build a complete models of uSDR's transceiver. \nFigure~\\ref{fig:envelop_modeling_sim_IQ} shows the received in-phase and quad-phase signal with \n$\\Delta f_2 = 15$ KHz. Thus, the period $T$ of envelops is $\\tfrac{1}{\\Delta f_2} = 66.67 \\mu$s. \n\\begin{figure}[h]\n\\centering\n\t\\includegraphics[width=0.98\\columnwidth]{envelop_modeling_sim/IQ}\n\t\\caption{This figure shows the received in-phase and quad-phase baseband signals in simulation. The \n\tparameters of this simulation are: $\\Delta f_1 = 0, \\Delta f_2 = 15$ KHz. We can see that the period\n\tof envelop $T = \\tfrac{200 \\mu s}{3} = 66.67 \\mu s = \\tfrac{1}{15 KHz} = \\tfrac{1}{\\Delta f_2}$}\n\t\\label{fig:envelop_modeling_sim_IQ}\n\\end{figure}\n\nIn the architectural based simulation, we add Gaussian noise to the signal and setting the signal to noise\nration (SNR) to 15dB. In addition to that, we set a threshold, which similar to $\\alpha$. If the amplitude\nless than $\\alpha$, instead of original signal, we randomly generate the noise bounded by $\\alpha$. \nFrom figure~\\ref{fig:envelop_modeling_sim}, we can see trend of PER from architectural simulation is similar\nto the theoretical method. However, in architectural simulation, the PER never goes to 0 even the $\\Delta f$\nis large enough. The resaon is the AWGN present and the random noise we added. The random noise wee add not\nonly exist on low-frequency envelop but the entire signal. Namely, every chip in the sequence is affected by\nthe noise. Thus, the architectural method has less \"effective\" chip distance.\n\n", "meta": {"hexsha": "4da71564b0406c8da955716f237fe16d8fce1d0c", "size": 19631, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/tex/freq_diff.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": "notes/tex/freq_diff.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": "notes/tex/freq_diff.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": 54.229281768, "max_line_length": 144, "alphanum_fraction": 0.7128011818, "num_tokens": 6847, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.853912760387131, "lm_q2_score": 0.8872045952083047, "lm_q1q2_score": 0.7575953249224707}}
{"text": "% !TeX root = ../main.tex\n% Add the above to each chapter to make compiling the PDF easier in some editors.\n\n\\chapter{Summary of Notation}\n\n\\begin{fullwidth}\nWe follow these general rules: \\begin{itemize}[noitemsep]\n    % \\item uppercase italic for constants $N$\n    \\item lowercase italic for indices $i$ and scalar variables $a$\n    % \\item lowercase italic bold for vectors $\\vx$\n    \\item uppercase italic bold for matrices $\\mM$\n    % \\item uppercase italic for random variables $X$\n    % \\item uppercase bold for random vectors $\\rX$\n    \\item uppercase italic for sets $A$\n    % \\item uppercase calligraphy for spaces (usually infinite sets) $\\spA$\n\\end{itemize}\n\n\\emptyparagraph\\begin{longtable}{p{2cm}l}\n    $\\defeq$ & equality by definition \\\\\n    $\\N$ & set of natural numbers $\\{1, 2, \\dots\\}$ \\\\\n    $\\NZ$ & set of natural numbers, including $0$, $\\N \\cup \\{0\\}$ \\\\\n    $[n]$ & set of natural numbers from $1$ to $n$, $\\{1, 2, \\dots, n-1, n\\}$ \\\\\n    $\\Z$ & set of integers $\\{\\dots, -2, 1, 0, 1, 2, \\dots\\}$ \\\\\n    $\\R$ & set of real numbers \\\\\n    $\\C = \\R^2$ & set of complex numbers \\\\\n    $A \\cupdot B$ & disjoint union of sets $A$ and $B$ \\\\\n    $f : A \\to B$ & function $f$ from elements of set $A$ to elements of set $B$ \\\\\n    $\\divides{a}{b}$ & $a$ is a divisor of $b$ \\\\\n\\end{longtable}\n\n\\section*{\\smallcaps{Groups}}\n\\begin{longtable}{p{2cm}l}\n    $U \\subgroup G$ & $U$ is a subgroup of $G$ \\\\\n    $\\gen{M} \\subgroup G$ & for $M \\subseteq G$, the subgroup generated by $M$ \\\\\n    $\\gen{a}$ & the cyclic group $\\gen{\\{a\\}}$ \\\\\n    $o(a)$ & order of element $a$, $|\\gen{a}|$ \\\\\n    $aU$ & left coset of $a \\in G$ and $U \\subgroup G$, $\\{a \\cdot u \\mid u \\in U\\}$ \\\\\n    $Ua$ & right coset of $a \\in G$ and $U \\subgroup G$, $\\{u \\cdot a \\mid u \\in U\\}$ \\\\\n    $[G:U]$ & index of $U \\subgroup G$ in $G$, $|\\{aU \\mid a \\in G\\}|$ \\\\\n    $\\ker \\varphi$ & kernel of homomorphism $\\varphi : G \\to H$, $\\{a \\in G \\mid \\varphi(a) = e_H\\} \\subseteq G$ \\\\\n    $\\im \\varphi$ & image of homomorphism $\\varphi : G \\to H$, $\\{\\varphi(a) \\mid a \\in G\\} \\subseteq H$ \\\\\n    $G \\cong H$ & $G$ and $H$ are isomorphic \\\\\n    $N \\normal G$ & $N$ is a normal subgroup of $G$ \\\\\n    $\\rep{a} = a N$ & the (left) coset of some $a \\in G$ in the context of the quotient group $\\Quot{G}{N}$ \\\\\n    \\addlinespace\n    $\\GL{n}{K}$ & \\emph{general linear group} over invertible linear maps $\\mA \\in K^{n \\times n}$, $\\det{\\mA} \\neq 0$ \\\\\n    $\\SL{n}{K}$ & \\emph{special linear group} over volume-preserving linear maps $\\mA \\in K^{n \\times n}$, $\\det{\\mA} = 1$ \\\\\n    $S_n$ & \\emph{symmetric group} over bijections on $[n]$ (so-called permutations) \\\\\n    $A_n$ & \\emph{alternating group} over bijections $\\sigma$ on $[n]$ with positive sign, $\\sgn{\\sigma} = 1$ \\\\\n    $Z(G)$ & \\emph{center} of group $G$, $\\{a \\in G \\mid \\forall x \\in G.\\ ax = xa\\} \\normal G$ \\\\\n    $\\Aut{G}$ & \\emph{automorphism group} over automorphisms on $G$ \\\\\n    $\\Inn{G}$ & \\emph{inner automorphism group} over inner automorphisms on $G$ \\\\\n    $\\Quot{G}{N}$ & for some $N \\normal G$, \\emph{quotient group} $G$ modulo $N$ over (left) cosets of $N$ \\\\\n    $n\\Z = \\gen{n}$ & subgroup $n\\Z \\subgroup \\Z$ of multiples of $n \\in \\Z$ \\\\\n    $Z_n = \\Quot{\\Z}{n\\Z}$ & quotient group $\\Z$ modulo $n\\Z$, $\\gen{\\rep{1}} = \\{\\rep{0}, \\rep{1}, \\dots, \\rep{n-1}\\}$ \\\\\n    $\\Out{G}$ & \\makecell[tl]{\\emph{outer automorphism group} over cosets of the inner automorphism group and \\\\ outer automorphisms on $G$, $\\Quot{\\Aut{G}}{\\Inn{G}}$} \\\\\n    \\addlinespace\n    $i_g$ & \\emph{inner automorphism} of some conjugating element $g \\in G$, $i_g : G \\to G, x \\to g \\cdot x \\cdot \\inv{g}$ \\\\\n\\end{longtable}\n\\end{fullwidth}\n", "meta": {"hexsha": "3c48949afee50ce333bf5aaed5b8fa4f09d29f97", "size": 3671, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/notation.tex", "max_stars_repo_name": "jonhue/algebra", "max_stars_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/notation.tex", "max_issues_repo_name": "jonhue/algebra", "max_issues_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/notation.tex", "max_forks_repo_name": "jonhue/algebra", "max_forks_repo_head_hexsha": "b91da0f3fff239010d0584535f1b5f0d4f0184aa", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 60.1803278689, "max_line_length": 170, "alphanum_fraction": 0.5867611005, "num_tokens": 1313, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952893703477, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7575606512371378}}
{"text": "\\section{Quaternions\\label{quaternions}}\n\\subsection{The need for Quaternions}\nBesides its position, each rigid body in 3D space may have an orientation, in which there are\nthree degrees of freedom (three independent axes to rotate about).\nWhile the position of a body can be neatly represented using Cartesian coordinates, there is\nno obvious best way of describing an orientation. The most common schemes describe\nit in terms of a rotation operation which transforms a vector in the body's local\ncoordinates into world coordinates (or \\textsl{vice versa}). But again, there are various different\napproaches to representing this rotation, all of which have advantages and disadvantages.\n\n\\emph{Euler angles} are probably the most intuitive representation of a 3D rotation, describing\nit as a series of three rotations about different axes. These axes are fixed by convention, so it\nsuffices to specify the three angles of rotation. However, this scheme has a number of\ndrawbacks~\\cite{Saunders:PhD,Shoemake:85}: amongst other things, it is possible that rotation\nabout one of the axes freezes during an animation (``Gimbal lock'').\n\n\\emph{Rotation matrices} are commonly used because they are well understood and\nallow efficient combination with other linear transformations (scaling\nand shearing~-- also translation if homogeneous coordinates are employed). However, ODEs over\nrotation matrices are difficult to implement correctly, since this representation uses nine\nnumbers (a $3\\times3$ matrix) to represent three degrees of freedom, thus introducing six\nadditional side conditions which must be maintained. Not doing so causes skew through numerical\ndrift~\\cite{Saunders:PhD}.\n\n\\emph{Quaternions}~\\cite{Shoemake:85,Eberly:01,MathWorld:Quaternion} are a popular alternative\nto the two previous sche\\-mes, and they are used extensively in this project.\n\n\\subsection{Definition and properties}\nMathematically, quaternions can be regarded as numbers with one real part and three\ndistinct imaginary parts:\n\\begin{equation}\n\\q{q} = q_w + q_x\\qi + q_y\\qj + q_z\\qk\n\\end{equation}\nwhere $q_w$, $q_x$, $q_y$ and $q_z$ are real numbers and \\qi{}, \\qj{} and \\qk{} satisfy\n\\begin{equation}\n\\qi^2 = \\qj^2 = \\qk^2 = \\qi\\qj\\qk = -1.\n\\end{equation}\nFrom this follows that\n$\\qi\\qj = -\\qj\\qi = \\qk$ and\n$\\qj\\qk = -\\qk\\qj = \\qi$ and\n$\\qk\\qi = -\\qi\\qk = \\qj$.\nNote that multiplication is not commutative.\n\nWe will also need the conjugate and the inverse of a quaternion. In analogy to\ncomplex numbers, these are given respectively by\n\\begin{eqnarray}\n\\overline{\\q{q}} & = & q_w - q_x\\qi - q_y\\qj - q_z\\qk \\label{quatConjugate}\\\\\n\\q{q}^{-1} & = & \\frac{\\overline{\\q{q}}}{\\norm{\\q{q}}^2} \\label{quatInverse}\\\\\n\\mathrm{where}\\quad\\quad \\norm{q_w + q_x\\qi + q_y\\qj + q_z\\qk} &=&\n    \\sqrt{q_w^2 + q_x^2 + q_y^2 + q_z^2} \\label{quatMagnitude}\n\\end{eqnarray}\n\nSometimes we will need to relate a 3D vector to a quaternion with zero real part.\nFor a given vector $\\ve{u} = (u_1, u_2, u_3)^T$ we define the corresponding\nquaternion to be\n\\begin{equation}\n\\label{vectorToQuat}\n\\tilde{\\ve{u}} = u_1\\qi + u_2\\qj + u_3\\qk.\n\\end{equation}\n\nThe complex constants \\qi{}, \\qj{} and \\qk{} are required for the algebra only, therefore we can\nrepresent a quaternion as four numbers $(q_w,q_x,q_y,q_z)$. It turns out that a quaternion\nwith unit magnitude ($\\norm{\\q{q}} = 1$) neatly represents an arbitrary rotation in\n3D space, similarly to the way that an ordinary complex number represents a rotation in the 2D\nArgand diagram. The condition $\\norm{\\q{q}} = 1$ reduces the number of degrees of freedom to\nthree, as required.\n\nEvery unit quaternion represents a rotation of angle $\\theta$ about an arbitrary axis.\nIf the axis passes through the origin and has a direction given by the vector\n\\ve{a} with $\\norm{\\ve{a}} = 1$, the quaternion describing this rotation is\n\\begin{equation}\n\\label{quatRotation}\n\\q{q} = \\cos\\left(\\frac{\\theta}{2}\\right) + \\tilde{\\ve{a}} \\sin\\left(\\frac{\\theta}{2}\\right).\n\\end{equation}\nIt can easily be verified that this quaternion always has unit magnitude. It shall be assumed\nthroughout this project that the rotation thus described is clockwise (as seen when looking in\nthe direction of the vector $\\ve{a}$) in a right-hand coordinate system, i.e.\\ that it is\ngiven by the ``right-hand rule''.\n\nTwo rotations can be concatenated by multiplying their quaternions together. The order in which\nthese rotations are applied is significant, and quaternion multiplication is not commutative,\nso the semantics match. The operations are, however, associative. The quaternion product is\nobtained simply by multiplying out the components, observing the rules for multiplying \\qi{},\n\\qj{} and \\qk{}:\n\\begin{eqnarray}\n\\lefteqn{(p_w + p_x\\qi + p_y\\qj + p_z\\qk)(q_w + q_x\\qi + q_y\\qj + q_z\\qk) = } \\nonumber\\\\*\n&& (p_w q_w - p_x q_x - p_y q_y - p_z q_z) + \n   (p_w q_x + p_x q_w + p_y q_z - p_z q_y) \\,\\qi + \\nonumber\\\\*\n&& (p_w q_y + p_y q_w + p_z q_x - p_x q_z) \\,\\qj + \n   (p_w q_z + p_z q_w + p_x q_y - p_y q_x) \\,\\qk \\label{quatProduct}\n\\end{eqnarray}\n\nTo rotate a vector $\\ve{v} = (v_1, v_2, v_3)^T$ by a quaternion \\q{q}, we first\nconvert it into its corresponding quaternion $\\tilde{\\ve{v}}$ as defined in\nequation~\\ref{vectorToQuat} and then calculate the quaternion product\n\\begin{equation}\n\\label{quatTransform}\n\\tilde{\\ve{v}}' = \\q{q}\\tilde{\\ve{v}}\\q{q}^{-1}\n\\end{equation}\n\nIf we expand this formula, we find that the real part of the result is always zero, and\nthat the rotated vector $\\ve{v}' = (v_1', v_2', v_3')^T$ corresponds\nto $\\tilde{\\ve{v}}'$ (i.e.\\ $\\ve{v}'$ is contained in the three complex parts of\nthe quaternion product).\n\nSome authors, notably Shoemake~\\cite{Shoemake:85}, choose to define the product in\nequation~\\ref{quatTransform} in\nthe reverse order. The choice is a matter of convention, since it merely changes the effect\nof this operation from being a clockwise to a counter-clockwise rotation. I chose the clockwise\nconvention because it is consistent with the usual definition of the angular velocity vector\nin physics.\n\nObserve that under this convention, if \\q{q} is itself a product of quaternions\n$\\q{q} = \\q{q}_n \\q{q}_{n-1} \\cdots \\q{q}_1$, the result is that of first applying the\n$\\q{q}_1$ rotation, then $\\q{q}_2$ etc. In other words, the rotations in a quaternion product\nare applied from right to left. To verify that this is the case, the identity\n$\\overline{\\q{p}\\, \\q{q}} = \\q{\\overline{q}}\\; \\q{\\overline{p}}$\nis useful~\\cite{MathWorld:Quaternion}.\n\n\\subsection{Quaternion integration}\n\nWe have seen that given the torques on a body, a numerical ODE solver can treat each component\nof the vector separately to obtain the new angular momentum. Now that we are representing\norientation as a quaternion, how do we compute the change in orientation given the body's angular\nvelocity?\n\nThe instantaneous rate of change of a quaternion \\q{q} over time is\nusually~\\cite{BaraffWitkin:97,Eberly:04,Saunders:PhD} given as\n\\begin{equation}\n\\label{quatRateOfChange}\n\\dot{\\q{q}}(t) = \\frac{1}{2}\\tilde{\\ve{\\omega}}(t)\\q{q}(t)\n\\end{equation}\nwhere $\\tilde{\\ve{\\omega}}$ is the quaternion corresponding to the angular velocity\nvector $\\ve{\\omega}$. The quaternion $\\dot{\\q{q}}$ can be fed into an ODE solver which can handle\nits four components separately. However, when this is done it is observed that the new orientation\n$\\q{q}'$ no longer has unit magnitude. This is an inherent property of the definition in\nequation~\\ref{quatRateOfChange}, and not, as sometimes claimed~\\cite{Eberly:04}, merely a matter\nof numerical round-off (proof in appendix~\\ref{quatIntegrationMagnitude}). Usually this problem\nis `solved' by renormalizing the quaternion:\n\\begin{equation}\n\\q{q}(t + h) = \\frac{\\q{q}'}{\\norm{\\q{q}'}} \\quad\\quad\\mathrm{where}\\quad\n    \\q{q}' = \\q{q}(t) + h\\dot{\\q{q}}(t)\n\\end{equation}\n(using Euler's method for clarity; $\\q{q}'$ would be appropriately redefined when using e.g.\\ RK4).\nThis `solution' seemed quite \\textsl{ad hoc} to me, and I demonstrated that it returns\nerroneous results if the angular velocity is large (see appendix~\\ref{quatNormalization}).\nI derive an exact algorithm for quaternion integration in appendix~\\ref{quatProofs}. Such\nan algorithm may be important in aerospace applications, as the NASA patent~\\cite{NASA:00}\nsuggests.\n", "meta": {"hexsha": "2272d48cd32e618605ad980a96e7181d751794a9", "size": 8290, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/quaternions.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/quaternions.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/quaternions.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": 55.2666666667, "max_line_length": 99, "alphanum_fraction": 0.7442702051, "num_tokens": 2446, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093975331751, "lm_q2_score": 0.8479677622198947, "lm_q1q2_score": 0.7574975707962087}}
{"text": "\\section{Modules}\r\n\\subsection{Definition and Examples}\r\n\\begin{definition}\r\n    A module over a ring $R$ (an $R$-module) is a triple $(M,+,\\cdot)$ where $(M,+,0)$ for some $0\\in M$ is an abelian group and $\\cdot:R\\times M\\to M$ (called scalar multiplication) satisfies, for any $r,r_1,r_2\\in R,m,m_1,m_2\\in M$:\\\\\r\n    1. $(r_1+r_2)\\cdot m=r_1\\cdot m+r_2\\cdot m$.\\\\\r\n    2. $r\\cdot (m_1+m_2)=r\\cdot m_1+r\\cdot m_2$.\\\\\r\n    3. $r_1\\cdot(r_2\\cdot m)=(r_1r_2)\\cdot m$.\\\\\r\n    4. $1\\cdot m=m$.\r\n\\end{definition}\r\nThe function $\\cdot$ is called the scalar multiplication and is omitted from writing sometimes.\r\n\\begin{remark}\r\n    To show something is a module, we also need to check closure (that is $+,\\cdot$ are well-defined).\r\n\\end{remark}\r\n\\begin{example}\r\n    1. If $R$ is a field, then an $R$-module $M$ is a vector space over $R$.\\\\\r\n    2. A $\\mathbb Z$-module is precisely the same as an abelian group as the scalar multiplication can be uniquely defined by $n\\cdot a=a+\\cdots +a$ for $n$ many copies of $a$.\\\\\r\n    3. Consider the ring $R=\\mathbb F[X]$ for a field $\\mathbb F$ and $V$ a vector space over $\\mathbb F$.\r\n    Consider $\\alpha:V\\to V$ an endomorphism.\r\n    We can make $V$ an $R$-module over the scalar multiplication $\\mathbb F[X]\\times V\\to V$ by $(f,v)\\mapsto f(\\alpha)(v)$.\r\n    Note that different choice of $\\alpha$ makes $V$ a different module.\r\n    We sometimes write this as $V_\\alpha$.\r\n\\end{example}\r\nThere are some general construction methods to produce a module.\r\n\\begin{example}\r\n    1. For any ring $R$, $R^n$ is an $R$-module by $r\\cdot(r_1,\\ldots,r_n)=(rr_1,\\ldots,rr_n)$ for $r,r_i\\in R$.\r\n    In particular, when $n=1$, $R$ itself is an $R$-module.\\\\\r\n    2. If $I$ is an ideal, then $I$ is an $R$-module by $r\\cdot i=ri$ for $r\\in R,i\\in I$.\\\\\r\n    3. If $I$ is an ideal, then $R/I$ is an $R$-module by $r\\cdot(s+I)=rs+I$ for $r,s\\in R$.\\\\\r\n    4. If $\\phi:R\\to S$ is a ring homomorphism, then any $S$-module $M$ is also an $M$-module by $r\\cdot m=\\phi(r)\\cdot m$ for $r\\in R,m\\in M$.\r\n    In particular, if $R\\le S$, then any $S$-module can be viewed as an $R$-module.\r\n\\end{example}\r\n\\begin{definition}\r\n    Let $M$ be an $R$-module, a subset $N\\subset M$ is called a $R$-submodule of $M$, written as $N\\le M$, if $(N,+)\\le (M,+)$ and for any $r\\in R,n\\in N$, we have $r\\cdot n\\in N$.\r\n\\end{definition}\r\n\\begin{example}\r\n    1. Any $R$-submodule of $R$ is an ideal.\\\\\r\n    2. When $R$ is a field, then an $R$-module is a vector space, then a submodule is a vector subspace.\r\n\\end{example}\r\n\\begin{definition}\r\n    If $N$ is a $R$-submodule of $M$, we can form the quotient $M/N$ by taking the quotient group under addition.\r\n    We can make it as an $R$-module by specifying the scalar multiplication $r\\cdot (m+N)=r\\cdot m+N$.\r\n\\end{definition}\r\nWe can check easily that the scalar multiplication defined in this way is well-defined and makes $M/N$ an $R$-module.\r\n\\subsection{Homomorphisms}\r\n\\begin{definition}\r\n    Let $M,N$ be $R$-modules, then a function $f:M\\to N$ is a homomorphism of $R$-modules (or $R$-module map) if $f$ is a homomorphism of groups under addition and $\\forall r\\in R,m\\in M,f(r\\cdot m)=r\\cdot f(m)$.\\\\\r\n    A bijective homomorphism is called an isomorphism, and two $R$-modules $M,N$ are called isomorphic (written as $M\\cong N$) if there is an isomorphism between them.\r\n\\end{definition}\r\n\\begin{example}\r\n    When $R$ is a field, a homomorphism of $R$-modules is a linear map.\r\n\\end{example}\r\n\\begin{theorem}[(First) Isomorphism Theorem for Modules]\r\n    Suppose $M,N$ are $R$-modules and $f:M\\to N$ is a homomorphism of $R$-modules, then $\\ker f\\le M,f(M)\\le N$ and $M/\\ker f\\cong f(M)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Similar to before.\r\n\\end{proof}\r\n\\begin{theorem}[Second Isomorphism Theorem]\r\n    Let $A,B$ be $R$-submodules of an $R$=module $M$, then $A+B=\\{a+b:a\\in A,b\\in B\\}\\le M$ and $A\\cap B\\le M$.\r\n    Moreover, $A/(A\\cap B)\\cong (A+B)/B$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Use the First Isomorphism Theorem.\r\n\\end{proof}\r\nTo motivate the Third Isomorphism Theorem, we note that for $R$-modules $N\\le M$, we have the correspondance between the submodules of $M/N$ and the submodules of $M$ containing $N$.\r\n\\begin{theorem}[Third Isomorphism Theorem]\r\n    Suppose $N\\le L\\le M$ are $R$-modules, then $M/L\\cong (M/N)/(L/N)$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    Same.\r\n\\end{proof}\r\nIn partricular, these are all true for vector spaces by taking the ring to be a field.\r\nOne can compare these results to familiar results in linear algebra (e.g. the First Isomorphism Theorem implies the Rank-Nullity Theorem).\r\n\\subsection{Finitely Generated Modules}\r\n\\begin{definition}\r\n    Let $M$ be an $R$-module, and $m\\in M$, then the submodule $Rm$ generated by $m$ is the smallest $R$-submodule of $M$ containing $m$, i.e. $Rm=\\{r\\cdot m:r\\in R\\}$.\r\n\\end{definition}\r\n\\begin{definition}\r\n    Let $M$ be an $R$-module.\r\n    $M$ is called cyclic if $M=Rm$ for some $m\\in M$.\r\n    $M$ is finitely generated if $\\exists m_1,\\ldots,m_n\\in M$ such that $Rm_1+\\cdots Rm_n=M$.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    An $R$-module $M$ is cyclic iff $M$ is isomorphic as an $R$-module to $R/I$ for some $I\\unlhd R$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $M$ is cyclic, write $M=Rm$, then there is a surjective $R$-module homomorphism $R\\to M$ by $r\\mapsto r\\cdot m$ so the claim follows by the First Isomorphism Theorem.\\\\\r\n    Conversely If $M\\cong R/I$, then $M\\cong R/I=R(1+I)$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    An $R$-module $M$ is finitely generated iff there exists a surjective $R$-module homomorphism from $f:R^n\\to M$ for some $n$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    If $M$ is finitely generated, then $M=Rm_1+\\cdots +Rm_n$ where $m_i\\in M$, so we can take $f(r_1,\\ldots,r_n)=r_1m_1+\\cdots +r_nm_n$.\\\\\r\n    Conversely, if such a map $f$ exists, then $M=Rf(e_1)+\\cdots+Rf(e_n)$, then $e_i$ has $1$ in $i^{th}$ entry and $0$ in $j^{th}$ entry for any $j\\neq i$.\r\n\\end{proof}\r\n\\begin{corollary}\r\n    The quotient of a finitely generated $R$-module is a finitely generated $R$-module.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Obvious from the preceding lemma.\r\n\\end{proof}\r\n\\begin{remark}\r\n    A submodule of a finitely generated $R$-module needs not be finitely generated.\r\n    For example, we can take a non-Noetherian ring $R$ itself as an $R$-module and consider a non-finitely generated ideal of it.\r\n\\end{remark}\r\n\\begin{lemma}\r\n    Let $R$ be an integral domain, then every $R$-submodule of a cyclic $R$-module is cyclic iff $R$ is a PID.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    $R$ itself is a cyclic $R$-module, so if all $R$-submodules of it are cyclic, then all of its ideals are generated by one element, so $R$ is a PID.\\\\\r\n    Conversely, if $R$ is a PID and $M$ is a cyclic $R$-module, so $M\\cong R/I$ for $I\\unlhd R$, so the $R$-submodules of $M$ are in the form $J/I$ for $I\\subset J\\unlhd R$.\r\n    Now since $R$ is a PID, $J$ is principal, so $J/I$ is cyclic.\r\n\\end{proof}\r\n\\begin{theorem}\r\n    Let $R$ be a PID, and $M$ an $R$-module.\r\n    Suppose $M$ is generated by $n$ elements, then any $R$-submodule $N$ of $M$ can also be generated by at most $n$ elements.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    $n=1$ is the preceding lemma.\r\n    For general $n$, we proceed by induction.\r\n    Suppose $M=Rx_1+\\cdots Rx_n$.\r\n    Let $M_i=Rx_1+\\cdots Rx_i$ and $0=M_0\\le M_1\\le\\cdots\\le M_n=M$.\r\n    So we have\r\n    $$0=M_0\\cap N\\le M_1\\cap N\\le\\cdots\\le M_n\\cap N=N$$\r\n    Then the $R$-module map $M_i\\cap N\\to M_i/M_{i-1}$ by $m\\mapsto m+M_{i-1}$ has kernel $M_{i-1}\\cap N$.\r\n    Hence\r\n    $$(M_i\\cap N)/(M_{i-1}\\cap N)\\cong M'\\le M_i/M_{i-1}$$\r\n    But $M_i/M_{i-1}$ is cyclic by hypothesis, so by preceding lemma, $(M_i\\cap N)/(M_{i-1}\\cap N)$ is also cyclic and is generated by $y_i+M_{i-1}\\cap N$ where $y_i\\in M_i\\cap N$.\r\n    Therefore $M_i=M_{i-1}\\cap N+Ry_i$.\r\n    It follows that $M_i\\cap N=Ry_1+\\cdots +Ry_i$.\r\n    In particular, $N=M_n\\cap N=Ry_1+\\cdots+Ry_n$, so $N$ is generated by $n$ elements.\r\n\\end{proof}\r\n\\begin{example}\r\n    Take $R=\\mathbb Z$, then we know that any subgroup of $\\mathbb Z^n$ can be generated by $n$ elements.\r\n\\end{example}", "meta": {"hexsha": "73fe92cb3177a237c53b18fd500d175a3f86ba7e", "size": 8122, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "14/modules.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": "14/modules.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": "14/modules.tex", "max_forks_repo_name": "david-bai-notes/IB-Groups-Rings-and-Modules", "max_forks_repo_head_hexsha": "f4d4cc7141d30f03f775a67afc5a724db6a35da6", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 59.7205882353, "max_line_length": 237, "alphanum_fraction": 0.6547648362, "num_tokens": 2896, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516188, "lm_q2_score": 0.8933094110250331, "lm_q1q2_score": 0.757497568508244}}
{"text": "\\subsection{Curl}\r\n\\noindent\r\nIn 2D, we define the curl of a vector field $\\vec{F}(x,y) = \\langle P(x,y), Q(x,y) \\rangle$ as\r\n\\begin{equation*}\r\n\t\\nabla \\times \\vec{F} = Q_x - P_y\r\n\\end{equation*}\r\nNote that the result is a scalar for this 2D case.\\\\\r\nIf $Q_x > 0$, then the field line accelerate upwards and to the left together: a counter-clockwise rotation.\\\\\r\nIf $P_y > 0$, then the field lines accelerate upwards and to the left together: a clockwise rotation.\\\\\r\nSo, $\\nabla \\times \\vec{F}$ tells us the net counter-clockwise rotation at a point.\\\\\r\n\r\n\\noindent\r\nWe use the same del operator we introduced in divergence for curl, so $\\nabla \\times \\vec{F} = \\left< \\frac{\\partial}{\\partial x}, \\frac{\\partial}{\\partial y},\\ldots \\right> \\times \\vec{F}$. This means that for 3D and higher dimensions, the curl is a vector that is perpendicular to the plane of net rotation.\\\\\r\n\r\n\\noindent\r\nFor example, let's compute the curl of $\\vec{F}(x,y) = \\langle -y, x \\rangle$.\\\\\r\n\\begin{equation*}\r\n\t\\frac{\\partial}{\\partial x}(x) - \\frac{\\partial}{\\partial y}(-y) = 1-(-1) = 2\r\n\\end{equation*}\r\n\r\n\\input{./vectorAnalysis/curlConservativeVFs}\r\n\\input{./vectorAnalysis/divergenceOfCurl}", "meta": {"hexsha": "ec0b51f17094966500faddd231cdf7dcced1c827", "size": 1182, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/curl.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "multiCalc/vectorAnalysis/curl.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "multiCalc/vectorAnalysis/curl.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": 53.7272727273, "max_line_length": 312, "alphanum_fraction": 0.692893401, "num_tokens": 378, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933093946927837, "lm_q2_score": 0.8479677526147223, "lm_q1q2_score": 0.7574975598072577}}
{"text": "\\lab{Optimization with Scipy}{scipy.optimize}\n\\label{lab:Optimization1}\n\\objective{The Optimize package in Scipy provides highly optimized and versatile methods for solving fundamental optimization problems.  \nIn this lab we introduce the syntax and variety of \\li{scipy.optimize} as a foundation for unconstrained numerical optimization.}\n\nNumerical optimization is one of the most common modern applications of mathematics. \nMany mathematical problems can be rewritten in terms of optimization, and unless the problem is both simple and small, usually cannot be solved analytically, and must be approximated by numerical computation. \n\nTo assist with this, the \\li{scipy.optimize} package has several functions for minimizing, root finding, and curve fitting, of which we will introduce the most essential.\n\nYou can learn about all of the functions at \\url{http://docs.scipy.org/doc/scipy/reference/optimize.html}.\n\n\\section*{Local Minimization} % ===============================================\n\nFirst we will test out a few of the minimization algorithms on the Rosenbrock function, which is defined as\n\\[\nf(x,y) = (1-x)^2 + 100(y-x^2)^2.\n\\]\nThe Rosenbrock function is commonly used when evaluating the performance of an optimization algorithm.\nReasons for this include the fact that its minimizer \\li{x = np.array([1., 1.])} is found in  curved valley, and so minimizing the function is non-trivial.\nSee Figure \\ref{opt:rosenbrock}.\nThe Rosenbrock function is included in the optimize package (as \\li{rosen}), as well as its gradient (\\li{rosen_der}) and its hessian (\\li{rosen_hess}).\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Rosenbrock.pdf}\n\\caption{$f(x,y) = (1-x)^2 + 100(y-x^2)^2$}\n\\label{opt:rosenbrock}\n\\end{figure}\n\nWe will use the \\li{minimize()} function and test some of its algorithms (specified by the keyword argument ``method\" -- see the documentation page for \\li{minimize()}).\nFor each algorithm, you need to pass in a callable function object for the Rosenbrock function, as well as a NumPy array giving the initial guess.\nFor some algorithms, you will additionally need to pass in the jacobian or hessian.\nYou may recognize some of these algorithms, and several of them will be discussed in greater detail later. For this lab, you do not need to understand how they work, just\nhow to use them.\n\n% Give an example and explain how to read the output\nAs an example, we'll minimize the Rosenbrock with the Newton-CG method. \nThis method often performs better by including the optional hessian as an argument, which we will do here.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> from scipy import optimize as opt\n>>> x0 = np.array([4., -2.5])\n>>> opt.minimize(opt.rosen, x0, method='Newton-CG', hess=opt.rosen_hess, \n\t\t\t\t\t\t\t\t\t\t\t\t\tjac=opt.rosen_der)\n     fun: 1.1496545381999877e-15\n     jac: array([  1.12295570e-05,  -5.63744647e-06])\n message: 'Optimization terminated successfully.'\n    nfev: 45\n    nhev: 34\n     nit: 34\n    njev: 78\n  status: 0\n success: True\n       x: array([ 0.99999997,  0.99999993])\n\\end{lstlisting}\nAs the online documentation indicates, \\li{opt.minimize()} returns an object of type \\li{opt.optimize.OptimizeResult}. \n\nThe printed output gives you information on the performance of the algorithm. \nThe most relevant output for this lab include \n\n\\li{fun: 1.1496545381999877e-15}, the obtained minimum; \n\n\\li{nit: 96}, the number of iterations the algorithm took to complete; \n\n\\li{success: True}, whether the algorithm converged or not; \n\n\\li{x: array([ 0.99999997,  0.99999993])}, the obtained minimizer.\n\nEach of these outputs can be accessed either by indexing \\li{OptimizeResult} object like a dictionary (\\li{result['nit']}), or as attributes of a class (\\li{result.nit}).  \nWe recommend access by indexing, as this is consistent with other optimization packages in Python.\n\nThe online documenation for \\li{scipy.optimize.minimize()} includes other optional parameters available to users, for example, to set a tolerance of convergence. \nIn some methods, the derivative may be optional, while it may be necessary in others. \nWhile we do not cover all possible parameters in this lab, they should be explored as needed for specific applications.\n\n\\begin{problem} % Minimize the Rosenbrock function.\nUse the \\li{opt.minimize()} function to find the minimum of the Rosenbrock function.\nTest Nelder-Mead, CG, and BFGS, starting each with the initial guess \\li{x_0 = np.array([4., -2.5])}.\nFor each method, print whether it converged, and if so, print how many iterations it took.\n\nNote that the hessian argument is not needed for these paticular methods. \n\\end{problem}\n\nEach of these three algorithms will be explored in great detail later in Volume 2: Nelder-Mead is a variation of the Simplex algorithm, CG is a variant of the Conjugate Gradient algorithm, and BFGS is a quasi-Newton method developed by Broyden, Fletcher, Goldfarb, and Shanno.\n\nThe \\li{minimize()} function can use various algorithms, each of which is best for certain problems.  \nWhich algorithm one uses depends on the specific nature of one's problem. \n\nIt is also important to note that in many optimization applications, very little is known about the function to optimize. \nThese functions are often called \\emph{blackbox functions}.\nFor example, one may be asked in the airline industry to analyze and optimize certain properties involving a segment of airplane wing. \nPerhaps expert engineers have designed extremely robust and complicated software to model this wing segment given certain inputs, but this function is so complicated that nobody except the experts dares to try parcing it.\nBriefly said, you simply don't want to understand it; nobody wants to understand it. \n\nFortunately, one can still optimize effectively in such situations by wisely selecting a correct algorithm.\nHowever, because so little is known about the blackbox function, one must wisely select an appropriate minimization method and follow the specifications of the problem exactly.\n\n\\begin{problem} % Minimize a 'blackbox' function.\nMinimize the \\li{blackbox()} function in the \\li{blackbox_function} module. \nYou don't need to know the source code or how it works in order to minimize it.\nSimply select the appropriate method of \\li{scipy.optimize.minimize()} for this problem, without passing your method a derivative. \nYou may need to test several methods and determine which is most appropriate.\n\nThe function \\li{blackbox()} returns a certain measure of a piecewise-linear curve between two fixed points: the origin, and the point \\li{(40,30)}.\nThis function accepts a one-dimensional \\li{ndarray} of length \\li{m} of y-values, where \\li{m} is the number of points of the piecewise curve excluding endpoints.\nThese points are spaced evenly along the x-axis, so only the y-values of each point are passed into \\li{blackbox()}.\n\nOnce you have selected a method, select an initial point with the following code:\n\n\\begin{lstlisting}\ny_initial = 30*np.random.random_sample(18)\n\\end{lstlisting}\n\nThen plot your initial curve and minimizing curve together on the same plot, including endpoints.\nNote that this will require padding your array of internal y-values with the y-values of the endpoints, so that you plot a total of 20 points for each curve.\n\\end{problem}\n\n\\section*{Global Minimization via Basin Hopping} % ============================\n\nIn the realm of optimization, convex functions are the most well-behaved, as any local minimum is a global minimum.\nHowever, in practice one must frequently deal with non-convex functions, and sometimes we need pick the global minimum out of many local minima.\n\nFor example, consider the function\n%This is the crazy function that we came up with to stump the algorithms\n\\[\nz = r^2 (1+ \\sin^2(4r)),\n\\]\nwhere\n\\[\nr = \\sqrt{(x+1)^2 + y^2}.\n\\]\nEssentially, this is a wavy crater offset from the origin by 1 along the $x$ axis (see Figure \\ref{opt:multimin}).\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{ManyMinima.pdf}\n\\caption{$z = r^2 (1+ 2\\sin^2(4r))$}\n\\label{opt:multimin}\n\\end{figure}\nThe presence of many local minima proves to be a difficulty for the minimization algorithms.\n\nFor example, if we try using the Nelder-Mead method as previously, with an initial point of \\li{x0 = np.array([-2, -2])}, the algorithm fails to find the global minimum, and instead comes to rest on a local minimum.\n\\begin{lstlisting}\n>>> def multimin(x):\n>>>     r = np.sqrt((x[0]+1)**2 + x[1]**2)\n>>>     return r**2 *(1+ np.sin(4*r)**2)\n>>>\n>>> x0 = np.array([-2, -2])\n>>> res = opt.minimize(multimin, x0, method='Nelder-Mead')\n final_simplex: (array([[-2.11758025, -2.04313668], [-2.11748198, -2.04319043],\n       [-2.11751491, -2.04317242]]), array([ 5.48816866,  \n       \t\t\t\t\t\t\t\t\t\t\t\t5.48816866,  5.48816866]))\n           fun: 5.488168656962328\n       message: 'Optimization terminated successfully.'\n          nfev: 84\n           nit: 44\n        status: 0\n       success: True\n             x: array([-2.11758025, -2.04313668])\n>>> print res['x']\n[-2.11758025, -2.04313668]\n>>> print res['fun']\n5.488168656962328\n>>> print multimin([-1,0])\n0.0\n\\end{lstlisting}\n\nHowever, SciPy does have some tools to help us with these problems. \nSpecifically, we can use the \\li{opt.basinhopping()} function.\n\nThe \\li{opt.basinhopping()} function uses the same minimizing algorithms (in fact, you can tell it whatever minimizing algorithm you can pass to \\li{opt.minimize()}).\nHowever, once it settles on a minimum, it hops randomly to a new point in the domain (depending on how we set the ``hopping\" distance) that hopefully lies outside of the valley\nor basin belonging to the current local minimum.\nIt then searches for the minimum from this new starting point, and if it finds a better minimizer, it repeats the hopping process from this new minimizer. \nThus, the \\li{opt.basinhopping()} function has multiple chances to escape a local basin and find the correct global minimum. \n\n\\emph{Only Scipy Version 0.12+ has \\li{opt.basinhopping}. In earlier versions, such as 0.11, you won't find it.}\n\n\\begin{problem} % Basinhopping\nExplore the documentation for the \\li{opt.basinhopping()} function online or via IPython, and use it to find the global minimum of our \\li{multimin()} function with \\li{x0 = np.array([-2, -2])}.\nCall it using the same \\li{Nelder-Mead} algorithm with \\li{opt.basinhopping(multimin, x0, stepsize=0.5, minimizer_kwargs=\\{'method':'nelder-mead'\\})}.\nTry it first with \\li{stepsize=0.5} and then with \\li{stepsize=0.2}. \n\nPlot the multimin function using the following code:\n\\begin{lstlisting}\nxdomain = np.linspace(-3.5,1.5,70)\nydomain = np.linspace(-2.5,2.5,60)\nX,Y = np.meshgrid(xdomain,ydomain)\nZ = multimin((X,Y))\nfig = plt.figure()\nax1 = fig.add_subplot(111, projection='3d')\nax1.plot_wireframe(X, Y, Z, linewidth=.5, color='c')\n\\end{lstlisting}\n\nPlot the initial point and minima by adapting the following line:\n\\begin{lstlisting}\nax1.scatter(x_value, y_value, z_value)     \n\\end{lstlisting}\n\nWhy doesn't the alogrithm find the global minimum with \\li{stepsize=0.2}?\nPrint your answer to this question, and return the true global minimum.\n\\end{problem}\n\n\\section*{Root Finding} % =====================================================\n\nThe \\li{optimize} package also has functions useful in root-finding.\nThe next example, taken from the online documentation, solves the following nonlinear system of equations using \\li{opt.root}.\n\n\\[\n\\begin{bmatrix}\n\tx_{0} + 1/2 ( x_{0} - x_{1} )^{3} - 1 \\\\\n\t1/2(x_{1}-x_{0})^{3} + x_{1}\n\\end{bmatrix} =\n\\begin{bmatrix}\n\t0 \\\\\n\t0\n\\end{bmatrix}.\n\\]\n\n\\begin{lstlisting}\n>>> def func(x):\n>>>     return [x[0] + 0.5 * (x[0] - x[1])**3 -1.0,\n>>>             0.5 * ( x[1] - x[0])**3 + x[1]]\n>>> def jac(x):\n>>>     return np.array([[1 + 1.5 * (x[0] - x[1])**2,\n>>>                     -1.5 * (x[0] - x[1])**2],\n>>>                     [-1.5 * (x[1] - x[0])**2,\n>>>                     1 + 1.5 * (x[1] - x[0])**2]])\n>>> sol = opt.root(func, [0, 0], jac=jac, method='hybr')\n>>> print sol.x\n[ 0.8411639  0.1588361]\n>>> print func(sol.x)\n[-1.1102230246251565e-16, 0.0]\n\\end{lstlisting}\n\n\\begin{problem}\nFind the roots of the system\n\\[\n\\begin{bmatrix}\n\t-x+y+z \\\\\n\t1+x^3-y^2+z^3\\\\\n\t-2-x^2+y^2+z^2\n\\end{bmatrix} =\n\\begin{bmatrix}\n\t0 \\\\\n\t0 \\\\\n\t0\n\\end{bmatrix} .\n\\]\nReturn the values of $x,y,z$ as an array.\n\\end{problem}\n\nAs with \\li{opt.minimize()}, \\li{opt.root()} has more than one algorithm for root finding.\nHere we have used the \\li{hybr} method. \nThere are also several algorithms for scalar root finding. See the online documentation for more.\n\n\\section*{Curve Fitting} % ====================================================\n\n%we still have curve fitting\n%least squares programming -- but it seems that it's already been done in Volume One\n\nSciPy also has methods for curve fitting wrapped by the \\li{opt.curve_fit()} function.\nJust pass it data and a function to be fit. \nThe function should take in the independent variable as its first argument and values for the fitting parameters as subsequent arguments.\nExamine the following example from the online documentation.\n\\begin{lstlisting}\n>>> import numpy as np\n>>> import scipy.optimize as opt\n\n>>> #the function with which to create the data and later fit it\n>>> def func(x,a,b,c):\n>>>     return a*np.exp(-b*x) + c\n\n>>> #create perturbed data\n>>> x = np.linspace(0,4,50)\n>>> y = func(x,2.5,1.3,0.5)\n>>> yn = y + 0.2*np.random.normal(size=len(x));\n\n>>> #perform the fit\n>>> popt, pcov = opt.curve_fit(func,x,yn)\n\\end{lstlisting}\nThe variable \\li{popt} now contains the fitted parameters and \\li{pcov} gives the covariance of the fit.\nSee Figure \\ref{opt:curve_fit} for a plot of the data and the fitted curve.\n\nOne of the most fundamental phenomena in the physical and engineering sciences is turbulent convection, wherein an unstable density gradient induces a fluid to move chaotically (basically, hot air rises).  \nThis problem is so important that experiments and numerical simulations have been pushed to their limits in the past several decades to determine the qualitative nature of the fluid's motion under an extreme forcing (think of boiling a pot of water, but instead at temperatures akin to the interior of the sun).  \nThe strength of the forcing (amount of the enforced temperature gradient) is measured by the non-dimensional Rayleigh number $R$.  \nOf paticular interest is to determine how well the chaotic turbulent flow transports the heat from the hot bottom to the cold top, as measured by the Nusselt number $\\nu$.  \nOne of the primary goals of experiments, simulations, and analysis is to determine how the Nusselt number $\\nu$ depends on the Rayleigh number $R$, i.e. if the bottom of the pot of water is heated more strongly, how much faster does the boiling water transport heat to the top?\n\nIt is often generically believed that the Nusselt number obeys a power law of the form $\\nu = cR^\\beta$, where $\\beta \\le 1/2$.  \nThrough some mild assumptions on the temperature, we can construct an eigenvalue problem that we solve numerically for a variety of Rayleigh numbers, thus obtaining an upper bound on the Nusselt number as $\\nu \\le cR^\\beta$.  With our physical specifications of the problem, we may predict $\\beta < 1/2$.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{curve_fit.pdf}\n\\caption{Example of perturbed data graphed with the resulting curve using the fitted parameters: $a=2.72$,  $b=1.31$, and $c=0.45$.}\n\\label{opt:curve_fit}\n\\end{figure}\n\n\\begin{problem} % Convection curve fitting.\nUse \\li{opt.curve_fit()} to fit a curve to data obtained from numerical simulations of convection.\nThe data are in the file \\li{convection.npy}. \nThe first column is $R$, the Rayleigh number, and the second column is $\\nu$, the Nusselt number.\nWith the convection equation \n\\[\n\\nu = cR^\\beta,\n\\]\nuse \\li{opt.curve_fit()} to find a fit to the data using $c$ and $\\beta$ as the fitting parameters. \nSee Figure \\ref{opt:ConvectionFit} for a plot of the data along with a fitted curve.\nThough it may be difficult to see in the figure, the first four points skew the data, and do not help us determine the appropriate long-term values of $c$ and $\\beta$. \nThus, do not use the first four points when fitting a curve to the data, but include them in the plot.\n\nJust so that you know that you are getting realistic values, $c$ should be around $.1$, and $\\beta$ should be less than $1/2$.\nReturn your values for $c$ and $\\beta$ in a NumPy array of length 2.\n\\end{problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{ConvectionFit.pdf}\n\\caption{The black points are the data from \\li{convection.npy} plotted as a scatter plot. The blue line is a fitted curve.}\n\\label{opt:ConvectionFit}\n\\end{figure}\n\nThe \\li{scipy.optimize} package has many other useful functions, and is a good first resource when confronting a numerical optimization problem. \nSee the online documentation for further details.\n", "meta": {"hexsha": "08c3a6b22456f179959f6b6fa56de187af90e417", "size": 16881, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Vol2B/scipyoptimize/scipyoptimize.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/scipyoptimize/scipyoptimize.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/scipyoptimize/scipyoptimize.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": 52.2631578947, "max_line_length": 313, "alphanum_fraction": 0.7296368699, "num_tokens": 4459, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088163, "lm_q2_score": 0.861538211208597, "lm_q1q2_score": 0.7574185416539788}}
{"text": "\\section{Universal coefficient theorem (and $\\Hom$, adjointness)}\nOn Wednesday, we'll talk about the K\\\"{u}nneth theorem, and later we'll talk about the K\\\"{u}nneth theorem. We've been talking about tensor products of $R$-modules, but we can do something that's more natural in a way. That's the notion of $\\Hom_R(M,N)$, which is the collection of $R$-linear homomorphisms between $R$-modules $M$ and $N$. This is actually itself an $R$-module. It's an abelian group, first of all, because you can add morphisms. How does $r\\in R$ act on $f\\in \\Hom_R(M,N)$? Just define $(rf)(x)=f\\cdot f(x)$. You should check that this does actually define an $R$-module homomorphism. (This is trivial.) If $R$ isn't commutative I guess there'd be an action of $Z(R)$ on $\\Hom_R(M,N)$. In particular, $\\Hom_R(M,-):\\mathbf{Mod}_R\\to\\mathbf{Mod}_R$.\n\\begin{remark}\nYou're supposed to technically write $\\underline{\\Hom}_R(M,N)$ to mean $\\Hom_R(M,N)$ with the structure of an $R$-module. But in these notes, I will not do this.\n\\end{remark}\nI wanted to bring this up because it relates to tensor products in a beautiful way. Consider $\\Hom_R(M\\otimes_R N,L)$. This is the collection of $R$-bilinear maps $M\\times N\\to L$. I claim that $\\Hom_R(M\\otimes_R N,L)\\cong\\Hom_R(M,\\Hom_R(N,L))$. The way this works is the following. Suppose $f:M\\otimes_R N\\to L$. Define $\\widehat{f}:M\\to\\Hom_R(N,L)$ via $\\widehat{f}:m\\mapsto(n\\mapsto f(m\\otimes_R n))$. This is a special case of the notion of an adjoint functor, introduced by Dan Kan, who was actually here at MIT. This is a big part of category theory.\n\\begin{prop}\nLet $\\cI$ be a direct set, and let $M:\\cI\\to\\mathbf{Mod}_R$ be a $\\cI$-directed system of $R$-modules. There is a natural isomorphism $(\\varinjlim_I M_i)\\otimes_R N\\cong \\varinjlim_I (M_i\\otimes_R N)$. It's very technical but it might be very useful. Maybe in the homework for example \\emph{;-)}\n\\end{prop}\n\\begin{proof}\nConsider $\\Hom_R((\\varinjlim_I M_i)\\otimes_R N,L)\\cong\\Hom_R(\\varinjlim_I M_i,\\Hom_R(N,L))$. That's cool, because this is the same thing as $\\Map_{\\Fun(\\cI,\\mathbf{Mod}_R)}(\\{M_i\\},c_{\\Hom_R(N,L)})$ because $\\{M_i\\}$ is a $\\cI$-directed system. Now, this is the same as $\\Map_{\\Fun(\\cI,\\mathbf{Mod}_R)}(\\{M_i\\otimes_R N\\},c_{L})$ by the Hom-tensor adjunction. We can unspool this to see that this is $\\Hom_R(\\varinjlim_\\cI (M_i\\otimes_R N),L)$. Now conclude via the Yoneda lemma (which we haven't discussed yet, but I think is a homework problem). Basically this states that $\\Map_\\cc(X,-)$ determines $X$.\n\\end{proof}\nWe'll talk a lot more about $\\Hom$ and adjunctions, but not today.\n\nHere's the question I want to talk about today. Suppose that I'm given $ H_\\ast(X;\\Z)$. Does it determine $ H_\\ast(X;\\Z/2\\Z)$? Consider $\\RP^2\\to S^2$. In homology with coefficients in $\\Z$, in dimension $2$, this map must induce $0$. But in $\\Z/2\\Z$-coefficients, in dimension $2$, this map gives an isomorphism. I could have considered reduced homology. This shows that there's not a functorial relationship between $ H_\\ast(X;\\Z)$ and $ H_\\ast(X;\\Z/2\\Z)$. So how \\emph{do} we go between different coefficients? That's the mystery.\n\nLet $R$ be a commutative ring. Let $M$ be a $R$-module. I want to think about some chain complex $C_\\bullet$ of $R$-modules. It could be the singular complex of a space, but it doesn't have to be. I'm going to forget to write $\\otimes_R$ now; I'll just write $\\otimes$. I can consider $ H_n(C_\\bullet)\\otimes M$, or $ H_n(C_\\bullet\\otimes M)$. The latter thing gives homology with coefficients in $M$. How can we compare these two? I claim that I can construct a map $\\alpha: H_n(C_\\bullet)\\otimes M\\to H_n(C_\\bullet\\otimes M)$. Recall the exact sequence $0\\to B_n\\to Z_n(C_\\bullet)\\to H_n\\to 0$ that defines homology. So I get an exact sequence $B_n\\otimes M\\to Z_n(C_\\bullet)\\otimes M\\to H_n(C_\\bullet)\\otimes M\\to 0$. And there's a surjection $Z_n(C_\\bullet)(C\\otimes M)\\to H_n(C_\\bullet\\otimes M)$. I have to tell you where $x\\otimes m\\in Z_n(C_\\bullet)\\otimes M$ goes. I'll send it to $x\\otimes m\\in Z_n(C_\\bullet)(C_\\bullet\\otimes M)$. I claim that this is a cycle, because $d(x\\otimes m)=(dx)\\otimes m$. But $x\\in\\ker d$, so this is zero, and thus $x\\otimes m\\in Z_n(C_\\bullet)(C_\\bullet\\otimes M)$. Does it descend to a map in homology? We want to check that $B_n\\otimes M\\to Z_n(C_\\bullet)(C_\\bullet\\otimes M)$ is zero. Suppose $y\\in C_{n+1}$. Then $dy\\in C_n$. Where does $dy\\otimes x$ go? Send it to $d(y\\otimes x)\\in B_n(C_\\bullet\\otimes M)$. And this maps to zero.\n\nThe problem is that $\\alpha$ is not always an isomorphism. But it is if $M$ is free, say $M=R\\langle S\\rangle$. That's because then $C_\\bullet\\otimes M\\cong\\bigoplus_S C_\\bullet$. Now there's a little lemma that nobody tells you about, because it's obvious, but here it is anyway:\n\\begin{lemma}\nSuppose I have a collection of exact sequences of $R$-modules $A_i\\to B_i\\to C_i$. Then $\\bigoplus A_i\\to \\bigoplus B_i\\to \\bigoplus C_i$ is short exact, i.e., $\\bigoplus$ is an exact functor.\n\\end{lemma}\n\\begin{proof}\nThe composition is obviously zero. If $(b_i)\\in\\bigoplus B_i$ maps to $0$, then by exactness, there are $a_i$ that map to $b_i$, and we assume that if some $b_i=0$, then $a_i=0$.\n\\end{proof}\nThis in particular implies that $ H(\\bigoplus C_i)\\cong\\bigoplus H(C_i)$.\n\nConsider a free resolution of $M$. Assume $R$ is a PID, so that $M$ has a free resolution of the form $0\\to F_1\\to F_0\\to M\\to 0$. Thus we get a chain complex $C_\\bullet\\otimes F_1\\to C_\\bullet\\otimes F_0\\to C_\\bullet M\\to 0$. Now I get a lexseq in $\\Tor$, namely $\\cdots\\to\\Tor^R_1(C_\\bullet,M)\\to C_\\bullet\\otimes F_1\\to C_\\bullet\\otimes F_0\\to C_\\bullet M\\to 0$.\n\nNow I'm going to make a second assumption. Suppose $C_n$ is a free $R$-module for all $n$. At least that $\\Tor^R_1(C_n,M)=0$. This shouldn't bother you at all, because the chain complexes that we need satisfy this condition. In particular, we have a sexseq $0\\to C_\\bullet\\otimes F_1\\to C_\\bullet\\otimes F_0\\to C_\\bullet M\\to 0$. What happens then? We get a lexseq. I want to give an unspliced form of this (huge diagram coming up!).\n\\begin{equation*}\n\\xymatrix{0\\ar[d]\\ar@{=}[r] & 0\\ar[d]\\\\\n\\coker( H_n(C_\\bullet\\otimes F_1)\\to H_n(C_\\bullet\\otimes F_0))\\ar[d]\\ar@{=}[r] & H_n(C_\\bullet)\\otimes M\\ar[d]^\\alpha\\\\\n H_n(C_\\bullet\\otimes M)\\ar[d]^\\partial\\ar@{=}[r] & H_n(C_\\bullet\\otimes M)\\ar[d]^\\partial\\\\\n\\ker( H_{n-1}(C_\\bullet\\otimes F_1)\\to H_{n-1}(C_\\bullet\\otimes F_0))\\ar@{=}[r]\\ar[d] & \\Tor^R_{1}( H_{n-1}(C_\\bullet),M)\\ar[d]\\\\\n0\\ar@{=}[r] & 0}\n\\end{equation*}\nBecause $\\ker( H_{n-1}(C_\\bullet\\otimes F_1)\\to H_{n-1}(C_\\bullet\\otimes F_0))=\\ker( H_{n-1}(C_\\bullet)\\otimes F_1\\to H_{n-1}(C_\\bullet)\\otimes F_0)$ and $\\coker( H_n(C_\\bullet)\\otimes F_1\\to H_n(C_\\bullet)\\otimes F_0)$. Also, $\\ker( H_{n-1}(C_\\bullet\\otimes F_1)\\to H_{n-1}(C_\\bullet\\otimes F_0))=\\Tor^R_{1}( H_{n-1}(C_\\bullet),M)$ because of the lexseq $0\\to \\Tor^R_1( H_{n-1}(C_\\bullet),M)\\to H_{n-1}(C_\\bullet)\\otimes F_1\\to H_{n-1}(C_\\bullet)\\otimes F_0\\to H_{n-1}(C_\\bullet)\\otimes M\\to 0$.\n\nThus we have a sexseq, which gives the universal coefficient theorem:\n\\begin{theorem}[Universal Coefficient Theorem]\nIf $R$ is a PID and $C_n$ is free for all $n$, then there is a natural sexseq of $R$-modules:\n\\begin{equation*}\n0\\to H_n(C_\\bullet)\\otimes M\\xrightarrow{\\alpha} H_n(C_\\bullet\\otimes M)\\xrightarrow{\\partial}\\Tor^R_1( H_{n-1}(C_\\bullet),M)\\to 0\n\\end{equation*}\nA further fact that we won't prove is that this splits as a sexseq of $R$-modules, but not naturally.\n\\end{theorem}\n\\begin{example}\nConsider $ H_2(\\RP^2;\\Z/2\\Z)\\cong\\Z/2\\Z$, and we can consider $ H_2(\\RP^2;\\Z)\\otimes\\Z/2\\Z=0$. So by the UCT, this must come from $\\Tor^\\Z_1( H_1(\\RP^2;\\Z),\\Z/2\\Z)\\cong\\Z/2\\Z$. So $\\partial$ is an isomorphism. This explains the mystery that we began with.\n\\end{example}\n\\begin{remark}\nSuppose $R$ is not a PID. For example, consider what we worked with before, e.g., $R=k[e]/(e^2)$, and let $M=k$ (so $e$ acts as $0$). Consider the chain complex $C_\\bullet:\\cdots\\to R\\xrightarrow{e}R\\xrightarrow{e} R\\xrightarrow{e}R\\to 0$. This is actually the free resolution of $k$ that we found before. In particular, $ H_n(C_\\bullet)=\\begin{cases}k & n=0 \\\\ 0 & n\\neq 0\\end{cases}$. What is $C_\\bullet\\otimes_R k$? It's exactly $\\cdots\\to k\\xrightarrow{0}k\\xrightarrow{0} k\\xrightarrow{0}k\\to 0$. So $ H_n(C_\\bullet\\otimes_R k)=\\begin{cases}k & n>0 \\\\ 0 & n<0\\end{cases}=\\Tor^R_n(k,k)$. The two homologies are super different. The excess $\\Tor$'s are accounted for via spectral sequences, which you'll see when you take 18.906.\n\\end{remark}\nThe next step is to consider the homology of products.\n", "meta": {"hexsha": "055e850205e6b6fdcd4350b1ec1b4eeb4149915c", "size": 8621, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-24-uct.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-24-uct.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-24-uct.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": 156.7454545455, "max_line_length": 1377, "alphanum_fraction": 0.7065305649, "num_tokens": 3057, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7574185338402919}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Independence of events and independence of random variables %\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section{Independence of Events and Random Variables}\n\n\\begin{theorem}{6.3}{Monotone Class Theorem}\n\n    Let $\\Pi$ be a $\\pi$-system contained in a $\\lambda$-system $\\Lambda$. Then $\\sigma(\\Pi)$ is contained in $\\Lambda$.\n\n\\end{theorem}\n\n\\begin{proposition}{6.4}{Extending $\\pi$-System Independence}\n\n    Let $C_1$ and $C_2$ be two \\emph{independent} $\\pi$-systems, i.e.\n\n        \\begin{align*}\n            P(A \\cap B) = P(A)P(B) \\quad \\forall A \\in C_1, B \\in C_2,\n        \\end{align*}\n\n    then the \\SigmaAlgebra s $\\sigma(C_1)$ and $\\sigma(C_2)$ are also independent.\n\n\\end{proposition}\n\n\\begin{theorem}{6.7}{Fubini-Tonelli Theorem}\n\n    Let $(\\Omega_i, \\CalF_i, \\mu_i)$, for $i = 1,2$, be measure spaces and $(\\Omega, \\CalF, \\mu)$ be the product measure space of the two, i.e. $\\Omega = \\Omega_1 \\times \\Omega_2$, $\\CalF = \\CalF_i \\otimes \\CalF_2$ and $\\mu = \\mu_1 \\otimes \\mu_2$. Let $f: \\Omega \\to \\overline{\\mathbb{R}}$ be a \\emph{non-negative} $\\CalF$-measurable function. If $\\mu_i$, for $i = 1,2$, are \\emph{finite measures} on $\\Omega_i$, for $i = 1,2$, respectively, then the following iterated integrals are well-defined and:\n\n        \\begin{align*}\n            \\int_{\\Omega_1 \\times \\Omega_2} f \\, d\\mu_1 \\otimes \\mu_2 &= \\int_{\\Omega_1} \\int_{\\Omega_2} f \\, d\\mu_2 d\\mu_1 = \\\\ &= \\int_{\\Omega_2} \\int_{\\Omega_1} f \\, d\\mu_1 d\\mu_2.\n        \\end{align*}\n\n    Furthermore, this statement holds for $\\CalF$-measurable functions if:\n\n        \\begin{align*}\n            \\int_{\\Omega_1 \\times \\Omega_2} |f| \\, d\\mu_1 \\otimes \\mu_2 < \\infty.\n        \\end{align*}\n\n\\end{theorem}\n\n\\begin{lemma}{6.9}{Borel-Cantelli (Full)}\n\n    Let $(A_n)_{n=1}^{\\infty}$ be a sequence of sets and set\n\n        \\begin{align*}\n            A \\coloneqq \\limsup_{n \\to \\infty} A_n \\coloneqq \\bigcap_{n=1}^{\\infty}\\bigcup_{k=n}^{\\infty} A_k,\n        \\end{align*}\n\n    then the following statements holds:\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item If $\\sum_{n=1}^{\\infty} \\mu(A_n) < \\infty$, then $\\mu(A) = 0$.\n            \\item If all $A_n$ are \\emph{jointly independent} and $\\sum_{n=1}^{\\infty} P(A_n) = \\infty$, then $P(A) = 1$.\n        \\end{enumerate}\n\n    \\Hint (i) provided in general case. (ii) Prove $P((\\limsup_{n \\to \\infty} A_n)^C) = 1$, define $B_n = \\bigcap_{k=n}^{\\infty} A_k^C$ and show that for a given $P(B_n) = P(\\lim_{m \\to \\infty} \\bigcap_{k=n}^{m} A_k) = 0$ using independence and observation that $1 - P(A) \\leq e^{-P(A)}$. Finally, use \\emph{sub}-$\\sigma$-additivity for $P(\\bigcup_{n=1}^{\\infty} B_n)$. \\emph{Do not} attempt to argue through increasing sequences.\n    \n\\end{lemma}\n\n\\begin{exercise}{}{Pulling Sum Through Variance}\n\n    Let $(X_i)_{i=1}^{\\infty}$ be a sequence of \\emph{pairwise independent} random variables. Assume that $EX_i^2 < \\infty$ for $i=1,2,\\hdots,n$, then\n\n        \\begin{align*}\n            \\mathrm{Var}\\left(\\sum_{i=1}^n X_i\\right) = \\sum_{i=1}^n \\mathrm{Var}\\left(X_i\\right).\n        \\end{align*}\n\n\\end{exercise}\n", "meta": {"hexsha": "9084c21ec9a91d2a5f0b3ed629b66bcada1c02f3", "size": 3190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/independence.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/independence.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/independence.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": 45.5714285714, "max_line_length": 501, "alphanum_fraction": 0.5902821317, "num_tokens": 1134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765140114859, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7573819226465206}}
{"text": "\\section{Double Integrals}\r\n\\noindent\r\nSimilar to how the limit of a Riemann Sum, the sum of the areas of small rectangles, is the area underneath a curve, we can find the volume underneath a surface by summing the volumes of small rectangular prisms.\\\\\r\n\r\n[INSERT IMAGE]\r\n\r\n\\noindent\r\nIn 2D (single variabe): $\\Delta x = \\frac{b-a}{n}$, $\\int_{a}^{b}{f(x)\\mathrm{d}x} = \\lim_{n \\to \\infty}{\\sum_{i = 0}^{n-1}{f(a+i\\Delta x)\\Delta a}}$.\\\\\r\nIn 3D: $\\Delta x = \\frac{b-a}{n}$, $\\Delta y = \\frac{d-c}{n}$,\r\n\\begin{equation*}\r\n\t\\int_{c}^{d}{\\int_{a}^{b}{f(x,y)\\mathrm{d}x}\\mathrm{d}y} = \\lim_{m \\to \\infty}{\\sum_{j = 0}^{m-1}{\\left(\\lim_{n \\to \\infty}{\\sum_{i = 0}^{n-1}{f(a+i\\Delta a, c+j\\Delta y)\\Delta x}}\\right)\\Delta y}}\r\n\\end{equation*}\r\n\\input{./multipleIntegrals/domainRegionsFubinisTheorem}\r\n\\input{./multipleIntegrals/averageValues}\r\n\\input{./multipleIntegrals/volumeBetweenSurfaces}\r\n\\input{./multipleIntegrals/planeLaminas}", "meta": {"hexsha": "c552ef99e0f94bd0754599681384374ac55d3b44", "size": 931, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/doubleIntegrals.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/multipleIntegrals/doubleIntegrals.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/multipleIntegrals/doubleIntegrals.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": 58.1875, "max_line_length": 215, "alphanum_fraction": 0.6702470462, "num_tokens": 350, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206712569268, "lm_q2_score": 0.8397339676722393, "lm_q1q2_score": 0.7573734238001885}}
{"text": "\\section{Geometry}\r\n  \\code{geom/compgeom.cpp}\r\n\t\\subsection{Dots and Cross Products}\r\n    \\code{geom/dot-cross.cpp}\r\n  \\subsection{Angles and Rotations}\r\n    \\code{geom/angles-rots.cpp}\r\n\t\\subsection{Spherical Coordinates}\r\n    \\[\r\n        \\begin{array}{cc}\r\n            x = r \\cos \\theta \\cos \\phi & r = \\sqrt{x^2 + y^2 + z^2} \\\\\r\n            y = r \\cos \\theta \\sin \\phi & \\theta = \\cos^{-1} x/r \\\\\r\n            z = r \\sin \\theta & \\phi = \\mathrm{atan2}(y,x)\r\n        \\end{array}\r\n    \\]\r\n\t\\subsection{Point Projection}\r\n    \\code{geom/pt-proj.cpp}\r\n\t\\subsection{Great Circle Distance}\r\n    \\code{geom/great-circle.cpp}\r\n\t\\subsection{Point/Line/Plane Distances}\r\n    \\code{geom/dists.cpp}\r\n\t\\subsection{Intersections}\r\n    \\subsubsection{Line-Segment Intersection}\r\n      Get intersection points of 2D lines/segments $\\overline{ab}$ and $\\overline{cd}$.\r\n      \\code{geom/line-seg-isect.cpp}\r\n    \\subsubsection{Circle-Line Intersection}\r\n      Get intersection points of circle at center $c$, radius $r$, and line $\\overline{ab}$.\r\n      \\code{geom/circ-line-isect.cpp}\r\n    \\subsubsection{Circle-Circle Intersection}\r\n      \\code{geom/circ-circ-isect.cpp}\r\n\t\\subsection{Areas}\r\n    \\subsubsection{Polygon Area}\r\n      Find the area of any 2D polygon given as points in $O(n)$.\r\n      \\code{geom/poly-area.cpp}\r\n    \\subsubsection{Triangle Area}\r\n      Find the area of a triangle using only their lengths. Lengths must be valid.\r\n      \\code{geom/tri-area.cpp}\r\n    \\subsubsection{Cyclic Quadrilateral Area}\r\n      Find the area of a cyclic quadrilateral using only their lengths. A quadrilateral is\r\n      cyclic if its inner angles sum up to $360^\\circ$.\r\n      \\code{geom/cyc-quad-area.cpp}\r\n  \\subsection{Polygon Centroid}\r\n    Get the centroid/center of mass of a polygon in $O(m)$.\r\n    \\code{geom/poly-centroid.cpp}\r\n  \\subsection{Convex Hull}\r\n    \\subsubsection{2D Convex Hull}\r\n      Get the convex hull of a set of points using Graham-Andrew's scan. This sorts the\r\n      points at $O(n \\log n)$, then performs the Monotonic Chain Algorithm at $O(n)$.\r\n      \\code{geom/convex-hull.cpp}\r\n    \\subsubsection{3D Convex Hull}\r\n      Currently $O(N^2)$, but can be optimized to a randomized $O(N\\log{N})$ using the Clarkson-Shor algorithm.\r\n      Sauce: \\href{https://codeforces.com/blog/entry/81768}{Efficient 3D Convex Hull Tutorial on CF}.\r\n      \\code{geom/convex-hull-3d.cpp}\r\n  \\subsectionRed{Delaunay Triangulation}\r\n    Simply map each point $(x,y)$ to $(x,y,x^2+y^2)$, find the 3d convex hull, and drop the 3rd dimension.\r\n  \\subsection{Point in Polygon}\r\n    Check if a point is strictly inside (or on the border) of a polygon in $O(n)$.\r\n    \\code{geom/pt-in-poly.cpp}\r\n  \\subsection{Cut Polygon by a Line}\r\n    Cut polygon by line $\\overline{ab}$ to its left in $O(n)$, such that $\\angle abp$ is counter-clockwise.\r\n    \\code{geom/cut-poly.cpp}\r\n  \\subsection{Triangle Centers}\r\n    \\code{geom/tri-centers.cpp}\r\n  \\subsection{Convex Polygon Intersection}\r\n    Get the intersection of two convex polygons in $O(n^2)$.\r\n    \\code{geom/convex-poly-isect.cpp}\r\n  \\subsection{Pick's Theorem for Lattice Points}\r\n    Count points with integer coordinates inside and on the boundary of a polygon in\r\n    $O(n)$ using Pick's theorem: $\\text{Area} = I + B/2 - 1$.\r\n    \\code{geom/picks.cpp}\r\n  \\subsection{Minimum Enclosing Circle}\r\n    Get the minimum bounding ball that encloses a set of points (2D or 3D) in $\\Theta{n}$.\r\n    \\code{geom/min-enclosing-circ.cpp}\r\n  \\subsection{Shamos Algorithm}\r\n    Solve for the polygon diameter in $O(n \\log n)$.\r\n    \\code{geom/shamos.cpp}\r\n  \\subsection{$k$D Tree}\r\n    Get the $k$-nearest neighbors of a point within pruned radius in $O(k \\log k \\log n)$.\r\n    \\code{geom/kd-tree.cpp}\r\n  \\subsection{Line Sweep (Closest Pair)}\r\n    Get the closest pair distance of a set of points in $O(n \\log n)$ by sweeping a line and\r\n    keeping a bounded rectangle. Modifiable for other metrics such as Minkowski and\r\n    Manhattan distance. For external point queries, see $k$D Tree.\r\n    \\code{geom/closest-pair.cpp}\r\n  \\subsection{Line upper/lower envelope}\r\n    To find the upper/lower envelope of a collection of lines $a_i+b_i x$,\r\n    plot the points $(b_i,a_i)$, add the point $(0,\\pm \\infty)$ (depending\r\n    on if upper/lower envelope is desired), and then find the convex hull.\r\n  \\subsection{Formulas}\r\n    Let $a = (a_x, a_y)$ and $b = (b_x, b_y)$ be two-dimensional vectors.\r\n    \\begin{itemize}\r\n      \\item $a\\cdot b = |a||b|\\cos{\\theta}$, where $\\theta$ is the angle\r\n        between $a$ and $b$.\r\n      \\item $a\\times b = |a||b|\\sin{\\theta}$, where $\\theta$ is the\r\n        signed angle between $a$ and $b$.\r\n      \\item $a\\times b$ is equal to the area of the parallelogram with\r\n        two of its sides formed by $a$ and $b$. Half of that is the\r\n        area of the triangle formed by $a$ and $b$.\r\n      \\item The line going through $a$ and $b$ is $Ax+By=C$ where $A=b_y-a_y$, $B=a_x-b_x$, $C=Aa_x+Ba_y$.\r\n      \\item Two lines $A_1x+B_1y=C_1$, $A_2x+B_2y=C_2$ are parallel iff.\\ $D=A_1B_2-A_2B_1$ is zero. Otherwise their unique intersection is $(B_2C_1-B_1C_2,A_1C_2-A_2C_1)/D$.\r\n      \\item \\textbf{Euler's formula:} $V - E + F = 2$\r\n      \\item Side lengths $a,b,c$ can form a triangle iff.\\ $a+b>c$, $b+c>a$ and $a+c>b$.\r\n      \\item Sum of internal angles of a regular convex $n$-gon is $(n-2)\\pi$.\r\n      \\item \\textbf{Law of sines:} $\\frac{a}{\\sin A} = \\frac{b}{\\sin B} = \\frac{c}{\\sin C}$\r\n      \\item \\textbf{Law of cosines:} $b^2 = a^2 + c^2 - 2ac\\cos B$\r\n      \\item Internal tangents of circles $(c_1,r_1), (c_2,r_2)$ intersect at $(c_1r_2+c_2r_1)/(r_1+r_2)$, external intersect at $(c_1r_2-c_2r_1)/(r_1+r_2)$.\r\n    \\end{itemize}\r\n", "meta": {"hexsha": "7d39f9755081d555e6163b1c573ce8578d34097b", "size": 5711, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebook/tex/geometry.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/geometry.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/geometry.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": 53.3738317757, "max_line_length": 175, "alphanum_fraction": 0.651549641, "num_tokens": 1771, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096112990285, "lm_q2_score": 0.8267118026095992, "lm_q1q2_score": 0.7573586281449991}}
{"text": "\\section{Model}\n\\label{sec:model}\n\nThe model computes the sequence of tags $t_1, ..., t_n$ (also denoted as $t_1^n$) with the highest probability given the observed sequence of words \n$w_1, ..., w_n$:\n\\begin{equation}\n    t_1, ..., t_n = \\argmax_{t_1, ..., t_n} P(t_1^n | w_1^n).\n    \\label{eq:model_original}\n\\end{equation}\n\nApplying the Bayes' Law, we obtain:\n\\begin{equation*}\n    t_1, ..., t_n = \\argmax_{t_1, ..., t_n} \\frac{P(w_1^n | t_1^n) P(t_1^n)}{P(w_1^n)};\n\\end{equation*}\n\nsince the denominator does not depend on $t_1, ..., t_n$, we can drop it:\n\\begin{equation}\n    t_1, ..., t_n = \\argmax_{t_1, ..., t_n} P(w_1^n | t_1^n) P(t_1^n).\n    \\label{eq:model_compact}\n\\end{equation}\n\nWe assume that the probability of a word only depends on its own tag, and not on the tags of the other words in sentence.\nThus, we have that:\n\\begin{equation}\n    P(w_1^n | t_1^n) \\approx \\prod_{i=1}^n P(w_i | t_i).\n    \\label{eq:model_first_term}\n\\end{equation}\n\nEach $P(w_i | t_i)$ can be easily computed from the training data using maximum likelihood as:\n\\begin{equation*}\n    P(w_i | t_i) = \\frac{C(w_i, t_i)}{C(t_i)},\n\\end{equation*}\nwhere $C(t_i, w_i)$ denotes the number of times that word $w_i$ has tag $t_i$ \nand $C(t_i)$ denotes the frequency of tag $t_i$.\n\nThe term $P(t_1^n)$ represent the probability of a tag given all its predecessor in the sentence.\nTo compute the term, we introduce a Markov assumption: the probability of a tag in the sentence\ndepends only on the $m$ previous tags:\n\\begin{equation}\n    P(t_1, ..., t_n) = \\prod_{i=m}^n P(t_i | t_{i-m}, ... t_{i-1}),\n    \\label{eq:model_second_term}\n\\end{equation}\nwhere $t_0$ denotes the beginning of the sentence.\nA Markov assumption of order $m$ corresponds to a $m+1$ n-gram language model.\n\nEach term $P(t_i | t_{i-1})$ can be computed using maximum likelihood as follows:\n\\begin{equation*}\n    P(t_i | t_{i-m}, ..., t_{i-1}) = \\frac{C(t_{i-m}, ..., t_{i})}{C(t_{i-m}, ..., t_{i-1})}.\n\\end{equation*}\n\nUsing \\cref{eq:model_compact}, (\\ref{eq:model_first_term}) and (\\ref{eq:model_second_term}), we can rewrite the model in \\cref{eq:model_original} as:\n\\begin{equation*}\n    t_1^n = \\argmax_{t_1, ..., t_n} \\prod_{i=1}^n P(w_i | t_i) \\prod_{i=m}^n P(t_i | t_{i-m}^{i-1}).\n\\end{equation*}\n", "meta": {"hexsha": "3820c3ee1ec80b97f94cb08d1cd99c28a6a00932", "size": 2254, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/03_model.tex", "max_stars_repo_name": "davidepedranz/lus_project_1", "max_stars_repo_head_hexsha": "5025fcc542cde8bd377efe5ee39fcc99ecee82b8", "max_stars_repo_licenses": ["MIT"], "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/03_model.tex", "max_issues_repo_name": "davidepedranz/lus_project_1", "max_issues_repo_head_hexsha": "5025fcc542cde8bd377efe5ee39fcc99ecee82b8", "max_issues_repo_licenses": ["MIT"], "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/03_model.tex", "max_forks_repo_name": "davidepedranz/lus_project_1", "max_forks_repo_head_hexsha": "5025fcc542cde8bd377efe5ee39fcc99ecee82b8", "max_forks_repo_licenses": ["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.9818181818, "max_line_length": 149, "alphanum_fraction": 0.661934339, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037323284109, "lm_q2_score": 0.817574471748733, "lm_q1q2_score": 0.7573222846372804}}
{"text": "\\section{Arc Length and Curvature}\\label{sec:arc length 3D}\n\nSometimes it is useful to compute the length of a curve in space; for\nexample, if the curve represents the path of a moving object, the\nlength of the curve between two points may be the distance traveled by\nthe object between two times.\n\nRecall that if the curve is given by the vector function $\\bf r$ then\nthe vector $\\Delta {\\bf r}=\n{\\bf r}(t+\\Delta t)-{\\bf r}(t)$ points from one position\non the curve to another, as depicted in Figure~\\ref{fig:vector derivative}.\nIf the points are close together, the length of \n$\\Delta {\\bf r}$ is close to the length of the\ncurve between the two points. If we add up the lengths of many such\ntiny vectors, placed head to tail along a segment of the curve, we get\nan approximation to the length of the curve over that segment. In the\nlimit, as usual, this sum turns into an integral that computes precisely\nthe length of the curve. \nFirst, note that \n$$|\\Delta {\\bf r}|={|\\Delta {\\bf r}|\\over \\Delta t}\\,\\Delta t\\approx\n|{\\bf r}'(t)|\\,\\Delta t,$$\nwhen $\\Delta t$ is small.\nThen the length of the curve between\n${\\bf r}(a)$ and ${\\bf r}(b)$ is \n$$\\lim_{n\\to\\infty} \\sum_{i=0}^{n-1}|\\Delta {\\bf r}|\n=\\lim_{n\\to\\infty} \\sum_{i=0}^{n-1} {|\\Delta {\\bf r}|\\over \\Delta t}\\,\\Delta t\n=\\lim_{n\\to\\infty} \\sum_{i=0}^{n-1} |{\\bf r}'(t)|\\,\\Delta t=\n\\int_a^b|{\\bf r}'(t)|\\,dt.$$\n(Well, sometimes. This works if between $a$ and $b$ the segment of curve\nis traced out exactly once.)\n\n\\begin{example}{}{}\nFind the length of one turn of the helix\n${\\bf r}=\\langle \\cos t, \\sin t, t\\rangle$ (see Figure~\\ref{fig:helixes}).\n\\end{example}\n\\begin{solution}\nWe compute ${\\bf r}'=\\langle -\\sin t, \\cos t, 1\\rangle$ and\n$|{\\bf r}'|=\\sqrt{\\sin^2 t+\\cos^2 t+1}=\\sqrt2$, so the length is\n$$\\int_0^{2\\pi} \\sqrt2\\,dt = 2\\sqrt2\\pi.$$\n\\end{solution}\n\n\\begin{example}{Length of a Curve}{}\nSuppose $y=\\ln x$; what is the length of this curve between\n$x=1$ and $x=\\sqrt3$?\n\\end{example}\n\\begin{solution}\nAlthough this problem does not appear to involve vectors or three\ndimensions, we can interpret it in those terms: let \n${\\bf r}(t)=\\langle t,\\ln t,0\\rangle$. This vector function traces\nout precisely $y=\\ln x$ in the $x$-$y$ plane. Then \n${\\bf r}'(t)=\\langle 1,1/t,0\\rangle$ and\n$\\ds |{\\bf r}'(t)|=\\sqrt{1+1/t^2}$ and the desired length is\n$$\\int_1^{\\sqrt3} \\sqrt{1+{1\\over\n    t^2}}\\,dt=2-\\sqrt2+\\ln(\\sqrt2+1)-{1\\over2}\\ln3.$$\n(This integral is a bit tricky, but requires only methods we have\nlearned.) \n\\end{solution}\n\nNotice that there is nothing special about $y=\\ln x$, except that the\nresulting integral can be computed. In general, given any $y=f(x)$, we\ncan think of this as the vector function\n${\\bf r}(t)=\\langle t,f(t),0\\rangle$. Then \n${\\bf r}'(t)=\\langle 1,f'(t),0\\rangle$ and\n$\\ds |{\\bf r}'(t)|=\\sqrt{1+(f')^2}$. The length of the curve $y=f(x)$\nbetween $a$ and $b$ is thus\n$$\\int_a^b \\sqrt{1+(f'(x))^2}\\,dx.$$\nUnfortunately, such integrals are often impossible to do exactly and\nmust be approximated.\n\nOne useful application of arc length is the \\dfont{arc length parameterization}.\nA vector function ${\\bf r}(t)$ gives the position of a point in terms of the\nparameter $t$, which is often time, but need not be. Suppose $s$ is\nthe distance along the curve from some fixed starting point; if we use\n$s$ for the variable, we get ${\\bf r}(s)$, the position in space in\nterms of distance along the curve. We might still imagine that the\ncurve represents the position of a moving object; now we get the\nposition of the object as a function of how far the object has\ntraveled.\n\n\\begin{example}{}{}\nSuppose ${\\bf r}(t)=\\langle \\cos t,\\sin t,0\\rangle$. We know\nthat this curve is a circle of radius 1. While $t$ might represent\ntime, it can also in this case represent the usual angle between the\npositive $x$-axis and ${\\bf r}(t)$. The distance along the circle from\n$(1,0,0)$ to $(\\cos t,\\sin t,0)$ is also $t$---this is the\ndefinition of radian measure. Thus, in this case $s=t$ and\n${\\bf r}(s)=\\langle \\cos s,\\sin s,0\\rangle$.\n\\end{example}\n\n\\begin{example}{}{}\nSuppose ${\\bf r}(t)=\\langle \\cos t,\\sin t,t\\rangle$. We know\nthat this curve is a helix. The distance along the helix from $(1,0,0)$\nto $(\\cos t,\\sin t,t)$ is \n$$s=\\int_0^t |{\\bf r}'(u)|\\,du=\\int_0^t \\sqrt{\\cos^2u+\\sin^2u+1}\\,du=\n\\int_0^t \\sqrt{2}\\,du=\\sqrt2t.$$\nThus, the value of $t$ that gets us distance $s$ along the helix is\n$t=s/\\sqrt2$, and so the same curve is given by $\\hat{\\bf r}(s)=\n\\langle \\cos(s/\\sqrt2),\\sin(s/\\sqrt2),s/\\sqrt2\\rangle$.\n\\end{example}\n\nIn general, if we have a vector function ${\\bf r}(t)$, to convert it\nto a vector function in terms of arc length we compute\n$$s=\\int_a^t |{\\bf r}'(u)|\\,du=f(t),$$\nsolve $s=f(t)$ for $t$, getting $t=g(s)$, and substitute this back\ninto ${\\bf r}(t)$ to get $\\hat{\\bf r}(s)={\\bf r}(g(s))$.\n\nSuppose that $t$ is time.\nBy the Fundamental Theorem of Calculus, if we start with\narc length\n$$s(t)=\\int_a^t |{\\bf r}'(u)|\\,du$$\nand take the derivative, we get\n$$s'(t)=|{\\bf r}'(t)|.$$\nHere $s'(t)$ is the rate at which the arc length is changing, and\nwe have seen that $|{\\bf r}'(t)|$ is the speed of a moving object;\nthese are of course the same.\n\nSuppose that ${\\bf r}(s)$ is given in terms of arc length; what is\n$|{\\bf r}'(s)|$? It is the rate at which arc length is changing\n\\emph{relative to arc length}; it must be 1! In the case of the helix, for\nexample, the arc length parameterization is $\\langle\n\\cos(s/\\sqrt2),\\sin(s/\\sqrt2),s/\\sqrt2\\rangle$, the derivative is\n$\\langle -\\sin(s/\\sqrt2)/\\sqrt2,\\cos(s/\\sqrt2)/\\sqrt2,1/\\sqrt2\\rangle$,\nand the length of this is\n$$\\sqrt{{\\sin^2(s/\\sqrt2)\\over2}+{\\cos^2(s/\\sqrt2)\\over2}+{1\\over2}}=\n\\sqrt{{1\\over2}+{1\\over2}}=1.$$\nSo in general, ${\\bf r}'$ is a unit tangent vector.\n\nGiven a curve ${\\bf r}(t)$, we would like to be able to measure, at\nvarious points, how sharply curved it is. Clearly this is related to\nhow ``fast'' a tangent vector is changing direction, so a first guess\nmight be that we can measure curvature with $|{\\bf r}''(t)|$. A little\nthought shows that this is flawed; if we think of $t$ as time, for\nexample, we could be tracing out the curve more or less quickly\nas time passes. The second derivative $|{\\bf r}''(t)|$ incorporates\nthis notion of time, so it depends not simply on the geometric\nproperties of the curve but on how quickly we move along the curve.\n\n\\begin{example}{}{}\nConsider ${\\bf r}(t)=\\langle \\cos t,\\sin t,0\\rangle$ and \n${\\bf s}(t)=\\langle \\cos 2t,\\sin 2t,0\\rangle$. Both of these vector\nfunctions represent the unit circle in the $x$-$y$ plane, but if $t$\nis interpreted as time, the second describes an object moving twice as\nfast as the first. Computing the second derivatives, we find\n$|{\\bf r}''(t)|=1$, $|{\\bf s}''(t)|=4$.\n\\end{example}\n\nTo remove the dependence on time, we use the arc length\nparameterization. If a curve is given by ${\\bf r}(s)$, then the first\nderivative ${\\bf r}'(s)$ is a unit vector, that is, \n${\\bf r}'(s)={\\bf T}(s)$. We now compute the second derivative\n${\\bf r}''(s)={\\bf T}'(s)$ and use  $|{\\bf T}'(s)|$ as the\n``official'' measure of \n\\dfont{curvature}, usually denoted $\\kappa$.\n\n\\begin{example}{}{}\nWe have seen that the arc length parameterization of a \nparticular helix is ${\\bf r}(s)=\n\\langle \\cos(s/\\sqrt2),\\sin(s/\\sqrt2),s/\\sqrt2\\rangle$.\nComputing the second derivative gives\n${\\bf r}''(s)=\n\\langle -\\cos(s/\\sqrt2)/2,-\\sin(s/\\sqrt2)/2,0\\rangle$ with length $1/2$.\n\\end{example}\n\nWhat if we are given a curve as a vector function ${\\bf r}(t)$, where\n$t$ is not arc length? We have seen that arc length can be difficult\nto compute; fortunately, we do not need to convert to the arc length\nparameterization to compute curvature. Instead, let us imagine that we have\ndone this, so we have found $t=g(s)$ and then formed\n$\\hat{\\bf r}(s)={\\bf r}(g(s))$. The first derivative $\\hat{\\bf r}'(s)$\nis a unit tangent vector, so it is the same as the unit tangent vector\n${\\bf T}(t)={\\bf T}(g(s))$. Taking the derivative of this we get\n$${d\\over ds}{\\bf T}(g(s))= {\\bf T}'(g(s)) g'(s)={\\bf T}'(t){dt\\over\n  ds}.$$\nThe curvature is the length of this vector:\n$$\\kappa = |{\\bf T}'(t)||{dt\\over ds}|={|{\\bf T}'(t)|\\over|ds/dt|}=\n{|{\\bf T}'(t)|\\over|{\\bf r}'(t)|}.$$\n(Recall that we have seen that $ds/dt=|{\\bf r}'(t)|$.) Thus we can\ncompute the curvature by computing only derivatives with respect to\n$t$; we do not need to do the conversion to arc length.\n\n\\begin{example}{}{}\nReturning to the helix, suppose we start with the parameterization\n${\\bf r}(t)=\\langle \\cos t,\\sin t,t\\rangle$. Then \n${\\bf r}'(t)=\\langle -\\sin t,\\cos t,1\\rangle$, \n$|{\\bf r}'(t)|=\\sqrt2$, and ${\\bf T}(t)=\\langle -\\sin t,\\cos\nt,1\\rangle/\\sqrt2$. Then\n${\\bf T}'(t)=\\langle -\\cos t,-\\sin t,0\\rangle/\\sqrt2$ and \n$|{\\bf T}'(t)|=1/\\sqrt2$. Finally, $\\kappa=1/\\sqrt2/\\sqrt2=1/2$,\nas before.\n\\end{example}\n\n\\begin{example}\nConsider this circle of radius $a$:\n${\\bf r}(t)=\\langle a\\cos t,a\\sin t,1\\rangle$. Then \n${\\bf r}'(t)=\\langle -a\\sin t,a\\cos t,0\\rangle$, \n$|{\\bf r}'(t)|=a$, and ${\\bf T}(t)=\\langle -a\\sin t,a\\cos\nt,0\\rangle/a$. Now\n${\\bf T}'(t)=\\langle -a\\cos t,-a\\sin t,0\\rangle/a$ and \n$|{\\bf T}'(t)|=1$. Finally, $\\kappa=1/a$:\nthe curvature of a circle is everywhere the inverse of the radius. It\nis sometimes useful to think of curvature as describing what circle a\ncurve most resembles at a point. The curvature of the helix in the\nprevious example is $1/2$; this means that a small piece of the helix\nlooks very much like a circle of radius $2$, as shown in\nFigure~\\ref{fig:osculating circle}.\n\\end{example}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm>\n\\setplotarea x from 0 to 1.1, y from 0 to 1.1\n\\put {\\hbox{\\epsfxsize5cm\\epsfbox{images/osculating_circle.eps}}} at 0 0\n\\endpicture}}\n\\caption{A circle with the same curvature as the helix. \\label{fig:osculating circle}}\n\\end{figure}\n\n\\begin{example}{}{}\nConsider ${\\bf r}(t)=\n\\langle \\cos t,\\sin\nt,\\cos 2t\\rangle$, as shown in Figure~\\ref{fig:roller coaster}.\n${\\bf r}'(t)=\n\\langle -\\sin t,\\cos\nt,-2\\sin (2t)\\rangle$ and $|{\\bf r}'(t)|=\n\\sqrt{1+4\\sin^2(2t)}$, so \n$${\\bf T}(t)=\\left\\langle {-\\sin t\\over \\sqrt{1+4\\sin^2(2t)}},\n{\\cos t\\over \\sqrt{1+4\\sin^2(2t)}},\n{-2\\sin 2t\\over \\sqrt{1+4\\sin^2(2t)}}\\right\\rangle.$$\nComputing the derivative of this and then the length of the resulting\nvector is possible but unpleasant.\n\\end{example}\n\nFortunately, there is an alternate formula for the\ncurvature that is often simpler than the one we have:\n$$\\kappa = {|{\\bf r}'(t)\\times{\\bf r}''(t)|\\over|{\\bf r}'(t)|^3}.$$\n\n\\begin{example}{}{}\nReturning to the previous example, we compute the second derivative\n${\\bf r}''(t)=\n\\langle -\\cos t,-\\sin t,-4\\cos(2t)\\rangle$. Then the cross product \n${\\bf r}'(t)\\times{\\bf r}''(t)$ is \n$$\\langle -4\\cos t\\cos 2t-2\\sin t\\sin 2t,\n2\\cos t\\sin 2t-4\\sin t \\cos2t,1\\rangle.$$ Computing the length of this\nvector and dividing by $|{\\bf r}'(t)|^3$ is still a bit tedious.\nWith the aid of a computer we get\n$$\\kappa = {\\sqrt{48\\cos^4 t - 48\\cos^2 t + 17}\\over\n(-16\\cos^4 t +16\\cos^2t+1)^{3/2}}.$$\nGraphing this we get\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <10truemm,10truemm>\n\\setplotarea x from 0 to 6.28, y from 0 to 4.2\n\\axis left ticks length <2pt> withvalues {$2$} {$4$} / at 2 4 / /\n\\axis bottom ticks length <2pt> withvalues {$\\pi\\over2$} {$\\pi$} \n{$3\\pi\\over2$} {$2\\pi$} / at 1.57 3.14 4.71 6.28 / /\n\\plot \n0.000 4.123 0.031 4.022 0.063 3.742 0.094 3.343 0.126 2.894 \n0.157 2.451 0.188 2.048 0.220 1.699 0.251 1.408 0.283 1.169 \n0.314 0.975 0.346 0.819 0.377 0.692 0.408 0.590 0.440 0.507 \n0.471 0.439 0.503 0.384 0.534 0.340 0.565 0.303 0.597 0.273 \n0.628 0.250 0.660 0.231 0.691 0.217 0.723 0.208 0.754 0.202 \n0.785 0.200 0.817 0.202 0.848 0.208 0.880 0.217 0.911 0.231 \n0.942 0.250 0.974 0.273 1.005 0.303 1.037 0.340 1.068 0.384 \n1.100 0.439 1.131 0.507 1.162 0.590 1.194 0.692 1.225 0.819 \n1.257 0.975 1.288 1.169 1.319 1.408 1.351 1.699 1.382 2.048 \n1.414 2.451 1.445 2.894 1.477 3.343 1.508 3.742 1.539 4.022 \n1.571 4.123 1.602 4.022 1.634 3.742 1.665 3.343 1.696 2.894 \n1.728 2.451 1.759 2.048 1.791 1.699 1.822 1.408 1.854 1.169 \n1.885 0.975 1.916 0.819 1.948 0.692 1.979 0.590 2.011 0.507 \n2.042 0.439 2.073 0.384 2.105 0.340 2.136 0.303 2.168 0.273 \n2.199 0.250 2.231 0.231 2.262 0.217 2.293 0.208 2.325 0.202 \n2.356 0.200 2.388 0.202 2.419 0.208 2.450 0.217 2.482 0.231 \n2.513 0.250 2.545 0.273 2.576 0.303 2.608 0.340 2.639 0.384 \n2.670 0.439 2.702 0.507 2.733 0.590 2.765 0.692 2.796 0.819 \n2.827 0.975 2.859 1.169 2.890 1.408 2.922 1.699 2.953 2.048 \n2.985 2.451 3.016 2.894 3.047 3.343 3.079 3.742 3.110 4.022 \n3.142 4.123 3.173 4.022 3.204 3.742 3.236 3.343 3.267 2.894 \n3.299 2.451 3.330 2.048 3.362 1.699 3.393 1.408 3.424 1.169 \n3.456 0.975 3.487 0.819 3.519 0.692 3.550 0.590 3.581 0.507 \n3.613 0.439 3.644 0.384 3.676 0.340 3.707 0.303 3.738 0.273 \n3.770 0.250 3.801 0.231 3.833 0.217 3.864 0.208 3.896 0.202 \n3.927 0.200 3.958 0.202 3.990 0.208 4.021 0.217 4.053 0.231 \n4.084 0.250 4.115 0.273 4.147 0.303 4.178 0.340 4.210 0.384 \n4.241 0.439 4.273 0.507 4.304 0.590 4.335 0.692 4.367 0.819 \n4.398 0.975 4.430 1.169 4.461 1.408 4.492 1.699 4.524 2.048 \n4.555 2.451 4.587 2.894 4.618 3.343 4.650 3.742 4.681 4.022 \n4.712 4.123 4.744 4.022 4.775 3.742 4.807 3.343 4.838 2.894 \n4.869 2.451 4.901 2.048 4.932 1.699 4.964 1.408 4.995 1.169 \n5.027 0.975 5.058 0.819 5.089 0.692 5.121 0.590 5.152 0.507 \n5.184 0.439 5.215 0.384 5.246 0.340 5.278 0.303 5.309 0.273 \n5.341 0.250 5.372 0.231 5.404 0.217 5.435 0.208 5.466 0.202 \n5.498 0.200 5.529 0.202 5.561 0.208 5.592 0.217 5.623 0.231 \n5.655 0.250 5.686 0.273 5.718 0.303 5.749 0.340 5.781 0.384 \n5.812 0.439 5.843 0.507 5.875 0.590 5.906 0.692 5.938 0.819 \n5.969 0.975 6.000 1.169 6.032 1.408 6.063 1.699 6.095 2.048 \n6.126 2.451 6.158 2.894 6.189 3.343 6.220 3.742 6.252 4.022 \n6.283 4.123 /\n\\endpicture}}\n\\end{figure}\n\nCompare this to Figure~\\ref{fig:roller coaster}. The highest\ncurvature occurs where the curve has its highest and lowest points,\nand indeed in the picture these appear to be the most sharply curved\nportions of the curve, while the curve is almost a straight line\nmidway between those points. \n\\end{example}\n\nLet's see why this alternate formula is correct. Starting with the\ndefinition of ${\\bf T}$,\n${\\bf r}'=|{\\bf r}'|{\\bf T}$ so by the product rule\n${\\bf r}''=|{\\bf r}'|'{\\bf T}+|{\\bf r}'|{\\bf T}'$. Then by\nTheorem~\\ref{thm:cross product properties} the cross product is\n\\begin{align*}\n{\\bf r}'\\times{\\bf r}''&=|{\\bf r}'|{\\bf T}\\times|{\\bf r}'|'{\\bf T}+\n|{\\bf r}'|{\\bf T}\\times|{\\bf r}'|{\\bf T}'\t\\\\\n&=|{\\bf r}'||{\\bf r}'|'({\\bf T}\\times{\\bf T})+|{\\bf r}'|^2\n({\\bf T}\\times{\\bf T}')\t\\\\\n&=|{\\bf r}'|^2({\\bf T}\\times{\\bf T}')\n\\end{align*}\nbecause ${\\bf T}\\times{\\bf T}={\\bf 0}$, since ${\\bf T}$ is\nparallel to itself. Then\n\\begin{align*}\n|{\\bf r}'\\times{\\bf r}''|&=|{\\bf r}'|^2|{\\bf T}\\times{\\bf T}'|\t\\\\\n&=|{\\bf r}'|^2|{\\bf T}||{\\bf T}'|\\sin\\theta\t\\\\\n&=|{\\bf r}'|^2|{\\bf T}'|\n\\end{align*}\nusing Exercise~\\ref{ex:derivative is perpendicular} in \nSection~\\ref{sec:calculus with vector functions}\nto see that $\\theta=\\pi/2$. Dividing both sides by \n$|{\\bf r}'|^3$ then gives the desired formula.\n\nWe used the fact here that ${\\bf T}'$ is perpendicular to ${\\bf T}$;\nthe vector ${\\bf N}={\\bf T}'/|{\\bf T}'|$ is thus a unit vector\nperpendicular to ${\\bf T}$, called the \\dfont{unit normal} \nto the curve. Occasionally of use is the \\dfont{unit binormal}\n${\\bf B}={\\bf T}\\times{\\bf N}$, a\nunit vector perpendicular to both ${\\bf T}$ and ${\\bf N}$.\n\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:arc length 3D}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nFind the length of $\\langle 3\\cos t,2t,3\\sin t\\rangle$, \n$t\\in[0,2\\pi]$.\n\\begin{sol}\n\t$2\\pi\\sqrt{13}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the length of $\\langle t^2,2,t^3\\rangle$, $t\\in[0,1]$.\n\\begin{sol}\n\t$(-8+13\\sqrt{13})/27$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the length of $\\langle t^2,\\sin t,\\cos t\\rangle$, $t\\in[0,1]$.\n\\begin{sol}\n\t$\\sqrt5/2+\\ln(\\sqrt5+2)/4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the length of the curve $y=x^{3/2}$, $x\\in[1,9]$.\n\\begin{sol}\n\t$(85\\sqrt{85}-13\\sqrt{13})/27$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nSet up an integral to compute the length of\n$\\langle \\cos t, \\sin t, e^t\\rangle$, $t\\in[0,5]$. (It is tedious but\nnot too difficult to compute this integral.)\n\\begin{sol}\n\t$\\int_0^5 \\sqrt{1+e^{2t}}\\,dt$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the curvature of $\\langle t,t^2,t\\rangle$.\n\\begin{sol}\n\t$2\\sqrt2/(2+4t^2)^{3/2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the curvature of $\\langle t,t^2,t^2\\rangle$.\n\\begin{sol}\n\t$2\\sqrt2/(1+8t^2)^{3/2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the curvature of $\\langle t,t^2,t^3\\rangle$.\n\\begin{sol}\n\t$2\\sqrt{1+9t^2+9t^4}/(1+4t^2+9t^4)^{3/2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nFind the curvature of $y=x^4$ at $(1,1)$.\n\\begin{sol}\n\t$12\\sqrt{17}/289$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "681157413cd9f2d06f67eb3c5498728cc8651ba0", "size": 16971, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13-vector-functions/13-3-arc-length-curvature.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-3-arc-length-curvature.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-3-arc-length-curvature.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.6978417266, "max_line_length": 86, "alphanum_fraction": 0.6587119203, "num_tokens": 6832, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430436757312, "lm_q2_score": 0.9111797130267452, "lm_q1q2_score": 0.7573206800206282}}
{"text": "\\section{Homotopy fibers}\nAn important, but easy, fact about fibrations is that the canonical map $X\\to \\ast$ from any space $X$ is a fibration\n\\footnote{Model category theorists get excited about this, because this says that all objects in the associated model structure on\ntopological spaces is fibrant.}.\nThis is because the dotted lift in the diagram below can be taken to the map $(t,w)\\mapsto f(w)$:\n\\begin{equation*}\n    \\xymatrix{\n    W\\ar[d]\\ar[r]^f & X\\ar[d]\\\\\n    I\\times W\\ar@{-->}[ur]\\ar[r] & \\ast.\n}\n\\end{equation*}\nHowever:\n\\begin{exercise}\n    The inclusion $\\ast\\hookrightarrow X$ is not always a cofibration;\n    if it is, say that $\\ast$ is a \\emph{nondegenerate basepoint} of $X$.\n    Give an example of a compactly generated space $X$ for which this is true.\n\\end{exercise}\nIf $\\ast$ has a neighborhood in $X$ that contracts to $\\ast$,\nthe inclusion $\\ast\\hookrightarrow X$ is a cofibration.\nNote that if $\\ast$ is a nondegenerate basepoint, the canonical map $X^A\\xrightarrow{\\mathrm{ev}} X$ is a fibration,\nwhere $A$ is a pointed subspace of $X$ (with basepoint given by $\\ast$).\nThe fiber of $\\mathrm{ev}$ is exactly the space of pointed maps $A\\to X$.\n\n\\begin{remark}\n    In Example \\ref{intervalcofib}, we saw that $\\{0,1\\}\\hookrightarrow I$ is a cofibration;\n    this implies that the map $Y^I\\to Y\\times Y$ (given by $\\omega\\mapsto (\\omega(0),\\omega(1))$) is a fibration.\n\\end{remark}\n\\subsection{``Fibrant replacements''}\nThe purpose of this subsection is to provide a proof of the following result, which says that every map can be ``replaced''\n(up to homotopy) by a fibration.\n\\begin{theorem}\\label{fibrep}\n    For any map $f:X\\to Y$, there is a space $T(f)$, along with a fibration $p:T(f) \\to Y$ and\n    a homotopy equivalence $X \\xar{\\simeq} T(f)$, such that the following diagram\n    commutes:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    X\\ar[r]^{\\simeq}\\ar[dr]_f & T(f)\\ar[d]^p\\\\\n\t    & Y.\n\t    }\n    \\end{equation*}\n\\end{theorem}\n\\begin{proof}\n    Consider the map $Y^I\\xrightarrow{\\binom{\\ev_0}{\\ev_1}}Y\\times Y$.\n    Let $T(f)$ be the pullback of the following diagram:\n\t\\begin{equation*}\n\t    \\xymatrix{\n\tT(f)\\ar[r]\\ar[d] & Y^I\\ar[d]^{\\binom{\\ev_0}{\\ev_1}}\\\\\n\t\t    X\\times Y\\ar[r]_{f\\times 1} & Y\\times Y.\n\t\t}\n\t\\end{equation*}\n\tSo, as a set, we can write\n\t$$T(f)=\\{(x,\\omega)\\in X\\times Y^I|f(x) = \\omega(0)\\}.$$\n\n\tLet us check that the canonical map $T(f) \\to Y$, given by $(x,\\omega) \\mapsto \\omega(1)$, is a fibration.\n\tThe projection map $\\pr: X\\times Y\\to Y$ is a fibration, so it suffices to show that the map $T(f) \\to X\\times Y$\n\tis also a fibration.\n\tSince fibrations are closed under pullbacks, we are reduced to checking that the map $Y^I\\to Y\\times Y$ is a fibration;\n\tbut this is exactly saying that the inclusion $\\{0,1\\} \\hookrightarrow I$ is a cofibration, which it is\n\t(Example \\ref{intervalcofib}).\n\n\tTo prove that $X$ is homotopy equivalent to $T(f)$, we need to produce a map $X\\to T(f)$.\n\tThis is equivalent to giving maps $X\\to X\\times Y$ and $X\\to Y^I$ that have compatible images in $Y\\times Y$.\n\tThe first map can be chosen to be $X\\xrightarrow{\\binom{1}{f}}X\\times Y$.\n\tDefine the map $X\\to Y^I$ by sending $x\\in X$ to the constant loop at $f(x)$.\n\tIt is clear that both composites $X\\to X\\times Y\\to Y\\times Y$ and $X\\to Y^I\\to Y\\times Y$ are the same;\n\tthis defines a map $X\\to T(f)$, denoted $g$.\n\tAs one can easily check, the composite $X\\to T(f)\\xar{p} Y$ is the map $f:X\\to Y$ that we started off with.\n\tIt remains to check that this map $X\\xar{g} T(f)$ is a homotopy equivalence.\n\tWe will construct a homotopy inverse to this map.\n\n\tThe composite $X\\to T(f)\\to X\\times Y\\to X$ is the identity, so one candidate for a homotopy inverse to $g$ is\n\tthe composite\n\t$$T(f)\\to X\\times Y\\xrightarrow{pr_1} X.$$\n\tTo prove that this map is indeed a homotopy inverse to $g$, we need to consider the composite\n\t$T(f)\\to X\\xar{g} T(f)$, which sends $(x,\\omega)\\mapsto x\\mapsto (x,c_{f(x)})$ where,\n\trecall, $c_{f(x)}$ is the constant path at $x$.\n\tWe need to produce a homotopy between this composite and the identity on $T(f)$.\n\t\n\tLet $s\\in I$. Given $\\omega \\in Y^I$, define a new loop $\\omega_s$ by $\\omega_s(t) = \\omega(st)$.\n\tFor instance, $\\omega_1 = \\omega$, and $\\omega_0 = c_{\\omega(0)}$ --- so, the loop $\\omega_s$ ``sucks in''\n\tthe point $\\omega(1)$.\n\tThis is precisely what we need to produce a homotopy between the composite $T(f) \\to X \\xar{g} T(f)$ and\n\t$\\mathrm{id}_{T(f)}$, since the only constraint on $(x,\\omega)\\in T(f)$ is on $\\omega(0)$.\n\tThe following map provides the desired homotopy equivalence $X \\simeq T(f)$.\n\t\\begin{align*}\n\t    H:I\\times T(f)\\to & T(f)\\\\\n\t    (s,(x,\\omega))\\mapsto & (x,\\omega_s).\n\t\\end{align*}\n%If you want to work through the diagram, this is how it looks.\n%\\begin{equation*}\n%    \\xymatrix{\n%        X\\ar@{-->}[dr]\\ar[drr]^{x\\mapsto c_{f(x)}}\\ar[ddr]_{\\begin{pmatrix}1 \\\\ f\\end{pmatrix}} & & \\\\\n%    \t& T(f)\\ar[d]\\ar[r]\\ar[dr] & Y^I\\ar[d]^{\\begin{pmatrix}ev_0 \\\\ ev_1\\end{pmatrix}}\\\\\n%    \t    X & X\\times Y\\ar[l]^{pr_1}\\ar[d]^{pr_2}\\ar[r] & Y\\times Y\\\\\n%        & Y\n%        }\n%\\end{equation*}\n\\end{proof}\n\n\\begin{example}[Path-loop fibration]\n    This is a silly, but important, example.\n    If $X = \\ast$, the space $T(f)$ consists of paths $\\omega$ in $Y$ such that $\\omega(0) = \\ast$.\n    In other words, $T(f) = Y^I_\\ast$; this is called the \\emph{(based) path space} of $Y$, and is denoted by $P(Y,\\ast)$,\n    or simply by $PY$.\n    The fiber of the fibration $T(f) = PY \\to Y$ consists of paths that begin and end at $\\ast$, i.e., \n    loops on $Y$ based at $\\ast$.\n    This is denoted $\\Omega Y$, and is called the \\emph{(based) loop space} of $Y$.\n    The resulting fibration $PY \\to Y$ is called the \\emph{path-loop fibration}.\n\\end{example}\n\n\\begin{exercise}[``Cofibrant replacements'']\\label{cofibrep}\n    In this exercise, you will prove the analogue of Theorem \\ref{fibrep} for cofibrations.\n    Let $f:X\\to Y$ be any map.\n    Show that $f$ factors (functorially) as a composite $X \\to M \\to Y$, where $X\\to M$ is a cofibration and $M\\to Y$ is a homotopy\n    equivalence.\n\\end{exercise}\n\n\\begin{solution}\n    Define $Mf$ via the pushout:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    X\\ar[r]^f \\ar[d]_{\\mathrm{in}_0} & Y\\ar[d]^g\\\\\n\t    I\\times X\\ar[r] & Mf.\n\t    }\n    \\end{equation*}\n    Define $r:Mf\\to Y$ via $r(y) = y$ on $Y$ and $r(x,s) = f(x)$ on $X\\times I$.\n    Then, clearly, $rg = \\mathrm{id}_Y$.\n    There is a homotopy $\\mathrm{id}_{Mf}\\simeq gr$ given by the map $h:Mf\\times I\\to Mf$,\n    defined by the formulae\n    $$h(y,t) = y,\\text{ and }h((x,s),t) = (x,(1-t)s).$$\n    %Essentially, one's pushing the cylinder $X\\times I$ down.\n    \n    We now have to check that $X\\to Mf$ is a cofibration, i.e., that\n    $Mf\\times I$ retracts onto $Mf\\times\\{0\\}\\cup_X (X\\times I)$.\n    This can be done by ``pushing'' $Y\\times I$ to $Y\\times\\{0\\}$ and $X\\times I\\times I$ down to $X\\times I$,\n    while fixing $X\\times\\{0\\}$.\n    \n    It is easy to see that this factorization is functorial:\n    if $f:X\\to Y$ is sent to $g:W\\to Z$ via $p:X\\to W$ and $q:Y\\to Z$,\n    then $Mf\\to Mg$ can be defined as the dotted map in the following diagram\n    (which exists, by the universal property of the pushout):\n    \\begin{equation*}\n\t\\xymatrix{\n\t    X\\ar[rr]^f\\ar[dd]_{\\mathrm{in}_0}\\ar[dr]|p & & Y\\ar[dd]|\\hole\\ar[dr]|q & \\\\\n\t    & W\\ar[rr]_g\\ar[dd] & & Z\\ar[dd]\\\\\n\t    X\\times I\\ar[rr]\\ar[dr]_{p\\times \\mathrm{id}} & & Mf\\ar@{-->}[dr] & \\\\\n\t    & W\\times I\\ar[rr] & & Mg.\n\t    }\n    \\end{equation*}\n    \\todo{Fix the overlapping arrows here, I don't know how to do this...}\n\\end{solution}\n\n\\subsection{Homotopy fibers}\nOne way to define the fiber (over a basepoint) of a map $f:X \\to Y$ is via the pullback\n\\begin{equation*}\n    \\xymatrix{\n\tf^{-1}(\\ast)\\ar[r]\\ar[d] & X\\ar[d]^f\\\\\n\t\\ast\\ar[r] & Y.\n    }\n\\end{equation*}\nIf $g:W \\to X$ is another map such that the composite $W\\xar{g} X\\xar{f} Y$ is trivial, the map $g$ factors through $f^{-1}(\\ast)$.\nIn homotopy theory, maps are generally not trivial ``on the nose''; instead, we usually have a nullhomotopy of a map.\nNullhomotopies of composite maps do not factor through this ``strict'' fiber; this leads to the notion of a homotopy fiber.\n\\begin{definition}[Homotopy fiber]\n    The \\emph{homotopy fiber} of a map $f:X\\to Y$ is the pullback:\n    \\begin{equation*}\n\t\\xymatrix{\n\t    F(f,\\ast)\\ar[r]\\ar[d] & T(f)\\ar[r]^\\simeq \\ar[d]^p & X\\ar[dl]^f\\\\\n\t    \\ast \\ar[r] & Y &\n\t    }\n    \\end{equation*}\n\\end{definition}\nAs a set, we have\n\\begin{equation}\\label{sethomotopyfiber}\n    F(f,\\ast) = \\{(x,\\omega)\\in X\\times Y^I| f(x) = \\omega(0), \\omega(1) = \\ast\\}.\n\\end{equation}\nA nullhomotopic composite $W\\to X\\xar{f} Y$ factors as $W\\to F(f,\\ast)\\to X\\xar{f} Y$.\n\\begin{warning}\n    The ordinary fiber and the homotopy fiber of a map are generally not the same!\n    There is a canonical map $p^{-1}(\\ast) \\to F(p,\\ast)$, but it is generally not a homotopy equivalence.\n\\end{warning}\n\\begin{prop}\\label{strictcomparison}\n    Suppose $p:X\\to Y$ is a fibration.\n    Then the canonical map $p^{-1}(\\ast)\\to F(p,\\ast)$ is a homotopy equivalence.\n\\end{prop}\nYou will prove this in a series of exercises.\n\n\\begin{exercise}\\label{sectionuptohomotopy}\n    Prove Proposition \\ref{strictcomparison} by working through the following statements.\n    \\begin{enumerate}\n\t\\item Let $p:E\\to B$ be a fibration.\n\t    Suppose $g:X \\to B$ lifts across $p$ up to homotopy, i.e., there exists a map $f:X\\to E$ such that\n\t    $p \\circ f \\simeq g$.\n\t    Prove that there exists a map $f^\\prime:X\\to E$ that is homotopic to $f$, such that $p \\circ f^\\prime = g$\n\t    (on the nose).\n%\t\\item Let $p:E_0 \\to B_0$ be a fibration, and let $f:B \\to B_0$ be a homotopy equivalence.\n%\t    Prove that the induced map $B\\times_{B_0} E_0 \\to E_0$ is a homotopy equivalence.\n%\t    (Warning: this exercise has a lot of technical details! The end of this chapter describes an\n%\t    alternative\\footnote{``Alternative'' in the sense that the proof uses statements\n%\t    not covered yet in this book.}\n%\t    solution to this exercise, when $E_0$ and $B\\times_{B_0} E_0$ are CW-complexes.)\n%\t    \\todo{Don't forget to do this!}\n\t\\item Show that if $p:E\\to B$ and $p^\\prime:E^\\prime \\to B$ are fibrations, and $f:E \\to E^\\prime$ such that\n\t    $p^\\prime \\circ f = p$, the map $f$ is a \\emph{fiber homotopy equivalence}: there is a homotopy inverse\n\t    $g: E^\\prime \\to E$ such that $g$, and the two homotopies $fg \\simeq \\mathrm{id}_{E^\\prime}$ and\n\t    $gf \\simeq \\mathrm{id}_{E}$ are all fiber preserving (e.g., $p\\circ g = p^\\prime$).\n\t\\item Conclude Proposition \\ref{strictcomparison}.\n   \\end{enumerate}\n\\end{exercise}\n\nBefore we proceed, recall that we constructed the homotopy fiber by replacing $f:X\\to Y$ by a fibration.\nIn doing so, we implicitly made a choice: we could have replaced the map $\\ast\\to Y$ by a fibration.\nAre the resulting pullbacks the same?\n\nBy replacing $\\ast \\to Y$ by a fibration (namely, the path-loop fibration), we end up with the following pullback diagram:\n\\begin{equation*}\n    \\xymatrix{\n\tF^\\prime(f,\\ast)\\ar[r]\\ar[d] & P(Y,\\ast)\\ar[r]^{\\simeq}\\ar[d] & \\ast\\ar[dl]\\\\\n\tX\\ar[r]_f & Y & \n    }\n\\end{equation*}\nAs a set, we have\n$$F^\\prime(f,\\ast) = \\{(x,\\omega)\\in X\\times Y^I\\text{ such that }\\omega(0) = \\ast\\text{ and }\\omega(1) = f(x)\\}.$$\nOur description of $F(f,\\ast)$ in \\eqref{sethomotopyfiber} is almost exactly the same --- except that\nthe directions of the paths are reversed.\nThus there's a homeomorphism $F^\\prime(f,\\ast) \\simeq F(f,\\ast)$ given by reversing directions of paths.\n\\begin{remark}\n    One could also replace both $f:X\\to Y$ and $\\ast\\to Y$ by fibrations, and the resulting pullback is also homeomorphic\n    to $F(f,\\ast)$. (Prove this, if the statement is not immediate.)\n\\end{remark}\n\n%Here's what you'll prove for homework.\n%\\begin{theorem}\n%    Suppose you have two fibrations $p$ and $p^\\prime$ such that the following diagram commutes, where $f$ is a homotopy equivalence.\n%    \\begin{equation*}\n%\t\\xymatrix{\n%\t    E\\ar[r]^p\\ar[dr]^p & E^\\prime\\ar[d]^{p^\\prime}\\\\\n%\t    & B\n%\t    }\n%    \\end{equation*}\n%    Then $f$ is a fiber homotopy equivalence. That means that it's a homotopy equivalence in $\\Top_{/B}$. What this means is that there is a map $g:E^\\prime\\to E$ over $B$ compatible with the fibrations and homotopies $I\\times E\\to E$ over $B$ and $I\\times E^\\prime\\to E^\\prime$ over $B$. I.e., the following three diagrams commute:\n%    \\begin{equation*}\n%\t\\xymatrix{\n%\t    E^\\prime\\ar[r]^g\\ar[dr]^{p^\\prime} & E\\ar[d]^p\\\\\n%\t    & B\n%\t    }\n%    \\end{equation*}\n%    and \n%    \\begin{equation*}\n%\t\\xymatrix{\n%\t    I\\times E\\ar[r]^{1\\sim gf}\\ar[dr] & E\\ar[d]^p\\\\\n%\t    & B\n%\t    }\n%    \\end{equation*}\n%    and\n%    \\begin{equation*}\n%\t\\xymatrix{\n%\t    I\\times E^\\prime\\ar[r]^{1\\sim fg}\\ar[dr] & E^\\prime\\ar[d]^{p^\\prime}\\\\\n%\t    & B\n%\t    }\n%    \\end{equation*}\n%\\end{theorem}\n%So we find that for all $b$, $p^{-1}(b)\\xrightarrow{\\simeq} (p^\\prime)^{-1}(b)$. So in particular, the fiber $F(f,\\ast)$, i.e., the homotopy fiber, of $T(f)\\to B$ and the fiber $f^{-1}(\\ast)$ of $f:E\\to B$ are homotopy equivalent if $f$ is a fibration.\n", "meta": {"hexsha": "32b35320905f09e8a07de312b21059573ff27ba6", "size": 13119, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "906/lec-44-homotopy-fibers.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-44-homotopy-fibers.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-44-homotopy-fibers.tex", "max_forks_repo_name": "ichung/algtop-notes", "max_forks_repo_head_hexsha": "3f5d3189e2082716a69fccc1711d02ed848552d2", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-21T18:15:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-13T17:38:04.000Z", "avg_line_length": 49.6931818182, "max_line_length": 333, "alphanum_fraction": 0.6480676881, "num_tokens": 4575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430311279742, "lm_q2_score": 0.9111797130267453, "lm_q1q2_score": 0.7573206685873667}}
{"text": "\\section{Change of Variables}\\label{sec:ChangeofVariables}\n\nOne of the most useful techniques for evaluating integrals is\nsubstitution, both ``$u$-substitu\\-tion'' and trigonometric\nsubstitution, in which we change the variable to something more\nconvenient. As we have seen, sometimes changing from rectangular\ncoordinates to another coordinate system is helpful, and this too\nchanges the variables. This is certainly a more complicated change,\nsince instead of changing one variable for another we change an entire\nsuite of variables, but as it turns out it is really very similar to\nthe kinds of change of variables we already know as substitution.\\index{integration!change of variables}\n\n\\begin{figure}[H]\n\\hbox to \\hsize{\\hfill\n\\begin{tikzpicture}[baseline=0,x=4cm,y=4cm,smooth]\n\\draw (0,0) -- (1.1,0) node [right] {$x$};\n\\draw (0,0) -- (0,0.5) ;\n\\foreach \\x in {0,0.5,1} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\n\\foreach \\y in {0,0.1,0.2,0.3,0.4,0.5} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east] {$\\y$};\n\\draw[fill=red!20,domain=0:1,samples=30] plot (\\x,{\\x*\\x*sqrt(1-\\x*\\x)}) -- (1,0);\n\\draw (0.7,0) rectangle (0.8,0.35); \n\\end{tikzpicture}\\hfill\n\\begin{tikzpicture}[baseline=0,x=4cm,y=4cm,smooth]\n\\draw (0,0) -- (1.7,0) node [right] {$u$};\n\\draw (0,0) -- (0,0.5) ;\n\\foreach \\x in {0,0.5,1,1.5} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\n\\foreach \\y in {0,0.1,0.2,0.3,0.4,0.5} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east] {$\\y$};\n\\draw[fill=red!20,domain=0:pi/2,samples=50] plot (\\x,{sin(deg(\\x))*sin(deg(\\x))*sqrt(1-sin(deg(\\x))*sin(deg(\\x)))});\n\\draw (0.775,0) rectangle (0.927,0.35);\n\\end{tikzpicture}\\hfill}\n\\caption{Single change of variable.}\n\\label{fig:onechangeofvariable}\n\\end{figure}\n\nLet's examine the single variable case again, from a slightly\ndifferent perspective than we have previously used.\nSuppose we start with the problem\n\\[\\int_0^1 x^2\\sqrt{1-x^2}\\,dx;\\]\nthis computes the area in the left graph of \nFigure~\\ref{fig:onechangeofvariable}.\nWe use the substitution $x=\\sin u$ to transform the function from \n$x^2\\sqrt{1-x^2}$ to $\\sin^2u\\sqrt{1-\\sin^2u}$, and we also convert\n$dx$ to $\\cos u\\,du$. Finally, we convert the\nlimits 0 and 1 to 0 and $\\pi/2$.\nThis transforms the integral:\n\\[\\int_0^1 x^2\\sqrt{1-x^2}\\,dx=\\int_0^{\\pi/2}\\sin^2u\\sqrt{1-\\sin^2u} \\cos u\\,du.\\]\nWe want to notice that there are three different conversions: the\nmain function, the differential $dx$, and the interval of\nintegration. The function is converted to\n$\\sin^2u\\sqrt{1-\\sin^2u}$, shown in the right-hand graph of \nFigure~\\ref{fig:onechangeofvariable}. It is evident that the two\ncurves pictured there have the same $y$-values in the same order, but\nthe horizontal scale has been changed. Even though the heights are the\nsame, the two integrals\n\\[\\int_0^1 x^2\\sqrt{1-x^2}\\,dx\\qquad\\hbox{and}\\qquad\n\\int_0^{\\pi/2}\\sin^2u\\sqrt{1-\\sin^2u}\\,du\\]\nare not the same; clearly the right hand area is larger. One way to\nunderstand the problem is to note that if both areas are approximated\nusing, say, ten subintervals, that the approximating rectangles on the\nright are wider than their counterparts on the left, as indicated. In\nthe picture, the width of the rectangle on the left is $\\Delta x=0.1$,\nbetween $0.7$ and $0.8$.  The rectangle on the right is situated\nbetween the corresponding values $\\arcsin(0.7)$ and $\\arcsin(0.8)$ so\nthat $\\Delta u=\\arcsin(0.8)-\\arcsin(0.7)$. To\nmake the widths match, and the areas therefore the same, we can\nmultiply $\\Delta u$ by a correction factor; in this case the\ncorrection factor is approximately $\\cos u=\\cos(\\arcsin(0.7))$, which\nwe compute when we convert $dx$ to $\\cos u\\,du$.\n\nNow let's move to functions of two variables. Suppose we want to\nconvert an integral\n\\[\\int_{x_0}^{x_1}\\int_{y_0}^{y_1} f(x,y)\\,dy\\,dx\\]\nto use new variables $u$ and $v$. In the single variable case, there's\ntypically just one reason to want to change the variable: to make the\nfunction ``nicer'' so that we can find an antiderivative. In the two\nvariable case, there is a second potential reason: the two-dimensional\nregion over which we need to integrate is somehow unpleasant, and we\nwant the region in terms of $u$ and $v$ to be nicer---to be a\nrectangle, for example. Ideally, of course, the new function and the\nnew region will be no worse than the originals, and at least one of\nthem will be better; this doesn't always pan out.\n\nAs before, there are three parts to the conversion: the function\nitself must be rewritten in terms of $u$ and $v$, $dy\\,dx$ must be\nconverted to $du\\,dv$, and the old region must be converted to the new\nregion. We will develop the necessary techniques by considering a\nparticular example, and we will use an example we already know how to\ndo by other means.\n\nConsider \n\\[\\int_{-1}^1\\int_0^{\\sqrt{1-x^2}} \\sqrt{x^2+y^2}\\,dy\\,dx.\\]\nThe limits correspond to integrating over the top half of a circular\ndisk, and we recognize that the function will simplify in polar\ncoordinates, so we would normally convert to polar coordinates:\n\\[\\int_{0}^\\pi\\int_0^1 \\sqrt{r^2}\\;r\\,dr\\,d\\theta={\\pi\\over3}.\\]\nBut let's instead approach this as a substitution problem, starting\nwith $x=r\\cos\\theta$, $y=r\\sin\\theta$. This pair of equations\ndescribes a function from ``$r$-$\\theta$ space'' to ``$x$-$y$ space'',\nand because it involves familiar concepts, it is not too hard to\nunderstand what it does. In Figure~\\ref{fig:twodimensionaltransformation}\nwe have indicated geometrically a bit about how this\nfunction behaves. The four dots labeled \\emph{a}--\\emph{d} in the $r$-$\\theta$ plane\ncorrespond to the three dots in the $x$-$y$ plane; dots \\emph{a} and \n\\emph{b} both go to the origin because $r=0$. The horizontal arrow in the\n$r$-$\\theta$ plane has $r=1$ everywhere and $\\theta$ ranges from 0 to\n$\\pi$, so the corresponding points \n$x=r\\cos\\theta$, $y=r\\sin\\theta$ start at $(1,0)$ and follow the unit\ncircle counter-clockwise. Finally, the vertical arrow has\n$\\theta=\\pi/4$ and $r$ ranges from 0 to 1, so it maps to the straight\narrow in the $x$-$y$ plane. Extrapolating from these few examples,\nit's not hard to see that every vertical line in the $r$-$\\theta$ plane\nis transformed to a line through the origin in the $x$-$y$ plane, and\nevery horizontal line in the $r$-$\\theta$ plane\nis transformed to a circle with center at the origin in the $x$-$y$\nplane. Since we are interested in integrating over the half-disk in\nthe $x$-$y$ plane, we will integrate over the rectangle\n$[0,\\pi]\\times[0,1]$ in the $r$-$\\theta$ plane, because we now see\nthat the points in this rectangle are sent precisely to the upper half\ndisk by $x=r\\cos\\theta$ and $y=r\\sin\\theta$.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 3.2, y from 0 to 1.1\n\\axis left ticks numbered from 0 to 1 by 1 /\n\\axis bottom  ticks withvalues {$\\pi$} / at 3.14 / /\n\\put {$\\theta$} [l] <3pt,0pt> at 3.2 0\n\\put {$r$} [b] <0pt,3pt> at 0 1.1\n\\arrow <5pt> [0.17, 0.5] from 0 1 to 3.14 1\n\\arrow <5pt> [0.17, 0.5] from 0.785 0 to 0.785 1\n\\multiput {$\\bullet$} at 0 0 1.57 0 0 1 1.57 0.5 /\n\\put {$a$} [t] <0pt,-4pt> at 0 0\n\\put {$b$} [t] <0pt,-4pt> at 1.57 0\n\\put {$c$} [tl] <2pt,-2pt> at 0 1\n\\put {$d$} [tr] <-2pt,-2pt> at 1.57 0.5\n\\setcoordinatesystem units <2truecm,2truecm> point at -6 0\n\\setplotarea x from -1.1 to 1.1, y from 0 to 1.1\n\\axis left shiftedto x=0 /\n\\axis bottom  ticks numbered from -1 to 1 by 1 /\n\\put {$x$} [l] <3pt,0pt> at 1.1 0\n\\put {$y$} [b] <0pt,3pt> at 0 1.1\n\\multiput {$\\bullet$} at 0 0 1 0 0 0.5 /\n\\put {$a,b$} [br] <-2pt,2pt> at 0 0\n\\put {$c$} [br] <-2pt,2pt> at 1 0\n\\put {$d$} [br] <-2pt,2pt> at 0 0.5\n\\arrow <5pt> [0.17, 0.5] from 0 0 to 0.707 0.707\n\\circulararc 180 degrees from 1 0 center at 0 0\n\\multiput {\\beginpicture % \n\\setcoordinatesystem units <0.4truein,0.4truein> point at 0 0\n\\startrotation by 0 -1 about 0 0 %\n\\plot -.1 .05 0 0 -.1 -.05 / \\endpicture} at -1 0 /\n\\endpicture}}\n\\caption{Double change of variable.}\n\\label{fig:twodimensionaltransformation}\n\\end{figure}\n\nAt this point we are two-thirds done with the task: we know the\n$r$-$\\theta$ limits of integration, and we can easily convert the\nfunction to the new variables:\n\\begin{equation}\\label{eq:transformedfunction}\n\\sqrt{x^2+y^2}=\\sqrt{r^2\\cos^2\\theta+r^2\\sin^2\\theta}=r\\sqrt{\\cos^2\\theta+\\sin^2\\theta} = r.\n\\end{equation}\nThe final, and most difficult, task is to figure out what replaces\n$dx\\,dy$. (Of course, we actually know the answer, because we are in\neffect converting to polar coordinates. What we really want is a\nseries of steps that gets to that right answer but that will also work\nfor other substitutions that are not so familiar.)\n\nLet's take a step back and remember how integration arises from\napproximation. When we approximate the integral in the $x$-$y$ plane,\nwe are computing the volumes of tall thin boxes, in this case boxes\nthat are $\\Delta x\\times \\Delta y\\times \\sqrt{x^2+y^2}$. We are aiming\nto come up with an integral in the $r$-$\\theta$ plane that looks like\nthis:\n\\begin{equation}\\label{eq:targetintegral}\n\\int_0^\\pi\\int_0^1 r (?) \\,dr\\,d\\theta.\n\\end{equation}\nWhat we're missing is exactly the right quantity to replace the ``?''\nso that we get the correct answer. Of course, this integral is also\nthe result of an approximation, in which we add up volumes of boxes\nthat are $\\Delta r\\times\\Delta \\theta\\times\\hbox{height}$; the problem\nis that the height that will give us the correct answer is not simply\n$r$. Or put another way, we can think of the correct height as $r$,\nbut the area of the base $\\Delta r\\Delta\\theta$ as being wrong. The\nheight $r$ comes from Equation~\\ref{eq:transformedfunction}, which\nis to say, it is precisely the same as the corresponding height in the\n$x$-$y$ version of the integral. The problem is that the area of the\nbase $\\Delta x\\times \\Delta y$ is not the same as the area of the base\n$\\Delta r\\times\\Delta\\theta$. We can think of the ``?'' in the integral as a\ncorrection factor that is needed so that\n$?\\,dr\\,d\\theta$ = $dx\\,dy$.\n\nSo let's think about what that little base $\\Delta\nr\\times\\Delta\\theta$ corresponds to. We know that each bit of\nhorizontal line in the $r$-$\\theta$ plane corresponds to a bit of\ncircular arc in the $x$-$y$ plane, and each bit of vertical line\nin the $r$-$\\theta$ plane corresponds to a bit of\n``radial line'' in the $x$-$y$ plane. In\nFigure~\\ref{fig:correspondingareas} we show a typical rectangle in\nthe $r$-$\\theta$ plane and its corresponding area in the $x$-$y$ plane.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <2truecm,2truecm>\n\\setplotarea x from 0 to 3.2, y from 0 to 1.1\n\\axis left ticks numbered from 0 to 1 by 1 /\n\\axis bottom  ticks withvalues {$\\pi$} / at 3.14 / /\n\\put {$\\theta$} [l] <3pt,0pt> at 3.2 0\n\\put {$r$} [b] <0pt,3pt> at 0 1.1\n\\put {$\\Delta r$} [r] <-3pt,0pt> at 2.094 0.625\n\\put {$\\Delta\\theta$} [t] <0pt,-3pt> at 2.356 0.5\n\\plot 2.094 0.5 2.094 0.75 2.618 0.75 2.618 0.5 2.094 0.5 /\n\\setcoordinatesystem units <2truecm,2truecm> point at -6 0\n\\setplotarea x from -1.1 to 1.1, y from 0 to 1.1\n\\axis left shiftedto x=0 /\n\\axis bottom  ticks numbered from -1 to 1 by 1 /\n\\put {$x$} [l] <3pt,0pt> at 1.1 0\n\\put {$y$} [b] <0pt,3pt> at 0 1.1\n%\\put {$\\Delta r$} [tr] <-2pt,-2pt> at -0.54 0.31\n%\\put {$r\\Delta\\theta$} [br] <-2pt,2pt> at -0.53 0.53\n\\circulararc 30 degrees from -0.25 0.433 center at 0 0\n\\circulararc 30 degrees from -0.375 0.65 center at 0 0\n\\plot -0.25 0.433 -0.375 0.65 /\n\\plot -0.433 0.25 -0.65 0.375 /\n\\endpicture}}\n\\caption{Corresponding areas.}\n\\label{fig:correspondingareas}\n\\end{figure}\n\nIn this case, the region in the $x$-$y$ plane is approximately a\nrectangle with dimensions $\\Delta r\\times r\\Delta\\theta$, but in\ngeneral the corner angles will not be right angles, so the region will\ntypically be (almost) a parallelogram. We need to compute the area of\nthis parallelogram. We know\na neat way to do this: compute the length of a certain cross product.\nIf we can determine an appropriate two vectors we'll be nearly done.\n\nFortunately, we've really done this before. The sides of the region in\nthe $x$-$y$ plane are formed by temporarily fixing either $r$ or\n$\\theta$ and letting the other variable range over a small interval.\nIn Figure~\\ref{fig:correspondingareas}, for example, the upper right\nedge of the region is formed by fixing $\\theta=2\\pi/3$ and letting $r$\nrun from $0.5$ to $0.75$. In other words, we have a vector function\n$\\vect{v}(r)=\\langle r\\cos\\theta_0, r\\sin\\theta_0, 0\\rangle$, and we\nare interested in a restricted set of values for $r$. A vector tangent\nto this path is given by the derivative $\\vect{v}'(r)=\\langle\n\\cos\\theta_0, \\sin\\theta_0, 0\\rangle$, and a small tangent vector,\nwith length approximately equal to the side of the region, is $\\langle\n\\cos\\theta_0, \\sin\\theta_0, 0\\rangle\\,dr$. Likewise, if we fix\n$r=r_0=0.5$, we get the vector function $\\vect{w}(\\theta)=\\langle\nr_0\\cos\\theta, r_0\\sin\\theta, 0\\rangle$ with derivative $\\vect{w}(\\theta)=\\langle -r_0\\sin\\theta, r_0\\cos\\theta, 0\\rangle$ and a\nsmall tangent vector $\\langle -r_0\\sin\\theta_0, r_0\\cos\\theta_0,\n0\\rangle\\,d\\theta$ when $\\theta=\\theta_0$ (at the corner we're\nfocusing on). These vectors are shown in \nFigure~\\ref{fig:smallapproximatingparallelogram}, with the actual\nregion outlined by a dotted boundary. Of course, since both $\\Delta r$\nand $\\Delta\\theta$ are quite large, the parallelogram is not a\nparticularly good approximation to the true area.\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <3truecm,3truecm> \n\\setplotarea x from -1.1 to 1.1, y from 0 to 1.1\n\\axis left shiftedto x=0 /\n\\axis bottom  ticks numbered from -1 to 1 by 1 /\n\\put {$x$} [l] <3pt,0pt> at 1.1 0\n\\put {$y$} [b] <0pt,3pt> at 0 1.1\n%\\put {$\\Delta r$} [tr] <-2pt,-2pt> at -0.54 0.31\n%\\put {$r\\Delta\\theta$} [br] <-2pt,2pt> at -0.53 0.53\n\\arrow <5pt> [0.17, 0.5] from  -0.25 0.433  to  -0.375 0.65\n\\arrow <5pt> [0.17, 0.5] from -0.25 0.433 to -0.477  0.302\n\\setdashes\n\\plot -0.477  0.302 -0.602 0.519 -0.375 0.65 /\n\\findlength{\\circulararc 30 degrees from -0.25 0.433 center at 0 0 }\n\\setdotsnear <2pt> for <\\totalarclength>\n\\circulararc 30 degrees from -0.25 0.433 center at 0 0\n\\findlength{\\circulararc 30 degrees from -0.375 0.65 center at 0 0 }\n\\setdotsnear <2pt> for <\\totalarclength>\n\\circulararc 30 degrees from -0.375 0.65 center at 0 0\n\\setlinear\n\\plot -0.433 0.25 -0.65 0.375 /\n\\endpicture}}\n\\caption{The approximating parallelogram.}\n\\label{fig:smallapproximatingparallelogram}\n\\end{figure}\n\nThe area of this parallelogram is the length of the cross product:\n\\begin{align*}\n\\langle -r_0\\sin\\theta_0, r_0\\cos\\theta_0, 0\\rangle\\,d\\theta\\times\\langle\\cos\\theta_0, \\sin\\theta_0, 0\\rangle\\,dr\n&= \\left|\\begin{matrix}\t\\vect{i}\t\t\t&\t\\vect{j}\t\t&\t\\vect{k}\t\\\\\n\t\t\t\t\t\t-r_0\\sin\\theta_0\t&\tr_0\\cos\\theta_0\t&\t0\t\t\t\\\\\n\t\t\t\t\t\t\\cos\\theta_0\t\t&\t\\sin\\theta_0\t&\t0\n\t\t \\end{matrix}\\right|\\,d\\theta\\,dr\t\\\\\n&=\\langle 0,0,-r_0\\sin^2\\theta_0-r_0\\cos^2\\theta_0\\rangle\\,d\\theta\\,dr\t\\\\\n&=\\langle 0,0,-r_0\\rangle\\,d\\theta\\,dr.\n\\end{align*}\nThe length of this vector is $r_0\\,dr\\,d\\theta$. So in general, for\nany values of $r$ and $\\theta$, the area in the $x$-$y$ plane\ncorresponding to a small rectangle anchored at $(\\theta,r)$ in the\n$r$-$\\theta$ plane is approximately $r\\,dr\\,d\\theta$. In other words, ``$r$''\nreplaces the ``?'' in Equation~\\ref{eq:targetintegral}.\n\nIn general, a substitution will start with equations $x=f(u,v)$ and\n$y=g(u,v)$. Again, it will be straightforward to convert the function\nbeing integrated. Converting the limits will require, as above, an\nunderstanding of just how the functions $f$ and $g$ transform the\n$u$-$v$ plane into the $x$-$y$ plane. Finally, the small vectors we\nneed to approximate an area will be\n$\\langle f_u,g_u,0\\rangle\\,du$ and $\\langle f_v,g_v,0\\rangle\\,dv$.\nThe cross product of these is $\\langle\n0,0,f_ug_v-g_uf_v\\rangle\\,du\\,dv$ with length \n$|f_ug_v-g_uf_v|\\,du\\,dv$. The quantity $|f_ug_v-g_uf_v|$ is usually\ndenoted\n$$\\left|{\\partial(x,y)\\over\\partial(u,v)}\\right|=|f_ug_v-g_uf_v|$$\nand called the \\dfont{Jacobian}\\index{Jacobian}.\nNote that this is the absolute value of the two by two determinant\n\\[\\left|\\begin{matrix}\tf_u\t&\tg_u\t\\\\\n\t\t\t\t\t\tf_v\t&\tg_v\n\t\t\\end{matrix}\\right|,\\]\nwhich may be easier to remember. (Confusingly, the matrix, the\ndeterminant of the matrix, and the absolute value of the determinant\nare all called the Jacobian by various authors.)\n\nBecause there are two things to worry about, namely, the form of the\nfunction and the region of integration, transformations in two (or\nmore) variables are quite tricky to discover.\n\n\\begin{example}{Integral of an Ellipse}{changeofvariables}\nIntegrate $x^2-xy+y^2$ over the region $x^2-xy+y^2\\le 2$.\n\\end{example}\n\\begin{solution}\nThe equation $x^2-xy+y^2= 2$ describes an ellipse as in\nFigure~\\ref{fig:skewedellipse}; the region of integration is the\ninterior of the ellipse. We will use the transformation \n$x=\\sqrt2 u-\\sqrt{2/3}v$, $y=\\sqrt2 u+\\sqrt{2/3}v$.\nSubstituting into the function itself we get\n\\[x^2-xy+y^2=2u^2+2v^2.\\]\nThe boundary of the ellipse is $x^2-xy+y^2=2$, so the boundary of\nthe corresponding region in the $u$-$v$ plane is $2u^2+2v^2=2$\nor $u^2+v^2=1$, the unit circle, so this substitution makes the region\nof integration simpler. \n\nNext, we compute the Jacobian, using $f=\\sqrt2 u-\\sqrt{2/3}v$ and \n$g=\\sqrt2 u+\\sqrt{2/3}v$:\n\\[f_ug_v-g_uf_v=\\sqrt2\\sqrt{2/3}+\\sqrt2\\sqrt{2/3}={4\\over\\sqrt3}.\\]\nHence the new integral is \n\\[\\iint_R (2u^2+2v^2){4\\over\\sqrt3}\\,du\\,dv,\\]\nwhere $R$ is the interior of the unit circle.\nThis is still not an easy integral, but it is easily transformed to\npolar coordinates, and then easily integrated.\n\\end{solution}\n\n\\begin{figure}[H]\n\\centerline{\n\\vbox{\\beginpicture\n\\normalgraphs\n\\setcoordinatesystem units <1.2truecm,1.2truecm> \n\\setplotarea x from -2 to 2, y from -2 to 2\n\\axis left shiftedto x=0 /\n\\axis bottom shiftedto y=0  /\n\\put {$x$} [l] <3pt,0pt> at 2 0\n\\put {$y$} [b] <0pt,3pt> at 0 2\n\\plot -1.630 -0.729 -1.548 -0.325 -1.467 -0.112 -1.386 0.056 -1.304 0.199 \n-1.222 0.326 -1.141 0.441 -1.060 0.546 -0.978 0.644 -0.896 0.734 \n-0.815 0.818 -0.734 0.897 -0.652 0.971 -0.570 1.040 -0.489 1.105 \n-0.408 1.166 -0.326 1.223 -0.244 1.276 -0.163 1.326 -0.082 1.372 \n0.000 1.414 0.082 1.453 0.163 1.489 0.244 1.521 0.326 1.549 \n0.408 1.573 0.489 1.594 0.570 1.610 0.652 1.623 0.734 1.630 \n0.815 1.633 0.896 1.630 0.978 1.622 1.060 1.606 1.141 1.582 \n1.222 1.549 1.304 1.503 1.386 1.441 1.467 1.355 1.548 1.223 \n1.630 0.901 /\n\\plot -1.630 -0.901 -1.548 -1.223 -1.467 -1.355 -1.386 -1.441 -1.304 -1.503 \n-1.222 -1.549 -1.141 -1.582 -1.060 -1.606 -0.978 -1.622 -0.896 -1.630 \n-0.815 -1.633 -0.734 -1.630 -0.652 -1.623 -0.570 -1.610 -0.489 -1.594 \n-0.408 -1.573 -0.326 -1.549 -0.244 -1.521 -0.163 -1.489 -0.082 -1.453 \n0.000 -1.414 0.082 -1.372 0.163 -1.326 0.244 -1.276 0.326 -1.223 \n0.408 -1.166 0.489 -1.105 0.570 -1.040 0.652 -0.971 0.734 -0.897 \n0.815 -0.818 0.896 -0.734 0.978 -0.644 1.060 -0.546 1.141 -0.441 \n1.222 -0.326 1.304 -0.199 1.386 -0.056 1.467 0.112 1.548 0.325 \n1.630 0.729 /\n\\plot 1.63 0.729 1.633 0.8164965809 1.63 0.901 /\n\\plot -1.63 -0.729 -1.633 -0.8164965809 -1.63 -0.901 /\n\\endpicture}}\n\\caption{$x^2-xy+y^2=2$}\n\\label{fig:skewedellipse}\n\\end{figure}\n\nThere is a similar change of variables formula for triple integrals,\nthough it is a bit more difficult to derive.\nSuppose we use three substitution functions, $x=f(u,v,w)$,\n$y=g(u,v,w)$, and $z=h(u,v,w)$.  The Jacobian determinant is now\n\\[\n  {\\partial(x,y,z)\\over\\partial(u,v,w)} =  \n  \\left|\\begin{matrix}\tf_u\t&\tg_u\t&\th_u\t\\\\\n  \t\t\t\t\t\tf_v\t&\tg_v\t&\th_v\t\\\\\n  \t\t\t\t\t\tf_w\t&\tg_w\t&\th_w\n  \t\t\\end{matrix}\\right|.\n\\]\nThen the integral is transformed in a similar fashion:\n\\[\n  \\iiint_R F(x,y,z) \\, dV = \n  \\iiint_S F(f(u,v,w),g(u,v,w),h(u,v,w)) \n  \\left|{\\partial(x,y,z)\\over\\partial(u,v,w)}\\right| \\,du\\,dv\\,dw,\n\\]\nwhere of course the region $S$ in $uvw$ space corresponds to the\nregion $R$ in $xyz$ space.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for \\ref{sec:ChangeofVariables}}\n\n\\begin{enumialphparenastyle}\n\n\\begin{ex}\nComplete Example~\\ref{exa:changeofvariables} by\nconverting to polar coordinates and evaluating the integral.\n\\begin{sol}\n$\\ds 4\\pi\\sqrt3/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint xy\\,dx\\,dy$ over the square\nwith corners $(0,0)$, $(1,1)$, $(2,0)$, and $(1,-1)$ in two ways:\ndirectly, and using $x=(u+v)/2$, $y=(u-v)/2$.\n\\begin{sol}\n$0$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint x^2+y^2\\,dx\\,dy$ over the square\nwith corners $(-1,0)$, $(0,1)$, $(1,0)$, and $(0,-1)$ in two ways:\ndirectly, and using $x=(u+v)/2$, $y=(u-v)/2$.\n\\begin{sol}\n$2/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint (x+y)e^{x-y}\\,dx\\,dy$ over the triangle\nwith corners $(0,0)$, $(-1,1)$, and $(1,1)$ in two ways:\ndirectly, and using $x=(u+v)/2$, $y=(u-v)/2$.\n\\begin{sol}\n$\\ds {e^2-1\\over 2e^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint y(x-y)\\,dx\\,dy$ over the parallelogram\nwith corners $(0,0)$, $(3,3)$, $(7,3)$, and $(4,0)$ in two ways:\ndirectly, and using $x=u+v$, $y=u$.\n\\begin{sol}\n$36$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint \\sqrt{x^2+y^2}\\,dx\\,dy$ over the\ntriangle with corners $(0,0)$, $(4,4)$, and $(4,0)$ using $x=u$, $y=uv$.\n\\begin{sol}\n$32(\\sqrt2+\\ln(1+\\sqrt2))/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint y\\sin(xy)\\,dx\\,dy$ over the\nregion bounded by $xy=1$, $xy=4$, $y=1$, and $y=4$ using\n$x=u/v$, $y=v$.\n\\begin{sol}\n$3\\cos(1)-3\\cos(4)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iint \\sin(9x^2 + 4y^2)\\,dA,$ over the region\n in the first quadrant bounded by the ellipse $9x^2+4y^2 = 1$.\n\\begin{sol}\n$\\pi(1-\\cos(1))/24$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nCompute the Jacobian for the substitutions \n$x=\\rho\\sin\\phi\\cos\\theta$, $y=\\rho\\sin\\phi\\sin\\theta$, \n$z=\\rho\\cos\\phi$.\n\\end{ex}\n\n\\begin{ex}\nEvaluate $\\ds\\iiint_E\\,dV$ where $E$ is the solid\nenclosed by the ellipsoid\n$${x^2\\over a^2} + {y^2\\over b^2} + {z^2\\over c^2} = 1,$$ \nusing the transformation $x=au$, $y=bv$, and $z=cw$.\n\\begin{sol}\n$(4/3)\\pi abc$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}\n", "meta": {"hexsha": "665862c3b55e60855ab88ab57607a05e05d579d7", "size": 22130, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "15-multiple-integration/15-7-change-variable.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-7-change-variable.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-7-change-variable.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.6489151874, "max_line_length": 128, "alphanum_fraction": 0.6914595572, "num_tokens": 8323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8104788995148791, "lm_q2_score": 0.9343951680216529, "lm_q1q2_score": 0.7573075674902098}}
{"text": "\\section*{Ex.3.2}\n\\subsection*{what is the upper bound}\n\nAs $h$ is strongly $c$-universal the keys hash independently, hence\n\n\\begin{align*}\nP(h(x)=q \\land h(y)=r) &= P(h(x)=q \\cap h(y)=r) = P(h(x)=q) P(h(y)=r) \\\\\n                       &\\leq \\frac{c}{m} \\frac{c}{m} = \\left(\\frac{c}{m}\\right)^2\n\\end{align*}\n\nSo the upper bound is $c^2/m^2$", "meta": {"hexsha": "e6aaf2544a0a3d57b5afad072d154f3ad4bfc3df", "size": 341, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Uge3/Ex.3.2.tex", "max_stars_repo_name": "pdebesc/AADS", "max_stars_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Uge3/Ex.3.2.tex", "max_issues_repo_name": "pdebesc/AADS", "max_issues_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Uge3/Ex.3.2.tex", "max_forks_repo_name": "pdebesc/AADS", "max_forks_repo_head_hexsha": "a26e24d18adee973d3ce88bdfd96d857ec472fdf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 31.0, "max_line_length": 81, "alphanum_fraction": 0.5601173021, "num_tokens": 135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9458012732322216, "lm_q2_score": 0.8006919925839876, "lm_q1q2_score": 0.7572955060527801}}
{"text": "\n\\subsection{Bellman equations}\n\nWe breakdown the value function into an immediate reward, and the discounted value function of the next state.\n\nThis is because the expectation function is linear.\n\n\\(v_\\pi (s)=R_{s,\\pi(s)}+\\gamma \\sum_{s'}P_{s,\\pi(s)}(s')v_\\pi (s')\\)\n\nWe can write this in matrix form.\n\n\\(v_pi (s)= r_\\pi + \\gamma P_\\pi v_\\pi(s)\\)\n\nWe can then solve this:\n\n\\(v_pi (s)= (I-\\gamma P_\\pi)^{-1})r_\\pi\\)\n\nThis depends on the starting state.\n\n", "meta": {"hexsha": "b398224d2c8337389e93177093849878e5a32e2b", "size": 454, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/computer/dynamic/01-04-bellman.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/dynamic/01-04-bellman.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/dynamic/01-04-bellman.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.7, "max_line_length": 110, "alphanum_fraction": 0.6806167401, "num_tokens": 140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133565584851, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7572244527037777}}
{"text": "\\section{Optimization Methods}\n\nIn order to explain the \\emph{convergence} and \\emph{efficiency} properties of the following optimization methods, we need to introduce some preliminary definitions about \\emph{convexity} and the \\emph{L-smoothness} of a function~\\cite{boyd2004convex}.\n\n\\begin{definition}[Convexity] \\label{def:convexity}\n\t\\hfill\n\t\\begin{enumerate}[i]\n\t\t\\item We say that a function $f: \\Re^m \\rightarrow \\Re$ is convex if: \n\t\t$$ \n\t\t\t(\\lambda x + (1 - \\lambda) y ) \\leq \\lambda f(x) + (1 - \\lambda) f(y) \\ \\forall \\ x, y \\in \\Re^m, \\lambda \\in [0,1] \n\t\t$$\n\t\t\\item We say that a differentiable function $f: \\Re^m \\rightarrow \\Re$, i.e., $f \\in C^1$, is convex if: \n\t\t$$ \n\t\t\tf(x) \\geq f(y) + \\langle \\nabla f(y), x - y \\rangle \\ \\forall \\ x, y \\in \\Re^m \n\t\t$$\n\t\t\\item We say that a twice differentiable function $f: \\Re^m \\rightarrow \\Re$, i.e., $f \\in C^2$ and the Hessian matrix is \\emph{symmetric}, is convex iff: \n\t\t$$ \n\t\t\t\\nabla^2 f(x) \\succeq 0 \\ \\forall \\ x \\in \\Re^m \n\t\t$$ i.e., the Hessian matix is \\emph{positive semidefinite}.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Strong Convexity] \\label{def:strong_convexity}\nWe say that a function $f: \\Re^m \\rightarrow \\Re$ is $\\mu$-strongly convex if the function:\n$$\ng(x) = f(x) - \\frac{\\mu}{2} \\| x \\|^2\n$$\nis convex for any $\\mu > 0$. \nIf $f$ is differentiable, i.e., $f \\in C^1$, this is also equivalent to:\n$$\nf(y) \\geq f(x) + \\langle \\nabla f(x), y - x \\rangle + \\frac{\\mu}{2} \\| y - x \\|^2 \\ \\forall \\ x, y \\in \\Re^m\n$$\nand, if $f$ is a twice differentiable function, i.e., $f \\in C^2$ and the Hessian matrix is \\emph{symmetric}, then $f$ is $\\mu$-strongly convex iff:\n$$\n\\nabla^2 g(x) \\succ 0 \\ \\forall \\ x \\in \\Re^m\n$$\ni.e., the Hessian matix is \\emph{positive definite}, which is:\n$$\n\\nabla^2 f(x) \\succeq \\mu \\ \\forall \\ x \\in \\Re^m\n$$\n\\end{definition}\n\n\\begin{definition}[L-smoothness] \\label{def:l_smoothness}\nWe say that a function $f: \\Re^m \\rightarrow \\Re$ is L-smooth, i.e., L-Lipschitz continuous, if it is differentiable and if:\n$$\n\\| \\nabla f(x) - \\nabla f(y) \\| \\leq L \\| x - y \\| \\ \\forall \\ x, y \\in \\Re^m\n$$\n\\end{definition}\n\n\\pagebreak\n\n\\subsection{Gradient Descent}\n\nThe Gradient Descent algorithm is the simplest \\emph{first-order optimization} method that exploits the orthogonality of the gradient wrt the level sets to take a descent direction. In particular, it performs the following iterations:\n\n\\begin{algorithm}[H]\n\t\\caption{Gradient Descent}\n\t\\label{alg:gd}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Function{GradientDescent}{$f,\\alpha$}\n\t\t\t\\State Initialize weight vector $x_0$\n\t\t\t\\State $t = 0$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $x_{t+1} = x_t - \\alpha \\nabla f(x_t)$\n\t\t\t\t\\State $t = t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{theorem}[Gradient Descent convergence for convex functions] \\label{thm:cvx_gd_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-smooth convex function. Let $x_*$ be the minimum of $f$ on $\\Re^m$. Then the Gradient Descent with step size $\\alpha \\leq 1/L$ satisfies:\n$$\nf(x_t) - f(x_*) \\leq \\frac{\\| x_0 - x_* \\|^2}{2 \\alpha t}\n$$\nIn particular, for $\\alpha = 1/L$:\n$$\nf(x_t) - f(x_*) \\leq \\frac{L \\| x_0 - x_* \\|^2}{2 t}\n$$\n\\end{theorem}\n\n\\begin{theorem}[Gradient Descent convergence for strongly convex functions] \\label{thm:str_cvx_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-smooth, $\\mu$ strongly convex function. Let $x_*$ be the minimum of $f$ on $\\Re^m$. Then the Gradient Descent with step size $\\alpha \\leq 1/L$ satisfies:\n$$\nf(x_t) - f(x_*) \\leq (1 - \\alpha \\mu)^t \\| x_0 - x_* \\|^2\n$$\nIn particular, for $\\alpha = 1/L$:\n$$\n\\begin{aligned}\n\tf(x_t) - f(x_*) \\leq & \\bigg(1 - \\frac{\\mu}{L}\\bigg)^t \\| x_0 - x_* \\|^2 \\\\ \n\t\t\t\t\t\t= & \\bigg(1 - \\frac{1}{\\kappa}\\bigg)^t \\| x_0 - x_* \\|^2\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\nGradient Descent is based on full gradients, since at each iteration we compute the average gradient on the whole dataset:\n$$\n\\nabla f(x) = \\frac{1}{n} \\sum_{i=1}^n \\nabla f_i(x)\n$$\nThe downside is that every step is very computationally expensive, $\\mathcal{O}(nm)$ per iteration, where $n$ is the number of samples in our dataset and $m$ is the number of dimensions.\n\nSince \\emph{Gradient Descent} becomes impractical when dealing with large datasets we introduce a stochastic version, called \\emph{Stochastic Gradient Descent}, which does not use the whole set of examples to compute the gradient at every step. By doing so, we can reduce computation all the way down to $\\mathcal{O}(m)$ per iteration, instead of $\\mathcal{O}(nm)$.\n\n\\begin{algorithm}[H]\n\t\\caption{Stochastic Gradient Descent}\n\t\\label{alg:sgd}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Batch size $k$}\n\t\t\\Function{StochasticGradientDescent}{$f,\\alpha,k$}\n\t\t\t\\State Initialize weight vector $x_0$\n\t\t\t\\State $t \\gets 0$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State Sample $(i_1,\\dots,i_k) \\sim \\mathcal{U}^k(1,\\dots,n)$ \n\t\t\t\t\\State $\\displaystyle x_{t+1} \\gets x_t - \\alpha \\frac{1}{k} \\sum_{j=1}^k \\nabla f_{i_j}(x_t)$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nNote that in expectation, we converge like GD, since $\\displaystyle \\mathbb{E}_{i \\sim \\mathcal{U}(1,\\dots,n)}[\\nabla f_i(x_t)] = \\nabla f(x_t)$, therefore, the expected iterate of SGD converges to the optimum.\n\nSGD’s convergence rate for L-smooth convex functions is $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{\\sqrt{t}}\\Big)$ and $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{t}\\Big)$ for strongly convex. More iterations are needed to reach the same accuracy as GD, but the iterations are far cheaper.\n\n\\subsubsection{Momentum} \n\nTo mitigate the pathological zig-zagging of the SGD method we introduce two accelerated methods~\\cite{polyak1964some} and~\\cite{nesterov1998introductory} that exploits information from the history, i.e., past iterates, to add some inertia, i.e., the momentum, to yield smoother trajectory.\n\nIn the Polyak's method~\\cite{polyak1964some} the velocity vector $v_t$ is calculated by applying the $\\beta$ momentum to the previous $v_{t-1}$ displacement, and subtracting the gradient step to $x_t$.\n\n\\begin{figure}[h!]\n\t\\centering\n  \t\\includegraphics[scale=0.5]{img/momentum}\n  \t\\caption{Polyak's and Nesterov's Momentum}\n  \t\\label{fig:momentum}\n\\end{figure}\n\n\\begin{algorithm}[H]\n\t\\caption{Polyak Accelerated Gradient Descent or or Heavy-Ball method}\n\t\\label{alg:hbg}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Momentum $\\beta \\in [0,1)$}\n\t\t\\Function{PolyakAcceleratedGradientDescent}{$f,\\alpha,\\beta$}\n\t\t\t\\State Initialize weight vector $x_1 \\gets x_0$ and velocity vector $v_0 \\gets 0$\n\t\t\t\\State $t \\gets 1$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $v_t = \\beta v_{t-1} + \\alpha \\nabla f(x_t)$\n\t\t\t\t\\State $x_{t+1} = x_t - v_t$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nLeveraging the idea of momentum introduced by Polyak, Nesterov introduced a slightly altered update rule that has been shown to converge not only for quadratic functions, but for general convex functions. In the Nesterov's method~\\cite{nesterov1998introductory}, instead, the velocity vector $v_t$ is calculated by applying the $\\beta$ momentum to the previous $v_{t-1}$ displacement, and subtracting the gradient step to $x_t + \\beta v_{t-1}$, which is the point where the momentum term leads from $x_t$.\n\n\\begin{algorithm}[H]\n\t\\caption{Nesterov Accelerated Gradient Descent}\n\t\\label{alg:nag}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate $\\alpha > 0$}\n\t\t\\Require{Momentum $\\beta \\in [0,1)$}\n\t\t\\Function{NesterovAcceleratedGradientDescent}{$f,\\alpha,\\beta$}\n\t\t\t\\State Initialize weight vector $x_1 \\gets x_0$ and velocity vector $v_0 \\gets 0$\n\t\t\t\\State $t \\gets 1$\n\t\t\t\\While{$not\\_convergence$}\n\t\t\t\t\\State $\\hat{x}_t \\gets x_t + \\beta v_{t-1}$\n\t\t\t\t\\State $v_t \\gets \\beta v_{t-1} + \\alpha \\nabla f(\\hat{x}_t)$\n\t\t\t\t\\State $x_{t+1} \\gets x_t - v_t$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nComparing the algorithm \\ref{alg:hbg} with the algorithm \\ref{alg:nag}, we can see that Polyak’s method evaluates the gradient before adding momentum, whereas Nesterov’s algorithm evaluates it after applying momentum, which intuitively brings us closer to the minimum $x^*$, as showb in figure \\ref{fig:momentum}.\n\n\\begin{theorem}[Nesterov Accelerated Gradient Descent convergence for convex functions] \\label{thm:cvx_nag_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-smooth convex function. Let $x_*$ be the minimum of $f$ on $\\Re^m$. Then the Gradient Descent with step size $\\alpha \\leq 1/L$ and $\\beta_{t+1} = t / (t+3)$ satisfies:\n$$\nf(x_t) - f(x_*) \\leq \\frac{2 \\| x_0 - x_* \\|^2}{\\alpha (t+1)^2}\n$$\nIn particular, for $\\alpha = 1/L$:\n$$\nf(x_t) - f(x_*) \\leq \\frac{2L \\| x_0 - x_* \\|^2}{(t+1)^2}\n$$\n\\end{theorem}\n\n\\begin{theorem}[Nesterov Accelerated Gradient Descent convergence for strongly convex functions] \\label{thm:str_cvx_nag_convergence}\nLet $f: \\Re^m \\rightarrow \\Re$ be a L-smooth, $\\mu$ strongly convex function. Let $x_*$ be the minimum of $f$ on $\\Re^m$. Then the Gradient Descent with step size $\\alpha \\leq 1/L$ and $\\beta_t = \\displaystyle \\frac{1 - \\sqrt{\\mu / L}}{1 + \\sqrt{\\mu / L}} = \\frac{1-1/\\sqrt{\\kappa}}{1+1/\\sqrt{\\kappa}}$ satisfies:\n$$\n\\begin{aligned}\n\tf(x_t) - f(x_*) \\leq & \\frac{\\| x_0 - x_* \\|^2}{\\alpha} \\Bigg(1 - \\sqrt{\\frac{\\mu}{L}}\\Bigg)^t \\\\ \n\t\t\t\t\t\t= & \\frac{\\| x_0 - x_* \\|^2}{\\alpha} \\Bigg(1 - \\frac{1}{\\sqrt{\\kappa}}\\Bigg)^t\n\\end{aligned}\n$$\nIn particular, for $\\alpha = 1/L$:\n$$\n\\begin{aligned}\n\tf(x_t) - f(x_*) \\leq & L \\| x_0 - x_* \\|^2 \\Bigg(1 - \\sqrt{\\frac{\\mu}{L}}\\Bigg)^t \\\\\n\t\t\t\t\t\t= & L \\| x_0 - x_* \\|^2 \\Bigg(1 - \\frac{1}{\\sqrt{\\kappa}}\\Bigg)^t\n\\end{aligned}\n$$\nwhere $\\kappa = L/\\mu$.\n\\end{theorem}\n\nNesterov momentum brings the rate of convergence from $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{t}\\Big)$ to $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{t^2}\\Big)$ and in the case of smooth and strongly convex functions gives the acceleration that we had with Polyak’s momentum for quadratic functions. This is great, because we get the guarantee for a more general class of functions.\n\n\\bigskip\n\nWe can write the iteration complexity of these methods, i.e., the smallest $t$ such that we’re within $\\epsilon$, for a L-smooth and $\\mu$-strongly convex function as $\\displaystyle \\mathcal{O}\\Big(\\kappa \\log \\frac{1}{\\epsilon}\\Big)$ for the standard GD method, $\\displaystyle \\mathcal{O}\\Big(\\sqrt{\\kappa}\\log \\frac{1}{\\epsilon}\\Big)$ for the Polyak’s method and, finally, $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{\\sqrt{\\epsilon}}\\Big)$ for the NAG method to get $\\epsilon$-close to global optimum and where $\\kappa$, i.e., the \\emph{conditioning number}, is defined as $\\kappa = L/\\mu$ and where $L$ and $\\mu$ are also equal to the smallest and the largest eigenvalues $\\lambda_{min}$ and $\\lambda_{max}$ respectively.\n\n\\pagebreak\n\n\\subsection{AdaGrad}\n\nDue to the sparsity of the weight vector of the \\emph{Lagrangian dual}, i.e., the Lagrange multipliers, we might end up in a situation where some components of the gradient are very small and others large. This, in terms of \\emph{conditioning number}, i.e., $\\kappa = L/\\mu \\gg 1$, means that the level sets of $f$ are ellipsoid, i.e., we are dealing with an ill-conditioned problem. So, given a learning rate, a standard gradient descent approach might end up in a situation where it decreases too quickly the small weights or too slowly the large ones.\n\nAnother method, that is usually deprecated in ML applications due to its increased computational complexity, is Newton’s method. Newton’s method favors a much faster convergence rate, i.e., number of iterations, at the cost of being more expensive per iteration. For convex problems, the recursion is similar to the gradient descent algorithm:\n\n$$\nx_{t+1} = x_t - \\alpha H^{-1} \\nabla f(x_t)\n$$\n\nwhere $\\alpha$ is often close to one (damped-Newton) or one, and $H^{-1}$ denotes the Hessian of $f$ at the current point, i.e., $\\nabla^2 f(x_t)$.\n\nThe above suggest a general rule in optimization: find any preconditioner, in convex optimization it has to be positive semidefinite, that improves the performance of gradient descent in terms of iterations, but without wasting too much time to compute that precoditioner. The above result into:\n\n$$\nx_{t+1} = x_t - \\alpha P^{-1} \\nabla f(x_t)\n$$\n\nwhere $P$ is the preconditioner. This idea is the basis of the BFGS quasi-Newton method.\n\nThe \\emph{AdaGrad}~\\cite{duchi2011adaptive} algorithm is just a variant of preconditioned gradient descent, where $P$ is selected to be a diagonal preconditioner matrix and is updated using the gradient information, in particular it is the diagonal approximation of the inverse of the square roots of gradient outer products, until the $k$-th iteration. The above lead to the algorithm:\n\n\\begin{algorithm}[H]\n\t\\caption{AdaGrad}\n\t\\label{alg:adagrad}\n\t\\begin{algorithmic}\n\t\t\\Require{Function $f$ to minimize}\n\t\t\\Require{Learning rate or step size $\\alpha > 0$}\n\t\t\\Require{Offset $\\epsilon > 0$ to ensures not divide by 0}\n\t\t\\Function{AdaGrad}{$f,\\alpha,\\epsilon$}\n\t\t\t\\State Initialize weight vector $x_0$ and the squared accumulated gradients vector $s_t \\gets 0$\n\t\t\t\\State $t = 1$\n\t\t\t\\While {$not\\_convergence$}\n\t\t\t\t\\State $g_t \\gets \\nabla f(x_t)$\n\t\t\t\t\\State $s_t \\gets s_{t-1} + g_t^2$\n\t\t\t\t\\State $x_{t+1} \\gets x_t - \\alpha P_t^{-1} g_t = x_t - \\displaystyle \\frac{\\alpha}{\\sqrt{s_t + \\epsilon}} \\odot g_t \\ \\text{where} \\ P_t \\gets diag(s_t + \\epsilon)^{1/2}$\n\t\t\t\t\\State $t \\gets t + 1$\n\t\t\t\\EndWhile\n\t\t\t\\State \\Return $x_t$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{algorithm}\n\nIn practical terms, \\emph{AdaGrad} addresses the problem of the sparse optimal by adaptively scaling the learning rate for each dimension with the magnitude of the gradients. Coordinates that routinely correspond to large gradients are scaled down significantly, whereas others with small gradients receive a much more gentle treatment. \\emph{AdaGrad}'s convergence rate for L-smooth convex functions is $\\displaystyle \\mathcal{O}\\Big(\\frac{1}{\\sqrt{t}}\\Big)$.\n\n\\pagebreak\n\n\\subsection{Sequential Minimal Optimization}\n\nThe \\emph{Sequential Minimal Optimization (SMO)}~\\cite{platt1998sequential} method is the most popular approach for solving the SVM QP problem without any extra $Q$ matrix storage required by common QP methods. The advantage of SMO lies in the fact that it performs a series of two-point optimizations since we deal with just one equality constraint, so the Lagrange multipliers can be solved analitically.\n\n\\subsubsection{Classification}\n\nAt each iteration, SMO chooses two $\\alpha_i$ to jointly optimize, let $\\alpha_1$ and $\\alpha_2$, finds the optimal values for these multipliers and update the SVM to reflect these new values. In order to solve for two Lagrange multipliers, SMO first computes the constraints over these and then solves for the constrained minimum. Since there are only two multipliers, the box-constraints cause the Lagrange multipliers to lie within a box, while the linear equality constraint causes the Lagrange multipliers to lie on a diagonal line inside the box. So, the constrained minimum must lie there as shown in \\ref{fig:smo_lagrange_multipliers}.\n\n\\begin{figure}[h!]\n\t\\centering\n\t\\includegraphics[scale=0.5]{img/smo_multipliers}\n\t\\caption{SMO for two Lagrange multipliers}\n\t\\label{fig:smo_lagrange_multipliers}\n\\end{figure}\n\nIn case of classification the ends of the diagonal line segment, i.e., the lower and upper bounds, can be espressed as follow if the target $y_1 \\ne y_2$:\n\n\\begin{equation} \\label{eq:smo_svc_bounds_update1}\n\t\\begin{aligned}\n\t\t& L = max(0, \\alpha_2 - \\alpha_1) \\\\\n\t\t& H = min(C, C + \\alpha_2 - \\alpha_1)\n\t\\end{aligned}\n\\end{equation}\n\nor, alternatively, if the target $y_1 = y_2$:\n\n\\begin{equation} \\label{eq:smo_svc_bounds_update2}\n\t\\begin{aligned}\n\t\t& L = max(0, \\alpha_2 + \\alpha_1 - C) \\\\\n\t\t& H = min(C, \\alpha_2 + \\alpha_1)\n\t\\end{aligned}\n\\end{equation}\n\nThe second derivative of the objective quadratic function along the diagonl line can be expressed as:\n\n\\begin{equation} \\label{eq:smo_eta}\n\t\\eta = K(x_1, x_1) + K(x_2, x_2) - 2K(x_1, x_2)\n\\end{equation}\n\nthat will be grather than zero if the kernel matrix will be positive definite, so there will be a minimum along the linear equality constraints that will be:\n\n\\begin{equation} \\label{eq:smo_svc_a2_new}\n\t\\alpha_2^{new} = \\alpha_2 + \\frac{y_2(E_1 - E_2)}{\\eta}\n\\end{equation}\n\nwhere $E_i = y_i - y'_i$ is the error on the $i$-th training example and $y'_i$ is the output of the SVC for the same.\n\nThen, the box-constrained minimum is found by clipping the unconstrained minimum to the ends of the line segment:\n\n\\begin{equation} \\label{eq:smo_svc_a2_new_clipped}\n    \\alpha_2^{new,clipped} =\n        \\begin{cases}\n            H & \\text{if} \\ \\alpha_2^{new} \\geq H \\\\\n            \\alpha_2^{new} & \\text{if} \\ L < \\alpha_2^{new} < H \\\\\n            L & \\text{if} \\ \\alpha_2^{new} \\leq L \\\\\n        \\end{cases}\n\\end{equation}\n\nFinally, the value of $\\alpha_1$ is computed from the new clipped $\\alpha_2$ as:\n\n\\begin{equation} \\label{eq:smo_svc_a1_new}\n\t\\alpha_1^{new} = \\alpha_1 + s (\\alpha_2 - \\alpha_2^{new,clipped})\n\\end{equation}\n\nwhere $s = y_1 y_2$.\n\nSince the \\emph{Karush-Kuhn-Tucker} conditions are necessary and sufficient conditions for optimality of a positive definite QP problem and the KKT conditions for the classification problem~\\eqref{eq:svc_min_wolfe_dual} are:\n\n\\begin{equation} \\label{eq:svc_smo_kkt}\n\t\\begin{aligned}\n\t\t\\alpha_i = 0 & \\Leftrightarrow y_i y'_i \\geq 1 \\\\\n\t\t0 < \\alpha_i < C & \\Leftrightarrow y_i y'_i = 1 \\\\\n\t\t\\alpha_i = C & \\Leftrightarrow y_i y'_i \\leq 1\n\t\\end{aligned}\n\\end{equation}\n\nthe steps described above will be iterate as long as there will be an example that violates them.\n\nAfter optimizing $\\alpha_1$ and $\\alpha_2$, we select the threshold $b$ such that the KKT conditions are satisfied for $x_1$ and $x_2$. If, after optimization, $\\alpha_1$ is not at the bounds, i.e., $0 < \\alpha_1 < C$, then the following threshold $b_{up}$ is valid, since it forces the SVC to output $y_1$ when the input is $x_1$:\n\n\\begin{equation} \\label{eq:smo_svc_b1}\n\tb_{up} = E_1 + y_1 (\\alpha_1^{new} - \\alpha_1) K(x_1,x_1) + y_2 (\\alpha_2^{new,clipped} - \\alpha_2) K(x_1,x_2) + b\n\\end{equation}\n\nsimilarly, the following threshold $b_{low}$ is valid if $0 < \\alpha_2 < C$:\n\n\\begin{equation} \\label{eq:smo_svc_b2}\n\tb_{low} = E_2 + y_1 (\\alpha_1^{new} - \\alpha_1) K(x_1,x_2) + y_2 (\\alpha_2^{new,clipped} - \\alpha_2) K(x_2,x_2) + b\n\\end{equation}\n\nIf, after optimization, both $0 < \\alpha_1 < C$ and $0 < \\alpha_2 < C$ then both these thresholds are valid, and they will be equal; else, if both $\\alpha_1$ and $\\alpha_2$ are at the bounds, i.e., $\\alpha_1 = 0$ or $\\alpha_1 = C$ and $\\alpha_2 = 0$ or $\\alpha_2 = C$, then all the thresholds between $b_{up}$ and $b_{low}$ satisfy the KKT conditions, so we choose the threshold to be halfway in between $b_{up}$ and $b_{low}$. This gives the complete equation for $b$:\n\n\\begin{equation} \\label{eq:smo_svc_b}\n\tb =\n        \\begin{cases}\n            b_{up} & \\text{if} \\ 0 < \\alpha_1 < C \\\\\n            b_{low} & \\text{if} \\ 0 < \\alpha_2 < C \\\\\n            \\displaystyle \\frac{b_{up}+b_{low}}{2} & \\text{otherwise} \\\\\n        \\end{cases}\n\\end{equation}\n\n\\newpage\n\n\\begin{breakablealgorithm}\n\t\\caption{Sequential Minimal Optimization for Classification}\n\t\\label{alg:smo_classifier}\n\t\\begin{algorithmic}\n\t\t\\Require{Training examples matrix $X \\in \\Re^{n \\times m}$}\n\t\t\\Require{Training target vector $y \\in \\pm1^n$}\n\t\t\\Require{Kernel matrix $K \\in \\Re^{n \\times n}$}\n\t\t\\Require{Regularization parameter $C > 0$}\n\t\t\\Require{Tolerance value $tol$ for stopping criterion}\n\t\t\\Function{SMOClassifier}{$X,y,K,C,tol$}\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha \\in \\Re^n, \\alpha \\gets 0$\n\t\t\t\\State Initialize the empty set $I0 \\gets \\{i : 0 < \\alpha_i < C\\}$\n\t\t\t\\State Initialize the set $I1 \\gets \\{i : y_i = +1, \\alpha_i = 0\\}$ to contain all the indices of the training examples of class $+1$\n\t\t\t\\State Initialize the empty set $I2 \\gets \\{i : y_i = -1,\t \\alpha_i = C\\}$\n\t\t\t\\State Initialize the empty set $I3 \\gets \\{i :  y_i = +1,\t \\alpha_i = C\\}$\n\t\t\t\\State Initialize the set $I4 \\gets \\{i : y_i = -1, \\alpha_i = 0\\}$ to contain all the indices of the training examples of class $-1$\n\t\t\t\\State Initialize $b_{up} \\gets -1$\n\t\t\t\\State Initialize $b_{low} \\gets +1$\n\t\t\t\\State Initialize the error cache vector $errors \\in \\Re^n, errors \\gets 0$\n\t\t\t\\While {$num\\_changed > 0$ \\OR $examine\\_all = True$}\n\t\t\t\t\\State $num\\_changed \\gets 0$\n\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\For {$i \\gets 0$ to $n$} \\Comment loop over all training examples\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\Else\n\t\t\t\t\t\\For {$i$ in $I0$} \\Comment loop over examples where $\\alpha_i$ are not already at their bounds\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\t\\If {$b_{up} > b_{low} - 2 tol$} \\Comment check if optimality on $I0$ is attained\n\t\t\t\t\t\t\t\\State {$num\\_changed \\gets 0$}\n\t\t\t\t\t\t\t\\Break\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\State $examine\\_all \\gets False$\n\t\t\t\t\\ElsIf {$num\\_changed = 0$}\n\t\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\State Compute $b$ by~\\eqref{eq:smo_svc_b}\n\t\t\t\\State \\Return $\\alpha,b$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{ExamineExample}{$i2$}\n\t\t\t\\If {$i2$ in $I0$}\n\t\t\t\t\\State $E_2 \\gets errors_{i2}$\n\t\t\t\\Else \n\t\t\t\t\\State Compute $E_2$\n\t\t\t\t\\State $errors_{i2} \\gets E_2$\n\t\t\t\t\\State Update $(b_{low}, i_{low})$ or $(b_{up}, i_{up})$ using $(E_2, i2)$\n\t\t\t\\EndIf\n\t\t\t\\If {optimality is attained using current $b_{low}$ and $b_{up}$}\n\t\t\t\t\\State \\Return 0\n\t\t\t\\Else\n\t\t\t\t\\State Find an index $i1$ to do joint optimization with $i2$\n\t\t\t\t\\If {$\\Call{TakeStep}{i1,i2}$ = True}\n\t\t\t\t\t\\State \\Return 1\n\t\t\t\t\\Else\n\t\t\t\t\t\\State \\Return 0\n\t\t\t\t\\EndIf\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i1$-th Lagrange multiplier}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{TakeStep}{$i1,i2$}\n\t\t\t\\If {$i1 = i2$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State Compute $L$ and $H$ using~\\eqref{eq:smo_svc_bounds_update1} or~\\eqref{eq:smo_svc_bounds_update2}\n\t\t\t\\If {$L = H$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State Compute $\\eta$ by~\\eqref{eq:smo_eta} \\Comment we assume that $\\eta > 0$, i.e., the kernel matrix $K$ is positive definite\n\t\t\t\\If {$\\eta < 0$}\n\t\t\t\t\\State Choose $\\alpha_2^{new,clipped}$ between $L$ and $H$ according to the largest value of the objective function at these points\n\t\t\t\\Else\n\t\t\t\t\\State Compute $\\alpha_2^{new}$ by~\\eqref{eq:smo_svc_a2_new}\n\t\t\t\t\\State Compute $\\alpha_2^{new,clipped}$ by~\\eqref{eq:smo_svc_a2_new_clipped}\n\t\t\t\\EndIf\n\t\t\t\\If {changes in $\\alpha_2^{new,clipped}$ are larger than some eps}\n\t\t\t\t\\State Compute $\\alpha_1^{new}$ by~\\eqref{eq:smo_svc_a1_new}\n\t\t\t\t\\State Update $\\alpha_2^{new,clipped}$ and $\\alpha_1^{new}$\n\t\t\t\t\\For {$i$ in $I0$}\n\t\t\t\t\t\\State Update $errors_i$ using new Lagrange multipliers\n\t\t\t\t\\EndFor\n\t\t\t\t\\State Update $\\alpha$ using new Lagrange multipliers\n\t\t\t\t\\State Update $I0, I1, I2, I3$ and $I4$\n\t\t\t\t\\State Update $errors_{i1}$ and $errors_{i2}$\n\t\t\t\t\\For {$i$ in $I0 \\cup \\{i1,i2\\}$}\n\t\t\t\t\t\\State Compute $(i_{low}, b_{low})$ by $b_{low} = \\max\\{errors_i : i \\in I0 \\cup I3 \\cup I4\\}$\n\t\t\t\t\t\\State Compute $(i_{up}, b_{up})$ by $b_{up} = \\min\\{errors_i : i \\in I0 \\cup I1 \\cup I2\\}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\State \\Return True\n\t\t\t\\Else\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\n\\newpage\n\n\\subsubsection{Regression}\n\nIn case of regression the bounds and the new multipliers $\\alpha_1^{+,new}$ and $\\alpha_2^{+,new}$ can be expressed as follows if ($\\alpha_1^+ > 0$ or ($\\alpha_1^- = 0$ and $ E_1 - E_2 > 0$)) and ($\\alpha_2^+ > 0$ or ($\\alpha_2^- = 0$ and $ E_1 - E_2 < 0$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update1}\n\t\\begin{aligned}\n\t\t& L = max(0, \\gamma - C) \\\\\n\t\t& H = min(C, \\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new1}\n\t\\alpha_2^{+,new} = \\alpha_2^+ - \\frac{E_1 - E_2}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new1}\n\t\\alpha_1^{+,new} = \\alpha_1^+ - (\\alpha_2^{+,new,clipped} - \\alpha_2^+)\n\\end{equation}\n\nor, if ($\\alpha_1^+ > 0$ or ($\\alpha_1^- = 0$ and $ E_1 - E_2 > 2 \\epsilon$)) and ($\\alpha_2^- > 0$ or ($\\alpha_2^+ = 0$ and $ E_1 - E_2 > 2 \\epsilon$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update2}\n\t\\begin{aligned}\n\t\t& L = max(0, -\\gamma) \\\\\n\t\t& H = min(C, -\\gamma + C)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new2}\n\t\\alpha_2^{-,new} = \\alpha_2^- + \\frac{(E_1 - E_2) - 2 \\epsilon}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new2}\n\t\\alpha_1^{+,new} = \\alpha_1^+ + (\\alpha_2^{-,new,clipped} - \\alpha_2^-)\n\\end{equation}\n\nor, if ($\\alpha_1^- > 0$ or ($\\alpha_1^+ = 0$ and $ E_1 - E_2 < - 2 \\epsilon$)) and ($\\alpha_2^+ > 0$ or ($\\alpha_2^- = 0$ and $ E_1 - E_2 < - 2 \\epsilon$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update3}\n\t\\begin{aligned}\n\t\t& L = max(0, \\gamma) \\\\\n\t\t& H = min(C, C + \\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new3}\n\t\\alpha_2^{+,new} = \\alpha_2^+ - \\frac{(E_1 - E_2) + 2 \\epsilon}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new3}\n\t\\alpha_1^{-,new} = \\alpha_1^- + (\\alpha_2^{+,new,clipped} - \\alpha_2^+)\n\\end{equation}\n\nor, finally, if ($\\alpha_1^- > 0$ or ($\\alpha_1^+ = 0$ and $ E_1 - E_2 < 0$)) and ($\\alpha_2^- > 0$ or ($\\alpha_2^+ = 0$ and $ E_1 - E_2 > 0$)):\n\n\\begin{equation} \\label{eq:smo_svr_bounds_update4}\n\t\\begin{aligned}\n\t\t& L = max(0, -\\gamma - C) \\\\\n\t\t& H = min(C, -\\gamma)\n\t\\end{aligned}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a2_new4}\n\t\\alpha_2^{-,new} = \\alpha_2^- + \\frac{E_1 - E_2}{\\eta}\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_a1_new4}\n\t\\alpha_1^{-,new} = \\alpha_1^- - (\\alpha_2^{-,new,clipped} - \\alpha_2^-)\n\\end{equation}\n\nwhere $\\gamma = \\alpha_1^+ - \\alpha_1^- + \\alpha_2^+ - \\alpha_2^-$. Notice that $\\eta$ and $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ are identical to~\\eqref{eq:smo_eta} and~\\eqref{eq:smo_svc_a2_new_clipped} respectively.\n\nThe KKT conditions for the regression problem~\\eqref{eq:svr_min_wolfe_dual} are:\n\n\\begin{equation} \\label{eq:svr_smo_kkt}\n\t\\begin{aligned}\n\t\t\\alpha_i^+ - \\alpha_i^- = 0 & \\Leftrightarrow | y_i - y'_i | < \\epsilon \\\\\n\t\t-C < \\alpha_i^+ - \\alpha_i^- < C & \\Leftrightarrow | y_i - y'_i | = \\epsilon \\\\\n\t\t\\alpha_i^+ + \\alpha_i^- = C & \\Leftrightarrow | y_i - y'_i | > \\epsilon\t\n\t\\end{aligned}\n\\end{equation}\n\nso, the steps described above will be iterate as long as there will be an example that violates them.\n\nIn case of regression we select the threshold $b$ as follows:\n\n\\begin{equation} \\label{eq:smo_svr_b1}\n\tb_{up} = E_1 + ((\\alpha_1^+ - \\alpha_1^-) - (\\alpha_1^{+,new} - \\alpha_1^{-,new})) K(x_1,x_1) + ((\\alpha_2^+ - \\alpha_2^-) - (\\alpha_2^{+,new,clipped} - \\alpha_2^{-,new,clipped})) K(x_1,x_2) + b\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_b2}\n\tb_{low} = E_2 + ((\\alpha_1^+ - \\alpha_1^-) - (\\alpha_1^{+,new} - \\alpha_1^{-,new})) K(x_1,x_2) + ((\\alpha_2^+ - \\alpha_2^-) - (\\alpha_2^{+,new,clipped} - \\alpha_2^{-,new,clipped})) K(x_2,x_2) + b\n\\end{equation}\n\n\\begin{equation} \\label{eq:smo_svr_b}\n\tb =\n        \\begin{cases}\n            b_{up} & \\text{if} \\ 0 < \\alpha_1^+, \\alpha_1^- < C \\\\\n            b_{low} & \\text{if} \\ 0 < \\alpha_2^+, \\alpha_2^- < C \\\\\n            \\displaystyle \\frac{b_{up}+b_{low}}{2} & \\text{otherwise} \\\\\n        \\end{cases}\n\\end{equation}\n\n\\bigskip\n\\bigskip\n\nThe improvements described in~\\cite{keerthi2001improvements, shevade1999improvements} for classification and regression respectively are about the definition of subsets of multipliers to efficiently update them at each iteration by separating the multipliers at the bounds from those who can be further minimized.\n\n\\newpage\n\n\\begin{breakablealgorithm}\n\t\\caption{Sequential Minimal Optimization for Regression}\n\t\\label{alg:smo_regression}\n\t\\begin{algorithmic}\n\t\t\\Require{Training examples matrix $X \\in \\Re^{n \\times m}$}\n\t\t\\Require{Training target vector $y \\in \\Re^n$}\n\t\t\\Require{Kernel matrix $K \\in \\Re^{n \\times n}$}\n\t\t\\Require{Regularization parameter $C > 0$}\n\t\t\\Require{Epsilon-tube value $\\epsilon \\geq 0$ within which no penalty is associated in the epsilon-insensitive loss function}\n\t\t\\Require{Tolerance value $tol$ for stopping criterion}\n\t\t\\Function{SMORegression}{$X,y,K,C,\\epsilon,tol$}\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha^+ \\in \\Re^n, \\alpha^+ \\gets 0$\n\t\t\t\\State Initialize the Lagrange multipliers vector $\\alpha^- \\in \\Re^n, \\alpha^- \\gets 0$\n\t\t\t\\State Initialize the empty set $I0 \\gets \\{i : 0 < \\alpha^+_i, \\alpha^-_i < C\\}$\n\t\t\t\\State Initialize the set $I1 \\gets \\{i : \\alpha^+_i = 0, \\alpha^-_i = 0\\}$ to contain all the indices of the training examples\n\t\t\t\\State Initialize the empty set $I2 \\gets \\{i : \\alpha^+_i = 0, \\alpha^-_i = C\\}$\n\t\t\t\\State Initialize the empty set $I3 \\gets \\{i : \\alpha^+_i = C, \\alpha^-_i = 0\\}$\n\t\t\t\\State Initialize $i_{up} \\gets 0$ \\Comment or any other target index $i_{up}$ from the training examples\n\t\t\t\\State Initialize $i_{low} \\gets 0$ \\Comment or any other target index $i_{low}$ from the training examples\n\t\t\t\\State Initialize $b_{up} \\gets y_{i_{up}} + \\epsilon$\n\t\t\t\\State Initialize $b_{low} \\gets y_{i_{low}} - \\epsilon$\n\t\t\t\\State Initialize the error cache vector $errors \\in \\Re^n, errors \\gets 0$\n\t\t\t\\While {$num\\_changed > 0$ \\OR $examine\\_all = True$}\n\t\t\t\t\\State $num\\_changed \\gets 0$\n\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\For {$i \\gets 0$ to $n$} \\Comment loop over all training examples\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\Else\n\t\t\t\t\t\\For {$i$ in $I0$} \\Comment loop over examples where $\\alpha^+_i$ and $\\alpha^-_i$ are not already at their bounds\n\t\t\t\t\t\t\\State $num\\_changed \\gets num\\_changed + \\Call{ExamineExample}{i}$\n\t\t\t\t\t\t\\If {$b_{up} > b_{low} - 2 tol$} \\Comment check if optimality on $I0$ is attained\n\t\t\t\t\t\t\t\\State {$num\\_changed \\gets 0$}\n\t\t\t\t\t\t\t\\Break\n\t\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\EndFor\n\t\t\t\t\\EndIf\n\t\t\t\t\\If {$examine\\_all = True$}\n\t\t\t\t\t\\State $examine\\_all \\gets False$\n\t\t\t\t\\ElsIf {$num\\_changed = 0$}\n\t\t\t\t\t\\State $examine\\_all \\gets True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\State Compute $b$ by~\\eqref{eq:smo_svr_b}\n\t\t\t\\State \\Return $\\alpha^+,\\alpha^-,b$\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\t\n\t\\newpage\n\t\n\t\\begin{algorithmic}\n\t\t\\Require{$i1$-th Lagrange multiplier}\n\t\t\\Require{$i2$-th Lagrange multiplier}\n\t\t\\Function{TakeStep}{$i1,i2$}\n\t\t\t\\If {$i1 = i2$}\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\t\\State $finished = False$\n\t\t\t\\While {\\NOT $finished$}\n\t\t\t\t\\State Compute $L$ and $H$ using~\\eqref{eq:smo_svr_bounds_update1},~\\eqref{eq:smo_svr_bounds_update2},~\\eqref{eq:smo_svr_bounds_update3} or~\\eqref{eq:smo_svr_bounds_update4}\n\t\t\t\t\\If {$L < H$}\n\t\t\t\t\t\\State Compute $\\eta$ by~\\eqref{eq:smo_eta} \\Comment we assume that $\\eta > 0$, i.e., the kernel matrix $K$ is positive definite\n\t\t\t\t\t\\If {$\\eta < 0$}\n\t\t\t\t\t\t\\State Choose $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ between $L$ and $H$ according to the largest value of the objective function at these points\n\t\t\t\t\t\\Else\n\t\t\t\t\t\t\\State Compute $\\alpha_2^{+,new}$ or $\\alpha_2^{-,new}$ using~\\eqref{eq:smo_svr_a2_new1},~\\eqref{eq:smo_svr_a2_new3} or~\\eqref{eq:smo_svr_a2_new2},~\\eqref{eq:smo_svr_a2_new4} respectively\n\t\t\t\t\t\t\\State Compute $\\alpha_2^{+,new,clipped}$ or $\\alpha_2^{-,new,clipped}$ by~\\eqref{eq:smo_svc_a2_new_clipped}\n\t\t\t\t\t\\EndIf\n\t\t\t\t\t\\State Compute $\\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ using~\\eqref{eq:smo_svr_a1_new1},~\\eqref{eq:smo_svr_a1_new2} or~\\eqref{eq:smo_svr_a1_new3},~\\eqref{eq:smo_svr_a1_new4} respectively\n\t\t\t\t\t\\If {changes in $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ are larger than some eps}\n\t\t\t\t\t\t\\State Update $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$\n\t\t\t\t\t\\EndIf\n\t\t\t\t\\Else\n\t\t\t\t\t\\State $finished = True$\n\t\t\t\t\\EndIf\n\t\t\t\\EndWhile\n\t\t\t\\If {changes in $\\alpha_2^{+,new,clipped}, \\alpha_2^{-,new,clipped}, \\alpha_1^{+,new}$ or $\\alpha_1^{-,new}$ are larger than some eps}\n\t\t\t\t\\For {$i$ in $I0$}\n\t\t\t\t\t\\State Update $errors_i$ using new Lagrange multipliers\n\t\t\t\t\\EndFor\n\t\t\t\t\\State Update $\\alpha^+$ and $\\alpha^-$ using new Lagrange multipliers\n\t\t\t\t\\State Update $I0, I1, I2$ and $I3$\n\t\t\t\t\\State Update $errors_{i1}$ and $errors_{i2}$\n\t\t\t\t\\For {$i$ in $I0 \\cup \\{i1,i2\\}$}\n\t\t\t\t\t\\State Compute $(i_{low}, b_{low})$ by $b_{low} = \\max\\{errors_i : i \\in I0 \\cup I1 \\cup I2\\}$\n\t\t\t\t\t\\State Compute and $(i_{up}, b_{up})$ by $b_{up} = \\min\\{errors_i : i \\in I0 \\cup I1 \\cup I3\\}$\n\t\t\t\t\\EndFor\n\t\t\t\t\\State \\Return True\n\t\t\t\\Else\n\t\t\t\t\\State \\Return False\n\t\t\t\\EndIf\n\t\t\\EndFunction\n\t\\end{algorithmic}\n\\end{breakablealgorithm}", "meta": {"hexsha": "ed074aa303830bc953c5b74ca66fc4645676eee7", "size": 33399, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notebooks/optimization/tex/methods.tex", "max_stars_repo_name": "AF207/optiml", "max_stars_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-04-06T13:59:03.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-06T13:59:03.000Z", "max_issues_repo_path": "notebooks/optimization/tex/methods.tex", "max_issues_repo_name": "AF207/optiml", "max_issues_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notebooks/optimization/tex/methods.tex", "max_forks_repo_name": "AF207/optiml", "max_forks_repo_head_hexsha": "f8860d90d4f5b6d35a3ed0ef3c1d014a2b517a72", "max_forks_repo_licenses": ["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.0561151079, "max_line_length": 720, "alphanum_fraction": 0.6749004461, "num_tokens": 11766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8596637541053281, "lm_q1q2_score": 0.75718931458967}}
{"text": "\\chapter{Sequential Data}\n\\label{chap:Sequential Data}\n\\section{Hidden Markov Models}\n\\subsection{representation}\n\t\\textbf{Directed Probabilistic Graphical Models} with \\textbf{Latent Variables} to represent \\textbf{Hidden Markov Models}.Hidden Markov Models are \\textbf{State Space Models}.\n\n\tIntroduce latent variable $\\vec{z}_n$ with 1-of-K coding scheme.\n\t\\textbf{Transition probabilities} or \\textbf{transition matrix} $\\vec{A}_{jk} = p(z_{nk}=1|z_{n-1,j}=1)$ and probabilities satisfy\n$0\\leq \\vec{A}_{jk}\\leq 1$ with $\\sum_k{A_{jk}} = 1$.So that matrix $\\vec{A}$ has $K(K-1)$ independent parameters.Write the conditional probability explicitly\n\\begin{align}\np(\\vec{z}_n|\\vec{z}_{n-1},\\vec{A}) = \\prod_{k=1}^{K}\\prod_{j=1}^{K}\\vec{A}_{jk}^{z_{n-1,j}z_{nk}}\n\\end{align}\n\nThe initial latent node does not have a parent node,so the marginal prior distribution is represented by a vector of probabilities $\\pi$ with $\\pi_k\\equiv p(z_{1k}=1)$,so that\n\\begin{align}\np(\\vec{z}_1|\\vec{\\pi}) = \\prod_{k=1}^{K}\\pi_k^{z_{1k}}\n\\end{align}\nwhere $\\sum_{k}^{\\pi_k}=1$.\nThe \\textbf{emission probabilities} can be represented in the form\n\\begin{align}\np(\\vec{x}_n|\\vec{z}_n,\\vec{\\phi})=\\prod_{k=1}^{K}p(\\vec{x}_n|\\vec{\\phi}_k)^{z_{nk}}\n\\end{align}\nFor \\textbf{homogeneous} models,the joint distribution over both latent and observed variables is given by\n\\begin{align}\\label{eqn:hmm joint distribution}\np(\\vec{X},\\vec{Z}|\\vec{\\theta})=p(\\vec{z}_1|\\vec{\\pi})\\left[\\prod_{n=2}^{N}p(\\vec{z}_n|\\vec{z}_{n-1},\\vec{A}) \\right]\n\\prod_{m=1}^{N}p(\\vec{x}_m|\\vec{z}_m,\\vec{\\phi})\n\\end{align}\nwhere $\\vec{\\theta} = \\left\\{\\vec{\\pi},\\vec{A},\\vec{\\phi} \\right\\}$ denotes the set of parameters governing the model.\n\n\\subsection{evaluation}\nThe likelihood function is obtained from the joint distribution by marginalizing over the latent variables\n\\begin{align}\np(\\vec{X}|\\vec{\\theta})=\\sum_{\\vec{Z}}{p(\\vec{X},\\vec{Z}|\\vec{\\theta})}\n\\end{align}\n\n\\subsection{optimization}\n\\subsubsection{EM algorithm}\nDirect maximization of the likelihood function lead to complex expressions with no close-form solutions(not i.i.d),so we turn the \\textbf{expectation maximization} (simplified \\textbf{variational bayesian}).In the \\textbf{E step},take these parameters to find the posterior distribution of the latent variables $p(\\vec{\\vec{Z}|\\vec{X},\\vec{\\theta}^{\\text{old}}})$.Then use this posterior distribution to evaluate the expectation of the logarithm of complete-data likelihood function,as a function of parameters $\\vec{\\theta}$\n\\begin{align}\n\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{\\text{old}}) =\\sum_{\\vec{Z}}{p(\\vec{Z}|\\vec{X},\\vec{\\theta}^{\\text{old}})}\\ln p(\\vec{X},\\vec{Z}|\\vec{\\theta})\n\\end{align}\nIntroduce some notation\n\\begin{align}\n\\gamma(\\vec{z}_n) &= p(\\vec{z}_n|\\vec{X},\\theta^{\\text{old}}) \n=\\mathbb{E}[z_{nk}]=\\sum_{\\vec{z}_n}{\\gamma(\\vec{z}_n)} \\\\\n\\xi(\\vec{z}_{n-1},\\vec{z}_n)&=p(\\vec{z}_{n-1},\\vec{z}_n|\\vec{X},\\vec{\\theta}^{\\text{old}})\n=\\mathbb{E}[{z_{n-1,j}z_{nk}}]=\n\\sum_{\\vec{z}_{n-1},\\vec{z}_n}\\xi(\\vec{z}_{n-1},\\vec{z}_n)z_{n-1,j}z_{nk}\n\\end{align}\nSubstitute the joint distribution $p(\\vec{X},\\vec{Z}|\\vec{\\theta})$\\ref{eqn:hmm joint distribution},we obtain\n\\begin{align}\n\\mathcal{Q}(\\vec{\\theta},\\vec{\\theta}^{\\text{old}}) \n&= \\sum{k=K}\\gamma(z_1 k)\\ln\\pi_k+\\sum_{n=2}^{N}\\sum_{j=1}^{K}\\sum_{k=1}^{K}\\xi(\\vec{z}_{n-1},\\vec{z}_n)\\ln\\vec{A}_{jk}\\\\\n&+ \\sum_{n=1}^{N}\\sum_{k=1}^{K}\\gamma(z_{nk})\\ln p(\\vec{x}_n|\\vec{\\phi}_k)\n\\end{align}\nwhere we have marginalized over the parameters' joint distribution.\n\nIn \\textbf{M step} we maximize $\\mathcal{Q}$ with respect to the parameters,in which we treat $\\gamma$ and $\\xi$ as constant.\n\nIn the case of discrete multinomial observed variables,the conditional distribution of the observations takes the form\n\\begin{align}\n\tp(\\vec{x}|\\vec{z})=\\prod_{i=1}^{D}\\prod_{k=1}^{K}\\mu_{ik}^{x_i z_k}\n\\end{align}\nsubject to $\\sum_{i=1}^{D}\\mu_{ik}=1$.\n\tIntroduce \\textbf{Lagrangian multiplier} $\\lambda$,the objective is to maximize\n\t\\begin{align}\n\t\\mathcal{L}(\\vec{\\mu},\\lambda) = \\sum_{n=1}^{N}\\sum_{k=1}^{K}\\gamma(z_{nk})\\sum_{i=1}^{D}x_{ni}\\ln\\mu_{ik}+\\lambda(\\sum_{i=1}^{D}\\mu_{ik}-1)\n\t\\end{align}\n\tSet the derivatives to zero\n\t\\begin{align}\n\t\\because\\begin{cases}\n\t\\dfrac{\\partial\\mathcal{L}}{\\partial \\mu_{ik}} &= \\sum_{n=1}^{N}\\gamma(z_{nk})x_{ni}\\dfrac{1}{\\mu_{ik}} + \\lambda = 0\\\\\n\t\\dfrac{\\partial\\mathcal{L}}{\\partial \\lambda} &= \\sum_{i=1}^{D}\\mu_{ik} -1 = 0\n\t\\end{cases}\\\\\n\t\\therefore\n\t\\begin{cases}\n\t\\mu_{ik}&=-\\dfrac{\\sum_{n=1}^{N}\\gamma(z_{nk})x_{ni}}{\\lambda} \\\\\n\t\\lambda &= \\sum_{i=1}^{D}\\gamma(z_{nk})\n\t\\end{cases}\\\\\n\t\\Longrightarrow \\\\\n\t\\mu_{ik}&=\\dfrac{\\sum_{n=1}^{N}\\gamma(z_{nk})x_{ni}}{\\sum_{n=1}^{N}\\gamma(z_{nk})}\n\t\\end{align}\n\\subsubsection{forward-backward algorithm}\n\tThe quantities $\\gamma$ and $\\xi$ are posterior distribution of latent variables,and can be obtained using a two-stage message passing algorithm,known as Baum-Welch,a.k.a alpha-beta algorithm.\n\n\n\\subsubsection{scaling factors}\n\tIn the recursion relationship,these probabilities are significantly less than unity,as we work our way forward along the chain,the values of $\\alpha$ can go to zero exponentially quickly.\n\n\\subsection{predict}\n\n\\subsection{title}\n\n\n\\section{Linear Dynamic Systems}\nTODO", "meta": {"hexsha": "6be6af005330244c196846622641104ec74fdaa0", "size": 5223, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "prml/Sequential Data.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/Sequential Data.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/Sequential Data.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": 54.40625, "max_line_length": 525, "alphanum_fraction": 0.6907907333, "num_tokens": 1863, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179018818865, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7571736397373037}}
{"text": "\\subsection{Semantic consequence}\n\nA formula, \\(A\\), semantically implies another, \\(B\\), if for every interpretation of \\(A\\), \\(B\\) is true.\n\nWe show this with:\n\n\\(A\\vDash B\\)\n\nFormula \\(B\\) is satisfisable if there is some \\(A\\) where this is true.\n\nFor example:\n\\(A\\land B \\vDash A\\)\n\nFormula \\(B\\) is a tautology if this is true for any \\(A\\). We can also write this as \\(\\vDash B\\).\n\n\\subsection{Logical equivalence}\n\nIf \\(A\\vDash B\\) and \\(B\\vDash A\\) we say that \\(A\\) and \\(B\\) are logically equivalent.\n\nThis is shown as \\(A \\Leftrightarrow B\\).\n", "meta": {"hexsha": "e151b506c8c314f4ec8176c6ed8f7447f4ec556c", "size": 556, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/propositionalLogic/04-01-semantic.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/04-01-semantic.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/04-01-semantic.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.4761904762, "max_line_length": 107, "alphanum_fraction": 0.6654676259, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9086178969328287, "lm_q2_score": 0.8333245870332531, "lm_q1q2_score": 0.7571736337325724}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{combinatorial -- combinatorial functions}\\linkedzero{combinatorial}\r\n%\r\n  \\subsection{binomial -- binomial coefficient}\\linkedone{combinatorial}{binomial}\r\n   \\func{binomial}\r\n   {%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the binomial coefficient for \\param{n} and \\param{m}.\r\n   In other words, $\\displaystyle{\\frac{\\param{n} !}{(\\param{n} - \\param{m}) ! \\param{m} !}}$.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\negok For convenience, {\\tt binomial(n, n+i)} returns \\(0\\) for positive \\(i\\), and {\\tt binomial(0,0)} returns \\(1\\).\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{n} must be a positive integer and \\param{m} must be\r\n   a non-negative integer. \\\\\r\n\r\n  \\subsection{combinationIndexGenerator -- iterator for combinations}\\linkedone{combinatorial}{combinationIndexGenerator}\r\n\r\n   \\func{combinationIndexGenerator}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{iterator}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return an iterator which generates indices of \\param{m}\r\n   element subsets of \\param{n} element set.\\\\\r\n   \\spacing\r\n   \\quad The number of generated indices is \\linkingone{combinatorial}{binomial}(\\param{n}, \\param{m}).\r\n   \\spacing \r\n   \\quad {\\tt combination\\_index\\_generator}\\linkedone{combinatorial}{combination\\_index\\_generator}\r\n   is an alias of {\\tt combinationIndexGenerator}.\\\\\r\n\r\n  \\subsection{factorial -- factorial}\\linkedone{combinatorial}{factorial}\r\n   \\func{factorial}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return \\(\\param{n}!\\) for non-negative integer \\param{n}.\\\\\r\n\r\n  \\subsection{permutationGenerator -- iterator for permutation}\\linkedone{combinatorial}{permutationGenerator}\r\n  \\func{permutationGenerator}{%\r\n    \\hiki{n}{integer}\r\n  }{%\r\n    \\out{iterator}\r\n  }\r\n   \\spacing\r\n   \\quad Generate all permutations of \\param{n} elements as list iterator.\\\\\r\n   % \r\n   \\spacing \r\n   \\quad The number of generated list is \\param{n}'s\r\n   \\linkingone{combinatorial}{factorial}, so be careful to use\r\n   big \\param{n}.\\\\\r\n   \\spacing \r\n   \\quad {\\tt permutation\\_generator}\\linkedone{combinatorial}{permutation\\_generator}\r\n   is an alias of {\\tt permutationGenerator}.\\\\\r\n\r\n  \\subsection{fallingfactorial -- the falling factorial}\\linkedone{combinatorial}{fallingfactorial}\r\n   \\func{fallingfactorial}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the falling factorial; \\param{n} to the \\param{m} falling,\r\n   i.e. \\(n(n-1)\\cdots(n-m+1)\\).\\\\\r\n\r\n  \\subsection{risingfactorial -- the rising factorial}\\linkedone{combinatorial}{risingfactorial}\r\n   \\func{risingfactorial}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the rising factorial; \\param{n} to the \\param{m} rising,\r\n   i.e.\\, \\(n(n+1)\\cdots(n+m-1)\\).\\\\\r\n\r\n  \\subsection{multinomial -- the multinomial coefficient}\\linkedone{combinatorial}{multinomial}\r\n   \\func{multinomial}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{parts}{list}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the multinomial coefficient.\\\\\r\n   \\spacing\r\n   % input, output document\r\n   \\quad \\param{parts} must be a sequence of natural numbers and the sum of elements in \\param{parts} should be equal to \\param{n}.\\\\\r\n\r\n  \\subsection{bernoulli -- the Bernoulli number}\\linkedone{combinatorial}{bernoulli}\r\n   \\func{bernoulli}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{Rational}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the \\param{n}-th Bernoulli number.\\\\\r\n\r\n  \\subsection{catalan -- the Catalan number}\\linkedone{combinatorial}{catalan}\r\n   \\func{catalan}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the \\param{n}-th Catalan number.\\\\\r\n\r\n  \\subsection{dyck\\_word\\_generator -- generator for Dyck words}\\linkedone{combinatorial}{dyck\\_word\\_generator}\r\n   \\func{dyck\\_word\\_generator}{%\r\n     \\hiki{n}{integer}\r\n     \\hikiopt{alphabet}{sequence}{(0, 1)}\r\n   }{%\r\n     \\out{iterator}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad  Generate all Dyck words of length \\(2\\times\\)\\param{n} as tuples.\\\\\r\n   \\spacing\r\n   \\quad The Dyck words are words on a two character alphabet.\r\n   The number of each character in a word is equal, \r\n   and the number of the second character never exceeds the first\r\n   in any initial parts of the word.\\\\\r\n   \\spacing\r\n   \\quad The number of generated words is the \\param{n}-th Catalan number.\r\n   (see \\linkingone{combinatorial}{catalan})\\\\\r\n   \\spacing\r\n   \\quad The alphabet is \\(\\{0, 1\\}\\) by default, but you can pass it into the\r\n   optional argument \\param{alphabet}.\\\\\r\n\r\n  \\subsection{euler -- the Euler number}\\linkedone{combinatorial}{euler}\r\n   \\func{euler}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the \\param{n}-th Euler number.\\\\\r\n\r\n  \\subsection{bell -- the Bell number}\\linkedone{combinatorial}{bell}\r\n   \\func{bell}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the \\param{n}-th Bell number.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad The Bell number \\(b\\) is defined by:\r\n   \\[b(n) = \\sum_{i=0}^{n} S(n, i),\\ \\]\r\n   where \\(S\\) denotes Stirling number of the second kind (\\linkingone{combinatorial}{stirling2}).\\\\\r\n\r\n  \\subsection{stirling1 -- Stirling number of the first kind}\\linkedone{combinatorial}{stirling1}\r\n   \\func{stirling1}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return Stirling number of the first kind.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad Let \\(s\\) denote the Stirling number and \\((x)_n\\) the falling factorial, then\r\n   \\[(x)_n = \\sum_{i=0}^{n} s(n,\\ i) x^i. \\]\\\\\r\n   \\(s\\) satisfies the recurrence relation:\r\n   \\[s(n,\\ m) = s(n-1,\\ m-1) - (n-1)s(n-1,\\ m)\\ .\\]\\\\\r\n\r\n  \\subsection{stirling2 -- Stirling number of the second kind}\\linkedone{combinatorial}{stirling2}\r\n   \\func{stirling2}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hiki{m}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return Stirling number of the second kind.\\\\\r\n   \\spacing\r\n   % added document\r\n   \\quad Let \\(S\\) denote the Stirling number, \\((x)_i\\) falling factorial, then:\r\n   \\[x^n = \\sum_{i=0}^{n} S(n,\\ i) (x)_i\\]\r\n   \\(S\\) satisfies:\r\n   \\[S(n,\\ m) = S(n-1,\\ m-1) + m S(n-1,\\ m)\\]\\\\\r\n\r\n  \\subsection{partition\\_number -- the number of partitions}\\linkedone{combinatorial}{partition\\_number}\r\n   \\func{partition\\_number}{%\r\n     \\hiki{n}{integer}\r\n   }{%\r\n     \\out{integer}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the number of partitions of \\param{n}.\\\\\r\n\r\n  \\subsection{partitionGenerator -- iterator for partition}\\linkedone{combinatorial}{partitionGenerator}\r\n   \\func{partitionGenerator}{%\r\n     \\hiki{n}{integer},\\ %\r\n     \\hikiopt{maxi}{integer}{0}\r\n   }{%\r\n     \\out{iterator}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return an iterator which generates partitions of \\param{n}.\\\\\r\n   % input, output document\r\n   \\spacing\r\n   \\quad If \\param{maxi} is given, then summands are limited not to exceed \\param{maxi}.\\\\\r\n   \\quad The number of partitions (given by\r\n   \\linkingone{combinatorial}{partition\\_number}) grows exponentially,\r\n   so be careful to use big \\param{n}.\\\\\r\n   \\spacing \r\n   \\quad {\\tt partition\\_generator}\\linkedone{combinatorial}{partition\\_generator}\r\n   is an alias of {\\tt partitionGenerator}.\\\\\r\n\r\n  \\subsection{partition\\_conjugate -- the conjugate of partition}\\linkedone{combinatorial}{partition\\_conjugate}\r\n   \\func{partition\\_conjugate}{%\r\n     \\hiki{partition}{tuple}\r\n   }{%\r\n     \\out{tuple}\r\n   }\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the conjugate of \\param{partition}.\\\\\r\n\r\n\\begin{ex}\r\n>>> combinatorial.binomial(5, 2)\r\n10L\r\n>>> combinatorial.factorial(3)\r\n6L\r\n>>> combinatorial.fallingfactorial(7, 3) == 7 * 6 * 5\r\nTrue\r\n>>> combinatorial.risingfactorial(7, 3) == 7 * 8 * 9\r\nTrue\r\n>>> combinatorial.multinomial(7, [2, 2, 3])\r\n210L\r\n>>> for idx in combinatorial.combinationIndexGenerator(5, 3):\r\n...     print idx\r\n...\r\n[0, 1, 2]\r\n[0, 1, 3]\r\n[0, 1, 4]\r\n[0, 2, 3]\r\n[0, 2, 4]\r\n[0, 3, 4]\r\n[1, 2, 3]\r\n[1, 2, 4]\r\n[1, 3, 4]\r\n[2, 3, 4]\r\n>>> for word in combinatorial.dyck_word_generator(3, alphabet=(\"(\", \")\")):\r\n...     print \"\".join(word)\r\n... \r\n()()()\r\n()(())\r\n(())()\r\n(()())\r\n((()))\r\n>>> for part in combinatorial.partitionGenerator(5):\r\n...     print part\r\n...\r\n(5,)\r\n(4, 1)\r\n(3, 2)\r\n(3, 1, 1)\r\n(2, 2, 1)\r\n(2, 1, 1, 1)\r\n(1, 1, 1, 1, 1)\r\n>>> combinatorial.partition_number(5)\r\n7\r\n>>> def limited_summands(n, maxi):\r\n...     \"partition with limited number of summands\"\r\n...     for part in combinatorial.partitionGenerator(n, maxi):\r\n...         yield combinatorial.partition_conjugate(part)\r\n...\r\n>>> for part in limited_summands(5, 3):\r\n...     print part\r\n...\r\n(2, 2, 1)\r\n(3, 1, 1)\r\n(3, 2)\r\n(4, 1)\r\n(5,)\r\n\\end{ex}%Don't indent!(indent causes an error.)\r\n\r\n\\C\r\n\r\n%---------- end document ---------- %\r\n\r\n\\input{../footer}\r\n", "meta": {"hexsha": "851e81881b9912a255e65225f4e224c4c06aa693", "size": 9623, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/combinatorial.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/combinatorial.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/combinatorial.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": 30.6464968153, "max_line_length": 134, "alphanum_fraction": 0.6219474176, "num_tokens": 2962, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625126757597, "lm_q2_score": 0.8128673155708975, "lm_q1q2_score": 0.757155432233668}}
{"text": "\\section{Introduction}\r\nOur aim for this course is to explore optimisation problems, typically minimising a function $f(x)$ with $f:\\mathbb R^n\\to\\mathbb R$ the objective function subject to the regional constraint $g(x)=b,x\\in X$ where $X\\subset\\mathbb R^n$ defines a regional constraint, and $g:\\mathbb R^n\\to\\mathbb R^m$ defines $m$ functional constraints.\\\\\r\nA feasible solution to the problem is any $x\\in X$ such that $g(x)=b$, so a feasible solution is just one that satisfy the constraint of the problem.\r\nAn optimal solution is a feasible solution $x^\\star$ such that $f(x^\\star)\\le f(x)$ for all feasible $x$.\r\nThe problem itself is feasible if there exists at least one feasible solution, and it is bounded if $\\inf\\{f(x):g(x)=b,x\\in X\\}\\in\\mathbb R$, which is the main focus of us.\\\\\r\nNotice that it makes no difference if we consider the maximisation instead of minimisation by putting appropriate minus signs in the definitions.", "meta": {"hexsha": "44a42d9a096168c03f4b60a9c046775c0d45b680", "size": 942, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "0/intro.tex", "max_stars_repo_name": "david-bai-notes/IB-Optimisation", "max_stars_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "0/intro.tex", "max_issues_repo_name": "david-bai-notes/IB-Optimisation", "max_issues_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "0/intro.tex", "max_forks_repo_name": "david-bai-notes/IB-Optimisation", "max_forks_repo_head_hexsha": "6a1b3e75d9cfeff6fafb6ac3580a78c2b48b690c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 157.0, "max_line_length": 338, "alphanum_fraction": 0.7537154989, "num_tokens": 246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9425067244294587, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7569967039519164}}
{"text": "\\section{Rotating Frames of Reference}\r\nNewton's Second Law works only in inertial frames.\r\nA rotating frame of reference (wrt an inertial frame) is clearly non-inertial in general.\r\nSo the equation of motion in this frame needs to be modified relative to Newton's Second Law.\\\\\r\nLet $S$ be an inertial frame and $S'$ another frame that is rotating along $z$-axis in $S$ with angular velocity $\\omega=\\dot\\theta$ where $\\theta$ is the angle between $x,y$-axis in $S$ and in $S'$.\r\nDenote the basis vectors of $S$ by $\\underline{e_1}=\\underline{\\hat{x}},\\underline{e_2}=\\underline{\\hat{y}},\\underline{e_3}=\\underline{\\hat{z}}$ and that of $S'$ by $\\underline{e_1'}=\\underline{\\hat{x}}',\\underline{e_2'}=\\underline{\\hat{y}}',\\underline{e_3'}=\\underline{\\hat{z}}'$.\r\nConsider a particle at rest in $S'$ viewed in $S$, then its velocity will be\r\n$$\\left( \\frac{\\mathrm d\\underline{r}}{\\mathrm dt} \\right)_S=\\underline{w}\\times\\underline{r}=\\omega\\underline{\\hat{z}}\\times\\underline{r}$$\r\nConventionally we take $\\omega>0$ as anticlockwise.\r\nWe certainly have some formula that applies to the basis vectors of $S'$, namely\r\n$$\\left( \\frac{\\mathrm d}{\\mathrm dt}\\underline{e_i'} \\right)_S=\\underline{\\omega}\\times\\underline{e_i'}$$\r\nSo for a time-dependent vector $\\underline{a}$ we have\r\n$$\\underline{a}(t)=\\sum_{i=1}^3a_i'(t)\\underline{e_i'}(t)$$\r\nSo when we observe in $S'$, the rate of change has\r\n$$\\left( \\frac{\\mathrm d}{\\mathrm dt}\\underline{a}(t) \\right)_{S'}=\\sum_{i=1}^3\\left( \\frac{\\mathrm d}{\\mathrm dt}a_i'(t) \\right)\\underline{e_i'}(t)$$\r\nTherefore\r\n\\begin{align*}\r\n    \\left(\\frac{\\mathrm d}{\\mathrm dt}\\underline{a}\\right)_S&=\\sum_{i=1}^3\\frac{\\mathrm da_i'}{\\mathrm dt}\\underline{e_i'}+\\sum_{i=1}^3a_i'\\left( \\frac{\\mathrm de_i'}{\\mathrm dt} \\right)_S\\\\\r\n    &=\\sum_{i=1}^3\\frac{\\mathrm da_i'}{\\mathrm dt}\\underline{e_i'}+\\sum_{i=1}^3a_i'(\\underline{\\omega}\\times\\underline{e_i'})\\\\\r\n    &=\\left( \\frac{\\mathrm d}{\\mathrm dt}\\underline{a} \\right)_{S'}+\\underline{\\omega}\\times\\underline{a}\r\n\\end{align*}\r\nWhich is the key identity that relates rate of change in one frame to that in the other.\r\nIf we apply this to the position vector $\\underline{r}$, then\r\n$$\\left(\\frac{\\mathrm d}{\\mathrm dt}\\underline{r}\\right)_S=\\left( \\frac{\\mathrm d}{\\mathrm dt}\\underline{r} \\right)_{S'}+\\underline{\\omega}\\times\\underline{r}$$\r\nAnd applying to velocity,\r\n\\begin{align*}\r\n    \\left( \\frac{\\mathrm d^2\\underline{r}}{\\mathrm dt^2} \\right)\r\n    &=\\left( \\left( \\frac{\\mathrm d}{\\mathrm dt} \\right)_{S'}+\\underline{\\omega}\\times \\right)\\left( \\left( \\frac{\\mathrm d}{\\mathrm dt}\\underline{r} \\right)_{S'}+\\underline{\\omega}\\times\\underline{r} \\right)\\\\\r\n    &=\\left( \\frac{\\mathrm d^2\\underline{r}}{\\mathrm dt^2} \\right)_{S'}+2\\underline{\\omega}\\times\\left( \\frac{\\mathrm d\\underline{r}}{\\mathrm dt} \\right)_{S'}+\\underline{\\dot{\\omega}}\\times\\underline{r}+\\underline{\\omega}\\times(\\underline{\\omega}\\times\\underline{r})\r\n\\end{align*}\r\nThis gives the acceleration.\r\n\\subsection{Equation of Motion in a Rotating Frame}\r\n$S$ is inertial, therefore Newton's Laws of Motion applies, hence\r\n$$m\\left( \\frac{\\mathrm d^2\\underline{r}}{\\mathrm dt^2} \\right)_S=\\underline{F}$$\r\nHence we have\r\n$$m\\left( \\frac{\\mathrm d^2\\underline{r}}{\\mathrm dt^2} \\right)_{S'}=\\underline{F}-m\\left( 2\\underline{\\omega}\\times\\left( \\frac{\\mathrm d\\underline{r}}{\\mathrm dt} \\right)_{S'}+\\underline{\\dot{\\omega}}\\times\\underline{r}+\\underline{\\omega}\\times(\\underline{\\omega}\\times\\underline{r}) \\right)$$\r\nThe second term is known as the fictitious forces, whcih are needed to explain the motion observed in a non-intertial frame.\r\nWe give names to each term in the fictitious forces:\\\\\r\nCoriolis force: $-2m\\underline{\\omega}\\times(\\mathrm d\\underline{r}/\\mathrm dt)_{S'}$.\\\\\r\nEuler force: $-m\\underline{\\dot{\\omega}}\\times\\underline{r}$.\\\\\r\nCentrifugal force: $-m\\underline{\\omega}\\times(\\underline{\\omega}\\times\\underline{r})$.\r\nSometimes we take $\\underline{\\omega}$ to be constant, so the Euler force will be zero.\r\n\\subsection{Centrifugal Force}\r\nNote that for $\\underline{\\omega}=\\omega\\underline{\\hat{\\omega}}$ with $\\underline{\\hat{\\omega}}$ being unit,\r\n\\begin{align*}\r\n    -m\\underline{\\omega}\\times(\\underline{\\omega}\\times\\underline{r})&=-m((\\underline{\\omega}\\cdot\\underline{r})\\omega-|\\underline{\\omega}|^2\\underline{r})\\\\\r\n    &=m\\omega^2(\\underline{r}-\\underline{\\hat{\\omega}}(\\underline{\\hat{\\omega}}\\cdot\\underline{r}))\\\\\r\n    &=m\\omega^2\\underline{r}_\\perp\r\n\\end{align*}\r\nwhere $\\underline{r}_\\perp$ is the projection of $\\underline{r}$ onto the plane that is perpendicular to $\\underline{\\omega}$, that is basically the plane of rotation.\r\nSo the centrifugal force is directed away from the rotatrion axis and its magnitude is $m\\omega^2d$ where $d$ is the distance of the particle to the rotation axis.\r\nNote that\r\n$$|\\underline{r}_\\perp|^2=|\\underline{r}|^2-(\\underline{\\hat{\\omega}}\\cdot\\underline{r})^2=|\\underline{r}\\times\\underline{\\hat\\omega}|^2$$\r\nWhile we also have $\\nabla{|\\underline{r}_\\perp|^2}=2\\underline{r}-2\\underline{\\hat\\omega}(\\underline{\\hat\\omega}\\cdot\\underline{r})=2\\underline{r}_\\perp$.\r\nTherefore\r\n$$m\\omega^2\\underline{r}_\\perp=\\nabla\\left( \\frac{1}{2}m|\\underline{r}\\times\\underline{\\omega}|^2 \\right)$$\r\nTherefore the centrifugal force is a potential force.\r\nOn a rotating planet, we can combine the centrifugal force with gravitational force to create the notion of an effective gravity $\\underline{g}_{\\rm eff}=\\underline{g}+\\omega^2\\underline{r}_\\perp$.\r\nConsider a point $P$ on the surface of the rotating planet, where the rotation axis is through the poles.\r\nWe define a local coordinate at $P$ where $\\underline{\\hat{z}}$ is the normal pointing outwards, $\\underline{\\hat{y}}$ is tangent northward, and $\\underline{\\hat{x}}$ is the tangent eastward.\r\nAssume that the point $P$ is at latitude $\\lambda$.\r\nSo $\\underline{r}=R\\underline{\\hat{z}}$ where $R$ is the radius of the planet.\r\nAlso, as for the angular velocity, $\\underline{\\omega}=\\omega(\\underline{\\hat{y}}\\cos\\lambda+\\underline{\\hat{x}}\\sin\\lambda)$.\r\n\\begin{align*}\r\n    \\underline{g}_{\\rm eff}&=-g\\underline{\\hat{z}}+\\omega^2R\\cos\\lambda(\\underline{\\hat{z}}\\cos\\lambda-\\underline{\\hat{y}}\\sin\\lambda)\\\\\r\n    &=-(g-\\omega^2R\\cos^2\\lambda)\\underline{\\hat{z}}-\\omega^2R\\cos\\lambda\\sin\\lambda\\underline{\\hat{y}}\r\n\\end{align*}\r\nSo the angle between $\\underline{g}$ and $\\underline{g}_{\\rm eff}$ would be\r\n$$\\alpha=\\tan^{-1}\\left( \\frac{\\omega^2R\\cos\\lambda\\sin\\lambda}{g-\\omega^2R\\cos^2\\lambda} \\right)$$\r\nFor earth, $\\omega\\approx 2\\pi/86400$, so upon calculation, we obtain $\\alpha\\approx 3.5\\times 10^{-3}$ which is very small.\r\n\\subsection{The Coriolis Force}\r\nThe coriolis force\r\n$$-2m\\underline{\\omega}\\times(\\mathrm d\\underline{r}/\\mathrm dt)_{S'}=-2m\\underline{\\omega}\\times\\underline{v}$$\r\nis perpendicular to the velocity, so it does not do any work.\r\nThis is just like the magnetic force.\r\nWe consider te horizontal motion on a rotating planet again.\r\nThe velocity is given by $\\underline{v}=v_x\\underline{\\hat{x}}+v_y\\underline{\\hat{y}}$.\r\nAs before in our choice of model we have $\\underline{\\omega}=\\omega(\\underline{\\hat{y}}\\cos\\lambda+\\underline{\\hat{z}}\\sin\\lambda)$.\r\nTherefore\r\n\\begin{align*}\r\n    -2m\\underline{\\omega}\\times\\underline{v}&=-2m\\omega(\\underline{\\hat{y}}\\cos\\lambda+\\underline{\\hat{z}}\\sin\\lambda)\\times v_x\\underline{\\hat{x}}+v_y\\underline{\\hat{y}}\\\\\r\n    &=2m\\omega\\sin\\lambda(v_y\\underline{\\hat{x}}-v_x\\underline{\\hat{y}})+2m\\omega\\cos\\lambda v_x\\underline{\\hat{z}}\r\n\\end{align*}\r\nSo by considering tthe sign, the horizontal coriolis force gives a acceleration, which is to the right if we are on the northern hemisphere, and to the left on the southern hemisphere.\r\nIn atmosphere, the coriolis force can be balanced by a pressure gradient.\r\nThe horizontal motion then gives the difference in the direction of cyclones, which is anticlockwise in northern hemisphere and clockwise in the southern hemisphere.\r\n\\begin{example}\r\n    Consider a ball dropped from the top of a tower, we want to know where does it land.\r\n    We have\r\n    $$\\underline{\\ddot{r}}=\\underline{g}-2\\underline{\\omega}\\times\\underline{\\dot{r}}-\\underline{\\omega}\\times(\\underline{\\omega}\\times\\underline{r})=\\underline{g}-2\\underline{\\omega}\\times\\underline{\\dot{r}}+O(\\omega^2)$$\r\n    where the rotation is slow (i.e. $\\omega^2R/g$ is small).\r\n    Integrate it to get\r\n    $$\\underline{\\dot{r}}=\\underline{g}t-2\\underline{\\omega}\\times (\\underline{r}-\\underline{r}(0))+O(\\omega^2)$$\r\n    We substitute this back to the original equation to get $\\underline{\\ddot{r}}=\\underline{g}-2\\underline{\\omega}\\times(\\underline{g}t)+O(\\omega^2)$, which solves to\r\n    $$\\underline{r}=\\underline{r}(0)+\\frac{1}{2}\\underline{g}t^2-\\underline{\\omega}\\times\\underline{g}\\frac{t^3}{3}+O(\\omega^2)$$\r\n    So if we take $\\underline{g}=(0,0,-g),\\underline{\\omega}=(0,\\omega,0)$ and $\\underline{r}(0)=(0,0,R+h)$, then\r\n    $$\\underline{r}=\\left(\\frac{1}{3}\\omega gt^3,0,R+h-\\frac{1}{2}gt^2\\right)$$\r\n    So the time to reach the ground would be $t=\\sqrt{2h/g}$, then it would travel a horizontal distance of approximately\r\n    $$\\frac{1}{3}\\omega g\\left(\\frac{2h}{g}\\right)^{3/2}$$\r\n\\end{example}\r\n(Foucaul Pendulum)\r\nConsider a pendulum at north pole, then the plane of its oscillation is rotating opposing the direction of rotation of the earth.\r\nAt latitude $\\lambda$, the angular velocity of plane of rotation is $\\omega\\sin\\lambda$, therefore the period $2\\pi/(\\omega\\sin\\lambda)$ which is greater than a day if $\\lambda<\\pi/2$.", "meta": {"hexsha": "15e392edecac9733e6d69b789efe31b823328ffe", "size": 9510, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5/rotate.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": "5/rotate.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": "5/rotate.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": 92.3300970874, "max_line_length": 296, "alphanum_fraction": 0.7010515247, "num_tokens": 3075, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.894789454880027, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7569403758144871}}
{"text": "\\subsection{Neural networks}\n\\subsubsection{Fully connected neural network}\nA fully connected neural network (FCNN) is such a neural network in which each neuron is connected to every neuron in the previous layer and each connection has its own weight. \\par This is a general purpose connection pattern and makes no assumptions about the features in the input data to recognize. This type of network is very expensive in terms of memory (weights) and computations (connections).\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=250px]{pictures/fcnn.png}\n\\caption{Fully connected neural network}\n\\end{figure}\n\n\\subsubsection{Convolutional neural network}\nConvolutional neural network (CNN) is a type of feed-forward artificial neural network, which means that connections between the neurons do not form a cycle. Information in the network moves only forward so the given signal goes through the neuron once.\n\\par CNN includes a convolutional layer and usually few other hidden layers. Each neuron is connected only to a small region of the previous layer called receptive field. Receptive fields of different neurons are overlapping with other neuron's fields so that together they are covering the whole input.\n\\par CNN are used for image processing because while using convolution they can recognize edges of an object on the image.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=250px]{pictures/cnn.png}\n\\caption{Convolutional neural network}\n\\end{figure}\n\n\\subsubsection{Recurrent neural network}\nIn recurrent neural network (RNN) connections between the neurons form a directed cycle. It means that RNN can use its internal memory to learn  sequences of inputs. The same set of weights is applied recursively to the structure.\n\\par RNN are used for text or speech recognition.\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=250px]{pictures/rnn.png}\n\\caption{Convolutional neural network}\n\\end{figure}\n\n\\subsection{Activation function}\nThe activation function defines the output of considered neuron with given input. There are many functions that can be used as an activation function in artificial neural networks. The most popular are:\n\\subsubsection{Linear}\n\\begin{center}\n$ f(x)=ax + b $ \\\\ $ a,b \\in R $ \\\\~\\\\\n\\begin{tikzpicture}\n\t\\begin{axis}\n\t\t\\addplot[cmhplot,-]{x};\n\t\\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\n\\subsubsection{Rectified Linear Unit (ReLU)}\n\\[\nf(x)=\n\\left\\{\n\\begin{array}{ll}\n      0 ,& x < 0 \\\\\n      x ,& x\\geq 0 \\\\\n\\end{array} \n\\right. \\]\n\\begin{center}\n\\begin{tikzpicture}\n    \\begin{axis}[\n            xmin=-4,xmax=4,\n            ymin=-4,ymax=4,\n        ]\n        \\addplot[cmhplot,-,domain=-4:0]{0};\n        \\addplot[cmhplot,-,domain=0:4]{x};\n\n    \\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\n\\subsubsection{Sigmoid}\n\\begin{center}\n$f(x) = \\frac{1}{1 + e^{-x}}$ \\\\\n\\begin{tikzpicture}\n    \\begin{axis}[\n            xmin=-5,xmax=5,\n            ymin=-1,ymax=1,\n        ]\n        \\addplot[cmhplot,-]{1/(1 + e^(-x))};\n    \\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\n\\subsubsection{TanH}\n\\begin{center}\n$ f(x)=\\tanh(x)=\\frac{2}{1+e^{-2x}}-1 $ \\\\\n\\begin{tikzpicture}\n    \\begin{axis}[\n            xmin=-5,xmax=5,\n            ymin=-1,ymax=1,\n        ]\n        \\addplot[cmhplot,-]{2/(1 + e^(-2*x))-1};\n    \\end{axis}\n\\end{tikzpicture}\n\\end{center}\n\n\\subsection{Optimization and regularization}\n\\subsubsection{Dropout}\n\\subsubsection{Initial weights}\n\\subsubsection{Learning rate decay}\n\\subsubsection{Gradient Descent}", "meta": {"hexsha": "8571966ae86b949f042d1bbbf0a1bfab05591e15", "size": 3453, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "theory.tex", "max_stars_repo_name": "SoundSourceAnalyzer/Report", "max_stars_repo_head_hexsha": "a7660983e79cdbff8fdbe257be135f12d39d8d61", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "theory.tex", "max_issues_repo_name": "SoundSourceAnalyzer/Report", "max_issues_repo_head_hexsha": "a7660983e79cdbff8fdbe257be135f12d39d8d61", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "theory.tex", "max_forks_repo_name": "SoundSourceAnalyzer/Report", "max_forks_repo_head_hexsha": "a7660983e79cdbff8fdbe257be135f12d39d8d61", "max_forks_repo_licenses": ["CC0-1.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.1290322581, "max_line_length": 402, "alphanum_fraction": 0.7208224732, "num_tokens": 940, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894548800271, "lm_q2_score": 0.8459424334245618, "lm_q1q2_score": 0.7569403688638473}}
{"text": "\\documentclass[main.tex]{subfiles}\n\\begin{document}\n\n\\section*{Thu Nov 28 2019}\n\nWe want to generate random numbers in order to draw samples from known distributions. \nWe can only really generate \\emph{pseudo}-random numbers: for example, we vary the integer\\(x\\) in the formula \n%\n\\begin{align}\n  x' = \\qty(ax+c) \\mod m\n\\,,\n\\end{align}\n%\nwith constant integer \\(a\\), \\(c\\) and \\(m\\). \n\nImportantly, the values of the constants and the starting value of \\(x\\) constitute a \\emph{seed} which can be used to reproduce our results. \n\nIf we want to produce numbers distributed according to an arbitrary pdf, we first produce uniformly distributed numbers, and then use the laws of probability. \nSay we have a desired pdf, \\(p(x)\\), and numbers uniformly distributed from 0 to 1, then \n%\n\\begin{align}\n  \\int_{ - \\infty }^{y(x)} p(\\widetilde{y}) \\dd{\\widetilde{y}} = \\int_{0}^{x} \\dd{\\widetilde{x}} = x \n\\,,\n\\end{align}\n%\nso if we are able to solve this and make \\(y(x)\\) explicit as a function of \\(x\\) we are done! The final expression is given in terms of the cumulative pdf: \n%\n\\begin{align}\n  y = P^{-1} (x)\n\\,.\n\\end{align}\n%\nWe want to generate numbers \\(m\\) between 0.1 and 150 distributed according to \\(p(m) = m^{-\\alpha }\\). \n\nThe cdf is \n%\n\\begin{align}\n\\frac{1}{N}\\int_{0.1}^{m} m^{-\\alpha } \\dd{m} = \\frac{1}{N}\\qty(-\\frac{0.1^{-\\alpha }}{1-\\alpha } +  \\frac{1}{1-\\alpha } m^{1-\\alpha }  )\n\\,,\n\\end{align}\n%\nwhere the normalization is \n%\n\\begin{align}\n  N = \\int_{0.1}^{150} p(m) \\dd{m} = \\frac{1}{1-\\alpha } \\qty(150^{1-\\alpha } - 0.1^{1-\\alpha })\n\\,,\n\\end{align}\n%\ntherefore we have \n%\n\\begin{align}\n  Nx = \\qty(-\\frac{0.1^{-\\alpha }}{1-\\alpha } +  \\frac{1}{1-\\alpha } m^{1-\\alpha }  )\n\\,,\n\\end{align}\n%\nso \n%\n\\begin{align}\n  m = \\qty(\\qty(0.1^{1-\\alpha } +  (1-\\alpha ) Nx))^{1/(1-\\alpha )}\n\\,.\n\\end{align}\n\nThis works; a note of caution: when using a linear axis the histogram (plot of the number ``\\(\\dd{N}\\)'' of counts in a bin of constant width ``\\(\\dd{m}\\)'') looks (up to a proportionality constant) like the probability density function, however if we plot the logarithm of our random variable we get \n%\n\\begin{align}\n  \\dv{N}{ \\log m}  = \\dv{N}{m} \\dv{m}{\\log m} = \\dv{N}{m} m\n\\,,\n\\end{align}\n%\nso if we want somthing which is proportional to the pdf we need to normalize the bin counts by multiplying them by \\(1/m\\).\n\n\\end{document}", "meta": {"hexsha": "3fdb83d062edd808999e00f59a10d87be5d99cf0", "size": 2354, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ap_first_semester/numerical_methods/28nov.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/28nov.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/28nov.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": 32.6944444444, "max_line_length": 301, "alphanum_fraction": 0.6465590484, "num_tokens": 793, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.894789452074398, "lm_q2_score": 0.8459424314825853, "lm_q1q2_score": 0.7569403647527865}}
{"text": "\\section{09/21}\nRecall our definition of conditional expectation\n\\[\\expectation{X \\given Y = y} = \\sum_{x} x \\prob{X = x \\given Y = y}\\]\nThis is a random variable in terms of the dummy variable $y$. Conditional\nexpectation is a powerful tool --- for example, recall the Geometric Random\nVariable given in~\\cref{def:geometricrv}. We previously showed that it has\nexpected value $\\sfrac{1}{p}$. This can similarly be shown using conditional\nexpectation.\n\nLet $X$ denote the number of trials until a success, and define\n\\[Y = \\begin{cases}1 & \\hbox{first trial is success}\\\\\n                   0 & \\hbox{otherwise}\\end{cases}\\]\nThen\n\\begin{align*}\\expectation{X}\n    &= \\expectation{\\expectation{X \\given Y}}\\\\\n    &= \\expectation{X \\given Y = 0}\\prob{Y = 0} + \\expectation{X \\given Y = 1}\\prob{Y = 1}\\\\\n    &= \\expectation{X + 1}(1 - p) + 1 \\cdot p\\\\\n    &= (1 - p)\\expectation{X} + 1\\\\\n    \\shortintertext{solving for $\\expectation{X}$}\\\\\n    &= \\frac{1}{p}\n\\end{align*}\n\nA probability distribution is \\emph{memoryless} if a future event is not\naffected by previous events. This is clearly true for the geometric\ndistribution. \n\nOn the other hand, suppose we toss a coin until we see $k$ \\emph{consecutive}\nheads. This is clearly \\emph{not} memoryless --- once we flip a coin heads, we\nonly need $k - 1$ more consecutive heads, and similarly, once we flip a tail,\nour count resets and we need $k$ more consecutive heads.\n\nLet $N_k$ denote the number of tosses to get $k$ heads in a row, and consider\n$\\expectation{N_k \\given N_{k - 1}}$. We are conditioning on $N_{k - 1}$, hence\nwe have already flipped $k - 1$ consecutive heads. If the next flip is heads, we\nare done. Otherwise, we must flip another $k$ consecutive heads. Thus, we have\n\\begin{align*}\\expectation{N_k \\given N_{k - 1}}\n    &= \\frac{1}{2}\\left(N_{k - 1} + 1\\right) + \\frac{1}{2}\\left(N_{k - 1} + 1 + N_k\\right)\\\\\n    &= N_{k - 1} + 1 + \\frac{1}{2}N_k\n\\end{align*}\nNow, linearity of expectation finishes this exercise:\n\\begin{align*}\\expectation{N_k}\n    &= \\expectation{\\expectation{N_k \\given N_{k - 1}}}\\\\\n    &= \\expectation{N_{k - 1}} + 1 + \\frac{1}{2}\\expectation{N_k}\n\\end{align*}\nwhich yields the recurrence\n\\begin{align*}\n    \\expectation{N_1} &= 2\\\\\n    \\expectation{N_k} &= 2\\expectation{N_{k - 1}} + 2\n\\end{align*}\nThe solution to this is $\\expectation{N_k} = 2^{k + 1} - 2$.\n\n\\subsection{Deviation from Expectation}\nSuppose we have a random variable $X$ with mean $\\mu$. What is the probability\nthat $X$ is ``far away'' from $\\mu$? For example, consider a game where a coin\nis tossed and, should it land heads, the player wins \\$1, otherwise the player\nloses \\$1. Call the player's winnings $X$ and observe that\n\\[\\expectation{X} = \\frac{1}{2}\\cdot 1 + \\frac{1}{2} \\cdot -1 = 0\\]\n\nOn the other hand, suppose the player tosses 10 coins and wins $2^{10} - 1 =\n1023$ dollars when \\emph{all 10} coins come up heads, otherwise the player loses\n\\$1. Then\n\\[\\expectation{X} = \\frac{1}{2^{10}}\\cdot \\left(2^{10} - 1\\right) + \\left(1 - \\frac{1}{2}\\right) \\cdot -1 = 0\\]\nWhile these games have the same expectation, we will later see that they have\nvery different deviation.\n\n\\begin{theorem}{Markov's Inequality}{markovinequality}\n    Let $X$ be any positive-valued random variable. Then\n    \\[\\prob{X \\geq a} \\leq \\frac{\\expectation{X}}{a}\\]\n\\end{theorem}\n\n\\begin{proof}\n    Define the random variable\n    \\[I = \\begin{cases}\n        1 & X \\geq a\\\\\n        0 & \\hbox{otherwise}\n    \\end{cases}\\]\n    and notice that $I \\leq \\sfrac{X}{a}$ and that $\\prob{I = 1} = \\prob{X \\geq\n    a}$. Then\n    \\[\\expectation{I} = \\prob{X \\geq a} \\leq \\frac{\\expectation{X}}{a}\\qedhere\\]\n\\end{proof}\n\n\\begin{corollary}{}{}\n    Let $X$ be any positive-valued random variable. Then\n    \\[\\prob{X \\geq k\\expectation{X}} \\leq \\frac{1}{k}\\]\n\\end{corollary}\n\nFor example, suppose we toss $n$ fair coins and let $X$ count the number of\nheads. We can determine an upper bound on $\\prob{X \\geq \\sfrac{2n}{3}}$ by\nnoting that $\\expectation{X} = \\sfrac{n}{2}$, hence\n\\[\\prob{X \\geq \\frac{2n}{3}} \\leq \\frac{\\sfrac{n}{2}}{\\sfrac{2n}{3}} = \\frac{3}{4}\\]\nThis is a fairly coarse bound, and is not very precise.\n% For example, the above\n% can be computed directly as\n% \\begin{align*}\\prob{X \\geq \\frac{2n}{3}}\n%     &= \\sum_{k = \\sfrac{2n}{3}}^n \\binom{n}{k}\\left(\\frac{1}{2}\\right)^n\\\\\n%     &< \\left(\\frac{1}{2}\\right)^n\\sum_{k = \\sfrac{2n}{3}}^n \\left(\\frac{ne}{k}\\right)^k\n% \\end{align*}\n\n\\subsection{Variance (Second Moment)}\n\\begin{definition}{Variance}{variance}\n    The \\emph{variance} of a random variable $X$, also called its \\emph{second\n    moment}, is defined\n    \\[\\variance{X} = \\expectation{(x - \\expectation{X})^2}\\]\n\\end{definition}\n\\begin{theorem}{}{newvardef}\n    \\[\\variance{X} = \\expectation{X^2} - \\expectation{X}^2\\]\n\\end{theorem}\n\\begin{proof}\n    By definition,\n    \\begin{align*}\\variance{X}\n        &= \\expectation{(X - \\expectation{X})^2}\\\\\n        &= \\expectation{X^2 - 2X\\expectation{X} + \\expectation{X}^2}\\\\\n        &= \\expectation{X^2} - 2\\expectation{X}\\expectation{X} + \\expectation{X}^2\\\\\n        &= \\expectation{X^2} - \\expectation{X}^2\\qedhere\n    \\end{align*}\n\\end{proof}\n\nRecall the definition of a Bernoulli Random Variable --- a single trial with\nprobability of success $p$. Let us write $X = 1$ if our trial is a success, 0\notherwise. Then\n\\begin{align*}\n    \\expectation{X} &= p\\\\\n    \\variance{X} &= \\expectation{X^2} - \\expectation{X}^2\\\\\n                 &= 1^2\\prob{X = 1} - p^2\\\\\n                 &= p - p^2\\\\\n                 &= p(1 - p)\n\\end{align*}\n\nNow, let us consider the variance of a sum of random variables.\n\\begin{theorem}{}{}\n    Let $X$ and $Y$ be random variables. Then\n    \\[\\variance{X + Y} = \\variance{X} + \\variance{Y} + 2\\left(\\expectation{XY} - \\expectation{X}\\expectation{Y}\\right)\\]\n\\end{theorem}\n\\begin{proof}\n    By~\\cref{thm:newvardef}, \n    \\begin{align*}\\variance{X + Y}\n        &= \\expectation{(X + Y)^2} - \\expectation{X + Y}^2\\\\\n        &= \\expectation{X^2 + 2XY + Y^2} - \\left(\\expectation{X} + \\expectation{Y}\\right)^2\\\\\n        &= \\expectation{X^2} + 2\\expectation{XY} + \\expectation{Y^2} - \\expectation{X}^2 - 2\\expectation{X}\\expectation{Y} - \\expectation{Y}^2\\\\\n        &= \\expectation{X^2} - \\expectation{X}^2 + \\expectation{Y^2} - \\expectation{Y}^2 + 2\\left(\\expectation{XY} - \\expectation{X}\\expectation{Y}\\right)\\\\\n        &= \\variance{X} + \\variance{Y} + 2\\left(\\expectation{XY} - \\expectation{X}\\expectation{Y}\\right)\n    \\end{align*}\n\\end{proof}\n\nBefore proceeding, we need to define \\emph{covariance}.\n\\begin{definition}{Covariance}{covariance}\n    Given random variables $X$ and $Y$, the \\emph{covariance} of $X$ and $Y$ is\n    defined\n    \\[\\covariance{X}{Y} = \\expectation{\\left(X - \\expectation{X}\\right)\\left(Y - \\expectation{Y}\\right)}\\]\n\\end{definition}\n\n\\begin{theorem}{}{}\n    Given random variables $X$ and $Y$,\n    \\[\\covariance{X}{Y} = \\expectation{XY} - \\expectation{X}\\expectation{Y}\\]\n\\end{theorem}\n\n\\begin{proof}\n    By definition\n    \\begin{align*}\\covariance{X}{Y}\n        &= \\expectation{\\left(X - \\expectation{X}\\right)\\left(Y - \\expectation{Y}\\right)}\\\\\n        &= \\expectation{XY - \\expectation{X}Y - X\\expectation{Y} + \\expectation{X}\\expectation{Y}}\\\\\n        &= \\expectation{XY} - \\expectation{X}\\expectation{Y} - \\expectation{X}\\expectation{Y} + \\expectation{X}\\expectation{Y}\\\\\n        &= \\expectation{XY} - \\expectation{X}\\expectation{Y}\\qedhere\n    \\end{align*}\n\\end{proof}\n\n\\begin{corollary}{}{}\n    Let $X$ and $Y$ be random variables. Then\n    \\[\\variance{X + Y} = \\variance{X} + \\variance{Y} + 2\\covariance{X}{Y}\\]\n\\end{corollary}\n\n\\begin{theorem}{}{}\n    Let $X$ and $Y$ be \\emph{independent} random variables. Then\n    \\[\\expectation{XY} = \\expectation{X}\\expectation{Y}\\] \n\\end{theorem}\n\n\\begin{proof}\n    By definition\n    \\begin{align*}\\expectation{XY}\n        &= \\sum_{x}\\sum_{y} xy\\prob{X = x \\cap Y = y}\\\\\n        &= \\sum_{x}\\sum_{y} xy\\prob{X = x} \\prob{Y = y}\\\\\n        &= \\sum_{x}x\\prob{X = x}\\sum_{y}y\\prob{Y = y}\\\\\n        &= \\expectation{X}\\expectation{Y}\\qedhere\n    \\end{align*}\n\\end{proof}\n\n\\begin{corollary}{}{}\n    If $X$ and $Y$ are independent, then $\\covariance{X}{Y} = 0$ and\n    \\[\\variance{X + Y} = \\variance{X} + \\variance{Y}\\]\n\\end{corollary}\n\nNow, suppose we toss $n$ independent fair coins and wish to determine the\nvariance on the number of heads. Let $X$ denote the number of heads and let\n$X_i$ indicate if the $i$-th coin is heads. Clearly, $\\variance{X_i} = p(1 -\np)$, and by the previous corollary,\n\\[\\variance{X} = \\sum_{i = 1}^n \\variance{X_i} = np(1 - p)\\]", "meta": {"hexsha": "7ca8912545348a49e68888875c3c423507aac8fc", "size": 8559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/0921.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/0921.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/0921.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": 43.6683673469, "max_line_length": 156, "alphanum_fraction": 0.6366397944, "num_tokens": 3065, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.835483553488848, "lm_q2_score": 0.905989822921759, "lm_q1q2_score": 0.7569395966794034}}
{"text": "\\section{Tabular and Real-time Forecasts without Retraining}\n\\label{tabular_ml_models}\n\nRegarding the structure of the feature matrix for the ML models in Sub-section\n    \\ref{ml_models}, we provide an alternative approach that works without\n    the STL method.\nInstead of decomposing a time series and arranging the resulting\n    seasonally-adjusted time series $a_t$ into a matrix $\\mat{X}$, one can\n    create a matrix with two types of feature columns mapped to the raw\n    observations in $\\vec{y}$:\nWhile the first group of columns takes all observations of the same time of\n    day over a horizon of, for example, one week ($n_h=7$), the second group\n    takes all observations covering a pre-defined time horizon, for example\n    $3$ hours ($n_r=3$ for 60-minute time steps), preceding the time step to\n    be fitted.\nThus, we exploit the two-dimensional structure of time tables as well, and\n    conceptually model historical and recent demand.\nThe alternative feature matrix appears as follows where the first three\n    columns are the historical and the last three the recent demand features:\n\n$$\n\\vec{y}\n=\n\\begin{pmatrix}\n    y_T \\\\\n    y_{T-1} \\\\\n    \\dots \\\\\n    y_{1+n_hH}\n\\end{pmatrix}\n~~~~~\n\\mat{X}\n=\n\\begin{bmatrix}\n    y_{T-H}              & y_{T-2H}       & \\dots & y_{T-n_hH}\n        & y_{T-1}        & y_{T-2}        & \\dots & y_{T-n_r} \\\\\n    y_{T-1-H}            & y_{T-1-2H}     & \\dots & y_{T-1-n_hH}\n        & y_{T-2}        & y_{T-3}        & \\dots & y_{T-n_r-1} \\\\\n    \\dots                & \\dots          & \\dots & \\dots\n        & \\dots          & \\dots          & \\dots & \\dots \\\\\n    y_{1+(n_h-1)H}       & y_{1+(n_h-2)H} & \\dots & y_1\n        & y^*_{1+n_hH-1} & y^*_{1+n_hH-2} & \\dots & y^*_{1+n_hH-n_r}\n\\end{bmatrix}\n$$\n\\\n\nBeing a detail, we note that the recent demand features lying on the end of\n    the previous day are set to $0$, which is shown with the $^*$ notation\n    above.\nThis alignment of the undecomposed order data $y_t$ ensures that the ML\n    models learn the two seasonal patterns independently.\nThe parameters $n_h$ and $n_r$ must be adapted to the data, but we found the\n    above values to work well.\n\nAs such matrices resemble time tables, we refer to them as tabular.\nHowever, we found the ML models with vertical time series to outperform the\n    tabular ML models, which is why we disregarded them in the study.\nThis tabular form could be beneficial for UDPs with a demand that exhibits\n    a weaker seasonality such as a meal delivery platform.\n", "meta": {"hexsha": "dc1e5ae528121117ff9fdbcf0fe38f0f04744f9b", "size": 2507, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/apx/tabular_ml_models.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/apx/tabular_ml_models.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/apx/tabular_ml_models.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": 42.4915254237, "max_line_length": 78, "alphanum_fraction": 0.6593538093, "num_tokens": 712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898279984214, "lm_q2_score": 0.8354835411997897, "lm_q1q2_score": 0.7569395897871095}}
{"text": "\\lab{Algorithms}{Optimization}{Simplex}\n\\label{lab:Simplex}\n\\objective{In this lab, you will write your own implementation of the Simplex method for solving linear optimization problems.}\n\n\n\n\\section*{Simplex}\nIn this lab you will write your own implementation of the Simplex method for solving linear optimization problems. Your function should have the following signature\n\n\\begin{lstlisting}\n>>> x,fval,exit = linprog(c, A, b)\n\\end{lstlisting}\n\nThe function should solve the linear program\n\\begin{align*}\n\t\\text{maximize } & c^T x \\\\\n\t\\text{subject to }  & Ax \\leq b \\\\\n\t\t\t&x \\geq 0\\\\\n\\end{align*}\n\nwhere $c \\in \\mathcal{R}^n$ is a column vector, $b \\in \\mathcal{R}^m$ is a row vector, and $A \\in \\mathcal{R}^{m \\times n}$. The output $x$ is the optimal point and the optimal value is {\\tt fval}. The output {\\tt exit} is one of the following values:\n\\begin{itemize}\n\t\\item 1: Successful execution--you found a solution.\n\t\\item 2: The problem is infeasible.\n\t\\item 3: The problem is unbounded.\n\\end{itemize}\nIf either of the two error events occur, you should return {\\tt None} for the values of {\\tt x} and {\\tt fval}.\n\nYou are free to implement {\\tt linprog} any way you see fit, provided it satisfies the above requirements (you cannot just call an existing lp solver however, and you must use the Simplex method!).\n\n\n\\section*{Code Organization}\nThis is a relatively large program, so you'll want to break it up into function. Below is a list of possible functions.\nHere are some of the functions you might want to use. \\emph{Tableau} will refer to the Simplex tableau in this lab to avoid confusion with a Python dictionary and will be represented by {\\tt T}  in the code.\n\n\n\\begin{lstlisting}\n: T = createtableau(c,A,b)\n: exit = isfeasible(T)\n: exit = simplex(T)\n: i,j,exit = choosepivot(T)\n: pivot(T,i,j)\n\\end{lstlisting}\n\n\nBy breaking the program into so many functions, the entire program is only about 150 lines, including comments.  The {\\tt simplex} function is just a few lines:\n\n\\begin{lstlisting}\n: def simplex(T):\n:    # choose the first pivot: this sets exit to 1 if finished or 3 if unbounded\n:    i, j, exit = choosepivot(T)\n:    while exit == 0:\n:        pivot(T,i,j)\n:        i, j, exit = choosepivot(T)\n\\end{lstlisting}\nThe {\\tt linprog} function is also pretty short, since it just calls other functions and then gets the return value.\n\n\\section*{Tableau Representation}\n\nThe first problem you need to address is how to represent the tableau. We're going to use an approach that might be a little confusing at first but greatly simplifies the pivot operations. We recommend creating an $m + n + 1$ square NumPy matrix, where $m$ is the number of constraints and $n$ is the number of decision variables.  The first row represents the objective function and the first column is for the constants. The remaining columns are the coefficients of the variables. The remaining rows express the value of the variables in terms of a constant and the nonbasic variables. To illustrate this approach, let's consider the following example problem:\n\n\\begin{align*}\n\t\\mbox{maximize}\\qquad\n        &    3x_1 + 2x_2 \\\\\n\t\\mbox{subject to}\\qquad\n        &     x_1 - x_2 \\leq 2 \\\\\n\t\t&\t 3x_1 + x_2 \\leq 5 \\\\\n\t\t&\t 4x_1 + 3x_2 \\leq 7 \\\\\n\t\t&     x_1, x_2 \\geq 0.\n\\end{align*}\n\nThere is no need to distinguish the slack variables from the decision variables, so we will call our slack variables $x_3, x_4,$ and $x_5$. Then our problem becomes\n\\begin{align*}\n\t\\mbox{maximize}\\qquad\n        &    3x_1 + 2x_2 \\\\\n\t\\mbox{subject to}\\qquad\n        &     x_1 - x_2 + x_3 = 2 \\\\\n\t\t&\t 3x_1 + x_2 + x_4 = 5 \\\\\n\t\t&\t 4x_1 + 3x_2 + x_5 = 7 \\\\\n\t\t&     x_1, x_2, x_3, x_4, x_5 \\geq 0.\n\\end{align*}\n\nWe initialize simplex by making the decision variables $x_1, x_2$ nonbasic and the slack variables basic (assuming the origin is feasible, but we will deal with initially infeasible problems shortly). The objective function is already written in terms of the nonbasic variables: $\\zeta = 0 + 3x_1 + 2x_2$. We want to write all the variables in terms of the nonbasic variables. This information we get from the constraints:\n\\[ x_3 = 2 - x_1 + x_2, \\qquad x_4 = 5 - 3x_1 - x_2, \\qquad x_5 = 7 - 4x_1 - 3x_2. \\]\nFor consistency, and simplicity that will be demonstrated later on, we want to express ALL the variables in terms of the nonbasic variables, not just the basic variables, so we add the expressions\n\\[ x_1 = x_1, \\qquad x_2 = x_2 \\]\nto the tableau. This may seem silly, but it makes pivot operations very simple, as we will see. In matrix form, we then have the following initial tableau.\n\n\\[\n\tT = \\begin{bmatrix}\n\t\t0 & 3 & 2 & 0 & 0 & 0 \\\\\n\t\t0 & 1 & 0 & 0 & 0 & 0 \\\\\n\t\t0 & 0 & 1 & 0 & 0 & 0 \\\\\n\t\t2 &-1 & 1 & 0 & 0 & 0 \\\\\n\t\t5 &-3 &-1 & 0 & 0 & 0 \\\\\n\t\t7 &-4 &-3 & 0 & 0 & 0\n\t\\end{bmatrix}.\n\\]\nThe first row is the objective function written as a constant plus a linear combination of the nonbasic variables. The remaining rows are all the variables written as a constant plus a linear combination of the nonbasic variables. The general form of the $T$ matrix is\n\\[ T = \\begin{bmatrix}\n    0 & c^T   & 0 \\\\\n    0 & I_n & 0 \\\\\n    b & -A  & 0\n\\end{bmatrix}, \\]\nwhere $I_n$ is an $n \\times n$ identity matrix. Therefore, your {\\tt createtableau} function might include code like the following\n\n\\begin{lstlisting}\n: m,n = A.shape\n: s = m + n + 1;    % number of variables + number of constraints + 1\n: T = numpy.zeros((s,s))\n: T[0, 1:n+1] = c.T\n: T[s-m:s, 0] = b.squeeze()\n...\n\\end{lstlisting}\n\nNote that you need the squeeze function, built into numpy, to remove single-dimensional entries from the shape of a numpy array. \n\n\\section*{Pivot Operations}\n\nOne of the nice features of the proposed tableau representation is the simplicity of pivot operations. \nWe want to pivot on the column $j$ that has the largest nonzero coefficient in the objective row, $c_j$, or the top row. This variable will become basic after the pivot. The pivot row,  $i$, will be the maximum of \n\\begin{equation}\n\\{\\frac{b_i}{a_{ik}}| i \\text{ is basic }, a_{ik} < 0\\}.\n\\end{equation}\n\nIn our example problem, the first pivot should occur with $x_1$ becoming basic since $c_0 = 3$ and $c_1 = 2$. \nThe table of ratios for our example is \n\n\n\\begin{table}[h]\n\\centering\n\\begin{tabular}{c|c|c|c}\nbasic index i & x3 & x4 & x5\\\\\n\\hline\nratio $\\frac{b_i}{a_{ik}}$ & $\\frac{2}{-1}$&$ \\frac{5}{-3}$ &$ \\frac{7}{-4}$\\\\\n\\end{tabular}\n\\end{table}\nSo $x_4$ becomes nonbasic. In 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 constants). The row corresponding to $x_4$ is\n\\[\n\\begin{bmatrix} 5 &-3 &-1 & 0 & 0 & 0\\end{bmatrix}.\n\\]\nThis represents the equation\n\\[\n\tx_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. A simple method to accomplish this is to rewrite the equation so that we have zero on the left-hand side:\n\\[\n\t0 = 5 - 3x_1 - x_2 - x_4.\n\\]\nNow, we can normalize this equation so that the coefficient of $x_1$ is -1. This is always accomplished by dividing the equation by the negative of the coefficient of $x_1$:\n\\begin{equation}\\label{eq:zero-equation}\n\t0 = \\frac{5}{3} - x_1 - \\frac{1}{3}x_2 - \\frac{1}{3}x_4.\n\\end{equation}\nThis is represented by the vector\n\\[\n\t\\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$. For example, the equation for $x_5$ is\n\\[\n\tx_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. In fact, this works in all of our equations, including those for the objective function and even for $x_1$! Since 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. If we want to do this in a single operation, we use the outer product. We set our new tableau to\n\\[\n\tT = 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. When we compute this sum, we obtain the tableau.\n\\[\n\tT = \\begin{bmatrix}\n\t\t5 &  0 & 1 & 0 & -1 & 0 \\\\\n\t\t5/3 & 0 &-1/3 & 0 &-1/3 & 0 \\\\\n\t\t0 & 0 & 1 & 0 & 0 & 0 \\\\\n\t\t1/3 & 0 & 4/3 & 0 & 1/3 & 0 \\\\\n\t\t0 & 0 & 0 & 0 & 1 & 0 \\\\\n\t\t1/3 & 0 & -5/3 & 0 & 4/3 & 0\n\t\\end{bmatrix}.\n\\]\nYou can check that these are all the correct pivots. Most importantly, $x_2$ and $x_4$ are now our nonbasic variables.\n\n\n\n\\section*{Auxiliary Problems}\n\nWhen one of the entries of $b$ is negative, we need to run an auxiliary problem to find a feasible point. Try adding $x_0$ as the last variable. That way you just need to add a single row and column to your current tableau $T$. 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. 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. We also need to change the objective function to $-x_0$. Let's let $N$ be the matrix for the auxiliary problem. 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\nBefore 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$. Check that the objective function value is 0 when simplex finishes running. If not, your initial problem is infeasible. 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}\nT[1:s,0:s] = N[1:s,0:s]\n\\end{lstlisting}\nThe last thing you need to do is insert your previous objective function. However, you need to re-write it in terms of the current nonbasic variables. Fortunately, $T$ currently contains all of your variables written in terms of the nonbasic variables. You can check (mathematically, or however you want to satisfy yourself) that\n\\begin{lstlisting}\nT[0,0:s] = T[0,0:s]*T\n\\end{lstlisting}\nwill put the objective function into the first row, now written in terms of the new nonbasic variables.\n\n\\section*{Getting Return Values}\n\nWhen you reach a stopping point (all the coefficients in the objective function are nonpositive), all you have to do to get the return values is to set $x = T[0,1:n+1]$, since these contain the current values of each $x_i$ and set $\\mathtt{fval} = T[0,0]$. This is of course assuming you didn't have any error situations (infeasibility or unboundedness), which you should handle separately.\n", "meta": {"hexsha": "a90773b7d8c22ec71cca58f6404d834751713e0f", "size": 11311, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/SimplexLabs/Simplex.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/SimplexLabs/Simplex.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/SimplexLabs/Simplex.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": 54.6425120773, "max_line_length": 726, "alphanum_fraction": 0.7003801609, "num_tokens": 3579, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8824278695464501, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.75691848465977}}
{"text": "\\section{Convergence in Law}%\n\\label{sec:convergence_in_law}\n\n\\begin{definition}\n    $Y_n$ is \\textit{bounded in probability} if for any $\\epsilon>0\\ \\exists K$\n    and $n_0(\\epsilon)$ such that\n    \\begin{equation*}\n        P(|Y_n| > K) < \\epsilon \\text{ for all } n > n_0(\\epsilon).\n    \\end{equation*}\n\\end{definition}\n\n\\begin{definition}[Convergence in Law/Distribution]\n    $Y_n \\convl Y$ if $H_n(x) \\to H(x)$ for all continuity points $x$.\n\\end{definition}\n\n\\begin{thm}\n    If $Y_n \\convl H$ then $Y_n$ is bounded in probability.\n\\end{thm}\n\n\\begin{thm}[Slutsky's Theorem]\n    If $Y_n \\convl Y$, $A_n \\convp a$, and $B_n \\convp b$, then\n    \\begin{equation*}\n        A_n + B_n Y_n \\convl a + b Y.\n    \\end{equation*}\n\\end{thm}\n\n\\begin{corollary}\n    If $Y_n \\convl Y$, $R_n \\convp 0$, and $B_n \\convp 1$, then\n    \\begin{equation*}\n        Y_n + R_n \\convl Y \\text{ and } Y_n / B_n \\convl Y.\n    \\end{equation*}\n\\end{corollary}\n\n\\begin{thm}\n    If $k_n (Y_n - c) \\convl H$ and $k_n \\to \\infty$ then $Y_n \\convp c$.\n\\end{thm}\n\n\\begin{definition}\n    $Y_n \\convp Y$ if $Y_n - Y \\convp 0$.\n\\end{definition}\n\n\\begin{thm}\n    $Y_n \\convp Y \\implies Y_n \\convl Y$ \n\\end{thm}\n", "meta": {"hexsha": "4f6c9e3bf5fbc4f3fb16ffdb4941751a82f91b15", "size": 1174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "statistics/inference/src/02-convergence-in-law.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/02-convergence-in-law.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/02-convergence-in-law.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.0888888889, "max_line_length": 79, "alphanum_fraction": 0.6192504259, "num_tokens": 464, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278633625322, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7569184697300314}}
{"text": "\\section{Metric Spaces and Non-Traditional Databases}\n\\subsection{Overview}\nChávez and Navarro \\cite{chavez2005metric} gives an accurate description of what a non-traditional database\nis, and which problems it intends to solve. To summarise the main idea of the former paper, traditional databases\ncan be seen as engines that answer queries based on the premise that for a certain key there is a certain element\nwith a (possibly unique) relationship. In other words, for a certain query $Q$ with constraints $C$ there is an answer\n$A$ which satisfies $Q \\times C$. In truth, there is nothing wrong with this approach, but it is really complex and\nexpensive to execute queries to which we do not desire a exact answer, because it does not exists or because it is\nresourse-expensive to compute. For instance, if we have a large dataset of points in space and we want to query \nthe ``10 points closest to a point $Q$'' (also known as a $k$-nearest-neighbour query) we need to \nexecute this query for each point in the database computing their individual distances as well, an operation with a cost\nthat is not known beforehand.\n\nThis is an interesting property of multimedia objects which makes the use of exact queries pointless as there are\nno two objects with the same parameters -unless they are exact copies-. A ``real'' world example of this situation is plagiarism\ndetection on multimedia files. Plagiarism\\cite{dictionary_plagiarism}\ncan be hard to detect because in most cases, only a part of the multimedia resembles the original work \\cite{citation_needed}.\nThere are many approaches to this problem, but in music one of the easiest representations is the ``spectrogram''\\cite{citation_needed}\nwhich is a visual representation of the different waveforms involved on a certain audio file. Spectrograms allows the extraction of\nmultiple features from a single audio picece such as scale, BPM (beats per minute), movements, entropy and so on.\n\n\nThe values of these features can be allocated as \\emph{vectors} $\\mathbb{X}$ on a \\emph{metric space} $\\mathbb{U}$ formally defined as follows:\n\nFor a given cartesian pair $\\mathbb{U} = (\\mathbb{X}, d)$ where $\\mathbb{X}$ is a non-empty set of elements and $d$ is a distance function which\noperates over $\\mathbb{X}$ in the following manner $d: \\mathbb{X}\\times\\mathbb{X}\\rightarrow[0,\\infty)$, then it is considered a \\emph{metric space}\nif it satisfies all the following conditions:\n\n\\begin{enumerate}\n\\item{\\textbf{Reflexibility:} $\\forall x_1,x_2 \\in \\mathbb{X}, x_1=x_2 : d(x_1,x_2) = 0$}\n\\item{\\textbf{Positiviness:} $\\forall x_1,x_2 \\in \\mathbb{X} : d(x_1,x_2) \\geq 0$}\n\\item{\\textbf{Simmetry:} $\\forall x_1,x_2 \\in \\mathbb{X} :d(x_1,x_2) = d(x_2,x_1)$}\n\\item{\\textbf{Triangular inequality:} $\\forall x_1,x_2,x_3 \\in \\mathbb{X} :d(x_1,x_2) \\leq d(x_1,x_3) + d(x_3,x_1)$}\n\\end{enumerate}\n\n\\subsection{Metric Range and Nearest Neighbour Queries}\nA typical request is to find all the songs from $\\mathbb{X}$ which have at most $15\\%$ of similarity with our query song $q$. This \nkind of queries are also known as \\emph{Metric Range Queries} on which the result is a subset $\\mathbb{X}'$of $\\mathbb{X}$ which satisfies \n$\\forall x \\in \\mathbb{X}'; q, x_1, x_2 \\in \\mathbb{X} : d(x,d) \\leq  0.15 \\times max(d(x_1,x_2))$, where $0.15 \\times max(d(x_1,x_2))$ represents\nthe 15\\% of the maximum distance between elements in the space. \n\nThere is a good reason behind to choose the maximum distance between elements instead of the maximum distance allowed by our space,\nbecause the maximum distance is infinity. Thus, the relative nature of the space does not allow such queries to be performed. In a strict\nsense, we can generalise metric range queries as follows:\n\n$\\forall x \\in \\mathbb{X}'; q, x_1, x_2 \\in \\mathbb{X} : d(x,d) \\leq d$\n\nNow, for our subset of waveforms if we want to obtain the 10 songs more similar to a certain one we are talking about\na \\emph{Nearest Neighbour query}, on which the dataset is filtered and the result is a subset $\\mathbb{X}'$ of $\\mathbb{X}$ of fixed size $k$ (in \nthis case 10) satisfying $\\forall x_1, x_2... x_n \\in \\mathbb{X}, x_1 < x_2 < .. < x_n ; q \\in \\mathbb{X} : \\mathbb{X}' = {x_1, x_2, .., x_{10} }$.\nFormally this can be defined as $\\forall x_1, x_2... x_n \\in \\mathbb{X}, x_1 < x_2 < .. < x_n; q \\in \\mathbb{X} : \\mathbb{X}' = {x_1, x_2, .., x_k }$.\n\n\\subsection{Dimensionality crux}\nAll the queries previously explained require an evaluation of every element on the index. Thus any improvement on\nthe execution time can only achieved by reducing the dataset to be compared, but this ignores the fact that we do not know\nhow expensive it is to compute the distance between two elements. On high-dimensional spaces, distance computation can be a pain,\ndepending on the function $d$ involved. This dependency on the space dimension is known as the \\emph{dimensionality crux}. There are \nseveral approaches to this problem, such as dimensionaly reduction using techniques like \\emph{Self Organizing Maps}, which work\nunder the premise that the real dimensions of the problem are less than the ones given by the dataset, that it depends on a\nprior treatment of the data, and that it requires the asumption of data loss.\n\n%TODO continue checking\nSo, dimensionality crux can be defined as the tradeoff between the amount of data available for computation (thus, the quality of our results) and\nthe efficiency of the operations performed on this space.\n\n\\subsection{Pivot and Permutant based indices}\nGiven the dimensionality crux, we know that we need to reduce the dataset to compare in order speed up out queries, so, let's change the problem from\nsearching similar songs to a geolocation problem, on which we need to find a point closer to another in the world map. If we were to\nfind Curicó (Chile) without any prior knowledge of where it is, then the only option is to search on every label on the map\nin the hopes of finding the one that we desire to mark. This is known as \\emph{exhaustive search}, which is pretty much like performing a \nlinear scan over the elements of $\\mathbb{X}$.\n\nEverything would be easier if we have an \\emph{index} to search on, a small database that can give us some insight on where\nthe location belongs in order to reduce the problem size even if doesn't give us the exact position. We do not worry about dimensionality crux\nimplcations at this point, since we are not quering the exact solution, rather a good aproximation of it. Now, assuming that we ask\nour index about the location of Curicó it can suggest how far it is from the major cities on the world (\\emph{pivot} cities), this kind of indices\nis known as \\emph{Pivot-based indices}, on which we don't store all the dimensions of the problem, rather than the distance of the element to certain\n\\emph{key elements} of $\\mathbb{X}$. Then by applying the triangular inequality property of metric spaces we can triangulate a reduced\narea on the map in which we know that Curicó is situated.\n\nSo, assuming that we have a set $\\mathbb{P} \\subset \\mathbb{X}$ of randomly chosen pivots, for a range query $(q,r)$ on $\\mathbb{U}$ we do not need to \ncompute the distance of every element of $\\mathbb{X}$ to our query object $q$ since the triangle inequality follows that \n$\\forall x \\in \\mathbb{X} : d(p_i,x) \\leq d(p_i, q) + d(q,x)$ and also that $\\forall x \\in \\mathbb{X} : d(p_i,q) \\leq d(p_i, x) + d(p_i,q)$ thus\nwe can approximate $d(q,x)$ for all elements on $\\mathbb{X}$ only using the reference data given by the closeness of each element to their pivots.\n\nThis approach implies that $|\\mathbb{P}|$ indices must be created in order to store the information needed for a pivot approach but since we can store them\nas sorted arrays of data we perform an approximate binary search on each one of the indices (which can be later retrieved using incremental sorting \ntechniques \\cite{7416566}), thus the search complexity yields $|\\mathbb{P}| \\times log_2(|\\mathbb{X}|)$ for the pivot discard stage plus linear time to retrieve \nall of the results from the resulting sets at the cost of  of extra $|\\mathbb{P}|\\times|\\mathbb{X}|$ space. \n\nTaking into account how space expensive is to generate such indices, another approach is to search for Curicó not using the distances to the major cities\nat all and only using the information given by the closeness order to each one of the pivots generated in the earlier stage. In this case, such cities which\nacts as pivots are know as \\emph{permutants}. Then our approach now is to not store all the indices generated by the pivots, rather to map the entire dataset to another index which condenses this queries\ncreating a single database in which the \\emph{real distance calculations} are replaced by computing the permutation distance between each one of the permutants.\n\nThis kind of indices are known as \\emph{permutation indices} and work under the premise that computing the permutation distance is much simplier than\nto compute the actual distance for every object in $\\mathbb{X}$. Such distances can be computed by using \\emph{vector absolute distance} forumlas such as\n\\emph{Spearman's footrule} and \\emph{Kendall 's tau}.\n\n\\subsection{Correlation coefficients and permutation distance metrics}\nOne of the most well-known formulas for computing the correlation on two datasets is \\emph{Spearman's rho}, which gives an interdependence metric\nbetween two continous random variables. For our case, we expect to have two permutations which represents a ranking of each object (namely, our\nquery object and a test object in the dataset) so, to measure the similarity between those two permutations is a feasible solution at first glance. \nBut there are two problems given by both the nature of the data and it is implementation. First \\emph{Spearman's rho} formula is intended for continous\nrandom variables, as such we always have intermediate objects between each data in the dataset, which is not our case. Second, it is hard to compute\ncontinous variable on a computer, since we do not enjoy o abritrary precision on our current compute machines.\n\nAs such, we use the discrete version of correlation coefficients, which are also known as \\emph{absolute distance} between vectors. In our case\nwe have the following formulas for each one of the before mentioned metrics:\n\nSpearman's Footrule, which measures the total element displacement between the identity permutation:\n$$ F(\\sigma) = \\sum_{i} (i-\\sigma(i))$$\n\nKendall's tau, which measures the total number of pairwise inversions:\n$$ K(\\sigma) = \\sum_{i,j : i>j} (\\sigma(i)<\\sigma(j))$$\n\n\n%put formal definition\n\n\n", "meta": {"hexsha": "d7625009a53f46cceacca47c6d9a1ab83ba1837a", "size": 10601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "memoria/first_course/memoria/chapters/required_knowledge/metric_spaces.tex", "max_stars_repo_name": "honorpeter/fpga_index_accelerator", "max_stars_repo_head_hexsha": "c09d222d3ad55d6bb354dee8aff97a4f519df89d", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-05T08:32:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-05T08:32:10.000Z", "max_issues_repo_path": "memoria/first_course/memoria/chapters/required_knowledge/metric_spaces.tex", "max_issues_repo_name": "honorpeter/fpga_index_accelerator", "max_issues_repo_head_hexsha": "c09d222d3ad55d6bb354dee8aff97a4f519df89d", "max_issues_repo_licenses": ["MIT"], "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/first_course/memoria/chapters/required_knowledge/metric_spaces.tex", "max_forks_repo_name": "honorpeter/fpga_index_accelerator", "max_forks_repo_head_hexsha": "c09d222d3ad55d6bb354dee8aff97a4f519df89d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-04-09T02:38:27.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-09T02:38:27.000Z", "avg_line_length": 87.6115702479, "max_line_length": 203, "alphanum_fraction": 0.7674747665, "num_tokens": 2741, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9230391643039738, "lm_q2_score": 0.8198933425148213, "lm_q1q2_score": 0.7567936656932723}}
{"text": "\\section{Analytical solution to~\\eqref{equ:noisy_min}}\n\\label{sec:opt}\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", "meta": {"hexsha": "03ea281b4ad424648e7010430650760015e14ee6", "size": 710, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "opt.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": "opt.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": "opt.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": 177.5, "max_line_length": 638, "alphanum_fraction": 0.7056338028, "num_tokens": 239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.951142217223021, "lm_q2_score": 0.7956580976404297, "lm_q1q2_score": 0.7567840071411692}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% CS624: Analysis of Algorithms\n% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>\n% Creative Commons Attribution-ShareAlike 4.0 International License\n% More info: https://github.com/ghorbanzade/beacon\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\\section*{Question 2}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item Show how to sort a set of $n$ numbers in $\\mathcal{O}(n\\log n)$ time using only the following binary search tree operations: \\textsc{Minimum}, \\textsc{Insert} and \\textsc{Sucessor}.\nYou may assume each operation takes $\\mathcal{O}(\\log n)$ time.\n\n\\item Let $b_n$ be the number of all possible binary search trees with $n$ nodes.\nTrivially $b_0$ is $1$.\nShow that $b_n = \\sum_{k=0}^{n-1} b_k b_{n-1-k}$.\n\\end{enumerate}\n\n\\subsection*{Solution}\n\n\\begin{enumerate}[label=(\\alph*)]\n\\item The algorithm to sort the set of $n$ numbers is shown in Algorithm \\ref{alg1}.\n\nFirst we can use the insert operation $n$ times to build a binary search tree out of $n$ elements.\nThis will have $n\\mathcal{O}(\\log n)$ runtime cost.\nThen we once use the minimum operation to obtain and print the element with minimum value.\nAlgorithm will continue by calling the successor operation $n-1$ times such that all elements are printed.\nAs one call to minimum and $n-1$ calls to successor operation has been made, the runtime will be $\\mathcal{O}(n\\log n)$.\nTherefore, the entire sorting cost is $2n\\mathcal{O}(\\log n) = \\mathcal{O}(n\\log n)$.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\For {$i \\leftarrow 1 : n$}\n\\State \\textsc{Insert}($A[i]$)\n\\EndFor\n\\State $s \\leftarrow$ \\textsc{Minimum}($A$)\n\\State print $s$\n\\For {$i \\leftarrow 2 : n$}\n\\State $s \\leftarrow$ \\textsc{Successor}($A, s$)\n\\State print $s$\n\\EndFor\n\\end{algorithmic}\n\\caption{Sort($A$)}\\label{alg1}\n\\end{algorithm}\n\n\\item With $n$ nodes, we can convert the problem of finding $b_n$ possible binary search trees to finding a root for the tree, a left subtree and a right subtree.\nSuppose there are $k$ elements in the left subtree where $0 \\leq k \\leq n-1$.\n\nLet $b_k$ be defined as number of binary search trees that can be constructed with $k$ elements.\nAs we still have $n-k-1$ elements with which to construct a right subtree, each choice of $k$ will give $b_k b_{n-1-k}$ possible binary search trees.\nThus, total number of binary search trees that can be constructed with $n$ elements will be as shown in Eq. \\ref{eq21}.\n\n\\begin{equation}\nb_n = \\sum_{k=0}^{n-1} b_k b_{n-1-k}\n\\label{eq21}\n\\end{equation}\n\n\\end{enumerate}\n", "meta": {"hexsha": "30cee4f5a619ae38a4bf49104588c47b7738f08d", "size": 2589, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs624-2015s/src/tex/m02/m02q02.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/m02q02.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/m02q02.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 43.8813559322, "max_line_length": 187, "alphanum_fraction": 0.686365392, "num_tokens": 769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711870587667, "lm_q2_score": 0.8902942377652497, "lm_q1q2_score": 0.7567244501049092}}
{"text": "\\section{Brief primer on tensors}\\label{sec:tensor}\nThe material here is based on \\cite{lee-book-2000,dullemond-1991-tensor}.\n\n\nLet \\(V\\) be an \\(n\\)-dimensional vector space over the reals. A {\\em covector} on \\(V\\) is a real-valued linear functional \\(\\omega:V\\rightarrow \\Re\\). The space of all covectors is itself a real vector space  under pointwise addition and multiplication. It is written as \\(V^{\\star}\\) and called the {\\em dual space} to \\(V\\). \n\n\\begin{proposition}[\\cite{lee-book-2000} Proposition 4.1] For \\(V\\) an \\(n\\)-dimensional vector space and \\(E_1, \\ldots, E_n\\) a basis for \\(V\\), the covectors \\(\\epsilon^1, \\ldots, \\epsilon^n\\), defined by:\n  \\[\n  \\epsilon^i(E_j) = \\delta^i_j = \\left\\{\n  \\begin{array}{ll}\n    1 & \\mbox{if \\(i =j\\)} \\\\\n    0 & \\mbox{if \\(i\\not=j\\)}\n    \\end{array}\\right.\n    \\]\n\\noindent form a basis for \\(V^{\\star}\\), called the {\\em dual basis} to \\((E_i)\\).   \n\\end{proposition}\n%% TODO: Define canonical isomorphism.\nNote that it follows that the dimensionality of \\(V^{\\star}\\) is the same as that of \\(V\\). It is also the case that \\(V^{\\star\\star}\\) is canonically isomorphic to \\(V\\). \n\n\n\\begin{definition}[(Covariant) Tensor] For $V$ a finite-dimensional real vector space, a {\\em covariant tensor} of rank $k$ over $V$ is a real-valued multilinear function of $k$ elements of $V$.\n\\end{definition}\n\nBy convention, a $0$-tensor is just a real number. Define $T^k(V)$ to be the set of all tensors of rank $k$ over $V$. $T^k(V)$ is a vector space under point-wise addition and scalar multiplication. Specifically:\n\\[\n\\begin{array}{l}\n  (\\alpha T)(X_1, \\ldots, X_k) = \\alpha(T(X_1, \\ldots, X_k))\\\\\n  (S+T)(X_1, \\ldots, X_k)=S(X_1, \\ldots, X_K) + T(X_1, \\ldots, X_k)\n\\end{array}\n\\]\n\nGiven two tensors \\(S \\in T^k(V), T \\in T^l(V)\\) (for \\(V\\) a finite-dimensional real vector space), the map:\n\\[ S \\otimes T \\defeq \\lambda X_1, \\ldots, X_{k+l}.S(X_1,\\ldots, X_k)T(X_{k+1}, \\ldots, X_{k+l})\\]\n\\noindent is a covariant \\((k+l)\\)-tensor, called the {\\em tensor product} of \\(S\\) and \\(T\\). More generally, given any two vector spaces \\(A,B\\), a canonical tensor product \\(A\\otimes B\\) can be defined on them \\cite[P.~175]{lee-book-2000}. it consists of linear combinations of objects of the form \\(a\\otimes b\\) for \\(a\\in A, b\\in B\\) which is defined in such a way that \\(a\\otimes b\\) depends bilinearly on \\(a\\) and \\(b\\). \n\n\\begin{proposition}[\\cite{lee-book-2000}, Proposition 8.2] Let \\(V\\) be an \\(n\\)-dimensional vector space with basis \\((E_i)\\), and let \\(V^{\\star}\\) have basis \\(\\epsilon^i\\). The set of all \\(k\\)-tensors of the form \\(\\epsilon^{i_1}\\otimes \\ldots \\otimes\\epsilon^{i_k}\\) for \\(1 \\leq i_1, \\ldots, i_k \\leq n\\) is a basis for \\(T^k(V)\\).\n\\end{proposition}\n\nThus the dimension of \\(T^k(V)\\) is \\(n^k\\). We can represent such a tensor extensionally, with a value $r\\in \\Re$ for each of the \\(n^k\\) basis vectors \\(\\epsilon_{i_1} \\otimes \\ldots \\otimes \\epsilon_{i_k}\\), for \\(1 \\leq i_1, \\ldots, i_k \\leq n\\). Note while it is tempting to consider such a collection of numbers as a \\(k\\)-dimensional array of numbers, care must be taken because the operation to be performed on this array are described by tensor contraction rather than matrix multiplication, as we shall see below. \n\n%The output of the tensor for any value \\(v_1\\otimes \\ldots \\otimes v_k\\) is obtained by an appropriate linear combination of the values on the basis vectors.\n\nMore abstractly:\n\\begin{proposition}[\\cite{lee-book-2000}, Corollary 8.5]\\label{prop:tensors-are-tensor-products} For \\(V\\) an \\(n\\)-dimensional real vector space, the space \\(T^k(V)\\) of covariant \\(k\\)-tensors on \\(V\\) is canonically isomorphic to the \\(k\\)-fold tensor product \\(V^{\\star}\\otimes \\ldots \\otimes V^{\\star}\\). \n\\end{proposition}\n\n%%If the transformation matrix of an index is the inverse matrix of the basis transformation, then the index is called contravariant and is traditionally denoted with an upper index (superscript). If the transformation matrix of an index is the basis transformation itself, then the index is called covariant and is denoted with a lower index (subscript).\n\nThis permits us to generalize the notion of tensors to {\\em mixed rank} tensors. For \\(V\\) an \\(n\\)-dimensional vector space, the space of {\\em contravariant tensors} of rank \\(k\\) is defined to be:\n\\[\nT_k(V) = V \\otimes \\ldots \\otimes V \\]\n(with \\(k\\) copies). Because of the isomorphism between \\(V\\) and \\(V^{\\star\\star}\\), and Proposition~\\ref{prop:tensors-are-tensor-products}, an element of \\(T_k(V)\\) can be identified with a multilinear function in \\(V^{\\star} \\times \\ldots \\times V^{\\star} \\rightarrow \\Re$. This allows us to define, for any \\(k, l \\in \\mathbb{N}\\) the space of {\\em mixed tensors} as:\n\\[T^k_l(V) = V^{\\star}\\otimes \\ldots V^{\\star}\\otimes V\\otimes \\ldots \\otimes V\\]\n\\noindent where the first product is taken \\(k\\) times and the second \\(l\\) times.  Thus \\(T^k_l(V)\\), the space of \\((k,l)\\)-tensors, is the space of real-valued multilinear functions of \\(k\\) vectors and \\(l\\) covectors. \n\nMixed-mode tensors  are written with upper indices for its contra-variant dimensions, and lower indices for its covariant dimensions. For instance, a matrix \\(M\\) is a \\((1,1)\\)-tensor, and we can write \\(M_i^j\\) to make its indices explicit. This is the same as \\(M_j^k\\) -- the identity of indices does not matter. Also, basis vectors will be written with a lower index, and components of a vector with respect to this basis with an upper index.\n\\subsection{Tensor Contraction}\\label{sec:summation-convention}\nIn the following we shall adopt the {\\em Einstein summation convention}:\n\\begin{quotation}\n  If the same index name appears twice in any term, once as an upper index and once as a lower index, that term is understood to be summed over all possible values of that index, generally from \\(1\\) to the dimension of the space in question. \n\\end{quotation}\nThus for instance we can rewrite:\n\\[\n\\begin{array}{lcl}\n  \\Sigma_{\\nu=1}^n A_{\\mu\\nu}v_{\\nu} & \\rightarrow &   A_{\\mu\\nu}v_{\\nu}\\\\\n  \\Sigma_{\\beta=1}^n \\Sigma_{\\gamma=1}^n A _{\\alpha \\beta}B_{\\beta \\gamma}C_{\\gamma \\delta} & \\rightarrow & A_{\\alpha \\beta}B_{\\beta \\gamma}C_{\\gamma \\delta}\n\\end{array}\n\\]\n\nThe {\\em contraction} of a tensor is obtained by setting unlike indices equal, thus indicating a summation per the convention above. The result of contracting a \\((k,l)\\)-tensor  is a \\((k-1,l-1)\\) tensor.\n\nThe contraction operation is invariant under coordinate changes.\n\n\n\\subsection{Working with tensors}\n  \nTensors can be ``partially'' evaluated. For \\(T\\) a tensor of rank \\(k\\) representing a predicate \\(p\\), and \\(a\\) a vector representing the value of argument \\(i\\), \\(T^{1\\ldots k}a_i\\) represents the predicate \\(\\lambda x_1, \\ldots, x_{i-1},x_{i+1},\\ldots x_k. p(x_1, \\ldots, x_{i-1}, a, x_{i+1}, \\ldots, x_k)\\). It can be thought of as {\\em contracting} \\(T\\) and \\(a\\) on index \\(i\\).\n  \n\n\\begin{example}\\label{ex:tc-1}\n  Consider the tensor representation of the boolean polynomial \\(p(x,y) = x(1-y)\\). Because \\(x,y\\in \\{0,1\\}\\) with the two values independent of each other, we will embed them in the two dimensional vector space \\(U=\\{0,1\\}^2\\), with ``one hot'' basis vectors \\(\\epsilon_1=(1,0)\\) and \\(\\epsilon_2=(0,1)\\) representing \\(0\\) and \\(1\\) respectively. Now the tensor \\(T^{1,2}\\) representing the binary predicate \\(\\lambda x,y. p(x,y)\\) is represented by the table:\n  \\[\n  \\begin{array}{l}\n    T(\\epsilon_1,\\epsilon_1)=0\\\\\n    T(\\epsilon_1,\\epsilon_2)=0\\\\\n    T(\\epsilon_2,\\epsilon_1)=1\\\\\n    T(\\epsilon_2,\\epsilon_2)=0\n  \\end{array}\n  \\]\n  We can use this representation to evaluate the predicate at different points through tensor contraction. For instance, \\(p(0,1)\\) is given, for \\(a=\\epsilon_1,b=\\epsilon_2\\) by \\(T^{1,2}a_1 b_2\\), which through the Einstein convention expands out to:\\footnote{Recall that for \\(x\\) a vector \\(x^j\\) represents its \\(j\\)th coordinate.}\n  \\[\\begin{array}{ll}\n  T^{1,2}a_1 b_2 &= \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 T(\\epsilon_i,\\epsilon_j)a_1^ib_2^j \\\\\n  &= T(\\epsilon_1,\\epsilon_1)*1*0 + T(\\epsilon_1,\\epsilon_2)*1*1 +\n  T(\\epsilon_2,\\epsilon_1)*0*0 + T(\\epsilon_2,\\epsilon_2)*0*1 \\\\\n  & =T(\\epsilon_1,\\epsilon_2)\\\\\n  & = 0\n  \\end{array}\n  \\]\n\\end{example}\n\nMore generally, we can compute tensor contraction symbolically. Let \\(x,y\\) be  unknown vectors in \\(U\\), and let \\(S\\) be a rank-2 tensor over \\(U\\). Then if \\(S\\) represents the predicate \\(q\\), the predication \\(q(x,y)\\) is represented by \\(S^{1,2}x_1 y_2\\) which expands out to:\n\\[\\begin{array}{ll}\n  [S(x,y)]&\\defeq  S^{1,2}x_1 y_2\\\\\n  & = \\Sigma_{j=1}^2 \\Sigma_{i=1}^2 S(\\epsilon_i,\\epsilon_j)x_1^iy_2^j \\\\\n  & =S(\\epsilon_1,\\epsilon_1)x^1y^1 + S(\\epsilon_1,\\epsilon_2)x^1y^2 +\n      S(\\epsilon_2,\\epsilon_1)x^2y^1 + S(\\epsilon_2,\\epsilon_2)x^2y^2 \\\\\n  \\end{array}\n  \\]\n\n  \\begin{example}[Example~\\ref{ex:tc-1} contd]\n    Taking the value of \\(S\\) above to be \\(T\\), we get:\n    \\[\\begin{array}{ll}    \n        [T(x,y)] & = x^2y^1\\\\\n         & = [x=1][y=0]\n    \\end{array}\n    \\]\n  \\end{example}\n\nThe representation of an arbitrary $k$-are predicate is similar, a tensor \\(T^k\\) represented by \\(n^k\\) numbers, for \\(U=\\{0,1\\}^n\\). \n", "meta": {"hexsha": "06cf6fe1c947cf3425daa42ae641e88efad86809", "size": 9174, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "appendix-tensor-1.tex", "max_stars_repo_name": "saraswat/logic-nn", "max_stars_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_stars_repo_licenses": ["CECILL-B"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2016-05-13T15:55:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-11T12:28:48.000Z", "max_issues_repo_path": "appendix-tensor-1.tex", "max_issues_repo_name": "saraswat/logic-nn", "max_issues_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "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": "appendix-tensor-1.tex", "max_forks_repo_name": "saraswat/logic-nn", "max_forks_repo_head_hexsha": "79af16ead7d86e4eca0b3cfc88d1c3379485088f", "max_forks_repo_licenses": ["CECILL-B"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 76.45, "max_line_length": 524, "alphanum_fraction": 0.6793110966, "num_tokens": 2993, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.84997116805678, "lm_q2_score": 0.8902942326713409, "lm_q1q2_score": 0.7567244288578743}}
{"text": "\\subsection{Features}\n\\label{sec:methods_features}\n\n\nIn this section, all the features of the model are introduced. We will present\nunivariate and bivariate analysis of the features as well as different\ntechniques to transform them, in particular fractional differentiation.\n\nWhen working with inference models, features should be stationary. Common\nprocedures to features like prices involve integer differentiation to end up\nworking with price returns instead. The latter would remove entirely the price\nseries memory which is required by the model to effectively predict the output.\nOther methods involve applying power transformations such as logarithms, square\nroots or box-cox transformations. We are not interested in those for price series.\nThey will drastically affect scales and might collapse movements around the trend\nwhile preserving the trend.\n\nIn \\cite{frac_diff_paper} the fractional differentiation method was introduced,\nand Lopez de Prado takes the method and explains the model in chapter 5 of\n\\cite{lopez_de_prado}. I will present the mathematical model and explain the\nalgorithm in what follows.\n\nLet $B$ be a backshift operator, i.e. delay operator, to be applied to a matrix \nof real valued features $X_{t}$ such that $B^k X_t = X_{t-k}$. Also, we can \nexpress the positive integer powers of a binomial as $(x+y)^n = \\sum_{k=0}^n {n \\choose k} x^k y^{n-k}$.\nWhen considering real valued exponents, combinatorial number ${n \\choose k}$\nbecomes (after substitution of $n$ an integer by $d$ a real number) ${d \\choose k} = \\frac{d (d-1) ... (d-k+1)}{k!}$\nwhich coincides with the integer formula. Thus,\n\n\\begin{equation}\n  \\label{eqn:binomial_expantion_frac_power}\n  (x+y)^d = \\sum_{k=0}^{\\infty} {d \\choose k} x^k y^{d-k}\n\\end{equation}\n\nEquation \\ref{eqn:binomial_expantion_frac_power} presents an infinite series, a\nkey difference with respect to the integer counterpart. If we replace $x$ by $1$\nand $y$ by $-B$, the backshift operator, one can write from \\ref{eqn:binomial_expantion_frac_power}:\n\n\\[(1-B)^d = \\sum_{k=0}^{\\infty} {d \\choose k} (-B)^k \\]\n\n\\[(1-B)^d = \\sum_{k=0}^{\\infty} \\frac{\\prod_{i=0}^{k-1}(d-i)}{k!} (-B)^k \\]\n\n\\begin{equation}\n  \\label{eqn:binomial_expantion_diff_operator}\n  (1-B)^d = 1 - dB + \\frac{d(d-1)}{2!}B^2 - \\frac{d(d-1)(d-2)}{3!}B^3 + ...\n\\end{equation}\n\nEquation \\ref{eqn:binomial_expantion_diff_operator} presents the foundation of\nthe fractional differentiation method. If one could find the value of $d$ such\nthat a series $X$ gets differentiated and becomes stationary while preserving\nas much memory as possible a later model would be able to exploit that memory to\npredict the output. In particular, when the value of $d$ ends up being less than 1.\nEquation \\ref{eqn:binomial_expantion_diff_operator} also\npresents a problem, it is a infinite series when $d$ is noninteger which makes\nthe operation to be non exact for the general case due to the impossibility of\napplying infinite multiplications and sums. Lopez de Prado proposes a solution\nfor both issues.\n\nA fractionally differentiated series $X$ can be expressed for a given $d$ as: \n\n\\[ X_t^d = \\sum_{k=0}^{\\infty} w_k X_{t-k} \\]\n\nThe vector $w$ of weights in the above equation follows:\n\n\\begin{equation}\n  \\label{eqn:ffd_weights}\n\tw = {1, -d, \\frac{d(d-1)}{2!}, -\\frac{d(d-1)(d-2)}{3!}, ..., (-1)^k \\prod_{i=0}^{k-1} \\frac{(d-i)}{k!}} \n\\end{equation}\n\nOne can derive by inspection of equation \\ref{eqn:ffd_weights} a generative and\nrecursive expression for each item in the series:\n\n\\begin{equation}\n  \\label{eqn:ffd_weights_generative}\n  w_k = -w_{k-1} \\frac{d-k+1}{k}\n\\end{equation}\n\nEquation \\ref{eqn:ffd_weights_generative} is easy to implement as a programming\nfunction which is ideal for this application. It is also interesting to evaluate\nthe tendency of $w_k$ as $k$ tends to infinite, see figure \\ref{fig:w_k_vs_k}.\n\n\\begin{figure}[!htb]\n    \\centering\n    \\includegraphics[width=\\textwidth]{methods/images/weights_vs_k.png}\n    \\caption{Weight values vs. $k$ for different $d$ values.}\n    \\label{fig:w_k_vs_k}\n\\end{figure}\n\nAs it can be seen in figure \\ref{fig:w_k_vs_k}, coefficients tend to zero as $k$\nincreases. It can also be proved the convergence of coefficients $w_k$. Let's\nanalyze the following when $k > d$ and $w_{k-1} \\ne 0$:\n\n\\[|\\frac{w_k}{w_{k-1}}| = |\\frac{d-k+1}{k}| < 1 \\]\n\nwhat makes $|w_k| < |w_{k-1}|$ leading to $\\lim_{k \\to \\infty} w_k = 0$.\n\nWhen implementing fractional differentiation on a real time series, one has two\noptions:\n\n\\begin{enumerate}\n  \\item Adjust the length of $w_k$ vector by weight loss with a certain\n        threshold.\n  \\item Work with a fixed number of coefficients.\n\\end{enumerate}\n\nOption 1 requires the operation to compute the size of $w_k$ vector to account\nfor weight loss given a certain threshold. Weight loss cam be computed:\n\n\\begin{equation}\n  \\lambda_l = \\frac{\\sum_{j=T-l}^{T}|w_j|}{\\sum_{i=0}^{T-1}|w_i|}\n\\end{equation}\n\nwhere:\n\n\\begin{itemize}\n  \\item $T$ is the length of the time series,\n  \\item $l$ is the index of the sample from the end where the fractional\n        differentiation occurs.\n  \\item $\\lambda_l$ the weight loss at $l$ index\n\\end{itemize}\n\nOne should discard all samples whose $\\lambda_l < \\tau$ and $\\tau$ is the\nthreshold. As $d \\to 0$, the energy of the weights decreases leading to more\nweight loss and more discarded samples.\n\nOption 2 comes with the simplicity of having always the same vector of\ncoefficients $w_k$ such that $|w_k| > \\tau$ and $\\tau$ is a user defined\nthreshold. It comes with the advantage of having no drift as option 1 and just\nneeds to drop $l$ samples at the beginning, being $l$ the value of $l$ that\nmakes $w_k$ less or equal to $\\tau$. In this thesis, option 2 is used.\n\nSo far, how to compute the weights vector was explained. Now, we just need to\naddress the value of $d$. $X_t$ might be stationary already which leads to\n$d^* = 0$ with $d^*$ the value of $d$ that preserves most memory making the \ntime series stationary. When $X_t$ has a \\emph{unit root} (see chapter 15 of \\cite{time_series_analysis}),\n$0 \\le d^* \\leq 1$. And when $X_t$ exhibits an explosive (bubble) behavior,\n$d^* > 1$. Unit roots can be tested with Dickey Fuller hypothesis test\n(see chapter 17 of \\cite{time_series_analysis}). The null hypothesis of the test claims the series has a unit root.\nAfter determining a certain confidence level one can derive an \\emph{optimum}\n$d^*$ by:\n\n\\begin{enumerate}\n  \\item Define a vector of $d$ values in range of 0 to 1.\n  \\item For each value of $d$:\n  \\begin{enumerate}\n    \\item Fractionally differentiate $X_t$ with $d$ given a certain amount of\n          weights. Obtain $X_t^d$.\n    \\item Compute the Dickey Fuller statistic, ADF, for $X_t^d$.\n    \\item Compute the p-value of the test.\n  \\end{enumerate}\n  \\item Choose $d^*$ that yields the maximum p-value between all p-values that\n        are less or equal to the confidence level.\n\\end{enumerate}\n\nThis process has two flaws:\n\n\\begin{itemize}\n  \\item It is computationally time complex. Each time we apply the fractional\n        differentiation, we are processing a $O(n^2)$ algorithm. Computing the\n        ADF of the differentiated series requires a differentiation and model\n        estimation which yields at least another $O(n^2)$ process. Finally, we\n        iterate through a vector of $d$ adding another dimension.\n  \\item \\emph{Optimum} $d$ is subject to the granularity of the $d$ vector of\n        samples. The smaller the step, the more information one could preserve\n        in the final time series, but the more iterations are required which\n        impacts directly in the aforementioned item.\n\\end{itemize}\n\nRegardless, all features that expose non-stationary characteristics could be\ntransformed and stabilized while preserving memory.", "meta": {"hexsha": "db7df641a39ad1062eef1c642c479f7a3f2fca6e", "size": 7779, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/methods/features/introduction.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/introduction.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/introduction.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": 45.7588235294, "max_line_length": 116, "alphanum_fraction": 0.7322277928, "num_tokens": 2194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9032942067038784, "lm_q2_score": 0.8376199673867852, "lm_q1q2_score": 0.7566172639599746}}
{"text": "\\section{Principle of Strong Induction}\n\nHere is the Principle of Strong Induction:\n\n\\begin{theorem}\nSuppose $P(n)$ is a proposition, and that the following statements hold:\n\\begin{itemize}\n    \\item $P(0)$ is true,\n    \\item If $P(i)$ is true for all $0 \\leq i \\leq n$, then we can prove that $P(n + 1)$ is true.\n\\end{itemize}\nThen $P(n)$ holds for all $n \\in \\mathbb{N}$.\n\\end{theorem}\n\\begin{proof}\nIn fact, this theorem actually directly follows from the Principle of Weak Induction. To see this clearly, define the proposition $Q(n)$ to be equivalent to the claim that $P(i)$ is true for $0 \\leq i \\leq n$. Then by the hypotheses:\n\\begin{itemize}\n\t\\item $Q(0)$ is true,\n\t\\item If $Q(n)$ is true, then $P(n + 1)$ is true. This essentially means that if $Q(n)$ is true, then $P(i)$ is true for all $0 \\leq i \\leq n + 1$, implying that $Q(n + 1)$ is true.\n\\end{itemize}\n\nSo by the Principle of Weak Induction $Q(n)$ is true for all natural numbers $n$, which implies that $P(n)$ is true for all natural numbers $n$ as well.\n\\end{proof}\n\n%note: define inductive hypothesis in weak_ind.tex\n\nThe Principle of Strong Induction is seemingly ``stronger'' than the Principle of Weak Induction. The reason behind this is because of the nature of the theorem's ``induction hypothesis'', which assumes the truth of $P(i)$ for all $i$ up to a value $n$. We may apply this principle to prove certain statements where in order to complete the inductive step assumptions about more than just the previous steps are needed. Here is a particular example of this. \n\n\\section{Exercises}\n\\begin{enumerate}\n    \\item \\input{Ch5/2_ex/problem_1}\n    \\item \\input{Ch5/2_ex/problem_2}\n    \\item \\input{Ch5/2_ex/problem_3}\n    \\item \\input{Ch5/2_ex/problem_4}\n    \\item \\input{Ch5/2_ex/problem_5}\n\\end{enumerate}", "meta": {"hexsha": "84134b7b78048e405b6430d8150a1f7c6f66a862", "size": 1789, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch5/strong_ind.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": "Ch5/strong_ind.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": "Ch5/strong_ind.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": 52.6176470588, "max_line_length": 458, "alphanum_fraction": 0.7160424818, "num_tokens": 526, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8840392725805822, "lm_q2_score": 0.8558511469672594, "lm_q1q2_score": 0.756606025402193}}
{"text": "\\subsection{Lines}\r\n\\noindent\r\nA straight line is probably the simplest 3D VVF. We can form any straight line using a point that the line passes through and the direction vector of the line.\r\nLetting $P$ be the point and $\\vec{v}$ be the direction, a straight line has the form $\\vec{r}(t) = \\vec{P}+t\\vec{v}$, where $\\vec{P}$ is the vector with components the same as $P$.\r\nThe function's output starts at $\\vec{P}$ when $t=0$ and moves in the direction of $\\vec{v}$ as $t$ increases.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.45\\textwidth]{./Images/vectorValuedFunctions/VectorLine.png}\r\n\t\\caption{A line can be formed by a single point and a direction vector or two points.}\r\n\\end{figure}\r\n\r\n\\noindent\r\nA line can also be formed using two points.\r\nTo find the equation of the line in this case, let $\\vec{v}$ be the vector connecting the two points, and let $\\vec{P}$ be a vector point from the origin to one of the two points.\r\nWe now have an origin point and direction and can write our function as\r\n\\begin{equation*}\r\n\t\\vec{r}(t) = \\vec{P_0} + t\\left(\\vec{P_1} - \\vec{P_0}\\right),\r\n\\end{equation*}\r\nwhere $P_0$ and $P_1$ are the two points on the line.", "meta": {"hexsha": "3749d7fa167448a7078121e385111fa2aa526a87", "size": 1177, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/lines.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/vectorValuedFunctions/lines.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/vectorValuedFunctions/lines.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": 58.85, "max_line_length": 182, "alphanum_fraction": 0.7162276975, "num_tokens": 351, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308147331956, "lm_q2_score": 0.8104789086703225, "lm_q1q2_score": 0.7565259880442103}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Suppose $V$ and $W$ are vector spaces, $T,S:V\\to W$ and $R,Q:W\\to W$\n  are linear transformations, and $k$ is a scalar. Which of the\n  following equalities are valid?\n  \\begin{enumerate}\n  \\item $R\\circ (T+kS) = R\\circ T + kR \\circ S$.\n  \\item $(R+Q)\\circ (R+Q) = R\\circ R + 2R\\circ Q + Q\\circ Q$.\n  \\item $(R+Q)\\circ (T+S) = R\\circ T + R\\circ S + Q\\circ T + Q\\circ S$.\n  \\item If $T$, $S$, and $T+S$ are invertible, then $(T+S)^{-1} =\n    T^{-1} + S^{-1}$.\n  \\end{enumerate}\n  \\begin{sol}\n    Yes, no, yes, no.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Finish the proof of\n  Proposition~\\ref{prop:addition-linear-transformations}, i.e., prove\n  that if $T:V\\to W$ is a linear transformation and $k$ a scalar, then\n  $kT:V\\to W$ is a linear transformation.\n\\end{ex}\n", "meta": {"hexsha": "b29b08fc26fd987e59cd44183dc0953fee345226", "size": 794, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/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/exercises/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/exercises/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": 31.76, "max_line_length": 71, "alphanum_fraction": 0.6083123426, "num_tokens": 311, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.939024825960626, "lm_q2_score": 0.8056321796478255, "lm_q1q2_score": 0.7565086172820791}}
{"text": "\\chapter{Finite differences in 2D}\\label{chap: finite diff 2d}\n\nIn this chapter, we study the numerical solution of the Dirichlet boundary-value \nproblem for the Poisson equation. Let $\\Omega$ be a bounded, open subset \nof~$\\mathbb{R}^2$, with a piecewise smooth boundary~$\\Gamma=\\partial\\Omega$.  \nGiven suitable functions $f(x,y)$~and $g(x,y)$, we see $u=u(x,y)$ satisfying\n\\begin{equation}\\label{eq: Poisson bvp}\n\\begin{aligned}\n-\\nabla^2u&=f(x,y)&&\\text{for $(x,y)\\in\\Omega$,}\\\\\nu&=g(x,y)&&\\text{for $(x,y)\\in\\Gamma$.}\n\\end{aligned}\n\\end{equation}\nHere, the \\emph{Laplacian} is the second-order elliptic differential operator\ndefined by\n\\[\n\\nabla^2 u=\\nabla\\cdot(\\nabla u)=\\frac{\\partial^2u}{\\partial x^2}\n    +\\frac{\\partial^2u}{\\partial y^2}.\n\\]\n\n\\section{Five-point difference scheme}\\label{sec: five point scheme}\nFor simplicity, we now restrict our attention to the case when the spatial \ndomain is a rectangle,\n\\begin{equation}\\label{eq: Omega rectangle}\n\\Omega=(0,L_x)\\times(0,L_y).\n\\end{equation}\nTo set up the spatial finite difference grid, we fix positive integers $P$~and \n$Q$, define the step sizes\n\\[\n\\Delta x=\\frac{L_x}{P}\\quad\\text{and}\\quad\\Delta y=\\frac{L_y}{Q},\n\\]\nand define the grid points\n\\begin{equation}\\label{eq: xp yq grid}\n(x_p,y_q)=(p\\,\\Delta x,q\\,\\Delta y)\n\\quad\\text{for $0\\le p\\le P$ and $0\\le q\\le Q$.}\n\\end{equation}\nOur is to compute $U_{p,q}\\approx u(x_p,y_q)$ where $u$ is the solution \nof~\\eqref{eq: Poisson bvp}.\n\nLet $\\delta_x^2$~and $\\delta_y^2$ denote the second-order, central difference \noperators in the $x$- and $y$-directions, respectively; that is,\n\\[\n\\delta_x^2u(x,y)=\\frac{u(x+\\Delta x,y)-2u(x,y)+u(x-\\Delta x,y)}{\\Delta x^2}\n    =\\frac{\\partial^2u}{\\partial x^2}+O(\\Delta x^2)\n\\]\nand\n\\[\n\\delta_y^2u(x,y)=\\frac{u(x,y+\\Delta y)-2u(x,y)+u(x,y-\\Delta y)}{\\Delta x^2}\n    =\\frac{\\partial^2u}{\\partial y^2}+O(\\Delta y^2).\n\\]\nWe also write\n\\[\n\\delta_x^2U_{pq}=\\frac{U_{p+1,q}-2U_{p,q}+U_{p-1,q}}{\\Delta x^2}\n\\quad\\text{and}\\quad\n\\delta_y^2U_{pq}=\\frac{U_{p,q}-2U_{p,q}+U_{p,q-1}}{\\Delta y^2}.\n\\]\nWith this notation, our finite difference scheme can be written compactly as\n\\begin{equation}\\label{eq: 5-pt Poisson}\n\\begin{aligned}\n-\\bigl(\\delta_x^2U_{p,q}+\\delta_y^2U_{p,q}\\bigr)&=f_{p,q}\n    &&\\text{for $(x_p,y_q)\\in\\Omega$,}\\\\\nU_{p,q}&=g_{p,q}&&\\text{for $(x_p,y_q)\\in\\Gamma$,}\n\\end{aligned}\n\\end{equation}\nwith the obvious abbreviations $f_{p,q}=f(x_p,y_q)$~and $g_{p,q}=g(x_p,y_q)$.\nNotice that $(x_p,y_q)\\in\\Omega$ for $1\\le p\\le P-1$ and $1\\le q\\le Q-1$, so \nthere are \n\\[\nM=(P-1)(Q-1)\n\\]\nunknown values of~$U_{p,q}$ at the interior grid points.  The remaining\n$(P+1)(Q+1)-M=2P+2Q$ values are given directly by the Dirichlet boundary \ncondition.  The finite difference approximation provides one equation for \neach interior grid points, and hence one equation for each unknown, to yield an \n$M\\times M$~linear system.  Figure~\\ref{fig: 5-pt stencil} shows the stencil \nfor the scheme, which involes 5~grid points: $(x_p,y_q)$ and its four nearest \nneighbours $(x_{p-1},y_q)$, $(x_{p+1},y_q)$, $(x_{p,q-1})$~and \n$(x_p,y_{q+1})$.\n\n\\begin{figure}\n\\caption{Five-point finite difference stencil for the discrete Poisson \nequation~\\eqref{eq: 5-pt Poisson}.}\\label{fig: 5-pt stencil}\n\\begin{center}\n\\begin{tikzpicture}[scale=0.5]\n\\draw[->] (-1,0) -- (17,0);\n\\node[right] at (17,0) {$x$};\n\\node[below] at (8,0) {$x_p$};\n\\draw[->] (0,-1) -- (0,13);\n\\node[above left] at (0,13) {$y$};\n\\node[left] at (0,6) {$y_q$};\n\\foreach \\x in {2, 4, ..., 14}\n    \\draw[thin] (\\x,0) -- (\\x,12);\n\\foreach \\y in {2, 4, ..., 10}\n    \\draw[thin] (0,\\y) -- (16,\\y);\n\\draw[ultra thick] (8,4) -- (8,8);\n\\draw[ultra thick] (6,6) -- (10,6);\n\\draw[fill=red] (8,4)  circle (0.15cm);\n\\draw[fill=red] (8,6)  circle (0.15cm);\n\\draw[fill=red] (8,8)  circle (0.15cm);\n\\draw[fill=red] (6,6) circle (0.15cm);\n\\draw[fill=red] (10,6) circle (0.15cm);\n\\node[below] at (16,0) {$L_x$};\n\\node[left]  at (0,12) {$L_y$};\n\\draw[thick] (0,0) -- (16,0) -- (16,12) -- (0,12) -- (0,0);\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\nTo describe the $M\\times M$ system explicitly, we need to arrange the \nunknowns~$U_{p,q}$ into a column vector of length~$M$.  A standard approach is \nto think of the $U_{p,q}$ as the entries of a $(P-1)\\times(Q-1)$ matrix and use \n\\emph{column-major ordering}, so that\n\\begin{equation}\\label{eq: column-major}\nU_j=U_{p,q}\\quad\n\\text{where $j=p+(q-1)(P-1)$ for $1\\le p\\le P-1$ and $1\\le q\\le Q-1$.}\n\\end{equation}\nThe right-hand sides $f_{p,q}$ are arranged in the same way.  \n\n\\begin{example}\\label{example: 5-pt matrix}\nSuppose $P=5$ and $Q=4$, with $\\Delta x=h=\\Delta y$.  The finite difference \nequation is then\n\\[\n-\\frac{1}{h^2}\\bigl(U_{p+1,q}-2U_{p,q}+U_{p-1,q}+U_{p,q+1}2-U_{p,q}+U_{p,q-1}\n    \\bigr)=f_{p,q},\n\\]\nor equivalently,\n\\[\n\\frac{1}{h^2}\\bigl(-U_{p,q-1}-U_{p-1,q}+4U_{p,q}-U_{p+1,q}-U_{p,q+1}\\bigr)\n    =f_{p,q}.\n\\]\nWhen $p=1$~and $q=3$,\n\\[\n\\frac{1}{h^2}\\bigl(-U_{1,2}-U_{0,3}+4U_{1,3}-U_{2,3}-U_{1,4}\\bigr)\n    =f_{1,3},\n\\]\nand the boundary conditions give $U_{0,3}=g_{0,3}$~and $U_{1,4}=g_{1,4}$, so\n\\[\n\\frac{1}{h^2}\\bigl(-U_{1,2}+4U_{1,3}-U_{2,3}\\bigr)\n    =f_{1,3}+\\frac{1}{h^2}\\bigl(g_{0,3}+g_{1,4}\\bigr).\n\\]\nUsing column-major ordering~\\eqref{eq: column-major} with~$P=5$, we have\n$U_5=U_{1,2}$, $U_9=U_{1,3}$~and $U_{10}=U_{2,3}$ so the $9$th equation is\n\\[\n\\frac{1}{h^2}\\bigl(-U_5+4U_9-U_{10}\\bigr)=f_9\n    +\\frac{1}{h^2}\\bigl(g_{0,3}+g_{1,4}\\bigr).\n\\]\nFigure~\\ref{fig: 5-pt matrix} shows the complete $12\\times12$ linear system.\n\\end{example}\n\n\\begin{figure}\n\\caption{The $12\\times12$ linear system from \nExample~\\ref{example: 5-pt matrix}.}\\label{fig: 5-pt matrix}\n\\begin{gather*}\n\\frac{1}{h^2}\n\\left[\\begin{array}{cccc|cccc|cccc}\n 4&-1& 0& 0&  -1& 0& 0& 0&   0& 0& 0& 0\\\\\n-1& 4&-1& 0&   0&-1& 0& 0&   0& 0& 0& 0\\\\\n 0&-1& 4&-1&   0& 0&-1& 0&   0& 0& 0& 0\\\\\n 0& 0&-1& 4&   0& 0& 0&-1&   0& 0& 0& 0\\\\\n\\hline\n-1& 0& 0& 0&   4&-1& 0& 0&  -1& 0& 0& 0\\\\\n 0&-1& 0& 0&  -1& 4&-1& 0&   0&-1& 0& 0\\\\\n 0& 0&-1& 0&   0&-1& 4&-1&   0& 0&-1& 0\\\\\n 0& 0& 0&-1&   0& 0&-1& 4&   0& 0& 0&-1\\\\\n\\hline\n 0& 0& 0& 0&  -1& 0& 0& 0&   4&-1& 0& 0\\\\\n 0& 0& 0& 0&   0&-1& 0& 0&  -1& 4&-1& 0\\\\\n 0& 0& 0& 0&   0& 0&-1& 0&   0&-1& 4&-1\\\\\n 0& 0& 0& 0&   0& 0& 0&-1&   0& 0&-1& 4\n\\end{array}\\right]\n\\left[\\begin{array}{c}\nU_{1,1}\\\\ U_{2,1}\\\\ U_{3,1}\\\\ U_{4,1}\\\\ \n\\hline\nU_{1,2}\\\\ U_{2,2}\\\\ U_{3,2}\\\\ U_{4,2}\\\\                \n\\hline\nU_{1,3}\\\\ U_{2,3}\\\\ U_{3,3}\\\\ U_{4,3}                \n\\end{array}\\right]\\\\\n=\\left[\\begin{array}{c}\nf_{1,1}\\\\ f_{2,1}\\\\ f_{3,1}\\\\ f_{4,1}\\\\                \n\\hline\nf_{1,2}\\\\ f_{2,2}\\\\ f_{3,2}\\\\ f_{4,2}\\\\                \n\\hline\nf_{1,3}\\\\ f_{2,3}\\\\ f_{3,3}\\\\ f_{4,3}                \n\\end{array}\\right]\n+\\frac{1}{h^2}\\left[\\begin{array}{c}\ng_{01}+g_{10}\\\\ g_{20}\\\\ g_{30}\\\\ g_{40}+g_{51}\\\\ \\hline\ng_{02}       \\\\ 0     \\\\ 0     \\\\ g_{52}\\\\ \\hline\ng_{03}+g_{14}\\\\ g_{24}\\\\ g_{34}\\\\ g_{44}+g_{53}\n\\end{array}\\right].\n\\end{gather*}\n\\end{figure}\n\n\\section{Matrix structure}\nThe structure of the matrix arising from the discrete Poisson \nproblem~\\eqref{eq: 5-pt Poisson} can be understood more easily with the help of \nthe following concept.\n\n\\begin{definition}\nGiven matrices\n$\\boldsymbol{A}\\in\\mathbb{R}^{M\\times N}$~and \n$\\boldsymbol{B}\\in\\mathbb{R}^{P\\times Q}$, the \\emph{Kronecker product} \n$\\boldsymbol{A}\\otimes\\boldsymbol{B}\\in\\mathbb{R}^{(MP)\\times(NQ)}$ \nis the $M\\times N$ block matrix whose $ij$-block equals $a_{ji}\\boldsymbol{B}$,\nthat is,\n\\[\n\\boldsymbol{A}\\otimes\\boldsymbol{B}=\\begin{bmatrix}\na_{11}\\boldsymbol{B}&a_{12}\\boldsymbol{B}&\\cdots&a_{1N}\\boldsymbol{B}\\\\\na_{21}\\boldsymbol{B}&a_{22}\\boldsymbol{B}&\\cdots&a_{2N}\\boldsymbol{B}\\\\\n              \\vdots&              \\vdots&\\ddots&              \\vdots\\\\\na_{M1}\\boldsymbol{B}&a_{M2}\\boldsymbol{B}&\\cdots&a_{MN}\\boldsymbol{B}\n\\end{bmatrix}.\n\\]\n\\end{definition}\n\n\\begin{example}\\label{example: Kronecker product}\nIf\n\\[\n\\boldsymbol{A}=\\begin{bmatrix}1&3\\\\ 2&4\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{B}=\\begin{bmatrix}1&0&-3\\\\ -2&1&-1\\end{bmatrix}\n\\]\nthen\n\\[\n\\boldsymbol{A}\\otimes\\boldsymbol{B}\n=\\begin{bmatrix}\n \\boldsymbol{B}&3\\boldsymbol{B}\\\\\n2\\boldsymbol{B}&4\\boldsymbol{B} \n\\end{bmatrix}\n=\\left[\\begin{array}{ccc|ccc}\n 1& 0&-3& 3& 0&-9\\\\\n-2& 1&-1&-6& 3&-3\\\\             \n\\hline\n 2& 0&-6& 4& 0&-12\\\\\n-4& 2&-2&-8& 4&-4\n\\end{array}\\right].\n\\]\n\\end{example}\n\nThe next theorem gives a key relation between the Kronecker product and the \nordinary matrix product.\n\n\\begin{theorem}\\label{thm: Kronecker A B C D}\nIf $\\boldsymbol{A}\\in\\mathbb{R}^{M\\times N}$,\n$\\boldsymbol{B}\\in\\mathbb{R}^{P\\times Q}$,\n$\\boldsymbol{C}\\in\\mathbb{R}^{N\\times R}$~and\n$\\boldsymbol{D}\\in\\mathbb{R}^{Q\\times S}$, then\n\\[\n(\\boldsymbol{A}\\otimes\\boldsymbol{B})(\\boldsymbol{C}\\otimes\\boldsymbol{D})\n=(\\boldsymbol{A}\\boldsymbol{C})\\otimes(\\boldsymbol{B}\\boldsymbol{D}).\n\\]\n\\end{theorem}\n\\begin{proof}\nThe $ij$-block of \n$(\\boldsymbol{A}\\otimes\\boldsymbol{B})(\\boldsymbol{C}\\otimes\\boldsymbol{D})$ \nequals\n\\[\n\\sum_{k=1}^N(a_{ik}\\boldsymbol{B})(c_{kj}\\boldsymbol{D})\n    =\\biggl(\\sum_{k=1}^Na_{ik}c_{kj}\\biggr)(\\boldsymbol{B}\\boldsymbol{D})\n    =(\\boldsymbol{A}\\boldsymbol{C})_{ij}(\\boldsymbol{B}\\boldsymbol{D}),\n\\]\nwhich is also the $ij$-block of\n$(\\boldsymbol{A}\\boldsymbol{C})\\otimes(\\boldsymbol{B}\\boldsymbol{D})$.\n\\end{proof}\n\n\\begin{example}\n\\newcommand{\\bs}[1]{\\boldsymbol{#1}}\nWith $\\boldsymbol{A}$~and $\\boldsymbol{B}$ as in \nExample~\\ref{example: Kronecker product}, and with\n\\[\n\\boldsymbol{C}=\\begin{bmatrix}1&-1&3\\\\ 5&0&3\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{D}=\\begin{bmatrix}1&0&7\\\\ 0&-4&1\\\\ 2&3&9\\end{bmatrix},\n\\]\nwe have\n\\[\n(\\bs{A}\\otimes\\bs{B})(\\bs{C}\\otimes\\bs{D})\n    =\\begin{bmatrix}\n \\bs{B}&3\\bs{B}\\\\\n2\\bs{B}&4\\bs{B}\\end{bmatrix}\n\\begin{bmatrix}\n \\bs{D}&-\\bs{D}&3\\bs{D}\\\\\n5\\bs{D}& \\bs{0}&3\\bs{D}\n\\end{bmatrix}\n=\\begin{bmatrix}\n16\\bs{B}\\bs{D}& -\\bs{B}\\bs{D}&12\\bs{B}\\bs{D}\\\\\n22\\bs{B}\\bs{D}&-2\\bs{B}\\bs{D}&18\\bs{B}\\bs{D}\n\\end{bmatrix}\n\\]\nwhich is the same matrix as\n\\[\n(\\bs{A}\\bs{C})\\otimes(\\bs{B}\\bs{D})\n=\\left(\\begin{bmatrix}1&3\\\\ 2&4\\end{bmatrix}\n\\begin{bmatrix}1&-1&3\\\\ 5&0&3\\end{bmatrix}\\right)\\otimes(\\bs{B}\\bs{D})\n=\\begin{bmatrix}16&-1&12\\\\ 22&-2&18\\end{bmatrix}\\otimes(\\bs{B}\\bs{D}).\n\\]\n\\end{example}\n\nThe Kronecker product makes sense for vector operands, if we identify an\n$N$-dimensional row vector with a $1\\times N$~matrix, and identify an \n$N$-dimensional column vector with an $N\\times1$~matrix.  Suppose that\n\\[\n\\newcommand{\\bs}[1]{\\boldsymbol{#1}}\n\\bs{U}=\\bs{w}\\otimes\\bs{v}\n    =\\begin{bmatrix}w_1\\bs{v}\\\\ w_2\\bs{v}\\\\ \\vdots\\\\ w_{Q-1}\\bs{v}\\end{bmatrix}\n\\quad\\text{for $\\bs{v}\\in\\mathbb{R}^{P-1}$ and $\\bs{w}\\in\\mathbb{R}^{Q-1}$,}\n\\]\nso that\n\\[\nU_j=U_{p,q}=v_pw_q\\quad\\text{where $j=p+(q-1)(P-1)$,}\n\\]\nfor $1\\le p\\le P-1$ and $1\\le q\\le Q-1$.  Define\n\\[\n\\boldsymbol{A}_x=\\frac{1}{\\Delta x^2}\\begin{bmatrix}\n 2&    -1&      &      &\\\\\n-1&     2&    -1&      &\\\\\n  &\\ddots&\\ddots&\\ddots&\\\\\n  &      &    -1&     2&-1\\\\\n  &      &      &    -1& 2\\end{bmatrix}\\in\\mathbb{R}^{(P-1)\\times(P-1)}\n\\]\nand\n\\[\n\\boldsymbol{A}_y=\\frac{1}{\\Delta y^2}\\begin{bmatrix}\n 2&    -1&      &      &\\\\\n-1&     2&    -1&      &\\\\\n  &\\ddots&\\ddots&\\ddots&\\\\\n  &      &    -1&     2&-1\\\\\n  &      &      &    -1& 2\\end{bmatrix}\\in\\mathbb{R}^{(Q-1)\\times(Q-1)},\n\\]\nso that\n\\begin{equation}\\label{eq: delta x y separable}\n-\\delta_x^2U_{p,q}=(\\boldsymbol{A}_x\\boldsymbol{v})_pw_q\n\\quad\\text{and}\\quad\n-\\delta_y^2U_{p,q}=v_p(\\boldsymbol{A}_y\\boldsymbol{w})_q,\n\\end{equation}\nif we set $v_0=0=v_P$ and $w_0=0=w_Q$.  These relations correspond to the case \nwhen $u(x,y)=v(x)w(y)$ so that $-u_{xx}=(-v'')w$~and $u_{yy}=v(-w'')$.\n\n\\begin{theorem}\\label{thm: Poisson matrix}\nLet\n\\[\n\\boldsymbol{A}\\boldsymbol{U}=\\boldsymbol{f}+\\boldsymbol{g}\n\\]\nbe the linear system resulting from the discrete Poisson \nproblem~\\eqref{eq: 5-pt Poisson} scheme~\\eqref{eq: 5-pt Poisson}.  Then,\n\\[\n\\boldsymbol{A}=\\boldsymbol{I}_y\\otimes\\boldsymbol{A}_x\n    +\\boldsymbol{A}_y\\otimes\\boldsymbol{I}_x,\n\\]\nwhere $\\boldsymbol{I}_x$~and $\\boldsymbol{I}_y$ are the identity matrices of \ndimension $P-1$~and $Q-1$, respectively.\n\\end{theorem}\n\\begin{proof}\nWe see from \\eqref{eq: delta x y separable}~and \nTheorem~\\ref{thm: Kronecker A B C D} that\n\\begin{align*}\n\\boldsymbol{A}(\\boldsymbol{w}\\otimes\\boldsymbol{v})\n    &=\\boldsymbol{w}\\otimes(\\boldsymbol{A}_x\\boldsymbol{v})\n    +(\\boldsymbol{A}_y\\boldsymbol{w})\\otimes\\boldsymbol{v}\\\\\n    &=\\bigl(\\boldsymbol{I}_y\\boldsymbol{w})\n        \\otimes(\\boldsymbol{A}_x\\boldsymbol{v})\n    +(\\boldsymbol{A}_y\\boldsymbol{w})\n        \\otimes(\\boldsymbol{I}_x\\boldsymbol{v})\\\\\n    &=(\\boldsymbol{I}_y\\otimes\\boldsymbol{A}_x)\n        (\\boldsymbol{w}\\otimes\\boldsymbol{v})\n    +(\\boldsymbol{A}_y\\otimes\\boldsymbol{I}_x)\n        (\\boldsymbol{w}\\otimes\\boldsymbol{v})\\\\\n    &=\\bigl(\\boldsymbol{I}_y\\otimes\\boldsymbol{A}_x\n    +\\boldsymbol{A}_y\\otimes\\boldsymbol{I}_x\\bigr)\n        (\\boldsymbol{w}\\otimes\\boldsymbol{v})\n\\end{align*}\nfor every $\\boldsymbol{v}\\in\\mathbb{R}^{P-1}$ and \n$\\boldsymbol{w}\\in\\mathbb{R}^{Q-1}$.\n\\end{proof}\n\n\n\\section{Band Cholesky factorization}\n\nA matrix~$\\boldsymbol{A}=[a_{ij}]$ has \\emph{upper bandwidth}~$\\beta$ \nif $a_{ij}=0$ whenever $j-i>\\beta$, or equivalently if $\\boldsymbol{A}$ has \n$\\beta$~non-zero superdiagonals.  Similarly, $\\boldsymbol{A}$ has \\emph{lower \nbandwidth}~$\\beta$ if $a_{ij}=0$ whenever $i-j>\\beta$, so that there are \n$\\beta$~non-zero subdiagonals.  For example, the following matrix has upper \nbandwidth~$2$ and lower bandwidth~$3$:\n\\[\n\\begin{bmatrix}\n 5& 2&-1& 0& 0& 0& 0\\\\\n 1& 6& 0& 8& 0& 0& 0\\\\\n 2& 3& 9& 1& 8& 0& 0\\\\\n-3& 4& 7& 2& 5& 8& 0\\\\\n 0& 0& 2& 8& 3&-7& 1\\\\\n 0& 0& 4&-5& 6& 9& 3\n\\end{bmatrix}.\n\\]\nIf a matrix is symmetric, then its upper and lower bandwidths must be equal, so \nwe refer to both as just the \\emph{bandwidth}.\n\nLet $\\boldsymbol{A}$ be an $n\\times n$ symmetric, positive-definite matrix\nwith bandwith~$\\beta$.  We will seek a \\emph{band Cholesky factorization}\n\\begin{equation}\\label{eq: Chol fact}\n\\boldsymbol{A}=\\boldsymbol{R}^T\\boldsymbol{R},\n\\end{equation}\nwhere the $n\\times n$ matrix~$\\boldsymbol{R}=[r_{ij}]$ is upper triangular with \nupper bandwidth~$\\beta$.  By the definition of matrix multiplication,\n\\[\n\\bigl(\\boldsymbol{R}^T\\boldsymbol{R}\\bigr)_{ij}\n\t=\\sum_{k=1}^n\\bigl(\\boldsymbol{R}^T\\bigr)_{ik}\\boldsymbol{R}_{kj}\n\t=\\sum_{k=1}^n r_{ki}r_{kj}.\n\\]\nSince $\\boldsymbol{R}$ is upper triangular, $r_{ki}r_{kj}=0$ if $k>i$~or $k>j$,\nthat is, if $k>\\min(i,j)$, so in fact\n\\[\n\\bigl(\\boldsymbol{R}^T\\boldsymbol{R}\\bigr)_{ij}\n\t=\\sum_{k=1}^{\\min(i,j)} r_{ki}r_{kj}.\n\\]\nIn addition, $\\boldsymbol{R}$ has upper bandwidth~$\\beta$ so $r_{ki}r_{kj}=0$ \nif $i>k+\\beta$~or $j>k+\\beta$.  Thus, taking account of symmetry, \n\\eqref{eq: Chol fact} is satisfied iff\n\\[\na_{ij}=\\sum_{k=\\max(1,j-\\beta)}^ir_{ki}r_{kj}\n\t\\quad\\text{for $\\max(1,j-\\beta)\\le i\\le j\\le n$.}\n\\]\nWe split the last term off the sum, writing\n\\[\na_{ij}=r_{ii}r_{ij}+\\sum_{k=\\max(1,j-\\beta)}^{i-1}r_{ki}r_{kj}\n\t\\quad\\text{for $\\max(1,j-\\beta)\\le i<j\\le n$,}\n\\]\nin the off-diagonal case, and\n\\[\na_{jj}=r_{jj}^2+\\sum_{k=\\max(1,j-\\beta)}^{j-1}r_{kj}^2\n\t\\quad\\text{for $1\\le j\\le n$.}\n\\]\nin the diagonal case.  Rearranging these equations leads to the formulae\n\\[\nr_{ij}=\\frac{1}{r_{ii}}\\biggl(a_{ij}-\\sum_{k=\\max(1,j-\\beta)}^{i-1}r_{ki}r_{kj}\n\t\\biggr)\\quad\\text{for $\\max(1,j-\\beta)\\le i\\le j\\le n$,}\n\\]\nand\n\\[\nr_{jj}=\\sqrt{a_{jj}-\\sum_{k=\\max(1,j-\\beta)}^{j-1}r_{kj}^2}\n\t\\quad\\text{for $1\\le j\\le n$,}\n\\]\nwhich yield Algorithm~\\ref{alg: band Chol}.\n\n\\begin{algorithm}\nG\\caption{Compute the band Cholesky factorization \\eqref{eq: Chol fact}.}\n\\label{alg: band Chol}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{A}=[a_{ij}]$ is a real, $n\\times n$, symmetric \npositive-definite matrix with bandwidth~$\\beta$.}\n\\State\n\\Function{Factorize}{$\\boldsymbol{A}$}\n\\State Allocate storage for the $n\\times n$ Cholesky \nfactor~$\\boldsymbol{R}=[r_{ij}]$ and initialize to zero.\n\\For{$j=1:n$}\n    \\For{$i=\\max(1,j-\\beta):j$}\n        \\State $s=0$\n        \\For{$k=\\max(1,j-\\beta):i-1$}\n            \\State $s=s+r_{ki}r_{kj}$\n        \\EndFor\n        \\State $r_{ij}=(a_{ij}-s)/r_{ii}$\n    \\EndFor\n    \\State $s=0$\n    \\For{$k=\\max(1,j-\\beta):j-1$}\n        \\State $s=s+r_{kj}^2$\n    \\EndFor\n    \\If{$a_{jj}\\le s$} \n        \\State Error: $\\boldsymbol{A}$ is not positive-definite.\n    \\EndIf\n    \\State $r_{jj}=\\sqrt{a_{jj}-s}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{R}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}\n\\caption{Solve the linear system $\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ \ngiven the band Cholesky factorization~\\eqref{eq: Chol fact}.}\n\\label{alg: band Chol solve}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{b}=[b_i]_{i=1}^n$ is the right-hand side vector.}\n\\Require{$\\boldsymbol{R}=[r_{ij}]_{i,j=1}^n$ is the band Cholesky factor \nof~$\\boldsymbol{A}$, computed via Algorithm~\\ref{alg: band Chol}.}\n\\State\n\\Function{Solve}{$\\boldsymbol{b}, \\boldsymbol{R}$}\n\\State Allocate storage for $\\boldsymbol{x}=[x_i]_{i=1}^n$~and\n$\\boldsymbol{y}=[y_i]_{i=1}^n$.\n\\For{$i=1:n$}\n    \\State $s=b_i$\n    \\For{$k=\\max(1,i-\\beta):i-1$}\n        \\State $s=s-r_{ji}y_j$\n    \\EndFor\n    \\State $y_i=s/r_{ii}$\n\\EndFor\n\\For{$i=n:-1:1$}\n    \\State $s=y_i$\n    \\For{$j=i+1:\\min(n,i+\\beta)$}\n        \\State $s=s-r_{ij}x_j$\n    \\EndFor\n    \\State $x_i=s/r_{ii}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{x}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nOnce the Cholesky factor~$\\boldsymbol{R}$ is known, we can solve a linear \nsystem~$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ by first solving the lower \ntriangular system $\\boldsymbol{R}^T\\boldsymbol{y}=\\boldsymbol{b}$, and then \nsolving the upper triangular \nsystem~$\\boldsymbol{R}\\boldsymbol{x}=\\boldsymbol{y}$, so that\n\\[\n\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{R}^T\\boldsymbol{R}\\boldsymbol{x}\n\t=\\boldsymbol{R}^T\\boldsymbol{y}=\\boldsymbol{b}.\n\\]\nSince $r_{ji}=0$ if $j>i$~or $i-j>s$,\n\\[\n(\\boldsymbol{R}^T\\boldsymbol{y})_i=\\sum_{j=1}^nr_{ji}y_j\n\t=\\sum_{j=\\max(1,i-\\beta)}^ir_{ji}y_j\n\t=r_{ii}y_i+\\sum_{j=\\max(1,i-\\beta)}^{i-1}r_{ji}y_j\n\\]\nand so $\\boldsymbol{R}^T\\boldsymbol{y}=\\boldsymbol{b}$ iff\n\\[\ny_i=\\frac{1}{r_{ii}}\\biggl(b_i-\\sum_{j=\\max(1,i-\\beta)}^{i-1}r_{ji}y_j\\biggr)\n\\quad\\text{for $1\\le i\\le n$.}\n\\]\nSimilarly, since $r_{ij}=0$ if $i>j$~or $j-i>\\beta$,\n\\[\n(\\boldsymbol{R}\\boldsymbol{x})_i=\\sum_{j=1}^nr_{ij}x_j\n\t=\\sum_{j=i}^{\\min(n,i+\\beta)}r_{ij}x_j\n\t=r_{ii}x_i+\\sum_{j=i+1}^{\\min(n,i+\\beta)}r_{ij}x_j\n\\]\nand so $\\boldsymbol{R}\\boldsymbol{x}=\\boldsymbol{y}$ iff\n\\[\nx_i=\\frac{1}{r_{ii}}\\biggl(y_i-\\sum_{j=i+1}^{\\min(n,i+\\beta)}r_{ij}x_j\\biggr)\n\t\\quad\\text{for $1\\le i\\le n$.}\n\\]\nThese formula lead to Algorithm~\\ref{alg: band Chol solve} for solving \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$.\n\n\\begin{algorithm}\n\\newcommand{\\rb}[1]{r^{\\mathrm{band}}_{#1}}\n\\caption{Solve in place the linear system \n$\\boldsymbol{A}\\boldsymbol{x}=\\boldsymbol{b}$ \ngiven the band Cholesky factorization~\\eqref{eq: Chol fact}.}\n\\label{alg: band Chol solve in place}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{x}=[b_i]_{i=1}^n$ stores the right-hand side vector.}\n\\Require{The $(\\beta+1)\\times n$ array \n$\\boldsymbol{R}_{\\mathrm{band}}=[\\rb{ij}]$ stores \nthe band Cholesky factor~$\\boldsymbol{R}=[r_{ij}]$ of~$\\boldsymbol{A}$, as \ncomputed via Algorithm~\\ref{alg: band Chol} so that \n$r_{ij}=\\rb{\\beta+1+i-j,j}$.}\n\\State\n\\Function{Solve}{$\\boldsymbol{x},\\boldsymbol{R}_{\\mathrm{band}}$}\n\\For{$i=1:n$}\n    \\State $s=x_i$\n    \\For{$j=\\max(1,i-\\beta):i-1$}\n        \\State $s=s-\\rb{\\beta+1+j-i,i}x_j$\n    \\EndFor\n    \\State $x_i=s/\\rb{\\beta+1,i}$\n\\EndFor\n\\For{$i=n:-1:1$}\n    \\State $s=x_i$\n    \\For{$j=i+1:\\min(n,i+\\beta)$}\n        \\State $s=s-\\rb{\\beta+1+i-j,j}x_j$\n    \\EndFor\n    \\State $x_i=s/\\rb{\\beta+1,i}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{x}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{algorithm}\n\nWhen $\\beta$ is small compared to~$n$, storing $\\boldsymbol{A}$ as an \n$n\\times n$~array wastes a lot of space.  A more efficient method is to use \nthe \\emph{symmetric band storage scheme} that uses a\n$(\\beta+1)\\times n$~matrix \n$\\boldsymbol{A}_{\\textrm{band}}=[a^{\\mathrm{band}}_{ij}]$ to hold the non-zero \nsuperdiagonals of~$\\boldsymbol{A}$ by putting\n\\begin{equation}\\label{eq: symm band storage}\na^{\\mathrm{band}}_{\\beta+1+i-j,j}=a_{ij}\n\t\\quad\\text{for $\\max(1,j-\\beta)\\le i\\le j$ and $1\\le j\\le n$.}\n\\end{equation}\nFor example, if $n=9$ and $\\beta=3$, then\n\\[\n\\boldsymbol{A}_{\\mathrm{b}}=\\begin{bmatrix}\n     *&     *&     *&a_{14}&a_{25}&a_{36}&a_{47}&a_{58}&a_{69}\\\\\n     *&     *&a_{13}&a_{24}&a_{35}&a_{46}&a_{57}&a_{68}&a_{79}\\\\\n     *&a_{12}&a_{23}&a_{34}&a_{45}&a_{56}&a_{67}&a_{78}&a_{89}\\\\\na_{11}&a_{22}&a_{33}&a_{44}&a_{55}&a_{66}&a_{77}&a_{88}&a_{99}           \n\\end{bmatrix}.\n\\]\n\nComputing the band Cholesky factor~$\\boldsymbol{R}$ using \nAlgorithm~\\ref{alg: band Chol}, the number of multiplications is\n\\begin{multline*}\n\\sum_{j=1}^n\\biggl([j-\\max(1,j-\\beta)]\n+\\sum_{i=\\max(1,j-\\beta)}^j[i-\\max(1,j-\\beta)]\\biggr)\\\\\n\t=\\sum_{j=1}^n\\biggl([j-\\max(1,j-\\beta)]\n\t+\\sum_{i=0}^{j-\\max(1,j-\\beta)}i\\biggr)\n\t\\le\\sum_{j=1}^n\\biggl(\\beta+\\sum_{i=1}^\\beta i\\biggr)\n\t=n\\bigl[\\beta+\\tfrac12\\beta(\\beta+1)\\bigr].\n\\end{multline*}\nAssuming that the bandwidth~$\\beta$ is small compared to~$n$, we can see that \nthe multiplication counts is essentially $\\tfrac12n\\beta^2$, as is the number \nof addition/subtractions.  There are also $n$ square roots and\n\\[\n\\sum_{j=1}^n\\bigl[j-\\max(1,j-\\beta)+1]\\le\\sum_{j=1}^n(\\beta+1)=n(\\beta+1)\n\\]\ndivisions.\n\n\n\\section{Maximum principle}\n\\newcommand{\\bx}{\\boldsymbol{x}}\n\\newcommand{\\by}{\\boldsymbol{y}}\nWe wish to show that the boundary-value problem~\\eqref{eq: Poisson bvp} is\nwell-posed, generalising the 1D results of \\cref{thm: Lu=f apriori infty}.\nConsider the general, second-order, linear partial differential operator,\n\\begin{equation}\\label{eq: general L Rn}\n(\\mathcal{L}u)(\\bx)\n\t=-\\sum_{j,k=1}^na_{jk}(\\bx)(\\partial_j\\partial_ku)(\\bx)\n\t+\\sum_{j=1}^nb_j(\\bx)(\\partial_ju)(x)+c(\\bx)u(\\bx)\n\\quad\\text{for $\\bx\\in\\Omega$,}\n\\end{equation}\nwhere $\\partial_j=\\partial/\\partial x_j$ and where $\\Omega$ is a bounded,\nopen, connected subset of~$\\mathbb{R}^n$.  Since \n$\\partial_k\\partial_ju=\\partial_k\\partial_ju$ if $u$ is $C^2$, we assume\nwithout loss of generality that the coefficient matrix is symmetric, that is,\n\\[\na_{jk}(\\bx)=a_{kj}(\\bx)\\quad\\text{for $\\bx\\in\\Omega$.}\n\\]\nIn addition, we assume that all coefficients of~$\\mathcal{L}$ are bounded\nand continuous on~$\\Omega$.  \n\n\\begin{definition}\nThe partial differential operator~\\eqref{eq: general L Rn} is\n\\emph{uniformly elliptic} in~$\\Omega$ if there exist strictly positive \nconstants $\\lambda_{\\min}$~and $\\lambda_{\\max}$ such that\n\\[\n\\lambda_{\\min}|\\boldsymbol{\\xi}|^2\\le\\sum_{j,k=1}^na_{jk}(\\bx)\\xi_j\\xi_k\n\t\\le\\lambda_{\\max}|\\boldsymbol{\\xi}|^2\n\\quad\\text{for $\\bx\\in\\Omega$ and $\\boldsymbol{\\xi}\\in\\mathbb{R}^n$.}\n\\]\n\\end{definition}\n\nEquivalently, $\\mathcal{L}$ is uniformly elliptic if the spectrum of the \nsymmetric matrix~$[a_{ij}(\\bx)]$ lies in the \ninterval~$[\\lambda_{\\min},\\lambda_{\\max}]$ \nfor all $\\bx\\in\\Omega$. \n\nThe next two results generalise \\cref{lem: Lu<0}~and \n\\cref{thm: max principle 1d}.  The proof of the lemma uses the notation\n\\[\nB(\\bx_0,\\delta)=\\{\\,\\bx\\in\\mathbb{R}^n:|\\bx-\\bx_0|<\\delta\\,\\}\n\\]\nfor the open ball with centre~$\\bx_0$ and radius~$\\delta>0$.\n\n\\begin{lemma}\\label{lem: Lu<0 Omega}\nAssume that $\\mathcal{L}$ is uniformly elliptic and that $u$ is $C^2$ \non~$\\Omega$.  If $c\\ge0$ and $\\mathcal{L}u<0$ on~$\\Omega$, then $u$ cannot \nattain a non-negative local maximum in~$\\Omega$.\n\\end{lemma}\n\\begin{proof}\nSuppose for a contradiction that there exist $\\bx_0\\in\\Omega$ and $\\delta>0$\nsuch that\n\\[\nu(\\bx_0)\\ge0\\quad\\text{and}\\quad \n\\text{$u(\\bx)\\le u(\\bx_0)$ for $\\bx\\in B(\\bx_0,\\delta)\\subseteq\\Omega$.}\n\\]\nSince $u$ has an interior local maximum at~$\\bx_0$, it follows that \n$\\partial_ju(\\bx_0)=0$ and so\n\\begin{equation}\\label{eq: Lu x0}\n(\\mathcal{L}u)(\\bx_0)\n\t=-\\sum_{j,k=1}^na_{jk}(\\bx_0)(\\partial_j\\partial_ku)(\\bx_0)\n\t+c(\\bx_0)u(\\bx_0).\n\\end{equation}\nMoreover, there is an orthogonal matrix~$\\boldsymbol{Q}$ and a diagonal \nmatrix~$\\boldsymbol{\\Lambda}=[\\lambda_j\\delta_{jk}]$ such that \n\\[\n\\text{$\\lambda_{\\min}\\le\\lambda_j\\le\\lambda_{\\max}$ for $1\\le j\\le n$}\n\\qquad\\text{and}\\qquad\n\\boldsymbol{Q}^T[a_{jk}(\\bx_0)]\\boldsymbol{Q}=\\boldsymbol{\\Lambda}.\n\\]\nLet\n\\[\n\\bar u(\\by)=u(\\bx)\\quad\n\\text{for $\\by=\\bx_0+Q^T(\\bx-\\bx_0)$ and $\\bx\\in B(\\bx_0,\\delta)$,}\n\\]\nnoting that $\\by\\in B(\\bx_0,\\delta)$ iff $\\bx\\in B(\\bx_0,\\delta)$ because\n$|\\bx-\\bx_0|=|\\by-\\bx_0|$.  Since $\\partial y_l/\\partial x_j=q_{jl}$, the \nchain rule gives\n\\[\n\\partial_ju(\\bx)=\\sum_{l=1}^n q_{jl}\\partial_l\\bar u(\\by),\n\\]\nand therefore\n\\begin{align*}\n\\sum_{j,k=1}^n a_{jk}(\\bx_0)(\\partial_j\\partial_k u)(\\bx_0)\n\t&=\\sum_{j,k=1}^n\\sum_{l=1}^nq_{jl}\\sum_{m=1}^nq_{km}\n\t\\partial_l\\partial_m\\bar u(\\bx_0)\\\\\n\t&=\\sum_{j,k=1}^n\\biggl(\\sum_{l,k=1}^n q_{jl}a_{jk}(\\bx_0)q_{km}\n\t\\biggr)\\partial_l\\partial_m\\bar u(\\bx_0)\\\\\n\t&=\\sum_{j,k=1}^n\\lambda_l\\delta_{lm}\n\t\\partial_l\\partial_m\\bar u(\\bx_0)\\\\\n\t&=\\sum_{j,k=1}^n\\lambda_j\\delta_{jk}\n\t\\partial_l\\partial_m\\bar u(\\bx_0)\n\t=\\sum_{j=1}^n\\lambda_j\\partial_j^2\\bar u(\\bx_0).\n\\end{align*}\nThe function~$\\bar u$ has a local maximum at~$\\bar x_0$ so \n$\\partial_j^2\\bar u(\\bx_0)\\le0$ for all~$j$.  But then we see \nfrom~\\eqref{eq: Lu x0} that $(\\mathcal{L}u)(\\bx_0)<0$, a contradiction.\n\\end{proof}\n\n\\begin{theorem}\\label{thm: max principle}\nAssume that $\\mathcal{L}$ is uniformly elliptic and that $u$ is $C^2$ \non~$\\Omega$.  If $c\\ge0$ and $\\mathcal{L}u\\le0$ on~$\\Omega$, then \n\\[\n\\max_{\\bx\\in\\overline{\\Omega}}u(\\bx)\\le\\max_{\\bx\\in\\partial\\Omega}u^+(\\bx).\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $\\epsilon>0$ and $\\mu>0$, and put $w(\\bx)=u(\\bx)+\\epsilon e^{\\mu x_1}$.\nSince\n\\begin{align*}\n(\\mathcal{L}w)(\\bx)&=(\\mathcal{L}u)(\\bx)+\\epsilon\\bigl[-a_{11}(\\bx)\\mu^2\n\t+b_1(\\bx)\\mu+c(\\bx)\\bigr]e^{\\mu x_1}\\\\\n\t&\\le-\\epsilon\\bigl[\\lambda_{\\min}\\mu^2\n\t-\\mu\\|b\\|_\\infty-\\|c\\|_\\infty\\bigr]e^{\\mu x_1}\n\\end{align*}\nby choosing $\\mu$ sufficiently large we can ensure that $\\mathcal{L}w<0$\non~$\\Omega$.  By \\cref{lem:}, the function~$w$ cannot attain a non-negative\nlocal maximum in~$\\Omega$, implying that \n\\[\nu(\\bx)\\le w(\\bx)\\le w^+(\\bx)\\le\\max_{by\\in\\partial\\Omega}w^+(\\by)\n\t\\le\\max_{\\by\\in\\partial\\Omega}[u^+(y)+\\epsilon e^{\\mu L}]\n\\]\nfor $\\bx\\in\\Omega$, where $L=\\max_{\\bx\\in\\Omega} x_1$.  Since this inequality\nholds for any $\\epsilon>0$, the result follows.\n\\end{proof}\n\n\\begin{theorem}\\label{thm: max min elliptic}\nAssume the $\\mathcal{L}$ is uniformly elliptic, and that $u$ is continuous \non~$\\overline{\\Omega}$ and $C^2$ on~$\\Omega$.  If $c\\ge0$~and \n$\\mathcal{L}u=f$ on~$\\Omega$, then\n\\[\n\\max_{\\overline{\\Omega}}u\\le\\bigl(\\max_{\\partial\\Omega}u^+\\bigr)\n\t+C\\max_{\\overline{\\Omega}}f^+\n\\]\nand\n\\[\n\\min_{\\overline{\\Omega}}u\\le\\bigl(\\min_{\\partial\\Omega}u^-\\bigr)\n\t+C\\min_{\\overline{\\Omega}}f^-,\n\\]\nwhere $C=\\cosh(\\tfrac12\\mu\\operatorname{diam}\\Omega)$~and \n$\\mu=\\max(1, (1+\\|b_1\\|_\\infty)/\\lambda_{\\min}$.\n\\end{theorem}\n\\begin{proof}\nWithout loss of generality, we may assume that\n$\\Omega\\subseteq B(\\boldsymbol{0},r)$ for $r=\\tfrac12\\operatorname\\Omega$.\nLet\n\\[\nw(x)=\\bigl(\\max_{\\partial\\Omega}u^+\\bigr)+v(x)\\max_{\\overline{\\Omega}}f^+\n\\quad\\text{where}\\quad\nv(x)=\\cos(\\mu r)-\\cosh(\\mu x_1),\n\\]\nand observe that $v\\ge0$ on~$\\overline{\\Omega}$ with\n\\begin{align*}\n(\\mathcal{L}v)(x)&=a_{11}(\\bx)\\mu^2\\cosh(\\mu x_1)-b_1(\\bx)\\mu\\sinh(\\mu x_1)\n\t+c(\\bx)\\bigl(v(x)+\\max_{\\partial\\Omega}u^+\\bigr)\\\\\n\t&\\ge\\bigl(\\lambda_{\\min}\\mu^2-\\|b_1\\|_\\infty\\mu\\bigr)\\cosh(\\mu x_1)\n\t\\ge(\\lambda_{\\min}\\mu-\\|b_1\\|_\\infty)\\mu\\ge1\n\\end{align*}\nfor $\\bx\\in\\Omega$, so\n\\[\n\\mathcal{L}(u-w)=f-c(x)\\max_{\\partial\\Omega}u^+\n\t-(\\mathcal{L}v)\\max_{\\overline{\\Omega}}f^+\\le0\n\\quad\\text{on $\\Omega$.}\n\\]\nBy \\cref{thm: max principle},\n\\[\nu(\\bx)-w(\\bx)\\le\\max_{\\partial\\Omega}(u-w)^+\\quad\\text{for $\\bx\\in\\Omega$,}\n\\]\nand we see that\n\\[\nu(\\bx)-w(\\bx)=\\bigl(u(\\bx)-\\max_{\\partial\\Omega}u^+\\bigr)\n\t-v(x)\\max_{\\overline{\\Omega}}f^+\\le0\n\t\\quad\\text{for $\\bx\\in\\partial\\Omega$.}\n\\]\nThus, $u-w\\le0$ on~$\\Omega$, and therefore\n\\[\n\\max_{\\overline{\\Omega}}u\\le\\max_{\\overline{\\Omega}}w\n\t\\le\\bigl(\\max_{\\partial\\Omega}u^+\\bigr)\n\t+\\cosh(\\mu r)\\max_{\\overline{\\Omega}}f^+,\n\\]\nproving the first inequality.  The second follows because \n$\\mathcal{L}(-u)=-f$, $(-u)^+=-(u^-)$ and $(-f)^+=-(f^-)$.\n\\end{proof}\n\nNow consider the elliptic boundary-value problem\n\\begin{equation}\\label{eq: Dirichlet problem L}\n\\mathcal{L}u=f\\quad\\text{in $\\Omega$,}\n\t\\quad\\text{with $u=g$ on $\\partial\\Omega$.}\n\\end{equation}\nAs an immediate consequence of \\cref{thm: max min elliptic}, we obtain\nthe desired \\emph{a priori} estimate for~$u$ in terms of the data $f$~and $g$.\n\n\\begin{theorem}\\label{thm: a priori elliptic}\nAssume the $\\mathcal{L}$ is uniformly elliptic and that $c\\ge0$ on~$\\Omega$.\nThen any solution $u\\in C^2(\\Omega)\\cap C(\\overline{\\Omega})$ \nof~\\eqref{eq: Dirichlet problem L} satisfies\n\\[\n\\max_{\\overline{\\Omega}}|u|\\le\\max_{\\partial\\Omega}|g|\n\t+C\\max_{\\overline{\\Omega}}|f|.\n\\]\n\\end{theorem}\n\n\\section{Discrete maximum principle}\nWe now restrict our attention to a rectangular \ndomain~$\\Omega=(0,L_x)\\times(0,L_y)$ in~$\\mathbb{R}^2$, and assume that the\ncoefficients of $\\mathcal{L}$ satisfy\n\\[\na_{jk}(x,y)=a_j(x,y)\\delta_{jk}\\quad\\text{and}\\quad\nb_j(x,y)=0\\quad\\text{for $j$, $k\\in\\{1,2\\}$.}\n\\]\nThus,\n\\begin{equation}\\label{eq: L simple}\n(\\mathcal{L}u)(x,y)=-a_1(x,y)(\\partial_1^2u)(x,y)\n\t-a_2(x,y)(\\partial_2^2u)(x,y)+c(x,y)u(x,y),\n\\end{equation}\nand we define the corresponding finite difference operator \n\\begin{multline*}\n(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{pq}=-a_1(x_p,y_q)\\,\n\t\\frac{U_{p+1,q}-2U_{pq}+U_{p-1,q}}{\\Delta x^2}\\\\\n\t-a_2(x_p,y_q)\\,\n\t\\frac{U_{p,q+1}-2U_{pq}+U_{p,q-1}}{\\Delta y^2}\n\t+c(x_p,y_q)U_{pq}.\n\\end{multline*}\nThe finite difference approximation to the boundary-value \nproblem~\\eqref{eq: Dirichlet problem L} can then be written as\n\\begin{equation}\\label{eq: discrete bvp 2d}\n\\begin{aligned}\n(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{pq}&=f_{pq}&&\n\\text{for $(x_p,y_q)\\in\\Omega$,}\\\\\nU_{pq}&=g_{pq}&&\\text{for $(x_p,y_q)\\in\\Gamma$,}\n\\end{aligned}\n\\end{equation}\nwhich, in the special case $a_1(x,y)=1$, $a_2(x,y)=1$, $c(x,y)=0$\nreduces to the five-point scheme \\eqref{eq: 5-pt Poisson} for the Poisson\n\nThe simplified operator~\\eqref{eq: L simple} is uniformly elliptic iff\nthere are positive constants $\\lambda_{\\min}$ and $\\lambda_{\\max}$ such that\n\\[\n\\lambda_{\\min}\\le a_1(x,y)\\le\\lambda_{\\max}\\quad\\text{for $(x,y)\\in\\Omega$,}\n\\]\nand we will assume throughout that this is the case.  Given a grid \npoint~$(x_{p^*},y_{q^*})\\in\\Omega$, let\n\\[\n\\operatorname{Nbr}(p^*,q^*)=\\{(p+1,q),(p-1,q),(p,q+1),(p,q-1)\\}.\n\\]\nso that $(p,q)\\in\\operatorname{Nbr}(p^*,q^*)$ if and only if $(x_p,y_q)$ is \none of the four nearest neighbours to~$(x_{p^*},y_{q^*})$.  The following \ndiscrete analogue of \\cref{lem: Lu<0 Omega}.\n\n\\begin{lemma}\\label{lem: Lu<0 Omega discrete}\nIf $c_{p,q}\\ge0$ and $(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}<0$ for\n$(x_p,y_q)\\in\\Omega$, then there is no grid point~$(x_{p^*},y_{q^*})\\in\\Omega$\nsuch that\n\\[\nU_{p^*,q^*}\\ge0\\quad\\text{and}\\quad\\text{$U_{p,q}\\le U_{p^*,q^*}$ \nfor $(p,q)\\in\\operatorname{Nbr}(p^*,q^*)$.}\n\\]\n\\end{lemma}\n\\begin{proof}\nIf such a grid point exists, then\n\\[\nU_{p^*+1,q^*}+U_{p^*-1,q^*}\\le 2U_{p^*,q^*}\n\\quad\\text{and}\\quad\nU_{p^*,q^*+1}+U_{p^*,q^*-1}\\le 2U_{p^*,q^*},\n\\]\nso $(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p^*,q^*}\\ge0$, contradicting the\nsecond hypothesis of the lemma.\n\\end{proof}\n\nA discrete analogue of \\cref{thm: max principle} then follows; we use the\nabbreviation\n\\[\n\\max_{S}U^+=\\max_{(x_p,y_q)\\in S}U_{p,q}\n\t\\quad\\text{for $S\\subseteq\\overline{\\Omega}.$}\n\\]\n\n\\begin{theorem}\nIf $c_{p,q}\\ge0$ and $(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}\\le0$\nfor $(x_p,y_q)\\in\\Omega$, then\n\\[\n\\max_\\Omega U\\le\\max_{\\partial\\Omega}U^+ \\quad\\text{for $(x_p,y_q)\\in\\Omega$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $\\epsilon>0$ and $\\mu>0$, and put \n\\[\nW_{p,q}=U_{p,q}+\\epsilon g(x_p)\\quad\\text{where $g(x)=e^{\\mu x}$.}\n\\]\nSince $g^{(4)}(x)=\\mu^4e^{\\mu x}\\ge0$ for all~$x$, if follows by considering\nthe remainder term for the Taylor expansion of~$g$ about~$x_p$ that\n\\[\n\\frac{g(x_{p+1}-2g(x_p)+g(x_{p-1}}{\\Delta x^2}\\ge g''(x_p)=\\mu^2 e^{\\mu x_p}.\n\\]\nHence, writing $a_{1,p,q}=a_1(x_p,y_q)$ and $c_{p,q}=c(x_p,y_q)$,\n\\begin{align*}\n(\\mathcal{L}_{\\Delta x,\\Delta y}W)_{p,q}\n\t&=(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}+\\epsilon\\biggl(-a_{1,p,q}\n\\frac{g(x_{p+1}-2g(x_p)+g(x_{p-1}}{\\Delta x^2}+c_{p,q}g(x_p)\\biggr)\\\\\n\t&\\le(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}+\\epsilon\\bigl(-a_{1,p,q}\ne^{\\mu x_p}+c_{p,q}e^{\\mu x_p}\\bigr)\\\\\n\t&\\le0-\\epsilon\\bigl(\\lambda_{\\min}\\mu^2-\\|c\\|_\\infty\\bigr)e^{\\mu x_p},\n\\end{align*}\nand by choosing $\\mu^2>\\|c\\|_\\infty/\\lambda_{\\min}$ we can ensure that\n$(\\mathcal{L}_{\\Delta x,\\Delta y}W)_{p,q}<0$ for $(x_p,y_q)\\in\\Omega$.\nApplying \\cref{lem: Lu<0 Omega discrete}, we conclude that\n\\[\n\\max_\\Omega U\\le\\max_\\Omega W\\le\\max_{\\partial\\Omega}W\n\t\\le\\bigl(\\max_{\\partial\\Omega}U\\bigr)+\\epsilon e^{\\mu L_x}.\n\\]\nSince this inequality holds for any $\\epsilon>0$, the result follows.\n\\end{proof}\n\nNext is a discrete version of \\cref{thm: max min elliptic}.\n\n\\begin{theorem}\\label{thm: discrete max principle elliptic}\nIf $c_{p,q}\\ge0$ and $(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}=f_{p,q}$\nfor $(x_p,y_q)\\in\\Omega$, then\n\\[\n\\max_\\Omega U\\le\\max_{\\partial\\Omega}U^++C\\max_{(x_p,y_q)\\in\\Omega} f^+_{p,q}.\n\\]\nand\n\\[\n\\min_\\Omega U\\le\\min_{\\partial\\Omega}U^-+C\\max_{(x_p,y_q)\\in\\Omega}f^-_{p,q},\n\\]\nwhere $C=L^2/(8\\lambda_{\\min})$.\n\\end{theorem}\n\\begin{proof}\nLet\n\\[\nW_{p,q}=\\bigl(\\max_{\\partial\\Omega}U^+\\bigr)\n\t+v(x_p)\\max_\\Omega f^+_{\\cdot,\\cdot}\n\\quad\\text{where $v(x)=\\frac{x(L_x-x)}{2\\lambda_{\\min}}$.}\n\\]\nSince the second-order central difference quotient equals the exact second\nderivative for a quadratic polynomial,\n\\[\n\\frac{v(x_{p+1})-2v(x_p)+v(x_{p-1})}{\\Delta x^2}=v''(x_p)\n\t=\\frac{-1}{\\lambda_{\\min}}\n\\]\nand thus, noting that $v(x)\\ge0$ for~$0\\le x\\le L_x$, we conclude that\n\\[\n(\\mathcal{L}_{\\Delta x,\\Delta y}v)_{p,q}=\\frac{a_{1,p,q}}{\\lambda_{\\min}}\n\t+c_{p,q}v_{p,q}\\ge1\\quad\\text{for $(x_p,y_q)\\in\\Omega$.}\n\\]\nIt follows that\n\\[\n(\\mathcal{L}_{\\Delta x,\\Delta y}W)_{p,q}\n\t=c_{p,q}\\bigl(\\max_{\\partial\\Omega}U^+\\bigr)\n\t+(\\mathcal{L}_{\\Delta x,\\Delta y}V)_{p,q}\n\t\\bigl(\\max_\\Omega f^+_{\\cdot,\\cdot}\\bigr)\n\t\\ge\\bigl(\\max_\\Omega f^+_{\\cdot,\\cdot}\\bigr)\n\\]\nand so\n\\[\n\\bigl(\\mathcal{L}_{\\Delta x,\\Delta y}(U-W)\\bigr)_{p,q}\n\t=f_{p,q}-(\\mathcal{L}_{\\Delta x,\\Delta y}W)_{p,q}\n\t\\le f_{p,q}-\\max_{\\Omega}f^+_{\\cdot,\\cdot}\\le0\n\\quad\\text{for $(x_p,y_q)\\in\\Omega$,}  \n\\]\nwith\n\\[\n(U-W)_{p,q}=U_{p,q}-\\bigl(\\max_{\\partial\\Omega}U^+\\bigr)\n\t-V_p\\max f^+_{\\cdot,\\cdot}\\le0\n\\quad\\text{for $(x_p,y_q)\\in\\partial\\Omega$.}  \n\\]\nBy \\cref{thm: discrete max principle elliptic},\n\\[\n\\max_\\Omega(U-W)\\le\\max_{\\partial\\Omega}(U-W)\\le0,\n\\]\nand the first inequality follows because $\\max_{0\\le x\\le L_x}v(x)=C$ and so\n\\[\n\\max_\\Omega U\\le\\max_\\Omega W\\le\\bigl(\\max_{\\partial\\Omega}U^+\\bigr)\n\t+C\\max_\\Omega f^+_{\\cdot,\\cdot}.\n\\]\nThe second follows because\n$\\bigl(\\mathcal{L}_{\\Delta x,\\Delta y}(-U)\\bigr)_{p,q}=-f_p$,\n$(-U)^+_{p,q}=-(U^+_{p,q})$ and $(-f)^+_{p,q}=-(f^+_{p,q})$.\n\\end{proof}\n\nOur final result for this section is a discrete version of \n\\cref{thm: a priori elliptic}.\n\n\\begin{theorem}\\label{thm: discrete apriori elliptic}\nIf $c\\ge0$ on $\\Omega$, then the discrete boundary-value \nproblem~\\eqref{eq: discrete bvp 2d} has a unique solutions~$U_{p,q}$, and\n\\[\n\\max_{\\overline{\\Omega}}|U|\\le\\max_{\\partial\\Omega}|g_{\\cdot,\\cdot}|\n\t+C\\max_\\Omega|f_{\\cdot,\\cdot}|.\n\\]\n\\end{theorem}\n\\begin{proof}\nThe \\emph{a priori} estimate follows at once from \n\\cref{thm: discrete max principle elliptic}, and shows that if $f_{p,q}=0$\nfor all $(x_p,y_q)\\in\\Omega$~and if $g_{p,q}=0$ for all \n$(x_p,y_q)\\in\\partial\\Omega$, then the problem has only the trivial solution\n$U_{p,q}=0$ for all $(x_p,y_q)\\in\\overline{\\Omega}$. Hence, the coefficient\nmatrix for the associated linear system is non-singular, implying the\nexistence and uniqueness of~$U_{p,q}$.\n\\end{proof}\n\n\\section{An error bound}\n\nWe will say that the finite difference scheme used in~\\eqref{eq: }\nis \\emph{stable} if there is a constant~$C$ --- independent of $f$, $g$,\n$\\Delta x$~and $\\Delta y$ --- such that\n\\begin{equation}\\label{eq: stability elliptic Omega}\n\\max_{\\overline{\\Omega}}|U|\\le C\\Bigl(\\max_{\\partial\\Omega}|g_{\\cdot,\\cdot}|.\n\\end{equation}\nFor example, by \\cref{thm: discrete apriori elliptic}, sufficient conditions\nfor stability are that the simplified partial differential \noperator~\\eqref{eq: L simple} is uniformly elliptic with~$c\\ge0$.  \n\nWe define the local truncation error in the usual way, as\n\\[\n\\tau_{p,q}=f_{p,q}-(\\mathcal{L}_{\\Delta x,\\Delta y}u)_{p,q}\n\t=(\\mathcal{L}u)_{p,q}-(\\mathcal{L}_{\\Delta x,\\Delta y}u)_{p,q},\n\\]\nand note that\n\\begin{equation}\\label{eq: tau pq bound}\n\\begin{aligned}\n\\tau_{p,q}&=-a_{1,p,q}\\biggl(u_{xx}(x_p,y_q)\n\t-\\frac{u(x_{p+1},y_q)-2u(x_p,y_q)+u(x_{p-1},y_q)}{\\Delta x^2}\\biggr)\\\\\n\t&\\qquad{}-a_{2,p,q}\\biggl(u_{yy}(x_p,y_q)\n\t-\\frac{u(x_p,y_{q+1})-2u(x_p,y_q)+u(x,y_{q-1})}{\\Delta y^2}\\biggr),\n\\end{aligned}\n\\end{equation}\nso, by \\cref{thm: 2nd central diff},\n\\begin{equation}\\label{eq: tau pq bound}\n|\\tau_{p,q}|\\le\\biggl(\n\\frac{|a_{1,p,q}|}{12}\\|\\partial_1^4u\\|_\\infty\\,\\Delta x^2\n+\\frac{|a_{2,p,q}|}{12}\\|\\partial_2^4u\\|_\\infty\\,\\Delta y^2\\biggr)\n\\end{equation}\nThe \\emph{solution error},\n\\[\nE_{p,q}=U_{p,q}-u(x_p,y_q),\n\\]\nsatisfies\n\\[\n(\\mathcal{L}_{\\Delta x,\\Delta y}E)_{p,q}\n\t=(\\mathcal{L}_{\\Delta x,\\Delta y}U)_{p,q}\n\t-(\\mathcal{L}_{\\Delta x,\\Delta y}u)_{p,q}\n\t=f_{p,q}-(\\mathcal{L}_{\\Delta x,\\Delta y}u)_{p,q}=\\tau_{p,q},\n\\]\nfor $(x_p,y_q)\\in\\Omega$, with $E_{p,q}=g_{p,q}-g_{p,q}=0$\nfor $(x_p,y_q)\\in\\partial\\Omega$.  Replacing $U$, $f$ and $g$ \nin~\\eqref{eq: stability elliptic Omega} by $E$, $\\tau$ and $0$, respectively,\nwe have\n\\[\n\\max_{\\overline{\\Omega}}|U|\\le C\\max_\\Omega|\\tau_{\\cdot,\\cdot}|.\n\\]\nCombining this estimate with~\\eqref{eq: tau pq bound}, we obtain the error\nbound\n\\[\n|U_{p,q}-u(x_p,y_q)|\\le C\\biggl(\n\\frac{\\|a_1\\|_\\infty}{12}\\|\\partial_1^4u\\|_\\infty\\,\\Delta x^2\n+\\frac{\\|a_2\\|_\\infty}{12}\\|\\partial_2^4u\\|_\\infty\\,\\Delta y^2\\biggr)\n\\]\nfor $(x_p,y_q)\\in\\overline{\\Omega}$.  In other words,\n\\[\nU_{p,q}=u(x_p,y_q)+O(\\Delta x^2+\\Delta y^2),\n\\]\nshowing that the finite difference scheme is indeed second-order \naccurate.\n\n\\section{Parabolic problems in 2D}\nConsider the following 2D initial-boundary value problem,\n\\begin{equation}\\label{eq: ibvp 2d}\n\\begin{aligned}\nu_t-a\\nabla^2u&=f(x,y,t)&&\\text{for $(x,y)\\in\\Omega$ and $0<t<T$,}\\\\\nu&=g(x,y,t)&&\\text{for $(x,y)\\in\\partial\\Omega$ and $0<t<T$,}\\\\\nu&=u_0(x,y)&&\\text{for $(x,y)\\in\\Omega$ when $t=0$,}\n\\end{aligned}\n\\end{equation}\nwhere, for simplicity, we assume that the coefficient~$a$ is a positive\nconstant.  For the rectangular domain~\\eqref{eq: Omega rectangle} and the\ngrid \\eqref{eq: xp yq grid}, we can define the semidiscrete finite difference\nsolution~$U_{pq}(t)\\approx u(x_p,y_q,t)$ by\n\\[\n\\frac{dU_{p,q}}{dt}-a\\biggl(\\frac{U_{p+1,q}-2U_{p,q}+U_{p-1,q}}{\\Delta x^2}\n\t+\\frac{U_{p,q+1}-2U_{p,q}+U_{p,q-1}}{\\Delta y^2}\\biggr)=f_{p,q}(t)\n\\]\nfor $1\\le p\\le P-1$ and $1\\le q\\le Q-1$, together with the discrete\nboundary conditions\n\\[\nU_{p,q}(t)=g(x_p,y_q,t)\\quad\n\t\\text{for $(x_p,y_q)\\in\\partial\\Omega$ and $1\\le t\\le T$,}\n\\]\nand initial condition\n\\[\nU_{p,q}(0)=u_0(x_p,y_q)\\quad\\text{for $1\\le p\\le P-1$ and $1\\le q\\le Q-1$.}\n\\]\nSince\n\\[\n-a\\bigl(\\delta_x^2U_{p,q}+\\delta_y^2U_{p,q}\\bigr)=f_{p,q}-\\frac{dU_{p,q}}{dt},\n\\]\nwe see that\n\\[\n\\boldsymbol{A}\\boldsymbol{U}=\\boldsymbol{f}(t)+\\boldsymbol{g(t)}\n\t-\\frac{d\\boldsymbol{U}}{dt}\n\\]\nwhere $\\boldsymbol{A}$ is the same matrix as in \\cref{thm: Poisson matrix},\nand the vectors $\\boldsymbol{f}(t)$~and $\\boldsymbol{g}(t)$ are time-dependent\nvectors constructed from grid values of the functions $f$~and $g$, as in \n\\cref{example: 5-pt matrix}.  Thus, in matrix form the semidiscrete method is\n\\[\n\\frac{d\\boldsymbol{U}}{dt}+\\boldsymbol{A}\\boldsymbol{U}\n\t=\\boldsymbol{f}(t)+\\boldsymbol{g(t)} \n\\quad\\text{for $0\\le t\\le T$, with $\\boldsymbol{U}(0)=\\boldsymbol{U}_0$.}\n\\]\nHere, the column vector~$\\boldsymbol{U}_0=[(U_0)_j]_{j=1}^M$ is defined\nby putting $(U_0)_j=u_0(x_p,y_q)$ for~$j$ as in~\\eqref{eq: column-major}.\n\nBy introducing the time levels~\\eqref{eq: uniform tn}, we can consider a\nfully-discrete approximation\n\\[\nU^n_{p,q}\\approx U_{p,q}(t_n)\\approx u(x_p,y_q,t_n).\n\\]\nThe forward Euler method for the 2D problem~\\eqref{eq: ibvp 2d} is\n\\[\n\\frac{U^{n+1}_{p,q}-U^n_{p,q}}{\\Delta t}\n\t-a\\biggl(\\frac{U_{p+1,q}^n-2U_{p,q}^n+U_{p-1,q}^n}{\\Delta x^2}\n\t+\\frac{U_{p,q+1}^n-2U_{p,q}^n+U_{p,q-1}^n}{\\Delta y^2}\\biggr)=f_{p,q}^n,\n\\]\nfor $0\\le n\\le N-1$, $1\\le p\\le P-1$ and $1\\le q\\le Q-1$, with the \nfully-discrete boundary and initial conditions\n\\begin{equation}\\label{eq: fully discrete bc ic 2d}\n\\begin{aligned}\nU^n_{p,q}&=g^n_{p,q}&\n&\\text{for $0\\le n\\le N-1$ and $(x_p,y_q)\\in\\partial\\Omega$,}\\\\\nU^0_{p,q}&=(U_0)_{p,q}&\n&\\text{for $(x_p,y_q)\\in\\Omega$.}\n\\end{aligned}\n\\end{equation}\nLet\n\\[\n\\rho_x=\\frac{a\\,\\Delta t}{\\Delta x^2}\\quad\\text{and}\\quad\n\\rho_y=\\frac{a\\,\\Delta t}{\\Delta y^2},\n\\]\nso that\n\\[\nU^{n+1}_{p,q}-U^n_{p,q}-\\rho_x\\bigl(U^n_{p+1,q}-2U^n_{p,q}+U^n_{p-1,q}\\bigr)\n\t-\\rho_y\\bigl(U^n_{p,q+1}-2U^n_{p,q}+U^n_{p,q-1}\\bigr)\n\t=f^n_{p,q}\n\\]\nand hence\n\\[\nU^{n+1}_{p,q}=f^n_{p,q}+\\rho_xU^n_{p-1,q}+\\rho_yU^n_{p,q-1}\n\t+(1-2\\rho_x-2\\rho_y)U^n_{p,q}+\\rho_yU^n_{p,q+1}+\\rho_xU^n_{p+1,q}.\n\\]\nThe proof of \\cref{thm: explicit Euler stability} generalises to\nshow that the scheme is stable if $1-2\\rho_x-2\\rho_y\\ge0$, or equivalently if\n\\[\n\\Delta t\\le\\frac{\\Delta x^2\\,\\Delta y^2}{2a(\\Delta x^2+\\Delta y^2)}\n\t=\\frac{\\Delta x\\,\\Delta y}{2a(\\theta+\\theta^{-1})},\n\\quad\\text{where $\\theta=\\frac{\\Delta x}{\\Delta y}$.}\n\\]\n\nThe backward Euler method for the 2D problem~\\eqref{eq: ibvp 2d} is\n\\[\n\\frac{U^n_{p,q}-U^{n-1}_{p,q}}{\\Delta t}\n\t-a\\biggl(\\frac{U_{p+1,q}^n-2U_{p,q}^n+U_{p-1,q}^n}{\\Delta x^2}\n\t+\\frac{U_{p,q+1}^n-2U_{p,q}^n+U_{p,q-1}^n}{\\Delta y^2}\\biggr)=f_{p,q}^n,\n\\]\nfor $1\\le n\\le N$, $1\\le p\\le P-1$ and $1\\le q\\le P-1$, with the boundary \nand initial conditions again given by~\\eqref{eq: fully discrete bc ic 2d}.\nRearranging the finite difference equation gives\n\\[\n-\\rho_yU^n_{p,q-1}-\\rho_xU^n_{p-1,q}+(1+2\\rho_x+2\\rho_y)U^n_{p,q}\n-\\rho_xU^n_{p+1,q}-\\rho_yU^n_{p,q+1}=U^{n-1}_{p,q}+f^n_{p,q}\\,\\Delta t.\n\\]\nIn matrix notation, the backward Euler method looks the same as in 1D,\n\\[\n\\frac{\\boldsymbol{U}^n-\\boldsymbol{U}^{n-1}}{\\Delta t}\n\t+\\boldsymbol{A}\\boldsymbol{U}^n=\\boldsymbol{f}^n+\\boldsymbol{g}^n,\n\\]\nand at the $n$th time step we must again solve the linear system\n\\[\n(\\boldsymbol{I}+\\Delta t\\,\\boldsymbol{A})\\boldsymbol{U}^n\n\t=\\boldsymbol{U}^{n-1}+\\Delta t(\\boldsymbol{f}^n+\\boldsymbol{g}^n).\n\\]\nHowever, $\\boldsymbol{A}$ is now given by \\cref{thm: Poisson matrix} and the \nmeanings of the vectors $\\boldsymbol{U}^n$, \n$\\boldsymbol{f}^n=\\boldsymbol{f}(t_n)$ and \n$\\boldsymbol{g}^n=\\boldsymbol{g}(t_n)$ are also different from in\n\\eqref{eq: implicit Euler 1d vector}.  The coefficient matrix is again \nsymmetric and positive-definite, with the same sparsity pattern \nas~$\\boldsymbol{A}$, so we can use a band Cholesky factorization,\n\\begin{equation}\\label{eq: backward Euler 2d Cholesky}\n\\boldsymbol{I}+\\Delta t\\,\\boldsymbol{A}=\\boldsymbol{R}^T\\boldsymbol{R},\n\\end{equation}\nto compute $\\boldsymbol{U}^n$ at the $n$th~time step.\n\n\\begin{Exercises}\n\\exercise\nFind $A\\otimes B$~and $B\\otimes A$ in each case.\n\\begin{description}\n\\item{(i)}\n\\[\nA=\\begin{bmatrix}2&0\\\\ 1&-7\\\\ 4&6 \\end{bmatrix},\\qquad\nB=\\begin{bmatrix}1&-1\\\\ 2&0 \\end{bmatrix}.\n\\]\n\\item{(ii)}\n\\[\nA=\\begin{bmatrix}2&5\\\\ 0&-1\\end{bmatrix},\\qquad\nB=\\begin{bmatrix}1\\\\ 8\\\\ -9 \\end{bmatrix}.\n\\]\n\\item{(iii)}\n\\[\nA=\\begin{bmatrix}3&-2&0 \\end{bmatrix},\\qquad\nB=\\begin{bmatrix}1&-4\\\\ 3&2 \\end{bmatrix}.\n\\]\n\\end{description}\n\\begin{ans}\n(ii)\n\\[\nA\\otimes B=\\begin{bmatrix}2B&5B\\\\0&-B\\end{bmatrix}\n        =\\left[\\begin{array}{c|c}\n2&5\\\\ 15&40\\\\ -18&-45\\\\ \n\\hline\n0&-1\\\\ 0&-8\\\\ 0&9\n\\end{array}\\right].\n\\]\n\\[\nB\\otimes A=\\begin{bmatrix}A\\\\ 8A\\\\ -9A \\end{bmatrix}\n=\\left[\\begin{array}{cc}\n2&5\\\\ 0&-1\\\\\n\\hline\n16&40\\\\ 0&-8\\\\\n\\hline\n-18&-45\\\\ 0&-9\n\\end{array}\\right].\n\\]\n\\end{ans}\n\n\\exercise\nProve the following properties of the Kronecker product.\n\\begin{description}\n\\item{(i)} $A\\otimes(B+C)=A\\otimes B+A\\otimes C$.\n\\item{(ii)} $(A+B)\\otimes C=A\\otimes C+B\\otimes C$.\n\\item{(iii)} $A\\otimes(B\\otimes C)=(A\\otimes B)\\otimes C$.\n\\item{(iv)} $(A\\otimes B)^\\top=A^\\top\\otimes B^\\top$.\n\\end{description}\n\n\\exercise\nSuppose that the matrices $\\boldsymbol{A}$~and $\\boldsymbol{B}$ have upper \nbandwidth $s_{\\boldsymbol{A}}$~and $s_{\\boldsymbol{B}}$, respectively, and that \nthe number of columns of~$\\boldsymbol{A}$ equals the number of rows \nof~$\\boldsymbol{B}$.  Show that the matrix \nproduct~$\\boldsymbol{A}\\boldsymbol{B}$ has upper \nbandwidth~$s_{\\boldsymbol{A}}+s_{\\boldsymbol{B}}$.  State and prove the \ncorresponding result for lower bandwidths.\n\n\\exercise\nWe wish to solve the Poisson problem,\n\\[\n\\begin{aligned}\n-(u_{xx}+u_{yy})&=f&&\\text{in $\\Omega$,}\\\\\nu&=g&&\\text{on $\\partial\\Omega$,}\n\\end{aligned}\n\\]\nwhere $\\Omega$ is the triangular region\n\\[\n0\\le x\\le1,\\quad 0\\le y\\le 1-x.\n\\]\nWe define grid points\n\\[\n(x_p,y_q)=(p\\,\\Delta x,q\\,\\Delta y)\n        \\quad\\text{for $0\\le p\\le P$, $0\\le q\\le P-p$,}\n\\]\nwhere $\\Delta x=\\Delta y=1/P$, as illustrated in \n\\cref{fig: finite diff triangle} for the case~$P=5$, and seek\n$U_{pq}\\approx u(x_p,y_q)$.\n\n\\begin{figure}\n\\caption{Finite difference grid for a triangular domain.}\n\\label{fig: finite diff triangle}\n\\begin{center}\n\\begin{tikzpicture}[scale=1.0]\n\\draw[->] (-1,0)--(6,0);\n\\node[right] at (6,0) {$x$};\n\\draw[->] (0,-1) -- (0,6);\n\\node[right] at (0,6) {$y$};\n\\foreach \\x in {1, 2, 3, 4}\n    {\n    \\draw[thin] (\\x,0) -- (\\x,5-\\x);\n    \\draw[fill] (\\x,0) circle (0.05cm);\n    \\draw[fill] (\\x,5-\\x) circle (0.05cm);\n    }\n\\foreach \\y in {1, 2, 3, 4}\n    {\n    \\draw[thin] (0,\\y) -- (5-\\y,\\y);\n    \\draw[fill] (0,\\y) circle (0.05cm);\n    \\draw[fill] (5-\\y,\\y) circle (0.05cm);\n    }\n\\draw[fill] (0,0) circle (0.05cm);\n\\draw[fill] (5,0) circle (0.05cm);\n\\draw[fill] (0,5) circle (0.05cm);\n\\foreach \\x in {1, 2, 3}\n    \\draw[fill=white] (\\x,1) circle (0.05cm);\n\\foreach \\x in {1, 2}\n    \\draw[fill=white] (\\x,2) circle (0.05cm);\n\\draw[fill=white] (1,3) circle (0.05cm);\n\\draw[thick] (0,0) -- (5,0) -- (0,5) -- (0,0);\n\\node[below] at (5,0) {$1$};\n\\node[left]  at (0,5) {$1$};\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\\begin{description}\n\\item{(i)}\nWrite down the usual 5-point finite difference approximation for the\nPoisson equation, based on second-order central difference\napproximations to $u_{xx}$~and $u_{yy}$.  Use the\nabbreviation~$f_{pq}=f(x_p,y_q)$\n\\item{(ii)}\nWrite down the equation at~$(x_1,y_1)$, after the known boundary\nvalues are moved to the right-hand side.  You can use the\nabbreviation~$g_{pq}=g(x_p,y_q)$.\n\\item{(iii)}\nAssume now that $P=5$, and put\n\\begin{align*}\n\\boldsymbol{U}&=[U_{11}\\quad U_{21}\\quad U_{31}\\quad U_{12} \\quad U_{22}\n        \\quad U_{13}]^\\top,\\\\\n\\boldsymbol{f}&=[f_{11}\\quad f_{21}\\quad f_{31}\\quad f_{12} \\quad f_{22}\n        \\quad f_{13}]^\\top.\n\\end{align*}\nFind the matrix~$\\boldsymbol{A}$ and vector~$\\boldsymbol{g}$ such that, with\n$h=\\Delta x=\\Delta y=1/5$,\n\\[\n\\boldsymbol{A}\\boldsymbol{U}=h^2\\boldsymbol{f}+\\boldsymbol{g}.\n\\]\n\\end{description}\n\\begin{ans}\n(ii) $4U_{11}-U_{21}-U_{12}=h^2f_{11}+g_{01}+g_{10}$ \\\\\n(iii)\n\\[\n \\boldsymbol{A}=\\kbordermatrix{\n      &U_{11}&U_{21}&U_{31}&U_{12}&U_{22}&U_{13}\\\\\n(x_1,y_1)& 4&-1&  &-1&  &\\\\\n(x_2,y_1)&-1& 4&-1&  &-1&\\\\     \n(x_3,y_1)&  &-1& 4&  &  &\\\\\n(x_1,y_2)&-1&  &  & 4&-1&-1\\\\\n(x_2,y_2)&  &-1&  &-1& 4&\\\\\n(x_1,y_3)&  &  &  &-1&  &4},\\qquad\n\\boldsymbol{g}=\\kbordermatrix{\n&\\\\\n(x_1,y_1)&g_{10}+g_{10}\\\\\n(x_2,y_1)&g_{20}\\\\\n(x_3,y_1)&g_{30}+g_{41}+g_{32}\\\\\n(x_1,y_2)&g_{02}\\\\\n(x_2,y_2)&g_{32}+g_{23}\\\\\n(x_1,y_3)&g_{03}+g_{23}+g_{14}}.\n\\]\n\\end{ans}\n\n\n\\exercise\nWrite down $\\boldsymbol{A}_{\\mathrm{band}}$ given \nby~\\eqref{eq: symm band storage} if\n\\[\n\\boldsymbol{A}=\\begin{bmatrix}\n 5& 1& 7&  &  &\\\\\n 1& 2& 0&-1&  &\\\\\n 7& 0& 8& 2& 3&\\\\\n  &-1& 2& 5& 1& 6\\\\\n  &  & 3& 1& 7& 2\\\\\n  &  &  & 6& 2& 9\n\\end{bmatrix}.\n\\]\n\\begin{ans}\n\\[\n\\boldsymbol{A}_{\\mathrm{band}}=\\begin{bmatrix}\n *& *& 7&-1& 3& 6\\\\\n *& 1& 0& 2& 1& 2\\\\\n 5& 2& 8& 5& 7& 9                                \n\\end{bmatrix}\n\\]\n\\end{ans}\n\n\\exercise\nWrite an in-place version of Algorithm~\\ref{alg: band Chol}.\n\\begin{ans}\nIn-place algorithm:\n\\begin{center}\n\\newcommand{\\rb}[1]{r^{\\mathrm{band}}_{#1}}\n\\begin{algorithmic}\n\\Require{The $(\\beta+1)\\times n$ \narray~$\\boldsymbol{R}_{\\mathrm{band}}=[\\rb{ij}]$\nstores a real, $n\\times n$, symmetric positive-definite matrix with \nbandwidth~$\\beta$, using the symmetric band storage so\n$a_{ij}=\\rb{\\beta+1+i-j,j}$.}\n\\State\n\\Function{Factorize}{$\\boldsymbol{R}_{\\mathrm{band}}$}\n\\For{$j=1:n$}\n    \\For{$i=\\max(1,j-\\beta):j$}\n        \\State $s=0$\n        \\For{$k=\\max(1,j-\\beta):i-1$}\n            \\State $s=s+\\rb{\\beta+1+k-i,i}\\rb{\\beta+1+k-j,j}$\n        \\EndFor\n        \\State $\\rb{\\beta+1+i-j,j}=(\\rb{\\beta+1+i-j,j}-s)/\\rb{\\beta+1,i}$\n    \\EndFor\n    \\State $s=0$\n    \\For{$k=\\max(1,j-\\beta):j-1$}\n        \\State $s=s+(\\rb{\\beta+1+k-j,j})^2$\n    \\EndFor\n    \\If{$\\rb{s+1,j}\\le s$} \n        \\State Error: $\\boldsymbol{A}$ is not positive-definite.\n    \\EndIf\n    \\State $\\rb{\\beta+1,j}=\\sqrt{\\rb{\\beta+1,j}-s}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{R}_{\\mathrm{band}}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{center}\n\\end{ans}\n\n\\exercise\nWrite an in-place version of Algorithm~\\ref{alg: band Chol solve}.\n\\begin{ans}\nIn-place algorithm:\n\\begin{center}\n\\newcommand{\\rb}[1]{r^{\\mathrm{band}}_{#1}}\n\\begin{algorithmic}\n\\Require{$\\boldsymbol{x}=[b_i]_{i=1}^n$ stores the right-hand side vector.}\n\\Require{The $(\\beta+1)\\times n$ array \n$\\boldsymbol{R}_{\\mathrm{band}}=[\\rb{ij}]$ stores \nthe band Cholesky factor~$\\boldsymbol{R}=[r_{ij}]$ of~$\\boldsymbol{A}$, as \ncomputed via Algorithm~\\ref{alg: band Chol} so that \n$r_{ij}=\\rb{\\beta+1+i-j,j}$.}\n\\State\n\\Function{Solve}{$\\boldsymbol{x},\\boldsymbol{R}_{\\mathrm{band}}$}\n\\For{$i=1:n$}\n    \\State $s=x_i$\n    \\For{$j=\\max(1,i-\\beta):i-1$}\n        \\State $s=s-\\rb{\\beta+1+j-i,i}x_j$\n    \\EndFor\n    \\State $x_i=s/\\rb{\\beta+1,i}$\n\\EndFor\n\\For{$i=n:-1:1$}\n    \\State $s=x_i$\n    \\For{$j=i+1:\\min(n,i+\\beta)$}\n        \\State $s=s-\\rb{\\beta+1+i-j,j}x_j$\n    \\EndFor\n    \\State $x_i=s/\\rb{\\beta+1,i}$\n\\EndFor\n\\State\\Return{$\\boldsymbol{x}$}\n\\EndFunction\n\\end{algorithmic}\n\\end{center}\n\\end{ans}\n\n\\exercise\nDescribe the 2D version of the Crank--Nicolson method, and count the number of \nfloating-point operations needed for each of the following computations.\n\\begin{description}\n\\item{(i)} Finding the Cholesky factor~$\\boldsymbol{R}$ \nin~\\eqref{eq: backward Euler 2d Cholesky}.\n\\item{(ii)} Solving for~$\\boldsymbol{U}^n$ for a single choice of~$n$.\n\\item{(iii)} Completing the whole calculation.\n\\item{(iv)} How does the computational cost scale with the overall problem \nsize~$S=NPQ$?\n\\end{description}\n\n\\exercise\nLet $(r,\\theta)$ denote the usual polar coordinates, and consider a\ndomain~$\\Omega$ of the form\n\\[\na<r<b \n\\quad\\text{and}\\quad \n\\alpha<\\theta<\\beta,\n\\]\nwith $a>0$~and $\\beta-\\alpha<2\\pi$. It is natural to define polar\ngrid points\n\\[\n(r_p,\\theta_q)=(a+p\\,\\Delta r, \\alpha+q\\,\\Delta\\theta),\\quad\n\\Delta r=\\frac{b-a}{P},\\quad\n\\Delta\\theta=\\frac{\\beta-\\alpha}{Q},\n\\]\nfor $0\\le p\\le P$~and $0\\le q\\le Q$.  Recall that\n\\[\n\\nabla^2u=\\frac{1}{r}\\frac{\\partial}{\\partial r}\n        \\biggl(r\\,\\frac{\\partial u}{\\partial r}\\biggr)\n        +\\frac{1}{r^2}\\,\\frac{\\partial^2u}{\\partial\\theta^2}.\n\\]\n\\begin{description}\n\\item{(i)} Formulate a finite difference approximation to the Poisson problem\n\\[\n\\begin{aligned}\n-\\nabla^2u&=f&\\text{in $\\Omega$,}\\\\\nu&=0&\\text{on $\\partial\\Omega$,}\n\\end{aligned}\n\\]\nby setting up a $P\\times Q$ rectangular grid in the\n$(r,\\theta)$-plane.\n\\item{(ii)}\nSuppose that $\\Omega$ is a disk of radius~$b$ (so $a=0$,\n$\\alpha=-\\pi$~and $\\beta=\\pi$).  Formulate a finite difference\nmethod with $1+(P-1)Q$~unknowns.  Hint: you will need an equation\nat the origin.\n\\end{description}\n\\begin{ans}\n(i)\nPut $(r_p,\\theta_q)=(a+p\\,\\Delta r,b+q\\,\\Delta\\theta)$\nfor $0\\le p\\le P$~and $0\\le q\\le Q$, where $\\Delta r=(b-a)/P$~and\n$\\Delta\\theta=(\\beta-\\alpha)/Q$.  Then $U_{pq}\\approx u(r_p,\\theta_q)$\nshould satisfy\n\\begin{multline*}\n\\frac{1}{\\Delta r^2}\\biggl(\n        -\\frac{r_{p-1/2}}{r_p}\\,U_{p-1,q}\n        +\\frac{r_{p-1/2}+r_{p+1/2}}{r_p}\\,U_{pq}\n        -\\frac{r_{p+1/2}}{r_p}\\,U_{p+1,q}\\biggr)\\\\\n        +\\frac{-U_{p,q-1}+2U_{pq}-U_{p,q+1}}{r_p^2\\Delta\\theta^2}\n        =f(r_p,\\theta_q)\n\\end{multline*}\nfor $1\\le p\\le P-1$~and $1\\le q\\le Q-1$, with zero boundary conditions\n$U_{0q}=0=U_{Pq}$ for $0\\le q\\le Q$, and $U_{p0}=0=U_{pQ}$\nfor~$0\\le p\\le P$.\\quad\n(ii) Note that $u(r,\\pi)=u(r,-\\pi)$ so we have a periodic\nboundary condition in~$\\theta$, that is $U_{pQ}=U_{p0}$\nfor~$0\\le q\\le Q$.  Also, $u(0,\\theta)$ is independent of~$\\theta$,\nso $U_{0q}=U_{00}$ for $1\\le q\\le Q$.  Since $u=0$ when~$r=b$, we have\n$U_{Pq}=0$ for $0\\le q\\le Q$.  Thus, the $1+(P-1)Q$ unknowns are\n$U_{00}$ and $U_{pq}$ for $1\\le p\\le P-1$ and $1\\le q\\le Q$.  We can\napply the finite difference equation above\nfor $1\\le p\\le P-1$ and $1\\le q\\le Q$, giving $(P-1)Q$~equations.\nThe extra equation is\n\\[\n\\frac{-U_{1,Q/2}+2U_{00}-U_{1,Q}}{\\Delta r^2}\n\\frac{-U_{1,Q/4}+2U_{00}-U_{1,3Q/4}}{\\Delta r^2}=f(r_0,\\theta_0).\n\\]\n\\end{ans}\n\n\\end{Exercises}\n", "meta": {"hexsha": "6cae0b4327de97518734331ffae6df20709d3763", "size": 53222, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap5.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/chap5.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/chap5.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": 34.4033613445, "max_line_length": 81, "alphanum_fraction": 0.6330464845, "num_tokens": 22675, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.8688267813328976, "lm_q1q2_score": 0.7563982167143465}}
{"text": "\n\n\\section{Multivariate eda}\n\nGraphical exploration of data is essential.   There are a wide range of techniques for use with multivariate data, this week we examine some of the more common ones.   The aim of this week is to introduce you to some of these techniques, and provide pointers for more advanced ones.   You should save the code you use to generate these graphs in a short script file for future reference!\n\n\n\\section{A correlation paradox}\n\nHere's the correlation paradox we referred to.   Can you explain what's going on here?\n\n\\begin{Schunk}\n\\begin{Sinput}\n> u <- rnorm(100)\n> v <- rnorm(100)\n> w <- rnorm(100)\n> x <- u + v\n> y <- u + w\n> z <- v - w\n> X <- cbind(x, y, z)\n> cor(X)\n> pairs(X)\n\\end{Sinput}\n\\end{Schunk}\n\n\n\\section{Key eda techniques}\n\nFirst, we need to load some data and obtain the most important summary statistics.   We will load data on USArrests as well as irises.   As you go through the lab, if appropriate do try to produce graphs for the other dataset.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> data(USArrests)\n> `?`(USArrests)\n> cov(USArrests)\n> cor(USArrests)\n> colMeans(USArrests)\n> data(iris)\n> `?`(iris)\n\\end{Sinput}\n\\end{Schunk}\n\nThere are then a few ways of producing the ``standard'' pairwise scatterplots.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> pairs(USArrests)\n> library(lattice)\n> splom(USArrests)\n\\end{Sinput}\n\\end{Schunk}\n\n\nAs well as examining the relationships between variables, we may be interested in the relationship between individuals.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> heatmap(as.matrix(USArrests))\n> stars(USArrests, col.segments = c(\"red\", \"green\", \"blue\", \"pink\"), \n+     draw.segments = TRUE, full = FALSE)\n> require(MASS)\n> parcoord(iris[, -5], col = as.numeric(iris[, 5]))\n> source(\"andrews.R\")\n> andrews.curves(iris[, -5], cls = iris[, 5])\n\\end{Sinput}\n\\end{Schunk}\n\nYou can see for example that \\texttt{parcoord} and \\texttt{andrews.curves} take a data matrix as the first argument (in this case we specify the first four columns of the iris data), and a grouping factor as the second argument (with slightly different syntax).\n\n\n\\section{Interactive Graphics}\n\nYou've been given a short piece of code in the portal which helps draw 3d scatterplots on the \\texttt{rgl} device.   If you put this code in your working directory and ``source'' it, you should be able to create a simple dynamic 3d scatterplot.   Check out \\texttt{?rgl} if you want any help on the rgl device, in particular to see how you might go about saving an image!\n\n%<<rgl, fig = FALSE, echo = TRUE, results = hide>>=\n\n\\begin{verbatim}\nsource(\"rglellipsoid.R\")\nscatter3d(iris$Sepal.Length, iris$Sepal.Width, iris$Petal.Width,\n           ellipsoid=TRUE, surface=FALSE,\n           groups=as.factor(iris$Species))\n\\end{verbatim}\n%@ \n\n\n\\section{Simulating multivariate normal data and linear combinations}\n\nFirst, load the \\texttt{MASS} library which contains a function \\texttt{mvrnorm} which simulates multivariate normal data.   The first argument to \\texttt{mvrnorm} is $n$, the number of variate rows to generate, the second argument is the mean vector to use.   Here you see that we want to generate three observations, each with mean zero.   Finally, we need to specify the covariance matrix, we have done this on the previous line and stored the results in \\texttt{covmat}.\n\n\n\\begin{Schunk}\n\\begin{Sinput}\n> library(MASS)\n> covmat <- matrix(c(1, 0.7, 0.7, 0.7, 1, 0.7, 0.7, 0.7, 1), 3, \n+     3)\n> X <- mvrnorm(1000, c(0, 0, 0), covmat)\n\\end{Sinput}\n\\end{Schunk}\n\n\nHaving simulated some data (stored in the matrix \\texttt{X}), we are going to check the univariate normality of each margin.   The code below produces histograms and plots for the second column, you should check all three!\n\n\\begin{Schunk}\n\\begin{Sinput}\n> hist(X[, 2])\n> qqnorm(X[, 2])\n> qqline(X[, 2], col = \"red\")\n\\end{Sinput}\n\\end{Schunk}\n\\includegraphics{week1eda-uvnorm}\n\nFinally, to start thinking about linear combinations, try generating a few linear combinations e.g. $z_{i} = 2x_{i1}+0.2x_{i2}+0.15x_{i3}$ for all $i = 1, \\ldots, n$.\n\n\\begin{Schunk}\n\\begin{Sinput}\n> Z <- 2 * X[, 1] + 0.2 * X[, 2] + 0.15 * X[, 3]\n> hist(Z)\n\\end{Sinput}\n\\end{Schunk}\n\nTry different values for the coefficients (i.e replace $2, 0.2 and 0.15$ with other values) and see whether $\\boldsymbol{z}$ can be considered to be univariate normal.\n\n\n\\section{On your own}\n\nLoad the following libraries, and check out the following functions and data files:   \n\n\\begin{itemize}\n\\item Libraries: \\texttt{library(gclus)}, \\texttt{library(Flury)}\n\\item Functions: \\texttt{?cpairs}, \\texttt{?cparcoord} \n\\item Data: \\texttt{data(wines)}, \\texttt{data(turtles)} and \\texttt{data(flea.beetles)} (in other words, load the data and look at the helpfiles in the same way you check the helpfile for a function)\n\\end{itemize}\n\n\n\nDo also check out the correlation demo:\n\n\\begin{verbatim}\nlibrary(TeachingDemos)\nrun.cor.examp()\n\\end{verbatim}\n\n\n\n\n\n\n\\section{Summary of week1}\n\n\\fbox{\\parbox[c]{0.9\\textwidth}{\\color{blue}\n\\begin{itemize}\n\\item You should have answered the correlation paradox (although we will either discuss it in the lab or in the lecture in week 2)\n\\item You have started collecting a library of scripts that let you carry out a multivariate e.d.a. - for example you have a few lines of R that let you create star plot, with suitable legends and labels.   Save these carefully as we will assume from now on that given a set of data, you can quickly and efficiently conduct an exploratory data analysis\n  \\end{itemize}\n\n}}\n", "meta": {"hexsha": "2f6dc763ebc067a0289c77eba08e9c6776021edc", "size": 5499, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "newworksheet/week1eda.tex", "max_stars_repo_name": "phewson/mvstats", "max_stars_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "newworksheet/week1eda.tex", "max_issues_repo_name": "phewson/mvstats", "max_issues_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 11, "max_issues_repo_issues_event_min_datetime": "2020-08-28T16:37:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-28T16:49:11.000Z", "max_forks_repo_path": "newworksheet/week1eda.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.025477707, "max_line_length": 474, "alphanum_fraction": 0.7243135115, "num_tokens": 1614, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009549929797, "lm_q2_score": 0.8267117919359419, "lm_q1q2_score": 0.7563594079461509}}
{"text": "\n\\subsection{Arithmetic}\nNormally Eigenmath uses integer and rational number arithmetic.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n1/2+1/3\n\\end{Verbatim}\n\n$\\displaystyle \\frac{5}{6}$\n\nA floating point value causes Eigenmath to switch to floating point arithmetic.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n1/2+1/3.0\n\\end{Verbatim}\n\n$\\displaystyle 0.833333$\n\nAn integer or rational number result can be converted to a floating\npoint value by entering {\\it float}.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\n212^17\n\\end{Verbatim}\n\n$\\displaystyle 3529471145760275132301897342055866171392$\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nfloat\n\\end{Verbatim}\n\n$\\displaystyle 3.52947\\times10^{39}$\n\nThe following example shows how to enter a floating point value\nusing scientific notation.\n\n\\begin{Verbatim}[formatcom=\\color{blue}]\nepsilon = 1.0*10^(-6)\nepsilon\n\\end{Verbatim}\n\n$\\displaystyle \\varepsilon=1.0\\times10^{-6}$\n", "meta": {"hexsha": "7f6c06f7833eebf24298fd3d81a41b4a5efb49cb", "size": 911, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/arithmetic.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/arithmetic.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/arithmetic.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.1860465116, "max_line_length": 79, "alphanum_fraction": 0.7650933041, "num_tokens": 274, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7563594078416678}}
{"text": "\\section{RSA Algorithm}\n\n\\frame{\n{Part 5: RSA Algorithm}\n\n\\tableofcontents[currentsection,hideallsubsections, firstsection=1, sections={1-5}]\n}\n\n\n\\begin{frame}{The RSA Cryptosystem}\n  Turing's cryptography algorithm that we described in the previous sections was flawed. But there is a cryptographic algorithm based on modular arithmetic which is the base of much of the security of the internet.\\bigskip\n\n  The RSA algorithm involves computing the remainders of numbers raised to large powers.\n\\end{frame}\n\n\\subsection{Euler's Theorem}\n\n\\begin{frame}{Euler's Function}\n\n  The number of integers between $0$ and $n$ that are relatively prime to $n$ is represented by \\structure{Euler's Function}:\n  \\begin{equation*}\n    \\Phi(n) ::= \\# k\\in[0,n), GCD(k,n) = 1\n  \\end{equation*}\n  \\bigskip\n\n  For example:\n  \\begin{itemize}\n    \\item $\\Phi(7) = 6$, because $\\{1,2,3,4,5,6\\}$ are relatively prime to 7;\n    \\item $\\Phi(12) = 4$, because $\\{1,5,7,11\\}$ are relatively prime to 12;\n  \\end{itemize}\\bigskip\n\\end{frame}\n\n\\begin{frame}{Euler's Theorem}\n  The value of $\\Phi$ is important because of \\structure{Euler's Theorem}: If $n$ and $k$ are relatively prime, then\n  \\begin{equation*}\n    k^{\\Phi(n)} \\equiv 1 (\\text{mod } n)\n  \\end{equation*}\\bigskip\n\n  Additionally, Euler's function and Euler's theorem gives us another way to calculate modular inverses:\n  \\begin{itemize}\n    \\item $k^{\\Phi(n)} \\equiv 1$ (mod $n$)\n    \\item $k^{\\Phi(n)-1}\\times k \\equiv 1$ (mod $n$)\n  \\end{itemize}\n  So $k$ and $k^{\\Phi(n)-1}$ are inverses, modulo $n$.\n\\end{frame}\n\n%% TODO: Prove Euler's Theorem (Page 274)\n\n\n\\begin{frame}{Calculating $\\Phi(n)$}\n\n  We can calculate $\\Phi(n)$ quickly with some simple rules:\\bigskip\n\n  \\begin{itemize}\n  \\item If $n$ is prime, $\\Phi(n) = n-1$\\bigskip\n\n  \\item If $n$ is a power of a prime, $\\Phi(p^k) = p^k - p^{k-1}$\n    \\begin{itemize}\n    \\item Ex: $\\Phi(9) = 3^2 - 3 = 6 \\hspace{1cm} \\{1,2,4,5,7,8\\}$\n    \\end{itemize}\\bigskip\n\n  \\item If $n$ is $ab$ where GCD(a,b)=1, $\\Phi(ab) = \\Phi(a)\\Phi(b)$\n    \\begin{itemize}\n    \\item Ex: $\\Phi(12) = \\Phi(3) \\times \\Phi(4) = (3-1)\\times (2^2 - 2) = 4$\n    \\end{itemize}\n  \\end{itemize}\n\\end{frame}\n\n% RSA\n\n\\subsection{RSA Algorithm}\n\\begin{frame}\n  \\frametitle{The RSA Encryption System}\n\n  The RSA, created in 1977, is a \\structure{Public Key Cyrptosystem}. This means that, unlike the Turing algorithm, it is not necessary to exchange a secret key between the \\emph{sender} and the \\emph{receiver}.\\bigskip\n\n  The RSA uses Euler's theorem for encrypting and decrypting messages, and its security is based on the difficulty of factoring large numbers.\n\\end{frame}\n\n\\begin{frame}{The RSA System}{Algorithm}\n\n  {\\bf Preparation}\n  \\begin{itemize}\n    \\item Generate two distinct large primes, $p$ and $q$, which are secret\n    \\item Let $n = pq$\n    \\item Create a \\structure{public key} $e \\in [0..n)$ such that gcd$(e, (p-1)(q-1)) = 1$;\n    \\item Create a \\structure{private key} $d \\in [0..n)$ be the modular inverse of $e$ (mod $(p-1)(q-1)$);\n  \\end{itemize}\\bigskip\n\n  {\\bf Encoding a Secret Message}\n  \\begin{itemize}\n    \\item Given a message $m \\in [0..n)$, construct the encrypted message as $\\hat{m} = m^e (\\text{mod }n)$\n  \\end{itemize}\\bigskip\n\n  {\\bf Decoding a Secret Message}\n  \\begin{itemize}\n    \\item Given an encrypted message $\\hat{m}$, it is decrypted as $m = \\hat{m}^d (\\text{mod }n)$\n  \\end{itemize}\\bigskip\n\\end{frame}\n\n\\begin{frame}{The RSA System}{Assumptions}\n\n  \\begin{itemize}\n  \\item \\structure{Basic Assumption:} {\\bf One Way Functions}\n    that are \\structure{easy to compute} but \\alert{hard to invert}\n\n    \\bigskip\n\n  \\item It is \\structure{easy} to compute the product $n$ of\n    two \\structure{large primes} $p$ and $q$ ($n = pq$)\n\n    \\bigskip\n\n  \\item It is \\alert{very hard} to \\structure{factor} $n$\n    into $p$ and $q$.\n\n  \\end{itemize}\n\\end{frame}\n", "meta": {"hexsha": "caa675fab9ea9bc819163290c82d600fe8d7238a", "size": 3860, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "week03/05_RSA.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/05_RSA.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/05_RSA.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.4369747899, "max_line_length": 222, "alphanum_fraction": 0.6634715026, "num_tokens": 1296, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473813156294, "lm_q2_score": 0.8670357666736772, "lm_q1q2_score": 0.7563563805647714}}
{"text": "\\nocite{*}\n\n\\begin{appendix}\n\n\\section{Mathematical developments}\n\n\\subsection{Random positioning optimization}\n\nThis section presents the methods used for the random positioning of points that must respect certain properties.\nA first approach would be to hide the points not respecting the required conditions.\nIt is more efficient to draw only points having already the required properties.\n\n\\subsubsection{Continuous uniform distribution in a circle}\\label{sec:circle-random-position}\n\nA polar coordinate system \\( (\\varphi, r) \\) is used in a disk of radius \\( R_0 \\) in which random positions are to be drawn.\nThe probability density of presence of a point in the disk is \\( 1 / \\left( \\pi {R_0}^2 \\right) \\).\nAt each random draw, the probability to find the dislocation in the surface element \\( r dr d\\varphi\\) is then:\n\n\\begin{equation}\n  \\frac{r dr d\\varphi}{\\pi {R_0}^2} =\n    \\frac{2 r}{{R_0}^2} dr \\frac{1}{2 \\pi} d\\varphi\n\\end{equation}\n\n\\bigskip\n\nLet \\( \\phi \\) and \\( R \\) be two random variables such that \\( \\phi(\\omega) \\in [0, 2\\pi[ \\) and \\( R(\\omega) \\in [0, R_0] \\). Let \\( f_\\phi \\) and \\( f_R \\) be the probability density functions of \\( \\phi \\) and \\( R \\), respectively.\n\n\\begin{equation}\n  f_\\phi(\\varphi) =\n    \\frac{1}{2 \\pi}\n\\end{equation}\n\n\\begin{equation}\n  f_R(r) =\n    \\frac{2r}{{R_0}^2}\n\\end{equation}\n\n\\medskip\n\nLet \\( F_\\phi \\) and  \\( F_R \\) be the  cumulative distribution functions of \\( \\phi \\) and \\( R \\), respectively.\n\n\\begin{equation}\n  F_\\phi(\\varphi) =\n    \\mathbb{P}(\\phi \\leq \\varphi) =\n      \\int_0^\\varphi f_\\phi(t) dt = \\frac{\\varphi }{2 \\pi}\n\\end{equation}\n\n\\begin{equation}\n  F_R(r) =\n    \\mathbb{P}(R \\leq r) =\n      \\int_0^r f_R(t) dt = \\left( \\frac{r}{R_0} \\right)^2\n\\end{equation}\n\n\\medskip\n\nLet \\( X_\\phi \\) and \\( X_R \\) be two new random variables defined using \\( \\phi \\) and \\( R \\) such that \\( X_\\phi \\) and \\( X_R \\) follow a uniform law \\( U(0, 1) \\).\n\n\\begin{equation}\n  X_\\phi =\n    \\frac{\\phi}{2 \\pi}\n\\end{equation}\n\n\\begin{equation}\n  X_R =\n    \\left( \\frac{R}{R_0} \\right)^2\n\\end{equation}\n\n\\medskip\n\nSince \\( X_\\phi \\sim U(0, 1) \\) and \\( X_R \\sim U(0, 1) \\), the random position \\( (\\varphi, r)\\) of a point on the disk can be choosen with the sampling \\( ( x_\\phi, x_R ) \\) of two uniformly distributed random variables \\( X_\\phi \\) and \\( X_R \\):\n\n\\begin{equation}\\label{eq:circle-random-position-theta}\n  \\varphi =\n    2 \\pi x_\\phi\n\\end{equation}\n\n\\begin{equation}\\label{eq:circle-random-position-r}\n  r =\n    R_0 \\sqrt{x_R}\n\\end{equation}\n\n\\subsubsection{Drawing of points in cell walls}\\label{sec:cell-random-position}\n\n\\bigfig{fig:cell-random-position}{insert/positions}{walls}{Division of the surface occupied by the walls}\n\nTo randomly select points in the cell borders, 4 virtual rectangles \\( A, B, C, D \\) are created in each cell. If the probability of presence in the cell is given by \\( P = \\gls{area}_{\\text{cell}} / \\gls{area}_{\\gls{roi}} \\), then the probability of presence in the rectangles is given by \\( P_A = P_B = P_C = P_D = P / 4 \\).\nThe position in the selected rectangle is then chosen by applying a uniform continuous law.\n\n\\subsection{Overlapping}\\label{sec:overlapping}\n\n\\subsubsection{Circular segment area}\n\nFor the area shaded in \\figref{fig:overlapping:circular-segment} the formula is obtained by calculating the angle between d and r.\n\n\\begin{minipage}{0.5\\linewidth}\n  \\bigfig{fig:overlapping:circular-segment}{insert/overlapping}{circular_segment}{Circular segment area}\n\\end{minipage}%\n\\begin{minipage}{0.5\\linewidth}\n  \\begin{equation}\\label{eq:overlapping:circular-segment}\n    \\cirseg(r, d) =\n      r^2 \\arccos\\left( \\frac{d}{r} \\right) - d \\sqrt{r^2 - d^2}\n  \\end{equation}\n\\end{minipage}%\n\n\\subsubsection{Intersection area of two circles}\\label{sec:circle-circle-intersection}\n\nThe area of intersection of two circles of radius \\( r \\) and \\( R \\) whose centers are spaced by a distance \\( d \\) as shown in \\figref{fig:circle-circle-intersection} can be calculated using equation \\eqref{eq:overlapping:circular-segment}. The expression is given by the function \\( \\circir (r, R, d) \\) in equation \\eqref{eq:circle-circle-intersection}.\n\n\\begin{align}\n  \\gls{area}_0 (r, R, d) & =\n    \\textstyle\n    \\cirseg \\left(r, \\frac{d^2 + r^2 - R^2}{2 d} \\right) + \\cirseg \\left( R, \\frac{d^2 + R^2 - r^2}{2 d} \\right)\n  \\\\[1mm]\n  \\gls{area}_0 (r, R, d) & =\n    \\textstyle\n    r^2 \\arccos \\left( \\frac{d^2 + r^2 - R^2}{2 d r} \\right)\n    + R^2 \\arccos \\left( \\frac{d^2 + R^2 - r^2}{2 d R} \\right)\n    - \\frac{\\sqrt{(-d+r+R)(d+r-R)(d-r+R)(d+r+R)}}{2}\n\\end{align}\n\n\\begin{minipage}{0.5\\linewidth}\n  \\bigfig{fig:circle-circle-intersection}{insert/overlapping}{circle_circle}{Intersection of two circles}\n\\end{minipage}%\n\\begin{minipage}{0.5\\linewidth}\n  \\begin{equation}\\label{eq:circle-circle-intersection}\n    \\circir (r, R, d) =\n    \\begin{cases}\n      0 & \\text{for } r + R < d \\\\[2mm]\n      \\pi r^2 & \\text{for } d + r < R \\\\[2mm]\n      \\pi R^2 & \\text{for } d + R < r \\\\[2mm]\n      \\gls{area}_0 (r, R, d) & \\text{else}\n    \\end{cases}\n  \\end{equation}\n\\end{minipage}%\n\n\\subsubsection{Intersection area of a circle and a square}\\label{sec:circle-square-intersection}\n\n\\bigfig{fig:overlapping:circle-square-examples}{insert/overlapping}{circle_square}{Some possibilities of overlapping of a square and a circle}\n\nIn order to calculate the area \\cirsqr \\ of intersection between a circle of radius \\( r \\) and a square of side \\( S \\) one would have to distinguish many cases of the circle overtaking the right, left and bottom of the square.\nTo simplify the distinction of cases the study is limited to one quadrant of the circle in a first time.\nThe area of the quadrant outside the square is calculated and the contribution of each quadrant is summed and subtracted from the area of the circle to obtain the total area of intersection.\n\\figref{fig:overlapping:circle-square-quadrants} show the different considered possibilities in a circle quadrant.\n\n\\bigfig{fig:overlapping:circle-square-quadrants}{insert/overlapping}{quadrants}{Possibilities illustrated in the upper right circle quadrant}\n\n\\bigskip\n\nThe occurrence of the cases presented in \\figref{fig:overlapping:circle-square-quadrants} is formally defined as a function of \\( d_1 \\), \\( d_2 \\) and \\( r \\) in equations \\eqref{eq:quadrant-case-1}, \\eqref{eq:quadrant-case-2} and \\eqref{eq:quadrant-case-3}.\n\n\\begin{align}\n  C1 &\\Longleftrightarrow \\left( \\neg C3 \\right) \\wedge \\left( d_1 < r \\right) \\label{eq:quadrant-case-1} \\\\\n  C2 &\\Longleftrightarrow \\left( \\neg C3 \\right) \\wedge \\left( d_2 < r \\right) \\label{eq:quadrant-case-2} \\\\\n  C3 &\\Longleftrightarrow \\left( d_1^2 + d_2^2 < r^2 \\right) \\label{eq:quadrant-case-3}\n\\end{align}\n\n\\medskip\n\nThe areas grayed in \\figref{fig:overlapping:circle-square-quadrants} are expressed in \\eqref{eq:overlapping:area-12} and \\eqref{eq:overlapping:area-3} using \\( \\cirseg(r, d) \\) defined in equation \\eqref{eq:overlapping:circular-segment}.\n\\begin{align}\n\\gls{area}_{1 \\lor 2} (r, d) &= \\frac{\\cirseg(r, d)}{2} \\label{eq:overlapping:area-12} \\ \\text{for } C1 \\text{ or } C2 \\\\\n\\gls{area}_3 (r, d_1, d_2) &= \\frac{\\pi r^2}{4} - d_1 d_2 \\label{eq:overlapping:area-3} \\ \\text{for } C3\n\\end{align}\n\n\\medskip\n\nThe area \\( \\gls{area}_Q (r, d_1, d_2) \\) outside a quadrant is then given in equation \\eqref{eq:outside-quadrant}.\n\n\\begin{equation}\\label{eq:outside-quadrant}\n  \\gls{area}_Q (r, d_1, d_2) =\n    \\gls{indfun}_{C1} \\gls{area}_{1 \\lor 2} (r, d_1) +\n    \\gls{indfun}_{C2} \\gls{area}_{1 \\lor 2} (r, d_2) +\n    \\gls{indfun}_{C3} \\gls{area}_{3} (r, d_1, d_2)\n\\end{equation}\n\n\\medskip\n\nFinally, to obtain the area \\( \\cirsqr (r, S, x, y) \\) of intersection between a circle of radius \\( r \\) centered in \\( (x, y) \\) and a square of side \\( S \\), the contribution of each quadrant is taken into account in equation \\eqref{eq:circle-square-intersection}.\n\n\\begin{equation}\\label{eq:circle-square-intersection}\n  \\cirsqr (r, S, x, y) =\n    \\pi r^2\n    - \\gls{area}_Q (r,     x,     y)\n    - \\gls{area}_Q (r, S - x,     y)\n    - \\gls{area}_Q (r,     x, S - y)\n    - \\gls{area}_Q (r, S - x, S - y)\n\\end{equation}\n\n\\subsubsection{Average intersection area of two circles}\n\nThe expected value of intersection of two circles of radius \\( r \\) and \\( R \\) whose centers are spaced by a random distance \\( D \\in [0, R] \\) is given by the function \\( \\gls{expval} \\left( \\circir (r, R, D) \\right) \\) defined in equation \\eqref{eq:mean-circle-circle-intersection}.\nFor a uniform distribution of points, \\( \\textstyle D = R \\sqrt{X} \\) with \\( X \\) following a uniform law \\( U(0, 1) \\) as explained in \\ref{sec:circle-random-position}.\n\n\\begin{equation}\\label{eq:mean-circle-circle-intersection}\n  \\gls{expval} \\left( \\circir(r, R, D) \\right) =\n    \\int_{x=0}^1 \\circir (r, R, R \\sqrt{x}) dx\n\\end{equation}\n\n\\bigfig{fig:mean-circle-circle-intersection}{insert/overlapping}{mean_circle_circle}{Comparison of the analytical formulation \\eqref{eq:mean-circle-circle-intersection} of \\( \\gls{expval} \\left( \\circir \\right) \\) with a simulation}\n\n\\subsubsection{Average intersection area of a circle and a square}\n\nLet \\( S \\) be the side of a square and \\( r \\) the circle of a radius.\nLet \\( X \\) and \\( Y \\) be two random variables following a uniform law \\( U(0, S) \\).\nHere it is sought the analytical expression of \\( \\gls{expval} \\left( \\cirsqr (r, S, X, Y) \\right) \\).\n\\figref{fig:overlapping:application-areas} show the areas of occurrence of the cases presented in \\figref{fig:overlapping:circle-square-quadrants}.\nWhen the center \\( ( X, Y ) \\) of the circle is choosen in a gray area of \\figref{fig:overlapping:application-areas}, then we calculate the corresponding air in \\figref{fig:overlapping:circle-square-quadrants}.\nThe probability that the center of the circle is chosen in a gray area is proportional to the area of the area since the law is uniform.\nBut the air outside the square depends on the position.\nIt will therefore be necessary to integrate these areas over the positions of occurrence.\n\n\\bigfig{fig:overlapping:application-areas}{insert/overlapping}{application_areas}{Case application areas for various radius values}\n\n\\medskip\n\nIt is defined limits of integration from \\figref{fig:overlapping:application-areas}.\n\n\\begin{align}\n  \\varphi_1 &=\n    \\arccos \\left( \\frac{S}{\\max(r, S)} \\right) \\\\\n  \\varphi_2 &=\n    \\arctan \\left( \\frac{S}{\\min(r, S)} \\right) \\\\\n  \\varphi_3 &=\n    \\arcsin \\left( \\frac{S}{\\max(r, S)} \\right) \\\\\n  x_1 (\\varphi) &=\n    \\frac{\\min(r, S)}{\\cos{\\varphi}} \\\\\n  x_2 (\\varphi) &=\n    \\frac{S}{\\sin{\\varphi}}\n\\end{align}\n\n\\medskip\n\nThe contributions for one quadrant of the different cases can then be expressed.\n\n\\begin{align}\n  \\gls{expval} \\left( \\gls{area}_{1 \\lor 2} \\right) &=\n    \\frac{1}{S^2} \\left(\n    \\int_{\\varphi = \\varphi_1}^{\\varphi_2}\n    \\int_{x=r}^{x_1(\\varphi)}\n    \\gls{area}_{1 \\lor 2} (r, x \\cos \\left( \\varphi) \\right)\n    x dx d\\varphi\n    +\n    \\int_{\\varphi = \\varphi_2}^{\\varphi_3}\n    \\int_{x=r}^{x_2(\\varphi)}\n    \\gls{area}_{1 \\lor 2} (r, x \\cos \\left( \\varphi) \\right)\n    x dx d\\varphi\n    \\right)\n  \\\\\n  \\gls{expval} \\left( \\gls{area}_{3} \\right) &=\n    \\frac{1}{S^2} \\left(\n    \\int_{\\varphi = \\varphi_1}^{\\varphi_3}\n    \\int_{x=0}^{r}\n    \\gls{area}_{3} \\left( r, x \\sin(\\varphi), x \\cos(\\varphi) \\right)\n    x dx d\\varphi\n    +\n    2 \\int_{y = 0}^{S}\n    \\int_{x=0}^{\\tan(\\varphi_1)y}\n    \\gls{area}_{3} \\left( r, x, y \\right)\n    dx dy\n    \\right)\n\\end{align}\n\n\\medskip\n\nFinally, for the mean intersection area, the contribution of each quadrant is taken into account.\n\n\\begin{equation}\\label{eq:mean-circle-square-intersection}\n  \\gls{expval} \\left( \\cirsqr (r, S, X, Y) \\right) =\n    \\begin{cases}\n      0 &\\text{if } r = 0\n      \\\\\n      \\pi r^2 - 4 \\left(2 \\gls{expval} \\left( \\gls{area}_{1 \\lor 2} \\right) +\\gls{expval} \\left( \\gls{area}_{3} \\right)\\right) &\\text{if } r \\in \\ ] 0, \\sqrt{2} S [\n      \\\\\n      S^2 &\\text{if } r \\geq \\sqrt{2} S\n    \\end{cases}\n\\end{equation}\n\n\\bigfig{fig:mean-circle-square-intersection}{insert/overlapping}{mean_circle_square}{Comparison of the analytical formulation \\eqref{eq:mean-circle-square-intersection} of \\( \\gls{expval} \\left( \\cirsqr \\right) \\) with a simulation}\n\n\\subsubsection{Conjecture}\n\nThe behavior of the expected value of overlapping area becomes simple when it is integrated over a radius of neighborhood \\( r \\in [r_0, +\\infty[\\).\nIt seems that for at least some functions \\( f \\) we have the relation given in equations \\eqref{eq-conjecture-circle} and \\eqref{eq-conjecture-square}.\n\\( \\mathcal{D}_{\\symcirclecircle f} \\) and \\( \\mathcal{D}_{\\symcirclesquare f} \\) are multiplicative constants of the size of the region of interest.\nThey introduce an equivalent effective size of the latter.\n\n\\begin{align}\n  \\int_{r=r_0}^{+\\infty} f(r) \\frac{d \\gls{expval} \\left( \\circir (r, R, D) \\right)}{dr} dr\n    \\ \\underset{\\frac{r_0}{R_{\\gls{roi}}} \\rightarrow 0}{\\sim} \\\n    \\int_{r=r_0}^{\\mathcal{D}_{\\symcirclecircle f} R} f(r) 2 \\pi r dr\n  \\label{eq-conjecture-circle} \\\\[2mm]\n  \\int_{r=r_0}^{+\\infty} f(r) \\frac{d \\gls{expval} \\left( \\cirsqr (r, S, X, Y) \\right)}{dr} dr\n    \\ \\underset{\\frac{r_0}{R_{\\gls{roi}}} \\rightarrow 0}{\\sim} \\\n    \\int_{r=r_0}^{\\mathcal{D}_{\\symcirclesquare f} S} f(r) 2 \\pi r dr\n  \\label{eq-conjecture-square}\n\\end{align}\n\n\\section{Data}\\label{sec:data}\n\nThe construction and analysis of the data produced for the study was automated.\nEverything was done from a same directory called \\textit{workspace}.\nThis repository contains the parameters and the the scripts that will allow you to replicate the results obtained.\nThe installation of the three packages mentioned above is necessary for the execution of the scripts.\n\n\\bigskip\n\nYou can find the scripts and documentations here: \\github{lpa-workspace}\n\n\\bigskip\n\nYou can also clone the project in tour local directory with git:\n\n\\begin{tcolorbox}[width=\\linewidth, title=shell]\n\\begin{verbatim}\n$ cd <the-place-you-want-to-clone-the-repository>\n$ git clone https://github.com/DunstanBecht/lpa-workspace.git\n\\end{verbatim}\n\\end{tcolorbox}\n\n\\bigskip\n\nThe following pages provide a summary of the data generated for each distribution studied.\n\n\\newpage\n\n\\begin{multicols}{2}\n\n\\input{load/tex/appendix}\n\n\\null\n\n\\end{multicols}\n\n\\section{Glossary}\n\n\\printnoidxglossaries\n\n\\newpage\n\n\\printbibliography[heading=bibintoc, heading=bibnumbered]\n\n\\end{appendix}\n", "meta": {"hexsha": "6aafa7a3230aecd2d0e2b452c6b82e319ad3508f", "size": 14385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/include/appendix.tex", "max_stars_repo_name": "DunstanBecht/lpa-workspace", "max_stars_repo_head_hexsha": "316db41fed08f856c376e7f8e2ff92f2af5ecf7d", "max_stars_repo_licenses": ["CC0-1.0"], "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/include/appendix.tex", "max_issues_repo_name": "DunstanBecht/lpa-workspace", "max_issues_repo_head_hexsha": "316db41fed08f856c376e7f8e2ff92f2af5ecf7d", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "report/include/appendix.tex", "max_forks_repo_name": "DunstanBecht/lpa-workspace", "max_forks_repo_head_hexsha": "316db41fed08f856c376e7f8e2ff92f2af5ecf7d", "max_forks_repo_licenses": ["CC0-1.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.9387755102, "max_line_length": 357, "alphanum_fraction": 0.6823079597, "num_tokens": 4830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8670357683915538, "lm_q1q2_score": 0.756356376308476}}
{"text": "\\section{Systems of linear equations}\n\\subsection{Defintions}\nEverything we learned so far about vectors and matrices can be used to solve and characterise a family of equations known as \\emph{linear equations}. You're probably already very familiar with linear equations: they are equations in which the \\emph{variables} appear directly, without any power or other functions acting on them. For example, the simple equation\n\\begin{equation}\n\ty = ax+b,\n\t\\label{eq:linear_equation_2_vars}\n\\end{equation}\nwhere $x,y$ are both variables and $a,b$ are both constant real numbers is a linear equation. \\autoref{eq:linear_equation_2_vars} can be re-written as\n\\begin{equation}\n\tax - y + b = 0,\n\t\\label{eq:linear_equation_2_vars_rewritten}\n\\end{equation}\nwhere now $a$ is the \\emph{coefficient} of the variable $x$, while the variable $y$ has the coefficient $-1$ and $b$ is a so-called \\emph{free coefficient}. In general, a linear equation of two variables has the form\n\\begin{equation}\n\ta_{0} + a_{x}x + a_{y}y = 0,\n\t\\label{eq:general_linear_equation_2_vars}\n\\end{equation}\ni.e. we changed the name of $a$ to $a_{x}$ and $b$ to $a_{0}$, and gave $y$ the coefficient $a_{y}$. We can also rename $x$ and $y$ to $x_{1}$ and $x_{2}$, respectively, and name their coefficients accordingly:\n\\begin{equation}\n\ta_{0} + a_{1}x_{1} + a_{2}x_{2} = 0.\n\t\\label{eq:general_linear_equation_2_vars_renamed}\n\\end{equation}\n\nThe form shown in \\autoref{eq:general_linear_equation_2_vars_renamed} can be easily expanded into $n$ variables:\n\\begin{equation}\n\ta_{0} + a_{1}x_{1} + a_{2}x_{2} + a_{3}x_{3} + \\cdots + a_{n-1}x_{n-1} + a_{n}x_{n} = 0,\n\t\\label{eq:general_linear_equation_n_vars}\n\\end{equation}\nwhere $x_{1},x_{2},\\dots,x_{n}$ are the variables of the equation, and $a_{0},a_{1},\\dots,a_{n}$ are its coefficients. We say that $n$ is the \\emph{order} (also: \\emph{degree}) of the equation.\n\n\\begin{note}{Number set used for linear equations}{}\n\tAs with other topics, in the context of this section both the variables and coefficients are all \\textbf{real numbers}, however almost anything we discuss here can genrally be applied to complex numbers or other structures.\n\\end{note}\n\n\\begin{example}{Linear equations}{}\n\tThe following is a linear equation of order $3$, using the variables $x,y,z$:\n\t\\[\n\t\t3x+2y-z+4 = 0.\n\t\\]\n\tThe coefficients of the equation are\n\t\\begin{align*}\n\t\ta_{0}&=4,\\\\\n\t\ta_{x}&=a_{1}=3,\\\\\n\t\ta_{y}&=a_{2}=2,\\\\\n\t\ta_{z}&=a_{3}=-1.\n\t\\end{align*}\n\n\tAnother linear equation of the same three variables is\n\t\\[\n\t\t5x-2y+1 = 0.\n\t\\]\n\tIn this case the coefficient $a_{z}=a_{3}=0$. Depending on the context, this equation can be considered as either an equation of order $3$ or an equation of order $2$.\n\\end{example}\n\nIn $\\Rs{2}$ linear equations represent a line, which doesn't necesserally go through the origin (and thus isn't necesserally a subspace of $\\Rs{n}$). For a line to go through the origin, the free coefficient $a_{0}$ must equal zero (see \\autoref{fig:linear_equations_2_vars}).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=9cm, height=9cm,\n\t\t\txmin=-1, xmax=6,\n\t\t\tymin=-1, ymax=6,\n\t\t\tdomain={-1:6},\n\t\t]\n\t\t\\addplot[function, xred] {2*\\x} node[pos=0.27, below, font=\\Large, rotate=63.435] {$-2x+y=0$};\n\t\t\\addplot[function, xblue] {-0.5*\\x+5} node[pos=0.7, above, font=\\Large, rotate=-30] {$\\frac{1}{2}x+y+5=0$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Two linear equations represented as lines in $\\Rs{2}$. Note how in the red equation the free coefficient is zero, and so the line goes through the origin.}\n\t\\label{fig:linear_equations_2_vars}\n\\end{figure}\n\nIn $\\Rs{3}$ linear equations represent planes. Much like with the lines in $\\Rs{2}$, these planes don't necesserally go through the origin. The trend continues with increasing dimensions: in $\\Rs{4}$ linear equations represent $3$-dimensional spaces, in $\\Rs{5}$ linear equations represent $4$-dimensional spaces, etc. When the free coefficient is equal to zero, these spaces become subspaces of the respective $\\Rs{n}$.\n\t\t\n\\begin{figure}\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t% The trick with the labels is copied from https://tex.stackexchange.com/questions/212699/text-projection-onto-plane-in-3d-pgf-plots\n\t\t\\def\\h{58}\n\t\t\\def\\v{30}\n\t\t\\begin{axis}[\n\t\t\twidth=9cm, height=9cm,\n\t\t\tview={\\h}{\\v},\n\t\t\t]\n\t\t\t% Plots\n\t\t\t\\pgfplotsset{plane/.style={surf, faceted color={#1!75!black!50}, fill={#1!20}, opacity=0.8, samples=6}}\n\t\t\t\\addplot3[plane={xpurple}, domain=-4:0, y domain=-4:0, samples=3] {-1};\n\t\t\t\\addplot3[plane={xpurple}, domain=-4:0, y domain=0:4, samples=3] {-1};\n\t\t\t\\addplot3[plane={xorange}, domain=-4:4] {-0.5*\\x};\n\t\t\t\\addplot3[plane={xpurple}, domain=0:4, y domain=-4:0, samples=3] {-1};\n\t\t\t\\addplot3[plane={xpurple}, domain=0:4, y domain=0:4, samples=3] {-1};\n\t\t\t\\addplot3[mark=*] coordinates { (0,0,0) };\n\n\t\t\t% Labels\n\t\t\t\\pgfmathparse{atan(tan(\\h)*sin(\\v))}\n\t\t\t\\let\\a=\\pgfmathresult\n\t\t\t\\pgfmathparse{atan(tan(90-\\h)*sin(\\v))}\n\t\t\t\\let\\b=\\pgfmathresult\n\t\t\t\\path (axis cs:-2.5,-1.5,1.25) -- (axis cs:-2.5,-0.5,1.25) node[color=xdarkorange, midway, above, sloped, xslant=tan(\\a+\\b+110), yscale=sin(\\a+\\b), font=\\Huge] {$\\frac{1}{2}x+z=0$};\n\t\t\t\\path (axis cs:3.5,-1.5,-1) -- (axis cs:3.5,-0.5,-1) node[color=xdarkpurple, midway, above, sloped, xslant=tan(\\a+\\b+80), yscale=sin(\\a+\\b), font=\\Huge] {$z+1=0$};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\t\\caption{Two intersecting planes in $\\Rs{3}$ with their corresponding equations.}\n\t\\label{fig:line_plane_R3}\n\\end{figure}\n\n\\subsection{Systems and matrix form}\nA \\emph{system of linear equations} is a set of linear equations using the same variables. For example, the three equations\n\\[\n\t\\begin{cases}\n\t\t&2x-5y+4z+2=0\\\\\n\t\t&-3x-2y+1=0\\\\\n\t\t&5x+4z+-3=0\\\\\n\t\\end{cases}\n\\]\nform together a system of $3$ linear equations with $3$ variables ($x,y$ and $z$). Systems of linear equations can be written together in matrix form: in the above example, the system can be represented as the equation\n\\[\n\t\\begin{bmatrix}\n\t\t2 & -5 & 4\\\\\n\t\t-3 & -2 & 0 \\\\\n\t\t5 & 0 & 4\n\t\\end{bmatrix}\\colvec{x;y;z} + \\colvec{2;1;-3} = \\colvec{0;0;0}, \n\\]\nsince performing the matrix-vector product and vector addition yields back the system of equations. We call the matrix the \\emph{coefficients matrix} of the equation.\n\n\\begin{note}{}{}\n\tIn practice, many times the vector representing the free coefficients is moved to the right hand side of the equation. In the case of the above system this yields the simple equation\n\t\\[\n\t\t\\begin{bmatrix}\n\t\t\t2 & -5 & 4\\\\\n\t\t\t-3 & -2 & 0 \\\\\n\t\t\t5 & 0 & 4\n\t\t\\end{bmatrix}\\colvec{x;y;z} = \\colvec{-2;-1;3}. \n\t\\]\n\\end{note}\n\nIn the most general form, a system of $m$ equations in $n$ variavles $x_{1},x_{2},x_{3},\\dots,x_{n}$ can be represented as the product of an $m\\times n$ coefficient matrix and the variables vector, yielding the free-coefficient vector:\n\n\\vspace{1em}\n\\begin{equation}\n\t\\begin{bNiceMatrix}[name=coeffMat_mxn]\n\t\ta_{11} & a_{12} & \\cdots & a_{1n}\\\\\n\t\ta_{21} & a_{22} & \\cdots & a_{2n}\\\\\n\t\t\\vdots & \\vdots & \\Ddots & \\vdots\\\\\n\t\ta_{m1} & a_{m2} & \\cdots & a_{mn}\n\t\t\\end{bNiceMatrix}\\begin{bNiceMatrix}[name=varVec]x_{1}\\\\x_{2}\\\\x_{3}\\\\\\vdots\\\\x_{n}\\end{bNiceMatrix} = \\begin{bNiceMatrix}[name=freeCoeffVec]b_{1}\\\\b_{2}\\\\\\vdots\\\\b_{m}\\end{bNiceMatrix},\n\t\\label{eq:n_eqs_m_vars}\n\\end{equation}\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t% Highlights\n\t\\node[mathl={xred!30}, fit=(coeffMat_mxn-1-1)(coeffMat_mxn-4-4)] {};\n\t\\node[mathl={xblue!30}, fit=(varVec-1-1)(varVec-5-1)] {};\n\t\\node[mathl={xgreen!30}, fit=(freeCoeffVec-1-1)(freeCoeffVec-4-1)] {};\n\n\t% Texts\n\t\\tikzset{node distance=2cm and 2mm}\n\t\\node[xred, below of=coeffMat_mxn-4-2, xshift=-5mm] (coeffMatTxt) {$\\bm{m}\\times \\bm{n}$ coefficients};\n\t\\node[xblue, below of=varVec-5-1] (varVecTxt) {$\\bm{n}$ variables};\n\t\\node[xgreen, below of=freeCoeffVec-4-1, xshift=15mm] (freeCoeffTxt) {$\\bm{m}$ free coefficients};\n\t\n\t% Arrows\n\t\\draw[vector, thin, xred] (coeffMatTxt) to [out=90, in=-90] ($(coeffMat_mxn-4-2)-(0,5mm)$);\n\t\\draw[vector, thin, xblue] (varVecTxt) to [out=90, in=-90] ($(varVec-5-1)-(0,5mm)$);\n\t\\draw[vector, thin, xgreen] (freeCoeffTxt) to [out=90, in=-90] ($(freeCoeffVec-4-1)-(0,5mm)$);\n}\n\n\\vspace{5em}\nwhich can be written succinctly as\n\\begin{equation}\n\t\\colorbox{xred!30}{$A$}\\colorbox{xblue!30}{$x$} = \\colorbox{xgreen!30}{$b$}.\n\t\\label{eq:system_equations_sussinct}\n\\end{equation}\n\n\n\\subsection{Solutions}\nA system of linear equations can have one or more \\emph{solutions}. A solution is a tuple\n\\[\n\ts=\\left(s_{1},s_{2},\\dots,s_{n}\\right)\n\\]\nsuch that if we substitute each $s_{i}$ into the respective variable $x_{i}$ all equation become \\true{} statements.\n\n\\begin{example}{Solutions of a system of linear equations}{}\n\tThe following linear system\n\t\\[\n\t\t\\begin{cases}\n\t\t\t&-4x+2y=0\\\\\n\t\t\t&x-y+3=0\n\t\t\\end{cases}\n\t\\]\n\thas the solution\n\t\\[\n\t\ts = (-1,2).\n\t\\]\n\tIndeed if we substitute $x=-1$ and $y=2$ into the system we get\n\t\\[\n\t\t\\begin{cases}\n\t\t\t&-4\\cdot(-1)+2\\cdot(2)=-4+4=0\\ \\Rightarrow\\ \\true{}\\\\\n\t\t\t&-1-2+3=-3+3=0\\ \\Rightarrow\\ \\true{}\n\t\t\\end{cases}\n\t\\]\n\\end{example}\n\nIn the graphical representation of linear equations, the solutions of a system are the points where the respective graphs representing the equation (line, plane, etc.) intersect.\n\n\\begin{example}{Solutions of a system of linear equations - graph}{sys_solution}\n\tThe linear system from the previous example can be represented by the following graph:\n\t\n\t\\vspace{2em}\n\t\\centering\n\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=9cm, height=9cm,\n\t\t\txmin=-4, xmax=4,\n\t\t\tymin=-4, ymax=4,\n\t\t\tdomain={-4:4},\n\t\t\tmajor grid style={black!10},\n\t\t]\n\t\t\\pgfmathsetmacro{\\A}{-2}\n\t\t\\pgfmathsetmacro{\\B}{1}\n\t\t\\addplot[function, xred] {\\A*\\x} node[pos=0.63, above, rotate={atan(\\A)}] {$4x+2y=0$};\n\t\t\\addplot[function, xblue] {\\B*\\x+3} node[pos=0.22, above, rotate={atan(\\B)}] {$x-y-6=0$};\n\t\t\\addplot[mark=*] coordinates { (-1,2) } node (s) {};\n\t\t\\node[] (stxt) at (-3,3) {solution};\n\t\t\\draw[-stealth, thick] (stxt.east) to [out=0, in=180] (s.west);\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{example}\n\nNot all systems have single solutions only, nor do all systems even have any solutions. For example, if we add to the system in \\autoref{example:sys_solution} the equation\n\\[\n\tx-3y+3=0,\n\\]\nthe resulting system\n\\[\n\t\\begin{cases}\n\t\t&-4x+2y=0\\\\\n\t\t&x-y+3=0\\\\\n\t\t&x-3y+3=0\n\t\\end{cases}\n\\]\nhas no solutions (see \\autoref{example:no_solution}).\n\n\\begin{example}{System with no solutions}{no_solution}\n\tWhen the system of linear equations from \\autoref{example:sys_solution} is supplemented with the equation\n\t\\[\n\t\tx-3y+3=0,\n\t\\]\n\tit has no solution. However, any two equations of the system do have solutions (represented below as black points).\n\n\t\\centering\n\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\\begin{axis}[\n\t\t\tvector plane,\n\t\t\twidth=9cm, height=9cm,\n\t\t\txmin=-4, xmax=4,\n\t\t\tymin=-4, ymax=4,\n\t\t\tdomain={-4:4},\n\t\t\tmajor grid style={black!10},\n\t\t]\n\t\t\\pgfmathsetmacro{\\A}{-2}\n\t\t\\pgfmathsetmacro{\\B}{1}\n\t\t\\pgfmathsetmacro{\\C}{1/3}\n\t\t\\addplot[function, xred] {\\A*\\x} node[pos=0.63, above, rotate={atan(\\A)}] {$4x+2y=0$};\n\t\t\\addplot[function, xblue] {\\B*\\x+3} node[pos=0.22, above, rotate={atan(\\B)}] {$x-y-6=0$};\n\t\t\\addplot[function, xgreen] {\\C*\\x+1} node[pos=0.7, above, rotate={atan(\\C)}] {$x-3y+3=0$};\n\t\t\\addplot[only marks, mark=*] coordinates {\n\t\t  \t(-1,2)\n\t\t  \t(-3,0)\n\t\t  \t(-0.4286,0.8571)\n\t\t} node (s) {};\n\t\t\\end{axis}\n\t\\end{tikzpicture}\n\\end{example}\n\nLet us now explore when a set of linear equations in $\\Rs{2}$ and $\\Rs{3}$ has a single solution, infinitely many solutions or no solutions. In $\\Rs{2}$, the lines representing two linear equations can be either parallel or non-parallel. If they are non-parallel then the two equations have a single solution - the intercept of both lines (as seen in the previous two examples). If the lines are parallel, there are two cases: either the two lines are identical, in which case there are infinitely many solutions (all the points on the line), or they are parallel yet distince, in which case there are no solutions to the system (see \\autoref{fig:R2_num_solutions}).\n\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {-0.5*\\x+1};\n\t\t\t\t\t\\addplot[function, xgreen] {2*\\x+3};\n\t\t\t\t\t% -0.5x+1 = 2x+3 ==> 2.5x=-2, x=-0.8, y=1.5\n\t\t\t\t\t\\addplot[only marks, mark=*] coordinates { (-0.8,1.4) };\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:}\n\t\\end{subfigure}\t\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {-0.5*\\x-0.5};\n\t\t\t\t\t\\addplot[function, dashed, xgreen] {-0.5*\\x-0.5};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:R2_infinite_solutions}\n\t\\end{subfigure}\t\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {-0.5*\\x-0.5};\n\t\t\t\t\t\\addplot[function, xgreen] {-0.5*\\x-1.5};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:}\n\t\\end{subfigure}\t\n\t\\caption{Three possible cases for two linear equations in $\\Rs{2}$: (a) non-parallel and thus a single solution, (b) parallel and identical and thus infinitely many solutions, and (c) parallel but not identical and thus no solutions.}\n\t\\label{fig:R2_num_solutions}\n\\end{figure}\n\nIn the case of more than two linear equations there can be, again, either a single solution, infinitely many solutions or no solutions. The difference is that in this case zero solutions can happen even when all of the lines representing the equations are non-parallel (see \\autoref{fig:R2_num_solutions_multi}).\n\n\\begin{figure}\n\t\\centering\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {x};\n\t\t\t\t\t\\addplot[function, xblue] {2*\\x-2};\n\t\t\t\t\t\\addplot[function, xgreen] {3*\\x-4};\n\t\t\t\t\t\\addplot[function, xpurple] {-\\x+4};\n\t\t\t\t\t\\addplot[function, xorange] {-2*\\x+6};\n\t\t\t\t\t\\addplot[only marks, mark=*] coordinates { (2,2) };\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:}\n\t\\end{subfigure}\t\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {x};          % x-y=0\n\t\t\t\t\t\\addplot[function, xblue] {2*\\x+2};    % 2x-y=-2\n\t\t\t\t\t\\addplot[function, xgreen] {3*\\x-5};   % 3x-y=5\n\t\t\t\t\t\\addplot[function, xpurple] {-\\x+1};   % -x-y=-1\n\t\t\t\t\t\\addplot[function, xorange] {-2*\\x+3}; % -2x-y=-3\n\t\t\t\t\t\\addplot[only marks, mark=*] coordinates {\n\t\t\t\t\t\t\t(-2.0,-2.0)\n\t\t\t\t\t\t\t(2.5,2.5)\n\t\t\t\t\t\t\t(0.5,0.5)\n\t\t\t\t\t\t\t(1.0,1.0)\n\t\t\t\t\t\t\t(7.0,16)\n\t\t\t\t\t\t\t(-0.334,1.334)\n\t\t\t\t\t\t\t(0.25,2.5)\n\t\t\t\t\t\t\t(1.5,-0.5)\n\t\t\t\t\t\t\t(1.6,-0.2)\n\t\t\t\t\t\t\t(2.0,-1.0)\n\t\t\t\t\t};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:}\n\t\\end{subfigure}\t\n\t\\begin{subfigure}[c]{0.3\\textwidth}\n\t\t\\begin{center}\n\t\t\t\\begin{tikzpicture}[every node/.style={font=\\Large}]\n\t\t\t\t\\begin{axis}[\n\t\t\t\t\tlinear plane no ticks,\n\t\t\t\t\t]\n\t\t\t\t\t\\addplot[function, xred] {\\x+2};\n\t\t\t\t\t\\addplot[function, xblue] {\\x+1};\n\t\t\t\t\t\\addplot[function, xgreen] {\\x};\n\t\t\t\t\t\\addplot[function, xpurple] {\\x-1};\n\t\t\t\t\t\\addplot[function, xorange] {\\x-2};\n\t\t\t\t\\end{axis}\n\t\t\t\\end{tikzpicture}\n\t\t\\end{center}\n\t\t\\caption{}\n\t\t\\label{fig:}\n\t\\end{subfigure}\t\n\t\\caption{Three possible cases for the number of solutions of several linear equations in $\\Rs{2}$: (a) non-parallel but all lines intercept at single point and thus the system has a solution, (b) non-parallel but no single interception point and thus no solution, and (c) parallel and thus no solutions. The case where all lines are identical and thus there are infinitely many solutions is ommited from the figure, and looks identical to \\autoref{fig:R2_infinite_solutions}.}\n\t\\label{fig:R2_num_solutions_multi}\n\\end{figure}\n\nIn $\\Rs{3}$\\ldots (TBW later because I'm lazy af)\n\n\\subsection{Finding solutions}\nSeveral method to solve systems of linear equations were established over the years. One of the most well-known is \\emph{Gauss elimination method}. The goal of this method is to use a set of pre-defined operations to bring the system into a form which is easy to solve. This form essentially exposes the rank of the coefficient matrix, from which one can deduce some important properties of the system such as the existance of a solution (or lack thereof), the degrees of freedom in the values which can be substituted into the system and more.\n\nWe start by describing the \\emph{row-echelon form} of a matrix. For now we simply assume that such matrices exist, and later we will use a set of pre-defined operations to convert any matrix to this form. The following matrix is in row-echelon form:\n\\[\n\tA =\n\t\\begin{bmatrix}\n\t\t1 & 3 & -5 & 7 &  0\\\\\n\t\t0 & 0 &  2 & 2 & -3\\\\\n\t\t0 & 0 &  0 & 1 &  2\\\\\n\t\t0 & 0 &  0 & 0 &  0\\\\\n\t\\end{bmatrix} \n\\]\n\nWe note three properties of the above matrix:\n\\begin{itemize}\n\t\\item The bottom row is all zeros.\n\t\\item When looking at each row (left to right), all values are zero until we reach a non-zero element. For example, the first row starts with a non-zero element, but the second row has two non zero elements followed by the number $2$. These first non-zero elements are called \\emph{leading coefficients} or \\emph{pivots}, and each one is strictle to the \\textbf{right} of the leading coefficient of the row above it.\n\t\\item The leading coefficient of each row has only zeros below it in its column.\n\\end{itemize}\nAny matrix that has the same three properies is said to be in its row-echelon form.\n\n\\begin{example}{Row-echelon form}{row-echelon}\n\tAll of the matrices below are in their row-echelon form, and the leading zeros in each row are highlighted:\n\n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tabular}{cccc}\n\t\t$\\begin{bNiceMatrix}[name=RE1]\n\t\t\t0 & 5 & 10\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RE2]\n\t\t\t1 &  2 & 4\\\\\n\t\t\t0 & -2 & 2\\\\\n\t\t\t0 &  0 & 7\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RE3]\n\t\t\t0 & 0 & 3\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RE4]\n\t\t\t0 & 0 & 3 & -6 & 9 & -3\\\\\n\t\t\t0 & 0 & 0 &  0 & 2 &  6\\\\\n\t\t\\end{bNiceMatrix}$\\\\\n\t\\end{tabular}\n\t\\tikz[overlay, remember picture, blend mode=multiply]{\n\t\t\\node[mathl={xred!20}, fit=(RE1-1-2)] {};\n\t\t\\foreach \\pivot in {(RE2-1-1),(RE2-2-2),(RE2-3-3)}{\n\t\t\t\\node[mathl={xblue!20}, fit=\\pivot] {};\n\t\t}\n\t\t\\node[mathl={xgreen!20}, fit=(RE3-1-3)] {};\n\t\t\\foreach \\pivot in {(RE4-1-3),(RE4-2-5)}{\n\t\t\t\\node[mathl={xpurple!20}, fit=\\pivot] {};\n\t\t}\n\t}\n\t\\flushleft\n\n\tThe following matrices are all \\textbf{not} in their row-echelon form:\n\t\n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tabular}{cccc}\n\t\t$\\begin{bmatrix}\n\t\t\t0 & 5 & 1\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 1 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bmatrix}$ &\n\t\t$\\begin{bmatrix}\n\t\t\t1 &  2 & 4\\\\\n\t\t\t0 & -2 & 2\\\\\n\t\t\t3 &  0 & 7\\\\\n\t\t\\end{bmatrix}$ &\n\t\t$\\begin{bmatrix}\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 3\\\\\n\t\t\\end{bmatrix}$ &\n\t\t$\\begin{bmatrix}\n\t\t\t0 & 0 & 7 & -3 & 4 & 4\\\\\n\t\t\t0 & 1 & 0 &  0 & 2 & 3\\\\\n\t\t\\end{bmatrix}$\\\\\n\t\\end{tabular}\n\\end{example}\n\nUsing the row-echelon form we define the \\emph{reduced row-echelon form}. A matrix in a reduced row-echelon form is a matrix that is already in its row-echelon form, and in addition:\n\\begin{itemize}\n\t\\item The leading coefficients are all equal to $1$ (and are thus called \\emph{leading ones}).\n\t\\item All the elements in the \\textbf{column} of a leading one are equal to zero (except the leading one itself).\n\\end{itemize}\n\n\\begin{example}{Reduced row-echelon form}{}\n\tThe following matrices are the reduced row-echelon forms of the row-echelon matrices in \\autoref{example:row-echelon}, with theleading ones in each row highlighted:\n\n\t\\vspace{1em}\n\t\\centering\n\t\\begin{tabular}{cccc}\n\t\t$\\begin{bNiceMatrix}[name=RRE1]\n\t\t\t0 & 1 & 2\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RRE2]\n\t\t\t1 &  0 & 0\\\\\n\t\t\t0 & -1 & 0\\\\\n\t\t\t0 &  0 & 1\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RRE3]\n\t\t\t0 & 0 & 1\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\t0 & 0 & 0\\\\\n\t\t\\end{bNiceMatrix}$ &\n\t\t$\\begin{bNiceMatrix}[name=RRE4]\n\t\t\t0 & 0 & 1 & -2 & 0 & -10\\\\\n\t\t\t0 & 0 & 0 &  0 & 1 &   3\\\\\n\t\t\\end{bNiceMatrix}$\\\\\n\t\\end{tabular}\n\t\\tikz[overlay, remember picture, blend mode=multiply]{\n\t\t\\node[mathl={xred!20}, fit=(RRE1-1-2)] {};\n\t\t\\foreach \\pivot in {(RRE2-1-1),(RRE2-2-2),(RRE2-3-3)}{\n\t\t\t\\node[mathl={xblue!20}, fit=\\pivot] {};\n\t\t}\n\t\t\\node[mathl={xgreen!20}, fit=(RRE3-1-3)] {};\n\t\t\\foreach \\pivot in {(RRE4-1-3),(RRE4-2-5)}{\n\t\t\t\\node[mathl={xpurple!20}, fit=\\pivot] {};\n\t\t}\n\t}\n\\end{example}\n\nTo bring a matrix to its reduced row-echelon form, we use a sequence of operations from the following set:\n\\begin{itemize}\n\t\\item Scaling a row by a non-zero real number. For example:\n\t\t\\[\n\t\t\t\\begin{bNiceMatrix}[name=rreo1]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t-3 & 2 &  1 &  1\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t 2 & 2 & -1 &  7\\\\\n\t\t\t \\end{bNiceMatrix} \\xrightarrow[]{\\colorbox{xblue!30}{$R_{2}$}\\rightarrow3\\colorbox{xblue!30}{$R_{2}$}}\n\t\t\t \\begin{bNiceMatrix}[name=rreo2]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t-9 & 6 &  3 &  3\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t 2 & 2 & -1 &  7\\\\\n\t\t\t \\end{bNiceMatrix}\n\t\t\\]\n\t\there we take the 2nd row of the matrix (denoted as $R_{2}$) and scale it by $3$. The notation above the arrow tells us exactly that: $R_{2}$ is transformed into $2\\times R_{2}$.\n\n\t\\item Exchanging two rows. For example:\n\t\t\\[\n\t\t\t\\begin{bNiceMatrix}[name=rreo3]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t-9 & 6 &  3 &  3\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t 2 & 2 & -1 &  7\\\\\n\t\t\t \\end{bNiceMatrix} \\xrightarrow[]{\\colorbox{xred!30}{$R_{2}$}\\leftrightarrow \\colorbox{xgreen!30}{$R_{3}$}}\n\t\t\t \\begin{bNiceMatrix}[name=rreo4]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t-9 & 6 &  3 &  3\\\\\n\t\t\t\t 0 & 2 &  6 &  3\\\\\n\t\t\t \\end{bNiceMatrix}\n\t\t\\]\n\n\t\\item Adding one scaled row to a different row (where the scalar is not zero). For example:\n\t\t\\[\n\t\t\t\\begin{bNiceMatrix}[name=rreo5]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t-9 & 6 &  3 &  3\\\\\n\t\t\t\t 2 & 2 & -1 &  7\\\\\n\t\t\t \\end{bNiceMatrix} \\xrightarrow[]{\\colorbox{xpurple!30}{$R_{4}$}\\rightarrow \\colorbox{xpurple!30}{$R_{4}$}-2\\colorbox{xorange!30}{$R_{1}$}}\n\t\t\t \\begin{bNiceMatrix}[name=rreo6]\n\t\t\t\t 1 & 0 & -3 &  2\\\\\n\t\t\t\t 5 & 1 &  0 & -4\\\\\n\t\t\t\t-9 & 6 &  3 &  3\\\\\n\t\t\t\t 0 & 2 &  5 &  3\\\\\n\t\t\t \\end{bNiceMatrix}\n\t\t\\]\n\t\t(note that $R_{1}$ itself is not changed by the operation)\n\n\\tikz[overlay, remember picture, blend mode=multiply]{\n\t% Scaling\n\t\\node[mathl={xblue!30}, fit=(rreo1-2-1)(rreo1-2-4)] {};\n\t\\node[mathl={xblue!30}, fit=(rreo2-2-1)(rreo2-2-4)] {};\n\n\t% Exchanging\n\t\\node[mathl={xred!30}, fit=(rreo3-2-1)(rreo3-2-4)] {};\n\t\\node[mathl={xred!30}, fit=(rreo4-3-1)(rreo4-3-4)] {};\n\t\\node[mathl={xgreen!30}, fit=(rreo3-3-1)(rreo3-3-4)] {};\n\t\\node[mathl={xgreen!30}, fit=(rreo4-2-1)(rreo4-2-4)] {};\n\n\t% Addition\n\t\\node[mathl={xorange!30}, fit=(rreo5-1-1)(rreo5-1-4)] {};\n\t\\node[mathl={xorange!30}, fit=(rreo6-1-1)(rreo6-1-4)] {};\n\t\\node[mathl={xpurple!30}, fit=(rreo5-4-1)(rreo5-4-4)] {};\n\t\\node[mathl={xpurple!30}, fit=(rreo6-4-1)(rreo6-4-4)] {};\n}\n\\end{itemize}\n\n\\begin{example}{Row operations}{}\n\tLet us apply a sequence of 6 row opertions on a matrix until it reaches its reduced row-echelon form:\n\n\t\\begin{align*}\n\t\t&\n\t\t\\begin{bmatrix}\n\t\t\t 1 &  5 & 0 \\\\\n\t\t\t-2 &  3 & 1 \\\\\n\t\t\t-3 & -8 & 0 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}+3R_{1}}\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 5 & 0 \\\\\n\t\t\t-2 & 3 & 1 \\\\\n\t\t\t 0 & 7 & 0 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{3}\\to \\frac{1}{7}R_{3}}\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 5 & 0 \\\\\n\t\t\t-2 & 3 & 1 \\\\\n\t\t\t 0 & 1 & 0 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{2}\\leftrightarrow R_{3}}\n\t\t\\\\&\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 5 & 0 \\\\\n\t\t\t 0 & 1 & 0 \\\\\n\t\t\t-2 & 3 & 1 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{1}\\to R_{1}-5R_{2}}\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 0 & 0 \\\\\n\t\t\t 0 & 1 & 0 \\\\\n\t\t\t-2 & 3 & 1 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}+2R_{1}}\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 0 & 0 \\\\\n\t\t\t 0 & 1 & 0 \\\\\n\t\t\t 0 & 3 & 1 \\\\\n\t\t\\end{bmatrix}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}-3R_{2}}\n\t\t\\\\&\n\t\t\\begin{bmatrix}\n\t\t\t 1 & 0 & 0 \\\\\n\t\t\t 0 & 1 & 0 \\\\\n\t\t\t 0 & 0 & 1 \\\\\n\t    \\end{bmatrix}=I_{3}.\n\t\\end{align*}\n\\end{example}\n\nTo use row operations to solve a system of linear equations, we first write the \\emph{augmented matrix} form of the system. This for looks as follows: suppose we have the system\n\\[\n\t\\begin{cases}\n\t\t% x=-1, y=3, z=2\n\t\t&2x+y-3z  = -5\\\\\n\t\t&4x-2y+6z =  2\\\\\n\t\t&x+y-z    =  0\n\t\\end{cases}\n\\]\nThen the augmenten matrix of the system is\n\\[\n\t\\begin{bNiceMatrixAug}\n\t\t2 &  1 & -3 & -5\\\\\n\t\t4 & -2 &  6 &  2\\\\\n\t\t1 &  1 & -1 &  0\n\t\\end{bNiceMatrixAug},\n\\]\ni.e. it is simpy the coefficients matrix \\textit{augmented} with the free coefficients vector. We draw a vertical line where the matrix and vector were \"stitched\" together, to remind us which elements belong to what object.\n\nTo solve the system, we bring the augmented matrix to its reduced row-echelon form. In our case, this would be the matrix\n\\[\n\t\\begin{bNiceMatrixAug}[name=AugM1]\n\t\t1 & 0 & 0 & -1\\\\\n\t\t0 & 1 & 0 &  3\\\\\n\t\t0 & 0 & 1 &  2\n\t\\end{bNiceMatrixAug},\n\\]\nwhich means that the solution to the system is\n\\[\n\tx=-1,\\ y=3,\\ z=2.\n\\]\n\\solvesym{AugM1-1-4}\n\n\\begin{example}{Solving a system of linear equations}{}\n\tLet us solve the following system of linear equations using the Gaussian elimination method:\n\n\t\\[\n\t\t% x=4, y=0, z=3, w=-2\n\t\t\\begin{cases}\n\t\t& -3x+6y+6z-2w = 10\\\\\n\t\t& 7x-5y+7z-6w = 61\\\\\n\t\t& 5x-5y-4z-5w = 18\\\\\n\t\t& -8x+2y+2z+7y = -40\n\t\t\\end{cases}\n\t\\]\n\n\tThe augmented matrix for the system is\n\t\\[\n\t\tA =\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t-3 &  6 &  6 & -2 &  10\\\\\n\t\t\t 7 & -5 &  7 & -6 &  61\\\\\n\t\t\t 5 & -5 & -4 & -5 &  18\\\\\n\t\t\t-8 &  2 &  2 &  7 & -40\n\t\t\\end{bNiceMatrixAug}.\n\t\\]\n\n\tApplying a sequence of row operations to $A$:\n\n\t\\begin{align*}\n\t\t&\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t-3 &  6 &  6 & -2 &  10\\\\\n\t\t\t 7 & -5 &  7 & -6 &  61\\\\\n\t\t\t 5 & -5 & -4 & -5 &  18\\\\\n\t\t\t-8 &  2 &  2 &  7 & -40\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{1}\\to R_{1}-3R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t21 &  0 &  0 & -23 & 130\\\\\n\t\t\t 7 & -5 &  7 &  -6 &  61\\\\\n\t\t\t 5 & -5 & -4 &  -5 &  18\\\\\n\t\t\t-8 &  2 &  2 &   7 & -40\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{2}\\to R_{2}-R_{3}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t21 &  0 &  0 & -23 & 130\\\\\n\t\t\t 2 &  0 & 11 &  -1 &  43\\\\\n\t\t\t 5 & -5 & -4 &  -5 &  18\\\\\n\t\t\t-8 &  2 &  2 &   7 & -40\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}+2R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t21 &  0 &  0 & -23 & 130\\\\\n\t\t\t 2 &  0 & 11 &  -1 &  43\\\\\n\t\t   -11 & -1 &  0 &   9 & -62\\\\\n\t\t\t-8 &  2 &  2 &   7 & -40\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{4}\\to R_{4}+2R_{3}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t21 &  0 &  0 & -23 & 130\\\\\n\t\t\t 2 &  0 & 11 &  -1 &  43\\\\\n\t\t   -11 & -1 &  0 &   9 & -62\\\\\n\t\t   -30 &  0 &  2 &  25 & -164\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{4}\\to R_{4}+15R_{2}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t21 &  0 &   0 & -23 & 130\\\\\n\t\t\t 2 &  0 &  11 &  -1 &  43\\\\\n\t\t   -11 & -1 &   0 &   9 & -62\\\\\n\t\t     0 &  0 & 167 &  10 & 481\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{1}\\to R_{1}-10.5R_{2}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 & -115.5 & -12.5 & -321.5\\\\\n\t\t\t 2 &  0 &   11   &    -1 &   43\\\\\n\t\t   -11 & -1 &    0   &     9 &  -62\\\\\n\t\t     0 &  0 &  167   &    10 &   481\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{1}\\to R_{1}-1.25R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 &  93.25 &  0 & 279.75\\\\\n\t\t\t 2 &  0 &  11    & -1 &  43\\\\\n\t\t   -11 & -1 &   0    &  9 & -62\\\\\n\t\t     0 &  0 & 167    & 10 &  481\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{1}\\to \\frac{1}{93.25}R_{1}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 &   1 &  0 &   3\\\\\n\t\t\t 2 &  0 &  11 & -1 &  43\\\\\n\t\t   -11 & -1 &   0 &  9 & -62\\\\\n\t\t     0 &  0 & 167 & 10 &  481\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{4}\\to R_{4}-167R_{1}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 &  1 &  0 &   3\\\\\n\t\t\t 2 &  0 & 11 & -1 &  43\\\\\n\t\t   -11 & -1 &  0 &  9 & -62\\\\\n\t\t     0 &  0 &  0 & 10 &  -20\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{4}\\to \\frac{1}{10}R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 &  1 &  0 &   3\\\\\n\t\t\t 2 &  0 & 11 & -1 &  43\\\\\n\t\t   -11 & -1 &  0 &  9 & -62\\\\\n\t\t     0 &  0 &  0 &  1 &  -2\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}-9R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 &  1 &  0 &   3\\\\\n\t\t\t 2 &  0 & 11 & -1 &  43\\\\\n\t\t   -11 & -1 &  0 &  0 & -44\\\\\n\t\t     0 &  0 &  0 &  1 &  -2\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{2}\\to R_{2}-11R_{1}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 & 1 &  0 &   3\\\\\n\t\t\t 2 &  0 & 0 & -1 &  10\\\\\n\t\t   -11 & -1 & 0 &  0 & -44\\\\\n\t\t     0 &  0 & 0 &  1 &  -2\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{2}\\to R_{2}-R_{4}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 & 1 & 0 &   3\\\\\n\t\t\t 2 &  0 & 0 & 0 &   8\\\\\n\t\t   -11 & -1 & 0 & 0 & -44\\\\\n\t\t     0 &  0 & 0 & 1 &  -2\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{2}\\to \\frac{1}{2}R_{2}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t 0 &  0 & 1 & 0 &   3\\\\\n\t\t\t 1 &  0 & 0 & 0 &   4\\\\\n\t\t   -11 & -1 & 0 & 0 & -44\\\\\n\t\t     0 &  0 & 0 & 1 &  -2\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{3}\\to R_{3}+11R_{2}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t0 &  0 & 1 & 0 &  3\\\\\n\t\t\t1 &  0 & 0 & 0 &  4\\\\\n\t\t\t0 & -1 & 0 & 0 &  0\\\\\n\t\t    0 &  0 & 0 & 1 & -2\n\t\t\\end{bNiceMatrixAug}\n\t  \\\\[5mm]&\n\t\t\\xrightarrow[]{R_{3}\\to -R_{3}}\n\t\t\\begin{bNiceMatrixAug}\n\t\t\t0 & 0 & 1 & 0 &  3\\\\\n\t\t\t1 & 0 & 0 & 0 &  4\\\\\n\t\t\t0 & 1 & 0 & 0 &  0\\\\\n\t\t    0 & 0 & 0 & 1 & -2\n\t\t\\end{bNiceMatrixAug}\n\t\t\\xrightarrow[]{R_{1}\\leftrightarrow R_{2},\\ R_{2}\\leftrightarrow R_{3}}\n\t\t\\begin{bNiceMatrixAug}[name=rrefe]\n\t\t\t1 & 0 & 0 & 0 &  4\\\\\n\t\t\t0 & 1 & 0 & 0 &  0\\\\\n\t\t\t0 & 0 & 1 & 0 &  3\\\\\n\t\t    0 & 0 & 0 & 1 & -2\n\t\t\\end{bNiceMatrixAug}.\n\t\\end{align*}\n\t\\tikz[overlay, remember picture]{\n\t\t\\node[thick, draw=xred, rounded corners, fill=xred!20, right of=rrefe-3-5, text width=2.5cm, xshift=1.3cm, align=center] (rrefeTxt) {Reduced row echelon form};\n\t\t\\draw[-stealth, thick, xred] (rrefeTxt.west) to ($(rrefe-3-5.east)+(2.5mm,0)$);\n\t}\n\n\tThe solution of the system is therefore\n\t\\[\n\t\tx=4,\\ y=0,\\ z=3,\\ w=-2.\n\t\\]\n\n\\end{example}\n", "meta": {"hexsha": "d7a743e5aab1c986f94ccea5a88da8eeb1cce760", "size": 30323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/linear_algebra_intuitive/linear_systems.tex", "max_stars_repo_name": "pelegs/maths_book", "max_stars_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2021-12-25T20:02:57.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T17:57:59.000Z", "max_issues_repo_path": "chapters/linear_algebra_intuitive/linear_systems.tex", "max_issues_repo_name": "pelegs/maths_book", "max_issues_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2022-01-17T05:01:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-20T06:18:24.000Z", "max_forks_repo_path": "chapters/linear_algebra_intuitive/linear_systems.tex", "max_forks_repo_name": "pelegs/maths_book", "max_forks_repo_head_hexsha": "d1bebf3516a5821772d8807ce3d222a3caff1360", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2022-01-17T10:15:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-02T10:45:13.000Z", "avg_line_length": 34.9343317972, "max_line_length": 666, "alphanum_fraction": 0.612142598, "num_tokens": 12327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357460591569, "lm_q2_score": 0.8723473796562744, "lm_q1q2_score": 0.7563563611430285}}
{"text": "\\def\\Mu{\\boldsymbol{\\mu}}\n\\def\\Lamb{\\boldsymbol{\\lambda}}\n\n\\lab{Interior Point 2: Quadratic Programs}{Interior Point 2: Quadratic Programs}\n\\objective{Interior point methods originated as an alternative to the Simplex method for solving linear optimization problems. However, they can also be adapted to treat convex optimization problems in general.\nIn this lab we implement a primal-dual Interior Point method for convex quadratic constrained optimization and explore applications in elastic membrane theory and finance.}\n\n% Todo: change \\geq in the constraints to the component-wise geq in the book.\n\n\\section*{Quadratic Optimization Problems}\n%In this lab, we will explore an extension of Interior Point methods to a broader class of problems, namely quadratic constrained optimization problems.\nA \\emph{quadratic constrained optimization problem} differs from a linear constrained optimization problem only in that the 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\\trp Q\\x + \\c\\trp \\x\\\\\n\\text{subject to }\\qquad &A\\x \\succeq \\b,\\\\\n&G\\x = \\mathbf{h}.\n\\end{align*}\n% Unlike linear constrained optimization, the optimal point is not guaranteed to be one of the vertices of the feasible polytope (if the feasible region even is, indeed, a polytope).\n% Thus, any attempt to extend the popular Simplex Algorithm to quadratic programs would require substantial adjustments, as that algorithm is crucially based on locating and searching through the vertices of the feasible region.\n% Interior Point methods, however, generalize readily to the situation at hand.\n\nWe will restrict our attention to quadratic programs involving positive semidefinite quadratic terms (in general, indefinite quadratic objective functions admit many local minima, complicating matters considerably).\nSuch problems are called \\emph{convex}, since the objective function is convex.\nTo simplify the exposition, we will also only allow inequality constraints (generalizing to include equality constraints is not difficult).\nThus, we have the problem\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}&\\x\\trp Q\\x + \\c\\trp \\x\\\\\n\\text{subject to }\\qquad &A\\x \\succeq \\b\\\\\n\\end{align*}\nwhere $Q\\in\\mathbb{R}^{n\\times n}$ is a positive semidefinite matrix, $A\\in\\mathbb{R}^{m\\times n}$, $\\x, \\c \\in \\mathbb{R}^n$,\nand $\\b \\in \\mathbb{R}^m$.\n\n%We begin by deriving the KKT conditions for this problem.\nThe Lagrangian function for this problem is:\n\\begin{align}\n\\mathcal{L}(\\x,\\Mu) = \\frac{1}{2}\\x\\trp Q\\x + \\c\\trp \\x - \\Mu\\trp (A\\x -\\b),\n\\label{eq:lagrangian}\n\\end{align}\nwhere $\\Mu \\in \\mathbb{R}^m$ is the Lagrange multiplier.\n\n\\begin{comment} % Derivation overkill vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\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\\trp \\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\\end{comment} % Derivation overkill ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n% What we have now is a mixture of equations and inequalities.\n% We want to express these conditions as a system of equations, so\nWe also introduce a nonnegative slack vector $\\y\\in\\mathbb{R}^m$ to change the inequality\n$A\\x - \\b \\succeq \\0$ into the equality $A\\x - \\b - \\y = \\0$.\n\n\\begin{comment}\n\\begin{align}\nA\\x - \\b - \\y = \\0 &&\\Longrightarrow &&\\y = A\\x - \\b\n\\label{eq:equality}\n\\end{align}\n\\end{comment}\n\nThen the complete set of KKT conditions are:\n% we make this substitution into the complementary slackness conditions.\n% We obtain the following statement of the KKT conditions:\n\\begin{align*}\nQ\\x - A\\trp \\Mu + \\c &= \\0,\\\\\nA\\x - \\b - \\y &= \\0,\\\\\ny_i\\mu_i &= 0, \\qquad i=1,2,\\ldots,m,\\\\\n\\y,\\Mu &\\succeq \\0.\n\\end{align*}\n\n\\section*{Quadratic Interior Point Method}\n\nThe Interior Point method we describe here is an adaptation of the method we used with linear programming.\n%The basic intuition is the same as before: we start at some point in the interior of the feasible region, and we make a series of steps so that we approach the solution to the KKT conditions iteratively.\n% Since the solution to the KKT conditions can be seen as the root of a system of equations, our first thought might be to use Newton's Method for root-finding.\n% This will not work on its own, however, because the KKT conditions also require inequality constraints, which will be violated if we blindly apply Newton's Method.\n% Hence, we make adjustments to our choice of search direction and step size, so that we respect the constraints while moving closer to the solution of the KKT conditions.\nDefine $Y = \\text{diag}(y_1,y_2,\\ldots,y_m)$, $M = \\text{diag}(\\mu_1,\\mu_2,\\ldots,\\mu_m)$, and let $\\e\\in\\mathbb{R}^m$ be a vector of all ones.\nThen the roots of the function\n\\begin{align*}\nF(\\x,\\y,\\Mu) =\n\\begin{bmatrix}\nQ\\x-A\\trp \\Mu + c\\\\\nA\\x-\\y-\\b\\\\\nYM\\e\n\\end{bmatrix}\n&= \\0,\\\\\n(\\y,\\Mu) &\\succeq \\0\n\\end{align*}\nsatisfy the KKT conditions.\nThe derivative matrix of this function is given by\n\\[\nDF(\\x,\\y,\\Mu) =\n\\begin{bmatrix}\nQ & 0 & -A\\trp \\\\\nA & -I & 0\\\\\n0 & M & Y\n\\end{bmatrix},\n\\]\nand the duality measure $\\nu$ for this problem is \\[\\nu = \\frac{\\y\\trp \\Mu}{m}.\\]\n\n\\subsection*{Search Direction}\n\nWe calculate the search direction for this algorithm in the spirit of Newton's Method; this is the same way that we did in the linear programming case.\nThat is, we solve the system:\n\\begin{align}\nDF(\\x,\\y,\\Mu)\n\\begin{bmatrix}\\triangle \\x\\\\ \\triangle \\y\\\\ \\triangle \\Mu\\end{bmatrix}\n= - F(\\x,\\y,\\Mu) +\n\\begin{bmatrix} \\0 \\\\ \\0 \\\\ \\sigma\\nu\\e \\end{bmatrix},\n\\label{eq:searchDirection}\n\\end{align}\nwhere $\\sigma\\in [0,1)$ is the centering parameter.\n\n\\begin{problem}\nCreate a function \\li{qInteriorPoint()}.\nIt should accept the arrays $Q, \\c, A,$ and $\\b$, a tuple of arrays \\li{guess} giving initial estimates for $\\x, \\y,$ and $\\Mu$ (this will be explained later), along with the keyword arguments \\li{niter=20} and \\li{tol=1e-16}.\n\nIn this function, calculate the search direction.\nCreate $F$ and $DF$ as described above, and calculate the search direction $(\\triangle \\x\\trp , \\triangle \\y\\trp , \\triangle \\Mu\\trp )$ by solving Equation \\ref{eq:searchDirection}.\nUse $\\sigma = \\frac{1}{10}$ for the centering parameter.\n\n(Hint: What are the dimensions of $F$ and $DF$?)\n\\end{problem}\n\n\\begin{comment} % Old method for search direction vvvvvvvvvvvvvvvvvvvvvvvvvvvvv\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,\\Mu \\geq \\0$.\nWe achieve this goal using largely the same approach as in 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\\trp \\\\\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\\trp \\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\\nu = \\frac{1}{m}y\\trp \\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{\\nu} = \\frac{1}{m}(y + \\hat{\\alpha}\\triangle y)\\trp (\\lambda + \\hat{\\alpha}\\triangle \\lambda),\n\\]\nand then the centering parameter\n\\[\n\\sigma = \\left(\\frac{\\hat{\\nu}}{\\nu}\\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\\trp \\\\\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\\trp \\lambda - c\\\\\n-Ax + y + b\\\\\n-\\Lambda\\mathcal{Y}e - \\triangle \\Lambda\\triangle\\mathcal{Y}e + \\sigma\\nu e\n\\end{bmatrix}.\n\\label{eq:perturbed}\n\\end{equation}\n\\end{comment} % Old method for search direction ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\\subsection*{Step Length}\nNow that we have our search direction, we select a step length.\n We want to step nearly as far as possible\nwithout violating the nonnegativity constraints. \nHowever, we back off slightly from the maximum allowed step length\nbecause an overly greedy step at one iteration may prevent a descent step at the next iteration. \nThus, we choose our step size\n\\[\n\\alpha = \\max\\{a \\in (0,1] \\, \\mid \\, \\tau(\\y,\\Mu) +a(\\triangle \\y, \\triangle \\Mu) \\succeq \\0\\},\n\\]\nwhere $\\tau \\in (0,1)$ controls how much we back off from the maximal step length. \nFor now, choose $\\tau = 0.95$.\nIn general, $\\tau$ can be made to approach $1$ at each successive iteration.\nThis may speed up convergence in some cases.\n\n% This is equivalent to the method of choosing a step direction used in the previous lab.\n% In this case, however, we will use a single step length for all three of the parameters.\nWe wish to step nearly as far as possible without violating the problem’s constraints, as to remain in the interior of the feasible region. \nFirst, we calculate the maximum allowable step lengths for $\\mu$ and $\\y$.\n\n\\begin{align*}\n\\beta_{\\max} &= \\min\\{-\\mu_i/\\triangle \\mu_i \\mid \\triangle \\mu_i < 0 \\}\\\\\n\\delta_{\\max} &=\\min\\{-y_i/\\triangle y_i \\mid \\triangle y_i < 0 \\}\n\\end{align*}\n% Since $\\Mu,\\y \\geq \\0$.\nIf all of the entries of $\\triangle \\mu$ are nonnegative, we let $\\beta_{\\max} = 1$.\nLikewise, if all the entries of $\\triangle \\y$ are nonnegative, let $\\delta_{\\max}=1$.\nNext, we back off from these maximum step lengths slightly:\n\\begin{align*}\n\\beta &= \\min(1, \\tau\\beta_{\\max})\\\\\n\\delta &= \\min(1, \\tau\\delta_{\\max})\\\\\n\\alpha &= \\min(\\beta, \\delta)\n\\end{align*}\nThis $\\alpha$ is our final step length.\nThus, the next point in the iteration is given by:\n\\[\n(\\x_{k+1}, \\y_{k+1}, \\Mu_{k+1}) = (\\x_k, \\y_k, \\Mu_k) + \\alpha(\\triangle \\x_k, \\triangle \\y_k, \\triangle \\Mu_k).\n\\]\nThis completes one iteration of the algorithm.\n\n\\begin{comment} % Put this back in?\n\\begin{info}\nAs with our Interior Point method for linear constrained optimization, the most expensive part of each iteration is solving the linear systems \\ref{eq:affine} and \\ref{eq:perturbed}.\nNote, however, that these systems both have the same matrix on the left-hand side.\nThis allows us to factor the matrix just once per iteration, and use the factorization to solve both systems.\nA more sophisticated implementation would likely split up these large systems of equations into a few smaller ones, and then use Cholesky-based factorizations.\nTo simplify matters, we suggest simply using as a first attempt an LU decomposition on the entire matrix.\n\\end{info}\n\\end{comment}\n\n\\subsection*{Initial Point}\nThe starting point $(\\x_0, \\y_0, \\Mu_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\\trp  Gx + x\\trp  c s.t. Ax >= b.\n    Parameters:\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 we 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 $\\Mu$ equal to arrays of ones.\nWe summarize the entire algorithm below.\n\n\\begin{algorithm}[H]\n\\begin{algorithmic}[1]\n\\Procedure{Interior Point Method for QP}{}\n    \\State \\textrm{Choose initial point } $(\\x_0, \\y_0, \\Mu_0)$.\n    \\While{$k <\\ $\\li{niters} and $\\nu <\\ $\\li{tol}:}\n        \\State \\textrm{Calculate the duality measure} $\\nu$.\n        \\State \\textrm{Solve \\ref{eq:searchDirection} for the search direction} $(\\triangle \\x_k, \\triangle \\y_k, \\triangle \\Mu_k)$.\n        \\State \\textrm{Calculate the step length} $\\alpha$.\n        \\State $(\\x_{k+1}, \\y_{k+1}, \\Mu_{k+1}) = (\\x_k, \\y_k, \\Mu_k) + \\alpha(\\triangle \\x_k, \\triangle \\y_k, \\triangle \\Mu_k).$\n    \\EndWhile\n\\EndProcedure\n\\end{algorithmic}\n\\label{alg:intPt2}\n\\end{algorithm}\n\n\\begin{problem}\nComplete the implementation of \\li{qInteriorPoint()}.\nReturn the optimal point $\\x$ as well as the final objective function value.\n% and \\li{verbose}, a boolean value indicating whether or not to print the current objective function value ($ \\frac{1}{2}x_k\\trp Qx_k + c\\trp x_k$) and duality measure ($\\nu_k = \\frac{1}{m}y_k\\trp \\lambda_k$) at each iteration.\n% \\end{problem}\n\nTest your algorithm on the simple problem\n\\begin{align*}\n\\text{minimize }\\qquad \\frac{1}{2}x_1^2 + x_2^2 - &x_1x_2 - 2x_1 - 6x_2\\\\\n\\text{subject to }\\qquad\n-x_1-x_2 &\\geq -2,\\\\\nx_1-2x_2 &\\geq -2,\\\\\n-2x_1-x_2&\\geq -3,\\\\\nx_1, x_2 &\\geq 0.\n\\end{align*}\nIn this case, we have for the objective function matrix $Q$ and vector $\\c$,\n\\[\nQ = \\begin{bmatrix}\n1 & -1\\\\\n-1 & 2\n\\end{bmatrix},\n\\qquad\n\\c = \\begin{bmatrix}\n-2\\\\\n-6\n\\end{bmatrix}.\n\\]\nThe constraint matrix $A$ and vector $\\b$ are given by:\n\\[\nA = \\begin{bmatrix}\n-1 & -1\\\\\n1 & -2\\\\\n-2 & -1\\\\\n1 & 0\\\\\n0 & 1\n\\end{bmatrix},\n\\qquad\n\\b = \\begin{bmatrix}\n-2\\\\\n-2\\\\\n-3\\\\\n0\\\\\n0\n\\end{bmatrix}.\n\\]\nUse $\\x = [.5, .5]$ as the initial guess.\nThe correct minimizer is $\\left[\\frac{2}{3}, \\frac{4}{3}\\right].$\n\n(Hint: You may want to print out the duality measure $\\nu$ to check the progress of the iteration).\n\\end{problem}\n% We 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% >>> mu = np.ones(5)\n% >>> print qInteriorPoint(Q, c, A, b, (x,y,mu), niter=7, verbose=True)\n% (array([ 0.66666668,  1.3333333 ]), -8.222222138159772)\n% \\end{lstlisting}\n% Check that your function gives the same output.\n\n\\begin{info}\nThe Interior Point methods presented in this and the preceding labs are only special cases of the more general Interior Point algorithm.\nThe general version can be used to solve many convex optimization problems, provided that one can derive the corresponding KKT conditions and duality measure $\\nu$.\n\\end{info}\n\n\\section*{Application: Optimal Elastic Membranes}\nThe properties of elastic membranes (stretchy materials like a thin rubber sheet) are of interest in certain fields of mathematics and various sciences.\nA mathematical model for such materials can be used by biologists to study interfaces in cellular regions of an organism or by engineers to design tensile structures.\nOften we can describe configurations of elastic membranes as a solution to an\noptimization problem.\nAs a simple example, we will find the shape of a large circus tent by solving a quadratic constrained optimization problem using our Interior Point method.\n\nImagine a large circus tent held up by a few poles.\nWe can model the tent by a square two-dimensional grid, where each grid point has an associated number that gives the height of the tent at that point.\nAt each grid point containing a tent pole, the tent height is constrained to be at least as large as the height of the tent pole.\nAt all other grid points, the tent height is simply constrained to be greater than zero (ground height).\nIn 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 array giving the underlying tent pole structure (consisting mainly of zeros, except at the grid points that contain a tent pole), we have the linear constraint: \\[\\x \\succeq L.\\]\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{figures/tent.pdf}\n\\caption{Tent pole configuration (left) and optimal elastic tent (right).}\n\\label{fig:tent}\n\\end{figure}\n\nThe theory of elastic membranes claims that such materials tend to naturally minimize a quantity known as the \\emph{Dirichlet energy}.\nThis 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 \\[\\frac{1}{2}\\x\\trp  H \\x + \\c\\trp  \\x,\\] where $H$ is a particular positive semidefinite matrix closely related to Laplace's Equation, $\\c$ is a vector whose entries are all equal to $-(n-1)^{-2}$, and $n$ is the side length of the grid.\nOur circus tent is therefore given by the solution to the quadratic constrained optimization problem:\n\\begin{align*}\n\\text{minimize }\\qquad &\\frac{1}{2}\\x\\trp  H \\x + \\c\\trp  \\x\\\\\n\\text{subject to }\\qquad &\\x \\succeq L.\\\\\n\\end{align*}\nSee Figure \\ref{fig:tent} for an example of a tent pole configuration and the corresponding tent.\n\nWe provide the following function for producing the Dirichlet energy matrix $H$.\n\\begin{lstlisting}\nfrom scipy.sparse import spdiags\ndef laplacian(n):\n    \"\"\"Construct the discrete Dirichlet energy matrix H for an n x n grid.\"\"\"\n    data = -1*np.ones((5, n**2))\n    data[2,:] = 4\n    data[1, n-1::n] = 0\n    data[3, ::n] = 0\n    diags = np.array([-n, -1, 0, 1, n])\n    return spdiags(data, diags, n**2, n**2).toarray()\n\\end{lstlisting}\nNow we initialize the tent pole configuration for a grid of side length $n$, as well as initial guesses for $\\x$, $\\y$, and $\\Mu$.\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\n# Set initial guesses.\n>>> x = np.ones((n,n)).ravel()\n>>> y = np.ones(n**2)\n>>> mu = np.ones(n**2)\n\\end{lstlisting}\nWe leave it to you to initialize the vector $\\c$, the constraint matrix $A$,\n%(it's just the identity matrix of appropriate size)\nand to initialize the matrix $H$ with the \\li{laplacian()} function.\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\n# Calculate the solution.\n>>> z = qInteriorPoint(H, c, A, L, (x,y,mu))[0].reshape((n,n))\n\n# Plot the solution.\n>>> domain = np.arange(n)\n>>> X, Y = np.meshgrid(domain, domain)\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?\nIf you hide it somewhere in your living quarters or on your person, it will lose value over time due to inflation, not to mention you run the risk of burglary or accidental loss.\nA safer choice might be to put the money into a bank account.\nThat way, there is less risk of losing the money, plus you may even add to your savings through interest payments from the bank.\nYou could also consider purchasing bonds from the government or stocks from various companies, which come with their own sets of risks and returns.\nGiven all of these possibilities, how can you invest your money in such a way that maximizes the return (i.e. the wealth that you gain over the course of the investment) while still exercising caution and avoiding excessive risk?\nEconomist and Nobel laureate Harry Markowitz developed the mathematical underpinnings 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.\nEach investment is characterized by a financial asset (such as a stock or bond) together with the proportion of wealth allocated to the asset.\nAn 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 over each time period is related to the return of the asset.\nFor our purposes, we will assume that each asset has a positive risk, i.e. there 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)\\trp $, where $x_i$ indicates the proportion of wealth we invest in asset $i$.\nBy definition, the vector $\\x$ must satisfy \\[\\sum_{i=1}^n x_i = 1.\\]\nSuppose the $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, is given by\n\\[\\sum_{i=1}^n \\mu_ix_i.\\]\nWe define the risk of this portfolio in terms of the covariance matrix $Q$ of the $n$ assets: \\[\\sqrt{\\x\\trp  Q \\x}.\\]\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 $R$, there are many possible allocation vectors $\\x$ that make this possible.\nIt would be wise to choose the vector minimizing the risk.\nWe can state this as a quadratic program:\n\\begin{align*}\n\\text{minimize }\\qquad &\\frac{1}{2}\\x\\trp Q\\x\\\\\n\\text{subject to }\\qquad &\\sum_{i=1}^n x_i = 1\\\\\n&\\sum_{i=1}^n \\mu_ix_i = R.\\\\\n\\end{align*}\nNote that we have slightly altered our objective function for convenience, as minimizing $\\frac{1}{2}\\x\\trp Q\\x$ is equivalent to minimizing $\\sqrt{\\x\\trp Q\\x}$.\nThe solution to this problem will give the portfolio with least risk having a return $R$.\nBecause the components of $\\x$ are not constrained to be nonnegative, the solution may have some negative entries.\nThis indicates short selling those particular assets.\nIf we want to disallow short selling, we simply include nonnegativity constraints, stated in the following problem:\n\\begin{align*}\n\\text{minimize }\\qquad &\\frac{1}{2}\\x\\trp Q\\x\\\\\n\\text{subject to }\\qquad &\\sum_{i=1}^n x_i = 1\\\\\n&\\sum_{i=1}^n \\mu_ix_i = R\\\\\n&\\x \\succeq \\0.\n\\end{align*}\n\nEach return value $R$ can be paired with its corresponding minimal risk $\\sigma$.\nIf we plot these risk-return pairs on the risk-return plane, we obtain a hyperbola.\nIn general, the risk-return pair of any portfolio, optimal or not, will be found in the region bounded on the left by the hyperbola.\nThe positively-sloped portion of the hyperbola is known as the\n\\emph{efficient frontier}, since the points there correspond to optimal portfolios.\nPortfolios with risk-return pairs that lie to the right of the efficient frontier are inefficient portfolios, since we could either increase the return while keeping the risk constant, or we could decrease the risk while keeping the return constant.\nSee Figure \\ref{fig:frontier}.\n\n\\begin{figure}[H]\n\\includegraphics[width=0.75\\textwidth]{figures/frontier.pdf}\n\\caption{Efficient frontier on the risk-return plane.}\n\\label{fig:frontier}\n\\end{figure}\n\nOne weakness of this model is that the risk and return of each asset is in general unknown.\nAfter all, no one can predict the stock market with complete certainty.\nThere are various ways of estimating these values given past stock prices, and we take a very straightforward approach.\nSuppose for each asset, we have $k$ previous return values of the asset. That is, for asset $i$, we have the data vector\\[y^i = [y^i_1,\\,\\, \\ldots, \\,\\,y^i_k]\\trp .\\]\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.\nWe can estimate the covariance matrix for all assets by taking the covariance matrix of the vectors $y^1,\\ldots,y^n$.\nIn this way, we obtain estimated values for each $\\mu_i$ and $Q$.\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.\nUse this data to estimate the covariance matrix $Q$ as well as the expected rates of return $\\mu_i$ for each asset.\nAssuming that we want to guarantee an expected return of $R = 1.13$ for our portfolio, find 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 \\li{qInteriorPoint()} function.\n\nHint: Use \\li{numpy.cov()} to compute Q.\n\\end{problem}\n", "meta": {"hexsha": "ac5ee7bfb0aae86239c5c896e58a6b9777028439", "size": 26609, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/InteriorPoint_Quadratic/InteriorPoint_Quadratic.tex", "max_stars_repo_name": "frigusgulo/Labs", "max_stars_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-12-27T06:20:37.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-27T06:20:37.000Z", "max_issues_repo_path": "Volume2/InteriorPoint_Quadratic/InteriorPoint_Quadratic.tex", "max_issues_repo_name": "frigusgulo/Labs", "max_issues_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Volume2/InteriorPoint_Quadratic/InteriorPoint_Quadratic.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": 47.8579136691, "max_line_length": 335, "alphanum_fraction": 0.7154722087, "num_tokens": 7705, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473746782093, "lm_q2_score": 0.8670357460591569, "lm_q1q2_score": 0.7563563568268681}}
{"text": "\n\\subsection{Axiom of infinity}\n\n\nThe axiom of infinity states that:\n\n\\(\\exists I (\\varnothing \\in I \\land \\forall x \\in I((x\\lor \\{x\\})\\in I))\\)\n\nThere exists a set, called the infinite set. This contains the empty set, and for all elements in \\(I\\) the set also contains the successor to it.\n\n\\subsubsection{Sequential function}\n\nLet's define the sequential function:\n\n\\(s(n):=\\{n\\lor \\{n\\}\\}\\)\n\nWe can now rewrite the axiom of infinity as:\n\n\\(\\exists \\mathbb{N} (\\varnothing \\in \\mathbb{N} \\land \\forall x \\in \\mathbb{N}(s(x)\\in \\mathbb{N}))\\)\n\n\\subsubsection{Zero}\n\nThis set contains the null set: \\(\\varnothing \\in \\mathbb{N} \\).\n\nZero is defined as the empty set.\n\n\\(0:=\\{\\}\\)\n\n\\subsubsection{Natural numbers}\n\nFor all elements in the infinite set, there also exists another element in the infinite set: \\(\\forall x \\in \\mathbb{N}((x\\lor \\{x\\})\\in \\mathbb{N}) \\).\n\nWe then define all sequential numbers as the set of all preceding numbers. So:\n\n\\(1:=\\{0\\}=\\{\\{\\}\\}\\)\n\n\\(2:=\\{0,1\\}=\\{\\{\\},\\{\\{\\}\\}\\}\\)\n\n\\(3:=\\{0,1,2\\}=\\{\\{\\},\\{\\{\\}\\},\\{\\{\\},\\{\\{\\}\\}\\}\\}\\)\n\n\\subsubsection{Existence of natural numbers}\n\nDoes each natural number exist? We know the infinite set exists, and we also know the axiom schema of specification:\n\nPoint is: For each set, all finite subsets exist. PROVE ELSEWHERE\n\n\\subsubsection{From infinite set to natural set}\n\nWe don’t know I is limited to natural numbers. Could contain urelements etc.\n\n\\subsubsection{More}\n\nInfinite set axiom written using N. should be I\n\n\nI could be superset of N, for example set of all natural numbers, and also the set containing the set containing 2.\n\nCan extract N using axiom of specification\n\nWe need a way to define the set of natural numbers:\n\n\\(\\forall n (n\\in \\mathbb{N}\\leftrightarrow ([n=\\emptyset \\lor \\exists k (n=k\\lor \\{k\\})]\\land ))\\)\n\nIf we can can define N, we can show it exists from specicication\n\n\\(\\forall x \\exists s [P(x)\\leftrightarrow (x\\in s)]\\)\n\n\\(\\forall n \\exists s [n\\in N \\leftrightarrow (n\\in s)]\\)\n\n", "meta": {"hexsha": "4473968e39272c93adccf31dd4979033f81f9b57", "size": 1989, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/sets/01-01-infinity.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/logic/sets/01-01-infinity.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/logic/sets/01-01-infinity.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.4142857143, "max_line_length": 152, "alphanum_fraction": 0.6807440925, "num_tokens": 592, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9124361676202372, "lm_q2_score": 0.8289388040954684, "lm_q1q2_score": 0.7563537456005717}}
{"text": "\\section{Convolutional Neural Networks}\n\\begin{frame}{\\insertsec}\n    This type of networks are a bit different because instead of computing the activations by\n    multiplying the previous ones with the weight matrix it convolutes the previous activations \n    (denoted by $*$):\n    \n    \\begin{align*}\n        \\bm{a}^{[l]} &= g(\\bm{W}^{[l]}\\cdot \\bm{a}^{[l - 1]} + \\bm{b}^{[l]}) \\\\\n        \\text{Becomes:} \\\\\n        \\bm{a}^{[l]} &= g(\\bm{W}^{[l]} * \\bm{a}^{[l-1]} + \\bm{b}^{[l]})\n    \\end{align*}\n\\end{frame}\n\n\\begin{frame}{Convolution Operation}\n    \\begin{alertblock}{Important}\n        What we call \\textit{Convolution} in ML it's actually the \\textit{Cross-Correlation} operation\n        in signal analysis.\n    \\end{alertblock}\n    \n    \\begin{align*}\n        \\left(\n        \\begin{array}{cccccc}\n            10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}0 & 0 & 0 \\\\\n            10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}0 & 0 & 0 \\\\\n            10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}10 & \\cellcolor{green!20}0 & 0 & 0 \\\\\n            10 & 10 & 10 & 0 & 0 & 0 \\\\\n            10 & 10 & 10 & 0 & 0 & 0 \\\\\n            10 & 10 & 10 & 0 & 0 & 0 \\\\\n        \\end{array}\n        \\right)\n        *\n        \\left(\n        \\begin{array}{ccc}\n            1 & 0 & -1 \\\\\n            1 & 0 & -1 \\\\ \n            1 & 0 & -1 \\\\\n        \\end{array}\n        \\right)\n        = \n        \\left(\n        \\begin{array}{cccc}\n            0 & \\cellcolor{green!20}30 & 30 & 0 \\\\\n            0 & 30 & 30 & 0 \\\\\n            0 & 30 & 30 & 0 \\\\\n            0 & 30 & 30 & 0 \\\\\n        \\end{array}\n        \\right)\n    \\end{align*}\n    $$\n        10 \\cdot 1 + 10 \\cdot 1 + 10 \\cdot 1 +\n        10 \\cdot 0 + 10 \\cdot 0 + 10 \\cdot 0 +\n        0 \\cdot -1 + 0 \\cdot -1 + 0 \\cdot -1 = 30\n    $$\n\\end{frame}\n\n\\begin{frame}{Volume}\n    With convolutions the Neural Network parameters ($w$) are the convolution matrix elements\n    and so we do multiple convolutions to filter different features.\n    \\input{drawings/convolutional_block.tikz.tex}\n\\end{frame}\n\n\\begin{frame}{Pooling operation}\n    We use pooling to reduce the volume width and height size\n    \\begin{block}{Max-Pooling}\n        \\begin{align*}\n            \\operatorname{max\\,pool}\n            \\left(\n            \\begin{array}{cccc}\n                \\cellcolor{green!20} 0 & \\cellcolor{green!20} 7 & 12 &  9 \\\\\n                \\cellcolor{green!20}15 & \\cellcolor{green!20} 3 & 22 &  6 \\\\\n                 2 & 12 &  8 &  3 \\\\\n                 6 &  2 & 18 &  3 \\\\\n            \\end{array}\n            \\right)\n            =\n            \\left(\n            \\begin{array}{cc}\n                \\cellcolor{green!20}15 & 22 \\\\\n                12 & 18\n            \\end{array}\n            \\right)\n        \\end{align*}\n    \\end{block}\n\n    \\begin{block}{Avg-Pooling}\n        \\begin{align*}\n            \\operatorname{avg\\,pool}\n            \\left(\n            \\begin{array}{cccc}\n                \\cellcolor{green!20} 0 & \\cellcolor{green!20} 7 & 12 &  9 \\\\\n                \\cellcolor{green!20}15 & \\cellcolor{green!20} 3 & 22 &  6 \\\\\n                 2 & 12 &  8 &  3 \\\\\n                 6 &  2 & 18 &  3 \\\\\n            \\end{array}\n            \\right)\n            =\n            \\left(\n            \\begin{array}{cc}\n                \\cellcolor{green!20}6.25 & 12.25 \\\\\n                5.50 & 8.00\n            \\end{array}\n            \\right)\n        \\end{align*}\n    \\end{block}\n\\end{frame}\n\n\\subsection{Residual Networks}\n\\begin{frame}{\\insertsubsec}\n    They are a type of network that can learn the identity function thus allowing us to do\n    very deep networks.\n    \\input{drawings/resNet.tikz.tex}\n\n    \\begin{align*}\n        \\bm{a}^{[l+2]} = \n        g(\\underbrace{W^{[l+2]} \\cdot \\bm{a}^{[l + 1]} + \\bm{b}^{[l + 2]}}\n        _{0 \\text{ if using regularization}} + \\bm{a}^{[l]})\n    \\end{align*}\n\\end{frame}\n\n\\subsection{Inception block}\n\\begin{frame}{\\insertsubsec}\n    \\begin{figure}[H]\n        \\includegraphics[width=\\textwidth]{images/GoogLeNet3}\n        \\caption{GoogLeNet Inception Module}\n    \\end{figure}\n\\end{frame}\n\n\\subsection{Methods for improving CNN}\n\\begin{frame}{\\insertsubsec}\n    \\begin{onlyenv}<1>\n        \\begin{block}{Transfer Learning}\n            With transfer learning it's possible to download someone elses pre-trained weights, \n            remove the softmax (output) layer and add your own and then only train this last layer.\n            \\begin{itemize}\n                \\item \\textbf{Fine tuning}: continue to train the weights then adding your own data\n                \\item The exit values of the last layer can also be pre-computed and stored to disk\n                to speed-up learning\n            \\end{itemize}\n        \\end{block}\n    \\end{onlyenv}\n    \\begin{onlyenv}<2>\n        \\begin{block}{Data augmentation}\n            Apply different transformations to the image\n            \\begin{itemize}\n                \\item Mirroring\n                \\item Random cropping\n                \\item Rotation\n                \\item Shearing\n                \\item Color shifting\n                \\begin{itemize}\n                    \\item Distort the color channels\n                    \\item Apply different types of illumination, makes the algorithm more robust\n                \\end{itemize}\n            \\end{itemize}\n        \\end{block}\n    \\end{onlyenv}\n\\end{frame}\n\n", "meta": {"hexsha": "025cbbfa055224a677d5f0796ad2cecfd429f6df", "size": 5379, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LATEX/CNN Presentation/sections/03_convolutional_neural_networks.tex", "max_stars_repo_name": "jmigual/FIB-TFG", "max_stars_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-04-02T15:17:51.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-02T15:17:51.000Z", "max_issues_repo_path": "LATEX/CNN Presentation/sections/03_convolutional_neural_networks.tex", "max_issues_repo_name": "jmigual/FIB-TFG", "max_issues_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "LATEX/CNN Presentation/sections/03_convolutional_neural_networks.tex", "max_forks_repo_name": "jmigual/FIB-TFG", "max_forks_repo_head_hexsha": "7551a3c13a985ee7eecf7a4f38a6ee4803b05ff1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-10-23T08:11:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-10-23T08:11:28.000Z", "avg_line_length": 33.8301886792, "max_line_length": 102, "alphanum_fraction": 0.5129206172, "num_tokens": 1647, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513759047847, "lm_q2_score": 0.8438951064805861, "lm_q1q2_score": 0.75634215030254}}
{"text": "\\documentclass{article}\n\n\\include{stddefs}\n\\include{imodefs}\n\n\\chapterno{3}\n\n\\begin{document}\n\n\\chapter{Matrices}\\label{Chapter:Matrices}\n\n\nHandling linear equations and keeping track of the unknowns can be a pain. At\na certain point one needs to simplify the notation. This is done introducing\nmatrices. \n\nFor example, the system of equations\n\\begin{equation}\\label{equ2l}\n\\begin{matrix}\n&&  &2y &+ &4z &= &-2\\\\\n&3x &+ &2y &+ &7z &= &4\n\\end{matrix}\n\\end{equation}\ncan be represented by the rectangular array (matrix)\n\\begin{equation}\\label{matrix1} \n\\begin{pmatrix}\n0 & 2 & 4 & -2\\\\\n3 & 2 & 7 & 4\n\\end{pmatrix}\n\\end{equation}\nof numbers. Many of the operations we do to solve linear equations might as well be done on this array forgetting\nabout the unknowns.\n\n\\section{Matrices}\n\n\\subsection{Definitions}\nA rectangular array of numbers is called a \\index{matrix}\\emph{matrix}. A matrix with $m$ \\emph{rows} and $n$ \n\\emph{columns} is called an $m\\times n$ ($m$ by $n$) matrix. \nThe notation for an $m\\times n$ matrix $A$ is\n\\begin{equation}\\label{matr}\nA =  \n\\begin{pmatrix}\na_{11} & \\cdots &a_{1j}& \\cdots& a_{1 n} \\\\\n\\vdots & \\ddots &\\vdots & \\ddots & \\vdots\\\\\na_{i1} & \\cdots &a_{ij}& \\cdots& a_{i n} \\\\\n\\vdots & \\ddots &\\vdots & \\ddots & \\vdots\\\\\na_{m1} & \\cdots &a_{mj}& \\cdots& a_{m n}\n\\end{pmatrix},\n\\end{equation}\nwhere $A_{ij} = a_{i j}$ denotes the number or \\emph{entry} in the  $i$-th row and $j$-th column. If the matrix in \\eqref{matrix1}\nis denoted $A$, then it has $2$ rows and $4$ columns with $A_{14} = -2$.\n\nTwo matrices are equal if they have the same number of rows and columns and their entries are\nidentical.\n \nSage is built on top of python and has access to all its libraries. A\nvery useful (and famous) library for handling matrices is \\texttt{numpy}. Here is how\nthe matrix in \\eqref{matrix1} is entered in \\texttt{numpy}.\n\n\\begin{sage}\nimport numpy as np\n  \nm = np.matrix( [[0, 2, 4, -2], [3, 2, 7, 4]] )\nprint(m)\n\\end{sage}\n\n\n\\begin{enumerate}\n\n\\item\n  A matrix whose entries are all $0$ is called a zero matrix. It is denoted simply by $0$, when\n  it is clear from the context what its numbers of rows and columns are.\n  \n\\item\n  A matrix is called  \\emph{quadratic}\\index{quadratic matrix} if it has an equal number of rows and columns.\n  The first two matrices below are quadratic, whereas the third is not.\n$$\n\\begin{pmatrix} 1 \\end{pmatrix}, \\qquad\n\\begin{pmatrix} 1 & 2 & 3\\\\ 4 & 5 & 6\\\\ 7 & 8 & 9\\end{pmatrix}, \\qquad\n\\begin{pmatrix} 0 & 1 & 0\\\\ 1 & 0 & 1\\end{pmatrix}.\n$$\n\\item \n\\label{diagonalmat}\nThe \\emph{diagonal} in a matrix is defined as the entries in the matrix with the same row- and column indices.\nBelow we have a $3\\times 4$ matrix with the diagonal elements marked\n$$\n\\begin{pmatrix}\n\\color{red}{1} & 3 & 0 & 1\\\\\n3 & \\color{red}{2} & 1 & 5\\\\\n1 & 0 & \\color{red}{3} & 6\n\\end{pmatrix}.\n$$\nA matrix is called a \\index{diagonal matrix}\\emph{diagonal matrix}, if all its entries outside the\ndiagonal are $=0$. Below is an example of a square diagonal matrix\n$$\n\\begin{pmatrix}\n1 & 0 & 0\\\\\n0 & 2 & 0\\\\\n0 & 0 & 3\n\\end{pmatrix}.\n$$\n\\item\nA matrix is called a \\index{row vector}\\emph{row vector} if it has only one row. For example,\n$$\n\\begin{pmatrix}\n1 & 2 & 3\n\\end{pmatrix}\n$$\nis a row vector with three columns.\n\\item\nA matrix is called a \\index{column vector}\\emph{column vector} if it has only one column.\nFor example, \n$$\n\\begin{pmatrix}\n1\\\\ 2 \\\\ 3\n\\end{pmatrix}\n$$\nis a column vector with three rows.\n\\item\n  The rows in a matrix are called the  \\emph{row vectors} of the matrix.\nThe $i$-th row in a matrix $A$ is denoted $A_i$.\nThe matrix $A$ in \\eqref{matrix1} contains the row vectors\n$$\nA_1 = \\begin{pmatrix}\n0 & 2 & 4 & -2\n\\end{pmatrix}\n\\qquad\\text{and}\\qquad\nA_2 = \\begin{pmatrix}\n3 & 2 & 7 & 4\n\\end{pmatrix}.\n$$\n\\item\n  The columns in a matrix are called the \\emph{column vectors} of the matrix.\nThe $j$-th column in a matrix $A$ is denoted \\footnote{$A^j$}{Not to be confused with powers of the matrix $A$ introduced later.}.\nThe matrix $A$ in \\eqref{matrix1} contains the column vectors\n$$\nA^1 = \\begin{pmatrix}\n0 \\\\ 3\n\\end{pmatrix},\\quad\nA^2 =\\begin{pmatrix}\n2 \\\\ 2\n\\end{pmatrix},\\quad\nA^3 =\\begin{pmatrix}\n4 \\\\ 7\n\\end{pmatrix}\\quad\\text{and}\\quad\nA^4 = \\begin{pmatrix}\n-2 \\\\ 4\n\\end{pmatrix}.\n$$\n \n\\item\n  A row- or column vector is referred to as a \\index{vector}\\emph{vector}.\n\\item\n  Even though we have used the notation $\\RR^n$ for the $n$-th cartesian product of $\\RR$, we\n  will use $\\RR^n$ henceforth to denote the set of column vectors with $n$ rows (entries). This\n  definition is almost identical with the previous one, except that the tuple is formatted as\n  a column vector.\n\n  Illustrated by an example, \n  $$\n  \\begin{pmatrix} 1 \\\\ 2 \\\\ 3 \\end{pmatrix} \\in \\RR^3\\qquad\\text{instead of}\\qquad (1, 2, 3)\\in \\RR^3.\n  $$\n\\end{enumerate}\n\n\n\n\\section{Linear maps}\\label{sectionLM}\n\nIn the first chapter we encountered a miniature version of a neural\nnetwork. Neural networks are generally incredibly complicated functions\nfrom $\\RR^n$ to $\\RR^m$. The function $f:\\RR^2\\rightarrow \\RR^2$\ngiven by\n$$\nf\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix} =\n\\begin{pmatrix}\n  x^7 y + \\cos(x y) e^{x^2 + y^2 -1}\\\\\n  2 x y^2 - \\sin(x + y) (x^3 + y^3)\n\\end{pmatrix},\n$$\neven though it looks complicated, is simple in comparison.\n\nYou probably agree that the function $g:\\RR^2\\rightarrow \\RR^2$ given by\n$$\ng\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix} =\n\\begin{pmatrix}\n  2 x + 3 y\\\\\n  3 x - 2 y\n\\end{pmatrix}\n$$\nis even simpler. This function (or map) is an example of a linear map.\nIn general, a \\emph{linear map}\n$f: \\RR^n\\rightarrow \\RR^m$ has the form\n$$\nf\\begin{pmatrix}\n  x_1 \\\\ \\vdots \\\\ x_n\n\\end{pmatrix} =\n\\begin{pmatrix}\n  a_{11} x_1 + \\cdots + a_{1 n} x_n\\\\\n  \\vdots \\\\\n  a_{m1} x_1 + \\cdots + a_{m n} x_n\n\\end{pmatrix},\n$$\nwhere $a_{11}, \\dots, a_{mn}$ are $m n$ real numbers.\n\nUsing matrices we will use the notation\n$$\n\\begin{pmatrix}\na_{11} & \\cdots & a_{1n}\\\\\n\\vdots & \\ddots & \\vdots\\\\\na_{m1} & \\cdots & a_{mn}\n\\end{pmatrix}\n\\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n\\end{pmatrix} =\n\\begin{pmatrix}\n  a_{11} x_1 + \\cdots + a_{1 n} x_n\\\\\n  \\vdots \\\\\n  a_{m1} x_1 + \\cdots + a_{m n} x_n\n\\end{pmatrix}.\n$$\n\n\nIn this way, we can write the map $f$ as\n$$\nf(v) = A v,\n$$\nwhere $A$ is the $m\\times n$ matrix\n$$\n\\begin{pmatrix}\na_{11} & \\cdots & a_{1n}\\\\\n\\vdots & \\ddots & \\vdots\\\\\na_{m1} & \\cdots & a_{mn}\n\\end{pmatrix}\n$$\nand $v$ is the vector\n$$\n\\begin{pmatrix} x_1 \\\\ \\vdots \\\\ x_n\\end{pmatrix}\n$$\nin $\\RR^n$.\n\nBasically a linear map is a system of linear equations without the right hand side (including $=$).\nIn fact, we may write the system of linear equations in \\eqref{equ2l} as\n$$\n\\begin{pmatrix}\n0 & 2 & 4\\\\\n3 & 2 & 7\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y \\\\ z\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n  -2 \\\\ 4\n\\end{pmatrix}.\n$$\n\\beginshex\nLet $f: \\RR^2\\rightarrow \\RR^2$ be the linear map given by the $2\\times 2$ matrix\n$$\n\\begin{pmatrix}\n  1 & 2\\\\\n  3 & 4\n\\end{pmatrix}.\n$$\nDoes there exist $u\\in \\RR^2$, such that\n$$\nf(u) = \\begin{pmatrix} 3 \\\\ 7 \\end{pmatrix}?\n$$\nQuite generally, can we find $u\\in \\RR^2$, such that\n$$\nf(u) = \\begin{pmatrix} b_1 \\\\ b_2 \\end{pmatrix}?\n$$\nfor arbitrary $b_1, b_2\\in \\RR$?\n\\endshex\n\n\\beginshex\nSuppose you know that $f: \\RR^n\\rightarrow \\RR^m$ is a linear map and\nthat you have a black box giving you output $f(v)\\in \\RR^m$ if you\nsupply the input $v\\in \\RR^n$. How would you find\nthe matrix defining $f$?\n\\endshex\n\n\n\\section{Matrix multiplication}\n\nSuppose we are given two linear maps $f: \\RR^2\\rightarrow \\RR^2$ and\n$g:\\RR^2\\rightarrow \\RR^2$. Then it turns out that the composition\n$f\\circ g: \\RR^2\\rightarrow \\RR^2$ is also a linear map. A word of advice:\nthe computations below look large and intimidating. They are not. It\nis important that you carry them out on your own. Do not look and copy or tell\nyourself that it looks okay. Do the computations yourself and ask me\nor fellow students if you get stuck.\n\nLet us look at an example. Suppose that\n$$\ng\\begin{pmatrix} x\\\\ y \\end{pmatrix} =\n\\begin{pmatrix}\n  2 & 3 \\\\\n  -1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\\qquad\n\\text{and}\n\\qquad\nf\\begin{pmatrix} u\\\\ v \\end{pmatrix} =\n\\begin{pmatrix}\n  1 & 2 \\\\\n  1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n  u \\\\ v\n\\end{pmatrix}.\n$$\nThen\n\\begin{align*}\n(f\\circ g)\\begin{pmatrix} x\\\\ y \\end{pmatrix} &=\nf\\left(g\\begin{pmatrix} x\\\\ y \\end{pmatrix}\\right) =\nf\\left(\\begin{pmatrix}\n  2 & 3 \\\\\n  -1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\\right)\n=\n\\begin{pmatrix}\n  1 & 2 \\\\\n  1 & -2\n\\end{pmatrix}\n      \\left(\n\\begin{pmatrix}\n  2 & 3 \\\\\n  -1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\n  \\right)\\\\\n  \\\\\n  &= \n\\begin{pmatrix}\n  1 & 2 \\\\\n  1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n  2 x + 3 y\\\\\n  -x - 2y\n\\end{pmatrix} =\n  \\begin{pmatrix}\n    - y \\\\\n    4 x + 7 y\n  \\end{pmatrix}\n  =\n  \\begin{pmatrix}\n    0 & -1\\\\\n    4 & 7\n  \\end{pmatrix}\n  \\begin{pmatrix}\n    x \\\\ y\n  \\end{pmatrix}.\n\\end{align*}\n\nIn terms of the matrices of the linear maps, we write this as\n\\begin{equation}\\label{moperation}\n\\begin{pmatrix}\n1 & 2\\\\\n1 & -2\n\\end{pmatrix}\n\\begin{pmatrix}\n2 & 3\\\\\n-1 & -2\n\\end{pmatrix}\n=\n\\begin{pmatrix}\n0 & -1\\\\\n4 & 7\n\\end{pmatrix}\n\\end{equation}\n\nThere is nothing special about the numbers in this example. We might as well\ndo the computation in general: suppose that\n\n$$\ng\\begin{pmatrix} x\\\\ y \\end{pmatrix} =\n\\begin{pmatrix}\n  b_{11} & b_{12} \\\\\n  b_{21} & b_{22}\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\\qquad\n\\text{and}\n\\qquad\nf\\begin{pmatrix} u\\\\ v \\end{pmatrix} =\n\\begin{pmatrix}\n  a_{11} & a_{12} \\\\\n  a_{21} & a_{22}\n\\end{pmatrix}\n\\begin{pmatrix}\n  u \\\\ v\n\\end{pmatrix}.\n$$\nThen\n\\begin{align*}\n(f\\circ g)\\begin{pmatrix} x\\\\ y \\end{pmatrix} &=\nf\\left(g\\begin{pmatrix} x\\\\ y \\end{pmatrix}\\right) =\nf\\left(\\begin{pmatrix}\n  b_{11} & b_{12} \\\\\n  b_{21} & b_{22}\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\\right)\n=\n\\begin{pmatrix}\n  a_{11} & a_{12} \\\\\n  a_{21} & a_{22}\n\\end{pmatrix}\n      \\left(\n\\begin{pmatrix}\n  b_{11} & b_{12} \\\\\n  b_{21} & b_{22}\n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}\n  \\right)\\\\\n  \\\\\n  &= \n\\begin{pmatrix}\n  a_{11} & a_{12} \\\\\n  a_{21} & a_{22}\n\\end{pmatrix}\n\\begin{pmatrix}\n  b_{11} x + b_{12} y\\\\\n  b_{21} x + b_{22} y\n\\end{pmatrix} =\n  \\begin{pmatrix}\na_{11} (b_{11} x + b_{12} y) + a_{12} (b_{21} x + b_{22} y)\\\\\na_{21} (b_{11} x + b_{12} y) + a_{22} (b_{21} x + b_{22} y) \n\\end{pmatrix}\\\\\n  \\\\\n  &=\n  \\begin{pmatrix}\n(a_{11} b_{11} + a_{12} b_{21}) x + (a_{11}b_{12} + a_{12} b_{22}) y \\\\ \n(a_{21} b_{11} + a_{22} b_{21}) x + (a_{21} b_{12} + a_{22} b_{22}) y \n\\end{pmatrix}\\\\\n  \\\\\n  &=\n  \\begin{pmatrix}\na_{11} b_{11} + a_{12} b_{21} & a_{11}b_{12} + a_{12} b_{22} \\\\ \na_{21} b_{11} + a_{22} b_{21} &  a_{21} b_{12} + a_{22} b_{22} \n\\end{pmatrix}\n\\begin{pmatrix}\n  x \\\\ y\n\\end{pmatrix}.\n\\end{align*}\n\n\nAgain, in terms of the matrices of the linear maps, we write this as\n\\begin{equation}\\label{matmult}\n\\begin{pmatrix}\na_{11} & a_{12}\\\\\n\\color{blue}{a_{21}} & \\color{red}{a_{22}}\n\\end{pmatrix}\n\\begin{pmatrix}\n\\color{blue}{b_{11}} & b_{12}\\\\\n\\color{red}{b_{21}} & b_{22}\n\\end{pmatrix}\n=\n\\begin{pmatrix}\na_{11} b_{11} + a_{12} b_{21} & a_{11} b_{12} + a_{12} b_{22}\\\\\n\\color{blue}{a_{21} b_{11}} + \\color{red}{a_{22} b_{21}} & a_{21} b_{12} + a_{22} b_{22}\n\\end{pmatrix}\n\\end{equation}\n\nThe equation above is the formula for matrix multiplication for two $2\\times 2$ matrices, precisely as\nit was introduced\nby \\url{Cayley}{https://en.wikipedia.org/wiki/Arthur_Cayley} around $1857$.\n\n\nUpon closer inspection (and colored in \\eqref{matmult} for $i=2$ and $j= 1$), you will see that\nthe number in the $i$-th row and $j$-th column in the product matrix is the\n\\emph{row-column multiplication}\\index{row-column multiplication} between the $i$-th row and\nthe $j$-th column in the two matrices:\n\n\\begin{frameit}\nThe \\emph{row-column multiplication} between a row vector\n$$\nx = (x_1 x_2 \\dots x_n)\\qquad\\text{and a column vector}\\qquad\ny = \\begin{pmatrix}\ny_1 \\\\ y_2 \\\\ \\vdots \\\\ y_n\n\\end{pmatrix}\n$$\nwith the same number of entries is defined as\n$$\nx y = x_1 y_1 + x_2 y_2 + \\cdots + x_n y_n.\n$$\n\\end{frameit}\n\n\n\\index{matrix multiplikation}\n\\begin{definition}[emph]\\label{defmatmult}\n  Let $A$ be an  $\\color{blue}{m}\\times \\color{brown}{n}$ matrix and $B$ an $\\color{brown}{n}\\times \\color{red}{r}$ matrix.\n  Then the matrix product $A B$ is defined as the $\\color{blue}{m}\\times\\color{red}{r}$ matrix $C$ given by the\n  row-column multiplication\n$$\nC_{ij} = A_i B^j = A_{i1} B_{1j} + A_{i2} B_{2j} + \\cdots + A_{in} B_{nj}\n$$\nfor $1\\leq i \\leq m$ and $1\\leq j \\leq r$.\n\\end{definition}\n\n\\begin{frameit}\nIf $A$ is an  $m\\times n$ matrix and $B$ is an  $r\\times s$, then the matrix product $A B$ only makes sense if\n$n = r$: the number of columns in $A$ must equal the number of rows in $B$. \n\\end{frameit}\n\n\n\\begin{quizexercise}[showhide]\n\\begin{quiz}\n\\question\nSuppose that \n$$\nA = \\begin{pmatrix} 1 & 0 & 0\\\\ 0 & 1 & 0 \\end{pmatrix}, \\quad\nB = \\begin{pmatrix} 1 & 0\\\\ 0 & 1\\end{pmatrix}, \\quad\nC = \\begin{pmatrix} 1 & 1 & 1\\end{pmatrix}, \\quad\\text{and}\\quad\nD = \\begin{pmatrix} 1 \\\\ 1 \\\\ 1\\end{pmatrix}\n$$\nWhich of the matrix products below make sense?\n\\answer{T}\n$B A$\n\\answer{F}\n$A B$\n\\answer{T}\n$C D$\n\\answer{T}\n$D C$\n\\answer{F}\n$C A$\n\\answer{T}\n$A D$\n\\end{quiz}\n\\end{quizexercise}\n\n\\begin{video}\n  I have been told that my pronunciation of \\emph{column} in the video below is wrong. In the area of the US, where I got my PhD, people for some reason had this (Irish?)\n  \\url{rare pronunciation}{https://en.wiktionary.org/wiki/column\\#Pronunciation}.\n  \n\\youtube{KVpBEynN3IM}\n\\end{video}\n\n\n\nUsing matrix product notation, the system of linear equations in \\eqref{equ2l} can now\nbe written as\n$$\n\\begin{pmatrix}\n0 & 2 & 4\\\\\n3 & 2 & 7\n\\end{pmatrix} \n\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix} = \n\\begin{pmatrix} -2 \\\\ 4 \\end{pmatrix}\n$$\nHere we multiply a $2\\times 3$ with a $3\\times 1$\nmatrix. The row-column multiplication gives the $2\\times 1$ matrix\n$$\n\\begin{pmatrix}\n2 y + 4 z\\\\\n3 x + 2 y + 7 z\n\\end{pmatrix}.\n$$\nThis matrix must equal the $2\\times 1$ matrix on the right hand side\nfor \\eqref{equ2l} to be true.\nThis is in agreement with our convention for writing linear maps in \nsection \\ref{sectionLM}.\n\n\\begin{quizexercise}[showhide]\n\\begin{quiz}\n\\question\nSuppose that\n$$\nA = \n\\begin{pmatrix}\n1 & 2 & 3\\\\\n0 & 1 & 2\\\\\n3 & x & 1\n\\end{pmatrix},\n\\quad\nB = \n\\begin{pmatrix}\n1& 1 & 1\\\\\n2 & 2 & 2\\\\\n0 & 1 & 1\n\\end{pmatrix}\\quad\\text{and}\\quad\nC = A B\n$$\nWhich ones of the statements below are true?\n\\answer{F}\n$C_{12} = 9$\n\\answer{T}\n$C_{23} = 4$\n\\answer{T}\nIf $C_{32} = 4$, then $x = 0$.\n\\answer{F}\nIf $C_{31} = -1$, then $x=-1$.\n\\end{quiz}\n\\end{quizexercise}\n\n\\subsection{Matrix multiplication in \\texttt{numpy}}\n\nMatrix multiplication in \\texttt{numpy} is represented by the function \\texttt{dot}:\n\n\\begin{sage}\nimport numpy as np\nA = np.matrix( [[1, 2], [1, -2]] )\nB = np.matrix( [[2, 3], [-1, -2]] )\nprint(\"A =\")\nprint(A)\nprint(\"B =\")\nprint(B)\nprint(\"AB =\")\nprint(np.dot(A, B))\n\\end{sage}\n\n\\subsection{The identity matrix}\n\n\n\\index{identity matrix}\nThe identity matrix $I_n$ of order $n$ is the $n\\times n$ diagonal matrix with $1$\nin the diagonal. Below is the identity matrix of order $5$.\n$$\n\\begin{pmatrix}\n1 & 0 & 0 & 0 & 0\\\\\n0 & 1 & 0 & 0 & 0\\\\\n0 & 0 & 1 & 0 & 0\\\\\n0 & 0 & 0 & 1 & 0\\\\\n0 & 0 & 0 & 0 & 1\n\\end{pmatrix}\n$$\n\nThe identity matrix $I_n$ has the crucial property that \n\\begin{equation}\\label{idmathident}\nI_n A = A I_n = A\n\\end{equation}\nfor all $n\\times n$ matrices $A$.\n\n\\begin{sage}\nimport numpy as np\n  \nI3 = np.identity(3)\nA = np.matrix( [[1, 2, 3], [4, 5, 6], [7, 8, 9]] )\nprint(\"The identity matrix of order 3 is I3 = \")\nprint(I3)\nprint(\"The matrix A is \")\nprint(A)\nprint(\"The matrix product I3 A is\")\nprint(np.dot(I3, A))\nprint(\"The matrix product A I3 is\")\nprint(np.dot(A, I3))\n\\end{sage}\n\n\\beginshex\nProve that the two identities in \\eqref{idmathident} are true for $n\\times n$ matrices.\n\\endshex\n\n\\subsection{Examples of matrix multiplication}\nMatrix multiplication is omnipresent in mathematics. Below we give an example,\nwhich is a baby version of \nGoogle's famous \\url{page rank algorithm}{https://en.wikipedia.org/wiki/PageRank}.\n\n\n\n\\begin{example}\\label{eksstokmatr}\n\n  Suppose that $20$\\% of the people living in the suburbs move to the big city and\n  that $30$\\% of the people living in the big city move to the suburbs per year.\n\n  Aiming for a model using probabilities, let us be a bit more precise.\n\n\\begin{enumerate}[(i)]\n\\item\n  If you live in the suburbs, the probability that you move to the big city is $0.2$,\n\\item\n  If you live in the suburbs, the probability that you do not move is $0.8$.\n\\item\n  If you live in the big city the probability that you move to the suburbs is $0.3$.\n\\item\n  If you live in the big city the probability that you do not move is $0.7$.\n\\end{enumerate}\nAll of the above probabilities are per year and can be illustrated in the diagram below\n\n\\includegraphics{markov.svg}\n\nWe are interested in predicting, using this model, how many people live\nin the big city and the suburbs given that we know how many people\nlive in the big city, $x_0$ and in the suburbs $y_0$ to begin with i.e.,\nsetting the time $t = 0$ (years).\n\nHow many people $x_1$ and $y_1$ live in the two places after the first year ($t=1$)?\n\nThe population of the big city will decrease by $30\\%$, but there are newcomers amounting to\n$20\\%$ of the population in the suburbs. Therefore\n$$\nx_1 = 0.7 x_0 + 0.2 y_0.\n$$\nIn the same way,\n$$\ny_1 = 0.3 x_0 + 0.8 y_0.\n$$\nUsing matrix multiplication, these two equations can be written\n$$\n\\begin{pmatrix} x_1 \\\\ y_1 \\end{pmatrix} = \n\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\n\\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix}.\n$$\nFor $t=2$ years, we can repeat the procedure and the result becomes\n\\begin{align}\\label{snyd}\n\\begin{pmatrix} x_2 \\\\ y_2 \\end{pmatrix} &= \n\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\n\\begin{pmatrix} x_1 \\\\ y_1 \\end{pmatrix} =\n\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\n\\left(\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\n\\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix}\\right)\\\\\n&=\n\\left( \n\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\n\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}\\right)\n\\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix} = \nP^2 \\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix},\n\\end{align}\nwhere \n\\begin{equation}\\label{stokmat}\nP=\\begin{pmatrix} \n0.7 & 0.2\\\\\n0.3 & 0.8\n\\end{pmatrix}.\n\\end{equation}\nIn general we have the formula\n\n\\begin{equation}[emph]\\label{markovformel}\n\\begin{pmatrix} x_n \\\\ y_n \\end{pmatrix} = \nP^n\n\\begin{pmatrix} x_0 \\\\ y_0 \\end{pmatrix},\n\\end{equation}\n\ngiving the distribution of the populations for $t = n$\nyears. Let us experiment a little:\n\\begin{align*}\nP^2 &= \n\\begin{pmatrix}\n0.55 & 0.3\\\\\n0.45 & 0.7\n\\end{pmatrix}\\\\\nP^3 = P P^2 &=\n\\begin{pmatrix} \n0.475 & 0.35\\\\\n0.525 & 0.65\n\\end{pmatrix}\\\\\nP^4 = P P^3 &=\n\\begin{pmatrix} \n0.4375 & 0.375\\\\\n0.5625 & 0.625\n\\end{pmatrix}\\\\\n&\\vdots\\\\\nP^{15} &= \n\\begin{pmatrix} \n0.400018 & 0.399951\\\\\n0.599982 & 0.600012\n\\end{pmatrix}\\\\\nP^{16} &= \n\\begin{pmatrix} \n0.400009 & 0.399994\\\\\n0.599991 & 0.600006\n\\end{pmatrix}\n\\end{align*}\n\nIt seems that the distribution stabilizes around $40\\%$ living\nin the big city and $60\\%$ living in the suburbs of the\noriginal total population.\n\n\\begin{sage}\nimport numpy as np\n\nP = np.matrix( [[0.7, 0.2], [0.3, 0.8]] )\n\nprint(P**16)\n\\end{sage}\n\n\nThe matrix $P$ is an example of a stochastic $2\\times 2$ matrix. \nIn general, a square matrix is called a \\emph{stochastic matrix} if its entries are\n$\\geq 0$ and the sum of the entries in its column vectors are $1$.\n\\end{example}\n\n\n\\begin{example}\n\n  A simple example of the page rank algorithm is\n  given in Example \\ref{Googleprlineqs}. There you\n  encountered the equations\n  \\begin{align*}\n    T_2 &= T_1 + \\tfrac{1}{2} T_4\\\\\n    T_3 &= T_2\\\\\n    T_4 &= T_3\\\\\n    T_1 &= \\tfrac{1}{2} T_4\\\\\n    T_1 + T_2 + T_3 + T_4 &= 1.\n  \\end{align*}\n  \n  In terms of matrix multiplication the first four equations can be rewritten to\n  $$\n  \\begin{pmatrix}\n    0 & 0 & 0 & \\tfrac{1}{2} \\\\[5pt]\n    1 & 0 & 0 & \\tfrac{1}{2}\\\\[5pt]\n    0 & 1 & 0 & 0 \\\\[5pt]\n    0 & 0 & 1 & 0 \n  \\end{pmatrix}\n  \\begin{pmatrix}\n    T_1 \\\\[5pt] T_2 \\\\[5pt] T_3 \\\\[5pt] T_4\n  \\end{pmatrix} =\n  \\begin{pmatrix}\n    T_1 \\\\[5pt] T_2 \\\\[5pt] T_3 \\\\[5pt] T_4\n  \\end{pmatrix}.\n  $$\n  Putting\n  $$\n  P = \\begin{pmatrix}\n    0 & 0 & 0 & \\tfrac{1}{2} \\\\[5pt]\n    1 & 0 & 0 & \\tfrac{1}{2}\\\\[5pt]\n    0 & 1 & 0 & 0 \\\\[5pt]\n    0 & 0 & 1 & 0 \n  \\end{pmatrix}\n  $$\n  we get a stochastic matrix and  may again iterate and compute $P, P^2, P^3, \\dots$.\n\n\\begin{sage}\nimport numpy as np\nP = np.matrix( [[0, 0, 0, 0.5], [1, 0, 0, 0.5], [0, 1, 0, 0], [0, 0, 1, 0]] )\n\nprint(P**10)\nprint(P**20)\nprint(P**30)\nprint(P**40)\nprint(P**50)\n\\end{sage}\n\nIs there a connection between the entries of $P^N$, where $N$ is very big and the solutions to the linear equations? \n\\end{example}\n\n\n\\beginshex\nIn the end of Example \\ref{eksstokmatr} (above) a stochastic matrix is defined. Show that\nthe matrix product of two $n\\times n$ stochastic matrices is a stochastic matrix.\n\\endshex\n\nBelow is an example, where  matrix multiplication occurs in networks.\n\n\\begin{example}\n  Suppose we have five cities connected with roads as shown below\n\n\\includegraphics{bygraf.svg}\n\nThis network has a so called $5\\times 5$ \\emph{incidence matrix}, where city $i$ is associated with the\n$i$-th row and $i$-th column. A $1$ in the matrix in the $(i, j)$ entry means that there is a road\nfrom city $i$ to city $j$, whereas a $0$ means that city $i$ and city $j$ are not connected by a road:\n$$\nA = \\begin{pmatrix}\n0 & 1 & 1 & 0 & 0\\\\\n1 & 0 & 1 & 1 & 0\\\\\n1 & 1 & 0 & 1 & 1\\\\\n0 & 1 & 1 & 0 & 1\\\\\n0 & 0 & 1 & 1 & 0\n\\end{pmatrix}.\n$$\nHere\n$$\nA^2 =  \n\\begin{pmatrix}\n2 & 1 & 1 & 2 & 1 \\\\\n1 & 3 & 2 & 1 & 2 \\\\\n1 & 2 & 4 & 2 & 1 \\\\\n2 & 1 & 2 & 3 & 1 \\\\\n1 & 2 & 1 & 1 & 2 \n\\end{pmatrix}\\quad\\text{and}\\quad\nA^3 =\n\\begin{pmatrix}\n 2 & 5 & 6 & 3 & 3 \\\\\n 5 & 4 & 7 & 7 & 3 \\\\\n 6 & 7 & 6 & 7 & 6 \\\\\n 3 & 7 & 7 & 4 & 5 \\\\\n 3 & 3 & 6 & 5 & 2 \n\\end{pmatrix}.\n$$\nWhat is the interpretation of $A^2, A^3$ and  $A^n$ in general?\nIt turns out that the entry $(i, j)$ in the matrix $A^n$ exactly is\nthe number of paths of length $n$ from city $i$ to city $j$.\n\n\nFor example, there are $3$ paths from city $1$ to city $5$ of length $3$\ncorresponding to the paths $1245, 1345, 1235$.  The $2$ paths from city $1$ to city $1$ of\nlength $3$ are $1231, 1321$ and the  $5$ paths of length $3$ from city $1$ to city \n$2$ are $1342, 1242, 1312, 1212, 1232$.\n\n\n\\begin{hideinbutton}{A deeper explanation}\nSuppose that we have a network with $m$ cities and incidence matrix $A$.\n\nThe general proof of the observations above in our special example, builds on the\nfact that \na path of length $n$ from city $i$ to city $j$ has to end with a road from a neighboring city\n$k$ to $j$.\nFor every one of these neighboring cities, we may count the number of paths of length $n-1$\nfrom city $i$.\nIf $A^{n-1}_{gh}$ is the number of paths of length $n-1$ from city $g$ to city $h$,\nthen matrix multiplication tells us that \n$$\nA^n_{i j} = A^{n-1}_{i 1} A_{1 j} + \\cdots + A^{n-1}_{i m} A_{m j} \n$$\nThis number is exactly the number of paths of length $n$ from city $i$ to\ncity $j$, since \n$A_{k j} = 1$ only when $k$ is a neighboring city to city $j$ (and $0$ otherwise).\n\\end{hideinbutton}\n\\end{example}\n\n\\section{Matrix arithmetic}\\index{matrix arithmetic}\n\nMatrix multiplication is very different from ordinary multiplication of numbers:\nit is not \\url{commutative}{https://en.wikipedia.org/wiki/Commutative_property}.\nConsider the matrices\n$$\nA=\n\\begin{pmatrix}\n0 & 1\\\\\n0 & 0\n\\end{pmatrix}\\qquad\\text{and}\\qquad\nB = \n\\begin{pmatrix}\n0 & 0\\\\\n1 & 0\n\\end{pmatrix}.\n$$\nThen\n$$\nA B = \\begin{pmatrix} 1 & 0 \\\\ 0 & 0\\end{pmatrix}\\qquad \\text{and} \\qquad \nB A = \\begin{pmatrix} 0 & 0 \\\\ 0 & 1\\end{pmatrix}\n$$\ni.e.., $A B \\neq B A$. \n\n\\begin{sage}\nimport numpy as np\n  \nA = np.matrix( [[1, 1], [0, 1]] )\nB = np.matrix( [[1, 0], [1, 1]] )\nprint(\"A =\")\nprint(A)\nprint(\"B =\")\nprint(B)\nprint(\"AB=\")\nprint(A*B)\nprint(\"BA=\")\nprint(B*A)\n\\end{sage}\n\n\n\nAddition of matrices is like ordinary addition, except that you add all the entries of\nthe involved matrices.\n\n\\subsection{Matrix addition}\\index{addition of matrices}\n\nAddition of two matrices with the same number of rows and columns is defined below.\n$$\n\\begin{pmatrix}\na_{11} & \\cdots & a_{1 n} \\\\\n\\vdots & \\ddots & \\vdots\\\\\na_{m1} & \\cdots & a_{m n}\n\\end{pmatrix} +\n\\begin{pmatrix}\nb_{11} & \\cdots& b_{1 n} \\\\\n\\vdots & \\ddots & \\vdots\\\\\nb_{m1} & \\cdots & b_{m n}\n\\end{pmatrix}\n=\n\\begin{pmatrix}\na_{11} + b_{11} & \\cdots & a_{1 n} + b_{1n}\\\\\n\\vdots & \\ddots  & \\vdots\\\\\na_{m1}+b_{m1} & \\cdots & a_{m n}+b_{mn}\n\\end{pmatrix}.\n$$\n\nThe zero matrix is the ($m\\times n$) matrix containing zero in all its entries. When its number of\nrows and columns are clear from the context it is simply denoted by $0$. For $2\\times 3$ matrices\nfor example, we write\n$$\n0 =\n\\begin{pmatrix}\n  0 & 0 & 0\\\\\n  0 & 0 & 0\n\\end{pmatrix}.\n$$\n\n\n\\beginshex\n  Given an example of a non-zero $2\\times 2$ matrix, such that\n  $$\n  A^2 = 0.\n  $$\n\\endshex\n\n\\subsection{Multiplication of a number and a matrix}\\index{multiplication of matrix med number}\n\nA matrix may be multiplied by a number $\\lambda$ by multiplying each entry by the number:\n$$\n\\lambda \\begin{pmatrix}\na_{11} & \\cdots & a_{1 n} \\\\\n\\vdots & \\ddots & \\vdots\\\\\na_{m1} & \\cdots & a_{m n}\n\\end{pmatrix} =\n\\begin{pmatrix}\n\\lambda a_{11} & \\cdots & \\lambda a_{1 n} \\\\\n\\vdots & \\ddots & \\vdots\\\\\n\\lambda a_{m1} & \\cdots & \\lambda a_{m n}\n\\end{pmatrix}.\n$$\n\n\\beginshex\nDoes there exists a number  $\\lambda$, such that \n$$\n\\lambda \n\\begin{pmatrix}\n1 & 2 & 3\\\\\n4 & 5 & 6\n\\end{pmatrix} \n+\n\\begin{pmatrix}\n0 & 0 & 0\\\\\n0 & 0 & 2\n\\end{pmatrix} \n= \n\\begin{pmatrix}\n2 & 4 & 6\\\\\n8 & 10 & 15\n\\end{pmatrix}?\n$$\n\\endshex\n\n\n\\beginshex\nLet $A$ be a $2\\times 2$ matrix, such that\n$$\nA B = B A,\n$$\nfor every other $2\\times 2$ matrix $B$. Show that $A$ is a diagonal matrix of the form\n$$\nA =\n\\begin{pmatrix}\n  a & 0\\\\\n  0 & a\n\\end{pmatrix},\n$$\nwhere $a\\in \\RR$ i.e., $A = a I_2$.\n\\endshex\n\n\n\\subsection{The distributive law}\n\nOrdinary numbers $a, b, c$ satisfy\n$a (b + c) = a b + a c$. This rule also holds for\nmatrices and is called the distributive law (multiplication\nis distributed over plus)\n\n\\begin{proposition}\nLet $B$ and $C$ be $m\\times n$ matrices, $A$ an $r\\times m$ matrix and $D$ an $n\\times s$ matrix. Then\n$$\nA ( B + C) = A B + A C\\qquad\\text{and}\\qquad (B + C) D = B D + C D.\n$$\n\\end{proposition}\n\\begin{proof}[showhide]\n  Let us start by looking at $A(B+C) = A B + A C$. \nHere it suffices to do the proof, when $A$ is a row vector and\n$B, C$ column vectors, since\n$$\n(A (B+C))_{ij} = A_i (B+C)^j = A_i (B^j + C^j).\n$$\nFor $(B + C) D = B D + C D$, we may reduce to the case, where\n$B, C$ are row vectors and  $D$ a column vector, since\n$$\n((B+C) D)_{ij} = (B+C)_i D^j = (B_i + C_i) D^j.\n$$\nBoth of these cases follow using the distributive law for ordinary numbers.\n\\end{proof}\n\n\n\n\n\\beginshex\nSuppose that $A$ and $B$ are two $2\\times 2$ matrices. Is it true that\n$$\n(A + B)^2 = A^2 + B^2 + 2 A B?\n$$\nWhat about\n$$\n(A + B) (A - B) = A^2 - B^2?\n$$\n\\endshex\n\n\n\n\\subsection{The miraculous associative law}\n\nIt does not make sense to multiply three matrices $A, B$ and $C$. We have only defined\nmatrix multiplication for two matrices. There are two natural ways of evaluating\n$A B C$:\n$$\n( A B ) C\\qquad \\text{and}\\qquad A (B C).\n$$\n\nWe can begin by multiplying $A$ by $B$ and then multiply $C$ from the right.\nHowever, we may just as well start by multiplying $B$ by $C$ and then\nmultiply $A$ from the left.\n\nIt is in no way clear, that these two computations give the same result!\n\nThat this turns out to be true, is just one of many miracles in the universe (there is a\nrather cool mathematical explanation, though, addressed in an exercise below).\n\n\\begin{theorem}\\label{thmmatmultass}\nLet $A$ be an $m\\times n$ matrix, $B$ an $n\\times r$ matrix and $C$ an $r\\times s$ matrix. Then\n$$\n(A B) C = A (B C).\n$$\n\\end{theorem}\n\\begin{proof}[showhide]\n  We must prove that \n$$\n((A B) C)_{ij} = (A (B C))_{ij}\n$$\nfor $1\\leq i \\leq m$ og $1\\leq j \\leq s$. The left hand side can be written\n\\begin{align}\\label{eqleft}\n(A B)_i C^j &= (A_i B^1, \\dots, A_i B^r) C^j\\\\\n            &= (A_i B^1) C_{1j} + (A_i B^2) C_{2j} + \\cdots + (A_i B^r) C_{rj}.\n\\end{align}\nThe right hand side is \n\\begin{equation}\\label{eqright}\nA_i (B C)^j = A_i \\begin{pmatrix} B_1 C^j \\\\ \\vdots \\\\ B_n C^j\\end{pmatrix}\n            = A_{i1} (B_1 C^j) + \\cdots + A_{in} (B_n C^j).\n          \\end{equation}\n\n          Writing the row-column multiplications in \\eqref{eqleft}, we get\n\\begin{align}\\label{rowscomp}\n&A_{i1} B_{11} C_{1j} + \\cdots + A_{in} B_{n1} C_{1j} +\\\\\n&A_{i1} B_{12} C_{2j} + \\cdots + A_{in} B_{n2} C_{2j} +\\\\\n&\\vdots\\\\\n&A_{i1} B_{1r} C_{rj} + \\cdots + A_{in} B_{nr} C_{rj}.\n\\end{align}\n          Writing the row-column multiplications in \\eqref{eqright}, we get\n\\begin{align}\\label{colscomp}\n&A_{i1} B_{11} C_{1j} + \\cdots + A_{i1} B_{1r} C_{rj} +\\\\\n&A_{i2} B_{21} C_{1j} + \\cdots + A_{i2} B_{2r} C_{rj} +\\\\\n&\\vdots\\\\\n&A_{in} B_{n1} C_{1j} + \\cdots + A_{in} B_{nr} C_{rj}.\n\\end{align}\nThe rows in the sum in  \\eqref{rowscomp} correspond to the columns in the sum \\eqref{colscomp}.\nTherefore these sums are equal and $((A B) C)_{ij} = (A (B C))_{ij}$.\n\\end{proof}\n\n\\begin{frameit}\n\\begin{remark}\nThe associative law $(A B) C = A (B C)$ is true, but in computing $A B C$ there can be a (big)\ndifference in the number of multiplications in the two computations\n$A (B C)$ and $(A B) C$ i.e., efficiency is not associative for\nmatrix multiplication. In the notation of Theorem \\ref{thmmatmultass}, computing\n$(A B) C$ requires\n$$\nm n r + m r s = m r (n + s)\n$$\nmultiplications, whereas computing $A (B C)$ requires\n$$\nn r s  + m n s = n s (m + r)\n$$\nmultiplications. If for example $m=10000, n = 10, r = 10000$ and $s = 10$, then computing\n$(A B) C$ requires $2\\cdot 10^9$ multiplications, whereas\ncomputing $A (B C)$ requires $2\\cdot 10^6$ multiplications!   \n\\end{remark}\n\\end{frameit}\n\n\n\\beginshex\nVerify the associative law for the three matrices\n$$\nA =\n\\begin{pmatrix}\n  1 & 2\\\\\n  3 & 4\n\\end{pmatrix}, \\qquad\nB =\n\\begin{pmatrix}\n  1 & 2 & 3\\\\\n  4 & 5 & 6\n\\end{pmatrix}\\qquad\\text{and}\\qquad\nC =\n\\begin{pmatrix}\n  6 & 3\\\\\n  5 & 2\\\\\n  4 & 1\n\\end{pmatrix}\n$$\nby showing by explicit computation that\n$$\n(A B) C = A (B C).\n$$\n\\endshex\n\n\\beginshex\nThere is in fact a high tech explanation that the associative law for matrices holds. An explanation\nthat makes the calculations in the above proof superfluous and shows the raw power of\nabstract mathematics: suppose that\n$f: \\RR^n\\rightarrow \\RR^m, g:\\RR^r\\rightarrow \\RR^n$ and $h:\\RR^s\\rightarrow \\RR^r$ are linear maps.\nThen $f\\circ (g\\circ h)$ and $(f\\circ g)\\circ h$ are both linear maps from $\\RR^s\\rightarrow \\RR^m$, such that\n$$\n(f\\circ (g\\circ h))(x) = ((f\\circ g)\\circ h)(x) = f( g ( h (x)))\n$$\nfor every $x\\in \\RR^s$. How does this relate to the associative law for matrix\nmultiplication?\n\\endshex\n\n\\section{The inverse matrix}\n\nYou are allowed to divide by a number provided it is $\\neq 0$. Does it makes sense\nto divide by matrices?\n\nIt does, but there are some matrices that correspond to the number $0$ that we are not allowed\nto divide by.\n\n\\beginshex\nLet $A, B$ and $C$ be $n\\times n$ matrices. Show that\n$$\nB A = I_n\n$$\nand\n$$\nA C = I_n\n$$\nimplies that $B = C$.\n\\endshex\n\n\\index{invertible matrix}\\index{inverse matrix}\n\n\\begin{definition}\nAn $n\\times n$ matrix $A$ is called invertible, if there exists an  $n\\times n$ matrix $B$, such that \n$$\nA B = B A = I_n.\n$$\nIn this case, $B$ is called the inverse matrix of $A$ and denoted $A^{-1}$.\n\\end{definition}\n\n\n\n\\beginshex\nShow that a quadratic matrix with a column or row consisting entirely of zeros cannot\nbe invertible.\n\\endshex\n\n\\beginshex\nSuppose that\n$$\nA = \\begin{pmatrix}\n  a & b\\\\\n  c & d\n  \\end{pmatrix}\n  $$\n  with $D = a d - b c\\neq 0$. Prove that $A$ is invertible with\n  $$\n  A^{-1} = \\frac{1}{D}\\begin{pmatrix} d & -b\\\\ -c & a \\end{pmatrix}.\n  $$\n\\endshex\n\n\n\\beginshex\nWhen is a quadratic diagonal matrix invertible? Look first at the $2\\times 2$ case:\n$$\n\\begin{pmatrix}\n  a & 0\\\\\n  0 & d\n\\end{pmatrix}.\n$$\n\\endshex\n\nThe inverse matrix can be computed in \\texttt{numpy}:\n\n\\begin{sage}\nimport numpy as np\n\nA = np.matrix( [[5, 3], [3, 2]] )\nprint(\"The inverse of\")\nprint(A)\nprint(\"is\")\nprint(A.I)\n\n\\end{sage}\n\nThe inverse matrix enters the picture when solving $n$ linear\nequations with $n$ unknowns:\n\\begin{align*}\na_{11}x_1 + a_{12} x_2 + \\cdots + a_{1n} x_n &= b_1\\\\\n&\\vdots\\\\\na_{n1} x_1 + a_{n2} x_2 + \\cdots + a_{nn} x_n &= b_n\n\\end{align*}\ncan be rewritten using matrix notation as \n$$\n\\begin{pmatrix}\na_{11} &  \\cdots & a_{1 n} \\\\\n\\vdots & \\ddots & \\vdots\\\\\na_{n1} & \\cdots & a_{n n}\n\\end{pmatrix}\n\\begin{pmatrix}\nx_1 \\\\ \\vdots \\\\ x_n\n\\end{pmatrix}\n= \n\\begin{pmatrix}\nb_1 \\\\ \\vdots \\\\ b_n\n\\end{pmatrix}\n$$\nor more compactly as $A x = b$.\n\n\n\nIf $A$ is invertible, then the associative law gives the following:\n\\label{ainvsol}\n\\begin{frameit}\n\\begin{align*}\nA x &= b \\iff\\\\\n A^{-1}  \\left(A x\\right) &= A^{-1} b \\iff \\\\\n(A^{-1} A) x &= A^{-1} b \\iff\\\\\nI x &= A^{-1} b\\iff\\\\\nx &= A^{-1} b.\\\\ \n\\end{align*}\n\\end{frameit}\n\nThe inverse matrix gives the solution to the linear equations $A x = b$ just by one matrix multiplication!\n\n\\begin{example}\n  The system of linear equations\n\\begin{equation}\\label{simplign}\n\\begin{matrix}\n&5 x &+ &3 y &= &13\\\\\n&3 x &+&2 y &= &8\n\\end{matrix}\n\\end{equation}\ncan be rewritten using matrix multiplication to\n$$\nA v = b,\n$$\nwhere\n$$\nA = \\begin{pmatrix}\n5& 3 \\\\ \n3 & 2\n\\end{pmatrix}, \\qquad\nv = \n\\begin{pmatrix} x \\\\ y \\end{pmatrix}\\qquad \\text{and}\\qquad\nb = \\begin{pmatrix} 13 \\\\ 8 \\end{pmatrix}.\n$$ \n\nHere $A$ is invertible and\n$$\nA^{-1} = \n\\begin{pmatrix}\n2 & -3\\\\\n-3 & 5\n\\end{pmatrix}.\n$$\nOne simple matrix multiplication\n$$\n\\begin{pmatrix} x \\\\ y \\end{pmatrix} = \n\\begin{pmatrix}\n2 & -3\\\\\n-3 & 5\n\\end{pmatrix} \\begin{pmatrix} 13 \\\\ 8 \\end{pmatrix} = \n\\begin{pmatrix} 2 \\\\ 1 \\end{pmatrix}\n$$\nshows the solution we expect from  \\eqref{simplign}.\n\\end{example}\n\n\nThe product of two invertible matrices (when this makes sense)\nis an invertible matrix. This is the content of the following result.\n\n\\label{prodinv}\n\\begin{proposition}\nThe product $A B$ of  two invertible matrices $A$ and $B$ is invertible and\n$(A B)^{-1} = B^{-1} A^{-1}$.\n\\end{proposition}\n\\begin{proof}[showhide]\nWe must check that \n$$\n(B^{-1} A^{-1}) (A B) = I\\qquad\\text{and}\\qquad A B (B^{-1} A^{-1}) = I.\n$$\nLet us check the first condition using the associative law:\n\\begin{align*}\n(B^{-1} A^{-1}) (A B) &= ((B^{-1} A^{-1}) A) B\\\\\n                    &= (B^{-1} (A^{-1} A)) B \\\\\n                    &= (B^{-1} I) B = B^{-1} (I B) = B^{-1} B = I,\n\\end{align*}\nwhere  $I$ denotes the identity matrix. The condition $A B (B^{-1} A^{-1}) = I$ is verified in the\nsame way.\n\\end{proof}\n\n\n\\beginshex\n\n  We have defined a matrix $A$ to be invertible if there exists a matrix $B$, such that\n  $A B = I$ and $B A = I$. Suppose that only $B A = I$. Can we then conclude that $A B = I$?\n\n\\endshex\n\n\n\\beginshex\nLet\n$$\nN =\n\\begin{pmatrix}\n  0 & 1 & 1 & 1\\\\\n  0 & 0 & 1 & 1\\\\\n  0 & 0 & 0 & 1\\\\\n  0 & 0 & 0 & 0\n\\end{pmatrix}.\n$$\nCompute the powers $N^k$ for $k\\geq 2$ i.e., $N^2, N^3, \\dots$. Now let\n$$\nA = I + N,\n$$\nwhere $I = I_4$.\nShow that $A$ is invertible, and\n$$\nA^{-1} = I - N + N^2 - N^3.\n$$\nCompute $A^{-1}$.\n\nDo you see a way of generalizing this computation to \n$n\\times n$ matrices $N$ with a property shared by the\n$4\\times 4$ matrix above?\n\n\\endshex\n\n\\subsection{Well, how do I find the inverse of a matrix?}\n\nFinding the inverse of a matrix or deciding that the matrix is not invertible is\na matter of solving systems of linear equations.\n\nGiven an $n\\times n$ matrix $A$, we need to see if there exists an $n\\times n$ matrix\n$B$, such that\n\\begin{equation}\\label{invdef}\nA B = I,\n\\end{equation}\nwhere $I = I_n$ is the identity matrix of order $n$. We can do this by\ncomputing the columns of $B$. From the definition in \\eqref{invdef}, the\n$j$-th column $B^j$ of $B$ must satisfy\n\\begin{equation}\\label{lineqinv}\nA B^j = I^j.\n\\end{equation}\nThis follows from the definition of matrix multiplication!\n\nThe identity in \\eqref{lineqinv} is a system of $n$ linear equations\nin $n$ unknowns. The unknowns are the entries in the $j$-th column\n$B^j$ of the inverse matrix $A^{-1}$ (if it exists).\n\n\\begin{example}\\label{exinverse}\n  Suppose that $A$ is a $2\\times 2$ matrix. Then the inverse matrix\n  $B$ (if it exists) can be computed from the systems of linear\n  equations below.\n  $$\n  A B^1 = \\begin{pmatrix} 1 \\\\ 0 \\end{pmatrix}\\qquad\\text{and}\\qquad A B^2 = \\begin{pmatrix} 0 \\\\ 1 \\end{pmatrix}.\n  $$\n  Writing\n  $$\n  \\begin{pmatrix} x \\\\ y \\end{pmatrix} = B^1\\qquad\\text{and}\\qquad \\begin{pmatrix} u \\\\ v\\end{pmatrix} = B^2\n  $$\n  for the first and second columns, the systems of linear equations can be written as\n$$\n\\begin{matrix}\n  &A_{11} x &+  &A_{12} y &=  &1\\\\\n  &A_{21} x &+  &A_{22} y &=  &0\n\\end{matrix}\\qquad\\text{and}\\qquad\n\\begin{matrix}\n  &A_{11} u &+  &A_{12} v &=  &0\\\\\n  &A_{21} u &+  &A_{22} v &=  &1\n\\end{matrix},\n$$\nwhere\n$$\nB =\n\\begin{pmatrix}\n  x & u\\\\\n  y & v\n\\end{pmatrix}.\n$$\nA concrete example along with a useful way of keeping track of the computation is presented in the video below.\n\n\\begin{video}\n\\youtube{4BX3eW4qo3g}\n\\end{video}\n\\end{example}\n\n\\beginshex\nCompute the inverse of the matrix\n$$\nA =\n\\begin{pmatrix}\n  1 & 1 & 1\\\\\n  1 & 2 & 1\\\\\n  1 & 1 & 3\n\\end{pmatrix}\n$$\nby employing the method of solving linear equations above. Explain\nthe steps in your computation. You may find it useful to collect\ninspiration from the video in Example \\ref{exinverse}.\n\\endshex\n\n\\section{The transposed matrix}\\index{transposed matrix}\n\nThe transpose of an $m\\times n$ matrix $A$ is the $n\\times m$ matrix $A^T$ given by\n$$\nA^T_{i j} = A_{j i}.\n$$\nAs an example, we have\n$$\n\\begin{pmatrix}\n0 & 2 & 4 & -2\\\\\n3 & 2 & 7 & 4\n\\end{pmatrix}^T =\n\\begin{pmatrix}\n0 & 3\\\\\n2 & 2\\\\\n4 & 7\\\\\n-2 & 4\n\\end{pmatrix}.\n$$\nNotice also that $(A^T)^T = A$ for an arbitrary matrix $A$.\n\n\\begin{proposition}\\label{prop:transformel}\nLet $A$ be an $m\\times r$ matrix and $B$ an $r\\times n$ matrix. Then\n$$\n(A B)^T = B^T A^T.\n$$\n\\end{proposition}\n\\begin{proof}[showhide]\n  By definition $(A B)^T_{i j} = (A B)_{j i}$. This entry is given\n  by row-column multiplication of the $j$-th row in $A$ and \nthe $i$-th column in  $B$, which is the row-column multiplication of the\n$i$-th row  in $B^T$ and the $j$-th column  in $A^T$.\n\\end{proof}\n\n\\beginshex\nLet $A$ be a quadratic matrix. Prove that $A$ is invertible if and only if\n$A^T$ is invertible.\n\\endshex\n\n\\beginshex In the sage window below, you are supposed to experiment a\nbit by entering an arbitrary matrix $B$ and studying the quadratic\nmatrix $B B^T$. Is there anything special about this product?  Press\nthe \\emph{Further explanation} button below the sage window to display\nthe rest of the exercise after(!) you have completed your\nexperimentation.\n\n\\begin{sage}\nimport numpy as np\n\nB = np.matrix( [[1, 2, 3], [4, 5, 6], [7, 8, 9]] )\nprint(\"B is \")\nprint(B)\nprint(\"B times the transpose of B is \")\nprint(B*np.transpose(B))\n\\end{sage}\n\n\\begin{hideinbutton}{Further explanation}\n  A quadratic matrix $A$ is called symmetric if $A = A^T$. Prove that\n$$\nB B^T\n$$\nis a symmetric matrix, where $B$ is an arbitrary matrix.\n\\end{hideinbutton}\n\\endshex\n\n\\section{Symmetric matrices}\\label{Sectionsymmat}\n\nA (quadratic) matrix $A$ is called symmetric if $A = A^T$. Visually,\nthis means that $A$ is symmetric around the diagonal like the\n$3\\times 3$ matrix\n$$\n\\begin{pmatrix}\n  1 & \\cblue{2} & 3\\\\\n  \\cblue{2} & 5 & 4\\\\\n  3 & 4 & 6\n\\end{pmatrix},\n$$\nbut not like the $3\\times 3$ matrix\n$$\n\\begin{pmatrix}\n  1 & \\cblue{2} & 3\\\\\n  \\cred{4} & 5 & 6\\\\\n  7 & 8 & 9\n\\end{pmatrix}.\n$$\n\n\\beginshex\nShow that\n$$\nB^T A B\n$$\nis a symmetric matrix, when $A$ is a symmetric matrix and\n$B$ is an arbitrary matrix. Both matrices are assumed\nquadratic of the same dimensions.\n\\endshex\n\n\nIf $A$ is a symmetric $n\\times n$ matrix, we define the\nfunction $f_A: \\RR^n\\rightarrow \\RR$ given by\n$$\nf_A(v) = v^T A v.\n$$\n\nThis definition is rather compact. You are encouraged to see the video below\nfor a specific example, when $A$ is a $2\\times 2$ matrix.\n\n\n\\begin{video}\\label{videoposdef}\n  \\youtube{YNwrLMJ8byM}\n\\end{video}\n\n\n\n\nInside set of the symmetric matrices we find two very important subsets\nof matrices: the positive definite and the positive semi-definite\nmatrices. They correspond to positive and non-negative\nreal numbers.\n\n\\subsection{Positive definite matrices}\n\nA symmetric matrix $A$ is called \\emph{positive definite} if\n$$\nf_A(v) > 0\n$$\nfor every $v\\in \\RR^n\\setminus\\{0\\}$.\n\n\\beginshex\nGive examples of (non-zero) $1\\times 1$ and $2\\times 2$ matrices that are\npositive definite and ones that fail to be positive\ndefinite.\n\nWhen is a $2\\times 2$ diagonal matrix positive definite?\n\\endshex\n\n\\beginshex\nLet $A$ be a symmetric $n\\times n$ matrix. Show that\n$A$ is not positive definite if $A_{11} < 0$.\n\\endshex\n\n\n\\subsection{Positive semi-definite matrices}\n\nA symmetric matrix $A$ is called \\emph{positive semi-definite} if\n$$\nf_A(v) \\geq 0\n$$\nfor every $v\\in \\RR^n$.\n\nFrom the definitions it follows that a positive definite matrix is\npositive semi-definite.\n\n\\beginshex\nGive an example of a non-zero matrix that is positive semi-definite,\nbut not positive definite.\n\nWhen is a $2\\times 2$ diagonal matrix positive semi-definite?\n\\endshex\n\n\n\\subsection{Symmetric reductions}\n\nAs you probably have noticed, it is rather straightforward to\nsee when a diagonal matrix is positive (semi)definite. For a\ngeneral symmetric matrix, one needs to transform to\nan equivalent diagonal matrix. This is done\nusing the following result.\n\n\\begin{proposition}\n  Let $A$ be a symmetric $n\\times n$ matrix and $B$ an\n  invertible $n\\times n$ matrix. Then $A$ is\n  positive (semi) definite if and only if\n  $$\n  B^T A B\n  $$\n  is positive (semi) definite.\n\\end{proposition}\n  \\begin{proof}[showhide]\n    Every vector $v\\in \\RR^n$ is equal to $B u$ for a unique $u\\in \\RR^n$,\n    since $B$ is invertible. Why? The upshot is that the equation\n$$\nv = B u\n$$\ncan be solved by multiplying both sides by $B^{-1}$ giving\n$$\nv = B u \\iff B^{-1} v = B^{-1} (B u) = (B^{-1} B) u = u.\n$$\n\n\n\n    So we get\n    $$\n    v^T A v = (B u)^T A (B u) = u^T (B^T A B) u.\n    $$\n    This computation shows that $A$ is positive (semi) definite if\n    $B^T A B$ is positive semi-definite. The same\n    reasoning with $u = B^{-1} v$ shows that $B^T A B$ is\n    positive (semi) definite if $A$ is positive (semi) definite.\n\n    Notice that it is important that $B v = 0$ only happens\n    when $v=0$.\n  \\end{proof}\n\n\n\\beginshex\nLet\n$$\nD =\n\\begin{pmatrix}\n  d & 0\\\\\n  0 & e\n\\end{pmatrix}\n$$\nbe a diagonal matrix. What conditions must the diagonal\nentries $d$ and $e$ satisfy in order for\n$D$ to be positive definite?\n\nLet\n$$\nA =\n\\begin{pmatrix}\n  a & c\\\\\n  c & b\n\\end{pmatrix}\n$$\ndenote a symmetric $2\\times 2$ matrix, where $a\\neq 0$. Let\n$$\nB =\n\\begin{pmatrix}\n  1 & -\\frac{c}{a}\\\\\n  0 & 1\n\\end{pmatrix}.\n$$\nShow that $B$ is invertible and compute\n$$\nB^T A B.\n$$\nUse this to show that $A$ is positive definite if and only if\n$a>0$ and $a b - c^2 > 0$.\n\nLet $f:\\RR^2\\rightarrow \\RR$ be the function defined by\n$$\nf(x, y) = 2 x^2 + 3 y^2 + 4 x y.\n$$\nShow that $f(x, y)\\geq 0$ for every $x, y\\in \\RR$.\n\\endshex\n\n\n\\end{document}\n", "meta": {"hexsha": "21f94a1f1cdfa9620629d67ce11add0d29963367", "size": 43479, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/IMO21/matrices.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/matrices.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/matrices.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": 24.317114094, "max_line_length": 170, "alphanum_fraction": 0.6485429748, "num_tokens": 16421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.843895106480586, "lm_q1q2_score": 0.7563421386096789}}
{"text": "\\subsection{Simulation}\n\nThe channel encoder that was skipped in section \\ref{sec:step1} is now implemented as a low-density parity check code (LDPC) encoder. Soft and hard decoding have been implemented with a code rate of 1/2 and their performance is compared next.\n\nThe channel coding adds structured redundancy  to the information sent by the transmitter to be able to detect and correct errors at the receiver side. The LDPC code has the property that the check matrix is sparse, allowing a lower complexity of the implementation.\n\n\\subsubsection{Hard decoding}\n\\iffalse\n\\begin{figure}[H]\n\\centering\n    \\includegraphics{fig/HardLDPC.tex}\n     \\caption{Hard LDPC}\n    \\label{fig:HardLDPC}\n\\end{figure}\n\\fi\n\nThe hard decoding is based on the implementation of a Tanner graph. The influence of the maximal number of iterations on the BER curves is shown in Figure \\ref{fig:HardLDPCbis} for a 16-QAM modulation. The conclusions can be generalized to any modulation.\n\n\\begin{figure}[H]\n\\centering\n    \\includegraphics[width=\\textwidth]{fig/HardLDPCbis.tex}\n     \\caption{Effect on the BER curves of Hard LDPC decoding for a 16-QAM modulation}\n    \\label{fig:HardLDPCbis}\n\\end{figure}\n\nFor the hard decoding, the performance is worsened at low SNR. Indeed, a noise which is too important causes the code to add errors when it is trying to correct them. Increasing the maximal number of iterations allows a slight improvement in performance.\n\n\\subsubsection{Soft decoding}\n\nIn practice, hard decoding is never used as the soft decoding allows for much better performance. Instead on basing the decision on the received bits, it computes probablities based on the received symbols. The results of the simulations for a 2-PAM is shown in Figure \\ref{fig:SoftLDPC}.\n\n\\begin{figure}[H]\n\\centering\n    \\includegraphics{fig/SoftLDPC.tex}\n     \\caption{Effect on the BER curves of Hard LDPC decoding for a 16-QAM modulation}\n    \\label{fig:SoftLDPC}\n\\end{figure}\n\nThe theoretical curve for the ideal communication chain as well as the curve for hard decoding are shown as references. The improvement is significant with soft decoding.\n\n\\subsection{Questions}\n\n\\subsubsection{Questions regarding the simulation}\n\n\\paragraph{When building the new BER curves, do you consider the uncoded or coded bit energy on\tthe x-axis?} \\mbox{}\n\nThe coded bit energy is considered here.\n\n\\paragraph{How do you limit the number of decoder iterations?} \\mbox{}\n\nFor the hard decoding, the iterations stop either when the maximum number of iterations is reached or when the syndrome is zero.\n\nFor the soft decoding,  stop either when the maximum number of iterations is reached or when there is no more detected errors.\n\n\\paragraph{Why is it much simpler to implement the soft decoder for BPSK or QPSK than for 16-QAM or 64-QAM?} \\mbox{}\n\nIn the case of the 16-QAM or 64-QAM, the euclidean distance should be computed when decoding. This is not the case for BPSK and QPSK, where the decision can be made only by looking at the real and imaginary part of the received symbols.\n\n\\subsubsection{Questions regarding the communication system}\n\n\\paragraph{Demonstrate analytically that the parity check matrix is easily deduced from the generator matrix when the code is systematic.} \\mbox{}\n\nA code is systematic when the mapping is such that part of the code vector coincides with the message vector. In that case, the generator matrix has the form $\\underline{\\underline{G}} = \\left[\\underline{\\underline{P}} | \\underline{\\underline{I}}\\right]$, with $\\underline{\\underline{P}}$ the parity array and $\\underline{\\underline{I}}$ the identity matrix of the corresponding size.\nThe parity check matrix should be created so that its rows are orthogonal to the rows of the generator matrix:\n\n\\begin{equation*}\n \\underline{\\underline{G}} \\cdot \\underline{\\underline{H}}^T = \\underline{\\underline{0}}\n\\end{equation*}\n\nThe solution to this equation is given by $\\underline{\\underline{H}} = \\left[\\underline{\\underline{I}} | \\underline{\\underline{P}}^T\\right]$. Indeed:\n\n\\begin{equation*}\n\t\\underline{\\underline{G}} \\cdot \\underline{\\underline{H}}^T = \\left[\\underline{\\underline{P}} | \\underline{\\underline{I}}\\right] \\cdot \\left[\\underline{\\underline{I}} | \\underline{\\underline{P}}^T\\right]^T =  \\underline{\\underline{P}} \\oplus  \\underline{\\underline{P}} =0\n\\end{equation*}\n\n\\paragraph{Explain why we can apply linear combinations on the rows of the parity check matrix to produce an equivalent systematic code.} \\mbox{}\n\nThe rows of the parity check matrix are the basis vectors of a subspace which is perpendicular to the subspace spanned by the generator matrix. A linear combination of these basis vectors will still be a basis for the same subspace and the resulting code will be equivalent.\n\n\\paragraph{Why is it especially important to have a sparse parity check matrix (even more important\tthan having a sparse generator matrix)?} \\mbox{}\n\nA sparse parity check matrix allows to significantly reduce the complexity of the decoder. Indeed, element $H_{ij}$ being equal to 1 results in a logical connection in the Tanner graph between the check-node $c_i$ and the variable-node $v_j$. Hence, reducing the number of 1's in $\\underline{\\underline{H}}$ reduces the number of exchanged messages and the number of computations.\n\n\\paragraph{Explain why the check nodes only use the information received from the other variable nodes when they reply to a variable node.} \\mbox{}\n\nThe information exchanged between the check and variable nodes has to be statistically independent for hard and soft decoding. This means that only the information which is not related to the current node is used to compute the answer.", "meta": {"hexsha": "921905888853ffb829d1a25e68991833edadd93f", "size": 5679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/step2.tex", "max_stars_repo_name": "mpetitjean/DVB-S2", "max_stars_repo_head_hexsha": "c63a0617cc679de76166c62727a0c778099f9d62", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-09-08T10:12:11.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-14T07:46:58.000Z", "max_issues_repo_path": "report/sections/step2.tex", "max_issues_repo_name": "amatepl/DVB-S2", "max_issues_repo_head_hexsha": "c63a0617cc679de76166c62727a0c778099f9d62", "max_issues_repo_licenses": ["MIT"], "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/step2.tex", "max_forks_repo_name": "amatepl/DVB-S2", "max_forks_repo_head_hexsha": "c63a0617cc679de76166c62727a0c778099f9d62", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2018-10-08T10:48:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T09:02:37.000Z", "avg_line_length": 66.0348837209, "max_line_length": 384, "alphanum_fraction": 0.7784821271, "num_tokens": 1329, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240791017536, "lm_q2_score": 0.8740772433654401, "lm_q1q2_score": 0.7562726779546622}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Which of the following equations are linear?\n  \\begin{enumerate}\n  \\item[(a)] $2x-3y+4z = -10$\n  \\item[(b)] $2.123x_1 + 5.541x_2 - 9.101x_3 = 11.012$\n  \\item[(c)] $x^2+y^2+z^2 = 1$\n  \\item[(d)] $\\frac{1}{\\sqrt{2}}x+4^3y = \\sin(\\frac{\\pi}{3})$\n  \\item[(e)] $x+yz = 3$\n  \\end{enumerate}\n\n  \\begin{sol}\n    All of them except (c) and (e).\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the system of equations\n  \\begin{equation*}\n    \\begin{array}{c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c@{~}c}\n      x&+&2y&+&3z&+&4w &=& 4 \\\\\n      x&+&y&+&z&+&w &=& 2 \\\\\n      x&+&2y&+&2z&+&w &=& 2.\n    \\end{array}\n  \\end{equation*}\n  For each of the following tuples $(x,y,z,w)$ of real numbers,\n  determine whether it is a solution of the first equation, second\n  equation, and/or third equation. Which ones are solutions to the\n  system of equations?\n\n  \\begin{center}\n    (a) $(2,0,-2,2)$ \\quad\n    (b) $(2,2,-2,0)$ \\quad\n    (c) $(1,1,-1,1)$ \\quad\n    (d) $(3,0,-1,1)$ \\quad\n    (e) $(2,-2,2,0)$\n  \\end{center}\n\n  \\begin{sol}\n    (a) is a solution to equations 1 and 2, (b) is a solution to\n    equations 2 and 3, (c) is a solution to equations 1, 2, and 3,\n    (d) is a solution to 1 and 3, and (e) is a solution to equations\n    1, 2, and 3. Only (c) and (e) are solutions to the system of\n    equations.\n  \\end{sol}\n\\end{ex}\n\n", "meta": {"hexsha": "28a49edd0abf5338b7b185831f8f19bda118af77", "size": 1345, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/SystemsofEquations-Algebraic.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/SystemsofEquations-Algebraic.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/SystemsofEquations-Algebraic.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 27.4489795918, "max_line_length": 68, "alphanum_fraction": 0.5576208178, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.8740772335247531, "lm_q1q2_score": 0.7562726664025913}}
{"text": "\\documentclass{article}\n\n%-------------------------------------------------\n\n\\usepackage{fullpage}\n\n\\usepackage{amsfonts}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\n%-------------------------------------------------\n\\begin{document}\n\n\\section*{Basics of Gaussian Process Priors}\n\nWe assume the values of a function are drawn from a single process, and assume a Gaussian distribution with a particular form for the covariance between values. \nWe then condition the values at sample points based on the values at observed points to obtain a ``posterior distribution'' for the sample points given the observed values.\nThis can be illustrated below with a simple example.\n\n\\subsection*{Simple example of conditioning}\n\nConsider 2 values of a function: $f_a$ and $f_b$ corresponding to the ordinates $x_a$ and $x_b$.\nWe assume these values are correlated in some way, so that\n\\begin{equation}\n\\begin{matrix}\nf_a \\\\ \nf_b\n\\end{matrix}\n\\sim\n\\mathcal{N} \\left(\n\\mathrm{mean}=\n\\begin{bmatrix}\n0 \\\\\n0\n\\end{bmatrix}\n,\n\\mathrm{covariance}=\n\\begin{bmatrix}\n\\sigma_{aa}^2 & \\sigma^2_{ab} \\\\\n\\sigma_{ba}^2 & \\sigma^2_{bb}\n\\end{bmatrix}\n\\right)\n\\end{equation}\n\nThe requirement for zero-mean is not stringent in practice. \nNow, a feature of the Gaussian distribution is that we can immediately write down the marginal distributions as\n\\begin{equation}\nf_a \\sim \\mathcal{N}\\left(0, \\sigma_{aa}^2\\right)\n\\end{equation}\nand so forth. \nNow, to compute the conditional probability $p(f_b|f_a)$, we recognize\n\\begin{equation}\np(f_b|f_a) = \\frac{p(f_a, f_b)}{p(f_a)}\n\\end{equation}\nand the rest is just algebra.\nWe provide this in all it's gory detail here for pedagogy.\n\n\\begin{align}\np(f_a) & = \\frac{1}{\\sqrt{2\\pi\\sigma^2_{aa}}} \\mathrm{exp}\\left(-\\frac{f_a^2}{2\\sigma^2_{aa}} \\right)\n\\end{align}\n\\begin{align}\np(f_a, f_b) & = \\frac{1}{2\\pi\\sqrt{\\sigma^2_{aa}\\sigma^2_{bb} - \\sigma^4_{ab}}} \\mathrm{exp}\\left( -\\frac{1}{2} \\begin{bmatrix} f_a & f_b \\end{bmatrix} \\frac{1}{\\sigma^2_{aa}\\sigma^2_{bb} - \\sigma^4_{ab}}\\begin{bmatrix} \\sigma_bb^2 & -\\sigma_{ab}^2 \\\\ -\\sigma_{ab}^2 & \\sigma_{aa}^2 \\end{bmatrix} \\begin{bmatrix} f_a \\\\ f_b \\end{bmatrix} \\right) \\nonumber \\\\\n            & = \\frac{1}{2\\pi\\sqrt{\\sigma^2_{aa}\\sigma^2_{bb} - \\sigma^4_{ab}}} \\mathrm{exp}\\left( -\\frac{1}{2} \\frac{f_a^2\\sigma_{bb}^2 + f_b^2\\sigma_{aa}^2 - 2f_a f_b \\sigma_{ab}^2}{\\sigma^2_{aa}\\sigma^2_{bb} - \\sigma^4_{ab}} \\right)\n\\end{align}\n\\begin{align}\np(f_b|f_a) & = \\frac{p(f_a, f_b)}{p(f_a)} \\nonumber \\\\\n           & = \\sqrt{\\frac{\\sigma_{aa}^2}{2\\pi\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}}\\mathrm{exp}\\left( \\frac{f_a^2}{2\\sigma_{aa}^2} - \\frac{1}{2} \\frac{f_a^2\\sigma_{bb}^2 + f_b^2\\sigma_{aa}^2 - 2f_a f_b \\sigma_{ab}^2}{\\sigma^2_{aa}\\sigma^2_{bb} - \\sigma^4_{ab}}\\right) \\nonumber \\\\\n           & = \\sqrt{\\frac{\\sigma_{aa}^2}{2\\pi\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}}\\mathrm{exp}\\left( \\frac{f_a^2}{2}\\left(\\frac{1}{\\sigma_{aa}^2} - \\frac{\\sigma_{bb}^2}{\\sigma_{aa}^2\\sigma_{bb}^2-\\sigma_{ab}^4}\\right) - \\frac{f_b^2 \\sigma_{aa}^2 - 2 f_a f_b \\sigma_{ab}^2}{2\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}\\right) \\nonumber \\\\\n           & = \\sqrt{\\frac{\\sigma_{aa}^2}{2\\pi\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}}\\mathrm{exp}\\left( -\\frac{f_a^2\\sigma_{ab}^4}{2\\sigma_{aa}^2\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)} - \\frac{\\sigma_{aa}^2}{2\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}\\left(f_b^2 - 2f_af_b\\frac{\\sigma_{ab}^2}{\\sigma_{aa}^2}\\right)\\right) \\nonumber \\\\\n           & = \\sqrt{\\frac{\\sigma_{aa}^2}{2\\pi\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)}}\\mathrm{exp}\\left( - \\frac{\\sigma_{aa}^2}{2\\left(\\sigma_{aa}^2\\sigma_{bb}^2 - \\sigma_{ab}^4\\right)} \\left(f_b - f_a\\frac{\\sigma_{ab}^2}{\\sigma_{aa}^2}\\right)^2 \\right)\n\\end{align}\nand we see that\n\\begin{equation}\n f_b|f_a \\sim \\mathcal{N}\\left(f_a\\frac{\\sigma_{ab}^2}{\\sigma_{aa}^2}, \\sigma_{bb}^2 - \\frac{\\sigma_{ab}^4}{\\sigma_{aa}^2}\\right)\n\\end{equation}\nThus, we can write conditional distributions for \\textit{test points} ($f_b$) based on \\textit{observed points} ($f_a$).\n\nThe last assumption needed is the form of the covariance assumed. \nThis is typically done by some measure of the distance in the ordinate via a kernel.\nA common kernel is the \\textit{squared exponential}\n\\begin{equation}\n    \\sigma_{ij}^2 = \\sigma^2 \\mathrm{exp}\\left(\\frac{(x_i - x_j)^2}{2l^2}\\right)\n\\end{equation}\nand we can incorporate the presence of noise in our observed samples by adding an additional term so that\n\\begin{equation}\n    \\sigma_{ij}^2 = \\sigma^2 \\mathrm{exp}\\left(\\frac{(x_i - x_j)^2}{2l^2}\\right) + \\sigma_{n}^2\\delta_{ij}\n\\end{equation}\nWe note that this kernel introduces several \\textit{hyper-parameters} which must be chosen in some way; there are common techniques for selecing optimal hyper-parameters based on the observed data.\nThey represent\n\\begin{itemize}\n  \\item{$\\sigma^2$ \n    \\begin{itemize}\n      \\item{The typical size of the covariance between different values of the function. This is is also the variance of each individual value of the function.}\n    \\end{itemize}\n  }\n  \\item{$l^2$\n    \\begin{itemize}\n      \\item{The length scale over which correlations persist within the function. For $|x_i-x_j|\\gg l$, the function values are essentially uncorrelated.}\n    \\end{itemize}\n  }\n  \\item{$\\sigma_n^2$\n    \\begin{itemize}\n      \\item{They typical size of the noise in each observation. We assume the noise is uncorrelated between different observations but drawn from the same distribution for each observation, thus the kronecker-$\\delta$.}\n    \\end{itemize}\n  }\n\\end{itemize}\n\n\n\\end{document}\n", "meta": {"hexsha": "4967abbd994873c010ee55e17e2aa0e2233151d8", "size": 5644, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "etc/notes.tex", "max_stars_repo_name": "isaaclegred/universality", "max_stars_repo_head_hexsha": "9eac607a78b7cb67c1509ea68f4de631437f393a", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-02T13:41:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-02T13:41:46.000Z", "max_issues_repo_path": "etc/notes.tex", "max_issues_repo_name": "isaaclegred/universality", "max_issues_repo_head_hexsha": "9eac607a78b7cb67c1509ea68f4de631437f393a", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 25, "max_issues_repo_issues_event_min_datetime": "2018-01-31T15:14:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-10T21:32:05.000Z", "max_forks_repo_path": "etc/notes.tex", "max_forks_repo_name": "isaaclegred/universality", "max_forks_repo_head_hexsha": "9eac607a78b7cb67c1509ea68f4de631437f393a", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2018-12-07T04:04:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T19:00:17.000Z", "avg_line_length": 51.3090909091, "max_line_length": 383, "alphanum_fraction": 0.6750531538, "num_tokens": 2000, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240686758841, "lm_q2_score": 0.8740772253241803, "lm_q1q2_score": 0.7562726532319148}}
{"text": "\\subsection{DenseNet} \n\\begin{itemize}\n\t\\item Semi-iterative method for accelerating the residual correction iterative scheme,\n\t\\begin{equation}\\label{eq:multi}\n\tu^{i} = \\sum_{j=0}^{i-1}  \\alpha_{j}^i\\left( u^{j} + B^{i}_j(f - A(u^j)) \\right), \\quad i=1:\\nu,\n\t\\end{equation}\n\twhere $\\alpha_j^i \\ge 0$ and $\\sum_{j=0}^{i-1}  \\alpha_{j}^i = 1$.\n\tLetting the residual $r^j = f - A(u^{j})$ for $j=0:i$, \n\tthe following iterative scheme for $r^j$ is implied by \\eqref{eq:multi}\n\t\\begin{equation}\\label{eq:multi-res}\n\tr^{i} = \\sum_{j=0}^{i-1}\\alpha^i_j(I - AB^{i}_j)(r^j),\n\t\\end{equation}\n\tbecause of the linearity of $A$. This scheme is analogous to the \n\tDenseNet \\cite{huang2017densely} which will be discussed more in \\S~\\ref{sec:CNNs} and below.\n\tMore discussion on semi-iterative method for linear system \n\tcan be found in \\cite{hackbusch1994iterative, golub2012matrix}.\n\\end{itemize}\n\n\nThe DenseNet \\cite{huang2017densely} can be written as:\n\\begin{equation}\\label{eq:densenet}\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&f^{\\ell,i} = \\sigma \\circ \\theta^{\\ell,i} (\\tilde f^{\\ell,i-1}), \\quad i = 1:\\nu_\\ell ,\\\\\n&\\tilde f^{\\ell,i} = [f^{\\ell,0,}, \\cdots, f^{\\ell,i}] \\quad i = 1:\\nu_\\ell  , \\\\\n\\quad &\\text{\\bf EndFor} \\\\\nf^{\\ell+1,0} &=  R_\\ell^{\\ell+1} (\\tilde f^{\\ell, \\nu_\\ell} ) , \\\\\n\\text{\\bf End} &\\\\\nH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\\end{cases}\n\\end{equation}\nHere $[f^{\\ell,0,}, \\cdots, f^{\\ell,i}]$ means the collection of \nall the previous output in $\\ell$-th grids after $i$-th smoother.\n\nThe original setup in DenseNet is:\n\\begin{equation}\nf^{\\ell,0} \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times k_0}, \\quad f^{\\ell,i} \\in \\mathbb{R}^{n_\\ell \\times n_\\ell \\times k}, \\quad i = 1:\\nu_\\ell.\n\\end{equation}\nThus to say,\n\\begin{equation}\n\\theta^{\\ell,i} = [[\\theta^{\\ell,i}]_0, [\\theta^{\\ell,i}]_{1}, \\cdots, [\\theta^{\\ell,i}]_i]: \\mathbb{R}^{n_\\ell\\times n_\\ell \\times (k_0 + ck)} \\mapsto \\mathbb{R}^{n_\\ell\\times n_\\ell \\times k} .\n\\end{equation}\nThis means that,\n\\begin{equation}\n[\\theta^{\\ell,i}]_{0}:  \\mathbb{R}^{n_\\ell\\times n_\\ell \\times k_0 } \\mapsto \\mathbb{R}^{n_\\ell\\times n_\\ell \\times k}, \\quad [\\theta^{\\ell,i}]_{j}:  \\mathbb{R}^{n_\\ell\\times n_\\ell \\times k } \\mapsto \\mathbb{R}^{n_\\ell\\times n_\\ell \\times k}, \\quad j = 1:i.\n\\end{equation}\nAt last, we have \n\\begin{equation}\n\\theta^{\\ell,i}(\\tilde f^{\\ell,i}) = \\sum_{j=0}^i [\\theta^{\\ell,i}]_{j} [\\tilde f^{\\ell,i}]_j = \\sum_{j=0}^i [\\theta^{\\ell,i}]_{j} f^{\\ell,j}.\n\\end{equation}\nFinally, we have that \n\\begin{equation}\n[\\theta^{\\ell,i}]_{j},\n\\end{equation}\nplays the role of $A$ in MgNet?\n\nSo, we can rewrite the above DenseNet with the above formula without $\\tilde f$:\n\\begin{equation}\\label{eq:densenet1}\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&f^{\\ell,i} = \\sigma \\left( \\sum_{j=0}^{i-1} [\\theta^{\\ell,i}]_{j} f^{\\ell,j} \\right) ,\\\\\n\\quad &\\text{\\bf EndFor} \\\\\nf^{\\ell+1,0} &=  R_\\ell^{\\ell+1} ([f^{\\ell,0,}, \\cdots, f^{\\ell,\\nu_\\ell}] ) , \\\\\n\\text{\\bf End} &\\\\\nH_0(f) &=  R_{\\rm ave}(f^{L,\\nu_\\ell}). \\\\\n\\end{cases}\n\\end{equation}\nSo, similar idea in removing $i$ in $A^{\\ell,i}$ in MgNet, we can remove $j$ in $\\theta^{\\ell,i}$ or\neven remove $i$, this can reduce the number of parameters very efficient....\n\nWe can also adopt this idea into MgNet.\n\\begin{breakablealgorithm}\n\t\\caption{$u^{J}={\\rm Dense-MgNet}(f; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:dense-mgnet}\n\t\\begin{algorithmic}\n\t\t\\State Initialization:  $f^1 =\\theta(f)$, $u^{1,0} \\leftarrow 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{itemize}\n\t\t\t\\item Standard Chebyshev iteration:\n\t\t\t\\begin{equation}\\label{chebyshev-mgnet}\n\t\t\tu^{\\ell,i} \\leftarrow u^{\\ell,i-1} + B_{\\ell,i}  ({f^\\ell -  A^{\\ell} (u^{\\ell,i-1})}) + C_{\\ell}(u^{\\ell,i-1} - u^{\\ell,i-2}).\n\t\t\t\\end{equation}\n\t\t\t\\item Expanded version: \n\t\t\t\\begin{equation}\\label{expanded-mgnet}\n\t\t\tu^{\\ell,i} \\leftarrow \\sum_{j=0}^{i-1} \\mathcal F^{\\ell,i}(u^{\\ell,j}, f^\\ell),\n\t\t\t\\end{equation}\n\t\t\twhere $\\mathcal F^{\\ell,i}$ is defined by $A^\\ell, B_{\\ell,i}$ and $C_\\ell$ with some special forms.(Parameter sharing in some sense.)\n\t\t\t\\item Dense-MgNet:\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item Extended form:\n\t\t\t\t\\begin{equation}\\label{extendes-mgnet}\n\t\t\t\tu^{\\ell,i} \\leftarrow \\sum_{j=0}^{i-1} \\mathcal F^{\\ell,i}(u^{\\ell,j}, f^\\ell),\n\t\t\t\t\\end{equation}\n\t\t\t\twhere $\\mathcal F^{\\ell,i}$ is free to be trained with some special forms.(Removing parameter sharing...)\n\t\t\t\t\\item $\\tilde u^{\\ell,i}$ form:\n\t\t\t\t\\begin{equation}\\label{dense-mgnet}\n\t\t\t\tu^{\\ell,i} \\leftarrow \\mathcal D_{\\ell,i}([\\tilde u^{\\ell,i-1}, f^{\\ell}]).\n\t\t\t\t\\end{equation}\n\t\t\t\twhere \n\t\t\t\t\\begin{equation}\\label{eq:tilde-u}\n\t\t\t\tu^{\\ell,i-1} = [u^{\\ell,0}, \\cdots, u^{\\ell,i-1}],\n\t\t\t\t\\end{equation}\n\t\t\t\tand $\\mathcal D_{\\ell,i}$ needs to be trained with some special forms.\n\t\t\t\\end{itemize}\n\t\t\n\t\t\\end{itemize}\n\t\t\n\t\t\\EndFor\n\t\t\\State Note $u^\\ell = u^{\\ell,\\nu_\\ell}$\n\t\t\\begin{equation}\n\t\t\\label{d-interpolation}\n\t\tu^{\\ell+1,0} \\leftarrow \\Pi_\\ell^{\\ell+1}u^{\\ell}\n\t\t\\end{equation}\n\t\t\\begin{equation}\n\t\t\\label{d-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\n%What's more, the above ideas consider about the DenseNet structures (Chebyshev iteration)\n%into the grids level for MgNet.\n\n\n", "meta": {"hexsha": "e28dba304afdef63984276ebc39bbac5dddcaae6", "size": 5539, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/mgnet_densenet.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_densenet.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_densenet.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.6466165414, "max_line_length": 258, "alphanum_fraction": 0.6181621231, "num_tokens": 2270, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.831143054132195, "lm_q1q2_score": 0.7562628920358471}}
{"text": "\\section{The Knapsack Problem}\n\n%%%%%%%%%%\n\\begin{frame}{The knapsack problem}\n  \\begin{exampleblock}{The change-making problem \\pno{2.2.17 (b), 2.2.4 (subset sum)}}\n    \\begin{itemize}\n      \\item coins values: $x_{1} \\dots x_{n}$\n      \\item amount: $v$\n      \\item possible to make change for $v$?\n      \\item without repetition\n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\pause\n  \\begin{alertblock}{Trial and error.}\n    \\begin{itemize}\n      \\item subproblem $C[i]$: is it possible to make change for $v$ using only $x_{1} \\cdots x_{n}$\n      \\item goal: $C[n]$\n      \\item question: using $x_{i}$ or not?\n      \\item recurrence:\n\t\\[\n\t  C[i] = C[i-1] \\lor \\textcolor{red}{???}\n\t\\]\n    \\end{itemize}\n  \\end{alertblock}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{The knapsack problem}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $C[i, w]$: is it possible to make change for $w$ using only $x_{1} \\dots x_{n}$\n      \\item goal: $C[n,v]$\n      \\item question: using $x_{i}$ or not?\n      \\item recurrence:\n\t\\[\n\t  C[i,w] = C[i-1, w] \\lor (C[i-1, w-x_{i}] \\textcolor{blue}{\\land w \\ge x_{i}})\n\t\\]\n      \\item<2-> initialization:\n\t\\begin{align*}\n\t  C[i,0] &= \\text{true}  \\\\\n\t  C[0,w] &= \\text{false}, \\text{if } w > 0 \\\\\n\t  C[0,0] &= \\text{true}\n\t\\end{align*}\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{The knapsack problem}\n  \\begin{exampleblock}{The change-making problem \\pno{2.2.17 (a)}}\n    \\begin{itemize}\n      \\item coins values: $x_{1} \\dots x_{n}$\n      \\item amount: $v$\n      \\item possible to make change for $v$?\n      \\item unbounded repetition\n    \\end{itemize}\n  \\end{exampleblock}\n  \n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $C[i, w]$: is it possible to make change for $w$ using only $x_{1} \\dots x_{n}$\n      \\item goal: $C[n,v]$\n      \\item question: using $x_{i}$ or not?\n      \\item recurrence:\n\t\\[\n\t  C[i,w] = C[i-1, w] \\lor (C[\\textcolor{red}{i}, w-x_{i}] \\land w \\ge x_{i})\n\t\\]\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{The knapsack problem}\n  \\begin{exampleblock}{The change-making problem \\pno{2.2.17 (c)}}\n    \\begin{itemize}\n      \\item coins values: $x_{1} \\dots x_{n}$\n      \\item amount: $v$\n      \\item possible to make change for $v$?\n      \\item $\\le k$-coins \n    \\end{itemize}\n  \\end{exampleblock}\n\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item subproblem $C[i,w,l]$: is it possible to make change for $w$ with $\\le l$ coins of $x_{1} \\dots x_{i}$\n      \\item goal: $C[n,v,k]$\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n\\begin{frame}{The knapsack problem}\n  \\begin{block}{Solution.}\n    \\begin{itemize}\n      \\item question: using $x_{i}$ or not?\n      \\item recurrence: \n\t\\[\n\t  C[i,w,l] = C[i-1,w,l] \\lor \\left( C[i,w-x_{i},l-1] \\land w \\ge x_{i} \\right)\n\t\\]\n      \\item<2-> initialization:\n\t\\begin{align*}\n\t  C[0,0,l] &= \\text{true} \\\\\n\t  C[0,w,l] &= \\text{false}, \\text{if } w > 0 \\\\\n\t  C[i,0,l] &= \\text{true} \\\\\n\t  C[i,w,0] &= \\text{false}, \\text{if } w > 0\n\t\\end{align*}\n    \\end{itemize}\n  \\end{block}\n\\end{frame}\n%%%%%%%%%%\n", "meta": {"hexsha": "78940c6e993f65f9cf680b0f62ec9953604c3cd2", "size": 3095, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "alg-ta-by-years/alg-ta-2016/algorithm-tutorial-dp-2016-06-16/sections/knapsack-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/knapsack-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/knapsack-dp.tex", "max_forks_repo_name": "courses-at-nju-by-hfwei/algorithm-ta-tutorial", "max_forks_repo_head_hexsha": "0bb0376d96f388671597903fc833f68d7946020e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2017-10-10T08:47:12.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-18T07:58:43.000Z", "avg_line_length": 28.6574074074, "max_line_length": 114, "alphanum_fraction": 0.5680129241, "num_tokens": 1140, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070133672954, "lm_q2_score": 0.8311430436757313, "lm_q1q2_score": 0.7562628845519882}}
{"text": "\\chapter{Heap}\n\n\\section{Introduction}\nHeap-ordered. Binary heap is one of the implementations of Priority Queue (ADT). The core relationship of elements in the heap:\n$A_{2i} \\leq A_{i} \\geq A_{2i+1}$.\n\n\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[height=1.3in]{heap}}\n\\caption{Heap}\n\\label{fig:heap}\n\\end{figure}\n\\section{Operations}\nAssume the root \\textbf{starts} at $a[1]$ rather than $a[0]$.\n\\\\\nBasic operations:\n\\begin{enumerate}\n\\item sink()/ sift\\_down() - recursive\n\\item swim()/ sift\\_up() - recursive\n\\item build()/ heapify() - bottom-up sink()\n\\end{enumerate}\n\\subsection{Sink (sift\\_down)}\nCore clue: compare parent to the \\textit{larger} child. \n\\begin{python}\ndef sink(self, idx):\n    while 2*idx <= self.N:\n        c = 2*idx\n        if c+1 <= self.N and self.less(c, c+1):\n            c += 1\n        if not self.less(idx, c):\n            return \n\n        self.swap(idx, c)\n        idx = c\n\\end{python}\n\n\\subsection{Swim (sift\\_up)}\nCore clue: compare child to its parent. \n\\begin{python}\ndef swim(self, idx):\n    while idx > 1 and self.less(idx/2, idx):\n        pi = idx/2\n        self.swap(pi, idx)\n        idx = pi\n\\end{python}\n\\subsection{Heapify}\nCore clue: bottom-up sink().\n\\begin{python}\ndef heapify(self):\n    for i in xrange(self.N/2, 0, -1):\n        self.sink(i);\n\\end{python}\n\\runinhead{Complexity.} Heapifying \\textbf{a sorted array} is the worst case for heap construction, because the root of each subheap considered sinks all the way to the bottom. The worst case complexity $\\sim 2N$. \n\nBuilding a heap is $O(N)$ rather than $O(N \\lg N)$. Intuitively, the deeper the level, the more the nodes, but the less the level to sink down. \n\nAt most $\\big\\lceil\\frac{n}{2^{h+1}}\\big\\rceil$ nodes of any height $h$.\n\nProof:\n\\begin{align*}\n\\because \\sum_{i=0}^{+\\infty} {ix^i} =\\frac{x}{(1-x)^2} \\\\\n\\therefore \\sum_{h=0}^{\\lfloor\\lg n\\rfloor}{\\Big\\lceil\\frac{n}{2^{h+1}}\\Big\\rceil\nO(h)} &= O\\Bigg(n\\sum_{h=0}^{\\lfloor\\lg n\\rfloor}{\\frac{h}{2^h}}\\Bigg) \\\\\n&= O(n)\n\\end{align*}\n\n\\section{Implementation}\n\\subsection{General}\nThe self-implemented binary heap's index usually starts at 1 rather than 0. \n\nThe array representation of heap is in \\textbf{level-order}.\n\nThe main reason that we can use an array to represent the heap-ordered tree in a binary heap is because the tree is \\textbf{complete}.\n\nSuppose that we represent a BST containing N keys using an array, with $a[0]$ empty, the root at $a[1]$. The two children of $a[k]$ will be at $a[2k]$ and $a[2k+1]$. Then, the length of the array might need to be as large as $2^N$.\n\nIt is possible to have 3-heap. A 3-heap is an array representation (using 1-based indexing) of a complete 3-way tree.\nThe children of $a[k]$ are $a[3k-1]$, $a[3k]$, and $a[3k+1]$.\n\\begin{figure}[hbtp]\n\\centering\n\\subfloat{\\includegraphics[scale=.90]{heapRepr}}\n\\caption{Heap representation}\n\\label{fig:heap} \n\\end{figure}\n\n\\subsection{Python Heapq}\nPython only has built in min-heap. To use max-heap, you can: \n\\begin{enumerate}\n\\item Invert the number: 1 becomes -1.\n(usually the best solution)\\item Wrap the data into another class and override \\textbf{comparators}: \\_\\_cmp\\_\\_ or \\_\\_lt\\_\\_\n\\end{enumerate}\n\nThe following code presents the wrapping method:\n\\begin{python}\nclass HeapValue(object):\n    def __init__(self, val):\n        self.val = val\n        self.deleted = False  # lazy delete \n\n    def __cmp__(self, other):\n        # Reverse order by height to get max-heap\n        assert isinstance(other, Value)\n        return other.val - self.val\n\\end{python}\n\nNormally the deletion by value in Python is $O(n)$, to achieve $O(\\lg n)$ we can use \\textbf{lazy deletion}. Before take the top of the heap, we do the following:\n\\begin{python}\nwhile heap and heap[0].deleted:\n    heapq.heappop(heap)\n\\end{python}\n\\subsection{Java Priority Queue}\n\\begin{java}\n// min-heap\nPriorityQueue<Integer> pq = new PriorityQueue<>(\n    (o1, o2) -> o1-o2\n);\n\n// max-heap\nPriorityQueue<Integer> pq = new PriorityQueue<>(\n    (o1, o2) -> o2-o1\n);\n\\end{java}\n\n\\section{Derivatives}\n\\subsection{Heap of Linked Lists}\nMaintain a heap of linked lists, pop the min head, and push the head's next back to the heap. \n\n", "meta": {"hexsha": "8a5aff14b5cd18c49638eefeb5b8f96616532c3b", "size": 4167, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterHeap.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": "chapterHeap.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": "chapterHeap.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": 32.3023255814, "max_line_length": 231, "alphanum_fraction": 0.6815454764, "num_tokens": 1297, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677468516188, "lm_q2_score": 0.8918110346549901, "lm_q1q2_score": 0.7562269936738029}}
{"text": "%%%%%%%%%%%%%%%%%%%%%%%%%%%\n% Conditional Expectation %\n%%%%%%%%%%%%%%%%%%%%%%%%%%% \n\n\\section{Conditional Expectation}\n\n\\begin{exercise}{8.1}{}\n\n    Let $\\CalG \\coloneqq \\{\\emptyset, \\Omega\\}$, i.e. the trivial \\SigmaAlgebra. Then if random variable $Y$ is $\\CalG$-measurable, then $Y$ is constant.\n\n\\end{exercise}\n\n\\begin{lemma}{8.2}{}\n\n    Let $Z$ be a $\\CalG$-measurable random variable such that:\n\n        \\begin{align*}\n            \\int_{A} Z \\, dP \\geq 0 \\iff E(\\Indicator{A}Z) \\geq 0,\n        \\end{align*}\n\n    for any $A \\in \\CalG$, then $Z \\geq 0$ (a.s.).\n\n\\end{lemma}\n\n\\begin{theorem}{8.6}{Properties of Conditional Expectations}\n\n    Let $X$ be a random variable and $\\CalG \\subset \\CalF$ be a \\SigmaAlgebra. Then the following properties hold (under the given conditions):\n\n        \\begin{enumerate}[(i)]\n            \\setlength{\\parskip}{0em}\n            \\item ``Adding/Dropping Conditional Expectation'':\n\n                \\begin{align*}\n                    EX = E(E(X|\\CalG));\n                \\end{align*}\n            \\item ``Tower Rule'': Let $\\mathcal{H} \\subset \\CalF$ be a \\SigmaAlgebra, such that $\\mathcal{H}$ \\emph{contains} $\\CalG$, then:\n\n                \\begin{align*}\n                    E(E(X|\\mathcal{H})|\\CalG) = E(X|\\CalG);\n                \\end{align*}\n            \\item ``Pulling/Pushing Random Variables Through'': Let $Y$ be a random variable, such that $Y$ is $\\CalG$-measurable \\emph{and} $E|XY| < \\infty$, then:\n\n                \\begin{align*}\n                    E(XY|\\CalG) = YE(X|\\CalG);\n                \\end{align*}\n            \\item ``Independence of Conditional'': Let $X$ and $\\CalG$ be independent, i.e. $\\sigma(X)$ and $\\CalG$ are independent, then:\n\n                \\begin{align*}\n                    E(X|\\CalG) = EX.\n                \\end{align*}\n        \\end{enumerate}\n\n\\end{theorem}\n", "meta": {"hexsha": "8e3d06ce6d5d238757801045174089ad63fb720d", "size": 1831, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/conditional-expectation.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/conditional-expectation.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/conditional-expectation.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.9074074074, "max_line_length": 164, "alphanum_fraction": 0.5286728564, "num_tokens": 538, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7562054521097432}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Main maths packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\\usepackage{mathtools}\n\n\\begin{document}\n\n\\section*{Boxed equation}\n\n\\begin{alignat*}{2}\n\t&& \\sqrt{4 x^2} - 1 &= 0 \\\\\n\t&\\Rightarrow & \\sqrt{4} \\sqrt{x^2} &= 1 \\\\\n\t&\\Rightarrow & 2 \\left|x\\right| &= 1 \\\\\n\t&\\Rightarrow & x &= \\pm \\frac{1}{2}\n\\end{alignat*}\n\nThe final result is\n\n\\begin{equation}\n\t\\boxed{x = \\pm \\frac{1}{2}}\n\\end{equation}\n\n\\end{document}", "meta": {"hexsha": "fd687d21e138af1edac12a2e917330213b79ace6", "size": 518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/boxed-equations.tex", "max_stars_repo_name": "ZenLulz/LatexCompendium", "max_stars_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-30T21:43:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T20:16:19.000Z", "max_issues_repo_path": "compendium/mathematics/boxed-equations.tex", "max_issues_repo_name": "ZenLulz/LatexCompendium", "max_issues_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compendium/mathematics/boxed-equations.tex", "max_forks_repo_name": "ZenLulz/LatexCompendium", "max_forks_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 17.8620689655, "max_line_length": 43, "alphanum_fraction": 0.6602316602, "num_tokens": 197, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.756205444886015}}
{"text": "\\section{$\\mathbf{X} = \\mathbf{U\\Sigma V^T}$ Eigenanalysis, Singular Value Decomposition (SVD)}\n\\label{sec:datasvd}\n\nSingular Value Decomposition (SVD) is a matrix decomposition of the form $\\mathbf{A}=\\mathbf{U}\\Sigma\\mathbf{V}^T$, where $\\mathbf{U}$ and $\\mathbf{V}$ are both unitary (cf. section \\ref{sec:svd}). The decomposition always exists for a general complex matrix $\\mathbf{A}\\in\\mathbb{C}^{m\\times n}$. \n\\\\\n\nIf $\\mathbf{X}\\in\\mathbb{R}^{N\\times p}$ is a data matrix with $N$ samples in the rows and $p$ features in the columns, then SVD allows for the decomposition of the data into $p$ linearly independent components, ranked by their explained variance (i.e. their strength in the dataset). The basis of the decomposition turns out to be the same as for PCA (cf. section \\ref{sec:pca}) except that it is arrived at slightly differently, because PCA involves diagonalizing the covariance matrix., nor are the singular values the same as the explained variances of the dataset. The decomposition of the dataset can be understood as follows. In the SVD of the data matrix: \n\n\\begin{equation}\n\\mathbf{X} = \\mathbf{U}\\mathbf{\\Sigma}\\mathbf{V}^T\n\\end{equation}\n\nThe individual rows of $\\mathbf{X}$, i.e. the individual data points, are expressed as:\n\n\\begin{equation}\n\\mathbf{x}^T_i = \\sum_{j=1}^p u_{i,j}\\sigma_j\\mathbf{v}_j^T\n\\end{equation}\n\nWhere $\\mathbf{x}_i$ is the $i$th data point. Hence the right singular vectors $\\mathbf{v}_i$ are the normalized basis vectors, and the columns of $\\mathbf{U}$ give the coefficients the basis expansion, together with the singular values $\\sigma_i$, which give a measure of the global strength of the corresponding basis vector. \n\nTruncating the expansion after the $r$th term results in a rank $r$ approximation of $\\mathbf{X}$ known as the \\textit{truncated singular value decomposition} (TSVD) estimator. According to the Eckart-Young Mirsky-Theorem, the estimator is the best rank-$r$ approximation under the Frobenius norm of the error (cf. \\ref{sec:frobenius}), which is the average mean square error across $\\mathbf{X}$. \n\n\\begin{equation}\n\\mathbf{\\hat{X}} = \\sum_{i=1}^r \\sigma_i (\\mathbf{u}_i \\otimes \\mathbf{v}_i)\n\\end{equation}\n\nSince it minimizes the average mean square error, $\\mathbf{\\hat{X}}$ is the rank $r$ maximum likelihood approximation to $\\mathbf{X}$ under the assumption of normally distributed noise. Optimal truncation is discussed in section \\ref{sec:truncation}.\n\nSVD is scalable to very large datasets and finds many applications in the wild, including page rank, facial recognition, recommendation algorithms, and others. Randomized SVD (cf. section \\ref{sec:rsvd}) is an approximate method that gives an even faster speedup.\n\n\n% eigenfaces\n\\subsection{Example: Eigenfaces and Facial Recognition}\nOne famous result are the so-called eigenfaces. The data matrix $\\mathbf{X}\\in\\mathbb{R}^{N\\times p}$ consists of $N$ pictures of faces that each have $p$ pixels. The right singular eigenvectors yield $p$ eigenfaces in terms of which any of the $N$ pictures can be expressed. \n\nBelow are the first eigenfaces extracted from the \"Labeled Faces in the Wild\" dataset, which includes 13233 portraits with 62x47=2914 pixels each. Running SVD on the data matrix $\\mathbf{X} \\in \\mathbb{R}^{13233\\times 2914}$ yields the eigenfaces shown in Figure \\ref{fig:svd_eigenfaces}.\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{svd_eigenfaces.png}\n    \\caption{Left: The first 48 eigenfaces. The colorscale is consistent across the images. As can be expected, the eigenfaces seem to have an ordering from more general features, that are highly prevalent in the dataset, towards more specific features. Right: Five sample portraits from the dataset approximated using different numbers of eigenvectors. 2914 corresponds to the original image, which had 2914 pixels (degrees of freedom).}\n    \\label{fig:svd_eigenfaces}\n\\end{figure}\n\nFacial recognition may be performed by projecting a new face into the space of eigenfaces and matching to the coefficients of a known subject. This could be done using the euclidean distance, or it could be done using a classifier. In case of classificiation, the dimensionality reduction that is enabled by approximating images with a smaller set of eigenvectors may be critical to making the problem tractable by overcoming the curse of dimensionality. When the data matrix is not centered (that is, the mean is not subtracted from it before performing the SVD), then the first right singular vector is vector close to the average row in the matrix.\n\n\n% eigenbasis \n\\subsection{Tracking an Eigensystem over Time}\n\\label{sec:svd_tracking}\n\t\nAs discussed in section \\ref{sec:svd}, the sign of the basis vectors can be flipped without affecting the validity of the singular value decomposition. That means that if the SVD is performed on some system may equally well return, say, a left-handed or a right-handed coordinate system. This becomes a problem when the results of repeated SVDs are supposed to be compared, for example to study the evolution of a system over time. Figure \\ref{fig:svd_consistently_oriented} shows the eigenbasis of a bivariate Gaussian with principal axes slowly rotating over a 180-degree angle. The top shows how the eigenbases that is found flips back and forth, so that there is a double-trajectory corresponding to results with positive and negative sign on an eigenvector. The trajectory is not described by an injective function, which complicates analysis. \n\n\n\\subsubsection{Heuristic Method}\nSay an SVD is performed on a slowly-evolving system at time $t=0$ and at time $t=1$. To compensate the sign flips, a heuristic method is to first match the basis vectors at $t=0$ to the basis vectors at $t=1$ using a distance metric that is immune to the sign of the vectors, for example the absolute value of the dot product. (This assumes that the vectors are similar enough at time $t=0$ and $t=1$ that the matching an be done unambiguously. For the higher-order singular vectors this might be a problem, because they have lower numerical certainty.) Once the vectors are matched, the sign of the inner product between the vectors at $t=0$ and $t=1$ may be compared, and the sign flipped accordingly. \n\nThis method works, but the problem is that the sign of the vectors is somewhat arbitrarily pinned relative to the result at $t=0$. That is, if, for example, the coordinate system found at $t=0$ was left-handed, then the time series of eigenbases will be adjusted to be left-handed. If the point of comparison had instead been the SVD performed at some other time $t=t'$, then one might have wound up with a right-handed coordinate system instead. It is desirable to find a consistent orientation.   \n\n\n\\subsubsection{Consistent Method}\n\n\\citeasnoun{damask2019consistently} recently developed a method that can be used to find a consistently oriented basis. Consistent orientation in this case means, roughly, that the eigenbasis is always flipped to obey the convention of being right-handed. The method relies on reconstructing the rotations and reflections necessary to transform the eigenbasis in question to the natural basis $\\mathbf{I}$ as reference. While rotations preserve the orientation of a basis, but reflections do not. When the reflections of an eigenbasis with respect to the natural basis are known, then they can be undone by flipping them back in place. \n\n\n\\begin{figure}\n\\centering\n    \\includegraphics[width=\\textwidth]{svd_consistently_oriented.png}\n    \\caption{Right singular vectors extracted using SVD, showing sign flips (top) and with a consistently oriented basis (bottom). The underlying data is a bivariate gaussian with principal axes undergoing a 180 degree rotation. With the consistently oriented basis, the singular vectors trace out a one-to-one trajectory that can be analyzed.}\n    \\label{fig:svd_consistently_oriented}\n\\end{figure}\n\n\n\\subsubsection{Rank Order Changes}\n\t\nThe singular vectors or eigenvectors of a system are labeled only in terms of their associated singular values or eigenvalues. In order to track a singular vector throughout rank order changes, it is necessary to figure out a way to attach a separate label, for example by looking at the \"content\" of a particular singular vector. How well that works has to be figured out in context, I am not currently aware of a generally valid solution. \n\n\n% Bayesian SVD\n\\subsection{Bayesian SVD}\nTo do! Cf. https://ieeexplore.ieee.org/document/7336426\n\nIt's awful to be tied to the assumption of normality and it's awful to not know the uncertainty of my singular vectors!\n\n\n\n\n\n\n", "meta": {"hexsha": "7329b12e789515ad0212a224d1c870b8188a8f76", "size": 8627, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/unsup_svd.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_svd.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_svd.tex", "max_forks_repo_name": "jpbm/probabilism", "max_forks_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 95.8555555556, "max_line_length": 849, "alphanum_fraction": 0.7827750087, "num_tokens": 2100, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391624034103, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.7561471572255611}}
{"text": "%!TEX root = /Volumes/HD_2/Rudin/Rudin_DM.tex\n\\textit{\nPut $K=[-1,1]$; define $\\D_{K}$ as in section 1.46 \n(with $\\R$ in place of $\\R^{n}$). \nSupose $\\{f_{n}\\}$ is a sequence of Lebesgue integrable functions such that \n%\n  $\\Lambda\\phi \n    = \n  \\underset{n \\to \\infty}{\\lim} \\int_{\\minus 1}^1 f_{n}(t)\\phi(t)dt$\n%\nexists for every $\\phi\\in\\D_{K}$. \nShow that $\\Lambda$ is a continuous linear functional on $\\D_{K}$. \nShow that there is a positive integer $p$ and a number $M<\\infty$ such that \n  \\begin{align}\n    \\left\\lvert \n      \\int_{\\minus 1}^1 f_n (t)\\phi (t) dt\\\n    \\right\\rvert\n    \\leq \n    M \\norm{\\infty}{D^{p}} \n  \\nonumber\n  \\end{align}\nfor all $n$.\nFor example, if $f_{n}(t)=n^{3}t$ on $[\\minus 1/n, 1/n]$ and $0$ elsewhere, \nshow that this can be done with $p=1$. \nConstruct an example where it can be done with $p=2$ but not with $p=1$.}\n%\n%\n\\renewcommand{\\labelenumi}{(\\roman{enumi})}%\n%\n\\newline\\newline\\noindent\nWe will also consider the case $p=0$. Since all supports of %\n%\n  $\\phi, \\phi', \\phi'', \\dots, $ are in $K$, %\n%\nwe make a specialization of the mean value theorem: %\n%\n\\paragraph{Lemma}\\label{2.3 Lemma}\n\\input{\\ROOT/chapter_2/2_03/2_03_0_lemma.tex}\n%: PROOF OF THE STATEMENT ----------------------------------------------------%\n%/ FIRST PART ----------------------------------------------------------------%\n%\n\\begin{proof}\n\\input{\\ROOT/chapter_2/2_03/2_03_1_radon_measures.tex}\n% SECOND PART -----------------------------------------------------------------\n\\input{\\ROOT/chapter_2/2_03/2_03_2_uniform_bound.tex}\n\\input{\\ROOT/chapter_2/2_03/2_03_3_example_1.tex}\n\\input{\\ROOT/chapter_2/2_03/2_03_4_example_2.tex}\n\\end{proof}\n%\\renewcommand{\\labelenumi}{\\alph{enumi}.}%\n\\renewcommand{\\labelenumi}{$(\\textit{\\alph{enumi}})$}%", "meta": {"hexsha": "03e753950d5cd08596b6a978f0f328b410da9d0c", "size": 1759, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter_2/2_03/2_03.tex", "max_stars_repo_name": "gitcordier/FunctionalAnalysis", "max_stars_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chapter_2/2_03/2_03.tex", "max_issues_repo_name": "gitcordier/FunctionalAnalysis", "max_issues_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "chapter_2/2_03/2_03.tex", "max_forks_repo_name": "gitcordier/FunctionalAnalysis", "max_forks_repo_head_hexsha": "4d54af9cab1ce2bf512341cc1f2a0c81d7097754", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 35.18, "max_line_length": 79, "alphanum_fraction": 0.5952245594, "num_tokens": 604, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916240341031, "lm_q2_score": 0.8757869786798664, "lm_q1q2_score": 0.7561471418303303}}
{"text": "\\section{Theory}\n\\label{sec:theory}\n\nThe aim of the MinOver algorithm is to find the perceptron of maximum stability, i.e. to maximize the margin between the weight vector $\\bm{\\mathsf{w}}$ and the closest input example $\\xi^\\mu$. Formally, the stability $\\kappa^\\mu$ is defined in \\cref{eq:perceptron-stability}:\n\n\\begin{equation}\n    \\kappa^\\mu = \\frac{\\mathsf{\\bm{w}} \\cdotp \\xi^\\mu S^\\mu_R}{\\lvert \\mathsf{\\bm{w}} \\rvert}\n    \\label{eq:perceptron-stability}\n\\end{equation}\n\nDuring the training phase, the MinOver algorithm looks for the input vector with the lowest stability at the current time $t$ (\\cref{eq:minimum_lookup}) and performs a Hebbian update using its value (\\cref{eq:hebbian_update}):\n\n\\begin{equation}\n    \\kappa^{\\mu(t)} = \\min_\\nu \\left \\{ \\kappa^{\\nu(t)} =  \\frac{\\mathsf{\\bm{w}}(t) \\cdotp \\xi^\\nu S^\\nu_R}{\\lvert \\mathsf{\\bm{w}}(t) \\rvert} \\right \\}\n    \\label{eq:minimum_lookup}\n\\end{equation}\n\n\\begin{equation}\n    \\mathsf{\\bm{w}}(t+1) = \\mathsf{\\bm{w}}(t) + \\frac{1}{N} \\xi^{\\mu(t)} S^{\\mu(t)}_R\n    \\label{eq:hebbian_update}\n\\end{equation}\n\nThe procedure is repeated for a certain number of epochs $n_{max}$ or until convergence, i.e. when $\\mathsf{\\bm{w}}(t+1) = \\mathsf{\\bm{w}}(t)$.\n\nLike in the Rosenblatt perceptron, the output $S^\\mu \\in \\{+1, -1\\}$ for a given examples is computed by evaluating the sign of the dot product between the example $\\xi^\\mu$ and the weights vector $\\mathsf{\\bm{w}}$, as shown in \\cref{eq:labels_definition}:\n\n\\begin{equation}\n    S^\\mu = sign(\\mathsf{w} \\cdotp \\xi^\\mu)\n    \\label{eq:labels_definition}\n\\end{equation}\n", "meta": {"hexsha": "59422f28924c5fc3e1dd6ba0c8cd24a71235805b", "size": 1582, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_2/report/02_theory.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_2/report/02_theory.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_2/report/02_theory.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": 51.0322580645, "max_line_length": 276, "alphanum_fraction": 0.6839443742, "num_tokens": 543, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425377849806, "lm_q2_score": 0.8221891370573388, "lm_q1q2_score": 0.7561201045426542}}
{"text": "\\lab{Algorithm}{The Knapsack Problem}{The Knapsack Problem}\n\\label{lab:Knapsack}\n\n\\objective{This section teaches about NP-hard problems, particularly the knapsack problem.}\n\n\\section*{The Knapsack Problem}\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{Knapsack.png}\n\\caption{Visualization of the Knapsack problem TODO: Make a picture similar to this}\n\\end{figure}\n\nYou are given a knapsack that can only hold a certain weight.\nYou have a plethora of items that have value and weight.\nYou want to find the combination of items that have the most value with out exceeding the weight.\nThis is the 2 dimensional knapsack problem.\nWill focus on the 0/1 knapsack problem, which states that each item must be put in entirely or not at all.\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 decision making in a wide variety of fields.\nTwo examples are finding the least wasteful way to cut raw materials and the selection of capital investments in financial portfolios.\nThis problem often appears in problems involving resource allocation and financial constraints.\n\n\\begin{problem}\nWrite a function that solves the Knapsack problem by testing all possible combinations of items and choosing the combination with the most value that meets the weight constraint.\nOnly test it up to 15 objects.\n\\end{problem}\n\nThis way finds the optimal solution, but there is a problem.\nGiven $n$ objects the number of combinations is $2^n$.\nThe complexity of the problem grows very quickly.\nFor example: if you had 50 items, it would take more than 10 years to compute the optimal solution.\nFor all the following timing problems let your items have values between 1 and 100 and 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$.\nPlot the times.\nWhat is the complexity of the algorithm for increasing the number of items?\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{naiveTime.pdf}\n\\caption{\nYour graph should look similar to this.\nAs you can see as the number of items increases time increases exponentially}\n\\end{figure}\n\\end{problem}\n\n\\begin{problem}\nTime that algorithm for the carrying capacities $10,000-90,000$ every multiple of $10,000$ with $15$ items.\nPlot the times.\nWhat is the complexity of the algorithm for increasing the weight?\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{naiveWeight.pdf}\n\\caption{\nYour graph should look like this.\nThe weight of the items has essentially no effect on the time.}\n\\end{figure}\n\\end{problem}\n\n\\section*{NP-Hard}\n\nAny problem that is not polynomial time is known as NP-hard.\nThe Knapsack Problem is an NP-hard problem since it is $\\mathcal{O}\\left(2^n\\right)$ where $n$ is the number of items that are available.\nUsing the branch and bound approach we can find the optimal solution in psuedo-polynomial time.\n\n\\section*{Branch and Bound method}\n\nWe calculate the optimal solution using only the first $i$ items for weights 0 through W (where W is the maximum weight the knapsack can hold).\n\n(ALGORITHM DESCRIPTION NEEDS REVISION)\nWe do this by initializing the 0th row to be empty.\nFor the $i$'th row (where $i>0$) we go through $j$ from 1 through W.\nIf the ith element's weight is more than j then the optimal combination is the same as it was for i-1.\nIf ith element's weight is less than j, then we compare the combination at i-1 at weight j to the combination i-1 at the weight j-the ith element weight plus the ith element.\nWhichever one has a higher value is the optimal combination using the first ith elements less than or equal to the weight of j.\nYou continue this until you have done all n elements.\nThe 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.\nThis 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$.\nPlot the times.\nWhat is the complexity of the algorithm with respect to the number of items?\nFor the items, use the specifications given for the previous timing problems.\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{dynamicTime.pdf}\n\\caption{\nYour graph should look similar to this.\nAs the number of items increases time increases linearly}\n\\end{figure}\n\\end{problem}\n\n\\begin{problem}\nTime the branch and bound algorithm for the carrying capacities $10,000-90,000$ every multiple of $10,000$ with $15$ items.\nPlot the times.\nWhat is the complexity of the algorithm with respect to weight?\n\n\\begin{figure}[H]\n\\includegraphics[width=\\textwidth]{dynamicWeight.pdf}\n\\caption{\nYour graph should look similar to this.\nAs the weight of items increases time increases linearly}\n\\end{figure}\n\\end{problem}", "meta": {"hexsha": "62946a85121befe9407aa9c02d37bf2728383f53", "size": 5027, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Knapsack/Knapsack.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/Knapsack/Knapsack.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/Knapsack/Knapsack.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 44.4867256637, "max_line_length": 178, "alphanum_fraction": 0.7853590611, "num_tokens": 1182, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245994514084, "lm_q2_score": 0.9073122182277757, "lm_q1q2_score": 0.75608559083203}}
{"text": "\\title{Degrees of Freedom}\n\\author{\n        Daniel Johnson \\\\\n                Division of Applied Mathematics\\\\\n        Brown University\n}\n\\date{\\today}\n\n\\documentclass[12pt]{article}\n\n\\usepackage{graphicx,amsfonts,amsbsy,bbm, amsmath}\n\n\\begin{document}\n\\maketitle\n%\\tableofcontents\n\n%\\begin{abstract}\n%\\end{abstract}\n\n\\section{Computing the Degrees of Freedom of a 3D Linkage}\n\nWe consider the linkage of rigid 2-dimensional polygons in $\\mathbb{R}^3$ by means of ideal hinges located at the edges of the polygons. In this way, by treating intermediates of our various models as such a linkage, we can compute the non-trivial degrees of freedom (DoF) each intermediate has. Every linkage of this type has 6 trivial degrees of freedom: 3 corresponding to translational movement and 3 corresponding to rotational freedom. While these freedoms do change the orientation of the intermediate, they do not cause the faces to move relative to each other. For this reason, we label them as trivial degrees of freedom and focus on the calculation the remaining, non-trivial degrees of freedom. Since the concept of degrees of freedom exists in many diverse scientific fields, such as mechanical engineering and statistical physics, many different formal definitions of DoF are used in the literature. McCarthy defines degrees of freedom of a mechanical system as follows. \n\\begin{quote}\nWe derive formulas for the number of parameters needed to specify the configuration of a mechanism, in terms of the number of links and joints and the freedom of movement allowed at each joint. This number is the \\textit{degrees of freedom} or \\textit{mobility} of the mechanism. Changing the values of these parameters changes the configuration of the mechanism. Thus, if we view the set of all configuration available to a mechanism as a manifold, then the mobility of the mechanism is the dimension of this manifold. \n\\end{quote}\nFor our purposes, we define the \\textbf{degrees of freedom} of a configuration to be the difference between the number of parameters needed to specify a configuration in an ambient parameter space $\\Omega$ and the number of independent constraints imposed upon the configuration as a function of these parameters. Consequently, the non-trivial degrees of freedom is the number of degrees of freedom minus the six trivial degrees of freedom. If the ambiant parameter space is $\\mathbb{R}^N$ and there are $M$ constraint equations given by $\\varphi : \\mathbb{R}^N \\to \\mathbb{R}^M$, we find the degrees of freedom to be $N - \\operatorname{rank}(\\varphi)$ and the non-trivial degrees of freedom to be $N - \\operatorname{rank}(\\varphi) - 6$. Here we need $\\varphi$ to be a smooth map so that the rank is well defined. Furthermore, we define the \\textbf{configuration space} to be the subset of parameter space $\\{\\omega \\in \\Omega : \\varphi(\\omega) = 0\\}$ upon which the contraints are satisfied.\n\nIn our case, the location and orientation of each polygon in the linkage can be represented by a total of 6 parameters: 3 for location and 3 for roational orientation. Thus, the entire configuration of an intermediate $x$ can be represented in the parameter space $\\mathbb{R}^{F_x\\times6}$. With constraints corresponding to hinged connections we construct a function $\\varphi$ which is zero if and only if the constraints are satisfied. Thus the configuration space is $\\{z \\in \\mathbb{R}^{F_x\\times6} : \\varphi(z) =0\\}$. As we will show below, the constraint equation $\\varphi$ can be constructed as a polynomial which means that the configuration space (as the zero set of this polynomial) is an algebraic variety. \n\n PARAGRAPH ON DIFFERENT DOF VALS AT DIFFERENT CONFIGS OF SAME INTERMEDIATE We refer to the embedded configuration of $x$ such that $x$ is a subset of the original polyhedron as the \\textbf{canonical configuration}.\n\nTo mathematically describe a particular configuration, we specify the locations of the vertices of each face. Thus, the configuration space can be described as a manifold embegged in $\\mathbb{R}^{3\\times N_x}$ where $N_x \\doteq \\sum_{f\\in \\left(\\mathcal{P}\\right)}s_f\\mathbbm{1}_{f\\subset x}$ and $s_f$ is the number of sides (and verticies) of face $f$. By parameterizing the configuration space as enmedding of the ambient space $\\mathbb{R}^{3\\times N_x}$, we must then identify the corresponding constaint equations as a function of points in ambient space. It is worth noting that while we represent each face with $3\\times s_b$ coordinates, only 6 are required to speciafy a face's position and orientation if they are chosen carefully. However, this redundancy will be removed via the constraint equations. Notationally, we refer to the $k$th vertex of the $j$th face of $x$ as $v^{jk} = \\left(v^{jk}_x,v^{jk}_y,v^{jk}_z\\right)$. There are five fundamental types of constraint equations: base constraints, edge length constraints, vertex identification constraints, angle constraints, and 2D face constraint. \n\nThe base constaints are put in place to fix one of the intermediate's faces in space to remove the 6 trivial degrees of freedom from the calculation. If $f_b$ is the face we wish to designate as the base we have the following $3\\times s_b$ constraint equations\n\\begin{align}\n\\psi_{base}^{k,x}\\left(\\mathbf{v}\\right)& = v^{b,k}_x - c^{b,k}_x \\\\\n\\psi_{base}^{k,y}\\left(\\mathbf{v}\\right)& = v^{b,k}_y - c^{b,k}_y \\\\\n\\psi_{base}^{k,z}\\left(\\mathbf{v}\\right)& = v^{b,k}_z - c^{b,k}_z\n\\end{align}  \nfor $k = 1,\\dots,s_b$ and with $c^{b,k}_\\bullet$ a known constant. The corresponding Jacobian calculation for each constraint equations is:\n\\[\n\\frac{\\partial\\psi_{base}^{k,\\bullet}}{\\partial v} =\n  \\begin{cases}\n   1 & \\text{if } v = v^{b,k}_\\bullet \\\\\n   0       & \\text{else} \n  \\end{cases}\n\\]\n\nEdge length constraints enforce that the lengths of the edges of each face in an intermediate cannot change. Since there are $s_j$ edges for each face $f_j$ of intermediate $x$, there are $N_x$ corresponsing edge constraints. \n\\begin{align}\n\\psi_{edge}^{j,k}\\left(\\mathbf{v}\\right)& = \\left|v^{j,k} - v^{j,k-1}\\right|^2 - \\ell_{j,k}^2 \\\\\n& = \\left(v_x^{j,k} - v_x^{j,k-1}\\right)^2 +\\left(v_y^{j,k} - v_y^{j,k-1}\\right)^2 +\\left(v_z^{j,k} - v_z^{j,k-1}\\right)^2 - \\ell_{j,k}^2 \n\\end{align}  \nfor all $j: f_j \\subset x$ and with the convention that $v^{j,0} \\doteq v^{j,s_j}$ and $\\ell_{j,k}$ is a known constant. The resulting partial derivatives are\n\\[\n\t\\frac{\\partial\\psi_{edge}^{j,k}}{\\partial v} =\n  \t\\begin{cases}\n        \t2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k}_\\bullet \\\\\n   \t\t-2\\left(v^{j,k}_\\bullet-v^{j,k-1}_\\bullet\\right) \t& \\text{if } v = v^{j,k-1}_\\bullet \\\\\n   \t\t0       & \\text{else} \n  \t\\end{cases}\n\\]\n%--definiteion of 'base configuration'\n%--representation of config space definition as system of constraint equations\n%--solution of the constraint equations is a manifold except perhaps at some 'sp0ecial' configurations\n%--define DoF as 6N - rank of the jacobian of the CEqs evaluated at the base config\n\n%--go through computation of jacobian  \n\n\\end{document}\n\n", "meta": {"hexsha": "ec9b9f33d7e16117474f886f00a5fd24015b8e98", "size": 7063, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Existing Writing Dump/Keep/dof_report.tex", "max_stars_repo_name": "Danie1Johnson/thesis", "max_stars_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Existing Writing Dump/Keep/dof_report.tex", "max_issues_repo_name": "Danie1Johnson/thesis", "max_issues_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Existing Writing Dump/Keep/dof_report.tex", "max_forks_repo_name": "Danie1Johnson/thesis", "max_forks_repo_head_hexsha": "cc1137b2ab121771a6937a903f835268a5ec313e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 98.0972222222, "max_line_length": 1115, "alphanum_fraction": 0.7435933739, "num_tokens": 1900, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767810736693, "lm_q2_score": 0.8615382165412808, "lm_q1q2_score": 0.755979781022593}}
{"text": "\\chapter[Finite elements in 1D]{Finite elements for \\\\\nstationary problems in 1D}\\label{chap: FEM 1d}\n\nRecall our model two-point boundary-value problem~\\eqref{eq: model 1d}, \n\\begin{equation}\\label{eq: model 1d chap 2}\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}\nMultiply both sides of the ODE by a \\emph{test function}~$v$ and integrate to \nobtain\n\\[\n-\\int_0^L u''(x)v(x)\\,dx=\\int_0^L f(x)v(x)\\,dx.\n\\]\nAssuming $v'$ exists and is continuous on~$[0,L]$, we can integrate by parts,\n\\begin{equation}\\label{eq: int by parts}\n-\\int_0^L u''(x)v(x)\\,dx=-\\bigl[u'(x)v(x)\\bigr]_0^L+\\int_0^Lu'(x)v'(x)\\,dx,\n\\end{equation}\nand conclude that\n\\begin{equation}\\label{eq: model 1d weak}\n\\int_0^L u'(x)v'(x)\\,dx=\\int_0^L f(x)v(x)\\,dx\n\t\\quad\\text{provided $v(0)=0=v(L)$.}\n\\end{equation}\nIn the finite element method, this \\emph{weak formulation} \nis used as the basis for a discretisation of~\\eqref{eq: model 1d chap 2}.\n\n\\section{Piecewise-linear functions}\nSuppose that we partition the interval~$[0,L]$ into $P$~subintervals, not \nnecessarily of equal length, by choosing grid points, or \\emph{nodes},\n\\begin{equation}\\label{eq: 1d nodes}\n0=x_0<x_1<x_2<\\cdots<x_P=L.\n\\end{equation}\nDenote the length of the $p$th subinterval, or \\emph{element}, \nby~$h_p=x_p-x_{p-1}$, for~$1\\le p\\le P$, and denote the maximum width \nby~$h=\\max_{1\\le p\\le P}h_p$.  A function $v:[0,L]\\to\\mathbb{R}$ is \n\\emph{piecewise-linear} (with respect to the chosen grid points~$x_p$) if \nthere exist polynomials $v_1$, $v_2$, \\dots, $v_P$, each of degree at most~$1$, \nsuch that\n\\begin{equation}\\label{eq: v piecewise}\nv(x)=v_p(x)\\quad\\text{for $x_{p-1}<x<x_p$ and $1\\le p\\le P$.}\n\\end{equation}\nSuch a function~$v$ is continuous on~$[0,L]$ if and only if the $P$~polynomials \nsatisfy\n\\begin{equation}\\label{eq: v cts}\nv_p(x_p)=v_{p+1}(x_p)\\quad\\text{for $1\\le p\\le P-1$.}\n\\end{equation}\nExercise~\\ref{ex: V_h vector space} shows that the set of all continuous, \npiecewise-linear functions forms a vector space~$V_h$.  Each $v\\in V_h$ is \ndetermined by its values at the grid points.  To see why, define polynomials\nof degree at most~$1$,\n\\begin{equation}\\label{eq: piecewise linear v}\n\\tilde v_p(x)=\\frac{1}{h_p}\\bigl((x_p-x)v(x_{p-1})+(x-x_{p-1})v(x_p)\\bigr)\n    \\quad\\text{for $x_{p-1}\\le x\\le x_p$,}\n\\end{equation}\nand observe that $\\tilde v_p(x_{p-1})=v(x_{p-1})$~and $\\tilde v_p(x_p)=v(x_p)$. \nBy uniqueness of polynomial interpolation, it follows \nfrom~\\eqref{eq: v piecewise} that $\\tilde v_p=v_p$ for~$1\\le p\\le P$.\n\nIn particular, we can define the $q$th \\emph{nodal basis function} \n$\\chi_q\\in V_h$ to be the unique continuous, piecewise-linear function \nsatisfying\n\\begin{equation}\\label{eq: chi q x p}\n\\chi_q(x_p)=\\delta_{pq}\\quad\\text{for $p$, $q\\in\\{0, 1, 2, \\ldots, P\\}$,}\n\\end{equation}\nwhere $\\delta_{pq}$ is the Kronecker delta, that is,\n\\[\n\\delta_{pq}=\\begin{cases}\n1,&\\text{if $p=q$,}\\\\ 0,&\\text{if $p\\ne q$.} \n\\end{cases}\n\\]\nThe formula~\\eqref{eq: piecewise linear v} shows that, when $1\\le q\\le P-1$,\n\\begin{equation}\\label{eq: chi_q formula}\n\\chi_q(x)=\\begin{cases}\n\t(x-x_{q-1})/h_q,&\\text{for $x_{q-1}\\le x\\le x_q$,}\\\\\n\t(x_{q+1}-x)/h_{q+1},&\\text{for $x_q\\le x\\le x_{q+1}$,}\\\\\n\t0,&\\text{otherwise,}\n\\end{cases}\n\\end{equation}\nwhereas\n\\[\n\\chi_0(x)=\\begin{cases}\n\t(x_1-x)/h_1,&\\text{for $0=x_0\\le x\\le x_1$,}\\\\\n\t0,&\\text{otherwise,}\n\\end{cases}\n\\]\nand \n\\[\n\\chi_P(x)=\\begin{cases}\n\t(x-x_{P-1})/h_P,&\\text{for $x_{P-1}\\le x\\le x_P=L$,}\\\\\n\t0,&\\text{otherwise.}\n\\end{cases}\n\\]\n\nThe property~\\eqref{eq: chi q x p} implies that each~$v\\in V_h$ has the \nrepresentation\n\\[\nv(x)=\\sum_{q=0}^P v(x_q)\\chi_q(x)\\quad\\text{for $0\\le x\\le L$,}\n\\]\nsince the sum on the right defines a continuous, piecewise-linear function that \nequals $v(x_p)$ when~$x=x_p$, for~$0\\le p\\le P$.  It follows that \n$\\{\\chi_q\\}_{q=0}^P$ is a basis for~$V_h$, and therefore that $\\dim V_h=P+1$.\n\nIn the finite element method for our model 2-point boundary-value \nproblem~\\eqref{eq: model 1d chap 2}, we define the \\emph{solution set} (or\n\\emph{trial set})\n\\begin{equation}\\label{eq: Sh 1D}\nS_h=\\{\\,v\\in V_h:\\text{$v(0)=\\gamma_0$ and $v(L)=\\gamma_L$}\\,\\}\n\\end{equation}\nand the \\emph{test space}\n\\[\nT_h=\\{\\,v\\in V_h:\\text{$v(0)=0$ and $v(L)=0$}\\,\\}.\n\\]\nNotice that $T_h$ is subspace of~$V_h$ with $\\dim T_h=P-1$ because \n$\\{\\chi_p\\}_{p=1}^{P-1}$ is a basis for~$T_h$, whereas $S_h$ is \nnot a subspace unless $\\gamma_0=0=\\gamma_L$.  Based \non~\\eqref{eq: model 1d weak}, the \\emph{finite element solution}~$u_h$\nof~\\eqref{eq: model 1d chap 2} is determined by requiring that\n\\[\nu_h\\in S_h\\qquad\\text{and}\\qquad\n\\int_0^L u_h'(x)v'(x)\\,dx=\\int_0^L f(x)v(x)\\,dx \\quad\\text{for all $v\\in T_h$.}\n\\]\nSince $\\{\\chi_p\\}_{p=1}^{P-1}$ is a basis for~$T_h$, and since the equations \nare linear in~$v$, it suffices that $u_h$ satisfies\n\\begin{equation}\\label{eq: model FEM chi p}\n\\int_0^L u_h'(x)\\chi_p'(x)\\,dx=\\int_0^L f(x)\\chi_p(x)\\,dx \n    \\quad\\text{for $1\\le p\\le P-1$.}\n\\end{equation}\nMoreover, \n\\begin{equation}\\label{eq: uh U 1d}\nu_h(x)=\\sum_{q=0}^P U_q\\chi_q(x)\\quad\\text{for $0\\le x\\le L$,}\\quad\n\\text{where $U_q=u_h(x_q)$,}\n\\end{equation}\nso\n\\[\n\\int_0^Lu_h'(x)\\chi_p'(x)\\,dx\n    =\\int_0^L\\biggl(\\sum_{k=0}^PU_q\\chi_q'(x)\\biggr)\\chi_p'(x)\\,dx\n    =\\sum_{q=0}^P\\biggl(\\int_0^L\\chi_q'(x)\\chi_p'(x)\\,dx\\biggr)U_q.\n\\]\nTherefore, by letting\n\\[\na_{pq}=\\int_0^L\\chi_q'(x)\\chi_p'(x)\\,dx\n\\quad\\text{and}\\quad\nf_p=\\int_0^Lf(x)\\chi_p(x)\\,dx,\n\\]\nwe can write \\eqref{eq: model FEM chi p} as\n\\[\n\\sum_{q=0}^P a_{pq}U_q=f_p\\quad\\text{for $1\\le p\\le P-1$.}\n\\]\nSince $u_h\\in S_h$, we have $U_0=u_h(x_0)=u_h(0)=\\gamma_0$~and \n$U_P=u_h(x_P)=u_h(L)=\\gamma_L$, leading to a $(P-1)\\times(P-1)$ linear system \nfor the unknowns $U_1$, $U_2$, \\dots, $U_{P-1}$, namely\n\\begin{equation}\\label{eq: model FEM eqns}\n\\sum_{q=1}^{P-1}a_{pq}U_q=f_p-a_{p0}\\gamma_0-a_{pM}\\gamma_L\n    \\quad\\text{for $1\\le p\\le P-1$.}\n\\end{equation}\nThe $U_q$ are called the \\emph{nodal values} of~$u_h$, and the \ncoefficients~$a_{pq}$ form the \\emph{stiffness matrix}.\n\n\\begin{theorem}\nIf $|p-q|\\ge2$ then $a_{pq}=0$.  The diagonal values are\n\\[\na_{00}=\\frac{1}{h_1},\\qquad\n\\text{$a_{pp}=\\frac{1}{h_p}+\\frac{1}{h_{p+1}}$ for $1\\le p\\le P-1$,}\\qquad\na_{PP}=\\frac{1}{h_P},\n\\]\nand the off-diagonal values are\n\\[\na_{p-1,p}=a_{p,p-1}=\\frac{-1}{h_p}\\quad\\text{for $1\\le p\\le P$.}\n\\]\nFurthermore, the $(P-1)\\times(P-1)$ symmetric, tridiagonal \nmatrix~$\\boldsymbol{A}=[a_{pq}]_{p,q=1}^{P-1}$ is strictly positive-definite.\n\\end{theorem}\n\\begin{proof}\nWe see from~\\eqref{eq: chi_q formula} that if $1\\le p\\le P-1$ then\n\\[\n\\chi_p'(x)=\\begin{cases}\n1/h_p,&\\text{for $x_{p-1}<x<x_p$,}\\\\\n-1/h_{p+1},&\\text{for $x_p<x<x_{p+1}$,}\\\\\n0,&\\text{otherwise,}\n\\end{cases}\n\\]\nwith the first case missing if~$p=0$, and the second if~$p=P$.  Thus,\nthe supports of $\\chi_p'$ and $\\chi_q'$ overlap iff $|p-q|\\le1$; otherwise,\nif $|p-q|\\ge2$, then $a_{pq}=0$. The diagonal values are\n\\[\na_{00}=\\int_0^L\\chi_0'(x)^2\\,dx\n    =\\int_{x_0}^{x_1}\\biggl(\\frac{1}{h_1}\\biggr)^2\\,dx\n    =\\frac{x_1-x_0}{h_1^2}=\\frac{1}{h_1}\n\\]\nand\n\\[\na_{pp}=\\int_{x_{p-1}}^{x_p}\\biggl(\\frac{1}{h_p}\\biggr)^2\\,dx\n      +\\int_{x_p}^{x_{p+1}}\\biggl(\\frac{-1}{h_{p+1}}\\biggr)^2\\,dx\n        =\\frac{1}{h_p}+\\frac{1}{h_{p+1}}\n\\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nwith\n\\[\na_{PP}=\\int_0^L\\chi'_P(x)^2\\,dx\n    =\\int_{x_{P-1}}^{x_P}\\biggl(\\frac{-1}{h_P}\\biggr)^2\\,dx\n    =\\frac{x_P-x_{P-1}}{h_P^2}=\\frac{1}{h_P}.\n\\]\nThe off-diagonal values are\n\\[\na_{p-1,p}=\\int_0^L\\chi'_p(x)\\chi'_{p-1}(x)\\,dx\n    =\\int_{x_{p-1}}^{x_p}\\biggl(\\frac{-1}{h_p}\\biggr)\n    \\biggl(\\frac{1}{h_p}\\biggr)\\,dx=\\frac{-(x_p-x_{p-1})}{h_p^2}=\\frac{-1}{h_p}\n\\]\nfor $1\\le p\\le P$. \n\nThe matrix~$\\boldsymbol{A}$ is thus tridiagonal and symmetric.  Given\n$\\boldsymbol{V}=[V_q]_{q=1}^{P-1}\\in\\mathbb{R}^{P-1}$\nwe define $v\\in T_h$ by $v(x)=\\sum_{q=1}^{P-1}V_q\\chi_q(x)$ and observe that\n\\begin{align*}\n\\boldsymbol{V}^T\\boldsymbol{A}\\boldsymbol{V}\n    &=\\sum_{p=1}^{P-1}\\sum_{q=1}^{P-1}V_pa_{pq}V_q\n    =\\sum_{p=1}^{P-1}\\sum_{q=1}^{P-1}V_pV_q\\int_0^L\\chi_q'(x)\\chi_p'(x)\\,dx\\\\\n    &=\\int_0^L\\biggl(\\sum_{q=0}^{P-1}V_q\\chi_q'(x)\\biggr)\n             \\biggl(\\sum_{p=0}^{P-1}V_p\\chi_p'(x)\\biggr)\\,dx\n    =\\int_0^L\\bigl(v'(x)\\bigr)^2\\,dx\\ge0.\n\\end{align*}\nThus, $\\boldsymbol{A}$ is positive-semidefinite.  To see that\n$\\boldsymbol{A}$ is in fact \\emph{strictly} positive-definite, suppose that\n$\\boldsymbol{V}^T\\boldsymbol{A}\\boldsymbol{V}=0$. Then \n$\\int_0^L\\bigl(v'(x)\\bigr)^2\\,dx=0$ so $v'=0$ and thus $v$ is constant \non~$[0,L]$. Since $v(0)=0=v(L)$, the function~$v$ must be identically zero, \nand hence $V_q=0$ for~$1\\le q\\le M-1$.   That is, \n$\\boldsymbol{V}^T\\boldsymbol{A}\\boldsymbol{V}=0$ implies \n$\\boldsymbol{V}=\\boldsymbol{0}$.\n\\end{proof}\n\n\\begin{example}\nIf $P=6$ then the matrix form of the $5\\times 5$ system of \nequations~\\eqref{eq: model FEM eqns} is\n\\[\n\\begin{bmatrix}\n h_1^{-1}+h_2^{-1}&        -h_2^{-1}&&&\\\\\n         -h_2^{-1}&h_2^{-1}+h_3^{-1}&-h_3^{-1}&&\\\\\n        &-h_3^{-1}&h_3^{-1}+h_4^{-1}&-h_4^{-1}&\\\\\n       &&-h_4^{-1}&h_4^{-1}+h_5^{-1}&-h_5^{-1}\\\\\n      &&&-h_5^{-1}&h_5^{-1}+h_6^{-1}\\\\\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+\\begin{bmatrix}h_1^{-1}\\gamma_0\\\\ \\\\ \\\\ \\\\ h_6^{-1}\\gamma_L\\end{bmatrix}.\n\\]\n\\end{example}\n\nBeing positive-definite, the stiffness matrix is non-singular so the linear \nsystem~\\eqref{eq: model FEM eqns} has a unique solution, which can be \ncomputed using the algorithms described in section~\\ref{sec: sym tridiagonal}.\n\n\\section{General self-adjoint problems}\\label{sec: self-adjoint 1d}\nA second-order linear differential operator~$\\mathcal{L}$ is \n\\emph{formally self-adjoint} if it can be written in the form\n\\begin{equation}\\label{eq: L self-adjoint}\n(\\mathcal{L}u)(x)=-\\bigl(a(x)u'\\bigr)'+c(x)u(x).\n\\end{equation}\nHere, the coefficients $a(x)$ and $c(x)$ are assumed to have the same \nproperties as in Chapter~\\ref{chap: finite diff 1d}; in particular, $a(x)$ must \nsatisfy the lower bound~\\eqref{eq: ellipticity 1d}. For such an $\\mathcal{L}$, \nconsider the following two-point boundary-value problem with \\emph{mixed \nboundary conditions},\n\\begin{equation}\\label{eq: self-adjoint mixed}\n\\mathcal{L}u=f(x)\\quad\\text{for $0<x<L$,}\\quad\n\\text{with $u(0)=\\gamma_0$ and $a(L)u'(L)=\\gamma_L$.}\n\\end{equation}\nHere, at the left end of the interval~$[0,L]$ we have imposed a\n\\emph{Dirichlet boundary condition} that fixes the value of~$u(0)$, whereas\nat the right end we have imposed a \\emph{Neumann boundary condition} that\nfixes the value of~$u'(L)$; note that $a(L)\\ne0$ due to our \nassumption~\\eqref{eq: ellipticity 1d}.\n\nIntegration by parts implies that\n\\begin{equation}\\label{eq: Lu v by parts}\n\\int_0^L(\\mathcal{L}u)(x)v(x)\\,dx\n    =-\\bigl[a(x)u'(x)v(x)\\bigr]_0^L+\\int_0^L\\bigl(a(x)u'(x)v'(x)+c(x)u(x)v(x)\n        \\bigr)\\,dx,\n\\end{equation}\nso any solution~$u$ of~\\eqref{eq: self-adjoint mixed} must satisfy\n\\begin{equation}\\label{eq: Lu=f weak 1d}\n\\int_0^L\\bigl(a(x)u'(x)v'(x)+c(x)u(x)v(x)\\bigr)\\,dx\n    =\\gamma_Lv(L)+\\int_0^Lf(x)v(x)\\,dx\n    \\quad\\text{provided $v(0)=0$.}\n\\end{equation}\nGiven nodes~\\eqref{eq: 1d nodes}, we therefore define the solution set~$S_h$ \nand test space~$T_h$ by\n\\[\nS_h=\\{\\,v\\in V_h:v(0)=\\gamma_0\\,\\}\n\\quad\\text{and}\\quad\nT_h=\\{\\,v\\in V_h:v(0)=0\\,\\},\n\\]\nand require that the finite element solution~$u_h\\in S_h$ satisfy\n\\begin{equation}\\label{eq: self-adjoint mixed bc FEM}\n\\int_0^L\\bigl(a(x)u_h'(x)v'(x)+c(x)u_h(x)v(x)\\bigr)\\,dx\n    =\\gamma_Lv(L)+\\int_0^Lf(x)v(x)\\,dx\n    \\quad\\text{for all $v\\in T_h$.}\n\\end{equation}\nEquivalently, since $\\{\\chi_p\\}_{p=1}^P$ is a basis for~$T_h$, we require\n\\[\n\\int_0^L\\bigl(a(x)u_h'(x)\\chi_p'(x)+c(x)u_h(x)\\chi_p(x)\\bigr)\\,dx\n    =\\gamma_L\\chi_p(L)+\\int_0^Lf(x)\\chi_p(x)\\,dx\n    \\quad\\text{for $1\\le p\\le P$.}\n\\]\nInserting the representation~\\eqref{eq: uh U 1d} yields the system of linear \nequations\n\\[\n\\sum_{q=0}^P\\bigl(a_{pq}U_q+c_{pq}U_q\\bigr)=\\gamma_L\\chi_p(L)+f_p\n    \\quad\\text{for $1\\le p\\le P$,}\n\\]\nwhere\n\\[\na_{pq}=\\int_0^La(x)\\chi_q'(x)\\chi_p'(x)\\,dx,\\quad\nc_{pq}=\\int_0^Lc(x)\\chi_q(x)\\chi_p(x)\\,dx,\\quad\nf_p=\\int_0^Lf(x)\\chi_p(x)\\,dx.\n\\]\nMoving $U_0=\\gamma_0$ to the right-hand side leads to a $P\\times P$ linear \nsystem,\n\\[\n\\sum_{q=1}^P\\bigl(a_{pq}+c_{pq})U_q\n    =\\gamma_L\\chi_p(L)+f_p-(a_{p0}+c_{p0})\\gamma_0\n    \\quad\\text{for $1\\le p\\le P$,}\n\\]\nor, in matrix notation,\n\\begin{equation}\\label{eq: self-adjoint mixed equations}\n\\bigl(\\boldsymbol{A}+\\boldsymbol{C}\\bigr)\\boldsymbol{U}\n    =\\boldsymbol{f}+\\boldsymbol{g},\n\\end{equation}\nwhere $\\boldsymbol{A}=[a_{pq}]_{p,q=1}^P$, $\\boldsymbol{C}=[c_{pq}]_{p,q=1}^P$,\n$\\boldsymbol{f}=[f_p]_{p=1}^P$ and $\\boldsymbol{g}=[g_p]_{p=1}^P$, with\n\\[\ng_1=-(a_{10}+c_{10})\\gamma_0,\\qquad\n\\text{$g_p=0$ for $2\\le p\\le M-1$,}\\qquad\ng_P=\\gamma_L.\n\\]\nWe again refer to~$\\boldsymbol{A}$ as the stiffness matrix;\n$\\boldsymbol{C}$ is called the \\emph{mass matrix}.  On the right-hand side, \n$\\boldsymbol{f}$ is called the \\emph{load vector}.  This terminology reflects \nthe historical origins of finite element methods in structural engineering.\n\nWe equip the vector space~$L^2(0,T)$ of square-integrable \nfunctions~$v:[0,L]\\to\\mathbb{R}$ with its usual inner product\n\\[\n\\iprod{v,w}=\\int_0^Lv(x)w(x)\\,dx,\n\\]\nand, provided $c(x)\\ge0$ for~$0\\le x\\le L$, introduce the \\emph{energy\ninner product}\n\\begin{equation}\\label{eq: energy iprod}\n\\iprod{v,w}_{\\mathcal{L}}=\\int_0^L\\bigl(a(x)v'(x)w'(x)+c(x)v(x)w(x)\\bigr)\\,dx,\n\\end{equation}\ntogether with the corresponding norms\n$\\|v\\|_{\\mathcal{L}}=\\sqrt{\\iprod{v,v}_{\\mathcal{A}}}$~and\n$\\|v\\|=\\sqrt{\\iprod{v,v}}$; thus,\n\\[\n\\|v\\|^2=\\int_0^L|v(x)|^2\\,dx\n\\quad\\text{and}\\quad\n\\|v\\|_{\\mathcal{L}}^2=\\int_0^L\\bigl(a(x)|v'(x)|^2+c(x)|v(x)|^2\\bigr)\\,dx.\n\\]\nWith this notation, we can re-write \\eqref{eq: Lu=f weak 1d} as\n\\begin{equation}\\label{eq: <u,v>A}\n\\iprod{u,v}_{\\mathcal{L}}=\\gamma_Lv(L)+\\iprod{f,v}\\quad\\text{provided $v(0)=0$.}\n\\end{equation}\nand can see from~\\eqref{eq: self-adjoint mixed bc FEM} that $u_h\\in S_h$\nsatisfies\n\\begin{equation}\\label{eq: <uh,v>A}\n\\iprod{u_h,v}_{\\mathcal{L}}=\\gamma_Lv(L)+\\iprod{f,v}\n\t\\quad\\text{for all $v\\in T_h$.}\n\\end{equation}\n\n\\begin{lemma}\\label{lem: v v'}\nIf $v$~and $v'$ belong to~$L^2(0,L)$, then\n\\[\n\\|v\\|^2\\le2L\\bigl(|v(0)|^2+\\beta\\|v\\|_{\\mathcal{L}}^2\\bigr)\n\\quad\\text{and}\\quad\n|v(L)|^2\\le 2\\bigl(|v(0)|^2+\\beta\\|v\\|_{\\mathcal{L}}^2\\bigr),\n\\]\nwhere the positive constant~$\\beta$ is given by\n\\[\n\\beta=\\int_0^L\\frac{dy}{a(y)}\\le\\frac{L}{a_{\\min}}.\n\\]\n\\end{lemma}\n\\begin{proof}\nSince $v(x)=v(0)+\\int_0^xv'(y)\\,dy$, the Cauchy--Schwarz inequality implies that\n\\begin{align*}\n|v(x)|^2&\\le2|v(0)|^2+2\\biggl(\\int_0^x v'(y)\\,dy\\biggr)^2\n\\le2|v(0)|^2+2\\biggl(\\int_0^x\\frac{dy}{a(y)}\\biggr)\n\\biggl(\\int_0^xa(y)|v'(y)|^2\\,dy\\biggr)\\\\\n\t&\\le2|v(0)|^2+2\\beta\\|v\\|_{\\mathcal{L}}^2\n\\end{align*}\nso\n\\begin{align*}\n\\|v\\|^2&=\\int_0^L|v(x)|^2\\,dx\\le 2L|v(0)|^2+2\\beta L\\|v\\|_{\\mathcal{L}}^2.\n\\end{align*}\nSimilarly, since $v(L)=v(0)+\\int_0^Lv'(y)\\,dy$ we have\n\\begin{align*}\n|v(L)|^2&\\le2|v(0)|^2+2\\biggl(\\int_0^Lv'(y)\\,\\biggr)^2\n\t\\le2|v(0)|^2+2\\biggl(\\int_0^L\\frac{dy}{a(y)}\\biggr)\n\t\\biggl(\\int_0^La(y)|v'(y)|^2\\,dy\\biggr)\\\\\n\t&=2|v(0)|^2+2\\beta\\|v\\|_{\\mathcal{L}}^2,\n\\end{align*}\nas claimed.\n\\end{proof}\n\nThe \\emph{Sobolev space} with differentiability index~$r$ is the vector\nspace\n\\begin{equation}\\label{eq: Hr 1d def}\nH^r(0,L)=\\{\\,v\\in L^2(0,L): \\text{$v^{(k)}\\in L^2(0,L)$ for $1\\le k\\le r$}\\,\\};\n\\end{equation}\nthus, $v\\in H^r(0,L)$ iff $v$, $v'$, \\dots, $v^{(r)}$ are square integrable\non~$[0,L]$.\n\n\\begin{theorem}\\label{thm: ||u||A}\nAssume that $c(x)\\ge0$ for~$0\\le x\\le L$.  Then, the mixed, two-point \nboundary-value problem~\\eqref{eq: self-adjoint mixed} has a unique weak\nsolution~$u\\in H^1(0,L)$, and there is a constant~$C>0$ (depending only on $L$,\n$a$~and $c$) such that\n\\[\n\\|u\\|_{\\mathcal{L}}^2\\le C\\bigl(|\\gamma_0|^2+|\\gamma_L|^2+\\|f\\|^2\\bigr).\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $u_0(x)=L^{-1}(L-x)u(0)$ and $v(x)=u(x)-u_0(x)$, so that\n\\[\nu_0(0)=u(0),\\quad u_0(L)=0,\\quad v(0)=0,\\quad v(L)=u(L).\n\\]\nBy~\\eqref{eq: <u,v>A},\n\\[\n\\iprod{u,u-u_0}_{\\mathcal{L}}=\\gamma_Lu(L)+\\iprod{f,u-u_0}\n\\]\nand so\n\\[\n\\|u\\|_{\\mathcal{L}}^2=\\gamma_L u(L)+\\iprod{f,u}-\\iprod{f,u_0}\n\t+\\iprod{u,u_0}_{\\mathcal{L}}.\n\\]\nFor any $\\epsilon>0$, \\cref{lem: v v'} gives\n\\[\n|\\gamma_L u(L)|=2\\bigl(\\epsilon^{-1/2}\\,|\\gamma_L|\\bigr)\n\t\\bigl(\\tfrac12\\epsilon^{1/2}\\,|u(L)|\\bigr)\n\\le\\epsilon^{-1}\\,\\gamma_L^2\n\t+\\tfrac14\\epsilon\\,|u(L)|^2\n\t\\le\\epsilon^{-1}\\gamma_L^2+\\tfrac12\\epsilon\\bigl(|u(0)|^2\n\t+\\beta\\|u\\|_{\\mathcal{L}}^2\\bigr),\n\\]\nand by the Cauchy--Schwarz inequality,\n\\begin{align*}\n|\\iprod{f,u}|&\\le\\|f\\|\\|u\\|=2\\bigl(\\epsilon^{-1/2}\\|f\\|\\bigr)\n\t\\bigl(\\tfrac12\\epsilon^{1/2}\\|u\\|\\bigr)\n\t\\le\\epsilon^{-1}\\|f\\|^2+\\tfrac14\\epsilon\\|u\\|^2\\\\\n\t&\\le\\epsilon^{-1}\\|f\\|^2\n\t+\\tfrac12 L\\epsilon\\bigl(|u(0)|^2+\\beta\\|u\\|_{\\mathcal{L}}^2\\bigr).\n\\end{align*}\nLikewise,\n\\[\n|\\iprod{f,u_0}|\\le\\epsilon^{-1}\\|f\\|^2+\\tfrac12\\epsilon\\|u_0\\|^2\n\\quad\\text{and}\\quad\n|\\iprod{u,u_0}_{\\mathcal{L}}|\\le\\epsilon^{-1}\\|u_0\\|_{\\mathcal{L}}^2\n\t+\\tfrac14\\epsilon\\|u_0\\|_{\\mathcal{L}}^2,\n\\]\nand, since $u(0)=\\gamma_0$,\n\\[\n\\|u\\|_{\\mathcal{L}}^2\\le\\epsilon^{-1}\\bigl(|\\gamma_L|^2+2\\|f\\|^2+\\|u_0\\|^2\\bigr)\n+\\tfrac12\\epsilon\\bigl((1+L)|\\gamma_0|^2+\\|u_0\\|^2\n\t+\\tfrac12\\|u_0\\|_{\\mathcal{L}}^2+(1+L)\\beta\\|u\\|_{\\mathcal{L}}^2\\bigr).\n\\]\nNow choose $\\epsilon=(1+L)^{-1}\\beta^{-1}$ so that $\\epsilon(1+L)\\beta=1$ and \nthus\n\\[\n\\|u\\|_{\\mathcal{L}}^2\\le(1+L)\\beta\\bigl(|\\gamma_L|^2+2\\|f\\|^2+\\|u_0\\|^2\\bigr)\n\t+\\tfrac12\\beta^{-1}|\\gamma_0|^2+\\tfrac12(1+L)^{-1}\\beta^{-1}\n\t\\bigl(\\|u_0\\|^2+\\tfrac12\\|u_0\\|_{\\mathcal{L}}^2\\bigr)\n\t+\\tfrac12\\|u\\|_{\\mathcal{L}}^2.\n\\]\nAfter cancelling the term~$\\tfrac12\\|u\\|_{\\mathcal{L}}^2$ and multiplying both\nsides by~$2$, we obtain\n\\[\n\\|u\\|_{\\mathcal{L}}^2\\le2(1+L)\\beta\\bigl(|\\gamma_L|^2+2\\|f\\|^2+\\|u_0\\|^2\\bigr)\n\t+\\beta^{-1}|\\gamma_0|^2+(1+L)^{-1}\\beta^{-1}\n\t\\bigl(\\|u_0\\|^2+\\tfrac12\\|u_0\\|_{\\mathcal{L}}^2\\bigr),\n\\]\nwith\n\\[\n\\|u_0\\|^2=\\frac{|u(0)|^2}{L^2}\\int_0^L(L-x)^2\\,dx\n\t=\\frac{|\\gamma_0|^2}{L^2}\\,\\frac{L^3}{3}=\\tfrac13L|\\gamma_0|^2\n\\]\nand\n\\[\n\\|u_0\\|_{\\mathcal{L}}^2=\\frac{|\\gamma_0|^2}{L^2}\\int_0^L\\bigl(\n\ta(x)+c(x)(L-x)^2\\bigr)\\,dx\n\t\\le\\bigl(L^{-1}a_{\\max}+\\tfrac13L^2c_{\\max}\\bigr)|\\gamma_0|^2,\n\\]\nimplying the desired estimate for~$\\|u\\|_{\\mathcal{L}}^2$.\n\\end{proof}\n\n\\section{Matrix assembly element-by-element}\\label{sec: matrix assembly 1d}\n\nIn the previous section, we used the nodal basis functions~$\\chi_q$ to set up \nthe linear system~\\eqref{eq: self-adjoint mixed equations}, but this approach \nbecomes very complicated in 2D~or 3D, or even in 1D when using \npiecewise-polynomials of higher degree.  Instead, a simpler method is to \nassemble the matrices $\\boldsymbol{A}$~and $\\boldsymbol{C}$, and the \nvector~$\\boldsymbol{f}$, element-by-element.  \n\nFor~$1\\le p\\le P$, we put $\\mathsf{n}\\brak{p}_1=x_{p-1}$~and\n$\\mathsf{n}\\brak{p}_2=x_p$ so that the $p$th \nelement is $[x_{p-1},x_p]=[\\mathsf{n}\\brak{p}_1,\\mathsf{n}\\brak{p}_2]$.  The\n\\emph{linear shape functions} for this element are defined by\n\\[\n\\psi\\brak{p}_1(x)=\\frac{x_p-x}{h_p}\n\\quad\\text{and}\\quad\n\\psi\\brak{p}_2(x)=\\frac{x-x_{p-1}}{h_p}\n\\quad\\text{for $x_{p-1}\\le x\\le x_p$,}\n\\]\nand satisfy\n\\[\n\\psi\\brak{p}_j(\\mathsf{n}\\brak{p}_k)=\\delta_{jk}\n    \\quad\\text{for $j$, $k\\in\\{1,2\\}$,}\n\\]\nso that for any~$v\\in V_h$,\n\\[\nv(x)=v(\\mathsf{n}\\brak{p}_1)\\psi\\brak{p}_1(x)\n    +v(\\mathsf{n}\\brak{p}_2)\\psi\\brak{p}_2(x)\n    \\quad\\text{for $x\\in[\\mathsf{n}\\brak{p}_1,\\mathsf{n}\\brak{p}_2]$.}\n\\]\nThe \\emph{element stiffness matrix} is defined by\n\\[\n\\boldsymbol{A}\\brak{p}=\\begin{bmatrix}\na\\brak{p}_{11}&a\\brak{p}_{12}\\\\\na\\brak{p}_{21}&a\\brak{p}_{22}\\end{bmatrix}\n\\quad\\text{where}\\quad\na\\brak{p}_{jk}=\\int_{x_{p-1}}^{x_p}a(x)\\bigl(\\psi_k\\brak{p}\\bigr)'(x)\n    \\bigl(\\psi_j\\brak{p}\\bigr)'(x)\\,dx,\n\\]\nthe \\emph{element mass matrix} by\n\\[\n\\boldsymbol{C}\\brak{p}=\\begin{bmatrix}\nc\\brak{p}_{11}&c\\brak{p}_{12}\\\\\nc\\brak{p}_{21}&c\\brak{p}_{22}\\end{bmatrix}\n\\quad\\text{where}\\quad\nc\\brak{p}_{jk}=\\int_{x_{p-1}}^{x_p}c(x)\\psi_k\\brak{p}(x) \n    \\psi_j\\brak{p}(x)\\,dx,\n\\]\nand the \\emph{element load vector} by\n\\[\n\\boldsymbol{f}\\brak{p}=\\begin{bmatrix}f\\brak{p}_1\\\\ f\\brak{p}_2\\end{bmatrix}\n\\quad\\text{where}\\quad\nf\\brak{p}_j=\\int_{x_{p-1}}^{x_p}f(x)\\psi_j\\brak{p}(x)\\,dx.\n\\]\n\n\\begin{example}\\label{example: linear elt matrix 1d}\nWe will show that for the constant coefficients $a(x)=1$ and $c(x)=1$, the\nelement stiffness and mass matrices are simply\n\\[\n\\boldsymbol{A}\\brak{p}=\\frac{1}{h_p}\\begin{bmatrix}1&-1\\\\ -1&1\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{C}\\brak{p}=\\frac{h_p}{6}\\begin{bmatrix}2&1\\\\ 1&2\\end{bmatrix}.\n\\]\nIn fact, since $(\\psi\\brak{p}_1)'(x)=-1/h_p$ and \n$(\\psi\\brak{p}_2)'(x)=1/h_p$, we see that\n\\[\na\\brak{p}_{11}=a\\brak{p}_{22}\n    =\\int_{x_{p-1}}^{x_p}\\frac{1}{h_p^2}\\,dx\n    =\\frac{x_p-x_{p-1}}{h_p^2}=\\frac{1}{h_p}\n\\]\nand\n\\[\na\\brak{p}_{12}=a\\brak{p}_{21}\n    =\\int_{x_{p-1}}^{x_p}\\frac{-1}{h_p^2}\\,dx=\\frac{-1}{h_p}.\n\\]\nFor the element mass matrix,\n\\[\nc\\brak{p}_{11}=\\int_{x_{p-1}}^{x_p}\\biggl(\\frac{x_p-x}{h_p}\\biggr)^2\\,dx\n    =\\biggl[-\\frac{(x_p-x)^3}{3h_p^2}\\biggr]_{x_{p-1}}^{x_p}\n    =\\frac{(x_p-x_{p-1})^3}{3h_p^2}=\\frac{h_p}{3}\n\\]\nand similarly\n\\[\nc\\brak{p}_{22}=\\int_{x_{p-1}}^{x_p}\\biggl(\\frac{x-x_{p-1}}{h_p}\\biggr)^2\\,dx\n    =\\biggl[-\\frac{(x-x_{p-1})^3}{3h_p^2}\\biggr]_{x_{p-1}}^{x_p}\n    =\\frac{(x_p-x_{p-1})^3}{3h_p^2}=\\frac{h_p}{3},\n\\]\nwhereas, integrating by parts,\n\\begin{align*}\nc\\brak{p}_{12}&=c\\brak{p}_{21}=\\int_{x_{p-1}}^{x_p}\n    \\biggl(\\frac{x_p-x}{h_p}\\biggr)\\biggl(\\frac{x-x_{p-1}}{h_p}\\biggr)\\,dx\\\\\n    &=\\frac{1}{h_p^2}\\biggl(\n    \\biggl[(x_p-x)\\frac{(x-x_{p-1})^2}{2}\\biggr]_{x_{p-1}}^{x_p}\n    -\\int_{x_{p-1}}^{x_p}(-1)\\frac{(x-x_{p-1})^2}{2}\\,dx\\biggr)\\\\\n    &=\\frac{1}{2h_p^2}\\int_{x_{p-1}}^{x_p}(x-x_{p-1})^2\\,dx\n    =\\frac{1}{2h_p^2}\\biggl[\\frac{(x-x_{p-1})^3}{3}\\biggr]_{x_{p-1}}^{x_p}\n    =\\frac{h_p}{6}.\n\\end{align*}\n\\end{example}\n\nWe enumerate the nodes of the mesh so that the \\emph{free nodes precede \nthe fixed nodes}, where the latter are those at which the value of the \nsolution is fixed by a Dirichlet boundary condition.  For our \nproblem~\\eqref{eq: self-adjoint mixed}, the only fixed node is~$x_0$, so we put\n\\[\n\\mathsf{n}_p=x_p\\quad\\text{for $1\\le p\\le P$,}\n\\quad\\text{and}\\quad\\mathsf{n}_{P+1}=x_0.\n\\]\nThe $2\\times(P+1)$ \\emph{connectivity matrix} $\\boldsymbol{T}=[t_{jp}]$ is \ndefined by\n\\begin{equation}\\label{eq: e pm def}\nt_{jp}=r\\quad\\text{iff}\\quad\\mathsf{n}\\brak{p}_j=\\mathsf{n}_r;\n\\end{equation}\n\n\\begin{figure}\n\\caption{Node numbering from \\cref{example: node numbers 1d} with~$P=4$.}\n\\begin{center}\n\\begin{tikzpicture}[scale=3.0]\n\\draw[-,thick](-0.5,0) -- (4.5,0);\n\\draw[fill] (0,0) circle (0.03cm);\n\\foreach \\x in {1, ..., 4}\n    \\draw[fill=red] (\\x,0) circle (0.03cm);\n\\node[below] at (0,-0.1) {$\\mathsf{n}_5=0$};\n\\node[below] at (1,-0.1) {$\\mathsf{n}_1$};\n\\node[below] at (2,-0.1) {$\\mathsf{n}_2$};\n\\node[below] at (3,-0.1) {$\\mathsf{n}_3$};\n\\node[below] at (4,-0.1) {$\\mathsf{n}_4=L$};\n\\node[above] at (0,0) {$\\mathsf{n}\\brak{1}_1$};\n\\node[above] at (1,0) {$\\mathsf{n}\\brak{1}_2=\\mathsf{n}\\brak{2}_1$};\n\\node[above] at (2,0) {$\\mathsf{n}\\brak{2}_2=\\mathsf{n}\\brak{3}_1$};\n\\node[above] at (3,0) {$\\mathsf{n}\\brak{3}_2=\\mathsf{n}\\brak{4}_1$};\n\\node[above] at (4,0) {$\\mathsf{n}\\brak{4}_2$};\n\\end{tikzpicture}\n\\end{center}\n\\end{figure}\n\n\\begin{example}\\label{example: node numbers 1d}\nIf $P=4$ then\n\\[\n\\boldsymbol{T}=\\begin{bmatrix}\n5&1&2&3\\\\\n1&2&3&4\\end{bmatrix}.\n\\]\n\\end{example}\n\nWriting $U\\brak{p}_k=u_h(\\mathsf{n}\\brak{p}_k)$~and\n$V\\brak{p}_j=v(\\mathsf{n}\\brak{p}_j)$, we see that\n\\[\nu_h(x)=\\sum_{k=1}^2U\\brak{p}_k\\psi\\brak{p}_k(x)\n\\quad\\text{and}\\quad\nv(x)=\\sum_{j=1}^2V\\brak{p}_j\\psi\\brak{p}_j(x)\n\\quad\\text{for $x\\in[x_{p-1},x_p]$.}\n\\]\nThus,\n\\[\n\\int_0^Lf(x)v(x)\\,dx=\\sum_{p=1}^P\\int_{x_{p-1}}^{x_p}f(x)\\sum_{j=1}^2\n    V\\brak{p}_j\\psi\\brak{p}_j(x)\\,dx\n    =\\sum_{p=1}^P\\sum_{j=1}^2 f\\brak{p}_jV_j\\brak{p}\n\\]\nand\n\\begin{align*}\n\\int_0^La(x)u_h'(x)v'(x)\\,dx\n    &=\\sum_{p=1}^P\\int_{x_{p-1}}^{x_p}a(x)\n    \\biggl(\\sum_{k=1}^2 U\\brak{p}_k(\\psi_k\\brak{p})'(s)\\biggr)\n    \\biggl(\\sum_{j=1}^2 V\\brak{p}_j(\\psi_j\\brak{p})'(x)\\biggr)\\,dx\\\\\n    &=\\sum_{p=1}^P\\sum_{k=1}^2\\sum_{j=1}^2\n    U\\brak{p}_ka\\brak{p}_{jk}V\\brak{p}_j;\n\\end{align*}\nlikewise\n\\[\n\\int_0^Lc(x)u_h(x)v(x)\\,dx=\\sum_{p=1}^P\\sum_{k=1}^2\\sum_{j=1}^2\n    U\\brak{p}_kc\\brak{p}_{jk}V\\brak{p}_j\n\\quad\\text{and}\\quad\nv(L)=V\\brak{P}_2.\n\\]\nTherefore, \\eqref{eq: self-adjoint mixed bc FEM} holds iff\n\\[\n\\sum_{p=1}^P\\sum_{j=1}^2V\\brak{p}_j\n\\sum_{k=1}^2\\bigl(a\\brak{p}_{jk}+c\\brak{p}_{jk}\\bigr)U\\brak{p}_k\n    =\\gamma_LV\\brak{P}_2+\\sum_{p=1}^P\\sum_{j=1}^2V\\brak{p}_jf\\brak{p}_j\n    \\quad\\text{for all $v\\in T_h$.}\n\\]\n\nFor~$v\\in V_h$, put\n\\[\nV_r=v(\\mathsf{n}\\brak{p}_r)\\quad\\text{for $1\\le r\\le P+1$,}\n\\]\nso that $V_r=V\\brak{p}_j$ iff $r=t_{jp}$, and hence\n\\[\n\\sum_{p=1}^{P+1}\\sum_{j=1}^2V\\brak{p}_jf\\brak{p}_j=\\sum_{r=1}^PV_rf_r,\n\\]\nwhere\n\\[\nf_r=\\sum_{j\\in\\mathcal{I}_r}f\\brak{p}_j\n\\quad\\text{and}\\quad\n\\mathcal{I}_r=\\{\\,(p,j):t_{jp}=r\\,\\}.\n\\]\nSimilarly, put $U_s=u_h(\\mathsf{n}_s)$ so that $U_s=U\\brak{p}_k$ iff \n$s=t_{kp}$, and hence\n\\[\n\\sum_{p=1}^P\\sum_{j=1}^2V\\brak{p}_j\\sum_{k=1}^2\n\\bigl(a\\brak{p}_{jk}+c\\brak{p}_{jk}\\bigr)U\\brak{p}_k\n=\\sum_{r=1}^{P+1}V_r\\sum_{s=1}^{P+1}(a_{rs}+c_{rs})U_s\n\\]\nwhere\n\\[\na_{rs}=\\sum_{(p,j,k)\\in\\mathfrak{I}_{rs}}a\\brak{p}_{jk}\n\\qquad\\text{and}\\qquad\nc_{rs}=\\sum_{(p,j,k)\\in\\mathfrak{I}_{rs}} c\\brak{p}_{jk},\n\\]\nwith\n\\[\n\\mathcal{I}_{rs}=\\{\\,(p,j,k):\\text{$t_{jp}=r$ and $t_{kp}=s$}\\,\\}.\n\\]\nIn this way, \\eqref{eq: self-adjoint mixed bc FEM} holds iff\n\\[\n\\sum_{r=1}^PV_r\\sum_{s=1}^{P+1}(a_{rs}+c_{rs})U_s=\\gamma_LV_{P}\n\t+\\sum_{r=1}^PV_r\\sum_{s=1}^{P+1}(a_{rs}+c_{rs})U_s,\n\\]\nremembering that $V_{P+1}=v(\\mathsf{n}_{P+1})=v(0)=0$.  Forming the \n$P\\times(P+1)$ matrices $\\boldsymbol{A}=[a_{pq}]$~and \n$\\boldsymbol{C}=[c_{pq}]$, and the $P$-dimensional vector~$\\boldsymbol{f}$,\nwe see that\n\\begin{equation}\\label{eq: VT(A+C)U}\n\\boldsymbol{V}^T\\bigl(\\boldsymbol{A}+\\boldsymbol{C}\\bigr)\\boldsymbol{U}\n    =\\gamma_LV_P+\\boldsymbol{V}^T\\boldsymbol{f}\n    \\quad\\text{for all $\\boldsymbol{V}\\in\\mathbb{R}^P$,}\n\\end{equation}\nand therefore\n\\begin{equation}\\label{eq: A C f example}\n\\bigl(\\boldsymbol{A}+\\boldsymbol{C}\\bigr)\\boldsymbol{U}\n    =\\gamma_L\\boldsymbol{e}_P+\\boldsymbol{f}.\n\\end{equation}\n\nPartition the matrices as\n$\\boldsymbol{A}=[\\boldsymbol{A}\\free\\quad\\boldsymbol{A}\\fix]$~and\n$\\boldsymbol{C}=[\\boldsymbol{C}\\free\\quad\\boldsymbol{C}\\fix]$, where\n$\\boldsymbol{A}\\free$~and $\\boldsymbol{C}\\free$ are $P\\times P$, and so\n$\\boldsymbol{A}\\fix$~and $\\boldsymbol{C}\\fix$ are $P\\times1$.  Likewise\npartition the vector~$\\boldsymbol{U}=[\\boldsymbol{U}\\free\\quad U\\fix]^T$ where\n$\\boldsymbol{U}\\free$ is $P\\times1$ and so $U\\fix$ is $1\\times1$, that is, a\nscalar.  Since $U\\fix=U_{P+1}=u_h(\\mathsf{n}_{P+1})=u_h(0)=\\gamma_0$,\n\\[\n\\bigl(\\boldsymbol{A}+\\boldsymbol{C}\\bigr)\\boldsymbol{U}\n    =\\bigl[(\\boldsymbol{A}\\free+\\boldsymbol{C}\\free)\\quad\n    (\\boldsymbol{A}\\fix+\\boldsymbol{C}\\fix)\\bigr]\n    \\begin{bmatrix}\\boldsymbol{U}\\free\\\\ U\\fix\\end{bmatrix}\n    =(\\boldsymbol{A}\\free+\\boldsymbol{C}\\free)\\boldsymbol{U}\\free\n    +\\gamma_0(\\boldsymbol{A}\\fix+\\boldsymbol{C}\\fix),\n\\]\nyielding the $P\\times P$ linear system\n\\begin{equation}\\label{eq: FEM 1d mixed linear system}\n\\bigl(\\boldsymbol{A}\\free+\\boldsymbol{C}\\free\\bigr)\\boldsymbol{U}\\free\n=\\boldsymbol{f}-\\gamma_0(\\boldsymbol{A}\\fix+\\boldsymbol{C}\\fix)\n    +\\gamma_L\\boldsymbol{e}_P.\n\\end{equation}\nAlgorithm~\\ref{alg: assemble f piecewise linear} shows how, using the \nconnectivity matrix~$\\boldsymbol{T}=[t_{pm}]$, the global load \nvector~$\\boldsymbol{f}$ can be assembled from the element load \nvectors~$\\boldsymbol{f}\\brak{p}$.  Likewise, \nalgorithm~\\ref{alg: assemble A piecewise linear} shows how the global \nstiffness matrix~$\\boldsymbol{A}$ can be assembled from the element stiffness \nmatrices~$\\boldsymbol{A}\\brak{p}$.  The global mass matrix~$\\boldsymbol{C}$ is \nassembled in the same way. In practice, $\\boldsymbol{A}$~and $\\boldsymbol{C}$ \nare constructed an appropriate \\emph{sparse matrix} data structure.\n\n\\begin{algorithm}\n\\caption{Assemble the load vector $\\boldsymbol{f}$\nfrom~\\eqref{eq: A C f example}.}\n\\label{alg: assemble f piecewise linear}\n\\begin{algorithmic}\n\\State Allocate storage for $\\boldsymbol{f}=[f_p]\\in\\mathbb{R}^P$.\n\\For{$p=1:P$}\n    \\State $f_p=0$\n\\EndFor\n\\For{$p=1:P$}\n    \\State Compute $\\boldsymbol{f}\\brak{p}$\n    \\For{$j=1:2$}\n        \\State $r=t_{pj}$\\Comment{$\\mathsf{n}_r=\\mathsf{n}\\brak{p}_j$}\n        \\If{$r\\le M$}\n            \\State $f_r\\gets f_r+f\\brak{p}_j$\n        \\EndIf\n    \\EndFor\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{algorithm}\n\\caption{Assemble the stiffness matrix $\\boldsymbol{A}$\nfrom~\\eqref{eq: A C f example}.}\n\\label{alg: assemble A piecewise linear}\n\\begin{algorithmic}\n\\State Allocate storage for\n$\\boldsymbol{A}=[a_{pq}]\\in\\mathbb{R}^{P\\times(P+1)}$\n\\For{$p=1:P$}\n    \\For{$q=1:P+1$}\n        \\State $a_{pq}=0$\n    \\EndFor\n\\EndFor\n\\For{$p=1:P$}\n    \\State Compute $\\boldsymbol{A}\\brak{p}$\n    \\For{$j=1:2$}\n        \\State $r=e_{jp}$\n        \\If{$r\\le P$}\n            \\For{$k=1:2$}\n                \\State $s=t_{kp}$\n                \\State $a_{rs}\\gets a_{rs}+a\\brak{p}_{jk}$\n            \\EndFor\n        \\EndIf\n    \\EndFor\n\\EndFor\n\\end{algorithmic}\n\\end{algorithm}\n\n\\begin{example}\\label{example: assemble A}\nLet $L=4$ and consider a uniform grid with $P=4$ subintervals, and suppose \nthat $a(x)=1=c(x)$.  Thus, by \\cref{example: linear elt matrix 1d},\n\\[\nh_p=1,\\quad\\boldsymbol{A}\\brak{p}=\\begin{bmatrix}1&-1\\\\ -1&1\\end{bmatrix},\\quad\n\\boldsymbol{C}=\\frac{1}{6}\\begin{bmatrix}2&1\\\\ 1&2\\end{bmatrix},\n\\]\nand by \\cref{example: node numbers 1d},\n\\[\n\\mathcal{I}_1=\\{(1,2),(2,1)\\},\\quad\n\\mathcal{I}_2=\\{(2,2),(3,1)\\},\\quad\n\\mathcal{I}_3=\\{(3,2),(4,1)\\},\\quad\n\\mathcal{I}_4=\\{(4,2)\\},\n\\]\nso\n\\[\nf_1=f\\brak{1}_2+f\\brak{2}_1,\\quad\nf_2=f\\brak{2}_2+f\\brak{3}_1,\\quad\nf_3=f\\brak{3}_2+f\\brak{4}_1,\\quad\nf_4=f\\brak{4}_2.\n\\]\nFurthermore,\n\\begin{align*}\n\\mathcal{I}_{11}&=\\{(1,2,2),(2,1,1)\\},&\n\\mathcal{I}_{12}&=\\{(2,1,2)\\},&\n\\mathcal{I}_{15}&=\\{(1,2,1)\\},\\\\\n\\mathcal{I}_{21}&=\\{(2,2,1)\\},&\n\\mathcal{I}_{22}&=\\{(2,2,2),(3,1,1)\\},&\n\\mathcal{I}_{23}&=\\{(3,1,2)\\},\\\\\n\\mathcal{I}_{32}&=\\{(3,2,1)\\},&\n\\mathcal{I}_{33}&=\\{(3,2,2),(4,1,1)\\},&\n\\mathcal{I}_{34}&=\\{(4,1,2)\\},\\\\\n\\mathcal{I}_{43}&=\\{(4,2,1)\\},&\n\\mathcal{I}_{44}&=\\{(4,2,2)\\},&&\n\\end{align*}\nwith $\\mathcal{I}_{rs}=\\emptyset$ otherwise, and hence\n\\begin{align*}\na_{11}&=a\\brak{1}_{22}+a\\brak{2}_{11},&\na_{12}&=a\\brak{2}_{12},&\na_{15}&=a\\brak{1}_{21},\\\\\na_{21}&=a\\brak{2}_{21},&\na_{22}&=a\\brak{2}_{22}+a\\brak{3}_{11},&\na_{23}&=a\\brak{3}_{12},\\\\\na_{32}&=a\\brak{3}_{21},&\na_{33}&=a\\brak{3}_{22}+a\\brak{4}_{11},&\na_{34}&=a\\brak{4}_{12},\\\\\na_{43}&=a\\brak{4}_{21},&\na_{44}&=a\\brak{4}_{22}.&&\n\\end{align*}\nAssembling the $4\\times5$ stiffness \nmatrix~$\\boldsymbol{A}=[\\boldsymbol{A}\\free\\quad\\boldsymbol{A}\\fix]$ \namounts to computing\n\\[\n\\left[\n\\begin{array}{cccc|c}1&0&0&0&-1\\\\0&0&0&0&0\\\\0&0&0&0&0\\\\0&0&0&0&0\\end{array}\n\\right]+\\left[\n\\begin{array}{cccc|c}1&-1&0&0&0\\\\-1&1&0&0&0\\\\0&0&0&0&0\\\\0&0&0&0&0\\end{array}\n\\right]+\\left[\n\\begin{array}{cccc|c}0&0&0&0&0\\\\0&1&-1&0&0\\\\0&-1&1&0&0\\\\0&0&0&0&0\\end{array}\n\\right]+\\left[\n\\begin{array}{cccc|c}0&0&0&0&0\\\\0&0&0&0&0\\\\0&0&1&-1&0\\\\0&0&-1&1&0\\end{array}\n\\right],\n\\]\nresulting in\n\\[\n\\boldsymbol{A}=\\left[\\begin{array}{cccc|c}\n2&-1&0&0&-1\\\\ -1&2&-1&0&0\\\\ 0&-1&2&-1&0\\\\ 0&0&-1&1&0\\end{array}\\right],\\qquad\n\\boldsymbol{A}\\free=\\begin{bmatrix}\n2&-1&0&0\\\\ -1&2&-1&0\\\\ 0&-1&2&-1\\\\ 0&0&-1&1\\end{bmatrix},\\qquad\n\\boldsymbol{A}\\fix=\\begin{bmatrix}-1\\\\ 0\\\\ 0\\\\ 0\\end{bmatrix}.\n\\]\nSimilarly, we find that the mass \nmatrix~$\\boldsymbol{C}=[\\boldsymbol{C}\\free\\quad\\boldsymbol{C}\\fix]$ is given by\n\\[\n\\boldsymbol{C}=\\frac{1}{6}\\left[\\begin{array}{cccc|c}\n4&1&0&0&1\\\\ 1&4&1&0&0\\\\ 0&1&4&1&0\\\\ 0&0&1&2&0\\end{array}\\right],\\qquad\n\\boldsymbol{C}\\free=\\frac{1}{6}\\begin{bmatrix}\n4&1&0&0\\\\ 1&4&1&0\\\\ 0&1&4&1\\\\ 0&0&1&2\\end{bmatrix},\\qquad\n\\boldsymbol{C}\\fix=\\frac{1}{6}\\begin{bmatrix}1\\\\ 0\\\\ 0\\\\ 0\\end{bmatrix}.\n\\]\n\\end{example}\n\n\\section{Quadratic elements}\\label{sec: quadratic elements}\n\nLet us again consider the self-adjoint, two-point boundary-value \nproblem~\\eqref{eq: self-adjoint mixed} but now let $V_h$ denote the vector \nspace consisting of the continuous, piecewise-\\emph{quadratic} functions with \nrespect to the grid points~$x_p$.  Thus, a function~$v:[0,L]\\to\\mathbb{R}$ \nbelongs to~$V_h$ iff there are polynomials $v_1$, $v_2$, \\dots, $v_M$ of degree \nat most~$2$ such that \\eqref{eq: v piecewise}~and \\eqref{eq: v cts} hold.\nFor the $p$th element~$[x_{p-1},x_p]$, we now define three nodes\n\\[\n\\mathsf{n}\\brak{p}_1=x_{p-1},\\qquad\n\\mathsf{n}\\brak{p}_2=\\tfrac12(x_{p-1}+x_p),\\qquad\n\\mathsf{n}\\brak{p}_3=x_p.\n\\]\nNotice that $\\mathsf{n}\\brak{p}_2$ is the midpoint of the element.\nCorresponding to these nodes are the quadratic shape functions\n\\begin{equation}\\label{eq: quadratic psi 1d}\n\\begin{aligned}\n\\psi\\brak{p}_1(x)\n\t&=2h_p^{-2}(x-\\mathsf{n}\\brak{p}_2)(x-\\mathsf{n}\\brak{p}_3),\\\\\n\\psi\\brak{p}_2(x)\n\t&=4h_p^{-2}(x-\\mathsf{n}\\brak{p}_1)(\\mathsf{n}\\brak{p}_3-x),\\\\\n\\psi\\brak{p}_3(x)\n\t&=2h_p^{-2}(x-\\mathsf{n}\\brak{p}_1)(x-\\mathsf{n}\\brak{p}_2),\n\\end{aligned}\n\\end{equation}\nand Exercise~\\ref{ex: quadratic DoF 1d} shows that\n\\begin{equation}\\label{eq: quadratic DoF 1d}\n\\psi\\brak{p}_j(\\mathsf{n}\\brak{p}_k)=\\delta_{jk}.\n\\end{equation}\nThe global enumeration of the free nodes is\n\\[\n\\mathsf{n}_{2p-1}=\\tfrac12(x_{p-1}+x_p)\n\\quad\\text{and}\\quad\n\\mathsf{n}_{2p}=x_p\\quad\\text{for $1\\le p\\le P$,}\n\\]\nand the fixed node is $\\mathsf{n}_{2P+1}=x_0$.  The connectivity \nmatrix~$\\boldsymbol{T}=[t_{jp}]$ is now $3\\times P$, with $t_{jp}$ again given \nby~\\eqref{eq: e pm def}.  For example, if $P=6$ then \n\\[\n\\boldsymbol{T}=\\begin{bmatrix}\n13&2&4&6&8&10\\\\\n 1&3&5&7&9&11\\\\\n 2&4&6&8&10&12          \n\\end{bmatrix}.\n\\]\n\nWe define the \\emph{reference element}~$[0,1]$ with \\emph{reference nodes}\n\\[\n\\mathsf{n}_1=0,\\qquad\\mathsf{n}_2=\\frac{1}{2},\\qquad\\mathsf{n}_3=1,\n\\]\nand corresponding quadratic (reference) shape functions\n\\begin{equation}\\label{eq: quadratic shape funcs 1d}\n\\Psi_1(\\xi)=2(\\xi-\\tfrac12)(\\xi-1),\\qquad\n\\Psi_2(\\xi)=4\\xi(1-\\xi),\\qquad\n\\Psi_3(\\xi)=2\\xi(\\xi-\\tfrac12),\n\\end{equation}\nsatisfying $\\Psi_j(\\mathsf{n}_k)=\\delta_{jk}$ for $j$, $k\\in\\{1,2,3\\}$.  \nIn this way,\n\\[\n\\Psi_j(\\xi)=\\psi\\brak{p}_j(x)\\quad\n\t\\text{if $x=x_{p-1}+\\xi h_p$,}\\quad\\text{for $0\\le\\xi\\le1$,}\n\\]\nand since $dx/d\\xi=h_p$, the chain rule implies that\n\\[\n\\Psi'_j(\\xi)=h_p(\\psi\\brak{p}_j)'(x).\n\\]\nThus, the entries of the $3\\times3$ element stiffness \nmatrix~$\\boldsymbol{A}\\brak{p}=[a_{jk}]$ are given by\n\\begin{equation}\\label{eq: a reference 1d}\na\\brak{p}_{jk}=\\frac{1}{h_p}\\int_0^1a(x_{p-1}+\\xi h_p)\n\t\\Psi'_k(\\xi)\\Psi'_j(\\xi)\\,d\\xi,\n\\end{equation}\nand those of the $3\\times3$ element mass \nmatrix~$\\boldsymbol{C}=[c\\brak{p}_{jk}]$ by\n\\begin{equation}\\label{eq: c reference 1d}\nc\\brak{p}_{jk}=h_p\\int_0^1c(x_{p-1}+\\xi h_p)\n\t\\Psi_k(\\xi)\\Psi_j(\\xi)\\,d\\xi.\n\\end{equation}\n\n\\begin{example}\\label{ex: quadratic Am Cm}\nIf $a(x)=1$~and $c(x)=1$, then\n\\begin{equation}\\label{eq: element matrices quadratic 1d}\n\\boldsymbol{A}\\brak{p}=\\frac{1}{3h_p}\\begin{bmatrix}\n 7&-8& 1\\\\\n-8&16&-8\\\\\n 1&-8& 7\\end{bmatrix}\n\\quad\\text{and}\\quad\n\\boldsymbol{C}\\brak{p}=\\frac{h_p}{30}\\begin{bmatrix}\n 4& 2&-1\\\\\n 2&16& 2\\\\\n-1& 2& 4 \\end{bmatrix}\n\\end{equation}\n\\end{example}\n\nTo deal with non-constant coefficients $a(x)$~and $c(x)$, it is convenient to \napproximate the integrals \\eqref{eq: a reference 1d}~and\n\\eqref{eq: c reference 1d} using a \\emph{quadrature rule}\n\\[\n\\int_0^1 f(\\xi)\\,d\\xi\\approx\\sum_{l=1}^J w_lf(\\xi_l)\n\\]\nwith \\emph{weights} $w_1$, $w_2$, \\dots, $w_J$ and \\emph{points}\n\\[\n0\\le\\xi_1<\\xi_2<\\cdots<\\xi_J\\le1.\n\\]\nUsing such an approximation yields, for the element stiffness matrix,\n\\[\n\\boldsymbol{A}\\brak{p}\\approx\n\t\\widetilde{\\boldsymbol{A}}\\brak{p}=[\\tilde a_{jk}\\brak{p}]\n\\quad\\text{where}\\quad\n\\tilde a\\brak{p}_{jk}=\\frac{1}{h_p}\\sum_{\\ell=1}^Jw_la(x_{p-1}+\\xi_lh_p)\n\t\\Psi'_k(\\xi_l)\\Psi'_j(\\xi_l),\n\\]\nand for the element mass matrix,\n\\[\n\\boldsymbol{C}\\brak{p}\\approx\n\t\\widetilde{\\boldsymbol{C}}\\brak{p}=[\\tilde c_{jk}\\brak{p}]\n\\quad\\text{where}\\quad\n\\tilde c\\brak{p}_{jk}=h_p\\sum_{\\ell=1}^Jw_lc(x_{p-1}+\\xi_lh_p)\n\t\\Psi_k(\\xi_l)\\Psi_j(\\xi_l).\n\\]\nWith the help of the connectivity matrix~$\\boldsymbol{T}$, the $3\\times3$ \nelement matrices $\\boldsymbol{A}\\brak{p}$~and $\\boldsymbol{C}\\brak{p}$ can be \nassembled into the $(2P)\\times(2P+1)$ global matrices $\\boldsymbol{A}$~and \n$\\boldsymbol{C}$; see exercise~\\ref{ex: assemble quadratic 1d}.\n\nBy adapting the arguments that led to~\\eqref{eq: VT(A+C)U} we find that the \nvector~$\\boldsymbol{U}=[U_j]_{j=1}^{2P+1}$ of nodal values \n$U_j=u_h(\\mathsf{n}_j)$ satisfies\n\\[\n\\boldsymbol{V}^T(\\boldsymbol{A}+\\boldsymbol{C})\\boldsymbol{U}\n\t=\\gamma_LV_{2M}+\\boldsymbol{V}^T\\boldsymbol{f}\n\t\\quad\\text{for all $\\boldsymbol{V}\\in\\mathbb{R}^{2P}$.}\n\\]\nWe again use the partitionings\n\\[\n\\boldsymbol{A}=[\\boldsymbol{A}\\free\\quad\\boldsymbol{A}\\fix],\\qquad\n\\boldsymbol{C}=[\\boldsymbol{C}\\free\\quad\\boldsymbol{C}\\fix],\\qquad\n\\boldsymbol{U}=[\\boldsymbol{U}\\free\\quad U\\fix]^T,\n\\]\nbut now $\\boldsymbol{A}\\free$~and $\\boldsymbol{C}$ are $(2P)\\times(2P)$, and\n$\\boldsymbol{A}\\fix$, $\\boldsymbol{C}\\fix$ and $\\boldsymbol{U}\\free$ are \n$(2P)\\times1$, with $U\\fix=\\gamma_0$.  It follows that $\\boldsymbol{U}\\free$ \nagain satisfies a linear system of the \nform~\\eqref{eq: FEM 1d mixed linear system}, but this system is now \n$(2P)\\times(2P)$.\n\n\\section{Polynomial interpolation}\n\nLet $\\mathbb{P}_r$ denote the vector space of real polynomials of degree at \nmost~$r$.  Let $x_1$, $x_2$, \\dots, $x_{r+1}$ be distinct points in an \ninterval~$[a,b]$, and let $f:[a,b]\\to\\mathbb{R}$ be a continuous function.  We \nsay that a polynomial~$g\\in\\mathbb{P}_r$ \\emph{interpolates} $f$ at the given \npoints if\n\\begin{equation}\\label{eq: g interpolates f}\ng(x_j)=f(x_j)\\quad\\text{for $1\\le j\\le r+1$.}\n\\end{equation}\nTo see that such a $g$ exists, we define the \\emph{Lagrange \ninterpolation polynomials} $\\ell_1$, $\\ell_2$, \\dots, $\\ell_{r+1}$ by\n\\begin{equation}\\label{eq: ell_j def}\n\\ell_j(x)=\\prod_{1\\le k\\le r+1, k\\ne j}\n\t\\frac{x-x_k}{x_j-x_k}\\quad\\text{for $1\\le j\\le r+1$,}\n\\end{equation}\nand then define the \\emph{linear interpolation operator}~$\\mathcal{Q}_r$ by\n\\[\n(\\mathcal{Q}_rf)(x)=\\sum_{j=1}^{r+1}f(x_j)\\ell_j(x).\n\\]\nObserve that $\\ell_j\\in\\mathbb{P}_r$ because it is the product of~$r$ linear \nfactors.  Moreover, if $x=x_j$ then each factor in the \nproduct~\\eqref{eq: ell_j def} equals~$1$ and so $\\ell_j(x_j)=1$, whereas if \n$x=x_k$ for some~$k\\ne j$, then one factor equals~$0$ and so $\\ell_j(x_k)=0$.\nIn other words,\n\\[\n\\ell_j(x_k)=\\delta_{jk}\\quad\\text{for $j$, $k\\in\\{1,2,\\ldots,r+1\\}$.}\n\\]\nIt follows that $\\mathcal{Q}_rf\\in\\mathbb{P}_r$ interpolates~$f$, that is,\n\\[\n(\\mathcal{Q}_rf)(x_j)=f(x_j)\\quad\\text{for $1\\le j\\le r+1$.}\n\\]\nFurthermore, $\\mathcal{Q}_rf$ is the only such interpolant, because if \n$g\\in\\mathbb{P}_r$ satisfies \\eqref{eq: g interpolates f} then the difference\n$g-\\mathcal{Q}_rf$ is a polynomial satisfying\n\\[\n(g-\\mathcal{Q}_rf)(x_j)=g(x_j)-(\\mathcal{Q}_rf)(x_j)=f(x_j)-f(x_j)=0\n\t\\quad\\text{for $1\\le j\\le r+1$,}\n\\]\nso, for some constant~$C$,\n\\[\ng(x)-(\\mathcal{Q}_rf)(x)=C(x-x_1)(x-x_2)\\cdots(x-x_{r+1}) \n\t=Cx^{r+1}+\\text{lower degree terms}.\n\\]\nBut $g-\\mathcal{Q}_rf$ has degree at most~$r$, so $C=0$ and hence\n$g(x)=(\\mathcal{Q}_rf)(x)$ for all~$x$. In particular, since any element \nof~$\\mathbb{P}_r$ interpolates itself, it follows that\n\\[\n\\mathcal{Q}_rf=f\\quad\\text{for every $f\\in\\mathbb{P}_r$,}\n\\]\nand thus $\\mathcal{Q}_r^2=\\mathcal{Q}_r$.  Hence, $\\mathcal{Q}_r$ is a \n\\emph{projection} onto~$\\mathbb{P}_r$.\n\nLet \n\\begin{equation}\\label{eq: pi r y}\n\\pi_{r,y}(x)=\\frac{(x-y)_+^r}{r!}=\\begin{cases}\n\t(x-y)^r/r!&\\text{if $a\\le y\\le x\\le b$,}\\\\\n\t0&\\text{if $a\\le x<y\\le b$.}\n\\end{cases}\n\\end{equation}\nIf $f$ is $C^{r+1}$ on~$[a,b]$ then, by Theorem~\\ref{thm: Taylor remainder}, \n\\[\nf(x)=\\sum_{k=0}^r\\frac{f^{(k)}(a)}{k!}\\,(x-a)^k\n\t+\\int_a^b\\pi_{r,y}(x)f^{(r+1)}(y)\\,dy\\quad\\text{for $a\\le x\\le b$.}\n\\]\nSince the sum on the right defines a function in~$\\mathbb{P}_r$,\napplying $\\mathcal{Q}_r$ to both sides gives\n\\[\n(\\mathcal{Q}_rf)(x)=\\sum_{k=0}^r\\frac{f^{(k)}(a)}{k!}\\,(x-a)^k\n\t+\\int_a^b(\\mathcal{Q}_r\\pi_{r,y})(x)f^{(r+1)}(y)\\,dy\n\\quad\\text{for $a\\le x\\le b$.}\n\\]\nHence, the \\emph{interpolation error} has the integral representation\n\\begin{equation}\\label{eq: Qr f error}\n(\\mathcal{Q}_rf)(x)-f(x)=\\int_a^b K_r(x,y)f^{(r+1)}(y)\\,dy\n\\quad\\text{for $a\\le x\\le b$,}\n\\end{equation}\nwhere the \\emph{Peano kernel} is defined by\n\\[\nK_r(x,y)=(\\mathcal{Q}_r\\pi_{r,y})(x)-\\pi_{r,y}(x)\n\t\\quad\\text{for $x$, $y\\in[a,b]$.}\n\\]\n\n\\begin{figure}\n\\caption{Peano kernel for linear interpolation at $0$~and $1$\n(Example~\\ref{example: linear interp}.}\n\\label{fig: linear Peano}\n\\begin{center}\n\\includegraphics[scale=0.6]{../src/chap2/Linear_PeanoK_3d.pdf}\n\\includegraphics[scale=0.5]{../src/chap2/Linear_PeanoK_contour.pdf}\n\\end{center}\n\\end{figure}\n\n\\begin{example}\\label{example: linear interp}\nConsider \\emph{linear interpolation}, that is, $r=1$, with interpolation points \n$x_1=a$~and $x_2=b$.  In this case, the Lagrange polynomials are\n\\[\n\\ell_1(x)=\\frac{x-x_2}{x_1-x_2}=\\frac{b-x}{b-a}\n\\quad\\text{and}\\quad\n\\ell_2(x)=\\frac{x-x_1}{x_2-x_1}=\\frac{x-a}{b-a},\n\\]\nand\n\\[\n(\\mathcal{Q}_1f)(x)=f(a)\\ell_1(x)+f(b)\\ell_2(x)\n\t=f(a)\\,\\frac{b-x}{b-a}+f(b)\\,\\frac{x-a}{b-a}.\n\\]\nIn particular, since $\\pi_{1,y}(a)=0$~and $\\pi_{1,y}(b)=b-y$ for~$a\\le y\\le b$,\n\\[\n(\\mathcal{Q}_1\\pi_{1,y})(x)=\\pi_{1,y}(a)\\ell_1(x)+\\pi_{1,y}(b)\\ell_2(x)\n\t=\\frac{(b-y)(x-a)}{b-a}\\quad\\text{for $x$, $y\\in[a,b]$,}\n\\]\nso\n\\[\nK_1(x,y)=\\frac{(b-y)(x-a)}{b-a}-(x-y)\\quad\\text{for $a\\le y\\le x\\le b$,}\n\\]\nand\n\\[\nK_1(x,y)=\\frac{(b-y)(x-a)}{b-a}\\quad\\text{for $a\\le x\\le y\\le b$.}\n\\]\nThus, $K_1(x,y)$ is piecewise linear in~$x$ for fixed~$y$, and vice versa, with\n\\[\nK_1(a,y)=0=K_1(b,y),\\qquad K_1(x,a)=0=K_1(x,b),\\qquad\nK_1(x,x)=\\frac{(b-x)(x-a)}{b-a}.\n\\]\n\\end{example}\n\n\\begin{figure}\n\\caption{Peano kernel~\\eqref{eq: quadratic Peano} for quadratic interpolation \nat $-1$, $0$~and $+1$.}\\label{fig: quadratic Peano}\n\\begin{center}\n\\includegraphics[scale=0.6]{../src/chap2/Quadratic_PeanoK_3d.pdf}\n\\includegraphics[scale=0.5]{../src/chap2/Quadratic_PeanoK_contour.pdf}\n\\end{center}\n\\end{figure}\n\n\\begin{example}\\label{example: quadratic interp}\nLet $x_1=-1$, $x_2=0$~and $x_3=1$.  The quadratic Lagrange polynomials are\n\\[\n\\ell_1(x)=\\frac{(x-0)(x-1)}{(-1-0)(-1-1)},\\qquad\n\\ell_2(x)=\\frac{(x+1)(x-1)}{(0+1)(0-1)},\\qquad\n\\ell_3(x)=\\frac{(x+1)(x-0)}{(1+1)(1-0)},\n\\]\nthat is,\n\\[\n\\ell_1(x)=\\tfrac12x(x-1),\\qquad\n\\ell_2(x)=(1+x)(1-x),\\qquad\n\\ell_3(x)=\\tfrac12x(x+1).\n\\]\nSince $\\pi_{2,y}(-1)=0$, $\\pi_{2,y}(0)=\\tfrac12(-y)_+^2$~and \n$\\pi_{2,y}(1)=\\tfrac12(1-y)^2$ for~$-1\\le y\\le 1$,\n\\begin{equation}\\label{eq: quadratic Peano}\nK_2(x,y)=\\tfrac12(-y)_+^2\\ell_2(x)+\\tfrac12(1-y)^2\\ell_3(x)-\\tfrac12(x-y)_+^2.\n\\end{equation}\nObserve that $\\ell_1(-x)=\\ell_3(x)$ and $\\ell_2(-x)=\\ell_2(x)$, so\n\\[\nK_2(-x,-y)=\\tfrac12(y)_+^2\\ell_2(x)+\\tfrac12(1+y)^2\\ell_1(x)-\\tfrac12(y-x)_+^2\n\\]\nand thus\n\\[\nK_2(x,y)+K_2(-x,-y)=\\tfrac12y^2\\ell_2(x)+\\tfrac12(1-y)^2\\ell_3(x)\n\t+\\tfrac12(1+y)^2\\ell_1(x)-\\tfrac12(x-y)^2.\n\\]\nWe use the identity $\\ell_1(x)+\\ell_2(x)+\\ell_3(x)=(\\mathcal{Q}_21)(x)=1$ to\nreplace $\\ell_2(x)$ with~$1-\\ell_1(x)-\\ell_3(x)$ and deduce that\n\\begin{align*}\nK_2(x,y)+K_2(-x,-y)&=\\tfrac12\\bigl[y^2-(x-y)^2\\bigr]\n\t+\\tfrac12\\bigl[(1+y)^2-y^2\\bigr]\\ell_1(x)\n\t+\\tfrac12\\bigl[(1-y)^2-y^2\\bigr]\\ell_3(x)\\\\\n\t&=\\tfrac12x(2y-x)+\\tfrac12(1+2y)\\ell_1(x)+\\tfrac12(1-2y)\\ell_3(x)\\\\\n\t&=\\tfrac12\\bigl[\\ell_1(x)+\\ell_3(x)-x^2\\bigr]\n\t+y\\bigl[x+\\ell_3(x)-\\ell_1(x)\\bigr]=0.\n\\end{align*}\nHence, $K_2$ possesses the symmetry property (Figure~\\ref{fig: quadratic Peano})\n\\begin{equation}\\label{eq: K2 symmetry}\nK_2(-x,-y)=-K_2(x,y)\\quad\\text{for $x$, $y\\in[-1,1]$.}\n\\end{equation}\n\\end{example}\n\nSince the $j$th derivative~$\\pi_{r,y}^{(j)}(x)=\\pi_{r-j,y}(x)$, we see that\n\\[\n\\partial_x^jK_r(x,y)=(\\mathcal{Q}_r\\pi_{r,y})^{(j)}(x)-\\pi_{r-j,y}(x)\n\\quad\\text{for $0\\le j\\le r$,}\n\\]\nand that the $j$th derivative of the interpolation error has the representation\n\\begin{equation}\\label{eq: Qr f error deriv}\n(\\mathcal{Q}_rf-f)^{(j)}(x)=\\int_a^b\\partial_x^j K_r(x,y)f^{(r+1)}(y)\\,dy\n\\quad\\text{for $a\\le x\\le b$.}\n\\end{equation}\n\n\n\\section{Accuracy of piecewise-polynomial approximation}\n\\label{sec: accuracy of interpolation}\n\nFix $r+1$~nodes in the reference element~$[0,1]$,\n\\begin{equation}\\label{eq: ref nodes 1d}\n0=\\mathsf{n}_1<\\mathsf{n}_2<\\cdots<\\mathsf{n}_{r+1}=1,\n\\end{equation}\nand consider an element~$[x_{p-1},x_p]$ with length~$h_p=x_p-x_{p-1}$.  The \nchange of variable,\n\\[\nx = x_{p-1} + \\xi h_p\\quad\\text{for $\\xi\\in[0,1]$,}\n\\]\ndefines an affine bijection~$\\xi\\mapsto x$ from the reference element~$[0,1]$ \nonto~$[x_{p-1},x_p]$.  We assume that the nodes in~$[x_{p-1},x_p]$ correspond \nto the reference nodes under this affine bijection, that is,\n\\[\n\\mathsf{n}_j\\brak{p}=x_{p-1}+\\mathsf{n}_jh_p\\quad\\text{for $1\\le j\\le r+1$.}\n\\]\nGiven a function $f(x)$, we define $\\hat f$ on the reference element by\n\\[\n\\hat f(\\xi)=f(x)\\quad\\text{where $x=x_{p-1}+\\xi h_p$,}\n\\]\nand let $\\mathcal{Q}_r\\brak{p}$~and $\\widehat{\\mathcal{Q}}_r$ denote \npolynomial interpolation operators for $[x_{p-1},x_p]$~and $[0,1]$, \nrespectively, so that\n\\[\n\\mathcal{Q}_r\\brak{p}f\\in\\mathbb{P}_{r+1}\\quad\\text{and}\\quad\n(\\mathcal{Q}_r\\brak{p}f)(\\mathsf{n}_j\\brak{p})=f(\\mathsf{n}_j\\brak{p})\n\\quad\\text{for $1\\le j\\le r+1$,}\n\\]\nwhereas\n\\[\n\\widehat{\\mathcal{Q}}_r\\hat f\\in\\mathbb{P}_{r+1}\\quad\\text{and}\\quad\n\\bigl(\\widehat{\\mathcal{Q}}_r\\hat f\\bigr)(\\mathsf{n}_j)=\\hat f(\\mathsf{n}_j)\n\\quad\\text{for $1\\le j\\le r+1$.}\n\\]\nNotice that if we let $g(x)=(\\mathcal{Q}_r\\brak{p}f)(x)$, then \n$\\hat g(\\xi)=\\widehat{\\mathcal{Q}}_r\\hat f(\\xi)$ because \n$\\hat g\\in\\mathbb{P}_r$~and \n\\[\n\\hat g(\\mathsf{n}_j)=g(\\mathsf{n}_j\\brak{p})=f(\\mathsf{n}_j\\brak{p})\n    =\\hat f(\\mathsf{n}_j)\\quad\\text{for $1\\le j\\le r+1$.}\n\\]\nIn other words, \n$\\widehat{\\mathcal{Q}_r\\brak{p}f}=\\widehat{\\mathcal{Q}}_r\\hat f$.\n\n\\begin{theorem}\nAssume that $f$ is $C^{r+1}$ on~$[x_{p-1},x_p]$, and let $K_r$ denote the Peano \nkernel for polynomial interpolation at the $r+1$~nodes of the reference \nelement~$[0,1]$.  Then,\n\\[\n\\int_{x_{p-1}}^{x_p}|(f-\\mathcal{Q}_r\\brak{p}f)^{(k)}(x)|^2\\,dx\n    \\le C_{r,k}h_p^{2(r+1-k)}\\int_{x_{p-1}}^{x_p}|\\hat f^{(r+1)}(x)|^2\\,dx\n    \\quad\\text{for $0\\le k\\le r$,}\n\\]\nwhere the constant\n\\[\nC_{r,k}=\\int_0^1\\int_0^1|\\partial_\\xi^kK_r(\\xi,\\eta)|^2\\,d\\eta\\,d\\xi\n\\]\ndepends only on $k$~and the choice of the $r+1$ nodes~\\eqref{eq: ref nodes 1d}.\n\\end{theorem}\n\\begin{proof}\nSince $dx/d\\xi=h_p$ we see that\n\\[\n\\hat f^{(k)}(\\xi)=h_p^k f^{(k)}(x),\n\\]\nso using \\eqref{eq: Qr f error deriv} and the Cauchy--Schwarz inequality,\n\\begin{align*}\n\\bigl|(f-\\mathcal{Q}_r\\brak{p}f)^{(k)}(x)\\bigr|^2\n    &=h_p^{-2k}\\bigl|\\bigl(\\hat f-\\widehat{Q}_r\\hat f)(\\xi)\\bigr|^2\n    =h_p^{-2k}\\biggl|\\int_0^1\\partial_\\xi^k K_r(\\xi,\\eta)\n        \\hat f^{(r+1)}(\\eta)\\, d\\eta\\biggr|^2\\\\\n    &\\le h_p^{-2k}\\biggl(\\int_0^1|\\partial_\\xi^kK_r(\\xi,\\eta)|^2\\,d\\eta\\biggr)\n    \\biggl(\\int_0^1|\\hat f^{(r+1)}(\\eta)|^2\\,d\\eta\\biggr)\n\\end{align*}\nfor $0\\le\\xi\\le1$.  Integrating with respect to~$x$, and noting that \n$dx=h_p\\,d\\xi$, we have\n\\begin{align*}\n\\int_{x_{p-1}}^{x_p}\\bigl|(f-\\mathcal{Q}_rf)^{(k)}(x)\\bigr|^2\\,dx\n&=h_p^{1-2k}\\int_0^1\\bigl|\\bigl(\\hat f-\\widehat{Q}_r\\hat f)(\\xi)\\bigr|^2\\,d\\xi\\\\\n&\\le h_p^{1-2k}\\biggl(\n    \\int_0^1\\int_0^1|\\partial_\\xi^kK_r(\\xi,\\eta)|^2\\,d\\eta\\,d\\xi\\biggr)\n    \\biggl(\\int_0^1|\\hat f^{(r+1)}(\\eta)|^2\\,d\\eta\\biggr),\n\\end{align*}\nand \n\\[\n\\int_0^1|\\hat f^{(r+1)}(\\eta)|^2\\,d\\eta=\\int_{x_{p-1}}^{x_p}\n    |h_p^{r+1}f^{(r+1)}(y)|^2h_p^{-1}\\,dy,\n\\]\nwhich implies the desired estimate.\n\\end{proof}\n\nFor any continuous~$v:[0,L]\\to\\mathbb{R}$ we define $\\mathcal{Q}_{r,h}v$, the \n\\emph{piecewise-polynomial interpolant} of degree at most~$r$, by\n\\[\n(\\mathcal{Q}_{r,h}v)(x)\n    =(\\mathcal{Q}_r\\brak{p}v)(x)\\quad\\text{for $x\\in[x_{p-1},x_p]$;}\n\\]\nsince $\\mathsf{n}\\brak{p-1}_{r+1}=x_{p-1}=\\mathsf{n}\\brak{p}_1$ we see \nthat\n\\[\n(\\mathcal{Q}_r\\brak{p-1}v)(x_{p-1})=v(x_{p-1})\n    =(\\mathcal{Q}_r\\brak{p}v)(x_{p-1})\\quad\\text{for~$2\\le p\\le P-1$,}\n\\]\nand hence the function~$\\mathcal{Q}_{r,h}v$ is continuous on~$[0,L]$.\n\n\\begin{theorem}\\label{thm: Q r h}\nIf $v$ is $C^{r+1}$ on~$[0,L]$, then\n\\[\n\\|v-\\mathcal{Q}_{r,h}v\\|_{L_2(0,L)}\n    \\le\\sqrt{C_{r,0}}\\,h^{r+1}\\|v^{(r+1)}\\|_{L_2(0,L)}\n\\]\nand\n\\[\n\\|v'-(\\mathcal{Q}_{r,h}v)'\\|_{L_2(0,L)}\n    \\le\\sqrt{C_{r,1}}\\,h^r\\|v^{(r+1)}\\|_{L_2(0,L)}.\n\\]\n\\end{theorem}\n\\begin{proof}\nWe have\n\\begin{align*}\n\\|v-\\mathcal{Q}_{r,h}v\\|_{L_2(0,L)}^2\n    &=\\int_0^L|(v-\\mathcal{Q}_{r,h}v)(x)|^2\\,dx=\\sum_{p=1}^P\n    \\int_{x_{p-1}}^{x_p}|(v-\\mathcal{Q}_r\\brak{p}v)(x)|^2\\,dx\\\\\n    &\\le\\sum_{p=1}^P C_{r,0}h_p^{2(r+1)}\\int_{x_{p-1}}^{x_p}\n        |\\hat v^{(r+1)}(x)|^2\\,dx\\\\\n    &\\le C_{r,0}h^{2(r+1)}\\sum_{p=1}^M\\int_{x_{p-1}}^{x_p} \n        |\\hat v^{(r+1)}(x)|^2\\,dx\n    =C_{r,0}h^{2(r+1)}\\|v^{(r+1)}\\|_{L_2(0,L)}^2,\n\\end{align*}\nwhich proves the first estimate.  The second follows in the same way.\n\\end{proof}\n\n\\section{Optimality property}\nSubtracting \\eqref{eq: <u,v>A} from~\\eqref{eq: <uh,v>A}, we see that the\nerror~$e_h=u_h-u$ in the finite element solution is energy-orthogonal to the \ntest space~$T_h$, that is, \n\\begin{equation}\\label{eq: energy orthog}\n\\iprod{e_h,v}_{\\mathcal{L}}=0\\quad\\text{for all $v\\in T_h$.}\n\\end{equation}\nUsing this property, we show in the next theorem that $u_h$ is the best \napproximation to~$u$ by a function in the trial space~$S_h$, as measured by \nthe energy norm.\n\n\\begin{theorem}\\label{thm: optimality}\nThe finite element solution~$u_h\\in S_h$ satisfies\n\\[\n\\|u_h-u\\|_{\\mathcal{L}}\\le\\|w-u\\|_{\\mathcal{A}}\n\t\\quad\\text{for all $w\\in S_h$.}\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $w\\in S_h$ and observe that the error~$e_h=u_h-u$ satisfies\n\\begin{align*}\n\\|e_h\\|_{\\mathcal{L}}^2=\\iprod{e_h,e_h}_{\\mathcal{A}}\n\t&=\\iprod{e_h,u_h-u}_{\\mathcal{L}}\n\t=\\iprod{e_h,u_h-w+w-u}_{\\mathcal{L}}\\\\\n\t&=\\iprod{e_h,u_h-w}_{\\mathcal{L}}+\\iprod{e_h,w-u}_{\\mathcal{A}}.\n\\end{align*}\nSince $(u_h-w)(0)=u_h(0)-w(0)=\\gamma_0-\\gamma_0=0$ we see that $u_h-w\\in T_h$\nand so the energy-orthogonality property~\\eqref{eq: energy orthog} implies\nthat $\\iprod{e_h,u_h-w}_{\\mathcal{L}}=0$.  Hence, by the Cauchy--Schwarz\ninequality,\n\\[\n\\|e_h\\|_{\\mathcal{L}}^2=\\iprod{e_h,w-u}_{\\mathcal{A}}\n\t\\le\\|e_h\\|_{\\mathcal{L}}\\|w-u\\|_{\\mathcal{A}},\n\\]\nwhich implies the desired inequality.\n\\end{proof}\n\nBy combining \\cref{thm: optimality} with the approximation property of the \ninterpolant~$\\mathcal{Q}_{r,h}u$ proved in \\cref{thm: Q r h}, we can show\nthat the finite element error, measured in the energy norm, is $O(h^r)$.\n\n\\begin{theorem}\\label{thm: uh-u L}\nAssume that the solution~$u:[0,L]\\to\\mathbb{R}$ of the boundary-value \nproblem~\\eqref{eq: self-adjoint mixed} is~$C^{r+1}$.  Then,\nthere is a constant~$C>0$, independent of~$h$, such that\n\\[\n\\|u_h-u\\|_{\\mathcal{L}}\\le Ch^r\\|u^{(r+1)}\\|.\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $w=\\mathcal{Q}_{r,h}u$.  Since $w(0)=u(0)=\\gamma_0$ we see that $w\\in S_h$,\nso we may apply \\cref{thm: optimality} and deduce that\n\\begin{align*}\n\\|u_h-u\\|_{\\mathcal{L}}^2\\le\\|w-u\\|_{\\mathcal{A}}^2\n\t&\\le a_{\\max}\\|w'-u'\\|^2+c_{\\max}\\|w-u\\|^2\\\\\n\t&\\le\\bigl(a_{\\max}C_{r,1}h^{2r}+c_{\\max}C_{r,0}h^{2r+2}\\bigr)\n\t\\|u^{(r+1)}\\|^2\\\\\n\t&=\\bigl(a_{\\max}C_{r,1}+c_{\\max}C_{r,0}h^2\\bigr)\n\t\\bigl(h^r\\|v^{(r+1)}\\|\\bigr)^2,\n\\end{align*}\nwhich implies the result since $h$ is bounded.\n\\end{proof}\n\\begin{corollary}\n$\\|u_h'-u'\\|\\le Ch^r\\|u^{(r+1)}\\|$.\n\\end{corollary}\n\\begin{proof}\nObserve that since $a(x)/a_{\\min}\\ge1$,\n\\[\n\\|v'\\|^2=\\int_0^L|v'(x)|^2\\,dx\\le\\int_0^L\\frac{a(x)}{a_{min}}\\,|v'(x)|^2\\,dx\n\t=\\frac{1}{a_{\\min}}\\int_0^La(x)|v'(x)|^2\\,dx\n\t\\le\\frac{\\|v\\|_{\\mathcal{L}}^2}{a_{\\min}},\n\\]\nand in particular $\\|u_h'-u'\\|^2\\le\\|u_h-u\\|^2_{\\mathcal{L}}/a_{min}$.\n\\end{proof}\n\nIn some applications, an integral of the form\n\\[\n\\iprod{\\phi,u}=\\int_0^L\\phi(x)u(x)\\,dx\n\\]\nis of interest.  The next theorem shows that if $\\phi\\in H^r(0,L)$~and \n$u\\in H^{r+1}(0,L)$, then\n\\[\n\\iprod{\\phi,u_h}=\\iprod{\\phi,u}+O(h^{2r+1}).\n\\]\n\n\\begin{theorem}\nIf $0\\le k\\le r$, then\n\\[\n|\\iprod{u_h-u,\\phi}|\\le Ch^{k+1}\\|\\phi\\|_{H^k(0,L)}\\|u_h-u\\|_{\\mathcal{L}}.\n\\]\n\\end{theorem}\n\\begin{proof}\nGiven $\\phi$, let $\\theta$ be the solution of the boundary-value problem\n\\[\n\\mathcal{L}\\theta=\\phi(x)\\quad\\text{for $0<x<L$,}\n\t\\quad\\text{with $\\theta(0)=0$ and $a(L)\\theta'(L)=0$,}\n\\]\nso that\n\\[\n\\iprod{\\theta,v}_{\\mathcal{L}}=\\iprod{\\phi,v}\\quad\\text{whenever $v(0)=0$.}\n\\]\nSince $(u_h-u)(0)=u_h(0)-u(0)=\\gamma_0-\\gamma_0=0$, it follows that\n\\[\n\\iprod{\\phi,u_h-u}=\\iprod{\\theta,u_h-u}_{\\mathcal{L}}\n\t=\\iprod{\\theta-Q_{k+1,h}\\theta,u_h-u}_{\\mathcal{L}},\n\\]\nwhere, in the second step, we used the fact that $u_h-u$ is energy-orthogonal\nto $Q_{k+1,h}\\theta\\in T_h$ because $k\\le r$.  Hence, by the Cauchy--Schwarz \ninequality,\n\\[\n|\\iprod{\\phi,u_h-u}|\\le\\|\\theta-Q_{k+1,h}\\theta\\|_{\\mathcal{L}}\n\t\\|u_h-u\\|_{\\mathcal{L}}.\n\\]\nSince\n\\[\n\\|\\theta-\\mathcal{Q}_{k+1,h}\\theta\\|_{\\mathcal{L}}^2\n\t\\le a_{\\max}\\|\\theta'-(\\mathcal{Q}_{k+1,h}\\theta)'\\|\n\t+c_{\\max}\\|\\theta-\\mathcal{Q}_{k+1,h}\\theta\\|\n\t\\le C\\bigl(h^{k+1}+h^{k+2})\\|\\theta^{(k+2)}\\|\n\\]\nit suffices to show, using induction on~$k$, that \n$\\|\\theta^{(k+2)}\\|\\le C\\|\\phi\\|_{H^k(0,L)}$.  \nRearranging the ODE $a\\theta''+c\\theta=\\phi$,  and using \\cref{lem: v v'} \nfollowed by~\\cref{thm: ||u||A},\n\\[\n\\|\\theta''\\|=\\|(\\phi-c\\theta)/a\\|\n\t\\le\\frac{\\|\\phi\\|+c_{\\max}\\|\\theta\\|}{a_{\\min}}\\le C\\|\\phi\\|\n\t\\le C(\\|\\phi\\|+\\|\\theta\\|_{\\mathcal{L}})\\le C\\|\\phi\\|,\n\\]\nwhich proves the claim for~$k=0$.  For the inductive step, we let~$k\\ge1$ and\nassume that \n\\[\n\\|\\theta^{(j+2)}\\|\\le C\\sum_{l=0}^j\\|\\phi^{(l)}\\|\n\t\\quad\\text{for~$0\\le j\\le k-1$.}\n\\]\nBy $k$-fold differentiation of $a\\theta''+c\\theta=\\phi$, \n\\[\na\\theta^{(k+2)}+c\\theta^{(k)}+\\sum_{j=0}^{k-1}\\binom{k}{j}\\bigl(\n\ta^{(k-j)}\\theta^{(j+2)}+c^{(k-j)}\\theta^{(j)}\\bigr)=\\phi^{(k)}\n\\]\nso\n\\[\n\\theta^{(k)}=\\frac{1}{a}\\bigg(\\phi^{(k)}-c\\theta^{(k)}\n\t-\\sum_{j=0}^{k-1}\\binom{k}{j}\\bigl(\n\ta^{(k-j)}\\theta^{(j+2)}+c^{(k-j)}\\theta^{(j)}\\bigr)\\biggr)\n\\]\nand\n\\[\n\\|\\theta^{(k)}\\|\\le C\\biggl(\\|\\phi^{(k)}\\|+\\|\\theta\\|+\\|\\theta'\\|\n\t+\\sum_{j=2}^{k+1}\\|\\theta^{(j)}\\|\\biggr)\n\\le C\\biggl(\\|\\phi^{(k)}\\|+\\|\\theta\\|_{\\mathcal{L}}\n\t+\\sum_{j=0}^{k-1}\\|\\theta^{(j+2)}\\|\\biggr),\n\\]\nimplying that the induction goes through.\n\\end{proof}\n\n\\begin{corollary}\n$\\|u_h-u\\|\\le Ch^{r+1}\\|u^{(r+1)}\\|$.\n\\end{corollary}\n\\begin{proof}\nApply \\cref{thm: uh-u L} with $\\phi=u_h-u$~and $k=0$ to obtain\n\\[\n\\|u_h-u\\|^2=\\iprod{u_h-u,u_h-u}\\le Ch\\|u_h-u\\|\\|u_h-u\\|_{\\mathcal{L}}\n\t\\le Ch\\|u_h-u\\|h^r\\|u^{(r+1)}\\|,\n\\]\nwhich implies the result.\n\\end{proof}\n\n\\section{Sturm--Liouville problems}\\label{sec: Sturm-Liouville}\n\nWe will now consider a Sturm--Liouville equation,\n\\begin{equation}\\label{eq: Sturm Liouville ODE}\n-\\bigl(a(x)\\phi'\\bigr)'+\\bigl(c(x)-\\lambda b(x)\\bigr)\\phi=0\\quad\n\t\\text{for $0<x<L$,}\n\\end{equation}\nsubject to (homogeneous) mixed boundary conditions\n\\begin{equation}\\label{eq: Sturm Liouville bc}\n\\phi(0)=0\\quad\\text{and}\\quad a(L)\\phi'(L)=0.\n\\end{equation}\nIn addition to assuming that the leading coefficient~$a(x)$ \nsatisfies~\\eqref{eq: ellipticity 1d}, we require that\n\\begin{equation}\\label{eq: b>0}\nb(x)>0\\quad\\text{for $0<x<L$.}\n\\end{equation}\nA non-trivial solution~$\\phi=\\phi(x)$ is said to an \\emph{eigenfunction} and \n$\\lambda$ is then the corresponding \\emph{eigenvalue}.  \n\nThe ODE~\\eqref{eq: Sturm Liouville ODE} can be written as\n\\[\n\\mathcal{L}\\phi=\\lambda b\\phi,\n\\]\nwhere the self-adjoint differential operator~$\\mathcal{L}$ is again given \nby~\\eqref{eq: L self-adjoint}.  Recalling the \nidentity~\\eqref{eq: Lu v by parts}, we see that any \\emph{eigenpair} \n$(\\phi,\\lambda)$ satisfies, for any test function~$v$,\n\\[\n\\int_0^L\\bigl(a(x)\\phi'(x)v(x)+c(x)\\phi(x)v(x)\\bigr)\\,dx\n\t=\\lambda\\int_0^Lb(x)\\phi(x)v(x)\\,dx\n\\quad\\text{provided $v(0)=0$.}\n\\]\n\nLet $V_h$ denote the continuous, piecewise-quadratic finite element space \ndiscussed in Section~\\ref{sec: quadratic elements}, and put\n\\[\nS_h=T_h=\\{\\,v\\in V_h:v(0)=0\\,\\}.\n\\]\nWe seek an approximate eigenfunction~$\\phi_h\\in S_h$ and corresponding \napproximate eigenvalue~$\\lambda_h$ such that\n\\[\n\\int_0^L\\bigl(a(x)\\phi_h'(x)v(x)+c(x)\\phi_h(x)v(x)\\bigr)\\,dx\n\t=\\lambda\\int_0^Lb(x)\\phi_h(x)v(x)\\,dx\n\\quad\\text{for all $v\\in T_h$.}\n\\]\nLet $\\chi_1$, $\\chi_2$, \\dots, $\\chi_{2P+1}$ be the nodal basis for~$V_h$, so \nthat\n\\[\n\\chi_r(\\mathsf{n}_s)=\\delta_{rs}\n\t\\quad\\text{for $r$, $s\\in\\{1,2,\\ldots, 2P+1\\}$,}\n\\]\nand thus, since $\\phi_h(\\mathsf{n}_{2P+1})=\\phi_h(x_0)=\\phi_h(0)=0$,\n\\[\n\\phi_h(x)=\\sum_{s=1}^{2P}\\Phi_s\\chi_s(x)\n\t\\quad\\text{for $0\\le x\\le L$},\n\t\\quad\\text{where $\\Phi_s=\\phi_h(\\mathsf{n}_s)$.}\n\\]\nChoosing $v=\\chi_r$ we see that\n\\[\n\\sum_{k=1}^{2P}\\bigl(a_{rs}+c_{rs}\\bigr)\\Phi_s\n\t=\\lambda_h\\sum_{s=1}^{2P}b_{rs}\\Phi_s\\quad\\text{for $1\\le r\\le 2P$,}\n\\]\nwhere\n\\[\na_{rs}=\\int_0^La(x)\\chi'_s(x)\\chi'_r(x)\\,dx,\\qquad\nc_{rs}=\\int_0^Lc(x)\\chi_s(x)\\chi_r(x)\\,dx,\n\\]\nand\n\\[\nb_{rs}=\\int_0^Lb(x)\\chi_s(x)\\chi_r(x)\\,dx.\n\\]\nIn this way, we obtain a $(2P)\\times(2P)$ \\emph{generalised algebraic \neigenproblem},\n\\[\n\\bigl(\\boldsymbol{A}+\\boldsymbol{C}\\bigr)\\boldsymbol{\\Phi}\n\t=\\Lambda\\boldsymbol{B}\\boldsymbol{\\Phi},\n\\]\nwhere $\\boldsymbol{A}=[a_{rs}]_{r,s=1}^{2P}$, \n$\\boldsymbol{C}=[c_{rs}]_{r,s=1}^{2P}$, \n$\\boldsymbol{B}=[b_{rs}]_{r,s=1}^{2P}$, \n$\\boldsymbol{\\Phi}=[\\Phi_s]_{s=1}^{2P}$~and \n$\\Lambda=\\lambda_h$.  Each of the three matrices is real and symmetric, and our \nassumptions \\eqref{eq: ellipticity 1d}~and \\eqref{eq: b>0} on the coefficients \n$a(x)$~and $b(x)$ ensure that $\\boldsymbol{A}$~and $\\boldsymbol{B}$ are \nstrictly positive-definite.  It follows that there exist eigenpairs \n$(\\Phi_s,\\Lambda_s)$ for~$1\\le s\\le 2P$, with\n\\[\n\\Lambda_1\\le\\Lambda_2\\le\\cdots\\le\\Lambda_{2P},\\qquad\n\\boldsymbol{\\Phi}_r^T(\\boldsymbol{A}+\\boldsymbol{C})\n    \\boldsymbol{\\Phi}_s=\\Lambda_s\\delta_{rs},\\qquad\n\\boldsymbol{\\Phi}_r^T\\boldsymbol{B}\\boldsymbol{\\Phi}_s=\\delta_{rs}.\n\\]\nFor a practical implementation, it is simpler to assemble $\\boldsymbol{A}$, \n$\\boldsymbol{B}$~and $\\boldsymbol{C}$ from the corresponding element matrices\n$\\boldsymbol{A}\\brak{p}$, $\\boldsymbol{B}\\brak{p}$~and \n$\\boldsymbol{C}\\brak{p}$; see Exercise \\ref{ex: assemble quadratic 1d}~(iii).\n\n\\begin{Exercises}\n\n\\exercise\\label{ex: V_h vector space}\nProve that the set~$V_h$ of continuous, piecewise-linear functions is a vector \nspace.\n\n\\exercise\nShow that the trial set~\\eqref{eq: Sh 1D} is a \\emph{convex subset} of~$V_h$,\nthat is, if $v$, $w\\in S_h$ then $\\lambda v+\\mu w\\in S_h$ for all $\\lambda\\ge0$\nand $\\mu\\ge0$ such that $\\lambda+\\mu=1$.\n\n\\exercise\nProve that $\\{\\chi_p\\}_{p=0}^P$ is a basis for~$V_h$, and that \n$\\{\\chi_p\\}_{p=1}^{P-1}$ is a basis for~$T_h$.\n\n\\exercise\nConsider the model problem~\\eqref{eq: model 1d chap 2}.  Define a uniform \nmesh~$x_p=ph$ on~$[0,L]$ for $0\\le p\\le P=M$ where $h=\\Delta x=L/P$.  Denote \nthe finite difference solution by~$U^{\\mathrm{d}}_p\\approx u(x_p)$, and denote \nthe nodal values of the piecewise-linear finite element solution \nby~$U^{\\mathrm{e}}_p=u_h(x_p)\\approx u(x_p)$.  Let \n\\[\nf^{\\,\\mathrm{d}}_p=f(x_p)\\quad\\text{and}\\quad\nf^{\\,\\mathrm{e}}_p=\\frac{1}{h}\\int_{x_{p-1}}^{x_{p+1}}f(x)\\chi_p(x)\\,dx\n\\quad\\text{for $1\\le p\\le P-1$,}\n\\]\nwhere $\\chi_p$ is the $p$th piecewise-linear nodal basis function (that is, the \n``hat function'' centred on~$x_p$).  Let\n\\[\n\\boldsymbol{A}=\\frac{1}{h^2}\\left[\\begin{array}{rrrrr}\n 2&    -1&      &      &\\\\\n-1&     2&    -1&      &\\\\\n  &\\ddots&\\ddots&\\ddots&\\\\\n  &      &    -1&     2&-1\\\\\n  &      &      &    -1& 2\n\\end{array}\\right],\\quad\n\\boldsymbol{f}^{\\,\\mathrm{d}}=\\begin{bmatrix}\nf^{\\,\\mathrm{d}}_1\\\\                              \nf^{\\,\\mathrm{d}}_2\\\\                              \n\\vdots\\\\\nf^{\\,\\mathrm{d}}_{P-2}\\\\                              \nf^{\\,\\mathrm{d}}_{P-1}                              \n\\end{bmatrix},\\quad\n\\boldsymbol{g}=\\frac{1}{h^2}\\begin{bmatrix}\n\\gamma_0\\\\ 0\\\\ \\vdots\\\\ 0\\\\ \\gamma_L                            \n\\end{bmatrix},\n\\]\nso that $\\boldsymbol{A}\\boldsymbol{U}^{\\mathrm{d}}=\\boldsymbol{f}^{\\,\\mathrm{d}}\n+\\boldsymbol{g}$ as in~\\eqref{eq: model 1d linear system}.\n\\begin{description}\n\\item{(i)} Show that $\\boldsymbol{A}\\boldsymbol{U}^{\\mathrm{e}}\n=\\boldsymbol{f}^{\\,\\mathrm{e}}+\\boldsymbol{g}$.\n\\item{(ii)} By applying Theorem~\\ref{thm: discrete apriori 1D} to the finite \ndifference equation satisfied by $U^{\\mathrm{e}}_p-U^{\\mathrm{d}}_p$, deduce \nthat\n\\[\n\\max_{0\\le p\\le P}\\bigl|U^{\\mathrm{e}}_p-U^{\\mathrm{d}}_p\\bigr|\n    \\le\\frac{L^2}{8}\\,\\max_{1\\le p\\le P-1}\n    \\bigl|f^{\\,\\mathrm{e}}_p-f^{\\,\\mathrm{d}}_p\\bigr|.\n\\]\n\\item{(iii)}\nLet $\\delta_pf=f^{\\,\\mathrm{e}}_p-f^{\\,\\mathrm{d}}_p$, and\nverify that $\\delta_pf=0$ for all $f\\in\\mathbb{P}_1$.\n(Hint: consider $f(x)=1$ and $f(x)=x-x_p$.)\n\\item{(iv)}\nBy applying $\\delta_p$ to the Taylor expansion\n\\[\nf(x)=f(x_{p-1})+f'(x_{p-1})(x-x_{p-1})+\\int_{x_{p-1}}^x\n\t(x-y)f''(y)\\,dy,\n\\]\nshow that \n\\[\n\\delta_pf=\\int_{x_{p-1}}^{x_{p+1}} K_p(y)f''(y)\\,dy\n\\]\nwhere, using the notation~\\eqref{eq: pi r y},\n\\[\nK_p(y)=\\delta_p\\pi_{1,y}=\\frac{1}{6h^2}\\times\\begin{cases}\n        (y-x_{p-1})^3,&x_{p-1}<y<x_p,\\\\\n        (x_{p+1}-y)^3,&x_p<y<x_{p+1}.\n\\end{cases}\n\\]\n\\item{(v)}\nDeduce using the Integral Mean Value Theorem that\n\\[\nf^{\\,\\mathrm{e}}_p-f^{\\,\\mathrm{d}}_p=\\frac{h^2}{12}\\,f''(\\xi)\n\\quad\\text{for some $\\xi\\in[x_{p-1},x_{p+1}]$,}\n\\]\nand hence conclude that the finite difference and finite element solutions \nagree to~$O(h^2)$.\n\\end{description}\n\n\\exercise\nConsider a differential operator $\\mathcal{L}u=-(au')'+bu'+cu$.  The term in \n$u'$ means that $\\mathcal{L}$ is not self-adjoint (assuming $b$ is not \nidentically zero), and the weak formulation of the mixed boundary-value \nproblem~\\eqref{eq: self-adjoint mixed} changes from~\\eqref{eq: Lu=f weak 1d} to\n\\[\n\\int_0^L\\bigl(au'v'+bu'v+cuv\\bigr)\\,dx\n    =\\gamma_Lv(L)+\\int_0^Lfv\\,dx\\quad\\text{provided $v(0)=0$,}\n\\]\nwith $u(0)=\\gamma_0$, and the linear \nsystem~\\eqref{eq: self-adjoint mixed equations} is now of the form\n\\[\n\\bigl(\\boldsymbol{A}+\\boldsymbol{B}+\\boldsymbol{C}\\bigr)\\boldsymbol{U}\n    =\\boldsymbol{f}+\\boldsymbol{g}.\n\\]\n\\begin{description}\n\\item{(i)} Why does the energy inner product no longer make sense.\n\\item{(ii)} How are the entries $b_{pq}$ of the matrix~$\\boldsymbol{B}$ defined \nin terms of the nodal basis functions~$\\chi_p$?\n\\item{(iii)} Assume now that $b(x)\\equiv1$ and we use piecewise-linear elements.\n\\begin{description}\n\\item{(a)} Show that \n$b_{pq}+b_{qp}=\\delta_{Pq}\\delta_{Pp}-\\delta_{0q}\\delta_{0p}$.\n\\item{(b)} Hence find the diagonal entries $b_{pp}$ for $1\\le p\\le P$, and\nthe off-diagonal entries $b_{p,p-1}$~and $b_{p-1,p}$ for $2\\le p\\le P$.\n\\item{(c)} Write out $\\boldsymbol{B}$ in the case $P=5$.\n\\end{description}\n\\end{description}\n\\begin{ans}\n(ii) $b_{pq}=\\int_0^Lb(x)\\phi_q'(x)\\phi_p(x)\\,dx$\\\\\n(iii) (b) $b_{00}=-1/2$, $b_{pp}=0$ for~$1\\le p\\le P-1$, $b_{PP}=1/2$\\\\\n$b_{p,p-1}=-1/2$ and $b_{p-1,p}=1/2$ for $1\\le p\\le P$\n(c) $\\boldsymbol{B}=\\frac{1}{2}\\begin{bmatrix}\n 0& 1& 0& 0&0\\\\\n-1& 0& 1& 0&0\\\\\n 0&-1& 0& 1&0\\\\\n 0& 0&-1& 0&1\\\\\n 0& 0& 0&-1&1\\end{bmatrix}$\n\\end{ans}\n\n\n\\exercise\nCheck that the energy inner product~\\eqref{eq: energy iprod} is in fact an \ninner product on the vector space of $C^1$ functions $v:[0,L]\\to\\mathbb{R}$ \nsatisfying $v(0)=0$, by checking that for all such functions\n\\begin{description}\n\\item{(i)} $\\iprod{v,w}_{\\mathcal{L}}$ is linear in~$v$ for fixed $w$, and\nvice versa.\n\\item{(ii)} $\\iprod{v,w}_{\\mathcal{L}}=\\iprod{w,v}_{\\mathcal{L}}$.\n\\item{(iii)} $\\iprod{v,v}_{\\mathcal{L}}\\ge0$.\n\\item{(iv)} If $\\iprod{v,v}_{\\mathcal{L}}=0$ then $v\\equiv0$.\n\\end{description}\nAssume throughout that $c(x)\\ge0$ for all~$x$.\n\n\\exercise\\label{ex: quadratic DoF 1d}\nVerify that the quadratic shape functions~\\eqref{eq: quadratic psi 1d} on the \n$p$th element~$[x_{p-1},x_p]$ satisfy \\eqref{eq: quadratic DoF 1d}.\n\n\\exercise\nRecall the formulae \\eqref{eq: a reference 1d}~and\n\\eqref{eq: c reference 1d} for the element stiffness and mass matrices using \nthe quadratic shape functions~\\eqref{eq: quadratic shape funcs 1d} on the \nreference element~$[0,1]$.  Assume that $a(x)=1$ and $c(x)=1$.\n\\begin{description}\n\\item{(i)} Verify that $\\Psi_3(1-\\xi)=\\Psi_1(\\xi)$ and \n$\\Psi_2(1-\\xi)=\\Psi_2(\\xi)$.\n\\item{(ii)} What can you conclude about the first derivatives $\\Psi_j'$?\n\\item{(iii)} Deduce that\n$a\\brak{p}_{11}=a\\brak{p}_{33}$, $a\\brak{p}_{12}=a\\brak{p}_{32}$,\n$c\\brak{p}_{11}=c\\brak{p}_{33}$, $c\\brak{p}_{12}=c\\brak{p}_{32}$.\n\\item{(iv)} Verify the formulae \\eqref{eq: element matrices quadratic 1d}\nfor the element stiffness and mass matrices.\n\\end{description}\n\\begin{ans}\n(ii) $\\Psi_1'(\\xi)=-\\Psi_3'(1-\\xi)$ and $\\Psi_2'(\\xi)=-\\Psi_2'(1-\\xi)$.\n\\end{ans}\n\n\n\\begin{figure}\n\\caption{The Peano kernel $K(y)$ for the quadrature rule of \nExercise~\\ref{ex: quadrature kernel}.}\\label{fig: quadrature kernel}\n\\begin{center}\n\\includegraphics[scale=0.5]{../src/chap2/quadrature_kernel.pdf}\n\\end{center}\n\\end{figure}\n\n\\exercise\\label{ex: quadrature kernel}\nConsider a quadrature rule of the form\n\\[\n\\int_{-1}^1f(x)\\,dx\\approx w_1f(-1)+w_2f(-a)+w_2f(a)+w_1f(1)\n\\quad\\text{with $0<a<1$,}\n\\]\nand denote the error by\n\\[\nEf=\\int_{-1}^1f(x)\\,dx-\\bigl(w_1f(-1)+w_2f(-a)+w_2f(a)+w_1f(1)\\bigr).\n\\]\n\\begin{description}\n\\item{(i)} Why does $Ef=0$ if $f$ is an odd function, that is, if\n$f(-x)=-f(x)$?\n\\item{(ii)} Simplify $Ef$ in the case when $f$ is an even function, that is, \nwhen $f(-x)=f(x)$. \\item{(iii)}\nDetermine the values of $w_1$, $w_2$~and $a$ for which $Ef=0$ whenever\n$f\\in\\mathbb{P}_5$.\n\\item{(iv)}\nDeduce that there is a Peano kernel~$K$ such that, if $f$ is $C^6$ \non~$[-1,1]$, then the rule given by part~(iii) has the error formula\n\\[\nEf=\\int_{-1}^1K(y)f^{(6)}(y)\\,dy.\n\\]\nExpress $K(y)$ in terms of the function $\\pi_{5,y}(x)$ defined as \nin~\\eqref{eq: pi r y}.\n\\item{(v)}\nWrite a script to verify that the graph of~$K$ is as shown in \nFigure~\\ref{fig: quadrature kernel}.\n\\item{(vi)}\nBy considering the function~$f(x)=x^6$, show that \n\\[\n\\int_{-1}^1K(y)\\,dy=\\frac{-32}{525}.\n\\]\n\\item{(vii)}\nHence determine the constant~$c$ such that, given a $C^6$ function~$f$,\nthere is a $\\xi\\in[-1,1]$ for which $Ef=cf^{(6)}(\\xi)$.\n\\end{description}\n\\begin{ans}\n(i) both sides equal $0$\\quad (ii) $\\int_0^1f(x)\\,dx=w_1f(1)+w_2f(a)$\\\\\n(iii) $a=1/\\sqrt{5}$, $w_1=1/6$, $w_2=5/6$.\\\\\n(iv) $K(y)=\\pi_{6,y}(1)-\\bigl(w_2\\pi_{5,y}(-a)+w_2\\pi_{5,y}(a)\n+w_1\\pi_{5,y}(1) \\bigr)$\\\\\n(vi) $c=\\dfrac{-32}{6!\\times525}=\\dfrac{-2}{23,625}$.\n\\end{ans}\n\n\\exercise\nRepeat the steps of Exercise~\\ref{ex: quadrature kernel} for a quadrature rule\nof the form\n\\[\n\\int_{-1}^1 f(x)\\,dx\\approx w_1f(-a)+w_2f(0)+w_1f(a).\n\\]\n\\begin{ans}\n$w_1=5/9$, $w_2=8/9$, $a=\\sqrt{3/5}$.\n\\end{ans}\n\n\n\\exercise\\label{ex: assemble quadratic 1d}\nConsider the two-point boundary-value problem~\\eqref{eq: self-adjoint mixed} \nwhere $\\mathcal{L}$ is of the form~\\eqref{eq: L self-adjoint}, and let\n\\[\nL=2,\\qquad a(x)=1,\\qquad c(x)=0,\\qquad f(x)=18.\n\\]\n\\begin{description}\n\\item{(i)} Suppose we take a uniform mesh with~$P=6$ subintervals and apply the \nfinite element method using quadratic elements.  Write down the connectivity \nmatrix~$\\boldsymbol{T}=[t_{jp}]$, the stiffness matrix~$\\boldsymbol{A}$ and \nthe load vector~$\\boldsymbol{f}$. Hint: adapt the approach used in \nExample~\\ref{example: assemble A} for piecewise-linear elements.\n\\item{(ii)} How do the boundary data $\\gamma_0$~and $\\gamma_L$ enter into the \nlinear system for the nodal vector?\n\\item{(iii)} Formulate an algorithm to assemble the stiffness matrix for a \ngeneral~$P$.  Hint: adapt Algorithm~\\ref{alg: assemble A piecewise linear}.\n\\end{description}\n\\begin{ans}\n(i) \n\\begin{gather*}\n\\boldsymbol{T}=\\begin{bmatrix}\n13& 2& 4& 6& 8&10\\\\\n 1& 3& 5& 7& 9&11\\\\\n 2& 4& 6& 8&10&12\n\\end{bmatrix},\\\\\n\\boldsymbol{A}=\\left[\\begin{array}{cccccccccccc|c}\n16&-8&  &  &  &  &  &  &  &  &  &  &-8\\\\\n-8&14&-8& 1&  &  &  &  &  &  &  &  & 1\\\\\n  &-8&16&-8&  &  &  &  &  &  &  &  &  \\\\\n  & 1&-8&14&-8& 1&  &  &  &  &  &  &  \\\\\n  &  &  &-8&16&-8&  &  &  &  &  &  &\\\\\n  &  &  & 1&-8&14&-8& 1&  &  &  &  &  \\\\\n  &  &  &  &  &-8&16&-8&  &  &  &  &  \\\\\n  &  &  &  &  & 1&-8&14&-8& 1&  &  &  \\\\\n  &  &  &  &  &  &  &-8&16&-8&  &  &  \\\\\n  &  &  &  &  &  &  & 1&-8&14&-8& 1&  \\\\\n  &  &  &  &  &  &  &  &  &-8&16&-8&  \\\\\n  &  &  &  &  &  &  &  &  & 1&-8& 7&\n\\end{array}\\right],\\quad\n\\boldsymbol{f}=\\left[\\begin{array}{c}\n4\\\\ 2\\\\ 4\\\\ 2\\\\ 4\\\\ 2\\\\ 4\\\\ 2\\\\ 4\\\\ 2\\\\ 4\\\\ 1\n\\end{array}\\right].\n\\end{gather*}\n(ii) $\\boldsymbol{A}'\\boldsymbol{U}'=\\boldsymbol{f}-\\gamma_0\\boldsymbol{A}''\n+\\gamma_L\\boldsymbol{e}_{2M}$\\\\\n(iii)\n\\begin{algorithmic}\n\\State Allocate storage for \n$\\boldsymbol{A}=[a_{jk}]\\in\\mathbb{R}^{(2M)\\times(2M+1)}$ \n\\For{$r=1:2P$}\n    \\For{$s=1:2P+1$}\n        \\State $a_{rs}=0$ \n    \\EndFor\n\\EndFor\n\\For{$p=1:P$}\n    \\State Compute $\\boldsymbol{A}\\brak{p}$ \n    \\For{$j=1:3$}\n        \\State $r=e_{jp}$\n        \\If{$r\\le2P$}\n            \\For{$k=1:3$}\n                \\State $s=t_{kp}$\n                \\State $a_{rs}\\gets a_{rs}+a\\brak{p}_{jk}$\n            \\EndFor\n        \\EndIf\n    \\EndFor\n\\EndFor\n\\end{algorithmic}\n\\end{ans}\n\n\\exercise\nShow that the Peano kernel for linear interpolation, discussed in \nExample~\\ref{example: linear interp}, satisfies\n\\[\n\\int_a^b K_1(x,y)\\,dy=\\frac{1}{2}\\,(x-a)(b-x)\\quad\\text{for $a\\le x\\le b$.}\n\\]\nHence use the integral mean value theorem to show that if~$f$ is $C^2$ \non~$[a,b]$, then \n\\[\n(\\mathcal{Q}_1f)(x)-f(x)=\\frac{f''(\\xi)}{2}\\,(x-a)(b-x)\n\\]\nfor some~$\\xi\\in[a,b]$ (depending on~$x$).\n\n\\exercise\nLet $x_1=-1$, $x_2=0$~and $x_3=+1$ as in \nExample~\\ref{example: quadratic interp}.  \n\\begin{description}\n\\item{(i)} Show that if $g(x)=f(-x)$, then \n$(\\mathcal{Q}_2g)(x)=(\\mathcal{Q}_2f)(-x)$.\n\\item{(ii)} Deduce that if $f$ is $C^3$ on~$[-1,1]$, then\n\\[\n\\int_{-1}^1K_2(-x,y)f'''(y)\\,dy=\\int_{-1}^1K_2(x,y)g'''(y)\\,dy\n\t\\quad\\text{for $-1\\le x\\le 1$.}\n\\]\n\\item{(iii)} Hence show that $K_2(-x,y)=-K_2(x,-y)$, in agreement \nwith~\\eqref{eq: K2 symmetry}.\n\\end{description}\n\n\\exercise\nSketch the graphs of the piecewise-quadratic nodal basis functions $\\chi_1$, \n$\\chi_2$, \\dots, $\\chi_{2P+1}$ used in section~\\ref{sec: Sturm-Liouville}\nfor the case~$P=4$.\n\n\\exercise\nLet $x_1=-1$, $x_2=0$, $x_3=1$, $x_4=2$ and consider the \nfunction~$f(x)=|x|$.\n\\begin{description}\n\\item{(i)} Find the corresponding Lagrange interpolation polynomials \n$\\ell_1(x)$, $\\ell_2(x)$, $\\ell_3(x)$ and $\\ell_4(x)$.\n\\item{(ii)} Hence write down $\\mathcal{I}_3f$, the cubic interpolant to~$f$.\n\\end{description}\n\\begin{ans}\n(i) $\\ell_1(x)=-\\tfrac16 x(x-1)(x-2)$, $\\ell_2(x)=\\tfrac12(x+1)(x-1)(x-2)$,\n$\\ell_3(x)=-\\tfrac12(x+1)x(x-2)$, $\\ell_4(x)=\\tfrac16(x+1)x(x-1)$.\\quad\n(ii) $(\\mathcal{I}_3f)(x)=\\ell_1(x)+\\ell_3(x)+2\\ell_4(x)$\n\\end{ans}\n\n\n\\end{Exercises}\n", "meta": {"hexsha": "059b42670fc2154b2fad85edb9105ba59e95d405", "size": 70518, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "texsrc/chap2.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/chap2.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/chap2.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.7053164557, "max_line_length": 80, "alphanum_fraction": 0.6263365382, "num_tokens": 31891, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872045877523147, "lm_q2_score": 0.8519528057272543, "lm_q1q2_score": 0.7558564377896765}}
{"text": "\\subsection{N-Hat $\\left(\\hat{N}\\right)$}\r\nStarting with the definition of $\\hat{T}(t)$,\r\n\\begin{align*}\r\n\t\\hat{T}(t) &= \\frac{\\vec{r^\\prime}(t)}{v(t)} \\\\\r\n\t\\vec{r^{\\prime}}(t) &= v(t)\\hat{T}(t) \\\\\r\n\t\\vec{r^{\\prime\\prime}}(t) &= v(t)\\hat{T}^{\\prime}(t)+\\hat{T}(t)v^{\\prime}(t).\r\n\\end{align*}\r\n\r\n\\noindent\r\nWe will show that $\\hat{T}(t) \\perp \\hat{T}^{\\prime}(t)$.\r\n\\begin{align*}\r\n\t\\frac{1}{2}\\dd{}{t}\\left(\\hat{T}(t)\\cdot\\hat{T}(t)\\right) &= \\hat{T}\\cdot\\hat{T}^{\\prime}(t) \\\\\r\n\t\\dd{}{t}\\left(\\hat{T}\\cdot\\hat{T}\\right) &= \\dd{}{t}1 = 0.\r\n\\end{align*}\r\nSo,\r\n\\begin{align*}\r\n\t\\hat{T}\\cdot\\hat{T}^{\\prime}(t) &= 0 \\implies \\hat{T}(t) \\perp \\hat{T}^{\\prime}(t) \\\\\r\n\t\\hat{N}(t) &= \\frac{\\hat{T}^{\\prime}(t)}{\\norm{\\hat{T}^{\\prime}(t)}}\\perp\\hat{T}.\r\n\\end{align*}\r\n\r\n\\noindent\r\n$\\hat{N}$ is a unit vector perpendicular to $\\hat{T}$ that points in the direction that the curve curls into.\r\nIt is called the normal vector because it is perpendicular to the curve.\r\nIt is in the same plane as $\\vec{r}^\\prime$, $\\hat{T}$, and  $\\vec{r}^{\\prime\\prime}$.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{that_nhat}\r\n\t\\centering\r\n\t\\includegraphics[width = 0.5\\textwidth]{./vectorValuedFunctions/TN.PNG}\r\n\t\\caption{$\\hat{T}$ and $\\hat{N}$}\r\n\\end{figure}\r\n\r\n\\noindent\r\n$\\hat{N}$ allows us to rewrite $\\vec{r}^{\\prime\\prime}$.\\\\\r\n\\begin{equation*}\r\n\t\\vec{r}^{\\prime\\prime}(t)=\\frac{\\mathrm{d}v}{\\mathrm{d}t}\\hat{T}(t)+v^{2}(t)\\kappa(t)\\hat{N}(t)\r\n\\end{equation*}\r\n\r\n\\noindent\r\nWe can see that $\\vec{r}^{\\prime\\prime}(t)$ has two parts. If $\\vec{r}(t)$ represents position, then $\\frac{\\mathrm{d}v}{\\mathrm{d}t}$ represents linear acceleration and $v^2(t)\\kappa(t)$ represents centripetal acceleration.\r\nYou might recognize the formula for centripetal acceleration in the 2nd part from physics.\r\nIf we let $R(t) = \\frac{1}{\\kappa(t)}$, then the 2nd part becomes $\\frac{v^2(t)}{R(t)}$, which looks exactly like the formula for centripetal acceleration for uniform circular motion: $a_c = \\frac{v^2}{r}$.", "meta": {"hexsha": "0fe6cd8b4b63a833a03ecf01968b9e349781d6c4", "size": 1969, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorValuedFunctions/nHat.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/nHat.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/nHat.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": 46.880952381, "max_line_length": 225, "alphanum_fraction": 0.6201117318, "num_tokens": 739, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519528094861981, "lm_q2_score": 0.8872045817875224, "lm_q1q2_score": 0.7558564360429071}}
{"text": "\\subsection{Justification for the  multiplier method}\n\nWhy does the multiplier method work for finding the $LU$ factorization?\nSuppose $A$ is a matrix which has the property that the {\\ef} for $A$ may be achieved without switching rows. Thus every row which is replaced using this\nrow operation in obtaining the {\\ef} may be modified by using a row which\nis above it.\\index{LU factorization!justification}\n\n\\begin{lemma}{Multiplier method and triangular matrices}{multiplier-method-triangular-matrices}\nLet $L$ be a lower (upper) triangular matrix $m\\times m$\nwhich has ones down the main diagonal. Then $L^{-1}$ also is a lower (upper)\ntriangular matrix which has ones down the main diagonal. In the case that $L$\nis of the form\n\\begin{equation}\nL=\\begin{mymatrix}{cccc}\n1 &  &  &  \\\\\na_{1} & 1 &  &  \\\\\n\\vdots &  & \\ddots &  \\\\\na_{n} &  &  & 1\n\\end{mymatrix}  \\label{4-nove-1h}\n\\end{equation}\nwhere all entries are zero except for the left column and main diagonal, it\nis also the case that $L^{-1}$ is obtained from $L$ by simply multiplying\neach entry below the main diagonal in $L$ with $-1$. The same is true if the\nsingle non-zero column is in another position.\n\\end{lemma}\n\n\\begin{proof}Consider the usual setup for finding the inverse $\\begin{mymatrix}{cc}\nL & I\n\\end{mymatrix}$. Then each row operation done to $L$ to reduce to\n{\\rref} results in changing only the entries in $I$ below the main\ndiagonal. In the special case of $L$ given in {\\eqref{4-nove-1h}} or the\nsingle non-zero column is in another position, multiplication by $-1$\nas described in the lemma clearly results in $L^{-1}$.\n\\end{proof}\n\nFor a simple illustration of the last claim,\n\\begin{equation*}\n\\begin{mymatrix}{cccccc}\n1 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 1 & 0 \\\\\n0 & a & 1 & 0 & 0 & 1\n\\end{mymatrix} \\rightarrow \\begin{mymatrix}{cccccc}\n1 & 0 & 0 & 1 & 0 & 0 \\\\\n0 & 1 & 0 & 0 & 1 & 0 \\\\\n0 & 0 & 1 & 0 & -a & 1%\n\\end{array}%\n}\n\\end{equation*}\n\nNow let $A$ be an $m\\times n$-matrix, say\n\\begin{equation*}\nA=\\begin{mymatrix}{cccc}\na_{11} & a_{12} & \\cdots & a_{1n} \\\\\na_{21} & a_{22} & \\cdots & a_{2n} \\\\\n\\vdots & \\vdots &  & \\vdots \\\\\na_{m1} & a_{m2} & \\cdots & a_{mn}\n\\end{mymatrix}\n\\end{equation*}\nand assume $A$ can be row reduced to an upper triangular form using only row\noperation 3. Thus, in particular, $a_{11}\\neq 0$. Multiply on the left by $\nE_{1}=$\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 0 & \\cdots & 0 \\\\\n-\n\\frac{a_{21}}{a_{11}} & 1 & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n-\\frac{a_{m1}}{a_{11}} & 0 & \\cdots & 1\n\\end{mymatrix}\n\\end{equation*}\nThis is the product of elementary matrices which make modifications in the\nfirst column only. It is equivalent to taking $-a_{21}/a_{11}$ times the\nfirst row and adding to the second. Then taking $-a_{31}/a_{11}$ times the\nfirst row and adding to the third and so forth. The quotients in the first\ncolumn of the above matrix are the multipliers. Thus the result is of the\nform\n\\begin{equation*}\nE_{1}A=\\begin{mymatrix}{cccc}\na_{11} & a_{12} & \\cdots & a_{1n}^{\\prime } \\\\\n0 & a_{22}^{\\prime } & \\cdots & a_{2n}^{\\prime } \\\\\n\\vdots & \\vdots &  & \\vdots \\\\\n0 & a_{m2}^{\\prime } & \\cdots & a_{mn}^{\\prime }%\n\\end{mymatrix}\n\\end{equation*}\nBy assumption, $a_{22}^{\\prime }\\neq 0$ and so it is possible to use this\nentry to zero out all the entries below it in the matrix on the right by\nmultiplication by a matrix of the form $E_{2}=\\begin{mymatrix}{cc}\n1 & \\mathbf{0} \\\\\n\\mathbf{0} & E\n\\end{mymatrix} $ where $E$ is an $(m-1)\\times (m-1)$-matrix of the form\n\\begin{equation*}\nE=\\begin{mymatrix}{cccc}\n1 & 0 & \\cdots & 0 \\\\\n-\\frac{a_{32}^{\\prime }}{a_{22}^{\\prime }} & 1 & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n-\\frac{a_{m2}^{\\prime }}{a_{22}^{\\prime }} & 0 & \\cdots & 1\n\\end{mymatrix}\n\\end{equation*}\nAgain, the entries in the first column below the 1 are the multipliers.\nContinuing this way, zeroing out the entries below the diagonal entries,\nfinally leads to\n\\begin{equation*}\nE_{m-1}E_{n-2}\\cdots E_{1}A=U\n\\end{equation*}\nwhere $U$ is upper triangular. Each $E_{j}$ has all ones down the main\ndiagonal and is lower triangular. Now multiply both sides by the inverses of\nthe $E_{j}$ in the reverse order$$. This yields\n\\begin{equation*}\nA=E_{1}^{-1}E_{2}^{-1}\\cdots E_{m-1}^{-1}U\n\\end{equation*}\nBy Lemma~\\ref{lem:multiplier-method-triangular-matrices}, this implies that the product of those $E_{j}^{-1}$\nis a lower triangular matrix having all ones down the main diagonal.\n\nThe above discussion and lemma gives the justification for the multiplier\nmethod. The expressions\n\\begin{equation*}\n\\frac{-a_{21}}{a_{11}},\\frac{-a_{31}}{a_{11}},\\ldots, \\frac{-a_{m1}}{a_{11}}\n\\end{equation*}\ndenoted respectively by $M_{21},\\ldots,M_{m1}$ to save notation which were\nobtained in building $E_{1}$ are the multipliers.\n\\index{multipliers} Then according to the lemma, to find $E_{1}^{-1}$ you\nsimply write\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 0 & \\cdots & 0 \\\\\n-M_{21} & 1 & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n-M_{m1} & 0 & \\cdots & 1\n\\end{mymatrix}\n\\end{equation*}\nSimilar considerations apply to the other $E_{j}^{-1}$. Thus $L$ is a\nproduct of the form\n\\begin{equation*}\n\\begin{mymatrix}{cccc}\n1 & 0 & \\cdots & 0 \\\\\n-M_{21} & 1 & \\cdots & 0 \\\\\n\\vdots & \\vdots & \\ddots & \\vdots \\\\\n-M_{m1} & 0 & \\cdots & 1\n\\end{mymatrix} \\cdots \\begin{mymatrix}{cccc}\n1 & 0 & \\cdots & 0 \\\\\n0 & 1 & \\cdots & 0 \\\\\n\\vdots & 0 & \\ddots & \\vdots \\\\\n0 & \\cdots & -M_{m\\mat{m-1} } & 1\n\\end{mymatrix}\n\\end{equation*}\neach factor having at most one non-zero column, the position of which moves\nfrom left to right in scanning the above product of matrices from left to\nright. It follows from what we know  about the effect of multiplying\non the left by an elementary matrix that the above product is of the form\n\\begin{equation*}\n\\begin{mymatrix}{ccccc}\n1 & 0 & \\cdots & 0 & 0 \\\\\n-M_{21} & 1 & \\cdots & 0 & 0 \\\\\n\\vdots & -M_{32} & \\ddots & \\vdots & \\vdots \\\\\n-M_{\\mat{M-1} 1} & \\vdots & \\cdots & 1 & 0 \\\\\n-M_{M1} & -M_{M2} & \\cdots & -M_{MM-1} & 1\n\\end{array}%\n}\n\\end{equation*}\n\nIn words, beginning at the left column and moving toward the right, you\nsimply insert, into the corresponding position in the identity matrix, $-1$\ntimes the multiplier which was used to zero out an entry in that position\nbelow the main diagonal in $A$, while retaining the main diagonal which\nconsists entirely of ones. This is $L$.\n", "meta": {"hexsha": "3a8314e4cc316a17ec2b4d4225f0f3f93a5ab613", "size": 6384, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/matricesLUFactorizationMultiplierJustification.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/matricesLUFactorizationMultiplierJustification.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/matricesLUFactorizationMultiplierJustification.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.4578313253, "max_line_length": 153, "alphanum_fraction": 0.6748120301, "num_tokens": 2265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8519527869325345, "lm_q2_score": 0.8872045981907006, "lm_q1q2_score": 0.7558564300079269}}
{"text": "\\input{../header_function}\r\n\r\n%---------- start document ---------- %\r\n \\section{arygcd -- binary-like gcd algorithms}\\linkedzero{arygcd}\r\n%\r\n  \\subsection{bit\\_num -- the number of bits}\\linkedone{arygcd}{bit\\_num}\r\n   \\func{bit\\_num}{\\hiki{a}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the number of bits for \\param{a}\\\\\r\n   %\\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a} must be int, long or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{binarygcd -- gcd by the binary algorithm}\\linkedone{arygcd}{binarygcd}\r\n   \\func{binarygcd}{\\hiki{a}{integer},\\ \\hiki{b}{integer}}{\\out{integer}}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor (gcd) of two integers \\param{a},\\ \\param{b} by the binary gcd algorithm.\\\\\r\n   %\\spacing\r\n   % added document\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a},\\ \\param{b} must be int, long or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{arygcd\\_i -- gcd over gauss-integer}\\linkedone{arygcd}{arygcd\\_i}\r\n   \\func{arygcd\\_i}{\\hiki{a1}{integer},\\ \\hiki{a2}{integer},\\ \\hiki{b1}{integer},\\ \\hiki{b2}{integer}}{(\\out{integer},\\ \\out{integer})}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor (gcd) of two gauss-integers \\param{a1}+\\param{a2}$i$,\\ \\param{b1}+\\param{b2}$i$, where ``$i$'' denotes the imaginary unit. \\\\\r\n   \\spacing\r\n   % added document\r\n   If the output of arygcd\\_i(\\param{a1}, \\param{a2}, \\param{b1}, \\param{b2}) is (\\param{c1}, \\param{c2}), then\r\n   the gcd of \\param{a1}+\\param{a2}$i$ and \\ \\param{b1}+\\param{b2}$i$ equals \\param{c1}+\\param{c2}$i$.\\\\\r\n   \\negok This function uses $(1+i)$-ary gcd algorithm, which is an generalization of the binary algorithm, proposed by A.Weilert\\cite{Weilert}.\\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a},\\ \\param{b} must be int, long or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n  \\subsection{arygcd\\_w -- gcd over Eisenstein-integer}\\linkedone{arygcd}{arygcd\\_w}\r\n   \\func{arygcd\\_w}{\\hiki{a1}{integer},\\ \\hiki{a2}{integer},\\ \\hiki{b1}{integer},\\ \\hiki{b2}{integer}}{(\\out{integer},\\ \\out{integer})}\\\\\r\n   \\spacing\r\n   % document of basic document\r\n   \\quad Return the greatest common divisor (gcd) of two Eisenstein-integers \\param{a1}+\\param{a2}$\\omega$,\\ \\param{b1}+\\param{b2}$\\omega$, \r\n   where ``$\\omega$'' denotes a primitive cubic root of unity.\\\\\r\n   \\spacing\r\n   % added document\r\n   If the output of arygcd\\_w(\\param{a1}, \\param{a2}, \\param{b1}, \\param{b2}) is (\\param{c1}, \\param{c2}), then\r\n   the gcd of \\param{a1}+\\param{a2}$\\omega$ and \\ \\param{b1}+\\param{b2}$\\omega$ equals \\param{c1}+\\param{c2}$\\omega$.\\\\\r\n   \\negok This functions uses $(1-\\omega)$-ary gcd algorithm, which is an generalization of the binary algorithm, proposed by I.B. Damg{\\aa}rd and G.S. Frandsen \\cite{Dam-Frand}. \\\\\r\n   %\\spacing\r\n   % input, output document\r\n   %\\quad \\param{a},\\ \\param{b} must be int, long or \\linkingone{rational}{Integer}.\\\\\r\n%\r\n\\begin{ex}\r\n>>> arygcd.binarygcd(32, 48)\r\n16\r\n>>> arygcd_i(1, 13, 13, 9)\r\n(-3, 1)\r\n>>> arygcd_w(2, 13, 33, 15)\r\n(4, 5)\r\n\\end{ex}%Don't indent!(indent causes an error.)\r\n\\C\r\n\r\n%---------- end document ---------- %\r\n\r\n\\input{../footer}\r\n", "meta": {"hexsha": "a56965412f2d6c1f1f7b56b956356306b42cadce", "size": 3297, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "manual/en/arygcd.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/arygcd.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/arygcd.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": 47.1, "max_line_length": 182, "alphanum_fraction": 0.6390658174, "num_tokens": 1133, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.904650527388829, "lm_q2_score": 0.8354835309589074, "lm_q1q2_score": 0.7558206169066566}}
{"text": "\\section{Unconstrained continuous optimization}\n\nIn the following we treat only unconstrained continuous optimization problems. In these we are looking for the minimum of a function $f: R^n \\Rightarrow R$ over \\textbf{all} points $\\overrightarrow{x} \\in R^n$ for which $f(\\overrightarrow{x})$ is defined.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\textwidth]{figures/one-dimensional-optimization.png}\n\\caption{One dimensional optimization example}\n\\end{figure}\n\nThe gradient $ \\bigtriangledown f$ of the function $f: R^n \\Rightarrow R$ is the vector consisting of the $n$ partial derivatives of the vector.\n\n$\\bigtriangledown f(\\overrightarrow{x}) = \\begin{vmatrix}\nf_{x1}(\\overrightarrow{x}) \\\\\nf_{x2}(\\overrightarrow{x})  \\\\\n\\vdots \\\\\nf_{x1}(\\overrightarrow{x})  \\\\\n\\end{vmatrix}$\n\\\\\n\\\\\nAt each point $\\overrightarrow{x}$ , the gradient $\\bigtriangledown f(\\overrightarrow{x})$ points in the direction of steepest ascent.\nIts norm $||\\bigtriangledown f(\\overrightarrow{x})||$ gives the slope in that direction.\n\nIf all $x$ in $\\bigtriangledown f(\\overrightarrow{x}) = 0$, we have a stationary point in $f$. This doesn't mean that we have a extremal point, because there are also stationary points like e in the figure on top.\n\n\\clearpage\n\\subsection{Gradient Descent}\nGradient descent is an algorithm to find a local minimum of an (unconstrained multidimensional smooth) function f.\nThe function increases in direction of the gradient, so by going in the opposite direction we will get decreasing function values.\n\nAlgorithm:\n\\begin{itemize}\n    \\item Initialization: Choose starting point $x^0$\n    \\item Iteration step $x^i \\Rightarrow x^{i+1}$: \\\\\n    Determine local gradient $\\bigtriangledown f(x^i)$ and move by some amount $\\beta$ in opposite direction $\\Rightarrow$ new point $x^{i+1}$. \\\\\n    Repeat until gradient is (approximately) zero / no more (significant) decreases of the function values are observed.\n\\end{itemize}\n\n\\textbf{But} what is the optimal Step size $\\beta$ in $x^{i+1} = x^i - \\beta \\bigtriangledown f(x^i)$?\n\n\\subsubsection{Successive halving of the step size}\nThe second step in the following notes is an extension of the successive halfening of the step size.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/stepsizehalfening.png}\n\\caption{Successive halving of the step size}\n\\end{figure}\n\n\\subsection{Newton’s method}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/newtonMethod.png}\n\\caption{Newton’s method}\n\\end{figure}\n\n\\begin{enumerate}\n    \\item Initialization: \\\\\n    Choose starting point $x^0$\n    \\item Iteration step $x^i \\Rightarrow x^{i+1}$: \\\\\n    $x^{i+1} = x^i - H_f(x^i)^{-1} \\bigtriangledown f(x^i)$ \n    \\item Repeat iteration step until break condition is met.\n\\end{enumerate}\n\n\\subsection{Speed of convergence}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/speedConvergence.png}\n\\caption{Continuous Optimization - Speed of convergence}\n\\end{figure}\n\n\\subsection{Approximating partial derivatives}\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.9\\textwidth]{figures/approxDerivatives.png}\n\\caption{Continuous Optimization - Approximating partial derivatives}\n\\end{figure}\n\n\\subsection{Broyden's method}\nComputing and inverting the Hessian matrix $H_f (x^i)$ exactly in\nthe (approximate version of) Newton’s method is computationally expensive.\nThe idea in quasi-Newton methods is to approximate the inverse of the Hessian, $H_f (x^i)^-1$, by some matrix $(A_i)^{-1}$ that can be computed more efficiently.\n\nBroyden’s method is a prominent example of a quasi-Newton\nmethod, where you aproximate the ”derivative of the derivative”.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/broyden.png}\n\\caption{Broyden's method}\n\\end{figure}\n\n\\clearpage\n\\subsection{Aitken's acceleration method}\nTo conclude, we present a general approach that can be used to improve the convergence speed of other methods (e.g. of the ones presented so far).\nAitken’s method is not a new method for finding local extrema, but can be used to improve the convergence speed of other existing methods that would converge slowly otherwise.\n\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=1\\textwidth]{figures/aitken.png}\n\\caption{Aitken's method}\n\\end{figure}\n\n\\clearpage", "meta": {"hexsha": "4e5e81d35357cf1f78ff22b9c98f4f33c6a3f07e", "size": 4329, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "FTP_Optimiz/05_UnconstrainedContinuousOptimization.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/05_UnconstrainedContinuousOptimization.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/05_UnconstrainedContinuousOptimization.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": 40.4579439252, "max_line_length": 255, "alphanum_fraction": 0.7597597598, "num_tokens": 1155, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637397236824, "lm_q2_score": 0.8791467722591728, "lm_q1q2_score": 0.755770602006325}}
{"text": "\\chapter{$2\\times 2$ matrix diagonalization}\\label{appMatrix}\n\nConsider a Hermitian $2\\times 2$ matrix $H$\n\\be\nH = \\left(\\ba{cc} x & z \\\\  z^* & y\\ea\\right), \n\\quad x = x^*, \\, y = y^*\n\\ee\n\nwith eigenvalues given by\n\\bem \n\\lambda_1 & = & \\frac{x + y}{2} + \\sqrt{\\frac{(x - y)^2}{4} + \\abs{z}^2}, \n\\nel\n\\lambda_2 & = & \\frac{x + y}{2} - \\sqrt{\\frac{(x - y)^2}{4} + \\abs{z}^2}, \n\\ee \n\nwhere I choose \n\n\\bel{lambdaOrder}\n\\lambda_1 \\ge \\lambda_2.\n\\ee\n\nA unitary matrix $U$ that diagonalizes $H$ should fulfill\n\\bel{diagonalization}\nUHU^\\hc  = H_0 \\quad \\mbox{or} \\quad UH = H_0U,\n\\ee\n\\be\nH_0 = \\left(\\ba{cc} \\lambda_1 & 0 \\\\ 0 &  \\lambda_2 \\ea\\right).\n\\ee\n\nA possible solution of \\rf{diagonalization} can be obtained by writing\n\\bel{explicit-U-form}\nU = \\pba{cc} \n   \\cos\\theta & \\sin\\theta e^{i\\phi} \\\\\n   -\\sin\\theta e^{-i\\phi} & \\cos\\theta\n   \\pea,\n\\ee\nand\n\\bem\n\\left(\\ba{cc} \nx\\cos\\theta  + z^*\\sin\\theta e^{i\\phi} &\nz\\cos\\theta + y\\sin\\theta e^{i\\phi}\\\\\n-x\\sin\\theta e^{-i\\phi} + z^*\\cos\\theta &\n-z\\sin\\theta e^{-i\\phi} + y\\cos\\theta\n\\ea\\right)\n&&\n\\nel\n\\qquad = \\quad\n\\pba{cc} \n   \\lambda_1\\cos\\theta & \\lambda_1\\sin\\theta e^{i\\phi} \\\\\n   -\\lambda_2\\sin\\theta e^{-i\\phi} & \\lambda_2\\cos\\theta\n\\pea\n&&\n\\ee\n\nwhich gives\n\\bel{matrix-phase-is}\ne^{i\\phi} = \\zOverAbs{z} \\quad \\mbox{or} \\quad \\phi = \\Arg{z},\n\\ee \n\n\\be\n\\abs{z}\\sin\\theta = (\\lambda_1 - x)\\cos\\theta,\n\\ee\n\nor\n\\be\n\\tan\\theta = {\\lambda_1 - x \\over \\abs{z}}\n= \\frac{y - x}{2\\abs{z}} + \\sqrt{\\frac{(x - y)^2}{4\\abs{z}^2} + 1}, \n\\ee\n\n\\bel{matrix-theta-is}\n\\tan\\theta = \\sqrt{1 + \\eta^2} - \\eta, \n\\quad \\eta \\equiv (x - y)/(2\\abs{z}).\n\\ee\n\nIf $z = 0$ and $x \\ge y$ the solution is $\\theta = 0$ and $U = 1$.\nIf $z = 0$ and $x < y$ I have $\\theta = \\pi/2$ and \n\\bel{formForU}\nU = \\left(\\ba{cc} \n   0 & e^{i\\phi} \\\\ e^{-i\\phi} & 0\n\\ea\\right),\n\\ee\n\nIt just reflects the fact that due to the requirement \n\\rf{lambdaOrder} in this situation $U$ should merely interchange $x$ and $y$.\n\nSo the domain for $\\theta$ can be restricted to the closed interval $[0,\\pi/2]$.\n\n\\P\nThe solution~\\rf{explicit-U-form} is not unique.\nTo find all possible $U'$ that satisfy~\\rf{diagonalization} I represent \nsuch $U'$ as a product $\\tilde{U}U$ where $U$ is given \nby~\\rf{explicit-U-form} and $\\tilde{U}$ is some unitary matrix. \nThis leads to the equation\n\\be\nH_0 = \\tilde{U}U H U^\\hc  \\tilde{U}^\\hc  = \\tilde{U} H_0 \\tilde{U}^\\hc ,  \n\\ee\n\\be\nH_0\\tilde{U} - \\tilde{U}H_0 = [H_0, \\tilde{U}] =  0.\n\\ee\nBut $H_0$ is a diagonal and only diagonal matrices can commute with \n$H_0$ thus\n\\be\n\\tilde{U} = \\left(\\ba{cc} e^{i\\psi} & 0 \\\\ 0 & e^{i\\psi'} \\ea\\right),\n\\ee\n\nwith two arbitrary phase factors $e^{i\\psi}$ and $e^{i\\psi'}$. So all possible \nsolutions of~\\rf{diagonalization} have the form\n\\bel{allDiagonalization}\n\\tilde{U}U =\n   \\left(\\ba{cc} e^{i\\psi} & 0 \\\\ 0 & e^{i\\psi'} \\ea\\right)\n   \\left(\\ba{cc} \n      \\cos\\theta & \\sin\\theta e^{i\\phi} \\\\\n      -\\sin\\theta e^{-i\\phi} & \\cos\\theta\n      \\ea\\right)\n.      \n\\ee\n\n\\P\nWhen $H$ is real, $H^* = H$, $z$ also becomes  a real quantity and\n\\be\nz = z^* \\Leftrightarrow e^{i\\phi} = \\zOverAbs{z} \\equiv \\sign(z) = \\pm 1\n.\n\\ee\n\nIt is natural to require in this case for $U$ to be also real and \nhence an orthogonal matrix. From \\rf{allDiagonalization} I find that \nany orthogonal matrix $O'$ that diagonalizes a real symmetric matrix $H_r$,\n\\be\nH_r = \\left(\\ba{cc} x & z \\\\ z & y\\ea\\right)\n= O'\\left(\\ba{cc} \\lambda_1 & 0 \\\\ 0 & \\lambda_2 \\ea\\right)O'^T\n, \n\\quad x = x^*, \\quad y = y^*, \\quad z = z^*,\n\\ee\n\\be\n\\ee\n\nhas the form\n\\bel{orthogonalDiagonalization}\nO' =\n   \\left(\\ba{cc} \\pm 1 & 0 \\\\ 0 & \\pm 1 \\ea\\right) O, \n\\quad\nO = \\left(\\ba{cc} \n      \\cos\\theta & \\sin\\theta \\sign(z) \\\\\n      -\\sin\\theta \\sign(z) & \\cos\\theta\n      \\ea\\right)\n.\n\\ee\n\n\\P\nConsider now the diagonalization problem for an arbitrary complex \n$2\\times 2$ matrix~$C$\n\\be\nC = \\pba{cc} a & b \\\\ c & d\\pea, \n\\quad C^\\hc  = \\left(\\ba{cc} a^* & c^*  \\\\ b^* & d^*\\ea\\right) \n\\ee \nby two unitary matrixes $X$, $Y$. By definition they should \nfulfill\\footnote{For conventional reasons \nI use $X^*$ and not just $X$ in~\\rf{equationForUs}.\n}\n\n\\bel{equationForUs}\nX^*CY^\\hc  = C_0 = \\left(\\ba{cc} \\lambda_1 & 0\\\\ 0 & \\lambda_2\\ea\\right).\n\\ee\n\nAs opposite to the case of the hermitian matrix $H$, in general \n$\\lambda_1$, $\\lambda_2$ in~\\rf{equationForUs} are not eigenvalues \nof $C$ and they can be found by following the procedure \ndescribed in~\\cite{howCharginosCome}. I find\n\\be\nC_0C_0^\\hc  = C_0^\\hc C_0 = X^*CY^\\hc YC^\\hc X^{*\\hc} = X^*CC^\\hc X^{*\\hc} \n= YC^\\hc CY^\\hc \n\\ee\n\nThis means that $X^*$ should diagonalize the hermitian matrix $CC^\\hc $ and \n$Y$ should do this for $C^\\hc C$ which in general differs from $CC^\\hc $ \nbut has the same eigenvalues $\\abs{\\lambda_{1,2}}^2$,\n\\be\nCC^\\hc  = \\left(\\ba{cc} \n   \\abs{a}^2 + \\abs{b}^2 & ac^* + bd^* \\\\ \n   ca^* + db^* & \\abs{c}^2 + \\abs{d}^2\n\\ea\\right),\n\\quad\nC^\\hc C = \\left(\\ba{cc} \n   \\abs{a}^2 + \\abs{c}^2 & ba^* + dc^* \\\\ \n   ab^* + cd^* & \\abs{b}^2 + \\abs{d}^2\n\\ea\\right),\n\\ee\n\\beml{lambdaForCompleMatrix}\n\\abs{\\lambda_1}^2 & = & S + \\sqrt{T}, \n\\qquad\n\\abs{\\lambda_2}^2 \\; = \\; S - \\sqrt{T},\n\\nel\nS &=& \\frac{\\abs{a}^2 + \\abs{b}^2 + \\abs{c}^2 + \\abs{d}^2}{2} \n,\n\\nel\nT &=& \\frac{(\\abs{a}^2 + \\abs{b}^2 - \\abs{c}^2 - \\abs{d}^2)^2}{4}\n      + \\abs{ac^* + bd^*}^2.\n\\ee \n\nAccording to \\rf{allDiagonalization} $X^*$ and $Y$ have the following \nrepresentation,\n\\bel{X-and-Y-representation}\nX^* = \\tilde{X}X', \n\\quad\nY = \\tilde{Y}Y'.\n\\ee\n\nHere $X'$, $Y'$ have the form \\rf{explicit-U-form},\n\\be\nX' = \\pba{cc} \n   \\cos\\theta_X & \\sin\\theta_X e^{i\\phi_X} \\\\\n   -\\sin\\theta_X e^{-i\\phi_X} & \\cos\\theta_X\n   \\pea,\n\\quad\nY' = \\pba{cc} \n   \\cos\\theta_Y & \\sin\\theta_Y e^{i\\phi_Y} \\\\\n   -\\sin\\theta_Y e^{-i\\phi_Y} & \\cos\\theta_Y\n   \\pea,\n\\ee\n\nwhere from~\\rf{matrix-phase-is} \n\\bel{matrixXandYcoef}\ne^{i\\phi_X} = \\zOverAbs{ac^* + bd^*}, \n\\qquad\ne^{i\\phi_Y} = \\zOverAbs{ba^* + dc^*}, \n\\quad\n\\ee\n\nand $\\theta_X$ and $\\theta_Y$ are defined by~\\rf{matrix-theta-is},\n\\be\n\\tan\\theta_X = \\sqrt{1 + \\eta_X^2} - \\eta_X, \n\\quad \\eta_X = \n   \\frac{\\abs{a}^2 + \\abs{b}^2 - \\abs{c}^2 - \\abs{d}^2}\n        {2\\abs{ac^* + bd^*}},\n\\ee\n\n\\be\n\\tan\\theta_Y = \\sqrt{1 + \\eta_Y^2} - \\eta_Y, \n\\quad \\eta_Y = \n   \\frac{\\abs{a}^2 + \\abs{c}^2 - \\abs{b}^2 - \\abs{d}^2}\n        {2\\abs{ba^* + dc^*}},\n\\ee\n\nIn the general case $\\tilde{X}$ and $\\tilde{Y}$ cannot be set to $1$ and \nto determine the phase factors present in $\\tilde{X}$ and $\\tilde{Y}$,\n\\be\n\\tilde{X} = \\left(\\ba{cc} e^{i\\psi_X} & 0 \\\\ 0 & e^{i\\psi'_X} \\ea\\right),\n\\quad\n\\tilde{Y} = \\left(\\ba{cc} e^{i\\psi_Y} & 0 \\\\ 0 & e^{i\\psi'_Y} \\ea\\right),\n\\ee\n\nI substitute~\\rf{X-and-Y-representation} into~\\rf{equationForUs} to find \nrelations for $\\tilde{X}$ and $\\tilde{Y}$,\n\n\\bel{m-tmp-1}\n\\tilde{X}{X'}C{Y'}^\\hc \\tilde{Y}^\\hc  = C_0, \n\\quad \\mbox{or} \\quad \n\\tilde{X}^\\hc C_0\\tilde{Y} \\; = \\; {X'}C{Y'}^\\hc .\n\\ee\n\nBy writing the matrices in~\\rf{m-tmp-1} explicitly I have\n\\bem\n\\lefteqn{\n\\pba{cc} \\lambda_1e^{i(\\psi_Y - \\psi_X)} & 0 \\\\ \n    0 & \\lambda_2e^{i(\\psi'_Y - \\psi'_X)} \\pea\n}\n\\nel\n& = & \n\\pba{cc} \n   \\cos\\theta_X & \\sin\\theta_X e^{i\\phi_X} \\\\\n   -\\sin\\theta_X e^{-i\\phi_X} & \\cos\\theta_X\n\\pea\n\\pba{cc} \n a & b \\\\ c & d\n\\pea\n\\pba{cc} \n   \\cos\\theta_Y &  -\\sin\\theta_Y e^{i\\phi_Y} \\\\\n   \\sin\\theta_Y e^{-i\\phi_Y} & \\cos\\theta_Y\n\\pea\n\\nel &=&\n\\pba{cc} \n   a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X} \n       & b\\cos\\theta_X + d\\sin\\theta_X e^{i\\phi_X} \\\\\n   -a\\sin\\theta_X e^{-i\\phi_X} + c\\cos\\theta_X\n       & -b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X\n\\pea\n\\nel && \\quad {} \\times \n\\pba{cc} \n   \\cos\\theta_Y &  -\\sin\\theta_Y e^{i\\phi_Y} \\\\\n   \\sin\\theta_Y e^{-i\\phi_Y} & \\cos\\theta_Y\n\\pea\n.\n\\ee\n\nThis gives me four equations,\n\\bem\n\\lambda_1e^{i(\\psi_Y - \\psi_X)}\n&=&\n(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\\cos\\theta_Y\n\\nel &&{} \n+(b\\cos\\theta_X + d\\sin\\theta_X e^{i\\phi_X})\\sin\\theta_Y e^{-i\\phi_Y},\n\\nel\n0 &=&\n-(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\\sin\\theta_Y e^{i\\phi_Y}   \n\\nel &&{} \n+(b\\cos\\theta_X + d\\sin\\theta_X e^{i\\phi_X})\\cos\\theta_Y\n,\n\\nel\n0 & = &\n(-a\\sin\\theta_X e^{-i\\phi_X} + c\\cos\\theta_X)\\cos\\theta_Y\n\\nel &&{} \n+\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)\\sin\\theta_Y e^{-i\\phi_Y}\n,\n\\nel\n\\lambda_2e^{i(\\psi'_Y - \\psi'_X)}\n& = &\n-(-a\\sin\\theta_X e^{-i\\phi_X} + c\\cos\\theta_X)\\sin\\theta_Y e^{i\\phi_Y}\n\\nel &&{} \n+\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)\\cos\\theta_Y\n.\n\\ee\n\nFrom the second and third equation it follows that\n\n\\bem\n(b\\cos\\theta_X + d\\sin\\theta_X e^{i\\phi_X}) & = &\n(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\\tan\\theta_Y e^{i\\phi_Y},\n\\nel \n(-a\\sin\\theta_X e^{-i\\phi_X} + c\\cos\\theta_X) & = &\n(b\\sin\\theta_X e^{-i\\phi_X} - d\\cos\\theta_X)\\tan\\theta_Y e^{-i\\phi_Y},\n\\ee\n\nThus the first and fourth equations give\n\n\\bem\n\\lambda_1e^{i(\\psi_Y - \\psi_X)}\n&=&\n(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\\cos\\theta_Y\n\\nel &&{} \n+(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\n \\tan\\theta_Y e^{i\\phi_Y} \\sin\\theta_Y e^{-i\\phi_Y}\n\\nel & = &\n(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})\n(\\cos\\theta_Y + \\tan\\theta_Y \\sin\\theta_Y)\n\\nel\n&=&\n(a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X})/\\cos\\theta_Y,\n\\nel\n\\lambda_2e^{i(\\psi'_Y - \\psi'_X)} & = &\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)\\tan\\theta_Y e^{-i\\phi_Y}\n\\sin\\theta_Y e^{i\\phi_Y}\n\\nel &&{} \n+\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)\\cos\\theta_Y\n\\nel &=&\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)\n(\\cos\\theta_Y + \\tan\\theta_Y\\sin\\theta_Y)\n\\nel &=&\n(-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X)/\\cos\\theta_Y,\n\\ee\n\nwhere I used\n\\be\n\\cos\\theta + \\tan\\theta\\sin\\theta\n = {1 \\over \\cos\\theta}(\\cos^2\\theta + \\sin^2\\theta) = {1 \\over \\cos\\theta}\n .\n\\ee\n\nSo\n\\bem\ne^{i(\\psi_Y - \\psi_X)}\n&=&\n{a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X} \\over \\lambda_1 \\cos\\theta_Y},\n\\nel\ne^{i(\\psi'_Y - \\psi'_X)} & = &\n{-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X \\over \\lambda_2\\cos\\theta_Y}\n.\n\\ee\n\n\\P\n\nFrom the last expressions I find that \nonly the absolute values of $\\lambda_{1,2}$\nare fixed by the matrix $C$ and to determine the phase factors for \n$\\lambda_{1,2}$ and to fix the phases $\\psi_{X,Y}$, $\\psi'_{X,Y}$ \nadditional conditions should be given.\n\n\\P\n\nFor example, under the requirement\nfor $\\lambda_{1,2}$ to be non-positive real numbers,\n$\\lambda_{1,2} = -\\abs{\\lambda_{1,2}}$ and for $\\tilde{X}$ to be the \nunit matrix, \n$\\tilde{X} = 1$ or $\\psi_X$ = $\\psi'_X$ = $0$,\n$X$ and $Y$ have the form\n\\beml{matrixXandY}\nX^* \n& = &\nX'\n\\; = \\;\n\\pba{cc} \n   \\cos\\theta_X & \\sin\\theta_X e^{i\\phi_X} \\\\\n   -\\sin\\theta_X e^{-i\\phi_X} & \\cos\\theta_X\n\\pea\n,\n\\nel\nY \n& = &\n\\tilde{Y}Y'\n\\; = \\;\n\\pba{cc} \n   e^{i\\psi_Y} & 0 \\\\ \n   0 & e^{i\\psi'_Y} \n\\pea \n\\pba{cc} \n   \\cos\\theta_Y & \\sin\\theta_Y e^{i\\phi_Y} \\\\\n   -\\sin\\theta_Y e^{-i\\phi_Y} & \\cos\\theta_Y\n\\pea,\n\\nel & = &\n\\pba{cc} \n   \\cos\\theta_Y e^{i\\psi_Y} & \\sin\\theta_Y e^{i\\phi_Y} e^{i\\psi_Y} \\\\\n   -\\sin\\theta_Y e^{-i\\phi_Y}e^{i\\psi'_Y} & \\cos\\theta_Y e^{i\\psi'_Y}\n\\pea\n,\n\\ee\n\n\\be\ne^{i\\psi_Y}\n= \n  \\frac{a\\cos\\theta_X + c\\sin\\theta_X e^{i\\phi_X}}{\\lambda_1\\cos\\theta_Y}\n        ,\n\\quad\ne^{i\\psi'_Y} = \n{-b\\sin\\theta_X e^{-i\\phi_X} + d\\cos\\theta_X \\over \\lambda_2\\cos\\theta_Y}\n      .\n\\ee\n\n", "meta": {"hexsha": "201a42b744d452382460133778af6ab97189cde5", "size": 11044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "writes/bergen_master_thesis/body/MatrixDiagonalization.tex", "max_stars_repo_name": "ibukanov/ahome", "max_stars_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "writes/bergen_master_thesis/body/MatrixDiagonalization.tex", "max_issues_repo_name": "ibukanov/ahome", "max_issues_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "writes/bergen_master_thesis/body/MatrixDiagonalization.tex", "max_forks_repo_name": "ibukanov/ahome", "max_forks_repo_head_hexsha": "dc12d4a98c626414264c0cf38b357035e6e04a45", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 25.1, "max_line_length": 80, "alphanum_fraction": 0.5928105759, "num_tokens": 4924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7557029185317752}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Consider the set of symmetric $n\\times n$-matrices%\n  \\index{matrix!symmetric}%\n  \\index{symmetric matrix}, i.e., matrices satisfying $A=A^T$. Show\n  that this set of symmetric matrices is a subspace of $\\Mat_{n,n}$,\n  the vector space of $n\\times n$-matrices.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the set of all vectors\n  $\\begin{mysmallmatrix}{c}x\\\\y\\end{mysmallmatrix}\\in\\R^2$ such that\n  $x+y\\geq 0$. Is this a subspace of $\\R^2$?\n  \\begin{sol}\n    No. It is not closed under scalar multiplication.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Consider the set of all vectors\n  $\\begin{mysmallmatrix}{c}x\\\\y\\end{mysmallmatrix}\\in\\R^2$ such that $xy=0$. Is\n  this a subspace of $\\R^2$?\n  \\begin{sol}\n    No. It is not closed under addition.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $V$ be the set of those polynomials $ax^2+bx+c\\in\\Poly_2$ such\n  that $a+b+c=0$. Is $V$ a subspace of $\\Poly_2$? Explain.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $U,W$ be subspaces of a vector space $V$ and consider $U+W$\n  defined as the set of all vectors that can be written of the form\n  $\\vect{u}+\\vect{w}$, where $\\vect{u}\\in U$ and $\\vect{w}\\in W$. Show\n  that $U+W$ is a subspace of $V$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $U,W$ be subspaces of a vector space $V$. Then $U\\cap W$ consists\n  of all vectors which are in both $U$ and $W$. Show that $U\\cap W$ is a\n  subspace of $V$.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $U,W$ be subspaces of a vector space $V$. Then $U\\cup W$\n  consists of all vectors which are in either $U$ or $W$. Show that\n  $U\\cup W$ is not necessarily a subspace of $V$ by giving an example\n  where $U\\cup W$ fails to be a subspace.\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $U=\\set{\\left.\\mat{x,y,z}^T \\in \\R^3~\\right\\vert~\\abs{x} \\leq 4}$. Is $U$ a\n  subspace of $\\R^3$?\n  \\begin{sol}\n    This is not a subspace.\n    $\\begin{mysmallmatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mysmallmatrix}$ is in it, but\n    $5\\begin{mysmallmatrix}{r} 1 \\\\ 1 \\\\ 1 \\end{mysmallmatrix}$ is not.\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subset of\\/ $\\Mat_{2,2}$ given by\n  \\begin{equation*}\n    W = \\set{\\left.\\begin{mysmallmatrix}{rr}\n        a  & b \\\\\n        c & d\n      \\end{mysmallmatrix}~\\right\\vert~ a,b,c,d \\in K,~ a + b = c + d}\n  \\end{equation*}\n  Is $W$ a subspace of $\\Mat_{2,2}$?\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $U=\\set{\n    A\\in\\Mat_{2,2}\n    ~\\left\\vert~\n      A\\begin{mysmallmatrix}{rr} 1 & 0 \\\\ 1 & -1 \\end{mysmallmatrix}\n      = \\begin{mysmallmatrix}{rr} 1 & 1 \\\\ 0 & -1 \\end{mysmallmatrix} A\n    \\right.}$.\n  Show that $U$ is a subspace of $\\Mat_{2,2}$.\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subset of\\/ $\\Poly_3$ given by\n  \\begin{equation*}\n    W = \\set{ax^3 + bx^2 + cx + d \\mid a,b,c,d \\in K, d = 0}\n  \\end{equation*}\n  Is $W$ a subspace of $\\Poly_3$?\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subset of\\/ $\\Poly_3$ given by\n  \\begin{equation*}\n    W = \\set{p(x) \\mid p(2) = 1}\n  \\end{equation*}\n  Is $W$ a subspace of $\\Poly_3$?\n  % \\begin{sol}\n  % \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subset of $\\Seq_{\\R}$ consisting of all sequences\n  that are alternating, i.e., where $a_i\\geq 0$ for even $i$ and\n  $a_i\\leq 0$ for odd $i$, or vice versa. Is $W$ a subspace of\n  $\\Seq_{\\R}$?\n\\end{ex}\n\n\\begin{ex}\n  Let $W$ be the subset of $\\Seq_K$ consisting of all sequences that\n  satisfy the recurrence relation\n  $a_{n+3} = a_{n+2} + 2a_{n+1} - a_n$. Is $W$ a subspace of\n  $\\Seq_K$?\n\\end{ex}\n\n\\begin{ex}\\label{ex:periodic}\n  A sequence $(a_i)_{i\\in\\N}$ is called \\textbf{periodic}%\n  \\index{periodic sequence}%\n  \\index{sequence!periodic} if there exists some $k>0$ such that for\n  all $i$, $a_{i+k}=a_i$. The number $k$ is called a \\textbf{period}\n  of the sequence. For example, the following is a periodic sequence\n  with period $3$:\n  \\begin{equation*}\n    (1,5,-7,1,5,-7,1,5,-7,1,5,-7,1,\\ldots).\n  \\end{equation*}\n  \\begin{enumerate}\n  \\item Show that the set of all periodic sequences of a fixed period\n    $k$ forms a subspace of $\\Seq_K$.\n  \\item More difficult: show that the set of all periodic sequences of\n    all periods forms a subspace of $\\Seq_K$.\n  \\end{enumerate}\n\\end{ex}\n\n\\begin{ex}\n  A function $f:\\R\\to\\R$ is called \\textbf{symmetric}%\n  \\index{function!symmetric}%\n  \\index{symmetric function} if $f(x)=f(-x)$ for all $x\\in\\R$.  Let\n  $W$ be the subset of $\\Func_{\\R,\\R}$ consisting of all symmetric\n  functions. Is $W$ a subspace of $\\Func_{\\R,\\R}$?\n\\end{ex}\n\n\\begin{ex}\n  A function $f:\\R\\to\\R$ is said to \\textbf{vanish at infinity}%\n  \\index{function!vanishing at infinity}%\n  \\index{vanish at infinity} if $\\lim_{x\\to\\infty}f(x)=0$ and\n  $\\lim_{x\\to-\\infty}f(x)=0$. Let $W$ be the subset of $\\Func_{\\R,\\R}$\n  consisting of all functions that vanish at infinity. Prove that $W$\n  is a subspace of $\\Func_{\\R,\\R}$.\n\\end{ex}\n\n\\begin{ex}\n  Show that the sets $S=\\set{x+2,(x+2)^2}$ and\n  $T=\\set{x^2-4, x^2+x-2}$ span the same subspace of $\\Poly_2$.\n\\end{ex}\n\n\\begin{ex}\n  Show that the sets $S=\\set{\n    \\begin{mysmallmatrix}{rr} 1 & 0 \\\\ 0 & 1 \\end{mysmallmatrix},~\n    \\begin{mysmallmatrix}{rr} 0 & 1 \\\\ 1 & 0 \\end{mysmallmatrix}\n  }$ and $T=\\set{\n    \\begin{mysmallmatrix}{rr} 1 & 1 \\\\ 1 & -1 \\end{mysmallmatrix},~\n    \\begin{mysmallmatrix}{rr} 1 & 1 \\\\ -1 & 1 \\end{mysmallmatrix}\n  }$\n  span the same subspace of $\\Mat_{2,2}$.\n\\end{ex}\n", "meta": {"hexsha": "8af9214a1cb97b80de7d877986467ccd82d351e8", "size": 5457, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/VectorSpaces-Subspaces.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/VectorSpaces-Subspaces.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/VectorSpaces-Subspaces.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 30.1491712707, "max_line_length": 81, "alphanum_fraction": 0.619571193, "num_tokens": 2137, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424528443251, "lm_q2_score": 0.8933094032139577, "lm_q1q2_score": 0.7556883477037156}}
{"text": "\\subsection{Dot product}\n\n\\begin{frame}[fragile]{Dot product}\n\n\n$ c = x^T\\cdot y; \\quad x,y \\in R^n\\text{ (vectors)} $\n\n\\vspace{10px}\n \\begin{lstlisting}[language=Matlab]\n\nfunction: c = dot(x,y)\n\n   c = 0\n   n = length(x)\n \tfor i = 1 : n\n \t\tc = c + x(i)%*$\\cdot$*)y(i)\n \tend\n\n end dot\n \\end{lstlisting}\n\n\n\\end{frame}\n\n\\subsection{saxpy}\n\n\\begin{frame}[fragile]{saxpy}\n\n$ z = \\alpha \\cdot x + y == $ (saxpy = \\textbf{s}calar \\textbf{a}lpha \\textbf{x} \\textbf{p}lus \\textbf{y})  $\\alpha$ -- scalar\n\\vspace{10px}\n \\begin{lstlisting}[language=Matlab]\n\nfunction: z = saxpy(%*$\\alpha$*),x,y)\n\n  n = length(x)\n \tfor i = 1 : n\n\n \t\tz(i) = %*$\\alpha \\cdot \\text{x(i)} + \\text{y(i)} $*)\n\n \tend\n\n end saxpy\n \\end{lstlisting}\n\n\\end{frame}\n\n\n\\subsection{The colon notation}\n\n\\begin{frame}{The colon notation}\n\n$ A\\in R^{m\\cdot n} $ \\\\\n\\vspace{10px}\n$k$-th row of $A$:\n$$A(k, :) = [a_{k1}, a_{k2}, \\dots , a_{kn}]$$\n$k$-th column of $A$:\n\\vspace{10px}\n\n\\begin{center}\n$A(:, k) = \\left [ \\begin{array}{l}\n   a_{1k} \\\\\n   a_{2k}\\\\\n   \\vdots\\\\\n   a_{nk}\n\\end{array}\n\\right ] $\n\\end{center}\n\n\\end{frame}\n", "meta": {"hexsha": "d973787ed8ae78ff71c2343c692ab1f73bbe30ed", "size": 1085, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_1_dot_product.tex", "max_stars_repo_name": "Arkowski24/lectures", "max_stars_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 12, "max_stars_repo_stars_event_min_datetime": "2017-07-30T20:04:07.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-04T07:17:48.000Z", "max_issues_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_1_dot_product.tex", "max_issues_repo_name": "Arkowski24/lectures", "max_issues_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 19, "max_issues_repo_issues_event_min_datetime": "2017-07-03T20:03:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-02T19:31:19.000Z", "max_forks_repo_path": "10_numeryczna_algebra_liniowa-wprowadzenie/10_4_1_dot_product.tex", "max_forks_repo_name": "Arkowski24/lectures", "max_forks_repo_head_hexsha": "6051f4779eb85fa07b41f434efc7210ab10689a9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2018-11-13T17:10:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-01-14T09:41:13.000Z", "avg_line_length": 15.5, "max_line_length": 126, "alphanum_fraction": 0.5732718894, "num_tokens": 439, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897525789548, "lm_q2_score": 0.8031737963569016, "lm_q1q2_score": 0.7556176771525093}}
{"text": "\\chapter{Solving Recurrences}\n\n\\section{The Master Theorem}\n\nIf $T(n) = aT(\\frac{n}{b}) + O(n^d)$, then\n\n\\begin{math}\nT(n) = \\left\\{\n\\begin{array}{l l}\nO(n^d)       & \\quad \\text{if} d > log_ba \\\\\nO(n^d logn)  & \\quad \\text{if} d = log_ba \\\\\nO(n^{log_ba}) & \\quad \\text{if} d < log_ba \\\\\n\\end{array} \\right.\n\\end{math}\n\n\\section{Recursion Tree}\n\nWe can reason about a recurrence of the form: $ T(n) = aT(\\frac{n}{b})\n+ f(n) $ where $ a \\geq 0, b > 0 $ with the following recursion tree:\n\n{\n  % Current graphic is hand-drawn by John Howat.\n  % Should replace asap with a nicer diagram\n  \\includegraphics[scale=1.2]{recursion_tree}\n  %\\caption{A recursion tree representing a recursions on n/b elements}\n  \\label{fig:recursion_tree}\n}\n\nThis tree has the following properties:\n\n\\begin{enumerate}\n\\item The number of nodes at level $i$: $a^i$\n\\item Work done at each node of level $i$: $f(\\frac{n}{b^i})$\n\\item Number of levels: $log_bn$\n\\item Number of leaves: $n^{log_ba}$\n\\end{enumerate}\n\nWe can use this information to solve the recurrence:\n\n\\begin{align*}\nT(n)\n&= \\summ{i=0}{log_bn} \n(\\text{\\# nodes at level } i) \n(\\text{work done at level } i) \\\\\n&= \\summ{i=0}{log_bn} a^i f(\\frac{n}{b^i})\n\\end{align*}\n", "meta": {"hexsha": "8f7a4b588c9617093c2b541ac0087bbb2c02f3b2", "size": 1206, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "recurrences.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": "recurrences.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": "recurrences.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": 25.6595744681, "max_line_length": 71, "alphanum_fraction": 0.6517412935, "num_tokens": 421, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9241418199787564, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7555547664516362}}
{"text": "\\subsection{Series}\\label{subsec:series}\n\nHere \\( (X, \\norm) \\) will refer to a Banach space over \\( \\BbbK \\).\n\n\\begin{definition}\\label{def:convergent_series}\n  When extending addition to a countable amount of terms, we need to impose some regularity conditions to avoid contradictions. The topologies of \\( \\BbbR \\) and \\( \\BbbC \\) are complete and allow us to define convergent and divergent series. We define series in great generality because the theory easily allows it.\n\n  A \\term{numeric series} or simply \\term{series} is an infinite sequence \\( x_0, x_1, \\ldots \\in X \\), which we call \\term{terms}, usually written as\n  \\begin{equation}\\label{def:convergent_series/series}\n    \\sum_{k=0}^\\infty x_k.\n  \\end{equation}\n\n  To each series, there corresponds its sequence of \\term{partial sums}\n  \\begin{equation*}\n    S_n \\coloneqq \\sum_{k=0}^n x_k, n = 0, 1, 2, \\ldots\n  \\end{equation*}\n\n  We can equivalently define a series as a sequence of partial sums and then recover the terms as\n  \\begin{equation*}\n    x_k \\coloneqq \\begin{cases}\n      S_0,           & k = 0, \\\\\n      S_k - S_{k-1}, & k > 0\n    \\end{cases}\n  \\end{equation*}\n\n  We say that the series \\eqref{def:convergent_series/series} \\term{converges} to a value \\( x \\) if \\( \\lim_{n \\to \\infty} S_n = x \\) in the sense of \\fullref{def:net_convergence/limit}. The value \\( x \\) is called the \\term{sum} of the series.\n\n  If a series does not converge, we say that it is \\term{divergent}.\n\n  If the related series\n  \\begin{equation}\\label{def:convergent_series/absolute_series}\n    \\sum_{k=0}^\\infty \\norm{x_k}\n  \\end{equation}\n  converges, we say that \\eqref{def:convergent_series/series} is \\term{absolutely convergent}.\n\\end{definition}\n\n\\begin{example}\\label{ex:series}\n  Several examples of series are\n  \\begin{itemize}\n    \\item An absolutely convergent series is \\eqref{thm:geometric_progression/series_sum}.\n    \\item A divergent series is the harmonic series \\eqref{eq:ex:harmonic_series/harmonic}.\n    \\item A convergent, but not absolutely convergent series is the alternating harmonic series \\eqref{eq:ex:harmonic_series/alternating}.\n  \\end{itemize}\n\\end{example}\n\n\\begin{proposition}\\label{thm:absolutely_convergent_series_is_convergent}\n  An absolutely convergent series is convergent.\n\\end{proposition}\n\\begin{proof}\n  Suppose that \\eqref{def:convergent_series/absolute_series} converges.\n\n  By the triangle inequality, for each index \\( n \\) we have\n  \\begin{equation*}\n    \\norm{\\sum_{k=0}^n x_k} \\leq \\sum_{k=0}^n \\norm{x_k} \\leq \\sum_{k=0}^\\infty \\norm{x_k}.\n  \\end{equation*}\n\n  Thus, the sequence \\( \\left\\{ \\norm{\\sum_{k=0}^{n} x_k} \\right\\}_{n=0}^\\infty \\) is a bounded (by \\( \\sum_{k=0}^\\infty \\norm{x_k} \\)) monotone sequence, which by \\fullref{thm:real_monotone_sequence_converges_iff_bounded} is convergent.\n\n  Therefore, the series \\eqref{def:convergent_series/series} is convergent.\n\\end{proof}\n\n\\begin{remark}\\label{rem:establish_series_convergence_by_absolute_series}\n  Convergence of the series \\eqref{def:convergent_series/series} can be established using the convergence of the nonnegative series \\eqref{def:convergent_series/absolute_series}.\n\n  The convergence of the latter can be established using techniques in \\fullref{subsec:real_series} like \\fullref{thm:cauchys_root_test} or \\fullref{thm:dalamberts_ratio_test}.\n\\end{remark}\n\n\\begin{proposition}\\label{thm:infinitary_triangle_inequality}\n  For every series \\eqref{def:convergent_series/series} we have\n  \\begin{equation}\\label{thm:infinitary_triangle_inequality/inequality}\n    \\norm{\\sum_{k=0}^\\infty x_k} \\leq \\sum_{k=0}^\\infty \\norm{x_k},\n  \\end{equation}\n  where both limits are allowed to be infinite.\n\\end{proposition}\n\\begin{proof}\n  If the series on the right diverges, the inequality is obviously true.\n\n  Suppose that it is convergent. By \\fullref{thm:absolutely_convergent_series_is_convergent}, the limit\n  \\eqref{def:convergent_series/series} exists.\n\n  By the triangle inequality, for each index \\( n \\) we have\n  \\begin{equation*}\n    \\norm{\\sum_{k=0}^n x_k} \\leq \\sum_{k=0}^n \\norm{x_k}.\n  \\end{equation*}\n\n  By \\fullref{thm:one_sided_squeeze_lemma}, since both sequences are convergent, we obtain \\fullref{thm:infinitary_triangle_inequality/inequality}.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:convergent_series_terms_vanish}\n  The terms of the convergent series \\eqref{def:convergent_series/series} vanish as \\( k \\to \\infty \\), that is,\n  \\begin{equation*}\n    \\lim_{k \\to \\infty} x_k = 0.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  Since the series is convergent, its sequence of partial sums converges, i.e. the partial sums get arbitrarily close to each other. Then\n  \\begin{equation*}\n    \\norm{x_n} = \\norm{S_n - S_{n-1}} \\to 0.\n  \\end{equation*}\n\\end{proof}\n\n\\begin{theorem}\\label{thm:product_of_series_convergence}\n  Consider two convergent series\n  \\begin{equation}\\label{thm:product_of_series_convergence/a}\n    A \\coloneqq \\sum_{k=0}^\\infty x_k\n  \\end{equation}\n  and\n  \\begin{equation}\\label{thm:product_of_series_convergence/b}\n    B \\coloneqq \\sum_{k=0}^\\infty y_k.\n  \\end{equation}\n\n  If either \\fullref{thm:product_of_series_convergence/a} or \\fullref{thm:product_of_series_convergence/b} converges absolutely, then\n  \\begin{equation}\\label{thm:product_of_series_convergence/prod}\n    \\sum_{k=0}^\\infty \\sum_{m=0}^k x_m y_{k-m} = AB.\n  \\end{equation}\n\\end{theorem}\n\n\\begin{proposition}[Cauchy's series convergence criterion]\\label{thm:cauchy_series_convergence_criterion}\\mcite[3.22]{Rudin1976Principles}\n  The series \\eqref{def:convergent_series/series} converges if and only if for every \\( \\varepsilon > 0 \\) there exists an index \\( k_0 \\) such that\n  \\begin{equation*}\n    \\norm{\\sum_{k=m}^n x_k} < \\varepsilon \\quad\\forall m, n \\geq k_0.\n  \\end{equation*}\n\\end{proposition}\n\\begin{proof}\n  This is simply a restatement of \\fullref{thm:cauchys_net_convergence_criterion}.\n\\end{proof}\n\n\\begin{proposition}[Cauchy's series continuity criterion]\\label{thm:cauchy_series_continuity_criterion}\\mcite[\\textnumero 265]{Фихтенгольц1968Том2}\n  Fix a topological space \\( A \\) and a set \\( S \\subseteq A \\). Let \\( \\{ f_k \\}_{k=0}^\\infty \\) be a sequence of continuous functions from \\( S \\) to \\( X \\).\n\n  Define the function \\( f: S \\to X \\) as\n  \\begin{equation}\\label{thm:cauchy_series_continuity_criterion/function}\n    f(x) \\coloneqq \\sum_{k=0}^\\infty f_k(x).\n  \\end{equation}\n\n  A sufficient condition for \\( f \\) to be continuous in \\( S \\) is that for every \\( \\varepsilon > 0 \\) there exists an index \\( K \\) such that\n  \\begin{equation*}\n    \\norm{\\sum_{k=m}^n f(x)} < \\varepsilon \\quad\\forall m, n \\geq K\n  \\end{equation*}\n  simultaneously for all \\( x \\in S \\).\n\\end{proposition}\n\\begin{proof}\n  This is simply a restatement of \\fullref{thm:uniform_limit_of_continuous_functions} in the style of \\fullref{thm:cauchy_series_convergence_criterion}.\n\\end{proof}\n\n\\begin{corollary}[Weierstrass' series criterion]\\label{thm:weierstrass_series_criterion}\\mcite[\\textnumero 265]{Фихтенгольц1968Том2}\n  Let \\( S \\) be any set and \\( \\{ f_k \\}_{k=0}^\\infty \\) be a sequence of functions from \\( S \\) to \\( X \\). Consider the series \\fullref{thm:cauchy_series_continuity_criterion/function}. If\n  \\begin{equation*}\n    \\forall k \\in \\BbbZ^{>0} \\ \\exists M_k \\in \\BbbR^{>0} \\ \\forall x \\in S : \\norm{f_k(x)} < M_k\n  \\end{equation*}\n  and if the series\n  \\begin{equation}\\label{thm:weierstrass_series_criterion/dominating}\n    \\sum_{k=0}^\\infty M_k\n  \\end{equation}\n  converges, then the limit \\fullref{thm:cauchy_series_continuity_criterion/function} exists for every \\( x \\in S \\) and, furthermore, the series converges absolutely and uniformly.\n\n  In analogy to \\fullref{thm:positive_series_comparison}, we say that the series \\fullref{thm:weierstrass_series_criterion/dominating} \\term{dominates} the series \\fullref{thm:cauchy_series_continuity_criterion/function}.\n\n  In particular, if \\( S \\) has a topology and the functions \\( f_k(x), k = 0, 1, \\ldots \\) are continuous (resp. uniformly continuous), so is \\( f(x) \\).\n\\end{corollary}\n\\begin{proof}\n  By \\fullref{thm:positive_series_comparison}, the series\n  \\begin{equation*}\n    \\sum_{k=0}^\\infty \\norm{f_k(x)}\n  \\end{equation*}\n  converges for any \\( x \\in S \\), hence \\fullref{thm:cauchy_series_continuity_criterion/function} converges absolutely for any \\( x \\in S \\).\n\n  Furthermore, each of the functions \\( f_k(x) \\) is bounded by \\( B(0, M_k) \\) and \\( M_k \\) does not depend on \\( x \\), hence the convergence is uniform.\n\n  The rest of the theorem follows from \\fullref{thm:uniform_limit_of_continuous_functions}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:continuous_function_series_powers_of_two}\n  Let \\( X \\subseteq \\BbbR \\) be a nonempty set. Consider the series of real-valued real functions\n  \\begin{equation}\\label{thm:continuous_function_series_powers_of_two/series}\n    f(x) \\coloneqq \\sum_{k=0}^\\infty \\frac {f_k(x)} {2^k},\n  \\end{equation}\n  where \\( \\{ f_k \\}_{k=0}^\\infty \\subseteq B_{C(X)} \\) is a sequence of continuous functions bounded in \\( [-1, 1] \\).\n\n  Then \\( f(x) \\) is defined and continuous for all \\( x \\in X \\).\n\\end{corollary}\n\\begin{proof}\n  For \\( \\abs{x} \\leq 1 \\), the series is dominated by the geometric series \\fullref{eq:ex:n_ary_decomposition/binary}, which sums to \\( 2 \\), hence by \\fullref{thm:weierstrass_series_criterion} \\( f(x) \\) is continuous in the interval \\( [-1, 1] \\).\n\n  Note that\n  \\begin{equation*}\n    f(2x) \\coloneqq \\sum_{k=0}^\\infty \\frac x {2^{k-1}} = 2 f(x),\n  \\end{equation*}\n  hence the series \\fullref{thm:continuous_function_series_powers_of_two/series} also converges for \\( \\abs{x} \\leq 2 \\).\n\n  By induction on \\( n \\), we show that \\( f(2^n x) = 2^n f(x) \\) and thus \\( f(x) \\) is continuous in \\( B(0, 2^n) \\), therefore also on the entire real line \\( \\BbbR \\).\n\\end{proof}\n\n\\begin{example}\\label{thm:weierstrass_series_criterion/counterexample}\\mcite[\\textnumero 266]{Фихтенгольц1968Том2}\n  Consider the real series\n  \\begin{equation*}\n    f(x) \\coloneqq \\sum_{k=0}^\\infty x^k (1 - x).\n  \\end{equation*}\n\n  It converges for \\( \\abs{x} < 1 \\) because it is dominated by a convergent geometric series.\n\n  For \\( x \\in (0, 1) \\),\n  \\begin{equation*}\n    f(x)\n    =\n    \\sum_{k=0}^\\infty x^k (1 - x)\n    =\n    \\sum_{k=0}^\\infty x^k - \\sum_{k=1}^\\infty x^k\n    =\n    1.\n  \\end{equation*}\n\n  But\n  \\begin{equation*}\n    \\lim_{t \\uparrow 1} f(x) = 1 \\neq 0 = f(1) = f(\\lim_{t \\uparrow 1} t).\n  \\end{equation*}\n\n  This shows that \\( f(x) \\) is not continuous, despite every term being continuous.\n\n  By contraposition to \\fullref{thm:weierstrass_series_criterion}, it follows that no series that dominates \\( f(x) \\) converges.\n\\end{example}\n\n\\begin{theorem}\\label{thm:uniform_limit_exchange}\\mcite[\\textnumero 268]{Фихтенгольц1968Том2}\n  Fix a uniform space \\( (A, \\mscrU) \\) and let \\( S \\subseteq A \\). Let \\( f_k: S \\to X, k = 0, 1, \\ldots \\) be a sequence of functions and assume that \\( x_0 \\in M \\) is a limit point of each of these functions.\n\n  \\begin{thmenum}\n    \\thmitem{thm:uniform_limit_exchange/sequence} If the sequence \\( \\{ f_k \\}_{k=0}^\\infty \\) converges uniformly on \\( S \\), we can exchange the limits\n    \\begin{equation*}\n      \\lim_{x \\to x_0} \\lim_{k \\to \\infty} f_k(x)\n      =\n      \\lim_{k \\to \\infty} \\lim_{x \\to x_0} f_k(x).\n    \\end{equation*}\n\n    \\thmitem{thm:uniform_limit_exchange/series} If the series \\fullref{thm:cauchy_series_continuity_criterion/function} converges uniformly on \\( S \\), we can exchange the limits\n    \\begin{equation*}\n      \\lim_{x \\to x_0} \\sum_{k=0}^\\infty f_k(x)\n      =\n      \\sum_{k=0}^\\infty \\lim_{x \\to x_0} f_k(x).\n    \\end{equation*}\n  \\end{thmenum}\n\\end{theorem}\n\n\\begin{remark}\\label{rem:thm:uniform_limit_exchange_continuity}\n  If the functions \\( f_k \\) in \\fullref{thm:uniform_limit_exchange/series} are continuous at \\( x_0 \\), we have the additional equality\n  \\begin{equation}\\label{thm:uniform_limit_exchange/continuous_equality}\n    \\lim_{x \\to x_0} f(x)\n    =\n    \\lim_{x \\to x_0} \\sum_{k=0}^\\infty f_k(x)\n    =\n    \\sum_{k=0}^\\infty \\lim_{x \\to x_0} f_k(x)\n    \\reloset * =\n    \\sum_{k=0}^\\infty f_k\\left(\\lim_{x \\to x_0} x \\right)\n    =\n    f\\left(\\lim_{x \\to x_0} x \\right),\n  \\end{equation}\n  thus \\( f \\) is continuous at \\( x_0 \\). The continuity actually follows from \\fullref{thm:cauchy_series_continuity_criterion} directly.\n\\end{remark}\n\n\\begin{corollary}\\label{thm:riemann_intergral_limit_exchange}\\mcite[\\textnumero 269]{Фихтенгольц1968Том2}\n  Let \\( \\{ f_k \\}_{k=0}^\\infty \\subseteq C([a, b], \\BbbR) \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:riemann_intergral_limit_exchange/sequence} If the sequence \\( \\{ f_k \\}_{k=0}^\\infty \\) converges uniformly, then\n    \\begin{equation*}\n      \\lim_{k \\to \\infty} \\int_a^b f_k(x) dx = \\int_a^b \\lim_{k \\to \\infty} f_k(x) dx.\n    \\end{equation*}\n\n    \\thmitem{thm:riemann_intergral_limit_exchange/series} If the series \\fullref{thm:cauchy_series_continuity_criterion/function} converges uniformly, then\n    \\begin{equation*}\n      \\int_a^b f(x) dx = \\int_a^b \\sum_{k=0}^\\infty f_k(x) dx = \\sum_{k=0}^\\infty \\int_a^b f_k(x) dx.\n    \\end{equation*}\n  \\end{thmenum}\n\\end{corollary}\n\\begin{proof}\n  \\SubProofOf{thm:riemann_intergral_limit_exchange/sequence} Assume that the sequence \\( \\{ f_k \\}_{k=0}^\\infty \\) converges uniformly to \\( f \\). Then by \\fullref{thm:uniform_limit_exchange}, we note that for any index \\( k \\), the difference \\( r_k(x) \\coloneqq f(x) - f_k(x) \\) is continuous, hence integrable, and\n  \\begin{equation*}\n    \\int_a^b f(x) dx = \\int_a^b f_k(x) dx + \\int_a^b r_k(x) dx.\n  \\end{equation*}\n\n  Because of the uniform convergence, for any \\( \\delta > 0 \\) and there exist an index \\( k_0 \\) such that\n  \\begin{equation*}\n    \\abs{f(x) - f_k(x)} = \\abs{r_k(x)} < \\delta \\quad\\forall k \\geq k_0, \\forall x \\in [a, b].\n  \\end{equation*}\n\n  Then\n  \\begin{equation*}\n    \\abs{\\int_a^b f(x) dx - \\int_a^b f_k(x) dx} = \\abs{\\int_a^b r_k(x) dx} < (b - a) \\delta.\n  \\end{equation*}\n\n  Given \\( \\varepsilon > 0 \\), we define \\( \\delta \\coloneqq \\frac \\varepsilon {b - a} \\) to obtain an index \\( k_0 \\) such that\n  \\begin{equation*}\n    \\abs{\\int_a^b f(x) dx - \\int_a^b f_k(x) dx} = \\abs{\\int_a^b r_k(x) dx} < \\varepsilon \\quad\\forall k \\geq k_0.\n  \\end{equation*}\n\n  Thus, \\fullref{def:net_convergence/limit} is satisfied and equality holds.\n\n  \\SubProofOf{thm:riemann_intergral_limit_exchange/series} This is a special case of \\fullref{thm:riemann_intergral_limit_exchange/sequence}.\n\\end{proof}\n\n\\begin{corollary}\\label{thm:derivative_limit_exchange}\\mcite[thm. 7.17]{Rudin1976Principles}\n  Let \\( \\{ f_k \\}_{k=0}^\\infty \\subseteq C^1([a, b], \\BbbR) \\). Suppose that the series \\fullref{thm:cauchy_series_continuity_criterion/function} converges for at least one point \\( x_0 \\in [a, b] \\).\n\n  \\begin{thmenum}\n    \\thmitem{thm:derivative_limit_exchange/sequence} If the sequence \\( \\{ D f_k \\}_{k=0}^\\infty \\) of derivatives converges uniformly, then \\( \\{ f_k \\}_{k=0}^\\infty \\) also converges uniformly, its limit is differentiable in \\( (a, b) \\) and\n    \\begin{equation*}\n      D\\left(\\lim_{k \\to \\infty} f_k(x) \\right) = \\lim_{k \\to \\infty} D f_k(x).\n    \\end{equation*}\n\n    \\thmitem{thm:derivative_limit_exchange/series} If the series of derivatives\n    \\begin{equation}\\label{thm:derivative_limit_exchange/derivative_series}\n      \\sum_{k=0}^\\infty D f_k(x)\n    \\end{equation}\n    converges uniformly, then \\fullref{thm:cauchy_series_continuity_criterion/function} converges uniformly, is differentiable in \\( (a, b) \\) and\n    \\begin{equation*}\n      D\\left(\\sum_{k=0}^\\infty f_k(x)\\right) = \\sum_{k=0}^\\infty D f_k(x).\n    \\end{equation*}\n  \\end{thmenum}\n\\end{corollary}\n\\begin{proof}\n  \\SubProofOf{thm:derivative_limit_exchange/sequence} Fix \\( \\varepsilon > 0 \\). Since the sequence \\( \\{ f_k \\}_{k=0}^\\infty \\) converges for \\( x_0 \\), there exists an index \\( k_0 \\) such that\n  \\todo{Prove complex case}\n  \\begin{equation*}\n    \\abs{f_m(x_0) - f_n(x_0)} < \\varepsilon \\quad\\forall m, n \\geq k_0.\n  \\end{equation*}\n\n  Furthermore, there exists an index \\( k_1 \\) such that\n  \\begin{equation*}\n    \\abs{D f_m(x) - D f_n(x)} < \\varepsilon \\quad\\forall x \\in [a, b] \\ \\forall m, n \\geq k_0.\n  \\end{equation*}\n\n  Fix \\( m, n \\geq k_0 \\) and \\( x \\in [a, b] \\). Note that the function \\( f_m - f_n \\) is differentiable and thus by the mean value theorem, there exists \\( \\xi \\) between \\( x_0 \\) and \\( x \\) such that\n  \\begin{equation*}\n    \\frac {[f_m(x) - f_n(x)] - [f_m(x_0) - f_n(x_0)]} {x - x_0} = D f_m(\\xi) - D f_n(\\xi).\n  \\end{equation*}\n\n  Thus,\n  \\begin{balign*}\n    \\abs{f_m(x) - f_n(x)}\n     & \\leq\n    \\abs{f_m(x_0) - f_n(x_0)} + (x - x_0)\\abs{D f_m(\\xi) - D f_n(\\xi)}\n    <       \\\\ &<\n    2 (x - x_0) \\varepsilon\n    \\leq    \\\\ &\\leq\n    2 (b - a) \\varepsilon.\n  \\end{balign*}\n\n  Therefore, the limit \\( \\lim_{k\\to\\infty} f_k(x) \\) exists. Since \\( x \\) was arbitrary and \\( 2 (b - a) \\varepsilon \\) does not depend on \\( x \\), we conclude that\n  \\begin{equation*}\n    f(x) \\coloneqq \\lim_{k\\to\\infty} f_k(x)\n  \\end{equation*}\n  is uniformly convergent on \\( [a, b] \\).\n\n  By the Newton-Leibniz theorem, for the sequence \\( \\{ D f_k \\}_{k=0}^\\infty \\) of derivatives we have\n  \\begin{equation*}\n    \\lim_{k \\to \\infty} \\int_a^x D f_k(t) dt\n    =\n    \\lim_{k \\to \\infty} [f_k(x) - f_k(a)]\n    =\n    \\lim_{k \\to \\infty} f_k(x) - \\lim_{k \\to \\infty} f_k(a)\n    =\n    f(x) - f(a).\n  \\end{equation*}\n\n  Differentiating both sides, we obtain\n  \\begin{equation*}\n    D\\left(\\lim_{k \\to \\infty} \\int_a^x D f_k(t) dt \\right)\n    =\n    D\\left(\\lim_{k \\to \\infty} f_k(x) dt \\right)\n    =\n    D f(x).\n  \\end{equation*}\n\n  \\Fullref{thm:riemann_intergral_limit_exchange/sequence} allows us to conclude that\n  \\begin{equation*}\n    D f(x)\n    =\n    D\\left(\\lim_{k \\to \\infty} \\int_a^x D f_k(t) dt \\right)\n    =\n    D \\int_a^x \\lim_{k \\to \\infty} D f_k(t) dt\n    =\n    \\lim_{k \\to \\infty} D f_k(x).\n  \\end{equation*}\n\n  \\SubProofOf{thm:derivative_limit_exchange/series} This is a special case of \\fullref{thm:riemann_intergral_limit_exchange/sequence}.\n\\end{proof}\n\n\\begin{example}\\label{ex:harmonic_series}\n  We list several important series related to \\hyperref[def:harmonic_progression]{harmonic progressions}.\n\n  \\begin{thmenum}\n    \\thmitem{ex:harmonic_series/harmonic} The series\n    \\begin{equation}\\label{eq:ex:harmonic_series/harmonic}\n      \\sum_{k=1}^\\infty \\frac 1 k = 1 + \\frac 1 2 + \\frac 1 3 + \\frac 1 4 + \\cdots\n    \\end{equation}\n    is called \\hi{the} \\term{harmonic series}. It diverges as shown in \\fullref{thm:harmonic_series_diverges}, which make it much less useful in practice, however it is an important enough example that it has a dedicated name.\n\n    \\thmitem{ex:harmonic_series/alternating} The series\n    \\begin{equation}\\label{eq:ex:harmonic_series/alternating}\n      \\sum_{k=1}^\\infty \\frac {(-1)^k} k\n      =\n      \\sum_{m=1}^\\infty \\parens*{ \\frac 1 {2m - 1} - \\frac 1 {2m} }\n      =\n      1 - \\frac 1 2 + \\frac 1 3 - \\frac 1 4 + \\cdots\n    \\end{equation}\n    is called the \\term{alternating harmonic series}. It converges, but not absolutely --- \\fullref{thm:alternating_harmonic_series_convergence}.\n\n    \\thmitem{ex:harmonic_series/hyperharmonic} For any \\( s \\in \\BbbC \\), the series\n    \\begin{equation}\\label{eq:ex:harmonic_series/hyperharmonic}\n      \\sum_{k=1}^\\infty \\frac 1 {k^s}.\n    \\end{equation}\n    is called the \\term{hyperharmonic series}.\n\n    Unlike the harmonic series, the hyperharmonic series sometimes converges --- see \\fullref{thm:hyperharmonic_series_convergence}.\n  \\end{thmenum}\n\\end{example}\n\n\\begin{proposition}\\label{thm:harmonic_series_diverges}\n  The harmonic series \\eqref{eq:ex:harmonic_series/harmonic} diverges.\n\\end{proposition}\n\\begin{proof}\n  Define the series\n  \\begin{equation*}\n    1 + \\frac 1 2 + \\underbrace{\\frac 1 4 + \\frac 1 4}_{\\sfrac 1 2} + \\underbrace{\\frac 1 8 + \\frac 1 8 + \\frac 1 8 + \\frac 1 8}_{\\sfrac 1 2} + \\underbrace{\\frac 1 {16} + \\cdots + \\frac 1 {16}}_{\\sfrac 1 2} + \\cdots\n  \\end{equation*}\n\n  It is divergent as the sum of infinitely many \\( \\sfrac 1 2 \\). Furthermore, it is dominated by the harmonic series:\n  \\begin{align*}\n    &1 + \\frac 1 2 + \\frac 1 3 + \\frac 1 4 + \\frac 1 5 + \\frac 1 6 + \\frac 1 7 + \\frac 1 8 + \\frac 1 9 \\thinspace + \\cdots + \\frac 1 {16} + \\cdots\n    \\\\\n    &1 + \\frac 1 2 + \\overbrace{ \\frac 1 4 + \\frac 1 4 }^{\\sfrac 1 2} + \\overbrace{ \\frac 1 8 + \\frac 1 8 + \\frac 1 8 + \\frac 1 8 }^{\\sfrac 1 2} + \\overbrace{ \\frac 1 {16} + \\cdots + \\frac 1 {16} }^{\\sfrac 1 2} + \\cdots\n  \\end{align*}\n\n  Thus, by \\fullref{thm:positive_series_comparison}, the harmonic series also diverges.\n\\end{proof}\n\n\\begin{proposition}\\label{thm:alternating_harmonic_series_convergence}\\cite[\\textnumero 247]{Фихтенгольц1968Том2}\n  Consider the alternating harmonic series \\eqref{eq:ex:harmonic_series/alternating}.\n\n  Compare the series with \\eqref{eq:ex:harmonic_series/harmonic}. Note that, by \\fullref{thm:leibniz_alternating_series_test}, the series is convergent. It is not absolutely convergent, because the harmonic series \\eqref{eq:ex:harmonic_series/harmonic} is divergent.\n\\end{proposition}\n\n\\begin{proposition}\\label{thm:hyperharmonic_series_convergence}\n  The hyperharmonic series \\eqref{ex:harmonic_series/hyperharmonic} converges all \\( s \\in \\BbbC \\) with \\( \\real(s) > 1 \\).\n\\end{proposition}\n\\begin{proof}\n  Let \\( s = (1 + \\varepsilon) + bi \\). We use the integral test on the series \\( \\sum_{k=1}^\\infty \\abs{k}^{-s} \\):\n  \\begin{equation*}\n    \\int_1^\\infty \\frac 1 {\\abs{x^s}} \\dl x\n    =\n    \\int_1^\\infty \\frac 1 {x^{1 + \\varepsilon} \\underbrace{\\abs{x^{bi}}}_{1}} \\dl x\n    =\n    -\\frac 1 {\\varepsilon x^\\varepsilon}\\Big\\restr_{x=1}^\\infty\n    =\n    \\frac 1 \\varepsilon \\lim_{x \\to \\infty} \\parens*{ 1 - \\frac 1 {x^\\varepsilon} }\n    =\n    \\frac 1 \\varepsilon.\n  \\end{equation*}\n\n  The integral is finite, hence the hyperharmonic series is absolutely convergent.\n\\end{proof}\n", "meta": {"hexsha": "7ccff79d7985c193edf81c8d2bcebac7046e7de4", "size": 21890, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/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/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/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": 47.4837310195, "max_line_length": 317, "alphanum_fraction": 0.6855641846, "num_tokens": 7780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8577681086260461, "lm_q1q2_score": 0.7555196517124408}}
{"text": "%&LaTeX\n\n\\section{The Z-Transform and Convolution}\n\nThis lab covers the z-transform, used to convert arbitrary digital\nsignals to the frequency domain. It also exercises the relationship\nbetween a filter's transfer function and impulse response and how the\noperations of multiplication and convolution, respectively, can be\nused to compute a filter's output.\n\n\\subsection{The z-transform, Transfer Function, \\& Impulse Response}\n\nA discrete signal $x[n]$ has a z-transform $X(z)$ defined by the\nfollowing equation:\n\\[\nX(z)=\\sum_{n=0}^{\\infty}x[n]z^{-n}\n\\]\nWith this definition lets investigate a feed forward filter with ten\ncoefficients, $\\{b_0, b_1,\\cdots, b_9\\}$.  Recall that the\n\\block{Filter} and \\block{Coeff.} blocks of J-DSP allow us to specify\na filter in terms of its \\emph{coefficients}, but we can also define\nit in terms of its \\emph{transfer function}. Considering the $b_k$\ncoefficients of the feed forward filter, the \\block{Filter} block\nimplements the transfer function:\n\\begin{equation}\n  H(z) = \\sum_{k=0}^{9} b_k z^{-k}\n\\end{equation}\nIn previous labs we have computed the transfer function using the\ndelays of the \\emph{defining function}.  Mathematically, we were\nactually taking the z-transform of the \\emph{impulse response}!  In\nthis example, the impulse response is:\n\\begin{equation}\n  h[n] = \\sum_{k=0}^{9} b_k \\delta[k]\n\\end{equation}\nwhere $\\delta[k]$ is the unit impulse and only has value at\n$k$. $H(z)$ and $h[n]$ form a z-transform pair,\n$h[n]\\xleftrightarrow{z} H(z)$. It should now be obvious why\nfeedforward filters are also known as finite impulse response filters\n-- their impulse response only has a \\emph{finite} number of\nvalues. To compute the output, $y[n]$, using the impulse response we\nuse \\emph{convolution}. Namely, we \\emph{convolve} the input, $x[n]$,\nby the impulse response, $h[n]$,\n\\begin{equation}\n  y[n] = x[n] \\ast h[n]  = \\sum_{k=0}^{9}x[k]h[n-k]\n\\end{equation}\nAlternatively, we can compute a filter's output by multiplying the\ntransfer function by the z-transform of the input to yield the\nz-transform of the output:\n\\begin{equation}\n  Y(z) = H(z) X(z)\n\\end{equation}\nFrom a practical point of view, of course, it makes more sense to\nimplement a filter in terms of its impulse response. However, for\nfilters with long impulse responses, it is sometimes more convenient\nto represent them mathematically using the transfer function (which we\nnow know is just the z-transform of the impulse response!).  So, in\neffect, the J-DSP blocks allow us to invert the z-transform of various\nsignals.\n\n\\subsection{Z-Transforms}\n\n\\paragraph{Step 1.1} On paper, compute the z-transform, $X(z)$, of\n\t\\begin{equation}\n\t\tx[n] = \\left\\{\n\t\t\\begin{array}{ll}\n\t\t\t(-1)^n & n \\ge 0 \\\\\n\t\t\t0 & n < 0\n\t\t\\end{array}\\right.\n\t\\end{equation}\n\tNote that this is an infinite geometric series. \n\t% Hand in hard copy of your work.\n\tWhat are the locations of any pole(s) (roots of the denominator\n\tpolynomial) or zero(s) (roots of the numerator polynomial)?\n\n\n\\paragraph{Step 1.2} Evaluate the frequency response of $X(z)$ from\n\tstep~1.1, $X(z)\\big{|}_{z=e^{j\\hat{\\omega}}}$. \n\t% Hand in hard copy of your work. \n\tWhat kind of filter is this?\n\n\n\\paragraph{Step 1.3} Consider the z-transform:\n\t\\begin{equation}\n\t  X(z) = 1 - 2z^{-1} + 3z^{-3} - z^{-5}  \n\t\\end{equation}\n\tWrite the inverse z-transform, $x[n]$, as a table of values for\n\tcorresponding $n$ values.\n\n\n\\subsection{Impulse Response}\n\n\\paragraph{Step 2.1} Consider a filter with a transfer function\n\t\\begin{equation}\n\tH(z) = 1 + 5z^{-1} - 3z^{-2} + 2.5z^{-3} + 4z^{-8}  \n\t\\end{equation}\n\tWhat is the defining equation for this filter, $y[n] = F(x[n])$?\n\n\n\\paragraph{Step 2.2} What is the output sequence of the filter of\n\tStep~2.1 when the input is $x[n] = \\delta[n]$?\n\n\n\\paragraph{Step 2.3} The impulse response of a filter is $h[n] = x[n]\n\t+ 2x[n-1] + x[n-2] - x[n-3]$, or equivalently, $h[n]=\\{1,2,1,-1\\}$,\n\t$n=\\{0, 1, 2, 3\\}$. Determine the response of the system to the input\n\tsignal $x[n]=\\{1,2,3,1\\}$, $n=\\{0, 1,2,3\\}$. Use J-DSP to check your\n\tresults. Include an image of the J-DSP block diagram with plots of the\n\t\\block{Sig Gen} signal and the filter output in your report.  Note\n\tthat the \\block{Sig Gen} block has a \\emph{user-defined}\n\t\\option{signal} option; use \\button{reset} to reset all the signal\n\tvalues to zero before entering your own. Additionally, you can view\n\tthe values in the \\block{Plot} block.\n\n\n\\paragraph{Step 2.4} Change the input to the filter of Step~2.3 to be\n\t$\\delta[n]$, using the \\option{signal} set to ``Delta''. What are the\n\toutput values? How do they compare to the impulse response? Include a\n\tplot of the filter output values in your report.\n\n\n\\begin{figure}[t] \n   \\centering\n   \t\\includegraphics[width=4in]{lab6/threeinputproblem} \n   \\caption{An example diagram for use in problem 2.5}\n   \\label{fg:threeinput}\n\\end{figure}\n\t\n\\paragraph{Step 2.5} Use J-DSP to determine the output of the filter \\{1/3,1/3,1/3\\}, $n=\\{0,1,2\\}$ for the\n\tinput:\n\t\\begin{equation}\n\t  x[n] = 4 + \\sin[0.25\\pi(n-1)] - 3 \\sin[(2\\pi/3)n]  \n\t\\end{equation}\n\tAn example diagram can be seen in Figure \\ref{fg:threeinput}. Include an image \n\tof the J-DSP block diagram with plots of the filter\n\tinput and output in your report. Is the result expected? Why or why\n\tnot?\n\t\n\t\n\n\\paragraph{Step 2.6} Create your own \\block{UserDefinedFun} block to implement convolution in J-DSP. \n\tTo test your function, make sure it works exactly like the \\block{Filter} block in J-DSP.\n\tUse the diagram in Figure \\ref{fg:userdefined} to plot the difference between your function output and the \\block{Filter} block output.\n\tUse the filter \\{1/3,1/3,1/3\\}, $n=\\{0,1,2\\}$ from step 2.5.\n\tNote: refer to section \\ref{sec:example} for how to use the \\block{UserDefinedFun} block in J-DSP.\n\t\n\t\\begin{figure}[t]\n\t    \\begin{center}\t     \n\t        \\includegraphics[width=4in]{lab6/userdefinedtest}\n\t        \\caption{A diagram to plot the difference between \\block{UserDefinedFun}\n\t         function output and the \\block{Filter} block output for use in step 2.6.}\n\t         \\label{fg:userdefined}\n\t    \\end{center}\n\t  \\end{figure}\n\t  \n\t  \n\n\\subsection{Canceling Sinusoidal Components}\n\nFilters can be designed to cancel sinusoids.  Construct a filter in\nJ-DSP with the following impulse response:\n\\begin{equation}\nh[n] = \\delta[n] - 2\\cos(\\pi/4) \\delta[n-1] + \\delta[n-2]\n\\end{equation}\n\n\\paragraph{Step 3.1} Plot the frequency response for this filter. What\n\tare the zero locations?\n\n\n\\paragraph{Step 3.2} Use as an input to this filter the signal $x[n] =\n\t\\sin\\hat{\\omega}n$, using the two frequencies $\\hat{\\omega} = \\pi/2$\n\tand $\\hat{\\omega} = \\pi/4$. Simulate the filter in J-DSP for each of\n\tthese two inputs. Plot the filter output for each. When do we get\n\tcancellation?\n\n\\paragraph{Step 3.3} Can you modify the filter coefficients to cancel\n\tthe other sinusoid? If so, show your work.\n\n\n\\subsection{Example User Defined J-DSP Function}\\label{sec:example}\nOpen J-DSP and navigate to the \\option{Advanced} function set. There\nis one block called \\block{UserDefinedFun}. Place it now and double\nclick to open the dialog.  You will see a dialog with example text for\na prototype java class.  In particular the class will look like:\n\\begin{lstlisting}\npublic void myCode(double[]x1,double[]x2, double[]y1, double[]y2,\n\t\tdouble[]b1,double[]a1, double[]b2, double[]a2, \n\t\tdouble para1, double para2, double para3)\n{\n  //                            /\\(3)\n  //                --------------------           \n  //           (0)<|                    |>(4)\n  //               |      BLOCK         |    \n  //           (1)<|                    |>(5)\n  //                --------------------           \n  //                            \\/(2)\n\n  // x1, x2 - input at pin 0 and pin1\n  // y1, y2 - output at pin 4 and pin5\n  // b1 - FIR Coefficients of the filter at input pin 2, \n  // a1 - IIR Coefficients of the filter at input pin 2\n  // b2 - FIR Coefficients of the filter at output pin 3, \n  // a2 - IIR Coefficients of the filter at output pin 3\n\n  // Para1, Para2 and Para3 are the variables that could be used \n  // in the code and can be controlled from the block Dialog.\n\n  // Paste your code here\n  // compile the file\n  // upload the .class file\n}\n\\end{lstlisting}\nYou can copy this code as a prototype and create your own signal\nprocessing algorithms!  For now, you will mainly deal with the $x$ and\n$y$ arrays. Each of the arrays is of length 256.  You can access this\nlike a any regular array in java, {\\it x1.length=256}. We also have\naccess to four variable length arrays, {\\it a1 a2 b1 b2} which contain\nany filter coefficients as inputs or outputs to the function.\n\nLets start by creating our own .java file. Copy the example code on\nthe next page and save it as a .java file using your favorite java\ntext editor or plain text editor. The example code creates a weighted\nsum of the entries in each index of {\\it x1}. Namely, it goes through\neach value of {\\it x1} and uses the {\\it b1} filter coefficients to\nweight and sum the value into {\\it y1}. Save the file as\n``MyFunction1.java'' and then compile the file using your favorite\ncompiler tool for java (javac from the command line works fine for\nlinux and mac or The Java SE Development Kit 6 (JDK 6) can be used in\nwindows). This creates ``MyFunction1.class.''\n\nAfter compiling, remember where you saved the ``MyFunction1.class''\ncompiled file. You will need to tell J-DSP where the file is\nlocated. Go back to the J-DSP block diagram and press\n\\button{open}. Navigate to the ``MyFunction1.class'' compiled file and\npress \\option{open}. That's it! J-DSP will automatically use the\nfunction when you attach inputs and outputs. To test the function we\njust made you can connect a \\block{SigGen} block to the top left pin\nand a \\block{Coeff} pin to the bottom as shown on page\n\\pageref{fg:userdefexample}. You should see a weighted sum of the\ninput when you plot the output. You should be able to change the\noutput by changing the weighting coefficients from \\block{Coeff}. In\nthe example on page \\pageref{fg:userdefexample} we are taking a\nweighted sum (using the weights in {\\it b1}) of each coefficient in\n{\\it x1} three times.  You are now ready to start developing your own\nfunctions in J-DSP!\n\n\\begin{lstlisting} \npublic class MyFunction1\n{\n  public void myCode(double[]x1,double[]x2, double[]y1, double[]y2,\n      double[]b1,double[]a1, double[]b2, double[]a2, \n      double para1, double para2, double para3)\n  {\n    //                            /\\(3)\n    //                --------------------           \n    //           (0)<|                    |>(4)\n    //               |      BLOCK         |    \n    //           (1)<|                    |>(5)\n    //                --------------------           \n    //                            \\/(2)\n\t\t\n    // x1, x2 - input at pin 0 and pin1\n    // y1, y2 - output at pin 4 and pin5\n    // b1 - FIR Coefficients of the filter at input pin 2, \n    // a1 - IIR Coefficients of the filter at input pin 2\n    // b2 - FIR Coefficients of the filter at output pin 3, \n    // a2 - IIR Coefficients of the filter at output pin 3\n\t\t\n    // Para1, Para2 and Para3 are the variables that could be used \n    // in the code and can be controlled from the block Dialog.\n\t\t\n    for( int i = 0 ; i < 256 ; i++)\n    {\n      y2[i] = 0;\n      for(int j=0 ; j < b1.length ; j++)\n      {\n        y2[i] += x1[i]*b1[j];\n      }\n\t\t\t\n    }\n    // Paste your code here\n    // compile the file\n    // upload the .class file\n  }\n}\n\\end{lstlisting}\n\n \\begin{figure}[h]\n    \\begin{center}     \n        \\includegraphics[width=6in]{lab6/function1examplewithplot}\n        \\caption{The result of using the weighted sum example code in J-DSP.}\n    \\end{center}\n    \\label{fg:userdefexample}\n  \\end{figure}\n\n\\subsection{Bonus: More $z$-Transforms and Convolutions}\n\nThe following properties of the $z$-transform may be useful here:\n\n\\begin{center}\n\\begin{tabular}{|l|c|c|} \\hline\nProperty      & Time Domain, $Z^{-1}\\{\\cdot\\}$ & z-Domain, $Z\\{\\cdot\\}$ \\\\ \\hline\\hline\nLinearity     & $a_1x[n]+a_2y[n]$ & $a_1X(z)+a_2Y(z)$\\\\ \nTime shift    & $x[n-k]$       & $z^{-k}X(z)$\\\\ \nScaling in the z-domain \n              & $a^nx[n]$        & $X(a^{-1}z)$ \\\\ \nTime reversal & $x[-n]$        & $X(z^{-1})$\\\\ \nDifferentiation in the z-domain \n              & $nx[n]$          & $-z \\deriv{X(z)}{z}$ \\\\ \nConvolution   & $x[n] \\ast y[n]$       & $X(z)Y(z)$ \\\\ \\hline\n\\end{tabular}\n\\end{center}\n\n\n\n\\paragraph{$z$-Transform of arbitrary sequences}\nGive the $z$-transform of the following sequences, $x[n]$ (assume\n$x[n]=0$ for all $n$ not stated):\n\\begin{enumerate}\n\\item $x[n]=\\{2, 4, 6, 4, 2\\}$, $n = \\{0, 1, 2, 3, 4\\}$\n\n\\item $x[n] = \\delta[n]$\n\n\\item $x[n] = \\delta[n-1]$\n\n\\item $x[n] = 2\\delta[n] - 3\\delta[n-1] +4\\delta[n-3]$\n\n\\item $x[n] = 2\\delta[n] + 4\\delta[n-1] + 6\\delta[n-2] + 4\\delta[n-3] + 2\\delta[n-4]$\n\\end{enumerate}\n\n\n\\paragraph{Inverse $z$-transforms}\nGive the inverse $z$-transform of $H(z) = 1 + 5z^{-1} - 3z^{-2} +\n2.5z^{-3} +4z^{-8}$.\n\n\\paragraph{Transfer function \\& impulse response}\nGive the transfer function and impulse response for a filter with\nzeros at $(r, \\hat{\\omega}) = \\{(1, 0), (1, \\pm \\pi/2), (0.9, \\pm\n\\pi/3)\\}$.\n\n% LocalWords:  WebQ MATLAB DSP\n", "meta": {"hexsha": "b326fc7f058b8a09b815e5b9f0a4392a1def17bb", "size": 13230, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "J-DSP Labs/lab6/lab6.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/lab6/lab6.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/lab6/lab6.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": 38.7976539589, "max_line_length": 136, "alphanum_fraction": 0.6584278156, "num_tokens": 4032, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970685907242, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7555196260008488}}
{"text": "\\subsection{Doubly Periodic Functions}\r\n\\begin{definition}\r\n    A meromorphic function $f$ on $\\mathbb C$ whose period contains $\\langle\\omega_1\\rangle\\oplus\\langle\\omega_2\\rangle\\cong\\mathbb Z^2$ is said to be doubly periodic or elliptic.\r\n\\end{definition}\r\nIn this case, $\\Omega$ is a lattice $\\Lambda$, so $f$ depends on a meromorphic function on $\\mathbb C/\\Lambda$.\r\n\\begin{proposition}\r\n    If $f$ is a meromorphic function on $\\mathbb C$ and the periods of $f$ contain a lattice $\\Lambda$, then there is a unique meromorphic function $\\bar{f}$ on the complex torus $\\mathbb C/\\Lambda$ such that $f(z)=\\bar{f}\\circ\\pi(z)$ where $\\pi:\\mathbb C\\to\\mathbb C/\\Lambda$ is the quotient map.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Same as Proposition \\ref{simply_periodic} by observing that $\\pi$, as a covering map, admits a local analytic inverse.\r\n\\end{proof}\r\nSo the elliptic functions on $\\mathbb C$ with $\\Lambda\\subset\\Omega$ corresponds to meromorphic functions on $\\mathbb C/\\Lambda$.\r\nThis means that we can apply our study in compact Riemann surfaces in doubly periodic functions.\r\n\\begin{corollary}\r\n    There is no doubly periodic analytic functions on $\\mathbb C$ other than constant maps.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Immediate.\r\n\\end{proof}\r\nAlso, since we can view a doubly periodic function $f$ as an analytic maps $\\bar{f}$ in the compact surface $\\mathbb C/\\Lambda$, we can make sense of its degree by writing $\\deg f=\\deg\\bar{f}$.\r\n\\begin{corollary}\\label{degree_doubly_periodic}\r\n    If $f:\\mathbb C\\to\\mathbb C_\\infty$ is doubly periodic and non-constant, then $\\deg f\\ge 2$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    If $\\deg f=1$, then $f$ is unramified so Riemann-Hurwitz gives $0=1(-2)+0=-2$, contradiction.\r\n\\end{proof}\r\nFor a lattice $\\Lambda=\\langle\\omega_1,\\omega_2\\rangle$, we construct the period parallelogram as the parallogram $P$ with vertices $z_0,z_0+\\omega_1,z_0+\\omega_2,z_0+\\omega_1\\omega_2$ for some fixed $z_0\\in\\mathbb C$ (usually $0$).\r\nSo $f$ is determined by its value on $P$.\r\n\\begin{proof}[Alternative proof of Corollary \\ref{degree_doubly_periodic}]\r\n    Choose $z_0$ so that no zeros nor poles of $f$ lie on $\\partial P$, which is possible as $\\mathbb C/\\Lambda$ is compact.\r\n    The residue theorem gives\r\n    $$\\sum_{z\\text{ pole in }P}\\operatorname{res}_z(f)=\\frac{1}{2\\pi i}\\int_{\\partial P}f(z)\\,\\mathrm dz=0$$\r\n    by the periodicity of $f$.\r\n    Hence either $f$ is no pole, which means $f$ is constant, or $f$ has at least two poles (counted with multiplicity), so $\\deg f\\ge 2$.\r\n\\end{proof}", "meta": {"hexsha": "165cae004206b350133615ea300e423d3dd059d1", "size": 2554, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "13/doubly.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/doubly.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/doubly.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": 72.9714285714, "max_line_length": 298, "alphanum_fraction": 0.7161315583, "num_tokens": 780, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8577680940822761, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.755519624140322}}
{"text": "\\documentclass[a4paper]{article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath, amssymb}\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{Proving The Power Rule}\n\\author{Dyson}\n\\date{\\today}\n\n\\newcommand{\\deriv}{\\dfrac{\\text{d}}{\\text{d}x}}\n\n\\begin{document}\n\n\\maketitle\n\n% Set paragraph spacing here to avoid messing with title\n\\setlength{\\parindent}{0em}\n\\setlength{\\parskip}{1em}\n\n\\section{The Conjecture}\n\nThe power rule states that for all $\\displaystyle n \\in \\mathbb{Z}, \\deriv x^n = nx^{n - 1}$. We want to prove this from first principles.\n\n\\section{The Proof}\n\n\\subsection{For The Naturals}\n\nProving the power rule for $n \\in \\mathbb{N}, 0 \\notin \\mathbb{N}$ is relatively easy and just involves some simple binomial expansion.\\\\\n\nLet $f(x) = x^n$.\n\nWe know that the derivate $f'(x)$ of $f(x)$ is defined as $$f'(x) = \\lim_{h \\to 0} \\left( \\frac{f(x + h) - f(x)}{h} \\right)$$\n\nIf we plug in our $f(x) = x^n$, then we get $$f'(x) = \\lim_{h \\to 0} \\left( \\frac{(x + h)^n - x^n}{h} \\right)$$\n\nWe need to cancel the $h$ before we let it go to 0. We can do this by expanding the binomial $(x + h)^n$ in the numerator like so: $$(x + h)^n = x^n + nx^{n - 1}h + \\binom{n}{2}x^{n - 2}h^2 + \\cdots + nxh^{n - 1} + h^n$$\n\nWe now have an $x^n$ term and a $-x^n$ term in the numerator. These cancel to give us $$\\lim_{h \\to 0} \\left( \\frac{nx^{n - 1}h + \\binom{n}{2}x^{n - 2}h^2 + \\cdots + nxh^{n - 1} + h^n}{h} \\right)$$\n\nWe can then factor out $h$ from the numerator and cancel like so: $$\\lim_{h \\to 0} \\left( \\frac{\\cancel{h} \\left( nx^{n - 1} + \\binom{n}{2}x^{n - 2}h + \\cdots + nxh^{n - 2} + h^{n - 1} \\right)}{\\cancel{h}} \\right)$$\n$$=\\lim_{h \\to 0} \\left(nx^{n - 1} + \\binom{n}{2}x^{n - 2}h + \\cdots + nxh^{n - 2} + h^{n - 1} \\right)$$\n\nWe can now let $h$ go to 0 and thereby show that $f'(x) = nx^{n - 1}$\n\n\\hspace*{\\fill}$\\square$\n\n\\subsection{For All Integers}\n\nProving the power rule for all $n \\in \\mathbb{Z}$ is a bit more complicated.\n\nWe know that the power rule would say $$\\deriv x^0 = 0x^{-1} = 0$$ We also know that $x^0$ is always 1, and the derivative of a constant is always 0, so the power rule holds for $n = 0$.\n\nTo prove it for negative integers, I'm going to prove that $$\\deriv x^{-n} = -nx^{-n-1}, n \\in \\mathbb{N}$$ because this is easier to prove and will expand the proof to all integers.\\\\\n\nLet $f(x) = x^{-n}$.\n\nWe plug this $f(x)$ into the definition and get $$f'(x) = \\lim_{h \\to 0}\\left( \\frac{(x + h)^{-n} - x^{-n}}{h} \\right)$$\n\nIf it's possible to expand binomials with negative powers, I don't know how to do it, but I do know that $a^{-b} = \\dfrac{1}{a^b}$, so we'll use that and focus on the numerator for now.\n\n\\begin{gather*}\n(x + h)^{-n} - x^{-n} = \\frac{1}{(x + h)^n} - \\frac{1}{x^n}\\\\[0.5em]\n= \\frac{x^n}{x^n(x + h)^n} - \\frac{(x + h)^n}{x^n(x + h)^n}\\\\[0.5em]\n= \\frac{x^n - (x + h)^n}{x^n(x + h)^n}\n\\end{gather*}\n\nWe're going to expand and simplify the numerator, so for the sake of simplicity, I'm leaving the denominator unexpanded for now.\n\n\\begin{gather*}\n\\frac{x^n - (x^n + nx^{n - 1}h + \\binom{n}{2}x^{n - 2}h^2 + \\cdots + nxh^{n - 1} + h^n)}{x^n(x + h)^n}\\\\[0.5em]\n= \\frac{-nx^{n - 1}h - \\binom{n}{2}x^{n - 2}h^2 - \\cdots - nxh^{n - 1} - h^n}{x^n(x + h)^n}\n\\end{gather*}\n\nNow, we're going to re-introduce $h$ before expanding the denominator.\n\nDividing a fraction by $h$ is the same as just multiplying the denominator by $h$.\n\n\\begin{gather*}\n\\frac{-nx^{n - 1}h - \\binom{n}{2}x^{n - 2}h^2 - \\cdots - nxh^{n - 1} - h^n}{x^n(x + h)^n} \\div h\\\\[0.5em]\n= \\frac{-nx^{n - 1}h - \\binom{n}{2}x^{n - 2}h^2 - \\cdots - nxh^{n - 1} - h^n}{hx^n(x + h)^n}\n\\end{gather*}\n\nWe can factor a $h$ out from the numerator and get $$\\frac{h(-nx^{n - 1} - \\binom{n}{2}x^{n - 2}h - \\cdots - nxh^{n - 2} - h^{n - 1})}{hx^n(x + h)^n}$$\n\nWe can now cancel the $h$ and expand the denominator.\n\n\\begin{gather*}\n\\frac{-nx^{n - 1} - \\binom{n}{2}x^{n - 2}h - \\cdots - nxh^{n - 2} - h^{n - 1}}{x^n(x^n + nx^{n - 1}h + \\binom{n}{2}x^{n - 2}h^2 + \\cdots + nxh^{n - 1} + h^n)}\\\\[0.5em]\n= \\frac{-nx^{n - 1} - \\binom{n}{2}x^{n - 2}h - \\cdots - nxh^{n - 2} - h^{n - 1}}{x^{2n} + nx^{2n - 1}h + \\binom{n}{2}x^{2n - 2}h^2 + \\cdots + nx^{n + 1}h^{n - 1} + x^nh^n}\n\\end{gather*}\n\nNow, we let $h$ go to 0 to get rid of all the $h$ terms and get left with $$\\dfrac{-nx^{n - 1}}{x^{2n}}$$\n\nBecause $\\dfrac{1}{x^{2n}} = x^{-2n}$, we can rewrite this as $$-nx^{n - 1}x^{-2n} = -nx^{n - 1 - 2n} = -nx^{-n - 1}$$\n\n\\hspace*{\\fill}$\\square$\n\nThe proof for negative integers is a bit longer and more involved. There's probably a much more elegant proof, but I'm pretty sure this one works, and I'm happy with it.\n\nThus, I have proved that for all $n \\in \\mathbb{Z}$, $\\deriv x^n = nx^{n - 1}$.\n\n\\end{document}\n", "meta": {"hexsha": "dd04eb3f2f2c0571c37ed21de455dfcc66390a07", "size": 4827, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Investigations/Power_Rule_Proof.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/Power_Rule_Proof.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/Power_Rule_Proof.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": 45.1121495327, "max_line_length": 220, "alphanum_fraction": 0.5951937021, "num_tokens": 1976, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782736, "lm_q2_score": 0.8499711718571774, "lm_q1q2_score": 0.7554193632207591}}
{"text": "\n\\chapter{Combination of Events}\n\n\\section{Important/Useful Theorems}\n\n\\subsection{}\nIf $A_1 \\subset A_2$ then $\\bar{A_1} \\supset \\bar{A_2}$\n\n\\subsection{}\nIf $A = A_1 \\cup A_2$ then $\\bar{A} = \\bar{A_1} \\cap \\bar{A_2}$\n\n\\subsection{}\nIf $A = A_1 \\cap A_2$ then $\\bar{A} = \\bar{A_1} \\cup \\bar{A_2}$\n\n\\subsection{}\n$0\\leq P(A) \\leq 1$\n\n\\subsection{}\n$P(A_1 \\cup A_2) = P(A_1) + P(A_2) - P(A_1 \\cap A_2 )$\n\n\\subsection{}\n\n$P(A_1) \\leq P(A_2)$ if $A_1 \\subset A_2$\n\n\\subsection{}\nGiven any $n$ events $A_1, A_2, ... A_n$, let\n\\begin{equation}\n\tP_1 = \\sum_{i=1}^{n} P(A_i)\n\\end{equation}\n\\begin{equation}\n\tP_2 = \\sum_{1 \\leq i < j \\leq n} P(A_iA_j)\n\\end{equation}\n\\begin{equation}\n\tP_3 = \\sum_{1 \\leq i < j < k \\leq n} P(A_i A_j A_k)\n\\end{equation}\netc. for integers up to $n$.  Then\n\\begin{equation}\n\tP\\left(\\bigcup_{k=1}^n A_k \\right) = P_1 -P_2 + P_3 + ... \\pm P_n\n\\end{equation}\n\n\\subsection{}\nIf $A_1, A_2, ...$ is an increasing sequence of events such that $A_1 \\subset A_2 \\subset ...$\n\\begin{equation}\n\tP\\left(\\bigcup_{k=1}^n A_k \\right) = \\lim_{n \\rightarrow \\infty} P(A_n)\n\\end{equation}\n\n\\subsection{}\nIf $A_1, A_2, ...$ is an decreasing sequence of events such that $A_1 \\supset A_2 \\supset ...$\n\\begin{equation}\n\tP\\left(\\bigcap_{k=1}^n A_k \\right) = \\lim_{n \\rightarrow \\infty} P(A_n)\n\\end{equation}\n\n\n\\subsection{}\nFor any collection of arbitrary events\n\\begin{equation}\n\tP\\left(\\bigcup_{k} A_k \\right) \\leq \\sum_k P(A_k)\n\\end{equation}\n\n\\subsection{}\nFor any sequence of events $A_1, A_2, ...$ with porbabilities $P(A_k)=p_k$\n\\begin{equation}\n\t\\sum_k p_k < \\infty\n\\end{equation}\n\n\\section{Answers to Problems}\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\\subsection{}\n%problem 2.1\n\\subsubsection{a--$AB=A$}\n$AB=A$ is shorthand for $A\\cap B=A$ or, in English, that the intersection of the events $A$ and $B$ is equivalent to the event $A$.  Clearly, this means that $A$ is equivalent to $B$ such that their overlap is complete--wither because they are exactly the same or because all outcomes in B are contained in A\n\\subsubsection{b--$ABC=A$}\n\nThe intersection $A$, $B$ and $C$ is equivalent to A. This implies that both $B$ and $C$ are either the same as $A$ or contained within $A$\n\n\\subsubsection{c--$A\\cup B\\cup C=A$}\n\nThe intersection of $A$, $B$ and $C$ is equivalent to $A$.  This statement implies that the overlap of $B$ and $C$ is $A$.  \n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 2.2\n\\subsubsection{a--$A \\cup B = \\bar{A}$}\n\nThe union of $A$ and $B$ is the complement of $A$.  This statement seems to imply that the sum of the events in both $A$ and $B$ are the same as the events NOT in A.  This seeming contradiction can only be true if $A$ as a set contains no events and $B$ contains all events.\n\n\n\\subsubsection{b--$AB=\\bar{A}$}\n\nThe intersection of $A$ and $B$ is equivalent to the complement of $A$.  This statement implies that the events contained in both $A$ and $B$ are the events NOT in $A$.  Again, this strange statement can be fulfilled if $A$ contains all events and $B$ contains no events \n\n\\subsubsection{c--$A \\cup B = A \\cap B$}\n\nThe union of $A$ and $B$ is equal to the intersection of $A$ and $B$.  This statement implies that the sum of all events in $A$ and $B$ is equivalent to the events in both $A$ and $B$.  This can be true, if $A=B$.\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 2.3\n\\subsubsection{a--$(A \\cup B)(B \\cup C)$}\n\nIn order to do this problem, we need to develop a distributive law for $\\cap$ and $\\cup$; we need to figure out what $A \\cup (B \\cap C)$ and $A \\cap (B \\cup C)$ is.\n\n$A \\cup (B \\cap C)$ is the union of A and the intersection of $B$ and $C$ which one can easily imagine is the same as the union of the intersection of the union of $A$ and $B$, and $A$ and $C$.  \n\n\\begin{equation}\n\tA \\cup (B \\cap C) = (A \\cup B) \\cap (A \\cup C)\n\\end{equation}\nsimilarly, for the second relation\n\\begin{equation}\n\tA \\cap (B \\cup C) = (A \\cap B) \\cup (A \\cap C)\n\\end{equation}\n\nALRIGHT  Back to the problem at hand\n\\begin{equation}\n\t(A \\cup B) \\cap (B \\cup C)=D\n\\end{equation}\nFor bookkeeping purposes, I have defined our expression to equal $D$.  Let's distribute...\n\\begin{equation}\n\t(A \\cap B) \\cup (A \\cap C)\\cup (B \\cap B)\\cup (B \\cap C)\n\\end{equation}\nclearly the intersection of $B$ and $B$ is just $B$\n\\begin{equation}\n\t(A \\cap B) \\cup (A \\cap C)\\cup B \\cup (B \\cap C)\n\\end{equation}\nlet's rearrange it to look like what we want to prove (cheap move, I know... but effective!).\n\\begin{equation}\n\t(AC\\cup B) \\cup \\left[(A \\cap B) \\cup (B \\cap C)\\right]=D\n\\end{equation}\nIf we could prove that the term in brackets is equal to $D$ then we would prove that $AC\\cup B=D$.  So let's work on that:\n\\begin{equation}\n\t(A \\cap B) \\cup (B \\cap C) = E\n\\end{equation}\nNow let's distribute\n\\begin{equation}\n\t(A \\cup B) \\cap (B \\cup C) \\cap (B \\cup B)\\cap (A \\cup C) = E\n\\end{equation}\nsimplify and rearrange\n\\begin{equation}\n\t\\left[(A \\cup B) \\cap (B \\cup C)\\right] \\cap B\\cap (A \\cup C) = E\n\\end{equation}\nwe recognize that the term in brackets is equivalent to the original expression we're trying to work with and then distribute one last time\n\\begin{equation}\n\tD \\cap \\left[(B \\cap A) (B \\cap C)\\right] = E\n\\end{equation}\nNow the term in brackets is equal to event $E$ meaning that $D=E$!  So we go back to the first equation.\n\\begin{equation}\n\t(AC\\cup B) \\cup D = D\n\\end{equation}\n\\begin{equation}\n\t(AC\\cup B) = D = (A \\cup B) \\cap (B \\cup C)\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified}\n\n\\subsubsection{b--$(A \\cup B)(A \\cup \\bar{B})$}\n\\begin{equation}\n\t(A \\cup B)\\cap (A \\cup \\bar{B})\n\\end{equation}\ndistribute out\n\\begin{equation}\n\t(A \\cap A)\\cup (A \\cap \\bar{B})\\cup (B \\cap A)\\cup (B \\cap \\bar{B})\n\\end{equation}\n$A$ will intersect with itself only at itself and $B$ will not intersect with its copmlement.\n\\begin{equation}\n\tA\\cup (A \\cap \\bar{B})\\cup (B \\cap A)\\cup 0\n\\end{equation}\nUnionizing the null set with anything else will leave the other things untouched.\n\\begin{equation}\n\tA\\cup (A \\cap \\bar{B})\\cup (B \\cap A)\n\\end{equation}\nNow we rearrange and redistribute.\n\\begin{equation}\n\tA\\cup \\left[  (A \\cup A) \\cap (A \\cup B) \\cap (A \\cup \\bar{B}) \\cap (B \\cup \\bar{B}) \\right]\n\\end{equation}\nClearly the sum of things in $B$ and not in $B$ is everything.\n\\begin{equation}\n\tA\\cup \\left[  A \\cap (A \\cup B) \\cap (A \\cup \\bar{B}) \\cap \\Omega \\right]\n\\end{equation}\nClearly the intersection of anything with everything is the same anything\n\\begin{equation}\n\tA\\cup \\left[  A \\cap (A \\cup B) \\cap (A \\cup \\bar{B}) \\right]\n\\end{equation}\nDistribute.\n\\begin{equation}\n\t(A\\cup A) \\cap \\left[  A \\cup (A \\cup B) \\right]\\cap \\left[  A \\cup (A \\cup \\bar{B}) \\right]\n\\end{equation}\n\\begin{equation}\n\tA \\cap \\left[  (A \\cup A) \\cup B \\right]\\cap \\left[  (A \\cup A) \\cup \\bar{B} \\right]\n\\end{equation}\n\\begin{equation}\n\tA \\cap \\left[  A \\cup B \\right]\\cap \\left[ A \\cup \\bar{B} \\right]\n\\end{equation}\nNow we call the original statement of the problem event $C$\n\\begin{equation}\n\tA \\cap C = C\n\\end{equation}\nWhich as we discussed in problem 2.1a, implies that $A=C$.  Therefore:\n\\begin{equation}\n\t(A \\cup B)(A \\cup \\bar{B}) = A\n\\label{answer2.3b}\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified}\n\n\\subsubsection{c--$(A \\cup B)(A \\cup \\bar{B})(\\bar{A} \\cup B)$}\nStart from the identity we just proved\n\\begin{equation}\n\t(A \\cup B)(A \\cup \\bar{B})(\\bar{A} \\cup B) = A \\cap (\\bar{A} \\cup B)\n\\end{equation}\nDistribute\n\\begin{equation}\n\t(A \\cap \\bar{A}) \\cup (A \\cap B)\n\\end{equation}\n\\begin{equation}\n\t0 \\cup AB\n\\end{equation}\n\\begin{equation}\n\tAB\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified} \n\n\\subsection{}\n%problem 2.4\nSolve for $X$:\n\\begin{equation}\n\t\\overline{(X \\cup A)} \\cup \\overline{(X \\cup \\overline{A})} = B\n\\end{equation}\nWe negate both sides and use DeMorgan's theorem\n\\begin{equation}\n\t(X \\cup A) \\cap (X \\cup \\overline{A}) = \\overline{B}\n\\end{equation}\nSince we just fought so hard to prove that $(A \\cup B)(B \\cup C) = AC \\cup B$, we want to use it!\n\\begin{equation}\n\t(A \\cup X) \\cap (X \\cup \\overline{A}) = \\overline{B}\n\\end{equation}\n\\begin{equation}\n\t(A \\overline{A}) \\cup X = \\overline{B}\n\\end{equation}\n\\begin{equation}\n\t0 \\cup X = \\overline{B}\n\\end{equation}\n\\begin{equation}\n\tX = \\overline{B}\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 2.5\n\n$A$ is the event that at least one of three inspected items is defective and $B$ is the event that all three inspected items are defective.  In this circumstance, the overlap of $A$ and $B$ ($A \\cap B$) is equal to $A$ since $A \\subset B$.  For similar reasons, the union of those two ($A \\cup B$) is simply equal to $B$.\n\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.6\n\nSince $B$ is the event a number ends in a zero, $\\overline{B}$ is the event a number does not end in a zero.  Thus, the overlap of that event and a number being divisible by 5 is the same as saying the event that a number is divisible by 5 and not divisible by 10.\n\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.7\n\nIt is easy to prove to oneself that these events $A_k$ are increasing such that $A_1 \\subset A_2 \\subset A_3 \\subset A_4 \\subset ... \\subset A_10$ since the radii of the disks are getting bigger.  Therefore, according to theorem 2.3 from the text\n\\begin{equation}\n\tB = \\bigcup_{k=1}^6 A_k = A_6\n\\end{equation}\nIntuitively, this is clear because we're taking the $A_6$ contains all the lower events so if you take the union of all the lower events then you're just adding parts of $A_6$ to itself.  Now, for\n\\begin{equation}\n\tC = \\bigcap_{k=5}^{10} A_k\n\\end{equation}\nwill clearly be $A_5$ because it's the smallest event and thus automatically sets the intersection to not be able to be any smaller.\n\n\\textbf{Answer verified}\n\n\n\\subsection{}\n%problem 2.8\nLuckily with just a bit of work, we can prove that the two statements are equivalent\n\\begin{equation}\n\tP(A) + P(\\overline{A}) = 1\n\\end{equation}\nTo prove this, we'll use the probability addition theorem for two events which will be $A$ and $\\overline{A}$ for us.\n\\begin{equation}\n\tP(A \\cup B) = P(A) + P(B) - P(A \\cap B)\n\\end{equation}\nsubstitute:\n\\begin{equation}\n\tP(A \\cup \\overline{A}) = P(A) + P(\\overline{A}) - P(A \\cap \\overline{A})\n\\end{equation}\nusing the fact that the union of anything with everything else is everything and that the intersection of anything with anything else is nothing...\n\\begin{equation}\n\tP(\\Omega) = P(A) + P(\\overline{A}) - P(0)\n\\end{equation}\nNow we use the fact that the probability of ell events is unity and the probability of no events is nothing.\n\\begin{equation}\n\t1 = P(A) + P(\\overline{A}) - 0\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 2.9\n\nI think this problem is as easy as it sounds since they're very clear to label the probabilities as belonging to the rings and the disk.  Thus, if you draw a picture of the bulls-eye it will become clear that the answer is just $1-.35-.30-.25=.10$ probability of missing.\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.10\n\nLet $A_i$ be the event where $i$ or fewer defective items are found; we're looking, then for the event $B$ that we find at least one defective item:\n\\begin{equation}\n\tB = \\bigcup_{i=1}^5 A_i\n\\end{equation}\n\\begin{equation}\n\tP(B) = P \\left( \\bigcup_{i=1}^5 A_i  \\right)\n\\end{equation}\nConsequently\n\\begin{equation}\n\tP(\\overline{B}) = P \\left( \\bigcup_{i=1}^5 \\overline{A_i}  \\right)\n\\end{equation}\nClearly $A_i$ are an increasing series of events so consequently, $\\overline{A_i}$ are a decreasing series of events and we can use theorem \n\\begin{equation}\n\tP(B) = 1- P(\\overline{B}) = 1- P ( \\overline{A_5} )\n\\end{equation}\n\nThis is saying the probability of rejecting the batch that has 5 bad items in it is 1 minus the probability of not finding 5 or fewer bad items: or of finding 5 good items.\n\nThere are $\\binom{100}{5}$ ways to pick 5 items from 100.  With 95 good items, there are $\\binom{95}{5}$ ways to pick up 5 good items.\n\\begin{equation}\n\tP = 1 - \\frac{\\binom{95}{5}}{\\binom{100}{5}} = 1 - \\frac{95!}{5! \\cdot 90! } \\frac{95! \\cdot 5!}{100!} = 1 - \\frac{95!}{90! } \\frac{95!}{100!}\n\\end{equation}\n\\begin{equation}\n\tP = 1 - \\frac{95\\cdot 94\\cdot 93\\cdot 92\\cdot 91}{100 \\cdot 99\\cdot 98\\cdot 97\\cdot 96} = \\frac{2478143}{10755360} = 0.23041\n\\label{answer2.10}\n\\end{equation}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 2.11\n\nThis problem boils down to the game you may have played as a kid to decide who got to go first or ride in the front of the car: I'm thinking of a number between 1 and 10.  Granted here the secretary gets to guess until she gets it right.  Let $A_i$ be the event that the secretary guesses just $i$ times (gets it right on the $i$th try). Thus we want:\n\\begin{equation}\n\tP(B) = P\\left(\\bigcup_{i=1}^4 A_i \\right) = \\sum_{i=1}^4 P(A_i)\n\\end{equation}\nThis factorization brought to you by the letter 'I` and the fact that you can't simultaneously get it right on the first try and get it right on the second try, meaning these events are mutually exclusive.  \n\nFor $i$ trials, there are $P^{10}_i$ possible ways to have tried.  Note that here order matters since we're talking about successive trials.  Consequently, there are $P^9_{i-1}$ ways to chose $i-1$ wrong numbers, giving\n\\begin{equation}\n\tP_i=\\frac{P^9_{i-1}}{P^{10}_i}=\\frac{1}{10}\n\\end{equation}\nThis answer, in itself, makes some sense although it does, at first glance, appear weird since you expect to gain an advantage as you learn about which numbers aren't correct.  In reality, there's 10 possible chances to get it right and you're no more likely to get it right on the first than on the second etc.; that's the best intuitive way to think about it.\n\\begin{equation}\n\tP(B) = \\sum_{i=1}^4 \\frac{1}{10} = .4\n\\end{equation}\nNow, if the secretary knew that the last number had to be even, that reduces our total number of possible numbers to 5 so the probability becomes:\n\\begin{equation}\n\tP_i=\\frac{P^4_{i-1}}{P^{5}_i}=\\frac{1}{5}\n\\end{equation}\nso instead we get\n\\begin{equation}\n\tP(B) = \\sum_{i=1}^4 \\frac{1}{5} = .8\n\\end{equation}\n\n\\textbf{Answer not verified}\n\n\n\\subsection{}\n%problem 2.12\nWe proved earlier that $P(A) = 1 - P(\\overline{A})$ so if we define\n\n\\begin{equation}\n\tB = \\bigcup_{k=1}^n A_k\n\\end{equation}\nthen we know\n\\begin{equation}\n\t\\overline{B} = \\bigcap_{k=1}^n \\overline{A_k}\n\\end{equation}\nand thus\n\\begin{equation}\n\t1 - P\\left(\\bigcup_{k=1}^n A_k\\right)  =P\\left( \\bigcap_{k=1}^n \\overline{A_k} \\right)\n\\end{equation}\n$\\Box$\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.13\n\nHere we need to find the probability that you get 5 good ones and the probability you get one bad one; their sum will be the probability that the batch passes.\n\nFor both probabilities, the total number of outcomes is equal to the total number of groups of 50 objects out of the 100 or $\\binom{100}{50} = 100891344545564193334812497256$.\n\nFor finding 5 good ones, there $\\binom{95}{50}$ ways to pick 50 good ones.  Additionally, there's $\\binom{95}{49}\\binom{5}{1}$ to get 49 good ones and one bad one.\n\n\\begin{equation}\n\tP = \\frac{\\binom{95}{50}+\\binom{95}{49}\\binom{5}{1}}{\\binom{100}{50}} = \\frac{1739}{9603} = 0.181089\n\\label{answer2.13}\n\\end{equation}\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 2.14\n\nTo solve this problem, you want to consider the people as buckets and the birthdays as things you put in the buckets.  As such, there are $365^r$ different possible ways for people to r people to have birthdays.  \n\nIn order to get the probability that at least one person shares a birthday, like we proved for the earlier problem, we need to just find the probability that no one shares a birthday and subtract that from 1.  \n\nFor the first person, there are 365 possibilities, 364 for the next, ad nauseum, giving $P^{365}_r$ ways of no one sharing a birthday.\n\n\\begin{equation}\n\tP(r) = 1 - \\frac{P^{365}_r}{365^r} = 1 - \\frac{365!}{365^r(365-r)!}\n\\label{answern2.14}\n\\end{equation}\n\\textbf{Answer verified by wikipedia}\n\n\\subsection{}\n%problem 2.15\n\nWe are asked to check how good the truncation of\n\\begin{equation}\n\t1-e^x = -\\sum_{n=1}^\\infty \\frac{x^n}{n!}\n\\end{equation}\nis for $n=3, 4, 5, 6$ at $x=-1$.  \n\\begin{equation}\n\t1-e^{-1} = 0.632121 \\approx 1 - \\frac{1}{2} + \\frac{1}{6} - \\frac{1}{24}  + \\frac{1}{120} - \\frac{1}{720} \n\\end{equation}\nThese truncations go as: $\\{0.666667,0.625,0.633333,0.631944\\}$ which relative to the exact answer are $\\{1.05465,0.988735,1.00192,0.999721\\}$\n\n\n\\textbf{Answer not verified}\n\n\\subsection{}\n%problem 2.16\n\nHere we have 4 events to look at: the probability that each player gets dealt a hand of one suit.  \n\\begin{equation}\n\tP_1 = P(A_1) + P(A_2) + P(A_3) + P(A_4) = 4P(A_i)\n\\end{equation}\n\\begin{equation}\n\tP_2 = P(A_1 A_2) + P(A_1 A_3) + P(A_1 A_4) + P(A_2 A_3) + P(A_2 A_4) + P(A_3 A_4) = 6 P(A_i A_j)\n\\end{equation}\nbecause each one of these is equivalent to the others (player 2 and 3 getting full hands is no more likely than player 4 and 1).  \n\\begin{equation}\n\tP_3 = P(A_1 A_2 A_3) + P(A_1 A_2 A_4) + P(A_1 A_3 A_4) + P(A_2 A_3 A_4) = 4 P(A_i A_j A_k)\n\\end{equation}\n\\begin{equation}\n\tP_4 = P(A_1 A_2 A_3 A_4)\n\\end{equation}\n\nFor one player's hand, there are $\\binom{52}{13}$ possibilities, only 4 of which are all the same suit.  For two players, the first player once again has $\\binom{52}{13}$ possibilities but that leaves only $\\binom{39}{13}$ for the second player (and $\\binom{26}{13}$ for the third) giving a total number of hands for two players as $\\binom{52}{13}\\binom{39}{13}$ and $\\binom{52}{13}\\binom{39}{13}\\binom{26}{13}$ for 3/4 players.\n\nFor 2 players, there are 4 possible hands for the first, leaving 3 for the second and giving 12 total desirable hands.  Consequently for three players, there are two more options giving 24 total desirable hands.\n\n\n\\begin{equation}\n\tP_1 =  4\\left(\\frac{4}{\\binom{52}{13}}\\right)\n\\end{equation}\n\\begin{equation}\n\tP_2 = 6\\left( \\frac{12}{\\binom{52}{13}\\binom{39}{13}} \\right)\n\\end{equation} \n\\begin{equation}\n\tP_3 = 4\\left( \\frac{24}{\\binom{52}{13}\\binom{39}{13}\\binom{26}{13}} \\right)\n\\end{equation}\n\\begin{equation}\n\tP_4 = \\frac{24}{\\binom{52}{13}\\binom{39}{13}\\binom{26}{13}}\n\\end{equation}\n\\begin{equation}\n\tP\\left(A_1 \\cup A_2 \\cup A_3 \\cup A_4\\right) = P_1 - P_2 +P_3 - P_4\n\\end{equation}\n\\begin{equation}\n\tP\\left(A_1 \\cup A_2 \\cup A_3 \\cup A_4\\right) = \\frac{16}{\\binom{52}{13}} - \\frac{72}{\\binom{52}{13}\\binom{39}{13}} + \\frac{72}{\\binom{52}{13}\\binom{39}{13}\\binom{26}{13}}\n\\label{answer2.16}\n\\end{equation}\nbecause I have mathematica and I'm feeling lazy at the moment, I am just going to forgo the Stirling's Approximation part and tell you:\n\\begin{equation}\n\tP\\left(A_1 \\cup A_2 \\cup A_3 \\cup A_4\\right) = \\frac{18772910672458601}{745065802298455456100520000} \\approx 2.5196312345 \\cdot 10^{-11}\n\\end{equation}\n\n\n\\textbf{Answer verified}\n\n\\subsection{}\n%problem 2.17\n\nSKIPPED\n\n\\begin{equation}\n\t0=0\n\\label{answer2.17}\n\\end{equation}\n\\textbf{Answer [not] verified}\n\n\\subsection{}\n%problem 2.18\n\nSKIPPED\n\n\\begin{equation}\n\t0=0\n\\label{answer2.18}\n\\end{equation}\n\\textbf{Answer [not] verified}\n\n\\subsection{}\n%problem 2.19\n\nSKIPPED\n\n\\begin{equation}\n\t0=0\n\\label{answer2.19}\n\\end{equation}\n\\textbf{Answer [not] verified}\n\n\n\n\n\n\n%%answer template\n%\\subsection{}\n%%problem n.n\n%\n%\n%\\begin{equation}\n%\t\n%\\label{answern.n}\n%\\end{equation}\n%\\textbf{Answer [not] verified}\n\n\n\n\n\n", "meta": {"hexsha": "77c8a9c31a6be10f8a278f50253390ffc03d0c3d", "size": 19406, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter2.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": "chapter2.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": "chapter2.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": 34.4689165187, "max_line_length": 428, "alphanum_fraction": 0.6898897248, "num_tokens": 6823, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587964389113, "lm_q2_score": 0.8499711775577736, "lm_q1q2_score": 0.7554193607740111}}
{"text": "\\subsection{Laminas}\r\n\\noindent\r\nSimilar to plane laminas:\r\n\\begin{equation*}\r\n\tM = \\iiint\\limits_{\\Omega}{\\sigma(x,y,z)\\mathrm{d}V}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\bar{x} = \\frac{M_{yz}}{M} = \\frac{\\iiint\\limits_{\\Omega}{x\\sigma(x,y,z)\\mathrm{d}V}}{M} \\text{, } \\bar{y} = \\frac{M_{xz}}{M} = \\frac{\\iiint\\limits_{\\Omega}{y\\sigma(x,y,z)\\mathrm{d}V}}{M} \\text{, and } \\bar{z} = \\frac{M_{xy}}{M} = \\frac{\\iiint\\limits_{\\Omega}{z\\sigma(x,y,z)\\mathrm{d}V}}{M}\r\n\\end{equation*}", "meta": {"hexsha": "ec4345ac8312ef2edd4dbb9cdf1abdfc164fd141", "size": 478, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/multipleIntegrals/planeLaminas_triple.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/multipleIntegrals/planeLaminas_triple.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/multipleIntegrals/planeLaminas_triple.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 53.1111111111, "max_line_length": 292, "alphanum_fraction": 0.6171548117, "num_tokens": 211, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9433475746920262, "lm_q2_score": 0.8006920044739461, "lm_q1q2_score": 0.755330860495794}}
{"text": "\\subsection{Exponential}\r\n\\noindent\r\nLet $a$ be a constant.\\\\\r\nBy definitions of a Laplace transform and an improper integral,\r\n\\begin{align*}\r\n\t\\Laplace{e^{at}} &= \\lim\\limits_{n\\to\\infty}{\\int_{0}^{n}{e^{at}e^{-st}\\mathrm{d}t}} \\\\\r\n\t &= \\lim\\limits_{n\\to\\infty}{\\int_{0}^{\\infty}{e^{(a-s)t} \\mathrm{d}t}} \\\\\r\n\t &= \\frac{1}{a-s}\\lim\\limits_{n\\to\\infty}{\\left[e^{(a-s)n}\\right]}_{0}^{n} \\text{, } s \\neq a \\\\\r\n\t &= \\frac{1}{a-s}\\lim\\limits_{n\\to\\infty}{\\left(e^{(a-s)n} - 1\\right)} \\text{, } s \\neq a \\\\\r\n\t &= \\begin{cases}\r\n\t \t\\frac{-1}{a-s} & s > a \\\\\r\n\t \t\\text{DNE} & s \\leq a\r\n\t \\end{cases}.\r\n\\end{align*}\r\nSo,\r\n\\begin{equation*}\r\n\t\\Laplace{e^{at}} = \\frac{-1}{a-s} \\text{, } s > a.\r\n\\end{equation*}", "meta": {"hexsha": "fad841c74e66ad87eb83b5531f2395a8db4d3c96", "size": 703, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/laplaceTransforms/derivations/exponential.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/derivations/exponential.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/derivations/exponential.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 39.0555555556, "max_line_length": 98, "alphanum_fraction": 0.5533428165, "num_tokens": 316, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9111797003640646, "lm_q2_score": 0.8289388104343892, "lm_q1q2_score": 0.7553122169117509}}
{"text": "%!TEX root =  ../main.tex\n\n\\objective{Understand and simplify the relationships between logs, powers, and roots.}\n\n\\subsection{The Three Components}\nOur modern mathematical notation obfuscates one relationship with three, different notations. \nThe following equations all express the same things:\n\\begin{enumerate}\n\\item $\\log_2{8}=3$\n\\item $2^3=8$\n\\item $\\sqrt[3]{8}=2$\n\\end{enumerate}\n\nAll three embody the same relationship: 2 is the base, 3 is the exponent, and 8 is result.  \nThree elements suggest a three-sided shape, a \\emph{triangle of power}.\n$\\tripow{2}{3}{8}$\n\nLeaving off any side of the triangle of power suggests that the missing number is needed.\n\\begin{enumerate}\n\\item $\\log_2{8}$ can be represented as $\\tripow{2}{}{8}$\n\\item $2^3$ can be represented as $\\tripow{2}{3}{}$\n\\item $\\sqrt[3]{8}$ can be represented as $\\tripow{}{3}{8}$\n\\end{enumerate}\n\nSome people complain that this new notation ruins the line height, that is is too tall.\nBut these pedants rarely write\\\\ \n$(2\\div(3+4))\\div((5+6)\\div(7+8))$.  Indeed, it is preferable to see:\n\n$$\\frac{\\frac{2}{3+4}}{\\frac{5+6}{7+8}}$$\n\nIn the same way, one might write $2\\triangle^3$, $2\\triangle_8$, and $\\triangle^3_8$,\nbut expand in two-dimensions when the occasion permits.\n\n\\subsection{Inverses}\nThe true usefulness of the triangle of power is revealed when we try to present more\ncomplicated relationships.  Some students immediately grasp what $e^{\\ln{x}}$ is saying,\nothers struggle for years with the notation.  \\emph{There is a power we can put on \\emph{e}\nto get \\emph{x}.  Raise \\emph{e} to that power.}  If you get it, the answer is obviously $x$.\nBut the symbols certainly don't help you see it.  Instead, triangles make the relationship \nmore obvious: \n\n\\begin{equation}\n\\tripow{e}{ \\tripow{e}{}{x}}{}=x \\quad \\text{vs} \\quad e^{\\ln{x}}\n\\end{equation}\n\nThe top triangle is blank in the same place it occupies in the larger triangle.  Because the\n$e$'s are in the same place, everything cancels, leaving only the $x$.  \nOther hard expressions which are simple inverses are equally obscure in traditional notation,\nand quite clear in triangle form:\n\\begin{equation}\n\\tripow{}{e}{\\scriptstyle \\tripow{x}{e}{}} = x \\quad \\text{vs} \\quad \\sqrt[e]{x^e} = x\n\\end{equation}\n\\begin{equation}\n\\tripow{\\tripow{}{e}{x}}{2}{} = x \\quad \\text{vs} \\quad \\sqrt[e]{x}^e = x\n\\end{equation}\n\\begin{equation}\n\\tripow{e}{}{\\tripow{e}{x}{}} = x \\quad \\text{vs} \\quad \\ln{e^x} = x\n\\end{equation}\n\\begin{equation}\n\\tripow{}{\\tripow{x}{}{e}}{e} = x \\quad \\text{vs} \\quad \\sqrt[\\log_x{e}]{e} = x\n\\end{equation}\n\\begin{equation}\\tripow{\\tripow{}{x}{e}}{}{e} = x \\quad \\text{vs} \\quad \\log_{\\sqrt[x]{e}}{e} = x\n\\end{equation}\n\n\n\\subsection{P-Plus}\nThe properties of logs, exponents, and roots become much more transparent in triangle notation.\nFor example, the sum of exponents look like this:\n$$\\tripow{b}{m}{}\\cdot{}\\tripow{b}{n}{}=\\tripow{b}{m+n}{}$$\n\nWe shall see that this bears a strong resemblance to a similar property of logs:\n$$\\tripow{b}{}{m} + \\tripow{b}{}{n} = \\tripow{b}{}{m+n}$$\n\nGraphically, keeping the base the same but switching from exponent to result changes where\nthe addition and multiplication happen.  You will make all the various versions of the rules in the\nexercises and problems, but there is one relationship which might appear overly perplexing at first.\nConsider the products of roots:\n\n$$\n\\tripow{}{x}{z} \\cdot{} \\tripow{}{y}{z}\n$$\n\nWe have not had occasion to contemplate this before.  What operation should govern this \nrelationship?  Given the thorough treatment of rational exponents in chapter 5, perhaps it would\nbe more clear for you to rewrite this problem as fractional powers:\n\n{\\Large\n$$z^{\\frac{1}{x}} \\cdot z^{\\frac{1}{y}}$$\n}\n\nThe answer is a root which is the sum of the reciprocals of $x$ and $y$, or a power which is the\nreciprocal of that!  This unusual operation is actually rather common in practical applications and\ndeserving of its own symbol in this book, $\\pplus$.  This symbol was chosen because\nthe reciprocal of the sum of reciprocal is used in parallel resistance, whose symbol is $\\parallel$.\n\n\n\\begin{derivation}{P-plus}\n$$x\\pplus y = \\cfrac{1}{\\frac{1}{x}+\\frac{1}{y}} = \\cfrac{1}{\\frac{y}{xy}+\\frac{x}{xy}} = \n\\cfrac{1}{\\frac{x+y}{xy}} = \\frac{xy}{x+y}$$\n\\end{derivation}\n\n\nThis strange operation is necessary in a world where power and roots are reciprocals of\neach other:\n$$\n\\tripow{a}{x}{} = \\tripow{}{\\frac{1}{x}}{a}\n$$\n\nThere are many more intriguing relationship that can be written clearly and intuitively\non the Triangle of Power, e.g. $\\tripow{m}{}{x}\\pplus\\tripow{n}{}{x} = \\tripow{m\\cdot{}n}{}{x}$\nor $\\tripow{x}{}{a}\\cdot{}\\tripow{a}{}{y} = \\tripow{x}{}{y}$  You are encouraged to experiment\nand tinker with this powerful tool.\n", "meta": {"hexsha": "fb0a17de71689988d9a281cf65b1b205a329117c", "size": 4762, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ch07/0701.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/0701.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/0701.tex", "max_forks_repo_name": "aquatiki/AnalysisTextbook", "max_forks_repo_head_hexsha": "011c16427ada1b1e3df8e66c02566a5d5ac8abcf", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 42.1415929204, "max_line_length": 100, "alphanum_fraction": 0.7068458631, "num_tokens": 1491, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278726384089, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7552269052912447}}
{"text": "\\paragraph{Empirical distribution function} (shortly e.d.f.)\nbased on a sample $X = \\sample$ is a function:\n%Empirical distribution function:\n%\\[ \\hat{F_n}(t; X_1, \\ldots , X_n) = \\frac{1}{n} \\Sigma_{i=1}^n I_{(-\\infty,t]} (X_i)\n%\\; , \\; t \\in R \\]\n\\[ \\hat{F}_n(x) = \\frac{\\#\\{i: X_i \\leq x\\}}{n} \\mbox{ or, defined in other way:} \\]\n\\[ \\hat{F}_n(x) = \\frac{1}{n} \\sum_{i=1}^{n} I_{(-\\infty,x]} (X_i) \n\\mbox{ , where }\nI_n(x) = \\begin{cases} 1 \\mbox{ if } x \\in A \\\\ 0 \\mbox{ otherwise} \\end{cases} \\]\n\nThe e.d.f. is a cumulative distribution function based not no the whole population, but only the sample.\n\n\\paragraph{Glivenko cantelli lemma}\n\nLet $\\sample$ i.i.d. $F$ and let $\\hat{F}_n$ denote the empirical distribution\nfunction based on this sample. Then:\n\\[  P ( \\lim_{n \\rightarrow \\infty}  \\sup_{x \\in R} | \\hat{F}_n(x) - F(x) | = 0 ) = 1 \\]\n\nThis lemma tells us that when sample size is tending to infinity, then the maximum difference\nbetween e.d.f. and cumulative d.f. of the whole population will tend to zero.\n\n\\paragraph{Statistical space}\n\\[  \\statspace \\]\n\\noindent where:\n\\begin{itemize}[noitemsep,nolistsep]\n  \\item $\\mathcal{H}$ is sample space\n  \n  \\item $\\mathcal{A}$ is $\\sigma$-algebra of $\\mathcal{H}$\n  \n  \\item $\\mathcal{P}$ is a family of distributions\n  \n  \\item $\\theta$ is value of the parameter\n  \n  \\item $\\Theta$ is family of parameters\n\\end{itemize}\n\n\\paragraph{Sufficient statistic}\nis a such statistic that is guaranteed to get us as much information as any statistic based on at\nmost the same sample size.\n\nA statistic is said to be sufficient for the parameter $\\param$ (for a family $\\mathcal{P}$) iff the\nconditional probability (given below) does not depend on $\\param$ for any value $t$ on statistic\n$T$.\n\\begin{gather*}\n\\Pr(X=x|T(X)=t,\\theta) = \\Pr(X=x|T(X)=t)\\\\\n\\Pr(x|t,\\theta) = \\Pr(x|t)\n\\end{gather*}\n\n%\\[ \\]\n\n\\paragraph{Factorization criteria}\nstates that a statistic $T$ is sufficient iff $\\exists$ the following factorization:\n\\[ p_\\param(\\sample) = g_\\param(T(\\sample)) h(\\sample) \\]\n\\noindent where:\n\\begin{itemize}[noitemsep,nolistsep]\n  \\item $p_\\param$ is a distribution under study\n  \n  \\item $g$ depends on $\\param$ and a sample but only through $T$\n  \n  \\item $h$ is independent of $\\theta$\n\\end{itemize}\n\n\\paragraph{Family of k-parametric exponential distributions}\ncontains those distributions that satisfy the following:\n\\[ p_\\theta(x) = h(x) \\exp{ \\left\\{ \\sum_{j=1}^k C_j(\\theta)S_j(x) + B(\\theta) \\right\\}  } \\]\n\nwhere $S_1, \\ldots, S_k$ are linearly independent.\n", "meta": {"hexsha": "1c5c65ab695b1231b7af5ffc6fed4a080dc775be", "size": 2528, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cs_3_probability_adv.tex", "max_stars_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_stars_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cs_3_probability_adv.tex", "max_issues_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_issues_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cs_3_probability_adv.tex", "max_forks_repo_name": "mbdevpl/wut-bsc-computer-statistics-formulas", "max_forks_repo_head_hexsha": "ce5febce6f6fc680c445257ca263962a0a76a688", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.1764705882, "max_line_length": 104, "alphanum_fraction": 0.6756329114, "num_tokens": 830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544911, "lm_q2_score": 0.8558511488056151, "lm_q1q2_score": 0.7552269032431641}}
{"text": "\\subsubsection{Lucas\\textquotesingle \\ Theorem}\n\tFor non-negative integer $n,m$ and prime $p$, $\\binom{m}{n}\\equiv\\prod_{i=0}^k\\binom{m_i}{n_i}\\pmod p$\\\\\n\twhere $m_i$ is the $i$-th digit of $m$ in base $p$.\n\\subsubsection{Sum of Two Squares Thm (Legendre)}\n\tFor a given positive integer $n$, let\\\\\n\t$D_1 =$ (\\# of positive integers $d$ dividing $N$ that $1\\equiv d\\pmod 4$)\\\\\n\t$D_3 =$ (\\# of positive integers $d$ dividing $N$ that $3\\equiv d\\pmod 4$)\\\\\n\tthen $n$ can be written as a sum of two squares in exactly\\\\\n\t$R(n) = 4(D_1-D_3)$ ways.\n\\subsubsection{Difference of D1-D3 Thm}\n\tlet $n = 2^t \\cdot (p_1^{e_1} \\cdot ... \\cdot p_r^{e_r}) \\cdots (q_1^{f_1} \\cdot ... \\cdot q_s^{f_s})$\\\\\n\twhere $p_i, q_i$ are primes and $1 \\equiv p_i\\pmod 4 , 3 \\equiv q_i\\pmod 4$\\\\\n\tthen $D_1 - D_3$ = \\begin{cases}\n  $(e_1+1)(e_2+1)...(e_r+1)$, & \\text{if (}$f_i$\\text{)s all even}\\\\\n\t$0$,& \\text{if any }$f_i$\\text{ is odd}\n  \\end{cases}\n\\subsubsection{Krush–Kuhn–Tucker Conditions}\n\\begin{body}\n  \\textbf{Stationarity}\\\\\n  For maximizing $f(x)$: $\\nabla f(x^*) = \\sum_{i=1}^m \\mu_i \\nabla g_i(x^*) + \\sum_{j=1}^l \\lambda_j \\nabla h_j(x^*)$\\\\\n  For minimizing $f(x)$: $-\\nabla f(x^*) = \\sum_{i=1}^m \\mu_i \\nabla g_i(x^*) + \\sum_{j=1}^l \\lambda_j \\nabla h_j(x^*)$ \\\\\n\\\\\n  \\textbf{Primal feasibility}\\\\\n  $g_i(x^*) \\le 0, \\mbox{ for all } i = 1, \\ldots, m$\\\\\n  $h_j(x^*) = 0, \\mbox{ for all } j = 1, \\ldots, l \\,\\!$\\\\\n\\\\\n  \\textbf{Dual feasibility}\\\\\n  $\\mu_i \\ge 0, \\mbox{ for all } i = 1, \\ldots, m$\\\\\n\\\\\n  \\textbf{Complementary slackness}\\\\\n  $\\mu_i g_i (x^*) = 0, \\mbox{for all}\\; i = 1,\\ldots,m$\n\\end{body}\n\\subsubsection{Chinese remainder theorem}\n\\begin{body}\n  $x \\equiv r_i \\mod p_i $\\\\\n  $N = \\prod p_i$\\\\\n  $N_i = N / p_i$\\\\\n  $x \\equiv \\sum r_i N_i (N_i)^{-1}_{p_i} \\mod N$\n\\end{body}\n", "meta": {"hexsha": "d1a0a0478ba9048af25083d0145be3743ae29f26", "size": 1783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "collection/cp/bcw_codebook-master/codes/Math/theorem.tex", "max_stars_repo_name": "daemonslayer/Notebook", "max_stars_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-03-24T13:12:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-24T13:12:01.000Z", "max_issues_repo_path": "collection/cp/bcw_codebook-master/codes/Math/theorem.tex", "max_issues_repo_name": "daemonslayer/Notebook", "max_issues_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "collection/cp/bcw_codebook-master/codes/Math/theorem.tex", "max_forks_repo_name": "daemonslayer/Notebook", "max_forks_repo_head_hexsha": "a9880be9bd86955afd6b8f7352822bc18673eda3", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.575, "max_line_length": 122, "alphanum_fraction": 0.596186203, "num_tokens": 800, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9263037363973295, "lm_q2_score": 0.815232489352, "lm_q1q2_score": 0.7551529009192538}}
{"text": "\\section{Two-point boundary problems and finite element discretization}\nDenote the functional space\n$$\nV:=H^1_0(0,1)=\\{v:\\, [0,1]\\rightarrow R,\\,\\,\\mbox{$v$ is continuous and}\\, v(0)=v(1)=0\\}.\n$$\nGiven any $f: [0,1]\\rightarrow R$, consider \n\\begin{equation*}\nJ(v)=\\frac12\\int_{0}^1|v'|^2dx-\\int_{0}^1 fvdx.\n\\end{equation*}\nFind $u\\in V$ such that \n\\begin{equation}\\label{minvar}\n\\displaystyle u=\\argmin_{v\\in V} J(v)\\quad\n\\end{equation}\n\\begin{theorem}\nProblem \\eqref{minvar} is equivalent to: Find $u\\in V$ such that \n\\begin{equation}\\label{1Dpossion}\n\\left\\{\n\\begin{aligned}\n-u''&= f, \\,\\, 0<x<1, \\\\\n u(0)&=u(1)=0.\n\\end{aligned}\n\\right.\n\\end{equation}\n\\end{theorem}\n\\begin{proof}\nFor any $v\\in V, t\\in R$, let $g(t)=J(u+t v)$. \nSince $u=\\argmin_{v\\in V} J(v)$ means $g(t)\\ge g(0)$. Hence, for any $v\\in V$, $0$ is the global minimum of the function $g(t)$. Therefore\n$g'(0)=0$ implies \n$$\n\\int_{0}^1 u'v'dx=\\int_0^1fvdx\\quad \\forall v\\in V. \n$$\nBy integration by parts, which is equivalent to \n$$\n\\int_{0}^1 (-u''-f)vdx=0\\quad \\forall v\\in V. \n$$\nIt can be proved that the above identity holds if and only if \n$-u''= f$ for all $x\\in (0,1)$. Namely $u$ satisfies \\eqref{1Dpossion}. \n\\end{proof}\n\nLet $V_h$ be finite element space and $\\{\\varphi_1, \\varphi_2, \\cdots \\varphi_{n}\\}$ be a nodal basis of $V_h$. \n%Let $\\{\\psi_1,\\psi_2,\\cdots, \\psi_{n}\\}$ be a dual basis of $\\{\\varphi_1, \\varphi_2, \\cdots \\varphi_{n}\\}$, namely $(\\varphi_i,\\psi_j )=\\delta_{ij}$.\n\\begin{equation}\nJ(v_h)=\\frac12\\int_0^1|v_h'|^2dx-\\int_0^1fv_hdx.\n\\end{equation}\nLet \n$$\n\\displaystyle v_h=\\sum_{i=1}^{n}\\nu_i\\varphi_i,\\quad \\nu=(\\nu_i)_{i=1}^{n}\n$$\nthen using the convolution notation, we have\n$$\nJ(v_h)=I(\\nu)=\\frac12\\nu^TA\\ast\\nu-b^T\\nu\n$$\nand \n$$\n\\nabla I(\\nu) =A\\ast \\nu -b,\n$$\nwhere $A=\\frac{1}{h}[-1,2, -1]$.\n\nAt the same time, let $\\displaystyle u_h=\\sum_{i=1}^{n}\\mu_i\\varphi_i,$\n\\begin{equation}\\label{min1d}\n\\displaystyle u_h=\\argmin_{v_h\\in V_h} J(v_h)\\Leftrightarrow \\mu=\\argmin_{\\nu \\in R^n} I(\\nu)\n\\end{equation}\nAnd $u_h$ solves the problem: Find $u_h\\in V_h$\n\\begin{equation}\\label{1ddiscrevar}\n\\frac{d}{dt}J(u_h+t v_h)|_{t=0}=a(u_h,v_h)-\\langle f, v_h\\rangle=0 \\quad \\forall v_h\\in V_h. \n\\end{equation}\nwhere \n$$\na(u_h,v_h)=\\int_0^1 u_h'v_h'dx.\n$$\n\n\\begin{theorem}\\label{thm:best-approximation}\nLet $V$ be a Hilbert space, $a(\\cdot,\\cdot)$ be a continuous,\nsymmetric, bilinear form defining an inner product on $V$. Let\n$f(\\cdot)$ be a continuous linear form. If $u$ is solution to the\nproblem~\\eqref{minvar} and $u_h$ is a solution\nto~\\eqref{min1d}, then the following equality holds:\n\\begin{equation}\\label{eq:best-approx}\n\\|u-u_h\\|_a = \\inf_{v\\in V_h}\\|u-v\\|_a,\n\\end{equation}\nwhere $\\|u-u_h\\|^2_a = a(u-u_h,u-u_h)$. \n\\end{theorem}\n\n\\begin{proof}\nFrist, one sees that\n$$\na(u-u_h, v)=0,~~~\\forall v\\in V_h.\n$$\nThus, for any $v\\in V_h$ we have\n\\begin{eqnarray*}\n& &\\|u-u_h\\|_a^2=a(u-u_h, u-u_h)\\\\[0.2cm]\n&=& a(u-u_h, u-v)\\\\[0.2cm]\n&\\le& \\|u-u_h\\|_a\\|u-v\\|_a.\n\\end{eqnarray*}\nTaking the infimum on both sides of this equation then gives. \n$$\n\\|u-u_h\\|_a\\le \\inf_{v\\in V_h}\\|u-v\\|_a.\n$$\nThe proof is complete, since \n\\[\n\\|u-u_h\\|_a\\ge \\inf_{v\\in V_h}\\|u-v\\|_a,\n\\]\nby the definition of infimum. \n\\end{proof}\nCombining Theorem \\ref{interp00} and Theorem \\ref{thm:best-approximation}, we obtain the error estimate for the finite element method. \n\\begin{theorem}\nIf $u\\in H^2(\\Omega)$ is solution to the\nproblem~\\eqref{1Dpossion} and $u_h$ is a solution to~\\eqref{min1d}, then we have:\n\\begin{equation}\n \\|u-u_h\\|+h |u-u_h|_{1}\\lc h^2 |u|_2.\n   \\end{equation}\n \\end{theorem}\n\n", "meta": {"hexsha": "1c875b0f664b9e01c1f6af4f2e884511732cec1a", "size": 3568, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.1-1Dvariational.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.1-1Dvariational.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.1-1Dvariational.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.298245614, "max_line_length": 150, "alphanum_fraction": 0.6561098655, "num_tokens": 1505, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066293, "lm_q2_score": 0.8947894710123925, "lm_q1q2_score": 0.7551084594306924}}
{"text": "\\chapter{Vector Calculus}\n\n\\section{Formalism}\nA \\textbf{set} is defined as an unordered unique collection of elements. For example $\\mathcal{S}_1 = {1,2,5},\\mathcal{S}_2 = {3,5,9}$. The intersection of a set is defined as \n$\\mathcal{S}_1\\cap \\mathcal{S}_2 = \\mathcal{S}_3 $\n\\begin{align}\n\t\\{1,2,5\\}\\cap \\{3,5,9\\} = \\{5\\}\n\\end{align}\nSimilarly the union of a set $\\mathcal{S}_1\\cup \\mathcal{S}_2 = \\mathcal{S}_4$ is defined as\n\\begin{align}\n\t\\{1,2,5\\}\\cup \\{3,5,9\\} = \\{1,2,3,5,9\\}\n\\end{align}\n\n\\subsection{Einstein notation}\nTypically to avoid writing $\\sum$'s all over the place there is a short hand for repeated indices with\n\\begin{align}\\label{einstein_notation}\n\\textbf{a}\\cdot\\textbf{b} = \\sum_{i=1}^3 a_ib_i = a_ib_i\n\\end{align}\nWhere $i = x,y,z$. This notation is called Einstein notation.\n\n\n\\subsection{Levi-Cevita Symbol}\n Levi-Civita symbol ($\\varepsilon_{ijk}$)  is an antisymmetric tensor and is equal to $1$ if the components are in order right to left (i.e. $ijk = 123$ or $312$ or $231$), is $-1$ if the are out of order, and 0 if not a cycle (i.e. $ijk = 122$). Some useful identities while using tensor notation are\n \\begin{align}\n \\varepsilon_{ijk}\\varepsilon_{imn} = \\delta_{jm}\\delta_{kn} - \\delta_{jn}\\delta_{km}\n \\end{align}\n\n\n\\subsection{Reducing Vector Identities to Components}\nFor order of operations, remember that you just take the curl before doing the divergence! A nice way to break down complicated vector functions is to break them down into components. For instance\n\\begin{align}\n(\\textbf{A} \\times \\textbf{B})_i = \\epsilon_{ijk}A_jB_k\n\\end{align}\nWhere the summation over $j$ and $k$ is implied. An example of how it is used is given below\n\\begin{align}\n\\nabla\\cdot\\textbf{A}\\times\\textbf{B} &= \\sum \\partial_i(\\epsilon_{ijk}A_jB_k) \\\\\n&= \\partial_0(\\epsilon_{012}A_1B_2 + \\epsilon_{021}A_2B_1) + ...\\\\\n&= B_2\\partial_0A_1 + A_1\\partial_0B_2 - B_1\\partial_0A_2 - A_2\\partial_0B_1 + ...\\\\\n&= (\\nabla\\times\\textbf{A})\\cdot\\textbf{B} - \\textbf{A}\\cdot(\\nabla\\times\\textbf{B})\n\\end{align}\nAnother nice identity, in somewhat sloppy notation is\n\\begin{align}\n\t\\nabla r = \\partial_i r &= \\partial_i \\sqrt{\\sum r_j^2} = \\frac{1}{2}\\frac{1}{\\sqrt{\\sum r_j^2}}\\partial_ir_j^2\\\\\n\t&= \\frac{1}{r}\\delta_{ij} r_j\\\\\n\t&= \\frac{r_i}{r} = \\hat{r}\n\\end{align}\n\n\n\n\\section{Special Functions}\n\\subsection{Complete and Orthogonal Sets of Functions}\nA set of eigenfunctions $\\psi_n$ is said to be \\emph{complete} on the interval $a\\le x\\le b$, if we can write any function as some linear combination of those eigenfunctions \n\\begin{align}\\label{complete}\nf(x) = \\sum_{n=0}^\\infty A_n \\psi_n(x) && a\\le x\\le b\n\\end{align}\nThis property actually falls out of the \\emph{closure relation}\n\\begin{align}\n\\sum_n \\psi_n(x)\\psi_n^*(x') = \\delta(x-x')\n\\end{align}\nsince \n\\begin{align}\nf(x) &= \\int_a^b dx' \\delta(x-x')f(x')\\\\\n&= \\sum_n \\psi_n(x) \\int dx' \\psi_n^*(x') f(x')\n\\end{align}\nWhich lets us find the coefficients, matching terms with equation \\ref{complete}\n\\begin{align}\nA_n = \\int_{a}^b dx f(x)\\psi^*_n(x)\n\\end{align}\nUsing $f(x) = \\psi_m(x)$ we see that\n\\begin{align}\n\\psi_m(x) = \\sum_n \\psi_n(x) \\int dx' \\psi_n^*(x') \\psi_m(x')\n\\end{align}\nWhich, because we are summing orthogonal functions, we have to have the integral in the sum evaluate to\n\\begin{align}\n \\int dx' \\psi_n^*(x') \\psi_m(x') = \\delta_{nm}\n\\end{align}\nThis is the \\emph{orthonormal} relation. A simple example is with sines and cosines, with the relation\n\\begin{align}\n\\int_0^\\pi dx\\sin (mx)\\sin (m'x) = \\frac{\\pi}{2}\\delta_{mm'}\n\\end{align}\nWhich can be remembered putting the trigfunctions in exponential form because\n\\begin{align}\n\\int_0^{2\\pi} d\\theta~ e^{i(m-m')\\theta} = 2\\pi\\delta_{mm'}\n\\end{align}\n\n\n\\subsection{Polynomials}\n%TOD Polynomials are also complete (?) so we can Taylor expand.\n\n\n\\subsection{Legendre Polynomials}\\label{legendrepoly}\nIn Electrodynamics, it is common when looking at potentials to have expressions that look like\n\\begin{align}\n\\frac{1}{|\\textbf{r} - \\textbf{r}'|} = \\frac{1}{r\\sqrt{1-2\\frac{r'}{r}\\cos\\theta + \\frac{r'^2}{r^2}}}\n\\end{align}\n\nWhere $\\theta$ is the angle between $\\textbf{r}$, the point you are looking at and $\\textbf{r}'$ the location of the charge. Conveniently, the Legendre Polynomials are defined as \n\n\\begin{equation}\\label{legendre}\n\\frac{1}{\\sqrt{1-2xt+t^2}} \\equiv \\sum_{l=0}^\\infty t^l P_l(x)\n\\end{equation}\nSo taking $t = \\frac{r'}{r}$ and $x = \\cos\\theta$, we can write\n\n\\begin{align}\n\\frac{1}{|\\textbf{r} - \\textbf{r}'|} = \\frac{1}{r} \\sum_{l=0}^\\infty \\Big(\\frac{r'}{r}\\Big)^l P_l(\\cos\\theta) && r' < r\n\\end{align}\nWe can also expand in the opposite case, just dividing a bit differently, yielding\n\\begin{align}\n\\frac{1}{|\\textbf{r} - \\textbf{r}'|} = \\frac{1}{r'} \\sum_{l=0}^\\infty \\Big(\\frac{r}{r'}\\Big)^l P_l(\\cos\\theta) && r < r'\n\\end{align}\nThese are easy to remember thinking about how they look at zero. The first few are given by\n\\begin{align}\nP_0(x) &= 1\\\\\nP_1(x) &= x\\\\\nP_2(x) &= \\frac{1}{2}(3x^2 -1)\n\\end{align}\n\nOne nice thing to remember is that the subscript tells us the highest power of the polynomial in the series. If you ever need to derive these on a test, you can just Taylor expand equation \\ref{legendre} to find them. These function also obey a nice set of properties that are usually exploited in various Electrostatic problems. They are complete (up to a constant), with\n\n\\begin{align}\n\\int^1_{-1} dx~ P_n(x) P_{m}(x) &= \\frac{2}{2n+1}\\delta_{nm}\n\\end{align}\nand \n\\begin{align}\n\\sum_{n=0}^\\infty \\frac{2n+1}{2}P_n(x)P_n(x') &= \\delta(x-x')\n\\end{align}\nThey are also somewhat symmetric with respect to $x$, with\n\\begin{align}\nP_n(-x) = (-1)^nP_n(x)\n\\end{align}\nIt also happens that for any polynomial \n\\begin{align}\nP_n(1) = 1\n\\end{align}\nWhich can be seen because Equation \\ref{legendre} breaks down into the equation for a Geometric series\n\\begin{align}\n\\frac{1}{\\sqrt{(1-t)^2}} = \\frac{1}{1-t} = 1 + t + t^2 + t^3 + ...\n\\end{align}\n\n\n%The Legendre polynomials can also be written using Rodrigues' formula with\n%\\begin{align}\n%P_l(x) = \\frac{1}{2^nn!}~\\frac{d^n}{dx^n} (x^2-1)^n\n%\\end{align}\n\nThe Legendre Polynomials can also be defined as the solution to the differential equation\n\\begin{align}\\label{legendrediffeq}\n\\frac{d}{dx}\\Big[(1-x^2)\\frac{d}{dx} P_n(x)\\Big] + n(n+1)P_n(x) = 0\n\\end{align}\n\n\n\n\n\n\n\\subsection{Associated Legendre Polynomials}\n\nBy just taking the derivative of the standard Legendre polynomials with respect to $x$ a total of $m$ times then multiplying by some extra stuff, we get a whole bunch of new equations that also happen to be very important with\n\\begin{align}\\label{associated}\nP^m_l(x) = (-1)^m(1-x^2)^{m/2}\\frac{d^m}{dx^m}P_l(x)\n\\end{align}\nWe can then find negative $m$ ones with\n\\begin{align}\nP^{-m}_l = (-1)^m\\frac{(l-m)!}{(l+m)!}P_l^m\n\\end{align}\nThey are also solutions to the differential equation\n\\begin{align}\\label{associatedlegendre}\n\\frac{d}{dx}\\Big[(1-x^2)\\frac{d}{dx}P_l^m(x)\\Big] + \\Big[l(l+1) - \\frac{m^2}{1-x^2}\\Big]P_l^m(x) = 0\n\\end{align}\n\nIt turns out that the associated Legendre polynomials aren't even in general actual polynomials, but just carry the name from the their relation to the Legendre generating function. The first few go like\n\\begin{align}\nP_0^0(x) &= 1\\\\\nP_1^{-1}(x) &= -\\frac{1}{2}P_1^1(x)\\\\\nP_1^0(x) &= x\\\\ \nP_1^1(x) &= -(1-x^2)^{1/2}\n\\end{align}\nWhere all of the associated Legendre polynomials should be identical to the regular Legendre polynomials when $m = 0$ as seen in equation \\ref{associated}.\n\n\n\n\\subsection{Spherical Harmonics}\n\n\nTypical notation goes as \n\\begin{align}\n\\int d\\Omega = \\int_0^{2\\pi} d\\phi \\int_0^\\pi d\\theta \\sin\\theta\n\\end{align}\nWhere $\\Omega$ is called the \\emph{solid angle}. These guys are also orthonormal (note the complex conjugate!)\n\n\\begin{align}\n\\int d\\Omega~Y^*_{lm}(\\Omega)Y_{l'm'}(\\Omega) = \\delta_{ll'}\\delta_{mm'}\n\\end{align}\n\nThey're analogous to $\\sin\\theta$  except in two dimensions instead of just one. They are also complete with\n\n\\begin{align}\n\\sum_{l=0}^\\infty \\sum_{m=-l}^l Y^*_{lm}(\\Omega)Y_{l'm'}(\\Omega) = \\frac{1}{\\sin\\theta}\\delta(\\theta-\\theta')\\delta(\\phi-\\phi')\n\\end{align}\n\nWhen we have spherical, but non-azimuthal symmetry when using Laplace's equation, since the argument is actually $P_l(\\cos\\gamma)$, where $\\gamma$ is the angle between one point in spherical coordinates ($\\theta,\\phi$) and another ($\\theta',\\phi'$) , we can expand the Legendre Polynomials in terms of the Spherical Harmonics, since they are complete.\n\n\\begin{align}\nP_l(\\cos\\gamma) = \\frac{4\\pi}{2l+1}\\sum_{m=-l}^l Y_{lm}^*(\\theta', \\phi')Y_{lm}(\\theta,\\phi)\n\\end{align}\n\n\nTheir polar portion come from the associated Legendre polynomials, with\n\\begin{align}\nY^m_l(\\theta,\\phi) \\sim P_l^m(\\cos\\theta)e^{im\\phi}\n\\end{align}\n\n\n\\begin{align}\nY^{m*}_{l}= (-1)^mY^{-m}_l\n\\end{align}\nThe first few look like\n\n\\begin{align}\nY_0^0 &= \\Big(\\frac{1}{4\\pi}\\Big)^{1/2}\\\\\nY_1^0 &= \\Big(\\frac{3}{4\\pi}\\Big)^{1/2}\\cos\\theta\\\\\nY_1^{\\pm 1} &= \\mp \\Big(\\frac{3}{8\\pi}\\Big)^{1/2}\\sin\\theta e^{\\pm i\\phi}\n\\end{align}\n\nA nice trick to evaluating certain integrals is recognizing how to put Cartesian variables into the forms of spherical harmonics, with\n\\begin{align}\nx &= r\\sin\\theta \\cos\\phi = r\\sqrt{\\frac{2\\pi}{3}}\\Big(Y^{-1}_1 - Y^1_1\\Big)\\\\\ny &= r\\sin\\theta\\sin\\phi = ir\\sqrt{\\frac{2\\pi}{3}}\\Big(Y^{-1}_1 + Y^1_1\\Big)\\\\\nz &= r\\cos\\theta = 2r\\sqrt{\\frac{\\pi}{3}}Y_1^0\n\\end{align}\n\n\n\\subsection{Bessel Functions}\\label{bessel}\n\nThese show up in Laplace's equation in Cylindrical coordinates. $J(x)$ is the Bessel function of the first kind, and $N(x)$ the Bessel function of the second kind. Often in problem we can get rid of the second kind ones since\n\\begin{align}\nN_\\alpha(x\\rightarrow 0) =-\\infty\n\\end{align}\n\n\nIn the limit of $x\\gg 1$, they break down into a somewhat more palatable form, with\n\\begin{align}\nJ_\\alpha \\sim \\frac{1}{\\sqrt{x}}\\cos\\Big(x - \\phi(\\alpha)\\Big)\\\\\nN_\\alpha \\sim \\frac{1}{\\sqrt{x}}\\sin\\Big(x - \\phi(\\alpha)\\Big)\n\\end{align}\nWhere $\\phi(\\alpha)$ is some phase dependent on $\\alpha$ \n\n%They can be found through iteration of the formula\n%\\begin{align}\n%\\frac{d}{dx}\\Big(\\frac{J_m(x)}{x^m}\\Big) = -\\frac{J_{m+1}}{x^m}\n%\\end{align}\n\n\\subsection{Spherical Bessel Functions}\nThese come from the radial portion of the Helmholtz equation in spherical coordinates\n\\begin{align}\nj_l(x) &= (-x)^l \\Big(\\frac{1}{x}\\frac{d}{dx}\\Big)^l~\\frac{\\sin x}{x}\\\\\ny_l(x) &= -(-x)^l\\Big(\\frac{1}{x}\\frac{d}{dx}\\Big)^l~\\frac{\\cos x}{x}\n\\end{align}\nThe first one is known as the (unnormalized) sinc function with\n\\begin{align}\nj_0(x) = \\frac{\\sin x}{x}\n\\end{align}\n\n\\subsection{Airy Functions}\nWhen looking at linear potentials in quantum mechanics, which happen when looking at the first order Taylor expansion on a potential wall, the Schrodinger equation usually boils down (after $u$ substituting away the constant energy term) into the form of\n\\begin{align}\n0 = \\Big(\\frac{d^2}{dx^2} - x\\Big) \\psi(x)\n\\end{align}\nThis equation is solved by\n\\begin{align}\n\\psi(x) = a\\textrm{Ai}(x) + b\\textrm{Bi}(x)\n\\end{align}\nI don't imagine we will ever need to know much more about this function outside of its limits, which look like\n\\begin{align}\n\\textrm{Ai}(x) &\\approx e^{-x} && x\\gg 0\\\\\n\\textrm{Bi}(x) &\\approx e^{x} && x\\gg 0\\\\\n\\end{align}\nThese functions are not symmetric about the origin (because of the non-symmetric potential $x$) which causes them to look differently when $x$ is negative, with\n\\begin{align}\n\\textrm{Ai}(x) &\\approx \\sin x && x\\ll 0\\\\\n\\textrm{Bi}(x) &\\approx \\cos x && x\\ll 0\\\\\n\\end{align}\nIntuitively, this happens because the energy is greater than the potential on one side, which swaps signs at the origin. which changes the exponential oscillation into growth or decay.\n\n\\subsection{Dirac Delta Function}\nThe Dirac delta function in other coordinate systems can be found knowing that always\n\\begin{align}\n\\int_{-\\infty}^\\infty dx \\delta(x-x') = 1\n\\end{align}\nAs long as the region you are integrating over contains $x'$. Extrapolating to Cylindrical\n\\begin{align}\n\\int dr^3 \\delta(\\textbf{r}-\\textbf{r}') = \\int_0^{2\\pi} d\\theta \\int_{-\\infty}^\\infty dz \\int_0^\\infty dr r ~\\delta(\\textbf{r}-\\textbf{r}') = 1\n\\end{align}\nThis tells us that in \\textbf{cylindrical} coordinates\n\\begin{align}\n\\delta(\\textbf{r}-\\textbf{r}') = \\frac{1}{r}\\delta(r-r')\\delta(\\theta-\\theta')\\delta(z-z')\n\\end{align}\nSimilarly in \\textbf{spherical} coordinates\n\\begin{align}\n\\delta(\\textbf{r}-\\textbf{r}') = \\frac{1}{r^2\\sin\\theta}\\delta(r-r')\\delta(\\theta-\\theta')\\delta(\\phi-\\phi')\n\\end{align}\n\n\n\n\n\n\\subsection{Heaviside Function}\nIncidentally not named because one side is \"heavier\" than the other but actually from Oliver Heaviside\n\\begin{align}\nH(x) =\n\\begin{cases}\n0 & x < 0\\\\\n1 & x\\ge 0\n\\end{cases}\\\\\n\\end{align}\n\nIt also has an infinite slope at the origin, so the derivative of it is in fact the Dirac delta function\n\\begin{align}\n\\frac{d}{dx} H(x) = \\delta(x)\n\\end{align}\n\n\nThis function is also useful in expressing charge densities as it implicitly changes the bounds of integrals. For instance if we have a charged disk with charge per unit area $\\sigma = Q/\\pi R^2$, we can express the volume charge density knowing that\n\n\\begin{align}\nQ = \\int dr^3 \\rho(\\textbf{r}) = \\int_{-\\infty}^\\infty dz \\int_0^{2\\pi} d\\theta \\int_0^\\infty dr~r \\sigma f(z)g(\\theta)h(r)\n\\end{align}\nCharge is only in the middle where $z=0$, so\n\\begin{align}\nf(z) = \\delta(z)\n\\end{align}\nCharge distribution is independent of $\\theta$, so\n\\begin{align}\ng(\\theta) = 1\n\\end{align}\nCharge distribution only extends to $r=R$, and everything else will make the integral evaulate to $\\sigma\\pi R^2$ so\n\\begin{align}\nh(r) = H(R-r)\n\\end{align}\nTherefore we have\n\\begin{align}\n\\rho(\\textbf{r}) = \\delta(z)H(R-r)\n\\end{align}\n\n\n\n\n\n\\subsection{Green's Functions}\\label{green}\nIn Physics, there are often times where you are given some differential equation that looks like\n\\begin{align}\\label{lindifeq}\nL u(x) = f(x)\n\\end{align}\nWhere $L$ is some linear differential operator, like $d/dx$ or $(3x+d^2/dx^2)$. The idea with Green's functions is that it is often easier to solve the equation\n\\begin{align}\nL G(x,s) = \\delta(x-s)\n\\end{align}\nWhere $s$ is an arbitrary parameter that $L$ does not act on. By only solving this equation, we can add up any arbitrary amount of delta functions that we want, thus reconstructing $f(x)$, and incidentally get an expression for $u(x)$, with\n\\begin{align}\nL\\Big(\\int ds~G(x,s)f(s)\\Big) = \\int ds~\\delta(x-s) f(s) = f(x)\n\\end{align}\nBy comparing this equation to equation \\ref{lindifeq}, we see that\n\\begin{align}\nu(x) = \\int ds~G(x,s)f(s)\n\\end{align}\nSo if we have both the Green's function and $f(x)$, we can plug it into this expression to solve for $u(x)$. % Solving for Green's function's is also usually tough, but can be done in a few ways... TODO\n\n\n\n\\subsection{Riemann-Zeta Function}\n\nDefined as\n\\begin{align}\n\t\\zeta(s) = \\frac{1}{\\Gamma(s)} \\int_{0}^{\\infty} \\frac{1}{e ^ x - 1}\\,x ^ s \\frac{\\mathrm{d}x}{x} \n\\end{align}\nFor all (potentially complex) $s$ with real part greater than 1. This integral shows up often in Bose-Einstein statistics integrals. It can also be defined as \n\\begin{align}\n\t\\zeta(s) = \\sum_{n=1}^\\infty n^{-s} = \\frac{1}{1^s} + \\frac{1}{2^s} + \\frac{1}{3^s} + ...\n\\end{align}\n\n\\begin{multicols}{2}\n\tThis looks not so bad, but, remember $s$ is potentially a \\emph{complex} number, which makes these functions nutty. See the picture to the right, which is a plot of the Riemann-Zeta function as a function of a complex number $\\zeta(z)$ This summation is the \\emph{analytic continuation} of this series if it were just a real number. \n\\columnbreak\n\n\n\n\t%\\includegraphics[width=0.5\\textwidth]{img/Riemann-Zeta-Func.png}\n\n\n\\end{multicols}\n\n\n\n\n\\section{Non-Cartesian Geometries}\n\nThe best way to remember these is remembering the gradient in whichever coordinate system\n\\begin{align}\n\\nabla f = \\rm{whatever}\n\\end{align}\nAnd also the divergence\n\\begin{align}\n\\nabla\\cdot\\textbf{A} = \\rm{something}\n\\end{align}\nThen using the identity\n\\begin{align}\n\\nabla^2 f = \\nabla\\cdot\\nabla f\n\\end{align}\nto get the Laplacian\n\n\n\\subsection{Spherical Coordinates}\\label{sphere}\nTaking $\\theta$ as the polar angle (goes from 0 to $\\pi$) and $\\phi$ as the azimuthal angle (goes from $0$ to $2\\pi$), we have the relations that\n\\begin{align}\\label{sphere}\nx &= r\\sin\\theta\\cos\\phi\\\\\ny &= r\\sin\\theta\\sin\\phi\\\\\nz &= r\\cos\\theta\n\\end{align}\nThe gradient is given by\n\\begin{align}\n\\nabla f = \\frac{\\partial f}{\\partial r}\\hat{r} +\\frac{1}{r}\\frac{\\partial f}{\\partial \\theta}\\hat{\\theta} + \\frac{1}{r\\sin\\theta}\\frac{\\partial f}{\\partial\\phi}\\hat{\\phi}\n\\end{align}\nAnd the divergence\n\\begin{align}\n\\nabla\\cdot\\textbf{A} = \\frac{1}{r^2}\\frac{\\partial(r^2A_r)}{\\partial r} + \\frac{1}{r\\sin\\theta}\\frac{\\partial}{\\partial\\theta}(A_\\theta\\sin\\theta) + \\frac{1}{r\\sin\\theta}\\frac{\\partial A_\\phi}{\\partial\\phi}\n\\end{align}\nUsing the method outlined before, the Laplacian in Spherical coordinates is then given as\n\\begin{align}\n\\nabla^2\\equiv \\frac{1}{r^2} \\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial}{\\partial r}\\Big) + \\frac{1}{r^2\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial}{\\partial\\theta}\\Big) +\\frac{1}{r^2\\sin^2\\theta}\\frac{\\partial^2}{\\partial\\phi^2} \n\\end{align}\nWe can also show that \n\\begin{align}\\label{dirac}\n\\boxed{\\nabla^2 ~\\frac{1}{r}= -\\nabla\\cdot\\frac{\\hat{r}}{r^2} = -4\\pi\\delta(\\textbf{r})}\n\\end{align}\nSince\n\\begin{align}\n\\int d^3r ~\\delta(\\textbf{r}) = 1\n\\end{align}\nAnd\n\\begin{align}\n\\int d^3r \\nabla^2\\Big(\\frac{1}{r}\\Big) = \\int d^3r \\nabla\\cdot\\nabla\\Big(\\frac{1}{r}\\Big) = \\int d^3 r \\nabla\\cdot -\\frac{1}{r^2}\\hat{r}\n\\end{align}\nThis looks like it is zero now, but using Gauss' law we see that\n\\begin{align}\n- \\int d^3 r \\nabla\\cdot \\frac{1}{r^2}\\hat{r} = -\\int d\\textbf{S}\\cdot \\frac{1}{r^2}\\hat{r} = -\\int_0^{2\\pi}d\\phi\\int_{-1}^1 d(\\cos\\theta) = -4\\pi\n\\end{align}\nWhere we converted the volume integral on the left to a \\emph{surface} integral which does not depend on $r$ at all. Thus we see we can match the integrands, giving us the result of equation \\ref{dirac}.\n\\begin{align}\n\\begin{bmatrix}\\mathbf{\\hat x} \\\\ \\mathbf{\\hat y}  \\\\ \\mathbf{\\hat z} \\end{bmatrix}\n  = \\begin{bmatrix} \\sin\\theta\\cos\\phi & \\cos\\theta\\cos\\phi & -\\sin\\phi \\\\\n                    \\sin\\theta\\sin\\phi & \\cos\\theta\\sin\\phi &  \\cos\\phi \\\\\n                    \\cos\\theta         & -\\sin\\theta        & 0 \\end{bmatrix}\n    \\begin{bmatrix} \\boldsymbol{\\hat\\rho} \\\\ \\boldsymbol{\\hat\\theta} \\\\ \\boldsymbol{\\hat\\phi} \\end{bmatrix}\n\\end{align}\nAn easy way to \"derive\" these in a pinch is looking at equation \\ref{sphere}, then taking the derivative in the order $r,\\theta,\\phi$, getting rid of all the terms dependent on the last variable as you proceed (elaborate more).\n\n\n\\subsection{Cylindrical Coordinates}\nThe gradient is\n\\begin{align}\n\\nabla f = \\frac{\\partial f}{\\partial \\rho}\\hat{\\rho} + \\frac{1}{\\rho}\\frac{\\partial f}{\\partial \\theta}\\hat{\\theta} + \\frac{\\partial f}{\\partial z}\\hat{z}\n\\end{align}\nThe divergence is\n\\begin{align}\n\\nabla\\cdot\\textbf{A} = {1 \\over \\rho}{\\partial \\left( \\rho A_\\rho  \\right) \\over \\partial \\rho}\n+ {1 \\over \\rho}{\\partial A_\\theta \\over \\partial \\theta}\n+ {\\partial A_z \\over \\partial z}\n\\end{align}\nThis gives the Laplacian as\n\\begin{align}\n\\nabla^2 f = {1 \\over \\rho}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial f \\over \\partial \\rho}\\right)\n+ {1 \\over \\rho^2}{\\partial^2 f \\over \\partial \\theta^2}\n+ {\\partial^2 f \\over \\partial z^2}\n\\end{align}\n\n\n\\begin{align}\n\\begin{bmatrix}\\mathbf{\\hat r} \\\\ \\boldsymbol{\\hat\\theta} \\\\ \\mathbf{\\hat z}\\end{bmatrix}\n  = \\begin{bmatrix} \\cos\\theta & \\sin\\theta & 0 \\\\\n                   -\\sin\\theta & \\cos\\theta & 0 \\\\\n                   0 & 0 & 1 \\end{bmatrix}\n    \\begin{bmatrix} \\mathbf{\\hat x} \\\\ \\mathbf{\\hat y} \\\\ \\mathbf{\\hat z} \\end{bmatrix}\t\n\\end{align}\n\n\\section{Vector Calculus}\n\n\\begin{align}\n\\nabla\\cdot u\\textbf{v} = \\nabla u\\cdot\\textbf{v} + u\\nabla\\cdot\\textbf{v}\n\\end{align}\n\\subsection{Spherical Poisson Equation}\nLet's say we have a differential equation that looks like\n\\begin{align}\n\\Big[\\nabla^2 -k^2 + f(r)\\Big]\\psi(r,\\theta,\\phi) = 0\n\\end{align}\nWe first assume separability of the function\n\\begin{align}\n\\psi(r,\\theta,\\phi) = R(r)Y(\\theta,\\phi)\n\\end{align}\nUse the spherical Laplacian (Section \\ref{sphere}) to turn the equation into\n\\begin{align}\n\\frac{Y}{r^2}\\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial R}{\\partial r}\\Big) + \\frac{R}{r^2\\sin\\theta}\\frac{\\partial} {\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial Y}{\\partial \\theta}\\Big) + \\frac{R}{r^2\\sin^2\\theta}\\frac{\\partial^2 Y}{\\partial\\phi^2}+\\Big(k^2 -f(r)\\Big)RY= 0\n\\end{align}\nNow we can divide everything by $YR/r^2$ to get\n\\begin{align}\n&\\Big[\\frac{1}{R}\\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial R}{\\partial r}\\Big) -\\Big(k^2 - f(r)\\Big)r^2\\Big]\\\\\n&+ \\Big[ \\frac{1}{Y\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial Y}{\\partial\\theta}\\Big) + \\frac{1}{Y\\sin^2\\theta}\\frac{\\partial^2 Y}{\\partial\\phi^2}\\Big] = 0\n\\end{align}\nBecause we can isolate all of the variables together and they are all independent of each other, each of the equations in brackets alone must be equal at least to a constant that cancels out. So calling that constant $C$ we have\n\\begin{align}\n\\frac{1}{R}\\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial R}{\\partial r}\\Big) -\\Big(k^2-f(r)\\Big)r^2 &= C\\\\\n\\frac{1}{Y\\sin\\theta}\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial Y}{\\partial\\theta}\\Big) + \\frac{1}{Y\\sin^2\\theta}\\frac{\\partial^2 Y}{\\partial\\phi^2} &= -C\n\\end{align}\n\\begin{itemize}\n\\item Let's take a tangent and pretend that the solution is not dependent on $\\phi$ at all (Azimuthal symmetry), then our equation becomes\n\\begin{align}\\label{radiallegendre}\n\\frac{1}{Y\\sin\\theta}\\frac{\\partial}{\\partial \\theta}\\Big(\\sin\\theta\\frac{\\partial Y}{\\partial\\theta}\\Big) =-C\n\\end{align}\n\\item We can create a new variable\n\\begin{align}\\label{xsub}\nx = \\cos\\theta \\rightarrow \\frac{\\partial}{\\partial\\theta} &=\\frac{dx}{d\\theta} \\frac{\\partial}{\\partial x}\\\\\n&= -\\sin\\theta\\frac{\\partial}{\\partial x}\n\\end{align}\n\\item Rewriting equation \\ref{radiallegendre} in terms of $x$, we see that\n\\begin{align}\n\\frac{1}{Y}\\frac{\\partial}{\\partial x}\\Big(\\sin^2\\theta\\frac{\\partial Y}{\\partial x}\\Big) = -C\n\\end{align}\n\\item Using $\\sin^2\\theta = 1-\\cos^2\\theta = 1-x^2$, we get the differential in the form\n\\begin{align}\n\\frac{d}{dx}\\Big((1-x^2)\\frac{d}{dx}Y\\Big) + CY = 0\n\\end{align}\nWhich is the exact form of the Legendre Polynomials in equation \\ref{legendrediffeq} with $C = l(l+1)$ and $Y(\\theta) = P_l(\\cos\\theta)$. Thus we see if we have azimuthal symmetry, we are free to use these for things to solve Laplace's equation.\n\\end{itemize}\nFrom now on, we write $C = l(l+1)$, because of the reduction to Legendre polynomials that happens when we have no angular dependence. Looking now at the angular portion, we again use seperation of variables\n\\begin{align}\nY(\\theta,\\phi) = \\Theta(\\theta)\\Phi(\\phi)\n\\end{align}\nWe plug this into the angular equation and moving things around we get\n\\begin{align}\n\\frac{1}{\\Theta}\\Big[\\sin\\theta\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial \\Theta}{\\partial\\theta}\\Big)\\Big] +l(l+1)\\sin^2\\theta  &= -\\frac{1}{\\Phi}\\frac{\\partial^2 \\Phi}{\\partial\\phi^2}\n\\end{align}\nWe do the same trick with the constants, here using a bit of foresight, calling \n\\begin{align}\n\\frac{1}{\\Theta}\\Big[\\sin\\theta\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial \\Theta}{\\partial\\theta}\\Big)\\Big] +l(l+1)\\sin^2\\theta &= m^2\\\\\n\\frac{1}{\\Phi}\\frac{\\partial^2 \\Phi}{\\partial\\phi^2} &= -m^2\n\\end{align}\nSolve the easy $\\phi$ one, without caring for normalization\n\\begin{align}\n\\frac{d^2\\Phi}{d\\phi^2} = -m^2\\Phi \\rightarrow \\Phi(\\phi) = e^{im\\phi}\n\\end{align}\nSince $\\Phi(\\phi) = \\Phi(\\phi+2\\pi)$ we have to have that \n\\begin{align}\nm = 0,\\pm 1, \\pm 2, \\pm 3, ...\n\\end{align}\nFor the $\\theta$ equation, we have that\n\\begin{align}\n\\sin\\theta\\frac{\\partial}{\\partial\\theta}\\Big(\\sin\\theta\\frac{\\partial \\Theta}{\\partial\\theta}\\Big) +\\Big[l(l+1)\\sin^2\\theta-m^2\\Big]\\Theta &= 0\n\\end{align}\nWe can then make the same substitution as in equation \\ref{xsub} to write the equation as\n\\begin{align}\n(1-x^2)\\frac{d}{dx}\\Big((1-x^2)\\frac{d\\Theta}{dx}\\Big) + \\Big(l(l+1)(1-x^2)-m^2\\Big)\\Theta = 0\n\\end{align}\nThe solution to this is the same as the associated Legendre Polynomials defined in \\ref{associatedlegendre} with $\\Theta(\\theta) = P_l^m(\\cos\\theta)$. So up to a constant, we have 2/3rd's of the solution, with \n\\begin{align}\nY_l^m(\\theta,\\phi) = \\alpha_{lm}~P_l^m(\\cos\\theta)e^{im\\phi}\n\\end{align}\nThe radial portion is therefore\n\\begin{align}\n\\frac{1}{R}\\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial R}{\\partial r}\\Big) -\\Big(k^2 - f(r)\\Big)r^2 = l(l+1)\n\\end{align}\nWe now change variables to simply the equations with\n\\begin{align}\nu(r) \\equiv rR(r)\n\\end{align}\nWhich simplifies the kinetic term with\n\\begin{align}\n\\frac{\\partial}{\\partial r}\\Big(r^2\\frac{\\partial }{\\partial r}\\frac{u(r)}{r}\\Big)  &= \\frac{\\partial}{\\partial r}\\Big[r\\frac{\\partial u(r)}{\\partial r} - u(r)\\Big]\\\\\n&= \\frac{\\partial u(r)}{\\partial r} + r\\frac{\\partial^2 u(r)}{\\partial r^2} - \\frac{\\partial u(r)}{\\partial r}\\\\\n&= r\\frac{\\partial^2 u(r)}{\\partial r^2}\n\\end{align}\nSo the equation becomes\n\\begin{align}\n\\frac{\\partial^2 u(r)}{\\partial r^2} -\\Big(k^2 - f(r)\\Big)u(r)-\\frac{l(l+1)}{r^2}u(r) = 0\n\\end{align}\nFrom here, we need the form of $f(r)$ to proceed.\n\n\n\n\\subsection{Cylindrical Laplaces Equation}\\label{cylinderlaplacian}\nWe first assume seperability of the potential\n\\begin{align}\n\\varphi(r,\\theta,z) = R(r)\\Theta(\\theta)Z(z)\n\\end{align}\nIn cylindrical coordinates we have\n\\begin{align}\n\\nabla^2 \\varphi = {Z\\Theta \\over \\rho}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n+ {ZR \\over \\rho^2}{\\partial^2 \\Theta \\over \\partial \\theta^2}\n+ R\\Theta {\\partial^2 Z\\over \\partial z^2}= 0\n\\end{align}\nDividing by the potential, we get\n\\begin{align}\n\\nabla^2 \\varphi = {1 \\over R\\rho}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n+ {1 \\over \\Theta\\rho^2}{\\partial^2 \\Theta \\over \\partial \\theta^2}\n+ \\frac{1}{Z} {\\partial^2 Z\\over \\partial z^2}= 0\n\\end{align}\nWe now have the $z$ part seperated out so we can set that equal to a constant, with\n\\begin{align}\n- \\Big[{1 \\over R\\rho}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n+ {1 \\over \\Theta\\rho^2}{\\partial^2 \\Theta \\over \\partial \\theta^2}\\Big]\n= k^2 = \\frac{1}{Z} {\\partial^2 Z\\over \\partial z^2}\n\\end{align}\nWe can solve the $z$ part relatively easily, shown in section \\ref{cylinderlaplace}. Rewriting the the left side, with the constant, we have\n\\begin{align}\n \\Big[{\\rho \\over R}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n +k^2\\rho^2\\Big]\n+ {1 \\over \\Theta}{\\partial^2 \\Theta \\over \\partial \\theta^2} = 0\n\\end{align}\nCalling the $\\Theta$ equation a constant, we get\n\\begin{align}\n{\\rho \\over R}{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n +k^2\\rho^2= \\alpha^2 = -{1 \\over \\Theta}{\\partial^2 \\Theta \\over \\partial \\theta^2}\n\\end{align}\nThe $\\Theta$ one is again easy to solve, but the remaining one becomes tough, with\n\\begin{align}\n{\\rho }{\\partial \\over \\partial \\rho}\\left(\\rho {\\partial R \\over \\partial \\rho}\\right)\n +(k^2\\rho^2-\\alpha^2)R = 0\n\\end{align}\nThis one is solved with Bessel functions, or other things depending on what form  the constants take.\n\n\n\n\n\n\n\n%\\section{Variational Calculus}\n%TODO\n\n\n\n\n\\section{Lagrange Multipliers}\\label{lagrange-mult}\nGiven some function $F(x,y,z,...)$ under the constraint that $G(x,y,z,...) = 0$, we solve for the extremum of $F$ under the constraint by minimizing \n\\begin{align}\nF' = F + \\lambda G\n\\end{align}\nWe take the derivative with respect to each coordinate and obtain some function that lets us solve for one of the variables in terms of the multiplier $\\lambda$, then once we do that for all the variables $x,y,z,...$ we can plug it back into our original constraint, solve for $\\lambda$ numerically, then obtain what the values of $x,y,z,...$ are from our previous expressions which gave them in terms of $\\lambda$. For example\n\\begin{align}\nF(x,y) = x^2 + y^2 && G(x,y) = x + y -1 = 0\\\\\n\\end{align}\n$$\\implies F' = x^2 + y^2 + \\lambda(x+y-1)$$\nThis gives us the equations\n\\begin{align}\n2x + \\lambda &= 0\\\\\n\\implies x &= -\\lambda/2\\\\\n2y + \\lambda &= 0\\\\\n\\implies y &=-\\lambda/2\\\\\n\\end{align}\nPlugging back into our constraint gives us\n\\begin{align}\n-\\lambda - 1 = 0\\\\\n\\implies \\lambda = -1\n\\end{align}\nWhich tells us that $F$ is at an extremum when $x = y = 1/2$. This is then generalized with more constraints by simply adding more Lagrange multipliers for each constraint, and minimizing in the same way. These constraints are the essence of statistical mechanics, where we try to maximize the entropy, under constraints of total energy, etc.\n\n\n\\section{Taylor Expansion}\n\n\nTaylor expansion is an incredibly useful tool if we know how some function behaves at one place, and want to see what would happen if we changed one of the parameters it depends on by a small amount.\n\n\\begin{align}\n\tf(x+\\delta) = f(x) + \\delta f'(x) + \\frac{\\delta^2}{2!}f''(x) + ...\n\\end{align}\n\nSo if we have a crazy looking function that we don't know how it looks, we can just take the derivative of it a bunch of times (usually just once) and multiply it by different factors of the small quantity $\\delta$. \n\n\\subsection{Taylor Expanding Vectors}\n\n%\\todo{This is bad, fix it}\nWe can write a vector as \n\n$$\\textbf{r} = (r_x,r_y,r_z)$$\n\nIf we want to Taylor expand to find the function at some point $\\textbf{r}'$, we have\n\n\\begin{align}\nf(\\textbf{r}') &= f(r_x',r_y',r_z')\\\\\n\\end{align}\nFirst Taylor expand around $r_x'-r_x$\n\\begin{align}\n f(r_x',r_y',r_z') &= f(r_x,r_y',r_z') + (r_x'-r_x)\\frac{\\partial}{\\partial x}f(r_x,r_y',r_z') + ...\n\\end{align}\nThen Taylor expand all these terms around $r_y'-r_y$\n\n\\begin{align}\nf(r_x',r_y',r_z') &= \\Big[f(r_x, r_y,r_z') + (r_y'-r_y)\\frac{\\partial}{\\partial y}f(r_x,r_y,r_z') + ...\\Big]\\\\ \n&+ (r_x'-r_x)\\frac{\\partial}{\\partial x}\\Big[f(r_x,r_y, r_z') + \\frac{\\partial}{\\partial y}f(r_x,r_y, r_z')\\Big]\n\\end{align}\nNeglecting second order terms, we have\n\\begin{align}\nf(r_x',r_y',r_z') &= f(r_x,r_y,r_z') + (r_x'-r_x)\\frac{\\partial}{\\partial x}f(r_x,r_y,r_z') + (r_y'-r_y)\\frac{\\partial}{\\partial y}f(r_x,r_y,r_z')\n\\end{align}\nNow expanding these around $r_z'-r_z$, we get\n\\begin{align}\nf(r_x',r_y',r_z') &= \\Big[f(r_x,r_y,r_z) + (r_z'-r_z)\\frac{\\partial}{\\partial z}f(r_x,r_y,r_z)\\Big]\\\\ \n&+ (r_x'-r_x)\\frac{\\partial}{\\partial x}\\Big[f(r_x,r_y,r_z) + (r_z'-r_z)\\frac{\\partial}{\\partial z}f(r_x,r_y,r_z)\\Big]\\\\  \n&+ (r_y'-r_y)\\frac{\\partial}{\\partial y}\\Big[f(r_x,r_y,r_z) + (r_z'-r_z)\\frac{\\partial}{\\partial z}f(r_x,r_y,r_z)\\Big]\n\\end{align}\nAgain neglecting second order terms, we get\n\\begin{align}\nf(r_x',r_y',r_z') &= f(r_x,r_y,r_z) + (r_x'-r_x)\\frac{\\partial}{\\partial x}f(r_x,r_y,r_z)\\\\ \n&+ (r_y'-r_y)\\frac{\\partial}{\\partial y}f(r_x,r_y,r_z) + (r_z'-r_z)\\frac{\\partial}{\\partial z}f(r_x,r_y,r_z)\\\\\n&= f(r_x,r_y,r_z) + \\Big[(r_x'-r_x)\\frac{\\partial}{\\partial x} + (r_y'-r_y)\\frac{\\partial}{\\partial y} + (r_z'-r_z)\\frac{\\partial}{\\partial z}\\Big] f(r_x,r_y,r_z)\\\\\n &= f(\\textbf{r}) + (\\textbf{r}'\\cdot\\nabla) f(\\textbf{r})\n\\end{align}\n\nIn general, the expansion looks just like\n\n$$f(\\textbf{r}') = f(\\textbf{r}) + (\\textbf{r}'\\cdot\\nabla) f(\\textbf{r}) + \\frac{1}{2}(\\textbf{r}'\\cdot\\nabla)^2 f(\\textbf{r}) + ...$$\n\n\n\\section{Differential Equations}\nMany differential equations can be solved by simply guessing a set of polynomials, then coming up with a relationship between coefficients (e.g. the Hermite Polynomials).\n\\begin{align}\n\ty(x) = \\sum_{n=0}^\\infty c_n x^n\n\\end{align}\n\n\n\\subsection{Wronskian}\nIf we have some differential equation to which we found multiple solutions for (lets say there are just two $\\phi_1(x), \\phi_2(x)$), we can check if they are linearly independent by computing the Wronskian $W(\\phi_1,\\phi_2)$. \n\\begin{align}\nW(\\phi_1,\\phi_2) = \\phi_1\\phi_2'-\\phi_2\\phi_1' \\neq 0\n\\end{align}\nWhere the $'$ is the derivative operator. If this quantity is non zero, then the solutions \\textbf{are} linearly independent. Which then let's us write a general solution to the differential equation as\n\\begin{align}\n\\phi(x) = A_1\\phi_1(x) + A_2\\phi_2(x)\n\\end{align}\n\n\\subsection{Continuity Equation}\nJust take the total time derivative of the whole thing, set it to zero, and match vector components.\n\n\n\\subsection{Forced Differential Equations}\nGiven some differential equation, such as for the Foucault pendulum\\cite{taylor}, whose first order equation looks like\n\\begin{align}\n\\ddot{y} + \\omega_0^2y = 2\\Omega\\omega_0 x_0\\sin(\\omega_0 t)\n\\end{align}\nWe see we can solve the equation easily if it were only the lefthand side. In order to solve a forced differential equation (which has the righthand side), the algorithm is as follows\n\\begin{enumerate}\n\\item Solve the equation as if it didn't have the forcing term (the \\emph{homogeneous} solution), in this case\n\\begin{align}\n\\ddot{y}_h + \\omega_0^2y_h &= 0\\\\\n\\implies y_h(t) &= A_h\\cos(\\omega_0 t) + B_h\\sin(\\omega_0 t)\n\\end{align}\n\\item Guess what the forced solution will look like (see Table \\ref{forcing}), called the \\emph{particular} solution. Here we will have\n\\begin{align}\ny_p(t) = A_p\\cos\\omega_0 t + B_p\\sin\\omega_0 t\n\\end{align}\n\\item Plug it in and solve for constants. If it doesn't work, multiply the solution by the independent variable. In this case, the trial function doesn't work (everything cancels on the left side), so we have to multiply by $t$\n\\begin{align}\ny_p'(t) &= t(A_p\\cos\\omega_0 t + B_p\\sin\\omega_0 t)\\\\\n\\implies \\dot{y}_p'(t) &= A_p\\cos\\omega_0 t + B_p\\sin\\omega_0 t + t(-\\omega_0A_p\\sin\\omega_0 t + \\omega_0B_p\\cos\\omega_0 t)\\\\\n\\implies \\ddot{y}_p'(t) &= -2\\omega_0A_p\\sin\\omega_0 t + 2\\omega_0B_p\\cos\\omega_0 t +t(-\\omega_0^2 A_p\\cos\\omega_0t -\\omega_0^2B_p\\cos\\omega_0 t)\\\\\n\\end{align}\nPlugging into the initial differential equation\n\\begin{align}\n\\implies & -2\\omega_0A_p\\sin\\omega_0 t + 2\\omega_0B_p\\cos\\omega_0 t = 2\\Omega\\omega_0 x_0\\sin(\\omega_0 t)\\\\\n\\end{align}\nThis tells us that\n\\begin{align}\nB_p &= 0\\\\\n-2\\omega_0A_p &= 2\\Omega \\omega_0x_0\\\\\n\\implies A_p &= -\\Omega x_0\n\\end{align}\nThus\n\\begin{align}\ny_p'(t) = -\\Omega x_0 t\\cos\\omega_0 t\n\\end{align}\n\n\\item The summation of the two gives us the full solution\n\\begin{align}\ny(t) &= y_h(t) + y_p(t)\\\\\n &= (A-\\Omega x_0 t)\\cos\\omega_0 t + B\\sin\\omega_0 t\n\\end{align}\n\\item Then plugging in for initial conditions lets us find the constants. Let's say that $y(0) = 0, \\dot{y}(0) = 0$\n\n\\begin{align}\ny(0) = 0 &= A\\\\\n\\dot{y}(0) = 0 &= -\\Omega x_0 +\\omega_0 B\\\\\n\\implies B &= \\Omega x_0/\\omega_0\n\\end{align}\n\nThus the full solution is given by\n\\begin{align}\ny(t) = -\\Omega x_0 t\\cos\\omega_0 t +\\frac{\\Omega}{\\omega_0} x_0\\sin\\omega_0 t\n\\end{align}\n\n\n\n\\end{enumerate}\n\n\n\\begin{center}\n \\begin{tabular}{||c c||} \n \\hline\nForcing Function & Trial Forced Solution \\\\ [0.5ex] \n \\hline\\hline\n const & $A$  \\\\ \n \\hline\n $t$ & $At+ B$  \\\\\n \\hline\n $t^n$ & $At^n + Bt^{n-1} + ... Et + F$  \\\\\n \\hline\n $e^{st}$ & $Ae^{st}$ \\\\\n \\hline\n $\\sin\\omega t, \\cos\\omega t$ & $A\\sin\\omega t + B\\cos\\omega t$   \\\\ \n \\hline\n\\end{tabular}\\label{forcing}\n\\end{center}\n\\section{Linear Algebra}\nA unimodular matrix has determinant $\\pm 1$\n\n\n$$\\rm{det}(\\bf{AB}) = \\rm{det}(\\bf{A})\\rm{det}(\\bf{B})$$\nThe trace is invariant under cyclic permutations\n\\begin{align}\n\t\\textrm{tr}(ABC) = \\textrm{tr}(CAB) = \\textrm{tr}(BCA)\n\\end{align}\n\n$$a_i b_{ij} c_j = \\textbf{a}\\cdot\\textbf{B}\\cdot\\textbf{b} = \\sum_{i} a_i \\sum_{j} b_{ij} c_j$$\n\n\\subsection{Tensors}\nThe rank of a tensor is simply the number of indices needed to describe it. A vector is a tensor of the first rank, and a general $n \\times m$ matrix is a tensor of the second rank. The tensor product of two 2x2 matrices is given by\n\\begin{align}\n\\begin{bmatrix}\na_{11} & a_{21} \\\\\na_{21} & a_{22}\n\\end{bmatrix}\n\\otimes\n\\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix} &=\n\\begin{bmatrix}\na_{11} \\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix}& a_{21} \\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix}\\\\\na_{21} \\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix}& a_{22}\\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix}\n\\end{bmatrix}\n\\end{align}\nWe can do this for any vector space by generalizing the form above. For instance\n\n\\begin{align}\n\\begin{bmatrix}\na_{1}  \\\\\na_{2} \n\\end{bmatrix}\n\\otimes\n\\begin{bmatrix}\nb_{1}\\\\\nb_{2}\n\\end{bmatrix} = \n\\begin{bmatrix}\na_{1}  \\begin{bmatrix}\nb_{1}\\\\\nb_{2}\n\\end{bmatrix} \\\\\na_{2} \\begin{bmatrix}\nb_{1}\\\\\nb_{2}\n\\end{bmatrix} \n\\end{bmatrix}\n\\end{align}\n\nAnother important tensor operator is the direct sum, which is written as\n\\begin{align}\n\t\\begin{bmatrix}\na_{11} & a_{21} \\\\\na_{21} & a_{22}\n\\end{bmatrix}\n\\oplus\n\\begin{bmatrix}\nb_{11} & b_{21} \\\\\nb_{21} & b_{22}\n\\end{bmatrix} &=\n\\begin{bmatrix}\na_{11} & a_{21} & 0 & 0\\\\\na_{21} & a_{22} & 0 & 0\\\\\n0 & 0& b_{11} & b_{12}\\\\\n0 & 0 & b_{21} & b_{22}\n\\end{bmatrix}\n\\end{align}\n\n\\subsection{Determinant}\nFor an arbitrarily sized matrix, can iterate this procedure.\n\\begin{enumerate}\n\\item Write out each value in the top row, alternating sign ($+,-,+,-,...$)\n\\item Multiply each respective value by the determinant of the square matrix created by the rows and columns that the value does not belong to\n\\end{enumerate}\nAs an example a 4 x 4\n\\begin{align}\n\\begin{vmatrix} a & b & c & d\\\\e & f & g & h\\\\i & j & k & l\\\\m & n & o & p \\end{vmatrix}=a\\,\\begin{vmatrix} f & g & h\\\\j & k & l\\\\n & o & p \\end{vmatrix}-b\\,\\begin{vmatrix} e & g & h\\\\i & k & l\\\\m & o & p \\end{vmatrix}+c\\,\\begin{vmatrix} e & f & h\\\\i & j & l\\\\m & n & p \\end{vmatrix}-d\\,\\begin{vmatrix} e & f & g\\\\i & j & k\\\\m & n & o \\end{vmatrix}\n\\end{align}\nThe matrix of a 3 x 3 is \n\\begin{align}\n \\begin{vmatrix} a & b & c\\\\d & e & f\\\\g & h & i \\end{vmatrix} &= a\\,\\begin{vmatrix} e & f\\\\h & i \\end{vmatrix} - b\\,\\begin{vmatrix} d & f\\\\g & i \\end{vmatrix} + c\\,\\begin{vmatrix} d & e\\\\g & h \\end{vmatrix}\\end{align}\n And 2 x 2\n \\begin{align}\\begin{vmatrix} a & b\\\\c & d \\end{vmatrix}=ad - bc .\\end{align}\n\n\n\n\\subsection{Matrix Diagonalization}\\label{diagonalize}\nOne can follow the procedure outlined below to diagonalize a matrix\\cite{griffiths_qm}\n\n\\begin{enumerate}\n\\item Find eigenvalues ($\\lambda_1, \\lambda_2, ... , \\lambda_N$) of matrix $\\bf{M}$ with det($\\bf{M}-\\lambda\\bf{I}$) = 0\n\\item Using the eigenvalues, find the corresponding eigenvectors by plugging in each to $(\\bf{M}-\\lambda_i\\bf{I})\\bf{a_i} = 0$\n\\item The diagonalized matrix $\\bf{T}$ is now \n\n$$\\bf{T} = \\left(\n{\\begin{array}{cccc}\n\\lambda_1 & 0 &...&0 \\\\\n0 & \\lambda_2 & ...&0\\\\\n\\vdots & \\vdots &\\ddots & \\vdots \\\\\n0 & 0 & ... &\\lambda_N\n\\end{array}}\n\\right)\n$$\n\n\\item We need to find$$ \\bf{M} = \\bf{STS^{-1}}$$\n\\item $\\bf{S^{-1}}$ is equal to each eigenvector laid out as a column of the matrix, placed according to where you place it with $\\bf{T}$\n\n$$\\bf{S^{-1}} = \\left(\n{\\begin{array}{cccc}\na(\\lambda_1)_1 & a(\\lambda_2)_1 &...&a(\\lambda_N)_1 \\\\\na(\\lambda_1)_2 & a(\\lambda_2)_2 & ...&a(\\lambda_N)_2\\\\\n\\vdots & \\vdots &\\ddots & \\vdots \\\\\na(\\lambda_1)_N & a(\\lambda_2)_N & ... &a(\\lambda_N)_N\n\\end{array}}\n\\right)\n$$\n\n\\item $\\bf{S}$ can be calculated by simply inverting the matrix $\\bf{S^{-1}}$\n\\end{enumerate}\n\n\\subsection{Simultaneous Eigenstates}\nTo find a simultaneous set of eigenvectors for two operators, follow this:\n\\begin{itemize}\n\\item Given two 3x3 matrices\n\n$$\\bf{M} = \n\\left(\n{\\begin{array}{ccc}\n1&0&1\\\\\n0&0&0\\\\\n1&0&1\\\\\n\\end{array}}\n\\right)\n~~~~\\bf{D} = \n\\left(\n{\\begin{array}{ccc}\n2&1&1\\\\\n1&0&-1\\\\\n1&-1&2\\\\\n\\end{array}}\n\\right)$$\n\n\\item First solve for their eigenvalues ($\\lambda_M = 0,0,2$, $\\lambda_D = -1,2,3$)\n\\item Next find both sets of unnormalized eigenvectors\n$$\n\\lambda_M\\rightarrow  \n\\left(\n{\\begin{array}{c}\na\\\\\nb\\\\\n-a\n\\end{array}}\n\\right),\n\\left(\n{\\begin{array}{c}\na\\\\\nb\\\\\n-a\n\\end{array}}\n\\right),\n\\left(\n{\\begin{array}{c}\na\\\\\n0\\\\\n-a\n\\end{array}}\n\\right)~~~~\n\\lambda_D\\rightarrow\n\\left(\n{\\begin{array}{c}\n0\\\\\n0\\\\\n0\n\\end{array}}\n\\right),\\left(\n{\\begin{array}{c}\na\\\\\na\\\\\n-a\n\\end{array}}\n\\right),\n\\left(\n{\\begin{array}{c}\na\\\\\n0\\\\\n-a\n\\end{array}}\n\\right)$$\n\\item Because $\\textbf{D}$ is not degenerate, correspond each vector to another vector for degenerate $\\textbf{M}$. \n\\item Then just normalize the vectors as usual, and you have a set of eigenvectors for both matrices\n\\end{itemize}\n\n\n\\section{Complex Analysis}\nIn general one can write \\emph{any} complex number as the sum of its real and complex part with\n\\begin{align}\n\tz = x + iy\\\\\n\\end{align}\t\n\tThe \\emph{complex conjugate} is the same thing as the normal complex number, but with the sign in front of  $i$ switched\n\\begin{align}\n\tz^* = x - iy\\\\\n\\end{align}\nThe absolute value of any complex number is just\n\\begin{align}\n\t|z|^2 = zz^* = (x+iy)(x-iy) = x^2 +y^2\n\\end{align}\nWe can also find the real part  or imaginary part of any complex number by rearranging the equation for it and its complex conjugate to find\n\\begin{align}\n\tx &= \\frac{z+z^*}{2}\\\\\n\ty &= \\frac{z - z^*}{2i}\n\\end{align}\n\n% TODO Book by Roger Penrose has good stuff about $re^{i\\theta}$\n\n\\section{Integration}\n\n\n\n\\subsection{Exponentials}\nThe Gaussian integral can be evaluated using a trick\n\\begin{align}\n\t\\int_{-\\infty}^\\infty dx~e^{-ax^2} = ?\n\\end{align}\nWe square whatever it evaluates to, which allows us to write\n\\begin{align}\n\t(?)^2 = \\Big(\\int_{-\\infty}^\\infty dx~e^{-ax^2}\\Big)^2 = \\int_{-\\infty}^\\infty dx \\int_{-\\infty}^\\infty dy~e^{-a(x^2+y^2)}\n\\end{align}\nSince both $x$ and $y$ are dummy variables. This is now effectively a 2 dimensional area integral over the entire plane, which we can actually evaluate in polar coordinates quite easily\n\\begin{align}\n\t\\int_{-\\infty}^\\infty dx \\int_{-\\infty}^\\infty dy~e^{-a(x^2+y^2)} = \\int_0^{2\\pi} d\\theta \\int_0^\\infty dr~re^{-ar^2} = \\frac{\\pi}{a} \\int_0^\\infty du~ e^{-u} = \\frac{\\pi}{a}\n\\end{align}\nSo we see that we have that this gives us the relation, below. With just these two equations, we can find expressions containing arbitrary powers of $x$ by taking the derivative of both sides with respect to the constant $a$.\n\n\\begin{align}\n\\int_{-\\infty}^\\infty dx ~e^{-ax^2} = \\sqrt{\\frac{\\pi}{a}}\n&&\\int_0^\\infty dx~e^{-a x} = \\frac{1}{a}\n\\end{align}\nFor instance\n\\begin{align}\n\\frac{d}{da}\\int_0^\\infty dx e^{-a x} &= \\frac{d}{da}\\frac{1}{a}\\\\\n\\int_0^\\infty dx~ x e^{-ax} &= \\frac{1}{a^2}\n\\end{align}\nOne that comes up often that can be found by completing the square on the normal Gaussian integral is\n\\begin{align}\n\t\\int_{-\\infty}^\\infty dx ~e^{-ax^2 + bx} = \\sqrt{\\frac{\\pi}{a}}~e^{b^2/4a}\n\\end{align}\n\n\n\\subsection{Stirlings Approximation}\\label{stirling}\n\\begin{align}\n\\ln N! &= \\ln \\Big(1\\times 2\\times 3\\times...\\times N\\Big)\\\\\n&= \\sum_{x=1}^N \\ln x\\\\\n&\\approx \\int_1^N dx~\\ln x\\\\\n&\\approx x\\ln x - x\\Big|_1^N\\\\\n&\\approx \\Big(N\\ln N- N \\Big) - 1\\ln 1 - 1\\\\\n&\\approx N\\ln N - N\n\\end{align}\nExponentiating both sides we get\n\\begin{align}\nN! &\\approx e^{N\\ln N - N}\\\\\n&\\approx e^{\\ln N^N}e^{-N}\\\\\n&\\approx N^Ne^{-N}\n\\end{align}\nWhen $N$ is large enough to make the conversion to the integral valid. If one includes does this a bit more thoroughly, one arrives at\n\\begin{align}\n\tN! \\approx \\sqrt{2\\pi N} N^Ne^{-N}\n\\end{align}\n\n\n\\subsection{Tabular Integration by Parts}\nGiven some integral that looks like\n\\begin{align}\n\\int dx~x^3\\cos x \n\\end{align}\nWe want use integration by parts to see what it evaluates to. We would normally have to use integration by parts many times, until we got the $x$ term to evaluate to zero, but there is a nice convention to evaluating all of these quickly\\cite{rdorst}. The algorithm goes as\n\\begin{itemize}\n\\item Find the part of the equation which, when differentiated enough, eventually goes to zero, in our case this would be $x^3$. At the same time, we want to find we can integrate the remaining piece over and over again without issues. $\\cos x$ works\n\\item Lay the two out in columns. Differentiate one side \\emph{flipping the sign} in each other row, and integrate the right column\n\\begin{center}\n\\begin{tabular}{ c c }\n $+x^3$ & $\\cos x$  \\\\ \\hline\n $-3x^2$& $\\sin x$  \\\\  \n $+6x$ & $-\\cos x$   \\\\\n $-6$ &  $-\\sin x$ \\\\\n $0$ & $\\cos x$\n\\end{tabular}\n\\end{center}\n\n\\item Now multiply diagonally, taking the top left, multiplying by right column one row lower. Then move down a row, summing it with what you had before, until you reach the end. So we get\n\\begin{align}\n\\int x^3\\cos x &= x^3\\sin x +3x^2\\cos x -6x\\sin x-6\\cos x\n\\end{align}\n\n\\end{itemize}\n\n% TODO Jacobian Comp 2012 question 10 variable change\n% \\subsection{Jacobian}\n%Useful for when you want to change variables that you want to integrate over\n%\\begin{align}\n%\t\\int \\int f(x,y) dx ~dy = \\int \\int f\\Big(x(u,v),y(u,v)\\Big) \\Big|\\frac{\\partial(x,y)}{\\partial(u,v)}\\Big| du~dv\n%\\end{align}\n%Where\n%\\begin{align}\n%\\frac{\\partial(x,y)}{\\partial(u,v)}  = \t\\Big|\n%{\\begin{array}{cc}\n%\\partial x/\\partial u & \\partial x / \\partial v\\\\\n%\\partial y/\\partial u &\\partial y/ \\partial v\\\\\n%\\end{array}}\n%\\Big|\n%\\end{align}\n", "meta": {"hexsha": "db66e0267c567e39cdbf5cea1bcb2534abb389eb", "size": 45071, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/vectorcalculus.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/vectorcalculus.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/vectorcalculus.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": 39.3289703316, "max_line_length": 427, "alphanum_fraction": 0.6821015731, "num_tokens": 15971, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894717137997, "lm_q2_score": 0.8438950966654774, "lm_q1q2_score": 0.7551084477271685}}
{"text": "\\documentclass[../thesis.tex]{subfiles}\n\\begin{document}\n\n\\chapter{Properties of Natural Numbers and Equational Reasoning}\\label{props}\n\nProperties of natural numbers play a big role in the development of proofs in\nthis thesis. With propositional equality at our disposal, we will demonstrate how\nto prove properties such as the commutative property of addition.\nAs proofs get more complicated, we will make proving easier by introducing a\npowerful tool: \\textit{equational reasoning}.\n\n\\paragraph{Remark}\nReaders who are familiar with equational/preorder reasoning may skip this chapter.\n\n\\section{Proving Equational Propositions}\n\n\\paragraph{Right identity of addition}\n\nRecap the definition of addition on {\\lstinline|ℕ|}.\n\n\\begin{lstlisting}\n_+_ : ℕ → ℕ → ℕ\nzero  + y = y\nsuc x + y = suc (x + y)\n\\end{lstlisting}\n\n{\\lstinline|_+_|} is defined by induction on the first argument. That means we\nget the \\textit{left identity} of addition for free, as {\\lstinline|zero + y|}\nand {\\lstinline|y|} are \\textit{computationally equal}. However, this is not the\ncase for the \\textit{right identity}. It has to be proven explicitly.\n\n\\begin{lstlisting}\n+-right-identity : (n : ℕ) → n + 0 ≡ n\n+-right-identity zero    = ?0\n+-right-identity (suc n) = ?1\n\\end{lstlisting}\n\nBy induction on the only argument, we get two sub-goals:\n\n\\begin{lstlisting}\n?0 : 0 ≡ 0\n?1 : suc (n + 0) ≡ suc n\n\\end{lstlisting}\n\n{\\lstinline|?0|} can be trivially proven with {\\lstinline|refl|}.\nAs for {\\lstinline|?1|}, we see that its type looks a lot like the proposition\nwe are proving, except that both sides of the equation are ``coated'' with a {\\lstinline|suc|}.\nWith {\\lstinline|cong suc : ∀ {x y} → x ≡ y → suc x ≡ suc y|}, we could substitute\na term in {\\lstinline|suc|} with another if they are equal, and finish\nthe proof by recursively calling itself with a \\textit{smaller} argument.\n\n\\begin{lstlisting}\n+-right-identity : ∀ n → n + 0 ≡ n\n+-right-identity zero    = refl\n+-right-identity (suc n) = cong suc (+-right-identity n)\n\\end{lstlisting}\n\n\\paragraph{Moving suc to the other side}\n\nThis is an essential lemma for proving more advanced theorems.\nThe proof also follows a similar pattern as that of {\\lstinline|+-right-identity|}.\n\\footnote{In fact, all of these proofs (hence programs) can be generalized to\na \\textit{fold}, but that is not the point here.}\n\n\\begin{lstlisting}\n+-suc : ∀ m n → m + suc n ≡ suc (m + n)\n+-suc zero    n = refl\n+-suc (suc m) n = cong suc (+-suc m n)\n\\end{lstlisting}\n\n\\paragraph{Commutative property of addition}\n\nSimilarly, by induction on the first argument, we get two sub-goals:\n\n\\begin{lstlisting}\n+-comm : ∀ m n → m + n ≡ n + m\n+-comm zero    n = ?0\n+-comm (suc m) n = ?1\n\n?0 : n           ≡ m + zero\n?1 : suc (m + n) ≡ m + suc n\n\\end{lstlisting}\n\n{\\lstinline|?0|} can be solved with {\\lstinline|+-right-identity|} with a ``twist''.\nThe symmetry of equality {\\lstinline|sym|} enables us to swap both sides of an equation.\n\n\\begin{lstlisting}\n+-comm zero    n = sym (+-right-identity n)\n\\end{lstlisting}\n\nHowever, it is not obvious how to solve {\\lstinline|?1|} straight out.\nThe proof has to be ``broken'', or ``split'' into two steps:\n\n\\begin{enumerate}\n    \\item Apply {\\lstinline|+-suc|} with {\\lstinline|sym|} to the right-hand side\n    of the equation to get {\\lstinline|suc (m + n) ≡ suc (n + m)|}.\n    \\item Apply the induction hypothesis to {\\lstinline|cong suc|}.\n\\end{enumerate}\n\nThese small pieces of proofs are glued back together with the transitivity of\nequality {\\lstinline|trans|}.\n\n\\begin{lstlisting}\n+-comm (suc m) n = trans (cong suc (+-comm m n)) (sym (+-suc n m))\n\\end{lstlisting}\n\n\\section{Equational Reasoning}\n\nWe can see that proofs are composable just like programs.\n\n\\begin{lstlisting}\ntrans (cong suc (+-comm m n)) (sym (+-suc n m))\n\\end{lstlisting}\n\nHowever, it is difficult to see what is going on in between these clauses, and it could\nget only worse as propositions get more complicated.\nImagine having dozens of {\\lstinline|trans|}, {\\lstinline|sym|} and {\\lstinline|cong|}\nspreading everywhere.\n\nFortunately, these complex proofs can be written in a concise and modular manner\nwith a simple yet powerful technique called \\textit{equational reasoning}.\nAgda's flexible mixfix syntax allows the technique to be implemented with just\na few combinators\\cite{erikhesselinkpaulvisschers2008}.\n\nThis is best illustrated by an example:\n\n\\begin{lstlisting}\n+-comm : ∀ m n → m + n ≡ n + m\n+-comm zero    n = sym (+-right-identity n)\n+-comm (suc m) n =\n    begin\n        suc m + n\n    ≡⟨ refl ⟩\n        suc (m + n)\n    ≡⟨ cong suc (+-comm m n) ⟩\n        suc (n + m)\n    ≡⟨ sym (+-suc n m) ⟩\n        n + suc m\n    ∎\n\\end{lstlisting}\n\nWith equational reasoning, we can see how an expression equates to another,\nstep by step, justified by theorems. The first and the last steps correspond to\ntwo sides of the equation of a proposition. {\\lstinline|begin_|} marks the beginning\nof a reasoning; {\\lstinline|_≡⟨_⟩_|} chains two expressions with the justification\nplaced in between; {\\lstinline|_∎|} marks the end of a reasoning (\\textit{QED}).\n\n\\subsection{Anatomy of Equational Reasoning}\n\nA typical equational reasoning can often be broken down into \\textbf{three} parts.\n\n\\begin{enumerate}\n    \\item\\label{eq-part1}\n        Starting from the left-hand side of the equation, through a series of steps, the expression will be ``arranged'' into a form that allows the induction\n        hypothesis to be applied.\n        In the following example of {\\lstinline|+-comm|}, nothing needs to be arranged\n        because these two expressions are computationally equal\n        (the {\\lstinline|refl|} can be omitted).\n\n        \\begin{lstlisting}\n            begin\n                suc m + n\n            ≡⟨ refl ⟩\n                suc (m + n)\n        \\end{lstlisting}\n    \\item\\label{eq-part2}\n        {\\lstinline|m + n|} emerged as part of the proposition which enables us\n        to apply the induction hypothesis.\n\n        \\begin{lstlisting}\n                suc (m + n)\n            ≡⟨ cong suc (+-comm m n) ⟩\n                suc (n + m)\n        \\end{lstlisting}\n    \\item\\label{eq-part3}\n        After applying the induction hypothesis, the expression is then ``rearranged''\n        into the right-hand side of the equation, hence completes the proof.\n\n        \\begin{lstlisting}\n                suc (n + m)\n            ≡⟨ sym (+-suc n m) ⟩\n                n + suc m\n            ∎\n        \\end{lstlisting}\n\\end{enumerate}\n\n\\paragraph{arranging expressions}\n\nTo arrange an expression into the shape that we desire as in part \\ref{eq-part1}\nand part \\ref{eq-part3}, while remaining equal,\nwe need properties such as commutativity or associativity of some operator,\nor distributive properties when there is more than one operator.\n\nThe operators we will be dealing with often comes with these properties.\nTake addition and multiplication, for example, together they form a nice semiring\nstructure.\n\n\\paragraph{substituting equals for equals}\n\nAs what we have seen in \\ref{eq-part2}, sometimes there is only a part of an\nexpression needs to be substituted.\nSay, we have a proof {\\lstinline|eq : X ≡ Y|}, and we want to substitute {\\lstinline|X|}\nfor {\\lstinline|Y|} in a more complex expression {\\lstinline|a b (c X) d|}.\nWe could ask {\\lstinline|cong|} to ``target'' the part to substitute by supplying a\nfunction like this:\n%\n\\begin{lstlisting}\nλ w → a b (c w) d\n\\end{lstlisting}\n%\nwhich abstracts the part we want to substitute away, such that:\n\n\\begin{lstlisting}\ncong (λ w → a b (c w) d) eq : a b (c X) d ≡ a b (c Y) d\n\\end{lstlisting}\n\n\\section{Decidable Equality on Natural Numbers}\n\nEquality is decidable on natural numbers, which means that we can always tell\nwhether two numbers are equal, and explain the reason with a proof.\n\n\\begin{lstlisting}\n_≟_ : Decidable {A = ℕ} _≡_\nzero  ≟ zero   = yes refl\nsuc m ≟ suc n  with m ≟ n\nsuc m ≟ suc .m | yes refl = yes refl\nsuc m ≟ suc n  | no prf   =\n    no (prf ∘ (λ p → subst (λ x → m ≡ pred x) p refl))\nzero  ≟ suc n  = no λ()\nsuc m ≟ zero   = no λ()\n\\end{lstlisting}\n\nDecidable functions are often used together with \\textit{with-abstractions}.\n\n\\begin{lstlisting}\nanswer : ℕ → Bool\nanswer n with n ≟ 42\nanswer n | yes p = true\nanswer n | no ¬p = false\n\\end{lstlisting}\n%\nwhere {\\lstinline|p : n ≡ 42|} and  {\\lstinline|¬p : n ≢ 42|}.\n\n\\section{Preorder}\n\nAside from stating that two expressions are equal, a proposition can also assert\nthat one expression is ``less than or equal to'' than another, given a preorder.\n\nA preorder is a binary relation that is \\textit{reflexive} and \\textit{transitive}.\nOne of the instances of preorder on natural numbers is the binary relation\n{\\lstinline|_≤_|} (less than or equal to.)\n\n\\begin{lstlisting}\ndata _≤_ : ℕ → ℕ → Set where\n    z≤n : ∀ {n}                 → zero  ≤ n\n    s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n\n\\end{lstlisting}\n\nThe following is a proof of $ 3 \\leq 5 $:\n\n\\begin{lstlisting}\n3≤5 : 3 ≤ 5\n3≤5 = s≤s (s≤s (s≤s z≤n))\n\\end{lstlisting}\n\nTo prove $ 3 \\leq 5 $, we need a proof of $ 2 \\leq 4 $ for {\\lstinline|s≤s|},\nand so on, until it reaches zero where it ends with a {\\lstinline|z≤n|}.\n\nHere are some other binary relations that can be defined with {\\lstinline|_≤_|}.\n\n\\begin{lstlisting}\n_<_ : Rel ℕ Level.zero\nm < n = suc m ≤ n\n\n_≰_ : Rel ℕ Level.zero\na ≰ b = ¬ a ≤ b\n\n_≥_ : Rel ℕ Level.zero\nm ≥ n = n ≤ m\n\\end{lstlisting}\n\n\\section{Preorder reasoning}\n\nCombinators for equational reasoning can be further generalized to support \\textit{preorder reasoning}.\nPreorders are \\textit{reflexive} and \\textit{transitive},\nwhich means that expressions can be chained with a series of relations just as that of\nequational reasoning.\n\nSuppose we already have {\\lstinline|m≤m+n : ∀ m n → m ≤ m + n|} and we want to\nprove a slightly different theorem.\n\n\\begin{lstlisting}\nm≤n+m : ∀ m n → m ≤ n + m\nm≤n+m m n =\n    start\n        m\n    ≤⟨ m≤m+n m n ⟩\n        m + n\n    ≈⟨ +-comm m n ⟩\n        n + m\n    □\n\\end{lstlisting}\n%\nwhere {\\lstinline|_≤⟨_⟩_|} and {\\lstinline|_≈⟨_⟩_|} are respectively transitive\nand reflexive combinators.\\footnote{Combinators for preorder reasoning are\nrenamed to prevent conflictions with equational reasoning.}\nStep by step, starting from the left-hand side of the relation, expressions get\ngreater and greater as it reaches the right-hand side the relation.\n\n\\paragraph{monotonicity of operators}\n\nIn equational reasoning, we could substitute part of an expression with something\nequal with {\\lstinline|cong|} because {\\lstinline|_≡_|} is congruent.\nHowever, we cannot substitute part of an expression with something \\textit{greater}\nin general.\n\nTake the following function {\\lstinline|f|} as example.\n\n\\begin{lstlisting}\nf : ℕ → ℕ\nf 0 = 1\nf 1 = 0\nf _ = 1\n\\end{lstlisting}\n\n{\\lstinline|f|} returns $ 1 $ on all inputs except for $ 1 $.\n{\\lstinline|0 ≤ 1|} holds, but it does not imply that {\\lstinline|f 0 ≤ f 1|} also holds.\nAs a result, a generic mechanism like {\\lstinline|cong|} does not exist in preorder reasoning.\nGiven \\lstinline|x ≤ y|, we can substitute \\lstinline|f x| by \\lstinline|f y|\nusing a proof that \\lstinline|f| is monotonic.\n\\footnote{Such a proof or theorem often goes by the name of \\lstinline|f-mono|}.\n\n\\section{Decidable Preorder on Natural Numbers}\n\nPreorder is also decidable on natural numbers, which means that we can always tell\nwhether one number is less than or equal to another.\n\n\\begin{lstlisting}\n_≤?_ : Decidable _≤_\nzero  ≤? _     = yes z≤n\nsuc m ≤? zero  = no λ()\nsuc m ≤? suc n with m ≤? n\n...            | yes m≤n = yes (s≤s m≤n)\n...            | no  m≰n = no  (m≰n ∘ ≤-pred)\n\\end{lstlisting}\n\nWith with-abstractions we could define some function like this:\n\n\\begin{lstlisting}\nthreshold : ℕ → ℕ\nthreshold n with n ≤? 87\nthreshold n | yes p = n\nthreshold n | no ¬p = 87\n\\end{lstlisting}\n%\nwhere {\\lstinline|p : n ≤ 42|} and {\\lstinline|¬p : n ≰ 42|}.\n\n% Suppose we want to prove that {\\lstinline|_+_|} is monotonic in both arguments.\n%\n% \\begin{lstlisting}\n% +-mono : ∀ m₁ m₂ n₁ n₂ → m₁ ≤ m₂ → n₁ ≤ n₂ → m₁ + n₁ ≤ m₂ + n₂\n% \\end{lstlisting}\n%\n% By induction on the argument of type {\\lstinline|m₁ ≤ m₂|}, we get two goals.\n% The type and context of the first goal is as follows:\n%\n% \\begin{lstlisting}\n% +-mono 0 m₂ n₁ n₂ z≤n n₁≤n₂ = ?0\n%\n% Goal of ?0 : n₁ ≤ m₂ + n₂\n% n₁≤n₂      : n₁ ≤ n₂\n% n₁, n₂, m₂ : ℕ\n% \\end{lstlisting}\n%\n% \\begin{lstlisting}\n% +-mono (suc m₁) (suc m₂) n₁ n₂ (s≤s p) n₁≤n₂ = ?1\n% \\end{lstlisting}\n%\n% The induction forces {\\lstinline|m₁ m₂|} to change as well.\n%\n% \\begin{lstlisting}\n% +-mono : ∀ m₁ m₂ n₁ n₂ → m₁ ≤ m₂ → n₁ ≤ n₂ → m₁ + n₁ ≤ m₂ + n₂\n% +-mono 0        m₂       n₁ n₂ z≤n     n₁≤n₂ = ?0\n% +-mono (suc m₁) (suc m₂) n₁ n₂ (s≤s p) n₁≤n₂ = ?1\n% \\end{lstlisting}\n\n% \\begin{lstlisting}\n% +-mono : ∀ m₁ m₂ n₁ n₂ → m₁ ≤ m₂ → n₁ ≤ n₂ → m₁ + n₁ ≤ m₂ + n₂\n% +-mono 0        m₂       n₁ n₂ z≤n     n₁≤n₂ = ?0\n% +-mono (suc m₁) (suc m₂) n₁ n₂ (s≤s p) n₁≤n₂ = ?1\n% \\end{lstlisting}\n\n% Take \\textit{monus} \\footnote{Monus, or \\textit{truncated subtraction}, is a\n% kind of subtraction that never goes negative when the subtrahend is greater then\n% the minued.} {\\lstinline|_∸_|} for example:\n%\n% \\begin{lstlisting}\n% f : ∀ m n\n%     → (prop : m ≤ n)\n%     → m ∸ m ≤ m ∸ n\n% f m n prop =\n%     start\n%         m ∸ m\n%     ≤⟨ ? ⟩\n%         m ∸ n\n%     □\n% \\end{lstlisting}\n%\n% We cannot prove {\\lstinline|f|} because {\\lstinline|m ≤ n|} does not imply\n% {\\lstinline|m ∸ m ≤ m ∸ n|}\\footnote{the second argument of {\\lstinline|_∸_|}\n% is \\textit{contravariant} in the sense that the result of {\\lstinline|_∸_|} would\n% increase when the second argument decreases.}\n\n% The proposition {\\lstinline|f|} as seen above can only be disapproved, because\n% the second argument of {\\lstinline|_∸_|} is \\textit{contravariant} in the sense\n% that the result of {\\lstinline|_∸_|} would increase when the second argument decreases.\n\n% Even worse, the function that takes the substitute as an argument may not\n% even be \\textit{monotonic} like monus. As a result, a generic mechanism like\n% {\\lstinline|cong|} does not exist in preorder reasoning. We can only substitute\n% part of an expression when the function is \\textit{monotonic}. The monotonicity\n% of each function are different and have to be proved\n\n\n%\n% Similar to that of equation reasoning, sometimes we need to rewrite expressions with\n% {\\lstinline|_≈⟨_⟩_|} when they are equal to each other (An equivalence relation is also a\n% preorder). We would also skip these steps.\n%\n% Some of the obvious transitive steps (that is written in {\\lstinline|_≤⟨_⟩_|})\n% will also be skipped.\n\n\\section{Skipping trivial proofs}\n\nFrom now on, we will dispense with most of the steps and justifications in\nequational and preorder reasonings,\nbecause it is often obvious to see what happened in the process.\n\nIn fact, there are is no formal distinction between the proofs we disregard and\nthose we feel important. They are all equally indispensable to Agda.\n\n\\section{Relevant Properties of Natural Numbers}\n\nRelevant properties of {\\lstinline|ℕ|} used in the remainder of the thesis\nare introduced in this section.\n\nAside from some basic properties taken from the standard library, we have\nalso added some useful theorems, lemmata, and corollaries.\n\\footnote{\\textit{Theorem}, \\textit{lemma}, \\textit{corollary} and \\textit{property}\nare all synonyms for \\textit{established proposition}. There are no formal\ndistinction between these terms and they are used exchangeably in the thesis.}\n\n\\subsection{Equational Propositions}\n\n\\subsubsection{natural number}\n\n\\begin{lstlisting}\ndata ℕ : Set where\n    zero : ℕ\n    suc : ℕ → ℕ\n\\end{lstlisting}\n\n\\begin{itemize}\n    \\item {\\lstinline|cancel-suc : ∀ {x y} → suc x ≡ suc y → x ≡ y|}\n        \\\\ suc is injective.\n\\end{itemize}\n\n\\subsubsection{addition}\n\n\\begin{lstlisting}\n_+_ : ℕ → ℕ → ℕ\nzero  + y = y\nsuc x + y = suc (x + y)\n\\end{lstlisting}\n\n\\begin{itemize}\n    \\item {\\lstinline|+-right-identity : ∀ n → n + 0 ≡ n|}\n        \\\\ the right identity of addition.\n    \\item {\\lstinline|+-suc : ∀ m n → m + suc n ≡ suc (m + n)|}\n        \\\\ moving {\\lstinline|suc|} from one term to another.\n    \\item {\\lstinline|+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)|}\n        \\\\ the associative property of addition.\n    \\item {\\lstinline|+-comm : ∀ m n → m + n ≡ n + m|}\n        \\\\ the commutative property of addition.\n    \\item {\\lstinline|[a+b]+c≡[a+c]+b : ∀ a b c → a + b + c ≡ a + c + b|}\n        \\\\ a convenient corollary for swapping terms.\n    \\item {\\lstinline|a+[b+c]≡b+[a+c] : ∀ a b c → a + (b + c) ≡ b + (a + c)|}\n        \\\\ a convenient corollary for swapping terms.\n    \\item {\\lstinline|cancel-+-left : ∀ i {j k} → i + j ≡ i + k → j ≡ k|}\n        \\\\ the left cancellation property of addition.\n    \\item {\\lstinline|cancel-+-right : ∀ k {i j} → i + k ≡ j + k → i ≡ j|}\n        \\\\ the right cancellation property of addition.\n\\end{itemize}\n\n\\subsubsection{multiplication}\n\n\\begin{lstlisting}\n_*_ : ℕ → ℕ → ℕ\nzero  * y = y\nsuc x * y = y + (x * y)\n\\end{lstlisting}\n\n\\begin{itemize}\n    \\item {\\lstinline|*-right-zero : ∀ n → n * 0 ≡ 0|}\n        \\\\ the right absorbing element of multiplication.\n    \\item {\\lstinline|*-left-identity : ∀ n → 1 * n ≡ n|}\n        \\\\ the left identity of addition multiplication.\n    \\item {\\lstinline|*-right-identity : ∀ n → n * 1 ≡ n|}\n        \\\\ the right identity of addition multiplication.\n    \\item {\\lstinline|+-*-suc : ∀ m n → m * suc n ≡ m + m * n|}\n        \\\\ multiplication over {\\lstinline|suc|}.\n    \\item {\\lstinline|*-assoc : ∀ m n o → (m * n) * o ≡ m * (n * o)|}\n        \\\\ the associative property of multiplication.\n    \\item {\\lstinline|*-comm : ∀ m n → m * n ≡ n * m|}\n        \\\\ the commutative property of multiplication.\n    \\item {\\lstinline|distribʳ-*-+ : ∀ m n o → (n + o) * m ≡ n * m + o * m|}\n        \\\\ the right distributive property of multiplication over addition.\n    \\item {\\lstinline|distrib-left-*-+ : ∀ m n o → m * (n + o) ≡ m * n + m * o|}\n        \\\\ the left distributive property of multiplication over addition.\n\\end{itemize}\n\n\\subsubsection{monus}\n\nMonus, or \\textit{truncated subtraction}, is a kind of subtraction that never\ngoes negative when the subtrahend is greater than the minued.\n\n\\begin{lstlisting}\n_∸_ : Nat → Nat → Nat\nn     ∸ zero = n\nzero  ∸ suc m = zero\nsuc n ∸ suc m = n ∸ m\n\\end{lstlisting}\n\n\\begin{itemize}\n    \\item {\\lstinline|0∸n≡0 : ∀ n → 0 ∸ n ≡ 0|}\n    \\item {\\lstinline|n∸n≡0 : ∀ n → n ∸ n ≡ 0|}\n    \\item {\\lstinline|m+n∸n≡m : ∀ m n → (m + n) ∸ n ≡ m|}\n    \\item {\\lstinline|m+n∸m≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n|}\n    \\item {\\lstinline|m∸n+n≡m : ∀ {m n} → n ≤ m → m ∸ n + n ≡ m|}\n    \\item {\\lstinline|∸-+-assoc : ∀ m n o → (m ∸ n) ∸ o ≡ m ∸ (n + o)|}\n        \\\\ the associative property of monus and addition.\n    \\item {\\lstinline|+-∸-assoc : ∀ m {n o} → o ≤ n → (m + n) ∸ o ≡ m + (n ∸ o)|}\n        \\\\ the associative property of monus and addition.\n    \\item {\\lstinline|*-distrib-∸ʳ : ∀ m n o → (n ∸ o) * m ≡ n * m ∸ o * m|}\n        \\\\ the right distributive property of monus over multiplication.\n\\end{itemize}\n\n\\subsubsection{min and max}\n\nSo called {\\lstinline|min|} and {\\lstinline|max|} in Haskell.\nMin {\\lstinline|_⊓_|} computes the lesser of two numbers.\n\n\\begin{lstlisting}\n_⊓_ : ℕ → ℕ → ℕ\nzero  ⊓ n     = zero\nsuc m ⊓ zero  = zero\nsuc m ⊓ suc n = suc (m ⊓ n)\n\\end{lstlisting}\n\nMax {\\lstinline|_⊔_|} computes the greater of two numbers.\n\n\\begin{lstlisting}\n_⊔_ : ℕ → ℕ → ℕ\nzero  ⊔ n     = n\nsuc m ⊔ zero  = suc m\nsuc m ⊔ suc n = suc (m ⊔ n)\n\\end{lstlisting}\n\n\\begin{itemize}\n    \\item {\\lstinline|⊓-comm : ∀ m n → m ⊓ n ≡ n ⊓ m|}\n        \\\\ the commutative property of min.\n    \\item {\\lstinline|⊔-comm : ∀ m n → m ⊔ n ≡ n ⊔ m|}\n        \\\\ the commutative property of max.\n\\end{itemize}\n\n\\subsection{Relational Propositions}\n\n\\subsubsection{natural number}\n\n\\begin{itemize}\n    \\item {\\lstinline|≤-pred : ∀ {m n} → suc m ≤ suc n → m ≤ n|}\n        \\\\ inverse of {\\lstinline|s≤s|}.\n    \\item {\\lstinline|<⇒≤ : _<_ ⇒ _≤_|}\n    \\item {\\lstinline|>⇒≰ : _>_ ⇒ _≰_|}\n    \\item {\\lstinline|≤⇒≯ : _≤_ ⇒ _≯_|}\n    \\item {\\lstinline|<⇒≱ : _<_ ⇒ _≱_|}\n    \\item {\\lstinline|>⇒≢ : _>_ ⇒ _≢_|}\n    \\item {\\lstinline|≥⇒≮ : _≥_ ⇒ _≮_|}\n    \\item {\\lstinline|<⇒≢ : _<_ ⇒ _≢_|}\n    \\item {\\lstinline|≤∧≢⇒< : ∀ {m n} → m ≤ n → m ≢ n → m < n|}\n    \\item {\\lstinline|≥∧≢⇒> : ∀ {m n} → m ≥ n → m ≢ n → m > n|}\n\\end{itemize}\n\n\\subsubsection{addition}\n\n\\begin{itemize}\n    \\item {\\lstinline|≤-step : ∀ {m n} → m ≤ n → m ≤ 1 + n|}\n    \\item {\\lstinline|≤-steps : ∀ {m n} k → m ≤ n → m ≤ k + n|}\n    \\item {\\lstinline|m≤m+n : ∀ m n → m ≤ m + n|}\n    \\item {\\lstinline|n≤m+n : ∀ m n → n ≤ m + n|}\n    \\item {\\lstinline|_+-mono_ : ∀ {m₁ m₂ n₁ n₂} → m₁ ≤ m₂ → n₁ ≤ n₂ → m₁ + n₁ ≤ m₂ + n₂|}\n        \\\\ the monotonicity of addition\n    \\item {\\lstinline|n+-mono : ∀ {i j} n → i ≤ j → n + i ≤ n + j|}\n        \\\\ {\\lstinline|_+-mono_|} with the first argument fixed.\n    \\item {\\lstinline|+n-mono : ∀ {i j} n → i ≤ j → n + i ≤ n + j|}\n        \\\\ {\\lstinline|_+-mono_|} with the second argument fixed.\n    \\item {\\lstinline|n+-mono-inverse : ∀ n → ∀ {a b} → n + a ≤ n + b → a ≤ b|}\n        \\\\ the inverse of {\\lstinline|n+-mono|}\n    \\item {\\lstinline|+n-mono-inverse : ∀ n → ∀ {a b} → a + n ≤ b + n → a ≤ b|}\n        \\\\ the inverse of {\\lstinline|+n-mono|}\n    \\item {\\lstinline|+-mono-contra : ∀ {a b c d} → a ≥ b → a + c < b + d → c < d|}\n\\end{itemize}\n\n\\subsubsection{monus}\n\n\\begin{itemize}\n    \\item {\\lstinline|n∸m≤n : ∀ m n → n ∸ m ≤ n|}\n    \\item {\\lstinline|n≤m+n∸m : ∀ m n → n ≤ m + (n ∸ m)|}\n    \\item {\\lstinline|∸-mono : ∀ x y u v → x ≤ y → u ≥ v → x ∸ u ≤ y ∸ v|}\n        \\\\ the monotonicity of monus\n\\end{itemize}\n\n\\end{document}\n", "meta": {"hexsha": "ef9e928ecd866d7d34e1bb083c5ed40a6afd6415", "size": 21638, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Thesis/tex/props.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/props.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/props.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": 34.6762820513, "max_line_length": 158, "alphanum_fraction": 0.6428505407, "num_tokens": 7128, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8438950986284991, "lm_q1q2_score": 0.7551084400130343}}
{"text": "\\newpage\r\n\\section{Special Functions}\r\n\\begin{Introduction}{Special Function Package}\r\nThe REDUCE \\name{Special Function Package} supplies extended\r\nalgebraic and numeric support for a wide class of objects.\r\nThis package was released together with REDUCE 3.5 (October 1993)\r\nfor the first time, a major update is released with REDUCE 3.6.\\\\\r\n\\\\\r\n\r\nThe functions included in this package are in most cases (unless otherwise\r\nstated) defined and named like in the book by Abramowitz and Stegun:\r\nHandbook of Mathematical Functions, Dover Publications.\\\\\r\n \\\\\r\n\r\nThe aim is to collect as much information on the special functions\r\nand simplification capabilities as possible,\r\ni.e. algebraic simplifications and numeric (rounded mode) code, limits\r\nof the functions together\r\nwith the definitions of the functions, which are in most cases a power \r\nseries, a (definite) integral and/or a differential equation.\\\\\r\n \\\\\r\n\r\n{\\em What can be found:} Some famous constants, a variety of Bessel functions,\r\nspecial polynomials,\r\nthe Gamma function, the (Riemann) Zeta function, Elliptic Functions, Elliptic\r\nIntegrals, 3J symbols (Clebsch-Gordan coefficients) and integral functions.\\\\\r\n \\\\\r\n\r\n{\\em What is missing:} Mathieu functions, LerchPhi, etc..\r\nThe information about the special functions which solve certain\r\ndifferential equation is very limited.\r\nIn several cases numerical approximation is restricted to real\r\narguments or is missing completely.\\\\\r\n \\\\\r\n\r\nThe implementation of this package uses REDUCE rule sets to a large extent,\r\nwhich guarantees a high 'readability' of the functions definitions in the\r\nsource file directory. It makes extensions to the special\r\nfunctions code easy in most cases too. To look at these rules\r\nit may be convenient to use the showrules operator e.g.\\\\\r\n \\\\\r\n \\nameref{showrules} Besseli;\\\\\r\n.\\\\\r\n\r\nSome evaluations are improved if the special function package is loaded,\r\ne.g. some (infinite) sums and products leading to expressions including\r\nspecial functions are known in this case.\\\\\r\n\\\\\r\n\r\nNote: The special function package has to be loaded explicitly by calling\r\n\\begin{verbatim}\r\n   load_package specfn;\r\n\\end{verbatim}\r\nThe functions \\nameref{MeijerG} and \\nameref{hypergeometric} require\r\nadditionally\r\n\\begin{verbatim}\r\n   load_package specfn2;\r\n\\end{verbatim}\r\n\r\n\\end{Introduction}\r\n\r\n\\begin{Concept}{Constants}\r\n\\index{Euler's constant}\\index{Catalan's constant}\\index{Khinchin's constant}\r\n\\index{Golden_Ratio}\r\n\r\nThere are a few constants known to the special function package, namely\r\n\\begin{itemize}\r\n\\item[\\name{Euler's constant }]  (which can be computed as -\\nameref{Psi}(1)) and\r\n\\item[\\name{Khinchin's constant}] (which is defined in Khinchin's book\r\n        ``Continued Fractions'') and\r\n\\item[\\name{Golden_Ratio}]  (which can be computed as (1 + sqrt 5)/2)   and\r\n\\item[\\name{Catalan's constant}] (which is known as an infinite sum of reciprocal \r\npowers)\r\n\\end{itemize}\r\n\r\n\\begin{Examples}\r\non rounded;\r\nEuler_Gamma;                 &       0.577215664902 \\\\\r\nKhinchin;                    &       2.68545200107 \\\\\r\nCatalan                      &       0.915965594177 \\\\\r\nGolden_Ratio                 &       1.61803398875\r\n\\end{Examples}\r\n\r\n\\end{Concept}\r\n\r\n\\subsection{Bernoulli Euler Zeta}\r\n\r\n\\begin{Operator}{BERNOULLI}\r\nThe \\name{bernoulli} operator returns the nth Bernoulli number.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Bernoulli}\\(\\meta{integer}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nbernoulli 20;                  &       - 174611 / 330 \\\\\r\nbernoulli 17;                  &       0\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nAll Bernoulli numbers with odd indices except for 1 are zero.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{BERNOULLIP}\r\nThe \\name{BernoulliP} operator returns the nth Bernoulli Polynomial\r\nevaluated at x.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{BernoulliP}\\(\\meta{integer},\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nBernoulliP(3,z);            &    z*(2*z^2  - 3*z + 1)/2\\\\\r\n\r\nBernoulliP(10,3);           &    338585 / 66\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe value of the nth Bernoulli Polynomial at 0 is the nth Bernoulli number. \r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{EULER}\r\nThe \\name{EULER} operator returns the nth Euler number.\r\n\r\n\\begin{Syntax}\r\n\\name{Euler}\\(\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEuler 20;                         &       370371188237525 \\\\\r\nEuler 0;                          &       1\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe \\name{Euler} numbers are evaluated by a recursive algorithm which\r\nmakes it hard to compute Euler numbers above say 200.\r\n\r\nEuler numbers appear in the coefficients of the power series \r\nrepresentation of 1/cos(z).\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{EULERP}\r\nThe \\name{EulerP} operator returns the nth Euler Polynomial.\r\n\r\n\\begin{Syntax}\r\n\\name{EulerP}\\(\\meta{integer},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEulerP(2,xx);            &  xx*(xx - 1) \\\\\r\nEulerP(10,3);            &  2046\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe Euler numbers are the values of the Euler Polynomials at 1/2\r\nmultiplied by 2**n.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{ZETA}\r\nThe \\name{Zeta} operator returns Riemann's Zeta function, \r\n\r\n  Zeta (z) := sum(1/(k**z),k,1,infinity)\r\n\r\n\\begin{Syntax}\r\n\\name{Zeta}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nZeta(2);                 &  pi^2 / 6 \\\\\r\non rounded; \\\\\r\nZeta 1.01;               &  100.577943338\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nNumerical computation for the Zeta function for arguments close to 1 are \r\ntedious, because the series is converging very slowly. In this case a formula\r\n(e.g. found in Bender/Orzag: Advanced Mathematical Methods for\r\nScientists and Engineers, McGraw-Hill) is used.\r\n\r\nNo numerical approximation for complex arguments is done.\r\n\\end{Comments}\r\n\r\n\\end{Operator}\r\n\\subsection{Bessel Functions}\r\n\r\n\\begin{Operator}{BESSELJ}\r\nThe \\name{BesselJ} operator returns the Bessel function of the first kind.\r\n\r\n\\begin{Syntax}\r\n\\name{BesselJ}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nBesselJ(1/2,pi);                &       0 \\\\\r\non rounded; \\\\\r\nBesselJ(0,1);                   &        0.765197686558  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{BESSELY}\r\n\\index{Weber's function}\r\nThe \\name{BesselY} operator returns the Bessel function of the second kind.\r\n\\begin{Syntax}\r\n\\name{BesselY}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nBesselY (1/2,pi);               &     - sqrt(2) / pi \\\\\r\non rounded; \\\\\r\nBesselY (1,3);                  &      0.324674424792\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{BesselY} is also called Weber's function.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{HANKEL1}\r\nThe \\name{Hankel1} operator returns the Hankel function of the first kind.\r\n\r\n\\begin{Syntax}\r\n\\name{Hankel1}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\non complex; \\\\\r\nHankel1 (1/2,pi);               &     - i * sqrt(2) / pi \\\\\r\nHankel1 (1,pi);                 &   besselj(1,pi) + i*bessely(1,pi)\r\n\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Hankel1} is also called Bessel function of the third kind.\r\nThere is currently no numeric evaluation of Hankel functions.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{HANKEL2}\r\nThe \\name{Hankel2} operator returns the Hankel function of the second kind.\r\n\r\n\\begin{Syntax}\r\n\\name{Hankel2}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\non complex; \\\\\r\nHankel2 (1/2,pi);               &     - i * sqrt(2) / pi \\\\\r\nHankel2 (1,pi);                 &   besselj(1,pi) - i*bessely(1,pi)\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Hankel2} is also called Bessel function of the third kind.\r\nThere is currently no numeric evaluation of Hankel functions.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{BESSELI}\r\nThe \\name{BesselI} operator returns the modified Bessel function I.\r\n\r\n\\begin{Syntax}\r\n\\name{BesselI}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\non rounded; \\\\\r\nBesseli (1,1);                  &      0.565159103992\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe knowledge about the operator \\name{BesselI} is currently fairly limited.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{BESSELK}\r\nThe \\name{BesselK} operator returns the modified Bessel function K.\r\n\r\n\\begin{Syntax}\r\n\\name{BesselK}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndf(besselk(0,x),x);            &    - besselk(1,x)\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThere is currently no numeric support for the operator \\name{BesselK}.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{StruveH}\r\nThe \\name{StruveH} operator returns Struve's H function.\r\n\r\n\\begin{Syntax}\r\n\\name{StruveH}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nstruveh(-3/2,x);               &    - besselj(3/2,x) / i\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{StruveL}\r\nThe \\name{StruveL} operator returns the modified Struve L function .\r\n\r\n\\begin{Syntax}\r\n\\name{StruveL}\\(\\meta{order},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nstruvel(-3/2,x);               &    besseli(3/2,x)\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{KummerM}\r\n\\index{Confluent Hypergeometric function}\r\nThe \\name{KummerM} operator returns Kummer's M function.\r\n\r\n\\begin{Syntax}\r\n\\name{KummerM}\\(\\meta{parameter},\\meta{parameter},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nkummerm(1,1,x);               &    e^x \\\\\r\non rounded; \\\\\r\nkummerm(1,3,1.3);             &    1.62046942914\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nKummer's M function is one of the Confluent Hypergeometric functions.\r\nFor reference see the \\nameref{hypergeometric} operator.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{KummerU}\r\n\\index{Confluent Hypergeometric function}\r\nThe \\name{KummerU} operator returns Kummer's U function.\r\n\r\n\\begin{Syntax}\r\n\\name{KummerU}\\(\\meta{parameter},\\meta{parameter},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndf(kummeru(1,1,x),x)           &    - kummeru(2,2,x)\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nKummer's U function is one of the Confluent Hypergeometric functions.\r\nFor reference see the \\nameref{hypergeometric} operator.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{WhittakerW}\r\n\\index{Confluent Hypergeometric function}\r\nThe \\name{WhittakerW} operator returns Whittaker's W function.\r\n\r\n\\begin{Syntax}\r\n\\name{WhittakerW}\\(\\meta{parameter},\\meta{parameter},\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nWhittakerW(2,2,2);     &    \\rfrac{4*sqrt(2)*kummeru(\\rfrac{1}{2},5,2)}{e}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nWhittaker's W function is one of the Confluent Hypergeometric functions.\r\nFor reference see the \\nameref{hypergeometric} operator.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Airy Functions}\r\n\r\n\\begin{Operator}{Airy_Ai}\r\nThe \\name{Airy\\_Ai} operator returns the Airy Ai function for a given argument.\r\n\r\n\\begin{Syntax}\r\n\\name{Airy\\_Ai}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\non complex;\r\non rounded;\r\nAiry_Ai(0);              &   0.355028053888          \\\\\r\nAiry_Ai(3.45 + 17.97i);   &  - 5.5561528511e+9 - 8.80397899932e+9*i  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Airy_Bi}\r\nThe \\name{Airy\\_Bi} operator returns the Airy Bi function for a given\r\nargument.\r\n\r\n\\begin{Syntax}\r\n\\name{Airy\\_Bi}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nAiry_Bi(0);              &   0.614926627446          \\\\\r\nAiry_Bi(3.45 + 17.97i);  &  8.80397899932e+9 - 5.5561528511e+9*i   \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator} \r\n\r\n\\begin{Operator}{Airy_Aiprime}\r\nThe \\name{Airy\\_Aiprime} operator returns the Airy Aiprime function for a\r\ngiven argument.\r\n\r\n\\begin{Syntax}\r\n\\name{Airy\\_Aiprime}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nAiry_Aiprime(0);              &  - 0.258819403793           \\\\\r\nAiry_Aiprime(3.45+17.97i);&  - 3.83386421824e+19 + 2.16608828136e+19*i \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Airy_Biprime}\r\nThe \\name{Airy\\_Biprime} operator returns the Airy Biprime function for a\r\ngiven argument.\r\n\r\n\\begin{Syntax}\r\n\\name{Airy\\_Biprime}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nAiry_Biprime(0);              &             \\\\\r\nAiry_Biprime(3.45 + 17.97i); & 3.84251916792e+19 - 2.18006297399e+19*i\\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\subsection{Jacobi's Elliptic Functions and Elliptic Integrals}\r\n\r\n\\begin{Operator}{JacobiSN}\r\nThe \\name{Jacobisn} operator returns the Jacobi Elliptic function sn.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobisn}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobisn(0.672, 0.36)    & 0.609519691792 \\\\\r\nJacobisn(1,0.9)          & 0.770085724907881 \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiCN}\r\nThe \\name{Jacobicn} operator returns the Jacobi Elliptic function cn.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobicn}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobicn(7.2, 0.6)      & 0.837288298482018  \\\\\r\nJacobicn(0.11, 19)      & 0.994403862690043 - 1.6219006985556e-16*i  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{JacobiDN}\r\nThe \\name{Jacobidn} operator returns the Jacobi Elliptic function dn.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobidn}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobidn(15, 0.683)     & 0.640574162024592 \\\\\r\nJacobidn(0,0)           & 1 \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiCD}\r\nThe \\name{Jacobicd} operator returns the Jacobi Elliptic function cd.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobicd}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobicd(1, 0.34)       & 0.657683337805273 \\\\\r\nJacobicd(0.8,0.8)       & 0.925587311582301 \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiSD}\r\nThe \\name{Jacobisd} operator returns the Jacobi Elliptic function sd.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobisd}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobisd(12, 0.4)       & 0.357189729437272    \\\\\r\nJacobisd(0.35,1)        &  - 1.17713873203043  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiND}\r\nThe \\name{Jacobind} operator returns the Jacobi Elliptic function nd.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobind}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobind(0.2, 17) & 1.46553203037507 + 0.0000000000334032759313703*i \\\\\r\nJacobind(30, 0.001)      & 1.00048958438  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiDC}\r\nThe \\name{Jacobidc} operator returns the Jacobi Elliptic function dc.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobidc}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobidc(0.003,1)        & 1 \\\\\r\nJacobidc(2, 0.75)        & 6.43472885111  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiNC}\r\nThe \\name{Jacobinc} operator returns the Jacobi Elliptic function nc.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobinc}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobinc(1,0)           & 1.85081571768093 \\\\\r\nJacobinc(56, 0.4387)    & 39.304842663512  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiSC}\r\nThe \\name{Jacobisc} operator returns the Jacobi Elliptic function sc.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobisc}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobisc(9, 0.88)        &  - 1.16417697982095  \\\\\r\nJacobisc(0.34, 7)        & 0.305851938390775 - 9.8768100944891e-12*i \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiNS}\r\nThe \\name{Jacobins} operator returns the Jacobi Elliptic function ns.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobins}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobins(3, 0.9)         & 1.00945801599785 \\\\\r\nJacobins(0.887, 15)      & 0.683578280513975 - 0.85023411082469*i \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiDS}\r\nThe \\name{Jacobisn} operator returns the Jacobi Elliptic function ds.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobids}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobids(98,0.223)       & - 1.061253961477 \\\\\r\nJacobids(0.36,0.6)       & 2.76693172243692 \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiCS}\r\nThe \\name{Jacobics} operator returns the Jacobi Elliptic function cs.\r\n\r\n\\begin{Syntax}\r\n\\name{Jacobics}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobics(0, 0.767)       & infinity   \\\\\r\nJacobics(1.43, 0)        & 0.141734127352112 \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiAMPLITUDE}\r\nThe \\name{JacobiAmplitude} operator returns the amplitude of u.\r\n\\begin{Syntax}\r\n\\name{JacobiAmplitude}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobiAmplitude(7.239, 0.427)  & 0.0520978301448978 \\\\\r\nJacobiAmplitude(0,0.1)         & 0 \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nAmplitude u = asin(\\name{Jacobisn(u,m)})\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{AGM_FUNCTION}\r\nThe \\name{AGM_function} operator returns a list of (N, AGM,\r\n list of aNtoa0, list of bNtob0, list of cNtoc0) where a0, b0 and c0 \r\nare the initial values; N is the index number of the last term\r\nused to generate the AGM.  AGM is the Arithmetic Geometric Mean.\r\n\r\n\\begin{Syntax}\r\n\\name{AGM_function}\\(\\meta{integer},\\meta{integer},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nAGM_function(1,1,1)   & {1,1,{1,1},{1,1},{0,1}}  \\\\\r\nAGM_function(1, 0.1, 1.3) &\r\n\\begin{multilineoutput}{6cm}\r\n\\{6,\r\n 2.27985615996629, \r\n \\{2.27985615996629, 2.27985615996629,\r\n  2.2798561599706, 2.2798624278857, \r\n  2.28742283656583, 2.55, 1\\},\r\n \\{2.27985615996629, 2.27985615996629,\r\n  2.27985615996198, 2.2798498920555, \r\n  2.27230201920557, 2.02484567313166, 4.1\\},\r\n \\{0, 4.30803136219904e-12, 0.0000062679151007581,\r\n  0.00756040868012758, 0.262577163434171, - 1.55, 5.9\\}\\}\r\n\\end{multilineoutput} \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe other Jacobi functions use this function with initial values\r\na0=1, b0=sqrt(1-m), c0=sqrt(m). \r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{LANDENTRANS}\r\nThe \\name{landentrans} operator generates the descending landen\r\ntransformation of the given imput values, returning a list of these\r\nvalues; initial to final in each case.\r\n\\begin{Syntax}\r\n\\name{landentrans}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nlandentrans(0,0.1)    & \\{\\{0,0,0,0,0\\},\\{0.1,0.0025041751943776, \\\\\r\n & 0.00000156772498954046,6.1444078 9914461e-13,0\\}\\}  \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe first list ascends in value, and the second descends in value.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{EllipticF}\r\nThe \\name{EllipticF} operator returns the Elliptic Integral of the\r\nFirst Kind.\r\n\\begin{Syntax}\r\n\\name{EllitpicF}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticF(0.3, 8.222)   & 0.3 \\\\\r\nEllipticF(7.396, 0.1)   & 7.58123216114307 \\\\ \r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe Complete Elliptic Integral of the First Kind can be found by\r\nputting the first argument to pi/2 or by using \\name{EllipticK}\r\nand the second argument.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{EllipticK}\r\nThe \\name{EllipticK} operator returns the Elliptic value K.\r\n\r\n\\begin{Syntax}\r\n\\name{EllipticK}\\(\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticK(0.2)          & 1.65962359861053   \\\\\r\nEllipticK(4.3)          & 0.808442364282734 - 1.05562492399206*i  \\\\\r\nEllipticK(0.000481)     & 1.57098526617635    \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe \\name{EllipticK} function is the Complete Elliptic Integral of \r\nthe First Kind.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{EllipticKprime}\r\nThe \\name{EllipticK'} operator returns the Elliptic value K(m).\r\n\r\n\\begin{Syntax}\r\n\\name{EllipticKprime}\\(\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticKprime(0.2)          & 2.25720532682085 \\\\\r\nEllipticKprime(4.3)          & 1.05562492399206 \\\\\r\nEllipticKprime(0.000481)     & 5.206621921966   \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe \\name{EllipticKprime} function is the Complete Elliptic Integral of \r\nthe First Kind of (1-m).\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{EllipticE}\r\nThe \\name{EllipticE} operator used with two arguments\r\nreturns the Elliptic Integral of the Second Kind.\r\n\\begin{Syntax}\r\n\\name{EllipticE}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticE(1.2,0.22)     & 1.15094019180949 \\\\\r\nEllipticE(0,4.35)       & 0                \\\\\r\nEllipticE(9,0.00719)    & 8.98312465929145  \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe Complete Elliptic Integral of the Second Kind can be obtained by\r\nusing just the second argument, or by using pi/2 as the first argument.\r\n\\end{Comments}\r\n\r\nThe \\name{EllipticE} operator used with one argument\r\nreturns the Elliptic value E.\r\n\\begin{Syntax}\r\n\\name{EllipticE}\\(\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticE(0.22)             & 1.48046637439519  \\\\\r\nEllipticE(pi/2, 0.22)       & 1.48046637439519  \\\\\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{EllipticTHETA}\r\nThe \\name{EllipticTheta} operator returns one of the four Theta \r\nfunctions. It cannot except any number other than 1,2,3 or 4 as\r\nits first argument.\r\n\r\n\\begin{Syntax}\r\n\\name{EllipticTheta}\\(\\meta{integer},\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nEllipticTheta(1, 1.4, 0.72)    & 0.91634775373  \\\\\r\nEllipticTheta(2, 3.9, 6.1 )    & -48.0202736969 + 20.9881034377 i \\\\\r\nEllipticTheta(3, 0.67, 0.2)    & 1.0083077448   \\\\\r\nEllipticTheta(4, 8, 0.75)      & 0.894963369304 \\\\\r\nEllipticTheta(5, 1, 0.1)       & ***** In EllipticTheta(a,u,m); a = 1,2,3 or 4. \r\n  \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nTheta functions are important because every one of the Jacobian\r\nElliptic functions can be expressed as the ratio of two theta functions.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiZETA}\r\nThe \\name{JacobiZeta} operator returns the Jacobian function Zeta.\r\n\r\n\\begin{Syntax}\r\n\\name{JacobiZeta}\\(\\meta{expression},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobiZeta(3.2, 0.8)    &  - 0.254536403439 \\\\\r\nJacobiZeta(0.2, 1.6)    &  0.171766095970451 - 0.0717028569800147*i  \\\\\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe Jacobian function Zeta is related to the Jacobian function Theta.\r\nBut it is significantly different from Riemann's Zeta Function \\nameref{Zeta}.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Gamma and Related Functions}\r\n\\begin{Operator}{POCHHAMMER}\r\n\r\nThe \\name{Pochhammer} operator implements the Pochhammer notation \r\n(shifted factorial).\r\n\r\n\\begin{Syntax}\r\n\\name{Pochhammer}\\(\\meta{expression},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\npochhammer(17,4);               &   116280 \\\\\r\n\r\npochhammer(1/2,z);              & \r\n \\rfrac{factorial(2*z)}{(2^{2*z}*factorial(z))}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nA number of complex rules for \\name{Pochhammer} are inactive, because they\r\ncause a huge system load in algebraic mode. If one wants to use more rules\r\nfor the simplification of Pochhammer's notation, one can do: \r\n\\\\\r\nlet special!*pochhammer!*rules;\r\n\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{GAMMA}\r\nThe \\name{Gamma} operator returns the Gamma function.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Gamma}\\(\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ngamma(10);             &       362880    \\\\\r\ngamma(1/2);            &       sqrt(pi)\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{BETA}\r\nThe \\name{Beta} operator returns the Beta function defined by\r\n\r\n   Beta (z,w) := defint(t**(z-1)* (1 - t)**(w-1),t,0,1)  .\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Beta}\\(\\meta{expression},\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nBeta(2,2);                  &       1 / 6 \\\\\r\nBeta(x,y);                  &   gamma(x)*gamma(y) / gamma(x + y)\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Beta} is simplified towards the \\nameref{GAMMA} operator.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{PSI}\r\n\\index{Euler's constant}\r\nThe \\name{Psi} operator returns the Psi (or DiGamma) function.\r\n\r\n   Psi(x) := df(Gamma(z),z)/ Gamma (z)\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Gamma}\\(\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nPsi(3);                 & (2*log(2) + psi(1/2) + psi(1) + 3)/2 \\\\\r\non rounded; \\\\\r\n- Psi(1);               &  0.577215664902\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nEuler's constant can be found as  - Psi(1). \r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{POLYGAMMA}\r\nThe \\name{Polygamma} operator returns the Polygamma function.\r\n\r\n   Polygamma(n,x) := df(Psi(z),z,n);\r\n\r\n\\begin{Syntax}\r\n\\name{Polygamma}\\(\\meta{integer},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n Polygamma(1,2);        &  (pi^2  - 6) / 6\\\\\r\non rounded; \\\\\r\nPolygamma(1,2.35);      &  0.52849689109\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe Polygamma function is used for simplification of the \\nameref{ZETA} \r\nfunction for some arguments.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Miscellaneous Functions}\r\n\r\n\\begin{Operator}{DILOG extended}\r\n\\index{Spence's Integral}\r\nThe package \\name{specfn} supplies an extended support for the\r\n\\nameref{dilog} operator  which implements the \\nameindex{dilogarithm function}.\r\n\r\ndilog(x) := - defint(log(t)/(t - 1),t,1,x);\r\n\r\n\\begin{Syntax}\r\n\\name{Dilog}\\(\\meta{order},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndefint(log(t)/(t - 1),t,1,x);  &  - dilog (x) \\\\\r\ndilog 2;                       &  - pi^2 /12 \\\\\r\n\r\non rounded; \\\\\r\nDilog 20;                      &  - 5.92783972438\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Dilog} is sometimes called Spence's Integral for n = 2.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Lambert\\_W function}\r\nLambert's W function is the inverse of the function w * e**w.\r\nIt is used in the \\nameref{solve} package for equations containing\r\nexponentials and logarithms.\r\n\r\n\\begin{Syntax}\r\n\\name{Lambert\\_W}\\(\\meta{z}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nLambert_W(-1/e);      &  -1 \\\\\r\nsolve(w + log(w),w);  & {w=lambert\\_w(1)}\\\\\r\non rounded; \\\\\r\nLambert_W(-0.05);     &  - 0.0527059835515\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe current implementation will compute the principal branch in\r\nrounded mode only.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Orthogonal Polynomials}\r\n\r\n\\begin{Operator}{ChebyshevT}\r\nThe \\name{ChebyshevT} operator computes the nth Chebyshev T Polynomial (of the\r\nfirst kind).\r\n\r\n\\begin{Syntax}\r\n\\name{ChebyshevT}\\(\\meta{integer},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nChebyshevT(3,xx);                 &   xx*(4*xx^2  - 3) \\\\\r\n\r\nChebyshevT(3,4);                  &       244\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nChebyshev's T polynomials are computed using the recurrence relation:\r\n\r\nChebyshevT(n,x) := 2x*ChebyshevT(n-1,x) - ChebyshevT(n-2,x)  with \\\\\r\nChebyshevT(0,x) := 0 and ChebyshevT(1,x) := x\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{ChebyshevU}\r\nThe \\name{ChebyshevU} operator returns the nth Chebyshev U Polynomial (of the\r\nsecond kind).\r\n\r\n\\begin{Syntax}\r\n\\name{ChebyshevU}\\(\\meta{integer},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nChebyshevU(3,xx);                 & 4*x*(2*x^2  - 1) \\\\\r\n\r\nChebyshevU(3,4);                  &      496\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nChebyshev's U polynomials are computed using the recurrence relation:\r\n\r\nChebyshevU(n,x) := 2x*ChebyshevU(n-1,x) - ChebyshevU(n-2,x)  with \\\\\r\nChebyshevU(0,x) := 0 and ChebyshevU(1,x) := 2x\r\n\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{HermiteP}\r\nThe \\name{HermiteP} operator returns the nth Hermite Polynomial.\r\n\r\n\\begin{Syntax}\r\n\\name{HermiteP}\\(\\meta{integer},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nHermiteP(3,xx);                 & 4*xx*(2*xx^2  - 3) \\\\\r\nHermiteP(3,4);                  &      464\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nHermite polynomials are computed using the recurrence relation:\r\n  \\\\\r\nHermiteP(n,x) := 2x*HermiteP(n-1,x) - 2*(n-1)*HermiteP(n-2,x)  with \\\\\r\nHermiteP(0,x) := 1 and HermiteP(1,x) := 2x\r\n\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\r\n\\begin{Operator}{LaguerreP}\r\nThe \\name{LaguerreP} operator computes the nth Laguerre Polynomial.\r\nThe two argument call of LaguerreP is a (common) abbreviation of\r\nLaguerreP(n,0,x).\r\n\r\n\\begin{Syntax}\r\n\\name{LaguerreP}\\(\\meta{integer},\\meta{expression}\\)  or\\\\\r\n\\name{LaguerreP}\\(\\meta{integer},\\meta{expression},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nLaguerreP(3,xx);                        &  (- xx^3  + 9*xx^2  - 18*xx + 6)/6\\\\\r\n\r\nLaguerreP(2,3,4);                       &       -2\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nLaguerre polynomials are computed using the recurrence relation:\r\n\r\nLaguerreP(n,a,x) := (2n+a-1-x)/n*LaguerreP(n-1,a,x) - \r\n                        (n+a-1) * LaguerreP(n-2,a,x) with \\\\\r\n \\\\\r\nLaguerreP(0,a,x) := 1 and LaguerreP(2,a,x) := -x+1+a\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{LegendreP}\r\nThe binary \\name{LegendreP} operator computes the nth Legendre\r\nPolynomial which is\r\na special case of the nth Jacobi Polynomial with \\\\\r\n \\\\\r\nLegendreP(n,x) := JacobiP(n,0,0,x)\\\\\r\n  \\\\\r\nThe ternary form returns the associated Legendre Polynomial (see below).\r\n\r\n\\begin{Syntax}\r\n\\name{LegendreP}\\(\\meta{integer},\\meta{expression}\\)      or\\\\\r\n\\name{LegendreP}\\(\\meta{integer},\\meta{expression},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nLegendreP(3,xx);                &\\rfrac{xx*(5*xx^2  - 3)}{2}\\\\\r\n\r\nLegendreP(3,2,xx);              &15*xx*( - xx^2  + 1)\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe ternary form of the operator \\name{LegendreP} is the associated\r\nLegendre Polynomial defined as \\\\ \r\n\\\\\r\n  P(n,m,x) = (-1)**m * (1-x**2)**(m/2) * df(LegendreP(n,x),x,m)\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{JacobiP}\r\nThe \\name{JacobiP} operator computes the nth Jacobi Polynomial.\r\n\r\n\\begin{Syntax}\r\n\\name{JacobiP}\\(\\meta{integer},\\meta{expression},\\meta{expression},\r\n   \\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nJacobiP(3,4,5,xx);      & \\rfrac{7*(65*xx^3  - 13*xx^2  - 13*xx + 1)}{8}\\\\\r\n\r\nJacobiP(3,4,5,6);       &       94465/8\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{GegenbauerP}\r\n\\index{ultraspherical polynomials}\r\nThe \\name{GegenbauerP} operator computes Gegenbauer's (ultraspherical)\r\npolynomials.\r\n\r\n\\begin{Syntax}\r\n\\name{GegenbauerP}\\(\\meta{integer},\\meta{expression},\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nGegenbauerP(3,2,xx);              &       4*xx*(8*xx^2  - 3)\\\\\r\n\r\nGegenbauerP(3,2,4);               &       2000\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{SolidHarmonicY}\r\n\\index{Solid harmonic polynomials}\r\nThe \\name{SolidHarmonicY} operator computes Solid harmonic (Laplace)\r\npolynomials.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{SolidHarmonicY}\\(\\meta{integer},\\meta{integer},\r\n\\meta{expression},\\meta{expression},\\meta{expression},\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n\r\nSolidHarmonicY(3,-2,x,y,z,r2); &\r\n\r\n\\rfrac{sqrt(105)*z*(-2*i*x*y + x^2 - y^2)}{4*sqrt(pi)*sqrt(2)}\\\\\r\n\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{SphericalHarmonicY}\r\n\\index{Spherical harmonic polynomials}\r\nThe \\name{SphericalHarmonicY} operator computes Spherical harmonic (Laplace)\r\npolynomials. These are special cases of the\r\nsolid harmonic polynomials, \\nameref{SolidHarmonicY}.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{SphericalHarmonicY}\\(\\meta{integer},\\meta{integer},\r\n\\meta{expression},\\meta{expression}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nSphericalHarmonicY(3,2,theta,phi); &\r\n \r\n\\rfrac{sqrt(105)*cos(theta)*sin(theta)^2*(cos(phi)^2+2*cos(phi)*sin(phi)*i-\r\nsin(phi)^2)}{4*sqrt(pi)*sqrt(2)}\\\\\r\n\r\n\\end{Examples}\r\n\r\n\\end{Operator}\r\n\r\n\r\n\\subsection{Integral Functions}\r\n\\index{sine integral function}\r\n\\begin{Operator}{Si}\r\n\\index{Sine integral function}\\index{integral function}\r\nThe \\name{Si} operator returns the Sine Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Si}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nlimit(Si(x),x,infinity);          &       pi / 2 \\\\\r\non rounded; \\\\\r\nSi(0.35);                         &       0.347626790989\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{Si} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Shi}\r\n\\index{hyperbolic sine integral function}\\index{integral function}\r\nThe \\name{Shi} operator returns the hyperbolic Sine Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Shi}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndf(shi(x),x);                      &     sinh(x) / x \\\\\r\non rounded; \\\\\r\nShi(0.35);                         &    0.352390716351\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{Shi} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{s_i}\r\n\\index{sine integral function}\\index{integral function}\r\nThe \\name{s_i} operator returns the Sine Integral function si.\r\n\r\n\\begin{Syntax}\r\n\\name{s_i}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ns_i(xx);          &       (2*Si(xx) - pi) / 2 \\\\\r\ndf(s_i(x),x);     &       sin(x) / x\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator name \\name{s_i} is simplified towards \\nameref{SI}.\r\nSince REDUCE is not case sensitive by default the name ``si'' can't be\r\nused.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Ci}\r\n\\index{cosine integral function}\r\nThe \\name{Ci} operator returns the Cosine Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Ci}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndefint(cos(t)/t,t,x,infinity);     &    - ci (x) \\\\\r\non rounded; \\\\\r\nCi(0.35);                          &    - 0.50307556932\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{Ci} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Chi}\r\n\\index{hyperbolic cosine integral function}\\index{integral function}\r\nThe \\name{Chi} operator returns the Hyperbolic Cosine Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Chi}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndefint((cosh(t)-1)/t,t,0,x);       &   - log(x) + psi(1) + chi(x)\\\\\r\non rounded; \\\\\r\nChi(0.35);                         &   - 0.44182471827\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{Chi} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{ERF extended}\r\n\\index{error function}\r\nThe special function package supplies an extended support for the\r\n\\nameref{erf} operator  which implements the \\nameindex{error function} \\\\\r\n \\\\\r\n  defint(e**(-x**2),x,0,infinity) * 2/sqrt(pi) \\\\\r\n.\\\\\r\n\\begin{Syntax}\r\n\\name{erf}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nerf(-x);                        &   - erf(x)\\\\\r\non rounded; \\\\\r\nerf(0.35);                      &   0.379382053562\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{erf} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{erfc}\r\n\\index{error function}\\index{complementary error function}\r\nThe \\name{erfc} operator returns the complementary Error function\\\\\r\n \\\\\r\n  1 - defint(e**(-x**2),x,0,infinity) * 2/sqrt(pi) \\\\\r\n.\\\\\r\n\\begin{Syntax}\r\n\\name{erfc}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nerfc(xx);                     &      - erf(xx) + 1\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{erfc} is simplified towards the \\nameref{erf} operator.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Ei}\r\n\\index{exponential integral function}\r\nThe \\name{Ei} operator returns the Exponential Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Ei}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\ndf(ei(x),x);               &   \\rfrac{e^x}{x}\\\\\r\non rounded; \\\\\r\nEi(0.35);                  &    - 0.0894340019184\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe numeric values for the operator \\name{Ei} are computed via the\r\npower series representation, which limits the argument range.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Fresnel_C}\r\nThe \\name{Fresnel_C} operator represents Fresnel's Cosine function.\r\n\r\n\\begin{Syntax}\r\n\\name{Fresnel_C}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nint(cos(t^2*pi/2),t,0,x);     &   fresnel\\_c(x) \\\\\r\non rounded; \\\\\r\nfresnel_c(2.1);                  &   0.581564135061\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Fresnel_C} has a limited numeric evaluation of \r\nlarge values of its argument.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Fresnel_S}\r\nThe \\name{Fresnel_S} operator represents Fresnel's Sine Integral function.\r\n\r\n\\begin{Syntax}\r\n\\name{Fresnel_S}\\(\\meta{expression}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nint(sin(t^2*pi/2),t,0,x);     &   fresnel\\_s(x) \\\\\r\non rounded; \\\\\r\nfresnel_s(2.1);                  &   0.374273359378\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Fresnel_S} has a limited numeric evaluation of \r\nlarge values of its argument.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Combinatorial Operators}\r\n\r\n\\begin{Operator}{BINOMIAL}\r\nThe \\name{Binomial} operator returns the Binomial coefficient if both\r\nparameter are integer and expressions involving the Gamma function otherwise.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Binomial}\\(\\meta{integer},\\meta{integer}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nBinomial(49,6);                &  13983816 \\\\\r\n\r\nBinomial(n,3);                 &  \\rfrac{gamma(n + 1)}{6*gamma(n - 2)}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Binomial} evaluates the Binomial coefficients from \r\nthe explicit form and therefore it is not the best algorithm if you\r\nwant to compute many binomial coefficients with big indices in which\r\ncase a recursive algorithm is preferable.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{STIRLING1}\r\nThe \\name{Stirling1} operator returns the Stirling Numbers S(n,m) of the first\r\nkind, i.e. the number of permutations of n symbols which have exactly m cycles\r\n(divided by (-1)**(n-m)).\r\n\r\n\\begin{Syntax}\r\n\\name{Stirling1}\\(\\meta{integer},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nStirling1 (17,4);              &       -87077748875904 \\\\\r\nStirling1 (n,n-1);             &  \\rfrac{-gamma(n+1)}{2*gamma(n-1)}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Stirling1} evaluates the Stirling numbers of the\r\nfirst kind by rulesets for special cases or by a computing the closed\r\nform, which is a series involving the operators \\nameref{BINOMIAL}\r\nand \\nameref{STIRLING2}.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{STIRLING2}\r\nThe \\name{Stirling1} operator returns the Stirling Numbers S(n,m) of the \r\nsecond kind, i.e. the number of ways of partitioning a set of n elements\r\ninto m non-empty subsets.\r\n\r\n\\begin{Syntax}\r\n\\name{Stirling2}\\(\\meta{integer},\\meta{integer}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nStirling2 (17,4);              &       694337290 \\\\\r\nStirling2 (n,n-1);             &   \\rfrac{gamma(n+1)}{2*gamma(n-1)}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{Stirling2} evaluates the Stirling numbers of the\r\nsecond kind by rulesets for special cases or by a computing the closed\r\nform. \r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{3j and  6j symbols}\r\n\r\n\\begin{Operator}{ThreejSymbol}\r\nThe \\name{ThreejSymbol} operator implements the 3j symbol.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{ThreejSymbol}\\(\\meta{list of j1,m1},\\meta{list of j2,m2},\r\n\\meta{list of j3,m3}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n\r\nThreejSymbol({j+1,m},{j+1,-m},{1,0}); & \r\n\r\n\\rfrac{( - 1)^j *(abs(j - m + 1) - abs(j + m + 1))}\r\n        { 2*sqrt(2*j^3  + 9*j^2  + 13*j + 6)*( - 1)^m}\\\\\r\n\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Clebsch_Gordan}\r\nThe \\name{Clebsch\\_Gordan} operator implements the Clebsch\\_Gordan\r\ncoefficients. This is closely related to the \\nameref{Threejsymbol}.\r\n\r\n\\begin{Syntax}\r\n\r\n\\name{Clebsch\\_Gordan}\\(\\meta{list of j1,m1},\\meta{list of j2,m2},\r\n\\meta{list of j3,m3}\\)\r\n\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\n Clebsch_Gordan({2,0},{2,0},{2,0});  & \\rfrac{-2}{sqrt(14)}\\\\\r\n\\end{Examples}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{SixjSymbol}\r\nThe \\name{SixjSymbol} operator implements the 6j symbol.\r\n\\begin{Syntax}\r\n\r\n\\name{SixjSymbol}\\(\\meta{list of j1,j2,j3},\\meta{list of l1,l2,l3}\\)\r\n\r\n\\end{Syntax}\r\n\\begin{Examples}\r\n\r\nSixjSymbol({7,6,3},{2,4,6}); & \\rfrac{1}{14*sqrt(858)}\\\\\r\n\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe operator \\name{SixjSymbol} uses the \\nameref{ineq} package in order\r\nto find minima and maxima for the summation index.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\subsection{Miscellaneous}\r\n\r\n\r\n\\begin{Operator}{HYPERGEOMETRIC}\r\n\\index{hypergeometric function}\r\n\\index{generalized hypergeometric function}\r\nThe \\name{Hypergeometric} operator  provides simplifications for the \r\ngeneralized hypergeometric functions. \r\nThe \\name{Hypergeometric} operator is included in the package specfn2.\r\n\r\n\\begin{Syntax}\r\n\\name{hypergeometric}\\(\\meta{list of parameters},\\meta{list of parameters},\r\n   \\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Examples}\r\nload specfn2;\\\\\r\nhypergeometric ({1/2,1},{3/2},-x^2); & \\rfrac{atan(x)}{x}\\\\\r\nhypergeometric ({},{},z);      &   e^z\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nThe special case where the length of the first list is equal to 2 and\r\nthe length of the second list is equal to 1 is often called\r\n``the hypergeometric function'' (notated as 2F1(a1,a2,b;x)).\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{MeijerG}\r\nThe \\name{MeijerG} operator provides simplifications for Meijer's G  \r\nfunction. The simplifications are performed towards polynomials,\r\nelementary or\r\nspecial functions or (generalized) \\nameref{hypergeometric} functions.\r\n\r\nThe \\name{MeijerG} operator is included in the package specfn2.\r\n\r\n\\begin{Syntax}\r\n\\name{MeijerG}\\(\\meta{list of parameters},\\meta{list of parameters},\r\n   \\meta{argument}\\)\r\n\\end{Syntax}\r\nThe first element of the lists has to be the list containing the\r\nfirst group (mostly called ``m'' and ``n'') of parameters. This passes\r\nthe  four parameters of a Meijer's G function implicitly via the\r\nlength of the lists.\r\n\r\n\\begin{Examples}\r\nload specfn2;\\\\\r\nMeijerG({{},1},{{0}},x);       &   heaviside(-x+1)\\\\\r\nMeijerG({{}},{{1+1/4},1-1/4},(x^2)/4) * sqrt pi;\r\n                & \\rfrac{sqrt(2)*sin(x)*x^2}{4*sqrt(x)}\r\n\\end{Examples}\r\n\r\n\\begin{Comments}\r\nMany well-known functions can be written as G functions,\r\ne.g. exponentials, logarithms, trigonometric functions, Bessel functions\r\nand hypergeometric functions.\r\nThe formulae can be found e.g. in \\\\\r\nA.P.Prudnikov, Yu.A.Brychkov, O.I.Marichev: \r\nIntegrals and Series, Volume 3: More special functions,\r\nGordon and Breach Science Publishers (1990).\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{Heaviside}\r\n\r\nThe \\name{Heaviside} operator returns the Heaviside function. \\\\\r\n\r\nHeaviside(~w) => if (w < 0) then 0 else 1 \\\\\r\n    when numberp w;\r\n\r\n\\begin{Syntax}\r\n\\name{Heaviside}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Comments}\r\nThis operator is often included in the result of the simplification\r\nof a generalized \\nameref{hypergeometric} function or a\r\n\\nameref{MeijerG} function.\r\n\r\nNo simplification is done for this function.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n\\begin{Operator}{erfi}\r\n\r\nThe \\name{erfi} operator returns the error function of an imaginary argument.\r\n\r\nerfi(~x) => 2/sqrt(pi) * defint(e**(t**2),t,0,x); \r\n\r\n\\begin{Syntax}\r\n\\name{erfi}\\(\\meta{argument}\\)\r\n\\end{Syntax}\r\n\r\n\\begin{Comments}\r\nThis operator is sometimes included in the result of the simplification\r\nof a generalized \\nameref{hypergeometric} function or a\r\n\\nameref{MeijerG} function.\r\n\r\nNo simplification is done for this function.\r\n\\end{Comments}\r\n\\end{Operator}\r\n\r\n", "meta": {"hexsha": "e8b262516898e64f39d232ac61e9525a5aecf25c", "size": 43801, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pk-specf.tex", "max_stars_repo_name": "nilqed/REDHELP", "max_stars_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pk-specf.tex", "max_issues_repo_name": "nilqed/REDHELP", "max_issues_repo_head_hexsha": "0c98a32bf21fa060ccd67ce82f638d6a1bc47a52", "max_issues_repo_licenses": ["BSD-2-Clause"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pk-specf.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": 27.3243917654, "max_line_length": 83, "alphanum_fraction": 0.6700075341, "num_tokens": 13777, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894520743981, "lm_q2_score": 0.8438951045175643, "lm_q1q2_score": 0.7551084381795383}}
{"text": "\\section{Linear dynamical systems}\n\\subsection{Linear dynamical systems}\n$x_{t+1} = A_tx_t$ , t = 1,2,. . .\\\\\n\\textbullet $A_t$ are n × n dynamics matrices\n\\textbullet $(A_t)_{ij}(x_t)_j\nis contribution to (x_{t+1})_i\nfrom (x_t)_j$\\\\\n\\textbullet system is called time-invariant if $A_t = A$ doesn't depend on time\\\\\n\\textbullet can simulate evolution of xt using recursion $x_{t+1} = A_tx$\\\\\n\\textbullet linear dynamical system with input\\\\\n$x_{t+1} = A_tx_t + B_tu_t + c_t$, t = 1,2,...\\\\\n\\thickspace -- $u_t$ is an input m-vector\\\\\n\\thickspace -- $B_t$ is n × m input matrix\\\\\n\\thickspace -- $c_t$ is offset\\\\\n\\textbf{K-Markov model}:\\\\\n$x_{t+1} = A_1x_t + ... + A_Kx_{t-K+1}$, t = K,K + 1,...\\\\\n\\thickspace -- next state depends on current state and K - 1 previous states\\\\\n\\thickspace – also known as auto-regresssive model\\\\\n\\thickspace – for K = 1, this is the standard linear dynamical system $x_{t+1} = Ax_t$\\\\\n\\subsection{Population dynamics}\n\n\\subsection{Epidemic dynamics}\n\\subsection{Motion of a mass}\n\\subsection{Supply chain dynamics}", "meta": {"hexsha": "31c0726d1e82ef2d8f021f0fe76bac94debedbe0", "size": 1048, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_stars_repo_name": "Bharat-Kulkarni/COT5615", "max_stars_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_issues_repo_name": "Bharat-Kulkarni/COT5615", "max_issues_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "cheatsheet/inhalt/chapter9.tex", "max_forks_repo_name": "Bharat-Kulkarni/COT5615", "max_forks_repo_head_hexsha": "2fc2f1b08976b1f34cfc1e941c67b25eb0e58fdf", "max_forks_repo_licenses": ["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.6666666667, "max_line_length": 88, "alphanum_fraction": 0.6908396947, "num_tokens": 365, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9343951643678382, "lm_q2_score": 0.8080672158638527, "lm_q1q2_score": 0.755054098987366}}
{"text": "\\chapter{Divide-and-Conquer}\n\n\\section{The maximum-subarray problem}\n\n\\begin{enumerate}\n\n\\item[4.1{-}1]{What does \\textsc{Find-Maximum-Subarray} return when all\nelements of A are negative?}\n\n\\begin{framed}\nA subarray with only the largest negative element of $A$.\n\\end{framed}\n\n\\item[4.1{-}2]{Write pseudocode for the brute-force method of solving the\nmaximum-subarray problem. Your procedure should run in $\\Theta(n^2)$ time.}\n\n\\begin{framed}\nThe pseudocode is stated below.\\\\\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{FindMaximumSubarray-BruteForce}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $low = 0$\\;\n\\nl $high = 0$\\;\n\\nl $sum = -\\infty$\\;\n\\nl \\For{$i = 1$ \\KwTo $A.length$}{%\n\\nl   $cursum = 0$\\;\n\\nl   \\For {$j = i$ \\KwTo $A.length$}{%\n\\nl     $cursum = cursum + A[j]$\\;\n\\nl     \\If{$cursum > sum$}{%\n\\nl       $sum = cursum$\\;\n\\nl       $low = i$\\;\n\\nl       $high = j$\\; } } }\n\\nl \\Return{$low, high, sum$} }\n\\end{algorithm}\n\\end{framed}\n\n\\item[4.1{-}3]{Implement both the brute-force and recursive algorithms for the\nmaximum-subarray problem on your own computer. What problem size $n_0$ gives\nthe crossover point at which the recursive algorithm beats the brute-force\nalgorithm? Then, change the base case of the recursive algorithm to use the\nbrute-force algorithm whenever the problem size is less than $n_0$. Does\nthat change the crossover point?}\n\n\n\n\\begin{framed}\nFigure below in the lhs ilustrates the crossover point between the\nBruteForce and Recursive solutions in my machine. In that comparison, $n_0\n\\approx 52$. Figure below in the rhs ilustrates the crossover point\nbetween the BruteForce and Mixed solutions in my machine. The crossover point\ndoes not change but the Mixed solution becomes as fast as the BruteForce\nsolution when the problem size is lower than 52.\n\n\\begin{center}\n\\includegraphics[width=0.35\\textwidth]{images/4_1_3_1.pdf}\n\\includegraphics[width=0.35\\textwidth]{images/4_1_3_2.pdf}\n\\end{center}\n\\end{framed}\n\n\\item[4.1{-}4]{Suppose we change the definition of the maximum-subarray problem\nto allow the result to be an empty subarray, where the sum of the values of an\nempty subarray is 0. How would you change any of the algorithms that do not\nallow empty subarrays to permit an empty subarray to be the result?}\n\n\\begin{framed}\nThe BruteForce algorithm (stated above in Question 4.1{-}2) can be updated just\nby modifying line 3 to $sum = 0$, instead of $sum = -\\infty$. In that case, if\nthere is no subarray whose sum is greater than zero, the algorithm will return\na invalid subarray ($low = 0, high = 0, sum = 0$), which will denote the empty\nsubarray.\n\nThe Recursive algorithm (stated in Section 4.1) can be updated as follows. In\nthe \\textsc{Find-Max-Crossing-Subarray} routine, update lines 1 and 8 to\ninitialize $left \\mhyphen sum$ and $right \\mhyphen sum$ to 0, instead of\n$-\\infty$. Also initialize $max \\mhyphen left$ (after line 1) and $max \\mhyphen\nright$ (after line 8) to 0. In the \\textsc{Find-Maximum-Subarray} routine,\nsurround the return statement of line 2  with a conditional that\nverifies if $A[low]$ is greater than zero. If it is, return the values as it was\nbefore. If it is not, return a invalid subarray (denoted by $low = 0$ and\n$high = 0$) and the sum as zero.\n\\end{framed}\n\n\\item[4.1{-}5]{Use the following ideas to develop a nonrecursive, linear-time\nalgorithm for the maximum-subarray problem. Start at the left end of the\narray, and progress toward the right, keeping track of the maximum subarray\nseen so far. Knowing a maximum subarray of $A[1, \\dots, j]$, extend the answer\nto find a maximum subarray ending at index $j + 1$ by using the following\nobservation: a maximum subarray of $A[1, \\dots, j + 1]$ is either a maximum\nsubarray of $A[1, \\dots, j]$ or a subarray $A[i, \\dots, j + 1]$, for some\n$1 \\le i \\le j + 1$. Determine a maximum subarray of the form $A[i, \\dots,\nj + 1]$ in constant time based on knowing a maximum subarray ending at index\n$j$.}\n\n\\begin{framed}\nThe pseudocode is stated below.\\\\\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{FindMaximumSubarray-Linear}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $low = 0$\\;\n\\nl $high = 0$\\;\n\\nl $sum = 0$\\;\n\\nl $current \\mhyphen low = 0$\\;\n\\nl $current \\mhyphen sum = 0$\\;\n\\nl \\For{$i = 1$ \\KwTo $A.length$}{%\n\\nl   $current \\mhyphen sum = \\max(A[i], current \\mhyphen sum + A[i])$\\;\n\\nl   \\If{$current \\mhyphen sum == A[i]$}{%\n\\nl     $current \\mhyphen low = i$\\; }\n\\nl   \\If{$current \\mhyphen sum > sum$}{%\n\\nl     $low = current \\mhyphen low$\\;\n\\nl     $high = i$\\;\n\\nl     $sum = current \\mhyphen sum$\\; } }\n\\nl \\Return{$low, high, sum$} }\n\\end{algorithm}\n\n\\vspace{0.5mm}\n\nWe can make it a little faster (twice as fast on my machine) by avoiding\nexecuting lines 7, 8, and 10 when not necessary.\\\\\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{FindMaximumSubarray-Linear-Optimized}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $low = 0$\\;\n\\nl $high = 0$\\;\n\\nl $sum = 0$\\;\n\\nl $current \\mhyphen low = 0$\\;\n\\nl $current \\mhyphen sum = 0$\\;\n\\nl \\For{$i = 1$ \\KwTo $A.length$}{%\n\\nl   \\If{$current \\mhyphen sum + A[i] \\le 0$}{%\n\\nl     $current \\mhyphen sum = 0$\\; }\n\\nl   \\Else{%\n\\nl     $current \\mhyphen sum = current \\mhyphen sum + A[i]$\\;\n\\nl     \\If{$current \\mhyphen sum == A[i]$}{%\n\\nl       $current \\mhyphen low = i$\\; }\n\\nl     \\If{$current \\mhyphen sum > sum$}{%\n\\nl       $low = current \\mhyphen low$\\;\n\\nl       $high = i$\\;\n\\nl       $sum = current \\mhyphen sum$\\; } } }\n\\nl \\Return{$low, high, sum$} }\n\\end{algorithm}\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Strassen's algorithm for matrix multiplication}\n\n\\begin{enumerate}\n\n\\item[4.2{-}1]{Use Strassen's algorithm to compute the matrix product\n\\[\n\\begin{bmatrix}\n  1 & 3\\\\\n  7 & 5\n\\end{bmatrix}\n\\begin{bmatrix}\n  6 & 8\\\\\n  4 & 2\n\\end{bmatrix}\n.\n\\]\nShow your work.\n}\n\n\\begin{framed}\nLet\n\\[\n  A = \\begin{bmatrix} 1 & 3\\\\ 7 & 5 \\end{bmatrix},\n  B = \\begin{bmatrix} 6 & 8\\\\ 4 & 2 \\end{bmatrix},\n\\]\nand $C = A \\cdot B$. To compute $C$ using Strassen's algorithm, we start by\ncomputing the $S_i$ matrices:\n\\begin{equation*}\n\\begin{aligned}\nS_1 \\; &= \\; B_{12} - B_{22} \\; = \\; 8 - 2 \\; = \\; 6,\\\\\nS_2 \\; &= \\; A_{11} + A_{12} \\; = \\; 1 + 3 \\; = \\; 4,\\\\\nS_3 \\; &= \\; A_{21} + A_{22} \\; = \\; 7 + 5 \\; = \\; 12,\\\\\nS_4 \\; &= \\; B_{21} - B_{11} \\; = \\; 4 - 6 \\; = \\; -2,\\\\\nS_5 \\; &= \\; A_{11} + A_{22} \\; = \\; 1 + 5 \\; = \\; 6,\\\\\nS_6 \\; &= \\; B_{11} + B_{22} \\; = \\; 6 + 2 \\; = \\; 8,\\\\\nS_7 \\; &= \\; A_{12} + A_{22} \\; = \\; 3 - 5 \\; = \\; -2,\\\\\nS_8 \\; &= \\; B_{21} + B_{22} \\; = \\; 4 + 2 \\; = \\; 6,\\\\\nS_9 \\; &= \\; A_{11} - A_{21} \\; = \\; 1 - 7 \\; = \\; -6,\\\\\nS_{10} \\; &= \\; B_{11} + B_{12} \\; = \\; 6 + 8 \\; = \\; 14.\n\\end{aligned}\n\\end{equation*}\n\nThen we compute the $P_i$ matrices:\n\\begin{equation*}\n\\begin{aligned}\n  P_1 \\; &= \\; A_11 \\cdot S_1 \\; &&= \\; 1 \\cdot 6 \\; &&= \\; 6,\\\\\n  P_2 \\; &= \\; S_2 \\cdot B_22 \\; &&= \\; 4 \\cdot 2 \\; &&= \\; 8,\\\\\n  P_3 \\; &= \\; S_3 \\cdot B_11 \\; &&= \\; 12 \\cdot 6 \\; &&= \\; 72,\\\\\n  P_4 \\; &= \\; A_22 \\cdot S_4 \\; &&= \\; 5 \\cdot (-2) \\; &&= \\; -10,\\\\\n  P_5 \\; &= \\; S_5 \\cdot S_6 \\; &&= \\; 6 \\cdot 8 \\; &&= \\; 48,\\\\\n  P_6 \\; &= \\; S_7 \\cdot S_8 \\; &&= \\; (-2) \\cdot 6 \\; &&= \\; -12,\\\\\n  P_7 \\; &= \\; S_9 \\cdot S_10 \\; &&= \\; (-6) \\cdot 14 \\; &&= \\; -84.\n\\end{aligned}\n\\end{equation*}\n\nUsing matrices $S_i$ and $P_i$, we compute $C$:\n\\[\nC =\n\\begin{bmatrix}\n(P_5 + P_4 - P_2 + P_6) & (P_2 + P_2)\\\\ (P_3 + P_4) & (P_5 + P_1 - P_3 - P_7)\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n18 & 14\\\\ 62 & 66\n\\end{bmatrix}\n.\n\\]\n\\end{framed}\n\n\\newpage\n\n\\item[4.2{-}2]{Write pseudocode for Strassen's algorithm.}\n\n\\begin{framed}\nThe pseudocode is stated below.\\\\\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Square-Matrix-Multiply-Strassen}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, B}}{%\n\\nl $n = A.rows$\\;\n\\nl let $C$ be a new $n \\times n$ matrix\\;\n\\nl \\If{$n == 1$}{%\n\\nl   $c_{11} = a_{11} \\cdot b_{11}$\\; }\n\\nl \\Else{%\n\\nl   partition $A, B$, and $C$ as into $n/2 \\times n/2$ submatrices\\;\n\\nl   let $S_1, S_2, \\dots, S_{10}$ be new $n/2 \\times n/2$ matrices\\;\n\\nl   let $P_1, P_2, \\dots, P_7$ be new $n/2 \\times n/2$ matrices\\;\n\\nl   $S_1 = B_{12} - B_{22}$\\;\n\\nl   $S_2 = A_{11} + A_{12}$\\;\n\\nl   $S_3 = A_{21} + A_{22}$\\;\n\\nl   $S_4 = B_{21} - B_{11}$\\;\n\\nl   $S_5 = A_{11} + A_{22}$\\;\n\\nl   $S_6 = B_{11} + B_{22}$\\;\n\\nl   $S_7 = A_{12} - A_{22}$\\;\n\\nl   $S_8 = B_{21} + B_{22}$\\;\n\\nl   $S_9 = A_{11} - A_{21}$\\;\n\\nl   $S_{10} = B_{11} - B_{12}$\\;\n\\nl   $P_1 =$ \\texttt{Square-Matrix-Multiply-Strassen}($A_{11}, S_1$)\\;\n\\nl   $P_2 =$ \\texttt{Square-Matrix-Multiply-Strassen}($S_2, B_{22}$)\\;\n\\nl   $P_3 =$ \\texttt{Square-Matrix-Multiply-Strassen}($S_3, B_{11}$)\\;\n\\nl   $P_4 =$ \\texttt{Square-Matrix-Multiply-Strassen}($A_{22}, S_4$)\\;\n\\nl   $P_5 =$ \\texttt{Square-Matrix-Multiply-Strassen}($S_5, S_6$)\\;\n\\nl   $P_6 =$ \\texttt{Square-Matrix-Multiply-Strassen}($S_7, S_8$)\\;\n\\nl   $P_7 =$ \\texttt{Square-Matrix-Multiply-Strassen}($S_9, S_{10}$)\\;\n\\nl   $C_{11} = P_5 + P_4 - P_2 + P_6$ \\;\n\\nl   $C_{12} = P_1 + P_2$ \\;\n\\nl   $C_{21} = P_3 + P_4$ \\;\n\\nl   $C_{22} = P_5 + P_1 - P_3 - P_7$ \\; }\n\\nl \\Return{$C$} }\n\\end{algorithm}\n\\end{framed}\n\n\\item[4.2{-}3]{How would you modify Strassen's algorithm to multiply $n \\times\nn$ matrices in which $n$ is not an exact power of 2? Show that the resulting\nalgorithm runs in time $\\Theta(n^{\\lg 7})$.}\n\n\\begin{framed}\nPad each input $n \\times n$ matrix (rows and columns) with $m - n$ zeros,\nresulting in an $m \\times m$ matrix, where $m = 2^{\\ceil{\\lg n}}$. After\ncomputing the final matrix, cut down the last $m - n$ rows and $m - n$ columns\n(which will be zeros).\n\nPadding the matrix with zeros is done once, in the root of the recursion tree,\nand takes $O(m^2)$. Since we now have an $m \\times m$ matrix, the algorithm runs\nin $\\Theta(m^{\\lg 7}) + O(m^2) = \\Theta(m^{\\lg 7})$. We have that\n$n \\le m <  2^{(\\lg n) + 1} = 2^{\\lg n} \\cdot 2 = 2n.$ Thus, the\nalgorithm runs in $\\Theta((2n)^{\\lg 7}) = \\Theta(n^{\\lg 7})$.\n\\end{framed}\n\n\\item[4.2{-}4]{What is the largest $k$ such that if you can multiply\n$3 \\times 3$ matrices using $k$ multiplications (not assuming commutativity of\nmultiplication), then you can multiply $n \\times n$ matrices in time\n$o(n^{\\lg 7})$?  What would the running time of this algorithm be?\n}\n\n\\begin{framed}\nIf we modify the \\textsc{Square-Matrix-Multiply-Recursive} algorithm to\npartition the matrices into $n/3 \\times n/3$ submatrices, we would have the\nfollowing recurrence:\n\\[\nT(n) = \\Theta(1) + 27 T(n/3) + \\Theta(n^2) = 27 T(n/3) + \\Theta(n^2).\n\\]\n\nLet's proceed to understand a little more about the above recurrence. Let $A$\nand $B$ be the two input matrices in each node of the above recursion tree.\nLike in the original \\textsc{Square-Matrix-Multiply-Recursive} algorithm, our\nmodified version will take $\\Theta(1)$ to partition $A$ and $B$ into $n/3 \\times\nn/3$ submatrices. In each node of the tree, the product of $A$ and $B$ is\nrecursively computed by the products of their submatrices. Since the number of\nrecursive (submatrices) products to compute $A \\cdot B$ in each node of the\nrecurstion tree is 27 and each of these submatrices is $3$ times smaller than\n$A$ and $B$, the 27 recursive products takes $27 T(n/3)$. Finally, the number of\nsummations to compute the final matrix is\n$\\Theta(3 \\cdot 9 \\cdot n^2/3) = \\Theta(n^2)$.\n\nIf after partitioning $A$ and $B$ into $n/3 \\times n/3$ submatrices we can\ncompute their product with $k$ multiplications (instead of 27), we would have\nthe following recurrence:\n\\[\nT(n) = \\Theta(1) + k T(n/3) + \\Theta(n^2) = k T(n/3) + \\Theta(n^2),\n\\]\n\nWe can solve the above recurrence using the master method. We have\n$f(n) = n^2$ and $n^{log_b a} = n^{\\log_3 k}$. Using the first case of the master\nmethod, we have\n\\[\n\\Forall k \\; | \\log_3 k > 2, \\; n^2 = O(n^{(\\log_3 k) - \\epsilon}), \\; 0 \\le \\epsilon \\le \\log_3 k - 2,\n\\]\nwhich implies\n\\[\nT(n) = \\Theta(n^{\\log_3 k}).\n\\]\n\nSince $\\log_3 21 < \\lg 7 < \\log_3 22$, the largest value for $k$ is 21. Its\nrunning time would be $n^{\\log_3 21} \\approx n^{2.7712}$.\n\n\\end{framed}\n\n\\item[4.2{-}5]{V. Pan has discovered a way of multiplying $68 \\times 68$\nmatrices using 132,464 multiplications, a way of multiplying $70 \\times 70$\nmatrices using 143,640 multiplications, and a way of multiplying $72 \\times 72$\nmatrices using 155,424 multiplications. Which method yields the best asymptotic\nrunning time when used in a divide-and-conquer matrix-multiplication algorithm?\nHow does it compare to Strassen's algorithm?}\n\n\\begin{framed}\nThe algorithms would take:\n\\begin{itemize}\n  \\item $n^{\\log_{68} 132,464} \\approx n^{2.795128}$,\n  \\item $n^{\\log_{70} 143,640} \\approx n^{2.795122}$,\n  \\item $n^{\\log_{72} 155,424} \\approx n^{2.795147}$.\n\\end{itemize}\n\nThe fastest is the one that multiplies $70 \\times 70$ matrices, but all of them\nare faster then the Strassen's algorithm.\n\\end{framed}\n\n\\item[4.2{-}6]{How quickly can you multiply a $k n \\times n$ matrix by an\n$n \\times k n$ matrix, using Strassen's algorithm as a subroutine? Answer the\nsame question with the order of the input matrices reversed.}\n\n\\begin{framed}\nLet $A$ and $B$ be $kn \\times n$ and $n \\times k n$ matrices, respectivelly. We\ncan compute $A \\cdot B$ as follows:\n\\begin{enumerate}\n\\item Partition $A$ and $B$ into $k$ submatrices $A_1, \\dots, A_k$ and $B_1,\n\\dots, B_k$, each one of size $n \\times n$.\n\\item Compute the desired submatrices $C_{ij}$ of the result matrix $C$ by the\nproduct of $A_i \\cdot B_j$. Use the Strassen's algorithm to compute each of\nthose products.\n\\end{enumerate}\n\nSince each of the $k^2$ products takes $\\Theta(n^{\\lg 7})$, this algorithm\nruns in $\\Theta(k^2 n^{\\lg 7})$.\n\nWe can compute $B \\cdot A$ as follows:\n\\begin{enumerate}\n\\item Partition $A$ and $B$ into $k$ submatrices $A_1, \\dots, A_k$ and $B_1,\n\\dots, B_k$, each one of size $n \\times n$.\n\\item Compute the the result matrix $C = \\sum_{i = 1}^{k} A_i \\cdot B_i$.\nUse the Strassen's algorithm to compute each of those products.\n\\end{enumerate}\n\nSince each of the $k$ products takes $\\Theta(n^{\\lg 7})$ and the $k - 1$\nsummations takes $\\Theta((k - 1) {n^2}/k) = O(n^2)$, this algorithm runs in\n$\\Theta(k n^{\\lg 7}) + O(n^2) = \\Theta(k n^{\\lg 7})$.\n\n\\end{framed}\n\n\\item[4.2{-}7]{Show how to multiply the complex numbers $a + b i$ and $c + di$\nusing only three multiplications of real numbers. The algorithm should take\n$a, b, c$, and $d$ as input and produce the real component $ac - bd$ and the\nimaginary component $ad + bc$ separately.}\n\n\\begin{framed}\nThe pseudocode is stated below.\\\\\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Complex-Product}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{a, b, c, d}}{%\n\\nl $x = a \\cdot c$\\;\n\\nl $y = b \\cdot d$\\;\n\\nl $real \\mhyphen part = x - y$\\;\n\\nl $imaginary \\mhyphen part = (a + b) \\cdot (c + d) - x - y$\\;\n\\nl \\Return{$real \\mhyphen part, imaginary \\mhyphen part$} }\n\\end{algorithm}\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{The substitution method for solving recurrences}\n\n\\begin{enumerate}\n\n\\item[4.3{-}1]{Show that the solution of $T(n) = T(n - 1) + n$ is $O(n^2)$.}\n\n\\begin{framed}\nOur guess is\n\\[\nT(n) \\le cn^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$ and $n_0$ are positive constants. Substituting into the recurrence\nyields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le c (n - 1)^2 + n\\\\\n     &= cn^2 - 2cn + c + n & \\text{($c = 1$)}\\\\\n     &= n^2 - 2n + n + 1\\\\\n     &= n^2 - n + 1\\\\\n     &\\le n^2,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $n_0 \\ge 1$.\n\n\\end{framed}\n\n\\item[4.3{-}2]{Show that the solution of $T(n) = T(\\ceil{n/2}) + 1$ is\n$O(\\lg n)$.}\n\n\\begin{framed}\nOur guess is\n\\[\nT(n) \\le c \\lg n - d \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le c \\lg(\\ceil{n/2}) - d + 1\\\\\n     &\\le c \\lg n - d + 1\\\\\n     &\\le c \\lg n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 1$.\n\\end{framed}\n\n\\item[4.3{-}3]{We saw that the solution of $T(n) = 2T(\\floor{n/2}) + n$ is\n$O(n \\lg n)$. Show that the solution of this recurrence is also\n$\\Omega(n \\lg n)$. Conclude that the solution is $\\Theta(n \\lg n)$.}\n\n\\begin{framed}\nOur guess is\n\\[\nT(n) \\ge c n \\lg n \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$ and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\ge 2(c \\floor{n/2} \\lg\\floor{n/2}) + n\\\\\n     &\\ge 2 c (n/4) \\lg(n/4) + n\\\\\n     &=   c (n/2) \\lg n - c (n/2) \\lg 4 + n\\\\\n     &=   c (n/2) \\lg n - c n + n\\\\\n     &\\ge c n \\lg n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c \\le 1$.\n\nThus, we have\n\\[\nc_1 n \\lg n \\le T(n) \\le c_2 n \\lg n,\n\\]\nwith $c_1 \\le 1$ and $c_2 \\ge 1$, which implies\n\\[\nT(n) = \\Theta(n \\lg n).\n\\]\n\\end{framed}\n\n\\newpage\n\n\\item[4.3{-}4]{Show that by making a different inductive hypothesis, we can\novercome the difficulty with the boundary condition $T(1) = 1$ for recurrence\n(4.19) without adjusting the boundary conditions for the inductive proof.}\n\n\\begin{framed}\nOur new guess is\n\\[\nT(n) \\le c n \\lg n + n \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 2(c \\floor{n/2} \\lg \\floor{n/2} + \\floor{n/2}) + n\\\\\n     &\\le cn \\lg (n/2) + 2(n/2) + n\\\\\n     &= cn \\lg n - cn \\lg 2 n + 2n\\\\\n     &= cn \\lg n - cn + 2n\\\\\n     &\\le c n \\lg n + n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c \\ge 1$.\n\nNow on the boundary condition, we have\n\\[\nT(1) \\le c (n \\lg n) + n = c 1 \\lg 1 + 1 = 0 + 1 = 1.\n\\]\n\\end{framed}\n\n\\item[4.3{-}5]{Show that $\\Theta(n \\lg n)$ is the solution to the ``exact''\nrecurrence (4.3) for merge sort.}\n\n\\begin{framed}\nFirst, we verify if (4.3) is $O(n \\lg n)$. Our guess is\n\\[\nT(n) \\le c (n - d) \\lg (n - d) \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le c (\\ceil{n/2} - d) \\lg (\\ceil{n/2} - d) + c (\\floor{n/2} - d) \\lg (\\floor{n/2} - d) + en\\\\\n     &\\le c (n/2 + 1 - d) \\lg (n/2 + 1 - d) + c (n/2 - d) \\lg (n/2 - d) + en & \\text{($d \\ge 2$)}\\\\\n     &\\le c\\left(\\frac{n - d}{2}\\right) \\lg \\left(\\frac{n - d}{2}\\right)\n     + c\\left(\\frac{n - d}{2}\\right) \\lg\\left(\\frac{n - d}{2}\\right) + en\\\\\n     &= c (n - d) \\lg \\left(\\frac{n - d}{2}\\right) + en\\\\\n     &= c (n - d) \\lg (n - d) - c (n - d) + en\\\\\n     &= c (n - d) \\lg (n - d) - cn + en + cd\\\\\n     &\\le c (n - d) \\lg (n - d),\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c > e$ and $n_0 \\ge cd$.\n\nThen we verify if (4.3) is $\\Omega(n \\lg n)$. Our guess is\n\\[\nT(n) \\ge c (n + d) \\lg (n + d) \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\ge c (\\ceil{n/2} + d) \\lg (\\ceil{n/2} + d) + c (\\floor{n/2} + d) \\lg (\\floor{n/2} + d) + en\\\\\n     &\\ge c (n/2 + d) \\lg (n/2 + d) + c (n/2 - 1 + d) \\lg (n/2 - 1 + d) + en & \\text{($d \\ge 2$)}\\\\\n     &\\ge c\\left(\\frac{n + d}{2}\\right) \\lg \\left(\\frac{n + d}{2}\\right)\n     + c\\left(\\frac{n + d}{2}\\right) \\lg\\left(\\frac{n + d}{2}\\right) + en\\\\\n     &= c (n + d) \\lg \\left(\\frac{n + d}{2}\\right) + en\\\\\n     &= c (n + d) \\lg (n + d) - c (n + d) + en\\\\\n     &= c (n + d) \\lg (n + d) - cn + en - cd\\\\\n     &\\ge c (n + d) \\lg (n + d),\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $e > c$ and $n_0 \\ge cd$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.3{-}6]{Show that the solution to $T(n) = 2T(\\floor{n/2} + 17) + n$ is\n$O(n \\lg n)$.}\n\n\\begin{framed}\nOur guess is\n\\[\nT(n) \\le c (n - d) \\lg (n - d) \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 2 c (\\floor{n/2} - d + 17) \\lg (\\floor{n/2} - d + 17) + n\\\\\n     &\\le 2 c (n/2 - d + 17) \\lg (n/2 - d + 17) + n & \\text{($d \\ge 34$)}\\\\\n     &\\le 2 c\\left(\\frac{n - d}{2}\\right) \\lg \\left(\\frac{n - d}{2}\\right) + n\\\\\n     &= c (n - d) \\lg \\left(\\frac{n - d}{2}\\right) + n\\\\\n     &= c (n - d) \\lg (n - d) - c (n - d) + n\\\\\n     &= c (n - d) \\lg (n - d) - cn + n + cd\\\\\n     &\\le c (n - d) \\lg (n - d),\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c \\ge 2$ and $n_0 \\ge cd$.\n\\end{framed}\n\n\\item[4.3{-}7]{Using the master method in Section 4.5 you can show that the\nsolution to the recurrence $T(n) = 4T(n/3) + n$ is\n$T(n) = \\Theta(n^{\\log_3 4})$. Show that a substitution proof with the\nassumption $T(n) \\le c n^{\\log_3 4}$ fails. Then show how to subtract off a\nlower-order term to make a substitution proof work.}\n\n\\begin{framed}\nThe initial guess is\n\\[\nT(n) \\le c n^{\\log_3 4} \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 4 c \\left(\\frac{n}{3}\\right)^{\\log_3 4} + n\\\\\n     &= 4 c \\frac{n^{\\log_3 4}}{4} + n\\\\\n     &= c n^{\\log_3 4} + n\n\\end{aligned}\n\\end{equation*}\nwhich does not imply $T(n) \\le c n^{\\log_3 4}$ for any choice of $c$.\n\nOur new guess is\n\\[\nT(n) \\le c n^{\\log_3 4} - dn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 4 \\left(c \\left(\\frac{n}{3}\\right)^{\\log_3 4} - d \\frac{n}{3}\\right) + n\\\\\n     &= 4 c \\frac{n^{\\log_3 4}}{4} - 4d \\frac{n}{3} + n\\\\\n     &\\le c n^{\\log_3 4},\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 3/4$.\n\\end{framed}\n\n\\item[4.3{-}8]{Using the master method in Section 4.5, you can show that the\nsolution to the recurrence $T(n) = 4T(n/2) + n$ is $T(n) = \\Theta(n^2)$. Show\nthat a substitution proof with the assumption $T(n) \\le cn^2$ fails. Then show\nhow to subtract off a lower-order term to make a substitution proof work.}\n\n\\begin{framed}\nThe initial guess is\n\\[\nT(n) \\le c n^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 4 c \\left(\\frac{n}{2}\\right)^2 + n\\\\\n     &= c n^2 + n\n\\end{aligned}\n\\end{equation*}\nwhich does not imply $T(n) \\le c n^2$ for any choice of $c$.\n\nOur new guess is\n\\[\nT(n) \\le c n^2 - dn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 4 \\left(c \\left(\\frac{n}{2}\\right)^2 - d\\frac{n}{2} \\right) + n\\\\\n     &= c n^2 - 2dn + n\\\\\n     &\\le c n^2,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 1/2$.\n\\end{framed}\n\n\\item[4.3{-}9]{Solve the recurrence $T(n) = 3T(\\sqrt{n}) + \\log n$ by making\na change of variables.  Your solution should be asymptotically tight. Do not\nworry about whether values are integral.}\n\n\\begin{framed}\nRenaming $m = \\log n$ yields\n\\[\nT(10^m) = 3T(10^{m/2}) + m.\n\\]\n\nNow renaming $S(m) = T(2^m)$ yields\n\\[\nS(m) = 3S(m/2) + m.\n\\]\n\nWith the master method, we have $f(n) = m = \\log n$ and\n$n^{\\log_b a} = n^{\\lg 3} \\approx n^{1.585}$. Using the first case, we have\n\\[\nf(n) = \\log n = O(n^{\\lg 3 - \\epsilon}), \\; \\text{($\\epsilon = 0.5$)}\n\\]\nwhich implies\n\\[\nS(m) = \\Theta(m^{\\lg 3}).\n\\]\n\nWe can double-check if $S(m) = O(m^{\\lg 3})$ using the substition method. Our\nguess is\n\\[\nS(m) \\le c m^{\\lg 3} - dm \\; \\Forall m \\ge m_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\le 3 \\left(c \\left(\\frac{m}{2}\\right)^{\\lg 3} - d \\frac{m}{2}\\right) + m\\\\\n     &= 3 c \\frac{m^{\\lg 3}}{3} - 3d\\frac{m}{2} + m\\\\\n     &\\le c m^{\\lg 3} + dm\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 2/3$.\n\nNow verifying if $S(m) = \\Omega(m^{\\lg 3})$ with the substitution method. Our\nguess is\n\\[\nS(m) \\ge c m^{\\lg 3} \\; \\Forall m \\ge m_0,\n\\]\nwhere $c$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\nT(n) &\\ge 3 c \\left(\\frac{m}{2}\\right)^{\\lg 3} + m\\\\\n     &= 3 c \\frac{m^{\\lg 3}}{3} + m\\\\\n     &\\ge c m^{\\lg 3}.\n\\end{aligned}\n\\end{equation*}\n\nFinally, we have\n\\[\nT(n) = T(10^m) = S(m) = \\Theta(m^{\\lg 3}) = \\Theta(\\log^{\\lg 3} n).\n\\]\n\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{The recursion-tree method for solving recurrences}\n\n\\begin{enumerate}\n\n\\item[4.4{-}1]{Use a recursion tree to determine a good asymptotic upper bound\non the recurrence $T(n) = 3T(\\floor{n/2}) + n$. Use the substitution method to\nverify your answer.}\n\n\\begin{framed}\nSince floors/ceiling usually do not matter, we will draw a recursion tree for\nthe recurrence $T(n) = 3T(n/2) + n$.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{images/4_4_1_1.pdf}\n\\end{center}\n\nThe number of nodes at depth $i$ is $3^i$. Since subproblem size reduce by\na factor of 2, each node at depth $i$, for $i = 0, 1, 2, \\dots, \\lg n - 1$,\nhas a cost of $c (n/2^i)$. Thus, the total cost over all nodes at depth\n$i$, for $i = 0, 1, 2, \\dots, \\lg n - 1$, is $(3/2)^i cn$. The bottom level,\nat deph $\\lg n$, has $3^{\\lg n} = n^{\\lg 3}$ nodes, each contributing cost\n$T(1)$, for a total cost of $n^{\\lg 3} T(1) = \\Theta(n^{\\lg 3})$.\n\nThe cost of the entire tree is\n\\begin{equation*}\n\\begin{aligned}\nT(n) &= cn + \\frac{3}{2} cn + \\left(\\frac{3}{2}\\right)^2 cn + \\dots\n           + \\left(\\frac{3}{2}\\right)^{\\lg n - 1} cn + \\Theta\\left({n^{\\lg 3}}\\right)\\\\\n     &= \\sum_{i = 0}^{\\lg n - 1} \\left(\\frac{3}{2}\\right)^i cn + \\Theta(n^{\\lg 3})\\\\\n     &= cn \\frac{\\left(\\frac{3}{2}\\right)^{\\lg n} - 1}{\\frac{3}{2} - 1} + \\Theta(n^{\\lg 3})\\\\\n     &= 2cn \\left(\\left(\\frac{3}{2}\\right)^{\\lg n} - 1\\right) + \\Theta(n^{\\lg 3})\\\\\n     &= 2cn \\frac{3^{\\lg n}}{2^{\\lg n}} - 2cn + \\Theta(n^{\\lg 3})\\\\\n     &= 2cn \\frac{n^{\\lg 3}}{n} - 2cn + \\Theta(n^{\\lg 3})\\\\\n     &= 2cn^{\\lg 3} - 2cn + \\Theta(n^{\\lg 3})\\\\\n     &= O(n^{\\lg 3}).\n\\end{aligned}\n\\end{equation*}\n\nOur guess is\n\\[\nT(n) \\le c n^{\\lg 3} - dn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le 3 \\left(c {\\Bigl\\lfloor\\frac{n}{2}\\Bigl\\rfloor}^{\\lg 3} - d {\\Bigl\\lfloor\\frac{n}{2}\\Bigl\\rfloor}\\right) + n\\\\\n       &\\le \\frac{3c}{3} n^{\\lg 3} - \\frac{3d}{2}n + n\\\\\n       &= c n^{\\lg 3} - dn - \\frac{d}{2}n + n\\\\\n       &\\le c n^{\\lg 3} - dn,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 2$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}2]{Use a recursion tree to determine a good asymptotic upper bound\non the recurrence $T(n) = T(n/2) + n^2$. Use the substitution method to verify\nyour answer.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = T(n/2) + n^2$.\n\n\\begin{center}\n\\includegraphics[width=0.3\\textwidth]{images/4_4_2_1.pdf}\n\\end{center}\n\nThe tree has $\\lg n$ levels and the cost at depth $i$ is\n$c(n/2^i)^2 = (1/4)^i cn^2$.\n\nThe cost of the entire tree is\n\\begin{equation*}\n\\begin{aligned}\nT(n) &= \\sum_{i = 0}^{\\lg n} \\left(\\frac{1}{4}\\right)^i cn^2\\\\\n     &< \\sum_{i = 0}^{\\infty} \\left(\\frac{1}{4}\\right)^i cn^2\\\\\n     &= \\frac{1}{1 - (1/4)} cn^2\\\\\n     &= \\frac{4}{3} cn^2\\\\\n     &= O(n^2).\n\\end{aligned}\n\\end{equation*}\n\nOur guess is\n\\[\nT(n) \\le d n^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence and using the same constant $c > 0$ as before yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le d \\left(\\frac{n}{2}\\right)^2 + c n^2\\\\\n       &= \\frac{1}{4} dn^2 + cn^2\\\\\n       &\\le dn^2,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge (4/3)c$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}3]{Use a recursion tree to determine a good asymptotic upper bound\non the recurrence $T(n) = 4T(n/2 + 2) + n$. Use the substitution method to\nverify your answer.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = 4T(n/2 + 2) + n$.\n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{images/4_4_3_1.pdf}\n\\end{center}\n\nThe number of nodes at depth $i$ is $4^i$. Since subproblem size reduce by\na factor of 2 and increment 2, each node at depth $i$, for\n$i = 0, 1, 2, \\dots, \\lg n - 1$, has a cost of $c (n/2^i + 2)$. Thus, the total\ncost over all nodes at depth $i$, for $i = 0, 1, 2, \\dots, \\lg n - 1$, is\n$4^i c (n/2^i + 2) = 2^i cn + 2^{2i + 1}$. The bottom level, at deph $\\lg n$,\nhas $4^{\\lg n} = n^{\\lg 4}$ nodes, each contributing cost $T(1)$, for a total\ncost of $n^{\\lg 4} T(1) = \\Theta(n^{\\lg 4})$.\n\nThe cost of the entire tree is\n\\begin{equation*}\n\\begin{aligned}\nT(n) &= \\sum_{i = 0}^{\\lg n - 1} \\left(4^i c \\left(\\frac{n}{2^i} + 2\\right)\\right) +\n        \\Theta(n^2)\\\\\n     &= \\sum_{i = 0}^{\\lg n - 1} \\left(4^i c \\cdot \\frac{n}{2^i}\\right) +\n        \\sum_{i = 0}^{\\lg n - 1} (4^i c \\cdot 2) + \\Theta(n^2)\\\\\n     &= cn \\sum_{i = 0}^{\\lg n - 1} (2^i) + 2c \\sum_{i = 0}^{\\lg n - 1} (4^i) + \\Theta(n^2)\\\\\n     &= cn \\frac{2^{\\lg n} - 1}{2 - 1} + 2c \\frac{4^{\\lg n} - 1}{4 - 1} + \\Theta(n^2)\\\\\n     &= cn (n - 1) + \\frac{2c}{3} (n^2 - 1) + \\Theta(n^2)\\\\\n     &= cn^2 - cn + \\frac{2cn^2}{3} - \\frac{2c}{3} + \\Theta(n^2)\\\\\n     &= O(n^2).\n\\end{aligned}\n\\end{equation*}\n\nOur guess is\n\\[\nT(n) \\le c n^2 - dn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le 4 \\left(c \\left(\\frac{n}{2} + 2\\right)^2 - d\\left(\\frac{n}{2} + 2\\right)\\right) + n\\\\\n       &\\le 4 \\left(c \\frac{n^2}{4} + 2cn + 4c - \\frac{dn}{2} - 2d\\right) + n\\\\\n       &= c n^2 + 8cn + 16c - 2dn - 8d + n\\\\\n       &= c n^2 - dn - (d - 8c - 1)n - (d - 2c)8\\\\\n       &\\le c n^2 - dn,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d - 8c - 1 \\ge 0$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}4]{Use a recursion tree to determine a good asymptotic upper bound\non the recurrence $T(n) = 2T(n - 1) + 1$. Use the substitution method to verify\nyour answer.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = 2T(n - 1) + 1$.\n\n\\begin{center}\n\\includegraphics[width=0.6\\textwidth]{images/4_4_4_1.pdf}\n\\end{center}\n\nThe tree has $n$ levels and $2^i$ nodes at each level. Since each node costs\n$1$, the cost at depth $i$ is $2^i$. The bottom level, at deph $n$,\nhas $2^n$ nodes, each contributing cost $1$, for a total\ncost of $2^n = \\Theta(2^n)$.\n\nThe cost of the entire tree is\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &= \\sum_{i = 0}^{n - 1} (2^i) + \\Theta(2^n)\\\\\n       &= \\frac{2^n - 1}{2 - 1} + \\Theta(2^n)\\\\\n       &= 2^n - 1 + \\Theta(2^n)\\\\\n       &= O(2^n).\n\\end{aligned}\n\\end{equation*}\n\nOur guess is\n\\[\nT(n) \\le c 2^n - d \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le 2 (c 2^{n - 1} - d) + 1\\\\\n       &= c2^n - 2d + 1\\\\\n       &= c2^n - d - d + 1\\\\\n       &\\le c 2^n - d,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 1$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}5]{Use a recursion tree to determine a good asymptotic upper bound\non the recurrence $T(n) = T(n - 1) + T(n/2) + n$. Use the substitution method to\nverify your answer.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = T(n - 1) + T(n/2) + n$.\n\n\\begin{center}\n\\includegraphics[width=0.85\\textwidth]{images/4_4_5_1.pdf}\n\\end{center}\n\nWe start obtaining a lower bound. The cost of the initial levels (before level\n$\\lg n$) of the tree are\n\\[\ncn \\rightarrow (3/2)^1 cn - c \\rightarrow (3/2)^2 cn - (7/2) c \\rightarrow (3/2)^3 cn - (37/4) c.\n\\]\n\nThus, the cost of the tree from the root to level $\\lg n$ is at most\n\\[\n  \\sum_{i = 0}^{\\lg n} \\left(\\frac{3}{2}\\right)^i cn\n  = cn \\frac{\\left(\\frac{3}{2}\\right)^{\\lg n + 1} - 1}{\\frac{3}{2} - 1}\n  = 2cn \\frac{3}{2} \\left(\\frac{3}{2}\\right)^{\\lg n} - 2cn\n  = 3cn \\frac{n^{\\lg 3}}{n} - 2cn\n  = 3cn^{\\lg 3} - 2cn\n  = O(n^{\\lg 3}).\n\\]\n\nThe cost of the longest simple path from the root to a leaf is\n\\[\n  \\sum_{i = 0}^{n} c(n - i) = c \\sum_{i = 0}^{n} i = c \\frac{n (n + 1)}{2}\n                            = c \\frac{n^2}{2} + \\frac{c}{2} = O(n^2).\n\\]\n\nThus, our guess for a lower bound for $T(n)$ is\n\\[\nT(n) \\ge cn^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\ge c (n - 1)^2 + c\\left(\\frac{n}{2}\\right)^2 + n\\\\\n       &=   cn^2 - 2cn + 1 + \\frac{cn^2}{4} + n\\\\\n       &=   \\frac{5}{4} cn^2 -2cn + n + 1\\\\\n       &\\ge cn^2 -2cn + n + 1\\\\\n       &\\ge cn^2,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c \\ge 1$ and $n_0 \\ge 1$. Thus, we have\n$T(n) = \\Omega(n^2)$.\n\nConsider now the recurrence\n\\[\nS(n) = 2T(n - 1) + n,\n\\]\nwhich is more costly than $T(n)$. We can easily prove that $S(n) = O(2^n)$. Our\nguess for an upper bound of $S(n)$ is\n\\[\nS(n) \\le c 2^n - dn \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  S(n) &\\le 2 (c 2^{n - 1} - d(n - 1)) + n\\\\\n       &=   c2^n - 2dn + 2d + n\\\\\n       &=   c2^n - dn - n(d - 1) + 2d\\\\\n       &\\le c 2^n - dn,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d \\ge 2$ and $n_0 \\ge 3$. Thus, we have\n$T(n) = O(S(n)) = O(2^n)$.\n\nWe can obtain a more tight upper bound without using the recursion tree.\nLet $R(n) = T(n/2) + n$. We have\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &= T(n - 1) + R(n)\\\\\n       &= T(n - 2) + R(n - 1) + R(n)\\\\\n       &= R(1) + R(2) + \\dots + R(n - 1) + R(n)\\\\\n       &\\le n \\cdot R(n)\\\\\n       &= n \\cdot T(n/2) + n^2,\n\\end{aligned}\n\\end{equation*}\nwhich can be solved using the master method. We have $f(n) = n^2$ and\n$n^{\\log_b a} = n^{\\lg n}$. Using the first case, we have\n\\[\nf(n) = n^2 = O(n^{\\lg n - \\epsilon}), \\; \\text{($\\epsilon = 1$)}\n\\]\nwhich implies\n\\[\nT(n) = O(n^{\\lg n}).\n\\]\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}6]{Argue that the solution to the recurrence\n$T(n) = T(n/3) + T(2n/3) + cn$, where $c$ is a constant, is $\\Omega(n \\lg n)$ by\nappealing to a recursion tree.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = T(n/3) + T(2n/3) + cn$.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{images/4_4_6_1.pdf}\n\\end{center}\n\nThe tree is complete until level $\\log_3 n$. The cost of the tree from the root\nto level $\\log_3 n$ is\n\\[\n  \\sum_{i = 0}^{\\log_3 n} cn = cn \\log_3 n,\n\\]\nwhich is $\\Omega(n \\lg n)$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}7]{Draw the recursion tree for $T(n) = 4T(\\floor{n/2}) + cn$, where\n$c$ is a constant, and provide a tight asymptotic bound on its solution. Verify\nyour bound by the substitution method.}\n\n\\begin{framed}\nSince floors/ceiling usually do not matter, we will draw a recursion tree for\nthe recurrence $T(n) = 4T(n/2) + cn$.\n\n\\begin{center}\n\\includegraphics[width=0.9\\textwidth]{images/4_4_7_1.pdf}\n\\end{center}\n\nThe number of nodes at depth $i$ is $4^i$. Since subproblem size reduce by\na factor of 2, each node at depth $i$, for $i = 0, 1, 2, \\dots, \\lg n - 1$,\nhas a cost of $c (n/2^i)$. Thus, the total cost over all nodes at depth\n$i$, for $i = 0, 1, 2, \\dots, \\lg n - 1$, is $(4/2)^i cn = 2^i cn$. The bottom\nlevel has $4^{\\lg n} = n^2$ nodes, each contributing cost $T(1)$, for a total\ncost of $n^2 T(1) = \\Theta(n^2)$.\n\nThe cost of the entire tree is\n\\[\n\\sum_{i = 0}^{\\lg n - 1} (2^i cn) + \\Theta(n^2)\n= cn \\frac{2^{\\lg n} - 1}{2 - 1} + \\Theta(n^2)\n= cn (n - 1) + \\Theta(n^2)\n= cn^2 - cn + \\Theta(n^2)\n= \\Theta(n^2).\n\\]\n\nLets verify with the substitution method. Our guess for an upper bound is\n\\[\nT(n) \\le dn^2 - en \\; \\Forall n \\ge n_0,\n\\]\nwhere $d$, $e$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le 4\\left(d \\Bigl\\lfloor\\frac{n}{2}\\Bigl\\rfloor^2 -e \\frac{n}{2}\\right) + cn\\\\\n       &\\le 4\\left(d \\left(\\frac{n}{2}\\right)^2 -e \\frac{n}{2}\\right) + cn\\\\\n       &=   4\\left(d \\frac{n^2}{4} -e \\frac{n}{2}\\right) + cn\\\\\n       &=   d n^2 -2en + cn\\\\\n       &=   d n^2 - en - en + cn\\\\\n       &\\le   d n^2 - en,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $e \\ge c$.\n\nOur guess for a lower bound is\n\\[\nT(n) \\ge dn^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\ge 4d \\Bigl\\lfloor\\frac{n}{2}\\Bigl\\rfloor^2 + cn\\\\\n       &\\ge 4d \\left(\\frac{n}{2} - 1\\right)^2 + cn\\\\\n       &=   4d \\left( \\frac{n^2}{4} - n + 1 \\right) + cn\\\\\n       &=   d n^2 - 4dn + 4d + cn\\\\\n       &=   d n^2 - (4d - c)n + 4d\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $4d - c \\ge 4$ and $n_0 \\ge d$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}8]{Use a recursion tree to give an asymptotically tight solution to\nthe recurrence $T(n) = T(n - a) + T(a) + cn$, where $a \\ge 1$ and $c > 0$ are\nconstants.}\n\n\\begin{framed}\nFigure below ilustrates the recursion tree $T(n) = T(n - a) + T(a) + cn$.\n\n\\begin{center}\n\\includegraphics[width=0.7\\textwidth]{images/4_4_8_1.pdf}\n\\end{center}\n\nThe height of the tree is $n/a$. Each level $i$, for $i = 1, 2, \\dots, (n/a)$,\nhas two nodes, one that costs $c(n - ia)$ and another that costs $T(a) = ca$.\nThus, the cost over the nodes at depth $i$, for $i = 1, 2, \\dots, (n/a)$, is\n$c(n - a) + ca$. The root level, at deph 0, has a single node that costs $cn$.\n\nThe cost of the entire tree is\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &= cn + \\sum_{i = 1}^{n/a} (c (n - ia) + ca)\\\\\n       &= cn + \\sum_{i = 1}^{n/a} cn - \\sum_{i = 1}^{n/a} cia + \\sum_{i = 1}^{n/a} ca\\\\\n       &= cn + c\\frac{n^2}{a} - \\frac{cn (a + n)}{2a} + cn\\\\\n       &= c \\frac{n^2}{a} - c\\frac{n^2}{2a} - c \\frac{n}{2} + 2cn\\\\\n       &= c \\frac{n^2}{2a} + \\frac{3}{2} cn\\\\\n       &= \\Theta(n^2).\n\\end{aligned}\n\\end{equation*}\n\nLets verify with the substitution method. Our guess for an upper bound is\n\\[\nT(n) \\le cn^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$ and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le c (n^2 - 2an + a^2) + ca + cn\\\\\n       &=   cn^2 - c (2an - a - n - a^2)\\\\\n       &\\le cn^2,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $n_0 \\ge a$.\n\nOur guess for a lower bound is\n\\[\n  T(n) \\ge \\frac{c}{2a} n^2 \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\ge \\frac{c}{2a} (n - a)^2 + ca + cn\\\\\n       &=   \\frac{c}{2a} (n^2 - 2an + a^2) + ca + cn\\\\\n       &=   \\frac{c}{2a} n^2 - cn + \\frac{1}{2} ca + ca + cn\\\\\n       &=   \\frac{c}{2a} n^2 + \\frac{3}{2} ca\\\\\n       &\\ge \\frac{c}{2a} n^2.\n\\end{aligned}\n\\end{equation*}\n\\end{framed}\n\n\\newpage\n\n\\item[4.4{-}9]{Use a recursion tree to give an asymptotically tight solution to\nthe recurrence $T(n) = T(\\alpha n) + T((1 - \\alpha) n) + cn$, where $\\alpha$ is\na constant in the range $0 < \\alpha < 1$ and $c > 0$ is also a constant.}\n\n\\begin{framed}\nLet $\\alpha \\ge 1 - \\alpha$. Figure below ilustrates the recursion tree\n$T(n) = T(\\alpha n) + T((1 - \\alpha n) n) + cn$.\n\n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{images/4_4_9_1.pdf}\n\\end{center}\n\nIf it were a complete tree, all the $\\log_{1 - \\alpha} n$ levels would cost $cn$\nand the entire tree $cn \\log_{1 - \\alpha} n$. Thus,\n$T(n) = O(n \\log_{1 - \\alpha} n) = O(n \\lg n)$. The tree is complete until level\n$\\log_{1/(1 - \\alpha)} n$. The cost of the tree from the root to level\n$\\log_{1/(1 - \\alpha)} n$ is\n\\[\n  \\sum_{i = 0}^{\\log_{1/(1 - \\alpha)} n} cn\n  = \\left(\\sum_{i = 1}^{\\log_{1/(1 - \\alpha)} n} cn\\right) + cn\n  = cn (\\log_{1/(1 - \\alpha)} n) + cn,\n\\]\nwhich is $\\Omega(n \\log_{1/(1 - \\alpha)} n)$ = $\\Omega(n \\lg n)$.\n\nLets verify with the substitution method. Our guess for an upper bound is\n\\[\nT(n) \\le d n \\lg n \\; \\Forall n \\ge n_0,\n\\]\nwhere $d$ and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le d \\alpha n \\lg (\\alpha n) + d (1 - \\alpha) n \\lg ((1 - \\alpha) n) + dn\\\\\n       &=   d \\alpha n \\lg \\alpha + d \\alpha n \\lg n + d (1 - \\alpha) n \\lg (1 - \\alpha) + d (1 - \\alpha) n \\lg n + cn\\\\\n       &=   d \\alpha n \\lg \\alpha + d \\alpha n \\lg n + d (1 - \\alpha) n \\lg (1 - \\alpha) + d n \\lg n - d \\alpha n \\lg n + cn\\\\\n       &=   d n \\lg n + dn (\\alpha \\lg \\alpha + (1 - \\alpha) \\lg (1 - \\alpha)) + cn\\\\\n       &\\le d n \\lg n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d(\\alpha \\lg \\alpha + (1 - \\alpha) \\lg (1 - \\alpha)) + c \\le 0$.\n\nOur guess for a lower bound is\n\\[\n  T(n) \\ge d n \\lg n \\; \\Forall n \\ge n_0,\n\\]\nwhere $d$, and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\ge d \\alpha n \\lg (\\alpha n) + d (1 - \\alpha) n \\lg ((1 - \\alpha) n) + dn\\\\\n       &=   d \\alpha n \\lg \\alpha + d \\alpha n \\lg n + d (1 - \\alpha) n \\lg (1 - \\alpha) + d (1 - \\alpha) n \\lg n + cn\\\\\n       &=   d \\alpha n \\lg \\alpha + d \\alpha n \\lg n + d (1 - \\alpha) n \\lg (1 - \\alpha) + d n \\lg n - d \\alpha n \\lg n + cn\\\\\n       &=   d n \\lg n + dn (\\alpha \\lg \\alpha + (1 - \\alpha) \\lg (1 - \\alpha)) + cn\\\\\n       &\\ge d n \\lg n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $d(\\alpha \\lg \\alpha + (1 - \\alpha) \\lg (1 - \\alpha)) + c \\ge 0$.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{The master method for solving recurrences}\n\n\\begin{enumerate}\n\n\\item[4.5{-}1]{Use the master method to give tight asymptotic bounds for the\nfollowing recurrences.\n\n\\begin{enumerate}\n  \\item[a.] $T(n) = 2T(n/4) + 1$.\n  \\item[b.] $T(n) = 2T(n/4) + \\sqrt{n}$.\n  \\item[c.] $T(n) = 2T(n/4) + n$.\n  \\item[d.] $T(n) = 2T(n/4) + n^2$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n  \\item[(a)] Case 1 applies. $T(n) = \\Theta(n^{\\log_4{2}}) = \\Theta(\\sqrt{n})$.\n  \\item[(b)] Case 2 applies. $T(n) = \\Theta(n^{\\log_4{2}} \\lg n) = \\Theta(\\sqrt{n} \\lg n)$.\n  \\item[(c)] Case 3 applies. $T(n) = \\Theta(n)$.\n  \\item[(d)] Case 3 applies. $T(n) = \\Theta(n^2)$.\n\\end{enumerate}\n\\end{framed}\n\n\\item[4.5{-}2]{Professor Caesar wishes to develop a matrix-multiplication\nalgorithm that is asymptotically faster than Strassen's algorithm. His algorithm\nwill use the divide-and-conquer method, dividing each matrix into pieces of\nsize $n/4 \\times n/4$, and the divide and combine steps together will take\n$\\Theta(n^2)$ time. He needs to determine how many subproblems his algorithm has\nto create in order to beat Strassen's algorithm. If his algorithm creates $a$\nsubproblems, then the recurrence for the running time $T(n)$ becomes\n$T(n) = a T(n/4) + \\Theta(n^2)$. What is the largest integer value of $a$ for\nwhich Professor Caesar's algorithm would be asymptotically faster than\nStrassen's algorithm?}\n\n\\begin{framed}\nStrassen's algorithm costs $\\Theta(n^{\\lg 7})$. The cost of $T(n)$ is stated\nbelow.\n\\begin{itemize}\n  \\item If $a < 16$, Case 3 applies. $T(n) = \\Theta(n^2) = o(n^{\\lg 7})$.\n  \\item If $a = 16$, Case 2 applies. $T(n) = \\Theta(n^2 \\lg n) = o(n^{\\lg 7})$.\n  \\item If $a > 16$, Case 1 applies. $T(n) = \\Theta(n^{\\log_4{a}}) = o(n^{\\lg 7})$ when $a < 49$.\n\\end{itemize}\nThus, the largest integer value of $a$ is 48.\n\\end{framed}\n\n\\item[4.5{-}3]{Use the master method to show that the solution to the\nbinary-search recurrence $T(n) = T(n/2) + \\Theta(1)$ is $T(n) = \\Theta(\\lg n)$.\n(See Exercise 2.3-5 for a description of binary search.)}\n\n\\begin{framed}\nWe have\n\\[\nn^{\\log_b a} = n^{\\lg 1} = \\Theta(1) = f(n).\n\\]\nThus, Case 2 applies. $T(n) = \\Theta(\\lg n)$.\n\\end{framed}\n\n\\newpage\n\n\\item[4.5{-}4]{Can the master method be applied to the recurrence\n$T(n) = 4 T(n/2) + n^2 \\lg n$? Why or why not? Give an asymptotic upper bound\nfor this recurrence.}\n\n\\begin{framed}\nWe have\n\\[\n  f(n) = n^2 \\lg n,\n\\]\nand\n\\[\nn^{\\log_b a} = n^{\\log_2 4} = \\Theta(n^2),\n\\]\nwhich is larger than $f(n)$, but not polynomially larger. Thus, we cannot use the\nmaster method to solve this recurrence.\n\nWe can use a recursion tree to guess the cost of $T(n)$ and verify with the\nsubstitution method. Figure below ilustrates the recursion tree of\n$T(n) = 4 T(n/2) + n^2 \\lg n$.\n\n\\begin{center} Figure here. \\end{center}\n\nThe tree has $\\lg n$ levels and the number of nodes at depth $i$ is $4^i$. Each\nnode at depth $i$ has a cost $c((n/2^i)^2) \\lg(n) = 1/4^i c n^2 \\lg n$. Thus,\nthe total cost at depth $i$ is $4^i \\times 1/4^i c n^2 \\lg n = c n^2 \\lg n$.\n\nThe cost of the entire tree is\n\\[\n  \\sum_{i = 0}^{\\lg n} c n^2 \\lg n = O(n^2 \\lg^2 n).\n\\]\n\nLets verify with the substitution method. Our guess is\n\\[\nT(n) \\le cn^2\\lg^2 n \\; \\Forall n \\ge n_0,\n\\]\nwhere $c$ and $n_0$ are positive constants. Substituting into the\nrecurrence yields\n\\begin{equation*}\n\\begin{aligned}\n  T(n) &\\le 4c \\left(\\left(\\frac{n}{2}\\right)^2 \\lg^2{\\left(\\frac{n}{2}\\right)}\\right) + n^2 \\lg n\\\\\n       &=   4c \\left(\\frac{n^2}{4} \\lg{\\left(\\frac{n}{2}\\right)}\\lg{\\left(\\frac{n}{2}\\right)}\\right) + n^2 \\lg n\\\\\n       &=   c n^2 \\lg{\\left(\\frac{n}{2}\\right)}\\lg{\\left(\\frac{n}{2}\\right)} + n^2 \\lg n\\\\\n       &=   c n^2 \\lg{\\left(\\frac{n}{2}\\right)}\\lg n - c n^2 \\lg{\\left(\\frac{n}{2}\\right)} + n^2 \\lg n\\\\\n       &=   c n^2 \\lg^2 n - c n^2 \\lg n - c n^2 \\lg n + c n^2 + n^2 \\lg n\\\\\n       &\\le c n^2 \\lg^2 n,\n\\end{aligned}\n\\end{equation*}\nwhere the last step holds as long as $c \\ge 1$.\n\n\\end{framed}\n\n\\item[4.5{-}5]{Consider the regularity condition $a f(n/b) \\ge c f(n)$ for some\nconstant $c < 1$, which is part of case 3 of the master theorem. Give an example\nof constants $a \\ge 1$ and $b > 1$ and a function $f(n)$ that satisfies all\nthe conditions in case 3 of the master theorem except the regularity\ncondition.}\n\n\\begin{framed}\nLet $a = 1$, $b = 2$, and $f(n) = n \\cos n$. We have\n\\[\n  n^{\\log_b a} = n^{\\log_2 1} = \\Theta(1),\n\\]\nwhich is polynomially smaller than $f(n)$ and satisfies the primary condition of\nCase 3. However, we have\n\\[\n  a f\\left(\\frac{n}{b}\\right) \\le c f(n) \\rightarrow \\frac{n}{2} \\cos\\left(\\frac{n}{2}\\right) \\le c ( n \\cos n ),\n\\]\nwhich is not valid for some constant $c < 1$ and all sufficiently large $n$\nsince $\\cos(\\cdot)$ is not monotonic. Thus, it satisfies the primary condition\nof Case 3, but not the regularity condition\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section*{Problems}\n\\addcontentsline{toc}{section}{\\protect\\numberline{}Problems}%\n\n\\begin{enumerate}\n\n\\item[4{-}1]{\\textbf{\\emph{Recurrence examples}}\\\\\nGive asymptotic upper and lower bounds for $T(n)$ in each of the following\nrecurrences. Assume that $T(n)$ is constant for $n \\ge 2$. Make your bounds as\ntight as possible, and justify your answers.\n\n\\begin{enumerate}\n  \\item [a.] $2T(n/2) + n^4$.\n  \\item [b.] $T(7n/10) + n$.\n  \\item [c.] $16T(n/4) + n^2$.\n  \\item [d.] $7T(n/3) + n^2$.\n  \\item [e.] $7T(n/2) + n^2$.\n  \\item [f.] $2T(n/4) + \\sqrt{n}$.\n  \\item [g.] $T(n - 2) + n^2$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n  \\item[(a)] We use the master method. Case 3 applies, since $n^{\\lg 2} = n$ is\n    polynomially smaller than $f(n)$. Thus, $T(n) = \\Theta(n^4)$.\n  \\item[(b)] We use the master method. Case 3 applies, since\n    $n^{\\log_{10/7} 1} = 1$ is polynomially smaller than $f(n)$. Thus,\n    $T(n) = \\Theta(n)$.\n  \\item[(c)] We use the master method. Case 2 applies, since\n    $n^{\\log_4 14} = n^2 = \\Theta(f(n))$. Thus, $T(n) = \\Theta(n^2 \\lg n)$.\n  \\item[(d)] We use the master method. Case 3 applies, since $n^{\\log_3 7}$ is\n    polynomially smaller than $f(n)$. Thus, $T(n) = \\Theta(n^2)$.\n  \\item[(e)] We use the master method. Case 1 applies, since $n^{\\lg 7}$ is\n    polynomially larger than $f(n)$. Thus, $T(n) = \\Theta(n^{\\lg 7})$.\n  \\item[(f)] We use the master method. Case 2 applies, since\n    $n^{\\log_4 2} = \\sqrt n = \\Theta(f(n))$. Thus, $T(n) = \\Theta(\\sqrt n \\lg n)$.\n  \\item[(g)] The recurrence has $n/2$ levels and depth $i$ costs $c(n - 2i)^2$.\n    Thus, we have\n    \\[\n      T(n) = \\sum_{i = 0}^{n/2} c(n - 2i)^2\n           = \\sum_{i = 0}^{n/2} c(n^2 - 4ni + 4i^2)\n           = c \\left(\\sum_{i = 0}^{n/2} n^2 - \\sum_{i = 0}^{n/2} 4ni + \\sum_{i = 0}^{n/2} 4i^2\\right)\n           = \\Theta(n^3) - \\Theta(n^2) + \\Theta(n^3)\n           = \\Theta(n^3).\n    \\]\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[4{-}2]{\\textbf{\\emph{Parameter-passing costs}}\\\\\nThroughout this book, we assume that parameter passing during procedure calls\ntakes constant time, even if an $N$-element array is being passed. This\nassumption is valid in most systems because a pointer to the array is passed,\nnot the array itself.  This problem examines the implications of three\nparameter-passing strategies:\n\n\\begin{enumerate}\n  \\item[1.] An array is passed by pointer. Time = $\\Theta(1)$.\n  \\item[2.] An array is passed by copying. Time = $\\Theta(N)$, where $N$ is the size\n    of the array.\n  \\item[3.] An array is passed by copying only the subrange that might be accessed\n    by the called procedure. Time = $\\Theta(q - p + 1)$ if the subarray $A[p\n    \\dots q]$ is passed.\n\\end{enumerate}\n\n\\begin{enumerate}\n  \\item[a.] Consider the recursive binary search algorithm for finding a number\n    in a sorted array (see Exercise 2.3-5). Give recurrences for the worst-case\n    running times of binary search when arrays are passed using each of the\n    three methods above, and give good upper bounds on the solutions of the\n    recurrences. Let $N$ be the size of the original problem and $n$ be the size\n    of a subproblem.\n  \\item[b.] Redo part (a) for the \\textsc{Merge-Sort} algorithm from Section\n    2.3.1.\n\\end{enumerate}\n}\n\n\\begin{framed}\n  \\begin{enumerate}\n    \\item[a.] Binary search.\n      \\begin{enumerate}\n        \\item[1.] \\emph{Array passed by pointer.}\\\\\n          $T(n) = T(n/2) + \\Theta(1)$.\n          Case 2 of master method applies, since\n          $n^{\\lg 1} = 1 = f(n)$. Thus, $T(n) = \\Theta(\\lg n)$.\n        \\item[2.] \\emph{Array passed by copying.}\\\\\n          $T(n) = T(n/2) + \\Theta(N) = T(n/4) + \\Theta(N) + \\Theta(N)$\n          $= T(n/8) + \\Theta(N) + \\Theta(N) + \\Theta(N)$\n          $= \\dots = \\sum_{i = 0}^{\\lg n} \\Theta(N) = \\Theta(n \\lg n)$.\n        \\item[3.] \\emph{Subarray passed by copying.}\\\\\n          $T(n) = T(n/2) + \\Theta(n)$.\n          Case 3 of master method applies, since $n^{\\lg 1} = 1$ is\n          polynomially smaller than $f(n)$.\\\\\n          Thus, $T(n) = \\Theta(n)$.\n      \\end{enumerate}\n    \\item[b.] Merge sort.\n      \\begin{enumerate}\n        \\item[1.] \\emph{Array passed by pointer.}\\\\\n          $T(n) = T(\\floor{n/2}) + T(\\ceil{n/2}) + \\Theta(n) \\approx 2T(n/2) + \\Theta(n)$.\n          Case 2 of master method applies, since\n          $n^{\\lg 2} = n = f(n)$. Thus, $T(n) = \\Theta(n \\lg n)$.\n        \\item[2.] \\emph{Array passed by copying.}\\\\\n          $T(n) = 2T(n/2) + \\Theta(N) = 4T(n/4) + 2\\Theta(N) + \\Theta(N)$\n          $= 16T(n/8) + 4\\Theta(N) + 2\\Theta(N) + \\Theta(N)$\n          $= \\dots = \\sum_{i = 0}^{\\lg n} 2^i \\Theta(N) = \\Theta(n^2)$.\n        \\item[3.] \\emph{Subarray passed by copying.}\\\\\n          $T(n) = 2T(n/2) + \\Theta(n)$.\n          Case 2 of master method applies, since\n          $n^{\\lg 2} = n = f(n)$. Thus, $T(n) = \\Theta(n \\lg n)$.\n      \\end{enumerate}\n  \\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[4{-}3]{\\textbf{\\emph{More recurrence examples}}\\\\\nGive asymptotic upper and lower bounds for $T(n)$ in each of the following\nrecurrences. Assume that $T(n)$ is constant for sufficiently small $n$. Make\nyour bounds as tight as possible, and justify your answers.\n\n\\begin{enumerate}\n  \\item[a.] $T(n) = 4T(n/3) + n \\lg n$.\n  \\item[b.] $T(n) = 3T(n/3) + n / \\lg n$.\n  \\item[c.] $T(n) = 4T(n/2) + n^2 \\sqrt n$.\n  \\item[d.] $T(n) = 3T(n/3 - 2) + n/2$.\n  \\item[e.] $T(n) = 2T(n/2) + n / \\lg n$.\n  \\item[f.] $T(n) = T(n/2) + T(n/4) + T(n/8) + n$.\n  \\item[g.] $T(n) = T(n - 1) + 1/n$.\n  \\item[h.] $T(n) = T(n - 1) + \\lg n$.\n  \\item[i.] $T(n) = T(n - 2) + 1 / \\lg n$.\n  \\item[j.] $T(n) = \\sqrt n T(\\sqrt n) + n$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n  \\begin{enumerate}\n    \\item[a.] We have $f(n) = n \\lg n$ and $n^{\\lg_b a} = n^{\\log_3 4}$.\n      Since $n \\lg n = O(n^{\\log_3(4) - 0.2})$, case 1 applies and we have\n      $T(n) = \\Theta(n^{\\log_3 4})$.\n    \\item[b.] The tree has $\\log_3 n$ levels and depth $i$, for $i = 0, 1,\n      \\dots, \\log_3 n - 1$, costs $n/(\\log_3 n - i)$. The cost of the entire\n      tree is\n      \\[\n        T(n) = \\sum_{i = 0}^{\\log_3 n - 1} \\frac{n}{\\log_3 n - i}\n             = \\sum_{i = 1}^{\\log_3 n} \\frac{n}{i}\n             = n \\sum_{i = 1}^{\\log_3 n} \\frac{1}{i}\n             = n \\cdot H_{\\log_3 n}\n             = n \\cdot \\Theta(\\lg \\log_3 n)\n             = \\Theta(n \\lg \\lg n).\n      \\]\n      Skipped the proof.\n    \\item[c.] We have $f(n) = n^2 \\sqrt n = n^{5/2}$ and\n      $n^{\\log_b a} = n^{\\log_2 4} = n^2$. Since\n      $n^{5/2} = \\Omega(n^{2 + 1/2})$, we look at the regularity condition in\n      case 3 of the master method. We have\n      $af(n/b) = 4(n/2)^2 \\sqrt{n/2} = (n^{5/2})/\\sqrt 2 \\le c n^{5/2}$ for\n      $1/\\sqrt 2 \\le c < 1$. Case 3 applies and we have\n      $T(n) = \\Theta(n^2 \\sqrt n)$.\n    \\item[d.]\n      The tree has $\\log_3 n$ levels and depth $i$, for\n      $i = 0, 1, \\dots, \\log_3 n - 1$ costs $c (n/2) - 2 \\cdot 3^i$. The cost of\n      the entire tree is\n      \\[\n        T(n) = \\sum_{i = 0}^{\\log_3 n - 1} \\left(c \\frac{n}{2} - 2 \\cdot 3^i\\right)\n             = c \\sum_{i = 0}^{\\log_3 n - 1} \\frac{n}{2} - 2 \\sum_{i = 0}^{\\log_3 n - 1} 3^i\n             = \\Theta(n \\lg n).\n      \\]\n      Our guess for the upper bound is\n      \\[\n      T(n) \\le c n \\lg n \\; \\Forall n \\ge n_0,\n      \\]\n      where $c$ and $n_0$ are positive constants. Substituting into the recurrence\n      yields\n      \\begin{equation*}\n      \\begin{aligned}\n        T(n) &\\le 3c \\left(\\frac{n}{3} - 2\\right) \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2}\\\\\n             &=   c n \\lg \\left(\\frac{n}{3} - 2\\right) - 6c \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2}\\\\\n             &\\le cn \\lg \\left(\\frac{n}{3} - 2\\right) - 6c \\lg \\left(\\frac{n}{4}\\right) + \\frac{n}{2} & \\text{($n \\ge 24$)}\\\\\n             &=   cn \\lg \\left(\\frac{n}{3} - 2\\right) - 6c \\lg n - 12 c + \\frac{n}{2}\\\\\n             &<   cn \\lg n - 6c \\lg n - 12c + \\frac{n}{2}\\\\\n             &\\le cn \\lg n,\n      \\end{aligned}\n      \\end{equation*}\n      where the last step holds as long as $-6c \\lg n - 12c + n/2 \\le 0$\n      (skipped simplification).\n\n      Our guess for the lower bound is\n      \\[\n      T(n) \\ge c n \\lg n \\; \\Forall n \\ge n_0,\n      \\]\n      where $c$, and $n_0$ are positive constants. Substituting into the recurrence\n      yields\n      \\begin{equation*}\n      \\begin{aligned}\n        T(n) &\\ge 3c \\left(\\frac{n}{3} - 2\\right) \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2}\\\\\n             &=   c n \\lg \\left(\\frac{n}{3} - 2\\right) - 6c \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2}\\\\\n             &\\ge cn \\lg \\left(\\frac{n}{4}\\right) - 6c \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2} & \\text{($n \\ge 24$)}\\\\\n             &=   cn \\lg n - 2cn - 6c \\lg \\left(\\frac{n}{3} - 2\\right) + \\frac{n}{2}\\\\\n             &\\ge cn \\lg n,\n      \\end{aligned}\n      \\end{equation*}\n      where the last step holds as long as $-2cn - 6c \\lg (n/3 - 2) + n/2 \\ge 0$\n      (skipped simplification).\n    \\item[e.] The tree has $\\lg n$ levels and depth $i$, for $i = 0, 1,\n      \\dots, \\lg n - 1$, costs $n/(\\lg n - i)$. The cost of the entire\n      tree is\n      \\[\n        T(n) = \\sum_{i = 0}^{\\lg n - 1} \\frac{n}{\\lg n - i}\n             = \\sum_{i = 1}^{\\lg n} \\frac{n}{i}\n             = n \\sum_{i = 1}^{\\lg n} \\frac{1}{i}\n             = n \\cdot H_{\\lg n}\n             = n \\cdot \\Theta(\\lg \\lg n)\n             = \\Theta(n \\lg \\lg n).\n      \\]\n      Skipped the proof.\n    \\item[f.] The tree has $\\lg n$ levels, but is not complete. Considering\n      only the levels in which the tree is complete, depth $i$, for\n      $i = 1, 2, \\dots, \\log_8 n$, costs $(7/8)^i cn$. Thus, the cost of the\n      entire tree is at most\n      \\[\n        T(n) \\le \\sum_{i=0}^{\\lg n - 1} \\left( \\left(\\frac{7}{8}\\right)^i cn \\right)\n             = cn \\sum_{i=0}^{\\lg n - 1} \\left( \\left(\\frac{7}{8}\\right)^i \\right)\n             = cn \\frac{1 - \\left(\\frac{7}{8}\\right)^{\\lg n}}{1 - \\frac{7}{8}}\n             = cn \\frac{1 - n^{\\lg 7 - 3}}{\\frac{1}{8}}\n             = 8cn - 8cn^{\\lg 7 - 2}\n             = O(n).\n      \\]\n      Our guess for the upper bound is\n      \\[\n      T(n) \\le c n \\; \\Forall n \\ge n_0,\n      \\]\n      where $c$ and $n_0$ are positive constants. Substituting into the recurrence\n      yields\n      \\begin{equation*}\n      \\begin{aligned}\n        T(n) &\\le c \\frac{n}{2} + c \\frac{n}{4} + c \\frac{n}{8}\\\\\n             &= \\frac{7}{8} cn + n\\\\\n             &\\le cn,\n      \\end{aligned}\n      \\end{equation*}\n      where the last step holds as long as $c \\ge 8$.\n\n      Our guess for the lower bound is\n      \\[\n      T(n) \\ge c n \\; \\Forall n \\ge n_0,\n      \\]\n      where $c$ and $n_0$ are positive constants. Substituting into the recurrence\n      yields\n      \\begin{equation*}\n      \\begin{aligned}\n        T(n) &\\ge c \\frac{n}{2} + c \\frac{n}{4} + c \\frac{n}{8}\\\\\n             &= \\frac{7}{8} cn + n\\\\\n             &\\ge cn,\n      \\end{aligned}\n      \\end{equation*}\n      where the last step holds as long as $c \\le 8$.\n    \\item[g.] The tree has $n$ levels and depth $i$, for\n      $i = 1, 2, \\dots, n - 1$, costs $1/(n - i)$. The cost of the entire tree\n      is\n      \\[\n        \\sum_{i = 0}^{n - 1} \\frac{1}{n - i} = \\sum_{i = 1}^{n} \\frac{1}{i} = H_n = \\Theta(\\lg n).\n      \\]\n      Skipped the proof.\n    \\item[h.] The tree has $n$ levels and depth $i$, for\n      $i = 1, 2, \\dots, n - 1$, costs $\\lg(n - i)$. The cost of the entire tree\n      is\n      \\[\n        \\sum_{i = 0}^{n - 1} \\lg(n - i) = \\sum_{i = 1}^{n} \\lg i = \\lg(n!) = \\Theta(n \\lg n).\n      \\]\n      Skipped the proof.\n    \\item[i.] Skipped.\n    \\item[j.] Skipped.\n  \\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[4{-}4]{\\textbf{\\emph{Fibonacci numbers}}\\\\\nThis problem develops properties of the Fibonacci numbers, which are defined by\nrecurrence (3.22). We shall use the technique of generating functions to solve\nthe Fibonacci recurrence. Define the generating function (or formal power\nseries) $\\mathcal{F}$ as\n\n\\begin{equation*}\n\\begin{aligned}\n  \\mathcal{F}(z) &= \\sum_{i = 0}^\\infty F_i z^i\n                 &= 0 + z + z^2 + 2z^3 + 3z^4 + 5z^5 + 8z^6 + 13z^7 + 21z^8 + \\dots,\n\\end{aligned}\n\\end{equation*}\nwhere $F_i$ is the $i$th Fibonacci number.\n\n\\begin{enumerate}\n  \\item[a.] Show that $\\mathcal{F}(z) = z + z \\mathcal{F}(z) + z^2 \\mathcal{F}(z)$.\n  \\item[b.] Show that\n    \\begin{equation*}\n    \\begin{aligned}\n      \\mathcal{F}(z) &= \\frac{z}{1 - z - z^2}\\\\\n                     &= \\frac{z}{(1 - \\phi z)(1 - \\hat\\phi z)}\\\\\n                     &= \\frac{1}{\\sqrt 5} \\left( \\frac{1}{1 - \\phi z} - \\frac{1}{1 - \\hat\\phi z} \\right),\n    \\end{aligned}\n    \\end{equation*}\n    where\n    \\[\n      \\phi = \\frac{1 + \\sqrt 5}{2} = 1.61803 \\dots\n    \\]\n    and\n    \\[\n      \\hat\\phi = \\frac{1 - \\sqrt 5}{2} = 0.61803 \\dots .\n    \\]\n  \\item[c.] Show that\n    \\begin{equation*}\n    \\begin{aligned}\n      \\mathcal{F}(z) &= \\sum_{i = 0}^\\infty \\frac{1}{\\sqrt 5} (\\phi^i - \\hat\\phi^i) z^i.\n    \\end{aligned}\n    \\end{equation*}\n  \\item[d.] Use part (c) to prove that $F_i = \\phi^i/\\sqrt{5}$ for $i > 0$,\n    rounded to the nearest integer.\\\\(Hint: Observe that $|\\hat\\phi| < 1$.)\n\\end{enumerate}\n}\n\n\\begin{framed}\n  \\begin{enumerate}\n    \\item[a.]\n      \\begin{equation*}\n      \\begin{aligned}\n        \\mathcal{F}(z) &= \\sum_{i = 0}^{\\infty} F_i z^i\\\\\n                       &= 0 + z + \\sum_{i = 2}^{\\infty} (F_{(i - 1)} + F_{(i - 2)}) z^i\\\\\n                       &= z + \\sum_{i = 2}^{\\infty} F_{(i - 1)} z^i + \\sum_{i = 2}^{\\infty} F_{(i - 2)} z^i\\\\\n                       &= z + \\sum_{i = 1}^{\\infty} F_i z^{i + 1} + \\sum_{i = 0}^{\\infty} F_i z^{i + 2}\\\\\n                       &= z + \\sum_{i = 0}^{\\infty} F_i z^{i + 1} + \\sum_{i = 0}^{\\infty} F_i z^{i + 2} & \\text{(since $F_0 = 0$)}\\\\\n                       &= z + z \\sum_{i = 0}^{\\infty} F_i z^{i} + z^2 \\sum_{i = 0}^{\\infty} F_i z^{i}\\\\\n                       &= z + z \\mathcal{F}(z) + z^2 \\mathcal{F}(z).\n      \\end{aligned}\n      \\end{equation*}\n    \\newpage\n    \\item[b.]\n      \\begin{equation*}\n        \\begin{aligned}\n          \\mathcal{F}(z) &= \\mathcal{F}(z) \\cdot \\frac{1 - z - z^2}{1 - z - z^2}\\\\\n                         &= \\frac{\\mathcal{F}(z) - z\\mathcal{F}(z) - z^2 \\mathcal{F}(z)}{1 - z - z^2}\\\\\n                         &= \\frac{\\mathcal{F}(z) - (z + z \\mathcal{F}(z) + z^2 \\mathcal{F}(z)) + z}{1 - z - z^2}\\\\\n                         &= \\frac{\\mathcal{F}(z) - \\mathcal{F}(z) + z}{1 - z - z^2} & \\text{(from previous proof)}\\\\\n                         &= \\frac{z}{1 - z - z^2}\\\\\n                         &= \\frac{z}{1 - (\\phi + \\hat\\phi)z + \\phi \\hat\\phi z^2}\n                         & \\text{(since $\\phi + \\hat\\phi = 1$ and $\\phi \\hat\\phi = -1$)}\\\\\n                         &= \\frac{z}{(1 - \\phi z)(1 - \\hat\\phi z)}\\\\\n                         &= \\frac{1}{\\sqrt 5} \\left(\\frac{1}{1 - \\phi z} - \\frac{1}{1 - \\hat\\phi z}\\right).\n                         & \\text{(skipped this proof)}\n        \\end{aligned}\n      \\end{equation*}\n    \\item[c.]\n      \\begin{equation*}\n        \\begin{aligned}\n          \\mathcal{F}(n) &= \\frac{1}{\\sqrt 5} \\left(\\frac{1}{1 - \\phi z} - \\frac{1}{1 - \\hat\\phi z}\\right)\\\\\n                         &= \\frac{1}{\\sqrt 5} \\left(\\sum_{i = 0}^{\\infty} (\\phi z)^i - \\sum_{i = 0}^{\\infty} (\\hat\\phi z)^i\\right)\n                         & \\text{(by equation A.6, geometric series)}\\\\\n                         &= \\frac{1}{\\sqrt 5} \\sum_{i = 0}^{\\infty} \\left( (\\phi z)^i - (\\hat\\phi z)^i \\right)\\\\\n                         &= \\sum_{i = 0}^{\\infty} \\frac{1}{\\sqrt 5} (\\phi^i - \\hat\\phi^i) z^i.\n        \\end{aligned}\n      \\end{equation*}\n    \\item[d.] Skipped.\n  \\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[4{-}5]{\\textbf{\\emph{Chip testing}}\\\\\nProfessor Diogenes has $n$ supposedly identical integrated-circuit chips that in\nprinciple are capable of testing each other. The professor's test jig\naccommodates two chips at a time. When the jig is loaded, each chip tests the\nother and reports whether it is good or bad. A good chip always reports\naccurately whether the other chip is good or bad, but the professor cannot trust\nthe answer of a bad chip. Thus, the four possible outcomes of a test are as\nfollows:\n\n\\begin{tabular}{lll}\n  Chip $A$ says & Chip $B$ says & Conclusion\\\\\n  \\toprule\n  $B$ is good & $A$ is good & both are good, or both are bad\\\\\n  $B$ is good & $A$ is bad  & at least one is bad\\\\\n  $B$ is bad  & $A$ is good & at least one is bad\\\\\n  $B$ is bad  & $A$ is bad  & at least one is bad\n\\end{tabular}\n\n\\begin{enumerate}\n  \\item[a.] Show that if at least $n/2$ chips are bad, the professor cannot\n    necessarily determine which chips are good using any strategy based on this\n    kind of pairwise test. Assume that the bad chips can conspire to fool the\n    professor.\n  \\item[b.] Consider the problem of finding a single good chip from among\n    $n$ chips, assuming that more than $n/2$ of the chips are good. Show that\n    $\\floor{n/2}$ pairwise tests are sufficient to reduce the problem to one of\n    nearly half the size.\n  \\item[c.] Show that the good chips can be identified with $\\Theta(n)$ pairwise\n    tests, assuming that more than $n/2$ of the chips are good. Give and solve\n    the recurrence that describes the number of tests.\n\\end{enumerate}\n}\n\n\\begin{framed}\n  \\begin{enumerate}\n    \\item[a.] Let $n_g$ be the number of good chips and $n_b$ the\n      number of bad chips, such that $n_b \\ge n_g$ and $n_g\n      + n_b = n$. If the bad chips decide evaluate the others incorrectly\n      (good as bad and bad as good), the professor will have the following\n      result:\n\n      \\begin{tabular}{lll}\n        Chip state & Tested as good & Tested as bad\\\\\n        \\toprule\n        Good       & $n_g - 1$ times & $n_b$ times\\\\\n        Bad        & $n_b - 1$ times & $n_g$ times\\\\\n      \\end{tabular}\n\n      In this jig test, the number of good tests of the bad chips will be equal\n      or greater the number of good tests of the good chips, which will confuse\n      the professor.\n    \\item[b.] Group the chips in groups of two (if $n$ is odd, put the remaining\n      chip in the next subproblem), making a total of $\\floor{n/2}$ groups, and\n      evaluate each group in the test jig. For each test, do the following:\n\n      \\begin{tabular}{llll}\n        Group type & Chip $A$ says & Chip $B$ says & Conclusion\\\\\n        \\toprule\n        1 & $B$ is good & $A$ is good & keep one of them\\\\\n        2 & $B$ is good & $A$ is bad  & discard both\\\\\n        3 & $B$ is bad  & $A$ is good & discard both\\\\\n        4 & $B$ is bad  & $A$ is bad  & discard both\n      \\end{tabular}\n\n      For each test where at least one of the chips is evaluated as bad (group\n      types 2, 3, and 4), we known that at least one of them is truly bad. Thus,\n      we can safely discard both and assure that the majority of the remaining\n      chips are good. As for the groups where both of the chips are evaluated as\n      good (group type 1), we can assure that at least half of these groups are\n      composed by truly good chips, thus keeping one of them is enough to assure\n      that the subproblem will have at least half of good chips. The case where\n      exactly half of the groups of type 1 is composed by good chips only can\n      happen when $n$ is odd and the remaining chip that we previously added to\n      the subproblem must be good, thus assuring that the majority of the chips\n      from the subproblem is good. Also, since the number of groups is\n      $\\floor{n/2}$, the algorithm will perform $\\floor{n/2}$ tests and the\n      subproblem will have at most $\\ceil{n/2}$ chips.\n    \\item[c.] The recurrence of the above algorithm is\n      \\[\n        T(n) = T\\left(\\Bigl\\lceil\\frac{n}{2}\\Bigl\\rceil\\right) + \\frac{n}{2}.\n      \\]\n      We have that $f(n) = n/2$ and $n^{\\log_b a} = n^{\\log_2 1} = n^0 = 1$.\n      Since $n/2 = \\Omega(n^{0 + 0.5})$, we look at the regularity condition in\n      case 3 of masther method. We have $a f(n/b) = n/4 \\le c n/2$ for $1/2 \\le\n      c < 1$. Case 3 applies and we have $T(n) = \\Theta(n/2) = \\Theta(n)$.\n  \\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[4{-}6]{\\textbf{\\emph{Monge arrays}}\\\\\nAn $m \\times n$ array $A$ of real numbers is a \\textbf{\\emph{Monge array}} if\nfor all $i, j, k$, and $l$ such that $1 \\le i < k \\le m$ and\n$1 \\le j < l \\le n$, we have\n\\[\n  A[i, j] + A[k, l] \\le A[i, l] + A[k, j].\n\\]\nIn other words, whenever we pick two rows and two columns of a Monge array and\nconsider the four elements at the intersections of the rows and the columns, the\nsum of the upper-left and lower-right elements is less than or equal to the sum\nof the lower-left and upper-right elements. For example, the following array is\nMonge:\n\n\\begin{tabular}{ccccc}\n10 & 17 & 13 & 28 & 23\\\\\n17 & 22 & 16 & 29 & 23\\\\\n24 & 28 & 22 & 34 & 24\\\\\n11 & 13 & 6  & 17 & 7\\\\\n45 & 44 & 32 & 37 & 23\\\\\n36 & 33 & 19 & 21 & 6\\\\\n75 & 66 & 51 & 53 & 34\n\\end{tabular}\n\n\\begin{enumerate}\n  \\item[a.] Prove that an array is Monge if and only if for all $i = 1, 2,\n    \\dots, m - 1$ and $j = 1, 2, \\dots, n - 1$, we have:\n    \\[\n      A[i, j] + A[i + 1, j + 1] \\le A[i, j + 1] + A[i + 1, j].\n    \\]\n    (Hint: For the ``if'' part, use induction separately on rows and columns.)\n  \\item[b.] The following array is not Monge. Change one element in order to\n    make it Monge. (Hint: Use part(a).)\n\n    \\begin{tabular}{cccc}\n      37 & 23 & 22 & 32\\\\\n      21 & 6  & 7  & 10\\\\\n      53 & 34 & 30 & 31\\\\\n      32 & 13 & 9  & 6\\\\\n      43 & 21 & 15 & 8\n    \\end{tabular}\n  \\item[c.] Let $f(i)$ be the index of the column containing the leftmost\n    minimum element of row $i$. Prove that $f(1) \\le f(2) \\le \\cdots \\le f(m)$\n    for any $m \\times n$ Monge array.\n  \\item[d.] Here is a description of a divide-and-conquer algorithm that\n    computes the leftmost minimum element in each row of an $m \\times n$ Monge array $A$:\n\n    \\begin{quote}\n      Construct a submatrix $A'$ of $A$ consisting of the even-numbered rows of\n      $A$.  Recursively determine the leftmost minimum for each row of $A'$.\n      Then compute the leftmost minimum in the odd-numbered rows of $A$.\n    \\end{quote}\n\n    Explain how to compute the leftmost minimum in the odd-numbered rows of $A$\n    (given that the leftmost minimum of the even-numbered rows is known) in\n    $O(m + n)$ time.\n\n  \\item[e.] Write the recurrence describing the running time of the algorithm\n    described in part (d). Show that it is $O(m + n \\log m)$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n  \\begin{enumerate}\n    \\item[a.] The ``only if'' part is trivial. Since $k = i + 1, \\dots, m$ and $l = j + 1, \\dots, n$, we have\n      \\[\n        A[i, j] + A[k, l] \\le A[i, l] + A[k, j] \\rightarrow A[i, j] + A[i + 1, j + 1] \\le A[i, j + 1] + A[i + 1, j],\n      \\]\n\n      For the ``if'' part, we first need to show\n      \\begin{equation}\n        A[i, j] + A[i + 1, j + 1] \\le A[i, j + 1] + A[i + 1, j] \\rightarrow A[i, j] + A[k, j + 1] \\le A[i, j + 1] + A[k, j]\n        \\label{eq:p_4_6}\n      \\end{equation}\n      is valid for all $k > i$. The base case, which occurs when $k = i + 1$, is\n      given. Thus, we have\n      \\[\n        A[k, j] + A[k + 1, j + 1] \\le A[k, j + 1] + A[k + 1, j].\n      \\]\n      in which $k = i + 1, \\dots, m - 1$. Now assume that the rhs of (1) holds for a given $k$\n      \\[\n        A[i, j] + A[k, j + 1] \\le A[i, j + 1] + A[k, j],\n      \\]\n      then we have\n      \\[\n        \\underbrace{A[i, j] + A[k, j + 1]}_\\text{assumption} +\n        \\underbrace{A[k, j] + A[k + 1, j + 1]}_\\text{base case} \\le\n        \\underbrace{A[i, j + 1] + A[k, j]}_\\text{assumption} +\n        \\underbrace{A[k, j + 1] + A[k + 1, j]}_\\text{base case},\n      \\]\n      cancelling equal terms on both sides, we have\n      \\[\n        A[i, j] + A[k + 1, j + 1] \\le A[i, j + 1] + A[k + 1, j],\n      \\]\n      which shows that it also holds for $k + 1$ and proves the inductive step.\n\n      Then we need to show\n      \\begin{equation}\n        A[i, j] + A[i + 1, j + 1] \\le A[i, j + 1] + A[i + 1, j] \\rightarrow A[i, j] + A[i + 1, l] \\le A[i, l] + A[i + 1, j]\n      \\end{equation}\n      is valid for all $l > j$. The base case, which occurs when $l = j + 1$, is\n      given. Thus, we have\n      \\[\n        A[i, l] + A[i + 1, l + 1] \\le A[i, l + 1] + A[i + 1, l].\n      \\]\n      in which $l = j + 1, \\dots, n - 1$. Now assume that the rhs of (2) holds for a given $l$\n      \\[\n        A[i, j] + A[i + 1, l] \\le A[i, l] + A[i + 1, j],\n      \\]\n      then we have\n      \\[\n        \\underbrace{A[i, j] + A[i + 1, l]}_\\text{assumption} +\n        \\underbrace{A[i, l] + A[i + 1, l + 1]}_\\text{base case} \\le\n        \\underbrace{A[i, l] + A[i + 1, j]}_\\text{assumption} +\n        \\underbrace{A[i, l + 1] + A[i + 1, l]}_\\text{base case},\n      \\]\n      cancelling equal terms on both sides, we have\n      \\[\n        A[i, j] + A[i + 1, l + 1] \\le  + A[i, l + 1] + A[i + 1, j],\n      \\]\n      which shows that it also holds for $l + 1$ and proves the inductive step.\n\n      From the ``if'' and ``only if'' proofs, we have\n      \\[\n        A[i, j] + A[k, l] \\le A[i, l] + A[k, j] \\iff A[i, j] + A[i + 1, j + 1] \\le A[i, j + 1] + A[i + 1, j].\n      \\]\n      \\item[b.] Let $M$ be the $m \\times n$ matrix we want to make Monge. In\n        this case, $m = 5$ and $n = 4$. From item (a), we know that, to be\n        Monge, the following needs to hold:\n        \\begin{equation*}\n        \\begin{aligned}\n        M[i, j] + M[i + 1, j + 1] \\le M[i, j + 1] + M[i + 1, j] \\; \\Forall i = 1, 2, \\dots, m - 1 \\; \\Forall j = 1, 2, \\dots, n - 1,\\\\\n        \\end{aligned}\n        \\end{equation*}\n      which implies\n      \\[\n        M[i, j] + M[i + 1, j + 1] - M[i, j + 1] + M[i + 1, j] \\le 0.\n      \\]\n      Let $K$ be an $(m - 1) \\times (n - 1)$ matrix where\n      \\[\n        K[i, j] = M[i, j] + M[i + 1, j + 1] - M[i, j + 1] + M[i + 1, j].\n      \\]\n      Thus, we have\n      \\[\n      K =\n      \\begin{bmatrix}\n      -1 &  2 & -7\\\\\n      -4 & -5 & -2\\\\\n       0 &  0 & -4\\\\\n      -3 & -2 & -4\n      \\end{bmatrix}\n      ,\\]\n    which shows that the problem is that\n    $M[1, 2] + M[2, 3] - M[1, 3] + M[2, 2] = 2 > 0$.\n\n    We can make $M$ monge by changing the element $M[1, 3]$ from $22$ to $24$,\n    now becoming:\n      \\[\n      M =\n      \\begin{bmatrix}\n      37 & 23 & 24 & 32\\\\\n      21 & 6  & 7  & 10\\\\\n      53 & 34 & 30 & 31\\\\\n      32 & 13 & 9  & 6\\\\\n      43 & 21 & 15 & 8\n      \\end{bmatrix}\n      .\\]\n    \\item[c.] Lets assume that $f(i + 1) < f(i)$. From the definition of a Monge\n      array, we have\n      \\[\n        A[i, f(i + 1)] + A[i + 1, f(i)] \\le A[i, f(i)] + A[i + 1, f(i + 1)],\n      \\]\n      which is not possible since from the definition of $f(\\cdot)$\n      \\[\n        A[i, f(i + 1)] > A[i, f(i)],\n      \\]\n      and\n      \\[\n        A[i + 1, f(i)] \\ge A[i + 1, f(i + 1)].\n      \\]\n    \\item[d.] We know from item (c) that $f(i - 1) \\le f(i) \\le f(i + 1)$. Thus,\n      for each odd-numbered row $i$ of the matrix, we just need to find the\n      leftmost minimum of row $i$ between the columns $f(i - 1)$ and $f(i + 1)$,\n      which includes $f(i + 1) - f(i - 1) + 1$ elements. If $i$ corresponds to\n      the first ($i = 1$) or the last ($i = m$) row of the matrix, consider\n      $f(i - 1) = f(0) = 1$ or $f(i + 1) = f(m + 1) = m$. Since the matrix has\n      $\\ceil{m / 2}$ odd-numbered rows, finding the leftmost minimum of all of\n      them takes\n      \\begin{equation*}\n      \\begin{aligned}\n        \\sum_{i = 1}^{\\ceil{m/2}} (f(i + 1) - f(i - 1) + 1)\n        &= \\Bigl\\lceil{\\frac{m}{2}}\\Bigl\\rceil + \\sum_{i = 1}^{\\ceil{m/2}} (f(i + 1) - f(i - 1))\\\\\n        &= O(m) + f(\\ceil{m/2}) - f(1)\\\\\n        &= O(m + n).\n      \\end{aligned}\n      \\end{equation*}\n    \\item[e.]\n      Since we can partition the array in $O(1)$ (working with pointers), the\n      recurrence can be written as\n      \\begin{equation*}\n      \\begin{aligned}\n        T(m) &= T(m/2) + O(m + n)\\\\\n             &= \\sum_{i = 0}^{\\lg m - 1} \\left(cn + d \\frac{m}{2^i}\\right)\\\\\n             &= cn \\lg m + dm \\sum_{i = 0}^{\\lg m - 1} \\frac{1}{2^i}\\\\\n             &\\le cn \\lg m + dm \\sum_{i = 0}^{\\infty} (1/2)^i & \\text{(infinity decreasing geometric series)}\\\\\n             &= cn \\lg m + dm \\left(\\frac{1}{1 - (1/2)}\\right)\\\\\n             &= cn \\lg m + 2dm\\\\\n             &= O(m + n \\lg m).\n      \\end{aligned}\n      \\end{equation*}\n  \\end{enumerate}\n\n\\end{framed}\n\n\\end{enumerate}\n", "meta": {"hexsha": "64ed6295feaf1e18c0f892f8c0eb16a2fc34d795", "size": 74385, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/C4.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/C4.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/C4.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 36.3563049853, "max_line_length": 134, "alphanum_fraction": 0.5718894938, "num_tokens": 29106, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8056321889812553, "lm_q2_score": 0.9372107874569682, "lm_q1q2_score": 0.7550471782358033}}
{"text": "\\section{Dependent function types}\n\\label{ch:pi}\n\n\\index{Pi-type@{$\\Pi$-type}|see {dependent function type}}\n\\index{dependent function type|(}\nA fundamental concept in dependent type theory is that of a dependent function. A dependent function is a function of which the type of the output may depend on the input. They are a generalization of ordinary functions, because an ordinary function $f:A\\to B$ is a function of which the output $f(x)$ has type $B$ regardless of the value of $x$.\n\n\\subsection{Dependent function types}\nConsider a section $b$ of a family $B$ over $A$ in context $\\Gamma$, i.e.,\n\\begin{equation*}\n  \\Gamma,x:A\\vdash b(x):B(x).\n\\end{equation*}\nFrom one point of view, such a section $b$ is an operation, or a program\\index{program}, that takes as input $x:A$ and produces a term $b(x):B(x)$. From a more mathematical point of view we see $b$ as a choice of an element of each $B(x)$. In other words, we may see $b$ as a function that takes $x:A$ to $b(x):B(x)$. Note that the type $B(x)$ of the output is dependent on $x:A$. In this section we postulate rules for the \\emph{type} of all such dependent functions: whenever $B$ is a family over $A$ in context $\\Gamma$, there is a type\n\\begin{equation*}\n  \\prd{x:A}B(x)\n\\end{equation*}\nin context $\\Gamma$, consisting of all the dependent functions of which the output at $x:A$ has type $B(x)$. There are four principal rules for $\\Pi$-types:\n\\begin{enumerate}\n\\item The formation rule, which tells us how we may form dependent function types.\n\\item The introduction rule, which tells us how to introduce new terms of dependent function types.\n\\item The elimination rule, which tells us how to use arbitrary terms of dependent function types.\n\\item The computation rules, which tell us how the introduction and elimination rules interact. These computation rules guarantee that every term of a dependent function type behaves as expected: as a dependent function.\n\\end{enumerate}\nIn the cases of the formation rule, the introduction rule, and the elimination rule, we also need rules that assert that all the constructions respect judgmental equality. Those rules are called \\define{congruence rules}.\n\n\\subsubsection{The $\\Pi$-formation rule}\n\\index{dependent function type!formation rule}\n\\define{Dependent function types} are formed by the following \\define{$\\Pi$-formation rule}\\index{rules!for dependent function types!formation}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$.}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)~\\type$}\n\\end{prooftree}\n\nThe congruence rule for $\\Pi$-formation asserts that formation of dependent function types respects judgmental equality of types:\n\\index{rules!for dependent function types!congruence}\n\\index{dependent function type!congruence rule}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A\\jdeq A'~\\type$}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)\\jdeq B'(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$-eq.}\n\\BinaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)\\jdeq\\prd{x:A'}B'(x)~\\type$}\n\\end{prooftree}\n\nThere is one last rule that we need about the formation of $\\Pi$-types, asserting that it does not matter what name we use for the variable $x$ that appears in the expression\n\\begin{equation*}\n  \\prd{x:A}B(x).\n\\end{equation*}\nMore precisely, when $x'$ is a fresh variable, i.e., which does not occur in the context $\\Gamma,x:A$, we postulate that\n\\index{rules!for dependent function types!change of bound variable}\n\\index{dependent function type!change of bound variable}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A\\vdash B(x)~\\textrm{type}$}\n\\RightLabel{$\\Pi$-$x'/x$.}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B(x)\\jdeq \\prd{x':A}B(x')~\\type$}\n\\end{prooftree}\nThis rule is also known as \\define{$\\alpha$-conversion} for $\\Pi$-types.\n\n\\subsubsection{The $\\Pi$-introduction rule}\nThe introduction rule%\n\\index{dependent function type!introduction rule|see {$\\lambda$-abstraction}}\nfor dependent function types is also called the $\\lambda$-abstraction rule. Recall that dependent functions are formed from terms $b(x)$ of type $B(x)$ in context $\\Gamma,x:A$.\nTherefore the \\define{$\\lambda$-abstraction rule}\n\\index{lambda-abstraction@{$\\lambda$-abstraction}}\n\\index{rules!for dependent function types!lambda-abstraction@{$\\lambda$-abstraction}}\n\\index{dependent function type!lambda-abstraction@{$\\lambda$-abstraction}}\nis as follows:\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n  \\RightLabel{$\\lambda$}\n  \\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x) : \\prd{x:A}B(x)$}\n\\end{prooftree}\n\nJust like ordinary mathematicians, we will sometimes write $x\\mapsto f(x)$ for a function $f$. The map $n\\mapsto n^2$ is an example.\n\nThe $\\lambda$-abstraction is also required to respect judgmental equality. Therefore we postulate the \\define{congruence rule} for $\\lambda$-abstraction,\n\\index{rules!for dependent function types!lambda-congruence@{$\\lambda$-congruence}}\n\\index{lambda-congruence@{$\\lambda$-congruence}}\n\\index{dependent function type!lambda-congruence@{$\\lambda$-congruence}}\nwhich asserts that\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma,x:A \\vdash b(x)\\jdeq b'(x) : B(x)$}\n  \\RightLabel{$\\lambda$-eq.}\n  \\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x)\\jdeq \\lam{x}b'(x) : \\prd{x:A}B(x)$}\n\\end{prooftree}\n\n\\subsubsection{The $\\Pi$-elimination rule}\n\n\\index{dependent function type!elimination rule|see {evaluation}}\nThe elimination rule for dependent function types provides us with a way to \\emph{use} dependent functions. The way to use a dependent function is to apply it to an argument of the domain type. The $\\Pi$-elimination rule is therefore also called the \\define{evaluation rule}\\index{evaluation}\\index{rules!for dependent function types!evaluation}\\index{dependent function type!evaluation}. It asserts that given a dependent function $f:\\prd{x:A}B(x)$ in context $\\Gamma$ we obtain a term $f(x)$ of type $B(x)$ in context $\\Gamma,x:A$. More formally:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\RightLabel{$ev$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash f(x) : B(x)$}\n\\end{prooftree}\nAgain we require that evaluation respects judgmental equality:\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma\\vdash f\\jdeq f':\\prd{x:A}B(x)$}\n  \\UnaryInfC{$\\Gamma,x:A\\vdash f(x)\\jdeq f'(x):B(x)$}\n\\end{prooftree}\n\n\\subsubsection{The $\\Pi$-computation rules}\n\n\\index{dependent function type!computation rules|see {$\\beta$- and $\\eta$-rules}}\nThe computation rules for dependent function types postulate that $\\lambda$-abstraction rule and the evaluation rule are mutual inverses. Thus we have two computation rules.\n\nFirst we postulate the \\define{$\\beta$-rule}\\index{beta-rule@{$\\beta$-rule}!for Pi-types@{for $\\Pi$-types}}\\index{rules!for dependent function types!beta-rule@{$\\beta$-rule}}\\index{dependent function type!beta-rule@{$\\beta$-rule}}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n\\RightLabel{$\\beta$.}\n\\UnaryInfC{$\\Gamma,x:A \\vdash (\\lambda y.b(y))(x)\\jdeq b(x) : B(x)$}\n\\end{prooftree}\nSecond, we postulate the \\define{$\\eta$-rule}\\index{eta-rule@{$\\eta$-rule}!for Pi-types@{for $\\Pi$-types}}\\index{rules!for dependent function types!eta-rule@{$\\eta$-rule}}\\index{dependent function type!eta-rule@{$\\eta$-rule}}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\RightLabel{$\\eta$.}\n\\UnaryInfC{$\\Gamma \\vdash \\lam{x}f(x) \\jdeq f : \\prd{x:A}B(x)$}\n\\end{prooftree}\nThis completes the specification of dependent function types.\n\n\\subsection{Ordinary function types}\nIn the case where both $A$ and $B$ are types in context $\\Gamma$, we may first weaken $B$ by $A$, and then apply the formation rule for the dependent function type:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\BinaryInfC{$\\Gamma,x:A\\vdash B~\\textrm{type}$}\n\\UnaryInfC{$\\Gamma\\vdash \\prd{x:A}B~\\textrm{type}$}\n\\end{prooftree}\nThe result is the type of functions that take an argument of type $A$, and return a term of type $B$. In other words, terms of the type $\\prd{x:A}B$ are \\emph{ordinary} functions from $A$ to $B$. We write $A\\to B$\\index{A arrow B@{$A\\to B$}|see {function type}} for the \\define{type of functions}\\index{function type} from $A$ to $B$. Sometimes we will also write $B^A$\\index{B^A@{$B^A$}|see {function type}} for the type $A\\to B$.\n\nWe give a brief summary of the rules specifying ordinary function types, omitting the congruence rules. All of these rules can be derived easily from the corresponding rules for $\\Pi$-types.\\index{rules!for function types}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\RightLabel{$\\to$}\n\\BinaryInfC{$\\Gamma\\vdash A\\to B~\\textrm{type}$}\n\\end{prooftree}%\n\\begin{center}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma,x:A\\vdash b(x):B$}\n\\RightLabel{$\\lambda$}\n\\BinaryInfC{$\\Gamma\\vdash \\lam{x}b(x):A\\to B$}\n\\end{prooftree}%\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\RightLabel{$ev$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n\\end{prooftree}%\n\\end{minipage}\n\\end{center}\n\\begin{center}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma,x:A\\vdash b(x):B$}\n\\RightLabel{$\\beta$}\n\\BinaryInfC{$\\Gamma,x:A\\vdash(\\lam{y}b(y))(x)\\jdeq b(x):B$}\n\\end{prooftree}%\n\\end{minipage}\n\\begin{minipage}{.45\\textwidth}\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\RightLabel{$\\eta$}\n\\UnaryInfC{$\\Gamma\\vdash\\lam{x} f(x)\\jdeq f:A\\to B$}\n\\end{prooftree}\n\\end{minipage}\n\\end{center}\n\n\\subsection{The identity function, composition, and their laws}\n\\begin{defn}\nFor any type $A$ in context $\\Gamma$, we define the \\define{identity function}\\index{identity function}\\index{function type!identity function} $\\idfunc[A]:A\\to A$\\index{id A@{$\\idfunc[A]$}} using the variable rule:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\UnaryInfC{$\\Gamma,x:A\\vdash x:A$}\n\\UnaryInfC{$\\Gamma\\vdash \\idfunc[A]\\defeq \\lam{x}x:A\\to A$}\n\\end{prooftree}\n\\end{defn}\n\nNote that we have used the symbol $\\defeq$ in the conclusion to define the identity function. A judgment of the form $\\Gamma\\vdash a\\defeq b:A$ should be read as \"$b$ is a well-defined term of type $A$ in context $\\Gamma$, and we will refer to it as $a$\".\n\n\\begin{defn}\nFor any three types $A$, $B$, and $C$ in context $\\Gamma$, there is a \\define{composition}\\index{function type!composition}\\index{composition!of functions} operation\n\\begin{equation*}\n\\comp:(B\\to C)\\to ((A\\to B)\\to (A\\to C)),\n\\end{equation*}\ni.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash B~\\textrm{type}$}\n\\AxiomC{$\\Gamma\\vdash C~\\textrm{type}$}\n\\TrinaryInfC{$\\Gamma\\vdash\\comp:(B\\to C)\\to ((A\\to B)\\to (A\\to C))$}\n\\end{prooftree}\nWe will write $g\\circ f$\\index{g composed with f@{$g\\circ f$}} for $\\comp(g,f)$\\index{comp(g,f)@{$\\comp(g,f)$}}.\n\\end{defn}\n\n\\begin{constr}\n  The idea of the definition is to define $\\comp(g,f)$ to be the function $\\lam{x}g(f(x))$. The derivation we use to construct $\\comp$ is as follows:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash A~\\type$}\n    \\AxiomC{$\\Gamma\\vdash B~\\type$}\n    \\BinaryInfC{$\\Gamma,f:B^A,x:A\\vdash f(x):B$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,x:A\\vdash f(x):B$}\n    \\AxiomC{$\\Gamma\\vdash B~\\type$}\n    \\AxiomC{$\\Gamma\\vdash C~\\type$}\n    \\BinaryInfC{$\\Gamma,g:C^B,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A,x:A,y:B\\vdash g(y):C$}\n    \\BinaryInfC{$\\Gamma,g:C^B,f:B^A,x:A\\vdash g(f(x)) : C$}\n    \\UnaryInfC{$\\Gamma,g:C^B,f:B^A\\vdash \\lam{x}g(f(x)):C^A$}\n    \\UnaryInfC{$\\Gamma,g:B\\to C\\vdash \\lam{f}\\lam{x}g(f(x)):B^A\\to C^A$}\n    \\UnaryInfC{$\\Gamma\\vdash\\comp\\defeq \\lam{g}\\lam{f}\\lam{x}g(f(x)):C^B\\to (B^A\\to C^A)$}\n  \\end{prooftree}\n\\end{constr}\n\nThe rules of function types can be used to derive the laws of a category\\index{category laws!for functions} for functions, i.e., we can derive that function composition is associative and that the identity function satisfies the unit laws. In the remainder of this section we will give these derivations.\n\n\\begin{lem}\nComposition of functions is associative\\index{associativity!of function composition}\\index{composition!of functions!associativity}, i.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n\\AxiomC{$\\Gamma\\vdash h:C\\to D$}\n\\TrinaryInfC{$\\Gamma \\vdash (h\\circ g)\\circ f\\jdeq h\\circ(g\\circ f):A\\to D$}\n\\end{prooftree}\n\\end{lem}\n\n\\begin{proof}\n  The main idea of the proof is that both $((h\\circ g)\\circ f)(x)$ and $(h\\circ (g\\circ f))(x)$ evaluate to $h(g(f(x))$, and therefore $(h\\circ g)\\circ f$ and $h\\circ(g\\circ f)$ must be judgmentally equal. This idea is made formal in the following derivation:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n    \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n    \\UnaryInfC{$\\Gamma,y:B\\vdash g(y):C$}\n    \\UnaryInfC{$\\Gamma,x:A,y:B\\vdash g(y):C$}\n    \\BinaryInfC{$\\Gamma,x:A\\vdash g(f(x)):C$}\n    \\AxiomC{$\\Gamma\\vdash h:C\\to D$}\n    \\UnaryInfC{$\\Gamma,z:C\\vdash h(z):D$}\n    \\UnaryInfC{$\\Gamma,x:A,z:C\\vdash h(z):D$}\n    \\BinaryInfC{$\\Gamma,x:A\\vdash h(g(f(x))):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash h(g(f(x)))\\jdeq h(g(f(x))):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash (h\\circ g)(f(x))\\jdeq h((g\\circ f)(x)):D$}\n    \\UnaryInfC{$\\Gamma,x:A\\vdash ((h\\circ g)\\circ f)(x)\\jdeq (h\\circ (g \\circ f))(x):D$}\n    \\UnaryInfC{$\\Gamma\\vdash (h\\circ g)\\circ f\\jdeq h\\circ(g\\circ f):A\\to D$.}\n  \\end{prooftree}\n\\end{proof}\n\n\\begin{lem}\\label{lem:fun_unit}\nComposition of functions satisfies the left and right unit laws\\index{left unit law|see {unit laws}}\\index{right unit law|see {unit laws}}\\index{unit laws!for function composition}\\index{composition!of functions!unit laws}, i.e., we can derive\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\UnaryInfC{$\\Gamma\\vdash \\idfunc[B]\\circ f\\jdeq f:A\\to B$}\n\\end{prooftree}\nand\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n\\UnaryInfC{$\\Gamma\\vdash f\\circ\\idfunc[A]\\jdeq f:A\\to B$}\n\\end{prooftree}\n\\end{lem}\n\n\\begin{proof}\nThe derivation for the left unit law is\n%\\begin{prooftree}\n%\\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n%\\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n%\\AxiomC{$\\Gamma\\vdash B~\\type$}\n%\\UnaryInfC{$\\Gamma,y:B\\vdash \\idfunc[B](y)\\jdeq y:B$}\n%\\UnaryInfC{$\\Gamma,x:A,y:B\\vdash \\idfunc[B](y)\\jdeq y:B$}\n%\\BinaryInfC{$\\Gamma,x:A\\vdash \\idfunc[B](f(x))\\jdeq f(x):B$}\n%\\UnaryInfC{$\\Gamma,x:A\\vdash (\\idfunc[B]\\circ f)(x)\\jdeq f(x):B$}\n%\\UnaryInfC{$\\Gamma\\vdash \\idfunc[B]\\circ f\\jdeq f:A\\to B$}\n%\\end{prooftree}\n\\begin{prooftree}\n  \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n  \\UnaryInfC{$\\Gamma,x:A\\vdash f(x):B$}\n  \\AxiomC{$\\Gamma\\vdash A~\\type$}\n  \\AxiomC{$\\Gamma\\vdash B~\\type$}\n  \\UnaryInfC{$\\Gamma,y:B\\vdash\\idfunc(y)\\jdeq y:B$}\n  \\BinaryInfC{$\\Gamma,x:A,y:B\\vdash\\idfunc(y)\\jdeq y:B$}\n  \\BinaryInfC{$\\Gamma,x:A\\vdash\\idfunc(f(x))\\jdeq f(x):B$}\n  \\UnaryInfC{$\\Gamma\\vdash\\lam{x}\\idfunc(f(x))\\jdeq\\lam{x}f(x):A\\to B$}\n  \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n  \\UnaryInfC{$\\Gamma\\vdash\\lam{x}f(x)\\jdeq f:A\\to B$}\n  \\BinaryInfC{$\\Gamma\\vdash\\idfunc\\circ f\\jdeq f:A\\to B$}\n\\end{prooftree}\nThe right unit law is left as \\cref{ex:fun_right_unit}.\n\\end{proof}\n\n\\begin{exercises}\n\\exercise \\label{ex:fun_right_unit}Give a derivation for the right unit law of \\cref{lem:fun_unit}.\\index{unit laws!for function composition}\n\\exercise Show that the rule\n\\begin{prooftree}\n\\AxiomC{$\\Gamma,x:A \\vdash b(x) : B(x)$}\n\\RightLabel{$\\lambda$-$x'/x$}\n\\UnaryInfC{$\\Gamma\\vdash \\lam{x}b(x)\\jdeq \\lam{x'}b(x') : \\prd{x:A}B(x)$}\n\\end{prooftree}\nis derivable for any variable $x'$ that does not occur in the context $\\Gamma,x:A$.\n\\exercise \n  \\begin{subexenum}\n  \\item Construct the \\define{constant function}\\index{constant function}\\index{function!constant function}\\index{const x@{$\\const_x$}}\\index{function!const@{$\\const$}}\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n      \\UnaryInfC{$\\Gamma,y:B\\vdash \\const_y:A\\to B$}\n    \\end{prooftree}\n  \\item Show that\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n      \\UnaryInfC{$\\Gamma,z:C\\vdash \\const_z\\circ f\\jdeq\\const_z : A\\to C$}\n    \\end{prooftree}\n  \\item Show that\n    \\begin{prooftree}\n      \\AxiomC{$\\Gamma\\vdash A~\\textrm{type}$}\n      \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n      \\BinaryInfC{$\\Gamma,y:B\\vdash g\\circ\\const_y\\jdeq \\const_{g(y)}:A\\to C$}\n    \\end{prooftree}\n  \\end{subexenum}\n\\exercise In this exercise we generalize the composition operation of non-dependent function types\\index{composition!of dependent functions}:\n\\begin{subexenum}\n\\item Define a composition operation for dependent function types\n  \\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\AxiomC{$\\Gamma\\vdash g:\\prd{x:A}\\prd{y:B(x)} C(x,y)$}\n\\BinaryInfC{$\\Gamma\\vdash g\\circ' f:\\prd{x:A} C(x,f(x))$}\n\\end{prooftree}\nand show that this operation agrees with ordinary composition when it is specialized to non-dependent function types.\n\\item Show that composition of dependent functions agrees with ordinary composition of functions:\n  \\begin{prooftree}\n    \\AxiomC{$\\Gamma\\vdash f:A\\to B$}\n    \\AxiomC{$\\Gamma\\vdash g:B\\to C$}\n    \\BinaryInfC{$\\Gamma\\vdash (\\lam{x}g)\\circ' f\\jdeq g\\circ f:A \\to C$}\n  \\end{prooftree}\n\\item Show that composition of dependent functions is associative.\\index{associativity!of dependent function composition}\\index{composition!of dependent functions!associativity}\n\\item Show that composition of dependent functions satisfies the right unit law\\index{unit laws!dependent function composition}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\UnaryInfC{$\\Gamma\\vdash (\\lam{x}f)\\circ'\\idfunc[A]\\jdeq f :\\prd{x:A}B(x)$}\n\\end{prooftree}\n\\item Show that composition of dependent functions satisfies the left unit law\\index{unit laws!dependent function composition}\\index{composition!of dependent functions!unit laws}:\n\\begin{prooftree}\n\\AxiomC{$\\Gamma\\vdash f:\\prd{x:A}B(x)$}\n\\UnaryInfC{$\\Gamma\\vdash (\\lam{x}\\idfunc[B(x)])\\circ' f\\jdeq f:\\prd{x:A}B(x)$}\n\\end{prooftree}\n\\end{subexenum}\n\\exercise \\label{ex:swap}\n\\begin{subexenum}\n\\item Given two types $A$ and $B$ in context $\\Gamma$, and a type $C$ in context $\\Gamma,x:A,y:B$, define the \\define{swap function}\\index{function!swap}\\index{swap function}\n\\begin{equation*}\n\\Gamma\\vdash \\sigma:\\Big(\\prd{x:A}\\prd{y:B}C(x,y)\\Big)\\to\\Big(\\prd{y:B}\\prd{x:A}C(x,y)\\Big)\n\\end{equation*}\nthat swaps the order of the arguments.\n\\item Show that\n\\begin{equation*}\n\\Gamma\\vdash \\sigma\\circ\\sigma\\jdeq\\idfunc:\\Big(\\prd{x:A}\\prd{y:B}C(x,y)\\Big)\\to \\Big(\\prd{x:A}\\prd{y:B}C(x,y)\\Big).\n\\end{equation*}\n\\end{subexenum}\n\\end{exercises}\n\\index{dependent function type|)}\n", "meta": {"hexsha": "c8e1d810085384c5cf2f24ef53424f3e3defac10", "size": 18612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Book/pi.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": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Book/pi.tex", "max_issues_repo_name": "hemangandhi/HoTT-Intro", "max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Book/pi.tex", "max_forks_repo_name": "hemangandhi/HoTT-Intro", "max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934", "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.5567867036, "max_line_length": 548, "alphanum_fraction": 0.706855792, "num_tokens": 6529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8397339736884712, "lm_q1q2_score": 0.7550227669631407}}
{"text": "\\section{Technical Details}\n\n\n\n\\subsection{Problem Statement}\n\nMinimize the objective function:\n\\begin{equation*}\n\\underset{t_0, t_F, \\bm{x}(t), \\bm{u}(t)} \\min \\;\nJ_B\\big(t_0,t_F,\\bm{x}(t_0),\\bm{x}(t_F) \\big) +\n\\int_{t_0}^{t_F} \\! J_P \\big( \\tau, \\bm{x}(\\tau), \\bm{u}(\\tau) \\big)  \\; d\\tau\n\\label{eqn:optimTraj_objectiveFunction}\n\\end{equation*}\n\nSubject to the constraints:\n\\begin{align*}\n& \\quad   \\dot{\\bm{x}}(t) = \\bm{f} \\big(t, \\bm{x}(t), \\bm{u}(t)\\big)   & \\quad & \\eqnTxt{system dynamics}\\\\\n\n& \\quad   \\bm{C}_P \\big(t, \\bm{x}(t), \\bm{u}(t)\\big) \\leq \\bm{0}    & \\quad &   \\eqnTxt{path constraints}\\\\\n\n& \\quad   \\bm{C}_B\\big(t_0,t_F,\\bm{x}(t_0),\\bm{x}(t_F) \\big) \\leq \\bm{0}    & \\quad & \\eqnTxt{boundary constraints} \\\\\n\n& \\quad   \\bm{x}^- \\leq \\bm{x}(t) \\leq \\bm{x}^+    & \\quad & \\eqnTxt{constant bounds on state} \\\\\n& \\quad   \\bm{u}^- \\leq \\bm{u}(t) \\leq \\bm{u}^+    & \\quad & \\eqnTxt{constant bounds on control} \\\\\n\n& \\quad   t^- \\leq t_0 < t_F \\leq t^+    & \\quad & \\eqnTxt{bounds on initial and final time} \\\\\n& \\quad   \\bm{x}_0^- \\leq \\bm{x}(t_0) \\leq  \\bm{x}_0^+   & \\quad & \\eqnTxt{bound on initial state} \\\\\n& \\quad   \\bm{x}_F^- \\leq \\bm{x}(t_F) \\leq \\bm{x}_F^+    & \\quad & \\eqnTxt{bound on final state}\n\\end{align*}\n\nAssuming that the user-defined objective, dynamics, and constraint functions ($J_P$, $J_B$, $\\bm{f}$, $\\bm{C}_P$, $\\bm{C}_B$) are smooth. The user must provide an initial guess for the decision variables $t_0$, $t_F$, $\\bm{x}(t)$, and $\\bm{u}(t)$, and ensure that a feasible solution exists.\n\n\\subsection{Trapezoidal Direct Collocation:  \\hc{trapezoid}}\n\nTrapezoidal direct collocation works by making the assumption that the optimal trajectory can be approximated using a low-order spline. In this case, the dynamics, objective function, and control trajectories are approximated using a linear spline, and the state trajectory is the quadratic spline, obtained by integration of the (linear) dynamics spline. Integration of a linear spline is computed using the trapezoid rule, hence the name. The implementation of trapezoidal direct collocation in OptimTraj is almost entirely based on the method as it is described in \\cite{Betts2010}.\n\n\\subsection{Hermite-Simpson Direct Collocation:  \\hc{hermiteSimpson}}\n\nHermite-Simpson direct collocation works by making the assumption that the optimal trajectory can be approximated using a medium-order spline. In this case, the dynamics, objective function, and control trajectories are approximated using a quadratic spline, and the state trajectory is a cubic hermite spline, obtained by integration of the (quadratic) dynamics spline. Integration of a quadratic spline is computed using Simpson's rule. There are two versions of this method: separated and compressed. In the separated form, the state at the mid-point of each trajectory segment is included as a decision variable, and the Hermite-interpolation is enforced with a constraint. In the compressed form, the state at the mid-point is computed from the definition of the Hermite-interpolant during optimization. OptimTraj implements the separated Hermite-Simpson method, almost entirely based on the method as it is described in \\cite{Betts2010}.\n\n\\subsection{Chebyshev--Lobatto Orthogonal Collocation:  \\hc{chebyshev}}\n\nChebyshev--Lobatto orthogonal collocation works by representing the entire trajectory using a high-order Chebyshev orthogonal polynomial. The implementation here might also be called pseudospectral or global collocation, since the entire trajectory is represented using a single segment, rather than several segments. Orthogonal collocation methods can be divided into three categories: Gauss, Radau, and Lobatto. In a Gauss method, neither end-point of a segment is a collocation point, in a Radau method, a single end-point of the segment is a collocation point, and in a Lobatto method, both end-points are collocation points \\cite{Garg2010}.\n\n\\par The implementation here uses the ChebFun toolbox \\cite{Driscoll2014} for computing the Chebyshev--Lobatto collocation points, and also for interpolation of the solution. More details regarding orthogonal polynomials and calculations with them can be found in \\cite{Berrut2004a} and \\cite{Trefethen2012}. The details of the collocation method itself are largely drawn from \\cite{Vlassenbroeck1988}.\n\n\\subsection{Runge--Kutta $4^\\text{th}$-order Multiple Shooting:  \\hc{rungeKutta}}\n\nA multiple shooting method works by breaking the trajectory into segments, and approximating each segment using an explicit simulation. In this case, we use a $4^\\text{th}$-order Runge--Kutta method for the simulation. A defect constraint is used to ensure that the end of each trajectory segment correctly lines up with the next. The interpolation of the solution trajectory, for both control and state, is approximated using a cubic Hermite spline. The implementation here, except for interpolation, is as described in \\cite{Betts2010}.\n\n\\subsection{GPOPS-II:    \\hc{gpops}}\n\nOptimTraj includes a wrapper to the software GPOPS-II \\cite{Patterson2013}, a professionally developed trajectory optimization library for Matlab. It implements a nicely optimized version of Radau orthogonal collocation with adaptive meshing \\cite{Darby2011a}. There are a few choice in GPOPS-II for both collocation metho and the adaptive meshing. It also supports analytic gradients using automatic differentiation. It is included in OptimTraj for two reasons: 1) GPOPS-II can be used to benchmark and verify the methods in OptimTraj, and 2) GPOPS-II provides a collection of methods that are not otherwise available in OptimTraj.\n\n\\subsection{Resources for Learning Trajectory Optimization}\n\nThe single best resource for learning about trajectory optimization is the textbook by John T. Betts: \"Practical Methods for Optimal Control and Estimation Using Nonlinear Programming\" \\cite{Betts2010}. The textbook by Bryson and Ho: \"Applied Optimal Control\" \\cite{Bryson1975}. Both of these books are also excellent for learning about nonlinear programming and optimization.\\\\\n\n\\par There are two good review papers about trajectory optimization. The paper by Betts \\cite{Betts1998} is more focused on direct collocation and shooting methods, while the paper by Rao \\cite{Rao2009} is more focused on orthogonal collocation methods.\\\\\n\n\\par Understanding orthogonal collocation is rather challenging, and I found that it was first necessary to get a solid understanding of orthogonal polynomials and function approximation. I started by reading \"Approximation Theory and Approximation Practice\" \\cite{Trefethen2012} by Trefethen, and then his paper on barycentric interpolation \\cite{Berrut2004a}. Some intuition can also be obtained by reading the source code of ChebFun \\cite{Driscoll2014}: \\\\\n\\url{http://www.chebfun.org/}\\\\\n\n\\par Russ Tedrake at MIT has also provided some excellent resources for learning about trajectory optimization, and robotics in general. The first is his online course on underactuated robotics. You can download the pdf of the course notes \\cite{Tedrake2009}, or access the full course and video lectures at: \\\\\n\\href{http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-832-underactuated-robotics-spring-2009/index.htm}{http://ocw.mit.edu/courses/} \\\\\n\nSecond, his group at MIT are producing a planning, control, and analysis toolbox called Drake, which includes trajectory optimization. It is open source, so it is another good place to read the source code and figure out how it works: \\\\\n\\url{https://github.com/RobotLocomotion/drake}\\\\\n\n\\par I wrote a tutorial paper for learning trajectory optimization. It goes into depth covering all technical content for the two direct collocation methods in this library, as well as a variety of related topics:\n\\url{https://epubs.siam.org/doi/pdf/10.1137/16M1062569}\n\n\n\\par There is also a tutorial page on my website. It contains a high-level summary and links to a variety of other resources including a video, slides, documents, and code samples: \\\\\n\\url{http://www.matthewpeterkelly.com/tutorials/trajectoryOptimization/index.html}\n", "meta": {"hexsha": "9b4e146e4643a307c6ab9e4d1ea09a74ebb7da0f", "size": 8106, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/UsersGuide/tex/technicalDetails.tex", "max_stars_repo_name": "wwehner/OptimTraj", "max_stars_repo_head_hexsha": "5888f87051c7a8fc6b59a2521025f397e012e514", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 336, "max_stars_repo_stars_event_min_datetime": "2016-08-08T16:39:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T13:17:04.000Z", "max_issues_repo_path": "docs/UsersGuide/tex/technicalDetails.tex", "max_issues_repo_name": "wwehner/OptimTraj", "max_issues_repo_head_hexsha": "5888f87051c7a8fc6b59a2521025f397e012e514", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 41, "max_issues_repo_issues_event_min_datetime": "2016-05-25T18:54:07.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-23T01:40:32.000Z", "max_forks_repo_path": "docs/UsersGuide/tex/technicalDetails.tex", "max_forks_repo_name": "wwehner/OptimTraj", "max_forks_repo_head_hexsha": "5888f87051c7a8fc6b59a2521025f397e012e514", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 147, "max_forks_repo_forks_event_min_datetime": "2016-09-30T18:19:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T02:01:55.000Z", "avg_line_length": 106.6578947368, "max_line_length": 943, "alphanum_fraction": 0.7707870713, "num_tokens": 2135, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213853793453, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7550227647573429}}
{"text": "\\lab{CVXPY}{CVXPY}\n\\objective{CVXPY 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 CVXPY and optimize eating healthily on a budget.}\n\n\\section*{Linear Programs} % ==================================================\n\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}$.\nIn other words, if $\\x\\preceq\\y$, then $x_i < y_i$ for all $x_i\\in\\x$ and $y_i\\in\\y$. \nCVXPY accepts  $\\leq, \\geq$, and $=$ in its constraints as long as the equations satisfy convexity requirements described later in this chapter, so we can reformulate this problem in yet another form:\n\\begin{align*}\n\\text{minimize}\\qquad &\\c\\trp \\x \\\\\n\\text{subject to}\\qquad &G\\x \\preceq \\mathbf{h}\\\\\n&P\\x \\succeq \\mathbf{q}\\\\\n&A\\x = \\b.\n\\end{align*}\nCVXPY accepts NumPy arrays and SciPy sparse matrices for the constraints, but the variable $\\x$ must be a CVXPY \\li{Variable}.\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*}\nWe can solve this problem using the following code.\nNote that \\li{cvxpy.Problem()} accepts the constraints as a single list and that \\li{>=} represents both standard and elementwise greater than or equal to.\nThe symbols \\li{<=} and \\li{==} are similarly versatile.\n\n\\begin{lstlisting}\n>>> import cvxpy as cp\n>>> import numpy as np\n\n#First we'll initialize the objective\n#We can declare x with its size and sign\n>>> x = cp.Variable(2, nonneg = True)\t\n>>> c = np.array([-4, -5])\n>>> objective = cp.Minimize(c.T @ x)\n\n#Then we'll write the constraints\n>>> A = np.array([2, 1])\n>>> G = np.array([1, 2])\n>>> P = np.eye(2)\n>>> constraints = [A @ x == 3, G @ x <= 3, P @ x >= 0] #This must be a list\n\n#Assemble the problem and then solve it\n>>> problem = cp.Problem(objective, constraints)\n>>> print(problem.solve())\n-8.999999999850528\n>>> print(x.value)\narray([1., 1.])\n\\end{lstlisting}\n%CVXPY can take in == or >= or <= so I deleted an irrelevant section here about switching constraint types\n\n%CVXPY Install Problem\n\\begin{warn}\n\tIf you are having trouble with \\li{pip install cvxpy} or \\li{conda install cvxpy} check the following:\n\t\\begin{itemize}\n\t\t\\item CVXPY requires a C++ compiler, most MacOs ad Linux Systems have them built in. \n\t\tIf you are running Windows, make sure that you have the \"C++ builder tools\" from the Visual Studio Build Tools installed.\n\t\t\\item CVXPY requires specific versions of packages in order to run, check that you have the right version of your packages. \n\t\tThe most common is NumPy is not up to date.\n\t\\end{itemize}\n\\end{warn}\n\n%Problem 1\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 \\leq 3 \\\\\n\t\t&x_2-4x_3\\leq 1\\\\\n\t        &2x_1+10x_2+3x_3 \\geq 12 \\\\\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\\end{problem}\n\\pagebreak\n\\subsection*{$l_1$ Norm}\nThe $l_1$ norm is defined \n\\[||\\x||_1=\\sum_{i=1}^n |x_i|.\\]\nAn $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\nCVXPY includes the $l_1$ norm and many other useful functions.\nTo specify a norm in CVXPY, use the syntax \\li{cp.norm(x, a)} where $a$ represents your choice of norm (1 in this case).\n%Removed a big section here about how to modify CVXOPT to do the L1 norm. It's significantly trickier than with CVXPY.\n\n%Problem 2\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.\n\nTo test your function consider the matrix $A$ and vector $\\mathbf{b}$ below.\n\\[\nA = \\begin{bmatrix}\n1 & 2 & 1 & 1\\\\\n0 & 3 & -2 & -1\n\\end{bmatrix} \\qquad\n\\mathbf{b} = \\begin{bmatrix}\n7 \\\\\n4\n\\end{bmatrix}\n\\]\nThe linear system $A\\x = \\b$ has infinitely many solutions.\nUse \\li{l1Min()} to verify that the solution which minimizes $||\\mathbf{x}||_1$ is approximately $\\x = [0., 2.571, 1.857, 0.]^T$ and the minimum objective value is approximately $4.429$.\n\\label{prob:l1}\n\\end{problem}\n\n\\section*{The Transportation Problem}\n\nConsider the following transportation problem:\nA piano company needs to transport thirteen pianos from their three  supply centers (denoted by 1, 2, 3) to two demand centers (4, 5).\nTransporting a piano from a supply center to a demand center incurs a cost, listed in Table \\ref{tab:cost}.\nThe company wants to minimize shipping costs for the pianos while meeting the demand.\n%How many pianos should each supply center send to each demand center?\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|}\nSupply Center & Number of pianos available\\\\\n\\hline\n1 & 7\\\\\n2 & 2\\\\\n3 & 4\\\\\n\\end{tabular}\n\n\\caption{Number of pianos available at each supply center}\n\\label{tab:supply}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|}\nDemand Center & Number of pianos needed\\\\\n\\hline\n4 & 5\\\\\n5 & 8\\\\\n\\end{tabular}\n\n\\caption{Number of pianos needed at each demand center}\n\\label{tab:demand}\n\\end{table}\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{|c|c|c|c|}\nSupply Center & Demand Center & Cost of transportation & Number of pianos\\\\\n\\hline\n1 & 4 & 4 & $p_1$\\\\\n1 & 5 & 7 & $p_2$\\\\\n2 & 4 & 6 & $p_3$\\\\\n2 & 5 & 8 & $p_4$\\\\\n3 & 4 & 8 & $p_5$\\\\\n3 & 5 & 9 & $p_6$\\\\\n\\end{tabular}\n\\caption{Cost of transporting one piano from a supply center to a demand center}\n\\label{tab:cost}\n\\end{table}\n\nA system of constraints can be defined using the variables $p_1,p_2,p_3,p_4,p_5,$ and $p_6$.\nFirst, there cannot be a negative number of pianos transported along any route.\nNext, use tables \\ref{tab:supply} and \\ref{tab:demand} and the variables $p_1...p_6$ to define a supply or demand constraint for each location.\nYou may want to format this as a matrix.\n\\begin{comment} %I think they can come up with these on their own.\nthe 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\\end{comment}\nFinally, the objective function is the number of pianos shipped along each route multiplied by the respective costs (Table \\ref{tab:cost}).\n%\\[\n%4p_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\n%Problem 3. The point was originally to change equality constraints to inequality, but that's not necessary with CVXPY, so now it's mostly about interpreting the tables.\n\\begin{problem}\nSolve the piano 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\\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.\n%In 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 CVXPY function for quadratic programming, \\li{cp.quad_form()}.\n\\begin{lstlisting}\n>>> Q = np.array([[4, 2],[2, 2]])\n>>> r = np.array([1, -1])\n>>> x = cp.Variable(2)\n>>> prob = cp.Problem(cp.Minimize(.5 * cp.quad_form(x, Q) + r.T @ x))\n>>> print(prob.solve())\n[-1. 1.5]\n>>> print(x.value)\n-1.25\n\\end{lstlisting}\n\n%Problem 4\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\nSo far we have only dealt with affine constraints.\nWhen working with non-affine constraints, be aware that CVXPY comes with some Disciplined Convex Programming (DCP) rules.\nA minimization problem requires a convex objective function; similarly, a maximization problem requires a concave objective function.\nEquality constraints (\\li{==}) must be affine.\nLess-than constraints (\\li{<=}) must have the left side convex and the right side concave.\nGreater-than constraints (\\li{>=}) must have the left side concave and the right side convex.\nThis webpage provides a list of which of CVXPY's functions are concave or convex.\n\\url{https://www.cvxpy.org/tutorial/functions/index.html}\n\n%Problem 5\n\\begin{problem}\nWrite a function that accepts  a matrix $A$ and vector $\\b$ and solves the following problem.\n\\begin{align*}\n\\text{minimize}\\qquad &\\|A\\x - \\b\\|_2\\\\\n\\text{subject to}\\qquad &\\|\\x\\|_1 = 1\\\\\n\t\t&\\x \\succeq 0\\\\\n\\end{align*}\nTo test your function, use the matrix $A$ and vector $\\b$ from Problem \\ref{prob:l1}. \nThe minimizer is approximately $\\x=[0, 1, 0, 0]$ with objective value $5.099$.\nHint: \\li{norm()} is a convex function, so you will have to think of a different way to take the 1-norm.\n\\end{problem}\n\\begin{comment}\n\\begin{problem} %Given that CVXPY comes with built-in norm functions, this feels too easy or maybe out of place.\nThe $l_2$ maximization problem is to\n\\begin{align*}\n\\text{maximize}\\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$ maximization problem.\nReturn the maximizer $\\x$ and the primal objective value.\n\nTo test your function, use the matrix $A$ and vector $\\b$ from Problem \\ref{prob:l1}. \nThe minimizer is approximately $\\x=[0.966, 2.169, 0.809, 0.888]^T$ and the minimum primal objective value is approximately $7.079$.\n\\end{problem}\n\\end{comment}\n\\begin{comment}\n\\section*{Allocation Models}\nAllocation models lead to simple linear programs. An allocation model seeks to allocate a valuable resource among competing needs. Consider the following example taken from ``Optimization in Operations Research\" by Ronald L. Rardin. %%pg 132\n\nThe U.S. Forest service has used an allocation model to deal with the task of managing national forests.\nThe model begins by dividing the land into a set of analysis areas. Several land management policies (also\ncalled prescriptions) are then proposed and evaluated for each area.\nAn \\emph{allocation} is how much land (in acreage) in each unique analysis area will be assigned to each of the possible prescriptions.\nWe seek to find the best possible allocation, subject to forest-wide restrictions on land use.\n\nThe file \\li{ForestData.npy} contains data for a fictional national forest (you can also find the data\nin Table \\ref{tab:forest}). There are 7 areas of analysis and 3 prescriptions for each of them.\n\n\\begin{align*}\n&\\text{Column 1: $i$, area of analysis} \\\\\n&\\text{Column 2: $s_i$, size of the analysis area (in thousands of acres)} \\\\\n&\\text{Column 3: $j$, prescription number} \\\\\n&\\text{Column 4: $p_{i,j}$, net present value (NPV) per acre in area $i$ under prescription $j$} \\\\\n&\\text{Column 5: $t_{i,j}$, protected timber yield per acre in area $i$ under prescription $j$} \\\\\n&\\text{Column 6: $g_{i,j}$, protected animal grazing capability per acre for area $i$ under prescription $j$} \\\\\n&\\text{Column 7: $w_{i,j}$, wilderness index rating (0 to 100) for area $i$ under prescription $j$}\n\\end{align*}\n\n\\begin{table}[H]\n\\centering\n    \\begin{tabular}{c c c c c c c}\n&&&Forest Data&&& \\\\\n\\hline\nAnalysis & Acres &Prescrip-&NPV&Timber&Grazing&Wilderness \\\\\nArea&(1000)'s &tion&(per acre) &(per acre)&(per acre)& Index\\\\\n$i$ &$s_i$&$j$& $p_{i,j}$ & $t_{i,j}$&$g_{i,j}$&$w_{i,j}$ \\\\\\hline\n1&\t75\t&1\t&503\t&310\t&0.01&\t40\\\\\n&&\t\t2&\t140&\t50&\t0.04\t&80\\\\\n&&\t\t3&\t203&\t0&\t0&\t95\\\\ \\hline\n2&\t90&\t1\t&675&\t198&\t0.03&\t55\\\\\n&&\t\t2&\t100&\t46&\t0.06&\t60\\\\\n&&\t\t3&\t45&\t0&\t0&\t65\\\\ \\hline\n3&\t140&\t1\t&630&\t210\t&0.04&\t45\\\\\n&&\t\t2&\t105&\t57&\t0.07&\t55\\\\\n&&\t\t3&\t40\t&0&\t0&\t60\\\\ \\hline\n4\t&60&\t1&\t330&\t112&\t0.01&\t30\\\\\n&&\t\t2\t&40&\t30&\t0.02&\t35\\\\\n&&\t\t3&\t295&\t0&\t0\t&90\\\\ \\hline\n5\t&212&\t1\t&105\t&40\t&0.05&\t60\\\\\n&&\t\t2\t&460&\t32\t&0.08&\t60\\\\\n&& 3\t&120&0&\t0\t&70\\\\ \\hline\n6\t&98\t&1\t&490\t&105\t&0.02\t&35\\\\\n&&\t\t2&\t55\t&25\t&0.03\t&50\\\\\n&&\t\t3\t&180\t&0\t&0\t&75\\\\ \\hline\n7&\t113&\t1\t&705\t&213&\t0.02\t&40\\\\\n&&\t\t2&\t60\t&40\t&0.04&\t45\\\\\n&&\t\t3\t&400\t&0\t&0\t&95\\\\\n\\hline\n    \\end{tabular}\n\\caption{}\n\\label{tab:forest}\n\\end{table}\nLet $x_{i,j}$ be the amount of land in area $i$ allocated to prescription $j$.\nUnder this notation, an allocation is a one-dimensional vector consisting of the $x_{i,j}$'s. \nFor this particular\nexample, there are 7 acres, with 3 prescriptions each.\nSo the allocation vector is a one-dimensional vector with 21 entries.\nOur goal is to find the allocation vector that maximizes net present value, while producing at least 40 million\nboard-feet of timber, at least 5 thousand units of grazing capability, and keeping the average wilderness index at least 70.\nThe allocation vector is also constrained to be nonnegative, and all of the land must be allocated precisely.\n\nSince acres are in thousands, divide the constraints of timber and animal grazing by 1000 in the problem setup, and compensate for this after obtaining a solution.\n\nThe problem can be written as follows:\n\\begin{align*}\n\\text{maximize } &\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 p_{i,j}x_{i,j} \\\\\n\\text{subject to } &\\sum\\limits_{j=1}^3 x_{i,j} = s_i  \\text{ for } i=1,..,7 \\\\\n\t        &\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 t_{i,j}x_{i,j} \\geq 40,000 \\\\\n\t\t&\\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 g_{i,j}x_{i,j} \\geq 5 \\\\\n\t\t&\\frac{1}{788} \\sum\\limits_{i=1}^7 \\sum\\limits_{j=1}^3 w_{i,j}x_{i,j} \\geq 70 \\\\\n\t\t&x_{i,j} \\geq 0 \\text{ for } i=1,...,7  \\text{ and } j=1,2,3\n\\end{align*}\n\n\\begin{problem}\nSolve the allocation problem above.\nReturn the minimizing allocation vector of $x_{i,j}$'s and the maximum total net present value.\nRemember to consider the following:\n\\begin{enumerate}\n\\item The allocation vector should be a (21,1) NumPy array.\n\\item Recall that the constraints of timber and animal grazing were divided by 1000.\nTo compensate, the maximum total net value will be equal to the primal objective of the appropriately minimized linear function multiplied by -1000.\n\\end{enumerate}\n\\end{problem}\n\n\\end{comment}\n\n\\section*{Eating on a Budget}\n\nIn 2009, the inmates of Morgan County jail convinced Judge Clemon of the Federal District Court in Birmingham to put Sheriff Barlett in jail for malnutrition.\nUnder Alabama law, in order to encourage less spending, \"the chief lawman could go light on prisoners' meals and pocket the leftover change.\"\\footnote[1]{Nossiter, Adam, 8 Jan 2009, \"As His Inmates Grew Thinner, a Sheriff’s Wallet Grew Fatter\", \\emph{New York Times},\\url{https://www.nytimes.com/2009/01/09/us/09sheriff.html}}.\nSheriffs had to ensure a minimum amount of nutrition for inmates, but minimizing costs meant more money for the sheriffs themselves.\nJudge Clemon jailed Sheriff Barlett until a plan was made to use all allotted funds, \\$1.75 per inmate, to feed prisoners more nutritious meals.\nWhile this case made national news, the controversy of feeding prisoners in Alabama continues as of 2019\\footnote[2]{Sheets, Connor, 31 January 2019, \"Alabama sheriffs urge lawmakers to get them out of the jail food business\", \\url{https://www.al.com/news/2019/01/alabama-sheriffs-urge-lawmakers-to-get-them-out-of-the-jail-food-business.html}}.\n\nThe problem of minimizing cost while reaching healthy nutritional requirements can be approached as a convex optimization problem.\nRather than viewing this problem from the sheriff's perspective, we view it from the perspective of a college student trying to minimize food cost in order to pay for higher education, all while meeting standard nutritional guidelines.\n\nThe file \\li{food.npy} contains a dataset with nutritional facts for 18 foods that have been eaten frequently by college students working on this text.\nA subset of this dataset can be found in Table \\ref{tab:food-data}, where the \"Food\" column contains the list of all 18 foods.\n\nThe columns of the full dataset are:\n\\begin{align*}\n& \\text{Column 1: $p$, price (dollars)} \\\\\n& \\text{Column 2: $s$, servings per container} \\\\\n& \\text{Column 3: $c$, calories per serving} \\\\\n& \\text{Column 4: $f$, fat per serving (grams)} \\\\\n& \\text{Column 5: $\\hat{s}$, sugar per serving (grams)} \\\\\n& \\text{Column 6: $\\hat{c}$, calcium per serving (milligrams)} \\\\\n& \\text{Column 7: $\\hat{f}$, fiber per serving (grams)} \\\\\n& \\text{Column 8: $\\hat{p}$, protein per serving (grams)}\n\\end{align*}\n\n\n \\begin{table}[H]\n% \\begin{adjustwidth}{-.5in}{-.5in}\n\\begin{tabular}{|c||c|c|c|c|c|c|c|c|c|c|}\n\\hline\n\\textbf{Food} & \\textbf{Price} & \\textbf{Servings} & \\textbf{Calories} & \\textbf{Fat} & \\textbf{Sugar} & \\textbf{Calcium} & \\textbf{Fiber} & \\textbf{Protein} \\\\ \n& $p$ & $s$ & $c$ & $f$ & $\\hat{s}$ & $\\hat{c}$ & $\\hat{f}$ & $\\hat{p}$ \\\\ \n& dollars & & & g & g & mg & g & g \\\\ \\hline\\hline\nRamen & 6.88 & 48 & 190 & 7 & 0 & 0 & 0 & 5 \\\\ \\hline\nPotatoes & 0.48 & 1 & 290 & 0.4 & 3.2 & 53.8 & 6.9 & 7.9 \\\\ \\hline\nMilk & 1.79 & 16 & 130 & 5 & 12 & 250 & 0 & 8 \\\\ \\hline\nEggs & 1.32 & 12 & 70 & 5 & 0 & 28 & 0 & 6 \\\\ \\hline\nPasta & 3.88 & 8 & 200 & 1 & 2 & 0 & 2 & 7 \\\\ \\hline\nFrozen Pizza & 2.78 & 5 & 350 & 11 & 5 & 150 & 2 & 14 \\\\ \\hline\nPotato Chips & 2.12 & 14 & 160 & 11 & 1 & 0 & 1 & 1 \\\\ \\hline\nFrozen Broccoli & 0.98 & 4 & 25 & 0 & 1 & 25 & 2 & 1 \\\\ \\hline\nCarrots & 0.98 & 2 & 52.5 & 0.3 & 6.1 & 42.2 & 3.6 & 1.2 \\\\ \\hline\nBananas & 0.24 & 1 & 105 & 0.4 & 14.4 & 5.9 & 3.1 & 1.3 \\\\ \\hline\nTortillas & 3.48 & 18 & 140 & 4 & 0 & 0 & 0 & 3 \\\\ \\hline\nCheese & 1.88 & 8 & 110 & 8 & 0 & 191 & 0 & 6 \\\\ \\hline\nYogurt & 3.47 & 5 & 90 & 0 & 7 & 190 & 0 & 17 \\\\ \\hline\nBread & 1.28 & 6 & 120 & 2 & 2 & 60 & 0.01 & 4 \\\\ \\hline\nChicken & 9.76 & 20 & 110 & 3 & 0 & 0 & 0 & 20 \\\\ \\hline\nRice & 8.43 & 40 & 205 & 0.4 & 0.1 & 15.8 & 0.6 & 4.2 \\\\ \\hline\nPasta Sauce & 3.57 & 15 & 60 & 1.5 & 7 & 20 & 2 & 2 \\\\ \\hline\nLettuce & 1.78 & 6 & 8 & 0.1 & 0.6 & 15.5 & 1 & 0.6 \\\\ \\hline\n\\end{tabular}\n\\caption{Subset of table containing food data}\n\\label{tab:food-data}\n% \\end{adjustwidth}\n\\end{table}\n\n According to the FDA\\footnote[1]{url{https://www.accessdata.fda.gov/scripts/InteractiveNutritionFactsLabel/pdv.html}} and US Department of Health, someone on a $2000$ calorie diet should have no more than 2000 calories, no more than 65 grams of fat, no more than 50 grams of sugar\\footnote[2]{https://www.today.com/health/4-rules-added-sugars-how-calculate-your-daily-limit-t34731}, at least 1000 milligrams of calcium\\footnote[1]{26 Sept 2018, \\url{https://ods.od.nih.gov/factsheets/Calcium-HealthProfessional/}}, at least 25 grams of fiber, and at least 46 grams of protein\\footnote[2]{\\url{https://www.accessdata.fda.gov/scripts/InteractiveNutritionFactsLabel/protein.html}} per day.\n\n We can rewrite this as a convex optimization problem below.\n\n \\begin{align*}\n\\text{minimize } & \\sum_{i=1}^{18}p_ix_i, \\\\\n\\text{subject to }& \\sum_{i=1}^{18} c_ix_i \\leq 2000, \\\\\n\t\t\t& \\sum_{i=1}^{18} f_ix_i \\leq 65, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{s}_ix_i \\leq 50, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{c}_ix_i \\geq 1000, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{f}_ix_i \\geq 25, \\\\\n\t\t\t& \\sum_{i=1}^{18} \\hat{p}_ix_i \\geq 46, \\\\\n\t\t\t& x_i \\geq 0.\n\\end{align*}\n\n%Problem 6\n \\begin{problem}\nRead in the file \\li{food.npy}.\nUse CVXPY to identify how much of each food item a college student should each to minimize cost spent each day given these simplified nutrition requirements.\nReturn the minimizing vector and the total amount of money spent.\n\nAccording to this problem, what is the food you should eat most each day? \nWhat are the three foods you should eat most each week?\n\n(Hint: Each nutritional value must be multiplied by the number of servings to get the nutrition value of the whole product).\n\\label{prob:diet}\n\\end{problem}\n\nYou can learn more about CVXPY at\n\\url{https://www.cvxpy.org/index.html}.\n", "meta": {"hexsha": "3fcb4b7434f39da3221fe9cc8da3f1740ee4a7e4", "size": 22850, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume2/CVXPY_Intro/CVXPY_Intro.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/CVXPY_Intro/CVXPY_Intro.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/CVXPY_Intro/CVXPY_Intro.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": 41.8498168498, "max_line_length": 687, "alphanum_fraction": 0.6925601751, "num_tokens": 7806, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898153067649, "lm_q2_score": 0.8333245953120234, "lm_q1q2_score": 0.7549835961973247}}
{"text": "\\chapter{Bayesian Monte Carlo}\nConsider the integral\n\\begin{equation}\\label{integralbmc}\nZ = \\int_{\\mathbb{R}^D} f(x) p(x) dx.\n\\end{equation}\nIn the following discussion, we drop  $\\mathbb{R}^D$ from the integral symbol, for simplicity. If $p(x)$ is a distribution whose sampling is easy, the bottleneck for a simple Monte Carlo method for estimating $Z$ would be the evaluation cost of $f$. If evaluating $f$ is costly then, a naive Monte Carlo method often becomes infeasible. In this section, we present a GP-based method that tries to circumvent this bottleneck. \n\n\\section{GP approximation for the integrand}\nIn Bayesian Monte Carlo (BMC), or Bayesian quadrature \\cite{Ghahramani_2003,O_Hagan_1991} \\footnote{The original name Bayesian quadrature describes more accurately the method, however the name Bayesian Monte Carlo will be used in this text. At the literature, both names can be found in roughly equal proportion}, $f$ itself is treated as a random function, and a GP prior $GP(m,k)$ is put on $f$. Therefore, given a set $\\mathcal{D} = \\{(x_i,f(x_i))\\}_{i=1}^N$ of $N$ evaluations, the posterior random function $f_{\\mathcal{D}}$ is also distributed according to a GP. In particular, since linear maps of GPs are themselves GPs \\cite{Rasmussen06,Hennig_2012}, this implies that the random variable\n\\begin{equation}\\label{bmcrv}\nZ_{\\mathcal{D}} = \\int f_{\\mathcal{D}}(x) p(x) dx\n\\end{equation}\nis a Gaussian random variable. Since we can find the mean by \n\\begin{equation}\\label{evbmc}\n\\begin{split}\n\\Ev[Z_{\\mathcal{D}}] = \\Ev \\left[\\int f_{\\mathcal{D}}(x) p(x) dx \\right] = \\int \\Ev[f_{\\mathcal{D}}(x)] p(x) dx,\n\\end{split}\n\\end{equation}\nand the variance by,\n\\begin{equation}\\label{varbmc}\n\\begin{split}\n\\Var(Z_{\\mathcal{D}}) & = \\Ev[(Z_{\\mathcal{D}} - \\Ev[Z_{\\mathcal{D}}])^2] \\\\\n& = \\Ev \\left[\\left( \\int (f_{\\mathcal{D}}(x) - \\Ev[f_{\\mathcal{D}}(x)]) p(x) dx \\right)^2 \\right] \\\\\n& = \\int \\int \\Ev \\left[(f_{\\mathcal{D}}(x) - \\Ev[f_{\\mathcal{D}}(x)]) (f_{\\mathcal{D}}(x') - \\Ev[f_{\\mathcal{D}}(x')]) \\right]  p(x) p(x') dx dx' \\\\\n& = \\int \\int \\Cov(f_{\\mathcal{D}}(x),f_{\\mathcal{D}}(x')) p(x) p(x') dx dx'.\n\\end{split}\n\\end{equation}\nWe have a complete description of the distribution of $Z_\\mathcal{D}$. Now, by substituting \\eqref{meancovGPR} in \\eqref{evbmc} and \\eqref{varbmc}, we have \n\\begin{equation}\\label{evvarbmc2}\n\\begin{split}\n& \\Ev[Z_{\\mathcal{D}}] = \\int m(x) p(x) dx - \\mathbf{z}^T K^{-1} (\\mathbf{f}-m(\\mathbf{x})) \\\\\n& \\Var[Z_{\\mathcal{D}}] = \\Gamma - \\mathbf{z}^T K^{-1} \\mathbf{z},\n\\end{split}\n\\end{equation}\nwhere $\\mathbf{z} = (z_1,...,z_N)^T$, with\n\\begin{equation}\\label{zbmcdef}\nz_i = \\int k(x,x_i) p(x) dx,\n\\end{equation}\nand \n\\begin{equation}\\label{varcoef}\n\\Gamma = \\int \\int k(x,x') p(x) p(x') dx dx'.\n\\end{equation}\nIn general, a good estimate of $Z_\\mathcal{D}$ is its mean, although if there is an asymmetric loss function associated with estimating $Z_\\mathcal{D}$, its variance should be taken in account.\n\nAn illustration of the Bayesian Monte Carlo approach to integration is shown in Figure \\ref{bmcfig}. There, the distribution is $p(x) = \\mathcal{N}(x|0,0.5)$, and $f(x) = -x^2$. The true value of the integral, and BMC estimation are shown. Notice that, in this example, for $|x|>2$ the GP estimate $m_\\mathcal{D}(x)$ of $f(x)$ becomes very inaccurate. However, since low probability mass is assigned outside the interval, the BMC estimation is still close to the target.\n\n\\begin{figure}\n\t\\centering\n\t\\includegraphics[width=0.7\\linewidth]{figs/exbmc.png}\n\t\\caption[Illustration of Bayesian Monte Carlo integration]{\\label{bmcfig} Illustration of Bayesian Monte Carlo integration. Here, dash-dot black is $f(x)$, whose value is on the left-axis, while in blue is it's GP mean (dark), and covariance (light), given 5 evaluations (blue circles). In red is $p(x)$, whose value is on the right axis. The true value of the integral, the BMC mean and variance are shown on the top right.}\n\\end{figure}\n\n\\subsection{Philosophical remark}\nAt first one may find strange to consider $f$ as a random function, in order to give a prior for it. After all, $f$ is a known, fixed function. However, notice that $f$ is only actually known in so far as one can evaluate it, and if evaluations for $f$ are limited, so is the knowledge of it. And by the discussion in Chapter 1, any object the learner has limited knowledge about should be considered a random variable, independent of the fact that the object is actually random or not.\n\nIf this philosophical approach is not convincing, maybe it is better to just think of the BMC method as an artificial way to integrate functions, and follow the famous dictum in quantum mechanics: \"Shut up and calculate\" \\cite{Mermin_2004}.\n\n\n\\section{Kernel-distribution combinations}\\label{kerneldistributionbmc}\nIn general, neither \\eqref{zbmcdef} nor \\eqref{varcoef} are analytically available, just like the original integral \\eqref{integralbmc}. However, evaluating the kernel function is in general cheap, so if evaluation of $f$ is expensive, there may be still computational gains in using BMC. For some particular distributions $p(x)$, combined with some suitable kernel choices, \\eqref{zbmcdef} nor \\eqref{varcoef} does lend analytical solutions, or can be treated in a relatively cheap manner. In the following, $m(x) = 0$ for simplicity, thus omitting the term.\n\n\\subsection{SQE kernel with Gaussian distributions}\nAssume $p(x) = \\mathcal{N}(x|\\mu,\\Sigma)$, and $k$ is a anisotropic squared exponential kernel, with vertical scale $\\theta$ and length scales $l = (l_1,...,l_D)$. Notice then that, by letting $A := \\text{diag}(l_1^2,...,l_D^2)$, we have \n\\begin{equation} \\label{rbfasnormal}\n\\begin{split}\nk(x,x') = \\theta \\exp \\left( -\\frac{1}{2} (x - x')^T A^{-1} (x - x') \\right) = & \\det(2 \\pi A) \\mathcal{N}(x'|x,A) = \\\\\n& \\det(2 \\pi A) \\mathcal{N}(x|x',A).\n\\end{split}\n\\end{equation}\nThen, by \\eqref{productgaussians}:\n\\begin{equation} \\label{kpexpansion1}\n\\begin{split}\n& k(x,x') \\mathcal{N}(x|\\mu,\\Sigma) = C(x') \\mathcal{N}(x|\\tilde{\\mu}_{x'},\\tilde{\\Sigma}) \\\\\n& C(x') = \\frac{\\theta}{\\det(I + A^{-1} \\Sigma)^{1/2}} \\exp \\left(-\\frac{1}{2}(x' - \\mu)^T (A + \\Sigma)^{-1}(x' - \\mu) \\right) \\\\\n& \\tilde{\\mu}_{x'} = (A^{-1} + \\Sigma^{-1})^{-1} (A^{-1} x' + \\Sigma^{-1} \\mu) \\\\\n& \\tilde{\\Sigma} = (A^{-1} + \\Sigma^{-1})^{-1},\n\\end{split}\n\\end{equation}\nand\n\\begin{equation} \\label{kpexpansion2}\n\\begin{split}\n& k(x,x') \\mathcal{N}(x|\\mu,\\Sigma) \\mathcal{N}(x'|\\mu,\\Sigma) = \\hat{C} \\mathcal{N}(x|\\tilde{\\mu}_{x'},\\tilde{\\Sigma}) \\mathcal{N}(x'|\\tilde{\\mu}_{x},\\tilde{\\Sigma}) \\\\\n& \\hat{C} = \\frac{\\theta}{\\det(I + 2 A^{-1} \\Sigma)^{1/2}}.\n\\end{split}\n\\end{equation}\nHence, by substituting \\eqref{kpexpansion1} and \\eqref{kpexpansion2} into \\eqref{zbmcdef} and \\eqref{varcoef}, we find \n\\begin{equation}\\label{termsbmcgaussian}\n\\begin{split}\n& z_i = \\frac{\\theta}{\\det(I + A^{-1} \\Sigma)^{1/2}} \\exp \\left(-\\frac{1}{2}(x_i - \\mu)^T (A + \\Sigma)^{-1}(x_i' - \\mu) \\right) \\\\\n& \\Gamma = \\frac{\\theta}{\\det(I + 2 A^{-1} \\Sigma)^{1/2}}.\n\\end{split}\n\\end{equation}\nSubstituting in \\eqref{evvarbmc2} we find the desired result:\n\\begin{equation}\\label{evvarbmcgaussian}\n\\begin{split}\n& \\Ev[Z_{\\mathcal{D}}] = \\mathbf{z}^T K^{-1} \\mathbf{f} \\\\\n& \\Var[Z_{\\mathcal{D}}] = \\frac{\\theta}{\\det(I + 2 A^{-1} \\Sigma)^{1/2}} - \\mathbf{z}^T K^{-1} \\mathbf{z} \\\\\n& z_i = \\frac{\\theta}{\\det(I + A^{-1} \\Sigma)^{1/2}} \\exp \\left(-\\frac{1}{2}(x_i - \\mu)^T (A + \\Sigma)^{-1}(x_i' - \\mu) \\right) \\\\\n& \\Gamma = \\frac{\\theta}{\\det(I + 2 A^{-1} \\Sigma)^{1/2}}.\n\\end{split}\n\\end{equation}\n\n\\subsection{Mixture distributions}\\label{bmcmixtures}\nConsider taking expectations in respect to a mixture distribution\n\\begin{equation}\n p(x) = \\sum_{i=1}^M \\alpha_i p_i(x).\n\\end{equation}\nFrom \\eqref{zbmcdef} and \\eqref{varcoef}, it is straightforward to see that in this case\n\\begin{equation}\n\\begin{split}\n z_i & = \\sum_{i=1}^M \\alpha_i \\int k(x,x_i) p_i(x) dx \\\\\n \\Gamma &= \\sum_{i=1}^M \\sum_{j=1}^M \\alpha_i \\alpha_j \\int \\int k(x,x') p_i(x) p_j(x') dx dx'.\n\\end{split}\n\\end{equation}\nThen, provided it is possible to calculate the integrals above for each component $p_i(x)$, one can easily use mixture distributions from these coefficients.\n\n\nAn important case is considering mixtures of normal distributions $p(x) = \\sum_{j=1}^{M} \\alpha_j \\mathcal{N}(x|\\mu_j,\\Sigma_j)$, and the squared-exponential kernel. Then, by substituting in \\eqref{zbmcdef} and \\eqref{varcoef}, and considering the results for normal distributions in \\eqref{termsbmcgaussian}, we find \n\\begin{equation}\\label{bmcmixgaussians}\n\\begin{split}\n & z_i = \\sum_{j=1}^M \\alpha_j z_{i,j} \\\\ \n & z_{i,j} = \\frac{\\theta}{\\det(I + A^{-1} \\Sigma_j)^{1/2}} \\exp \\left(-\\frac{1}{2}(x_i - \\mu_j)^T (A + \\Sigma_j)^{-1}(x_i' - \\mu_j) \\right) \\\\\n & \\Gamma = \\sum_{j=1}^M \\sum_{m=1}^M \\alpha_j \\alpha_m \\Gamma_{j,m}, \\\\\n & \\Gamma_{j,m} = \\frac{\\theta}{\\det(I + A^{-1} (\\Sigma_j+\\Sigma_m))^{1/2}} \\exp \\left(-\\frac{1}{2}(\\mu_j-\\mu_m)^T (A + \\Sigma_j + \\Sigma_m)^{-1}(\\mu_j-\\mu_m)\\right).\n\\end{split}\n\\end{equation}\n\n\\subsection{Tensor product kernels and diagonal-covariance Gaussian distributions}\\label{tensorprodbmc}\nConsider tensor product kernels in $\\mathbb{R}^D$ of the form\n\\begin{equation}\n k(x,x') = \\prod_{d=1}^D k_d(x_d,x'_d),\n\\end{equation}\nand a Gaussian distribution $p(x) = \\mathcal{N}(x|\\mu,\\Sigma)$ with diagonal covariance $\\Sigma = \\text{diag}(\\sigma_1^2,\\ldots,\\sigma_D^{d})$, so that $p(x) = \\prod_{d=1}^D \\mathcal{N}(x_d|\\mu_d,\\sigma_d^2)$. Then, \n\\begin{equation}\\label{prodkernelz}\n\\begin{split}\n z_i & = \\int \\prod_{d=1}^D k_d(x_d,x_{i,d}) \\prod_{d=1}^D \\mathcal{N}(x_d|\\mu_d,\\sigma_d^2) dx \\\\\n & = \\prod_{d=1}^D \\int k_d(x,x_{i,d}) \\mathcal{N}(x|\\mu_d,\\sigma_d^2) dx,\n\\end{split}\n\\end{equation}\nand \n\\begin{equation}\\label{prodkernelgamma}\n\\begin{split}\n \\Gamma & = \\int \\int \\prod_{d=1}^D k_d(x_d,x'_d) \\prod_{d=1}^D \\mathcal{N}(x_d|\\mu_d,\\sigma_d^2) \\prod_{d=1}^D \\mathcal{N}(x'_d|\\mu_d,\\sigma_d^2) dx dx' = \\\\\n & = \\prod_{d=1}^D \\int \\int k_d(x,x')\\mathcal{N}(x|\\mu_d,\\sigma_d^2)\\mathcal{N}(x'|\\mu_d,\\sigma_d^2) dx dx'.\n\\end{split}\n\\end{equation}\nConsider each individual component in \\eqref{prodkernelz}. Even with none of then being analytically computable, they can easily be approximated using Gauss-Hermite quadrature, that approximates \n\\begin{equation}\\label{gausshermite}\n\\int f(x) \\mathcal{N}(x|\\mu,\\sigma^2) dx \\approx \\frac{1}{\\sqrt{\\pi}} \\sum_{k=1}^K w_k f(\\sqrt{2} \\sigma x_k + \\mu),\n\\end{equation}\nwhere $x_i$ are the roots of the physicists' Hermite polynomial\n\\begin{equation}\n H_K(x) = (-1)^N e^{x^2} \\frac{d^K}{dx^K} e^{-x^2},\n\\end{equation}\nand $w_k$ are the associated weights\n\\begin{equation}\n w_k = \\frac{2^{K-1} K! \\sqrt{\\pi}}{K^2 (H_{K-1}(x_k))^2}.\n\\end{equation}\nAn analysis of this approximation can be found in \\cite{Liu_1994}. It is important to notice that for each $K$, $\\{(x_k,w_k)\\}_{k=1}^K$ are fixed, unlike standard Monte Carlo methods that would require sampling from $\\mathcal{N}(x|\\mu,\\sigma^2)$. Applying \\eqref{gausshermite} to \\eqref{prodkernelz}, one finds that\n\\begin{equation}\n z_i \\approx \\prod_{d=1}^D \\frac{1}{\\sqrt{\\pi}}\\sum_{k=1}^K w_k k_d(\\sqrt{2} \\sigma_d x_k + \\mu_d,x_{i,d}),\n\\end{equation}\nand that\n\\begin{equation}\n\\Gamma \\approx \\prod_{d=1}^D \\frac{1}{\\pi} \\sum_{k,k'=1}^K w_k w_{k'} k_d(\\sqrt{2} \\sigma_d x_k + \\mu_d,\\sqrt{2} \\sigma_d x_{k'} + \\mu_d).\n\\end{equation}\n\nBy the discussion in section \\ref{bmcmixtures}, one can easily extend this to mixtures of Gaussians with diagonal covariance. Therefore, one is free to use more flexible kernels than the squared exponential one, provided they are tensor product kernels. The trade-off is that $p(x)$ is a more restrictive distribution, but, as discussed next, this is not an insurmountable restriction. Moreover, the techniques presented in chapters 4 and 5 uses exactly those kinds of distributions as approximations.\n\n\\subsection{Importance reweighting for Bayesian Monte Carlo}\nOne can use the above results for doing integral estimations for general distributions using squared exponential kernels, without Monte Carlo integration of kernels, by an importance re-weighting trick\n\\begin{equation}\n\\int f(x) p(x) dx = \\int \\frac{f(x) p(x)}{q(x)} q(x) dx,\n\\end{equation}\nwhere $q(x)$ may be either a normal distribution or a mixture of normals. This becomes interesting because since mixtures of normals can approximate continuous densities arbitrarily close as the number of mixtures goes to infinity \\cite{Epanechnikov_1969}, thus providing good re-weighting distributions.\n\n\n\\section{Bayesian Monte Carlo for positive integrands}\\label{positivebmc}\nFor many cases the integral we are interested is one arising from marginalization:\n\\begin{equation}\n p(\\mathcal{D}) = \\int L(x) p(x) dx = \\int p(\\mathcal{D}|x) p(x) dx.\n\\end{equation}\nIn particular, in this case $L(x)$ must be a positive function. However, applying the BMC method naively can result in rather inaccurate evaluations, due to the fact that in general, GP regression can predict negative means even when all function evaluations are positive. This way, the positivity of the GP mean for $L(x)$ is not guaranteed, resulting in possibly pathological predictions \\cite{Ghahramani_2003}.\n\nIn \\cite{Osborne_2012}, it is proposed to make a GP regression by putting an prior over $\\log L(x) \\sim GP(m,k)$. However, this means that for predictive distribution in the original space, $L(x|x_{D}) \\sim \\text{Lognormal}(m_\\mathcal{D}(x),k_\\mathcal{D}(x,x))$, which results in\n\\begin{equation}\\label{lntranswrong}\n \\Ev \\left[ \\int L(x|x_\\mathcal{D}) p(x) dx \\right] = \n \\int e^{m_\\mathcal{D}(x)+\\frac{1}{2}k_\\mathcal{D}(x,x)} p(x) dx,\n\\end{equation}\nwhich is still non-tractable integral, requiring further approximations. It is proposed in \\cite{OHagan_1992} a somehow complicated heuristic to circumvent this problem, relying in a number of approximations whose accuracy is questionable, and an inner application of BMC.\n\nIn \\cite{Gunter_2014}, the transformation used is the square-root transformation, so the prior for GP regression is over $\\tilde{L}(x) = \\sqrt{2 L(x) - \\alpha}$, with $\\alpha$ being a small positive scalar, resulting in $L(x|x_\\mathcal{D}) = \\alpha + \\frac{1}{2} \\tilde{L}(x|x_\\mathcal{D})^2$. However, this way we have $\\Ev[L(x|x_\\mathcal{D})] = \\alpha + \\frac{k_\\mathcal{D}(x,x)}{2}(1+m_\\mathcal{D}(x)^2)$, hence, just like \\eqref{lntranswrong}, we can't arrive at a tractable mean. In order to circunvent this, in \\cite{Gunter_2014} two approaches are proposed. The first is a linearization of $\\alpha + \\frac{1}{2} \\tilde{L}(x|x_\\mathcal{D})^2$ around $m_\\mathcal{D}(x)$, resulting in \n\\begin{equation}\n L(x|x_\\mathcal{D}) \\approx L^{\\mathcal{L}}(x|x_\\mathcal{D}) = \\alpha - \\frac{1}{2} m_\\mathcal{D}(x)^2 + m_\\mathcal{D}(x) \\tilde{L}(x),\n\\end{equation}\nwhich, since it is a affine transformation of $\\tilde{L}(x)$, results an approximate GP distribution for $L(\\cdot|x_\\mathcal{D})$:\n\\begin{equation}\\label{sqlinearization}\n\\begin{split}\n & L^{\\mathcal{L}}(\\cdot|x_\\mathcal{D}) \\sim GP(m_\\mathcal{D}^\\mathcal{L}(x),k_\\mathcal{D}^\\mathcal{L}(x)) \\\\\n & m_\\mathcal{D}^\\mathcal{L}(x) = \\alpha + \\frac{1}{2} m_\\mathcal{D}(x) \\\\\n & k_\\mathcal{D}^\\mathcal{L}(x,x') = m_\\mathcal{D}(x) k_\\mathcal{D}(x,x') m_\\mathcal{D}(x).\n\\end{split}\n\\end{equation}\nThe second proposal is to approximate $L(\\cdot|x_\\mathcal{D})$ by a random GP-distributed function $L^\\mathcal{M}(\\cdot|x_\\mathcal{D}) = GP(m^\\mathcal{M}_\\mathcal{D},k^\\mathcal{M}_\\mathcal{D})$, where $m^\\mathcal{M}_\\mathcal{D}(x)$ and $k^\\mathcal{M}_\\mathcal{D}(x)$ are chosen so that $L^\\mathcal{M}(\\cdot|x_\\mathcal{D})$ is moment-matched with $L(\\cdot|x_\\mathcal{D})$, that is,\n $m^\\mathcal{M}_\\mathcal{D}(x) = \\Ev[L(x|x_\\mathcal{D})]$ and $k^\\mathcal{M}_\\mathcal{D}(x,x') = \\Cov(L(x|x_\\mathcal{D}),L(x'|x_\\mathcal{D}))$. This results in the approximation\n \\begin{equation}\\label{sqmomentmatched}\n  \\begin{split}\n  & L^{\\mathcal{M}}(\\cdot|x_\\mathcal{D}) \\sim GP(m_\\mathcal{D}^\\mathcal{M}(x),k_\\mathcal{D}^\\mathcal{M}(x)) \\\\\n  & m_\\mathcal{D}^\\mathcal{M}(x) = \\alpha + \\frac{1}{2} (m_\\mathcal{D}(x) + k_\\mathcal{D}(x,x)) \\\\\n  & k_\\mathcal{D}^\\mathcal{M}(x,x') = \\frac{1}{2} k_\\mathcal{D}(x,x')^2 + m_\\mathcal{D}(x) k_\\mathcal{D}(x,x') m_\\mathcal{D}(x).\n  \\end{split}\n \\end{equation}\nIn particular, both approaches results in tractable integrals for gaussian distributions and SQE kernels.\n\nThe idea of moment-matching is extended to a general setting in \\cite{Chai_2019}, where it is considered the integral \\eqref{integralbmc}, where $f$ is now a function from $\\mathbb{R}^D$ to a strict subset $\\mathcal{Y}$ of $\\mathbb{R}$. In the case presented previously, $\\mathcal{Y} = (0,\\infty)$, while another important case is $\\mathcal{Y} = (0,1)$. Considering an bijective map $\\epsilon : \\mathbb{R} \\to \\mathcal{Y}$, it is placed a GP prior $GP(m,k)$ over $g = \\epsilon^{-1} \\circ f$. Then, the posterior distribution for $f(\\cdot|x_\\mathcal{D}$ is approximated by a moment-matched GP with mean\n$m^\\mathcal{M}_\\mathcal{D}(x) = \\Ev[\\epsilon(g(x|x_\\mathcal{D}))]$ and $k^\\mathcal{M}_\\mathcal{D}(x,x') = \n\\Cov(\\epsilon(g(x|x_\\mathcal{D})),\\epsilon(g(x'|x_\\mathcal{D})))$. In particular, for $\\epsilon^{-1}(x) = \\log(x)$, the same warping considered in \\cite{Osborne_2012}, the moment matched mean and covariance becomes \n\\begin{equation}\\label{logmomentmatched}\n\\begin{split}\n & m^\\mathcal{M}_\\mathcal{D}(x) = e^{m_\\mathcal{D}(x) + \\frac{1}{2}k_\\mathcal{D}(x,x)}\\\\\n & k^\\mathcal{M}_\\mathcal{D}(x,x') =e^{m_\\mathcal{D}(x) + \\frac{1}{2}k_\\mathcal{D}(x,x)} e^{m_\\mathcal{D}(x') + \\frac{1}{2}k_\\mathcal{D}(x',x')} \\left(e^{k_\\mathcal{D}(x,x')}-1\\right).\n\\end{split}\n\\end{equation}\n\nHowever, when integrated this GP does not result in a integrable mean or variance. One further proposal of \\cite{Chai_2019} is to do a Taylor expansion of $m^\\mathcal{M}_\\mathcal{D}(x)$, \n\\begin{equation}\\label{taylormomentmatched}\n m^\\mathcal{M}_\\mathcal{D}(x) \\approx 1 + m_\\mathcal{D}(x) + \\frac{1}{2} k_\\mathcal{D}(x,x) + \\frac{1}{2}\\left(m_\\mathcal{D}(x) + \\frac{1}{2} k_\\mathcal{D}(x,x)\\right)^2 + \\ldots,\n\\end{equation}\nand of $k^\\mathcal{M}_\\mathcal{D}(x,x')$,\n\\begin{equation}\n\\begin{split}\n k^\\mathcal{M}_\\mathcal{D}(x,x')  \\approx 1 & + k_\\mathcal{D}(x,x') + \\frac{1}{2} k_\\mathcal{D}(x,x')^2 \\\\ & +\n k_\\mathcal{D}(x,x') \\left(m_\\mathcal{D}(x) + \\frac{1}{2} k_\\mathcal{D}(x,x) + m_\\mathcal{D}(x') + \\frac{1}{2} k_\\mathcal{D}(x',x')\\right)^2 + \\ldots\\end{split},\n\\end{equation}\nwhich, depending on the mean function and kernel function (for instance, zero mean and SQE kernel), is integrable when truncated \\cite{Chai_2019}.\n\nThe use of function warping raises a question on how to choose the GP hyperparameters. In \\cite{Chai_2019}, it is argued that for the moment-matched procedure, one should choose the hyperparameters considering the approximated GP distribution for $f$,  $GP(m^\\mathcal{M},k^\\mathcal{M}(x,x'))$ and the data $(\\mathbf{x},f(\\mathbf{x}))$, as opposed to the exact GP distribution for $g$, where it is considered $GP(m,k)$ and the data $(\\mathbf{x},g(\\mathbf{x}))$. The authors of \\cite{Chai_2019} call the first approach \\textit{$f$-space} optimization, and the second one \\textit{$g$-space} optimization, and it is argued that empirically, $f$-space optimization results in better integral estimations for their test cases. \\footnote{Tests with $f$-space optimization in this work weren't successful.}\n\n\\section{Choosing evaluation points}\n\nThe integral estimate variance $\\Var[Z_{\\mathcal{D}}]$ yields a natural metric for choosing a set of evaluation points $X_\\mathcal{D} = \\{x_1,...,x_N\\}$. Namely, since $\\Var[Z_\\mathcal{D}]$ does not depend on the evaluation values $\\{f(x_1),\\ldots,f(x_N)\\}$, one can, given a budget of $N$ evaluations, minimize the function $\\alpha_{\\text{OBQ}}:\\mathbb{R}^{dN} \\to \\mathbb{R}$ given by\n\\begin{equation}\\label{optimal_bmc}\n\\alpha_{\\text{OBQ}}(X_\\mathcal{D}) =  \\Var[Z_{\\mathcal{D}}](X_\\mathcal{D}) = \\Gamma(X_\\mathcal{D}) - \\mathbf{z}(X_\\mathcal{D})^T K(X_\\mathcal{D})^{-1} \\mathbf{z}(X_\\mathcal{D})\n\\end{equation}\nHowever, the evaluation of this function has a $\\mathcal{O}(N^3)$ cost, due to the need for matrix inversion, is not necessarily convex, and is defined on a very high dimensional space, so its minimization will be feasible only in specific cases. An easier way would be to take a greedy approach, that is, given $X_{\\mathcal{D}_{m}} = \\{x_1,...,x_m\\}$ previously chosen evaluation points, with $m < n$, we choose $x_{m+1}$ such that the variance of $Z_{\\mathcal{D}_m \\cup \\{x_{m+1},f(x_{m+1})\\}}$ is minimized, that is, we are looking to minimize the objective function \n\\begin{equation}\n\\alpha^m_{\\text{SBQ}}(x_{m+1}) = \\alpha^m_\\text{OBQ}(x_{m+1};x_1,\\ldots,x_m)\n\\end{equation}\n\n\\begin{equation}\\label{sequential_bmc}\n\\alpha^m_{SBQ} : \\mathbb{R}^d \\to \\mathbb{R} , \\quad x_{m+1} \\to \\Var[Z_{\\mathcal{D}^m \\cup \\{x_{m+1},f(x_{m+1})\\}}](x_{m+1}),\n\\end{equation}\nThis algorithm is referred as Sequential Bayesian Quadrature (SBQ) in \\cite{Briol_2015}, while in the same work the first objective is referred as Optimal Bayesian Quadrature (OBQ). Notice that the kernel matrix Cholesky decomposition can be updated in $\\mathcal{O}(N^2)$ by the discussion in Section \\ref{onlinelearningsection}, and that this operation is differentiable, since the Cholesky decomposition is differentiable \\cite{Smith_1995,Murray_2016}. \n\nOne can simplify this objective function, by substituting it for an heuristic of finding the point of maximum variance of the integrand, that is, substituting\n\\begin{equation}\n\\argmin_{x_{m+1}} \\int f_{\\mathcal{D} \\cup \\{x_{m+1}\\}}(x) p(x)\n\\end{equation}\nfor \n\\begin{equation}\n\\argmax_{x_{m+1}} \\Var[f_\\mathcal{D}(x_{m+1}) p(x_{m+1})] = \\argmax_{x_{m+1}} k_\\mathcal{D}(x_{m+1},x_{m+1}) p(x)^2\n\\end{equation}\nThis maximization objective \n\\begin{equation}\\label{us_bmc}\n\\alpha^m_{\\text{US}}(x_{m+1}) = k_\\mathcal{D}(x_{m+1},x_{m+1}) p(x)^2 , \n\\end{equation}\nin referred as \\textit{uncertainty sampling} (US).\n\n\nIn the approaches above, since the variance of $f_\\mathcal{D}(x)$ and $\\mathcal{Z}_\\mathcal{D}$ is independent of evaluation values, there is no active selection for evaluation points, and in principle one can choose then beforehand. This is not true anymore if one optimizes the GP hyperparameters as the evaluation points are selected, or if one considers one of the approaches to treat positive integrands, as shown in previous sections. However, the heuristic motivating the maximization of \\eqref{us_bmc} can be extended for warped approaches, as proposed in \\cite{Gunter_2014}. For the model \\eqref{sqlinearization}, this returns the maximization objective \\footnote{In these functions, WSABI refers to \\textit{warped sequential active Bayesian integration}, with the letter L standing for linearization and M for moment-matched, and MMLT stands for moment-matched log transform}\n\\begin{equation}\n \\alpha^m_{\\text{WSABI-L}}(x_{m+1}) = k_{\\mathcal{D}^m}^\\mathcal{L}(x,x) p(x)^2 = k_{\\mathcal{D}^m}(x,x) m_{\\mathcal{D}^m}(x)^2 p(x)^2,\n\\end{equation}\nwhile for \\eqref{sqmomentmatched},\n\\begin{equation}\n\\alpha^m_{\\text{WSABI-M}}(x_{m+1}) = k_{\\mathcal{D}^m}^\\mathcal{M}(x,x) p(x)^2 = \\left(k_{\\mathcal{D}^m}(x,x)^2 k_{\\mathcal{D}^m}(x,x) m_{\\mathcal{D}^m}(x)^2\\right) p(x)^2.\n\\end{equation}\nFinally, for the model \\eqref{logmomentmatched} proposed in \\cite{Chai_2019}, we arrive at:\n\\begin{equation}\\label{mmlt1}\n\\alpha^m_{\\text{MMLT}_1}(x_{m+1}) = e^{2 m_\\mathcal{D}(x) + k_\\mathcal{D}(x,x)} \\left(e^{k_\\mathcal{D}(x,x')}-1\\right)p(x)^2.\n\\end{equation}\n\nRecent work \\cite{Kanagawa_2019} analyzes jointly those methods under the umbrella term \\textit{adaptive Bayesian quadrature}, where their convergence rates are studied. In particular, there it is considered a version of \\eqref{mmlt1} without the $p(x)$ term, resulting in the maximization objective\n\\begin{equation}\\label{mmlt2}\n\\alpha^m_{\\text{MMLT}_2}(x_{m+1}) = e^{2 m_\\mathcal{D}(x) + k_\\mathcal{D}(x,x)} \\left(e^{k_\\mathcal{D}(x,x')}-1\\right).\n\\end{equation}\n\nIn the spirit of Bayesian optimization (discussed below), the maximization objectives presented, and others will be called \\textit{acquisition functions}, nomenclature that implies they are criteria for acquiring new information.\n\n\n\\section{Bayesian Monte Carlo and Bayesian Optimization}\nBayesian Monte Carlo belongs to the general family of surrogate model or response surface methods, that are popular in engineering \\cite{Booker_1999,Jones_2001,Asher_2015}. Namely, surrogate models tries to approximate a function $f$ of hard evaluation by a function $\\hat{f}$ that is easy to evaluate, and try to work with it. Gaussian processes are popular as surrogate models \\footnote{In engineering literature they are often called kriging}, since they offer a measure of uncertainty, are flexible, and since the original function evaluation is hard, relatively few data will be available, which mitigates the scaling problem of GPs.\n\nIn particular, an important GP-based surrogate method is Bayesian optimization \\cite{Shahriari_2016,Brochu_2010,Snoek_2012}, which tries to optimize an expensive function, usually without gradient information. The idea is, from function evaluations $\\mathcal{D}_N = \\{(x_i,f(x_i)\\}_{i=1}^N$, to construct a GP model $\\hat{f}_N$, and with it, sequentially use some criteria $\\alpha_f$ to choose the $x_{N+1}$ evaluation. Such functions $\\alpha_f$ are called acquisition functions in the context. Bayesian optimization in particular is a popular method in machine learning, to tune training parameters of learning algorithms.\n\n\n", "meta": {"hexsha": "ece10578418afb52e796e7c234d71ff96afaa843", "size": 25551, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex_copy/chapters/capituloC.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/capituloC.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/capituloC.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": 86.0303030303, "max_line_length": 885, "alphanum_fraction": 0.7054518414, "num_tokens": 8670, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8333245953120234, "lm_q2_score": 0.9059898108646849, "lm_q1q2_score": 0.7549835924956302}}
{"text": "\\chapter{Circular Motion}\n\nLet's say you tie a 0.16 kg billard ball to a long string and begin to swing\nit around in a circle above your head. Let's say the string is 3\nmeters long, and the ball returns to where it started every 4\nseconds. If you start your stopwatch as the the ball crosses the\n$x$-axis, the position of the ball at any time $t$ given by:\n\n$$p(t) = [3 \\cos{\\left( \\frac{2 \\pi} {4}t\\right)}, 3 \\sin{ \\left( \\frac{2 \\pi}{4}t\\right) }, 2]$$\n\n(This assumes that the ball would be going counter-clockwise if viewed\nfrom above. The spot you are standing on is considered the origin $[0, 0, 0]$.)\n\nNotice that the height is a constant -- 2 meters in this\ncase. That isn't very interesting, so we will talk just about the the\nfirst two components.  Here is what it would look like from above:\n\n% 3sin = 1.267854785222098\n% 3cos = 2.71892336110995\n\\begin{tikzpicture}[declare function={angle=25;},bullet/.style={inner\n    sep=1pt,fill,draw,circle,solid}, scale=1.7]\n    % Axis\n    \\draw[thick,-stealth,black] (-3.2,0)--(3.2,0) node[right] {$x$}; % x axis\n    \\draw[thick,-stealth,black] (0,-3.2)--(0,3.2) node[left] {$y$}; % y axis\n    % Rest\n    \\draw [dashed, sdkblue] (0,0) circle (3);\n    \\draw[thick] (0,0) -- (angle:3.0) node [midway, above] {3};\n    \\draw[sdkblue] (1.05, 0.2) node[right] {$\\theta = \\frac{2\\pi t}{4}\\text{ radians}$};\n    \\draw[-stealth,sdkblue] (1,0) arc (0:angle:1);\n    \\draw[dashed, black] (2.71892336110995, 1.267854785222098) -- (2.71892336110995, 0)\n    node[below] {$3 \\cos(\\theta)$}; % vertical\n    \\draw[dashed, black] (2.71892336110995, 1.267854785222098) -- (0, 1.267854785222098)\n    node[left] {$3 \\sin(\\theta)$}; % horizontal\n    \\filldraw[black] (angle:3.0) circle(4pt);\n    \\draw[->, thick] (2.71892336110995, 1.267854785222098) --\n    (2.71892336110995 - 3 * 0.1267, 1.267854785222098 + 3 * 0.2718);\n\\end{tikzpicture}\n\nIn this case, the radius, $r$, is 3 meters.  The period, $T$ is 4\nseconds.  In general, we say that circular motion is given by:\n\n$$p(t) = \\left[ r \\cos{\\frac{2 \\pi t}{T}}, r \\cos{\\frac{2 \\pi t}{T}}\\right]$$\n\nA common question is ``How fast is it turning right now?''  If you\ndivide the $2\\pi$ radians of a circle by the 4 seconds it takes, you\nget the answer ``About 1.57 radians per second.''  This is known as\n\\newterm{angular velocity} and we typically represent it with the\nlowercase Omega: $\\omega$. (Yes, it looks a lot like a ``w''.)  To be\nprecise, in our example, the angular velocity is $\\omega = \\frac{\\pi}{2}$.\n\nNotice that this is different from the question ``How fast is it\ngoing?''  This ball is traveling the circumference of $6\\pi \\approx\n18.85$ meters every 4 seconds.  So the speed of the ball is about\n4.71 meters per second.\n\n\\section{Velocity}\n\nThe velocity of the ball is a vector, and we can find that vector by\ndifferentiating each component of the position vector.\n\nFor any constants $a$ and $b$:\n\n\\begin{tabular}{c | c }\n  Expression & Derivative \\\\\n  \\hline\n  $a \\sin{b t}$ & $ab \\cos{b t}$ \\\\\n  $a \\cos{b t}$ & $-ab \\sin{b t}$  \\\\\n\\end{tabular}\n\nThus, in our example, the velocity of the ball at any time $t$ is given by:\n\n$$v(t) = \\left[ -\\frac{3 (2\\pi)}{4} \\sin{\\frac{2\\pi t}{4}}, \\frac{3(2\\pi)}{4} \\cos{\\frac{2\\pi t}{4}}, 0 \\right]$$\n\nNotice that the velocity vector is perpendicular to the position vector.  It has a constant magnitude.\n\nIn general, an object traveling in a circle at a constant speed has the velocity vector:\n\n$$v(t) = \\left[ -r\\omega \\sin{\\omega t}, r\\omega \\cos{\\omega t}\\right]$$\n\nwhere $t = 0$ is the time that it crosses the $x$ axis.  If \\omega is\nnegative, that means the motion would be clockwise when viewed from\nabove.\n\nThe magnitude of the velocity vector is $r\\omega$. \n\n\\begin{tikzpicture}[declare function={angle=25;},bullet/.style={inner\n    sep=1pt,fill,draw,circle,solid}, scale=1.7]\n    % Axis\n    \\draw[thick,-stealth,black] (-3.2,0)--(3.2,0) node[right] {$x$}; % x axis\n    \\draw[thick,-stealth,black] (0,-3.2)--(0,3.2) node[left] {$y$}; % y axis\n    % Rest\n    \\draw [dashed, sdkblue] (0,0) circle (3);\n    \\filldraw[black] (angle:3.0) circle(4pt);\n    \\draw[->, thick] (2.71892336110995, 1.267854785222098) --\n    (2.71892336110995 - 0.6 * 1.267, 1.267854785222098 + 0.6 * 2.718) node[right]{$v(t)=\\left[ -r\\omega \\sin{\\omega t}, r\\omega \\cos{\\omega t}\\right]$};\n\\end{tikzpicture}\n\n\\section{Acceleration}\n\nWe can get the acceleration by differentiating the components of the velocity vector.\n\n$$a(t) = \\left[-r \\omega^2 \\cos{\\omega t}, -r \\omega^2 \\sin{\\omega t} \\right]$$\n\nNotice that the acceleration vector points toward the center of the\ncircle it is traveling on.  That is, when an object is traveling on a\ncircle at a constant speed, its only acceleration is toward the center\nof the circle.\n\n\\begin{tikzpicture}[declare function={angle=25;},bullet/.style={inner\n    sep=1pt,fill,draw,circle,solid}, scale=1.7]\n    % Axis\n    \\draw[thick,-stealth,black] (-3.2,0)--(3.2,0) node[right] {$x$}; % x axis\n    \\draw[thick,-stealth,black] (0,-3.2)--(0,3.2) node[left] {$y$}; % y axis\n    % Rest\n    \\draw [dashed, sdkblue] (0,0) circle (3);\n    \\filldraw[black] (angle:3.0) circle(4pt);\n    \\draw[->, thick] (2.71892336110995, 1.267854785222098) --\n    (2.71892336110995 * 0.2 , 1.267854785222098 * 0.2) node[midway, right]{$a(t) = \\left[-r \\omega^2 \\cos{\\omega t}, -r \\omega^2 \\sin{\\omega t} \\right]$};\n\\end{tikzpicture}\n\nThe magnitude of the acceleration vector is $r \\omega^2$.\n\n\\section{Centripetal force}\n\nHow hard is the ball pulling against your hand?  That is, if you let\ngo, the ball would fly in a straight line.  The force you are exerting\non the string is what causes it to accelerate toward the center of the\ncircle. We call this the \\newterm{centripetal force}.\n\nRecall that $F = m a$.  The magnitude of the acceleration is $r\n\\omega^2 = 3 \\left(\\frac{2 pi}{4}\\right)^2 \\approx 7.4$ m/s.  The mass\nof the ball is 0.16 kg.  So the force pulling against your hand is\nabout 1.18 newtons.\n\nThe general rule is that when something is traveling in a circle at a\nconstant speed, the centripetal force needed to keep it traveling in a\ncircle is:\n\n$$F = m r \\omega^2$$\n\nIf you know the radius $r$ and the speed $v$ of the the object, here is the rule:\n\n$$F = \\frac{m v^2}{r}$$\n\n\\begin{Exercise}[title={Circular Motion}, label=circular]\nJust as your car rolls onto a circular track with a radius of 200 m,\nyou realize your 0.4 kg cup of coffee is on the slippery dashboard of your\ncar.  While driving 120 km/hour, you hold the cup to keep it from sliding.\n\nWhat is the maximum amount of force you would need to use (The friction of\nthe dashboard helps you, but the max is when the friction is zero.)\n\n\\end{Exercise}\n\\begin{Answer}[ref=circular]\n  $$\\frac{120 \\text{ km}}{1 hour} = \\frac{1000 \\text{ m}}{1 \\text{ km}}\\frac{120 \\text{ km}}{1 hour} \\frac{1 \\text{ hour}}{3600 \\text{ seconds}}= 33.3 \\text{ m/s}$$\n\n  $$F = \\frac{m v^2}{r} = \\frac {0.4 (33.3)^2}{200} = 2.2 \\text{ newtons}$$\n\\end{Answer}\n", "meta": {"hexsha": "0ff4f26ffec6896c988bb632b4a1647992a07937", "size": 6948, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Modules/Oscillations/circular-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/circular-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/circular-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.6981132075, "max_line_length": 164, "alphanum_fraction": 0.6737190558, "num_tokens": 2405, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677699040321, "lm_q2_score": 0.890294235582146, "lm_q1q2_score": 0.7549408175050074}}
{"text": "\n\\lab{Introduction to NumPy}{Introduction to NumPy}\n\\label{lab:NumPy}\n\\objective{NumPy is a powerful Python package for manipulating data with multi-dimensional vectors.\nIts versatility and speed makes Python an ideal language for applied and computational mathematics.\nIn this lab we introduce basic NumPy data structures and operations as a first step to numerical computing in Python.}\n\n\\section*{Arrays} % ===========================================================\n\nIn many algorithms, data can be represented mathematically as a \\emph{vector} or a \\emph{matrix}.\nConceptually, a vector is just a list of numbers and a matrix is a two-dimensional list of numbers (a list of lists).\nHowever, even basic linear algebra operations like matrix multiplication are cumbersome to implement and slow to execute when data is stored this way.\nThe \\emph{NumPy} module\\footnote{NumPy is \\emph{not} part of the standard library, but it is included in most Python distributions.} \\cite{oliphant2006guide,ascher2001numerical,oliphant2007python} offers a much better solution.\n\nThe basic object in NumPy is the \\emph{array}, which is conceptually similar to a matrix.\nThe NumPy array class is called \\li{ndarray} (for ``$n$-dimensional array'').\nThe simplest way to explicitly create a 1-D \\li{ndarray} is to define a list, then cast that list as an \\li{ndarray} with NumPy's \\li{array()} function.\n\n\\begin{lstlisting}\n>>> import numpy as np\n\n# Create a 1-D array by passing a list into NumPy's array() function.\n>>> np.array([8, 4, 6, 0, 2])\narray([8, 4, 6, 0, 2])\n\n# The string representation has no commas or an array() label.\n>>> print(np.array([1, 3, 5, 7, 9]))\n[1 3 5 7 9]\n\\end{lstlisting}\n%\nThe alias ``\\li{np}'' for numpy is standard in the Python community. % Make footnote?\n\nAn \\li{ndarray} can have arbitrarily many dimensions.\nA 2-D array is a 1-D array of 1-D arrays (like a list of lists), a 3-D array is a 1-D array of 2-D arrays (a list of lists of lists), and, more generally, an $n$-dimensional array is a 1-D array of $(n-1)$-dimensional arrays (a list of lists of lists of lists...).\nEach dimension is called an \\emph{axis}.\nFor a 2-D array, the $0$-axis indexes the rows and the $1$-axis indexes the columns.\nElements are accessed using brackets and indices, with the axes separated by commas.\n\n\\begin{lstlisting}\n# Create a 2-D array by passing a list of lists into array().\n>>> A = np.array( [ [1, 2, 3],[4, 5, 6] ] )\n>>> print(A)\n[[1 2 3]\n [4 5 6]]\n\n# Access elements of the array with brackets.\n>>> print(A[0, 1], A[1, 2])\n2 6\n\n# The elements of a 2-D array are 1-D arrays.\n>>> A[0]\narray([1, 2, 3])\n\\end{lstlisting}\n\n\\begin{problem} % Matrix Multiplication\nThere are two main ways to perform matrix multiplication in NumPy: with NumPy's \\li{dot()} function (\\li{np.dot(A, B)}), or with the \\li{@} operator (\\li{A @ B}).\nWrite a function that defines the following matrices as NumPy arrays.\n\\begin{align*}\nA = \\left[\\begin{array}{rrr}\n3 & -1 &  4 \\\\\n1 &  5 & -9 \\end{array}\\right]\n&&\nB = \\left[\\begin{array}{cccc}\n2 &  6 & -5 &  3\\\\\n5 & -8 &  9 &  7\\\\\n9 & -3 & -2 & -3\\end{array}\\right]\n\\end{align*}\nReturn the matrix product $AB$.\n% Solution:\n% array([[ 37,  14, -32, -10],\n%        [-54,  -7,  58,  65]])\n\nFor examples of array initialization and matrix multiplication, use object introspection in IPython to look up the documentation for \\li{np.ndarray}, \\li{np.array()} and \\li{np.dot()}.\n\\begin{lstlisting}\n<g<In [1]:>g> import numpy as np\n\n<g<In [2]:>g> np.array?       # press 'enter'\n\\end{lstlisting}\n\\end{problem}\n\n\\begin{warn} % The @ operator.\nThe \\li{@} operator was not introduced until Python 3.5.\nIt triggers the \\li{__matmul__()} magic method,%\n\\footnote{See the lab on Object Oriented Programming for an overview of magic methods.}\nwhich for the \\li{ndarray} is essentially a wrapper around \\li{np.dot()}.\nIf you are using a previous version of Python, always use \\li{np.dot()} to perform basic matrix multiplication.\n\\end{warn}\n\n\\subsection*{Basic Array Operations} % ----------------------------------------\n\nNumPy arrays behave differently with respect to the binary arithmetic operators \\li{+} and \\li{*} than Python lists do.\nFor lists, \\li{+} concatenates two lists and \\li{*} replicates a list by a scalar amount (strings also behave this way).\n\n\\begin{lstlisting}\n# Addition concatenates lists together.\n>>> [1, 2, 3] + [4, 5, 6]\n[1, 2, 3, 4, 5, 6]\n\n# Mutliplication concatenates a list with itself a given number of times.\n>>> [1, 2, 3] * 4\n[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]\n\\end{lstlisting}\n\nNumPy arrays act like mathematical vectors and matrices: \\li{+} and \\li{*} perform component-wise addition or multiplication.\n\\begin{comment}\n\\[\n\\left[\\begin{array}{c}1 \\\\ 2 \\\\ 3\\end{array}\\right]\n+\n\\left[\\begin{array}{c}4 \\\\ 5 \\\\ 6\\end{array}\\right]\n=\n\\left[\\begin{array}{c}1+4 \\\\ 2+5 \\\\ 3+6\\end{array}\\right]\n=\n\\left[\\begin{array}{c}5 \\\\ 7 \\\\ 9\\end{array}\\right]\n\\qquad\n4*\n\\left[\\begin{array}{c}1 \\\\ 2 \\\\ 3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}4*1 \\\\ 4*2 \\\\ 4*3\\end{array}\\right]\n=\n\\left[\\begin{array}{c}4 \\\\ 8 \\\\ 12\\end{array}\\right]\n\\]\n\\end{comment}\n\n\\begin{lstlisting}\n>>> x, y = np.array([1, 2, 3]), np.array([4, 5, 6])\n\n# Addition or multiplication by a scalar acts on each element of the array.\n>>> x + 10                          # Add 10 to each entry of x.\narray([11, 12, 13])\n>>> x * 4                           # Multiply each entry of x by 4.\narray([ 4,  8, 12])\n\n# Add two arrays together (component-wise).\n>>> x + y\narray([5, 7, 9])\n\n# Multiply two arrays together (component-wise).\n>>> x * y\narray([ 4, 10, 18])\n\\end{lstlisting}\n\n% Subtraction and division are also component-wise operations for NumPy arrays.\n% Apart from being syntactically convenient, arithmetic operations on NumPy arrays also execute significantly faster than component-wise list operations.\n\n\\begin{comment}\n\\begin{warn} % Don't mix up * and np.dot().\nMatrix multiplication is executed via \\li{np.dot()} or \\li{@} and scalar (component-wise) multiplication is executed via the \\li{*} operator.\nThe equation below is an example of scalar multiplication, which uses \\li{*}.\n\\begin{align*}\n2 \\left[\\begin{array}{rrr}\n1 & 2 & 3\\\\\n4 & 5 & 6 \\end{array}\\right]\n= \\left[\\begin{array}{rrr}\n2 & 4 & 6\\\\\n8 & 10 & 12 \\end{array}\\right]\n\\end{align*}\n\\end{warn}\n\\end{comment}\n\n\\begin{problem} % Simple Matrix Equation 2 (Cayley Hamilton)\nWrite a function that defines the following matrix as a NumPy array.\n\\[\nA = \\left[\\begin{array}{rrr}\n3 & 1 & 4\\\\\n1 & 5 & 9 \\\\\n-5 & 3 & 1 \\end{array}\\right]\n\\]\nReturn the matrix $-A^3 + 9A^2 - 15A$.\n\nIn this context, $A^2 = AA$ (the matrix product, not the component-wise square).\nThe somewhat surprising result is a demonstration of the Cayley-Hamilton theorem.\n\\end{problem}\n\n\\subsection*{Array Attributes} % ----------------------------------------------\nAn \\li{ndarray} object has several attributes, some of which are listed below.\n\n\\begin{table}[H] % Important ndarray Attributes\n\\centering\n\\begin{tabular}{c|l}\n    Attribute & Description \\\\\n    \\hline \\li{dtype} & The type of the elements in the array. \\\\\n    \\li{ndim} & The number of axes (dimensions) of the array. \\\\\n    \\li{shape} & A tuple of integers indicating the size in each dimension. \\\\\n    \\li{size} & The total number of elements in the array. \\\\\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n>>> A = np.array([[1, 2, 3],[4, 5, 6]])\n\n# 'A' is a 2-D array with 2 rows, 3 columns, and 6 entries.\n>>> print(A.ndim, A.shape, A.size)\n2 (2, 3) 6\n\\end{lstlisting}\n\nNote that \\li{ndim} is the number of entries in \\li{shape}, and that\nthe \\li{size} of the array is the product of the entries of \\li{shape}.\n\n\\begin{comment} % This is being severely shortened.\n\\subsection*{Data Types} % ----------------------------------------------------\n\nUnlike native Python data structures, \\textbf{all elements of a NumPy array must have the same data type}.\nThe data types used by NumPy arrays are machine-native and avoid the overhead of Python objects, meaning that they are faster to compute with.\nThus NumPy's \\li{np.float64} and Python's standard \\li{float} are not the same; the former has been optimized to speed up numerical computations.\nNumPy's more common numerical data types are listed below in Table \\ref{table:numpytypes}.\n\n\\begin{table}[H] % Numpy Data Types\n\\centering\n\\begin{tabular}{l|l}\nData type & Description\n\\\\ \\hline\n\\li{bool_} & Boolean \\\\\n\\li{int8} & 8-bit integer \\\\\n\\li{int16} & 16-bit integer \\\\\n\\li{int32} & 32-bit integer \\\\\n\\li{int64} & 64-bit integer \\\\\n\\li{uint8} & Unsigned 8-bit integer \\\\\n\\li{uint16} & Unsigned 16-bit integer \\\\\n\\li{uint32} & Unsigned 32-bit integer \\\\\n\\li{uint64} & Unsigned 64-bit integer \\\\\n\\li{float16} & Half-precision float \\\\\n\\li{float32} & Single-precision float \\\\\n\\li{float64} & Double-precision float (default type for most computations)\\\\\n\\li{complex64} & Complex number represented by two single-precision floats \\\\\n\\li{complex128} & Complex number represented by two double-precision floats\n\\end{tabular}\n\\caption{Native numerical data types available in NumPy. The numbers on these types, such as the 16 on \\li{int16}, indicates the number of bits used by the machine to store the number. Thus \\li{float64} is more precise, but more computationally expensive, than \\li{float16}.}\n\\label{table:numpytypes}\n\\end{table}\n\nWe specify the data type of an array as it is created with the keyword argument \\li{dtype}.\nIf unspecified, then the type is determined as the minimum type required to hold the objects in the provided sequence.\nTo change an existing array's type, use the array's \\li{astype()} method.\n\n\\begin{lstlisting}\n# A list of integers becomes an array of integers.\n>>> x = np.array([0, 1, 2, 3, 4])\n>>> print(x)\n[0 1 2 3 4]\n>>> x.dtype\n<<dtype('int64')>>\n\n# Change the data type to one of NumPy's float types.\n>>> x = x.astype(np.float64)\n>>> print(x)\n[ 0.  1.  2.  3.  4.]\n>>> x.dtype\n<<dtype('float64')>>\n\\end{lstlisting}\n\n\\begin{warn}\nThe default data type for most NumPy operations is \\li{np.float64}.\nUsing smaller data types can speed up computations, but can result in unexpected problems due to overflow.\n\nFor example, an integer represented in binary with 8 bits (including one bit for the sign) can range from $-128$ to $127$.\nCasting a number outside of this range as an 8-bit integer can cause some unexpected overflow issues.\n\n\\begin{lstlisting}\n>>> np.int8(200)\n-56\n\\end{lstlisting}\n\\end{warn}\n\\end{comment}\n\n\\subsection*{Array Creation Routines} % ---------------------------------------\n\nIn addition to casting other structures as arrays via \\li{np.array()}, NumPy provides efficient ways to create certain commonly-used arrays.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\nFunction & Returns \\\\\n\\hline \\li{arange()} & Array of sequential integers (like \\li{list(range())}).\\\\\n% \\li{empty()} & Array of given shape and type, without initializing entries. \\\\\n% \\li{empty_like()} & Array with the same shape and type as a given array. \\\\\n\\li{eye()} & 2-D array with ones on the diagonal and zeros elsewhere. \\\\\n% \\li{identity()} & The square identity array. \\\\\n\\li{ones()} & Array of given shape and type, filled with ones. \\\\\n\\li{ones_like()} & Array of ones with the same shape and type as a given array. \\\\\n\\li{zeros()} & Array of given shape and type, filled with zeros. \\\\\n\\li{zeros_like()} & Array of zeros with the same shape and type as a given array. \\\\\n\\li{full()} & Array of given shape and type, filled with a specified value. \\\\\n\\li{full_like()} & Full array with the same shape and type as a given array.\n\\end{tabular}\n\\end{table}\n\nEach of these functions accepts the keyword argument \\li{dtype} to specify the data type.\nCommon types include \\li{np.bool_}, \\li{np.int64}, \\li{np.float64}, and \\li{np.complex128}.\n\n\\begin{lstlisting}\n# A 1-D array of 5 zeros.\n>>> np.zeros(5)\narray([ 0.,  0.,  0.,  0.,  0.])\n\n# A 2x5 matrix (2-D array) of integer ones.\n>>> np.ones((2,5), dtype=<<np.int>>)    # The shape is specified as a tuple.\narray([[1, 1, 1, 1, 1],\n       [1, 1, 1, 1, 1]])\n\n# The 2x2 identity matrix.\n>>> I = np.eye(2)\n>>> print(I)\n[[ 1.  0.]\n [ 0.  1.]]\n\n# Array of 3s the same size as 'I'.\n>>> np.full_like(I, 3)              # Equivalent to np.full(I.shape, 3).\narray([[ 3.,  3.],\n       [ 3.,  3.]])\n\\end{lstlisting}\n\nUnlike native Python data structures, \\textbf{all elements of a NumPy array must be of the same data type}.\nTo change an existing array's data type, use the array's \\li{astype()} method.\n\n\\begin{lstlisting}\n# A list of integers becomes an array of integers.\n>>> x = np.array([0, 1, 2, 3, 4])\n>>> print(x)\n[0 1 2 3 4]\n>>> x.dtype\n<<dtype('int64')>>\n\n# Change the data type to one of NumPy's float types.\n>>> x = x.astype(np.float64)        # Equivalent to x = np.float64(x).\n>>> print(x)\n[ 0.  1.  2.  3.  4.]               # Floats are displayed with periods.\n>>> x.dtype\n<<dtype('float64')>>\n\\end{lstlisting}\n\nThe following functions are for dealing with the diagonal, upper, or lower portion of an array.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{c|l}\nFunction & Description \\\\ \\hline\n\\li{diag()} & Extract a diagonal or construct a diagonal array.\\\\\n\\li{tril()} & Get the lower-triangular portion of an array by replacing entries above\\\\&the diagonal with zeros.\\\\\n\\li{triu()} & Get the upper-triangular portion of an array by replacing entries below\\\\&the diagonal with zeros.\n\\end{tabular}\n\\label{table:numpycreate2}\n\\end{table}\n\n\\begin{lstlisting}\n>>> A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n\n# Get only the upper triangular entries of 'A'.\n>>> np.triu(A)\narray([[1, 2, 3],\n       [0, 5, 6],\n       [0, 0, 9]])\n\n# Get the diagonal entries of 'A' as a 1-D array.\n>>> np.diag(A)\narray([1, 5, 9])\n\n# diag() can also be used to create a diagonal matrix from a 1-D array.\n>>> np.diag([1, 11, 111])\narray([[  1,   0,   0],\n       [  0,  11,   0],\n       [  0,   0, 111]])\n\\end{lstlisting}\n\nSee \\url{http://docs.scipy.org/doc/numpy/reference/routines.array-creation.html} for the official documentation on NumPy's array creation routines.\n\n\\begin{problem} % Simple Matrix Equation 3\nWrite a function that defines the following matrices as NumPy arrays using the functions presented in this section (not \\li{np.array()}).\nCalculate the matrix product $ABA$.\nChange the data type of the resulting matrix to \\li{np.int64}, then return it.\n\\begin{align*}\nA = \\left[\\begin{array}{rrrrrrr}\n1 & 1 & 1 & 1 & 1 & 1 & 1\\\\\n0 & 1 & 1 & 1 & 1 & 1 & 1\\\\\n0 & 0 & 1 & 1 & 1 & 1 & 1\\\\\n0 & 0 & 0 & 1 & 1 & 1 & 1\\\\\n0 & 0 & 0 & 0 & 1 & 1 & 1\\\\\n0 & 0 & 0 & 0 & 0 & 1 & 1\\\\\n0 & 0 & 0 & 0 & 0 & 0 & 1\\end{array}\\right]\n&&\nB = \\left[\\begin{array}{rrrrrrr}\n-1 &  5 &  5 &  5 &  5 &  5 &  5\\\\\n-1 & -1 &  5 &  5 &  5 &  5 &  5\\\\\n-1 & -1 & -1 &  5 &  5 &  5 &  5\\\\\n-1 & -1 & -1 & -1 &  5 &  5 &  5\\\\\n-1 & -1 & -1 & -1 & -1 &  5 &  5\\\\\n-1 & -1 & -1 & -1 & -1 & -1 &  5\\\\\n-1 & -1 & -1 & -1 & -1 & -1 & -1\\end{array}\\right]\n\\end{align*}\n% Solution:\n% array([[ -7,  -8,  -3,   8,  25,  48,  77],\n%        [ -6, -12, -12,  -6,   6,  24,  48],\n%        [ -5, -10, -15, -14,  -7,   6,  25],\n%        [ -4,  -8, -12, -16, -14,  -6,   8],\n%        [ -3,  -6,  -9, -12, -15, -12,  -3],\n%        [ -2,  -4,  -6,  -8, -10, -12,  -8],\n%        [ -1,  -2,  -3,  -4,  -5,  -6,  -7]])\n\\end{problem}\n\n\\section*{Data Access} % ======================================================\n\n\\subsection*{Array Slicing} % -------------------------------------------------\n\nIndexing for a 1-D NumPy array uses the slicing syntax \\li{x[start:stop:step]}.\nIf there is no colon, a single entry of that dimension is accessed.\nWith a colon, a range of values is accessed.\nFor multi-dimensional arrays, use a comma to separate slicing syntax for each axis.\n\n\\begin{lstlisting}\n# Make an array of the integers from 0 to 10 (exclusive).\n>>> x = np.arange(10)\n>>> x\narray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n\n# Access elements of the array with slicing syntax.\n>>> x[3]                            # The element at index 3.\n3\n>>> x[:3]                           # Everything before index 3.\narray([0, 1, 2])\n>>> x[3:]                           # Everything from index 3 on.\narray([3, 4, 5, 6, 7, 8, 9])\n>>> x[3:8]                          # Everything between index 3 and index 8 (exclusive).\narray([3, 4, 5, 6, 7])\n\n>>> A = np.array([[0,1,2,3,4],[5,6,7,8,9]])\n>>> A\narray([[0, 1, 2, 3, 4],\n       [5, 6, 7, 8, 9]])\n\n# Use a comma to separate the dimensions for multi-dimensional arrays.\n>>> A[1, 2]                         # The element at row 1, column 2.\n7\n>>> A[:, 2:]                        # All of the rows, from column 2 on.\narray([[2, 3, 4],\n       [7, 8, 9]])\n\\end{lstlisting}\n\n% See Appendix \\ref{appendix:numpy-visual-guide} for visual examples of slicing.\n\n\\begin{info} % Views vs. Copies.\nIndexing and slicing operations return a \\emph{view} of the array.\nChanging a view of an array also changes the original array.\nIn other words, \\textbf{arrays are mutable}.\nTo create a copy of an array, use \\li{np.copy()} or the array's \\li{copy()} method.\nChanges to a copy of an array does not affect the original array, but copying an array uses more time and memory than getting a view.\n\\end{info}\n\n\\subsection*{Fancy Indexing} % ------------------------------------------------\n\nSo-called \\emph{fancy indexing} is a second way to access or change the elements of an array.\nInstead of using slicing syntax, provide either an array of indices or an array of boolean values (called a \\emph{mask}) to extract specific elements.\n\n\\begin{lstlisting}\n>>> x = np.arange(0, 50, 10)        # The integers from 0 to 50 by tens.\n>>> x\narray([ 0, 10, 20, 30, 40])\n\n# An array of integers extracts the entries of 'x' at the given indices.\n>>> index = np.array([3, 1, 4])     # Get the 3rd, 1st, and 4th elements.\n>>> x[index]                        # Same as np.array([x[i] for i in index]).\narray([30, 10, 40])\n\n# A boolean array extracts the elements of 'x' at the same places as 'True'.\n>>> mask = np.array([True, False, False, True, False])\n>>> x[mask]                         # Get the 0th and 3rd entries.\narray([ 0, 30])\n\\end{lstlisting}\n\nFancy indexing is especially useful for extracting or changing the values of an array that meet some sort of criterion.\nUse comparison operators like \\li{<} and \\li{==} to create masks.\n\n\\begin{lstlisting}\n>>> y = np.arange(10, 20, 2)        # Every other integers from 10 to 20.\n>>> y\narray([10, 12, 14, 16, 18])\n\n# Extract the values of 'y' larger than 15.\n>>> mask = y > 15                   # Same as np.array([i > 15 for i in y]).\n>>> mask\n<<array([False, False, False,  True,  True], dtype=bool)>>\n>>> y[mask]                         # Same as y[y > 15]\narray([16, 18])\n\n# Change the values of 'y' that are larger than 15 to 100.\n>>> y[mask] = 100\n>>> print(y)\n[10 12 14  100  100]\n\\end{lstlisting}\n\nWhile indexing and slicing always return a view, fancy indexing always returns a copy.\n\n\\begin{problem} % Slicing / Fancy Indexing\nWrite a function that accepts a single array as input.\nMake a copy of the array, then use fancy indexing to set all negative entries of the copy to $0$.\nReturn the copy.\n\\end{problem}\n\n\\section*{Array Manipulation} % ===============================================\n\n\\subsection*{Shaping} % -------------------------------------------------------\n\nAn array's \\li{shape} attribute describes its dimensions.\nUse \\li{np.reshape()} or the array's \\li{reshape()} method to give an array a new shape.\nThe total number of entries in the old array and the new array must be the same in order for the shaping to work correctly.\nUsing a \\li{-1} in the new shape tuple makes the specified dimension as long as necessary.\n% Whenever possible, \\li{np.reshape()} returns a view.\n\n\\begin{lstlisting}\n>>> A = np.arange(12)               # The integers from 0 to 12 (exclusive).\n>>> print(A)\n[ 0  1  2  3  4  5  6  7  8  9 10 11]\n\n# 'A' has 12 entries, so it can be reshaped into a 3x4 matrix.\n>>> A.reshape((3,4))                # The new shape is specified as a tuple.\narray([[ 0,  1,  2,  3],\n       [ 4,  5,  6,  7],\n       [ 8,  9, 10, 11]])\n\n# Reshape 'A' into an array with 2 rows and the appropriate number of columns.\n>>> A.reshape((2,-1))\narray([[ 0,  1,  2,  3,  4,  5],\n       [ 6,  7,  8,  9, 10, 11]])\n\\end{lstlisting}\n\nUse \\li{np.ravel()} to flatten a multi-dimensional array into a 1-D array and \\li{np.transpose()} or the \\li{T} attribute to transpose a 2-D array in the matrix sense.\n\n\\begin{lstlisting}\n>>> A = np.arange(12).reshape((3,4))\n>>> A\narray([[ 0,  1,  2,  3],\n       [ 4,  5,  6,  7],\n       [ 8,  9, 10, 11]])\n\n# Flatten 'A' into a one-dimensional array.\n>>> np.ravel(A)                     # Equivalent to A.reshape(A.size)\narray([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])\n\n# Transpose the matrix 'A'.\n>>> A.T                             # Equivalent to np.transpose(A).\narray([[ 0,  4,  8],\n       [ 1,  5,  9],\n       [ 2,  6, 10],\n       [ 3,  7, 11]])\n\\end{lstlisting}\n\n\\begin{info} % All 1-D Numpy arrays are flat!\nBy default, all NumPy arrays that can be represented by a single dimension, including column slices, are automatically reshaped into ``flat'' 1-D arrays.\nFor example, by default an array will have 10 elements instead of 10 arrays with one element each.\nThough we usually represent vectors vertically in mathematical notation, NumPy methods such as \\li{dot()} are implemented to purposefully work well with 1-D ``row arrays''.\n\n\\begin{lstlisting}\n>>> A = np.arange(10).reshape((2,5))\n>>> A\narray([[0, 1, 2, 3, 4],\n       [5, 6, 7, 8, 9]])\n\n# Slicing out a column of A still produces a \"flat\" 1-D array.\n>>> x = A[:,1]                      # All of the rows, column 1.\n>>> x\narray([1, 6])                       # Not array([[1],\n>>> x.shape                         #            [6]])\n(2,)\n>>> x.ndim\n1\n\\end{lstlisting}\n\nHowever, it is occasionally necessary to change a 1-D array into a ``column array''.\nUse \\li{np.reshape()}, \\li{np.vstack()}, or slice the array and put \\li{np.newaxis} on the second axis.\nNote that \\li{np.transpose()} does not alter 1-D arrays.\n\n\\begin{lstlisting}\n>>> x = np.arange(3)\n>>> x\narray([0, 1, 2])\n\n>>> x.reshape((-1,1))               # Or x[:,np.newaxis] or np.vstack(x).\narray([[0],\n       [1],\n       [2]])\n\\end{lstlisting}\n\nDo not force a 1-D vector to be a column vector unless necessary.\n\\end{info}\n\n\\subsection*{Stacking} % ------------------------------------------------------\n\nNumPy has functions for \\emph{stacking} two or more arrays with similar dimensions into a single block matrix.\nEach of these methods takes in a single tuple of arrays to be stacked in sequence.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & Description\\\\\n    \\hline\n    % % Shaping methods, already discussed\n    % \\li{reshape()} & Return a view of the array with a changed shape.\\\\\n    % \\li{ravel()} & Make a flattened version of an array, return a view if possible.\\\\\n    % \\li{transpose()} & Permute the dimensions of the array (also \\li{ndarray.T}).\\\\\n    % \\hline\n    \\li{concatenate()} & Join a sequence of arrays along an existing axis\\\\\n    \\li{hstack()} & Stack arrays in sequence horizontally (column wise).\\\\\n    \\li{vstack()} & Stack arrays in sequence vertically (row wise).\\\\\n    \\li{column_stack()} & Stack 1-D arrays as columns into a 2-D array.\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n>>> A = np.arange(6).reshape((2,3))\n>>> B = np.zeros((4,3))\n\n# vstack() stacks arrays vertically (row-wise).\n>>> np.vstack((A,B,A))\narray([[ 0.,  1.,  2.],             # A\n       [ 3.,  4.,  5.],\n       [ 0.,  0.,  0.],             # B\n       [ 0.,  0.,  0.],\n       [ 0.,  0.,  0.],\n       [ 0.,  0.,  0.],\n       [ 0.,  1.,  2.],             # A\n       [ 3.,  4.,  5.]])\n\n>>> A = A.T\n>>> B = np.ones((3,4))\n\n# hstack() stacks arrays horizontally (column-wise).\n>>> np.hstack((A,B,A))\narray([[ 0.,  3.,  1.,  1.,  1.,  1.,  0.,  3.],\n       [ 1.,  4.,  1.,  1.,  1.,  1.,  1.,  4.],\n       [ 2.,  5.,  1.,  1.,  1.,  1.,  2.,  5.]])\n\n# column_stack() stacks arrays horizontally, including 1-D arrays.\n>>> np.column_stack((A, np.zeros(3), np.ones(3), np.full(3, 2)))\narray([[ 0.,  3.,  0.,  1.,  2.],\n       [ 1.,  4.,  0.,  1.,  2.],\n       [ 2.,  5.,  0.,  1.,  2.]])\n\\end{lstlisting}\n%\nSee \\url{http://docs.scipy.org/doc/numpy-1.10.1/reference/routines.array-manipulation.html} for more array manipulation routines and documentation.\n\n\\begin{problem} % Simple Matrix Equation 4\nWrite a function that defines the following matrices as NumPy arrays.\n\\begin{align*}\nA = \\left[\\begin{array}{rrr}\n0 & 2 & 4\\\\\n1 & 3 & 5\\end{array}\\right]\n&&\nB = \\left[\\begin{array}{rrr}\n3 & 0 & 0\\\\\n3 & 3 & 0\\\\\n3 & 3 & 3\\end{array}\\right]\n&&\nC = \\left[\\begin{array}{rrr}\n-2 & 0 & 0\\\\\n0 & -2 & 0\\\\\n0 & 0 & -2\\end{array}\\right]\n\\end{align*}\nUse NumPy's stacking functions to create and return the block matrix:\n\\begin{align*}\n\\left[\\begin{array}{ccc}\n\\0 & A\\trp & I\\\\\nA & \\0 & \\0 \\\\\nB & \\0 & C \\end{array}\\right],\n\\end{align*}\nwhere $I$ is the $3\\times 3$ identity matrix and each $\\0$ is a matrix of all zeros of appropriate size.\n\nA block matrix of this form is used in the interior point method for linear optimization.\n\\end{problem}\n\n\\subsection*{Array Broadcasting} % --------------------------------------------\n\nMany matrix operations make sense only when the two operands have the same shape, such as element-wise addition.\n\\emph{Array broadcasting} extends such operations to accept some (but not all) operands with different shapes, and occurs automatically whenever possible.\n\nSuppose, for example, that we would like to add different values to the columns of an $m\\times n$ matrix $A$.\nAdding a 1-D array $x$ with the $n$ entries to $A$ will automatically do this correctly.\nTo add different values to the different rows of $A$, first reshape a 1-D array of $m$ values into a column array.\nBroadcasting then correctly takes care of the operation.\n\nBroadcasting can also occur between two 1-D arrays, once they are reshaped appropriately.\n\n\\begin{lstlisting}\n>>> A = np.arange(12).reshape((4,3))\n>>> x = np.arange(3)\n>>> A\narray([[ 0,  1,  2],\n       [ 3,  4,  5],\n       [ 6,  7,  8],\n       [ 9, 10, 11]])\n>>> x\narray([0, 1, 2])\n\n# Add the entries of 'x' to the corresponding columns of 'A'.\n>>> A + x\narray([[ 0,  2,  4],\n       [ 3,  5,  7],\n       [ 6,  8, 10],\n       [ 9, 11, 13]])\n\n>>> y = np.arange(0, 40, 10).reshape((4,1))\n>>> y\narray([[ 0],\n       [10],\n       [20],\n       [30]])\n\n# Add the entries of 'y' to the corresponding rows of 'A'.\n>>> A + y\narray([[ 0,  1,  2],\n       [13, 14, 15],\n       [26, 27, 28],\n       [39, 40, 41]])\n\n# Add 'x' and 'y' together with array broadcasting.\n>>> x + y\narray([[ 0,  1,  2],\n       [10, 11, 12],\n       [20, 21, 22],\n       [30, 31, 32]])\n\\end{lstlisting}\n\n\\section*{Numerical Computing with NumPy} % ===================================\n\n\\subsection*{Universal Functions} % -------------------------------------------\n\nA \\emph{universal function} is one that operates on an entire array element-wise.\nUniversal functions are significantly more efficient than using a loop to operate individually on each element of an array.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Function & Description \\\\\n    \\hline\n    \\li{<<abs()>>} or \\li{absolute()} & Calculate the absolute value element-wise. \\\\\n    % \\li{conj()} & Return the complex conjugate of the array.\\\\\n    \\li{exp()} / \\li{log()} & Exponential ($e^x$) / natural log element-wise.\\\\\n    \\li{maximum()} / \\li{minimum()}& Element-wise maximum / minimum of two arrays.\\\\\n    % \\li{<<round()>>} & Return a rounded version of the array.\\\\\n    \\li{sqrt()} & The positive square-root, element-wise.\\\\\n    \\li{sin()}, \\li{cos()}, \\li{tan()}, etc. & Element-wise trigonometric operations.\n\\end{tabular}\n\\label{table:ufuncs}\n\\end{table}\n\n\\begin{lstlisting}\n>>> x = np.arange(-2,3)\n>>> print(x, np.<<abs>>(x))             # Like np.array([abs(i) for i in x]).\n[-2 -1  0  1  2] [2 1 0 1 2]\n\n>>> np.sin(x)                       # Like np.array([math.sin(i) for i in x]).\narray([-0.90929743, -0.84147098,  0.        ,  0.84147098,  0.90929743])\n\\end{lstlisting}\n\nSee \\url{http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs} for a more comprehensive list of universal functions.\n\n\\begin{warn}\nThe \\li{math} module has many useful functions for numerical computations.\nHowever, most of these functions can only act on single numbers, not on arrays.\nNumPy functions can act on either scalars or entire arrays, but \\li{math} functions tend to be a little faster for acting on scalars.\n\\begin{lstlisting}\n>>> import math\n\n# Math and NumPy functions can both operate on scalars.\n>>> print(math.exp(3), np.exp(3))\n20.085536923187668 20.0855369232\n\n# However, math functions cannot operate on arrays.\n>>> x = np.arange(-2, 3)\n>>> np.tan(x)\narray([ 2.18503986, -1.55740772,  0.        ,  1.55740772, -2.18503986])\n>>> math.tan(x)\n<<Traceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\nTypeError: only length-1 arrays can be converted to Python scalars>>\n\\end{lstlisting}\nAlways use universal NumPy functions, not the \\li{math} module, when working with arrays.\n\\end{warn}\n\n\\subsection*{Other Array Methods} % -------------------------------------------\n\nThe \\li{np.ndarray} class itself has many useful methods for numerical computations.\n\n\\begin{table}[H]\n\\centering\n\\begin{tabular}{r|l}\n    Method & Returns \\\\\n    \\hline\n    \\li{<<all()>>} & \\li{True} if all elements evaluate to \\li{True}.\\\\\n    \\li{<<any()>>} & \\li{True} if any elements evaluate to \\li{True}.\\\\\n    \\li{argmax()} & Index of the maximum value.\\\\\n    \\li{argmin()} & Index of the minimum value.\\\\\n    \\li{argsort()} & Indices that would sort the array.\\\\\n    \\li{clip()} & restrict values in an array to fit within a given range\\\\\n    \\li{<<max()>>} & The maximum element of the array.\\\\\n    \\li{mean()} & The average value of the array.\\\\\n    \\li{<<min()>>} & The minimum element of the array.\\\\\n    \\li{sort()} & Return nothing; sort the array in-place.\\\\\n    \\li{std()} & The standard deviation of the array.\\\\\n    \\li{<<sum()>>} & The sum of the elements of the array.\\\\\n    % \\li{trace()} & return the sum of the elements along the main diagonal\\\\\n    \\li{var()} & The variance of the array.\\\\\n\\end{tabular}\n\\label{table:ndarraymethods}\n\\end{table}\n\nEach of these \\li{np.ndarray} methods has an equivalent NumPy function.\nFor example, \\li{A.<<max>>()} and \\li{np.<<max>>(A)} operate the same way.\nThe one exception is the \\li{sort()} function: \\li{np.sort()} returns a sorted copy of the array, while \\li{A.sort()} sorts the array in-place and returns nothing.\n\nEvery method listed can operate \\emph{along an axis} via the keyword argument \\li{axis}.\nIf \\li{axis} is specified for a method on an $n$-D array, the return value is an $(n-1)$-D array, the specified axis having been collapsed in the evaluation process.\nIf \\li{axis} is not specified, the return value is usually a scalar.\nRefer to the NumPy Visual Guide in the appendix for more visual examples.\n\n\\begin{lstlisting}\n>>> A = np.arange(9).reshape((3,3))\n>>> A\narray([[0, 1, 2],\n       [3, 4, 5],\n       [6, 7, 8]])\n\n# Find the maximum value in the entire array.\n>>> A.<<max>>()\n8\n\n# Find the minimum value of each column.\n>>> A.<<min>>(axis=0)                   # np.array([min(A[:,i]) for i in range(3)])\narray([0, 1, 2])\n\n# Compute the sum of each row.\n>>> A.<<sum>>(axis=1)                   # np.array([sum(A[i,:]) for i in range(3)])\narray([3, 12, 21])\n\\end{lstlisting}\n\nSee \\url{http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html} for a more comprehensive list of array methods.\n\n\\begin{problem} % Row stochastic matrices.\nA matrix is called \\emph{row-stochastic}\\footnote{Similarly, a matrix is called \\emph{column-stochastic} if its columns each sum to $1$.} if its rows each sum to $1$.\nStochastic matrices are fundamentally important for finite discrete random processes and some machine learning algorithms.\n\nWrite a function than accepts a matrix (as a 2-D array).\nDivide each row of the matrix by the row sum and return the new row-stochastic matrix.\nUse array broadcasting and the \\li{axis} argument instead of a loop.\n\\end{problem}\n\n\\begin{problem} % Project Euler #11\nThis problem comes from \\url{https://projecteuler.net}.\n\nIn the $20 \\times 20$ grid below, four numbers along a diagonal line have been marked in red.\n%\n\\begin{align*}\n\\centering\n\\arraycolsep=1.4pt\\begin{array}{cccccccccccccccccccc}\n08&02&22&97&38&15&00&40&00&75&04&05&07&78&52&12&50&77&91&08\\\\\n49&49&99&40&17&81&18&57&60&87&17&40&98&43&69&48&04&56&62&00\\\\\n81&49&31&73&55&79&14&29&93&71&40&67&53&88&30&03&49&13&36&65\\\\\n52&70&95&23&04&60&11&42&69&24&68&56&01&32&56&71&37&02&36&91\\\\\n22&31&16&71&51&67&63&89&41&92&36&54&22&40&40&28&66&33&13&80\\\\\n24&47&32&60&99&03&45&02&44&75&33&53&78&36&84&20&35&17&12&50\\\\\n32&98&81&28&64&23&67&10&\\textcolor{red}{26}&38&40&67&59&54&70&66&18&38&64&70\\\\\n67&26&20&68&02&62&12&20&95&\\textcolor{red}{63}&94&39&63&08&40&91&66&49&94&21\\\\\n24&55&58&05&66&73&99&26&97&17&\\textcolor{red}{78}&78&96&83&14&88&34&89&63&72\\\\\n21&36&23&09&75&00&76&44&20&45&35&\\textcolor{red}{14}&00&61&33&97&34&31&33&95\\\\\n78&17&53&28&22&75&31&67&15&94&03&80&04&62&16&14&09&53&56&92\\\\\n16&39&05&42&96&35&31&47&55&58&88&24&00&17&54&24&36&29&85&57\\\\\n86&56&00&48&35&71&89&07&05&44&44&37&44&60&21&58&51&54&17&58\\\\\n19&80&81&68&05&94&47&69&28&73&92&13&86&52&17&77&04&89&55&40\\\\\n04&52&08&83&97&35&99&16&07&97&57&32&16&26&26&79&33&27&98&66\\\\\n88&36&68&87&57&62&20&72&03&46&33&67&46&55&12&32&63&93&53&69\\\\\n04&42&16&73&38&25&39&11&24&94&72&18&08&46&29&32&40&62&76&36\\\\\n20&69&36&41&72&30&23&88&34&62&99&69&82&67&59&85&74&04&36&16\\\\\n20&73&35&29&78&31&90&01&74&31&49&71&48&86&81&16&23&57&05&54\\\\\n01&70&54&71&83&51&54&69&16&92&33&48&61&43&52&01&89&19&67&48\n\\end{array}\n\\end{align*}\n\nThe product of these numbers is $26 \\times 63 \\times 78 \\times 14 = 1788696$.\nWrite a function that returns the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the grid.\n\nFor convenience, this array has been saved in the file \\texttt{grid.npy}.\nUse the following syntax to extract the array:\n\n\\begin{lstlisting}\n>>> grid = np.load(\"grid.npy\")\n\\end{lstlisting}\n\nOne way to approach this problem is to iterate through the rows and columns of the array, checking small slices of the array at each iteration and updating the current largest product.\nArray slicing, however, provides a much more efficient solution.\n\nThe na\\\"{i}ve method for computing the greatest product of four adjacent numbers in a horizontal row might be as follows:\n\n\\begin{lstlisting}\n>>> winner = 0\n>>> for i in range(20):\n...     for j in range(17):\n...         winner = max(np.prod(grid[i,j:j+4]), winner)\n...\n>>> winner\n48477312\n\\end{lstlisting}\n\nInstead, use array slicing to construct a single array where the $(i,j)$th entry is the product of the four numbers to the right of the $(i,j)$th entry in the original grid.\nThen find the largest element in the new array.\n\n\\begin{lstlisting}\n>>> np.<<max>>(grid[:,:-3] * grid[:,1:-2] * grid[:,2:-1] * grid[:,3:])\n48477312\n\\end{lstlisting}\n\nUse slicing to similarly find the greatest products of four vertical, right diagonal, and left diagonal adjacent numbers.\n\\\\\n(Hint: Consider drawing the portions of the grid that each slice in the above code covers, like the examples in the visual guide.\nThen draw the slices that produce vertical, right diagonal, or left diagonal sequences, and translate the pictures into slicing syntax.)\n\\end{problem}\n\n\\begin{warn}\nAll of the examples in this lab use NumPy arrays, objects of type \\li{np.ndarray}.\nNumPy also has a ``matrix'' data structure called \\li{np.matrix} that was built specifically for MATLAB users who are transitioning to Python and NumPy.\nIt behaves slightly differently than the regular array class, and can cause some unexpected and subtle problems.\n\nFor consistency (and your sanity), \\textbf{never} use a NumPy matrix; \\textbf{always} use NumPy arrays.\nIf necessary, cast a matrix object as an array with \\li{np.array()}.\n\\end{warn}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Random Sampling} % -----------------------------------------------\n\nThe submodule \\li{np.random} holds many functions for creating arrays of random values chosen from probability distributions such as the uniform, normal, and multinomial distributions.\nIt also contains some utility functions for getting non-distributional random samples, such as random integers or random samples from a given array.\n\n\\begin{table}[H] % The np.random submodule.\n\\begin{tabular}{r|l}\nFunction & Description\\\\\n\\hline\n\\li{choice()} & Take random samples from a 1-D array.\\\\\n\\li{random()} & Uniformly distributed floats over [0, 1).\\\\\n\\li{randint()} & Random integers over a half-open interval.\\\\\n\\li{random_integers()} & Random integers over a closed interval.\\\\\n\\li{randn()} & Sample from the standard normal distribution.\\\\\n\\li{permutation()} & Randomly permute a sequence / generate a random sequence.\\\\\n\\\\\nFunction & Distribution\\\\\n\\hline\n\\li{beta()} & Beta distribution over [0, 1].\\\\\n\\li{binomial()} & Binomial distribution.\\\\\n\\li{exponential()} & Exponential distribution.\\\\\n\\li{gamma()} & Gamma distribution.\\\\\n\\li{geometric()} & Geometric distribution.\\\\\n\\li{multinomial()} & Multivariate generalization of the binomial distribution.\\\\\n\\li{multivariate_normal()} & Multivariate generalization of the normal distribution.\\\\\n\\li{normal()} & Normal / Gaussian distribution.\\\\\n\\li{poisson()} & Poisson distribution.\\\\\n\\li{uniform()} & Uniform distribution.\n\\end{tabular}\n\\end{table}\n\nNote that many of these functions have counterparts in the standard library's \\li{random} module.\nThese NumPy functions, however, are much better suited for working with large collections of random samples.\n\n\\begin{lstlisting}\n# 5 uniformly distributed values in the interval [0, 1).\n>>> np.random.random(5)\narray([ 0.21845499,  0.73352537,  0.28064456,  0.66878454,  0.44138609])\n\n# A 2x5 matrix (2-D array) of integers in the interval [10, 20).\n>>> np.random.randint(10, 20, (2,5))\narray([[17, 12, 13, 13, 18],\n       [16, 10, 12, 18, 12]])\n\\end{lstlisting}\n\n\n\n\\subsection*{Saving and Loading Arrays} % -------------------------------------\n\nIt is often useful to save an array as a file for later use.\nNumPy provides several easy methods for saving and loading array data.\n\n\\begin{table}[H]\n\\begin{tabular}{r|l}\nFunction & Description\\\\\n\\hline\n\\li{save()} & Save a single array to a \\texttt{.npy} file.\\\\\n\\li{savez()} & Save multiple arrays to a \\texttt{.npz} file.\\\\\n\\li{savetxt()} & Save a single array to a \\texttt{.txt} file.\\\\\n\\hline\n\\li{load()} & Load and return an array or arrays from a \\texttt{.npy} or \\texttt{.npz} file.\\\\\n\\li{loadtxt()} & Load and return an array from a text file.\n\\end{tabular}\n\\end{table}\n\n\\begin{lstlisting}\n# Save a 100x100 matrix of uniformly distributed random values.\n>>> x = np.random.random((100,100))\n>>> np.save(\"uniform.npy\", x)       # Or np.savetxt(\"uniform.txt\", x).\n\n# Read the array from the file and check that it matches the original.\n>>> y = np.load(\"uniform.npy\")      # Or np.loadtxt(\"uniform.txt\").\n>>> np.allclose(x, y)               # Check that x and y are close entry-wise.\n<<True>>\n\\end{lstlisting}\n\nTo save several arrays to a single file, specify a keyword argument for each array in \\li{np.savez()}.\nThen \\li{np.load()} will return a dictionary-like object with the keyword parameter names from the save command as the keys.\n\n\\begin{lstlisting}\n# Save two 100x100 matrices of normally distributed random values.\n>>> x = np.random.randn(100,100)\n>>> y = np.random.randn(100,100)\n>>> np.savez(\"normal.npz\", first=x, second=y)\n\n# Read the arrays from the file and check that they match the original.\n>>> arrays = np.load(\"normal.npz\")\n>>> np.allclose(x, arrays[\"first\"])\n<<True>>\n>>> np.allclose(y, arrays[\"second\"])\n<<True>>\n\\end{lstlisting}\n\n\\begin{comment}\n\\subsection*{Polynomials} % ---------------------------------------------------\n\nThe \\li{np.poly1d} object represents a polynomial in NumPy.\nThe constructor is called with the coefficients of the desired polynomial.\n\n\\begin{lstlisting}\n>>> poly = np.poly1d([3, 5, 1, 2, 0, 1])\n>>> print(poly)\n   5     4     3     2\n3 x + 5 x + 1 x + 2 x + 1\n\\end{lstlisting}\n\nThe object \\li{poly} represents the polynomial $3x^5+5x^4+x^3+2x^2+1$.\nNumPy provides many functions to operate on \\li{poly1d} objects (see \\url{http://docs.scipy.org/doc/numpy/reference/routines.polynomials.polynomial.html}).\n\nRecall that\n\\[\ne^x = \\sum_{n=0}^{\\infty} \\frac{x^n}{n!}.\n\\]\nThe following function evaluates the $N$th partial sum of this series at the value $a$.\n\n\\begin{lstlisting}\n>>> from scipy.special import factorial\n>>> def exp(a, N=25):\n...     \"\"\"Construct an array in reverse order from n to 0.\"\"\"\n...     n = np.arange(N, -1, -1)\n...     # Use broadcasting to compute coefficients\n...     coeffs = 1. / factorial(n)\n...     poly = np.poly1d(coeffs)        # Make a polynomial object.\n...     return poly(a)\n...\n\\end{lstlisting}\n\nThe last two lines can be condensed by using the following command:\n\n\\begin{lstlisting}\nnp.polyval(p, a)\n\\end{lstlisting}\n\n\\begin{problem}\n\\leavevmode\n\\begin{enumerate}\n\\item Use NumPy's polynomial objects to approximate the following series.\n\\[\n\\arcsin x = \\sum_{n=0}^{\\infty} \\frac{\\left(2 n\\right) ! x^{2 n + 1}}{\\left(2 n + 1\\right)\\left(n!\\right)^2 4^n}\n\\]\nThis series converges on $(-1, 1)$. Use your series approximation to approximate $\\pi$. Hint: think of the powers of $x$ that\nare not included in the series as having zero coefficients.\n\n\\item The lambert W function is the inverse of $x e^x$.\nIts Taylor series is below (note the index starts at 1).\n\\[\nW(x) = \\sum_{n=1}^{\\infty} \\frac{\\left(-n\\right)^{n-1} x^n}{n!}\n\\]\nThis series has a radius of convergence of $\\frac{1}{e}$.\nUse the series to approximate a number $x$ such that $x e^x = \\frac{1}{4}$.\nVerify that your approximation is close.\n\\end{enumerate}\n\\end{problem}\n\\end{comment}\n\n\\begin{comment}\n\\subsection*{Iterating Through Arrays} % --------------------------------------\n\nIterating through an array (using a \\li{for} loop) negates most of the advantages of using NumPy.\nAvoid iterating through arrays as much as possible by using array broadcasting and universal functions.\nWhen absolutely necessary, use \\li{np.nditer()} to create an efficient iterator for the array.\nSee \\url{http://docs.scipy.org/doc/numpy/reference/arrays.nditer.html} for details.\n\\end{comment}\n", "meta": {"hexsha": "9135a01b0ea45a64dd42cbc82dee097d93e245fc", "size": 42413, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PythonEssentials/NumpyIntro/NumpyIntro.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": "PythonEssentials/NumpyIntro/NumpyIntro.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": "PythonEssentials/NumpyIntro/NumpyIntro.tex", "max_forks_repo_name": "frigusgulo/Labs", "max_forks_repo_head_hexsha": "58faeab611e2d54bf2debded58d6e13db40f4146", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.9110091743, "max_line_length": 275, "alphanum_fraction": 0.6448258789, "num_tokens": 13379, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.810478913248044, "lm_q2_score": 0.9314625102975306, "lm_q1q2_score": 0.7549307230772375}}
{"text": "\\section{Fourier Sampling}\n\nThe Nyquist-Shannon sampling theorem states that a signal that contains\nno frequencies higher than $B$ is completely determined by sampling it\nat a rate of $1/(2B)$.  \n\nIn the context of simulating observations with an interferometer, this\nmeans that if our instrument samples only to a spatial frequency of\n\\math{\\umax}, then an image sampled at $1/({2\\umax})$ will contain all the\ninformation that the interferometer can detect.\n \nSimulated images in \\climax\\ will therefore be pixelized with $\\mdx =\n1/({2\\umax})$, with $x_{\\rm max}$ given by the specified correlation\nlength in the Fourier plane.\n\n", "meta": {"hexsha": "d4d1f0a003f60a1ab2c66dd61779e69b1f836f85", "size": 630, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "help/intro.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/intro.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/intro.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": 39.375, "max_line_length": 74, "alphanum_fraction": 0.7698412698, "num_tokens": 156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9399133447766225, "lm_q2_score": 0.8031738057795403, "lm_q1q2_score": 0.7549137782272172}}
{"text": "\\documentclass[11pt, a4paper]{article}\n\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{pgfplots}\n\n\\begin{document}\n\n\\title{LOGISTIC REGRESSION}\n\\date{}\n\\maketitle\n\nThe classification problem can be written as follows:\n\n\\begin{align*}\n\t\\mathbf{Y} = \\operatorname*{argmax}_{y_k}\\left\\{    \n\t\\mathbf{P}(\\mathbf{Y}=y_k\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) \n\t\\right.                                             \n\\end{align*}\n\n``Generative'' classifiers like the Naive Bayes classifier solve this problem using\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=y_k\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) = \\frac{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p|\\mathbf{Y}=y_k) \\times \\mathbf{P}(\\mathbf{Y}=y_k)}{\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p)} \\\\\n\\end{align*}\n\nand modelling\n\n\\begin{align*}\n\t\\mathbf{P}(x_1,\\ x_2,\\ ...\\ x_p|\\mathbf{Y}=y_k) \n\\end{align*}\n\nOn the other hand, ``Discriminative'' classifiers like Logistic Regression model\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=y_k\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) \n\\end{align*}\n\ndirectly. \n\n\\section{Probability Model}\n\nAssume the binary classification problem. Logistic Regression assumes:\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=1\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) = \\frac{e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p}}{1 + e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p}} \n\\end{align*}\n\nTo simplify this equation, the following notation is used,\n\n\\begin{align*}\n\t\\boldsymbol{\\beta} = \\begin{pmatrix} \\beta_0 \\\\ \\beta_1 \\\\ . \\\\ . \\\\ .  \\\\ \\beta_p \\end{pmatrix} \\ \\text{and}\\ \n\t\\boldsymbol{x} = \\begin{pmatrix} 0           \\\\ x_1 \\\\ . \\\\ . \\\\ .  \\\\ x_p \\end{pmatrix}\n\\end{align*}\n\nThe equation now becomes,\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=1|\\mathbf{X} = \\boldsymbol{x}) = \\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}} \n\\end{align*}\n\nThe other half of this equation is,\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=0|\\mathbf{X} = \\boldsymbol{x}) = \\frac{1}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}} \n\\end{align*}\n\n\nThese half equations can be combined as follows,\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=y|\\mathbf{X} = \\boldsymbol{x}) = \\left(\\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}}\\right) ^y \\left(\\frac{1}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x}}}\\right)^{1-y} \n\\end{align*}\n\n\\section{Maximum Likelihood estimation}\n\nIf the form of a Probability Density Function(PDF) is known and some independent and identically distributed(i.i.d.) observations are given, Maximum Likelihood Estimation(MLE) can be used to estimate the optimal parameters of the PDF.\n\nFor example, consider a random variable whose PDF is known to be Gaussian,\n\n\\begin{align*}\n\tf(x|\\mu, \\sigma^2) = \\frac{1}{\\sqrt{2 \\pi \\sigma^2}} e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}} \n\\end{align*}\n\nIf some i.i.d. observations $x_1, x_2, \\ ...\\ x_n$ are given, likelihood can be written as follows,\n\n\\begin{align*}\n\tl(\\mu, \\sigma^2) & = P(x_1, x_2,\\ ... \\ x_n|\\mu, \\sigma^2) \\\\\n\t                 & = \\prod_i P(x_i|\\mu, \\sigma^2)          \n\\end{align*}\n\nLog likelihood is more desirable to work with most of the times and expressed as follows,\n\n\\begin{align*}\n\tL(\\mu, \\sigma^2) & = \\sum_i log(P(x_i|\\mu, \\sigma^2))                                        \\\\\n\t                 & = -\\frac{n}{2} log(2 \\pi \\sigma^2) - \\sum_i \\frac{(x_i-\\mu)^2}{2\\sigma^2} \n\\end{align*}\n\nTo maximize log likelihood, its derivative must be equated to zero.\n\n\\begin{align*}\n\t\\frac{\\partial L(\\mu, \\sigma^2)}{\\partial \\mu}                                                                    & = 0 \\\\\n\t\\frac{\\partial}{\\partial \\mu}\\left(-\\frac{n}{2} log(2 \\pi \\sigma^2) - \\sum_i \\frac{(x_i-\\mu)^2}{2\\sigma^2}\\right) & = 0 \\\\\n\t\\sum_i (x_i - \\mu)                                                                                                & = 0 \\\\\n\t\\mu = \\frac{1}{n} \\sum_i x_i\n\\end{align*}\n\nSo, in this case, MLE estimates $\\mu$ to be average of the observations.\n\n\\section{MLE application to Logistic Regression}\n\n\\begin{align*}\n\tL(\\boldsymbol{\\beta}) & = \\sum_i log\\left\\{ \\left(\\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}\\right) ^{y_i} \\left(\\frac{1}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}\\right)^{1-y_i}\\right\\} \\\\\n\t                      & = \\sum_i \\left(y_i \\boldsymbol{\\beta}^T\\boldsymbol{x_i} - log(1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}})\\right)                                                                                                        \n\\end{align*}\n\n\nTaking the derivative and equating it to zero,\n\n\n\\begin{align*}\n\t\\frac{\\partial \\boldsymbol{L}(\\boldsymbol{\\beta})} {\\partial \\boldsymbol{\\beta}}                                                                          & = 0 \\\\\n\t\\sum_i \\left(y_i \\boldsymbol{x_i} - \\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}} \\boldsymbol{x_i}\\right) & = 0 \\\\\n\\end{align*}\n\nUnfortunately, no closed form solution exists in this case and hence this equation must be solved by numerical methods like the Newton-Raphson method. The objective function is always convex, so there are no problems of local maxima.\n\n\\section {Newton-Raphson Method}\n\nNewton-Raphson method successively finds better approximations to the root of a real valued function.\n\n\\subsection {Single varable}\n\n\\begin{figure}[htbp]\n\t\\centering\n\t\\begin{tikzpicture}\n\t\t\\draw[-latex] (0,0) -- (8,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\t\t\t\t\n\t\t\\draw[line width=1pt] (1,-1) .. controls (5,1) .. (6,4); \n\t\t\t\t\t\t\n\t\t\\draw[] (5.5,2.3) -- (4,0);\n\t\t\\draw[] (5,1.6) -- (5,0);\t\n\t\t\t\t\t\t\n\t\t\\draw (5, 4) node [above right] {$y = f(x)$};'\n\t\t\\draw (4, 0) node [below] {$x_{n+1}$};\n\t\t\\draw (5, 0) node [below] {$x_n$};\n\t\t\\draw (5, 1.6) node [right] {($x_n, f(x_n))$};\n\t\\end{tikzpicture}\n\\end{figure}\n\n\\begin{align*}\n\tf(x+\\Delta x) \\approx f(x) + f'(x) \\Delta x \n\\end{align*}\n\nSetting $f(x+\\Delta x) = 0$ to find a better approximation of the root,\n\n\\begin{align*}\n\tf(x) + f'(x) \\Delta x & \\approx 0                    \\\\\n\t\\Delta x              & \\approx - \\frac{f(x)}{f'(x)} \\\\\n\tx_{n+1} - x_{n}       & \\approx - \\frac{f(x)}{f'(x)} \n\\end{align*}\n\nThe method starts with an initial guess $x_0$ and then applies the above updation logic to come up with $x_1,\\ x_2,\\ ...$ until convergence.\n\n\\subsection{Multiple Variables}\n\n\\begin{align*}\n\tf_1(x+\\Delta x, y+\\Delta y) \\approx f_1(x, y) + \\begin{pmatrix} \\frac{\\partial f_1}{\\partial x}, \\frac{\\partial f_1}{\\partial y} \\end{pmatrix} \\begin{pmatrix} \\Delta x \\\\ \\Delta y \\end{pmatrix} \\\\\n\tf_2(x+\\Delta x, y+\\Delta y) \\approx f_2(x, y) + \\begin{pmatrix} \\frac{\\partial f_2}{\\partial x}, \\frac{\\partial f_2}{\\partial y} \\end{pmatrix} \\begin{pmatrix} \\Delta x \\\\ \\Delta y \\end{pmatrix} \t\n\\end{align*}\n\nThese two equations can be written in matrix form as follows,\n\n\\begin{align*}\n\t\\begin{pmatrix} f_1(x+\\Delta x, y+\\Delta y) \\\\ f_2(x+\\Delta x, y+\\Delta y)\\end{pmatrix} \\approx \\begin{pmatrix} f_1(x, y) \\\\ f_2(x, y) \\end{pmatrix} + \\begin{pmatrix} \\frac{\\partial f_1}{\\partial x}, \\frac{\\partial f_1}{\\partial y} \\\\ \\frac{\\partial f_2}{\\partial x}, \\frac{\\partial f_2}{\\partial y}\\end{pmatrix} \\begin{pmatrix} \\Delta x \\\\ \\Delta y \\end{pmatrix} \n\\end{align*}\n\nSetting the l.h.s to zero and solving,\n\n\\begin{align*}\n\t\\begin{pmatrix} \\Delta x \\\\ \\Delta y \\end{pmatrix}  \\approx -\\begin{pmatrix} \\frac{\\partial f_1}{\\partial x}, \\frac{\\partial f_1}{\\partial y} \\\\ \\frac{\\partial f_2}{\\partial x}, \\frac{\\partial f_2}{\\partial y}\\end{pmatrix}^{-1} \\begin{pmatrix} f_1(x, y) \\\\ f_2(x, y) \\end{pmatrix}\n\\end{align*}\n\nThe $2\\times2$ matrix of partial derivatives is called Jacobian and denoted by $J$. The same idea can be extended to any number of variables.\n\n\\section{Newton-Raphson application to Logistic Regression}\n\nTo find optimal parameter $\\beta$ for Logistic Regression using MLE, the roots of the following equation must be found,\n\n\\begin{align*}\n\t\\frac{\\partial \\boldsymbol{L}(\\boldsymbol{\\beta})} {\\partial \\boldsymbol{\\beta}} & = 0 \\\\\n\\end{align*}\n\nThe Newton-Raphson update rule for this has the form,\n\n\\begin{align*}\n\t\\Delta \\boldsymbol{\\beta} & = -\\left(\\frac{\\partial^2 L(\\boldsymbol{\\beta})}{\\partial \\boldsymbol{\\beta} \\partial \\boldsymbol{\\beta}^T}\\right)^{-1} \\frac{\\partial \\boldsymbol{L}(\\boldsymbol{\\beta})} {\\partial \\boldsymbol{\\beta}}                                                                                                                                                                                                                \\\\\n\t\\Delta \\boldsymbol{\\beta} & = \\left[ \\sum_i \\left(\\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}\\right) \\left(\\frac{1}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}\\right) \\boldsymbol{x_i} \\boldsymbol{x_i}^T \\right]^{-1} \\left[ \\sum_i \\left(y_i \\boldsymbol{x_i} - \\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}} \\boldsymbol{x_i}\\right)\\right] \n\\end{align*} \n\nUsing the following notation\n\n\\begin{align*}\n\t\\boldsymbol{X} & = \\begin{pmatrix} \\boldsymbol{x_1}, \\boldsymbol{x_2}, .., \\boldsymbol{x_N}\\end{pmatrix}         \\\\\n\tP_i            & = \\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}} \\\\\n\t\\boldsymbol{Y} & = \\begin{pmatrix} y_1                                                                           \\\\ y_2 \\\\ . \\\\ . \\\\ . \\\\ y_N \\end{pmatrix} \n\t\\boldsymbol{P} = \\begin{pmatrix} P_1 \\\\ P_2 \\\\ . \\\\ . \\\\ . \\\\ P_N \\end{pmatrix}\n\\end{align*} \n\nthe update rule can be rewritten as\n\n\\begin{align*}\n\t\\Delta \\boldsymbol{\\beta} = [\\boldsymbol{X}\\boldsymbol{W}\\boldsymbol{X}^T]^{-1}\\boldsymbol{X}(\\boldsymbol{Y}-\\boldsymbol{P}) \n\\end{align*}\n\nwhere $\\boldsymbol{W}$ is a $N\\times N$ diagonal matrix of $P_i(1-P_i)$s with N as total number of $\\boldsymbol{x_i}^T, y_i$ pairs. This equation bears a surprising resemblance with the OLS solution of the problem of linear regression. In fact $\\Delta \\boldsymbol{\\beta}$ is solutions to the following linear regression problem.\n\n\\begin{align*}\n\t(\\boldsymbol{Y}-\\boldsymbol{P}) = \\boldsymbol{W}\\boldsymbol{X}^T \\Delta \\boldsymbol{\\beta} \n\\end{align*}\n\n\nHence, the update in each iteration of Newton-Raphson method for Logistic Regression is the solution of a weighted least square linear regression problem where the response is the difference between the observed response and estimated probability of the Logistic Regression model.\n\n\n\\section{Interpretation}\n\n\\subsection{Coefficients}\n\nRewriting the base equations for Logistic Regression\n\n\\begin{align*}\n\t\\mathbf{P}(\\mathbf{Y}=1\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) = \\frac{e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p}}{1 + e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p}} \\\\\n\t\\mathbf{P}(\\mathbf{Y}=0\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) = \\frac{1}{1 + e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p}}                                                 \n\\end{align*}\n\nDividing both equations\n\n\\begin{align*}\n\t\\frac{\\mathbf{P}(\\mathbf{Y}=1\\ |\\ x_1,\\ x_2,\\ ...\\ x_p)}{\\mathbf{P}(\\mathbf{Y}=0\\ |\\ x_1,\\ x_2,\\ ...\\ x_p) } = e^{\\beta_0 + \\beta_1 x_1 +\\  ...\\  + \\beta_p x_p} \n\\end{align*}\n\nThe left side of the equation: the ratio of the probability of an event occurring to the probability of it not occurring is called the ``odds\" for the event. Hence, the odds of the event $\\mathbf{Y}=1$  is equal to $e$ raised to a linear function of the input features. Every other thing remaining equal, if one of the input features is increased by one unit, the odds are multiplied by $e$ raised to the coefficient of the input features. Positive coefficients have a multiplicative effect on the odds, but negative coefficients have a divisive effect.\n\n\\subsection{Coordinate Freedom}\n\nRewriting the MLE solution equation again,\n\n\\begin{align*}\n\t\\sum_i \\left(y_i \\boldsymbol{x_i} - \\frac{e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}}{1 + e^{\\boldsymbol{\\beta}^T\\boldsymbol{x_i}}} \\boldsymbol{x_i}\\right) & = 0 \\\\\n\\end{align*}\n\nor \n\n\\begin{align*}\n\t\\sum_i \\left(y_i \\boldsymbol{x_i} - P_i \\boldsymbol{x_i}\\right) & = 0 \\\\\n\\end{align*}\n\nor \n\n\\begin{align*}\n\t\\boldsymbol{X}(\\boldsymbol{Y}-\\boldsymbol{P}) = 0 \n\\end{align*}\n\nIf $\\boldsymbol{P}$ satisfies $ \\boldsymbol{X}(\\boldsymbol{Y}-\\boldsymbol{P}) = 0$, then it will also satisfy $\\boldsymbol{M}\\boldsymbol{X}(\\boldsymbol{Y}-\\boldsymbol{P}) = 0$ for non singular matrix $\\boldsymbol{M}$. Since $\\boldsymbol{M}\\boldsymbol{X}$ is related to $\\boldsymbol{X}$ by linear transformations, it is clear that linear combinations of input features like rescaling and combination will not have any effect on the probabilities estimated by a Logistic Regression model. Hence, Logistic regression is a coordinate free model.\n\n\\subsection{Marginal Probability Preservation}\n\nSince the Logistic Regression model demands,\n\n\\begin{align*}\n\t\\sum_i \\left(y_i \\boldsymbol{x_i} - P_i \\boldsymbol{x_i}\\right) & = 0 \\\\\n\\end{align*}\n\nFor every feature, the sum of the input feature values corresponding to positive response will be equal to the weighted sum of the all the input feature values where the probabilities estimated by the model serve as the weights. Hence, Logistic Regression preserves marginal probabilities of the input.\n\n\\end{document}\n", "meta": {"hexsha": "6998e43523949ae16cc7431ea17d4ce4f601214f", "size": 13147, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Logistic Regression/Logistic 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": "Logistic Regression/Logistic 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": "Logistic Regression/Logistic 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": 47.1218637993, "max_line_length": 553, "alphanum_fraction": 0.6259983266, "num_tokens": 4278, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8840392863287585, "lm_q1q2_score": 0.7548924207064501}}
{"text": "\\documentclass[a4paper,11pt]{article}\n\n\\usepackage{physics}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{amsmath}\n\\usepackage{amsthm, mathtools}\n%\\usepackage{hyperref}\n\\usepackage{color}\n\\usepackage{jheppub}\n\\usepackage[T1]{fontenc} % if needed\n\n\\newcommand{\\be}{\\begin{equation}}\n\\newcommand{\\ee}{\\end{equation}}\n\\newcommand{\\bes}{\\begin{equation*}}\n\\newcommand{\\ees}{\\end{equation*}}\n\\newcommand{\\bea}{\\begin{flalign*}}\n\\newcommand{\\eea}{\\end{flalign*}}\n\n%\\linespread{1.0}\n%\\setlength{\\parindent}{0em}\n%\\setlength{\\parskip}{0.8em}\n\n\\title{\\textbf{Singular Perturbation Theory}}\n\\author{Aditya Vijaykumar}\n\\affiliation{International Centre for Theoretical Sciences, Bengaluru, India.}\n\\emailAdd{aditya.vijaykumar@icts.res.in}\n\\abstract{Course Project - Dynamical Systems}\n\n\\begin{document}\n\\maketitle\n\\section{Introduction}\nWe take a tour of the theory of singular perturbations and the methods to solve them. Main references for the material in this report are :-\n\\begin{itemize}\n\\item Bender, Carl M., and Steven A. Orszag. 2013. \\textit{Advanced mathematical methods for scientists and engineers}. New York: Springer.\n\\item O'Malley, Robert E. 2013. \\textit{Singular perturbation methods for ordinary differential equations}.  Springer-Verlag New York.\n\\item Lin, C. C., Lee A. Segel, and G. H. Handelman. 2006. \\textit{Mathematics applied to deterministic problems in the natural sciences}. Philadelphia, Pa: Society for Industrial and Applied Mathematics.\n\\end{itemize}\n\\section{Singular Perturbation theory for Algebraic Equations}\nConsider first the equation $ \\epsilon m^2 + 2m + 1 =0 $, where $ \\epsilon << 1 $ is a small parameter. We note that with $ \\epsilon= 0$ the equation has just one solution $ m = -1/2 $, whereas the full equation has two solutions by virtue of being quadratic. If what we desire are perturbative solutions around the unperturbed solutions, we won't be able to obtain two solutions by usual power series substitution.\n\nSo where exactly are we failing to capture the problem? As this problem is exactly solvable, let's look at the roots -\n\\begin{equation*}\nm_\\pm = \\dfrac{-1 \\pm \\sqrt{1 - \\epsilon}}{\\epsilon} \\approx\\dfrac{-1 \\pm (1 - \\epsilon/2)}{\\epsilon} \\approx -\\dfrac{1}{2}, - \\dfrac{2}{\\epsilon}\n\\end{equation*}\nWe see that the roots are diverging at $ \\epsilon \\rightarrow 0 $, which explains why the perturbative approach fails! So  from the two preceding observations that \\textit{ignoring} the $ \\epsilon $ for obtaining the unperturbed solution is not the best of ideas. \n\nLet's then try to do the next best thing - trying to see what terms have comparable orders as the $ \\epsilon m^2 $ term. We adopt a trial and error approach. Let's first try $ \\epsilon m^2 \\sim m \\implies m \\sim \\frac{1}{\\epsilon} \\implies 2m  = \\order{\\frac{1}{\\epsilon}} $. This means that now the $ \\epsilon m^2 $ term cannot be ignored. Let's make the substitution $ m = \\frac{x}{\\epsilon}$ to, in some sense, normalize $ \\epsilon  $ term.\n\\begin{align*}\n\\implies \\epsilon \\qty(\\dfrac{x}{\\epsilon})^2 + 2 \\dfrac{x}{\\epsilon} + 1 = 0 \\\\\n\\implies \\dfrac{x^2}{\\epsilon} + 2 \\dfrac{x}{\\epsilon} + 1 = 0 \\\\\n\\implies x^2 + 2 x + \\epsilon = 0\n\\end{align*}\nLet's make the substitution $  x = \\sum_{n=0}^{\\infty} x_n \\epsilon^n$. Upto first order in $ \\epsilon $, we get the following equations,\n\\begin{align*}\nx_0^2 + 2 x_0 = 0 &\\implies x_0 = 0 , -2 \\\\\n2 x_0 x_1 + 2 x_1 + 1 = 0 &\\implies x_1 = -\\dfrac{1}{2}, x_1 = \\dfrac{1}{2} \\qq{pairwise for } x_0= 0 , -\\frac{1}{2}\n\\end{align*}\nHence we have the two roots, perturbatively to $ \\order{\\epsilon} $,\n\\begin{equation*}\nx = -\\dfrac{\\epsilon}{2}, -2 + \\dfrac{\\epsilon}{2} \\implies m = -\\dfrac{1}{2}, -\\dfrac{2}{\\epsilon}\n\\end{equation*}\nSo this procedure works! The procedure is actually called the \\textit{method of dominant balance}. Let's look at a more complicated equation, $ \\epsilon x^4 + \\epsilon x^3 - x^2 + 2x - 1 =0 $. A usual characteristic of a singular perturbation problem is that the highest order term is multiplied by an infinitesimal quantity. Let's apply the above procedure to this equation -\n\\begin{itemize}\n\t\\item Substituting $ x = \\sum_{n} a_n \\epsilon^n $, we get,\n\t\\begin{align*}\n\ta_0^2 -2a_0 +1 = 0 \\implies a_0 = 1,-1 \\\\\n\ta_0^4 +a_0^3 - 2 a_0 a_1 + 2 a_1 = 0 \\implies \n\t\\end{align*}\n\t\\item $ \\epsilon x^4 \\sim x^2 \\implies x \\sim \\frac{1}{\\sqrt{\\epsilon}} \\sim \\frac{1}{\\mu} $. Substituting $ x = \\frac{m}{\\mu} $, $ m^4 + \\mu m^3 - m^2 + 2 \\mu m - \\mu^2 = 0$. Substituting $ m = \\sum_{n=0}^{\\infty} a_n \\mu^n $ and using sympy to do the algebraic manipulations, we get the following equations,\n\t\\begin{align*}\n\ta_0^4 - a_0^2 = 0 &\\implies a_0 = 1,-1 \\\\\n\t4 a_0^3 a_1 + a_0^3 - 2 a_0 a_1 + 2 a_0 = 0 &\\implies a_1 = -\\frac{3}{2}, -\\frac{3}{2} \\\\\n\t4 a_0^3 a_2 + 6 a_0^2 a_1^2 + 3 a_0^2 a_1 -2 a_0 a_2 - a_1^2 +2 a_1 - 1 = 0 &\\implies a_2 = -\\dfrac{11}{8}, \\dfrac{11}{8}\n\t\\end{align*}\n\tHence, we get two roots as,\n\t\\begin{align*}\n\tx &= \\frac{1 -\\frac{3}{2}\\mu - \\frac{11}{8} \\mu^2}{\\mu}, \\frac{-1 -\\frac{3}{2}\\mu + \\frac{11}{8} \\mu^2}{\\mu} \\\\\n\t\\implies x &\\approx \\frac{1}{\\sqrt{\\epsilon}} -\\frac{3}{2}, -\\frac{1}{\\sqrt{\\epsilon}} -\\frac{3}{2}\n\t\\end{align*}\n\t\\item $ \\epsilon x^4 + \\epsilon x^3 = (x-1)^2 \\implies x = 1 \\pm \\sqrt{\\epsilon} \\sqrt{x^3 + x^4}$. We can use this to set up an iterative scheme in $ \\sqrt{\\epsilon} $. Therefore, two more roots are,\n\t\\begin{equation*}\n\tx = 1 + \\sqrt{2} \\sqrt{\\epsilon} + \\dfrac{7}{2} \\epsilon, 1 - \\sqrt{2} \\sqrt{\\epsilon} + \\dfrac{7}{2} \\epsilon, \n\t\\end{equation*}\n\\end{itemize}\n\t\n\\section{Singular Perturbation Theory for Ordinary Differential Equations}\n\\subsection{Boundary Value Problem}\n\\begin{equation*}\n\\epsilon y'' + 2 y' + y = 0 \\qq{,} y' = \\dv{y}{x} \\qq{,} y(0) = 0 \\qq{,} y(1)=1\n\\end{equation*}\nThe unperturbed differential equation reads $ 2y' + y = 0  $. We see now, if we take both boundary conditions into account, that this is an overdetermined problem. Anyway, this unperturbed equation has the general solution,\n\\begin{equation*}\ny = A \\exp(-\\dfrac{x}{2}) \\implies y = 0 \\qq{OR} y = \\exp(\\dfrac{1-x}{2})\n\\end{equation*} \nHow do we reconcile the differences? Let's first solve the differential equation exactly by substituting $ y = \\exp(mx) $ :-\n\\begin{align*}\n\\epsilon m^2 + 2m + 1 = 0 &\\implies m = \\dfrac{-1 \\pm \\sqrt{1 - \\epsilon}}{\\epsilon} \\approx -\\dfrac{1}{2}, -\\dfrac{2}{\\epsilon} \\\\\n\\implies y = B \\exp(-\\dfrac{x}{2}) +  C \\exp(-\\dfrac{2x}{\\epsilon}) &\\implies y \\approx e^{1/2} \\qty(\\exp(-\\dfrac{x}{2}) - \\exp(-\\dfrac{2x}{\\epsilon}) )\n\\end{align*}\nSo, we see that there is a term which becomes large as $ x\\rightarrow 0 $, but dies of faster as $ x $ increases. This infinitesimal region near $x =0 $ is popularly called the the \\textit{boundary layer}, mainly inspired by fluid mechanics problems. \n\nWhat does this tell us? We can clearly see that there are two regions in the problem - one where the effects of the $ \\epsilon $ term are significant, and one where the effects are insignificant. This suggests we should really solve this equation in these regions separately and then adopt some kind of matching procedure. So let's do exactly that, first for the region where $ x \\sim \\order{\\epsilon} $. Substituting $ t = \\frac{x}{\\delta} $ in the governing equation, we get,\n\\begin{equation*}\n\\dfrac{\\epsilon}{\\delta^2} \\ddot{y} + \\dfrac{2}{\\delta} \\dot{y} + y = 0 \\qq{,} \\dot{y} = \\dv{y}{t}\n\\end{equation*}\nLet's now apply a dominant balance like method here. If $ \\frac{\\epsilon}{\\delta^2} \\sim \\frac{2}{\\delta}  \\implies \\epsilon \\sim \\delta$, after rearranging terms and neglecting $ \\order{\\epsilon} $ terms, we have\n\\begin{equation*}\n\\ddot{y} + 2 \\dot{y} = 0 \\implies y = A + B \\exp(-2t) \n\\end{equation*}\nWe note that this solution is only valid when $ \\delta \\sim \\epsilon $, \\textit{ie} when $ x \\rightarrow 0 $. Hence, imposing only the boundary condition $ y(0) = 0 $, we have $ y_{in} = A(1 - e^{-2t}) $. We have already obtained the solution far away from zero, which is just $ y_{out} =e^{\\frac{1-x}{2}}  $. So we have now got solutions at two extremities, and need to match these solutions at some intermediate points. If $ \\theta(\\epsilon) $ is the scale of the intermediate region, we can say it should satisfy the following,\n\\begin{equation*}\n\\lim\\limits_{\\epsilon \\rightarrow 0} \\dfrac{\\theta}{\\epsilon} = \\infty \\qq{and} \\lim\\limits_{\\epsilon \\rightarrow 0} \\theta = 0\n\\end{equation*}\nSo it's natural to now consider another scale in the system $ x \\sim \\theta $ and substitute $ x = \\eta \\theta \\implies t = \\frac{\\eta \\theta}{\\delta}$. Matching condition requires,\n\\begin{align*}\n\\lim\\limits_{\\epsilon \\rightarrow 0} y_{out}(x=\\eta \\theta) &= \\lim\\limits_{\\epsilon \\rightarrow 0} y_{in}( x =\\eta \\theta) \\\\\n\\implies \\lim\\limits_{\\epsilon \\rightarrow 0}e^{\\frac{1 - \\eta \\theta}{2}} &= \\lim\\limits_{\\epsilon \\rightarrow 0}A( 1 - e^{-2 \\eta \\theta/\\delta}) \\\\\n\\implies e^{1/2} &= A\n\\end{align*}\nHence, we can now say that $ y_{in} =   e^{1/2}(1 - e^{-2x/\\epsilon})$. To obtain a seemingly uniform solution, what we can do is add the inner and outer solutions and subtract the common part \\textit{i.e.} $ e^{1/2} $,\n\\begin{equation*}\n\\implies y_{uni} = e^{1/2}(e^{-x/2} - e^{-2x/\\epsilon})\n\\end{equation*}\nwhich exactly agrees with our initial approximation.\n\nThis was a problem whose exact solution was known to us. Let's try to do a slightly trickier problem. Consider,\n\\begin{equation*}\n\\epsilon y''' - y' + xy = 0 \\qq{,} y(0) = y'(0) = y(1)= 1\n\\end{equation*}\nThe unperturbed equation has solution $ y_{out} = A_0 e^{x^2/2} $. Let us consider the boundary layer of thickness $ \\delta $ near $ x=0 $. Substituting $ t = \\frac{x}{\\delta} $, the equation becomes,\n\\begin{align*}\n\\dfrac{\\epsilon}{\\delta^3} \\dddot{y} - \\dfrac{1}{\\delta} \\dot{y} + xy = 0 &\\qq{,} \\dfrac{\\epsilon}{\\delta^3} \\sim \\dfrac{1}{\\delta} \\implies \\delta \\sim \\sqrt{\\epsilon} \\\\\n\\dddot{y} - \\dot{y} = 0 \\implies \\dot{y} = A e^t + B e^{-t} &\\implies y_{in} = A e^t - B e^{-t} + C \\implies y_{in}' = \\dfrac{A}{\\sqrt{\\epsilon}} e^{\\frac{x}{\\sqrt{\\epsilon}}} + \\dfrac{B}{\\sqrt{\\epsilon}} e^{-\\frac{x}{\\sqrt{\\epsilon}}}\n\\end{align*}\nWe now impose boundary conditions $ y(0)= y'(0) = 1 \\implies  $ and get $ y_{in}  = A (e^\\frac{x}{\\sqrt{\\epsilon}} + e^{-\\frac{x}{\\sqrt{\\epsilon}}}) + (1- 2A )$, where we have retained only the leading terms. If we try to match the inner and outer solutions, we see that there is now way that the final form of the solution satisfies the boundary condition $ y(1) = 1 $ . Hence we expect to have another layer at $ x=1 $. Now using t = $\\frac{1-x}{\\delta}$ and doing a similar procedure again, we obtain,\n\\begin{equation*}\ny_{1in} = A' e^{\\frac{1-x}{\\sqrt{\\epsilon}}} + B' e^{-\\frac{1-x}{\\sqrt{\\epsilon}}} + (1 - A' - B')\n\\end{equation*}\nMatching this with the outer solution gives $ A'=0, B'=1, A_0 = 1  \\implies y_{out} = e^{x^2/2} $ and $ y_{1in} = e^{\\frac{x-1}{\\sqrt\n\\epsilon}} $. The perturbative solution upto leading order is, hence,\n\\begin{equation*}\ny_{uni} = e^{x^2/2} (1 + \\sqrt{\\epsilon}) + e^{\\frac{x-1}{\\sqrt{\\epsilon}}} (\\sqrt{\\epsilon }-1) - \\sqrt{\\epsilon} e^{-\\frac{x}{\\sqrt{\\epsilon}}} + constant\n\\end{equation*}\n\n\n\n\n\n\n\\subsection{Initial Value Problem}\nWe consider a problem which is prevalant in chemical kinetics. without going into the details of it, we note that the governing equations are,\n\\begin{align*}\n\\dot{x}=-x + (x + \\kappa - \\lambda )y \\qq{,} x(0)=1\\\\\n\\epsilon \\dot{y} = x - (x + \\kappa )y \\qq{,} y(0)=0\n\\end{align*}\nHere, $ \\epsilon $ is typically $ \\order{10^{-6}} $, and $ \\kappa, \\lambda $ are positive constants. The unperturbed equation is,\n\\begin{align*}\n0 = x - (x + \\kappa )y  &\\implies y_{out} = \\dfrac{x_{out}}{x_{out}+ \\kappa}\\\\\n\\dot{x}=-x + (x + \\kappa - \\lambda )y = -\\dfrac{\\lambda x}{x + \\kappa} &\\implies x_{out} + \\kappa \\log x_{out} = - \\lambda t + C \n\\end{align*}\n\nTo get a perturbative solution, we take inspiration from the boundary layer problems and say that there should be a initial time layer of thickness $ \\delta $. Hence, changing variables $ \\tau = t/\\delta $, we see, with $ x' = \\dv{x}{\\tau} $,\n\\begin{equation*}\n\\dfrac{1}{\\delta} x' = -x + (x + \\kappa - \\lambda )y \\qq{and} \\dfrac{\\epsilon}{\\delta} y' = x - (x + \\kappa) y  \n\\end{equation*}\nComparing scales, we see that $ \\delta \\sim \\epsilon $, and hence\n\\begin{align*}\n x' = -\\epsilon x + \\epsilon (x + \\kappa - \\lambda )y \\qq{and} y' = x - (x + \\kappa) y  \n\\end{align*}\nAs the boundary layer is near $ t = \\tau = 0 $, the boundary conditions $ x(0)=1, y(0)=0  $ should be satisfied inside the boundary layer. Solving the above equations,\n\\begin{equation*}\nx_{in } =1 \\qq{and} y_{in} = \\dfrac{1 - e^{- (\\kappa + 1) t/\\epsilon}}{\\kappa + 1}\n\\end{equation*}\n\nWe now need to match solutions at intermediate times. Let $ \\eta  $ be our matching scale in $ t $. Here,\n\\begin{equation*}\n\\lim\\limits_{\\epsilon \\rightarrow 0} \\dfrac{\\eta}{\\epsilon} = \\infty \\qq{and} \\lim\\limits_{\\epsilon \\rightarrow 0} \\eta = 0\n\\end{equation*}\nMatching the $ x$ solutions, we get $ C=1 $. To obtain the \\textit{uniform solution}, we again add the inner and outer solutions and subtract the common part. Therefore,\n\\begin{align*}\nx_{uni} = 1 + x_{out} -1 = x_{out} \\\\\ny_{uni} = \\dfrac{1 - e^{- (\\kappa + 1) t/\\epsilon}}{\\kappa + 1} + \\dfrac{x_{out}}{x_{out} + \\kappa}\n\\end{align*}\nwhere $ x_{out} $ is given implicitly as stated before.\n\n\n\n\n\n\n\n\n\\section{Method of Multiple Scales}\nConsider the damped harmonic oscillator with the following governing equation,\n\\begin{equation*}\n\\ddot{x} + 2 \\epsilon \\dot{x} + x = 0 \\qq{,}  x(0) = 0 \\qq{,} \\dot{x}(0) = 1 \\implies x(t) = e^{-\\epsilon t} \\dfrac{\\sin(t \\sqrt{1-\\epsilon^2})t}{\\sqrt{1-\\epsilon^2}}\n\\end{equation*}\nWe can see in this solution that there are two timescales governing the variation in the solution. One is the \\textit{slow} timescale $ \\tau = \\epsilon t $ during which the solution has an exponential decay, and the other is the \\textit{fast} timescale $ T = t \\sqrt{1 - \\epsilon^2} $ in which the solution varies sinusoidally. We could say then that a formulation of the problem should exist in $ \\tau, T, \\epsilon $. This is the philosophy behind the method of multiple scales.\n\nWe could solve this damped harmonic oscillator problem by multiple scales, but since it is easy and exactly solvable, let us look at a somewhat more complicated \\textit{non-linear} equation namely the Duffing equation with damping given by,\n\\begin{equation*}\n\\ddot{x} + x + \\epsilon(2 \\lambda \\dot{x} - x^3) = 0 \\qq{,} x(0)=1 \\qq{,} \\dot{x}(0) = 0 \n\\end{equation*}\nWe introduce two timescales into this problem,\n\\begin{equation*}\n\\tau = \\epsilon t \\qq{and} T = \\qty(1 + \\sum_{n=2}^\\infty \\epsilon^n \\omega_n ) t \\qq{and also} x(t) = X(\\tau,T, \\epsilon) = \\sum_{n=0}^{\\infty} \\epsilon^n X_n(\\tau,T)\n\\end{equation*}\nAs we have changed the timescales, we need to rewrite the time derivatives in the governing equation,\n\\begin{align*}\n\\dv{t} = \\epsilon \\dv{\\tau} &+ \\qty(1 + \\sum_{n=2}^\\infty \\epsilon^n \\omega_n )\\dv{T} \\\\\n\\implies \\epsilon^2 X_{\\tau \\tau} + \\qty(1 + \\sum_{n=2}^\\infty \\epsilon^n \\omega_n )^2 X_{TT} &+ 2 \\epsilon \\qty(1 + \\sum_{n=2}^\\infty \\epsilon^n \\omega_n ) X_{T \\tau} + \n\\\\2 \\epsilon \\lambda \\qty[\\epsilon X_\\tau + \\qty(1 + \\sum_{n=2}^\\infty \\epsilon^n \\omega_n ) X_{T}]  &- \\epsilon X^3 = 0 \n\\end{align*}\nSubstituting expansion for $ X $ in the second equation above, one obtains the following,\n\\begin{align*}\nX_{0TT} + X_0 = 0 \\qq{,} X_{1TT}  + X_1 + 2 X_{0T \\tau} + 2 \\lambda X_{0T} - X_0^3 = 0 \\\\\nX_{2TT} + X_2 + 2 \\omega_2 X_{0TT} + 2 X_{1 T \\tau} + X_{0 \\tau \\tau } + 2 \\lambda (X_{1T} + X_{0 \\tau}) - 3 X_0^2 X_1 = 0\n\\end{align*}\nThe initial conditions in terms of $ X, \\dot{X}$ become,\n\\begin{align*}\nX_0(0,0) = 1 &\\qq{,} X_n(0,0 ) = 0 , \\forall n \\ne 0 \\\\\nX_{0T}(0,0) = X_{0 \\tau}(0,0) + X_{1 T}(0,0) &= X_{2T}(0,0) + \\omega_2 X_{0T}(0,0) + X_{1T}(0,0) = 0 \n\\end{align*}\nSolving the first differential equation for $ X_0 $ and applying appropriate boundary conditions, we get,\n\\begin{equation*}\nX_0(T, \\tau) = A_0(\\tau) \\cos(T + \\phi_0(\\tau))  \\qq{,} A_0(0) = 1 \\qq{,} \\phi_0( 0) = 0 \n\\end{equation*}\nWith this solution, we can write the equation for $ X_1 $ as (with $ \\theta_0 = T + \\phi_0 $),\n\\begin{align*}\nX_{1TT} + X_1 -2 A_0'\\sin \\theta_0 -2 A_0 \\phi_0' \\sin \\theta_0 + 2 \\lambda A_0 \\sin \\theta_0 - A_0^3 \\cos^3\\theta_0 = 0 \\\\\nX_{1TT} + X_1 -2 A_0'\\sin \\theta_0 -2 A_0 \\phi_0' \\cos \\theta_0 - 2 \\lambda A_0 \\sin \\theta_0 - A_0^3 \\dfrac{\\cos 3\\theta_0}{4} - 3A_0^3 \\dfrac{\\cos \\theta_0}{4}   = 0 \n\\end{align*}\nNow, we want an overall periodic solution for $ X $, and hence $ X_1 $ should also exhibit periodic behaviour. For this to hold,\n\\begin{equation*}\nA_0' + \\lambda A_0 = 0 \\qq{and} \\phi_0' = - \\dfrac{3}{8} A_0^2 \\implies A_0 = e^{-\\lambda \\tau} \\qq{and} \\phi_0 = \\dfrac{3}{16 \\lambda} ( 1 - e^{-2 \\lambda \\tau})\n\\end{equation*}\nWith these substitutions, $ X_1 $ becomes,\n\\begin{equation*}\nX_1(T,\\tau) = A_1(\\tau) \\cos (T + \\phi_1(\\tau) ) + \\dfrac{1}{32} e^{-3 \\lambda \\tau} \\cos(3\\{T + \\phi_0(\\tau)\\})\n\\end{equation*}\nThe boundary conditions for $ X_1  $ are $ X_1(0,0)= 0 , X_{1T}(0,0) = - A'(0) $. Substituting gives,\n\\begin{equation*}\nA_1(0) \\cos(\\phi_1(0)) = -\\dfrac{1}{32} \\qq{and} A_1(0) \\sin(\\phi_1(0)) = \\lambda \n\\end{equation*}\nSimilarly, we substitute $ X_1 , X_0 $ in the equation for $ X_2 $. The calculations are long, but the conclusion derived after all that is $ \\omega_2 = -\\frac{1}{\\lambda^2} $. So finally, we have out answer,\n\\begin{equation*}\nx \\sim e^{-\\lambda\\tau} \\cos\\qty[T + \\dfrac{3}{16 \\lambda}(1- e^{-2 \\lambda \\tau})] + \\epsilon \\qty{ A_1(\\tau) \\cos(T + \\phi_1(\\tau)) + \\dfrac{1}{32} e^{-3 \\lambda \\tau}  \\cos\\qty[3T + \\dfrac{9}{16 \\lambda}(1- e^{-2 \\lambda \\tau}) ]}\n\\end{equation*}\n\nWe can apply this method to a whole range of differential equations.\n\\end{document}\n\n\n\n\n", "meta": {"hexsha": "60bb38b21cf8442cd67df4a8e4a46240884d7864", "size": 17785, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sem2/dysys/termpaper/termpaper.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": "sem2/dysys/termpaper/termpaper.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": "sem2/dysys/termpaper/termpaper.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": 69.2023346304, "max_line_length": 530, "alphanum_fraction": 0.663817824, "num_tokens": 6424, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127641048443, "lm_q2_score": 0.8840392695254319, "lm_q1q2_score": 0.754892416217689}}
{"text": "\\section{Figure and Output}\n\\subsection{Figure file: \\lstinline[style=Plain]{lab_12_figure.pdf}}\n\\begin{figure}[!hbtp]\n\\centering\n\\includegraphics[width=\\textwidth]{../src/lab_12_figure.pdf}\n\\caption{Romberg Integration error vs. $n$}\n\\end{figure}\n\\newpage\n\\subsection{Output file: \\lstinline[style=Plain]{lab_12_output.txt}}\n\\lstinputlisting[style=Plain]{../src/lab_12_output.txt}\n\\newpage\n\\section{Function and Script}\n\\subsection{Function file:  \\lstinline[style=Plain]{lab_12_romberg.m}}\n\\lstinputlisting[style=MATLAB]{../src/lab_12_romberg.m}\n\\newpage\n\\subsection{Script file: \\lstinline[style=Plain]{lab_12_script.m}}\n\\lstinputlisting[style=MATLAB]{../src/lab_12_script.m}\n", "meta": {"hexsha": "1cea082de51fabe1314092a8a345e2fbccc6cc73", "size": 679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.12/Math.3341.Lab.12.Report/LaTeX/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.12/Math.3341.Lab.12.Report/LaTeX/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.12/Math.3341.Lab.12.Report/LaTeX/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.7222222222, "max_line_length": 70, "alphanum_fraction": 0.7820324006, "num_tokens": 210, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267626522814, "lm_q2_score": 0.8688267694452331, "lm_q1q2_score": 0.7548599494027419}}
{"text": "\\section{Multigrid for finite element methods}\nBy the definition of convolution \\eqref{con1}, we can rewrite \\eqref{2d-fe0} and \\eqref{2d-fe1} as follows: \n\\begin{equation}\\label{conA}\nA\\ast:  \\mathbb{R}^{m\\times n}\\rightarrow \\mathbb{R}^{m\\times n},~~~A\\ast u=f,~~\\Leftrightarrow~~ u=\\argmin J(v)=\\argmin \\left(\\frac{1}{2}(A\\ast v,v)-(f,v)_{l^2}\\right)\n\\end{equation}\nwhere $u=(u_{ij})$, $f=(f_{ij})$, \n\\begin{equation}\\label{fe0_Ka}\nA=\\left\\{\n\\begin{array}{ll}\n\t\\begin{pmatrix}\n\t0 &-1&0\\\\\n\t-1& 4&-1\\\\\n\t0 &-1& 0\n\t\\end{pmatrix}\n&\\text{for linear finite element,}\t\\\\\n%\t\\begin{equation}\\label{fe1_Ka}\n%\tK_A=\n\t\\begin{pmatrix}\n\t-1 &-1&-1\\\\\n\t-1& 8&-1\\\\\n\t-1 &-1& -1\n\t\\end{pmatrix}\n&\\text{for bilinear finite element.}\n\\end{array}\\right.\n\t\\end{equation}\n\nIt is easy to see that \n$$\n\\nabla J(v)= A\\ast v - f := - r,\\quad r=f-A\\ast v.\n$$\nApplying the gradient descent method to \\eqref{minProblem}, we obtain the following iterative method: \n\\begin{equation}\\label{iterativeAst}\nu^{k+1} = u^k + \\eta r^k,\\quad r^k = f-A\\ast u^k.\n\\end{equation}\nHere we can clearly see that gradient descent method is equivalent to\ndamped Jacobi method. Usually, we call this as smoother. \n\\begin{lemma}\nThe gradient descent method \\eqref{iterativeAst} for linear finite element converges if $\\eta={1\\over 8} %\\in (0,1/4)\n$, and the one for bilinear finite element converges  if $\\eta={1\\over 16}% \\in (0,1/8)\n$. Furthermore, the high frequence in $u-u^k$ are damped very rapidly. \n\\end{lemma}\n\\begin{proof}\nAccording to \\eqref{iterativeAst} ,\n$$\nu^{k+1}-u=(I-\\eta A)\\ast (u^k-u).\n$$\nThe gradient descent method \\eqref{iterativeAst} converges if $\\rho((I-\\eta A)\\ast)<1$, namely $\\eta\\rho(A\\ast)<2$. For linear finite element, if $\\eta= {1\\over 8}$, $\\rho(A\\ast )<8$, thus the gradient descent method \\eqref{iterativeAst} converges.\nFor bilinear finite element, if $\\eta= {1\\over 16}$, $\\rho(A\\ast )<16$, thus the gradient descent method \\eqref{iterativeAst} converges.\n\nFor linear finite element, let $(\\lambda_i, v_i)$ satisfy $A\\ast v_i=\\lambda_i v_i$ and $0<\\lambda_1\\leq \\lambda_2\\leq\\cdots\\lambda_{N}$ with $N=n^2$. Expand the error $u^k-u$ in terms of eigenvectors $v_i$, namely,\n$$\nu^k-u=\\sum_{i=1}^{N} a_i^kv_i.\n$$\nThen\n$$\nu^{k}-u=\\sum_{i=1}^{N} a_i^k(1-\\eta \\lambda_i)v_i=\\sum_{i=1}^{N} a_i^0(1-\\eta \\lambda_i)^{k}v_i.\n$$\nAccording to Proposition \\ref{prop:A}, it is easy to see that \n$$\n1-{1\\over 8}\\lambda_N\\approx {\\pi^2\\over 4(n+1)^2} \\ll 1.\n$$\nFor $\\eta={1\\over 8}$, the coefficient $a_N^0(1-{1\\over 8} \\lambda_N)^{k}$ of $v_N$ approximates to zero much faster. This means that high frequency in the error will damp rapidly.\n\\end{proof}\n\nFor an initial guess $u^0$, the left picture in Fig \\ref{fig:smooth} plots the error $u-u^0$ and the the right one plots the error $u-u^1$. Fig \\ref{fig:smooth} shows that the high frequency in the error of the initial guess $u^0$ is damped after one step of smoothing and results in a smoother error $u-u^1$.\n\\begin{figure}\n\\centering\n\\includegraphics[width=5.5cm,height=5cm]{pictures/smooth0.jpg} \\quad\n\\includegraphics[width=5.5 cm,height=5cm]{pictures/smooth10.jpg}\\quad\n\\includegraphics[width=5.5cm,height=5cm]{pictures/smooth50.jpg}\\quad\n\\includegraphics[width=5.5cm,height=5cm]{pictures/smooth100.jpg}\n\\caption{\\footnotesize{The errors of an random initial guess $u^0$, $u^{10}$, $u^{50}$ and  $u^{100}$.}}\n\\label{fig:smooth}\n\\end{figure}\n%\\begin{figure}\n%\\includegraphics[width=12cm,height=8cm]{pictures/smoothing.pdf}\n%\\end{figure}\nNext, we make the following particular choice:\n\\begin{equation}\n  \\label{eta}\n\\eta={1\\over 8}.  \n\\end{equation}\n\nThe gradient descent method can be written in terms of $S_{0}:\\mathbb\nR^{m\\times n}\\mapsto \\mathbb R^{m\\times n}$ satisfying\n\\begin{equation}\n\\label{jacobi1}\nu^1=(S_{0}f)={1\\over 8} f,\n\\end{equation}\nfor equation \\eqref{2d-fe0} with initial guess zero.\nIf we apply this method twice, then\n$$\nu^2=S_1(f) = S_{0} f + S_0(f - A\\ast(S_{0}f)),\n$$\nwith element-wise form\n\\begin{equation} \n\\begin{aligned}\nu^2_{i,j} &={3\\over 16}f_{i,j} + {1\\over 64}(f_{i+1,j}+f_{i-1,j}+f_{i,j+1}+f_{i,j-1}).\n\\end{aligned}\n\\end{equation}\nThen by the definition of convolution \\eqref{con1}, we have\n \\begin{equation}\\label{eq:convS}\nu^1= S_{0}\\ast f \\quad u^2 = S_1 \\ast f.\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:kernel-S}\nS_{0} = {1 \\over 8},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:kernel-S2}\nS_1={1\\over 64} \\begin{pmatrix}\n0 & 1 & 0 \\\\\n1 & 12 & 1  \\\\\n0 &1  & 0\n\\end{pmatrix}.\n\\end{equation}\n\nNext, we make the following particular choice for the bilinear case:\n\\begin{equation}\n  \\label{eta}\n\\eta={1\\over 16}.  \n\\end{equation}\n\nThe gradient descent method can be written in terms of $S_{0}:\\mathbb\nR^{m\\times n}\\mapsto \\mathbb R^{m\\times n}$ satisfying\n\\begin{equation}\n\\label{jacobi1}\nu^1=(S_{0}f)_{i,j}={1\\over 16} f_{i,j},\n\\end{equation}\nfor equation \\eqref{2d-fe1} with initial guess zero.\nIf we apply this method twice, then\n$$\nu^2=S_1(f) = S_{0} f + S_0(f - A\\ast(S_{0}f)),\n$$\nwith element-wise form\n\\begin{equation} \n\\begin{aligned}\nu^2_{i,j} &={3\\over 32}f_{i,j} + {1\\over 256}(f_{i+1,j}+f_{i-1,j}+f_{i,j+1}+f_{i,j-1}+f_{i+1,j+1}+f_{i-1,j-1}+f_{i-1,j+1}+f_{i+1,j-1}).\n\\end{aligned}\n\\end{equation}\nThen by the definition of convolution \\eqref{con1}, we have\n \\begin{equation}\\label{eq:convS}\nu^1= S_{0}\\ast f \\quad u^2 = S_1 \\ast f.\n\\end{equation}\nwith\n\\begin{equation}\\label{eq:kernel-S}\nS_{0} = {1 \\over 16},\n\\end{equation}\nand \n\\begin{equation}\\label{eq:kernel-S2}\nS_1={1\\over 256} \\begin{pmatrix}\n1 & 1 & 1 \\\\\n1 & 24 & 1  \\\\\n1 &1  & 1\n\\end{pmatrix}.\n\\end{equation}\n\n\n\n\nWe note the gradient descent method \\eqref{iterativeAst} can be written as\n\\begin{equation}\\label{GD0}\nu^k=u^{k-1} + S_0\\ast (f-A\\ast u^{k-1}).\n\\end{equation}\n\\begin{equation}\\label{GD1}\nu^{2k}=u^{2(k-1)} + S_1\\ast (f-A\\ast u^{2(k-1)}).\n\\end{equation}\nWe can sometimes use $S_1$ and the above identity to define a smoother\ndirectly, namely \n\\begin{equation}\\label{GD2}\nu^{k}=u^{k-1} + S_1\\ast (f-A\\ast u^{k-1}).\n\\end{equation}\n\n\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\n\nFirst solve the problem on the fine grid $\\mathcal T_{\\ell}$, denote the solution by $u^{\\ell}$, \n\\begin{equation}\\label{eq:smoothing0}\nu^{\\ell} \\leftarrow u^{\\ell} + S^\\ell \\ast (f^\\ell - A_\\ell \\ast u^{\\ell}).\n\\end{equation}\nDenote the error by $e^\\ell=u-u^{\\ell}$ and the residual\n\\begin{equation}\\label{eq:formresidual}\nr^{\\ell}=f-A_{\\ell}\\ast u^{\\ell}.\n\\end{equation}\nIt is obvious that $A_{\\ell}\\ast e^\\ell=r^{\\ell}.$\nWe need to solve the residual equation\n\\begin{equation}\\label{erreq}\nA_{\\ell}\\ast e^\\ell=r^{\\ell}.\n\\end{equation}\nThe idea of multigrid method is to solve this residual equation on the coarse grid space $\\mathcal V_{\\ell+1}$ \nand repeat the process until coarsest grid. \n\nWe note that the restriction of \\eqref{erreq} to the coarse level $\\ell+1$ is\n\\begin{equation}\\label{coarse:correc}\nA_{\\ell+1}\\ast e^{\\ell+1}=r^{\\ell+1}\n\\end{equation}\nwith $r^{\\ell+1}=R_\\ell^{\\ell+1}r^\\ell=R\\ast r^\\ell$.\n\nDenote the finite element approximation to $e_\\ell$ on the coarse grid $\\mathcal T_{\\ell+1}$ by $e_{\\ell+1}$. Interpolate the error $e_{\\ell+1}$ back to the fine space $\\mathcal V_{\\ell}$ and add the resulting residual to $u_{\\ell+1}$, that is \n\\begin{equation}\\label{eq:prolongation00}\nu^\\ell \\leftarrow u^{\\ell}+P^{\\ell}_{\\ell+1}e^{\\ell+1}\n\\end{equation}\n%as defined in \\eqref{mg-prolong} and restriction $R_{\\ell}^{\\ell+1} = (P_{\\ell+1}^{\\ell})^T$. \n\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^{1}, u^2, \\cdots, u^J) = {\\text{MG0}}(f; u^0; 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}=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 (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}\nHere $S^\\ell$ can be chosen as $S_0$ or $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} as follows.\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u = {\\text{MG1}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J)$}\n\t\\label{alg:L-Slash1}\n\t\\begin{algorithmic}\n\t\t\\State \n\t\t$$\n\t\tu \\leftarrow u^0.\n\t\t$$\n\t\t\\State\n\t\t$$\n\t\t(u^{1}, u^2, \\cdots, u^J) = {\\text{MG0}}(f; u; 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} \\leftarrow u^{\\ell} + R  \\ast_2^{\\top} u^{\\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\n\t\t$$\n\t\tu \\leftarrow u^{1}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nIf we add the post-smoothing with a symmetric form which means we \nuse $[S^\\ell \\ast ]^\\top$ as the smoother, then we can get the V-cycle\nversion multigrid algorithm.\n\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u = {\\text{MG2}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J; \\nu'_1, \\cdots, \\nu'_J )$}\n\t\\label{alg:V-cycle}\n\t\\begin{algorithmic}\n\t\t\\State \n\t\t$$\n\t\t(u^{1}, u^2, \\cdots, u^J) = {\\text{MG0}}(f; u^0; 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} \\leftarrow u^{\\ell} + R  \\ast_2^{\\top} u^{\\ell+1}.\n\t\t$$\n\t\t\\For{$i = 1:\\nu'_\\ell$}\n\t\t\\State\n\t\t$$\n\t\tu^{\\ell} \\leftarrow u^{\\ell} + S^\\ell \\ast (f^\\ell - A_\\ell \\ast u^{\\ell})\n\t\t$$\n\t\t\\EndFor\n\t\t\t\t%\t\t\\ENDIF\n\t\t\\EndFor\n\t\t\\State \n\t\t$$\n\t\tu = u^{1}.\n\t\t$$\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\nHere $S^\\ell $ means the central symmetry of kernel for smoother $S^\\ell$ as in the \ndefinition of \\eqref{eq:def_tildeK} in Lemma \\ref{lemm:tilde-K}. \n\nWe note that \n$$\n\\text{MG1}(f; u^0; J,\\nu_1, \\cdots, \\nu_J) = {\\text{MG2}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J; 0, \\cdots, 0).\n$$\n\nEither MG1 or MG2 only represents one cycle in a multigrid process. There many  different ways\nto use this basis multigrid cycle. For a given iterate $u$, we need to define a metric to measure the\naccuracy of $u$. One way to define it is:\n$$\n\\text{error}(u) = \\|f - A\\ast u\\|  \\big/ \\|f - A\\ast u^0\\|.\n$$\nSometimes, when we debug a code, we can first try to find the exact solution. $u_{\\text{exact}}$, and\nthen define \n$$\n\\text{error}(u) = \\| u_{\\text{exact}} - u\\|_A.\n$$\nBelow is one example fo algorithm for application of the basic multigrid cycle, say MG1:\n\\begin{breakablealgorithm}%[!htb]\n\t\\caption{$u = {\\text{multigrid1}}(f; u^0; J,\\nu_1, \\cdots, \\nu_J;  \\text{tol})$;}\n\t\\label{alg:multigrid-1}\n\t\\begin{algorithmic}\n\t\t\\State \n\t\t$$\n\t\tu \\leftarrow u^0.\n\t\t$$\n\t\t\\While{$\\text{error}(u) \\ge tol $}\n\t\t\\State\n\t\t$$\n\t\tu \\leftarrow u + \\text{MG1}(f-Au;0;\\nu_1, \\cdots, \\nu_J).\n\t\t$$\n\t\t\\EndWhile\n\t\\end{algorithmic}\n\\end{breakablealgorithm}\n\nA slightly more general multigrid method. \n\n\\begin{breakablealgorithm}\\label{alg:multigrid-Pi}\n\\begin{enumerate}\n\\item Initialization of inputs\n\t\t$$\n\t\tg_1 \\leftarrow g, \\quad\n                u_{1}\\leftarrow {\\rm random}.\n\t\t$$\n\t\\vspace{-.6mm}\n\\item Smoothing and restriction\n  \\begin{itemize}\n  \\item  For $\\ell = 1:J$\n    \\begin{itemize}%3\n    \\item For $i = 1:\\nu_\\ell$\n\t\t\\begin{equation}\\label{eq:smoothing}\n\t\tu_{\\ell} \\leftarrow u_{\\ell} + S_\\ell \\ast (g_\\ell - A_\\ell \\ast u_{\\ell}).\n\t\t\\end{equation}\n\\item  Form restricted residual and set initial guess:\n\\begin{equation*}\nu_{\\ell+1,0} \\leftarrow\\Pi_\\ell^{\\ell+1}u_{\\ell},  \\quad g_{\\ell+1} \\leftarrow R_\\ell \\ast_2 (g_\\ell -  A_\\ell \\ast u_{\\ell}) + A_{\\ell+1} \\ast u_{\\ell+1}^0,\n\\end{equation*}\n    \\end{itemize} %3\n  \\end{itemize}\n\\item  Prolongation with post-smoothing\n  \\begin{itemize} %4\n  \\item For {$\\ell = J-1:1$}\n\t\t$$\n\t\tu_{\\ell} \\leftarrow u_{\\ell} + R_\\ell  \\ast_2^{\\top} (u_{\\ell+1}-u_{\\ell+1}^0).\n\t\t$$\n\t\t\n                \\begin{itemize}\n  \\item For $i = 1:\\nu'_\\ell$\n\t\t$$\n\t\tu_{\\ell} \\leftarrow u_{\\ell} + S_\\ell' \\ast (g_\\ell - A_\\ell \\ast u_{\\ell})\n\t\t$$\n                \\end{itemize}\n                \\end{itemize} %4\n\\item Output\n\t\t$$\nu_1\n\t\t$$\n\\end{enumerate} %1\n\\end{breakablealgorithm}\n\n\\section{Numerical examples}\nWe consider to solve \n\\begin{equation}\n\\label{laplacenu}\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}{n+1},\\quad (i=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}\nWe use linear finite to discretize the 2D Laplacian equation \\eqref{laplacenu}.  The size of \nunknowns is $n^2$. We use gradient descent method as smoother in the multigrid method. \n\\begin{table}\\label{table:multivsGS}%[htdp]\n\\begin{center}\n\\begin{tabular}{|c||c|c|}\n\\hline \\hline\nSize of Unkowns & Gauss-Seidel for $A$ & Multigrid for $A$ \\\\ \\hline\\hline %& V + PCG for $A$\\\\ \\hline %\\hline\n225  &  226/0.04s     &    13/0.004s \\\\ \\hline %&\\onslide<3->{\\brown{5/0.003s}}  \\\\ \\hline\n961   &  910/0.26s      & 13/0.007s\n\\\\ \\hline %& \\onslide<5->{\\brown{5/0.005s}} \\\\ \\hline \n3969   &  3,044/2.40s   &13/0.021s  \\\\ \\hline %&  \\onslide<7->{\\brown{5/0.016s}} \\\\ \\hline \n16,129   & 9,869/31.45s    &13/0.08s \\\\ \\hline %& \\onslide<9->{\\brown{5/0.06s}}  \\\\ \\hline \n65,025   &  30,226/347.38s  &13/0.3s\\\\ \\hline %& \\onslide<11->{\\brown{5/0.22s}} \\\\   \\hline \\hline\n\\end{tabular}\n\\caption{Number of iterations for $\\| Ax - b \\|/ \\|b\\| \\leq 10^{-6}$.}\n\\end{center}\n\\end{table}\n\\vspace{-30pt}\n\\begin{figure}[!ht]\n\\centering\n%\\setlength{\\abovecaptionskip}{0pt}\n%\\setlength{\\belowcaptionskip}{0pt}\n\\includegraphics[width=10cm]{figures/mgcompare.png}\n\\caption{ Comparison GD with Multigrid.}\n\\label{fig:Hmesh}\n\\end{figure}\n\nFrom the Table \\ref{table:multivsGS} and Figure \\ref{fig:Hmesh}, we can see that the multigrid method is much faster than Gauss-Seidel method and is uniform with respect to the size of unknowns. \n\n\n\n\n\n\n", "meta": {"hexsha": "212bcc8b09f014c9717bec61b7942d0a726cee17", "size": 14805, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "497-6DL/8 Convolutional Multigrid Method/8.12-FEM-MG-CONV.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.12-FEM-MG-CONV.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.12-FEM-MG-CONV.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.0344827586, "max_line_length": 309, "alphanum_fraction": 0.652887538, "num_tokens": 5954, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8705972751232808, "lm_q1q2_score": 0.7548389699182132}}
{"text": "%!TEX root = ../notes.tex\n\\section{January 31, 2022}\n\\subsection{Linear Combinations \\emph{continued}}\nRecall from last time that we proposed that\n\\[\\text{greatest common divisor} \\leq \\text{least linear combination}.\\]\n\\begin{example}\n    $\\gcd(2024, 748)=44$ because we have\n    \\begin{align*}\n        2024 & = 748\\cdot 2 + 528                                  \\\\\n        748  & = 528\\cdot 1 + 220                                  \\\\\n        528  & = 220\\cdot 2 + 88                                   \\\\\n        220  & = 88\\cdot 2 + \\boxed{44} \\leftarrow \\gcd(2024, 748) \\\\\n        88   & = 44\\cdot 2 + 0\n    \\end{align*}\n    We determine which linear combinations or $2024$ and $748$ we can create:\n    \\begin{align*}\n        2024 & = 1\\cdot 2024 + 0\\cdot 748                         \\\\\n        748  & = 0\\cdot 2024 + 1\\cdot 748                         \\\\\n        528  & = 1\\cdot 2024 + (-2)\\cdot 748                      \\\\\n        220  & = 748 - 1\\cdot 528                                 \\\\\n             & = 748 - 1\\cdot (1\\cdot 2024 + (-2)\\cdot 748)       \\\\\n             & = -1\\cdot 2024 + 3\\cdot 748                        \\\\\n        88   & = 528 - 2\\cdot 220                                 \\\\\n             & = \\underbrace{[1\\cdot 2024 + (-2)\\cdot 748]}_{528}\n        - 2\\cdot \\underbrace{[-1\\cdot 2024 + 3\\cdot 748]}_{220}   \\\\\n             & = 3\\cdot 2024 - 8\\cdot 748                         \\\\\n        44   & = 220 - 2\\cdot 88                                  \\\\\n             & = [-1\\cdot 2024 + 3\\cdot 748]\n        - 2\\cdot [3\\cdot 2024 - 8\\cdot 748]                       \\\\\n             & = -7\\cdot 2024 + 19\\cdot 748\n    \\end{align*}\n\\end{example}\nFollowing this example, we have shown that every common divisor of $a$ and $b$ can be written as a linear combination of $a$ and $b$, and since the greatest common divisor has to be less than the least linear combination (as shown last time), the greatest common divisor \\emph{is} the least linear combination\\footnote{Assume for contradiction that the gcd were any less, then that would also be a linear combination. $\\lightning$}.\n\nWe realize that there is a \\emph{recurrence} happening here. If we call every set of coefficients $x, y$ and $z, w$ for $a$ and $b$ respectively, such that\n\\begin{align*}\n    a & = x\\cdot a_0 + y\\cdot b_0 \\\\\n    b & = z\\cdot a_0 + y\\cdot b_0\n\\end{align*}\nwhere $a_0$ and $b_0$ are the original numbers, we can use a sliding window approach\\footnote{Updating our iterators on every loop by sliding our window of coefficients down.} again to determine the next set of $x, y, z, w, a, b$.\n\nRecall from last time we had\n\\begin{align*}\n    a' & = b       \\\\\n    b' & = a\\mod b\n\\end{align*}\nWe can extend this algorithm for our new coefficients:\n\\begin{align*}\n    x' & = z                                               \\\\\n    y' & = w                                               \\\\\n    z' & = w - \\left\\lfloor\\frac{a}{b}\\right\\rfloor\\cdot z \\\\\n    w' & = y - \\left\\lfloor\\frac{a}{b}\\right\\rfloor\\cdot w \\\\\n\\end{align*}\nwhere $\\left\\lfloor\\frac{a}{b}\\right\\rfloor$ are the quotients from our Euclidean Algorithm. Note that initially, we have\n\\begin{align*}\n    a & = 1\\cdot a_0 + 0\\cdot b_0 \\\\\n    b & = 0\\cdot a_0 + 1\\cdot b_0\n\\end{align*}\nso we have initial values of $x=1, y=0, z=0, w=0$.\n\nso our code for the \\emph{extended Euclidean Algorithm} is now\n\\begin{algorithm}[Extended Euclidean Algorithm]\n    ~\\lstinputlisting[numbers=none,language=Python]{code/ext_gcd.py}\n\\end{algorithm}\n\n\\subsection{Modular Arithmetic}\n% *** Create recall environment\n\\recall We used a substitution/shift cipher to encrypt text:\n\\[\\begin{array}{ccc}\n        \\mathtt{Y} & \\mathtt{E} & \\mathtt{S} \\\\\n        \\downarrow & \\downarrow & \\downarrow \\\\\n        \\mathtt{D} & \\mathtt{J} & \\mathtt{X}\n    \\end{array}\\]\nby incrementing 5 letters for each lecture.\n\n$a = 0$, $b = 1$, \\dots, $z=25$.\n\nWe had this notion of\n\\begin{align*}\n    \\text{ciphertext} & = \\text{plaintext} + 5 \\\\\n    \\mathtt{d}        & = \\mathtt{y} + 5       \\\\\n    3                 & = 24+5 = 29\n\\end{align*}\n\n\\begin{definition}\n    We say $a\\equiv b\\mod{m}$ if $m\\mid a - b$.\n\n    We say ``$a$ is congruent\\footnote{Congruence is a ``behave like'' equality.} to $b$ modulo $m$''.\n\\end{definition}\n\\begin{example}\n    \\begin{align*}\n        24 + 5 \\equiv 3\\mod{26} \\\\\n        22 + 2 \\equiv 1\\mod{12} \\\\\n    \\end{align*}\n    The first example is from our shift sipher, the second example is equivalent to ``two hours after 11:00, it is 1:00''.\n\\end{example}\n\n\\begin{proposition}\n    If we have\n    \\begin{align}\n        a_1          & \\equiv a_2\\mod{m} \\nonumber                    \\\\\n        b_1          & \\equiv b_2\\mod{m} \\nonumber                    \\\\\n        \\intertext{Then we have the following: }\n        a_1 + b_1    & \\equiv a_2 + b_2\\mod{m} \\label{premod-add}     \\\\\n        a_1 - b_1    & \\equiv a_2 - b_2\\mod{m} \\label{premod-sub}     \\\\\n        a_1\\cdot b_1 & \\equiv a_2\\cdot b_2\\mod{m} \\label{premod-mult}\n    \\end{align}\n\\end{proposition}\n\\begin{proof}\n    For \\cref{premod-add}, realize that we have\n    \\[(a_1 + b_1) - (a_2 + b_2) = (a_1 - a_2) + (b_1 - b_2)\\]\n    and the two terms on the right are each divisible by $m$ by our premise. We can also write out\n    \\begin{align*}\n        a_1 + b_1 & = (a_2 + \\alpha m) + (b_2 + \\beta m)     \\\\\n                  & = (a_2 + b_2) + (\\alpha + \\beta)\\cdot m.\n    \\end{align*}\n    Similarly, for \\cref{premod-sub}, we have\n    \\begin{align*}\n        a_1 - b_1 & = a_2 + \\alpha m - (b_2 + \\beta m)      \\\\\n                  & = a_2 - b_2 + (\\alpha - \\beta) \\cdot m.\n    \\end{align*}\n    and for \\cref{premod-mult}, we have\n    \\begin{align*}\n        a_1\\cdot b_1 & = (a_2 + \\alpha m)\\cdot (b_2 + \\beta m)                           \\\\\n                     & = a_2\\cdot b_2 + \\alpha m b_2 + \\beta m a_2 + \\alpha\\beta m^2     \\\\\n                     & = a_2\\cdot b_2 + (\\alpha b_2 + \\beta a_2 + \\alpha\\beta m)\\cdot m.\n    \\end{align*}\n    which concludes the proofs of the premod rules.\n\\end{proof}\n\n\\begin{proposition}\\label{existence-of-inverse}\n    There exists $b$ with\n    \\[a\\cdot b\\equiv 1\\mod{m}\\]\n    if and only if $\\gcd(a, m) = 1$.\n\\end{proposition}\n\\begin{proof}\n    We can write linear combination equation\n    \\[a\\cdot b + m\\cdot k = 1\\]\n    and we have that the following are equivalent (we cascade down the list and can easily prove the iff relations):\n    \\begin{enumerate}[i.]\n        \\item such a $b$ exists,\n        \\item there is a solution $b, k$ to this equation,\n        \\item $1$ is a linear combination of $a$ and $m$,\n        \\item $1$ is the \\emph{least} linear combination of $a$ and $m$,\n        \\item $1 = \\gcd(a, m)$.\n    \\end{enumerate}\n    so we have that $1 = \\gcd(a, m)$ if and only if $a$'s inverse $b$ exists.\n\\end{proof}", "meta": {"hexsha": "66fa6adf0025669bc842711d2ccf856dd12c3c72", "size": 6765, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lectures/2022-01-31.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-01-31.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-01-31.tex", "max_forks_repo_name": "jchen/math1580-notes", "max_forks_repo_head_hexsha": "9784be9e0faa57bbb3c421d8a104daadebf99a2f", "max_forks_repo_licenses": ["BSL-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 45.7094594595, "max_line_length": 432, "alphanum_fraction": 0.5427937916, "num_tokens": 2241, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220787, "lm_q2_score": 0.8652240930029118, "lm_q1q2_score": 0.7547759574251409}}
{"text": "\\section{Determinants}\n\n\\begin{definition}\n\tLet $A \\in M_{n \\times n} (F)$. If $n =1$, let $A=(A_{11})$ and we define $\\text{det}(A) = A_{11}$. For $n \\geq 2$, $\\text{det}(A)$ (or $\\determinate{A}$) is defined as\n\t\\begin{equation}\n\t\t\\determinate{A} = \\sum_{j=1}^n (-1)^{i + j} A_{ij} \\times \\determinate{\\tilde{A}_{ij}}\n\t\\end{equation}\n\t\n\twhere $\\tilde{A}_{ij}$ is obtained from $A$ by deleting row $i$ and column $j$. This is called \\cindex{Laplace expansion}.\n\t\\qed\n\\end{definition}\n\n\n\\begin{theorem}\n    A function $\\delta: M_{n \\times n} (F) \\rightarrow F$ is the same as $\\determinate{A}$ if it satisfies the following 3 properties:\n    \\begin{enumerate}\n        \\item It is \\cindex{$n$-linear function}: for a scalar $k$, \\begin{equation}\n        \\determinate{\\begin{bmatrix}\n            a_1\\\\\n            \\vdots\\\\\n            u + kv \\\\\n            \\vdots\\\\\n            a_n\n        \\end{bmatrix}} = \\determinate{\\begin{bmatrix}\n            a_1\\\\\n            \\vdots\\\\\n            u \\\\\n            \\vdots\\\\\n            a_n\n        \\end{bmatrix}} + k \\determinate{\\begin{bmatrix}\n            a_1\\\\\n            \\vdots\\\\\n            v \\\\\n            \\vdots\\\\\n            a_n\n        \\end{bmatrix}}\n    \\end{equation}\n    \\item It is \\cindex{alternating}: $\\delta(A) = 0$ if any two adjacent rows are identical.\n    \\item $\\delta(I) = 1$.\n    \\end{enumerate}\n    The determinate is linear on each row when the remaining rows are held fixed.\n    \\qed\n\\end{theorem}\n\n\n\n\\begin{theorem}\n    The effect of elementary row operation on the determinant of a matrix $A$ is:\n\\begin{enumerate}\n    \\item interchange any two rows: $\\determinate{B} = - \\determinate{A}$.\n    \\item multiply a row: $\\determinate{B} = k \\determinate{A}$.\n    \\item add a multiple of a row to another: $\\determinate{B} = \\determinate{A}$.\n\\end{enumerate}\n\\end{theorem}\n\n\n\\begin{theorem}\n    If $\\rank{A_{n \\times n}} < n$, then $\\determinate{A} = 0$.\n\\end{theorem}\n\\begin{proof}\n    If $\\rank{A_{n \\times n}} < n$, one row is a linear combination of all other rows.\n\\end{proof}\n\n\n\n\\begin{theorem}\n\t\\begin{equation}\n\t\t\\determinate{AB} = \\determinate{A} \\times \\determinate{B}\n\t\\end{equation}\n\\end{theorem}\n\n\\begin{theorem}\n\tA matrix $A \\in M_{n \\times n}(F)$ is invertible $\\Leftrightarrow$ $\\determinate{A} \\neq 0$. If it is invertible, $\\determinate{A^{-1}} = \\dfrac{1}{\\determinate{A}}$.\n\\end{theorem}\n\n\\begin{definition}\n    The \\cindex{cofactor} of $A$ is defined as \n    \\begin{equation}\n        \\cofactor{A}_{ij} = (-1)^{i+j} \\determinate{\\tilde{A}_{ij}}\n    \\end{equation}\\qed\n\\end{definition}\n\n\nIf the determinate is calculated using cofactor operation, the performance is $n!$ multiplication. However if it is calculated using elementary row operation, the performance is $\\dfrac{n^3 + 2n - 3}{3}$ multiplication.\n\n\\begin{definition}\n    The \\cindex{adjugate} of $A$ is defined as\n    \\begin{equation}\n        \\adjugate{A} = (\\cofactor{A})^\\top\n    \\end{equation}\n\\end{definition}\n\n\\begin{theorem}\n    The inverse of invertible square matrix A is:\n    \\begin{equation*}\n        A^{-1} = \\frac{1}{\\determinate{A}} \\adjugate{A}\n    \\end{equation*}\n\\end{theorem}\n\n\n\\begin{theorem}[\\cindex{Cramer's Rule}]\n\tLet $Ax=b$ be a system of $n$ equation with $n$ unknowns. If $\\determinate{A} \\neq 0$, the system has a unique solution:\n\t\\begin{equation}\n\t\tx_k = \\frac{\\determinate{M_k}}{\\determinate{A}}\n\t\\end{equation}\n\t\n\twhere $M_k$ is a $n\\times n$ matrix obtained from $A$ by replacing column $k$ of $A$ by $b$.\n\\end{theorem}\n\n\\begin{proof}\n\tLet $a_k$ be the $k$th column of $A$ and $X_k$ denote the matrix obtained from replacing the column $k$ of identity matrix $I_n$ by $x$. Then $A X_k = M_k$:\n\t\\begin{equation*}\n\t\\begin{aligned}\n        A X_k &= A \\begin{bmatrix}\n\t\t\t1 &   &   & x &   \\\\\n\t\t\t & 1 &  & x &   \\\\\n\t\t\t && \\ddots &  \\vdots \\\\\n\t\t\t&&& x & \\\\\n\t\t\t&&& \\vdots & \\ddots \\\\\n\t\t\t&&& x&   & 1 \n\t\t\\end{bmatrix} \\\\\n\t\t&= \\begin{bmatrix}\n\t\t    Ae_1, Ae_2, \\dots, Ax, \\dots, Ae_n\n\t\t\\end{bmatrix} \\\\\n\t\t& = \\begin{bmatrix}\n\t\t    a_1, a_2, \\dots, b, \\dots, a_n\n\t\t\\end{bmatrix} \\\\\n\t\t&= M_k\n\t\t\\end{aligned}\n    \\end{equation*}\n\t\n\t\n\tEvaluate $X_k$ by cofactor expansion along row $k$ produces\n\t\\begin{equation*}\n\t\t\\determinate{X_k} = x_k \\times \\determinate{I_{n-1}} = x_k\n\t\\end{equation*}\n\t\n\tHence \n\t\\begin{equation*}\n\t\t\\determinate{M_k} = \\determinate{A X_k} = \\determinate{A} \\times \\determinate{X_k} = \\determinate{A} \\times x_k\n\t\\end{equation*}\n\t\n\tTherefore\n\t\\begin{equation*}\n\t\tx_k = \\frac{\\determinate{M_k}}{\\determinate{A}}\n\t\\end{equation*}\n\\end{proof}\n\nNote: Cramer's Rule is too slow for real world calculation.\n\n\\begin{theorem}\n\tIn geometry, for a square matrix $A \\in M_{n\\times n}(F)$, $\\absolutevalue{\\determinatetext{A}}$ is the \\cindex{n-dimensional volume} of the parallelepiped having vector $A_{i,\\cdot}$ as adjacent sides.\n\\end{theorem}\n\n\n", "meta": {"hexsha": "7325e502c0b49d6d9b13edffa489a8a30fffa63b", "size": 4822, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/linear_algebra/la.4.determinants.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.4.determinants.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.4.determinants.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 30.9102564103, "max_line_length": 219, "alphanum_fraction": 0.6165491497, "num_tokens": 1664, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190225, "lm_q2_score": 0.8740772269642948, "lm_q1q2_score": 0.7546709534474759}}
{"text": "\\documentclass[PHIL101-Textbook.tex]{subfiles}\n\\begin{document}\n\n\\part{Truth Tables}\\label{part:truth.tables}\n\n\\chapter{Introducing Truth Tables}\\label{ch:TruthTables}\n\n\\section{Characteristic Truth Tables}\n\nAny formula of \\tfl\\ is composed of stomic statement symbols, possibly combined using sentential connectives. The truth value of a complex formula depends only on the truth value of the statement symbols that it contains. In order to know the truth value of `$(D \\eand E)$', for instance, you only need to know the truth value of `$D$' and the truth value of `$E$', and how `$\\eand$' works. That's what makes the logic truth-functional. \n\nWe will need to define the connectives we introduced in chapter \\ref{ch:TFLConnectives}. We will abbreviate \\emph{True}  with `\\vT' and \\emph{False}  with `\\vF'. (But just to be clear, the  truth values are \\emph{True} and \\emph{False}; truth values are not numbers!)\n\n\n\\paragraph{Negation.} If \\meta{A} is true, then \\enot\\meta{A} is false. If \\enot\\meta{A} is true, then \\meta{A} is false. We can summarise this in the \\emph{characteristic truth table} for negation:\n\\begin{center}\n\\begin{tabular}{c|c}\n\\meta{A} & \\enot\\meta{A}\\\\\n\\hline\n\\vT & \\vF\\\\\n \\vF & \\vT \n\\end{tabular}\n\\end{center}\n\n\\paragraph{Conjunction.} $(\\meta{A}\\eand\\meta{B})$ is true if and only if \\meta{A} is true and \\meta{B} is true. Here is the {characteristic truth table} for conjunction:\n\\begin{center}\n\\begin{tabular}{c c |c}\n\\meta{A} & \\meta{B} & $(\\meta{A}\\eand\\meta{B})$\\\\\n\\hline\n \\vT  & \\vT & \\vT \\\\\n \\vT  & \\vF & \\vF \\\\\n \\vF & \\vT & \\vF \\\\\n \\vF & \\vF &  \\vF\n\\end{tabular}\n\\end{center}\nNote that conjunction is \\emph{symmetrical}. The truth value for $(\\meta{A} \\eand \\meta{B})$ is always the same as the truth value for $(\\meta{B} \\eand \\meta{A})$.  \n\n\\paragraph{Disjunction.} $(\\meta{A}\\eor \\meta{B})$ is true if and only if at least one of \\meta{A} and \\meta{B} is true. Here is  the {characteristic truth table} for disjunction:\n\\begin{center}\n\\begin{tabular}{c c|c}\n\\meta{A} & \\meta{B} & $(\\meta{A}\\eor\\meta{B})$ \\\\\n\\hline\n \\vT  & \\vT & \\vT \\\\\n \\vT  & \\vF & \\vT \\\\\n \\vF & \\vT & \\vT \\\\\n \\vF & \\vF &  \\vF\n\\end{tabular}\n\\end{center}\nLike conjunction, disjunction is symmetrical. \n\n\\paragraph{Conditional.} Conditionals are complex and \\tfl\\ treats them in a simplified manner: $(\\meta{A}\\eif\\meta{B})$ is false if and only if \\meta{A} is true and \\meta{B} is false; otherwise it is true. Here is the characteristic truth table for the conditional.\n\\begin{center}\n\\begin{tabular}{c c|c}\n\\meta{A} & \\meta{B} & $(\\meta{A}\\eif\\meta{B})$\\\\\n\\hline\n \\vT  & \\vT & \\vT \\\\\n \\vT  & \\vF & \\vF \\\\\n \\vF & \\vT & \\vT \\\\\n \\vF & \\vF &  \\vT \n\\end{tabular}\n\\end{center}\nThe conditional is \\emph{asymmetrical}. You cannot swap the antecedent and consequent without changing the meaning of the formula, because $(\\meta{A}\\eif\\meta{B})$ has a very different truth table from $(\\meta{B}\\eif\\meta{A})$.\n\n\\paragraph{Biconditional.} Since a biconditional is to be the same as the conjunction of a conditional running in each direction, the characteristic truth table for the biconditional must be:\n\\begin{center}\n\\begin{tabular}{c c|c}\n\\meta{A} & \\meta{B} & $(\\meta{A}\\eiff\\meta{B})$\\\\\n\\hline\n \\vT  & \\vT & \\vT \\\\\n \\vT  & \\vF & \\vF \\\\\n \\vF & \\vT & \\vF \\\\\n \\vF & \\vF &  \\vT \n\\end{tabular}\n\\end{center}\nUnsurprisingly, the biconditional is symmetrical. \n\n\\paragraph{Exclusive Disjunction.} We won't be using exclusive disjunction very much. However, it's a worthwhile exercise for you to devise your own characteristic truth table for exclusive disjunction, or for any other connective you would like to add to \\tfl.\n\n\n\\section{Truth-functional Connectives}\n\\label{s:TruthFunctionality}\n\nLet's formalise an idea we've talked about earlier. \n\t\\factoidbox{\n  A connective is \\define{truth-functional} iff the truth value of a formula with that connective as its main logical operator is uniquely determined by the truth value(s) of its constituent formula(s).\n\t}\n        \nEvery connective in \\tfl\\ is truth-functional. The truth value of a negation is uniquely determined by the truth value of the unnegated formula. The truth value of a conjunction is uniquely determined by the truth value of both conjuncts. The truth value of a disjunction is uniquely determined by the truth value of both disjuncts, and so on. To determine the truth value of some \\tfl\\ formulas, we only need to know the truth value of its component formulas. \n\n%This is what gives \\tfl\\ its name: \\emph{truth-functional logic}.\n\nTruth-functionality is actually quite rare. Almost no connectives and operators in English are truth-functional.\n\nFor example the connectives `although' and `because' seem very `logical', but aren't truth-functional. Think about how the components of each of these statements contribute to the truth of the overall statement:\n\n\t\\begin{earg}\n  \\item Sara is trustworthy and she is a lawyer.\n  \\item Sara is trustworthy because she is a lawyer.\n  \\item Sara is trustworthy although she is a lawyer.\n\t\\end{earg}\n\nTo be true, each sentence needs the statements `Sara is trustworthy' and `Sara is a lawyer' to be true. Truth is all that \\tfl\\ knows about, so the \\tfl\\ symbolisation of these three statements would be identical. However, you can see that they do convey very different ideas about the relationship between being trustworthy and a lawyer, so they aren't interchangeable in English. `Although' and `because' are not \\emph{truth-functional}.\\\\\n\nMore abstractly, we can form a new statement from any simpler statement by prefixing it with, for example: `Audrey Hepburn thought that \\ldots'. The truth value of this new sentence is not fixed solely by the truth value of the original sentence. For consider two true sentences:\n\t\\begin{earg}\n  \\item $2 + 2 = 4$.\n  \\item Beyonc\\'{e}'s middle name is Giselle.\n\t\\end{earg}\nAs both these sentences are true, adding our Hepburn operator should make them both true (or both false). But while Audrey Hepburn thought that $2+2=4$, she certainly didn't think Beyonc\\'{e}'s middle name was Giselle. So `Audrey Hepburn thought that\\ldots' is an English operator, but it is not a \\emph{truth-functional} or logical operator.\n\n\n\\section{Symbolising vs. Translating}\nAll of the connectives of \\tfl\\ are truth-functional, but more than that: they really do \\emph{nothing} except map between truth values.  \n\nWhen we symbolise a sentence or an argument in \\tfl, we ignore everything \\emph{besides} the contribution that the truth values of a component might make to the truth value of the whole. There are subtleties to our ordinary claims that far outstrip their mere truth values, such as sarcasm; poetry; tension; surprise; causation; temporality; emotional connotations; emphasis; and many others. These are important parts of everyday discourse, which are not expressible in \\tfl. As remarked in Chapter \\ref{ch:TFLConnectives}, \\tfl\\ cannot capture the subtle differences between the following English sentences:\n\t\\begin{earg}\n  \\item Dana is a logician and Dana is a nice person\n  \\item Although Dana is a logician, Dana is a nice person\n  \\item Dana is a logician despite being a nice person\n  \\item Dana is a nice person, since they are a logician\n  \\item Dana is a logician; co-incidentally they are also a nice person\n\t\\end{earg}\nAll of the above sentences would be symbolised with the same \\tfl\\ formula, perhaps `$(L \\eand N)$'.\n\nWe keep saying that we use \\tfl\\ formulas to \\emph{symbolise} English statements. Many other textbooks talk about \\emph{translating} English sentences into \\tfl. However, a  translation must preserve certain facets of meaning, and -- as we have just pointed out -- \\tfl\\ cannot do that. This is why we will speak of \\emph{symbolising} English statements, rather than of \\emph{translating} them.\n\nThis affects how we should understand our symbolisation keys. Consider a key like:\n\t\\begin{ekey}\n  \\item[L] Dana is a logician.\n  \\item[N] Dana is a nice person.\n\t\\end{ekey}\nOther textbooks will understand this as a stipulation that the \\tfl\\ formula `$L$' should \\emph{mean} that Dana is a logician, and that the \\tfl\\ formula `$N$' should \\emph{mean} that Dana is a nice person, but \\tfl\\ is totally unequipped to deal with \\emph{meaning}. The preceding symbolisation key is only stipulating that the \\tfl\\ formula `$L$' must take the same truth value as the English statement `Dana is a logician', and that the \\tfl\\ formula `$N$' must take the same truth value as the English statement `Dana is a nice person'. \n%\t\\factoidbox{\n%  When we treat a \\tfl\\ formula as \\emph{symbolising} an English sentence, we are stipulating that the \\tfl\\ formula is to take the same truth value as that English sentence.\n%\t}\n\nWe should not expect that a symbolisation of a statement's truth value would also contain all the richness of communication. Truth is only a very small (if central) element of communication.\n\n\n\n\\pagebreak\n\n\\practiceproblems\\label{pr.TT.intro}\n\\problempart\nWrite characteristic truth tables for each of the following connectives:\n\\begin{earg}\n\\item Exclusive disjunction (Either $A$ nor $B$, but not both).\n\\item Nor (Neither $A$ nor $B$).\n\\item Only if (Only if $A$ then $B$).\n\\item Another connective that you think might be interesting.\n\\end{earg}\n\n\\problempart\nOne major limitation on \\tfl\\ connectives is our choice of having two truth values (True and False). What third truth value might you add (e.g. `unknown', `both true and false', `irrelevant', `unproven', `future' (i.e. not yet true or false), `partially true'? Create characteristic truth tables for conjunction and negation using True, False, and your third truth value.\n\n\n\\chapter{Complete Truth Tables}\n\\label{ch:CompleteTruthTables}\n\nWe have two main uses for truth values. First, we can assign truth values to a \\tfl\\ formula based on the truth value of the statement it symbolises. For example, `$B$' could take the same truth value as the English sentence `Big Ben is in London'.  Second -- and more interesting for logicians -- we can stipulate the truth value of some of our formulas, and check if this informs us of the truth values of others. Usually we only provide values for the atomic statement symbols in \\tfl.\n\t\\factoidbox{\n  A \\define{valuation} in \\tfl\\ is any assignment of truth values to \\\\ individual \\tfl\\ statement symbols.\n\t}\n\n\nThe power of truth tables lies in the following: Each row of a truth table represents a possible valuation. The entire truth table represents all possible valuations; thus the truth table provides us with a means to calculate the truth values of complex formulas, over all possibilities. This is easiest to explain with examples.\n\n\\section{Our First Complete Truth Table}\nConsider the formula `$((H\\eor I)\\eif H)$'. There are four possible ways to assign True and False to the statement symbols `$H$' and `$I$' -- four possible valuations -- which we can represent on four rows, as follows:\n\\begin{center}\n\\begin{tabular}{c c|ccccc}\n$H$&$I$&$((H$&\\eor&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT \\\\\n \\vT & \\vF \\\\\n \\vF & \\vT \\\\\n \\vF &  \\vF\n\\end{tabular}\n\\end{center}\nTo calculate the truth value of the entire formula `$((H \\eor I) \\eif H)$', we first copy the truth values underneath their symbols in the formula:\n\\begin{center}\n\\begin{tabular}{c c|ccccc}\n$H$&$I$&$((H$&\\eor&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT & {\\vT} & & {\\vT} & & {\\vT}\\\\\n \\vT & \\vF & {\\vT} & & {\\vF} & & {\\vT}\\\\\n \\vF & \\vT & {\\vF} & & {\\vT} & & {\\vF}\\\\\n \\vF & \\vF & {\\vF} & & {\\vF} & & {\\vF}\n\\end{tabular}\n\\end{center}\nNow consider the subformula `$(H\\eor I)$'. This is a disjunction $(\\meta{A}\\eor\\meta{B})$ with `$H$' as \\meta{A} and with `$I$' as \\meta{B}. A disjunction is true iff one of its disjuncts is true. In this case, our disjuncts are just `$H$' and `$I$'.\n\n\\begin{center}\n\\begin{tabular}{c c|ccccc}\n & & (\\meta{A} & \\eor & \\meta{B}) & & \\\\\n$H$&$I$&$((H$&\\eor&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\vT & \\gT & & \\vT \\\\\n \\vT & \\vF & \\gT & \\vT & \\gF & & \\vT \\\\\n \\vF & \\vT & \\gF & \\vT & \\gT & & \\vF \\\\\n \\vF & \\vF & \\gF & \\vF & \\gF & &  \\vF\n\\end{tabular}\n\\end{center}\nTip: When we show that a column is used to to calculate another, we will often grey that column out once it's used, as we'll never need to use that column again. You could cross out, tick, or highlight them instead. %This makes it easier to read the truth table. \n\nThe next connective is a conditional $(\\meta{A}\\eif\\meta{B})$ with `$(H \\eor I)$' as \\meta{A} and with `$H$' as \\meta{B}. On the first row, for example, `$(H\\eor I)$' is true and `$H$' is true, so `$((H\\eor I) \\eif I)$' is true. We write `\\vT' on the row:\n\n\\begin{center}\n\\begin{tabular}{c c| ccccc}\n & &  & (\\meta{A} &  &\\eif &\\meta{B}) \\\\\n$H$&$I$&$((H$&\\eor&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\gT & \\gT & \\vT & \\gT \\\\\n \\vT & \\vF & \\gT & \\gT & \\gF &     & \\gT \\\\\n \\vF & \\vT & \\gF & \\gT & \\gT &     & \\gF \\\\\n \\vF & \\vF & \\gF & \\gF & \\gF &     & \\gF \\\\\n% & & & & & $\\uparrow$\n\\end{tabular}\n\\end{center}\n\nThe second row is similar. In the third row, however, `$(H\\eor I)$ is true and `$H$' is false, so we write `\\vF'. Finally, the antecedent of the conditional is false on the last row, so we write `\\vT'. The completed table looks like this: \n\n\\begin{center}\n\\begin{tabular}{c c| ccccc}\n$H$&$I$&$((H$&\\eor&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\gT & \\gT &\\mT & \\gT \\\\\n \\vT & \\vF & \\gT & \\gT & \\gF &\\mT & \\gT \\\\\n \\vF & \\vT & \\gF & \\gT & \\gT &\\mF & \\gF \\\\\n \\vF & \\vF & \\gF & \\gF & \\gF &\\mT & \\gF \\\\\n\n\\end{tabular}\n\\end{center}\nThe conditional is the main logical operator of the formula. It is true on three rows, and false on one row.\n\n\n\\section{Building Complete Truth Tables}\nA complete truth table has a row for every possible valuation; that is, every possible combination of \\emph{True} and \\emph{False} for the relevant statement symbols. To make sure you include every possibility, it's best to be orderly when building your truth table.\n\n\nThe size of the complete truth table depends on the number of different statement symbols in the table. Two rows are needed for the complete truth table for a formula that contains only one atomic statement symbol, such as the characteristic truth table for negation.\nFour rows are needed for the complete truth table for formulas that contain two atomic statement symbols, such as the characteristic truth tables for our binary connectives, and the truth table for `$((H \\eand I)\\eif H)$'.\n\nEight rows are needed for the complete truth table for formulas that contain three atomic statement symbols. Sixteen rows for four different symbols, 32 rows for five symbols, 64 rows for six symbols, etc., In general: A complete truth table with $n$ atomic statement symbols has $2^n$ rows.\n\nIn order to write the columns of a complete truth table, begin with the right-most atomic symbol; write alternately `\\vT' and `\\vF'. In the next column to the left, write two `\\vT's, then two `\\vF's, and repeat. For the third atomic symbol, write four `\\vT's then four `\\vF's. This yields an eight line truth table like the one below: \n\n\\begin{center}\n\\begin{tabular}{c c c|ccccc}\n$M$&$N$&$P$&$(M$&\\eand&$(N$&\\eor&$P))$\\\\\n\\hline\n%           M        &     N   v   P\n \\vT  & \\vT & \\vT \\\\%& \\vT & \\vT & \\vT & \\vT & \\vT \\\\\n \\vT  & \\vT & \\vF \\\\%& \\vT & \\vT & \\vT & \\vT & \\vF \\\\\n \\vT  & \\vF & \\vT \\\\%& \\vT & \\vT & \\vF & \\vT & \\vT \\\\\n \\vT  & \\vF & \\vF \\\\%& \\vT & \\vF & \\vF & \\vF & \\vF \\\\\n \\vF & \\vT & \\vT \\\\%& \\vF & \\vF & \\vT & \\vT & \\vT \\\\\n \\vF & \\vT & \\vF \\\\%& \\vF & \\vF & \\vT & \\vT & \\vF \\\\\n \\vF & \\vF & \\vT \\\\%& \\vF & \\vF & \\vF & \\vT & \\vT \\\\\n \\vF & \\vF & \\vF %& \\vF & \\vF & \\vF & \\vF &  \\vF\n\\end{tabular}\n\\end{center}\n\n\\noindent For a 16 line truth table, the next column of statement symbols should have eight `\\vT's followed by eight `\\vF's. Then 16 `\\vT's and 16 `\\vF's, and so on.\n\n\nBut what if the same atomic symbol occurs many times, as in the formula\n`$(((C\\eiff C) \\eif C) \\eand \\enot(C \\eif C))$'?\nOnly two lines are required because there is only one atomic symbol $C$, and so only two possibilities: $C$ is true or false. The complete truth table for this formula is:\n\n\\begin{center}\n  \\begin{tabular}{c|  c  c c c c c  c  c c c c }\n$C$&$(((C$&\\eiff&$C)$&\\eif&$C)$&\\eand&\\enot&$(C$&\\eif&$C))$\\\\\n\\hline\n \\vT &     \\,\\,\\,\\, \\gT &  \\gT  & \\gT &    \\gT  & \\gT &\\mF&  \\gF &    \\gT &  \\gT  & \\gT   \\\\\n \\vF &     \\,\\,\\,\\, \\gF &  \\gT  & \\gF &    \\gF  & \\gF  &\\mF&   \\gF &    \\gF &  \\gT  & \\gF \n\\end{tabular}\n\\end{center}\n\n\n\n\\section{Dropping Brackets}\\label{s:MoreBracketingConventions}\nOur formulas are starting to accumulate a lot of brackets. You might think that not all these brackets are necessary. And you'd be right. But it can be tricky to know which brackets are needed and which are not. One pair more than you need is annoying. One pair less is disastrous. Given that warning, there \\emph{are} times you can safely drop brackets.\\\\\n\n(1) You can drop the outermost set of brackets, if they are the very first and very last symbols.\n\n\\begin{center}\n\\begin{tabular}{ l c l} \n$(A \\eor B)$ & $\\Rightarrow$ & $A \\eor B$ \\\\\n$((A \\eand B) \\eif (C \\eor D))$ & $\\Rightarrow$ & $(A \\eand B) \\eif (C \\eor D)$ \\\\\n$(A \\eand B) \\eif (C \\eor D)$ & $\\not\\Rightarrow$ & $A \\eand B) \\eif (C \\eor D$ \\\\\n$\\enot(A \\eor B)$ & $\\not\\Rightarrow$ & $\\enot A \\eor B$\n\\end{tabular}\n\\end{center}\n\nDon't forget to add those brackets again though, if you need to negate your formula, or join it to another formula.\\\\\n\n(2) If you have several conjuncts in a row, or several disjuncts in a row, you can drop the pairs of brackets separating them. However, be careful, and if in doubt, leave the  brackets alone.\n\n\\begin{center}\n\\begin{tabular}{lcl} \n$((A \\eand B) \\eand C)$ & $\\Rightarrow$ & $(A \\eand B \\eand C)$ \\\\\n$(A \\eor (B \\eor C))$ & $\\Rightarrow$ & $(A \\eor B \\eor C)$ \\\\\n$((A \\eif B) \\eif C)$ & $\\not\\Rightarrow$ &$(A \\eif B \\eif C)$ \\\\\n$((A \\eand B) \\eor C)$ & $\\not\\Rightarrow$ & $(A \\eand B \\eor C)$ \\\\\n\\end{tabular}\n\\end{center}\n\nYou cannot drop brackets if there are several conditionals in a row. Nor can you drop brackets if there are a mixture of conjuncts and disjuncts. And even if it's permissible to drop brackets, you'll find it is sometimes useful to use them to group some of the subformulas.\n\nYou might be wondering, why only conjunctions or disjuncts? The answer is that $((A \\eand B) \\eand C)$ and $(A \\eand (B \\eand C))$ have the same truth tables:\n\n\\begin{center}\n\\begin{tabular}{c c c|ccccc|ccccc}\n$A$ & $B$ & $C$ & $((A$ & \\eand & $B)$ & \\eand & $C)$ & $(A$ & \\eand & $(B$ & \\eand & $C))$\\\\\n\\hline\n%           M        &     N   v   P\n \\vT  & \\vT & \\vT & \\gT & \\gT & \\gT & \\mT & \\gT & \\gT & \\mT & \\gT & \\gT & \\gT \\\\\n \\vT  & \\vT & \\vF & \\gT & \\gT & \\gT & \\mF & \\gF & \\gT & \\mF & \\gT & \\gF & \\gF \\\\\n \\vT  & \\vF & \\vT & \\gT & \\gF & \\gF & \\mF & \\gT &  \\gT & \\mF & \\gF & \\gF & \\gT \\\\\n \\vT  & \\vF & \\vF & \\gT & \\gF & \\gF & \\mF & \\gF &  \\gT & \\mF & \\gF & \\gF & \\gF \\\\\n \\vF  & \\vT & \\vT & \\gF & \\gF & \\gT & \\mF & \\gT &  \\gF & \\mF & \\gT & \\gT & \\gT \\\\\n \\vF  & \\vT & \\vF & \\gF & \\gF & \\gT & \\mF & \\gF &  \\gF & \\mF & \\gT & \\gF & \\gF \\\\\n \\vF  & \\vF & \\vT & \\gF & \\gF & \\gF & \\mF & \\gT &  \\gF & \\mF & \\gF & \\gF & \\gT \\\\\n \\vF  & \\vF & \\vF & \\gF & \\gF & \\gF & \\mF & \\gF &  \\gF & \\mF & \\gF & \\gF & \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent Because these two conjunction formulas have the same truth table, the precise bracketting doesn't matter. We can then write this formula simply as: $(A \\eand B \\eand C)$.\nThe same story holds for disjunction: $((A \\eor B) \\eor C)$ and $(A \\eor (B \\eor C))$ have the same truth tables, so we can simply write $(A \\eor B \\eor C)$. \n\nBut $((A \\eif B) \\eif C)$ and $(A \\eif (B \\eif C))$ have different truth tables:\n\n\\begin{center}\n\\begin{tabular}{c c c|ccccc|ccccc}\n$A$ & $B$ & $C$ & $((A$ & \\eif & $B)$ & \\eif & $C)$ & $(A$ & \\eif & $(B$ & \\eif & $C))$\\\\\n\\hline\n%           M        &     N   v   P\n \\vT  & \\vT & \\vT & \\gT & \\gT & \\gT & \\mT & \\gT & \\gT  & \\mT & \\gT & \\gT & \\gT \\\\\n \\vT  & \\vT & \\vF & \\gT & \\gT & \\gT & \\mF & \\gF & \\gT  & \\mF & \\gT & \\gF & \\gF \\\\\n \\vT  & \\vF & \\vT & \\gT & \\gF & \\gF & \\mT & \\gT &  \\gT & \\mT & \\gF & \\gT & \\gT \\\\\n \\vT  & \\vF & \\vF & \\gT & \\gF & \\gF & \\mT & \\gF &  \\gT & \\mT & \\gF & \\gT & \\gF \\\\\n \\vF  & \\vT & \\vT & \\gF & \\gT & \\gT & \\mT & \\gT &  \\gF & \\mT & \\gT & \\gT & \\gT \\\\\n \\vF  & \\vT & \\vF & \\gF & \\gT & \\gT & \\mF & \\gF &  \\gF & \\mT & \\gT & \\gF & \\gF \\\\\n \\vF  & \\vF & \\vT & \\gF & \\gT & \\gF & \\mT & \\gT &  \\gF & \\mT & \\gF & \\gT & \\gT \\\\\n \\vF  & \\vF & \\vF & \\gF & \\gT & \\gF & \\mF & \\gF &  \\gF & \\mT & \\gF & \\gT & \\gF \n\\end{tabular}\n\\end{center}\n\n\\noindent Because their truth tables are different, we need to distinguish between them, so we can't simplify the formula to: $(A \\eif B \\eif C)$. Similarly $((A \\eand B) \\eor C)$ and $(A \\eand (B \\eor C))$ have different truth tables, so we can't write: $(A \\eand B \\eor C)$.\\\\\n\nThis tension between having enough brackets, and avoiding confusing clutter, will reoccur throughout this course, as we learn more techniques and create more complicated formulas. If in doubt, use brackets.\n\nImportantly, always make sure you have the same number of opening `('and closing `)' brackets. There are several useful tricks for this. One way is to use different sized or shaped pairs of brackets, such as \n$$[\\big( ( p \\eand q) \\eif q\\big) \\to \\enot \\{ p \\lor q\\}]$$ However, we are going to use $[$square brackets$]$ for a particular type of bracket in the second half of this book, so you might find that using different colours, or even numbering your brackets, might work better: \n\n$$(^1(^2 (^3 p \\eand q)^3 \\eif q)^2 \\to \\enot (^4 p \\lor q)^4)^1$$\n\nWith a little practice, you'll be keeping track of your brackets, and dropping the ones you don't need, without causing yourself any confusion.\\\\\n\nFinally, don't drop all your brackets when writing a complex formula. Writing $((A \\eand B) \\eand C)$ as $A \\eand B \\eand C$ isn't wrong, but it leaves the formula completely naked. Have \\emph{some} decency.\n\n\n\\pagebreak\n\n\\practiceproblems\\label{pr.TT.TTorC}\n\\problempart\nWrite complete truth tables for each of the following:\n\\begin{earg}\n\\item $(A \\eif A)$ %taut\n\\item $(C \\eif\\enot C)$ %contingent\n\\item $((A \\eiff B) \\eiff \\enot(A\\eiff \\enot B))$ %logical truth\n\\item $((A \\eif B) \\eor (B \\eif A))$ % taut\n\\item $((A \\eand B) \\eif (B \\eor A))$  %taut\n\\item $(\\enot(A \\eor B) \\eiff (\\enot A \\eand \\enot B))$ %taut\n\\item $(((A\\eand B) \\eand\\enot(A\\eand B))\\eand C)$ %contradiction\n\\item $(((A \\eand B) \\eand C) \\eif B)$ %taut\n\\item $\\enot((C\\eor A) \\eor B)$ %contingent\n\\end{earg}\n\\problempart\nCheck all the claims made in \\S\\ref{s:MoreBracketingConventions} Dropping Brackets, i.e.\\ show:\n\\begin{earg}\n\t\\item `$((A \\eand B) \\eand C)$' and `$(A \\eand (B \\eand C))$' have the same truth table\n\t\\item `$((A \\eor B) \\eor C)$' and `$(A \\eor (B \\eor C))$' have the same truth table\n\t\\item `$((A \\eor B) \\eand C)$' and `$(A \\eor (B \\eand C))$' have different truth tables\n\t\\item `$((A \\eif B) \\eif C)$' and `$(A \\eif (B \\eif C))$' have different truth tables\n\t\\item[]\\hspace{-30pt}Also, check whether:\n\t\\item `$((A \\eiff B) \\eiff C)$' and `$(A \\eiff (B \\eiff C))$' have the same truth table\n\\end{earg}\n\n\\noindent\\solutions\n\\problempart \\label{pr.completeTT1}\nWrite complete truth tables for the following formulas and mark the column that represents the truth values for the whole formula.\n\n\\begin{earg}\n\\item $\\enot (S \\eiff (P \\eif S))$\n\\item $\\enot ((X \\eand Y) \\eor (X \\eor Y))$\n\\item $((\\enot P \\eor \\enot M) \\eiff M)$\n\\item $((A \\eif B) \\eiff (\\enot B\\eiff \\enot A))$\n\\item $\\enot \\enot (\\enot A \\eand \\enot B)$\n\\item $(((D \\eand R) \\eif I) \\eif \\enot(D \\eor R))$\n\\item $((C \\eiff (D \\eor E)) \\eand \\enot C)$\n\\item $(\\enot(G \\eand (B \\eand H)) \\eiff (G \\eor \\enot(B \\eor H)))$\n\\item $(\\enot ((D \\eiff O) \\eiff A) \\eif (\\enot D \\eand O))$\n\\end{earg}\n\n\\problempart\nWrite out each of the formulas in this set of exercises, using as few pairs of brackets as possible.\\\\\n\n\\problempart \nIf you want additional practice, you can construct truth tables for any of the formulas in the exercises for the previous chapter.\n\n\n\n\\chapter{Semantic Notions}\n\\label{ch:SemanticNotions}\n\nNow we know how to determine the truth value of any \\tfl\\ formula for any possible valuation by using a truth table, we can put this to good use. We have discussed several logical notions such as validity and consistency for English statements. We can now create tests for these same notions in \\tfl.\n\n\n\\section{Logical Truths and Falsehoods}\nIn Chapter \\ref{ch:BasicNotions}, we explained \\emph{logical truth} and \\emph{logical falsity}. Both notions have analogues in \\tfl. Here is the definition of logical truth for \\tfl:\n\t\\factoidbox{\n  $\\meta{A}$ is a \\define{logical truth} (in \\tfl) iff it is true in every valuation.\n\t}\n\n\n\nWe can determine whether a formula is a logical truth just by using truth tables. If the formula is true on every line of a complete truth table, then it is true in every valuation, so it is a logical truth. For example, the formula `$(H \\eand I) \\eif H$' is a logical truth, as is shown in the completed truth table:\n\n\\begin{center}\n\\begin{tabular}{c c| ccccc}\n$H$&$I$&$((H$&\\eand&$I)$&\\eif&$H)$\\\\\n\\hline\n \\vT & \\vT & \\gT & {\\gT} & \\gT &{\\mT} & \\gT \\\\\n \\vT & \\vF & \\gT & {\\gF} & \\gF &{\\mT} & \\gT \\\\\n \\vF & \\vT & \\gF & {\\gF} & \\gT &{\\mT} & \\gF \\\\\n \\vF & \\vF & \\gF & {\\gF} & \\gF &{\\mT} & \\gF \\\\\n% & & & & & $\\uparrow$\n\\end{tabular}\n\\end{center}\n\n\\noindent The column of `\\vT's underneath the conditional shows that the \\tfl\\ formula `$((H \\eand I)\\eif H)$' is a logical truth: it is true in all cases. `$H$' and `$I$' can be true or false in any combination, and the conditional formula still comes out true. Since we have considered all possibilities for the truth of `$H$' and `$I$' -- since, that is, we have considered all their \\emph{valuations} -- we can say that `$((H \\eand I)\\eif H)$' is true on every valuation, so is a logical truth.\n\nA completed truth-table can also show that $(A \\eif B) \\eif C$ isn't a logical truth, because some rows of its main connective are false (shaded pink): \n\n\\begin{center}\n\\begin{tabular}{c c c|ccccc}\n$A$ & $B$ & $C$ & $((A$ & \\eif & $B)$ & \\eif & $C)$ \\\\\n\\hline\n \\vT  & \\vT & \\vT & \\gT & \\gT & \\gT & \\mT & \\gT \\\\\n \\vT  & \\vT & \\vF & \\gT & \\gT & \\gT & \\mF & \\gF \\\\\n \\vT  & \\vF & \\vT & \\gT & \\gF & \\gF & \\mT & \\gT \\\\\n \\vT  & \\vF & \\vF & \\gT & \\gF & \\gF & \\mT & \\gF \\\\\n \\vF  & \\vT & \\vT & \\gF & \\gT & \\gT & \\mT & \\gT \\\\\n \\vF  & \\vT & \\vF & \\gF & \\gT & \\gT & \\mF & \\gF \\\\\n \\vF  & \\vF & \\vT & \\gF & \\gT & \\gF & \\mT & \\gT \\\\\n \\vF  & \\vF & \\vF & \\gF & \\gT & \\gF & \\mF & \\gF \n\\end{tabular}\n\\end{center}\n\nThis methods identifies all logical truths that can be captured by \\tfl. There are some logical truths that we cannot adequately symbolise in \\tfl. For example `Every cat is a cat' \\emph{must} always be true, but the best symbolisation we can offer is an atomic symbol, and no atomic symbol is a logical truth. That's because any atomic symbol has the possibility of being true, and of being false.\n Still, any English statement that is symbolised by a logical truth in \\tfl\\ will also be a logical truth in English.\\\\\n\nWe have a similarly restricted definition for logical falsity:\n\t\\factoidbox{\n  $\\meta{A}$ is a \\define{logical falsehood} iff it is false in every valuation.\n\t}\n\n\nWe can determine whether a formula is a falsehood just by using truth tables. If the formula is false on every line of a complete truth table, then it is false on every valuation, so it is a falsehood. This formula from Chapter \\ref{ch:CompleteTruthTables}, `$((C\\eiff C) \\eif C) \\eand \\enot(C \\eif C)$', is a logical falsehood:\n\n\\begin{center}\n  \\begin{tabular}{c|  c  c c c c c  c  c c c c }\n$C$&$(((C$&\\eiff&$C)$&\\eif&$C)$&\\eand&\\enot&$(C$&\\eif&$C))$\\\\\n\\hline\n \\vT &     \\,\\,\\,\\, \\gT &  \\gT  & \\gT &    \\gT  & \\gT &\\mF&  \\gF &    \\gT &  \\gT  & \\gT   \\\\\n \\vF &     \\,\\,\\,\\, \\gF &  \\gT  & \\gF &    \\gF  & \\gF  &\\mF&   \\gF &    \\gF &  \\gT  & \\gF \n\\end{tabular}\n\\end{center}\n\nFinally, most statements are neither logical truths nor  falsehoods:\n\t\\factoidbox{\n  $\\meta{A}$ is \\define{contingent} iff it is not a logical truth or falsehood.\n\t}\n\nContingent statements are those that are useful in the world; one's that can affect our actions, because they can be either true or false, and we need to engage in observation to determine which they are. For logicians, that's just too much work.\n\n\n\\section{Consistency}\nIn Chapter \\ref{ch:BasicNotions}, we said that statements are mutually consistent iff it is possible for all of them to be true at once. We can adapt this to \\tfl\\ too:\n\t\\factoidbox{\n  $\\meta{A}_1, \\meta{A}_2, \\ldots, \\meta{A}_n$ are \\define{mutually consistent} (in \\tfl) iff there is some valuation which makes them all true.\n\t}\n\nTo test for mutually consistency using complete truth tables, we look for a truth table row where all the formulas are true. For instance, the formulas `$(P \\eif Q)$' and `$(\\enot P \\eand \\enot Q)$' are mutually consistent:\n\n\\begin{center}\n\\begin{tabular}{c c|ccc |ccccc}\n$P$&$Q$&$(P$&\\eif&$Q)$&$($\\enot&$P$&\\eand&\\enot&$Q)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\bT & \\gT & \\gF & \\gT & \\bF & \\gF & \\gT \\\\\n \\vT & \\vF & \\gT & \\bF & \\gF & \\gF & \\gT & \\bF & \\gT & \\gF \\\\\n \\vF & \\vT & \\gF & \\bT & \\gT & \\gT & \\gF & \\bF & \\gF & \\gT \\\\\n \\vF & \\vF & \\gF & \\mT & \\gF & \\gT & \\gF & \\mT & \\gT & \\gF \n\\end{tabular}\n\\end{center}\n\n\\noindent Both formulas get the value `\\vT' (true) on the last row in the table, which shows it is possible for the formulas to be true together.\\\\\n\n\\noindent A set of formulas is \\define{mutually inconsistent} iff it isn't mutually consistent. \n\n\t\\factoidbox{\n  $\\meta{A}_1, \\meta{A}_2, \\ldots, \\meta{A}_n$ are \\define{mutually inconsistent} (in \\tfl) iff there is no valuation which makes them all true.\n\t}\n\n\nWe can show that `$(P \\eif Q)$' and `$(P \\eand \\enot Q)$' are mutually inconsistent:\n\n\\begin{center}\n\\begin{tabular}{cc|ccc |cccc}\n$P$&$Q$&$(P$&\\eif&$Q)$&$(P$&\\eand&\\enot&$Q)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\bT & \\gT & \\gT & \\bF & \\gF & \\gT \\\\\n \\vT & \\vF & \\gT & \\bF & \\gF & \\gT & \\bT & \\gT & \\gF \\\\\n \\vF & \\vT & \\gF & \\bT & \\gT & \\gF & \\bF & \\gF & \\gT \\\\\n \\vF & \\vF & \\gF & \\bT & \\gF & \\gF & \\bF & \\gT & \\gF \n\\end{tabular}\n\\end{center}\n\nTo show that a set of formulas is mutually inconsistent, we must check every row, as we did for checking logical truth and falsehood. \n\nConsistency (and inconsistency) need not apply just to pairs of formulas. In fact, it's possible to have a set of formulas, each pair of which is consistent, while the whole set is inconsistent:\n\n\\begin{center}\n\\begin{tabular}{cc|ccc |ccccc|ccc}\n$P$&$Q$&\n$(P$&\\eor&$Q)$&$($\\enot&$P$&\\eor&\\enot&$Q)$&$(P$&\\eiff&$Q)$\\\\\n\\hline\n \\vT & \\vT & \n \\gT& \\bT& \\gT&   \\gF  &\\gT& \\bF& \\gF & \\gT& \\gT& \\bT & \\gT \\\\\n \\vT & \\vF &\n \\gT& \\bT& \\gF&   \\gF  &\\gT& \\bT& \\gT & \\gF& \\gT& \\bF & \\gF \\\\\n \\vF & \\vT &\n \\gF& \\bT& \\gT&   \\gT  &\\gF& \\bT& \\gF & \\gT& \\gF& \\bF & \\gT \\\\\n \\vF & \\vF &\n \\gF& \\bF& \\gF&   \\gT  &\\gF& \\bT& \\gT & \\gF& \\gF& \\bT & \\gF \\\\\n\\end{tabular}\n\\end{center}\n\nSo be careful when you specify which set of formulas is consistent!\n\n\n\\section{Validity}\nThe validity of an argument is closely related to mutual consistency of its premises and negated conclusion:\n\t\\factoidbox{\n          $\\meta{A}_1, \\meta{A}_2, \\ldots, \\meta{A}_n\\ \\therefore\\ \\meta{C}$ is valid iff \\\\\\indent\\indent$\\meta{A}_1, \\meta{A}_2, \\ldots, \\meta{A}_n, \\enot\\, \\meta{C}\\ $ are mutually inconsistent. \t}\nRestating this relationship in English, an argument is valid if and only if there is no possibility that every premise and the negated conclusion can all be true. And this holds iff the conclusion can't be false when the premises are true.\n\nWe can use a complete truth table to test for validity. In a truth table, we indicate the start of each premise with a vertical line, and the start of the conclusion with a double vertical line. For example, to test whether `$\\enot L \\eif (J \\eor L), \\enot L \\ \\therefore\\ J$' is a valid argument, we check if every row where the premises `$\\enot L \\eif (J \\eor L)$' and `$\\enot L$' are true also has `$J$' true:\n\\begin{center}\n\\begin{tabular}{c c|cccccc|cc||c}\n$J$&$L$&\\enot&$L$&\\eif&$(J$&\\eor&$L)$&\\enot&$L$&$J$\\\\\n\\hline\n \\vT & \\vT & \\gF & \\gT & \\bT & \\gT & \\gT & \\gT & \\bF & \\gT & \\bT\\\\\n \\vT & \\vF & \\gT & \\gF & \\mT & \\gT & \\gT & \\gF & \\mT & \\gF & \\mT\\\\\n \\vF & \\vT & \\gF & \\gT & \\bT & \\gF & \\gT & \\gT & \\bF & \\gT & \\bF\\\\\n \\vF & \\vF & \\gT & \\gF & \\bF & \\gF & \\gF & \\gF & \\bT & \\gF & \\bF \\\\\n\\end{tabular}\n\\end{center}\n\n The above argument is valid, because the conclusion is true on every row where the premises are true. Note that had there been \\emph{no} rows where the premises were true, the argument would automatically be valid, because there are no rows where it could go wrong.\\\\\n\nThe test for invalidity is similar. For example, to test whether `$\\enot L \\eif (J \\eor L), \\enot L \\ \\therefore\\ \\enot J$' is invalid argument, we check if there is any valuation that makes both `$\\enot L \\eif (J \\eor L)$' and `$\\enot L$' true and `$\\enot J$' false:\n\\begin{center}\n\\begin{tabular}{c c|cccccc|cc||cc}\n$J$&$L$&\\enot&$L$&\\eif&$(J$&\\eor&$L)$&\\enot&$L$&\\enot&$J$\\\\\n\\hline\n \\vT & \\vT & \\gF & \\gT & \\bT & \\gT & \\gT & \\gT & \\bF & \\gT &\\bF& \\gT\\\\\n \\vT & \\vF & \\gT & \\gF & \\mT & \\gT & \\gT & \\gF & \\mT & \\gF &\\mF& \\gT\\\\\n \\vF & \\vT & \\gF & \\gT & \\bT & \\gF & \\gT & \\gT & \\bF & \\gT &\\bT& \\gF\\\\\n \\vF & \\vF & \\gT & \\gF & \\bF & \\gF & \\gF & \\gF & \\bT & \\gF &\\bT& \\gF \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent  Only the second row has both `$\\enot L \\eif (J \\eor L)$' and `$\\enot L$' true, and on that row `$\\enot J$' is false. We have found one row where it failed (no matter how many rows it might pass the test for validity. So `$\\enot L \\eif (J \\eor L), \\enot L \\ \\therefore\\ \\enot J$' is invalid.\n\n\n\n\\section{Equivalent and Contradictory}\nOnly pairs of formulas can be Equivalent or Contradictory. We start with Equivalence in \\tfl:\n\t\\factoidbox{\n  $\\meta{A}$ and $\\meta{B}$ are \\define{equivalent} (in \\tfl) iff their truth values agree for each valuation.\n\t}\n\nWe have already made use of this notion in \\S\\ref{s:MoreBracketingConventions} when we showed that `$(A \\eand B) \\eand C$' and  `$A \\eand (B \\eand C)$' are equivalent. To test for equivalence using truth tables, we complete the truth tables and check the columns are identical. For example, are the formulas `$\\enot(P \\eor Q)$' and `$(\\enot P \\eand \\enot Q)$' equivalent?\n\\begin{center}\n\\begin{tabular}{c c|cccc |ccccc}\n$P$&$Q$&\\enot&$(P$&\\eor&$Q)$&$($\\enot&$P$&\\eand&\\enot&$Q)$\\\\\n\\hline\n \\vT & \\vT & \\bF & \\gT & \\gT & \\gT & \\gF & \\gT & \\bF & \\gF & \\gT \\\\\n \\vT & \\vF & \\bF & \\gT & \\gT & \\gF & \\gF & \\gT & \\bF & \\gT & \\gF \\\\\n \\vF & \\vT & \\bF & \\gF & \\gT & \\gT & \\gT & \\gF & \\bF & \\gF & \\gT \\\\\n \\vF & \\vF & \\bT & \\gF & \\gF & \\gF & \\gT & \\gF & \\bT & \\gT & \\gF \\\\\n %& & $\\uparrow$ & & & & & & $\\uparrow$\n\\end{tabular}\n\\end{center}\nBoth formulas are false on the first three rows, and true on the final row. Since they have identical truth values on every row, the two formulas are equivalent.\\\\\n\nThe definition of Contradictory formulas in \\tfl\\ is similar:\n\t\\factoidbox{\n  $\\meta{A}$ and $\\meta{B}$ are \\define{contradictory} (in \\tfl) iff their truth values differ for each valuation.\n}\n\nWe can test if the formulas `$(P \\eif Q)$' and `$(P \\eand \\enot Q)$' are contradictory:\n\\begin{center}\n\\begin{tabular}{c c|ccc |cccc}\n$P$&$Q$&$(P$&\\eif&$Q)$&$(P$&\\eand&\\enot&$Q)$\\\\\n\\hline\n \\vT & \\vT & \\gT & \\bT & \\gT & \\gT & \\bF & \\gF & \\gT \\\\\n \\vT & \\vF & \\gT & \\bF & \\gF & \\gT & \\bT & \\gT & \\gF \\\\\n \\vF & \\vT & \\gF & \\bT & \\gT & \\gF & \\bF & \\gF & \\gT \\\\\n \\vF & \\vF & \\gF & \\bT & \\gF & \\gF & \\bF & \\gT & \\gF \\\\\n %& & $\\uparrow$ & & & & & & $\\uparrow$\n\\end{tabular}\n\\end{center}\nThe first formula is false only on the second row, while the second formula is true on the second row, and false elsewhere. Since they have different truth values on every row, the two formulas are contradictory.\\\\\n\nBeing equivalent and contradictory are negations of each other, in the sense that $\\meta{A}$ and $\\meta{B}$ are equivalent iff $\\meta{A}$ and $\\enot\\meta{B}$ are contradictory.\n\n\n\n\\section{Relationships between Logical Notions}\nWe can observe a number of relationships between our logical terms.\n\n\\begin{earg}\n\\item The negation of a logical truth is a logical falsehood.\n\\item The negation of a logical falsehood is a logical truth.\\\\\n\n\\item The conjunction of inconsistent formulas is a logical falsehood.\n\\item A single formula is inconsistent iff it is a logical falsehood.\n\\item A set of formulas is inconsistent iff their conjunction is a logical falsehood.\n\\item A formula's negation is inconsistent iff it is a logical truth.\n\\item A set of formulas is inconsistent iff the disjunction of their negations is a logical truth.\\\\\n\n\\item An argument is valid iff the conditional from the conjunction of its premises to its conclusion is a logical truth.\n\\item An argument is valid iff its premises plus its negated conclusion is inconsistent.\n\\item An argument is invalid iff its premises plus its negated conclusion is consistent.\n\\item Any argument whose conclusion is a logical truth is valid.\n\\item Any argument whose premises are inconsistent is valid.\\\\\n\n\\item All logical truths are equivalent to each other.\n\\item All logical falsehoods are equivalent to each other.\n\\item Any logical truth and falsehood are contradictory.\n\\item A pair of formulas is equivalent iff one paired with the negation of the other is contradictory.\n\\item A pair of formulas is equivalent iff a formula joining them with a biconditional is a logical truth.\n\\item A pair of formulas is equivalent iff each is mutually inconsistent with the other's negation.\n\\item A pair of formulas is contradictory iff a formula joining them with a biconditional is a logical falsehood.\n\\item A pair of formulas is contradictory iff a formula joining them with an exclusive disjunction is a logical truth.\n\\item A pair of formulas is contradictory iff they are mutually inconsistent and so are their negations.\n\\item A pair of formulas is equivalent iff the arguments from each to the other are both valid.\n\n\\end{earg}\n\n\n\n%Mutual consistency only requires that we find one row where the formulas are all true. This is similar to a failure of logical truth (one false row), or a failure of logical falsehood (one row true). In this sense, checking consistency is the opposite process to truth, falsity, and (as we will shortly see) validity and equivalence.\\\\\n%\n%Consistency is about the possibility that things could be a certain way. The rest of our logical terms are about certainty, ruling out possibilities that they could be otherwise. This makes checking for consistency a special case in ways that will prove to be important in Part \\ref{part:tfl.trees}.\n%\n%Framing our other logical tests in terms of mutual inconsistency is useful, as we can look for a possibility (row) where the formulas are consistent. This row would be a counter-example to the property we seek. Seeking this single row can be a lot faster than writing a complete truth table. For example, we can show that $(A \\eor \\enot B) \\ \\therefore\\ \\enot (A \\eif B)$ is invalid by showing that $(A \\eor \\enot B)$ is mutually consistent with $(A \\eif B)$: \n%\n%\\begin{center}\n%\\begin{tabular}{cc|ccc |cccc}\n%$A$&$B$&$(A$&\\eif&$B)$&$(A$&\\eor&\\enot&$B)$\\\\\n%\\hline\n% \\vT & \\vT & \\gT & \\mT & \\gT & \\gT & \\mT & \\gF & \\gT \\\\\n%% \\vT & \\vF & \\gT & \\mF & \\gF & \\gT & \\mT & \\gT & \\gF \\\\\n%% \\vF & \\vT & \\gF & \\mT & \\gT & \\gF & \\mT & \\gF & \\gT \\\\\n%% \\vF & \\vF & \\gF & \\mT & \\gF & \\gF & \\mF & \\gT & \\gF \n%\\end{tabular}\n%\\end{center}\n\n\n%\\section{Logical Truth and Falsehood}\n%Here is a similarly useful notion that we can adapt to \\tfl:\n%\t\\factoidbox{\n%  $\\meta{A}$ is a \\define{logical truth} (in \\tfl) iff it is true for all valuations.\n%\n%  $\\meta{A}$ is a \\define{logical falsehood} iff it is false for all valuations.\n%  \n%  $\\meta{A}$ is \\define{contingent} iff it is not a logical truth nor falsehood.\n%\t}\n%\n%\\begin{center}\n%\\begin{tabular}{c |ccc |cccc| cccc}\n%$P$ & $P$ & \\eif & $P$ & $P$ & \\eand & \\enot & $P$ & $P$ & \\eif & \\enot & $P$\\\\\n%\\hline\n% \\vT & \\vT & \\mT & \\vT & \\vT & \\mF   & \\vF   & \\vT & \\vT & \\mF  & \\vF   & \\vT \\\\\n% \\vF & \\vF & \\mT & \\vF & \\vF & \\mF   & \\vT   & \\vF & \\vF & \\mT  & \\vT   & \\vF \\\\\n% %& & $\\uparrow$ & & & & & & $\\uparrow$\n%\\end{tabular}\n%\\end{center}\n%The above complete truth table tells us that $(p \\eif p)$ is a logical truth, $(p \\land \\enot p)$ a logical falsehood, and surprisingly, $(p \\eif\\enot p)$ is contingent.\n%\n%\\medskip\n%\n%Take a moment to explore these notions. Ask yourself some questions. For instance: Are any two logical truths equivalent? Are they always mutually consistent? Is there a pair of equivalent formulas that are mutually inconsistent?\n%\n%In \\tfl, logical truths are often called \\emph{tautologies}, and logical falsehoods are often called \\emph{contradictions}. We will use these terms occasionally.\n\n\\pagebreak\n\n\n\n\n\\section{Some Challenges with \\tfl}\\label{s:ParadoxesOfMaterialConditional}\nWe can now test for validity of arguments in \\tfl! Sadly, this means that we can also describe some of \\tfl's limitations. We will illustrate some of these using three examples. \\\\\n\n\n(1) The expressive paucity of \\tfl\\ affects our analysis of argument validity. Consider the argument: \n\\begin{earg}\n\\item Daisy has four legs. So Daisy has more than two legs.\n\\end{earg}\nThis argument is valid in English. But as there are no logical connectives that \\tfl\\ recognises, any symbolisation of this argument in \\tfl\\ would be of the form `$A\\ \\therefore \\ B$',  which is not formally valid:\n\n\\begin{center}\n  \\begin{tabular}{cc|c||c}\n    $A$&$B$&$A$&$B$\\\\\n    \\hline\n    \\vT & \\vT & \\bT & \\bT \\\\\n    \\vT & \\vF & \\mT & \\mF \\\\\n    \\vF & \\vT & \\bT & \\bT\\\\\n    \\vF & \\vF & \\bF & \\bF\n  \\end{tabular}\n\\end{center}      \n\n\nOn the second row the premise is true and the conclusion is false. So \\tfl\\ hasn't preserved whatever made the argument valid.\nThe logical link between the English premise and conclusion is that both are about the number of legs that Daisy has. But \\tfl\\ doesn't recognise the subject of a sentence. Later in this book we will introduce a logic that can represent this link, and show that this argument is valid in that logic. \\\\\n\n(2) When reasoning with vague concepts, using binary categories such as truth/falsity imposes substantial limitations. Consider the statement:\n\\begin{earg}\n  \\setcounter{eargnum}{1}\n\\item\\label{n:JanBald} Jan is neither completely bald nor completely not-bald.\n\\end{earg}\nA symbolisation of this statement in \\tfl\\ would be roughly like `$\\enot B \\eand \\enot \\enot B$'. This is a contradiction:\n\n\\begin{center}\n  \\begin{tabular}{c|cccccc}\n    $B$ & $\\enot$& $B$ & $\\eand$ & $\\enot$ & $\\enot$ & $B$\\\\\n    \\hline\n    \\vT & \\gF & \\gT & \\mF & \\gT & \\gF & \\gT \\\\\n    \\vF & \\gT & \\gF & \\mF & \\gF & \\gT & \\gF\n  \\end{tabular}\n\\end{center}      \n\n\\noindent But Statement \\ref{n:JanBald} doesn't seem to be a contradiction; we might say something like `Jan isn't really bald, but he's also not really not-bald. Jan is somewhere in-between.' Or `Jan is kinda bald', or `Jan is bald-ish'.\n\n\\pagebreak\n(3) Conditionals aren't represented adequately in \\tfl. For example:\n\n\\begin{earg}\\label{argGod1}\n\\item[P1] If God doesn't exist, then it is not the case that if I pray, then God answers my prayers.\n\\item[P2] I don't pray. \n\\item[\\therefore] God exists. \n\\end{earg}\n\n\\noindent We will use the following symbolisation key:\n\n\\begin{ekey}\n\\item[A] God answers my prayers. \n\\item[G] God exists. \n\\item[P] I pray. \n\\end{ekey}\n\n\n\\noindent Symbolising the argument in \\tfl, we obtain:\n\n\\begin{earg}\\label{argGod2}\n\\item[P1] $\\enot G \\eif \\enot (P \\eif A)$\n\\item[P2] $\\enot P$\n\\item[\\therefore] $G$\n\\end{earg}\n\n\\noindent But this argument is valid! Look at the truth-tables: \n\n\\begin{center}\n  \\begin{tabular}{ccc|ccccccc|cc||c}\n    $A$&$G$&$P$ & $\\enot$ & $G$ & $\\eif$ & $\\enot$ &  $(P$& $\\eif$& $A)$ & $\\enot$ & $P$ & $G$\\\\\n    \\hline\n    \\vT & \\vT & \\vT & \\gF & \\gT &\\bT& \\gF & \\gT &\\gT&\\gT &\\bF& \\gT & \\bT\\\\\n    \\vT & \\vT & \\vF & \\gF & \\gT &\\mT& \\gF & \\gF &\\gT&\\gT &\\mT& \\gF & \\mT\\\\\n    \\vT & \\vF & \\vT & \\gT & \\gF &\\bF& \\gF & \\gT &\\gT&\\gT &\\bF& \\gT & \\bF\\\\\n    \\vT & \\vF & \\vF & \\gT & \\gF &\\bF& \\gF & \\gF &\\gT&\\gT &\\bT& \\gF & \\bF\\\\\n    \\vF & \\vT & \\vT & \\gF & \\gT &\\bT& \\gT & \\gT &\\gF&\\gF &\\bF& \\gT & \\bT\\\\\n    \\vF & \\vT & \\vF & \\gF & \\gT &\\mT& \\gF & \\gF &\\gT&\\gF &\\mT& \\gF & \\mT\\\\\n    \\vF & \\vF & \\vT & \\gT & \\gF &\\bT& \\gT & \\gT &\\gF&\\gF &\\bF& \\gT & \\bF\\\\\n    \\vF & \\vF & \\vF & \\gT & \\gF &\\bF& \\gF & \\gF &\\gT&\\gF &\\bT& \\gF & \\bF\\\\\n  \\end{tabular}\n\\end{center}     \n\n\\noindent All rows in which both premises are true (the second and sixth row) are rows in which the conclusion is also true. So the argument is valid. But the premises could be true, and in that case, the conclusion must also be true. Hence, I can prove that God exists simply by not praying.\n\n\\begin{quote}\\emph{That escalated quickly!}\\end{quote}\n                \nIn different ways, these examples highlight some of the limits of working with a language (like \\tfl) that can \\emph{only} handle truth-functional connectives. Moreover, these limits give rise to some interesting questions in philosophical logic. \nThe case of Jan's quasi-baldness raises the general question of how logic should deal with \\emph{vague} discourse.\nThe case of the existence of God raises the question of how logic should deal with negated conditionals such as `it is not the case that if I pray, then God answers my prayers.' Both are discussed in PHIL 216. \nThe expressive paucity of \\tfl\\ is addressed in the second half of this book.\n%Part of the purpose of this course is to equip you with the tools to explore these questions of \\emph{philosophical logic}. But we have to walk before we can run; we have to become proficient in using \\tfl, before we can adequately discuss its limits, and consider alternatives. \n\n\n\n\\pagebreak\n\\practiceproblems\n\\problempart\nRevisit your answers to Chapter \\ref{ch:CompleteTruthTables} Exercise \\textbf{A}. Determine which formulas were tautologies (logical truths), which were contradictions (logical falsehoods), and which were contingent. \n\n\\\n\n\\noindent\\solutions\n\\problempart\\label{pr.TT.consistent}\nUse truth tables to determine whether these formulas are mutually consistent, or mutually inconsistent:\n\\begin{earg}\n\\item $A\\eif A$, $\\enot A \\eif \\enot A$, $A\\eand A$, $A\\eor A$ %consistent\n\\item $A\\eor B$, $A\\eif C$, $B\\eif C$ %consistent\n\\item $B\\eand(C\\eor A)$, $A\\eif B$, $\\enot(B\\eor C)$  %inconsistent\n\\item $A\\eiff(B\\eor C)$, $C\\eif \\enot A$, $A\\eif \\enot B$ %consistent\n\\end{earg}\n\n\n\\noindent\\solutions\n\\problempart\n\\label{pr.TT.valid}\nUse truth tables to determine whether each argument is valid or invalid.\n\\begin{earg}\n\\item $A\\eif A \\therefore A$ %invalid\n\\item $A\\eif(A\\eand\\enot A) \\therefore \\enot A$ %valid\n\\item $A\\eor(B\\eif A) \\therefore \\enot A \\eif \\enot B$ %valid\n\\item $A\\eor B, B\\eor C, \\enot A \\therefore B \\eand C$ %invalid\n\\item $(B\\eand A)\\eif C, (C\\eand A)\\eif B \\therefore (C\\eand B)\\eif A$ %invalid\n\\end{earg}\n\n\\noindent\\problempart Determine whether each formula is a logical truth, a logical falsehood, or a contingent formula, using a complete truth table.\n\\begin{earg}\n\\item $\\enot B \\eand B$ \\vspace{.5ex}%contra\n\\item $\\enot D \\eor D$ \\vspace{.5ex}%taut\n\\item $(A\\eand B) \\eor (B\\eand A)$\\vspace{.5ex} %contingent\n\\item $\\enot[A \\eif (B \\eif A)]$\\vspace{.5ex} %contra\n\\item $A \\eiff [A \\eif (B \\eand \\enot B)]$ \\vspace{.5ex}%contra\n\\item $[(A \\eand B) \\eiff B] \\eif (A \\eif B)$ \\vspace{.5ex}% contingent. \n\\end{earg}\n\n\n\n\\noindent\\problempart\n\\label{pr.TT.equiv}\nDetermine whether each pair of formulas are logically equivalent using complete truth tables. %If the two formulas really are logically equivalent, write ``equivalent.'' Otherwise write, ``Not equivalent.'' \n\\begin{earg}\n\\item $A$ and $\\enot A$\n\\item $A \\eand \\enot A$ and $\\enot B \\eiff B$\n\\item $[(A \\eor B) \\eor C]$ and $[A \\eor (B \\eor C)]$\n\\item $A \\eor (B \\eand C)$ and $(A \\eor B) \\eand (A \\eor C)$\n\\item $[A \\eand (A \\eor B)] \\eif B$ and $A \\eif B$\\end{earg}\n\n\n\\noindent\\problempart\n\\label{pr.TT.equiv2}\nDetermine whether each pair of formulas are logically equivalent using complete truth tables. %If the two formulas really are equivalent, write ``equivalent.'' Otherwise write, ``not equivalent.''\n\\begin{earg}\n\\item $A\\eif A$ and $A \\eiff A$ \\vspace{.5ex}\n\\item $\\enot(A \\eif B)$ and $\\enot A \\eif \\enot B$ \\vspace{.5ex}\n\\item $A \\eor B$ and $\\enot A \\eif B$ \\vspace{.5ex}\n\\item$(A \\eif B) \\eif C$ and $A \\eif (B \\eif C)$ \\vspace{.5ex}\n\\item $A \\eiff (B \\eiff C)$ and $A \\eand (B \\eand C)$ \\vspace{.5ex}\n\\end{earg}\n\n\n\\noindent\\problempart\n\\label{pr.TT.consistent2}\nDetermine whether each list of formulas is mutually consistent or mutually inconsistent using a complete truth table. \n\\begin{earg}\n\\item $A \\eand \\enot B$, $\\enot(A \\eif B)$, $B \\eif A$\\vspace{.5ex} %Consistent\n\\item $A \\eor B$, $A \\eif \\enot A$, $B \\eif \\enot B$ \\vspace{.5ex} %inconsistent. \n\\item $\\enot(\\enot A \\eor B) $, $A \\eif \\enot C$, $A \\eif (B \\eif C)$\\vspace{.5ex} %Inconsistent\n\\item $A \\eif B$, $A \\eand \\enot B$\\vspace{.5ex} %Inconsistent\n\\item $A \\eif (B \\eif C)$, $(A \\eif B) \\eif C$, $A \\eif C$\\vspace{.5ex} %consistent. \n\n\\end{earg}\n\n\\noindent\\problempart\n\\label{pr.TT.consistent3}\nDetermine whether each collection of formulas is mutually consistent or mutually inconsistent, using a complete truth table. \n\\begin{earg}\n\\item $\\enot B$, $A \\eif B$, $A$ \\vspace{.5ex}%inconsistent.\n\\item $\\enot(A \\eor B)$, $A \\eiff B$, $B \\eif A$\\vspace{.5ex} %Consistent\n\\item $A \\eor B$, $\\enot B$, $\\enot B \\eif \\enot A$\\vspace{.5ex} %Inconsistent\n\\item $A \\eiff B$, $\\enot B \\eor \\enot A$, $A \\eif B$\\vspace{.5ex} %consistent. \n\\item $(A \\eor B) \\eor C$, $\\enot A \\eor \\enot B$, $\\enot C \\eor \\enot B$\\vspace{.5ex} %consistent\n\\end{earg}\n\n\n\\noindent\\problempart\n\\label{pr.TT.valid2}\nDetermine whether each argument is valid or invalid, using a complete truth table. \n\\begin{earg}\n\\item $A\\eif B$, $B \\therefore  A$ \\vspace{.5ex} %invalid\n\\item $A\\eiff B$, $B\\eiff C \\therefore A\\eiff C$ \\vspace{.5ex} %valid\n\\item $A \\eif B$, $A \\eif C\\therefore B \\eif C$ \\vspace{.5ex} %invalid. \n\\item $A \\eif B$, $B \\eif A\\therefore A \\eiff B$ \\vspace{.5ex} %valid. \n\\end{earg}\n\n\\pagebreak\n\\noindent\\problempart\n\\label{pr.TT.valid3}\nDetermine whether each argument is valid or invalid, using a complete truth table. \n\\begin{earg}\n\\item $A\\eor\\bigl[A\\eif(A\\eiff A)\\bigr] \\therefore  A $\\vspace{.5ex}%invalid\n\\item $A\\eor B$, $B\\eor C$, $\\enot B \\therefore A \\eand C$\\vspace{.5ex} %valid\n\\item $A \\eif B$, $\\enot A\\therefore \\enot B$ \\vspace{.5ex}%invalid\n\\item $A$, $B\\therefore \\enot(A\\eif \\enot B)$ \\vspace{.5ex}%valid\n\\item $\\enot(A \\eand B)$, $A \\eor B$, $A \\eiff B\\therefore C$ \\vspace{.5ex}%valid \n\\end{earg}\n\n\\noindent\\solutions\n\\problempart\n\\label{pr.TT.concepts}\nGive reasons for your answers to these questions.\n\\begin{earg}\n\\item Suppose that \\meta{A} and \\meta{B} are logically equivalent. What can you say about $\\meta{A}\\eiff\\meta{B}$?\n%\\meta{A} and \\meta{B} have the same truth value on every line of a complete truth table, so $\\meta{A}\\eiff\\meta{B}$ is true on every line. It is a logical truth.\n\\item Suppose that $(\\meta{A}\\eand\\meta{B})\\eif\\meta{C}$ is neither a logical truth nor a contradiction. What can you say about whether $\\meta{A}, \\meta{B} \\therefore\\meta{C}$ is valid?\n%The formula is false on some line of a complete truth table. On that line, \\meta{A} and \\meta{B} are true and \\meta{C} is false. So the argument is invalid.\n\\item Suppose that $\\meta{A}$, $\\meta{B}$ and $\\meta{C}$  are mutually inconsistent. What can you say about $(\\meta{A}\\eand\\meta{B}\\eand\\meta{C})$?\n%Since $\\meta{A}$, $\\meta{B}$ and $\\meta{C}$  are mutually inconsistent,  there is no line on which all three are true, so their conjunction will be a logical falsehood.\n\\item Suppose that \\meta{A} is a contradiction. What can you say about $\\meta{A}, \\meta{B} \\ \\therefore\\ \\meta{C}$?\n%Since \\meta{A} is false on every line of a complete truth table, there is no line on which \\meta{A} and \\meta{B} are true and \\meta{C} is false. So the argument is valid.\n\\item Suppose that \\meta{C} is a logical truth. What can you say about $\\meta{A}, \\meta{B}\\ \\therefore\\  \\meta{C}$?\n%Since \\meta{C} is true on every line of a complete truth table, there is no line on which \\meta{A} and \\meta{B} are true and \\meta{C} is false. So the argument is valid.\n\\item Suppose that \\meta{A} and \\meta{B} are logically equivalent. What can you say about $(\\meta{A}\\eor\\meta{B})$?\n%It's equivalent to $\\meta{A}$. So $(\\meta{A}\\eor\\meta{B})$ is a logical truth iff \\meta{A} is; a contradiction iff \\meta{A} is; and contingent iff \\meta{A} is.\n\\item Suppose that \\meta{A} and \\meta{B} are \\emph{not} logically equivalent. What can you say about $(\\meta{A}\\eor\\meta{B})$?\n%\\meta{A} and \\meta{B} have different truth values on at least one line of a complete truth table, and $(\\meta{A}\\eor\\meta{B})$ will be true on that line. On other lines, it might be true or false. So $(\\meta{A}\\eor\\meta{B})$ is either a logical truth or it is contingent; it is \\emph{not} a contradiction.\n\\end{earg}\n\\problempart \nConsider the following possible principle:\n\t\\begin{ebullet}\n  \\item Suppose $\\meta{A}$ and $\\meta{B}$ are logically equivalent. The validity of any argument containing $\\meta{A}$ would be unaffected, if we replaced $\\meta{A}$ with $\\meta{B}$.\n\t\\end{ebullet}\nIs this principle correct? Does it matter if we replace a premise or the conclusion? What about replacing a subformula? Explain your answer.\n\n\n\n\\chapter{Partial Truth Tables}\n\\label{ch:PartialTruthTable}\n\n\\section{Going Backwards to Move Forwards}\nWhen we use truth tables to test for mutual consistency, we check for a good row -- one where all the formulas are true. Similarly when testing for validity we check for a \\emph{bad} row -- one where the premises are all true and the conclusion is false. To test logical truth we check for a bad row -- one where the formula is false. To test logical falsity we check for a bad row -- one where the formula is true. And finally to test for equivalence, we test for a bad row -- one where the formulas have different truth values.\n\nSince each test for a semantic notion \\emph{only} looks for a single row, we could try to create a partial truth table with only the valuation we are seeking. This should save a lot fo work, particualry for long truth tables.\n\nHere's our general approach for testing: we will assume we've found the row we want, and work backwards to identify what row we are on. If we get contradictory information, the row is impossible. If not, we've described our row. Either way, we'll have a result for our test. All we need to do is use our truth tables backwards:\n\n\\begin{earg}\n\t\\item If a negated formula is true, the formula is false.\n\t\\item If a negated formula is false, the formula is true.\n\t\\item If a conjunction is true, both its conjuncts are true.\n\t\\item If a conjunction is false, at least one of its conjuncts is false.\n\t\\item If a disjunction is false, both its disjuncts are false.\n\t\\item If a disjunction is true, at least one of its disjuncts is true.\n\t\\item If a conditional is false, its antecedent is true and consequent false.\n\t\\item If a conditional is true, its antecedent is false or consequent true.\n\t\\item If a biconditional is true, its subformulas have the same truth value.\n\t\\item If a biconditional is false, its subformulas have different truth values.\n\\end{earg}\n\n\n\\section{Testing our Logical Notions}\n\\paragraph{Consistency} We will use this approach to test if the set of formulas $\\{\\ (P \\eand Q), (P \\eif  R)\\ \\}$ is mutually consistent.\nIf the formulas are consistent, there is a valuation where they are both true:\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$&$(P$&\\eif&$R)$\\\\\n\\hline\n \\ & \\ & \\ & \\ &  \\vT &  \\  & \\ &  \\vT &   \\\n\\end{tabular}\n\\end{center}\n\n\\noindent We first analyse the first formula. As $(P \\eand Q)$ is true, so are $P$ and $Q$:\n\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$& $(P$&\\eif&$R)$\\\\\n\\hline\n  & & \\ & \\vT &  \\gT &  \\vT  &  &  \\vT &   \n\\end{tabular}\n\\end{center}\n\n\\noindent We record this information in the valuation for $P$ and $Q$: \n\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$& $(P$&\\eif&$R)$\\\\\n\\hline\n \\bT & \\bT & \\ & \\gT &  \\gT &  \\gT  & &  \\vT &   \n\\end{tabular}\n\\end{center}\n\n\\noindent Next, we consider the second formula, and we start by copying the information from the valuation, in this case that $P$ is true:\n\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$& $(P$&\\eif&$R)$\\\\\n\\hline\n \\bT & \\bT & \\ & \\gT &  \\gT &  \\gT  & \\vT&  \\vT &   \n\\end{tabular}\n\\end{center}\n\n\\noindent As $(P \\eif R)$ and $P$ are true, $R$ must be true as well:\n\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$& $(P$&\\eif&$R)$\\\\\n\\hline\n \\bT & \\bT & \\ & \\gT &  \\gT &  \\gT  & \\gT&  \\gT & \\vT \n\\end{tabular}\n\\end{center}\n\n\\noindent Finally, we record the information in the valuation for $R$: \n\n\\begin{center}\n\\begin{tabular}{c c c | ccc|ccc}\n$P$&$Q$&$R$  &$(P$&\\eand&$Q)$& $(P$&\\eif&$R)$\\\\\n\\hline\n \\bT & \\bT & \\bT & \\gT &  \\gT &  \\gT  & \\gT&  \\gT & \\gT \n\\end{tabular}\n\\end{center}\n\n\\noindent We've found the truth values for all the subformulas and atomic symbols. There has been no contradictory information, and we've identified a valuation where the formulas are true, so they are mutually consistent.\\\\\n\nBy working backwards from the values requires for the desired row, we can fill in the rest of the truth values, and then check if this row is possible. While each step requires a little more thought, the ultimate process is faster than the laborious task of filling in a large complete truth table. And, with the number of steps drastically reduced, the chance of a silly error can be reduced with practice.\n\n\n\\pagebreak\n\nNow let's use the same method on another set of  formulas:\n$$\\{\\ (P \\eand Q), (\\enot P \\eor  \\enot Q)\\ \\}$$ If the formulas are consistent, there is a valuation where they are both true:\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\ & \\ & \\ &  \\vT &  \\  & \\  & \\  &  \\vT &   \\\n\\end{tabular}\n\\end{center}\n\n\\noindent We start with the first formula. As $(P \\eand Q)$ is true, so are $P$ and $Q$:\n\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\ & \\ & \\vT &  \\gT &  \\vT  & \\  & \\  &  \\vT &   \\\n\\end{tabular}\n\\end{center}\n\n\\noindent We record this information in the valuation for $P$ and $Q$: \n\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT & \\bT & \\gT &  \\gT &  \\gT  & \\  & \\  &  \\vT &   \\\n\\end{tabular}\n\\end{center}\n\n\\noindent We can copy the values of $P$ and $Q$ in the second formula:\n\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT & \\bT & \\gT &  \\gT &  \\gT  & \\  & \\vT  &  \\vT &  & \\vT\n\\end{tabular}\n\\end{center}\n\n\\noindent We can now find $\\enot P$ and $\\enot Q$:\n\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT & \\bT & \\gT &  \\gT &  \\gT  & \\vF  & \\gT  &  \\vT & \\vF & \\gT\n\\end{tabular}\n\\end{center}\n\n\\noindent But as$\\enot P$ and $\\enot Q$ are false, so is $(\\enot P \\eor \\enot Q)$. But we already made that true. This is impossible!\n\n\\begin{center}\n\\begin{tabular}{c c | ccc|ccccc}\n$P$&$Q$  &$(P$&\\eand&$Q)$&$(\\enot$ & $P$&\\eor&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT & \\bT & \\gT &  \\gT &  \\gT  & \\gF  & \\gT  & \\mTF & \\gF & \\gT\n\\end{tabular}\n\\end{center}\n\n\nWe have tried to find an example of a row where the formulas are all true, that is, proof of the claim that the formulas are  mutually consistent. However, our attempt has not produced a possible valuation. We can then confidentially say that there is no row where all the premises are true, and so the set if mutually inconsistent.\n\n\n\\paragraph{Contradiction.}\nShowing that a formula is a contradiction requires us to show that there is no valuation which makes the formula true.  \nHowever, to show that a formula is \\emph{not} a contradiction, we only need find a single valuation which makes the formula true. The formula $((P \\eif Q) \\eif P) \\eand \\enot P$ seems like it might be contradictory. Let's try to make it true:\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $((P$&\\eif &$ Q )$&\\eif &$P)$&$\\eand$ & $\\enot$ &$P$\\\\\n\\hline\n  &   &   &   &  &  &  &\\vT &  \\ \n\\end{tabular}\n\\end{center}\n\n\\noindent As the conjunction is true, so are $(P \\eif Q) \\eif P$ and $\\enot P$:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $((P$&\\eif &$ Q )$&\\eif &$P)$&$\\eand$ & $\\enot$ &$P$\\\\\n\\hline\n&   & &   &  & \\vT & &\\gT & \\vT & \n\\end{tabular}\n\\end{center}\n\n\\noindent Since $\\enot P$ is true, $P$ must be false, which we record in the valuation and copy over under each occurence of $P$: \n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $((P$&\\eif &$ Q )$&\\eif &$P)$&$\\eand$ & $\\enot$ &$P$\\\\\n\\hline\n \\bF &   & \\, \\vF  &   &  & \\vT & \\vF &\\gT & \\gT & \\vF\n\\end{tabular}\n\\end{center}\n\n\\noindent As $(P \\eif Q) \\eif P$ is true, and $P$ is false, $(P \\eif Q)$ must be false:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $((P$&\\eif &$ Q )$&\\eif &$P)$&$\\eand$ & $\\enot$ &$P$\\\\\n\\hline\n \\bF &   & \\, \\gF  &  \\vF &  & \\gT & \\gF &\\gT & \\gT & \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent Now, $(P \\eif Q)$ is false, as is $P$. But this isn't possible; a false antecedent always gives a true conditional:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $((P$&\\eif &$ Q )$&\\eif &$P)$&$\\eand$ & $\\enot$ &$P$\\\\\n\\hline\n \\bF &   & \\, \\gF  &  \\mTF &  & \\gT & \\gF &\\gT & \\gT & \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent So there's no valuation where the formula is true; it's a contradiction.\\\\\n\n\nThe formula $(P \\eif Q) \\eand (P \\eif \\enot Q)$ also seems contradictory. Let's try to make it true. As it's a conjunction, its conjuncts will also be true:\n\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n  &   &   & \\vT   &   &\\gT &  & \\vT & \\ & \\\n\\end{tabular}\n\\end{center}\n\n\\noindent But there are lots of valuations where each of these formulas can be true. We will have to try several valuations; let's start with those for $P$:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT &   &  \\vT & \\gT   &   &\\gT & \\vT & \\gT & \\ & \\  \\\\\n \\bF &   &  \\vF & \\gT   &   &\\gT & \\vF & \\gT & \\ & \\ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent On the first row, as $P$ and $P \\eif Q$ are true, $Q$ must be true:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT &  \\vT &  \\gT & \\gT   &  \\vT &\\gT & \\vT & \\gT & \\ & \\vT  \\\\\n \\bF &   &  \\vF & \\gT   &   &\\gT & \\vF & \\gT & \\ & \\ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent If $Q$ is true, then $\\enot Q$ must be false:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT &  \\bT &  \\gT & \\gT   &  \\gT &\\gT & \\vT & \\vT & \\vF & \\gT  \\\\\n \\bF &   &  \\vF & \\gT   &   &\\gT & \\vF & \\gT & \\ & \\ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Now we have a conflict:\n\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bT &  \\bT &  \\gT & \\gT   &  \\gT &\\gT & \\gT & \\mTF & \\gF & \\gT  \\\\\n \\bF &   &  \\vF & \\gT   &   &\\gT & \\vF & \\gT & \\ & \\ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent So we discard the first attempt at a valuation as it is impossible:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bF &   &  \\vF & \\gT   &   &\\gT & \\vF & \\gT & \\ & \\ \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent For the remaining valuation, notice that both conjuncts are conditionals with a false antecedent, which is always true in \\tfl. We are thus free to pick any value for $Q$. Let's make it false:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eand &$(P$&\\eif&$\\enot$ & $Q)$\\\\\n\\hline\n \\bF & \\bF  &  \\gF & \\gT   & \\gF  &\\gT & \\gF & \\gT & \\gT & \\gF \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent We've found truth values for all the subformulas and atomic symbols. There has been no contradictory information, and we've identified a valuation where the formula is true, so it is not contradictory. %But you can see that this method starts to get messy.\n\n\n\n\\logic{When there is only one truth value for the subformulas that gives the desired truth value for the overall formula (such as a true conjunction), this process is straight-forward. No choices need to be made. When there are several options (such as a true disjunction), you need to list all the options, and the advantages of this method start to fade away. Either subtle strategy (or computational brute force) starts to play an important role, or we can revert to using complete truth tables.}\n\n\n\\paragraph{Tautology.} \nShowing that a formula is a logical truth requires us to show that there is no valuation which makes the formula false.  Thus, to show that a formula is \\emph{not} a logical truth, we only need  find a single valuation which makes the formula false. Let's test the formula $(P \\eif Q) \\eor (Q \\eif P)$:\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eor &$(Q$&$\\eif$ & $P)$\\\\\n\\hline\n  &   &   &   &  &  \\vF &  &  & \\ \n\\end{tabular}\n\\end{center}\n\n\\noindent If a disjunction is false, so are both its disjuncts:\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eor &$(Q$&$\\eif$ & $P)$\\\\\n\\hline\n  &   &   &  \\vF &  &  \\gF &  & \\vF  & \\ \n\\end{tabular}\n\\end{center}\n\n\\noindent  Each disjunct is a conditional, and a false conditional has a true antecedent and false consequent: \n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eor &$(Q$&$\\eif$ & $P)$\\\\\n\\hline\n  &   &  \\vT &  \\gF & \\vF &  \\gF & \\vT & \\gF  & \\vF \n\\end{tabular}\n\\end{center}\n\n\\noindent This means that $P$ (and $Q$) is both true and false:\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eor &$(Q$&$\\eif$ & $P)$\\\\\n\\hline\n \\mTF & \\mTF  &  \\gT &  \\gF & \\gF &  \\gF & \\gT & \\gF  & \\gF \n\\end{tabular}\n\\end{center}\n\n\\noindent This is an impossible valuation. There is thus no valuation where the formula is false; it's a tautology.\\\\\n\n\\noindent Let's try a different formula. Is $(P \\eif Q) \\eif (P \\eor Q)$ a tautology?\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eif &$(P$& \\eor & $Q)$\\\\\n\\hline\n  &   &   &   &  &  \\vF &  &  & \\ \n\\end{tabular}\n\\end{center}\n\n\\noindent A false conditional has a true antecedent and false consequent:\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eif &$(P$& \\eor & $Q)$\\\\\n\\hline\n  &   &   &  \\vT &  &  \\gF &  & \\vF  & \\ \n\\end{tabular}\n\\end{center}\n\n\\noindent If a disjunction is false, so are both its disjuncts:\n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eif &$(P$& \\eor & $Q)$\\\\\n\\hline\n &  &  &  \\vT & &  \\gF & \\vF & \\gF  & \\vF \n\\end{tabular}\n\\end{center}\n\n\\noindent We record this information in the valuation for $P$ and $Q$ and compute the rest of the table: \n\n\\begin{center}\n\\begin{tabular}{c c|ccccccc}\n$P$&$ Q $&   $(P$&\\eif &$ Q )$&\\eif &$(P$& \\eor & $Q)$\\\\\n\\hline\n \\bF & \\bF  & \\gF  &  \\gT & \\gF &  \\gF & \\gF & \\gF  & \\gF \n\\end{tabular}\n\\end{center}\n\n\n\\noindent We've found the truth values for all the subformulas and atomic symbols. There has been no contradictory information, and we've identified a valuation where the formula is false, so it is not a tautology.\n\n\n%Sometimes, we do not need to know what happens on every line of a truth table. Sometimes, just a line or two will do. \n\n\\paragraph{Equivalence.}\nShowing that two formulas are equivalent requires that we show there \\emph{is no} row  where the formulas have different truth values. To show that two formulas are \\emph{not} equivalent, we need to show that there \\emph{is} a row where they have different truth values. Either way, we need to check if the first formula is true and second is false, or \\emph{vice versa}. Let's test the formulas $(P \\eand \\enot Q)$ and $\\enot(\\enot P \\eor Q)$:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n  &   &   &   \\vF &  &    & \\vT \\\\\n  &   &   &   \\vT &  &    & \\vF \\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent We'll start with the second formula. If a negation is true, the subformula is false, and \\emph{vice versa}:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n  &   &   &   \\vF &  & & \\gT &&& \\vF \\\\\n  &   &   &   \\vT &  & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Now we work row by row. In the first row, we have a false conjunction and a false disjunction. The latter is more informative, because a false disjunction tells us that each disjunct is false:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n  &   &   &   \\vF &  & & \\gT &\\, \\vF&& \\gF & \\vF\\\\\n  &   &   &   \\vT &  & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent This tells us that $P$ is true (because $\\enot P$ is false) and that $Q$ is false. We record this in the valuation and compute the rest of the row, if possible:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n\\bT& \\bF  &\\vT   &   \\vF & \\vT &\\gF & \\gT &\\, \\gF&\\gT& \\gF & \\gF\\\\\n  &   &   &   \\vT &  & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Unfortunately, that gives an impossible answer for the conjunction: \n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n\\bT& \\bF  &\\gT   &   \\mTF & \\gT &\\gF & \\gT &\\, \\gF&\\gT& \\gF & \\gF\\\\\n  &   &   &   \\vT &  & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent This attempt at finding a valuation has failed, so we  try the second row: \n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n  &   &   &   \\vT &  & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\nThis time, we start with the first formula, a true conjunction, which tells us that $P$ and $\\enot Q$ must be true:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n \\bT &   & \\vT  &   \\gT & \\vT & & \\gF &&& \\vT\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Since $\\enot Q$ is true, $Q$ must be false. We record this in the valuation, copy the values over to the second formula and compute as much as we can:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n \\bT & \\bF  & \\gT  &   \\gT & \\gT &\\gF & \\gF &\\, \\vF&\\gT& \\vT & \\vF\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent Now the disjunction has an impossible answer:\n\n\\begin{center}\n\\begin{tabular}{c c|cccc|cccccc}\n$P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n\\hline\n \\bT & \\bF  & \\gT  &   \\gT & \\gT &\\gF & \\gF &\\, \\gF&\\gT& \\mTF & \\gF\\\\\n\\end{tabular}\n\\end{center}\n\n\\noindent We are unable to find a valuation that makes the two formulas have different truth values. Therefore, the formulas are equivalent. \n\n% The first valuation has a false conjunction (boo!) and a false disjunction (yay!). The second valuation has a true conjunction (yay!) and a true disjunction (boo!). Let's start with the easy option for each row:\n\n% \\begin{center}\n% \\begin{tabular}{c c|cccccccccc}\n% $P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & \\ \\  & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n% \\hline\n%  &   &   &   \\vF &  &  &  & \\gT & \\vF &  & \\gF & \\vF\\\\\n%  &  &  \\vT &   \\gT & \\vT &  &  & \\gF & & & \\vT &\\\\\n% \\end{tabular}\n% \\end{center}\n\n% Now we fill in the valuations for the atomic symbols:\n\n% \\begin{center}\n% \\begin{tabular}{c c|d e e e e e e e e f}\n% $P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & \\ \\  & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n% \\hline\n% \\vT & \\vF  &   &   \\gF &  &  &  & \\gT & \\gF & \\vT & \\gF & \\gF\\\\\n% \\vT & \\vF &  \\gT & \\gT & \\gT & \\vF &  & \\gF & & & \\gT &\\\\\n% \\end{tabular}\n% \\end{center}\n\n% \\noindent Hmm. The only valuation that might make the first formula false and the second true is where $P$ is true and $Q$ is false. But that's also the only valuation which might make the first formula true and the second. If we completely fill in this truth table row, we have:\n\n\n% \\begin{center}\n% \\begin{tabular}{c c|d e e e e e e e e f}\n% $P$&$ Q $&   $(P$&\\eand & $\\enot$ &$ Q )$ & \\ \\  & $\\enot$ &$(\\enot$ & $P$&$\\eor$ & $Q)$\\\\\n% \\hline\n% \\vT & \\vF &  \\vT & \\vT & \\vT & \\vF & & \\vT & \\vF & \\vT & \\vF & \\vF\n% \\end{tabular}\n% \\end{center}\n\n% Our best attempt at making the two formulas have different truth values results in a valuation where they are the same. These two formulas are equivalent.\n% We can also see our method of working backwards becoming less mechanical, and more like an ordinary argument. It's reaching it's limits.\n\n\\paragraph{Validity.}\nTo show an argument is invalid argument requires that we find a valuation which makes all of the premises true and the conclusion false. So to show that an argument is valid we show there is no valuation which makes all of the premises true and the conclusion false. Consider this argument:\n\n$$\\enot L \\eif (J \\eor L), \\ \\enot L, \\ \\therefore\\ J$$\n\n\n\\noindent We look for a valuation where $\\enot L \\eif (J \\eor L)$ and $\\enot L$ are true and $J$ false:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccc|cc||c}\n$J$ & $L$ & $\\enot$ & $L$ & $\\eif$ & $(J$ & $\\eor$ & $L)$ & $\\enot$ & $L$ & $J$\\\\\n  \\hline\n  && && \\vT &&&& \\vT&& \\vF\n\\end{tabular}\n\\end{center}\n\n\\noindent If $\\enot L$ is true, $L$ is false. We know $J$ is false. We record this information in the valuation and copy the values over to the first formula:\n\n\\begin{center}\n\\begin{tabular}{c c|cccccc|cc||c}\n$J$ & $L$ & $\\enot$ & $L$ & $\\eif$ & $(J$ & $\\eor$ & $L)$ & $\\enot$ & $L$ & $J$\\\\\n  \\hline\n  \\bF & \\bF& \\vF&& \\gT &\\vF&&\\vF& \\gT&\\vF& \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent Next we compute as much as we can:\n\n%\\begin{center}\n%\\begin{tabular}{c c|cccccc|cc||c}\n%$J$ & $L$ & $\\enot$ & $L$ & $\\eif$ & $(J$ & $\\eor$ & $L)$ & $\\enot$ & $L$ & $J$\\\\\n%  \\hline\n%  \\bF & \\bF& \\gF&\\vT& \\gT &\\gF&\\vF&\\gF& \\gT&\\gF& \\gF\n%\\end{tabular}\n%\\end{center}\n\n\n\\begin{center}\n\\begin{tabular}{c c|cccccc|cc||c}\n$J$ & $L$ & $\\enot$ & $L$ & $\\eif$ & $(J$ & $\\eor$ & $L)$ & $\\enot$ & $L$ & $J$\\\\\n  \\hline\n  \\bF & \\bF& \\gF&\\gT& \\mTF &\\gF&\\gF&\\gF& \\gT&\\gF& \\gF\n\\end{tabular}\n\\end{center}\n\nWe've reached an impossible situation, so there's no counter-example; this means that the argument is valid.\n\n\n% Also, if $\\enot L$ and $\\enot L \\eif (J \\eor L)$ are both true, so is $(J \\eor L)$:\n\n% \\begin{center}\n% \\begin{tabular}{c c|d e e e e e e e e e e e e f}\n% $J$ & $L$ & $\\enot$ & $L$ & \\eif & $(J$ & \\eor & $L)$ & \\ \\ \\ & $\\enot$ & $L$ & \\ \\ \\ & $J$\\\\\n% \\hline\n% \\vF & \\vF & \\vT & \\vF & \\gT & \\vF &\\vT & \\vF & & \\gT & \\vF & & \\gF\n% \\end{tabular}\n% \\end{center}\n\n% \\noindent But $(J \\eor L)$ is true and $L$ is false, so $J$ is also true:\n\n% \\begin{center}\n% \\begin{tabular}{c c|d e e e e e e e e e e e e f}\n% $J$ & $L$ & $\\enot$ & $L$ & \\eif & $(J$ & \\eor & $L)$ & \\ \\ \\ & $\\enot$ & $L$ & \\ \\ \\ & $J$\\\\\n% \\hline\n% \\gF & \\gF & \\gT & \\gF & \\gT & \\vTF &\\gT & \\gF & & \\gT & \\gF & & \\gF\n% \\end{tabular}\n% \\end{center}\n\n% \\noindent But $J$ can't be true and false. This is a contradiction. There can't be a valuation where the premises are all true and the conclusion false, so the argument is valid.\n\n\\pagebreak\nWe will test one last argument: \n\n$$A,\\ (\\enot A \\eif \\enot B)\\ \\therefore\\ B$$\n\n\n\\noindent As before, we assign the truth values required for a counter-example: \n\n\\begin{center}\n\\begin{tabular}{c c|c|ccccc||c}\n$A$ & $B$ & $A$ & \\ $(\\enot$ & $A$ & \\eif & \\enot & $B)$ & \\ $B$\\\\\n\\hline\n&& \\vT &&&\\vT &&& \\vF\n\\end{tabular}\n\\end{center}\n\n\\noindent We immediately get valuations for $A$ and $B$, which we record in the valuation, and copy over in the second formula:\n\n\\begin{center}\n\\begin{tabular}{c c|c|ccccc||c}\n$A$ & $B$ & $A$ & \\ $(\\enot$ & $A$ & \\eif & \\enot & $B)$ & \\ $B$\\\\\n\\hline\n\\bT&\\bF& \\gT &&\\vT&\\vT &&\\vF& \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent We compute further, looking for conflict:\n\n\\begin{center}\n\\begin{tabular}{c c|c|ccccc||c}\n$A$ & $B$ & $A$ & \\ $(\\enot$ & $A$ & \\eif & \\enot & $B)$ & \\ $B$\\\\\n\\hline\n\\bT&\\bF& \\gT &\\vF&\\gT&\\vT &\\vT&\\gF& \\gF\n\\end{tabular}\n\\end{center}\n\n\\noindent But everything calculates fine. We've found truth values for all the subformulas and atomic symbols. There has been no contradictory information, and we've identified a valuation where the premises are true and conclusion false. Therefore, the argument is invalid.\\\\\n\nEvery logical notion can be tested for (perhaps the trickiest is contingency, which requires that a formula not be a logical truth nor a logical falsehood). While the process can be messy, the essential points that we hope to have established are:\n\n(1) You can use truth tables `backwards' to derive the truth value of simpler formulas from more complex ones.\n\n(2) By searching for a single row that serves as a counter-example (or a confirming instance, for consistency), you can avoid the time-consuming process of filling in a complete truth table. For the small examples we've given so far, this is not really a savings, but as formulas get more complicated, the savings can become substantial.\n\n(3) When there's more than one option to consider, this method doesn't work as well. For complex cases, it can be worse than a complete truth table.\\\\\n\n\nWe still value the key insights of (1) and (2), but would like to avoid the problems with (3). To do this, we will have to create a new proof method from scratch. This new method, Truth Trees, is the topic of the next Part of this textbook. Until then, practice the reasoning-backwards mindset, and become confident in how to use the definition of a logical notion to know which row you are looking for in your partial truth table.\n\n\n\\pagebreak\n\\practiceproblems\n\n\\noindent\\solutions\n\\problempart \\label{pr.TT.eQuiv3}\nUse partial truth tables to test for logical equivalence:\n\\begin{earg}\n\\item $A$, $\\enot A$ %No\n\\item $A$, $A \\eor A$ %Yes\n\\item $A\\eif A$, $A \\eiff A$ %Yes\n\\item $A \\eor \\enot B$, $A\\eif B$ %No\n\\item $A \\eand \\enot A$, $\\enot B \\eiff B$ %Yes\n\\item $\\enot(A \\eand B)$, $\\enot A \\eor \\enot B$ %Yes\n\\item $\\enot(A \\eif B)$, $\\enot A \\eif \\enot B$ %No\n\\item $(A \\eif B)$, $(\\enot B \\eif \\enot A)$ %Yes\n\\end{earg}\n\n\n\\noindent\\problempart\n\\label{pr.TT.TTorC2}\nUse partial truth tables to test for a tautology or contradiction. \n\\begin{earg}\n\\item $\\enot B \\eand B$ %contra\n\\item $\\enot D \\eor D$ %taut\n\\item $(A\\eand B) \\eor (B\\eand A)$ %contingent\n\\item $\\enot(A \\eif (B \\eif A))$ %contra\n\\item $A \\eiff (A \\eif (B \\eand \\enot B))$ %contra\n\\item $\\enot(A\\eand B) \\eiff A$ %contingent\n\\item $A\\eif(B\\eor C)$ %contingent\n\\item $(A \\eand\\enot A) \\eif (B \\eor C)$ %logical truth\n\\item $(B\\eand D) \\eiff (A \\eiff(A \\eor C))$%contingent\n\\end{earg}\n\n\n\\noindent\n\\problempart\n\\label{pr.TT.consistent4}\nUse partial truth tables to test for mutual consistency:\n\\begin{earg}\n\\item $A \\eand B$, $C\\eif \\enot B$, $C$ %inconsistent\n\\item $A\\eif B$, $B\\eif C$, $A$, $\\enot C$ %inconsistent\n\\item $A \\eor B$, $B\\eor C$, $C\\eif \\enot A$ %consistent\n\\item $A$, $B$, $C$, $\\enot D$, $\\enot E$, $ \\vF$ %consistent\n\\item $A \\eand (B \\eor C)$, $\\enot(A \\eand C)$, $\\enot(B \\eand C)$ %consistent\n\\item $A \\eif B$, $B \\eif C$, $\\enot(A \\eif C)$ %inconsistent\n\\end{earg}\n\n\\noindent\\solutions\n\\problempart\n\\label{pr.TT.valid4}\nUse partial truth tables to test for validity:\n\\begin{earg}\n\\item $A\\eor\\bigl(A\\eif(A\\eiff A)\\bigr) \\therefore A$ %invalid\n\\item $A\\eiff\\enot(B\\eiff A) \\therefore A$ %invalid\n\\item $A\\eif B, B \\therefore A$ %invalid\n\\item $A\\eor B, B\\eor C, \\enot B \\therefore A \\eand C$ %valid\n\\item $A\\eiff B, B\\eiff C \\therefore A\\eiff C$ %valid\n\\end{earg}\n\n\\pagebreak\n\n\\noindent\\problempart\n\\label{pr.TT.TTorC3}\nUse partial truth tables to test for a tautology or contradiction. \n\n\\begin{earg}\n\\item  $A \\eif \\enot A$ \\vspace{.5ex}      \t\n\\item $A \\eif (A \\eand (A \\eor B))$ \\vspace{.5ex}\t\n\\item $(A \\eif B) \\eiff (B \\eif A)$ \t\\vspace{.5ex}    %\n\\item $A \\eif \\enot(A \\eand (A \\eor B)) $\t\\vspace{.5ex}\t\n\\item $\\enot B \\eif ((\\enot A \\eand A) \\eor B)$\\vspace{.5ex} \n\\item $\\enot(A \\eor B) \\eiff (\\enot A \\eand \\enot B)$ \\vspace{.5ex}\n\\item $((A \\eand B) \\eand C) \\eif B$\\vspace{.5ex}      \t\n\\item $\\enot\\bigl((C\\eor A) \\eor B\\bigr)$\\vspace{.5ex}       \n\\item $\\bigl((A\\eand B) \\eand\\enot(A\\eand B)\\bigr) \\eand C$ \\vspace{.5ex}\t\n\\item $(A \\eand B) )\\eif((A \\eand C) \\eor (B \\eand D))$ \\vspace{.5ex}  \n\n\\end{earg}\n\n\\noindent\\problempart\n\\label{pr.TT.TTorC4}\nUse partial truth tables to test for a tautology or contradiction. \n\\begin{earg}\n\\item  $\\enot (A \\eor A)$\\vspace{.5ex}      \t%\tContradiction  1 symbol, 2 connectives\n\\item $(A \\eif B) \\eor (B \\eif A)$\\vspace{.5ex}    \t%\tTautology  \t2 symbols, 2 connectives\n\\item $((A \\eif B) \\eif A) \\eif A$\\vspace{.5ex}    \t%\tTautology  \t2 symbols, 3 connectives\n\\item $\\enot(( A \\eif B) \\eor (B \\eif A))$\\vspace{.5ex}  \t%\tContradiction  2 symbols, 4 connectives\n\\item $(A \\eand B) \\eor (A \\eor B)$\\vspace{.5ex}     %\tContingent  2 symbols, 5 connectives\n\\item $\\enot(A\\eand B) \\eiff A$\\vspace{.5ex}     \t%contingent  \t2 symbols, 3 connectives\n\\item $A\\eif(B\\eor C)$\\vspace{.5ex}       \t%contingent  \t3 symbols, 2 connectives\n\\item $(A \\eand\\enot A) \\eif (B \\eor C)$\\vspace{.5ex}   \t%logical truth  \t3 symbols, 4 connectives \n\\item $(B\\eand D) \\eiff (A \\eiff(A \\eor C))$\\vspace{.5ex}  \t%contingent  \t4 symbols, 4 connectives\n\\item $\\enot((A \\eif B) \\eor (C \\eif D))$\\vspace{.5ex}   \t% Contingent.   4 symbols, 4 connectives\n\\end{earg}\n\n\n\n\\noindent\\problempart\nUse complete truth tables to test for logical equivalence. Then attempt this exercise again using partial truth tables.\n\\begin{earg}\n\\item $A$ and $A \\eor A$\n\\item $A$ and $A \\eand A$\n\\item $A \\eor \\enot B$ and $A\\eif B$\n\\item $(A \\eif B)$ and $(\\enot B \\eif \\enot A)$\n\\item $\\enot(A \\eand B)$ and $\\enot A \\eor \\enot B$\n\\item $ ((U \\eif (X \\eor X)) \\eor U)$ and $\\enot (X \\eand (X \\eand U))$\n\\item $ ((C \\eand (N \\eiff C)) \\eiff C)$ and $(\\enot \\enot \\enot N \\eif C)$\n\\item $((A \\eor B) \\eand C)$ and $(A \\eor (B \\eand C))$\n\\item $((L \\eand C) \\eand I)$ and $L \\eor C$\n\\end{earg}\n\n\n\\noindent\\problempart\n\\label{pr.TT.consistent5}\nTest for mutual consistency. Use either a complete or partial truth table.\n\\begin{earg}\n\\item $A\\eif A$, $\\enot A \\eif \\enot A$, $A\\eand A$, $A\\eor A$ %consistent\n\\item $A \\eif \\enot A$, $\\enot A \\eif A$%inconsistent. \n\\item $A\\eor B$, $A\\eif C$, $B\\eif C$ %consistent\n\\item $A \\eor B$, $A \\eif C$, $B \\eif C$, $\\enot C$ %\tInconsistent\n\\item $B\\eand(C\\eor A)$, $A\\eif B$, $\\enot(B\\eor C)$  %inconsistent\n\\item $(A \\eiff B) \\eif B$,  $B \\eif \\enot (A \\eiff B)$, $A \\eor B$  %\tConsistent\n\\item $A\\eiff(B\\eor C)$, $C\\eif \\enot A$, $A\\eif \\enot B$ %consistent\n\\item  $A \\eiff B$,  $\\enot B \\eor \\enot A$,  $A \\eif  B$ % Consistent\n\\item $A \\eiff B$, $A \\eif C$, $B \\eif D$, $\\enot(C \\eor D)$ %consitent\n\\item $\\enot (A \\eand \\enot B)$,  $B \\eif \\enot A$, $\\enot B$   %Consistent\n\\end{earg}\n\n\\noindent\\problempart Test for validity. Use either a complete or partial truth table.\n\n\\label{pr.TT.valid5} \n\\begin{earg}\n\\item $A\\eif(A\\eand\\enot A)\\therefore \\enot A$% valid\n\\item $A \\eor B$, $A \\eif B$, $B \\eif A \\therefore  A \\eiff B$  % Valid\n\\item $A\\eor(B\\eif A)\\therefore \\enot A \\eif \\enot B$ %valid\n\\item $A \\eor B$, $A \\eif B$, $ B \\eif A \\therefore  A \\eand B$ %valid\n\\item $(B\\eand A)\\eif C$, $(C\\eand A)\\eif B\\therefore (C\\eand B)\\eif A$ % invalid\n\\item $\\enot (\\enot A \\eor \\enot B)$, $A \\eif \\enot C \\therefore  A \\eif (B \\eif C)$ % invalid.\n\\item $A \\eand (B \\eif C)$, $\\enot C \\eand (\\enot B \\eif \\enot A)\\therefore C \\eand \\enot C$ % valid\n\\item $A \\eand B$, $\\enot A \\eif \\enot C$, $B \\eif \\enot D \\therefore  A \\eor B$ % Invalid\n\\item $A \\eif B\\therefore (A \\eand B) \\eor (\\enot A \\eand \\enot B)$ % invalid\n\\item $\\enot A \\eif B$,$ \\enot B \\eif C $,$ \\enot C \\eif A \\therefore  \\enot A \\eif (\\enot B \\eor \\enot C) $% Invalid\n\n\\end{earg}\n\n\\noindent\\problempart Test for validity. Use either a complete or partial truth table.\n\\label{pr.TT.valid6} \n\\begin{earg}\n\\item $A\\eiff\\enot(B\\eiff A)\\therefore A$ % invalid\n\\item $A\\eor B$, $B\\eor C$, $\\enot A\\therefore B \\eand C$ % invalid\n\\item $A \\eif C$, $E \\eif (D \\eor B)$, $B \\eif \\enot D\\therefore (A \\eor C) \\eor (B \\eif (E \\eand D))$ % invalid\n\\item $A \\eor B$, $C \\eif A$, $C \\eif B\\therefore A \\eif (B \\eif C)$ % invalid\n\\item $A \\eif B$, $\\enot B \\eor A\\therefore A \\eiff B$ % valid\n\\end{earg}\n\n\\end{document}", "meta": {"hexsha": "5e0a9415973d908cd6139a5559a6b102a1f5ca8d", "size": 85100, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "part03-truth-tables.tex", "max_stars_repo_name": "jseligma/forallx-auckland", "max_stars_repo_head_hexsha": "62c7b8be2240f9ad693556a7f3662678530deaeb", "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": "part03-truth-tables.tex", "max_issues_repo_name": "jseligma/forallx-auckland", "max_issues_repo_head_hexsha": "62c7b8be2240f9ad693556a7f3662678530deaeb", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "part03-truth-tables.tex", "max_forks_repo_name": "jseligma/forallx-auckland", "max_forks_repo_head_hexsha": "62c7b8be2240f9ad693556a7f3662678530deaeb", "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.7399770905, "max_line_length": 609, "alphanum_fraction": 0.6431609871, "num_tokens": 31454, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916134888613, "lm_q2_score": 0.8740772335247532, "lm_q1q2_score": 0.7546709529668169}}
{"text": "\\section*{Problem 5: Naive Bayes: Implementation [30 pts] (Siddharth)}\n\nAs part of this problem, you will implement a Naive Bayes classifier for classifying movie reviews as positive or negative. The dataset that you will be using is the IMDB Large Movie Review dataset (Maas et. al, ACL 2011). The processed dataset can be found \\textit{\\href{https://www.dropbox.com/s/liz0o40f5mpj8ye/hw1_dataset_nb.tar.gz?dl=0}{here}}. The task is to estimate appropriate parameters using the training data, and use it to predict reviews from the test data, and classify each of them as either positive or negative.\n\nWe employ the {\\color{red}Multinomial Naive Bayes model for modeling each $P(X_i | Y = y_k)$ ($i = 1 .. n$), with appropriate word counts} (Note $n$ is the number of dimensions).\n\nPlease use Matlab, Python, R, C/C++ or Java for your implementation. Note that you will have to submit your codes in Autolab, and provide the answers to the questions in the below subsections in your report.\n\n\\subsection*{Preprocessing}\nThe dataset is partitioned into 2 folders: `train' and `test', each of which contains 2 subfolders (`pos' and `neg', for positive and negative samples respectively). The content of each file has to be converted to a bag-of-words representation. So the first task is to go through all the files in the `train' folder, and construct the vocabulary $V$ of all unique words. Please ignore all the stop-words as given in the file `sw.txt' (provided along with the dataset). The words from each file (both in training and testing phase) must be extracted by splitting the raw text only with whitespace characters and {\\color{red}converting them to lowercase characters}. \n\nThe next step is to get counts of each individual words for the positive and the negative classes separately, to get $P(word | class)$. \n\n\\subsection*{Classification}\nIn this step, you need to go through all the negative and positive samples in the test data, and classify each sample according to the parameters learned earlier. The classification should be done by comparing the log-posterior (un-normalized), which is given by $\\log(P(X|Y)P(Y))$, for both the classes.\n\n\\subsection*{Laplace smoothing}\nAn issue with the original Naive Bayes setup is that if a test sample contains a word which is not present in the dictionary, the $P(word|label)$ goes to $0$. To mitigate this issue, one solution is to employ Laplace smoothing (it has a parameter $\\alpha$). Augment your $P(word | class)$ calculations by including the appropriate terms for doing Laplace smoothing. \n\nReport the confusion matrix and overall accuracy of your classifier on the test dataset with $\\alpha = 1$. Recall that the confusion matrix for such 2-class classification problem, is a matrix of the number of true positives (positive samples correctly classified as positive), number of true negatives (negative samples correctly classified as negative), number of false positives (negative samples incorrectly classified as positive), and number of false negatives (positive samples incorrectly classified as negative). The accuracy is the ratio of sum of true positives and true negatives, and the total number of samples (in the test dataset).\n\nNow vary the value of $\\alpha$ from $0.0001$ to $1000$ (by multiplying $\\alpha$ with 10 each time), and report a plot of the accuracy on the test dataset for the corresponding values of $\\alpha$. (The x-axis should represent $\\alpha$ values and use a $\\log$ scale for the x-axis).\n\n Why do you think the accuracy suffers when $\\alpha$ is too high or too low? \n    \n\n\n\n", "meta": {"hexsha": "821b5e3551fcab52c8e342536a07b86d1619b4e4", "size": 3577, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem5.tex", "max_stars_repo_name": "DylanFrank/Learn", "max_stars_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_stars_repo_licenses": ["BSD-2-Clause"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-10-24T09:26:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T12:55:26.000Z", "max_issues_repo_path": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem5.tex", "max_issues_repo_name": "DylanFrank/Learn", "max_issues_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "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": "CMU-ML/10701/HW1_Tex_v3/Tex Folder_v3/problem5.tex", "max_forks_repo_name": "DylanFrank/Learn", "max_forks_repo_head_hexsha": "e7cb6281af0c45fa469c854c2ad6325e8207f1c8", "max_forks_repo_licenses": ["BSD-2-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2019-01-10T02:18:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-09T07:45:23.000Z", "avg_line_length": 123.3448275862, "max_line_length": 665, "alphanum_fraction": 0.7746715124, "num_tokens": 814, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916064586998, "lm_q2_score": 0.8740772318846387, "lm_q1q2_score": 0.7546709454058517}}
{"text": "\\section{Bootstrap}\nThe {\\bf bootstrap} is a statistical method for estimating standard errors and confidence sets of statistics, such as estimators.\n\n\\subsection{Non-parametric Bootstrap for Confidence Sets}\\label{S:NPBootstrap}\nLet $T_n := T_n((X_1,X_2,\\ldots,X_n))$ be a statistic, i.e.~any function of the data $X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F^*$.  Suppose we want to know its variance $\\V_{F^*}(T_n)$, which clearly depends on the fixed and possibly unknown DF $F^*$.  \n\nIf our statistic $T_n$ is one with an analytically unknown variance, then we can use the bootstrap to estimate it.  The bootstrap idea has the following two basic steps:\n\\begin{enumerate}\n\\item[$\\mathsf{Step~1}$:] Estimate $\\V_{F^*}(T_n)$ with $\\V_{\\widehat{F}_n}(T_n)$.\n\\item[$\\mathsf{Step~2}$:] Approximate $\\V_{\\widehat{F}_n}(T_n)$ using simulated data from the ``Bootstrap World.'' \n\\end{enumerate}\nFor example, if $T_n=\\overline{X}_n$, in $\\mathsf{Step~1}$, $\\V_{\\widehat{F}_n}(T_n) = s_n^2/n$, where $s_n^2=n^{-1} \\sum_{i=1}^n (x_i-\\overline{x}_n)$ is the sample variance and $\\overline{x}_n$ is the sample mean.  In this case,  $\\mathsf{Step~1}$ is enough.  However, when the statistic $T_n$ is more complicated (e.g.~$T_n=\\widetilde{X}_n = F^{[-1]}(0.5)$), the sample median, then we may not be able to find a simple expression for $\\V_{\\widehat{F}_n}(T_n)$ and may need $\\mathsf{Step~2}$ of the bootstrap.\n\n\\begin{eqnarray}\n\\text{Real World Data come from} &  F^* \\quad \\implies X_1,X_2,\\ldots,X_n & \\implies \nT_n((X_1,X_2,\\ldots,X_n))=t_n \\notag \\\\\n\\text{Bootstrap World Data come from} & \\widehat{F}_n \\quad  \\implies X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n & \\implies \nT_n((X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n))=t^{\\bullet}_n \\notag\n\\end{eqnarray}\n\nObserve that drawing an observation from the ECDF $\\widehat{F}_n$ is equivalent to drawing one point at random from the original data (think of the indices $[n] := \\{ 1,2,\\ldots,n \\}$ of the original data $X_1,X_2,\\ldots,X_n$ being drawn according to the equi-probable $\\demoivre(1/n,1/n,\\ldots,1/n)$ RV on $[n]$).  Thus, to simulate $X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n$ from $\\widehat{F}_n$, it is enough to drawn $n$ observations with replacement from $X_1,X_2,\\ldots,X_n$.\n\nIn summary, the algorithm for Bootstrap Variance Estimation is:\n\n\\begin{enumerate}\n\\item[$\\mathsf{Step~1}$:] Draw $X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n \\sim \\widehat{F}_n$\n\\item[$\\mathsf{Step~2}$:] Compute $t_n^{\\bullet} = T_n((X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n))$\n\\item[$\\mathsf{Step~3}$:] Repeat $\\mathsf{Step~1}$ and $\\mathsf{Step~2}$ $B$ times, for some large $B$, say $B>1000$, to get $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$\n\\item[$\\mathsf{Step~4}$:] Several ways of estimating the bootstrap confidence intervals are possible:\n\\begin{enumerate}\n\\item The  $1-\\alpha$ Normal-based bootstrap confidence interval is:\n\\[\nC_n = [T_n - z_{\\alpha/2} \\widehat{se}_{boot}, T_n + z_{\\alpha/2} \\widehat{se}_{boot}] \\ ,\n\\]\nwhere the bootstrap-based standard error estimate is:\n\\[\n\\widehat{se}_{boot} = \\sqrt{v_{boot}} = \\sqrt{ \\frac{1}{B} \\sum_{b=1}^B \\left(  t_{n,b}^{\\bullet} - \\frac{1}{B} \\sum_{r=1}^B t_{n,r}^{\\bullet} \\right)^2}\n\\]\n\\item The $1-\\alpha$ percentile-based bootstrap confidence interval is:\\\\\n\\[\nC_n=[\\widehat{G^{\\bullet}}_{n}^{-1}(\\alpha/2),\\widehat{G^{\\bullet}}_{n}^{-1}(1-\\alpha/2)] ,\n\\]\nwhere $\\widehat{G^{\\bullet}}_{n}$ is the empirical DF of the bootstrapped $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$ and $\\widehat{G^{\\bullet}}_{n}^{-1}(q)$ is the $q^{\\text{th}}$ sample quantile \\eqref{E:qthSampleQuantile} of $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$.\n\\end{enumerate}\n\\end{enumerate}\n\n\\begin{labwork} [Confidence Interval for Median Estimate of Inter Earth Quake Times]\\label{LW:NZSIEQTimesMedianBootstrap}\nLet us find the $95\\%$ Normal-based bootstrap confidence interval as well as the  $95\\%$ percentile-based bootstrap confidence interval for our plug-in estimate of the median of inter earth quake times from \\hyperref[LW:PlugInEstimatesEarthQuakes]{Labwork~\\ref*{LW:PlugInEstimatesEarthQuakes}} using the following script:\n\\VrbMf[label=NZSIEQTimesMedianBootstrap.m]{scripts/NZSIEQTimesMedianBootstrap.m}\n\nWe get the following output when we call the script file.\n\\begin{VrbM}\n>> NZSIEQTimesMedianBootstrap\nn =        6127\nMedianhat =   25.5092\nB =        1000\nans =        6127        1000\nConfInt95BootNormal =   24.4383   26.5800\nConfInt95BootPercentile =   24.4057   26.4742\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[Confidence Interval for Median Estimate of Web Login Data]\nFind the $95\\%$ Normal-based bootstrap confidence interval as well as the  $95\\%$ percentile-based bootstrap confidence interval for our plug-in estimate of the median for each of the data arrays:\n\\[\n\\text{{\\tt WebLogSeconds20071001035730} and {\\tt WebLogSeconds20071002035730} .}\n\\]\nOnce again, the arrays can be loaded into memory by following the commands in the first $13$ lines of the script file {\\tt WebLogDataProc.m} of \\hyperref[DA:WebLogs]{Section~\\ref*{DA:WebLogs}}.  Produce four intervals (two for each data-set).  Do the confidence intervals for the medians for the two days intersect?\n\\begin{VrbM}\n>> WebLogDataProc % load in the data\n>> Medianhat = median(WebLogSeconds20071001035730) % plug-in estimate of median\nMedianhat =       37416\n>> % store the length of data array\n>> K=length(WebLogSeconds20071001035730) \nK =       56485\n>> B= 1000 % Number of Bootstrap replications\nB =        1000\n>> BootstrappedDataSet = WebLogSeconds20071001035730([ceil(K*rand(K,B))]); \n>> size(BootstrappedDataSet) % dimension of the BootstrappedDataSet\nans =       56485        1000\n>> BootstrappedMedians=median(BootstrappedDataSet); % get the statistic in Bootstrap world\n>> % 95% Normal based Confidence Interval\n>> SehatBoot = std(BootstrappedMedians); % std of BootstrappedMedians\n>> % 95% C.I. for median from Normal approximation\n>> ConfInt95BootNormal = [Medianhat-1.96*SehatBoot, Medianhat+1.96*SehatBoot] \nConfInt95BootNormal =    37242    37590\n>> % 95% Percentile based Confidence Interval\nConfInt95BootPercentile = ...\n    [qthSampleQuantile(0.025,sort(BootstrappedMedians)),...\n    qthSampleQuantile(0.975,sort(BootstrappedMedians))]\nConfInt95BootPercentile =   37239    37554\n\\end{VrbM}\n\\end{labwork}\n\n\\begin{labwork}[Confidence interval for correlation]\\label{LW:LSATGPACorrBoot}\nHere is a classical data set used by Bradley Efron (the inventor of bootstrap) to illustrate the method.  The data are LSAT (Law School Admission Test in the U.S.A.) scores and GPA of fifteen individuals.\n\nThus, we have bivariate data of the form $(Y_i,Z_i)$, where $Y_i={\\rm LSAT}_i$ and $Z_i={\\rm GPA}_i$.  For example, the first individual had an LSAT score of  $y_1=576$ and a GPA of $z_1=3.39$ while the fifteenth individual had an LSAT score of $y_{15}=594$ and a GPA of $z_{15}=3.96$.  We supose that the bivariate data $(Y_i,Z_i) \\overset{IID}{\\sim} F^*$, such that $F^* \\in \\{ \\text{all bivariate DFs} \\}$.  This is a bivariate non-parametric experiment.  The bivariate data are plotted in Figure .\n\n\nThe law school is interested in the correlation between the GPA and LSAT scores:\n$$\n\\theta^* = \\frac{\\int \\int (y-\\E(Y))(z-\\E(Z))dF(y,z)}{\\sqrt{\\int (y-\\E(Y))^2 dF(y) \\int (z-\\E(Z))^2 dF(z)}}\n$$\nThe plug-in estimate of the population correlation $\\theta^*$ is the sample correlation:\n$$\n\\widehat{\\Theta}_n = \\frac{\\sum_{i=1}^n(Y_i-\\overline{Y}_n)(Z_i-\\overline{Z}_n)}{\\sqrt{\\sum_{i=1}^n(Y_i-\\overline{Y}_n)^2 \\sum_{i=1}^n(Z_i-\\overline{Z}_n)^2}}\n$$ \n\\VrbMf[label=LSATGPACorrBootstap.m]{scripts/LSATGPACorrBootstap.m}\n\nWe get the following output when we call the script file.\n\\begin{VrbM}\n>> LSATGPACorrBootstap\nSampleCorrelation =    0.5459\nConfInt95BootNormal =    0.1770    0.9148\nConfInt95BootPercentile =    0.2346    0.9296\n\\end{VrbM}\n\n\\begin{figure}\n\\caption{Data from Bradley EfronÕs LSAT and GPA scores for fifteen individuals (left).  The confidence interval of the sample correlation, the plug-in estimate of the population correlation, is obtained from the sample correlation of one thousand bootstrapped data sets (right).\\label{F:LSATGPACorrBootstrap}}\n\\begin{center}\n\\makebox{\\includegraphics[width=4.5in]{figures/LSATGPACorrBootstrap}}\n\\end{center}\n\\end{figure}\n\n\\end{labwork}\n\n\\subsection{Parametric Bootstrap for Confidence Sets}\\label{S:PBootstrap}\n\nThe {\\bf bootstrap} may also be employed for estimating standard errors and confidence sets of statistics, such as estimators, even in a parametric setting.  This is much easier than the the variance calculation based on Fisher Information and/or the Delta method.  \n\nThe only difference in the {\\bf parametric bootstrap} as opposed to the {\\bf non-parametric bootstrap} we saw earlier is that our statistic of interest $T_n := T_n((X_1,X_2,\\ldots,X_n))$ is a function of the data: \n$$X_1,X_2,\\ldots,X_n \\overset{\\IID}{\\sim} F(x;\\theta^*) \\enspace .$$\nThat is, our data come from a parametric distribution $F(x;\\theta^*)$ and we want to know the variance of our statistic $T_n$, i.e.~$\\V_{\\theta^*}(T_n)$.  \n\nThe parametric bootstrap concept has the following two basic steps:\n\\begin{enumerate}\n\\item[$\\mathsf{Step~1}$:] Estimate $\\V_{\\theta^*}(T_n)$ with $\\V_{\\widehat{\\theta}_n}(T_n)$, where $\\widehat{\\theta}_n$ is an estimate of $\\theta^*$ based on maximum likelihood or the method of moments.\n\\item[$\\mathsf{Step~2}$:] Approximate $\\V_{\\widehat{\\theta}_n}(T_n)$ using simulated data from the ``Bootstrap World.'' \n\\end{enumerate}\nFor example, if $T_n=\\overline{X}_n$, the sample mean, then in $\\mathsf{Step~1}$, $\\V_{\\widehat{\\theta}_n}(T_n) = n^{-1} \\sum_{i=1}^n (x_i-\\overline{x}_n)$ is the sample variance.  Thus, in this case,  $\\mathsf{Step~1}$ is enough.  However, when the statistic $T_n$ is more complicated, say $T_n=\\widetilde{X}_n = F^{[-1]}(0.5)$, the sample median, then we may not be able to write down a  simple expression for $\\V_{\\widehat{\\theta}_n}(T_n)$ and may need $\\mathsf{Step~2}$ of the bootstrap.\n\\begin{eqnarray}\n{\\scriptsize \\text{Real World Data come from}} &  F(\\theta^*) \\quad \\implies X_1,X_2,\\ldots,X_n & \\implies \nT_n((X_1,X_2,\\ldots,X_n))=t_n \\notag \\\\\n{\\scriptsize \\text{Bootstrap World Data come from}} & F(\\widehat{\\theta}_n) \\quad  \\implies X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n & \\implies \nT_n((X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n))=t^{\\bullet}_n \\notag\n\\end{eqnarray}\nTo simulate $X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n$ from $F(\\widehat{\\theta}_n)$, we must have a simulation algorithm that allows us to draw IID samples from $F(\\theta)$, for instance the inversion sampler.  In summary, the algorithm for Bootstrap Variance Estimation is:\n\\begin{enumerate}\n\\item[$\\mathsf{Step~1}$:] Draw $X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n \\sim F(\\widehat{\\theta}_n)$\n\\item[$\\mathsf{Step~2}$:] Compute $t_n^{\\bullet} = T_n((X^{\\bullet}_1,X^{\\bullet}_2,\\ldots,X^{\\bullet}_n))$\n\\item[$\\mathsf{Step~3}$:] Repeat $\\mathsf{Step~1}$ and $\\mathsf{Step~2}$ $B$ times, for some large $B$, say $B\\geq1000$, to get $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$\n\\item[$\\mathsf{Step~4}$:] We can estimate the bootstrap confidence intervals in several ways:\n\\begin{enumerate}\n\\item The  $1-\\alpha$ normal-based bootstrap confidence interval is:\n\\[\nC_n = [T_n - z_{\\alpha/2} \\widehat{se}_{boot}, T_n + z_{\\alpha/2} \\widehat{se}_{boot}] \\ ,\n\\]\nwhere the bootstrap-based standard error estimate is:\n\\[\n\\widehat{se}_{boot} = \\sqrt{v_{boot}} = \\sqrt{ \\frac{1}{B} \\sum_{b=1}^B \\left(  t_{n,b}^{\\bullet} - \\frac{1}{B} \\sum_{r=1}^B t_{n,r}^{\\bullet} \\right)^2}\n\\]\n\\item The $1-\\alpha$ percentile-based bootstrap confidence interval:\\\\\n\\[\nC_n=[\\widehat{G^{\\bullet}}_{n}^{-1}(\\alpha/2),\\widehat{G^{\\bullet}}_{n}^{-1}(1-\\alpha/2)] ,\n\\]\nwhere $\\widehat{G^{\\bullet}}_{n}$ is the empirical DF of the bootstrapped $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$ and $\\widehat{G^{\\bullet}}_{n}^{-1}(q)$ is the $q^{\\text{th}}$ sample quantile \\eqref{E:qthSampleQuantile} of $t_{n,1}^{\\bullet}, t_{n,2}^{\\bullet},\\ldots,t_{n,B}^{\\bullet}$.\n\\end{enumerate}\n\\end{enumerate}\n\nLet us apply the bootstrap method to the previous problem of estimating the standard error of the coefficient of variation from $n=100$ samples from $\\normal(100,10^2)$ RV.  The confidence intervals from bootstrap-based methods are similar to those from the Delta method.\n{\\VrbMf[label=CoeffOfVarNormalBoot.m]{scripts/CoeffOfVarNormalBoot.m}}\n\\begin{VrbM}\n>> CoeffOfVarNormal\nMuhat =  100.3117\nSigmahat =   10.9800\nPsihat =    0.1095\nSehat =    0.0077\nConfInt95DeltaMethod =    0.0943    0.1246\nConfInt95BootNormal =    0.0943    0.1246\nConfInt95BootPercentile =    0.0946    0.1249\n\\end{VrbM}\n", "meta": {"hexsha": "f5a5ebdedbfde735860c13ae2942ad55a57b9766", "size": 12783, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/Bootstrap.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/Bootstrap.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/Bootstrap.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": 69.8524590164, "max_line_length": 511, "alphanum_fraction": 0.7078932958, "num_tokens": 4335, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.874077222043951, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7546709430543886}}
{"text": "\\section{The Chain Rule}\\label{sec:ChainRule}\nLet $h(x)=\\sqrt{625-x^2}$.\nThe rules stated previously do not allow us to find $h'(x)$.\nHowever, $h(x)$ is a composition of two functions.\nLet $f(x)=\\sqrt x$ and $g(x)=625-x^2$.\nThen we see that \n$$h(x)=(f\\circ g)(x).$$\nFrom our rules we know that $f'(x)=\\frac{1}{2}x^{-1/2}$ and $g'(x)=-2x$, thus it would be convenient to have a rule which allows us to differentiate $f\\circ g$ in terms of $f'$ and $g'$.\nThis gives rise to the chain rule.\n\n\\begin{formulabox}[The Chain Rule]\nIf $g$ is differentiable at $x$ and $f$ is differentiable at $g(x)$, then the composite function $h=f\\circ g$ [recall $f\\circ g$ is defined as $f(g(x))$] is differentiable at $x$ and $h'(x)$ is given by:\n$$h'(x)=f'(g(x))\\cdot g'(x).$$\n\\end{formulabox}\n\nThe chain rule has a particularly simple expression if we use the\nLeibniz notation for the derivative. The quantity $f'(g(x))$ is the\nderivative of $f$ with $x$ replaced by $g$; this can be written \n$df/dg$. As usual, $g'(x)=dg/dx$. Then the chain rule becomes\n$${df\\over dx} = {df\\over dg}{dg\\over dx}.$$\nThis looks like trivial arithmetic, but it is not: $dg/dx$ is not a\nfraction, that is, not literal division, but a single symbol that\nmeans $g'(x)$. Nevertheless, it turns out that what looks like trivial\narithmetic, and is therefore easy to remember, is really true.\n\nIt will take a bit of practice to make the use of the chain rule come\nnaturally---it is more complicated than the earlier differentiation\nrules we have seen.\n\n\\begin{example}{Chain Rule}{ChainRule}\nCompute the derivative of $\\ds \\sqrt{625-x^2}$.\n\\end{example}\n\n\\begin{solution} \n We already know that the\nanswer is $\\ds -x/\\sqrt{625-x^2}$, computed directly from the limit. In\nthe context of the chain rule, we have $\\ds f(x)=\\sqrt{x}$,\n$\\ds g(x)=625-x^2$. We know that $\\ds f'(x)=(1/2)x^{-1/2}$, so $\\ds f'(g(x))=\n(1/2)(625-x^2)^{-1/2}$. Note that this is a two step computation:\nfirst compute $f'(x)$, then replace $x$ by $g(x)$. Since $g'(x)=-2x$\nwe have\n$$f'(g(x))g'(x)={1\\over 2\\sqrt{625-x^2}}(-2x)={-x\\over\n    \\sqrt{625-x^2}}.\n$$\n\\end{solution}\n\n\\begin{example}{Chain Rule}{ChainRule2}\nCompute the derivative of $\\ds 1/\\sqrt{625-x^2}$.\n\\end{example}\n\n\\begin{solution} \nThis is a quotient with\na constant numerator, so we could use the quotient rule, but it is\nsimpler to use the chain rule. The function is $\\ds (625-x^2)^{-1/2}$, the\ncomposition of $\\ds f(x)=x^{-1/2}$ and $\\ds g(x)=625-x^2$. We compute\n$\\ds f'(x)=(-1/2)x^{-3/2}$ using the power rule, and then\n$$f'(g(x))g'(x)={-1\\over 2(625-x^2)^{3/2}}(-2x)={x\\over (625-x^2)^{3/2}}.$$\n\\end{solution}\n\nIn practice, of course, you will need to use more than one of the\nrules we have developed to compute the derivative of a complicated\nfunction.\n\n\\begin{example}{Derivative of Quotient}{DerivativeQuotient}\nCompute the derivative of $$f(x)={x^2-1\\over x\\sqrt{x^2+1}}.$$\n\\vspace{-0.5cm}\n\\end{example}\n\n\\begin{solution} \nThe ``last'' operation here is division, so to get started we need to\nuse the quotient rule first. This gives\n\\begin{eqnarray*}\nf'(x)&=&{(x^2-1)'x\\sqrt{x^2+1}-(x^2-1)(x\\sqrt{x^2+1})'\\over\nx^2(x^2+1)}\\cr\n&=&{2x^2\\sqrt{x^2+1}-(x^2-1)(x\\sqrt{x^2+1})'\\over\nx^2(x^2+1)}.\\cr\n\\end{eqnarray*}\nNow we need to compute the derivative of $\\ds x\\sqrt{x^2+1}$. This is a\nproduct, so we use the product rule:\n$${d\\over dx}x\\sqrt{x^2+1}=x{d\\over dx}\\sqrt{x^2+1}+\\sqrt{x^2+1}.$$\nFinally, we use the chain rule:\n$${d\\over dx}\\sqrt{x^2+1}={d\\over dx}(x^2+1)^{1/2}=\n{1\\over 2}(x^2+1)^{-1/2}(2x)={x\\over \\sqrt{x^2+1}}.$$\nAnd putting it all together:\n\\begin{eqnarray*}\nf'(x)&=&{2x^2\\sqrt{x^2+1}-(x^2-1)(x\\sqrt{x^2+1})'\\over\nx^2(x^2+1)}.\\cr\n&=&{2x^2\\sqrt{x^2+1}-(x^2-1)\\left(x{\\ds{x\\over \\sqrt{x^2+1}}}\n+\\sqrt{x^2+1}\\right)\\over\nx^2(x^2+1)}.\\cr\n\\end{eqnarray*}\nThis can be simplified of course, but we have done all the calculus,\nso that only algebra is left.\n\\end{solution}\n\n\\begin{example}{Chain of Composition}{ChainComposition}\nCompute the derivative of $\\ds \\sqrt{1+\\sqrt{1+\\sqrt{x}}}$. \n\\end{example}\n\n\\begin{solution} \nHere we have a\nmore complicated chain of compositions, so we use the chain rule\ntwice.\nAt the outermost ``layer'' we have the function\n$\\ds g(x)=1+\\sqrt{1+\\sqrt{x}}$ plugged into $\\ds f(x)=\\sqrt{x}$, so applying\nthe chain rule once gives \n$${d\\over dx}\\sqrt{1+\\sqrt{1+\\sqrt{x}}}=\n{1\\over 2}\\left(1+\\sqrt{1+\\sqrt{x}}\\right)^{-1/2}{d\\over dx}\n\\left(1+\\sqrt{1+\\sqrt{x}}\\right).$$\nNow we need the derivative of $\\ds \\sqrt{1+\\sqrt{x}}$. Using the chain\nrule again:\n$${d\\over dx}\\sqrt{1+\\sqrt{x}}={1\\over\n  2}\\left(1+\\sqrt{x}\\right)^{-1/2}{1\\over 2}x^{-1/2}.$$\nSo the original derivative is \n\\begin{eqnarray*}\n{d\\over dx}\\sqrt{1+\\sqrt{1+\\sqrt{x}}}&=&\n{1\\over 2}\\left(1+\\sqrt{1+\\sqrt{x}}\\right)^{-1/2}\n{1\\over\n  2}\\left(1+\\sqrt{x}\\right)^{-1/2}{1\\over 2}x^{-1/2}.\\cr\n&=&{1\\over 8 \\sqrt{x}\\sqrt{1+\\sqrt{x}}\\sqrt{1+\\sqrt{1+\\sqrt{x}}}}\n\\end{eqnarray*}\n\\end{solution}\n\nUsing the chain rule, the power rule, and the product rule, it is\npossible to avoid using the quotient rule entirely.\n\n\\begin{example}{Derivative of Quotient without Quotient Rule}{DerivativeQuotientWithoutQuotientRule}\nCompute the derivative of $\\ds f(x)={x^3\\over x^2+1}$.\n\\end{example}\n\n\\begin{solution} \nWrite \n$\\ds f(x)=x^3(x^2+1)^{-1}$, then\n\\begin{eqnarray*}\nf'(x)&=&x^3{d\\over dx}(x^2+1)^{-1}+3x^2(x^2+1)^{-1}\\cr\n\\\\\n&=&x^3(-1)(x^2+1)^{-2}(2x)+3x^2(x^2+1)^{-1}\\cr\n\\\\\n&=&-2x^4(x^2+1)^{-2}+3x^2(x^2+1)^{-1}\\cr\n\\\\\n&=&{-2x^4\\over (x^2+1)^{2}}+{3x^2\\over x^2+1}\\cr\n\\\\\n&=&{-2x^4\\over (x^2+1)^{2}}+{3x^2(x^2+1)\\over (x^2+1)^{2}}\\cr\n\\\\\n&=&{-2x^4+3x^4+3x^2\\over (x^2+1)^{2}}={x^4+3x^2\\over (x^2+1)^{2}}\n\\end{eqnarray*}\nNote that we already had the derivative on the second line; all the\nrest is simplification. It is easier to get to this answer by using\nthe quotient rule, so there's a trade off: more work for fewer\nmemorized formulas.\n\\end{solution}\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\Opensolutionfile{solutions}[ex]\n\\section*{Exercises for Section \\ref{sec:ChainRule}}\n\n\\begin{enumialphparenastyle}\n\nFind the derivatives of the functions. For extra practice, and to\ncheck your answers, do some of these in more than one way if\npossible. \n\n\\begin{ex}  $\\ds x^4-3x^3+(1/2)x^2+7x-\\pi$\n\\begin{sol} \n$\\ds 4x^3-9x^2+x+7$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds x^3-2x^2+4\\sqrt{x}$\n\\begin{sol} \n$\\ds 3x^2-4x+2/\\sqrt{x}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (x^2+1)^3$\n\\begin{sol} \n$\\ds 6(x^2+1)^2x$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds x\\sqrt{169-x^2}$\n\\begin{sol} \n$\\ds \\sqrt{169-x^2}-x^2/\\sqrt{169-x^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (x^2-4x+5)\\sqrt{25-x^2}$\n\\begin{sol} \n$\\ds  (2x-4)\\sqrt{25-x^2}-$\\hfill\\break$(x^2-4x+5)x/\\sqrt{25-x^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds \\sqrt{r^2-x^2}$, $r$ is a constant\n\\begin{sol} \n$\\ds -x/\\sqrt{r^2-x^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds \\sqrt{1+x^4}$\n\\begin{sol} \n$\\ds 2x^3/\\sqrt{1+x^4}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds {1\\over\\sqrt{5-\\sqrt{x}}}$.\n\\begin{sol} \n$\\ds{1\\over 4\\sqrt{x}(5-\\sqrt{x})^{3/2}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (1+3x)^2$\n\\begin{sol} \n$\\ds  6+18x$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{(x^2+x+1)\\over(1-x)}$\n\\begin{sol} \n$\\ds {2 x + 1\\over1 - x }+{x^2  + x + 1\\over(1 - x)^2}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{\\sqrt{25-x^2}\\over x}$\n\\begin{sol} \n$\\ds  -1/\\sqrt{25-x^2}-\\sqrt{25-x^2}/x^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds\\sqrt{{169\\over x}-x}$\n\\begin{sol} \n$\\ds{1\\over2}\\left({-169\\over x^2}-1\\right)\\Big/\\sqrt{{169\\over x}-x}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds \\sqrt{x^3-x^2-(1/x)}$\n\\begin{sol} \n$ \\ds{3x^2-2x+1/x^2\\over 2\\sqrt{x^3-x^2-(1/x)}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds 100/(100-x^2)^{3/2}$\n\\begin{sol} \n$ \\ds{300 x \\over(100-x^2)^{5/2}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds {\\root 3 \\of{x+x^3}}$\n\\begin{sol} \n$ \\ds{ 1 + 3 x^2\\over3(x+x^3)^{2/3}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds \\sqrt{(x^2+1)^2+\\sqrt{1+(x^2+1)^2}}$\n\\begin{sol} \n$\\ds \\left(4x(x^2+1)+{4x^3+4x\\over2\\sqrt{1+(x^2+1)^2}}\\right)\\Big/$\\hfill\\break$2\\sqrt{(x^2+1)^2+\\sqrt{1+(x^2+1)^2}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (x+8)^5$\n\\begin{sol} \n$\\ds 5(x+8)^4$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (4-x)^3$\n\\begin{sol} \n$\\ds -3(4-x)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (x^2+5)^3$\n\\begin{sol} \n$\\ds 6x(x^2+5)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (6-2x^2)^3$\n\\begin{sol} \n$\\ds -12x(6-2x^2)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (1-4x^3)^{-2}$\n\\begin{sol} \n$\\ds 24x^2(1-4x^3)^{-3}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds 5(x+1-1/x)$\n\\begin{sol} \n$\\ds 5+5/x^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds 4(2x^2-x+3)^{-2}$\n\\begin{sol} \n$\\ds -8(4x-1)(2x^2-x+3)^{-3}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds {1\\over 1+1/x}$\n\\begin{sol} \n$\\ds 1/(x+1)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds {-3\\over 4x^2-2x+1}$\n\\begin{sol} \n$\\ds 3(8x-2)/(4x^2-2x+1)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (x^2+1)(5-2x)/2$\n\\begin{sol} \n$\\ds -3x^2+5x-1$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (3x^2+1)(2x-4)^3$\n\\begin{sol} \n$\\ds 6x(2x-4)^3+6(3x^2+1)(2x-4)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{x+1\\over x-1}$\n\\begin{sol} \n$\\ds -2/(x-1)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{x^2-1\\over x^2+1}$\n\\begin{sol} \n$\\ds 4x/(x^2+1)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{(x-1)(x-2)\\over x-3}$\n\\begin{sol} \n$\\ds (x^2-6x+7)/(x-3)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{2x^{-1}-x^{-2}\\over 3x^{-1}-4x^{-2}}$\n\\begin{sol} \n$\\ds -5/(3x-4)^2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds 3(x^2+1)(2x^2-1)(2x+3)$\n\\begin{sol} \n$\\ds 60x^4+72x^3+18x^2+18x-6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds{1\\over (2x+1)(x-3)}$\n\\begin{sol} \n$\\ds (5-4x)/((2x+1)^2(x-3)^2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds ((2x+1)^{-1}+3)^{-1}$\n\\begin{sol} \n$\\ds 1/(2(2+3x)^2)$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  $\\ds (2x+1)^3(x^2+1)^2$\n\\begin{sol} \n$\\ds 56x^6+72x^5+110x^4+100x^3+60x^2+28x+6$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}   Find an equation for the tangent line to \n$\\ds f(x) = (x-2)^{1/3}/(x^3 + 4x - 1)^2$ at $x=1$.\n\\begin{sol} \n$y=23x/96-29/96$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find an equation for the tangent line to $\\ds y=9x^{-2}$ at $(3,1)$.\n\\begin{sol} \n$y=3-2x/3$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find an equation for the tangent line to $\\ds (x^2-4x+5)\\sqrt{25-x^2}$ \nat $(3,8)$.\n\\begin{sol} \n$y=13x/2-23/2$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find an equation for the tangent line to $\\ds \\ds{(x^2+x+1)\\over(1-x)}$ \nat $(2,-7)$.\n\\begin{sol} \n$y=2x-11$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}  Find an equation for the tangent line to \n$\\ds \\sqrt{(x^2+1)^2+\\sqrt{1+(x^2+1)^2}}$\nat $\\ds (1,\\sqrt{4+\\sqrt{5}})$.\n\\begin{sol} \n$\\ds y={20+2\\sqrt5\\over5\\sqrt{4+\\sqrt5}}\\,x+{3\\sqrt5\\over5\\sqrt{4+\\sqrt5}}$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nLet $y=f(x)$ and $x=g(t)$. If $g(1)=2$, $f(2)=3$, $g'(1)=4$ and $f'(2)=5$, find the derivative of $f\\circ g$ at 1.\n\\begin{sol}\n\t$(f(g(1)))'=20$\n\\end{sol}\n\\end{ex}\n\n\\begin{ex}\nExpress the derivative of $g(x)=x^2f(x^2)$ in terms of $f$ and the derivative of $f$.\n\\begin{sol}\n\t$g'(x)=2x(f(x^2)+x^2f'(x^2))$\n\\end{sol}\n\\end{ex}\n\n\\end{enumialphparenastyle}", "meta": {"hexsha": "d8be92840598cb803d9e30e8003690b3a923c5e6", "size": 10879, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-6-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": "4-derivatives/4-6-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": "4-derivatives/4-6-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": 25.7186761229, "max_line_length": 203, "alphanum_fraction": 0.601709716, "num_tokens": 4947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8740772302445241, "lm_q1q2_score": 0.7546709409173384}}
{"text": "\\subsection{Compact spaces}\\label{subsec:compact_spaces}\n\n\\begin{definition}\\label{def:centered_family}\\mcite[123]{Engelking1989}\n  The nonempty family \\( \\mscrF \\) of subsets of the topological space \\( X \\) is said to be a \\term{centered family of sets} or to have the \\term{finite intersection property} if the intersection \\( F_1 \\cap \\cdots \\cap F_n \\) of any finite collection of sets is nonempty.\n\\end{definition}\n\n\\begin{definition}\\label{def:compact_space}\\mcite[123]{Engelking1989}\n  The space \\( X \\) is called \\term{compact} if any of the following equivalent finiteness conditions hold:\n  \\begin{thmenum}\n    \\thmitem{def:compact_space/finite_subcover} Every open cover of \\( X \\) has a finite subcover.\n    \\thmitem{def:compact_space/centered_family} Every centered \\hyperref[def:centered_family]{family} \\( \\mscrF \\) of closed subsets of \\( X \\) has a nonempty intersection.\n    \\thmitem{def:compact_space/convergent_nets} Every \\hyperref[def:topological_net]{net} has a cluster point or, \\hyperref[thm:def:net_convergence/properties/cluster_point_iff_subnet_limit_point]{equivalently}, a \\hyperref[def:net_convergence]{convergent} subnet. This property is also called \\enquote{generalized sequential compactness} or, when restricted to sequences instead of general nets, simply \\enquote{sequential compactness}.\n  \\end{thmenum}\n\\end{definition}\n\\begin{proof}\n  \\ImplicationSubProof{def:compact_space/finite_subcover}{def:compact_space/centered_family} Assume that every open cover of \\( X \\) has a finite subcover. Let \\( \\mscrF \\) be a centered family of closed subsets of \\( X \\). Aiming at a contradiction, suppose that \\( \\bigcap \\mscrF = \\varnothing \\). Then\n  \\begin{equation*}\n    X\n    =\n    X \\setminus \\bigcap \\mscrF\n    =\n    \\bigcup_{F \\in F} (X \\setminus F),\n  \\end{equation*}\n  which has a finite subcover indexed by, say, \\( \\mscrF' \\subseteq F \\). But \\( \\mscrF \\) is a centered family and \\( \\bigcap \\mscrF' \\) is nonempty, hence\n  \\begin{equation*}\n    X\n    =\n    \\bigcup_{F \\in F'} (X \\setminus F)\n    =\n    X \\setminus \\bigcap \\mscrF'\n    \\neq\n    X.\n  \\end{equation*}\n\n  The obtained contradiction shows that \\( \\bigcap \\mscrF \\) is nonempty.\n\n  \\ImplicationSubProof{def:compact_space/centered_family}{def:compact_space/finite_subcover} Assume that every centered family of closed sets has a nonempty intersection. Let \\( \\{ U_k \\}_{k \\in \\mscrK} \\) be an open cover of \\( X \\). By putting \\( F_k \\coloneqq U_k \\) for all \\( k \\in \\mscrK \\), we obtain a family \\( \\{ F_k \\}_{k \\in \\mscrK} \\) of closed sets with an empty intersection. Therefore, it is not a centered family. Then there exists at least one finite subfamily \\( \\{ F_k \\}_{k \\in \\mscrK'} \\) with an empty intersection. The complement of this subfamily is then a finite cover of \\( X \\), which proves our statement.\n\n  \\ImplicationSubProof{def:compact_space/finite_subcover}{def:compact_space/convergent_nets} Assume that every open cover of \\( X \\) has a finite subcover. Fix a net \\( \\{ x_k \\}_{k \\in \\mscrK} \\subseteq X \\).\n\n  Aiming at a contradiction, suppose that the net has no cluster points. For any point \\( x \\in X \\) and any neighborhood \\( U_x \\) of \\( x \\), the net is not frequently in \\( U_x \\). Obviously \\( \\{ U_x \\}_{x \\in X} \\) is an infinite open cover of \\( X \\). Then it has a finite subcover indexed by, say, \\( X' \\subseteq X \\).\n\n  Therefore, every element of the net \\( \\{ x_k \\}_{k \\in \\mscrK} \\) if contained in one of the finitely many neighborhoods \\( \\{ U_x \\}_{x \\in X'} \\) and the net itself is frequently in at least one of the neighborhoods.\n\n  Thus, one of the finitely many points in \\( X' \\) is a cluster point of \\( \\{ x_k \\}_{k \\in \\mscrK} \\).\n\n  \\ImplicationSubProof{def:compact_space/convergent_nets}{def:compact_space/centered_family}\\mcite[thm. 3.1.23]{Engelking1989} Assume that every net has a cluster point. Let \\( \\{ F_k \\}_{k \\in \\mscrK} \\) be a central family of closed sets.\n\n  Denote by \\( \\mathcal C \\) the family of all finite subsets of \\( \\mscrK \\). For each \\( C \\in \\mathcal C \\), the set \\( \\bigcap_{c \\in C} F_c \\) is a finite intersection of members of a central family and is hence nonempty. Choose an element \\( x_C \\in \\bigcap_{c \\in C} F_c \\) for each \\( C \\in \\mathcal C \\).\n\n  If we order \\( \\mathcal C \\) by reverse inclusion, that is, if \\( C \\leq C' \\iff \\bigcap_{c \\in C'} F_c \\subseteq \\bigcap_{c \\in C} F_c \\), then the family \\( \\{ x_C \\}_{C \\in \\mathcal C} \\) becomes a net. Our assumption is that it has a cluster point, say \\( x_0 \\).\n\n  It remains to show that \\( x_0 \\) belongs to the intersection of the centered family \\( \\{ F_k \\}_{k \\in \\mscrK} \\) itself. Fix an element \\( F_0 \\) of this family and denote by \\( C_0 \\) the singleton set \\( \\{ k_0 \\} \\in \\mathcal C \\). Because \\( x_0 \\) is a cluster point, for every neighborhood \\( U \\) of \\( x_0 \\), there exists an index \\( C \\in \\mathcal C \\) such that \\( C \\geq C_0 \\) and \\( x_C \\in U \\). Then \\( x_C \\in \\bigcap_{c \\in C} F_c \\subseteq \\bigcap_{c \\in C_0} F_c = F_0 \\).\n\n  Therefore, \\( F_0 \\cap U \\neq \\varnothing \\) for all neighborhoods \\( U \\) of \\( x_0 \\). By \\fullref{thm:def:topological_closure_operator/properties/neighborhood_intersection}, \\( x_0 \\in F_0 \\). Since \\( F_0 \\) was an arbitrary set from the centered family \\( \\{ F_k \\}_{k \\in \\mscrK} \\), we conclude that the intersection of the family is not empty. This proves the theorem.\n\\end{proof}\n\n\\begin{remark}\\label{rem:precompact_set}\n  If the closure of \\( A \\) is compact, we call \\( A \\) \\term{relatively compact} or \\term{precompact} (although the term \\enquote{precompact} is also used for totally bounded sets, see \\fullref{def:totally_bounded_set}).\n\\end{remark}\n\n\\begin{proposition}\\label{thm:def:compact_space/properties}\n  \\hyperref[def:compact_space]{Compact spaces} have the following basic properties:\n  \\begin{thmenum}\n    \\thmitem{thm:def:compact_space/properties/closed} If \\( X \\) is any topological space and \\( A \\subseteq X \\) is a compact subspace, then \\( A \\) is closed in \\( X \\).\n    \\thmitem{thm:def:compact_space/properties/closed_subspace} A closed subspace of a compact space is compact.\n  \\end{thmenum}\n\\end{proposition}\n\\begin{proof}\n  \\SubProofOf{thm:def:compact_space/properties/closed} If \\( A \\) is compact, by \\fullref{def:compact_space/convergent_nets} every net in \\( A \\) has a cluster point in \\( A \\). By \\fullref{thm:def:derived_set/properties/closed_iff_contains_all_cluster_points}, \\( A \\) is closed in \\( X \\).\n\n  \\SubProofOf{thm:def:compact_space/properties/closed_subspace} Let \\( X \\) be \\hyperref[def:compact_space]{compact} and let \\( X' \\subseteq X \\) be a closed subspace.\n\n  Fix an open cover \\( \\{ U_k \\}_{k \\in \\mscrK} \\) of \\( X' \\). By definition of the subspace \\hyperref[def:topological_subspace]{topology} for each \\( U_k \\) there exists a set \\( V_k \\) that is open in \\( X \\) and \\( U_k = V_k \\cap X' \\). Since \\( X' \\) is closed, \\( X \\setminus X' \\) is open and hence the family \\( \\{ V_k \\}_{k \\in \\mscrK} \\) together with \\( X \\setminus X' \\) is an open cover of the space \\( X \\).\n\n  By \\fullref{def:compact_space/finite_subcover}, there exists a finite subcover \\( \\{ V_k \\}_{k \\in \\mscrK'} \\) that, along with \\( X \\setminus X' \\), still covers \\( X' \\). Therefore, \\( X' \\) is also compact.\n\\end{proof}\n\n\\begin{theorem}[Tychonoff's product theorem]\\label{thm:tychonoffs_product_theorem}\\mcite[thm. 3.2.4]{Engelking1989}\n  Let \\( { (X_k, \\mscrT_k) }_{k \\in \\mscrK} \\) be a family of topological spaces. Their \\hyperref[def:topological_product]{product} \\( (\\prod_{k \\in \\mscrK} X_k, \\prod_{k \\in \\mscrK} \\mscrT_k) \\) is \\hyperref[def:compact_space]{compact} if and only if \\( (X_k, \\mscrT_k) \\) is compact for every \\( k \\in \\mscrK \\).\n\n  In \\hyperref[def:zfc]{\\logic{ZF}} this theorem is equivalent to the \\hyperref[def:zfc/choice]{axiom of choice} --- see \\fullref{thm:axiom_of_choice_equivalences/tychonoff}.\n\\end{theorem}\n\n\\begin{theorem}[Weierstrass' extreme value theorem]\\label{thm:weierstrass_extreme_value_theorem}\\mcite[cor. 3.2.9]{Engelking1989}\n  Let \\( X \\) be a compact topological space and let \\( f: X \\to \\BbbR \\) be a continuous function into the \\hyperref[def:set_of_real_numbers]{real numbers}.\n\n  Then \\( f \\) is \\hyperref[def:metric_space/bounded_function]{bounded} and there exist \\( m, M \\in X \\) such that\n  \\begin{balign*}\n    f(m) = \\min_{x \\in X} f(x)\n     &  &\n    f(M) = \\max_{x \\in X} f(x).\n  \\end{balign*}\n\\end{theorem}\n\n\\begin{definition}\\label{def:locally_compact_space}\\mcite[148]{Engelking1989}\n  A topological space is called \\term{locally compact} if every point has a relatively compact neighborhood.\n\\end{definition}\n", "meta": {"hexsha": "58ce9249f7b5e48235e8f477ce5ece1dcb2b933f", "size": 8639, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/compact_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/compact_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/compact_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": 87.2626262626, "max_line_length": 634, "alphanum_fraction": 0.6977659451, "num_tokens": 2736, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382129861583, "lm_q2_score": 0.8757869981319863, "lm_q1q2_score": 0.7545239653271435}}
{"text": "\\section{Principal Component Analysis(PCA)}\n\tSometimes, the dimension of input data is very large, we need to reduce the dimension before analyzing it. The \\textbf{Principal Component Analysis} is a popular method of dimensional reduction.\n\t\n\tSuppose $\\mathbf x_1,...,\\mathbf x_n\\in\\mathbb R^d$ are the input data ($d\\gg 1$), and satisfy $\\sum_{i=1}^{n}\\mathbf x_i=\\mathbf 0$. Write $\\mathbf X = (\\mathbf x_1,...,\\mathbf x_n)$. We want to find a subspace $\\mathbb F$ (dim$\\mathbb F$ = k) of $\\mathbb{R}^d$ such that each projections of $\\mathbf x_i$ in $\\mathbb F$ is as close as possible to $\\mathbf x_i$. The effect of PCA on MNist Dataset is showed in Figure \\ref{fig:mnistpca}.\n\t\n\t\\begin{figure}[h]\n\t\t\\centering\n\t\t\\includegraphics[width=0.7\\linewidth]{MNistPCA}\n\t\t\\caption{The effect of PCA on MNist Dataset, where $\\dim \\mathbb F=3$}\n\t\t\\label{fig:mnistpca}\n\t\\end{figure}\n\n\\subsection{The Case of k=1: The First Component}\n\n\n\tIn the 1-d case, the subspace $\\mathbb F$ is a line which goes through the original point in $\\mathbb R^d$, let's write the direction vector of $\\mathbb F$ as $\\mathbf w$, where $\\|\\mathbf w\\|_2=1$. Then $\\mathbb F=\\text{span}\\{\\mathbf w\\}$ $\\sum_{i=1}^N x_i=0$. The projections of $\\mathbf x_1,...,\\mathbf x_n$ in $\\mathbb F$ is $\\mathbf y_1,...,\\mathbf y_n$, i.e.\n\t\\begin{align}\n\ty_i&=\\alpha_i \\mathbf w \\\\\\notag\n\t(y_i,\\mathbf w)&=(x_i ,\\mathbf w) \\\\\\notag\n\t\\alpha_i &=(x_i ,\\mathbf w)=\\mathbf w^T\\mathbf x_i \\\\\\notag\n\t\\end{align}\n\n\t $$\\mathbf y_i=(\\mathbf w^T\\mathbf x_i)\\mathbf w=\\mathbf w \\mathbf w^T\\mathbf x_i.$$\n\t  So we can easily get \n\t$$\\sum_{i=1}^{n}\\mathbf y_i=\\sum_{i=1}^{n}(\\mathbf w^T\\mathbf x_i)\\mathbf w=\\sum_{i=1}^{n}\\mathbf w^T(\\sum_{i=1}^{n}\\mathbf x_i)\\mathbf w=\\bm 0.$$\n\n\\begin{itemize}\n\\item Maximize the Variance (from the point of statistical learning)\t\n\n\tBecause the more point $\\mathbf y_1,...,\\mathbf y_n$ is decentralized, the easily we classify them. And we can use the variance to measure the degree of decentralization of these points. So our goal is to find the line, maximizes the variance of  $\\mathbf y_1,...,\\mathbf y_n$, i.e.\n\n\t\\begin{align*}\n\t\\max_{\\|\\mathbf w\\|^2_2=1}f(\\textbf w)\n\t&=Var(\\textbf y) = \\sum_i \\mathbf ||\\mathbf y_i-\\dfrac{1}{n}\\sum_{i=1}^{n}\\mathbf y_i||_2^2\\\\\n\t&= \\sum_i \\mathbf ||\\mathbf y_i-\\mathbf 0||_2^2= \\sum_i(\\textbf w^T \\textbf x_i)^2 \\hspace{1cm} (\\text{use} \\|\\mathbf w\\|_2=1)\n\t\\end{align*}\n\n\\item Minimize distance (form the point of autoencoder)\n\n\tIn other opinion, we want the distance between $\\mathbf x_i$ and $\\mathbf y_i$ can be as small as possible. So we can minimize \n\t\\begin{align*}\n\t\\min_{\\|\\mathbf w\\|^2_2=1}g(\\textbf w)\n\t=&\\sum_i \\mathbf ||\\mathbf y_i-\\mathbf x_i||_2^2\\\\\n\t=&\\sum_i \\mathbf( ||\\mathbf y_i||_2^2-2\\mathbf x_i^T\\mathbf y_i + ||\\mathbf x_i||_2^2)\\\\\n\t=&-\\sum_i(\\textbf w^T \\textbf x_i)^2+\\sum_i||\\mathbf x_i||_2^2\n\t\\end{align*}\n\tSo our goal is to find the optimal $\\mathbf w$ \n\t\\begin{align}\n\t\\mathbf w&=\\arg\\max_{||\\mathbf w||^2=1} f(\\mathbf w)=\\arg\\max_{||w||^2=1} \\sum_i(\\textbf w^T \\textbf x_i)^2 \\\\\\notag\n\t&= \\arg\\max_{||\\mathbf w||^2=1} \\sum_i\\textbf w^T \\textbf x_i \\textbf x_i^T  \\sum_i\\textbf w \n\t= \\arg\\max_{||\\mathbf w||^2=1} \\textbf w^T XX^T  \\sum_i\\textbf w   \\hspace{1cm}\n\t\\end{align}\n\n\\item Solve this problem:\n\n\tIts Lagrange multiplier: $$L(\\textbf w,\\mu )=\\sum_i(\\textbf w^T \\textbf x_i)^2-\\mu(\\textbf w^T \\textbf w-1),$$\n\tThen we get gradient of $L$:\n\t$$\\nabla_{\\mathbf w} L=2(\\sum_i \\textbf x_i \\textbf x_i^T)\\mathbf w-2\\mu  \\mathbf w=0,$$\n\t$$\\nabla_{\\mu} L=\\mathbf w^T \\mathbf w-1=0,$$\n\tand we can obtain $$S\\mathbf w=(\\sum_i \\textbf x_i \\textbf x_i^T)\\textbf w=\\mu \\mathbf w,$$\n\twhere $\\textbf S=\\sum_i \\textbf x_i \\textbf x_i^T=\\mathbf X\\mathbf X^T \\in \\mathbb{R}^{d\\times d}$.v Then $\\mu$ and $\\textbf w$ is the eigenvalue and corresponding eigenvector of $\\mathbf S$. It is easy to calculator that\n\t $$f(\\mathbf w)=\\mathbf w^T \\mathbf S \\mathbf w =\\mu \\mathbf w^T\\mathbf w =\\mu.$$\n\\end{itemize}\t \n\t So we can get a theorem:\n\t\\begin{theorem}\\label{PCA}  $\\mathbf w$ is the corresponding eigenvector of the max eigenvalue of $\\mathbf S=\\mathbf X\\mathbf X^T$.\n\t\\end{theorem}\n\t\n\tBesides, we call $\\mathbf x_i\\cdot \\mathbf w$ the first component of data $\\mathbf X$, and $\\mathbf w$ is the first component vector.\n\n\\subsection{The Case of High Dimensions: Further Components}\n\tSuppose $\\dim \\mathbb F = k$, and we have calculated the first component, then we reduce the first component: $\\hat{\\mathbf X}=\\mathbf X - \\mathbf w\\mathbf w^T\\mathbf X$. Now we use  $\\mathbf w_{2}^T\\mathbf x = \\bm 0$ to represent $\\mathbb F_2$ and do the same work as the 1-d case.\n\tBy \\textbf{theorem} \\ref{PCA} we can get $\\mathbf w_2$ is the corresponding eigenvector of the max eigenvalue of $\\hat{\\mathbf S}=\\hat{\\mathbf X}\\hat{\\mathbf X}^T$.\n\t\n\tLet $\\mathbf X = \\mathbf U \\bm \\Sigma \\mathbf V^T$ is the SVD decomposition of $\\mathbf X$, where $\\mathbf U=(\\mathbf u_1,...,\\mathbf u_n), \\bm \\Sigma = \\text{diag}(\\sigma_1,...,\\sigma_n)$, $\\mathbf  V=(\\mathbf v_1,...,\\mathbf v_n)$. We have\n\t$$\\mathbf S = \\mathbf U \\bm \\Sigma^2\\mathbf U^T,$$ so $\\mathbf w =\\mathbf u_1$, and\n\t\n\t \\begin{align*}\\hat{\\mathbf X} =& \\mathbf X - \\mathbf w\\mathbf w^T\\mathbf X\\\\\n\t =&\\mathbf U \\bm \\Sigma \\mathbf V^T-\\sigma_1 \\mathbf u_1\\mathbf v_1^T\\\\\n\t =&\\sum_{i=1}^n \\sigma_i \\mathbf u_i\\mathbf v_i^T-\\sigma_1 \\mathbf u_1\\mathbf v_1^T\\\\\n\t =&\\sum_{i=2}^n \\sigma_i \\mathbf u_i\\mathbf v_i^T\\\\\n\t =&(\\bm 0,\\mathbf u_2,...,\\mathbf u_n)\\text{diag} (0,\\sigma_2,...,\\sigma_n)(\\bm 0,\\mathbf v_2,...,\\mathbf v_n)^T\n\t \\end{align*}\n\t \n\t So the corresponding eigenvector of the max eigenvalue of $\\hat{\\mathbf S}$ is the corresponding eigenvector of the second big eigenvalue of $\\mathbf S$. If we generalize this conclusion, we can get the theorem:\n\t\\begin{theorem} \n\t \tThe $i$-th component vector $\\mathbf w_i$ is the corresponding eigenvector of the $i$-th big eigenvalue of $\\mathbf S=\\mathbf X\\mathbf X^T$, i.e. the $i$-th big left singular value of $\\mathbf S=\\mathbf X$.\n\t\\end{theorem}\n\t\\begin{remark}\n\tSuppose the eigenvalues are listed in a descending order as $$\\mu_1\\geq \\mu_2\\geq ...\\geq...$$ Take $\\sigma_i=\\sqrt{\\mu_i}$, then $\\sigma$s are called the corresponding  singular values.\n\t\\end{remark}\n\n\n\\subsection{A General Proof}\n\tSuppose $\\text{dim}\\mathbb F = k$,  $\\mathbf{W}=(\\mathbf{w}_1,...,\\mathbf{w}_k)$, and $\\mathbb F=\\text{span}\\{\\mathbf{w}_1,...,\\mathbf{w}_k\\}$ ($\\mathbf{w}_j^T\\mathbf{w}_j=1,\\mathbf{w}_i^T\\mathbf{w}_j=0, i\\neq j$), then the projection of $\\mathbf x_i$ is\n\t\\begin{equation}\n\t\t\\mathbf{y}_i=\\sum_{j=1}^{k}(\\mathbf{w}_j^T \\mathbf{x}_i)\\mathbf{w}_j=\\mathbf W\\mathbf W^T\\mathbf x_i=\\mathbf W \\tilde{\\mathbf x}_i.\n\t\\end{equation}\n\t\n\tBy the previous discussion, our goal is also to maximize the variance of $\\mathbf y_i$, $i=1,...,n$.\n\t\n\tBecause\n\t\\begin{align*}\n\tf(\\textbf W)\n\t&=Var(\\textbf y) = \\sum_i \\mathbf ||\\mathbf y_i-\\dfrac{1}{n}\\sum_{i=1}^{n}\\mathbf y_i||_2^2\\\\\n\t&= \\sum_i \\mathbf ||\\mathbf y_i-\\mathbf 0||_2^2\\\\\n\t&= \\sum_i\\sum_j^k(\\textbf w_j^T \\textbf x_i)^2 \\hspace{1cm} (\\text{use} \\|\\mathbf w_j\\|_2=1)\\\\\n\t&=\\sum_j^k\\textbf w_j^T \\mathbf{S} \\textbf w_j, \\\\\n\t\\end{align*}\n\tsince $w_i^T w_j=\\delta_{ij}$, we get a optimal problem:\n\t\n\t\\begin{equation}\n\t\\max_{\\mathbf W^T\\mathbf W=\\mathbf I}f(\\mathbf W)=\\sum_j^k\\textbf w_j^T \\mathbf{S} \\textbf w_j= \\text{tr}(\\mathbf W^T\\mathbf S\\mathbf W)\n\t\\end{equation}\n\tThe Lagrange multiplier of $f(\\mathbf W)$ is: \n\t\\begin{equation}\n\tL(\\textbf W,\\bm \\mu)\n\t=\\sum_j\\textbf w_j^T \\mathbf{S} \\textbf w_j-\\sum_j\\mu_{jj}(\\textbf w_j^T \\textbf w_j-1)-2\\sum_{j< s} \\mu_{js}(\\textbf w_j^T \\textbf w_s-0)\n\t\\end{equation}\n\tThe derivative of $L$ is\n\t\\begin{equation}\n\t0=\\dfrac{\\partial L}{\\partial \\mathbf w_j}=2(\\mathbf{S}\\mathbf w_j-\\sum_s \\mu_{js}  \\mathbf w_s), \\hspace{1cm} \\mu_{js}=\\mu_{sj}\n\t\\end{equation}\n\tthe we have\n\t\\begin{equation}\n\t\\mathbf{S}\\mathbf w_j=\\sum_s \\mu_{js}  \\mathbf w_s,\\hspace{1cm} j=1,2,...,k.\n\t\\end{equation}\n\t\n\tSo the subspace $\\mathbb F=\\text{span}\\{\\mathbf w_1,...,\\mathbf w_k \\} $ is the invariant subspace of $\\mathbf S$, then we can obtain that there are $k$ unit eigenvectors $\\mathbf u_1,...,\\mathbf u_k$ of $\\mathbf S$ s.t. $\\text{span}\\{\\mathbf u_1,...,\\mathbf u_k \\}=\\mathbb F$.\n\tLet $\\lambda_i$ is the eigenvalue of $\\mathbf u_i$ and $\\mathbf U=(\\mathbf u_1,...,\\mathbf u_k)$.\n\t\n\tAssume $\\mathbf w_j=\\sum_s a_{js} \\mathbf u_s$ and $\\mathbf A=(a_{js})$, then $\\mathbf W=\\mathbf U\\mathbf A$. By $\\mathbf W^T\\mathbf W=\\mathbf I$ and $\\mathbf U^T\\mathbf U=\\mathbf I$, we can obtain $$\\mathbf A^T\\mathbf A=\\mathbf A^T\\mathbf U^T\\mathbf U\\mathbf A=\\mathbf W^T\\mathbf W=\\mathbf I,$$ so $\\mathbf A$ is unit orthogonal matrix.\n\t\n\t\\begin{align}\n\tf(\\mathbf W)&=\\sum_j (\\sum_s a_{js}\\mathbf u_s)\\mathbf S (\\sum_t a_{jt}\\mathbf u_t)\\\\\n\t &=\\sum_j (\\sum_s a_{js}\\mathbf u_s) (\\sum_t a_{jt}\\lambda_t\\mathbf u_t)\\\\\n\t &=\\sum_j \\sum_s \\lambda_s a_{js}^2\\\\\n\t &=\\sum_s \\lambda_s (\\sum_j a_{js}^2 ).\\\\\n\t &=\\sum_s^k \\lambda_s\n\t\\end{align}\n\t\n\tSo $\\lambda_s$ is the largest $k$ eigenvalues of $\\mathbf S$(Suppose $\\lambda_1 \\geq \\lambda_2 \\geq ...\\geq \\lambda_k \\geq...\\geq \\lambda_d$ are the eigenvalues of S).\n\t\nWe can also get the optimal $\\mathbf W$ without using Lagrangian multiplier. \n\n\t\\begin{equation}\n\t\\mathbf W=\\arg\\min_{\\mathbf W^T\\mathbf W=\\mathbf I}\\sum_i^N ||y_i-x_i||_2^2\n\t\\end{equation}\n\t\n\t\\begin{align}\n\t||y_i-x_i||_2^2&=||\\mathbf W\\mathbf W^T x_i-x_i||_2^2\\\\\\notag\n\t&=(\\mathbf W\\mathbf W^T x_i, \\mathbf W\\mathbf W^T x_i)-2(\\mathbf W\\mathbf W^T x_i,x_i)+||x_i||_2^2  \\\\\\notag\n\t&=||x_i||_2^2-(\\mathbf W\\mathbf W^T x_i,x_i)  \\\\\\notag\n\t&=||x_i||_2^2-x_i^T\\mathbf W\\mathbf W^T x_i  \n\t\\end{align}\n\t\n\t\\begin{align}\n\t\\sum_i^N x_i^T\\mathbf W\\mathbf W^T x_i &=  \\sum_i^N \\sum_j^k (\\mathbf w_j^T x_i)^2 \\\\\\notag\n\t&=  \\sum_i^N \\sum_j^k \\mathbf w_j^T x_i x_i^T \\mathbf w_j\\\\\\notag\n\t&=  \\sum_j^k \\mathbf w_j^T XX^T \\mathbf w_j\n\t\\end{align}\n\t\n\t\\begin{equation}\n\t\\mathbf W=\\arg\\max_{\\mathbf W^T\\mathbf W=\\mathbf I}f(\\mathbf W)=\\arg\\max_{\\mathbf W^T\\mathbf W=\\mathbf I}\\sum_j^k \\mathbf w_j^T XX^T \\mathbf w_j\n\t\\end{equation}\n\t\nDenote the singular value decomposition of $XX^T$ as $XX^T=U\\Sigma U^T$. Suppose $\\mathbf w_i=U \\alpha_i$, where $|\\alpha_i|=1$, then \n\t\\begin{align}\n\tf(\\mathbf W)&=\\sum_j^k \\mathbf w_j^T XX^T \\mathbf w_j\\\\\\notag\n\t&=\\sum_j^k \\mathbf w_j^T U\\Sigma U^T \\mathbf w_j\\\\\\notag\n    &=\\sum_j^k \\mathbf \\alpha_j^T \\Sigma \\alpha_j\\\\\\notag\n    &=\\sum_j \\sum_i \\mathbf \\alpha_{j,i}^2 \\sigma_i^2 \\\\\\notag\n    &=\\sum_i \\sigma_i^2 \\sum_j \\mathbf \\alpha_{j,i}^2  \\\\\\notag\n    &\\leq\\sum_i^k \\sigma_i^2,\n\t\\end{align}\t\n\twhere the equality holds only when $\\alpha_{j,i}=\\delta_{i,j}$. In this case, $\\mathbf W$ is the matrix composed with the first $k$ columns of $U$. \n\t\n\tWe can get a theorem:\n\t\\begin{theorem}\\label{theorem:PCA}\n\t\tIf $\\text{dim}\\mathbb F = k$, then the optimal $\\mathbb F$ of PCA is $\\mathbb F= \\text{span}\\{\\mathbf u_1,...,\\mathbf u_k \\}$, where $\\mathbf u_i$ is the corresponding eigenvector of the $i$-th big eigenvalue of $\\mathbf S=\\mathbf X\\mathbf X^T$, i.e. the corresponding left singular of the $i$-th big value of $\\mathbf X$. \n\t\\end{theorem}\n\t\n\t\\subsection{The case of $\\sum_i^n x_i\\neq 0$}\n\tWhile $\\sum_i^n x_i\\neq 0$, and the $\\mathbb F$ is affine set of $\\mathbb R^d$, suppose $\\mathbf w_1,...\\mathbf w_k$ is a unit orthonormal base of $\\mathbb F$ and $\\mathbf x_0$ is a point in $\\mathbb F$ such that $\\mathbf W^T\\mathbf x_0 =\\mathbf 0$. Write $\\mathbf{W}=(\\mathbf{w}_1,...,\\mathbf{w}_k)$, obviously $\\mathbf W^T\\mathbf W=\\mathbf I$. The the projection of $\\mathbf x_i$ in $\\mathbb F$ is\n\t\\begin{equation}\n\t\t\\mathbf y_i=\\mathbf W(\\mathbf W^T\\mathbf x_i)+\\mathbf x_0\n\t\\end{equation}\n\t\n\t\\begin{align*}\n\t\tf(\\mathbf W,\\mathbf x_0)&=\\sum_i^n\\|\\mathbf y_i-\\mathbf x_i\\|_2^2\\\\\n\t\t&=\\sum_i^n\\|\\mathbf W(\\mathbf W^T\\mathbf x_i)+\\mathbf x_0-\\mathbf x_i\\|_2^2\\\\\n\t\t&=\\sum_i^n\\|(\\mathbf W\\mathbf W^T-\\mathbf I)\\mathbf x_i+\\mathbf x_0\\|_2^2\\\\\n\t\\end{align*}\n\t\n\t\\begin{align*}\n\t\\dfrac{\\partial f}{\\partial \\mathbf x_0}&=2\\sum_i^n((\\mathbf W\\mathbf W^T-\\mathbf I)\\mathbf x_i+\\mathbf x_0)\\\\\n\t&=2n((\\mathbf W\\mathbf W^T-\\mathbf I)\\bar{\\mathbf x}+\\mathbf x_0)\n\t\\end{align*}\n\twhere $\\tilde{\\mathbf x}=\\dfrac 1n\\sum_i^n \\mathbf x_i$.\n\t\n\tThus $\\mathbf x_0=(\\mathbf I-\\mathbf W\\mathbf W^T)\\bar{\\mathbf x}$, and $f$ can be write as \n\t\\begin{equation}\n\tf(\\mathbf W,\\mathbf x_0)\n\t=\\sum_i^n\\|(\\mathbf W\\mathbf W^T-\\mathbf I)(\\mathbf x_i-\\bar{\\mathbf x})\\|_2^2\n\t\\end{equation}\n\tIf we use $\\hat{\\mathbf x}_i=\\mathbf x_i -\\bar{\\mathbf x}$ to replace $\\mathbf x_i$ in the case of $\\sum_i^n x_i=0$, the next steps are the same as the case of $\\sum_i^n x_i= 0$. Then we can get a theorem:\n\t\\begin{theorem}\n\t\tIf $\\mathbb F$ is the affine set of $\\mathbb R^d$, and $\\text{dim}\\mathbb F = k$, then the optimal $\\mathbb F$ of PCA is $\\mathbb F= \\text{span}\\{\\tilde{\\mathbf u}_1,...,\\tilde{\\mathbf u}_k \\}+\\bar{\\mathbf x}$, where $\\tilde{\\mathbf u}_i$ is the corresponding eigenvector of the $i$-th big eigenvalue of $\\mathbf S=\\tilde{\\mathbf X}\\tilde{\\mathbf X}^T$, i.e. the corresponding left singular of the $i$-th big value of $\\tilde{\\mathbf X}$, where $\\tilde{\\mathbf X}=(\\mathbf x_1-\\bar{\\mathbf x},...,\\mathbf x_n-\\bar{\\mathbf x})$.\n\t\\end{theorem}\n\n\\section{Optimal pairing of encoding and decoding}\n\\subsection{Linear decoding}\nSuppose $\\mathbf x_i\\in \\mathbb R^d$ and we want to use a function to\ncompress them into $\\mathbb R^{d_c}$, we call this function encoder\n(restriction, compress) function $f:\\mathbb R^d\\rightarrow \\mathbb\nR^{d_c}$. Besides, after compression, we want to uncompress the data\nby a decoder (prolongation, uncompress) function and let the distance\nbetween the origin data and uncompressed data be as small as possible,\ni.e. minimize the loss function\n\\begin{equation}\n  \\label{encode-decode-loss}\n\tL=\\sum_i^n||g\\circ f(\\mathbf x_i)-\\mathbf x_i ||_2^2.  \n\\end{equation}\n\tIf we fix the decoder as a linear function, i.e.\n        \\begin{equation}\n          \\label{linear-encoding}\n\tg(\\mathbf y)=\\mathbf W\\mathbf y+\\mathbf b.          \n        \\end{equation}\n\tThen the loss function \n\t\\begin{align*}\n\tL&=\\sum_i^n||\\mathbf W f(\\mathbf x_i)+\\mathbf b-\\mathbf x_i ||_2^2\n\t\\end{align*}\n\tbecause \n\t\\begin{align*}\n\t&\\min_{\\mathbf W,\\mathbf b,f} \\sum_i^n||\\mathbf W f(\\mathbf x_i)+\\mathbf b-\\mathbf x_i ||_2^2\\\\\n\t&\\geq \\min_{\\mathbf W,\\mathbf b,f(\\mathbf x_i)} \\sum_i^n||\\mathbf W f(\\mathbf x_i)+\\mathbf b-\\mathbf x_i ||_2^2\\\\\n\t&=\\min_{\\mathbf W,\\mathbf b,\\bm\\beta_1,...,\\bm\\beta_n} \\sum_i^n||\\mathbf W \\bm \\beta_i+\\mathbf b-\\mathbf x_i ||_2^2\n\t\\end{align*}\n\t\n\tWrite $ I(\\mathbf W,\\mathbf b,\\bm\\beta_1,...,\\bm\\beta_n)=\\sum_i^n||\\mathbf W \\bm \\beta_i+\\mathbf b-\\mathbf x_i ||_2^2$, because of nonzero sum of $\\bm \\beta_i$ can be represented by $\\mathbf b$, we can suppose $\\sum_i^n \\bm \\beta_i = 0$. We calculate its derivative:\n\t\n\t\n\t\\begin{align*}\n\t\\dfrac{\\partial I}{\\partial \\mathbf b}=-2\\sum_i^n (\\mathbf W \\bm \\beta_i+\\mathbf b-\\mathbf x_i )=0 \\Rightarrow \\mathbf b = \\dfrac 1n \\sum_i^n \\mathbf x_i=\\bar {\\mathbf x}\\\\\n\t\\dfrac{\\partial I}{\\partial \\bm \\beta_i}=-2 (\\mathbf W \\bm \\beta_i+\\mathbf b-\\mathbf x_i )^T\\mathbf W=0\\Rightarrow \\bm \\beta_i =\\mathbf W^T(\\mathbf x_i -\\mathbf b)\n\t\\end{align*}\n\t\nThis means if $g$ is a linear function, the best $f$ is also linear function, and then the steps are same as PCA.\n\t\nIn summary, we have\n\\begin{theorem}\nGiven data $\\mathbf x_i\\in \\mathbb R^d$ for $i=1:n$ and any encoding\nfunction \n$f:\\mathbb R^d\\rightarrow \\mathbb R^{d_c}$, \nif the encoding function $g:\\mathbb R^{d_c}\\mapsto \\mathbb R^d$ is\nchosen to the linear as given \n\\eqref{linear-encoding}\nThen the best encoder $f$ should also be linear.  Furthermore\n\\begin{equation}\n  \\label{encoder-decoder}\nf(x)=W^T(x-b), g(y)=Wy+b\n\\end{equation}\nwith \n\\begin{equation}\n\\label{b}\n\\mathbf b = \\dfrac 1n \\sum_i^n \\mathbf x_i\n\\end{equation}\n``Optimal'' $W$ may be find by\n\\begin{equation}\n  \\label{eq:1}\n  \\min_W L\n=  \\min_W \\sum_{i=1}^n\\|g\\circ f(x_i)-x_i\\|^2 \n=  \\min_W \\sum_{i=1}^n\\|WW^T\\hat x_i-\\hat x_i\\|^2 \n\\end{equation}\nwhere $\\hat x_i=x_i-b$.\n \\end{theorem}\n\nIt follows that \n$$\nL_i=\\|WW^T\\hat x_i-\\hat x_i\\|^2 =\n\\hat x_i^TWW^TWW^T\\hat x_i-2\\hat x_i^TWW^T\\hat x_i\n+\\|\\hat x_i\\|^2 \n$$\n\\paragraph{Orthogonal case:} If $W^TW=I$, then \n$$\nL_i=-\\hat x_i^TWW^T\\hat x_i\n+\\|\\hat x_i\\|^2 \n$$\nIf we write\n$$\nW=(w_1,\\ldots,w_{d_c})\n$$\n\\begin{small}\n$$\n\\sum_{i=1}^n\\hat x_i^TWW^T\\hat x_i \n=\\sum_j\\sum_{i=1}^n\\hat x_i^Tw_jw_j^T\\hat x_i \n=\\sum_j\\sum_{i=1}^nw_j^T\\hat x_i \\hat x_i^Tw_j \n=\\sum_jw_j^T\\hat X \\hat X^Tw_j \n={\\rm trace}(W^T\\hat X \\hat X^TW)\n$$\n\\end{small}\nwhich leads to PCA:\n\\begin{equation}\n  \\label{PCA}\nW=\\arg\\max_{W^TW=I}  {\\rm trace}(W^T\\hat X \\hat X^TW)\n\\end{equation}\nThe solution is given by the eigenvectors corresponding the $d_c$\nlargest eigenvalues of $XX^T$.\t\n\n\\subsubsection{General case}\n\\begin{tiny}\n$$\n\\sum_ix_i^TWW^TWW^Tx_i=\\sum_{i, k,l}x_i^Tw_k w_k^T w_l w_l^Tx_i\n=\\sum_{i, k,l}w_k^T w_l w_l^Tx_ix_i^Tw_k \n=\\sum_{l}w_l^TXX^TWW^T w_l \n$$\n\\end{tiny}\n$$\nL=\\sum_{l}w_l^TXX^T(WW^T-2) w_l +\\|X\\|_F^2\n$$\n\\subsection{Nonlinear PCA}\n\t\n\tNow we have a linear  $\\psi(\\mathbf x)=\\mathbf W_1^T(\\mathbf x-\\bar{\\mathbf x})$ and a linear prolongation (uncompress, decoder) $\\phi(\\mathbf x)=\\mathbf W_2\\mathbf y+\\bar{\\mathbf x}$. The goal of PCA is to minimize the loss function\n\t$$L=\\|\\psi\\circ \\phi(\\mathbf X)-\\mathbf X \\|_F^2$$.\n\t\n\tFor nonlinear case, we use an entrywise activation $\\sigma(x)$ on $\\psi$ and $\\phi$,\n\t$$\n\tf=\\sigma\\circ \\psi, g=\\sigma\\circ\\phi\n\t$$\n\tIt becomes $$f(x)=\\sigma(W_1^T x +b), g(y)=\\sigma (W_2 y + b')$$\n\tThe goal of nonlinear PCA is to minimize \n\t$$L=\\|g\\circ f(\\mathbf X)-\\mathbf X \\|_F$$.\n\t\n\n\\section{A classical application of PCA}\nIn this section, we will introduce the application of PCA on face recognition. The Dataset of Labeled Faces in the Wild\\footnote{Learned-Miller, Erik, et al. \"Labeled faces in the wild: A survey.\" Advances in face detection and facial image analysis. Springer, Cham, 2016. 189-248.} is used. \nThere are  in total $N=13233$ face images for 5749 people  with $d=64\\times 64$ resolution, $X = [x_1, \\cdots, x_{N}]\\in \\mathbb{R}^{d\\times N}$.\nSome example pictures are shown below. \n\\begin{center}\n\\includegraphics[width=0.8\\textwidth]{1000Face} \n\\end{center}\n\n\n\\subsection{Task of face recognition}\nThe task of face recognition is to identify a new image $x$ of a face whether the person is in the dataset $X$ and classify who that is if the person is in $X$. \n\nA natural idea is to find $i$ such that $$||x-x_i||_2=\\min_{1\\le j\\le N} ||x-x_j||_2$$ or $$i=\\arg\\min_{1\\le j\\le N} ||x-x_j||_2.$$ But it doesn't work since different pictures of the same person can have a very large $\\ell^2$-distance (between pixels). The solution is projecting the data to a lower dimensional space. \nThen we can find some approximation of the data in a lower dimensional hyperplane for better classification.  To minimize the total distance between the original data and the uncompressed data, we can use PCA for application. \n\n\\subsection{PCA}\nWithout loss of generality, we assume $\\sum x_i=0$. Then we can apply Theorem \\ref{theorem:PCA} to find the best projection directions. \n\n\tWe use the same notation. Suppose  $\\text{dim}\\mathbb F = k$, then the optimal projection matrix is $\\mathbf{W}=(\\mathbf{w}_1,...,\\mathbf{w}_k)$, where $\\mathbf{w}_i$ is the corresponding eigenvector of the $i$-th big eigenvalue of $\\mathbf S=\\mathbf X\\mathbf X^T$, and $\\mathbb F=\\text{span}\\{\\mathbf{w}_1,...,\\mathbf{w}_k\\}$ ($\\mathbf{w}_j^T\\mathbf{w}_j=1,\\mathbf{w}_i^T\\mathbf{w}_j=0, i\\neq j$), then the uncompressed data of $\\mathbf x_i$ is\n\t\\begin{equation}\n\t\t\\mathbf{y}_i=\\sum_{j=1}^{k}(\\mathbf{w}_j^T \\mathbf{x}_i)\\mathbf{w}_j=\\mathbf W\\mathbf W^T\\mathbf x_i=\\mathbf W \\tilde{\\mathbf x}_i.\n\t\\end{equation}\n\nMoreover, we call the eigenvector of $\\mathbf S=\\mathbf X\\mathbf X^T$, $\\mathbf{w}_i$, as EigenFace.  We show the first 16 EigenFaces below. \n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.5\\textwidth]{15EigenFace} \n\\caption{Examples of EigenFaces}\n\\end{center}\n\\end{figure}\n\n\\subsection{Encoding and decoding}\nSimilarly, we can divide the uncompressed data of $\\mathbf x_i$ with two steps, encoding and decoding, where $\\tilde{\\mathbf x}_i=W^T\\mathbf x_i$ is the encoding and $\\mathbf{y}_i=\\mathbf W \\tilde{\\mathbf x}_i$ is the decoding part. In detail, the encoding part projects the data to a $k$-dimensional space and we get a lower dimensional coefficient vector $\\tilde{\\mathbf x}_i=W^T\\mathbf x_i$. Thus we can classify faces in this lower dimensional space. Then we can get the the uncompressed data with the decoding part by $\\mathbf{y}_i=\\mathbf W \\tilde{\\mathbf x}_i$.\n\nWe use the picture of one face data as an example. \nWe have an original image: $\\mathbf x\\in \\mathbb{R}^{d}$.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{1000Face-100ori-2} \n\\caption{Original image}\n\\end{center}\n\\end{figure}\n\\newpage\nAfter encoding, we get a lower dimensional coefficient vector $\\tilde{\\mathbf x}=W^T\\mathbf x$.\nThen after decoding, we get the the uncompressed data\n$\\mathbf{y}=\\mathbf W \\tilde{\\mathbf x} \\in \\mathbb{R}^{d}$.\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{1000Face-100-2} \n\\caption{Uncompressed image}\n\\end{center}\n\\end{figure}\n\n\\subsection{Classification accuracy}\nIn the task of face recognition in the dataset of Labeled Faces in the Wild,\nPCA extracts features with eigenvectors and achieves 85\\% test accuracy in average. \nIf we use CNN on this dataset, CNN extracts features with convolutional filters and can achieve 99.85\\% test accuracy in average. \n\n\n\n", "meta": {"hexsha": "7a26e39816176d8b2e0f169b646b0390d5d45ea7", "size": 21482, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/PCA.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/PCA.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/PCA.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": 54.5228426396, "max_line_length": 568, "alphanum_fraction": 0.6791732613, "num_tokens": 8327, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382236515259, "lm_q2_score": 0.8757869803008764, "lm_q1q2_score": 0.7545239593055509}}
{"text": "\\subsection{Linear finite element cannot be recovered by ${\\rm DNN}_1$ for $d\\ge2$}\nIn view of  Theorem~\\ref{thm:1dLFEMDNN} and the fact that ${\\rm{DNN}_J}\n\\subseteq {\\rm{DNN}_{J+1}} $, it is natural to ask that how many\nlayers are needed at least to recover all linear finite element\nfunctions in $\\mathbb{R}^d$ for $d\\ge2$.  In this section, we will show that \n\\begin{equation}\\label{key}\nJ_d \\ge 2, \\quad \\text{if} \\quad d\\ge 2,\n\\end{equation}\nwhere $J_d$ is the minimal $J$ such that all linear finite element\nfunctions in $\\mathbb R^d$ can be recovered by ${\\rm DNN}_J$.\n\nIn particular, we will show the following theorem~\\cite{he2020relu}.\n\\begin{theorem}\\label{lowerbound}\n\tIf $\\Omega\\subset \\mathbb R^d$ is either \n\ta bounded domain or $\\Omega=\\mathbb{R}^d$,  \n\t${\\rm DNN}_1$ can not be used to recover all linear finite element\n\tfunctions on $\\Omega$. \n\\end{theorem}\n\\begin{proof}\n\tWe prove it by contradiction. Let us assume that for any continuous\n\tpiecewise linear function $f: \\Omega \\to \\mathbb{R} $, we can find\n\tfinite $N \\in \\mathbb{N}$, $w_i \\in \\mathbb{R}^{1,d}$ as row vector\n\tand $\\alpha_i, b_i, \\beta \\in \\mathbb{R}$ such that\n\t$$\n\tf =  \\sum_{i=1}^N \\alpha_i {\\rm ReLU}(w_i\\cdot  x +b_i) + \\beta,\n\t$$\n\twith $f_i = \\alpha_i {\\rm ReLU}(w_i\\cdot  x +b_i)$, $\\alpha_i \\neq 0$ and $w_i\n\t\\neq 0$.  Consider the finite element functions, if this one hidden\n\tlayer ReLU DNN can recover any basis function of FEM, then it can\n\trecover the finite element space.  Thus let us assume $f$ is a locally\n\tsupported basis function for FEM.\n\tFurthermore, if $\\Omega$ is a bounded domain, we assume that \n\t\\begin{equation}\\label{distcondi}\n\td({\\rm supp}(f), \\partial \\Omega) > 0,\n\t\\end{equation}with \n\t$$\n\td(A, B) = \\inf_{x\\in A, y\\in B} \\|x-y\\|,\n\t$$ \n\tas the distance of two closed sets. \n\t\n\tA more important observation is that $\\nabla f: \\Omega \\to\n\t\\mathbb{R}^d$ is a piecewise constant vector function. The key\n\tpoint is to consider the discontinuous points for \n\t$$g := \\nabla\n\tf = \\sum_{i=1}^N \\nabla f_i.$$\n\tFor more general case, we can define the set of discontinuous points of a function by\n\t$$\n\tD_{g} := \\{x \\in \\Omega~|~ x ~ \\text{is a discontinuous point of} ~ g\\}.\n\t$$\n\tBecause of the property that \n\t\\begin{equation}\\label{eq:disfun}\n\tD_{f+g} \\supseteq D_{f} \\cup D_{g} \\backslash (D_{f} \\cap D_{g}),\n\t\\end{equation}\n\twe have\n\t\\begin{equation}\\label{eq:dis_fn}\n\tD_{\\sum_{i=1}^N g_i} \\supseteq \\bigcup_{i=1}^N D_{g_i} \\backslash \\bigcup_{i\\neq j}\\left( D_{g_i}\\cap D_{g_j} \\right).\n\t\\end{equation}\n\tNote that\n\t\\begin{equation}\\label{eq:def_gi}\n\tg_i = \\nabla f_i(x) =  \\nabla \\left( \\alpha_i {\\rm ReLU}(w_i\\cdot   x +b_i)  \\right) =\\left(\\alpha_iH(w_i \\cdot  x +b_i)\\right)w_i \\in \\mathbb{R}^d,\n\t\\end{equation}\n\tfor $i=1:N$ with $H$ be the Heaviside function defined as: \n\t$$\n\tH(x) = \\begin{cases}\n\t0 &\\text{if} ~ x \\le 0, \\\\\n\t1 &\\text{if} ~ x > 0.\n\t\\end{cases}\n\t$$ \n\tThis means that \n\t\\begin{equation}\\label{eq: D_gi}\n\tD_{g_i} = \\{ x ~|~ w_i\\cdot   x + b_i = 0\\}\n\t\\end{equation}\n\tis a $d-1$ dimensional affine space in $\\mathbb{R}^d$.  \n\t\n\t\n\tWithout loss of generality, we can assume that \n\t\\begin{equation}\\label{eq:assumD_gi}\n\tD_{g_i} \\neq D_{g_j}.\n\t\\end{equation}\n\tWhen the other case occurs, i.e. $D_{g_{\\ell_1}} = D_{g_{\\ell_2}} = \\cdots= D_{g_{\\ell_k}}$, by the definition of $g_i$ in \\eqref{eq:def_gi} and $D_{g_i}$ in \\eqref{eq: D_gi} , \n\tthis happens if and only if there is a row vector $(w, b)$ such that\n\t\\begin{equation}\\label{eq:Dfcondition}\n\tc_{\\ell_i}\\begin{pmatrix}\n\tw &\n\tb\n\t\\end{pmatrix} =  \n\t\\begin{pmatrix}\n\tw_{\\ell_i} &\n\tb_{\\ell_i}\n\t\\end{pmatrix},\n\t\\end{equation}\n\twith some $c_{\\ell_i} \\neq 0$ for $i = 1:k$.  We combine those $g_{\\ell_i}$ as\n\t\\begin{equation*}\n\t\\begin{aligned}\\label{mergeH}\n\t%\t\\begin{split}\n\t\\tilde g_{\\ell} &= \\sum_{i=1}^k g_{\\ell_i} = \\sum_{i=1}^k \\alpha_{\\ell_i} H(w_{\\ell_i} \\cdot  x + b_{\\ell_i}) w_{\\ell_i}, \\\\\n\t&= \\sum_{i=1}^k \\left( c_{\\ell_i}\\alpha_{\\ell_i} H\\left(c_{\\ell_i}(w\\cdot   x + b)\\right) \\right) w, \\\\\n\t&=\\begin{cases}\n\t\\displaystyle \\left(\\sum_{i=1}^k  c_{\\ell_i}\\alpha_{\\ell_i} H(c_{\\ell_i}) \\right) w  \\quad &\\text{if} \\quad w x + b > 0,\\\\\n\t\\displaystyle \\left(\\sum_{i=1}^k  c_{\\ell_i}\\alpha_{\\ell_i} H(-c_{\\ell_i}) \\right) w  \\quad &\\text{if} \\quad w x + b \\le 0.\\\\\n\t\\end{cases}\n\t%\t\\end{split}\n\t\\end{aligned}\n\t\\end{equation*}\t\n\tThus, if \n\t$$\n\t\\left(\\sum_{i=1}^k  c_{\\ell_i}\\alpha_{\\ell_i} H(c_{\\ell_i}) \\right)  = \\left(\\sum_{i=1}^k  c_{\\ell_i}\\alpha_{\\ell_i} H(-c_{\\ell_i}) \\right),\n\t$$\n\t$\\tilde g_\\ell$ is a constant vector function, that is to say $D_{\\sum_{i=1}^k g_{\\ell_i}} = D_{\\tilde g_\\ell} = \\emptyset$. \n\tOtherwise, $\\tilde g_\\ell$ is a piecewise constant vector function with the property that \n\t$$\n\tD_{\\sum_{i=1}^k g_{\\ell_i}} = D_{\\tilde g_\\ell} = D_{g_{\\ell_i}} = \\{ x ~|~ w\\cdot  x + b = 0\\}.\n\t$$\n\tThis means that we can use condition \\eqref{eq:Dfcondition} as an equivalence relation and split $\\{g_i\\}_{i=1}^N$ into some groups, and we can combine those $g_{\\ell_i}$ in each group as what we do above. After that, we have\n\t$$\n\t\\sum_{i=1}^N g_i = \\sum_{\\ell=1}^{\\tilde N} \\tilde g_{\\ell},\n\t$$\n\twith $D_{\\tilde g_s} \\neq D_{\\tilde g_t}$.\n\tFinally, we can have that $D_{\\tilde g_s} \\cap D_{\\tilde g_t}$ is an empty set or a $d-2$ dimensional affine space in $\\mathbb{R}^d$.\n\tSince\n\t$\\tilde N \\le N$ is a finite number, \n\t$$\n\tD := \\bigcup_{i=1}^N D_{\\tilde g_\\ell} \\backslash \\bigcup_{s\\neq t}\\left( D_{\\tilde g_s}\\cap D_{\\tilde g_t} \\right)\n\t$$\n\tis an unbounded set. \n\t\\begin{itemize}\n\t\t\\item If $\\Omega = \\mathbb{R}^d$,\n\t\t$$\n\t\t{\\rm supp(f)} \\supseteq D_{g} = D_{\\sum_{i=1}^N g_i} = D_{ \\sum_{\\ell=1}^{\\tilde N} \\tilde g_{\\ell}} \\supseteq D,\n\t\t$$ is contradictory to the assumption that $f$ is locally supported.\n\t\t\\item If $\\Omega$ is a bounded domain, \n\t\t$$\n\t\td(D, \\partial \\Omega) = \n\t\t\\begin{cases}\n\t\ts > 0 \\quad &\\text{if}\\quad  D_{\\tilde g_i} \\cap \\Omega = \\emptyset, \\forall i\\\\\n\t\t0 \\quad &\\text{otherwise}.\n\t\t\\end{cases}\n\t\t$$\n\t\tNote again that all $D_{\\tilde g_i}$'s are $d-1$ dimensional affine spaces, while $D_{\\tilde g_i} \\cap D_{\\tilde g_j}$ is either an empty set or a d-2 dimensional affine space. \n\t\tIf $d(D, \\partial \\Omega) > 0$, this implies that $\\nabla f$ is continuous in $\\Omega$, which contradicts the  assumption that $f$ is a basis function in FEM.\n\t\tIf $d(D, \\partial \\Omega) = 0$, this contradicts the previous assumption in \\eqref{distcondi}.\n\t\\end{itemize}\n\tHence ${\\rm DNN}_1$ cannot recover any piecewise linear function in $\\Omega$ for $d \\ge 2$.\n\\end{proof}\n\nFollowing the proof above, we have the following theorem~\\cite{he2020relu}.\n\\begin{theorem}\\label{linearindep}\n\t$\\{{\\rm ReLU}(w_i\\cdot x+b_i)\\}_{i=1}^m$ are linearly independent if $(w_i,\n\tb_i)$ and $(w_j, b_j)$ are linearly independent in\n\t$\\mathbb{R}^{1\\times (d+1)} $ for any $i \\neq j$.\n\\end{theorem}\n", "meta": {"hexsha": "14f1b8239bdea41d6e9fa960f5969f318c7f915c", "size": 6797, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/DNN1FEM-2D.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/DNN1FEM-2D.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/DNN1FEM-2D.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.7171052632, "max_line_length": 226, "alphanum_fraction": 0.6519052523, "num_tokens": 2694, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.86153820232079, "lm_q2_score": 0.8757869965109764, "lm_q1q2_score": 0.7545239545899906}}
{"text": "\\chapter{Bit Manipulation}\n\\section{Concepts}\n\\subsection{Basics}\n\\begin{enumerate}\n\\item Bit value: bit0, bit1. \n\\item BitSet/Bits\n\\item Bit position (bit interchangeably)\n\\item 32-bit signed range: $[-2^{31}, 2^{31}-1]$. $0$ is like positive number without complement. \n\\end{enumerate}\n\\begin{python}\nMAX = 0x7FFFFFFF\nMIN = 0x80000000\nMSK = 0xFFFFFFFF\n\\end{python}\n\\subsection{Operations}\n\\runinhead{Mask.} \n\\begin{enumerate}\n\\item Masking to 1: to mask a single bit position, $bit\\OR 1$\n\\item Masking to 0: to mask a single bit position, $bit\\AND 0$\n\\item Querying a bit position value: to query a single bit position, $bit\\AND 0010$\n\\item Toggling bit values: to toggle a single bit position, $bit\\XOR 1$\n\\end{enumerate}\nThis can be extended to do masking operations on multiple bits. \n\n\\runinhead{2's complement}\n$$\n-i = \\NOT i+1\n$$\n\n\\runinhead{Check 2's power}\n$$x\\AND(x-1)$$\n\n\\runinhead{Rightmost bit set.} To get the rightmost bit, with the help of 2's complement:\n\\begin{enumerate}\n\\item Left extended with 1's:\n$$x \\XOR (-x)$$\n\\item Left extended with 0's:\n$$x \\AND (-x)$$\n\\end{enumerate}\n\n\\runinhead{Negation and index} We can use tilde notation for the index accessing a string or an array\n\\begin{lstlisting}\ni  ~i  \n0  -1\n1  -2\n2  -3\n3  -4 \n4  -5 \n5  -6\n\\end{lstlisting}\n$$\n\\NOT i = -i+1\n$$\nTo determine whether a string is palindrome:\n\\begin{python}\ndef is_palindrome(s):\n  return all(s[i] == s[~i] for i in xrange(len(s)/2)) \n\\end{python}\n\n\\subsection{Python}\nPython int is larger than 32 bit. \nIf 32bit signed int, in python, we may need to mask the int:\n\\begin{enumerate}\n\\item Mask to 32bit: \\pyinline{x & MSK}, \n\\item Left extended with 1's: \\pyinline{\\~(x ^ MSK)}\n\\end{enumerate}\n\n, where \\pyinline{MSK = 0xFFFFFFFF}\n\n\\section{Radix}\n\\runinhead{Convert to hexadecimal with 2's complement.} Very easy to convert positive number of hex, but need to pay more attention to negative number when thinking in the decimal representation. \n\nEverything easy to convert the number even under 2's complement if thinking in the binary representation. \n\\begin{enumerate}\n\\item current digit we need: \\pyinline{num & 0xf}\n\\item next significant number: \\pyinline{num >>= 4}\n\\end{enumerate}\n\\section{Circuit}\nIt is under 32-bit assumption, for Python, we need additional masking in the previous section. \n\\subsection{Full-adder}\n\\rih{Plus.} Handle carry: only 1 + 1 needs carry, thus \\pyinline{a & b} determines carry. \n\\begin{python}\ndef plus(a, b):\n  carry = (a & b) << 1\n  out = a ^ b \n  if carry != 0:\n    return plus(out, carry)\n  else:\n    return out\n\\end{python}\n\\rih{Half Adder}. One bit \\pyinline{a, b}:\n\\begin{python}\ndef half_add(a, b): \n  carry = a & b\n  out   = a ^ b \n  return out, carry \n\\end{python}\n\\rih{Full Adder}. One bit \\pyinline{a, b, cin}. \\pyinline{out = a ^ b ^ cin}. and \\pyinline{cout = a & b | cin & a ^ b}\n\\begin{python}\ndef full_add(a, b, cin): \n  out, c1 = half_add(a, b)\n  out, c2 = half_add(out, cin)\n  cout    = c1 | c2  # ^ possible\n  return out, cout \n\\end{python}\n\n\\subsection{Full-substractor}\n\\rih{Substract.} Handle borrow: only 0 - 1 needs borrow, thus \\pyinline{\\~a & b} determines borrow. \n\\begin{python}\ndef sub(a, b):\n  borrow = (~a & b) << 1\n  out = a ^ b \n  if borrow != 0:\n    return sub(out, borrow)\n  else:\n    return out\n\\end{python}\n\\rih{Half Substractor.} One bit \\pyinline{a, b}:\n\\begin{python}\ndef half_sub(a, b):\n  borrow = (~a & b)\n  out = a ^ b\n  return out, borrow\n\\end{python}\nNotice negation can be done in xor. \n\\begin{python}\n~a == 1 ^ a \n\\end{python}\n\\rih{Full Substractor}. One bit \\pyinline{a, b, bin}. \\pyinline{out = a ^ b ^ bin}. \n\\begin{python}\ndef full_sub(a, b, bin):\n  out, b1 = half_sub(a, b)\n  out, b2 = half_sub(out, bin)\n  bout = b1 | b2 \n  return out, bout \n\\end{python}\n\n\\subsection{Multipler}\n\n\n\\section{Single Number}\n\\subsection{Three-time appearance} \nGiven an array of integers, every element appears three times except for one. Find that single one.\n\n\\rih{Using list.} Consider 4-bit numbers:\n\\begin{eqnarray*}\n&& 0000 \\\\\n&& 0001 \\\\\n&& 0010 \\\\\n&& ... \\\\\n&& 1111\n\\end{eqnarray*}\n\nAdd (not $\\&$) the bit values \\textbf{vertically}, then result would be $abcd$ where $a, b, c, d$ can be any number, not just binary. $a, b, c, d$ can be divided by 3 if the all element appears three times. Until here, you can use a list to hold $a, b, c, d$. By mod 3, the single one that does not appear 3 times is found. \n\nTo generalize to 32-bit \\pythoninline{int}, use a list of length 32.\n\n\\rih{Using bits.}\nTo further optimize the space, use bits (bit set) instead of list. \n\\begin{itemize}\n\\item Since all except one appears 3 times, we are only interested in $0, 1, 2$ (mod 3) count of bit1 appearances in a bit position.\n\\item We create 3 bit sets to represent $0, 1, 2$ appearances of all positions of bits.\n\\item For a bit, there is one and only one bit set containing bit1 in that bit position.\n\\item Transition among the 3 bit sets for every number:\n$$\nbitSet^{(i)} = (bitSet^{(i-1)}\\AND num)\\OR(bitSet^{(i)}\\AND \\NOT num)\n$$\n\\end{itemize}\n\nFor $i$ appearances, the first part is the bit set \\textbf{transited from} $(i-1)$ appearances, and the second part is the bit set \\textbf{transited out} from itself.\n\nConsider each single bit separately. For the $j$-th bit in $num$, if $num_j=1$, the first part indicates $bitSet^{(i-1)}$ will transit in (since transition); the 2nd part is always 0 (since transition out or initially 0). If $num_j=0$, the 1st part is always 0 (since no transition); the 2nd part indicates $bitSet^{(i)}$ will remain the same (since no transition). \n\n\n\n\\subsection{Two Numbers} \nGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.\n\n\\begin{itemize}\n\\item Easily get: $x = a \\XOR b$.\n\\item $a \\neq b$; thus there are at least one 1-bit in $x$ is different.  \n\\item Take an arbitrary 1 bit set in $x$, and such bit set can classify the elements in the array into two separate groups.\n\\end{itemize}\n\n\\section{Bitwise operators}\n\\runinhead{Comparison.} Write a method which finds the maximum of two numbers $a, b$. You should not use if- else or any other comparison operator\n\\\\\nClues:\n\\begin{enumerate}\n\\item check the sign bit $s$ of $a-b$.\n\\item return $a-s*(a-b)$\n\\end{enumerate}\nCodes:\n\\begin{java}\nint getMax(int a, int b) { \n    int c = a - b;\n    int k = (c >> 31) & 0x1; \n    int max = a - k * c; \n    return max;\n}\n\n\\end{java}\nIf consider overflow, it raises another level of difficulty. \n", "meta": {"hexsha": "0f676c465051bab0d0c4979ee2c473a201481714", "size": 6524, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterBitManipulation.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": "chapterBitManipulation.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": "chapterBitManipulation.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": 31.9803921569, "max_line_length": 366, "alphanum_fraction": 0.692213366, "num_tokens": 2102, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8757869851639066, "lm_q2_score": 0.86153820232079, "lm_q1q2_score": 0.7545239448140565}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Torsion \\& The Frenet-Serret Formulas}\n                We have previously defined some properties of curves, and some associated vectors, namely the unit tangent vector \\(\\vec{T}\\), the curvature \\(\\kappa\\), the principal normal vector \\(\\vec{N}\\), and the binormal vector \\(\\vec{B}\\). We have also defined the osculating planes and circles associated with curves, which function as approximations to curves different from the typical linear ones. Another property which we may wish to consider is torsion, which encodes the rate of change of the binormal vector.\n                \\begin{definition}{Torsion}{}\n                        Consider\n                        \\[\n                        \\frac{d\\vec{B}}{ds}\n                        \\]\n                        which is the rate of change of the binormal per unit length. This vector is perpendicular to both \\(\\vec{B}\\) and \\(\\vec{T}\\). The fact that it is perpendicular to \\(\\vec{B}\\) follows from the fact that the derivative of a vector of constant magnitude (\\(\\vec{B}\\) having constant unit magnitude) is always perpendicular to that vector. For \\(\\vec{T}\\), the relevant fact is that\n                        \\[\n                        \\frac{d\\vec{B}}{ds}=\\frac{d\\vec{T}}{ds}\\times\\vec{N}+\\vec{T}\\times\\frac{d\\vec{N}}{ds}\n                        \\]\n                        but\n                        \\[\n                        \\frac{d\\vec{T}}{ds}=\\kappa\\vec{N}\n                        \\]\n                        so the first term is zero, and thus\n                        \\[\n                        \\frac{d\\vec{B}}{ds}=\\vec{T}\\times\\frac{d\\vec{N}}{ds}\n                        \\]\n                        and therefore \\(\\vec{B}\\) must be perpendicular to \\(\\vec{T}\\), and we have\n                        \\[\n                        \\frac{d\\vec{B}}{ds}=-\\tau\\vec{N}\n                        \\]\n                        where \\(\\tau\\) is defined to be the \\emph{torsion} of the curve.\n                \\end{definition}\n                \\begin{example}{}{}\n                        Consider the helix parameterized by \\(\\vec{r}=a\\cos{t}\\i+a\\sin{t}\\j+bt\\k\\). Find the binormal vector and the torsion.\n                        \\tcblower\n                        We already know\n                        \\[\n                        v(t)=\\sqrt{a^2+b^2}=\\frac{ds}{dt}\n                        \\]\n                        \\[\n                        \\vec{T}=\\frac{1}{\\sqrt{a^2+b^2}}(-a\\sin{t}\\i+a\\cos{t}\\j+b\\k)\n                        \\]\n                        \\[\n                        \\vec{N}=-\\cos{t}\\i-\\sin{t}\\j\n                        \\]\n                        \\[\n                        \\kappa=\\frac{a}{a^2+b^2}\n                        \\]\n                        so to find \\(\\vec{B}\\), we must simply compute \\(\\vec{T}\\times\\vec{N}\\), which yields\n                        \\[\n                        \\vec{B}=\\frac{1}{\\sqrt{a^2+b^2}}(b\\sin{t}\\i-b\\cos{t}\\j+a\\k)\n                        \\]\n                        the torsion is then obtained by differentiating \\(\\vec{B}\\) in \\(s\\). This may be done using the chain rule, noting that\n                        \\[\n                        \\frac{d\\vec{B}}{dt}=\\frac{1}{\\sqrt{a^2+b^2}}(b\\cos{t}\\i+b\\sin{t}\\j)\n                        \\]\n                        and using the previously calculated value for \\(\\frac{ds}{dt}\\) we obtain\n                        \\[\n                        \\frac{d\\vec{B}}{ds}=-\\frac{b}{a^2+b^2}(-\\cos{t}\\i-\\sin{t}\\j)=-\\frac{b}{a^2+b^2}\\vec{N}\n                        \\]\n                        and therefore we have\n                        \\[\n                        \\tau=\\frac{b}{a^2+b^2}\n                        \\]\n                \\end{example}\n                It may be noted that the helix has constant curvature and torsion. As such, the helix is among the simplest 3D curves, having curvature and torsion which are constant, but non-zero.\n                \\begin{definition}{Frenet-Serret Formulas}{}\n                        The \\emph{Frenet-Serret formulas} define the derivatives of \\(\\vec{T}\\), \\(\\vec{B}\\), and \\(\\vec{N}\\). We have previously found\n                        \\begin{align*}\n                                \\frac{d\\vec{T}}{ds}&=\\kappa\\vec{N}\\\\\n                                \\frac{d\\vec{B}}{ds}&=-\\tau\\vec{N}\n                        \\end{align*}\n                        but we require a formula for the derivative of \\(\\vec{N}\\). We know that \\(\\vec{B}=\\vec{T}\\times\\vec{N}\\), but this implies \\(\\vec{N}=\\vec{B}\\times\\vec{T}\\), and therefore\n                        \\begin{align*}\n                                \\frac{d\\vec{N}}{ds}&=\\frac{d}{ds}\\vec{B}\\times\\vec{T}\\\\\n                                                   &=\\frac{d\\vec{B}}{ds}\\times\\vec{T}+\\vec{B}\\times\\frac{d\\vec{T}}{ds}\\\\\n                                                   &=-\\tau\\vec{N}\\times\\vec{T}+\\vec{B}\\times\\kappa\\vec{N}\\\\\n                                                   &=\\tau(\\vec{T}\\times\\vec{N})-\\kappa(\\vec{N}\\times\\vec{B})\\\\\n                                                   &=\\tau\\vec{B}-\\kappa\\vec{T}\n                        \\end{align*}\n\n                        This completes the Frenet-Serret formulas, which may also be written in a matrix form as\n                        \\[\n                        \\frac{d}{ds}\n                        \\begin{bmatrix}\n                                \\vec{T}\\\\\n                                \\vec{N}\\\\\n                                \\vec{B}\n                        \\end{bmatrix}=\n                        \\begin{bmatrix}\n                                0&\\kappa&0\\\\\n                                -\\kappa&0&\\tau\\\\\n                                0&-\\tau&0\n                        \\end{bmatrix}\n                        \\begin{bmatrix}\n                                \\vec{T}\\\\\n                                \\vec{N}\\\\\n                                \\vec{B}\n                        \\end{bmatrix}\n                        \\]\n                \\end{definition}\n\\end{document}\n", "meta": {"hexsha": "1cfc56209707c0242bdd4323a190e381d9f6f9ff", "size": 6011, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_6.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_6.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_6.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": 60.7171717172, "max_line_length": 524, "alphanum_fraction": 0.4019297954, "num_tokens": 1476, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314768368161, "lm_q2_score": 0.851952809486198, "lm_q1q2_score": 0.7545162248605362}}
{"text": "\\subsubsection{Parabolic Cylinders}\r\n\\noindent\r\nA paraboloid cylinder look like a parabola that has been extruded into 3D space. One of its forms is\r\n\\begin{equation*}\r\n\tz = cy^2,\r\n\\end{equation*} \r\nwhere $c \\in \\R$.\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\includegraphics[width=0.33\\textwidth]{./Images/differentialMultivariableCalculus/parabolid_cylinder.png}\r\n\t\\caption{A parabolic cylinder}\r\n\\end{figure}", "meta": {"hexsha": "29d480c4abc9396deb2464f29d1bdf1fa900b45d", "size": 405, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/parabolicCylinder.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/parabolicCylinder.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/parabolicCylinder.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": 31.1538461538, "max_line_length": 107, "alphanum_fraction": 0.750617284, "num_tokens": 129, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.8418256492357358, "lm_q1q2_score": 0.7544873847352799}}
{"text": "\\section{Indefinite Integrals}\\label{sec:IndefInt}\r\n\r\nIn this section we focus on computing indefinite integrals.\r\nThe process of finding the indefinite integral is called \\dfont{integration} (or \\dfont{integrating $f(x)$}).\r\n\r\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral}\r\nEvaluate the following indefinite integral:\r\n$$\\int x^5+3x-2\\,dx.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nSince this is asking for the most general anti-derivative we have:\r\n$$\\int x^5+3x-2\\,dx=\\frac{x^6}{6}+\\frac{3x^2}{2}-2x+C$$\r\nwhere $C$ is a constant.\r\n\\end{solution}\r\n\r\n{\\bf Common mistakes:}\r\nOne habit students make with integrals is to \\ifont{drop the dx} at the end of the integral.\r\nThis is required! Think of the integral as a set of parenthesis.\r\nBoth are required so it is clear where the integrand ends and what variable you are integrating with respect to.\r\n\r\nAnother common mistake is to \\ifont{forget the +C} for indefinite integrals.\r\n\r\nNote that we don't have properties to deal with products or quotients of functions, that is,\r\n%Just like with derivatives, the following will \\dfont{NOT} work:\r\n$$\\int f(x)\\cdot g(x)\\,dx\\neq \\int f(x)\\,dx\\int g(x)\\,dx.$$\r\n$$\\int \\frac{f(x)}{g(x)}\\,dx\\neq \\frac{\\int f(x)\\,dx}{\\int g(x)\\,dx}.$$\r\nWith derivatives, we had the product and quotient rules to deal with these cases.\r\nFor integrals, we have no such rules, but we will learn a variety of different techniques to deal with these cases.\r\n\r\nThe following integral rules can be proved by taking the derivative of the functions on the right side.\r\n\r\n\\begin{formulabox}[Integral Rules]\r\nSome properties and rules to know:\\\\\r\n$$\\mbox{Constant Rule:}\\quad\\int k\\,dx=kx+C.$$\r\n$$\\mbox{Constant Multiple Rule:}\\quad\\int kf(x)\\,dx=k\\int f(x)\\,dx,\\quad\\mbox{$k$ is constant}.$$\r\n$$\\mbox{Sum/Difference Rule:}\\quad\\int f(x)\\pm g(x)\\,dx=\\int f(x)\\,dx\\pm\\int g(x)\\,dx.$$\r\n$$\\mbox{Power Rule:}\\quad\\int x^n\\,dx=\\frac{x^{n+1}}{n+1}+C,\\quad n\\neq -1.$$\r\n$$\\mbox{Log Rule:}\\quad\\int \\frac{1}{x}\\,dx=\\ln|x|+C,\\quad x\\neq 0.$$\r\n$$\\mbox{Exponent Rule:}\\quad\\int a^{kx}=\\frac{a^{kx}}{k\\ln a}+C,\\quad x\\neq 0.$$\r\n$$\\mbox{Sine Rule:}\\quad\\int \\sin x\\,dx=-\\cos x+C.$$\r\n$$\\mbox{Cosine Rule:}\\quad\\int \\cos x\\,dx=\\sin x+C.$$\r\n\\end{formulabox}\r\n\r\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral2}\r\nIf $f'(x)=x^4+2x-8\\sin x$ then what is $f(x)$?\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nThe answer is:\r\n$$\\begin{array}{rcl}\r\n\\ds{f(x)=\\int f'(x)\\,dx}&=&\\ds{\\int \\left(x^4+2x-8\\sin x\\right)\\,dx}\\\\\r\n\\\\\r\n&=&\\ds{ \\int x^4 \\,dx + 2\\int x\\,dx -8 \\int \\sin x\\,dx }\\\\\r\n\\\\\r\n&=&\\ds{\\frac{x^5}{5}+x^2+8\\cos x+C,}\\\\\r\n\\end{array}$$\r\nwhere $C$ is a constant.\r\n\\end{solution}\r\n\r\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral3}\r\nFind the general indefinite integral of $\\ds\\int 3x^2\\,dx$.\r\n\\end{example}\r\n\\begin{solution}\r\n\t$$\\begin{array}{rcl}\r\n\t\\ds{\\int 3x^2\\,dx} & = & \\ds{3\\int x^2\\,dx}\\\\\r\n\t\\\\\r\n\t&=&\\ds{3\\frac{x^3}{3}+C}\\\\\r\n\t\\\\\r\n\t&=&x^3+C\\\\\r\n\t\\end{array} $$\r\n\\end{solution}\r\n\r\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral4}\r\nFind the general indefinite integral of $\\ds\\int \\frac{2}{\\sqrt x}\\,dx$.\r\n\\end{example}\r\n\\begin{solution}\r\n\t$$\\begin{array}{rcl}\r\n\t\\ds{\\int \\frac{2}{\\sqrt x}\\,dx} & = & \\ds{2\\int x^{-\\frac{1}{2}}\\,dx}\\\\\r\n\t\\\\\r\n\t&=&\\ds{2\\frac{x^{-\\frac{1}{2}+1}}{-\\frac{1}{2}+1}+C}\\\\\r\n\t\\\\\r\n\t&=&4\\sqrt x+C\\\\\r\n\t\\end{array}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral5}\r\nFind the general indefinite integral of $\\ds\\int \\left(\\frac{1}{x}+e^{7x}+x^\\pi+7\\right)\\,dx$.\r\n\\end{example}\r\n\\begin{solution}\r\n\t$$\\begin{array}{rcl}\r\n\t\\ds{\\int \\left(\\frac{1}{x}+e^{7x}+x^\\pi+7\\right)\\,dx} & = & \\ds{\\int \\frac{1}{x}\\,dx+\\int e^{7x}\\,dx+\\int x^\\pi\\,dx+\\int 7\\,dx}\\\\\r\n\t\\\\\r\n\t&=& \\ds{\\ln|x|+\\frac{1}{7}e^{7x}+\\frac{x^{\\pi+1}}{\\pi+1}+7x+C}\\\\\r\n\t\\end{array}$$\r\n\\end{solution}\r\n\r\n\\subsection*{Differential Equations}\r\nAn equation involving derivatives where we want to solve for the original function is called a \\dfont{differential equation}.\r\nFor example, $f'(x)=2x$ is a differential equation with general solution $f(x)=x^2+C$.\r\nSome solutions (i.e., particular values of $C$) are shown below.\r\n$$\\includegraphics[width=3in]{images2/integral-curves}$$\r\nAs seen with integral curves, we may have an infinite family of solutions satisfying the differential equation.\r\nHowever, if we were given a point (called an \\ifont{initial value}) on the curve then we could determine $f(x)$ completely.\r\nSuch a problem is known as an \\ifont{initial value problem}.\r\n\r\n\\begin{example}{Initial Value Problem}{Initial Value Problem}\r\nIf $f'(x)=2x$ and $f(0)=2$ then determine $f(x)$.\r\n\\end{example}\r\n\r\n\\begin{solution} \r\nAs previously stated, we have a solution of:\r\n$$f(x)=x^2+C.$$\r\nBut $f(0)=2$ implies:\r\n$$2=0^2+C\\quad\\to\\quad C=2.$$\r\nTherefore, $f(x)=x^2+2$ is the solution to the initial value problem.\r\n\\end{solution}\r\n\r\n\r\n\r\n%\r\n%\\dfont{Rectlinear Motion:} We can use the concept of anti-derivatives to find position functions when given the velocity function (or velocity functions when given the acceleration).\r\n%In particular, since $a(t)=v'(t)$ and $v(t)=s'(t)$, where $s(t)$, $v(t)$ and $a(t)$ are the position, velocity and acceleration functions respectively, we have,\r\n%$$v(t)=\\int a(t) \\,dt,\\quad s(t)=\\int v(t) \\,dt.$$\r\n%\r\n%\\begin{example}\r\n%A particle moves along a straight line with acceleration $a(t)=6t+4$. \r\n%Its initial velocity is $v(0)=-6$ cm/s and initial position is $s(0)=9$ cm. \r\n%Find $s(t)$.\r\n%\\end{example}\r\n%\r\n%\\begin{solution}\r\n%Antidifferentiation gives (since $v(t)=\\int a(t) \\,dt$):\r\n%\\[ v(t) = 6 \\frac{t^2}{2}+ 4t +C = 3t^2+4t+C.\\]\r\n%But $v(0)=-6$, so $C=-6$, and \r\n%\\[ v(t) =  3t^2+4t-6 \\]\r\n%Now antidifferentiation again gives  (since $s(t)=\\int v(t) \\,dt$):\r\n%\\[ s(t) = 3 \\frac{t^3}{3} + 4 \\frac{t^2}{2} -6t +D = t^3+2t^2-6t+D.\\]\r\n%But $s(0)=9$, so $D=9$, and we finally get:\r\n%\\[ s(t) = t^3+2t^2-6t+9.\\]\r\n%\\end{solution}\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:IndefInt}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\nFind the antiderivatives of the functions:\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds 8\\sqrt{x}$\r\n\\begin{sol}\r\n $\\ds (16/3)x^{3/2}+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds 3t^2+1$\r\n\\begin{sol}\r\n $\\ds t^3+t+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds 4/\\sqrt{x}$\r\n\\begin{sol}\r\n $\\ds 8\\sqrt{x}+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds 2/z^2$\r\n\\begin{sol}\r\n $-2/z+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds 7s^{-1}$\r\n\\begin{sol}\r\n $7\\ln s+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds (5x+1)^2$\r\n\\begin{sol}\r\n $\\ds (5x+1)^3/15+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds (x-6)^2$\r\n\\begin{sol}\r\n $\\ds (x-6)^3/3+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds x^{3/2}$\r\n\\begin{sol}\r\n $\\ds 2x^{5/2}/5+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds {2\\over x\\sqrt x}$\r\n\\begin{sol}\r\n $\\ds -4/\\sqrt{x}+C$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds |2t-4|$\r\n\\begin{sol}\r\n $\\ds 4t-t^2+C$, $t<2$; $\\ds t^2-4t+8+C$, $t\\ge 2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}\r\n", "meta": {"hexsha": "a0629df4f092a12cfd41e29a00ae35b2856f7548", "size": 7109, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6-integration/6-3-indefinite-integrals.tex", "max_stars_repo_name": "TimAlderson/OpenCalc", "max_stars_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6-integration/6-3-indefinite-integrals.tex", "max_issues_repo_name": "TimAlderson/OpenCalc", "max_issues_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6-integration/6-3-indefinite-integrals.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.3803418803, "max_line_length": 184, "alphanum_fraction": 0.6151357434, "num_tokens": 2627, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110454379297, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7544208076645406}}
{"text": "% Project for Integration Workshop. Dept. Mathematics. UArizona\n% Compute and plot lagrange interpolating polynomials. Explore when they do well and when they do poorly. `Discovery' of chebychev points.\n\n\\section{Lagrange Interpolation for Function Approximation}\nLet $\\{(x_k,y_k) ,\\,\\text{for}\\, k = 1, \\dots, N\\}$ be $N$ points in $\\mathbb{R}^2$ that satisfy $x_k \\neq x_j$ whenever $k \\neq j$. The \\textit{Lagrange interpolating polynomial} is defined as\n\\begin{equation}\nL(x) = \\sum_{k = 1}^N \\left(\\prod_{j \\neq k}\\frac{x-x_j}{x_k-x_j} \\right) y_k.\n\\end{equation}\nIn this project, you will determine how well a Lagrange interpolating polynomial can approximate the functions \n\\begin{equation}\nf(x) = (x-.9)(x-.4)(x+.1)(x+.7)(x+.8)\n\\end{equation}\nand \n\\begin{equation}\ng(x) = \\frac{1}{1+10x^2} \\quad \\quad \\text{for } -1 \\leq x \\leq 1\n\\end{equation}\n\\begin{enumerate}[(a)]\n    \\item Observe that the Lagrange interpolating polynomial is a linear combination of $N$ terms in the form\n    \\begin{equation}\n    T_k(x): =\\left( \\prod_{j \\neq k}\\frac{x-x_j}{x_k-x_j}  \\right) \n    \\end{equation}\n    Let $x_1= -1$, $x_2 = 0$, and $x_3 = 1$. Plot the functions $T_k(x)$ for $k = 1,\\dots,3$, and describe what you see.\n    \\item \n    \\begin{enumerate}[i.]\n      \\item Sample $f(x)$ at the points $x_1 = -1$, $x_2 = 0$, and $x_3= 1$. Compute and plot the Lagrange interpolating polynomial given by these 3 equi-spaced points.\n      \\item Repeat part (b)(i) with 5 equi-spaced points, and again with 9 equi-spaced points. Plot your results and describe whether your approximation improves with more points. \n    \\end{enumerate}\n    \\item Repeat part (b) for the function $g(x)$.\n    \\item There is a well-known rule of thumb for improving numerical approximations: Increase the sampling density in the regions where the error is greatest. Does this rule of thumb seem to work with the functions $f$ and $g$?\n\\end{enumerate}\n\n", "meta": {"hexsha": "6b89b95cbe078c10e627c6dc5d1af68cd8ec8422", "size": 1920, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lagrange-interpolants.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": "lagrange-interpolants.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": "lagrange-interpolants.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": 60.0, "max_line_length": 228, "alphanum_fraction": 0.6979166667, "num_tokens": 617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8459424373085146, "lm_q2_score": 0.8918110346549902, "lm_q1q2_score": 0.7544208002746706}}
{"text": "% !TEX root = Main.tex\n\\section{Gaussian Mixture Models (GMM)}\nlet $\\boldsymbol{\\theta}_k = (\\boldsymbol{\\mu}_k, \\boldsymbol{\\Sigma}_k)$, $p(\\mathbf{x};\\theta_k) = \\mathcal{N}(\\mathbf{x} | \\boldsymbol{\\mu}_k, \\Sigma_k)$\\\\\n\\textbf{Mixture Models:} $p_\\theta(\\mathbf{x}) = \\sum_{k=1}^K \\pi_k p(\\mathbf{x};\\theta_k)$\\\\\n1. sample cluster index $j \\sim Categorical(\\pi)$\\\\\n2. given $j$, sample data $x \\sim \\text{Normal}(\\mu_j, \\Sigma_j)$ \\\\\n\\textbf{Latent variables:} data point $x_i$ belongs to cluster $z_i$. $p(z_i=j)=\\pi_j$ \\\\\n\\textbf{Max. Likelihood Estimation (MLE):}\\\\\n$\\argmax_\\theta\\sum_{n=1}^N \\log \\left( \\sum_{k=1}^K \\pi_k p(\\mathbf{x}_n;\\theta_k)\\right)\\\\\n\\ge \\sum_{n=1}^N \\sum_{k=1}^K{q_{k,n}[\\log p(\\mathbf{x}_n;\\theta_k) + \\log \\pi_k - \\log q_{k,n}]}$\\\\\n\n\\subsection*{Expectation-Maximization (EM) for GMM}\n\\textbf{E-Step: (posterior over latent variables)}\\\\\n$q_{k,n}^* = \\operatorname{Pr}(z_n=k|x_n) = \\frac{1}{Z}p(z_n=k)p(x_n|z_n=k) = \\frac{\\boldsymbol{\\pi}_k p(x_n;\\theta_k)}{\\sum_{l=1}^K \\boldsymbol{\\pi}_l p(x_n;\\theta_l)}$ \\\\\n\\textbf{M-Step: } $\\boldsymbol{\\mu}_k^* := \\frac{\\sum_{n=1}^N q_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N q_{k,n}}$\n$, \\boldsymbol{\\pi}_k^* := \\frac{1}{N} \\sum_{n=1}^N q_{k,n}$\\\\\n$\\Sigma_k^* = \\frac{\\sum_{n=1}^N q_{k, n} (\\mathbf{x}_n - \\boldsymbol{\\mu}_k)(\\mathbf{x}_n - \\boldsymbol{\\mu}_k)^\\top}{\\sum_{n=1}^N q_{k,n}}$\n\n\\subsection*{Gaussian distribution}\nStandard deviation $\\sigma$, Mean $\\mu$ \\\\\n$p(x;\\mu, \\sigma) = \\frac{1}{\\sqrt{2\\pi \\sigma^2}} e^{- \\frac{1}{2} \\frac{(x-\\mu)^2}{\\sigma^2}}$\\\\\nCovariance matrix $\\Sigma$, Mean $\\mu$ \\\\\n$p(x;\\mu, \\Sigma) = \\frac{1}{(2\\pi)^{D/2} |\\Sigma|^{1/2}} e^{- \\frac{1}{2} (x-\\mu)^T \\Sigma^{-1} (x-\\mu)}$\n\n\\subsection*{Model Order Selection (AIC / BIC for GMM)}\nTrade-off between data fit (i.e. likelihood $p(\\mathbf{X} | \\theta)$) and complexity (i.e. \\# of free parameters $\\kappa(\\cdot)$). For choosing $K$:\\\\\n\\textbf{Akaike Information Criterion}: $\\operatorname{AIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\kappa(\\theta)$\\\\\n\\textbf{Bayesian Information Criterion}: $\\operatorname{BIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\frac{1}{2} \\kappa(\\theta) \\log N$\\\\\n\\# of free params for GMM: $\\kappa(\\theta) = KD + K\\frac{D(D+1)}{2} + (K - 1)$.\\\\\n\n", "meta": {"hexsha": "90c85dec03b33843a67fe6069e215b5035ec194b", "size": 2255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GaussianMixtureModel.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": "GaussianMixtureModel.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": "GaussianMixtureModel.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": 72.7419354839, "max_line_length": 172, "alphanum_fraction": 0.6172949002, "num_tokens": 947, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9481545289551957, "lm_q2_score": 0.7956580952177051, "lm_q1q2_score": 0.7544068264805315}}
{"text": "\\section{Information Criteria}\r\nIn this section we review the concepts behind \r\nAkaike's Information Criterion (AIC).\r\n\r\nAkaike's original work is for\r\nIID data, however it is extended to a regression type setting in a\r\nstraight forward way. Suppose that the conditional distribution of $Y$\r\ngiven $\\bx$ is know except for a $P$-dimensional parameter $\\bb$. In\r\nthis case,  the probability density function of $\\bY =\r\n(Y_1,\\dots,Y_n)$ can be written as \r\n\\begin{equation}\r\n\\label{parsimodel}\r\nf_{\\bY}(\\by;\\bX,\\bb) \\equiv \\prod_{i=1}^n f(y_i;\\bx_i,\\bb)\r\n\\end{equation}\r\nwith $\\bX$ the design matrix with rows $\\bx_i$. \r\n\r\nAssume that\r\nthere exists a true parameter vector $\\bb^*$ defining a true\r\nprobability density denoted by\r\n$f_{\\bY}(\\by;\\bX,\\bb^*)$. Given these assumptions, we wish to select\r\n$\\bb$, from one of the models \r\ndefined as in (\\ref{modelpdef}), ``nearest'' to the true\r\nparameter $\\bb^*$ based on the observed data $\\by$.\r\nThe principle behind Akaike's criterion is to\r\ndefine ``nearest'' as the model that minimizes the Kullback-Leibler \r\nInformation Quantity\r\n\\begin{equation}\r\n\\label{KLdef} \r\n\\Delta(\\bb^*;\\bX,\\bb) = \\int \\left\\{\\log\r\n  f_\\bY(\\by;\\bX,\\bb^*) - \\log\r\n  f_\\bY(\\by;\\bX,\\bb)\\right\\} f_{\\bY}(\\by;\\bX,\\bb^*) \\, d\\by.\r\n\\end{equation}\r\n\r\nThe analytical properties of the Kullback-Leibler Information Quantity\r\nare discussed in detail by Kullback (1959) \\nocite{kull:1959}. Two\r\nimportant properties \r\nfor Akaike's criterion are\r\n\\begin{enumerate}\r\n\\item $\\Delta(\\bb^*;\\bX,\\bb) > 0$ if \r\n$f_{\\bY}(\\by;\\bX,\\bb^*) \\neq f_{\\bY}(\\by;\\bX,\\bb)$\r\n\\item\r\n$\\Delta(\\bb^*;\\bX,\\bb) = 0$  if and only if $f_{\\bY}(\\by;\\bX,\\bb^*) =\r\nf_{\\bY}(\\by;\\bX,\\bb)$ \r\n\\end{enumerate}\r\nalmost everywhere on the range of $\\bY$. \r\nThe properties\r\nmentioned suggest that finding the model that \r\nminimizes the Kullback-Leibler \r\nInformation Quantity is an appropriate way to choose the ``nearest''\r\nmodel.\r\n\r\nSince the first term on the\r\nright hand side of \r\n(\\ref{KLdef}) is constant over all models we consider, we may instead\r\nmaximize\r\n\\begin{eqnarray}\r\n\\nonumber\r\nH(\\bb) &=& \\int \\log\r\n  f_\\bY(\\by;\\bX,\\bb) f_{\\bY}(\\by;\\bX,\\bb^*) \\, d\\by\\\\\r\n\\label{Hdef}\r\n&=& \\sum_{i=1}^n \\int \\log f(y_i;\\bX,\\bb) \\, f(y_i;\\bx_i,\\bb^*) \\, dy_i.\r\n\\end{eqnarray}\r\n\r\nLet $\\bbh_p$ be the maximum likelihood estimate under\r\nModel(p). Akaike's procedure for model selection is based on choosing\r\nthe model which produces the estimate that maximizes \r\n$\\E_{\\bb^*}\\left[H(\\bbh_p)\\right]$ amongst all\r\ncompeting models. Akaike then derives a criterion by constructing an\r\nasymptotically unbiased estimate of $\\E_{\\bb^*}\\left[H(\\bbh_p)\\right]$ based\r\non the observed data. \r\n\r\nNotice that $H(\\bbh_p)$ is a function,\r\ndefined by (\\ref{Hdef}),\r\nof the maximum likelihood estimate $\\bbh_p$, which is a\r\nrandom variable obtained from the observed data.\r\nA natural estimator of \r\nits expected value (under the true distribution of the data) is\r\nobtained by substituting the empirical distribution of the data into\r\n(\\ref{Hdef}) \r\nresulting in the log likelihood equation evaluated at the maximum\r\nlikelihood estimate under model(p)\r\n\\[\r\nl(\\bbh_p) = \\sum_{i=1}^n \\log f(y_i;\\bx_i,\\bbh_p).\r\n\\]\r\nAkaike noticed that in general  $l(\\bbh_p)$ will \r\noverestimate $\\E_{\\bb^*}\\left[H(\\bbh)\\right]$.  In particular Akaike found\r\nthat under some regularity conditions\r\n\\[\r\nE_{\\bb^*}\\left[l(\\bbh_p) - H(\\bbh_p)\\right] \\approx p .\r\n\\]\r\nThis suggests that larger \r\nvalues of $p$ will result in smaller values \r\nof $l(\\bbh_p)$, which may be\r\nincorrectly interpreted as a ``better'' \r\nfit, regardless of the true model. We need to ``penalize'' for larger\r\nvalues of $p$ in order to obtain an unbiased estimate of\r\nthe ``closeness'' of the model. \r\nThis fact leads to the Akaike Information Criteria which is a\r\nbias-corrected estimate given by \r\n\\begin{equation}\r\n\\label{AIC}\r\n\\mbox{AIC}(p) = - 2 l(\\bbh_{p}) + 2p .\r\n\\end{equation}\r\nSee, for example, Akaike (1973) and Bozdogan (1987)  for\r\nthe details.  \r\n\r\n\r\n", "meta": {"hexsha": "b86d7a8b035120bf3914697a1e08ed8d9ba80d95", "size": 3967, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "pages/754/section-09-02.tex", "max_stars_repo_name": "igrabski/rafalab.github.io", "max_stars_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 50, "max_stars_repo_stars_event_min_datetime": "2016-08-17T23:04:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-31T19:21:02.000Z", "max_issues_repo_path": "pages/754/section-09-02.tex", "max_issues_repo_name": "igrabski/rafalab.github.io", "max_issues_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-18T00:41:36.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-21T22:35:40.000Z", "max_forks_repo_path": "pages/754/section-09-02.tex", "max_forks_repo_name": "igrabski/rafalab.github.io", "max_forks_repo_head_hexsha": "2f27ea0d9e0b8a2342bb851ae7415ba3268fd00f", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 38, "max_forks_repo_forks_event_min_datetime": "2016-08-17T22:17:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-20T12:17:08.000Z", "avg_line_length": 36.7314814815, "max_line_length": 77, "alphanum_fraction": 0.6944794555, "num_tokens": 1253, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.877476800298183, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7543349923974421}}
{"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 6 for Bayesian Data Analysis}}\n\\author{Fan JIN\\quad (2015011506)}\n\\maketitle\n\n\\section*{Question 10.4a}\n{\n    Let the identity function $I$ indicate whether a sample $x$ is accepted or not. It follows that \n    $$p(I=1) = \\int{ p(I=1 | x) g(x) \\deriv{x} }$$\n    $$= \\int{ \\frac{f(x)}{c g(x)} g(x) \\deriv{x} }$$\n    $$= \\int{ \\frac{f(x)}{c} \\deriv{x} } = \\frac{1}{c}.$$\n\n    Then, we have \n    $$p(x | I=1) = p(x, I=1) / p(I=1)$$\n    $$= g(x) \\frac{f(x)}{c g(x)} / \\frac{1}{c} = f(x).$$\n}\n\n\\section*{Question 10.4b}\n{\n    To make the integral above valid, it requires 1) the denominator $g(x)>0$ for any $x$ that satisfies $f(x)>0$, and 2) the probability $f(x) / c g(x) \\leq 1$ for any $x$. These two requirements cannot be met unless $f(x)/g(x)$ is bounded.\n}\n\n\\section*{Question 10.6}\n{\n    Without loss of generality, suppose the posterior distribution is normal $N(0, 3)$, which matches, in mode and curvature (variance), to the standard $t_3$ distribution. \n    \\begin{table}[H]\n        \\centering\n        \\caption{Estimated posterior expectation and variance}\n        \\begin{tabular}{@{}clc@{}clc@{}}\n        \\toprule\n        sample size & \\multicolumn{1}{c}{E (estimated)} & \\multicolumn{1}{c}{E (true)} & \\multicolumn{1}{c}{Var (estimated)} & \\multicolumn{1}{c}{Var (true)}  \\\\ \\midrule\n        100 & 0.076218 & 0 & 3.043008 & 3   \\\\ \n        10000 & -0.035262 & 0 & 3.051913 & 3  \\\\ \\bottomrule\n        \\end{tabular}\n    \\end{table}\n    The estimation is accurate even for a small sample size ($S=100$).\n    Some importance weights are extremely small, but no weights are extremely large. This implies well behaved importance weights.\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.6\\linewidth]{1_weight_100.png}\n        \\includegraphics[width = 0.6\\linewidth]{1_log_weight_100.png}\n        \\caption{Sample size = 100}\n    \\end{figure}\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.6\\linewidth]{1_weight_10000.png}\n        \\includegraphics[width = 0.6\\linewidth]{1_log_weight_10000.png}\n        \\caption{Sample size = 10000}\n    \\end{figure}\n\n}\n\n\\section*{Question 10.7}\n{\n    Without loss of generality, suppose the posterior distribution is standard $t_3$, which matches, in mode and curvature (variance), to the normal $N(0, 3)$ distribution. \n    \\begin{table}[H]\n        \\centering\n        \\caption{Estimated posterior expectation and variance}\n        \\begin{tabular}{@{}clc@{}clc@{}}\n        \\toprule\n        sample size & \\multicolumn{1}{c}{E (estimated)} & \\multicolumn{1}{c}{E (true)} & \\multicolumn{1}{c}{Var (estimated)} & \\multicolumn{1}{c}{Var (true)}  \\\\ \\midrule\n        100 & 0.084248 & 0 & 1.648969 & 1   \\\\ \n        10000 & -0.008052 & 0 & 2.193678 & 1  \\\\ \\bottomrule\n        \\end{tabular}\n    \\end{table}\n    The estimation is not accurate even for a large sample size ($S=10000$).\n    Some importance weights are extremely large, especially for large sample size. This implies the importance weights are too variate, and therefore, explains why our estimation is even worse when we have larger sample size: \n    \n    Since the $t$ distribution has heavier tails than the normal distribution does, we can hardly draw a sample at the tail from simulation based on normal distribution. With a large sample size, it is more likely that such a tail sample is drawn, leading to a large importance weight. This would increase the variance of our estimation, as the weights are not so uniform. According to the textbook, the estimation is sensitive to an outlier of extremely large importance weight (when we try to estimate heavy tailed distribution with a light tailed one), while it is not when we try to estimate in the reversed way.\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.6\\linewidth]{2_weight_100.png}\n        \\includegraphics[width = 0.6\\linewidth]{2_log_weight_100.png}\n        \\caption{Sample size = 100}\n    \\end{figure}\n    \\begin{figure}[H]\n        \\centering\n        \\includegraphics[width = 0.6\\linewidth]{2_weight_10000.png}\n        \\includegraphics[width = 0.6\\linewidth]{2_log_weight_10000.png}\n        \\caption{Sample size = 10000}\n    \\end{figure}\n}\n\n\\section*{Source Code in R}\n{\n    \\begin{lstlisting}[language=R]\n        set.seed(2018)\n\n        weight <- function(x) {\n          return (dnorm(x, sd = sqrt(3)) / dt(x, 3))\n        }\n        \n        for (S in c(100, 10000)) {\n          t = rt(S, 3)\n          w = unlist(lapply(t, weight))\n          \n          png(sprintf(\"1_weight_%d.png\", S), width = 640, height = 480)\n          hist(w, breaks = 100)\n          dev.off()\n          \n          png(sprintf(\"1_log_weight_%d.png\", S), width = 640, height = 480)\n          hist(log(w), breaks = 100)\n          dev.off()\n          \n          first.order = mean(t * w) / mean(w)\n          second.order = mean(t^2 * w) / mean(w)\n          \n          expectation = first.order\n          variance = second.order - first.order^2\n          \n          print(sprintf(\"1: size = %d, expectation = %f, \n                        variance = %f\", S, expectation, variance))\n        }\n        \n        weight <- function(x) {\n          return (dt(x, 3) / dnorm(x, sd = sqrt(3)))\n        }\n        \n        for (S in c(100, 10000)) {\n          n = rnorm(S, sd = sqrt(3))\n          w = unlist(lapply(n, weight))\n          \n          png(sprintf(\"2_weight_%d.png\", S), width = 640, height = 480)\n          hist(w, breaks = 100)\n          dev.off()\n          \n          png(sprintf(\"2_log_weight_%d.png\", S), width = 640, height = 480)\n          hist(log(w), breaks = 100)\n          dev.off()\n          \n          first.order = mean(n * w) / mean(w)\n          second.order = mean(n^2 * w) / mean(w)\n          \n          expectation = first.order\n          variance = second.order - first.order^2\n          \n          print(sprintf(\"2: size = %d, expectation = %f, \n                        variance = %f\", S, expectation, variance))\n        }\n    \\end{lstlisting}\n}\n\n\\clearpage\n\\end{document}\n", "meta": {"hexsha": "8782b689b69df95e11b98f67a5238f5b20c3664f", "size": 6668, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "HW6/Homework6.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": "HW6/Homework6.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": "HW6/Homework6.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": 39.6904761905, "max_line_length": 616, "alphanum_fraction": 0.6114277145, "num_tokens": 1960, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637577007393, "lm_q2_score": 0.8774767826757122, "lm_q1q2_score": 0.7543349882901578}}
{"text": " \\subsection{Model (what is $\\theta$)}\n\n In our project, we analyze the time-series, i.e. the sequence of given data\n \\begin{equation}\n  \\label{eq:timeseries}\n\tx_0, x_1, \\dots, x_{T-1},\n \\end{equation}\n where $x_t \\in \\mathbb{R}^{\\mathrm{xdim}}$ and $\\mathrm{xdim} \\in \\mathbb{N}$ is the number of values (measurements) in each time step. \n We try to understand the inner mechanism (dynamics) of the sequence. \\newline\n \n As the first step of analyze of given data, we can use classical tools and easily compute \"static\"\\footnote{I decided to use this term, because following properties does not take into account the time} statistics, like average, variance, deviation and other moments or central moments.\n These values provide us the basic properties of the given set of data, however they does not take into account the fact, that we are not working with only set, but we analyze the sequence.\n\n One of the most typical way how to analyze sequences is to appoximate the given data by much more simplier function. Afterwards, analyzing this approximating function provides us the basic knowledge of sequence behaviour with respect to time. \n The approximation is performed to be \"as good as possible\", i.e. in a such way, that the error of the approximation is as small as possible.\n \n The most simplest approximation function is linear\\footnote{in fact, the simplest approximation function is constant function; however the constant function is in this case the average of given set of data; constant function is constant with respect to time and therefore it cannot reflect the dynamics of the sequence}.\n In this case, we are talking about \\emph{linear regression}.\n \n For the simplicity, in the following we will suppose one dimensional data $\\mathrm{xmem} = 1$, i.e. $x(t) \\in \\mathbb{R}$. \n Provided observations could be easily generalized to more dimensions.\n \n Suppose that all given data \\eqref{eq:timeseries} linearly depends on the time, i.e. each data point could be written in form $x(t) = \\alpha_0 + \\alpha_1 t$, where $\\alpha_0,\\alpha_1 \\in \\mathbb{R}$ are unknown time-independent parameters of this linear \\emph{model}. \n However, general sequence is not generated by linear function, therefore in each time-step we make an error. To be more exact, we rather write\n \\begin{equation}\n  \\label{eq:linear}\n  x(t) = \\alpha_0 + \\alpha_1 t + \\varepsilon_t, ~~t = 0,\\dots,T,\n \\end{equation}\n where $\\varepsilon_t$ is an error of approximation (hopefully small for all $t$). \n If we denote \n \\begin{displaymath}\n  \\begin{array}{rcl}\n   x & = & [x_0, \\dots, x_{T-1}]^T \\in \\mathbb{R}^T, \\\\[5mm]\n   Z & = & \\left[\n    \\begin{array}{ccccc}\n     1 & 1 & 1 & \\dots & 1 \\\\\n     0 & 1 & 2 & \\dots & T-1\n    \\end{array} \n     \\right] \\in \\mathbb{R}^{2,T}, \\\\[5mm]\n   y & = & [\\alpha_0,\\alpha_1]^T \\in \\mathbb{R}^2, \\\\[5mm]\n   \\varepsilon & = & [\\varepsilon_0,\\dots,\\varepsilon_{T-1}] \\in \\mathbb{R}^T,\n  \\end{array}\n \\end{displaymath}\n then the system of equations \\eqref{eq:linear} could be written in form\n \\begin{equation}\n  \\label{eq:linear2}\n  x = Z^T y + \\epsilon.\n \\end{equation}\n We want to perform the approximation (i.e. find $y$) in the best way as possible. We minimize the size of the error $\\Vert \\varepsilon \\Vert \\rightarrow \\min\\limits_{y}$. \n Using \\eqref{eq:linear2}, we can substitute and we get optimization problem\n \\begin{equation}\n  \\label{eq:linear_opt}\n  \\hat{y} = \\arg\\min\\limits_{y} \\Vert \\varepsilon \\Vert  = \\arg\\min\\limits_{y} \\Vert Z^T y - x \\Vert = \\arg\\min\\limits_{y} \\underbrace{\\frac{1}{2}\\Vert Z^T y - x \\Vert^2}_{ = \\Psi(y)}  \n \\end{equation}\n Please, notice that $\\Psi(y)$ is quadratic function\n \\begin{displaymath}\n  \\Psi(y) = \\frac{1}{2}\\Vert Z^T y - x \\Vert^2 = \\frac{1}{2}\\langle Z^T y - x, Z^T y - x \\rangle = \\frac{1}{2}y^T Z Z^T y - y^T Z x + \\frac{1}{2}x^T x,\n \\end{displaymath}\n therefore the gradient is given by\n \\begin{displaymath}\n  \\nabla \\Psi(y) = ZZ^T y - Z x\n \\end{displaymath}\n and the necessary optimality condition of \\eqref{eq:linear_opt} is given by the system of linear equations\\footnote{yes, this is a least-square solution of our first naiive approach $x(t) = \\alpha_0 + \\alpha_1 t$}\n \\begin{displaymath}\n  ZZ^T y = Zx .\n \\end{displaymath}\n\n% \\begin{example}\n%  Let us consider data\n%  \\begin{displaymath}\n%   x_0 = \n%  \\end{displaymath}\n% \\end{example}\n\n Using a simple generalization idea, we are able to extend the linear regression model to polynomial models\n \\begin{displaymath}\n  x(t) = p(t) + \\varepsilon_t, p \\in \\mathcal{P}_n,\n \\end{displaymath}\n where $\\mathcal{P}_n$ is a vector space of polynomial function of degree $n \\in \\mathbb{N}$.\n\n All parameters of the model will be denoted by a $\\Theta$.\n\n\n \\subsection{Non-stationarity (what is $\\gamma$)}\n\n", "meta": {"hexsha": "ae56523fcf1256590e783c34f4601e54dfbe46f8", "size": 4733, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Documents/PASC_report/section/problem.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/problem.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/problem.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": 55.0348837209, "max_line_length": 321, "alphanum_fraction": 0.7082188887, "num_tokens": 1435, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8596637469145053, "lm_q2_score": 0.8774767922879692, "lm_q1q2_score": 0.7543349870887966}}
{"text": "\\section{Deriving the invariant extended Kalman filter}\nThe filtering problem is a MAP problem given by\n\\begin{align}\n    \\mbfhat{X}_{k} \n    &= \\argmax_{\\mbf{X}_{k}\\in G} \\pdf{\\mbf{X}_{k+1}\\mid \\mbfhat{X}_{k-1}, \\mbf{u}_{k-1}, \\mbf{y}_{k}}\\\\\n    \\label{eq:InEKF derivation:pdf Xhat given Xhatkm1 ukm1 yk}\n    &= \\argmax_{\\mbf{X}_{k-1}\\in G} \\pdf{\\mbf{y}_{k}\\mid \\mbf{X}_{k}}\\pdf{\\mbf{X}_{k}\\mid\\mbfhat{X}_{k-1}, \\mbf{u}_{k-1}},\n\\end{align}\nwhere $\\mbfhat{X}_{k-1}$ is the InEKF estimate of $\\mbf{X}_{k-1}$.\n\nAs briefly discussed in Section~\\ref{sec:Random variables on Lie groups}, random variables on Lie groups can be described by\n\\begin{align}\n    \\pdf{\\mbf{X}; \\mbfbar{X}, \\mbs{\\Sigma}} &= \n    \\mc{N}\\left( \\mbf{X}\\ominus\\mbfbar{X}, \\mbs{\\Sigma} \\right)\\\\\n    &=\n    \\label{eq:pdf of X in Lie group}\n    \\eta\\exp\\left(-\\f{1}{2}\\norm{\n        \\mbf{X}\\ominus\\mbfbar{X}\n    }_{\\mbs{\\Sigma}\\inv}^{2}\\right).\n\\end{align}\n\nLet\n\\begin{align}\n    \\mbfcheck{X}_{k} &\\coloneqq (\\mbfhat{X}_{k-1}\\rplus\\mbf{u}_{k-1}) \\oplus\\mbfrv{w}_{k-1},\n\\end{align}\nand let the measurement function be given by\n\\begin{align}\n    \\mbf{y}_{k} &= \\mbf{X}_{k}\\mbf{b} + \\mbfrv{n}_{k},\n\\end{align}\nwhere $\\mbf{b}$ is a know column matrix.\n\nTaking the above assumptions into consideration, and plugging \\eqref{eq:pdf of X in Lie group} into the MAP objective function \\eqref{eq:InEKF derivation:pdf Xhat given Xhatkm1 ukm1 yk} and taking the negative log, results in\n\\begin{align}\n    \\mbfhat{X}_{k} \n    &= \\argmax_{\\mbf{X}_{k}\\in G} \\pdf{\\mbf{y}_{k}\\mid \\mbf{X}_{k}}\\pdf{\\mbf{X}_{k}\\mid\\mbfhat{X}_{k-1}, \\mbf{u}_{k-1}}\\\\\n    &= \\argmin_{\\mbf{X}_{k}\\in G} \\f{1}{2}\\norm{\\mbf{y}_{k} - \\mbf{X}_{k}\\mbf{b}}^{2}_{\\mbf{R}\\inv} \n    + \\f{1}{2}\\norm{\n        \\mbf{X}_{k}\\ominus\\mbfcheck{X}_{k}\n    }^{2}_{\\mbfcheck{P}_{k}\\inv},\n\\end{align}\nwhich is a (nonlinear) least squares problem.\n\nThe optimization problem can be rewritten as\n\\begin{align}\n    \\label{eq:deriving InEKF: NLS et SigmaInv e}\n    \\mbfhat{X}_{k} &= \\argmin_{\\mbf{X}_{k}\\in G} \\f{1}{2}\\mbf{e}(\\mbf{X}_{k})^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{e}(\\mbf{X}_{k}),\n\\end{align}\nwhere\n\\begin{align}\n    \\label{eq:deriving InEKF: error function def}\n    \\mbf{e} &: G \\to \\rnums^{m},\\\\\n    \\mbf{e}(\\mbf{X}_{k}) &=\n    \\bbm\n        \\mbf{X}_{k} \\ominus \\mbfcheck{X}_{k}\\\\\n        \\mbf{X}_{k}\\mbf{b} - \\mbf{y}_{k}\n    \\ebm,\\\\\n    \\mbs{\\Sigma} &=\n    \\bbm\n        \\mbfcheck{P}_{k} & \\\\ & \\mbf{R}_{k}\n    \\ebm.\n\\end{align}\n\\begin{remark}\n    Note that the error function $\\mbf{e}$ is a mapping from the (Lie) group space $G$ to a the Lie algebra vector space $\\rnums^{m}$. That's the nice thing about Lie algebra; we can use the standard optimization tools on the Lie algebra Euclidean space.\n\\end{remark}\n\nThe optimization problem \\eqref{eq:deriving InEKF: NLS et SigmaInv e} can be solved using Gauss-Newton algorithm \\cite{Nocedal_Numerical_2006, Barfoot_State_2017, Dellaert_Factor_2017}.\n\nFirst, get an affine approximation of the error function \\eqref{eq:deriving InEKF: error function def} linearized around the operating point $\\mbfbar{X}_{k}$. To do so, define the perturbation \n\\begin{align}\n    \\mbf{d}_{k} &\\coloneqq \\mbf{X}_{k}\\ominus\\mbfbar{X}_{k},\\\\\n    \\label{eq:deriving InEKF: X_k = Xbar oplus dk}\n    \\mbf{X}_{k} &= \\mbfbar{X}_{k} \\oplus\\mbf{d}_{k},\n\\end{align}\n\\marginnote[-1cm]{The variable name $\\mbf{d}_{k}\\in\\rnums^{n_{x}}$ is chosen because it'll be used as a search direction in the optimization.}\naccording to the chosen error definition\\sidenote{That is, replace `$\\ominus$' and `$\\oplus$' with the appropriate definition such as `$\\liplus$'.}.\n\nThen, the affine approximation can be written as\n\\begin{align}\n    \\label{eq:InEKF derivation: error affine approx}\n    \\mbf{e}(\\mbf{X}_{k}) &= \\mbf{e}(\\mbfbar{X}_{k}\\oplus\\mbf{d}_{k})\\\\\n    &\\approx \\mbf{e}\\left( \\mbfbar{X}_{k}  \\right) + \\mbf{J}\\mbf{d}_{k},\n\\end{align}\nwhere $\\mbf{J}\\in\\rnums^{m\\times n}$ is the Jacobian of the error function with respect to the Lie algebra coordinates.\n\\sidenote{Basically, \n    \\begin{align}\n        \\mbf{J} &= \\pd{\\mbf{e}(\\mbfbar{X}_{k}\\oplus \\mbs{\\xi}_{k})}{\\mbs{\\xi}_{k}},\n    \\end{align}\n    where $\\mbs{\\xi}_{k}\\in \\rnums^{n_{k}}$ is the coordinates of the Lie algebra components.\n}\n\nPlugging the error affine approximation \\eqref{eq:InEKF derivation: error affine approx} into the objective function gives the quadratic\\sidenote{Quadratic in $\\mbf{d}_{k}$.} approximation\n\\begin{align}\n    \\tilde{J}(\\mbf{d}_{k}) &\\coloneqq\n    J(\\mbfbar{X}_{k}\\oplus\\mbf{d}_{k}) \\\\\n    &= \\f{1}{2}\\mbf{e}(\\mbfbar{X}_{k}\\oplus\\mbf{d}_{k})^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{e}(\\mbfbar{X}_{k}\\oplus\\mbf{d}_{k})\\\\    \n    &\\approx \\f{1}{2}\\left( \\mbf{e}\\left( \\mbfbar{X}_{k}  \\right) + \\mbf{J}\\mbf{d}_{k} \\right)^{\\trans}\\mbs{\\Sigma}\\inv\\left( \\mbf{e}\\left( \\mbfbar{X}_{k}  \\right) + \\mbf{J}\\mbf{d}_{k} \\right)\\\\\n    &= \\f{1}{2}\\mbf{d}_{k}^{\\trans}\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{J}\\mbf{d}_{k} + \\mbf{e}\\left( \\mbfbar{X}_{k} \\right)^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{J}\\mbf{d}_{k} + \\f{1}{2}\\mbf{e}\\left( \\mbfbar{X}_{k} \\right)^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{e}\\left( \\mbfbar{X}_{k} \\right).\n\\end{align}\nIf $\\mbf{J}$ is full column rank, then the quadratic function $\\tilde{J}$ is strongly convex and has a unique minimizer. The minimizer is given by solving\n\\begin{align}\n    \\label{eq:deriving InEKF: optimal search direction}\n    \\mbf{d}_{k}^{\\star} &= - \\left(\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{J}\\right)\\inv\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{e}(\\mbfbar{X}_{k}),\n\\end{align}\nwhere\n\\begin{align}\n    \\label{eq:deriving InEKF: Phat}\n    \\mbfhat{P}_{k} &= \\left(\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{J}\\right)\\inv\n\\end{align}\nat convergence \\cite{Barfoot_State_2017}.\n\nWe can try to solve for $\\mbf{d}_{k}$ analytically. \nSay the error function Jacobian is given by\n\\begin{align}\n    \\label{eq:deriving InEKF: Jacobian eye C}\n    \\mbf{J} &= \\bbm \\gamma\\eye \\\\ \\mbf{C}_{k}\\ebm,\n\\end{align}\nwhere $\\gamma = \\pm 1$ depends on the choice of the error definition.\n\n\\subsection{The Kalman gain}\nPlugging \\eqref{eq:deriving InEKF: Jacobian eye C} into \\eqref{eq:deriving InEKF: Phat} gives\n\\begin{align}\n    \\mbfhat{P}_{k}\\inv &= \\left(\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{J}\\right)\\\\\n    &= \n    \\mbfcheck{P}_{k}\\inv + \\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv\\mbf{C}_{k}.\n\\end{align}\nPre-multiplying by $\\mbfhat{P}_{k}$ gives\n\\begin{align}\n    \\eye \n    &= \\mbfhat{P}_{k}\\mbfcheck{P}_{k}\\inv + \\underbrace{\\mbfhat{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv}_{\\eqqcolon \\mbf{K}_{k}}\\mbf{C}_{k}\\\\\n    \\label{eq:deriving InEKF: eye = PhatPcheckinv + KkCk}\n    &=\\mbfhat{P}_{k}\\mbfcheck{P}_{k}\\inv + \\mbf{K}_{k}\\mbf{C}_{k},\n\\end{align}\nwhere $\\mbf{K}_{k}$ is the \\emph{Kalman gain}.\nSolving for $\\mbfhat{P}_{k}$ results in \n\\begin{align}\n    \\mbfhat{P}_{k} &= \\left( \\eye - \\mbf{K}_{k}\\mbf{C}_{k} \\right)\\mbfcheck{P}_{k}.\n\\end{align}\nPost-multiply by $\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv$ gives\n\\begin{align}\n    \\underbrace{\\mbfhat{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv}_{\\mbf{K}_{k}} &= \\left( \\eye - \\mbf{K}_{k}\\mbf{C}_{k} \\right)\\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv\\\\\n    \\mbf{K}_{k} &=  \\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv - \\mbf{K}_{k}\\mbf{C}_{k}\\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv\\\\\n    \\mbf{K}_{k}\\left( \\eye + \\mbf{C}_{k}\\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv  \\right) &= \\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv\n\\end{align}\nPost-multiply by $\\mbf{R}_{k}$\n\\begin{align}\n    \\mbf{K}_{k}\\left( \\mbf{R}_{k} + \\mbf{C}_{k}\\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\right) &= \\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}.\n\\end{align}\nFinally, the Kalman gain is given by\n\\begin{align}\n    \\mbf{K}_{k} &= \n    \\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans} \\underbrace{\\left( \\mbf{R} + \\mbf{C}_{k}\\mbfcheck{P}_{k}\\mbf{C}_{k}^{\\trans}\\right)\\inv}_{\\mbf{S}_{k}\\inv}.\n\\end{align}\n\n\\subsection{The search direction}\nPlugging the posterior covariance \\eqref{eq:deriving InEKF: Phat} into the optimal search direction \\eqref{eq:deriving InEKF: optimal search direction} results in\n\\begin{align}\n    \\mbf{d}_{k}^{\\star} &= - \\mbfhat{P}_{k}\\mbf{J}^{\\trans}\\mbs{\\Sigma}\\inv\\mbf{e}(\\mbfbar{X}_{k})\\\\\n    &=\n    -\\mbfhat{P}_{k} \\bbm \\gamma\\eye & \\mbf{C}_{k}^{\\trans} \\ebm \n    \\bbm \\mbfcheck{P}_{k}\\inv & \\\\ & \\mbf{R}_{k}\\inv \\ebm\n    \\bbm \\mbfbar{X}_{k}\\ominus \\mbfcheck{X}_{k} \\\\\\mbfbar{X}_{k}\\mbf{b} - \\mbf{y}_{k} \\ebm\n    \\\\\n    &= -\\mbfhat{P}_{k}\\left( \\gamma \\mbfcheck{P}_{k}\\inv\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv(\\mbfbar{X}_{k}\\mbf{b} - \\mbf{y}_{k})\\right)\\\\\n    &= -\\gamma\\mbfhat{P}_{k}\\mbfcheck{P}_{k}\\inv\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) - \\underbrace{\\mbfhat{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv}_{\\mbf{K}_{k}}(\\mbfbar{X}_{k}\\mbf{b} - \\mbf{y}_{k})\\\\    \n    &\\overset{\\star}{=} \n    -\\gamma\\left(\\eye - \\mbf{K}_{k}\\mbf{C}_{k}  \\right)\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) - \\underbrace{\\mbfhat{P}_{k}\\mbf{C}_{k}^{\\trans}\\mbf{R}_{k}\\inv}_{\\mbf{K}_{k}}(\\mbfbar{X}_{k}\\mbf{b} - \\mbf{y}_{k}) \\\\\n    &= -\\gamma\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\gamma\\mbf{K}_{k}\\mbf{C}_{k}\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) - \\mbf{K}_{k}\\left( \\mbfbar{X}_{k}\\mbf{b} - \\mbf{y}_{k} \\right)\\\\\n    &= -\\gamma\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{K}_{k}\\left(\\gamma \\mbf{C}_{k} \\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\left( \\mbf{y}_{k} - \\mbfbar{X}_{k}\\mbf{b}\\right)\\right)\\\\\n    &= -\\gamma\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{K}_{k}\\left(\\gamma \\mbf{C}_{k} \\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\left( \\mbf{y}_{k} - \\mbfbar{X}_{k}\\mbf{b}\\right)\\right)\\\\\n    &= -\\gamma\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{K}_{k}\\mbf{z}_{k}(\\mbfbar{X}_{k}),\n\\end{align}\n\\marginnote[-3.5cm]{$\\star$ From \\eqref{eq:deriving InEKF: eye = PhatPcheckinv + KkCk}, \n    \\begin{align}\n        \\mbfhat{P}_{k}\\mbfcheck{P}_{k}\\inv &= \\eye - \\mbf{K}_{k}\\mbf{C}_{k}.\n    \\end{align}\n}\nwhere \n\\begin{align}\n    \\label{eq:deriving InEKF: general innovation}\n    \\mbf{z}_{k}(\\mbfbar{X}_{k}) &= \\gamma\\mbf{C}_{k}\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{y}_{k} - \\mbfbar{X}_{k}\\mbf{b}\n\\end{align}\nis the innovation.\n\nFinally, using \\eqref{eq:deriving InEKF: X_k = Xbar oplus dk}, the posterior estimate is \n\\begin{align}\n    \\mbfhat{X}_{k}\n    &= \\mbfbar{X}\\oplus\\mbf{d}_{k}^{\\star}\\\\\n    \\label{eq:deriving InEKF: general update equation}\n    &= \\mbfbar{X}\\oplus\\left(-\\gamma\\left( \\mbfbar{X}_{k}\\ominus\\mbfcheck{X}_{k} \\right) + \\mbf{K}_{k}\\mbf{z}_{k}(\\mbfbar{X}_{k})\\right).\n\\end{align}\nNote that if the linearization point is defined as\n\\begin{align}\n    \\mbfbar{X}_{k} &\\coloneqq \\mbfcheck{X}_{k}, \n\\end{align}\nthen \nthe innovation \\eqref{eq:deriving InEKF: general innovation} simplifies to\n\\begin{align}\n    \\mbf{z}_{k}(\\mbfcheck{X}_{k}) &= \\mbf{y}_{k} - \\mbfbar{X}_{k}\\mbf{b},\n\\end{align}\nand the update equation \\eqref{eq:deriving InEKF: general update equation} becomes\n\\begin{align}\n    \\mbfbar{X}_{k} &= \\mbfcheck{X}_{k}\\oplus\\left( \\mbf{K}_{k}\\mbf{z}_{k}(\\mbfcheck{X}_{k}) \\right)\\\\\n    &= \\mbfcheck{X}_{k}\\oplus\\left( \\mbf{K}_{k}(\\mbf{y}_{k} - \\mbfcheck{X}_{k}\\mbf{b}) \\right).\n\\end{align}\nThis is the invariant extended Kalman filter correction.", "meta": {"hexsha": "6766cbb3d37cf864aff0b77e2d8b435be6bfecff", "size": 11298, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/sections/appendices.tex", "max_stars_repo_name": "aalbaa/cpp_kalman_filter", "max_stars_repo_head_hexsha": "4e7ec9f8dfafeeeecced92650f5b3a39c57e37ca", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 13, "max_stars_repo_stars_event_min_datetime": "2021-05-03T19:19:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T16:07:14.000Z", "max_issues_repo_path": "doc/sections/appendices.tex", "max_issues_repo_name": "aalbaa/cpp_kalman_filter", "max_issues_repo_head_hexsha": "4e7ec9f8dfafeeeecced92650f5b3a39c57e37ca", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2021-05-08T15:58:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-16T18:04:57.000Z", "max_forks_repo_path": "doc/sections/appendices.tex", "max_forks_repo_name": "aalbaa/cpp_kalman_filter", "max_forks_repo_head_hexsha": "4e7ec9f8dfafeeeecced92650f5b3a39c57e37ca", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2021-05-07T04:44:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-11T23:50:14.000Z", "avg_line_length": 55.112195122, "max_line_length": 276, "alphanum_fraction": 0.6252434059, "num_tokens": 4887, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787536, "lm_q2_score": 0.837619961306541, "lm_q1q2_score": 0.7543017201312875}}
{"text": "\\subsection{Law of Exponents}\r\nThe Law of Exponents is a set of rules for simplifying expressions that governs \r\nthe combination of exponents (powers).\r\nRecall that $\\sqrt[n]{~}$ denotes the $n$th root. \r\nFor example $\\sqrt[3]{8}=2$ represents that the cube root of $8$ is equal to $2$.\\\\\r\n\r\n\\begin{definition}{Law of Exponents}{ExponentRules1}\r\n{\\bf Definitions}\r\n\r\nIf $m,n$ are positive integers, then:\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item $x^n=x\\cdot x\\cdot\\ldots\\cdot x$ ($n$ times).\r\n\t\\item $x^0=1$, for $x\\neq 0$.\r\n\t\\item $\\ds{x^{-n}=\\frac{1}{x^n}}$, for $x\\neq 0$.\r\n\t\\item $x^{m/n}=\\sqrt[n]{x^m}$ or $\\left(\\sqrt[n]{x}\\right)^m$, for $x\\geq 0$.\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\r\n{\\bf Combining}\\\\\r\n\r\n\\hspace{4mm} 1. \\hspace{1mm} $x^ax^b=x^{a+b}$.\r\n\\hspace{0.5cm} 2. \\hspace{1mm}  $\\ds{\\frac{x^a}{x^b}=x^{a-b}}$, for $x\\neq 0$.\r\n\\hspace{0.5cm} 3. \\hspace{1mm}  $\\left(x^a\\right)^b=x^{ab}=x^{ba}=\\left(x^b\\right)^a$. \\\\\r\n\r\n%\\begin{multicols}{3}\r\n%\\begin{enumerate}\r\n%\t\\item $x^ax^b=x^{a+b}$.\r\n%\t\\item $\\ds{\\frac{x^a}{x^b}=x^{a-b}}$, for $x\\neq 0$.\r\n%\t\\item $\\left(x^a\\right)^b=x^{ab}=x^{ba}=\\left(x^b\\right)^a$.\r\n%\\end{enumerate}\r\n%\\end{multicols}\r\n\r\n{\\bf Distributing}\r\n\\begin{multicols}{2}\r\n\\begin{enumerate}\r\n\t\\item $(xy)^a=x^ay^a$, for $x\\geq 0$, $y\\geq 0$.\r\n\t\\item $\\ds{\\left(\\frac{x}{y}\\right)^a=\\frac{x^a}{y^a}}$, for $x\\geq 0$, $y>0$.\r\n\\end{enumerate}\r\n\\end{multicols}\r\n\\end{definition}\r\n\r\nIn the next example, the word \\ifont{simplify} means \\ifont{to make simpler} or to write the expression more compactly.\\\\\r\n\r\n\\begin{example}{Laws of Exponents}{LawsExponents}\\label{LawsExponents}\r\nSimplify the following expression as much as possible assuming $x,y>0$:\r\n$$\\frac{3x^{-2}y^3x}{y^2\\sqrt x}.$$\r\n\\vspace{-0.5cm}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nUsing the Law of Exponents, we have:\r\n$$\\def\\arraystretch{2.5}\r\n\\begin{array}{>{\\displaystyle}r>{\\displaystyle}c>{\\displaystyle}l>{\\displaystyle}l}\r\n\\frac{3x^{-2}y^3x}{y^2\\sqrt x} & = & \\frac{3x^{-2}y^3x}{y^2x^{\\frac{1}{2}}}, \r\n\t\t&\\mbox{since $\\ds\\sqrt x = x^{\\frac{1}{2}}$},\\\\\r\n~ & = & \\frac{3x^{-2}yx}{x^{\\frac{1}{2}}}, \r\n\t\t&\\mbox{since $\\ds\\frac{y^3}{y^2}=y$},\\\\\r\n~ & = & \\frac{3y}{x^{\\frac{3}{2}}}, \r\n\t\t&\\mbox{since $\\ds\\frac{x^{-2}x}{x^{\\frac{1}{2}}}=\\frac{x^{-1}}{x^{\\frac{1}{2}}} =x^{-\\frac{3}{2}}=\\frac{1}{x^{\\frac{3}{2}}}$},\\\\\r\n~ & = & \\frac{3y}{\\sqrt{x^3}}, \r\n\t\t&\\mbox{since $\\ds x^{\\frac{3}{2}}=\\sqrt{x^3}$}.\r\n\\end{array}$$\r\nAn answer of $3yx^{-3/2}$ is equally acceptable, and such an expression may prove to be computationally simpler, although a positive exponent may be preferred.\r\n\\end{solution}\r\n", "meta": {"hexsha": "46825db9f0b038b95a047f55b433c027001bfe71", "size": 2590, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1-review/1-1-2-law-of-exponents.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-2-law-of-exponents.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-2-law-of-exponents.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.2424242424, "max_line_length": 160, "alphanum_fraction": 0.6027027027, "num_tokens": 1071, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850075259039, "lm_q2_score": 0.8056321913146127, "lm_q1q2_score": 0.7543013423081126}}
{"text": "\\section{Matrix Calculus}\n\n\\subsection{Layout}\n\n\nThere are two different layout:\n\n\\begin{itemize}\n\t\\item \\cindex{numerator layout}:\n\t\t\\begin{equation}\n\t\t\\left [\n\t\t\\begin{matrix}\n\t\t\\nabla f \\\\\n\t\t\\nabla g\n\t\t\\end{matrix}\n\t\t\\right ]\n\t\t\\end{equation}\n\t\\item \\cindex{denominator layout}:\n\t\\begin{equation}\n\t\\left [\n\t\\nabla f ,\t\\nabla g\t\\right ]\n\t\\end{equation}\n\\end{itemize}\n\nnumerator layout is preferred.\n\n\n\\subsection{Jacobian Matrix}\nfor $\\mathbf{y}_{1 \\times m} = \\mathbf{f}(\\mathbf{x}_{1 \\times n})$, its \\cindex{Jacobian matrix} is:\n\n\\begin{equation}\n\t\\nabla{}_{\\mathbf{x}} \\mathbf{y} = \n\\frac{\\partial \\mathbf{y}}{\\partial \\mathbf{x}} = \\left [ \\begin{matrix}\n\t\\nabla f_1 (\\mathbf{x}) \\\\\n\t\\nabla f_1 (\\mathbf{x}) \\\\\n\t\\vdots \\\\\n\t\\nabla f_m (\\mathbf{x})  \n\\end{matrix} \\right ] = \\begin{pmatrix}\n    \\pd{f_1}{x} \\\\\n    \\\\\n    \\pd{f_2}{x} \\\\\n    \\vdots \\\\\n    \\pd{f_m}{x} \n    \\end{pmatrix} = \\left [ \\begin{matrix}\n\\frac{\\partial f_1({\\mathbf{x}})}{x_1} & \\frac{\\partial f_1({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial f_1({\\mathbf{x}})}{x_n} \\\\\n\\frac{\\partial f_2({\\mathbf{x}})}{x_1} & \\frac{\\partial f_2({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial f_2({\\mathbf{x}})}{x_n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots  \\\\\n\\frac{\\partial f_m({\\mathbf{x}})}{x_1} & \\frac{\\partial f_m({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial f_m({\\mathbf{x}})}{x_n}\n\\end{matrix} \\right ]\n\\end{equation}\n\n\\subsection{Element-wise binary operator}\n\nfor element-wise binary operator \n\\begin{equation}\n\t\\mathbf{y}= \\mathbf{f}(\\mathbf{w}) \\bigcirc \\mathbf{g}(\\mathbf{x})\n\\end{equation}\n\n$\\bigcirc$ could be $+,-,\\times\\footnote{called \\emph{hadamard product}}, \\div, max $. The gradient is:\n\n\\begin{equation}\n\t\\nabla{}_{\\mathbf{x}} \\mathbf{y} = \n\t\\left [ \\begin{matrix}\n\t\ty_1 \\\\\n\t\ty_2 \\\\\n\t\t\\vdots \\\\\n\t\ty_n\n\t\\end{matrix} \\right ] = \\left [ \\begin{matrix}\n\tf_1 (\\mathbf{w}) \\bigcirc g_1 (\\mathbf{x}) \\\\\n\tf_2 (\\mathbf{w}) \\bigcirc g_2 (\\mathbf{x}) \\\\\n\t\\vdots \\\\\n\tf_n (\\mathbf{w}) \\bigcirc g_n (\\mathbf{x})\n\\end{matrix} \\right ]\n\\end{equation}\n\nThe expanded matrix could be differentiated using Jacobian matrix.\n\n\\subsection{Vector Sum}\nVector sum operation $sum$ could be expressed as \n\\begin{equation}\n\ty = \\text{sum}\\Big (\\mathbf{f}(\\mathbf{x}) \\Big ) = \\sum_{i=1}^{n} f_i (\\mathbf{x})\n\\end{equation}\n\n$\\nabla \\mathbf{y}$ could be calculated as usual.\n\n\n\\subsection{Chain Rules}\n\nIn machine learning there are two ways of taking \\cindex{chain rules}:\n\\begin{itemize}\n\t\\item forward differentiation: $\\frac{dy}{dx} =\\frac{du}{dx} \\times \\frac{dy}{du}$\n\t\\item backward differentiation: $\\frac{dy}{dx}=\\frac{dy}{du} \\times \\frac{du}{dx}$\n\\end{itemize}\n\nBackward differentiation is preferred for matrix operation.\n\n\n\nThe full expression of $\\mathbf{y}=\\mathbf{f}(\\mathbf{g}(\\mathbf{x}))$ is:\n\n\\begin{equation}\n\\begin{aligned}\n\t\\nabla{}_{\\mathbf{x}} f &=  \\pd{\\mathbf{f}(\\mathbf{g}(\\mathbf{x}))}{\\mathbf{x}} \\\\\n\t&= \\pd{\\mathbf{f}}{\\mathbf{g}} \\times \\pd{\\mathbf{g}}{\\mathbf{x}} \\\\\n\t&= \\left [ \\begin{matrix}\n\\frac{\\partial f_1({\\mathbf{x}})}{g_1} & \\frac{\\partial f_1({\\mathbf{x}})}{g_2} & \\dots & \\frac{\\partial f_1({\\mathbf{x}})}{g_n} \\\\\n\\frac{\\partial f_2({\\mathbf{x}})}{g_1} & \\frac{\\partial f_2({\\mathbf{x}})}{g_2} & \\dots & \\frac{\\partial f_2({\\mathbf{x}})}{g_n} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots  \\\\\n\\frac{\\partial f_m({\\mathbf{x}})}{g_1} & \\frac{\\partial f_m({\\mathbf{x}})}{g_2} & \\dots & \\frac{\\partial f_m({\\mathbf{x}})}{g_n}\n\\end{matrix} \\right ]_{m \\times n}\n\\times % multiple another one\n\\left [ \\begin{matrix}\n\\frac{\\partial g_1({\\mathbf{x}})}{x_1} & \\frac{\\partial g_1({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial g_1({\\mathbf{x}})}{x_r} \\\\\n\\frac{\\partial g_2({\\mathbf{x}})}{x_1} & \\frac{\\partial g_2({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial g_2({\\mathbf{x}})}{x_r} \\\\\n\\vdots & \\vdots & \\ddots & \\vdots  \\\\\n\\frac{\\partial g_n({\\mathbf{x}})}{x_1} & \\frac{\\partial g_n({\\mathbf{x}})}{x_2} & \\dots & \\frac{\\partial g_n({\\mathbf{x}})}{x_r}\n\\end{matrix} \\right ]_{n \\times r}\n\\end{aligned}\n\\end{equation}\n", "meta": {"hexsha": "9bfd4f632902e96393a983269bf9b14d017d3c7b", "size": 3991, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/matrix/math.2.matrix_differentiation.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/matrix/math.2.matrix_differentiation.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/matrix/math.2.matrix_differentiation.tex", "max_forks_repo_name": "elvisren/machine-learning-notes", "max_forks_repo_head_hexsha": "d12ac08d30be4341776714ad895116a243ec026f", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-10-01T23:34:47.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T23:34:47.000Z", "avg_line_length": 33.2583333333, "max_line_length": 131, "alphanum_fraction": 0.6241543473, "num_tokens": 1594, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9362850093037731, "lm_q2_score": 0.8056321819811829, "lm_q1q2_score": 0.7543013350016708}}
{"text": "\\section{Level Curves}\r\n\\noindent\r\nWe can look at different cross sections of a surface $f(x,y)$ by looking at the equation $f(x,y) = c$ where $c \\in \\mathbb{R}$. This curve lives in the xy-plane and is called the C-level curve. We often visualize these curves in the $z=c$ plane as part of the surface. In higher dimensions, like $f(x,y,z)$, a C-level curve becomes a C-level surface.\r\n\r\n[INSERT IMAGES]\r\n\r\n\\noindent\r\nFor example, the C-level surface of $f(x,y,z) = e^{-\\left(x^2+y^2+z^2\\right)}$ is the sphere centered at the origin with radius $\\sqrt{-\\ln{c}}$: $x^2 + y^2 + z^ 2 =-\\ln{c}$.", "meta": {"hexsha": "af87115ec0b74f76aa0e1f0dd7965a8d62a37701", "size": 593, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/differentialMultivariableCalculus/levelCurves.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/levelCurves.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/levelCurves.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": 74.125, "max_line_length": 351, "alphanum_fraction": 0.6812816189, "num_tokens": 184, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009596336302, "lm_q2_score": 0.8244619220634457, "lm_q1q2_score": 0.7543010036772336}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      1 & 3 \\\\\n      5 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rrr}\n      1 & 0 & 2 \\\\\n      0 & 2 & 1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rrr}\n      2 & 1 & 0 \\\\\n      1 & 0 & 2 \\\\\n      0 & 3 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  and compute the following over $\\Z_{11}$:\n  \\begin{enumerate}\n  \\item $3A$,\n  \\item $A^2$,\n  \\item $AB$,\n  \\item $BC$,\n  \\item $C^{-1}$.\n  \\end{enumerate}\n\\end{ex}\n\n", "meta": {"hexsha": "e6a5d3fb743ba91e4b0a91e48bbe6f0f2661319a", "size": 537, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Matrices-MatrixArithmeticModP.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/exercises/Matrices-MatrixArithmeticModP.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/exercises/Matrices-MatrixArithmeticModP.tex", "max_forks_repo_name": "selinger/linear-algebra", "max_forks_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2020-11-09T11:12:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-30T16:23:12.000Z", "avg_line_length": 16.78125, "max_line_length": 43, "alphanum_fraction": 0.4674115456, "num_tokens": 234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9252299488452012, "lm_q2_score": 0.8152324848629215, "lm_q1q2_score": 0.7542775102666671}}
{"text": "\t\\subsubsection{Simulations for Fourier-Galerkin Method}\n\t\t\n\t\tFollowing the ideas in the previous section for the Fourier-Galerkin method, we will assume that the expansion of the solution of (\\ref{IVP_Burgers}) is as follows\n\t\t\\begin{align*}\n\t\t\tu(x, t) = \\displaystyle \\sum_{|n| \\leq \\infty} \\hat{u}_n (t) \\phi_n (x), \\hspace{2mm} \\hat{u}_n (t) = \\frac{1}{2 \\pi} \\left\\langle u (x, t), \\phi_n (x) \\right\\rangle,  \n\t\t\\end{align*}\n\t\tand as before $\\phi_n (x) = e^{inx}$. \\\\\n\t\n\t\tSimilarly, we consider the space $V_N = \\hat{B}_N \\cap H^2_p (\\mathcal{D})$ where we will look for its truncated expansion given by\n\t\t\\begin{align*}\n\t\t\tu_N (x, t) = \\displaystyle \\sum_{ |n| \\leq N } \\hat{u}_n (t) \\phi_n (x), \\hspace{2mm} \\hat{u}_n (t) = \\frac{1}{2 \\pi} \\left\\langle u (x, t), \\phi_n (x) \\right\\rangle, \n\t\t\\end{align*}  \n\t\twhich we are going to force to satisfy the following\n\t\t\\begin{align}\n\t\t\t\\left\\langle R_N, \\phi_n \\right\\rangle = \\left\\langle \\frac{\\partial u_N}{\\partial t} + \\frac{1}{2} (u_N^2)_x - \\alpha \\frac{\\partial^2 u_N}{\\partial x^2}, \\phi_n \\right\\rangle = 0, \\hspace{2mm}  \\hspace{2mm} \\phi_n \\in V_N, \\hspace{2mm} \\forall t > 0\n\t\t\\end{align}\n\t\tor equivalently\n\t\t\\begin{align*}\n\t\t\t\\displaystyle \\int_{I} \\frac{\\partial}{\\partial t} u_N (x, t) \\overline{\\phi_n (x)} dx = \\alpha \\int_{I} \\frac{\\partial^2}{\\partial x^2} u_N(x, t) \\overline{\\phi_n (x)} dx - \\int_{I} \\frac{1}{2} \\frac{\\partial}{\\partial x} \\left[ u_N(x, t) \\right]^2 \\overline{\\phi_n (x)} dx   \n\t\t\\end{align*}\n\t\tSince $u_N (x, t)$ and its derivatives are periodic in space, integrating by parts we obtain that\n\t\t\\begin{align*}\n\t\t\t\\displaystyle \\int_{I} \\frac{\\partial}{\\partial t} u_N (x, t) \\overline{\\phi_n (x)} dx = - \\alpha \\int_{I} \\frac{\\partial}{\\partial x} u_N(x, t) \\frac{\\partial}{\\partial x} \\overline{\\phi_n (x)} dx + \\int_{I} \\frac{1}{2} \\left[ u_N(x, t) \\right]^2 \\frac{\\partial}{\\partial x} \\overline{\\phi_n (x)} dx   \n\t\t\\end{align*} \n\t\t\n\t\tThen writing again as an inner product\n\t\t\\begin{align*}\n\t\t\t\\left\\langle \\frac{\\partial u_N}{\\partial t}, \\phi_n  \\right\\rangle = \\left\\langle - \\alpha \\frac{\\partial u_N}{\\partial x} + \\frac{1}{2} [u_N]^2, \\frac{\\partial \\phi_n}{\\partial x}  \\right\\rangle\n\t\t\\end{align*}\n\t\tand using the orthogonality $\\langle \\phi_l, \\phi_n \\rangle = 2 \\pi \\delta_{ln}$, for each $n$ fixed we have to\n\t\t\\begin{align*}\n\t\t\t\\left\\langle \\frac{\\partial u_N}{\\partial t}, \\phi_n  \\right\\rangle = \\left\\langle \\displaystyle \\sum_{ |l| \\leq N} \\frac{d \\hat{u}_l (t)}{dt} \\phi_l, \\phi_n  \\right\\rangle = 2 \\pi \\frac{d \\hat{u}_n (t)}{dt}\n\t\t\\end{align*}\n\t\t\n\t\t\\noindent and for the other terms\n\t\t\\begin{align*}\n\t\t\t\\left\\langle \\frac{\\partial u_N}{\\partial x} - \\frac{1}{2} [u_N]^2, \\frac{\\partial \\phi_n}{\\partial x}  \\right\\rangle = & \\alpha \\left\\langle - i \\displaystyle \\sum_{ |l| \\leq N} l \\hat{u}_l (t) \\phi_l, in \\phi_n \\right\\rangle \\\\\n\t\t\t&+ \\left\\langle\\frac{1}{2} \\left( \\sum_{ |p| \\leq N} \\hat{u}_p (t) \\phi_p \\right) \\left( \\sum_{ |q| \\leq N} \\hat{u}_q (t) \\phi_q \\right), in \\phi_n \\right\\rangle \\\\\n\t\t\t=&  - \\alpha n \\left\\langle  \\displaystyle \\sum_{ |l| \\leq N} l \\hat{u}_l (t) \\phi_l, \\phi_n \\right\\rangle - \\frac{in}{2} \\left\\langle \\sum_{ |p| \\leq N} \\sum_{ |q| \\leq N} \\hat{u}_p (t) \\hat{u}_q (t) \\phi_{p + q}, \\phi_n \\right \\rangle \\\\\n\t\t\t=& -2 \\pi \\alpha n^2 \\hat{u}_n (t) - in \\pi \\sum_{ p + q = n} \\hat{u}_p (t) \\hat{u}_q (t), \\hspace{2mm} |q|, |p| \\leq N.\n\t\t\\end{align*}\n\t\t\n\t\t\\noindent Therefore, using the linear transformation from $\\mathcal{D}_p = [0, 2 \\pi]$ to $\\mathcal{D} = [x_L, x_R]$ given by $x = P z + x_L$ to escalate the problem, where $P = \\frac{x_R - x_L}{2 \\pi}$ and $z \\in \\mathcal{D}_p$, we have the following system of nonlinear ordinary differential equations\n\t\t\\begin{align}\n\t\t\\label{Galerkin_Nonlinear}\t\n\t\t\t\\frac{d \\hat{u}_n (t)}{dt} = - \\alpha P^2 n^2 \\hat{u}_n (t) - \\frac{in}{2} P \\sum_{ p + q = n} \\hat{u}_p (t) \\hat{u}_q (t), \\hspace{2mm} |q|, |p| \\leq N, \n\t\t\\end{align}\n\t\tor equivalently\n\t\t\\begin{align*}\n\t\t\t\\frac{d \\hat{u}_n (t)}{dt} = - \\alpha P^2 n^2 \\hat{u}_n (t) - \\frac{in}{2} P \\sum_{|q| \\leq N} \\hat{u}_{n - q} (t) \\hat{u}_q (t), \\hspace{2mm} |n| \\leq N, \n\t\t\\end{align*}\n\t\twhich is solved using the initial condition of the original projected problem on the space $V_N$, that is,\n\t\t\\begin{align*}\n\t\t\t\\mathcal{P}_N u_0 = \\displaystyle \\sum_{|n| \\leq N} a_n \\phi_n (x), \\hspace{2mm} a_n = \\frac{1}{2 \\pi} \\langle u_0 (x), \\phi_n (x) \\rangle.   \n\t\t\\end{align*}\n\t\t\n\t\tThis problem can be treated in different ways and, in this work, we will develop it with the following approach. First, let's discard the terms $\\hat{u}_q$ such that $|q| > N$ on the right side of the equation above, to get the following\n\t\t\\begin{align*}\n\t\t\t\\frac{d \\hat{u}_n (t)}{dt} =  -\\alpha P^2 n^2 \\hat{u}_n (t) - \\frac{in}{2} P \\sum_{|q| \\leq N} \\hat{u}_{n - q} (t) \\hat{u}_q (t), \\hspace{2mm} |n - q| \\leq N , \n\t\t\\end{align*}\n\t\twhich is a system of $2N + 1$ equations. \\\\\n\t\t\n\t\tThere is a wide variety of numerical methods to solve the above problem, and since this is not linear, it is not easy to justify choosing an appropriate method, since advanced knowledge of numerical analysis is required to investigate its characteristics. The way to choose a candidate method is by investigating its numerical stability, which guarantees that the numerical solution does not explode towards infinity and that it is at least bounded. \\\\\n\t\t\n\t\tIn general, explicit methods are not suitable for nonlinear problems and are commonly handled by implicit methods. To show the implementation, and in addition to looking at its most relevant characteristics, we will solve the problem using Euler's implicit method. First, note that when $n = 0$ we have $\\hat{u}_0 (t) = \\hat{u}_0 (0)$, and that the nonlinear term involves the term $\\hat{u}_n$ only when $q = 0$. So, using the integrating factor $e^{\\lambda_n t}$ with $\\lambda_n = \\alpha P^2 n^2 + \\frac{in}{2} P \\hat{u}_0 (0) $ we can obtain the following formulation\n\t\t\\begin{align*}\n\t\t\t\\frac{d \\left[ e^{\\lambda_n t} \\right]  \\hat{u}_n (t)}{dt} = - \\frac{in}{2} P e^{ \\lambda_n t} \\left[ \\hat{u}_0 (0) \\hat{u}_n (t) + \\sum_{\\substack{|q|\\leq N \\\\ q \\neq 0, n}} \\hat{u}_{n - q} (t) \\hat{u}_q (t) \\right],\n\t\t\\end{align*}\t\n\t\tand its solution using implicit Euler\n\t\t\\begin{align*}\n\t\t\t\\hat{u}^{j+1}_n = e^{- \\lambda_n \\Delta t} \\left[ \\hat{u}^j_n - \\Delta t \\frac{in}{2} P \\sum_{\\substack{|q|\\leq N \\\\ q \\neq 0, n}} \\hat{u}^{j}_{n - q} \\hat{u}^{j}_q \\right] - \\Delta t \\frac{in}{2} P \\hat{u}_0 (0) \\hat{u}^{j+1}_n, \n\t\t\\end{align*}\n\t\tand then solving for the term $\\hat{u}^{j + 1}_n$ to obtain\n\t\t\\begin{align*}\n\t\t\t\\hat{u}^{j+1}_n &= \\frac{ e^{- \\lambda_n \\Delta t}}{ 1 + \\Delta t \\frac{in}{2} P \\hat{u}_0 (0) } \\left[ \\hat{u}^j_n - \\Delta t \\frac{in}{2} P \\sum_{\\substack{|q|\\leq N \\\\ q \\neq 0, n}} \\hat{u}^{j}_{n - q} \\hat{u}^{j}_q \\right].   \n\t\t\\end{align*}\t\n\t\t\n\t\tFurthermore, using this formulation repeatedly for each $j$ gives us\n\t\t\\begin{align}\n\t\t\\label{Galerkin_Euler}\n\t\t\t\\hat{u}^{j+1}_n &= \\left[ \\frac{ e^{- \\lambda_n \\Delta t}}{ 1 + \\Delta t \\frac{in}{2} P \\hat{u}_0 (0) } \\right]^{j+1} \\hat{u}^0_n - \\Delta t \\frac{in}{2} P \\sum_{k=1}^{j+1} \\left[ \\frac{ e^{- \\lambda_n \\Delta t}}{ 1 + \\Delta t \\frac{in}{2} P \\hat{u}_0 (0) } \\right]^{k}  \\sum_{\\substack{|q|\\leq N \\\\ q \\neq 0, n}} \\hat{u}^{j+1-k}_{n - q} \\hat{u}^{j+1-k}_q\n\t\t\\end{align}\n\t\tNow, we will proceed to describe the steps necessary to implement the method based on the above. The simulations we are going to show were based on the formulation (\\ref{Galerkin_Euler}), taking advantage of the fast Fourier transformation to calculate the coefficients $\\hat{u}_n$, since it allows us to go from physical space to the space of Fourier and conversely. Also, it is worth mentioning that the codes used in this work can be found at \\url{https://github.com/alanmatzumiya/pySpectralPDE.git}. \\\\ \n\t\t\n\t\tTo carry out these numerical experiments it was necessary to follow the following steps:\n\t\t\\begin{enumerate}\n\t\t\t\\item Set the intervals to consider, $[x_L, x_R]$ for physical space and $[t_0, t_f]$ for time, and give an initial condition function $u_0$. It is also necessary to choose the value of $N$, and another for the parameter $\\alpha$. \n\t\t\t\n\t\t\t\\item We proceed to calculate the points in the spatial grid where we want to obtain the solution, and for this, we define the points $z_i \\in [0, 2 \\pi]$ as\n\t\t\t\\begin{align*}\n\t\t\t\tz_i = \\frac{2 \\pi i}{N}, \\hspace{2mm} i = 0, 1, \\dots, N\n\t\t\t\\end{align*}\n\t\t\twhich are used to obtain the points $x_i \\in [x_L, x_R]$\n\t\t\t\\begin{align*}\n\t\t\t\tx_i = P z_i + x_L, \\hspace{2mm} P = \\frac{x_R - x_L}{2 \\pi}\n\t\t\t\\end{align*}\n\t\t\t\n\t\t\tTo obtain the points $t_j \\in [t_0, t_f]$, we define the sequence $j = 0, 1, \\dots, M$, for some positive $M$, and calculate the following\n\t\t\t\\begin{align*}\n\t\t\t\tt_j = t_0 + j \\Delta t, \\hspace{2mm} \\Delta t = \\frac{t_f - t_0}{M} \n\t\t\t\\end{align*}\n\t\t\t\n\t\t\tThe values $| n | = 0, 1, \\dots, N $ must be established to calculate $in, n^2$, which are required to approximate the derivatives.\n\t\t\t \n\t\t\t\\item Calculate the coefficients $\\hat{u}_0$ of the initial condition function $u_0$, using the fast Fourier transformation based on the already fixed spatial grid. So, it is possible to start the recursive rule given by (\\ref{Galerkin_Euler}) for every $t_j$.\n\t\t\t\n\t\t\t\\item Finally, the approximation obtained is evaluated using the equation given by\n\t\t\t\\begin{align*}\n\t\t\t\tu_N(x, t_j) = \\displaystyle \\sum_{|n| \\leq N} \\hat{u}_n (t_j) e^{inx}.\n\t\t\t\\end{align*}\n\t\t\\end{enumerate}\n\t\t\n\t\tFor the numerical study, we will establish the following initial condition\n\t\t\\begin{align}\n\t\t\t\\label{IC}\n\t\t\tu_0 (x) = e^{0.05 x^2}, \\hspace{3mm} x \\in [x_L, x_R] \n\t\t\\end{align}\t\n\t\t\n\t\tTo compare results, we will use the approximation given by (\\ref{Exact_Solution_Approximation}) as the exact solution. In the figure \\ref{Galerkin_alphas} shows the maximum distance over every $t \\in [0, 100]$ between the exact solution and its approximations given by (\\ref{Galerkin_Euler}) for $N = 2^m$, $m = 4, \\dots, 12$, $\\Delta t = 1.0 \\times 10^{-5}$, and different values of $\\alpha$. Furthermore, in Tables \\ref{Galerkin_tabla_L2_alpha=1} and \\ref{Galerkin_tabla_max_alpha=1}, we can see the numerical values ​​of these distances for different configurations of $N$ and $\\Delta t$. Similarly, in Tables \\ref{Galerkin_tabla_L2_alpha=005} and \\ref{Galerkin_tabla_max_alpha=005} but for $\\alpha = 0.005$.\n\t\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=15cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/galerkin/alphas_Error_N.png}\n\t\t\\caption{(a) $L^2$-norm between the exact solution and its approximations using Galerkin method. (b) Max norm between the exact solution and its approximations.}\n\t\t\\label{Galerkin_alphas}\n\t\\end{figure}\n\t\\newpage\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) with $\\alpha = 1.0$, $N=2048$, and $\\Delta t = 1.0 \\times 10^{-5}$.}\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/galerkin/Numerical_Solution_alpha=1.png}\n\t\t\\label{Galerkin_alpha=1}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) at the time $T = 100$ with $\\alpha = 1.0$, and $\\Delta t = 1.0 \\times 10^{-5}$. (b) Point-wise error of approximation}\n\t\t\\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/galerkin/Numerical_Solution_alpha=1_T=100.png}\n\t\t\\label{Galerkin_alpha=1_T}\n\t\\end{figure}\n\t\\begin{table}[H]\n\t\t\\begin{tabular}{lcccc}\n\t\t\t\\toprule\n\t\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 16 & 0.72504    & 0.72504    & 0.72504    & 0.72504    \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 32 & 6.90249 $\\times 10 ^{-2}$   & 6.88052 $\\times 10 ^{-2}$   & 6.87838 $\\times 10 ^{-2}$   & 6.87816 $\\times 10 ^{-2}$   \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 64 & 1.23827 $\\times 10 ^{-3}$  & 8.85367 $\\times 10 ^{-4}$ & 8.80521 $\\times 10 ^{-4}$ & 8.80410 $\\times 10 ^{-4}$  \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 128 & 9.43454 $\\times 10 ^{-4}$ & 9.41793 $\\times 10 ^{-5}$ & 9.41148 $\\times 10 ^{-6}$ & 9.41827 $\\times 10 ^{-7}$  \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 256 & 9.43454 $\\times 10 ^{-4}$ & 9.41793 $\\times 10 ^{-5}$ & 9.41109 $\\times 10 ^{-6}$ & 9.36411 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 512 & 9.43454 $\\times 10 ^{-4}$ & 9.41793 $\\times 10 ^{-5}$ & 9.41109 $\\times 10 ^{-6}$ & 9.36411 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 1024 & $\\ast$ & 9.41793 $\\times 10^{-5}$ & 9.41109 $\\times 10^{-6}$ & 9.36411 $\\times 10^{-7}$              \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 2048 & $\\ast$ & $\\ast$ & 9.41109 $\\times 10^{-6}$ & 9.36411 $\\times 10^{-7}$   \\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\\caption{Error using $L^2$-norm with $\\alpha = 1.0$}\n\t\t\\label{Galerkin_tabla_L2_alpha=1}\n\t\t\\vspace{1cm}\n\t\t\\begin{tabular}{lcccc}\n\t\t\t\\toprule\n\t\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 16 & 0.203363    & 0.203333    & 0.203331    & 0.20333     \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 32 & 2.64192 $\\times 10 ^{-2}$   & 2.6248 $\\times 10 ^{-2}$    & 2.62491 $\\times 10 ^{-2}$  & 2.62492 $\\times 10 ^{-2}$   \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 64 & 6.93001 $\\times 10 ^{-4}$ & 4.11641 $\\times 10 ^{-4}$ & 3.85563 $\\times 10 ^{-4}$ & 3.82972 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 128 & 4.74934 $\\times 10 ^{-4}$ & 4.73649 $\\times 10 ^{-5}$ & 4.74295 $\\times 10 ^{-6}$ & 5.16105 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 256 & 4.74936 $\\times 10 ^{-4}$ & 4.7368 $\\times 10 ^{-5}$  & 4.72569 $\\times 10 ^{-6}$ & 4.64922 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 512 & 4.74936 $\\times 10 ^{-4}$ & 4.7368 $\\times 10 ^{-5}$  & 4.72569 $\\times 10 ^{-6}$ & 4.64922 $\\times 10 ^{-4}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 1024 & * & 4.7368 $\\times 10 ^{-5}$  & 4.72569 $\\times 10 ^{-6}$ & 4.64922 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\midrule\n\t\t\t\\hspace{7mm} 2048 & * & * & 4.72569 $\\times 10 ^{-6}$ & 4.64922 $\\times 10 ^{-7}$ \\\\\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\t\\caption{Error using Max norm with $\\alpha = 1.0$}\n\t\t\\label{Galerkin_tabla_max_alpha=1}\n\t\\end{table}\n\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) with $\\alpha = 0.005$, $N=2048$, and $\\Delta t = 1.0 \\times 10^{-5}$.}\n\t\t\\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/galerkin/Numerical_Solution_alpha=0005.png}\n\t\t\\caption{Numerical solution for (\\ref{IVP_Burgers}) using (\\ref{Galerkin_Euler}) at the time $T = 100$ with $\\alpha = 1.0$, and $\\Delta t = 1.0 \\times 10^{-5}$. (b) Point-wise error of approximation}\n\t\t\\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/galerkin/Numerical_Solution_alpha=0005_T=100.png}\n\t\t\\label{Galerkin_alpha=005_T}\n\t\\end{figure}\n\t\n\t\\begin{table}[H]\n\t\\begin{tabular}{lcccc}\n\t\t\\toprule\n\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 16 & 9.95328   & 9.91901    & 9.91597    & 9.91567    \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 32 & 2.72607   & 2.70558    & 2.70347    & 2.70326    \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 64 & 2.50343   & 2.45988    & 2.45543    & 2.45497    \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 128 & 2.16142   & 2.06992    & 2.05918    & 2.05795    \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 256 & 1.3658    & 1.19385    & 1.17602    & 1.17412    \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 512 & 0.339826  & 0.265843   & 0.262164   & 0.261805   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 1024 & 0.161405  & 0.133743   & 0.131882   & 0.131699   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 2048 & 6.50292 $\\times 10^{-2}$ & 4.70602 $\\times 10^{-2}$ & 4.57371 $\\times 10^{-2}$  & 4.56090 $\\times 10^{-2}$  \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{Error using $L^2$-norm with $\\alpha = 0.005$}\n\t\\label{Galerkin_tabla_L2_alpha=005}\n\t\\vspace{1cm}\n\t\\begin{tabular}{lcccc}\n\t\t\\toprule\n\t\t\\multicolumn{1}{c}{\\textbf{Expansion}} & \\multicolumn{4}{c}{\\textbf{Error}} \\\\\n\t\t$\\hspace{9mm}N$ & $\\Delta t=1\\times 10^{-2}$ & $\\Delta t=1\\times 10^{-3}$ & $\\Delta t=1\\times 10^{-4}$ & $\\Delta t=1\\times 10^{-5}$ \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 16 & 2.50002  & 2.48992   & 2.48891   & 2.48881   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 32 & 1.21263  & 1.20544   & 1.2047    & 1.20463   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 64 & 1.21269  & 1.17736   & 1.17517   & 1.17495   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 128 & 1.10164  & 1.03493   & 1.03093   & 1.03048   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 256 & 0.954369 & 0.881472  & 0.873392  & 0.87259   \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 512 & 0.665071 & 0.418735  & 0.398664  & 0.396931  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 1024 & 0.241841 & 0.244188  & 0.244437  & 0.244461  \\\\\n\t\t\\midrule\n\t\t\\hspace{7mm} 2048 & 0.133067 & 0.104675  & 0.109151  & 0.109596  \\\\\n\t\t\\bottomrule\n\t\\end{tabular}\n\t\\caption{Error using Max norm with $\\alpha =0.005$}\n\t\\label{Galerkin_tabla_max_alpha=005}\n\t\\end{table}\n\t\n\t\\newpage\n", "meta": {"hexsha": "01eef1d158996a6aa8c2a92bf24c85ff0571797c", "size": 17330, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Galerkin.tex", "max_stars_repo_name": "alanmatzumiya/Maestria", "max_stars_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-12-29T10:44:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T11:18:45.000Z", "max_issues_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Galerkin.tex", "max_issues_repo_name": "alanmatzumiya/spectral-methods", "max_issues_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "docs/burgers_equation/deterministic/numerical_experiments/viscid/Viscid_Galerkin.tex", "max_forks_repo_name": "alanmatzumiya/spectral-methods", "max_forks_repo_head_hexsha": "c5e2a019312fb8f9bc193b04b07b7815e6ed4032", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2022-03-04T13:29:56.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T13:29:56.000Z", "avg_line_length": 69.0438247012, "max_line_length": 713, "alphanum_fraction": 0.6304096942, "num_tokens": 7098, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9334308110294983, "lm_q2_score": 0.8080672089305841, "lm_q1q2_score": 0.7542748301984182}}
{"text": "\\lab{Algorithms}{Poisson's equation}{Poisson's equation}\n\\label{lab:finitedifference2}\n\n % The basic idea behind finite difference methods is to replace a \n % differential operator, defined on some space of continuous functions, with a \n % difference operator defined on a finite vector space (i.e., a space of grid functions).\n % \n % To do this, we replace derivative terms in the differential equation with \n % appropriate difference expressions. \n % \n % \\begin{align*}\n % \tu_{xx}(t,x) &\\approx \\frac{(u(t,x+h)- 2u(t,x) + u(t,x-h))}{h^2},\\\\\n % \tu_x(t,x) & \\approx \\frac{u(t,x+h)-u(t,x-h)}{2h}.\n % \\end{align*}\n% Recall that the heat equation is given by $u_t = u_{xx} + f(x,t,u)$. \nSuppose that we want to describe the distribution of heat throughout a region $\\Omega$.\nLet $g(x)$ represent the temperature on the boundary of $\\Omega$ ($\\partial \\Omega$), and let $h(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\\section*{Poisson's equation in one dimension}\nThe 1D Poisson equation is given by \n\\begin{align}\n\t\\begin{split}\nu'' &= f(x), \\quad a \\leq x \\leq b,\\\\\n\tu(a) &= \\alpha,\\quad u(b) = \\beta,\n\t\\end{split} \\label{eqn:1d_poisson}\n\\end{align}\nwhere $f$ is continuous.\nWe will develop a finite difference method for solving this BVP. \n\nThe basic idea behind most numerical methods for differential equations is to approximate the exact solution $u(x)$ at some finite collection of points in the \ndomain of the problem.\nInstead of analytically solving an infinite-dimensional problem, we look for a simple finite collection of algebraic equations that approximate the original problem.\n\nNote that this equation can easily be solved by integrating twice and using the boundary conditions to determine the constants of integration.\nSolving this \\eqref{eqn:1d_poisson} is equivalent to solving the equation $\\triangle u = f,$ where $\\triangle = \\frac{d^2}{dx^2}$ is a differential operator defined on the infinite-dimensional space of functions $u:[a,b] \\to \\mathbb{R}$ that are twice continuously differentiable and satisfy the boundary conditions $u(a) = \\alpha$, $u(b) = \\beta$.\nThe finite difference method replaces infinite-dimensional differential operators with finite-dimensional difference operators.\n\nWe consider an approximate solution $\\{U_i\\}_{i=-1}^N$ on an evenly spaced grid of $N$ subintervals, $a = x_{-1}, x_0, \\ldots, x_{N-1} = b$ with $h = x_{i+1}-x_i$ for each $i$.\nRecalling that $\\frac{d^2}{dx^2}u(x) = \\frac{1}{h^2}\\left(u(x-h) -2u(x) + u(x+h)\\right) + \\mathcal{O}(h^2),$ we define the finite difference operator $D$ by  $DU_i = \\frac{1}{h^2}\\left(U_{i-1} -2U_i + U_{i+1}\\right)$.\nWe may discretize \\eqref{eqn:1d_poisson} using the equations \n\\begin{align*}\n\t\\frac{1}{h^2} (U_{i+1}- 2U_i + U_{i-1})  &= f(x_i), \\quad i = 0, \\ldots, N-2,\n\\end{align*}\nalong with boundary conditions $U_{-1} = \\alpha,$ $U_{N-1} = \\beta$.\nThis gives $N+1$ equations and $N+1$ unknowns, and can be written in matrix form as \n\\[ \\frac{1}{h^2} \\begin{bmatrix}h^2 & 0 &0&\\hdots &0 \\\\ 1 &-2 & 1 &\\hdots &0\\\\ \\vdots &  & \\ddots & &\\vdots \\\\\n0 & \\hdots & 1 & -2 & 1 \\\\ 0 & \\hdots & & 0 & h^2\n\\end{bmatrix} \\cdot \\begin{bmatrix}U_{-1}\\\\U_0\\\\ \\vdots \\\\U_{N-2} \\\\U_{N-1}\\end{bmatrix} = \\begin{bmatrix}f(x_{-1})\\\\f(x_0)\\\\ \\vdots \\\\ f(x_{N-2}) \\\\ f(x_{N-1}) \\end{bmatrix}\\]\nWe can further modify the system to obtain an $(N-1)\\times (N-1)$ tridiagonal matrix on the left: \n\\[\\frac{1}{h^2} \\begin{bmatrix}-2 & 1 &0 & \\hdots &0\\\\ 1 &-2 & 1 &\\hdots &0\\\\ \\vdots &  & \\ddots & &\\vdots \\\\ 0 & \\hdots & 1 & -2 & 1 \\\\\n0 & \\hdots & 0 & 1 & -2 \n\\end{bmatrix} \\cdot \\begin{bmatrix}U_0\\\\U_1\\\\ \\vdots \\\\U_{N-3}\\\\U_{N-2}\\end{bmatrix} = \\begin{bmatrix}f(x_0) -\\alpha/h^2 \\\\f(x_1)\\\\ \\vdots \\\\ f(x_{N-3})\\\\ f(x_{N-2})-\\beta/h^2 \\end{bmatrix}\\]\n\nThe following code uses this finite difference method to solve the BVP\n\\begin{align*}\nu'' &= -3 \\sin{x}, \\quad 0 \\leq x \\leq 2,\\\\\n\tu(0) &= -2,\\quad u(2) = 1\n\\end{align*}\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.sparse import spdiags\nfrom scipy.sparse.linalg import spsolve\n\ndef bvp(func, a, b, alpha, beta, N):\n    \"\"\" Solving u'' = f(x), x in [a, b],\n    u(a) = alpha, u(b) = beta\n    N = number of subintervals \"\"\"\n    \n    # We use the finite difference method to construct a system \n    # of algebraic equations described by the matrix equation \n    # AU = F\n    \n    # The length of each subinterval\n    h = (b - a) / N\n    \n    # Initialize and define the vector F on the right.\n    F = np.empty(N - 1)\n    F[0] = func(a + 1. * h) - alpha * h**(-2.)\n    F[N-2] = func(a + (N-1) * h) - beta * h**(-2.)\n    for j in xrange(1,  N-2): \n        F[j] = func(a + (j+1) * h)\n\n    # Here we define the arrays that will go on the diagonals of A.\n    data = np.empty((3, N-1))\n    # main diagonal\n    data[0,:] = -2. * np.ones((1, N-1))\n    # off-diagonals\n    data[1,:], data[2,:] = np.ones((1, N-1)), np.ones((1, N-1))\n    # Next we specify on which diagonals they will be placed\n    diags = np.array([0, -1, 1])\n    \n    A = h**(-2.) * spdiags(data, diags, N-1, N-1).asformat('csr')\n    \n    # We create and return the numerical approximation\n    U = np.empty(N + 1)\n    U[1:-1] = spsolve(A, F)\n    U[0], U[-1] = alpha, beta\n    return np.linspace(a, b, N+1), U\n\nx, y = bvp(lambda x:(-3. * np.sin(x)), a=0., b=2., alpha=-2., beta=1, N=30)\n\\end{lstlisting}\n\n\\begin{comment}\n\nHow do we know if a numerical approximation is reasonable?\nOne way to determine this is to compute solutions for various step sizes $h$ and see if the solutions are converging to something.\nTo be more specific, suppose our finite difference method is $\\mathcal{O}(h^p)$ accurate.\nThis means that the error $E(h) \\approx Ch^p$ for some constant $C$ as $h \\to 0$ (i.e., for $h>0$ small enough).\n \nSo compute the approximation $y_k$ for each stepsize $h_k$, $h_1 > h_2> \\ldots>h_m$.\nWe will think of $y_m$ as the true solution.\nThen the error of the approximation for \nstepsize $h_k, k < m,$ is \n\\begin{align*}\n\tE(h_k) &= \\max( \\abs{ y_k - y_m}) \\approx C h_k^p ,\\\\\n\t\\log(E(h_k)) &= \\log(C) + p \\log(h_k).\n\\end{align*}\nThus on a log-log plot of $E(h)$ vs. $h,$ these values should be on a straight line with slope $p$ when $h$ is small enough to start getting convergence. \n\nThe following code generates the log-log plot in \\ref{figure1}, and demonstrates second-order convergence for this finite difference approximation. \n\\begin{lstlisting}\nimport matplotlib.pyplot as plt\na, b = 0., 1.\nnum_approx = 10 # Number of Approximations\nN = np.array([5*2**j for j in range(num_approx)])\nh, max_error = (b-a)/N[:-1], np.ones(num_approx-1)\n\nmesh_best, num_sol_best = bvp(lambda x:-3.*np.sin(x), a, b, alpha=-2., beta=1, N=N[-1])\nfor j in range(len(N)-1): \n    mesh, num_sol = bvp(lambda x:-3.*np.sin(x), a, b, alpha=-2., beta=1, N=N[j])\n    max_error[j] = np.max(np.abs( num_sol- num_sol_best[::2**(num_approx-j-1)] ) )\nplt.loglog(h,max_error,'.-r',label=\"$E(h)$\")\nplt.loglog(h,h**(2.),'-k',label=\"$h^{\\, 2}$\")\nplt.xlabel(\"$h$\")\nplt.legend(loc='best')\nplt.show()\nprint \"The order of the finite difference approximation is about \", ( (np.log(max_error[0]) - \n    np.log(max_error[-1]) )/( np.log(h[0]) - np.log(h[-1]) ) ), \".\"\n\\end{lstlisting}\n\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=12cm]{example_convergence.pdf}\n\\caption{TODO}\n\\end{figure}\n\n\\end{comment}\n\n\\begin{problem}\nExtend the given finite difference code to the case of a general second order linear BVP with Dirichlet conditions:\n\\begin{align*}\n\t&{ } a_1(x)y'' +a_2(x)y'+ a_3(x) y = f(x), \\quad x \\in (a,b),\\\\\n\t&{ } y(a) = \\alpha, \\quad y(b) = \\beta.\n\\end{align*}\nUse your code to solve the singularly perturbed BVP\n\\begin{align}\n\t\\begin{split}\n\t&{ } \\epsilon y''(x)-y'= -1, \\quad x \\in (0,1), \\\\\n\t&{ } y(0) = 1, \\quad y(1) = 3,\n\t\\end{split} \\label{eqn:singular_perturbed_BVP}\n\\end{align}\nwith $\\epsilon = 1/10$.\nHow many subintervals are needed to obtain 4 digits of accuracy?\n\nHint: consider using a centered, forward, or backward differencing scheme to approximate $u'$.\n\n% If $\\alpha = 1$,  $\\beta = 3$, and $f(x) = -1$, there is an exact solution: \n% \\[y(x) = \\alpha + x+ (\\beta - \\alpha -1)\\frac{e^{x/\\epsilon -1}}{e^{1/\\epsilon -1}}\\]\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=12cm]{figure2.pdf}\n\\caption{The solution to \\eqref{eqn:singular_perturbed_BVP}.\nThe solution gets steeper near $x = 1$ as $\\epsilon $ gets small.}\n\\end{figure}\n\n\\section*{Poisson's equation in two dimensions}\n\n Consider Poisson's equation together with Dirichlet boundary conditions on a rectangular  domain $R = [a,b] x [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)\\triangle x, \\\\\n\ty_j &= c + (j+1)\\triangle y,\n\\end{align*}\nfor $i,j = 0, \\ldots, N-2$, where $\\triangle x = x_i-x_{i-1}, \\triangle y = y_i-y_{i-1}$.\nWe look for an approximation $U_{i,\\,j}$ on the grid $\\{(x_i,u_j)\\}_{i,j=-1}^{N-1}$.\n\nRecall that \n \\begin{align*}\n \\triangle u = u_{xx}(x,y) + u_{yy}(x,y) &= \\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 Then the set of equations  $\\triangle_h U_{ij} = f_{ij}$, $i,j = 0,\\ldots,N-2$ % $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\\[\\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}\\]\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\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, 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\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% \\begin{problem}\n% Find the solution $u$ of the 2D Laplace equation $\\Delta u = 0$ on the unit \n% square $[0,1]\\times [0,1] \\subset \\mathbb{R}^2,$ subject to the (Dirichlet) condition that \n% $u(x,y) = x^3$ on the boundary. \n% \t \n% Graph your solution, and demonstrate convergence of the numerical approximation by \n% creating a log-log plotof the error $E(h).$\n% \\end{problem}\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\n\\section*{Poisson's Equation and Conservative Forces}\n<<<<<<< HEAD\nIn physics Poisson's equation is used to describe the scalar potential of a conservative force (we'll explain what each of these terms mean).\nA conservative force $\\bold{F}(\\bold{r})$ is a vector function that obeys any of three equivalent conditions\n\\begin{enumerate}\n\t\\item The curl is identically zero\n\t\t\\[\\nabla \\times \\bold{F}(\\bold{r}) = 0\\]\n\t\\item It can be written as the negative of a gradient, called the scalar potential\n\t\t\\[\\bold{F}(\\bold{r}) = - \\nabla U(\\bold{r})\\]\n\t\\item The line integral over a closed path is zero\n\t\t\\[\\oint \\bold{F}(\\bold{r}) \\cdot d\\bold{r} = 0\\]\n\n\\end{enumerate}\n\\textit{Note: Letters in bold are vector quantities}\n\nThe scalar potential defined over the space is a measure of the potential energy a particle would have if placed at that point.\nIt could be electric potential energy, gravitational potential energy, or anything else governed by a conservative force.\n\nWhenever we have a conservative force we can use a few identities from vector calculus to obtain Poisson's equation for it's scalar potential. \nConsider for example the electrostatic force, the force that two electric charges exert on each other. \nIt can be summarized in two of Maxwell's four equations.\n\\[\\nabla \\times \\bold{E} = -\\frac{\\delta \\bold{B} } {\\delta t} \\qquad\n\\nabla \\cdot \\bold{E} = \\frac{\\rho}{\\epsilon_0}\\]\nWhere $\\bold{E}$ is the electric field, $\\bold{B}$ is the magnetic field, $\\rho$ the charge density, and $\\epsilon_0$ the permisivity of free space, a constant. $\\nabla \\times$ and $\\nabla \\cdot$ represent respectively the curl and the divergence operators. In the absence of a changing magnetic field the curl is zero and so we have a conservative force (although $\\bold{E}$ is not actually a force but a force per charge we can still treat it as a conservative field, proportionaly to a related conservative force). Because the curl is zero we can immediately assume the other properties of a conservative force and write $\\bold{E}$ as a gradient\n\\[\\bold{E}  = - \\nabla V = 0\\]\n$V$ is called the electrostatic scalar potential, more commonly known as the voltage. \nIf we insert this into the equation for the divergence of $E$ we find after the application of the identity $\\nabla \\cdot (\\nabla\\psi) = \\Delta \\psi$\n\\[\\nabla \\cdot ( - \\nabla V) = - \\Delta V = \\frac {\\rho}{\\epsilon_0}\\]\nWith this we have Poisson's equation for electrostatics. \nIf there are no charges ( or that the divergence of $E$ is zero), then this reduces to Laplace's equation. \nA similar analysis can be applied using Gauss's law of gravity (a reformulation of Newton's law of gravity in terms of a divergence) for a description of the gravitational scalar potential in terms of mass density.\n\nUnfortunately, because in most physical systems charges are free to roam, this electric potential feeds back into the system and changes the charge distribution. \nThis means that in reality $V$ is present on both sides of the equation.\nIn fact it is usually non-linear. \nHowever, in the following analysis, we'll assume that the charges are fixed in space, or \"frozen in\".\nWe'll also ignore all constants (specifically $\\epsilon_0$) and units so that we are really dealing with the relative charge.\n\nOne simple application of the electric potential is to calculate basic properties of simple molecules, starting from a charge distibution and from that calculating the electric potential field.\nWe'll assume that the electrons produce a clouds of charge centered around the atoms, appoximated by a Boltzmann Distribution $\\rho = q e^{-r}$, where $q$ is the relative charge of the atom and $r$ is the distance from the atom. \nTo make this easier, we'll make a function (\\li{rho1}) to calculate the $\\rho$ value at a certain point in space based the position of an atom and it's relative charge. \nWe'll make another function (\\li{rhoSum}) to give the total charge density at a point based on a list of atoms.\n\n\\begin{lstlisting}\n#definitions for atoms position and charges\n#the angle the hydrogen atoms make\ntheta = 106.0/180.0*np.pi\n#Length of the two branches\nA = 1.0\n# Hydrogen 1 (x0,y0,q)\n# Hydrogen 2 \n# Oxygen\nwater = ((-np.sin(theta / 2) * A, 0, 1),\n         (np.sin(theta / 2) * A, 0, 1),\n         (0, -np.cos(theta / 2) * A, -2))\n\ndef rho1(x, y, atom):\n    return atom[2] * np.exp(-np.sqrt((x - atom[0])**2 + (y - atom[1])**2))\n\ndef rhoSum(x,y,atoms):\n    return np.sum([rho1(x,y,atom) for atom in atoms],axis=0)\n\n# Generate a color dictionary for use with LinearSegmentedColormap.\n# It places red and blue at the min and max values of data\n# and white when data is zero.\ndef genDict(data):\n    zero = 1 / (1 - np.max(data) / np.min(data))\n    cdict = {'red':[(0.0,  1.0, 1.0),\n                   \t(zero,  1.0, 1.0),\n                   \t(1.0,  0.0, 0.0)],\n         'green':  [(0.0,  0.0, 0.0),\n                   \t(zero,  1.0, 1.0),\n                   \t(1.0,  0.0, 0.0)],\n         'blue':   [(0.0,  0.0, 0.0),\n                   \t(zero,  1.0, 1.0),\n                   \t(1.0,  1.0, 1.0)]}\n    return cdict\nX = np.linspace(-5, 5, 100)\nX, Y = np.meshgrid(X, X)\n# Generate the grid of rho values.\nRho = rhoSum(X, Y, water)\nplt.imshow(Rho, cmap =  mcolors.LinearSegmentedColormap('cmap', genDict(Rho)))\nplt.colorbar()\nplt.show()\n\\end{lstlisting}\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\n\\begin{figure}\n\\centering\n\\includegraphics[width=12cm]{waterRho.png}\n\\caption{Relative charge density of an H$_2$O molecule}\n\\end{figure}\n\nWith a function for $\\rho$, we can solve Poisson's equation for the electric potential field.\n\\begin{problem}\nSolve for the electric potential $V$\n\\[\\Delta V = -\\rho(x,y)\\]\nThe electric potential is usually defined to go to zero at inifinity.\nWe can approximate this using $V=0$ at the boundry conditions on $[-5,5]\\times [-5,5]$.\nSolve and plot the electric potential of water, using the definition for the atoms above.\n\n\\end{problem}\n\n\\begin{problem}\nSolve for the electric potential of a CO$_2$ molecule.\n\nCO$_2$ can be modeled as two atoms of relative charge $-1$ placed at $x=-1$ and $x=1$ on the $x$ axis and a third atom with relative charge $2$ at the origin.\nSimply reuse your code from the last problem with new definitions for the atoms using the template for a water molecule.\n\nIf the molecules are moving slowly (ie. when the temperature is low) electrostatic forces will dominate molecular interactions.\nMolecules will want to align themselves in the lowest energy configuration, or the lowest electric potential.\nPositive potentials will overlap themselves with negative potentials.\nFrom the electric potential plots you obtain, how do you think the molecules will arrange themselves when the temperature is cold, when they form an ice?\n\\end{problem}\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=12cm]{co2V.png}\n\\caption{Relative electric potential field of a CO$_2$ molecule}\n\\end{figure}", "meta": {"hexsha": "9cdd1dfdadd65505f68d6de9af85310b9ea0d468", "size": 22915, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Poisson/Poisson.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/Poisson/Poisson.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/Poisson/Poisson.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": 50.5849889625, "max_line_length": 648, "alphanum_fraction": 0.6560768056, "num_tokens": 7819, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070109242131, "lm_q2_score": 0.8289388125473628, "lm_q1q2_score": 0.7542572371640375}}
{"text": "\\section{Probabilistic Graphical Models}\nProbabilistic Graphical Models are models for which a graph can express the\nconditional dependence structure between random variables. We will define\nthe basics used to understand PGMs here. \\\\\nFor starters, a model is a set of probability distributions that may\nhave generated data. For example, a model could be the set of normal distributions\n\\begin{equation}\n  \\left\\{ p(x) : p(x) = \\frac{1}{\\sqrt{2\\pi \\sigma^2}} \\exp \\left( -\\frac{(x-\\mu)^2}{2\\sigma^2} \\right), \\mu \\in \\mathbb{R}, \\sigma^2 \\in \\mathbb{R}^+\\right\\}\n\\end{equation}\nA graphical model is defined to be a pair $(\\mathcal{G}, \\mathcal{P})$ where\n$\\mathcal{G}$ is a graph and $\\mathcal{P}$ is a set of distributions which\nfactorizes according to $\\mathcal{G}$. A graph $\\mathcal{G} = (\\mathbf{V}, \\mathbf{E})$\nconsists of a set of vertices $\\mathbf{V}$ and a set of edges $\\mathbf{E}$.\nTypically the vertices are random variables and the edges relate the random variables.\\\\\nWe say that random variable $X_i$ is conditionally independent of $X_j$ given a set of\nvariables $\\mathbf{Z}$, and write this as: $X_i \\indep X_j | \\mathbf{Z}$.\\\\\n\\subsection{Graphoid Axioms}\nSome properties of conditonal independence are as follows:\n\\begin{enumerate}\n  \\item $X_1 \\indep X_2 | \\mathbf{Z} \\implies X_2 \\indep X_1|\\mathbf{Z}$ (symmetry)\n  \\item $X_1 \\indep \\left( X_2, X_3 \\right) | \\mathbf{Z} \\implies X_1 \\indep X_2|\\mathbf{Z}$ (decomposition)\n  \\item $X_1 \\indep \\left( X_2, X_3 \\right) | \\mathbf{Z} \\implies X_1 \\indep X_2|\\left(\\mathbf{Z}, X_3\\right)$ (weak union)\n  \\item $X_1 \\indep X_2|\\left(\\mathbf{Z}, X_3\\right) \\,\\, \\& \\,\\, X_1 \\indep X_3 | \\mathbf{Z} \\implies X_1 \\indep \\left(X_2, X_3 \\right) | \\mathbf{Z}$ (contraction)\n  \\item $X_1 \\indep X_2 | \\left(\\mathbf{Z}, X_3\\right) \\,\\, \\& \\,\\, X_1 \\indep X_3 | \\left(\\mathbf{Z}, X_2\\right) \\implies X_1 \\indep \\left(X_2, X_3\\right)|\\mathbf{Z}$ (intersection, for positive distributions)\n\\end{enumerate}\n\\subsection{Bayesian Networks}\nBayesian Networks are a type of PGM constructed from directed acyclic graphs.\nA directed acyclic graph (DAG) is a graph $\\mathcal{G} = (\\mathbf{V}, \\mathbf{E})$\nsuch that $\\mathbf{E}$ contains only directed edges ($\\rightarrow)$ and there\ndoes not exist a sequence of directed edges from $X_i$ to $X_i$ for all nodes\nin the graph.\\\\\nDue to the structure of the DAG, we can factorize the joint distribution\n$p(\\mathbf{x})$ with respect to the graph as:\n\\begin{equation}\n  p(\\mathbf{x}) = \\prod_{i=1}^n p(x_i \\, | \\, pa(x_i, \\mathcal{G}))\n\\end{equation}\nHere, $pa(x_i, \\mathcal{G})$ are the parents of $x_i$ with respect to graph $\\mathcal{G}$.\\\\\nUsing this factorization, we can specify conditional independencies from the graph's structure.\nWe define three useful set construction operations for these networks:\n\\begin{equation}\n  \\begin{matrix}\n    an(x_i, \\mathcal{G}) \\equiv \\left\\{ x_j \\, | \\, x_j \\rightarrow \\cdots \\rightarrow x_i \\in \\mathcal{G} \\right\\} & (\\textrm{ancestors of } x_i)\\\\\n    de(x_i, \\mathcal{G}) \\equiv \\left\\{ x_j \\, | \\, x_j \\leftarrow \\cdots \\leftarrow x_i \\in \\mathcal{G} \\right\\} & (\\textrm{descendants of } x_i)\\\\\n    nd(x_i, \\mathcal{G}) \\equiv \\left\\{ x_j \\, | \\, x_j \\notin de(x_i, \\mathcal{G}) \\right\\} & (\\textrm{non-descendants of } x_i)\\\\\n  \\end{matrix}\n\\end{equation}\nA distribution $p(\\mathbf{x})$ satisfies the local Markov property wrt DAG\n$\\mathcal{G}$ if:\n\\begin{equation}\n  x_i \\indep nd^*(x_i, \\mathcal{G}) \\, | \\, pa(x_i, \\mathcal{G})\n\\end{equation}\nwhere $nd^*(x_i, \\mathcal{G}) \\equiv nd(x_i, \\mathcal{G}) \\setminus pa(x_i, \\mathcal{G})$\\\\\n\n\\subsection{Markov Random Fields}\n\\subsection{Exact Inference}\n\\subsection{Variational Inference}\n", "meta": {"hexsha": "a78ff0effd88b67bcce3ae543820deb3de49d695", "size": 3679, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "study_guide/sections/pgm.tex", "max_stars_repo_name": "nextBillyonair/StudyGuide", "max_stars_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-02-18T19:47:01.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-17T21:49:14.000Z", "max_issues_repo_path": "study_guide/sections/pgm.tex", "max_issues_repo_name": "nextBillyonair/StudyGuide", "max_issues_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "study_guide/sections/pgm.tex", "max_forks_repo_name": "nextBillyonair/StudyGuide", "max_forks_repo_head_hexsha": "3fbb85c1f738878935c18280d728ca7e92aa1414", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 64.5438596491, "max_line_length": 210, "alphanum_fraction": 0.6969285132, "num_tokens": 1298, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9099070084811306, "lm_q2_score": 0.8289388019824946, "lm_q1q2_score": 0.754257225525824}}
{"text": "% Section 3: Problem Background\n\n\\section{Problem Background}\n\nFor the present context it is sufficient to restrict ourselves to optimal transport on $\\mathbb {R}^d$. Let $X$,  $Y$ be subsets of $\\mathbb{R}^d$ and let $\\mu$ and $\\nu$ be probability measures on $X$ and $Y$, respectively. In this paper we will always have X = Y , but using different notation for domain and target space makes definitions easier to grasp.\n\nTransport map $T$ is any (measurable) map $X  \\rightarrow Y$ that transforms the measure $\\mu$ into the measure $\\nu$. More precisely it satis\ffies $\\mu(T^{-1}(B)) = \\nu(B)$ for every measurable $B \\subset Y$ . A transference plan is a measure $\\pi$ on $X \\times Y$ with marginals $\\pi(\\cdot \\times Y) = \\mu$ and $\\pi(X \\times \\cdot) = \\nu$. The set of transference plans from $\\mu$ to $\\nu$ is denoted by $\\Pi(\\mu, \\nu)$. Any transport map $T$ from $\\mu$ to $\\nu$ defines a transference plan $\\pi_T$ from $\\mu$ to $\\nu$ as the unique measure satisfying $\\pi_{T}(A \\times B)=\\mu\\left(A \\cap T^{-1}(B)\\right)$ for all measurable $A \\subset X$ and $B \\subset Y$. Not every transference plan $\\pi$ can be represented in this way, because transference plans allow mass from one site $x \\in X$ to be split between multiple destinations, which is not possible under a transport map. Figure 1 shows such an example.\n\n\\begin{figure}[htbp]\n  \\centering\n  \\includegraphics[width=0.8\\linewidth]{img/1d_ot}\n  \\label{fig:ot}\n  \\caption{Two one-dimensional distributions $\\mu$  and $\\nu$ , plotted on the x and y axes, and one possible joint distribution that defines a transport plan between them.}\n\\end{figure}\n\nWe assume that the cost of transporting a unit mass from $x \\in X$ to $y \\in Y$ is $c_p(x,y) = \\|x-y\\|^p$ for some $p \\geq 1$. The minimum cost for transferring $\\mu$ to $\\nu$ is then given by \n\n\\begin{equation}\n  C_p (\\mu, \\nu) = \\min_{x \\in \\Pi(\\mu,\\nu)} \\|x-y\\|^p d\\pi(x,y)\n\\end{equation}\n\nTaking the $p^{th}$ root, we obtain the Wasserstein metric $W_p$. More precisely we have \n\n\\begin{equation}\n  W_p(\\mu, \\nu) = C_p(\\mu, \\nu)^{1/p}\n\\end{equation}\n\nfor and measures $\\mu$ and $\\nu$ that satisfy $\\int_{X}\\|x\\|^{p} d \\mu(x)<\\infty$ adn $\\int_{Y}\\|y\\|^{p} d \\nu(y)<\\infty$. In order to evaluate the Wasserstein metric, we need to find an optimal solution to $C_p(\\mu,\\nu)$, i.e., a minimizing transference plan $\\pi$. This problem is often referred to as the Kantorovich formulation of optimal transport. Note that by Theorem 4.1 in [29] a minimizing always exists. However, it neither has to be unique nor representable in terms of an optimal transport map.\n\nOften one would like to compare data sets that are available as images from a certain source, e.g. real photography, astronomical imagery, or microscopy data. We may think of such images as discrete measures on a grid. For example, tiny clippings from STED microscopy images of mitochondrial networks. A question of interest might be whether both images stem from the same part of the network, which can in principle be answered by finding an optimal transference plan (third panel in Figure 1) and computing the Wasserstein distance. Note that this coarse resolution is not representative for a serious analysis, but was only chosen for illustrative purposes.\n\nAssume now that we have discrete measures of the form $\\mu = \\sum_{i=1}^m \\mu_i \\delta_{x_i}$ and $\\nu = \\sum_{j = 1}^n \\nu_i \\delta_{y_j}$ and write $c_{ij} = ||x_i - y_j||^p$. In what follows, we always have $m = n$, and $(x_i)_{1 \\leq i \\leq m} = (y_j)_{i\\leq j \\leq n}$ form a regular square grid in $R^2$, but since it is more intuitive, we keep different notation for source locations and target locations. Let $\\pi_{ij}$ be the amount of mass transported from $x_i$ to $y_j$. Then, the problem can be rewritten as a linear program: \n\n\\begin{equation}\n  \\begin{array}{rl}{\\mathrm{(primal)}} & {\\min_\\pi \\sum_{i=1}^{m} \\sum_{j=1}^{n} c_{i j} \\pi_{i j}} \\\\{\\text { subject to }} & {\\sum_{j=1}^{n} \\pi_{i j}=\\mu_{i},\\quad \\forall i=1, \\ldots, m} \\\\{} & {\\sum_{i=1}^{m} \\pi_{i j}=\\nu_{j},\\quad \\forall j=1, \\ldots, n} \\\\{} & {\\pi_{i j} \\geq 0}\\end{array}\n\\end{equation}\n\nNote that this primal form has $mn$ variables which leads to computational difficulties, we can deduct the dual form of this problem as:\n\n\\begin{equation}\n  \\begin{array}{rl}{\\mathrm{(dual)}} & {\\max _{u, v} \\sum_{i=1}^{m} \\mu_{i} u_{i}+\\sum_{j=1}^{n} \\nu_{j} v_{j}} \\\\{\\text { subject to }} & {c_{ij} - u_i - v_j \\geq 0\\qquad\\forall i=1, \\ldots, m \\quad j = 1,\\cdots,n}\\end{array}\n\\end{equation}\n\nThough only $m + n$ variables left, there still exist $mn$ constraints.", "meta": {"hexsha": "1a623565a9bcdb68bd5a6a56edc9bf1ed44285d3", "size": 4591, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/content-3.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-3.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-3.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": 104.3409090909, "max_line_length": 908, "alphanum_fraction": 0.6967980832, "num_tokens": 1414, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026641072387, "lm_q2_score": 0.8221891392358015, "lm_q1q2_score": 0.7541962878210381}}
{"text": "\\subsection{Damped Forced Vibrations ($b \\neq 0$)}\r\n\\noindent\r\nOur equation is \r\n\\begin{equation*}\r\n\tmy' + by' + ky = F_0\\cos{(\\gamma t)}.\r\n\\end{equation*}\r\nDepending on if $\\Delta = b^2 - 4mk$ is positive, zero, or negative, we'll get different results and thus different guesses for $y_p$ and thus different solutions.\r\nThere is, however, one long, complicated and not very useful for $y$.\r\n\\begin{equation*}\r\n\ty = C_1e^{\\frac{-b+\\sqrt{b^2-4mk}}{2m}t} + C_2e^{\\frac{-b-\\sqrt{b^2-4mk}}{2m}t} +\r\n\t \\frac{F_0\\left(b\\gamma\\sin{(\\gamma t)} + \\left(k-\\gamma^2m\\right)\\cos{(\\gamma t)}\\right)}{b^2\\gamma^2 + (k-\\gamma^2m)^2}.\r\n\\end{equation*}\r\nThe one useful thing this formula does tell us is that assuming $m$, $b$, $k$, $F_0$, and $\\gamma$ are all positive and non-zero, the exponential terms quickly decrease to 0, so in the limit the function looks like the particular solution part.\r\n\r\n\\begin{center}\r\n\t\\includegraphics[width=0.75\\textwidth]{./higherOrder/forcedVibrs/damped_forced.png}\r\n\\end{center}\r\n\r\n\\begin{example}\r\n\tSolve the following IVP.\r\n\t\\begin{equation*}\r\n\t\t\\begin{cases}\r\n\t\t\ty'' + 2y' + 10y = 5\\cos{(4t)} \\\\\r\n\t\t\ty(0) = 0 \\\\\r\n\t\t\ty'(0) = -2.6\r\n\t\t\\end{cases}\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\noindent\r\nSome of the work has been omitted for brevity.\r\n\r\n\\noindent\r\nSolving the auxiliary equation and finding $y_h$,\r\n\\begin{equation*}\r\n\tr^2 + 2r + 10 = 0 \\implies r = -1 \\pm 3i \\implies y_h = e^{-t}\\left(C_1\\cos{(3t) + C_2\\sin{(3t)}}\\right).\r\n\\end{equation*}\r\nGuessing the form of $y_p$, noting that $\\omega \\neq \\gamma$,\r\n\\begin{equation*}\r\n\ty_p = A\\cos{(4t)} + B\\sin{(4t)}.\r\n\\end{equation*}\r\nSolving for $A$ and $B$,\r\n\\begin{equation*}\r\n\ty_p'' + 2y_p' + 10y_p = 5\\cos{(4t)} \\implies A = -3/10 \\text{ and } B = 4/10.\r\n\\end{equation*}\r\nSolving for $C_1$ and $C_2$,\r\n\\begin{equation*}\r\n\t\\begin{cases}\r\n\t\ty(0) = 0 \\\\\r\n\t\ty'(0) = -2.6\r\n\t\\end{cases} \\implies C_1 = 3/10 \\text{ and } C_2 = -13/10.\r\n\\end{equation*}\r\nSo, we have a solution for $y$,\r\n\\begin{equation*}\r\n\ty = e^{-t}\\left(\\frac{3}{10}\\cos{(3t)} - \\frac{13}{10}\\sin{(3t)}\\right) + \\left(\\frac{-3}{10}\\cos{(4t)} + \\frac{4}{10}\\sin{(4t)}\\right).\r\n\\end{equation*}\r\nThe graph of this solution was shown above before the example.", "meta": {"hexsha": "064074aabec53abe4343137de770b6972c906c9d", "size": 2190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/higherOrder/forcedVibrs/dampedForcedVibrs.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "diffEq/higherOrder/forcedVibrs/dampedForcedVibrs.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "diffEq/higherOrder/forcedVibrs/dampedForcedVibrs.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 39.1071428571, "max_line_length": 245, "alphanum_fraction": 0.6347031963, "num_tokens": 849, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8221891261650248, "lm_q1q2_score": 0.7541962739724082}}
{"text": "\\chapter{Introduction}\n\n\\section{Types of machine learning}\n\\begin{equation}\\nonumber\n\\begin{cases}\n\\text{Supervised learning} \\begin{cases} \\text{Classification} \\\\ \\text{Regression} \\end{cases}\\\\\n\\text{Unsupervised learning} \\begin{cases} \\text{Discovering clusters} \\\\ \\text{Discovering latent factors} \\\\ \\text{Discovering graph structure} \\\\ \\text{Matrix completion} \\end{cases}\\\\\n\\end{cases}\n\\end{equation}\n\n\n\\section{Three elements of a machine learning model}\n\n\\textbf{Model = Representation + Evaluation + Optimization}\\footnote{Domingos, P. A few useful things to know about machine learning. Commun. ACM. 55(10):78–87 (2012).}\n\n\n\\subsection{Representation}\nIn supervised learning, a model must be represented as a conditional probability distribution $P(y|\\vec{x})$(usually we call it classifier) or a decision function $f(x)$. The set of classifiers(or decision functions) is called the hypothesis space of the model. Choosing a representation for a model is tantamount to choosing the hypothesis space that it can possibly learn. \n\n\n\\subsection{Evaluation}\nIn the hypothesis space, an evaluation function (also called objective function or risk function) is needed to distinguish good classifiers(or decision functions) from bad ones.\n\n\n\\subsubsection{Loss function and risk function}\n\\label{sec:Loss-function-and-risk-function}\n\n\\begin{definition}\nIn order to measure how well a function fits the training data, a \\textbf{loss function} $L:Y \\times Y \\rightarrow R \\geq 0$ is defined. For training example $(x_i,y_i)$, the loss of predicting the value $\\widehat{y}$ is $L(y_i,\\widehat{y})$.\n\\end{definition}\n\nThe following is some common loss functions:\n\\begin{enumerate}\n\\item 0-1 loss function \\\\ $L(Y,f(X))=\\mathbb{I}(Y,f(X))=\\begin{cases} 1, & Y=f(X) \\\\ 0, & Y \\neq f(X) \\end{cases}$\n\\item Quadratic loss function $L(Y,f(X))=\\left(Y-f(X)\\right)^2$\n\\item Absolute loss function $L(Y,f(X))=\\abs{Y-f(X)}$\n\\item Logarithmic loss function \\\\ $L(Y,P(Y|X))=-\\log{P(Y|X)}$\n\\end{enumerate}\n\n\\begin{definition}\nThe risk of function $f$ is defined as the expected loss of $f$:\n\\begin{equation}\\label{eqn:expected-loss}\nR_{\\mathrm{exp}}(f)=E\\left[L\\left(Y,f(X)\\right)\\right]=\\int L\\left(y,f(x)\\right)P(x,y)\\mathrm{d}x\\mathrm{d}y\n\\end{equation}\nwhich is also called expected loss or \\textbf{risk function}.\n\\end{definition}\n\n\\begin{definition}\nThe risk function $R_{\\mathrm{exp}}(f)$ can be estimated from the training data as\n\\begin{equation}\nR_{\\mathrm{emp}}(f)=\\dfrac{1}{N}\\sum\\limits_{i=1}^{N} L\\left(y_i,f(x_i)\\right)\n\\end{equation}\nwhich is also called empirical loss or \\textbf{empirical risk}.\n\\end{definition}\n\nYou can define your own loss function, but if you're a novice, you're probably better off using one from the literature. There are conditions that loss functions should meet\\footnote{\\url{http://t.cn/zTrDxLO}}:\n\\begin{enumerate}\n\\item They should approximate the actual loss you're trying to minimize. As was said in the other answer, the standard loss functions for classification is zero-one-loss (misclassification rate) and the ones used for training classifiers are approximations of that loss.\n\\item The loss function should work with your intended optimization algorithm. That's why zero-one-loss is not used directly: it doesn't work with gradient-based optimization methods since it doesn't have a well-defined gradient (or even a subgradient, like the hinge loss for SVMs has).\n\nThe main algorithm that optimizes the zero-one-loss directly is the old perceptron algorithm(chapter \\S \\ref{chap:Perceptron}).\n\\end{enumerate}\n\n\n\\subsubsection{ERM and SRM}\n\\begin{definition}\nERM(Empirical risk minimization)\n\\begin{equation}\n\\min\\limits _{f \\in \\mathcal{F}} R_{\\mathrm{emp}}(f)=\\min\\limits _{f \\in \\mathcal{F}} \\dfrac{1}{N}\\sum\\limits_{i=1}^{N} L\\left(y_i,f(x_i)\\right)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nStructural risk\n\\begin{equation}\nR_{\\mathrm{smp}}(f)=\\dfrac{1}{N}\\sum\\limits_{i=1}^{N} L\\left(y_i,f(x_i)\\right) +\\lambda J(f)\n\\end{equation}\n\\end{definition}\n\n\\begin{definition}\nSRM(Structural risk minimization)\n\\begin{equation}\n\\min\\limits _{f \\in \\mathcal{F}} R_{\\mathrm{srm}}(f)=\\min\\limits _{f \\in \\mathcal{F}} \\dfrac{1}{N}\\sum\\limits_{i=1}^{N} L\\left(y_i,f(x_i)\\right) +\\lambda J(f)\n\\end{equation}\n\\end{definition}\n\n\n\\subsection{Optimization}\nFinally, we need a \\textbf{training algorithm}(also called \\textbf{learning algorithm}) to search among the classifiers in the the hypothesis space for the highest-scoring one. The choice of optimization technique is key to the \\textbf{efficiency} of the model.\n\n\n\\section{Some basic concepts}\n\n\n\\subsection{Parametric vs non-parametric models}\n\n\n\\subsection{A simple non-parametric classifier: K-nearest neighbours}\n\n\\subsubsection{Representation}\n\\begin{equation}\ny=f(\\vec{x})=\\arg\\min_{c}{\\sum\\limits_{\\vec{x}_i \\in N_k(\\vec{x})} \\mathbb{I}(y_i=c)}\n\\end{equation}\nwhere $N_k(\\vec{x})$ is the set of k points that are closest to point $\\vec{x}$.\n\nUsually use \\textbf{k-d tree} to accelerate the process of finding k nearest points.\n\n\\subsubsection{Evaluation}\nNo training is needed.\n\n\\subsubsection{Optimization}\nNo training is needed.\n\n\n\\subsection{Overfitting}\n\n\n\\subsection{Cross validation}\n\\label{sec:Cross-validation}\n\\begin{definition}\n\\textbf{Cross validation}, sometimes called \\emph{rotation estimation}, is a \\emph{model validation} technique for assessing how the results of a statistical analysis will generalize to an independent data set\\footnote{\\url{http://en.wikipedia.org/wiki/Cross-validation_(statistics)}}.\n\\end{definition}\n\nCommon types of cross-validation:\n\\begin{enumerate}\n\\item K-fold cross-validation. In k-fold cross-validation, the original sample is randomly partitioned into k equal size subsamples. Of the k subsamples, a single subsample is retained as the validation data for testing the model, and the remaining k − 1 subsamples are used as training data.\n\\item 2-fold cross-validation. Also, called simple cross-validation or holdout method. This is the simplest variation of k-fold cross-validation, k=2.\n\\item Leave-one-out cross-validation(\\emph{LOOCV}). k=M, the number of original samples.\n\\end{enumerate}\n\n\n\\subsection{Model selection}\nWhen we have a variety of models of different complexity (e.g., linear or logistic regression models with different degree polynomials, or KNN classifiers with different values ofK), how should we pick the right one? A natural approach is to compute the \\textbf{misclassification rate} on the training set for each method.\n\n\n", "meta": {"hexsha": "7dedf6ad1cb1649b9c6871e69684a0b8b50ad704", "size": 6508, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mlapp/chapterIntroduction.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/chapterIntroduction.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/chapterIntroduction.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": 47.8529411765, "max_line_length": 375, "alphanum_fraction": 0.75829748, "num_tokens": 1767, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122313857378, "lm_q2_score": 0.8311430478583168, "lm_q1q2_score": 0.7541062533530725}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath}\n\n\\begin{document}\n\n\\section{Reparametrizing the Two Body Problem}\n\nWhen fitting radial velocity (RV) data for exoplanet or binary star systems, the\nRV model is typically expressed as:\n\\begin{equation}\n    v_r(t) = v_0 + K\\,\\left[\\cos(\\omega + f(t)) + e\\,\\cos(\\omega)\\right]\n\\end{equation}\nwhere $v_0$ is the systemic (barycentric) velocity of the system relative to the\nSun, $K$ is the velocity semi-amplitude, $\\omega$ is the argument of pericenter,\nand $f(t)$ is the True Anomaly. The True Anomaly is computed from the Mean\nAnomaly $M(t)$\n\\begin{equation}\n    M = \\frac{2\\pi}{P} \\, (t - t_{\\mathrm{peri}})\n\\end{equation}\nthrough a transcendental equation that relates the Mean Anomaly to the Eccentric\nAnomaly $E(t)$:\n\\begin{equation}\n    M = E - e\\,\\sin E\n\\end{equation}\nThe Eccentric Anomaly is related to the True Anomaly by:\n\\begin{align}\n    \\tan\\frac{f}{2} &= \\sqrt{\\frac{1+e}{1-e}} \\, \\tan\\frac{E}{2} \\\\\n    \\tan\\frac{E}{2} &= \\sqrt{\\frac{1-e}{1+e}} \\, \\tan\\frac{f}{2}\n\\end{align}\n\nIn the above parametrization, the full set of parameters is $(v_0, K, P, e,\n\\omega, t_{\\mathrm{peri}})$.\n\nAnother common representation of the Mean Anomaly is in terms of the phase of\npericenter $M_0$, which specifies the phase at which pericenter occurs in the\nangle defined by time relative to a reference time $t_{\\mathrm{ref}}$, which is\noften taken to be the minimum or mean observation time. So, an alternate\ndefinition of Mean Anomaly is:\n$$\n    M = \\frac{2\\pi}{P} \\, (t - t_{\\mathrm{ref}}) - M_0\n$$\nWith this convention, $t_{\\mathrm{peri}}$ is replaced by $M_0$ as a parameter so\nthe list of parameters is $(v_0, K, P, e, \\omega, M_0)$, but it is\nstraightforward to transform between $M_0$ and $t_{\\mathrm{peri}}$. In either\ncase, the Mean Anomaly is defined such at $M=0$ (mod $2\\pi$) occurs at\npericenter.\n\nTODO: discussion about how this is not a good parametrization for MCMC sampling,\nand history (Ford 2005).\n\n\\subsection{Replacing $\\omega, M_0$ with phase of max/min velocity}\n\nObserved phase of max/min radial velocity $M^*_{\\mathrm{max}},\nM^*_{\\mathrm{min}}$.\n\\begin{align}\nM^*_{\\mathrm{max}} &= \\frac{2\\pi}{P} \\, (t_{\\mathrm{max}} - t_{\\mathrm{ref}}) \\\\\nM^*_{\\mathrm{min}} &= \\frac{2\\pi}{P} \\, (t_{\\mathrm{min}} - t_{\\mathrm{ref}})\n\\end{align}\nNote: $M^*_{\\mathrm{max}}, M^*_{\\mathrm{min}}$ are not actually mean anomalies.\nThey are mean anomaly $+ M_0$, because what we observe are phases relative to\nthe reference time $t_{\\mathrm{ref}}$.\n\nSo, how do we relate these quantities to $(\\omega, M_0)$?\n\nAs far as I can figure, there is no direct, closed-form transformation, but I\nhave figured out a procedure to do the transformation in terms of a different\ntranscendental equation. This method is built on the intuition (guess) that the\nquantity\n\\begin{equation}\n    \\Delta M = M^*_{\\mathrm{min}} - M^*_{\\mathrm{max}}\n\\end{equation}\nwill be related to the argument of pericenter. Defining also\n\\begin{align}\n    \\Delta E &= E_{\\mathrm{min}} - E_{\\mathrm{max}} \\\\\n    \\Sigma E &= E_{\\mathrm{min}} + E_{\\mathrm{max}}\n\\end{align}\nwe can re-express the classic Kepler transcendental equation as\n\\begin{align}\n    \\Delta M &= \\Delta E - e\\, (\\sin E_{\\mathrm{min}} - \\sin E_{\\mathrm{max}})\\\\\n    \\frac{\\Delta M}{2} &= \\frac{\\Delta E}{2} - e\\, \\sin\\frac{\\Delta E}{2} \\, \\cos\\frac{\\Sigma E}{2}\n\\end{align}\nwhere the last line makes use of the `difference of sines' trig identity.\n\nUsing the relationship between $E$ and $f$,\n\\begin{align}\n    (E_{\\mathrm{min}} - E_{\\mathrm{max}})/2 =\n        \\arctan\\left[ \\sqrt{\\frac{1-e}{1+e}} \\,\n            \\tan \\frac{f_{\\mathrm{min}}}{2} \\right] -\n        \\arctan\\left[ \\sqrt{\\frac{1-e}{1+e}} \\,\n            \\tan \\frac{f_{\\mathrm{max}}}{2} \\right]\n\\end{align}\nHowever, we know the values of $f_{\\mathrm{min}}$ and $f_{\\mathrm{max}}$: From\nEquation (1), we know that the RV is maximum when $f=f_{\\mathrm{max}} \\equiv\n-\\omega$, and minimum when $f=f_{\\mathrm{min}} \\equiv \\pi-\\omega$.\nPlugging in these values and doing some trig algebra (using the difference of\narctan's trig identity), this simplifies to\n\\begin{align}\n    \\Delta E / 2 = \\arctan\\left(\\frac{\\sqrt{1 - e^2}}{e\\,\\sin\\omega}\\right)\n\\end{align}\nand similarly, for the sum of $E_{\\mathrm{min}} + E_{\\mathrm{max}}$,\n\\begin{align}\n    \\Sigma E / 2 = \\arctan\\left(\\frac{\\sqrt{1 - e^2}}{\\tan\\omega}\\right)\n        \\quad .\n\\end{align}\nSo, the relationship between $\\omega$, $e$, and $\\Delta M$ is defined by the\nexpression\n\\begin{align}\n    \\frac{\\Delta M}{2} &= \\frac{\\Delta E}{2} -\n        e\\, \\sin\\frac{\\Delta E}{2} \\, \\cos\\frac{\\Sigma E}{2} \\\\\n    % \\frac{\\Delta M}{2} &=\n    %     \\arctan\\left(\\frac{\\sqrt{1 - e^2}}{e\\,\\sin\\omega}\\right) -\n    %     \\,e \\,\n    %         \\sin\\left(\\arctan\\left(\\frac{\\sqrt{1 - e^2}}{e\\,\\sin\\omega}\\right)\\right) \\,\n    %         \\cos\\left(\\arctan\\left(\\frac{\\sqrt{1 - e^2}}{\\tan\\omega}\\right)\\right)\n    \\frac{M_{\\rm min} - M_{\\rm max}}{2} &=\n        \\arctan\\left( \\frac{\\sqrt{1 - e^2}}{e \\, \\sin\\omega} \\right) +\n        \\frac{2\\, e \\, \\sqrt{1 - e^2} \\, \\sin\\omega}{e^2 - 2 + e^2\\,\\cos(2\\omega)}\n\\end{align}\nand the phase $M_0$ can be retrieved with\n\\begin{align}\n    M_0 &= M^*_{\\mathrm{max}} - M_{\\mathrm{max}} \\\\\n    M_{\\mathrm{max}} &= E_{\\mathrm{max}} - e \\, \\sin E_{\\mathrm{max}} \\\\\n    E_{\\mathrm{max}} &= 2\\,\\arctan\\left(\\sqrt{\\frac{1-e}{1+e}} \\,\n        \\tan\\frac{f_{\\mathrm{max}}}{2}\\right) \\\\\n    &= -2\\,\\arctan\\left(\\sqrt{\\frac{1-e}{1+e}} \\,\n        \\tan\\frac{\\omega}{2}\\right) \\\\\n\\end{align}\n\n\\end{document}\n", "meta": {"hexsha": "74d7f7c7ebc6621d004a6a47dabe0e3f30fc95ab", "size": 5502, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/phase-at-rv-max-min.tex", "max_stars_repo_name": "adrn/kermit", "max_stars_repo_head_hexsha": "b31c83f7a6cfdd004bd8aa365b44ddff35022554", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2021-05-14T17:58:55.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-16T01:22:43.000Z", "max_issues_repo_path": "notes/phase-at-rv-max-min.tex", "max_issues_repo_name": "adrn/kermit", "max_issues_repo_head_hexsha": "b31c83f7a6cfdd004bd8aa365b44ddff35022554", "max_issues_repo_licenses": ["MIT"], "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/phase-at-rv-max-min.tex", "max_forks_repo_name": "adrn/kermit", "max_forks_repo_head_hexsha": "b31c83f7a6cfdd004bd8aa365b44ddff35022554", "max_forks_repo_licenses": ["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": 99, "alphanum_fraction": 0.6414031261, "num_tokens": 1935, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122163480667, "lm_q2_score": 0.8311430478583169, "lm_q1q2_score": 0.7541062408546169}}
{"text": "\\documentclass {article}\n\\usepackage[utf8]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{graphicx}\n\\usepackage{soul}\n\\begin{document}\n\n\\section{Solve graphically}\nFind two positive numbers that minimize the sum of twice the first number plus second if product of two is 288.\\\\\n\\\\\n- Assume that the first and second numbers are $a$ and $b$, respectively.\\\\\n- Using the given information, we already know:\\\\ \n\n\\begin{align*}\n\ta > 0 \\\\\n\tb > 0 \\\\\n\tab = 288 \\\\\n\tb=\\frac{288}{a} \\\\\n\tf(x)= 2a + b \\\\\n\tf(x)= 2a + \\frac{288}{a} \\\\\n\\end{align*}\n\nand we need to find out the number $a$ that minimizes the function:\\\\\n\n\\begin{align*}\n\tf(x)= 2a + \\frac{288}{a} \\\\\n\\end{align*}\n\n\\begin{figure}\n  \\includegraphics[width=\\linewidth]{graph1.png}\n  \\caption{Graph of $f(x)= 2a + \\frac{288}{a}$}\n\\end{figure}\n\nWe can tell from the below graph that f(x) has a local minimum of $(12,48)$ and since $a > 0$ in this case, it is also the global minimum of $f(x)$.\n\n\\begin{align*}\na = 12 \\\\\n\\\\\nb = \\frac{288}{a} \\\\\n\\\\\nb = \\frac{288}{12} \\\\\n\\\\\nb = 24 \\\\\n\\end{align*}\n\nThe two positive numbers the minimize the sum of twice the first number plus the second number if the product of the two is 288 is: $a = 12, b = 24$\\\\\nANSWER: $a = 12, b = 24$\n\n\\section{Solve algebraically}\nFind two positive numbers whose product is 750 and for which the sum of one and 10 times the other is a minimum.\\\\\n\\\\\n- Assume that the first and second numbers are $a$ and $b$, respectively.\\\\\n- Using the given information, we already know:\\\\ \n\n\\begin{align*}\n\ta > 0 \\\\\n\tb > 0 \\\\\n\tab = 750 \\\\\n\tb=\\frac{750}{a} \\\\\n\tf(x)= a+10b \\\\\n\tf(x)= a+\\frac{7500}{a}\\\\\n\\end{align*}\n\\\\\nTo algebraically determine the minimum in this case, we have to find which point on the function does its tangent line have a slope of zero. Although this sounds fairly complicated, this point is found by finding the derivative of the function and setting it equal to zero since the derivative $\\frac{d}{dx}$ represents rate of change at any given point and we're looking for a slope of zero at a particular point.\\\\\n\\\\\n\n\\begin{align*}\n\tf(a)=a + 7500a^{-1}\\\\\n\t\\frac{d}{da}f(a)=\\frac{d}{da}(a) + 7500*\\frac{d}{da}(a^{-1})\\\\\n\t\\frac{d}{da}f(a)=1+7500*(-a^{-2})\\\\\n\t\\frac{d}{da}f(a)=1+\\frac{-7500}{a^2}\\\\\n\t\\frac{d}{da}f(a)=0\\\\\n\t1+\\frac{-7500}{a^2}=0\\\\\n\t\\frac{-7500}{a^2}=-1\\\\\n\t-7500=(-a)^2\\\\\n\ta=50\\sqrt{3}\\\\\n\ta=-50\\sqrt{3} [rejected]\\\\\n\t\\\\\n\tb=\\frac{750}{50\\sqrt{3}}\\\\\n\tb=5\\sqrt{3}\n\\end{align*}\n\nThe answer to the question, \"What two positive numbers whose product is 750 and for which the sum of one and 10 times the other is a minimum?\" is: $a=50\\sqrt{3}, b=5\\sqrt{3}$.\n\n\n\\end{document}", "meta": {"hexsha": "0081153eb3b9efdb95e8d7555adaa0a8aa19cf86", "size": 2600, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "LateX/Calc-Optimization-Project-lh/untitled-3.tex", "max_stars_repo_name": "tacslouai/python", "max_stars_repo_head_hexsha": "87bdb6623440c4e6810c2a77df9f2b912ba16d5a", "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": "LateX/Calc-Optimization-Project-lh/untitled-3.tex", "max_issues_repo_name": "tacslouai/python", "max_issues_repo_head_hexsha": "87bdb6623440c4e6810c2a77df9f2b912ba16d5a", "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": "LateX/Calc-Optimization-Project-lh/untitled-3.tex", "max_forks_repo_name": "tacslouai/python", "max_forks_repo_head_hexsha": "87bdb6623440c4e6810c2a77df9f2b912ba16d5a", "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.2325581395, "max_line_length": 416, "alphanum_fraction": 0.6546153846, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467770088162, "lm_q2_score": 0.8577681104440172, "lm_q1q2_score": 0.7541040697178}}
{"text": "\\chapter{Inference for the mean}\n\\label{meaninf}\n\n\nWe introduced the Mahalanobis distance earlier in \\ref{standarddist}.   Consideration of the \\emph{squared} Mahalabnobis distance leads us to consider the so called T$^{2}$ statistic (the nomenclature reflects that this relates to a $t$-statistic for one variable). This can be found as:\n\n\\begin{equation}\n\\label{t2}\nT^{2} = n (\\boldsymbol{\\mu}_{0} - \\bar{\\boldsymbol{x}})^{T} \\boldsymbol{S}  (\\boldsymbol{\\mu}_{0} - \\bar{\\boldsymbol{x}})\n\\end{equation}\nwhere $n$ is the sample size, $\\boldsymbol{\\mu}_{0}$ is the hypothesised mean, $\\bar{\\boldsymbol{x}}$ and $\\boldsymbol{S}$ are the sample mean and covariance matrices respectively.    It turns out that this statistic follows a T$^{2}$ distribution, however, given that there is a simple relationship between the T$^{2}$ and $F$ distribution it is often easier to work with the latter.\n\n\n%turn this into a theorm ala flury 379, proof in Anderson and Seber (and muirhead\nIf $\\boldsymbol{x}_{i}$, $i = 1, \\ldots n$ represent a sample from a $p$ variate normal distribution with mean $\\boldsymbol{\\mu}$ and covariance $\\boldsymbol{\\Sigma}$, provided $\\boldsymbol{\\Sigma}$ is positive definite and $n > p$, given sample estimators for mean and covariance $\\bar{\\boldsymbol{x}}$ and $\\boldsymbol{S}$ respectively, then:\n\\begin{equation}\nF = \\left(\\frac{n}{n-1}\\right) \\left(\\frac{n-p}{p}\\right)  (\\boldsymbol{\\mu}_{0} - \\bar{\\boldsymbol{x}})^{T} \\boldsymbol{S}  (\\boldsymbol{\\mu}_{0} - \\bar{\\boldsymbol{x}})\n\\end{equation}\nfollows an $F$-distribution with $p$ and $(n-p)$ degrees of freedom.   Note the requirement that $n > p$, i.e. that $\\boldsymbol{S}$ is non-singular.   This clearly limits the use of this test in bio-informatic applications and we may examine a few proposals to deal with this.   To carry out a test on $\\boldsymbol{\\mu}$, we determine whether $F \\leq F_{(1-\\alpha),p,n-p}$, the $(1-\\alpha)$ quantile of the $F$ distribution on $p$ and $n-p$ degrees of freedom.   We reject the null hypothesis if our test statistic exceeds this value.   We will not consider the one sample T$^{2}$ test any further, but will now examine the two-sampled test.\n\n\\section{Two sample Hotelling's T$^{2}$  test}\n\\label{t2}\n\nAnalagous to the univariate context, we wish to determine whether the mean vectors are comparable, more formally:\n\\begin{equation}\nH_{0}: \\boldsymbol{\\mu}_{1} = \\boldsymbol{\\mu}_{2}\n\\end{equation}\n\nThe T$^{2}$ statistic proposed by \\cite{Hotelling:1931}, will be based this time on the distance between two mean vectors.   It can be calculated as:\n\n\\begin{equation}\n\\label{hotelling}\nT^{2} = \\left(\\frac{n_{1}n_{2}}{n_{1}+n_{2}}\\right)(\\boldsymbol{\\bar{x}_{1}} - \\boldsymbol{\\bar{x}_{2}})^{T}\\boldsymbol{S}^{-1}(\\boldsymbol{\\bar{x}_{1}} - \\boldsymbol{\\bar{x}_{2}})\n\\end{equation}\nwhere $S^{-1}$ is the inverse of the pooled correlation matrix given by:\n\\begin{displaymath}\n\\label{poolcov}\n\\boldsymbol{S} = \\frac{(n_{1} - 1) \\boldsymbol{S_{1}} + (n_{2} - 1) \\boldsymbol{S_{2}}}{n_{1} + n_{2} - 2}\n\\end{displaymath}\ngiven the sample estimates for covariance, $\\boldsymbol{S_{1}}$ and $\\boldsymbol{S_{2}}$ in the two samples.   As before, there is a simple relationship between the test statistic, $T^2$, and the $F$ distribution.   \n\n%make theorm flury 404, proof seber, anderson\nIf $\\boldsymbol{x}_{1i}$, $i = 1, \\ldots n_{1}$ and $\\boldsymbol{x}_{2i}$, $i = 1, \\ldots n_{2}$ represent independent samples from two $p$ variate normal distribution with mean vectors $\\boldsymbol{\\mu}_{1}$ and  $\\boldsymbol{\\mu}_{2}$ but with common covariance matrix $\\boldsymbol{\\Sigma}$, provided $\\boldsymbol{\\Sigma}$ is positive definite and $n > p$, given sample estimators for mean and covariance $\\bar{\\boldsymbol{x}}$ and $\\boldsymbol{S}$ respectively, then:\n\\begin{displaymath}\nF = \\frac{(n_{1} + n_{2} - p - 1) T^{2}}{(n_{1} + n_{2} - 2)p}\n\\end{displaymath}\nhas an $F$ distribution on $p$ and $(n_{1}+n_{2}-p-1)$ degrees of freedom.   Essentially, we compute the test statistic, and see whether it falls within the $(1-\\alpha)$ quantile of the F distribution on those degrees of freedom.   note again that to ensure non-singularity of $\\boldsymbol{S}$, we require that $n_{1}+n_{2} > p$.\n\nWhilst we won't use the next formula for computation, it may clarify understanding of this test if we consider the sample estimate of the mean difference $\\boldsymbol{d} = \\bar{\\boldsymbol{x}}_{1} - \\bar{\\boldsymbol{x}}_{2}$, and the corresponding population distance $\\boldsymbol{\\delta} = \\boldsymbol{\\mu}_{1} - \\boldsymbol{\\mu}_{2}$ we can use the formula:\n\\begin{displaymath}\nF = \\left( \\frac{n_{1} + n_{2} - p - 1}{p(n_{1} + n_{2} - 2)} \\right) \\left(\\frac{n_{1}n_{2}}{n_{1}+n_{2}} \\right) (\\boldsymbol{d} - \\boldsymbol{\\delta})^{T}\\boldsymbol{S}^{-1}(\\boldsymbol{d} - \\boldsymbol{\\delta})\n\\end{displaymath}\nto calculate the test statistic. \n\n\n\n\nWe are going to consider an example using data from Flea Beetles reported by \\cite{Lubischew:1962} and used in [page 307] \\cite{Flury:1997}.   It should be noted that in terms of practical computation, methods are based on the QR decomposition will be used, details are given in \\cite{Seber:1984}.   However, for the purposes of understanding the principles behind the test, we follow the formula directly.\n\n\n\\singlespacing\n\\begin{verbatim}\n> library(Flury)\n> ?flea.beetles\n> data(flea.beetles)\n\\end{verbatim}\n\\onehalfspacing\n\nIt can be seen that there is a factor ``Species'' denoting whether the beetles are from 'oleracea' or 'carduorum'.   There are four numeric variables as follows: 'TG'; Distange of the Transverse Groove to the posterior border of\n          the prothorax (microns), 'Elytra'; Length of the Elytra (in units of 0.01mm), 'Second.Antenna'; Length of the second antennal joint (microns) and 'Third.Antenna'; Length of the third antennal joint (microns).   We need to estimate the mean for each sample, and calculate the difference between the two vectors:\n\\singlespacing\n\\begin{verbatim}\nmu <- by(flea.beetles[,-1], flea.beetles$Species, colMeans)\nmudiff <- mu[[1]] - mu[[2]]\np <- dim(flea.beetles)[2] - 1 ## how many variables are we using\n\\end{verbatim}\n\\onehalfspacing\n\nThe next step is to extract the two covariance matrices:\n\n\\singlespacing\n\\begin{verbatim}\n> covmats <- by(flea.beetles[,-1], flea.beetles$Species, cov)\n> covmats\n\\end{verbatim}\n\\onehalfspacing\nand then to estimate the pooled covariance matrix $\\boldsymbol{S}$ for the flea beetle data (where N[1] gives $n_{1}$,  N[2] gives $n_{2}$), can be calculated as:\n\n\\singlespacing\n\\begin{verbatim}\n> N <- xtabs(~flea.beetles[,1])\n> pooledS <- ((N[1]-1) * covmats[[1]] + (N[2]-1) * covmats[[2]]) / (N[1] + N[2] -2)\n> pooledS\n> Sinv <- solve(pooledS)\n> Sinv\n                         TG        Elytra Second.Antenna Third.Antenna\nTG              0.013257964 -0.0053492256   0.0015134494 -0.0021617878\nElytra         -0.005349226  0.0066679441  -0.0047337699 -0.0005969439\nSecond.Antenna  0.001513449 -0.0047337699   0.0130490933 -0.0007445297\nThird.Antenna  -0.002161788 -0.0005969439  -0.0007445297  0.0060093005\n\\end{verbatim}\n\\onehalfspacing\n\nHaving calculated the inverse of the pooled correlation matrix we also need the scaling factor $\\frac{n_{1} n_{2}}{n_{1} + n_{2}}$.   Hotellings T$^{2}$ is then quite straightforward to calculate:\n\n\n\\singlespacing\n\\begin{verbatim}\n> scaleFact <- (N[1]*N[2]) / (N[1]+N[2])\n> Hotellings <-  t(mudiff) %*% Sinv %*% mudiff * scaleFact\n> Hotellings\n         [,1]\n[1,] 133.4873\n\\end{verbatim}\n\\onehalfspacing\nwhich is the value of the T$^{2}$ statistic.   We could work with this value directly, but it is more convenient to transform it into something we can compare with the $F$ distribution.\n\\singlespacing\n\\begin{verbatim}\ntest <- ((N[1] + N[2] - p - 1) * Hotellings )/ ((N[1] + N[2] - 2) * p)\ntest\n       [,1]\n[1,] 30.666\n\\end{verbatim}\n\\onehalfspacing\n\nand we compare this with an $F$ distribution having $p$ and $(n_{1} + n_{2} - p - 1)$ d.f.\n\nAnd we can check this as follows:\n\\singlespacing\n\\begin{verbatim}\n> pf(test, p, N[1]+N[2]-p-1,lower.tail = FALSE )\n             [,1]\n[1,] 3.215324e-11\n\\end{verbatim}\n\\onehalfspacing\nwhich gives us the area under the curve from our test statistic ($30.666$) to $\\infty$.   Clearly in this case, we have reject H$_{0}$, i.e. there is evidence that the mean vectors, $\\bar{\\boldsymbol{x}}_{oleracea} = (194.4737, 267.0526, 137.3684, 185.9474), \\bar{\\boldsymbol{x}}_{carduorum} = (179.55, 290.80, 157.20, 209.25)$, \n for the two species differ.   This is perhaps no surprise if you consider the data.   Figure \\ref{lubishew} contains a scatterplot where different symbols have been used in the lower panels for the two species.   However, we do need to consider this in a little more detail.  \n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = 0.6\\textwidth]{images/lubishew}\n\\caption{Scatterplot for Lubischew flea data, lower panel has symbols denoting the two species}\n\\label{lubishew}\n\\end{center}\n\\end{figure}\n\n\n\n\\section{Constant Density Ellipses}\n\\label{cdellipse}\n\n\\cite{Flury:1997} gives an interpretation of constant density ellipses in terms of the Mahalanobis distance which is worth reading.   Essentially, we wish to find a region of squared Mahlanobis distance such that:\n\\begin{displaymath}\nPr \\left( (\\boldsymbol{\\bar{x}} - \\boldsymbol{\\mu})^{T} \\boldsymbol{S}^{-1} (\\boldsymbol{\\bar{x}} - \\boldsymbol{\\mu}) \\right) c^{2}) \n\\end{displaymath}\nand we can find $c^{2}$ as follows:\n\\begin{displaymath}\nc^{2} = \\left( \\frac{n-1}{n} \\right) \\left( \\frac{p}{n-p} \\right) F_{(1-\\alpha), p, (n-p)}\n\\end{displaymath}\nwhere $F_{(1-\\alpha), p, (n-p)}$ is the $(1-\\alpha)$ quantile of the $F$ distribution with $p$ and $n-p$ degrees of freedom, $p$ represents the number of variables and $n$ the sample size.\n\n\nThis illustration is based on, but differs from code provided by Marco Bee to accompany and will make much more sense if used in conjunction with that book.   It is worth checking how and why this code differs!   Firstly, we need a function to draw ellipses:\n\n\\singlespacing\n\\begin{verbatim}\nellipse <- function(covmat, centroid, csquare, resolution, plot = TRUE) {\nangles <- seq(0, by = (2 * pi)/resolution, length = resolution)\n  sd <- covmat[1,2] / sqrt(covmat[1,1] * covmat[2,2])\n    projmat <- matrix(0,2,2)\n    projmat[1,1] <- sqrt(covmat[1,1] %*% (1+sd)/2)\n    projmat[1,2] <- -sqrt(covmat[1,1] %*% (1-sd)/2)\n    projmat[2,1] <- sqrt(covmat[2,2] %*% (1+sd)/2)\n    projmat[2,2] <- sqrt(covmat[2,2] %*% (1-sd)/2)\ncircle <- cbind(cos(angles), sin(angles))\nellipse <- t(centroid + sqrt(csquare) * projmat %*% t(circle))\nif (plot == TRUE) {lines(ellipse)}\nreturn(ellipse)\n}\n\\end{verbatim}\n\\onehalfspacing\n\nIt is possible to define a function which calculates $c^{2}$ and calls the ellipse routine (I'm not completely convinced this is doing the calculation correctly yet, in particular I'm not sure I'm using the correct tail).\n\n\\singlespacing\n\\begin{verbatim}\nfunction (data, alpha=0.05, resolution=500) \n{\nxbar <- colMeans(data)\nn <- dim(data)[1]\np <- dim(data)[2]\nf <- qf(1-alpha, p, n-p)\ncsquare <- ((n-1)/n) * (p / (n-p)) * f\ncat(csquare) \nellipse <- ellipse(cov(data), xbar, csquare, resolution)\n}\n\\end{verbatim}\n\\onehalfspacing\n\n%# call procedure ellips\n\n%X <- ellips(A, m, const, k)               \n\n%# graph the results\n\nFor illustrative purposes, we'll create a $n \\times 2$ data object from our flea beetles, and plot the confidence ellipse for these.\n\n\\singlespacing\n\\begin{verbatim}\nX <- cbind(flea.beetles[,2], flea.beetles[,3])\nplot(X)\ncdellipse(X, alpha = 0.01)\ncdellipse(X, alpha = 0.05)\n\\end{verbatim}\n\\onehalfspacing\n\n\nThese can be contrasted with the univariate confidence intervals:\n\n\\singlespacing\n\\begin{verbatim}\nabline(v = confint(lm(X[,1]~1)))\nabline(h = confint(lm(X[,2]~1)))\n\\end{verbatim}\n\\onehalfspacing\n\nThis exercise should be repeated with the turtles data!   However, it is possible to illustrate the basic idea with the sibling heads data, where we construct two derivative variables indicating the difference in head breadth and the difference in head width.   These are plotted in figure \\ref{cdellipse}, it can be seen that the univariate confidence intervals and the constant density ellipse support different areas of parameter space.   Ignoring the correlation structure in these data could lead to flaws in inference when assessesing parameter uncertainty.\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[width = 0.5\\textwidth]{images/cdellipse}\n\\caption{Constant density ellipse for mean vector for difference in head width and breadth, and univariate confidence intervals for the mean of each variable}\n\\label{cdellipse}\n\\end{center}\n\\end{figure}\n\n\n\n% X <- sibling.heads\n%Y <- cbind((X[, 1] - X[, 3]),(X[, 2] - X[, 4]))\n%plot(Y, main = \"Contrasts in sibling head measurements\", xlab = \"Difference in length\", ylab = \"Difference in breadth\", pch = 16)\n%X <- Y\n%cdellipse(X)\n%abline(v = confint(lm(X[,1]~1)))\n%abline(h = confint(lm(X[,2]~1)))\n\n\n%\\section{Likelihood ratio tests}\n%\\label{lrt}\n\n%\\section{Profile analysis}\n%\\label{profile}\n\n%\\section{Confidence regions}\n%\\label{confR}\n\n%\\section{Multivariate analysis of variance}\n%\\label{manova}\n\n%\\section{Multivariate regression}\n%\\label{mvreg}\n\n%\\section{Shrinkage of parameters in multivariate regression}\n%\\label{shrinkage}\n\n%\\section{Introduction to the forward search}\n%\\label{forward}\n\n\\section{Multivariate Analysis of Variance}\n\\label{manova}\n\nAs with the univariate situation, t-tests are fine for comparing the means of two groups, but we would have ``multiple comparison'' problems if we tried to compare more than two.   In an analagous way, in the multivariate context we have MANOVA.\n\nFirst of all we'll enter some data relating to the production of plastic film reported in \\cite{Krzanowski:2000}.   Tear, gloss and opacity are measures of the manufactured films.\n\n\\singlespacing\n\\begin{verbatim}\n> tear <- c(6.5, 6.2, 5.8, 6.5, 6.5, 6.9, 7.2, 6.9, 6.1, 6.3,                \n            6.7, 6.6, 7.2, 7.1, 6.8, 7.1, 7.0, 7.2, 7.5, 7.6)\n> gloss <- c(9.5, 9.9, 9.6, 9.6, 9.2, 9.1, 10.0, 9.9, 9.5, 9.4,\n             9.1, 9.3, 8.3, 8.4, 8.5, 9.2, 8.8, 9.7, 10.1, 9.2)\n> opacity <- c(4.4, 6.4, 3.0, 4.1, 0.8, 5.7, 2.0, 3.9, 1.9, 5.7,\n               2.8, 4.1, 3.8, 1.6, 3.4, 8.4, 5.2, 6.9, 2.7, 1.9)\nY <- cbind(tear, gloss, opacity)\n\\end{verbatim}\n\\onehalfspacing\n\nWe now need to put in information on the rate of extrusion, and the amount of additive used (\\texttt{gl()} is a command which specifically creates these kind of experimental factors).\n\n\\singlespacing\n\\begin{verbatim}\n> rate <- factor(gl(2,10), labels=c(\"Low\", \"High\"))\n> additive <- factor(gl(2, 5, len=20), labels=c(\"Low\", \"High\"))\n\\end{verbatim}\n\\onehalfspacing\n\nThere are three conventional ANOVA that could be considered here, but to consider the three responses together we may wish to conduct a MANOVA.   However, we can use \\texttt{manova()} to fit the multivariate ANOVA, and use \\texttt{summary.aov()} to extract the results of the unvariate analyses.\n\nThere are three matrices of interest in MANOVA:\n\n\\begin{itemize}\n\\item Total SSP ($\\boldsymbol{T}$)\n\\item Between-group SSP ($\\boldsymbol{B} = \\boldsymbol{T} - \\boldsymbol{W}$)\n\\item Within-group SSP ($\\boldsymbol{W}$)\n\\end{itemize}\n\nWilk's Lambda is the ratio $\\frac{|\\boldsymbol{W}|}{|\\boldsymbol{T}|}$\n\n\\singlespacing\n\\begin{verbatim}\n>      fit <- manova(Y ~ rate * additive)\n>      summary.aov(fit)           # univariate ANOVA tables\n Response tear :\n              Df  Sum Sq Mean Sq F value   Pr(>F)   \nrate           1 1.74050 1.74050 15.7868 0.001092 **\nadditive       1 0.76050 0.76050  6.8980 0.018330 * \nrate:additive  1 0.00050 0.00050  0.0045 0.947143   \nResiduals     16 1.76400 0.11025                    \n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\n Response gloss :\n              Df  Sum Sq Mean Sq F value  Pr(>F)  \nrate           1 1.30050 1.30050  7.9178 0.01248 *\nadditive       1 0.61250 0.61250  3.7291 0.07139 .\nrate:additive  1 0.54450 0.54450  3.3151 0.08740 .\nResiduals     16 2.62800 0.16425                  \n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\n Response opacity :\n              Df Sum Sq Mean Sq F value Pr(>F)\nrate           1  0.421   0.421  0.1036 0.7517\nadditive       1  4.901   4.901  1.2077 0.2881\nrate:additive  1  3.961   3.961  0.9760 0.3379\nResiduals     16 64.924   4.058               \n\\end{verbatim}\n\\onehalfspacing\n\n\nA call to \\texttt{summary()} will give the MANOVA table.   If you leave out the \\texttt{text = \\\"Wilks\\\"} call you will get a default Pillai-Bartlett statistic.\n\n\\singlespacing\n\\begin{verbatim}\n>      summary(fit, test=\"Wilks\") # ANOVA table of Wilks' lambda\n              Df  Wilks approx F num Df den Df   Pr(>F)   \nrate           1 0.3819   7.5543      3     14 0.003034 **\nadditive       1 0.5230   4.2556      3     14 0.024745 * \nrate:additive  1 0.7771   1.3385      3     14 0.301782   \nResiduals     16                                          \n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n\\end{verbatim}\n\\onehalfspacing\n\n\nAs with Hotellings T$^{2}$, Wilk's Lambda has to be converted into an F statistic, a calculation that has been done by the software.   It is possible to approximate this by a $\\chi^{2}_{pb df}$ with $W = -\\left( w - \\frac{p - b + 1}{2}\\right)log \\Lambda$ where p = number of variables, w = residual degrees of freedom (16), b = number of hypotheses degrees of freedom (1).\n\nIn any case, the interaction term is not significant.   We can fit the model without interactions, which as anticipated suggests that both additive and extrusion rate have an effect on the outcome measures.   We will use \\texttt{by()} to examine the various group means.\n\n\\singlespacing\n\\begin{verbatim}\n> fit <- manova(Y ~ rate + additive)\n> summary(fit, test = \"Wilks\")\n          Df  Wilks approx F num Df den Df   Pr(>F)   \nrate       1 0.3868   7.9253      3     15 0.002120 **\nadditive   1 0.5538   4.0279      3     15 0.027533 * \nResiduals 17                                          \n---\nSignif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 \n> by(Y, rate, mean) ## group means according to extrusion rate\nINDICES: Low\n   tear   gloss opacity \n   6.49    9.57    3.79 \n------------------------------------------------------------ \nINDICES: High\n   tear   gloss opacity \n   7.08    9.06    4.08 \n> by(Y, additive, mean) ## group means according to additive\nINDICES: Low\n   tear   gloss opacity \n   6.59    9.14    3.44 \n------------------------------------------------------------ \nINDICES: High\n   tear   gloss opacity \n   6.98    9.49    4.43 \n> \n> by(Y, list(rate,additive), mean) ## group means by both.\n: Low\n: Low\n   tear   gloss opacity \n   6.30    9.56    3.74 \n------------------------------------------------------------ \n: High\n: Low\n   tear   gloss opacity \n   6.88    8.72    3.14 \n------------------------------------------------------------ \n: Low\n: High\n   tear   gloss opacity \n   6.68    9.58    3.84 \n------------------------------------------------------------ \n: High\n: High\n   tear   gloss opacity \n   7.28    9.40    5.02 \n\\end{verbatim}\n\\onehalfspacing\n\nHigh levels of extrusion rate lead to higher levels of tear and opacity but lower levels of gloss.   High levels of addtive lead to higher levels of tear, gloss and opacity.\n\n\n\n\n\n\n%%% Local Variables: ***\n%%% mode:latex ***\n%%% TeX-master: \"../book.tex\"  ***\n%%% End: ***", "meta": {"hexsha": "60f8265a41628c863dcd828bb0d44f3b75f26907", "size": 19394, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/CompMeans.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/CompMeans.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/CompMeans.tex", "max_forks_repo_name": "phewson/mvstats", "max_forks_repo_head_hexsha": "f39ab1c1b97c89e26c708bd6d532fe13c063a95c", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 46.0665083135, "max_line_length": 642, "alphanum_fraction": 0.6674229143, "num_tokens": 6246, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8577681031721325, "lm_q1q2_score": 0.7541040578926226}}
{"text": "%% Added this section, to ha ve a list of algorithms in lwarp\n\\chapter{CENG242Cheat}\n\\todo{Remember to add more algorithms later}{Future Work}\n\n\\begin{algorithm}\n\\caption{Euclid’s algorithm}\\label{euclid}\n\\begin{algorithmic}[1]\n\\Procedure{Euclid}{$a,b$}\\Comment{The g.c.d. of a and b}\n\\State $r\\gets a\\bmod b$\n\\While{$r\\not=0$}\\Comment{We have the answer if r is 0}\n\\State $a\\gets b$\n\\State $b\\gets r$\n\\State $r\\gets a\\bmod b$\n\\EndWhile\\label{euclidendwhile}\n\\State \\textbf{return} $b$\\Comment{The gcd is b}\n\\EndProcedure\n\\end{algorithmic}\n\\end{algorithm}\n\n\n\n \\begin{algorithm}\n\t\\caption{Merge Sort}\n\t\\begin{algorithmic}[1]\n\t\t\\Function{Merge}{$A,p,q,r$}\\Comment{Where A - array, p - left, q - middle, r - right}\n\t\t\n\t\t\\State ${n_1} = q - p + 1$\n\t\t\\State ${n_2} = r - q$\n\t\t\\State Let $L[1 \\ldots {n_1} + 1]$ and $R[1 \\ldots {n_2} + 1]$ be new arrays\n\t\t\\For{$i = 1$ to ${n_1}$}\n\t\t\\State $L[i] = A[p + i - 1]$\n\t\t\\EndFor\n\t\t\\For{$j = 1$ to ${n_2}$}\n\t\t\\State $R[i] = A[q + j]$\n\t\t\\EndFor\n\t\t\\State $L[{n_1} + 1] =  \\infty $\n\t\t\\State $R[{n_2} + 1] =  \\infty $\n\t\t\\State $i = 1$\n\t\t\\State $j = 1$\n\t\t\\For{$k = p$ to $r$}\n\t\t\\If {$L[i] < R[j]$}\n\t\t\\State $A[k] = L[i]$\n\t\t\\State $i = i + 1$\n\t\t\\ElsIf {$L[i] > R[j]$}\n\t\t\\State $A[k] = R[j]$\n\t\t\\State $j = j + 1$\n\t\t\\Else\n\t\t\\State $A[k] = - \\infty$ \\Comment{We mark the duplicates with the largest negative integer}\n\t\t\\State $j = j + 1$\n\t\t\\EndIf\n\t\t\\EndFor\n\t\t\\EndFunction\n\t\t\n\t\\end{algorithmic}\n\\end{algorithm}\n\n\\section{Basic Graph Definitions}\n\\begin{itemize}\n\t\\item A graph $G = (V,E)$ consists of a finite set of {\\em vertices} $V$\n\tand a finite set of {\\em edges} $E$.\n\t\\begin{itemize}\n\t\t\\item {\\em Directed graphs}: $E$ is a set of ordered pairs of vertices\n\t\t$(u,v)$ where $u,v \\in V$ \\\\\n\t\t% \\centerline{\\epsfig{file=directed_example.eps,height=3.5cm}}\n\t\t\\item {\\em Undirected graph}: $E$ is a set of unordered pairs of\n\t\tvertices $\\{u,v\\}$ where $u,v \\in V$ \\\\ \\\\\n\t\t% \\centerline{\\epsfig{file=undirected_example.eps,height=3cm}}\n\t\\end{itemize}\n\t\\item Edge $(u,v)$ is {\\em incident} to $u$ and $v$\n\t\\item {\\em Degree} of vertex in undirected graph is the number of edges\n\tincident to it.\n\t\\item {\\em In (out) degree} of a vertex in directed graph is the number of\n\tedges entering (leaving) it.\n\t\\item A {\\em path} from $u_1$ to $u_2$ is a sequence of vertices\n\t$<u_1$=$v_0,v_1,v_2, \\cdots , v_k$=$u_2>$ such that $(v_i,v_{i+1}) \\in E$\n\t(or $\\{v_i,v_{i+1}\\} \\in E$)\n\t\\begin{itemize}\n\t\t\\item We say that $u_2$ is {\\em reachable} from $u_1$\n\t\t\\item The {\\em length} of the path is $k$\n\t\t\\item It is a {\\em cycle } if $v_0 = v_k$\n\t\\end{itemize}\n\t\n\t\n\t\\item An undirected graph is {\\em connected /} if every pair of vertices are\n\tconnected by a path\n\t\\begin{itemize}\n\t\t\\item The {\\em connected components } are the equivalence classes of\n\t\tthe vertices under the ``reachability'' relation. (All connected\n\t\tpair of vertices are in the same connected component).\n\t\\end{itemize}\n\t\\item A directed graph is {\\em strongly connected } if every pair of\n\tvertices are reachable from each other\n\t\\begin{itemize}\n\t\t\\item The {\\em strongly connected components } are the equivalence\n\t\tclasses of the vertices under the ``mutual reachability'' relation. \n\t\\end{itemize}\n\t\n\t\\vspace*{\\baselineskip}\n\t\n\t\\item Graphs appear all over the place in all kinds of applications, e.g:\n\t\\begin{itemize}\n\t\t\\item Trees $(\\vert E \\vert = \\vert V \\vert - 1)$\n\t\t\\item Connectivity/dependencies (house building plans, WWW-page\n\t\tconnections = internet graph)\n\t\\end{itemize}\n\t\\item Often the edges $(u,v)$ in a graph have weights $w(u,v)$, e.g.\n\t\\begin{itemize}\n\t\t\\item Road networks (distances)\n\t\t\\item Cable networks (capacity)\n\t\\end{itemize}\n\\end{itemize}\n\n\n\\subsection{Representation}\n\\begin{itemize}\n\t\\item {\\em Adjacency-list} representation:\n\t\\begin{itemize}\n\t\t\\item Array of $\\vert V \\vert$ list of edges incident to each\n\t\tvertex. \\\\\n\t\t\n\t\tExamples: \\\\\n\t\t\\item Note: For undirected graphs, every edge is stored twice.\n\t\t\\item If graph is weighted, a weight is stored with each edge.\n\t\\end{itemize}\n\t\n\t\n\t\\item {\\em Adjacency-matrix} representation:\n\t\\begin{itemize}\n\t\t\\item $\\vert V \\vert \\times \\vert V \\vert$ matrix $A$ where \n\t\t\\[ a_{ij} = \\left\\{ \\begin{array}{ll}\n\t\t1        & \\mbox{ if $(i,j) \\in E$} \\\\\n\t\t0        & \\mbox{ otherwise } \\\\\n\t\t\\end{array}\n\t\t\\right. \\]\n\t\t\n\t\tExamples: \\\\\n\t\t\\item Note: For undirected graphs, the adjacency matrix is\n\t\tsymmetric along the main diagonal ($A^T = A$).\n\t\t\\item If graph is weighted, weights are stored instead of one's.\n\t\\end{itemize}\n\t\\item Comparison of matrix and list representation: \\\\\n\t\\begin{itemize}\n\t\t\\item[]\n\t\t\\begin{tabular}{l|l}\n\t\t\tAdjacency list & Adjacency matrix \\\\ \\hline\n\t\t\t$O(\\vert V \\vert + \\vert E \\vert)$ space & $O(\\vert V \\vert ^2)$\n\t\t\tspace \\\\\n\t\t\tGood if graph {\\em sparse} $(\\vert E \\vert << \\vert V\n\t\t\t\\vert ^2)$ & Good if graph {\\em dense} $(\\vert E \\vert \\approx\n\t\t\t\\vert V \\vert ^2)$ \\\\\n\t\t\tNo quick access to $(u,v)$ & $O(1)$ access to $(u,v)$ \\\\\n\t\t\\end{tabular}\n\t\\end{itemize}\n\t\\item We will use adjacency list representation unless stated otherwise\n\t($O(|V|+|E|)$ space).\n\\end{itemize}\n\n\n\\section{Graph traversal}\n\\begin{itemize}\n\t\\item There are two standard (and simple) ways of traversing all\n\tvertices/edges in a graph in a systematic way\n\t\\begin{itemize}\n\t\t\\item Breadth-first\n\t\t\\item Depth-first\n\t\\end{itemize}\n\t\\item We can use them in many fundamental algorithms, e.g finding cycles,\n\tconnected components, $\\dots$\n\\end{itemize}\n\n\\subsection{Breadth-first search (BFS)}\n\\begin{itemize}\n\t\\item Main idea:\n\t\\begin{itemize}\n\t\t\\item Start at some source vertex $s$ and visit,\n\t\t\\item All vertices at distance 1,\n\t\t\\item Followed by all vertices at distance 2,\n\t\t\\item Followed by all vertices at distance 3,\n\t\t\n\t\t$\\vdots$\n\t\\end{itemize}\n\t\\item BFS corresponds to computing {\\em shortest path} distance (number of\n\tedges) from $s$ to all other vertices.\n\t\\item To control progress of our BFS algorithm, we think about {\\em coloring}\n\teach vertex\n\t\\begin{itemize}\n\t\t\\item {\\em White } before we start,\n\t\t\\item {\\em Gray } after we visit the vertex but before we have\n\t\tvisited all its adjacent vertices,\n\t\t\\item {\\em Black } after we have visited the vertex and all its\n\t\tadjacent vertices (all adjacent vertices are gray).\n\t\\end{itemize}\n\t\\item We use a queue $Q$ to hold all gray vertices---vertices we have seen\n\tbut  are still not done with.\n\t\\item We remember from which vertex a given vertex $v$ is colored gray\n\t-- i.e. the node that discovered $v$ first; this is called\n\tparent[$v$].\n\t\\item Algorithm: \\\\ \\\\\n\t\\fbox{\n\t\t\\parbox{10cm}{\n\t\t\t{\\sc BFS($s$) }\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item[] color[$s$] = gray\n\t\t\t\t\\item[] $d[s] = 0$\n\t\t\t\t\\item[] ENQUEUE($Q,s$)\n\t\t\t\t\\item[] WHILE $Q$ not empty DO\n\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\\item[] DEQUEUE($Q,u$)\n\t\t\t\t\t\\item[] FOR $(u,v)\\in E$ DO\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\t\\item[] IF color[$v$] = white THEN\n\t\t\t\t\t\t\\item[] ~~~~color[$v$] = gray\n\t\t\t\t\t\t\\item[] ~~~~$d[v] = d[u] + 1$\n\t\t\t\t\t\t\\item[] ~~~~parent[$v$] = u\n\t\t\t\t\t\t\\item[] ~~~~ENQUEUE($Q,v$)\n\t\t\t\t\t\t\\item[] FI\n\t\t\t\t\t\t\\item[] color[$u$] = black\n\t\t\t\t\t\\end{itemize}\n\t\t\t\t\\end{itemize}\n\t\t\t\t\\item[] OD\n\t\t\t\\end{itemize}\n\t}}\n\t\\vspace*{\\baselineskip}\n\t\n\t\\item Algorithm runs in $O(\\vert V \\vert + \\vert E \\vert)$ time\n\t\n\t\n\t\\item Example (for directed graph): \\\\\n\t\\item Note:\n\t\\begin{itemize}\n\t\t\\item parent[$v$] forms a tree; {\\em BFS-tree}.\n\t\t\\item $d[v]$ contains length of shortest path from $s$ to\n\t\t$v$. (Prove by induction)\n\t\t\\item We can use parent[$v$] to find the shortest path from $s$ to a\n\t\tgiven vertex.\n\t\t%       \\item We can use algorithm to detect cycles; just check if gray\n\t\t%       node is ever met.\n\t\\end{itemize}\n\t\\item If graph is not connected we have to try to start the traversal\n\tat all nodes. \\\\\n\t\n\t\\fbox{\n\t\t\\parbox{8cm}{ \n\t\t\tFOR each vertex $u \\in V $ DO\n\t\t\t\\begin{itemize}\n\t\t\t\t\\item[] IF color[$u$] = white THEN BFS($u$)\n\t\t\t\\end{itemize}\n\t\t\tOD\n\t}}\n\t\n\t\\begin{itemize}\n\t\t\\item Note: We can use algorithm to compute connected components in\n\t\t$O(|V|+|E|)$ time.\n\t\\end{itemize}\n\\end{itemize}\n\n\n\n\\subsection{Depth-first search (DFS)}\n\\begin{itemize}\n\t\\item If we use stack instead of queue $Q$ we get another traversal order;\n\tdepth-first\n\t\\begin{itemize}\n\t\t\\item We go ``as deep as possible'',\n\t\t\\item Go back until we find unexplored adjacent vertex,\n\t\t\\item Go as deep as possible,\n\t\t\n\t\t$\\vdots$\n\t\\end{itemize}\n\t\\item Often we are interested in ``start time'' and ``finish time'' of\n\tvertex $u$\n\t\\begin{itemize}\n\t\t\\item {\\em Start time\\/} (d[$u$]): indicates at what ``time'' vertex\n\t\tis first visited.\n\t\t\\item {\\em Finish time\\/} (f[$u$]): indicates at what ``time'' all\n\t\tadjacent vertices have been visited.\n\t\\end{itemize}\n\t\\item We can write DFS iteratively using the same algorithm as for BFS\n\tbut with a STACK instead of a QUEUE, or, we can write a recursive DFS\n\tprocedure\n\t\\begin{itemize}\n\t\t\\item We will color a vertex gray when we first meet it and black\n\t\twhen we finish processing all adjacent vertices.\n\t\\end{itemize}\n\t\\item Algorithm: \\\\\n\t\n\t\\fbox{\n\t\t\\parbox{8cm}{\n\t\t\t{\\sc DFS($u$) } \n\t\t\t\\begin{itemize}\n\t\t\t\t\\item[] color[$u$] = gray\n\t\t\t\t\\item[] $d[u]$ = time\n\t\t\t\t\\item[] time = time + 1\n\t\t\t\t\\item[] FOR $(u,v)\\in E$ DO\n\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\\item[] IF color[$v$] = white THEN\n\t\t\t\t\t\\begin{itemize}\n\t\t\t\t\t\t\\item[] parent[$v$] = $u$\n\t\t\t\t\t\t\\item[] {\\sc DFS(v)}\n\t\t\t\t\t\\end{itemize}\n\t\t\t\t\t\\item[] FI\n\t\t\t\t\\end{itemize}\n\t\t\t\t\\item[] OD\n\t\t\t\t\\item[] color[$u$] = black\n\t\t\t\t\\item[] $f[u]$ = time\n\t\t\t\t\\item[] time = time + 1\n\t\t\t\\end{itemize}\n\t}}\n\t\n\t\\item Algorithm runs in $O(\\vert V \\vert + \\vert E \\vert)$ time\n\t\\begin{itemize}\n\t\t\\item As before we can extend algorithm to unconnected graphs and\n\t\twe can use it to detect cycles in $O(|V|+|E|)$ time.\n\t\\end{itemize}\n\t\n\t\\item As previously parent[$v$] forms a tree; {\\em DFS-tree}\n\t\\begin{itemize}\n\t\t\\item Note: If $u$ is descendent of $v$ in DFS-tree  then $d[v] <\n\t\td[u] < f[u] < f[v]$\n\t\\end{itemize}\n\\end{itemize}\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n\n\\section{Topological sorting}\n\\begin{itemize}\n\t\\item Definition: Topological sorting of {\\em directed acyclic graph}\n\t$G=(V,E)$ is a linear ordering of vertices $V$ such that $(u,v) \\in E\n\t\\Rightarrow u$ appear before $v$ in ordering.\n\t\\item Topological ordering can be used in scheduling:\n\t\\begin{itemize}\n\t\t\\item Example: Dressing (arrow implies ``must come before'') \\\\ \\\\\n\t\t% \\centerline{\\epsfig{file=top_sort_example.eps,height=5.5cm}} \\\\\n\t\t\n\t\tWe want to compute order in which to get dressed. One possibility: \\\\\n\t\t\n\t\t\n\t\t\\vspace*{\\baselineskip}\n\t\t\n\t\tThe given order is one possible topological order.\n\t\\end{itemize}\n\t\\item Algorithm: Topological order just reverse DFS finish time ($\n\t\\Rightarrow O(\\vert V \\vert + \\vert E \\vert)$ running time).\n\t\\item Correctness: $(u,v) \\in E \\Leftrightarrow f(v) < f(u)$\n\t\\begin{itemize}\n\t\t\\item Proof: When $(u,v)$ is explored by DFS algorithm, $v$ must be\n\t\twhite or black (gray $\\Rightarrow$ cycle).\n\t\t\\begin{itemize}\n\t\t\t\\item $v$ white: $v$ visited and finished before $u$ is\n\t\t\tfinished $\\Rightarrow f(v) < f(u)$\n\t\t\t\\item $v$ black: $v$ already finished $\\Rightarrow f(v) <\n\t\t\tf(u)$\n\t\t\\end{itemize}\n\t\\end{itemize}\n\t\\item Alternative algorithm: Count in-degree of each vertex and repeatedly\n\tnumber and remove in-degree 0 vertex and its outgoing edges: Homework. \n\t\n\\end{itemize}\n", "meta": {"hexsha": "b8ce8cd30aa8142513208be7af00400c71e58621", "size": 11253, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "public/CheatSheets/CENG242Cheat.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/CENG242Cheat.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/CENG242Cheat.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": 31.2583333333, "max_line_length": 93, "alphanum_fraction": 0.6434728517, "num_tokens": 3856, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711832583695, "lm_q2_score": 0.8872045862611166, "lm_q1q2_score": 0.7540983319766135}}
{"text": "%---------------------------Maximum Edge Ratio---------------------------\n\\section{Maximum Edge Ratio}\n\nGiven principal axes with lengths $L_f$ and $L_g$,\nthe aspect ratio is defined as the largest ratio of those lengths\n\\[\n   A_{fg} = \\max\\left\\{ \\frac{L_f}{L_g}, \\frac{L_g}{L_f} \\right\\}.\n\\]\nSince a hexahedron has 3 principal axes, we take the largest of all pairwise combinations of axes.\n\\[\n  q  = \\max\\left\\{\n    A_{\\normvec{ X_1 }\\normvec{ X_2 }},\n    A_{\\normvec{ X_1 }\\normvec{ X_3 }},\n    A_{\\normvec{ X_2 }\\normvec{ X_3 }}\n  \\right\\}\n\\]\n\nNote that if $\\normvec{X_1}$ or $\\normvec{X_2}$ or $\\normvec{X_3} < DBL\\_MIN$, we set $q = DBL\\_MAX$.\n\n\\hexmetrictable{maximum edge ratio}%\n{$1$}%                                      Dimension\n{$[1,1.3]$}%                                Acceptable range\n{$[1,DBL\\_MAX]$}%                           Normal range\n{$[1,DBL\\_MAX]$}%                           Full range\n{$1$}%                                      Unit square\n{Adapted from \\cite{tf:89}}%                Citation\n{v\\_hex\\_max\\_edge\\_ratio}%                      Verdict function name\n", "meta": {"hexsha": "2d62f42a4ef2af1e4729ce81b7c161dc6e5b668c", "size": 1096, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/HexMaximumEdgeRatio.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/HexMaximumEdgeRatio.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/HexMaximumEdgeRatio.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.1428571429, "max_line_length": 101, "alphanum_fraction": 0.5118613139, "num_tokens": 323, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9196425311777929, "lm_q2_score": 0.8198933447152497, "lm_q1q2_score": 0.7540087908297589}}
{"text": "In this section, we will closely follow\\ \\cite{pitfalls}\n\n\n\n\\subsubsection{Introduction}\n\nNormally, samples in machine learning are of huge sample sizes, for which most MCMC algorithms are not designed to process. \nAs a result of the computational cost, several new approaches were proposed recently, Stochastic Gradient Langevin Dynamics (SGLD) is a popular one. \nSGLD is based on the Langevin Monte Carlo (LMC)\nLMC – a discretization of a continuous-time process, it requires to compute the gradient of the log-posterior at the current fit of the parameter and avoid the accept/reject step.\nSGLD – use unbiased estimator of the gradient of log-posterior based on subsampling, suitable for samples of huge size. \n\n\n\\subsubsection{Governing Equation}\nRecall the following equations:\nEuler discretization of the Langevin SDE:\n$$\\theta_{n+1} = \\theta_n - h \\nabla U(\\theta_n)+\\sqrt{2h} Z_{n+1}$$ where $h > 0$ is a constant step size and $(Z_n)_{n\\geq1}$ is a sequence of i.i.d standard d - dimensional Guassian vectors. \nTo reduce the costs of the algorithms, we will switch to SGLD, for which we will replace $\\nabla U$ with an unbiased estimate $\\nabla U_0+(\\frac{N}{p}) \\sum_{i\\in S}\\nabla U_i$, where S is a minibatch of \\{1,...., N\\} with replacement of size p. Our iterations were then updated as\n$$\\theta_{n+1} = \\theta_{n}-h \\Bigg (\\nabla U_0(\\theta_n)+\\frac{N}{p}\\sum_{i\\in S_{n+1}}\\nabla U_i(\\theta_n)\\Bigg )+\\sqrt{2h}Z_{n+1}$$\nStochastic Gradient Descent (SGD) is characterised by the same recursion as SGLD without the Gaussian noise, (the last term):\n\n\n$$\\theta_{n+1} = \\theta_{n}-h \\Bigg (\\nabla U_0(\\theta_n)+\\frac{N}{p}\\sum_{i\\in S_{n+1}}\\nabla U_i(\\theta_n)\\Bigg)$$\n\\textbf{Analysis in Wasserstein distance}\n\\subsubsection{Definitions and Notations in Markov Chain theory}\nRecall the following definitions:\n$\\mathcal{P}_2(\\mathbb{R}^d)$ the set of probablity measures with finite second momet.\\\\\n$\\mathcal{B}(\\mathbb{R}^d)$ the Borel $\\sigma$ - algebra of $\\mathbb{R}^d$.\\\\\nFor $\\lambda, \\nu \\in \\mathcal{P}_2(\\mathbb{R}^d)$, we define the Wasserstein distance by \n\n$$W_2(\\lambda, \\nu) =\\inf_{\\xi \\in \\Pi(\\lambda, \\nu)}(\\int_{\\mathbb{\\mathbb{R}^d \\times \\mathbb{R}^d}}||\\theta-\\vartheta)||^2 \\xi(d\\theta, d\\vartheta))^{\\frac{1}{2}}$$\nwhere, $\\Pi(\\lambda, \\nu)$ is the set of probablity measures $\\xi$ on $\\mathcal{B}(\\mathbb{R}^d)\\otimes\\mathcal{B}(\\mathbb{R}^d)$ satisfying for all $A \\in \\mathcal{B}(\\mathbb{R}^d), \\xi(A \\times \\mathbb{R}^d)= \\lambda(A)$ and $\\xi (\\mathbb{R}^d \\times A) = \\nu(A)$.\\\\\nFor any probablity measure $\\lambda$ on $\\mathcal{B}(\\mathbb{R}^d)$, we define $\\lambda R$ for all $A \\in \\mathcal{B}(\\mathbb{R}^d)$ by $\\lambda R(A) = \\int_{\\mathbb{R}^d}\\lambda(d\\theta)R(\\theta, A)$.\\\\\nFor all $k\\in \\mathbb{N}*$, we define the Markov kernel $R^k$ recursively by $R^1 = R$ and for all $\\theta \\in \\mathbb{R}^d$ and $A \\in \\mathcal{B}(\\mathbb{R}^d)$, $R^{k+1}(\\theta, A) = \\int_{\\mathbb{R}^d}  R^k(\\theta, d\\vartheta)R(\\vartheta, A).$\\\\\nA probablity measure $\\bar{\\pi}$ is invariant for R if $\\bar{\\pi}R = \\bar{\\pi}$.\\\\\nOur algorithms LMC, SGLD, SGD and SGLDFP algorithms are homogeneous Markov chains with Markov kernels denoted $R_{LMC}, R_{SGLD}, R_{SGD}$ and $R_{FP}$.\n\n\\subsubsection{Results}\nRecall our assumptions:\n\\begin{enumerate}[label={\\bf H\\arabic*}]\n    \\item For all $i \\in \\{0,...,N\\}, \\ U_i$ is four times continuously differentiable and for all $j \\in \\{2, 3, 4\\},$$sup_{\\theta \\in \\mathbb{R}^d}||D^j U_i(\\theta)||\\leq \\Tilde{L}.$ In particular for all $i\\in \\{0, ..., N\\}$, $U_i$ $\\Tilde{L}$-gradient Lipschitz, i.e. for all $\\theta_1, \\theta_2\\in \\mathbb{R}^d$, $||\\nabla U_i(\\theta_1) - \\nabla U_i (\\theta_2)|| \\leq \\Tilde{L}||\\theta_1 - \\theta_2||.$\n    \\item U is m-strongly convex, i.e. for all $\\theta_1, \\theta_2 \\in \\mathbb{R}^d$,$\\left< \\nabla U(\\theta_1) - \\nabla U(\\theta_2), \\theta_1 - \\theta_2\\right>\\geq m ||\\theta_1 - \\theta_2||^2.$\n    \\item For all $i\\in\\{0,...,N\\}$, $U_i$ is convex.\n\\end{enumerate}\nFor the below Lemma, Theorem and Corollary, we assume H1, H2 and H3.\n\\begin{lemma}\nFor any step size $h \\in (0, \\frac{2}{L})$, $R_{SGLD}$(respectively $R_{LMC}, R_{SGD}, R_{FP}$) has a unique invariant measure $\\pi_{SGLD}\\in \\mathcal{P}_2(\\mathbb{R}^d)$(respectively $\\pi_{LMC}, \\pi_{SGD}, \\pi_{FP}$). In addition, for all $h \\in (0, \\frac{1}{L}], \\theta\\in \\mathbb{R}^d and k\\in\\mathbb{N}$,\n$$W_2^2(R_{SGLD}^k(\\theta, \\cdot), \\pi_{SGLD})\\leq(1-mh)^k\\int_{\\mathbb{R}^d}||\\theta-\\vartheta||^2\\pi_{SGLD}(d\\vartheta)$$\nsame inequality holds for LMC, SGD and SGLDFP.\n\\end{lemma}\n\n\\begin{theorem}\nFor all $h\\in(0,\\frac{1}{L}], \\lambda, \\nu\\in \\mathcal{P}_2(\\mathbb{R}^d)\\ and \\ n\\in\\mathbb{N}$, we have the following upper- bounds in Wasserstein distance between\n\\begin{enumerate}\n\t\\item \n\tLMC and SGLDFP,\n\n\\begin{dmath}\t\nW_2^2(\\lambda R_{LMC}^n, \\nu R_{FP}^n)\\leq(1-mh)^nW_2^2(\\lambda, \\nu) + \\frac{2L^2h d}{pm^2}+\\frac{L^2h^2}{p}n(1-mh)^{n-1}\\int_{\\mathbb{R}^d}||\\vartheta-\\theta*||^2 \\mu(d\\vartheta)\n\\end{dmath},\n\t\\item \n\tthe Langevin diffusion and LMC,\n\\begin{dmath}\nW_2^2(\\lambda R_{LMC}^n, \\mu P_{nh})\\leq2(1-\\frac{mLh}{m+L})^nW_2^2(\\lambda, \\mu)+dh\\frac{m+L}{2m}(3+\\frac{L}{m})(\\frac{13}{6}+\\frac{L}{m})\\\\+ne^{-(\\frac{m}{2})h(n-1)}L^3h^3(1+\\frac{m+L}{2m})\\int_{\\mathbb{R}^d}||\\vartheta - \\theta*||^2 \\mu(d\\vartheta)\n\\end{dmath},\n\t\\item \n\tSGLD and SGD\n\t\\begin{dmath}\n\tW_2^2(\\lambda R_{SGLD}^n, \\mu R_{SGD}^n)\\leq (1-mh)^n W_2^2(\\lambda, \\mu)+\\frac{(2d)}{m}.\n\t\\end{dmath}\n\\end{enumerate}\n\\end{theorem}\nProof omitted.\n\\begin{cor}\nSet $h - \\frac{\\eta}{N} \\ with \\ \\eta \\in (0, \\frac{1}{(2L)}]$ and assume that $lim \\inf_{N \\to \\infty}mN^{-1}>0$. Then\n\\begin{enumerate}\n\\item\nfor all $n \\in N$, we get $W_2(R_{LMC}^n(\\theta*, \\cdot), R_{FP}^{n}(\\theta*, \\cdot)) = \\sqrt{d\\eta}\\mathcal{O}(N^{-\\frac{1}{2}})$ and $W_2(\\pi_{LMC}, \\pi_{FP}) = \\sqrt{d\\eta}\\mathcal{O}(N^{-\\frac{1}{2}})$.\n\\item \nfor all $n\\in \\mathbb{N}, we get W_2(R_{SGLD}^{n}(\\theta*, \\cdot), R^n_{SGD}(\\theta*, \\cdot)) = \\sqrt{d}\\mathcal{O}(N^{-\\frac{1}{2}})$, and $W_2(\\pi_{SGLD}, \\pi_{SGD}) = \\sqrt{d}\\mathcal{O}(N^{-\\frac{1}{2}})$.\n\\end{enumerate}\n\\end{cor}", "meta": {"hexsha": "6878885cc6256e7b626614dd828e7c2eeaf8a0b2", "size": 6094, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "WriteUp/report.tex", "max_stars_repo_name": "Tom271/LangevinMC", "max_stars_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2019-02-07T12:51:19.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-04T13:35:13.000Z", "max_issues_repo_path": "WriteUp/report.tex", "max_issues_repo_name": "swyoon/LangevinMC", "max_issues_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "WriteUp/report.tex", "max_forks_repo_name": "swyoon/LangevinMC", "max_forks_repo_head_hexsha": "ed36a17ce9b7d1e39097aeaf5b92f0fa286d5489", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2021-01-19T17:44:19.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-19T17:44:19.000Z", "avg_line_length": 74.3170731707, "max_line_length": 407, "alphanum_fraction": 0.6583524778, "num_tokens": 2477, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7538675410617549}}
{"text": "\\chapter{COORDINATE SYSTEMS}\r\nA co-ordinate system is a mathematical tool to describe the position of an object. It  is used extensively in describing a physical problem or a situation . The information about problem of interest is depicted in 'co-ordinate', it is the set of two or more numbers that specifies the position of a point, line, or other geometric figure in relation to some reference system.\\newline There are mainly four kinds of coordinate systems. Cartesian (Rectangular) coordinate system, Plane polar coordinate system, Cylindrical polar coordinate system and Spherical polar coordinate system.The choice of the coordinate system is based on the symmetry problem we are interested in.\r\n\\section{Cartesian Coordinate System}\r\nThe most common coordinate systems that we are likely to encounter are Cartesian coordinate systems. These are used where the plane, surface or space can be described in flat, rectangular dimensions (like a box, or a square ).\r\n\\\\\r\n\\begin{minipage}{0.50\\textwidth}\r\n\tA 3-D Cartesian coordinate consist of a set of 3 mutually perpendicular axes, which intersect at a common point, the origin O. In a three dimensional Cartesian coordinate system, the position of an object is specified by using the three coordinates, ${x}, {y},$ and ${z}$. The range of the coordinates are,\r\n\t\\begin{align*}\r\n\t-\\infty \\leqslant x \\leqslant \\infty \\\\\r\n\t-\\infty \\leqslant y \\leqslant \\infty \\\\\r\n\t-\\infty \\leqslant z \\leqslant \\infty\r\n\t\\end{align*}\r\n\\end{minipage}\\hfill\r\n\\begin{minipage}{0.35\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\begin{center}\r\n\t\t\t\\includegraphics[width=6cm,height=5cm]{cartesian }\r\n\t\t\\end{center}\r\n\t\t\\caption{3-D Cartesian coordinate system}\r\n\t\\end{figure}\r\n\\end{minipage}\r\n\\subsection{Position Vector and Unit Vectors}\r\n\\textbf{Position vector :} A position vector defines the position of point with respect to origin in a plane or space.\r\n\\\\\\\\\\textbf{Unit vector \\hspace{0.55cm}:} A vector of  unit length is called as  a unit vector. It's also called the direction vector since it specifies the direction of a vector. In general  the unit vector in the direction of $ x $ is represented as $\\hat{e_{x}}$, in the direction of y,  $\\hat{e_{y}}$ and in the direction of z,  $\\hat{e_{z}}$.\r\n\\begin{align*}\r\n\\intertext{Then the position vector in cartesian coordinate system in general is represented by,} \r\n\\vec{r}&=x\\hat{e_{x}}+y\\hat{e_{y}}+z\\hat{e_{z}}\r\n\\intertext{In conventional form the unit vectors are defined as $\\hat{e_{x}}$ ,$\\hat{e_{y}}$ and $\\hat{e_{z}}$ in $ x, y \\ \\text{and } z$ directions respectively. Then the position vector becomes,}\r\n\\vec{r}&=x\\hat{e_{x}}+y\\hat{e_{y}}+z\\hat{e_{z}}\r\n\\end{align*}\r\n\r\n\\subsection{Line, Area and Volume Elements}\r\n\\begin{figure}[h]\r\n\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\\includegraphics[scale=0.4]{cs-05-crop.pdf}\r\n\t\t\\caption{line element}\r\n\t\t\\label{line element}\r\n\t\\end{minipage}\r\n\t\\begin{minipage}{0.35\\textwidth}\r\n\t\t\\includegraphics[scale=0.4]{cs-03-crop.pdf}\r\n\t\t\\caption{Area element}\r\n\t\\end{minipage}\r\n\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\\includegraphics[scale=0.4]{cs-06-crop.pdf}\r\n\t\t\\caption{Volume element}\r\n\t\\end{minipage}\r\n\\end{figure}\r\n\\begin{itemize}\r\n\t\\item{\\textbf{Line element}}\\\\\r\n\tConsider a small infinitesimal displacement $dl$  between two points $p_{1}$ and $p_{2}$ as in the fig.\\ref{line element} then it  is defined as, \\begin{align*}\r\n\td {\\vec{l}}&=d x \\hat{e_{x}}+d y \\hat{e_{y}}+d z \\hat{e_{z}}\r\n\t\\end{align*}\r\n\t\\item{\\textbf{Area element}}\\\\ The infinitesimal area element in a cartesian coordinate system is defined as ,\r\n\t\\begin{align*}\r\n\td\\vec{A}&=dx dy \\hat{e_{z}}\\qquad \\text{Area element in the x-y plane.}\\\\\r\n\t\\intertext{Similiarly, }\\\r\n\td\\vec{A}&=dx dz \\hat{e_{y}} \\qquad \\text{Area element in the x-z plane.}\\\\\r\n\t\\text{And}\\quad  d\\vec{A}&=dy dz  \\hat{e_{x}} \\qquad \\text{Area element in the y-z plane.}\r\n\t\\end{align*}\r\n\t\\item{\\textbf{Volume element}}\\\\ The infinitesimal volume element in a cartesian coordinate system is defined as,\r\n\t\\begin{equation*}\r\n\td{V}=dx dy dz \r\n\t\\end{equation*}\r\n\tRemember that the infinitesimal volume element is a scalar quantity.\t\r\n\t\r\n\t\r\n\\end{itemize}\r\n\\subsection{Kinematic Vectors in Cartesian Coordinate System}\r\n\\begin{itemize}\r\n\t\\item \\textbf{Velocity}\r\n\t\\begin{align*}\r\n\t\\intertext{We know that velocity is the rate of change of displacement. So, differentiating the displacement vector we get,}\r\n\t\\text { Velocity }, \\vec{v}&=\\frac{d \\vec{r}}{d t}\\\\\r\n\t\\text{Velocity in cartesian coordinate system:} \\\\\r\n\t\\vec{v}&=\\frac{d \\vec{r}}{d t}=\\frac{d}{d t}(x \\hat{e_{x}}+y \\hat{e_{y}}+z \\hat{e_{z}})\\\\&=\\dot{x} \\hat{e_{x}}+\\dot{y} \\hat{e_{y}}+\\dot{z} \\hat{e_{z}}\\\\\r\n\t\\text{Where,} \\ \\dot{x}&=\\frac{dx}{dt}\\quad ;\\quad \\dot{y}=\\frac{dy}{dt}\\quad ;\\quad\\dot{z}=\\frac{dz}{dt}\r\n\t\\end{align*}\r\n\t\r\n\t\\item \\textbf{Acceleration}\r\n\t\\begin{align*}\r\n\t\\intertext{Acceleration is the rate of change of velocity. differentiating velocity vector with respect to time we get acceleration .}\r\n\t\\text{Accelaration} ,\\ \\vec{a}&=\\frac{d \\vec{v}}{d t}\\\\\r\n\t\\text{Accelaration in cartesian coordinate system:}\\\\ \\vec{a}&=\\frac{d \\vec{v}}{d t}=\\frac{d \\dot{\\vec{x}}}{d t}+\\frac{d \\dot{\\vec{y}}}{d t}+\\frac{d \\dot{\\vec{z}}}{d t}\\\\&=\\ddot{x} \\hat{e_{x}}+\\ddot{y} \\hat{e_{y}}+\\ddot{z} \\hat{e_{z}}\r\n\t\\end{align*}\r\n\t\r\n\t\r\n\\end{itemize}\r\n\r\n%.........................\r\n\\section{Polar Co-Ordinate System}\r\nThe polar coordinate system is just an another way of describing the locations of points in a plane. We need to use polar coordinates , where there is circular  symmetry in the form of a physical object, or some kind of circular or orbital (oscillatory) motion. A polar equation describes a relationship between $\\rho$ and $\\phi$ on a polar grid. One of the main  application of polar coordinates is in orbital motions of celestial objects.  Instead of giving x and y coordinates, we’ll describe the location of a point by,\\\\\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{itemize}\r\n\t\t\\item {$\\rho$= Distance  from origin}\r\n\t\t\\item{$\\phi$= Angle between the ray from the origin to the point and the horizontal\r\n\t\t\taxis.}\r\n\t\t\\begin{align*}\r\n\t\tx&=\\rho \\cos \\phi\r\n\t\t\\quad;\\quad y=\\rho\\sin \\phi\r\n\t\t\\intertext{ $\\rho$ and $\\phi$ varies as,}\r\n\t\t0 &\\leq \\rho \\leq \\infty\\\\ 0 &\\leq \\phi\\leq 2 \\pi\r\n\t\t\\end{align*}\r\n\t\\end{itemize}\r\n\\end{minipage}\\hfill\r\n\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\centering\r\n\t\t\\includegraphics[width=6cm,height=5cm]{polar}\r\n\t\t\\caption{ Polar Coordinate system}\r\n\t\t\\label{ Polar Coordinate system}\r\n\t\\end{figure}\r\n\\end{minipage}\\\\\\\\\r\nIn the plane polar coordinates the condition $\\rho=\\text{Constant}$ , provides circles, where as $\\phi=\\text{Constant }$ provides radial line.\r\nSince we are dealing with free vectors, we can translate the polar reference frame for a given point $(\\rho, \\phi),$ to cartesian, by  a standard change of basis procedure.\r\n\\\\So that the inverse relationships to convert rectangular coordinates to polar coordinates, we can  use,\r\n\r\n\\begin{align*}\r\nx&= \\rho \\cos \\phi\\\\\r\ny&= \\rho \\sin \\phi\\\\\r\n\\rho &=\\sqrt{x^{2}+y^{2}} \\\\\r\n\\phi &=\\tan ^{-1} \\frac{y}{x}\r\n\\end{align*}\r\n\r\n\\subsection{Position Vector and Unit Vector}\r\n\\begin{align*}\r\n\\intertext{The position vector $\\vec{r}$ in polar coordinate is given by :}\r\n\\vec{r}&=\\rho\\hat{{e_{\\rho}}}\\\\\r\n\\intertext{In the polar coordinate system we have $\\hat{e_{\\rho}}$ in the increasing direction of $\\rho$ and  $\\hat{e_{\\phi}}$ in the increasing direction of $\\phi$. Since the direction of the unit vectors depend on the position of the point both $\\hat{e_{\\rho}}$ and $\\hat{e_{\\phi}}$ are a function of $\\phi$,}\r\n\\intertext{The unit vectors are defined as ,}  \\hat{e_{\\rho}}&=\\frac{\\partial \\vec{r} / \\partial \\rho}{|\\partial \\vec{r} / \\partial \\rho|}=\\cos \\phi \\hat{e_{x}}+\\sin \\phi \\hat{e_{y}}\\\\ \\hat{e_{\\phi}}&=\\frac{\\partial \\vec{r} / \\partial \\phi}{|\\partial \\vec{r} / \\partial \\phi|}=-\\sin \\phi \\hat{e_{x}}+\\cos \\phi \\hat{e_{y}}\r\n\\intertext{In matrix notation,}\r\n\\left(\\begin{array}{c}\r\n\\hat{e_{\\rho}} \\\\\r\n\\hat{e_{\\phi}}\r\n\\end{array}\\right)&=\\left(\\begin{array}{cc}\r\n\\cos \\phi & \\sin \\phi \\\\\r\n-\\sin \\phi & \\cos \\phi\r\n\\end{array}\\right)\\left(\\begin{array}{c}\r\n\\hat{e_{x}} \\\\\r\n\\hat{e_{y}}\r\n\\end{array}\\right)\\\\\\\\\r\n\\hat{e_{\\rho}} \\times \\hat{e_{\\phi}}&=\\hat{e_{z}}\r\n\\end{align*}\r\nSince the unit vectors transforms this way components of any general vector $A$ should transform in the same way. And we have the transformation matrix,\r\n\\begin{align*}\r\n\\left(\\begin{array}{c}\r\nA_{\\rho} \\\\\r\nA_{\\phi}\r\n\\end{array}\\right)&=\\left(\\begin{array}{cc}\r\n\\cos \\phi & \\sin \\phi \\\\\r\n-\\sin \\phi & \\cos \\phi\r\n\\end{array}\\right)\\left(\\begin{array}{c}\r\nA_{x} \\\\\r\nA_{y}\r\n\\end{array}\\right) \\\\\\intertext { And } \\quad\\left(\\begin{array}{c}\r\nA_{x} \\\\\r\nA_{y}\r\n\\end{array}\\right)&=\\left(\\begin{array}{cc}\r\n\\cos \\phi & -\\sin \\phi \\\\\r\n\\sin \\phi & \\cos \\phi\r\n\\end{array}\\right)\\left(\\begin{array}{c}\r\nA_{\\rho} \\\\\r\nA_{\\phi}\r\n\\end{array}\\right)\r\n\\end{align*}\r\n\r\n\\subsection{Line, Area and Volume Elements}\r\n\\begin{itemize}\r\n\t\\item \\textbf{Line element}\r\n\t\\begin{align*}\r\n\t\\vec{dl}=d \\rho \\hat{e_{\\rho}}+\\rho d \\hat{e_{\\phi}}\r\n\t\\end{align*}\r\n\t\\item \\textbf{Area element} \\begin{align*}\r\n\td \\vec{A}&=d \\rho \\hat{e_{\\rho}} \\times \\rho d \\phi \\hat{e_{\\phi}}\\\\&=\\rho d \\rho d \\phi \\hat{e_{z}}\r\n\t\\end{align*}\r\n\\end{itemize}\r\n\t\\begin{figure}[h]\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\\includegraphics[width=6cm,height=5.5cm]{diagram-20211126(3)}\r\n\t\t\\caption{Circular symmetry of Polar coordinate system}\r\n\t\t\r\n\t\\end{minipage}\\hfill\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\\includegraphics[width=6cm,height=5.5cm]{diagram-20211126(2)}\r\n\t\t\\caption{Area element}\r\n\t\\end{minipage}\r\n\\end{figure}\r\n\\subsection{Kinematic in Polar Coordinate System}\r\n\\begin{itemize}\r\n\t\\item {\\textbf{Velocity vector}}\r\n\t\\begin{equation*}\r\n\t\\text{Velocity }=\\vec{v}=\\frac{d \\vec{r}}{d t}\r\n\t\\end{equation*}\r\n\tBut here the displacement vector is given by, $\\vec{r}=\\rho \\hat{e_{\\rho}}$\r\n\t\\\\\\\\Since the unit vectors  changes with time, they should have finite time derivatives:\r\n\t\\begin{align*}\r\n\t\\frac{d }{dt} e_{\\rho}&=\\dot{\\hat{e_{\\rho}}}\\\\&=\\dot{\\phi}(-\\sin \\phi \\hat{e_{x}}+\\cos \\phi \\hat{e_{y}})\\\\&=\\dot{\\phi} \\hat{e_{\\phi}}\\\\\r\n\t\\text{And}\\quad\t\\frac{d }{dt} e_{\\rho}&=  \\dot{\\hat{e_{\\phi}}}\\\\&=\\dot{\\phi}(-\\cos \\phi \\hat{e_{x}}-\\sin \\phi \\hat{e_{y}})\\\\&=-\\dot{\\phi} \\hat{e_{\\rho}}\\\\\r\n\t\\intertext{Therefore the velocity is given by:}\r\n\t\\vec{v}&=\\frac{d \\vec{\\rho}}{d t}=\\dot{\\rho} \\hat{e_{\\rho}}+\\rho \\dot{\\hat{e_{\\rho}}}\\\\&=\\dot{\\rho} \\hat{e_{\\rho}}+\\rho \\dot{\\phi} \\hat{e_{\\phi}}\\\\\r\n\t\\text{Where,}\\quad v_{\\rho}&=\\dot{\\rho} \\hat{e_{\\rho}} \\hspace{0.62cm} -\\text{Radial velocity component.}\\\\\r\n\tv_{\\phi}&=\\rho \\dot{\\phi} \\hat{e_{\\phi}}\\quad -\\text{Tangential / Azimuthal velocity component.}\r\n\t\\end{align*}\r\n\t\r\n\t\\item{\\textbf{Acceleration vector}}\\\\\r\n\tDifferentiating again with respect to time, we obtain the acceleration\r\n\t\\begin{align*}\r\n\t\\boldsymbol{a}&=\\dot{\\boldsymbol{v}}=\\ddot{\\rho} \\hat{e_{\\rho}}+\\dot{\\rho} \\dot\\hat{e_{\\rho}}+\\dot{\\rho} \\dot{\\phi} \\hat{e_{\\phi}}+\\rho \\ddot{\\phi} \\hat{e_{\\phi}}+\\dot{\\rho} \\dot{\\boldsymbol{\\phi}} \\hat{\\dot{\\phi}}\\\\\r\n\t\\boldsymbol{a}&=\\left(\\ddot{\\rho}-\\rho \\dot{\\phi}^{2}\\right) \\hat{e_{\\rho}}+(\\rho \\ddot{\\phi}+2 \\dot{\\rho} \\dot{\\phi}) \\hat{e_{\\phi}}\\\\\r\n\ta_{\\rho}&=\\left(\\ddot{\\rho}-\\rho \\dot{\\phi}^{2}\\right) \\hspace{0.62cm}-\\text{ Radial acceleration component.}\\\\\r\n\ta_{\\phi}&=(\\rho \\ddot{\\phi}+2 \\dot{\\rho} \\dot{\\phi})\\quad -\\text{ Azimuthal acceleration component.}\\\\\r\n\t|a|&=\\sqrt{a_{\\rho}^{2}+a_{\\phi}^{2}}\r\n\t\\end{align*}\r\n\t\r\n\\end{itemize}\r\n%--------------------------------------------\r\nThe Cylindrical and spherical polar systems are the three-dimensional relatives of the two-dimensional polar coordinate system. Let us look into those systems.\r\n\\section{ Cylindrical Polar Co-Ordinate System}\r\n\r\n\\begin{wrapfigure}{r}{0.32\\textwidth}\r\n\t\\begin{center}\r\n\t\t\\includegraphics[width=6cm,height=5cm]{cylindrical 1}\r\n\t\\end{center}\r\n\t\\caption{Cylindrical Polar Coordinate system}\r\n\t\\label{Cylindrical Polar Coordinate system}\r\n\\end{wrapfigure}\r\nWe make the use of Cylindrical polar coordinate system when there is a \\textbf{cylindrical symmetry} in the form of a physical object.  Polar coordinates can be extended to three dimensions in a very straightforward manner. We simply add\r\nthe z coordinate, which is then treated in a cartesian like manner. Every point in space is determined by\r\nthe $\\rho$ and $\\theta$ coordinates of its projection in the xy plane, and its z coordinate.\r\n\\\\ In the figure  \\ref{Cylindrical Polar Coordinate system} ,$\\rho$\\ is the distance of the foot of the perpendicular drawn from the point to the $x-y(\\rho, \\theta)$\\ plane.\r\nNote that $\\rho$ here is not the distance of the point $\\mathrm{P}$ from the origin, as is the case in polar coordinate systems.\\\\The range of the coordinate varies as,\\begin{align*}\r\n0 &\\leq \\rho \\leq \\infty\\\\\r\n0 &\\leq \\phi \\leq 2 \\pi\\\\\r\n-\\infty &\\leq z \\leq+\\infty\r\n\\intertext{In terms of cartesian coordinates  }\r\nx&=\\rho \\cos \\phi \\\\\r\ny&=\\rho \\sin \\phi \\\\\r\nz&=z\r\n\\end{align*}\r\nWe can change the basis of a \r\nvector in cylindrical coordinate system to cartesian. Any vector $\\vec{A}$ can be expressed in terms of them in the usual way,\r\n$$\r\n\\vec{A}=A_{\\rho} \\hat{e_{\\rho}}+A_{\\phi} \\hat{\\phi}+A_{z} \\hat{z}\r\n$$\r\nIn matrix form we can write,\r\n$$\r\n\\begin{aligned}\r\n&\\left[\\begin{array}{c}\r\nA_{\\rho} \\\\\r\nA_{\\phi} \\\\\r\nA_{z}\r\n\\end{array}\\right]=\\left[\\begin{array}{ccc}\r\n\\cos (\\phi) & \\sin (\\phi) & 0 \\\\\r\n-\\sin (\\phi) & \\cos (\\phi) & 0 \\\\\r\n0 & 0 & 1\r\n\\end{array}\\right]\\left[\\begin{array}{l}\r\nA_{x} \\\\\r\nA_{y} \\\\\r\nA_{z}\r\n\\end{array}\\right]\r\n\\end{aligned}\r\n$$\r\n\r\n\\subsection{ Unit Vectors}\r\nThe unit vectors $\\hat{e_{\\rho}}, \\hat{\\phi}$ and $\\hat{e_{z}},$ expressed in cartesian coordinates, are,\r\n$$\r\n\\begin{array}{l}\r\n\\hat{e_{\\rho}}=\\cos \\phi \\hat{e_{x}}+\\sin \\phi \\hat{e_{y}} \\\\\r\n\\hat{e_{\\phi}}=-\\sin \\phi \\hat{e_{x}}+\\cos \\phi \\hat{e_{y}}\\\\\r\n\\hat{e_{z}}=\\hat{e_{z}}\r\n\\end{array}\r\n$$\r\n\r\n\\subsection{Line, Area and Volume Elements}\r\n\\begin{itemize}\r\n\t\\item  \\textbf{Line element} \r\n\t$$\r\n\t\\overrightarrow{d l}= d \\rho \\hat{e_{\\rho}}+\\rho d \\phi \\hat{\\phi}+d \\hat{e_{z}}\r\n\t$$\r\n\t\r\n\t\\item \\textbf{Area element }\r\n\t\\\\ Orthogonal surfaces in cylindrical coordinate system can be generated in three ways.\\\\\\\\ i.e., $\\rho=$ constant,  $\\phi=$ constant,\r\n\t$\\mathrm{z}=$ constant.\r\n\t\\begin{align*}\r\n\t\\rho&= \\text{constant : A circular cylinder} \\Rightarrow d A=\\rho d \\phi d z\\\\\r\n\t\\phi&=\\text{constant : A semi infinite plane with its edge along $\\mathrm{z}$ axis} \\Rightarrow d A= \\phi d\\rho   d z \\\\\r\n\t\\mathrm{z}&= \\text{constant : An infinite plane as in the rectangular system.}\\Rightarrow d A= zd\\phi d\\rho   \r\n\t\\end{align*}\r\n\t\r\n\t\r\n\t\r\n\t\\begin{figure}[h]\r\n\t\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\t\\includegraphics[width=6cm,height=6cm]{cylindrical 3}\r\n\t\t\t\\caption{Constant $\\rho$ surface}\r\n\t\t\t\r\n\t\t\\end{minipage}\\hspace{0.5cm}\r\n\t\t\\begin{minipage}{0.35\\textwidth}\r\n\t\t\t\\includegraphics[width=6cm,height=6cm]{cylindrical 2}\r\n\t\t\t\\caption{Constant $\\phi$ surface}\r\n\t\t\\end{minipage}\r\n\t\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\t\\includegraphics[width=6cm,height=6cm]{cylindrical 4}\r\n\t\t\t\\caption{Constant $z$ surface}\r\n\t\t\\end{minipage}\r\n\t\\end{figure}\r\n\t\\item   \\textbf{Volume element}\r\n\t$$\r\n\td V=\\rho d \\phi d \\rho d z\r\n\t$$\r\n\t\\end {itemize}\r\n\t\r\n\t\\subsection{Kinematic Vectors in  Cylindrical Polar Coordinate System}\r\n\t\\begin{itemize}\r\n\t\t\\item \\textbf{Velocity Vector}\r\n\t\t\\begin{align*}\r\n\t\t\\boldsymbol{v}&=\\dot{\\rho} \\hat{e_{\\rho}}+{\\rho} \\dot{\\phi} \\hat{\\phi}+\\dot{z} \\boldsymbol{k}\\\\\r\n\t\t\\text{Where,}\\quad  v_{\\rho}&=\\dot{\\rho}\\quad;\\quad v_{\\phi}=r \\dot{\\phi}\\quad;\\quad v_{z}=\\dot{z}\\\\ \\text{And} \\quad\r\n\t\tv&=\\sqrt{v_{\\rho}^{2}+v_{\\phi}^{2}+v_{z}^{2}} \\\\\\intertext{Where $ \\dot{\\rho}$  is radial velocity in $ \\hat{e_{\\rho}} $ direction and $ r \\dot{\\phi}$  is tangential velocity in $ \\hat{\\phi} $ direction}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\\item \\textbf{Acceleration Vector}\r\n\t\t\\begin{align*}\r\n\t\t\\boldsymbol{a}&=\\left(\\ddot{\\rho}-\\rho \\dot{\\phi}^{2}\\right) \\hat{e_{\\rho}}+(\\rho \\ddot{\\phi}+2 \\dot{\\rho} \\dot{\\phi}) \\hat{\\phi}+\\ddot{z} \\boldsymbol{k}\\\\\r\n\t\t\\text{Where}  \\quad a_{\\rho}&=\\ddot{\\rho}-\\rho \\dot{\\phi}^{2}\\quad;\\quad a_{\\phi}=\\rho \\ddot{\\phi}+2 \\dot{\\rho} \\dot{\\phi}\\quad;\\quad a_{z}=\\ddot{z}\\\\ \\text{And}\\quad a&=\\sqrt{a_{\\rho}^{2}+a_{\\phi}^{2}+a_{z}^{2}}\r\n\t\t\\end{align*}\r\n\t\t\r\n\t\t\r\n\t\t\\end {itemize}\r\n\t\t\r\n\t\t%------------------------------------------------------\r\n\t\t\\section{Spherical Polar Co-Ordinate System}\r\n\t\t\r\n\t\tWe make  use of Spherical polar coordinate system when there is a \\textbf{Spherical symmetry} in the form of a physical object. \r\n\t\tIn spherical polar coordinates, we utilize two angles and a distance to specify the position of a particle. Every point in space is determined by\r\n\t\tthe $r$ , $\\theta$  and $\\phi $ coordinates.\r\n\t\tThe range of coordinates varies as, \\\\\r\n\t\t\\begin{minipage}{0.45\\textwidth}\r\n\t\t\t\\begin{align*}\r\n\t\t\t0 &\\leq r \\leq \\infty\\\\\r\n\t\t\t0 &\\leq \\theta \\leq \\pi\\\\\r\n\t\t\t0&\\leq \\phi \\leq 2\\pi\r\n\t\t\t\\end{align*}\r\n\t\t\tIf you are given spherical coordinates $(r, \\theta, \\phi)$ of a point in the plane.The Cartesian coordinates $(x, y, z)$ can be determined from the coordinate transformations.\r\n\t\t\t\r\n\t\t\t\\begin{align*}\r\n\t\t\tx&=r \\sin \\theta \\cos \\phi \\\\\r\n\t\t\ty&=r \\sin \\theta \\sin \\phi \\\\\r\n\t\t\tz&=r \\cos \\theta\r\n\t\t\t\\end{align*}\r\n\t\t\\end{minipage}\r\n\t\\begin{minipage}{0.45\\textwidth}\r\n\t\\begin{figure}[H]\r\n\t\t\\centering\r\n\t\\includegraphics[width=7cm,height=6.5cm]{spherical 1}\r\n\t\t\\caption{Spherical Polar Coordinate system}\r\n\t\t\\label{Spherical Polar Coordinate system}\r\n\t\\end{figure}\r\n\t\\end{minipage}\r\n\t\t\r\n\t\r\n\t\t\\subsection{Unit Vectors}\r\n\t\tCurresponding to radial distance(r), polar distance ($\\theta$) and azimuthal angle ($\\phi$) We have three orthogonal unit vectors in SPC and they constitute an orthonormal basis $\\left\\lbrace \\hat{e_{r}},\\hat{e_{\\theta}},\\hat{e_{\\phi}} \\right\\rbrace $. The unit vectors also are related by the coordinate transformations\r\n\t\t$$\r\n\t\t\\begin{array}{l}\r\n\t\t\\hat{e_{r}}=\\sin \\theta \\cos \\phi \\hat{e_{x}}+\\sin \\theta \\sin \\phi \\hat{e_{y}}+\\cos \\theta \\hat{e_{z}} \\\\\r\n\t\t\\hat{e_{\\theta}}=\\cos \\theta \\cos \\phi \\hat{e_{x}}+\\cos \\theta \\sin \\phi \\hat{e_{y}}-\\sin \\theta \\hat{e_{z}} \\\\\r\n\t\t\\hat{e_{\\phi}}=-\\sin \\phi \\hat{e_{x}}+\\cos \\phi \\hat{e_{y}}\r\n\t\t\\end{array}\r\n\t\t$$\r\n\t\t In matrix representation,\r\n\t\t$$\\left[\\begin{array}{c}\r\n\t\t\t\\hat{e_{r}} \\\\\r\n\t\t\t\\hat{e_{\\theta}} \\\\\r\n\t\t\t\\hat{e_{\\phi}}\r\n\t\t\\end{array}\\right]=\\left[\\begin{array}{ccc}\r\n\t\t\t\\sin \\theta \\cos \\phi & \\sin \\theta \\sin \\phi & \\cos \\theta \\\\\r\n\t\t\t\\cos \\theta \\cos \\phi & \\cos \\theta \\sin \\phi & -\\sin \\theta \\\\\r\n\t\t\t-\\sin \\phi & \\cos \\phi & 0\r\n\t\t\\end{array}\\right]\\left[\\begin{array}{c}\r\n\t\t\t\\hat{e_{x}} \\\\\r\n\t\t\t\\hat{e_{y}} \\\\\r\n\t\t\t\\hat{e_{z}}\r\n\t\t\\end{array}\\right]$$\r\n\t\tThe inverse transformation will be\r\n\t\t\t$$\\left[\\begin{array}{c}\r\n\t\t\t\\hat{e_{x}} \\\\\r\n\t\t\t\\hat{e_{y}} \\\\\r\n\t\t\t\\hat{e_{z}}\r\n\t\t\\end{array}\\right]=\\left[\\begin{array}{ccc}\r\n\t\t\\sin \\theta \\cos \\phi & \\cos \\theta \\cos \\phi & -\\sin \\phi \\\\\r\n\t\t\\sin \\theta \\sin \\phi & \\cos \\theta \\sin \\phi & \\cos \\phi \\\\\r\n\t\t\\cos \\theta & -\\sin \\theta & 0\r\n\t\t\\end{array}\\right]\\left[\\begin{array}{c}\r\n\t\t\\hat{e_{r}} \\\\\r\n\t\t\\hat{e_{\\theta}} \\\\\r\n\t\t\\hat{e_{\\phi}}\r\n\t\t\\end{array}\\right]$$\r\n\t\t\tThen any vector $\\vec{A}$ can be expressed in terms of them in the usual way:\r\n\t\t\\begin{align*}\r\n\t\t\\vec{A}&=A_{r} \\hat{e_{r}}+A_{\\theta} \\hat{e_{\\theta}}+A _{\\phi} \\hat{e_{\\phi}}\\\\\r\n\t\tA_{r}&=A_{x} \\sin \\theta \\cos \\phi+A_{y} \\sin \\theta \\sin \\phi+A_{z} \\cos \\theta\\\\\r\n\t\tA_{\\theta}&=A_{x} \\cos \\theta \\cos \\phi+A_{y} \\cos \\theta \\sin \\phi-A_{z} \\sin \\theta\\\\\r\n\t\tA_{\\phi}&=-A_{x} \\sin \\phi+A_{y} \\cos \\phi\r\n\t\t\\intertext{\tIn matrix form we can write}\r\n\t\t\\left[\\begin{array}{c}\r\n\t\tA_{r} \\\\\r\n\t\tA_{\\theta} \\\\\r\n\t\tA_{\\phi}\r\n\t\t\\end{array}\\right]&=\\left[\\begin{array}{ccc}\r\n\t\t\\sin \\theta \\cos \\phi & \\sin \\theta \\sin \\phi & \\cos \\theta \\\\\r\n\t\t\\cos \\theta \\cos \\phi & \\cos \\theta \\sin \\phi & -\\sin \\theta \\\\\r\n\t\t-\\sin \\phi & \\cos \\phi & 0\r\n\t\t\\end{array}\\right]\\left[\\begin{array}{c}\r\n\t\tA_{x} \\\\\r\n\t\tA_{y} \\\\\r\n\t\tA_{z}\r\n\t\t\\end{array}\\right]\r\n\t\t\\end{align*}\r\n\t\t\\subsection{Line, Area ,Volume Elements}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item\\textbf{ Line element}$$d \\vec{{l}}=d r \\hat{e_{r}}+r d \\theta \\hat{e_{\\theta}}+r \\sin \\theta d \\phi \\hat{e_{\\phi}}$$\r\n\t\t\t\\item \\textbf{Area element}\\\\\r\n\t\t\t\\\\ Orthogonal surfaces in Spherical polar coordinate system can be generated in three ways \\\\ i.e., $r=$ constant $\\phi=$ constant and \r\n\t\t\t$\\mathrm{z}=$ constant.\r\n\t\t\t\\begin{align*}\r\n\t\t\tr&= \\text{constant : A sphere.}\\Rightarrow d A_{r}=r^{2} \\sin \\theta d \\theta d \\phi  \\\\\r\n\t\t\t\\theta&=\\text{constant : A cone.} \\Rightarrow d A_{\\theta}=r \\sin \\theta d r d \\phi \\\\\r\n\t\t\t\\phi&= \\text{constant : An semi infinite plane as in the rectangular system.} \\Rightarrow d A_{\\phi}=r d r d \\theta \r\n\t\t\t\\end{align*}\r\n\t\t\t\r\n\t\t\t\\begin{figure}[h]\r\n\t\t\t\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\t\t\t\\includegraphics[width=6.5cm,height=6cm]{spherical 2}\r\n\t\t\t\t\t\\caption{Constant $r$ surface}\r\n\t\t\t\t\\end{minipage}\\hspace{0.5cm}\r\n\t\t\t\t\\begin{minipage}{0.35\\textwidth}\r\n\t\t\t\t\t\\includegraphics[width=6cm,height=6cm]{spherical 5}\r\n\t\t\t\t\t\\caption{Constant $\\theta$ surface}\r\n\t\t\t\t\\end{minipage}\r\n\t\t\t\t\\begin{minipage}{0.30\\textwidth}\r\n\t\t\t\t\t\\includegraphics[width=6.5cm,height=6cm]{spherical 4}\r\n\t\t\t\t\t\\caption{Constant $\\phi$ surface}\r\n\t\t\t\t\\end{minipage}\r\n\t\t\t\\end{figure}\r\n\t\t\t\r\n\t\t\t\\item \\textbf{Volume elment}\r\n\t\t\t$$\r\n\t\t\td V=r^{2}d r \\sin \\theta d \\theta d \\phi \r\n\t\t\t$$\r\n\t\t\\end{itemize}\r\n\t\t\r\n\t\t\\subsection{Kinematic Vectors in Spherical Polar Coordinate System}\r\n\t\t\\begin{itemize}\r\n\t\t\t\\item\t\\textbf{Velocity Vector}\\begin{align*}\r\n\t\t\t\\vec{v}&=\\dot{\\vec{r}}\\\\&=\\dot{\\hat{e_{r}}} r+\\hat{e_{r}} \\dot{r} \\\\\r\n\t\t\t\\vec{v}&=\\hat{e_{r}} \\dot{r}+\\hat{e_{\\theta}} r \\dot{\\theta}+\\hat{e_{\\phi}} r \\dot{\\phi} \\sin \\theta\r\n\t\t\t\\end{align*}\r\n\t\t\t\\item \\textbf{Acceleration Vector}\r\n\t\t\t\\begin{align*}\r\n\t\t\t\\vec{a}=&\\hat{e_{r}}\\left(\\ddot{r}-r \\dot{\\theta}^{2}-r \\dot{\\phi}^{2} \\sin ^{2} \\theta\\right)+\\hat{e_{\\theta}}\\left(r \\ddot{\\theta}+2 \\dot{r} \\dot{\\theta}-r \\dot{\\phi}^{2} \\sin \\theta \\cos \\theta\\right)\\\\&+\\hat{e_{\\phi}}(r \\ddot{\\phi} \\sin \\theta+2 r \\dot{\\theta} \\dot{\\phi} \\cos \\theta+{2 \\dot{r} \\dot{\\phi} \\sin \\theta})\\\\\r\n\t\t\t\\intertext{Where,}\r\n\t\t\ta_{r}&=\\left(\\ddot{r}-r \\dot{\\theta}^{2}-r \\dot{\\phi}^{2} \\sin ^{2} \\theta\\right)\\\\\r\n\t\t\ta_{\\theta}&=\\left(r \\ddot{\\theta}+2 \\dot{r} \\dot{\\theta}-r \\dot{\\phi}^{2} \\sin \\theta \\cos \\theta\\right)\\\\\r\n\t\t\ta_{\\phi}&=(r \\ddot{\\phi} \\sin \\theta+2 r \\dot{\\theta} \\dot{\\phi} \\cos \\theta+2 \\dot{r} \\dot{\\phi} \\sin \\theta)\r\n\t\t\t\\end{align*} \r\n\t\t\t\r\n\t\t\t\\end {itemize}\r\n\t\t\t\r\n\t\t\t%----------------------------------------------\r\n\t\t\t\\begin{table}[H]\r\n\t\t\t\t\\centering\r\n\t\t\t\t\\renewcommand*{\\arraystretch}{2}\r\n\t\t\t\t\\arrayrulecolor{ocre}\r\n\t\t\t\t\r\n\t\t\t\t\\begin{tabular}{|p{3cm}|p{3.5cm}|p{2.5cm}|p{3.5cm}|}\r\n\t\t\t\t\t\\hline\r\n\t\t\t\t\t\\multicolumn{4}{|c|}{\\textbf{Co-ordinate systems}}\\\\\\hline\r\n\t\t\t\t\t\\textbf{System}&\\textbf{Symmetry}&\\textbf{Co-ordinates}\r\n\t\t\t\t\t&\\textbf{Length elements}\\\\\\hline\r\n\t\t\t\t\tCartesian &Rectangular &$x,y,z$&$dx,dy,dz$\\\\\\hline \r\n\t\t\t\t\tPolar&Circular symmetry &$r ,\\theta $&$dr ,r d\\theta $ \\\\\\hline\r\n\t\t\t\t\tCylindrical polar&Cylindrical symmetry &$r ,\\theta,z $&$dr ,r d\\theta, dz $ \\\\\\hline\r\n\t\t\t\t\tSpherical polar&Spherical symmetry &$r ,\\theta ,\\phi$&$dr ,r d\\theta, r \\sin \\theta d\\phi $\\\\\\hline\r\n\t\t\t\t\t\r\n\t\t\t\t\\end{tabular}\r\n\t\t\t\t\\caption{Basic summary of Coordinate system.}\r\n\t\t\t\\end{table}\r\n\t\t\t\r\n", "meta": {"hexsha": "7082194f8bb835cee8e6658c4c8a57df3cfbcbe2", "size": 23246, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/coordinate.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/coordinate.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/coordinate.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": 47.5378323108, "max_line_length": 674, "alphanum_fraction": 0.6408844532, "num_tokens": 8320, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9046505351008904, "lm_q2_score": 0.8333245911726382, "lm_q1q2_score": 0.7538675373170579}}
{"text": "\\section[Bayesian Inference]{Lecture 2: Bayesian Inference}\n\n'Bayesian Inference' refers to computation of the posterior distribution over parameters given the data.\n\n\\begin{itemize}\n\\item Data $\\mathcal{D}=\\{t_1, t_2, \\ldots, t_N\\}$\n\\item Supervised learning: $\\mathcal{D}=\\{(x_1,t_1), (x_2,t_2), \\ldots, (x_N,t_N)\\}$\n\\item Likelihood function $P(t|w)$ \\hspace{1cm}(parameterized by $w$)\n\\item $P(D|w)= \\prod_{n=1}^N P(t_n|w)$ Independence assumption\n\\item Prior distribution $\\pi(w)$\n\\item Bayes rule: $\\mbox{Posterior} \\propto \\mbox{Likelihood}  \\times \\mbox{Prior}$\n\\begin{align}\nP(w | D) =\\frac{1}{Z} P(D|w) P(w)\n\\end{align}\n\\item Probabilities must normalize to $1$: \n\\begin{align}\nZ= P(D)= \\int P(D|w) P(w) dw\n\\end{align}\nMarginalization is the difficult part in Bayesian inference, how we can get arund this step will be shown in a later section\n\\end{itemize}\n\n\\subsection{Usage of the posterior distribution}\n\n\t\\begin{itemize}\n\t\t\\item Predictive Distribution\n\t\t\\begin{align}\n\t\t\tP(t^*|x^*, D)= \\int_w P(t^*| x^*, w) P(w| D)   dw\n\t\t\\end{align}\n\t\twhere $(t^*,x^*)$ is a new observation\n\n\t\t\\item Decision making\n\t\tSuppose we have calculated $P(t^*|x^*, D)$, and someone asks us to give a guess $\\hat t$ of $t^*$. While we could just take the \\emph{most likely value} of $t^*$, it really depends on the cost function. Are mistakes in one direction as costly as mistakes in the other direction? For example, what is the cost of a false positive or false negative? Given a {cost function} $C(\\hat t, t)$, one can calculate the 'Bayes-optimal' decision from the posterior distribution. \n\t\t\\item Scientific statements\n\t\te.g. 'After observing 100 data points, we were 90\\% sure that the parameter $\\theta$ is between -.1 and .3. Now that we have observed another 200, we are 97\\% sure.'\n\t\\end{itemize}\n\t\n\\subsection{Alternatives to a full Bayesian treatment}\nIn most cases, the posterior distribution can not be calculated exactly, and approximations have to be used.\n\\begin{itemize}\n\\item Ignore prior, maximize likelihood $P(D|w)$: {Maximum likelihood learning}\n\\item Only search for mode of posterior ({Maximum a posteriori, MAP}), i.e. $\\mbox{argmax}_w P(w |D) $. In practice, maximize log-posterior.\\\\\n\\end{itemize}\n\n\\begin{bbbox}{Maximum a posteriori}\n\\textcolor{gray}{Q: Why is finding the mode of the posterior so much easier than finding the full posterior?}\\\\\nIt is a point estimate similar to ML, this makes the approach similarly expensive in computational terms.\nWe can escape the intractability of the normalization constant.\n\n\\textcolor{gray}{Q: When is MAP a really bad idea?}\n\\begin{itemize}\n\t\\item multiple local maxima\n\t\\item Very skewed posterior distribution\n\\end{itemize} \n\\end{bbbox}\n\n\\begin{itemize}\n\\item Use simplified model to approximate posterior: Find parameters of model $q(w,\\Phi)$ such that\n$q(w) \\approx P(w|D)$. \\\\\n\n\\item Examples: Varational Inference, Expectation Propagation, Laplace Approximation\n\\item Very often, a Normal approximation is used: $q(w) \\approx \\mathcal{N}(w|\\mu,\\Sigma)$.\n\\item Use MCMC sampling to generate samples from posterior distribution\n\\end{itemize}\n\n\t\t\n\n\\subsection{Coin flip example}\n\\begin{itemize}\n\\item Suppose we have $N$ throws of a coin, $D=\\{t_1, t_2, \\ldots, t_N\\}$\n\\item We write $T_n= 1$ if the n-th throw was head, and $t_n=0$ if it was tail.\n\\item One parameter:  $q\\in [0, 1]$, the probability of obtaining heads\n\\item Likelihood of one throw:\n\\begin{align}\n P(T_n=1|q)&= q\\\\\n P(T_n=0|q)&= (1-q)\n\\end{align}\nMultiple throws: Bernoulli process\n\\item Likelihood of data $D$: [on board]\n\\end{itemize}\n\\begin{bbbox}{Bernoulli likelihood}\n\\begin{flalign*}\n\tP(T_n = t | q) &= q^t (1-q)^{1-t}  \\\\\n\tP(D | q) &= \\prod_{n_1}^N q^{t_n} (1-q)^{1-t_n}\n\\end{flalign*}\n\\end{bbbox}\n\n\\subsubsection{The beta distribution as a conjugate prior for the Bernoulli distribution}\nThe shape of the distribution is determined by two parameters.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{./lecture2/BetaZoo}\n\\caption{The beta distribution for different parameter configurations. Notice the symmetricity for $\\alpha_1 = \\alpha_2$. A prior distribution reflects our beliefs about the parameters. If we have no beliefs we will stick to a flat prior in the upper left corner. Whereas if we believe $q$ to be close to $1$ we might prefer to use the prior in the lower left corner.}\n\\end{figure}\n\n\n\\begin{itemize}\n\\item \nBeta distribution: \n\\begin{align}\n\\pi(q| \\alpha, \\alpha_{2})= \\frac{1}{Z}q^{\\alpha_1-1} (1-q)^{\\alpha_{2}-1}\n\\end{align}\n\\item Normalizing constant: the 'beta function'\n\\begin{align}\nZ= \\int_0^1 q^{\\alpha_1-1} (1-q)^{\\alpha_{2}-1} dq=: B(\\alpha_1, \\alpha_{2})\n\\end{align}\nHowever there is no need to calculate this constant due to the conjugacy. We will see more on that in a later section.\n\\item Mean and Variance:\n\\begin{align}\n\\mbox{E}(q|\\alpha_1,\\alpha_{2})&= \\frac{\\alpha_1}{\\alpha_1+\\alpha_{2}}\\\\\n\\mbox{Var}(q|\\alpha_1,\\alpha_{2})&= \\frac{\\alpha_1\\alpha_{2}}{(\\alpha_1+\\alpha_{2})^2(\\alpha_1+\\alpha_{2}+1)}\n\\end{align}\n\\item Symmetric case and heuristics:  [on board]\n\\end{itemize}\n\n\\begin{bbbox}{Symmetric case and heuristics}\n\\begin{align*}\n\tSay: \\; \\alpha_1 = \\alpha_2 \\\\\n\tthen \\mbox{E}(q|\\alpha_1,\\alpha_{2})&= \\frac{\\alpha_1}{\\alpha_1+\\alpha_{2}}\\\\\n\t&= \\frac{\\alpha_1}{2 \\alpha_1} = 0.5\\\\\n\t\\mbox{Var}(q|\\alpha_1,\\alpha_{2})&= \\frac{\\alpha_1^2}{(2\\alpha_1)^2(2\\alpha_1 + 1)} \\\\\n\t\t\t\t\t\t\t\t\t &= \\frac{1}{4(2\\alpha_1 + 1)}\n\\end{align*}\nThat means for $\\alpha_1 = \\alpha_2 \\rightarrow \\infty : \\mbox{Var}(q|\\alpha_1,\\alpha_{2}) \\rightarrow 0$\n\\end{bbbox}\n\n\\subsubsection{Posterior inference}\n\n\\begin{bbbox}{Posterior inference}\nWe use $S_n$ to denote the number of heads on the first $n$ trials.\n$S_N = \\sum_{n_1}^N t_n$\n\\vspace{.5cm}\nMaximum likelihood estimation:\n$L(D,q) = log P(D,q) = \\sum_{n_1}^N t_n log(q) + (1-t_n) log(1-q) = log(q) S_N + log(1-q)(N-S_N)$\\\\\nFind the q for which the log likelihood is maximized, such that\n$\\frac{\\partial L(D,q)}{\\partial q} = 0$\\\\\n$\\frac{\\partial L(D,q)}{\\partial q} = \\frac{S_N}{q} - \\frac{N-S_N}{1-q} = 0$\\\\\n$\\frac{q}{S_N} = \\frac{1-q}{N-S_N}$ \\\\\n$q = \\frac{S_N}{N}$\n\\vspace{.5cm}\n[on board]\n\n\\vspace{.5cm}\nPosterior distribution:\n\\begin{align}\nP(q | D) &= \\frac{1}{Z}P(D|q)P(q) \\\\\n&= \\frac{1}{Z} \\prod_{n=1}^N q^{t_n} (1-q)^{1-t_n} \\frac{1}{B(\\alpha_1,\\alpha_2)} q^{\\alpha_1 -1} (1-q)^{\\alpha_2 - 1} \\nonumber \\\\\n&= \\frac{1}{Z_2} q^{S_N} (1-q)^{N - S_N} q^{\\alpha_1 -1} (1-q)^{\\alpha_2 - 1} \\nonumber \\\\\n&= \\frac{1}{Z_2} q^{S_N + \\alpha_1 -1} (1-q)^{N - S_N + \\alpha_2 - 1} \\nonumber \\\\\nwhere \\; Z_2 &= B(S_N + \\alpha_1, N - S_n + \\alpha_2) \\nonumber\n\\end{align}\n\n$q | D \\backsim Beta(S_N + \\alpha_1, N - S_n + \\alpha_2)$ \\\\\n\\vspace{.5cm}\n[on board]\n\\end{bbbox}\n\n\\vspace{.5cm}\nWe can either take all the data and calculate the posterior at once, or do it sequentially as new data comes in:\n\\vspace{.5cm}\n[on board]\n\nData: $D=\\{1     1     0     1     1     1     1     1     0\\}$\n\n\\includegraphics[width=\\textwidth]{./lecture2/BetaPosterior}\n\n\\subsubsection{Predictive distribution}\n\\vspace{.5cm}\nAfter observing $N$ coin-flips, what is our prediction for the next coin flip?\n\\begin{align}\nP(T^*=1| D)&= \\int_0^1 P(T^*=1|q) P(q|D) dq\\\\\n& = \\int_0^1 q P(q|D) dq\\\\\n&= \\mbox{E}(q|D) \\\\\n&=\\frac{\\alpha_1+S_N}{(\\alpha_1+ S_N)+(\\alpha_{2}+N-S_N)}\\\\\n&=\\frac{\\alpha_1+S_N}{(\\alpha_1+\\alpha_2+N)}\n\\end{align}\n\n\\vspace{.5cm}\nIn our example, $\\mbox{E}(q|D)=0.69$, and $\\mbox{MLE}=0.78$. \n\n\\begin{bbbox}{What happens if $N$ gets very large?}\n\nFor $ \\alpha_1,\\alpha_2 \\rightarrow 0$ or $ S_N , N \\rightarrow \\infty $ the prediction will approach the maximum likelihood solution.\n\\end{bbbox}\n\n\\vspace{.5cm}\nNote: This is a bit of a special case-- in general, the predictive distribution is not simply the likelihood evaluated at the mean!!!\n\n\n\\subsubsection{Statistical Reasoning}\n\\includegraphics[width=\\textwidth]{./lecture2/BetaPosteriorConfidence}\n\n\\subsubsection{Decision making}\nSomeone offers you the bet that you get 1 euros if you predict the next coin toss correctly, but you have to pay 2 euros if if you are wrong. \n\nShould you take the bet? What should you predict?\n\n\\begin{align}\nC(t^*,\\hat t)=\n\\begin{cases}\n-1 &\\mbox{if~} t^*= \\hat t\\\\\n2 &\\mbox{if~} t^*\\neq \\hat t\\\\\n\\end{cases}\n\\end{align}\n\nExpected cost: \n\\begin{align}\nE(C)=\\sum_{t^*=0}^1 C(t^*,\\hat t) P(t^*| D)\n\\end{align}\n\nIf we predict tail ($t^*=0$): \n\\begin{align}\nE(C)&= P(t^*=1|D) C(0,1)+P(t^*=0|D) C(0,0)  \\\\\n&=0.69 (2)  + 0.31 (-1)= 1.07\n\\end{align}\n\nIf we predict head ($t^*=1$): \n\\begin{align}\nE(C)=0.69 (-1)  + 0.31 (2)= -0.07;\n\\end{align}\n\n\\subsection{The exponential family and conjugate priors}\nWhy was inference so easy here?\n\n\\begin{itemize}\n\\item Posterior distribution had a closed form solution.\n\\item In fact, the posterior had the same functional form as the prior, just different parameters.\n\\item Parameters of posterior could be calculated by simply adding observations to prior parameters.\n\\item We used a likelihood from the {exponential family} and its {conjugate prior}. In this case,  Bayesian inference is always easy.\n\\item For this reason, exponential families and conjugate priors are used extensively in Bayesian modelling, often as 'building blocks' of more complicated models.\n\\end{itemize}\n\n\nInference is easy whenever the likelihood is in the exponential family and the prior is its conjugate.\n\\begin{itemize}\n\\item Exponential family distributions  have the form \n\\begin{align}\nP(\\xx|\\theta)&= g(\\theta) f(\\xx) \\exp\\left(\\phi(\\theta)^\\top S(\\xx)\\right)\n\\end{align}\n\n\\item The conjugate prior is\n\\begin{align}\n\\pi(\\theta)&= F(\\tau,\\nu) g(\\theta)^\\nu \\exp(\\phi(\\theta)^\\top \\tau)\n\\end{align}\n\\item Calculating the posterior:\n\\begin{align}\n [\\mbox{on board}]\n\\end{align}\n\\end{itemize}\n\nThe posterior given an exponential family likelihood and conjugate prior is \n\\begin{align}\nP(\\theta|D)= F(\\tau+ \\sum_i S(x_i), \\nu+N) g(\\theta)^{\\nu+N} \\exp\\left(\\phi(\\theta)^\\top(\\tau +\\sum_i S(x_i)    )\\right)\n\\end{align}\n\n\\begin{itemize}\n\\item $\\phi(\\theta)$ is the vector of {natural parameters}\n\\item $\\sum_i S(x_i)$ is the vector of {sufficient statistics}\n\\item $\\tau$ are {pseudo-observations}\n\\item $\\nu$ is the scale of the prior\\\\\n\\end{itemize}\n\nThe exponential family includes most common distributions, including the Normal, Exponential, Gamma, Chi-square, Beta, Dirichlet, Bernoulli, Poisson, Wishart and the Inverse Wishart.\n\n\\begin{bbbox}{How can we put our coin-example into this framework?}\n\\begin{align*}\n\tP(x | \\theta) &= \\theta^x (1-\\theta)^{1-x} \\\\\n\t              &= \\theta^x (1-\\theta)(1-\\theta)^{-x} \\\\\n\t              &= (1-\\theta) \\exp\\left(\\log\\left(\\theta^x (1-\\theta)^{-x}\\right)\\right) \\\\\n\t              &= (1-\\theta) \\exp\\left(x \\log\\left(\\frac{\\theta}{1-\\theta}\\right)\\right) \\\\\n        g(\\theta) &= 1 - \\theta \\\\\n             f(x) &= 1 \\\\\n     \\phi(\\theta) &= log\\left(\\frac{\\theta}{1 - \\theta}\\right) : log odds \\\\\n             S(x) &= x\n\\end{align*}\n\\end{bbbox}\n", "meta": {"hexsha": "e295193b47aedd472a721e06471fb3245248ab0c", "size": 10900, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "script/lecture2/lecture2.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/lecture2/lecture2.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/lecture2/lecture2.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": 39.4927536232, "max_line_length": 470, "alphanum_fraction": 0.6828440367, "num_tokens": 3693, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511469672594, "lm_q2_score": 0.8807970701552505, "lm_q1q2_score": 0.7538311827377728}}
{"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 a learning problem where each instance is described by a conjunction of $n$ boolean attributes $A_1$, ..., $A_n$.\nHere, a boolean attribute is an attribute whose domain consists of two values, \\textbf{t} and \\textbf{f}.\nThus, a typical instance would be as given in Expression \\ref{eq31}.\n\n\\begin{equation}\\label{eq31}\n(A_1 = \\textbf{t}) \\wedge (A_2 = \\textbf{f}) \\wedge ... \\wedge (A_n = \\textbf{t})\n\\end{equation}\n\nConsider a hypothesis space \\textit{H} in which each hypothesis is a disjunction of constraints over these attributes.\nFor example, a typical hypothesis would be as given in Expression \\ref{eq32}.\n\n\\begin{equation}\\label{eq32}\n(A_1 = \\textbf{t}) \\vee (A_5 = \\textbf{f}) \\vee (A_7 = \\textbf{t})\n\\end{equation}\n\nDesign an algorithm that accepts a series of training examples and outputs a consistent hypothesis \\textit{if one exists}.\nYour algorithm should run in time that is polynomial in \\textit{n} (the number of attributes) and in \\textit{m}, the number of training examples.\n\n\\subsection*{Solution}\n\nSuppose $\\mathcal{C}_i$ is the concept class containing set of conjunctions of Boolean literals $x_1$, $x_2$, ..., $x_n$, $\\bar{x_1}$, $\\bar{x_2}$, ..., $\\bar{x_n}$.\nThe series of training examples can therefore be defined as shown in Equation \\ref{eq33}.\n\n\\begin{equation}\\label{eq33}\n\\mathcal{C} = \\{\\prod_{j=1}^{n} a_i | 1 \\leq i \\leq m, a_i \\in \\{x_i, \\bar{x_i}, 1\\}\\}\n\\end{equation}\n\nUsing fundamental \\textit{De Morgan}'s laws in boolean algebra, the proposed algorithm would output the consistent hypothesis $\\mathcal{H}$ by taking the complement of the inconsistent hypothesis as shown in Equation \\ref{eq34}.\n\n\\begin{equation}\\label{eq34}\n\\mathcal{H} = \\overline{(\\overline{C_1}\\wedge \\overline{C_2} \\wedge ... \\wedge \\overline{C_m})}\n\\end{equation}\n\nAs $C_i$ is based on conjunction of Boolean literals corresponding to attributes of training instances, we will define $D_i$ as $\\bar{C_i}$ and call it disjunctions of Boolean literals, in conformance to Expression \\ref{eq32}.\nWe can thus rewrite Equation \\ref{eq34} as given below.\n\n\\begin{equation}\\label{eq35}\n\\mathcal{H} = \\overline{(D_1 \\wedge D_2 \\wedge ... \\wedge D_m)}\n\\end{equation}\n\nTherefore, to obtain the concept target it suffices to find disjunctions of $n$ boolean literals for each $D_i$ when $1 \\leq i \\leq m$.\nTo achieve this objective \\textsc{Disjunct} is proposed in Algorithm 2 that outputs disjunctions of Boolean Literals for both positive or negative concepts $C$.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Disjunct}($C$, $i$)}\n\\begin{algorithmic}[1]\n\\If {(example is positive \\textbf{and} $C(a_i) = 0$) \\textbf{or} (example negative \\textbf{and} $C(a_i) = 1$)}\n\\State $term \\leftarrow X_i$\n\\Else\n\\State $term \\leftarrow \\overline{X_i}$\n\\EndIf\n\n\\If {i = 1}\n\\State \\textbf{return} term\n\\Else\n\\State \\textbf{return} \\textsc{Disjunct}($C$, $i-1$) $\\vee$ term\n\\EndIf\n\\end{algorithmic}\n\\end{algorithm}\n\nBy obtaining disjunctions of boolean literals of concept $C$ using \\textsc{Disjunct}($C$, $i$), the main proposed algorithm can be given in Algorithm 3.\n\n\\begin{algorithm}[H]\n\\caption{\\textsc{Find-Target-Concept}}\n\\begin{algorithmic}[1]\n\\State hypothesis $\\leftarrow 1$\n\\For {$i \\leftarrow 1$ to $m$}\n\\State hypothesis $\\leftarrow$ hypothesis $\\wedge$ Disjunct($C_i$, $m$)\n\\EndFor\n\\State \\textbf{return} compliment of hypothesis.\n\\end{algorithmic}\n\\end{algorithm}\n\nAs \\textsc{Disjunct} is a recursive algorithm that calls itself $n$ times for a concept of $n$ attributes, its runtime is $\\mathcal{O}(n)$.\nSince \\textsc{Disjunct} is called once for each $m$ examples, the total runtime of the proposed algorithm would be $\\mathcal{O}(n) + \\mathcal{O}(m) = \\mathcal{O}(nm)$.\n", "meta": {"hexsha": "737bc2ab4c87d106f00e67fe27362ba9dd72fe9b", "size": 4055, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "umb-cs671-2015s/src/tex/hw01/hw01q03.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/hw01q03.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/hw01q03.tex", "max_forks_repo_name": "ghorbanzade/beacon", "max_forks_repo_head_hexsha": "c36e3d1909b9e1e47b1ad3cda81f7f33b713adc4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2019-09-20T05:58:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-06T17:18:05.000Z", "avg_line_length": 47.7058823529, "max_line_length": 228, "alphanum_fraction": 0.7055487053, "num_tokens": 1234, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952921073469, "lm_q2_score": 0.8397339736884711, "lm_q1q2_score": 0.7538252348027352}}
{"text": "\\section{Summation notation, product notation}\n\nOne should read \n\\[\\sum_{k = m}^na_m\\] as the value of \\verb|result| after executing this code:\n\\begin{verbatim}\n    result = 0;\n    for (k = m; k <= n; k = k + 1) {\n        result = result + a_m.\n    }\n\\end{verbatim}\n\nIdeally, most of the time you should see the above sum as just a compactified way to write \n\\[a_m + a_{m + 1} + \\cdots + a_n\\]\n\nNotice that this code does not make sense if $m > n$, because the index $k$ is \\textbf{always} incremented. In this case we always take the sum to be $0$ by default. So a sum like\n\\[\\sum_{k = 1}^0k\\] is equal to $0$, not $1$.\n\nSimilarly for products. one should read \\[\\prod_{k = m}^na_m\\] as the value of \\verb|result| after executing this code:\n\n\\begin{verbatim}\n    result = 1;\n    for (k = m; k <= n; k = k + 1) {\n        result = result * a_m.\n    }\n\\end{verbatim}\n\nAgain this code does not make sense if $m > n$. In this case we always take the product to be $1$ by default.\n\nThe following equations are some useful properties related to summations.\n\\[\\sum_{i = m}^n(a_i + b_i) = \\sum_{i = m}^na_i + \\sum_{i = m}^nb_i\\]\nThe above property is often colloquially referred to as ``splitting a sum''.\n\\[\\sum_{i = m}^nca_i = c\\sum_{i = 1}^ma_i\\] if $c$ is a constant that does not depend on the index $i$.\n\\[\\sum_{i = m}^na_i = a_m + \\sum_{i = m + 1}^na_i\\]\n\\[\\sum_{i = m}^na_i = a_n + \\sum_{i = n}^{n-1}a_i\\]\nNote that the above two equations make sense if $n \\leq m$. (What happens when $n = m$?)\n\nBy yourself come up with some analogous formulas for products.\n\n\\section{The Principle of Mathematical Induction}\n\n\\begin{definition}\n    A proposition $P(n)$ is a logical statement involving some value $n$.\n\\end{definition}\n\nIt is very helpful to consider an example or two. For example, define $P(n)$ to be the logical statement that $n = 1$. In other words, $P(n) \\equiv (n = 1)$. Then $P(n) \\equiv T$ if and only if $n = 1$, which is true but is silly to say. Another example: define $P(n) \\equiv (2 \\mid n)$. Then\n\\[P(n) \\equiv \\begin{cases}T, & 2 \\mid n \\\\ F, & 2 \\nmid n\\end{cases}\\]\n\nBut as of now we aren't really interested in examples like this. We'd like to know if there is a way to show that $P(n) \\equiv T$ for $n \\geq k$ for some integer $k$, for example.\n\nFor example, we'd like to figure out whether or not\n\\[\\sum_{i = 1}^n(2i - 1) = n^2\\] for all $n$. It seems true! But how might we prove it? This leads us to a technique called \\textit{mathematical induction}, a powerful technique which lets us prove classes of statements indexed by the natural numbers. The technique of mathematical induction essentially relies on the following theorem. We will prove this theorem is true in a future section using a property of the natural numbers called the \\textbf{Well-Ordering Principle}.\n\n\\begin{theorem}\nLet $a$ be any natural number. And let $P(k)$ be a proposition about $k \\in \\mathbb{N}$. Assume the following claims are true:\n\\begin{itemize}\n    \\item $P(a) \\equiv T$\n    \\item Assuming $P(k)$ is true for any natural number $k \\geq a$, we can prove that $P(k + 1)$ is true.\n\\end{itemize}\n\nThen $P(k)$ is true for all $k \\geq a$.\n\\end{theorem}\n\nEssentially, suppose you have an indexed family of propositions $P(n)$ which you want to prove true for $n \\geq a$. A proof by mathematical induction is essentially the same as satisfying the hypotheses of the above theorem. Essentially, in a proof by induction you show the following:\n\n\\begin{enumerate}\n    \\item First we show that $P(a) \\equiv T$.\n    \\item Next, assuming that $P(k)$ is true for $k \\geq a$, prove that $P(k + 1)$ is true.\n\\end{enumerate}\n\nHere is an example of this in action. We will prove the first equality stated at the beginning of the chapter.\n\\begin{proposition}\n\\[\\sum_{i = 1}^n(2i - 1) = n^2\\] for all $n$ for all natural numbers $n \\geq 1$.\n\\end{proposition}\n\\begin{proof}\nWe will prove this equality using mathematical induction. First, we observe for $n = 1$ that\n\\[\\sum_{i = 1}^1(2i - 1) = 1 = 1^2.\\]\nNow assume that \n\\[\\sum_{i = 1}^k(2i - 1) = k^2.\\]\nThen\n\\[\\sum_{i = 1}^{k + 1}(2i - 1) = \\sum_{i = 1}^k(2i - 1) + 2(k + 1) - 1 = k^2 + 2k + 1 = (k + 1)^2,\\]\nso we are done.\n\\end{proof}\n\nLet's break down this proof a little bit further. Here the statement $P(n)$ is the statement that the equality \n\\[\\sum_{i = 1}^n(2i - 1) = n^2\\] is true for that specific $n$. In the first part of the proof we show that $P(1)$ is true. In the second part of the proof we show that the truth of $P(k)$ implies the proof of $P(k + 1)$. To do this, we split the sum\n\\[\\sum_{i = 1}^{k + 1}(2i - 1) = \\sum_{i = 1}^k(2i - 1) + 2(k + 1) - 1\\]\ninto two parts. By our hypothesis, the left part is exactly $k^2$. The rest of the prooof simplifies the sum to achieve the desired conclusion: that is to show \n\\[\\sum_{i = 1}^{k + 1}(2i - 1) = (k + 1)^2.\\]\n\n\\section{Exercises}\n\\begin{enumerate}\n    \\item \\input{Ch5/1_ex/problem_2}\n    \\item \\input{Ch5/1_ex/problem_1}\n    \\item \\input{Ch5/1_ex/problem_3}\n    \\item \\input{Ch5/1_ex/problem_4}\n    \\item \\input{Ch5/1_ex/problem_5}\n    \\item \\input{Ch5/1_ex/problem_6}\n\\end{enumerate}\n\n", "meta": {"hexsha": "8468db9200262195e7d604995f047c3f3217dcc4", "size": 5103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Ch5/weak_ind.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": "Ch5/weak_ind.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": "Ch5/weak_ind.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": 51.03, "max_line_length": 476, "alphanum_fraction": 0.6686262983, "num_tokens": 1698, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339676722393, "lm_q2_score": 0.8976952914230972, "lm_q1q2_score": 0.7538252288274045}}
{"text": "\\section{Linear Algebra}\n\n\\subsection{Distance}\n\nConsider a line  $L$  in  $\\mathbb{R}^2$  given by the equation $L:\\theta \\cdot x + \\theta_0=$ where $\\theta$ is a vector normal to the line $L$. Let the point $P$ be the endpoint of a vector $x_0$(so the coordinates of $P$  equal the components of $x_0$).\\\\\n\nThe shortest distance $d$ between the line $L$ and the point $P$ is:\n\\begin{align*}\nd= \\displaystyle \\frac{\\mid \\theta \\cdot x_0+ \\theta _0\\mid }{\\mid \\mid \\theta \\mid \\mid }\n\\end{align*}", "meta": {"hexsha": "10e8ebdce6ac57c0afa53442f5fe32fff4ebb095", "size": 496, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/linear_algebra.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/linear_algebra.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/linear_algebra.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": 49.6, "max_line_length": 258, "alphanum_fraction": 0.6814516129, "num_tokens": 166, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9504109742068042, "lm_q2_score": 0.793105953629227, "lm_q1q2_score": 0.7537766020379701}}
{"text": "\n\\subsection{Discrete uniform distribution}\n\nThere is a set \\(s\\) such that:\n\n\\(P(x\\in s)=p\\)\n\n\\(P(x\\not\\in s)=0\\)\n\n\\subsubsection{Moments of the uniform distribution}\n\nThe mean is the mean of the set \\(s\\).\n\nIf the set is all numbers of the real line between two values, \\(a\\) and \\(b\\), then:\n\nThe mean is \\(\\dfrac{1}{2}(a+b)\\).\n\nThe variance is \\(\\dfrac{(b-a)^2}{12}\\) in the continuous case.\n\nThe variance is \\(\\dfrac{(b-a+1)^2-1}{12}\\) in the discrete case.\n\n", "meta": {"hexsha": "6f6d44506e6fffc5d11c76842616da89083194c9", "size": 464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/distributionsContinous/02-01-uniform.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/probability/distributionsContinous/02-01-uniform.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/probability/distributionsContinous/02-01-uniform.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.0909090909, "max_line_length": 85, "alphanum_fraction": 0.6487068966, "num_tokens": 150, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.921921834855049, "lm_q2_score": 0.817574478416099, "lm_q1q2_score": 0.7537397632720296}}
{"text": "\n%\\section{Numerical examples}\nIn this section, we will list some numerical results using different methods on the MNIST dataset. \n\n%The MNIST data set contains the pictures of single digits. The size of each digit picture is 28*28 and the label is the digit from 0 to 9. There are 60000 training data and 10000 test data in all.\n\\subsection{Least square}\n\nWe first present the details of the experiments using the least square for classification. \n\nThe most straightforward model for prediction is the linear model\n$$\ny=Wx+b,\n$$\nwhere $x\\in \\mathbb{R}^{784}$ is the input data, $y\\in \\mathbb{R}^{10}$ is the prediction and $W \\in \\mathbb{R}^{10 \\times 784}, b \\in \\mathbb{R}^{10} $ are the parameters of the model. \nFor each data in the MNIST dataset, $x_i\\in \\mathbb{R}^{784}, i=1,...,60000$, denote the corresponding label as $y_i\\in \\mathbb{R}^{10}$. \nWe denote the training set and labels in matrix form, \n$$A=\\begin{pmatrix}\n    x_{1} &x_{2}  &...  &x_{60000}     \\\\\n    1&1&... &1\\\\\n\\end{pmatrix}^T \\in \\mathbb{R}^{60000\\times 785},$$ \n$$Y=\\begin{pmatrix}\n    y_{1}        ,\n    y_{2}       ,\n    ... ,\n    y_{60000}     \n\\end{pmatrix}^T\\in \\mathbb{R}^{60000\\times 10}.\n$$\nOur goal is to find the optimal parameter \n$\\theta=\\left[ W ,b  \\right]^T\\in \\mathbb{R}^{785\\times 10}$ to minimize the total sum of square loss \n$$\n\\sum_{i=1}^{60000} \\|y_i-(W x_i+b)\\|^2_2=\\|Y- A\\theta\\|^2_2.\n$$\nThe empirical formulae gives the optimal parameter as\n\\begin{align}\n\\hat{\\theta}=(A^TA)^{-1}A^TY.\n\\end{align}\n\n\nFor the MNIST dataset, after $\\hat{\\theta}$ is calculated, we can classify $x_i$ based on the linear model\n\\begin{align}\n\\hat{y_i}=\\hat{W}x_i+\\hat{b} \\in \\mathbb{R}^{10}.\n\\end{align}\nWe choose the entry in $\\hat{y_i}$ with the maximum value as the predicted label for $x_i$. Finally, the training accuracy is 85.77$\\%$ and the test accuracy is 86.03$\\%$. \n\n\\subsection{Logistic regression }\nThe model of logistic regression is slightly different from least square in the prediction and the loss function. With similar notations, we use $\\hat{y}$=softmax($Wx+b$) as the predicted label of the input.\nHere there is one more operation of softmax in the predicted label of an input $x$. It is used for normalizing the output to a probability distribution. Moreover, the loss function here is the cross entropy loss with an $\\ell^2$ regularization term\n\\begin{align}\nL_{\\lambda}(\\theta)=L(\\theta)+\\lambda R(\\|\\theta\\|)=\n-(y \\log(\\hat{y})+(1-y)\\log(1-\\hat{y}))\n+\\lambda \\|\\theta\\|^2.\n\\end{align}\nWe use the {\\color{red}Adam} optimization algorithm in the numerical experiment. We choose the learning rate to be 0.001,  batch size to be 100\nand regularization coefficient to be 0.0001 for 50 training epochs. Finally, the training accuracy is 93.46$\\%$ and the test accuracy is 92.56$\\%$. \n\n\n\n\n\\subsection{Support vector machine (SVM) }\nFinally, we use SVM for classification which we discussed in Section \\ref{sec:SVMintro}. The main hypercoefficient is the kernel to be used in the algorithm. There are many kernels available such as linear kernel, Gaussian kernel, polynomial kernel and so on. We recall these kernels here. \n\\begin{itemize}\n\t\\item Polynomial kernel: $k(x,y) = (a\\langle x,y\\rangle+ b)^n, a > 0, b\\geq 0, n\\in \\mathbb{N}^+$.\n\t\\item Gaussian kernel: $k(x,y) = e^{-\\gamma\\|x-y\\|^2}, \\gamma > 0$.\n\\end{itemize}\nWe choose the regularization parameter $\\lambda=1$ in \\eqref{SVM_Quad_soft} and use polynomial kernel \nand Gaussian kernel as well as no kernel \nfor numerical experiments. \nWith no kernel, the training accuracy is 87.91$\\%$ and the test accuracy is 87.73$\\%$. \nWith polynomial kernel, the training accuracy is 99.16$\\%$ and the test accuracy is 97.71$\\%$. \nWith Gaussian kernel, the training accuracy is 98.99$\\%$ and the test accuracy is 97.92$\\%$.\n\n%The training accuracy is 99.16$\\%$ and the test accuracy is 97.71$\\%$.\n\n\\subsection{Summary }\nFor the dataset of MNIST, the traditional linear machine learning models can achieve good classification accuracy. \n\n  If we apply standard least square to the  MNIST dataset, we only get 86.03\\% test accuracy. If we apply logistic regression to the  MNIST dataset, we get 92.56\\% test accuracy. If we apply support vector machine (SVM) with polynomial kernel to the  MNIST dataset, we get 97.71\\% test accuracy. If we apply support vector machine (SVM) with Gaussian kernel to the  MNIST dataset, we get 97.92\\% test accuracy. \n\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\\hline\n\t\t\tModel &  Training accuracy(\\%)   &   Test accuracy(\\%) \\\\\n\t\t\t\\hline\n\t\t\tLeast square & 85.77\t           &   86.03 \\\\ \\hline\n\t\t\tLogistic regression & 93.46   &   92.56\t     \\\\ \\hline\n\t\t\tSVM without kernel& 87.91           &   87.73         \\\\\t\\hline\n\t\t\tSVM with kernel& 99.16            &   97.71         \\\\\t\\hline\n\t\t\tCNN & 99.99            &   99.79         \\\\\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Training and test accuracy of different models on MNIST.}\n\t\\label{tab:MNIST-LR-Results}\n\\end{table}\n\n\n\\begin{table}[!htbp]\n\t\\begin{center}\n\t\t\\begin{tabular}{|c|c|c|}\n\t\t\t\\hline\n\t\t\tModel &  Training accuracy(\\%)   &   Test accuracy(\\%) \\\\\n\t\t\t\\hline\n\t\t\tLeast square & 45.10           &   32.86 \\\\ \\hline\n\t\t\tLogistic regression & 39.25   &   35.23\t     \\\\ \\hline\n\t\t\tSVM without kernel& 33.02            &   23.76         \\\\\t\\hline\n\t\t\tSVM with kernel& 70.29            &   54.37         \\\\\t\\hline\n\t\t\tCNN & 99.97            &   95.05         \\\\\t\\hline\n\t\t\\end{tabular}\n\t\\end{center}\n\t\\caption{Training and test accuracy of different models on CIFAR-10.}\n\t\\label{tab:MNIST-LR-Results2}\n\\end{table}\nIn the meanwhile, the accuracy of the state-of-art CNN model (see more details in Section \\ref{sec:CNNs})applied on the MNIST dataset is 99.79\\%. We summarize the accuracy of these models on MNIST in the following Table \\ref{tab:MNIST-LR-Results}.\n\nIn the following Table \\ref{tab:MNIST-LR-Results2}, we summarize the accuracy of different models on CIFAR-10.\n\nBased on the previous results, CNN models outperform all the other models significantly. \nThus we want to investigate the convolutional neural networks for better performance rather than the traditional machine learning models. \n", "meta": {"hexsha": "14c0ab91307b0d4612efb092fa6a6f51cf6864b6", "size": 6165, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/LR-SVM-Num.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/LR-SVM-Num.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/LR-SVM-Num.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 51.8067226891, "max_line_length": 411, "alphanum_fraction": 0.6879156529, "num_tokens": 1902, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318196, "lm_q2_score": 0.8479677602988601, "lm_q1q2_score": 0.7536388110592104}}
{"text": "\\subsubsection{Defective Matrix}\r\nIf $A$ has an eigenvalue $\\lambda$ with multiplicity $k$ that does not generate $k$ corresponding linearly independent eigenvectors, the the matrix $A$ is defective. To generate enough vectors, we need to extend eigenvectors.\r\n\\begin{definition}\r\n\tLet $A$ be a square matrix. A nonzero vector $\\vec{v}$ satisfying\r\n\t\\begin{equation*}\r\n\t\t(A-\\lambda I)^n \\vec{v} = \\vec{0}\r\n\t\\end{equation*}\r\n\tfor some eigenvalue $\\lambda$ and some positive integer $n$ is a generalized eigenvector or rank $n$.\r\n\\end{definition}\r\nThese generalized eigenvectors also make up solutions.\r\n\\begin{theorem}\r\n\tLet $\\vec{v}$ be an generalized eigenvector of a square matrix $A$ corresponding to an eigenvalue $\\lambda$ with multiplicity $k$. Then\r\n\t\\begin{equation*}\r\n\t\te^{At}\\vec{v} = e^{\\lambda t}\\left(\\vec{v} + t(A-\\lambda I)\\vec{v} + \\frac{t^2}{2!}(A-\\lambda I)^2\\vec{v} + \\ldots\\right)\r\n\t\\end{equation*}\r\n\tis the corresponding fundamental solution. Further, the above sequence will terminate after $k$ or fewer terms (all subsequent terms are 0).\r\n\\end{theorem}\r\n\r\n\\ifodd\\includeLinearSystemsExamples\\input{./linearSystems/homogeneousSystems/defectiveMatrices_example.tex}\\fi", "meta": {"hexsha": "b7e3bed585175c0187e50074cea600261ae060ed", "size": 1190, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_stars_repo_name": "rawsh/Math-Summaries", "max_stars_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_issues_repo_name": "rawsh/Math-Summaries", "max_issues_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diffEq/linearSystems/homogeneousSystems/defectiveMatrices.tex", "max_forks_repo_name": "rawsh/Math-Summaries", "max_forks_repo_head_hexsha": "3ad58ef55c176f7ebaf145144e0a4eb720ebde86", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 62.6315789474, "max_line_length": 226, "alphanum_fraction": 0.7344537815, "num_tokens": 342, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587934924569, "lm_q2_score": 0.8479677564567913, "lm_q1q2_score": 0.7536388001490434}}
{"text": "\\documentclass[\n12pt, %font size\nletterpaper, %for printing on American sized paper\nfleqn, % for ligning up our equations\nnotitlepage % we don't want a title page\n]{article}\n\n\\usepackage{amsmath,amsfonts,amssymb} % Math packages\n\\usepackage[letterpaper,margin=1in]{geometry} % Margins\n\\usepackage{setspace} % let's us choose between single or double spacing\n\n\\usepackage{sectsty} % Allows customizing section commands\n\\allsectionsfont{\\normalfont\\scshape} % Make all sections centered, the default font and small caps\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\\singlespacing\n\\frenchspacing % No extra spaces after sentances\n\n\n\\begin{document}\n\n%------------------------------------------------\n% title information\n\\title{\\vspace{-2cm}Precalculus: Chapter 5 Notes}\n\\author{Amin Mesbah}\n\\date{}\n\\maketitle\n\n%------------------------------------------------\n\n\\section{Exponents}\n\n%------------------------------------------------\n\n\\subsection*{Laws of Exponents} % the asterisk ommits the section number\nIf $s$, $t$, $a$, and $b$ are real numbers with $a>0$ and $b>0$, then\n\n% the align environment aligns things on multiple lines based on where I put an '&'\n\\begin{align}\n\ta^s \\cdot a^t &= a^{s+t} &(a^s)^t &= a^{st} & (ab)^s &= a^s \\cdot b^s \\\\\n\t1^s &= 1 & a^{-s} &= \\frac{1}{a^s} = \\left(\\frac{1}{a}\\right)^s & a^0 &= 1 \n\\end{align}\n% fractions are a bit tricky. You use them like this:\n% \\frac{numerator}{denominator}\n\n%------------------------------------------------\n\n\\subsection*{Exponential Functions}\nAn \\textbf{exponential function} is a function of the form\n\n\\begin{align}\n\tf(x) = Ca^x\n\\end{align}\n\nwhere $a \\in \\mathbb{R}$, $a>0$, $a\\neq1$, and $C\\neq0$ is a real number. The domain of $f$ is $\\mathbb{R}$. The base $a$ is the \\textbf{growth factor}, and because $f(0) = Ca^0 = C$, we call $C$ the \\textbf{initial value}.\\\\\n\nFor $f(x)=Ca^x$, where $a>0$ and $a\\neq1$, if $x\\in\\mathbb{R}$, then\n\n\\begin{align}\n\t\\frac{f(x+1)}{f(x)} &= a & \\text{or} && f(x+1)&=af(x)\n\\end{align}\n\n%------------------------------------------------\n\n\\subsection*{The number $e$}\n\n\\begin{align}\n\te&=\\lim_{n\\to\\infty}\\left(1+\\frac{1}{n}\\right)^n\n\\end{align}\n\n%------------------------------------------------\n\n\\subsection*{Solving Exponential Equations}\n\nUse this property, expressing each side of the equation using the same base:\n\n\\begin{align}\n\t\\text{If }a^u=a^v\\text{, then }u=v\n\\end{align}\n\n%------------------------------------------------\n\n\\section{Logarithms}\n\n%------------------------------------------------\n\n$\\log_{a}x$ represents the exponent to which $a$ must be raised to obtain $x$.\n\n\\begin{align}\n\ty &=\\log_{a}x\\text{ if and only if }x=a^y \\\\\n\ty &=\\ln{x}\\text{ if and only if }x=e^y \\\\\n\ty &=\\log{x}\\text{ if and only if }x=10^y\n\\end{align}\n\nThe domain of $y=\\log_{a}x$ is $\\{x|x>0\\}$.\n\n%------------------------------------------------\n\n\\subsection*{Logarithmic Functions}\n\nThe logarithmic function is the inverse of the exponential function.\n\n\\begin{align}\n\t\\text{If }f(x)=a^x\\text{, then }f^{-1}(x)=\\log_{a}x\n\\end{align}\n\nThe domain of $f^{-1}$ is the range of $f$. The range of $f^{-1}$ is the domain of $f$.\n\n%------------------------------------------------\n\n\\subsection*{Properties of Logarithms}\n\nIn the following properties, $M$, $N$, and $a$ are positive real numbers, $a\\neq1$, and $r \\in \\mathbb{R}$.\n\n\\begin{align}\n\t\\log_{a}1 &= 0 & log_{a}a &= 1 \\\\\n\ta^{\\log_{a}M} &= M & \\log_{a}a^r &= r \\\\\n\t\\log_{a}M^r &= r\\log_{a}M & a^x &= e^{x\\ln{a}}\n\\end{align}\n\n\\begin{align}\n\t\\log_{a}(MN) &= \\log_{a}M + \\log_{a}N &\n\t\\log_{a}\\left(\\frac{M}{N}\\right) &= \\log_{a}M - \\log_{a}N \n\\end{align}\n\n\\begin{align}\n\t\\text{If }M &= N\\text{, then }\\log_{a}M = \\log_{a}N &\n\t\\text{If }\\log_{a}M &= \\log_{a}N\\text{, then }M = N\n\\end{align}\n\n%------------------------------------------------\n\n\\subsection*{Change of Base Formula}\n\nIf $a\\neq1$, $b\\neq1$, and $M$ are positive real numbers, then\n\n\\begin{align}\n\t\\log_{a}M &= \\frac{\\log_{b}M}{\\log_{b}a} & \\text{so,} &&\n\t\\log_{a}M &= \\frac{\\log{M}}{\\log{a}} & \\text{and} && \\log_{a}M &= \\frac{\\ln{M}}{\\ln{a}}\n\\end{align}\n\n%------------------------------------------------\n\n\\end{document}\n", "meta": {"hexsha": "ca391dcdd44bf5c66d3848f96f20a24b7956b799", "size": 4545, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/math-notes-example/math-notes-example.tex", "max_stars_repo_name": "mesbahamin/latex-workshop", "max_stars_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2017-10-27T17:44:25.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-27T17:44:25.000Z", "max_issues_repo_path": "examples/math-notes-example/math-notes-example.tex", "max_issues_repo_name": "mesbahamin/latex-workshop", "max_issues_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "examples/math-notes-example/math-notes-example.tex", "max_forks_repo_name": "mesbahamin/latex-workshop", "max_forks_repo_head_hexsha": "36dfc6f18038c8e642c98a2c27c476646bf62728", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 30.5033557047, "max_line_length": 225, "alphanum_fraction": 0.5676567657, "num_tokens": 1529, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677583778257, "lm_q2_score": 0.8887587831798665, "lm_q1q2_score": 0.7536387931116354}}
{"text": "\\section*{Variables and constraints}\n\\subsection*{Input data}\n$ |E| $ is the total number of exams.\n\\newline\n$ |S| $ is the total number of enrolled students.\n\\newline\n$ |T| $ is the total number of available timeslots.\n\\newline\n$ \\vec{ns} $ is a $ n \\times n $ matrix, being $ n = |E| $, containing the number of students in conflit among two exams. More precisely, $ ns_{ij} $ contains the number of students in conflit among the exam $i$ and the exam $j$.\n\\newline\n$ ns_{ij} \\in \\mathbb{N} \\quad i = 1, \\dots , |E| \\quad j = 1, \\dots , |E| $.\n\\newline\n$ \\vec{ns} $ is built directly from the input data.\n\n\\subsection*{Variables}\n$ \\vec{p} $ is a vector containing the penalty value associated to exams. More precisely, $ p_{k} $ contains the penalty weight associated to exams which are $k$ timeslots far, being $ k \\in \\mathbb{N}, 1 \\le k \\le 5 $. Hence $p_{k} = 2^{5-k}$.\n\\newline\n$ \\vec{y} $ is a 3d matrix containing the information about conflicts at a certain distance. More precisely, \n\\[\ny_{ijk} = \n\\begin{cases}\n1\t&\t\\text{if exams $ i $ and $ j $ are $k$ timeslot far}\t\\\\\n0\t&\t\\text{otherwise}\n\\end{cases}\n\\]\n\n\\subsection*{Output data}\n$ \\vec{x} $ is a vector containing the number of the timeslot assigned to an exam. More precisely, $ x_{i} $ contains the number of the timeslot assigned to the exam $i$. Hence $ 1 \\le x_{i} \\le |T| $.\n\n\\subsection*{Constraints}\n$ ns_{ij} > 0 $ means that there are some students that can not substain the same exam in the same timeslot. Hence, it is needed to force $ x_{i} \\ne x_{j} $.\nIn order to express this condition, it is necessary to introduce two new variables\n\\[\nl_{ij} = \n\\begin{cases}\n1\t&\tns_{ij} > 0\t\\\\\n0\t&\t\\text{otherwise}\n\\end{cases}\n\\]\n\\[\nq_{ij} = \n\\begin{cases}\n1\t&\tx_{i} \\ne x_{j}\t\\\\\n0\t&\t\\text{otherwise}\n\\end{cases}\n\\]\nand to generate the following constraints:\n\\begin{gather*}\nns_{ij} \\le M l_{ij} \\qquad ns_{ij} \\ge m l_{ij} \\\\\nx_{i} - x_{j} \\ge m q_{ij} \\qquad x_{i} - x_{j} \\le M q_{ij} \\\\\nl_{ij} \\le q_{ij}\n\\end{gather*}\n\\newline\nIt is needed to activate the proper $ y_{ijk} $ in order to represent the correct couple of exams in conflict at a certain distance.\n\\newline\n$ x_{i} - x_{j} = k $ means that exam $i$ and exam $j$ are $k$ slots far. Hence, it is needed to force $ y_{ijk} = 1 $ being $ k \\in \\mathbb{N}, 1 \\le k \\le 5 $.\nIn order to express this condition, it is necessary to introduce two different blocks of constraints.\n\nThe first one forces $ y_{ijk} = 0 $ when $ x_{i} - x_{j} \\ne k $ in order to \"facilitate\" the minimization of the objective function.\n\\begin{gather*}\nk - (x_{i} - x_{j}) \\le M (1-y_{ijk}) \\\\\n(x_{i} - x_{j}) - k \\le M (1-y_{ijk})\n\\end{gather*}\n\nThe second one forces $ y_{ijk} = 1 $ when $ x_{i} - x_{j} = k $.\nIn order to express this constrains it is needed to introduce two more boolean variables, $ y_{ijk, I} $ and $ y_{ijk, II} $.\n\\begin{gather}\n\\label{eqn:1}\n(x_{i} - x_{j}) - k - \\epsilon \\ge (m - \\epsilon) y_{ijk, I} \\\\\n\\label{eqn:2}\n(x_{i} - x_{j}) - k + \\epsilon \\le (M + \\epsilon) y_{ijk, II} \\\\\n\\label{eqn:3}\ny_{ijk, I} + y_{ijk, II} - 1 \\le y_{ijk}\n\\end{gather}\nbeing $ \\epsilon < 1 $ an arbitrarily small positive quantity.\n\nWith the relation \\ref{eqn:1} the following constraint is expressed:\n\\[\ny_{ijk, I} = \n\\begin{cases}\n1\t&\t\\text{if $ (x_{i} - x_{j}) \\ge k $}\t\\\\\n0\t&\t\\text{otherwise}\n\\end{cases}\n\\]\nAnalagously, with the relation \\ref{eqn:2} the following constraint is expressed:\n\\[\ny_{ijk, II} = \n\\begin{cases}\n1\t&\t\\text{if $ (x_{i} - x_{j}) \\le k $}\t\\\\\n0\t&\t\\text{otherwise}\n\\end{cases}\n\\]\nFinally, the relation \\ref{eqn:3} forces $ y_{ijk} = 1 $ only if $ y_{ijk, I} = 1 $ and $ y_{ijk, II} = 1 $, that represents the situation in which $ x_{i} - x_{j} = k $.", "meta": {"hexsha": "9bbe528f0677d6c98917d7d7d9e887982ded0d06", "size": 3692, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Model/constraints.tex", "max_stars_repo_name": "enricofranco/examination-timetabling-problem", "max_stars_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-02-02T17:49:44.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-02T17:49:44.000Z", "max_issues_repo_path": "Model/constraints.tex", "max_issues_repo_name": "enricofranco/examination-timetabling-problem", "max_issues_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Model/constraints.tex", "max_forks_repo_name": "enricofranco/examination-timetabling-problem", "max_forks_repo_head_hexsha": "b319595d93f560f1c34e753b44d5ba24dda17c2b", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-17T10:46:00.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-17T10:46:00.000Z", "avg_line_length": 39.6989247312, "max_line_length": 244, "alphanum_fraction": 0.6486998917, "num_tokens": 1312, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9353465188527685, "lm_q2_score": 0.8056321866478979, "lm_q1q2_score": 0.7535452612568552}}
{"text": "\\section{Deep Learning and Neural Networks}\nConsider the next model:\n\\begin{equation}\n    \\begin{cases}\n        z^* &= Wx \\\\\n        z &= \\rho(z) \\\\\n        y &= \\tilde{W}z, \n    \\end{cases}\n\\end{equation}\nthis is a simple neural network model with one hidden layer. So the multi-layer neural network can be expressed as:\n\\begin{itemize}\n    \\item {\\bf Input:} \n        $$\n        z^{(0)} = x,\n        $$\n    \\item \n        \\begin{equation}\n            \\begin{cases}\n                z_*^{(k)} &= W^{(k)}z^{(k)} \\\\\n                z^{(k+1)} &= \\rho(z_*^{(k)}) \\\\\n            \\end{cases}\n        \\end{equation}\n    \\item {\\bf Output:}\n        $$\n        y = W^{t+1}z^{(T)}.\n        $$\n\\end{itemize}\nThis can be seen as a discrete dynamics system. So the problem is:\n\\begin{equation}\\label{opti-DL}\n    \\min_{W^{(1)}, \\cdots, W^{(T+1)}} \\sum_{j=1}^N (y_j - W^{(T+1)}z(x_j)^{(T)})^2.\n\\end{equation}\n%\\begin{remark}\n    \\begin{itemize}\n        \\item {\\bf E:} Generally speaking: the number of parameters is larger than the number of data($N$), but there are not so many overfit  phenomenon. {\\bf This is unclear!}\n        \\item {\\bf E:} If one can solve the exact solution for the above optimization problem \\eqref{opti-DL}, there is a high probability to see overfit. (Is there any experiments to show this?)\n    \\end{itemize}\n    %\\end{remark}\n{\\bf Application of DL:}\n\\begin{itemize}\n    \\item Dimension reduction: Encoder $+$ Decoder $\\to$ Auto-encoder, a kind of unspervised learning. In mathematically, it can be expressed as:\n        \\begin{itemize}\n            \\item {\\bf Input:} \n                $$\n                z^{(0)} = x,\n                $$\n            \\item \n                \\begin{equation}\n                    \\begin{cases}\n                        z_*^{(k)} &= W^{(k)}z^{(k-1)} \\\\\n                        z^{(k+1)} &= \\rho(z_*^{(k)}) \\quad k=1:T-1\\\\\n                    \\end{cases}\n                \\end{equation}\n            \\item {\\bf Mid-output:}\n                \\begin{align}\n                    \\hat{y} &= W^{t+1}z^{(T)} \\\\\n                    \\tilde{y}    &= \\rho(\\hat{y})\n                \\end{align}\n\n            \\item $$z^{T+1} = \\tilde{y}$$\n\n            \\item \n                \\begin{equation}\n                    \\begin{cases}\n                        z_*^{(k)} &= W^{(k)}z^{(k-1)} \\\\\n                        z^{(k+1)} &= \\rho(z_*^{(k)}) \\quad k =T + 2 : T + K+1 \\\\\n                    \\end{cases}\n                \\end{equation}\n\n            \\item {\\bf Output:}\n                \\begin{equation}\n                    y = W^{T+K + 3}z^{(T+K+2)}.\n                \\end{equation}\n        \\end{itemize}\n\n        So the problem is:\n        \\begin{equation}\n            \\min_{W} (x_j - W^{T+K + 3}z^{(T+K+2)(x_j)})^2.\n        \\end{equation}\n        But in fact, the real thing we wanted is $\\hat{y}$ or $\\tilde{y}$, because in this way, we can use  $\\hat{y}$ or $\\tilde{y}$ to denote or encoder the $x$, generally have the next relation:\n        \\begin{equation}\n            \\rm{Dim}(\\hat{y}) = \\rm{Dim}(\\tilde{y}) < \\rm{Dim}(x).\n        \\end{equation}\n\n    \\item There is no one have researched about deep learning for cluster, but E think, one can use DL for cluster, also for density approximation.\n\n    \\item Generative model: GAN, do sampling directly without doing density approximation first. This cannot be used to write paper, but now ``NLP'' is very hot.\n\n    \\item Text analysis, time sequence, RNN and LSTM.\n\n\\end{itemize}\n\n\nHow to solve the problem \\eqref{opti-DL}. BP! We assume that the loss function as:\n$$\nJ(W^{(0)}, \\cdots, W^{(T+1)}).\n$$\nSo BP is:\n\\begin{align}\n    \\nabla_{W^{k}} J = \\nabla_{Z^{(k)}} J\\nabla_{W^{(k)}} Z^{(k)}.\n\\end{align}\n\nTo state the BP process better, we change the expression for DL model before as:\n\n\\subsection{Mathematical expression of neural network}\nThe network would be like:\n\\begin{figure}[!ht]        \n    \\center{\\includegraphics[width=12cm,height=6cm] {ANN.png}}        \n    \\caption{ANN}      \n\\end{figure}\n\nThis is called fully connected feedforward neural network. Now we want to give a more compressive expression, we collect all the output in $k$-th level $f_{k,l}$ $l = 1,\\cdots, L_k$ with $f_{k,L_k+1} = 1$ as a extended vector $\\bm{f}_k$. \nSo we can have the output in $k+1$-th level under this setting with \n\\begin{equation}\n    \\bm{f}_{k+1}(W_{k+1}) = \n    \\begin{pmatrix}\n        \\bm{g}_{k+1}(\\omega_{k+1} \\cdot \\bm{f}_k(W_k)) \\\\\n        1,\n    \\end{pmatrix}\n\\end{equation}\nwith \n\\begin{equation}\n    W_{k+1} = \\{ \\omega_{k+1}, W_k\\} \\quad \\omega_{k+1} \\in \\mathbb{R}^{(L_{k+1}) \\times (L_{k} + 1)},\n\\end{equation}\nand\n\\begin{equation}\n    \\bm{g}_{k+1}(x_1,\\cdots,x_{L_{k+1}}) = \n    \\begin{pmatrix}\n        g_{k+1}(x_1) \\\\ \n        \\cdots  \\\\\n        g_{k+1}(x_{L{k+1}})\n    \\end{pmatrix}\n\\end{equation}\nSo at last, we get the final iterative definition with the last output and initial input of this network like:\n\\begin{equation}\n    \\begin{cases}\n        &\\bm{f}_K(W_{K}) = \n        \\begin{pmatrix}\n            \\bm{g}_{K}(\\omega_{K} \\cdot \\bm{f}_{K-1}(W_{K-1})) \\\\\n            1,\n        \\end{pmatrix} \\\\\n        &\\bm{f}_0 = \n        \\begin{pmatrix}\n            \\bm{x} \\\\\n            1\n        \\end{pmatrix}.\n    \\end{cases}\n\\end{equation}\nAll in all, we can define the tensor similar space like:\n\\begin{equation}\n    T_{3}(\\mathcal{L}_K) := \\{ \\omega_{k,li} \\in \\mathbb{R}~|~ 1 \\le k \\le K, 1\\le l \\le L_k, 1 \\le i \\le L_{k-1} + 1\\}, \n\\end{equation}\nwith \n\\begin{equation}\n    \\mathcal{N}_{K} = (m, L_1, L_2, \\cdots, L_{K-1}, c).\n\\end{equation}\nHere we need to mention that, for this kind of deep feedforward neural network, once $\\mathcal{N}_K$ is defined we know the whole structure of this network. So we may call $\\mathcal{N}_K$ as the network structure parameters. By the way, we have $c = Dim(Y^i) = n_K$ and $m = Dim(X^i) = n_0 $ which are defined by the data and problem properties.\n\n\\subsection{Interpolation by optimization}\nSo the  interpolation process can be seen as a optimization problem in the special function class if the activation function for every elements and  the network structure parameter $\\mathcal{N}_K$ are given:\n\\begin{equation}\n    \\mathcal{F} = \\{\\bm{f}_K(W_K;\\bm{x}) ~|~  \\bm{f}_0 = (\\bm{x}^{T},1)^{T}\\},\n\\end{equation}\nand the optimization problem can be seen as\n\\begin{equation}\n    %\\mathop{\\min}_{f \\in \\mathcal{F}}  \\frac{1}{N}\\sum_{i=1}^N \\|f(X^i) - Y^i\\|^2 = \n    \\mathop{\\min}_{W_K \\in T_3(\\mathcal{N}_K)}  L(W_K) := \\frac{1}{N}\\sum_{i=1}^N \\|\\bm{f}_K(W_K; X^i) - Y^i\\|^2.\n\\end{equation}\nBut $\\mathcal{F}$ this is neither a linear space nor a convex set.\n\n\n\n\n\\subsection{Back-Propagation}\nHere we will talk about how to compute $\\nabla_{W_K} L(W_K)$ by using chain rule which is called BP algorithm in deep learning. By the definition we have:\n\\begin{equation}\n    \\nabla_{W_K} L(W_K) = \\frac{2}{N} \\sum_{i=1}^{N} \\nabla_{W_K}\\bm{f}_K(W_K; X^i) \\cdot (\\bm{f}_K(W_K;X^i) - Y^i) . \n\\end{equation}\nSo, the only thing we need to do is to compute $\\nabla_{W_K}\\bm{f}_K(W_K; X^i)$, if we state this element by element, that is: \n\\begin{equation}\n    \\frac{\\partial (\\bm{f}_K)_j}{ \\partial \\omega_{k,l,i}} = \\frac{\\partial (\\bm{f}_K)_j}{\\partial \\bm{f}_{K-1}} \\cdot \\frac{ \\partial \\bm{f}_{K-1}}{\\partial \\bm{f}_{K-2}} \\cdots \\frac{ \\partial \\bm{f}_k}{\\partial \\omega_{k,l,i}}.\n\\end{equation}\nWe can see from the above that, we only need to compute those terms like:\n\\begin{equation}\n    \\frac{ \\partial \\bm{f}_k}{\\partial \\omega_{k}}  \\quad \\text{and} \\quad \\frac{\\partial \\bm{f}_k}{\\partial \\bm{f}_{k-1}}  \\quad k = 1,2,\\cdots,K. \n\\end{equation}\n\nNow we are going to derive the expression for every terms, first of all we have $(\\bm{f}_k)_{L_k + 1} = 1$, so we have \n$$\n\\frac{\\partial(\\bm f_k)_{L_{k} + 1}}{\\partial \\bm f_{k-1}} = (0,0,\\cdots,0) \\in \\mathbb{R}^{L_{k-1} + 1},\n$$\nand\n$$\n\\frac{\\partial(\\bm f_k)}{\\partial (\\bm f_{k-1})_{L_{k-1}+1}} = (0,0,\\cdots,0)^{t} \\in \\mathbb{R}^{L_{k} + 1}.\n$$\nTo compute $\\frac{\\partial(\\bm f_k)_j}{\\partial (\\bm f_{k-1})_{l}}$ with $ 1 \\le j \\le L_k$ and $1 \\le l \\le L_{k-1}$ we have \n$$\n\\frac{\\partial(\\bm f_k)_j}{\\partial (\\bm f_{k-1})_{l}} = \\frac{ g_k( (\\omega_k \\cdot \\bm{f}_{k-1})_j)}{\\partial (\\bm f_{k-1})_{l}} = g_k'((\\omega_k \\cdot \\bm{f}_{k-1})_j)\\omega_{k,jl} .\n$$\nCombine those results we have:\n\\begin{equation}\\label{eq:partial-f}\n    \\frac{\\partial \\bm{f}_k}{\\partial \\bm{f}_{k-1}} = \n    \\begin{pmatrix}\n        \\omega_{k, (1:n_{k} )\\times(1:n_{k-1})} & 0 \\\\\n        0 & 0\n    \\end{pmatrix}\n\\end{equation}\nThe similar results can be derived for $\\frac{ \\partial \\bm{f}_k}{\\partial \\omega_{k}}$ and we get:\n\\begin{equation}\\label{eq:partial-omega}\n    \\frac{ \\partial (\\bm{f}_k)_l}{\\partial \\omega_{k,ij}} = \\begin{cases}\n        0 &\\text{if} \\quad l = L_k + 1\\\\\n        g_k'( \\sum_{l,s} \\omega_{k,l,s}(\\bm{f}_{k-1})_s)\\delta_{li}\\delta_{js}(\\bm{f}_{k-1})_{s} \\quad &\\text{others}.\n    \\end{cases}\n\\end{equation} \n\nIn short, BP algorithm can be expressed as:\n\\begin{algorithm}[H]\n    \\begin{algorithmic}[1]\n        \\STATE {\\bf{Input:}}  $X^i$ and $W_K$;\n        \\FOR{$k = K:-1:1$}\n        \\STATE Compute and save \n        $$\\frac{ \\partial \\bm{f}_k}{\\partial \\omega_{k}}  \\quad \\text{and} \\quad \\frac{\\partial \\bm{f}_k}{\\partial \\bm{f}_{k-1}}$$ by \\ref{eq:partial-f} and \\ref{eq:partial-omega}\n        \\STATE Compute \n        $$\\frac{ \\partial \\bm{f}_K}{\\partial \\omega_{k}} = \\frac{\\partial \\bm{f}_K}{\\partial \\bm{f}_{K-1}} \\cdot \\frac{ \\partial \\bm{f}_{K-1}}{\\partial \\bm{f}_{K-2}} \\cdots \\frac{ \\partial \\bm{f}_k}{\\partial \\omega_{k}}$$\n        \\ENDFOR\n    \\end{algorithmic}\n    \\caption{Back-Propagation Algorithm}\n\\end{algorithm}\n\n\n\n", "meta": {"hexsha": "abae7d710ed5524e44dc332ed28a6a750fde2df0", "size": 9612, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/5th_jche_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/5th_jche_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/5th_jche_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": 41.6103896104, "max_line_length": 345, "alphanum_fraction": 0.5682480233, "num_tokens": 3418, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7535398733190393}}
{"text": "\\chapter{Spectral Methods}\n\nFollowing Durran~\\cite{durran2010numerical}, we will discuss spectral\nmethods to solve differential equations. The intuition guiding these\nmethods should be thinking of a truncated Fourier series\n\\begin{equation}\n  \\phi_{N}(x) = \\sum^{N}_{k=-N}c_{k}\\E^{\\I kx}\n\\end{equation}\nthen trying to find the coefficients $c_{k}$ such that they minimize\nsome error, or satisfy some system of equations. More generally, instead\nof working with the basis functions $\\exp(\\I kx)$ we could use some\nother basis: this is what spectral methods study.\n", "meta": {"hexsha": "ad3a270ad6e8df4a72a4b6ed2b114080788cb00f", "size": 563, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/spectral-methods.tex", "max_stars_repo_name": "pqnelson/gcm", "max_stars_repo_head_hexsha": "dfbe1f42368fc3513f1e2548a963d0182951e56f", "max_stars_repo_licenses": ["BSD-3-Clause-Clear"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-23T00:20:23.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-23T00:20:23.000Z", "max_issues_repo_path": "tex/spectral-methods.tex", "max_issues_repo_name": "pqnelson/gcm", "max_issues_repo_head_hexsha": "dfbe1f42368fc3513f1e2548a963d0182951e56f", "max_issues_repo_licenses": ["BSD-3-Clause-Clear"], "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/spectral-methods.tex", "max_forks_repo_name": "pqnelson/gcm", "max_forks_repo_head_hexsha": "dfbe1f42368fc3513f1e2548a963d0182951e56f", "max_forks_repo_licenses": ["BSD-3-Clause-Clear"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 43.3076923077, "max_line_length": 72, "alphanum_fraction": 0.7726465364, "num_tokens": 147, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206686206199, "lm_q2_score": 0.8354835350552604, "lm_q1q2_score": 0.7535398685585596}}
{"text": "\\Extrachap{Notations}\\label{sec:Notation}\n\n\\section*{General Math Notations}\n\n\\begin{longtable}{cl}\n\\hline\\noalign{\\smallskip}\n\\textbf{Symbol} & \\textbf{Meaning} \\\\\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n$\\lfloor x \\rfloor$ & Floor of $x$, i.e. round down to nearest integer\\\\\n$\\lceil x \\rceil$ & Ceiling of $x$, i.e. round up to nearest integer\\\\\n% floor(key) & The largest key $\\leq$ the given key \\\\\n% ceil(key) & The smallest key $\\geq$ the given key \\\\\n$\\log x$ & The base of logarithm is 2 unless otherwise stated\\\\\n$a \\wedge b$ & Logical AND\\\\\n$a \\vee b$ & Logical OR\\\\\n$\\neg a $ & Logical NOT\\\\\n$a\\AND b$ & Bit AND\\\\\n$a \\OR b$ & Bit OR\\\\\n$a \\XOR  b$ & Bit XOR\\\\\n$\\NOT a$ & Bit NOT\\\\\n$\\SHIFTL a$ & Bit shift left\\\\\n$\\SHIFTR a$ & Bit shift right\\\\\n$\\infty$ & Infinity\\\\\n$\\rightarrow$ & Tends towards, e.g., $n \\rightarrow \\infty$\\\\\n$\\propto$ &Proportional to; $y = ax$ can be written as $y \\propto x$\\\\\n$\\abs{x}$ & Absolute value\\\\\n$||\\vec{a}||$ & $L_2$ distance (Euclidean distance) of a vector; norm-2 \\\\\n$\\abs{\\mathcal{S}}$ & Size (cardinality) of a set\\\\\n$n!$ & Factorial function\\\\\n$\\triangleq$ & Defined as\\\\\n$O(\\cdot)$ & Big-O notation, complexity upper bound\\\\\n$\\mathbb{R}$ & The real numbers\\\\\n$0:n$ & Range (Python convention): $0:n = {0, 1, 2,...,n-1}$\\\\\n$\\approx$ & Approximately equal to\\\\\n$\\sim$ & Tilde, the leading term of mathematical expressions \\\\\n$\\arg\\max\\limits_x f(x)$ & Argmax: the value $x$ that maximizes $f$\\\\\n$\\binom{n}{k}$ & $n$ choose $k$ , equal to $\\frac{n!}{k!(n-k)!}$\\\\\n$\\text{range}(i,j)$ & Range of number from i (inclusive) to j (exclusive) \\\\\n$A[i:j]$ & Subarray consist of $A_i, A_{i+1}, ..., A_{j-1}$.\n\\noalign{\\smallskip}\\hline\\noalign{\\smallskip}\n\\end{longtable}\n\n\n\\twocolumn\n", "meta": {"hexsha": "3bb9ac6ff589a0e7c66fc0a2e9c09266273c6f4e", "size": 1732, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notation.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": "notation.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": "notation.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": 38.4888888889, "max_line_length": 76, "alphanum_fraction": 0.6345265589, "num_tokens": 617, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127603871312, "lm_q2_score": 0.8824278772763471, "lm_q1q2_score": 0.7535164245276021}}
{"text": "%----------------------------------------------------------------------------------------\n% Why Does RBI Work\n%----------------------------------------------------------------------------------------\n\n\\section{Why Does RBI Work?}\n\n\\subsection{Layman's Terms}\n\nLet’s assume we're conducting a simple linear regression. Suppose that our model failed the the homoscedasticity and normality of residuals conditions, our data is random, and we have n > 30 observations in our dataset. By the central limit theorem, we can then assume our slope coefficient, $\\beta_1$ is approximately normally distributed. However, we can’t wholly trust the p-value associated with that slope. This is because for statistical inference, we need certain conditions to be met depending on the test. In this example of linear regression, we need a independence, a linear relationship between our response and predictor, and homoscedasticity of residuals. If it’s the case where these conditions cannot be met but we do have a sample representative of the population, we can create our randomization model. This randomization model is the distribution of n test statistics that we get from scrambling the data n times and calculating the given test statistic. Our randomization model also assumes the null hypothesis of the test statistic being zero or no statistically significant effect being present, creating what is called a null distribution. This is because the model has no parameters and that each time the data is shuffled, the observations become independent of their outcomes. Our original model, and typically most models, are tested at a significance level of $\\alpha=.05$. Because our randomization model assumes observations are independent of their outcomes, a constant significance level, or type 1 error rate, is held constant for the randomization model. Furthermore, by creating this randomization model, our randomization distribution is approximately the null distribution of whatever statistic we're calculating. Now, we calculate the p-value from the proportion of test statistics calculated from our randomly permuted dataset that are as or more extreme than our original test statistic. We can trust this p-value because the p-value comes from a now uniform distribution. \n\n\n\n\\subsection{Sharp Null Hypothesis \\& Asymptotic Normality and p-value}\n\nAs with many concepts in statistics and probability, the basis for randomization-based inference lies in the Central Limit Theorem. Let's stick with our simple linear regression example from above. As we saw, when we permute our data in simple linear regression, we are basically saying that there is independence between $x$ and $y$. This is equivalent to the null hypothesis, $H_0:\\hat{\\beta_1}=0$. In fact, for many permutations, this is equivalent to Fischer's sharp null hypothesis which says that there is no effect for each pairwise set of $x$ and $y$ values. Traditionally Fischer's exact test is defined as \n$$H_0:Y_i(1)=Y_i(0)\\quad\\forall i=1,2,\\dots,N \\text{ for } N \\text{ many permutations.}$$ As our example is dealing with linear regression we can't have this specific null hypothesis, but instead we can interpret it as $$H_0:\\hat{\\beta_1}_{,i}=0\\quad\\forall i = 1,2,\\dots,N.$$ Now, let's recall the Central Limit Theorem. The CLT says that given a population with mean $\\mu$ and standard deviation $\\sigma$ and we take sufficiently large random samples from the population with replacement, then our sampling distribution will be approximately normally distributed about $\\mu$. What does this mean for our case of simple linear regression? Well, we can think about the population of least squares estimators as every $\\hat{\\beta_1}$ we would get if were to permute the response column. A critical part of this is that our data from which we are calculating the least squares estimator is a representative random sample from the population. If so, then we can validate this claim that our distribution of least squares estimators is representative of the population as required by the CLT. This is crucial if we are to conduct statistical inference as randomization-based inference spells out. This is the reason we are able to generalize and make inferences about the population, even when model conditions aren't met. Now, with this in mind, each time we take a permutation of our data, we are taking a random sample from the population of $\\hat{\\beta_1}\\text{'s}$. As we saw above, the permutations we make lead to the assumption of the null hypothesis, $H_0:\\hat{\\beta_1}=0$. Therefore, by the central limit theorem, our reference distribution will be centered around zero because under the null hypothesis we have $E(\\beta_1)=0$ and for a normal distribution we have $E(X)=\\mu$. If we take all $n!$ permutations of an $n$-length response vector we would have an approximately normal distribution. As we take more permutations and include each newly calculated test statistic in the randomization distribution, we will only further approach normality to the point where more permutations with neither help nor hurt the normality of our reference distribution. This type of distribution is called an asymptotic distribution, thus, we have asymptotic normality in our reference distribution.\n\\newline\\\\\nSince our distribution in asymptotically normal, our p-value is not only valid, but it will be approximately exact, depending on the number of permutations that we run. If we reach the point where we have approached asymptotic normality, we would not just be approximating a p-value through statistical theory, but actually calculating it on an asymptotic normal distribution. By the same virtue as we showed asymptotic normality, we have an asymptotic p-value since we are calculating a p-value from this asymptotic distribution. We cannot take any more permutations that will influence the p-value since the distribution we are calculating the p-value on is nearly fixed for large numbers of permutations. \n\n\\subsection{In General}\n\nThis process that we took is true for many test statistics that we can choose. If we know that our sample is truly an approximation of the population, we are able to construct a roughly normal randomization centered around the null hypothesis of our test. Examples of other test statistics that we can use this approach for are means, proportions, difference in means, difference in proportions, and correlations. The same is true for $\\chi^2$- and $F$-distributions, however there is a bit more legwork that needs to happen before we can see this clearly. The formula for a $\\chi^2$ test statistic is $$\\sum\\frac{(O_i-E_i)}{E_i}$$ where $O_i$ is each observed data point and $E_i$ is the expected value for that group. Assuming that our data has been randomly sampled from the population, one of the assumptions that we hold for randomization based inference, then $O_i$ will be normal random variable meaning the difference $O_i-E_i$ is also a normal random variable. Assuming the null hypothesis  of no relationship (as we do when we shuffle the data), $E(O_i-E_i)=0$. Thus, the $\\chi^2$-distribution will be a sum of squared normal random variables taken from a standard normal distribution. As we shuffle the data and  sample more normal random variables from the standard normal distribution, the sum of their squares will only further approximate a $\\chi^2$-distribution. From this randomization distribution we can calculate a p-value by taking the proportion of $\\chi^2$ statistics that are greater than what we observed in our original sample over the total number of permutations. \n\\newline\\\\\nSimilarly, we can show that our randomized $F$-distribution will in fact be $F$-distributed using the same reasoning as we did previously to show that random permutations of our data will lead to a $\\chi^2$-distribution. Again, we're assuming the null in this case when we randomize our data. For an $F$-test, the null hypothesis is that both models or groups are the same. When we calculate our proportion that we do for an $F$-statistic, we will be taking a proportion of $\\chi^2$ random variables (multiplied by a factor of the inverse of each $\\chi^2$ random variable's degrees of freedom). By definition, this will be an $F$ random variable. Thus with many permutation we will have the null distribution of $F$-statistics which is centered at 1. Since we've satisfied that we can approximate our necessary distribution, we can calculate a p-value just as above. ", "meta": {"hexsha": "91412253b43fdfbf8fedfb2918e8c1805d8e2099", "size": 8476, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Project/Math%20420%20Final%20Paper/content/3-WhyDoesRBIWork.tex", "max_stars_repo_name": "jake-caldwell/Math420Proj", "max_stars_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_stars_repo_licenses": ["CC0-1.0"], "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/Math%20420%20Final%20Paper/content/3-WhyDoesRBIWork.tex", "max_issues_repo_name": "jake-caldwell/Math420Proj", "max_issues_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_issues_repo_licenses": ["CC0-1.0"], "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/Math%20420%20Final%20Paper/content/3-WhyDoesRBIWork.tex", "max_forks_repo_name": "jake-caldwell/Math420Proj", "max_forks_repo_head_hexsha": "460deedb53a0a18509bc412c012f33e04440e9bb", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 353.1666666667, "max_line_length": 2292, "alphanum_fraction": 0.7812647475, "num_tokens": 1766, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7534849498520184}}
{"text": "\\subsubsection{Simulation}\n\\paragraph{Algorithm 1: Force Calculation Between Two Bodies}\nThis equation can be used to calculate the gravitational force exerted by two masses on x and y components without the need to use the trigonometric functions.\n\n$$\\begin{bmatrix} F_x \\\\ F_y \\end{bmatrix} = \\frac{GmM}{r^3} \\begin{bmatrix} r_x \\\\ r_y \\end{bmatrix}$$\n\n\\paragraph{}\nThe proof for this equation is fairly straightforward, by equating the original full equation including the trigonometric component finding to the vector equation.\n\n$$F_x=\\frac{GmM}{r^2}\\cos\\theta \\hspace{25pt} F_x=\\frac{GmM}{r^3}\\hat{x} \\hspace{25pt} : GmM = 1 $$ \n\\vspace{10pt}\n$$F_x=\\frac{1}{r^2}\\cos\\theta \\hspace{25pt} F_x=\\frac{1}{r^3}\\hat{x} \\hspace{25pt} : r=\\sqrt{\\hat{x}^2+\\hat{y}^2}$$ \n\\vspace{10pt}\n$$F_x=\\frac{1}{(\\sqrt{\\hat{x}^2+\\hat{y}^2})^2}\\cos\\theta = \\frac{1}{(\\sqrt{\\hat{x}^2+\\hat{y}^2})^3}\\hat{x} \\hspace{25pt} : \\frac{1}{x^2} \\div \\frac{1}{x^3}  = x$$\n\\vspace{10pt}\n$$\\sqrt{\\hat{x}^2+\\hat{y}^2}\\cos\\theta=\\hat{x} \\hspace{25pt} : \\cos\\theta=\\frac{adj}{hyp} \\hspace{25pt} adj=\\hat{x} \\hspace{25pt} hyp=\\sqrt{\\hat{x}^2+\\hat{y}^2}$$\n\\vspace{10pt}\n$$\\sqrt{\\hat{x}^2+\\hat{y}^2}\\frac{\\hat{x}}{\\sqrt{\\hat{x}^2+\\hat{y}^2}}=\\hat{x} \\rightarrow \\hat{x} = \\hat{x}$$\n\n\\paragraph{}\nThe benefit of not requiring the use of the trigonometric functions is that the management of signs is a lot simpler, as well as a reduced computational requirement and much simpler code, this algorithm is also much easier to use for 3D, as the forces can just be calculated on the z axis based on z distance. \\\\\n\nRequired Parameters:\n\\begin{itemize}\n\\item Gravitational Constant ($G$)\n\\item Mass of Bodies ($m$ $M$)\n\\item Distance Between Bodies ($r$, $r_x$ and $r_y$)\n\\end{itemize}\n\n\\paragraph{Algorithm 2: Calculation of all Forces}\nIn order to simulate the interaction of multiple bodies, all relationships between bodies must be calculated, this can be presented as an undirected graph in an abstract sense. This also means that it can be represented as a matrix. \n\n\\paragraph{}\nWhen showing this organisation structure as a matrix, it becomes clear as to how many calculations need to be done in order to calculate all the required relationships.\n\n\\paragraph{}\nBecause the 'graph' is undirected, the matrix would be mirrored, the same force applies to both bodies in a relationship.\nIn order to reduce wasted memory footprint and increase ease of passing the variable, the x and y forces can be packed into the same matrix. (Will require slightly more complex programming when accessing the forces.)\n\n\\paragraph{}\nSign of the force must be retained, meaning that the way round that the force is calculated must be constant throughout all (x to y).\nThe number of individual calculations that need to be done becomes $\\frac{1}{2}n^2-n$ for the main force calculation and $n^2-n$ for the directional vector, this is still $O(n^2)$ time complexity per body. \\\\\\\n\nRequired Parameters:\n\\begin{itemize}\n\\item Current Number of Bodies\n\\item Scenario Body Structure\n\\end{itemize}\n\n\\begin{figure}[!ht]\n  \\centering\n  $$\\begin{array}{c|c|c|c|c|c}\n  ~ & \\textbf{0} & \\textbf{1} & \\textbf{2} & \\textbf{3} & \\textbf{4} \\\\ \n  \\hline\n  \\textbf{0} & -      & y_{01} & y_{02} & y_{03} & y_{04} \\\\\n  \\hline\n  \\textbf{1} & x_{01} & -      & y_{12} & y_{13} & y_{14} \\\\\n  \\hline\n  \\textbf{2} & x_{02} & x_{12} & -      & y_{23} & y_{24} \\\\\n  \\hline\n  \\textbf{3} & x_{03} & x_{13} & x_{23} & -      & y_{34} \\\\\n  \\hline\n  \\textbf{4} & x_{04} & x_{14} & x_{24} & x_{34} & -\n \\end{array}$$\n  \\caption{Example Force Matrix Representation (Body Count = 5)}\n\\end{figure}\n\n\\paragraph{Algorithm 3: Summation of Forces on Bodies}\nThe forces on each body must be summed up so the total force on each body can be resolved to two numbers for x and y respectively.\n\n\\paragraph{}\nBecause the force is only stored in the matrix an implied direction, in certain cases it may be necessary to flip the sign of some of the results to correctly sum the answers, Results will be stored in an individual bodies dataset.\n\n\\paragraph{}\nThe force is calculated x to y on the matrix, meaning that all forces will initially be calculated with a sign that represents this direction (The sign of the unit vector distance).\nThis function will need to 'traverse' the matrix in a similar way to the previous function, but only add a force if one of the loop axis is equal to the current body ID.\n\n\\paragraph{} If the body ID is found in the first array access column, the original sign is kept. If it is found in the second, the sign must be flipped to preserve the correct direction of force relative to the body because of the way round that force has been calculated. \\\\\\\n\nRequired Parameters\n\\begin{itemize}\n\\item Current Number of Bodies\n\\item Scenario Body Structure\n\\item Scenario Component Force Matrix\n\\end{itemize}\n\n\\pagebreak\n\\paragraph{Algorithm 4: Integration of New Position}\nUsing the second order leapfrog integration method, calculates change in velocity and change in position/acceleration out of step with each other in order to reduce deviation.\n\n\\paragraph{}\nEach iteration will be calculated in the order $\\frac{1}{2}v \\rightarrow r \\rightarrow F \\rightarrow a \\rightarrow \\frac{1}{2}v$, but initial acceleration should be calculated should any new bodies be added into the simulation as velocity is calculated at the start of each iteration.\n\n\\paragraph{}\nIn order to calculate the acceleration of each body the force gets calculated for every body and given to the individual body objects, the instantaneous force for that iteration is then used to calculate instantaneous acceleration based on Newton's Second Law or $a=\\frac{F}{m}$ after which all other operations are done in the body object methods instead.\n\n\\paragraph{}\nVelocity and Position are both accumulative properties, meaning that they are conserved in the body objects iteration to iteration. Velocity is $\\Delta{v}=a\\Delta{t}$, but this will be calculated as $\\Delta{v}=\\frac{1}{2}a\\Delta{t}$ and will be done at two points in the iteration. Position is calculated as $\\Delta{r}=v\\Delta{t}$. (Velocity and Acceleration are first and second derivatives of position respectively.) \\\\\\\n\nReferences: \\cite{leapfrog} \\\\\\\n\nRequired Parameters\n\\begin{itemize}\n\\item Current Number of Bodies\n\\item Scenario Body Structure\n\\end{itemize}\n\n\\paragraph{Algorithm 5: Body Collision Detection and Calculation}\nThe simulation will have a simple body collision detection algorithm implemented that makes use of basic inelastic collisions, no fragments will be created and colliding bodies will simply merge together in mass and circular area.\n\n\\paragraph{}\nDetecting if bodies are colliding can be done using the radius property of bodies, if two bodies vector distance is smaller than the sum of their radii, the bodies can be considered to have collided and the result can be calculated. Because this method checks every single body, the time order complexity is $O(n^2)$.\n\n\\paragraph{}\nIf a collision is detected, the momentum for individual bodies can be calculated using the equation $p=mv$, momentum will be conserved in an inelastic collision, meaning that the momentum for both bodies can be added together and then divided by the total mass of both bodies combined to get the new velocity for the result. This will need to be done for both X and Y vectors.\n\nRequired Parameters\n\\begin{itemize}\n\\item Current Number of Bodies\n\\item Scenario Body Structure\n\\end{itemize}\n\n\\pagebreak\n\\subsubsection{Graphics}\n\\paragraph{Algorithm 6: Circle Drawing}\nDue to the fact that OpenGL has no inbuilt support for drawing circle primitives, they must be constructed using vertices and line segments in order to form a polygon (GL\\_POLYGON) and fill it in to create a approximated circle.\n\n\\paragraph{}\nTo do this, the center coordinates will be used in conjunction with the radius to calculate trigonometric factors in order to speed up the calculation of the circle. Traditionally, you would calculate the position of the next point in respect to radius by calling the trigonometric functions for every vertex, however with this method they only need to be called once per object as they will be the same for every vertex.\n\n\\paragraph{}\nThe benefit of this is that it still allows for different numbers of segments to be used, higher numbers will make a much smoother looking circle, however it will be dependant somewhat on the radius of the drawn circle, as being able to zoom in will make the straight edges a lot more visible, even when anti-aliasing is used. Due to performance constraints, a lower number here would be better, 16 or 32 is sensible.\n\n$$ \\theta=2\\pi/Segments \\hspace{20pt} k_{\\tan}=\\tan\\theta \\hspace{20pt} k_{\\cos}=\\cos\\theta $$\n$$ x_{pos} = r \\hspace{10pt} \\& \\hspace{10pt} y_{pos} = 0 $$\n$$ x_{pos}+(-y_{pos}k_{\\tan})k_{rad} \\hspace{10pt} \\& \\hspace{10pt} y_{pos}+(x_{pos}k_{\\tan})k_{rad}$$\n\nReferences: \\cite{circle} \\\\\\\n\nRequired Parameters:\n\\begin{itemize}\n\\item Center Point\n\\item Radius\n\\item Segments\n\\end{itemize}\n\n\\pagebreak\n\\subsubsection{Interface}\n\\paragraph{Algorithm 7: Body Selection}\nThis algorithm will work in a similar way to the collision detection code, but on the end of a single body instead of two. By getting the current position of the cursor in the world by using the function gluUnProject() and checking to see if the cursor is inside the radius of any body when a click occurs. Mouse input is handled by GLFW.\n\n\\paragraph{}\nThis function is used as it will use the current matrices that are used for manipulating what is displayed on screen on the cursor coordinates, providing a perfect mapping of what is happening on screen to the window system coordinates.\n\n\\paragraph{}\nIf a body is selected, a GUI will open which will allow the properties of that body to be modified, and then applied with a button on that GUI.\n\n\\paragraph{Algorithm 8: Pan and Zoom}\nBy holding down middle click and dragging, the user will be able to pan the view around the scene to get a better view of different parts. By scrolling, they will also be able to zoom into the position currently at the center of their screen, mouse coordinates and clicks are provided by GLFW.\n\n\\paragraph{}\nThe panning will be calculated by first waiting to see if the mouse has been held down for at least several hundred milliseconds using the GLFW timer, after which the change in cursor positions can be calculated per frame. Zoom will will modify a scale variable that will have set limits, preventing the user from zooming too far in and out.\n\n\\paragraph{}\nThese variables will then be passed into OpenGL specific functions that will perform transformation and scales on the OpenGL ModelView Matrix, giving the illusion of movement and zooming.\n\n\\paragraph{Algorithm 9: Scenario Saving and Loading}\nThe scenario will be able to be saved by the user using elements provided on the UI. The user will be required to enter a file-name in order to save the scenario. The file extension (.sav) will be automatically added.\n\n\\paragraph{}\nThe file will contain a structured and human readable/editable version of the scenario data used by the program, it contains any scenario control variables and the properties of any bodies present in the simulation. There will also be some utility for auto-generation features, such as providing bodies with orbital velocity relative to any other body in the simulation or the generation of large super-structures.\n\n\\paragraph{}\nIn order to load a save, the user can either drag and drop a .sav file into the window or they can enter the file name into the UI element and click on the 'load' button.\n\n\\subsubsection{Management}\n\\paragraph{Algorithm 10: Thread Synchronisation and Shared Data Management}\nWhen shared data is accessed, other threads must be prevented from accessing (Read or Write) the data at the same time as it could cause corruption or deadlocks due to race conditions. Once the thread is done accessing the data it will unlock it to allow another thread to access it.\n\n\\paragraph{}\nThe simulation thread will get initially get the body storage and control variables from the shared storage area (Previously set up and sent to shared by the main thread). It will then perform a number of iterations based on iterations per frame and place the data in the shared area buffer as well as setting a variable to show that new data is available.\n\n\\paragraph{}\nIf the simulation completes another frames worth of iteration before the renderer has taken the data and unset the new data available flag the simulation thread will wait until that data has been taken.\n\n\\paragraph{}\nIf any changes are made to the input scenario, the main thread will update the shared area and notify the simulation thread that new data is available, the Sim thread will discard any data it is currently carrying and take on the new user changes.", "meta": {"hexsha": "0546b89366e26cc4c096d44809f504577ffba829", "size": 12866, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/tex/sections/design/algorithms.tex", "max_stars_repo_name": "btheobald/compa2", "max_stars_repo_head_hexsha": "aa9d5b966fb4c6a4e836e481d9df1bd297de3140", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-02-11T20:01:26.000Z", "max_stars_repo_stars_event_max_datetime": "2016-11-30T16:16:02.000Z", "max_issues_repo_path": "doc/tex/sections/design/algorithms.tex", "max_issues_repo_name": "btheobald/compa2", "max_issues_repo_head_hexsha": "aa9d5b966fb4c6a4e836e481d9df1bd297de3140", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "doc/tex/sections/design/algorithms.tex", "max_forks_repo_name": "btheobald/compa2", "max_forks_repo_head_hexsha": "aa9d5b966fb4c6a4e836e481d9df1bd297de3140", "max_forks_repo_licenses": ["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.8021390374, "max_line_length": 422, "alphanum_fraction": 0.764262397, "num_tokens": 3177, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9324533069832973, "lm_q2_score": 0.8080672066194945, "lm_q1q2_score": 0.753484939077103}}
{"text": "\\subsection{Second and Other Derivatives}\nIf $f$ is a differentiable function then its derivative $f'$ is also a function and so we can take the derivative of $f'$.\nThe new function, denoted by $f''$, is called the \\dfont{second derivative} of $f$, since it is the derivative of the derivative of $f$.\n\nThe following symbols represent the second derivative:\n$$f''(x)=y''=\\frac{d^2y}{dx^2}=\\frac{d}{dx}\\left(\\frac{dy}{dx}\\right).$$\n\nWe can continue this process to get the third derivative of $f$.\n\nIn general, the \\dfont{$n$th derivative} of $f$ is denoted by $f^{(n)}$ and is obtained from $f$ by differentiating $n$ times.\nIf $y=f(x)$, then we write:\n$$y^{(n)}=f^{(n)}(x)=\\frac{d^ny}{dx^n}.$$", "meta": {"hexsha": "0dc0501daf4774ad948f2722b4c618d01d8ee542", "size": 694, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-3-2-second-other-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": "4-derivatives/4-3-2-second-other-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": "4-derivatives/4-3-2-second-other-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": 57.8333333333, "max_line_length": 136, "alphanum_fraction": 0.6873198847, "num_tokens": 221, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.938124016006303, "lm_q2_score": 0.8031737987125612, "lm_q1q2_score": 0.753476629599266}}
{"text": "\\chapter{RELEVANT BACKGROUND IN LINEAR PROGRAMMING} \\label{app:LP}% Must have a blank line after every section label\n\nThis appendix presents an operational description of linear programming (LP), a method of constrained optimization for linear systems of inequalities. Linear programs are the common method for solving the maximum concurrent flow problem (MCFP) and hierarchical MCFP (HMCFP). For greater detail, the reader is directed to Luenberger and Ye~\\cite{luenberger2008linear} or Chvatal~\\cite{chvatal1983linear}.\n\n\\section{Linear Programming}\n\nLinear programming optimizes an objective function that is constrained by linear equalities and inequalities. For some linear objective function $z = c \\transpose x$, we want to find the $x$ that maximizes $z$ while constrained by a system of linear inequalities $Ax \\leq b$. \n\nA linear program in standard form comprises three parts:\n\\begin{enumerate}\n\\item A linear \\say{cost} function to be maximized, e.g. $ z(x_{1},x_{2}) = c_1 x_1 + c_2 x_2$\n\\item Problem constraints, e.g.\n\\begin{equation}\n\\begin{matrix}\n  a_{11} x_1 + a_{12} x_2 &\\leq b_1 \\\\\n  a_{21} x_1 + a_{22} x_2 &\\leq b_2 \\\\\n  a_{31} x_1 + a_{32} x_2 &\\leq b_3 \\\\\n\\end{matrix}\\end{equation}\n\\item Non-negative variables, e.g.\n\\begin{equation}\\begin{matrix}\n x_1 \\geq 0 \\\\\n x_2 \\geq 0\n\\end{matrix}\\end{equation}\n\\end{enumerate}\nProblems with equality constraints or bounds other than non-negativity can be converted into these three parts; the reader is directed toLuenberger~and Ye~\\cite{luenberger2008linear}. The problem is usually expressed in matrix form, and then becomes:\n\\begin{equation}\n\\max \\{ %\n\\mathbf{c} \\transpose\n\\mathbf{x} \\;|\\;\n \\mathbf{A} \\mathbf{x} \\leq \\mathbf{b} \\land \\mathbf{x} \\geq 0 \\}\n\\end{equation}\n\nThese linear constraints form half-planes that bound a convex polytope (a bounded polyhedron)~\\cite{nemhauser1988integer}. Any point inside this polytope is a \\emph{feasible solution}. \n\nSolving a linear program (when a solution exists) gives an optimal basis~$\\mathbf{B}$. This basis is a matrix of  For a given basis, there is a corresponding \\emph{basic solution}~$(\\mathbf{x_B}, \\mathbf{0})$. Here, $\\mathbf{0}$ is the zero vector. The solution only has values for each $x_i$ corresponding to a column in $\\mathbf{B}$. At most, $m$ of its entries are nonzero, where $m$ is the number of columns in A. (Here, we assume as for our problem that the number of rows $n \\geq m$. \n\n\\section{Shadow Prices and Sensitivity}\n\nEvery linear program has a corresponding dual program in the form:\n\n\\begin{equation}\n\\min \\{ %\n\\bm{\\lambda} \\transpose\n\\mathbf{b} \\;|\\;\n\\bm{\\lambda} \\transpose \\mathbf{A} \\geq \\mathbf{c} \\transpose \\land \\bm{\\lambda} \\geq 0 \\}\n\\end{equation}\n\nThe solutions to the dual program provide \\emph{shadow prices}~$\\bm \\lambda$. The shadow prices reflect the marginal utility of relaxing the corresponding constraint in the primal, or the marginal cost of tightening the constraint:\n\n\\begin{align}\n\\lambda_i = \\frac{\\partial z}{\\partial b_i}, \\quad \\forall i \\in \\{1, 2, \\ldots, |\\lambda|\\}\n\\end{align}\n\nThese shadow prices are piecewise linear, and the particular range over which some shadow price~$\\lambda_i$ is valid can be computed~\\cite{luenberger2008linear}: when a value in $\\mathbf{b}$ is altered, the values of the right-hand side in the optimal tableau are altered. The stable range is the interval along which the right-hand side of the tableau remains nonnegative. \n\n\\section{Practical Considerations}\n\nLPs can be quickly solved using the simplex method~\\cite{puterman2014markov}. Although the method scales exponentially with input size in the worst case, average-case performance is far better. Additional methods have been proposed with polynomial worst-case behavior, such as interior point methods.\n", "meta": {"hexsha": "ace11a6a93eb6fa0b249ac95b907061705408763", "size": 3773, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "reports/app.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/app.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/app.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": 63.9491525424, "max_line_length": 490, "alphanum_fraction": 0.7569573284, "num_tokens": 1054, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357735451835, "lm_q2_score": 0.8688267847293731, "lm_q1q2_score": 0.7533039033746066}}
{"text": "\\section{The kernel and image of a linear map}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Describe the kernel and image of a linear transformation, and\n    find a basis for each.\n  \\end{enumerate}\n\\end{outcome}\n\nIn this section we will consider the case where the linear transformation is not necessarily an\nisomorphism. First consider the following important definition.\n\n\\begin{definition}{Kernel and image}{kernel-image}\nLet $V$ and $W$ be subspaces of $\\R^n$ and let $T:V\\to W$ be a linear transformation. Then the image of $T$\ndenoted as $\\func{im}(T) $ is defined to be the set\n\\index{linear map!image}\n\\index{linear map!kernel}\n\\begin{equation*}\n\\func{im}(T) = \\set{T (\\vect{v}):\\vect{v}\\in V}\n\\end{equation*}\nIn words, it consists of all vectors in $W$ which equal $T(\\vect{v})$ for some $\n\\vect{v}\\in V$.\n\nThe kernel of $T$, written $\\ker (T)$, consists of all $\\vect{v}\\in V$ such that $T(\\vect{v})=\\vect{0}$. That is,\n\\begin{equation*}\n\\ker (T) =\\set{\\vect{v}\\in V:T(\\vect{v})=\\vect{0}}\n\\end{equation*}\n\\end{definition}\n\nIt follows that $\\func{im}(T) $ and $\\ker (T) $\nare subspaces of $W$ and $V$ respectively.\n\n\\begin{proposition}{Kernel and image as subspaces}{kernel-image-subspaces}\nLet $V, W$ be subspaces of $\\R^n$ and let $T:V\\rightarrow W$ be a linear transformation. Then $\\ker (\nT) $ is a subspace of $V$ and $\\func{im}(T) $ is a\nsubspace of $W$.\n\\end{proposition}\n\n\\begin{proof}\nFirst consider $\\ker (T)$. It is necessary to\nshow that if $\\vect{v}_{1},\\vect{v}_{2}$ are vectors in $\\ker (T) $\nand if $a,b$ are scalars, then $a\\vect{v}_{1}+b\\vect{v}_{2}$ is also in $\\ker\n(T)$. But\n\\begin{equation*}\nT(a\\vect{v}_{1}+b\\vect{v}_{2}) =aT(\\vect{v}_{1})+bT(\\vect{v}_{2})=a\\vect{0}+b\\vect{0}=\\vect{0}\n\\end{equation*}\nThus $\\ker (T) $ is a subspace of $V$.\n\nNext suppose $T(\\vect{v}_{1}),T(\\vect{v}_{2})$ are two vectors in $\\func{im}(\nT)$. Then if $a,b$ are scalars,\n\\begin{equation*}\naT(\\vect{v}_{2})+bT(\\vect{v}_{2})=T(a\\vect{v}_{1}+b\\vect{v}_{2})\n\\end{equation*}\nand this last vector is in $\\func{im}(T) $ by definition.\n\\end{proof}\n\nWe will now examine how to find the kernel and image of a linear transformation and describe the basis of each.\n\n\\begin{example}{Kernel and image of a linear transformation}{kernel-image}\nLet $T: \\R^4 \\to \\R^2$ be defined by\n\\[\nT \\begin{mymatrix}{c}\na \\\\\nb \\\\\nc \\\\\nd\n\\end{mymatrix} =\n\\begin{mymatrix}{c}\na - b \\\\\nc + d\n\\end{mymatrix}\n\\]\nThen $T$ is a linear transformation. Find a basis for $\\func{ker}(T)$ and $\\func{im}(T)$.\n\\end{example}\n\n\\begin{solution}\nYou can verify that $T$ is a linear transformation.\n\nFirst we will find a basis for $\\func{ker}(T)$. To do so, we want to find a way to describe all vectors $\\vect{x} \\in \\R^4$ such that $T(\\vect{x}) = \\vect{0}$. Let $\\vect{x} =  \\begin{mymatrix}{c}\na \\\\\nb \\\\\nc \\\\\nd\n\\end{mymatrix}$ be such a vector. Then\n\\[\nT \\begin{mymatrix}{c}\na \\\\\nb \\\\\nc \\\\\nd\n\\end{mymatrix} =\n\\begin{mymatrix}{c}\na - b \\\\\nc + d\n\\end{mymatrix} =\n\\begin{mymatrix}{c}\n0 \\\\\n0\n\\end{mymatrix}\n\\]\n\nThe values of $a, b, c, d$ that make this true are given by solutions to the system\n\\begin{eqnarray*}\na - b &=& 0 \\\\\nc + d &=& 0\n\\end{eqnarray*}\nThe solution to this system is $ a = s, b = s, c = t, d = -t$ where $s, t$ are scalars. We can describe $\\func{ker}(T)$ as follows.\n\\[\n\\func{ker}(T) = \\set{\\begin{mymatrix}{r}\ns \\\\\ns \\\\\nt \\\\\n-t\n\\end{mymatrix} }\n=\n\\sspan \\set{\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0 \\\\\n0\n\\end{mymatrix}, \\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n1 \\\\\n-1\n\\end{mymatrix} }\n\\]\nNotice that this set is linearly independent and therefore forms a basis for $\\func{ker}(T)$.\n\nWe move on to finding a basis for $\\func{im}(T)$. We can write the image of $T$ as\n\\[\n\\func{im}(T) = \\set{\\begin{mymatrix}{c}\na - b \\\\\nc + d\n\\end{mymatrix}\n}\n\\]\nWe can write this in the form\n\\[\n\\sspan = \\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n-1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix} }\n\\]\nThis set is clearly not linearly independent. By removing unnecessary vectors from the set we can create a linearly independent set with the same span. This gives a basis for $\\func{im}(T)$ as\n\\[\n\\func{im}(T) = \\sspan \\set{\n\\begin{mymatrix}{r}\n1 \\\\\n0\n\\end{mymatrix},\n\\begin{mymatrix}{r}\n0 \\\\\n1\n\\end{mymatrix}\n}\n\\]\n\\end{solution}\n\nRecall that a linear transformation $T$ is called one to one if and only if $T(\\vect{x}) = \\vect{0}$ implies $\\vect{x} = \\vect{0}$. Using the concept of kernel, we can state this theorem in another way.\n\n\\begin{theorem}{One to one and kernel}{one-to-one-kernel}\nLet $T$ be a linear transformation where $\\func{ker}(T)$ is the kernel of $T$. Then $T$ is one to one if and only if $\\func{ker}(T)$ consists of \\textbf{only} the zero vector.\n\\end{theorem}\n\nA major result is the relation between the dimension of the kernel and\ndimension of the image of a linear transformation. In the previous example $\\func{ker}(T)$ had dimension $2$, and $\\func{im}(T)$ also had dimension of $2$. Is it a coincidence that the dimension of $\\Mat_{2,2}$ is $4 = 2 + 2$? Consider the following theorem.\n\n\\begin{theorem}{Dimension of kernel and image}{dimension-kernel-image}\nLet $T:V\\rightarrow W$ be a linear transformation where $V,W$ are subspaces of $\\R^n$. Suppose the dimension of $V$ is $m$. Then\n\\[\nm=\\dim (\\ker (T)) +\\dim (\\func{im}(\nT))\n\\]\n\\index{rank added to nullity}\n\\index{nullity}\n\\index{rank}\n\\end{theorem}\n\n\\begin{proof}\nFrom Proposition~\\ref{prop:kernel-image-subspaces}, $\\func{im}(T) $ is a subspace of $W$. We know that there exists a basis for $\\func{im}(T)$, $\\set{T(\\vect{v}\n_{1}),\\ldots,T(\\vect{v}_{r})} . $ Similarly, there is a basis for $\\ker\n(T) ,\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s}}$. Then if $\n\\vect{v}\\in V$, there exist scalars $c_{i}$ such that\n\\begin{equation*}\nT(\\vect{v})=\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})\n\\end{equation*}\nHence $T\\paren{\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}} =0$. It follows\nthat $\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}$ is in $\\ker (T)$.\nHence there are scalars $a_{i}$ such that\n\\begin{equation*}\n\\vect{v}-\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}=\\sum_{j=1}^{s}a_{j}\\vect{u}_{j}\n\\end{equation*}\nHence $\\vect{v}=\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}+\\sum_{j=1}^{s}a_{j}\\vect{u}\n_{j}. $ Since $\\vect{v}$ is arbitrary, it follows that\n\\begin{equation*}\nV=\\sspan\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}}\n\\end{equation*}\nIf the vectors $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\n\\vect{v}_{r}} $ are linearly independent, then it will follow that\nthis set is a basis. Suppose then that\n\\begin{equation*}\n\\sum_{i=1}^{r}c_{i}\\vect{v}_{i}+\\sum_{j=1}^{s}a_{j}\\vect{u}_{j}=0\n\\end{equation*}\nApply $T$ to both sides to obtain\n\\begin{equation*}\n\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})+\\sum_{j=1}^{s}a_{j}T(\\vect{u})\n_{j}=\\sum_{i=1}^{r}c_{i}T(\\vect{v}_{i})=0\n\\end{equation*}\nSince $\\set{T(\\vect{v}_{1}),\\ldots,T(\\vect{v}_{r})} $ is linearly\nindependent, it follows that each $c_{i}=0$. Hence $\\sum_{j=1}^{s}a_{j}\\vect{u\n}_{j}=0$ and so, since the $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s}} $\nare linearly independent, it follows that each $a_{j}=0$ also. Therefore $\\set{\\vect{u}_{1},\\ldots,\\vect{u}_{s},\\vect{v}_{1},\\ldots,\\vect{v}\n_{r}} $ is a basis for $V$ and so\n\\begin{equation*}\nn=s+r=\\dim (\\ker (T)) +\\dim (\\func{im}(\nT))\n\\end{equation*}\n\\end{proof}\n\nThe above theorem leads to the next corollary.\n\n\\begin{corollary}{}{}\nLet $T:V\\rightarrow W$ be a linear transformation where $V,W$ are subspaces of $\\R^n$. Suppose the dimension of $V$ is $m$. Then\n\\[\n\\dim (\\ker (T)) \\leq m\n\\]\n\\[\n\\dim (\\func{im}(T)) \\leq m\n\\]\n\\end{corollary}\n\nThis follows directly from the fact that $n=\\dim (\\ker (T)) +\\dim (\\func{im}(\nT))$.\n\nConsider the following example.\n\n\\begin{example}{}{}\nLet $T:\\R^{2}\\rightarrow \\R^{3}$ be defined by\n\\begin{equation*}\nT(\\vect{x})=\\begin{mymatrix}{rr}\n1 & 0 \\\\\n1 & 0 \\\\\n0 & 1\n\\end{mymatrix} \\vect{x}\n\\end{equation*}\nThen $\\func{im}(T) =V$ is a subspace of $\\R^{3}$ and $T$\nis an isomorphism of $\\R^{2}$ and $V$. Find a $2\\times 3$-matrix $A$\nsuch that the restriction of multiplication by $A$ to $V=\\func{im}(\nT) $ equals $T^{-1}$.\n\\end{example}\n\n\\begin{solution}\nSince the two columns of the above matrix are linearly independent, we conclude that $\\dim(\\func{im}(T)) = 2$ and therefore $\\dim(\\func{ker}(T)) = 2 - \\dim(\\func{im}(T)) = 2-2 = 0$ by Theorem~\\ref{thm:dimension-kernel-image}. Then by Theorem~\\ref{thm:one-to-one-kernel} it follows that $T$ is one to one.\n\nThus $T$ is an isomorphism of $\\R^{2}$ and the $2$-dimensional subspace of $\\R^{3}$ which is the\nspan of the columns of the given matrix. Now in particular,\n\\begin{equation*}\nT(\\vect{e}_{1})=\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\ T(\\vect{e}_{2})=\\begin{mymatrix}{r}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nThus\n\\begin{equation*}\nT^{-1}\\begin{mymatrix}{r}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\vect{e}_{1},\\ T^{-1}\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} =\\vect{e}_{2}\n\\end{equation*}\nExtend $T^{-1}$ to all of $\\R^{3}$ by defining\n\\begin{equation*}\nT^{-1}\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\vect{e}_{1}\n\\end{equation*}\nNotice that the vectors\n\\begin{equation*}\n\\set{\\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} ,\\begin{mymatrix}{c}\n0 \\\\\n1 \\\\\n0\n\\end{mymatrix} }\n\\end{equation*}\nare linearly independent so $T^{-1}$ can be extended linearly to yield a\nlinear transformation defined on $\\R^{3}$. The matrix of $T^{-1}$\ndenoted as $A$ needs to satisfy\n\\begin{equation*}\nA\\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n1 & 0 & 1 \\\\\n0 & 1 & 0\n\\end{mymatrix} =\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n0 & 1 & 0\n\\end{mymatrix}\n\\end{equation*}\nand so\n\\begin{equation*}\nA=\\begin{mymatrix}{rrr}\n1 & 0 & 1 \\\\\n0 & 1 & 0\n\\end{mymatrix} \\begin{mymatrix}{rrr}\n1 & 0 & 0 \\\\\n1 & 0 & 1 \\\\\n0 & 1 & 0\n\\end{mymatrix}^{-1}=\\begin{mymatrix}{rrr}\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix}\n\\end{equation*}\nNote that\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\n1 \\\\\n1 \\\\\n0\n\\end{mymatrix} =\\begin{mymatrix}{c}\n1 \\\\\n0\n\\end{mymatrix}\n\\end{equation*}\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n0 & 1 & 0 \\\\\n0 & 0 & 1\n\\end{mymatrix} \\begin{mymatrix}{c}\n0 \\\\\n0 \\\\\n1\n\\end{mymatrix} =\\begin{mymatrix}{c}\n0 \\\\\n1\n\\end{mymatrix}\n\\end{equation*}\nso the restriction to $V$ of matrix multiplication by this matrix yields $\nT^{-1}$.\n\\end{solution}\n", "meta": {"hexsha": "1420911b5235f54f6897da006f61a173ca8cdc1d", "size": 10323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/lineartransformationsKernelImage.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/lineartransformationsKernelImage.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/lineartransformationsKernelImage.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.454787234, "max_line_length": 304, "alphanum_fraction": 0.6439019665, "num_tokens": 3968, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8688267796346599, "lm_q2_score": 0.867035752930664, "lm_q1q2_score": 0.7533038810468615}}
{"text": "\\chapter{Countable Sets}\nIn the previous section we studied properties of finite sets; this section\nuses developed methods to study of infinite sets.\n\n\\section{Equipotent Sets}\n\n\\Cref{theorem:bijection-to-equality} says that there is a bijection between\nfinite sets $X$ to $Y$ iff they have equal cardinalities. In this case we say\nthat $X$ and $Y$ equipotent.\nThis idea can be extended to infinite sets.\n\\begin{definition}\n  Let $X$ and $Y$ be sets. We say that $X$ and $Y$ are \\emph{equipotent} (this\n  is written $\\cardinality{X} = \\cardinality{Y}$) if there is a bijection from\n  $X$ to $Y$.\n\n  We say that a set $X$ is \\emph{denumerable} if $X$ and $\\N$ are equipotent.\n  If the set $X$ is denumerable, then it is said to have cardinality $\\aleph_0$\n  (this is written $\\cardinality{X} = \\aleph_0$ and read `aleph null').\n\n  We also say that the set is \\emph{countable} if it is finite or denumerable;\n  otherwise the set is \\emph{uncountable}.\\footnote{%\n    This notation may vary from book to book and in some of them countable is\n    used where this book uses denumerable.\n  }\n\\end{definition}\n\nIt is possible to show that $\\Z$ is denumerable. Indeed, we may consider $f :\n\\Z$ to $\\N$ such that \n\\[\n  f(x) = \n  \\begin{cases}\n    2x + 2 & \\text{if } x \\ge 0 \\\\\n    -2x - 1 & \\text{if } x < 0\n  \\end{cases}.\n\\]\nIt is clear that $f(-1) = 1$, $f(-2) = 3$, \\dots, $f(0) = 2$, $f(1) = 4$, $f(2)\n= 6$, \\dots, so $f$ is a bijection.\n\\begin{itemize}\n  \\item More formally $f$ is a surjection since $f(k / 2 - 1) = k$ for any even\n    $k$ and $f(-(k + 1) / 2) = k$ for all odd $k$.\n  \\item Assume $f(x) = f(y)$ for some $x$ and $y$. Note that if $x$ and\n    $y$ have different signs, one of $f(x)$ and $f(y)$ is even and another is\n    odd so they cannot be equal to each other.\n    \\begin{itemize}\n      \\item If $x, y \\ge 0$, then $f(x) = 2x + 2 = f(y) = 2y + 2$ implies that\n        $x = y$.\n      \\item If $x, y < 0$, then $f(x) = -2x - 1= f(y) = -2y - 1$ also implies\n        that $x = y$.\n    \\end{itemize}\n    Hence, $f$ is an injection.\n\\end{itemize}\n\n\\begin{exercise}\n  Show that $\\N_0$ and $\\Z$ are equipotent.\n\\end{exercise}\n\n\\section{Properties of Denumerable Sets}\n\nFor finite sets, their cardinality determine if they are equipotent or not; the\nsame property can be proven for denumerable sets.\n\\begin{remark}\n\\label{remark:denumerable-equipotent-to-denumerable}\n  Let $X$ and $Y$ be sets such that $X$ is denumerable. Then $Y$ is denumerable\n  iff $X$ and $Y$ are equipotent.\n\\end{remark}\n\nThe additive principle states that union of two finite sets is also finite\nthough normally it is bigger; however, in case of denumerable sets only first\npart is true.\n\\begin{theorem}\n\\label{theorem:union-denumerable-sets}\n  Let $X$ and $Y$ be denumerable sets. Then $X \\cup Y$ is also denumerable.\n\\end{theorem}\n\n\\begin{exercise}\n  Prove \\Cref{theorem:union-denumerable-sets}.\n\\end{exercise}\n\n\nWe can also prove an analogue of the multiplicative principle.\n\\begin{theorem}\n  Let $X$ and $Y$ be denumerable sets. Then $X \\times Y$ is also denumerable.\n\\end{theorem}\n\\begin{proof}\n  It is clear that it is enough to prove the statement for $X = \\N$ and $Y =\n  \\N$. The set $\\N^2$ can be represented as an infinite grid:\n  \\[\n    \\begin{matrix}\n      (1, 1) & (2, 1) & (3, 1) & \\dots \\\\\n      (1, 2) & (2, 2) & \\dots \\\\\n      (1, 3) & \\dots \\\\\n      \\dots \\\\\n    \\end{matrix}.\n  \\]\n  We cannot enumerate elements of this table column-wise or row-wise since they\n  are infinite. However, we can enumerate them along the diagonals, as follows:\n  \\[\n    \\begin{matrix}\n      1 & 3 & 6 & \\dots \\\\\n      2 & 5 & \\dots \\\\\n      4 & \\dots \\\\\n      \\dots \\\\\n    \\end{matrix}.\n  \\]\n  Note $n$th diagonal contains $n$ elements so the element $(m, n)$ appears as\n  the $m$th element of the $(m + n - 1)$th diagonal and has the number \n  $1 + 2 + \\dots + (m + n - 2) + n = (m + n - 1) (m + n - 2) / 2 + n$.\n\\end{proof}\n\nIn addition we may prove the following.\n\\begin{theorem}\n  Let $X$ and $Y$ be two sets such that $X$ is denumerable and $Y \\subseteq X$.\n  Then $Y$ is countable.\n\\end{theorem}\n\\begin{proof}\n  It is clear that the statement is true if $Y$ is finite and $X = \\N$. \n  Hence, let us assume that $Y \\subseteq \\N$ is infinite. So we need to\n  construct a bijection $f : Y \\to \\N$; we are going to do it inductively.\n\n  We start with the base case.\n  Let $f(1)$ be the smallest element of $Y$; it exists by the well-ordering\n  principle (\\Cref{theorem:well-ordering}). \n\n  For the induction step from $k$ to $k + 1$, assume that $f(k)$ is defined.\n  Let $f(k + 1)$ be the minimal element of $\\set[y > f(k)]{y \\in Y}$ (this set\n  is not empty since $Y$ is infinite).\n\n  This process clearly defines an increasing function from $\\N$ to $Y$. So to\n  finish the proof we need to prove that it is a surjection.\n  Let $y \\in Y$ and let $n$ be the minimal number such that $f(n) \\ge y$ (such a\n  number exists since it can be proven that $f(n) \\ge n$). Then by the\n  definition of $f$, $f(n) = y$.\n\\end{proof}\n\nUsing the last two results we can make the following observation.\n\\begin{theorem}\n  The set of rationals $\\Q$ is denumerable.\n\\end{theorem}\n\n\\begin{chapterendexercises}\n    \\exercise[recommended] Show that $\\set[n \\in \\Z]{2n}$ is denumerable.\n    \\exercise Show that $\\set[n \\in \\Z]{n^2}$ is denumerable.\n    \\exercise Let $X$ be a countable set and $n$ be a positive integer. Prove\n      that $X^n$ is countable.\n    \\exercise[recommended] Let $X_1$, \\dots, $X_n$, \\dots be finite sets. Show that\n      $\\bigcup_{i \\in \\N} X_i$ is countable.\n    \\exercise Let $X_1$, \\dots, $X_n$, \\dots be denumerable sets. Show that\n      $\\bigcup_{i \\in \\N} X_i$ is denumerable.\n    \\exercise Show that $\\set{0, 1}^\\N$ is equipotent to $\\set{0, 1, 2, 3}^\\N$.\n\\end{chapterendexercises}\n", "meta": {"hexsha": "169da4361c22598140de8c635ac18ddab86390bf", "size": 5777, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "parts/part_5/chapter_25_countable.tex", "max_stars_repo_name": "alexanderknop/I2DM", "max_stars_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2020-01-12T05:01:10.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-12T11:44:11.000Z", "max_issues_repo_path": "parts/part_5/chapter_25_countable.tex", "max_issues_repo_name": "aaknop/I2DM", "max_issues_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": 69, "max_issues_repo_issues_event_min_datetime": "2019-01-09T00:19:58.000Z", "max_issues_repo_issues_event_max_datetime": "2019-06-04T00:27:16.000Z", "max_forks_repo_path": "parts/part_5/chapter_25_countable.tex", "max_forks_repo_name": "aaknop/I2DM", "max_forks_repo_head_hexsha": "745bc4e24087c1d7abd02f39c1481bb7b7ddb796", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2019-01-08T23:55:41.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-12T07:14:44.000Z", "avg_line_length": 38.2582781457, "max_line_length": 83, "alphanum_fraction": 0.6482603427, "num_tokens": 1949, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117940706734, "lm_q2_score": 0.9111797166446536, "lm_q1q2_score": 0.7532830182681094}}
{"text": "\\subsection{Introduction to Determinant}\n\nCan define the $2\\times 2$ determinant as a function $D:\\mathbb{M}_{2\\times2}\\rightarrow R$.\nIt can be observed that $2\\times 2$ matrix $A$ is only invertible if $D(A)=ad-bc\\neq 0$.\n\n\\subsection{Cross-Product}\n\nGiven $\\begin{bmatrix}a\\\\ c\\end{bmatrix}$ and $\\begin{bmatrix}b\\\\ d\\end{bmatrix}$, the cross\nproduct is defined as the $\\R^3$ vector $D(A)\\tb{e}_3=(ad-bc)\\tb{e}_3$. The direction\nof this vector is the sign of $\\mathrm{det}(A)$.\n\n\\noindent\nCan visualize using right hand rule: if sweeping index into middle is appropriate for the vectors,\nthen the direction of thumb is cross-product direction (positive). Otherwise, sign is negative.\n\n\\subsubsection{Algorithm}\n\nFor $\\tb{v}=\\begin{bmatrix}v_x\\\\ v_y\\\\ v_z\\end{bmatrix}$ and $\\tb{w}=\\begin{bmatrix}w_x\\\\ w_y\\\\ w_z\\end{bmatrix}$:\n\n\\[\\boxed{\\tb{v}\\times\\tb{w}=c_z\\tb{e}_1+c_y\\tb{e}_2+c_z\\tb{e}_z}\\]\n\nFollowing through, to calculate each component ignore the desired row and perform cross-product on remaining matrix:\n\n\\[c_x=\\begin{bmatrix}v_y\\\\ v_z\\end{bmatrix}\\times \\begin{bmatrix}w_y\\\\ w_z\\end{bmatrix}=v_yw_z-v_zw_z\\]\n\nThe $y$ component is done as $bc-ad$ compared to $ad-bc$.\n\n\\[c_y=\\begin{bmatrix}v_x\\\\ v_z\\end{bmatrix}\\times \\begin{bmatrix}w_x\\\\ w_z\\end{bmatrix}=w_xv_z-w_zv_x\\]\n\n\\[c_z=\\begin{bmatrix}v_y\\\\ v_z\\end{bmatrix}\\times \\begin{bmatrix}w_y\\\\ w_z\\end{bmatrix}=v_xw_y-v_yw_x\\]\n\n\\subsection{Determinant Theory}\n\nConsidering $A=\\begin{bmatrix}|&|&| \\\\\\tb v_1 & \\tb v_2 &\\tb v_3 \\\\ |&|&| \\\\ \\end{bmatrix}$,\nsay it is singular such that $\\tb{v}_3\\in \\mathrm{span}\\{\\tb{v}_1,\\tb{v}_2\\}$. Because it is assumed that\n$\\tb{v}_1,\\tb{v}_2$ are linearly independent, then $\\mathrm{span}\\{\\tb{v}_1,\\tb{v}_2\\}$ is perpendicular to \n$\\tb{v}_1\\times \\tb{v}_2$ by definition. Thus, $\\boxed{(\\tb{v}_1\\times\\tb{v}_2)\\cdot \\tb{v}_3=0}$.\nIf $\\tb{v}_1,\\tb{v}_2$ are not linearly independent, then this is still 0 because the cross-product (area of parallelogram made by vectors)\nis still 0.\n\n\\noindent\nIf $\\tb{v}_1,\\tb{v}_2,\\tb{v}_3$ are linearly independent, then $(\\tb{v}_1\\times\\tb{v}_2)\\cdot \\tb{v}_3\\neq0$.\n\n\\[\\boxed{D(A)=\\mathrm{det}(A)=(\\tb{v}_1\\times\\tb{v}_2)\\cdot \\tb{v}_3}\\]\n\n\\noindent\nThe sub-matrices used when computing cross-products are \\textbf{minors}.\nCan rewrite determinant:\n\n\\[\\boxed{\\det A= a_{1,3}\\left|A_{1,3}\\right|-a_{2,3}\\left|A_{2,3}\\right|+a_{3,3}\\left|A_{3,3}\\right|}\\]\n\nMust use following rule for the sign of constant terms $a_{m,n}$ (dot product):\n\n\\[\\begin{bmatrix}+&-&+\\\\-&+&-\\\\+&-&+\\end{bmatrix}\\]\n\n\\subsection{Rules}\n\nDeterminant of $n\\times n$ follows recursively:\n\n\\[\\boxed{\\mbox{det}A=a_{1,1}\\left|A_{1,1}\\right|-a_{1,2}\\left|A_{1,2}\\right|+a_{1,3}\\left|A_{1,3}\\right|+\\dots\\pm a_{1,n}\\left|A_{1,n}\\right|}\\]\n\n\\noindent\nRules:\n\\begin{itemize}\n    \\item Swapping rows multiplies determinant by -1\n    \\item Multiplying row by $m$ scales determinant by $m$\n    \\item Replacing row with sum of row and multiple of another does not change determinant\n    \\item If $A$ and $B$ are $n\\times n$, then $\\mathrm{det}(AB)=\\mathrm{det}(A)\\mathrm{det}(B)$\n    \\item Cramer's rule: If $A\\tb{x}=\\tb{b}$ is a linear system with invertible $A$ then $\\tb{x}$ components can be determined\n    from $x_i=\\frac{\\mathrm{det}(A-_{b,i})}{\\mathrm{det}(A)}$ where $A-_{b,i}$ replaces $i^{\\mathrm{th}}$ column of $A$ with $\\tb{b}$\n\\end{itemize}", "meta": {"hexsha": "fd41b86114705014de343fd8435b484464b48801", "size": 3349, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/16_determinants.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/16_determinants.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/16_determinants.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": 47.1690140845, "max_line_length": 144, "alphanum_fraction": 0.6864735742, "num_tokens": 1243, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972616934408, "lm_q2_score": 0.865224072151174, "lm_q1q2_score": 0.7532617079660602}}
{"text": "\\section{Recurrence and Transience of Random Walks}\r\n\\begin{example}[Simple random walk on $\\mathbb Z$]\r\n    Consider the Markov chain with $I=\\mathbb Z$ with $p_{i,i+1}=p,p_{i,i-1}=q=1-p$ where $p\\in (0,1)$.\r\n    We shall try to compute $p_{00}^{(N)}$.\r\n    Now if $N$ is odd, then obviously $p_{00}^{(N)}=0$ by a parity argument.\r\n    If $N=2n,n\\in\\mathbb Z$,\r\n    $$p_{00}^{(2n)}=\\binom{2n}{n}p^nq^n=\\frac{(2n)!}{(n!)^2}p^nq^n$$.\r\n    Stirling's formula gives $n!\\sim\\sqrt{2\\pi n}e^{-n}n^n$ for large $n$ which gives\r\n    $$p_{00}^{(2n)}\\sim\\frac{\\sqrt{4\\pi n}}{2\\pi n}\\frac{(2n)^{2n}}{n^{2n}}(pq)^n=\\frac{C}{\\sqrt{n}}(4pq)^n$$\r\n    where $C$ is a constant we do not really care about at the moment.\r\n    In the symmetric case $p=q=1/2$, we have $p_{00}^{(2n)}\\sim C/\\sqrt{n}\\ge C/(2\\sqrt{n})$ for $n\\ge n_0$ for some $n_0$.\r\n    Hence\r\n    $$\\sum_{n=0}^\\infty p_{00}^{(n)}\\ge \\sum_{n=n_0}p_{00}^{(2n)}\\ge \\frac{C}{2}\\sum_{n=n_0}^\\infty \\frac{1}{\\sqrt{n}}=\\infty$$\r\n    so the random walk is recurrent.\r\n    Otherwise $p\\neq q$, in which case necessarily $4pq<(2p+2q)/2=1$ by AM-GM, so $p_{00}^{(2n)}\\le r^n$ for $n\\ge n_0$, so $\\sum_np_{00}^{(n)}$ converges, therefore this random walk is transient.\r\n    Hence symmetric random walks on $\\mathbb Z$ is recurrent while asymmetric ones are transient.\r\n\\end{example}\r\n\\begin{example}[Simple symmetric random walk on $\\mathbb Z^2$]\r\n    Take $I=\\mathbb Z^2$ and\r\n    $$p_{ij}=\\begin{cases}\r\n        1/4\\text{, if $|i-j|=1$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    We will use a nice trick, which sadly doesn't work in high dimensions in general.\r\n    Suppose $X_0=0$ and write $X_n^{\\pm}$ as the orthogonal projections of $X_n$ onto the diagonal lines $y=\\pm x$.\r\n    Now $X_n^\\pm$ are independent symmetric random walks in $2^{-1/2}\\mathbb Z$.\r\n    Also $X_0=0$ iff $X_0^{\\pm}=0$.\r\n    So by Stirling's approximation.\r\n    $$p_{00}^{(2n)}=\\left( \\binom{2n}{n}\\left(\\frac{1}{2}\\right)^{2n} \\right)^2\\sim\\frac{C}{n}$$\r\n    for some constant $C$.\r\n    But then by summing them up we know this random walk is also recurrent.\r\n\\end{example}\r\nSome na\\\"ive kids will then conjecture that any symmetric random walks on $\\mathbb Z^n$ is recurrent.\r\nWell, they are called na\\\"ive for a reason.\r\n\\begin{example}[Simple symmetric random walk on $\\mathbb Z^3$]\r\n    Consider $I=\\mathbb Z^3$ and\r\n    $$p_{ij}=\\begin{cases}\r\n        1/6\\text{, if $|i-j|=1$}\\\\\r\n        0\\text{, otherwise}\r\n    \\end{cases}$$\r\n    Again $p_{00}^{(N)}=0$ for odd $N$.\r\n    All walks from $0$ to $0$ must take the same number of steps in directions $\\pm e_i$, so\r\n    \\begin{align*}\r\n        p_{00}^{(2n)}&=\\sum_{i,j,k\\ge 0,i+j+k=n}\\binom{2n}{i,i,j,j,k,k}\\left( \\frac{1}{6} \\right)^{2n}\\\\\r\n        &=\\binom{2n}{n}\\left(\\frac{1}{2} \\right)^{2n}\\sum_{i,j,k\\ge 0,i+j+k=n}\\binom{n}{i,j,k}^2\\left( \\frac{1}{3} \\right)^{2n}\r\n    \\end{align*}\r\n    Now if $n=3m$, it can be easily seen that $\\binom{n}{i,j,k}$ is at most $\\binom{n}{m,m,m}$.\r\n    Also, we have\r\n    $$\\sum_{i,j,k\\ge 0,i+j+k=n}\\binom{n}{i,j,k}\\left( \\frac{1}{3} \\right)^n=1$$\r\n    by the multinomial theorem.\r\n    These facts then implies that if $n=3m$,\r\n    $$p_{00}^{(2n)}\\le\\binom{2n}{n}\\left( \\frac{1}{2} \\right)^{2n}\\binom{3m}{m,m,m}\\left( \\frac{1}{3} \\right)^{3m}\\sim Cn^{-3/2}$$\r\n    In addition, we know that $p_{00}^{(2n)}\\ge (1/6)^2p_{00}^{(2n-2)}$, so we can modify our $C$ by a factor to obtain $p_{00}^{(2n)}\\le Cn^{-3/2}$ for large enough $n$, which shows\r\n    $$\\sum_{n}p_{00}^{(2n)}\\le C\\sum_{n}n^{-3/2}<\\infty$$\r\n    Hence this random walk is transcient.\r\n\\end{example}", "meta": {"hexsha": "f9e4e0bfa436cacbf2c5b31a01558b083363607d", "size": 3576, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6/walk.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": "6/walk.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": "6/walk.tex", "max_forks_repo_name": "david-bai-notes/IB-Markov-Chains", "max_forks_repo_head_hexsha": "cef4f20b59106a1deaed4de2f503e594e3ffc61d", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.8571428571, "max_line_length": 197, "alphanum_fraction": 0.5942393736, "num_tokens": 1415, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972549785203, "lm_q2_score": 0.8652240686758841, "lm_q1q2_score": 0.7532616991305714}}
{"text": "\\chapter{Discrete Fourier Transform}\n\nThe Discrete Fourier Transform or DFT is the Fourier Transform of a finite length DT signal. As we shall see, the DFT/FFT is mathematically equivalent to the Discrete-Time Fourier Series. It can be viewed as a way to numerically approximate the CT Fourier transform. Lets first just state the transform and then derive it and see how to interpret and apply it.\n\nGiven a finite-length sequence of real or complex numbers $x[n]$, indexed from $0$ to $N-1$, the \\emph{Discrete Fourier Transform} or DFT is given by\n\\[\nX[k] = \\sum_{n = 0}^{N-1}  x[n] e^{-j \\frac{2\\pi}{N}k n}\n\\]\nfor $k = 0, 1, 2, \\cdots, N-1$. When $N$ is a power of 2, an efficient algorithm to compute this result exists and is called the \\emph{Fast Fourier Transform} or FFT.\n\n\\section{Numerically Approximating the CT Fourier Transform}\n\nRecall the CT Fourier transform pair $x(t) \\stackrel{\\mathcal{F}}{\\longleftrightarrow} X(j\\omega)$:\n\\[\nX(j\\omega) = \\int\\limits_{-\\infty}^{\\infty} x(t) e^{-j\\omega t} \\; dt\n\\]\n\n\\[\nx(t) = \\frac{1}{2\\pi} \\int\\limits_{-\\infty}^{\\infty} X(j\\omega) e^{j\\omega t} \\; d\\omega\n\\]\n\nHow could we compute these when we have a physical signal, rather than just a mathematical model?\n\nRecall from calculus the (left) Riemann sum approximation of a definite integral\n\\[\n\\int\\limits_{t_1}^{t_2} f(t) \\; dt = \\lim_{N \\rightarrow \\infty} \\sum_{n = 0}^{N-1} \\frac{t_2-t_1}{N} f\\left(t_1 + n\\frac{t_2-t_1}{N}\\right) \n\\]\n\\begin{center}\n  \\includegraphics[scale=0.9]{graphics/riemann_sum.pdf}\n\\end{center}\nIn the case of the CTFT, if the signal $x(t)$ is non-zero only over some interval $(t_1, t_2)$, then\n\\[\n\\mathcal{F}\\{ x(t) \\} = \\int\\limits_{t_1}^{t_2} x(t) e^{-j\\omega t} \\; dt \\approx \\sum_{n = 0}^{N-1} \\frac{t_2-t_1}{N} x\\left(t_1 + n\\frac{t_2-t_1}{N}\\right) e^{-j\\omega \\left(t_1 + n\\frac{t_2-t_1}{N}\\right)} \n\\]\nfor large $N$.\\\\[1em]\n\nIf we define the time sample spacing as $T = \\frac{t_2-t_1}{N}$, then\n\\[\nX(j\\omega) \\approx \\sum_{n = 0}^{N-1} T \\, x\\left(t_1 + nT\\right) e^{-j\\omega \\left(t_1 + nT\\right)}\n\\]\n\nNote $x\\left(t_1 + nT\\right)$ corresponds to \\emph{samples} of $x(t)$ starting at $t_1$ with sampling interval $T$. This information is equivalent to the triad $t_1, T, x[n]$, where $x[n]$ is a finite length sequence of numbers, i.e. a DT signal where $x[n] = 0$ for $n < 0$ and $n \\geq N$. Thus,\n\n\\[\nx\\left(t_1 + nT\\right) = x[n]\n\\]\n\nSubstituting into our approximation\n\\[\nX(j\\omega) \\approx \\sum_{n = 0}^{N-1} T \\, x\\left(t_1 + nT\\right) e^{-j\\omega \\left(t_1 + nT\\right)} = T e^{-j\\omega t_1} \\sum_{n = 0}^{N-1} x[n] e^{-j\\omega n T} \n\\]\n\nNow, consider a sampling of the frequency axis $\\omega = \\frac{2\\pi}{NT} k$. Then\n\\[\n\\omega n T = \\frac{2\\pi}{N T} k n T = \\frac{2\\pi}{N}k n\n\\]\nand\n\\[\nX\\left(j\\frac{2\\pi}{NT} k\\right) = T e^{-j\\omega t_1} \\underbrace{\\sum_{n = 0}^{N-1} x[n]  e^{-j \\frac{2\\pi}{N}k n}}_{\\text{DFT}} = T e^{-j\\omega t_1} \\, X[k] \n\\]\n\nThus we see the DFT corresponds to the Fourier transform of a sampled CT signal over a limited time-interval, at samples of the frequency axis.\n\nSimilarly, in the case of the Inverse CTFT, if the signal $X(j\\omega)$ is non-zero only over some interval $(\\omega_1, \\omega_2)$, then\n\\begin{align*}\n  \\mathcal{F}^{-1}\\{ X(j\\omega) \\} &= \\frac{1}{2\\pi} \\int\\limits_{\\omega_1}^{\\omega_2} X(j\\omega) e^{j\\omega t} \\; dt\\\\ &\\approx \\frac{1}{2\\pi} \\sum_{k = 0}^{M-1} \\frac{\\omega_2-\\omega_1}{M} X\\left(\\omega_1 + k\\frac{\\omega_2-\\omega_1}{M}\\right) e^{j \\left(\\omega_1 + k\\frac{\\omega_2-\\omega_1}{M}\\right)t} \n\\end{align*}\nfor large $M$. If we define the frequency sample spacing as $W = \\frac{\\omega_2-\\omega_1}{M}$, then\n\\[\nx(t) \\approx \\sum_{m = 0}^{M-1} \\frac{W}{2\\pi}  \\, X\\left(\\omega_1 + kW\\right) e^{j\\left(\\omega_1 + kW\\right)t}\n\\]\n\nNote $X\\left(\\omega_1 + mW\\right)$ corresponds to samples of $X(j\\omega)$ starting a $\\omega_1$ with sampling interval $W$. This information is equivalent to the triad $\\omega_1$, $W$, $X[k]$, where $X[k]$ is a finite length sequence of numbers where \n\\[\nX\\left(\\omega_1 + mW\\right) = X[k]\n\\]\nSubstituting \n\\[\nx(t) \\approx \\sum_{m = 0}^{M-1} \\frac{W}{2\\pi}  \\, X\\left(\\omega_1 + kW\\right) e^{j\\left(\\omega_1 + kW\\right)t} = \\frac{W}{2\\pi} e^{j\\omega_1} \\sum_{m = 0}^{M-1}  X[k] e^{j kWt} \n\\]\n\nConsider the sampling of the time axis in the derivation of the DFT, $t = nT$. Let $\\omega_1 = 0$ and $\\omega_2 = \\frac{2\\pi}{T}$ and $M = N$. Then\n\\[\nkWt = kWnT = k \\frac{2\\pi}{NT} n T = \\frac{2\\pi}{N}kn\n\\]\nSince $W = \\frac{2\\pi}{NT}$\n\\[\nx(nT) = \\frac{1}{T} \\underbrace{\\frac{1}{N} \\sum_{k = 0}^{N-1}  X[k] e^{j \\frac{2\\pi}{N}k n}}_{\\text{Inverse DFT}} = \\frac{1}{T} x[n] \n\\]\nThus we see the IDFT corresponds to the Inverse Fourier transform of a sampled Fourier Transform over a limited bandwidth, at samples of the time axis.\n\nThis gives us the DFT pair\n\\[\nX[k] = \\text{DFT} \\{ x[n] \\} = \\sum_{n = 0}^{N-1}  x[n] e^{-j \\frac{2\\pi}{N}k n}\n\\]\n\\[\nx[n] = \\text{IDFT} \\{ x[n] \\} = \\frac{1}{N} \\sum_{k = 0}^{N-1}  X[k] e^{j \\frac{2\\pi}{N}k n}\n\\]\nNote the similarity to the DT Fourier Series when $N_0 = 0$\n\\[\nx[n] = \\sum\\limits_{k = N_0}^{N_0 + N - 1} a_k e^{j\\frac{2\\pi}{N}kn} =  \\sum\\limits_{k = 0}^{N - 1} a_k e^{j\\frac{2\\pi}{N}kn}\n\\]\n\\[\na_k = \\frac{1}{N}\\sum\\limits_{n = N_0}^{N_0 + N - 1} x[n] e^{-j\\frac{2\\pi}{N}kn} =  \\frac{1}{N}\\sum\\limits_{n = 0}^{N - 1} x[n] e^{-j\\frac{2\\pi}{N}kn}\n\\]\n\n\\section{Efficient Computation of DFT (FFT)}\n\nGiven the DFT pair and an input signal, it is easy to compute the DFT. For example in C++ we can define a signal as an array of complex numbers\n\n\\begin{verbatim}\n#include <complex>\n#include <vector>\n\ntypedef Signal std::vector<std::complex<double>>;\n\\end{verbatim}\n\nand implement the DFT in a straightforward translation of the expressions above:\n\n\\begin{verbatim}\nSignal dft(const Signal & in){\n\n  Signal out = in;\n  \n  const int N = in.size();\n\n  for(int k = 0; k < N; ++k){\n    out[k] = 0;\n    for(int n = 0; n < N; ++n){\n      out[k] += in[n]*exp(-j*2.*PI*double(k)*double(n)/double(N));\n    }\n  }\n\n  return out;\n}\n\\end{verbatim}\n\nBecause of the nested for loops the number of multiplies and adds required to compute the DFT is proportional to the number of samples in the signal, squared. However, by expanding the complex exponential we see\n\\begin{align*}\n  X[k] &= \\sum_{n = 0}^{N-1}  x[n] e^{-j \\frac{2\\pi}{N}k n}\\\\\n  &= \\sum_{n = 0}^{N-1}  x[n] \\left\\{ \\cos\\left( -\\frac{2\\pi}{N}k n\\right) + j \\sin\\left(-\\frac{2\\pi}{N}k n \\right)\\right\\}\\\\\n  &= \\sum_{n = 0}^{N-1}  x[n] \\left\\{ \\cos\\left( \\frac{2\\pi}{N}k n\\right) - j \\sin\\left(\\frac{2\\pi}{N}k n \\right)\\right\\}\n\\end{align*}\nWhich can be compactly written as\n\\[\nX = \\mathcal{W} x\n\\]\nwhere $x \\in \\mathbb{C}^N$ is the sampled signal treated as a complex-valued vector, and $\\mathcal{W} \\in \\mathbb{C}^{N\\times N}$ is a complex-valued matrix with entries\n\\[\n\\mathcal{W}_{k\\,n} = \\cos\\left( \\frac{2\\pi}{N}k n\\right) - j \\sin\\left(\\frac{2\\pi}{N}k n \\right) = \\left( e^{-j\\frac{2\\pi}{N}}\\right)^{kn}\n\\]  \n\nSimilarly for the inverse DFT\n\\begin{align*}\n  x[n] &= \\sum_{k = 0}^{N-1}  X[k] e^{j \\frac{2\\pi}{N}k n}\\\\\n  &= \\sum_{k = 0}^{N-1}  X[k] \\left\\{ \\cos\\left( \\frac{2\\pi}{N}k n\\right) + j \\sin\\left(\\frac{2\\pi}{N}k n \\right)\\right\\}\n\\end{align*}\nWhich can be compactly written as\n\\[\nx = \\frac{1}{N} \\mathcal{W}^{*} X\n\\]\n\nThis implies $\\frac{1}{N}\\mathcal{W}\\mathcal{W}^* = I$. This special structure ($\\mathcal{W}$ is orthogonal) is what enables the Fast Fourier Transform algorithm to compute the DFT/IDFT in $O(N\\log_2 N)$ multiply/adds. The most common algorithm for implemeting the FFT is called the Cooley–Tukey radix-2 algorithm. This algorithm can be implemented using C++ as:\n\n\\begin{verbatim}\nSignal fft(const Signal & in){\n\n  Signal out;\n\n  std::size_t n = in.size();\n  double logn = log2(n);\n\n  for (unsigned int i = 0; i < n; ++i) {\n    int rev = bitReverse(i, logn);\n    out[i] = in[rev];\n  }\n\n  // make sure logn is positive integer > 1\n  std::size_t temp = static_cast<std::size_t>(logn);\n  assert(static_cast<double>(temp) == logn);\n\n  for(std::size_t s = 1; s <= logn; ++s){\n    std::complex<double> w(1,0);\n\n    int m = 1 << s; // 2 power s\n    int m2 = m >> 1; // m2 = m/2 -1\n\n    std::complex<double> wm = exp(-PI*j/static_cast<double>(m2));\n\n    for(std::size_t j = 0; j < m2; ++j){\n      for(std::size_t k = j; k < n; k+=m){\n        std::complex<double> t = w*out[k+m2];\n        std::complex<double> u = out[k];\n        out[k] = u + t;\n        out[k+m2] = u - t;\n      }\n      w = w*wm;\n    }\n  }\n\n  return out;\n}\n\\end{verbatim}\n\nwhere the function \\texttt{bitReverse} reverses the bitwise representation of the index argument\n\n\\begin{verbatim}\nunsigned int bitReverse(unsigned int x, int log2n){\n  int n = 0;\n  for (int i = 0; i < log2n; i++){\n    n <<= 1;\n    n |= (x & 1);\n    x >>= 1;\n  }\n return n;\n}\n\\end{verbatim}\n\n\\section{DFT/FFT in Matlab}\n\nIn Matlab (and other languages/platforms) you can use the Fast Fourier Transform to compute the DFT. For example:\n\n\\begin{verbatim}\n>> T = 0.001;\n>> t = 0:T:100;\n>> x = cos(2*pi*t);\n>> X = fft(x);\n>> plot(abs(X))\n\\end{verbatim}\nTo give a plot consistent with the CTFT\n\\begin{verbatim}\n>> w = (-pi/0.001):(2*pi/100):(pi/0.001);\n>> stem(w, T*fftshift(abs(X)))\n\\end{verbatim}\nor\n\\begin{verbatim}\n>> stem(w, T*fftshift(angle(X)))\n\\end{verbatim}\n\n\n\\section{Summary of Fourier Transforms}\n\n\\begin{itemize}\n\\item Discrete-time Fourier Series: periodic DT signal $x[n] \\mapsto a_k$ periodic discrete frequencies\n\\item Discrete-time Fourier Transform: aperiodic DT signal of indefinite length $x[n] \\mapsto X(e^{j\\omega})$ periodic continuous frequencies\n\\item Continuous-time Fourier Series: periodic CT signal  $x(t) \\mapsto a_k$ discrete frequencies of indefinite length\n\\item Continuous-time Fourier Transform: aperiodic CT signal of indefinite length  $x(t) \\mapsto X(j\\omega)$ continuous frequencies \n\\end{itemize}\n\nAnd now we have the DFT\n\\begin{itemize}\n\\item Discrete Fourier Transform: aperiodic DT signal of finite length $x[n] \\mapsto X[k]$ periodic discrete frequencies\n\\end{itemize}\n\n\\section{Applications the DFT}\n\nOur discussion of the DFT raises some important questions:\n\n\\begin{itemize}\n\\item For what values of sampling interval $T$ does this hold?\n\\item What are the effects of time and frequency sampling on $x(t)$ and $X(j\\omega)$?\n\\item What if $x(t)$ or $X(j\\omega)$ is non-zero outside the interval?\n\\end{itemize}\nThese will be answered in the last two lectures. It also admits some important applications:\n\\begin{itemize}\n\\item Numerical computation of Fourier transform of physical signals\n\\item Simulation or approximation of stable CT systems\n\\item Implementation of CT systems using DT systems\n\\end{itemize}\n\nAs an example application, suppose you have a physical signal, say an audio signal from a microphone. How would you estimate it's Fourier Transform? Sample $x(t)$ at a frequency of $\\frac{2\\pi}{T}$ for $NT$ seconds.\n\\[\nx[n] = x(nT)\n\\]\n\\[\nX[k] = \\text{DFT}\\left\\{ x[n] \\right\\}\n\\]\n\\[\nX\\left(j\\frac{2\\pi}{NT} k\\right) = T X[k]\n\\]\nNote, in practice this requires multiplication by a windowing function to get good results unless there is silence on either side of the audio.\n\n\\begin{example}\n  Consider a CT signal $x(t) = \\cos(2\\pi t)\\left[u(t) - u(t-100)\\right]$ sampled at a frequency of $\\frac{2\\pi}{0.001}$ for $NT = 100$ seconds to obtain $x[n]$. Given the DFT of $x[n]$, $X[k]$, what values of $k$ correspond to $\\omega = \\pm 2\\pi$?\n  \n  \\[\n  \\omega = 2\\pi = \\frac{2\\pi}{NT} k \\implies k = 100\n  \\]\n  \n  \\[\n  \\omega = - 2\\pi = \\frac{2\\pi}{NT} k \\implies k = -100\n  \\]\n  However $k \\in (0, N-1)$ where $N= 100000$. Thus $k = -100 = N - 100 = 99900$. Note, the Matlab command \\texttt{fftshift} does this unwrapping for you.\n\\end{example}\n\nAs another application, suppose you have a CT frequency response, for example a CT filter. How could you simulate the response to a physical signal, such as an audio signal from a microphone? Again, sample $x(t)$ at a frequency of $\\frac{2\\pi}{T}$ for $NT$ seconds.\n\\[\nx[n] = x(nT)\n\\]\n\\[\nX[k] = \\text{DFT}\\left\\{ x[n] \\right\\}\n\\]\nUsing the convolution property of the CTFT\n\\[\nY[k] = H\\left(j\\frac{2\\pi}{NT} k\\right) X[k]\n\\]\n\\[\ny(nT) = \\frac{1}{T} \\text{IDFT}\\left\\{ Y[k] \\right\\}\n\\]\n\nAs a final application example we consider the case of filtering. DT implementations of CT systems have a number of benefits over CT implementations. The previous application hints at a method to implement a CT system using a DFT. We sample $x(t)$ at a frequency of $\\frac{2\\pi}{T}$ for $NT$ seconds into a buffer, called a \\emph{frame}.\n\\[\nx[n] = x(nT)\n\\]\n\\[\nX[k] = \\text{DFT}\\left\\{ x[n] \\right\\}\n\\]\n\\[\nY[k] = H\\left(e^{j\\frac{2\\pi}{NT} k}\\right) X[k]\n\\]\n\\[\ny(t) \\approx y(nT) = \\frac{1}{T} \\text{IDFT}\\left\\{ Y[k] \\right\\}\n\\]\nThis last step is called \\emph{reconstruction}. Note this can be done in real time using three frames, one being sampled, one being processing, and one being reconstructed.\n\nNote the DT filter in the previous application adds a two frame delay. This delay can be removed using an FIR or IIR filter implementation, as we saw in lecture 25. We can sample $x(t)$ at a frequency of $\\frac{2\\pi}{T}$ continuously into a \\emph{ring buffer}.\n\\[\nx[n] = x(nT)\n\\]\nCompute $y[n]$ using a delay difference equation, e.g. for second order\n\\[\ny[n] = a_1 y[n-2] + a_2 y[n-1] + a_3 x[n-2] + a_4 x[n-1] + a_5 x[n]\n\\]\nReconstruct the current output\n\\[\ny(t) \\approx y(nT) = y[n]\n\\]\n\n", "meta": {"hexsha": "70eaa4c69143a398d29b2a7b27eee984a4500b31", "size": 13347, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "22-dft.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": "22-dft.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": "22-dft.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": 39.3716814159, "max_line_length": 362, "alphanum_fraction": 0.6488349442, "num_tokens": 4830, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894632969136, "lm_q2_score": 0.8418256532040708, "lm_q1q2_score": 0.7532567244200442}}
{"text": "\n\\subsection{Rolle's theorem}\n\n\\subsubsection{Rolle’s theorem}\n\nTake a real function \\(f(x)\\) on closed interval \\([a,b]\\), differentiable on \\((a,b,)\\), and \\(f(a)=f(b)\\).\n\nRolle’s theorem states that:\n\n\\(\\exists c\\in(a,b) (f’(c)=0)\\)\n\nGeneralised Rolle’s theorem states that:\n\nGeneralised Rolle’s theorem implies Rolle’s theorem, so we only need to prove the generalised theorem.\n\n", "meta": {"hexsha": "8b8d3d08a7a0a788ab0102a2f6909cab2d288a2c", "size": 383, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/analysis/calculus/01-07-rolle.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/analysis/calculus/01-07-rolle.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/analysis/calculus/01-07-rolle.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 23.9375, "max_line_length": 108, "alphanum_fraction": 0.6945169713, "num_tokens": 112, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8947894604912848, "lm_q2_score": 0.8418256551882382, "lm_q1q2_score": 0.753256723833606}}
{"text": "\\subsection{Work}\n\nThe mathematical concept of work is an application of vectors in $\\R^n$.  The physical concept\nof work differs from the notion of work employed in\nordinary conversation. For example, suppose you were to slide an object of mass 150 kilograms\noff a table which is one meter high and carry the object to another table 50 meters away, keeping the object always exactly one meter above ground. The physical concept\nof work would indicate that the force exerted by your arms did no work\nduring this project. The reason for this definition is that even\nthough your arms exerted considerable force on the object, the direction of motion was at right angles to the force they\nexerted. The only part of a force which does work in the sense of physics is\nthe component of the force in the direction of motion.\n\nWork is defined to be the magnitude of the component of\nthis force times the distance over which it acts, when the\ncomponent of force points in the direction of motion. In the case where the force points in exactly the opposite direction of motion\nwork is given by $(-1) $\ntimes the magnitude of this component times the distance.\nThus the work done by a force on an object as\nthe object moves from one point to another is a measure of the extent to\nwhich the force contributes to the motion. This is illustrated in the\nfollowing picture in the case where the given force contributes to the\nmotion.\n\n\\begin{center}\n\\begin{tikzpicture}\n\\draw[blue, ->](0,0)--(4,1);\n\\draw[purple, ->](0,0)--(2,1.5);\n\\draw[red, ->](0,0)--(-0.5, 2);\n\\node[below] at (0,0){$P$};\n\\node[right] at (4,1){$Q$};\n\\node[left] at (-0.5,1.5){$\\vect{F}_{\\perp}$};\n\\node[left] at (1.75,1.5){$\\vect{F}$};\n\\node[below] at (3,0.75){$\\vect{F}_{||}$};\n\\node[right] at (0.75, 0.5){$\\theta$};\n\\end{tikzpicture}\n\\end{center}\n\nRecall that for any vector $\\vect{u}$ in $\\R^n$, we can write $\\vect{u}$ as a sum\nof two vectors, as in\n\\begin{equation*}\n\\vect{u} = \\vect{u}_{||} + \\vect{u}_{\\perp}\n\\end{equation*}\nFor any force $\\vect{F}$,\nwe can write this force as the sum of a vector in the direction of the motion and a vector\nperpendicular to the motion. In other words,\n\\begin{equation*}\n\\vect{F} = \\vect{F}_{||} + \\vect{F}_{\\bot}\n\\end{equation*}\n\nIn the above picture the force, $\\vect{F}$ is applied to an object which moves\non the straight line from $P$ to $Q$. There are two vectors shown, $\\vect{F}_{||}$ and $\\vect{F}_{\\bot }$ and the\npicture is intended to indicate that when you add these two vectors you get\n$\\vect{F}$. In other words, $\\vect{F} = \\vect{F}_{||} + \\vect{F}_{\\bot}$. Notice that\n $\\vect{F}_{||}$ acts in the direction of motion and\n$\\vect{F}_{\\bot }$ acts perpendicular to the direction of motion. Only\n$\\vect{F}_{||}$ contributes to the work done by $\\vect{F}$ on the object\nas it moves from $P$ to $Q$. $\\vect{F}_{||}$ is\ncalled the component of the force in\n\\index{component of a force} the direction of motion. From trigonometry, you\nsee the magnitude of $\\vect{F}_{||}$ should equal $\\norm{\\vect{F}\n} \\abs{\\cos \\theta}$. Thus, since $\\vect{F}_{||}$ points\nin the direction of the vector from $P$ to $Q$,\nthe total work done should equal\n\\begin{equation*}\n\\norm{\\vect{F}} \\norm{\n\\longvect{PQ}} \\cos \\theta =\\norm{\n\\vect{F}} \\norm{\\vect{q}-\\vect{p}} \\cos \\theta\n\\end{equation*}\n\nNow, suppose the included angle had been obtuse. Then the work done by the force\n$\\vect{F}$ on the object would have been negative because $\\vect{F}_{||}$\nwould point in $-1$ times the direction of the motion.  In this case, $\\cos \\theta $ would also be negative and\nso it is still\nthe case that the work done would be given by the above formula. Thus from\nthe geometric description of the dot product given above, the work equals\n\\begin{equation*}\n\\norm{\\vect{F}} \\norm{\\vect{q}-\\vect{p}} \\cos\n\\theta =\\vect{F}\\dotprod (\\vect{q}-\\vect{p})\n\\end{equation*}\nThis explains the following definition.\n\n\\begin{definition}{Work done on an object by a force}{work-done-by-force}\nLet $\\vect{F}$ be a force acting on an object which moves from the point\n$P$ to the point $Q$, which have position vectors given by $\\vect{p}$ and $\\vect{q}$ respectively.\n Then the \\textbf{work} done\n\\index{work} on the object by the given force equals $\\vect{F}\\dotprod (\n\\vect{q}-\\vect{p})$.\n\\end{definition}\n\nConsider the following example.\n\n\\begin{example}{Finding work}{finding-work}\nLet $\\vect{F}=\n\\begin{mymatrix}{rrr}\n2 & 7 & -3\n\\end{mymatrix}^T$ Newtons. Find the work\ndone by this force in moving from the point $(1,2,3) $ to the\npoint $(-9,-3,4) $ along the straight line segment joining these\npoints where distances are measured in meters.\n\\end{example}\n\n\\begin{solution}\nFirst, compute the vector $\\vect{q} - \\vect{p}$, given by\n\\begin{equation*}\n\\begin{mymatrix}{rrr}\n-9 & -3 & 4\n\\end{mymatrix}^T\n-\n\\begin{mymatrix}{rrr}\n1 & 2 & 3\n\\end{mymatrix}^T\n=\n\\begin{mymatrix}{rrr}\n-10 & -5 & 1\n\\end{mymatrix}^T\n\\end{equation*}\n\nAccording to Definition~\\ref{def:work-done-by-force} the work done is\n\\begin{align*}\n\\begin{mymatrix}{rrr}\n2 & 7 & 3\n\\end{mymatrix}^T\n \\dotprod\n\\begin{mymatrix}{rrr}\n-10 & -5 & 1\n\\end{mymatrix}^T\n& =-20+(-35) +(\n-3) \\\\\n& =-58\\text{ Newton meters}\n\\end{align*}\n\\end{solution}\n\nNote that if the force had been given in pounds and the distance had been\ngiven in feet, the units on the work would have been foot pounds. In\ngeneral, work has units equal to units of a force times units of a length.\nRecall that $1$ Newton meter is equal to $1$ Joule.  Also notice that the work done by the force can be negative as in the\nabove example.\n", "meta": {"hexsha": "5feae3306bbd871179cd8e4b211bc2fa62cb2e00", "size": 5521, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/RnVectorsApplicationsWork.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/RnVectorsApplicationsWork.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/RnVectorsApplicationsWork.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.0072463768, "max_line_length": 168, "alphanum_fraction": 0.7098351748, "num_tokens": 1702, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256393148982, "lm_q2_score": 0.8947894724152068, "lm_q1q2_score": 0.7532567196681719}}
{"text": "\\section{Numerical implementation of the Bogoliubov-de Gennes equations}\nIn section \\ref{sec:bogo}, we have shown the BdG equations, which are used to examine the stability of a state in BECs. To solve the Bogoliubov equations numerically requires searching for the solution to a generalised non-Hermitian eigenvalue problem. Thus, the system must be formally specified in matrix form. The derivative operators of $H_0$ are specified using second-order central differences, represented by\n\\begin{equation}\n    \\partial^2_i = \\frac{U_{i+1,j} + U_{i-1,j} - 2U_{i,j}}{h^2}\n\\end{equation}\nwhere $i$ is the respective dimension for the derivative, and $h$ is the step size. In matrix form, this becomes\n\\begin{equation}\n    \\mathbf{B} =\n    \\begin{bmatrix}\n            -2      &   1    &    0   &  \\cdots   &  \\cdots   &  \\cdots   & 0 \\\\\n            1       &   -2   &    1   &           &           &     &  \\vdots \\\\\n            0       &    1   &   -2   & \\ddots    &           &     &  \\vdots \\\\\n            \\vdots  &        & \\ddots & \\ddots    & {\\ddots}  &     &  \\vdots \\\\\n            \\vdots  &        &        & \\ddots    &    -2     &  1  &       0 \\\\\n            \\vdots  &        &        &           &     1     & -2  &       1 \\\\\n            0       & \\cdots & \\cdots & \\cdots    &     0     &  1  &      -2 \\\\\n        \\end{bmatrix}.\n\\end{equation}\nwhere the number of rows and columns equal the number of elements along the dimension to be differentiated. To construct a multidimensional version, we take a Kronecker sum of the matrix $\\mathbf{B}$ along each respective dimension of the system. This can be represented as\n\\begin{equation}\n    \\mathbf{B}_{i,j} = \\mathbf{B}_i \\oplus \\mathbf{B}_j = \\mathbf{B}_i \\otimes \\mathbf{I}_j + \\mathbf{I}_i \\otimes \\mathbf{B}_j\n\\end{equation}\nwere $i,j$ are the indices of the respective dimensions, and $\\mathbf{I}$ is the identity equal in size to dimensions $i,j$. With this operation, we can obtain a block diagonal matrix that represents the Laplacian operator as\n\n\\begin{equation}\n    \\nabla^2=\n    \\begin{bmatrix}\n        \\mathbf{B}    & \\mathbf{I} &      0      &  \\cdots      &      0       \\\\\n        \\mathbf{I}    & \\mathbf{B} &  \\ddots     &              &  \\vdots      \\\\\n        0             & \\ddots     &  \\ddots     &  \\ddots      &      0       \\\\\n        \\vdots        &            &  \\ddots     &  \\ddots      &  \\mathbf{I}  \\\\\n        0             & \\cdots     &      0      &  \\mathbf{I}  &  \\mathbf{B}\n    \\end{bmatrix}.\n\\end{equation}\n\nSimilarly, the angular momentum operator $L_z = i\\hbar(x\\partial_y + y\\partial_x)$ can be defined in terms of first derivative matrices. The non-derivative operators require a reshaping into lexicographical indexing ($N$-D to 1-D), and will sit along the diagonal. As these systems have many more 0's than elements, it makes sense to store them in a sparse matrix format. Given the proposed system is not Hermitian, a generalised eigenvalue solver is required. For the sake of simplicity, these systems can be solved in MATLAB, using \\textit{eigs}, which makes use of the Arnoldi (non-Hermitian) or Lanczos (Hermitian) algorithm for finding the specified number of eigenvectors and values.\n", "meta": {"hexsha": "a9ffb5d4fb2fa2e4357b8dbfe0528fdeb225f28b", "size": 3200, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MainText/ch3_numerics/num_bogo.tex", "max_stars_repo_name": "mlxd/PhDThesis", "max_stars_repo_head_hexsha": "1b5c6bfd1bfd073b47aa0b1b5abbc7bff5cd521e", "max_stars_repo_licenses": ["MIT"], "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/ch3_numerics/num_bogo.tex", "max_issues_repo_name": "mlxd/PhDThesis", "max_issues_repo_head_hexsha": "1b5c6bfd1bfd073b47aa0b1b5abbc7bff5cd521e", "max_issues_repo_licenses": ["MIT"], "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/ch3_numerics/num_bogo.tex", "max_forks_repo_name": "mlxd/PhDThesis", "max_forks_repo_head_hexsha": "1b5c6bfd1bfd073b47aa0b1b5abbc7bff5cd521e", "max_forks_repo_licenses": ["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.4864864865, "max_line_length": 689, "alphanum_fraction": 0.596875, "num_tokens": 961, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.916109606718245, "lm_q2_score": 0.8221891283434877, "lm_q1q2_score": 0.7532153590147692}}
{"text": "\\input{../qxfkindle}\r\n\\begin{document}\r\n\r\n\\chapter{Linear Algebra}\r\n\r\n\\textbf{Matrix Definitions:}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&A_{m\\times n}=\\begin{bmatrix}\r\n      a_{11} &~a_{12} &~\\cdots &~a_{1n}\\\\\r\n      a_{21} &~a_{22} &~\\cdots &~a_{2n}\\\\\r\n      \\vdots &~\\vdots &~       &~\\vdots\\\\\r\n      a_{m1} &~a_{m2} &~\\cdots &~a_{mn}\r\n      \\end{bmatrix}=[a_{ij}]_{m\\times n }\\\\\r\n   &\\text{Abbreviate as}~A.~\\text{For}~m=n,\\,\\text{write as}~A_n~\\tag{Matrix}\\\\\r\n   &\\text{For}~B=[b_{ij}]_{m\\times n},\\,a_{ij}=b_{ij},\\\\\r\n   &\\text{write as}~A=B\\tag{Matrix Equivalence}\\\\\r\n   &\\text{For}~\\forall a_{ij}=0,~\\text{write as}~O\\tag{Zero Matrix}\\\\\r\n   &\\text{For}~m=n,\\,\\forall(i\\neq j)\\,a_{ij}=0,\\,\\forall(i=j)\\,a_{ij}=1,\\\\\r\n   &\\text{write as}~E\\tag{Identity Matrix}\\\\\r\n   &\\text{Recollect here.}\\tag{Block Matrix}\\\\\r\n\\C~&A+B=[a_{ij} + b_{ij}]_{m\\times n}\\tag{Matrix Addition}\\\\\r\n   &C=AB=[a_{ij}]_{m\\times s}[b_{ij}]_{s\\times n}=[c_{ij}]_{m\\times n},\\\\\r\n   &c_{ij}=\\sum_{k=1}^{s}a_{ik}b_{kj}\\tag{Matrix Multiplication}\\\\\r\n   &kA=k[a_{ij}]_{m\\times n}=[ka_{ij}]_{m\\times n}\\tag{Matrix Scalar Multiplication}\\\\\r\n   &A=[a_{ij}]_{m\\times n},\\,A^T=[a_{ji}]_{n\\times m}\\tag{Transposition}\\\\\r\n\\C~&\\text{For}~A_n,~\\text{there is}~B~{that let}~AB=BA=E,\\\\\r\n   &\\text{write}~B~\\text{as}~A^{-1}\\tag{Inverse of Matrix}\\\\\r\n   &\\text{For}~A~\\text{that has}~A^{-1},\\\\\r\n   &\\text{call it invertible matrix}\\tag{Invertible Matrix}\\\\\r\n\\C~&\\text{Elementary Row Operations,}\\\\\r\n   &\\text{matrix row write as}~R_i,\\\\\r\n   &R_i\\leftrightarrow R_j\\tag{Row Switching}\\\\\r\n   &kR_i\\rightarrow R_i\\tag{Row Multiplication}\\\\\r\n   &kR_j + R_i\\rightarrow R_i\\tag{Row Addition}\\\\\r\n\\C~&\\text{Elementary Matrix}\\\\\r\n   &\\text{Apply row switching to}~E\\tag{\\(E_{ij}\\)}\\\\\r\n   &\\text{Apply row multiplication to}~E\\tag{\\(E_i(k)\\)}\\\\\r\n   &\\text{Apply row addition to}~E\\tag{\\(E_{ij}(k)\\)}\\\\\r\n\\C~&\\text{For}~AA^T=A^TA=E\\Leftrightarrow A^T=A^{-1}\\tag{Orthogonal Matrix}\\\\\r\n\\C~&|A_n|=\\begin{vmatrix}\r\n      a_{11} &~a_{12} &~\\cdots &~a_{1n}\\\\\r\n      a_{21} &~a_{22} &~\\cdots &~a_{2n}\\\\\r\n      \\vdots &~\\vdots &~       &~\\vdots\\\\\r\n      a_{n1} &~a_{n2} &~\\cdots &~a_{nn}\r\n      \\end{vmatrix}\\\\\r\n   &\\qquad=\\sum_{j_1 j_2 \\cdots j_n} (-1)^{\\tau{(j_1 j_2 \\cdots j_n)}}\r\n      a_{1j_1}a_{2j_2}\\cdots a_{nj_n}\\tag{Determinant}\\\\\r\n\\C~&\\text{Pick}~p~\\text{rows and}~q~\\text{columns from}~A,\\\\\r\n   &\\text{use the cross elements of these rows and columns}\\\\\r\n   &\\text{to construct a matrix.}\\tag{Submatrix}\\\\\r\n   &\\text{For}~p=q=k,\\\\\r\n   &\\text{write as}~\\ps{A}_k\\tag{Principal Submatrix}\\\\\r\n\\C~&\\text{For}~\\exists{r},\\,\\forall|\\ps{A}_r|\\neq 0,\\,\\forall|\\ps{A}_{r+1}|=0,\\\\\r\n   &\\text{write as}~r(A)\\tag{Rank of Matrix}\\\\\r\n\\C~&M_{ij}=\\begin{vmatrix}\r\n      a_{11}&~\\cdots&~a_{1,j-1}&~a_{1,j+1}&~\\cdots&~a_{1n}\\\\\r\n      \\vdots&~      &~\\vdots   &~\\vdots   &~      &~\\vdots\\\\\r\n      a_{i-1,1}&~\\cdots&~a_{i-1,j-1}&~a_{i-1,j+1}&~\\cdots&~a_{i-1,n}\\\\\r\n      a_{i+1,1}&~\\cdots&~a_{i+1,j-1}&~a_{i+1,j+1}&~\\cdots&~a_{i+1,n}\\\\\r\n      \\vdots&~      &~\\vdots   &~\\vdots   &~      &~\\vdots\\\\\r\n      a_{n1}&~\\cdots&~a_{n,j-1}&~a_{n,j+1}&~\\cdots&~a_{nn}\r\n      \\end{vmatrix}\\tag{Minor}\\\\\r\n\\C~&A_{ij}=(-1)^{i+j}M_{ij}\\tag{Cofactor}\\\\\r\n\\C~&A^* = \\begin{bmatrix}\r\n      A_{11} &~ A_{12} &~ \\cdots &~ A_{1n}\\\\\r\n      A_{21} &~ A_{22} &~ \\cdots &~ A_{2n}\\\\\r\n      \\vdots &~ \\vdots &~        &~ \\vdots\\\\\r\n      A_{n1} &~ A_{n2} &~ \\cdots &~ A_{nn}\\\\\r\n      \\end{bmatrix}\\tag{Cofactor Matrix}\\\\\r\n\\C~&\\text{For}~AA^*=A^*A=E\\Leftrightarrow A^*=A^{-1}\\tag{Unitary Matrix}\r\n\\end{align*}\r\n\r\n\\textbf{Vector:}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&\\text{For 1 column matrix}~A_{n\\times 1},\\\\\r\n   &\\text{call it column vector, or simply vector},\\\\\r\n   &\\text{write it as}~\\V{\\alpha}\\tag{n-dimensional Vector}\\\\\r\n   &\\text{For all zero element vector,}\\\\\r\n   &\\text{write as}~\\V{0}\\tag{Zero Vector}\\\\\r\n\\C~&\\text{Vector Operation}\\\\\r\n   &\\text{For the rest of this \\textbf{Vector} section,}\\\\\r\n   &\\V{\\alpha} = \\begin{bmatrix}\r\n      a_1\\\\a_2\\\\\\vdots\\\\a_n\r\n   \\end{bmatrix};\\;\\V{\\beta} = \\begin{bmatrix}\r\n      b_1\\\\b_2\\\\\\vdots\\\\b_n\r\n   \\end{bmatrix};\\;k_1,k_2,\\cdots,k_n \\in \\V{Z}\\\\\r\n   &\\V{\\alpha} + \\V{\\beta} = \\begin{bmatrix}\r\n      a_1 + b_1\\\\a_2 + b_2\\\\\\vdots\\\\a_n + b_n\r\n   \\end{bmatrix}\\tag{Addition}\\\\\r\n   &k\\V{\\alpha} = \\begin{bmatrix}\r\n      k a_1\\\\k a_2\\\\\\vdots\\\\k a_n\r\n   \\end{bmatrix}\\tag{Scalar Multiplication}\\\\\r\n   &\\V{\\alpha}^T\\V{\\beta} = \\begin{bmatrix}\r\n      a_1~a_2~\\cdots~a_n\r\n   \\end{bmatrix}\\begin{bmatrix}\r\n      b_1\\\\b_2\\\\\\vdots\\\\b_n\r\n   \\end{bmatrix}\\\\\r\n   &= a_1b_1 + a_2b_2 + \\cdots + a_nb_n\\tag{Dot/Inner Product}\\\\\r\n\\C~&\\V{\\beta} = k_1\\V{\\alpha}_1 + k_2\\V{\\alpha}_2 + \\cdots + k_n\\V{\\alpha}_n\\tag{Linear Combination \\& Linear Representation}\\\\\r\n\\C~&\\V{\\alpha}\r\n\\end{align*}\r\n\r\n\\textbf{Elementary Matrix properties:}\r\n\\begin{align*}\r\n\\Creset\r\n\\C~&E_{ij}^{-1}=E_{ij}\\\\\r\n\\C~&|E_{ij}|=-1\\Rightarrow |E_{ij}A|=-|A|\\N\\\\\r\n\\Creset\r\n\\C~&E_i^{-1}(k)=E_{i}(1/k)\\\\\r\n\\C~&E_i(k)~\\text{and}~E_i^{-1}(k)~\\text{are diagonal matrices}\\\\\r\n\\C~&|E_i(k)|=k\\Rightarrow |E_i(k)A|=k|A|\\N\\\\\r\n\\Creset\r\n\\C~&E_{ij}(k)~\\text{is kind of shear mapping}\\\\\r\n\\C~&E_{ij}^{-1}(k)=E_{ij}(-k)\\\\\r\n\\C~&E_{ij}(k)~\\text{and}~E_{ij}^{-1}(k)~\\text{are triangular matrices}\\\\\r\n\\C~&|E_{ij}(k)|=1\\Rightarrow |E_{ij}(k)A|=|A|\\N\r\n\\end{align*}\r\n\r\n\\textbf{Determinant properties:}\r\n\\begin{align*}\r\n\\Creset\r\n&\\C~\\text{row/column exchange update sign}\\\\\r\n&\\C~\\text{common divisor can be extracted}\\\\\r\n&\\C~\\text{row/column can be splitted}\\\\\r\n&\\C~\\text{multiply\\&plus equivalent}\\\\\r\n&\\C~|A^T|=|A|\\N\r\n\\end{align*}\r\n\r\n\\textbf{Special forms' properties:}\r\n\\Creset\r\n\\begin{align*}\r\n\\C~&\\text{Triangular form,}\\,|A| = \\prod_{i=1}^n{a_{ii}}\\\\\r\n   &\\text{Secondary coefficient:}\\:(-1)^{\\frac{n(n-1)}{2}}\\\\\r\n\\C~&\\text{Laplace form,}\\,\\begin{vmatrix}A_m&~O\\\\O&~B_n\\end{vmatrix} = |A|\\cdot|B|\\\\\r\n   &\\text{Secondary coefficient:}\\:(-1)^{mn}\\\\\r\n\\C~&\\text{Vandermonde form,}\\\\\r\n   &|A|=\\begin{vmatrix}\r\n   1     &~ 1     &~ \\cdots &~ 1\\\\\r\n   x_1   &~ x_2   &~ \\cdots &~ x_n\\\\\r\n   x_1^2 &~ x_2^2 &~ \\cdots &~ x_n^2\\\\\r\n   \\vdots&~ \\vdots&~        &~ \\vdots\\\\\r\n   x_1^{n-1} &~ x_2^{n-1} &~ \\cdots &~ x_n^{n-1}\r\n   \\end{vmatrix} = \\prod_{1\\leq j\\leq i\\leq n}{(x_i - x_j)}\\\\\r\n   &\\text{Another style to represent}~A:\\\\\r\n   &A_{i,j} = x_j^{i-1},\\,(1\\leq i,j \\leq n)\\N\r\n\\end{align*}\r\n\r\n\\textbf{Useful formulas:}\r\n\\begin{align*}\r\n\\Creset\r\n\\C~&AA^*=A^*A=|A|E\\\\\r\n\\C~&|A| = \\sum_{k=1}^{n} a_{ik} A_{ik},\\,\\text{true for}~i=1,2,\\cdots,n\\\\\r\n   &\\text{Above column form is true}\\\\\r\n\\C~&\\sum_{k=1}^{n} a_{ik} A_{jk} = 0,\\,(i\\neq j),~\\text{column form is true}\\\\\r\n\\C~&|kA_n| = k^n|A|\\\\\r\n\\C~&|A_nB_n| = |A|\\cdot|B|\\\\\r\n\\C~&|A^*_n| = |A|^{n-1}\\\\\r\n\\C~&|A^{-1}_n|=|A|^{-1}\\\\\r\n\\C~&|A_n|=\\prod_{i=1}^{n}\\lambda_i,\\,(\\lambda_i~\\text{is eigenvalue of}~A_n)\\\\\r\n\\C~&A\\sim B \\Rightarrow |A| = |B|\\N\r\n\\end{align*}\r\n\r\n\\end{document}", "meta": {"hexsha": "67731cb3bdbbf6c12ba658f2f8b28119a8ae2843", "size": 6764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/linear-algebra-properties.tex", "max_stars_repo_name": "qixiaofeng-gst/math-learning", "max_stars_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_stars_repo_licenses": ["MIT"], "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/linear-algebra-properties.tex", "max_issues_repo_name": "qixiaofeng-gst/math-learning", "max_issues_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_issues_repo_licenses": ["MIT"], "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/linear-algebra-properties.tex", "max_forks_repo_name": "qixiaofeng-gst/math-learning", "max_forks_repo_head_hexsha": "19386e162f5e93e7f4fe9aa220eff231619528c0", "max_forks_repo_licenses": ["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.9939393939, "max_line_length": 128, "alphanum_fraction": 0.5520402129, "num_tokens": 3094, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9496693702514736, "lm_q2_score": 0.7931059511841119, "lm_q1q2_score": 0.7531884292037114}}
{"text": "% !TEX root = main.tex\n\nExpectation is to random variables what probability is to events. \n\\bit\n\\it Probability quantifies the `size' of a random event.\n\\it Expectation quantifies the `size' of a random variable.\n\\eit\n\n\\subsubsection*{Elementary probability} \nLet $\\Omega$ be a finite sample space and let $p:\\Omega\\to[0,1]$ be a probability mass function on $\\Omega$. In elementary probability the \\emph{expectation} of a random variable $X:\\Omega\\to\\R$ is defined to be\n\\[\n\\expe(X) = \\sum_{\\omega\\in\\Omega} X(\\omega)\\prob(\\omega)\n\\]\nThis is a sum over the \\emph{domain} of $X$. Expectation can also be defined over the \\emph{range} of $X$.\n\n%\\subsubsection*{Frequentist model} \n%Let $\\Omega$ be the sample space of a random experiment which can be repeated many times under the same conditions, let $X$ be a simple random variable on $\\Omega$, and let $\\{x_1,x_2,\\ldots,x_n\\}$ be its range. \n%\n%Suppose we repeat the experiment $N$ times. Let $N(\\omega)$ be the number of times outcome $\\omega$ is observed. record the sequence of values $\\xi_1,\\xi_2,\\ldots,\\xi_N$ taken by $X$. Let $N_i$ be the number of times the event $\\{X=x_i\\}$ is observed. Under the \\emph{frequentist model}, the sample mean of the observations satisfies\n%\n%\\[\n%\\bar{X} \n%\t= \\frac{1}{N}\\sum_{j=1}^{N} \\xi_j \n%\t= \\frac{1}{N}\\sum_{i=1}^{n} x_i N_i \n%\t= \\sum_{i=1}^{n} x_i \\left(\\frac{N_i}{N}\\right)\n%\t\\longrightarrow \\sum_{i=1}^{n} x_i P(X=x_i) \\quad\\text{as $N\\to\\infty$}.\n%\\]\n%\n%Suppose we repeat the experiment $N$ times and record the sequence of values $\\xi_1,\\xi_2,\\ldots,\\xi_N$ taken by $X$. Let $N_i$ be the number of times the event $\\{X=x_i\\}$ is observed. Under the \\emph{frequentist model}, the sample mean of the observations satisfies\n%\\[\n%\\bar{X} \n%\t= \\frac{1}{N}\\sum_{j=1}^{N} \\xi_j \n%\t= \\frac{1}{N}\\sum_{i=1}^{n} x_i N_i \n%\t= \\sum_{i=1}^{n} x_i \\left(\\frac{N_i}{N}\\right)\n%\t\\longrightarrow \\sum_{i=1}^{n} x_i P(X=x_i) \\quad\\text{as $N\\to\\infty$}.\n%\\]\n%\n%This motivates the following definition of expectation for simple random variables.\n\n%-------------------------------------------------\n\\section{Simple variables}\\label{sec:expe-simple}\n\n\\begin{definition}[Expectation of simple random variables]\n%Let $X$ be a simple random variable and $\\{x_1,x_2,\\ldots,x_n\\}$ be its range. The expectation of $X$ is\nThe expectation of a simple random variable $X:\\Omega\\to\\R$ is\n\\[\n%\\expe(X) = \\sum_{i=1}^n x_i \\prob(X=x_i).\n\\expe(X) = \\sum_{i=1}^n x_i f(x_i).\n\\]\nwhere $f$ is the PMF of $X$ and $\\{x_1,x_2,\\ldots,x_n\\}$ is the range of $X$.\n\\end{definition}\n\nIn particular, the expectation of an indicator variable $I_A:\\Omega\\to\\R$ is\n\\[\n\\expe(I_A) = \\prob(A)\n\\]\nwhich shows the connection between an event and its indicator function.\n\n\n%-----------------------------\n%\\subsection{Properties}\n%Before deriving the properties of expectation for simple random variables we need the following.\n\n% definition: positivity & domination\n\\begin{definition}\nLet $X$ and $Y$ be random variables.\n\\ben\n\\it We say that $X$ is \\emph{non-negative} if $X(\\omega)\\geq 0$ for all $\\omega\\in\\Omega$. This is denoted by $X\\geq 0$.\n%\\it We say that $X$ is \\emph{non-negative} (denoted by $X\\geq 0$) if $X(\\omega)\\geq 0$ for all $\\omega\\in\\Omega$.\n\\it We say that $X$ \\emph{dominates} $Y$ if $X(\\omega)\\geq Y(\\omega)$ for all $\\omega\\in\\Omega$. This is denoted by $X\\geq Y$.\n\\een\n\\end{definition}\n\n% theorem: properties\n\\begin{theorem}[Properties of expectation for simple random variables]\nLet $X$ and $Y$ be simple random variables.\n\\ben\n\\it \\textbf{Linearity}.  For every $a,b\\in\\R$,\\ \\ $\\expe(aX+bY) = a\\expe(X) + b\\expe(Y)$.\n\\it \\textbf{Positivity}. If $X\\geq 0$ then $\\expe(X)\\geq 0$.\n\\it \\textbf{Monotonicity}. If $X\\geq Y$ then $\\expe(X)\\geq\\expe(Y)$.\n\\een\n\\end{theorem}\n\n\\begin{proof}\n\\ben\n\\it % << (ii)\n\\textbf{Linearity}. Let $\\{x_1,x_2,\\ldots,x_m\\}$ be the range of $X$ and $\\{y_1,y_2,\\ldots,y_n\\}$ be the range of $Y$. We define two partitions $\\{A_1,A_2,\\ldots,A_m\\}$ and $\\{B_1,B_2,\\ldots,B_n\\}$ of the underlying sample space $\\Omega$ by\n\\[\nA_i = \\{\\omega:X(\\omega)=x_i\\} \\quad\\text{and}\\quad B_j = \\{\\omega:Y(\\omega)=y_j\\}.\n\\]\nThese can be combined to produce another partition of $\\Omega$:\n\\[\n\\{A_i\\cap B_j: i=1,2,\\ldots,m;\\ j=1,2,\\ldots,n\\}.\n\\]\nThe composite variable $aX + bY$ takes the value $ax_i+by_j$ on the set $A_i\\cap B_j$. Because there are only finitely many such sets, it follows that $aX+bY$ is also a simple random variable, so its expectation is given by\n\\begin{align*}\n\\expe(aX+bY)\n\t& = \\sum_{i=1}^m\\sum_{j=1}^n (ax_i + by_j) \\prob(A_i\\cap B_j) \\\\\n\t& = a\\sum_{i=1}^m x_i \\sum_{j=1}^n \\prob(A_i\\cap B_j) + b\\sum_{j=1}^n y_j \\sum_{i=1}^m \\prob(A_i\\cap B_j).\n\\end{align*}\nBy the additivity of probability measures:\n\\bit\n\\it $\\{A_i\\cap B_j\\}_{j=1}^n$ is a partition of $A_i$, so $\\sum_{j=1}^n \\prob(A_i\\cap B_j) = \\prob(A_i)$.\n\\it $\\{A_i\\cap B_j\\}_{i=1}^m$ is a partition of $B_j$, so $\\sum_{i=1}^m \\prob(A_i\\cap B_j) = \\prob(B_j)$.\n\\eit\nHence,\n\\[\n\\expe(aX+bY)\n\t= a\\sum_{i=1}^n x_i\\prob(A_i) + b\\sum_{j=1}^m y_j\\prob(B_j)\n\t= a\\expe(X) + b\\expe(Y).\n\\]\n\n\\it % << (ii)\n\\textbf{Positivity}. If $X(\\omega)\\geq 0$ for all $\\omega$ we must have that each $x_i\\geq 0$. Thus $\\expe(X) = \\sum_{i=1}^n x_i \\prob(X=x_i)$ is a sum of non-negative terms, so $\\expe(X)\\geq 0$.\n\n\\it % << (iii)\n\\textbf{Monotonicity}. If $X\\geq Y$ then $X-Y\\geq 0$, so\n\\bit\n\\it by positivity, $\\expe(X-Y)\\geq 0$;\n\\it by linearity, $\\expe(X)-\\expe(Y)\\geq 0$, so $\\expe(X)\\geq\\expe(Y)$.\n\\eit\n\\een\n\\end{proof}\n\n% expectation of transformed variables\nFor a transformed variable, we need not compute its PMF to compute its expectation. The following result is sometimes called the \\emph{law of the unconscious statistician}.\n\n\\begin{theorem}[Expectation of transformed simple random variables]\\label{thm:expe-simple-transformed}\nIf $X$ be a simple random variable and $g:\\R\\to\\R$ is a transformation, the expected value of the transformed variable $g(X)$ is\n\\[\n\\expe\\big[g(X)\\big] = \\sum_{i=1}^{n} g(x_i) f(x_i).\n\\]\n\\end{theorem}\n\\begin{proof}\nLet $Y=g(X)$. Because $X$ is simple, $Y$ must also be simple. Let $\\{x_1,\\ldots,x_m\\}$ and $\\{y_1,\\ldots,y_n\\}$ be the range of $X$ and $Y$ respectively and let $C_j$ be the set containing those $x_i$ that are mapped to $y_j$:\n\\[\nC_j  = \\{x_i:g(x_i)=y_j\\} \\qquad\\text{for $i=1,2,\\ldots,m$.}\n\\]\nClearly, $\\prob(Y=y_j) = \\displaystyle\\sum_{x_i\\in C_j}\\prob(X=x_i)$, so\n\\begin{align*}\n\\expe(Y)\n\t& = \\sum_{j=1}^n y_j\\prob(Y=y_j) = \\sum_{j=1}^n y_j\\left(\\sum_{x_i\\in C_j} \\prob(X=x_i)\\right) \\\\\n\t& = \\sum_{j=1}^n \\sum_{x_i\\in C_j} y_j\\prob(X=x_i) \\\\\n\t& = \\sum_{j=1}^n \\sum_{x_i\\in C_j} g(x_i)\\prob(X=x_i) \\text{\\quad because $y_j=g(x_i)$ whenever $x_i\\in C_j$,}\\\\\n\t& = \\sum_{i=1}^m g(x_i)\\prob(X=x_i),\n\\end{align*}\nwhere the last equality follows because $\\{C_1,C_2,\\ldots,C_m\\}$ is a partition of $\\{x_1,\\ldots,x_n\\}$.\n\\end{proof}\n", "meta": {"hexsha": "adc4fa584e021ffb9983eeb90d00e9cbe2caad23", "size": 6824, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "L5/MA2500/04A_simple.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/04A_simple.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/04A_simple.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.7986577181, "max_line_length": 334, "alphanum_fraction": 0.6611957796, "num_tokens": 2552, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473879530491, "lm_q2_score": 0.8633916117313211, "lm_q1q2_score": 0.7531774172743911}}
{"text": "\\subsection{Ordinary vs. Partial}\r\n\\noindent\r\nAnother useful classification is by the type. There are two broad types of differential equation: ordinary and partial.\r\n\\begin{definition}\r\n\tAn ordinary differential equation (ODE) is a differential equation where only 1 independent variable involved in the derivatives.\r\n\\end{definition}\r\n\\begin{definition}\r\n\tA partial differential equation (PDE) is a differential equation where 2 or more independent variables are involved in the derivative.\r\n\\end{definition}\r\n\\noindent\r\nBelow is a table of types and equation numbers.\r\n\\begin{table}[H]\r\n\t\\centering\r\n\t\\begin{tabular}{c|c}\r\n\t\tType & Equation Number \\\\\r\n\t\t\\hline\r\n\t\tODE &  1, 2, 5, 6, 7, 8, 10 \\\\\r\n\t\tPDE & 3, 4, 9 \\\\\r\n\t\\end{tabular}\r\n\\end{table}\r\n\\noindent\r\nWe'll work mostly with ODEs.", "meta": {"hexsha": "dd3addadc1b495bad07278d102de9521b006c59f", "size": 787, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "diffEq/basics/classification/type.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/type.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/type.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.7727272727, "max_line_length": 136, "alphanum_fraction": 0.7357052097, "num_tokens": 218, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8633916099737807, "lm_q2_score": 0.8723473730188542, "lm_q1q2_score": 0.7531774028471468}}
{"text": "\\chapter{Expectation Maximization}\n\n\\section{EM-algorithm}\nLets first explore the data and let’s motivate the reason of why you would use a mixture model by using an example. Suppose we have the following density plot \\ref{5quakes_depth_dist} and \\ref{5faith_wait_dist}:\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5quakes_depth_dist.png}\n\\caption{Density plot for  variable \\texttt{quakes\\$depth}}\n\\label{5quakes_depth_dist}\n\\end{figure} \n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5faith_wait_dist.png}\n\\caption{Density plot for  variable \\texttt{faith\\$waiting}}\n\\label{5faith_wait_dist}\n\\end{figure}\n\nWe can immediately see that the resulting distribution appears to be bi-modal (i.e. there are two bumps in both the plots) suggesting that these in case of both the data, they might be coming from two different sources.\n\n\nPutting the the \\texttt{quakes} data into context suggests that the earthquakes in Fiji may be coming from two different sub-populations, depending upon the depth of the region. Similarly, putting the the \\texttt{faithful} data into context suggests that the eruption times may be coming from two different sub-populations. There could be several reasons for this. For instance, maybe at different times of the year the geyser eruptions are more frequent. We can probably take an intuitive guess as to how we could split this data.\n\nFor instance, we can observe in Figure \\ref{5quakes_depth_dist}, there likely is a sub-population with a mean depth of $\\sim 80$ with some variance around this mean (red vertical line in figure \\ref{5quakes_depth_dist}.) Another population with a mean depth of $\\sim 565$ with again some variance around this mean (blue vertical line in figure \\ref{5quakes_depth_dist}). Similarly, as we can observe in Figure \\ref{5faith_wait_dist}, there likely is a sub-population with a mean eruption of $\\sim 53$ with some variance around this mean (red vertical line in figure \\ref{5faith_wait_dist}.) Another population with a mean eruption of $\\sim 80$ with again some variance around this mean (blue vertical line in figure \\ref{5faith_wait_dist}).\n\n\\section{Gaussian Mixture Model}\nWhat we have done is a naive attempt at trying to group the data into sub-populations or clusters.\nBut surely there must be some objective and “automatic” way of defining these clusters? This is where mixture models come in by providing a “model-based approach” to clustering through the use of statistical distributions.\n\n\nA mixture model consist of a mixture of distributions. The first thing we need to do when performing mixture model clustering is to determine what type of statistical distribution we want to use for the components.\n\nIn our exercise we will use one of the most common statistical distributions used for mixture model clustering which is the Gaussian/Normal Distribution. When Gaussian distributions are used for mixture model clustering, they are referred to as \\emph{Gaussian Mixture Models (GMM).} As it turns out, our earlier intuition on where the means and variance of the sub-population in the plot above is a perfect example of how we could apply a GMM. Specifically, we could try to represent each sub-population as its own distribution (aka. mixture component). The entire set of data could then be represented as a mixture of 2 Gaussian distributions (aka. 2-component GMM)\n\n The procedures is based on the iterative \\emph{expectation maximization (EM) algorithm.} The following two points are important to note here. First, the EM algorithm is an iterative procedure, and the time required for it to reach convergence, if it converges at all depends strongly on the problem to which it is applied.  The second key point is that because it is an iterative procedure, the EM algorithm requires starting values for the parameters, and algorithm performance can depend strongly on these initial values.\n \n In our exercise, for both the data sets, we are going take initial values,\n $$\\theta^ 0 =(\\mu_{1}^{(0)},\\mu_{2}^{(0)},\\sigma_{1}^{(0)}, \\sigma_{2}^{(0)},p^{(0)}) =(m-sd/2, m + sd/2, sd, sd, 0.5)$$\nwhere $m$ is the mean of all observation and $sd$ the standard deviation.\n\nObserve the following plots \\ref{5quakes_depth_mix} and \\ref{5faith_wait_mix}. We have built a 2-component GMM. So how do we interpret figures \\ref{5quakes_depth_mix} and \\ref{5faith_wait_mix}? It’s actually quite simply, the red and blue lines simply indicate $2$ different fitted Gaussian distributions.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5quakes_depth_mix.png}\n\\caption{Density plot for  GMM with barplot for \\texttt{quakes\\$depth}}\n\\label{5quakes_depth_mix}\n\\end{figure} \n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5faith_wait_mix.png}\n\\caption{Density plot for  GMM with barplot for \\texttt{faith\\$waiting}}\n\\label{5faith_wait_mix}\n\\end{figure}\n\n\n\n\\section{Stopping criteria}\nIn the EM-algorithm we have used the (log-)likelihood function, which is a non-decreasing sequence. Also, is strictly increasing unless $\\theta^{(k)} = \\theta^{(k-1)}.$ We can observe this fact for the two data sets.\n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5quakes_depth_iter.png}\n\\caption{Values of the log-likelihood function per iteration for \\texttt{quakes\\$depth}}\n\\label{5quakes_depth_iter}\n\\end{figure} \n\n\n\\begin{figure}[h]\n\\centering\n\\includegraphics[scale=0.75, keepaspectratio]{ex5/5faith_wait_iter.png}\n\\caption{Values of the log-likelihood function per iteration for  \\texttt{faith\\$waiting}}\n\\label{5faith_wait_iter}\n\\end{figure}\n\nWe can this be used to formulate a stopping criterion for the EM-Algorithm. We can decide a threshold on $\\theta^{(k)} - \\theta^{(k-1)}$, if it is below the threshold then, we can stop the algorithm. For eg. we have take the threshold as $0.00001$. In the case of \\texttt{quakes\\$depth} algorithm stopped after $12$ iterations, where as in the case of \\texttt{faith\\$waiting} it stopped after $9$ iterations.  This just assures that the improvement in the maximization step is small and the algorithm can be stopped.", "meta": {"hexsha": "af4e284a95e5ee45fed83794ab26c77f7b5972ad", "size": 6181, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ex10/ex5/ex5.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": "ex10/ex5/ex5.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": "ex10/ex5/ex5.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": 77.2625, "max_line_length": 740, "alphanum_fraction": 0.7835301731, "num_tokens": 1539, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8633916134888614, "lm_q1q2_score": 0.7531774016154985}}
{"text": "\n\\section*{Part B, Problem 3: Kernel SVM (15 pts) (Adams)}\nAfter Homework 2, you must be very familiar with SVM.\nIn this question, we are considering its Kernel version:\n\\begin{align*}\n\\min_{w\\in \\mathbb{R}^d, b, \\xi_i\\in\\mathbb{R},i=1,2,...,n} &\\quad \\frac{1}{2}||w||_2^2 + C\\sum_{i=1}^n\\xi_i\\\\\n\\text{s.t.} &\\quad y^{(i)}(w^\\mathsf{T}\\phi(x^{(i)}) + b) \\geq 1-\\xi_i,~~  \\forall i = 1,\\ldots, n\\\\\n &\\quad \\xi_i \\geq 0, ~~ \\forall i = 1,\\ldots, n\n\\end{align*}\nwhere $x^{(i)}\\in\\mathbb{R}^p, i=1,2,...,n$ is the original training data coming along with the label $y^{(i)}\\in\\{-1,1\\}$, $C>0$ is a constant and $\\phi: \\mathbb{R}^p \\rightarrow \\mathbb{R}^d$ is a mapping function that maps the original data to a new space. Generally speaking, $d>p$ (In fact, $d$ can be $+\\infty$). Please answer the following questions. Note that the questions with complexity could be answered with big-O notation.\n\n\\begin{enumerate}\n\\item \\textbf{[6 points]} First write down the Lagrangian of the above problem and then derive the dual problem step by step.\n\\\\\\textbf{Answer:}\\\\\n\n$$J(\\vec{w},b,\\vec{\\xi},\\vec{\\alpha},\\vec{\\gamma}) = \\frac{1}{2}\\vec{w}^T\\vec{w}+C\\sum_{i=1}^{n}\\xi_i + \\sum_{i=1}^{n} \\alpha_i(1-\\xi_i-y^{(i)}(\\vec{w}^T\\phi(\\vec{x}^{(i)})+b)) - \\sum_{i=1}^{n}\\gamma_i\\xi_i~~~~(\\alpha_i\\geq0,~\\gamma_i\\geq0)$$\n\nBecause,\n\\begin{equation}\n\\nonumber\n\\begin{array}{rcl}\n\\left.\\frac{\\partial J}{\\partial \\vec{w}}\\right|_{\\vec{w}^*} & = & \\vec{w}^*-\\sum_{i=1}^{n}\\alpha_iy^{(i)}\\phi(\\vec{x}^{(i)}) = 0 \\\\\n\t\t\t\t\t\t\t\t\t& \\Rightarrow & \\vec{w}^* = \\sum_{i=1}^{n}\\alpha_iy^{(i)}\\phi(\\vec{x}^{(i)}) \\\\\n\n\\left.\\frac{\\partial J}{\\partial b}\\right|_{b^*} & = & -\\sum_{i=1}^{n}\\alpha_iy^{(i)} = 0 \\\\\n& \\Rightarrow & \\sum_{i=1}^{n}\\alpha_iy^{(i)} = 0 \\\\\t\n\n\\left.\\frac{\\partial J}{\\partial \\xi_i}\\right|_{\\xi_i^*} & = & C-\\alpha_i-\\gamma_i = 0 \\\\\n& \\Rightarrow & C = \\alpha_i+\\gamma_i \\\\\t\t\t\t\t\t\t\t\n\\end{array}\n\\end{equation}\nTherefore,\n$$J(\\vec{w}^*,b^*,\\vec{\\xi}^*,\\vec{\\alpha},\\vec{\\gamma}) = -\\frac{1}{2}\\sum_{i=1}^{n}\\sum_{j=1}^{n}\\alpha_i\\alpha_j y^{(i)} y^{(j)} \\phi^T(\\vec{x}^{(i)})\\phi(\\vec{x}^{(j)})+\\sum_{i=1}^{n}\\alpha_i$$\nTherefore, the dual form is:\n$$\\max_{\\vec{\\alpha},\\vec{\\gamma}} -\\frac{1}{2}\\sum_{i=1}^{n}\\sum_{j=1}^{n}\\alpha_i\\alpha_j y^{(i)} y^{(j)} \\phi^T(\\vec{x}^{(i)})\\phi(\\vec{x}^{(j)})+\\sum_{i=1}^{n}\\alpha_i$$\ns.t.\n$$\\sum_{i=1}^{n}\\alpha_i y^{(i)} = 0$$\n$$0\\leq\\alpha_i\\leq C$$\n\n\n\\item \\textbf{[9 points, (3 for each subproblem)]} Suppose we have obtained the solution of the dual problem, which is denoted as $\\alpha_i^*$ for $i=1,2,...,n$. Please find out the corresponding primal solution $w^*$ and $b^*$ in the course slides. Given a test data point $z\\in \\mathbb{R}^p$,\n\\\\\\textbf{Answer:}\\\\\n$$\\vec{w}^* = \\sum_{i=1}^{n}\\alpha_i^*y^{(i)}\\phi(\\vec{x}^{(i)})$$\n$$b^* = y^{(k)}-\\sum_{i=1}^{n}\\alpha_i^*y^{(i)}\\phi^T(\\vec{x}^{(i)})\\phi(\\vec{x}^{(k)})~~~~(for~any~k~where~C>\\alpha_k>0)$$\n\n\\begin{itemize}\n\\item What is the time complexity of making the classification decision if the mapping is given by $$\\phi(x) = (\\underbrace{x_p^2, x_{p-1}^2, ..., x_1^2}_{p}, \\underbrace{ \\sqrt{2}x_{p}x_{p-1},..., \\sqrt{2}x_{p}x_{1}}_{p-1}, \\underbrace{\\sqrt{2}x_{p-1}x_{p-2},...,\\sqrt{2}x_{p-1}x_{1}}_{p-2},...,\\sqrt{2}x_{2}x_{1}, \\sqrt{2c}x_{p},...,\\sqrt{2c}x_{1}, c)^\\mathsf{T}$$\nwith a constant $c>0$ and we need to compute it from scratch?\n\\\\\\textbf{Answer:}\\\\\n\\begin{itemize}\n\t\\item For $\\phi(\\vec{x}^{(i)})$: the number of multiply operations is $n\\frac{(p+2)(p+1)}{2}$\n\t\\item For $\\vec{w}^*$: the number of multiply operations is $n\\frac{(p+2)(p+1)}{2}$\n\t\\item For $b^*$: the number of multiply operations is $2n\\frac{(p+2)(p+1)}{2}$\n\t\\item For $\\phi(\\vec{z})$: the number of multiply operations is $\\frac{(p+2)(p+1)}{2}$\n\t\\item For $sgn(\\vec{w}^*\\cdot\\phi(\\vec{z})+b)$:\tthe number of multiply operations is $\\frac{(p+2)(p+1)}{2}$\n\t\\item Therefore, the time complexity is $O(np^2)$\n\\end{itemize}\n\n\\item  Let $K(u,v) = \\phi(u)^\\mathsf{T}\\phi(v)$ where $\\phi(\\cdot)$ has the same definition as above. Please give a compact form of $K(u,v)$. What is the time complexity of making the classification decision if we directly compute $K(\\cdot, \\cdot)$?\n\\\\\\textbf{Answer:}\\\\\n$$K(\\vec{u},\\vec{v}) = \\phi(\\vec{u})^T\\phi(\\vec{v}) = (\\vec{u}^T\\vec{v}+C)^2$$\n\\begin{itemize}\n\t\\item For $\\vec{w}^*\\cdot\\phi(\\vec{z})=\\sum_{i=1}^{n}\\alpha_iy_iK(\\vec{z},\\vec{x}_i)$: the number of multiply operations is $n(p+2)$\n\t\\item For $b^*=y_k-\\sum_{i=1}^{n}\\alpha_iy_iK(\\vec{x}_k,\\vec{z})$: the number of multiply operations is $n(p+2)$\n\t\\item For $sgn(\\vec{w}^*\\cdot\\phi(\\vec{z})+b)$:\tthe number of multiply operations is $0$\n\t\\item Therefore, the time complexity is $O(np)$\n\\end{itemize}\n\n\\item Now please go back to the dual formulation you derived previously. To avoid repetitive computation, one can precompute all the inner products $K(x^{(i)},x^{(j)})=\\phi(x^{(i)})^\\mathsf{T}\\phi(x^{(j)})$ before solving the dual problem. What is the space complexity of this approach and what might be a problem if $n$ is huge?\n\\\\\\textbf{Answer:}\\\\\nThe space complexity of $K(x^{(i)},x^{(j)})$ is $O(n^2)$, and this may lead memory overflow if $n$ is huge.\n\n\\end{itemize}\n\\end{enumerate}\n\n\\newpage\n", "meta": {"hexsha": "772b0a7e8657489463ff7b950af831f6f89954d5", "size": 5162, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Homeworks/HW3/problem3.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/problem3.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/problem3.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": 67.038961039, "max_line_length": 436, "alphanum_fraction": 0.6156528477, "num_tokens": 2104, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916099737806, "lm_q2_score": 0.872347368040789, "lm_q1q2_score": 0.753177398549127}}
{"text": "\n\n\\color{black}\n\\subsection*{Inference with Markov models}\n\nRecall the state transition diagram and transition probability matrix of a Markov chain ${\\lambda_1}$ which models the behavior of an NPC who is ``patrolling the map''\n\\begin{center}\n\\includegraphics[width=0.4\\textwidth]{dungeonMC1.pdf}\n\\qquad\n\\raisebox{2.5cm}{$\\mat{P}_{\\lambda_1} = \\begin{bmatrix} 0.3 & 0.2 & 0.5 \\\\ 0.5 & 0.3 & 0.2 \\\\ 0.2 & 0.5 & 0.3 \\end{bmatrix}$}\n\\end{center}\n\nThe probability of the event $E_1 = $ ``the NPC goes from room $C$ to room $B$ and then to room $A$'' amounts to\n\\begin{align*}\n\\prob{E_1} & = \\cprob{X_1 = B}{X_0 = C} \\cdot \\cprob{X_2 = A}{X_1 = B}\n\\intertext{and the corresponding log-likelihood amounts to}\n\\mathcal{L} \\bigl( E_1 \\bigr) & =  \\ln \\cprob{X_1 = B}{X_0 = C} + \\ln \\cprob{X_2 = A}{X_1 = B}\n\\end{align*}\n\nCompute both these values for the model $\\lambda_1$. Round your results to \\emph{two} decimal places.\n\\color{blue}\n%%%%%\n%%%%% enter your results after the '=' signs\n%%%%%\n\\begin{equation*}\n\\prob{E_1} = 0.04\n\\end{equation*}\n\\begin{equation*}\n\\mathcal{L} \\bigl( E_1 \\bigr) = -3.22\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\n\n\n\nAlso for model $\\lambda_1$, compute the probability and log-likelihood of the event $E_2 = $ ``the NPC goes from room $C$ to room $A$ and then to room $B$''\n\\color{blue}\n%%%%%\n%%%%% enter your results after the '=' signs\n%%%%%\n\\begin{equation*}\n\\prob{E_2} = 0.25\n\\end{equation*}\n\\begin{equation*}\n\\mathcal{L} \\bigl( E_2 \\bigr) = -1.39\n\\end{equation*}\n%%%%%\n%%%%%\n%%%%%\n\\color{black}\n\\newpage\n\n\n\n\n", "meta": {"hexsha": "08e7c4347b991296866977cba08d0f1a89b91ee5", "size": 1540, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SelfTest1SS2020/selfTestProblem1.tex", "max_stars_repo_name": "baraaHassan/Game-AI-Course", "max_stars_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "SelfTest1SS2020/selfTestProblem1.tex", "max_issues_repo_name": "baraaHassan/Game-AI-Course", "max_issues_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "SelfTest1SS2020/selfTestProblem1.tex", "max_forks_repo_name": "baraaHassan/Game-AI-Course", "max_forks_repo_head_hexsha": "dd4ed04b10b2231aac2f98b3b88274f7ab0cc339", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 26.1016949153, "max_line_length": 167, "alphanum_fraction": 0.6454545455, "num_tokens": 587, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391602943619, "lm_q2_score": 0.8723473746782093, "lm_q1q2_score": 0.753177398147077}}
{"text": "\\subsection{Projections}\\label{ssec:projections}\n\nIt is sometimes important to find the component of a vector in a\nparticular direction. Consider the following picture:\n\\begin{center}\n  \\begin{tikzpicture}[scale=0.8,rotate=13]\n    \\draw[draw=green!50!black] (3,0.5) -- (2.5,0.5) -- (2.5,0);\n    \\draw[->, thick, red](0,0) -- node[left]{$\\vect{v}$} (3,3.5);\n    \\draw[->, thick, blue](0,0) -- node[below, near end]{$\\vect{u}$} (8,0);\n    \\draw[dashed] (3,3.5) -- (3,0);\n    \\draw[fill](0,0) circle [radius=2.25pt] node[below=1ex]{$0$};\n    \\draw[fill](3,0) circle [radius=2.25pt] node[below=1ex]{$P$};\n    \\draw[fill](3,3.5) circle [radius=2.25pt] node[right=1ex]{$Q$};\n  \\end{tikzpicture}\n\\end{center}\nHere, $\\vect{u}$ is a non-zero vector specifying a {\\em direction},\nand $\\vect{v}$ is any vector. We have given the label $Q$ to the tip\nof $\\vect{v}$. The point $P$ lies at the place along $\\vect{u}$ that\nis closest to $Q$, or equivalently, such that $(0,P,Q)$ forms a right\ntriangle. The distance from $0$ to $P$ (measured positively in the\ndirection of $\\vect{u}$) is called the \\textbf{component}%\n\\index{component!of a vector}%\n\\index{vector!component} of $\\vect{v}$ in the direction of $\\vect{u}$,\nand is denoted $\\comp_{\\vect{u}}(\\vect{v})$. The vector\n$\\longvect{0P}$ is called the \\textbf{projection}%\n\\index{projection!vector to vector}%\n\\index{vector!projection of} of $\\vect{v}$ onto $\\vect{u}$, and is\ndenoted $\\proj_{\\vect{u}}(\\vect{v})$. We wish to find formulas for\nthese quantities.\n\nLet $\\theta$ be the included angle between $\\vect{v}$ and\n$\\vect{u}$. From trigonometry, considering the right triangle\n$(0,P,Q)$, we know that\n\\begin{equation*}\n  \\cos \\theta = \\frac{|0P|}{|0Q|} = \\frac{|0P|}{\\norm{\\vect{v}}},\n\\end{equation*}\nand therefore\n\\begin{equation}\\label{eqn:component-1}\n  |0P| = \\norm{\\vect{v}} \\cos \\theta.\n\\end{equation}\nOn the other hand, from Proposition~\\ref{prop:dot-product-angle},  we\nhave\n\\begin{equation*}\n  \\vect{u}\\dotprod \\vect{v}=\\norm{\\vect{u}} \\norm{\\vect{v}} \\cos \\theta,\n\\end{equation*}\nand therefore\n\\begin{equation}\\label{eqn:component-2}\n  \\norm{\\vect{v}} \\cos \\theta = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}}.\n\\end{equation}\nPutting equations {\\eqref{eqn:component-1}} and\n{\\eqref{eqn:component-2}} together, we obtain the desired formula for\nthe component of $\\vect{v}$ in the direction of $\\vect{u}$:\n\\begin{equation}\\label{eqn:component}\n  \\comp_{\\vect{u}}(\\vect{v})\n  = |0P|\n  = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}}.\n\\end{equation}\nNote that it is possible for this quantity to be negative; this\nhappens when the angle between $\\vect{v}$ and $\\vect{u}$ is obtuse.\nIn this case, $\\vect{v}$ will have a negative component along\n$\\vect{u}$.\n\nThe vector $\\proj_{\\vect{u}}(\\vect{v})=\\longvect{0P}$ can now be\ncomputed by re-scaling $\\vect{u}$ to the correct length. Specifically,\nwe first normalize $\\vect{u}$ by dividing it by its own length, and\nthen multiply by $|0P|$. In formulas:\n\\begin{equation}\n  \\proj_{\\vect{u}}(\\vect{v})\n  = \\longvect{0P}\n  = \\frac{|0P|}{\\norm{\\vect{u}}}\\vect{u}\n  = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}^2}\\,\\vect{u}\n  = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\,\\vect{u}.\n\\end{equation}\nThe following definition summarizes what we have just found.\n\n\\begin{definition}{Vector projection}{projection}\n  Let $\\vect{u}$ be a non-zero vector and $\\vect{v}$ any vector. Then\n  the \\textbf{component of $\\vect{v}$ in the direction of $\\vect{u}$}%\n  \\index{vector!component} is defined to be the scalar\n  \\begin{equation*}\n    \\comp_{\\vect{u}}(\\vect{v})\n    = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}}.\n  \\end{equation*}\n  The \\textbf{projection of $\\vect{v}$ onto $\\vect{u}$}%\n  \\index{vector!projection of} is defined to be the vector\n  \\begin{equation*}\n    \\proj_{\\vect{u}}(\\vect{v}) =\n      \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\, \\vect{u}\n    =\n    \\frac{\\vect{u}\\dotprod \\vect{v}}{\\norm{\\vect{u}}^2}\\,\\vect{u}.\n  \\end{equation*}\n  These two operations are also called the \\textbf{scalar projection}%\n  \\index{scalar projection} and \\textbf{vector projection}%\n  \\index{vector projection}, respectively.\n\\end{definition}\n\n\\begin{example}{Find the projection of one vector onto another}{vector-projection}\n  Find $\\proj_{\\vect{u}}(\\vect{v})$ if\n  \\begin{equation*}\n    \\vect{u}=\n    \\begin{mymatrix}{r}\n      2 \\\\\n      3 \\\\\n      -4\n    \\end{mymatrix}\n    \\quad\\mbox{and}\\quad\n    \\vect{v}=\n    \\begin{mymatrix}{r}\n      1 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We can use the formula provided in Definition~\\ref{def:projection}\n  to find $\\proj_{\\vect{u}}(\\vect{v})$.  First, compute\n  $\\vect{u} \\dotprod \\vect{v}$.  This is given by\n  \\begin{equation*}\n    \\begin{mymatrix}{r}\n      2 \\\\\n      3 \\\\\n      -4\n    \\end{mymatrix}\n    \\dotprod\n    \\begin{mymatrix}{r}\n      1 \\\\\n      -2 \\\\\n      1\n    \\end{mymatrix}\n    = (2)(1) + (3)(-2) + (-4)(1)\n    = -8.\n   \\end{equation*}\n   Similarly, $\\vect{u} \\dotprod \\vect{u}$ is given by\n   \\begin{equation*}\n     \\begin{mymatrix}{r}\n       2 \\\\\n       3 \\\\\n       -4\n     \\end{mymatrix}\n     \\dotprod\n     \\begin{mymatrix}{r}\n       2 \\\\\n       3 \\\\\n       -4\n     \\end{mymatrix}\n     = 2^2 + 3^2 + (-4)^2\n     = 29.\n  \\end{equation*}\n  Therefore, the projection is equal to\n  \\begin{equation*}\n    \\proj_{\\vect{u}}(\\vect{v})\n    =-\\frac{8}{29}\n        \\begin{mymatrix}{r}\n          2 \\\\\n          3 \\\\\n          -4\n        \\end{mymatrix}\n    =\n        \\begin{mymatrix}{r}\n          -16/29 \\\\\n          -24/29 \\\\\n          32/29\n        \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n\nAn important application of projections is that every vector\n$\\vect{v}$ can be uniquely written as a sum of two orthogonal vectors,\none of which is a scalar multiple of some given non-zero vector\n$\\vect{u}$, and the other of which is orthogonal to $\\vect{u}$.\n\n\\begin{theorem}{Decomposition into components}{decomposition-into-components}\n  Let $\\vect{u}$ be a non-zero vector, and let $\\vect{v}$ be any\n  vector. Then there exist unique vectors $\\vect{v}_{\\coll}$ and\n  $\\vect{v}_{\\bot}$ such that\n  \\begin{equation}\\label{projection}\n    \\vect{v}=\\vect{v}_{\\coll}+\\vect{v}_{\\bot}\n  \\end{equation}\n  where $\\vect{v}_{\\coll}$ is a scalar multiple of $\\vect{u}$,\n  and $\\vect{v}_{\\bot}$ is orthogonal to $\\vect{u}$.\n\\end{theorem}\n\n\\begin{proof}\n  \\begin{center}\n    \\begin{tikzpicture}[scale=0.7,rotate=-8]\n      \\draw[draw=green!50!black] (3,0.5) -- (2.5,0.5) -- (2.5,0);\n      \\draw[->, thick, blue](0,0) -- node[left]{$\\vect{v}$} (3,3.5);\n      \\draw[->, thick, blue](0,0) -- node[below]{$\\vect{u}$} (10,0);\n      \\draw[->, thick, red] (0,0) -- node[below]{$\\vect{v}_{\\coll}$} (3,0);\n      \\draw[->, thick, red] (3,0) -- node[right]{$\\vect{v}_{\\bot}$} (3,3.5);\n      \\draw[fill](0,0) circle [radius=2.25pt];\n      \\draw[fill](3,0) circle [radius=2.25pt];\n      \\draw[fill](3,3.5) circle [radius=2.25pt];\n    \\end{tikzpicture}\n  \\end{center}\n  To show that such a decomposition exists, let\n  \\begin{equation*}\n    \\vect{v}_{\\coll} = \\proj_{\\vect{u}}(\\vect{v}) = \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\, \\vect{u},\n  \\end{equation*}\n  and define $\\vect{v}_{\\bot} = \\vect{v}-\\vect{v}_{\\coll}$. By\n  definition, {\\eqref{projection}} is satisfied, and\n  $\\vect{v}_{\\coll}$ is a scalar multiple of $\\vect{u}$. We must show\n  that $\\vect{v}_{\\bot}$ is orthogonal to $\\vect{u}$. For this,\n  we verify that their dot product equals zero:\n  \\begin{eqnarray*}\n    \\vect{u}\\dotprod\\vect{v}_{\\bot}\n    &=& \\vect{u}\\dotprod(\\vect{v}-\\vect{v}_{\\coll}) \\\\\n    &=& \\vect{u}\\dotprod\\vect{v}-\\vect{u}\\dotprod\\vect{v}_{\\coll} \\\\\n    &=& \\vect{u}\\dotprod \\vect{v}-\\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod\\vect{u}}\\,\\vect{u}\\dotprod \\vect{u} \\\\\n    &=& \\vect{u}\\dotprod\\vect{v}-\\vect{u}\\dotprod \\vect{v} \\\\\n    &=& 0.\n  \\end{eqnarray*}\n  To show uniqueness, suppose that {\\eqref{projection}} holds and\n  $\\vect{v}_{\\coll}= k \\vect{u}$.  Taking the dot product of both\n  sides of {\\eqref{projection}} with $\\vect{u}$ and using\n  $\\vect{u}\\dotprod\\vect{v}_{\\bot}=0$, this yields\n  \\begin{equation*}\n    \\begin{array}{ll}\n      \\vect{u}\\dotprod \\vect{v} & = \\vect{u}\\dotprod( \\vect{v}_{\\coll}+\\vect{v}_{\\bot}) \\\\\n                                & =  \\vect{u} \\dotprod k\\vect{u} + \\vect{u}\\dotprod\\vect{v}_{\\bot} \\\\\n                                & = k \\norm{\\vect{u}}^2,\n    \\end{array}\n  \\end{equation*}\n  which implies\n  $k =\\vect{u}\\dotprod \\vect{v} / \\norm{\\vect{u}}^2$.  Thus there\n  can be no more than one such vector $\\vect{v}_{\\coll}$. Since\n  $\\vect{v}_{\\bot}$ must equal $\\vect{v}-\\vect{v}_{\\coll}$, it follows\n  that there can be no more than one choice for both\n  $\\vect{v}_{\\coll}$ and $\\vect{v}_{\\bot}$, proving their uniqueness.\n\\end{proof}\n\n\\begin{example}{Decomposition into components}{decomposition-into-components}\n  Decompose the vector $\\vect{v}$ into $\\vect{v}=\\vect{a}+\\vect{b}$\n  where $\\vect{a}$ is parallel to $\\vect{u}$ and $\\vect{b}$ is\n  orthogonal to $\\vect{u}$.\n  \\begin{equation*}\n    \\vect{v} = \\begin{mymatrix}{r} -5\\\\3\\\\-5 \\end{mymatrix},\\quad\n    \\vect{u} = \\begin{mymatrix}{r} 1\\\\2\\\\-2 \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  We can let $\\vect{a}=\\vect{v}_{\\coll}$ and $\\vect{b}=\\vect{v}_{\\bot}$\n  as in the proof of Theorem~\\ref{thm:decomposition-into-components}.\n  Then\n  \\begin{equation*}\n    \\vect{a} ~=~ \\vect{v}_{\\coll}\n    ~=~ \\proj_{\\vect{u}}(\\vect{v})\n    ~=~ \\frac{\\vect{u}\\dotprod \\vect{v}}{\\vect{u}\\dotprod \\vect{u}}\\, \\vect{u}\n    ~=~ \\frac{11}{9}\\, \\begin{mymatrix}{r} 1\\\\2\\\\-2 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} 11/9\\\\22/9\\\\-22/9 \\end{mymatrix}\n  \\end{equation*}\n  and\n  \\begin{equation*}\n    \\vect{b} ~=~ \\vect{v}_{\\bot}\n    ~=~ \\vect{v}-\\vect{v}_{\\coll}\n    ~=~ \\begin{mymatrix}{r} -5\\\\3\\\\-5 \\end{mymatrix}\n    - \\begin{mymatrix}{r} 11/9\\\\22/9\\\\-22/9 \\end{mymatrix}\n    ~=~ \\begin{mymatrix}{r} -56/9\\\\5/9 \\\\-23/9 \\end{mymatrix}.\n  \\end{equation*}\n\\end{solution}\n", "meta": {"hexsha": "1746341fa40d72e0129e7697b3999b7fb225ef6a", "size": 10014, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Vectors-DotProduct-Projections.tex", "max_stars_repo_name": "selinger/linear-algebra", "max_stars_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-03-21T06:37:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-30T16:23:10.000Z", "max_issues_repo_path": "baseText/content/Vectors-DotProduct-Projections.tex", "max_issues_repo_name": "selinger/linear-algebra", "max_issues_repo_head_hexsha": "37ad955fd37bdbc6a9e855c3794e92eaaa2d8c02", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "baseText/content/Vectors-DotProduct-Projections.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.9318181818, "max_line_length": 123, "alphanum_fraction": 0.6082484522, "num_tokens": 3728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.872347368040789, "lm_q2_score": 0.8633916064586998, "lm_q1q2_score": 0.7531773954827555}}
{"text": "\\documentclass[fleqn,leqno]{article}\n\n% Defining page margins\n\\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}\n\n\\usepackage{mathtools}\n\\usepackage{amsmath}\n\\usepackage{empheq}\n\\usepackage{amssymb}\n\n% argmin function\n\\DeclareMathOperator*{\\argmin}{arg\\,min}\n\n\\begin{document}\n\n\\setlength{\\parindent}{0pt}\n\n\\section*{Auxiliary notation: subset of $k$-minimal values}\n\nGiven the set $X \\subset \\mathbb{N}$, and some $k \\in \\mathbb{N}$, for the sake of convenience let's introduce an auxiliary notation for the subset of $k$-minimal values: $min_k(X) \\subseteq X$, such that $\\forall a \\in min_k(X), \\forall b \\in X \\setminus min_k(X)$ it follows, that $a < b$, and $|min_k(X)|=k$ (in case if $|X| < k$, then $min_k(X) = X$).\n\n\\section*{K smallest edit distances}\n\nLet $lev_{a,b}(i, j)$ be the set of $k$ smallest edit distances between the first $i$ characters of the string $a$ and the first $j$ characters of the string $b$. \\\\\n\nLet's introduce the following sets:\n\\begin{equation}\n\\begin{split}\n\t      & I_{a,b}(i, j) := \\{ d + 1 \\mid d \\in lev_{a,b}(i - 1, j) \\}  && \\text{The set of $k$ edit distances obtained through insertions} \\\\\n\t      & D_{a,b}(i, j) := \\{ d + 1 \\mid d \\in lev_{a,b}(i, j - 1) \\} && \\text{The set of $k$ edit distances obtained through deletions} \\\\\n\t      & S_{a,b}(i, j) := \\{ d + 1_{(a_i \\neq b_j)} \\mid d \\in lev_{a,b}(i - 1, j - 1) \\} && \\text{The set of $k$ edit distances obtained through substitutions} \\\\ \n\t      & E_{a,b}(i, j) := I_{a,b}(i, j) \\cup D_{a,b}(i, j) \\cup S_{a,b}(i, j) && \\text{The set of all $3k$ edit distances}  \\\\\n\\end{split}\n\\end{equation}\n\nWhere $1_{(a_i \\neq b_j)}$ is the indicator function equal to $0$ when $a_{i}=b_{j}$ and equal to $1$ otherwise. \\\\\n\nThen the set of $k$ smallest edit distances between the first $i$ characters of the string $a$ and the first $j$ characters of the string $b$ is defined as follows:\n\\begin{equation}\n\\begin{cases}\n\tlev_{a,b}(i, j) := \\{ max(i, j) \\}  \t\t& \\text{when $i = 0$ or $j = 0$} \\\\\n\tlev_{a,b}(i, j) := min_k(E_{a,b}(i, j)) \t& \\text{otherwise} \\\\\n\\end{cases}\n\\end{equation}\n\n\\section*{Proof of correctness} \n\n\\subsection*{Lemma 1}\nWhenever the arbitrary natural number $a$ doesn't belong to the set $min_k(X)$ and there exists some item of $min_k(X)$ which is greater than $a$, it means that $a \\not \\in X$. \\\\\n\nMore formally, let's prove the following statement for any $a \\in \\mathbb{N}$ and any $X \\subset \\mathbb{N}$:\n\\begin{equation}\n\t\\Big( (a \\not \\in min_k(X)) \\wedge (\\exists b \\in min_k(X), a < b) \\Big) \\Rightarrow \\Big( a \\not \\in X \\Big)\n\\end{equation}\n\n\\subsubsection*{Proof}\n\nAccording to the contrapositive  proof scheme, let's show that: \n\\begin{equation}\n\t\\neg \\Big( a \\not \\in X \\Big) \\Rightarrow \\neg \\Big( (a \\not \\in min_k(X)) \\wedge (\\exists b \\in min_k(X), a < b) \\Big)\n\\end{equation}\n\nWhich is equivalent to:\n\\begin{equation}\n\t\\Big( a \\in X \\Big) \\Rightarrow \\Big( (a \\in min_k(X)) \\lor (\\forall b \\in min_k(X), a \\geq b) \\Big)\n\\end{equation}\n\nThe latter statement is equivalent to:\n\\begin{equation}\n\t\\Big( a \\in X \\Big) \\Rightarrow \\Big( (a \\in min_k(X)) \\lor (a \\in X \\setminus min_k(X)) \\Big)\n\\end{equation}\n\nWhich is a tautology. $\\blacksquare$\n\n\\subsection*{Proof by the smallest counterexample}\n\n\\textit{Induction Basis:} \\\\ \\\\\nIn case if $i = 0$ or $j = 0$ there is possible only one edit distance, hence the set $lev_{a,b}(i, j)$ contains only one item, namely $max(i, j)$. As far as there is only one possible edit distance - it means, that $lev_{a,b}(i, j) = max_k(\\{ max(i, j) \\}) = \\{ max(i, j) \\}$, which complies to the definition of the subset of $k$-minimal values. \\\\\n\n\\textit{Induction Hypothesis:}\n\\begin{itemize}\n\t\\item The set $lev_{a,b}(i - 1, j)$ contains the $k$ minimal edit distances between the first $i - 1$ characters of the string $a$ and the first $j$ characters of the string $b$. \\\\\n\t\tHence, for every edit distance $y$ between the first $i - 1$ characters of the string $a$ and the first $j$ characters of the string $b$, such that $y \\not \\in lev_{a,b}(i - 1, j)$ it follows, that $\\forall x \\in lev_{a,b}(i - 1, j), y > x$.\n\t\\item The set $lev_{a,b}(i, j - 1)$ contains the $k$ minimal edit distances between the first $i$ characters of the string $a$ and the first $j - 1$ characters of the string $b$. \\\\\n\t\tHence, for every edit distance $y$ between the first $i$ characters of the string $a$ and the first $j - 1$ characters of the string $b$, such that $y \\not \\in lev_{a,b}(i, j - 1)$ it follows, that $\\forall x \\in lev_{a,b}(i, j - 1), y > x$.\n\t\\item The set $lev_{a,b}(i - 1, j - 1)$ contains the $k$ minimal edit distances between the first $i - 1$ characters of the string $a$ and the first $j - 1$ characters of the string $b$. \\\\\n\t\tHence, for every edit distance $y$ between the first $i - 1$ characters of the string $a$ and the first $j - 1$ characters of the string $b$, such that $y \\not \\in lev_{a,b}(i - 1, j - 1)$ it follows, that $\\forall x \\in lev_{a,b}(i - 1, j - 1), y > x$.\n\\end{itemize}\n\n\\textit{Inductive Step:} \\\\ \\\\\nWe want to show, that the \\textit{Induction Hypothesis} implies, that the set $lev_{a,b}(i, j)$ contains the $k$ smallest edit distances between the first $i$ characters of the string $a$ and the first $j$ characters of the string. \\\\ \\\\\n\\textbf{For the sake of contradictions} let's assume, that the set $lev_{a,b}(i, j)$ doesn't contain the $k$ smallest edit distances. Thus, there there exists some edit distance $y \\not \\in lev_{a,b}(i, j)$ between the first $i$ characters of the string $a$ and the first $j$ characters of the string $b$, such that $\\exists x \\in lev_{a,b}(i, j)$ for which $y < x$:\n\\begin{equation}\n\\begin{split}\n\t\\Big( y \\not \\in lev_{a,b}(i, j) \\Big) \\land \\Big( \\exists x \\in lev_{a,b}(i, j), y < x \\Big)\n\\end{split}\n\\end{equation}\n\nLet's rewrite the expression in a following way:\n\\begin{equation}\n\\begin{split}\n\t\t\t\t\t& \\Big( y \\not \\in lev_{a,b}(i, j) \\Big) \\land \\Big( \\exists x \\in lev_{a,b}(i, j), y < x \\Big) \\\\\n\t\\Leftrightarrow \\ \t& \\Big( y \\not \\in min_k(E_{a,b}(i, j)) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{By definition of $lev_{a,b}(i, j)$} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( y \\not \\in min_k(E_{a,b}(i, j)) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{Idempotence} \\\\\n\t\\Rightarrow \\ \t\t& \\Big( y \\not \\in E_{a,b}(i, j) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{According to the Lemma 1} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( y \\not \\in I_{a,b}(i, j) \\cup D_{a,b}(i, j) \\cup S_{a,b}(i, j) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{By definition of $E_{a,b}(i, j)$} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( y \\not \\in I_{a,b}(i, j) \\Big) \\land \\Big( y \\not \\in D_{a,b}(i, j) \\Big) \\land \\Big( y \\not \\in S_{a,b}(i, j) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{De-Morgan's law} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( (y - 1) \\not \\in lev_{a,b}(i - 1, j) \\Big) \\land \\Big( (y - 1) \\not \\in lev_{a,b}(i, j - 1) \\Big) \\land && \\text{By definition of $I_{a,b}(i, j),$}\\\\\n\t\t\\land\t\t\t& \\Big( (y - 1_{(a_i \\neq b_j)}) \\not \\in lev_{a,b}(i - 1, j - 1) \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{$D_{a,b}(i, j)$ and $S_{a,b}(i, j)$} \\\\\n\t\\Rightarrow \\ \t\t& \\Big( \\forall m \\in lev_{a,b}(i - 1, j), y - 1 > m \\Big) \\land \\Big( \\forall n \\in lev_{a,b}(i, j - 1), y - 1 > n \\Big) \\land && \\text{By Induction Hypothesis}\\\\\n\t\t\\land\t\t\t& \\Big( \\forall u \\in lev_{a,b}(i - 1, j - 1), y - 1_{(a_i \\neq b_j)} > u \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( \\forall m \\in I_{a,b}(i, j), y > m \\Big) \\land \\Big( \\forall n \\in D_{a,b}(i, j), y > n \\Big) \\land && \\text{By definition of $I_{a,b}(i, j),$}\\\\\n\t\t\\land\t\t\t& \\Big( \\forall u \\in S_{a,b}(i, j), y > u \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{$D_{a,b}(i, j)$ and $S_{a,b}(i, j)$} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( \\forall m \\in I_{a,b}(i, j) \\cup D_{a,b}(i, j) \\cup S_{a,b}(i, j), y > m \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{Reordering} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( \\forall m \\in E_{a,b}(i, j), y > m \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{By definition of $E_{a,b}(i, j)$} \\\\\n\t\\Rightarrow \\ \t\t& \\Big( \\forall m \\in min_k(E_{a,b}(i, j)), y > m \\Big) \\land \\Big( \\exists x \\in min_k(E_{a,b}(i, j)), y < x \\Big) && \\text{Because $min_k(X) \\subseteq X$} \\\\\n\t\\Leftrightarrow \\ \t& \\Big( \\forall m \\in lev_{a,b}(i, j), y > m \\Big) \\land \\Big( \\exists x \\in lev_{a,b}(i, j), y < x \\Big) && \\text{By definition of $lev_{a,b}(i, j)$} \\\\\n\t\\Rightarrow \\ \t\t& Contradiction. \\\\\n\\end{split}\n\\end{equation}\n\nHence, our assumption was wrong. Consequently, the set $lev_{a,b}(i, j)$ contains the $k$-minimal edit distances. $\\blacksquare$\n\n\n\\end{document}", "meta": {"hexsha": "fae6c31051fcfd02bd3572bf6663c94ee7e32c66", "size": 8923, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "levenshtein_top_k.tex", "max_stars_repo_name": "lagodiuk/levenshtein-top-k", "max_stars_repo_head_hexsha": "f30435d9a665d4734227a9a63503f2e8d3d5ab6b", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2021-04-21T07:38:13.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-15T05:36:48.000Z", "max_issues_repo_path": "levenshtein_top_k.tex", "max_issues_repo_name": "lagodiuk/levenshtein-top-k", "max_issues_repo_head_hexsha": "f30435d9a665d4734227a9a63503f2e8d3d5ab6b", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "levenshtein_top_k.tex", "max_forks_repo_name": "lagodiuk/levenshtein-top-k", "max_forks_repo_head_hexsha": "f30435d9a665d4734227a9a63503f2e8d3d5ab6b", "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.384, "max_line_length": 366, "alphanum_fraction": 0.6140311554, "num_tokens": 3404, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213745668094, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7531220073299498}}
{"text": "\\subsection{Subtraction of natural numbers}\n\nWe have inverse functions for addition. This is subtraction.\n\nFor function \\(\\oplus\\), its inverse is \\(\\oplus' \\), as defined below:\n\n$a\\oplus b=c$\n\n$b=c\\oplus 'a$\n\n$f(a,b)=c\\rightarrow f^{-1}(c,b)=a$\n\n\\subsubsection{Subtraction}\n\n$a+b=c\\rightarrow b=c-a$\n\nThere is no natural number \\(b\\) that satisfies:\n\n$3+b=2$\n\nWhile addition and multiplication are defined across all natural numbers, subtraction is not.\n\\subsubsection{Properties of subtraction}\n\nSubtraction is not commutative:\n\n$x-y\\ne y-x$\n\nSubtraction is not associative:\n\n$x-(y-z)\\ne (x-y)-z$\n\n", "meta": {"hexsha": "f272dfd01c6023a2a11d78a8dbe56c6b57cbd596", "size": 601, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/logic/arithmetic/01-01-subtraction.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/arithmetic/01-01-subtraction.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/arithmetic/01-01-subtraction.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.78125, "max_line_length": 93, "alphanum_fraction": 0.7171381032, "num_tokens": 162, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9184802507195636, "lm_q2_score": 0.8198933359135361, "lm_q1q2_score": 0.753055836733164}}
{"text": "\\section{Markov Chains}\n\\label{sec:markov-chains}\n\n\\begin{definition}[Markovian Property]\n\\label{def:markovian-property}\n\tThe Markovian property states that the conditional distribution of any future state $X_{n+1}$, given past states $X_{0},X_{1},...,X_{n-1}$, and given the present state $X_{n}$, is independent of past states and depends only on the present state.\n\\end{definition}\n\n\\begin{definition}[Discrete-Time Markov Chain]\n\\label{def:discrete-time-markov-chain}\n\n\tA Discrete-Time Markov Chain (DTMC) is a stochastic process $\\{X_{n \\in \\natural}\\}$, where $X_{n}$ denotes the state at time $n$ and such that\n\t\n\t\\begin{equation}\n\t\\label{eqn:discrete-time-markov-chain}\n\t\t\\begin{split}\t\n\t\t\t\\probability{X_{n+1} = j | X_{n} = i,X_{n-1} = i_{n}-1,...,X_{0} = i_{0}}\n\t\t\t& = \\probability{X_{n+1} = j | X_{n} = i} \\\\\n\t\t\t& = P_{i,j} \\\\\n\t\t\t& \\forall n \\geq 0, \\forall i,j, \\forall i_{0},...,i_{n-1}\n\t\t\\end{split}\t\t\n\t\\end{equation}\n\t\n\twhere $P_{i,j}$ is independent of time and past history.\n\\end{definition}\n\n\\begin{definition}[Continuous-Time Markov Chain]\n\\label{def:continuous-time-markov-chain}\n\t\n\tA Continuous-Time Markov Chain (CTMC) is a stochastic process $\\{X(t),t \\in \\Re^{+}\\}$, where $X_{n}$ denotes the state at time $n$ and such that\n\t\n\t\\begin{equation}\n\t\\label{eqn:continuous-time-markov-chain}\n\t\t\\begin{split}\t\n\t\t\t\\probability{X(s+t) = j | X(s) = i,X(u) = x(u)} \n\t\t\t& = \\probability{X(s+t) = j | X(s) = i} \\\\\n\t\t\t& = \\probability{X(t) = j | X(0) = i} \\\\\n\t\t\t& = P_{i,j}(t) \\\\\n\t\t\t& \\forall s,t \\geq 0, \\forall i,j,x(u) \n\t\t\\end{split}\t\t\n\t\\end{equation}\n\t\n\twhere $P_{i,j}$ is independent of time and past history.\n\\end{definition}\n\nAlternatively\n\n\\begin{definition}[Continuous-Time Markov Chain 2]\n\t\\label{def:continuous-time-markov-chain-2}\n\t\n\tA Continuous-Time Markov Chain (CTMC) is a stochastic process with the property that every time it enters state $i$, the following hold:\n\t\n\t\\begin{enumerate}\n\t\t\\item The amount of time the process spends in state $i$ is a r.v. $X \\sim Exp(\\lambda)$.\n\t\t\n\t\t\\item The probability $p_{i,j}$ to transit from state $i$ to state $j$ is independent of the time spent in state $i$.\n\t\\end{enumerate}\n\\end{definition}\n\n\\begin{definition}[Transition Probability Matrix]\n\\label{def:transition-probability-matrix}\n\t\n\tThe transition probability matrix associated with any Markov chain is a matrix, whose $(i,j)$-th entry $P_{i,j}$ is the probability of moving in the next transition from state $i$ to state $j$.\n\\end{definition}\n\nBy definition, we have that \n\n\\begin{equation*}\n\\sum_{j} P_{i,j} = 1 \\quad \\forall i\n\\end{equation*}\n\nA queue network that exposes the Markovian property can be modeled by a Markov chain.\n\nNon Markovian workloads can be approximated by mixtures of Exponential distributions, hence lending themselves to Markov chain analysis.\n\n\\begin{theorem}[Balance equations for CTMC]\n\\label{thm:balance-equations-continuous-time-markov-chains}\n\n\tGiven an irreducible CTMC, we have that\n\t\n\t\\begin{equation}\n\t\t\\pi_{j} \\sum_{i} q_{j,i} = \\sum_{i} \\pi_{i} q_{i,j} \n\t\\end{equation}\n\t\n\tand\n\t\n\t\\begin{equation}\n\t\t\\sum_{i} \\pi_{i} = 1\n\t\\end{equation}\n\t\n\twhere $\\pi_{i}$ is the limiting probability for the CTMC to be in state $i$.\n\\end{theorem}\n\n\\begin{definition}[Time Reversibility]\n\\label{def:time-reversibility}\n\n\tA CTMC is time-reversible if, for all states $i$ and $j$, the rate of transitions from state $i$ to state $j$ equals the rate of transitions from state $j$ to state $i$. That is\n\t\n\t\\begin{equation}\n\t\t\\pi_{i} q_{i,j} = \\pi_{j} q_{j,i} \\quad \\forall i,j\n\t\\end{equation}\n\\end{definition}\n\nAll birth-death processes are time-reversible.\nFor a time-reversible process, the time-reversibility equations are always solvable.\n\n\\begin{theorem}\n\\label{thm:statistical-description-time-reversible}\n\n\tIf a CTMC is time-reversible, then its reverse chain is statistically identical to the forwards chain, that is\n\t\t\n\t\\begin{equation}\n\t\\label{eqn:statistical-description-time-reversible}\n\tP_{i,j} = P_{i,j}^{*}\n\t\\end{equation}\n\\end{theorem}\n\n\\Cref{thm:statistical-description-time-reversible} means that the reverse chain can be described by the same CTMC as the forwards chain\n\n\n\n\n\\subsection{PASTA}\n\\label{sec:pasta}\n\nIn many stochastic models, particularly in queueing theory, Poisson arrivals both observe a stochastic process and interact with it. In some cases it has been shown that the fraction of arrivals that see the process in some state is equal to the fraction of time the process is in that state.\n\nThis property il called PASTA, standing for \\textit{Poisson Arrivals See Time Averages}.\n\nThe PASTA property is the adaptation of the Arrival Theorem for Poisson processes \\cite{asmussen2003queueing,el2012sample} \\footnote{also referred to as the Random Observer Property (ROP) \\cite{el2012sample}.}. \nThe property states that the probability of the state as seen by an outside random observer is the same as the probability of the state seen by an arriving customer \\cite{wolff1982poisson}. \nThe property also holds for the case of a doubly stochastic Poisson process where the rate parameter is allowed to vary depending on the state \\cite{van1988conditional}.\n\n\\begin{theorem}[PASTA Property]\n\\label{thm:pasta}\n\n\tFor any system with Poisson arrival process, we have that\n\n\t\\begin{equation}\n\t\ta_{n} = d_{n} = p_{n}\n\t\\end{equation}\t\n\t\n\twhere \n\t$a_{n}$ is the probability that an arrival sees $n$ jobs in the system,\n\t$d_{n}$ is the probability that a departure leaves $n$ jobs in the system, and\n\t$p_{n}$ is the probability that there are $n$ jobs in the system.\n\t\n\\end{theorem}\n\nPASTA is useful in system simulation. When simulating a Poisson arrival process, it suffices to average over what arrivals see at the moment they enter the system to know averages of the whole system. It is not the case when arrivals do not follow a Poisson process.", "meta": {"hexsha": "45e9dceaa44238d2fbf9b9f6a44f173aaf021300", "size": 5816, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "performance-modeling/sec/markov-chains.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/markov-chains.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/markov-chains.tex", "max_forks_repo_name": "gmarciani/research", "max_forks_repo_head_hexsha": "7cc526fe7cd9916ceaf8285c4e4bc4dce4028537", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2018-02-17T13:30:49.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-17T13:30:49.000Z", "avg_line_length": 38.7733333333, "max_line_length": 292, "alphanum_fraction": 0.7255845942, "num_tokens": 1723, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382200964034, "lm_q2_score": 0.87407724336544, "lm_q1q2_score": 0.753050952475832}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\begmath 10.1 One-Dimensional Real Fourier Transform\n\n\\silentfootnote{$^\\copyright$1997 Calif. Inst. of Technology, \\thisyear \\ Math \\`a la Carte, Inc.}\n\n\\subsection{Purpose}\n\nThis subroutine computes discrete Fourier transforms for real data using the\nfast Fourier transform. The relations between the real values $x$ and the\ncomplex Fourier coefficients $\\xi $ are as follows:\n\nFor Fourier analysis:\n\\begin{equation}\\label{fa}\n\\xi _k=\\frac 1N\\sum_{j=0}^{N-1}x_jW^{-jk},\\quad k=0,1...,N-1,\n\\end{equation}\nFor Fourier synthesis:\n\\begin{equation}\n\\label{fs}x_j=\\sum_{k=0}^{N-1}\\xi _kW^{jk},\\quad j=0,1,...,N-1,\n\\end{equation}\nwhere $N=2^{\\text{M}}$ and $W=e^{2\\pi i/N}=\\cos (2\\pi /N)+i\\ \\sin (2\\pi /N)$, and $%\ni^2=-1$. Note that the sign on the exponent of $W$ is negative for analysis\nand positive for synthesis.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype, Single Precision}\n\n\\begin{description}\n\\item[\\bf INTEGER]  \\ {\\bf M, MS}\n\\item[\\bf REAL]  \\ {\\bf A}($\\geq 2^{\\text{M}}$)\\bf\n {, S}($\\geq 2^{\\text{M}-2}-1$)\n\\item[\\bf CHARACTER]  \\ {\\bf MODE}\n\\end{description}\nOn the initial call set MS = 0 to indicate the array S() does not yet\ncontain a sine table. Assign values to A(), MODE, and M.%\n$$\n\\fbox{{\\bf CALL SRFT1(A, MODE, M, MS, S)}}\n$$\nOn return A() will contain the computed results. S() will contain the sine\ntable used in computing the Fourier transform. MS may have been changed.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[A()]  [inout] If the argument MODE selects Analysis, A() must contain $%\nx$ on input and will contain $\\xi $ on output. If MODE selects Synthesis,\nA() must contain $\\xi $ on input and will contain $x$ on output. When A()\ncontains $x$'s, $A(k+1)$ contains $x_k$, $k=0$, 1, ..., $N-1$. When\nA() contains $\\xi $'s, the real coefficients $\\xi _0$ and $\\xi\n_{N/2}$ are in A(1) and A(2), respectively and the complex coefficients, $%\n\\xi _k$, for $k=1$, ..., $(N/2)-1$, are in the paired locations $(A(2k+1)$, $%\nA(2k+2))$. The remaining complex coefficients satisfy $\\xi _{N-k} =\n\\overline{\\xi}_k$, for $k$ = 1, ..., $\\frac N2-1$.\n\n\\item[MODE]  [in] MODE\\ =\\ $^{\\prime }\\text{A}^{\\prime }$\nor $^{\\prime }\\text{a}^{\\prime }$ selects Analysis.\nMODE\\ =\\ $^{\\prime }\\text{S}^{\\prime }$ or $^{\\prime }\\text{s}^{\\prime }$\nselects Synthesis.\n\n\\item[M]  [in] The number of data points is $N=2^{\\text{M}}$. If $\\text{M}=0$,\nthe subroutine returns taking no action. Require $0\\leq \\text{M}\\leq 31.$\n\n\\item[MS]  [inout] Gives the state of the sine table in S().  Let\n$\\text{MS}_{in}\\text{ and MS}_{out}$ denote the values of MS on entry\nand return respectively. If the sine table has not previously been\ncomputed, set $\\text{MS}_{in} = 0$ or $-$1 before the call. Otherwise\nthe value of $\\text{MS}_{out}$ from the previous call using the same\nS() array can be used as $\\text{MS}_{in}$ for the current call.\n\nCertain error conditions described in Section E cause the subroutine\nto set $\\text{MS}_{out} = -2$ and return.  Otherwise, with M $>$ 0, the\nsubroutine sets $\\text{MS}_{out} = \\max (\\text{M}, \\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, and as\nillustrated in the example of Section~C.\n\n\\item[S()]  [inout] When the sine table has been computed, $\\text{S}(j)=\n\\sin \\pi j/(2\\times NT)$, $j=1,2,...,NT-1$, see MS above.\n\\end{description}\n\n\\subsubsection{Modifications for Double Precision}\n\nChange SRFT1 to DRFT1, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nProgram DRSRFT1 computes an estimate of the spectral composition of\n\\begin{equation}\n\\label{e1}f(t)=[\\sin 2\\pi (t+.01)+4\\cos 2\\pi (\\sqrt{2}\\,t+.3)]\n\\end{equation}\nwith output in ODSRFT1. It is assumed $t$ has units of seconds, $f$ has\ndiscrete frequencies with mutual separation of at least 0.4~cycles/second,\nand that there is no interest in frequencies $>2$ cycles/second. To resolve\ndifferent frequencies we select $\\Delta \\omega =0.4/10=.04$ cycles/second,\nwhich according to Eq.~(20) of Chapter~16.0 implies a sampling period of $%\nT=1/\\Delta \\omega =25$ seconds. According to Eq.~(24) of Chapter~16.0, $\\Delta\nt\\leq \\frac 12\\omega _{N/2}=\\frac 14$~second, if any information about the\nhighest frequency is to be obtained. Thus, $N=T/\\Delta t\\geq 100$. Since\nmodest accuracy is sufficient, we give results for $N=128$ in the program\nbelow. Lanczos sigma factors are used as described in Section G of\nChapter~16.0. The complex transform has peaks for $k=26$ and for $k=36$.\nThese values of $k$ correspond to frequencies of 1 and~1.4~cycles/second.\nResults for this problem, but without the use of Sigma factors are\ngiven in Chapter~16.3.\n\n\\subsection{Functional Description}\n\nFrom Eq.~(\\ref{fa}), the fact that $x_j$ is real, and $W^N=e^{2\\pi i}=1$, it\nfollows that $\\xi _{N-k}=\\overline{\\xi }_k$. Thus $\\xi _{N/2}$ is real, and\nclearly $\\xi _0$ is also real. Thus only half the $\\xi $'s need be\nstored if $\\xi _0$ and $\\xi _{N/2}$ are counted as one. The $\\xi $'s\nare stored in the same space used for the $x$'s by taking advantage\nof this symmetry.\n\nThe primitive FFT routine SFFT (or DFFT) is used to compute $\\zeta $ from $x$%\n, or $x$ from $\\zeta $ where $\\zeta $ is defined by\n\\begin{equation}\\label{e4}\n\\zeta _k=\\frac 2N\\sum_{j=0}^{\\frac\nN2-1}(x_{2j}+ix_{2j+1})W^{-2jk},k=0,1,...,\\frac N2-1.\n\\end{equation}\nUsing Eq.\\ (\\ref{e4}), one finds that $\\zeta _k+\\overline{\\zeta }_{(N/2)-k}$\ndepends only on $x_{2j}$ and $\\zeta _k-\\overline{\\zeta }_{(N/2)-k}$ only on $%\nx_{2j+1}$. From this and Eq.\\ (\\ref{fa}) there follows immediately%\n\\begin{equation}\\label{e5}\n\\begin{split}\n\\xi_k  &=\\frac 14 \\left[(\\zeta _k+\\overline{\\zeta }_{(N/2)-k})\\right.\\\\\n -i&\\left.W^{-k}(\\zeta_k-\\overline{\\zeta}_{(N/2)-k})\\right] ,\n \\ \\ 0<k<N/4\\\\\n \\overline{\\xi}_{(N/2)-k} &= \\frac 14 \\left[(\\zeta _k+\\overline{\\zeta }_{(N/2)\n -k})\\right.\\\\\n +i&\\left.W^{-k}(\\zeta _k-\\overline{\\zeta }_{(N/2)-k})\\right] ,\n \\ \\ 0<k<N/4\\\\\n  \\xi_0 &=\\frac 12 [\\Re\\zeta _0+\\Im\\zeta _0]\\\\\n  \\xi_{N/2} &=\\frac 12 [\\Re\\zeta _0-\\Im\\zeta _0]\\\\\n  \\xi _{N/4} &=\\frac 12 \\overline {\\zeta}_{N/4}\n\\end{split}\n\\end{equation}\n%\\begin{eqnarray}\n%    \\nonumber \\xi_k  & = &  \\frac 14\n%        \\left[(\\zeta _k+\\overline{\\zeta }_{(N/2)-k}) \\hspace{1in}\\right. \\\\\n% \\nonumber &  &  \\left. \\hspace{-.35in} \\mbox{}-iW^{-k}\n%                        (\\zeta _k-\\overline{\\zeta }_{(N/2)-k})\\right] ,\\  0<k<N/4\\\\\n% \\nonumber \\overline{\\xi}_{(N/2)-k} & = &\n%                     \\frac 14 \\left[(\\zeta _k+\\overline{\\zeta }_{(N/2)-k})\\right. \\\\\n%   & & \\left. \\hspace{-.35in} \\mbox{}+iW^{-k}(\\zeta _k-\\overline{\\zeta }_{(N/2)-k})\\right] ,\n%     \\  0<k<N/4\\ \\ \\ \\ \\\\\n%  \\nonumber \\xi_0 & = & \\frac 12 [\\Re\\zeta _0+\\Im\\zeta _0] \\\\\n%   \\nonumber \\xi_{N/2} & = & \\frac 12 [\\Re\\zeta _0-\\Im\\zeta _0] \\\\\n%  \\nonumber      \\xi _{N/4} & = & \\frac 12 \\overline {\\zeta}_{N/4} \\\\\n%  \\nonumber\n%\\end{eqnarray}\nThus to compute $\\xi $ given $x$, $\\zeta /4$ is computed\nusing Eq.~(\\ref{e4}) (divided by~4) and the $\\xi $'s are computed\nfrom Eq.~(\\ref{e5}). To compute $x$ given $\\xi $, the above process is reversed.\nMore details can be found in \\cite{Krogh:1970:RF1}.\n\n\\bibliography{math77}\n\\bibliographystyle{math77}\n\n\\subsection{Error Procedures and Restrictions}\n\nM must satisfy 0 $\\leq \\text{M} \\leq 31$ and MODE must have one of its\nallowed values.  If these conditions are violated an error message will be\nissued using the error processing procedures of Chapter~19.2 with a\nseverity level of~2 to stop execution.  A return will be made with $%\n\\text{MS}=-2$ instead of stopping if the statement ``CALL ERMSET($-1$)''\nis executed before calling this subroutine.\n\nIf the sine table does not appear to have valid data, an error message is\nprinted, and the sine table and then the transform are computed.\n\n\\subsection{Supporting Information}\n\nThe source language is ANSI Fortran~77.\n\n\\begin{tabular}{@{\\bf}l@{\\hspace{5pt}}l}\n\\bf Entry & \\hspace{.35in} {\\bf Required Files}\\vspace{2pt} \\\\\nDRFT1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n DFFT, DRFT1, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSRFT1 & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\n ERFIN, ERMSG, IERM1, IERV1, SFFT, SRFT1}\\\\\n\\end{tabular}\n\nSubroutine designed and written by: Fred T. Krogh, JPL Section~373, August\n1969; Revised January~1988.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSRFT1}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{srft1}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSRFT1}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{srft1}}\n\\end{document}\n", "meta": {"hexsha": "582c145bcdbe747582145330471eef7d714b5d17", "size": 9009, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch10-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/ch10-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/ch10-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": 43.1052631579, "max_line_length": 98, "alphanum_fraction": 0.6723276723, "num_tokens": 3199, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8615382165412809, "lm_q2_score": 0.8740772400852111, "lm_q1q2_score": 0.7530509465423378}}
{"text": "\\subsection{Support Vector Machine} \\label{svm}\n\nSupport Vector Machines (SVM) are highly used due to high empirical performance and somewhat-simple computational complexity, being binary classifiers that when allied with strategies, such as \\textit{one-vs-all}, can be expanded to become multi-class classifiers.\n\nIn our case, SVM was our first approach to the face detection problem, because the dataset, even after the process of data augmentation, is not very large and we are dealing with a binary classification problem, so we decided to start our initial approach with a simpler model like SVM.\n\nInitially we divide our data in two subsets: training subset with \\(80\\%\\) of the images and testing subset with \\(20\\%\\) of the images.\n\nIn SVM there are two main hyper-parameters that can be tweaked to improve the performance of the model, C and Gamma. To get the best performance out of the model we made every combination possible for C and gamma, starting with one of the values present in table \\ref{table:svm-initial-configuration}.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{SVM - 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{Gamma} & [100, 33, 10, 3, 1, 0.3, 0.1, 0.03 ] \\\\ \n \\hline\n \\textbf{C} & [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30] \\\\ \n \\hline\n\\end{tabular}\n\\label{table:svm-initial-configuration}\n\\end{table}\n\nTo validate which combination of hyper-parameters enabled the best performance out of our model we used K-Fold Cross Validation where our training set was divided in \\(K = 5\\) smaller sets, where 4 were used for training and 1 was used to validate the model. With this approach we didn't need to reduce the training dataset by creating a validation dataset and the results did not depend on a particular random choice for the pair of (train, validation) datasets.\n\nAfter validating every combination, as we can see in figure \\ref{fig:svm-cross-validation}, the values of C and gamma where our model performed the best are: C = 30 and Gamma = 1.\n\n\\begin{figure}[htbp]\n\\centerline{\\includegraphics[width=1\\linewidth]{images/svm_cross_validation.png}}\n\\caption{SVM - Cross-Validation using multiple values for C and Gamma}\n\\label{fig:svm-cross-validation}\n\\end{figure}\n\nBased on the Cross Validation data, we created an SVM model with a Radial Basis Function (RBF) kernel, and with the hyper-parameters C = 30 and Gamma = 1, that returns 1 when the image is a face, and 0 otherwise, as we can see in table \\ref{table:svm-final-configuration}.\n\n\\begin{table}[htbp]\n\\centering\n\\caption{SVM - 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{Kernel} &  Radial Basis Function (RBF) \\\\ \n \\hline\n \\textbf{Gamma} & 1 \\\\ \n \\hline\n \\textbf{C} & 30 \\\\ \n \\hline\n\\end{tabular}\n\\label{table:svm-final-configuration}\n\\end{table}\n\nFinally, 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.\n", "meta": {"hexsha": "71630de491a5d9ea07acd4d17c4aab646c45323e", "size": 3133, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/sections/svm.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/svm.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/svm.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": 52.2166666667, "max_line_length": 463, "alphanum_fraction": 0.7465687839, "num_tokens": 858, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9059898254600903, "lm_q2_score": 0.8311430562234877, "lm_q1q2_score": 0.7530071524402837}}
{"text": "\\section{Evaluation}\n\\label{sec:evaluation}\nIf not differently specified, all experiments discussed in this section are run with the following parameters: $N = 500$, $n_{max} = 200$, $n_D = 100$ and $c = 0$.\n\n\\subsection{Storage Capacity}\n\\label{subsec:capacity}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/base}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$. The experiments use $N = 500$, $n_{max} = 200$ and $n_D = 100$.}\n\t\\label{fig:base}\n\\end{figure}\n\\cref{fig:base} shows the results of the base experiment.\nThe x-axis represent different values of $\\alpha = P / N$, while the y-axis the success rate $Q_{l.s.}$.\nAs expected, the function looks like a step function from $1$ to $0$.\nFor $\\alpha \\approx 1.7$, the success rate $Q_{l.s.}$ drops from $1$ to $0$ very quickly. \n\nThe value of $\\alpha$ for which the function drops is called storage capacity of the perceptron.\nFor $N \\to \\infty$ (very large number of examples) and $n_{max} \\to \\infty$ (no limit on the maximum number of training iterations), the theoretical storage capacity of the Rosenblatt perceptron is $\\alpha = 2$.\n\n\\subsection{Number of Iterations}\n\\label{subsec:epochs}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/multiple_epochs}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$ for different values of $n_{max}$.}\n\t\\label{fig:multiple_epochs}\n\\end{figure}\n\nThe difference between the theoretical value and the experimental one are mainly due to the limited number of training iterations.\n\\cref{fig:multiple_epochs} gives an experimental proof of this statement:\nfor a very small number of iterations (eg. $n_{max} = 10$), the step is close to $\\alpha = 1$, while for higher values of iterations the step moves closer and closer to the theoretical value $\\alpha = 2$ found with \\cref{eq:prob-lin-sep-alpha}.\nThe theoretical result still remains far from the practical one because of the limited size of input's dimension $N$.\n\n\\subsection{Number of Dimensions}\n\\label{subsec:dimensions}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/multiple_n}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$ for different values of $N$.}\n\t\\label{fig:multiple_n}\n\\end{figure}\nThe theoretical results are valid for $N \\to \\infty$.\nHowever, real datasets have a limited number of features.\n\\cref{fig:multiple_n} shows the behaviour of the perceptron for different values of $N$.\nFor high values of $N$, the shape of the success rate $Q_{l.s.}$ as a function of $\\alpha$ is similar to a step function.\nFor small values of $N$, the function looks like a smoothed step function:\nthe smaller $N$ is, the higher is the smoothing.\n\n\\subsection{Weight Update Criterion}\n\\label{subsec:c}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/bonus_2_c}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$ for different values of $c$.}\n\t\\label{fig:multiple_c}\n\\end{figure}\n\\cref{fig:multiple_c} shows the effect of changing the values of $c$ in the training procedure of the perceptron.\nFor higher values of $c$, the curve is shifted to the left.\nSince an example $\\xi^\\mu$ is considered correctly classified only when its local potential is greater than $c$ ($E = \\mathsf{\\bm{w}} \\cdot \\xi^\\mu S^\\mu > c$), the potential only depends on $\\mathsf{\\bm{w}}$ for a fixed $\\xi^\\mu$ and the update of $\\mathsf{\\bm{w}}$ is fixed for a given wrong classified example, the perceptron will need a higher number of updates to increase the norm of $\\mathsf{\\bm{w}}$ and make the local potentials higher than a threshold $c > 0$.\nFormally, we can show that the value of $c > 0$ is irrelevant (provided the perceptron is trained long enough):\n\\begin{equation*}\n\t\\mathsf{\\bm{w}}_1 : \\{E_1^\\mu \\geq c\\}_{\\mu = 1}^{P} \\Leftrightarrow \\mathsf{\\bm{w}}_2 = \\lambda \\mathsf{\\bm{w}}_1 : \\{E_2^\\mu \\geq c\\}_{\\mu = 1}^{P}, \\lambda > 0\n\\end{equation*}\n\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/bonus_2_epoch}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$ for different numbers of iterations with fixed value of $c=2$.}\n\t\\label{fig:fixed_c_multiple_epoch}\n\\end{figure}\nTo give an empirical proof of this, we fix the value of $c$ and train the perceptron for different number of iterations $n_{max}$.\nWe expect to see the curve shifted to the left for small $n_{max}$, and approximate a step function centered in $\\alpha = 2$ for big $n_{max}$.\n\\cref{fig:fixed_c_multiple_epoch} shows that the results of the experiment confirm our hypothesis.\n\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/bonus_2_c_epoch}\n    \\caption{Storage success rate of a Rosenblatt perceptron as a function of $\\alpha = P / N$ for different numbers of iterations and $c$.}\n\t\\label{fig:multiple_c_multiple_epoch}\n\\end{figure}\n\\cref{fig:multiple_c_multiple_epoch} compares the curves for $c = 0$ and $c = 2.0$ for different values of $n_{max}$:\nby increasing $n_{max}$, the curve is ``pushed'' towards the right, contrasting the effect of the increased value of $c$.\nWe can somehow see $c$ as a simple version of the learning rate that is used in more complex neural networks: it ``regulates'' the speed of the training.\n\n\\subsection{Inhomogeneous Hyperplanes}\n\\label{subsec:homogeneous}\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/homogeneous}\n    \\caption{Storage success rate of a Rosenblatt perceptron and its inhomogeneous version for $N = 500$ as a function of $\\alpha = P / N$.}\n\t\\label{fig:homogeneous}\n\\end{figure}\nWe run an experiment to verify the behaviour of $Q_{l.s.}$ by allowing inhomogeneous hyperplanes:\nwe train both a normal and modified perceptron for $N = 500$.\n\\cref{fig:homogeneous} shows the results of the experiment.\nAs expected, the success rate $Q_{l.s.}$ of the inhomogeneous perceptron is slightly higher than homogeneous one.\nHowever, the difference is not significant, since data points follow a normal distribution $\\xi^\\mu_j \\sim \\mathcal{N}(0,\\,1)$ and are therefore distributed around the origin.\n\nThe problem of finding an inhomogeneously solution in $R^{N}$ can be solved by finding a homogeneously solution in $R^{N + 1}$.\nIn a second experiment, we compare the success rate $Q_{l.s.}$ of an inhomogeneous perceptron for $N = 500$ with an homogeneous perceptron for $N = 501$.\n\\cref{fig:homogeneous_n_n1} shows the result of this experiment.\nAs expected, the success rates for the $2$ perceptrons are very close to each other.\n\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=\\columnwidth]{figures/homogeneous_n_n1}\n    \\caption{Storage success rate of a homogeneous Rosenblatt perceptron for $N = 501$ and its inhomogeneous version for $N = 500$ as a function of $\\alpha = P / N$.}\n\t\\label{fig:homogeneous_n_n1}\n\\end{figure}\n", "meta": {"hexsha": "2b49bc8bbe27d39d1e30e40738d6a4040aad2422", "size": 7018, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "assignment_1/report/04_evaluation.tex", "max_stars_repo_name": "davidepedranz/neural_networks_assignments", "max_stars_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "assignment_1/report/04_evaluation.tex", "max_issues_repo_name": "davidepedranz/neural_networks_assignments", "max_issues_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "assignment_1/report/04_evaluation.tex", "max_forks_repo_name": "davidepedranz/neural_networks_assignments", "max_forks_repo_head_hexsha": "262a2b33d5c3fe67bbeb20fa6ef1f4870bdfa9a0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 63.2252252252, "max_line_length": 470, "alphanum_fraction": 0.7456540325, "num_tokens": 1963, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8596637577007394, "lm_q1q2_score": 0.7528823445466406}}
{"text": "% !Mode:: \"TeX:UTF-8\"\n% !TEX program  = xelatex\n\\section{Applications}\\label{S:applications}\n\\subsection{Solution to Article Title}\nFrom the definition of quadratic equation in Section~\\ref{S:quadratic}, we can finally answer the question, \\emph{what Angle Should We Throw a Football for Maximum Range?}\n\nFirstly, we establish a rectangular coordinate system, as shown in Figure~\\ref{F:parabolic-throwing}. We denote $\\theta$ as shot angle, $V$ as initial velocity, $g$ as gravity, $S$ as distance, $t$ as time.\n\n\\begin{figure}\n    \\centering\n    \\includegraphics[width=.45\\textwidth]{figures/quadratic_equation-3.png}\n    \\caption{Displacement and coordinates of parabolic throwing}\\label{F:parabolic-throwing}\n\\end{figure}\n\nThen, we have both horizontal and vertical velocity,\n\\begin{equation}\\label{E:solution-1}\n    \\begin{cases}\n        V_x &= V\\cos(\\theta) \\\\\n        V_y &= V\\sin(\\theta) - gt\n    \\end{cases}\n\\end{equation}\n\nTherefore, we have both horizontal and vertical distance at time $t$,\n\\begin{equation}\\label{E:solution-2}\n    \\begin{cases}\n        S_x &= V\\cos(\\theta)t \\\\\n        S_y &= V\\sin(\\theta)t - \\frac{1}{2} gt^2\n    \\end{cases}\n\\end{equation}\n\nFrom Equation~\\eqref{E:solution-1} and Equation~\\ref{E:solution-1}, we can find all of the coordinate $(S_x, S_y)$ with angle $\\theta$. From Equation~\\eqref{E:solution-2}, we have $t=\\tfrac{2V\\sin(\\theta)}{g}$, then we substitute the expression of $t$ back to the $S_y$, we have the quadratic equation\n\\begin{equation}\\label{E:solution-3}\n    S_y = \\tan(\\theta)S_x - \\frac{g}{2V^2\\cos^2(\\theta)}S_x^2.\n\\end{equation}\n\nFrom Equation~\\eqref{E:quadratic-formula}, we can solve this quadratic equation, the solutions are $0$ and $\\tfrac{2V^2}{g}\\sin(\\theta)$. Obviously, $0$ is the initial position, then the football will land at $\\tfrac{2V^2}{g}\\sin(\\theta)$, that is, $\\tfrac{V^2}{g}\\sin(2\\theta)$.\n\nAccording to knowledge of trigonometric functions, we have the maximum range of the football is $\\tfrac{V^2}{g}$, which is taken at $\\theta=45$.\n\n\n\\subsection{Simulation of Projectile Motion}\nYou can use quadratic equation to simulate projectile motion, which can solve free fall problems. If you are familiar with \\texttt{Python}, you can use \\texttt{Python} to draw the pictures of trajectories, and you will find it easy to use Python to solve quadratic equations, especially in symbolic calculations. And the code is in Appendix~\\ref{A:python}.\n", "meta": {"hexsha": "18d43d6c7b31ac686a021bc47f6d46e5f9d01dfe", "size": 2419, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "MA320/sections/quadratic_equation/applications.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/applications.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/applications.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": 56.2558139535, "max_line_length": 356, "alphanum_fraction": 0.72054568, "num_tokens": 717, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8856314647623015, "lm_q2_score": 0.8499711699569787, "lm_q1q2_score": 0.7527612122547261}}
{"text": "\\section{Vector Spaces and Bases}\n\n\\subsection{Real Vector Spaces}\n  A vector space is the abstract reformulation of the quintessential properties of $n$-dimensional Euclidean Space $\\R^n$, which is defined as the set of all real (column) vectors with $n$ entries. The basic laws of vector addition and scalar multiplication in $\\R$.\n\n  \\begin{definition}\n    AA vector space is a set of $V$ equipped with two operations:\n    \\begin{itemize}\n      \\item Addition: adding any pair of vectors v, w $\\in V$ produces another vector v + w $\\in V$;\n      \\item Scalar Multiplication: multiplying a vector v $\\in V$ by a scalar $c\\in\\R$ produces a vector $c$v$\\in V$\n    \\end{itemize}\n\n    These are subject to the following axioms, valid for all u, v, w $\\in V$ and all scalars $c,d\\in\\R$:\n    \\begin{itemize}\n      \\item Commutativity of Addition: v + w = w + v.\n      \\item Associativity of Addition: u + (v + w) = (u + v) + w.\n      \\item Additive Identity: There is a zero element $0\\in V$ satisfying v + 0 = v = 0 + v.\n      \\item Additive Inverse: For each v $\\in V$ there is an element -v $\\in V$ such that v+(-v)=0=(-v)+v.\n      \\item Distributivity: $(c+d)$v=($c$v) + ($d$v), and $c$(v+w)=($c$v)+($c$w).\n      \\item Associativity of Scalar Multiplication: $c$($d$v) = ($cd$)v.\n      \\item Unit for Scalar Multiplication: the scalar 1$\\in\\R$ satisfies 1v=v.\n    \\end{itemize}\n  \\end{definition}\n\n  \\begin{theorem}\n    Let $V$ be a vector space.\n    \\begin{itemize}\n      \\item $0\\times\\vec{V}=\\vec{0}$\n      \\item $-1\\vec{V}=-\\vec{V}$\n      \\item $c\\times\\vec{0}=\\vec{0}$\n      \\item If $c\\times\\vec{V}=\\vec{0}$, then $c=0$ or $\\vec{V}=\\vec{0}$\n    \\end{itemize}\n  \\end{theorem}\n  \n  Here are some examples of vector spaces:\n\n  \\begin{itemize}\n    \\item $\\R^n=\\left\\{\\left.\\left(\\begin{smallmatrix}r_1\\\\r_2\\\\\\vdots\\\\r_n\\end{smallmatrix}\\right)\\right|r_1,r_2,r_n\\in\\R\\right\\}$\n    \\item $M_{m\\times n}=$ The $m$ by $n$ matrices over $\\R$.\n    \\item $\\P^n=$ the polynomials of degree $\\le n$.\n  \\end{itemize}\n\n  \\begin{definition}\n    Let $V$ be a vector space over $F$. $W\\le V$ is a subspace of $V$ if $W$ is a vector space over $F$ under the same operation as $V$.\n  \\end{definition}\n\n  An example of definition (2.1.2). Let $V=\\R^3=\\left\\{\\left.\\left(\\begin{smallmatrix}a\\\\b\\\\c\\end{smallmatrix}\\right)\\right|a,b,c\\in\\R\\right\\}$. $V$ is a vector space. If we let $W=\\left\\{\\left.\\left(\\begin{smallmatrix}a\\\\b\\\\0\\\\\\end{smallmatrix}\\right)\\right|a,b\\in\\R\\right\\}$, then $W$ is a subspace of $V$.\n\n  \\begin{theorem}\n    Let $V$ be a vector space. Let $W\\le V$. $W$ is a subspace of $V$ if \n    \\begin{itemize}\n      \\item $w\\neq0$.\n      \\item $\\forall w_1w_2\\in W;w_1+w_2\\in W$.\n      \\item $\\forall c\\in F;\\vec{W}\\in W;c\\cdot\\vec{W}\\in W$.\n    \\end{itemize}\n  \\end{theorem}\n\n  If we were to let $V=\\R^3$ for $\\left(\\begin{smallmatrix}a\\\\b\\\\c\\\\\\end{smallmatrix}\\right)$. We can determine the following:\n\n  \\begin{itemize}\n    \\item $\\{\\vec{0}\\}$ is a subspace of $V$.\n    \\item $\\left\\{\\left.\\left(\\begin{smallmatrix}a\\\\0\\\\c\\end{smallmatrix}\\right)\\right|a,c\\in\\R\\right\\}$ is a subspace of $V$.\n    \\item Consider the equation $\\left\\{\\left.\\left(\\begin{smallmatrix}x\\\\x\\\\0\\end{smallmatrix}\\right)\\right|x\\in\\R\\right\\}=W$ Show that $W$ is a subspace of $V$.\n    \\begin{itemize}\n      \\item $\\left(\\begin{smallmatrix}0\\\\0\\\\0\\end{smallmatrix}\\right)\\in W$ so $W\\neq0$.\n      \\item $\\left(\\begin{smallmatrix}x\\\\x\\\\0\\end{smallmatrix}\\right),\\left(\\begin{smallmatrix}y\\\\y\\\\0\\end{smallmatrix}\\right)\\in W$. Then $\\left(\\begin{smallmatrix}x\\\\x\\\\0\\end{smallmatrix}\\right)+\\left(\\begin{smallmatrix}y\\\\y\\\\0\\end{smallmatrix}\\right)=\\left(\\begin{smallmatrix}x+y\\\\x+y\\\\0\\end{smallmatrix}\\right)$\n      \\item $\\left(\\begin{smallmatrix}x\\\\x\\\\0\\end{smallmatrix}\\right)\\in W$, then $c\\times\\left(\\begin{smallmatrix}x\\\\x\\\\0\\end{smallmatrix}\\right)=\\left(\\begin{smallmatrix}cx\\\\cx\\\\0\\end{smallmatrix}\\right)\\in W$.\n      \\item Therefore, we know that $W$ is a subspace of $V$ with respect to scalar multiplication and addition.\n    \\end{itemize}\n    \\item $W=\\left\\{\\left.\\left(\\begin{smallmatrix}x\\\\y\\\\2x+3y\\end{smallmatrix}\\right)\\right|x,y\\in\\R\\right\\}$. $W$ is a subspace of $V$.\n  \\end{itemize}\n\n  $\\R^3$ only has 4 kinds of subspaces. $\\R^3$, $\\{\\vec{0}\\}$, planes passing through the origin and lines that are passing through the origin.\n\n  \n\\subsection{Subspaces}\n\n  \\begin{definition}\n    Let $I$ be an interval in $\\R$. Let $\\mathbb{F}(I)$ be the vector space of functions $\\mathbb{F}=I\\to\\R$.\n\n    \\begin{itemize}\n      \\item $\\mathbb{C}^0(I)=$ the continuous functions from $I\\to\\R$ is a subspace.\n      \\item $\\P^n(I)=$ polynomials of degree $\\le n$ restricted to $\\mathbb{F}(I)$. This is a subspace of $C^0(I)$.\n      \\item $\\P^\\infty(I)=$ all polynomials on $I$. This is a subspace of $\\mathbb{F}(I)$.\n      \\item $\\mathbb{C}^n (I)=$ the set of functions $f:I\\to\\R$ such that $f',f''...f^{(n)}$ all exist and are continuous.\n      \\item $\\mathbb{C}^\\infty(I)=$ functions from $I\\to\\R$ such that $f',f'',f'''$ all exist and are smooth functions.\n      \\item $A(I)=$ the functions in $\\mathbb{C}^\\infty(I)$ such that all $A\\in I$, the power series $f(a)+\\frac{f'(a)(x-a)}{1!}+\\frac{f''(a)(x-a)^2}{2!}+\\dots$ converges for all $x\\in I$ sufficiently close to $a$.\n    \\end{itemize}\n  \\end{definition}\n\n  \\begin{problem}\n    Show that $v=\\left(\\begin{smallmatrix}x\\\\y\\\\2x+y\\end{smallmatrix}\\right)$ is a subspace of $\\R^3$.\n\n    \\begin{itemize}\n      \\item Because $\\left(\\begin{smallmatrix}0\\\\0\\\\2(0)+0\\end{smallmatrix}\\right)=\\left(\\begin{smallmatrix}0\\\\0\\\\0\\end{smallmatrix}\\right)$ is in $v$, $v$ is not empty.\n      \\item Let $\\vec{v_1}=\\left(\\begin{smallmatrix}x_1\\\\y_1\\\\2x_1+y_1\\end{smallmatrix}\\right),\\vec{v_2}=\\left(\\begin{smallmatrix}x_2\\\\y_2\\\\2x_2+y_1\\end{smallmatrix}\\right)\\in V$\n        \\[\n          v_1+v_2=\\begin{pmatrix}\n            x_1+x_2\\\\\n            y_1+y_2\\\\\n            2x_1+y_1+2x_2+y_2\n          \\end{pmatrix}\n          = \\begin{pmatrix}\n            x_1+x_2\\\\\n            y_1+y_2\\\\\n            2(x_1+x_2)+(y_1+y_2)\n          \\end{pmatrix}\n          \\in V\n        \\]\n        so $v$ is closed with respect to addition.\n      \\item Let $r\\in\\R$ and $\\left(\\begin{smallmatrix}x\\\\y\\\\2x+y\\end{smallmatrix}\\right)=\\vec{v}\\in v$.\n    \\end{itemize}\n  \\end{problem}\n\n\\subsection{Span and Linear Independence}\n\n  If we let $V$ be a vector space over $\\R$ and let $\\vec{v_1},\\dots,\\vec{v_n}\\in V$, then we can determine that the \n  \\[\n    span(\\{\\vec{v_1},\\dots,\\vec{v_n}\\})=\\{c_1\\vec{v_1}+\\dots+c_n\\vec{v_n}|c_1,\\dots,c_n\\in\\R\\}\n  \\]\n\n  \\begin{prop}\n    The span of $\\{\\vec{v_1},\\vec{v_2}\\}$ is a subspace of $V$.\n    \\begin{proof}\n      \\begin{align*}\n        c_1\\vec{v_1}+\\dots+c_n\\vec{v_n}\\\\\n        k_1\\vec{v_1}+\\dots+k_n\\vec{v_n}\\in span\\\\\n      \\end{align*}\n\n      If we add together both of the equations above we get\n\n      \\begin{align*}\n        (c_1+k_1)\\vec{v_1}+\\dots+(c_n+k_n)\\vec{v_n}\\in span.\\\\\n        r(c_1\\vec{v_1}+\\dots+c_n\\vec{v_n})\\\\\n        =rc_1\\vec{v_1}+\\dots+rc_n\\vec{v_n}\\in span\n      \\end{align*}\n    \\end{proof}\n  \\end{prop}\n\n  \\begin{problem}\n    Let $V\\in\\R^3$. Also, we are going to let\n\n    \\[\n      \\vec{v_1}=\\begin{pmatrix}\n        1\\\\2\\\\0\n      \\end{pmatrix}\n      ,span(\\vec{v_1})=\\left\\{c\\left.\\begin{pmatrix}1\\\\2\\\\0\\end{pmatrix}\\right|c\\in\\R\\right\\}\n    \\]\n    $\\left(\\begin{smallmatrix}1\\\\2\\\\0\\end{smallmatrix}\\right)$ is a vector in 3-space. $c\\times\\left(\\begin{smallmatrix}1\\\\2\\\\0\\end{smallmatrix}\\right)$ expands, contracts, changes direction. This is a line which goes through $\\left(\\begin{smallmatrix}0\\\\0\\\\0\\end{smallmatrix}\\right)$.\n    \\[\n      c\\begin{pmatrix}\n        1\\\\2\\\\0 \n      \\end{pmatrix}\n    \\]\n    is in the $xy$-plane, let's solve for $y$ to find the equation of the line that is drawn by the vector:\n\n    \\begin{align*}\n      \\begin{pmatrix}\n        c\\\\2c\\\\0\n      \\end{pmatrix}\\\\\n      x&=c\\\\\n      y&=2c\\\\\n      \\frac{1}{2}y&=c\\\\\n      \\to x=\\frac{1}{2}y\\\\\n      \\to y=2x\\\\\n    \\end{align*}\n    Now we are going to let $\\vec{v_2}=\\left(\\begin{smallmatrix}1\\\\1\\\\0\\end{smallmatrix}\\right)$. Consider the span of $(\\{\\vec{v_1},\\vec{v_2}\\})$. The span of $(\\{\\vec{v_1}\\vec{v_2}\\})$ is a plane.\n  \\end{problem}\n\n  In $\\R^3$, if $\\vec{0}\\neq\\vec{v}\\in\\R$, then the span$\\vec{v}$ is a line.\n\n  \\begin{problem}\n    Let $v=\\P^2$. $v$ is the set of polynomials of degree $\\le2\\in\\R$.\n\n    \\begin{itemize}\n      \\item $span(1,x,x^2)=\\P^2$\n      \\item $span(4,2x)=\\P^1$, which means all polynomials of degree $\\le1$\n    \\end{itemize}\n\n  \\end{problem}\n  \\begin{definition}\n    Let $v$ be a vector space. $\\vec{v_1},\\dots,\\vec{v_n}$ are linearly dependent if there exists $c_1,\\dots,c_n$ are not all zero, such that $c_1\\vec{v_1}+\\dots+c_n\\vec{v_n}=\\vec{0}$, otherwise, $\\vec{v_1},\\dots,\\vec{v_n}$ are linearly independent.\n  \\end{definition}\n  \n  If we let $\\vec{v_1}=\\SmallMatrix{1\\\\2},\\vec{v_2}=\\SmallMatrix{2\\\\4}$, we can do a simple test to see if they are linearly independent. We know that $2\\vec{v_1}=\\vec{v_2}$, which means that $2\\vec{v_1}+-1\\vec{v_2}=0$. Because we can make $\\vec{v_1}+\\vec{v_2}$ by using a simple scalar value, these functions are linearly dependent.\n\n  \\begin{problem}\n    Consider the following three matrices\n    \\[\n      \\vec{v_1}=\\begin{pmatrix}\n        1\\\\2\\\\1\n      \\end{pmatrix}\n      ,\\vec{v_2}=\\begin{pmatrix}\n        2\\\\1\\\\1\\\\\n      \\end{pmatrix}\n      ,\\vec{v_3}=\\begin{pmatrix}\n        8\\\\1\\\\11\n      \\end{pmatrix}\n    \\]\n    Are these matrices linearly dependent or independent of each other? The following equation will let us set up a matrix to determine the results:\n\n    \\[\n      c_1\\vec{v_1}+c_2\\vec{v_2}+c_3\\vec{v_3}=\\vec{0}\n    \\]\n\n    We must try to see if there are any $c_n$ values that are not zero to make this true.\n\n    \\[\n      \\begin{pmatrix}\n        1&2&8\\\\2&-1&1\\\\1&3&11\n      \\end{pmatrix}\n      \\begin{pmatrix}\n        c_1\\\\c_2\\\\c_3\\\\\n      \\end{pmatrix}\n      =\\begin{pmatrix}\n        0\\\\0\\\\0\n      \\end{pmatrix}\n    \\]\n    \\[\n      = \\begin{pmatrix}\n        1&2&8&\\vdots&0\\\\\n        2&-1&1&\\vdots&0\\\\\n        1&3&0&\\vdots&0\\\\\n      \\end{pmatrix}\n    \\]\n    By doing some elementary row operations, we can find that in row echelon form, the matrix from equation (2.21) can be written as\n\n    \\[\n      \\begin{pmatrix}\n        1&2&8&\\vdots&0\\\\\n        9&1&3&\\vdots&0\\\\\n        0&0&0&\\vdots&0\\\\\n      \\end{pmatrix}\n    \\]\n    And from here we can solve for the different $c_n$ values.\n\n    \\begin{align*}\n      1c_1+2c_2+8c_3&=0\\\\\n      c_1+3c_3&=0\\\\\\\\\n      c_3=-3c_3\\\\\n      c_1=-2c_3\\\\\n      c_3=c_3  \n    \\end{align*}\n\n    Because we have this relationship where $c_1,c_2,c_3$ all depend on each other, we can tell that this is linearly independent.\n  \\end{problem}\n\n  \\subsubsection{Linear Independence and Dependence}\n  \n\\subsection{Basis and Dimension}\n  \\begin{definition}\n    AA basis of a vector space $v$ is a collection of vectors $\\vec{v_1},\\dots,\\vec{v_n}$ that (1) span $v$ and (2) are linearly dependent.\n  \\end{definition}\n\n  \\begin{problem}\n    If we are looking at $\\mathbb{R}^2$, with $e_1=\\left(\\begin{smallmatrix}1\\\\0\\end{smallmatrix}\\right)$, and $e_2=\\left(\\begin{smallmatrix}0\\\\1\\end{smallmatrix}\\right)$\n    We can tell that this is a basis of $\\mathbb{R}^2$. We can tell this because the span of $v$ is linearly independent. We can also see this because:\n\n    \\[\n      a\\times e_1+b\\times e_2=\\begin{pmatrix}a\\\\b\\end{pmatrix}\n    \\]\n  \\end{problem}\n\n  \\begin{problem}\n    Now we are going to look at an example in $\\mathbb{R}^3$, with $e_1=\\left(\\begin{smallmatrix}1\\\\0\\\\0\\end{smallmatrix}\\right)$, $e_2=\\left(\\begin{smallmatrix}0\\\\1\\\\0\\end{smallmatrix}\\right)$, and $e_3=\\left(\\begin{smallmatrix}0\\\\0\\\\1\\end{smallmatrix}\\right)$. We can figure out that this is a basis by doing the same technique as we did before:\n\n    \\begin{align*}\n      c_1\\vec{e_1}+c_2\\vec{e_2}+c_3\\vec{e_3}=0\\\\\n      c_1=c_2=c_3=0\n    \\end{align*}\n\n    Because $c_1$, $c_2$, and $c_3$ are all equal to zero, $\\vec{e_1}$, $\\vec{e_2}$, and $\\vec{e_3}$ form a basis.\n  \\end{problem}\n\n  \\newpage\n\n  \\begin{theorem}\n    If a vector space $v$ has a basis with $n$ elements, then every basis of $v$ has $n$ elements. We say $v$ has dimension $n$. We write down $v=n$.\n  \\end{theorem}\n\n  \\begin{theorem}\n    If the dimension of $v$ is $n$, then any collection of $n+1$ or more vectors must be linearly dependent.\n  \\end{theorem}\n\n  \\begin{theorem}\n    Suppose $v=n$\n    \n    \\begin{enumerate}\n      \\item Every collection of more than $n$ vectors is linearly dependent.\n      \\item No set of fewer than $n$ vectors spans $v$.\n      \\item A set of $n$ vectors is a basis if and only if it spans $v$.\n      \\item A set of $n$ vectors is a basis if and only if it is linearly dependent.\n    \\end{enumerate}\n  \\end{theorem}\n\n  \\begin{problem}\n    Assume $1,x,x^2$ is a basis for $\\mathbb{P}^2$. We are going to multiply $1\\times5$, $x\\times6$, and $x^2\\times2$.\n\n    \\begin{align*}\n      5+6x+2x^2&\\\\\n      c_1\\times1+c_2\\times x+c_3\\times x^2&=0\\\\\n      dim(\\mathbb{P}^2)&=3\\\\\n    \\end{align*}\n  \\end{problem}\n\n  \\begin{theorem}\n   h$\\vec{v_1},\\dots\\vec{v_2}$ form a basis of $v$ if and only if for all $\\vec{v}\\in v$, there exist unique $c_{1},\\dots,c_{n}$ such that $\\vec{v}=c_1\\vec{v_1}+\\dots c_n\\vec{v_n}$\n  \\end{theorem}\n\n  \\begin{problem}\n    Let $v=\\mathbb{R}^2$. Let $\\vec{v}=\\left(\\begin{smallmatrix}4\\\\3\\end{smallmatrix}\\right)$. We know from previous problems that $\\left(\\begin{smallmatrix}1\\\\0\\end{smallmatrix}\\right)\\left(\\begin{smallmatrix}0\\\\1\\end{smallmatrix}\\right)$ is a basis of $\\mathbb{R}^2$. We can also figure out what our basis is by trying to figure out what our $c_1$ and $c_2$ values should be. Because the matrices we know are a basis consist of 1's and 0's, we can see that \n\n    \\[\n      4\n      \\begin{pmatrix}\n        1\\\\0\n      \\end{pmatrix}\n      +\n      \\begin{pmatrix}\n        0\\\\1\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        4\\\\3\n      \\end{pmatrix}.\n    \\]\n    The coordinates of $\\vec{v}$ with respect to this basis, are $(4,3)$. Let's consider a different basis. We are now going to look at the basis,\n\n    \\[\n      \\left\\{\n        \\begin{pmatrix}\n          1\\\\-3\n        \\end{pmatrix},\n        \\begin{pmatrix}\n          2\\\\-1\n        \\end{pmatrix}\n      \\right\\}\n    \\]\n\n    Now we need to figure out the $a$ and $b$ values for this basis respectively.\n\n    \\begin{align*}\n      a\n      \\begin{pmatrix}\n        1\\\\-3 \n      \\end{pmatrix}\n      + b\n      \\begin{pmatrix}\n        2\\\\-1\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        4\\\\3\n      \\end{pmatrix}\n      \\\\\n    \\end{align*}\n    The coordinates of $\\vec{v}$ with respect to this basis are $(4,3)$. Let's consider the same problem but with the following basis:\n\n    \\[\n      \\left\\{\n        \\begin{pmatrix}\n          1\\\\-3\n        \\end{pmatrix}\n        ,\n        \\begin{pmatrix}\n          2\\\\-1\n        \\end{pmatrix}\n      \\right\\}\n    \\]\n    Now, we are going to do the same thing as before, where we solve for $a$ and $b$ in the following equation\n\n    \\[\n      a\n      \\begin{pmatrix}\n        1\\\\-3\\\n      \\end{pmatrix}\n      +b\n      \\begin{pmatrix}\n        2\\\\-1\n      \\end{pmatrix}\n      =\n      \\begin{pmatrix}\n        4\\\\3\n      \\end{pmatrix}\n    \\]\n\n    We can set up this to be a system of equations that we can turn into a matrix\n\n    \\[\n      \\begin{cases}\n        1a+2b=4\\\\\n        -3a+(-1)b=3\\\\\n      \\end{cases}\n      \\to\n      \\begin{bmatrix}\n        1&2&\\vdots&4\\\\\n        -3&-1&\\vdots&3\\\\\n      \\end{bmatrix}\n    \\]\n    And now we can use the basic row operation $R_2=R_2+3R_1$ in order to solve for $a$ and $b$:\n\n    \\[\n      \\begin{bmatrix}\n        1&2&\\vdots&4\\\\\n        0&5&\\vdots&5\n      \\end{bmatrix}\n    \\]\n\n    \\begin{align*}\n      5b=15 && a+2b=4\\\\\n      b=3 && 1+2*3=4\\\\\n      && a=-2\n    \\end{align*}\n  \\end{problem}\n  \n\\subsection{The fundamental Matrix Subspaces (Kernel and Image)}\n\n  \\begin{definition}\n    The image of an $m\\times n$ matrix $A$ is the subspace spanned by the columns of A.\n  \\end{definition}\n\n  \\begin{problem}\n\n    Let's consider the following equation. \n\n    \\[\n      \\begin{bmatrix}\n        1&2&3\\\\4&5&6\\\\\n      \\end{bmatrix}\n      \\begin{bmatrix}\n        r_1\\\\r_2\\\\r_3\n      \\end{bmatrix}\n      =\n      \\begin{bmatrix}\n        x\\\\y\n      \\end{bmatrix}\n    \\]\n\n    When we multiply our the matrix, we see that the span of the columns give us all the possible $\\left[\\begin{smallmatrix}x\\\\y\\end{smallmatrix}\\right]$ values. The span of the matrix \n\n    \\[\n      \\begin{bmatrix}\n        1\\times r_1&2\\times r_2&3\\times r_3\\\\\n        4\\times r_1&5\\times r_2&6\\times r_3\\\\\n      \\end{bmatrix}\n    \\]\n    would be the values $\\left[\\begin{smallmatrix}1\\\\4\\end{smallmatrix}\\right]$, $\\left[\\begin{smallmatrix}2\\\\5\\end{smallmatrix}\\right]$, and $\\left[\\begin{smallmatrix}3\\\\6\\end{smallmatrix}\\right]$\n  \\end{problem}\n\n  \\begin{definition}\n    AA space, $A$, is an $m\\times m$ matrix, The kernel of $A$ is \n    \\begin{align*}\n      A&=Ker(A)\\\\\n      &=\\{\\vec{x}|A\\vec{x}=\\vec{0}\\}\n    \\end{align*}\n  \\end{definition}\n\n  Using definition (2.5.2), if $A=\\left[\\begin{smallmatrix}1&0\\\\5&0\\\\\\end{smallmatrix}\\right]$, then \n\n  \\[\n    \\vec{x_1}=\n    \\begin{bmatrix}\n      0\\\\0\n    \\end{bmatrix}\n    , \n    \\vec{x_2}=\n    \\begin{bmatrix}\n      0\\\\5\n    \\end{bmatrix}.\n  \\]\n\n  Something to keep in mind: If $\\vec{x_1},\\vec{x_2}\\in Ker(A)$, then $r_1\\vec{x_1}+r_2\\vec{x_2}\\in Ker(A)$. So the kernel of $A$ is a subspace of the domain of the function.\n\n  \\begin{theorem}\n    Assume $\\vec{x_1}$ solves $A\\vec{x}=\\vec{b}$. Then, $\\vec{x_2}$ is another solution to $A\\vec{x}=\\vec{b}$ if and only if $\\vec{x_2}=\\vec{x_1}+\\vec{z}$, where $z\\in Ker(A)$\n  \\end{theorem}\n\n  \\begin{prop}\n    Let $A$ be an $m\\times n$ matrix. The following are true:\n\n    \\begin{enumerate}\n      \\item $Ker(A)=\\{\\vec{0}\\}$\n      \\item $rank(A)=n$\n      \\item $A\\vec{x}=\\vec{b}$ has a unique solution for any $\\vec{b}$ in the integer of $A$.\n      \\item $A\\vec{x}=\\vec{b}$ has no free variables.\n      \\item $A$ is non-singular.\n    \\end{enumerate}\n  \\end{prop}\n\n  \\begin{definition}\n    Let $A$ be $m\\times n$. \n    \\begin{align*}\n      coimg(A)=img(A^T)\\\\\n      coker(A)=ker(A^T)\\\\\n    \\end{align*}\n  \\end{definition}\n\n  The image of $A$ is the span of its columns. Thus, the coimage is the span of its radius. Also, the $\\vec{r^T}$ in the cokernel of $A$ are those $\\vec{r}$ such that $r\\times A=\\vec{0^T}$ since\n\n  \\begin{align*}\n    (r\\cdot A)^T=(\\vec{0^T})^T\\\\\n    A^T\\cdot r^T=\\vec{0}\n  \\end{align*}\n\n  \\begin{theorem}\n    The Fundamental Theorem of Linear Algebra: Let $A$ be an $m\\times n$ matrix and let r be its rank. Then\n\n    \\[\n      dim(coimg(A))=dim(img(A))=rank(A)=rank(A^T)=r\\\\\n    \\]\n    \\[\n      span(A_{rows})=span(A_{columns})\\\\\n    \\]\n    \\[\n      dim(ker(A))=n-r\\\\\n    \\]\n    \\[\n      dim(coker(A))=m-r\\\\\n    \\]\n  \\end{theorem}\n\n  Let's take a look at an example using the fundamental theorem of linear algebra. Let\n\n  \\[\n    A=\\begin{bmatrix}\n      1&2&3&-1\\\\\n      1&-1&0&2\\\\\n      -1&1&0&-2\\\\\n      2&1&3&1\n    \\end{bmatrix}\n  \\]\n\n  Let's do some row operations to get this matrix into row echelon form:\n\n  \\[\n    A=\\begin{bmatrix}\n      1&2&3&-1\\\\\n      0&-3&-3&3\\\\\n      0&0&0&0\\\\\n      0&0&0&0\\\\\n    \\end{bmatrix}\n  \\]\n\n  From this form, we can tell that $v_3$ and $v_4$ both depend on $v_1$ and $v_2$. Because there are only two pivot points within $A$ that are filled with values other than 0, $rank(A)=0$. We also know that the dimension of the column space is equal to the dimension of the row space. Let's find the dimension of the kernel of $A$:\n\n  \\begin{align*}\n    dim(ker(A))+rank=n\\\\\n    dim(key(A))+2=4\\\\\n  \\end{align*}\n\n  From here, we know that both $y$ and $z$ are free variables.\n\n  \\begin{align*}\n    w+2x+3y-z&=0\\\\\n    -3x-3y+3z&=0\\\\\n    x+y-z&=0\\\\\n    x&=-y+z\n  \\end{align*}\n  \\begin{align*}\n    w&=-2x-3y+z\\\\\n    &=-2(-y+z)-3y+z\\\\\n    &=-y-z\n  \\end{align*}\n\n  Now we need to determine the basis for $ker(A)$.\n\n  \\[\n    \\begin{pmatrix}\n      -y-z\\\\-y+z\\\\y\\\\z\n    \\end{pmatrix}\n    =\\begin{pmatrix}\n      -y\\\\-y\\\\-y\\\\0\n    \\end{pmatrix}\n    +\\begin{pmatrix}\n      -z\\\\z\\\\0\\\\z\n    \\end{pmatrix}\n    =y\\begin{pmatrix}\n      -1\\\\-1\\\\1\\\\0\n    \\end{pmatrix}\n    +z\\begin{pmatrix}\n      -1\\\\1\\\\0\\\\1\n    \\end{pmatrix}\n  \\]\n  \n  Our basis for $ker(A)$ is $\\SmallMatrix{-1\\\\-1\\\\1\\\\0}$ and $\\SmallMatrix{-1\\\\1\\\\0\\\\1}$.\n", "meta": {"hexsha": "4624cb4ddfc35bf4557c86412dfe2000e7aed7ec", "size": 20301, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math363/chapters/2.tex", "max_stars_repo_name": "CameronSWilliamson/GU-MATH", "max_stars_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-03-18T00:49:14.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-18T00:49:14.000Z", "max_issues_repo_path": "math363/chapters/2.tex", "max_issues_repo_name": "therealkeyisme/Math-Notes", "max_issues_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math363/chapters/2.tex", "max_forks_repo_name": "therealkeyisme/Math-Notes", "max_forks_repo_head_hexsha": "a501bcb919b60bc35fa43b99eb6ed2a2630cb100", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 34.6433447099, "max_line_length": 459, "alphanum_fraction": 0.5920890597, "num_tokens": 7510, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.903294214513915, "lm_q2_score": 0.8333245891029457, "lm_q1q2_score": 0.7527372801488763}}
{"text": "%---------------------------Shape-----------------------------\n\\section{Shape\\label{s:quad-shape}}\n\nThe shape metric is 2 divided by the condition number of the Jacobian matrix:\n\\[\nq =\n  2 \\min \\left\\{ \\frac {\\alpha_0} { \\normvec{L_0}^2 + \\normvec{L_3}^2 }, \n                 \\frac {\\alpha_1} { \\normvec{L_1}^2 + \\normvec{L_0}^2 }, \n                 \\frac {\\alpha_2} { \\normvec{L_2}^2 + \\normvec{L_1}^2 }, \n                 \\frac {\\alpha_3} { \\normvec{L_3}^2 + \\normvec{L_2}^2 }\n  \\right\\}.\n\\]\nNote that if $\\alpha_i < DBL\\_MIN$ or any edge has length $L < DBL\\_MIN$, we set $q = 0$.\n\n\\quadmetrictable{shape}%\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\\_shape}%                           Verdict function name\n\n", "meta": {"hexsha": "311c276471745e30d97d5f54ce102bd058e7f05e", "size": 1013, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Utilities/verdict/docs/VerdictUserManual2007/QuadShape.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/QuadShape.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/QuadShape.tex", "max_forks_repo_name": "Armand0s/homemade_vtk", "max_forks_repo_head_hexsha": "6bc7b595a4a7f86e8fa969d067360450fa4e0a6a", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 5, "max_forks_repo_forks_event_min_datetime": "2015-03-23T21:13:19.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T11:15:39.000Z", "avg_line_length": 42.2083333333, "max_line_length": 89, "alphanum_fraction": 0.4234945706, "num_tokens": 300, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625088705931, "lm_q2_score": 0.8080672066194946, "lm_q1q2_score": 0.7526843076138464}}
{"text": "% -*- root: Main.tex -*-\n\\section{SVD}\n$\\mathbf{A} = \\mathbf{U} \\mathbf{D} \\mathbf{V}^\\top = \\sum_{i=1}^{s=min\\{m,n\\}} \\sigma_i u_i (v_i)^\\top$\\\\\n$\\mathbf{A} \\in \\mathbb{R}^{m \\times n}, \\mathbf{U} \\in \\mathbb{R}^{m \\times m}, \\mathbf{D} \\in \\mathbb{R}^{m \\times n}, \\mathbf{V} \\in \\mathbb{R}^{n \\times n}$\\\\\n$\\mathbf{U,V}$ orthogonal, $D=diag(\\sigma_1,...,\\sigma_s), \\sigma_1 \\geq ... \\geq \\sigma_s \\geq 0$. Rank($\\mathbf{A})=$\\#non-zero singular values.\n\n\\subsection*{Eckart-Young Theorem}\n$\\min_{rank(B)=K} ||A-B||_F^2 = ||A-A_k||_F^2 = \\sum_{r=k+1}^{rank(A)} \\sigma_r^2$ \\\\\nnote: use $Tr(A^\\top A)$ def of F-norm to prove.\n$\\min_{rank(B)=K} ||A-B||_2 = ||A-A_k||_2 = \\sigma_{k+1}$\n", "meta": {"hexsha": "0e3d906c74e73979ddc9d81a61cfd2dd85b71ccb", "size": 685, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "SVD.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": "SVD.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": "SVD.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": 62.2727272727, "max_line_length": 162, "alphanum_fraction": 0.5751824818, "num_tokens": 318, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9314625069680098, "lm_q2_score": 0.808067204308405, "lm_q1q2_score": 0.7526843039237379}}
{"text": "\\chapter{Vector Integration}\n\\begin{enumerate}\n\t\\item  If $\\vec{F}=3 x y \\hat{i}-y^{2} \\hat{j}$ determine the value of $\\int_{c} \\vec{F} \\cdot d \\vec{r}$ where $C$ is the curve $y=2 x^{2}$ in the $x y$ plane from $(0,0)$ to $(1,2)$.\n\t\\begin{figure}[H]\n\t\t\\begin{center}\n\t\t\t\\includegraphics[width=4cm,height=4cm]{VI-Assignment-01}\n\t\t\\end{center}\n\t\\end{figure}\n\t\\begin{answer}\n\t\tThe curve lies in $x y$ plane, so, $z=0 . z$ can never be taken as independent variable $z$ is a dependent variable. Now, out of $x$ and $y$, any one variable can be taken as independent.\n\t\tSuppose $x$ is taken as independent variable\n\t\t\\begin{align*}\n\t\t y &=2 x^{2}, d y=4 x d x \\\\ \\vec{F} \\cdot d \\vec{r} &=3 x y d x-y^{2} d y \\\\ &=6 x^{3} d x-4 x^{4} \\cdot 4 x d x \\\\ &=\\left(6 x^{3}-16 x^{5}\\right) d x \n\t\t \\intertext{So, the line integral $\\int_{C} \\vec{f} \\cdot d \\vec{r}$ reduces to a definite integral.}\n\t\t \\int_{0}^{1}\\left(6 x^{3}-16 x^{5}\\right) d x&\\\\\n\t\t &=\\left.6 \\frac{x^{4}}{4}\\right|_{0} ^{1}-\\left.16 \\frac{x^{6}}{6}\\right|_{0} ^{1}\\\\\n\t\t &=-\\frac{7}{6}\n\t\t \\intertext{If $y$ is taken as independent variable then $x$ can be expressed in terms of $y$ as}\n\t\t x &=\\sqrt{\\frac{y}{2}} \\\\ d x &=\\frac{1}{2 \\sqrt{2}} \\frac{1}{\\sqrt{y}} d y \\\\ \\text{So}\\quad \\vec{f} \\cdot d \\vec{r} &=3 x y d x-y^{2} d y \\\\ &=3 y \\sqrt{\\frac{y}{2}} \\cdot \\frac{1}{2 \\sqrt{2}} \\frac{1}{\\sqrt{y}} d y-y^{2} d y \\\\ &=\\left(\\frac{3}{4} y-y^{2}\\right) d y \n\t\t \\intertext{So, the line integral $\\int \\vec{f} . d \\vec{r}$ reduces to a definite integral}\n\t\t \\int_{0}^{2}\\left(\\frac{3}{4} y-y^{2}\\right) d y&\\\\\n\t\t &=\\frac{3}{8} y^{2}-\\left.\\frac{y^{3}}{3}\\right|_{0} ^{2}\\\\\n\t\t &=-\\frac{7}{6}\\\\\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate $\\int_{c} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=\\left(x^{2}-y^{2}\\right) \\hat{i}+x y \\hat{j}$ and curve $C$ is arc of the curve $y=x^{2}$ from $(0,0)$ to $(2,4)$\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=3cm]{VI-Assignment-02}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\vec{F} \\cdot d \\vec{r}&=\\left(x^{2}-y^{2}\\right) d x+x y d y\n\t\\intertext{\tTaking $x$ as independent variable}\n\t\ty=x^{2} & d y=2 x d x \\\\\n\t\t\\vec{F} \\cdot d \\vec{r} & =\\left(x^{2}-y^{2}\\right) d x+x y d y \\\\\n\t\t& =\\left(x^{2}-x^{4}\\right) d x+x^{3} \\cdot 2 x d x \\\\\n\t\t& =\\left(x^{2}+x^{4}\\right) d x\n\t\t\\intertext{So, the line integral $\\int \\vec{F} \\cdot d \\vec{r}$ reduces to a definite integral}\n\t\t\\int_{0}^{2}\\left(x^{2}+x^{4}\\right) d x&=\\frac{x^{3}}{3}+\\left.\\frac{x^{5}}{5}\\right|_{0} ^{2}=\\frac{136}{15}\n\t\t\\intertext{Suppose a force acts on a particle and particles is displaced along a given path $C$. Then work done by the force $\\vec{F}$ is given by line integral.}\n\t\tW&=\\int_{C} \\vec{F} \\cdot d \\vec{r}\n\t\t\\intertext{The integration is being carried in the sense of displacement.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the work done when a force\n\t$$\n\t\\vec{F}=\\left(x^{2}-y^{2}+x\\right) \\hat{i}-(2 x y+y) \\hat{j}\n\t$$\n\tmoves a particle in $x y$ plane from $(0,0)$ to $(1,1)$ along the parabola $y^{2}=x$\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=3.5cm]{VI-Assignment-03}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{Here, on the curve $C, y$ can be taken as independent variable and}\n\tx&=y^{2}, d x=2 y d y\n\t\\intertext{workdone in moving a particle by displacement $d \\vec{r}$}\n\td W &=\\vec{F} \\cdot d \\vec{r} \\\\ &=\\left(x^{2}-y^{2}+x\\right) d x-(2 x y+y) d y \\\\ &=\\left(y^{4}-y^{2}+y^{2}\\right) \\cdot 2 y d y-\\left(2 y^{2} \\cdot y+y\\right) d y \\\\ &=\\left(2 y^{5}-2 y^{3}-y\\right) d y \n\t\\intertext{Hence, work done is moving a particle from $O$ to $P$ is given by}\n\tW&=\\int_{0}^{1}\\left(2 y^{5}-2 y^{3}-y\\right) d y=2 \\frac{y^{6}}{6}-2 \\frac{y^{4}}{4}-\\left.\\frac{y^{2}}{2}\\right|_{0} ^{1}=-\\frac{2}{3}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate $\\oint x d y-y d x$ around a circle $x^{2}+y^{2}=r^{2}$\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=4cm]{VI-Assignment-04}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\\intertext{\tLet $C$ denotes the circle. The parametric equations of circle is}\n\t\t&x=r \\cos \\theta \\\\\n\t\t&y=r \\sin \\theta\n\t\t\\intertext{Here, $x$ and $y$ have been expressed in terms of parameter which varies from 0 to $2 \\pi$ as one traverses the circle.}\n\t\tx&=r \\cos \\theta \\Rightarrow d x=-r \\sin \\theta d \\theta\\\\\n\t\ty&=r \\sin \\theta \\Rightarrow d y=r \\cos \\theta d \\theta\\\\\n\t\t x d y-y d x &=r \\cos \\theta r \\cos \\theta d \\theta-r \\sin \\theta(-r \\sin \\theta) d \\theta \\\\ &=r^{2} d \\theta \\\\\n\t\t\\text{ So,}\\quad\n\t\t \\oint_{c} x d y-y d x&=r^{2} \\oint d \\theta \\\\\n\t\t &=2 \\pi r^{2}\n\t\t \\intertext{Here, $r$ is a constant, because integral is carried over a circle.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Calculate the work done when a force $\\vec{F}=x y \\hat{i}+\\left(x^{2}+y^{2}\\right) \\hat{j}$ moves a particle in $x y$ plane from $(1,0)$ to $(3,8)$ along the curve $C, y=x^{2}-1$.\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]{VI-Assignment-05}\n\t\t\\end{figure}\n\t\tThe curve $C$ is $y=x^{2}-1$. Since, this is quadratic in $x$ and linear in $y$ with no $x y$ terms. This is a parabola. Let us put this parabola in the form\n\t\t\\begin{align*}\n\t\t(x-\\alpha)^{2} &=4 a(y-\\beta) \\\\ C:(x-0)^{2} &=(y+1) \n\t\t\\intertext{This is a parabola with vertex at $(0,-1)$ and axis parallel to $y$ axis.}\n\t\t\\intertext{On curve $C$, let us take $x$ as indepedent variable. The dependent variable $y$ can be written in terms of $x$ as}\n\t\t y &=x^{2}-1 \\\\ d y &=2 x d x \n\t\t \\intertext{work done is moving a particle by displacement $d \\vec{r}$}\n\t\t  d W &=\\vec{F} \\cdot d \\vec{r} \\\\ &=x y d x+\\left(x^{2}+y^{2}\\right) d y \\\\ &=x\\left(x^{2}-1\\right) d x+\\left(x^{2}+\\left(x^{2}-1\\right)^{2}\\right) 2 x d x \\\\ &=\\left(2 x^{5}-x^{3}+x\\right) d x \n\t\t  \\intertext{So, work done is moving a particle from $(1,0)$ to $(3,8)$ along a curve $C$.}\n\t\t   W &=\\int_{c} \\vec{F} \\cdot d \\vec{r}=\\int_{1}^{3}\\left(2 x^{5}-x^{3}+x\\right) d x \\\\ &=\\left.\\left(2 \\cdot \\frac{x^{6}}{6}-\\frac{x^{4}}{4}+\\frac{x^{2}}{2}\\right)\\right|_{1} ^{3}=227 \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate the line integral $\\int_{c} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=(x+2 y) \\hat{i}+(2 y-x) \\hat{j}$ and $C$ is curve in $x y$ plane consisting of the straight lines from $(0,0)$ to $(1,0)$ and then to $(3,4)$.\n\t\\begin{answer}\n\t\tThe curve $C$ consists of two pieces of smooth curves $C_{1}$ and\\\\ $C_{2}$. $C_{1}$ is straight line from $(0,0)$ to $(1,0)$ ie. $y=0$\\\\\n\t\t$C_{2}$ is straight line from $(1,0)$ to $(3,4)$\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=3.5cm]{VI-Assignment-06}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\text{i.e}.\\qquad \\quad y-0&=\\left(\\frac{4-0}{3-1}\\right) \\cdot(x-1)\\\\\n\t\t\\text{or, }\\qquad y&=2 x-2\\\\\n\t\t\\text{So, along }C_{1}, y&=0, d y=0 \\text{( $x$ is an independent variable )}\\\\\n\t\t\\vec{F} \\cdot d \\vec{r}&=x d x\\\\\n\t\\text{\tAlong }C_{2} ; y&=2 x-2, d y=2 d x\\text{ (let us take $x$ as independent variables).}\\\\\n\t\t\\vec{F} \\cdot d \\vec{r}&=(x+2 y) d x+(2 y-x) d y\\\\\n\t\\text{\ton }\\quad C_{2}, \\quad \\vec{F} \\cdot d \\vec{r} &=(x+2(2 x-2)) d x+(2(2 x-2)-x) \\cdot 2 d x \\\\ &=(11 x-12) d x \\\\\n\t\\text{So,}\\quad\n\t\\int_{c} \\vec{F} \\cdot d \\vec{r}&=\\int_{c_{1}} \\vec{F} \\cdot d \\vec{r}+\\int_{C_{2}} \\vec{F} \\cdot d \\vec{r}\\\\\n\t&=\\int_{0}^{1} x d x+\\int_{1}^{3}(11 x-12) d x\\\\\n\t&=\\left.\\frac{x^{2}}{2}\\right|_{0} ^{1}+\\left.\\left(\\frac{11}{2} x^{2}-12 x\\right)\\right|_{1} ^{3}\\\\\n\t&=20.5\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate $\\oint_{C} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=\\left(x^{2}+y^{2}\\right) \\hat{i}-2 x y \\hat{j}$, where curve $C$ is a rectangle in the $x y$ plane bounded by $y=0, x=a, y=b, x=0$.\n\t\\begin{answer}$\\left. \\right. $\n\t\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=4.6cm]{VI-Assignment-07}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{The curve $C$ as shown in figure $8.11$ consists of four pieces of smooth curves $C_{1}, C_{2}, C_{3} \\& C_{4}$. }\n\t\t\\vec{F} \\cdot d \\vec{r}&=\\left(x^{2}+y^{2}\\right) d x-2 x y d y\\\\\n\t\t\\text{On }C_{1}, y&=0, d y=0, \\vec{F} . d \\vec{r}=x^{2} d x\\\\\n\t\\text{\tOn }C_{2}, x&=a, d x=0, \\vec{F} \\cdot d \\vec{r}=-2 a y d y\\\\\n\t\t\\text{On }C_{3}, y&=b, d y=0, \\vec{F} \\cdot d \\vec{r}=\\left(x^{2}+b^{2}\\right) d x\\\\\n\t\t\\text{On }C_{4}, x&=0, d x=0, \\vec{F} . d \\vec{r}=0\\\\\n\t\t\\oint \\vec{F} \\cdot d \\vec{r}&=\\int_{C_{1}} \\vec{F} \\cdot d \\vec{r}+\\int_{C_{2}} \\vec{F} \\cdot d \\vec{r}+\\int_{C_{3}} \\vec{F} \\cdot d \\vec{r}+\\int_{C_{4}} \\vec{F} \\cdot d \\vec{r}\\\\\n\t\t&=\\int_{0}^{a} x^{2} d x+\\int_{0}^{b}-2 a y d y+\\int_{a}^{0}\\left(x^{2}+b^{2}\\right) d x+\\int_{b}^{0} 0 . d y\\\\\n\t\t&=\\left.\\frac{x^{3}}{3}\\right|_{0} ^{a}+\\left[-a y^{2}\\right]_{0}^{b}+\\left[\\frac{x^{3}}{3}+b^{2} x\\right]_{a}^{0}\\\\\n\t\t&=\\frac{a^{3}}{3}-a b^{2}-\\frac{a^{3}}{3}-a b^{2}\\\\\n\t\t&=-2 a b^{2}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Find the total work done in moving a particles in a force field given by $\\vec{F}=3 x y \\hat{i}-5 z \\hat{j}+10 x \\hat{k}$ along the curve $x=t^{2}+1, y=2 t^{2}, z=t^{3}$ from $t=1$ to $t=2$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\intertext{On curve $C$, the coordinates $x, y, z$ are expressed in terms of parameter $t$.}\n\t\t&x=t^{2}+1, d x=2 t d t \\\\\n\t\t&y=2 t^{2}, d y=4 t d t \\\\\n\t\t&z=t^{3}, d z=3 t^{2} d t\\\\\n\t\tt\\text{ varies from }t&=1\\text{ to }t=2.\\\\\n\t\t \\vec{F} \\cdot d \\vec{r} &=3 x y d x-5 z d y+10 x d z \\\\ &=3\\left(t^{2}+1\\right) \\cdot 2 t^{2} \\cdot 2 t d t-5 t^{3} 4 t d t+10\\left(t^{2}+1\\right) \\cdot 3 t^{2} d t \\\\ &=\\left(12 t^{5}+10 t^{4}+12 t^{3}+30 t^{2}\\right) d t \\\\\n\t\t \\text{So, total}&\\text{ work done,}\\\\\n\t\t  W &=\\int_{C} \\vec{F} \\cdot d \\vec{r} \\\\ &=\\int_{1}^{2}\\left(12 t^{5}+10 t^{4}+12 t^{3}+30 t^{2}\\right) d t \\\\ &=\\left.\\left(12 \\frac{t^{6}}{6}+10 \\frac{t^{5}}{5}+12 \\frac{t^{4}}{4}+30 \\frac{t^{3}}{3}\\right)\\right|_{1} ^{2} \\\\ &=303 \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \n\tFind the work done in moving a particle once around a circle $C$ in the $x y$ plane if the circle has a centre at the origin and radius 2 and if the force field $\\vec{F}$ is given by\n\t$$\\vec{F}=(2 x-y+2 z) \\hat{i}+(x+y-z) \\hat{j}+(3 x-2 y-5 z) \\hat{k}$$\n\t\\begin{answer}\tEquation of circle as shown in figure $8.12$ is written in parametric form as\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.8cm,width=4cm]{VI-Assignment-08}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\tx&=2 \\cos \\theta \\Rightarrow d x=-2 \\sin \\theta d \\theta\\\\\n\t\ty&=2 \\sin \\theta  \\Rightarrow d y=2 \\cos \\theta d \\theta \\\\ z&=0  \\Rightarrow d z=0\n\t\t\\intertext{$x, y, z$ are expressed in terms of parameter $\\theta$.}\n\t \\vec{F} \\cdot d \\vec{r}=&(2 x-y+2 z) d x+(x+y-z) d y+(3 x-2 y-5 z) d z \\\\=&(4 \\cos \\theta-2 \\sin \\theta)(-2 \\sin \\theta) d \\theta \\\\ & \\quad+(2 \\cos \\theta+2 \\sin \\theta)(6 \\cos \\theta-4 \\sin \\theta) .0 \\\\=&(4-4 \\sin \\theta \\cos \\theta) d \\theta \\\\\n\t \\text{$\\theta$ varies from 0 to $2 \\pi$}&\\\\\n\t \\text{So, total work done}&\\\\\n\t  W &=\\int_{0}^{2 \\pi}(4-4 \\sin \\theta \\cos \\theta) d \\theta \\\\ &=4 \\theta-\\left.2 \\sin ^{2} \\theta\\right|_{0} ^{2 \\pi} \\\\ &=8 \\pi \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If $\\vec{F}=\\left(3 x^{2}+6 y\\right) \\hat{i}-14 y z \\hat{j}+20 x z^{2} \\hat{k}$. Evaluate $\\int \\vec{F} \\cdot d \\vec{r}$ where $C$ is a straight line joining $(0,0,0)$ to $(1,1,1)$.\n\t\\begin{answer}\n\t\tEquation of straight line joining $(0,0,0)$ to $(1,1,1)$ is given by $\\frac{x-0}{1-0}=\\frac{y-0}{1-0}=\\frac{z-0}{1-0}=t$, where $t$ is parameter.\n\t\t\\begin{align*}\n\t\t\\intertext{In parametric form, equation of curve is given by}\n\t\tx&=t \\Rightarrow d x=d t\\\\\n\t\ty&=t \\Rightarrow d y=d t\\\\\n\t\tz&=t \\Rightarrow d z=d t\n\t\t\\intertext{$t$ varies from 0 to 1 .}\n\t\t \\vec{F} \\cdot d \\vec{r} &=\\left(3 x^{2}+6 y\\right) d x-14 y z d y+20 x z^{2} d z \\\\ &=\\left(20 t^{3}-11 t^{2}+6 t\\right) d t \\\\ \\int_{C} \\vec{F} \\cdot d \\vec{r} &=\\int_{0}^{1}\\left(20 t^{3}-11 t^{2}+6 t\\right) d t \\\\ &=\\left.\\left(5 t^{4}-\\frac{11}{3} t^{3}+3 t^{2}\\right)\\right|_{0} ^{1} \\\\ &=\\frac{13}{3} \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Integrate the function $\\vec{F}=x^{2} \\hat{i}-x y \\hat{j}$ from the point $(0,0)$ to $(1,1)$ along the parabola $y^{2}=x$.\n\t\\begin{answer}\n\t\tHere the curve $C$ is parabola $y^{2}=x$ as shown in figure 8.13. On $C, y$ can be taken as independent variable.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=4cm]{VI-Assignment-09}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\intertext{The dependent variable $x$ can be written in terms of $y$ as}\n\t\tx&=y^{2}\\\\\n\t\td x&=2 y d y\\\\\n\t\t \\vec{F} \\cdot d \\vec{r} &=x^{2} d x-x y d y \\\\ &=y^{4} \\cdot 2 y d y-y^{2} \\cdot y d y \\\\ &=\\left(2 y^{5}-y^{3}\\right) d y \n\t\t \\text{So, the line integral}\\\\\n\t\t \\int_{C} \\vec{F} \\cdot d \\vec{r} &=\\int_{0}^{1}\\left(2 y^{5}-y^{3}\\right) d y \\\\ &=\\frac{1}{3} y^{6}-\\left.\\frac{1}{4} y^{4}\\right|_{0} ^{1}=\\frac{1}{12} \n\t\t\\end{align*}\n\t\\end{answer}\n\\item Find the value of $\\int_{C}\\left[\\left(x+y^{2}\\right) d x+\\left(x^{2}-y\\right) d y\\right]$ taken in the counter-clockwise sense along the closed curve $C$ formed by $y^{3}=x^{2}$ and the straight line $y=x$.\n\\begin{answer}\n\tThe curve $C$ consists of chord $O A$ and curved part $A O$ as shown in figure 8.14.\\\\\n\tEquation of $O A$ is $y=x$ and curved part is $y^{3}=x^{2}$.\\\\\n\tAlong chord $O A, x$ can be taken as independent variable and $y=x$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4cm]{VI-Assignment-10}\n\t\\end{figure}\n\t\\begin{align*}\n\t \\vec{F} \\cdot d \\vec{r} &=\\left(x+y^{2}\\right) d x+\\left(x^{2}-y\\right) d y \\\\ &=\\left(x+x^{2}\\right) d x+\\left(x^{2}-x\\right) d x \\\\ &=2 x^{2} d x \n\t \\intertext{Along $O A, x$ varies from 0 to 1 . On curved part $A O$, let $y$ be taken as independent variable $\\&$ dependent variable $x$ can be put as}\n\t x&=y^{3 / 2}, d x=\\frac{3}{2} y^{1 / 2} d y\\\\\n\t  \\vec{F} \\cdot d \\vec{r} &=\\left(x+y^{2}\\right) d x+\\left(x^{2}-y\\right) d y \\\\ &=\\left(y^{3 / 2}+y^{2}\\right) \\frac{3}{2} y^{1 / 2} d y+\\left(y^{3}-y\\right) d y \\\\ &=\\left(y^{3}+\\frac{3}{2} y^{5 / 2}+\\frac{3}{2} y^{2}-y\\right) d y \\\\\n\t  \\text{$y$ varies from 1 to $0 .$}\\\\\n\t  \\oint_{C} \\vec{F} \\cdot d \\vec{r}&=\\int_{C_{1}} \\vec{F} \\cdot d \\vec{r}+\\int_{C_{2}} \\vec{F} \\cdot d \\vec{r}\\\\\n\t  &=\\int_{0}^{1} 2 x^{2} d x+\\int_{1}^{0}\\left(y^{3}+\\frac{3}{2} y^{5 / 2}+\\frac{3}{2} y^{2}-y\\right) d y\\\\\n\t  &=\\left.\\frac{2}{3} x^{3}\\right|_{0} ^{1}+\\frac{1}{4} y^{4}+\\frac{3}{7} y^{7 / 2}+\\frac{1}{2} y^{3}-\\left.\\frac{1}{2} y^{2}\\right|_{1} ^{0}\\\\\n\t  &=-\\frac{1}{84}\n\t  \\intertext{\n\t  \tNote:- If the integral is carried out in clockwise direction. The answer will differ only in sign. $\\oint_{C} \\vec{F} \\cdot d \\vec{r}$ in clockwise direction $=\\frac{1}{84}$}\n\t\\end{align*}\n\\end{answer}\n\\item Calculate $\\int_{C} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=\\frac{y^{2}}{x^{2}+y^{2}} \\hat{i}-\\frac{x^{2}}{x^{2}+y^{2}} \\hat{j}$, where $C$ is the semi-circle $y=\\sqrt{a^{2}-x^{2}}$.\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=5cm]{VI-Assignment-11}\n\t\\end{figure}\n\tThe curve $C$ shown in Figure $8.15$ is the semi-circle\n\t\\begin{align*}\n\ty&=\\sqrt{a^{2}-x^{2}}\n\t\\intertext{The equation can be written in parametric form as}\n\tx&=a \\cos \\theta \\Rightarrow d x=-a \\sin \\theta d \\theta\\\\\n\ty&=a \\sin \\theta \\Rightarrow d y=a \\cos \\theta d \\theta\n\t\\intertext{$\\theta$ varies from 0 to $\\pi$.}\n\t\\vec{F} \\cdot d \\vec{r}&=\\frac{y^{2} d x-x^{2} d y}{x^{2}+y^{2}}\\\\\n\t&=\\frac{a^{2} \\sin ^{2} \\theta(-a \\sin \\theta) d \\theta-\\left(a^{2} \\cos ^{2} \\theta\\right) a \\cos \\theta d \\theta}{a^{2}}\\\\\n\t&=-a\\left(\\sin ^{3} \\theta+\\cos ^{3} \\theta\\right) d \\theta\\\\\n\t\\int_{C} \\vec{F} \\cdot d \\vec{r}&=-a \\int_{0}^{\\pi}\\left(\\sin ^{3} \\theta+\\cos ^{3} \\theta\\right) d \\theta\\\\\n\t&=-a \\int_{0}^{\\pi} \\sin ^{3} \\theta d \\theta-a \\int_{0}^{\\pi} \\cos ^{3} \\theta d \\theta\\\\\n\t&=-2 a \\int_{0}^{\\pi / 2} \\sin ^{3} \\theta d \\theta-0\\left(\\right.\n\t\\text{ Since, }\\left.\\int_{0}^{\\pi} \\cos ^{3} \\theta d \\theta=0\\right)\\\\\n\t&=-2 a \\frac{\\sqrt{2} \\sqrt{1 / 2}}{2 \\cdot \\sqrt{5 / 2}}\\\\\n\t&=-\\frac{4 a}{3}\n\t\\end{align*}\n\\end{answer}\n\\item Evaluate $\\int_{C} \\frac{d x}{x+y}$ where $C$ is the curve $y^{2}=4 a x$ from $(0,0)$ to $(4 a, 4 a)$.\n\\begin{answer}\n\tThe equation of curve (as shown in the figure 8.16) can be written in parametric form as\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.7cm,width=3.5cm]{VI-Assignment-12}\n\t\\end{figure}\n\t\\begin{align*}\n\tx&=a t^{2} \\Rightarrow d x=2 a t d t\\\\\n\ty&=2 a t \\Rightarrow d y=2 a d t\n\t\\intertext{Parameter, $t$ varies from 0 to 2 .}\\\\\n\t\\text{The integral}\\\\\n\t \\int_{0} \\frac{d x}{x+y} &=\\int_{0}^{2} \\frac{2 a t d t}{a t^{2}+2 a t}=2 \\int_{0}^{2} \\frac{d t}{t+2}=\\left.2 \\log (t+2)\\right|_{0} ^{2} \\\\ &=2 \\log 2 \n\t\\end{align*}\n\\end{answer}\n\\item Evaluate $\\int_{C}(y d x-x d y)$, where $C$ is arc of cycloid $x=2(\\theta-\\sin \\theta), y=2(1-\\cos \\theta)$ joining the points $(0,0)$ and $(4 \\pi, 0)$.\n\\begin{answer}\n\t\tThe parametric equation of curve $C$ as shown in figure $8.17$ is given as\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=5cm]{VI-Assignment-13}\n\t\t\\end{figure}\n\t\\begin{align*}\n\tx&=2(\\theta-\\sin \\theta) \\Rightarrow d x=2(1-\\cos \\theta) d \\theta \\\\\n\ty&=2(1-\\cos \\theta) \\Rightarrow d y=2 \\sin \\theta d \\theta\n\t\\intertext{$\\theta$ is the parameter since $(x, y)$ varies from $(0,0)$ to $(4 \\pi, 0)$. So, $\\theta$ will vary from 0 to $2 \\pi$.\n\t\tThe integrand $y d x-x d y$}\n\t&=2(1-\\cos \\theta) \\cdot 2(1-\\cos \\theta) d \\theta-2(\\theta-\\sin \\theta) \\cdot 2 \\sin \\theta d \\theta\\\\\n\t&=4(2-2 \\cos \\theta-\\theta \\sin \\theta)\\\\\n\\text{\tSo,}\\quad\n\t\\int_{C} y d x-x d y&=4 \\int_{0}^{2 \\pi}(2-2 \\cos \\theta-\\theta \\sin \\theta) d \\theta\\\\\n\t&=8 \\int_{0}^{2 \\pi} d \\theta-8 \\int_{0}^{2 \\pi} \\cos \\theta d \\theta-4 \\int_{0}^{2 \\pi} \\theta \\sin \\theta d \\theta\\\\\n\t&=16 \\pi-8[\\sin \\theta]_{0}^{2 \\pi}-4[-\\theta \\cos \\theta+\\sin \\theta]_{0}^{2 \\pi}\\\\\n\t&=24 \\pi\n\t\\end{align*}\n\\end{answer}\n\\item Evaluate $\\int_{C} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=(2 a-y) \\hat{i}-(a-y) \\hat{j}$ where $C$ is the arc of the cycloid $x=a(\\theta-\\sin \\theta)$, $y=a(1-\\cos \\theta)$ from $(0,0)$ to $(2 \\pi a, 0)$.\n\\begin{answer}\n\tThe equation of cycloid is written in parametric form as\n\t\\begin{align*}\n\tx&=a(\\theta-\\sin \\theta) \\Rightarrow d x=a(1-\\cos \\theta) d \\theta\\\\\n\ty&=a(1-\\cos \\theta) \\Rightarrow d y=a \\sin \\theta d \\theta\n\t\\intertext{where $\\theta$ is the parameter varying from 0 to $2 \\pi$.}\n\\text{\tOn $C:$}\n\t\\vec{F} \\cdot d \\vec{r} &=(2 a-y) d x-(a-y) d y \\\\\n\t&=a(1+\\cos \\theta) \\cdot a(1-\\cos \\theta) d \\theta-a \\cos \\theta \\cdot a \\sin \\theta d \\theta \\\\\n\t&=a^{2}\\left(1-\\cos ^{2} \\theta-\\sin \\theta \\cos \\theta\\right) d \\theta\n\t\\intertext{So, the line integral}\n\t \\int_{C} \\vec{F} \\cdot d \\vec{r} &=a^{2} \\int_{0}^{2 \\pi}\\left(1-\\cos ^{2} \\theta-\\sin \\theta \\cos \\theta\\right) d \\theta \\\\ &=a^{2} \\int_{0}^{2 \\pi} d \\theta-a^{2} \\int_{0}^{2 \\pi} \\cos ^{2} \\theta d \\theta-a^{2} \\int_{0}^{2 \\pi} \\sin \\theta \\cos \\theta d \\theta \\\\ &=\\pi a^{2} \n\t\\end{align*}\n\\end{answer}\n\\item Evaluate $\\int_{C} \\frac{x^{2} d y-y^{2} d x}{x^{5 / 3}+y^{5 / 3}}$\nwhere $C$ is the quarter of the astroid $x=a \\cos ^{3} t, y=a \\sin ^{3} t$ from the point $(a, 0)$ to the point $(0, a)$.\n\\begin{answer}\n\tThe parametric equation of the astroid as shown in figure $8.18$ is given as\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=4cm]{VI-Assignment-14}\n\t\\end{figure}\n\t\\begin{align*}\n\tx&=a \\cos ^{3} t \\Rightarrow d x=-3 a \\cos ^{2} t \\sin t d t\\\\\n\ty&=a \\sin ^{3} t \\Rightarrow d y=3 a \\sin ^{2} t \\cos t d t\n\t\\intertext{$(x, y)$ varies from $(a, 0)$ to $(0, a)$.}\n\t\\intertext{So, $t$ varies from 0 to $\\pi / 2$.}\n\t\\text{The integrand }&\\frac{x^{2} d y-y^{2} d x}{x^{5 / 3}+y^{5 / 3}}\\\\\n\t&=\\frac{a^{2} \\cos ^{6} t\\left(3 a \\sin ^{2} t \\cos t\\right) d t-\\left(a^{2} \\sin ^{6} t\\right) \\cdot\\left(-3 a \\cos ^{2} t \\sin t\\right) d t}{a^{5 / 3}\\left(\\cos ^{5} t+\\sin ^{5} t\\right)}\\\\\n\t&=3 a^{4 / 3} \\sin ^{2} t \\cos ^{2} t d t\n\t\\intertext{The line integral reduces to}\n\t3 a^{4 / 3} \\int_{0}^{\\pi / 2} \\sin ^{2} t \\cos ^{2} t d t&=3 a^{4 / 3} \\frac{\\sqrt{3 / 2 / 3 / 2}}{2 \\sqrt{3}}=\\frac{3 \\pi a^{4 / 3}}{16}\n\t\\end{align*}\n\\end{answer}\n\\item Find the value of $\\int_{c}\\left(x^{2}+y^{2}\\right) d y$ taken in the counter clockwise sense along the quadrilateral with vertices $(0,0),(2,0),(4,4),(0,4)$.\n\\begin{answer}\n\tThe quadirlateral as shown in Figure $8.19$ consists of four pieces of smooth curves $A B, B C, C D $\\&$ D A$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4cm]{VI-Assignment-15}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\text{On }A B, y&=0, d y=0,\\left(x^{2}+y^{2}\\right) d y=0\\\\\n\t y &=2 x-4, d y=2 d x \\\\\\left(x^{2}+y^{2}\\right) d y &=\\left(x^{2}+(2 x-4)^{2}\\right) 2 d x \\\\ &=\\left(10 x^{2}-32 x+32\\right) d x \\\\\n\t \\text{$x$ varies from 2 to 4}\\\\\n\t \\text{On CD, }y&=4, d y=0\\\\\n\t \\left(x^{2}+y^{2}\\right) d y=0\\\\\n\t \\text { On  D A, }x&=0, d x=0\\\\\n\t \\left(x^{2}+y^{2}\\right) d y&=y^{2} d y\\\\\n\t \\text{$y$ varies from 4 to 0}\\\\\n\t\\text{ So, the line integral}\\\\\n\t \\int_{C}\\left(x^{2}+y^{2}\\right) d y &=\\int_{A B}\\left(x^{2}+y^{2}\\right) d y+\\int_{B C}\\left(x^{2}+y^{2}\\right) d y+\\int_{C D}\\left(x^{2}+y^{2}\\right) d y+\\int_{D A}\\left(x^{2}+y^{2}\\right) d y \\\\ &=0+\\int_{2}^{4}\\left(10 x^{2}-32 x+32\\right) d x+0+\\int_{4}^{0} y^{2} d y \\\\ &=\\left.\\left(\\frac{10}{3} x^{3}-16 x^{2}+32 x\\right)\\right|_{2} ^{4}+\\left.\\frac{y^{3}}{3}\\right|_{4} ^{0} \\\\ &=\\frac{112}{3} \n\t\\end{align*}\n\\end{answer}\n\\item  Evaluate $\\int_{C} x y^{2} d y-x^{2} y d x$ taken in the counter clockwise sense along the cardioid $r=a(1+\\cos \\theta)$\n\\begin{answer}\n\tThe curve $C$ as shown in figure $8.20$ cardiod whose equation is\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{VI-Assignment-16}\n\t\\end{figure}\n\t\\begin{align*}\n\tr&=a(1+\\cos \\theta)\\\\\n\tx&=r \\cos \\theta=a(1+\\cos \\theta) \\cos \\theta=a\\left(\\cos \\theta+\\cos ^{2} \\theta\\right)\\\\\n\td x&=a(-\\sin \\theta-2 \\cos \\theta \\sin \\theta) d \\theta\\\\\n\ty &=r \\sin \\theta=a(1+\\cos \\theta) \\sin \\theta=a(\\sin \\theta+\\sin \\theta \\cos \\theta) \\\\ d y &=a\\left(\\cos \\theta+\\cos ^{2} \\theta-\\sin ^{2} \\theta\\right) d \\theta \\\\\n\t\\text{The integrand}&\\\\\n\t\\left(x y^{2} d y-x^{2} y d x\\right)&\\\\\n\t&=r^{3} \\cos \\theta \\sin ^{2} \\theta a\\left(\\cos \\theta+\\cos ^{2} \\theta-\\sin ^{2} \\theta\\right) d \\theta\\\\\n\t&\\quad \\quad-r^{3} \\cos ^{2} \\theta \\sin \\theta a(\\sin \\theta-2 \\cos \\theta \\sin \\theta) d \\theta\\\\\n\t&=a r^{2} \\cos \\theta \\sin ^{2} \\theta\\left(\\cos \\theta+\\cos ^{2} \\theta-\\sin ^{2} \\theta+\\cos \\theta+2 \\cos ^{2} \\theta\\right) d \\theta\\\\\n\t&=a^{4}(1+\\cos \\theta)^{3} \\cos \\theta \\sin ^{2} \\theta\\left(4 \\cos ^{2} \\theta+2 \\cos \\theta-1\\right) d \\theta\\\\\n\t&=a^{4}\\left[\\cos ^{6} \\theta \\sin ^{2} \\theta+14 \\cos ^{5} \\theta \\sin ^{2} \\theta+17 \\cos ^{4} \\theta \\sin ^{2} \\theta\\right.\\\\\n\t&\\left.\\quad+7 \\cos ^{3} \\theta \\sin ^{2} \\theta-\\cos ^{2} \\theta \\sin ^{2} \\theta-\\cos \\theta \\sin ^{2} \\theta\\right]\\\\\n\t\\text{The line integral}&\\\\\n\t\\oint\\left(x y^{2} d y-x^{2} y d x\\right)&\\\\\n\t&=a^{4} \\int_{0}^{2 \\pi}\\left(\\cos ^{6} \\theta \\sin ^{2} \\theta+14 \\cos ^{5} \\theta \\sin ^{2} \\theta+17 \\cos ^{4} \\theta \\sin ^{2} \\theta+7 \\cos ^{3} \\theta \\sin ^{2} \\theta\\right.\\\\\n\t&\\quad \\left.-\\cos ^{2} \\theta \\sin ^{2} \\theta-\\cos \\theta \\sin ^{2} \\theta\\right) d \\theta\\\\\n\t&=\\frac{35}{16} a^{4} \\pi\n\t\\end{align*}\n\\end{answer}\n\\item A particle moves counterclockwise along the curve $3 x^{2}+y^{2}=3$ from $(1,0)$ to a point $P$, under the action of the force\n$$\n\\vec{F}(x, y)=\\frac{x}{y} \\hat{i}+\\frac{y}{x} \\hat{j} .\n$$\nProve that there are two possible locations of $P$ such that the work done by $\\vec{F}$ is 1 .\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=4cm]{VI-Assignment-17}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\frac{x^{2}}{1}+\\frac{y^{2}}{3}&=1\n\t\\intertext{Point on ellipse is represented as}\n\t(\\cos \\theta, \\sqrt{3} \\sin \\theta)&\\\\\n\t \\int \\vec{F} \\cdot d \\vec{r} &=\\int\\left(\\frac{x}{y} \\hat{i}+\\frac{y}{x} \\hat{j}\\right) \\cdot(d x \\hat{i}+d y \\hat{j}) \\\\ &=\\int \\frac{x}{y} d x+\\frac{y}{x} d y \\\\ &=\\int_{0}^{\\theta} \\frac{\\cos \\theta}{\\sqrt{3} \\sin \\theta}(-\\sin \\theta) d \\theta+\\frac{\\sqrt{3} \\sin \\theta}{\\cos \\theta} \\cdot \\sqrt{3} \\cos \\theta d \\theta \\\\ &=\\int_{0}^{\\theta}\\left(-\\frac{1}{\\sqrt{3}} \\cos \\theta+3 \\sin \\theta\\right) d \\theta \\\\ &=-\\frac{1}{\\sqrt{3}} \\sin \\theta-\\left.3 \\cos \\theta\\right|_{0} ^{\\theta} \\\\ &=-\\frac{1}{\\sqrt{3}} \\sin \\theta-3 \\cos \\theta+3 \n\t \\intertext{Work done in equal to 1}\n\t \\mathrm{So},&-\\frac{1}{\\sqrt{3}} \\sin \\theta-3 \\cos \\theta+3=1\\\\\n\t \\Rightarrow &\\quad \\frac{1}{\\sqrt{3}} \\sin \\theta+3 \\cos \\theta=2\\\\\n\t \\Rightarrow &\\quad\\left(\\frac{1}{\\sqrt{3}} \\sin \\theta\\right)^{2}=(2-3 \\cos \\theta)^{2}\\\\\n\t \\Rightarrow &\\quad \\frac{1}{3} \\sin ^{2} \\theta=4+9 \\cos ^{2} \\theta-12 \\cos \\theta\\\\\n\t \\Rightarrow &\\quad 28 \\cos ^{2} \\theta-36 \\cos \\theta+11=0\\\\\n\t \\Rightarrow &\\quad(2 \\cos \\theta-1)(14 \\cos \\theta-11)=0\\\\\n\t \\quad \\cos \\theta&=\\frac{1}{2}, \\frac{11}{14}\n\t \\intertext{So, there are two value of $\\theta$ i.e., two possible location of $P$ such that the work done by $\\vec{F}$ is 1 .}\n\t\\end{align*}\n\\end{answer}\n\\item Find the circulation of the field\n$$\n\\vec{F}=-x^{2} y \\hat{i}+x y^{2} \\hat{j}+\\left(y^{3}-x^{3}\\right) \\hat{k}\n$$\naround the curve $C$, where $C$ is the intersection of the sphere $x^{2}+y^{2}+z^{2}=25$ and the plane $z=3$. The orientation of the curve $C$ is counterclockwise when viewed from above.\n\\begin{answer}$\\left. \\right. $\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5.2cm]{VI-Assignment-18}\n\t\\end{figure}\n\t\\begin{align*}\n\t\\vec{F}&=-x^{2} y \\hat{i}+x y^{2} \\hat{j}+\\left(y^{3}-x^{3}\\right) \\hat{k}\n\\intertext{\t$C$ is the curve of intersection of surfaces}\n\tx^{2}+y^{2}+z^{2}&=25, z=3\\\\\n\t\\text{So, }\\quad x^{2}+y^{2}&=16\\\\\n\t\\vec{F} \\cdot d \\vec{r}&=x^{2} y d x+x y^{2} d y+\\left(y^{3}-x^{3}\\right) d z\\\\\n\t\\text{For curve }C, z&=3, d z=0\\\\\n\t\\oint \\vec{F} \\cdot d \\vec{r}&=\\int-x^{2} y d x+x y^{2} d y\\\\\n\t\\text{Let }x&=4 \\cos \\theta, y=4 \\sin \\theta\\\\\n\t \\oint \\vec{F} \\cdot d \\vec{r} &=\\int_{0}^{2 \\pi}\\left(256 \\cos ^{2} \\theta \\sin ^{2} \\theta d \\theta+256 \\cos ^{2} \\theta \\sin ^{2} \\theta\\right) d \\theta \\\\ &=512 \\int_{0}^{2 \\pi} \\sin ^{2} \\theta \\cos ^{2} \\theta d \\theta \\\\ &=512 \\times 4 \\int_{0}^{\\pi / 2} \\sin ^{2} \\theta \\cos ^{2} \\theta d \\theta \\\\ &=2048 \\frac{\\sqrt{3 / 2} \\sqrt{3 / 2}}{2 \\sqrt{3}}=128 \\pi \n\t\\end{align*}\n\\end{answer}\n\\item If $\\phi=2 x^{2} y z, \\vec{F}=x y \\hat{i}-z^{2} y \\hat{j}+x^{2} \\hat{k}$ and $C$ is the curve $x=2 t, y=t^{2}, z=t^{3}$ from $t=0$ and $t=1$. Evaluate the line integrals (a) $\\int_{C} \\phi d \\vec{r}$ (b) $\\int_{C} \\vec{F} \\times d \\vec{r}$.\n\\begin{answer}\n\t\\begin{align*}\n\\text{\t(a)\\quad Along }C, \\phi&=2 x^{2} y z=2(2 t)^{2} \\cdot t^{2} \\cdot t^{3}=8 t^{7}\\\\\n\t\\vec{r} &=x \\hat{i}+y \\hat{j}+z \\hat{k} \\\\\n\t&=2 t \\hat{i}+t^{2} \\hat{j}+t^{3} \\hat{k} \\\\\n\td \\vec{r} &=\\left(2 \\hat{i}+2 \\hat{j}+3 t^{2} \\hat{k}\\right) d t \\\\\n\t\\int_{C} \\phi d \\vec{r} &=\\int_{0}^{1} 8 t^{7}\\left(2 \\hat{i}+2 t \\hat{j}+3 t^{2} \\hat{k}\\right) d t \\\\\n\t&=\\hat{i}_{0}^{1} 16 t^{7} d t+\\hat{j}_{0}^{1} 16 t^{8} d t+\\hat{k} \\int_{0}^{1} 24 t^{9} d t \\\\\n\t&=2 \\hat{i}+\\frac{16}{9} \\hat{j}+\\frac{12}{5} \\hat{k}\\\\\\\\\n\t\\text{(b)\\quad Along }C, \\vec{F}&=x y \\hat{i}-z^{2} y \\hat{j}+x^{2} \\hat{k}\\\\\n\t&=2 t^{3} \\hat{i}-t^{8} \\hat{j}+4 t^{2} \\hat{k} \\\\\n\t\\vec{F} \\times d \\vec{r} &=\\left(2 t^{3} \\hat{i}-t^{8} \\hat{j}+4 t^{2} \\hat{k}\\right) \\times\\left(2 \\hat{i}+2 t \\hat{j}+3 t^{2} \\hat{k}\\right) \\\\\n\t&=\\left|\\begin{array}{ccc}\n\t\\hat{i} & \\hat{j} & \\hat{k} \\\\\n\t2 t^{3} & -t^{8} & 4 t^{2} \\\\\n\t2 & 2 t & 3 t^{2}\n\t\\end{array}\\right| \\\\\n\t&=\\left(-3 t^{10}-8 t^{3}\\right) \\hat{i}+\\left(8 t^{2}-6 t^{5}\\right) \\hat{j}+\\left(4 t^{4}+2 t^{8}\\right) \\hat{k} \\\\\n\t\\int_{C} \\vec{F} \\times d \\vec{r} &=\\hat{i}_{0}^{1}\\left(-3 t^{10}-8 t^{3}\\right) d t+\\hat{j} \\int_{0}^{1}\\left(8 t^{2}-6 t^{5}\\right) d t+\\hat{k} \\int_{0}^{1}\\left(4 t^{4}+2 t^{8}\\right) d t \\\\\n\t&=-\\frac{47}{11} \\hat{i}+\\frac{5}{3} \\hat{j}+\\frac{46}{45} \\hat{k}\n\t\\end{align*}\n\\end{answer}\n\\item Find the work done in moving the particle once round the ellipse $\\frac{x^{2}}{25}+\\frac{y^{2}}{16}=1, z=0$ under the field of force given by $\\vec{F}=(2 x+y+z) \\hat{i}+\\left(x+y-z^{2}\\right) \\hat{j}+(3 x-2 y+4 z) \\hat{k}$.\n\\begin{answer}\n\t\tWork done moving the particle by distance $d r$\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=3.5cm]{VI-Assignment-19}\n\t\t\\end{figure}\n\t\\begin{align*}\n\t\\vec{F} \\cdot d \\vec{r}&=(2 x+y+z) d x+\\left(x+y-z^{2}\\right) d y+(3 x-2 y+4 z) d z\\\\\n\t\\text{The curve $C$ is ellipse }&\\frac{x^{2}}{25}+\\frac{y^{2}}{16}=1\\\\\n\\text{\tThe equation  }&\\text{of ellipse is given by}x=5 \\cos \\theta, y=4 \\sin \\theta, z=0\\\\\nd x &=-5 \\sin \\theta d \\theta \\\\ d y &=4 \\cos \\theta d \\theta \\\\ d z &=0 \\\\ \\vec{F} \\cdot d \\vec{r} &=(10 \\cos \\theta+4 \\sin \\theta)(-5 \\sin \\theta) d \\theta+(5 \\cos \\theta+4 \\sin \\theta) 4 \\cos \\theta d \\theta \\\\ &=\\left(-34 \\sin \\theta \\cos \\theta+20 \\cos ^{2} \\theta-20 \\sin ^{2} \\theta\\right) d \\theta \n\\intertext{On $C, \\theta$ varies from 0 to $2 \\pi$}\n\\intertext{So, work done in moving a particle around the ellipse}\n\\text{So, }\\quad W&=\\oint \\vec{F} \\cdot d \\vec{r}\\\\\n&=\\int_{0}^{2 \\pi}\\left(-34 \\sin \\theta \\cos \\theta+20 \\cos ^{2} \\theta-20 \\sin ^{2} \\theta\\right) d \\theta\\\\\n&=-34 \\int_{0}^{2 \\pi} \\sin \\theta \\cos \\theta d \\theta+20 \\int_{0}^{2 \\pi} \\cos ^{2} \\theta d \\theta-20 \\int_{0}^{2 \\pi} \\sin ^{2} \\theta d \\theta \\\\\n&=0\n\t\\end{align*}\n\\end{answer}\n\\item Evaluate $\\int_{C} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=c\\left[-3 a \\sin ^{2} \\theta \\cos \\theta \\hat{i}+a\\left(2 \\sin \\theta-3 \\sin ^{2} \\theta\\right) \\hat{j}+b \\sin 2 \\theta \\hat{k}\\right]$ and the curve $C$ is given by $\\vec{r}=a \\cos \\theta \\hat{i}+a \\sin \\theta \\hat{j}+b \\theta \\hat{k}, \\theta$ varying from $\\frac{\\pi}{4}$ to $\\frac{\\pi}{2}$.\n\\begin{answer}\n\t\\begin{align*}\n\t \\vec{r} &=a \\cos \\theta \\hat{i}+a \\sin \\theta \\hat{j}+b \\theta \\hat{k} \\\\ d \\vec{r} &=(-a \\sin \\theta \\hat{i}+a \\cos \\theta \\hat{j}+b \\hat{k}) d \\theta \\\\ \\vec{F} \\cdot d \\vec{r} &=c\\left[3 a^{2} \\sin ^{3} \\theta \\cos \\theta+a^{2}\\left(2 \\sin \\theta-3 \\sin ^{2} \\theta\\right) \\cos \\theta+b^{2} \\sin 2 \\theta\\right] d \\theta \n\t \\intertext{The line integral}\n\t  \\int_{C} \\vec{F} \\cdot d \\vec{r} &=3 a^{2} c \\int_{\\pi / 4}^{\\pi / 2} \\sin ^{3} \\theta \\cos \\theta d \\theta+a^{2} c \\int_{\\pi / 4}^{\\pi / 2}\\left(2 \\sin \\theta-3 \\sin ^{2} \\theta\\right) \\cos \\theta d \\theta+b^{2} c \\int_{\\pi / 4}^{\\pi / 2} \\sin 2 \\theta d \\theta \\\\ &=3 a^{2} c\\left[\\frac{\\sin ^{4} \\theta}{4}\\right]_{\\pi / 4}^{\\pi / 2}+a^{2} c\\left[\\sin ^{2} \\theta-\\sin ^{3} \\theta\\right]_{\\pi / 4}^{\\pi / 2}-\\frac{b^{2} c}{2}[\\cos 2 \\theta]_{\\pi / 4}^{\\pi / 2} \\\\ &=\\frac{9}{16} a^{2} c+a^{2} c\\left[\\frac{1}{2}-\\frac{1}{2 \\sqrt{2}}\\right]+\\frac{b^{2} c}{2} \\\\ &=\\left(\\frac{17}{16}-\\frac{1}{2 \\sqrt{2}}\\right) a^{2} c+\\frac{b^{2} c}{2} \n\t\\end{align*}\n\\end{answer}\n\\end{enumerate}\n\\section{Green's Theorem}\n\\begin{enumerate}\n\t\\item Verify Green's theorem in the place for $\\oint_{C}\\left(x y+x^{2}\\right) d x+x^{2} d y$ where $C$ is the closed curve of the region \n\tbounded by $y=x$ and $x^{2}=4 a y$.\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=4.5cm]{GT-Assignment-01}\n\t\\end{figure}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\\text{\tHere }M d x&+N d y\\\\\n\t\t&=\\left(x y+x^{2}\\right) d x+x^{2} d y \\\\\n\t\tM&=x y+x^{2} \\Rightarrow \\frac{\\partial M}{\\partial y}=x \\\\\n\t\tN&=x^{2} \\quad \\Rightarrow \\frac{\\partial N}{\\partial x}=2 x\n\t\t\\intertext{Let us first evaluate the double integral over Region $R$ bounded by $x^{2}=4 a y$ (curve $\\left.C_{1}\\right) \\& y=x$ (curve $C_{2}$ ) as}\n\t \\iint\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y &=\\int_{0}^{4 a} \\int_{x^{2} / 4 a}^{x} x d y d x \\\\ &=\\int_{0}^{4 a} x\\left(x-\\frac{x^{2}}{4 a}\\right) d x=\\frac{x^{3}}{3}-\\left.\\frac{x^{4}}{16 a}\\right|_{0} ^{4 a}=\\frac{16 a^{3}}{3} \n\t \\intertext{Now let us evaluate the line integral $\\oint M d x+N d y$ on closed curve $C$. The curve $C$ is a piecewise smooth curve consisting of $C_{1}$ and $C_{2}$.}\n\t\\text{ On }C_{1}, y&=\\frac{x^{2}}{4 a}\\quad \n\t d y=\\frac{x}{2 a} d x\\\\\n\t M d x+N d y &=\\left(x y+x^{2}\\right) d x+x^{2} d y \\\\ &=\\left(\\frac{x^{3}}{4 a}+x^{2}\\right) d x+x^{2} \\frac{x}{2 a} d x \\\\ &=\\left(\\frac{3}{4} \\cdot \\frac{x^{3}}{a}+x^{2}\\right) d x \n\t \\intertext{$x$ varies from 0 to $4 a$ on $C_{1}$}\n\t\\text{ So,}\n\t \\int_{C_{1}} M d x+N d y&=\\int_{0}^{4 a}\\left(\\frac{3 x^{3}}{4 a}+x^{2}\\right) d x\\\\\n\t &=\\frac{3}{16 a} x^{4}+\\left.\\frac{x^{3}}{3}\\right|_{0} ^{4 a}\\\\\n\t &=8 a^{3}+\\frac{64 a^{3}}{3}=\\frac{208 a^{3}}{3}\\\\\n\t \\text{On }C_{2}, \\quad y&=x, d y=d x\\\\\n\t M d x+N d y &=\\left(x y+x^{2}\\right) d x+x^{2} d y \\\\ &=3 x^{2} d x \n\t \\intertext{$x$ varies from $4 a$ to 0 .}\n\t\\text{ So,}\n\t \\int_{C_{2}} M d x+N d y&=\\int_{4 a}^{0} 3 x^{2} d x\\\\\n\t &=\\left.x^{3}\\right|_{4 a} ^{0}=-64 a^{3}\\\\\n\t  \\text{so, }\\int_{C} M d x+N d y &=\\int_{C_{1}} M d x+N d y+\\int_{C_{2}} M d x+N d y \\\\ &=\\frac{208}{3} a^{3}-64 a^{3}=\\frac{16}{3} a^{3} \\\\\n\t \\text{ Since, }\n\t  \\iint_{R}\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y&=\\oint_{C} M d x+N d y\n\t \\intertext{ So, Green's theorem is verified.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item \tApply Green's theorem in the plane to evaluate $\\oint\\{(y-\\sin x) d x+\\cos x d y\\}$ where $C$ is the triangle enclosed by the lines $y=0, x=\\pi, \\pi y=2 x$.\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=4cm]{GT-Assignment-06}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\\text{\tHere, }\\quad M d x+N d y&=(y-\\sin x) d x+\\cos x d y\\\\\n\t\\text{So, }\\quad M&=y-\\sin x, \\quad \\frac{\\partial M}{\\partial y}=1\\\\\n\tN&=\\cos x, \\quad \\frac{\\partial N}{\\partial x}=-\\sin x\n\t\\intertext{According to Green's theorem}\n\t\\oint_{C} M d x+N d y&=\\iint_{R}\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y\n\t\\intertext{where $R$ is the region enclosed by the piecewise smooth curve $C$ consisting of curve $C_{1}(y=0)$, curve $C_{2}(x=\\pi)$ curve $C_{3}(\\pi y=2 x)$ as shown in Figure 9.4.}\n\t\\text{So, }\\quad \\iint\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y&=\\int_{0}^{2} \\int_{\\pi y / 2}^{\\pi}(-\\sin x-1) d x d y\\\\\n\t&=\\int_{0}^{2}[\\cos x-x]_{\\pi y / 2}^{\\pi} d y\\\\\n\t&=\\int_{0}^{2}\\left(-1-\\pi-\\cos \\frac{\\pi y}{2}+\\frac{\\pi y}{2}\\right) d y\\\\\n\t&=-(1+\\pi) y-\\frac{2}{\\pi} \\sin \\frac{\\pi y}{2}+\\left.\\frac{\\pi y^{2}}{4}\\right|_{0} ^{2}=-2-\\pi\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If $\\vec{F}=\\left(x^{2}-y^{2}\\right) \\hat{i}+2 x y \\hat{j}$ and $\\vec{r}=x \\hat{i}+y \\hat{j}$, find the value of $\\oint\\left(x^{2}-y^{2}\\right) d x+2 x y d y$ around the rectangular boundary $x=0, x=a, y=0$ and $y=b$.\n\t\\begin{answer}\n\t\tHere, the curve $C$ is a piecewise smooth curve consisting of $C_{1}(y=0), C_{2}(x=a), C_{3}(y=b) \\& C_{4}$ $(x=0)$.\\\\\n\t\tThe region bounded by $C$ is shown in figure $9.5$.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4cm,width=5.5cm]{GT-Assignment-03}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\oint \\vec{F} \\cdot d \\vec{r}&=\\oint\\left(x^{2}-y^{2}\\right) d x+2 x y d y=\\oint M d x+N d y\\\\\n\t\t\\text{Here, }M&=x^{2}-y^{2}, \\quad \\frac{\\partial M}{\\partial y}=-2 y\\\\\n\t\tN&=2 x y, \\quad \\frac{\\partial N}{\\partial x}=2 y\n\t\t\\intertext{Applying Green's theorem}\n\t\t \\oint M d x+N d y &=\\iint\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y \\\\ &=4 \\int_{0}^{b} \\int_{0}^{a} y d x d y=4 a \\int_{0}^{b} y d y \\\\ &=2 a b^{2} \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item  Evaluate $\\oint e^{-x} \\sin y d x+e^{-x} \\cos y d y$ by Green's theorem in plane where $C$ is the rectangle with vertices $(0,0),(\\pi, 0),(\\pi, \\pi / 2),(0, \\pi / 2)$.\n\t\\begin{answer}\n\t\tThe curve $C$ is a piecewise smooth curve consisting of $C_{1}(y=0), C_{2}(x=\\pi), C_{3}(y=\\pi / 2) \\& C_{4}(x=0)$. The region $R$ bounded by $C$ is as shown in figure.\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3.5cm,width=5.5cm]{GT-Assignment-02}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\oint_{C} M d x+N d y&=\\oint_{C} e^{-x} \\sin y d x+e^{-x} \\cos y d y\\\\\n\t\t\\text{Here }M&=e^{-x} \\sin y \\Rightarrow \\frac{\\partial M}{\\partial y}=e^{-x} \\cos y\\\\\n\t\tN&=e^{-x} \\cos y \\Rightarrow \\frac{\\partial N}{\\partial x}=-e^{-x} \\cos y\n\t\t\\intertext{Applying Green's theorem}\n\t\t \\oint M d x+N d y &=\\iint\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d y d x \\\\ &=-2 \\int_{0}^{\\pi / 2} \\int_{0}^{\\pi / 2} e^{-x} \\cos y d y d x \\\\ &=-2 \\int_{0}^{\\pi} e^{-x}[\\sin y]_{0}^{\\pi / 2} d x \\\\ &=-2 \\int_{0}^{\\pi} e^{-x} d x=\\left.2 e^{-x}\\right|_{0} ^{\\pi} \\\\ &=2\\left(e^{-\\pi}-1\\right) \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Let $\\vec{F}=\\left(x^{2}-x y^{2}\\right) \\hat{i}+y^{2} \\hat{j}$. Using Green's theorem, evaluate the line integral $\\int_{C} \\vec{F} \\cdot d \\vec{r}$, where $C$ is the positively oriented closed curve which is the boundary of the region enclosed by the $x$-axis and the semi-circle $y=\\sqrt{1-x^{2}}$ in the upper half plane.\n\t\\begin{answer}$\\left. \\right. $\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=5cm]{GT-Assignment-04}\n\t\t\\end{figure}\n\t\t\\begin{align*}\n\t\t\\vec{F}&=\\left(x^{2}-x y^{2}\\right) \\hat{i}+y^{2} \\hat{j}\\\\\n\t\t\\text{So}\\quad\\vec{F} \\cdot d \\vec{r}&=\\left(x^{2}-x y^{2}\\right) d x+y^{2} d y\n\t\t\\intertext{According to Green's theorem}\n\t\t\\oint_{C} \\vec{F} \\cdot d \\vec{r}&=\\iint_{R}\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y\n\t\t\\intertext{( $R$ is the region of integration shown in Figure )}\n\t\t&=\\int_{-1}^{\\sqrt{1-x^{2}}} \\int_{0}^{1} 2 x y d y d x\\\\\n\t\t&=\\int_{-1}^{1} x\\left[y^{2}\\right]_{0}^{\\sqrt{1-x^{2}}} d x\\\\\n\t\t&=\\int_{-1}^{1} x\\left(1-x^{2}\\right) d x=0 \\quad\\left(\\int_{-a}^{a} f(x)=0\\right.\\text{ if }f(x)\\text{ is odd function})\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate by Green's theorem $\\oint(\\cos x \\sin y-x y) d x+\\sin x \\cos y d y$ where $C$ is the circle $x^{2}+y^{2}=a^{2}$\n\t\\begin{answer}\n\t\tThe given integral is\n\t\t\\begin{align*}\n\t\t\\oint_{C}(\\cos x \\sin y-x y) d x&+\\sin x \\cos y d y\n\t\t\\intertext{Where curve $C$ is a circle of radius $a$ and centred at origin enclosing region $R$ as shown in Figure }\n\t\t\\text{Here }M=\\cos x \\sin y-x y \\Rightarrow \\frac{\\partial M}{\\partial y}&=\\cos x \\cos y-x\\\\\n\t\t N=\\sin x \\cos y \\quad \\Rightarrow \\frac{\\partial N}{\\partial x}&=\\cos x \\cos y\n\t\t \\intertext{Using Green's theorem}\n\t\t \\oint M d x+N d y&=\\iint_{R}\\left(\\frac{\\partial N}{\\partial x}-\\frac{\\partial M}{\\partial y}\\right) d x d y\n\t\t\\end{align*}\n\t\t\\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=4.2cm,width=4.5cm]{GT-Assignment-05}\n\t\t\\end{figure}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Conservative vector Field}\n\\begin{enumerate}\n\t\\item Evaluate $\\int_{C} \\vec{F} \\cdot d \\vec{r}$ where $\\vec{F}=y z \\hat{i}+z x \\hat{j}+x y \\hat{k}$ and $C$ is the portion of the curve $\\vec{r}=a \\cos t \\hat{i}+b \\sin t \\hat{j}+c t \\hat{k}$ from $t=0$ to $t=\\pi / 2$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t \\vec{F} \\cdot d \\vec{r} &=y z d x+z x d y+x y d z \\\\ &=d(x y z) \n\t\t \\intertext{$\\vec{F} \\cdot d \\vec{r}$ is an exact differential. So, $\\vec{F}$ is conservative.}\n\t\t  \\int_{C} \\vec{F} \\cdot d \\vec{r} &=\\int_{C} d(x y z) \\\\ &=[x y z]_{t=0}^{t=\\pi / 2}=[x y z]_{(a, 0,0)}^{(0, b, c r / 2)}=0 \n\t\t  \\intertext{Since, $t=0$ corresponds to point $(0,0,0)$ and $t=\\pi / 2$ corresponds to point $(a, b, \\pi / 2)$.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate $\\int_{C}\\left(2 x y^{3}-y^{2} \\cos x\\right) d x+\\left(1-2 y \\sin x+3 x^{2} y^{2}\\right) d y$ where $C$ is the arc of the parabola $2 x=\\pi y^{2}$ from $(0,0)$ to $(\\pi / 2,1)$.\n\t\\begin{answer}\n\t\tFirst let us check whether $\\left(2 x y^{3}-y^{2} \\cos x\\right) d x+\\left(1-2 y \\sin x+3 x^{2} y^{2}\\right) d y$ is an exact differential.\n\t\t\\begin{align*}\n\t\t\\text{We know that }M d x&+N d y\\text{ is an exact differential if }\\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}.\\\\\n\t\t\\text{Here}\\qquad M &=2 x y^{3}-y^{2} \\cos x \\\\ \\frac{\\partial M}{\\partial y} &=6 x y^{2}-2 y \\cos x \\\\ N &=1-2 y \\sin x+3 x^{2} y^{2} \\\\ \\frac{\\partial N}{\\partial x} &=-2 y \\cos x+6 x y^{2} \\\\\n\t\\text{\tThus,}\\qquad\n\t\t\\frac{\\partial M}{\\partial y}&=\\frac{\\partial N}{\\partial x}\\\\\n\t\t\\text{So, }M d x&+N d y\\text{ is exact.}\n\t\t\\end{align*}\n\t\tLet $M d x+N d y$ can be expressed as total differential of a scalar function $\\phi$\n\t\t\\begin{align}\n\t\t\\text{So}\\qquad d \\phi&=\\left(2 x y^{3}-y^{2} \\cos x\\right) d x+\\left(1-2 y \\sin x+3 x^{2} y^{2}\\right) d y\\notag\\\\\n\t\t\\Rightarrow \\quad \\frac{\\partial \\phi}{\\partial x} d x+\\frac{\\partial \\phi}{\\partial y} d y&=\\left(2 x y^{3}-y^{2} \\cos x\\right) d x+\\left(1-2 y \\sin x+3 x^{2} y^{2}\\right) d y\\notag\\\\\n\t\t\\frac{\\partial \\phi}{\\partial x}&=2 x y^{3}-y^{2} \\cos x\\notag\\\\\n\t\t\\Rightarrow\n\t\t\\phi&=\\int_{y=\\text { constant }}\\left(2 x y^{3}-y^{2} \\cos x\\right) d x=x^{2} y^{3}-y^{2} \\sin x\\label{VI-01}\\\\\n\t\t\\frac{\\partial \\phi}{\\partial y}&=1-2 y \\sin x+3 x^{2} y^{2}\\notag\\\\\n\t\t\\Rightarrow\n\t\t\\phi&=\\int_{x=\\text { constant }}\\left(1-2 y \\sin x+3 x^{2} y^{2}\\right) d y=y-y^{2} \\sin x+x^{2} y^{3}\\label{VI-02}\n\t\t\\intertext{Adding (\\ref{VI-01}) \\& (\\ref{VI-02}) while writing the common term once}\n\t\t\\phi&=y-y^{2} \\sin x-x^{2} y^{3}\\notag\n\t\t\\intertext{So, given integral}\n\t\t \\int_{C} M d x+N d y &=\\int d \\phi=\\phi \\notag\\\\ &=\\left[y-y^{2} \\sin x-x^{2} y^{3}\\right]_{(0,0)}^{(\\pi / 2,1)}=\\frac{\\pi^{2}}{4} \\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\item Evaluate $\\int_{C} 2 x y z^{2} d x+\\left(x^{2} z^{2}+z \\cos y z\\right) d y+\\left(2 x^{2} y z+y \\cos y z\\right) d z$ where $C$ is any path from $(0,0,1)$ to $(1, \\pi / 4,2)$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t2 x y z^{2} d x&+\\left(x^{2} z^{2}+z \\cos y z\\right) d y+\\left(2 x^{2} y z+y \\cos y z\\right) d z\\\\\n\t\t &=\\left[2 x y z^{2} \\hat{i}+\\left(x^{2} z^{2}+z \\cos y z\\right) \\hat{j}+\\left(2 x^{2} y z+y \\cos y z\\right) \\hat{k}\\right] \\cdot d \\vec{r} \\\\ \\text{Here}\\qquad \\vec{F} &=2 x y z^{2} \\hat{i}+\\left(x^{2} z^{2}+z \\cos y z\\right) \\hat{j}+\\left(2 x^{2} y z+y \\cos y z\\right) \\hat{k} \\\\\n\t\t \\nabla \\times \\vec{F}&=\\left|\\begin{array}{ccc}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ 2 x y z^{2} & x^{2} z^{2}+z \\cos y z & 2 x^{2} y z+y \\cos y z\\end{array}\\right|\\\\\n\t\t &=\\left(2 x^{2} z+\\cos y z-y z \\sin y z-2 x^{2} z-\\right.\\cos y z+y z \\sin y z) \\hat{i} \\\\ \\qquad&+(4 x y z-4 x y z) \\hat{j}+\\left(2 x z^{2}-2 x z^{2}\\right) \\hat{k}=0 \n\t\t\\end{align*}\n\t\tSince, curl $\\vec{F}=0$. So, $\\vec{F}$ is conservative vector field.\\\\ So, the given line integral is independent of path.\\\\ Let us find the potential $\\phi$ corresponding to $\\vec{F}$.\n\t\t\\begin{align}\n\t\t\\vec{F}&=\\nabla \\phi\\notag\\\\\n\t\t\\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j}+\\frac{\\partial \\phi}{\\partial z} \\hat{k}&=2 x y z^{2} \\hat{i}+\\left(x^{2} z^{2}+z \\cos y z\\right) \\hat{j}+\\left(2 x^{2} y z+y \\cos y z\\right) \\hat{k}\\notag\\\\\n\t\t\\text{So}\\qquad\\frac{\\partial \\phi}{\\partial x}&=2 x y z^{2}  \\Rightarrow  \\phi=x^{2} y z^{2}+\\text { constant }\\label{VI-03} \\\\ \\frac{\\partial \\phi}{\\partial y}&=x^{2} z^{2}+z \\cos y z  \\Rightarrow  \\phi=x^{2} y z^{2}+\\sin y z+\\text { constant } \\ldots . \\label{VI-04}\\\\ \\frac{\\partial \\phi}{\\partial z}&=2 x^{2} y z+y \\cos y z  \\Rightarrow  \\phi=x^{2} y z^{2}+\\sin y z+\\text { constant } \\ldots .\\label{VI-05}\n\t\t\\intertext{Adding $(\\ref{VI-03}),(\\ref{VI-04}),(\\ref{VI-05})$ and adding the common terms once}\n\t\t\\phi&=x^{2} y z^{2}+\\sin y z+\\text{ constant}\\notag\n\t\t\\intertext{So, the given line integral}\n\t\t \\int 2 x y z^{2} d x&+\\left(x^{2} z^{2}+z \\cos y z\\right) d y+\\left(2 x^{2} y z+y \\cos y z\\right) d z \\notag\\\\ &=\\int d\\left(x^{2} y z^{2}+\\sin y z\\right)=\\left[x^{2} y z^{2}+\\sin y z\\right]_{(0,0,0)}^{(1, \\pi / 4,2)} \\notag\\\\ &=\\pi+1 \\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\item Evaluate\n\t$$\n\t\\int_{C} y z d x+(x z+1) d y+x y d z\n\t$$\n\twhere $C$ is any path from $(1,0,0)$ to $(2,1,4)$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\text{Here, }\\quad y z d x+(x z+1) d y+x y d z&=(y z \\hat{i}+(x z+1) \\hat{j}+x y \\hat{k}) \\cdot d \\vec{r}\\\\\n\t\t\\text{So}\\qquad \\vec{F}&=y z \\hat{i}+(x z+1) \\hat{j}+x y \\hat{k}\\\\\n\t\t\\operatorname{curl} \\vec{F}&=\\left|\\begin{array}{ccc}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ y z & x z+1 & x y\\end{array}\\right|=0\n\t\t\\end{align*}\n\t\tSince, $\\operatorname{curl} \\vec{F}=0$, So, $\\vec{F}$ is a conservative vector field and hence, given line integral is independent of path.\\\\\n\t\tLet us find the potential $\\phi$ corresponding to $\\vec{F}$.\n\t\t\t\\begin{align}\n\t\t\t\\vec{F}&=\\nabla \\phi\\notag\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j}+\\frac{\\partial \\phi}{\\partial z} \\hat{k}&=y z \\hat{i}+(x z+1) \\hat{j}+x y \\hat{k}\\notag\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial x}&=y z \\quad \\Rightarrow \\quad \\phi=x y z+\\text{ constant}\\label{VI-06}\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial y}&=x z+1 \\Rightarrow \\phi=x y z+y+ \\text{constant}\\label{VI-07}\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial z}&=x y \\quad \\Rightarrow \\quad \\phi=x y z+\\text{ constant}\\label{VI-08}\n\t\t\t\\intertext{Adding (\\ref{VI-06}), (\\ref{VI-07}) \\& (\\ref{VI-08}) and writing the common term once}\n\t\t\t\\phi&=x y z+y\\notag\n\t\t\t\\intertext{The given line integral is therefore}\n\t\t\t \\int_{C} y z d x+(x z+1) d y+x y d z &=\\int_{(1,0,0)}^{(2,1,4)} d(x y z+y)\\notag \\\\ &=[x y z+y]_{(1,0,0)}^{(2,1,4)}\\notag \\\\ &=9\\notag \n\t\t\t\\end{align}\n\t\\end{answer}\n\t\\item Show that the vector field\n\t$$\n\t\\vec{F}=\\left(2 x y-y^{4}+3\\right) \\hat{i}+\\left(x^{2}-4 x y^{3}\\right) \\hat{j}\n\t$$\n\tis conservative. Find its potential and also the work done in moving a particle from $(1,0)$ to $(2,1)$ along some curve.\n\t\\begin{answer}\n\t\t$\n\t\t\\text { Vector field } \\vec{F} \\text { is conservative if } \\oint \\vec{F} \\cdot d \\vec{r} \\text { around any closed curve is always zero }\r$\\\\\n\t\tBy stokes theorem,\n\t\t\\begin{align*}\n\t\t\\oint \\vec{F} \\cdot d \\vec{r}&=\\int \\nabla \\times \\vec{F} \\cdot \\hat{n} d S=0\n\t\t\\intertext{So, for conservative field}\n\t\t \\nabla \\times \\vec{F} &=0 \\\\ \\vec{F} &=\\left(2 x y-y^{4}+3\\right) \\hat{i}+\\left(x^{2}-4 x y^{3}\\right) \\hat{j} \\\\\n\t\t \\nabla \\times \\vec{F}&=\\left|\\begin{array}{lll}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ 2 x y-y^{4}+3 & x^{2}-4 x y^{3} & 0\\end{array}\\right|\\\\\n\t\t  &=\\left[\\left(2 x-4 y^{3}\\right)-\\left(2 x-4 y^{3}\\right)\\right] \\hat{k}=0 \\\\ \\vec{F} &=\\nabla \\phi \\\\ \\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j} &=\\left(2 x y-y^{4}+3\\right) \\hat{i}+\\left(x^{2}-4 x y^{3}\\right) \\hat{j} \\\\ \\frac{\\partial \\phi}{\\partial x} &=2 x y-y^{4}+3 \\\\\n\t\t   \\Rightarrow\\quad \\phi &=\\int_{y=\\text { const }}\\left(2 x y-y^{4}+3\\right) d x \\\\ &=x^{2} y-x y^{4}+3 x \\\\ \\frac{\\partial \\phi}{\\partial y} &=x^{2}-4 x y^{3} \\\\\n\t\t   \\Rightarrow \\quad \\phi&=\\int_{x=c o n s t}\\left(x^{2}-4 x y^{3}\\right) d y=x^{2} y-x y^{4}\n\t\t   \\intertext{So, the potential $\\phi$ is given by}\n\t\t    \\phi &=x^{2} y-x y^{4}+3 x \\\\ \\vec{F} \\cdot d \\vec{r} &=\\nabla \\phi \\cdot d \\vec{r}=d \\phi \\\\ \\int \\vec{F} \\cdot d \\vec{r} &=\\int d \\phi=[\\phi]_{(1,0)}^{(2,1)} \\\\ &=\\left[x^{2} y-x y^{4}+3 x\\right]_{(1,0)}^{(2,1)}=5 \n\t\t    \\intertext{So, work done in moving a particle from $(1,0)$ to $(2,1)$ is equal to 5 .}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item If $\\vec{F}=\\cos y \\hat{i}-x \\sin y \\hat{j}$. Evaluate $\\int_{C} \\vec{F} \\cdot d \\vec{r}$ where $C$ is the curve in the xy plane from $(2,0)$ to $(0,2)$.\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t \\vec{F} &=\\cos y \\hat{i}-x \\sin y \\hat{j} \\\\ \\vec{F} \\cdot d \\vec{r} &=\\cos y d x-x \\sin y d y \n\t\t \\intertext{Let us check whether $\\vec{F} \\cdot d \\vec{r}$ is exact.}\n\t\t M&=\\cos y \\quad \\Rightarrow \\quad \\frac{\\partial M}{\\partial y} 11=-\\sin y\\\\\n\t\t N&=-x \\sin y \\quad \\Rightarrow \\quad \\frac{\\partial N}{\\partial x}=-\\sin y\\\\\n\t\t \\text{Since, }&\\quad \\frac{\\partial M}{\\partial y}=\\frac{\\partial N}{\\partial x}\n\t\t \\intertext{$\\vec{F} \\cdot d \\vec{r}$ is an exact and hence, $\\vec{F}$ is a conservative vector field. So, the given line integral is independent of path. Let us find the potential corresponding to $\\vec{F}$.}\n\t\t \\vec{F} &=\\nabla \\phi \\\\ \\Rightarrow \\quad \\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j} &=\\cos y \\hat{i}-x \\sin y \\hat{j} \\\\ \\frac{\\partial \\phi}{\\partial x} &=\\cos y \\quad \\Rightarrow \\quad \\phi=x \\cos y+\\text { constant } \\\\ \\frac{\\partial \\phi}{\\partial y} &=-x \\sin y \\Rightarrow \\quad \\Rightarrow=x \\cos y+\\text { constant } \\\\\n\t\t \\text{So}\\hspace{2cm}  \\phi &=x \\cos y \\\\ \\text{So}\\hspace{1.2cm} \\int \\vec{F} \\cdot d \\vec{r} &=\\int \\cos y d x-x \\sin y d y \\\\ &=\\int d(x \\cos y) \\\\ &=[x \\cos y]_{(2,0)}^{(0,2)} \\\\ &=-2 \n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Evaluate\n\t$$\n\t\\int_{C}\\left(3 y^{2}+2 z^{2}\\right) d x+(6 x-10 z) y d y+\\left(4 x z-5 y^{2}\\right) d z\n\t$$\n\talong the portion from $(1,0,1)$ to $(3,4,5)$ of the curve $C$, which is the intersection of the surfaces $z^{2}=x^{2}+y^{2}$ and $z=y+1$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t \\vec{F} \\cdot d \\vec{r} &=d \\phi=\\frac{\\partial \\phi}{\\partial x} d x+\\frac{\\partial \\phi}{\\partial y} d y+\\frac{\\partial \\phi}{\\partial z} d z \\\\ \\frac{\\partial \\phi}{\\partial x} &=3 y^{2}+2 z^{2} \\quad \\Rightarrow \\quad \\phi=3 x y^{2}+2 x z^{2}+\\text { constant } \\\\ \\frac{\\partial \\phi}{\\partial y} &=6 x y-10 y z \\quad \\Rightarrow \\quad \\phi=3 x y^{2}-5 y^{2} z+\\text { constant } \\\\ \\frac{\\partial \\phi}{\\partial z} &=4 x z-5 y^{2} \\quad \\Rightarrow \\quad \\phi=2 x z^{2}-5 y^{2} z+\\text { constant } \\\\ \\text{So}\\hspace{2cm}\\phi &=3 x y^{2}+2 x z^{2}-5 y^{2} z \\\\\n\t \\text{The line integral }\\int_{C} \\vec{F} \\cdot d \\vec{r}&\\text{ along the portion }(1,0,1)\\text{ to }(3,4,5)\\\\\n\t &=\\left[3 x y^{2}+2 x z^{2}-5 y^{2} z\\right]_{(1,0,1)}^{(3,4,5)} \\\\\n\t &=-108\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\item Show that $\\vec{F}=\\left(2 x y+z^{3}\\right) \\hat{i}+x^{2} \\hat{j}+3 z^{2} x \\hat{k}$ is a conservative field. Find its scalar potential and also the work done in moving a particle from $(1,-2,1)$ to $(3,1,4)$.\n\t\\begin{answer}\n\t\t\\begin{align}\n\t\t\\vec{F}&=\\left(2 x y+z^{3}\\right) \\hat{i}+x^{2} \\hat{j}+3 z^{2} x \\hat{k}\\notag\\\\\n\t\t\\nabla \\times \\vec{F}&=\\left|\\begin{array}{ccc}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ 2 x y+z^{3} & x^{2} & 3 z^{2} x\\end{array}\\right|=0\\notag\n\t\t\\intertext{So, $\\vec{F}$ is conservative field, it can be expressed as gradient of scalar $\\phi$.}\n\t\t\\vec{F} &=\\nabla \\phi \\notag\\\\ \\Rightarrow \\quad\\left(2 x y+z^{3}\\right) \\hat{i}+x^{2} \\hat{j}+3 z^{2} x \\hat{k} &=\\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j}+\\frac{\\partial \\phi}{\\partial z} \\hat{k} \\notag\\\\\n\t\t\\frac{\\partial \\phi}{\\partial x}&=2 x y+z^{3} \\quad \\Rightarrow \\quad \\phi=x^{2} y+x z^{3}\\dots\\label{VI-9}\\\\\n\t\t\\frac{\\partial \\phi}{\\partial y}&=x^{2} \\quad \\Rightarrow \\quad \\phi=x^{2} y\\dots\\label{VI-10}\\\\\n\t\t\\frac{\\partial \\phi}{\\partial z}&=3 z^{2} x \\quad \\Rightarrow \\quad \\phi=x z^{3}\\dots\\label{VI-11}\n\t\t\\intertext{Adding (\\ref{VI-9}), (\\ref{VI-10}), (\\ref{VI-11}) and writing the common term once}\n\t\t\\phi&=x^{2} y+x z^{3}\\notag\n\t\t\\intertext{Work done in moving a particle from $(1,-2,1)$ to $(3,1,4)$}\n\t\t W &=\\int \\vec{F} \\cdot d \\vec{r}=\\int d \\phi \\notag\\\\ &=\\left[x^{2} y+x z^{3}\\right]_{(1,-2,1)}^{(3,1,4)}=200 \\notag\n\t\t\\end{align}\n\t\\end{answer}\n\t\\item Show that $\\vec{A}=\\left(6 x y+z^{3}\\right) \\hat{i}+\\left(3 x^{2}-z\\right) \\hat{j}+\\left(3 x z^{2}-y\\right) \\hat{k}$ is irrotational. Find a scalar potential $\\phi$ such that $\\vec{A}=\\operatorname{grad} \\phi .$\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\operatorname{curl} \\vec{A}&=\\left|\\begin{array}{ccc}\\hat{i} & \\hat{j} & \\hat{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ 6 x y+z^{3} & 3 x^{2}-z & 3 x z^{2}-y\\end{array}\\right|=0\n\t\t\\end{align*}\n\t\tSince, curl $\\vec{A}=0$, so, $\\vec{A}$ is irrotational.\\\\\n\t\t$\\vec{A}$ can be expressed as gradient of scalar function $\\phi$.\n\t\t\t\\begin{align}\n\t\t\t\\vec{A}&=\\nabla \\phi\\notag\\\\\n\t\t\t\\left(6 x y+z^{3}\\right) \\hat{i}+\\left(3 x^{2}-z\\right) \\hat{j}&+\\left(3 x z^{2}-y\\right) \\hat{k}=\\frac{\\partial \\phi}{\\partial x} \\hat{i}+\\frac{\\partial \\phi}{\\partial y} \\hat{j}+\\frac{\\partial \\phi}{\\partial z} \\hat{k}\\notag\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial x}&=6 x y+z^{3} \\quad \\Rightarrow \\quad \\phi=3 x^{2} y+z^{3} x\\label{VI-12}\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial y}&=3 x^{2}-z \\quad \\Rightarrow \\quad \\phi=3 x^{2} y-y z\\label{VI-13}\\\\\n\t\t\t\\frac{\\partial \\phi}{\\partial z}&=3 x z^{2}-y \\quad \\Rightarrow \\quad \\phi=x z^{3}-y z\\label{VI-14}\n\t\t\t\\intertext{Adding $(\\ref{VI-12}),(\\ref{VI-13}),(\\ref{VI-14}) \\&$ writing the common terms once}\n\t\t\t\\phi&=3 x z^{3}-y z+x z^{3}\\notag\n\t\t\t\\end{align}\n\t\\end{answer}\n\\end{enumerate}\n\\section{Gauss Divergence Theorem}\n\\begin{enumerate}\n\t\\item Let $\\vec{F}=x \\hat{i}+2 y \\hat{j}+3 z \\hat{k}, S$ be the surface of the sphere $x^{2}+y^{2}+z^{2}=1$ and $\\hat{n}$ be the inward unit normal vector to $S$. Then $\\oint_{S} \\vec{F} \\cdot \\hat{n} d S$ is equal to\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$4 \\pi$\n\t\t\\task[\\textbf{b.}]$-4 \\pi$\n\t\t\\task[\\textbf{c.}]$8 \\pi$\n\t\t\\task[\\textbf{d.}] $-8 \\pi$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\oint \\vec{F} \\cdot \\hat{n} d S&=-\\oint \\vec{F} \\cdot n^{\\prime} d S\n\t\t\\intertext{Where $\\hat{n}^{\\prime}$ is outward drawn unit normal vector to $S$ i.e. $\\hat{n}=-\\hat{n}^{\\prime}$}\\\\\n\t\t&=-\\int \\nabla \\cdot \\vec{F} d \\tau\n\t\t\\text{ (Gauss Divergence theorem)}\\\\\n\t\t&=-6 \\times\\text{ volume of sphere }\\quad(\\text{ Since, }\\nabla \\cdot \\vec{F}=6 )\\\\\n\t\t&=-8 \\pi\n\t\\end{align*}\t\n\tSo the correct answer is \\textbf{Option (d)}\n\t\\end{answer}\n\\item Let $S$ be a closed surface for which $\\iint_{S} \\vec{r} \\cdot \\hat{n} d \\sigma=1$. Then the volume enclosed by the surface is\n \\begin{tasks}(2)\n\t\\task[\\textbf{a.}]1\n\t\\task[\\textbf{b.}]$\\frac{1}{3}$\n\t\\task[\\textbf{c.}] $\\frac{2}{3}$\n\t\\task[\\textbf{d.}] 3\t\n\\end{tasks}\t\n\\begin{answer}\n\t\\begin{align*}\n\t\\oint \\vec{r} \\cdot \\hat{n} d S&=1\\\\\n\t\\Rightarrow \\int \\nabla \\cdot \\vec{r} d \\tau&=1  \\quad\\text { (Using Gauss Divergence theorem) } \\\\ \\Rightarrow  3 \\int d \\tau&=1  \\quad\\text { (Since, } \\nabla \\cdot \\vec{r}=3)\\\\\n\\text{\tVolume }V&=\\int d \\tau=\\frac{1}{3}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\t\n\t\\item Let $V=\\left\\{(x, y, z) \\in \\boldsymbol{R}^{3}, \\frac{1}{4} \\leq x^{2}+y^{2}+z^{2} \\leq 1\\right\\}$ and $\\vec{F}=\\frac{x \\hat{i}+y \\hat{j}+z \\hat{k}}{\\left(x^{2}+y^{2}+z^{2}\\right)^{2}}$ for $(x, y, z) \\in V$.\n\tLet $\\hat{n}$ denote the outward unit normal vector to the boundary of $V$ and $S$ denotes the part $\\left\\{(x, y, z) \\in \\boldsymbol{R}^{3} ; x^{2}+y^{2}+z^{2}=\\frac{1}{4}\\right\\}$ of the boundary of $V$. Then $\\int_{S} \\vec{F} \\cdot \\hat{n} d S$ is equal to\n\t \\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$-8 \\pi$\n\t\t\\task[\\textbf{b.}]$-4 \\pi$\n\t\t\\task[\\textbf{c.}] $4 \\pi$\n\t\t\\task[\\textbf{d.}] $8 \\pi$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\tOutward unit normal to boundary of $V$.\n\t\t\\begin{align*}\n\t\t\\hat{n} &=-\\frac{x \\hat{i}+y \\hat{j}+z \\hat{k}}{1 / 2} \\\\ &=-2(x \\hat{i}+y \\hat{j}+z \\hat{k}) \\\\ \\int \\vec{F} \\cdot \\hat{n} d S &=-2 \\int \\frac{(x \\hat{i}+y \\hat{j}+z \\hat{k})}{\\left(x^{2}+y^{2}+z^{2}\\right)^{2}} \\cdot(x \\hat{i}+y \\hat{j}+z \\hat{k}) d S \\\\\n\t\t&=-2 \\int \\frac{1}{x^{2}+y^{2}+z^{2}} d S\\\\\n\t\t&=-8 \\int d S \\left(\\right.\\text{ Since, }x^{2}+y^{2}+z^{2}=\\frac{1}{4}\\text{ on }\\left.\\mathrm{S}\\right)\\\\\n\t\t&=-8 \\times 4 \\pi \\cdot \\frac{1}{4}=-8 \\pi\\\\\n\t\t\\end{align*}\n\t\t\tSo the correct answer is \\textbf{Option (a)}\n\t\\end{answer}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\\end{enumerate}", "meta": {"hexsha": "738a98a7588429b859854ba577c00cff44f1510b", "size": 55451, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Assignments/Assignment-Vector Integration.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-Vector Integration.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-Vector Integration.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 67.7057387057, "max_line_length": 643, "alphanum_fraction": 0.5737497971, "num_tokens": 24575, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8774767874818408, "lm_q2_score": 0.8577680977182186, "lm_q1q2_score": 0.7526715947901921}}
{"text": "If you haven't downloaded and unzipped \\href{https://libaoj.in/courses/2021f/MATH3341/zip/Math.3341.zip}{\\texttt{Math.3341.zip}}. Download and unzip it under \\verb|H:| (H Drive if you are working on the Remote Lab). Change the current working directory by typing \\verb|cd H:\\Math.3341\\Math.3341.Lab.13| in the Command Window, and type \\verb|edit lab_13_script| in the Command Window to edit \\verb|lab_13_script.m|.\n\n%---------------------------------------------\n\\section{Random Numbers and Histogram}\n%---------------------------------------------\n\\begin{enumerate}[(a)]\n    \\item Create a vector \\verb`x_uniform` of length $N = 10000$ random numbers, which are uniformly distributed on the interval $[-3.5, 3.5]$, using \\verb`rand`.\n    \\item Create a vector \\verb`x_normal` of length $N = 10000$ random numbers, which are normally distributed with zero mean $\\mu = 0$ and unit variance $\\sigma^2 = 1$, using \\verb`randn`.\n    \\item Create historgrams for \\verb`x_uniform` and \\verb`x_normal`.\n\\end{enumerate}\n%---------------------------------------------\n\\section{Monte Carlo Integration}\n\\begin{enumerate}[(a)]\n    \\item Open \\verb`lab_13_example.m` and \\verb`monteCarlo.m`. Go through \\verb`lab_13_example.m`, see how the script is written to use Monte Carlo Integration to integrate the function $f(x, y) = 1$ over the disk $x^2 + y^2 \\leq 1$. Then convert the Monte Carlo Integration part in the script to a function in \\verb|monteCarlo.m|.\n    \\item Then in \\verb`lab_13_script.m`, use \\verb`monteCarlo.m` to evaluate the following integral using $N = 100000$ samples:\n        $$\n        \\int_{-1}^{1} \\int_{2 x^2}^{1 + x^2} (x + 2y) \\, dy \\, dx.\n        $$\n    \\item Use the built-in function \\verb`integral2` to evaluate the above integral, and compare the error between these two integrations.\n\\end{enumerate}\n%---------------------------------------------\nFinally, call \\verb|diary('lab_13_output.txt')|, run the script \\verb|lab_13_script.m|, and then call \\verb|diary off| to save the output. Upload the script file \\verb|lab_13_script.m|, function file \\verb|monteCarlo.m|, figure file \\verb|lab_13_figure.pdf|, and output file \\verb|lab_13_output.txt| to Overleaf. Recompile, and submit the generated .pdf file on WyoCourses.\n", "meta": {"hexsha": "2eb0e23a22ae6ba3bb9827a16affa195b77b8dd7", "size": 2243, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "courses/template/MATH3341/Math.3341.Lab.13/exercise/body.tex", "max_stars_repo_name": "butlerm0405/math3341", "max_stars_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "courses/template/MATH3341/Math.3341.Lab.13/exercise/body.tex", "max_issues_repo_name": "butlerm0405/math3341", "max_issues_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "courses/template/MATH3341/Math.3341.Lab.13/exercise/body.tex", "max_forks_repo_name": "butlerm0405/math3341", "max_forks_repo_head_hexsha": "524d4e23cd8fab4ab8368df8b7e6b4442f8436f1", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 97.5217391304, "max_line_length": 414, "alphanum_fraction": 0.6674097191, "num_tokens": 635, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8397339797047029, "lm_q2_score": 0.896251371748038, "lm_q1q2_score": 0.752612731213779}}
{"text": "\\section{Generative Models}\nUnderstand structure of data probabilisticaly.\n\n\\subsection{Multinominal Models}\n\nFixed Vocabulary $W$\\\\\n\nMultinomial model $M$ to generate text in documents.\\\\\n\nDocument $D$\\\\\n\nLikelihood of generating certain word $w \\in W$: $p(w|\\theta)=\\theta_w$ where $\\theta_w \\geq 0$ and $\\sum _{w\\in W} \\theta _ w = 1$.\n\nLikelihood function:\\\\\n\n\\begin{align*}\nP(D|\\theta) &= \\prod_{i=1}^n \\theta_{wi}\\\\\n&= \\prod_{w \\in W} \\theta_w^{count(w)}\n\\end{align*}\n\nToy Example:\n\n\\begin{align*}\n&\\theta_1: \\theta_{cat}=0.3; \\theta_{dog}=0.7\\\\\n&\\theta_2: \\theta_{cat}=0.9; \\theta_{dog}=0.1\\\\\n&D = \\{cat,cat,dog\\}\\\\\n&P(D|\\theta_1)= 0.3^2 \\cdot 0.7 = 0.063\\\\\n&P(D|\\theta_2)= 0.9^2 \\cdot 0.1 = 0.081\\\\\n\\end{align*}\n\nMaximum likelihood:\\\\\n\\begin{align*}\nmax_{\\theta}P(D|theta) = max_{theta} \\prod_{w \\in W} \\theta_w^{count(w)}\\\\\nlog \\prod_{i=1}^n \\theta_w^{count(w)} = \\sum_{w \\in W} count(w) log(\\theta_w)\\\\\nW=\\{0,1\\}; \\theta_0=\\theta; \\theta_1=(1-\\theta)\\\\\n\\frac{d}{d \\theta}(count(0) log(\\theta) + count(1)log(1-\\theta) =\\\\\n= \\frac{count(0}{\\theta} - \\frac{count(1}{1-\\theta} = 0\\\\\n\\hat{\\theta}=\\frac{count(0)}{count(1)+count(0)}\n\\end{align*}\n\nFor any length of $W$:\n\n\\begin{align*}\n\\hat{\\theta} = count(w) / \\left(\\sum_{w'\\in W}count(w) \\right)\n\\end{align*}\n\n\\subsection{Prediction}\n\nGoal: categorize between minus and plus class. Both classes have a associated parameter $\\theta^{+}$ and $\\theta^{-}$ \n\nClass conditional distribution:\\\\\n\n\\begin{align*}\nlog(\\frac{P(D|\\theta^{+})}{P(D|\\theta^{-})} = \n\\begin{cases} \n\\geq 0, +\\\\\n< 0, -\n\\end{cases}\n\\end{align*}\n\nModel is the same as a linear classifier through origin:\n\n\\begin{align*}\n&log(P(D|\\theta^{+})) - log(P(D|\\theta^{-})) =\\\\\n&= log \\prod_{w \\in W} \\theta_w^{+count(w)} - log \\prod_{w \\in W} \\theta_w^{-count(w)} =\\\\\n&= \\sum_{w \\in W} count(w) log(\\theta_w^{+count(w)}) - \\sum_{w \\in W} count(w) log(\\theta_w^{-count(w)}) =\\\\\n&=\\sum_{w \\in W} count(w) log \\frac{\\theta_w^{+count(w)}}{\\theta_w^{-count(w)}}\\\\\n&= \\sum_{w \\in W} count(w) \\tilde{\\theta}_w\n\\end{align*}\n\n\\subsection{Prior, Posterior and Likelihood}\n\nFrom bayes rule $P(A|B) = \\frac{P(B|A)P(A)}{P(B'B)}$ we get:\n\n\\begin{align*}\nP(y=+ | D) = \\frac{ P(D | \\theta ^{+})P(y = +)}{P(D)}\n\\end{align*}\n\nWhere $P(y=+|D)$ is the posterior distribution and $P(y=+)$ is the prior distribution while $P(D|\\theta+)$ is the likelihood of document $D$ given parameter  $\\theta^{+}$. This yields (after some work) a linear separator with offset:\n\n\\begin{align*}\nlog(\\frac{P(y=+|D)}{P(y=-|D)} &= \\frac{ P(D | \\theta ^{+}) P(y = +)}{P(D | \\theta ^{-}) P(y = -)}\\\\\n&= log(\\frac{P(D | \\theta ^{+}}{P(D | \\theta ^{-}}) + log(\\frac{P(y = +)}{P(y = -)})\\\\\n&= \\sum_{w \\in W} count(w) \\tilde{\\theta}_w + \\tilde{\\theta}_0\n\\end{align*}\n\n\\subsection{Gaussian Generative models}\n\nVectors in $x \\in R^d$ \"cloud\" of data in which $\\mu$ (average over all points) is the center of the cloud and $\\sigma^2$ (square of average distance) the radius.\n\nProbability of $x$ generated by gaussian cloud:\n\n\\begin{align*}\nP(x | \\mu , \\sigma ^2) = \\frac{1}{(2\\pi \\sigma ^2)^{d/2}} exp(-\\frac{1}{2\\sigma ^2} \\|  x - \\mu \\| ^2)\n\\end{align*}\n\nLikelihood of the training data: $S_n=\\{x^{(t)}|t=1,\\cdots,n\\}$ given the gaussian model $p(S_n|\\mu,\\sigma^2)=\\prod_{t=1}^n P(x^{(t)|\\mu,\\sigma^2}$.\n\nTo get the MLE calculate likelihood, take the log and massage:\n\\begin{align*}\nlog(\\prod_{t=1}^n \\frac{1}{(2\\pi \\sigma ^2)^{d/2}} exp(-\\frac{1}{2\\sigma ^2} \\|  x - \\mu \\| ^2)) =\\\\\n= \\sum_{t=1}^n log \\frac{1}{2\\sigma ^2} + \\sum_{t=1}^n log (exp(-\\frac{1}{2\\sigma ^2} \\|  x - \\mu \\| ^2))\\\\\n= \\sum_{t=1}^n( -\\frac{d}{2} log(2\\pi\\sigma^2)) + \\sum_{t=1}^n (- \\frac{1}{2\\sigma^2}  \\|  x - \\mu \\| ^2) \\\\\n= -\\frac{nd}{2}log(2\\pi\\sigma^2) + \\frac{1}{2\\sigma^2} \\sum_{t=1}^n \\|  x - \\mu \\| ^2) \\\\\n= L\n\\end{align*}\n\nDifferentiate loglikelihood with respect to $\\mu$ and $\\sigma^2$ set to zero and solve for the respective parameters yields:\n\n\\begin{align*}\n\\hat{\\mu } = \\frac{\\sum _{t=1}^{n} x^{(t)}}{n}\\\\\n\\hat{\\sigma }^2 = \\frac{\\sum _{t=1}^ n \\| x^{(t)} - \\mu \\| ^2}{nd}\n\\end{align*}\n\n\\subsection{Gaussian Mixture Models}\nIs called \"Soft Clustering\" because it  deals with probabilities not hard classification.\\\\\n\nWe have $K$ clusters, each with own gaussian cloud $N(x, \\mu^{(j)}, \\sigma^2_{(j)}), j=1,\\cdots,K$. \n\nEach Cluster gets own mixture-weight $j \\sim Multinomial(p_1,\\cdots,p_k)$ \n\nParameters of the mixture model are parameters of Multinomials and gaussians: \n\\begin{align*}\n\\theta={p_1,\\cdots,p_k;\\mu^{(1)},\\cdots,\\mu^{(k)};\\sigma^2_{(j)}),\\cdots,\\sigma^2_{(j)})}\n\\end{align*}\n\nConditional probability of data-point given gaussian mixture:\n\n\\begin{align*}\nP(x|\\theta)=\\sum_{i=1}^K p_j N(x,\\mu^{(j)},\\sigma^2_{(j)}\n\\end{align*}\n\nConditional Likelihood of Training set $S_n$ given gaussian mixture:\n\n\\begin{align*}\nP(S_n|\\theta)= \\prod_{j=1}^{n} \\sum_{j=1}^{k} N(x,\\mu^{(j)},\\sigma^2_{(j)}\n\\end{align*}\n\n\\textbf{Observed Case:}\\\\\nWe know to which mixture $x$ belongs.\\\\\n\nIndicator Variable is used to count the cases in which observation is part of a cluster $\\delta(j|i)=\\textbf{1}(x^{(i)} \\text{is assinged to j})$.\n\n\n\\begin{align*}\n&\\sum_{i=1}^n [\\sum_{j=1}^k \\delta(j|i) log (p_j N(x,\\mu^{(j)},\\sigma^2_{(j)})]=\\\\\n&= \\sum_{j=1}^k [\\sum_{i=1}^n \\delta(j|i) log (p_j N(x,\\mu^{(j)},\\sigma^2_{(j)})]\\\\\n\\end{align*}\n\nOptimizing (according to MLE principle) yields:\n\n\\begin{align*}\n&\\hat{n}_j = \\sum_{i=1}^n \\delta(j|i)\\\\\n&\\hat{p}_j = \\frac{\\hat{n}_j}{n}\\\\\n&\\hat{\\mu}^{(j)}= \\frac{1}{\\hat{n}} \\sum\n_{i=1}^n \\delta(j|i) \\cdot x^{(i)}\\\\\n&\\hat{\\sigma}^2 = \\frac{1}{\\hat{n}_j}\\sum_{i=1}^n \\delta(j|i) || x^{(i)} - \\mu^{(j)}||^2\n\\end{align*}\n\n\\textbf{EM Algorithm (Unobserved Case):}\\\\\nWe don't know to which mixture $x$ belongs.\\\\\n\n\\begin{enumerate}\n\\item Randomly initialize $\\theta={p_1,\\cdots,p_k;\\mu^{(1)},\\cdots,\\mu^{(k)};\\sigma^2_{(j)}),\\cdots,\\sigma^2_{(j)})}$\n\\item E-Step:\n\t\\begin{enumerate}\n\t\t\\item Calculate the softcount of a point (the probability of a cluster $j$ given the point $i$: $\\displaystyle  p(j \\mid i) = \\frac{p_ j ~  \\mathcal{N}(x^{(i)} ; \\mu ^{(j)}, \\sigma _ j^2)}{p(x^{(i)} | \\theta )}$, where $P(x|\\theta)=\\sum_{j=1}^K p_j N(x,\\mu^{(j)},\\sigma^2_{(j)}$\n\t\\end{enumerate}\n\\item M-Step\n\t\\begin{enumerate}\n\t\t\\item  Use softcounts to calculate new parameters.\n\t\t\\begin{align*}\n\t\t&\\hat{n}_j = \\sum_{i=1} p(j|i)\\\\\n\t\t&\\hat{p}_j= \\frac{\\hat{n}_j}{n}\\\\\n\t\t&\\hat{\\mu}^{(j)}= \\frac{1}{\\hat{n}} \\sum\n_{i=1}^n p(j|i) \\cdot x^{(i)}\\\\\n\t\t&\\hat{\\sigma}^2_j=\\frac{1}{\\hat{n}_j}\\sum_{i=1}^n p(j|i) (x^{(i)} - \\mu^{(j)})^2\n\t\t\\end{align*}\n\t\\end{enumerate}\n\\end{enumerate}", "meta": {"hexsha": "f57e0d1d548704cf3fc752cc73c7f77439b86e80", "size": 6544, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "content/generative_models.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/generative_models.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/generative_models.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": 36.3555555556, "max_line_length": 280, "alphanum_fraction": 0.6039119804, "num_tokens": 2667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513786759491, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7526127280446213}}
{"text": "\\section{PWGrid version 1}\n\n\\subsection{The implementation: {\\tt PWGrid\\_01.jl}}\n\nThe type definition\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\n\nThe constructor\n\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\n\nMapping between half of the sampling points to the negative ones\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\nInitialization of real space and reciprocal space grid points\n\n\\begin{juliacode}\nfunction init_grids( Ns, LatVecs, RecVecs )\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] + LatVecs[3,1]*k/Ns[3]\n    r[2,ip] = LatVecs[1,2]*i/Ns[1] + LatVecs[2,2]*j/Ns[2] + LatVecs[3,2]*k/Ns[3]\n    r[3,ip] = LatVecs[1,3]*i/Ns[1] + LatVecs[2,3]*j/Ns[2] + LatVecs[3,3]*k/Ns[3]\n  end\n  end\n  end\n  #\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  return r,G,G2\nend\n\\end{juliacode}\n\n\\subsection{Testing the {\\tt PWGrid\\_01}}\n\nInclude files:\n\n\\begin{juliacode}\ninclude(\"../common/PWGrid_v01.jl\")\ninclude(\"../common/gen_lattice.jl\")\n\\end{juliacode}\n\nMain driver\n\n\\begin{juliacode}\nfunction test_main_hexagonal()\n  # call these functions for other types of lattice\n  #LL = 16.0*diagm([1.0, 1.0, 1.0]) # cubic\n  #LL = gen_lattice_fcc(16.0)       # face-centered cubic\n  #LL = gen_lattice_bcc(16.0)       # body-centered cubic\n\n  Ns = [10, 10, 20]\n  LL = gen_lattice_hexagonal(10.0, coa=2.0)\n  pw = PWGrid( Ns, LL )\n  atpos = pw.r\n\n  println(pw.LatVecs)\n  println(pw.RecVecs)\n\n  write_XSF(\"R_grid_hexagonal.xsf\", LL, atpos)\n\n  Rec = pw.RecVecs*Ns[1]/2.0\n  atpos = pw.G\n  write_XSF(\"G_grid_hexagonal.xsf\", LL, atpos, molecule=true)\n\n  for ii = 1:3\n    @printf(\"LatVecLen %d %18.10f\\n\", ii, norm(pw.LatVecs[ii,:]))\n  end\n  @printf(\"Ratio coa: %18.10f\\n\", norm(pw.LatVecs[1,:])/norm(pw.LatVecs[3,:]))\n\n  @printf(\"\\n\")\n  for ii = 1:3\n    @printf(\"RecVecLen %d %18.10f\\n\", ii, norm(pw.RecVecs[ii,:]))\n  end\n  @printf(\"Ratio coa: %18.10f\\n\", norm(pw.RecVecs[1,:])/norm(pw.RecVecs[3,:]))\n\nend\n\\end{juliacode}\n\n", "meta": {"hexsha": "890c23178c50e7e7a1b8d37e67fe95dcb3aee533", "size": 3007, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "PW/annotated/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/annotated/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/annotated/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": 22.9541984733, "max_line_length": 80, "alphanum_fraction": 0.6291985367, "num_tokens": 1321, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513814471135, "lm_q2_score": 0.8397339656668287, "lm_q1q2_score": 0.7526127267769581}}
{"text": "\n \\FloatBarrier\n\\section{Multi-population Games}\\label{sec:multi-pop}\n\n\n\n\n\\subsection{Matching pennies}\n\nWe implement a matching pennies game defining a society $\\pop = \\{p_1, p_2\\}$ with two populations and two strategies per population, namely \\emph{heads} and \\emph{tails}. First, note that the payoff of the game in normal form is\n%\n\\begin{table}[H]\n\\centering\n \\begin{tabular}{|c|c|} \\hline\n  2, 1 & 1, 2 \\\\ \\hline\n  1, 2 & 2, 1 \\\\ \\hline\n \\end{tabular}\n\\end{table}\n%\nNow, the fitness vector of the  population $p_j$ can be expressed as $F^{p_j}(x^{p_k}) = A^{p_j} x^{p_k}$, for $p_j, p_k \\in \\pop$ and $p_j \\neq p_k$. That is, the payoff of a population is affected only by the state of the opponent population.\nThe payoff matrices are defines as follows\n%\n\\begin{equation}\n  A^1 = \\begin{pmatrix}\n2 & 1 \\\\\n1 & 2 \n  \\end{pmatrix}\n\\end{equation}\n%\n\\begin{equation}\n  A^2 = \\begin{pmatrix}\n  1 & 2 \\\\\n  2 & 1 \n  \\end{pmatrix}\n\\end{equation}\n%\nFig. \\ref{fig:mp_game_rd} to \\ref{fig:mp_game_logit} show the evolution of the social state with the evolutionary dynamics presented in Section \\ref{sec:protocols}. \n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_simplex_rd.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test2_simplex_rd}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_ev_rd.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test2_ev_rd}\n  \\end{subfigure}\n  \\caption{Matching pennies game with replicator dynamics.}\n  \\label{fig:mp_game_rd}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_simplex_maynard_rd.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test2_simplex_maynard_rd}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_ev_maynard_rd.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test2_ev_maynard_rd}\n  \\end{subfigure}\n  \\caption{Matching pennies game with Maynard replicator dynamics.}\n  \\label{fig:mp_game_maynard_rd}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_simplex_bnn.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test2_simplex_bnn}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_ev_bnn.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test2_ev_bnn}\n  \\end{subfigure}\n  \\caption{Matching pennies game with BNN dynamics.}\n  \\label{fig:mp_game_bnn}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_simplex_smith.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test2_simplex_smith}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_ev_smith.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test2_ev_smith}\n  \\end{subfigure}\n  \\caption{Matching pennies game with Smith dynamics.}\n  \\label{fig:mp_game_smith}\n\\end{figure}\n\n\n\n\\begin{figure}[h]\n  \\centering\n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_simplex_logit.eps}\n\t  \\caption{Simplex.}\n\t  \\label{fig:test2_simplex_logit}\n  \\end{subfigure}\n  ~ \n  \\begin{subfigure}[b]{0.45\\textwidth}\n\t  \\includegraphics[width=\\textwidth]{./images/test2_ev_logit.eps}\n\t  \\caption{Evolution of the strategies in time.}\n\t  \\label{fig:test2_ev_logit}\n  \\end{subfigure}\n  \\caption{Matching pennies game with Logit dynamics with $\\eta=0.02$.}\n  \\label{fig:mp_game_logit}\n\\end{figure}\n\n", "meta": {"hexsha": "7ca0068d3236e5fdb58ba312b92384712b8375df", "size": 3770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/multipopulation.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/multipopulation.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/multipopulation.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": 28.5606060606, "max_line_length": 244, "alphanum_fraction": 0.7167108753, "num_tokens": 1265, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513703624558, "lm_q2_score": 0.8397339756938818, "lm_q1q2_score": 0.7526127264555547}}
{"text": "\n% JuliaCon proceedings template\n\\documentclass{juliacon}\n\\setcounter{page}{1}\n\n\n\n\\usepackage{hyperref}\n%\\usepackage[linesnumbered,ruled,vlined]{algorithm2e}\n\\usepackage{graphicx}\n%\\usepackage[font=small,labelfont=bf]{caption}\n\\usepackage{subcaption}\n\n\\usepackage{tikz}\n\\usetikzlibrary{shapes.misc}\n\\tikzset{cross/.style={cross out, draw=black, thick, minimum size=2*(#1-\\pgflinewidth), inner sep=0pt, outer sep=0pt},\n%default radius will be 1pt. \ncross/.default={3.5pt}}\n\\usepackage{pgfplots}\n\\pgfplotsset{samples=600}\n\\pgfplotsset{compat=newest}\n\\usepackage{amsmath} \n%\\usetikzlibrary{external}\n%\\tikzexternalize[prefix=tikz/]\n\n\\def\\sinc{\\mathrm{sinc}}\n\\def\\lc{\\lstinline}\n\\newcommand\\todo[1]{\\textcolor{red}{\\textbf{TODO: #1}}}\n\n\\usepackage{siunitx}\n\n\\begin{document}\n\n\\input{header}\n\n\\maketitle\n\n\\begin{abstract}\n\\verb|FourierTools.jl| aims at simplifying work in Fourier\nspace without loosing efficiency.\nFirst, we provide several convenient wrappers to ease the usage of the common Fourier processing operations.\nSecond, we implement array transformations like $\\sinc$ interpolation, sub pixel shifting, convolution, rotation and shearing based on Fourier transforms.\nNotably, those algorithms handle the Nyquist term in case of an even sized array correctly\nunder the condition of minimum mean-square slope.\n\n\\end{abstract}\n\n\\section{Introduction}\nThe fast Fourier transform (FFT) is a popular algorithm because it can evaluate the Discrete Fourier Transform (DFT) \n\\begin{equation}\n    X_k = \\sum_{n=0}^{N-1} x_n \\exp\\left(-i2 \\pi \\frac{kn}{N} \\right)\n    \\label{eq:dft}\n\\end{equation}\nand the Inverse Discrete Fourier Transform (IDFT)\n\\begin{equation}\n    x_n = \\frac1{N}\\sum_{k=0}^{N-1} X_k \\exp\\left(i2 \\pi \\frac{kn}{N} \\right)\n    \\label{eq:idft}\n\\end{equation}\nin $\\mathcal{O}(N \\log N)$ operations, whereas the straightforward\nevaluation takes $\\mathcal{O}(N^2)$ operations.\nThe DFT transforms the signal to a different basis, the Fourier space which\nhas wide applications in signal processing.\nIn Julia \\cite{bezanson2017julia} \\verb|FFTW.jl| offers a convenient interface to\nthe \\verb|FFTW| library \\cite{FFTW05} which is among the fastest FFT libraries.\nThe interpretation of a signal in Fourier space is versatile and many operations can\nbe done using FFT operations. \nIn this work, we present several operations which can be calculated quickly \ndue to the good performance of FFTs.\nAdditionally, we also stick to a certain boundary handling in all algorithms.\nAll algorithms and examples are implemented using the Julia package \\verb|FourierTools.jl|\\footnote{The full source is available on GitHub: \\url{https://github.com/bionanoimaging/FourierTools.jl/}}.\n\n\\section{Mathematical Background}\n    Essential for the understanding of the algorithms presented here, is the Discrete Fourier series (DFS).\n    Qualitatively, the DFS is a weighted sum of complex $\\cos$ and $\\sin$ terms.\n    In our notation, the DFS of a signal defined in $[0, L)$ is defined as\n    \\begin{align}\n        x_n &= \\frac1{N}\\sum_{k=0}^{N-1} X_k \\cdot \\exp\\left(i2\\pi \\frac{k}{N} n \\right) \\\\\n        &= \\frac1{N}\\sum_{k=0}^{N-1} X_k \\cdot \\left[ \\cos\\left(i2\\pi \\frac{k}{N} n \\right) + i \\cdot  \\sin\\left(i2\\pi \\frac{k}{N} n \\right) \\right]\\label{eq:DFS2}\\\\\n        &=\\frac1{N}\\sum_{k=-\\lfloor N/2\\rfloor}^{\\lceil N/2 -1 \\rceil} X_k \\cdot \\left[ \\cos\\left(i2\\pi \\frac{k}{N} n \\right) + i \\cdot  \\sin\\left(i2\\pi \\frac{k}{N} n \\right) \\right]\\label{eq:DFS}\n    \\end{align}\n    which is the same as the IDFT definition in \\autoref{eq:idft}.\n    The brackets $\\lfloor \\cdot \\rfloor$, $\\lceil \\cdot \\rceil$ denote the floor, next lower integer number and the ceil, next upper inter number respectively. In fact, the coefficients $X_k$ are obtained with the DFT.\n    \\autoref{eq:DFS} can be derived from the $2\\pi$ periodicity of $\\sin$ and $\\cos$.\n    An inherent assumption of the DFS is that the signal $x_n$ is circular repeating.\n    So whenever a DFT/IDFT is calculated, this property is included.\n    The coefficients $X_K$ describe the strength of an individual complex\n    exponential basis function.\n    In general, coefficients $X_k$ are complex valued but for real input data $x_n$ it follows that\n    \\begin{equation}\n        X_{N-k} = X_k^*.\n        \\label{eq:symmetry}\n    \\end{equation}\n    This property is usually called \\textit{Hermitian}.\n%    \\begin{figure}\n%        \\centering\n%        \\begin{tikzpicture}\n%            \\def\\myradius{1.6}\n %           \\def\\mydiff{0.3}\n %           \\draw[->] (-\\myradius - \\mydiff, 0) -- (+\\myradius + \\mydiff,0) node[right] {$\\mathrm{Re}$};\n%            \\draw[->] (0, -\\myradius - \\mydiff) -- (0, +\\myradius + \\mydiff) node[right] {$\\mathrm{Im}$};\n%            \\draw (0,0) circle(\\myradius);\n %           \\foreach \\i in {0, 1, ..., 6}{\n%                \\pgfmathsetmacro{\\anglee}{360/7 * \\i}\n%            }\n%        \\end{tikzpicture}\n%        \\caption{Caption}\n%        \\label{fig:dft}\n%    \\end{figure}\n\n    As seen from \\autoref{eq:DFS}, the maximum frequency of a signal described with the DFS is $-\\lfloor N/2 \\rfloor / L$ (the border of the summation interval of $k = -\\lfloor N/2 \\rfloor$)\\footnote{You might wonder why the maximum frequency in \\autoref{eq:DFS2} would be at $k=N-1$. However, this frequency is not Nyquist sampled\\footnote{According to the Whittaker–Nyquist–Shannon \n        theorem \\cite{whittaker_e_t_1915_1428702}, \\cite{Shannon1949}.} and leads to aliasing which results that those frequencies appear at lower frequencies.}. \n    For a signal (over the range $[0, L)$) with 7 elements, the frequencies in the Fourier series would be\n    \\begin{equation}\n        f_{\\{k\\}} = \\left[-\\frac{3}{7 L} , -\\frac{2}{7 L},  -\\frac{1}{7L}, \\frac{0}{7L}, \\frac{1}{7L}, \\frac{2}{7L}, \\frac{3}{7L} \\right]\n        \\label{eq:7elems}\n    \\end{equation}\n    and for one with 6 elements\n    \\begin{equation}\n       f_{\\{k\\}} = \\left[-\\frac{4}{8 L} ,-\\frac{3}{8 L} ,-\\frac{2}{8 L} ,-\\frac{1}{8 L} ,\\frac{0}{8 L} ,\\frac{1}{8 L} ,\\frac{2}{8 L} ,\\frac{3}{8 L} \\right].\n       \\label{eq:6elems}\n    \\end{equation}\n    The highest frequency $-\\frac{4}{8 L}$ in \\autoref{eq:6elems} does not fulfill Nyquist sampling and thus \n    cannot be interpreted uniquely. As drawn in \\autoref{fig:nyquist_sample}, comparing the solid green, red and blue curves, there are infinitely many periodic functions of one and the same coarsest frequency\n     (varying in phase and amplitude) exhibiting same sampled values.\n    \\begin{figure}\n        \\centering\n        \\begin{tikzpicture}\n            \\begin{axis}[xmin=-0.5, xmax=7, ymax=1.2, ymin=-1.2, width=8cm, height=5cm,\n                xtick = {0, 3.1415, 6.283}, xticklabels={0, $L/2$, $L$}]\n                    \\addplot[sharp plot, domain=-1:9, color=green, samples=400] {0.2 * cos(deg(x)};\n                    \\addplot[sharp plot, domain=-1:9, color=blue, samples=100] {0.5 * cos(deg(x) - 66.42};\n                    \\addplot[sharp plot, domain=-1:9, color=red, samples=100] {1 * cos(deg(x) - 78.46};\n                    \\addplot[sharp plot, domain=-1:9, color=orange, samples=100] {0.2*cos(deg( 3 *x))};\n                    \\draw[] (axis cs:-1, 0) -- (axis cs:8, 0);\n                    \\draw[dashed] (axis cs:0, -2) -- (axis cs:0, 2);\n                    \\draw[dashed] (axis cs:3.1415, -2) -- (axis cs:3.1415, 2);\n                    \\draw[dashed] (axis cs:6.283, -2) -- (axis cs:6.283, 2);\n                    \n                    \n                   \\draw (0,0.2) node[cross, thick] { };\n                    \\draw (3.1415,-0.2) node[cross, thick] { };\n                     \\draw (6.283,0.2) node[cross, thick] { };\n\n            \\end{axis}\n        \\end{tikzpicture}\n        \\caption{Periodic signal of period length $2\\pi$ which has been sampled with $\\pi$ spacing.}\n        \\label{fig:nyquist_sample}\n    \\end{figure}\n    \n    Coming back to \\autoref{eq:7elems} we can think about what happens if we extend the Fourier spectrum by introducing additional frequencies. \n    For example, we can symmetrically introduce higher frequencies, which we pretend to have measured but which yielded zero amplitude. That means, that we do not add new information to our measured information.\n    However, calculating the IDFT we now evaluate the Fourier series on a different grid.\n    By our introduction of higher frequencies with zero strength, we did not change the domain of the function but we simply evaluate the Fourier series at a denser spaced grid in real space. This evaluation changes the signal to a smother, \\textit{interpolated} appearance.\n    The whole procedure is called Sinc \\textit{interpolation}.\\\\\n    \n    \\subsection{Sinc Upsampling of Real--Valued Signals}\n        Now we discuss how we apply $\\sinc$ interpolation to of real--valued signals.\n        Starting with an odd-sized signal is simple (see above) as we only have to pad with zeros.\n        Starting with an even-sized signal is more difficult, which is demonstrated in the next parts.\n        \n        \\subsubsection{Even $\\rightarrow$ Odd}\n            If we consider a real signal (with length $N=4$) $[x_0, x_1, x_2, x_3]$ we discuss how to interpolate\n            this signal to a length of $N=5$ and $N=6$.\n            The frequencies of the signal shall be called $[X_{-2}, X_{-1}, X_0, X_1]$.\n            Interpolation to a length $N=5$, naively we would think that padding the frequencies to\n            \\begin{equation}\n                Y_k = [X_{-2}, X_{-1}, X_0, X_1, 0]\n            \\end{equation}\n            would be sufficient. However, because of \\autoref{eq:symmetry} the resulting signal\n            \\begin{equation}\n                y_n = \\mathcal{F}^{-1}\\left[X_{-2}, X_{-1}, X_0, X_1, 0\\right]\n            \\end{equation}\n            is not real anymore. In our opinion, a real interpolated signal\n            should result in a real signal after interpolation.\n            Therefore, we have to restore the symmetry property, resulting in a real signal.\n            To achieve that, one way would be to equally split the real--valued Nyquist amplitude (the highest frequency) equally between two highest frequencies like\n            \\begin{equation}\n                y_n = \\mathcal{F}^{-1}\\left[X_{-2} / 2, X_{-1}, X_0, X_1, X_{-2}/2 \\right].\n            \\end{equation}\n            This choice of interpolation warrants real values of $y_n$ and additionally, minimizes the mean-square slope\\footnote{This has been derived by Steven G. Johnson: \\url{https://discourse.julialang.org/t/sinc-interpolation-based-on-fft/52512/82}.\n            There are also additional notes here: \\url{https://math.mit.edu/~stevenj/fft-deriv.pdf}.}. Note, that since $X_{-2}$ is guaranteed to be real for real--valued signals, no complex conjugation is required in the split for one-dimensional Fourier-transformations.\n        \n        \\subsubsection{Even $\\rightarrow$ Even}\n            To interpolate to $N=8$ we can then do\n            \\begin{equation}\n                y_n = \\mathcal{F}^{-1}\\left[0, 0, X_{-2} / 2, X_{-1}, X_0, X_1, X_{-2}/2, 0 \\right].\n            \\end{equation}\n            The limit--frequency is split as before and all frequencies above the initial Nyquist amplitude are set to zero.\n            \n        \\subsubsection{Odd $\\rightarrow$ Odd}\n            The odd case is straightforward, starting with the frequencies\n            \\begin{equation}\n                X_k = [X_{-1}, X_0, X_1]\n            \\end{equation}\n            going to a larger odd or even array by zero--padding, always fulfills the real property.\n            \\begin{equation}\n                y_n = \\mathcal{F}^{-1}[0, X_{-1}, X_0, X_1, 0]\n            \\end{equation}\n            \n        \\subsubsection{Odd $\\rightarrow$ Even}\n            Also for the even case, the all new frequencies are set to zero including the new Nyquist frequency.\n            \\begin{equation}\n                y_n = \\mathcal{F}^{-1}\\left[0, X_{-1}, X_0, X_1\\right].\n            \\end{equation}\n    \n    \n    \\subsection{Sinc Downsampling}\n        Instead of upsampling the signal, we can also remove higher frequency content.\n        The result is a signal which in principle is free of aliasing, as opposed to for example binning of adjacent pixels, which would result in aliasing.\n        \n        \\subsubsection{Even $\\rightarrow$ Odd}\n            We can simply remove the Nyquist amplitude.\n            Starting from $[X_{-2}, X_{-1}, X_0, X_1]$ downsampling to $N=3$ is \n            \\begin{equation}\n                Y_k = [X_{-1}, X_0, X_1].\n            \\end{equation}\n        \\subsubsection{Even $\\rightarrow$ Even}\n            However, going to $N=2$ we have to accumulate the two highest frequencies into the one remaining Nyquist amplitude: \n            \\begin{equation}\n                Y_k = [X_{-1} + X_{1}, X_0].\n            \\end{equation}\n            The qualitative meaning is, that since we only have a single negative Nyquist amplitude, this frequency is aliased (positive counter--part is missing) and this negative Nyquist amplitude stores the sum of both entries. Note that also here, no complex conjugation is applied to yield a real-valued Nyquist frequency, forcing the resulting signal $y_n$ to be real (see symmetry property \\autoref{eq:symmetry}), .\n            \n        \\subsubsection{Odd $\\rightarrow$ Odd}\n            We can downsample \n            \\begin{equation}\n                Y_k = [X_{-2}, X_{-1}, X_0, X_1, X_2]\n            \\end{equation}\n            to an odd--sized array in a straight--forward way by dropping the surplus frequencies:\n            \\begin{equation}\n                Y_k = [X_{-1}, X_0, X_1].\n            \\end{equation}\n            \n       \\subsubsection{Odd $\\rightarrow$ Even}\n           Going to an even sized signal is again achieved by accumulating the Nyquist amplitude entry:\n            \\begin{equation}\n                Y_k = [X_{-1} + X_1, X_0].\n            \\end{equation}\n        In summary, for upsampling only the source even--sized arrays and for downsampling only the destination even-sized arrays require a special treatment.\n        It is worth stressing that the Nyquist-frequency data in even-sized signals has no unique interpretation neither for real nor for complex valued data many combinations of underlying amplitude and phase yield the same sampled signal. Therefore, first downsampling to an even-sized array followed by upsampling will in general be modifying this downsampled Nyquist--frequency, which can only be avoided if additional assumptions can be made. Ideally, the user should avoid data being present at this even-sized Nyquist frequency, to avoid ambiguities.\n        Finally, real--valued signals should be interpolated by exploiting real--to--complex Fourier transform algorithms, as this comes with increased speed and reduced memory consumption. Yet the considerations presented above apply in an analogous way.\n    \\subsection{Sinc Interpolation in $N$ Dimensions}\n        The multidimensional signal handling is in principle similar as for \n        a 1D dataset. However, the Nyquist amplitude is not a single entry anymore but rather a $(N-1)$--dimensional hyperplane.\n        \\subsubsection{Odd Case}\n            Assuming the real dataset $x_{i,j}$, we obtain its DFT as\n            \\begin{equation}\n                X_{k, m} = \\begin{bmatrix}\n                   X_{-1, -1} &  X_{-1, 0} \\\\ \n                   X_{0,-1} & X_  {0, 0} \\\\\n                \\end{bmatrix}\n            \\end{equation}\n            The interpolation to a $3\\times 3$ array  $y_{\\{i, j\\}}$, needs the following form\n            \\begin{equation}\n                y_{i, j} = \\mathcal{F}^{-1}\\begin{bmatrix}\n                   X_{-1, -1}/2 &  X_{-1, 0}/2  & 0\\\\ \n                   X_{0,-1}/2   & X_{0, 0}      &  X_{0,-1}^*/2\\\\\n                    0           &  X_{-1, 0}^*/2 &  X_{-1, -1}^*/2\\\\\n                \\end{bmatrix}\n            \\end{equation}\n            Note, in $N>1$ dimensions we need to adhere to the \\textit{Hermitian} property for the\n            resulting signal to be real. \n            For a 1D signal the Nyquist term is real and hence complex conjugation was not necessary but in $N>1$ complex conjugation seems to be required.\\\\\n            However, due to the separability of the DFT, we can  interpolate each dimension separately.\n            This allows us to treat any N dimensional signal as a collection of 1D signals, treating each dimension individually but simultaneously for all such 1D signals.\n            The first interpolation along the first dimension would be\n            \\begin{equation}\n                y^{1}_{i, j} = \\mathcal{F}_{m}^{-1}\\begin{bmatrix}\n                   X^1_{-1, -1}/2 &  X^1_{-1, 0}/2 \\\\ \n                   X^1_{0,-1} & X^1_{0, 0} \\\\\n                   X^1_{-1,-1}/2 & X^1_{-1, 0}/2 \\\\\n                \\end{bmatrix}\n            \\end{equation}\n            and with the new coefficients $\\mathcal{F} \\left[y^{1}_{\\{i, j\\}} \\right] =Y^{1}_{k, m} $  \n            If we interpolate this intermediate result along the second dimension we obtain\n            \\begin{equation}\n                y^{1,2}_{k, m} = \\mathcal{F}_{k}^{-1}\\begin{bmatrix}\n                   Y^1_{-1, -1} /2 &  Y^1_{-1, 0} & Y^1_{-1, -1} / 2\\\\ \n                   Y^1_{0,-1} /2& Y^1_{0, 0} & Y^1_{0, -1} / 2\\\\\n                   Y^1_{-1,-1}/2 & Y^1_{-1, 0}& Y^1_{-1, -1} / 2\\\\ \n                \\end{bmatrix}.\n            \\end{equation}\n            The advantage of this method is the easier boundary handling since we only \n            need to divide the $N-1$ dimensional slice and do not have to care about maintaining the \n            Hermitian property (which is more difficult to program).\n            In the even case, the Nyquist amplitude gets aliased and hence we would have\n            to add the $(N-1)$ dimensional slices together in a flipped way.\n            But again, doing that sequentially is simpler because there is no need to flip the data. \n            \n        \\subsubsection{Downsampling}\n            As described in the 1D case, for downsampling to an even-sized array we have to \n            add the two highest frequencies to yield one new Nyquist amplitude. For $N$ dimensions this \n            procedure works sequentially over the dimensions as described in the upsampling routine.\n            \n            \n    \\subsection{Convolution Theorem}\n        The convolution theorem states that a convolution can be expressed as\n        a point wise multiplication and three Fourier transforms,\n        \\begin{equation}\n            u * v = \\mathcal{F}^{-1}\\left[\\mathcal F[u] \\cdot \\mathcal{F}[v]\\right]\n        \\end{equation}\n        where $*$ is the convolution and $\\cdot$ the point wise multiplication.\n        This property can be proved with the usage of the DFT definition (see \\autoref{eq:dft}).\n        A FFT based convolution usually offers an improvement if the kernel $u$ is large.\n        \n    \\subsection{Shift Theorem}\n        The Fourier Shift theorem tells us that a shift of a signal can be calculated \n        in Fourier space the point wise multiplication of the Fourier--transformed signal by a complex-valued phase ramp.\n        This is directly derived from the DFT definition.\n        The full form of the Fourier shift theorem is:\n        \\begin{equation}\n            u(\\mathbf x+ \\Delta \\mathbf x) = \\mathcal{F}^{-1}\\big[\\mathcal{F}[u(\\mathbf x)](\\mathbf k) \\cdot \\exp(i \\mathbf k \\Delta \\mathbf x) \\big]\n            \\label{eq:shifting}\n        \\end{equation}\n        where $\\Delta x$ can be an arbitrary shift not restricted to integer values.\n        \\subsubsection{Handling of the Nyquist Amplitude}\n            As before, separate handling of the Nyquist amplitude is essential, otherwise \n            the real symmetry property might be violated leading to a complex--valued output for a real input.\n            \\autoref{eq:shifting} can be also interpreted as a convolution of the signal $u$\n            with the kernel $\\mathcal{F}^{-1}\\left[\\exp(i \\mathbf k \\Delta \\mathbf x)\\right]$.            \n            Hence, this kernel should be purely real in real space, otherwise the\n            shifting kernel does mix real and imaginary part of the signal.\n            For a real signal not observing this kernel--property would introduce an imaginary part, for a purely imaginary signal it would introduce real values, and for a complex--valued signal it would mix both of them. We thus need to ensure a real--valued kernel. The complex exponential in \\autoref{eq:shifting} has the required Hermitian property except for its value at the Nyquist--frequency in case of even--sized arrays. In this case we only multiply by the real part of the phase factor! Note that this yield to a positive and negative shift operation not perfectly compensating each other. Another consequence of the undefined underlying signal. This effect can be avoided and a reversible shift can be guaranteed by setting this frequency of the kernel to the real value of 1.0 but this might be less accurate on average for the shift. Note that for shifts not being exactly half-pixels, the inverse shift can be modified such that it perfectly recreates the original signal, even if the first shift used the real part of the kernel at Nyquist--frequency, if the user knows that the operation is an inverse shift: We simply need to replace the real part with one over the real part. \n            \n        \\subsection{Shifting in $N$ Dimensions}\n            As for multidimensional $\\sinc$ interpolation, we similarly can process the shifting in multiple dimensions sequentially.\n            \n    \\subsection{Array Shearing}\n        Since we can shift data by an arbitrary amount via the shift theorem, \n        we can apply it with varying amounts of shifts between the $(N-1)$ dimensional hyperplanes of an $N$ dimensional array. If we vary the shifts linearly with position we obtain a sheared version of the input signal.\n            \n    \\subsection{Array Rotation}\n        A very simple image rotation algorithm is the \"three shear algorithm\" \\cite{Paeth1986:15}.\n        Its essence is that a rotation in two dimensions can be implemented by shearing an image first horizontally, then vertically and finally horizontally again.\n        Mathematically, the rotation matrix (in 2D) with rotation angle $\\theta$ can be separated into three shear matrices:\n        \\begin{equation}\n            \\begin{pmatrix}\n                \\cos(\\theta) & -\\sin(\\theta)\\\\\n                \\sin(\\theta) & \\phantom{-}\\cos(\\theta)\n            \\end{pmatrix} \n            =  \\begin{pmatrix}\n                1 & \\alpha\\\\\n                0 & 1\n            \\end{pmatrix}\n            \\cdot\n             \\begin{pmatrix}\n                1 & 0\\\\\n                \\beta & 1\n            \\end{pmatrix}\n            \\cdot\n             \\begin{pmatrix}\n                1 & \\alpha\\\\\n                0 & 1\n            \\end{pmatrix}\n        \\end{equation}\n        The new parameters are $\\alpha=-\\tan\\left(\\frac{\\theta}{2} \\right)$ and $\\beta=\\sin(\\theta)$\\footnote{See also the more detailed notes of Tobin Fricke: \\url{https://www.ocf.berkeley.edu/~fricke/projects/israel/paeth/rotation_by_shearing.html}.}.\n        Since shearing is a shift operation with different amounts along each line, the complete rotation\n        can be fully expressed with Fourier transforms and element--wise multiplications. Note that care has to be taken to provide additional padding prior to shifting, as the Fourier--based shifts (and thus also the shears) are cyclic in nature.\n\n    \n\n\\section{Examples}\n    In this part we present the main contributions of \\verb|FourierTools.jl| which\n    include \\lstinline{fftshift} alternatives, wrappers for \\lstinline{fft}, $\\mathrm{sinc}$ interpolation, convolutions and shifting, shearing and rotation.\n    Our experiments additionally made use of the packages ArrayInterface.jl\\cite{DifferentialEquations.jl-2017}, BenchmarkTools.jl\\cite{BenchmarkTools.jl-2016} .\n    \n    \\subsection{FFT Helpers}\n        A very common pattern in signal processing is to apply various frequency filters\n        which are multiplied by the signal in Fourier space. \n\\begin{lstlisting}[language=Julia, caption={Typical workflow to manipulate the data in Fourier space. Note that it would be also possible to \\lc{ifftshift(mask)} instead of rearranging the data twice. However, this breaks apart once one has a non-straightforward accessing scheme instead of a plain array which is multiplied.}, \nlabel = {lst:example_render}, \ncaptionpos = b,]\nfunction fft_filter(arr, mask)\n    arr_ft = fftshift(fft(arr))\n    arr_ft .*= mask\n    ifft(ifftshift(arr_ft))\nend\n\nfunction ffts_filter(arr, mask)\n    arr_ft = ffts(arr) \n    arr_ft .*= mask\n    iffts(arr_ft)\nend\n\\end{lstlisting}\n\n\nOur package provides \\lc{ffts} and \\lc{iffts} which automatically applies \\lc{fftshift} and \\lc{ifftshift} after respectively before calling \\lc{fft}.\n\\lc{fftshift} and \\lc{ifftshift} also copy and reshuffle the data. We instead make use of the package\n\\verb|ShiftedArrays.jl|\\footnote{See \\url{https://github.com/bionanoimaging/ShiftedArrays.jl}. Thanks\nto Pietro Vertechi who supported us in implementing \\lc{ShiftedArrays.fftshift} and \\lc{ShiftedArrays.ifftshift}}\nBy keeping track of the total shifts we can avoid to copy the data in between using the \\lc{fftshift} and \\lc{ifftshift} but instead return the original data.\n\nIn \\autoref{code:ffts} we can see the simple benchmark showing the computing time and the total\nallocations needed.\n\\begin{lstlisting}[language=Julia, label={code:ffts}, caption={By using \\lc{ffts} we can save a factor of 2 in memory}, captionpos=b]\njulia> using FourierTools, BenchmarkTools, FFTW, IndexFunArrays\njulia> N = (4000, 3001);\njulia> arr = randn(ComplexF32, N); # 91.583 MiB\njulia> mask = IndexFunArrays.rr(Float32, N) .< 50; # low pass\njulia> @btime fft_filter($arr, $mask); # using fftshift\n  604.883 ms (78 allocations: 366.34 MiB)\njulia> @btime ffts_filter($arr, $mask); # using a fftshift_view\n  596.754 ms (54 allocations: 183.17 MiB)\n\\end{lstlisting}\n\nAdditionally, to \\lc{ffts}, inspired by DipImage\\footnote{\\url{https://diplib.org/}}, we also provide \\lc{ft} which does both a shifting before and after calling \\lc{fft}.\nThe schematic behavior of all different methods is drawn in \\autoref{fig:freq_pos}.\n    \\begin{figure}[h]\n        \\centering\n        \\begin{tikzpicture}\n            \\begin{scope}[shift={(0,00)}]\n                \\draw[->] (2.3, 0.25) -- (3.2, 0.25) node[midway, above] {\\lc{fft}};\n                \\draw[fill=red!50!white] (0, 0) rectangle (0.5, 0.5);\n                \\draw[fill=green!50!white] (3.5, 0) rectangle (4.0, 0.5);\n                \\foreach \\i/\\j/\\k in {0/0/1,1/1/2,2/-2/3,3/-1/4}{\n                    \\draw (\\i/2, 0) rectangle (\\i/2+1/2, 1/2) node[midway] {\\k};\n                    \\draw (3.5+\\i/2, 0) rectangle (3.5+\\i/2+1/2, 1/2)node[midway] {\\j};\n                }\n\n            \\end{scope}\n            \\begin{scope}[shift={(0,-1)}]\n                \\draw[->] (2.3, 0.25) -- (3.2, 0.25) node[midway, above] {\\lc{ffts}};\n                \\draw[fill=red!50!white] (0, 0) rectangle (0.5, 0.5);\n                \\draw[fill=green!50!white] (4.5, 0) rectangle (5.0, 0.5);\n                \\foreach \\i/\\j/\\k in {0/-2/1,1/-1/2,2/0/3,3/1/4}{\n                    \\draw (\\i/2, 0) rectangle (\\i/2+1/2, 1/2)node[midway] {\\k};\n                    \\draw (3.5+\\i/2, 0) rectangle (3.5+\\i/2+1/2, 1/2)node[midway] {\\j};\n                }\n \n            \\end{scope}\n            \\begin{scope}[shift={(0,-2)}]\n                            \\draw[->] (2.3, 0.25) -- (3.2, 0.25) node[midway, above] {\\lc{ft}};\n                \\draw[fill=red!50!white] (1, 0) rectangle (1.5, 0.5);\n                \\draw[fill=green!50!white] (4.5, 0) rectangle (5.0, 0.5);\n                \\foreach \\i/\\j/\\k in {0/-2/1,1/-1/2,2/0/3,3/1/4}{\n                    \\draw (\\i/2, 0) rectangle (\\i/2+1/2, 1/2)node[midway] {\\k};\n                    \\draw (3.5+\\i/2, 0) rectangle (3.5+\\i/2+1/2, 1/2)node[midway] {\\j};\n                }\n            \\end{scope}\n            \\draw[color=white] (1,-2.5) --(2,-2.5);\n        \\end{tikzpicture}\n        \\caption{Schematic description how the different methods interpret the center  position. The red box \n            indicates the center index position in real space and the green box the center position of the 0 frequency. The corresponding inverse routines have the letter i prepended and perform the corresponding transformation from right to left. The intensity scaling is unmodified compared to the underlying fft routine.}\n        \\label{fig:freq_pos}\n    \\end{figure}\n\nIn \\autoref{code:fft_ft_difference} the difference between those methods becomes clear,\nif we transform a delta peak in real space.\n\\begin{lstlisting}[language=Julia, label={code:fft_ft_difference}, caption={Difference between \\lc{fft} and \\lc{ft}.}, captionpos=b]\njulia> fft([1.0, 0.0, 0.0])\n3-element Vector{ComplexF64}:\n 1.0 + 0.0im\n 1.0 + 0.0im\n 1.0 + 0.0im\n\njulia> fft([0.0, 1.0, 0.0])\n3-element Vector{ComplexF64}:\n  1.0 + 0.0im\n -0.5 - 0.8660254037844386im\n -0.5 + 0.8660254037844386im\n\njulia> ft([0.0, 1.0, 0.0])\n3-element ShiftedArrays.CircShiftedVector{ComplexF64, \n                                          Vector{ComplexF64}}:\n 1.0 + 0.0im\n 1.0 + 0.0im\n 1.0 + 0.0im\n\\end{lstlisting}\n\n    \\subsection{Convolution}\n        The filter operation from above, is the same as a convolution of the \\lc{arr} with \\lc{ifft(mask)}.\n\n        Similar to \\lc{plan_fft} we offer a method called \\lc{plan_conv}.\n        The speedup in \\autoref{code:conv} is mainly due to the FFTW planning flag \\lc{FFTW.PATIENT}.\n        For repeated use of \\lc{conv} (e.g. an iterative algorithm) another option is\n        \\lc{plan_conv_buffer} which allocates buffers beforehand and has zero\n        memory consumption during \\lc{conv} calls.\n\\begin{lstlisting}[language=Julia, captionpos=b, caption={Convolution planning. One with memory allocations, the other without.}, label=code:conv]\njulia> mask, pconv = plan_conv(arr, ComplexF32.(iffts(mask)), \n                               flags=FFTW.PATIENT);\n\njulia> @btime pconv(arr);\n  394.561 ms (8 allocations: 366.33 MiB)\n  \njulia> @time mask, pconv_buffer = FourierTools.plan_conv_buffer(\n        arr, ComplexF32.(iffts(mask)), flags=FFTW.PATIENT);\n  0.862628 seconds (156 allocations: 1.073 GiB, 2.29% gc time)\n\njulia> @btime pconv_buffer(arr);\n  348.121 ms (0 allocations: 0 bytes)\n\\end{lstlisting}    \n        \n    \\subsection{Sinc Interpolation}\n        \n        The upsampled (since interpolated) data (dashed blue curve) in \\autoref{fig:resampling} was generated with the source code in \\autoref{code:resampling}. The input \\lc{arr_low} (green crosses) interpreted as sampled according to Nyquist sampling and hence all information is already included in the low sampling.\n        Therefore, a re-evaluation of the Fourier series does not generate new information but\n        just evaluates the sampled data on a new grid with smaller spacing leading\n        to a smoother (interpolated) appearance.\n\n\\begin{lstlisting}[language=Julia, label={code:resampling}, caption={Resampling of a Nyquist sampled signal.}, captionpos=b] \nN_low = 64\nx_min = 0.0 \nx_max = 8*2π\n\nxs_low = range(x_min, x_max, length=N_low+1)[1:N_low]\nxs_high = range(x_min, x_max, length=5000)[1:end-1]\nf(x) = sin(0.5*x) + cos(x) + cos(2 * x) + sin(0.25*x)\narr_low = f.(xs_low)\narr_high = f.(xs_high)\n\nN = 1000\nxs_interp = range(x_min, x_max, length=N+1)[1:N]\narr_interp = resample(arr_low, N)\n\\end{lstlisting}\n\n         \\begin{figure}[h]\n             \\centering\n             \\includegraphics[width=.45\\textwidth]{figures/resampling.pdf}\n             \\caption{The array with low sampling, $\\sinc$ interpolation and high sampling all contain the same information.}\n             \\label{fig:resampling}\n         \\end{figure}\n    \n\n %   In cases where the input signal is Nyquist sampled, Sinc interpolation can lead\n %   to results which look far superior to classic interpolation schemes\n    \n %   \\begin{figure}\n %       \\centering\n %       \\subcaptionbox{$\\SI{32}{px}\\times\\SI{32}{px}$}{\\includegraphics[width=.15\\textwidth]{%%figures/jinc_small.png}}\n   %     \\subcaptionbox{\\lc{ImageTransformations.imresize}}{\\includegraphics[width=.15\\textwid%th]{figures/jinc_imresize.png}}\n%        \\subcaptionbox{\\lc{FourierTools.resample}}{\\includegraphics[width=.15\\textwidth]{figures/jinc_sinc.png}}\n  %      \\caption{Caption}\n  %      \\label{fig:sinc_interp_image}\n   % \\end{figure}\n\n\n    \\subsection{Subpixel Shifting of Signals}\n    \n    In \\autoref{code:shifting} we show that we can shift a Nyquist sampled signal by an sub pixel amount.\n    We evaluate the function \\lc{f(x)} shifted by a distance of $0.25$, a quarter of its period. Since the original signal is periodic on the grid and was sampled according to the Nyquist limit, the full information\n    of the signal was captured and hence an evaluation of the Fourier series provides identical results up to rounding errors. \n    \n    \n\\begin{lstlisting}[language=Julia, label={code:shifting}, caption={Shifting a Nyquist sampled signal by a sub pixel amount.}, captionpos=b]       \njulia> f(x) = sin(x * 2π / 5)\nf (generic function with 1 method)\n\njulia> x = 0:4\n0:4\n\njulia> transpose(f.(x))\n1x5 transpose(::Vector{Float64}) with eltype Float64:\n 0.0  0.951057  0.587785  -0.587785  -0.951057\n\njulia> transpose(f.(x .- 0.25))\n1x5 transpose(::Vector{Float64}) with eltype Float64:\n -0.309017  0.809017  0.809017  -0.309017  -1.0\n\njulia> transpose(shift(f.(x), 0.25))\n1x5 transpose(::Vector{Float64}) with eltype Float64:\n -0.309017  0.809017  0.809017  -0.309017  -1.0\n\\end{lstlisting}        \nAdditionally, shifting based on Fourier transforms is also fully revertible, with the only exception being the even--sized Nyquist frequency as mentioned above.\n\n\\subsubsection{Handling the Nyquist Amplitude}\nIn \\autoref{code:shifting2} we demonstrate that handling the Nyquist amplitude\nin the phase ramp is crucial for correct output results.\nOtherwise, shifting a real signal would result in a nonzero imaginary part.\nFor a real signal one could also take the real part at the end.\n\n\\begin{lstlisting}[language=Julia, label={code:shifting2}, caption={Fixing the Nyquist amplitude of the shifting exponential phase ramp.}, captionpos=b] \njulia> x = [1.0, 0.0, 1.0, 0.0];\n\njulia> exp_term = cispi.(2 .* 0.5 .* \n                         fftfreq(size(x, 1))) # shift 0.5 indices\n4-element Vector{ComplexF64}:\n                1.0 + 0.0im\n 0.7071067811865476 + 0.7071067811865476im\n                0.0 - 1.0im\n 0.7071067811865476 - 0.7071067811865476im\n \njulia> ifft(exp_term) # real space kernel is not real\n4-element Vector{ComplexF64}:\n   0.6035533905932737 - 0.25im\n -0.10355339059327379 + 0.25im\n -0.10355339059327379 - 0.25im\n   0.6035533905932737 + 0.25im \n \njulia> ifft(fft(x) .* exp_term) # contains imaginary parts\n4-element Vector{ComplexF64}:\n 0.5 - 0.5im\n 0.5 + 0.5im\n 0.5 - 0.5im\n 0.5 + 0.5im\n\njulia> exp_term[div(size(x, 1), 2) + 1] = real(exp_term[div(size(x, 1), 2) + 1])\n0.0\n\njulia> ifft(exp_term) # real space kernel is real\n4-element Vector{ComplexF64}:\n   0.6035533905932737 + 0.0im\n -0.10355339059327379 + 0.0im\n -0.10355339059327379 + 0.0im\n   0.6035533905932737 + 0.0im\n\n\njulia> ifft(fft(x) .* exp_term) # real output\n4-element Vector{ComplexF64}:\n 0.5 + 0.0im\n 0.5 + 0.0im\n 0.5 + 0.0im\n 0.5 + 0.0im\n\\end{lstlisting}        \n\nAlso for complex--valued signals this modification is required, as the real and imaginary part would mix. \nThis is demonstrated in \\autoref{code:shifting3} where we first shift again\nby the na\\\"ive kernel. And as we can see, shifting the signal with the wrong kernel, can lead to completely wrong results.\n% I disagree. I think it is matter of interpretation here.\n% There is no right of wrong in this case.\n\\begin{lstlisting}[language=Julia, label={code:shifting3}, caption={Handling of Nyquist frequency is also for complex signals important.}, captionpos=b] \njulia> x = [1.0 + 1.0im, 0, 1.0 + 1.0im, 0]\n4-element Vector{ComplexF64}:\n 1.0 + 1.0im\n 0.0 + 0.0im\n 1.0 + 1.0im\n 0.0 + 0.0im\n\njulia> ifft(fft(x) .* cispi.(2 .* 0.5 .*fftfreq(size(x, 1)))) # wrong because of Nyquist amplitude\n4-element Vector{ComplexF64}:\n 1.0 + 0.0im\n 0.0 + 1.0im\n 1.0 + 0.0im\n 0.0 + 1.0im\n\njulia> shift(x, 0.5) # Using the correct kernel\n4-element Vector{ComplexF64}:\n 0.5 + 0.5im\n 0.5 + 0.5im\n 0.5 + 0.5im\n 0.5 + 0.5im\n\\end{lstlisting}        \n\n\n\n    \\subsection{Shearing and Rotation}\n        \\autoref{fig:shearandrotation} shows the results of shearing and rotating an image.\n        The image is provided by \\verb|TestImages.jl|\\footnote{\\url{https://github.com/JuliaImages/TestImages.jl}}.\n        Since we do not resize the image before, the shearing happens completely within the boundaries of the image.\n        This circular property is induced by the circularity assumption of the DFT itself.\n        The rotated image has even more complex patterns in the boundary regions.\n        The reason is that the rotation is based on three shears and hence \n        each shear introduces circular artifacts which are shifted again by following shearing.\n        \\begin{figure}[h]\n            \\subcaptionbox{Sheared by \\SI{150}{px}.\\label{fig:sheared}}{\\includegraphics[width=.23\\textwidth]{figures/img_sheared.png}}\n            \\subcaptionbox{Rotated by \\SI{50}{\\degree}.\\label{fig:rotated}}{\\includegraphics[width=.23\\textwidth]{figures/img_rotated.png}}\n            \\caption{Mandril testimage.}\n            \\label{fig:shearandrotation}\n        \\end{figure}\n        Fortunately, those artifacts are completely revertible\\footnote{in some case the shifting exponential multiplies with $0$ which cannot be recovered.}.\n        To rotate without such boundary artifacts, one has to pre-allocate a suitable array beforehand.\n        \n\\section{Conclusion}\n    \\verb|FourierTools.jl| offers convenient functions to handle data in Fourier space.\n    In additon to those functions, we also provide algorithms for different kinds of array manipulation.\n    % Hier wird es total Cyptisch!\n    The advantage of those algorithms is, that they do not add additional information \n    to the signal but instead rely on the available information\n    by reinterpreting the information Fourier space.\n\n\\section{Acknowledgement}\nWe want to thank all people participating in the Discourse discussion\\footnote{\\url{https://discourse.julialang.org/t/sinc-interpolation-based-on-fft/52512}} and contributing to the clarification of how the boundary is the best handled.\nEspecially, Steven G. Johnson pointed out the underlying mathematics.\n\n\n\\input{bib.tex}\n\n\\end{document}\n% Inspired by the International Journal of Computer Applications template\n", "meta": {"hexsha": "aced417d011101f38d857e6500bcffcb20cb2408", "size": 38657, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "paper/paper.tex", "max_stars_repo_name": "bionanoimaging/FourierTools.jl", "max_stars_repo_head_hexsha": "c8a37c8f38b0b9897fac2be1bf3c1e109f844964", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 27, "max_stars_repo_stars_event_min_datetime": "2021-03-30T23:15:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-08T14:20:15.000Z", "max_issues_repo_path": "paper/paper.tex", "max_issues_repo_name": "bionanoimaging/FourierTools.jl", "max_issues_repo_head_hexsha": "c8a37c8f38b0b9897fac2be1bf3c1e109f844964", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2021-03-28T13:01:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-22T09:43:02.000Z", "max_forks_repo_path": "paper/paper.tex", "max_forks_repo_name": "bionanoimaging/FourierTools.jl", "max_forks_repo_head_hexsha": "c8a37c8f38b0b9897fac2be1bf3c1e109f844964", "max_forks_repo_licenses": ["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.9322533137, "max_line_length": 1197, "alphanum_fraction": 0.6594924593, "num_tokens": 11017, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513620489619, "lm_q2_score": 0.839733963661418, "lm_q1q2_score": 0.7526127086903194}}
{"text": "\\subsection{Integration by Parts (Reversing the Product Rule)}\r\nWhen a $u$-substitution won't work because the integrand is the product of two functions that are not related by a derivative, integration by parts may be able to help us.\r\nStarting from the product rule\\footnote{This justification isn't completely rigorous because you can't always treat differentials like fractions, but the overall result is correct.},\r\n\\begin{align*}\r\n\t\\dd{}{x}{(uv)} &= u\\dd{v}{x} + v\\dd{u}{x} \\\\\r\n\t\\int{\\dd{}{x}{(uv)}\\d{x}} &= \\int{u\\dd{v}{x}\\d{x}} + \\int{v\\dd{u}{x}\\d{x}} \\\\\r\n\t\\int{\\d{(uv)}} &= \\int{u\\d{v}} + \\int{v\\d{u}} \\\\\r\n\tuv &= \\int{u\\d{v}} + \\int{v\\d{u}} \\\\\r\n\t\\int{u\\d{v}} &= uv - \\int{v\\d{u}}.\r\n\\end{align*}\r\n\r\nEssentially, if we are integrating a function that is a product of something we can differentiate ($u$) and something we can integrate ($\\d{v}$), then we can do integration by parts.\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{x\\sin{x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tSince $x$ and $\\sin{x}$ don't have any parts that are related by a derivative, a $u$-substitution wouldn't be helpful.\r\n\tHowever, we know how to differentiate $x$ and integrate $\\sin{x}$, so integration by parts is a good strategy to try.\r\n\t\\begin{align*}\r\n\t\tu = x &\\text{ and } \\d{u} = \\d{x} \\\\\r\n\t\t\\d{v} = \\sin{x}\\d{x} &\\text{ and } v =\\footnotemark -\\cos{x} \\\\\r\n\t\t\\int{x\\sin{x}\\d{x}} &= -x\\cos{x} - \\int{-\\cos{x}\\d{x}} \\\\\r\n\t\t&= -x\\cos{x} + \\sin{x} + C.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\footnotetext{We don't include the $+C$ when integrating $\\d{v}$. We'll still include one at the end.}\r\n\r\n\\subsubsection{LIPET (How to choose $u$)}\r\nThe tricky part of integration by parts is choosing what should be $u$ and what should be $\\d{v}$.\r\nIf in the previous example we had instead chosen $u=\\sin{x}$, we would have gotten that $\\int{x\\sin{x}\\d{x}} = \\frac{x^2}{2}-\\int{\\frac{x^2}{2}\\cos{x}\\d{x}}$, which although true, doesn't give us an easier function to integrate.\r\nGenerally, we want to choose $u$ such that $\\d{u}$ is a ``simplier'' function to integrate.\r\nThis can mean a lower-degree polynomial, or getting rid of functions like $\\ln{x}$ and replacing them with polynomials.\r\nYou can remember the acronym \\textbf{LIPET} as a guide to help you.\r\n\\begin{itemize}[align=left, leftmargin=0.66in]\r\n\t\\item[\\textbf{L}ogarithms]\r\n\t\\item[\\textbf{I}nverse Trig Functions]\r\n\t\\item[\\textbf{P}olynomials]\r\n\t\\item[\\textbf{E}xponentials]\r\n\t\\item[\\textbf{T}rig Functions]\r\n\\end{itemize}\r\n\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{x^3\\ln{x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tFollowing LIPET, we select $u = \\ln{x}$.\r\n\t\\begin{align*}\r\n\t\tu = \\ln{x} &\\text{ and } \\d{u} = \\frac{\\d{x}}{x} \\\\\r\n\t\t\\d{v} = x^3\\d{x} &\\text{ and } v = x^4/4 \\\\\r\n\t\t\\int{x^3\\ln{x}\\d{x}} &= \\frac{x^4\\ln{x}}{4} - \\int{\\frac{x^3}{4}\\d{x}} \\\\\r\n\t\t&= \\frac{x^4\\ln{x}}{4} - \\frac{x^4}{16} + C.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\r\nSometimes, we might have to do integration by parts multiple times.\r\nIt might seem like integration by parts is leading us in circles, but this can actually be a good thing, allowing us to solve the integral if we're observant.\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{e^{-x}\\cos{x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tFollowing LIPET, $u=e^{-x}$.\r\n\t\\begin{align*}\r\n\t\tu = e^{-x} &\\text{ and } \\d{u} = -e^{-x}\\d{x} \\\\\r\n\t\t\\d{v} = \\cos{x}\\d{x} &\\text{ and } v = \\sin{x} \\\\\r\n\t\t\\int{e^{-x}\\cos{x}\\d{x}} &= e^{-x}\\sin{x} + \\int{e^{-x}\\sin{x}\\d{x}}.\r\n\t\\end{align*}\r\n\t\r\n\tFollowing LIPET, $u = e^{-x}$ again.\r\n\t\\begin{align*}\r\n\t\tu = e^{-x} &\\text{ and } \\d{u} = -e^{-x}\\d{x} \\\\\r\n\t\t\\d{v} = \\sin{x}\\d{x} &\\text{ and } v = -\\cos{x} \\\\\r\n\t\te^{-x}\\sin{x} + \\int{e^{-x}\\cos{x}\\d{x}} &= e^{-x}\\sin{x} - e^{-x}\\cos{x} - \\int{e^{-x}\\cos{x}\\d{x}}\r\n\t\\end{align*}\r\n\t\r\n\tIt might seem like we've hit a dead end, since we're back trying to integrate the exact same function we started with.\r\n\tHowever, if we rearrange our equations a little bit, we'll see that we're actually really close to a solution.\r\n\t\\begin{align*}\r\n\t\t\\int{e^{-x}\\cos{x}\\d{x}} &= e^{-x}\\sin{x} - e^{-x}\\cos{x} - \\int{e^{-x}\\cos{x}\\d{x}} \\\\\r\n\t\t2\\int{e^{-x}\\cos{x}\\d{x}} &=\\footnotemark\\hspace{5pt} e^{-x}\\sin{x} - e^{-x}\\cos{x} + C \\\\\r\n\t\t\\int{e^{-x}\\cos{x}\\d{x}} &= \\frac{e^{-x}\\sin{x} - e^{-x}\\cos{x}}{2} + C.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\\footnotetext{We need to remember to include a $+C$. Usually it would come from completely solving an integral, but here we just did some rearranging.}\r\n\r\n\\subsubsection{Inverse Trig Functions}\r\nWe can use tabular integration to integrate the inverse trig functions.\r\nWe'll also end up applying two different strategies: Integration by parts and $u$-substitution to solve one integral.\r\n\\begin{align*}\r\n\tu = \\arcsin{x} &\\text{ and } \\d{u} = \\frac{1}{\\sqrt{1-x^2}} \\\\\r\n\t\\d{v} = \\d{x} &\\text{ and } v = x \\\\\r\n\t\\int{\\arcsin{x}\\d{x}} &= x\\arcsin{x} - \\int{\\frac{x}{\\sqrt{1-x^2}}\\d{x}} \\\\\r\n\tu = 1-x^2 &\\text{ and } x\\d{x} = \\frac{-1}{2}\\d{u} \\text{ (this is a different $u$ than before)} \\\\\r\n\t&= x\\arcsin{x} + \\frac{1}{2}\\int{\\frac{\\d{u}}{\\sqrt{u}}} \\\\\r\n\t&= x\\arcsin{x} + \\frac{1}{2}\\left(\\frac{\\sqrt{u}}{1/2}\\right) + C \\\\\r\n\t&= x\\arcsin{x} + \\sqrt{u} + C \\\\\r\n\t&= x\\arcsin{x} + \\sqrt{1-x^2} + C.\r\n\\end{align*}\r\n\r\nWe can do the exact same thing to find the integral of $\\arccos{x}$.\r\n\\begin{equation*}\r\n\t\\int{\\arccos{x}\\d{x}} = x\\arccos{x} - \\sqrt{1-x^2} + C.\r\n\\end{equation*}\r\n\r\n\r\nThe integration by parts into $u$-substitution idea even works for $\\arctan{x}$.\r\n\\begin{align*}\r\n\tu = \\arctan{x} &\\text{ and } \\d{u} = \\frac{1}{1+x^2} \\\\\r\n\t\\d{v} = \\d{x} &\\text{ and } v = x \\\\\r\n\t\\int{\\arctan{x}\\d{x}} &= x\\arctan{x} - \\int{\\frac{x}{1+x^2}\\d{x}} \\\\\r\n\tu = 1+x^2 &\\text{ and } x\\d{x} = \\frac{1}{2}\\d{u} \\text{ (this is a different $u$ than before)} \\\\\r\n\t&= x\\arctan{x} - \\frac{1}{2}\\int{\\frac{\\d{u}}{u}} \\\\\r\n\t&= x\\arctan{x} - \\frac{1}{2}\\ln{\\abs{u}} + C \\\\\r\n\t&= x\\arctan{x} - \\frac{1}{2}\\ln{\\abs{1+x^2}} + C.\r\n\\end{align*}\r\n\r\nWe can do the same thing to find the integral of $\\arccot{x}$.\r\n\\begin{equation*}\r\n\t\\int{\\arccot{x}\\d{x}} = x\\arccot{x} + \\frac{1}{2}\\ln{\\abs{1+x^2}} + C.\r\n\\end{equation*}\r\n\r\n\r\nThe integrals of $\\arcsec{x}$ and $\\arccsc{x}$ involve a special type of function you probably haven't seen before, $\\text{arccosh}{x}$.\r\nHowever, if you're familiar with this function and it's derivative, you can still apply integration by parts to find their antiderivatives.\r\n\\begin{align*}\r\n\t\\int{\\arcsec{x}\\d{x}} &= x\\arcsec{x} - \\text{arccosh}{x} + C \\\\\r\n\t\\int{\\arccsc{x}\\d{x}} &= x\\arccsc{x} + \\text{arccosh}{x} + C.\r\n\\end{align*}\r\n\r\n\\subsubsection{Tabular Integration}\r\nIf we're trying to integrate a function like $x^4e^{-x}$ using integration by parts, we quickly realize that we'll need to perform integration by parts 4 times, choosing the same value for $\\d{v}$ every time.\r\nSince this would be rather tedious and repetitive, we can extract the essential elements of integration by parts into a table and perform integration by parts many times without needing to repeat ourselves.\r\n\r\n\r\nIn integration by parts, we essentially choose one function ($u$) to continually differentiate and another ($\\d{v}$) to continually integrate.\r\nWe then alternate signs with each iteration of integration by parts, due to negative signs canceling each other out.\r\nSo, in our table, we'll have three columns, one where we'll continually differentiate a function, usually until its a constant, a column to keep track of the sign, and a final column that we'll continually integrate.\r\nThen, all we'll have to do is multiply across columns and sum across rows to get our result from repeated integration by parts.\r\n\r\n\\begin{example}\r\n\tSolve the following indefinite integral:\r\n\t\\begin{equation*}\r\n\t\t\\int{x^4e^{-x}\\d{x}}.\r\n\t\\end{equation*}\r\n\\end{example}\r\n\\begin{answer}\r\n\tFollowing LIPET, $x^4$ is our function to differentiate and $e^{-x}$ is our function to integrate.\r\n\tSetting up our table,\r\n\t\\begin{figure}[H]\r\n\t\t\\label{tabular}\r\n\t\t\\centering\r\n\t\t\\includegraphics[width = 0.5\\textwidth]{./integrals/integration_by_parts/tabular.png}\r\n\t\\end{figure}\r\n\tMultiplying across each arrow and summing,\r\n\t\\begin{align*}\r\n\t\t\\int{x^4e^{-x}\\d{x}} &= x^4\\left(-e^{-x}\\right) + 4x^3(-1)e^{-x} + 12x^2\\left(-e^{-x}\\right) + 24x(-1)e^{-x} + 24\\left(-e^{-x}\\right) + C \\\\\r\n\t\t&= -x^4e^{-x} - 4x^3e^{-x} - 12x^2e^{-x} - 24xe^{-x} - 24e^{-x} + C \\\\\r\n\t\t&= -e^{-x}\\left(x^4 + 4x^3 + 12x^2 + 24x + 24\\right) + C.\r\n\t\\end{align*}\r\n\\end{answer}", "meta": {"hexsha": "303b2e6ed8937bb8801a4c52dbfc3bd18469b8f7", "size": 8559, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/integrals/integration_by_parts/integration_by_parts.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/integrals/integration_by_parts/integration_by_parts.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/integrals/integration_by_parts/integration_by_parts.tex", "max_forks_repo_name": "aneziac/Math-Summaries", "max_forks_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 10, "max_forks_repo_forks_event_min_datetime": "2020-04-10T05:41:17.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-17T15:21:12.000Z", "avg_line_length": 50.6449704142, "max_line_length": 229, "alphanum_fraction": 0.6279939245, "num_tokens": 3066, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110396870287, "lm_q2_score": 0.8438950947024555, "lm_q1q2_score": 0.7525949617933804}}
{"text": "\\section{Antiderivatives and Indefinite Integration}\\label{sec:antider}\n\nWe have spent considerable time considering the derivatives of a function and their applications. In the following chapters, we are going to starting thinking in ``the other direction.'' That is, given a function $f(x)$, we are going to consider functions $F(x)$ such that $F'(x) = f(x)$. There are numerous reasons this will prove to be useful: these functions will help us compute areas, volumes, mass, force, pressure, work, and much more.\n\n\n\n\nGiven a function $y=f(x)$, a \\textit{differential equation} is one that incorporates $y$, $x$, and the derivatives of $y$. For instance, a simple differential equation is: $$y' = 2x.$$\n\nSolving a differential equation amounts to finding a function $y$ that satisfies the given equation. Take a moment and consider that equation; can you find a function $y$ such that $y' = 2x$?\n\nCan you find another?\n\nAnd yet another?\n\nHopefully one was able to come up with at least one solution: $y = x^2$. ``Finding another'' may have seemed impossible until one realizes that a function like $y=x^2+1$ also has a derivative of $2x$. Once that discovery is made, finding ``yet another'' is not difficult; the function $y = x^2 + 123,456,789$ also has a derivative of $2x$. The differential equation $y' = 2x$ has many solutions. This leads us to some definitions.\n%\\enlargethispage{3\\baselineskip}\n\n\\begin{definition}{Antiderivatives and Indefinite Integrals}{antider}\n{Let a function $f(x)$ be given. An \\textbf{antiderivative} of $f(x)$ on an open interval $ I $ is a function $F(x)$ such that $\\Fp(x) = f(x)$ for all $ x\\in I $.\\index{antiderivative}\\index{indefinite integral}\\index{integration!indefinite}\\\\\n\nThe set of all antiderivatives of $f(x)$ is referred to as the \\textit{General Antiderivative}, ot the \\textbf{(indefinite) integral of $f$}, denoted by $$\\int f(x) \\ dx.$$\n}\n\\end{definition}\n\nThe process of finding the indefinite integral is called \\dfont{integration} (or \\dfont{integrating $f(x)$}).\nMake a note about our definition: we refer to \\textit{an} antiderivative of $f$, as opposed to \\textit{the} antiderivative of $f$, since there is \\textit{always} an infinite number of them. We often use upper-case letters to denote antiderivatives.\n\nKnowing one antiderivative of $f$ allows us to find infinitely more, simply by adding a constant. Not only does this give us \\textit{more} antiderivatives, it gives us \\textit{all} of them.\n\n\\begin{theorem}{Antiderivative Forms}{antideriv_const}\n{Let $F(x)$ and $G(x)$ be antiderivatives of $f(x)$. Then there exists a constant $C$ such that $$G(x) = F(x) + C.$$\n}\n\\end{theorem}\n\nTo see why this is true, observe that if $ F $ and $ G $ are both antiderivatives of $ f $, then $ F'=G'=f $, so $ \\frac{d}{dx}(G-F)=G'-F'=f-f=0$, so $ G-F $ is a constant function giving $ G-F=C $, so $ G=F+C$.\n\nSo, given a function $f$ and one of its antiderivatives $F$, we know \\textit{all} antiderivatives of $f$ have the form $F(x) + C$ for some constant $C$. Using Definition \\ref{def:antider}, we can say that $$\\int f(x) \\ dx = F(x) + C.$$\n\nLet's analyze this indefinite integral notation.\\index{integration!notation}\n\n\n\\begin{figure}\n\\begin{center}\n\\begin{tikzpicture}[scale=1.5,>=latex]\n%\\draw [thin,step=1cm] (0,0) grid  (3,3);\n\\draw  (2,2) node {$\\displaystyle \\int f(x)\\ dx=F(x)+C$};\n\n\\draw [{\\colorone}] (1,1) node [](a) {\\scriptsize Integrand};\n\\draw [{\\colorone},->] (a) -- (1.1,1.75);\n\n\\draw [{\\colorone}] (0,3) node [text width=32pt,align=center] (b) {\\scriptsize \\centering Integration\\\\[-5pt] symbol};\n\\draw [{\\colorone},->] (b) -- (.6,2.1);\n\n\\draw [{\\colorone}] (2,3) node [text width=32pt,align=center] (c) {\\scriptsize \\centering Differential\\\\[-5pt] of $x$};\n\\draw [{\\colorone},->] (c) -- (1.7,2.3);\n\n\\draw [{\\colorone}] (2.5,1) node [text width=32pt,align=center] (c) {\\scriptsize \\centering One\\\\[-5pt] antiderivative};\n\\draw [{\\colorone},->] (c) -- (2.5,1.75);\n\n\\draw [{\\colorone}] (3.5,3) node [text width=35pt,align=center] (c) {\\scriptsize \\centering Constant of\\\\[-5pt] integration};\n\\draw [{\\colorone},->] (c) -- (3.45,2.3);\n\\end{tikzpicture}\n\n\\caption{Understanding the indefinite integral notation.\\label{fig:anti1}}\n\\end{center}\n\\end{figure}\n\n%\\includegraphics{figures/figanti1}\n%\\captionsetup{type=figure}%\n%\\caption{Understanding the indefinite integral notation.}\\label{fig:anti1}\n\n\nFigure \\ref{fig:anti1} shows the typical notation of the indefinite integral. The integration symbol, $\\int$, is in reality an ``elongated S,'' representing ``take the sum.'' We will later see how \\textit{sums} and \\textit{antiderivatives} are related.\n\nThe function we want to find an antiderivative of is called the \\textit{integrand}. It contains the differential of the variable we are integrating with respect to. The $\\int$ symbol and the differential $dx$ are not ``bookends'' with a function sandwiched in between; rather, the symbol $\\int$ means ``find all antiderivatives of what follows,'' and the function $f(x)$ and $dx$ are multiplied together; the $dx$ does not ``just sit there.''\n\nLet's practice using this notation.\\\\\n\n\n\\begin{example}{Evaluating indefinite integrals}{ex_anti2}{\nEvaluate $\\displaystyle \\int \\sin x\\ dx.$}\n\\end{example}\n\\begin{solution}\n{We are asked to find all functions $F(x)$ such that $\\Fp(x) = \\sin x$. Some thought will lead us to one solution: $F(x) = -\\cos x$, because $\\frac{d}{dx}(-\\cos x) = \\sin x$.\n\nThe indefinite integral of $\\sin x$ is thus $-\\cos x$, plus a constant of integration. So:\n$$\\int \\sin x \\ dx = -\\cos x + C.$$\n\\vskip-\\baselineskip\n} \n\\end{solution}\n\n\n{\\bf Common mistakes:}\nOne habit students make with integrals is to \\ifont{drop the dx} at the end of the integral.\nThis is required! Think of the integral as a set of parenthesis.\nBoth are required so it is clear where the integrand ends and what variable you are integrating with respect to.\n\nAnother common mistake is to \\ifont{forget the +C} for indefinite integrals.\n\n\nA commonly asked question is ``What happened to the $dx$?'' The unenlightened response is ``Don't worry about it. It just goes away.'' A full understanding includes the following.\n\nThis process of \\textit{antidifferentiation} is really solving a \\textit{differential} question. The integral $$\\int \\sin x\\ dx$$ presents us with a differential, $dy = \\sin x\\ dx$. It is asking: ``What is $y$?'' We found lots of solutions, all of the form $y = -\\cos x+C$.\n\n%We can view integration in the following way. \nLetting $dy = \\sin x\\ dx$,  rewrite \n$$\\int \\sin x \\ dx \\quad \\text{as}\\quad \\int  dy.$$\nThis is asking: ``What functions have a differential of the form $dy$?'' The answer is ``Functions of the form $y+C$, where $C$ is a constant.'' What is $y$? We have lots of choices, all differing by a constant; the simplest choice is $y = -\\cos x$.\n\nUnderstanding all of this is more important later as we try to find antiderivatives of more complicated functions. In this section, we will simply explore the rules of indefinite integration, and one can succeed for now with answering ``What happened to the $dx$?'' with ``It went away.''\n\n\n\nLet's practice once more before stating integration rules.\\\\\n\n\\begin{example}{Evaluating indefinite integrals}{ex_anti3}{\nEvaluate $\\ds \\int (3x^2 + 4x+5)\\ dx$.}\n\\end{example}\n\n\\begin{solution}\n{We seek a function $F(x)$ whose derivative is $3x^2+4x+5$. When taking derivatives, we can consider functions term--by--term, so we can likely do that here.\n\nWhat functions have a derivative of $3x^2$? Some thought will lead us to a cubic, specifically $x^3+C_1$, where $C_1$ is a constant. \n\nWhat functions have a derivative of $4x$? Here the $x$ term is raised to the first power, so we likely seek a quadratic. Some thought should lead us to $2x^2+C_2$, where $C_2$ is a constant.\n\nFinally, what functions have a derivative of $5$? Functions of the form $5x+C_3$, where $C_3$ is a constant.\n\nOur answer appears to be \n$$\\int (3x^2+4x+5)\\ dx = x^3+C_1+2x^2+C_2+5x+C_3.$$ We do not need three separate constants of integration; combine them as one constant, giving the final answer of \n$$\\int (3x^2+4x+5)\\ dx = x^3+2x^2+5x+C.$$\n\nIt is easy to verify our answer; take the derivative of $x^3+2x^3+5x+C$ and see we indeed get $3x^2+4x+5$.\n}\n\\end{solution}\n\n\nThis final step of ``verifying our answer'' is important both practically and theoretically. In general, taking derivatives is easier than finding antiderivatives so checking our work is easy and vital as we learn.\n\nWe also see that taking the derivative of our answer returns the function in the integrand. Thus we can say that: $$\\frac{d}{dx}\\left(\\int f(x)\\ dx\\right) = f(x).$$\nDifferentiation ``undoes'' the work done by antidifferentiation. \n\nThe table at the end of Chapter 4  gave a list of the derivatives of common functions we had learned at that point. We restate part of that list here to stress the relationship between derivatives and antiderivatives. This list will also be useful as a glossary of common antiderivatives as we learn.\n\n%\\newlength{\\bh}%box height\n%\\newlength{\\bd}%box depth\n%\\settoheight{\\bh}{$\\frac{d}{dx}$}\n%\\settodepth{\\bd}{$\\frac{d}{dx}$}\n\n%\\newcommand{\\myrule}{\\rule[-\\bd]{0pt}{\\bh+\\bd}}%\\ $\\frac{d}{dx}$\n%\\newcommand{\\myrule}{\\rule[-4pt]{0pt}{13pt}}%\\ $\\frac{d}{dx}$\n\n\\begin{theorem}{Derivatives and Antiderivatives}{indef_alg}\n\\begin{minipage}[t]{.45\\textwidth}\nCommon Differentiation Rules\\rule[-2pt]{0pt}{1pt}\n\\begin{enumerate}\n\\item \\myrule$\\frac{d}{dx}\\big(cf(x) \\big) = c\\cdot \\fp(x)$\n\\item \\myrule$\\frac{d}{dx}\\big(f(x)\\pm g(x) \\big) = $\n\\vskip .05\\baselineskip\n\\myrule$\\fp(x)\\pm g'(x)$\n\\item $\\frac{d}{dx}\\big(C \\big) = 0$\\myrule\n\\item $\\frac{d}{dx}\\big(x \\big) = 1$\\myrule\n\\item $\\frac{d}{dx}\\big(x^n \\big) = n\\cdot x^{n-1}$\\myrule\n\\item $\\frac{d}{dx}\\big(\\sin x \\big) = \\cos x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\cos x \\big) = -\\sin x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\tan x \\big) = \\sec^2 x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\csc x \\big) = -\\csc x\\cot x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\sec x \\big) = \\sec x\\tan x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\cot x \\big) = -\\csc^2 x$\\myrule\n\\item $\\frac{d}{dx}\\big(e^ x \\big) = e^x$\\myrule\n\\item $\\frac{d}{dx}\\big(a^x \\big) = \\ln a\\cdot a^x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\ln x \\big) =\\frac{d}{dx}\\big(\\ln |x| \\big) = \\frac1 x$\\myrule\n\\item $\\frac{d}{dx}\\big(\\cosh x\\big) = \\sinh x$\n\\item $\\frac{d}{dx}\\big(\\sinh x\\big) = \\cosh x$\n\\item $\\frac{d}{dx}\\big(\\ln(\\cosh x)\\big) = \\tanh x$\n\\item $\\frac{d}{dx}\\big(\\ln(\\sinh x)\\big) = \\coth x$\n\\item $\\ds \\frac{d}{dx}\\big(\\sin^{-1}(x)\\big) = \\frac{1}{\\sqrt{1-x^2}}$ \\label{invsin} \n%\\item $\\ds \\frac{d}{dx}\\big(\\sec^{-1}(x)\\big) = \\frac{1}{ x \\sqrt{x^2-1}}$\n\\item $\\ds \\frac{d}{dx}\\big(\\tan^{-1}(x)\\big) = \\frac{1}{1+x^2}$ \\label{invtan}\n%\\item $\\frac{d}{dx}\\big(\\csch x\\big) = -\\csch x\\coth x$\n%\\item $\\frac{d}{dx}\\big(\\coth x\\big) = -\\csch^2x$\n\n\\end{enumerate}\n\\end{minipage}\n\\begin{minipage}[t]{.55\\textwidth}\nCommon Indefinite Integral Rules\\rule[-2pt]{0pt}{1pt}\n\\begin{enumerate}\n\\item \\myrule$\\int c\\cdot f(x)\\ dx = c\\cdot \\int f(x)\\ dx$\n\\item \\myrule$\\int \\big(f(x)\\pm g(x)\\big)\\ dx =$\n\\vskip .05\\baselineskip\n\\myrule$ \\int f(x)\\ dx\\pm \\int g(x)\\ dx$\n\\item $\\int 0\\ dx = C$\\myrule\n\\item $\\int 1\\ dx = \\int dx = x+C$\\myrule\n\\item $\\int x^n\\ dx =\\frac{1}{n+1}x^{n+1}+ C$\\quad {\\scriptsize ($n\\neq -1$)}\\myrule\n\\item $\\int \\cos x\\ dx = \\sin x+C$\\myrule\n\\item $\\int \\sin x\\ dx = -\\cos x+C$\\myrule\n\\item $\\int \\sec^2 x\\ dx = \\tan x+C$\\myrule\n\\item $\\int \\csc x\\cot  x\\ dx = -\\csc x+C$\\myrule\n\\item $\\int \\sec x\\tan x\\ dx = \\sec x+C$\\myrule\n\\item $\\int \\csc^2 x\\ dx = -\\cot x+C$\\myrule\n\\item $\\int e^x\\ dx = e^x+C$\\myrule\n\\item $\\int a^x\\ dx = \\frac{1}{\\ln a}\\cdot a^x+C$\\myrule\n\\item $\\int \\frac{1}x\\ dx = \\ln |x|+C$\\myrule\n\\item $\\ds\\int \\cosh x\\ dx = \\sinh x+C$ \\myrule\n\\item $\\ds\\int \\sinh x\\ dx = \\cosh x+C$ \\myrule\n\\item $\\ds\\int \\tanh x\\ dx = \\ln(\\cosh x) +C$ \\myrule\n\\item $\\ds\\int \\coth x\\ dx = \\ln|\\sinh x\\,|+C$ \\myrule\n\\item $\\ds     \\int \\frac{1}{\\sqrt{1-x^2}} dx = \\sin^{-1}(x) +C $ \n%\\item $\\ds \\frac{d}{dx}\\big(\\sec^{-1}(x)\\big) = \\frac{1}{ x \\sqrt{x^2-1}}$\n\\item $\\ds  \\int \\frac{1}{1+x^2} \\; dx = \\tan^{-1}(x) +C$\n\\end{enumerate}\n\\end{minipage}%\\\\\n%\n%\\textit{\\small (continued $\\ldots$)}\n\\end{theorem}\n%\\addtocounter{theoremcounter}{-1}\n%\n%\\theorem{thm:indef_algb}{Derivatives and Antiderivatives -- Continued}\n%{\\begin{minipage}[t]{.45\\specialboxlength}\n%Common Differentiation Rules\\rule[-2pt]{0pt}{1pt}\n%\\begin{enumerate}\\addtocounter{enumi}{5}\n%%\\item \\myrule$\\frac{d}{dx}\\big(cf(x) \\big) = c\\cdot \\fp(x)$\n%%\\item \\myrule$\\frac{d}{dx}\\big(f(x)\\pm g(x) \\big) = $\n%%\\vskip .05\\baselineskip\n%%\\myrule$\\fp(x)\\pm g'(x)$\n%%\\item $\\frac{d}{dx}\\big(C \\big) = 0$\\myrule\n%%\\item $\\frac{d}{dx}\\big(x \\big) = 1$\\myrule\n%%\\item $\\frac{d}{dx}\\big(x^n \\big) = n\\cdot x^{n-1}$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\sin x \\big) = \\cos x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\cos x \\big) = -\\sin x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\tan x \\big) = \\sec^2 x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\csc x \\big) = -\\csc x\\cot x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\sec x \\big) = \\sec x\\tan x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\cot x \\big) = -\\csc^2 x$\\myrule\n%\\item $\\frac{d}{dx}\\big(e^ x \\big) = e^x$\\myrule\n%\\item $\\frac{d}{dx}\\big(a^x \\big) = \\ln a\\cdot a^x$\\myrule\n%\\item $\\frac{d}{dx}\\big(\\ln x \\big) = \\frac1 x$\\myrule\n%\\end{enumerate}\n%\\end{minipage}\n%\\begin{minipage}[t]{.55\\specialboxlength}\n%Common Indefinite Integral Rules\\rule[-2pt]{0pt}{1pt}\n%\\begin{enumerate}\\addtocounter{enumi}{5}\n%%\\item \\myrule$\\int c\\cdot f(x)\\ dx = c\\cdot \\int f(x)\\ dx$\n%%\\item \\myrule$\\int \\big(f(x)\\pm g(x)\\big)\\ dx =$\n%%\\vskip .05\\baselineskip\n%%\\myrule$ \\int f(x)\\ dx\\pm \\int g(x)\\ dx$\n%%\\item $\\int 0\\ dx = C$\\myrule\n%%\\item $\\int 1\\ dx = \\int dx = x+C$\\myrule\n%%\\item $\\int x^n\\ dx =\\frac{1}{n+1}x^{n+1}+ C$\\quad {\\scriptsize ($n\\neq -1$)}\\myrule\n%\\item $\\int \\cos x\\ dx = \\sin x+C$\\myrule\n%\\item $\\int \\sin x\\ dx = -\\cos x+C$\\myrule\n%\\item $\\int \\sec^2 x\\ dx = \\tan x+C$\\myrule\n%\\item $\\int \\csc x\\cot  x\\ dx = -\\csc x+C$\\myrule\n%\\item $\\int \\sec x\\tan x\\ dx = \\sec x+C$\\myrule\n%\\item $\\int \\csc^2 x\\ dx = -\\cot x+C$\\myrule\n%\\item $\\int e^x\\ dx = e^x+C$\\myrule\n%\\item $\\int a^x\\ dx = \\frac{1}{\\ln a}\\cdot a^x+C$\\myrule\n%\\item $\\int \\frac{1}x\\ dx = \\ln |x|+C$\\myrule\n%\\end{enumerate}\n%\\end{minipage}\n%}\n\n\nWe highlight a few important points from Theorem \\ref{thm:indef_alg}:\n\\begin{itemize}\n\t\\item\t\tRule \\#1 states $\\int c\\cdot f(x)\\ dx = c\\cdot \\int f(x)\\ dx$. This is the Constant Multiple Rule: \\index{Constant Multiple Rule!of integration} we can temporarily ignore constants when finding antiderivatives, just as we did when computing derivatives (i.e., $\\frac{d}{dx}\\big(3x^2\\big)$ is just as easy to compute as $\\frac{d}{dx}\\big(x^2\\big)$). An example:\n\t$$\\int 5\\cos x\\ dx = 5\\cdot\\int \\cos x\\ dx = 5\\cdot (\\sin x+C) = 5\\sin x + C.$$\n\tIn the last step we can consider the constant as also being multiplied by 5, but ``5 times a constant'' is still a constant, so we just write ``$C$\\,''.\n\t\\item\t\tRule \\#2 is the Sum/Difference Rule:\\index{integration!Sum/Difference Rule}\\index{Sum/Difference Rule!of integration} we can split integrals apart when the integrand contains terms that are added/subtracted, as we did in Example \\ref{ex_anti3}. So:\n\t\\begin{align*}\n\t\\int(3x^2+4x+5)\\ dx &= \\int 3x^2\\ dx + \\int 4x\\ dx + \\int 5\\ dx \\\\\n\t\t\t\t\t\t\t\t\t\t\t&= 3\\int x^2\\ dx + 4\\int x\\ dx + \\int 5 \\ dx\\\\\n\t\t\t\t\t\t\t\t\t\t\t&= 3\\cdot \\frac13x^3 + 4\\cdot \\frac12x^2+5x+C\\\\\n\t\t\t\t\t\t\t\t\t\t\t&= x^3+2x^2+5x+C\n\t\\end{align*}\n\tIn practice we generally do not write out all these steps, but we demonstrate them here for completeness.\n\t\\item\t\tRule \\#5 is the Power Rule of indefinite integration.\\index{integration!Power Rule}\\index{Power Rule!integration} There are two important things to keep in mind:\n\t\t\\begin{enumerate}\n\t\t\\item\t\tNotice the restriction that $n\\neq -1$. This is important: $\\int \\frac{1}{x}\\ dx \\neq $ ``$\\frac{1}{0}x^0+C$''; rather, see Rule \\#14.\n\t\t\\item\t\tWe are presenting antidifferentiation as the ``inverse operation'' of differentiation. Here is a useful quote to remember:\n\t\t\\begin{quote}%\\centering\n\t\t``Inverse operations do the opposite things in the opposite order.''\n\t\t\\end{quote}\n\t\tWhen taking a derivative using the Power Rule, we \\textbf{first} \\textit{multiply} by the power, then \\textbf{second} \\textit{subtract} 1 from the power. To find the antiderivative, do the opposite things in the opposite order: \\textbf{first} \\textit{add} one to the power, then \\textbf{second} \\textit{divide} by the power.\n\t\t\t\\end{enumerate}\n\t\t\\item\t\tNote that Rule \\#14 incorporates the absolute value of $x$. The exercises will work the reader through why this is the case; for now, know the absolute value is important and cannot be ignored.\n\\end{itemize}\n\n\nNote that we don't have properties to deal with products or quotients of functions, that is, in general\n%Just like with derivatives, the following will \\dfont{NOT} work:\n$$\\int f(x)\\cdot g(x)\\,dx\\neq \\int f(x)\\,dx\\int g(x)\\,dx.$$\n$$\\int \\frac{f(x)}{g(x)}\\,dx\\neq \\frac{\\int f(x)\\,dx}{\\int g(x)\\,dx}.$$\nWith derivatives, we had the product and quotient rules to deal with these cases.\nFor integrals, we have no such rules, but we will learn a variety of different techniques to deal with these cases.\n\n\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral2}\nIf $f'(x)=x^4+2x-8\\sin x$ then what is $f(x)$?\n\\end{example}\n\n\\begin{solution} \nThe answer is:\n$$\\begin{array}{rcl}\n\\ds{f(x)=\\int f'(x)\\,dx}&=&\\ds{\\int \\left(x^4+2x-8\\sin x\\right)\\,dx}\\\\\n\\\\\n&=&\\ds{ \\int x^4 \\,dx + 2\\int x\\,dx -8 \\int \\sin x\\,dx }\\\\\n\\\\\n&=&\\ds{\\frac{x^5}{5}+x^2+8\\cos x+C,}\\\\\n\\end{array}$$\nwhere $C$ is a constant.\n\\end{solution}\n\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral3}\nFind the indefinite integral: $\\ds\\int 3x^2\\,dx$.\n\\end{example}\n\\begin{solution}\n\t$$\\begin{array}{rcl}\n\t\\ds{\\int 3x^2\\,dx} & = & \\ds{3\\int x^2\\,dx}\\\\\n\t\\\\\n\t&=&\\ds{3\\frac{x^3}{3}+C}\\\\\n\t\\\\\n\t&=&x^3+C\\\\\n\t\\end{array} $$\n\\end{solution}\n\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral4}\nFind the general antiderivative of $\\ds \\frac{2}{\\sqrt x}\\,dx$.\n\\end{example}\n\\begin{solution}\n\t$$\\begin{array}{rcl}\n\t\\ds{\\int \\frac{2}{\\sqrt x}\\,dx} & = & \\ds{2\\int x^{-\\frac{1}{2}}\\,dx}\\\\\n\t\\\\\n\t&=&\\ds{2\\frac{x^{-\\frac{1}{2}+1}}{-\\frac{1}{2}+1}+C}\\\\\n\t\\\\\n\t&=&4\\sqrt x+C\\\\\n\t\\end{array}$$\n\\end{solution}\n\n\\begin{example}{Indefinite Integral}{IndefiniteIntegral5}\nFind:  $\\ds\\int \\left(\\frac{1}{x}+e^{7x}+x^\\pi+7\\right)\\,dx$.\n\\end{example}\n\\begin{solution}\n\t$$\\begin{array}{rcl}\n\t\\ds{\\int \\left(\\frac{1}{x}+e^{7x}+x^\\pi+7\\right)\\,dx} & = & \\ds{\\int \\frac{1}{x}\\,dx+\\int e^{7x}\\,dx+\\int x^\\pi\\,dx+\\int 7\\,dx}\\\\\n\t\\\\\n\t&=& \\ds{\\ln|x|+\\frac{1}{7}e^{7x}+\\frac{x^{\\pi+1}}{\\pi+1}+7x+C}\\\\\n\t\\end{array}$$\n\\end{solution}\n\n\\subsection*{Differential Equations and Initial Value Problems}\nAn equation involving derivatives where we want to solve for the original function is called a \\dfont{differential equation}.\nFor example, $f'(x)=2x$ is a differential equation with general solution $f(x)=x^2+C$.\nSome solutions (i.e., particular values of $C$) are shown below.\n$$\\includegraphics[width=3in]{images2/integral-curves}$$\nAs seen with integral curves, we may have an infinite family of solutions satisfying the differential equation.\nHowever, if we were given a point (called an \\ifont{initial value}) on the curve then we could determine $f(x)$ completely.\nSuch a problem is known as an \\ifont{initial value problem}.\n\n\\begin{example}{Initial Value Problem}{Initial Value Problem}\nIf $f'(x)=2x$ and $f(0)=2$ then determine $f(x)$.\n\\end{example}\n\n\\begin{solution} \nAs previously stated, we have a solution of:\n$$f(x)=x^2+C.$$\nBut $f(0)=2$ implies:\n$$2=0^2+C\\quad\\to\\quad C=2.$$\nTherefore, $f(x)=x^2+2$ is the solution to the initial value problem.\n\\end{solution}\n\n\nWe have seen that the derivative of a position function is a velocity function, and the derivative of a velocity function describes  acceleration.\\index{initial value problem} We can now go ``the other way:'' the antiderivative of an acceleration function gives a velocity function, etc. While there is just one derivative of a given function, there are infinite antiderivatives. Therefore we cannot ask ``What is \\textit{the} velocity of an object whose acceleration is $-32$ft/s$^2$?'', since there is more than one answer. \n\nAs above, we can find \\textit{the} answer if we provide more information with the question, in the form of an  initial value, a value of the function that one knows beforehand.\\\\\n\n\\begin{example}{Solving initial value problems}{ex_anti4}\nThe acceleration due to gravity of a falling object is $-32$ ft/s$^2$. At time $t=3$, a falling object had a velocity of $-10$ ft/s. Find the equation of the object's velocity.\n\\end{example}\n\n\\begin{solution}\n{We want to know a velocity function, $v(t)$. We know two things:\n\t\\begin{itemize}\n\t\t\\item\t\tThe acceleration, i.e., $v\\primeskip'(t)= -32$, and\n\t\t\\item\t\tthe velocity at a specific time, i.e., $v(3) = -10$.\n\t\\end{itemize}\nUsing the first piece of information, we know that $v(t)$ is an antiderivative of $v\\primeskip'(t)=-32$. So we begin by finding the indefinite integral of $-32$:\n\t\t$$\\int (-32)\\ dt = -32t+C=v(t).$$\nNow we use the fact that $v(3)=-10$ to find $C$:\n\\begin{align*}\n\tv(t) &= -32t+C \\\\\n\tv(3) &= -10 \\\\\n\t-32(3)+C &= -10\\\\\n\tC &= 86\n\\end{align*}\n\nThus $v(t)= -32t+86$. We can use this equation to understand the motion of the object: when $t=0$, the object had a velocity of $v(0) = 86$ ft/s. Since the velocity is positive, the object was moving upward.\n\nWhen did the object begin moving down? Immediately after $v(t) = 0$:\n$$-32t+86 = 0 \\quad \\Rightarrow\\quad  t = \\frac{43}{16}  \\approx 2.69\\text{s}.$$\nRecognize that we are able to determine quite a bit about the path of the object knowing just its acceleration and its velocity at a single point in time.\n}\n\\end{solution}\n\n\\begin{example}{Solving initial value problems}{ex_anti5}\n {\nFind $f(t)$, given that $\\fpp(t) = \\cos t$, $\\fp(0) = 3$ and $f(0) = 5$.}\n\\end{example}\n\n\\begin{solution}\n{We start by finding $\\fp(t)$, which is an antiderivative of $\\fpp(t)$:\n\t\t$$\\int \\fpp(t)\\ dt = \\int \\cos t\\ dt = \\sin t + C = \\fp(t).$$\n\t\t\n\t\tSo $\\fp(t) = \\sin t+C$ for the correct value of $C$. We are given that $\\fp(0) = 3$, so:\n\t\t$$\\fp(0) = 3 \\quad \\Rightarrow \\quad \\sin 0+C = 3 \\quad \\Rightarrow \\quad C=3.$$\n\t\tUsing the initial value, we have found $\\fp(t) = \\sin t+ 3.$\n\t\t\nWe now find $f(t)$ by integrating again.\n\n%\\enlargethispage{3\\baselineskip}\n$$f(t)=\\int \\fp(t) \\ dt = \\int (\\sin t+3)\\ dt = -\\cos t + 3t + C.$$ \nWe are given that $f(0) = 5$, so\n\\begin{align*}\n-\\cos 0 + 3(0) + C &= 5 \\\\\n-1 + C &= 5\\\\\nC &= 6\n\\end{align*}\n Thus $f(t) = -\\cos t + 3t + 6$.\n}\n\\end{solution}\n\n\nThis section introduced antiderivatives and the indefinite integral. We found they are needed when finding a function given information about its derivative(s). For instance, we found a position function given a velocity function.\n\nIn the next section, we will see how position and velocity are unexpectedly related by the areas of certain regions on a graph of the velocity function. Then, in Section \\ref{sec:FTC}, we will see how areas and antiderivatives are closely tied together.\n", "meta": {"hexsha": "a39fdb3fdd2c5a3e5767131d60d575c69e4bc268", "size": 23103, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "5-applications-of-derivatives/5-8-antiderivatives.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-8-antiderivatives.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-8-antiderivatives.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 52.8672768879, "max_line_length": 526, "alphanum_fraction": 0.6745877159, "num_tokens": 7936, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.815232489352, "lm_q2_score": 0.9230391664210672, "lm_q1q2_score": 0.7524915174108416}}
{"text": "% -*- LaTeX -*-\n% -*- coding: utf-8 -*-\n%\n% michael a.g. aïvázis\n% orthologue\n% (c) 1998-2019 all rights reserved\n%\n\n\\section{Monte Carlo integration: a bit of theory}\n\\label{sec:montecarlo}\n\nSuppose you have a function $f(x)$ that is sufficiently well behaved for\nall $x$ in a region $\\Omega \\subset \\mathbb{R}^{n}$ and you wish to compute the\ndefinite integral\n%\n\\begin{equation}\n  I_{\\Omega} (f)\n  =\n  \\int_{\\Omega} f\n\\label{eq:integral}\n\\end{equation}\n%\nThe Monte Carlo integration method estimates the value of a definite integral by sampling\nthe function at points $x$ in $\\Omega$ that are chosen at random with uniform\nprobability. Suppose that you have $N$ such points forming a sample $X_{N}$. The Monte\nCarlo estimate for the integral is\n%\n\\begin{equation}\n  I_{\\Omega} (f; X_{N})\n  =\n  \\Omega \\cdot \\langle f \\rangle\n  =\n  \\Omega \\, \\frac{1}{N} \\sum_{x \\in X_{N}} f(x)\n\\label{eq:mc-estimate}\n\\end{equation}\n%\nwhere $\\langle f \\rangle$ is the sample mean of the function $f$ and we have used $\\Omega$\nas short-hand for the volume of the associated region. More details can be found in\n\\citep{hammersley,ueberhuber}; see \\cite{weinzierl} for an excellent pedagogical\nintroduction to the subject.\n\nOne can show that the error in the estimate descreases as $1/\\sqrt{N}$, a convergence rate that\nis rather slow. It is possible to improve on this by being smart about how the region of\nintegration is sampled; see \\cite{lepage-78,lepage-80,press}. On the bright side, the\nconvergence rate is {\\em independent} of the dimensionality of the integral, making this method\nvery well suited for multi-dimensional integrals. Further, it is rather straightforward to\nwrite a parallel implementation and compensate for the slow convergence by computing on a large\nmachine.\n\nWe are ready to recast \\eqref{mc-estimate} in a form better suited for a computer\nimplementation, where we use pseudo-random number generators to create the sample set. Most\ngenerators produce numbers between $0$ and $1$, so actual calculations require finding a box\n$B_{\\Omega}$ that contains $\\Omega$, and building $n$-dimensional sampling points $x$ by\nstretching and translating the unit interval to match the dimensions of $B_{\\Omega}$. The\nintegration is then restricted to $\\Omega$ by introducing a function\n%\n\\begin{equation}\n  \\Theta_{\\Omega}(x)\n  =\n  \\left\\{\n  \\begin{array}{ll}\n  1 & x \\in \\Omega \\\\\n  0 & {\\rm otherwise}\n  \\end{array}\n  \\right.\n\\label{eq:theta}\n\\end{equation}\n%\nthat takes the value $1$ inside $\\Omega$ and vanishes identically outside. We can now recast\n\\eqref{integral} as\n%\n\\begin{equation}\n  I_{\\Omega} (f)\n  =\n  \\int_{B_{\\Omega}} \\Theta_{\\Omega} \\, f\n\\label{eq:integral-box}\n\\end{equation}\n%\nThere are now two classes of points in the sample $X_{N}$: those interior to $\\Omega$, and the\nrest. Let $\\tilde{N}$ be the number of points in $X_{N}$ that fall in $\\Omega$; then\n\\eqref{mc-estimate} becomes:\n%\n\\begin{equation}\n  I_{\\Omega} (f; X_{N})\n  =\n  \\Omega \\, \\frac{1}{\\tilde{N}} \\sum_{x \\in X_{\\tilde{N}}} f(x)\n\\label{eq:mc-box}\n\\end{equation}\n%\nwhere $X_{\\tilde{N}}$ is the subset of the sample in $\\Omega$. Now, let $B$ be the volume\nof the sampling box and observe that\n%\n\\begin{equation}\n  \\Omega\n  =\n  \\frac{\\tilde{N}}{N} B\n\\label{eq:volume-estimate}\n\\end{equation}\n%\nis a good estimate of the volume of the integration region. Further, the sum over\n$X_{\\tilde{N}}$ in \\eqref{mc-box} can be extended to $X_{N}$ as long as $f$ is\nmultiplied by $\\Theta_{\\Omega}$. We obtain\n%\n\\begin{equation}\n  I_{\\Omega} (f; X_{N})\n  =\n  B \\, \\frac{1}{N} \\sum_{x \\in X_{N}} \\Theta_{\\Omega} \\, f(x)\n\\label{eq:mc}\n\\end{equation}\n%\n\nIn the remainder of this article, we will transform this rather innocuous expression into\na sequence of computer programs of increasing complexity and, hopefully, flexibility. The\ngoal is to construct a piece of software that will enable our end users to explore the\nmethod with as little programming on their part as possible.\n\n% end of file\n", "meta": {"hexsha": "7aeef6d74fbb03fe3c97d749cab92f13123f1ea9", "size": 3966, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/gauss/sections/montecarlo.tex", "max_stars_repo_name": "lijun99/pyre", "max_stars_repo_head_hexsha": "004dfd4c06489b4ba5b32877338ca6440f2d523b", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 3, "max_stars_repo_stars_event_min_datetime": "2019-08-02T21:02:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-08T13:59:43.000Z", "max_issues_repo_path": "doc/gauss/sections/montecarlo.tex", "max_issues_repo_name": "lijun99/pyre", "max_issues_repo_head_hexsha": "004dfd4c06489b4ba5b32877338ca6440f2d523b", "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/gauss/sections/montecarlo.tex", "max_forks_repo_name": "lijun99/pyre", "max_forks_repo_head_hexsha": "004dfd4c06489b4ba5b32877338ca6440f2d523b", "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.6101694915, "max_line_length": 95, "alphanum_fraction": 0.718103883, "num_tokens": 1194, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.855851143290548, "lm_q2_score": 0.8791467754256018, "lm_q1q2_score": 0.7524187728682}}
{"text": "\\chapter{Dimensional analysis}\n\n\\section{Non-dimensionalisation}\nConsider system (\\ref{boussinesq}) and rescale spatial lengths with the transformation\n\\begin{equation}\n\\tilde{x}=\\frac{x}{L},\\quad \\tilde{y}=\\frac{y}{L},\\quad \\tilde{z}=\\frac{z}{H},\n\\end{equation}\nwhere $\\tilde{x},\\tilde{y},\\tilde{z}$ are nondimensional numbers and $L$ and $H$\nare scaling values in the horizontal and vertical respectively. These generally take\ntypical values for length scales so that $\\tilde{x},\\tilde{y},\\tilde{z}$ are ${\\cal O}(1)$.\n\nThe momentum equations in (\\ref{boussinesq}) then become (for simplicity dropping $\\bmF$, $\\hat{\\bmu}$\nand assuming that $2 \\bmOmega \\times \\bmu=f\\bmk\\times\\bmu$ and $\\nabla\\cdot \\tautens = \\nu\\nabla^2\\bmu$),\n\\begin{subeqnarray*}\n\\frac{\\pp u}{\\pp t}\n+ L^{-1}u\\frac{\\pp u}{\\pp\\tilde{x}} + L^{-1}v\\frac{\\pp u}{\\pp\\tilde{y}} + H^{-1}w\\frac{\\pp u}{\\pp\\tilde{z}}\n-fv\n&=& -L^{-1}\\frac{\\pp p}{\\pp\\tilde{x}} - L^{-1}g\\frac{\\pp \\eta}{\\pp\\tilde{x}}\\\\&&\\quad\n+L^{-2}\\nu\\frac{\\pp^2 u}{\\pp\\tilde{x}^2}+L^{-2}\\nu\\frac{\\pp^2 u}{\\pp\\tilde{y}^2}+H^{-2}\\nu\\frac{\\pp^2 u}{\\pp\\tilde{z}^2},\\\\\n\\frac{\\pp v}{\\pp t}\n+ L^{-1}u\\frac{\\pp v}{\\pp\\tilde{x}} + L^{-1}v\\frac{\\pp v}{\\pp\\tilde{y}} + H^{-1}w\\frac{\\pp v}{\\pp\\tilde{z}}\n+fu\n&=& -L^{-1}\\frac{\\pp p}{\\pp\\tilde{y}} - L^{-1}g\\frac{\\pp \\eta}{\\pp\\tilde{y}}\\\\&&\\quad\n+L^{-2}\\nu\\frac{\\pp^2 v}{\\pp\\tilde{x}^2}+L^{-2}\\nu\\frac{\\pp^2 v}{\\pp\\tilde{y}^2}+H^{-2}\\nu\\frac{\\pp^2 v}{\\pp\\tilde{z}^2},\\\\\n\\frac{\\pp w}{\\pp t}\n+ L^{-1}u\\frac{\\pp w}{\\pp\\tilde{x}} + L^{-1}v\\frac{\\pp w}{\\pp\\tilde{y}} + H^{-1}w\\frac{\\pp w}{\\pp\\tilde{z}}\n&=& -H^{-1}\\frac{\\pp p}{\\pp\\tilde{z}} - \\rho g\\\\&&\\quad\n+L^{-2}\\nu\\frac{\\pp^2 w}{\\pp\\tilde{x}^2}+L^{-2}\\nu\\frac{\\pp^2 w}{\\pp\\tilde{y}^2}+H^{-2}\\nu\\frac{\\pp^2 w}{\\pp\\tilde{z}^2}.\n\\end{subeqnarray*}\n\nNow suppose that we also have representative velocity scales in the horizontal and vertical ($U,W$) and\ndefine\n\\begin{equation}\n\\tilde{u}=\\frac{u}{U},\\quad \\tilde{v}=\\frac{v}{U},\\quad \\tilde{w}=\\frac{w}{W},\n\\end{equation}\nthen substituting we have\n\\begin{subeqnarray*}\nU\\frac{\\pp \\tilde{u}}{\\pp t}\n+ U^2L^{-1}\\left(\\tilde{u}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{y}}\\right) + UWH^{-1}\\tilde{w}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{z}}\n-Uf\\tilde{v}\n&=& -L^{-1}\\frac{\\pp p}{\\pp\\tilde{x}} - L^{-1}g\\frac{\\pp \\eta}{\\pp\\tilde{x}}\\\\&&\\quad\n+UL^{-2}\\nu\\left(\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{y}^2}\\right)+H^{-2}U\\nu \\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{z}^2},\\\\\nU\\frac{\\pp \\tilde{v}}{\\pp t}\n+ U^2L^{-1}\\left(\\tilde{u}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{y}}\\right) + UWH^{-1}\\tilde{w}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{z}}\n+Uf\\tilde{u}\n&=& -L^{-1}\\frac{\\pp p}{\\pp\\tilde{y}} - L^{-1}g\\frac{\\pp \\eta}{\\pp\\tilde{y}}\\\\&&\\quad\n+UL^{-2}\\nu\\left(\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{y}^2}\\right)+H^{-2}U\\nu\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{z}^2},\\\\\nW\\frac{\\pp \\tilde{w}}{\\pp t}\n+ UWL^{-1}\\left(\\tilde{u}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{y}}\\right) + W^2H^{-1}\\tilde{w}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{z}}\n&=& -L^{-1}\\frac{\\pp p}{\\pp\\tilde{z}} -  \\rho g\\\\&&\\quad\n+WL^{-2}\\nu\\left(\\frac{\\pp^2 \\tilde{w}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{w}}{\\pp\\tilde{y}^2}\\right)+H^{-2}W\\nu\\frac{\\pp^2 \\tilde{w}}{\\pp\\tilde{z}^2}.\n\\end{subeqnarray*}\n\nOnce representative length and velocity scales have been defined this automatically sets a temporal scale\n\\begin{equation*}\n\\tilde{t}=\\frac{t}{T},\\quad T=\\frac{L}{U},\n\\end{equation*}\nand the divergence-free continuity equation $\\nabla\\cdot\\vec{u}=0$\nsuggests the scaling constraint\n\\begin{equation}\n\\frac{W}{H}=\\frac{U}{L}.\n\\label{aspect99}\n\\end{equation}\n\nAgain, substituting and dividing through by $UT^{-1}$ in the horizontal and $WT^{-1}$\nin the vertical, and making use of (\\ref{aspect99}) yields\n\\begin{subeqnarray*}\n\\frac{\\pp \\tilde{u}}{\\pp \\tilde{t}}\n+ \\tilde{u}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{y}} + \\tilde{w}\\frac{\\pp \\tilde{u}}{\\pp\\tilde{z}}\n-\\frac{Lf}{U}\\tilde{v}\n&=& -U^{-2}\\frac{\\pp p}{\\pp\\tilde{x}} - U^{-2}g\\frac{\\pp \\eta}{\\pp\\tilde{x}}\\\\&&\\quad\n+U^{-1}L^{-1}\\nu\\left(\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{y}^2}\\right)+H^{-2}LU^{-1}\\nu \\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{z}^2},\\\\\n\\frac{\\pp \\tilde{v}}{\\pp \\tilde{t}}\n+ \\tilde{u}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{y}} + \\tilde{w}\\frac{\\pp \\tilde{v}}{\\pp\\tilde{z}}\n+\\frac{Lf}{U}\\tilde{u}\n&=& -U^{-2}\\frac{\\pp p}{\\pp\\tilde{y}} - U^{-2}g\\frac{\\pp \\eta}{\\pp\\tilde{y}}\\\\&&\\quad\n+U^{-1}L^{-1}\\nu\\left(\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{y}^2}\\right)+H^{-2}LU^{-1}\\nu \\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{z}^2},\\\\\n\\frac{\\pp \\tilde{w}}{\\pp \\tilde{t}}\n+ \\tilde{u}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{x}} + \\tilde{v}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{y}} + \\tilde{w}\\frac{\\pp \\tilde{w}}{\\pp\\tilde{z}}\n&=& -LH^{-1}U^{-1}W^{-1}\\frac{\\pp p}{\\pp\\tilde{z}} - LU^{-1}W^{-1}\\rho g\\\\&&\\quad\n+U^{-1}L^{-1}\\nu\\left(\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{y}^2}\\right)+H^{-2}LU^{-1}\\nu \\frac{\\pp^2 \\tilde{v}}{\\pp\\tilde{z}^2}.\n\\end{subeqnarray*}\n\nThe Coriolis term takes the form\n\\begin{equation*}\n\\frac{Lf}{U}\\bmk\\times\\tilde{\\bmu}=\\Ro^{-1}\\bmk\\times\\tilde{\\bmu}.\n\\end{equation*}\nThe buoyancy term takes the form\n\\begin{equation*}\n\\frac{L}{UW}\\rho g = \\frac{L}{H}\\frac{U}{W}\\Fr^{-1}\\rho = \\frac{L^2}{H^2}\\Fr^{-1}\\rho = \\Delta^2\\Fr^{-1}\\rho.\n\\end{equation*}\nThe viscous term takes the form\n\\begin{equation*}\nU^{-1}L^{-1}\\nu\\left(\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{y}^2}\\right)+H^{-2}LU^{-1}\\nu \\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{z}^2}\n=\\Re_H^{-1}\\left(\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{x}^2}+\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{y}^2}\\right) + \\Re_V^{-1}\\frac{\\pp^2 \\tilde{u}}{\\pp\\tilde{z}^2},\n\\end{equation*}\nwhere $\\Re_H=UL/\\nu$ and $\\Re_V=WH/\\nu$. \n%Note that is would have been\n%trivial in the above to use a tensor of viscosity values rather than a\n%constant.  -- COLIN: not sure what this means\nRescaling the free surface height in terms of the vertical\ncoordinate ($\\tilde{\\eta}=\\eta/H$) yields a free surface term\n\\begin{equation*}\n\\frac{Hg}{U^2}\\nabla_{\\tilde{x}}\\tilde{\\eta}=\\Fr^{-1}\\nabla_{\\tilde{x}}\\tilde{\\eta}.\n\\end{equation*}\n\nDropping tildes and using $p=U^{-2}p$ we have finally that\n\\begin{subeqnarray*}\n\\frac{\\pp {u}}{\\pp {t}}\n+ \\bmu\\cdot\\nabla u\n-\\Ro^{-1}{v}\n&=& \\frac{\\pp p}{\\pp {x}} - \\Fr^{-1}\\frac{\\pp \\eta}{\\pp {x}}\n+\\Re_H^{-1}\\left(\\frac{\\pp^2 {u}}{\\pp {x}^2}+\\frac{\\pp^2 {u}}{\\pp {y}^2}\\right)+ \\Re_V^{-1}\\frac{\\pp^2 {u}}{\\pp {z}^2},\\\\\n\\frac{\\pp {v}}{\\pp {t}}\n+ \\bmu\\cdot\\nabla v\n+\\Ro^{-1}{u}\n&=& \\frac{\\pp p}{\\pp {y}} - \\Fr^{-1}\\frac{\\pp \\eta}{\\pp {y}}\n+\\Re_H^{-1}\\left(\\frac{\\pp^2 {v}}{\\pp {x}^2}+\\frac{\\pp^2 {v}}{\\pp {y}^2}\\right)+ \\Re_V^{-1}\\frac{\\pp^2 {v}}{\\pp {z}^2},\\\\\n\\frac{\\pp {w}}{\\pp \\tilde{t}}\n+ \\bmu\\cdot\\nabla w\n&=& -\\Delta^2 \\frac{\\pp p}{\\pp {z}} - \\Delta^2 \\Fr^{-1}g\n+\\Re_H^{-1}\\left(\\frac{\\pp^2 {v}}{\\pp {x}^2}+\\frac{\\pp^2  {v}}{\\pp {y}^2}\\right)+ \\Re_V^{-1}\\frac{\\pp^2 {v}}{\\pp {z}^2}.\n\\end{subeqnarray*}\n\n%\\begin{thm}[Buckingham-Pi Theorem]\n%Why nondimensionalising can help reduce parameter phase space ... Barenblatt ...\n%\\end{thm}\n\n\n\\section{Dimensionless parameters}\nTable \\ref{table:dimensionless} gives some common non-dimensional numbers.\nThe following expressions are also useful\n\\begin{equation*}\nN^2=-\\frac{g}{\\rho_0}\\ddt[z]{\\rho} \\approx \\frac{g}{\\rho_0}\\frac{\\Delta\\rho}{H}=\\frac{g'}{H}\n\\end{equation*}\n\\begin{equation*}\ng' =\\frac{\\Delta\\rho}{\\rho_0}g\n\\end{equation*}\n\n\n\\begin{table}[t]\n\\begin{center}\n\\begin{tabular}{lll} \\hline\nName        &   Description         &   Form        \\\\  \\hline\n            &                           &               \\\\\nAspect ratio   &   Ratio of length scales   &   $\\Delta=L/H$  \\\\\nReynolds    &   inertial/viscous        &   $\\Re=UL/\\nu$    \\\\\nRossby      &   inertial/Coriolis\\footnotemark[6]            &   $\\Ro=U/fL$      \\\\\nFroude      &   inertial/gravitational\\footnotemark[7] &   $\\Fr=U^2/gH$    \\\\\nFroude (internal)   &   inertial/buoyancy   &   $\\Fr_{\\mathrm{internal}}=U^2/g'H=U/NH$   \\\\\nBurger      &  $\\Bu=\\Ro/\\Fr$    &   $\\Bu = NH/fL$  \\\\\nRichardson  &   buoyancy/inertial\\footnotemark[8]       &   $\\Ri=N^2/(U/L)^2$   \\\\\nRichardson (gradient)   &   buoyancy/shear  &   $\\Ri_{\\mathrm{gradient}}=N^2/(\\Delta U/\\Delta L)^2$ \\\\\nStokes      &   viscous/gravitational   &   \\\\\nPrandtl     &   viscosity/diffusivity   &  $\\nu/\\kappa$ \\\\\nP\\'ecl\\'et  &     $\\Pe=\\Re\\,\\Pr$  &  $UL/\\kappa$ \\\\\nEkman       &   viscous/Coriolis    &   $\\Ek=2\\nu_H/fL^2$   \\\\\nGrashof     &    free convective/viscous    & $\\Gr=g\\Delta\\rho L^3/\\rho \\nu^2$\\\\\nRayleigh    &     $Ra=\\Gr\\,\\Pr$                 & $\\Ra = g\\beta(T-T_0)L^3/\\alpha\\nu$\\\\\n            &                           &               \\\\  \\hline\n\\label{table:dimensionless}\n\\end{tabular}\n\\end{center}\n\n\\caption{Summary of useful dimensionless numbers}\n\\label{tab:dimensionless}\n\\end{table}\n\n\\footnotetext[6]{Also ratio of rotational and convective timescales.}\n\\footnotetext[7]{This sometimes termed the first Froude number and is also often defined as the square root of this (the second Froude number).}\n\\footnotetext[8]{also $(\\textrm{internal Froude number})^{-2}$ if $H=L$}\n\n", "meta": {"hexsha": "bc734e86738d8fe35db83222d1241dc52a42b32d", "size": 9323, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "software/multifluids_icferst/manual/dimensionless.tex", "max_stars_repo_name": "msc-acse/acse-9-independent-research-project-Wade003", "max_stars_repo_head_hexsha": "cfcba990d52ccf535171cf54c0a91b184db6f276", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-05-11T02:39:46.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-11T03:08:38.000Z", "max_issues_repo_path": "software/multifluids_icferst/manual/dimensionless.tex", "max_issues_repo_name": "msc-acse/acse-9-independent-research-project-Wade003", "max_issues_repo_head_hexsha": "cfcba990d52ccf535171cf54c0a91b184db6f276", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "software/multifluids_icferst/manual/dimensionless.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": 53.8901734104, "max_line_length": 167, "alphanum_fraction": 0.5867210125, "num_tokens": 4127, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467706759584, "lm_q2_score": 0.8558511414521923, "lm_q1q2_score": 0.7524187671870277}}
{"text": "\\subsection{Permutations}\n\nFunction to make row exchanges. Elimination with row exchanges:\n\n\\[A=LU\\implies PA=LU\\]\n\nWorks for any invertible $A$.\n\n\\[P=\\text{identity with reordered rows (exchanges)}\\]\n\nCount of possible reorderings ($n\\times n$ permutations): $n! = n(n-1)\\cdots 3(2)(1)$.\n\n\\[\\boxed{P^{-1}=P^T\\text{ and }P^TP=I}\\]\n\nDefining a transpose, or flip over diagonal:\n\n\\[(A^T)_{ij}=A_{ji}\\]\n\nFor symmetric matrices, transpose does not cause change; $A^T=A$. If two rectangular matrices $R^T$ and $R$\ngive a square matrix, then $R^TR$ is always symmetric.\n\n\\[\\boxed{(R^TR)^T=R^TR^{TT}=R^TR}\\]\n\n\\subsection{Vector Spaces and Subspaces}\n\nExamples: $\\R^2$ is all vectors in 2D space, $x-y$ plane: $\\begin{bmatrix}3\\\\2\\end{bmatrix}$.\n$\\R^3$ is all vectors with 3 components. All combinations of vectors in $\\R^n$ yield a result in that space $\\R^n$.\n\n\\[\\boxed{\\R^n\\text{ is all column vectors with $n$ components.}}\\]\n\nThe origin exists to allow for scalar multiplication and addition of vectors. Every vector space has a $\\tb{0}$.\n\n\\subsubsection{Subspaces}\n\nIf a vector space is defined as 1st quadrant in $\\R^2$, then multiplying by a negative scalar $k$ \nremoves the result from that space, so it is not \\textbf{closed} under that operation, so this is not a vector space. \nVector space must be closed under linear combinations. Thus, subspace in $\\R^2$ is all multiples of that vector, a line and the line must go through $\\tb{0}$.\nEvery subspace must contain $\\tb{0}$.\\newline\n\nSubspaces of $\\R^2$:\n\\begin{itemize}\n    \\item All of $\\R^2$\n    \\item Any line through $\\tb{0}_2$ or $L$\n    \\item Just $\\tb{0}_2$ or $Z$\n\\end{itemize}\n\nSimilarly, for $\\R^3$ can have $\\R^3$, plane, line, $\\tb{0}_3$.\\newline\n\nGiven $A=\\left[\\begin{array}{ll}\n    1 & 3 \\\\\n    2 & 3 \\\\\n    4 & 1\\end{array}\\right]$, all linear combinations of these columns form a subspace. \nThis is called \\textbf{column space}, $C(A)$. This would form a plane in $\\R^3$. Thus, the column space is a subspace.", "meta": {"hexsha": "826b1baab1bb81e6685e7316935170ad8c643160", "size": 1981, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "linear-algebra/tex/10_transposes-permutations.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/10_transposes-permutations.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/10_transposes-permutations.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": 37.3773584906, "max_line_length": 158, "alphanum_fraction": 0.6880363453, "num_tokens": 621, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511322604133, "lm_q2_score": 0.8791467770088162, "lm_q1q2_score": 0.7524187645260884}}
{"text": "\\subsection{Introduction}\n\\begin{definition}\n\tA first order linear differential equation is given by $x' = a\\p{t}x + f\\p{t}$. If $f\\p{t} = 0$, then the equation is said to be \\textit{homogeneous}. Otherwise, it is said to be \\textit{inhomogeneous}.\n\\end{definition}\n\\begin{minipage}[t]{0.5\\textwidth}\n\t\\textit{Examples:}\n\t\\vspace{-\\baselineskip}\n\t\\begin{addmargin}{0.25in}\n\t\t\\noskip\n\t\t\\begin{flalign*}\n\t\t\t& x' = tx + t^2 & \\\\\n\t\t\t& x' = \\p{\\frac{\\sin{t}}{t} + e^t}x + e^{t^2}\n\t\t\\end{flalign*}\n\t\\end{addmargin}\n\\end{minipage}%\n\\begin{minipage}[t]{0.5\\textwidth}\n\t\\textit{Non-examples:}\n\t\\vspace{-\\baselineskip}\n\t\\begin{addmargin}{0.25in}\n\t\t\\noskip\n\t\t\\begin{flalign*}\n\t\t \t& x' = x^2 & \\\\\n\t\t\t& xx' = \\sin{t} \\\\\n\t\t\t& x' = \\sin{x}\n\t\t\\end{flalign*}\n\t\\end{addmargin}\n\\end{minipage}%\n\n\\subsection{Solutions to Homogeneous Linear Equations}\n\\normalskip\nHomogeneous first order linear differential equations are of the form $x' = a\\p{t}x$. Notice that it is separable, and that the general solution is given by \\[ x\\p{t} = Ce^{\\int a\\p{t} \\, \\diff{t}}, \\text{ where } C \\in \\mathbb{R}. \\]\n\n\\subsection{Solutions to Inhomogeneous Equations}\n\\subsubsection{Integrating Factors}\nConsider the simple inhomogeneous equation \\[ x' + x = A. \\] The appearance of the $+$ sign and a derivative reminds us of the product rule. As the equation stands, we can't write it as a derivative of a product. However, if we multiply it by some function, we will be able to. The integrating factor for this particular differential equation is $e^x$. Notice that $\\p{e^x x}' = e^x x' + e^x x$. Then\n\\begin{align*}\n\te^x x' + e^x x &= Ae^x \\\\\n\t\\p{e^x x}' &= Ae^x\n\\end{align*}\nwhich is a separable equation in terms of the function $e^x x$. Using the substitution $u = e^x x$ will make this clear:\n\\begin{align*}\n\tu' &= Ae^x \\\\\n\t\\int \\diff{u} &= \\int Ae^x \\, \\diff{x} \\\\\n\tu &= Ae^x + C \\\\\n\te^x x &= Ae^x + C\n\\end{align*}\nWe now generalize this method to any first order linear ODE.\n\\par\\bigskip\nConsider a linear equation written in the form $x' + a\\p{t}x = f\\p{t}$. Our goal is to find some function $\\mu\\p{t}$ so that after multiplying both sides of the equation, the LHS can be written as the derivative of a product.\n\\[ \\mu\\p{t} x' + \\mu\\p{t} a\\p{t}x = g'\\p{t} \\]\nBy inspection, it is easy to see that the LHS is the derivative of a function times the function $x$. Taking $g\\p{t} = h\\p{t}x$, we have\n\\begin{align*}\n\t\\p{h\\p{t}x}' &= \\mu\\p{t} x' + \\mu\\p{t} a\\p{t}x \\\\\n\th\\p{t}x' + h'\\p{t}x &= \\mu\\p{t} x' + \\mu\\p{t} a\\p{t}x \\\\\n\t\\implies h\\p{t} = \\mu\\p{t}, \\, h'\\p{t} &= \\mu'\\p{t} = \\mu\\p{t} a\\p{t} \\\\\n\t\\mu\\p{t} &= Ce^{\\int a\\p{t} \\, \\diff{t}}\n\\end{align*}\nNotice that the value of $C$ does not matter, as long as it is non-zero. We take $\\mu\\p{t} = e^{\\int a\\p{t} \\, \\diff{t}}$, which yields\n\\begin{align*}\n\t\\mu\\p{t} x' + \\mu\\p{t} a\\p{t}x &= \\mu\\p{t} f\\p{t} \\\\\n\t\\p{\\mu\\p{t} x}' &= \\mu\\p{t} f\\p{t} \\\\\n\t\\mu\\p{t} x &= \\int \\mu\\p{t} f\\p{t} \\, \\diff{t} \\\\\n\tx &= \\frac{1}{\\mu\\p{t}} \\int \\mu\\p{t} f\\p{t} \\, \\diff{t} \\\\\n\tx\\p{t} &= e^{-\\int a\\p{t} \\, \\diff{t}} \\int f\\p{t} e^{\\int a\\p{t} \\, \\diff{t}} \\, \\diff{t}\n\\end{align*}\nThis formula is quite complicated and not worth memorizing. It is easier to find $\\mu\\p{t}$ and then work from there.\n\\par\\bigskip\n\\begin{example}\n\t\\noskip\n\t\\begin{align*}\n\t\tx' + x\\tan{t} &= 2t\\cos{t} \\\\\n\t\t\\mu = e^{\\int \\tan{t} \\, \\diff{t}} &= e^{\\ln\\abs{\\sec{t}}} = \\sec{t} \\\\\n\t\tx'\\sec{t} + x\\sec{t}\\tan{t} &= 2t \\\\\n\t\t\\p{x\\sec{t}}' &= 2t \\\\\n\t\tx\\sec{t} &= t^2 + C \\\\\n\t\tx &= t^2\\cos{t} + C\\cos{t}\n\t\\end{align*}\n\\end{example}\n\n\\subsubsection{Variation of Parameters}\n\\normalskip\nConsider the linear equation \\[ y' = 3y + 6. \\] Now, consider the associated homogeneous equation: \\[ y'_h = 3y_h \\implies y_h = Ae^{3t} \\] The solution to the associated homogeneous equation is related to the solution of our original equation somehow. Once again, the $+$ sign is suggestive of the product rule, so we will guess that the solution is the product of $y_h\\p{t}$ and another function $v\\p{t}$. Let $y\\p{t} = v\\p{t}y_h\\p{t}$. Then\n\\begin{align*}\n\ty' = v'y_h + vy'_h &= 3vy_h + 6 \\\\\n\tv' \\cdot Ae^{3t} + \\cancel{v \\cdot 3Ae^{3t}} &= \\cancel{3v \\cdot Ae^{3t}} + 6 \\\\\n\tv' &= \\frac{6}{A}e^{-3t} \\\\\n\tv &= -\\frac{2}{A}e^{-3t} + C\n\\end{align*}\nThus, the general solution to the ODE is given by \\[ y\\p{t} = -2 + Ce^{3t}. \\]\n\\par\nWe will now generalize this method to any first order linear ODE. Consider the equation \\\\ $y' = a\\p{t}y + f\\p{t}$ and its associated homogeneous equation: \\[ y'_h = a\\p{t}y_h \\implies y_h = Ae^{\\int a\\p{t} \\, \\diff{t}} \\]\nAgain, we assume that the solution to our ODE will be of the form $y\\p{t} = v\\p{t}y_h\\p{t}$. Then\n\\begin{align*}\n\ty' = v'y_h + vy'_h &= a\\p{t}vy_h + f\\p{t} \\\\\n\tv' \\cdot Ae^{\\int a\\p{t} \\, \\diff{t}} + \\cancel{v \\cdot Aa\\p{t}e^{\\int a\\p{t} \\, \\diff{t}}} &= \\cancel{v \\cdot Aa\\p{t}e^{\\int a\\p{t} \\, \\diff{t}}} + f\\p{t} \\\\\n\tv' &= \\frac{1}{A}f\\p{t}e^{-\\int a\\p{t} \\, \\diff{t}} \\\\\n\tv &= \\frac{1}{A} \\int f\\p{t}e^{-\\int a\\p{t} \\, \\diff{t}} \\, \\diff{t}\n\\end{align*}\nwhich gives us the general solution \\[ y\\p{t} = e^{\\int a\\p{t} \\, \\diff{t}} \\int f\\p{t}e^{-\\int a\\p{t} \\, \\diff{t}} \\, \\diff{t}. \\] Note that the solution from here and from using integrating factors differ by a negative sign on $a\\p{t}$. This is simply because of the general form of each equations we started with: in the section of integrating factors we had $y' + a\\p{t}y = f\\p{t}$ whereas in this section, we used the form $y' = a\\p{t}y + f\\p{t}$. We can simply rewrite the second equation as $y' + \\p{-a\\p{t}}y = f\\p{t}$, which eliminates the discrepancy.\n\\subsubsection{Structure of Solutions}\n\\begin{theorem}\n\tLet $y' - ay = f$ be a general first order linear differential equation. Suppose that $y_p\\p{t}$ is a particular solution to the equation, and $y_h\\p{t}$ is a particular solution to the associated homogeneous differential equation $y' - ay = 0$. Then every solution of $y' - ay = f$ is of the form \\[ y\\p{t} = y_p\\p{t} + Cy_h\\p{t}. \\]\n\\end{theorem}\n\\begin{proof}\n\tConsider the differential equation $y' - ay = f$, and the function $y\\p{t} = y_p\\p{t} + Cy_h\\p{t}$ with $y_p$ and $y_h$ be as described above. Then\n\t\\begin{align*}\n\t\ty'\\p{t} - ay\\p{t} &= \\p{y_p + Cy_h}' - a\\p{y_p + Cy_h} \\\\\n\t\t\t\t\t\t\t\t  &= y_p' + Cy_h' - ay_p - Cay_h \\\\\n\t\t\t\t\t\t\t\t  &= \\p{y_p' - ay_p} + C\\p{y_h' - ay_h} \\\\\n\t\t\t\t\t\t\t\t  &= f + C \\cdot 0 \\\\\n\t\ty'\\p{t} - ay\\p{t} &= f\n\t\\end{align*}\n\tThus, $y\\p{t} = y_p\\p{t} + Cy_h\\p{t}$ satisfies the differential equation.\n\\end{proof}\n\\subsection{Mixing Problems}\n\\textit{Example:} \\\\\n\\begin{minipage}[t]{0.25\\textwidth}\n\t\\begin{tikzpicture}[baseline = (current bounding box.north)]\n\t\t\\draw[->] (1, -0.25) -- (1, -0.75) node[pos = 0, above] {\\begin{tabular}{c} 5 gal/min \\\\ 1 lb/gallon of salt \\end{tabular}};\n\t\t\\fill[fill=blue!20!white] (0, -1) rectangle (2, -2);\n\t\t\\draw (0, -0.5) -- (0, -2) -- (2, -2) -- (2, -0.5);\n\t\t\\node at (1, -1.5) {\\begin{tabular}{c} 100~gal \\\\ Pure water \\end{tabular}};\n\t\t\\draw[->] (1, -2.25) -- (1, -2.75) node[pos = 1, below] {2 gal/min};\n\t\\end{tikzpicture}\n\\end{minipage}%\n\\begin{minipage}[t]{0.75\\textwidth}\n\t\\begin{center}\n\t\t(We assume the liquid in the tank is homogeneous at all times.)\n\t\\end{center}\n\tWe want to model the amount of salt in the container at any time. Let $x\\p{t}$ be the number of pounds of salt at time $t$. While we can't model $x\\p{t}$ directly, we can easily model its rate of change. To do so, we have to look at how much salt flows in and out over time. The rate of salt flow is simply the rate at which the solution flows in or out multiplied by the concentration of salt. In other words, it's the amount of salt that comes with the solution per unit time. Thus, we can model the rate of change of $x\\p{t}$ as follows:\n\\end{minipage}\n\\begin{align*}\n\t\t\\frac{\\diff{x}}{\\diff{t}} &= \\text{(inflow of salt)} - \\text{(outflow of salt)} \\\\\n\t\t&= \\p{5~\\frac{\\text{gal}}{\\text{min}} \\cdot 1~\\frac{\\text{lb}}{\\text{gal}}} - \\p{2~\\frac{\\text{gal}}{\\text{min}} \\cdot \\frac{x}{100 + \\p{5 - 3}t}~\\frac{\\text{lb}}{\\text{gal}}} \\\\\n\t\t&= 5~\\frac{\\text{lb}}{\\text{min}} - \\frac{2x}{100 + 2t}~\\frac{\\text{lb}}{\\text{min}} \\\\\n\t\t&= 5 - \\frac{x}{50 + t}\n\\end{align*}\nNotice that the outflow of salt is a function of $x$ and $t$, which is because the amount of salt isn't constant and the amount of solution in the tank changes over time (at a constant rate in this problem).\n\\par\\bigskip\nThe differential equation is linear with the initial condition $x\\p{0} = 0$, meaning we can solve it using any of the techniques discussed in this chapter. We will use variation of parameters (Section 3.3.2).\n\\begin{align*}\n\t\\frac{\\diff{x_h}}{\\diff{t}} &= -\\frac{x_h}{50 + t} \\\\\n\t\\int\\frac{\\diff{x_h}}{x_h} &= -\\int\\frac{\\diff{t}}{50 + t} \\\\\n\t\\ln{\\abs{x_h}} &= -\\ln{\\abs{50 + t}} \\\\\n\tx_h &= \\frac{1}{50 + t} \\qquad \\text{(both quantities are positive)}\n\\end{align*}\nOur solution will be in the form $x = vx_h$, so substituting into the differential equation yields\n\\begin{align*}\n\tv'x_h + vx_h' &= 5 - \\frac{vx_h}{50 + t} \\\\\n\t\\frac{v'}{50 + t} - \\cancel{\\frac{v}{\\p{50 + t}^2}} &= 5 - \\cancel{\\frac{v}{\\p{50 + t}^2}} \\\\\n\t\\frac{\\diff{v}}{\\diff{t}} &= 5\\p{50 + t} \\\\\n\tv &= 250t + \\frac{5}{2}t^2 + C\n\\end{align*}\nThus, the general solution to the mixing problem is given by \\[ x\\p{t} = \\frac{250t + \\frac{5}{2}t^{2} + C}{50 + t}. \\] With the initial condition $x\\p{0} = 0$, we get \\[ \\frac{C}{50} = 0 \\implies C = 0, \\] so the solution to the mixing problem is \\[ x\\p{t} = \\frac{250t + \\frac{5}{2}t^2}{50 + t} = \\frac{500t + t^2}{100 + 2t}. \\] A common variation to this problem is the addition to one or more tanks. In those problems, the outflow of one tank may be the inflow of another, but the overall setup will be the same. The main difference is that there will be more differential equations to solve, but they will all be linear.", "meta": {"hexsha": "51210c3b00babec90c480c1c82fe8786b551c2be", "size": 9756, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/linear.tex", "max_stars_repo_name": "stevenktruong/differential-equations-intro", "max_stars_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_stars_repo_licenses": ["MIT"], "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/linear.tex", "max_issues_repo_name": "stevenktruong/differential-equations-intro", "max_issues_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_issues_repo_licenses": ["MIT"], "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/linear.tex", "max_forks_repo_name": "stevenktruong/differential-equations-intro", "max_forks_repo_head_hexsha": "d320cb4cecd6d611687e9a58abf999a7d6e067e2", "max_forks_repo_licenses": ["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.3506493506, "max_line_length": 625, "alphanum_fraction": 0.6219762198, "num_tokens": 3831, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8558511396138365, "lm_q2_score": 0.8791467690927438, "lm_q1q2_score": 0.7524187642158472}}
{"text": "\\chapter{Numerical methods for PDE}\n\nPDE stands for Partial Differential Equations, and we are going to study in particular Finite Difference Methods, not Finite Element Methods.\n\nPDEs can be divided in three categories: elliptic, parabolic and high-parabolic. We will see a test problem on each of these categories.\n\n\\section{Poisson 2D problem with Dirichlet boundary conditions}\n\\begin{equation}\n\\text{Poisson equation:\\quad} \\Delta u(x, y) = f(x, y), \\quad (x, y) \\in \\Omega\n\\end{equation}\n\n\\begin{equation}\n\\text{Dirichlet Boundary condition:\\quad} u(x, y) = g(x, y), \\quad (x, y) \\in \\Gamma\n\\end{equation}\n\nwhere $\\Omega = (0, 1)^2$\n\n% im:I\n\nExample: the electric potential inside a domain with a defined potential inside, $f$, and a fixed potential, $g$, at the border.\n\nThe Poisson 2D problem can be solved analytically using \\textit{separation of variables} by searching for solutions of this type:\n\n\\begin{equation}\n\tu(x, y) = X(x) Y(y)\n\\end{equation}\n\nDiscretization: fix N positive integer and put $h = \\frac{1}{N}$ as the stepsize.\n\nNow we discretize the plane $\\mathbb{R}^2$ by the mesh:\n\n\\begin{equation}\n\t\\mathbb{R}^2_h = \\{(mh, nh): m,n \\in \\mathbb{Z}\\}\n\\end{equation}\n\n% im:2\n\nFor a mesh point $(mh, nh)$, with $m, n \\in \\mathbb{Z}$ we can define four neighbors:\n\n% im:3\n\nThe discrete version of $\\Omega$ is\n\n\n\\begin{equation}\n\t\\Omega_h := \\Omega \\cap \\mathbb{R}^2_h\n\\end{equation}\n\n% 4\n\nwhile the discrete version of $\\Gamma$ is the set of points $\\Gamma_h$ in $\\mathbb{R}^2_h$ which are not in $\\Omega_h$, but have a neighbor in $\\Omega_h$.\n\nNotice how $\\Gamma_h \\neq \\Gamma \\cap \\mathbb{R}^2_h$ because the four corners $\\{(0,0), (0,1), (1,0), (1,1)\\}$ are not included. \n\nWe also define $\\overline{\\Omega_h} = \\Omega_h \\cup \\Gamma_h$: this is the discrete version of $\\overline{\\Omega_h}  = \\Omega \\cup \\Gamma$.\\\\\n\n\nThe discrete version of the Poisson problem with Dirichlet Boundary conditions is:\n\n\n\\begin{equation}\n\\text{discrete Poisson equation:\\enspace} \\Delta_h u_h(x, y) = f(x, y), (x, y) \\in \\Omega_h\n\\end{equation}\n\t\n\\begin{equation}\n\\text{discrete Dirichlet Boundary condition:\\enspace} u_h(x,y) = g(x, y), (x, y) \\in \\Gamma_h\n\\end{equation}\n\n\nAn operator is a map/function, whose domains and codomains are set of functions.\n\n$\\Delta_h$ is a discrete Laplacian, i.e. and operator such that:\n\\begin{itemize}\n\t\\item it associates (as a map) to a mesh function $\\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ an interior mesh function $\\Omega_h \\rightarrow \\mathbb{R}$;\n\t\n\t\\item it approximates the Laplacian, in the sense that, for function $v: \\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ sufficiently smooth, which means $C^2(\\overline{\\Omega_h})$:\n\t\t\n\t\t\\begin{equation}\n\t\t\t\\Delta_h v |_{\\overline{\\Omega_h}} \\; (x,y) \\approx \\Delta v(x, y) \\quad (x, y) \\in \\Omega_h\n\t\t\\end{equation}\n\n\twhere $|_{\\overline{\\Omega_h}}$ is the restriction of $v$ to $\\overline{\\Omega_h}  \\subseteq \\overline{\\Omega}$.\t\n\\end{itemize}\n\nWe are going to show how to construct a discrete Laplacian.\\\\\n\n\nConsider a function $v$ of only one variable $t$. We discretize $v''(t)$ by:\n\n\\begin{equation}\n\\frac{v(t - h) - 2 v(t) + v(t + h)}{h^2}\n\\end{equation}\n.\n\n%5\n\n\\begin{equation}\n\\frac{\\frac{v(t + h) - v(t)}{h} - \\frac{v(t) - v(t - h)}{h}}{h} \\approx\\\\\n\\frac{v'(t) - v'(t-h)}{h} \\approx\\\\\nv''(t-h) \\approx v''(t)\n\\end{equation}\n\nBy Taylor approximations under the assumptions that v is $C^4$:\n\n\\begin{equation}\nv(t-h) = v(t) - v'(t) h + \\frac{1}{2} v''(t) h^2 - \\frac{1}{6} v'''(t) h^3 + \\frac{1}{24} v^{(4)}(\\alpha_h) h^4\n\\label{t-h}\n\\end{equation}\n\nwhere $\\alpha_h \\in [t-h, t]$;\n\n\\begin{equation}\nv(t+h) = v(t) + v'(t) h + \\frac{1}{2} v''(t) h^2 + \\frac{1}{6} v'''(t) h^3 + \\frac{1}{24} v^{(4)}(\\beta_h) h^4\n\\label{t+h}\n\\end{equation}\n\nwhere $\\beta_h \\in [t, t+h]$.\n\nBy summing \\ref{t-h} and \\ref{t+h} we obtain:\n\\begin{equation}\nv(t-h) + v(t+h) = 2 v(t) + v''(t) h^2 + \\frac{1}{24} (v^{(4)}(\\alpha_h) + v^{(4)}(\\beta_h)) h^4\n\\end{equation}\n\n\\begin{equation}\nv(t-h) - 2 v(t) + v(t+h) = v''(t) h^2 + \\frac{1}{24} (v^{(4)}(\\alpha_h) + v^{(4)}(\\beta_h)) h^4\n\\end{equation}\n\\begin{equation}\n\\frac{v(t-h) - 2 v(t) + v(t+h)}{h^2} = v''(t) + \\frac{1}{24} (v^{(4)}(\\alpha_h) + v^{(4)}(\\beta_h)) h^2\n\\end{equation}\n\nSo we got an approximation of the second derivative of the function $v$.\n\n\\subsection{Discretization of the Laplacian}\n\nFor a smooth function $v: \\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ we approximate the Laplacian:\\\\\n\n\n% 6\n\nby:\n\n\\begin{equation}\n\\Delta_h v(x, y) = \\frac{v(x-h, y) - 2v(x,y) + v(x+h, y)}{h^2} + \\frac{v(x, y-h) - 2v(x,y) + v(x, y+h)}{h^2}\n\\end{equation}\n\nat $(x, y) \\in \\Omega_h$.\n\n% 7\n\nThe computation of $\\Delta_h v(x, y)$ requires $v(x-h, y)$ and $v(x, y+h)$ with $(x-h, y), (x, y+h) \\in \\Gamma_h$.\n\nThis discretization of the Laplacian is called the \\textit{Five-points discretization}:\n\n% 8\n\n\n\\subsection{Assess approximation of the discrete Laplacian}\n\nConsider $v: \\overline{\\Omega} \\rightarrow \\mathbb{R}$ of class $C^4$. For $(x, y) \\in \\Omega_h$:\n\n\\begin{equation}\n|\\Delta_h v {|}_{\\overline{\\Omega_h}} (x,y) \\Delta v(x,y)|\n\\end{equation}\n\n\\begin{equation}\n|\\frac{v(x-h, y)  - 2v(x, y) + v(x+h, y)}{h} + \\frac{v(x, y-h) - 2v(x, y) + v(x, y+h)}{h} - \\frac{\\partial^2 v}{\\partial x^2}(x, y) - \\frac{\\partial^2 v}{\\partial y^2}(x, y)|\n\\end{equation}\n\nwhich is $\\leq$ than: \n\n\\begin{equation}\n|\\frac{v(x-h, y) - 2v(x, y) + v(x+h, y)}{h^2} - \\frac{\\partial^2 v}{\\partial x^2}(x, y)| + |\\frac{v(x, y-h) - 2v(x, y) + v(x, y+h)}{h^2} - \\frac{\\partial^2 v}{\\partial y^2}(x, y)|\n\\label{buh}\n\\end{equation}\n.\n\n\\ref{buh} is equal to:\n\n\\begin{equation}\n|\\frac{1}{24} ( \\frac{\\partial^4 v}{\\partial x^4}(\\alpha_h, y) + \\frac{\\partial^4 v}{\\partial x^4}(\\beta_h, y) \\; h^2) | + |\\frac{1}{24} ( \\frac{\\partial^4 v}{\\partial y^4}(x, \\gamma_h) + \\frac{\\partial^4 v}{\\partial y^4}(x, \\delta_h) \\; h^2) |\n\\label{buh2}\n\\end{equation}\n\nwhere $\\alpha_h \\in [x-h, x], \\beta_h \\in [x, x+h], \\gamma_h \\in [y-h, y], \\delta_h \\in [y, y+h]$.\n\n\\ref{buh2} (the error) can be bounded ($\\leq$) by:\n\n\\begin{equation}\n\\frac{1}{6} \\max\\{ \\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial x^4} (x, y)|, \\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial y^4} (x, y)| \\} \\; h^2\n\\end{equation}\n\nSo we can conclude that:\n\n\\begin{equation}\n\\max_{(x,y) \\in \\Omega_h}  |\\Delta_h v {|}_{\\overline{\\Omega_h}} (x,y) \\Delta v(x,y)| \\leq \\frac{1}{6} \\max\\{ \\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial x^4} (x, y)|, \\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial y^4} (x, y)| \\} \\; h^2\n\\end{equation}\n\n\nThis is called the \\textit{consistency error} of the five point approximation of the discrete Laplacian.\n\n\\subsection{Exercise}\n\nGiven $v \\in C^6(\\Omega)$, find  a function $C(x,y)$ of the point $(x, y) \\in \\overline{\\Omega}$ and $M \\ge 0$ such that \n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h}  |\\Delta_h v {|}_{\\overline{\\Omega_h}} (x,y) - \\Delta v(x,y) - C(x, y) h^2| \\le M h^4\n\\end{equation*}\n\n\\begin{equation*}\n%\\max_{(x,y) \\in \\Omega_h}  |\n\\Delta_h v {|}_{\\overline{\\Omega_h}} (x,y) = \\Delta v'(x,y) + \\text{error}\n\\end{equation*}\n\nwith $\\text{error} = O(h^2)(*) = C(x, y) h^2 + O(h^4) (**)$.\n\n\nRemind that:\n\\begin{equation}\nv''(t) \\approx \\frac{v(t - h) - 2 v(t) + v(t + h)}{h^2}\n\\end{equation}\n\nwe can continue with the Taylor expansion:\n\\begin{equation*}\nv(t-h) = v(t) - v'(t) h + \\frac{v''(t)}{2} h^2 - \\frac{v'''(t)}{6} h^3 + \\frac{v^{4}(t)}{24} h^4  - \\frac{v^{5}(t)}{120} h^5 + \\frac{v^{6}(t)}{6!} h^6\n\\end{equation*}\n\n\\begin{equation*}\nv(t-h) = v(t) + v'(t) h + \\frac{v''(t)}{2} h^2 + \\frac{v'''(t)}{6} h^3 + \\frac{v^{4}(t)}{24} h^4  + \\frac{v^{5}(t)}{120} h^5 + \\frac{v^{6}(t)}{6!} h^6\n\\end{equation*}\n\nwhere $\\alpha \\in [t-h, t]$ and $\\beta \\in [t, t+h]$.\n\n\\begin{equation*}\nv(t-h) + v(t+h) = 2v(t) + v''(t) h^2 + \\frac{v^{4}(t)}{12} h^4 + \\frac{v^{6}(\\alpha)}{6!} h^6 + \\frac{v^{6}(\\beta)}{6!} h^6\n\\end{equation*}\n\n\\begin{equation*}\n\\frac{v(t-h) - 2v(t)+ v(t+h)}{h^2} - v''(t) h^2 = \\frac{v^{4}(t)}{12} h^4 + \\frac{v^{6}(\\alpha)}{6!} h^6 + \\frac{v^{6}(\\beta)}{6!} h^6\n\\end{equation*}\n\n\n\\dots\n\n\nThe discrete problem:\n\\begin{equation*}\n\\text{Poisson equation:\\quad} \\Delta u_h(x, y) = f(x, y), (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\n\\text{Dirichlet Boundary condition:\\quad} u_h(x, y) = g(x, y), (x, y) \\in \\Gamma_h\n\\end{equation*}\n\nis a linear system of $(N-1)^2$ unknowns (where $N$ is the number of subdivisions we do in each dimension of the square)  and $(N-1)^2$ equations.\n\nThe unknowns are $u_{ij} := u_h (ih, jh)$ with $i \\in \\{1, \\dots, N-1 \\}$ and $j \\in \\{1, \\dots, N-1 \\}$.\n\n% 1 : 2018/03/15\n\n.. we don't consider the values on the borders as unknowns because they are known, from the second equation of the Dirichlet Boundary condition.\n\nOn the border $\\Gamma_h$:\n\n\\begin{equation*}\nu_{ij} = u_h (ih, jh) = h_{ij} := g(ih, jh)\n\\end{equation*}\n\nwhere \n\\begin{equation*}\n(i,j) \\in \\{0\\} \\times \\{1, \\dots, N-1 \\} \\cup \\{1, \\dots, N-1 \\} \\times \\{0\\} \\cup \\{N\\} \\times  \\{1, \\dots, N-1 \\} \\cup  \\{1, \\dots, N-1 \\} \\times \\{N\\}\n\\end{equation*}\n\nThe equations are \n\\begin{equation*}\n\\Delta_h u_h (x, y) = f(x, y), \\quad \\in \\Omega_h\n\\end{equation*}\n\neach equation corresponds to a point in $\\Omega_h$ with $(N-1)^2$ equations.\n\nThe equation corresponding to the point $(ih, jh)$, with $i \\in  \\{1, \\dots, N-1 \\}, j \\in  \\{1, \\dots, N-1 \\}$ is:\n\n\\begin{equation*}\n\\frac{u_{i-1\\; j} - 2 u_{ij} + u_{i+1\\; j}}{h^2} + \\frac{u_{i\\; j-1} - 2 u_{ij} + u_{i\\; j+1}}{h^2} = f(ih, jh) = f_{ij}\n\\end{equation*}\n\n\\begin{equation*}\nu_{i\\; j-1} + u_{i-1\\; j} -4 u_{ij} +  u_{i+1\\; j} + u_{i\\; j+1} = h^2 f_{ij}\n\\end{equation*}\n\nIn order to apply a linear system of the form $A u = b$, we need to re-arrange the equations of the points of the square (which are 2D) into a 1D vector.\n\nConsider $N=4$:\n\n% 2\n\\dots\n\nWe want to rewrite our matrix of unknowns $u$:\n\n\\begin{equation*}\nu = \\begin{bmatrix}\nu_{11} & u_{21} & u_{31} \\\\\nu_{12} & u_{22} & u_{32} \\\\\nu_{13} & u_{23} & u_{33} \\\\\n\\end{bmatrix}\n\\end{equation*}\n\nas a vector:\n\n\\begin{equation*}\nu = \\begin{bmatrix}\nu_{11} \\\\\nu_{21} \\\\\nu_{31} \\\\\nu_{12} \\\\\nu_{22} \\\\\nu_{32} \\\\\nu_{13} \\\\\nu_{23} \\\\\nu_{33} \\\\\n\\end{bmatrix}\n\\end{equation*}\n\nThen we can rewrite our equation $u_{i\\; j-1} + u_{i-1\\; j} -4 u_{ij} +  u_{i+1\\; j} + u_{i\\; j+1} = h^2 f_{ij}$ as (for the point $(1,1)$):\n\n\\begin{equation*}\nu_{10} + u_{01} - 4u_{11} + u_{21}  + u_{12} = h^2 f_{11}\n\\end{equation*}\n\nwhere $u_{10}$ and $u_{01}$ correspond to $g_{10}$ and $g_{01}$ respectively.\n\n\\begin{equation*}\n- 4u_{11} + u_{21}  + u_{12} = h^2 f_{11} - u_{10} - u_{01}\n\\end{equation*}\n\nFor the point $(2,1)$:\n\n\\begin{equation*}\nu_{20} + u_{11} - 4u_{21} + u_{31}  + u_{22} = h^2 f_{22}\n\\end{equation*}\n\nrewritten as:\n\\begin{equation*}\nu_{11} - 4u_{21} + u_{31} + u_{22} = h^2 f_{22} - g_{20}\n\\end{equation*}\n\nWe can write a matrix $\\mathcal{A}$:\n\n\\begin{equation*}\n\\mathcal{A} = \\begin{bmatrix}\n-4 &  1 &  0 &  1 &  0 &  0 &  0 &  0 &  0 \\\\\n 1 & -4 &  1 &  0 &  1 &  0 &  0 &  0 &  0 \\\\\n 0 &  1 & -4 &  0 &  0 &  1 &  0 &  0 &  0 \\\\\n 1 &  0 &  0 & -4 &  1 &  0 &  1 &  0 &  0 \\\\\n 0 &  1 &  0 &  1 & -4 &  1 &  0 &  1 &  0 \\\\\n 0 &  0 &  1 &  0 &  1 & -4 &  0 &  0 &  1 \\\\\n 0 &  0 &  0 &  1 &  0 &  0 & -4 &  1 &  0 \\\\\n 0 &  0 &  0 &  0 &  1 &  0 &  1 & -4 &  1 \\\\\n 0 &  0 &  0 &  0 &  0 &  1 &  0 &  1 & -4 \\\\\n\\end{bmatrix}\n\\end{equation*}\n\nand the unknown vector $u$:\n\n\\begin{equation*}\nu = \\begin{bmatrix}\nh^2 f_{11} - g_{01} - g_{10} \\\\\nh^2 f_{21} - g_{20}          \\\\\nh^2 f_{31} - g_{14}          \\\\\nh^2 f_{12} - g_{02}          \\\\\nh^2 f_{22}                   \\\\\nh^2 f_{32} - g_{24}          \\\\\nh^2 f_{13} - g_{03} - g_{14} \\\\\nh^2 f_{23} - g_{24}          \\\\\nh^2 f_{33} - g_{34} - g_{43} \\\\\n\\end{bmatrix}\n\\end{equation*}\n\n$\\mathcal{A}$ can be rewritten as a $3x3$ blocks matrix with blocks of size $3x3$:\n\\begin{equation*}\n\\mathcal{A} = \\begin{bmatrix}\n  A & I_3 &   0 \\\\\nI_3 &   A & I_3 \\\\\n  0 & I_3 &   A \\\\\n\\end{bmatrix}\n\\end{equation*}\n\n\nFor a general $N$, $\\mathcal{A}$ is a $(N - 1) \\times (N - 1)$ block matrix:\n\\begin{equation*}\n\\mathcal{A} = \\begin{bmatrix}\n      A & I_{N-1} &        &         &         \\\\\nI_{N-1} &       A & \\ddots &         &         \\\\\n        &  \\ddots & \\ddots &  \\ddots &         \\\\\n%\n        &         & \\ddots &       A & I_{N-1} \\\\\n        &         &        & I_{N-1} &       A \\\\\n\\end{bmatrix}\n\\end{equation*}\n\n% -4  1\n%  1 -4\n\n\nA generic matrix with dimension $n \\times n$ is called ``sparse\" if the number of non-zero elements is $O(n)$.\n\nThe matrix $\\mathcal{A}$ is sparse, block \\textit{tridiagonal} (it has elements on the diagonal, on the diagonal of the upper matrix and on the diagonal of the lower matrix), symmetric ($\\mathcal{A}^T = \\mathcal{A}$) and negative definite (all the eigenvalues are negative).\n\nConsider a symmetric (real eigen-values) matrix B $n \\times n$, B is negative definite when:\n\n\\begin{equation*}\n<x, Bx> = x^T B x = \\sum_{i=1}^{m} \\sum_{j=1}^{n} b_{ij} x_i x_j\n\\end{equation*}\n\nis $ \\le 0 \\;\\; \\forall x: n \\times 1$ vectors (negative semi-definite) and\\\\\n$< 0$ for $x \\ne 0$.\n\n\\subsection{$\\mathcal{A}$ is negative definite}\nWe are going to prove that $\\mathcal{A}$ is negative definite, which then means that it is a non-singular matrix, which means that it can be inverted, which means that our system can be solved.\n\nFirst we prove that:\n\n\\begin{equation*}\n<v, \\mathcal{A}v> \\le -2 \\; {||v||}^2\n\\end{equation*}\nfor all $v \\in \\mathbb{R}^{N-1}$.\n\n\\begin{equation*}\n<v, \\mathcal{A}v> = \\sum_{i=1}^{N-1} \\sum_{j=1}^{N-1} a_{ij} v_i v_j =\n\\end{equation*}\n\\begin{equation*}\n-4 v_{1}^{2} + v_1 v_2 + v_2 v_1 -4 v_2^2 + v_2 v_3 + v_3 v_2 - 4 v_3^2 + \\dots -4 v_{N-2}^2 + v_{N-2} v_{N-1} + v_{N-1} v_{N-2} -4 v_{N-1}^2 =\n\\end{equation*}\n\\begin{equation*}\n-4 v_1^2 -4 v_2^2 -4 v_3^2 + \\dots -4 v_{N-2}^2 - 4 v_{N-1}^2 + 2 v_1 v_2 + 2 v_2 v_3 + \\dots + 2 v_{N-2} v_{N-1} =\n\\end{equation*}\n\\begin{equation*}\n-3 v_1^2 - 2 v_2^2 - 2 v_3^2 + \\dots - 2 v_{N-2}^2 - 3 v_{N-1}^2 - (v_1^2 - 2 v_1 v_2 + v_2^2) - (v_2^2 - 2 v_2 v_3 + v_3^2) + \\dots + ( v_{N-2}^2 - 2 v_{N-2} v_{N-1} + v_{N-1}^2) =\n\\end{equation*}\n\\begin{equation*}\n-3 v_1^2 - 2 v_2^2 - 2 v_3^2 + \\dots - 2 v_{N-2}^2 - 3 v_{N-1}^2 - (v_1 - v_2)^2 - (v_2 - v_3)^2 + \\dots - (v_{N-2} - v_{N-1})^2 \\le\n\\end{equation*}\n\\begin{equation*}\n-2 v_1^2 - 2 v_2^2 - 2 v_3^2 + \\dots - 2 v_{N-2}^2 - 2 v_{N-1}^2 = -2 \\underbrace{(v_1^2 + v_2^2 + v_3^2 + \\dots + v_{N-2}^2 + v_{N-1}^2)} %{= || v ||_2^2}\n\\end{equation*}\n\n\nConsider $v = (v_1, \\dots, v_{N-1}) \\in \\mathbb{R}^{(N-1)^2}$, where $v_1, \\dots, v_{N-1} \\in \\mathbb{R}^{N-1}$.\n\n\\begin{equation*}\n<v, \\mathcal{A}v> = v^T \\mathcal{A} v = [v_1^T, v_2^T, \\dots, v_{N-1}^T]\n\\end{equation*}\n\n\n\\begin{equation*}\n<x, Bx> = \\sum_{i=1}^{m} \\sum_{j=1}^{n} b_{ij} x_i x_j = \\sum_{i=1}^{m} \\sum_{j=1}^{n} <v_i, \\mathcal{A}_ij v_j> = \n\\end{equation*}\n\\begin{equation*}\n<v_1, A v_1> + <v_1, I v_2> + <v_2, I v_1> + <v_2, A v_2> + <v_2, I v_3> + <v_3, I v_2> + <v_3, A v_3> + \\dots +\n\\end{equation*}\n\\begin{equation*}\n+ <v_{N-2}, A v_{N-2}> + <v_{N-2}, v_{N-1}> + <v_{N-1}. v_{N-2}> + <v_{N-1}. A v_{N - 1}> =\n\\end{equation*}\n\\begin{equation*}\n\\overbrace{<v_1, A v_1>}^{\\le -2 ||v_1||_2^2} + \\overbrace{<v_1, I v_2>}^{\\le -2 || v_2 ||_2^2} + \\overbrace{<v_2, I v_1>}^{\\le -2 || v_3 ||_2^2} + \\dots + \\overbrace{<v_{N-2}, A v_{N-2}>}^{\\le -2 || v_{N-2} ||_2^2} + \\overbrace{<v_{N-1}, A v_{N - 1}>}^{\\le -2 || v_{N-1} ||_2^2} + 2 \\dots\\dots \\le\n\\end{equation*}\n\\begin{equation*}\n-2 ||v_1||_2^2 -2 ||v_2||_2^2 +\\dots -2 ||v_{N-1}||_2^2 \\dots\\dots =\n\\end{equation*}\n\\begin{equation*}\n= - ||v_1||_2^2 - (||v_1||_2^2 -2 <v_1, v_2> + ||v_2||_2^2) - (||v_2||_2^2 -2 <v_2, v_3> + ||v_3||_2^2) + \\dots - (||v_{N-2}||_2^2 -2 <v_{N-2}, v_{N-1}> + ||v_{N-1}||_2^2) - ||v_{N-1}||_2^2 =\n\\end{equation*}\n\\begin{equation*}\n= - ||v_1||_2^2 - ||v_1 - v_2||_2^2 - ||v_2 - v_3||_2^2 + \\dots - ||v_{N-2} - v_{N-1}||_2^2 - ||v_{N-1}||_2^2 \\le 0\n\\end{equation*}\n\nNow we show that $<v, \\mathcal{A}v> < 0$ for  $v \\ne 0$.\n\nEquivalently, we show that $<v, \\mathcal{A}v> = 0 \\implies v = 0$.\nWhen $<v, \\mathcal{A}v> = 0$, also \n\n\\begin{equation*}\n- ||v_1||_2^2 - ||v_1 - v_2||_2^2 - ||v_2 - v_3||_2^2 + \\dots - ||v_{N-2} - v_{N-1}||_2^2 = 0\n\\end{equation*}\n\n\\dots\n\n\\begin{equation*}\n||v_1||_2 = ||v_1 - v_2||_2 = \\dots = ||v_{N-2} - v_{N-1}||_2 = ||v_{N-1}||_2 = 0\n\\end{equation*}\nand so:\n\\begin{equation*}\nv_1 = 0, v_1 = v_2, \\dots, v_{N-1} = 0\n\\end{equation*}\n\nand so:\n\\begin{equation*}\nv_1 = v_2 = \\dots = v_{N-1} = 0\n\\end{equation*}\nand so:\n\\begin{equation*}\nv = 0\n\\end{equation*}\n\n\\subsubsection*{Exercise}\n\nWrite the 1D Poisson problem with Dirichlet Boundary condition on $\\Omega = (0, 1)$.\n\nBy definition, the Laplacian is: $\\frac{\\partial^2}{\\partial x^2} (x,y) + \\frac{\\partial^2 u}{\\partial y^2} (x,y)$.\n\nThe 1D version of the Poisson problem is: $u''(x) = f(x), \\quad x \\in \\Omega = (0,1)$\n$u(x) = g(x), \\quad x \\in \\Gamma$ : $u(0) = g(0), u(1) = g(1)$.\n\n\nSolve analytically this problem:\n\n$u'(x) = u'(0) + \\int_{0}^{x} \\underbrace{u''(s)}_{f(s)} ds$, \\quad $x \\in [0, 1]$.\n\n\\begin{equation*}\nu(x) = u(0) + \\int_{0}^{x} u'(s) ds = u(0) + \\int_{0}^{x} (u'(0) + (\\int_{0}^{s} f(\\delta) d\\delta) \\;\\, ds = \n\\end{equation*}\n\\begin{equation*}\nu(0) + u'(0) \\int_{0}^{x} ds + \\int_{0}^{x} \\int_{0}^{s} f(\\delta) d\\delta ds = \n\\end{equation*}\n\n\\begin{equation*}\nu(x) = u(0) + u'(0) x + \\int_{0}^{x} \\int_{0}^{s} f(\\delta) d\\delta ds \\quad x \\in [0, 1]\n\\end{equation*}\n\n$u(0) = g(0)$\n$u(1) = u(0) + u'(0) + \\int_{0}^{1} \\int_{0}^{s} f(\\delta) d\\delta ds \\quad x \\in [0, 1]$\n\n\\dots\\dots\n\n\nPropose a corresponding discrete problem and write the associated linear system:\n\n$\\Omega = (0, 1)$, $h = 1/N$ with $N$ positive integer.\n$\\Omega_h = {h, 2h, \\dots, (N-1) h}$\n\nThe discrete problem is:\n\n\\begin{equation*}\n\\Delta_h u_h (x) = f(x), \\quad x \\in \\Omega_h\nu_h (0) = g(0)\nu_h (1) = g(1)\n\\end{equation*}\n\n$\\Delta_h$ associates to a function $\\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ a function $\\Omega_h \\rightarrow \\mathbb{R}$ that approximates $\\Delta u = u''$.\n\nFor a function $v_h: \\overline{\\Omega_h} \\rightarrow \\mathbb{R}$, we define:\n\\begin{equation*}\n\\Delta_h v_h(x) = \\frac{v_h(x-h) - 2 v_h(x) + v_h(x+h)}{h^2}, \\quad x \\in \\Omega_h\n\\end{equation*}\n\nWe can rewrite the discrete problem as:\n\\begin{equation*}\nu_i = u_h(ih), \\quad i \\in {1, \\dots, N-1}\n\\end{equation*}\n\\begin{equation*}\nf_i = f(ih)\n\\end{equation*}\n\\begin{equation*}\ng_0 = g(0), \\; g_N = g(1)\n\\end{equation*}\n\n\\begin{equation*}\n\\frac{u_{i-1} - 2 u_i + u_i+1}{h^2} = f_i, \\quad i \\in {1, \\dots, N-1}\n\\end{equation*}\n\nwith $u_0 = g_0, \\quad u_N = g_N$,\n\n\\begin{equation*}\nu_{i-1} - 2 u_i + u_i+1 = h^2 f_i, \\quad i \\in {1, \\dots, N-1}\n\\end{equation*}\n\nwith $u_0 = g_0, \\quad u_N = g_N$.\n\nThe linear system is:\n\nWe can write a matrix:\n\n\\begin{equation*}\n\\begin{bmatrix}\n-2 &  1 &    &    &    &    &    \\\\\n 1 & -2 &  1 &    &    &    &    \\\\\n   &  1 & \\ddots &  \\ddots &    &    &    \\\\\n & & \\ddots &   &   & & \\\\\n\n   &    &    &    &  1 & -2 &  1 \\\\\n   &    &    &    &    &  1 & -2 \\\\\n\\end{bmatrix}\n\\end{equation*}\n\nand the unknown vector is:\n\n\\begin{equation*}\nu = \\begin{bmatrix}\nh^2 f_{1} - g_{0}   \\\\\nh^2 f_{2}           \\\\\nh^2 f_{3}           \\\\\n\\dots               \\\\\nh^2 f_{N-2}         \\\\\nh^2 f_{N-1} - g_{N} \\\\\n\\end{bmatrix}\n\\end{equation*}\n\nFor $v \\in \\mathbb{R}^{N-1}$: $<v, \\mathcal{A}v$ = $-2 v_1^2 + v_1 v_2 + v_2 v_1 - 2 v_2^2 + \\dots$\\\\\n$. \\qquad \\quad \\qquad \\qquad \\qquad \\qquad \\qquad \\qquad  + v_{N-2} v_{N-1} + v_{N-1} v_{N-2} + 2 v_N^2 =$\n\n\\begin{equation*}\n- v_1^2 - (v_1 - v_2)^2 - (v_2 - v_3)^2 + \\dots - (v_{N-2} - v_{N-1})^2 - v_{N-1}^2 \\le 0\n\\end{equation*}\n\nIf $<v, \\mathcal{A}v> = - v_1^2 - (v_1 - v_2)^2 + \\dots - (v_{N-2} - v_{N-1})^2 - v_{N-1}^2 = 0$ then $v_1 = 0, v_1 - v_2 = 0, \\dots, v_{N-2} - v_{N-1} = 0, v_{N-1} = 0$ and so $v = 0$.\n\n\n\\subsubsection*{Exercise}\n\nConsider the 3D Poisson problem with Dirichlet boundary conditions on $\\Omega = (0, 1)^3$.\nPropose a discrete Laplacian and a consequent discrete problem.\n\n\\begin{equation*}\n\\Delta u(x, y, z) = f(x, y, z), \\quad (x, y, z) \\in \\Omega = (0, 1)^3\n\\end{equation*}\n\n\\begin{equation*}\nu(x, y, z) = g(x, y, z), \\quad (x, y, z) \\in \\Gamma\n\\end{equation*}\n\n\\begin{equation*}\n\\Delta u(x, y, z) = \\frac{\\partial^2 u}{\\partial x^2} (x, y, z) + \\frac{\\partial^2 u}{\\partial y^2} (x, y, z) + \\frac{\\partial^2 u}{\\partial z^2} (x, y, z)\n\\end{equation*}\n\n\\begin{equation*}\n\\Omega_h = \\Omega \\cap \\mathbb{R}^3_h\n\\end{equation*}\n\n\\begin{equation*}\n\\mathbb{R}^3_h = {(mh, uh, ph) : m,n,p \\in \\mathbb{Z}}\n\\end{equation*}\n\n$\\Gamma_h$ in 2D was the border without the corners. In 3D is the set of faces, without the edges and the corners.\n$\\Gamma_h = $ \"points of $\\mathbb{R}^3_h \\cap \\Gamma$ with a neighbor in $\\Omega_h$\"\n\nThe discrete problem then is \n\n\\begin{equation*}\n\\Delta_h u(x, y, z) = f(x, y, z), \\quad (x, y, z) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nu_h(x, y, z) = g(x, y, z), \\quad (x, y, z) \\in \\Gamma_h\n\\end{equation*}\n\nThe discrete Laplacian is given by a mesh function $v: \\overline{\\Omega_h} = \\Omega_h \\cup \\Gamma_h \\rightarrow \\mathbb{R}$\n\n\\begin{equation*}\n\\Delta_h v_h(x, y, z) = \\frac{v(x-h, y, z) - 2v(x,y,z) + v(x+h, y, z)}{h^2} +\\\\\n\\frac{v(x, y-h, z) - 2v(x,y,z) + v(x, y+h, z)}{h^2} + \\frac{v(x, y, z-h) - 2v(x,y,z) + v(x, y, z+h)}{h^2} \\quad (x, y, z) \\in \\Omega_h\n\\end{equation*}\n\nDescribe in the matrix of the linear system associated to the discrete problem the row corresponding to a mesh point in $\\Omega_h$ with nearest neighbors in $\\Omega_h$.\n\nIn order to write our problem in this way: $\\mathcal{A} U = b$ we need to order the unknowns.\nThere are $(N-1)^3$ unknowns, where $h = \\frac{1}{N}$; therefore $\\mathcal{A}$ is a $(N-1)^3 \\times (N-1)^3$ matrix.\n\nWhat is the equation of a point whose neighbors are part of $\\Omega_h$?\n\nWe construct the matrix from the equation $\\Delta_h u_h(x, y, z) = f(x, y, z)$; which becomes $h^2 \\Delta_h u_h(x, y, z) = h^2 f(x, y, z)$\n\n%\\begin{equation*}\n$\n-6 \\overbrace{u(x, y, z)}^{= u_{ijk} = U_l} + \\overbrace{u_h(x-h, y, z)}^{= u_{l-1}} + \\overbrace{u_h(x+h, y, z)}^{= u_{l+1}} +\\\\\n.\\qquad\\qquad\\qquad \\; \\; + \\overbrace{u_h(x, y-h, z)}^{= u_{l-(N-1)}} + \\overbrace{u_h(x, y+h, z)}^{= u_{l+(N-1)}} +\\\\\n.\\qquad\\qquad\\qquad \\; \\; + \\overbrace{u_h(x, y, z-h)}^{= u_{l- (N-1)^2}} + \\overbrace{u_h(x, y, z+h)}^{= u_{l+ (N-1)^2}} =\nh^2 f(x, y, z)\n$\n%\\end{equation*}\n\n\\begin{equation*}\n%U_{l-(N-1)^2} + U_{l-(N-1)^} + U_{l-1} - 6 U_{l} + U_{l+1} + U_{l+(N-1)} + U_{l+(N-1)^2} = h^2 f_l\n\\end{equation*}\n\n\\dots\n\n\\section{Convergence analysis of the discrete Poisson problem (with D. b.c)}\n\nWe assume that the continuous problem has a unique solution $u$.\n\nWe want to prove that the discrete problem has a unique solution $u_h$ (already done, but we obtain this by using another technique) and we want to give a bound on the error:\n\n\\begin{equation*}\n\\max_{(x,y) \\in \\overline{\\Omega}_h} |u_h (x, y) - u(x, y)|\n\\end{equation*}\n\nThis bound will prove the convergence of $\\mu_h$ to $u$ as $h \\rightarrow 0$.\n\n\n\\subsection{Theorem: Discrete maximum principle}\n\nLet $v_h: \\overline{\\Omega}_h \\rightarrow \\mathbb{R}$ such that:\n\n\\begin{equation*}\n\\Delta_h v_h \\ge 0 \\qquad \\forall (x, y) \\in \\Omega_h\n\\end{equation*}\n\nThen:\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h (x, y) \\le \\max_{(x,y) \\in \\Gamma_h} v_h (x, y)\n\\end{equation*}\n\nwith equality iff $v_h$ is constant.\n\n\\subsubsection{Continuous maximum principle}\n\nLet $v: \\overline{\\Omega} \\rightarrow \\mathbb{R}$ of class $C^2$ such that:\n\n\\begin{equation*}\n\\Delta v (x,y) \\ge 0 \\qquad \\forall (x, y) \\in \\Omega\n\\end{equation*}\n\nThen:\n\\begin{equation*}\n\\sup_{(x,y) \\in \\Omega} v(x, y) \\le \\max_{(x,y) \\in \\Gamma} v(x, y)\n\\end{equation*}\n\n\n\\subsubsection{Proof of the Discrete maximum principle theorem}\n\nWe have to prove that:\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) \\le \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\nwith $=$ iff $v_h$ is constant.\n\nWe begin by observing if $v_h$ is constant, then:\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) = \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\nGiven two logical sentences $A$ and $B$, $A \\implies B$ is equivalent to $\\neg B \\implies \\neg A$\n\nWhen $v_h$ is not constant ($A$), then ($B$):\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) < \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\nTherefore we prove the counter-opposite ($\\neg B$) of the previous equation.\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) > \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\nwhich means that $v_h$ is not constant ($\\neg A$).\n\nSuppose:\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) \\ge \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\nSo:\n\\begin{equation*}\n\\max_{(x,y) \\in \\Omega_h} v_h(x, y) = \\max_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\nConsider now a point $(x_0, y_0) \\in \\Omega_h$ where $v_h$ is the maximum.\n\nWe prove that all $(x_0 - h, y_0), (x_0 + h, y_0), (x_0, y_0 - h), (x_0, y_0 + h)$ are maximum points for $v_h$.\n\nWe have:\n\\begin{equation*}\nh^2 \\Delta_h v_h(x_0, y_0) \\ge 0\n\\end{equation*}\n\\begin{equation*}\n= v_h(x_0, y_0 - h) + v_h(x_0 - h, y_0) - 4 v_h(x_0, y_0) + v_h(x_0 + h, y_0) + v_h(x_0, y_0 + h)\n\\end{equation*}\n\nand then:\n\\begin{equation*}\n4 v_h(x_0, y_0) \\le \\overbrace{v_h(x_0, y_0 - h)}^{v_h (x_0, y_0)} + \\overbrace{v_h(x_0 - h, y_0)}^{v_h (x_0, y_0)} + \\overbrace{v_h(x_0 + h, y_0)}^{v_h (x_0, y_0)} + \\overbrace{v_h(x_0, y_0 + h)}^{v_h (x_0, y_0)}\n\\end{equation*}\nwhich means that the second member must be $\\le 4 v_h (x_0, y_0)$.\n\nThus:\n\\begin{equation*}\n4 v_h(x_0, y_0) = v_h(x_0, y_0 - h) + v_h(x_0 - h, y_0) + v_h(x_0 + h, y_0) + v_h(x_0, y_0 + h)\n\\end{equation*}\n\nand it follows that:\n\\begin{equation*}\nv_h(x_0, y_0 - h) = v_h(x_0 - h, y_0) = v_h(x_0 + h, y_0) = v_h(x_0, y_0 + h) = v_h(x_0, y_0)\n\\end{equation*}\n\nWe have proved that $(x_0 - h, y_0), (x_0 + h, y_0), (x_0, y_0 - h), (x_0, y_0 + h)$ are maximum points for $v_h$; this argument can be repeated recursively for all the neighbors, which means that they all have value $v_{max}$; we obtain that all the mesh points obtain the maximum value $v_{max}$, and $v_h$ is constant. $\\blacksquare$\n\n\\subsection{Corollary of the Discrete maximum principle}\n\nLet $v_h: \\overline{\\Omega}_h \\rightarrow \\mathbb{R}$ such that:\n\n\\begin{equation*}\n\\Delta_h v_h (x,y) \\le 0 \\qquad \\forall (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\n\\min_{(x,y) \\in \\Omega_h} v_h(x, y) \\ge \\min_{(x,y) \\in \\Gamma_h} v_h(x, y) \n\\end{equation*}\n\n\n\\subsubsection{Proof}\nConsider $w_h = - v_h$. We have:\n\n\\begin{equation*}\n\\Delta_h w_h (x, y) = - \\Delta_h v_h (x, y) \\ge 0 \\forall (x, y) \\in \\Omega_h\n\\end{equation*}\n\nFrom the discrete maximum principle, we have:\n\\begin{equation*}\n\\max_{(x, y) \\in \\Omega_h} \\overbrace{w_h (x, y)}^{= - v_h(x, y)} \\le \\max_{(x, y) \\in \\Gamma_h} \\overbrace{w_h (x, y)}^{= - v_h(x, y)}\n\\end{equation*}\n$\\blacksquare$\n\n\\subsection{Theorem:}\n\nThe discrete Poisson problem (with D. b.c.) has a unique solution.\n\n\\subsubsection{Proof:}\n\nThe discrete problem is written as a linear system: $\\mathcal{A} U = b$.\n\nExistence and uniqueness of the solution of the discrete problem follows by the non singularity of the matrix $\\mathcal{A}$.\n\n$\\mathcal{A}$ is non singular if:\n\n\\begin{equation*}\n\\mathcal{A} U = 0 \\implies U = 0\n\\end{equation*}\n\nWe are now going to prove this implication.\n\n$\\mathcal{A} U = 0$ is obtained for the discrete problem:\n\n\n\\begin{equation*}\n\\Delta_h u_h(x, y) = 0, \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nu_h(x, y) = 0, \\quad (x, y) \\in \\Gamma_h\n\\end{equation*}\n\nNow we show that $u_h = 0$ (i.e. $U = 0$).\n\nWe have:\n\n\\begin{equation*}\n\\Delta_h u_h(x, y) \\ge 0, \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\nand from the discrete max principle:\n\n\\begin{equation*}\n\\max_{(x, y) \\in \\Omega_h} u_h(x, y) \\le \\max_{(x, y) \\in \\Gamma_h} u_h(x, y) = 0\n\\end{equation*}\n\nMoreover, we have:\n\\begin{equation*}\n\\Delta_h u_h(x, y) \\le 0, \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\nand then from the discrete min principle:\n\n\\begin{equation*}\n\\min_{(x, y) \\in \\Omega_h} u_h(x, y) \\ge \\min_{(x, y) \\in \\Gamma_h} u_h(x, y) = 0\n\\end{equation*}\n\nFor any $(x, y) \\in \\Omega_h$ we have: $0 \\le u_h(x, y) \\le 0$, and so: $u_h(x, y) = 0$. $\\blacksquare$\n\n\\section{$\\infty$-norm and $L^\\infty$ norm}\n\nGiven a function $f: \\mathcal{A} \\rightarrow \\mathbb{R}$, we set:\n\n\\begin{equation*}\n||f||_{L^\\infty(\\mathcal{A})} := \\sup_{x \\in \\mathcal{A}} |f(x)|\n\\end{equation*}\n\nWhen A is finite or $\\mathcal{A} sub \\mathbb{R}^d$ closed and bounded (i.e. compact) then:\n\n\\begin{equation*}\n||f||_{L^\\infty(\\mathcal{A})} := \\max_{x \\in \\mathcal{A}} |f(x)|\n\\end{equation*}\n\n$L^\\infty(\\mathcal{A})$ is the set of functions $f: \\mathcal{A} \\rightarrow \\mathbb{R}$ such that $||f||_{L^\\infty(\\mathcal{A})} < +\\infty$.\n\nWe have, for $v: \\overline{\\Omega} \\rightarrow \\mathbb{R}$ of class $C^4$:\n\n\\begin{equation*}\n\\max_{(x, y) \\in \\Omega_h} {|\\Delta_h v|}_{\\overline{\\Omega_h}} (x, y) - \\Delta v(x, y)| \\le \\frac{h^2}{6} \\max\\{\\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial x^4} (x, y)|, \\max_{(x, y) \\in \\overline{\\Omega}} |\\frac{\\partial^4 v}{\\partial y^4} (x, y)|\\}\n\\end{equation*}\n\n\\begin{equation*}\n||\\Delta_h v{|}_{\\overline{\\Omega_h}} (x, y) - \\Delta v(x, y)||_{L^\\infty(\\Omega_h)} \\le \\frac{h^2}{6} \\max\\{ ||\\frac{\\partial^4 v}{\\partial x^4}||_{L^\\infty(\\overline{\\Omega_h})}, ||\\frac{\\partial^4 v}{\\partial y^4}||_{L^\\infty(\\overline{\\Omega_h})} \\}\n\\end{equation*}\n\nThe stability result says that the map: $(f, g) \\rightarrowtail u_h$ (underbraces: data for the discrete problem ... solution of the discrete problem) is uniformly bounded with respect to h, i.e.:\n\n\\begin{equation*}\n||u_h||_{L^\\infty(\\overline{\\Omega_h})} \\le C \\cdot \\max \\{ ||f||_{L^\\infty(\\Omega)}, ||g||_{L^\\infty(\\Gamma)} \\}\n\\end{equation*}\n\nwith a constant C independent of $f$, $g$ and $h$.\n\n\\subsection{Theorem (stability problem)}\n\nLet $f \\in L^\\infty(\\Omega)$ and let $g \\in L^\\infty(\\Gamma)$ and let $u_h$ be the solution of the discrete problem:\n\n\\begin{equation*}\n\\Delta_h u_h = f(x, y), \\qquad (x, y) \\in \\Omega_f\n\\end{equation*}\n\n\\begin{equation*}\nu(x, y) = g(x, y) \\qquad (x, y) \\in \\Gamma_h\n\\end{equation*}\n\nThen we have:\n\n\\begin{equation*}\n{||u_h||}_{L^\\infty(\\overline{\\Omega})} \\le \\frac{1}{8} \\overbrace{{||f||}_{L^\\infty(\\Omega)}}^{\\le max} + \\overbrace{{||g|}_{L^\\infty(\\Gamma)}}^{\\le max}\n\\end{equation*}\n\n\n\\subsubsection{Proof:}\nWe introduce the mesh function:\n\n\\begin{equation*}\n\\Phi(x, y) = \\frac{(x - \\frac{1}{2})^2 + (y - \\frac{1}{2})^2}{4} = \\frac{d^2}{4}, \\quad (x, y) \\in \\overline{\\Omega_h}\n\\end{equation*}\n\nWe have:\n\n\\begin{equation*}\n\\Delta_h \\Phi(x, y) = 1, \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\n\\Delta_h \\Phi(x, y) = \\frac{\\Phi(x, y-h) + \\Phi(x - h, y) - 4 \\Phi(x, y) + \\Phi(x + h, y) + \\Phi(x, y + h)}{h^2}\n\\end{equation*}\n\n\\begin{equation*}\n\\Phi(x, y - h) = \\frac{(x - \\frac{1}{2})^2 + (y - h - \\frac{1}{2})^2}{4} = \\frac{(x - \\frac{1}{2})^2 + (y - \\frac{1}{2})^2 - 2(y - \\frac{1}{2})h + h^2}{4}\n\\end{equation*}\n\n\\begin{equation*}\n\\Phi(x - h, y) = \\frac{(x - \\frac{1}{2})^2 + (y - \\frac{1}{2})^2 - 2(x - \\frac{1}{2})h + h^2}{4}\n\\end{equation*}\n\n\\begin{equation*}\n-4 \\Phi(x, y) = \\frac{-4(x - \\frac{1}{2})^2 - 4(y - \\frac{1}{2})^2}{4}\n\\end{equation*}\n\n\\begin{equation*}\n\\Phi(x, y + h) = \\frac{(x - \\frac{1}{2})^2 + (y - \\frac{1}{2})^2 + 2(x - \\frac{1}{2})h + h^2}{4}\n\\end{equation*}\n\n\\begin{equation*}\n\\Phi(x + h, y) = \\frac{(x - \\frac{1}{2})^2 + (y - \\frac{1}{2})^2 + 2(y - \\frac{1}{2})h + h^2}{4}\n\\end{equation*}\n\nwhich means\n\\begin{equation*}\n\\Delta_h \\Phi(x, y) = \\frac{\\frac{4 h^2}{4}}{h^2} = 1\n\\end{equation*}\n\nWe have:\n\n\\begin{equation*}\n0 \\le \\Phi(x,y) \\le \\frac{1}{8}, \\quad (x, y) \\in \\overline{\\Omega_h}\n\\end{equation*}\n\n\\begin{equation*}\n\\Phi(x, y) = \\frac{d^2}{4} \\le \\frac{l^2}{4} = \\frac{(\\frac{\\sqrt{2}}{2})^2}{4} = \\frac{(\\frac{1}{\\sqrt{2}})^2}{4}\n\\end{equation*}\n\nwhere $l$ is the diagonal from the center of the square to a corner:\n\nWe prove that $\\Delta_h$ is a linear operator, i.e. for $v_h, w_h: \\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ we have:\n\n\\begin{equation*}\n\\Delta_h(v_h + w_h) = \\Delta_h v_h + \\Delta_h w_h\n\\end{equation*}\n\nfor $v_h: \\overline{\\Omega_h} \\rightarrow \\mathbb{R}$ and $\\alpha \\in \\mathbb{R}$ we have:\n\n\\begin{equation*}\n\\Delta_h \\dots\n\\end{equation*}\n\nFor $(x, y) \\in \\Omega_h$:\n\n\\begin{equation*}\n\\Delta_h(v_h + w_h)(x, y) = ( v_h(x, y-h) + w_h(x, y-h) + v_h(x-h, y) + w_h(x-h, y) - 4 v_h(x,y) - 4 w_h(x, y) + v_h(x, y+h) + w_h(x, y+h) + v_h(x+h, y) + w_h(x+h, y) ) \\cdot \\frac{1}{h^2} = \n\\end{equation*}\n\n\\begin{equation*}\n= ( v_h(x, y-h)+ v_h(x-h, y) - 4 v_h(x,y) + v_h(x, y+h) + v_h(x+h, y)) \\cdot \\frac{1}{h^2} + ( w_h(x, y-h) + w_h(x-h, y) - 4 w_h(x, y) + w_h(x, y+h) + w_h(x+h, y) ) \\cdot \\frac{1}{h^2} = \n\\end{equation*}\n\n\\begin{equation*}\n= \\Delta_h v_h(x, y) + \\Delta_h w_h(x, y)\n\\end{equation*}\n\n\n\\begin{equation*}\n\\Delta_h(\\alpha v_h)(x,y) = ( \\alpha v_h(x, y-h) + \\alpha v_h(x-h, y) - \\alpha 4 v_h(x,y) + \\alpha v_h(x, y+h) + \\alpha v_h(x+h, y)) \\cdot \\frac{1}{h^2} = \\alpha (v_h(x, y)) \\dots\n\\end{equation*}\n\nSet:\n\\begin{equation*}\nA := {||f||}_{L^\\infty(\\Omega)}, B := {||g||}_{L^\\infty(\\Gamma)}\n\\end{equation*}\n\nFor $(x, y) \\in \\Omega_h$:\n\\begin{equation*}\n\\Delta_h (u_h + A\\Phi) (x, y) = \\Delta_h u_h(x, y) + A \\underbrace{\\Delta_h \\Phi(x, y)}_{=1} = \\Delta_h u_h(x, y) + A = f(x, y) + A \\ge - |f(x, y)| + \\underbrace{A}_{= \\sup_{(x, y) \\in \\Omega} |f(x, y)} \\ge 0\n\\end{equation*}\n\n\\begin{equation*}\n\\Delta_h (u_h - A\\Phi) (x, y) = \\Delta_h u_h(x, y) - A \\underbrace{\\Delta_h \\Phi(x, y)}_{=1} = \\Delta_h u_h(x, y) - A = f(x, y) - A \\le |f(x, y)| - \\underbrace{A}_{= \\sup_{(x, y) \\in \\Omega} |f(x, y)} \\le 0\n\\end{equation*}\n\nThe discrete maximum principle says that:\n\\begin{equation*}\n\\max_{(x, y) \\in \\Omega_h} (u_h + A \\Phi) (x, y) \\le \\max_{(x, y) \\in \\Gamma_h} (u_h + A \\Phi) (x, y) \n\\end{equation*}\n\n\\begin{equation*}\n\\min_{(x, y) \\in \\Omega_h} (u_h - A \\Phi) (x, y) \\ge \\max_{(x, y) \\in \\Gamma_h} (u_h - A \\Phi) (x, y) \n\\end{equation*}\n\n\\begin{equation*}\n\\max_{(x, y) \\in \\Omega_h} u_h(x, y) \\le \\max_{(x, y) \\in \\Omega_h} (\\underbrace{u_h + \\overbrace{A \\Phi(x, y)}^{\\ge 0}}_{= (u_h + A \\Phi) (x, y)}) \\le\n\\end{equation*}\n\n\\begin{equation*}\n\\le \\max_{(x, y) \\in \\Gamma_h} (\\underbrace{u_h + A \\Phi(x, y)}_{= (u_h + A \\Phi) (x, y)}) = \\max_{(x, y) \\in \\Gamma_h} (g(x, y) + A \\underbrace{\\Phi(x,y)}_{\\le \\frac{1}{8}}) \\le \\max_{(x, y) \\in \\Gamma_h}(g(x, y) - \\frac{1}{8}A) = \\max_{(x, y) \\in \\Gamma_h} \\underbrace{g(x, y)}_{\\ge -|g(x, y)|} + \\frac{1}{8}A \\le - \\max_{(x, y) \\in \\Gamma_h} |g(x, y)| - \\frac{1}{8}A \\le - \\dots\n\\end{equation*}\n\nThe opposite with the $\\min$.\n\nWe have proved, for $(x, y) \\in \\overline{\\Omega_h}$:\n\n\\begin{equation*}\n-\\frac{1}{8}A - B \\le u_h(x, y) \\le \\frac{1}{8}A + B\n\\end{equation*}\n\nThis is exactly the same of:\n\n\\begin{equation*}\n|u_h(x, y)| \\le \\frac{1}{8}A + B\n\\end{equation*}\n\nIn other words:\n\\begin{equation*}\n||u_h||_{L^\\infty()} \\dots\n\\end{equation*}\n\n\\begin{equation*}\n|| \\Delta_h v|_{\\Omega_h} - (\\Delta_h v)|_{\\Omega_h} ||_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\n\\begin{equation*}\n|| u_h - u|_{\\overline{\\Omega_h}}  ||\n\\end{equation*}\n\n\\subsection{Theorem (the convergence theorem)}\n\nLet $u$ be the solution of:\n\n\\begin{equation*}\n\\Delta u(x, y) = f(x, y) \\quad (x, y) \\in \\Omega\n\\end{equation*}\n\n\\begin{equation*}\nu(x, y) = g(x, y) \\quad (x, y) \\in \\Gamma\n\\end{equation*}\n\nand let $u_h$ be the solution of:\n\\begin{equation*}\n\\Delta u_h(x, y) = f(x, y) \\quad (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nu_h(x, y) = g(x, y) \\quad (x, y) \\in \\Gamma_h\n\\end{equation*}\n\nWe have:\n\n\\begin{equation*}\n|| u_h - u|_{\\Omega_h} ||_{L^\\infty(\\overline{\\Omega_h})} \\le \\frac{1}{8} ||\\Delta_h u|_{\\Omega_h} - (\\Delta u)|_{\\Omega_h} ||_{L^\\infty(\\Omega_h)}\n\\end{equation*}\n\n\\subsubsection{Proof:}\n\nWe set:\n\\begin{equation*}\nl_h := u_h - u|_{\\overline{\\Omega_h}}\n\\end{equation*}\n\nWe have:\n\\begin{equation*}\n\\Delta_h l_h = \\Delta_h (u_h - u|_{\\overline{\\Omega_h}}) = \\Delta_h u_h - \\Delta_h u|_{\\overline{\\Omega_h}} = \\Delta_h u_h - (\\Delta u)|_{\\Omega_h} + (\\Delta u)|_{\\Omega_h} - \\Delta_h u|_{\\Omega_h}\n\\end{equation*}\n\nWe have, for $(x, y) \\in \\Omega_h$\n\\begin{equation*}\n\\Delta_h u_h(x, y) - \\Delta u (x, y) = g(x, y) - f(x, y) = 0\n\\end{equation*}\n\nWe have:\n\\begin{equation*}\n\\Delta_h l_h = - \\epsilon_h\n\\end{equation*}\n\nwhere\n\\begin{equation*}\n\\epsilon_h = \\Delta_h u|_{\\Omega_h} - (\\Delta u)|_{\\Omega_h}\n\\end{equation*}\n\nFor $(x, y) \\in \\Gamma_h$:\n\\begin{equation*}\nl_h (x, y) = u_h (x, y) - u(x, y) = \\dots\n\\end{equation*}\n\nBy concluding, we can say that the important error $l_h$ satisfies the discrete problem:\n\\begin{equation*}\n\\Delta_h \\epsilon_h (x, y) = - \\epsilon_h(x, y) \\qquad (x, y) \\in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nl_h(x, y) = 0 \\qquad (x, y) \\in \\Gamma_h\n\\end{equation*}\n\nBy means of the previous theorem:\n\\begin{equation*}\n||l_h||_{L^\\infty(\\overline{\\Omega_h})} \\le \\frac{1}{8} \\underbrace{|| -\\epsilon_h||_{L^\\infty(\\Omega_h)}}_{= || \\epsilon_h ||_{L^\\infty(\\Omega_h)} } + \\underbrace{||o||_{L^\\infty(\\Gamma_h)}}_{= 0} \\le \\frac{1}{8} ||\\epsilon_h||_{L^\\infty(\\Omega_h)} + \\dots\n\\end{equation*}\n$\\blacksquare$\n\nWe know that:\n\\begin{equation*}\n|| \\Delta_h u|_{\\Omega_h} - (\\Delta u)|_{\\Omega_h} ||_{L^\\infty(\\Omega_h)} \\le \\frac{h^2}{6} \\max \\{ ||\\frac{\\partial^4 u}{\\partial x^4}||_{L^\\infty(\\overline{\\Omega_h})}, ||\\frac{\\partial^4 v}{\\partial y^4}||_{L^\\infty(\\overline{\\Omega_h})} \\}\n\\end{equation*}\n\nand then:\n\\begin{equation*}\n|| u_h - u|_{\\overline{\\Omega_h}} ||_{L^\\infty(\\overline{\\Omega_h})} \\le \\frac{h^2}{48} \\max \\{ ||\\frac{\\partial^4 u}{\\partial x^4}||_{L^\\infty(\\overline{\\Omega_h})}, ||\\frac{\\partial^4 v}{\\partial y^4}||_{L^\\infty(\\overline{\\Omega_h})} \\}\n\\end{equation*}\nwhen $u \\in C^4$.\n\n\\subsection{Some final remarks}\n\nConsider:\n\\begin{itemize}\n\t\\item $u$ is the solution of the continuous problem;\n\t\\item $u_h$ is the solution of the discrete problem;\n\t\\item $\\Delta_h$ is a discrete Laplacian, not necessarily the five-point discretization.\n\\end{itemize}\n\nWe define:\n\\begin{equation*}\nl_h := u_h - u|_{\\overline{\\Omega_h}}\n\\end{equation*}\n\n$l_h$ is called the \\textit{convergence error}:\n\\begin{equation*}\n\\epsilon_h := \\Delta_h u|_{\\Omega_h} - (\\Delta u)|_{\\Omega_h}\n\\end{equation*}\n\n$\\epsilon_h$ is called the \\textit{consistency error}.\n\nWe are interested on $l_h$, since $\\epsilon_h$ is a \"surrogate\" of $l_h$.\\\\\n\n\nWe say that, given $p$ a positive integer:\n\n\\begin{itemize}\n\t\\item the discretization is \\textit{consistent of order $p$} if:\n\t\t\\begin{equation*}\n\t\t|| \\epsilon_h ||_{L^\\infty(\\Omega_h)} = O(h^p) \\qquad N \\rightarrow \\infty\n\t\t\\end{equation*}\n\t\\item the discretization is \\textit{convergent of order $p$} if\n\t\t\\begin{equation*}\n\t\t|| l_h ||_{L^\\infty(\\overline{\\Omega_h})} = O(h^p) \\qquad N \\rightarrow \\infty\n\t\t\\end{equation*}\n\t\t\n\t\\item the discretization is \\textit{stable} if the solution $v_h$ of the discrete problem:\n\t\t\\begin{equation*}\n\t\t\\Delta_h v_h(x, y) = l(x,y), \\qquad (x, y) \\in \\Omega_h\n\t\t\\end{equation*}\n\t\t\\begin{equation*}\n\t\tv_h(x, y) = 0\n\t\t\\end{equation*}\n\t\n\t\twe have:\n\t\t\\begin{equation*}\n\t\t|| v_h ||_{L^\\infty(\\overline{\\Omega_h})} \\le C || l ||_{L^\\infty(\\Omega)}\n\t\t\\end{equation*}\n\t\t\n\t\twhere $C$ is independent of $l$ and $h$.\n\\end{itemize}\n\nWe have: consistency of order $p$ and stability $\\implies$ convergence of order $p$.\n\nWe have:\n\\begin{equation*}\n\\Delta_h \\l_h = \\epsilon_h in \\Omega_h\n\\end{equation*}\n\n\\begin{equation*}\nl_h = 0 in \\Gamma_h\n\\end{equation*}\n\nIf $||\\epsilon_h||_{L^\\infty(\\Omega_h)} = O(h^p)$ (consistency) and $||l_h||_{L^\\infty(\\overline{\\Omega_h})} \\le C || \\epsilon_h ||_{L^\\infty(\\Omega_h)}$ then $||L_h||_{L^\\infty(\\overline{\\Omega_h})} = O(h^p)$ (convergence).\n\n", "meta": {"hexsha": "fb8caa9fdc5f1ea6f9c36c48822645283d9f3300", "size": 39682, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/ch02.tex", "max_stars_repo_name": "bebosudo/advanced-numerical-analysis", "max_stars_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/ch02.tex", "max_issues_repo_name": "bebosudo/advanced-numerical-analysis", "max_issues_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/ch02.tex", "max_forks_repo_name": "bebosudo/advanced-numerical-analysis", "max_forks_repo_head_hexsha": "a46aea05b7bef661c689ca5facf10d5ea4a85d30", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 32.47299509, "max_line_length": 381, "alphanum_fraction": 0.5909732372, "num_tokens": 17406, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8558511451289037, "lm_q1q2_score": 0.7524187595794286}}
{"text": "\\subsection{Typing a Big Formula}\n\nHow to type a big formula step-by-step. By the end of this example you will have typed the formula:\n\n\\[\n    \\sum_{i = 1}^{ \\left[ \\frac{n}{2} \\right] }\n    \\binom{ x_{i, i + 1}^{i^{2}} }\n        { \\left[ \\frac{i + 3}{3} \\right] }\n    \\frac{ \\sqrt{ \\mu(i)^{ \\frac{3}{2}} (i^{2} - 1) } }\n        { \\sqrt[3]{\\rho(i) - 2} + \\sqrt[3]{\\rho(i) - 1} }\n\\]\n\nType each step, and compile to double check that there are no mistakes.\n\n\\begin{enumerate}\n    \\item Start with the $\\left[ \\frac{n}{2} \\right]$\\\\\n    \\begin{verbatim}\n$\\left[ \\frac{n}{2} \\right]$\n    \\end{verbatim}\n    \\item Now type the sum:\\[\n        \\sum_{i+1}^{ \\left[ \\frac{n}{2} \\right] }\n    \\]\\\\\n    For the superscript you can copy the formula above (removing the ``\\$'')\\\\\n    \\begin{verbatim}\n\\sum_{i+1}^{ \\left[ \\frac{n}{2} \\right] }\n    \\end{verbatim}\n    \\item Next the two formulas in the binomial\\[\n        x_{i, i + 1}^{i^{2}} \\qquad \\left[ \\frac{i + 3}{3} \\right]\n    \\] Type as two separated formulas\n    \\begin{verbatim}\nx_{i, i + 1}^{i^{2}} \\qquad \\left[ \\frac{i + 3}{3} \\right]\n    \\end{verbatim}\n    \\item Modify the formula above, by removing the \\texttt{qquad}, and adding \\texttt{binom} in the beginning\n    \\begin{verbatim}\n\\binom{ x_{i,i + 1}^{i^{2}} }{ \\left[ \\frac{i + 3}{3} \\right] }\n    \\end{verbatim}\n    You will get the binomial formula:\n    \\[\n        \\binom{ x_{i,i + 1}^{i^{2}} }{ \\left[ \\frac{i + 3}{3} \\right] }\n    \\]\n    \\item Next type the formula under the square root $\\mu(i)^{ \\frac{3}{2} } (i^{2} - 1)$ as\n    \\begin{verbatim}\n\\mu(i)^{ \\frac{3}{2} } (i^{2} - 1)\n    \\end{verbatim}\n    Then add the square root $\\sqrt{ \\mu(i)^{ \\frac{3}{2} } (i^{2} - 1) }$\n    \\begin{verbatim}\n\\sqrt{ \\mu(i)^{ \\frac{3}{2} } (i^{2} - 1) }    \n    \\end{verbatim}\n    \\item Type the two cubic roots: $\\sqrt[3]{ \\rho(i) - 2 }$, and $\\sqrt[3]{ \\rho(i) - 1 }$\n    \\begin{verbatim}\n\\sqrt[3]{ \\rho(i) - 2 }  \\sqrt[3]{ \\rho(i) - 1 }\n    \\end{verbatim}\n    \\item Now get the fraction\n    \\[\n    \\frac{ \\sqrt{ \\mu(i)^{ \\frac{3}{2}} (i^{2} -1) } }\n        { \\sqrt[3]{ \\rho(i) - 2 }  + \\sqrt[3]{ \\rho(i) - 1 } }\n    \\]\n    \\begin{verbatim}\n\\frac{ \\sqrt{ \\mu(i)^{ \\frac{3}{2}} (i^{2} -1) } }\n    { \\sqrt[3]{ \\rho(i) - 2 }  + \\sqrt[3]{ \\rho(i) - 1 } }\n    \\end{verbatim}\n    \\item Finally put everything together by copying-and-pasting from the steps above\n    \\begin{verbatim}\n    \\sum_{i = 1}^{ \\left[ \\frac{n}{2} \\right] }\n    \\binom{ x_{i, i + 1}^{i^{2}} }\n        { \\left[ \\frac{i + 3}{3} \\right] }\n    \\frac{ \\sqrt{ \\mu(i)^{ \\frac{3}{2}} (i^{2} - 1) } }\n        { \\sqrt[3]{\\rho(i) - 2} + \\sqrt[3]{\\rho(i) - 1} }\n    \\end{verbatim}\n    To get the complete formula\n    \\[\n    \\sum_{i = 1}^{ \\left[ \\frac{n}{2} \\right] }\n    \\binom{ x_{i, i + 1}^{i^{2}} }\n        { \\left[ \\frac{i + 3}{3} \\right] }\n    \\frac{ \\sqrt{ \\mu(i)^{ \\frac{3}{2}} (i^{2} - 1) } }\n        { \\sqrt[3]{\\rho(i) - 2} + \\sqrt[3]{\\rho(i) - 1} }\n    \\]\n\\end{enumerate}\n\nNotice the use of:\n\\begin{itemize}\n    \\item \\emph{spacing} to help distinguish the braces (Overleaf can help balancing the braces).\n    \\item Separated lines for each major part of the formula. \n\\end{itemize}\n\nThe points are for \\emph{your} readability, \\LaTeX{} itself doesn't care about spaces, but try to find the error in the formula below\n\n\\begin{verbatim}\n\\sum_{i=1}^{\\left[\\frac{n}{2}\\right]}\\binom{x_{i,i+1}^{i^{2}}}\n{\\left[\\frac{i+3}{3}\\right]}\\frac{\\sqrtt{\\mu(i)^{\\frac{3}{2}}(i^{2}-1)}}\n{\\sqrt[3]{\\rho(i)-2}+\\sqrt[3]{\\rho(i)-1}}\n\\end{verbatim}\n", "meta": {"hexsha": "10765b1c75bbe1691e40dc1a1de7b99d64af6003", "size": 3495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "examples/big_formula.tex", "max_stars_repo_name": "kaust-library/Overleaf_latex", "max_stars_repo_head_hexsha": "665a3b368ff7d15687d71e0db706c460e2bf56be", "max_stars_repo_licenses": ["MIT"], "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/big_formula.tex", "max_issues_repo_name": "kaust-library/Overleaf_latex", "max_issues_repo_head_hexsha": "665a3b368ff7d15687d71e0db706c460e2bf56be", "max_issues_repo_licenses": ["MIT"], "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/big_formula.tex", "max_forks_repo_name": "kaust-library/Overleaf_latex", "max_forks_repo_head_hexsha": "665a3b368ff7d15687d71e0db706c460e2bf56be", "max_forks_repo_licenses": ["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.5806451613, "max_line_length": 133, "alphanum_fraction": 0.5327610873, "num_tokens": 1382, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297861178929, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7523778165061102}}
{"text": "\\newpage\n\\part{Regression Analysis}\n\\section{Definition \\& Terminology}\nRegressions identify \\textbf{relationship between dependent and independent variables}.\n\\begin{itemize}\n\t\\item Association between dependent \\& independent variables, \n\t\\item Impact of independent variables on dependent variables.\n\t\\item Formulation of association/impact in functional form.\n\t\\item Used for \n\t\\begin{itemize}\n\t\t\\item descriptive analysis\n\t\t\\item numerical prediction\n\t\t\\item time series forcasting\n\t\\end{itemize}\n\\end{itemize} \n\\subsection*{Terminology}\n\\begin{itemize}\n\t\\item \\textbf{measurement tuples}: data streams  $(x_1,y_1), \\dots, (x_n,y_n)$\n\t\\item \\textbf{predictor (independent variable, feature, regressor, covariate)}: $x_i$\n\t\\item \\textbf{response (dependent variable, outcome)}: $y_i$\n\t\\item \\textbf{regression function}: $\\eta(x) = E(y|x)$\n\\end{itemize}\n\n\n\n\n\n\n\\section{Linear Regression}\n\\subsection{First Order Linear Model}\n\n$$Y = \\beta_0 + \\beta_1 X + \\varepsilon$$\n\n\\begin{itemize}\n\t\\item Y: response variable (from measurement tuples)\n\t\\item X: predictor variable (from measurement tuples)\n\t\\item $\\beta_0$: y-Axis intercept, \\textbf{unknown, to be estimated} \n\t\\item $\\beta_1$: slope, \\textbf{unknown, to be estimated}\n\t\\item $\\varepsilon$: \\textbf{residual}, random error \n\\end{itemize}\n\n\\subsection{Multiple Linear Regression Model}\n$$Y = \\beta_0 + \\beta_1 X_1 + \\beta_2 X_2 + \\dots + \\beta_k X_k + \\varepsilon$$\nFormulation in \\textbf{matrix form}:\n$$\\begin{bmatrix}\ny_1 \\\\ y_2 \\\\ \\vdots \\\\ y_m\n\\end{bmatrix} = \\begin{bmatrix}\n1 & X_11 &X_12 &\\dots &X_1k \\\\\n1 & X_21 &X_22 &\\dots &X_2k \\\\\n\\vdots & \\vdots &\\vdots &\\vdots &\\vdots \\\\\n1 & X_m1 &X_m2 &\\dots &X_mk\n\\end{bmatrix} \\begin{bmatrix}\n\\beta_0 \\\\ \\beta_1 \\\\ \\beta_2 \\\\ \\vdots \\\\ \\beta_k\n\\end{bmatrix} + \\begin{bmatrix}\n\\varepsilon_1 \\\\ \\varepsilon_2 \\\\ \\vdots \\\\ \\varepsilon_m\n\\end{bmatrix}$$\n$$[m \\times 1] = [m \\times (k+1)] \\cdot [(k+1) \\times 1] + [m \\times 1]$$\n\n\\textbf{OLS Estimator} for multiple linear regression model: minimize the RSS\n\\begin{itemize}\n\t\\item Model:\n\t\\begin{align*}\n\t\tRSS  &= e^{T} e = (y - X\\hat{\\beta})^T (y - X\\hat{\\beta}) \\rightarrow \\min \\\\\n\t\t\\rightarrow  &\\frac{\\partial RSS}{\\partial \\beta} = -2X^Ty + 2X^TX\\beta= 0\n\t\\end{align*}\n\t\n\t\\item Solution:\n\t\\begin{align*}\n\t\t\\hat{\\beta} &= (X^TX)^{-1}X^Ty \\\\ \\ \\\\\n\t\t\\hat{y} &= X(X^TX)^{-1}X^Ty\n\t\\end{align*}\n\t\n\t\\item Projection: minimizing RSS $\\rightarrow \\vec{e}$ is orthogonal to the subspace spanned by all independent variables\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[width=0.4\\textwidth]{projection.png}\n\t\\end{figure}\n\\end{itemize}\n\n\\subsection{Estimation of Coefficients: Ordinary Least Square Estimator}\n\\begin{itemize}\n\t\\item input: data streams $(x_i, y_i)$\n\t\t  \n\t\t  model: linear regression $Y = \\beta_0 + \\beta_1 X + \\varepsilon$ \n\t\t  \n\t\t  output: $\\hat{\\beta}_0$, $\\hat{\\beta}_1$\n\t\\item Goal of OLS estimator: \\textbf{minimize the sum of squared residuals (RSS) } \n\t\n\tOutlier will have larger value input when residual squared.\n\t$$\\hat{y} = \\hat{\\beta}_0 + \\hat{\\beta}_1 x$$\n\t$$\\min{\\Sigma_i e_i^2} = \\min{\\Sigma_i (y - \\hat{y})^2} = \\min{\\Sigma_i (y - (\\hat{\\beta}_0 + \\hat{\\beta}_1 x))^2} $$\n\t\n\\end{itemize}\n\\subsection{Quality Metrics of the Model}\nTo measure how well the model fits the data, you can analyze the quality model-wise or coefficient-wise.\n\\begin{itemize}\n\t\\item Model-wise: \n\t\\begin{itemize}\n\t\t\\item Residual Sum of Squares (RSS)\n\t\t\\item Total Sum of Squares (TSS)\n\t\t\\item $R^2$\n\t\\end{itemize}\n\t\\item Coefficient-wise:\n\t\\begin{itemize}\n\t\t\\item Significance-Test on each coefficient in the model\n\t\\end{itemize}\n\\end{itemize}\n\\subsubsection{Residual Sum of Squares (RSS)}\nAn \\textbf{unbiased} estimator of RSS of the population is given by \n$$RSS = \\Sigma_{i=1}^{n} (y_i - \\hat{y}_i)^2$$\n\\begin{itemize}\n\t\\item RSS = 0: the model fits 100\\% of the data\n\t\\item RSS $\\neq$ 0: distance between true $y$ and $\\hat{y}$ : residual $e$\n\t\\item RSS $\\downarrow$, model-fit quality $\\uparrow$\n\\end{itemize}\n\\subsubsection{Mean Squared Error (MSE)}\n$$MSE = \\frac{RSS}{N}$$\n\\subsubsection{Root Mean Squared Error (RMSE)}\n$$RMSE = \\sqrt{MSE}$$\n\\subsubsection{Total Sum of Squares (TSS)}\n\\textbf{Total Sum of Squares(TSS)} is the sum of Explained Sum of Squares(ESS) and Residual Sum of Squares(RSS).\n\\begin{align*}\n\t\\Sigma (y - \\bar{y})^2 &= \\Sigma (\\hat{y} - \\bar{y})^2 + \\Sigma (y - \\hat{y})^2 \\\\\n\tTSS &= ESS + RSS\n\\end{align*}\n\\subsubsection{$\\mathbf{R^2}$}\n$R^2$ measures the proportion of the variation in y that is explained by the variation in x. $\\rightarrow$ the \\textbf{proportion of Explained Sum of Squares(ESS).}\n$$R^2 = \\frac{TSS - RSS}{TSS} = 1 - \\frac{RSS}{TSS} = \\frac{ESS}{TSS}$$ \n\\begin{itemize}\n\t\\item range of $R^2$: [0,1]\n\t\\begin{itemize}\n\t\t\\item $R^2 = 0$: ESS = 0, RSS = $\\infty$. No linear relationship between x and y.\n\t\t\\item $R^2 = 1$: ESS = TSS, RSS = 0. Perfect match between x and y.\n\t\\end{itemize}\n\\end{itemize}\n\n\\subsubsection{Significance Test of the coefficients: T-Test}\n\\begin{itemize}\n\t\\item Test the significance of the coefficients in alternative hypothesis($H_1$):\n\t$$H_0: \\beta_1 = 0$$\n\t$$H_1: \\beta_1 \\neq 0$$\n\t\\item Distribution: T-Distribution\n\t\\item Degree of Freedom: if \\textbf{error variable} is \\textbf{normally distributed}, then $$df = n - 2 $$\n\t\\item test statistic:\n\t\\large{$$t = \\frac{\\hat{\\beta}_1 - 0}{SE(\\hat{\\beta}_1)} = \\dfrac{\\hat{\\beta}_1}{\\sqrt{\\frac{RSS}{\\Sigma_{i=1}^n (x_i - \\bar{x})^2} \\cdot \\frac{1}{n-2}}}$$}\n\t\\item Conclusion: \n\t\n\ttwo-sided test, reject $H_0$, if $|t| > t^c_{1-\\frac{\\alpha}{2}}$ or $p < \\alpha$\n\t\n\\end{itemize}\n\\subsubsection{Other Metrics}\n\\begin{itemize}\n\t\\item Adjusted $R^2$: allows models \\textbf{with different number of variables} to be compared\n\t\\item F-statistic: indicates linear relationship between y and \\textbf{at least one} of the xs\n\t\\item T-test of each partial regression coefficient: significance of a single coefficient while controlling others\n\\end{itemize}\n\n\n\n\\subsection{Model Specification}\nThe process of developing a regression model. It's a repeated process. You need to try different combinations or test the significance of variables to find an optimal regression model.\n\n\\begin{itemize}\n\t\\item selection of an appropriate functional form (linear, quadratic, log-linear, interaction terms, etc.)\n\t\\item choosing which variables to include (might include irrelevant or omit relevant variables)\n\\end{itemize}\n\n\\subsubsection{Functional Form of Linear Model} \n\\begin{itemize}\n\t\\item standard normal linear model(first-order/multiple)\n\t\\item nominal variables(categorical): 0 or 1\n\t\\item quadratic models: $y = \\beta_0 + \\beta_1 x_1 + \\beta_2 x_2^2 \\rightarrow z_2 = x_2^2$ \n\t\\item interaction terms: $y = \\beta_0 + \\beta_1 x_1 + \\beta_2 x_1x_2 \\rightarrow z_2 = x_1x_2$\n\t\\item exponential terms into logarithm terms: $y = \\alpha x^{\\beta}\\varepsilon \\rightarrow \\ln(y) = \\ln(\\alpha) + \\beta\\ln{x} + \\ln(\\varepsilon)$\n\\end{itemize}\n\n\\subsubsection{Choosing Variables to Include}\n\\begin{itemize}\n\t\\item Idea: The initial model might include large set of irrelevant variables or omit some relevant variables. \n\t\\item Goal: find an optimal combination that explains variation in Y with \\textbf{a small and meaningful predictors Xs} $\\rightarrow$ feature selection\n\t\\item Methods:\n\t\\begin{itemize}\n\t\t\\item \\textbf{Best Subset}: \n\t\t\n\t\tTest \\textbf{all combinations} ($2^n$) and find out best subset \n\t\t\\item \\textbf{Backward Elimination}: (top-down)\n\t\t\n\t\tStart with\\textbf{ full model with all variables}, test the significance(t-Test) of the variables.\n\t\t\n\t\tConsider the predictor with lowest t-statistic/highest p-value: remove the variable if $p > \\alpha$ (can't reject $H_0$)  \n\t\t\\item \\textbf{Forward Selection}: (buttom-up)\n\t\t\n\t\tStart with \\textbf{only one variable}, test the significance(t-Test) of the variable.\n\t\t\n\t\tOnly consider the variable with highest t-statistic/lowest p-value: add the variable if $p < \\alpha$ (reject $H_0$)\n\t\t\\item \\textbf{Stepwise Regression}: combination of forward/backward selection.\n\t\\end{itemize}\n\\end{itemize}\n \n\\subsection{Model Interpretation}\nResult of a model fitting can be retrieved by ''summary(model)''\n\\begin{itemize}\n\t\\item Hypothesis:\n\t\\begin{itemize}\n\t\t\\item Parameters: \n\t\t\n\t\t$H_0$: $\\beta_i = 0$\n\t\t\n\t\t$H_1$: $\\beta_i \\neq 0$\n\t\t\\item Whole Model: \n\t\t$H_0$: All predictors are not able to explain the model.\n\t\t\n\t\t$H_1$: The whole model is statistically significant. \t\t \n\t\\end{itemize}\n\t\\item Conclusion: \n\t\n\tfor an $\\alpha = 0.05$ level, $p > \\alpha, \\rightarrow$ cannot reject $H_0$, the parameter x is not significant from 0. \n\\end{itemize}\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[width=0.9\\textwidth]{lm_R.png}\n\\end{figure}\t\n\n\\subsubsection*{Interpretation}\n\\begin{itemize}\n\t\\item \\textbf{predictors, intercepts -- coefficient \\& p-value}: \n\t\\begin{itemize}\n\t\t\\item Significance: significant? at a significance level of $\\alpha$ = ?\n\t\t\\item $\\beta_0$: intercept, the value when all predictors are 0.\n\t\t\\item $\\beta_i$: slope, coefficient positive/negative influence of predictors on response? \n\t\t\\item \\textbf{Transformed} predictors/response\n\t\\end{itemize} \n\t\\item \\textbf{whole model -- F-statistic \\& p-value}: significant? at a significance level of $\\alpha$ = ?\n\t\\item \\textbf{Explanatory power of the model -- Adjusted $R^2$}: high/low? why?\n\t\n\\end{itemize}\n\n\n", "meta": {"hexsha": "30baa9796360677f64784a99b6c661c3b6fb3345", "size": 9308, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Business Analytics/lectures/regression_analysis.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/regression_analysis.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/regression_analysis.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.9456066946, "max_line_length": 184, "alphanum_fraction": 0.7025139665, "num_tokens": 3060, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8354835432479661, "lm_q1q2_score": 0.7523778098149658}}
{"text": "\\section{Linear Regression}\n\\smallskip \\hrule height 2pt \\smallskip\n\nThe loss is $|| y - Xw ||^2 + \\lambda || w ||^2$ \\hfill \\\\\n(this corresponds to the sum of squared error loss + L2 regularization)\\hfill \\\\\n\\hfill \\\\\n\n\\underline{Ordinary Least Squares} \\hfill \\\\\n\nNotation:\n\\begin{itemize}\n\t\\item \\textbf{$x_i$}: an input data point.  \\_\\_ rows by \\_\\_ columns. \n\t\\item \\textbf{$y_i$}: a predicted output\n\t\\item \\textbf{$\\widehat{y_i}$}: a predicted output\n\t\\item \\textbf{$\\widehat{y}$}: \n\t\\item \\textbf{$w_k$}: weight k\n\t\\item \\textbf{$\\bm{w}^*$}: the vector of weights found in regression.   \n\t\\item \\textbf{$f_k(x_i)$}\n\t\\item \\textbf{$t$}: what we want to regress against\n\t\\item \\textbf{$t_j$}: the output variable that you either have data for or are predicting. \n\t\\item \\textbf{$t(\\bm{x})$}: Data.  \"Mapping from x to t(x)\"\n\t\\item \\textbf{$H$}: $H = \\{ h_1, \\dots, h_K \\}$.  Basis functions.  In the simplest case, they can just be the value of an input variable/feature or a constant (for bias).  \n\t\\item \\textbf{$L_2$}: The $L_2$.  Can appear as a loss function to describe the deviation from data or as a penalty.  \n\t\t% Erick clarification\n\t\\item \\textbf{$ || \\widehat{w} ||_1$}: \"$L_1$\" penalty.  The \"Manhattan distance\".  Like traveling a, b in a pythagorean triangle.  $\\sum |x_i|$\n\t\\item \\textbf{$ || \\widehat{w} ||_2$}.  \"$L_2$\" penalty.  Euclidean length of a vector.  Like c in a pythagorean triangle.  $\\sqrt{\\sum |x_i|^2}$\t\n\\end{itemize}\n\n\\underline{Vocab}:\n\\begin{itemize}\n\t\\item \\textbf {bias-variance tradeoff} - the problem of simultaneously minimizing two sources of error that prevent \n\t\t\tsupervised learning algorithms from generalizing beyond their training set.  % https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff\n\t\t\t\\begin{itemize}  \n\t\t\t\t\\item The bias is error from erroneous assumptions in the learning algorithm. \n\t\t\t\t\tHigh bias can cause an algorithm to miss the relevant relations between features \n\t\t\t\t\tand target outputs (underfitting).\n\t\t\t\t\\item The variance is error from sensitivity to small fluctuations in the training set. \n\t\t\t\t\tHigh variance can cause overfitting: modeling the random noise in the training \n\t\t\t\t\tdata, rather than the intended outputs.\n\t\t\t\\end{itemize}\n\t\\item \\textbf{basis function}\n\t\\item \\textbf{bias} (parameter): like the intercept in a linear equation.  The part that doesn't depend on the features. \n\t\\item \\textbf{bias} (learning bias):  (?? \"inductive bias\" ??)  - \n\t\\item \\textbf{hyperplane} - a plane, usually with more than 2 dimensions. \n\t\\item \\textbf{input variable} - a.k.a. feature.  % https://en.wikipedia.org/wiki/Dependent_and_independent_variables\n\t\tE.g. a column like CEO salary for rows of data corresponding to different companies.\n\t\\item \\textbf{response variable} - synonyms: \"dependent variable\", \"regressand\", \"predicted variable\", \"measured variable\", \"explained variable\", \"experimental variable\", \"responding variable\", \"outcome variable\", and \"output variable\".   E.g. a predicted stock price.   \n\t\\item \\textbf{regularization} -  introducing additional information in order to solve an ill-posed problem or to prevent overfitting. \n\t% https://en.wikipedia.org/wiki/Regularization_(mathematics)\n\tE.g. applying a penalty for large parameters in the model. \n\t\\item \\textbf{ridge regression} - \n\t\\item \\textbf{vector norm}: put in a vector and get out a number like length or size.  Real valued function of some sort of vector or matrix quantity. \n\t\\item \\textbf{hyperparameters}: \\hfill \\\\\n\t$\\lambda$, not $w$.  Parameters that control your actual parameters.  \\hfill \\\\ \\hfill \\\\\n\t% Wrong?!?   Norm 1 and norm 2 are not \"parameters\".  $\\dots$ model design.  \\hfill \\\\\n\t% Wrong?!?   Different values of lambda won't change the complexity of the model.  \\hfill \\\\\n\n\t% Erick definition:\n\tIn Bayesian analysis, the parameters that don't touch the data.  \n\tLike the parameters for the prior on the prior.  \n\tCalled the ridge regression $\\lambda$ a hyperparameter, though this is a stretch in the terminology.  \\hfill \\\\\n\tClass version: \n\t\\item \\textbf{feature selection}: explicitly select features that can go into your model instead of throwing all features in. \n\t\\item \\textbf{loss function}:  \n\t\t% wikipedia:\n\t\t A function that maps an event or values of one or more variables onto a real number intuitively representing some \t\t\t\"cost\" associated with the event. \n\t\t An optimization problem seeks to minimize a loss function. \\hfill \\\\\n\t\t% week 4 typed notes near bottom. \n\t\t$\\sum_j (t(x_j) - \\sum w_i h(x_i))^2$. (least-squares error ($L_2$))  (??? = training error??)\n\t\\item \\textbf{training set error}:  *doesn't include the regularization penalty!*.  A.k.a. \"training error\".  \n\t\t\tSum of squares error divided by the number of points.   See formula later. \n%\t\\item \\textbf{training error}:  sononomous\n\\end{itemize}\n\n\\subsection{Ordinary Least Squares}\ntotal error = $\\displaystyle \\sum_i (y_i-\\hat{y_i})^2 = \\sum_i(y_i - \\sum_k w_k f_k(x_i))^2$ \\hfill \\\\\n$i$ is for each data point, $k$ is for each of the k basis functions. \n\n \\hfill \\\\ \\hfill \\\\\n\nUnder the additional assumption that the errors be normally distributed, OLS is the maximum likelihood estimator. \\hfill \\\\ % https://en.wikipedia.org/wiki/Ordinary_least_squares\n?? Use words to describe what subset of regression in general this is.  What is ordinary? What are we limiting?  \\hfill \\\\\n \\hfill \\\\\n\nThe regression problem: \\hfill \\\\\nGiven basis functions $\\{ h_1, \\dots, h_K \\}$  with $h_i(\\bf{x}) \\in \\mathbb{R}$,  \\hfill \\\\\n\tfind coefficients $\\bm{w} = \\{ w_1, \\dots, w_k \\}$.  \\hfill \\\\%  \n$t(\\bm{x}) \\approx \\widehat{f}(\\bm{x}) = \\sum_i w_i h_i(\\bm{x})$     \\hfill \\\\  \\hfill \\\\\n\n\nThis is called linear regression b/c it is linear in the parameters. \nWe can still fit to nonlinear functions by using nonlinear basis functions;  $f_k \\rightarrow  h_i$\nMinimize the \\textbf{residual squared error}: \\hfill \\\\\n$ \\displaystyle \\bm{w}* = \\argmin_{\\bm{w}}  \\sum_j (t(\\bm{x}_j) - \\sum_i w_i h_i(\\bm{x}_j))^2$  \\hfill \\\\\n$j$ for each data point, $i$ for the number of weights, which is the number of basis functions.  \\hfill \\\\\n\\hfill \\\\  \\hfill \\\\\n\nFor fitting a line in 2D space, your basis functions are $\\{ h_1(x) = x, h_2(x) = 1 \\}$.  $h_2(x)$ = 1 is the (constant) bias basis function.  The size of $w_2$ controls the effect in prediction.    \\hfill \\\\  \\hfill \\\\\n\nTo fit a parabola, your basis functions could be $\\{ h_1(x) = x^2, h_2(x)=x, h_3(x)=1 \\}$.   \\hfill \\\\\nWant a 2D parabola? Use $\\{ h_1(x) = x_1^2, h_2(x)=x_2^2, h_3(x)=x_1 x_2, \\dots \\}$. \\hfill \\\\\nCan define any basis functions $h_i(\\bm{x})$ for n-dimensional input $\\bm{x} = <x_1, \\dots, x_n>$\n\\hfill \\\\  \\hfill \\\\\n\n\\underline{Linear in feature space vs linear in the parameter space}:  \\hfill \\\\\nWhen we want to fit a parabola, we are still using a function that is linear in \\underline{parameter} space. \nThe weight matrix is still all constants. \nWhen we use nonlinear basis functions, we are nonlinear in \\underline{feature} space.  The basis functions may be transformations of the input parameters. \n \\hfill \\\\ \\hfill \\\\\n\n\\subsection{Regression: matrix notation}\n\\begin{align*}\n\t\\bm{w}* &= \\argmin_w \\sum_j(t(\\bm{x}_j - \\sum_i w_i h_i(\\bm{x}_j))^2  \\\\\n\t\\bm{w}* &= \\argmin_w (\\bm{Hw} -\\bm{t})^T (\\bm{Hw} -\\bm{t})\n\\end{align*}\n$  (\\bm{Hw} -\\bm{t})^T (\\bm{Hw} -\\bm{t})$ is the residual error.  \n\\includegraphics[width=3in]{figures/Least_squares_matricies.pdf}\n\n\\subsection{Regression: closed form solution}\n % derivation: http://courses.cs.washington.edu/courses/cse446/16wi/Slides/4_LinearRegression.pdf\n\\begin{align*}\n\t\\bm{w}^* = \\argmin_w (\\bm{Hw} -\\bm{t})^T (\\bm{Hw} -\\bm{t})  & \\\\\n\t\\bm{F}(\\bm{w}) =  \\argmin_w (\\bm{Hw} -\\bm{t})^T (\\bm{Hw} -\\bm{t}) & \\\\\n\t\\triangledown_{\\bm{w}}\\bm{F}(\\bm{w}) = 0 \\\\\n\t2 \\bm{H}^T (\\bm{H}\\bm{w}-\\bm{t}) = 0  & \\\\\n\t(\\bm{H}^T\\bm{H}\\bm{w}) - \\bm{H}^T\\bm{t} = 0 & \\\\\n\t\\bm{w}^* = (\\bm{H}^T\\bm{H})^{-1}\\bm{H}^T\\bm{t} &\n\\end{align*}\n\n\\includegraphics[width=3in]{figures/Regression_matrix_math.pdf}\n\nDimensions: \n\\begin{itemize}\n\t\\item $\\bm{t}$:  N-dimensional  (N = \\# of input data points) \n\t\\item $\\bm{w}$: \n\t\\item $\\bm{H}$: k + 1 by N.  N is \\# of rows. \n\\end{itemize}\n\\hfill \\\\\n\n\\subsubsection{Linear regression prediction is a linear function plus Gaussian noise}\n%______TA e-mail 3/15________________________\n\\underline{Casual explanation:} \\hfill \\\\\nIf we assume that our data $y_i$ is drawn from a linear function with some zero-mean Gaussian noise, i.e.\n\n$$y_i = \\sum_j w_j X_ij + \\epsilon_i$$\n(where $\\epsilon_i$ is zero-mean gaussian noise drawn from Normal(0, $\\sigma$)\n\nThen we can show that the MLE estimates of $w_j$ are exactly the optimal weights obtained by minimizing the SSE: $\\sum_i (y_i - w^T X_i)^2$\n\n(note that the variance $\\sigma$ actually doesn't matter for the derivation, you can just assume it's some positive number). \\hfill \\\\ %%\n\\hfill \\\\\n%______________________________\n\\underline{More formal explanation:} \\hfill \\\\\nWe can model as linear combination of basis functions + noise $\\epsilon$.  \nIt's safe to assume epsilon comes from Gaussian distribution.  \\hfill \\\\\n\n$t(\\bm{x}) = \\sum_i w_i h_i(\\bm{x}) + \\epsilon $ \\hfill \\\\\nNote: no $\\mu$ because we set it to zero.  \\hfill \\\\\n\nWe can learn $\\bf{w}$ using MLE: \n$P(t | x, w, \\sigma) = \\frac{1}{\\sigma \\sqrt{2 \\pi}} e^\\frac{-[t - \\sum_i w_i h_i(x)]^2}{2 \\sigma^2}$\nTake the log and maximize with respect to w:  (maximizing log-likelihood with respect to w) \\hfill \\\\\n$\\displaystyle \\ln P(D | \\bm{w}, \\sigma) = \\ln(\\frac{1}{\\sigma \\sqrt{2 \\pi}})^N \\prod_{j=1}^N e^\\frac{-[t_j - \\sum_i w_i h_i(x_j)]^2}{2 \\sigma^2}$ \\hfill \\\\\nNow find the w that maximizes this: \\hfill \\\\\n$\\argmax_w \\ln(\\frac{1}{\\sigma \\sqrt{2 \\pi}})^N + \\sum_{j=1}^N \\frac{-[t_j - \\sum_i w_i h_i(x_j)]^2}{2 \\sigma^2}$ \\hfill \\\\\nthe first term isn't impacted by $w$ so  \\hfill \\\\\n$= \\argmax_w  \\sum_{j=1}^N \\frac{-[t_j - \\sum_i w_i h_i(x_j)]^2}{2 \\sigma^2}$ \\hfill \\\\\nswitch to $\\argmin_w$ when we divide by -1.  The numerator is constant.:  \\hfill \\\\\n$= \\argmin_w  [t_j - \\sum_i w_i h_i(x_j)]^2 $ \\hfill \\\\\n\n\\textbf{Least-squares Linear Regression is MLE for Gaussians!!!}  \\hfill \\\\ \\hfill \\\\\n\nIf you have a polynomial you are fitting, how many basis functions are there (??)  \\hfill \\\\ % asked Wed 1/27\n\n\n\\subsection{OLS Protocol (incomplete)}  \\hfill \\\\\n\\begin{enumerate}\n\t\\item Chose your basis functions $h_i$.  (Requires expertise).  Can be nonlinear, e.g. $x_1^2, \\sin(x)$, etc. \n\t\t\\begin {itemize}\n\t\t\t\\item \n\t\t\t\tThe number of parameters is len(H) + 1 (bias).  \n\t\t\t\tE.g. for fitting a parabola (formula $y = ax^2 + bx + c$), \n\t\t\t\tyou have 3 parameters: weights for basis functions $x$, $x^2$, and bias. \n\t\t\t\tTypically the \\# of basis functions is $<$ the \\# of features.\n\t\t\\end {itemize}\n\t\\item Chose a regularization method so your weights don't get too big.  (see below)\n\t\\item Plug them in to regression to get the weights ($w_i$s).  (Form the sum (residual squared error + regularization) that you want to minimize, then minimize.)    \n\t\\item Make sure your weights aren't too big. \n\t\n\\end{enumerate}\n\n\\subsection{Regularization in Linear Regression}  \\hfill \\\\\nYou need to regularize to prevent parameters from growing too large.  \nBoth of these were built from the same set of basis functions; the right one is clearly over-fit. \\hfill \\\\\n\\includegraphics[width=1.2in]{figures/need_to_regularize.pdf}\n\n\\subsubsection{Ridge Regression}  \\hfill \\\\\nRidge Regression is the most famous form of linear regression\nHere is our old \"ordinary\" least squares objective function:   \\hfill \\\\\n$\\displaystyle \\widehat{w} = \\argmin_w \\sum_{j=1}^N [t(x_j) - (w_0 + \\sum_{i=1}^k w_i h_i(x_j))]^2$   \\hfill \\\\\nIt is the same as the previous ones but $i=0$ is pulled out.    \\hfill \\\\\nNow for ridge regression, we use that same notation.  \\hfill \\\\\nAnd we add a penalty term that isn't applied to the bias feature:\n\\begin{align*}\n\t\\widehat{w}_{ridge} &= \\argmin_w \\sum_{j=1}^N [t(x_j) - (w_0 + \\sum_{i=1}^k w_i h_i(x_j))]^2 + \\lambda \\sum_{i=1}^k w_i^2   \\\\\n\t&= \\argmin_w (\\bm{H}\\bm{w} - \\bm{t})^T(\\bm{H}\\bm{w}-\\bm{t}) + \\lambda \\bm{w}^T I_{0+k} \\bm{w}\n\\end{align*}\nThat $I_{0+k}$ matrix is this: \n\\includegraphics[width=1.0in]{figures/ridge_identity_matrix_with_zero.pdf}  \\hfill \\\\\n% Erick hasn't seen this notation.\nAllows you to multiply the whole weight array without getting the bias term in there. \n\nNote: $W^TW$ is $w_i^2$ or $|| w_i ||^2$ \n\nA similar derivation leads to a closed form solution:  \\hfill \\\\\n% http://courses.cs.washington.edu/courses/cse446/16wi/Slides/4_LinearRegression.pdf \n$w_{ridge}^* = (\\bm{H}^T\\bm{H} + \\lambda I_{0+k})^{-1}\\bm{H}^T\\bm{t}$ \\hfill \\\\\n(Recall that un-regularized regression was $w^* = (\\bm{H}^T\\bm{H})^{-1}\\bm{H}^T\\bm{t}$).  \\hfill \\\\   \\hfill \\\\\n\nHow do you chose how large $\\lambda$ is? \\hfill \\\\\n* As $\\lambda \\rightarrow 0$, becomes same as MLE: unregularized.  Large magnitudes of coefficients. \\hfill \\\\\n* As $\\lambda \\rightarrow \\infty$, all weights become 0.  \\hfill \\\\   \\hfill \\\\\n\n\\subsubsection{Experiment cycle}\n\\begin{enumerate}\n\t\\item select a hypothesis $f$ to best match the training set.  \n\t\t(??) Is this the same as choosing your basis functions (?)\n\t\\item isolate a held-out data set if you have enough data, or do K-fold cross-validation if not enough data. \n\t\\begin{itemize}\n\t\t\\item tune hyperparameters ($\\lambda$) on the held-out set or via cross-validation.  \n\t\t\t(Try many values of $\\lambda$ and chose the best one.) \n\t\t\\item You can use the same held-out data set each time if that set is big.  \n\t\t\\item If doing K-fold, divide the data into k subsets.  \n\t\t\t\tRepeatedly train on k-1 and test on the remaining one.  \n\t\t\t\tAverage the results. \n\t\t\\item find the $w$ that minimizes the error.  \n\t\t\t(Do so by taking the derivative and setting = 0); \n\t\t\tsee ridge regression notes. \n\t\\end{itemize}\n\t\\item Select basis functions\n\\end{enumerate}\n\n\\subsection{Regularization options: Ridge \\& Lasso}  \\hfill \\\\\nRidge: \n\\begin{itemize}\n\t\\item $ \\displaystyle \\widehat{w}_{ridge} = \\argmin_w \\sum_{j=1}^N [t(x_j) - (w_0 + \\sum_{i=1}^k w_i h_i(x_j))]^2 + \\lambda \\sum_{i=1}^k w_i^2   $ \n\t\\item $L_2$ penalty.  (\"$L_2$ norm of $\\bm{w}$).  \n\t\tLarge distances get penalized more.  $Y = x^2$: \n\t\tdon't want errors to cancel each other; differentiable. \n\\end{itemize}\nLasso: \\hfill \\\\\n\\begin{itemize}\n\t\\item$ \\displaystyle \\widehat{w}_{ridge} = \\argmin_w \\sum_{j=1}^N [t(x_j) - (w_0 + \\sum_{i=1}^k w_i h_i(x_j))]^2 + \\lambda \\sum_{i=1}^k |w_i|   $ \n\t\\item L1 penalty: linear penalty pushes more weights to zero.  Allows for a type of feature selection.  But it is not differentiable and there is no closed form solution. \n\t\\item L1 is absolute value: don't need to square it. \n\t\\item Lasso may be more useful when you have too many features for the amount of data you get.  \n\t\tExample: 100k parameters about companies to predict stock prices but only 100 data points.  \n\t\tCould tune lambda until you have about 100 nonzero weights. \n\\end{itemize}\n\nYour chose of penalty has huge effects on the algorithm! \\hfill \\\\\nSometimes $L_1$ will do better than $L_2$ and vice versa, but usually $L_2$ is more powerful than $L_1$. \\hfill \\\\\nWould be better to use a combination of the penalties than to first reduce the number of features with $L_2$ before applying $L_1$.    \\hfill \\\\\nYou can generate a lot of basis functions and use $L_1$ to chose the good ones. \\hfill \\\\\n\\hfill \\\\\n\n\\includegraphics[width=3in]{figures/lasso_and_ridge_geometry.pdf}\n\nThis figure shows: \n\\begin{itemize}\n\t\\item The contour lines represent the maximum likelihood of the vector of weights.  \n\t\tAll points on the contour have equal likelihood.\n\t\\item The two axes represent different parameters for two of the weights.  (regression coefficients)\n\t\\item Circles are characteristic of ridge regression (with L2 penalty): Penalty = the magnitude of the vector.\n\t\\item Shapes that are pointy on the axes are characteristic of Lasso (with L1 penalty): the vector components get added. \n\t\\item Where the likelihood function touches in this $w_1, w_2$ space represents the coefficients of the weights.\n\t\tFor Ridge Regression, we see that small but nonzero values of the coefficients can be obtained.\n\t\tFor Lasso Regression, the curves are most likely to touch the diamond on the axes, \n\t\tresulting in coefficients that are truly zero. \n\\end{itemize} \n\n\\includegraphics[width=1.8in]{figures/lambda_with_w2.pdf}  \\includegraphics[width=1.6in]{figures/lambda_with_w1.pdf}\nDon't compare coefficient magnitudes at given $\\lambda$s, \nbut do note that for Ridge the gradually come away from the zero axis and in Lasso they are zero until they pop out.   \\hfill \\\\ \\hfill \\\\\n\n\\subsection{Bias-Variance Tradeoff}\n\\includegraphics[width=2.0in]{figures/biasvariance.png} \n\nYour choice of hypothesis class (e.g. degree of polynomial) introduces learning bias.  \\hfill \\\\\nThe more complex the model, the more the \\_\\_\\_\\_ set accuracy goes down  \\hfill \\\\  % had \"training\" with ?\n\\textbf{A more complex class } $\\rightarrow$ less bias and more variance.   \\hfill \\\\ \\hfill \\\\\n\nFrom https://www.youtube.com/watch?v=Rm6s6gmLTdg: hfill \\\\\nHigh bias = inability to represent the true function in the class of functions we are willing to tolerate.\nPulls us to a particular function or class of functions regardless of the data.\nCan be from looking only at a specific type of function, or by having strong regularization  \\hfill \\\\\nHigh variance = extremely dependent on the exact data they were trained on.\nMight fit the data well, but may do poorly on a different data self.  \\hfill \\\\\n\n\nFrom Wikipedia: \\hfill \\\\  % https://en.wikipedia.org/wiki/Bias%E2%80%93variance_tradeoff\nIdeally, one wants to choose a model that both accurately captures the regularities in its training data, \nbut also generalizes well to unseen data. Unfortunately, it is typically impossible to do both simultaneously. \nHigh-variance learning methods may be able to represent their training set well, but are at risk of overfitting \nto noisy or unrepresentative training data. \nIn contrast, algorithms with high bias typically produce simpler models that don't tend to overfit, \nbut may underfit their training data, failing to capture important regularities. \\hfill \\\\  \\hfill \\\\\n\nModels with low bias are usually more complex (e.g. higher-order regression polynomials), \nenabling them to represent the training set more accurately. \nIn the process, however, they may also represent a large noise component in the training set, \nmaking their predictions less accurate - despite their added complexity. \nIn contrast, models with higher bias tend to be relatively simple (low-order or even linear regression polynomials), \nbut may produce lower variance predictions when applied beyond the training set. \\hfill \\\\ \\hfill \\\\\n\nAdding features (predictors) tends to decrease bias, at the expense of introducing additional variance.   \\hfill \\\\\n\\hfill \\\\\n\nSolutions:\n\\begin{itemize}\n\t\\item Dimensionality reduction and feature selection can decrease variance by simplifying models. \n\t\\item Similarly, a larger training set tends to decrease variance. \n\t\\item Use tunable modeling parameters such as applying more significant regularization.\n\\end{itemize}\n\n\\textbf{If held-out is too small, we can end up over-fitting.}\n\n\n\\hfill \\\\  \\hfill \\\\\n\n\\subsection{Error Definitions}\n\n\\underline{True (\"Prediction\") Error}:   \\hfill \\\\\nSince the training set error can be a poor measure of the \"quality\" of the solution, we can use prediction error (\"true error\").  \nThe error over all possibilities.   Instead of sum, take expectation. \n\\begin{align*}\n\terror_{true}(\\bm{w}) &= E_X[(t(\\bm{x_j})-\\sum_{i} w_i h_i(\\bm{x_j}))^2] \\\\\n\t\t& \\mbox{Gold Standard:} \\\\\n\terror_{true}(\\bm{w}) &= \\int_x (t(\\bm{x_j})-\\sum_{i} w_i h_i(\\bm{x_j}))^2 p(\\bm{x}) d\\bm{x}\n\\end{align*}\n\n% TA 3/15/2016:\n$p(x)$ is assumed to be the \"true\" distribution of the data, which we don't actually know. \n\nHow to get $p(\\bm{x})$?  Need to know the true distribution of the data (?).  \nYou almost never know how to compute $p(x)$.\nAnd, the integral is a very big sum. \\hfill \\\\  \\hfill \\\\\n\n% Find $p(x)$ using monte-carlo integration. \\hfill \\\\\n\n% TA 3/15/2016:\nTo do this, you need to split your data into training and test set. \nIf we have a dataset which is randomly sampled from $p(x)$, which we assume our data is, we can estimate the true error using the average of the samples. \nSince we train on our training set, the error might be a bad estimate of the true error (we're biased to decrease the error), so we use a separate hold-out testing set to approximate the true error in instead.\n\nSample a set of i.i.d. points  $\\{ \\bm{x}_1, \\dots, \\bm{x}_M \\}$ from $p(x)$.   \\hfill \\\\\nApproximate the integral with the sample average:\n$$ error_{true}(\\bm{w}) \\approx \\frac{1}{M} \\sum_{j=1}^M \\left( t(\\bm{x}_j - \\sum_i w_i h_i(\\bm{x}_j) \\right) $$\nThat is the sampling approximation of the predicted error: \\hfill \\\\\nThat leads to a fair approximation.   \\hfill \\\\\n\n\\hfill \\\\  \\hfill \\\\\n\nThe true prediction error is the expectation over \\textbf{future} test cases you don't have.  \nSince you don't have the x values, you go to probability. \nPick a point from the distribution, and calculate the \\_\\_\\_\\_\\_.     \\hfill \\\\  \\hfill \\\\\n\nDon't use the training data to predict true error; you've already trained to that data!  You would have too optimistic of a prediction for true error. \n\nPrediction error is high when the model is too simple \\underline{and} too complex, unlike training set error which only penalizes too simple.  \\hfill \\\\\n\\hfill \\\\\n\n\\underline{Training Set Error}:  \\textbf{optimistically biased}  (a.k.a. training error) \\hfill \\\\\n$\\displaystyle  error_{train}(\\bm{w}) = \\frac{1}{N_{train}} \\sum_{j=1}^{N_{train}}(t(\\bm{x_j})-\\sum_{i} w_i h_i(\\bm{x_j}))^2$ \\hfill \\\\\nDecreases exponentially with model complexity.   \\hfill \\\\\n\\textbf{Training error is a poor prediction of prediction error!} \\hfill \\\\\nYou expect to see training error to decrease with complexity, but that doesn't mean you have a good solution!  \\hfill \\\\\n\\hfill \\\\  \\hfill \\\\\n% http://courses.cs.washington.edu/courses/cse446/16wi/Slides/4_LinearRegression.pdf\n\n\n\\underline{Test Error}: (our final measure)  \\hfill \\\\\nUses the same formula as prediction error, except that we have never observed the test data.  See formula below. \nWe expect the true error to be smile shaped if the x-axis is model-complexity. \n\\hfill \\\\ \\hfill \\\\\n\n\\underline{\\textbf{Testing is for the user of your algorithm. }}\nThe user doesn't care about the values in your model.  They just care about how well it works.  \n They dont' care about the value of your hyperparameters. \n\n\n\\subsubsection{Effects of $\\lambda$ value on model}\n% week 4 typed notes. \n \\begin{itemize}\n \t\\item high lambda $\\rightarrow$ simple model $\\rightarrow$ lots of zeros $\\rightarrow$ high error. \n\t\\item with lambda = 0 $\\rightarrow$ converges ridge regression to regular regression. \n\t\\item with enough traiing data and lambda = 0, we expect overfitting $\\rightarrow$ small training error. \n\\end{itemize}\n\n\\subsubsection{Choosing $\\lambda$}\nHow to find lambdas? \n\\begin{itemize}\n\t\\item try a bunch and find which does best on the held out data set.  \n\t\tCan't touch test data, even w/ stick so use held-out set. \n\t\\item Do k-fold cross validation to pick the lambda that gives minimum error. \\hfill \\\\\n\t\tAverage over the loss curves Loss($fold_i$, $\\lambda$) \\hfill \\\\ \n\t\tMinimum error = lowest loss on the hold-out set (the curve should look U shaped, so you just find the bottom of the U).  \\hfill \\\\\n\t\tMay not find the bottom-of-the-U shape lambda.    \\hfill \\\\\n\t\tBut it is ok to be off a bit; the red U might be pretty flat at the bottoms. \\hfill \\\\\n\\end{itemize}\t\t\nThis use of the held-out data doesn't count as training.  \nLambda is fixed each time, and we train separately. \nTraining on training data, just watching the number on the held-out set. \\hfill \\\\\n\\textbf{The model's parameters are not determined by the held-out data} \\hfill \\\\\n\\hfill \\\\\n\nHow do you chose the range of lambda? (practical solution) \n\\begin{itemize}\n\t\\item You are limited to a grid search over values of lambda. \n\t\\item You need a strategy for sweeping that space.   \n\t\tCould do a \"binary search\", or something like a gradient search: \n\t\ttake a step until we screw it up, and step back smaller.   \n\t\tIf it gets worse, you take a smaller step.\n\t\\item From your loss, take the value of your loss (compute it).  \\hfill \\\\\n\t\tLoss = $(t(x) - \\sum w_i h(x_i))^2$  \n        \t\t\\textbf{\"You should be able to find loss given w}\n            \tCan compute norm of W, too.  \n\t\tIf your loss is on the order of 1000 and your norm is on the order of 1, you can use these for defining search space.\n                \tFirs try lamba = 1, 10, 100, 1000.  \n\t\tFind the best from there then explore around there.\n\t\tIf 100 was good, try 200, etc.   \n\t\tYou just want to know in which order the loss function is going to appear. \n\\end{itemize}\n\n\\subsubsection{How to handle error calculations:}\nGiven a dataset, randomly split it into two parts:  \\hfill \\\\\n* training data: $\\{ \\bm{x_1}, \\dots, \\bm{x_{N_train}} \\}$   \\hfill \\\\\n* test data: $\\{ \\bm{x_1}, \\dots, \\bm{x_{N_test}} \\}$   \\hfill \\\\\nUse the training data to optimize parameters $\\bm{w}$. \\hfill \\\\\nTo calculate the test set error, you use the final solution $\\bm{w^*}$ and calculate \\hfill \\\\\n$\\displaystyle error_{test}(\\bm{w}) \\approx \\frac{1}{N_{test}} \\sum_{j=1}^{N_{test}} (t(\\bm{x_j} - \\sum_i w_i h_i(\\bm{x_j}))^2$  \\hfill \\\\\n\n\\includegraphics[width=3in]{figures/errors_as_f_of_complexity.pdf}   \\hfill \\\\\n(blue is train, red is true, green is test) \\hfill \\\\\n\n\\subsubsection{overfitting}\nAssume: \\hfill \\\\\n* Data generated from distribution D(X,Y). \\hfill \\\\\n* A hypothesis space H \\hfill \\\\\nDefine:  \\hfill \\\\\n* Training error: $error_{train}(h)$ \\hfill \\\\\n* Data (true) error: $error_{true}(h)$ \\hfill \\\\\nWe say $h$ \\textbf{overfits} the training data if there exists an $h' \\in H$ such that:  \\hfill \\\\ \n* $error_{train}(h) < error_{train}(h)'$ and $error_{true}(h) > error_{true}(h)'$\n\n\\includegraphics[width=2in]{figures/Error--vs_lambda--fixed_model_complexity.pdf}   \\hfill \\\\\nLambda (the regularization parameter) is fixed.  Blue = training set error.  \nLeads to overfitting/too-large-parameters when $\\lambda$ --> 0. \nRed = true error, which likes a happy medium $\\lambda$.  \\hfill \\\\  \\hfill \\\\\n\n\\textbf{Warning}: your test set is only unbiased if you never ever ever do \\textbf{any} learning on the data. \nThis includes using the test data to select for the degree of the polynomial you fit.   \\hfill \\\\  \\hfill \\\\\n(Recall, you can create a held-out/validation set from your training data or do k-fold validation.)  \\hfill \\\\\n\\hfill \\\\\n\nThe height of the true error (red curve) is the \"bias\".  \\hfill \\\\\n\n\\subsubsection{What you need to know}\nRegression:\n\\begin{itemize}\n\t\\item Basis functions = features\n\t\\item Optimizing a sum of squared errors\n\t\\item Relationship between regression and Gaussians\n\\end{itemize}\nRegularization\n\\begin{itemize}\n\t\\item Ridge regression math\n\t\\item LASSO formulation\n\t\\item How to set lambda\n\\end{itemize}\nBias-Variance trade-off\n\n\n\n\n\n", "meta": {"hexsha": "ecb7c2433ba72494351b71255ecf027248822172", "size": 27097, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/linear_regression.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/linear_regression.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/linear_regression.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.6406570842, "max_line_length": 272, "alphanum_fraction": 0.7057238809, "num_tokens": 8134, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8872046056466901, "lm_q2_score": 0.8479677583778258, "lm_q1q2_score": 0.7523209006727067}}
{"text": "\\paragraph{Simplicial convolution.}\n\nA convolutional layer is of the form $\\psi\\circ(f\\ast \\varphi_W)$, where $\\ast$ denotes convolution, $\\varphi_W$ is a function\n\\emph{with small support} parameterized by learnable weights $W$, and $\\psi$ is some nonlinearity and bias. This formulation of CNNs lends itself to a spectral interpretation that we exploit to extend CNNs to a much more general setting.\n\nFollowing~\\cite{defferrard2016convolutional} and motivated by the fact that the discrete Fourier transform of a real-valued function on an $n$-dimensional cubical grid coincides with its decomposition into a linear combination of the eigenfunctions of the graph Laplacian for that grid, we define the Fourier transform of real $p$-cochains on a simplicial complex with Laplacians $\\mathcal{L}_p$ as\n\\begin{align*}\n  &\\mathcal{F}_p: C^p(K) \\to \\mathbb{R}^{\\lvert K_p \\rvert} \\\\\n  &\\mathcal{F}_p(c) = \\left(\\ip{c}{e_1}_p, \\ip{c}{e_2}_p, \\dotsc, \\ip{c}{e_{\\lvert K_p \\rvert}}_p\\right),\n\\end{align*}\nwhere the $e_i$'s are the eigencochains of $\\mathcal{L}_p$ ordered by eigenvalues $\\lambda_1\\leq\\dotsm\\leq\\lambda_{\\lvert K_p \\rvert}$. The function $\\mathcal{F}_p$ is invertible since $\\mathcal{L}_p$ is diagonalizable; explicitly, if we write $U\\diag(\\Lambda)U\\transpose$ for a normalized eigendecomposition, the orthonormal matrices $U$ and $U\\transpose$ represent $\\mathcal{F}\\inv_p$ and $\\mathcal{F}_p$, respectively. This is the foundation for Barbarossa's development of signal processing on simplicial complexes~\\cite{barbarossa2018learning}.\n\nRecall that on the function classes for which it is defined, the classical Fourier transform satisfies $\\mathcal{F}(f\\ast g)=\\mathcal{F}(f)\\mathcal{F}(g)$, where the right-hand side denotes pointwise multiplication. This will be our definition of convolution in the simplicial setting. Indeed, for cochains $c,c'\\in C^p(K)$ we \\emph{define} their convolution as the cochain\n\\begin{equation*}\n  c\\ast_p c' = \\mathcal{F}_p\\inv\\left(\\mathcal{F}_p(c)\\mathcal{F}_p(c')\\right).\n\\end{equation*}\n\nWithin this framework, we are led to define a \\emph{simplicial convolutional layer} with input $p$-cochain $c$ and weights $W$ as being of the form\n\\begin{equation*}\n  \\psi\\circ\\left(\\mathcal{F}\\inv_p(\\varphi_W)\\ast_p c\\right)\n  \\end{equation*}\nfor some as of yet unspecified $\\varphi_W\\in\\mathbb{R}^{\\lvert K_p \\rvert}$. To ensure the central property that a convolutional layer be localizing, we demand that $\\varphi_W$ be a low-degree polynomial in $\\Lambda=(\\lambda_1, \\dotsc, \\lambda_{\\lvert K_p \\rvert})$, namely\n\\begin{equation*}\n  \\varphi_W = \\sum_{i=0}^N W_i\\Lambda^i = \\sum_{i=0}^N W_i(\\lambda^i_1, \\lambda^i_2, \\dotsc, \\lambda^i_{\\lvert K_p \\rvert}),\n\\end{equation*}\nfor small $N$. In signal processing parlance, one would say that such a convolutional layer \\emph{learns filters that are low-degree polynomials in the frequency domain}.\n\nThe reason for restricting the filters to be these low-degree polynomials is best appreciated when writing out the convolutional layer in a basis. Let $L^i_p$ denote the $i$'th power of the matrix for $\\mathcal{L}_p$ in, say, the standard basis for $C^p(K)$, and similarly for $c$. Then (ignoring $\\psi$),\n\\begin{equation*}\n  \\mathcal{F}\\inv_p(\\varphi_W)\\ast_p c = \\sum_{i=0}^N W_iU\\diag(\\Lambda^i)U\\transpose c = \\sum_{i=0}^N W_i\\left(U\\diag(\\Lambda)U\\transpose\\right)^i c = \\sum_{i=0}^NW_iL^i_pc. %\\label{eq:filter}\n\\end{equation*}\nThis is important for three reasons, like for traditional CNNs.\nFirst, the convolution can be efficiently implemented by $N$ sparse matrix-vector multiplications: This reduces the computational complexity from $\\mathcal{O}(\\lvert K_p\\rvert^2)$ to $\\mathcal{O}(\\xi\\lvert K_p\\rvert)$ where $\\xi$ is the density factor.\nSecond, the number of weights to be learned is reduced from $\\mathcal{O}(\\lvert K_p\\rvert)$ to $\\mathcal{O}(1)$.\nThird, the operation is $N$-localizing in the sense that if two simplices $\\sigma,\\tau$ are more than $N$ hops apart, then a degree-$N$ convolutional layer does not cause interaction between $c(\\sigma)$ and $c(\\tau)$ in its output (see the supplementary material).\nThose local interactions (in the spatial domain) can be interpreted as message-passing between simplices.%~\\cite{gilmer2017NeuralMP}.\n\n%In practice we implement \\refeq{filter} using Chebyshev polynomials, as suggested for GNNs in~\\cite{defferrard2016convolutional}.\n%\\mdeff{Not very important: The choice of polynomial (monomials, Chebyshev, Legendre, etc.) doesn't make much difference in practice.}\n", "meta": {"hexsha": "88a41c028df3095256d64aa95f5b5abaec6d0735", "size": 4519, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "scnn.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": "scnn.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": "scnn.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": 112.975, "max_line_length": 549, "alphanum_fraction": 0.7537065723, "num_tokens": 1392, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.942506726044381, "lm_q2_score": 0.7981867729389246, "lm_q1q2_score": 0.7522964021345956}}
{"text": "\\lab{Algorithms}{Temporal Complexity and Sparse Matrices}{Complexity and Sparse Matrices}\n\n\\objective{It also introduces the concept of temporal complexity. \nFinally, it explores SciPy's special methods for working with sparse matrices.}\n\n\\section*{Temporal Complexity}\nOne of the most important questions in scientific computing is: \nHow long will this operation take?  \nThe concept of temporal complexity attempts to answer this question by determining \nhow much time a function needs to operate on a given size of input.  \nFor example suppose calculating the inverse of a matrix of size $n$ requires the following number of calculations.\n\\begin{equation*}\nf(n) = \\frac{3n^3}{2} + 75n^2 + 250n + 30\n\\end{equation*}\nWhat is the most important part of this expression? \nWhen our input gets very large the only relevant term in this equation is $n^3$. \nFor this reason we say that $f(n) \\in O(n^3)$, or more commonly that $f(n)$ is $O(n^3)$ \n(spoken ``Big O of n cubed'' or ``order of n cubed\"). \nThis notation is borrowed from analysis. The notation captures the salient behavior of our temporal complexity, \nor more precisely the growth rate we can expect of the execution time of our algorithm. \nWe also refer to this as \\emph{asymptotic notation}. \nWe will discuss this concept later, but this is a simple introduction to the notion of complexity and Big O.\n\\begin{definition}[Temporal Complexity]\nLet $n$ represent the problem size.  Let $f(n)$ and $g(n)$ be functions mapping natural numbers to positive real numbers. \n$f \\in O(g(n))$ if $\\exists c > 0, \\forall n > n_0, f(n) \\leq cg(n)$. \nWhen this is satisfied, we say that $g(n)$ is an asymptotic upper bound for $f(n)$. \nThe notation $f = O(g(n))$ is also common.\n\\end{definition}\n\n\\begin{problem}\nVerify the following relationships\n\\begin{itemize}\n\\item $O(\\log{n}) \\subset O(n) \\subset O(n\\log{n})$\n\\item $O(n^k) \\subset O(n^{k+1})$\n\\item $O(n^p) \\subset O(2^n)$ for all $p \\in \\mathbb{N}$\n\\end{itemize}\n\\end{problem}\n\nWhat does this have to do with computer programs?  \nEvery algorithm executed on a computer corresponds to a function \nthat returns the number of steps taken (and therefore the time) \ngiven an input of size n.  Certain problems can be solved with fewer steps,\nwhilst others require many more.  For example, given two matrices of size n,\nit only takes about n steps to add the entries together and thus matrix addition is $O(n)$.  \nOn the other hand, given a matrix of size $n$, it takes about \n$n^3$ steps to calculate its inverse, \nand thus inverting a matrix is $O(n^3)$.\nThere is something inherently more difficult about inverting a matrix; \nthere is complexity that simply isn't there with the straightforward operation of addition.\n\nHow do we determine the temporal complexity of a piece of code?\nCalculating the exact temporal complexity of a formula is fairly difficult.\nHowever, to asymptotically analyze a function is fairly straightforward.\n\\begin{lstlisting}\ns = 0\nfor i in xrange(100):\n    s = s + i\n\\end{lstlisting}\nThe code above is $O(n)$ because it takes approximately $n$ steps to complete its work.\nFor-loops are a good indicator of the complexity is.  A double for-loop strongly suggests\n$O(n^2)$ or worse.  The reason that array addition is $O(n^2)$ is because we have to add\n$n^2$ elements in and $n \\times n$ array.  Asymptotic analysis reveals that\nif we have an array of size $n \\times n$ and it takes $x$ seconds to execute a $O(n^2)$ algorithm,\nthen if we increase the size of the array to $2n \\times 2n$, we should expect the same algorithm\nto terminate in about $(2)^2 x = 4x$ seconds.  Sometimes, when you don't have code to look at, \nyou can determine the asymptotic growth of a function by timing it on various sized inputs.\n\n\\begin{problem}\nDetermine the asymptotic growth of the following code that calculates all the partial sums\nup to 1000.\n\\begin{lstlisting}\nt = 0\nfor n in xrange(1000):\n    t += sum(xrange(n))\n\\end{lstlisting}\n%the asymptotic growth is $O(n^2)$\n\\end{problem}\n\nWe can also classify an algorithm by the amount of memory it needs to execute.  We will use the term \\emph{spatial complexity} to measure the amount of memory an algorithm uses.  The definition of spatial complexity is the same as the definition for temporal complexity with the obvious difference that $n$ refers to space rather than time.\n\n\\section*{Sparse Matrices}\nA sparse matrix is a matrix that has relatively few nonzero elements.\nSciPy has several different ways of storing sparse matrices.  \nEach way has it pros and cons (the reader is encouraged to read the help for each way).\n\n\\begin{table}[h!]\n\\centering\n\\begin{tabular}{|l|l|}\n\\hline\nFunction & Description \\\\\n\\hline\n\\li{sparse.bsr()} & Compressed Block Sparse Row\\\\\n\\li{sparse.coo()} & Coordinate\\\\\n\\li{sparse.csc()} & Compressed Sparse Column\\\\\n\\li{sparse.csr()} & Compress Sparse Row\\\\\n\\li{sparse.dia()} & Sparse Diagonal\\\\\n\\li{sparse.dok()} & Dictionary of Keys\\\\\n\\li{sparse.lil()} & Linked List\\\\\n\\hline\n\\end{tabular}\n\\caption{Sparse matrix representations in SciPy}\n\\end{table}\nType the following into IPython.\n\\begin{lstlisting}\n: from scipy import sparse\n: A = np.diagflat([2,3,4])\n: B = sparse.csc_matrix(A)\n: C = B.todense()\n\\end{lstlisting}\nNotice that the matrix $A$ has only three non-zero entries, and so we can consider it sparse. \nIn memory, an array stores a bit of data (be it an integer, float, or complex number)\neach entry, meaning that a $3 \\times 3$ matrix requires a total 9 blocks of memory. \nHowever, if we leverage the sparsity of $A$ we realize that we only need to store 3 numbers.\nThe \\li{sparse} methods do exactly this: they store only the non-zero entries and their locations in the matrix.\nNo longer are we working with an array.  SciPy has many methods for performing operations on sparse matrices.\nTo convert back to a dense matrix, we use the \\li{todense()} method of the sparse matrix. \nWe can also convert between the different types sparse matrices.\n\nWe remark that if you want to make a sparse diagonal matrix, the\nbest way to do it isn't to use \\li{diagflat()} followed by \\li{sparse},\nit's actually better to use the \\li{sparse.spdiags()} method:\n\\begin{lstlisting}\n: sparse.spdiags([2,3,4],0,3,3)\n\\end{lstlisting}\nOften, when we are using sparse matrices, we are dealing with matrices \nthat are too large to be handled efficiently when represented in full form.\n\n\\section*{Banded Matrices}\nA banded matrix is one whose only non-zero entries are diagonal\nstrips.  For example, the matrix\n\\begin{equation*}\nA = \\begin{pmatrix} \n1 & 2 & 0 & 0 \\\\\n3 & 4 & 5 & 0 \\\\\n0 & 6 & 7 & 8 \\\\\n0 & 0 & 9 & 10\n\\end{pmatrix}\n\\end{equation*}\nis banded because there are three nonzero diagonals.  This\nparticular type of banded matrix is called a tri-diagonal matrix.\n\nYou can easily create banded matrices using the \\li{diagflat()} method.\nFor example, the matrix $A$ above can be created by entering\n\\begin{lstlisting}\n: np.diagflat([3, 6, 9], -1) + np.diagflat([1, 4, 7, 10], 0) + np.diagflat([2, 5, 8], 1)\n\\end{lstlisting}\n\nOften a better way to create a tri-diagonal is it use the \\li{sparse.spdiags()} method. \nThis is because many diagonal matrices are sparse. \nFor example, we create the same matrix in Python (while designating that it is sparse) using the command:\n\\begin{lstlisting}\n: Z = np.array([[3, 1, 0], [6, 4, 2], [9, 7, 5], [0, 10, 8]]).T\n: sparse.spdiags(Z, [-1, 0, 1], 4, 4)\n\\end{lstlisting}\n\nFor more information, check the documentation by typing \\li{spar.spdiags?}. \nFor example we create a tri-diagonal array with uniformly distributed random entries. \nThis example also demonstrates the efficiency of using sparse arrays.\n\\begin{lstlisting}\n: B = np.rand(3,10000)\n: A = sparse.spdiags(B, range(-1, 2), 10000, 10000)\n: denseA = A.todense()  #only do this step if you have _lots_ of memory!\n: A.data.nbytes\n240000          #about 0.24MB of memory\n: denseA.nbytes\n800000000       #about 762.9MB of memory!\n\\end{lstlisting}\nWe can't use the \\li{full} command in this case because the computer will almost \ncertainly run out of memory (the matrix is $10000 \\times 10000$). \nHowever, we can still visualize this matrix using the \\li{plt.spy()} command from Matplotlib, \nwhich essentially shows the location of non-zero entries in a matrix. \nThe output of \\li{plt.spy(A)} in this case is shown in Figure \\ref{fig:mpl_spy}.\n\\begin{figure}[h]\n\\centering\n\\includegraphics[width=\\textwidth]{spy.pdf}\n\\caption{The output of the \\li{spy()} command}\n\\label{fig:mpl_spy}\n\\end{figure}\n\n\\section*{Using Sparse Matrices}\nConsider the linear system $A x = b$, where $A$ is a $100000\\times 100000$ tri-diagonal matrix. \nTo store a full matrix of that size in your computer, it would normally require 10\nbillion double-precision floating-point numbers.  Since it takes 8\nbytes to store a double, it would take roughly 80GB to store the\nfull matrix.  For most desktop computers, that fact alone makes the\nsystem numerically prohibitive to solve. \nThe temporal complexity of the problem is even more problematic. \nMethods for directly solving an arbitrary linear system are usually $O(n^3)$.  \nAs a result, even if the computer could store an 80GB matrix in RAM, it\nwould still take several weeks to solve the system.  However, since\nwe don't have computers with that much available RAM, most of the\nmatrix would have to be stored on the hard drive, so the computation\nwould probably take between $6$ months to a year.\n\nThe point is that even the next generation of computers will\nstruggle with solving arbitrary linear systems of this size in a\nreasonable period of time.  However, if we take advantage of the\nsparse structure of the tri-diagonal matrix, we can solve the linear\nsystem, even with a modest modern computer.  This is because all of\nthose zeros don't need to be stored and we don't need to do as many\noperations to row reduce the tri-diagonal system.\n\nLet's first compute the spatial complexity of the above system when\nconsidered as a sparse matrix.  There are three diagonals that have\nroughly $100000$ non-zero entries.  That's $300000$\ndouble-precision floating point numbers, which is about 2.4 MB (Less\nstorage than your favorite song).  As a result, it will easily\nfit into the computer's RAM.  Furthermore, the temporal complexity for solving\na tri-diagonal matrix is $O(n)$. Let's see how long it takes to\nsolve the system for random data:\n\\begin{lstlisting}\n: from scipy.sparse import linalg as sparla\n: D = sp.rand(3, 100000)\n: b = sp.rand(1, 100000)\n: A = spar.spdiags(D,[-1,0,1],100000,100000)\n: def solSys():\n:     return sparla.spsolve(A,b)\n: %timeit solSys()\n\\end{lstlisting}\n\n\\begin{problem}\nWrite a function that returns a full $n\\times n$\ntri-diagonal array with $2$'s along the diagonal and $-1$'s along\nthe two sub-diagonals above and below the diagonal. \nHint: Use the \\li{la.toeplitz()} method.\n\\label{prob:full_tridiag}\n\\end{problem}\n\n\\begin{problem}\nWrite another function that builds the same array as above, but as a sparse array. \nYou must build this as a sparse matrix from the beginning. \nHint: Use the \\li{spar.spdiags()} method.\n\\label{prob:sparse_tridiag}\n\\end{problem}\n\n\\begin{problem}\nSolve the linear system $Ax = b$ where $A$ is the $n\\times n$\ntri-diagonal array from Problem \\ref{prob:full_tridiag} and Problem \\ref{prob:sparse_tridiag} and $b$ is randomly\ngenerated.  How high can you go for each method?  Make a table for\nseveral different values of $n$ and the time it took to solve for\neach run.  What conclusions can you draw?\n\\end{problem}\n\n\\begin{problem}\nUsing the sparse array above and the method \\li{la.eigs()}, \ncalculate the smallest eigenvalue $\\lambda$ of the array as the array's size goes to infinity. \nWhat value does $\\lambda n^2$ approach?  \nHint: It's the square of an important number. \nThis is related to operator theory: the second derivative operator has this eigenvalue in certain cases.\n\\end{problem}\n\n\\section*{Other Sparse Commands}\nOne important method of sparse matrix objects is the \\li{nonzero()} method, \nwhich is related to the number of nonzero entries in the matrix.  \nThis number is important because it is an indicator of the amount of time and space\nthat is required to operate on the sparse matrix. \nYou should be aware that there is some overhead to using and storing the sparse matrix data structure. \nSparsely represented matrices are very beneficial when the number of \nnonzero entries is relatively small compared to the total number of entries. \nWhen the matrix has many nonzero entries, a sparse representation becomes disadvantageous. \nTo see this, create and execute a script with the following code:\n\\begin{lstlisting}\n: A = np.random.rand(600,600); B = spar.csc_matrix(A)\n: def square(A): return sp.power(A, 2)\n: with timer() as t:\n:     t.time(square, A)\n:     t.time(square, B)\n\\end{lstlisting}\nRun the script and note the two different runtimes. \nNotice that it takes much longer to square the sparse matrix.\nThis is because the sparse matrix data structure is optimized for matrices that are actually sparse.\nThe array $A$ is entirely nonzero. \nThus, you incur the overhead of the sparse array representation without any \nbenefits since there are no entries you are not required to store or compute.\nTo summarize, only use a sparse matrix when your matrix is in fact sparse. \nUsing sparse matrices for mostly nonzero arrays will negatively impact performance and memory requirements.\n\nJust as with dense arrays, we can pre-allocate sparse matrices.\nSometimes it is necessary to create sparse matrices that do not have a nice banded pattern. \nWe initialize a sparse matrix just like any other array.  \nThe most efficient sparse matrix for pre-allocation is LIL.  \nOnce you are done constructing you sparse matrix and wish to perform calculations, \nyou should convert to a more efficient sparse matrix (CSR or CSC).\n\\begin{lstlisting}\n: Z = spar.lil_matrix((400,300))\n<400x300 sparse matrix of type '<type 'numpy.float64'>'\n        with 0 stored elements in LInked List format>\n: Z[1,34] = 23\n: Z[23,32] = 56\n: Z[2,:] = 13.2\n\\end{lstlisting}\nThis code snippet creates a $400 \\times 300$ LIL sparse matrix. \nWe can then work with the sparse matrix as though it were a dense array. \nWhen the matrix is initialized all of the entries are assumed to be zero.", "meta": {"hexsha": "386149295e495f60887baf266a4219b73c86b412", "size": 14249, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Matrices_Complexity/Matrices_Complexity.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/Matrices_Complexity/Matrices_Complexity.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/Matrices_Complexity/Matrices_Complexity.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": 48.4659863946, "max_line_length": 340, "alphanum_fraction": 0.7509298898, "num_tokens": 3784, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267118026095992, "lm_q2_score": 0.909906997487259, "lm_q1q2_score": 0.75223085409978}}
{"text": "\\section{Area Between Curves}\\label{sec:AreaBetweenCurves}\r\n\r\n\r\n\r\nWe begin this chapter with a reminder of a few key concepts discussed thus far. Let $f$ be a continuous function on $[a,b]$ which is partitioned into $n$ equally spaced subintervals as $$a<x_1 < x_2 < \\cdots < x_n<x_{n+1}=b.$$ Let $\\dx=(b-a)/n$ denote the length of the  subintervals, and let $c_i$ be any $x$-value in the $i^\\text{ th}$ subinterval. Definition \\ref{def:rie_sum} states that the sum $$\\sum_{i=1}^n f(c_i)\\dx$$ is a \\textit{Riemann Sum.} Riemann Sums are often used to approximate some quantity (area, volume, work, pressure, etc.). The \\textit{approximation} becomes \\textit{exact} by taking the limit \r\n$$\\lim_{n\\to\\infty} \\sum_{i=1}^n f(c_i)\\dx.$$ Theorem \\ref{thm:riemann_sum} connects limits of Riemann Sums to definite integrals:\r\n$$\\lim_{n\\to\\infty} \\sum_{i=1}^n f(c_i)\\dx = \\int_a^b f(x)\\ dx.$$ Finally, the Fundamental Theorem of Calculus states how definite integrals can be evaluated using antiderivatives. \r\n\r\nThis chapter employs the following technique to a variety of applications. Suppose the value $Q$ of a quantity is to be calculated. We first approximate the value of $Q$ using a Riemann Sum, then find the exact value via a definite integral. We spell out this technique in the following Key Idea.\r\n\r\n\r\n\\begin{formulabox}[\\label{idea:app_of_defint} Application of Definite Integrals Strategy ]\r\n{Let a quantity be given whose value $Q$ is to be computed.\\index{integration!general application technique}\r\n\\begin{enumerate}\r\n\\item\t\tDivide the quantity into $n$ smaller ``subquantities'' of value $Q_i$.\r\n\\item\t\tIdentify a variable $x$ and function $f(x)$ such that each subquantity can be approximated with the product $f(c_i)\\dx$, where $\\dx$ represents a small change in $x$. Thus $Q_i \\approx f(c_i)\\dx$. A sample approximation $f(c_i)\\dx$ of $Q_i$ is called a \\textit{differential element}.\r\n\\item\t\tRecognize that $\\ds Q= \\sum_{i=1}^n Q_i \\approx \\sum_{i=1}^n f(c_i)\\dx$, which is a Riemann Sum.\r\n\\item\t\tTaking the appropriate limit gives $\\ds Q = \\int_a^b f(x)\\ dx$\r\n\\end{enumerate}\r\n}\r\n\\end{formulabox}\r\n\r\n\r\nThis Key Idea will make more sense after we have had a chance to use it several times. We begin with Area Between Curves.\r\n%\\end{minipage}\r\n\\clearpage\r\n\r\n\\section*{Area Between Curves}\\label{sec:ABC}\r\n\r\nWe are often interested in knowing the area of a region. Forget momentarily that we discussed this already in Section  \\ref{chapter:integration}.\\ref{sec:FTC} and approach it instead using the technique described in Key Idea \\ref{idea:app_of_defint}. \r\n\r\nLet $Q$ be the area of a region bounded by continuous functions $f$ and $g$. If we break the region into many subregions, we have an obvious equation:\r\n\r\n\\hfill Total Area = sum of the areas of the subregions. \\hfill \\null\r\n\r\nThe issue to address next is how to systematically break a region into subregions. A graph will help. Consider Figure \\ref{fig:abcintro} (a) where a region between two curves is shaded. While there are many ways to break this into subregions, one particularly efficient way is to ``slice'' it vertically, as shown in Figure \\ref{fig:abcintro} (b), into $n$ equally spaced slices. \r\n\r\nWe now approximate the area of a slice. Again, we have many options, but using a rectangle seems simplest. Picking any $x$-value $c_i$ in the $i^\\text{ th}$ slice, we set the height of the rectangle to be $f(c_i)-g(c_i)$, the difference of the corresponding $y$-values. The width of the rectangle is a small difference in $x$-values, which we represent with $\\dx$. Figure \\ref{fig:abcintro} (c) shows sample points $c_i$ chosen in each subinterval and appropriate rectangles drawn. (Each of these rectangles represents a differential element.) Each slice has an area approximately equal to $\\big(f(c_i)-g(c_i)\\big)\\dx$; hence, the total area is approximately the Riemann Sum\r\n$$Q = \\sum_{i=1}^n \\big(f(c_i)-g(c_i)\\big)\\dx.$$\r\nTaking the limit as $n\\to \\infty$ gives the exact area as $\\int_a^b \\big(f(x)-g(x)\\big)\\ dx.$\r\n\r\n\r\n\\begin{figure}\r\n\t\\centering\r\n\t\\begin{subfigure}{0.33\\textwidth}\r\n\t\t\\begin{tikzpicture}\r\n\t\t\\begin{axis}[width=\\textwidth,%\r\n\t\ttick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t\t\t%y=.37\\marginparwidth,\r\n\t\t\t\t\txtick=\\empty,% \r\n\t\t\t\t\textra x ticks={.5,3},\r\n\t\t\t\t\textra x tick labels={$a$,$b$},\r\n\t\t\t\t\tytick=\\empty,\r\n\t\t\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n\t\t%\t\t\tminor x tick num=4,\r\n\t\t\t\t\tymin=-.2,ymax=2,%\r\n\t\t\t\t\txmin=-.5,xmax=3.5%\r\n\t\t]\r\n\t\t\r\n\t\t\\addplot [{\\coloronefill},domain=.5:3,stack plots=y] {.25*(x-2)^2+.2};\r\n\t\t\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=.5:3,stack plots=y] {.25*sin(deg(2*x))+1.25-(.25*(x-2)^2+.2)} \\closedcycle;\r\n\t\t\\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*sin(deg(2*x))+1.25} node [shift={(5pt,7pt)} ,black] {\\scriptsize $f(x)$};\r\n\t\t\\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*(x-2)^2+.2}node [shift={(5pt,7pt)} ,black] {\\scriptsize $g(x)$};\r\n\t\t\r\n\t\t\r\n\t\t\\end{axis}\r\n\t\t\r\n\t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\t\t\\end{tikzpicture}\r\n        \\label{fig:figabcintroa}\r\n        \\caption{} \r\n    \\end{subfigure}% \r\n    \\begin{subfigure}{0.33\\textwidth}\r\n    \\include{figures/figabcintrob.tex}\r\n        \\begin{tikzpicture}\r\n        \\begin{axis}[width=\\textwidth,%\r\n        tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n        \t\t\t%x=.37\\marginparwidth,\r\n        \t\t\t%y=.37\\marginparwidth,\r\n        \t\t\txtick=\\empty,% \r\n        \t\t\textra x ticks={.5,3},\r\n        \t\t\textra x tick labels={$a$,$b$},\r\n        \t\t\tytick=\\empty,\r\n        \t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n        %\t\t\tminor x tick num=4,\r\n        \t\t\tymin=-.2,ymax=2,%\r\n        \t\t\txmin=-.5,xmax=3.5%\r\n        ]\r\n        \r\n        \\addplot [{\\coloronefill},domain=.5:3,stack plots=y] {.25*(x-2)^2+.2};\r\n        \\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=.5:3,stack plots=y] {.25*sin(deg(2*x))+1.25-(.25*(x-2)^2+.2)} \\closedcycle;\r\n        \\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*sin(deg(2*x))+1.25} node [shift={(5pt,7pt)} ,black] {\\scriptsize $f(x)$};\r\n        \\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*(x-2)^2+.2}node [shift={(5pt,7pt)} ,black] {\\scriptsize $g(x)$};\r\n        \r\n        \\draw [thick] (axis cs:0.5,0.7625)--(axis cs:0.5,1.46) (axis cs:1.,0.45)--(axis cs:1.,1.477) (axis cs:1.5,0.2625)--(axis cs:1.5,1.285) (axis cs:2.,0.2)--(axis cs:2.,1.061) (axis cs:2.5,0.2625)--(axis cs:2.5,1.01) (axis cs:3.,1.18)--(axis cs:3.,0.45) (axis cs:0.75,1.499)--(axis cs:0.75,0.5906) (axis cs:1.25,0.3406)--(axis cs:1.25,1.4) (axis cs:1.75,1.162)--(axis cs:1.75,0.2156) (axis cs:2.25,0.2156)--(axis cs:2.25,1.006) (axis cs:2.75,1.074)--(axis cs:2.75,0.3406);\r\n        \r\n        %(0.5,0.7625)(1.,0.45)(1.5,0.2625)(2.,0.2)(2.5,0.2625)(3.,0.45)\r\n        %(0.5,1.46)(1.,1.477)(1.5,1.285)(2.,1.061)(2.5,1.01)(3.,1.18)\r\n        \r\n        %(0.75,0.5906)(1.25,0.3406)(1.75,0.2156)(2.25,0.2156)(2.75,0.3406)\r\n        %(0.75,1.499)(1.25,1.4)(1.75,1.162)(2.25,1.006)(2.75,1.074)\r\n        \\end{axis}\r\n        \r\n        \\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n        \\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n        \\end{tikzpicture}\r\n        \\caption{}    \r\n    \\end{subfigure} \r\n    \r\n    \\begin{subfigure}{0.33\\textwidth}\r\n        \\begin{tikzpicture}\r\n        \\begin{axis}[width=\\textwidth,%\r\n        tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n        \t\t\t%x=.37\\marginparwidth,\r\n        \t\t\t%y=.37\\marginparwidth,\r\n        \t\t\txtick=\\empty,% \r\n        \t\t\textra x ticks={.5,3},\r\n        \t\t\textra x tick labels={$a$,$b$},\r\n        \t\t\tytick=\\empty,\r\n        \t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n        %\t\t\tminor x tick num=4,\r\n        \t\t\tymin=-.2,ymax=2,%\r\n        \t\t\txmin=-.5,xmax=3.5%\r\n        ]\r\n        \r\n        \\addplot [{\\coloronefill},domain=.5:3,stack plots=y] {.25*(x-2)^2+.2};\r\n        \\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=.5:3,stack plots=y] {.25*sin(deg(2*x))+1.25-(.25*(x-2)^2+.2)} \\closedcycle;\r\n        \\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*sin(deg(2*x))+1.25} node [shift={(5pt,7pt)} ,black] {\\scriptsize $f(x)$};\r\n        \\addplot [smooth,thick, {\\colorone},domain=-.25:3.25] {.25*(x-2)^2+.2}node [shift={(5pt,7pt)} ,black] {\\scriptsize $g(x)$};\r\n        \r\n        %\\draw [thick] (axis cs:0.5,0.7625)--(axis cs:0.5,1.46) (axis cs:1.,0.45)--(axis cs:1.,1.477) (axis cs:1.5,0.2625)--(axis cs:1.5,1.285) (axis cs:2.,0.2)--(axis cs:2.,1.061) (axis cs:2.5,0.2625)--(axis cs:2.5,1.01) (axis cs:3.,1.18)--(axis cs:3.,0.45) (axis cs:0.75,1.499)--(axis cs:0.75,0.5906) (axis cs:1.25,0.3406)--(axis cs:1.25,1.4) (axis cs:1.75,1.162)--(axis cs:1.75,0.2156) (axis cs:2.25,0.2156)--(axis cs:2.25,1.006) (axis cs:2.75,1.074)--(axis cs:2.75,0.3406);\r\n        \r\n        \\draw [thick] (axis cs:0.5,0.6225)rectangle(axis cs:0.75,1.5) (axis cs:1.,1.487)rectangle(axis cs:0.75,0.4756) (axis cs:1.,0.4025)rectangle(axis cs:1.25,1.452) (axis cs:1.5,1.334)rectangle(axis cs:1.25,0.29) (axis cs:1.5,0.24)rectangle(axis cs:1.75,1.235) (axis cs:2.,1.097)rectangle(axis cs:1.75,0.2025) (axis cs:2.,0.21)rectangle(axis cs:2.25,1.012) (axis cs:2.5,1.002)rectangle(axis cs:2.25,0.2225) (axis cs:2.5,0.29)rectangle(axis cs:2.75,1.029)(axis cs:3.,1.134)rectangle(axis cs:2.75,0.4025);\r\n        \r\n        \\filldraw (axis cs:.7,.6225) circle (1.3pt)\r\n        (axis cs:0.95,0.4756) circle (1.3pt)\r\n        (axis cs:1.1,0.4025) circle (1.3pt)\r\n        (axis cs:1.4,0.29) circle (1.3pt)\r\n        (axis cs:1.6,0.24) circle (1.3pt)\r\n        (axis cs:1.9,0.2025) circle (1.3pt)\r\n        (axis cs:2.2,0.21) circle (1.3pt)\r\n        (axis cs:2.3,0.2225) circle (1.3pt)\r\n        (axis cs:2.6,0.29) circle (1.3pt)\r\n        (axis cs:2.9,0.4025) circle (1.3pt)\r\n        (axis cs:0.7,1.496) circle (1.3pt)\r\n        (axis cs:0.95,1.487) circle (1.3pt)\r\n        (axis cs:1.1,1.452) circle (1.3pt)\r\n        (axis cs:1.4,1.334) circle (1.3pt)\r\n        (axis cs:1.6,1.235) circle (1.3pt)\r\n        (axis cs:1.9,1.097) circle (1.3pt)\r\n        (axis cs:2.2,1.012) circle (1.3pt)\r\n        (axis cs:2.3,1.002) circle (1.3pt)\r\n        (axis cs:2.6,1.029) circle (1.3pt)\r\n        (axis cs:2.9,1.134) circle (1.3pt);\r\n        \\end{axis}\r\n        \r\n        \\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n        \\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n        \\end{tikzpicture}\r\n            \\label{fig:figabcintroc}\r\n            \\caption{}    \r\n        \\end{subfigure} \r\n    \\caption{Subdividing a region into vertical slices and approximating the areas with rectangles. \\label{fig:abcintro}}\r\n\\end{figure}\r\n\r\n\r\n\r\n\\begin{theorem}{Area Between Curves}{areabetweencurves}\r\n{Let $f(x)$ and $g(x)$ be continuous functions defined on $[a,b]$. The area, $ A $, of the region bounded by the curves $y=f(x)$, $y=g(x)$ and the lines $x=a$ and $x=b$ is \\index{integration!area between curves}\r\n$$A = \\int_a^b \\big|f(x)-g(x)\\big|\\ dx.$$\r\n\r\nIn particular, if $ f(x)\\ge g(x) $ everywhere on the interval $ [a,b] $, then\r\n$$A = \\int_a^b \\big(f(x)-g(x)\\big)\\ dx.$$\r\n}\r\n\\end{theorem}\r\n\r\n\r\n\r\n\\begin{example}{Finding area enclosed by curves}{ex_abc1}{\r\nFind the area of the region bounded by $f(x) = \\sin x+2$, $g(x) = \\frac12\\cos (2x)-1$, $x=0$ and $x=4\\pi$, as shown in Figure \\ref{fig:abc1}.}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{The graph verifies that the upper boundary of the region is given by $f$ and the lower bound is given by $g$. Therefore the area of the region is the value of the integral\r\n\\begin{align*} \r\n\\text{\\mbox{\\green{\\bf Area}}} &= \\int_1^4 \\big|f(x)-g(x)\\big|\\ dx\\\\ \r\n&=\\int_0^{4\\pi} \\big(f(x)- g(x)\\big)\\ dx \r\n& = \\int_0^{4\\pi} \\Big(\\sin x+2 - \\big(\\frac12\\cos (2x)-1\\big)\\Big)\\ dx \\\\\r\n\t\t&= -\\cos x -\\frac14\\sin(2x)+3x\\Big|_0^{4\\pi}\\\\\r\n\t\t&=\t12\\pi \\approx 37.7\\ \\text{units}^2.\r\n\\end{align*}\r\n\r\n\\mfigure{.8}{Graphing an enclosed region in Example \\ref{ex_abc1}.}{fig:abc1}{\\begin{tikzpicture}\r\n\\begin{axis}[,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={12.57},\r\n\t\t\textra x tick labels={$4\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-2,ymax=3.5,%\r\n\t\t\txmin=-.5,xmax=13.5%\r\n]\r\n\r\n\\addplot [{\\coloronefill},domain=0:12.57,stack plots=y,samples=40] {.5*cos(deg(2*x))-1.2};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=0:12.57,stack plots=y,samples=40] {sin(deg(x))+2-(.5*cos(deg(2*x))-1.2)} \\closedcycle;\r\n\\addplot [smooth,thick, {\\colorone},domain=0:12.57,samples=40] {sin(deg(x))+2} node [shift={(-15pt,7pt)} ,black] {\\scriptsize $f(x)$};\r\n\\addplot [smooth,thick, {\\colorone},domain=0:12.57,samples=40] {.5*cos(deg(2*x))-1.2}node [shift={(-25pt,-16pt)} ,black] {\\scriptsize $g(x)$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\r\n}\r\n\\end{solution}\r\n\r\n\r\n\\begin{example}{Finding total area enclosed by curves}{ex_abc2}{\r\nFind the total area of the region enclosed by the functions $f(x) = -2x+5$ and $g(x) = x^3-7x^2+12x-3$ as shown in Figure \\ref{fig:abc2}.}\r\n\\end{example}\r\n\r\n\\begin{solution}\r\n\\begin{center}\r\n\\mfigure{.55}{Graphing a region enclosed by two functions in Example \\ref{ex_abc2}.}{fig:abc2}{\\begin{tikzpicture}\r\n\\begin{axis}[,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,2,3,4},% \r\n%\t\t\textra x ticks={12.57},\r\n%\t\t\textra x tick labels={$4\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-5,ymax=3.5,%\r\n\t\t\txmin=-.5,xmax=4.7%\r\n]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,domain=1:4] {5-2*x};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=1:4,stack plots=y] {x^3-7*x^2+12*x-3-(5-2*x)} \\closedcycle;\r\n\\addplot [smooth,thick, {\\colorone},domain=-.2:4.5,samples=30] {x^3-7*x^2+12*x-3};\r\n\\addplot [smooth,thick, {\\colorone},domain=0:4.5] {5-2*x};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\r\n\\end{center}\r\n\r\nA quick calculation shows that $f=g$ at $x=1, 2$ and $ 4 $. One can proceed thoughtlessly by computing $\\ds \\int_1^4 \\big(f(x)-g(x)\\big)\\ dx$, but this ignores the fact that on $[1,2]$, $g(x)>f(x)$. (In fact, the thoughtless integration returns $-9/4$, hardly the expected value of an \\textit{area}.) Thus we compute the total area by breaking the interval $[1,4]$ into two subintervals, $[1,2]$ and $[2,4]$ and using the proper integrand in each.\r\n\\begin{align*}\r\n\\text{\\mbox{\\green{\\bf Area}}} &= \\int_1^4 \\big|f(x)-g(x)\\big|\\ dx\\\\ \r\n&= \\int_1^2 \\big(g(x)-f(x)\\big)\\ dx + \\int_2^4\\big(f(x)-g(x)\\big)\\ dx\\\\\r\n\t\t\t&= \\int_1^2 \\big(x^3-7x^2+14x-8\\big) \\ dx + \\int_2^4\\big(-x^3+7x^2-14x+8\\big)\\ dx\\\\\r\n\t\t\t&= 5/12 + 8/3 \\\\\r\n\t\t\t&= 37/12 = 3.083\\ \\text{units}^2.\r\n\\end{align*}\t\t\r\n\\end{solution}\r\n\r\n\r\n\r\nThe previous example makes note that we are expecting area to be \\textit{positive}. When first learning about the definite integral, we interpreted it as ``signed area under the curve,'' allowing for ``negative area.'' That doesn't apply here; area is to be positive.\r\n\r\nThe previous example also demonstrates that we often have to break a given region into subregions before applying Theorem \\ref{thm:areabetweencurves}. The following example shows another situation where this is applicable, along with an alternate view of applying the Theorem.\\\\\r\n\r\n\r\n\\begin{example}{Finding area: integrating with respect to $y$}{ex_abc3}\r\n{\r\nFind the area of the region enclosed by the functions $y=\\sqrt{x}+2$, $y=-(x-1)^2+3$ and $y=2$, as shown in Figure \\ref{fig:abc3}.}\r\n\\end{example}\r\n\r\n\r\n\r\n\\begin{solution}\r\n{We give two approaches to this problem. In the first approach, we notice that the region's ``top'' is defined by two different curves. On $[0,1]$, the top function is $y=\\sqrt{x}+2$; on $[1,2]$, the top function is $y=-(x-1)^2+3$. \r\n\r\n\\begin{center}\r\n\\mfigure{.55}{Graphing a region for Example \\ref{exa:ex_abc3}.}{fig:abc3}{\\begin{tikzpicture}\r\n\\begin{axis}[,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,2},% \r\n%\t\t\textra x ticks={12.57},\r\n%\t\t\textra x tick labels={$4\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=3.5,%\r\n\t\t\txmin=-.1,xmax=2.5%\r\n]\r\n\r\n\\addplot [{\\colorone},thick,fill={\\coloronefill}] coordinates {(0,2.)(0.02,2.141)(0.04,2.2)(0.06,2.245)(0.08,2.283)(0.1,2.316)(0.12,2.346)(0.14,2.374)(0.16,2.4)(0.18,2.424)(0.2,2.447)(0.22,2.469)(0.24,2.49)(0.26,2.51)(0.28,2.529)(0.3,2.548)(0.32,2.566)(0.34,2.583)(0.36,2.6)(0.38,2.616)(0.4,2.632)(0.42,2.648)(0.44,2.663)(0.46,2.678)(0.48,2.693)(0.5,2.707)(0.52,2.721)(0.54,2.735)(0.56,2.748)(0.58,2.762)(0.6,2.775)(0.62,2.787)(0.64,2.8)(0.66,2.812)(0.68,2.825)(0.7,2.837)(0.72,2.849)(0.74,2.86)(0.76,2.872)(0.78,2.883)(0.8,2.894)(0.82,2.906)(0.84,2.917)(0.86,2.927)(0.88,2.938)(0.9,2.949)(0.92,2.959)(0.94,2.97)(0.96,2.98)(0.98,2.99)(1.,3.)(1.04,2.998)(1.08,2.994)(1.12,2.986)(1.16,2.974)(1.2,2.96)(1.24,2.942)(1.28,2.922)(1.32,2.898)(1.36,2.87)(1.4,2.84)(1.44,2.806)(1.48,2.77)(1.52,2.73)(1.56,2.686)(1.6,2.64)(1.64,2.59)(1.68,2.538)(1.72,2.482)(1.76,2.422)(1.8,2.36)(1.84,2.294)(1.88,2.226)(1.92,2.154)(1.96,2.078)(2.,2.)(0,2)};\r\n\r\n\\draw (axis cs:.5,3.1) node {\\scriptsize $y=\\sqrt{x}+2$} (axis cs:1.8,3.2) node {\\scriptsize $y=-(x-1)^2+3$};\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\r\n\\end{center}\r\n\r\nThus we compute the area as the sum of two integrals:\r\n\\begin{align*}\r\n\\mbox{\\green{\\bf Area}} &= \\int_0^1 \\Big(\\big(\\sqrt{x}+2\\big)-2\\Big)\\ dx + \\int_1^2 \\Big(\\big(-(x-1)^2+3\\big)-2\\Big)\\ dx \\\\\r\n\t\t\t\t\t\t\t\t\t&= 2/3 + 2/3\\\\\r\n\t\t\t\t\t\t\t\t\t&=4/3.\r\n\\end{align*}\r\n\r\nThe second approach is clever and very useful in certain situations. We are used to viewing curves as functions of $x$; we input an $x$-value and a $y$-value is returned. Some curves can also be described as functions of $y$: input a $y$-value and an $x$-value is returned. We can rewrite the equations describing the boundary by solving for $x$:\r\n\t$$y=\\sqrt{x}+2 \\quad \\Rightarrow\\quad x=(y-2)^2$$\r\n\t$$y=-(x-1)^2+3 \\quad \\Rightarrow \\quad x=\\sqrt{3-y}+1.$$\r\n\r\n\\mfigure{.8}{The region used in Example \\ref{ex_abc3} with boundaries relabeled as functions of $y$.}{fig:abc3b}{\\begin{tikzpicture}\r\n\\begin{axis}[,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,2},% \r\n%\t\t\textra x ticks={12.57},\r\n%\t\t\textra x tick labels={$4\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=3.5,%\r\n\t\t\txmin=-.1,xmax=2.5%\r\n]\r\n\r\n\\addplot [{\\colorone},thick,fill={\\coloronefill}] coordinates {(0,2.)(0.02,2.141)(0.04,2.2)(0.06,2.245)(0.08,2.283)(0.1,2.316)(0.12,2.346)(0.14,2.374)(0.16,2.4)(0.18,2.424)(0.2,2.447)(0.22,2.469)(0.24,2.49)(0.26,2.51)(0.28,2.529)(0.3,2.548)(0.32,2.566)(0.34,2.583)(0.36,2.6)(0.38,2.616)(0.4,2.632)(0.42,2.648)(0.44,2.663)(0.46,2.678)(0.48,2.693)(0.5,2.707)(0.52,2.721)(0.54,2.735)(0.56,2.748)(0.58,2.762)(0.6,2.775)(0.62,2.787)(0.64,2.8)(0.66,2.812)(0.68,2.825)(0.7,2.837)(0.72,2.849)(0.74,2.86)(0.76,2.872)(0.78,2.883)(0.8,2.894)(0.82,2.906)(0.84,2.917)(0.86,2.927)(0.88,2.938)(0.9,2.949)(0.92,2.959)(0.94,2.97)(0.96,2.98)(0.98,2.99)(1.,3.)(1.04,2.998)(1.08,2.994)(1.12,2.986)(1.16,2.974)(1.2,2.96)(1.24,2.942)(1.28,2.922)(1.32,2.898)(1.36,2.87)(1.4,2.84)(1.44,2.806)(1.48,2.77)(1.52,2.73)(1.56,2.686)(1.6,2.64)(1.64,2.59)(1.68,2.538)(1.72,2.482)(1.76,2.422)(1.8,2.36)(1.84,2.294)(1.88,2.226)(1.92,2.154)(1.96,2.078)(2.,2.)(0,2)};\r\n\r\n\\draw (axis cs:.5,3.1) node {\\scriptsize $x=(y-2)^2$} (axis cs:1.8,3.2) node {\\scriptsize $x=\\sqrt{3-y}+1$};\r\n\r\n\\filldraw [{\\colortwo},fill={\\colortwofill},thick] (axis cs: 0.0625,2.2) rectangle (axis cs:1.867,2.3);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\t\r\n\r\nFigure \\ref{fig:abc3b} shows the region with the boundaries relabeled. A differential element, a horizontal rectangle, is also pictured.\tThe width of the rectangle is a small change in $y$: $\\Delta y$. The height of the rectangle is a difference in $x$-values. The ``top'' $x$-value is the largest value, i.e., the rightmost. The ``bottom'' $x$-value is the smaller, i.e., the leftmost. Therefore the height of the rectangle is $$\\big(\\sqrt{3-y}+1\\big) - (y-2)^2.$$\r\n\r\nThe area is found by integrating the above function with respect to $y$ with the appropriate bounds. We determine these by considering the $y$-values the region occupies. It is bounded below by $y=2$, and bounded above by $y=3$. That is, both the ``top'' and ``bottom'' functions exist on the $y$ interval $[2,3]$. Thus\r\n\\begin{align*}\r\n\\mbox{\\green{\\bf Area}} &= \\int_2^3 \\big(\\sqrt{3-y}+1 - (y-2)^2\\big)\\ dy \\\\\r\n\t\t\t&= \\Big(-\\frac23(3-y)^{3/2}+y-\\frac13(y-2)^3\\Big)\\Big|_2^3 \\\\\r\n\t\t\t&= 4/3.\r\n\\end{align*}\r\n\\vskip-\\baselineskip\r\n}\r\n\\end{solution}\r\n\r\n\r\nSometimes the given curves are not given as functions of $x$, but rather functions of $ y $.\r\nIn this instances, it may be more useful to use the \"horizontal rectangle\" approach outlined above.\r\n$$\\includegraphics[width=2.5in]{images2/area-between-formula-2}$$\r\nThe area $A$ of the region bounded by the curves $x=f(y)$ and $x=g(y)$ and the lines $y=c$ and $y=d$ is:\r\n$$A=\\int_c^d\\left|f(y)-g(y)\\right|\\,dy.$$ \r\nInformally this can be thought of as follows:\r\n\r\n\\begin{formulabox}[Area Between Two Curves]\r\n$$Area=\\int_c^d (\\mbox{right curve}) - (\\mbox{left curve})\\,dy,\\qquad c\\leq y\\leq d.$$\r\n\\end{formulabox}\r\n \r\n\\begin{example}{Area Between Two Curves}{Area Between Two Curves}\r\nDetermine the area enclosed by $x=y^2$ and $x=8$.\r\n\\end{example} \r\n\r\n\\begin{solution}\r\nNote that $x=y^2$ and $x=8$ intersect when:  \r\n$$y^2=8\\qquad\\to  \\qquad y=\\pm\\sqrt 8\\qquad\\to \\qquad y=\\pm 2\\sqrt 2$$ \r\nSketching the two curves gives:\r\n\r\n$$\\includegraphics[width=2.5in]{images2/area-between-example-3}$$\r\n\r\n\r\nFrom the sketch $c=-2\\sqrt 2$, $d=2\\sqrt 2$, the right curve is $x=8$ and the left curve is $x=y^2$.\r\n$$\\mbox{\\exfont{Area}}\r\n~=~\\int_c^d[\\mbox{right}-\\mbox{left}]\\,dy\r\n~=~\\int_{-2\\sqrt 2}^{2\\sqrt 2} (8-y^2)\\,dy \r\n~=~\\left.\\left(8y-\\frac{1}{3}y^3\\right)\\right|_{-2\\sqrt 2}^{2\\sqrt 2}$$ \r\n$$= \\left[8(2\\sqrt 2)-\\frac{1}{3}(2\\sqrt 2)^3\\right] - \\left[8(-2\\sqrt 2)-\\frac{1}{3}(-2\\sqrt 2)^3\\right]\r\n~=~\\frac{64\\sqrt 2}{3}$$\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\\begin{example}{Area Between Two Curves}{Area Between Two Curves}\r\nDetermine the area enclosed by $y=x^2$, $y=\\sqrt x$, $x=0$ and $x=2$.\r\n\\end{example} \r\n\r\n\\begin{solution}\r\nThe points of intersection of $y=x^2$ and $y=\\sqrt x$ are\r\n$$x^2=\\sqrt x\\qquad\\to \\qquad x^4=x\\qquad\\to \\qquad x^4-x=0 \\qquad\\to \\qquad x(x^3-1)=0.$$\r\nThus, either $x=0$ or $x=1$.\r\nSketching the curves gives:\r\n\r\n\\begin{tikzpicture} %[scale=.6]\r\n\\begin{axis}[\r\n        xmin=-1,\r\n        xmax=2.5,\r\n        ymin=-1,\r\n        ymax=4.5,\r\n       % y=2cm,\r\n       % x=1cm,\r\n    domain=-0.2:2.1,\r\n    samples=40,\r\n    axis lines=middle,\r\n   % xtick = {0.78539, 1.57079, 2.3561,3.1415, 3.92699,4.7123,5.49778,6.28318,7.06858},\r\n % xticklabels = {$\\frac{\\pi}{4}$,$\\frac{\\pi}{2}$,$\\frac{3\\pi}{4}$,$\\pi $, $\\frac{5\\pi}{4}$, $\\frac{3\\pi}{2}$, $\\frac{7\\pi}{4}$, $2\\pi$,},\r\n %   ytick={-1,1},\r\n]\r\n\\addplot [ thick, red,name path=A] {x^2}; \r\n\\draw[red] (axis cs:1.5,4) node {$y=x^2$};\r\n\\addplot [thick, blue,name path=B,domain=0:2.1] {sqrt(x)};\r\n\\draw[blue] (axis cs:1.6,.8) node {$y=\\sqrt{x}$};\r\n\\draw[blue] (axis cs: .4,.4) node {\\scriptsize $A_1$};\r\n\\draw[blue] (axis cs:1.6,1.8) node {\\scriptsize $A_2$};\r\n% \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [\\coloronefill] fill between[of = A and B,soft clip={domain=0:2}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\r\n\r\n%$$\\includegraphics[width=2.75in]{images2/area-between-example-2}$$\r\nThe area we want to compute is the shaded region. \r\nSince the top curve changes at $x=1$, we need to use the formula twice. \r\nFor $A_1$ we have $a=0$, $b=1$, the top curve is $y=\\sqrt x$ and the bottom curve is $y=x^2$. \r\nFor $A_2$ we have $a=1$, $b=2$, the top curve is $y=x^2$ and the bottom curve is $y=\\sqrt x$. \r\n$$\\mbox{\\green{\\bf Area}}\r\n~=~\\mbox{\\green{\\bf A$_1$}}+\\mbox{\\green{\\bf A$_2$}}  \r\n~=~\\int_0^1(\\sqrt x-x^2)\\,dx+\\int_1^2(x^2-\\sqrt x)\\,dx$$\r\nFor the first integral we have:\r\n$$\\int_0^1(\\sqrt x-x^2)\\,dx  \r\n~=~\\left.\\left(\\frac{2}{3}x^{3/2}-\\frac{1}{3}x^3\\right)\\right|_0^1  \r\n~=~\\frac{1}{3}$$\r\nThus,\r\n$$\\mbox{\\green{\\bf Area}}~=~\\frac{1}{3}+\\left.\\left(\\frac{1}{3}x^3-\\frac{2}{3}x^{3/2}\\right)\\right|_1^2 \r\n~=~\\frac{1}{3}+\\left[\\left(\\frac{8}{3}-\\frac{2(\\sqrt 2)^3}{3}\\right)-\\left(\\frac{1}{3}-\\frac{2}{3}\\right)\\right] \r\n~=~\\frac{10-4\\sqrt 2}{3}$$\r\n\\end{solution}\r\n\r\n\\begin{example}{Area Between Sine and Cosine}{Area Between Sine and Cosine}\r\nDetermine the area enclosed by $y=\\sin x$ and $y=\\cos x$ on the interval $[0,~2\\pi]$.\r\n\\end{example}\r\n\r\n\\begin{solution}\r\nThe curves $y=\\sin x$ and $y=\\cos x$ intersect when:  \r\n$$\\sin x=\\cos x\\qquad\\to  \\qquad \\tan x = 1\\qquad\\to  \\qquad x=\\frac{\\pi}{4}+\\pi k,~\\mbox{$k$ an integer.}$$\r\nWe have the following sketch:\r\n\r\n\r\n\r\n\r\n\\begin{tikzpicture} %[scale=.6]\r\n\\begin{axis}[\r\n        xmin=-1.5,\r\n        xmax=8,\r\n        ymin=-1.5,\r\n        ymax=1.5,\r\n        y=3cm/2,\r\n        x=1.7cm,\r\n    domain=0:5*pi/2,\r\n    samples=100,\r\n    axis lines=middle,\r\n    xtick = {0.78539, 1.57079, 2.3561,3.1415, 3.92699,4.7123,5.49778,6.28318,7.06858\r\n    },\r\n  xticklabels = {$\\frac{\\pi}{4}$,$\\frac{\\pi}{2}$,$\\frac{3\\pi}{4}$,$\\pi $, $\\frac{5\\pi}{4}$, $\\frac{3\\pi}{2}$, $\\frac{7\\pi}{4}$, $2\\pi$,},\r\n    ytick={-1,1},\r\n]\r\n\\addplot [samples=501,mark=none, thick, red,name path=A,domain=-2*pi:3*pi] {cos(deg(x))}; \\draw[red] (axis cs:-1,1) node {$\\cos(x)$};\r\n\\addplot [samples=501,mark=none, thick, blue,name path=B,domain=-2*pi:3*pi] {sin(deg(x))};\r\n\\draw[blue] (axis cs:-1,-.4) node {$\\sin(x)$};\r\n% \\addplot [draw=none,name path=B] {0};     % “fictional” curve\r\n  \\addplot [\\coloronefill] fill between[of = A and B,soft clip={domain=0:2*pi}]; % filling\r\n\\end{axis}\r\n\\end{tikzpicture}\r\n\r\n\r\n%$$\\includegraphics[width=5.5in]{images2/area-between-example-4}$$\r\nThe area we want to compute is the shaded region.\r\nThe top curve changes at $x=\\pi/4$ and $x=5\\pi/4$, thus, we need to split the area up into three regions:\r\nfrom $0$ to $\\pi/4$; from $\\pi/4$ to $5\\pi/4$; and from $5\\pi/4$ to $2\\pi$. \r\n\\begin{eqnarray*}\r\n\\mbox{\\green{\\bf Area}} & = & \\int_0^{\\frac{\\pi}{4}}(\\cos x-\\sin x)\\,dx  + \\int_{\\frac{\\pi}{4}}^{\\frac{5\\pi}{4}}(\\sin x-\\cos x)\\,dx  + \\int_{\\frac{5\\pi}{4}}^{2\\pi}(\\cos x-\\sin x)\\,dx\\\\  \r\n\t\t\t & = & \\left(\\sin x + \\cos x\\right)\\bigg|_0^{\\pi/4}+ \\left(-\\cos x - \\sin x\\right)\\bigg|_{\\pi/4}^{5\\pi/4} +  \\left(\\sin x + \\cos x\\right)\\bigg|_{5\\pi/4}^{2\\pi}\\\\ \r\n\t\t\t& = & \\left(\\sqrt 2-1\\right) + \\left(\\sqrt 2+\\sqrt 2\\right) + \\left(1+\\sqrt 2\\right)\\\\ \r\n\t\t\t& = & 4\\sqrt 2\r\n\\end{eqnarray*}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\n\r\n%\r\nThis calculus--based technique of finding area can be useful even with shapes that we normally think of as ``easy.'' Example \\ref{ex_abc4} computes the area of a triangle. While the formula ``$\\frac12\\times\\text{base}\\times\\text{height}$'' is well known, in arbitrary triangles it can be nontrivial to compute the height. Calculus makes the problem simple.\\\\\r\n\r\n\\begin{example}{Finding the area of a triangle}{ex_abc4}\r\n{\r\nCompute the area of the regions bounded by the lines  $y=x+1$, $y=-2x+7$ and $y=-\\frac12x+\\frac52$, as shown in Figure \\ref{fig:abc4}.}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{Recognize that there are two ``top'' functions to this region, causing us to use two definite integrals.\r\n\\begin{align*}\r\n\\text{Total Area} &= \\int_1^2\\big((x+1)-(-\\frac12x+\\frac52)\\big)\\ dx + \\int_2^3\\big((-2x+7)-(-\\frac12x+\\frac52)\\big)\\ dx \\\\\r\n\t\t\t\t\t\t&= 3/4+3/4\\\\\r\n\t\t\t\t\t\t&=3/2.\r\n\\end{align*}\r\n\r\n\\mfigure{.8}{Graphing a triangular region in Example \\ref{ex_abc4}.}{fig:abc4}{\\begin{tikzpicture}\r\n\\begin{axis}[ %width=\\marginparwidth+25pt,%\r\ntick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={1,2,3},% \r\n%\t\t\textra x ticks={12.57},\r\n%\t\t\textra x tick labels={$4\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=3.5,%\r\n\t\t\txmin=-.1,xmax=3.9%\r\n]\r\n\r\n\\addplot [{\\colorone},thick,fill={\\coloronefill}] coordinates {(1,2) (2,3) (3,1) (1,2)};\r\n\r\n\\draw (axis cs:.9,2.5) node {\\scriptsize $y=x+1$} (axis cs:3,2.5) node {\\scriptsize $y=-2x+7$} (axis cs:1.5,1.1) node {\\scriptsize $y=-\\frac12x+\\frac52$};\r\n%\r\n%\\filldraw [{\\colortwo},fill={\\colortwofill},thick] (axis cs: 0.0625,2.2) rectangle (axis cs:1.867,2.3);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}}\r\n\r\nWe can also approach this by converting each function into a function of $y$. This also requires $ 2 $ integrals, so there isn't really any advantage to doing so. We do it here for demonstration purposes.\r\n\r\nThe ``top'' function is always $x=\\frac{7-y}2$ while there are two ``bottom'' functions. Being mindful of the proper integration bounds, we have\r\n\\begin{align*}\r\n\\text{Total Area} &= \\int_1^2\\big(\\frac{7-y}2 - (5-2y)\\big)\\ dy + \\int_2^3\\big(\\frac{7-y}2-(y-1)\\big)\\ dy \\\\\r\n\t\t\t&= 3/4 + 3/4\\\\\r\n\t\t\t&= 3/2.\r\n\\end{align*}\r\nOf course, the final answer is the same. (It is interesting to note that the area of all 4 subregions used is 3/4. This is coincidental.)\r\n}\r\n\\end{solution}\r\n\r\n\r\n%\r\nWhile we have focused on producing exact answers, we are also able to make approximations using the principle of Theorem \\ref{thm:areabetweencurves}. The integrand in the theorem is a distance (``top minus bottom''); integrating this distance function gives an area. By taking discrete measurements of distance, we can approximate an area using numerical integration techniques developed in Section \\ref{sec:numerical_integration}. The following example demonstrates this.\\\\\r\n\r\n\\begin{example}{Numerically approximating area}{ex_abc5}{\r\nTo approximate the area of a lake, shown in Figure \\ref{fig:abc5} (a),  the ``length'' of the lake is measured at $ 200 $-meter increments as shown in Figure \\ref{fig:abc5} (b), where the lengths are given in hundreds of meters. Approximate the area of the lake.}\r\n\\end{example}\r\n\r\n\r\n\\begin{solution}\r\n{The measurements of length can be viewed as measuring ``top minus bottom'' of two functions. The exact answer is found by integrating $\\ds \\int_0^{12} \\big(f(x)-g(x)\\big)\\ dx$, but of course we don't know the functions $f$ and $g$. Our discrete measurements instead allow us to approximate.\r\n\r\n\r\n\\begin{figure}[H]\r\n\t\\centering\r\n\t\\begin{subfigure}[t]{0.5\\textwidth}\r\n             {\\begin{tikzpicture}\r\n                 \t\t\\begin{axis}[ %width=\\marginparwidth+25pt,%\r\n                 \t\ttick label style={font=\\scriptsize},axis lines=none,name=myplot,%\r\n                 \t\t\t\t\t%x=.37\\marginparwidth,\r\n                 \t\t\t\t\t%y=.37\\marginparwidth,\r\n                 \t\t%\t\t\txtick={1,2,3,4,5,6,7,8,9,10,11,12},% \r\n                 \t\t%\t\t\textra x ticks={12.57},\r\n                 \t\t%\t\t\textra x tick labels={$4\\pi$},\r\n                 \t\t%\t\t\tytick={1,2,3,4,5,6,7,8},\r\n                 \t\t\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n                 \t\t%\t\t\tminor x tick num=4,\r\n                 \t\t\t\t\tymin=-.1,ymax=8.5,%\r\n                 \t\t\t\t\txmin=-.1,xmax=12.5%\r\n                 \t\t]\r\n                 \t\t\r\n                 \t\t\\addplot [{\\colorone},thick,fill={\\coloronefill},smooth] coordinates {(0,3.2)(0.5,3.417)(1.,3.637)(1.5,4.041)(2.,4.505)(2.5,5.)(3.,5.495)(3.5,5.959)(4.,6.363)(4.5,6.683)(5.,6.898)(5.5,6.995)(6.,6.968)(6.5,6.819)(7.,6.556)(7.5,6.197)(8.,5.763)(8.5,5.282)(9.,4.784)(9.5,4.298)(10.,3.857)(10.5,3.486)(11.,3.21)(11.5,2.8)(11.5,2)(11.,1.545)(10.5,1.314)(10.,1.102)(9.5,0.9154)(9.,0.7585)(8.5,0.6361)(8.,0.5514)(7.5,0.5069)(7.,0.5038)(6.5,0.5421)(6.,0.6208)(5.5,0.7378)(5.,0.8897)(4.5,1.072)(4.,1.281)(3.5,1.509)(3.,1.751)(2.5,2.)(2.,2.249)(1.5,2.491)(1.,2.719)(0.5,2.9102)(0,3.15)(0,3.2)};\r\n                 \t\t%(0.5,3.317)\r\n%                 \t\t\\draw (axis cs:2,4.5) -- (axis cs:2,2.249) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 2.25}\r\n%                 \t\t(axis cs:4,6.36) -- (axis cs:4,1.28) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 5.08}\r\n%                 \t\t(axis cs:6,6.97) -- (axis cs:6,0.62) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 6.35}\r\n%                 \t\t(axis cs:8,5.76) -- (axis cs:8,.55) node  [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 5.21}\r\n%                 \t\t(axis cs:10,3.86) -- (axis cs:10,1.1) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 2.76};\r\n                 \t\t\\end{axis}\r\n                 \t\t\r\n%                 \t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n%                 \t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n                 \t\t\\end{tikzpicture}}\t\r\n        \\label{fig:abc5a}\r\n        \\caption{A sketch of a lake.} \r\n    \\end{subfigure}% \r\n    \\begin{subfigure}[t]{0.5\\textwidth}\r\n    {\\begin{tikzpicture}\r\n    \t\t\\begin{axis}[ %width=\\marginparwidth+25pt,%\r\n    \t\ttick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n    \t\t\t\t\t%x=.37\\marginparwidth,\r\n    \t\t\t\t\t%y=.37\\marginparwidth,\r\n    \t\t\t\t\txtick={1,2,3,4,5,6,7,8,9,10,11,12},% \r\n    \t\t%\t\t\textra x ticks={12.57},\r\n    \t\t%\t\t\textra x tick labels={$4\\pi$},\r\n    \t\t\t\t\tytick={1,2,3,4,5,6,7,8},\r\n    \t\t\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n    \t\t%\t\t\tminor x tick num=4,\r\n    \t\t\t\t\tymin=-.1,ymax=8.5,%\r\n    \t\t\t\t\txmin=-.1,xmax=12.5%\r\n    \t\t]\r\n    \t\t\r\n    \t\t\\addplot [{\\colorone},thick,fill={\\coloronefill},smooth] coordinates {(0,3.2)(0.5,3.417)(1.,3.637)(1.5,4.041)(2.,4.505)(2.5,5.)(3.,5.495)(3.5,5.959)(4.,6.363)(4.5,6.683)(5.,6.898)(5.5,6.995)(6.,6.968)(6.5,6.819)(7.,6.556)(7.5,6.197)(8.,5.763)(8.5,5.282)(9.,4.784)(9.5,4.298)(10.,3.857)(10.5,3.486)(11.,3.21)(11.5,2.8)(11.5,2)(11.,1.545)(10.5,1.314)(10.,1.102)(9.5,0.9154)(9.,0.7585)(8.5,0.6361)(8.,0.5514)(7.5,0.5069)(7.,0.5038)(6.5,0.5421)(6.,0.6208)(5.5,0.7378)(5.,0.8897)(4.5,1.072)(4.,1.281)(3.5,1.509)(3.,1.751)(2.5,2.)(2.,2.249)(1.5,2.491)(1.,2.719)(0.5,2.9102)(0,3.15)(0,3.2)};\r\n    \t\t%(0.5,3.317)\r\n    \t\t\\draw (axis cs:2,4.5) -- (axis cs:2,2.249) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 2.25}\r\n    \t\t(axis cs:4,6.36) -- (axis cs:4,1.28) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 5.08}\r\n    \t\t(axis cs:6,6.97) -- (axis cs:6,0.62) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 6.35}\r\n    \t\t(axis cs:8,5.76) -- (axis cs:8,.55) node  [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 5.21}\r\n    \t\t(axis cs:10,3.86) -- (axis cs:10,1.1) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 2.76};\r\n    \t\t\r\n    \t\t\r\n    \t\t\\end{axis}\r\n    \t\t\r\n    \t\t\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n    \t\t\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n    \t\t\\end{tikzpicture}}\r\n\r\n        \\label{fig:abc5b}\r\n        \\caption{The lake with length measurements.}    \r\n    \\end{subfigure} \r\n    \\caption{\\label{fig:abc5}}\r\n\\end{figure}\r\n\r\n\r\n\r\nWe have the following data points:\r\n$$(0,0),\\ (2,2.25),\\ (4,5.08),\\ (6,6.35),\\ (8,5.21),\\ (10,2.76),\\ (12,0).$$\r\nWe also have that $\\dx=\\frac{b-a}{n} = 2$, so Simpson's Rule gives\r\n\\begin{align*}\r\n\\text{Area}&\\approx \\frac{2}{3}\\Big(1\\cdot0+4\\cdot2.25+2\\cdot5.08+4\\cdot6.35+2\\cdot5.21+4\\cdot2.76+1\\cdot0\\Big)\\\\\r\n\t\t\t&= 44.01\\overline{3} \\ \\text{100m.}^2.\r\n\\end{align*}\r\n\r\nSince the measurements are in hundreds of meters, units$^2 = (100\\ \\text{m})^2 = 10,000\\ \\text{m}^2$, giving a total area of $440,133\\ \\text{m}^2$. (Since we are approximating, we'd likely say the area was about $440,000\\ \\text{m}^2$, which is   $ 44 $ hectares.)\r\n}\r\n\\end{solution}\r\n\r\n\r\n\r\n\r\nIn the next section we apply our applications--of--integration techniques to finding the volumes of certain solids.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n%% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %\r\n%\r\n%We have seen how integration can be used to find an area between a\r\n%curve and the $x$-axis. With very little change we can find some areas\r\n%between curves; indeed, the area between a curve and the $x$-axis may\r\n%be interpreted as the area between the curve and a second ``curve''\r\n%with equation $y=0$. \r\n%%In the simplest of cases, the idea is quite easy to understand.\r\n%\r\n%%\\begin{example}{Area between Curves} {AreaBetweenCurves} \r\n%%Find the area below $\\ds f(x)= -x^2+4x+3$ and above\r\n%%$\\ds g(x)=-x^3+7x^2-10x+5$ over the interval $1\\le x\\le2$. \r\n%%\\end{example}\r\n%%\r\n%%\\begin{solution} \r\n%%In the figure below we show the two curves together, with\r\n%%the desired area shaded, then $f$ alone with the area under $f$\r\n%%shaded, and then $g$ alone with the area under $g$ shaded. \r\n%%\r\n%%\\[\r\n%%\\includegraphics[width=5in]{images/area-between1} \r\n%%\\]\r\n%%%\\figure[!ht]\r\n%%%\\hbox to \\hsize{\\hfill\r\n%%%\\def\\yarrow{-- +(-1.5pt,-3pt) +(0pt,0pt) -- +(1.5pt,-3pt) +(0pt,0pt)}\r\n%%%\\def\\xarrow{-- +(-3pt,-1.5pt) +(0pt,0pt) -- +(-3pt,1.5pt) +(0pt,0pt) }\r\n%%%\\tikzpicture[domain=0:3,y=3mm]\r\n%%%\\draw[->] (0,0) -- (3.2,0) \\xarrow node [right] {$x$};\r\n%%%\\draw[->] (0,0) -- (0,11.2) \\yarrow node [above] {$y$};\r\n%%%\\gpad\r\n%%%\\draw[color=black] plot[id=\\the\\gpnum,domain=0:3] function{-x**3+7*x**2-10*x+5};\r\n%%%\\gpad\r\n%%%\\draw[color=black] plot[id=\\the\\gpnum,domain=0:3] function{-x**2+4*x+3};\r\n%%%\\draw[dashed] (1,0) -- (1,6);\r\n%%%\\draw[dashed] (2,0) -- (2,7);\r\n%%%\\foreach \\x in {0,1,2,3} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\r\n%%%\\foreach \\y in {0,5,10} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east]\r\n%%%         {$\\y$};\r\n%%%\\gpad\r\n%%%\\fill[opacity=0.5,fill=red!20] plot[id=\\the\\gpnum,domain=1:2]\r\n%%%function{-x**3+7*x**2-10*x+5} -- (2,7) node {\\gpad}\r\n%%%plot[parametric,id=\\the\\gpnum,domain=0:1] function{2-t,-t**2+7} -- (1,1);\r\n%%%\\endtikzpicture\r\n%%% \r\n%%%\\tikzpicture[domain=0:3,y=3mm]\r\n%%%\\draw[->] (0,0) -- (3.2,0) \\xarrow node [right] {$x$};\r\n%%%\\draw[->] (0,0) -- (0,11.2) \\yarrow node [above] {$y$};\r\n%%%\\gpad\r\n%%%\\draw[color=black] plot[id=\\the\\gpnum,domain=0:3] function{-x**2+4*x+3};\r\n%%%\\draw[dashed] (1,0) -- (1,6);\r\n%%%\\draw[dashed] (2,0) -- (2,7);\r\n%%%\\foreach \\x in {0,1,2,3} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\r\n%%%\\foreach \\y in {0,5,10} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east] {$\\y$};\r\n%%%\\gpad\\fill[opacity=0.5,fill=red!20] (2,0) -- (2,7)\r\n%%%plot[parametric,id=\\the\\gpnum,domain=0:1] function{2-t,-t**2+7} -- (1,0) -- (2,0);\r\n%%%\\endtikzpicture\r\n%%%\r\n%%%\\tikzpicture[domain=0:3,y=3mm]\r\n%%%\\draw[angle 90] (0,0) -- (3.2,0) \\xarrow node [right] {$x$};\r\n%%%\\draw[->] (0,0) -- (0,11.2) \\yarrow node [above] {$y$};\r\n%%%\\gpad\\draw[color=black] plot[id=\\the\\gpnum,domain=0:3] function{-x**3+7*x**2-10*x+5};\r\n%%%\\draw[dashed] (1,0) -- (1,1);\r\n%%%\\draw[dashed] (2,0) -- (2,5);\r\n%%%\\foreach \\x in {0,1,2,3} \\draw (\\x,0) -- (\\x,-2pt) node[anchor=north] {$\\x$};\r\n%%%\\foreach \\y in {0,5,10} \\draw (0,\\y) -- (-2pt,\\y) node[anchor=east]\r\n%%%         {$\\y$};\r\n%%%\\gpad\r\n%%%\\fill[opacity=0.5,fill=red!20] (1,0) -- (1,1) plot[id=\\the\\gpnum,domain=1:2]\r\n%%%function{-x**3+7*x**2-10*x+5} -- (2,0) -- (1,0);\r\n%%%\\endtikzpicture\r\n%%%\\hfill}\r\n%%%\\label{fig:area between curves1}\r\n%%%\\caption{Area between curves as a difference of areas.}\r\n%%%\\endfigure\r\n%%\r\n%%It is clear\r\n%%from the figure that the area we want is the area under $f$ minus the\r\n%%area under $g$, which is to say\r\n%%$$\\int_1^2 f(x)\\,dx-\\int_1^2 g(x)\\,dx = \\int_1^2 f(x)-g(x)\\,dx.$$\r\n%%It doesn't matter whether we compute the two integrals on the left and\r\n%%then subtract or compute the single integral on the right. In this\r\n%%case, the latter is perhaps a bit easier:\r\n%%\\begin{eqnarray*}\r\n%  %\\int_1^2 f(x)-g(x)\\,dx&=&\\int_1^2 -x^2+4x+3-(-x^3+7x^2-10x+5)\\,dx\\cr\r\n%%\\\\\r\n%  %&=&\\int_1^2 x^3-8x^2+14x-2\\,dx\\cr\r\n%%\\\\\r\n%  %&=&\\left.{x^4\\over4}-{8x^3\\over3}+7x^2-2x\\right|_1^2\\cr\r\n%%\\\\\r\n%  %&=&{16\\over4}-{64\\over3}+28-4-({1\\over4}-{8\\over3}+7-2)\\cr\r\n%%\\\\\r\n%  %&=&23-{56\\over3}-{1\\over4}\\cr\r\n%%\\\\\r\n%  %&=&{49\\over12}.\\cr\r\n%%\\end{eqnarray*}\r\n%%\\end{solution}\r\n%%\r\n%%It is worth examining this problem a bit more. We have seen one way to\r\n%%look at it, by viewing the desired area as a big area minus a small\r\n%%area, which leads naturally to the difference between two\r\n%%integrals. But it is instructive to consider how we might find the\r\n%%desired area directly. \r\n%\r\n%Suppose we would like to find the area below $\\ds f(x)= -x^2+4x+3$ and above\r\n%$\\ds g(x)=-x^3+7x^2-10x+5$ over the interval $1\\le x\\le2$. \r\n%We can approximate the area between two curves by dividing the\r\n%area into thin sections and approximating the area of each section by\r\n%a rectangle, as indicated in \r\n%figure~\\ref{fig:rectangles between curves}. \r\n%The area of a typical rectangle is \r\n%$\\Delta x(f(x_i)-g(x_i))$, so the total area is approximately\r\n%$$\\sum_{i=0}^{n-1} (f(x_i)-g(x_i))\\Delta x.$$\r\n%This is exactly the sort of sum that turns into an integral in the\r\n%limit, namely the integral\r\n%$$\\int_1^2 f(x)-g(x)\\,dx.$$\r\n%Then\r\n%$$\\int_1^2 f(x)-g(x)\\,dx=\\int_1^2 (-x^2+4x+3)-(-x^3+7x^2-10x+5)\\,dx={49\\over12}.$$\r\n%\r\n%%Of course, this is the integral we actually computed above, but we\r\n%%have now arrived at it directly rather than as a modification of the\r\n%%difference between two other integrals. In that example it really\r\n%%doesn't matter which approach we take, but in some cases this second\r\n%%approach is better.\r\n%\r\n%\\figure[H]\r\n%\\centerline{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <3truecm,0.4truecm>\r\n%\\setplotarea x from 0 to 3, y from 0 to 10\r\n%\\axis left ticks numbered from 0 to 10 by 5 /\r\n%\\axis bottom  ticks numbered from 0 to 3 by 1 /\r\n%\\setquadratic\r\n%%\\putrule from 1.52 2.707 to 1.52 6.819\r\n%%\\putrule from 1.63 2.707 to 1.63 6.819\r\n%%\\putrule from 1.52 2.707 to 1.63 2.707\r\n%%\\putrule from 1.52 6.819 to 1.63 6.819\r\n%\\putrule from 1.465 2.229 to 1.465 6.714\r\n%\\putrule from 1.575 2.229 to 1.575 6.714\r\n%\\putrule from 1.575 2.229 to 1.465 2.229\r\n%\\putrule from 1.575 6.714 to 1.465 6.714\r\n%%\r\n%\\putrule from 1.575 2.707 to 1.575 6.819\r\n%\\putrule from 1.685 2.707 to 1.685 6.819\r\n%\\putrule from 1.575 2.707 to 1.685 2.707\r\n%\\putrule from 1.575 6.819 to 1.685 6.819\r\n%\\plot\r\n%0.000 3.000 0.075 3.294 0.150 3.578 0.225 3.849 0.300 4.110 \r\n%0.375 4.359 0.450 4.598 0.525 4.824 0.600 5.040 0.675 5.244 \r\n%0.750 5.438 0.825 5.619 0.900 5.790 0.975 5.949 1.050 6.098 \r\n%1.125 6.234 1.200 6.360 1.275 6.474 1.350 6.578 1.425 6.669 \r\n%1.500 6.750 1.575 6.819 1.650 6.878 1.725 6.924 1.800 6.960 \r\n%1.875 6.984 1.950 6.998 2.025 6.999 2.100 6.990 2.175 6.969 \r\n%2.250 6.938 2.325 6.894 2.400 6.840 2.475 6.774 2.550 6.698 \r\n%2.625 6.609 2.700 6.510 2.775 6.399 2.850 6.278 2.925 6.144 \r\n%3.000 6.000 /\r\n%\\plot\r\n%0.000 5.000 0.075 4.289 0.150 3.654 0.225 3.093 0.300 2.603 \r\n%0.375 2.182 0.450 1.826 0.525 1.535 0.600 1.304 0.675 1.132 \r\n%0.750 1.016 0.825 0.953 0.900 0.941 0.975 0.978 1.050 1.060 \r\n%1.125 1.186 1.200 1.352 1.275 1.557 1.350 1.797 1.425 2.071 \r\n%1.500 2.375 1.575 2.707 1.650 3.065 1.725 3.446 1.800 3.848 \r\n%1.875 4.268 1.950 4.703 2.025 5.151 2.100 5.609 2.175 6.075 \r\n%2.250 6.547 2.325 7.021 2.400 7.496 2.475 7.968 2.550 8.436 \r\n%2.625 8.896 2.700 9.347 2.775 9.785 2.850 10.208 2.925 10.614 \r\n%3.000 11.000 /\r\n%\\setdashes\r\n%\\putrule from 1 0 to 1 6\r\n%\\putrule from 2 0 to 2 7\r\n%\\setsolid\r\n%\\endpicture}}\r\n%\\caption{Approximating area between curves with rectangles. \\label{fig:rectangles between curves}}\r\n%\\endfigure\r\n%\r\n%This procedure can informally be thought of as follows.\r\n%\r\n%\\begin{formulabox}[Area Between Two Curves]\r\n%$$Area=\\int_a^b (\\mbox{top curve}) - (\\mbox{bottom curve})\\,dx,\\qquad a\\leq x\\leq b.$$\r\n%\\end{formulabox}\r\n%\r\n%$$\\includegraphics[width=2.5in]{images2/area-between-formula}$$\r\n%\r\n%More formally, the area $A$ of the region bounded by the curves $y=f(x)$ and $y=g(x)$ and the lines $x=a$ and $x=b$ is:\r\n%$$A=\\int_a^b\\left|f(x)-g(x)\\right|\\,dx.$$\r\n%\r\n%\\begin{example}{Area between Curves} {AreaBetweenCurves4} \r\n%Find the area between $\\ds f(x)= -x^2+4x$ and\r\n%$\\ds g(x)=x^2-6x+5$; the\r\n% curves are shown in figure~\\xrefn{fig:area bounded by curves}. \r\n%\\end{example}\r\n%\r\n%\\begin{solution} \r\n%Here we\r\n%are not given a specific interval, so it must be the case that there\r\n%is a ``natural'' region involved. Since the curves are both parabolas,\r\n%the only reasonable interpretation is the region between the two\r\n%intersection points, which can be computed as:\r\n%$${5\\pm\\sqrt{15}\\over2}.$$\r\n%If we let $\\ds a=(5-\\sqrt{15})/2$ and $\\ds b=(5+\\sqrt{15})/2$,\r\n%the total area is \r\n%\\begin{eqnarray*}\r\n%  \\int_a^b -x^2+4x-(x^2-6x+5)\\,dx\r\n%  &=&\\int_a^b -2x^2+10x-5\\,dx\\cr\r\n%  &=&\\left.-{2x^3\\over3}+5x^2-5x\\right|_a^b\\cr\r\n%  &=&5\\sqrt{15}.\\cr\r\n%\\end{eqnarray*}\r\n%after a bit of simplification.\r\n%\\end{solution}\r\n%\r\n%\\figure[H]\r\n%\\centerline{\\vbox{\\beginpicture\r\n%\\normalgraphs\r\n%%\\ninepoint\r\n%\\setcoordinatesystem units <1.7truecm,0.4truecm>\r\n%\\setplotarea x from 0 to 5, y from -5 to 5\r\n%\\axis left ticks numbered from -5 to 5 by 5 /\r\n%\\axis bottom shiftedto y=0 ticks numbered from 1 to 5 by 1 /\r\n%\\setquadratic\r\n%\\plot\r\n%0.000 0.000 0.250 0.938 0.500 1.750 0.750 2.438 1.000 3.000 \r\n%1.250 3.438 1.500 3.750 1.750 3.938 2.000 4.000 2.250 3.938 \r\n%2.500 3.750 2.750 3.438 3.000 3.000 3.250 2.438 3.500 1.750 \r\n%3.750 0.938 4.000 0.000 4.250 -1.062 4.500 -2.250 4.750 -3.562 \r\n%5.000 -5.000 /\r\n%\\plot\r\n%0.000 5.000 0.250 3.562 0.500 2.250 0.750 1.062 1.000 0.000 \r\n%1.250 -0.938 1.500 -1.750 1.750 -2.438 2.000 -3.000 2.250 -3.438 \r\n%2.500 -3.750 2.750 -3.938 3.000 -4.000 3.250 -3.938 3.500 -3.750 \r\n%3.750 -3.438 4.000 -3.000 4.250 -2.438 4.500 -1.750 4.750 -0.938 \r\n%5.000 0.000 /\r\n%\\endpicture}}\r\n%\\caption{Area bounded by two curves. \\label{fig:area bounded by curves}}\r\n%\\endfigure\r\n%\r\n%Some general guidelines to compute the area between two curves follows.\r\n%\r\n%\\begin{formulabox}[Guidelines for Area Between Two Curves]\r\n%\\begin{enumerate}\r\n%\t\\item Find the intersection points.  \r\n%\t\\item Draw a sketch of the two curves.  \r\n%\t\\item Using the sketch determine which curve is the top curve and which curve is the bottom curve. You may need to split the area up into multiple regions if the curves intersect multiple times in $[a,b]$.\r\n%\t\\item Put the above information into the appropriate formula (once for each region): \r\n%\t\t$$\\ffont{Area}=\\int_a^b (\\mbox{top curve}) - (\\mbox{bottom curve})\\,dx,\\qquad a\\leq x\\leq b.$$\r\n%\t\\item Evaluate the integral using the Fundamental Theorem of Calculus (you should get a positive number representing an area).\r\n%\\end{enumerate}\r\n%\\end{formulabox}\r\n%\r\n\r\n\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:AreaBetweenCurves}}\r\n\r\n\\begin{multicols}{2}[]\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n% % % % % % % % % % % % % %\r\n\r\n\\begin{ex}\r\nFind the area of the shaded region in the given graph.\r\n\r\n\\begin{enumerate}\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={3.14,1.57},\r\n\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.5,ymax=2.2,%\r\n\t\t\txmin=-.1,xmax=3.5,%\r\n\t\t\tclip=false]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=0:3.14] {1};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=0:3.14] {1} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40, domain=-0.2:3.5] {1} node [shift={(-70pt,-5pt)} ,black] { $y=1$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40, domain=-0.2:3.5] {2} node [shift={(-70pt,5pt)} ,black] {  $y=2$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n}\r\n\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={3.14,6.28},\r\n\t\t\textra x tick labels={$\\pi$,$2\\pi$},\r\n%\t\t\tytick=\\empty,\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.2,ymax=6.5,%\r\n\t\t\tclip=false, % \r\n\t\t\txmin=-1,xmax=7%\r\n]\r\n\\addplot [{\\coloronefill},domain=0:6.28,stack plots=y,samples=40] {.5*cos(deg(x))+1};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=0:6.28,stack plots=y,samples=40] {.5*x+3-(.5*cos(deg(x))+1)} \\closedcycle;\r\n\\addplot [smooth,thick, {\\colorone},domain=-.9:6.5,samples=40] {.5*cos(deg(x))+1} node [shift={(-25pt,7pt)} ,black] {\\scriptsize $y=\\frac12\\cos x+1$};\r\n\\addplot [smooth,thick, {\\colorone},domain=-.9:6.5,samples=40] {.5*x+3}node [shift={(-30pt,0pt)} ,black] {\\scriptsize $y=\\frac12x+3$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\\item {\\begin{minipage}{\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick={-1,1},% \r\n%\t\t\textra x ticks={3.14,6.28},\r\n%\t\t\textra x tick labels={$\\pi$,$2\\pi$},\r\n\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-1.5,ymax=3.5,%\r\n\t\t\txmin=-1.1,xmax=1.1,%\r\n\t\t\tclip=false\r\n]\r\n\r\n\\addplot [{\\coloronefill},domain=-1:1,stack plots=y,samples=40] {x^2+x-1};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,domain=-1:1,stack plots=y,samples=40] {-3*x^3+3*x+2-(x^2+x-1)} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-1.05:1.05,samples=40] {x^2+x-1} node [shift={(-23pt,-55pt)} ,black] {\\small $y=x^2+x-1$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-1.05:1.05,samples=40] {-3*x^3+3*x+2}node [shift={(-120pt,22pt)} ,black] {\\small $y=-3x^3+3x+2$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}%\\ifthenelse{\\boolean{printquestions}}{\\columnbreak}{}\r\n}\r\n\r\n\\item {\\begin{minipage}{\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={3.14,1.57},\r\n\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.5,ymax=2.2,%\r\n\t\t\txmin=-.1,xmax=3.5,%\r\n\t\t\tclip=false\r\n]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=0:3.14] {sin(deg(x))};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=0:3.14] {sin(deg(x))+1-(sin(deg(x)))} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:3.14] {sin(deg(x))} node [shift={(-75pt,10pt)} ,black] { $y=\\sin x$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:3.14] {sin(deg(x))+1} node [shift={(-75pt,50pt)} ,black] { $y=\\sin x+1$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) { $x$};\r\n\\node [above] at (myplot.above origin) { $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n}\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={.785,.392},\r\n\t\t\textra x tick labels={$\\pi/4$,$\\pi/8$},\r\n\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.2,ymax=2.2,%\r\n\t\t\txmin=-.1,xmax=1,%\r\n\t\t\tclip=false\r\n]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=0:.785] {sin(deg(4*x))};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=0:.785] {sec(deg(x))^2-(sin(deg(4*x)))} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:.9,samples=60] {sin(deg(4*x))} node [shift={(-65pt,40pt)} ,black] {  $y=\\sin (4x)$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:.9,samples=60] {sec(deg(x))^2} node [shift={(-35pt,-20pt)} ,black] {  $y=\\sec^2 x$};\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\\item {\\begin{minipage}{\\textwidth}\r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n\t\t\txtick=\\empty,% \r\n\t\t\textra x ticks={.785,1.57,2.36,3.14,3.92},\r\n\t\t\textra x tick labels={$\\pi/4$,$\\pi/2$,$3\\pi/4$,$\\pi$,$5\\pi/4$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-1.1,ymax=1.1,%\r\n\t\t\txmin=-.1,xmax=4.1,%\r\n\t\t\tclip=false\r\n]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=.785:3.92] {cos(deg(x))};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=.785:3.92] {sin(deg(x))-(cos(deg(x)))} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:4.1,samples=40] {sin(deg(x))} node [shift={(-15pt,70pt)} ,black] {  $y=\\sin x$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:4.1,samples=40] {cos(deg(x))} node [shift={(-95pt,0pt)} ,black] {  $y=\\cos x$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}\r\n}\r\n\r\n\\item {\\begin{minipage}{\\linewidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=\\linewidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={.785,1.57,2.36,3.14,3.92},\r\n%\t\t\textra x tick labels={$\\pi/4$,$\\pi/2$,$3\\pi/4$,$\\pi$,$5\\pi/4$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=4.1,%\r\n\t\t\txmin=-.1,xmax=1.1,%\r\n\t\t\t\t\t\tclip=false]\r\n\r\n\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=0:1] {2^x};\r\n\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=0:1] {4^x-(2^x)} \\closedcycle;\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:1.1,samples=40] {2^x} node [shift={(-25pt,-20pt)} ,black] {  $y=2^x$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},domain=-.1:1.1,samples=40] {4^x} node [shift={(-40pt,-20pt)} ,black] {  $y=4^x$};\r\n\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {  $x$};\r\n\\node [above] at (myplot.above origin) {  $y$};\r\n\\end{tikzpicture}\r\n\r\n\\end{minipage}}\r\n\r\n\r\n\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {$\\pi$}\r\n\\item {$4\\pi+\\pi^2\\approx 22.436$}  \r\n\\item {$16/3$}\r\n\\item {$\\pi$}\r\n\\item {$1/2$}\r\n\\item {$2\\sqrt{2}$}\r\n\\item {$1/\\ln 4$}\r\n\\end{enumerate}\r\n\\end{sol}\r\n\\end{ex}\r\n% % % % % % % % % % % % % % % % %\r\n\r\n\r\n\\begin{ex}\r\nFind the area of the enclosed region in two ways:\\\\\r\n(1)\tby treating the boundaries as functions of $x$, and\\\\\r\n(2) by treating the boundaries as functions of $y$.\r\n\\begin{enumerate}\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={3.14,1.57},\r\n%\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=2.2,%\r\n\t\t\txmin=-.5,xmax=3.5%\r\n]\r\n\r\n%\\addplot [{\\coloronefill},stack plots=y,samples=40,domain=0:3.14] {1};\r\n%\\addplot [{\\coloronefill},thick,fill={\\coloronefill},area style,stack plots=y,samples=40,domain=0:3.14] {1} \\closedcycle;\r\n\r\n\\addplot [thick, {\\coloronefill},fill={\\coloronefill}] coordinates { (0,1.)(0.1,1.01)(0.2,1.04)(0.3,1.09)(0.4,1.16)(0.5,1.25)(0.6,1.36)(0.7,1.49)(0.8,1.64)(0.9,1.81)(1.,2.)(1.1,1.903)(1.2,1.81)(1.3,1.723)(1.4,1.64)(1.5,1.563)(1.6,1.49)(1.7,1.423)(1.8,1.36)(1.9,1.303)(2.,1.25)(2.1,1.203)(2.2,1.16)(2.3,1.123)(2.4,1.09)(2.5,1.063)(2.6,1.04)(2.7,1.023)(2.8,1.01)(2.9,1.003)(3.,1.)(0,1)};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:1] {x^2+1} node [shift={(-30pt,-15pt)} ,black,fill=white] {\\scriptsize $y=x^2+1$};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=1:3] {.25*(x-3)^2+1} node [shift={(-20pt,40pt)} ,black] {\\scriptsize $y=\\frac14(x-3)^2+1$};\r\n\r\n\\draw [smooth,thick, {\\colorone}] (axis cs:0,1) --  node [pos=.5,below,black] {\\scriptsize $y=1$} (axis cs:3,1);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={3.14,1.57},\r\n%\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-1.1,ymax=1.1,%\r\n\t\t\txmin=-.5,xmax=2.5%\r\n]\r\n\r\n\\addplot [thick, {\\coloronefill},fill={\\coloronefill}] coordinates { (0,0)(0.02,0.1414)(0.04,0.2)(0.06,0.2449)(0.08,0.2828)(0.1,0.3162)(0.2,0.4472)(0.3,0.5477)(0.4,0.6325)(0.5,0.7071)(0.6,0.7746)(0.7,0.8367)(0.8,0.8944)(0.9,0.9487)(1.,1.)(2,-1)(0,0)};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:1] {sqrt(x)} node [shift={(-25pt,-3pt)} ,black] {\\scriptsize $y=\\sqrt{x}$};\r\n%\r\n%\\addplot [smooth,thick, {\\colorone},samples=40,domain=1:3] {.25*(x-3)^2+1} node [shift={(-25pt,25pt)} ,black] {\\scriptsize $y=x^2+1$};\r\n%\r\n\\draw [smooth,thick, {\\colorone}] (axis cs:1,1) --  node [pos=.5,shift={(20pt,15pt)},black] {\\scriptsize $y=-2x+3$} (axis cs:2,-1);\r\n\r\n\\draw [smooth,thick, {\\colorone}] (axis cs:2,-1) --  node [pos=.3,shift={(-25pt,0pt)},black] {\\scriptsize $y=-\\frac12x$} (axis cs:0,0);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={3.14,1.57},\r\n%\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=4.5,%\r\n\t\t\txmin=-1.5,xmax=2.5%\r\n]\r\n\r\n\\addplot [thick, {\\coloronefill},fill={\\coloronefill}] coordinates { (-1.,1.)(-0.9,0.81)(-0.8,0.64)(-0.7,0.49)(-0.6,0.36)(-0.5,0.25)(-0.4,0.16)(-0.3,0.09)(-0.2,0.04)(-0.1,0.01)(0,0)(0.1,0.01)(0.2,0.04)(0.3,0.09)(0.4,0.16)(0.5,0.25)(0.6,0.36)(0.7,0.49)(0.8,0.64)(0.9,0.81)(1.,1.)(1.1,1.21)(1.2,1.44)(1.3,1.69)(1.4,1.96)(1.5,2.25)(1.6,2.56)(1.7,2.89)(1.8,3.24)(1.9,3.61)(2.,4.)(-1,1)};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=-1:2] {x^2} node [shift={(0pt,-30pt)} ,black] {\\scriptsize $y=x^2$};\r\n%\r\n%\\addplot [smooth,thick, {\\colorone},samples=40,domain=1:3] {.25*(x-3)^2+1} node [shift={(-25pt,25pt)} ,black] {\\scriptsize $y=x^2+1$};\r\n%\r\n\\draw [smooth,thick, {\\colorone}] (axis cs:2,4) --  node [pos=.5,shift={(10pt,25pt)},black] {\\scriptsize $y=x+2$} (axis cs:-1,1);\r\n\r\n%\\draw [smooth,thick, {\\colorone}] (axis cs:2,-1) --  node [pos=.3,shift={(-25pt,0pt)},black] {\\scriptsize $y=-1/2x$} (axis cs:0,0);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={3.14,1.57},\r\n%\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-2.5,ymax=1.5,%\r\n\t\t\txmin=-.5,xmax=2.5%\r\n]\r\n\r\n\\addplot [thick, {\\coloronefill},fill={\\coloronefill}] coordinates { (2.,-2.)(1.805,-1.9)(1.62,-1.8)(1.445,-1.7)(1.28,-1.6)(1.125,-1.5)(0.98,-1.4)(0.845,-1.3)(0.72,-1.2)(0.605,-1.1)(0.5,-1.)(0.405,-0.9)(0.32,-0.8)(0.245,-0.7)(0.18,-0.6)(0.125,-0.5)(0.08,-0.4)(0.045,-0.3)(0.02,-0.2)(0.005,-0.1)(0,0)(0.005,0.1)(0.02,0.2)(0.045,0.3)(0.08,0.4)(0.125,0.5)(0.18,0.6)(0.245,0.7)(0.32,0.8)(0.405,0.9)(0.5,1.)(2,-2)};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=-2:1] ({.5*x^2},x) node [shift={(5pt,-70pt)} ,black] {\\scriptsize $x=\\frac12y^2$};\r\n%\r\n%\\addplot [smooth,thick, {\\colorone},samples=40,domain=1:3] {.25*(x-3)^2+1} node [shift={(-25pt,25pt)} ,black] {\\scriptsize $y=x^2+1$};\r\n%\r\n\\draw [smooth,thick, {\\colorone}] (axis cs:2,-2) --  node [pos=.85,shift={(30pt,0pt)},black] {\\scriptsize $x=-\\frac12y+1$} (axis cs:.5,1);\r\n\r\n%\\draw [smooth,thick, {\\colorone}] (axis cs:2,-1) --  node [pos=.3,shift={(-25pt,0pt)},black] {\\scriptsize $y=-1/2x$} (axis cs:0,0);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\r\n\r\n\r\n\\item {\\begin{minipage}{\\textwidth} \r\n\\begin{tikzpicture}\r\n\\begin{axis}[width=0.4\\textwidth,%\r\ntick label style={font=\\small},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n\t\t\t%x=.37\\marginparwidth,\r\n\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick=\\empty,% \r\n%\t\t\textra x ticks={3.14,1.57},\r\n%\t\t\textra x tick labels={$\\pi$,$\\pi/2$},\r\n%\t\t\tytick={-1,1,2,3},\r\n\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%\t\t\tminor x tick num=4,\r\n\t\t\tymin=-.1,ymax=1.1,%\r\n\t\t\txmin=-.1,xmax=1.1%\r\n]\r\n\r\n\\addplot [thick, {\\coloronefill},fill={\\coloronefill}] coordinates { (0,0)(0.01,0.2154)(0.02,0.2714)(0.03,0.3107)(0.04,0.342)(0.05,0.3684)(0.06,0.3915)(0.07,0.4121)(0.08,0.4309)(0.09,0.4481)(0.1,0.4642)(0.12,0.4932)(0.14,0.5192)(0.16,0.5429)(0.18,0.5646)(0.2,0.5848)(0.22,0.6037)(0.24,0.6214)(0.26,0.6383)(0.28,0.6542)(0.3,0.6694)(0.4,0.7368)(0.5,0.7937)(0.6,0.8434)(0.7,0.8879)(0.8,0.9283)(0.9,0.9655)(1.,1.)(1.,0.7071)(0.9,0.6325)(0.8,0.5477)(0.7,0.4472)(0.6,0.3162)(0.59,0.3)(0.58,0.2828)(0.57,0.2646)(0.56,0.2449)(0.55,0.2236)(0.54,0.2)(0.53,0.1732)(0.52,0.1414)(0.51,0.1)(0.5,0)(0,0)};\r\n\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:1] (x^3,x) node [shift={(-25pt,0pt)} ,black] {\\scriptsize $y=x^{1/3}$};\r\n%\r\n\\addplot [smooth,thick, {\\colorone},samples=40,domain=0:.7071] ({(x)^2+.5},x) node [shift={(-20pt,-45pt)} ,black] {\\scriptsize $y=\\sqrt{x-1/2}$};\r\n%\r\n%\\draw [smooth,thick, {\\colorone}] (axis cs:2,-2) --  node [pos=.85,shift={(30pt,0pt)},black] {\\scriptsize $x=-1/2y+1$} (axis cs:.5,1);\r\n\r\n%\\draw [smooth,thick, {\\colorone}] (axis cs:2,-1) --  node [pos=.3,shift={(-25pt,0pt)},black] {\\scriptsize $y=-1/2x$} (axis cs:0,0);\r\n\r\n\\end{axis}\r\n\r\n\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{minipage}}\r\n\\end{enumerate}\t\t\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item {$1$}\r\n\\item {$5/3$}\r\n\\item {$9/2$}\r\n\\item {$9/4$}\r\n\\item {$1/12(9-2\\sqrt{2})\\approx 0.514$}\r\n\\end{enumerate}\t\t\r\n\\end{sol}\r\n\r\n\r\n\\end{ex}\r\n\r\n\r\n\\begin{ex}\r\n\\begin{enumerate}\r\n\\item {$(1,1)$,\\quad $(2,3)$,\\quad and \\quad $(3,3)$}\r\n\\item {$(-1,1)$,\\quad $(1,3)$,\\quad and \\quad $(2,-1)$}\r\n\\item {$(1,1)$,\\quad $(3,3)$,\\quad and \\quad $(3,3)$}\r\n\\item {$(0,0)$,\\quad $(2,5)$,\\quad and \\quad $(5,2)$}\r\n\\end{enumerate}\r\n\r\n\\begin{sol}\r\n\\begin{enumerate}\r\n\\item $ 1 $\r\n\\item $ 5 $\r\n\\item $ 4 $\r\n\\item $ \\frac{133}{20} $\r\n\\end{enumerate}\r\n\\end{sol}\r\n\r\n\\end{ex}\r\n\r\n\r\nFind the area bounded by the curves.\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds y=x^4-x^2$ and $\\ds y=x^2$ (the part to the right of the $y$-axis)\r\n\\begin{sol}\r\n $\\ds 8\\sqrt2/15$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds x=y^3$ and $\\ds x=y^2$\r\n\\begin{sol}\r\n $1/12$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds x=1-y^2$ and $y=-x-1$\r\n\\begin{sol}\r\n $9/2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds x=3y-y^2$ and $x+y=3$\r\n\\begin{sol}\r\n $4/3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $y=\\cos(\\pi x/2)$ and $\\ds y=1- x^2$ (in the first quadrant)\r\n\\begin{sol}\r\n $2/3-2/\\pi$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $y=\\sin(\\pi x/3)$ and $y=x$ (in the first quadrant)\r\n\\begin{sol}\r\n $\\ds 3/\\pi - 3\\sqrt3/(2\\pi)-1/8$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds y=\\sqrt{x}$ and $\\ds y=x^2$\r\n\\begin{sol}\r\n $1/3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds y=\\sqrt x$ and $\\ds y=\\sqrt{x+1}$, $0\\le x\\le 4$\r\n\\begin{sol}\r\n $\\ds 10\\sqrt{5}/3-6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $x=0$ and $\\ds x=25-y^2$\r\n\\begin{sol}\r\n $500/3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $y=\\sin x\\cos x$ and $y=\\sin x$, $0\\le x\\le \\pi$\r\n\\begin{sol}\r\n $2$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds y=x^{3/2}$ and $\\ds y=x^{2/3}$\r\n\\begin{sol}\r\n $1/5$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n $\\ds y=x^2-2x$ and $y=x-2$\r\n\\begin{sol}\r\n $1/6$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n{Use the Trapezoidal Rule to approximate the area of the pictured lake whose lengths, in hundreds of meters, are measured in $ 100 $-m. increments.\\label{07_01_ex_29}\r\n\r\n\\begin{center}\r\n\r\n\\begin{tikzpicture}[yscale=.6]%[width=\\marginparwidth+25pt]\r\n%\\begin{axis}[width=\\marginparwidth+25pt,%\r\n%tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n%\t\t\t%x=.37\\marginparwidth,\r\n%\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1,2,3,4,5,6,7,8,9,10,11,12},% \r\n%%\t\t\textra x ticks={12.57},\r\n%%\t\t\textra x tick labels={$4\\pi$},\r\n%%\t\t\tytick=\\empty,\r\n%\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%%\t\t\tminor x tick num=4,\r\n%\t\t\tymin=-.1,ymax=8.5,%\r\n%\t\t\txmin=-.1,xmax=12.5%\r\n%]\r\n\r\n\\draw [{\\colorone},thick,fill={\\coloronefill},smooth] plot coordinates {(0,1.)(0.1013,1.899)(0.3567,2.785)(0.6934,3.42)(1.039,3.569)(1.355,3.224)(1.646,2.705)(1.925,2.355)(2.2,2.473)(2.475,2.968)(2.75,3.529)(3.025,3.844)(3.3,3.709)(3.575,3.249)(3.85,2.651)(4.125,2.098)(4.389,1.661)(4.624,1.285)(4.807,0.9071)(4.921,0.4743)(4.958,0)(4.921,-0.4743)(4.807,-0.9071)(4.624,-1.279)(4.389,-1.625)(4.125,-1.986)(3.85,-2.401)(3.575,-2.843)(3.3,-3.233)(3.025,-3.487)(2.75,-3.536)(2.475,-3.397)(2.2,-3.111)(1.925,-2.718)(1.646,-2.263)(1.355,-1.792)(1.039,-1.352)(0.6934,-0.9844)(0.3567,-0.6744)(0.1013,-0.3653)(0,0)(0,1)};\r\n\r\n\\draw (1,3.56) -- (1,-1.35) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 4.9};\r\n\r\n\\draw (2,2.37) -- (2,-2.8) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 5.2};\r\n\r\n\\draw (3,3.8) -- (3,-3.5) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 7.3};\r\n\r\n\\draw (4,2.35) -- (4,-2.15) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 4.5};\r\n\r\n%\\end{axis}\r\n%\r\n%\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n%\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\\end{center}}\r\n\r\n\r\n\\begin{sol}\r\n{219,000 m$^2$}\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\n{Use Simpson's Rule to approximate the area of the pictured lake whose lengths, in hundreds of meters, are measured in 200-meter increments.\\label{07_01_ex_30}\r\n\r\n\\begin{center}\r\n\\begin{tikzpicture}[yscale=.6]%[width=\\marginparwidth+25pt]\r\n%\\begin{axis}[width=\\marginparwidth+25pt,%\r\n%tick label style={font=\\scriptsize},axis y line=middle,axis x line=middle,name=myplot,axis on top,%\r\n%\t\t\t%x=.37\\marginparwidth,\r\n%\t\t\t%y=.37\\marginparwidth,\r\n%\t\t\txtick={1,2,3,4,5,6,7,8,9,10,11,12},% \r\n%%\t\t\textra x ticks={12.57},\r\n%%\t\t\textra x tick labels={$4\\pi$},\r\n%%\t\t\tytick=\\empty,\r\n%\t\t\t%minor y tick num=1,%extra y ticks={-5,-3,...,7},%\r\n%%\t\t\tminor x tick num=4,\r\n%\t\t\tymin=-.1,ymax=8.5,%\r\n%\t\t\txmin=-.1,xmax=12.5%\r\n%]\r\n\r\n\\draw [{\\colorone},thick,fill={\\coloronefill},smooth] plot coordinates {(0,2.)(0.1013,2.717)(0.3567,3.238)(0.6934,3.594)(1.039,3.818)(1.355,3.948)(1.646,4.035)(1.925,4.132)(2.2,4.28)(2.475,4.428)(2.75,4.471)(3.025,4.307)(3.305,3.88)(3.607,3.287)(3.952,2.652)(4.361,2.098)(4.815,1.661)(5.253,1.285)(5.614,0.9071)(5.843,0.4705)(5.938,-0.04167)(5.919,-0.6295)(5.807,-1.293)(5.624,-2.009)(5.389,-2.703)(5.125,-3.29)(4.849,-3.692)(4.562,-3.892)(4.243,-3.929)(3.871,-3.846)(3.432,-3.674)(2.956,-3.409)(2.484,-3.028)(2.057,-2.511)(1.692,-1.869)(1.363,-1.168)(1.039,-0.4819)(0.6934,0.1248)(0.3567,0.679)(0.1013,1.273)(0,2.)};\r\n\r\n\\draw (1,3.8) -- (1,-.45) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 4.25};\r\n%\r\n\\draw (2,4.15) -- (2,-2.45) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 6.6};\r\n\r\n\\draw (3,4.3) -- (3,-3.4) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 7.7};\r\n\r\n\\draw (4,2.6) -- (4,-3.85) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 6.45};\r\n\r\n\\draw (5,1.45) -- (5,-3.45) node [shift={(-3pt,0pt)},rotate=90,pos=.5] {\\scriptsize 4.9};\r\n\r\n%\\end{axis}\r\n%\r\n%\\node [right] at (myplot.right of origin) {\\scriptsize $x$};\r\n%\\node [above] at (myplot.above origin) {\\scriptsize $y$};\r\n\\end{tikzpicture}\r\n\r\n\r\n\r\n\\end{center}}\r\n\r\n\\begin{sol}\r\n{623,333 m$^2$}\r\n\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n\\end{enumialphparenastyle}\r\n\r\n\\end{multicols}\r\n\\clearpage ", "meta": {"hexsha": "1edcfad3d1d802f5e4256905aaa498bea9059aaf", "size": 70887, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "8-applications-of-integration/8-2-area-between-two-curves.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-2-area-between-two-curves.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-2-area-between-two-curves.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.5691456669, "max_line_length": 932, "alphanum_fraction": 0.605019256, "num_tokens": 29078, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8267117855317474, "lm_q2_score": 0.9099070103134426, "lm_q1q2_score": 0.7522308491640802}}
{"text": "\\section{Properties of Power Spectral Density (PSD)}\rOne of the definitions of PSD is expressed in instruction and the power expression can be separated into conjugate product,  which is\r\r\\begin{align}\rP(\\omega) & = \\lim\\limits_{N \\to \\infty} \\mathbb{E} \\left\\{ \\frac{1}{N} \\left| \\sum_{n=0}^{N-1} x(n) e^{-j n \\omega} \\right|^2 \\right\\}\\label{proof:periodogram:starter}\\\\\r& = \\lim\\limits_{N \\to \\infty} \\mathbb{E} \\left\\{ \\frac{1}{N} \\sum_{n=0}^{N-1} x(n) e^{-j n \\omega} \\sum_{m=0}^{N-1} x(m)^\\ast e^{j m \\omega}  \\right\\} \\notag\\\\\r& =\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{n=0}^{N-1} \\sum_{m=0}^{N-1} \\mathbb{E} \\bigg \\{  x(n)e^{-j n \\omega}  x^*(n)e^{j m \\omega}\\bigg\\}\\notag\\\\\r& =\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{n=0}^{N-1} \\sum_{m=0}^{N-1}\t\\mathbb{E} \\bigg \\{  x(n) x^*(n)\\bigg\\}e^{-j(n-m)\\omega}\r\\label{proof:periodogram}\r\\end{align}\rIn addition, the correlation of a complex signal can be expressed as\r\r\\begin{equation}\r\\begin{split}\rr_{xx}(n) &= \\mathbb E\\bigg\\{ x(k)x^*(k-n)\\bigg\\}\\\\\rr_{xx}(k-n) &= \\mathbb E\\bigg\\{ x(k)x^*(k-n)\\bigg\\}\r\\label{proof:corr}\r\\end{split}\r\\end{equation}\rTherefore, the Equation \\ref{proof:periodogram} can be expressed as\r\\begin{equation}\rP(\\omega)=\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{n=0}^{N-1} \\sum_{m=0}^{N-1}\tr_{xx}(n-m)e^{-j(n-m)\\omega}=\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{n=0}^{N-1} \\sum_{m=0}^{N-1} g(n-m)\r\\label{proof:rxx}\r\\end{equation}\rThen, the double summation of Equation \\ref{proof:rxx} could be converted into single one based on $\\sum_{n=-N}^N \\sum_{m=-N}^N g(n-m)=\\sum_{k =-2N}^{2N}(2N+1-|k|)g(k)$. Thus, Equation \\ref{proof:rxx} is \r\\begin{align}\rP(\\omega)&=\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{n=0}^{N-1} \\sum_{m=0}^{N-1} g(n-m)\\notag\\\\\r&=\\lim\\limits_{N \\to \\infty} \\frac{1}{N} \\sum_{k=-(N-1)}^{N-1}(N-|k|) g(k)\\notag\\\\\r&=\\sum_{k=-\\infty}^{\\infty} r_{xx}(k) e^{-jk\\omega}  - \\lim_{N\\to\\infty} \\frac{1}{N} \\sum_{k=-(N-1)}^{N-1} |k| r_{xx}(k) e^{-jk\\omega}\\label{proof:assump}\\\\\r&\\approx \\sum_{k=-\\infty}^{\\infty} r_{xx}(k) e^{-jk\\omega} \\  (under \\ fast \\ decays)\r\\label{proof: final}\r\\end{align}\rWith the assumption of rapidly decays, the latter part of Equation \\ref{proof:assump} tends to zero. Hence, the Equation \\ref{proof:periodogram:starter} of PSD could be deduced to Equation \\ref{proof: final}.\r\r\r\r\r\r\r\r\r\r\r\r\r", "meta": {"hexsha": "5c9061aead493af52251b853da21c797499524ab", "size": 2318, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Report/sections/Part1/11.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/11.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/11.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": 2318.0, "max_line_length": 2318, "alphanum_fraction": 0.6242450388, "num_tokens": 1046, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009526726545, "lm_q2_score": 0.8221891305219504, "lm_q1q2_score": 0.7522216187916339}}
{"text": "\\subsection*{Velocity}\\label{sec:Velocity}\r\n\r\nWe started this section by saying, ``It is often useful to know\r\nhow sensitive the value of $y$ is to small changes in $x$.'' We have\r\nseen one purely mathematical example of this, involving the function $f(x)=\\sqrt{625-x^2}$. \r\nHere is a more applied example.\r\n\r\nWith careful measurement it might be possible to discover that the height of a\r\ndropped ball $t$ seconds after it is released is $\\ds h(t)=h_0-kt^2$. \r\n(Here $h_0$ is the initial height of the ball, when $t=0$,\r\nand $k$ is some number determined by the experiment.)  A natural\r\nquestion is then, ``How fast is the ball going at time $t$?'' We can\r\ncertainly get a pretty good idea with a little simple arithmetic. To\r\nmake the calculation more concrete, let's use units of meters and seconds and say that $\\ds h_0=100$ meters and $k=4.9$.\r\nSuppose we're interested in the speed at $t=2$. We know that when\r\n$t=2$ the height is $100-4\\cdot 4.9=80.4$ meters. A second later, at $t=3$,\r\nthe height is $100-9\\cdot 4.9=55.9$ meters. The change in height during that second is\r\n $55.9-80.4=-24.5$ meters. The negative sign means the height has decreased, as we expect for a falling ball, and the number 24.5 is the average speed of the ball during the time interval, in meters per second.\r\n\r\nWe might guess that 24.5 meters per second is not a terrible estimate of the speed at\r\n$t=2$, but certainly we can do better. At $t=2.5$ the height is\r\n$\\ds 100-4.9(2.5)^2=69.375$ meters. During the half second from $t=2$ to $t=2.5$, the change in height is\r\n $69.375-80.4=-11.025$ meters giving an average speed of \r\n$11.025/(1/2)=22.05$ meters per second. This should be a better estimate\r\nof the speed at $t=2$. So it's clear now how to get better and better\r\napproximations: compute average speeds over shorter and shorter time\r\nintervals. Between $t=2$ and $t=2.01$, for example, the ball drops\r\n0.19649 meters in one hundredth of a second, at an average speed of\r\n19.649 meters per second.\r\n \r\nWe still might reasonably ask for the precise speed at $t=2$ (the {\\em instantaneous} speed)\r\nrather than just an approximation to it. For this, once again, we need a limit. Let's calculate\r\nthe average speed during the time interval from $t=2$ to $t=2+\\Delta t$ without specifying a particular value for $\\Delta t$.\r\nThe change in height during the time interval from $t=2$ to $t=2+\\Delta t$ is\r\n\\begin{align*}\r\nh(2+\\Delta t)-h(2)\r\n&=(100-4.9(2+\\Delta t)^2)-80.4\\\\\r\n&=100-4.9(4+4\\Delta t+\\Delta t^2)-80.4\\\\\r\n&=100-19.6-19.6\\Delta t-4.9\\Delta t^2-80.4\\\\\r\n&=-19.6\\Delta t-4.9\\Delta t^2\\\\\r\n&=-\\Delta t(19.6+4.9\\Delta t)\r\n\\end{align*}\r\nThe average speed during this time interval is then\r\n$$\\frac{\\Delta t(19.6+4.9\\Delta t)}{\\Delta t}=19.6+4.9\\Delta t.$$\r\n\r\nWhen $\\Delta t$ is very small, this is very close to 19.6. Indeed,\r\n$\\lim_{\\Delta x\\to 0}(19.6+4.9\\Delta t)=19.6$. So the exact speed at $t=2$ is 19.6 meters per second.\r\n\r\nAt this stage we need to make a distinction between \\textit{speed} and\r\n\\textit{velocity}. Velocity is signed speed, that is, speed with a\r\ndirection indicated by a sign (positive or negative). Our algebra\r\nabove actually told us that the instantaneous velocity of the ball at $t=2$ is\r\n$-19.6$ meters per second. The number 19.6 is the speed and the\r\nnegative sign indicates that the motion is directed downwards (the\r\ndirection of decreasing height).\r\n\r\nIn the language of the previous section, we might have started with\r\n$\\ds f(x)=100-4.9x^2$ and asked for the slope of the tangent line at\r\n$x=2$. We would have answered that question by computing $$\r\n\\lim_{\\Delta x\\to 0}\\frac{f(2+\\Delta x) - f(2)}{\\Delta x}\r\n=\\lim_{\\Delta x\\to 0}\\frac{-19.6\\Delta x-4.9\\Delta x^2}{\\Delta x}\r\n=-19.6-4.9\\Delta x=19.6\r\n$$ \r\nThe algebra is the same. Thus, the velocity of the ball is the value\r\nof the derivative of a certain function, namely, of the function that\r\ngives the position of the ball.\r\n\r\nThe upshot is that this problem, finding the velocity of the ball, is\r\n\\ifont{exactly} the same problem mathematically as finding the slope\r\nof a curve. This may already be enough evidence to convince you that\r\nwhenever some quantity is changing (the height of a curve or the\r\nheight of a ball or the size of the economy or the distance of a space\r\nprobe from earth or the population of the world) the \\textit{rate} at which the\r\nquantity is changing can, in principle, be computed in exactly the\r\nsame way, by finding a derivative.\r\n\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\\Opensolutionfile{solutions}[ex]\r\n\\section*{Exercises for Section \\ref{sec:Slope}}\r\n\r\n\\begin{enumialphparenastyle}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nDraw the graph of the function $\\ds y=f(x)=\\sqrt{169-x^2}$ between $x=0$\r\nand $x=13$.  Find the slope $\\Delta y/\\Delta x$ of the chord between the\r\npoints of the circle lying over (a) $x=12$ and $x=13$, (b) $x=12$ and\r\n$x=12.1$,  (c) $x=12$ and $x=12.01$, (d) $x=12$ and $x=12.001$.  Now use\r\nthe geometry of tangent lines on a circle to find (e) the exact value of the\r\nderivative $f'(12)$.  Your answers to (a)--(d) should be getting closer and\r\ncloser to your answer to (e).\r\n\\begin{sol}\r\n$-5$, $-2.47106145$, $-2.4067927$, $-2.400676$, $-2.4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nUse geometry to find the derivative $f'(x)$ of the function\r\n$\\ds f(x)=\\sqrt{625-x^2}$ in the text for each of the following $x$: (a) 20,\r\n(b) 24, (c) $-7$, (d) $-15$.  Draw a graph of the upper semicircle, and\r\ndraw the tangent line at each of these four points.\r\n\\begin{sol}\r\n$-4/3$, $-24/7$, $7/24$, $3/4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nDraw the graph of the function $y=f(x)=1/x$ between $x=1/2$ and $x=4$.\r\nFind the slope of the chord between (a) $x=3$ and $x=3.1$, (b) $x=3$ and\r\n$x=3.01$, (c) $x=3$ and $x=3.001$.  Now use algebra to find a simple\r\nformula for the slope of the chord between $(3,f(3))$ and $(3+\\Delta\r\nx,f(3+\\Delta x))$.  Determine what happens when $\\Delta x$ approaches 0.\r\nIn your graph of $y=1/x$, draw the straight line through the point\r\n$(3,1/3)$ whose slope is this limiting value of the difference quotient as\r\n$\\Delta x$ approaches 0.\r\n\\begin{sol}\r\n$-0.107526881$, $-0.11074197$, $-0.1110741$, \r\n$\\ds{-1\\over3(3+\\Delta x)}\\rightarrow {-1\\over9}$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nFind an algebraic expression for the difference quotient $\\ds \\bigl(f(1+\\Delta\r\nx)-f(1)\\bigr)/\\Delta x$ when $\\ds f(x)=x^2-(1/x)$.  Simplify the expression as\r\nmuch as possible.  Then determine what happens as $\\Delta x$ approaches 0.\r\nThat value is $f'(1)$.\r\n\\begin{sol}\r\n$\\ds{3+3\\Delta x+\\Delta x^2\\over1+\\Delta x}\\rightarrow3$ \r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nDraw the graph of $\\ds y=f(x)=x^3$ between $x=0$ and $x=1.5$.  Find the slope\r\nof the chord between (a) $x=1$ and $x=1.1$, (b) $x=1$ and $x=1.001$, (c)\r\n$x=1$ and $x=1.00001$.  Then use algebra to find a simple formula for the\r\nslope of the chord between $1$ and $1+\\Delta x$.  (Use the expansion\r\n$\\ds (A+B)^3=A^3+3A^2B+3AB^2+B^3$.)  Determine what happens as $\\Delta x$\r\napproaches 0, and in your graph of $\\ds y=x^3$ draw the straight line through\r\nthe point $(1,1)$ whose slope is equal to the value you just found.\r\n\\begin{sol}\r\n$3.31$, $3.003001$, $3.0000$,\\hfill\\break\r\n $3+3\\Delta x+\\Delta x^2\\rightarrow3$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\\label{ex:derivative of a line}\r\nFind an algebraic expression for the difference quotient $(f(x+\\Delta\r\nx)-f(x))/\\Delta x$ when $f(x)=mx+b$.  Simplify the expression as\r\nmuch as possible.  Then determine what happens as $\\Delta x$ approaches 0.\r\nThat value is $f'(x)$.\r\n\\begin{sol}\r\n$m$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSketch the unit circle.  Discuss the behavior of the slope\r\nof the tangent line at various angles around the circle.  Which\r\ntrigonometric function gives the slope of the tangent line at an angle\r\n$\\theta$?  Why? Hint: think in terms of ratios of sides of triangles.\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nSketch the parabola $\\ds y=x^2$.  For what values of $x$ on the parabola\r\nis the slope of the tangent line positive?  Negative?  What do you notice\r\nabout the graph at the point(s) where the sign of the slope changes from\r\npositive to negative and vice versa?\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nAn object is traveling in a straight line so that its position (that\r\nis, distance from some fixed point) is\r\ngiven by this table:\r\n\\begin{table}[!ht]\r\n\\begin{tabular}{|c|c|c|c|c|}\r\n\\hline\r\ntime (seconds)& 0& 1& 2& 3\\\\\r\n\\hline\r\ndistance (meters)& 0& 10& 25& 60\\\\\r\n\\hline\r\n\\end{tabular}\r\n\\end{table}\r\n\r\nFind the average speed of the object during the following time\r\nintervals: $[0,1]$, $[0,2]$, $[0,3]$,\r\n$[1,2]$, $[1,3]$, $[2,3]$. If you had to guess the speed at\r\n$t=2$ just on the basis of these, what would you guess?\r\n\\begin{sol}\r\n$10$, $25/2$, $20$, $15$, $25$, $35$.\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nLet $\\ds y=f(t)=t^2$, where $t$ is the time in seconds and $y$ is the distance\r\nin meters that an object falls on a certain airless planet.  Draw a graph\r\nof this function between $t=0$ and $t=3$.  Make a table of the average\r\nspeed of the falling object between (a) 2 sec and 3 sec, (b) 2 sec and\r\n2.1 sec, (c) 2 sec and 2.01 sec, (d) 2 sec and 2.001 sec.  Then use algebra\r\nto find a simple formula for the average speed between time $2$ and time\r\n$2+\r\n\\Delta t$.  (If you substitute $\\Delta t=1,\\>0.1,\\>0.01,\\>0.001$ in this\r\nformula you should again get the answers to parts (a)--(d).)  Next, in your\r\nformula for average speed (which should be in simplified form) determine\r\nwhat happens as $\\Delta t$ approaches zero.  This is the instantaneous\r\nspeed.  Finally, in your graph of $\\ds y=t^2$ draw the straight line\r\nthrough the point $(2,4)$ whose slope is the instantaneous velocity you\r\njust computed; it should of course be the tangent line.\r\n\\begin{sol}\r\n$5$, $4.1$, $4.01$, $4.001$, $4+\\Delta t\\rightarrow 4$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n%%%%%%%%%%\r\n\\begin{ex}\r\nIf an object is dropped from an 80-meter high window, its height $y$ above\r\nthe ground at time $t$ seconds is given by the formula $\\ds y=f(t)=80-4.9t^2$.\r\n(Here we are neglecting air resistance; the graph of this function was\r\nshown in figure~\\ref{fig:data plot}.)  Find the average velocity of\r\nthe falling object between (a) 1 sec and 1.1 sec, (b) 1 sec and 1.01 sec,\r\n(c) 1 sec and 1.001 sec.  Now use algebra to find a simple formula for the\r\naverage velocity of the falling object between 1 sec and $1+\\Delta t$ sec.\r\nDetermine what happens to this average velocity as $\\Delta t$ approaches 0.\r\nThat is the instantaneous velocity at time $t=1$ second (it will be negative,\r\nbecause the object is falling).\r\n\\begin{sol}\r\n$-10.29$, $-9.849$, $-9.8049$, \\hfill\\break\r\n$-9.8-4.9\\Delta t\\rightarrow -9.8$\r\n\\end{sol}\r\n\\end{ex}\r\n\r\n\\end{enumialphparenastyle}", "meta": {"hexsha": "e4049f908c4a776891ea741548187465d3b82958", "size": 10800, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "4-derivatives/4-2-limits-velocity.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-2-limits-velocity.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-2-limits-velocity.tex", "max_forks_repo_name": "TimAlderson/OpenCalc", "max_forks_repo_head_hexsha": "7d0110b6bc4ba42a6b911729420e1406296d6964", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 44.8132780083, "max_line_length": 211, "alphanum_fraction": 0.677962963, "num_tokens": 3485, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797071719777, "lm_q2_score": 0.8539127585282744, "lm_q1q2_score": 0.7521238572158611}}
{"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{Face-off}{Face-off}\n\n\\input{../fncextra}\n\\begin{document}\n\n\\begin{center}\n  \\bf Project: The least squares face-off\n\\end{center}\n\nBy now you are familiar with representing an image that is $p$ pixels by $q$ pixels as a $p\\times q$ matrix with entries from 0 to 255. A $p\\times q$ matrix can also be viewed a $pq\\times 1$ vector. In fact, this is how it is stored in computer memory, which is addressed linearly. In MATLAB, you can convert between an $p \\times q$ matrix $\\mZ$ and its vector form $\\bfz$ as follows:\n\\begin{verbatim}\nz = Z(:);\nZ = reshape(z,p,q);\n\\end{verbatim}\nThe vector point of view has certain advantages. For example, we can collect a library of $n$ identically sized $p\\times q$ images as columns of a single $pq \\times n$ matrix $\\mA$. If another image comes along as the $pq$-vector $\\bfz$, we might want to know how much it resembles other images in the library, for instance as part of a facial recognition application. \n\nA natural way to attack this problem is to solve $\\mA\\bfx\\approx\\bfz$ for $\\bfx$ using linear least squares. If $\\bfz$ is well represented as a linear combination of\nimages in the library, then we should see a relatively small residual $\\|\\bfz-\\mA\\bfx\\|$. Furthermore, suppose $J$ is a set of column indices in $\\mA$ all representing images of a single person. We could define, say,\n\\begin{equation}\n  \\label{eq:faceoff1}\n  s_J = \\sum_{j\\in J} x_j,\n\\end{equation}\nand use $s_J$ as an indicator of the similarity of $\\bfz$ to that person. However, there are many other ways one could define $s_J$ based on the $x_j$, and you are not required to use~\\eqref{eq:faceoff1}. \n\nFor this project you will need data available online as \\textsf{attfaces.zip}. This file has a README describing 400 face images of size $112\\times 92$. The file also has two MATLAB functions: \\texttt{loadface}, which accepts a subject and pose number and returns the corresponding image in column form, and \\texttt{showfaces}, which takes a matrix of image vectors and displays them in a grid. \n\nYour team will be given a list of 25 subject numbers and 6 pose numbers, implying a total of 150 images. Thus, your library matrix $\\mA$ will have $n=150$ columns, each of length $m=(112)(92)=10304$. You should also create an $n$-vector \\texttt{subj} that records the subject number whose image appears in the corresponding column. Because you will be solving many different least squares problems with the same matrix, you should perform a reduced (not full!) factorization $\\mA=\\hat{\\mQ}\\hat{\\mR}$; see section~3.3 on how this factorization is used to solve the least squares problem.\n\nYour goal is to write a function\n\\begin{verbatim}\nfunction [s,conf] = identiface(Q,R,subj,z)\n\\end{verbatim}\nThe inputs \\texttt{Q} and \\texttt{R} are the reduced QR factors of $\\mA$, and \\texttt{subj} is described above. The other input is another image \\texttt{z} in vector form. The only information you are permitted to use are the input arguments and the solution vector $\\bfx$ of the linear least squares problem min $\\|\\bfz-\\mA\\bfx\\|_2$. The first output \\texttt{s} is the subject number (not column number) that is judged to be the most likely match for \\texttt{z}, and the second output \\texttt{conf} is a number between 0 (lowest) and 1 (highest) that indicates the level of confidence in the identification.\nFor example, calling\n\\begin{verbatim}\nidentiface(Q,R,subj,A(:,j))\n\\end{verbatim}\nshould return \\texttt{subj(j)} and 1 as outputs. On the other hand, if the image is not from one of the subjects in your collection (or not even a face at all!), then \\texttt{conf} should ideally be small. \n\nTo measure the performance of the algorithm, suppose $T$ is a collection of test images. For each $z_i\\in T$, let the returned confidence score be $w_i$. Then the performance is\n\\begin{equation}\n  \\label{eq:faceoff2}\n  p(T) = \\left( \\sum_{i\\in \\text{HITS}} w_i \\right) -\n  \\left( \\sum_{i\\in \\text{MISSES}} w_i \\right),\n\\end{equation}\nwhere HITS and MISSES are index sets that divide the successful subject identifications from the errors. You should perform tests using your own choice(s) of $T$, including images from the library, images of subjects in poses not used in the library, images of other subjects in the database, and images of things other than faces, until you are satisfied that changes to your algorithm are unlikely to improve the overall performance. \n\n\\subsection*{Submission requirements}\n\\label{sec:subm-requ}\n\nYou should turn in all code needed to run and test the \\texttt{identiface} function. (Submit as separate files; there is no need to zip them.) Also turn in a short PDF report (no more than 2 pages) describing in mathematical terms how your function computes its outputs. Justify your algorithm with mathematical or experimental arguments. \n\n\\end{document}\n\n", "meta": {"hexsha": "9412aed4fc0dd4c32a0cc0c78ae2cc08b9021acc", "size": 5006, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "projects/faceoff/faceoff.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/faceoff/faceoff.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/faceoff/faceoff.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": 78.21875, "max_line_length": 608, "alphanum_fraction": 0.7570914902, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.880797068590724, "lm_q2_score": 0.8539127548105611, "lm_q1q2_score": 0.7521238512693719}}
{"text": "\\section{Finite Fields and Bit Lengths}\n\\label{sec:finiteFieldsAndBitLengths}\n\n\\noindent\nFor those who go through the Nightfall code, you might realise there are many number conversions being made in the zkp microservice. In particular, there are frequently conversions and restrictions to $216$-bit ($27$-byte) values in much of today's Nightfall code. These conversions are a consequence of working with zk-SNARKs.\\\\\n\\\\\nLike many cryptographic protocols, zk-SNARKs make use of representing numbers as points on an elliptic curve. In doing so, the results of our computations become quite difficult to `unravel' -- that is, given an output, it becomes computationally infeasible for someone to determine the inputs. However, it also restricts the mathematics we can do. This is a gross oversimplification of why elliptic curves are used, but let's talk about them.\\\\\n\\\\\nCurrently on Ethereum, there is only one elliptic curve for which it is `cheap' (in terms of gas costs) to perform calculations (due to there being precompile contracts supporting calculations on this curve):\n\\begin{align*}\n    E := y^2 = x^3 + 3\n\\end{align*}\n\nThis curve looks like this:\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.8\\textwidth]{images/ellipticCurveReals.png}\n\t\\end{center}\n\t\\caption{$y^2 = x^3 + 3$ over the real numbers.}\n\t\\label{pic:ftShield}\n\\end{figure}\n\nAs an example, let's restrict the $x$ and $y$ coordinates to be the field of integers modulo $7$. I.e. we only allow the numbers $\\mathbb{F}_7 = {0, 1, 2, 3, 4, 5, 6}$. In this world, $5 + 5 = 10 = 3\\;(mod\\;7)$.\\\\\n\\\\\nLet's consider the possible $y$-values of our elliptic curve $E$ when restricted to $\\mathbb{F}_7$ (note: we write $E[\\mathbb{F}_7]$ for 'the elliptic curve defined over the finite field $\\mathbb{F}_7$).\n\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n    \\hline\n    $y$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ \\\\\n    \\hline\n    $y^2$ & $0$ & $1$ & $4$ & $9=2$ & $16=2$ & $25=4$ & $36=1$ \\\\\n    \\hline\n\\end{tabular}\n\nNow let's consider the $x$-values of $E[\\mathbb{F}_7]$:\n\n\\begin{tabular}{|c|c|c|c|c|c|c|c|}\n    \\hline\n    $x$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ \\\\\n    \\hline\n    $x^3$ & $0$ & $1$ & $8=1$ & $27=6$ & $64=1$ & $125=6$ & $216=6$ \\\\\n    \\hline\n    $x^3+3$ & $3$ & $4$ & $4$ & $9=2$ & $4$ & $9=2$ & $9=2$ \\\\\n    \\hline\n    $= y^2$ & - & $4$ & $4$ & $2$ & $4$ & $2$ & $2$ \\\\\n    \\hline\n    Valid $y$-values & \n        -- & \n        \\makecell{$2$\\\\$5$} &\n        \\makecell{$2$\\\\$5$} &\n        \\makecell{$3$\\\\$4$} &\n        \\makecell{$2$\\\\$5$} &\n        \\makecell{$3$\\\\$4$} & \n        \\makecell{$3$\\\\$4$} \\\\\n    \\hline\n\\end{tabular}\n\nSo we have a set of valid points of $\\infty, (1,2), (1,5), (2,2), (2,5), (3,3), (3,4), (4,2), (4,5), (5,3), (5,4), (6,3), (6,4)$.\\\\\n\\\\\nThese $13$ points are the only points which exist on $E[\\mathbb{F}_7]$. $E[\\mathbb{F}_7]$ is a `group' of order $13$.\\\\\nIn other words: the curve $E: y^2 = x^3 + 3$ --- when restricted to the $7$ values of $\\mathbb{F}_7$ --- produces a group $E[\\mathbb{F}_7]$ of order $13$.\\\\\n\\\\\nWe superimpose the points of $E[\\mathbb{F}_7]$ (in green) below:\n\\begin{figure}[H]\n\t\\begin{center}\n\t\t\\includegraphics[width=0.8\\textwidth]{images/ellipticCurveF7.png}\n\t\\end{center}\n\t\\caption{$y^2 = x^3 + 3$ over $\\mathbb{F}_7$ shown as green dots.}\n\t\\label{pic:ftShield}\n\\end{figure}\n\nAn important thing to take away from this example, is that there are 3 distinct things for us to be aware of: an elliptic curve equation $E$, a finite field $\\mathbb{F}$, and the resulting group $G = E[\\mathbb{F}]$. Sometimes the number of elements in the group $G$ is \\textit{more than} the number of elements in the field $\\mathbb{F}$ (as in the above example), and sometimes the number of elements in the group $G$ is \\textit{less than} the number of elements in the field $\\mathbb{F}$ (as we will see is the case with Ethereum).\\\\\n\\\\\nIn practice, the finite field $\\mathbb{F}_p$ used in Ethereum is of size\n\\begin{align*}\n    p = 21888242871839275222246405745257275088696311157297823662689037894645226208583\n\\end{align*}\n\nThe elliptic curve $E: y^2 = x^3 + 3$, when restricted to the $p$ values of $\\mathbb{F}_p$, produces a group $G_1 = E[\\mathbb{F}_p]$ of prime order\n\\begin{align*}\n    q = 21888242871839275222246405745257275088548364400416034343698204186575808495617\n\\end{align*}\n\nI.e. $G_1 = E[\\mathbb{F}_p]$ is a group with $q$ distinct points. Here, $q < p$; the size of the group $G_1$ is less than the size of the field $\\mathbb{F_p}$.\\\\\n\\\\\nThis has an important consequence when working within ZoKrates. To generate zk-SNARKs, ZoKrates will convert the numbers we pass as inputs to our off-chain calculation (as well as all intermediate numbers of the calculation) into elliptic curve points. To tie-in with Ethereum, ZoKrates converts all of the numbers used in its calculations into elements of the group $G_1$. Therefore, we need to make sure that \\textbf{all} of the inputs we pass into ZoKrates are \\textbf{less than} the size of the group $G_1$, $q = 21888242871839275222246405745257275088548364400416034343698204186575808495617$.\\\\\n\\\\\nThis value of $q$ is slightly less than $254$-bits. I.e. $2^{253} < q < 2^{254}$.\\\\\n\\\\\nHence, to be sure we don't `overflow' modulo-$q$, it's safest to only pass numbers to ZoKrates which are $\\leq 253$-bits. When working with Ethereum, we often work with hex numbers (because Solidity `likes' hex numbers), which means it's often nice for the bit-length we work with to be divisible by $8$. Since $248$ is the largest number below $253$ which is divisible by $8$, this would have been a nice choice for all of the numbers Nightfall passes to ZoKrates.\\\\\n\\\\\nHowever, you might notice we instead restrict all our numbers to $216$-bits. The reason for this is the maximum size of a message in the NIST specification of the sha256 hashing algorithm. The largest message size for `one round' of sha256 hashing is $447$-bits. The version of ZoKrates used in Nightfall currently only supports `one round' of sha256 hashing. Hence our inputs to each hashing iteration must be $447$-bits or less.\\\\\n\\\\\nYou'll see in the protocols below, that we frequently need to concatenate two values and then hash them. Hence we need each of the two values to be at most $223$-bits to fit inside `one round' of sha256 hashing. Given that we also prefer bit-lengths which are divisible by $8$, $216$-bits becomes the best choice for our purposes.\\\\\n\\\\\n\\textbf{And that's why you'll see conversions and restrictions to 216-bit (27-byte) values in much of today's Nightfall code.}\\\\\n\\\\\nIn cases where we need to use a number with a greater bit-length than $216$ (for security purposes), we deconstruct that number into an array of $216$-bit values. E.g. a $512$-bit number might be deconstructed into an array [$80$-bits, $216$-bits, $216$-bits].\n", "meta": {"hexsha": "bb948695b0f750595aa613ff0d53d0319bebf7f8", "size": 6803, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/whitepaper/application/finiteFieldsAndBitLengths.tex", "max_stars_repo_name": "shadmoney/nightfall", "max_stars_repo_head_hexsha": "e01c19127a667381bf44a0f8f5929d0b16fb9824", "max_stars_repo_licenses": ["CC0-1.0"], "max_stars_count": 893, "max_stars_repo_stars_event_min_datetime": "2019-04-16T18:49:34.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T20:02:38.000Z", "max_issues_repo_path": "doc/whitepaper/application/finiteFieldsAndBitLengths.tex", "max_issues_repo_name": "shadmoney/nightfall", "max_issues_repo_head_hexsha": "e01c19127a667381bf44a0f8f5929d0b16fb9824", "max_issues_repo_licenses": ["CC0-1.0"], "max_issues_count": 292, "max_issues_repo_issues_event_min_datetime": "2019-05-06T12:08:58.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T11:16:49.000Z", "max_forks_repo_path": "doc/whitepaper/application/finiteFieldsAndBitLengths.tex", "max_forks_repo_name": "shadmoney/nightfall", "max_forks_repo_head_hexsha": "e01c19127a667381bf44a0f8f5929d0b16fb9824", "max_forks_repo_licenses": ["CC0-1.0"], "max_forks_count": 161, "max_forks_repo_forks_event_min_datetime": "2019-05-28T15:33:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-18T10:29:50.000Z", "avg_line_length": 68.7171717172, "max_line_length": 598, "alphanum_fraction": 0.6855798912, "num_tokens": 2239, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122238669025, "lm_q2_score": 0.8289388083214156, "lm_q1q2_score": 0.7521063136276837}}
{"text": "\n\\subsection{Exogeneity}\n\n\\subsubsection{Contemporaneous exogeneity}\n\n\\(Cov(x_{it},u_{it})=0\\)\n\n\\subsubsection{Strict exogeneity}\n\n\\(Cov (x_{is}, u_{it})=0)\\)\n\nThis is stronger than contemporeous, all periods.\n\nShocks don't affect future outcomes.\n\n\\subsubsection{Sequential exogeneity}\n\nSequential exogeneity: a bit looser than strict exogeneity. only holds when \\(s\\le t\\).\n\nSo shocks can affect, but only in future.\n\n", "meta": {"hexsha": "4a2f16a18e8156d70ba2d64621e59ee3032a892d", "size": 420, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/probability/stochasticMulti/01-02-exogeneity.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-02-exogeneity.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-02-exogeneity.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": 87, "alphanum_fraction": 0.7476190476, "num_tokens": 117, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9173026618464795, "lm_q2_score": 0.8198933337131076, "lm_q1q2_score": 0.7520903374452175}}
{"text": "\\section{Dynamic Programming}\n\\label{section:dp}\n\n\\paragraph{Policy Evaluation Algorithm}\nFor (small) tabular environments with known MDP, Bellman equations can be computed exactly and one can converge on $V^{\\pi}$ by applying equation \\ref{eq:bellman-v} repeatedly:\n\\[\n    V_{i+1}(s) = \\sum_{a\\in A} \\sum_{s' \\in S} \\pi(a\\mid s) P(s'\\mid s,a) [R(s,a,s') + \\gamma V_i(s')]\n\\]\n\n\\paragraph{Policy Iteration Algorithm}\nBeing \\emph{greedy} with respect to current value function $V^{\\pi_k}$ makes it possible to define a better (deterministic) policy: \n\\[\n    \\pi_{k+1}(s) = \\argmax_a \\sum_{s' \\in S} P(s'\\mid s,a) [R(s,a,s') + \\gamma V^{\\pi_k}(s')] \\tag*{\\emph{policy improvement}}\n\\]\nIn the policy iteration algorithm, the policy evaluation algorithm is applied until convergence to $V^{\\pi_k}$ and followed by one policy improvement step. This is repeated until convergence to $\\pi^*$ (characterized by stationarity). The idea of having these two policy evaluation and improvement processes interact is found in many RL algorithms (not necessarily as separate steps, but also simultaneously) and is called \\emph{general policy iteration}.\n\n\\paragraph{Value Iteration Algorithm}\nEquation \\ref{eq:bellman-v*} is applied repeatedly to converge directly on $V^*$:\n\\[\n    V_{i+1}(s) = \\max_{a\\in A} \\sum_{s' \\in S} P(s'\\mid s,a) [R(s,a,s') + \\gamma V_i(s')]\n\\]\nAnd $\\pi^*$ is obtained by being greedy to $V^*$, which is possible since we know the MDP. Q-Value iteration (with equation \\ref{eq:bellman-q*}) requires storing more values but is possible as well, and makes model-free approaches possible when the MDP is unknown (\\nameref{section:value-based} section).", "meta": {"hexsha": "9108d55eb4cfebdd30e7226fcddbe331b9f54fed", "size": 1659, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "sections/3_dp.tex", "max_stars_repo_name": "alexandrethm/rl-cheatseet", "max_stars_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-06-18T23:54:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T11:54:02.000Z", "max_issues_repo_path": "sections/3_dp.tex", "max_issues_repo_name": "alexandrethm/rl-cheatsheet", "max_issues_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "sections/3_dp.tex", "max_forks_repo_name": "alexandrethm/rl-cheatsheet", "max_forks_repo_head_hexsha": "1f1d1f51b66eb48981d07f991ebfef8f76292138", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 75.4090909091, "max_line_length": 455, "alphanum_fraction": 0.7215189873, "num_tokens": 474, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.92522995296862, "lm_q2_score": 0.8128673246376009, "lm_q1q2_score": 0.7520891965441755}}
{"text": "\n\\subsection{Introduction to forecasting}\n\nWe observe a series of observations:\n\n\\(x_1, x_2,...,x_t)\\)\n\nWhat can we say about \\(x_{t+1}\\)?\n\nIf the data was drawn iid then the past data then we would just want to identify moments.\n\nHowever if the data is not iid, for example because it is increasing in time, then this is not the best way.\n\n\\subsubsection{Regression formation}\n\nWe can model\n\n\\(x_t=\\alpha + \\epsilon_t \\)\n\n\n", "meta": {"hexsha": "ec29c4e13cfd01ee80eed3ffbf4d5e9d11fd5516", "size": 424, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/stochasticSampling/01-01-introduction.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/stochasticSampling/01-01-introduction.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/stochasticSampling/01-01-introduction.tex", "max_forks_repo_name": "adamdboult/nodeHomePage", "max_forks_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 20.1904761905, "max_line_length": 108, "alphanum_fraction": 0.7287735849, "num_tokens": 108, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9252299550303293, "lm_q2_score": 0.8128673110375457, "lm_q1q2_score": 0.7520891856368932}}
{"text": "\\section*{Exercises}\n\n\\begin{ex}\n  Find the (real or complex) eigenvalues and eigenvectors of the\n  following matrices. Diagonalize each matrix if possible.\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rr}\n      2 & 1 \\\\\n      -1 & 2 \\\\\n    \\end{mymatrix},\n    \\quad\n    B = \\begin{mymatrix}{rr}\n      -1 & -2 \\\\\n      1 &  1 \\\\\n    \\end{mymatrix},\n    \\quad\n    C = \\begin{mymatrix}{rrr}\n      2   & -1  &  3  \\\\\n      0   &  1  &  1  \\\\\n      -1  &  1  &  0  \\\\\n    \\end{mymatrix},\n    \\quad\n    D = \\begin{mymatrix}{rrr}\n      1  &  1 & 1 \\\\\n      -1 &  2 & 0 \\\\\n      1  & -1 & 1 \\\\\n    \\end{mymatrix}\n  \\end{equation*}\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item The characteristic polynomial is\n      $\\eigenvar^2 -4\\eigenvar + 5$, the eigenvalues are\n      $\\eigenvar_1 = 2+i$ and $\\eigenvar_2 = 2-i$, and the\n      corresponding basic eigenvectors are\n      $\\vect{v}_1 = \\mat{1, i\\,}^T$ and\n      $\\vect{v}_2 = \\mat{1, -i\\,}^T$, respectively. The matrix $A$ is\n      diagonalizable as $A=PDP^{-1}$, where\n      \\begin{equation*}\n        P = \\begin{mymatrix}{cc}\n          1 & 1 \\\\\n          i & -i \\\\\n        \\end{mymatrix}\n        \\quad\\mbox{and}\\quad\n        D = \\begin{mymatrix}{cc}\n          2+i & 0 \\\\\n          0 & 2-i \\\\\n        \\end{mymatrix}.\n      \\end{equation*}\n    \\item The characteristic polynomial is $\\eigenvar^2 + 1$, the\n      eigenvalues are $\\eigenvar_1=i$ and $\\eigenvar_2=-i$, and the\n      corresponding basic eigenvectors are\n      $\\vect{v}_1 = \\mat{1-i, -1}^T$ and\n      $\\vect{v}_2 = \\mat{1+i, -1}^T$, respectively. Therefore\n      $B=PDP^{-1}$, where\n      \\begin{equation*}\n        P = \\begin{mymatrix}{cc}\n          1-i & 1+i \\\\\n          -1 & -1 \\\\\n        \\end{mymatrix}\n        \\quad\\mbox{and}\\quad\n        D = \\begin{mymatrix}{cc}\n          i & 0 \\\\\n          0 & -i \\\\\n        \\end{mymatrix}.\n      \\end{equation*}\n    \\item The characteristic polynomial is\n      $x^2 -2x + 2 - (x^3 -2x^2 + 2x)$\n      $-\\eigenvar^3 - \\eigenvar^2 + 2 =\n      (1-\\eigenvar)(\\eigenvar^2-2\\eigenvar+2)$.  The eigenvalues are\n      $\\eigenvar_1 = 1$, $\\eigenvar_2 = 1+i$, and $\\eigenvar_3 =\n      1-i$. The corresponding basic eigenvectors are\n      $\\vect{v}_1 = \\mat{1, 1, 0}^T$,\n      $\\vect{v}_2 = \\mat{-1-2i, -i, 1}^T$,\n      and $\\vect{v}_2 = \\mat{1+2i, i, 1}^T$,\n      respectively. Therefore\n      $C=PDP^{-1}$, where\n      \\begin{equation*}\n        P = \\begin{mymatrix}{ccc}\n          1 & -1-2i & 1+2i \\\\\n          1 &  -i   &  i   \\\\\n          0 &   1   &  1   \\\\\n        \\end{mymatrix}\n        \\quad\\mbox{and}\\quad\n        D = \\begin{mymatrix}{ccc}\n          1 &  0  &  0  \\\\\n          0 & 1+i &  0  \\\\\n          0 &  0  & 1-i \\\\\n        \\end{mymatrix}.\n      \\end{equation*}\n    \\item The characteristic polynomial is\n      $-\\eigenvar^3+4\\eigenvar^2-5\\eigenvar+2 =\n      -(\\eigenvar-1)(\\eigenvar-1)(\\eigenvar-2)$. Therefore the\n      eigenvalues are $\\eigenvar=1$ with algebraic multiplicity 2 and\n      $\\eigenvar=2$ with algebraic multiplicity 1. The eigenspace for\n      $\\eigenvar=1$ is $1$-dimensional; it is spanned by\n      $\\mat{1,1,-1}^T$. Since the geometric multiplicity of the\n      eigenvalue $1$ is less than its algebraic multiplicity, the\n      matrix is not diagonalizable, not even over the complex numbers.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  I know a certain real $2\\times 2$-matrix $A$. My matrix has complex\n  eigenvalue $\\eigenvar=1+2i$ and corresponding eigenvector\n  $\\vect{v}=\\begin{mymatrix}{c}1\\\\i\\end{mymatrix}$.\n  \\begin{enumerate}\n  \\item Find another eigenvalue and corresponding eigenvector of $A$.\n  \\item Diagonalize $A$.\n  \\item What is the secret matrix $A$?\n  \\end{enumerate}\n\n  \\begin{sol}\n    \\begin{enumerate}\n    \\item By Proposition~\\ref{prop:conjugate-eigenvalues}, the other\n      eigenvalue is $1-2i$ with corresponding eigenvector\n      $\\begin{mymatrix}{c} 1 \\\\ -i \\end{mymatrix}$.\n    \\item From the eigenvalues and eigenvectors, we know that\n      $A=PDP^{-1}$, where\n      \\begin{equation*}\n        P = \\begin{mymatrix}{cc}\n          1 & 1 \\\\\n          i & -i\n        \\end{mymatrix}\n        \\quad\\mbox{and}\\quad\n        D = \\begin{mymatrix}{cc}\n          1+2i & 0 \\\\\n          0 & 1-2i\n        \\end{mymatrix}.\n      \\end{equation*}\n    \\item $A = PDP^{-1} = \\begin{mymatrix}{cc}\n        1 & 2 \\\\\n        -2 & 1 \\\\\n      \\end{mymatrix}$.\n    \\end{enumerate}\n  \\end{sol}\n\\end{ex}\n\n\\begin{ex}\n  Solve the recurrence\n    \\begin{equation*}\n    \\begin{array}{l@{~}c@{~}l}\n      a_0 &=& 0, \\\\\n      a_1 &=& 1, \\\\\n      a_{n+2} &=& 4a_{n+1} - 5a_n, \\quad\\mbox{for all $n\\geq 0$.} \\\\\n    \\end{array}\n  \\end{equation*}\n\\end{ex}\n", "meta": {"hexsha": "b6655b8c65bcd92ef9ec2134419d2debbe88876f", "size": 4628, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/exercises/Eigenvalues-Complex.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-Complex.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-Complex.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.0604026846, "max_line_length": 70, "alphanum_fraction": 0.5296024201, "num_tokens": 1759, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.841825655188238, "lm_q1q2_score": 0.7520107712552896}}
{"text": "\\section{Exercises in Conditional Probability}\\label{S:xsCondProb}\n\n\\begin{ExerciseList}\n\n\\Exercise\nWhat gives the greater probability of hitting some target at least\n  once: \n\\begin{enumerate}\n\\item  hitting in a shot with probability $\\frac{1}{2}$ and firing 1 shot, or \n\\item hitting in a shot with probability $\\frac{1}{3}$ and firing 2 shots?\n\\end{enumerate}\nFirst guess. Then calculate.\n\n\\Answer\nWe can assume  that the first shot is independent of\nthe second shot so we can multiply the probabilities here.\n\nFor case A, there is only one shot so the probability of hitting at least once is $\\frac{1}{2}$.\n\nFor case B, the probability of missing both shots is\n$\\frac{2}{3}\\,\\frac{2}{3}\\,=\\,\\frac{4}{9}$,  so  the probability hitting some target at least once is\n  \\[ 1- \\P(\\text{missing the target both times})\\;=\\; 1-\\frac{4}{9}\\;=\\;\\frac{5}{9}\\]\nTherefore, case B has the greater probability of hitting the target at least once.\n\n\\Exercise\nSuppose we independently roll two fair dice each of whose faces are marked by numbers\n  $\\sf 1$,$\\sf 2$,$\\sf 3$,$\\sf 4$, $\\sf 5$ and $\\sf 6$.\n\\begin{enumerate}\n\\item List the sample space for the experiment if we note the   numbers\n  on the 2 upturned faces.\n\\item What is the probability of obtaining a sum greater than 4 but less\n  than 7?\n\\end{enumerate}\n\n\\Answer\n\\be\n\\item The sample space is\n$$\n\\begin{aligned}\n\\{\n\\mathsf{(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),\\quad (2,1),(2,2),(2,3),(2,4),(2,5),(2,6),}\\\\\n\\mathsf{(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),\\quad (4,1),(4,2),(4,3),(4,4),(4,5),(4,6),}\\\\\n\\mathsf{(5,1),(5,2),(5,3),(5,4),(5,5),(5,6),\\quad (6,1),(6,2),(6,3),(6,4),(6,5),(6,6)}\n\\}\n\\end{aligned}\n$$\nNote: Order matters here. For example, the outcome ``16'' refers to a ``1'' on the first die and a ``6'' on the second,\nwhereas the outcome ``61'' refers to a ``6'' on the first die and a ``1'' on the\nsecond.\n\n\\item First tabulate all possible sums as follows:\n$$\n\\begin{array}{c|cccccc}\n+       &       1       &       2       &       3       &       4       &       5       &       6       \\\\\\hline\n1       &       2       &       3       &       4       &       \\mathbf{5}      &       \\mathbf{6}      &       7       \\\\\n2       &       3       &       4       &       \\mathbf{5}      &       \\mathbf{6}      &       7       &       8       \\\\\n3       &       4       &       \\mathbf{5}      &       \\mathbf{6}      &       7       &       8       &       9       \\\\\n4       &       \\mathbf{5}      &       \\mathbf{6}      &       7       &       8       &       9       &       10      \\\\\n5       &       \\mathbf{6}      &       7       &       8       &       9       &       10      &       11      \\\\\n6       &       7       &       8       &       9       &       10      &       11      &       12      \\\\\n\\end{array}$$\n Let $A$ be the event {\\em the sum is 5} and $B$ be the event {\\em\n    the sum is 6}, then $A$ and $B$ are mutually exclusive events with\n  probabilities \\[\\P(A) = \\frac{4}{36} \\quad \\text{and}\\quad \\P(B) =\n  \\frac{5}{36} \\,.\\]\nTherefore,\n   $$\\P(4<\\textrm{sum }<7)\\;=\\; \\P( A \\cup B) \\;=\\; \\P(A)\\,+\\,\\P(B)\\;=\\; \\frac{4}{36} +\n\\frac{5}{36} \\;=\\;\\frac{1}{4}$$\n\\ee\n\n\n\\Exercise\nBased on past experience, 70\\% of students in a certain course pass the midterm test.  \nThe final exam is passed by 80\\% of those who passed the midterm test, but only by 40\\% of those who fail the midterm test.  \nWhat fraction of students pass the final exam?\n\n\\Answer\nFirst draw a tree  with the first split based on the outcome of the midterm test and the second on the outcome of the final exam.  \nNote that the probabilities involved in this second branch are {\\em conditional} probabilities that depend on the outcome of the midterm test.  \nLet $A$ be the event that the student passes the final exam and let $B$ be the event that the student passes the midterm test.\n\n\\begin{center}\n\\begin{picture}(100,160)(75,30){\\drawline(0,90)(75,120)(125,140)\n\\drawline(75,120)(125,100)\\drawline(0,90)(75,60)(125,40)\n\\drawline(75,60)(125,80)\n\\put(55,125){$B$}\\put(55,50){$B^c$}\n\\put(130,140){$A$\\quad $\\P(A \\cap  B) = 0.56$}\\put(130,100){$A^c$ \\quad\n  $\\P(A^c\\cap B)= 0.14$}\n\\put(130,80){$A$ \\quad $\\P(A\\cap B^c) = 0.12$ }\\put(130,40){$A^c$ \\quad\n  $\\P(A^c\\cap B^c)= 0.18$}\n\\put(100,137){0.8}\\put(100,112){0.2}\n\\put(100,77){0.4}\\put(100,52){0.6}\n\\put(30,110){0.7}\\put(30,85){0.3}}\n\\put(40,165){Midterm}\n\\put(120,165){Final}\n\\end{picture}\n\\end{center}\n\nThen the probability of passing the final exam is:\n\\[ \\P(A)\\;=\\; 0.56\\,+\\,0.12\\;=\\;0.68\\,.\\]\n\nTo do this with formulae,  partitioning according to the midterm test\nresult  and using the multiplication rule, we get:\n\\begin{eqnarray*}\n\\P(A)&=& \\P(A\\cap B)+\\P(A\\cap B^c)\\\\\n&=& \\P(A|B)\\P(B)+\\P(A|B^c)\\P(B^c)\\\\\n&=& (0.8)(0.7)+(0.4)(0.3)\\;=\\;0.68\n\\end{eqnarray*}\n\n\\Exercise\nA small brewery has two bottling machines.  \nMachine 1 produces 75\\% of the bottles and machine 2 produces 25\\%.  \nOne out of every 20 bottles filled by machine 1 is rejected for some reason, while one out of every 30 bottles filled by machine 2 is rejected. \nWhat is the probability that a randomly selected bottle comes from machine 1 given that it is accepted?\n\\Answer\nLet $A$ be the event that bottles are produced by machine 1; and $A^c$ is the event that bottles are produced by machine 2. \n$R$ denotes the event that the bottles are rejected; and $R^c$ denotes the event that the bottles are accepted.  \nWe know the following probabilities:\n\n\\[ \\P(A) \\;=\\; 0.75 \\quad \\text{and} \\quad \\P(A^c) \\;=\\; 0.25\\]\n\\[ \\P(R | A) \\;=\\; \\frac{1}{20} \\quad \\text{and } \\quad  \\P(R^c | A) \\;=\\;\n\\frac{19}{20}\\]\n\n\\[ \\P(R | A^c) \\;=\\; \\frac{1}{30} \\quad \\text{and} \\quad  \\P(R^c | A^c) \\;=\\;\n\\frac{29}{30}\\]\n\nWe want $\\P(A|R^c)$ which is give by\n$$\\P(A|R^c)\\;=\\;\\frac{\\P(R^c\\cap A)}{\\P(R^c)}\\;=\\;\\frac{\\P(R^c\\cap A)}{\\P(R^c\\cap A)+\\P(R^c\\cap A^c)}$$\nwhere, $$\\P(R^c\\cap A)\\;=\\;\\P(R^c| A)\\P(A)\\;=\\;\\frac{19}{20}\\times0.75$$\nand, $$\\P(R^c\\cap A^c)\\;=\\;\\P(R^c|A^c)\\P(A^c)\\;=\\;\\frac{29}{30}\\times0.25$$\nTherefore,\n$$\\P(A|R^c)\\;=\\;\\frac{\\frac{19}{20}\\times0.75}{\\frac{19}{20}\\times\n  0.75+\\frac{29}{30}\\times0.25}\\;\\approxeq \\;0.747\\quad $$\\\\[6pt]\n\nThe  tree diagram for this problem is:\n\\begin{center}\n\\begin{picture}(100,140)(75,30){\\drawline(0,90)(75,120)(125,140)\n\\drawline(75,120)(125,100)\\drawline(0,90)(75,60)(125,40)\n\\drawline(75,60)(125,80)\n\\put(60,120){$A$}\n\\put(60,50){$A^c$}\n\\put(130,140){$\\mathsf{R}$}\n\\put(130,100){$\\mathsf{R^c}$ \\;\\;$\\P(A\\cap R^c)= 0.75\\times 19/20$}\n\\put(130,80){$\\mathsf{R}$}\n\\put(130,40){$\\mathsf{R^c}$ \\;\\;$\\P(A^c\\cap R^c)= 0.25\\times 29/30$}\n\\put(90,140){$1/20$}\\put(90,95){$19/20$}\n\\put(90,75){$1/30$}\\put(90,35){$29/30$}\n\\put(30,110){$0.75$}\\put(30,60){$0.25$}\n\\put(40,160){Machine 1}\n\\put(120,160){Rejection}\n}\n\\end{picture}\n\\end{center}\n\nSo the required probability is \n$$\\P(A|R^c)\\;=\\;\\frac{\\P(R^c\\cap A)}{\\P(R^c)}\\;=\\;\\frac{\\frac{19}{20}\\times0.75}{\\frac{19}{20}\\times\n  0.75+\\frac{29}{30}\\times0.25}\\;\\approxeq \\;0.747$$\n\n\\Exercise\nA process producing micro-chips, produces 5\\% defective, at random.  \nEach micro-chip is tested, and the test will correctly detect a defective one $4/5$ of the time, and if a good micro-chip is tested the test will declare it is defective with probability $1/10$.\n\\begin{itemize}\n \\item[(a)]If a micro-chip is chosen at random, and tested to be good, what was the probability that it was defective anyway?\n\\item[(b)]If a micro-chip is chosen at random, and tested to be defective, what was the probability that it was good anyway?\n\\item[(c)]If 2 micro-chips are tested and determined to be good, what is\n  the probability that at least one is in fact defective?\n\\end{itemize}\n\\Answer\nLet  the event that a micro-chip is defective be $D$, and the event  that the test  is correct be  $C$.  \nSo  the probability that the micro-chip is defective is $P(D)=0.05$, and the probability that it is effective is $P(D^c)=0.95$.\n\nThe probability that  the test correctly detects a defective micro-chip is the conditional probability $P(C|D)=0.8$, and the probability that if a good micro-chip is tested but the test declares it is defective is the conditional probability $P(C^c|D^c)=0.1$.  \nTherefore, we also have the probabilities $P(C^c|D)=0.2$, and $P(C|D^c)=0.9$.\n\nMoreover, the probability that a micro-chip is defective, and has been declared as defective is $$P(C\\cap D)\\;=\\;P(C|D)P(D)\\;=\\;0.8\\times0.05\\;=\\;0.04\\,.$$\nThe probability that a micro-chip is effective, and has been declared as effective is $$P(C\\cap D^c)\\;=\\;P(C|D^c)P(D^c)\\;=\\;0.9\\times0.95\\;=\\;0.855\\,.$$\nThe probability that a micro-chip is defective, and has been declared as effective is $$P(C^c\\cap D)\\;=\\;P(C^c|D)P(D)\\;=\\;0.2\\times 0.05=0.01\\,.$$\nThe probability that a micro-chip is effective, and has been declared as defective is $$P(C^c\\cap D^c)\\;=\\;P(C^c|D^c)P(D^c)\\;=\\;0.1\\times0.95\\;=\\;0.095\\,.$$\n\nThe tree diagram for  these events  and probabilities is:\n\\begin{center}\n\\begin{picture}(100,140)(75,30){\\drawline(0,90)(75,120)(125,140)\n\\drawline(75,120)(125,100)\\drawline(0,90)(75,60)(125,40)\n\\drawline(75,60)(125,80)\n\\put(60,120){$D$}\n\\put(60,50){$D^c$}\n\\put(130,140){$C$\\;\\;$P(C\\cap D)= 0.04$}\n\\put(130,100){$C^c$ \\;\\;$P(C^c\\cap D)=  0.01$}\n\\put(130,80){$C$\\;\\;$P(C\\cap D^c)= 0.855$}\n\\put(130,40){$C^c$ \\;\\;$P(C^c\\cap D^c)= 0.095$}\n\\put(90,140){$0.8$}\\put(90,95){$0.2$}\n\\put(90,75){$0.9$}\\put(90,35){$0.1$}\n\\put(30,110){$0.05$}\\put(30,60){$0.95$}\n\\put(40,160){ Defective}\n\\put(100,160){ Tested Correctly}\n}\n\\end{picture}\n\\end{center}\n\n\\begin{itemize}\n\\item[(a)]\nIf a micro-chip is tested to be good, it could be defective but tested incorrectly, or it could be effective and tested correctly. Therefore, the probability that the micro-chip is tested good, but it is actually defective is\n$$\\frac{P(C^c\\cap D)}{P(C^c\\cap D)+P(C\\cap D^c)}\\;=\\;\\frac{0.01}{0.01+0.855}\\;\\approxeq\\; 0.012$$\n\\item[(b)] \nSimilarly,  the probability that a micro-chip is  tested to be defective, but it was good is\n$$\\frac{P(C^c\\cap D^c)}{P(C\\cap D)\\;+\\;P(C^c\\cap\n  D^c)}=\\frac{0.095}{0.095+0.04} \\approxeq 0.704$$\n\\item[(c)]\nThe  probability that  both  the micro-chips are effective, and have been\ntested and determined to be good,  is\n\\[\\left(\\frac{P(C\\cap D^c)}{P(C^c\\cap D)+P(C\\cap D^c)}\\right)^2\\]\nand so  the probability that at least one is defective is:\n$$1\\;-\\;\\left(\\frac{P(C\\cap D^c)}{P(C^c\\cap D)+P(C\\cap\n    D^c)}\\right)^2\\;=\\;1-\\left(\\frac{0.855}{0.01+0.855 }\\right)^2\\;\\approxeq\\;0.023$$\n\\end{itemize}\n\n\n\\Exercise\nSuppose that $\\frac{2}{3}$  of all gales are  force 1, $\\frac{1}{4}$  are force 2 and $\\frac{1}{12}$  are force 3.  \nFurthermore, the probability that force 1 gales cause damage is\n$\\frac{1}{4}$,  the probability that force 2 gales cause damage is\n$\\frac{2}{3}$  and  the probability that force 3 gales cause damage is\n$\\frac{5}{6}$.\n\n\\begin{itemize}\n\\item[(a)]If a  gale is reported,  what is the probability of it causing damage?\n\\item[(b)] If the gale caused damage, find  the probabilities that it\n  was  of:  force 1;  force 2;  force 3.\n\\item[(c)] If the gale did  NOT cause damage, find  the probabilities\n  that it was of: force 1; force 2; force 3.\n\\end{itemize}\n\\Answer\n\\begin{itemize}\n\\item[(a)] Let $F1$ be the event a gale of force 1 occurs, let $F2$\nbe the event a gale of force 2 occurs and $F3$ be the event a gale\nof force 3 occurs.  Now we know that\n\\[ P(F1)\\; =\\; \\frac{2}{3}, \\quad  P(F2) \\;= \\;\\frac{1}{4},  \\quad P(F3) \\;= \\;\\frac{1}{12}\\,.\\]\nIf $D$ is the event that a gale causes damage, then we also know the\nfollowing conditional probabilities:\n\\[ P(D|F1) \\;= \\;\\frac{1}{4}, \\quad  P(D|F2) \\;=\\; \\frac{2}{3},  \\quad  P(D|F3)\\; = \\;\\frac{5}{6}\\,.\\]\nThe probability that a reported gale causes damage is\n\\[P(D)\\;=\\;P(D\\cap F1)\\;+\\;P(D\\cap F2)\\;+\\;P(D\\cap F3)\\]\nwhere\n\\[P(D\\cap F1)\\;=\\; P(D| F1)P(F1)\\;=\\;\\frac{1}{4} \\times \\frac{2}{3}\n\\;=\\; \\frac{1}{6}\\,, \\]\n\\[P(D\\cap F2)\\;=\\; P(D| F2)P(F2)\\;=\\;\\frac{2}{3} \\times \\frac{1}{4}\n\\;=\\; \\frac{1}{6}\\,, \\]\nand\n\\[P(D\\cap F3)\\;=\\; P(D| F3)P(F3)\\;=\\;\\frac{5}{6} \\times \\frac{1}{12}\n\\;=\\; \\frac{5}{72} \\,.\\]\nHence \\[P(D)\\;=\\;  \\frac{1}{6}\\,+\\,  \\frac{1}{6}\\,+\\,\\frac{5}{72}\\;=\\; \\frac{29}{72} \\]\n\n\\item[(b)] Knowing that the gale did cause damage we can calculate the probabilities that it was of the various forces using the probabilites in (a) as follows (Note: $P(D\\cap F1)= P(F1\\cap D)$ etc.):\n{$$P(F1|D)\\;=\\;\\frac{P(F1\\cap D)}{P(D)}\\;=\\;\\frac{1/6}{29/72}\\;=\\;\\frac{12}{29}$$\n$$P(F2|D)\\;=\\;\\frac{P(F2\\cap D)}{P(D)}\\;=\\;\\frac{1/6}{29/72}\\;=\\;\\frac{12}{29}$$\n$$P(F3|D)\\;=\\;\\frac{P(F3\\cap D)}{P(D)}\\;=\\;\\frac{5/72}{29/72}\\;=\\;\\frac{5}{29}$$\n}\n\n\\item[(c)]First note that the probability that a reported gale does NOT\n  cause damage is:\n\\[ P(D^c)\\;=\\; 1-P(D)\\;=\\; 1- \\frac{29}{72}\\;=\\; \\frac{43}{72}\\,.\\]\nNow we need to find probabilities like $P(F1\\cap D^c)$. The best way to\ndo this is to use the partitioning idea of the  ``Total Probability\nTheorem'', and write:\n\\[ P(F1) \\;=\\;  P(F1\\cap D^c) \\;+\\; P(F1\\cap D)\\,,\\]\nRearranging this gives\n\\[  P(F1\\cap D^c) \\;= \\;P(F1) \\;- \\; P(F1\\cap D) \\]\nand so\n\\[P(F1|D^c)\\;=\\;\\frac{P(F1\\cap D^c)}{P(D^c)}\\;=\\;\\frac{P(F1)-P(D\\cap\n  F1)}{P(D^c)}\\;=\\;\\frac{2/3-1/6}{43/72}\\;=\\;\\frac{36}{43}\\,.\n\\]\nSimilarly,\n\\[P(F2|D^c)\\;=\\;\\frac{P(F2\\cap D^c)}{P(D^c)}\\;=\\;\\frac{P(F2)-P(D\\cap F2)}{P(D^c)}\\;=\\;\\frac{1/4-1/6}{43/72}\\;=\\;\\frac{6}{43}\\,,\\]\nand\n\\[P(F3|D^c)\\;=\\;\\frac{P(F3\\cap D^c)}{P(D^c)}\\;=\\;\\frac{P(F3)-P(D\\cap F3)}{P(D^c)}\\;=\\;\\frac{1/12-5/72}{43/72}\\;=\\;\\frac{1}{43}\\,.\\]\n\n\\end{itemize}\n\\newpage\n\n\n\\Exercise\n{**}The sensitivity and specificity of a medical diagnostic test for a disease are defined as follows:\n\\begin{eqnarray*}\n\\text{sensitivity } &=& \\P \\left( \\text{ test is positive } | \\text{ patient has the disease } \\right) \\enspace ,\\\\\n\\text{specificity} &=& \\P \\left( \\text{ test is negative } | \\text{ patient does not have the disease } \\right) \\enspace .\n\\end{eqnarray*}\nSuppose that a medical test has a sensitivity of $0.7$ and a specificity of $0.95$.  \nIf the prevalence of the disease in the general populaiton is $1\\%$, find\n\\begin{itemize}\n\\item[(a)] the probability that a patient who tests positive actually has the disease,\n\\item[(b)] the probability that a patient who tests negative is free from the disease.\n\\end{itemize}\n\n\\Exercise\n{**}The detection rate and false alarm rate of an intrusion sensor are defined as\n\\begin{eqnarray*}\n\\text{detection rate} &=& \\P \\left( \\text{ detection declared } | \\text{ intrusion } \\right) \\enspace ,\\\\\n\\text{false alarm rate} &=& \\P \\left( \\text{ detection declared } | \\text{ no intrusion } \\right) \\enspace .\n\\end{eqnarray*}\nIf the detection rate is $0.999$ and the false alarm rate is $0.001$, and the probability of an intrusion occuring is $0.01$, find\n\\begin{itemize}\n\\item[(a)] the probability that there is an intrusion when a detection is declared,\n\\item[(b)] the probability that there is no intrusion when no detection is declared.\n\\end{itemize}\n\n\\Exercise\n{**}Let $A$ and $B$ be events such that $\\P(A) \\neq 0$ and $\\P(B) \\neq 0$.  \nWhen $A$ and $B$ are disjoint, are they also independent?  \nExplain clearly why or why not.\n\n\\end{ExerciseList}\n\n\n", "meta": {"hexsha": "517705356d516743b041c0f3b4af3fb814f3f8b4", "size": 15047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/csebook/ExsInConditionalProbability.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/ExsInConditionalProbability.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/ExsInConditionalProbability.tex", "max_forks_repo_name": "raazesh-sainudiin/computational-statistical-experiments", "max_forks_repo_head_hexsha": "edb33db9a05b32645e8337c03729c0b8d02fa728", "max_forks_repo_licenses": ["Unlicense"], "max_forks_count": 4, "max_forks_repo_forks_event_min_datetime": "2018-07-18T07:47:52.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-19T11:28:24.000Z", "avg_line_length": 47.9203821656, "max_line_length": 261, "alphanum_fraction": 0.6128796438, "num_tokens": 5769, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256313782276, "lm_q2_score": 0.8933094096048376, "lm_q1q2_score": 0.7520107577567042}}
{"text": "\\section{Informed Search}\n\n\\subsection{Heuristics}\n\n\\paragraph{Admissibility} An admissible heuristic never\noverestimates the cost to reach the goal, that is it is\noptimistic. A heuristic h is admissible if:\n\\begin{math}\n  \\forall\\medspace node \\medspace n, \\medspace h(n) \\leq h^*(n)\n\\end{math}\nwhere $h^*$ is true cost to reach the goal from $n$.\n\nIn a map, the air distance between two points is an admissible\nheuristic because it is by definition the shortest distance\nbetween the two points.\n\n\\paragraph{Consistency}\n\n\\begin{math}\nh(a) - h(b) \\leq cost(a to b)\n\\end{math}\n\nWhich implies:\n\\begin{math}\nh(a) \\leq cost(a to b) + h(b)\n\\end{math}\n\n\\begin{table}[hb!]\n\\begin{tabular}{lL}\n  Strategy & Implementation \\\\\n  Greedy search &\n  \\multicolumn{1}{p{0.65\\linewidth}}{\n    Expands the node that appears to be closest to goal\n  } \\\\\n  $A^*$ &\n  \\multicolumn{1}{p{0.65\\linewidth}}{\n    Minimize the total estimated solution cost ($f$), that is\n    the cost to reach node $n$ ($g$), and the cost to\n    get from $n$ to the goal ($h$)\n  }\n\\end{tabular}\n\\caption{Informed Search Strategies}\n\\label{tab:informed_search_strategies}\n\\end{table}\n\n\\subsection{A*}\n\n\\begin{itemize}\n  \\item Complete\n  \\item Time: exponential\n  \\item Space: keeps every node in memory\n\\end{itemize}\n\n\n\\subsection{A* optimality}\n\nIf the heuristic function used by A* is admissible, then A* is admissible. \n\n\\paragraph{Sketch of proof} When A* terminates its search, \nit has found a path from start to goal whose actual cost is \nlower than the estimated cost of\nany path from start to goal through any open node (the node's\n$f$ value). \nWhen the heuristic is admissible, those estimates are\noptimistic (not quite—see the next paragraph), so $A^{*}$ can\nsafely ignore those nodes because they cannot possibly lead\nto a cheaper solution than the one it already has. \nIn other words, $A^{*}$ will never overlook the\npossibility of a lower-cost path from start to goal and so it\nwill continue to search until no such possibilities exist.\n\nThe actual proof is a bit more involved because the\n$f$ values of open nodes are not guaranteed to\nbe optimistic even if the heuristic is admissible. This is\nbecause the $g$ values of open nodes are not guaranteed to be\noptimal, so the sum $g+h$ is not guaranteed to be optimistic.\n\n", "meta": {"hexsha": "0f78543eaf99b394ab7d7fea39f475e9b824dfd4", "size": 2292, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/informed_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/informed_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/informed_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": 29.3846153846, "max_line_length": 75, "alphanum_fraction": 0.7342931937, "num_tokens": 642, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8376199694135332, "lm_q1q2_score": 0.7519274985324982}}
{"text": "\\section*{Introduction}\n\nThe problem of learning smooth functions is a key problem in machine learning, as many problems\nare framed as finding continuous solutions to problems with only a small number of data points.\nThis smoothness is often not guaranteed, and is enforced through regularization of the output,\nusually using something like $L_2$ loss or temporal consistency~\\cite{tretschk2021nonrigid}. Since\nthe consistency is usually imposed as some weighted loss, it is not a guaranteed property of the\nnetwork. This leads to difficulties in interpolation between time-steps, which can be used to\nexaggerate motion, or predict intermediate time steps. In addition, there is also the\npossibility for sudden changes in motion.\nNotably, we are interested in constructing functions with $C^0$ continuity. That is, the\nfunction must be continuous on some domain. We are also to some extent interested in $C^1$\ncontinuity, or the derivative of a function is continuous on some domain, which often is\nreflected in the realism of motion by enforcing smooth velocity changes.\n\nWe examine the specific problem of predicting movement for dynamic scenes using NeRF. For this,\nwe define some static configuration, which is referred to as the canonical scene. From this, we\nmarch rays into the scene, warping them in order to deform the rendered view, which is\nessentially a perspective shift from moving objects in the scene. This is layered on top of the\noriginal NeRF model in order to reconstruct movement from a fixed set of views. This simple\nformulation is highly effective at reconstructing lambertian scenes with continuous movement as\ndescribed in D-NeRF~\\cite{pumarola2020dnerf} and NR(non-rigid)-NeRF~\\cite{tretschk2021nonrigid}. These works show convincing\nreconstructions of dynamic movement in scenes, predicting accurate reconstructions on both real\nand synthetic scenes. If we are satisfied with pure reconstruction these methods suffice, but we\nare also interested in performing operations on movement, such as interpolating between frames,\nexaggerating it, or classifying regions of movement. These methods demonstrate capability to\nperform well on certain tasks such as motion interpolation, but require specific optimizations\nin order to demonstrate improvements. In contrast, we examine classical animation tools in order\nto better handle movement.\n\nIn animation, there are many existing tools for creating smooth movement with a high-degree of\ncontrol for artists and animators. For example, there are tools such as keyframing, splines,\nand other techniques. These tools allow artists and animators to breathe life into animation,\nwith a high degree of control. Mathematical constructs such as splines have also been thoroughly\nstudied to understand their behaviour, as well as how they can be manipulated. These tools are\nclearly powerful enough to represent most movement, but have not been leveraged in machine\nlearning for this purpose.\n\nWe blend these existing tools in order to apply a prior on movement in Dynamic NeRF, finding that we are able to get a slight increase in performance without additional cost. In addition, we propose a new architecture for long duration $C^0$-continuous signal reconstruction. In summary, our contributions are as follows:\n\n\\begin{enumerate}\n    \\item A formulation of a prior on top of existing D-NeRF, which enforces smoothness of movement, a canonical basis, and an analytic form at no additional cost, while slightly outperforming the original.\n    \\item An evaluation of our architecture against D-NeRF which demonstrates its performance.\n    \\item A general architecture for reconstructing long, continuous signals, which guarantees smoothness. This architecture can be used to reconstruct long, dynamic sequences, but is more general and can be applied broadly to smooth signal reconstruction.\n\\end{enumerate}\n", "meta": {"hexsha": "c03c26308b9d1ec5fad5b00bb9ea6081b913fda5", "size": 3872, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "c0_paper/intro.tex", "max_stars_repo_name": "princeton-computational-imaging/nerf_atlas", "max_stars_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 14, "max_stars_repo_stars_event_min_datetime": "2021-05-17T13:17:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:44:44.000Z", "max_issues_repo_path": "c0_paper/intro.tex", "max_issues_repo_name": "princeton-computational-imaging/nerf_atlas", "max_issues_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-09-07T08:31:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-28T06:55:40.000Z", "max_forks_repo_path": "c0_paper/intro.tex", "max_forks_repo_name": "princeton-computational-imaging/nerf_atlas", "max_forks_repo_head_hexsha": "f66ba284ea440cd816b303cdb7312288901da97e", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 7, "max_forks_repo_forks_event_min_datetime": "2021-05-16T01:06:03.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-26T01:48:09.000Z", "avg_line_length": 84.1739130435, "max_line_length": 321, "alphanum_fraction": 0.8184400826, "num_tokens": 796, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952975813453, "lm_q2_score": 0.8376199572530449, "lm_q1q2_score": 0.7519274967863459}}
{"text": "\\chapter{Arithmetic}\n\n\n\\section{Big Number}\n\\rih{Plus One.} Given a non-negative number represented as an array of digits, plus one to the number.\n\\begin{python}\ndef plusOne(self, digits):\n    for i in xrange(len(digits)-1, -1, -1):\n        digits[i] += 1\n        if digits[i] < 10:\n            return digits\n        else:\n            digits[i] -= 10\n\n    # if not return within the loop \n    digits.insert(0, 1)\n    return digits\n\\end{python}\n\n\\section{Polish Notations}\nPolish Notation is in-fix while Reverse Polish Notation is post-fix. \n\nReverse Polish notation (RPN) is a mathematical notation in which every operator follows all of its operands (i.e. operands are followed by operators). RPN should be treated as the orthogonal expression.  \n\nPolish notation (PN) is a mathematical notation in which every operator is followed by its operands. \n\n\\subsection{Convert in-fix to post-fix (RPN)}\n\\pyinline{ret} stores the final result of reverse polish notation. \\pyinline{stk} stores\nthe temporary result in strictly increasing order. \n\nIn-fix\n\\begin{python}\n5 + ((1 + 2) * 4) - 3\n\\end{python}\n\ncan be written as\n\\begin{python}\n5 1 2 + 4 * + 3 - \n\\end{python}\nCore clues:\n\\begin{enumerate}\n\\item \\rih{Stack}. The stack temporarily stores the operators of \\textit{strictly increasing precedence order}.\n\\item \\rih{Precedence}. Digits have the highest precedence, followed by \\pyinline{*, /, +, (}. Notice that \\pyinline{(} operator itself has the \\textit{lowest} precedence.\n\\item \\rih{Bracket}. \\textit{Match} the brackets. \n\\end{enumerate}\nCode:\n\\begin{python}\ndef infix2postfix(self, lst):\n  stk = []\n  ret = []  # post fix result\n  for elt in lst:\n    if elt.isdigit():\n      ret.append(elt)\n    elif elt == \"(\":\n      stk.append(elt)\n    elif elt == \")\":\n      while stk and stk[-1] != \"(\":\n        ret.append(stk.pop())\n      stk.pop()  # pop \"(\"\n    else:\n      while stk and precdn(elt) <= precdn(stk[-1]):\n        ret.append(stk.pop())\n      stk.append(elt)\n\n  while stk:  # clean up \n    ret.append(stk.pop())\n\n  return ret\n\\end{python}\n\n\\subsection{Evaluate post-fix expressions}\\label{section:evaluationPostFix}\nConsider: \n\nIn-fix\n\\begin{python}\n5 + ((1 + 2) * 4) - 3\n\\end{python}\n\nPost-fix\n\\begin{python}\n5 1 2 + 4 * + 3 - \n\\end{python}\nStraightforward: use a \\textit{stack} to store the number. Iterate the input, push\nstack when hit numbers, pop stack when hit operators.\n\n\\subsection{Convert in-fix to pre-fix (PN)}\nPN is the \\textit{reverse} of RPN, thus, scan the expression from right to left; and \\pyinline{stk} stores the temporary result in non-decreasing order. \n\n\nIn-fix\n\\begin{python}\n5 + ((1 + 2) * 4) - 3\n\\end{python}\n\ncan be written as\n\\begin{python}\n3 4 2 1 + * 5 + -\n\\end{python}\n\nreverse as \n\\begin{python}\n- + 5 * + 1 2 4 3\n\\end{python}\n\n\\begin{python}\n  def infix2prefix(self, lst):\n    \"\"\"starting from right the left\"\"\"\n    stk = []\n    pre = []\n    for elt in reversed(lst):\n      if elt.isdigit():\n        pre.append(elt)\n      elif elt == \")\":\n        stk.append(elt)\n      elif elt == \"(\":\n        while stk and stk[-1] != \")\":\n          pre.append(stk.pop())\n        stk.pop()\n      else:\n        # < rather than <=\n        while stk and precdn(elt) < precdn(stk[-1]):  \n          pre.append(stk.pop())\n        stk.append(elt)\n\n    while stk:\n      pre.append(stk.pop())\n\n    pre.reverse()\n    return pre\n\\end{python}\n\n\n\\subsection{Evaluate pre-fix (PN) expressions}\nConsider: \n\nIn-fix\n\\begin{python}\n5 + ((1 + 2) * 4) - 3\n\\end{python}\n\nPre-fix\n\\begin{python}\n- + 5 * + 1 2 4 3\n\\end{python}\n\nreverse as \n\\begin{python}\n3 4 2 1 + * 5 + -\n\\end{python}\nPut into \\textit{stack}, similar to evaluating post-fix \\ref{section:evaluationPostFix}, but pay attention to operands order, which should be reversed when hitting a operator. \n", "meta": {"hexsha": "3c4e8c9c936fdfb66909b48d5e811321d40b56db", "size": 3770, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapterArithmetic.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": "chapterArithmetic.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": "chapterArithmetic.tex", "max_forks_repo_name": "li77leprince/Algo-Quicksheet", "max_forks_repo_head_hexsha": "1736bc0ee1d73b0b06dcf3823a65ea0f8c286108", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 24.9668874172, "max_line_length": 205, "alphanum_fraction": 0.6453580902, "num_tokens": 1105, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9046505325302034, "lm_q2_score": 0.8311430394931456, "lm_q1q2_score": 0.7518939932862461}}
{"text": "\\documentclass[12pt]{matlatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Quadratic convergence of Newton-Raphson iterations}\n\nThis is a simple example that uses the Matlab Symbolic Toolbox to demonstrate the quadratic converegnce of Newton-Raphson iterations to the exact root of a non-linear equation.\n\n\\begin{matlab}\n   syms x f(x) df(x) Step(x)\n\n   f(x)    = x-exp(-x);\n   df(x)   = diff(f,x);\n   Step(x) = x- f(x)/df(x);\n\n   digits(200);\n\n   x_new = vpa (1/2);\n   f_new = vpa (f(x_new));\n\n   % matBeg (table)\n\n   fprintf ('\\\\RuleA %2d & % .25f & % .10e &\\\\\\\\\\n',[0,x_new,f_new]);\n\n   for n = 1:6\n      x_old = x_new;\n      x_new = vpa (Step(x_new));\n      f_old = vpa (f(x_old));\n      f_new = vpa (f(x_new));\n      ratio = vpa (f_new / f_old^2);\n      fprintf ('\\\\RuleA %2d & % .25f & % .10e & % .5f\\\\\\\\\\n',[n,x_new,f_new,ratio]);\n   end\n\n   % matEnd (table)\n\\end{matlab}\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\\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$&$\\epsilon_{n} = x_{n} - e^{-x_{n}}$&$\\epsilon_{n}/\\epsilon_{n-1}^2$\\\\\n      \\noalign{\\hrule height 0.5pt}\n      \\mat{table}\n      \\noalign{\\hrule height 1pt}\n   \\end{tabular}\n\\end{center}\n\n\\vspace{20pt}\n\n\\begin{latex}\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$&$\\epsilon_{n} = x_{n} - e^{-x_{n}}$&$\\epsilon_{n}/\\epsilon_{n-1}^2$\\\\\n         \\noalign{\\hrule height 0.5pt}\n         \\mat{table}\n         \\noalign{\\hrule height 1pt}\n      \\end{tabular}\n   \\end{center}\n\\end{latex}\n\n\\end{document}\n", "meta": {"hexsha": "d016b8c451ef22b51cdd2d08122e3af0a91cbfea", "size": 2658, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "matlab/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": "matlab/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": "matlab/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": 30.5517241379, "max_line_length": 330, "alphanum_fraction": 0.6309255079, "num_tokens": 924, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588023318195, "lm_q2_score": 0.8459424411924673, "lm_q1q2_score": 0.7518387908758729}}
{"text": "\\section*{Chapter 4: Euclid's Algorithm}\n\n\\paragraph{Exercise 4.3}\nProve that $\\KthRoot{3}{16} + \\KthRoot{3}{54} = \\KthRoot{3}{250}$\n\n\\begin{proof}\n$16 = 2^4$, $54 = 2 \\cdot 3^3$ and $250 = 2 \\cdot 5^3$. Then,\n\\begin{eqnarray*}\n\\KthRoot{3}{16} + \\KthRoot{3}{54} &=& \\KthRoot{3}{2^4} +\n                                      \\KthRoot{3}{2 \\cdot 3^3} \\\\\n                                  &=& 2 \\KthRoot{3}{2} + 3 \\KthRoot{3}{2} \\\\\n                                  &=& 5 \\KthRoot{3}{2} \\\\\n                                  &=& \\KthRoot{3}{5^3} \\cdot \\KthRoot{3}{2} \\\\\n                                  &=& \\KthRoot{3}{2 \\cdot 5^3} \\\\\n                                  &=& \\KthRoot{3}{250}\n\\end{eqnarray*}\n\\end{proof}\n\n\\paragraph{Exercise 4.4}\nProve that, for any odd square number $x$, there is an even square number $y$\nsuch that $x+y$ is a square number.\n\n\\begin{proof}\nSince $x$ is square and odd, there must be an $n \\in \\Nat$ such that\n$x = (2n+1)^2$. Let $y$ be some even square number. Thus, there must be an\n$m \\in \\Nat$ such that $y = (2m)^2$. It follows that\n\\begin{eqnarray*}\nx+y &=& (2n+1)^2 + (2m)^2 \\\\\n    &=& 4(n^2 + m^2) + 4n + 1 \n\\end{eqnarray*}\nWe must define $m$ as a function of $n$ in such a way that this number conforms\na square. In order to do this, let's see what happens for some small cases:\n\\begin{itemize}\n    \\item If $n = 1$, then $x = 9$. If we set $m = 2$, $y = 16$ and $x+y = 25$,\n    which is a square.\n    \\item If $n = 2$, then $x = 25$. Taking $m = 6$, $y = 144$ and $x+y = 169$,\n    which is a square (since $13^2 = 169$).\n    \\item If $n = 3$, then $x = 49$. Now, $m$ can be $12$, and then $y = 576$\n    and $x+y = 625 = 25^2$.\n\\end{itemize}\nA careful analysis of these cases reveals a pattern: $m = n^2 + n$. Substituting\nthis in the equation shown before,\n\\begin{eqnarray*}\nx+y &=& 4(n^2 + m^2) + 4n + 1  \\\\\n    &=& 4(n^2 + (n^2 + n)^2) + 4n + 1 \\\\\n    &=& 4n^2 + 4(n^2 + n)^2 + 4n + 1 \\\\\n    &=& 4(n^2 + n)^2 + 4(n^2 + n) + 1 \\\\\n    &=& (2(n^2 + n) + 1)^2 \\\\\n\\end{eqnarray*}\n\\end{proof}\n\n\n\\newsavebox\\sqpython\n\\begin{lrbox}{\\sqpython}\n    \\begin{minipage}[t]{3in}\n         \\vspace{4px}\n         \\begin{verbatim}\ndef find_squares(x, y):\n    x1, x2 = x\n    y1, y2 = y\n    n = (x1**2 + x2**2)*(y1**2 + y2**2)\n    return [(i,j) for i in xrange(n)\n                  for j in xrange(i,n)\n                  if n == i**2 + j**2]\n         \\end{verbatim}\n    \\end{minipage}\n\\end{lrbox}\n\n\\paragraph{Exercise 4.5}\nProve that, if $x$ and $y$ are both sums of two squares, then so is their\nproduct $xy$.\n\n\\begin{proof}\nBeing $x$ and $y$ both sums of two squares, we can write them like so:\n\\begin{eqnarray*}\n    x &=& x_1^2 + x_2^2 \\\\\n    y &=& y_1^2 + y_2^2\n\\end{eqnarray*}\nThis implies that\n\\begin{eqnarray*}\n    xy &=& (x_1^2 + x_2^2) \\, (y_1^2 + y_2^2)  \\\\\n       &=& x_1^2 y_1^2 + x_1^2 y_2^2 + x_2^2 y_1^2 + x_2^2 y_2^2\n\\end{eqnarray*}\nAfter several failed attempts at completing the squares (i.e., adding and\nsubtracting the same thing), the following Python\nscript was used to gain some insight into the underlying pattern of $xy$:\n    \\begin{center}\n    \\framebox[8.5cm]{\n    \\usebox\\sqpython}\n    \\end{center}\nFor example, \n\\begin{itemize}\n    \\item \\texttt{find\\_squares((2,3), (5,7))} $\\rightarrow$ \\texttt{[(1, 31), (11, 29)]}.\n    \\item \\texttt{find\\_squares((1,2), (3,4))} $\\rightarrow$ \\texttt{[(2, 11), (5, 10)]}.\n\\end{itemize}\nPlaying with this script and guessing how to combine the elements in the input\ntuples in order to generate an output tuple $(z_1, z_2)$, the following\npattern emerged: \n\\begin{eqnarray*}\n    z_1 &=& x_2 y_1 + x_1 y_2  \\\\\n    z_2 &=& x_2 y_2 - x_1 y_1\n\\end{eqnarray*}\nIndeed,\n\\begin{eqnarray*}\n    z_1^2 + z_2^2 &=& (x_2 y_1 + x_1 y_2)^2 + (x_2 y_2 - x_1 y_1)^2  \\\\\n                  &=& ((x_2 y_1)^2 + (x_1 y_2)^2 + 2 x_2 y_1 x_1 y_2)\n                      + ((x_2 y_2)^2 + (x_1 y_1)^2 - 2 x_2 y_2 x_1 y_1) \\\\\n                  &=& x_2^2 y_1^2 + x_1^2 y_2^2 + x_2^2 y_2^2 + x_1^2 y_1^2 \\\\\n                  &=& x_1^2 y_1^2 + x_1^2 y_2^2 + x_2^2 y_1^2 + x_2^2 y_2^2 \\\\\n                  &=& xy\n\\end{eqnarray*}\n\n\\end{proof}\n", "meta": {"hexsha": "1dfdd4a23359877de4dbd16d1019cdb3e7acb850", "size": 4093, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "math/src/chapter4.tex", "max_stars_repo_name": "lukius/fmtgp", "max_stars_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 6, "max_stars_repo_stars_event_min_datetime": "2017-10-12T17:40:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-23T03:00:43.000Z", "max_issues_repo_path": "math/src/chapter4.tex", "max_issues_repo_name": "lukius/fmtgp", "max_issues_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "math/src/chapter4.tex", "max_forks_repo_name": "lukius/fmtgp", "max_forks_repo_head_hexsha": "4809c0b430fa05a2676db5750e502b112941d6d7", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2020-05-15T07:07:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-29T14:01:30.000Z", "avg_line_length": 35.9035087719, "max_line_length": 90, "alphanum_fraction": 0.535792817, "num_tokens": 1687, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887587875995483, "lm_q2_score": 0.8459424353665381, "lm_q1q2_score": 0.7518387732353736}}
{"text": "%\n% Chapter 4.5\n%\n\n\\section*{4.5 Substitution Rule}\n\n\\subsection*{Substitution Rule for Indefinite Integrals}\n\nIf \\(u=g(x)\\) is a differentiable function whose range is an interval \\(I\\) and \\(f\\) is continuous on \\(I\\), then\n$$ \\int f(g(x))g'(x)dx = \\int f(u)du $$ \n\n\\subsection*{Substitution Rule for Definite Integrals}\n\nIf \\(g'\\) is continuous on \\([a, b]\\) and \\(f\\) is continuous on the range of \\(u=g(x)\\), then \n$$ \\int_a^b f(g(x))g'(x)dx=\\int_{g(a)}^{g(b)}f(u)du $$\n\n\\subsection*{Integrals of Symmetric Functions}\n\nSuppose \\(f\\) is continuous on \\([-a, a]\\).\n$$ \\text{If } f \\text{ is even } [f(-x)=f(x)] \\text{, then } \\int_{-a}^a f(x)dx = 2 \\int_{0}^{a} f(x)dx. $$\n$$ \\text{If } f \\text{ is odd } [f(-x)=-f(x)] \\text{, then } \\int_{-a}^a f(x)dx = 0. $$\n", "meta": {"hexsha": "cd37be75b08fb51f09f1ae285eb2241b1542a643", "size": 764, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/4-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/4-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/4-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": 34.7272727273, "max_line_length": 114, "alphanum_fraction": 0.5916230366, "num_tokens": 295, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8519527944504227, "lm_q1q2_score": 0.7517868867268283}}
{"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{5^n \\ln 5}{5^n-1}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution 1}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\frac{5^n \\ln 5}{5^n-1} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{5^n \\ln 5 \\ln 5}{5^n \\ln 5} \\quad\\text{by L'Hopital} \\\\\r\n&= \\lim_{n \\to \\infty} \\frac{\\ln 5}{1} \\quad\\text{by algebra cancellation} \\\\\r\n& = \\ln 5\r\n\\end{align*}\r\nso the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{5^n \\ln 5}{5^n-1}$ diverges by the Test for Divergence.\r\n\r\n\\subsection*{Solution 2}\r\n\r\nThe function $f(x)=\\frac{5^x \\ln 5}{5^x-1}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\nWe first find the indefinite integral by substitution $u=5^x-1$ so $du = 5^x \\ln 5\\,dx$:\r\n\\begin{align*}\r\n\\int \\frac{5^x \\ln 5}{5^x-1}\\,dx\r\n&= \\int \\frac1u\\,du\\\\\r\n&= \\ln |u|+C\\\\\r\n&= \\ln |5^x-1|+C.\r\n\\end{align*}\r\n\r\nSo, going to our definite (improper) integral,\r\n\\begin{align*}\r\n\\int_1^\\infty  \\frac{5^x \\ln 5}{5^x-1}\\,dx\r\n&= \\lim_{t \\to \\infty} \\int_1^t  \\frac{5^x \\ln 5}{5^x-1}\\,dx\\\\\r\n&= \\lim_{t \\to \\infty} ( \\ln |5^t-1| - \\ln |5^1-1| )\\\\\r\n&= \\infty.\r\n\\end{align*}\r\nSince the integral $\\displaystyle \\int_1^\\infty \\frac{5^x \\ln 5}{5^x-1}\\,dx$ diverges, the  series  $\\displaystyle \\sum_{n=1}^\\infty \\frac{5^n \\ln 5}{5^n-1}$ diverges by the Integral 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\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": "f71967da377e2a59204a4da5e51786e94cc82024", "size": 2026, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/j3.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/j3.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/j3.tex", "max_forks_repo_name": "edward-kim-math/edward-d-kim.github.io", "max_forks_repo_head_hexsha": "db677132d89eb95dc5749dceeb9544c77b6b4a05", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-12-25T18:51:52.000Z", "max_forks_repo_forks_event_max_datetime": "2017-06-25T22:14:59.000Z", "avg_line_length": 32.1587301587, "max_line_length": 189, "alphanum_fraction": 0.6130306022, "num_tokens": 818, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357494949105, "lm_q2_score": 0.8670357649558006, "lm_q1q2_score": 0.7517510043073456}}
{"text": "\\section{CW-complexes and cellular homology}\nRecall:\n\\begin{definition}\nA \\emph{CW-complex} is a space $X$ with a sequence of subspaces $\\emptyset=X_{-1}\\subseteq X_0\\subseteq X_1\\subseteq\\cdots\\subseteq X$ (could be an infinite sequence) such that for all $n$, there is a map $f:\\coprod_{\\alpha\\in A_n}S^{n-1}_\\alpha\\to X_{n-1}$ (called the \\emph{attaching map}), such that there is a pushout diagram like this:\n\\begin{equation*}\n\\xymatrix{\\coprod_{\\alpha\\in A_n}S^{n-1}_\\alpha\\ar[r]^f\\ar@{^(->}[d]_i & X_{n-1}\\ar[d]\\\\\n\\coprod_{\\alpha\\in A_n}D^n_\\alpha\\ar[r] & X_{n}}\n\\end{equation*}\nAnd $X=\\bigcup X_n$, topologically (i.e. $A\\subseteq X$ is open if and only if $A\\cap X_n$ is open for all $n$). Often, $X_n$ is written $\\mathrm{Sk}_n(X)$, and is called the $n$-skeleton of $X$.\n\\end{definition}\n\\begin{remark}\nThis means that if you ignore the topology, i.e., as sets: $X=\\coprod_{n\\geq 0}\\left(\\coprod_{\\alpha\\in A_n}\\mathrm{Int}(D^n_\\alpha)\\right)$ where $\\mathrm{Int}(D^n)=\\{x\\in D^n: |x|<1\\}$ (the interior of $D^n$), so that $\\mathrm{Int}(D^0)=D^0=\\ast$. The $\\mathrm{Int}(D^n_\\alpha)$ are called ``open $n$-cells''. Note that the open $n$-cells are not generally open in the topology on $X$.\n\\end{remark}\n\\begin{example}\nThe $n$-sphere $S^n$. Let $\\mathrm{Sk}_0(S^n)=\\ast=\\mathrm{Sk}_1(S^n)=\\cdots=\\mathrm{Sk}_{n-1}(S^n)\\subseteq \\mathrm{Sk}_n(S^n)=S^n$. We attach it by using the pushout:\n\\begin{equation*}\n\\xymatrix{S^{n-1}\\ar[d]\\ar[r] & \\ast\\ar@{^(->}[d]\\\\\nD^n\\ar[r] & S^n}\n\\end{equation*}\nHere's another CW-structure. Let $\\mathrm{Sk}_0(S^n)=S^0=S^n\\cap \\mathbf{R}^1\\langle \\mathbf{e}_1\\rangle$, $\\mathrm{Sk}_1(S^n)=S^{1}=S^n\\cap\\mathbf\\mathbf{R}\\langle \\mathbf{e}_1,\\mathbf{e}_2\\rangle$, $\\mathrm{Sk}_2(S^n)=S^2=S^n\\cap\\mathbf{R}\\langle \\mathbf{e}_1,\\mathbf{e}_2,\\mathbf{e}_3\\rangle$, etc. until $\\mathrm{Sk}_n(S^n)=S^n$. I have to give maps $u,\\ell:D^k\\to S^k$ so that you have a pushout:\n\\begin{equation*}\n\\xymatrix{D^k\\ar[r] & S^k\\\\\nS^{k-1}\\ar@{^(->}[u]\\ar@{=}[r] & \\mathrm{Sk}_k(S^n)\\ar@{^(->}[u]}\n\\end{equation*}\nLet $u(x)=(x,\\sqrt{1-|x|^2})$ and $\\ell(x)(x,-\\sqrt{1-|x|^2})$ where $x\\in D^k$. Clearly $u,\\ell$ take values in $S^k$.\n\\end{example}\nThere's another definition I have to make.\n\\begin{definition}\nLet $X$ be a CW-complex. A subcomplex of $X$ is a subspace $Y\\subseteq X$ such that $\\emptyset\\subseteq Y\\cap X_0\\subseteq Y\\cap X_1\\subseteq\\cdots\\subseteq Y\\cap X_k\\subseteq \\cdots\\subseteq Y$ is a CW-structure on $Y$.\n\\end{definition}\n\\begin{example}\n$X_n\\subseteq X$ is a subcomplex of a CW-complex $X$. It's not that hard to see why. In particular, $S^0\\subseteq S^1\\subseteq S^2\\subseteq\\cdots\\subseteq \\bigcup_{n\\geq 1}S^n=:S^\\infty$. This of finite type, but isn't finite-dimensional.\n\\end{example}\n\\begin{lemma}\n$S^\\infty$ is contractible.\n\\end{lemma}\n\\begin{proof}\n$S^0$ itself is not contractible, but attaching two $1$-cells makes this contractible. Similarly, $S^1$ isn't contractible, but attaching two $2$-cells makes this contractible. This is the idea. You have $S^{k-1}\\times I\\to S^k$ by $(x,t)\\mapsto u(tx+(1-t)\\mathbf{e}_1)$ where $u$ is the map we defined above. Therefore we get a map $S^\\infty\\times I\\to S^\\infty$ that's a contracting homotopy.\n\\end{proof}\n\\begin{example}\nRecall $\\mathbf{RP}^n=S^n/\\sim$ where $x\\sim -x$. There's a map from $S^n\\to\\mathbf{RP}^n$ that's a double cover. Let me propose a CW-decomposition. We have:\n\\begin{equation*}\n\\xymatrix{\\cdots\\ar@{^(->}[r] & S^{k-1}\\ar@{^(->}[r]\\ar[d] & S^k\\ar[d]\\ar[r] & \\cdots\\ar[r] & S^n\\ar[d]\\\\\n\\cdots\\ar@{^(->}[r] & \\mathbf{RP}^{k-1}\\ar@{^(->}[r] & \\mathbf{RP}^k\\ar@{^(->}[r] & \\cdots\\ar@{^(->}[r] & \\mathbf{RP}^n}\n\\end{equation*}\nWe claim that this is a CW-decomposition. We have a double cover $S^1\\to\\mathbf{RP}^1=S^1$. The maps $S^{k-1}\\to\\mathbf{RP}^{k-1}$ are not degree $2$ maps -- they're different spaces! If we use the double cover $S^{k-1}\\to\\mathbf{RP}^{k-1}$, then we claim that there is a pushout:\n\\begin{equation*}\n\\xymatrix{\\mathbf{RP}^{k-1}\\ar@{^(->}[r]& \\mathbf{RP}^k\\ar@{^(->}[r] & \\cdots\\ar@{^(->}[r] & \\bigcup_{k\\geq 0}\\mathbf{RP}^k=\\mathbf{RP}^\\infty\\\\\nS^{k-1}\\ar[u]^{\\text{double cover}}\\ar[r] & D^k\\ar[u]}\n\\end{equation*}\nThis is true if you notice that the preimage of any point of $\\mathbf{RP}^k$ must be two points, one of which must be in the upper hemisphere, which is a disk, unless both points are on the equatorial sphere.\n\\end{example}\n\\subsection{Homology of CW-complexes}\nConsider:\n\\begin{equation*}\n\\xymatrix{A\\ar@{^(->}[r]\\ar[d]^f & B\\ar[r]\\ar[d] & B/A\\ar@{-->}[d]\\\\\nX\\ar@{^(->}[r] & X\\cup_f B\\ar[r] & (X\\cup_fB)/X}\n\\end{equation*}\nBy a diagram chase, the dotted arrow exists and is continuous. This is actually a pointed map. You can see that this is a homeomorphism. What if this is part of a CW-structure?\n\\begin{equation*}\n\\xymatrix{\\coprod_{\\alpha}S^{k-1}\\ar@{^(->}[r]\\ar[d]^f & \\coprod_{\\alpha}D^k_\\alpha\\ar[r]\\ar[d] & \\bigvee_{\\alpha}S^k_\\alpha\\ar@{-->}[d]\\\\\nX_{k-1}\\ar@{^(->}[r] & X_k\\cup_f B\\ar[r] & X_k/X_{k-1}}\n\\end{equation*}\nwhere $\\bigvee$ is the wedge product (disjoint union with all basepoints identified). Then $\\bigvee_{\\alpha}S^k_\\alpha$ is a bouquet of spheres. So $X_k/X_{k-1}\\cong\\bigvee_{\\alpha}S^k_\\alpha$. We know the homology of spheres very well by now, so let's exploit this.\n\\begin{lemma}\n$ H_q(X_k,X_{k-1})\\to H_q(X_k/X_{k-1},\\ast)$ is an isomorphism.\n\\end{lemma}\n\\begin{proof}\nLater.\n\\end{proof}\nBut now, we know $ H_q(X_k/X_{k-1},\\ast)$ very well! It's exactly $\\widetilde{ H}_q(\\bigvee_{\\alpha\\in A_k}S^k_\\alpha)\\cong\\begin{cases}\\Z[A_k] & q=k \\\\ 0 & q\\neq k\\end{cases}$. Therefore the relative homology $ H_q(X_k,X_{k-1})$ counts the number of $k$-cells of $X$.\n\\begin{definition}\nLet $C_k(X):= H_k(X_k,X_{k-1})$. This is the ``cellular $k$-chains'' of $X$.\n\\end{definition}\n\\begin{corollary}\nThere's an exact sequence:\n\\begin{equation*}\n\\xymatrix{ & & H_{k+1}(X_k,X_{k-1})=0\\ar[dll]\\\\\n H_k(X_{k-1})\\ar[r] & H_k(X_k)\\ar[r] & C_k(X)\\ar[dll]\\\\\n H_{k-1}(X_{k-1})\\ar[r] & H_{k-1}(X_k)\\ar[r] & H_{k-1}(X_k,X_{k-1})=0}\n\\end{equation*}\nAnd in other dimensions, $ H_q(X_{k-1})\\cong H_q(X_k)$ for $q\\neq k,k-1$. So:\n\\begin{enumerate}\n\\item We have maps $ H_q(X_k)\\to H_q(X_{k+1})\\to\\cdots$ that are all isomorphisms for $q<k$. (There was a lot of confusion here about what $q$ is greater than or less than). All of these map to $ H_q(X)$. There's another lemma that I will defer again:\n\t\\begin{lemma}\n\tThis limit $ H_q(X_k)\\to H_q(X_{k+1})\\to\\cdots\\to H_q(X)$ is an isomorphism.\n\t\\end{lemma}\n\t\\begin{proof}\n\tDeferred.\n\t\\end{proof}\n\\item (There was a bit of confusion at this point, I'm not sure on what exactly.) $ H_q(X_0)\\to H_q(X_1)\\to\\cdots\\to H_q(X_k)$ are all isomorphisms for $q>k$. Agreed? That's not what I wanted to say. I'll continue this on Wednesday. It's not supposed to be confusing.\n\\end{enumerate}\n\\end{corollary}\n", "meta": {"hexsha": "dbf90e942e6a71c142a08a2824d958e9c8790a68", "size": 6808, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-15-cw-complexes-cellular-homology.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-15-cw-complexes-cellular-homology.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-15-cw-complexes-cellular-homology.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": 72.4255319149, "max_line_length": 401, "alphanum_fraction": 0.6630434783, "num_tokens": 2697, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240895276223, "lm_q2_score": 0.8688267898240861, "lm_q1q2_score": 0.7517298681827518}}
{"text": "\\section{Measurement Uncertainty Analysis}\n\n\\subsection{Uncertainty of The Distance Measurement}\nWe use formula to calculate type-A uncertainty\n\\begin{multline*}\n u_A = t_{0.95} \\sqrt{\\frac{1}{3(3-1)} \\sum_{k=1}^3{(S_k-\\bar{S})^2} } = \\\\\n4.30 \\cdot \\sqrt{1/6\\cdot ( (147.0-  146.83)^2 +  (147.0-  146.83)^2 + (146.5-\n  146.83)^2 ) } =   0.7 mm\n\\end{multline*}\nAnd type-B uncertainty is $u_B = $ = 1 mm. Thus,\n\n$$   u_s = \\sqrt{u_A^2+u_B^2} = \\sqrt{0.7^2+1^2} = 1.2 mm  $$\n$$   u_{S,r} = 1.2 / 146.8 = 0.82 \\% $$ \n\n\\subsection{Uncertainty of The Time Measurement}\nWe use formula to calculate type-A uncertainty\n\\begin{equation}\n u_A = t_{0.95} \\sqrt{\\frac{1}{6(6-1)} \\sum_{k=1}^6{(t_k-\\bar{t})^2} } = 1.05\n \\cdot 0.0252 = 0.0492 s\n\\end{equation}\nAnd type-B uncertainty is $u_B = $ = 0.01 s. Thus,\n$$   u_t = \\sqrt{u_A^2+u_B^2} = \\sqrt{0.0492^2+0.01^2} =  0.0502 s $$\n$$   u_{t,r} = 0.050 / 6.8517= 0.73 \\% $$ \n\n\n\\subsection{Uncertainty of The Ball Diameter}\nWe use formula to calculate type-A uncertainty\n\\begin{equation}\n  u_A = t_{0.95} \\sqrt{\\frac{1}{10(10-1)} \\sum_{k=1}^{10}{(d_k-\\bar{d})^2} }\n = 0.715  \\cdot   0.0197 = 0.0141 s\n\\end{equation}\nAnd type-B uncertainty is $u_B = $ = 0.005 mm. Thus,\n$$   u_d = \\sqrt{u_A^2+u_B^2} = \\sqrt{0.0141^2+0.005^2} = 0.0150 mm $$\n$$   u_{d,r} = 0.0150 / 1.977 =  0.76 \\% $$ \n\n\\subsection{Uncertainty of The Inner Diameter of The Flask}\nWe use formula to calculate type-A uncertainty\n\\begin{equation}\n  u_A = t_{0.95} \\sqrt{\\frac{1}{6(6-1)} \\sum_{k=1}^{6}{(D_k-\\bar{D})^2} }\n = 1.05  \\cdot 0.0523 =  0.0549 mm \n\\end{equation}\nAnd type-B uncertainty is $u_B = $ = 0.02 mm. Thus,\n$$   u_D = \\sqrt{u_A^2+u_B^2} = \\sqrt{0.0549^2+0.02^2} = 0.0584 mm $$\n$$   u_{D,r} = 0.0584 /  61.3533 =  0.095 \\% $$ \n\n\\subsection{Uncertainty of The Mass of The Ball}\nWe have $u_m $ for 40 balls, thus\n$$   u_{m_0} = u_m /40 = 0.0001 / 40 / 1000 = 2.5 \\cdot 10^{-8} kg  $$\n\n\\subsection{Uncertainty of The Density of One Ball}\nFrom\n$$   \\rho_2 = \\frac{6m_0}{ \\pi d^3 } $$\nThen we can find that\n$$ u_{\\rho_2} = \\sqrt{(\\frac{\\partial \\rho_2}{\\partial m_0})^2(u_{m_0})^2 +\n  (\\frac{\\partial \\rho_2}{\\partial d})^2(u_d)^2 \n} = 96.70  $$ \n$$   u_{\\rho_2,r} = u_{\\rho_2 } / \\rho_2  =  96.70 / 8.385 \\cdot 10^3 =   1.14 \\% $$ \nThe code is included as matlab/cal1.m \n\n\n\\subsection{Uncertainty of The Viscosity Coefficient}\n\n\n$$ \\mu = \\frac{2}{9} g R^2 \\frac{( \\rho_2 - \\rho_1 ) t  }{s} (1 + 2.4\n\\frac{R}{R_c})  $$\n\nThus,\n$$ u_{\\mu} = \\sqrt{(\\frac{\\partial \\mu}{\\partial d})^2(u_d)^2\n  + (\\frac{\\partial \\mu}{\\partial s})^2(u_s)^2\n  + (\\frac{\\partial \\mu}{\\partial t})^2(u_t)^2\n  + (\\frac{\\partial \\mu}{\\partial \\rho_1})^2(u_{\\rho_1})^2\n  + (\\frac{\\partial \\mu}{\\partial D})^2(u_D)^2 }  $$ \n$$ u_{\\mu}  =  1.4264 \\cdot 10^{-2}   $$\n$$ u_{\\mu,r} =\\frac{u_\\mu}{\\mu}=  1.42 \\cdot 10^{-2}  / 0.7307 =   1.94 \\% $$\n\nThe code is included as matlab/cal2.m \n\n", "meta": {"hexsha": "f533441850e3ad3e5da8bbddc26e9883668cb518", "size": 2862, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "E2/part/6mua.tex", "max_stars_repo_name": "iamwrm/VP141", "max_stars_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2021-06-24T11:28:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-24T11:28:04.000Z", "max_issues_repo_path": "E2/part/6mua.tex", "max_issues_repo_name": "iamwrm/VP141", "max_issues_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "E2/part/6mua.tex", "max_forks_repo_name": "iamwrm/VP141", "max_forks_repo_head_hexsha": "c0a5d1992967b1552d6f7ea0806c9244d58f64ac", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 36.6923076923, "max_line_length": 85, "alphanum_fraction": 0.5849056604, "num_tokens": 1303, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8652240756264639, "lm_q2_score": 0.868826769445233, "lm_q1q2_score": 0.7517298384727785}}
{"text": "\n\\subsection{Extreme IID multinomial}\n\n\\subsubsection{IID}\n\nThe probability of \\(j\\) being chosen is:\n\n\\(P_{ij}=P(\\epsilon_{ik} <v_{ij} -v_{ik} +\\epsilon_{ij}\\forall k\\ne j)\\)\n\nIf these are independent then we have:\n\n\\(P_{ij}=\\prod_{k\\ne j} P(\\epsilon_{ik} <v_{ij} -v_{ik} +\\epsilon_{ij})\\)\n\n\\(P_{ij}=\\prod_{k\\ne j} F_\\epsilon (v_{ij} -v_{ik} +\\epsilon_{ij})\\)\n\nWe do not know \\(\\epsilon_{ij}\\) so we have to integrate over possibilities.\n\n\\(P_{ij}=\\int [\\prod_{k\\ne j} F_\\epsilon (v_{ij} -v_{ik} +\\epsilon_{ij})]f_\\epsilon(\\epsilon_{ij})d\\epsilon_{ij}\\)\n\n\\subsubsection{Extreme values}\n\nWe have:\n\n\\(P_{ij}=\\int [\\prod_{k\\ne j} F_\\epsilon (v_{ij} -v_{ik} +\\epsilon_{ij})]f_\\epsilon(\\epsilon_{ij})d\\epsilon_{ij}\\)\n\nIf \\(\\epsilon \\) is extreme value type-I this gives us:\n\n\\(P_{ij}=\\dfrac{e^{v_{ij}}}{\\sum_k e^{v_{ik}}}\\)\n\n\\subsubsection{Independence of irrelevant alternatives}\n\nConsider the ratio two probabilities:\n\n\\(\\dfrac{P_{ij}}{P_{im}}=\\dfrac{e^{v_{ij}}}{e^{v_{im}}}\\)\n\nThis means that changes to any other products do not affect relative odds.\n\nThis can be undesirable. For example removing one option may cause unbalanced substitution.\n\nFor example raising the price of buses may cause more substitution to trains than helicopter, for a commute.\n\n", "meta": {"hexsha": "d34926ff8df9605273c2c9171ef0c922502f1e50", "size": 1255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/glmMulti/01-02-extremeIID.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/glmMulti/01-02-extremeIID.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/glmMulti/01-02-extremeIID.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.880952381, "max_line_length": 114, "alphanum_fraction": 0.6908366534, "num_tokens": 408, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273632996617212, "lm_q2_score": 0.8104789155369048, "lm_q1q2_score": 0.7516084014185574}}
{"text": "\\section{Measurement Error Modeling}\n\nThe general model of a measurement error is as follows:\n\\begin{equation}\n\te = b + v\n\\end{equation}\nwhere $b$ models the systematic errors, and $v$ models the measurement noise.  We assume that the measurement noise is a discrete sequence of uncorrelated random numbers.  Variables such as $v$ are known as random variables, and the next subsection describes how to model them.  Subsequent subsections describe models for the systematic errors.\n\nThe discussion of systematic errors treats such errors as scalar quantities to simplify the exposition; generalization to the vector case is straightforward.  Note that if the measurement is non-scalar, but the errors in the component measurements are independent of one another, then we can model each measurement independently, so modeling the biases as vector is not required.  If the measurement errors are not independent, then many estimators require that we apply a transformation to the data prior to processing so that the data input to the estimator have independent measurement errors; the next subsection describes some ways to accomplish this transformation.\n\n\\subsection{Models and Realizations of Random Variables}\n\nA continuous random variable is a function that maps the outcomes of random events to the real line.  Realizations of random variables are thus real numbers.  A vector of $n$ random variables maps outcomes of random events to $\\mathcal{R}^n$.  For our purposes, random variables will always be associated with a probability density function that indicates the likelihood that a realization occurs within a particular interval of the real line, or within a particular subspace of $\\mathcal{R}^n$ for the vector case.  Currently, all of our models assume that this density is the normal or Gaussian density.  For the vector case, the normal probability density function is\n\\begin{equation}\n\tf(x) = \\frac{1}{2\\pi|P|}\\text{e}^{-\\frac{1}{2}(x-\\mu)'P^{-1}(x-\\mu)}\n\\end{equation}\nwhere $\\mu$ is a vector of mean values for each component of $x$, and $P$ is a matrix that contains the variances of each component of $x$ along its diagonal, and the covariances between each component as its off-diagonal components.  The covariances indicate the degree of correlation between the random variables composing $x$.  The matrix $P$ is thus called the variance-covariance matrix, which we will hereafter abbreviate to just ``covariance matrix,'' or ``covariance.''  Since the normal density is completely characterized by its mean and covariance, we will use the following notation as a shorthand to describe normally-distributed random vectors:\n\\begin{equation}\n\tx \\sim N(\\mu, P)\n\\end{equation}\nThus, the model for the measurement noise is\n\\begin{equation}\n\tv \\sim N(0, R)\n\\end{equation}\n\nFor the scalar case, or for the vector case when the covariance is diagonal, we may directly generate realizations of a normally-distributed random vector from normal random number generators available in most software libraries.  If $P$ has non-zero off-diagonal elements, we must model the specified correlations when we generate realizations.  If $P$ is strictly positive definite, we can factor it as follows:\n\\begin{equation}\n\tP = SS'\n\\end{equation}\nwhere $S$ is a triangular matrix known as a Cholesky factor; this can be viewed as a ``matrix square root.''  The Cholesky factorization is available in many linear algebra libraries.  We can then use $S$ to generate correlated realizations of $x$ as follows.  Let $z$ be a normally-distributed random vector of the same dimension as $x$, with zero mean and unit variance, that is\n\\begin{equation}\n\tz \\sim N(0,I)\n\\end{equation}\nThen, with\n\\begin{equation}\n\tx = S z\n\\end{equation}\nwe can generate properly correlated realizations of $x$.  We can also use a Cholesky factorization of the measurement noise covariance $R$, if $R$ is non-diagonal, to transform correlated measurements into uncorrelated auxiliary measurements for cases in which the estimator cannot handle correlated measurement data.\n\nIf $P$ is only non-negative definite, i.e.\\@ $P \\geq 0$ rather than $P > 0$ as above, the Cholesky factorization does not exist.  In this case, since $P$'s eigenvalues are real and distinct, it has a diagonal factorization:\n\\begin{equation}\n\tP = V D V'\n\\end{equation}\nwhere $V$ is a matrix of eigenvectors and $D$ is a diagonal matrix of eigenvalues.\nThen, with $z$ as above,\n\\begin{equation}\n\tx = V \\sqrt{D} z\n\\end{equation}\nwhere $\\sqrt{D}$ implies taking the square roots of each diagonal element.\n\n\\subsection{Zero-Input Bias State Models}\n\nThe simplest non-zero measurement error consists only of measurement noise.  The next simplest class of measurement errors consists of biases which are either themselves constant, or are the integrals of constants.  We can view such biases as the output of a system which has zero inputs, and which may have internal states.  In the sequel, we will consider cases where there are random inputs to the system.\n\nIn cases were the bias is the output of a system with internal states, the estimator may treat the internal states as solve-for or consider parameters.  In such cases, the estimator requires a measurement partials matrix.  Otherwise, the ``measurement partial'' is just $H = \\partial b / \\partial b = 1$.\n\n\\subsubsection{Random Constant}\n\nThe simplest type of systematic error is a constant bias on the measurement.  There are two types of such biases: deterministic constants, which are truly constant for all time, and random constants, which are constant or very nearly so over a particular time of interest.  For example, each time a sensor is power-cycled, a bias associated with it may change in value, but so long as the sensor remains powered on, the bias will not change.\n\nIn some cases, we may have reason to believe that a particular systematic error source truly is a deterministic bias, but due to limited observability, we do not have knowledge of its true value.  In such cases, we may view our estimate of the bias as a random constant, and its variance as a measure of the imprecision of our knowledge.\n\nThus, we may view all constants that could be solve-for or consider parameters in orbit determination as random constants.  Our model for a random constant is\n\\begin{equation}\n\t\\dot{b}(t) = 0, \\, b(t_o) \\sim N(0, p_{bo}).\n\\end{equation}\nSince $b(t)$ is a zero-mean constant, its mean is zero for all time, and its covariance is constant for all time as well.  Thus, to simulate a realization of the random constant, we need only generate a random number according to $N(0, p_{bo})$, as the previous subsection described.\n\n\\subsubsection{Random Ramp}\n\nThe random ramp model assumes that the rate of change of the bias is itself a random constant; thus the random ramp model is\n\\begin{equation}\n\t\\ddot{b}(t) = 0, \\, \\dot{b}(t_o) \\sim N(0, p_{\\dot{b}o}).\n\\end{equation}\nThus, the initial condition $\\dot{b}(t_o)$ is a random constant.  For a pure random ramp, the initial condition on $b(t_o)$ and its covariance are taken to be zero, but an obvious and common generalization is to allow $b(t_o)$ to also be a random constant.\n\nIt is convenient to write this model as a first-order vector system as follows:\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\ddot{b}(t) \\end{bmatrix} =\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\end{bmatrix} \\\\\n\t\\dot{x}(t) &=& A(t) x(t)\n\\end{eqnarray}\nThe resulting output equation is\n\\begin{eqnarray}\n\te & = &  \\begin{bmatrix} 1 & 0 \\end{bmatrix} x + v \\\\\n\t& = & H x + v\n\\end{eqnarray}\nNote that the ensemble of realizations of $x(t)$ has zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\Phi(t) = \\begin{bmatrix} 1 & t \\\\ 0 & 1 \\end{bmatrix} \\, \\text{and} \\;\n\tP_{xo} = \\begin{bmatrix} p_{bo} & 0 \\\\ 0 & p_{\\dot{b}o} \\end{bmatrix}\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tP_x(t+\\Delta t) = \\Phi(\\Delta t)P_x(t)\\Phi'(\\Delta t)\n\\end{equation}\nThus, we can generate realizations of the random ramp with either $x(t) \\sim N(0, P_x(t))$ or recursively from\n\\begin{equation}\n\tx(t+\\Delta t) = \\Phi(\\Delta t) x(t)\n\\end{equation}\n\nNote that $\\|P_x\\|$ becomes infinite as $t^2$ becomes infinite.  This could lead to an overflow of the representation of $P_x$ in a computer program if the propagation time is large, and could also lead to the representation of $P_x$ losing either its symmetry and/or its positive definiteness due to roundoff and/or truncation.\n\n\\subsubsection{Higher-Order Derivatives of Random Constants}\n\nIn principle, a random constant may be associated with any derivative of the bias in a straightforward extension of the models above.  In practice, it is rare to need more than two derivatives.  Conventional terminology does not appear in the literature for derivatives of higher order than the random ramp.  The slope of the bias is most commonly described as the ``bias drift,'' so that a ``drift random ramp'' would be one way to describe a bias whose second derivative is a random constant.  The measurement partials matrix needs to be accordingly padded with trailing zeros for the derivatives of the bias in such cases.\n\n\\subsection{Single-Input Bias State Models}\n\nThe simplest non-constant systematic errors are systems with a single input that is a random process.  We can think of a random process as the result of some kind of limit in which the intervals between an uncorrelated sequence of random variables get infinitesimally small.  In this limit, each random increment instantaneously perturbs the sequence, so that the resulting process is continuous but non-differentiable.  We call this kind of a random input ``process noise.''\n\nAlthough such random processes are non-differentiable, there are various techniques for generalizing the concept of integration so that something like integrals of the process noise exist, and hence so do the differentials that appear under the integral signs.  It turns out that so long as any coefficients of the process noise are non-random, these differentials behave for all practical purposes as if they were differentiable.\n\n\\subsubsection{Random Walk}\n\nThe random walk is the simplest random process of the type described above.  In terms of the ``formal derivatives'' mentioned above, the random walk model for a measurement bias is\n\\begin{equation}\n\t\\dot{b}(t) = w(t), \\, w(t) \\sim N(0, q\\delta(t-s))\n\\end{equation}\nThe input noise process on the right hand side is known as ``white noise,'' and the Dirac delta function that appears in the expression for its variance indicates that the white noise process consists of something like an infinitely-tightly spaced set of impulses.  The term $q$ that appears along with the delta function is the intensity of each impulse\\footnote{Another way to imagine the input sequence, in terms of a frequency domain interpretation, is that it is a noise process whose power spectral density, $q$, is non-zero at all frequencies, which implies infinite bandwidth.}.  The initial condition $b(t_o)$ is an unbiased random constant.  Since $b(t_o)$ and $w(t)$ are zero-mean, then $b(t)$ is also zero-mean for all time.  The variance of $b$ evolves in time according to\n\\begin{equation}\n\tp_b(t) = p_{bo} + q (t-t_o)\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tp_b(t+\\Delta t) = p_b(t) + q\\Delta t\n\\end{equation}\nThus, to generate a realization of the random walk at time $t$, we need only generate a random number according to $N(0, p_b(t))$.  Equivalently, we could also generate realizations of $w_\\Delta(t) \\sim N(0, q\\Delta t)$, and recursively add these discrete noise increments to the bias as follows:\n\\begin{equation}\n\t b(t+\\Delta t) = b(t) + w_\\Delta(t)\n\\end{equation}\n\nNote that $p_b$ becomes infinite as $t$ becomes infinite.  This could lead to an overflow of the representation of $p_b$ in a computer program if both the propagation time and $q$ are large.\n\n\\subsubsection{Random Run}\n\nThe random run model assumes that the rate of change of the bias is itself a random walk; thus the random run model is\n\\begin{equation}\n\t\\ddot{b}(t) = w(t), \\, w(t) \\sim N(0, q\\delta(t-s))\n\\end{equation}\nThe initial condition $\\dot{b}(t_o)$ is a random constant.  For a pure random run, the initial condition on $b(t_o)$ and its covariance are taken to be zero, but an obvious and common generalization is to allow $b(t_o)$ to also be a random constant.\n\nIt is convenient to write this model as a first-order vector system as follows:\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\ddot{b}(t) \\end{bmatrix} =\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\end{bmatrix} +\n\t\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} w(t) \\\\\n\t\\dot{x}(t) &=& A(t) x(t) + b(t) w(t)\n\\end{eqnarray}\nThe measurement partial is the same as for the random ramp.  The initial condition $x(t_o)$ is an unbiased random constant.  Since $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o) + Q_\\Delta(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\Phi(t) = \\begin{bmatrix} 1 & t \\\\ 0 & 1 \\end{bmatrix} \\, \\text{and} \\;\n\tP_{xo} = \\begin{bmatrix} p_{bo} & 0 \\\\ 0 & p_{\\dot{b}o} \\end{bmatrix}\n\\end{equation}\nand\n\\begin{equation}\n\tQ_\\Delta(t) = q\\begin{bmatrix} t^3/3 & t^2/2 \\\\ t^2/2 & t \\end{bmatrix}\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tP_x(t+\\Delta t) = \\Phi(\\Delta t)P_x(t)\\Phi'(\\Delta t) + Q_\\Delta(\\Delta t)\n\\end{equation}\nThus, we can generate realizations of the random run with either $x(t) \\sim N(0, P_x(t))$ or recursively from\n\\begin{equation}\n\tx(t+\\Delta t) = \\Phi(\\Delta t) x(t) + w_\\Delta(t)\n\\end{equation}\nwhere $w_\\Delta(t) \\sim N(0, Q_\\Delta(\\Delta t))$.  Note that a Cholesky decomposition of $Q_\\Delta(t)$ is\n\\begin{equation}\n\t\\sqrt[C]{Q_\\Delta(t)} = \\begin{bmatrix} \\sqrt{3t^3}/3 & 0 \\\\ \\sqrt{3t}/2 & \\sqrt{t}/2 \\end{bmatrix}\n\\end{equation}\n\nNote that $\\|P_x\\|$ becomes infinite as $t^3$ becomes infinite.  This could lead to an overflow of the representation of $P_x$ in a computer program if both the propagation time and $q$ are large, and could also lead to the representation of $P_x$ losing either its symmetry and/or its positive definiteness due to roundoff and/or truncation.\n\n\\subsubsection{Higher-Order Derivatives of Random Walks}\n\nIn principle, a random walk may be associated with any derivative of the bias in a straightforward extension of the models above.  In practice, it is rare to need more than two derivatives.  Conventional terminology does not appear in the literature for derivatives of higher order than the random run.  A ``drift random run'' would be one way to describe a bias whose second derivative is a random walk.  Below, we will refer to such a model as a ``random zoom.''\n\n\\subsubsection{First-Order Gauss-Markov}\n\nThe first-order Gauss-Markov (FOGM) process is one of the simplest random processes that introduces time correlation between samples.  In terms of a frequency domain interpretation, we can view it as white noise passed through a low-pass filter.  Since such noise, often called ``colored noise,'' has finite bandwidth, it is physically realizable, unlike white noise.  In the notation of formal derivatives, the FOGM model is\n\\begin{equation}\n\t\\dot{b}(t) = -\\frac{1}{\\tau} b(t) + w(t),\n\\end{equation}\nwhere, as with the random walk, $b(t_o) \\sim N(0, P_{bo})$, and $w(t) \\sim N(0, q\\delta(t-s))$.  The time constant, $\\tau$, also known as the ``half-life,'' gives the correlation time, or the time over which the intensity of the time correlation will fade to half its value.\n\nSince $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tp_b(t) = \\text{e}^{-\\frac{2}{\\tau}(t-t_o)}p_{bo} + q_\\Delta(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\tq_\\Delta(t-t_o) = \\frac{q\\tau}{2}\\left(1-\\text{e}^{-\\frac{2}{\\tau}(t-t_o)}\\right)\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tp_b(t+\\Delta t) = \\text{e}^{-\\frac{2\\Delta t}{\\tau}}p_b(t) + q_\\Delta(\\Delta t)\n\\end{equation}\nThus, to generate a realization of the random walk at time $t$, we need only generate a random number according to $N(0, p_b(t))$.  Equivalently, we could also generate realizations of $w_\\Delta(t) \\sim N(0, q_\\Delta(\\Delta t))$, and recursively add these discrete noise increments to the bias as follows:\n\\begin{equation}\n\t b(t+\\Delta t) = \\text{e}^{-\\frac{\\Delta t}{\\tau}}b(t) + w_\\Delta(t)\n\\end{equation}\n\nNote that $p_b$ approaches a finite steady-state value of $q\\tau/2$ as $t$ becomes infinite.  We can choose the parameters of the FOGM so that this steady-state value avoids any overflow of the representation of $p_b$ in a computer program.\n\n\\subsubsection{Integrated First-Order Gauss-Markov Model}\n\nAs with the random walk and random constant models, any number of derivatives of the bias may be associated with a FOGM process.  However, integation of the FOGM destroys its stability.  For example, the singly integrated first-order Gauss-Markov model is given by\n\\begin{equation}\n\t\\left[\\begin{array}{c}\n\t\t\\dot{b}(t) \\\\\n\t\t\\dot{d}(t)\n\t\\end{array}\\right] =\n\t\\left[\\begin{array}{cc}\n\t\t0 & 1 \\\\\n\t\t0 & -1/\\tau\n\t\\end{array}\\right]\n\t\\left[\\begin{array}{c}\n\t\tb(t) \\\\\n\t\td(t)\n\t\\end{array}\\right]\n\t+ \\left[\\begin{array}{c}\n\t\t0 \\\\\n\t\tw(t)\n\t\\end{array}\\right],\n\\end{equation}\nwhich leads to the following state transition matrix,\n\\begin{equation}\n\t\\Phi(t) = \\left[\\begin{array}{cc}\n\t\t1 & \\tau \\left( 1-e^{-t/\\tau} \\right) \\\\\n\t\t0 & e^{-t/\\tau}\n\t\\end{array}\\right],\n\\end{equation}\nand process noise covariance,\n\\begin{equation}\n\tQ_\\Delta(t) = \\frac{q\\tau}{2} \\left[\\begin{array}{cc}\n\t\t\\tau^2 \\left\\{ \\left( 1-e^{-2t/\\tau} \\right)^2  +2t/\\tau\n\t\t+ 4 \\left( 1-e^{-t/\\tau} \\right) \\right\\}\n\t\t& \\tau \\left( 1-e^{-t/\\tau} \\right)^2 \\\\\n\t\t\\tau \\left( 1-e^{-t/\\tau} \\right)^2 & \\left( 1-e^{-2t/\\tau} \\right)\n\t\\end{array}\\right].\n\\end{equation}\nClearly, this is an unstable model, as the bias variance increases linearly with elapsed time.  If a Gauss-Markov model is desired because of its stability properties, the following second-order model is available.\n\n\\subsubsection{Second-Order Gauss-Markov}\n\nThe model for a second-order Gauss-Markov random process is\n\\begin{equation}\n\t\\ddot{b}(t) = -2\\zeta\\omega_n \\dot{b}(t) -\\omega_n^2 b(t) + w(t), \\, w(t) \\sim N(0, q\\delta(t-s))\n\\end{equation}\nThe initial conditions $b(t_o)$ and $\\dot{b}(t_o)$ are random constants.  It is convenient to write this model as a first-order vector system as follows:\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\ddot{b}(t) \\end{bmatrix} =\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} 0 & 1 \\\\ -\\omega_n^2 & -2\\zeta\\omega_n \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\end{bmatrix} +\n\t\\begin{bmatrix} 0 \\\\ 1 \\end{bmatrix} w(t) \\\\\n\t\\dot{x}(t) &=& A(t) x(t) + b(t) w(t)\n\\end{eqnarray}\nThe measurement partial is the same as for the random ramp.  The initial condition $x(t_o)$ is an unbiased random constant.  Since $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.\n\nThe covariance evolves in time according to according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o) + Q_\\Delta(t-t_o)\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tP_x(t+\\Delta t) = \\Phi(\\Delta t)P_x(t)\\Phi'(\\Delta t) + Q_\\Delta(\\Delta t)\n\\end{equation}\nThus, we can generate realizations of the random run with either $x(t) \\sim N(0, P_x(t))$ or recursively from\n\\begin{equation}\n\tx(t+\\Delta t) = \\Phi(\\Delta t) x(t) + w_\\Delta(t)\n\\end{equation}\nwhere $w_\\Delta(t) \\sim N(0, Q_\\Delta(\\Delta t))$.\n\nFor the underdamped case ($\\zeta < 1$), the state transition matrix and discrete process noise covariance are given by\\footnote{M.~C. Wang and G.~E. Uhlenbeck. On the theory of brownian motion ii. In N.~Wax, editor, {\\em Selected Papers on Noise and Stochastic Processes}, pages 113--132. Dover, 1954.}:\n\\begin{equation}\n\t\\Phi(t) = \\frac{\\text{e}^{-\\zeta\\omega_{n}t}}{w_{d}}\n\t\\begin{bmatrix}\n\t\t(\\omega_{d}\\cos\\omega_{d}t + \\zeta\\omega_{n}\\sin\\omega_{d}t) &\n\t\t\\sin\\omega_{d}t  \\\\\n\t\t-\\omega_{n}^{2}\\sin\\omega_{d}t &\n\t\t(\\omega_{d}\\cos\\omega_{d}t - \\zeta\\omega_{n}\\sin\\omega_{d}t)\n\t\\end{bmatrix}\n\\end{equation}\nand\n\\begin{eqnarray}\n\tQ^{(1,1)}_\\Delta(t) &=&  \\frac{q}{4\\zeta\\omega_{n}^{3}}\\left[ 1\n\t- \\frac{\\text{e}^{-2\\zeta\\omega_{n}t}}{w_{d}^{2}}(\\omega_{d}^{2}\n\t+ 2\\zeta\\omega_{n}\\omega_{d}\\cos\\omega_{d}t\\sin\\omega_{d}t\n\t+ 2\\zeta^{2}\\omega_{n}^{2}\\sin^{2}\\omega_{d}t)\\right] \\\\\n\tQ^{(2,2)}_\\Delta(t) &=&  \\frac{q}{4\\zeta\\omega_{n}}\\left[ 1\n\t- \\frac{\\text{e}^{-2\\zeta\\omega_{n}t}}{w_{d}^{2}}(\\omega_{d}^{2}\n\t- 2\\zeta\\omega_{n}\\omega_{d}\\cos\\omega_{d}t\\sin\\omega_{d}t\n\t+ 2\\zeta^{2}\\omega_{n}^{2}\\sin^{2}\\omega_{d}t)\\right] \\\\\n\tQ^{(2,1)}_\\Delta(t) = Q^{(1,2)}_\\Delta(t) &=& \\frac{q}{2\\omega_{d}^{2}}\n\t\\text{e}^{-2\\zeta\\omega_{n}t}\\sin^{2}\\omega_{d}t\n\\end{eqnarray}\nwhere $\\omega_d = \\omega_n\\sqrt{1-\\zeta^2}$. In the over-damped case ($\\zeta > 1$), replace $\\sin$ and $\\cos$ with $\\sinh$ and $\\cosh$, respectively.  In the critically-damped case,\n\\begin{equation}\n\t\\Phi(t) =\n\t\\begin{bmatrix}\n\t\t\\text{e}^{-\\omega_{n}t}(1 + \\omega_{n}t) &\n\t\tt\\text{e}^{-\\omega_{n}t}  \\\\\n\t\t-\\omega_{n}^{2}t\\text{e}^{-\\omega_{n}t} &\n\t\t \\text{e}^{-\\omega_{n}t}(1 - \\omega_{n}t)\n\t\\end{bmatrix}\n\\end{equation}\nand\n\\begin{eqnarray}\n\tQ^{(1,1)}_\\Delta(t) &=& \\frac{q}{4\\omega_{n}^{3}}\\left[ 1\n\t- \\text{e}^{-2\\omega_{n}t}(1\n\t+ 2\\omega_{n}t\n\t+ 2\\omega_{n}^{2}t^2)\\right]  \\\\\n\tQ^{(2,2)}_\\Delta(t) &=& \\frac{q}{4\\omega_{n}}\\left[ 1\n\t- \\text{e}^{-2\\omega_{n}t}(1\n\t- 2\\omega_{n}t\n\t+ 2\\omega_{n}^{2}t^2)\\right]  \\\\\n\tQ^{(2,1)}_\\Delta(t) = Q^{(1,2)}_\\Delta(t) &=& \\frac{q t^2}{2}\n\t\\text{e}^{-2\\omega_{n}t}\n\\end{eqnarray}\n\nNote that for any damping ratio, $\\|P_x\\|$ remains finite, since as $t\\rightarrow\\infty$,\n\\begin{equation}\n\tP_x(t\\rightarrow\\infty) = \\frac{q}{4\\zeta\\omega_{n}}\\left[\n\t\\begin{array}{cc}\n\t\t1/\\omega_{n}^{2} & 0  \\\\\n\t\t0 & 1\n\t\\end{array}\\right].\n\\end{equation}\nThus, the ratio of the steady-state standard deviations of $x$ and $\\dot{x}$ will be\n\\begin{equation}\n\t\\frac{\\sigma_{d}}{\\sigma_{b}} = \\omega_{n},\n\\end{equation}\nand these are related to the power spectral density by\n\\begin{equation}\n\tq = 4\\zeta\\frac{\\sigma_{d}^{3}}{\\sigma_{b}}.\n\\end{equation}\nHence, we can choose the parameters of the SOGM so that we avoid any overflow, loss of symmetry and/or positive definiteness of $P_x$ due to roundoff and/or truncation.\n\n\\subsection{Multi-Input Bias State Models}\n\nWe may combine any of the above models to create multi-input bias models; for example the bias could be a second-order Gauss-Markov, and the bias rate could be a first-order Gauss-Markov.  In practice, the most useful have been found to be the following.\n\n\\subsubsection{Bias and Drift Random Walks (Random Walk + Random Run)}\n\nA common model for biases in clocks, gyros, and accelerometers is that the bias is driven by both its own white noise input, and also by the integral of the white noise of its drift.  Such models derive from observations that the error magnitudes of these devices depend on the time scale over which the device is observed.  They are often characterized by Allan deviation specifications, which may be heuristically associated with the white noise power spectral densities.  The model is as follows:\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} 0 & 1 \\\\ 0 & 0 \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\end{bmatrix} +\n\t\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\n\t\\begin{bmatrix} w_b(t) \\\\ w_d(t) \\end{bmatrix} \\\\\n\t\\dot{x}(t) &=& A(t) x(t) + B(t) w(t)\n\\end{eqnarray}\nThe measurement partial is the same as for the random ramp.  The initial condition $x(t_o)$ is an unbiased random constant.  Since $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o) + Q_\\Delta(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\Phi(t) = \\begin{bmatrix} 1 & t \\\\ 0 & 1 \\end{bmatrix} \\, \\text{and} \\;\n\tP_{xo} = \\begin{bmatrix} p_{bo} & 0 \\\\ 0 & p_{\\dot{b}o} \\end{bmatrix}\n\\end{equation}\nand\n\\begin{equation}\n\tQ_\\Delta(t) = \\begin{bmatrix} q_b t + q_d t^3/3 & q_d t^2/2 \\\\ q_d t^2/2 & q_d t \\end{bmatrix}\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tP_x(t+\\Delta t) = \\Phi(\\Delta t)P_x(t)\\Phi'(\\Delta t) + Q_\\Delta(\\Delta t)\n\\end{equation}\nThus, we can generate realizations of the random run with either $x(t) \\sim N(0, P_x(t))$ or recursively from\n\\begin{equation}\n\tx(t+\\Delta t) = \\Phi(\\Delta t) x(t) + w_\\Delta(t)\n\\end{equation}\nwhere $w_\\Delta(t) \\sim N(0, Q_\\Delta(\\Delta t))$.  Note that a Cholesky decomposition of $Q_\\Delta(t)$ is\n\\begin{equation}\n\t\\sqrt[C]{Q_\\Delta(t)} = \\begin{bmatrix} \\sqrt{q_b t + q_d t^3/12} & 0 \\\\ \\sqrt{q_d t^3}/2 & \\sqrt{q_d t} \\end{bmatrix}\n\\end{equation}\n\nNote that $\\|P_x\\|$ becomes infinite as $t^3$ becomes infinite.  This could lead to an overflow of the representation of $P_x$ in a computer program if both the propagation time and $q$ are large, and could also lead to the representation of $P_x$ losing either its symmetry and/or its positive definiteness due to roundoff and/or truncation.\n\n\\subsubsection{Bias, Drift, and Drift Rate Random Walks (Random Walk + Random Run + Random Zoom)}\n\nAnother model for biases in very-high precision clocks, gyros, and accelerometers is that the bias is driven by two integrals of white noise in addition to its own white noise input.  Such models are often characterized by Hadamard deviation specifications, which may be heuristically associated with the white noise power spectral densities.  The model is as follows:\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\\\ \\ddot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} 0 & 1 & 0 \\\\ 0 & 0 & 1 \\\\ 0 & 0 & 0 \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\\\ \\dot{d}(t) \\end{bmatrix} +\n\t\\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}\n\t\\begin{bmatrix} w_b(t) \\\\ w_d(t) \\\\ w_{\\dot{d}}(t) \\end{bmatrix} \\\\\n\t\\dot{x}(t) &=& A(t) x(t) + B(t) w(t)\n\\end{eqnarray}\nThe resulting output equation is\n\\begin{eqnarray}\n\te & = &  \\begin{bmatrix} 1 & 0 & 0 \\end{bmatrix} x + v \\\\\n\t& = & H x + v\n\\end{eqnarray}\nThe initial condition $x(t_o)$ is an unbiased random constant.  Since $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o) + Q_\\Delta(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\Phi(t) = \\begin{bmatrix} 1 & t & t^2/2 \\\\ 0 & 1 & t \\\\ 0 & 0 & 1 \\end{bmatrix} \\, \\text{and} \\;\n\tP_{xo} = \\begin{bmatrix} p_{bo} & 0 & 0 \\\\ 0 & p_{do} & 0 \\\\ 0 & 0 & p_{\\dot{d}o} \\end{bmatrix}\n\\end{equation}\nand\n\\begin{equation}\n\tQ_\\Delta(t) = \\begin{bmatrix}\n\tq_b t + q_d t^3/3 + q_{\\dot{d}} t^5/5 &\n\tq_d t^2/2 + q_{\\dot{d}} t^4/8 &\n\tq_{\\dot{d}}t^3/6 \\\\\n\tq_d t^2/2 + q_{\\dot{d}} t^4/8 &\n\tq_d t + q_{\\dot{d}} t^3/3 &\n\tq_{\\dot{d}}t^2/2 \\\\\n\tq_{\\dot{d}}t^3/6 & q_{\\dot{d}}t^2/2 &  q_{\\dot{d}} t\n\t\\end{bmatrix}\n\\end{equation}\nwhich we can also write in recursive form as\n\\begin{equation}\n\tP_x(t+\\Delta t) = \\Phi(\\Delta t)P_x(t)\\Phi'(\\Delta t) + Q_\\Delta(\\Delta t)\n\\end{equation}\nThus, we can generate realizations of the random run with either $x(t) \\sim N(0, P_x(t))$ or recursively from\n\\begin{equation}\n\tx(t+\\Delta t) = \\Phi(\\Delta t) x(t) + w_\\Delta(t)\n\\end{equation}\nwhere $w_\\Delta(t) \\sim N(0, Q_\\Delta(\\Delta t))$.  Note that a Cholesky decomposition of $Q_\\Delta(t)$ is\n\\begin{equation}\n\t\\sqrt[C]{Q_\\Delta(t)} = \\begin{bmatrix}\n\t\\sqrt{q_b t + q_d t^3/12 + q_{\\dot{d}}t^5/720} & 0 & 0 \\\\\n\tt/2\\sqrt{q_d t + q_{\\dot{d}}t^3/12} & \\sqrt{q_d t + q_{\\dot{d}}t^3/12} & 0 \\\\\n\tt^2/6\\sqrt{q_{\\dot{d}}t} & t/2\\sqrt{q_{\\dot{d}}t} &\n\t\\sqrt{q_{\\dot{d}} t}\n\t\\end{bmatrix}\n\\end{equation}\n\nNote that $\\|P_x\\|$ becomes infinite as $t^3$ becomes infinite.  This could lead to an overflow of the representation of $P_x$ in a computer program if both the propagation time and $q$ are large, and could also lead to the representation of $P_x$ losing either its symmetry and/or its positive definiteness due to roundoff and/or truncation.\n\n\\subsubsection{Bias and Drift Coupled First- and Second-Order Gauss-Markov}\n\nThe following model provides a stable alternative to the ``Random Walk + Random Run'' model\\footnote{R.~Carpenter and T.~Lee. A stable clock error model using coupled first- and second-order gauss-markov processes. In {\\em Astrodynamics 2008}, Advances in the Astronautical Sciences. Univelt, 2008.}.  Its transient response can be tuned to approximate the Random Walk + Random Run model, and its stable steady-state response can be used to avoid computational issues with long propagation times.  The model is as follows.\n\\begin{eqnarray}\n\t\\begin{bmatrix} \\dot{b}(t) \\\\ \\dot{d}(t) \\end{bmatrix} &=&\n\t\\begin{bmatrix} -1/\\tau & 1 \\\\ -\\omega_n^2 & -2\\zeta\\omega_n \\end{bmatrix}\n\t\\begin{bmatrix} b(t) \\\\ d(t) \\end{bmatrix} +\n\t\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}\n\t\\begin{bmatrix} w_b(t) \\\\ w_d(t) \\end{bmatrix} \\\\\n\t\\dot{x}(t) &=& A(t) x(t) + B(t) w(t)\n\\end{eqnarray}\nThe measurement partial is the same as for the random ramp.  The initial condition $x(t_o)$ is an unbiased random constant.  Since $x(t_o)$ and $w(t)$ are zero-mean, then $x(t)$ is also zero-mean for all time.  The covariance evolves in time according to\n\\begin{equation}\n\tP_x(t) = \\Phi(t-t_o)P_{xo}\\Phi'(t-t_o) + Q_\\Delta(t-t_o)\n\\end{equation}\nwhere\n\\begin{equation}\n\t\\Phi(t) = \\frac{e^{at}}{b}\\left[\\begin{array}{cc}\n\t\tb\\cos bt + \\left(a + 2\\zeta\\omega_n\\right)\\sin bt & \\sin bt \\\\\n\t\t-\\omega_n^2\\sin bt & b\\cos bt + \\left(a + \\beta\\right)\\sin bt\n\t\\end{array}\\right]\n\\end{equation}\nwhere\n\\begin{align}\n\t\\beta &= 1/\\tau, \\\\\n\ta &= -\\frac{1}{2}\\left(\\beta + 2\\zeta\\omega_n\\right), \\\\\n\tb &= \\sqrt{\\omega_d^2 + \\beta\\zeta\\omega_n - \\frac{1}{4}\\beta^2}, \\\\\n\t\\omega_d &= \\omega_n\\sqrt{1 - \\zeta^2},\n\\end{align}\nand we assume that $b^2 > 0$.\nLet $$c = -\\frac{\\beta}{2} + \\zeta\\omega_n;$$ then, the process noise covariance is given by the following:\n\\begin{align}\\begin{split}\n\tQ_\\Delta^{(1,1)}(t) =\\; & q_b \\left[ \\frac{e^{2at}-1}{4a}\n\t\\left( 1+\\frac{c^2}{b^2} \\right) + \\frac{e^{2at}\\sin2bt}{4(a^2+b^2)}\n\t\\left( \\frac{b^2-c^2+2ac}{b} \\right) \\right. \\\\\n\t&\\left. + \\frac{e^{2at}\\cos2bt-1}{4(a^2+b^2)}\n\t\\left( \\frac{ab^2-ac^2+2b^2c}{b^2} \\right) \\right] \\\\\n\t& + \\frac{q_d}{b^2} \\left( \\frac{e^{2at}-1}{4a} -\n\t\\frac{e^{2at}(b\\sin2bt + a\\cos2bt) - a}{4(a^2+b^2)} \\right)\n\\end{split} \\\\\n\\begin{split}\n\tQ_\\Delta^{(2,2)}(t) =\\; & q_d \\left[ \\frac{e^{2at}-1}{4a}\n\t\\left( 1+\\frac{c^2}{b^2} \\right) + \\frac{e^{2at}\\sin2bt}{4(a^2+b^2)}\n\t\\left( \\frac{b^2-c^2+2ac}{b} \\right) \\right. \\\\\n\t&\\left. + \\frac{e^{2at}\\cos2bt-1}{4(a^2+b^2)}\n\t\\left( \\frac{ab^2-ac^2+2b^2c}{b^2} \\right) \\right] \\\\\n\t& + \\frac{q_b \\omega_n^4}{b^2} \\left( \\frac{e^{2at}-1}{4a} -\n\t\\frac{e^{2at}(b\\sin2bt + a\\cos2bt) - a}{4(a^2+b^2)} \\right)\n\\end{split} \\\\\n\\begin{split}\n\tQ_\\Delta^{(1,2)}(t) =\\; & \\frac{q_b \\omega_n^2}{b^2} \\left[ \\frac{c}{4a}\n\t\\left( 1 - e^{2at} \\right)\n\t+ \\frac{e^{2at} \\left[ (bc-ab)\\sin2bt + (ac-b^2)\\cos2bt \\right]\n\t-(ac-b^2)}{4(a^2+b^2)} \\right] \\\\\n\t& + \\frac{q_d}{b^2} \\left[ \\frac{c}{4a} \\left( 1 - e^{2at} \\right)\n\t+ \\frac{e^{2at} \\left[ (ab+bc)\\sin2bt + (ac-b^2)\\cos2bt \\right]\n\t-(ac-b^2)}{4(a^2+b^2)} \\right].\n\\end{split}\\end{align}\n\nExamining the solution given above, we see that the parameter $a$ governs the rate of decay of all of the exponential terms.  Therefore, we define the ``rise time'' as that interval within which the transient response of the covariance will reach a close approximation to the above steady-state value; thus, we define the rise time as follows:\n\\begin{equation}\n\tt_r = -\\frac{3}{a}.\n\\end{equation}\n\nNext, we note that all of the trigonometric terms are modulated by $2b$; thus we may view this value as a characteristic damped frequency of the coupled system.  The period of the oscillation, $\\Pi$, is then\n\\begin{equation}\n\t\\Pi = \\pi/b\n\\end{equation}\n\nIn the limit as $t\\rightarrow\\infty$, all the exponential terms in the analytical solution die out, so that the steady-state value of the covariance simplifies to:\n\\begin{equation}\n\tP(\\infty) = -\\frac{1}{4a(a^2+b^2)}\n\t\\left[\\begin{array}{cc}\n\t\tq_d + (2a^2 + b^2 + c^2 - 2ac) q_b & \\beta (q_d + q_b \\omega_n^2) \\\\\n\t\t\\beta (q_d + q_b \\omega_n^2) & (2a^2 + b^2 + c^2 + 2ac) q_d\n\t\t+ q_b \\omega_n^4\n\t\\end{array}\\right]\n\\end{equation} ", "meta": {"hexsha": "ad228fc68920edd289cee2be2af016e5ecb6f2f1", "size": 32752, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/SystemDocs/MathematicalSpecification/MeasurementErrorModeling.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/MeasurementErrorModeling.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/MeasurementErrorModeling.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": 61.9130434783, "max_line_length": 786, "alphanum_fraction": 0.7027051783, "num_tokens": 10667, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9273633016692238, "lm_q2_score": 0.810478913248044, "lm_q1q2_score": 0.7516084009229904}}
{"text": "The previous chapter introduced a probabilistic framework that can be used to design algorithms for robot localization and state estimation. The chapter concluded with the introduction of the Bayes filter, which is a fundamental algorithm for maintaining and updating a belief distribution (a probability distribution over possible states). While the Bayes filter is generally intractable to implement in practice, it lays a mathematical foundation for the development of algorithms that can exploit structure or other approximations to generate tractable approaches. One such example is the discrete Bayes filter, which assumes that the number of possible states is finite such that the belief distribution can be represented by simply storing the probability of each state individually. This type of distribution is referred to as \\textit{non-parametric} since the belief distribution is not required to have a particular structure.\n\nAlternatively, it is possible to develop tractable algorithms for probabilistic localization and state estimation by leveraging \\textit{parametric} belief distributions. Parametric distributions are distributions that are fully specified by a fixed number of parameters, for example Gaussian distributions are defined by the mean and covariance parameters. These \\textit{parametric filters} can generally be viewed as practical implementations of Bayes filter that exploit structure for efficiency, and include the Kalman filter family of algorithms.\n\n\\notessection{Parametric Filters}\nParametric filters\\cite{ThrunBurgardEtAl2005} are a family of algorithms for robot localization and state estimation that model the robot's belief with parametric distributions. Therefore, as the robot's state evolves and new measurement information arrives, updating the belief distribution is accomplished by simply updating the parameters that define the distribution. This can lead to practically implementable algorithms since the number of parameters is generally not too large. For example, a Gaussian distribution in one dimension only requires the specification of two parameters: the mean and standard deviation. Yet with these two parameters a probability distribution is defined over an infinite number of values! This is an example of how parametric filters exploit structure for efficiency.\n\n\\subsection{Gaussian Distribution}\nThe Gaussian distribution (also referred to as a normal distribution) is likely the most commonly used parametric distribution in many disciplines, including robotics. The probability density function for a one-dimensional (univariate) Gaussian distribution is given by:\n\\begin{equation}\np(x) = \\frac{1}{\\sqrt{2\\pi \\sigma^2}} e^{-\\frac{1}{2}\\frac{(x-\\mu)^2}{\\sigma^2}},\n\\end{equation}\nwhere the parameters are the mean $\\mu$ and standard deviation $\\sigma$ (the quantity $\\sigma^2$ is referred to as the variance). A shorthand notation for saying that a random variable $X$ is distributed according to a Gaussian (normal) distribution is $X \\sim \\mathcal{N}(\\mu,\\sigma^2)$.\nFor the multi-dimensional case, the multivariate Gaussian distribution is defined by the probability density function:\n\\begin{equation}\np(\\x) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bSigma)}} \\text{exp}\\big( -\\frac{1}{2}(\\x-\\bmu)^\\top  \\bSigma^{-1} (\\x-\\bmu) \\big),\n\\end{equation}\nwhere $\\x\\in \\R^n$ and the parameters are the mean $\\bmu \\in \\R^n$ and the covariance matrix $\\bSigma \\in \\R^{n \\times n}$. Again, a shorthand to say a random variable $X$ is distributed according to the multivariate Gaussian distribution is $X \\sim \\mathcal{N}(\\bmu,\\bSigma)$. These distributions are represented graphically for the univariate and bivariate case in Figure \\ref{fig:Gaussians}.\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=.85\\textwidth]{tex/figs/ch14_figs/gaussians.png}\n\\caption{Univariate and multivariate Gaussian distributions.}\n\\label{fig:Gaussians}\n\\end{figure}\nThese distributions exhibit several important properties which make them particularly attractive for algorithm development:\n\\begin{enumerate}\n    \\item The affine transformation of a Gaussian random variable is also a Gaussian random variable. In particular, suppose the random variable $X$ has a multivariate Gaussian distribution with mean $\\bmu$ and covariance $\\bSigma$. Then the random variable $Y$ resulting from an affine transformation:\n    \\begin{equation*}\n        Y = AX + b,\n    \\end{equation*}\n    also has a multivariate Gaussian distribution with expected value $A\\bmu + b$ and covariance $A\\bSigma A^\\top $. In other words, if $X \\sim \\mathcal{N}(\\bmu, \\bSigma)$ then $Y \\sim \\mathcal{N}(A\\bmu+b, A\\bSigma A^\\top )$.\n    \\item The sum of two independent Gaussian random variables is also a Gaussian random variable. In particular, suppose $X_1$ and $X_2$ have multivariate Gaussian distributions with means $\\bmu_1$ and $\\bmu_2$ and covariances $\\bSigma_1$ and $\\bSigma_2$. Then the random variable $Y$ given by the sum:\n    \\begin{equation*}\n        Y = X_1 + X_2,\n    \\end{equation*}\n    also has a multivariate Gaussian distribution with expected value $\\bmu_1 + \\bmu_2$ and covariance $\\bSigma_1 + \\bSigma_2$. In other words, if $X_1 \\sim \\mathcal{N}(\\bmu_1, \\bSigma_1)$ and $X_2 \\sim \\mathcal{N}(\\bmu_2, \\bSigma_2)$ then $Y \\sim \\mathcal{N}(\\bmu_1 + \\bmu_2, \\bSigma_1 + \\bSigma_2)$.\n    \\item The product of two Gaussian random variables is also a Gaussian random variable.\n\\end{enumerate}\n\n\\subsection{Kalman Filter}\nThe Kalman filter is an extremely well known algorithm for state estimation that leverages the Gaussian distribution for efficiency. Unlike the discrete Bayes filter from the previous chapter, this filter can be applied to problems with \\textit{continuous} states.\nIn particular, a multivariate Gaussian distribution is used to parameterize the belief distribution over possible states, in other words the state $\\x_t \\sim \\mathcal{N}(\\bmu_t, \\bSigma_t)$, and in long form this can be expressed as:\n\\begin{equation*}\nbel(\\x_t) = p(\\x_t) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bSigma_t)}} \\text{exp}\\big( -\\frac{1}{2}(\\x_t-\\bmu_t)^\\top  \\bSigma_t^{-1} (\\x_t-\\bmu_t) \\big).\n\\end{equation*}\n\n\\subsubsection{Assumptions}\nTo ensure that the belief \\textit{remains} Gaussian after the prediction and measurement update steps of the filtering algorithm, several additional assumptions are required.\nFirst, it is assumed that the initial belief $bel(\\x_0)$ is Gaussian with $\\x_0 \\sim \\mathcal{N}(\\bmu_0, \\bSigma_0)$ and that the state transition model is linear and is given by:\n\\begin{equation} \\label{eq:KFdynamics}\n    \\x_t = A_t \\x_{t-1} + B_t \\bu_t + \\bm{\\epsilon}_t,\n\\end{equation}\nwhere $\\x_{t-1}$ is the previous state, $\\bu_t$ is the most recent control input, and $\\bm{\\epsilon}_{t}$ is an independent \\textit{process noise} that is normally distributed with $\\bm{\\epsilon}_t \\sim \\mathcal{N}(\\bm{0},\\bm{R}_t)$.\nBecause of the properties of the Gaussian distribution presented earlier, this affine model preserves the Gaussian structure. In particular, the state transition model can be explicitly written as:\n\\begin{equation*}\np(\\x_t \\mid \\x_{t-1}, \\bu_t) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bm{R}_t)}} \\text{exp}\\big( -\\frac{1}{2}(\\x_t-A_t \\x_{t-1} - B_t \\bu_t)^\\top  \\bm{R}_t^{-1} (\\x_t-A_t \\x_{t-1} - B_t \\bu_t) \\big).\n\\end{equation*}\nIn other words, this can be expressed in shorthand as $\\x_t \\sim \\mathcal{N}(A_t \\x_{t-1} + B_t \\bu_t, \\bm{R}_t)$.\n\nSecond, the measurement model is also assumed to be linear, which again preserves the Gaussian structure:\n\\begin{equation} \\label{eq:measure}\n\\z_t = C_t \\x_t + \\bm{\\delta}_t,\n\\end{equation}\nwhere $\\bm{\\delta}_t$ is an independent measurement noise that is normally distributed with $\\mathcal{N}(\\bm{0},\\bm{Q}_t)$.\nAgain, this implies the measurement model can be expressed probabilistically as:\n\\begin{equation*}\np(\\z_t \\mid \\x_t) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bm{Q}_t)}} \\text{exp}\\big( -\\frac{1}{2}(\\z_t-C_t\\x_t)^\\top  \\bm{Q}_t^{-1} (\\z_t-C_t\\x_t) \\big),\n\\end{equation*}\nand in shorthand as $\\z_t \\sim \\mathcal{N}(C_t \\x_{t}, \\bm{Q}_t)$.\n\nTo summarize, if the belief is modeled as a Gaussian distribution and the state transition and measurement models are both linear with Gaussian noise, then the Bayes filter updates can be applied and the belief will always remain Gaussian (i.e. the prediction and measurement correction steps will not warp or alter the \\textit{structure} of the belief distribution)! This results in a very practically efficient algorithm since now only the parameters $\\bmu$ and $\\bSigma$ need to be updated by the algorithm.\n\n\n\\subsubsection{Algorithm}\nThe Kalman filter algorithm is a recursive Bayes filter whose prediction and measurement correction steps take on a special form due to the structure of the Gaussian belief distributions and the assumptions listed above.\nIn particular, the Kalman filter algorithm is given in Algorithm \\ref{alg:KF}.\n\n\\begin{algorithm}[ht]\n \\KwData{$\\bmu_{t-1}, \\bSigma_{t-1}, \\bu_{t},\\z_{t}$}\n \\KwResult{$\\bmu_t, \\bSigma_t$}\n $\\bar{\\bmu}_t = A_t\\bmu_{t-1}+B_t \\bu_t$\\\\\n $\\bar{\\bSigma}_t = A_t\\bSigma_{t-1} A_t^{T} + \\bm{R}_t$\\\\\n $K_t = \\bar{\\bSigma}_{t}C_t^{T}(C_t\\bar{\\bSigma}_{t}C_t^{T}+\\bm{Q}_t)^{-1}$\\\\\n $\\bmu_t = \\bar{\\bmu}_t + K_t(\\z_t-C_t\\bar\\bmu_{t})$\\\\\n $\\bSigma_t = (I-K_tC_t )\\bar{\\bSigma}_t$\\\\\n \\Return $\\bmu_t, \\bSigma_t$\n \\caption{Kalman Filter Algorithm}\n \\label{alg:KF}\n\\end{algorithm}\nIn this algorithm, the first two steps define the predicted mean $\\bar{\\bmu}_t$ and covariance $\\bar{\\bSigma}_t$, and the remaining steps perform the measurement correction. The matrix $K_t$ that is computed for the measurement correction is typically referred to as the \\textit{Kalman gain}.\n\n\\subsubsection{Practical Considerations}\nDue to the exploitation of the Gaussian distribution, the Kalman filter is a computationally efficient algorithm that can handle continuous state values. However, the consideration of Gaussian beliefs also restricts the flexibility of the probabilistic model. In particular, the belief is forced to be unimodal which may limit performance. Additionally, the assumption about the linearity of the state transition and measurement models may not be very accurate for some robots and certain sensors, which can make the Kalman filter not perform well for some robotics applications. \n\n\\subsubsection{Derivation}\nWhile it is possible to derive the Kalman filter algorithm by evaluating the Bayes filter updates from the previous chapter (i.e. computing the integral of $p(\\x_t \\mid \\x_{t-1}, \\bu_t) p(\\x_{t-1}$, etc.), it is more intuitive to directly leverage the properties of Gaussians presented in the preceding section. First, from the prior belief distribution $bel(\\x_{t-1}) \\sim \\mathcal{N}(\\bmu_{t-1},\\bSigma_{t-1})$ the predicted belief $\\overline{bel}(\\x_{t-1})$ can be computed by using the affine transformation property of Gaussian random variables and the sum of two independent Gaussian random variables property. Specifically, these properties can be applied to the assumed linear state transition model \\eqref{eq:KFdynamics} to give:\n\\begin{equation*}\n\\begin{split}\n\\bar{\\bmu}_t &= A_t \\bmu_{t-1} + B_t\\bar{\\bu}_t + \\bm{0}, \\\\\n\\end{split}\n\\end{equation*}\nwhere the $\\bm{0}$ is the mean of the independent noise $\\bm{\\epsilon}_t \\sim \\mathcal{N}(\\bm{0},\\bm{R}_t)$. The covariance properties can similarly be used to give:\n\\begin{equation*}\n\\begin{split}\n\\bar{\\bSigma}_t &= A_t \\bSigma_{t-1}A_t^\\top  + \\bm{R}_t. \\\\\n\\end{split}\n\\end{equation*}\n\nFor the measurement update it is possible to again use the properties of Gaussians to simplify the derivation of the Kalman filter measurement correction step. In particular, that the product of two Gaussians is also Gaussian. In fact, the product of the two Gaussians:\n\\begin{equation*}\n\\begin{split}\nbel(x_t) = p(\\z_t \\mid \\x_t)\\overline{bel}(\\x_t) &= \\mathcal{N}(C_t\\x_t,\\bm{Q}_t) \\mathcal{N}(\\bar{\\bmu}_{t},\\bar{\\bSigma}_{t}), \\\\\n\\end{split}\n\\end{equation*}\ncan be expressed as:\n\\begin{equation*}\n\\begin{split}\nbel(x_t) = \\eta\\: \\text{exp}\\big(-\\frac{1}2 J_t \\big),\n\\end{split}\n\\end{equation*}\nwhere $\\eta$ is a normalization constant and:\n\\begin{equation*}\n    J_t = (\\z_t-C_t\\x_t)^\\top  \\bm{Q}_t^{-1} (\\z_t-C_t\\x_t) + (\\x_t-\\bar{\\bmu}_t)^\\top  \\bar{\\bSigma}_t^{-1} (\\x_t-\\bar{\\bmu}_t).\n\\end{equation*}\nTo determine the mean $\\bmu_t$ and covariance $\\bSigma_t$ of this new Gaussian, one simple approach is just take the first and second derivative of $J_t$ with respect to $\\x_t$. The mean is found where the first derivative is zero, and the covariance is the (inverse) of the constant second derivative:\n\\begin{equation*}\n\\begin{split}\n0 &= -C_t^\\top  \\bm{Q}_t^{-1}(\\z_t - C_t \\bmu_t) + \\bar{\\bSigma}_t^{-1}(\\bmu_t - \\bar{\\bmu}_t), \\\\   \n\\bSigma_t^{-1} &= C_t^\\top  \\bm{Q}_t^{-1} C_t + \\bar{\\bSigma}_t^{-1}.\n\\end{split}\n\\end{equation*}\nThrough some algebraic manipulation the mean can be written in terms of the covariance $\\bSigma_t$:\n\\begin{equation*}\n\\begin{split}\n\\bmu_t &= \\bar{\\bmu}_t + \\bSigma_t C_t^\\top  \\bm{Q}_t^{-1}(\\z_t - C_t \\bar{\\bmu}_t), \\\\\n\\end{split}\n\\end{equation*}\nand of course the covariance can be written as:\n\\begin{equation*}\n\\begin{split}\n\\bSigma_t &= (C_t^\\top  \\bm{Q}_t^{-1} C_t + \\bar{\\bSigma}_t^{-1})^{-1}.\n\\end{split}\n\\end{equation*}\nWhile it is technically possible to stop here, this is not quite the form of the Kalman filter equations. In particular a few more algebraic steps are needed, based on the matrix inversion lemma result:\n\\begin{equation*}\n(C_t^\\top  \\bm{Q}_t^{-1} C_t + \\bar{\\bSigma}_t^{-1})^{-1} = \\bar{\\bSigma}_t - \\bar{\\bSigma}_tC_t^\\top (C_t\\bar{\\bSigma}_tC_t^\\top  + \\bm{Q}_t)^{-1}C_t\\bar{\\bSigma}_t.\n\\end{equation*}\nBy choosing to define the Kalman gain as $K_t = \\bar{\\bSigma}_{t}C_t^{T}(C_t\\bar{\\bSigma}_{t}C_t^{T}+\\bm{Q}_t)^{-1}$ it can be seen that the covariance can be expressed as:\n\\begin{equation*}\n\\begin{split}\n\\bSigma_t &= \\bar{\\bSigma}_t - K_tC_t\\bar{\\bSigma}_t,\n\\end{split}\n\\end{equation*}\nThrough some additional algebra, the expression for the mean can also be expressed in terms of the Kalman gain and simplified to its final form:\n\\begin{equation*}\n\\bmu_t = \\bar{\\bmu}_t + K_t(\\z_t-C_t\\bar\\bmu_{t}).\n\\end{equation*}\nFor more details on the algebraic steps see Thrun et al.\\cite{ThrunBurgardEtAl2005}.\n\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Extended Kalman Filter (EKF)}\nThe extended Kalman filter (EKF) is a modified version of the Kalman filter that revisits the assumption of linearity for the state transition and measurement models. This extension still exploits the Gaussian distribution to represent the belief in a computationally efficient parametric way, but by generalizing to more complex models the EKF can be applied to a wider variety of robotics state estimation and localization problems. In particular, the EKF considers general nonlinear state transition and measurement models defined as:\n\\begin{equation}\n\\begin{split}\n\\x_t &= g(\\bu_t, \\x_{t-1}) + \\bm{\\epsilon}_{t}, \\\\\n\\z_t &= h(\\x_t) + \\bm{\\delta}_{t},\n\\end{split}\n\\end{equation}\nwhere again $\\bm{\\epsilon}_{t}\\sim \\mathcal{N}(\\bm{0},\\bm{R}_t)$ and $\\bm{\\delta}_{t}\\sim \\mathcal{N}(\\bm{0},\\bm{Q}_t)$ are normally distributed noise terms.\n\nThe EKF handles these nonlinear functions by taking advantage of their first order Taylor series expansions (which are linear functions, similar to those used in the Kalman filter). In particular the Taylor series expansion of the state transition model $g$ is performed about the \\textit{most likely state} from the current belief distribution, which is the expected value $\\bmu_{t-1}$:\n\\begin{equation*}\n\\begin{split}\ng(\\bu_t, \\x_{t-1}) &\\approx g(\\bu_t, \\bmu_{t-1}) + G_t (\\x_{t-1}-\\bmu_{t-1}), \\\\\n\\end{split}\n\\end{equation*}\nwhere $G_t = \\nabla_{\\x} g(\\bu_t, \\bmu_{t-1})$ is the Jacobian of $g$ evaluated at $\\bmu_{t-1}$. From this linear approximation the state transition model can be expressed as:\n\\begin{equation*}\np(\\x_t \\mid \\x_{t-1}, \\bu_t) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bm{R}_t)}} \\text{exp}\\big( -\\frac{1}{2}\\Delta \\x_t^\\top  \\bm{R}_t^{-1} \\Delta \\x_t \\big),\n\\end{equation*}\nwhere\n\\begin{equation*}\n\\Delta \\x_t = \\x_t-g(\\bu_t, \\bmu_{t-1}) - G_t (\\x_{t-1}-\\bmu_{t-1}).\n\\end{equation*}\nFrom this result, the linear predictions that are used in the Kalman filter algorithm can be replaced by the nonlinear generalizations:\n\\begin{equation*}\n\\begin{split}\n\\bar{\\bmu}_t &= g(\\bu_t,\\bmu_{t-1}), \\\\\n\\bar{\\bSigma}_t &= G_t\\bSigma_{t-1} G_t^{T} + \\bm{R}_t.\n\\end{split}\n\\end{equation*}\nAs can be seen the prediction of the new mean is simply an evaluation of the nonlinear function $g$, and the updated covariance is very similar to the Kalman filter but leverages the Jacobian $G_t$.\n\nA very similar procedure is used for the measurement corrections. The measurement model is also Taylor series expanded to yield (this time about the \\textit{predicted} point $\\bar{\\bmu}_t$):\n\\begin{equation*}\n\\begin{split}\nh(\\x_t) \\approx h(\\bar{\\bmu}_t) + H_t (\\x_{t}-\\bar{\\bmu}_{t}), \\\\\n\\end{split}\n\\end{equation*}\nwhere $H_t = \\nabla_{\\x} h(\\bar{\\bmu}_{t})$ is the Jacobian of $h$ evaluated at $\\bar{\\bmu}_{t}$. The measurement model can then be expressed using this approximation as:\n\\begin{equation*}\np(\\z_t \\mid \\x_t) = \\frac{1}{\\sqrt{\\text{det}(2\\pi \\bm{Q}_t)}} \\text{exp}\\big( -\\frac{1}{2}\\Delta \\z_t^\\top  \\bm{Q}_t^{-1} \\Delta \\z_t \\big),\n\\end{equation*}\nwhere $\\Delta \\z_t = \\z_t-h(\\bar{\\bmu}_t) - H_t (\\x_{t}-\\bar{\\bmu}_{t})$. From this result the measurement correction in the EKF can be shown to be similar to the Kalman filter, but where the Jacobians $H_t$ are used:\n\\begin{equation*}\n\\begin{split}\n\\bmu_t &= \\bar{\\bmu}_t + K_t(\\z_t - h(\\bar{\\bmu}_{t})), \\\\\n\\bSigma_t &= (I - K_t H_t)\\bar{\\bSigma}_t,\n\\end{split}\n\\end{equation*}\nwhere the Kalman gain is $K_t = \\bar{\\bSigma}_{t}H_t^{T}(H_t\\bar{\\bSigma}_{t}H_t^{T}+\\bm{Q}_t)^{-1}$.\n\n\\subsubsection{Algorithm}\nThe extended Kalman filter algorithm is quite similar to the Kalman filter algorithm outlined in Algorithm \\ref{alg:KF}. In particular the main differences are that the updates use the nonlinear functions and their Jacobians rather than assuming strictly linear models. The EKF algorithm is outlined in Algorithm \\ref{alg:ekf}.\n\\begin{algorithm}[ht]\n \\KwData{$\\bmu_{t-1}, \\bSigma_{t-1}, \\bu_{t},\\z_{t}$}\n \\KwResult{$\\bmu_t, \\bSigma_t$}\n $\\bar{\\bmu}_t = g(\\bu_t,\\bmu_{t-1})$\\\\\n $\\bar{\\bSigma}_t = G_t\\bSigma_{t-1} G_t^{T} + \\bm{R}_t$\\\\\n $K_t = \\bar{\\bSigma}_{t}H_t^{T}(H_t\\bar{\\bSigma}_{t}H_t^{T}+\\bm{Q}_t)^{-1}$\\\\\n $\\bmu_t = \\bar{\\bmu}_t + K_t(\\z_t - h(\\bar{\\bmu}_{t}))$\\\\\n $\\bSigma_t = (I - K_t H_t)\\bar{\\bSigma}_t$\\\\\n \\Return $\\bmu_t, \\bSigma_t$\n \\caption{Extended Kalman Filter Algorithm}\n \\label{alg:ekf}\n\\end{algorithm}\n\n\\subsubsection{Practical Considerations}\nThe extended Kalman filter can provide more accurate results than the Kalman filter in many applications due to its ability to consider more general nonlinear models. However, the approximation of the nonlinear models by a Taylor series expansion can lead to the filter to diverge if the approximation is not accurate enough.\nAdditionally, the EKF still suffers from the same unimodal modeling assumption as the Kalman filter since the beliefs are still represented by a single Gaussian distribution.\n\n\\subsection{Unscented Kalman Filter}\nThe unscented Kalman filter (UKF) is another variation of the Kalman filter (still uses Gaussian distribution to parameterize the belief). This filter is also similar to the EKF in that it can handle nonlinear state transition and measurement models. However, this filter improves upon the EKF by not relying on Taylor series expansions, which can cause filter divergence due to approximation errors. \nThis is accomplished by representing the Gaussian through a set of \\textit{sigma-points} that are transformed through the nonlinear functions. Once each sigma-point has been updated, a new Gaussian distribution is computed to represent the updated belief.\n\n\\subsection{Exercises}\n\\subsubsection{EKF Localization}\nComplete \\textit{Problem 1: EKF Localization} located in the online repository:\n\n\\vspace{\\baselineskip}\n\n\\url{https://github.com/PrinciplesofRobotAutonomy/AA274A_HW4},\n\n\\vspace{\\baselineskip}\n\nwhere you will implement an EKF for robot localization based on linear feature extraction and a map of known features.", "meta": {"hexsha": "7dc1d081f555762614dc3e253e7106fedefd4eac", "size": 20269, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch14.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/ch14.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/ch14.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": 82.0607287449, "max_line_length": 934, "alphanum_fraction": 0.741526469, "num_tokens": 5851, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9019206765295399, "lm_q2_score": 0.8333245953120233, "lm_q1q2_score": 0.7515926827725251}}
{"text": "\\chapter{Complex Analysis}\nA simple algebraic equation like $x^{2}=-1$ may not have a real solution. Introducing complex numbers validates the existence of 'root' for every polynomial with a positive degree . Which then proves the fundamental theorem of algebra. The idea of complex numbers are widely used in Physics and Mathematics.\n\\begin{definition}\n\tA number of the form {${x+i y}$} , where $x$ and $y$ are real numbers and $i=\\sqrt{(-1)},$ is called a complex number.\n\\end{definition}\n\t\\textbf{\\large Real Part\\ \\hspace{1.08cm}:} $x$ is called the real part of the complex number,  $x+i y$ and is written as,\\ ${{R(x+i y)}}$.\\\\\\\\ \n\t\\textbf{\\large Imaginary Part\\ :} $y$ is called the imaginary part of the complex number and is written as,\\ ${I(x+i y)}$.\n\t\\section{Representation of a Complex number}\nThe point whose cartesian coordinates are $(x, y)$ uniquely\nrepresents the complex number, {${z=x+i y}$} on the complex plane $z$. The diagram in which this representation is carried out is called the Argand's diagram. It's shown in the figure \\ref{Argand Diagram}.  Since $x$ is the real part of $z$ we call the $x$ -axis the real axis. Likewise, the $y$ -axis is the imaginary axis.\n\n\t\t\\begin{figure}[H]\n\t\t\t\t\\begin{center}\n\t\t\t\\includegraphics[width=0.30\\textwidth]{cn1}\n\t\t\t\t\\end{center}\n\t\t\t\\caption{Argand Diagram}\n\t\t\t\\label{Argand Diagram}\n\t    \\end{figure}\n    In terms of the polar coordinates  , we have\n    \\begin{align}\n    x&=r \\cos \\theta, \\quad y=r \\sin \\theta\\\\\n    z&=x+\\text { iy }=re^{i\\theta} \\notag \\\\&=r(\\cos \\theta+i \\sin \\theta)\n    \\label{Euler's equation}\n    \\end{align}\n    Then, the  equation \\ref{Euler's equation} is known as, Euler's formula\n    \\begin{figure}[H]\n    \t\\begin{minipage}{0.40\\textwidth}\n    \t\t\\begin{center}\n    \t\t\\includegraphics[width=0.70\\textwidth]{cn2}\n    \t\\end{center}\n    \t\\end{minipage}\\hfil\n    \t\\begin{minipage}{0.40\\textwidth}\n    \t\\begin{center}\n    \t\t\\includegraphics[width=0.70\\textwidth]{cn3}\n    \t\\end{center}\n    \\end{minipage}\n    \n    \\caption{Polar representation}\n    \\end{figure}\n   \\subsection{Absolute Value}\n    We define the absolute value of a complex number $x+i y$ to be the length ${r}$ of the vector from the origin to $P(x, y)$. \n    $$\n    r=|x+i y|=\\sqrt{x^{2}+y^{2}}\n    $$\n    \\\\\\textbf{Properties:}\n    \\begin{itemize}\n    \t\\item $\\left|z_{1}+z_{2}\\right| \\leq\\left|z_{1}\\right|+\\left|z_{2}\\right|$\n    \t\\item $\\left|z_{1}-z_{2}\\right| \\geq\\left|z_{1}\\right|-\\left|z_{2}\\right|$\n    \t\\item $\\left|z_{1} z_{2}\\right|=\\left|z_{1}\\right|\\left|z_{2}\\right|$\n    \t\\item $\\left|\\frac{z_{1}}{z_{2}}\\right|=\\frac{\\left|z_{1}\\right|}{\\left|z_{2}\\right|}$\n    \\end{itemize}\n    \\subsection{Argument of }\n    The polar angle $\\theta$ is called the {argument} of $z$ and it is written as, $${\\theta=\\arg z }$$ Any integer multiple of $2 \\pi$ may be added to $\\theta$ to produce another appropriate  angle.\\\\From the figure \\ref{Argand Diagram},\n    $${\\theta=\\arg z }=\\tan ^{-1}\\left(\\frac{y}{x}\\right)$$\n    \\\\\\textbf{Properties:}\n    \\begin{itemize}\n    \t\\item $\\operatorname{Arg}\\left(z_{1}  z_{2} \\cdot z_{3} \\ldots \\ldots z_{n}\\right)=\\operatorname{Arg} \\left(z_{1}\\right)+\\operatorname{Arg}  \\left(z_{2}\\right)+\\operatorname{Arg}  \\left(z_{3}\\right)+\\ldots \\ldots . .+\\operatorname{Arg}\\left(z_{n}\\right)$\n    \t\\item $\\operatorname{Arg}\\left(\\frac{z_{1}}{z_{2}}\\right)=\\operatorname{Arg}\\left(z_{1}\\right)-\\operatorname{Arg}\\left(z_{2}\\right)$\n    \\end{itemize}\n\\begin{exercise}\n\tFind the modulus and principal argument of the complex number\n\t$\\frac{1+2 i}{1-(1-i)^{2}}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{1+2 i}{1-(1-i)^{2}}&=\\frac{1+2 i}{1-(1-1-2 i)}=\\frac{1+2 i}{1+2 i}\\\\&=1=1+0 i \\\\\n\t\\therefore \\quad\\left|\\frac{1+2 i}{1-(1-i)^{2}}\\right|&=|1+0 i|=\\sqrt{1^{2}}=1\\\\\n\t\\text{Principal argument of}\\ \\frac{1+2 i}{1-(1-i)^{2}}&= \\text{Principal argument of} \\quad \\left( 1+0 i\\right) \\\\\n\t\\tan ^{-1} \\frac{0}{1}&=\\tan ^{-1} 0\\\\&=0^{\\circ}\n\t\\end{align*}\n\\end{answer}\n     \\subsection{Conjugate of a Complex number}\n\tThe conjugate of a complex number $z$ is represented by, $${\\bar{z}=x-i y}$$\n\t\\begin{note}\\newline \n\t$ \\left. \\right. $ \\hspace{1.5cm}\t\n\t$\\begin{aligned}\n\t\t\\frac{z + \\bar{z}}{2}&=Re\\left\\lbrace z\\right\\rbrace \\\\\n\t\t\\frac{z - \\bar{z}}{2i}&=Im\\left\\lbrace z\\right\\rbrace\\\\\n\t\tz \\cdot \\bar{z}&=|z|^{2}\n\t\t\\end{aligned}$\n\t\\end{note}\n\\section{Algebra of Complex numbers}\nFor two Complex numbers, $a+i b$ and $c+i d $\n\\subsubsection{Equality:}\n\t\\begin{align*}\n\ta+i b&=c+i d \\quad\n\t\\end{align*}\n\tTwo complex numbers $(a, b)$\n and $(c, d)$ are equal if and only $a=c$ and $b=d$.\n \\subsubsection{Addition:} \n \\begin{align*}\n (a+i b)+(c+i d) \\quad&=(a+c)+i(b+d) \\quad\n \\end{align*}\n \\subsubsection{Multiplication:} \\begin{align*}\n (a+i b)(c+i d) &=(a c-b d)+i(a d+b c) \\\\\n c(a+i b)&=a c+i(b c)\n \\end{align*}\n \\textbf{Polar form:} \n \\begin{align*} \n \\text{Let,} \\quad z_{1}&=r_{1}\\left(\\cos \\theta_{1}+i \\sin \\theta_{1}\\right) \\quad \\text{and}\\quad z_{2}=r_{2}\\left(\\cos \\theta_{2}+i \\sin \\theta_{2}\\right)\\\\\n z_{1} . z_{2} &=r_{1} r_{2}\\left(\\cos \\theta_{1}+i \\sin \\theta_{1}\\right)\\left(\\cos \\theta_{2}+i \\sin \\theta_{2}\\right) \\\\ &=r_{1} r_{2}\\left[\\cos \\theta_{1} \\cos \\theta_{2}-\\sin \\theta_{1} \\sin \\theta_{2}+i\\left(\\sin \\theta_{1} \\cos \\theta_{2}+\\cos \\theta_{1} \\sin \\theta_{2}\\right)\\right] \\\\ &=r_{1} r_{1}\\left[\\cos \\left(\\theta_{1}+\\theta_{2}\\right)+i \\sin \\left(\\theta_{1}+\\theta_{2}\\right)\\right], \\end{align*}\n \n \\subsubsection{Division:}\\begin{align*}\n \\frac{c+i d}{a+i b}&=\\frac{(c+i d)(a-i b)}{(a+i b)(a-i b)}\\\\&=\\frac{(a c+b d)+i(a d-b c)}{a^{2}+b^{2}}\\\\\n \\text{Where,}\\quad x&=\\frac{a c+b d}{a^{2}+b^{2}},\\quad \\text{and} \\quad y=\\frac{a d-b c}{a^{2}+b^{2}}\n \\end{align*}\n \n\\section{Important Identities}\n\\subsection{Circular functions of Complex numbers}\n\n\\begin{align*}\n\t\\bullet\\quad\\sin \\theta=\\frac{e^{i \\theta}-e^{-i \\theta}}{2 i}\\quad\\bullet&\\quad\\cos \\theta=\\frac{e^{i \\theta}+e^{-i \\theta}}{2}\\\\\\\\\n\\bullet\\quad\\sin z=\\frac{e^{i z}-e^{-i z}}{2 i}\\quad\\bullet&\\quad\\cos z=\\frac{e^{i z}+e^{-i z}}{2}\n\\end{align*}\n\n\\subsection{Hyperbolic functions of Complex numbers}\n\\begin{alignat*}{2}\n&\\bullet\\quad \\sinh x=\\frac{e^{x}-e^{-x}}{2}\\quad&&\\bullet\\quad \\cosh x=\\frac{e^{x}+e^{-x}}{2}\\\\\n&\\bullet\\quad\\tanh x=\\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}}\\quad&&\\bullet \\quad {\\coth} x=\\frac{e^{x}+e^{-x}}{e^{x}-e^{-x}}\n\\\\\n&\\bullet\\quad{\\operatorname{sech}} x=\\frac{2}{e^{x}+e^{-x}} \\quad&&\\bullet \\quad {\\operatorname{cosech}} x=\\frac{2}{e^{x}-e^{-x}}\\\\\n&\\bullet\\quad\\cosh x+\\sinh x=\\frac{e^{x}+e^{-x}}{2}+\\frac{e^{x}-e^{-x}}{2}=e^{x} \\quad&& \\quad\n\\end{alignat*}\n\\begin{note}\n\\textbf{\\textbf{Relation between Circular and Hyperbolic functions:}}\\\\\\\\\n$\\begin{array}{ll}\\bullet\\quad\\sin i x=i \\sinh x & \\bullet\\quad \\sinh i x=i \\sin x \\\\ \\bullet\\quad\\cos i x=\\cosh x & \\bullet\\quad \\cosh i x=\\cos x \\\\ \\bullet\\quad\\tan i x=i \\tanh x& \\bullet\\quad \\tanh i x=i \\tan x\\end{array}$\n\n\\end{note}\n\n\\begin{theorem}\n\t\\textbf{De Moivre's Theorem:}\n\t\\begin{enumerate}\n\t\t\\item For any integer $n,$ $(\\cos \\theta+i \\sin \\theta)^{n}=\\cos n \\theta+i \\sin n \\theta$\n\t\t\\item \tIf $n$ is a fraction, then $(\\cos n \\theta+i \\sin n \\theta)$ is one of the values .\n\t\\end{enumerate}\n\\end{theorem}\n\\begin{exercise}\n  Express $\\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{(\\sin \\theta+i \\cos \\theta)^{4}}$ in the form $(x+i y)$\n\\end{exercise}\n\\begin{answer}\n\t$$\n\t\\begin{aligned}\n\t\\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{(\\sin \\theta+i \\cos \\theta)^{4}}=&\\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{(i)^{4}\\left(\\cos \\theta+\\frac{1}{i} \\sin \\theta\\right)^{4}} \\\\\n\t=& \\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{(\\cos \\theta-i \\sin \\theta)^{4}}=\\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{[\\cos (-\\theta)+i \\sin (-\\theta)]^{4}} \\\\\n\t=& \\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{\\left[(\\cos \\theta+i \\sin \\theta)^{-1}\\right]^{4}}=\\frac{(\\cos \\theta+i \\sin \\theta)^{8}}{(\\cos \\theta+i \\sin \\theta)^{-4}}=(\\cos \\theta+i \\sin \\theta)^{12} \\\\\n\t=& \\cos 12 \\theta+i \\sin 12 \\theta\n\t\\end{aligned}\n\t$$\n\\end{answer}\n\\begin{note}\n\tSeries expansion of different functions\n\t\\begin{align*}\n\te^{x}&=1+x+\\frac{x^{2}}{2 !}+\\frac{x^{3}}{3 !}+\\frac{x^{4}}{4 !}+\\ldots \\\\\n\t\\sin x&=x-\\frac{x^{3}}{3 !}+\\frac{x^{5}}{5 !}-\\frac{x^{7}}{7 !}+\\ldots \\\\\n\t\\cos x&=1-\\frac{x^{2}}{2 !}+\\frac{x^{4}}{4 !}-\\frac{x^{6}}{6 !}+\\ldots \\\\\n\t\\tan x&=x+\\frac{x^{3}}{3}+\\frac{2 x^{5}}{15}+\\frac{17 x^{7}}{315}+\\frac{62 x^{9}}{2835} +\\cdots\\\\\n\t\\ln (1+x)&=x-\\frac{x^{2}}{2}+\\frac{x^{3}}{3}-\\frac{x^{4}}{4}+\\ldots \\\\\n    \\tan ^{-1}(x)&=x-\\frac{x^{3}}{3}+\\frac{x^{5}}{5}-\\frac{x^{7}}{7}+\\ldots\n\t\\end{align*}\n\t\\end{note}\n\t\\section{Function of a Complex Variable}\n\t\\subsection{Basic Representation}\n\t\\begin{align*}\n\tW&=f(z)=v(x, y)+i v(x, y)\\hspace{4cm}\\text{Real part (u)},\\left(x^{2}-y^{2}\\right)^{2}\\\\\n\tf(z)&=z^{2}=(x+i y)^{2}=\\left(x^{2}-y^{2}\\right)^{2}+i 2 x y\\hspace{3cm}\\text{Imaginary part (v)}, 2 x y\n\t\\end{align*}\n\\subsection{Existance of $\\lim _{z \\rightarrow z_{0}} f(z)$ :}\n\t\tThe limit will exists only if the limiting value is independent of the path along which $z$ approaches $z_0$\n\t\\begin{exercise}\n\t\tFind whether the limit $\\lim _{z \\rightarrow 0} \\frac{z}{|z|}$ exist or not.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tz \\rightarrow 0\\text{ means }&x \\rightarrow 0 \\& y \\rightarrow 0\\\\\n\t\t\\text{\tFor }\\mathrm{z}&=0,\\text{ we have to choose a path passing through a origin.}\n\t\\intertext{\tTherefore, we have choosen a straight line passing through the origin i.e. $y=m x$}\n\t\t\\lim _{z \\rightarrow 0} \\frac{z}{|z|}&=\\lim _{\\substack{z \\rightarrow 0 \\\\ y \\rightarrow 0}} \\frac{x+i y}{\\sqrt{x^{2}+y^{2}}}=\\lim _{x \\rightarrow 0} \\frac{x+i m x}{\\sqrt{x^{2}+m^{2} x^{2}}}=\\frac{1+i m}{\\sqrt{1+m^{2}}}\n\t\t\\intertext{Therefore, the limit depends on m i.e. slope of the straight line. Thus, the limiting values is dependent on the path and the limit does not exists.}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\begin{exercise}\n\t\tCalculate the vahue $\\lim _{z \\rightarrow \\infty} \\frac{i z^{3}+i z-1}{(2 z+3 i)(z-i)^{2}}$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\lim _{z \\rightarrow \\infty} \\frac{i z^{3}+i z-1}{(2 z+3 i)(z-i)^{2}}=\\lim _{z \\rightarrow \\infty} \\frac{z^{3}\\left(i+\\frac{i}{z^{2}}-\\frac{1}{z^{3}}\\right)}{z\\left(2+\\frac{3 i}{z}\\right) z^{2}\\left(1-\\frac{i}{z}\\right)^{2}}=\\frac{i}{2}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\subsection{Differentiability of Complex Function}\n\t\\begin{align*}\n\t\\mathrm{f}^{\\prime}(\\mathrm{z})&=\\underset{\\delta \\mathrm{z} \\rightarrow 0}{\\mathrm{Lt}} \\frac{[\\mathrm{f}(\\mathrm{z}+\\delta \\mathrm{z})-\\mathrm{f}(\\mathrm{z})]}{\\delta \\mathrm{z}}\n\\intertext{\tThe function will be differentiable if limit should exists and it is independent of path along with $\\delta z \\rightarrow 0$.}\n\\text{\tEx: }\\quad \\mathrm{f}(z)&=(4 x+y)+i(4 y-x) \\Rightarrow u=(4 x+y)\\text{ and }v=(4 y-x)\\\\\n\t&\\Rightarrow f(z+\\delta z)=4(x+\\delta x)+(y+\\delta y)+i[4(y+\\delta y)-(x+\\delta x)] \\\\\n\t&\\Rightarrow f(z+\\delta z)-f(z)=4 \\delta x+\\delta y+i(4 \\delta y-\\delta x)\\\\\n\t&\\Rightarrow \\frac{f(z+\\delta z)-f(z)}{\\delta z}=\\frac{4 \\delta x+\\delta y+i(4 \\delta y-\\delta x)}{\\delta z} \\Rightarrow \\frac{\\delta f}{\\delta z}=\\frac{4 \\delta x+\\delta y-i \\delta x+4 i \\delta y}{\\delta x+i \\delta y}\\\\\n\t&\\text{Along real axis : }\\delta x=\\delta z, \\delta y=0, \\Rightarrow \\frac{\\delta f}{\\delta z}=4-i\\\\\n\t&\\text{Along imaginary axis : }i \\delta y=\\delta z, \\delta x=0, \\Rightarrow \\frac{\\delta f}{\\delta z}=4-i\\\\\n\t&\\text{Along a line }: y=x, \\delta y=\\delta x, \\delta z=(1+i) \\delta x, \\Rightarrow \\frac{\\delta f}{\\delta z}=\\frac{5 \\delta x+3 i \\delta x}{(1+i) \\delta \\dot{x}}=\\frac{5+3 i}{1+i}=4-i\n\t\t\\end{align*}\n\t\\section{Complex Analysis Function}\n\tA function $f(z)$ is said to be analytic at a point $z=z_{0}$ if it is single valued and has the derivative at every point in some neighhourhood of $z_{0}$. The function $f(z)$ is said to be analytic in a domain $D$ if it is single valued and is differentiable at every point of domain D.\n\t\\subsection{Cauchy Reamann Equations}\n\t\\begin{align*}\n\t\\intertext{\tFor a function $f(z)=u+i v$ to be analytic at all points in some region ' $\\mathrm{R}$ ', the necessary conditions are:}\n\t\t\\frac{\\partial u}{\\partial x}&=\\frac{\\partial v}{\\partial y} \\text { and } \\frac{\\partial u}{\\partial y}=-\\frac{\\partial v}{\\partial x}\\\\\n\t\t\\text{Sufficient Condition: }&\\frac{\\partial u}{\\partial x}, \\frac{\\partial u}{\\partial y}, \\frac{\\partial v}{\\partial x}, \\frac{\\partial v}{\\partial y}\\text{ are continuous functions of $x$ and $y$.}\\\\\n\t\t\\text{\tDerivative of }\\mathrm{f}(\\mathrm{z}): f^{\\prime}(\\mathrm{z})&=\\frac{\\partial u}{\\partial x}+i \\frac{\\partial v}{\\partial x}=\\frac{\\partial v}{\\partial y}-i \\frac{\\partial u}{\\partial y}\n\t\\end{align*}\n\t\\begin{exercise}\n\t\tCheck whether $f(z)=\\sin z$ is analytic or not.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t&f(z)=\\sin z=\\sin (x+i y)=\\sin x \\cdot \\cos (i y)+\\cos x \\cdot \\sin (i y)=\\sin x \\cdot \\cosh y+i \\cos x \\cdot \\sinh y\\\\\n\t\t&\\text{Therefore, }u=\\sin x \\cdot \\cosh y\\text{ and }v=\\cos x.sinhy \\\\\n\t\t&\\frac{\\partial u}{\\partial x}=\\cos x \\cdot \\cosh y ; \\frac{\\partial u}{\\partial y}=\\sin x \\cdot \\sinh y ; \\frac{\\partial v}{\\partial x}=-\\sin x \\cdot \\sinh y ; \\frac{\\partial v}{\\partial y}=\\cos x \\cdot \\cosh y\\\\\n\t\t&\\text { So, C-R equation is satisfied, given } \\mathrm{f}(\\mathrm{z}) \\text { is analytic. }\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\begin{exercise}\n\t\tIf the real part of a complex analytic function is $u(x, y)=x+\\frac{1}{2}\\left(x^{2}-y^{2}\\right)$, find the corresponding imaginary part.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{\\partial u}{\\partial x}=x+1=\\frac{\\partial v}{\\partial y} & \\Rightarrow v(x, y)=y+x y+f(x) \\\\\n\t\t\\frac{\\partial u}{\\partial y}=-y=-\\frac{\\partial v}{\\partial x} & \\Rightarrow v(x, y)=x y+g(y)\\\\\n\t\\text{\tTherefore, the imaginary }&\\text{part will be }v(x, y)=y+x y+C\n\t\\text{\t( $C=$ numerical constant )}\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\begin{exercise}\n\t\tExample-7: If $f(x, y)=(1+x+y)(1+x-y)+a\\left(x^{2}-y^{2}\\right)-1+2 i y(1-x-a x)$ is a complex analytic function then find the value of ' $a$ '.\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tu(\\mathrm{x}, \\mathrm{y})&=(1+x+y)(1+x-y)+a\\left(x^{2}-y^{2}\\right)-1 \\quad \\Rightarrow \\frac{\\partial u}{\\partial x}=2 x+2+2 a x \\\\\n\t\tv(x, y)&=2 y(1-x-a x) \\quad \\Rightarrow \\frac{\\partial v}{\\partial y}=2(1-x-a x)\\\\\n\t\t\\text{According to Cauchy  }&\\text{ Reamann equation,}\\frac{\\partial \\mathrm{u}}{\\partial \\mathrm{x}}=\\frac{\\partial \\mathrm{v}}{\\partial \\mathrm{y}} \\Rightarrow 4 \\mathrm{x}=-4 \\mathrm{ax} \\Rightarrow \\mathrm{a}=-1\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\begin{exercise}\n\t\tThe harmonic conjugate function of $u(x, y)=2 x(1-y)$ corresponding to a complex analytic function $\\omega=u(x, y)+i v(x, y)$ is given $v(x, y)=\\alpha x^{2}+\\beta y+\\gamma y^{2}$ (Taking the integration constant to be zero).\n\t\tWhich of the following statement is true ?\n\t\t \\begin{tasks}(2)\n\t\t\t\\task[\\textbf{a.}]$\\alpha-\\gamma=\\beta$\n\t\t\t\\task[\\textbf{b.}]$\\alpha+\\gamma+\\beta=0$\n\t\t\t\\task[\\textbf{c.}]$\\alpha+\\gamma=\\beta$\n\t\t\t\\task[\\textbf{d.}] $\\alpha \\gamma \\beta=1$.\n\t\t\\end{tasks}\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tu(x, y)&=2 x(1-y) \\\\\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial x}&=2(1-y)=\\frac{\\partial v}{\\partial y} \\Rightarrow v=2 y-y^{2}+f_{1}(x) \\\\\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial y}&=-2 x=-\\frac{\\partial v}{\\partial x} \\Rightarrow v=x^{2}+f_{2}(y)\n\t\t\\end{align*}\n\t\t\tTherefore, the imaginary part of the complex function $v=x^{2}-y^{2}+2 y$ \\\\Comparing with the question, $\\alpha=1, \\beta=2, \\gamma=-1 \\quad \\Rightarrow \\alpha-\\gamma=\\beta$\n\t\\end{answer}\n\\\n\t\\subsection{Method for Finding Conjugate Function }\n\t\t\\begin{align*}\n\t\t\\textbf{Case 1: }f(z)&=u+i v,\\text{ and $u$ is known.}\\\\\n\t\td v&=\\frac{\\partial v}{\\partial x} d x+\\frac{\\partial v}{\\partial y} d y=-\\frac{\\partial u}{\\partial y} d x+\\frac{\\partial u}{\\partial x} d y \\Rightarrow v=-\\int \\frac{\\partial u}{\\partial y} d x+\\int \\frac{\\partial u}{\\partial x} d y\\\\\n\t\t\\textbf{Case 2: }f(z)&=u+i v,\\text{ and $v$ is known}\\\\\n\t\td u&=\\frac{\\partial u}{\\partial x} d x+\\frac{\\partial u}{\\partial y} d y=\\frac{\\partial v}{\\partial y} d x-\\frac{\\partial v}{\\partial x} d y \\Rightarrow u=\\int \\frac{\\partial v}{\\partial y} d x-\\int \\frac{\\partial v}{\\partial x} d y\n\t\t\\end{align*}\n\t\\begin{exercise}\n\t\t Find the imaginary part of the complex analytic function whose real part is $u(x, y)=x^{3}-3 x y^{2}+3 x^{2}-3 y^{2}+1$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t&\\frac{\\partial u}{\\partial x}=3 x^{2}-3 y^{2}+6 x=\\frac{\\partial v}{\\partial y} \\Rightarrow v=3 x^{2} y-y^{3}+6 x y+f_{1}(x) \\\\\n\t\t&\\frac{\\partial u}{\\partial y}=-6 x y-6 y=-\\frac{\\partial v}{\\partial x} \\Rightarrow v=3 x^{2} y+6 x y+f_{2}(y) \\\\\n\t\t&v(x, y)=3 x^{2} y-y^{3}+6 x y+C\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\subsection{Milne-Thomson Method : (To find Analytic function if either ' $u$ ' or ' $v$ ' is given)}\n\t\\begin{align*}\n\\textbf{\tCase 1:}&\\text{ When 'u' is given,}\\\\\n\t&\\text{(1) Find }\\frac{\\partial u}{\\partial x}=\\phi_{1}(x, y) \\text{and }\\frac{\\partial u}{\\partial y}=\\phi_{2}(x, y)\\\\\n\t&\\text{(2) Replace }\\text{$x$ by $z$ and $y$ by 0 in $\\phi_{1}(x, y)$ and $\\phi_{2}(x, y)$ to get $\\phi_{1}(z, 0)$ and $\\phi_{2}(z, 0)$.}\\\\\n\t&\\text{(3) Find }f(z)=\\int\\left\\{\\phi_{1}(z, 0)-i \\phi_{2}(z, 0)\\right\\} d z+c\\\\\n\\textbf{\tCase 2: }&\\text{When ' $v$ ' is given,}\\\\\n&\\text{\t(1) Find }\\frac{\\partial v}{\\partial x}=\\psi_{2}(x, y)\\text{ and }\\frac{\\partial v}{\\partial y}=\\psi_{1}(x, y)\\\\\n&\\text{(2) Replace }\\text{$x$ by $z$ and $y$ by 0 in $\\psi_{1}(x, y)$ and $\\psi_{2}(x, y)$ to get $\\psi_{1}(z, 0)$ and $\\psi_{1}(z, 0)$.}\\\\\n&\\text{(3) Find }f(z)=\\int\\left\\{\\psi_{1}(z, 0)+i \\psi_{2}(z, 0)\\right\\} d z+c\n\t\\end{align*}\n\t\\begin{exercise}\n\t\tFind the analytical function whose imaginary part is $v(x, y)=e^{x}(x \\cos y-y \\sin y)$\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t\\frac{\\partial v}{\\partial x}=e^{x}(x \\cos y-y \\sin y)+e^{x} \\cos y=\\Psi_{2}(x, y) \\quad& \\Rightarrow \\frac{\\partial v}{\\partial y}=-e^{x} x \\sin y-e^{x}(\\sin y+y \\cos y)=\\Psi_{1}(x, y) \\\\\n\t\t\\Psi_{1}(z, 0)=0 \\text { and } \\Psi_{1}(z, 0)=e^{z} z+e^{z} \\quad& \\Rightarrow f(z)=\\int 0+i\\left[e^{z} z+e^{z}\\right] d z=i z e^{z}+C\n\t\t\\end{align*}\n\t\\end{answer}\n\t\\begin{exercise}\n\t\t If the real part of a complex analytic function $\\mathrm{f}(\\mathrm{z})$ is given as, $u(x, y)=e^{-2 x y} \\sin \\left(x^{2}-y^{2}\\right)$, then $\\mathrm{f}(\\mathrm{z})$ can be written as\n\t\t \\begin{tasks}(2)\n\t\t\t\\task[\\textbf{a.}]$i e^{i^{2}}+C$\n\t\t\t\\task[\\textbf{b.}] $-i e^{i x^{2}}+C$\n\t\t\t\\task[\\textbf{c.}] $-i e^{-i z^{2}}+C$\n\t\t\t\\task[\\textbf{d.}] $i e^{-i i^{2}}+C$\n\t\t\\end{tasks}\n\t\\end{exercise}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\tu(x, y)&=e^{-2 x y} \\sin \\left(x^{-2}-y^{2}\\right) \\\\\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial x}&=e^{-2 x y}(-2 y) \\sin \\left(x^{2}-y^{2}\\right)+e^{-2 x y} \\cos \\left(x^{2}-y^{2}\\right) 2 x=\\phi_{1}(x, y) \\\\\n\t\t\\Rightarrow \\frac{\\partial u}{\\partial y}&=e^{-2 x y}(-2 x) \\sin \\left(x^{2}-y^{2}\\right)+e^{-2 x y} \\cos \\left(x^{2}-y^{2}\\right)(-2 y)=\\phi_{2}(x, y)\\\\\n\t\t\\therefore \\quad \\phi_{1}(z, 0) &=\\cos z^{2} \\cdot 2 z, \\phi_{2}(z, 0)=\\sin z^{2}(-2 z) \\\\\n\t\t\\therefore \\quad f(z) &=\\int\\left(\\cos z^{2} \\cdot 2 z-i \\sin z^{2} \\cdot(-2 z)\\right) d z+c=2 \\int\\left(\\cos z^{2}+i \\sin z^{2}\\right) \\cdot z d z+c \\\\\n\t\t&=2 \\int e^{i z^{2}} \\cdot z d z+c=-i e^{i z^{2}}+c\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{option (b)}\n\t\\end{answer}\n\\subsection{Harmonic Function}\nAny function which satisfies the Laplace's equation, is known as harmonic function. If $u+i v$ is an analytic function, then $u, v$ are conjugate harmonic functions i.e.\n$$\n\\frac{\\partial^{2} u}{\\partial x^{2}}+\\frac{\\partial^{2} u}{\\partial y^{2}}=0 \\text { and } \\frac{\\partial^{2} v}{\\partial x^{2}}+\\frac{\\partial^{2} v}{\\partial y^{2}}=0\n$$\n\\begin{exercise}\n\tFind the values of $\\mathrm{m}, \\mathrm{n}$ such that $f(x, y)=x^{2}+m x y+n y^{2}$ is harmonic in nature.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text { Since, } \\frac{\\partial^{2} f}{\\partial x^{2}}+\\frac{\\partial^{2} f}{d y^{2}}=0 \\Rightarrow 2 n+2=0 \\Rightarrow n=-1 ;^{\\prime} m^{\\prime} \\text { can take any value. }\n\t\\end{align*}\n\\end{answer}\n\\section{Cauchy's Integral Theorem}\nIf a funciion $f(z)$ is analytic and its derivative $f^{\\prime}(z)$ is continuous at all points inside and on a simple closed curve ' $C$ ', then $\\oint_{C} f(z) d z=0$\\\\\n\\subsection{Cauchy's Integral Formula}\n\n\tIf $f(z)$ is analytic within or on a closed curve $\\mathrm{C}$ and if ' $\\mathrm{a}$ ' is any point within ${\\mathrm{C}}$, where $\\frac{f(z)}{z-a}$ is not analytic at $z=a$ then\n\t\\begin{align*}\n\tf(a)&=\\frac{1}{2 \\pi i} \\oint_{C} \\frac{f(z)}{z-a} d z \\qquad \\text { and } f^{\\prime}(a)=\\frac{1}{2 \\pi i} \\oint_{C} \\frac{f(z)}{(z-a)^{2}} d z\\\\\n\t\\text{Similarly, }\\qquad f^{\\prime \\prime}(\\mathrm{a})&=\\frac{2 !}{2 \\pi i} \\oint_{C} \\frac{f(z)}{(z-a)^{3}} d z \\quad\\text{ and } \\mathrm{f}^{\\mathrm{n}}(\\mathrm{a})=\\frac{n !}{2 \\pi i} \\oint_{C} \\frac{f(z)}{(z-a)^{n+1}} d z\n\t\\end{align*}\n\n\\begin{exercise}\n\tEvaluate the integral $\\frac{1}{2 \\pi i} \\oint \\frac{z e^{z}}{(z-a)^{3}}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\frac{1}{2 \\pi i} \\oint \\frac{z e^{z}}{(z-a)^{3}}&=\\left.\\frac{1}{2 \\pi i} 2 \\pi i \\frac{1}{2 !} \\frac{d^{2}}{d z^{2}}\\left(z e^{z}\\right)\\right|_{z=a}\\\\&=\\frac{a e^{a}+2 e^{a}}{2}\\\\&=\\frac{1}{2}(a+{2}) e^{a}\n\t\\end{align*}\n\\end{answer}\n\\section{Power Series Expansion of Complex Function}\n\t\\begin{align*}\n\t\\intertext{Every analytic function which is analytic at $z=z_{0}$ can be expanded into power series about $z=z_{0}$.}\n\tf(z)&=\\sum_{n=0}^{\\infty} a_{n}\\left(z-z_{0}\\right)^{n}=a_{0}+a_{1}\\left(z-z_{0}\\right)+a_{2}\\left(z-z_{0}\\right)^{2}+\\ldots \\ldots\n\t\\intertext{where, $z_{0}$ is the centre of power series.}\n\\end{align*}\n\\subsection{Radius of Convergence}\nImagine a circle of centre $z_{0}$ and radius $r$, then $\\left|z-z_{0}\\right|=R$, \nThe power series is convergent in the region $\\left|z-z_{0}\\right|<R$ (i.e. within the circle) and divergent $\\left|z-z_{0}\\right|>R$ (outside the circle). Therefore, $R$ is known as the radius of convergence of power series and defined as\\\\\n$$R=\\lim _{n \\rightarrow \\infty}\\left|\\frac{a_{n}}{a_{n+1}}\\right|$$\n\\begin{exercise}\n\tFind the radius of convergence of the series\n\t$$\n\t\\frac{z}{2}+\\frac{1.3}{2.5} z^{2}+\\frac{1.3 .5}{2.5 .8} z^{3}+\\ldots \\ldots .\n\t$$\n\\end{exercise}\n\\begin{answer}\n\tThe coefficient of $z^{n}$ of the given power series is given by\n\t\\begin{align*}\n\ta_{n}&=\\frac{1.3 .5 \\ldots(2 n-1)}{2.5 .8 \\ldots(3 n-1)} \\\\\n\ta_{n+1}&=\\frac{1.3 .5 \\ldots(2 n-1)(2 n+1)}{25.8 \\ldots(3 n-1)(3 n+2)}\\\\\n\t\\text{So }\\frac{a_{n+1}}{a_{n}}&=\\frac{2 n+1}{3 n+2}=\\frac{2}{3} \\cdot \\frac{\\left(1+\\frac{1}{2 n}\\right)}{\\left(1+\\frac{2}{3 n}\\right)}\\\\\n\t\\text{Therefore,}\\quad\n\t\\frac{1}{R}&=\\lim _{n \\rightarrow \\infty}\\left|\\frac{a_{n+1}}{a_{n}}\\right|=\\frac{2}{3} \\cdot \\frac{(1+0)}{(1+0)}=\\frac{2}{3} \\Rightarrow R=\\frac{3}{2}\n\t\\end{align*}\n\\end{answer}\n\\subsubsection{Taylor Series Expansion}\nIf a function $\\mathrm{f}(\\mathrm{z})$ is analytic at all points inside and on a circle $C$, with its center at the point ' $a$ ' and radius ' $r$ ', then at each point $z$ inside $C$, the function $f(z)$ can be expanded as,\n\\begin{align*}\n\tf(z) &=f(a)+\\frac{f^{\\prime}(a)}{1 !}(z-a)+\\frac{f^{\\prime \\prime}(a)}{2 !}(z-a)^{2}+\\ldots .+\\frac{f^{n}(a)}{n !}(z-a)^{n}+\\ldots \\\\\n\t& \\Rightarrow f(z)=\\sum_{n=0}^{\\infty} \\frac{f^{n}\\left(z_{0}\\right)}{n !}\\left(z-z_{0}\\right)^{n}\n\\end{align*}\n\\begin{exercise}\n\tExpand the function $\\ln (\\cosh x)$ about the point $x=0$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tf(x)&=f(0)+(x-0) f^{\\prime}(0)+\\frac{1}{2 !}(x-0)^{2} f^{\\prime \\prime}(0)+\\ldots \\ldots \\\\\n\tf^{\\prime}(x)&=\\frac{1}{\\cosh x} \\cdot \\sinh x=\\tanh x, f^{\\prime \\prime}(x)=\\sec h^{2} x \\\\\n\tf^{\\prime \\prime \\prime}(x)&=2 \\operatorname{sech} x(-\\operatorname{sech} x \\tanh x)=-2 \\sec h^{2} x \\tanh x \\\\\n\tf^{\\prime \\prime \\prime}(x)&=4 \\operatorname{sech} h^{2} x \\cdot \\tanh ^{2} x-2 \\sec h^{4} x\\\\\n\t\\text { Therefore, } f(x)&=0+0+\\frac{x^{2}}{2}+0-\\frac{x^{4}}{12}+\\ldots \\ldots=\\frac{x^{2}}{2}-\\frac{x^{4}}{12}+\\ldots . .\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\\section{Laurent Series}\nLet $C_{1}$ and $C_{2}$ be two circles with center at $z_{0}$. Let $f(z)$ be analytic in the region $R$ between the circles. Then $f(z)$ can be expanded in a series of the form,\n\\begin{equation}\nf(z)=a_{0}+a_{1}\\left(z-z_{0}\\right)+a_{2}\\left(z-z_{0}\\right)^{2}+\\cdots+\\frac{b_{1}}{z-z_{0}}+\\frac{b_{2}}{\\left(z-z_{0}\\right)^{2}}+\\cdots \\label{complex1}\n\\end{equation}\nconvergent in $R$. Such a series is called a Laurent series. The \"b\" series in equation \\ref{complex1} is called the principal part of the Laurent series.\\\\\n Consider the Laurent series in equation.\\label{complex1}\n\\begin{align}\nf(z)=1+\\frac{z}{2}+\\frac{z^{2}}{4}+\\frac{z^{3}}{8}+\\cdots+&\\left(\\frac{z}{2}\\right)^{n}+\\cdots \\notag\\\\\n&+\\frac{2}{z}+4\\left(\\frac{1}{z^{2}}-\\frac{1}{z^{3}}+\\cdots+\\frac{(-1)^{n}}{z^{n}}+\\cdots\\right)\\label{complex2}\n\\end{align}\nLet us see where this series converges. First consider the series of positive powers; by the ratio test (see Chapters 1 and 2), this series converges for $|z / 2|<1$, that is, for $|z|<2$. Similarly, the series of negative powers converges for $|1| z \\mid<1$, that is, $|z|>1$. Then both series converge (and so the Laurent series converges) for $|z|$ between 1 and 2 , that is, in a ring between two circles of radii 1 and 2 .\\\\\nWe expect this result in general. The ``$a$'' series is a power series, and a power series converges inside some circle (say $C_{2}$ in Figure .\\ref{Laurent series}). The  ``$b$'' series is a series of inverse powers of $z$, and so converges for $|1 / z|<$ some constant. Thus the ``$b$'' series converges outside some circle. Then a Laurent series converges between two circles (if it converges at all). (Note that the inner circle may be a point and the outer circle may have infinite radius).\n\\begin{figure}[H]\n\t\\centering\n\t\\includegraphics[height=3.7cm,width=7cm]{CN.01}\n\t\\caption{Laurent series}\n\t\\label{Laurent series}\n\\end{figure}\nThe formulas for the coefficients are \n$$\na_{n}=\\frac{1}{2 \\pi i} \\oint_{C} \\frac{f(z) d z}{\\left(z-z_{0}\\right)^{n+1}}, \\quad b_{n}=\\frac{1}{2 \\pi i} \\oint_{C} \\frac{f(z) d z}{\\left(z-z_{0}\\right)^{-n+1}}\n$$\nWhere $C$ is any simple closed curve surrounding $z_{0}$ and lying in $R$. However, this is not usually the easiest way to find a Laurent series. Like power series about a point, the Laurent series (about $z_{0}$ ) for a function in a given annular ring (about $z_{0}$ ) where the function is analytic, is unique, and we can find it by any method we choose. (See examples below.) If $f(z)$ has several isolated singularities, there are several annular rings, $R_{1}, R_{2}, \\cdots$, in which $f(z)$ is analytic; then there are several different Laurent series for $f(z)$, one for each ring. The Laurent series which we usually want is the one that converges near $z_{0}$. If you have any doubt about the ring of convergence of a Laurent series, you can find out by testing the ``$a$'' series and the ``$b$'' series separately.\n\\section{Singularity of Complex Function}\n\\textbf{\\large{Singular Point of an Analytic Function}}\\\\\\\\\nA point at which the function ceases to be analytic is called a singular point.\\\\\n\\begin{example}\n$f(z)=\\frac{1}{(z-2)}$ has a singularity at $\\mathrm{z}=2$.\n\\end{example} \nDifferent kinds of singularities exist.they are,\n\\subsection{Isolated Singularity}\nA point $\\mathrm{z}=\\mathrm{z}_{0}$ is said to be isolated singularity of $f(z)$ if,\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item  $f(z)$ is not analytic at $\\mathrm{z}=\\mathrm{z}_{0}$.\n\t\\item  $f(z)$ is analytic in the neighbourhood of $\\mathrm{z}=\\mathrm{z}_{0}$ i.e. there exists a neighbourhood of $\\mathrm{z}=\\mathrm{z}_{0}$, containing no other singularity.\n\\end{enumerate}\n\n\\begin{example}$\\left. \\right. $\\\\\\\\\n\t\\textbf{(i)} Function $f(z)=\\frac{1}{z}$ is analytic everywhere except at $\\mathrm{z}=0$, therefore $\\mathrm{z}=0$ is an isolated singularity.\\\\\\\\\n\t\\textbf{(ii)} The function $f(z)=\\frac{z+2}{(z-1)(z-2)(z-3)}$ has three isolated singularities at $z=1,2$ and 3 .\n\\end{example}\n\\subsection{Non-isolated Singularity}\nA singular point $z_{0}$ is said to be an non-isolated singularity if $z_{0}$ is not an isolated singular point.\n\\begin{example}$\\left. \\right. $\\\\\\\\\n\t$f(z)=\\frac{1}{\\left[\\sin \\frac{\\pi}{z}\\right]}$\n\t\\begin{align*}\n\tf(z)&=\\frac{1}{\\left[\\sin \\frac{\\pi}{z}\\right]} \\text { is not analytic when } \\sin \\frac{\\pi}{z}=0 \\\\\\frac{\\pi}{\\mathrm{z}}&=\\mathrm{n} \\pi \\\\ z&=\\frac{1}{n}(n=0,1,2,3 \\ldots \\ldots \\ldots \\ldots)\\\\\n\t\\intertext { Thus,$z=0$  is an non-isolated singularity of $ f(z)$ surrounded by a infinite number of other singularity $z=\\frac{1}{n}$}\n\tf(z)&=\\frac{1}{\\sin \\pi / z} \\text { has non-isolated singularity at } \\mathrm{z}=0\n\t\\end{align*}\n\\end{example}\n\n\\subsection{Types of Isolated Singularity}\n If  $\\mathrm{f}(\\mathrm{z})$  is an isolated singular point at  $\\mathrm{z}=\\mathrm{a}$ , the we can expand $ f(\\mathrm{z})$ about $ \\mathrm{z}=\\mathrm{a}$ into laurent series as: \n\\begin{align*}\n\\mathrm{f}(\\mathrm{z})=\\sum_{n=0}^{\\infty} a_{n}(z-a)^{n}+\\sum_{n=1}^{\\infty} \\frac{b_{n}}{(z-a)^{n}}=\\left[a_{0}+a_{1}(z-a)+a_{2}(z-a)^{2}+\\ldots . .\\right]+\\left[\\frac{b_{1}}{(z-a)}+\\frac{b_{2}}{(z-a)^{2}}+\\ldots . .\\right]\n\\end{align*}\nTherefore, three types of singularity exists and they are as follows.\n\\subsubsection{1.\\ Removable Singularity } If the principal part of the Laurrent series expansion of $f(z)$ about $z=a$ contains no term i.e. if $b_{n}=0$ for all ' $n$ ', then $\\mathrm{f}(\\mathrm{z})$ has a removable singularity at $\\mathrm{z}=\\mathrm{a}$. In this case, Laurent series expansion is $f(z)=\\sum_{n=0}^{\\infty} a_{n}(z-a)^{n}$\n\\begin{example}$\\left. \\right. $\\\\\n\tSuppose $f(z)=\\frac{\\sin z}{z}$, then $\\lim _{z \\rightarrow 0}\\left(\\frac{\\sin z}{z}\\right)=1$, therefore, $z=0$ is a removable singularity of $f(z)$.\\\\\n\tAgain, $\\frac{\\sin z}{z}=\\frac{1}{z}\\left(z-\\frac{z^{3}}{3 !}+\\ldots \\ldots \\ldots\\right)=1-\\frac{z^{2}}{3 !}+\\frac{z^{4}}{5 !} \\ldots \\ldots$\\\\\n\tSince, there is no negative term in the laurent series expansion of $f(z)$ about $z=0$, hence $z=0$ is a removable singularity of $f(z)$.\n\\end{example}\n\\subsubsection{2.\\ Non-essential singularity or Pole:} If the principal part of the Laurrent series expansion of $f(z)$ about $z=$ a contains a finite number of terms, saym, i.e. $b_{n}=0$ for all $n>m$, then $f(z)$ has a non-essential singularity or a pole of order ' $m$ ' at $z=a$. A polc of order one is also known as simple pole.\\\\\nThus if $\\mathrm{z}=\\mathrm{a}$ is pole of order mof function $\\mathrm{f}(\\mathrm{z})$, then $\\mathrm{f}(\\mathrm{z})$ will have the Laurent series expansion of the form\n$$\nf(z)=\\sum_{n=0}^{\\infty} a_{n}\\left(z-z_{0}\\right)^{n}+\\sum_{n=1}^{m} b_{n}\\left(z-z_{0}\\right)^{-n}\n$$\n\\begin{example}\n\t$f(z)=\\frac{z}{(z-1)(z+2)^{2}}$ has a simple pole at $z=1$ and a pole of order 2 at $z=-2$.\n\\end{example} \n\\subsubsection{3.\\ Essential singularity: }If the principal part of the Laurrent series expansion of $f(z)$ about $z=a$, contains infinite number of terms i.e. $b_{n} \\neq 0$ for infinitely many values of $n$, then $f(z)$ has an essential singularity at $z=a$.\\\\\n\\begin{example}\n\t$f(z)=e^{1 / 2}$ has an essential singularity at $z=0$, since the expansion $e^{\\frac{1}{z}}=1+\\frac{1}{z}+\\frac{1}{z^{2}} 2 !+\\ldots . .$ is an infinite series of-ve powers of $\\mathrm{z}$.\n\\end{example} \n\\begin{exercise}\n\tExamine the nature of singularity of the functions: (a) $\\sin \\left(\\frac{1}{1-z}\\right)$, (b) $(z-3) \\sin \\left(\\frac{1}{z+2}\\right)$.\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{(a) }&\\sin \\left(\\frac{1}{1-z}\\right)=\\frac{1}{1-z}-\\frac{1}{(1-z)^{3} \\cdot 3 !}+\\frac{1}{(1-z)^{5} \\cdot 5 !}-.\\\\\n&\\text{\tso, $z=1$ is an isolated essential singular point.}\\\\\n\\text { (b) }&(z-3) \\sin \\left(\\frac{1}{z+2}\\right)=(z-3)\\left[\\frac{1}{z+2}-\\frac{1}{(z+2)^{3} \\cdot 3 !}+\\frac{1}{(z+2)^{5} .5 !}-\\ldots \\ldots . .\\right] \\\\ &\\text { so, $\\mathrm{z}=-2$  is an isolated essential point}\n\t\\end{align*}\n\\end{answer}\n\\section{Zero of an Analytic Function}\nA zero of an analytic function $f(z)$ is a value of $z$ such that $$f(z)=0$$\nAn analytic function $\\mathrm{f}(\\mathrm{z})$ is said to have a zero of order ' $\\mathrm{m}$ ' at $\\mathrm{z}=\\mathrm{z}_{0}$ if $\\mathrm{f}(\\mathrm{z})$ is expressible as, $$f(z)\\left(z-z_{0}\\right)^{m} \\phi(z)$$\nwhere $\\phi(z)$ is analytic and $\\phi\\left(z_{0}\\right) \\neq 0$. For $m=1, f(z)$ is said to have a simple zero at $z=z_{0}$\n\n\\section{Residue of Complex Fuction}\n\\subsection{Definition of residue at a pole:}\nLet, $\\mathrm{z}=$ a be a pole of order ' $m$ ' of $\\mathrm{f}(\\mathrm{z})$ and $\\mathrm{C}_{1}$ is a circle of radius ' $r$ ' with center at $\\mathrm{z}=$ a which does not contain singularities except $\\mathrm{z}=\\mathrm{a}$, then $\\mathrm{f}(\\mathrm{z})$ is analytic within the annular region $\\mathrm{r}<|\\mathrm{z}-\\mathrm{a}|<\\mathrm{R}$ can be expanded into Laurrent series within the annulur region as:\n$$f(z)=\\sum_{n=0}^{\\infty} a_{n}(z-a)^{n}+\\sum_{n=1}^{\\infty} b_{n}(z-a)^{-n}$$\nCo-efficient $\\mathrm{b}_{n}$ is known as residue of $\\mathrm{f}(\\mathrm{z})$ at $\\mathrm{z}=\\mathrm{a}$ i.e.\n\\begin{equation}\n\\text{Res.} \\mathrm{f}(\\mathrm{z}=\\mathrm{a})=\\mathrm{b}_{n}=\\frac{1}{2 \\pi i} \\oint f(z) d z\n\\end{equation} \n\\subsection{Methods of Finding Residues}\n\\begin{enumerate}[label=(\\alph*)]\n\t\\item $\\left. \\right. $\\\\\n\t\\textbf{Method 1:}  Res. $f(z=a)=\\underset{z \\rightarrow a}{L t}(z-a) f(z)$\\\\\n\t\\textbf{Method 2: }If $f(z)=\\frac{\\phi(z)}{\\psi(z)}$ where $\\psi(a)=0$ but $\\phi(a) \\neq 0$, then $$\\operatorname{Res} . f(z=a)=\\frac{\\phi(a)}{\\psi^{\\prime}(a)}$$\n\t\\item Residue at a pole of order ' $n$ '\\\\\n\t\\textbf{Method 1:} Res. $f(z=a)=\\frac{1}{(n-1) !}\\left\\{\\frac{d^{n-1}}{d z^{n-1}}\\left[(z-a)^{n} f(z)\\right]\\right\\}_{z=a}$\\\\\n\t\\textbf{Method 2:} First put $z+a=t$ and expand it into series, then Res. $f(z=a)=$ co-efficient of $1 / t$\n\t\\item Residue at $\\mathrm{z}=\\infty$ : Res. $f(z=\\infty) \\underset{z \\rightarrow \\infty}{L t}[-z f(z)]$\n\\end{enumerate}\n\n\n\n\\begin{exercise}\n\t Find the singular points of the following function and the corresponding residues:\\\\\n\t(a) $f(z)=\\frac{1-2 z}{z(z-1)(z-2)}$\\quad\n\t(b) $f(z)=\\frac{z^{2}}{z^{2}+a^{2}}$\\quad\n\t(c) $f(z)=z^{2} e^{1 / z}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\text{(a )}f(z)&=\\frac{1-2 z}{z(z-1)(z-2)} \\Rightarrow \\text { Poles }: z=0, z=1, z=2\\\\\n\t\\text{Res. }f(z=0)&=\\operatorname{Lt}_{z \\rightarrow 0}(z-0) f(z)=\\operatorname{Lt}_{z \\rightarrow 0} \\frac{1-2 z}{(z-1)(z-2)}=\\frac{1}{2}.\\\\\n\t\\text{Res. } f(z=1)&=L_{z \\rightarrow 1}(z-1) f(z)=L_{z \\rightarrow 1} \\frac{1-2 z}{z(z-2)}=1\\\\\n\t\\text{Res. }f(z=2)&=\\underset{z \\rightarrow 2}{L t}(z-2) f(z)=\\underset{z \\rightarrow 2}{L t} \\frac{1-2 z}{z(z-1)}=-\\frac{3}{2}\\\\\\\\\n\\text{\t(b) }f(z)&=\\frac{z^{2}}{z^{2}+a^{2}} \\Rightarrow\\text{ Poles : }z=i a, z=-i a\\\\\n\t\\text { Res. } f(z=i a)&=\\left(\\frac{z^{2}}{2 z}\\right)_{z=i a}=\\frac{1}{2} i a ; \\operatorname{Res} . f(z=-i a)=\\left(\\frac{z^{2}}{2 z}\\right)_{z=-i a}=-\\frac{1}{2} i a\\\\\\\\\n\t\\text{(c) }f(z)&=z^{2} e^{1 / z}=z^{2}\\left[1+\\frac{1}{z}+\\frac{1}{z^{2} \\cdot 2 !}+\\frac{1}{z^{3} \\cdot 3 !}+\\ldots \\ldots .\\right] \\Rightarrow\\text{ Poles :} z=0\\\\\n\t\\text{Res. }f(z=0)&=\\text{ Coefficient of }\\frac{1}{z}=\\frac{1}{3 !}=\\frac{1}{6}\n\t\\end{align*}\n\\end{answer}\n\\section{Cauchy's Residue Theorem }\nIf $\\mathrm{f}(\\mathrm{z})$ in single-valued and analytic in a closed curve ' $\\mathrm{C}$ ', except at a finite number of poles within ' $\\mathrm{C}$, then, \n\\begin{equation}\n\\oint_{C} \\mathrm{f}(\\mathrm{z}) \\mathrm{dz}=2 \\pi \\mathrm{i}\\ \\text{(Sum of the residues at poles within `$\\mathrm{C}$')}\n\\end{equation}\n\\begin{exercise}\n\tEvaluate the integral: $\\oint_{C} \\frac{4-3 z}{z(z-1)(z-3)} d z$ where $|z|=\\frac{3}{2}$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\hat{f}(z)&=\\frac{4-3 z}{z(z-1)(z-3)} \\Rightarrow\\text{ Poles : }z=0, z=1, z=3\\\\\n\\intertext{\tBut, the given contour is circle centered at the origin and radius $3 / 2$ units.} \n\\text{Therefore, only $z=0$ }&\\text{and $z=1$ within the contour.}\\\\\n\tI&=2 \\pi i[\\operatorname{Re} s . f(z=0)+\\operatorname{Re} s . f(z=1)]=2 \\pi i\\left[\\frac{4}{3}-\\frac{1}{2}\\right]=\\frac{5 \\pi i}{3}\n\t\\end{align*}\n\\end{answer}\n\\begin{exercise}\n\tEvaluate the integral: $\\oint_{C} \\frac{e^{2 z}+z^{2}}{(z-1)^{5}} d z$ where $|z|=2$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\begin{aligned}\n\tf(z)&=\\frac{e^{2 z}+z^{2}}{(z-1)^{5}} \\Rightarrow \\text { Poles }: z=1(\\text { order } 5) \\\\\n\tI&=2 \\pi i \\times \\operatorname{Re} s . f(z=1)=2 \\pi i \\times \\frac{1}{4 !} \\frac{d^{4}}{d z^{4}}\\left[e^{2 z}+z^{2}\\right]_{z=1}=2 \\pi i \\times \\frac{2 e^{2}}{3}=\\frac{4 \\pi i e^{2}}{3} .\n\t\\end{aligned}\n\t\\end{align*}\n\\end{answer}\n\\subsection{Definite Integrals of Trigonometric Functions of $\\cos\\theta$ and $\\sin\\theta$ : (Integration round the unit circle)} \n\t\\textbf{Method:} Consider the contour to be a circle centered at the origin and having radius one unit i.e. $|\\mathrm{z}|=1$\n\\begin{align*}\n\t\\text{Assume, }z&=e^{i \\theta} \\Rightarrow d z=i e^{i \\theta} d \\theta \\\\ d \\theta&=\\frac{d z}{i z}\\\\\n\t\\text{Therefore, }\\cos \\theta&=\\frac{e^{i \\theta}+e^{-i \\theta}}{2}=\\frac{1}{2}\\left(z+\\frac{1}{z}\\right)\n\t\\\\ \\text{and }\\sin \\theta&=\\frac{e^{i \\theta}-e^{-i \\theta}}{2 i}=\\frac{1}{2 i}\\left(z-\\frac{1}{z}\\right)\n\t \\intertext { And the limit will be changed from $ 0 \\rightarrow 2 \\pi \\text { to } \\oint_{C}$}\n\\end{align*}\nThe replacements regarding $\\cos \\theta$ and $\\sin \\theta$ is to be done only in the denominator of the given integral.\n\\begin{exercise}\n\tEvaluate the integral: $\\int_{0}^{2 \\pi} \\frac{d \\theta}{a+b \\cos \\theta} ; \\quad a>b>0$\n\\end{exercise}\n\\begin{answer}\n\t\\begin{align*}\n\t\\int_{0}^{2 \\pi} \\frac{d \\theta}{a+b \\cos \\theta}&=\\int_{0}^{2 \\pi} \\frac{d z / i z}{a+b\\left(\\frac{z^{2}+1}{2 z}\\right)}\\\\&=\\int_{0}^{2 \\pi} \\frac{2 d z}{i\\left(b z^{2}+2 a z+b\\right)}\\\\\n\t\\text { The singular points are at ($z=\\alpha$) }  &=\\frac{-a+\\sqrt{a^{2}-b^{2}}}{b}  \\\\ \t\\text { The singular points are at ($z=\\beta$) }&=\\frac{-a-\\sqrt{a^{2}-b^{2}}}{b}\\\\\n\t\\intertext{The singular point $z=\\beta$ will lie outside the unit circle as $a>b>0$ while the singular point $z=\\alpha$ will lie inside the unit circle which is a simple pole.}\n\t\\text { Res. } f(z=\\alpha)&=\\lim _{z \\rightarrow \\alpha}(z-\\alpha) f(z)\\\\&=\\lim _{z \\rightarrow \\alpha} \\frac{2}{i b} \\frac{(z-\\alpha)}{(z-\\alpha)(z-\\beta)}=\\frac{2}{i b(\\alpha-\\beta)}\\\\&=\\frac{2}{i b} \\times \\frac{b}{2 \\sqrt{a^{2}-b^{2}}}\\\\&=\\frac{1}{i \\sqrt{a^{2}-b^{2}}}\\\\\n\\text { Therefore,by cauchy Residue theorem.}\\\nI&=2 \\pi i \\times \\text { Residue }\\\\&=2 \\pi \\mathrm{i} \\times \\frac{1}{i \\sqrt{a^{2}-b^{2}}}\\\\&=\\frac{2 \\pi}{\\sqrt{a^{2}-b^{2}}}\n\t\\end{align*}\n\\end{answer}\n\\subsection{ Evaluation of improper integrals between the limit $-\\infty$ to $+\\infty$ : }\n$\\left. \\right. $\\\\\n\\subsubsection{Theorem I:}\n\\begin{align*}\n\\intertext{If $f(x)$ contain  only polynomial terms}\n\\text{Then }f(x)&=f(x) \n\\intertext{$\\rightarrow$ find singular points}\n\\intertext{$\\rightarrow$ check point lie in upper half}\n\\intertext{\\textbf{A.}\\quad If singular point lie on imaginary axis}\n\\int\\limits_{-\\infty}^{\\infty}f(z)dz&=\\int\\limits_{-\\infty}^{\\infty}f(x)dx\n=2\\pi i[\\Sigma \\text{ Res}]-\\left( \\stackrel{\\text{lim}}{z\\rightarrow \\infty}\\quad zf(x)\\right) x\\pi i\n\\intertext{\\textbf{B.}\\quad If singular point lie on real axis }\n\\int\\limits_{-\\infty}^{\\infty}f(x)dx=&\n\\int\\limits_{-\\infty}^{\\infty}f(z)dz=\\pi i[\\Sigma \\text{ Res}]-\\pi i \\left[\\stackrel{\\text{lim}}{z\\rightarrow \\infty}\\quad zf(z) \\right] \n\\end{align*}\n\\subsubsection{Theorem II:}\n\\begin{align*}\n\\intertext{If $f(x)$ contains sine and cosine function along with polynomial function rule is same, except second term which is $0$ in this case.}\n\\intertext{\\textbf{A.}\\quad If singular point lie on imaginary axis}\\\\\n\\int\\limits_{-\\infty}^{\\infty}f(z)dz&=\\int\\limits_{-\\infty}^{\\infty}f(x)dx\n=2\\pi i[\\Sigma \\text{ Res}]\n\\intertext{\\textbf{B.}\\quad If singular point lie on real axis }\n\\int\\limits_{-\\infty}^{\\infty}f(x)dx&=\n\\int\\limits_{-\\infty}^{\\infty}f(z)dz=\\pi i[\\Sigma \\text{ Res}]\n\\end{align*}\n\\newpage\n\\begin{abox}\n\tPractise Set-1\n\t\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item The value of the integral $\\int_{C} d z z^{2} e^{z}$, where $C$ is an open contour in the complex $z$-plane as shown in the figure below, is:\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=5cm,width=9cm]{diagram-20211005-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{5}{e}+e$\n\t\t\\task[\\textbf{B.}] $e-\\frac{5}{e}$\n\t\t\\task[\\textbf{C.}] $\\frac{5}{e}-e$\n\t\t\\task[\\textbf{D.}] $-\\frac{5}{e}-e$\n\t\\end{tasks}\n\t\n\t\\item Which of the following is an analytic function of the complex variable $z=x+i y$ in the domain $|z|<2 ?$\n\t{\\exyear{NET/JRF(JUNE-2011)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $(3+x-i y)^{7}$\n\t\t\\task[\\textbf{B.}] $(1+x+i y)^{4}(7-x-i y)^{3}$\n\t\t\\task[\\textbf{C.}] $(1-x-i y)^{4}(7-x+i y)^{3}$\n\t\t\\task[\\textbf{D.}] $(x+i y-1)^{1 / 2}$\n\t\\end{tasks}\n\n\t\\item The first few terms in the Laurent series for $\\frac{1}{(z-1)(z-2)}$ in the region $1 \\leq|z| \\leq 2$ and around $z=1$ is\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $\\frac{1}{2}\\left[1+z+z^{2}+\\ldots\\right]\\left[1+\\frac{z}{2}+\\frac{z^{2}}{4}+\\frac{z^{3}}{8}+\\ldots .\\right]$\n\t\t\\task[\\textbf{B.}] $\\frac{1}{1-z}-z-(1-z)^{2}+(1-z)^{3}+\\ldots .$\n\t\t\\task[\\textbf{C.}] $\\frac{1}{\\mathrm{z}^{2}}\\left[1+\\frac{1}{\\mathrm{z}}+\\frac{1}{\\mathrm{z}^{2}}+\\ldots .\\right]\\left[1+\\frac{2}{\\mathrm{z}}+\\frac{4}{\\mathrm{z}^{2}}+\\ldots . .\\right]$\n\t\t\\task[\\textbf{D.}]  $2(z-1)+5(z-1)^{2}+7(z-1)^{3}+\\ldots$\n\t\\end{tasks}\n\t\n\t\\item Let $u(x, y)=x+\\frac{1}{2}\\left(x^{2}-y^{2}\\right)$ be the real part of analytic function $f(z)$ of the complex variable $z=x+i y$. The imaginary part of $f(z)$ is\n\t{\\exyear{NET/JRF(JUNE-2012)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $y+x y$\n\t\t\\task[\\textbf{B.}] $x y$\n\t\t\\task[\\textbf{C.}] $y$\n\t\t\\task[\\textbf{D.}] $y^{2}-x^{2}$\n\t\\end{tasks}\n\n\t\\item The value of the integral $\\int_{C} \\frac{z^{3} d z}{\\left(z^{2}-5 z+6\\right)}$, where $C$ is a closed contour defined by the equation $2|z|-5=0$, traversed in the anti-clockwise direction, is\n\t{\\exyear{NET/JRF(DEC-2012)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-16 \\pi i$\n\t\t\\task[\\textbf{B.}] $16 \\pi \\mathrm{i}$\n\t\t\\task[\\textbf{C.}] $8 \\pi i$\n\t\t\\task[\\textbf{D.}] $2 \\pi i$\n\t\\end{tasks}\n\t\n\t\\item  With $z=x+i y$, which of the following functions $f(x, y)$ is NOT a (complex) analytic function of $z$ ?\n\t{\\exyear{NET/JRF(JUNE-2013)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $f(x, y)=(x+i y-8)^{3}\\left(4+x^{2}-y^{2}+2 i x y\\right)^{7}$\n\t\t\\task[\\textbf{B.}] $f(x, y)=(x+i y)^{7}(1-x-i y)^{3}$\n\t\t\\task[\\textbf{C.}] $f(x, y)=\\left(x^{2}-y^{2}+2 i x y-3\\right)^{5}$\n\t\t\\task[\\textbf{D.}] $f(x, y)=(1-x+i y)^{4}(2+x+i y)^{6}$\n\t\\end{tasks}\n\n\t\\item  Which of the following functions cannot be the real part of a complex analytic function of $z=x+i y ?$\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $x^{2} y$\n\t\t\\task[\\textbf{B.}]  $x^{2}-y^{2}$\n\t\t\\task[\\textbf{C.}] $x^{3}-3 x y^{2}$\n\t\t\\task[\\textbf{D.}] $3 x^{2} y-y-y^{3}$\n\t\\end{tasks}\n\t\n\t\\item  Given that the integral $\\int_{0}^{\\infty} \\frac{d x}{y^{2}+x^{2}}=\\frac{\\pi}{2 y}$, the value of $\\int_{0}^{\\infty} \\frac{d x}{\\left(y^{2}+x^{2}\\right)^{2}}$ is\n\t{\\exyear{NET/JRF(DEC-2013)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{y^{3}}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\pi}{4 y^{3}}$\n\t\t\\task[\\textbf{C.}]  $\\frac{\\pi}{8 y^{3}}$\n\t\t\\task[\\textbf{D.}] $\\frac{\\pi}{2 y^{3}}$\n\t\\end{tasks}\n\n\t\\item If $C$ is the contour defined by $|z|=\\frac{1}{2}$, the value of the integral\n\t$$\n\t\\oint_{C} \\frac{d z}{\\sin ^{2} z}\n\t$$\n\tis\n\t{\\exyear{NET/JRF(JUNE-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\infty$\n\t\t\\task[\\textbf{B.}] $2 \\pi i$\n\t\t\\task[\\textbf{C.}] 0\n\t\t\\task[\\textbf{D.}] $\\pi i$\n\t\\end{tasks}\n\n\t\\item The principal value of the integral $\\int_{-\\infty}^{\\infty} \\frac{\\sin (2 x)}{x^{3}} d x$ is\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $-2 \\pi$\n\t\t\\task[\\textbf{B.}]  $-\\pi$\n\t\t\\task[\\textbf{C.}] $\\pi$\n\t\t\\task[\\textbf{D.}]  $2 \\pi$\n\t\\end{tasks}\n\t\n\t\\item The Laurent series expansion of the function $f(z)=e^{2}+e^{1 / 2}$ about $z=0$ is given by\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] $\\sum_{n=-\\infty}^{\\infty} \\frac{z^{n}}{n !}$ for all $|z|<\\infty$\n\t\t\\task[\\textbf{B.}] $\\sum_{n=0}^{\\infty}\\left(z^{n}+\\frac{1}{z^{n}}\\right) \\frac{1}{n !}$ only if $0<|z|<1$\n\t\t\\task[\\textbf{C.}] $\\sum_{n=0}^{\\infty}\\left(z^{n}+\\frac{1}{z^{n}}\\right) \\frac{1}{n !}$ for all $0<|z|<\\infty$\n\t\t\\task[\\textbf{D.}]  $\\sum_{n=-\\infty}^{\\infty} \\frac{z^{n}}{n !}$ only if $|z|<1$\n\t\\end{tasks}\n\t\n\t\\item Consider the function $f(z)=\\frac{1}{z} \\ln (1-z)$ of a complex variable $z=r e^{i \\theta}(r \\geq 0, \\quad-\\infty<\\theta<\\infty)$. The singularities of $f(z)$ are as follows:\n\t{\\exyear{NET/JRF(DEC-2014)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}]  Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ only for $0 \\leq \\theta<2 \\pi$\n\t\t\\task[\\textbf{B.}] Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ for all $\\theta$ other than $0 \\leq \\theta<2 \\pi$\n\t\t\\task[\\textbf{C.}] Branch points at $z=1$ and $z=\\infty$; and a pole at $z=0$ for all $\\theta$\n\t\t\\task[\\textbf{D.}] Branch points at $z=0, z=1$ and $z=\\infty$.\n\t\\end{tasks}\n\t\n\t\\item  The value of integral $\\int_{-\\infty}^{\\infty} \\frac{d x}{1+x^{4}}$\n\t{\\exyear{NET/JRF(JUNE-2015)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{\\sqrt{2}}$\n\t\t\\task[\\textbf{B.}] $\\frac{\\pi}{2}$\n\t\t\\task[\\textbf{C.}] $\\sqrt{2} \\pi$\n\t\t\\task[\\textbf{D.}] $2 \\pi$\n\t\\end{tasks}\n\n\t\\item  The function $\\frac{Z}{\\sin \\pi z^{2}}$ of a complex variable $z$ has\n\t{\\exyear{NET/JRF(DEC-2015)}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] A simple pole at 0 and poles of order 2 at $\\pm \\sqrt{n}$ for $n=1,2,3 \\ldots$\n\t\t\\task[\\textbf{B.}] A simple pole at 0 and poles of order 2 at $\\pm \\sqrt{n}$ and $\\pm i \\sqrt{n}$ for $n=1,2,3 \\ldots$\n\t\t\\task[\\textbf{C.}] Poles of order 2 at $\\pm \\sqrt{n}, n=0,1,2,3 \\ldots$\n\t\t\\task[\\textbf{D.}] Poles of order 2 at $\\pm n, n=0,1,2,3 \\ldots$\n\t\\end{tasks}\n\t\n\t\\item The value of the contour integral $\\frac{1}{2 \\pi i} \\oint_{C} \\frac{e^{4 z}-1}{\\cosh (z)-2 \\sinh (z)} d z$ around the unit circle $C$ traversed in the anti-clockwise direction, is\n\t{\\exyear{NET/JRF(JUNE-2016)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] 2\n\t\t\\task[\\textbf{C.}] $\\frac{-8}{\\sqrt{3}}$\n\t\t\\task[\\textbf{D.}] $-\\tanh \\left(\\frac{1}{2}\\right)$\n\t\\end{tasks}\n\t\n\t\\item  Let $u(x, y)=e^{a x} \\cos (b y)$ be the real part of a function $f(z)=u(x, y)+i v(x, y)$ of the complex variable $z=x+i y$, where $a, b$ are real constants and $a \\neq 0 .$ The function $f(z)$ is complex analytic everywhere in the complex plane if and only if\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $b=0$\n\t\t\\task[\\textbf{B.}] $b=\\pm a$\n\t\t\\task[\\textbf{C.}] $b=\\pm 2 \\pi a$\n\t\t\\task[\\textbf{D.}]  $b=a \\pm 2 \\pi$\n\t\\end{tasks}\n\t\n\t\\item  The integral $\\oint_{\\Gamma} \\frac{z e^{i \\pi z / 2}}{z^{2}-1} d z$ along the closed contour $\\Gamma$ shown in the figure is\n\t{\\exyear{NET/JRF(JUNE-2017)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4cm,width=5cm]{diagram-20211005(19)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $2 \\pi$\n\t\t\\task[\\textbf{C.}] $-2 \\pi$\n\t\t\\task[\\textbf{D.}] $4 \\pi i$\n\t\\end{tasks}\n\t\n\t\\item What is the value of $a$ for which $f(x, y)=2 x+3\\left(x^{2}-y^{2}\\right)+2 i(3 x y+a y)$ is an analytic function of complex variable $z=x+i y$\n\t{\\exyear{NET/JRF(JUNE-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 1\n\t\t\\task[\\textbf{B.}] 0\n\t\t\\task[\\textbf{C.}] 3\n\t\t\\task[\\textbf{D.}] 2\n\t\\end{tasks}\n\n\t\\item  The value of the integral $\\oint_{C} \\frac{d z}{z} \\frac{\\tanh 2 z}{\\sin \\pi z}$, where $C$ is a circle of radius $\\frac{\\pi}{2}$, traversed counter-clockwise, with centre at $z=0$, is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 4\n\t\t\\task[\\textbf{B.}] $4 i$\n\t\t\\task[\\textbf{C.}] $2 i$\n\t\t\\task[\\textbf{D.}] 0\n\t\\end{tasks}\n\t\n\t\\item The integral $I=\\int_{C} e^{z} d z$ is evaluated from the point $(-1,0)$ to $(1,0)$ along the contour $C$, which is an arc of the parabola $y=x^{2}-1$, as shown in the figure. The value of $I$ is\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=4.5cm,width=5cm]{diagram-20211005(3)-crop}\n\t\\end{figure}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}]  0\n\t\t\\task[\\textbf{B.}] $2 \\sinh 1$\n\t\t\\task[\\textbf{C.}]  $e^{2 i} \\sinh 1$\n\t\t\\task[\\textbf{D.}] $e+e^{-1}$\n\t\\end{tasks}\n\n\t\\item The contour $C$ of the following integral\n\t$$\n\t\\oint_{C} d z \\frac{\\sqrt{(z-1)(z-3)}}{\\left(z^{2}-25\\right)^{3}}\n\t$$\n\tin the complex $z$ plane is shown in the figure below.\\\\\n\t\\begin{figure}[H]\n\t\t\\centering\n\t\t\\includegraphics[height=3.5cm,width=6cm]{diagram-20211005(8)-crop}\n\t\\end{figure}\n\tThis integral is equivalent to an integral along the contours\n\t{\\exyear{NET/JRF(DEC-2018)}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(4)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{B.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(5)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{C.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(6)-crop}\n\t\t\\end{figure}\n\t\t\\task[\\textbf{D.}] \\begin{figure}[H]\n\t\t\t\\centering\n\t\t\t\\includegraphics[height=3cm,width=6.5cm]{diagram-20211005(7)-crop}\n\t\t\\end{figure}\n\t\\end{tasks}\n\n\t\\item  Let $C$ be the circle of radius $\\frac{\\pi}{4}$ centered at $z=\\frac{1}{4}$ in the complex $z$-plane that is traversed counter-clockwise. The value of the contour integral $\\oint_{C} \\frac{z^{2}}{\\sin ^{2} 4 z} d z$ is\n\t{\\exyear{NET/JRF(DEC-2019)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $\\frac{i \\pi^{2}}{4}$\n\t\t\\task[\\textbf{C.}] $\\frac{i \\pi^{2}}{16}$\n\t\t\\task[\\textbf{D.}] $\\frac{i \\pi}{4}$\n\t\\end{tasks}\n\n\t\\item  A function of a complex variable $z$ is defined by the integral $f(z)=\\oint_{\\Gamma} \\frac{w^{2}-2}{w-z} d w$, where $\\Gamma$ is a circular contour of radius 3 , centred at origin, running counter-clockwise in the $w$ - plane. The value of the function at $z=(2-i)$ is\n\t{\\exyear{NET/JRF(JUNE-2020)}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] 0\n\t\t\\task[\\textbf{B.}] $1-4 i$\n\t\t\\task[\\textbf{C.}]  $8 \\pi+2 \\pi \\mathrm{i}$\n\t\t\\task[\\textbf{D.}] $-\\frac{2}{\\pi}-\\frac{i}{2 \\pi}$\n\t\\end{tasks}\n\t\n\\end{enumerate}\n\\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.5cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{C} &2&\\textbf{B}\\\\\\hline \n\t\t3&\\textbf{B} &4&\\textbf{A} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{D} \\\\\\hline\n\t\t7&\\textbf{A}&8&\\textbf{-}\\\\\\hline\n\t\t9&\\textbf{C}&10&\\textbf{A}\\\\\\hline\n\t\t11&\\textbf{C} &12&\\textbf{-}\\\\\\hline\n\t\t13&\\textbf{A}&14&\\textbf{B}\\\\\\hline\n\t\t15&\\textbf{C}&16&\\textbf{B}\\\\\\hline\n\t\t17&\\textbf{C} &18&\\textbf{A}\\\\\\hline\n\t\t19&\\textbf{B}&20&\\textbf{B}\\\\\\hline\n\t\t21&\\textbf{C}&22&\\textbf{C}\\\\\\hline\n\t\t23&\\textbf{C}& &\\\\\\hline\n\t\t\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-2\n\\end{abox}\n\\begin{enumerate}[label=\\color{ocre}\\textbf{\\arabic*.}]\n\t\\item  The value of the integral $\\oint_{C} \\frac{e^{z} \\sin (z)}{z^{2}} d z$, where the contour $C$ is the unit circle: $|z-2|=1$, is\n\t{\\exyear{GATE 2010}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $2 \\pi i$\n\t\t\\task[\\textbf{B.}] $4 \\pi i$\n\t\t\\task[\\textbf{C.}] $\\pi i$\n\t\t\\task[\\textbf{D.}] 0\n\t\\end{tasks}\n\t\\item Which of the following statements is TRUE for the function $f(z)=\\frac{z \\sin z}{(z-\\pi)^{2}}$ ?\n\t{\\exyear{GATE 2011}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $f(z)$ is analytic everywhere in the complex plane\n\t\t\\task[\\textbf{B.}] $f(z)$ has a zero at $z=\\pi$\n\t\t\\task[\\textbf{C.}] $f(z)$ has a pole of order 2 at $z=\\pi$\n\t\t\\task[\\textbf{D.}] $f(z)$ has a simple pole at $z=\\pi$\n\t\\end{tasks}\n\t\\item For the function $f(z)=\\frac{16 z}{(z+3)(z-1)^{2}}$, the residue at the pole $z=1$ is (your answer should be an integer)-------\n\t{\\exyear{GATE 2013}}\n\t\\item The value of the integral\n\t$$\n\t\\oint_{C} \\frac{z^{2}}{e^{z}+1} d z\n\t$$\n\twhere $C$ is the circle $|z|=4$, is\n\t{\\exyear{GATE 2014}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $2 \\pi i$\n\t\t\\task[\\textbf{B.}] $2 \\pi^{2} i$\n\t\t\\task[\\textbf{C.}]  $4 \\pi^{3} i$\n\t\t\\task[\\textbf{D.}] $4 \\pi^{2} i$\n\t\\end{tasks}\n\t\\item Consider a complex function $f(z)=\\frac{1}{z\\left(z+\\frac{1}{2}\\right) \\cos (z \\pi)}$. Which one of the following statements is correct?\n\t{\\exyear{GATE 2015}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $f(z)$ has simple poles at $z=0$ and $z=-\\frac{1}{2}$\n\t\t\\task[\\textbf{B.}] $f(z)$ has second order pole at $z=-\\frac{1}{2}$\n\t\t\\task[\\textbf{C.}] $f(z)$ has infinite number of second order poles\n\t\t\\task[\\textbf{D.}] $f(z)$ has all simple poles\n\t\\end{tasks}\n\t\\item  Consider $w=f(z)=u(x, y)+i v(x, y)$ to be an analytic function in a domain $D$. Which one of the following options is NOT correct?\n\t{\\exyear{GATE 2015}}\n\t\\begin{tasks}(1)\n\t\t\\task[\\textbf{A.}] $u(x, y)$ satisfies Laplace equation in D\n\t\t\\task[\\textbf{B.}]  $v(x, y)$ satisfies Laplace equation in $D$\n\t\t\\task[\\textbf{C.}] $\\int_{1}^{z_{2}} f(z) d z$ is dependent on the choice of the contour between $z_{1}$ and $z_{2}$ in $D$\n\t\t\\task[\\textbf{D.}]  $f(z)$ can be Taylor expended in $D$\n\t\\end{tasks}\n\t\\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  Which of the following is an analytic function of $z$ everywhere in the complex plane?\n\t{\\exyear{GATE 2016}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $z^{2}$\n\t\t\\task[\\textbf{B.}]  $\\left(z^{*}\\right)^{2}$\n\t\t\\task[\\textbf{C.}] $|z|^{2}$\n\t\t\\task[\\textbf{D.}] $\\sqrt{z}$\n\t\\end{tasks}\n\t\\item The contour integral $\\oint \\frac{d z}{1+z^{2}}$ evaluated along a contour going from $-\\infty$ to $+\\infty$ along the\n\treal axis and closed in the lower half-plane circle is equal to............... (up to two decimal places).\n\t{\\exyear{GATE 2017}}\n\t\\item The imaginary part of an analytic complex function is $v(x, y)=2 x y+3 y .$ The real part of the function is zero at the origin. The value of the real part of the function at $1+i$ is ................. (up to two decimal places)\n\t{\\exyear{GATE 2017}}\n\t\\item The absolute value of the integral\n\t$$\n\t\\int \\frac{5 z^{3}+3 z^{2}}{z^{2}-4} d z\n\t$$\n\tover the circle $|z-1.5|=1$ in complex plane, is $\\ldots$ (up to two decimal places).\n\t{\\exyear{GATE 2018}}\n\t\\item The pole of the function $f(z)=\\cot z$ at $z=0$ is\n\t{\\exyear{GATE 2019}}\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{A.}] A removable pole\n\t\t\\task[\\textbf{B.}] An essential singularity\n\t\t\\task[\\textbf{C.}]  A simple pole\n\t\t\\task[\\textbf{D.}] A second order pole\n\t\\end{tasks}\n\t\\item The value of the integral $\\int_{-\\infty}^{\\infty} \\frac{\\cos (k x)}{x^{2}+a^{2}} d x$, where $k>0$ and $a>0$, is\n\t{\\exyear{GATE 2019}}\n\t\\begin{tasks}(4)\n\t\t\\task[\\textbf{A.}] $\\frac{\\pi}{a} e^{-k a}$\n\t\t\\task[\\textbf{B.}] $\\frac{2 \\pi}{a} e^{-k a}$\n\t\t\\task[\\textbf{C.}] $\\frac{\\pi}{2 a} e^{-k a}$\n\t\t\\task[\\textbf{D.}] $\\frac{3 \\pi}{2 a} e^{-k a}$\n\t\\end{tasks}\n\\item The value of the integral $\\int_{0}^{\\infty} \\frac{\\ln x}{\\left(x^{2}+1\\right)^{2}} d x$ is\n{\\exyear{ JEST 2012}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]0\n\t\\task[\\textbf{b.}]$\\frac{-\\pi}{4}$\n\t\\task[\\textbf{c.}] $\\frac{-\\pi}{2}$\n\t\\task[\\textbf{d.}] $\\frac{\\pi}{2}$\n\\end{tasks}\n\\item Compute $\\lim _{z \\rightarrow 0} \\frac{\\operatorname{Re}\\left(z^{2}\\right)+\\operatorname{Im}\\left(z^{2}\\right)}{z^{2}}$\n{\\exyear{ JEST 2013}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}] The limit does not exist\n\t\\task[\\textbf{b.}]1\n\t\\task[\\textbf{c.}]$-i$\n\t\\task[\\textbf{d.}] $-1$\n\\end{tasks}\n\\item The value of limit\n$$\n\\lim _{z \\rightarrow i} \\frac{z^{10}+1}{z^{6}+1}\n$$\nis equal to\n{\\exyear{ JEST 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]1\n\t\\task[\\textbf{b.}]0\n\t\\task[\\textbf{c.}] $\\frac{-10}{3}$\n\t\\task[\\textbf{d.}] $\\frac{5}{3}$\n\\end{tasks}\n\\item The value of integral\n$$\nI=\\oint \\frac{\\sin z}{2 z-\\pi} d z\n$$\nwith $c$ a circle $|z|=2$, is\n{\\exyear{ JEST 2014}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}] 0\n\t\\task[\\textbf{b.}]$2 \\pi i$\n\t\\task[\\textbf{c.}] $\\pi i$\n\t\\task[\\textbf{d.}]  $-\\pi i$\n\\end{tasks}\n\\item Given an analytic function $f(z)=\\phi(x, y)+i \\psi(x, y)$, where $\\phi(x, y)=x^{2}+4 x-y^{2}+2 y$\nIf $C$ is a constant, which of the following relations is true?\n{\\exyear{ JEST 2015}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\psi(x, y)=x^{2} y+4 y+C$\n\t\\task[\\textbf{b.}]$\\psi(x, y)=2 x y-2 x+C$\n\t\\task[\\textbf{c.}]$\\psi(x, y)=2 x y+4 y-2 x+C$\n\t\\task[\\textbf{d.}] $\\psi(x, y)=x^{2} y-2 x+C$\n\\end{tasks}\n\\item Which one is the image of the complex domain $\\{z \\mid x y \\geq 1, x+y>0\\}$ under the mapping $f(z)=z^{2}$, if $z=x+i y ?$\n{\\exyear{ JEST 2017}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}] $\\{z \\mid x y \\geq 1, x+y>0\\}$\n\t\\task[\\textbf{b.}]$\\{z \\mid x \\geq 2, x+y>0\\}$\n\t\\task[\\textbf{c.}]$\\{z \\mid y \\geq 2 \\forall x\\}$\n\t\\task[\\textbf{d.}] $\\{z \\mid y \\geq 1 \\forall x\\}$\n\\end{tasks}\n\\item The integral $I=\\int_{1}^{\\infty} \\frac{\\sqrt{x-1}}{(1+x)^{2}} d x$ is\n{\\exyear{ JEST 2017}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{\\sqrt{2}}$\n\t\\task[\\textbf{b.}]$\\frac{\\pi}{2 \\sqrt{2}}$\n\t\\task[\\textbf{c.}]$\\frac{\\sqrt{\\pi}}{2}$\n\t\\task[\\textbf{d.}]$\\sqrt{\\frac{\\pi}{2}}$\n\\end{tasks}\n\\item The integral\n$$\n\\int_{-\\infty}^{\\infty} \\frac{\\cos x}{x^{2}+1} d x \\text { is }\n$$\n{\\exyear{ JEST 2018}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{e}$\n\t\\task[\\textbf{b.}] $\\pi e^{-2}$\n\t\\task[\\textbf{c.}]$\\pi$\n\t\\task[\\textbf{d.}] zero\n\\end{tasks}\n\\item Consider the function $f(x, y)=|x|-i|y| .$ In which domain of the complex plane is this function analytic?\n{\\exyear{ JEST 2019}}\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]First and second quadrants\n\t\\task[\\textbf{b.}]Second and third quadrants\n\t\\task[\\textbf{c.}]Second and fourth quadrants\n\t\\task[\\textbf{d.}]  Nowhere\n\\end{tasks}\n\\end{enumerate}\n \\colorlet{ocre1}{ocre!70!}\n\\colorlet{ocrel}{ocre!30!}\n\\setlength\\arrayrulewidth{1pt}\n\\begin{table}[H]\n\t\\centering\n\t\\arrayrulecolor{ocre}\n\t\\begin{tabular}{|p{1.5cm}|p{1.7cm}||p{1.5cm}|p{1.5cm}|}\n\t\t\\hline\n\t\t\\multicolumn{4}{|c|}{\\textbf{Answer key}}\\\\\\hline\\hline\n\t\t\\rowcolor{ocrel}Q.No.&Answer&Q.No.&Answer\\\\\\hline\n\t\t1&\\textbf{D} &2&\\textbf{C}\\\\\\hline \n\t\t3&\\textbf{3(NAT)} &4&\\textbf{C} \\\\\\hline\n\t\t5&\\textbf{A} &6&\\textbf{C} \\\\\\hline\n\t\t7&\\textbf{C}&8&\\textbf{A}\\\\\\hline\n\t\t9&\\textbf{$\\pi$(NAT)}&10&\\textbf{3(NAT)}\\\\\\hline\n\t\t11&\\textbf{81.64(NAT)} &12&\\textbf{C}\\\\\\hline\n\t\t13&\\textbf{A}& 14&\\textbf{B}\\\\\\hline\n\t\t15&\\textbf{A}&16 &\\textbf{D}\\\\\\hline\n\t\t17&\\textbf{C}&18&\\textbf{C}\\\\\\hline\n\t\t19&\\textbf{-} &20&\\textbf{B}\\\\\\hline\n\t\t21&\\textbf{A}&22&\\textbf{C}\\\\\\hline\n\t\\end{tabular}\n\\end{table}\n\\newpage\n\\begin{abox}\n\tPractise Set-3\n\\end{abox}\n\\begin{enumerate}\n\t\\item The amplitude of $\\frac{1+i \\sqrt{3}}{\\sqrt{3}+i}$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{\\pi}{3}$\n\t\t\\task[\\textbf{b.}]$-\\frac{\\pi}{3}$\n\t\t\\task[\\textbf{c.}]$\\frac{\\pi}{6}$\n\t\t\\task[\\textbf{d.}]  $-\\frac{\\pi}{6}$\n\t\\end{tasks}\n\t\\begin{answer}\n\t\\begin{align*}\n\t\\frac{1+i \\sqrt{3}}{\\sqrt{3}+i}&=\\frac{(1+i \\sqrt{3})(\\sqrt{3}-i)}{(\\sqrt{3}+i)(\\sqrt{3}-i)}\\\\&=\\frac{2 \\sqrt{3}+2 i}{4}\\\\&=\\frac{\\sqrt{3}}{2}+\\frac{1}{2} i\\\\\n\t\\intertext{\tSince both the real and complex parts are greater than zero, hence the argument is the acute angle given by $\\tan ^{-1}\\left|\\frac{\\frac{1}{2}}{\\frac{\\sqrt{3}}{2}}\\right|=\\tan ^{-1} \\frac{1}{\\sqrt{3}}=\\frac{\\pi}{6}$}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\t\n\t\\item If $\\frac{1-i x}{1+i x}=a+i b$, then $a^{2}+b^{2}$ is\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]1\n\t\t\\task[\\textbf{b.}]$-1$\n\t\t\\task[\\textbf{c.}] 0\n\t\t\\task[\\textbf{d.}] none of these\n\t\\end{tasks}\n\t\\begin{answer}\n\t\\begin{align*}\n\ta+i b&=\\frac{1-i x}{1+i x} \\Rightarrow a-i b=\\frac{1+i x}{1-i x}\\\\\n\t\\therefore \\quad(a+i b)(a-i b)&=\\frac{1-i x}{1+i x} \\cdot \\frac{1+i x}{1-i x} \\Rightarrow a^{2}+b^{2}=\\frac{1+x^{2}}{1+x^{2}}=1\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\t\\item If $z=1-\\cos \\theta+i \\sin \\theta$, then $|z|$ equals\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$2 \\sin \\frac{\\theta}{2}$\n\t\t\\task[\\textbf{b.}]$2 \\cos \\frac{\\theta}{2}$\n\t\t\\task[\\textbf{c.}]$2\\left|\\sin \\frac{\\theta}{2}\\right|$\n\t\t\\task[\\textbf{d.}] $2\\left|\\cos \\frac{\\theta}{2}\\right|$\n\t\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t|z|&=\\sqrt{(1-\\cos \\theta)^{2}+\\sin ^{2} \\theta}\\\\&=\\sqrt{2-2 \\cos \\theta}\\\\&=\\sqrt{4 \\sin ^{2} \\frac{\\theta}{2}}\\\\&=2\\left|\\sin \\frac{\\theta}{2}\\right|\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\t\\item If $z=\\frac{1}{(2+3 i)^{2}}$, then $|z|$ equals\n\t\\begin{tasks}(2)\n\t\t\\task[\\textbf{a.}]$\\frac{1}{13}$\n\t\t\\task[\\textbf{b.}]$\\frac{1}{15}$\n\t\t\\task[\\textbf{c.}]$\\frac{1}{12}$\n\t\t\\task[\\textbf{d.}] none of these\n\t\\end{tasks}\n\t\\begin{answer}\n\t\t\\begin{align*}\n\t\t|z|=\\frac{1}{|2+3 i|^{2}}=\\frac{1}{\\left(\\sqrt{2^{2}+3^{2}}\\right)^{2}} \\quad|z|=\\frac{1}{13}\n\t\t\\end{align*}\n\t\tSo the correct answer is \\textbf{Option (a)}\n\t\\end{answer}\n\t\\item If the number $\\frac{z-1}{z+1}$ is purely imaginary, then\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$|z|=1$\n\t\\task[\\textbf{b.}]$|z|>1$\n\t\\task[\\textbf{c.}]$|z|<1$\n\t\\task[\\textbf{d.}] $|z|>2$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t&\\text{we have: }\\frac{z-1}{z+1}\\text{ is purely imaginary}\\\\\n\t\t&\\Rightarrow \\quad\\text{ argument of }\\frac{z-1}{z+1}\\text{ is }\\pm \\frac{\\pi}{2} \\Rightarrow \\arg \\left(\\frac{\\mathrm{z}-1}{\\mathrm{z}+1}\\right)=\\pm \\frac{\\pi}{2}\\\\\n\t\t&\\Rightarrow \\quad z\\text{ lies on a circle having $(1,0)$ and $(-1,0)$ as the end point of a diameter.}\\\\\n\t\t&\\Rightarrow \\quad z\\text{ lies on a circle with centre at the origin and radius are unit}\\\\\n\t\t&\\Rightarrow \\quad z\\text{ lies on }|z|=1 \\Rightarrow|z|=1\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item The value of integral $I=\\int_{0}^{\\pi} \\frac{2 d \\theta}{R-\\cos \\theta}$ is given by where $R$ is real constant.\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{-1}{2 \\sqrt{R^{2}-1}}$\n\t\\task[\\textbf{b.}]$\\frac{2 \\pi}{\\sqrt{R^{2}-1}}$\n\t\\task[\\textbf{c.}]$\\frac{\\pi}{\\sqrt{1-R^{2}}}$\n\t\\task[\\textbf{d.}] $\\frac{\\pi}{\\sqrt{R^{2}-1}}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t\\int_{0}^{\\pi} \\frac{2 d \\theta}{R-\\cos \\theta}&=\\frac{1}{2} \\int_{0}^{2 \\pi} \\frac{2 d \\theta}{R-\\cos \\theta}=\\int_{0}^{2 \\pi} \\frac{d \\theta}{R-\\cos \\theta}\\\\\n\t\tz&=e^{i \\theta} \\Rightarrow d z=i e^{i \\theta} d \\theta=i z d \\theta \\Rightarrow d \\theta=\\frac{d z}{i z} \\\\\n\t\t\\therefore \\int_{0}^{\\pi} \\frac{2 d \\theta}{R-\\cos \\theta}&=\\oint_{c} \\frac{d z / i z}{R-\\frac{1}{2}\\left(z+z^{-1}\\right)}\\\\&=\\oint_{C} \\frac{d z / i z}{R-\\frac{1}{2}\\left(\\frac{z^{2}+1}{z}\\right)}\\\\&=\\oint_{C} \\frac{d z / i z}{\\frac{2 R z-\\left(z^{2}+1\\right)}{2 z}}\\\\\n\t\t&=-\\frac{2}{i} \\oint_{c} \\frac{d z}{z^{2}-2 R z+1}\\hspace{2cm}\n\t\t\\text{\twhere $C$; unit circle}\\\\\n\t\t\\text{Poles are }&: z^{2}-2 R z+1=0\\\\\n\t\t\\Rightarrow z&=\\frac{-(-2 R) \\pm \\sqrt{4 R^{2}-4 \\times 1 \\times 1}}{2 \\times 1} \\quad \\\\\\Rightarrow z&=\\frac{2 R \\pm \\sqrt{4 R^{2}-4}}{2} \\\\\\Rightarrow z&=\\frac{2 R \\pm 2 \\sqrt{R^{2}-1}}{2}\\\\\n\t\t&=R \\pm \\sqrt{R^{2}-1}\\\\\n\t\tz_{1}&=R+\\sqrt{R^{2}-1} z_{2}=R-\\sqrt{R^{2}-1} \\quad(\\text{ inside }C)\\\\\n\t\t\\operatorname{Res}\\left(z=z_{2}\\right)&=\\lim _{z \\rightarrow z_{2}}\\left(z-z_{2}\\right) \\frac{1}{\\left(z-z_{1}\\right)\\left(z-z_{2}\\right)}\\\\\n\t\t&=\\frac{1}{z_{2}-z_{1}}=\\frac{1}{R-\\sqrt{R^{2}-1-R-\\sqrt{R^{2}-1}}}=\\frac{-1}{2 \\sqrt{R^{2}-1}}\\\\\n\t\t\\therefore \\int_{0}^{\\pi} \\frac{2 d \\theta}{(R-\\cos \\theta)}&=\\frac{-2}{i} \\times 2 \\pi i \\times \\frac{-1}{2 \\sqrt{R^{2}-1}}\\\\&=\\frac{2 \\pi}{\\sqrt{R^{2}-1}}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\t\\item The value of integral $\\int_{-\\infty}^{+\\infty} \\frac{d x}{\\left(1+x^{2}\\right)^{2}}$ is given by\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$\\frac{\\pi}{2}$\n\t\\task[\\textbf{b.}]$\\pi$\n\t\\task[\\textbf{c.}] $i \\frac{\\pi}{2}$\n\t\\task[\\textbf{d.}]  $\\frac{1}{4 i}$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t\\oint_{C} \\frac{d z}{\\left(1+z^{2}\\right)^{2}}&=\\int_{-\\infty}^{+\\infty} \\frac{d x}{\\left(1+x^{2}\\right)^{2}}+\\int_{\\Gamma} \\frac{d z}{\\left(1+z^{2}\\right)^{2}}\\\\\n\t\t\\text{\tpoles, }1+z^{2}&=0 \\quad z=\\pm i\\text{ of order $2 \\quad z=i$ is inside } c\\\\\n\t\t\\therefore \\operatorname{Res}(z=i)&=\\lim _{z \\rightarrow i} \\frac{1}{\\lfloor} \\frac{d}{d z}\\left[(z-i)^{2} \\frac{1}{(z-i)^{2}(z+i)^{2}}\\right]=\\lim _{z \\rightarrow i} \\frac{-2}{(z+i)^{3}}=\\frac{1}{4 i}\\\\\n\t\t\\oint_{C} \\frac{d z}{\\left(1+z^{2}\\right)^{2}}&=2 \\pi i \\times \\frac{1}{4 i}=\\frac{\\pi}{2}\\text{ also }\\int_{\\Gamma} \\frac{d z}{\\left(1+z^{2}\\right)^{2}}=0\\\\\n\t\t\\therefore \\int_{-\\infty}^{+\\infty} \\frac{d x}{\\left(1+x^{2}\\right)^{2}}&=\\frac{\\pi}{2}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\\item The value of $\\oint_{C} \\frac{\\sin 3 z}{z^{2}} d z$\n$c:|z|=\\pi$ is given by\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]$6 \\pi i$\n\t\\task[\\textbf{b.}]$-6 \\pi i$\n\t\\task[\\textbf{c.}]0\n\t\\task[\\textbf{d.}]  3\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\t\t\\frac{\\sin 3 z}{z^{2}}&=\\frac{1}{z^{2}}\\left[3 z-\\frac{(3 z)^{3}}{\\lfloor 3}+\\ldots\\right]=\\frac{3}{z}-\\frac{9}{2} z+\\ldots\\\\\n\t\t\\text{Residue }&=3\\\\\n\t\t\\therefore \\oint_{C} \\frac{\\sin 3 z}{z^{2}} d z&=2 \\pi i \\times 3\\\\&=6 \\pi i\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (a)}\n\\end{answer}\n\t\\item Consider a complex function $f(z)=\\frac{1}{z\\left(z+\\frac{1}{2}\\right) \\cos (z \\pi)}$. Which one of the following\nstatements is correct?\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}] $f(z)$ has simple poles at $z=0$ and $z=-\\frac{1}{2}$\n\t\\task[\\textbf{b.}]$f(z)$ has second order pole at $z=-\\frac{1}{2}$\n\t\\task[\\textbf{c.}]$f(z)$ has infinite number of second order poles\n\t\\task[\\textbf{d.}] $f(z)$ has all simple poles\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tf(z)&=\\frac{1}{z\\left(z+\\frac{1}{2}\\right) \\cos (z \\pi)}\\\\\n\t\\text{For }n^{t h}&\\text{ order pole $\\because \\lim _{z \\rightarrow a}(z-a)^{n} f(z)=$ finite and $\\neq 0$}\\\\\n\t\\text{At }z&=0\\\\\n\t\\lim _{z \\rightarrow 0} z f(z)&=\\text{ finite }\\Rightarrow z=0\\text{ is a simple pole.}\\\\\n\t\\text{At }z&=-\\frac{1}{2}\\\\\n\t\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{\\left(z+\\frac{1}{2}\\right)^{2}}{z\\left(z+\\frac{1}{2}\\right) \\cos z \\pi}&=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{\\left(z+\\frac{1}{2}\\right)}{z \\cos z \\pi}\\\\&=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{1}{1 \\cdot \\cos z \\pi+z \\cdot \\pi(-\\sin z \\pi)}\\\\\n\t&=\\lim _{z \\rightarrow-\\frac{1}{2}} \\frac{1}{\\cos z \\pi-z \\pi \\sin z \\pi}\\\\&=\\frac{1}{\\frac{\\pi}{2}}=\\frac{2}{\\pi}\\\\&=\\text{ finite}\\\\\n\t\\Rightarrow f(z)\\text{ has second order pole at }z&=-\\frac{1}{2}\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (b)}\n\\end{answer}\n\t\\item The value of integral\n$$\nI=\\oint_{c} \\frac{\\sin z}{2 z-\\pi} d z\n$$\nwith $c$ a circle $|z|=2$, is\n\\begin{tasks}(2)\n\t\\task[\\textbf{a.}]0\n\t\\task[\\textbf{b.}]$2 \\pi i$\n\t\\task[\\textbf{c.}]$\\pi i$\n\t\\task[\\textbf{d.}] $-\\pi i$\n\\end{tasks}\n\\begin{answer}\n\t\\begin{align*}\n\tI&=\\oint_{C} \\frac{\\sin z}{2 z-\\pi} \\quad\\text{ pole }\\Rightarrow 2 z-\\pi=0 \\Rightarrow z=\\frac{\\pi}{2}\\\\\n\t\\text{\tResidue at }z&=\\frac{\\pi}{2} \\quad \\because|z|=2\\text{ so it will be lies within the contour}\\\\\n\tI&=\\oint_{C} \\frac{e^{i z}}{2\\left(z-\\frac{\\pi}{2}\\right)}=\\sum Res \\times 2 \\pi i\\\\\n\t\\operatorname{Res} \\mid&=\\frac{\\left(z-\\frac{\\pi}{2}\\right) e^{i z}}{2\\left(z-\\frac{\\pi}{2}\\right)}\\\\&=\\frac{e^{i \\pi / 2}}{2}\\\\&=\\frac{i}{2}\\text{ (taking imaginary part, Residue $=\\frac{1}{2}$})\\\\\n\t\\text{Now }I&=\\frac{1}{2} \\times 2 \\pi i\\\\&=\\pi i\n\t\\end{align*}\n\tSo the correct answer is \\textbf{Option (c)}\n\\end{answer}\n\\end{enumerate}\n", "meta": {"hexsha": "58ce0b319cc9e964af02c4d2a37ce821e60c14fd", "size": 68393, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "CSIR- Mathematical Physics/chapter/Complex Analysis.tex", "max_stars_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_stars_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CSIR- Mathematical Physics/chapter/Complex Analysis.tex", "max_issues_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_issues_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CSIR- Mathematical Physics/chapter/Complex Analysis.tex", "max_forks_repo_name": "archives-futuring/CSIR-Physics-Study-Material", "max_forks_repo_head_hexsha": "689cff91895fec36b4bb0add178f13a0f68648ab", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 54.3232724384, "max_line_length": 826, "alphanum_fraction": 0.6101940257, "num_tokens": 28457, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8723473647220786, "lm_q2_score": 0.8615382058759129, "lm_q1q2_score": 0.7515605835032403}}
{"text": "\\section{Piecewise (bi-)linear functions on multilevel grids}\\label{sec:functions}\nAn image can be viewed as a function on a grid.  Images\nwith different resolutions can then be viewed as functions on grids of\ndifferent sizes.  The use of such multiple-grids is a main technique\nused in the standard multigrid method for solving discretized partial\ndifferential equations, \nand it can also be interpreted as a main ingredient used in\nconvolutional neural networks (CNN). \n\nWithout loss of generality, for simplicity, we assume that the initial\ngrid, $\\mathcal T$, is of size\n$$\nm=2^{s}+1~~~n=2^{t}+1 \n$$\nfor some integers $t\\ge 1$.\nStarting from $\\mathcal T_1=\\mathcal T$,  we consider a sequence of\ncoarse grids (as depicted in Fig.~\\ref{mgrid} with $J=4$):\n\\begin{equation}\n\\label{grids}\n\\mathcal T_1, \\mathcal T_2, \\ldots, \\mathcal T_J\n\\end{equation}\nsuch that ${\\cal T}_\\ell$ consist of $n_\\ell\\times n_\\ell$ grid\npoints, with \n\\begin{equation}\n\\label{mn-ell}\n m_\\ell=2^{s-\\ell+1}+1,~~ n_\\ell=2^{t-\\ell+1}+1.   \n\\end{equation}\n\\begin{figure}[!htbp]\\label{mgrid}\n\t\\begin{center}\n\t\t\\includegraphics[width=0.15\\textwidth]{grid2.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid1.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid0.png} \\quad \n\t\t\\includegraphics[width=0.15\\textwidth]{grid.png} \n\t\\end{center}\n\t$$ \n\t\\mathcal T_1\\hskip1in \\mathcal T_2\\hskip1in \\mathcal T_3\\hskip1in\\mathcal T_4\n\t$$\n\t\\caption{multilevel grids for piecewise linear functions}\n\\end{figure}\n\nThe grid points of these grids can be given by\n$$\nx_i^{\\ell}=i h_{\\ell}, y_j^{\\ell}=j h_{\\ell},  i=1, \\ldots, m_\\ell,\nj=1, \\ldots, n_\\ell.\n$$\nHere $h_{\\ell} = 2^{-s + \\ell -1}a$ for some $a >0$. The above geometric coordinates $(x_i^\\ell, y_i^\\ell)$\nare usually not used in image precess literatures, but they are relevant\nin the context of multigrid method for numerical solution of PDEs.\nWe now consider piecewise linear functions on the sequence of grids\n\\eqref{grids} and we obtain a nested sequence of linear vector spaces\n\\begin{equation}\n\\label{Vk}\n\\mathcal V_1\\supset\\mathcal V_2\\supset\\ldots\\supset \\mathcal\nV_J.\n\\end{equation}\nHere each $\\mathcal V_\\ell$ consists of all piecewise bilinear (or linear)\nfunctions with respect to the grid \\eqref{grids} and \\eqref{mn-ell}.\nEach $\\mathcal V_\\ell $ has a set of basis functions:\n$\\phi_{ij}^\\ell\\in \\mathcal V_\\ell$ satisfying:\n$$\n\\phi_{ij}^\\ell(x_p,y_q)=\\delta_{(i,j), (p,q)} = \n\\begin{cases}\n1 \\quad &\\text{if} \\quad (p,q) = (i,j), \\\\\n0 \\quad &{\\text{if}} \\quad (p,q)\\neq (i,j).\n\\end{cases}\n$$\nThus, for each $v \\in \\mathcal V_{\\ell}$, we have \n\\begin{equation}\\label{expand}\nv(x,y)=\\sum_{i=1}^{m_\\ell}\\sum_{j=1}^{n_\\ell}v^\\ell_{ij}\\phi_{ij}^\\ell(x,y).\n\\end{equation}\n\nLet $\\mathcal  V_1=\\mathcal  V_h$, then the finite element method: Find $u_h\\in \\mathcal  V_h$ such that \n\\begin{equation}\\label{FEdis}\na(u_h, v_h)=(f, v_h)~~~\\forall~~v_h\\in \\mathcal  V_h,\n\\end{equation}\nwhere $a(u_h, v_h)=(\\nabla u_h, \\nabla v_h)$.\n%\\begin{lemma}\n%FE $\\rightarrow$ FD with $f_{i,j}=\\int_{\\Omega}f(x,y)\\phi_{ij}(x,y)dxdy$.\n%\\end{lemma}\n\nFinite element method: $A_h: \\mathcal  V_h\\rightarrow \\mathcal  V_h, ~~(A_hu_h,v_h)_{L^2}=(\\nabla u_h, \\nabla v_h)$ (discrete Laplacian $A_h\\approx -\\Delta_h$. )\n\\begin{equation}\\label{FE:eq}\nA_hu_h=f_h,~~ \n\\end{equation}\nwhere~$f_h(x,y)=\\sum_{i=1}^{m_1}\\sum_{j=1}^{n_1}f_{i,j}\\psi_{i,j}(x,y)$ and $\\psi_{i,j}(x,y)\\subset \\mathcal V_h$ is also a basis, \nwhich is dual to the nodal basis $\\phi_{ij}(x,y)$. namely $(\\psi_{i,j}(x,y), \\phi_{i,j}(x,y))_{L^2}=\\delta_{(i,j), (p,q)}$.\n\nThe gradient descent for \\eqref{FE:eq} is equivalent to the damped Jacobi method for \\eqref{FE:eq} and can be written as follows \n$$\nu^k=u^{k-1}+S_0(f-K_A\\ast u^{k-1}),~~~1\\le k\\le m_1.\n$$\nSmoother  is equivalent to filter (filtering out high frequncies). Given any $u^0$, $u-u^k$ is much smoother than $u-u^0$. \n\n%Fine grid smoothing $\\Longleftrightarrow$ feature extraction.\n\nAfter smoothing, we do coarse grid correction: for example, for \n$\\mathcal T_h,~\\mathcal T_H,~H=2h, \\mathcal V_2=\\mathcal V_H\\subset \\mathcal V_h=\\mathcal V_1$, we do\n\\begin{itemize}\n\\item $K_A\\ast e=f- K_A\\ast u^{m_1}=r^h$;\n\\item  $u=u^{m_1}+e$;\n\\item  $K_A\\ast u=f$.\n\\end{itemize}\nWe need to solve the residual equation\n$$\nK_A\\ast e=r^h.\n$$\nMultigrid idea: solve this residual  equation on coarse grid space $\\mathcal V_H$ with $H=2h$ \n\n\\subsection{Pooling or restriction}\\label{sec:cnn-restriction}\nSolving the residual equation \n$$\nK_A\\ast e=r^h\n$$\nin matrix form is equivalent to solve the problem \n\\begin{equation}\\label{FEres}\na(e_h, v_h)=(r_h,v_h)~~\\forall~~v_h\\in \\mathcal V_h,\n\\end{equation}\nwhere \n\\begin{equation}\\label{expresion:residual}\ne_h=\\sum_{i=1}^{m_1}\\sum_{j=1}^{n_1}e^h_{i,j}\\phi^h_{i,j}(x,y), r_h=\\sum_{i=1}^{m_1}\\sum_{j=1}^{n_1}r^h_{i,j}\\psi^h_{i,j}(x,y).\n\\end{equation}\nWe solve the equation \\eqref{FEres} on the coarse grid space $\\mathcal V_H$, namely \n\\begin{equation}\\label{FEres:coarse}\na(e_{2h}, v_{2h})=(r_h,v_{2h})~~\\forall~~v_{2h}\\in \\mathcal V_{2h},\n\\end{equation}\nwhere $e_{2h}=\\sum_{i=1}^{m_2}\\sum_{j=1}^{n_2}e^{2h}_{i,j}\\phi^{2h}_{i,j}(x,y)$, the matrix form for \\eqref{FEres:coarse} is \n\\begin{equation}\\label{coarse:matrix}\nK_A\\ast e^{2h}=r^{2h},~~r_{i,j}^{2h}=(r_h,\\phi^{2h}_{i,j})\n\\end{equation}\n\\begin{equation}\\label{restriction}\nr_{i,j}^{2h}=(r_h,\\phi^{2h}_{i,j})\n\\end{equation}\nNow we consider the expression of nodal basis functions $(\\phi_{i,j}^{2h})(x,y)\\subset \\mathcal V_{2h}$ \nby the nodal basis functions $(\\phi_{i,j}^{h})(x,y)\\subset \\mathcal V_{h}$. Here, we only show the details of the case of \nbilinear finite element space. The case of linear finite element space can be shown similarly. \n\\begin{equation}\\label{basis:plongation}\n\\begin{split}\n\\phi_{i,j}^{2h}(x,y)&=\\phi_{2i,2j}^{h}(x,y)+\\frac{1}{2}\\left(\\phi_{2i-1,2j}^{h}(x,y)+\\phi_{2i,2j-1}^{h}(x,y)\n+\\phi_{2i+1,2j}^{h}(x,y)+\\phi_{2i,2j+1}^{h}(x,y)\\right)\\\\\n&+\\frac{1}{4}\\left(\\phi_{2i-1,2j-1}^{h}(x,y)+\\phi_{2i+1,2j-1}^{h}(x,y)\n+\\phi_{2i+1,2j+1}^{h}(x,y)+\\phi_{2i-1,2j+1}^{h}(x,y)\\right)\n\\end{split}\n\\end{equation}\n\n\n\\input{6DL/MgNet_ConvStride.tex}\n\n\n\\subsection{Prolongation under the convolution notation}\nDenote $\\phi^h=\\{\\phi^h_{i,j}\\}\\in \\mathbb R^{m_1\\times n_1}$, \nby the definitions of convolution \\eqref{con1} and stride \\eqref{stride}, \\eqref{basis:plongation} means that \n$$\n \\phi^{2h}=K_R\\ast_2 \\phi^{h},\n$$\nwhere \n\\begin{equation}\\label{bi-restrict}\n\tK_R=\n\t\\begin{pmatrix}\n\t\\frac{1}{4} &\\frac{1}{2}&\\frac{1}{4}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{4}&\\frac{1}{2}&  \\frac{1}{4} \n\t\\end{pmatrix}.\n\t\\end{equation}\nNow we derivatve of restriction and prolongation as follows. \n\nLet $r_{i,j}^{2h}=(r_h,\\phi^{2h}_{i,j})_{L^2(\\Omega)}$, then we have\n\\begin{equation}\n\\begin{split}\n r^{2h}&=\\int_{\\Omega} r_h \\phi^{2h}=\\sum\\limits_{i=1}^{m_1}\\sum\\limits_{j=1}^{n_1}\\int_{\\Omega}r_{i,j}^{h}\\psi_{i,j}(K_R\\ast_2) \\phi^h\n=\\sum\\limits_{i=1}^{m_1}\\sum\\limits_{j=1}^{n_1}r_{i,j}^{h}(K_R\\ast_2)\\int_{\\Omega}\\psi_{i,j} \\phi^h\\\\\n&=\\sum\\limits_{i=1}^{m_1}\\sum\\limits_{j=1}^{n_1}(K_R\\ast_2)r_{i,j}^{h}e_ie_j=K_R\\ast_2 r^{h}.\n\\end{split}\n\\end{equation}\nHence the restriction \n$$\nR^{2h}_h: \\mathbb R^{m_{1}\\times n_{1}}\\mapsto  \\mathbb R^{m_{2}\\times n_{2}} \n$$\nis obtain by $R^{2h}_h  r^{h}= K_R\\ast_2  r^{h}$, namely\n\\begin{equation}\\label{restriction:freedom}\n\\begin{split}\nr_{i,j}^{2h}&=r^{h}_{2i,2j}+\\frac{1}{2}(r^{h}_{2i-1,2j}+r^{h}_{2i,2j-1}+r^{h}_{2i+1,2j}+r^{h}_{2i,2j+1})\\\\\n&+\\frac{1}{4}\\left(r^{h}_{2i-1,2j-1}+r^{h}_{2i+1,2j-1}+r^{h}_{2i+1,2j+1}+r^{h}_{2i-1,2j+1}\\right).\n\\end{split}\n\\end{equation}\n. \n\nNext \nlet $u_{2h}=\\sum\\limits_{i=1}^{m_2}\\sum\\limits_{j=1}^{n_2}u_{i,j}^{2h}\\phi^{2h}_{i,j}=( u^{2h}, \\phi^{2h})_{l^2}$, then we have\n\\begin{equation}\n%\\begin{split}\nu_{2h}=( u^{2h}, \\phi^{2h})_{l^2}\n=( u^{2h}, K_R\\ast_2\\phi^{h})_{l^2}=(K_R\\ast_2^{\\top} u^{2h}, \\phi^{h})_{l^2}.\n%\\end{split}\n\\end{equation}\nThus the prolongation $P_{2h}^h u^{2h}=K_R\\ast_2^{\\top} u^{2h}$. Therefore by the definition of $K_R$ and equations \n\\eqref{eq:7} and \\eqref{eq:9} for the expression of $K_R\\ast_2^{\\top}$, we have \n the prolongation \n$$\nP_{2h}^h: \\mathbb R^{m_{2}\\times n_{2}}\\mapsto  \\mathbb R^{m_{1}\\times n_{1} }\n$$\nis defined by \n$$\nu^h_{2i,2j}=u^h_{i,j},\n$$\n$$\nu^h_{2i-1,2j}=\\frac{1}{2}(u^h_{i,j}+u^h_{i-1,j}),~~~ u^h_{2i,2j-1}=\\frac{1}{2}(u^{2h}_{i,j}+u^{2h}_{i,j-1})\n$$\nand \n$$\nu^h_{2i-1,2j-1}=\\frac{1}{4}(u^{2h}_{i,j}+u^{2h}_{i-1,j}+u^{2h}_{i-1,j-1}+u^{2h}_{i,j-1}).\n$$\nIn summery, for general $\\mathcal V_1=\\mathcal  V_\\ell,  \\mathcal V_2=\\mathcal  V_{\\ell+1}$, we have the restriction and prolongation\nas follows: \n\\begin{lemma}\\label{ris:plon}\nThe restriction \n$$\nR^{\\ell+1}_\\ell: \\mathbb R^{m_\\ell\\times n_\\ell}\\mapsto  \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}~~\\hbox{is}~~ R^{\\ell+1}_\\ell = K_R\\ast_2  \n$$ \nand the prolongation\n$$\nP_{\\ell+1}^{\\ell}: \\mathbb R^{m_{\\ell+1}\\times n_{\\ell+1}}\\mapsto  \\mathbb R^{m_{\\ell}\\times n_{\\ell} } ~~\\hbox{is}~~ P^{\\ell}_{\\ell+1} =K_R\\ast_2^{\\top} \n$$\nwhere \n\\begin{equation}\\label{bi-restrict}\n\tK_R=\n\t\\begin{pmatrix}\n\t\\frac{1}{4} &\\frac{1}{2}&\\frac{1}{4}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t\\frac{1}{4}&\\frac{1}{2}&  \\frac{1}{4} \n\t\\end{pmatrix}.\n\t\\end{equation}\n\tfor bilinear finite element space or \n\\begin{equation}\\label{li-restrict}\n\tK_R=\n\t\\begin{pmatrix}\n\t0&\\frac{1}{2}&\\frac{1}{2}\\\\\n\t\\frac{1}{2}& 1&\\frac{1}{2}\\\\\n\t \\frac{1}{2} &\\frac{1}{2}& 0\n\t\\end{pmatrix}.\n\t\\end{equation}\t\nfor bilinear finite element space.\t\n\\end{lemma}\n\n\n\n\n\n\t\n\t\n\n", "meta": {"hexsha": "4f96b1523e71fabb974101c2dc38ef0318a0d00e", "size": 9425, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "6DL/MgNet_CNNintro.tex", "max_stars_repo_name": "liuzhengqi1996/math452", "max_stars_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "6DL/MgNet_CNNintro.tex", "max_issues_repo_name": "liuzhengqi1996/math452", "max_issues_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "6DL/MgNet_CNNintro.tex", "max_forks_repo_name": "liuzhengqi1996/math452", "max_forks_repo_head_hexsha": "635b6ce53cb792e316abf4f47396f2e4f0686815", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 37.5498007968, "max_line_length": 161, "alphanum_fraction": 0.6584615385, "num_tokens": 4043, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8596637505099168, "lm_q2_score": 0.87407724336544, "lm_q1q2_score": 0.7514125212669035}}
{"text": "\\subsection{Introduction}\n\n\\begin{frame}\n  \\frametitle{Simplex Algorithm}\n\n  Invented by Tobias Dantzig around 1950 \\\\\n  \\vfill\n  Used to solve optimization problems in linear programming \\\\\n  \\vfill\n  Greg Nelson was the first to employ it for \n  constraint solving, AFAIK, around 1980\n  \\vfill\n  Difference is that in linear programming input problem is\n  feasible and one looks for optimum. In constraint solving\n  problem can be infeasible, and we are interested in \n  finding any solution\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Introduction}\n\nLinear Rational Arithmetic \\Lra consists in solving\nBoolean combinations of atoms of the form\n$$\n\\sum_{j=1}^n a_j x_j \\leq b\\quad\\quad\\quad\\quad\\sum_{j=1}^n a_j x_j \\geq b\n$$\nwhere $a_j$ are constants (coefficients), $x_j$ are\nvariables, and $b$ is a constant (bound). The domain\nof $a_j$, $x_j$, $b$ is that of rationals.\n\\vfill\n\\pause\nNotice that the following translations hold\n\\begin{itemize}\n  \\item $\\sum_{j=1}^n a_j x_j = b     \\quad\\quad\\Longrightarrow\\quad\\quad  (\\sum_{j=1}^n a_j x_j \\leq  b) \\wedge (\\sum_{j=1}^n a_j x_j \\geq b)$  \n  \\item $\\sum_{j=1}^n a_j x_j < b     \\quad\\quad\\Longrightarrow\\quad\\quad$ see later\n  \\item $\\sum_{j=1}^n a_j x_j > b     \\quad\\quad\\Longrightarrow\\quad\\quad$ see later \n  \\item $\\sum_{j=1}^n a_j x_j \\not= b \\quad\\quad\\Longrightarrow\\quad\\quad  (\\sum_{j=1}^n a_j x_j < b) \\vee (\\sum_{j=1}^n a_j x_j > b)$  \n\\end{itemize}\n\n\\end{frame}\n\n\\subsection{Preprocessing}\n\n\\begin{frame}\n  \\frametitle{Preprocessing}\n\n  In the SMT setting, we are given a formula $\\varphi$ like\n  $$\n  (x \\geq 0) \\wedge ((x + y \\leq 2) \\vee (x + 2y - z \\geq 6)) \\wedge ((x + y \\geq 2) \\vee (2y - z \\leq 4))\n  $$\n  We perform a {\\bf preprocessing step}, in order to separate the formula into a set of {\\bf equations}\n  and a set of simple {\\bf bounds}. This is done by introducing {\\bf fresh} variables. \n  \\pause\n  \\vfill\n  The formula above $\\varphi$ is equivalent to (the conjunction of)\n  $$\n  \\begin{array}{lc}\n    (x \\geq 0) \\wedge ((s_1 \\leq 2) \\vee (s_2 \\geq 6)) \\wedge ((s_1 \\geq 2) \\vee (s_3 \\leq 4)) & \\onslide<3>{\\varphi'} \\\\\n    \\\\\n    (s_1 = x + y) \\\\ \n    (s_2 = x + 2y - z) & \\onslide<3>{A\\vec{x}=\\vec{0}} \\\\\n    (s_3 = 2y - z)\n  \\end{array}\n  $$\n\n\\end{frame}\n\n\\begin{frame}\n  \\frametitle{Preprocessing}\n  In general, from a formula $\\varphi$, we end up in a rewritten formula of the kind\n  $$\n  \\varphi' \\ \\wedge\\ A\\vec{x} = \\vec{0} \n  $$\n  where $\\varphi'$ is a Boolean combination of {\\bf bounds}, while $A\\vec{x}=\\vec{0}$ is a system of {\\bf equations}\n  of the form\n  $$\n  \\begin{array}{rcl}\n    a_{11} x_1 + \\ldots + a_{1n} x_n & = & 0 \\\\ \n    a_{21} x_1 + \\ldots + a_{2n} x_n & = & 0 \\\\ \n    \\ldots \\\\                             \n    a_{i1} x_1 + \\ldots + a_{in} x_n & = & 0 \\\\ \n    \\ldots \\\\                             \n    a_{m1} x_1 + \\ldots + a_{mn} x_n & = & 0 \\\\ \n  \\end{array}\n  $$\n  \\vfill\n  \\pause\n  Now we detach $A\\vec{x} = \\vec{0}$ from the formula, and we store it into the \\tsolver\n  permanently. The \\satsolver will work only on $\\varphi'$. Therefore {\\bf the constraints\n  that are pushed into and popped from the \\tsolver are just bounds} \n\n\\end{frame}\n", "meta": {"hexsha": "c2c04fc6d4f76e56904ea24e5a6a9d79e096b2c3", "size": 3161, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "lecture6/introduction.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/introduction.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/introduction.tex", "max_forks_repo_name": "formalmethods/smtlectures", "max_forks_repo_head_hexsha": "d4ec5f7eb377d26427ecc34c72906c85eafe8631", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-05-06T00:40:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-06T00:40:41.000Z", "avg_line_length": 33.6276595745, "max_line_length": 145, "alphanum_fraction": 0.6308130339, "num_tokens": 1156, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8740772286044095, "lm_q2_score": 0.8596637451167997, "lm_q1q2_score": 0.7514125038633798}}
{"text": "\\section{Groups}\r\n\\subsection{Basics}\r\n\\begin{definition}\r\n    A group is a pair $(G,\\cdot)$ consisting of a set $G$ and a function $\\cdot:G\\times G\\to G$ such that\\\\\r\n    1. $\\forall a,b,c\\in G,(a\\cdot b)\\cdot c=a\\cdot(b\\cdot c)$.\\\\\r\n    2. $\\exists e\\in G,\\forall g\\in G,e\\cdot g=g\\cdot e=e$.\\\\\r\n    3. $\\forall g\\in G,\\exists g^{-1}\\in G,g\\cdot g^{-1}=g^{-1}\\cdot g=e$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. To check something is a group, we need also to check that $\\cdot$ is well-defined.\r\n    This is sometimes called the closure axiom, i.e. $\\forall a,b\\in G, a\\cdot b\\in G$.\\\\\r\n    2. If using additive notation, we write $0$ for $e$ and if we are using mutiplicative notation we write $1$ for $e$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    For a group $(G,\\cdot)$, a subset $H\\subset G$ is a subgroup if $(H,\\cdot|_{H\\times H})$ is a well-defined group.\r\n    In this case, we write $H\\le G$.\r\n\\end{definition}\r\n\\begin{remark}\r\n    A nonempty subset $H\\subset G$ is a subgroup iff $\\forall a,b\\in H,ab^{-1}\\in H$.\r\n\\end{remark}\r\n\\begin{example}\r\n    1. $(\\mathbb Z,+)\\le(\\mathbb Q,+)\\le(\\mathbb R,+)\\le\\cdots$.\\\\\r\n    2. The cyclic group $C_n$ of order $n$ and the dihedral group $D_{2n}$ of isometries preserving a regular $n$-gon.\\\\\r\n    3. Symmetric groups $S_n$ of the permutations of $n$ letters and alternatig groups $A_n$ containing all even permutations of those $n$ letters.\\\\\r\n    4. The quarterion group $Q_8=\\{\\pm 1,\\pm i,\\pm j,\\pm k\\}$.\\\\\r\n    5. The group $\\operatorname{GL}_n(\\mathbb F)$ of all invertible matrices over a field $\\mathbb F$ is a group.\r\n    We can also get $\\operatorname{SL}_n(\\mathbb F)$ consisting of those with determinant $1$.\r\n\\end{example}\r\n\\begin{definition}\r\n    The direct product of groups $G,H$ is a group $G\\times H$ under the operation\r\n    $$\\forall g,g'\\in G,h,h'\\in H,(g,h)(g',h')=(gg',hh')$$ \r\n\\end{definition}\r\nFor a subgroup $H$ of $G$, the left cosets of $H$ are the sets of the form $gH,g\\in G$.\r\nIt is obvious that cosets partition $G$ and all of them have the same cardinality.\r\nSo immediately,\r\n\\begin{theorem}[Lagrange's Theorem]\r\n    If $G$ is finite and $H\\le G$, then $|H|$ divides $|G|$.\r\n\\end{theorem}\r\n\\begin{definition}\r\n    The value $|G|/|H|$ is called the index $|G:H|$ of $H$ in $G$.\r\n\\end{definition}\r\nThere is a partial converse to this theorem which we shall introduce soon.\r\n\\begin{theorem}[First Sylow's Theorem]\r\n    If $|G|=p^nm$ where $p$ is a prime and $p\\nmid m$, there is a subgroup $H\\le G$ such that $|H|=p^n$\r\n\\end{theorem}\r\nFrom which Cauchy's Theorem is immediate.\r\n\\begin{definition}\r\n    For $g\\in G$, the least $n$ such that $g^n=1$ is called the order of $g$.\r\n    If there is no such integer, we say $g$ has infinite order.\r\n\\end{definition}\r\n\\begin{remark}\r\n    1. If $g$ has order $d$, then $g^n=1\\iff d|n$.\\\\\r\n    2. $n||G|$ by considering the subgroup $\\langle g\\rangle$ generated by $g$.\r\n\\end{remark}\r\n\\begin{definition}\r\n    A subgroup $H\\le G$ is called a normal subgroup of $G$, written as $H\\unlhd G$, if $\\forall g\\in G,gHg^{-1}=H$.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    If $H\\unlhd G$, then the set of left cosets $gH$ is a group, called the quotient group $G/H$, under the operation $(aH)(bH)=abH$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial to check that the operation is well-defined.\r\n    The rest is obvious.\r\n\\end{proof}\r\n\\subsection{The Isomorphism Theorems}\r\n\\begin{definition}\r\n    Let $G,H$ be groups, a map $\\phi:G\\to H$ is called a group homomorphism if $\\forall g,g'\\in G,\\phi(gg')=\\phi(g)\\phi(g')$.\r\n    The kernel of $\\phi$ is defined as $\\ker\\phi=\\{g\\in G:\\phi(g)=1\\}\\le G$.\r\n    The image of $\\phi$ is defined as $\\operatorname{Im}\\phi=\\{h\\in H:\\exists g\\in G,\\phi(g)=h\\}\\le H$\r\n\\end{definition}\r\nObviously $\\ker\\phi\\unlhd G$.\r\nThe concerse is also true: any normal subgroup of $G$ is the kernel of the canonical projection of $G$ to the quotient.\r\n\\begin{definition}\r\n    An isomorphism is a bijective homomorphism.\r\n    We say $G,H$ are isomorphic, or $G\\cong H$, if there is an isomorphism between them.\r\n\\end{definition}\r\n\\begin{proposition}\r\n    If $\\phi$ is an isomorphism, so is $\\phi^{-1}$.\r\n\\end{proposition}\r\n\\begin{proof}\r\n    Trivial.\r\n\\end{proof}\r\n\\begin{theorem}[Isomorphism Theorem]\r\n    Let $\\phi:G\\to H$ be a group homomorphism, then $G/\\ker\\phi\\cong\\operatorname{Im}\\phi$.\r\n\\end{theorem}\r\n\\begin{proof}\r\n    The map $\\tilde{\\phi}:G/\\ker\\phi\\to\\operatorname{Im}\\phi$ by $g\\ker\\phi\\mapsto \\phi(g)$ is a well-defined isomorphism.\r\n\\end{proof}\r\n\\begin{example}\r\n    The function $\\exp:\\mathbb C\\to\\mathbb C^\\star$ is a homomorphism with kernel\r\n    $$\\ker\\exp=\\{z\\in C:\\exp(z)=1\\}=2\\pi\\mathbb Z,\\operatorname{Im}\\exp=\\mathbb C^\\star$$\r\n    Hence $\\mathbb C/2\\pi\\mathbb Z=\\mathbb C^\\star$.\r\n\\end{example}\r\nThe Isomorphism Theorem is sometimes called the \\textit{First} Isomorphism Theorem.\r\nThere are other isomorphism theorems, but they are all corollaries of the first one.\r\n\\begin{corollary}[Second Isomorphism Theorem]\r\n    Consider a group $G$ and subgroups $H\\le G,K\\unlhd G$, then the set $HK=\\{hk:h\\in H,k\\in K\\}$ is a subgroup of $G$.\r\n    Also $H\\cap K\\unlhd H$.\r\n    Then we have $HK/K\\cong H/H\\cap K$.\r\n\\end{corollary}\r\n\\begin{proof}\r\n    The (normal) subgroup conditions in $HK,H\\cap K$ are trivial.\r\n    The function $\\phi:H\\to G/K$ by $h\\mapsto hK$ is a homomorphism because it is the composition of the inclusion $H\\to G$ and the projection $G\\to G/K$.\r\n    So immediately $\\ker\\phi=H\\cap K$ and $\\operatorname{Im}\\phi=HK/K$, and the result follows.\r\n\\end{proof}\r\n\\begin{remark}\r\n    There is a natural bijection from the subgroups of $G/K$ and the subgroups of $G$ containing $K$ by $X\\mapsto \\{g\\in G:gK\\in X\\}$.\r\n    How about normal subgroups?\r\n    Turns out we have the Third Isomorphism Theorem to describe this.\r\n\\end{remark}\r\n\\begin{corollary}[Third Isomorphism Theorem]\r\n    Suppose $H,K$ are normal subgroups of $G$ and $K\\subset H$.\r\n    SO $K\\unlhd H$ and $H/K\\unlhd G/K$ with\r\n    $$G/H\\cong (G/K)/(H/K)$$\r\n\\end{corollary}\r\n\\begin{proof}\r\n    Let $\\phi:G/K\\to G/H$ by $gK\\mapsto gH$ which is clearly a well-defined surjective homomorphism, then $\\ker\\phi=H/K$.\r\n    The result then follows from the First Isomorphism Theorem.\r\n\\end{proof}\r\n\\subsection{Simple Groups}\r\nIf $K\\unlhd G$, then the study of the groups $K$ and $G/K$ gives some information about $G$ (but not all).\r\nBut sometimes this approach fails due to the lack of normal proper subgroups.\r\n\\begin{definition}\r\n    A group is called simple if it has no normal proper subgroups.\r\n\\end{definition}\r\n\\begin{lemma}\r\n    An abelian group $G$ is simple if and only if it is isomorphic to the cyclic group of order $p$ for some prime $p$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    An abelian group is simple if and only if it has no proper subgroup.\r\n    It is obvious that for any prime $p$, $C_p$ has no proper subgroup due to Lagrange's Theorem, so we proceed to the converse.\r\n    Note that any nonidentity element $x\\in G$ must generate $G$, otherwise the subgroup generated by it will be a proper subgroup of $G$.\r\n    However this means that $G$ is cyclic, so immediately to make it simple $G$ must be isomorphic to $C_p$ for some prime $p$.\r\n\\end{proof}\r\n\\begin{lemma}\r\n    If $G$ is a finite group, then it has a composition series\r\n    $$1=G_0\\lhd G_1\\lhd\\cdots\\lhd G_m=G$$\r\n    with $G_{i}/G_{i-1}$ is simple for each $i$.\r\n\\end{lemma}\r\n\\begin{proof}\r\n    Induction on $|G|$.\r\n    By the Third Isomorphism Theorem a normal proper subgroup $H\\lhd G$ with maximal order must have $G/H$ simple, so the result follows.\r\n\\end{proof}", "meta": {"hexsha": "b4f97d5438b2cd982399a18b0eb4ab128456a59b", "size": 7565, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "1/groups.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": "1/groups.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": "1/groups.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": 52.9020979021, "max_line_length": 155, "alphanum_fraction": 0.6683410443, "num_tokens": 2472, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951182587158, "lm_q2_score": 0.8902942173896131, "lm_q1q2_score": 0.7513149438690584}}
{"text": "\\documentclass{article}\n\n\\usepackage[margin=1.0in]{geometry}\n\\usepackage{amsmath}\n\\author{Aayush Arya \\\\ (tomriddle257@gmail.com)}\n\\title{Introduction to Ordinary Differential Equations}\n\\begin{document}\n\t\\maketitle\n\t\n\t\\section*{Introduction}\n\tWhen we solve an algebraic equation $3x + 5 = 8$, we seek a number. The purpose of solving a differential equation such as\n\t$$ \\frac{d^2x}{dt^2} = -\\frac{k}{m}x$$\n\t\n\tthe goal is to find a function x(t) that satisfies it.\n\t\n\tA differential equation of a function y(x) has the general form\n\t$$ f(x, y(x), y'(x), y''(x), ..., y^n(x)) = 0$$\n\t\n\t\\section*{Nature of Solutions}\n\tFor a differential equation\n\t\t$$ y'' + 2y' + 5 = 0$$\n\t\tif $y = g(x)$ and $y = h(x)$ are two solutions of the differential equations, then a linear combination of these, i.e.,\n\t\t$$ y = c_1g(x) + c_2h(x) $$\n\t\tis also a solution.\\\\\n\t\t\n\tA differential equation of order $n$ has $n$ independent solutions. We can form a general solution of the differential equation using a linear combination of the independent solutions. \\textit{Picard's Existence and Uniqueness Theorem} helps us figure out that our general solution is complete and no other solutions are left.\\\\ But how do we know that we have found a solution? The hallmark sign is that no derivatives of $y$ will be left in the equation.\n\tThe equation will relate $y$ with $x$ at least implicitly.\n\t\n\t\\section*{Geometric interpretation}\n\tThe geometric interpretation of differential equations is easier to see for linear equations.\\\\\n\tA differential equation of the form\n\t\\begin{equation}\n\t\\frac{dy}{dx} = f(x,y)\n\t\\end{equation}\n\tcan be interpreted as a set of vectors pointing towards (1, $\\frac{dy}{dx}$) at every point (x,y) in the plane.% \\footnote{See Chapter 1 of Simmons-Krantz}\n\t\\\\\n\tConsider the differential equation\n\t$$ y''(x) = 0 $$\n\tSolving this gives\n\t$$ y' = c_1 $$\n\t$$ y = c_1x + c_2 $$\n\tWhich looks like the familiar equation $y = mx + c$. We note that these arbitrary constants can take up any value. So the equation doesn't represent 'a' straight line but a family of straight lines (of having all possible slope values and y-intercepts).\n\t\n\t\\section{Solving first order equations}\n\t\\subsection*{Exact Differential Equations}\n\tAn exact or total differential of a function $\\psi(x,y)$ is one which shows the contribution of all independent variables for an infinitesimal change\n\t\\begin{equation}\n\td\\psi = \\frac{\\partial\\psi}{\\partial x}dx + \\frac{\\partial\\psi}{\\partial y}dy\n\t\\end{equation}\n\tA differential equation\n\t$$M(x,y)dx + N(x,y)dy = 0$$ is exact if it can be represented as the exact differential of some function $\\psi (x,y)$ where $d\\psi (x,y) = 0$\n\t\\\\\n\tThat is,\n\t$$M = \\frac{\\partial\\psi}{\\partial x} $$ and $$N = \\frac{\\partial\\psi}{\\partial y} $$\n\tA natural question arises: it would be easy to check the exactness for trivial expressions. Can we write a criterion that assures the exactness of the equation?\\\\\n\t\n\tThe equation is exact if\n\t$$ \\frac{\\partial M}{\\partial y} = \\frac{\\partial N}{\\partial x}$$\n\tbecause, if we substitute the expressions for M and Y as partial derivatives of $\\psi$, the criterion becomes\n\t\n\t$$\\frac{\\partial^2\\psi}{\\partial y \\partial x} = \\frac{\\partial^2\\psi}{\\partial x \\partial y}$$\n\t\n\tIf the equation is exact, it is easy to see that if $d\\psi=0$, the solution is just $\\psi = constant$\n\t\n\tTo find $\\psi$, we first integrate M(x,y)\n\t\n\t$$\\psi = \\int \\frac{\\partial \\psi}{\\partial x}dx + f(y)$$\n\tThe constant of integration is a function of y alone. This can be justified by intuition, because if we take the partial derivative of $\\psi$ with respect to x, the terms containing functions of y alone would have vanished. We'd like to bring those back.\n\t\\\\\n\t\n\tA more rigorous proof for this justification is as follows\\\\\n\t\n\tAs we said before,\n\t$$ N(x,y) = \\frac{\\partial\\psi}{\\partial y}$$\n\t\n\tsubstituting the value of $\\psi$ from the equation above\n\t \n\t$$ N(x,y) = \\frac{\\partial\\psi}{\\partial y} \\left(\\int \\frac{\\partial \\psi}{\\partial x}dx + f(y)\\right) $$\n\t\n\ttaking the partial derivative and transposing for f'(y)\n\t\n\t$$ f'(y) = N(x,y) - \\frac{\\partial\\psi}{\\partial y} \\left(\\int \\frac{\\partial \\psi}{\\partial x}dx\\right) $$\n\t\n\ttaking the partial derivate with respect to x leaves us with\n\t\n\t$$ \\frac{\\partial f'(y)}{\\partial x} = \\frac{\\partial N}{\\partial x} - \\frac{\\partial^2 }{\\partial x \\partial y}\\left(\\int \\frac{\\partial \\psi}{\\partial x}dx \\right) $$\n\t\n\twhich on simplifying, becomes\n\t\n\t$$ \\frac{\\partial f'(y)}{\\partial x} = \\frac{\\partial N}{\\partial x} - \\frac{\\partial M}{\\partial y} $$\n\t\n\tfrom the condition of exactness, we know that the R.H.S. is zero. Therefore\n\t\n\t$$f'(y) = C$$\n\t\n\twhich means $f(y)$ is some function of y alone.\n\t\n\t\\subsection{First Order Linear Differential Equations}\n\tThese are a special case of inexact equations. The general form of these equations is\n\t\t\\begin{equation}\n\t\\label{lineareqn}\n\ty'(x) + P(x)y = Q(x)\n\t\\end {equation}\n\tThese equations can be made exact by multiplying by a suitable integrating factor such that\n\t\n\t$$ \\frac{d(\\mu y)}{dx} = \\mu Q(x)$$\n\tand the solution is just\n\t\\begin{equation}\n\t\\boxed{\\mu (x) y = \\int \\mu(x) Q(x)}\n\t\\end{equation}\n\t$\\mu$ can be calculated easily. If we multiply equation \n\t\\ref{lineareqn} with $\\mu(x)$\n\t\n\t$$ \\frac{d(\\mu y)}{dx} = \\mu \\frac{dy}{dx} + \\mu (x) P(x) $$ \n\twhich becomes\n\t$$ \\mu\\frac{dy}{dx} + y\\frac{d\\mu}{dx} = \\mu \\frac{dy}{dx} + \\mu (x) P(x) $$\n\tsimplifying gives\n\t$$y\\frac{d\\mu}{dx} = \\mu (x)P(x) $$\n\tRearranging and integrating gives \n\t\\begin{equation*}\n\t\t\\boxed{\\mu = e^{\\int P(x)dx}}\n\t\\end{equation*}\n\t\\subsection{Homogenous equations}\n\tAn equation $f(x,y)=0$\n\t\\subsection{Special Forms}\n\tIf the equation is of the form $$yM(xy)dx + xN(xy)dy)$$\n\nthen its integrating factor $\\mu$ is given by\n\n$$ \\mu = \\frac{1}{M(xy) - N(xy)dy} $$\n\n\\subsubsection{Example}\nThe differential equation\n$$ y(1+xy)dx + x(1-xy)dy = 0$$\nhas the integrating factor\n $$ \\mu = \\frac{1}{Mx+ Ny} $$\n$$\\mu = \\frac{1}{xy + (xy)^2 + xy - (xy)^2} $$\n\n$$\\mu = \\frac{1}{2xy} $$\n\nMultiplying our equation with $\\mu$ gives\n\n$$\\frac{1}{2xy}\\cdot \\left(y(1+xy)dx + x(1-xy)dy\\right) = 0 $$\n\nwhich can be written as\n\n$$\\frac{(y + xy^2)dx + (x - x^2y)dy}{2xy} = 0 $$\n\nsimplifying and integrating,\n\n\n$$ \\int(\\frac{1}{2x} + \\frac{y}{2})dx + \\int(\\frac{1}{2y} + \\frac{x}{2})dy = 0$$\n\nwhich is\n\n$$log(x) + \\frac{y^2}{2} + log(y) + \\frac{x^2}{2} = 0 $$\n\nwhich can be further condensed\n\n$$ log(xy)^2 + x^2 + y^2 = C$$\n\nor \n\n$$ log(x^2y^2) + x^2 + y^2 = C$$\n\\end{document}", "meta": {"hexsha": "de062c07f840e6bd2c2ee082f3c1ce5267a913eb", "size": 6464, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Differential Equations/Intro.tex", "max_stars_repo_name": "cartilage-ftw/notes", "max_stars_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_stars_repo_licenses": ["CC0-1.0"], "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/Intro.tex", "max_issues_repo_name": "cartilage-ftw/notes", "max_issues_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_issues_repo_licenses": ["CC0-1.0"], "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/Intro.tex", "max_forks_repo_name": "cartilage-ftw/notes", "max_forks_repo_head_hexsha": "7dc18ec28890040405e48a4b42a936fa712cec40", "max_forks_repo_licenses": ["CC0-1.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.1757575758, "max_line_length": 457, "alphanum_fraction": 0.672029703, "num_tokens": 2080, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950947024555, "lm_q2_score": 0.8902942348544447, "lm_q1q2_score": 0.7513149376355418}}
{"text": "\\subsection{Variance of the IV estimator}\n\nIn OLS we had:\n\n\\(\\hat {\\theta_{OLS}} = (X^TX)^{-1}X^Ty\\)\n\n\\(Var [\\hat {\\theta_{OLS}}]=(X^TX)^{-1}X^T\\Omega X(X^TX)^{-1}\\)\n\nWith IV we have\n\n\\(\\hat {\\theta_{IV}} = (Z^TX)^{-1}Z^Ty\\)\n\n\\(Var [\\hat {\\theta_{IV}}]=(Z^TX)^{-1}Z^T\\Omega Z(Z^TX)^{-1}\\)\n\nWe can use weighted least squares for \\(\\Omega \\).\n\n\n", "meta": {"hexsha": "5694f5f857417373996370dc947e60a340a0d591", "size": 343, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/pug/theory/statistics/olsMore/05-03-variance.tex", "max_stars_repo_name": "adamdboult/nodeHomePage", "max_stars_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/pug/theory/statistics/olsMore/05-03-variance.tex", "max_issues_repo_name": "adamdboult/nodeHomePage", "max_issues_repo_head_hexsha": "266bfc6865bb8f6b1530499dde3aa6206bb09b93", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2021-03-03T12:36:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T22:16:09.000Z", "max_forks_repo_path": "src/pug/theory/statistics/olsMore/05-03-variance.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.0555555556, "max_line_length": 63, "alphanum_fraction": 0.5539358601, "num_tokens": 139, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9441768557238084, "lm_q2_score": 0.7956581024858786, "lm_q1q2_score": 0.7512419654362886}}
{"text": "\\documentclass[twoside]{MATH77}\n\\usepackage{multicol}\n\\usepackage[fleqn,reqno,centertags]{amsmath}\n\\begin{document}\n\\hyphenation{DRDHERQL DRSHERQL ODSHERQL}\n\\begmath 5.2 Eigenvalues and Eigenvectors of a Hermitian Complex 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 right eigenvectors of an N $\\times $ N\ncomplex Hermitian matrix $A$. A complex matrix is Hermitian if its\ndiagonal elements are real and its off-diagonal pairs $a_{i,j}$ and\n$a_{j,i}$ are complex conjugates of each other. Such a matrix will\nhave real eigenvalues. The eigenvectors will in general be complex\nbut can be chosen so that the matrix $V$ of N eigenvectors is\nunitary, $i.e.$, the conjugate transpose of $V$ is the inverse of\n$V$.\n\n\\subsection{Usage}\n\n\\subsubsection{Program Prototype}\n\n\\begin{description}\n\\item[REAL]  \\ {\\bf AR}(LDA,$\\geq $N){\\bf , AI}(LDA,$\\geq $N) [LDA$\\geq $N]\n{\\bf ,\\newline\nEVAL}($\\geq $N)\n\n\\item[REAL]  \\ {\\bf VR}(LDA,$\\geq $N){\\bf , VI}(LDA,$\\geq $N){\\bf , WORK}($%\n\\geq $3N)\n\n\\item[INTEGER]  \\ {\\bf LDA, N, IERR}\n\\end{description}\n\nAssign values to AR(,), AI(,), LDA, and N.\n\n\\begin{center}\n\\fbox{\\begin{tabular}{@{\\bf }c}\nCALL SHERQL(AR, AI, LDA, N,\\\\\nEVAL, VR, VI, WORK, IERR)\\\\\n\\end{tabular}}\n\\end{center}\n\nResults are returned in EVAL(), VR(,), VI(,), and IERR.\n\n\\subsubsection{Argument Definitions}\n\n\\begin{description}\n\\item[AR(,), AI(,)]  \\ [inout] On entry the locations on and below the\ndiagonal of these arrays must contain the lower-triangular elements of the\nN $\\times $ N complex Hermitian matrix $A$ with the real part in AR(,) and\nthe imaginary part in AI(,). On return AR(,) and AI(,) contain information\nabout the unitary transformations used in the reduction of $A$ in their lower\ntriangle. The strict upper triangles of AR(,) and AI(,), and the diagonal of\nAR(,) are unaltered.\n\n\\item[LDA]  \\ [in] Dimension of the first subscript of the arrays AR(,),\nAI(,), VR(,), and VI(,). Require LDA $\\geq $ N.\n\n\\item[N]  \\ [in] Order of the complex Hermitian matrix $A$. N $\\geq 1.$\n\n\\item[EVAL()]  \\ [out] Array in which the N real eigenvalues of $A$ will be\nstored by the subroutine. The eigenvalues will be sorted with the\nalgebraically smallest eigenvalues first.\n\n\\item[VR(,), VI(,)]  \\ [out] On return contains the real and imaginary parts\nof the eigenvectors with column $k$ corresponding to the eigenvalue in EVAL$%\n(k)$. These N eigenvectors will be mutually orthogonal and will have a\nunit unitary norm.\n\n\\item[WORK()]  \\ [scratch] An array of at least 3N 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 SHERQL to DHERQL, and the REAL type statement to DOUBLE PRECISION.\n\n\\subsection{Examples and Remarks}\n\nConsider the following complex Hermitian matrix:\n\\begin{equation*}\nA=\\left[\n\\begin{array}{cccc}\n\\phantom{-}25 & -3-4i & -8+6i & \\phantom{-}0 \\\\\n-3+4i & \\phantom{-}25 & \\phantom{-}0 & -8-6i \\\\\n-8-6i & \\phantom{-}0 & \\phantom{-}25 & \\phantom{-}3-4i \\\\\n\\phantom{-}0 & -8+6i & \\phantom{-}3+4i & \\phantom{-}25\n\\end{array}\n\\right]\n\\end{equation*}\nunit unitary norm associated with these eigenvalues are column\nvectors with the following quadruples of elements:\n($0.5i$, $0.4+0.3i$, $-0.3+0.4i$, 0.5),\n($-0.5i$, $0.4+0.3i$, $0.3-0.4i$, 0.5),\n($-0.5i$, $-0.4-0.3i$, $-0.3+0.4i$, 0.5),  and\n($0.5i$, $-0.4-0.3i$, $0.3-0.4i$, 0.5), respectively.\n\nThe code in DRSHERQL, given below, computes the eigenvalues and eigenvectors\nof this matrix. Output from this program is given in the file ODSHERQL.\n\nBefore the call to SHERQL, the matrix is saved in order to compute the\nrelative residual matrix $D$ defined as%\n\\begin{equation*}\nC=\\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, and $\\gamma $ is the\nmaximum-row-sum norm of $A$.\n\nRecall that if ${\\bf v}$ is an eigenvector, then so is $\\alpha{\\bf\nv}$ for any nonzero complex scalar $\\alpha$.  More generally, if an\neigenvalue, $\\lambda$, of a complex Hermitian matrix occurs with\nmultiplicity $k$, there will be an associated  $k$-dimensional\ncomplex subspace in which every vector is an eigenvector for\n$\\lambda$.  This subroutine will return eigenvectors constituting an\northogonal basis for such an eigenspace.\n\n\\subsection{Functional Description}\n\nHouseholder complex unitary similarity transformations are used to transform\nthe matrix $A$ to a Hermitian tridiagonal matrix. Additional unitary\nsimilarity transformations are used to transform the matrix to a real\ntridiagonal matrix. From this point, this subroutine uses the same method as\nthe subroutine SSYMQR of Chapter~5.1. As was the case there, all routines\nare minor modifications of EISPACK routines, \\cite{Smith:1974:MER}.\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\nare computed correctly but the eigenvalues are not ordered, and the\neigenvectors are not computed. If N $\\leq $ 0 on entry, IERR is set to $-$1.\nIn either case an error message is printed using IERM1 of Chapter 19.2\nwith an error level of 0, before 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} \\\\\nDHERQL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nDHERQL, DIMQL, ERFIN, ERMSG, IERM1, IERV1\\rule[-5pt]{0pt}{8pt}}\\\\\nSHERQL & \\parbox[t]{2.7in}{\\hyphenpenalty10000 \\raggedright\nERFIN, ERMSG, IERM1, IERV1, SHERQL, SIMQL}\\\\\n\\end{tabular}\n\nConverted by: F. T. Krogh, JPL, October~1991.\n\n\n\\begcodenp\n\n\\lstset{language=[77]Fortran,showstringspaces=false}\n\\lstset{xleftmargin=.8in}\n\n\\centerline{\\bf \\large DRSHERQL}\\vspace{10pt}\n\\lstinputlisting{\\codeloc{sherql}}\n\n\\vspace{30pt}\\centerline{\\bf \\large ODSHERQL}\\vspace{10pt}\n\\lstset{language={}}\n\\lstinputlisting{\\outputloc{sherql}}\n\\end{document}\n", "meta": {"hexsha": "1334527c666929609c161a1b827a243a0a7c6ce4", "size": 6255, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/doctex/ch05-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/ch05-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/ch05-02.tex", "max_forks_repo_name": "jacobwilliams/math77", "max_forks_repo_head_hexsha": "b562d09e191e99eba8a5bedfec45acf7461203b1", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2016-01-07T09:26:45.000Z", "max_forks_repo_forks_event_max_datetime": "2018-11-25T05:32:54.000Z", "avg_line_length": 36.5789473684, "max_line_length": 98, "alphanum_fraction": 0.725019984, "num_tokens": 2019, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.875787001374006, "lm_q2_score": 0.8577681013541613, "lm_q1q2_score": 0.7512221533592354}}
{"text": "Previous chapters introduced several algorithms for robot localization and state estimation that are based on a probabilistic framework. In particular, the Bayes filter was first introduced as a fundamental approach to the problem, which uses a probabilistic state transition model and a measurement model to recursively update a belief distribution over possible states. A set tractable implementations of the Bayes filter that model the belief distribution in a \\textit{parametric} way, for example using Gaussian distributions, was then presented (in particular the Kalman and extended Kalman filters).\nThese filters leverage the structure of the parametric belief distribution to provide a computationally efficient approach to dealing with continuous state spaces (which have an infinite number of states). For example the Gaussian distribution represents a continuous distribution through a \\textit{finite} set of parameters: the mean and covariance.\nHowever there are also other implementations of Bayes filter that can be efficiently used in continuous state spaces that are \\textit{non-parametric}. \n\n\\notessection{Nonparametric Filters}\n\\cite{ThrunBurgardEtAl2005}\nIn contrast to parametric filters, \\textit{non-parametric} filters do not make assumptions on the structure of the belief distribution. This can be a desirable property for applications in robotics where rigid structures in the belief distribution may result in poor performance. A classic example is that the Gaussian distributions used in the Kalman filter and EKF are unimodal, which cannot express the possibility that two distinct ``high probability'' states might exist at the same time.\nNon-parametric filters on the other hand generally represent the belief distribution in an unstructured way, for example through a finite number of samples drawn from the distribution, which allows for more expressive distributions.\nThis chapter introduces two main approaches for non-parametric filtering: the \\textit{histogram filter} and the \\textit{particle filter}.\n\n\\subsection{Histogram Filter}\nThe histogram filter is essentially a modification of the discrete Bayes filter presented earlier to work in continuous state spaces. In particular, the continuous state space is decomposed into a finite number of regions and the belief is represented over the discretized space by collecting the finite number of probabilities of the state being in each discretized region.\n\nIn particular for the random state variable $X_t$, the continuous state space $\\text{dom}(X_t)$ is decomposed into a finite set of regions (often called \\textit{bins} in the context of histogram filters):\n\\begin{equation}\n\\text{dom}(X_t) = \\x_{1,t} \\cup \\x_{2,t} \\cup ... \\cup \\x_{K,t},\n\\end{equation}\nwhere $\\x_{k,t}$ is the $k$-th ``bin''.\nFor example, if the one-dimensional random variable $X$ could take on values in the interval $[a,b]$ then one possible decomposition would be to split the interval into a finite number of sub-intervals with equal width.\nThe belief distribution is then defined in non-parametric way by simply specifying a probability $p_{k,t}$ to each bin $\\x_{k,t}$. A probability density function can then be defined in a piecewise manner:\n\\begin{equation}\np(\\x_t) = \\frac{p_{k,t}}{\\lvert \\x_{k,t} \\rvert}, \\quad \\x_t \\in \\x_{k,t},\n\\end{equation}\nwhere $\\lvert \\x_{k,t} \\rvert$ denotes the ``area'' or ``volume'' of the bin.\nThis definition implies that the probability that the random variable $X_t$ takes on \\textit{any} value in the bin $\\x_{k,t}$ is equal to $p_{k,t}$.\n\nThe prediction and measurement update steps of the Bayes filter are then accomplished by also discretizing the state transition and measurement models by computing a representative ``mean'' state for each bin:\n\\begin{equation}\n\\hat{\\x}_{k,t} = \\lvert \\x_{k,t} \\rvert ^{-1}\\int_{\\x_{k,t}}x_t d \\x_t.\n\\end{equation}\nThe state transition model $p(\\x_{k,t} \\mid \\bu_t, \\x_{i,t-1})$ that defines the probability of transitioning from one bin to another is then approximated in terms of the mean bin states by:\n\\begin{equation}\np(\\x_{k,t} \\mid \\bu_t, \\x_{i,t-1}) \\approx \\eta \\lvert \\x_{k,t} \\rvert p(\\hat{\\x}_{k,t} \\mid \\bu_t, \\hat{\\x}_{i,t-1}),\n\\end{equation}\nwhere $p(\\hat{\\x}_{k,t} \\mid u_t, \\hat{\\x}_{i,t-1})$ is the original (non-discretized) state transition model evaluated at the mean bin states $\\hat{\\x}$ and $\\eta$ is a normalization constant\\footnote{In the case that the bin areas $\\lvert \\x_{k,t} \\rvert$ are equal, these terms can be absorbed into the normalization constant.}.\n\nThe discretization of the measurement model is accomplished in a similar manner, with the discretized model given by:\n\\begin{equation}\np(\\z_t \\mid \\x_{k,t}) \\approx p(\\z_t \\mid \\hat{\\x}_{k,t}).\n\\end{equation}\nIn other words, the measurement probability associated with a bin is approximated by the measurement probability associated with the mean bin state $\\hat{\\x}_{k,t}$.\n\nAfter the discretization has been performed, the discrete Bayes filter algorithm from before can be directly applied by iterating over each bin and updating the probability $p_{k,t}$.\n\n\\subsection{Particle Filter}\nThe particle filter is another non-parametric filter that provides a computationally tractable implementation of the Bayes filter for continuous state spaces. This filter represents the belief distribution by a finite set of random samples called particles, which are denoted by:\n\\begin{equation}\n\\mathcal{X}_t \\coloneqq \\{\\x_t^{[1]}, \\x_t^{[2]},..., \\x_t^{[M]}\\}.\n\\end{equation}\nEach particle $\\x_t^{[m]}$ represents a hypothesis about the true state $\\x_t$, and therefore regions of the state space with more particles correspond to regions of high probability.\nIdeally, the particles are distributed according to the current belief:\n\\begin{equation}\n    \\x_t^{[m]} \\sim p(\\x_t \\mid \\z_{1:t}, \\bu_{1:t}) = bel(\\x_t),\n    \\label{bel-posterior}\n\\end{equation}\nbut theoretically this only occurs as $M\\rightarrow \\infty$. Instead the set of particles approximately represents the belief distribution, and in practice around $M\\approx 1000$ samples tends to be sufficient (but of course this depends on the application).\n\nThe particle filter updates the belief (via a prediction and measurement correction step) by manipulating the prior set of particles $\\mathcal{X}_{t-1}$ to yield a new set of particles $\\mathcal{X}_t$. The prediction step is implemented by considering each particle $\\x_{t-1}^{[m]}$ in the prior set $\\mathcal{X}_{t-1}$ and sampling from the state transition model a new ``predicted'' sample $\\bar{\\x}_{t}^{[m]} \\sim p(\\x_t \\mid \\bu_t, \\x_{t-1}^{[m]})$. An importance factor $w_{t}^{[m]}$ is then defined for the predicted sample $\\bar{\\x}_{t}^{[m]}$ based on how well the observed measurement matches the prediction. Specifically, the importance factor is computed as $w_t^{[m]} = p(\\z_t \\mid \\bar{\\x}_t^{[m]})$. The predicted particles $\\bar{\\x}_{t}^{[m]}$ and their associated weights $w_t^{[m]}$ can then be collected in a new particle set $\\bar{\\mathcal{X}}_t$, which represents the predicted belief distribution $\\overline{bel}(\\x_t)$.\nThe correction step is then accomplished by simply resampling (with replacement) a new set of $M$ particles from the predicted set $\\bar{\\mathcal{X}}_t$ with a probability proportional to the weights $w_t^{[m]}$. This procedure performs the measurement correction by giving preference in the new sample set to those predicted particles that showed higher correlation to the measurement $\\z_t$.\nThe resampled points are then collected in a new set $\\mathcal{X}_t$ that defines the posterior belief distribution.\nThis algorithm is also outlined in Algorithm \\ref{alg:particle} and a few iterations of the algorithm for a simple robot localization problem are shown in Figure \\ref{fig:Particle_filter}.\n\n\\begin{algorithm}[ht]\n \\KwData{$\\mathcal{X}_{t-1}, \\bu_{t}, \\z_{t}$}\n \\KwResult{$\\mathcal{X}_{t}$}\n $\\bar{\\mathcal{X}}_{t} = \\mathcal{X}_t = \\emptyset$\\\\\n \\For{$m=1$ \\KwTo $M$}{\n  Sample $\\bar{\\x}_{t}^{[m]} \\sim p(\\x_t\\mid \\bu_t, \\x_{t-1}^{[m]})$\\\\\n  $w_t^{[m]} = p(\\z_t \\mid \\bar{\\x}_{t}^{[m]})$\\\\\n  $\\bar{\\mathcal{X}}_{t} = \\bar{\\mathcal{X}}_{t} \\cup \\big(\\bar{\\x}_{t}^{[m]}, w_t^{[m]} \\big)$\\\\\n }\n \\For{$m=1$ \\KwTo $M$}{\n  Draw $i$ with probability $\\propto w_t^{[i]}$\\\\\n  Add $\\bar{\\x}_{t}^{[i]}$ to $\\mathcal{X}_t$\n }\n \\Return $\\mathcal{X}_t$\n \\caption{Particle Filter Algorithm}\n \\label{alg:particle}\n\\end{algorithm}\n\nNote that the concept of resampling in the correction step can be quite important for reasons beyond just updating the belief for the measurement correction. In particular, without the resampling step over time some of the particles would drift to regions of low probability and there would be fewer particles to represent the regions of high probability. The resampling step can therefore be viewed as a probabilistic implementation of the Darwinian idea of survival of the fittest: it refocuses the particle set to regions in state space with high posterior probability. This helps from a computational efficiency standpoint because it reduces the number of particles that are needed by focusing them on the regions of the state space that matter (i.e. regions of high probability).\n\\begin{figure}[ht]\n\\centering\n\\includegraphics[width=0.8\\linewidth]{tex/figs/ch15_figs/particlefilter.png}\n\\caption{Particle filter used for robot localization. The initial set of particles are first updated according to the transition model, and then weighted according to the observation. Finally, a new set of particles is generated through weighted resampling.}\n\\label{fig:Particle_filter}\n\\end{figure}\n\n\\subsection{Exercises}\n\\subsubsection{Monte Carlo Localization}\nComplete \\textit{Extra Credit: Monte Carlo Localization} located in the online repository:\n\n\\vspace{\\baselineskip}\n\n\\url{https://github.com/PrinciplesofRobotAutonomy/AA274A_HW4},\n\n\\vspace{\\baselineskip}\n\nwhere you will implement a particle filter for localizing a robot with line feature extraction, similar to the exercise on EKF localization from the previous chapter.\n\n", "meta": {"hexsha": "baea496ff5552399c6d67fbe5eeb67ecc8f4e41f", "size": 10044, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/source/ch15.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/ch15.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/ch15.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": 99.4455445545, "max_line_length": 941, "alphanum_fraction": 0.7632417364, "num_tokens": 2532, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765281148512, "lm_q2_score": 0.8221891370573386, "lm_q1q2_score": 0.7512149162002948}}
{"text": "% !TEX root = Main.tex\n\\section{Gaussian Mixture Models (GMM)}\nFor GMM let $\\boldsymbol{\\theta}_k = (\\boldsymbol{\\mu}_k, \\boldsymbol{\\Sigma}_k)$; $p_{\\theta_k}(\\mathbf{x}) = \\mathcal{N}(\\mathbf{x} | \\boldsymbol{\\mu}_k, \\Sigma_k)$\\\\\n\\textbf{Mixture Models:} $p_\\theta(\\mathbf{x}) = \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x})$\\\\\n\\textbf{Assignment variable (generative model):} $z_{ij} \\in \\{0, 1\\}$, $\\sum_{j=1}^k z_{ij} = 1$\\\\\n$\\operatorname{Pr}(z_k = 1) = \\pi_k \\Leftrightarrow p(\\mathbf{z}) = \\prod_{k=1}^K \\pi_k^{z_k}$\\\\\n\\textbf{Complete data distribution:}\\\\\n$p_\\theta(\\mathbf{x}, \\mathbf{z}) = \\prod_{k=1}^K \\left( \\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})\\right)^{z_k}$\\\\\n\\textbf{Posterior Probabilities:} $\\\\\\operatorname{Pr}(z_k = 1 | \\mathbf{x}) = \\frac{\\operatorname{Pr}(z_k = 1) p(\\mathbf{x} | z_k = 1)}{\\sum_{l=1}^K \\operatorname{Pr}(z_l = 1) p(\\mathbf{x} | z_l = 1)} = \\frac{\\boldsymbol{\\pi}_k p_{\\theta_k}(\\mathbf{x})}{\\sum_{l=1}^K \\boldsymbol{\\pi}_l p_{\\theta_l}(\\mathbf{x})}$\n\\textbf{Likelihood of observed data $\\mathbf{X}$:}\\\\\n$p_\\theta(\\mathbf{X}) = \\prod_{n=1}^N p_\\theta(\\mathbf{x}_n) = \\prod_{n=1}^N \\left(\\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)$\n\\textbf{Max. Likelihood Estimation (MLE):}\\\\\n$\\argmax_\\theta\\sum_{n=1}^N \\log \\left( \\sum_{k=1}^K \\pi_k p_{\\theta_k}(\\mathbf{x}_n)\\right)\\\\\n\\ge \\sum_{n=1^N} \\sum_{k=1}^K{q_k[\\log p_{\\theta_k}(\\mathbf{x}_n) + \\log \\pi_k - \\log q_k]}$\\\\\nwith $\\sum_{k=1}^K{q_k} = 1$ by Jensen Inequality.\n\n\\subsection*{Generative Model}\n1. sample cluster index $j \\sim Categorical(\\pi)$\\\\\n2. given $j$, sample data $x \\sim \\text{Normal}(\\mu_j, \\Sigma_j)$\n\n\n\\subsection*{Expectation-Maximization (EM) for GMM}\n\\textbf{E-Step: }\\\\\nPr$[z_{k,n} = 1 | \\mathbf{x}_n] = q_{k, n} = \\frac{\\boldsymbol{\\pi}_k^{(t-1)} \\mathcal{N}(\\mathbf{x}_n | \\boldsymbol{\\mu}_k^{(t-1)}, \\boldsymbol{\\Sigma}_k^{(t-1)})}{\\sum_{j=1}^K \\boldsymbol{\\pi}_j^{(t-1)} \\mathcal{N}(\\mathbf{x}_n | \\boldsymbol{\\mu}_j^{(t-1)}, \\boldsymbol{\\Sigma}_j^{(t-1)})}$\\\\\n\\textbf{M-Step: } $\\boldsymbol{\\mu}_k^{(t)} := \\frac{\\sum_{n=1}^N q_{k,n} \\mathbf{x}_n}{\\sum_{n=1}^N q_{k,n}}$\n$, \\boldsymbol{\\pi}_k^{(t)} := \\frac{1}{N} \\sum_{n=1}^N q_{k,n}$\\\\\n$\\Sigma_k^{(t)} = \\frac{\\sum_{n=1}^N q_{k, n} (\\mathbf{x}_n - \\boldsymbol{\\mu}_k^{(t)})(\\mathbf{x}_n - \\boldsymbol{\\mu}_k^{(t)})^\\top}{\\sum_{n=1}^N q_{k,n}}$\n\n\\subsection*{Discussion K-means vs. EM}\nhard assignment vs soft. sherical clusters shapes vs covariance matrix. fast vs slow and more iteration. K-means can be used as initialization for EM.\\\\\nK-means os a special case of GMM with covariances $\\Sigma_j = \\sigma^2 * I$. in the limit of $\\sigma \\rightarrow 0$, recover K-means.\n\n\\subsection*{Model Order Selection (AIC / BIC for GMM)}\nTrade-off between data fit (i.e. likelihood $p(\\mathbf{X} | \\theta)$) and complexity (i.e. \\# of free parameters $\\kappa(\\cdot)$). For choosing $K$:\\\\\n\\textbf{Akaike Information Criterion}: $\\operatorname{AIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\kappa(\\theta)$\\\\\n\\textbf{Bayesian Information Criterion}: $\\operatorname{BIC}(\\theta | \\mathbf{X}) = -\\log p_\\theta(\\mathbf{X}) + \\frac{1}{2} \\kappa(\\theta) \\log N$\\\\\n\\# of free params, fixed covariance matrix: $\\kappa(\\theta) = K \\cdot D + (K - 1)$ ($K$: \\# clusters, $D$: $\\mathsf{dim}\\text{(data)}=\\mathsf{dim}(\\mu_i)$, $K-1$: \\# free clusters, full covariance matrix: $\\kappa(\\theta) = K(D + \\frac{D(D+1)}{2}) + (K - 1)$.\\\\\nCompare AIC/BIC for different $K$ -- the smaller the better. BIC penalizes complexity more.\n", "meta": {"hexsha": "0465fb74771041c72538ff1ba61504b10c304647", "size": 3494, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "GaussianMixtureModel.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": "GaussianMixtureModel.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": "GaussianMixtureModel.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": 89.5897435897, "max_line_length": 313, "alphanum_fraction": 0.6342301088, "num_tokens": 1440, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9136765163620469, "lm_q2_score": 0.822189134878876, "lm_q1q2_score": 0.7512149045468566}}
{"text": "\\lab{Algorithms}{Speeding up Python Functions: Vectorization}{Vectorization One}\n\n\\objective{Demonstrates the importance of vectorization.}\n\nThis lab introduces two applied topics (Information Entropy and Chebyshev Polynomials) to explore how we can make functions faster through vectorization. There are two primary motivations behind vectorizing code.  First, vectorized code is often much clearer and more concise than non-vectorized code.  The second, much larger motivation is performance.  Vectorized code is often order of magnitudes faster than non-vectorized code.\n\nThe concept behind vectorizing code is to move away from operating on one element at a time and toward operating on entire collections of elements at once.  This section will focus specifically on reducing the number of for loops in our program.  Let us look at two examples of functions that would be really useful if we could vectorize them to make them execute faster.\n\n\\section*{Information Entropy}\n\nInformation entropy is loosely defined as the amount of information that is encoded in each bit of a signal. It is directly related to amount of compression that a signal can undergo without loss.\n\nFor example, suppose that our signal is an infinite string ``AAAAAAA...\" Since the signal never changes, each additional bit after the first adds no new information. Thus the entropy in this case is zero.\n\nOn the other hand, we assign a truly random uniform binary source an entropy of one (such a source may be related to radioactive decay). The reason for this is that we have absolutely no clue what the next symbol we read will be.\n\nWe can empirically calculate the entropy of a given signal by the following:\n\\begin{equation*}\nH = -\\sum_k{p_k \\log_2(p_k)}\n\\end{equation*}\nwhere $p_k$ is the probability of the $k^{th}$ symbol. Note that this fits the two conventions we set above since\n\\begin{equation*}\n-(1\\cdot\\log_2(1) + 0\\cdot\\log_2(0)) = 0\n\\end{equation*}\n\\begin{equation*}\n-(\\frac{1}{2}\\log_2\\frac{1}{2} + \\frac{1}{2}\\log_2\\frac{1}{2}) = 1\n\\end{equation*}\n\n\\begin{problem}\nWrite a function that finds the entropy of an array (you will need to flatten multidimensional arrays to a single dimension). You will also need to empirically calculate the probability of a given symbol (start by letting your symbols be integers). To find the probability of a symbol, you need to find the number of times it occurs in the sequence and divide it by the length of the sequence (watch out for integer division).\n\\end{problem}\n\nWe can test the entropy function that you just wrote against bit sources to see how ``random\" they are. For example, we can read an image into Python and view it using the following code:\n\\begin{lstlisting}\n>>> from scipy import misc\n>>> img = misc.imread('cameraman.tif'); img\n\\end{lstlisting}\n\n\\begin{figure}[h!]\n\\begin{center}\n\\includegraphics{cameramanClean.pdf}\n\\end{center}\n\\caption{The MIT Camera Man, a classic image used in image processing}\n\\label{fig:cameramanclean}\n\\end{figure}\n\nYou should see the image shown in Figure \\ref{fig:cameramanclean}. Now pass this image to the entropy function to calculate the entropy of the image data. We get a value of $7.009$. If this image were uniformly random, the entropy would be $8$, since each pixel is an $8$ bit number, and a uniform distribution of integers between $1$ and $128 = 2^8$ will have an entropy of $8$ (you can verify this fairly easily using the equation we defined above). This implies that the image has potential for compression.\n\n\\begin{problem}\nNow rewrite your function without using loops. This is an example of using vectorization to speed up algorithms. Use the cameraman image to test how much faster this function is than the original.\n\\end{problem}\n\n\\section*{Chebyshev Polynomials}\n\nOne special class of polynomials is the class of Chebyshev Polynomials. They are useful in a variety of applications including:\n\\begin{itemize}\n\\item Evaluating integrals using Gaussian quadrature\n\\item Solving partial differential equations\n\\item Speeding up iterative matrix methods (finding eigenvalues and solving large systems)\n\\item Minimizing interpolation error\n\\end{itemize}\n\nWe will explain many of the these applications in subsequent chapters. The purpose of this example is for you to investigate ways to speed up a process on your own.\n\nThe $n^{th}$ Chebyshev Polynomial can be described equivalently by the following formulae\\footnotemark :\n\\begin{equation*}\nT_n(x) = \\cos(n \\cos^{-1}(x))\n\\end{equation*}\n\\begin{equation*}\nT_n(x) = 2xT_{n-1}(x) - T_{n-2}(x), T_0(x) = 1, T_1(x) = x\n\\end{equation*}\n\n\\footnotetext{Technically the first formula only works on the interval $[-1,1]$. There are more general formulae, piecewise defined using $\\cosh$ outside of $[-1,1]$, but for this exercise we'll stick to the above definition.}\n\n\\begin{problem}\nWrite a function that accepts a vector $x_0$ of values in $[-1,1]$ and a degree $n$.  The function should return an array evaluating each entry of $x_0$ at every Chebyshev polynomial of degree $n$ or less. The $n^{th}$ column of the output should contain the $n-1$ Chebyshev Polynomial evaluated at $x_0$.\n\nYou will be writing four slightly different versions of this function.\n\\begin{enumerate}\n\\item Use only for-loops and Python's \\li{math} library (you will need two for-loops).\n\\item Same as previous, but replacing one for loop with a list comprehension.\n\\item Use \\li{numpy.vectorize} to vectorize Python's \\li{math} functions.  Keep the list comprehension from previous part.\n\\item Use SciPy's optimized $\\cos$ and $\\arccos$ functions.\n\\end{enumerate}\n\nMake this function as fast as possible. You should investigate both mathematical definitions, and how the number of for-loops affects the speed.\n\\end{problem}\n", "meta": {"hexsha": "882e7b770c9b08d73d1d08d135b3d04b1dbc251b", "size": 5748, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Applications/Vectorization/Vectorization_C.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/Vectorization/Vectorization_C.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/Vectorization/Vectorization_C.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": 65.3181818182, "max_line_length": 510, "alphanum_fraction": 0.7754001392, "num_tokens": 1422, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8221891305219504, "lm_q2_score": 0.9136765151867664, "lm_q1q2_score": 0.7512148995997331}}
{"text": "\\subsection{Angles on a sphere}\nGiven two spherical segments $[AB]$ and $[AC]$ on a sphere around the origin $O$, how do we compute the amplitude of the angle they form on the surface of the sphere at $A$? This angle is equal to the angle between planes $OAB$ and $OAC$, or more precisely between their normals $A \\times B$ and $A \\times C$. Thus we can find the angle using \\lstinline|angle()|, which gives values in $[0,\\pi]$.\n\n\\centerFig{sph-13}\n\n\\begin{lstlisting}\ndouble angleSph(p3 a, p3 b, p3 c) {\n    return angle(a*b, a*c);\n}\n\\end{lstlisting}\n\nIf instead of values in $[0,\\pi]$, we want to know the oriented angle\\footnote{We defined a similar notion in 2D in section~\\ref{ss:cross}.} between $[AB]$ and $[AC]$, that is, how much we rotate if we go from $B$ to $C$ around $A$ counterclockwise, then we need to know on which side of plane $OAB$ point $C$ lies. If $C$ lies ``to the left'' of plane $OAB$, the angle given by \\lstinline|angle()| is correct, but if $C$ lies ``to the right'', we should subtract it from $2\\pi$.\n\n\\centerFig{sph-14}\n\n\\begin{lstlisting}\ndouble orientedAngleSph(p3 a, p3 b, p3 c) {\n    if ((a*b|c) >= 0)\n        return angleSph(a, b, c);\n    else\n        return 2*M_PI - angleSph(a, b, c);\n}\n\\end{lstlisting}\n\n\\subsection{Spherical polygons and area}\nGiven points $P_1,\\ldots,P_n$ on a sphere, let's call spherical polygon $P_1\\cdots P_n$ the region on the sphere delimited by spherical segments $[P_1P_2]$, $[P_2P_3]$, \\ldots, $[P_nP_1]$, and which is on the left when travelling from $P_1$ to $P_2$. The counterclockwise order is important here because both ``sides'' on the contour are valid candidates.\n\n\\centerFig{sph-15}\n\nComputing the area of such a spherical polygon is surprisingly simple. First, let's consider the case of a spherical triangle $ABC$. It's area is given by\n\\[r^2(\\alpha + \\beta + \\gamma - \\pi)\\]\nwhere $r$ is the radius of the sphere and $\\alpha,\\beta,\\gamma$ are the amplitudes of the three interior angles of $ABC$. Note that this would be equal to $0$ if $ABC$ were on a plane, but because of the curvature of the sphere, the angles of a triangle actually add up to more than $\\pi$.\n\nThis is actually pretty easy to prove. If we prolong the segments $[AB]$, $[BC]$, and $[CA]$ into their full great-circles, this splits the sphere into 8 parts, of which four are the direct image of each other by point reflection around the center of the sphere. Let's call $S$ the area of triangle $ABC$, and $S_A$ (resp. $S_B,S_C$ the area of the triangle on the other side of $[BC]$ (resp. $[CA],[AB]$).\n\n\\centerFig{sph-16}\n\nSince those four triangles cover half of the sphere together, we have $S+S_A+S_B+S_C = 2\\pi r^2$.\nBesides if we take triangle $ABC$ and the triangle on the other side of $[BC]$, together they form a whole \\emph{spherical wedge}\\footnote{A section of a sphere determined by two flat cuts going through the center. \\url{https://en.wikipedia.org/wiki/Spherical_wedge}} of angle $\\alpha$.\nSo their combined area should be $\\alpha/2\\pi$ of the total area, that is $S+S_A = 2\\alpha r^2$.\nSimilarly, we obtain $S+S_B = 2\\beta r^2$ and $S+S_C = 2\\gamma r^2$.\n\nCombining those four equations, we obtain\n\\begin{align*}\n2S &= (S+S_A) + (S+S_B) + (S+S_C) - (S+S_A+S_B+S_C)\\\\\n&= r^2(2\\alpha + 2\\beta + 2\\gamma - 2\\pi)\n\\end{align*}\nwhich is the desired result.\n\nThe formula can be extended to an arbitrary spherical polygon $P_1\\cdots P_n$. The area is given by \n\\[r^2\\,\\big[\\,\\mathrm{sum\\ of\\ interior\\ angles} - (n - 2)\\pi\\,\\big]\\]\nThis can be proven by decomposing the $n$-gon into $n-2$ triangles.\n\n\\begin{lstlisting}\ndouble areaOnSphere(double r, vector<p3> p) {\n    int n = p.size();\n    double sum = -(n-2)*M_PI;\n    for (int i = 0; i < n; i++)\n        sum += orientedAngleSph(p[(i+1)%n], p[(i+2)%n], p[i]);\n    return r*r*sum;\n}\n\\end{lstlisting}\n\n\\subsection{Solid angle}\nThe \\emph{solid angle} subtended by an object at an observation point $O$ is the apparent size of the object when looking at it from $O$. For example, the Sun and the Moon have roughly the same apparent size when watched from the Earth, even though their actual sizes are very different. So we say that they subtend the same solid angle at the observation point that is Earth.\n\nLet's define it more precisely. Just like the planar angle subtended by an object is the length of the object once it is projected onto a unit circle around the point, the solid angle subtended by an object is the area of the object once it is projected onto a unit sphere around the point.\n\n\\centerFig{sph-17}\n\nThe unit for solid angles is the steradian (\\steradian), and because the area of a unit sphere is $4\\pi$, a solid angle of $4\\pi$ means that the observation point is completely surrounded, while a solid angle of $2\\pi$ means that half of the view is covered.\n\nWe can easily find the solid angle subtended by a polygon by using the function \\lstinline|areaOnSphere()| we just defined and setting $r=1$. Indeed, all it does is compute angles, so the distance from the origin $O$ doesn't matter.\n\n\n\\centerFig{sph-18}\n\nThis also allows us to find the solid angle subtended by a polyhedron if we know which faces are visible from $O$.\n\n\\begin{mathy}\nThe solid angle subtended by a small surface $d\\vv{S}$ at a position $\\vv{r}$ is inversely proportional to the square of the distance from the origin, $\\normv{r}^2$, and proportional to the cosine of the angle between $\\vv{r}$ and $d\\vv{S}$, because a surface seen from sideways occupies less of the view. So we can also find solid angles with the following integral:\n\\[\\Omega = \\int \\frac{\\vv{r}\\cdot d\\vv{S}}{\\normv{r}^3}\\]\n\\end{mathy}\n\n\\subsection{3D winding number}\\label{ss:wind-3d}\nWe can use this notion of solid angle to implement a 3D version of winding number that we defined in section~\\ref{ss:wind-2d}. Given an observation point $O$ and a polyhedron, we will compute an integer that is\n\\begin{itemize}\n\\item $0$ if $O$ is outside the polyhedron;\n\\item $1$ if $O$ is inside the polyhedron, and the vector areas $\\vv{S}$ of the faces are oriented towards the outside;\n\\item $-1$ if $O$ is inside the polyhedron, and the vector areas $\\vv{S}$ of the faces are oriented towards the inside.\n\\end{itemize}\n\nTo do this, we will consider the faces one by one.\nFor each one, if its vector area $\\vv{S}$ points away from $O$, we add the solid angle it subtends to the total, and otherwise we subtract it.\nThat way:\n\\begin{itemize}\n\\item if $O$ is outside of the polyhedron, the solid angles will cancel out;\n\\item if $O$ is inside of the polyhedron and the $\\vv{S}$ point towards the outside, there will mostly be additions and the total will add up to $4\\pi$;\n\\item if $O$ is inside the polyhedron and the $\\vv{S}$ point towards the inside, there will mostly be subtractions and the total will add up to $-4\\pi$.\n\\end{itemize}\nDividing this total angle by $4\\pi$ gives the desired winding number.\n\n\\centerFig{sph-19}\n\nTo find what quantity to add or subtract for each face, we will use function \\lstinline|areaOnSphere()| directly. If $\\vv{S}$ points away from $O$, it will return a value in $(0,2\\pi)$, the area of the projection of the face a unit sphere, which we should keep. If $\\vv{S}$ points towards $O$, it will return a value in $(2\\pi,4\\pi)$, the area of the \\emph{rest} of the unit sphere, so we should remove $4\\pi$ to get the subtraction we want.\n\nSince we always want the value to be in $(-2\\pi,2\\pi)$ in the end, we can use function \\lstinline|remainder()|, giving the simple implementation below.\n\\begin{lstlisting}\nint windingNumber3D(vector<vector<p3>> fs) {\n    double sum = 0;\n    for (vector<p3> f : fs)\n        sum += remainder(areaOnSphere(1, f), 4*M_PI);\n    return round(sum / (4*M_PI));\n}\n\\end{lstlisting}\n", "meta": {"hexsha": "e8e25bc3958e280b23e41ac9e84a9502fc99381b", "size": 7713, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "archives/codelibraries/cp-geo-master/3d/sph/sph-angles.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-angles.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-angles.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": 66.4913793103, "max_line_length": 479, "alphanum_fraction": 0.7171009983, "num_tokens": 2262, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8991213772699435, "lm_q2_score": 0.8354835330070839, "lm_q1q2_score": 0.7512011048836875}}
{"text": "\\section{Introduction}\nThis paper discusses the symmetric groups as an idexed category and their representations on finitely generated modules of some unital commutative ring ($\\zz$, $\\zz_n$, ...). Firstly, we will briefly discuss (finite groups) and their representations.\n\\subsection{Representation theory}\nGiven a unital commutative ring $R$ and a group $G$, a representation is some $R$ module $M$ with a group homomorphism\n$$\\rho : G \\longrightarrow \\mathrm{Gl}_R(M).$$\nIt is denoted by the pair $(M, \\rho)$. Alternatively, the module $M$ for every representation $(M, \\rho)$ is called a $G$ module, with $G$ action induced via $\\rho$:\n$$\\alpha : G \\times M \\longrightarrow M,\\ (g, m) \\longmapsto \\rho(g)(m).$$\nThus, discussing $G$ modules or representations $(M, \\rho)$ is identical. If the representation homomorphism $\\rho$ is clear from the context, we will omit it and simply write\n$$G.M = \\{g \\cdot m: g \\in G, m \\in M\\} \\subset M \\equiv \\{\\rho(g)(m) : g \\in G, m \\in M\\} \\subset M$$\nif we wish to define a $G$ module.\n\\begin{defi}\nGiven a representation $(M, \\rho)$ for a group $G$. We call a submodule $N \\subset M$ a sub representation or a $G$ submodule if\n$$\\rho : G \\longrightarrow \\mathrm{Gl}_R(N) \\Leftrightarrow G.N \\subset N.$$\nFor two representations $(M, \\rho_M)$, $(N, \\rho_N)$, we call a module homomorphism $\\phi \\in \\mathrm{Hom}_R(M,N)$ a $G$ module homomorphism if the following diagram commutes:\n$$\\xymatrix{\nM \\ar[r]^{g}\\ar[d]_\\phi &M\\ar[d]^\\phi\\\\\nN \\ar[r]_g & N.\\\\\n}$$\n\\end{defi}\n\\paragraph{Remark}\nFor a given $G$ module $M$ and a $G$ submodule $N \\subset M$, the quotient module\n$$M/N := \\{m + N : m \\in M\\}$$\nis a $G$ module via:\n$$\\rho_{M/N} := \\left[m + N \\longmapsto g m + N\\right],$$\nas $G. N \\subset N$. In particular, the projections $\\pi_N, \\pi_{M/N} \\equiv id_{M/N} - \\pi_N$ are $G$ module homomorphisms. Therefore, the decomposition:\n$$M \\simeq M/N \\oplus N$$\nis a decomposition in 'smaller' $G$ modules. Furthermore, for any given $G$ submodule $N \\subset M$, we get the complement as a $G$ submodule $N' \\simeq M/N$. In addition, we have for to $G$ modules $M_1, M_2$ the sum \n$$M_1 + M_2 = \\left\\{\\sum_i \\lambda_i m_i : \\lambda_i \\in R, m_i \\in M_i\\right\\},$$\nas $G$ module via $\\rho_{M_1 + M_2} := (\\rho_1 + id_{M_2}) \\circ (\\rho_2 + id_{M_1})$, with $id_{M_i}$ as trivial representation. This gets us to a very important classification of $G$ modules:\n\\begin{defi}\nWe call a $G$ module simple/irreducible if the only $G$ submodules are $\\{0\\}$ and $M$ (i.e. the trivial $G$ submodules). Thus, its representation is called irreducible. A $G$ module is indecomposible if $M$ does not admit a decomposition in non-trivial $G$ submodules:\n$$M = M' \\oplus M'' \\Leftrightarrow (M' = \\{0\\} \\vee M'' = \\{0\\}.$$\nAquivalently, every decomposition into $G$ submodules is trivial if and only if $M$ is indecomposible.\n\\end{defi}\nFirstly, we remark that any $G$ module with a non-trivial submodule is called reducible. Secondly, we remark that a simple $G$ module is clearly indecomposible but, there are indecomposible modules that are reducible: $M = R.e_1 \\oplus R.e_2$, $G \\subset \\mathrm{Gl}_2(R)$ the group of upper triangular matrices and $A \\in G \\backslash \\{I_2\\}$ than clearly, $R.e_1$ is a non-trivial $G$ submodule, hence, reducible but indecomposible: basis $B = \\{b_1 = e_1, b_2 = e_1 + e_2\\}$\n$$A = \\left(\\begin{array}{cc}\\lambda & \\mu\\\\ &\\lambda'\\\\\\end{array}\\right)\\ \\mathrm{with}\\ \\lambda, \\lambda' \\in R^\\times \\wedge \\mu \\in R$$$$ \\Rightarrow\\ A.b_1 = \\lambda b_1,\\ A.b_2 = (\\lambda + \\mu) e_1 + \\lambda' e_2 = (\\lambda + \\mu - \\lambda' ) b_1 + \\lambda' b_2$$\nClearly, $b_2$ does not span its own $G$ submodule. Thus, our decomposition is not direct but also not trivial and therefore not simple but also indecomposible.\n$$\\{b_1 = e_1, b_2 = (\\lambda + \\mu - \\lambda') e_1 + \\lambda e_2\\} = M_0 \\supset M_1 = \\{b_1\\} \\supset 0$$\n", "meta": {"hexsha": "5b40dc9579e5e44621e3e1cca2d52afc07c1121f", "size": 3885, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "symm_grp_rep/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": "symm_grp_rep/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": "symm_grp_rep/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": 99.6153846154, "max_line_length": 478, "alphanum_fraction": 0.6795366795, "num_tokens": 1325, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086179043564153, "lm_q2_score": 0.8267118004748678, "lm_q1q2_score": 0.7511651436541933}}
{"text": "\\section{Polar Functions}\r\n\\subsection{Polar Coordinates}\r\nUp to this point, we've mostly described points in the plane by listing two numbers: the distance along the $x$-axis and the distance along the $y$-axis.\r\nThis description, called ``rectangular coordinates\" is pretty simple and has the advantage that every pair of coordinates describes a unique point on the plane. \\\\\r\n\r\n\r\nHowever, we could instead describe points in the plane with two numbers $(r,\\theta)$, where $r$ is the point's distance from the origin and $\\theta$ is the point's angle of inclination.\r\nThis system is more suited to describing points related to trig functions.\r\nFor example the point at $x=\\cos{\\frac{\\pi}{4}}$ and $y=\\sin{\\frac{\\pi}{4}}$ is $\\left(\\frac{\\sqrt{2}}{2},\\frac{\\sqrt{2}}{2}\\right)$ in rectangular coordinates but $\\left(1,\\frac{\\pi}{4}\\right)$ in polar coordinates. \\\\\r\n\r\n\r\nNote that unlike rectangular coordinates, multiple pairs of numbers can describe the same point.\r\nFor example $\\left(1,0\\right)$ is the same point as $\\left(1,2\\pi\\right)$ is the same point as $\\left(1,-2\\pi\\right)$ is the same point as $\\left(1,4\\pi\\right)$. \\\\\r\n\r\n\r\nWe can easily convert between polar and rectangular coordinates.\r\n\\begin{align*}\r\n\t\\left(r,\\theta\\right) \\text{polar} &= \\left(r\\cos{\\theta}, r\\sin{\\theta}\\right) \\text{rectangular} \\\\\r\n\t\\left(x,y\\right) \\text{rectangular} &= \\left(\\sqrt{x^2+y^2}, \\arctan{\\frac{y}{x}}\\right) \\text{polar}.\r\n\\end{align*}\r\n\r\n\\subsection{Polar Functions}\r\nPolar functions are written in the form $r = f(\\theta)$.\r\nUsing our polar coordinate conversion formulas, we can convert any polar function to a parametric function.\r\n\\begin{align*}\r\n\tx(\\theta) &= r\\cos{\\theta} = f(\\theta)\\cos{\\theta} \\\\\r\n\ty(\\theta) &= r\\sin{\\theta} = f(\\theta)\\sin{\\theta}.\r\n\\end{align*}\r\n\r\nNow we can use our parametric function formulas to get $\\dd{y}{x}$.\r\n\\begin{equation*}\r\n\t\\dd{y}{x} = \\frac{\\d{y}/\\d{\\theta}}{\\d{x}/\\d{\\theta}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tA cardioid is defined by $r=1-\\cos{\\theta}, 0 \\leq \\theta \\leq 2\\pi$.\r\n\tFind $\\dd{y}{x}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\t\\begin{align*}\r\n\t\tx(\\theta) &= \\left(1-\\cos{\\theta}\\right)\\cos{\\theta} \\\\\r\n\t\t\\dd{x}{\\theta} &= \\sin{(2\\theta)} - \\sin{\\theta} \\\\\r\n\t\ty(\\theta) &= \\left(1-\\cos{\\theta}\\right)\\sin{\\theta} \\\\\r\n\t\t\\dd{y}{\\theta} &= \\cos{\\theta} - \\cos{(2\\theta)} \\\\\r\n\t\t\\dd{y}{x} &= \\frac{\\cos{\\theta} - \\cos{(2\\theta)}}{\\sin{(2\\theta)} - \\sin{\\theta}} \\\\\r\n\t\t&= \\tan{\\frac{3\\theta}{2}}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Area Enclosed}\r\nWhen a polar function is changed by $\\d{\\theta}$, it sweeps out an circular sector.\r\n\r\n\\begin{figure}[H]\r\n\t\\label{polar_area}\r\n\t\\centering\r\n\t\\includegraphics[width=0.66\\textwidth]{./parametric_vector_polar/polar_area.png}\r\n\t\\caption{\\hyperref{}{}{}{Polar Area}}\r\n\\end{figure}\r\n\r\nThis circular sector has area $\\d{A} = \\frac{\\d{\\theta}}{2}r^2$.\r\nIntegrating $\\d{A}$ for $\\alpha \\leq \\theta \\leq \\beta$,\r\n\\begin{equation*}\r\n\tA = \\int_{\\alpha}^{\\beta}{\\frac{1}{2}r^2\\d{\\theta}} = \\int_{\\alpha}^{\\beta}{\\frac{1}{2}f^2(\\theta)\\d{\\theta}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the area inside the smaller loop of the lima\\c{c}on $r=2\\cos{\\theta}+1$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tFirst, we need to find our bounds on $\\theta$.\r\n\tWe know that the small loop begins and ends when $r=0$.\r\n\t\\begin{align*}\r\n\t\t0 &= 2\\cos{\\theta}+1 \\\\\r\n\t\t-\\frac{1}{2} &= \\cos{\\theta} \\\\\r\n\t\t\\theta &= \\frac{\\pi}{3}, \\frac{4\\pi}{3}.\r\n\t\\end{align*}\r\n\t\r\n\tNow that we have our bounds, we can integrate.\r\n\t\\begin{align*}\r\n\t\tA &= \\int_{2\\pi/3}^{4\\pi/3}{\\frac{1}{2}\\left(2\\cos{\\theta}+1\\right)^2\\d{\\theta}} \\\\\r\n\t\t&= \\frac{1}{2}\\left(\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}4\\cos^{2}\\left(\\theta\\right)\\d{\\theta}+4\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\cos\\left(\\theta\\right)\\d{\\theta}+\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\d{\\theta}\\right) \\\\\r\n\t\t&= \\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\left(1+\\cos\\left(2\\theta\\right)\\right)\\d{\\theta}+2\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\cos\\left(\\theta\\right)\\d{\\theta}+\\frac{1}{2}\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\d{\\theta} \\\\\r\n\t\t&= \\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\cos\\left(2\\theta\\right)\\d{\\theta}+2\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\cos\\left(\\theta\\right)\\d{\\theta}+\\frac{3}{2}\\int_{\\frac{2\\pi}{3}}^{\\frac{4\\pi}{3}}\\d{\\theta} \\\\\r\n\t\t&= \\frac{1}{2}\\sin\\left(2\\theta\\right)+2\\sin\\left(\\theta\\right)+\\frac{3}{2}\\theta \\biggr\\rvert_{2\\pi/3}^{4\\pi/3} \\\\\r\n\t\t&= \\left(\\frac{1}{2}\\sin\\left(\\frac{8\\pi}{3}\\right)+2\\sin\\left(\\frac{4\\pi}{3}\\right)+\\frac{3}{2}\\frac{4\\pi}{3}\\right)-\\left(\\frac{1}{2}\\sin\\left(\\frac{4\\pi}{3}\\right)+2\\sin\\left(\\frac{2\\pi}{3}\\right)+\\frac{3}{2}\\frac{2\\pi}{3}\\right) \\\\\r\n\t\t&= \\left(\\frac{\\sqrt{3}}{4}-\\sqrt{3}+2\\pi\\right)-\\left(-\\frac{\\sqrt{3}}{4}+\\sqrt{3}+\\pi\\right) \\\\\r\n\t\t&= \\frac{\\sqrt{3}}{2}-2\\sqrt{3}+\\pi \\\\\r\n\t\t&= \\pi-\\frac{3\\sqrt{3}}{2}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\subsubsection{Area Between Curves}\r\nThe area between $r_1(\\theta)$ and $r_2(\\theta)$ is simply the difference between the areas.\r\n\\begin{equation*}\r\n\tA = \\frac{1}{2}\\int_{\\alpha}^{\\beta}{r_1^2(\\theta)\\d{\\theta}} - \\frac{1}{2}\\int_{\\alpha}^{\\beta}{r_2^2(\\theta)\\d{\\theta}} = \\frac{1}{2}\\int_{\\alpha}^{\\beta}{(r_1^2(\\theta)-r_2^2(\\theta))\\d{\\theta}}.\r\n\\end{equation*}\r\n\r\n\\begin{example}\r\n\tFind the area that lies inside the circle $r=1$ and outside the cardioid $r=1-\\cos{\\theta}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tTo find the bounds, we need to find where these curves intersect.\r\n\t\\begin{align*}\r\n\t\t1 &= 1-\\cos{\\theta} \\\\\r\n\t\t\\cos{\\theta} &= 0 \\\\\r\n\t\t\\theta &= \\frac{\\pi}{2}, \\frac{-\\pi}{2}.\r\n\t\\end{align*}\r\n\t\r\n\tSince we want the area inside of the circle and outside of the cardioid, our bounds are $\\frac{-\\pi}{2} \\leq \\theta \\leq \\frac{\\pi}{2}$.\r\n\tWe'll also have $r_1(\\theta)$ be the circle and $r_2(\\theta)$ be the cardioid, since we are effectively finding the area inside the circle and subtracting away the area that is also in the cardioid.\r\n\t\\begin{align*}\r\n\t\tA &= \\frac{1}{2}\\int_{-\\pi/2}^{\\pi/2}{\\left(1^2 - \\left(1-\\cos{\\theta}\\right)^2\\right)\\d{\\theta}} \\\\\r\n\t\t&= \\frac{1}{2}\\int_{\\frac{-\\pi}{2}}^{\\frac{\\pi}{2}}\\left(2\\cos\\left(\\theta\\right)-\\cos^{2}\\theta\\right)\\d{\\theta} \\\\\r\n\t\t&= \\frac{1}{2}\\int_{\\frac{-\\pi}{2}}^{\\frac{\\pi}{2}}\\left(2\\cos\\left(\\theta\\right)-\\frac{1+\\cos\\left(2\\theta\\right)}{2}\\right)\\d{\\theta} \\\\\r\n\t\t&= \\frac{1}{2}\\left(2\\sin\\left(\\theta\\right)-\\frac{\\theta}{2}-\\frac{\\sin\\left(2\\theta\\right)}{4}\\right) \\biggr\\rvert_{\\frac{-\\pi}{2}}^{\\frac{\\pi}{2}} \\\\\r\n\t\t&= \\frac{1}{2}\\left(\\left(2\\sin\\left(\\frac{\\pi}{2}\\right)-\\frac{\\pi}{4}-\\frac{\\sin\\left(\\pi\\right)}{4}\\right)-\\left(2\\sin\\left(\\frac{-\\pi}{2}\\right)+\\frac{\\pi}{4}-\\frac{\\sin\\left(-\\pi\\right)}{4}\\right)\\right) \\\\\r\n\t\t&= \\left(2\\sin\\left(\\frac{\\pi}{2}\\right)-\\frac{\\pi}{4}-\\frac{\\sin\\left(\\pi\\right)}{4}\\right) \\\\\r\n\t\t&= 2-\\frac{\\pi}{4}.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tFind the area that lies outside the circle $r=1$ and inside the cardioid $r=1-\\cos{\\theta}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tWe need to make sure our bounds are sweeping out the correct area.\r\n\tIf we did $\\frac{-\\pi}{2} \\leq \\theta \\leq \\frac{\\pi}{2}$, we'd get the area inside the circle and outside the cardioid, which isn't what we want here.\r\n\tWe know that for polar coordinates, $\\frac{-\\pi}{2} \\equiv \\frac{3\\pi}{2}$.\r\n\tSo, out bounds are $\\frac{\\pi}{2} \\leq \\theta \\leq \\frac{3\\pi}{2}$.\r\n\tSince we want the area inside the cardioid and outside the circle, effectively taking the cardioid and subtracting away the intersection, so $r_1(\\theta)$ is the cardioid, and $r_2(\\theta)$ is the circle.\r\n\t\\begin{align*}\r\n\t\tA &= \\frac{1}{2}\\int_{\\pi/2}^{3\\pi/2}{\\left(\\left(1-\\cos{\\theta}\\right)^2-1^2\\right)\\d{\\theta}} \\\\\r\n\t\t&= \\frac{1}{2}\\int_{\\frac{\\pi}{2}}^{\\frac{3\\pi}{2}}\\left(\\cos^{2}\\left(\\theta\\right)-2\\cos\\left(\\theta\\right)\\right)\\d{\\theta} \\\\\r\n\t\t&= \\frac{1}{2}\\int_{\\frac{\\pi}{2}}^{\\frac{3\\pi}{2}}\\left(\\frac{1+\\cos\\left(2\\theta\\right)}{2}-2\\cos\\left(\\theta\\right)\\right)\\d{\\theta} \\\\\r\n\t\t&= \\frac{1}{2}\\left(\\frac{\\theta}{2}+\\frac{\\sin\\left(2\\theta\\right)}{4}-2\\sin\\left(\\theta\\right)\\right)\\biggr\\rvert_{\\pi/2}^{3\\pi/2} \\\\\r\n\t\t&= \\frac{1}{2}\\left(\\left(\\frac{3\\pi}{4}+\\frac{\\sin\\left(3\\pi\\right)}{4}-2\\sin\\left(\\frac{3\\pi}{2}\\right)\\right)-\\left(\\frac{\\pi}{4}+\\frac{\\sin\\left(\\pi\\right)}{4}-2\\sin\\left(\\frac{\\pi}{2}\\right)\\right)\\right) \\\\\r\n\t\t&= \\frac{\\pi}{4}+2.\r\n\t\\end{align*}\r\n\\end{answer}\r\n\r\n\\begin{example}\r\n\tFind the area inside both the circle $r=1$ and the cardioid $r=1-\\cos{\\theta}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThis area isn't between two polar curves like the previous examples in the sense that we can't define it as one region minus another.\r\n\tWe'll prove it it two ways: logically and by using two regions.\r\n\tLogically, we know that the total area of the circle is $\\pi$.\r\n\tWe also know the area inside the circle but outside the cardioid is $2-\\frac{\\pi}{4}$.\r\n\tSo,\r\n\t\\begin{equation*}\r\n\t\tA_{\\text{both}} = \\pi - \\left(2-\\frac{\\pi}{4}\\right) = \\frac{5\\pi}{4} - 2.\r\n\t\\end{equation*}\r\n\t\r\n\tWe can break the region inside both curves into two parts: a half circle for $x\\leq 0$ and the two cardioid bulges for $x\\geq 0$.\r\n\tThe area of the half-circle is $\\pi/2$.\r\n\tWe can find the area of the two cardioid bulges.\r\n\t\\begin{align*}\r\n\t\tA_{\\text{bulges}} &= 2A_{\\text{bulge}} \\\\\r\n\t\t&= \\int_{0}^{\\pi/2}{\\left(1-\\cos{\\theta}\\right)^2\\d{\\theta}} \\\\\r\n\t\t&= \\int_{0}^{\\frac{\\pi}{2}}\\left(\\cos^{2}\\theta-2\\cos\\left(\\theta\\right)+1\\right)\\d{\\theta} \\\\\r\n\t\t&= \\int_{0}^{\\frac{\\pi}{2}}\\left(\\frac{1+\\cos\\left(2\\theta\\right)}{2}-2\\cos\\left(\\theta\\right)+1\\right)\\d{\\theta} \\\\\r\n\t\t&= \\frac{3\\theta}{2}+\\frac{\\sin\\left(2\\theta\\right)}{4}-2\\sin\\left(\\theta\\right)\\biggr\\rvert_{0}^{\\frac{\\pi}{2}} \\\\\r\n\t\t&= \\frac{3\\pi}{4}+\\frac{\\sin\\left(\\pi\\right)}{4}-2\\sin\\left(\\frac{\\pi}{2}\\right) \\\\\r\n\t\t&= \\frac{3\\pi}{4}-2 \\\\\r\n\t\\end{align*}\r\n\t\r\n\tAdding in the area of the half-circle,\r\n\t\\begin{align*}\r\n\t\tA_{\\text{both}} &= A_{\\text{half}} + A_{\\text{bulges}} \\\\\r\n\t\t&= \\frac{\\pi}{2} + \\frac{3\\pi}{4} - 2 \\\\\r\n\t\t&= \\frac{5\\pi}{4} - 2.\r\n\t\\end{align*}\r\n\t\r\n\tWe see that we get the same answer either way.\r\n\\end{answer}\r\n\r\n\\subsubsection{Arc Length}\r\nSince we know how to convert polar functions to parametric, we can simply adapt the parametric arc length formula.\r\n\\begin{equation*}\r\n\ts = \\int_{\\alpha}^{\\beta}{\\sqrt{\\left(\\dd{x}{\\theta}\\right)^2 + \\left(\\dd{y}{\\theta}\\right)^2}\\d{\\theta}}.\r\n\\end{equation*}\r\n\r\n\r\nHowever, there is an alternate form that works just for polar functions.\r\nFor some small change $\\d{\\theta}$, we see a corresponding small changes $\\d{r}$ and $r\\d{\\theta}$.\r\n\\begin{figure}[H]\r\n\t\\label{polar_area}\r\n\t\\centering\r\n\t\\includegraphics[width=0.66\\textwidth]{./parametric_vector_polar/polar_length.png}\r\n\t\\caption{\\hyperref{}{}{}{Polar Arc Length}}\r\n\\end{figure}\r\nWe see that these changes for a right triangle with hypotenuse $\\d{s}$.\r\n\\begin{align*}\r\n\t(\\d{s})^2 &= (r\\d{\\theta})^2 + (\\d{r})^2 \\\\\r\n\t&= \\left(r^2 + \\left(\\dd{r}{\\theta}\\right)^2\\right)\\left(\\d{\\theta}\\right)^2 \\\\\r\n\t\\d{s} &= \\sqrt{r^2 + \\left(\\dd{r}{\\theta}\\right)^2}\\d{\\theta} \\\\\r\n\ts &= \\int_{\\alpha}^{\\beta}{\\sqrt{r^2 + \\left(\\dd{r}{\\theta}\\right)^2}\\d{\\theta}}.\r\n\\end{align*}\r\n\r\nGiving us an alternate formula for polar arc length.\r\n\r\n\\begin{example}\r\n\tFind the arc length of the cardioid $r=1-\\cos{\\theta}$.\r\n\\end{example}\r\n\\begin{answer}\r\n\tThe bounds are $0 \\leq \\theta \\leq 2\\pi$.\r\n\tUsing the polar arc length formula,\r\n\t\\begin{align*}\r\n\t\t\\dd{r}{\\theta} &= \\sin{\\theta} \\\\\r\n\t\t\\left(\\dd{r}{\\theta}\\right)^2 &= \\sin^2{\\theta} \\\\\r\n\t\ts &= \\int_{0}^{2\\pi}{\\sqrt{\\left(1-\\cos{\\theta}\\right)^2+\\sin^2{\\theta}}\\d{\\theta}} \\\\\r\n\t\t&= \\int_{0}^{2\\pi}{\\sqrt{2+2\\cos{\\theta}}\\d{\\theta}} \\\\\r\n\t\t&= \\int_{0}^{2\\pi}{2\\sin{\\left(\\frac{\\theta}{2}\\right)}\\d{\\theta}} \\\\\r\n\t\t&= -4\\cos{\\left(\\frac{\\theta}{2}\\right)}\\biggr\\rvert_{0}^{2\\pi} \\\\\r\n\t\t&= 8.\r\n\t\\end{align*}\r\n\\end{answer}\r\n", "meta": {"hexsha": "ee8bb0a22db27b6c5e163a9827f68fc7cba002f9", "size": 11757, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "calc/parametric_vector_polar/polar.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/parametric_vector_polar/polar.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/parametric_vector_polar/polar.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": 53.9311926606, "max_line_length": 238, "alphanum_fraction": 0.6226078081, "num_tokens": 4534, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178994073576, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7511651259851623}}
{"text": "\\section{Operations on FSA}\n\n\\subsection{Reflection}\nGiven a \\textbf{deterministic} FSA.\n\\begin{itemize}\n    \\item Switch initial and final states\n    \\item Reverse the arrow directions\n\\end{itemize}\n\n\\subsection{Complement}\nGiven a \\textbf{deterministic} FSA.\n\\begin{itemize}\n    \\item Extend the FSA with the error state: $Q' = Q \\cup \\{p\\}$\n    \\item Make $\\delta$ complete (using $p$)\n    \\item Switch final and non-final states\n\\end{itemize}\n\n\\subsection{Intersection}\n$M_1 \\cap M_2 = M_3$ where the states of $M_3$ are the cartesian product of the original 2 sets (i.e. all the pairs).\n\\[\n    <q_1, q_2> \\xrightarrow{a} <r_1,r_2> \\iff q_1\\xrightarrow{a} r_1 \\land q_2 \\xrightarrow{a} r_2\n\\]\n\nThe final/initial states are the ones final/initial for both.\n", "meta": {"hexsha": "6a81b9c1078948e51f261d92bb020614aedae52f", "size": 760, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "automata/operations-on-fsa.tex", "max_stars_repo_name": "Kakasinho/FLC-cheatsheet", "max_stars_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 5, "max_stars_repo_stars_event_min_datetime": "2020-01-13T14:36:20.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-18T16:22:18.000Z", "max_issues_repo_path": "automata/operations-on-fsa.tex", "max_issues_repo_name": "Kakasinho/FLC-cheatsheet", "max_issues_repo_head_hexsha": "9293e89e803006f1b419c78087caa5d5e04a5931", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "automata/operations-on-fsa.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": 30.4, "max_line_length": 117, "alphanum_fraction": 0.7144736842, "num_tokens": 251, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9086178895092414, "lm_q2_score": 0.8267117855317474, "lm_q1q2_score": 0.7511651178022729}}
{"text": "\\label{sec:general}\n\n\n%-----------------------------------------------------------------\n\n\\subsection{Identities for real vector operations}\n\\label{sec:RX}\n\nSee \\cite[p. 85, ex. 4-9]{spivak-1965}.\n\nLet $\\p, \\q \\in \\Reals^{n}$.\nLet $\\theta(\\p,\\q)$ be the angle between $\\p$ and $\\q$.\n\n\\begin{itemize}\n\\item The inner (dot) product:\n\\begin{equation}\n\\p \\bullet \\q \\; \\equiv \\; \\sum_{i=0}^{n-1} p_i q_i\n\\end{equation}\n\n\\item The euclidean ($l_2$) norm:\n\\begin{equation}\n\\| \\p \\|^2 \\; \\equiv \\; \\p \\bullet \\p\n\\end{equation}\n\\begin{equation}\n\\p \\bullet \\q \\; = \\; \\| \\p \\| \\| \\q \\| \\cos(\\theta(\\p,\\q))\n\\end{equation}\n\n\\item Orthogonal complement:\n\\begin{equation}\n\\p \\perp \\q \\; \\equiv \\; \\p \\; - \\; \\left( \\p \\bullet \\frac{\\q}{\\|\\q\\|}\\right) \\frac{\\q}{\\|\\q\\|}\n\\end{equation}\n\n\\item The tensor product\n\nLet $\\p \\in \\Reals^m, \\q, \\r \\in \\Reals^n.$\n$\\p \\otimes \\q$ is a rank 1 linear transformation\nfrom $\\Reals^n$ to $\\Reals^m$, defined by:\n\\begin{equation}\n(\\p \\otimes \\q)(\\r) \\; \\equiv \\; \\p (\\q \\bullet \\r)\n\\end{equation}\n\n\\end{itemize}\n\n%-----------------------------------------------------------------\n\n\\subsection{Identities for 3-dimensional vector operations}\n\\label{sec:R3X}\n\nSee \\cite[p. 85, ex. 4-9]{spivak-1965}.\n\nLet $\\p, \\q, \\r \\in \\Reals^3$.\nLet $(p_0,p_1,p_2), (q_0,q_1,q_2), (r_0,r_1,r_2), $ be their coordinates\nin some orthonormal basis.\n\nThe cross product:\n\\begin{equation}\n\\p \\times \\q  \\; \\equiv \\; (p_1 q_2 - p_2 q_1, \\; p_2 q_0 - p_0 q_2, \\; p_0 q_1 - p_1 q_0)\n\\end{equation}\n\\begin{equation}\n\\p \\times \\q  \\; = \\; - \\; \\q \\times \\p\n\\end{equation}\n\\begin{equation}\n\\| \\p \\times \\q \\| \\; = \\; \\| \\p \\| \\; \\| \\q \\| \\; \\sin(\\theta(\\p,\\q))\n\\end{equation}\n\\begin{equation}\n\\| \\p \\times \\q \\|  \\; = \\;  \\sqrt{\\| \\p \\|^2 \\| \\q \\|^2 \\; - \\; (\\p \\bullet \\q)^2}\n\\end{equation}\n\\begin{equation}\n\\p \\bullet ( \\p \\times \\q ) \\; = \\; ( \\p \\times \\q ) \\bullet \\q \\; = \\; 0\n\\end{equation}\n\\begin{equation}\n\\label{eq:dot_cross}\n\\p \\bullet ( \\q \\times \\r ) \\; = \\; ( \\p \\times \\q ) \\bullet \\r \\; = \\; \\q \\bullet ( \\r \\times \\p )\n\\end{equation}\n\\begin{equation}\n\\p \\times ( \\q \\times \\r ) \\; = \\; ( \\p \\bullet \\r ) \\q \\; - \\; (\\p \\bullet \\q) \\r\n\\end{equation}\n\\begin{equation}\n( \\p \\times \\q ) \\times \\r \\; = \\; ( \\p \\bullet \\r ) \\q \\; - \\; (\\q \\bullet \\r) \\p\n\\end{equation}\n\\begin{equation}\n( \\p \\times \\q ) \\times \\r \\; = \\; \\left((\\q \\otimes \\p) - (\\p \\otimes \\q)\\right) \\r\n\\end{equation}\n\n\n%------------------------------------------------------------------\n\n\\subsection{Functions on real vector spaces}\n\\label{sec:functions}\n\nThis paper describes functions of triangular meshes.\n\nInteresting functions usually depend, directly or indirectly,\non the positions of some subset of the vertices.\nI consider the vertex positions to be elements of $\\Reals^3$,\nwith an (implied) universal origin,\nand thus do not distinguish points and vectors.\n\nIn general, the functions discussed here map between real vector spaces:\n$\\f:{\\Re}^{n} \\mapsto \\Reals^{m}$, where $\\Reals^n$ is the\n{\\it domain} and $\\Reals^m$ is the {\\it codomain}.\nStrictly speaking, the {\\it range} of $\\f$ is the set $\\f(\\Reals^n)$,\nwhich may be a proper subset of its codomain $\\Reals^m$.\n\nI typically use $\\p$, $\\q$, $\\r$, etc., for elements of $\\Reals^n$\nand\n$\\f$, $\\g$, $\\h$ for vector-valued functions.\nI generally do not distinguish $\\Re$, the real numbers,\nand $\\Reals^1$, the 1-dimensional real vector space.\nI sometimes use $f$, $g$, $h$ for extra clarity in the special\ncase of real-valued functions.\n\nThe domains of many interesting functions,\nsuch as those that depend on vertex positions,\nare direct sums of $\\Reals^3$.\nThe {\\it direct sum} $\\Reals^n \\oplus \\Reals^m$ is the cartesian product\nof $\\Reals^n$ and $\\Reals^m$ --- the set of ordered pairs $(\\p,\\q)$\nwhere $\\p \\in \\Reals^n$ and $\\q \\in \\Reals^m$ ---\nwith the restriction that the inner product is the obvious extension of the\ninner products on $\\Reals^n$ and $\\Reals^m$:\n$(\\p_0,\\q_0) \\bullet (\\p_1,\\q_1) = (\\p_0 \\bullet \\p_1) + (\\q_0 \\bullet \\q_1).$\nFor simplicity, I identify\n$\\Reals^{3n} = \\Reals^3 \\oplus \\Reals^3 \\oplus \\cdots \\oplus \\Reals^3 = \\oplus^n \\Reals^3\n= \\Reals^n \\oplus \\Reals^n \\oplus \\Reals^n $.\nI will usually write an element of $\\oplus^n \\Reals^3$ as\n$(\\p_0,\\ldots,\\p_{n-1})$\nand use\n$\\f(\\p_0,\\p_1,\\ldots,\\p_{n-1})$\nfor a function that depends on $n$ vertices.\nSometimes it will be useful to separate the $x,$ $y,$ and $z$ coordinates:\n$\\p = (\\x,\\y,\\z),$\nwhere $\\x =(x_0, \\ldots x_{n-1}) \\in \\Reals^n$, are the $x$-coordinates\nof the positions of the vertices, and similarly for $y$ and $z$.\n\n%------------------------------------------------------------------\n\n\\subsection{Derivatives}\n\\label{sec:derivatives}\n\nOne way to view the derivative of a function\n$\\f:{\\Re}^{n} \\mapsto \\Reals^{m}$,\nat a point $\\p$,\nis as the linear transformation $\\L:{\\Re}^{n} \\mapsto \\Reals^{m}$,\nthat best approximates the local 'slope' of $\\f$ at $\\p$.\nTo be a little more precise, we want\n\\begin{displaymath}\n\\lim_{ \\|{\\bf \\delta}  \\| \\mapsto 0}\n{ \\|{\\f(\\p + {\\bf \\delta}) - (\\f(\\p) + \\L({\\bf\\delta})) \\|}\n  \\over  \\|{\\bf \\delta}  \\|}\n = 0\n\\end{displaymath}\nFor a concise and correct discussion, see \\cite{spivak-1965}.\n\n\\begin{itemize}\n\n\\item $\\Da{\\f}$\n\nIn its most general form,\nI denote the derivative of $\\f$ by $\\Da{\\f}$.\nNote that this is\nlinear-transformation-valued function of the domain of $\\f$.\n\n\\item $\\Db{\\f}{\\p}$\n\nI denote the derivative of $\\f$ at $\\p$ by $\\Db{\\f}{\\p}$.\n$\\Db{\\f}{\\p}$ is a specific linear transformation from\nthe domain of $\\f$ to the codomain of $\\f$.\n\n\\item $\\Dc{\\f}{\\p}{\\q}$\n\nThe derivative is most often represented by the {\\it Jacobian},\nthe $m \\times n$ matrix of partial derivatives\nwith respect to some bases for $\\Reals^n$ and $\\Reals^m$.\nHowever, it's often easier to express the derivative clearly if we\nexplicitly include the argument of the linear transformation.\nIn this case, I write $\\Dc{\\f}{\\p}{\\q}$\nfor the derivative of $f$ at the point $\\p$\napplied to the vector $\\q$.\n\n\\item $\\Dd{\\p_i}{\\f}{(\\q_0,\\ldots,\\q_{n-1})}{\\r_i}$\n\nFor functions on direct sum spaces,\n$\\f(\\p_0,\\p_1,\\ldots,\\p_{n-1})$, $\\p_i \\in \\Reals^{n_i}$,\nit's often easier to consider the derivative\nwith respect to one argument at a time.\nI write $\\Dd{\\p_i}{\\f}{(\\q_0,\\ldots,\\q_{n-1})}{\\r_0,\\ldots,\\r_{n-1}}$\nfor the derivative of $\\f$ with respect to $\\p_i$,\nat the point $(\\q_0,\\ldots,\\q_{n-1}) \\in \\oplus_{i=0}^{n-1} \\Reals^{m_i}$,\napplied to the vector $\\r_i \\in \\Reals^{n_i}$.\nNote that, if you consider $\\f$ to be a function\nof direct sums of $\\Reals^1$, we have the usual\npartial derivatives.\n\n\\end{itemize}\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Gradients of real-valued functions}\n\\label{sec:gradients}\n\n\\begin{itemize}\n\n\\item $\\Ga{f}$\n\nIn minimizing real-valued functions, $f(\\p)$, $\\p \\in \\Reals^n$,\nwe frequently need\nthe {\\it gradient,} $\\Ga{f} \\in \\Reals^n$,\nthe vector pointing in the direction of most rapid increase of $f$,\nwhose magnitude is the rate of increase, or slope,\nof $f$ in that direction.\n\nThe gradient, $\\Ga{f}$,\nhas a close relationship to the derivative, $\\Da{f}$,\nand the two are often confused.\nRecall that the derivative is a linear transformation\nfrom the domain of $f$ to its codomain.\nIn the case of real-valued functions,\nthis means the derivative is a linear function on $\\Reals^n$,\nan element of the dual space of $\\Reals^n$, a 'row' vector.\nIt's easy to see that the gradient is simply the dual (the 'transpose')\nof the derivative, $\\Ga{f} = (\\Da{f})^{\\dagger}$\n(see \\cite[p. 96, ex. 4-18]{spivak-1965}).\n\nNotation for the various versions of the gradient\nfollows that for derivatives:\n\n\\item $\\Gb{f}{\\q}$\n\nThe gradient of $f$ at $\\q$.\n\n\\item $\\Gc{\\p_i}{f}{\\q}$\n\nThe gradient of $f$\nwith respect to $\\p_i$ at $\\q$.\n\n\\item $(\\Gb{f}{\\q}) \\bullet \\; \\r$\n\nThe analog to exressing the derivative as a linear transformation\nwith an explicit argument is to write expressions for\nthe inner product of the gradient and an arbitrary other vector $\\r$\n\n\\item $(\\Gc{\\p_i}{f}{\\q}) \\bullet \\;\\r_i$\n\nSee above.\n\n\\end{itemize}\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Chain rule}\n\\label{sec:chain}\n\nThe most general identity used in computing derivatives is the {\\it chain rule.}\nSuppose\n$\\f:\\Reals^{n_0} \\mapsto \\Reals^{n_1}$,\n$\\g:\\Reals^{n_1} \\mapsto \\Reals^{n_2}$,\nand\n$\\h = \\g \\circ \\f : \\Reals^{n_0} \\mapsto \\Reals^{n_2}.$\nThen\n\\begin{equation}\n\\label{eq:chain-rule}\n\\Db{\\h}{\\p} \\;\\; = \\;\\; \\Db{(\\g \\circ \\f)}{\\p}\n            \\;\\; = \\;\\; \\Db{\\g}{\\f(\\p)} \\; \\circ \\; \\Db{\\f} {\\p}.\n\\end{equation}\n\nSee \\cite[Theorem~2-2]{spivak-1965}, .\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of multilinear functions}\n\\label{sec:multilinear}\n\nA function $\\f(\\p_0,\\ldots,\\p_k):\\Reals^{n_0} \\oplus \\Reals^{n_k} \\mapsto \\Reals^m$\nis {\\it multilinear} if\n\\begin{equation}\n\\f(a_{00} \\p_{00} + a_{01} \\p_{01}, \\ldots, a_{k0} \\p_{k0} + a_{k1} \\p_{k1})\n\\; = \\; \\sum_{i_0,\\ldots,i_k = 0,1} \\;(a_{0i_0} \\cdots a_{ki_k}) \\f(\\p_{0i_0}, \\ldots, \\p_{ki_k}).\n\\end{equation}\n\nThe derivative of $\\f$\nat the point $(\\p_0,\\ldots,\\p_k)$, applied to the vector $(\\q_0,\\ldots,\\q_k)$ is\n\n\\begin{equation}\n\\Dc{\\f}{(\\p_0,\\ldots,\\p_k)}{\\q_0,\\ldots,\\q_k}\n\\; = \\; \\sum_{i=0,k} \\f(\\p_0,\\ldots,\\p_{i-1},\\q_i,\\p_{i+1},\\ldots,\\p_k).\n\\end{equation}\n\nSee \\cite[ex.~2-14]{spivak-1965}, .\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of bilinear functions}\n\\label{sec:bilinear}\n\nBilinear functions are a useful special case of multilinear functions.\n\nA function $\\f(\\p,\\q):\\Reals^{n_0} \\oplus \\Reals^{n_1} \\mapsto \\Reals^m$\nis {\\it bilinear} if\n\\begin{eqnarray}\n\\f(a_0 \\p_0 + a_1 \\p_1, b_0 \\q_0 + b_1 \\q_1) & = & a_0 b_0 f(\\p_0,\\q_0)  \\\\\n                                             & + & a_0 b_1 f(\\p_0,\\q_1) \\nonumber \\\\\n                                             & + & a_1 b_0 f(\\p_1,\\q_0) \\nonumber \\\\\n                                             & + & a_1 b_1 f(\\p_1,\\q_1).\\nonumber\n\\end{eqnarray}\n\nThe derivative of $\\f$\nat the point $(\\p_0,\\q_0)$, applied to the vector $(\\p,\\q)$ is\n\n\\begin{equation}\n\\Dc{\\f}{(\\p_0,\\q_0)}{\\p,\\q} = \\f(\\p_0,\\q) + \\f(\\p,\\q_0).\n\\end{equation}\n\nSee \\cite[ex.~2-12]{spivak-1965}.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of linear functions}\n\\label{sec:Derivatives-of-linear-functions}\n\nLinear functions are another useful special case of multilinear functions.\nA function $\\f(\\p):\\Reals^{n} \\mapsto \\Reals^m$\nis {\\it linear} if\n\\begin{equation}\n\\f(a_0 \\p_0 + a_1 \\p_1)\n =\na_0 \\f(\\p_0) + a_1 \\f(\\p_1)\n\\end{equation}\n\nThe derivative of $\\f$ is simply $\\f$ itself.\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of inner products}\n\\label{sec:inner}\n\nWe can view the inner product on $\\Reals^m$, $\\p \\bullet \\q$,\nas a bilinear function $d(\\p,\\q) : \\Reals^m \\oplus \\Reals^m \\mapsto \\Re$.\nThus\n\\begin{equation}\n\\Dc{d}{(\\p_0,\\q_0)}{\\p,\\q} = \\p_0 \\bullet \\q + \\p \\bullet \\q_0.\n\\end{equation}\n\nSuppose\n$\\f:\\Reals^{n} \\mapsto \\Reals^{m}$, and\n$\\g:\\Reals^{n} \\mapsto \\Reals^{m}$.\nThe derivative of $\\f \\bullet \\g$ is:\n\\begin{eqnarray}\n\\label{eq:dot_derivative}\n\\Dc{(\\f \\bullet \\g)}{\\p_0}{\\p}\n& =\n& \\Db{d}{(\\f(\\p_0),\\g(\\p_0))} \\;\\circ \\;(\\Dc{\\f}{\\p_0}{\\p}, \\Dc{\\g}{\\p_0}{\\p})\n\\\\\n& =\n& \\f(\\p_0) \\bullet \\Dc{\\g}{\\p_0}{\\p} \\; + \\; \\g(\\p_0) \\bullet \\Dc{\\f}{\\p_0}{\\p} \\nonumber\n\\end{eqnarray}\n\nSee \\cite[ex.~2-13]{spivak-1965}.\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of cross products}\n\\label{sec:cross}\n\nWe can view the 3-dimensional cross product\n$ \\times $\nas a bilinear function\n$\\c(\\p,\\q) = \\p \\times \\q : \\Reals^3 \\oplus \\Reals^3 \\mapsto \\Reals^3$.\nAs with the inner product,\nthe derivative is\n\\begin{equation}\n\\Dc{c}{(\\p_0,\\q_0)}{\\p,\\q} = \\p_0 \\times \\q + \\p \\times \\q_0.\n\\end{equation}\n\nSuppose\n$\\f:\\Reals^{n} \\mapsto \\Reals^3$, and\n$\\g:\\Reals^{n} \\mapsto \\Reals^3$.\nThe derivative of $\\f \\times \\g$ is:\n\\begin{eqnarray}\n\\Dc{(\\f \\times \\g)}{\\p_0}{\\p}\n& =\n& \\Db{\\c}{(\\f(\\p_0),\\g(\\p_0))} \\;\\circ \\;(\\Dc{\\f}{\\p_0}{\\p}, \\Dc{\\g}{\\p_0}{\\p})\n\\\\\n& =\n& \\f(\\p_0) \\;\\times \\;\\Dc{\\g}{\\p_0}{\\p} \\;+ \\;\\Dc{\\f}{\\p_0}{\\p} \\;\\times \\;\\g(\\p_0) \\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of scalar products}\n\\label{sec:scalar}\n\nSuppose\n$f:\\Reals^{n} \\mapsto \\Re$, and\n$\\g:\\Reals^{n} \\mapsto \\Reals^m$.\nIt follows from the chain rule that the derivative of $\\h = f\\g$ is:\n\\begin{eqnarray}\n\\label{eq:scalar_product_derivative}\n\\Db{(f\\g)}{\\p}\n& = & f(\\p) \\;\\Db{\\g}{\\p} \\;+ \\g(\\p) \\; \\Db{f}{\\p}  \\\\\n& = & f(\\p) \\;\\Db{\\g}{\\p} \\;+ \\g(\\p) \\otimes \\Gb{f}{\\p} \\; \\nonumber\n\\end{eqnarray}\n\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of euclidean norms}\n\\label{sec:norms}\n\nLet $l_2(\\p) = \\; \\| \\p  \\|: \\Reals^n \\mapsto \\Re$ \nbe the usual euclidean norm on $Re^n$.\nLet $l_2^2(\\p) = \\; \\| \\p  \\|^2 $\nbe its square\n($ \\| \\p  \\|^2  = \\sum_{i=0,n-1} \\p_i^2$),\nand $ \\| \\p  \\|^3$ the cube.\n\\begin{eqnarray}\n\\label{eq:l2-gradient}\n\\Gb{l_2}{\\p} & = & {{ \\p } \\over { \\| \\p  \\|}} \\\\\n\\Db{l_2}{\\p} & = &{{ \\p^\\dagger } \\over { \\| \\p  \\|}} \\nonumber \\\\\n\\Gb{l_2^2}{\\p} & = & 2\\p \\nonumber \\\\ \n\\Db{l_2^2}{\\p} & = & 2\\p^\\dagger \\nonumber \\\\\n\\Gb{l_2^3}{\\p} & = & 3 \\| \\p  \\| \\p \\nonumber \\\\\n\\Db{l_2^3}{\\p} & = & 3 \\| \\p  \\| \\p^\\dagger \\nonumber\n\\end{eqnarray}\n\nLet $\\f(\\p) : \\Reals^n \\mapsto \\Reals^m$.\nBy the chain rule:\n$\\Db{\\| \\f \\|^2}{\\p}  =  2 {\\f(\\p)}^{\\dagger} \\Db{\\f}{\\p} $.\n\n\\begin{equation}\n\\Gb{\\| \\f \\|^2}{\\p}  =  2 \\;\\Db{\\f}{\\p}^\\dagger \\;\\circ \\;\\f(\\p)\n\\end{equation}\n\n\\begin{eqnarray}\n\\label{eq:norm_derivative}\n\\Db{\\| \\f \\|}{\\p}\n& = &\n{{\\f(\\p)^\\dagger} \\over {\\| \\f(\\p) \\|}} \\Db{\\f}{\\p}  \\\\\n\\Gb{\\| \\f \\|}{\\p}\n& = &\n\\left(\\Db{\\f}{\\p}\\right)^\\dagger \\;\\circ \\;{{\\f(\\p)} \\over { \\| \\f(\\p)  \\|}}\n\\label{eq:norm_gradient}\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of normalized functions}\n\\label{sec:Derivatives-of-normalized-functions}\n\nLet $\\tilde{\\f}$ be the normalized version of $\\f$:\n\\begin{equation}\n\\tilde{\\f} \\;= \\;{{\\f} \\over {\\| \\f \\|}}\n\\end{equation}\n\nThen, from equations \\ref{eq:scalar_product_derivative}\nand \\ref{eq:norm_derivative}:\n\\begin{eqnarray}\n\\Dc{\\tilde{\\f}}{\\p}{\\q}\n& = &\n\\Dc{\\left({\\f \\over {\\| \\f \\|}}\\right)}{\\p}{\\q}\n\\\\\n& = &\n{\\Dc{\\f}{\\p}{\\q} \\over {\\| \\f(\\p) \\|}}\n\\; + \\;\n\\f(\\p) \\; \\Dc{\\left({1 \\over {\\| \\f \\|}}\\right)}{\\p}{\\q} \\nonumber \\\\\n& = &\n{\\Dc{\\f}{\\p}{\\q} \\over {\\| \\f(\\p) \\|}}\n\\; - \\;\n\\f(\\p) {{\\Dc{\\| \\f \\|}{\\p}{\\q}} \\over {\\|\\f(\\p)\\|^2}} \\nonumber \\\\\n& = &\n{\\Dc{\\f}{\\p}{\\q} \\over {\\| \\f(\\p) \\|}}\n\\; - \\;\n\\f(\\p) \\left( {{\\f(\\p)^\\dagger} \\over {\\| \\f(\\p) \\|^3}} \\;\\Dc{\\f}{\\p}{\\q} \\right) \\nonumber \\\\\n& = &\n{\\| \\f(\\p) \\|^2 \\Dc{\\f}{\\p}{\\q}\n\\; - \\;\n\\f(\\p)\\left( \\f(\\p) \\bullet \\Dc{\\f}{\\p}{\\q} \\right) }\n\\over {\\| \\f(\\p) \\|^3}  \\nonumber \\\\\n& = &\n{{\\| \\f(\\p) \\|^2 \\I_{\\Reals^3} \\;- \\;\\left( \\f(\\p) \\otimes \\f(\\p) \\right)  }\n\\over {\\| \\f(\\p) \\|^3} }\n\\;\\Dc{\\f}{\\p}{\\q} \\nonumber \\\\\n& = &\n{{\\I_{\\Reals^3} \\;- \\;\\left( \\tilde{\\f}(\\p) \\otimes \\tilde{\\f}(\\p) \\right)  }\n\\over {\\| \\f(\\p) \\|} }\n\\;\\Dc{\\f}{\\p}{\\q} \\nonumber\n\\end{eqnarray}\n\n$\\otimes$ is the elementary tensor product operation.\nIf you are stuck thinking in terms of row and column vectors,\n$\\p \\otimes \\q \\;= \\;\\p\\q^\\dagger$.\nMore generally, if $\\p \\in \\Reals^m$ and $\\q \\in \\Reals^n$,\nthen $\\p \\otimes \\q$ is the rank 1 linear transformation from $\\Reals^n \\mapsto \\Reals^m$:\n$\\left(\\p \\otimes \\q\\right) (\\r) \\;= \\;\\p \\left(\\q \\bullet \\r\\right)$.\n\nWe can write the derivative above without reference to the argument $\\q$:\n\\begin{eqnarray}\n\\label{eq:normalized_function_derivative}\n\\Db{\\tilde{\\f}}{\\p}\n& = &\n\\Db{\\left({\\f \\over {\\| \\f \\|}}\\right)}{\\p}  \\\\\n& = &\n{{\\I_{\\Reals^3} \\;- \\;\\left( \\tilde{\\f}(\\p) \\otimes \\tilde{\\f}(\\p) \\right) }\n\\over {\\| \\f(\\p) \\|} }\n\\;\\Db{\\f}{\\p} \\nonumber\n\\end{eqnarray}\n\nA common, trivial, normalized function is the normalized version of\na vector:\n\\begin{equation}\n\\tilde{\\p} \\;= \\;{{\\p} \\over {\\| \\p \\|}}\n\\end{equation}\n\nFrom equation \\ref{eq:normalized_function_derivative}\nit follows that:\n\\begin{eqnarray}\n\\label{eq:normalized_vector_derivative}\n\\Db{\\tilde{\\p}}{\\q}\n& = &\n\\Db{\\left({\\p \\over {\\| \\p \\|}}\\right)}{\\q}\n\\\\\n& = &\n{{\\I_{\\Reals^3} \\;- \\;\\left( \\tilde{\\q} \\otimes \\tilde{\\q} \\right) }\n\\over {\\| \\q \\|} }\n\\nonumber\n\\\\\n& = &\n{{\\| \\q \\|^2 \\I_{\\Reals^3} \\;- \\;\\left( \\q \\otimes \\q \\right) }\n\\over {\\| \\q \\|^3} }\n\\nonumber\n\\end{eqnarray}\n\n%------------------------------------------------------------------\n\n\\subsubsection{Derivatives of angles}\n\\label{sec:derivatives-of-angles}\n\nThe angle between 2 vectors $\\p_0, \\p_1 \\in \\Reals^m$, is the inverse cosine\nof their normalized inner product:\n\\begin{equation}\n\\theta(\\p_0,\\p_1)\n=\n\\cos^{-1}\n\\left(\n{ \\p_0 \\bullet \\p_1 } \\over {\\|\\p_0\\| \\|\\p_1\\|}\n\\right)\n\\end{equation}\nRecall that the derivative of the $\\cos^{-1}$ is:\n\\begin{equation}\n\\frac{d}{\\mathit dx} \\cos^{-1}(x) = { -1 \\over \\sqrt{1 - x^2} }\n\\end{equation}\nIt follows that:\n\\begin{eqnarray}\n\\label{eq:angle_gradient}\n\\Gc{\\p_0}{\\theta(\\p_0,\\p_1)}{\\q}\n& = &\n{{-1} \\over\n{ \\sqrt{1 - \\left( {\\q_0 \\bullet \\q_1} \\over {\\| \\q_0 \\| \\| \\q_1 \\|} \\right)^2 }}}\n\\Gc{\\p_0}{\\left( {\\q_0 \\bullet \\q_1} \\over {\\| \\q_0 \\| \\| \\q_1 \\|} \\right)} {\\q}\n\\\\\n& = &\n{\n{-\\|\\q_0\\|\\|\\q_1\\|}\n\\over\n{ \\sqrt{\\|\\q_0\\|^2\\|\\q_1\\|^2 - \\left( \\q_0 \\bullet \\q_1 \\right)^2 }}\n}\n\\left[\n{{\\q_1} \\over {\\|\\q_0\\|\\|\\q_1\\|}}\n+\n{{\\left( \\q_0 \\bullet \\q_1 \\right)} \\over {\\| \\q1 \\|}}\n\\Gc{\\p_0}{\\left( {1} \\over {\\| \\p_0 \\|} \\right)} {\\q}\n\\right]\n\\nonumber\n\\\\\n& = &\n{\n{-\\|\\q_0\\|\\|\\q_1\\|}\n\\over\n{ \\sqrt{\\|\\q_0\\|^2\\|\\q_1\\|^2 - \\left( \\q_0 \\bullet \\q_1 \\right)^2 }}\n}\n\\left[\n{{\\q_1} \\over {\\|\\q_0\\|\\|\\q_1\\|}}\n-\n{{\\left( \\q_0 \\bullet \\q_1 \\right) \\q0} \\over {\\| \\q1 \\| \\|\\q_0\\|^3}}\n\\right]\n\\nonumber\n\\\\\n& = &\n{\n{-1}\n\\over\n{ \\sqrt{\\|\\q_0\\|^2\\|\\q_1\\|^2 - \\left( \\q_0 \\bullet \\q_1 \\right)^2 }}\n}\n\\left[\n\\q_1\n-\n{{\\left( \\q_0 \\bullet \\q_1 \\right) \\q0} \\over {\\|\\q_0\\|^2}}\n\\right]\n\\nonumber\n\\\\\n& = &\n{\n{- \\q_1 \\perp \\q_0}\n\\over\n{ \\sqrt{\\|\\q_0\\|^2\\|\\q_1\\|^2 - \\left( \\q_0 \\bullet \\q_1 \\right)^2 }}\n}\n\\nonumber\n\\\\\n&  &\n\\nonumber\n\\\\\n\\Gc{\\p_1}{\\theta(\\p_0,\\p_1)}{\\q}\n& = &\n{\n{- \\q_0 \\perp \\q_1}\n\\over\n{ \\sqrt{\\|\\q_0\\|^2\\|\\q_1\\|^2 - \\left( \\q_0 \\bullet \\q_1 \\right)^2 }}\n}\n\\nonumber\n\\end{eqnarray}", "meta": {"hexsha": "86d79ecd0645cb65966e93a882b2e5df9b252934", "size": 18369, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/old/fotm/general.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/general.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/general.tex", "max_forks_repo_name": "palisades-lakes/les-elemens", "max_forks_repo_head_hexsha": "970bcbf5e31e40017b2333039e1505c7ea2f56dd", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 29.4847512039, "max_line_length": 99, "alphanum_fraction": 0.5578420164, "num_tokens": 7191, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9161096204605946, "lm_q2_score": 0.819893335913536, "lm_q1q2_score": 0.7511121727819202}}
{"text": "\n\\chapter[Eigenvalues]{Eigenvalues}\n\n\\section{Introduction}\n\nThe eigenvalues and eigenvectors of a matrix are of fundamental\nimportance in many matrix problems: for example, in matrix\ndescriptions of physical models they often represent fundamental\nphysical quantities, like the energy levels of an atom or the\nfrequency of vibrations of a string.  In numerical analysis problems,\nthe eigenvalues determine the convergence conditions of many\niterations schemes, like Jacobi and Gauss-Seidel.\n\nIt is, therefore, important to be able to compute quickly and\naccurately the eigenvalues and, eventually, the eigenvectors of a\nsquare matrix.  This is an apparently simple problem that could be\ntackled using standard nonlinear equations techniques.  In fact, the\neigenvalues $\\lambda$ of a $n \\times n$ square matrix $A$ are the $n$\nroots of the characteristic polynomial of $A$,\n%\n\\begin{equation*}\n \\text{det}(A - \\lambda \\text{Id}) = 0 .\n\\end{equation*}\n%\nWe could envisage using a root finding algorithm to detect all the\nroots of the polynomial and, hence, all the eigenvalues of the matrix\n$A$.  This is the procedure that is used in analytical calculations\nwhen finding the eigenvalues of small ($2 \\times 2$ or $3 \\times 3$)\nmatrices.  However, roots of high order polynomials may be very\nsensitive to the values of the coefficients: therefore, all the\nunavoidable numerical errors involved in the lengthy calculation of\nthe coefficients of the characteristic polynomial of $A$ may well be\namplified at the stage of computing the roots and produce estimates\nthat bear very little relation to the eigenvalues of $A$.\n\n\\begin{Example}\n  Polynomials may be badly conditioned, in the sense that a small\n  change in the values of just one coefficient changes considerably\n  the values of the roots.\n\\end{Example}\n\nConsider the polynomial\n%\n\\begin{align*}\n p(z) &= (z-1)\\,(z-2)\\,(z-3)\\,(z-4)\\,(z-5) \\\\\n      &= -120 + 274 z - 225 z^2 + 85 z^3 - 15 z^4 + z^5 .\n\\end{align*}\n%\nThe roots of this fifth order polynomial are quite obviously\n$\\{1,2,3,4,5\\}$.  The roots of\n%\n\\begin{equation*}\n  p(z) = -120 + 274 z - 225 z^2 + 85 z^3 - 15 z^4 + 1.01 z^5\n\\end{equation*}\n%\nare $\\{ 0.999, 2.067, 2.624, 4.580 \\pm 0.966 \\, i \\, \\}$ . \\hfill\n\\rule{3mm}{3mm}\n\n\\smallskip\n\nIt is therefore necessary to develop techniques to identify the\neigenvalues of a matrix $A$ that do not rely on finding the roots of\nthe characteristic polynomial.\n\nIf we are interested in just a few eigenvalues then we can use one of\nthe many variations of the \\textit{power method}.  Obtaining the full\nspectrum is a much harder problem; an efficient algorithm to do so,\nthe $QR$-algorithm, was developed by J.G.F. Francis in 1961.  We\ndescribe the power method first and give a relatively simple account\nof the $QR$-algorithm after.  The chapter is based in its entirety on\nthe book by Kincaid and Cheney (chapter 5).%~\\cite[Ch.~5]{kincaid96a}.\n\n\\section{The power method}\n\n\\subsection{The method}\n\nThe power method is an iterative procedure designed to compute the\ndominant eigenvalue of a matrix and its corresponding eigenvector.\nThe method is based on two assumptions:\n\n\\begin{enumerate}\n  %\n\\item There is a single eigenvalue of maximum modulus.\n  %\n\\item There is a linearly independent set of $n$ eigenvectors, where\n  $n$ is the size of the matrix.\n  %\n\\end{enumerate}\n\nAccording to the first assumption the eigenvalues of $A$ can be\nlabelled so that\n%\n\\begin{equation*}\n |\\lambda_1| > | \\lambda_2 | \\ge | \\lambda_3 | \\ge \\ldots |\\lambda_n|\n\\end{equation*}\n%\nAccording to the second assumption there is a basis of eigenvectors\n$\\{\\bu_1, \\bu_2, \\ldots, \\bu_n\\}$ in $\\bCn$ such that:\n%\n\\begin{equation*}\n A \\bu_j = \\lambda_j \\bu_j , \\qquad 1 \\le j \\le n .\n\\end{equation*}\n\nTo start the iteration we need to define an initial vector $\\bx^{(0)}$\nand we have to require that its component along the eigenvector\n$\\bu_1$ is not zero:\n%\n\\begin{equation*}\n \\bx^{(0)} = \\sum_{j=1}^n a_j \\bu_j , \\qquad a_1 \\neq 0 .\n\\end{equation*}\n%\nConsider now the vector\n%\n\\begin{equation*}\n \\bx^{(k)} = A \\bx^{(k-1)} = \\ldots = A^k \\bx^{(0)}.\n\\end{equation*}\n%\nIts decomposition on the basis of the eigenvectors is\n%\n\\begin{equation*}\n \\bx^{(k)} = \\sum_{j=1}^n \\lambda_j^k \\bu_j =\n             \\lambda_1^k \\left [ a_1 \\bu_1 +\n             \\left ( \\frac{\\lambda_2}{\\lambda_1} \\right )^k a_2 \\bu_2 +\n             \\left ( \\frac{\\lambda_3}{\\lambda_1} \\right )^k a_3 \\bu_3 +\n             \\ldots\n             \\left ( \\frac{\\lambda_n}{\\lambda_1} \\right )^k a_n \\bu_n\n              \\right ] .\n\\end{equation*}\n%\nWe note that all the terms $\\lambda_j/\\lambda_1$, $j=2,3,\\ldots,n$,\nhave modulus strictly smaller than one.  We can write this expression\nas\n%\n\\begin{equation}\n  \\bx^{(k)} = \\lambda_1^k ( a_1 \\bu_1 + \\boldsymbol{\\varepsilon}^{(k)} )\n  \\label{eq:Ev3}\n\\end{equation}\n%\nwhere\n%\n\\begin{equation}\n  \\boldsymbol{\\varepsilon}^{(k)} \\equiv  \\sum_{j=2}^n\n  \\left ( \\frac{\\lambda_j}{\\lambda_1} \\right )^k a_j \\bu_j\n  \\label{eq:Ev5}\n\\end{equation}\n%\nis such that\n%\n\\begin{equation}\n  \\| \\boldsymbol{\\varepsilon}^{(k)} \\| =\n  O \\left ( \\left | \\frac{\\lambda_j}{\\lambda_1} \\right |^k \\right )\n  \\implies\n  \\lim_{k \\to \\infty} \\| \\boldsymbol{\\varepsilon}^{(k)} \\| = 0.\n  \\label{eq:Ev2}\n\\end{equation}\n%\nAs we have assumed that $a_1 \\neq 0$ we can write\n%\n\\begin{equation}\n  \\bx^{(k)} = \\lambda_1^k a_1 \\bu_1 +\n  O \\left ( \\left | \\frac{\\lambda_2}{\\lambda_1} \\right |^k \\right ) .\n  \\label{eq:Ev6}\n\\end{equation}\n%\nThis expression is at the heart of the power method: at each iteration\nthe vector $\\bx^{(k)}$ aligns itself more and more along the\neigenvector $\\bu_1$ and is multiplied by a (complex) number that gets\ncloser and closer to the eigenvalue $\\lambda_1$.  In order to obtain a\nquantitative estimate of the eigenvalue we need to pass from vectors\nto numbers. As a simple example, we define the ratio\n%\n\\begin{equation*}\n r_k = \\frac{\\| \\bx^{(k+1)} \\|}{\\| \\bx^{(k)} \\|} = | \\lambda_1 |\n        \\frac{\\| a_1 \\bu_1 + \\boldsymbol{\\varepsilon}^{(k+1)} \\|}\n             {\\| a_1 \\bu_1 + \\boldsymbol{\\varepsilon}^{(k)} \\|} .\n\\end{equation*}\n%\nUsing equation~(\\ref{eq:Ev2}) we then have that\n%\n\\begin{equation*}\n \\lim_{k \\to \\infty} r_k = | \\lambda_1 | .\n\\end{equation*}\n\n\\noindent\nTherefore, a first approximate algorithm to implement the power method\nis as follows:\n\n\\begin{enumerate}\n  %\n\\item Chose an initial vector $\\bx^{(0)}$ such that its component\n  along $\\bu_1$ is not zero.\n  %\n\\item From the vector at iteration $k$, $\\bx^{(k)}$, compute the\n  vector at iteration $k+1$, $\\bx^{(k+1)} = A \\bx^{(k)}$.\n  %\n\\item Compute the ratio $r_k = \\| \\bx^{(k+1)}\\|/\\| \\bx^{(k)} \\|$.\n  %\n\\item If the ratio $r_k$ has converged to $| \\lambda_1|$ stop;\n  otherwise repeat from step 2.\n  %\n\\end{enumerate}\n\n\\noindent\n\\textbf{Remark 1} - In practice, it is impossible to know a priori\nthat the vector $\\bx_0$ satisfies the condition that its component\nalong $\\bu_1$ is not zero.  However, a random choice of vector will,\nwith great probability, satisfy it.  In general, however, this is a\nmoot point: numerical errors will always induce a non-zero coefficient\n$a_1$ that will be amplified at each iteration and the method will\nultimately converge to the dominant eigenvalue.\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark 2} - From equation~(\\ref{eq:Ev3}) we see that $\\|\n\\bx^{(k)} \\| \\simeq | \\lambda_1|^k$.  Therefore if $| \\lambda_1 | > 1$\nwe have that $\\| \\bx^{(k)} \\| \\to \\infty$ as $k \\to \\infty$.  This may\ninduce an overflow problem for sufficiently large $k$.  If, on the\nother hand, $| \\lambda_1 | < 1$, then $\\| \\bx^{(k)} \\| \\to 0$ as $k\n\\to \\infty$.  This may induce an underflow problem for sufficiently\nlarge $k$.  To avoid either pitfall it is convenient to normalise the\nvectors $\\bx^{(k)}$ at each iteration (or after a small number of\niterations).  A suitable algorithm is:\n\n\\begin{enumerate}\n  %\n\\item Chose an initial vector $\\bx^{(0)}$ such that its\n  component along $\\bu_1$ is not zero and $\\| \\bx^{(0)} \\| = 1$.\n  %\n\\item From the vector at iteration $k$, $\\bx^{(k)}$, compute the\n  vector at iteration $k+1$, $\\bx^{(k+1)} = A \\bx^{(k)}$.\n  %\n\\item Compute  $r_k = \\| \\bx^{(k+1)}\\|$ and assign $\\|\n  \\bx^{(k+1)}\\|/r_k \\to \\| \\bx^{(k+1)}\\|$.\n  %\n\\item If the ratio $r_k$ has converged to $|\\lambda_1|$ stop;\n  otherwise repeat from step 2.\n  %\n\\end{enumerate}\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark 3} - The method as described so far returns only the\nmodulus of the eigenvalue.  However, it is fairly simple to modify it\nso that it returns the eigenvalue itself.  We lose information on the\nphase of the eigenvalue when we compute the ratio $r_k$ using the norm\nof $\\| \\bx^{(k+1)}\\|$ and $\\| \\bx^{(k)}\\|$. We could use, instead, a\nlinear function $\\phi$ from $\\bC^n \\to \\bC$, that is, $\\phi(\\alpha \\bx\n+ \\beta \\by) = \\alpha \\phi(\\bx) + \\beta \\phi(\\by)$. (Note that\n$\\|\\bx\\|$ is not linear!)  A possible choice for $\\phi(\\bx)$ is, for\nexample, the sum of the components of $\\bx$.  We can define the ratio\n$r_k$ in terms of the functional $\\phi(\\bx)$ as\n%\n\\begin{equation}\n r_k = \\frac{\\phi( \\bx^{(k+1)} )}{\\phi(\\bx^{(k)})} = \\lambda_1\n        \\frac{a_1 \\phi(\\bu_1) + \\phi(\\boldsymbol{\\varepsilon}^{(k+1)})}\n             {a_1 \\phi(\\bu_1) + \\phi(\\boldsymbol{\\varepsilon}^{(k)})} .\n \\label{eq:Ev7}\n\\end{equation}\n%\nUsing equation~(\\ref{eq:Ev2}) and the fact that $\\lim_{\\| \\bx \\| \\to\n  0} \\phi(\\bx) = 0$ we then have that\n%\n\\begin{equation*}\n \\lim_{k \\to \\infty} r_k = \\lambda_k.\n\\end{equation*}\n%\nThe algorithm that implements this scheme is as follows:\n\n\\begin{enumerate}\n  %\n\\item Chose an initial vector $\\bx^{(0)}$ such that its\n  component along $\\bu_1$ is not zero.\n  %\n\\item At each iteration $k=0,1,2,\\ldots$ compute $d_k = \\|\n  \\bx^{(k)}\\|$ and assign $\\| \\bx^{(k)}\\|/d_k \\to \\| \\bx^{(k)}\\|$.\n  %\n\\item From the vector at iteration $k$, $\\bx^{(k)}$, compute the\n  vector at iteration $k+1$, $\\bx^{(k+1)} = A \\bx^{(k)}$.\n  %\n\\item Compute  $r_k = \\phi(\\bx^{(k+1)})/\\phi(\\bx^{(k)})$.\n  %\n\\item If the ratio $r_k$ has converged to $\\lambda_1$ stop;\n  otherwise repeat from step 2.\n  %\n\\end{enumerate}\n\n\\subsection{Rate of convergence}\n\nWe now show that the power method converges linearly.  We define $\\mu\n= {\\lambda_2}/{\\lambda_1}$.  This parameter controls the convergence\nrate of the method.  We apply Taylor's theorem to\nequation~(\\ref{eq:Ev7}) and use equation~(\\ref{eq:Ev2}) to obtain\n%\n\\begin{equation*}\n r_k = \\lambda_1\n        \\frac{a_1 \\phi(\\bu_1) + \\phi(\\boldsymbol{\\varepsilon}^{(k+1)})}\n             {a_1 \\phi(\\bu_1) + \\phi(\\boldsymbol{\\varepsilon}^{(k)})}\n     = \\lambda_1\n        \\left [ 1 - \\frac{\\phi (\\boldsymbol{\\varepsilon}^{(k)} )}{a_1 \\phi(\\bu_1)}\\right ] \\,\n        + O(\\mu^{k+1}) .\n\\end{equation*}\n%\nTherefore the relative error of the approximation, defined as\n%\n\\begin{equation}\n  \\epsilon^{(k)} \\equiv \\left |\n    \\frac{r_k - \\lambda_1}{\\lambda_1} \\right | ,\n  \\label{eq:Ev4}\n\\end{equation}\n%\nis given by\n%\n\\begin{equation}\n  \\epsilon^{(k)} =\n  \\left | \\frac{\\phi (\\boldsymbol{\\varepsilon}^{(k)} )}{a_1 \\phi(\\bu_1)} \\right|  + O(\\mu^{k+1}) =  c_k \\mu^k\n  \\label{eq:Ev9}\n\\end{equation}\n%\nwhere $\\{c_k\\}$ is a bounded sequence.  Note that this equation\nimplies that $\\epsilon^{(k)} \\propto \\mu \\epsilon^{(k+1)}$, i.e.\\ that\nthe rate of decrease of the error is linear.  In fact one can show\nthat\n%\n\\begin{equation*}\n  \\frac{r^{(k+1)} - \\lambda_1}{\\lambda_1} = (c + \\delta_k)\n  \\frac{r^{(k)} - \\lambda_1}{\\lambda_1}\n\\end{equation*}\n%\nwhere $|c| < 1$ and $\\lim_{k \\to \\infty} \\delta_k = 0$.\n\n\\smallskip\n\n\\smallskip\n\n\\noindent \\textbf{Remark 1} - The condition that there should be a\nsingle eigenvalue of maximum modulus should be qualified.  If the\neigenvalue is multiple then the power method will converge to it, but\nit will not be able to return the eigenvectors associated to the\n(multiple) eigenvalue; it will just return a random vector in the\neigenspace of the eigenvalue of maximum modulus.  If, on the other\nhand, the matrix has distinct eigenvalues all with the same maximum\nmodulus (a rather common situation in problems with symmetry), the\nmethod may fail to converge.\n\n\\smallskip\n\n\\noindent \\textbf{Remark 2} - The convergence can be improved using\nAitken's acceleration, a technique similar to Richardson's\nextrapolation  that uses the fact that the error decreases linearly to\nimprove the convergence.\n\n\\subsection{Variations on the power method}\n\n\\subsubsection{The inverse power method}\n\nWe can use a variation of the power method, called the \\textit{inverse\npower method}, to compute the smallest eigenvalue of a non singular\n(and well conditioned) matrix.  The algorithm is based on the result\nof linear algebra that if $\\lambda$ is an eigenvalue of a nonsingular\nmatrix $A$, then $\\lambda^{-1}$ is an eigenvalue of $A^{-1}$.\n\nWe assume as before that the eigenvectors of $A$ form a basis for\n$\\bC^n$, but we now require that the eigenvalue of smallest modulus is\nisolated, i.e.\\ that we can label the eigenvalues of $A$ so that\n%\n\\begin{equation*}\n  |\\lambda_1| \\ge |\\lambda_2| \\ge \\ldots \\ge |\\lambda_{n-1}| >\n  |\\lambda_n| > 0 .\n\\end{equation*}\n%\nTherefore the eigenvalues of $A^{-1}$ are ordered as\n%\n\\begin{equation*}\n  |\\lambda_n^{-1}| > |\\lambda_{n-1}^{-1}| \\ge \\ldots \\ge\n  |\\lambda_{1}^{-1}| > 0 .\n\\end{equation*}\n%\nWe are now in the position to compute $\\lambda_n^{-1}$ using the power\nmethod applied to $A^{-1}$.\n\n\\smallskip\n\n\\noindent\n\\textbf{Remark} - It is \\underline{not} a good idea to compute\n$A^{-1}$ first and then use $\\bx^{(k+1)} = A^{-1} \\bx^{(k)}$.   It is\nbetter to obtain $\\bx^{(k+1)}$ by solving the linear system\n%\n\\begin{equation*}\n  A \\bx^{(k+1)} = \\bx^{(k)}\n\\end{equation*}\n%\nusing an efficient (and accurate) linear solver.   The $LU$\ndecomposition is an excellent candidate for this problem.\n\n\\subsection{The shifted inverse power method}\n\nThe shifted inverse power method is used to compute the eigenvalue of\n$A$ closest to a given complex number $\\nu$.   Suppose that there is a\nreal number $\\epsilon$ such that there is only one eigenvalue of $A$,\n$\\lambda_j$, such that\n%\n\\begin{equation}\n  |\\lambda_j - \\nu| \\le \\epsilon \\quad \\text{and} \\quad\n  |\\lambda_i - \\nu| > \\epsilon \\; \\forall \\, i \\ne j.\n  \\label{eq:Ev10}\n\\end{equation}\n\nConsider now the ``shifted'' matrix $A - \\nu \\text{Id}$: its\neigenvalues are given by $\\lambda_i - \\nu$.  Equation~(\\ref{eq:Ev10})\nimplies that we can find $\\lambda_j - \\nu$ by applying the inverse\npower method to the matrix $A - \\nu \\text{Id}$.  This algorithm is\ncalled the shifted inverse power method.\n\n\\section{The \\texorpdfstring{$QR$}{QR}-algorithm}\n\n\\subsection{Introduction}\n\nThe methods to compute the full spectrum of a matrix are based on the\nidea that finding the eigenvalues is an easy problem for certain\nclasses of matrices, e.g.\\ diagonal and triangular matrices: their\neigenvalues are the elements along the diagonal.  The trick\nis to find operations that transform a matrix in an ``easy'' form\nwhile not altering the spectrum.    The first step in doing so is to\nidentify classes of matrices that have the same spectrum and classes\nof operations that do not alter the spectrum.\n\n\\begin{definition}\nTwo square matrices are similar if there exists a nonsingular matrix\n$P$ such that $B = P A P^{-1}$.   We say that $B$ is obtained from $A$\nusing a similarity transformation.   If $P$ is unitary, i.e.\\ $P =\nP^\\dagger$, the two matrices are unitary similar.\n\\end{definition}\n\n\\begin{theorem}\n  \\label{thr:1}\n  Similar matrices have the same eigenvalues.\n\\end{theorem}\n\\noindent\n\\textbf{Proof}\n\n\\begin{equation*}\n  A \\bx = \\lambda \\bx \\quad \\Leftrightarrow \\quad\n  (P A P^{-1}) (P \\bx) = P A \\bx = \\lambda (P \\bx).\n\\end{equation*}\nSo if $\\bx$ is an eigenvector of with eigenvalue $\\lambda$ then $A$ $P\n\\bx$ is an eigenvector of $P A P^{-1}$ with the same\neigenvalue. Moreover, $P$ provides a bijection between the\neigenvectors of $A$ and the eigenvectors of $P A P^{-1}$. \\hfill\n\\rule{3mm}{3mm}\n\n\\noindent\nIn other words, similar matrices have the same spectrum and similarity\ntransformations do not change the spectrum of a matrix.\n\n\\subsection{Schur's theorem}\n\nTheorem~\\ref{thr:1} suggests a strategy to find the eigenvalues of\nmatrix: find a similarity transformation $B = P A P^{-1}$ such that\n$B$ is triangular.  The following theorem states that this strategy is\nalways (theoretically) possible.\n\n\\begin{theorem}[Schur]\n  Every square matrix is unitary similar to a triangular matrix.\n\\end{theorem}\n\n\\noindent\nIn order to prove this theorem we need the following two lemmas. In\nthe remainder of this section, we always use the inner product\n$(\\bu,\\bv)=\\bu^\\dagger\\bv$ on $\\bC^n$ and the associated norm\n$\\|\\bu\\|=\\sqrt{\\bu^\\dagger\\bu}$.\n\n\\begin{lemma}\n  \\label{ax:1}\n  The matrix $\\Id - \\bu \\bu^{\\dagger}$ is unitary if and only if\n  $\\|\\bu\\| = \\sqrt{2}$ or $\\bu=0$.\n\\end{lemma}\n\\noindent\n\\textbf{Proof}\n\n\\begin{equation*}\n  (\\Id - \\bu \\bu^{\\dagger})(\\Id - \\bu \\bu^{\\dagger})^\\dagger\n  = (\\Id - \\bu \\bu^{\\dagger})^2 = \\Id - 2 \\bu \\bu^{\\dagger}\n  + \\bu \\bu^{\\dagger} \\bu \\bu^{\\dagger}\n  = \\Id +(\\bu^{\\dagger} \\bu - 2) \\bu \\bu^{\\dagger}\n\\end{equation*}\n\\null \\hfill \\rule{3mm}{3mm}\n\n\\begin{lemma}\n  \\label{ax:2}\n  Let $\\bx$ and $\\by$ be two vectors such that $\\|\\bx\\| = \\|\\by\\|$ and\n  $(\\bx,\\by)$ is real.  Then there exists an unitary matrix $U = \\Id -\n  \\bu \\bu^{\\dagger}$ such that $U \\bx = \\by$.  The vector $\\bu$ is\n  given by:\n  \\begin{equation*}\n    \\bu = \\sqrt{2} \\frac{\\bx - \\by}{\\|\\bx - \\by\\|} .\n  \\end{equation*}\n\\end{lemma}\n\\noindent\n\\textbf{Proof}\n\n\\begin{align*}\n  U \\bx &= \\left(\\Id - \\frac{2}{\\|\\bx - \\by\\|^2}(\\bx - \\by)(\\bx - \\by)^\\dagger\n  \\right) \\bx \\\\\n  &= \\bx - \\frac{2 (\\|\\bx\\|^2 - (\\by,\\bx))}{\n    \\|\\bx\\|^2 - (\\bx,\\by) - (\\by,\\bx) + \\|\\by\\|^2} (\\bx - \\by) = \\by\n\\end{align*}\n\\null \\hfill \\rule{3mm}{3mm}\n\n\\noindent\n\\textbf{Remark} - The matrix $U$ is called a \\textit{Householder\n  reflection} and its action can be interpreted geometrically as:\n``the vector $\\by$ can be obtained by reflecting the vector $\\bx$ with\nrespect to a plane orthogonal to the vector $\\bu$''.\n\n\\noindent\n\\textbf{Proof of Schur's theorem} - We prove this theorem for two\nreasons: firstly, the proof is an example of the techniques used to\ntransform a given matrix in an ``easy'' matrix.  Secondly, the proof\nclearly shows why this theorem is of little practical use.\n\nIn a nutshell the proof consists in constructing a succession of\nunitary transformations that change the given $n \\times n$ matrix $A$\nin upper triangular form, one row and column at a time.\n\nThe proof of the theorem is by induction on the size $n$ of the\nmatrix.  The theorem is clearly true for $n=1$.  We now suppose that\nit is true for all matrices of order $n-1$ and prove that it must also\nhold for any matrix $A$ of order $n$.  The idea of the proof is to use\nLemma~\\ref{ax:2} to find a unitary transformation $U$ that acts on the\nfirst column of $A$ and transforms it in a scalar multiple of the\nvector $\\be_1 = (1,0,0,\\ldots,0)$, i.e.\n%\n\\begin{equation}\n  U \\left ( \\begin{array}{c|ccc}\n      a_{1 1} & a_{1 2} & \\ldots & a_{1 n} \\\\ \\hline\n      a_{2 1} & a_{2 2} & \\ldots & a_{2 n} \\\\\n      \\vdots & & \\ddots & \\\\\n      a_{n 1} & a{_n 2} & \\ldots & a_{n n} \\\\\n    \\end{array} \\right ) U^{\\dagger} =\n  \\left ( \\begin{array}{c|ccc}\n      \\mu & & \\bw & \\\\ \\hline\n      0 & & & \\\\\n      \\vdots & & A_{n-1} & \\\\\n      0 & & & \\\\\n    \\end{array} \\right )\n  \\label{eq:Ev13}\n\\end{equation}\n%\nwhere $A_{n-1}$ is an $(n-1) \\times (n-1)$ matrix, $\\bw$ is a row\nvector of dimension $n-1$ and $\\mu$ is a number.  Unfortunately, in\norder to build the transformation matrix $U$ we need one eigenvalue\n$\\lambda$ of $A$ with the corresponding eigenvector $\\bv=(v_1, v_2,\n\\ldots, v_n)$, chosen such that $\\| \\bv \\|=1$.  Following\nLemma~\\ref{ax:2} we define the (complex) number\n%\n\\begin{equation*}\n  \\beta =\n  \\begin{cases}\n    \\dfrac{v_1}{|v_1|} & v_1 \\neq 0 \\\\*[4mm] 1 & v_1 = 0\n  \\end{cases}\n\\end{equation*}\n%\nand the vector\n%\n\\begin{equation*}\n  \\bu = \\frac{\\sqrt{2}}{\\|\\bv - \\beta \\be_1\\|} (\\bv - \\beta \\be_1) .\n\\end{equation*}\n%\nNote that $(\\bv, \\beta \\be_1) = v_1^{*} v_1/|v_1|=|v_1| \\in \\bR$ and\nthat $\\|\\bv\\| = \\|\\beta \\be_1\\| = 1$ so that both the hypotheses of\nLemma~\\ref{ax:2} are satisfied.  Therefore, the matrix\n%\n\\begin{equation}\n  U = \\text{Id} - \\bu \\bu^{\\dagger}\n  \\label{eq:Ev11}\n\\end{equation}\n%\nis unitary and such that\n%\n\\begin{equation}\n  U \\bv = \\beta \\be_1 \\implies U^{\\dagger} \\be_1 = \\frac{1}{\\beta} \\, \\bv .\n  \\label{eq:Ev12}\n\\end{equation}\n%\nThe matrix defined by this equation is the transformation required\nfor~(\\ref{eq:Ev13}) to be valid.  To verify that this is the case we\nnote that the product of any $n \\times n$ matrix with $\\be_1$ is its\nfirst column vector.  We therefore proceed to verify that the first\ncolumn vector of $U A U^{\\dagger}$ is a scalar multiple of $\\be_1$:\n%\n\\begin{equation*}\n  U A U^{\\dagger} \\, \\be_1 = U A \\, \\frac{1}{\\beta} \\bv =\n  \\frac{1}{\\beta} U \\lambda \\bv = \\frac{\\lambda}{\\beta} U \\bv =\n  \\lambda \\be_1 .\n\\end{equation*}\n%\nHence the application of $U$ defined in~(\\ref{eq:Ev11}) to $A$ reduces\nthis matrix to the form~(\\ref{eq:Ev13}) with $\\mu = \\lambda$.\n\nTo complete the proof we note that by the induction hypothesis there\nis a unitary matrix $Q_{n-1}$ such that $Q_{n-1} A_{n-1}\nQ^{\\dagger}_{n-1}$ is triangular.  Therefore, the unitary\ntransformation that reduces $A$ to triangular form is\n%\n\\begin{equation*}\n  V =\n  \\left ( \\begin{array}{c|ccc}\n      1 & & 0 \\ldots 0 & \\\\ \\hline\n      0 & & & \\\\\n      \\vdots & & Q_{n-1} & \\\\\n      0 & & & \\\\\n    \\end{array} \\right ) \\, U\n\\end{equation*}\n\\null \\hfill \\rule{3mm}{3mm}\n\n\\smallskip\n\n\\noindent\nAt each step of the proof we assume that the eigenvalues exist and use\nthem, but we do not address the question of how to compute them.  In\nother words, if we know the eigenvalues then we can apply the method\ndescribed in the proof to find the unitary transformation required to\nput $A$ in upper triangular form.  However, if we do not know them we\ncannot apply the procedure and we are no nearer to solving the\noriginal eigenvalue problem.\n\n\\noindent\n\\textbf{Remark} - One could think of using the power method to find\none eigenvalue of $A$ and thus build $U$ and $A_{n-1}$, and then apply\nthe same trick to $A_{n-1}$ and so on.  This method is called\n\\textit{deflation} and it works, but is rather sensitive to numerical\nerrors.\n\n\\begin{corollary}\n  Every Hermitian matrix is unitary similar to a diagonal matrix.\n\\end{corollary}\n\n\\noindent\n\\textbf{Proof} - If $A$ is Hermitian then $A = A^{\\dagger}$.  Let $U$\nbe the unitary matrix such that $U A U^{\\dagger}$ is upper triangular.\nThen $(U A U^{\\dagger})^{\\dagger}$ is lower triangular.  But\n%\n\\begin{equation*}\n  (U A U^{\\dagger})^{\\dagger} =\n  (U^{\\dagger})^{\\dagger} A^{\\dagger} U^{\\dagger} =\n  U A U^{\\dagger} .\n\\end{equation*}\n%\nThus, the matrix $U A U^{\\dagger}$ is both upper and lower triangular;\nhence, it must be a diagonal matrix.\n\n\\subsection{Householder's \\texorpdfstring{$QR$}{QR}-factorisation}\n\nIn order to introduce the $QR$-algorithm of Francis to find the\neigenvalues of a matrix, we must first take a detour and discuss\n\\textit{orthogonal factorisations} of a matrix.  An orthogonal\nfactorisation consists in writing a given matrix $A$ as the product of\nother matrices, some of which are orthogonal.  The most useful\northogonal factorisation if the $QR$-factorisation developed by Alston\nHouseholder: its objective is to factor an $m \\times n$ matrix $A$\ninto a product\n%\n\\begin{equation}\n  A = Q \\, R\n  \\label{eq:Ev15}\n\\end{equation}\n%\nwhere $Q$ is an $m \\times m$ unitary matrix and $R$ is an $m \\times n$\nupper triangular matrix.\n\nThe $QR$-factorisation is used not only to find the eigenvalues of a\nmatrix, but also to solve least-squares problems and ill-posed\nproblems.  The algorithm produces the factorisation\n%\n\\begin{equation}\n  Q^{\\dagger} A = R\n  \\label{eq:Ev16}\n\\end{equation}\n%\nwhere $Q^{\\dagger}$ is built step by step as the product of unitary\nmatrices that at step $k=0,1,\\ldots,m-1$ have the form\n%\n\\begin{equation}\n  U_k =\n  \\begin{pmatrix}\n    \\Id_{k-1} & 0 \\\\ 0 & \\Id_{m-k+1} - \\bu \\bu^{\\dagger}\n  \\end{pmatrix},\n  \\quad k = 1,2, \\ldots, n-1,\n  \\label{eq:Ev17}\n\\end{equation}\n%\nwith $\\Id_k$ the $k \\times k$ identity matrix and $\\bu \\in\n\\bC^{m-k+1}$.  These matrices are called \\textit{reflections} or\n\\textit{Householder transformations}: the aim of each of them is to\ntransform the matrix $A$ into a matrix that looks more and more like\n$R$, in a similar way that a triangular matrix is constructed in the\nproof of Schur's theorem.\n\nAt the first step we wish to determine a vector $\\bu \\in \\bC^m$ such\nthat $\\Id_m - \\bu^{\\dagger} \\bu$ is unitary and $(\\Id_m -\n\\bu^{\\dagger} \\bu) A$ has first column of the form suitable for an\nupper triangular matrix, i.e.\\ of the type $(\\beta, 0, \\ldots, 0)^T$.\nWe indicate with $\\ba_1$ the first column of $A$ and with $\\be_1$ the\nvector $(1,0,\\ldots,0)$.  Following Lemma~\\ref{ax:2} we define the\n(complex) number\n%\n\\begin{equation*}\n  \\beta =\n  \\begin{cases}\n    -\\dfrac{a_{11}}{|a_{11}|} \\|\\ba_1\\|_2 & a_{11} \\neq 0 \\\\*[4mm]\n    \\| \\ba_1 \\|_2 & a_{11} = 0\n  \\end{cases}\n\\end{equation*}\n%\nand the vector\n%\n\\begin{equation*}\n  \\bu = \\frac{\\sqrt{2}}{\\|\\ba_1 - \\beta \\be_1\\|} (\\ba_1 - \\beta \\be_1) .\n\\end{equation*}\n%\nBy Lemma~\\ref{ax:2} the matrix\n%\n\\begin{equation}\n  U_1 = \\text{Id} - \\bu \\bu^{\\dagger}\n  \\label{eq:Ev18}\n\\end{equation}\n%\nis unitary and such that\n%\n\\begin{equation}\n  U_1 \\ba_1 = \\beta \\be_1 .\n  \\label{eq:Ev19}\n\\end{equation}\n%\nUsing the unitary matrix $U$ defined in equation~(\\ref{eq:Ev18}) we\nhave that the matrix $U_0 A$ has form:\n%\n\\begin{equation*}\n  U_1 A =\n  \\left ( \\begin{array}{c|ccc}\n      \\beta & & \\bw_1 & \\\\ \\hline\n      0 & & & \\\\\n      \\vdots & & \\tilde{A_1} & \\\\\n      0 & & & \\\\\n    \\end{array} \\right )  \\equiv R_1\n\\end{equation*}\n%\nWe can now repeat the same procedure for the first column of the\nmatrix $A_1$ and build the unitary operator $U_k$ defined in\nequation~(\\ref{eq:Ev17}) with $k=2$ and so on.  At stage $k$ in the\nprocess, we shall have multiplied $A$ on the left by $k$ unitary\nmatrices and the result will be a matrix having its first $k$ columns\nof the correct form, i.e.\\ with $0$'s below the diagonal:\n%\n\\begin{equation*}\n  U_k \\, U_{k-1} \\, U_{k-2} \\, \\ldots \\, U_1 A =\n  \\left ( \\begin{array}{c|c} J & H \\\\ \\hline 0 & W \\end{array} \\right )\n\\end{equation*}\n%\nwhere $J$ is an upper triangular $k \\times k$ matrix, $0$ is an $(m-k)\n\\times k$ null matrix, $H$ is $k \\times (n-k)$ and $W$ is $(m-k)\n\\times (m-k)$.\n\nThe process terminates at $k=(n-1)$ when $R_{n-1}$ is in the correct\nform for equation~(\\ref{eq:Ev15}), i.e.\\ $R= R_{n-1}$.  Moreover,\n%\n\\begin{equation*}\n  Q^{\\dagger} = U_{n-1} \\ldots U_{1} \\implies\n  Q = U_1 \\ldots U_{n-1} .\n\\end{equation*}\n\n\\subsection{The \\texorpdfstring{$QR$}{QR}-Algorithm of Francis}\n\n\\subsubsection{The basic algorithm}\n\nThe $QR$-Algorithm of Francis is an iterative procedure that uses a\nvariant of the $QR$-factorisation to find the eigenvalues of a $n\n\\times n$ matrix $A$ by reducing to triangular form.\n\nWe can interpret the $QR$-algorithm as an extension of the power\nmethod - from Epperson (2002):%~\\cite{epperson02a}:\n\n\\begin{quote}\n  One of the primary drawbacks to the power methods is that they work\n  on a single vector at a time; if we want all the eigenpairs of a\n  matrix, then we spend a lot of computation time in deflation [...].\n  Why not do the power method on several vectors at once?  Let $Z_0$\n  be an initial guess matrix and do the computation\n  %\n  \\begin{equation*}\n    Y_{k+1} = A Z_k, \\qquad Z_{k+1} = Y_{k+1} D_{k+1}\n  \\end{equation*}\n  %\n  where $D_{k+1}$ is some properly chosen diagonal scaling matrix.\n  The problem is that this won't work; the repeated multiplications by\n  $A$ will simply cause all of the columns of $Y_{k+1}$ to line up on\n  the direction of the dominant eigenvalue and so we will converge to\n  $n$ copies of the dominant eigenpair - hardly an improvement on the\n  power method.\n\n  This algorithm does have something to recommend it, though.  If the\n  $Z_k$ matrices are all \\textit{orthogonal} matrices, then we get\n  something that might work, because the orthogonality of the columns\n  of $Z_k$ would prevent the columns of $Y_{k+1}$ from all lining up\n  in the same direction.\n\\end{quote}\n\nThe $QR$-algorithm implements this idea using the $QR$ factorisation.\nAdditional information on its relation to the power method and\ndeflation techniques can be found in Burden \\& Faires (2005,\n$8^{\\textrm{th}}$ ed.).\n\nThe $QR$-algorithm consists of the following steps:\n\n\\begin{enumerate}\n  %\n\\item Start the iteration - Iteration index $k=1$, working matrix $A_k\n  = A$.\n  %\n\\item Compute the $QR$ factorisation of $A_k = Q_k R_k$, where $Q_k$\n  is unitary and $R$ is upper triangular with non-negative diagonal.\n  %\n\\item Compute $A_{k+1} = R_k Q_k$.  Under appropriate hypotheses, the\n  matrix $A_{k+1}$ tends, as $k \\to \\infty$, to an upper triangular\n  matrix whose diagonal elements are the eigenvalues of $A$ .  The\n  procedure is repeated from step (2) until convergence has been\n  attained.\n\\end{enumerate}\n\n\\noindent\n\\textbf{Remark 1} - All the matrices $A_k$ are similar to $A$:\n%\n\\begin{equation*}\n  A_k = Q_k R_k = (Q_k R_k) \\, (Q_k Q_k^{\\dagger}) =\n  Q_k \\, ( R_k Q_k) \\, Q_k^{\\dagger} =\n  Q_k A_{k+1} Q_k^{\\dagger} .\n\\end{equation*}\n\n\\noindent\n\\textbf{Remark 2} - If the matrix $A$ is real, then all the matrices\n$A_k$ are real.  Therefore, if $A$ has non-real eigenvalues then at\nmost $A_k$ will converge to a ``triangular'' matrix with $2 \\times 2$\nminors on its diagonal.\n\n\\noindent\n\\textbf{Remark 3} - In order to reduce the burden of computation and\nincrease the speed of convergence the $QR$-algorithm is coupled with\nother techniques, namely the reduction to upper Hessenberg form and an\norigin shift (\\textit{Shifted $QR$-factorisation}).\n\n\\section*{Further reading}\n\nTopics covered here are also covered in\n\\begin{itemize}\n\\item Chapter 9 of Linz \\& Wang, \\textit{Exploring Numerical Methods}\n  (QA297 LIN),\n\\item Chapter 5 of S{\\\"u}li \\& Mayers, \\textit{An Introduction to\n    Numerical Analysis} (not in library),\n\\item Chapters 7 and 8 of the extremely detailed Golub \\& Van Loan,\n  \\textit{Matrix Computations} (QA263 GOL).\n\\end{itemize}\n", "meta": {"hexsha": "b222f0b9e059db0def11c1ba8307f3475324af82", "size": 30197, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Notes/tex/Eigenvalues.tex", "max_stars_repo_name": "josh-gree/NumericalMethods", "max_stars_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_stars_repo_licenses": ["CC-BY-3.0"], "max_stars_count": 76, "max_stars_repo_stars_event_min_datetime": "2015-02-12T19:51:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-26T15:34:11.000Z", "max_issues_repo_path": "Notes/tex/Eigenvalues.tex", "max_issues_repo_name": "josh-gree/NumericalMethods", "max_issues_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_issues_repo_licenses": ["CC-BY-3.0"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2017-05-24T19:49:52.000Z", "max_issues_repo_issues_event_max_datetime": "2018-01-23T21:40:42.000Z", "max_forks_repo_path": "Notes/tex/Eigenvalues.tex", "max_forks_repo_name": "josh-gree/NumericalMethods", "max_forks_repo_head_hexsha": "03cb91114b3f5eb1b56916920ad180d371fe5283", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 41, "max_forks_repo_forks_event_min_datetime": "2015-01-05T13:30:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-15T09:59:39.000Z", "avg_line_length": 34.9502314815, "max_line_length": 109, "alphanum_fraction": 0.676524158, "num_tokens": 10067, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.82893881677331, "lm_q2_score": 0.9059898273638386, "lm_q1q2_score": 0.7510101355036358}}
{"text": "\\section{Minors and cofactors}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Compute minors and cofactors of matrices.\n  \\item Use cofactor expansion to compute the determinant of an\n    $n\\times n$-matrix.\n  \\end{enumerate}\n\\end{outcome}\n\nDeterminants of larger matrices can be computed in terms of the\ndeterminants of smaller matrices. We begin with the following\ndefinition.\n\n\\begin{definition}{The $\\ijth$ minor of a matrix}{ijth-minor}\n  Let $A$ be an $n\\times n$-matrix. The $\\ijth$ \\textbf{minor}%\n  \\index{matrix!minor}%\n  \\index{determinant!minor of a matrix}%\n  \\index{minor} of $A$, denoted by $\\minor{A}{ij}$, is the\n  determinant of the $(n-1)\\times(n-1)$-matrix that is obtained by\n  deleting the $i\\th$ row and the $j\\th$ column of $A$.\n\\end{definition}\n\nHence, there is a minor associated with each entry of $A$. The\nfollowing example illustrates this definition.\n\n\\begin{example}{Finding minors of a matrix}{finding-minors}\n  Let\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 3 & 2 \\\\\n      3 & 2 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n  Find the minors $\\minor{A}{12}$ and $\\minor{A}{33}$.\n\\end{example}\n\n\\begin{solution}\n  First we will find $\\minor{A}{12}$. By definition, this is the\n  determinant of the $2\\times 2$-matrix that results when we delete\n  the first row and the second column of $A$. This minor is given by\n  \\begin{equation*}\n    \\minor{A}{12}\n    ~=~\n    \\begin{absmatrix}{ccc}\n      \\strikeh{3.2em}{1} & \\strikev{3.2em}{2} & 3 \\\\\n      4 & 3 & 2 \\\\\n      3 & 2 & 1 \\\\\n    \\end{absmatrix}\n    ~=~\n    \\begin{absmatrix}{rr}\n      4 & 2 \\\\\n      3 & 1\n    \\end{absmatrix}\n    ~=~ 4\\cdot 1 - 3\\cdot 2\n    ~=~ -2.\n  \\end{equation*}\n  Similarly, $\\minor{A}{33}$ is the determinant of the\n  $2\\times 2$-matrix that is obtained by deleting the third row and\n  the third column of $A$. This minor is therefore\n  \\begin{equation*}\n    \\minor{A}{33}\n    ~=~\n    \\begin{absmatrix}{ccc}\n      1 & 2 & \\strikev{3.2em}{3} \\\\\n      4 & 3 & 2 \\\\\n      \\strikeh{3.2em}{3} & 2 & 1 \\\\\n    \\end{absmatrix}\n    ~=~\n    \\begin{absmatrix}{rr}\n      1 & 2 \\\\\n      4 & 3\n    \\end{absmatrix}\n    ~=~ -5.\n  \\end{equation*}\n\\end{solution}\n\nWe now define the $\\ijth$ cofactor of a matrix $A$, which is either\nplus or minus the $\\ijth$ minor.\n\n\\begin{definition}{The $\\ijth$ cofactor of a matrix}{ijth-cofactor}\n  Suppose $A$ is an $n\\times n$-matrix. The $\\ijth$ \\textbf{cofactor}%\n  \\index{matrix!cofactor of}%\n  \\index{determinant!cofactor of a matrix}%\n  \\index{cofactor}, denoted by $\\cofactor{A}{ij}$, is\n  defined to be\n  \\begin{equation*}\n    \\cofactor{A}{ij} = (-1)^{i+j} \\minor{A}{ij}\n  \\end{equation*}\n\\end{definition}\n\nIn other words, the $\\ijth$ cofactor is equal to the corresponding\nminor if $i+j$ is even, and the negative of the minor if $i+j$ is\nodd. For remembering the signs, the following picture is sometimes\nhelpful:\n\\begin{equation*}\n  \\begin{mymatrix}{cccc}\n    + & - & + & - \\\\\n    - & + & - & + \\\\\n    + & - & + & - \\\\\n    - & + & - & + \\\\\n  \\end{mymatrix}.\n\\end{equation*}\n\n\\begin{example}{Finding cofactors of a matrix}{finding-cofactors}\n  Consider the matrix\n  \\begin{equation*}\n    A=\\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 3 & 2 \\\\\n      3 & 2 & 1\n    \\end{mymatrix}\n  \\end{equation*}\n  Find the cofactors $\\cofactor{A}{12}$ and $\\cofactor{A}{33}$.\n\\end{example}\n\n\\begin{solution}\n  We have already computed the corresponding minors in\n  Example~\\ref{exa:finding-minors}. For the cofactors, we have:\n  \\begin{eqnarray*}\n    \\cofactor{A}{12} &=& (-1)^{1+2}\\minor{A}{12} ~=~ -\\minor{A}{12} ~=~ -(-2) ~=~ 2, \\\\\n    \\cofactor{A}{33} &=& (-1)^{3+3}\\minor{A}{33} ~=~ +\\minor{A}{33} ~=~ +(-5) ~=~ -5.\n  \\end{eqnarray*}\n  Note that $1+2$ is odd, so $\\cofactor{A}{12}=-\\minor{A}{12}$. On the\n  other hand, $3+3$ is even, so $\\cofactor{A}{33}=\\minor{A}{33}$.\n\\end{solution}\n\nYou may wish to find the remaining cofactors of the above\nmatrix. Remember that there is a cofactor for every entry in the\nmatrix.\n\nWe have now established the tools we need to find the determinant of\nan $n\\times n$-matrix.\n\n\\begin{definition}{The determinant of an $n\\times n$-matrix}{n-by-n-determinant}\n  Let $A$ be an $n\\times n$-matrix. Then $\\det(A)$ is calculated by\n  picking a row (or column) and taking the product of each entry in\n  that row (column) with its cofactor and adding these products\n  together. This process is known as \\textbf{expanding along the\n    $i\\th$ row (or column)}%\n  \\index{determinant!expanding along row or column}.\n  \\bigskip\n\n  In formulas, the process of expanding along the $i\\th$ row is given\n  as follows:\n  \\begin{equation*}\n    \\det(A) =\n    a_{i1}\\cofactor{A}{i1} + a_{i2}\\cofactor{A}{i2} + \\ldots + a_{in}\\cofactor{A}{in}.\n  \\end{equation*}\n  Similarly, the process of expanding along the $j\\th$ column is:\n  \\begin{equation*}\n    \\det(A) =\n    a_{1j}\\cofactor{A}{1j} + a_{2j}\\cofactor{A}{2j} + \\ldots + a_{nj}\\cofactor{A}{nj}.\n  \\end{equation*}\n\n\\end{definition}\n\nWhen calculating the determinant, you can choose to expand any row or\nany column. Regardless of which row or column you expand, you will\nalways get the same number, which is the determinant of the matrix\n$A$.  This method of evaluating a determinant by expanding along a row\nor a column is also called \\textbf{cofactor expansion}%\n\\index{determinant!cofactor expansion}%\n\\index{cofactor expansion} or \\textbf{Laplace expansion}%\n\\index{determinant!Laplace expansion}%\n\\index{Laplace expansion}.\n\n\\begin{example}{Finding a determinant by cofactor expansion}{determinant-three-by-three}\n  Find $\\det(A)$ using the method of cofactor expansion, where\n  \\begin{equation*}\n    A = \\begin{mymatrix}{rrr}\n      1 & 2 & 3 \\\\\n      4 & 3 & 2 \\\\\n      3 & 2 & 1\n    \\end{mymatrix}.\n  \\end{equation*}\n\\end{example}\n\n\\begin{solution}\n  First, we will calculate $\\det(A)$ by expanding along the first\n  column.  Using Definition~\\ref{def:n-by-n-determinant}, the\n  determinant is\n  \\begin{eqnarray*}\n    \\det(A)\n    &=& a_{11}\\cofactor{A}{11} + a_{21}\\cofactor{A}{21} + a_{31}\\cofactor{A}{31} \\\\\n    &=& a_{11}\\minor{A}{11} - a_{21}\\minor{A}{21} + a_{31}\\minor{A}{31} \\\\\\\\[-2ex]\n    &=&\n        1 \\begin{absmatrix}{rr}\n          3 & 2 \\\\\n          2 & 1 \\\\\n        \\end{absmatrix}\n        - 4 \\begin{absmatrix}{rr}\n          2 & 3 \\\\\n          2 & 1 \\\\\n        \\end{absmatrix}\n        + 3 \\begin{absmatrix}{rr}\n          2 & 3 \\\\\n          3 & 2\n        \\end{absmatrix} \\\\\\\\[-1ex]\n    &=& 1 (-1) - 4 (-4) + 3 (-5) \\\\\n    &=& 0.\n  \\end{eqnarray*}\n  As mentioned in Definition~\\ref{def:n-by-n-determinant}, we\n  can choose to expand along any row or column. Let's try now by\n  expanding along the second row. The calculation is as follows.\n  \\begin{equation*}\n    \\det(A)\n    ~=~ -4 \\begin{absmatrix}{rr}\n      2 & 3 \\\\\n      2 & 1\n    \\end{absmatrix}\n    + 3 \\begin{absmatrix}{rr}\n      1 & 3 \\\\\n      3 & 1\n    \\end{absmatrix}\n    - 2 \\begin{absmatrix}{rr}\n      1 & 2 \\\\\n      3 & 2\n    \\end{absmatrix}\n    ~=~ -4(-4) + 3(-8) - 2(-4)\n    ~=~ 0.\n  \\end{equation*}\n  You can see that for both methods, we obtained $\\det(A) = 0$.\n\\end{solution}\n\nYou should try to compute the above determinant by expanding along\nother rows and columns. This is a good way to check your work, because\nyou should come up with the same number each time!\n\n\\begin{theorem}{The determinant is well-defined}{well-defined-determinant}\n  Expanding an $n\\times n$-matrix along any row or column always gives\n  the same answer, which is the determinant.\n\\end{theorem}\n\n\\begin{example}{Determinant of a four by four matrix}{four-by-four-determinant}\n  Calculate\n  $\\begin{absmatrix}{rrrr}\n    1 & 2 & 3 & 0 \\\\\n    2 & 4 & 2 & 3 \\\\\n    0 & 3 & 0 & 5 \\\\\n    3 & 0 & 3 & 2\n  \\end{absmatrix}$.\n\\end{example}\n\n\\begin{solution}\n  Using the cofactor method, we can expand this determinant along any\n  row or column. But notice that the third row contains two zeros.\n  This makes the cofactor expansion particularly convenient. So let us\n  expand along the third row. We have:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      1 & 2 & 3 & 0 \\\\\n      2 & 4 & 2 & 3 \\\\\n      0 & 3 & 0 & 5 \\\\\n      3 & 0 & 3 & 2\n    \\end{absmatrix}\n    =\n    0 \\begin{absmatrix}{rrr}\n      2 & 3 & 0 \\\\\n      4 & 2 & 3 \\\\\n      0 & 3 & 2\n    \\end{absmatrix}\n    -3 \\begin{absmatrix}{rrr}\n      1 & 3 & 0 \\\\\n      2 & 2 & 3 \\\\\n      3 & 3 & 2\n    \\end{absmatrix}\n    +0 \\begin{absmatrix}{rrr}\n      1 & 2 & 0 \\\\\n      2 & 4 & 3 \\\\\n      3 & 0 & 2\n    \\end{absmatrix}\n    -5 \\begin{absmatrix}{rrr}\n      1 & 2 & 3 \\\\\n      2 & 4 & 2 \\\\\n      3 & 0 & 3\n    \\end{absmatrix}.\n  \\end{equation*}\n  Note that we only need to compute two of the $3\\times 3$\n  determinants, since the remaining two are multiplied by $0$. We can\n  compute each $3\\times 3$ determinant using the method of\n  Definition~\\ref{def:3-by-3-determinant}. We find:\n  \\begin{equation*}\n    \\begin{absmatrix}{rrrr}\n      1 & 2 & 3 & 0 \\\\\n      2 & 4 & 2 & 3 \\\\\n      0 & 3 & 0 & 5 \\\\\n      3 & 0 & 3 & 2\n    \\end{absmatrix}\n    =\n    -3 \\begin{absmatrix}{rrr}\n      1 & 3 & 0 \\\\\n      2 & 2 & 3 \\\\\n      3 & 3 & 2\n    \\end{absmatrix}\n    -5 \\begin{absmatrix}{rrr}\n      1 & 2 & 3 \\\\\n      2 & 4 & 2 \\\\\n      3 & 0 & 3\n    \\end{absmatrix}\n    = -3 \\cdot 10 - 5\\cdot (-24)\n    = 90.\n  \\end{equation*}\n\\end{solution}\n\nWe remark that the cofactor expansion is mainly useful for calculating\ndeterminants of small matrices, or matrices containing many\nzeros. Indeed, imagine calculating the determinant of a\n$10\\times 10$-matrix by the cofactor method. This requires calculating\nthe determinants of ten $9\\times 9$-matrices, each of which requires\ncalculating the determinants of nine $8\\times 8$-matrices, each of\nwhich requires calculating the determinants of eight\n$7\\times 7$-matrices, and so on. Calculating the determinant of a\n$10\\times 10$-matrix by the cofactor method would therefore require\n$10\\cdot 9\\cdot 8\\cdot \\ldots \\cdot 2\\cdot 1 = 3628800$ steps!\n\nIn the next few sections, we will explore some important properties\nand characteristics of the determinant, including a much more\nefficient method of calculating determinants of large matrices.\n", "meta": {"hexsha": "db33ab1a562eefdbd236530cd50ccf27b7cfd9e7", "size": 10113, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "baseText/content/Determinants-MinorsCofactors.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-MinorsCofactors.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-MinorsCofactors.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.5046728972, "max_line_length": 88, "alphanum_fraction": 0.6213784238, "num_tokens": 3516, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8479677545357568, "lm_q2_score": 0.8856314692902446, "lm_q1q2_score": 0.7509869283602517}}
{"text": "\\chapter{Arithmetic}\n\\textbf{Definition:} Arithmetic (from the Greek arithmos, \"number\") is a branch of mathematics that consists of the study of numbers, especially the properties of the traditional operations on them.\n\n\\section{Numbers}\n\n$\\mathbb{N} = \\{0,1,2,3,...\\} $ = natural numbers \\\\\n$\\mathbb{N^+} = \\mathbb{N}\\setminus\\{0\\}$ \\\\\n$\\mathbb{Z} = \\{...,-3,-2,-1,0,1,2,3,...\\} $ = integers \\\\\n$\\mathbb{Q}$ = rational numbers \\\\\n$\\mathbb{R}$ = real numbers \\\\\n$\\mathbb{C}$ = complex numbers\n\n\\section{Absolute Value}\n\nAbsolute value function: $ \\left|x\\right| = max\\{x,-x\\} = \\sqrt{x^2} = \\begin{cases}\nx & \\text{if } x\\geq0\\\\\n-x & \\text{if } x<0\n\\end{cases} $\n\n\\section{Factorial}\n\nFactorial: $ n! = \\prod_{k=1}^{n}k  = \\begin{cases}\n0! &= 1\\\\\nn! &= n(n-1)! \\ \\ \\forall n\\ge1\n\\end{cases} $\n\n\\section{Exponential}\nExponentiation is a mathematical operation, written as $b^n$, involving two numbers, the base b and the exponent n. When $n>0$ exponentiation corresponds to: $$b^n=\\underbrace{b \\times ... \\times b}_\\text{n times}$$\n\nProperties:\n\\[\na^0=1 \\ \\ , \\ \\ a^{x+y}=a^xa^y \\ \\ , \\ \\ a^{x-y}=\\frac{a^x}{a^y} \\ \\ , \\ \\ (a^x)^y=a^{xy} \\ \\ , \\ \\ (ab)^n = a^nb^n \\ \\ , \\ \\ a^{\\frac{x}{y}}=\\sqrt[y]{a^x}\n\\]\n\n\\section{Logarithm}\n{\\bf Definition}: $a^x=y\\Leftrightarrow\\log_a(y)=x $. For logarithms with\nbase $e$ one writes $\\ln(x)$.\n\n{\\bf Rules}:\n\n\\begin{tabular}{ l l }\n$ \\displaystyle \\log_a(1)=0 $ &\n$ \\displaystyle a^{log_a(y)}=y $ \\\\\n$ \\displaystyle \\log_a(a^x)=x $ &\n$ \\displaystyle \\log_a(x^y)=y\\log_a(x) \\ \\forall x>0 \\ \\forall y \\in \\mathbb{R} $ \\\\\n$ \\displaystyle \\log_a(x)=\\frac{1}{\\log_x(a)} $ &\n$ \\displaystyle \\log_a\\left(1/x\\right)=-\\log_a(x) $ \\\\\n$ \\displaystyle \\log_a(xy) = \\log_a(x)+\\log_a(y) \\  \\forall x,y>0 $ &\n$ \\displaystyle \\log_a(x/y) = \\log_a(x)-\\log_a(y) \\ \\forall x,y>0 $\n\\end{tabular}\n\n\n\\section{Hyperbolic functions}\nThe hyperbolic functions are defined by:\n\\[\n\\sinh(x)=\\frac{{\\rm e}^x-{\\rm e}^{-x}}{2}~~~,~~~\\cosh(x)=\\frac{{\\rm e}^x+{\\rm e}^{-x}}{2}~~~,~~~\\tanh(x)=\\frac{\\sinh(x)}{\\cosh(x)}\n\\]\nFrom this follows that $\\cosh^2(x)-\\sinh^2(x)=1$. Further holds:\n\\[\n{\\rm arsinh}(x)=\\ln|x+\\sqrt{x^2+1}|~~~,~~~{\\rm arcosh}(x)={\\rm arsinh}(\\sqrt{x^2-1})\n\\]\n\n", "meta": {"hexsha": "96d5f2c4b1fef56d7e31b8273df6bf8924dbe418", "size": 2183, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Mathematics_Formulary/sections/arithmetic.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/arithmetic.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/arithmetic.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": 34.6507936508, "max_line_length": 215, "alphanum_fraction": 0.5945945946, "num_tokens": 866, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9407897542390751, "lm_q2_score": 0.7981867753392728, "lm_q1q2_score": 0.7509259402083144}}
{"text": "\\section{Resource-Constrained Project Scheduling Problem (RCPSP)}\n\\label{sec:RCPSP}\n\nIn this section, we consider the resource-constrained project scheduling problem (RCPSP).\nIn RCPSP, the activities of a project have to be scheduled such that the makespan of the\nproject is minimized. Thereby, technological precedence constraints have to be observed\nas well as limited capacities of the renewable resources that are required to accomplish\nthe activities. The RCPSP for the scheduling of maintenance and surveillance activities\nof nuclear power plant can be summarized as follows:\n\nWe consider a project that consists of a set of $J$ jobs (or tasks). Due to technological\nrequirements, precedence relations among some of the jobs enforce that job $j=2,3,\\cdots,J$\nmay not be started before all its predecessors, denoted by $P_j$, are finished. Here,\n$j=1$ indexes an artificial job with zero duration, which precedes all jobs that can\nstart at time zero, and  $j=J$ indexes an artificial final job, again with zero duration,\nwhich represents the end of the project. Executing job $j$ takes $d_j$ time periods and\nis supported by a set, $R$, of renewable resources. Consider a horizon with an upper\nbound, $T$, on the project's makespan, i.e., the time at which the final job\nis completed. We assume $K_{r}^{p}$ units of renewable resource $r\\in R$, are available\nin time period $t=1,2,\\cdots,T$. Job $j$ requires $k_{jr}^{p}$  units of the renewable\nresource, $r\\in R$, for each period of the job’s duration, i.e., for time periods\nwhen the job is in process.\n\nThe objective is to find a schedule which minimizes the project’s makespan while\nrespecting the constraints imposed by the precedence relations and the limited\nresource availability.\n\n\\[\n\\begin{array}{ll}\n%%%%%%%%%%%%%% INDICES AND Parameters %%%%%%%%%%%%%%%%\n\\multicolumn{2}{l}{\\mbox{\\em Indexes and parameters:} } \\\\\nt = 1, 2, \\cdots, T & \\mbox{time periods, where $T$ is an upper bound on the projects's makespan} \\\\\nj = 1, 2, \\cdots, J & \\mbox{jobs, with $j=1$ and $j=J$ denoting artificial jobs} \\\\\nr\\in R & \\mbox{set of renewable resources} \\\\\nd_j & \\mbox{duration of job $j$} \\\\\nK_{r}^{p} & \\mbox{number of units of renewable resource $r$ available in period $t$} \\\\\nk_{jr}^{p} & \\mbox{number of units of renewable resource $r$ consumed by job $j$ while in process} \\\\\nP_j & \\mbox{set of immediate predecessors of job j} \\\\\n\\\\\n%%%%%%%%%%%%%% Decision Variables %%%%%%%%%%%%%%%%\n\\multicolumn{2}{l}{\\mbox{\\em Decision variables:}} \\\\\nx_{jt} & \\mbox{1 if job $j$ completes in period $t$; 0 otherwise} \\hspace*{4.0in}\\\\\n\\end{array}\n\\]\n\n\\vst \\noi {\\em Formulation:}\n\\begin{subequations}\\label{rcpsp_eq}\n\\begin{eqnarray}\n&\\dst \\min &  \\dst \\sum_{t=1}^{T} (t-1) x_{Jt}  \\\\\n& s. t.  & \\sum_{t=1}^{T} x_{jt} = 1,   j=1, \\cdots, J \\\\\n& & \\sum_{t' \\le t} x_{jt'} \\le \\sum_{t' \\le t - d_j} x_{it'}, j = 2, \\cdots, J; t = 1, \\cdots, T; i\\in P_j \\\\\n& & \\sum_{j=1}^{J} \\sum_{t'=t}^{t+d_j-1} k_{jr}^{p} x_{jt'} \\le K_{r}^{p}, r \\in R; t=1, \\cdots, T \\\\\n& & x_{jt} \\in \\{0,1\\}, j=1, \\cdots, J, t = 1, \\cdots, T\n\\end{eqnarray}\n\\end{subequations}\n\nThe RCPSP model must consists the following modeling components: \\xmlNode{Sets},\n\\xmlNode{Parameters}, and \\xmlNode{Settings}. Each of these components is illustrated\nin the following sections.\n\n\\subsection{Sets}\n\\label{subsec:rcpsp_sets}\n\nThis subsection contains information regarding the XML nodes used to define the\n\\xmlNode{Sets} of the RCPSP model being performed through LOGOS.\n\\xmlNode{Sets} specifies a collection of data, possibly including\nnumeric data (e.g. real or integer values) as well as symbolic data (e.g. strings)\ntypically used to specify the valid indices for indexed components.\n\\nb Numeric data provided in \\xmlNode{Sets} would be treated as strings.\n\\xmlNode{Sets} accepts the following additional sub-nodes:\n\\begin{itemize}\n  \\item \\xmlNode{tasks}, \\xmlDesc{comma/space-separated string, required}, specifies\n  the valid indices for tasks.\n  \\item \\xmlNode{resources}, \\xmlDesc{comma/space-separated string, required},\n  specifies the indices for renewable resources.\n  \\item \\xmlNode{predecessors}, \\xmlDesc{comma/space-separated string, required},\n  specifies the indices for preceding tasks.\n  \\item \\xmlNode{successors}, \\xmlDesc{comma/space-separated string, required},\n  specifies indices for successors.\n  This sub-node accepts the following attribute:\n  \\begin{itemize}\n    \\item \\xmlAttr{index}, \\xmlDesc{string, required}, specifies the index dependence.\n    Valid index is \\xmlString{predecessors}.\n  \\end{itemize}\n\\end{itemize}\n\nExample XML:\n\\begin{lstlisting}[style=XML]\n<Sets>\n  <tasks>\n    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12\n  </tasks>\n\n  <resources>\n    r1 r2 r3 r4\n  </resources>\n\n  <predecessors>\n    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\n  </predecessors>\n\n  <successors index='predecessors'>\n    s1 s2 s3 s4;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1;\n    s1\n  </successors>\n</Sets>\n\\end{lstlisting}\n\n\n\\subsection{Parameters}\n\\label{subsec:rcpsp_params}\n\nThis subsection contains information regarding the XML nodes used to define the\n\\xmlNode{Parameters} of the RCPSP optimization model being performed through LOGOS:\n\\begin{itemize}\n  \\item \\xmlNode{available\\_resources}, \\xmlDesc{comma/space-separated string, required},\n  specifies the available renewable resources. This node accepts the\n  following attribute:\n  \\begin{itemize}\n    \\item \\xmlAttr{index}, \\xmlDesc{string, required},\n    specifies the indices of this parameter; keywords should be predefined in \\xmlNode{Sets}.\n    Valid keywords are \\xmlString{resources}.\n  \\end{itemize}\n  \\item \\xmlNode{task\\_resource\\_consumption}, \\xmlDesc{comma/space-separated string, required},\n  specifies the resource consumption for each task. This node accepts the\n  following attribute:\n  \\begin{itemize}\n    \\item \\xmlAttr{index}, \\xmlDesc{comma-separated string, required},\n    specifies the indices of this parameter; keywords should be predefined in \\xmlNode{Sets}.\n    Valid keywords are \\xmlString{tasks, resources}.\n  \\end{itemize}\n  \\item \\xmlNode{task\\_duration}, \\xmlDesc{comma/space-separated string, required},\n  specifies the duration for each task.\n  This node accepts the following attribute:\n  \\begin{itemize}\n    \\item \\xmlAttr{index}, \\xmlDesc{string, required},\n    specifies the indices of this parameter; keywords should be predefined in \\xmlNode{Sets}.\n    Valid keywords are \\xmlString{tasks}.\n  \\end{itemize}\n  \\item \\xmlNode{task\\_successors}, \\xmlDesc{comma/space-separated string, required},\n  specifies the successors for each predecessor.\n  This node accepts the following attribute:\n  \\begin{itemize}\n    \\item \\xmlAttr{index}, \\xmlDesc{string, required},\n    specifies the indices of this parameter; keywords should be predefined in \\xmlNode{Sets}.\n    Valid keywords are \\xmlString{successors}.\n    \\item \\xmlAttr{type}, \\xmlDesc{string, optional},\n    specifies the text type of the provided node, i.e., integer, float or string.\n    Valid keywords are \\xmlString{int}, \\xmlString{float}, or \\xmlString{str}.\n    \\default{float}\n  \\end{itemize}\n\\end{itemize}\n\nExample XML:\n\\begin{lstlisting}[style=XML]\n<Parameters>\n  <available_resources index='resources'>\n    13 13 13 12\n  </available_resources>\n  <task_resource_consumption index='tasks, resources'>\n    0\t0\t0\t0\n    10\t0\t0\t0\n    0\t7\t0\t0\n    0\t9\t0\t0\n    0\t4\t0\t0\n    0\t0\t0\t6\n    10\t0\t0\t0\n    0\t0\t6\t0\n    0\t0\t0\t8\n    0\t6\t0\t0\n    0\t0\t0\t5\n    0\t0\t0\t0\n  </task_resource_consumption>\n\n  <task_duration index=\"tasks\">\n    0\n    8\n    1\n    10\n    6\n    5\n    8\n    9\n    1\n    9\n    8\n    0\n  </task_duration>\n\n  <task_successors index='successors' type='str'>\n    2 3 4 9\n    5\n    7\n    8\n    6\n    10\n    11\n    10\n    12\n    9\n    12\n  </task_successors>\n</Parameters>\n\\end{lstlisting}\n\n\\subsection{Settings}\n\\label{subsec:rcpsp_settings}\n\nThis subsection contains information regarding the XML nodes used to define the\n\\xmlNode{Settings} of the RCPSP optimization model being performed through LOGOS:\n\\begin{itemize}\n  \\item \\xmlNode{problem\\_type}, \\xmlDesc{string, required parameter}, specifies the type of\n  optimization problem. Currently available type only include \\xmlString{rcpsp}.\n  \\item \\xmlNode{solver}, \\xmlDesc{string, optional parameter}, represents available solvers including\n  \\xmlNode{cbc} from \\url{https://github.com/coin-or/Cbc.git} and \\xmlNode{glpk} from\n  \\url{https://www.gnu.org/software/glpk/}.\n  \\item \\xmlNode{sense}, \\xmlDesc{string, optional parameter}, specifies \\xmlString{minimize}\n  or \\xmlString{maximize} for minimization or maximization, respectively.\n  \\default{minimize}\n  \\item \\xmlNode{makespan\\_upperbound}, \\xmlDesc{integer, required parameter},\n  specifies upper bound of the makespan.\n\\end{itemize}\n\nExample LOGOS input XML for RCPSP Model:\n\\begin{lstlisting}[style=XML]\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Logos>\n  ...\n  <Settings>\n    <makespan_upperbound>65</makespan_upperbound>\n    <solver>cbc</solver>\n    <sense>minimize</sense>\n    <problem_type>rcpsp</problem_type>\n  </Settings>\n  ...\n</Logos>\n\\end{lstlisting}\n", "meta": {"hexsha": "3e5036b9b00acbf960f97ec9b27b87998c22c7be", "size": 9082, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "doc/user_manual/include/rcpsp.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/rcpsp.tex", "max_issues_repo_name": "dgarrett622/LOGOS", "max_issues_repo_head_hexsha": "7234b8b5e80bc79526b4cbced7efd5ae482f7c44", "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/rcpsp.tex", "max_forks_repo_name": "dgarrett622/LOGOS", "max_forks_repo_head_hexsha": "7234b8b5e80bc79526b4cbced7efd5ae482f7c44", "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": 36.7692307692, "max_line_length": 110, "alphanum_fraction": 0.7094252367, "num_tokens": 2754, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9032942067038785, "lm_q2_score": 0.8311430499496095, "lm_q1q2_score": 0.7507667019616746}}
{"text": "\\chapter{Heapsort}\n\n\\section{Heaps}\n\n\\begin{enumerate}\n\n\\item[6.1{-}1]{What are the minimum and maximum numbers of elements in a heap of\nheight $h$?}\n\n\\begin{framed}\nMinimum is $2^{h}$. Maximum is $2^{h + 1} - 1$.\n\\end{framed}\n\n\\item[6.1{-}2]{Show that an $n$-element heap has height $\\floor{\\lg n}$.}\n\n\\begin{framed}\nA heap of height $h + 1$ is a complete tree of height $h$ plus one additional\nlevel with $1 \\le k \\le 2^h$ nodes. This additional level does not count to the\nheight of the heap, which then explain the height of $\\floor{\\lg n}$.\n\\end{framed}\n\n\\item[6.1{-}3]{Show that in any subtree of a max-heap, the root of the subtree\ncontains the largest value occurring anywhere in that subtree.}\n\n\\begin{framed}\n  Every node of the subtree has a path upwards to the root of the subtree.\n  Therefore, the max-heap property assures that each of these nodes are no\n  larger than the root of the subtree.\n\\end{framed}\n\n\\item[6.1{-}4]{Where in a max-heap might the smallest element reside, assuming\nthat all elements are distinct?}\n\n\\begin{framed}\nIn the leaves. Note that, since the bottom level may be incomplete, in addition\nto the nodes on level zero, some of the nodes on level one may also be leaves.\n\\end{framed}\n\n\\item[6.1{-}5]{Is an array that is in sorted order a min-heap?}\n\n\\begin{framed}\nYes, since for each node $i$, we have $A[\\textsc{Parent}(i)] \\le A[i]$.\n\\end{framed}\n\n\\item[6.1{-}6]{Is the array with values\n$\\langle 23, 17, 14, 6, 13, 10, 1, 5, 7, 12 \\rangle$ a max-heap?}\n\n\\begin{framed}\nNo. The element 6 is the parent of the element 7 and $6 < 7$, which violates the\nmin-heap property.\n\\end{framed}\n\n\\item[6.1{-}7]{Show that, with the array representation for storing an\n$n$-element heap, the leaves are the nodes indexed by\n$\\floor{n/2} + 1, \\ceil{n/2} + 2, \\dots, n$.}\n\n\\begin{framed}\nThe parent of the last element of the array is the element at position\n$\\floor{n/2}$, which implies that all elements after $\\floor{n/2}$ has no\nchildren and are therefore leaves. Also, since the element at position\n$\\floor{n/2}$ has at least one child (the element at position $n$), the\nelements before $\\floor{n/2}$ also have and therefore can not be leaves.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Maintaining the heap property}\n\n\\begin{enumerate}\n\n\\item[6.2-1]{Using Figure 6.2 as a model, illustrate the operation of\n\\textsc{Max-Heapify}$(A, 3)$ on the array\n$A = \\langle 27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0 \\rangle$.}\n\n\\begin{framed}\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n[.27\n    [.17\n    \\edge[];\n        [.16\n        \\edge[]; {5}\n        \\edge[]; {7}\n        ]\n    \\edge[];\n        [.13\n        \\edge[]; {12}\n        \\edge[]; {4}\n        ]\n    ]\n    [.\\node[red]{3};\n    \\edge[red];\n        [.\\node[red]{10};\n        \\edge[]; {8}\n        \\edge[]; {9}\n        ]\n    \\edge[];\n        [.1\n        \\edge[]; {0}\n        \\edge[blank]; \\node[blank]{};\n        ]\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.27\n    [.17\n    \\edge[];\n        [.16\n        \\edge[]; {5}\n        \\edge[]; {7}\n        ]\n    \\edge[];\n        [.13\n        \\edge[]; {12}\n        \\edge[]; {4}\n        ]\n    ]\n    [.10\n    \\edge[];\n        [.\\node[red]{3};\n        \\edge[]; {8}\n        \\edge[red]; \\node[red]{9};\n        ]\n    \\edge[];\n        [.1\n        \\edge[]; {0}\n        \\edge[blank]; \\node[blank]{};\n        ]\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.27\n    [.17\n    \\edge[];\n        [.16\n        \\edge[]; {5}\n        \\edge[]; {7}\n        ]\n    \\edge[];\n        [.13\n        \\edge[]; {12}\n        \\edge[]; {4}\n        ]\n    ]\n    [.10\n    \\edge[];\n        [.9\n        \\edge[]; {8}\n        \\edge[]; {3}\n        ]\n    \\edge[];\n        [.1\n        \\edge[]; {0}\n        \\edge[blank]; \\node[blank]{};\n        ]\n    ]\n]\n\\end{tikzpicture}\n\\end{center}\n\\end{framed}\n\n\\item[6.2-2]{Starting with the procedure \\textsc{Max-Heapify}, write pseudocode\nfor the procedure \\textsc{Min-Heapify}$(A, i)$, which performs the corresponding\nmanipulation on a min-heap. How does the running time of \\textsc{Min-Heapify}\ncompare to that of \\textsc{Max-Heapify}?}\n\n\\begin{framed}\nThe pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Min-Heapify}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, i}}{%\n\\nl $l = \\texttt{Left}(i)$\\;\n\\nl $r = \\texttt{Right}(i)$\\;\n\\nl \\If{$l \\le A.\\text{\\emph{heap-size}}$ \\upshape{and} $A[l] < A[i]$}{%\n\\nl   $\\text{\\emph{smallest}} = l$\\; }\n\\nl \\Else{%\n\\nl   $\\text{\\emph{smallest}} = i$\\; }\n\\nl \\If{$r \\le A.\\text{\\emph{heap-size}}$ \\upshape{and} $A[r] < A[smallest]$}{%\n\\nl   $\\text{\\emph{smallest}} = r$\\;}\n\\nl \\If{$\\text{\\emph{smallest}} \\neq i$}{%\n\\nl   \\upshape{exchange} $A[i]$ \\upshape{with} $A[smallest]$\\;\n\\nl   \\texttt{Min-Heapify}$(A, \\text{\\emph{smallest}})$\\; } }\n\\end{algorithm}\n\nThe running time is the same.\n\\end{framed}\n\n\\item[6.2-3]{What is the effect of calling \\textsc{Max-Heapify}$(A, i)$ when the\nelement $A[i]$ is larger than its children?}\n\n\\begin{framed}\nNode $i$ and its children already satisfies the max-heap property. No recursion\nwill be called and the array will keep the same.\n\\end{framed}\n\n\\item[6.2-4]{What is the effect of calling \\textsc{Max-Heapify}$(A, i)$ for\n$i > A.\\text{\\emph{heap-size}}/2$?}\n\n\\begin{framed}\nEvery node $i > A.\\text{\\emph{heap-size}}/2$ is a leaf. No recursion will be\ncalled and the array will keep the same.\n\\end{framed}\n\n\\newpage\n\n\\item[6.2-5]{The code for \\textsc{Max-Heapify} is quite efficient in terms of\nconstant factors, except possibly for the recursive call in line 10, which might\ncause some compilers to produce inefficient code. Write an efficient\n\\textsc{Max-Heapify} that uses an iterative control construct (a loop) instead\nof recursion.}\n\n\\begin{framed}\nThe pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Max-Heapify-Iterative}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, i}}{%\n\\nl $\\text{\\emph{solved}} = \\texttt{False}$\\;\n\\nl $\\text{\\emph{current-node}} = i$\\;\n\\nl \\While{\\upshape{not} \\text{\\emph{solved}}}{%\n\\nl   $l = \\texttt{Left}(\\text{\\emph{current-node}})$\\;\n\\nl   $r = \\texttt{Right}(\\text{\\emph{current-node}})$\\;\n\\nl   \\If{$l \\le A.\\text{heap-size}$ \\upshape{and} $A[l] > A[\\text{\\emph{current-node}}]$}{%\n\\nl     $\\text{\\emph{largest}} = l$\\; }\n\\nl   \\Else{%\n\\nl     $\\text{\\emph{largest}} = \\text{\\emph{current-node}}$\\; }\n\\nl   \\If{$r \\le A.\\text{heap-size}$ \\upshape{and} $A[r] > A[\\text{\\emph{largest}}]$}{%\n\\nl     $\\text{\\emph{largest}} = r$\\;}\n\\nl   \\If{$\\text{largest} \\neq \\text{current-node}$}{%\n\\nl     \\upshape{exchange} $A[\\text{\\emph{current-node}}]$ \\upshape{with} $A[\\text{\\emph{largest}}]$\\;\n\\nl     $\\text{\\emph{current-node}} = \\text{\\emph{largest}}$\\; }\n\\nl   \\Else{%\n\\nl     $\\text{\\emph{solved}} = \\texttt{True}$\\; } } }\n\\end{algorithm}\n\\end{framed}\n\n\\item[6.2-6]{Show that the worst-case running time of \\textsc{Max-Heapify} on a\nheap of size $n$ is $\\Omega(\\lg n)$. (Hint: For a heap with $n$ nodes, give node\nvalues that cause \\textsc{Max-Heapify} to be called recursively at every node on\na simple path from the root down to a leaf.)}\n\n\\begin{framed}\nThe worst-case occurs when $A[\\textsc{Left}(i)] \\ge A[\\textsc{Right}(i)] > A[i]$\nin each level of the recursion, which will cause the node to be pushed to the\nleftmost position on the bottom level of the heap. There will be exactly\n$\\floor{\\lg n}$ recursive calls (in addition to the first call). Since each call\nis $\\Theta(1)$, the total running time is\n$\\floor{\\lg n} \\cdot \\Theta(1) = \\Theta(\\lg n) = \\Omega(\\lg n)$.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Building a heap}\n\n\\begin{enumerate}\n\n\\item[6.3-1]{Using Figure 6.3 as a model, illustrate the operation of\n\\textsc{Build-Max-Heap} on the array\n$A = \\langle 5, 3, 17, 10, 84, 19, 6, 22, 9 \\rangle$.}\n\n\\begin{framed}\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n[.5\n    [.3\n    \\edge[];\n        [.\\node[red]{10};\n        \\edge[]; {22}\n        \\edge[]; {9}\n        ]\n    \\edge[]; {84}\n    ]\n    [.17\n    \\edge[]; {19}\n    \\edge[]; {6}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.5\n    [.3\n    \\edge[];\n        [.22\n        \\edge[]; {10}\n        \\edge[]; {9}\n        ]\n    \\edge[]; {84}\n    ]\n    [.\\node[red]{17};\n    \\edge[]; {19}\n    \\edge[]; {6}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.5\n    [.\\node[red]{3};\n    \\edge[];\n        [.22\n        \\edge[]; {10}\n        \\edge[]; {9}\n        ]\n    \\edge[]; {84}\n    ]\n    [.19\n    \\edge[]; {17}\n    \\edge[]; {6}\n    ]\n]\n\\end{tikzpicture}\n\\vspace{1em}\\\\\n\\begin{tikzpicture}\n\\Tree\n[.\\node[red]{5};\n    [.84\n    \\edge[];\n        [.22\n        \\edge[]; {10}\n        \\edge[]; {9}\n        ]\n    \\edge[]; {3}\n    ]\n    [.19\n    \\edge[]; {17}\n    \\edge[]; {6}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.84\n    [.22\n    \\edge[];\n        [.10\n        \\edge[]; {5}\n        \\edge[]; {9}\n        ]\n    \\edge[]; {3}\n    ]\n    [.19\n    \\edge[]; {17}\n    \\edge[]; {6}\n    ]\n]\n\\end{tikzpicture}\n\\end{center}\n\\end{framed}\n\n\\item[6.3-2]{Why do we want the loop index $i$ in line 2 of\n\\textsc{Build-Max-Heap} to decrease from $\\floor{A.\\text{\\emph{length}}/2}$ to\n1 rather than increase from 1 to $\\floor{A.\\text{\\emph{length}}/2}$}?\n\n\\begin{framed}\nWhen we use \\textsc{Max-Heapify} in a bottom-up manner, before each call to\n\\textsc{Max-Heapify}$(A, i)$, we can be sure that the subtrees rooted on\nits children are max-heaps and thus after exchanging $A[i]$ with\n$\\max(A[\\textsc{Left}(i)], A[\\textsc{Right}(i)])$, $A[i]$ will be the largest\nnode among the nodes of the subtree rooted at $i$. In contrast, when we use\n\\textsc{Max-Heapify} in a top-down manner, we can not be sure of that. For\ninstance, if in a call to $\\textsc{Max-Heapify}(i)$,\n$\\textsc{Left}(i) > \\textsc{Right}(i)$ and the largest node of the subtree\nrooted on $i$ is on the subtree rooted on $\\textsc{Right}(i)$, this largest\nelement will never reach the position $i$, which will then violate the max-heap\nproperty.\n\\end{framed}\n\n\\item[6.3-3]{Show that there are at most $\\ceil{n/2^{h + 1}}$ nodes of heigh $h$\nin any $n$-element heap.}\n\n\\begin{framed}\nFrom 6.1-7, we know that the leaves of a heap are the nodes indexed by\n\\[\n\\floor{n/2} + 1, \\floor{n/2} + 2, \\dots, n.\n\\]\nNote that those elements corresponds to the second half of the heap array (plus\nthe middle element if $n$ is odd). Thus, the number of leaves in any heap of\nsize $n$ is $\\ceil{n/2}$. Lets prove by induction. Let $n_h$ denote the number\nof nodes at height $h$. The upper bound holds for the base since\n$n_0 = \\ceil{n/2^{0 + 1}} = \\ceil{n/2}$ is exactly the number of leaves in\na heap of size $n$. Now assume is holds for $h - 1$. We shall prove that it\nalso holds for $h$.  Note that if $n_{h - 1}$ is even each node at height $h$\nhas exactly two children, which implies\n$n_h = n_{h - 1}/2 = \\ceil{n_{h - 1}/2}$. If $n_{h - 1}$ is odd, one node at\nheight $h$ has one child and the remaining has two children, which also implies\n$n_h = \\floor{n_{h - 1}/2} + 1 = \\ceil{n_{h - 1}/2}$. Thus, we have\n\\[\n  n_h =   \\Bigl\\lceil \\frac{n_{h - 1}}{2} \\Bigr\\rceil\n      \\le \\Bigl\\lceil\\frac{1}{2} \\cdot \\Bigl\\lceil\\frac{n}{2^{(h - 1) + 1}}\\Bigr\\rceil\\Bigr\\rceil\n      =   \\Bigl\\lceil\\frac{1}{2} \\cdot \\Bigl\\lceil\\frac{n}{2^h}\\Bigr\\rceil\\Bigr\\rceil\n      =   \\Bigl\\lceil \\frac{n}{2^{h + 1}} \\Bigr\\rceil,\n\\]\nwhich shows that it also holds for $h$.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{The heapsort algorithm}\n\n\\begin{enumerate}\n\n\\item[6.4-1]{Using Figure 6.4 as a model, illustrate the operation of\n\\textsc{HeapSort} on the array\n$A = \\langle 5, 13, 2, 25, 7, 17, 20, 8, 4 \\rangle$.}\n\n\\begin{framed}\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n[.25\n    [.13\n    \\edge[];\n        [.8\n        \\edge[]; {5}\n        \\edge[]; {4}\n        ]\n    \\edge[]; {7}\n    ]\n    [.20\n    \\edge[]; {17}\n    \\edge[]; {2}\n    ]\n]\n\\end{tikzpicture}\n\n\\vspace{1em}\n\n\\begin{tikzpicture}\n\\Tree\n[.20\n    [.13\n    \\edge[];\n        [.8\n        \\edge[]; {5}\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[]; {7}\n    ]\n    [.17\n    \\edge[]; {4}\n    \\edge[]; {2}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.17\n    [.13\n    \\edge[];\n        [.8\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[]; {7}\n    ]\n    [.5\n    \\edge[]; {4}\n    \\edge[]; {2}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.13\n    [.8\n    \\edge[];\n        [.2\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[]; {7}\n    ]\n    [.5\n    \\edge[]; {4}\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.8\n    [.7\n    \\edge[];\n        [.2\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[]; {4}\n    ]\n    [.5\n    \\edge[blank]; \\node[red]{13};\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\n\\vspace{1em}\n\n\\begin{tikzpicture}\n\\Tree\n[.7\n    [.4\n    \\edge[];\n        [.2\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[blank]; \\node[red]{8};\n    ]\n    [.5\n    \\edge[blank]; \\node[red]{13};\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.5\n    [.4\n    \\edge[blank];\n        [.\\node[red]{7};\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[blank]; \\node[red]{8};\n    ]\n    [.2\n    \\edge[blank]; \\node[red]{13};\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.4\n    \\edge[];\n    [.2\n    \\edge[blank];\n        [.\\node[red]{7};\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[blank]; \\node[red]{8};\n    ]\n    \\edge[blank];\n    [.\\node[red]{5};\n    \\edge[blank]; \\node[red]{13};\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.2\n    \\edge[blank];\n    [.\\node[red]{4};\n    \\edge[blank];\n        [.\\node[red]{7};\n        \\edge[blank]; \\node[red]{20};\n        \\edge[blank]; \\node[red]{25};\n        ]\n    \\edge[blank]; \\node[red]{8};\n    ]\n    \\edge[blank];\n    [.\\node[red]{5};\n    \\edge[blank]; \\node[red]{13};\n    \\edge[blank]; \\node[red]{17};\n    ]\n]\n\\end{tikzpicture}\n\\end{center}\n\\end{framed}\n\n\\item[6.4-2]{Argue the correctness of \\textsc{HeapSort} using the following loop\ninvariant:\n\\begin{quote}\nAt the start of each iteration of the \\textbf{for} loop of line 2{--}5, the\nsubarray $A[1 \\dots i]$ is a max-heap containing the $i$ smallest elements of\n$A[1 \\dots n]$, and the subarray $A[i + 1 \\dots n]$ contains the $n - i$ largest\nelements of $A[1 \\dots n]$, sorted. \\vspace{0.5em}\n\\end{quote}\n}\n\n\\begin{framed}\nWe need to show that this invariant is true prior to the first loop iteration,\nthat each iteration of the loop maintains the invariant, and that the invariant\nprovides a useful property to show correctness when the loop terminates.\n\n\\begin{itemize}\n  \\item \\textbf{Initialization.} Before the \\textbf{for} loop, $i = n$ and line\n    $1$ assures $A$ is a max-heap. Thus, $A[1, \\dots, i] = A$ is a max-heap\n    containing the $i$ smallest elements of $A$ and\n    $A[i + 1, \\dots, n] = \\emptyset$ contains the $n - i = 0$ largest elements\n    of $A$, sorted.\n  \\item \\textbf{Maintenance.} By the loop invariant, $A[1, \\dots, i]$ is\n    a max-heap containing the $i$ smallest elements of $A$, which implies that\n    $A[1]$ is the $i$th smallest element of $A$. Since $A[i + 1, \\dots, n]$\n    already contains the $n - i$ largest elements of $A$ in sorted order, after\n    exchanging $A[1]$ with $A[i]$, the subarray $A[i, \\dots, n]$ now contains\n    the $n - i + 1$ largest elements of $A$ in sorted order. Lines 4-5 maintains\n    the max-heap property on the subarray $A[1, \\dots, i - 1]$ and decrement $i$\n    for the next iteration preserves the loop invariant.\n  \\item \\textbf{Termination.} At termination $i = 1$ and the subarray\n    $A[2, \\dots n]$ contains the $n - 1$ smallest elements of $A$ in sorted\n    order, which also implies that $A[1, \\dots, n]$ is fully sorted.\n\\end{itemize}\n\\end{framed}\n\n\\newpage\n\n\\item[6.4-3]{What is the running time of \\textsc{HeapSort} on an array $A$ of\nlength $n$ that is already sorted in increasing order? What about decreasing\norder?}\n\n\\begin{framed}\nSince an array that is sorted in increasing order is not a max-heap,\n\\textsc{Build-Max-Heap} will break that ordering. The \\textsc{Build-Max-Heap}\nprocedure will take $\\Theta(n)$ to build the max-heap and the \\textbf{for} loop\nof lines $2{-}5$ will take $O(n \\lg n)$, which gives a total running time of\n$\\Theta(n) + O(n \\lg n) = O(n \\lg n)$.\n\nAn array sorted in drecreasing order is already a max-heap, but even in that\ncase \\textsc{Build-Max-Heap} will take $\\Theta(n)$. Note that, although the\ninput is sorted in decreasing order, the intent of the algorithm is to sort in\nincreasing order. In each iteration of the \\textbf{for} loop of lines $2{-}5$,\nit will exchange $A[1]$ with $A[i]$ and will call \\textsc{Max-Heapify} on\n$A[1]$. Since $A[1]$ is not anymore the largest element of $A$, each call to\n\\textsc{Max-Heapify} may cover the entire height of the heap and thus will take\n$O(\\lg n)$. Thus, the \\textbf{for} loop of lines $2{-}5$ will run in\n$O(n \\lg n)$ and the algorithm will take $\\Theta(n) + O(n \\lg n) = O(n \\lg n)$.\n\\end{framed}\n\n\\item[6.4-4]{Show that the worst-case running time of \\textsc{HeapSort} is\n$\\Omega(n \\lg n)$.}\n\n\\begin{framed}\nThe worst-case is when every call to \\textsc{Max-Heapify} covers the entire\nheight of the heap. In that case, \\textsc{HeapSort} will take\n\\[\n  \\sum_{i = 1}^{n - 1} \\floor{\\lg i} \\le \\sum_{i = 1}^{n - 1} \\lg i = \\lg((n - 1)!) = \\Theta((n - 1) \\lg (n - 1)) = \\Omega(n \\lg n).\n\\]\n\\end{framed}\n\n\\item[6.4-5]{($\\star$) Show that when all elements are distinct, the best-case\nrunning time of \\textsc{HeapSort} is $\\Omega(n \\lg n)$.}\n\n\\begin{framed}\nProof on (Theorem 1, Page 86):\n\\begin{quote}\nSchaffer, Russel, and Robert Sedgewick. ``The analysis of heapsort.''\n\\emph{Journal of Algorithms} 15.1 (1993): 76-100.\n\\end{quote}\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section{Priority queues}\n\n\\begin{enumerate}\n\n\\item[6.5{-}1]{Illustrate the operation of \\textsc{Heap-Extract-Max}\non the heap $A = \\langle 15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1 \\rangle$.}\n\n\\begin{framed}\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n[.15\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[];\n        [.8\n        \\edge[]; {1}\n        \\edge[blank]; \\node[blank]{};\n        ]\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\n\\vspace{1em}\n\n\\begin{tikzpicture}\n\\Tree\n[.\\node[red]{1};\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[]; {8}\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.13\n    [.\\node[red]{1};\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[]; {8}\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.13\n    [.12\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.\\node[red]{1};\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[]; {8}\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.13\n    [.12\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.6\n        \\edge[]; \\node[red]{1};\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[]; {8}\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\end{center}\n\\end{framed}\n\n\\item[6.5{-}2]{Illustrate the operation of \\textsc{Max-Heap-Insert}$(A, 10)$\non the heap $A = \\langle 15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1 \\rangle$.}\n\n\\begin{framed}\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n[.15\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[];\n        [.8\n        \\edge[]; {1}\n        \\edge[blank]; \\node[blank]{};\n        ]\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\n\\vspace{1em}\n\n\\begin{tikzpicture}\n\\Tree\n[.15\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[];\n        [.8\n        \\edge[]; {1}\n        \\edge[]; \\node[red]{10};\n        ]\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.15\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.9\n    \\edge[];\n        [.\\node[red]{10};\n        \\edge[]; {1}\n        \\edge[]; {8}\n        ]\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n[.15\n    [.13\n    \\edge[];\n        [.5\n        \\edge[]; {4}\n        \\edge[]; {0}\n        ]\n    \\edge[];\n        [.12\n        \\edge[]; {6}\n        \\edge[]; {2}\n        ]\n    ]\n    [.\\node[red]{10};\n    \\edge[];\n        [.9\n        \\edge[]; {1}\n        \\edge[]; {8}\n        ]\n    \\edge[]; {7}\n    ]\n]\n\\end{tikzpicture}\n\\end{center}\n\\end{framed}\n\n\\newpage\n\n\\item[6.5{-}3]{Write pseudocode for the procedures \\textsc{Heap-Minimum},\n\\textsc{Heap-Extract-Min}, \\textsc{Heap-Decrease-Key}, and\n\\textsc{Min-Heap-Insert} that implement a min-priority queue with a min-heap.}\n\n\\begin{framed}\nThe pseudocodes are stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Heap-Minimum}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl \\Return{$A[1]$}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Heap-Extract-Min}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl \\If{$A.\\text{heap-size} < 1$}{%\n\\nl \\textbf{error} ``heap underflow''\\; }\n\\nl \\emph{min} = $A[1]$\\;\n\\nl $A[1] = A[A.\\text{\\emph{heap-size}}]$\\;\n\\nl $A.\\text{\\emph{heap-size}} = A.\\text{\\emph{heap-size}} - 1$\\;\n\\nl \\texttt{Min-Heapify}$(A, 1)$\\;\n\\nl \\Return{min}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Heap-Decrease-Key}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, i, key}}{%\n\\nl \\If{$\\text{key} > A[i]$}{%\n\\nl   \\textbf{error} ``new key is larger than current key''\\; }\n\\nl $A[i] = key$\\;\n\\nl \\While{$i > 1$ \\textbf{and} $A[\\texttt{\\upshape{Parent}}(i)] > A[i]$}{%\n\\nl   \\upshape{exchange} $A[i]$ \\upshape{with} $A[\\texttt{Parent}(i)]$\\;\n\\nl   $i = \\texttt{Parent}(i)$\\; } }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Min-Heap-Insert}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, key}}{%\n\\nl $A.\\text{\\emph{heap-size}} = A.\\text{\\emph{heap-size}} + 1$\\;\n\\nl $A[A.\\text{\\emph{heap-size}}] = +\\infty$\\;\n\\nl \\texttt{Heap-Decrease-Key}$(A, A.\\text{\\emph{heap-size}}, key)$\\; }\n\\end{algorithm}\n\\end{framed}\n\n\\item[6.5{-}4]{Why do we bother setting the key of the inserted node to\n$-\\infty$ in line 2 of \\textsc{Max-Heap-Insert} when the next thing we do is\nincrease its key to the desired value?}\n\n\\begin{framed}\nBeacause the \\textsc{Heap-Increase-Key} procedure requires that the new key is\ngreater than or equal to the current key.\n\\end{framed}\n\n\\item[6.5{-}5]{Argue the correctness of \\textsc{Heap-Increase-Key} using the\nfolowing loop invariant:\n\\begin{quote}\nAt the start of each iteration of the \\textbf{while} loop of lines 4-6,\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Left}(i)]$ and\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Right}(i)]$, if these nodes exist, and the\nsubarray $A[1, \\dots, A.\\text{\\emph{heap-size}}]$ satisfies the max-heap\nproperty, except that there may be one violation: $A[i]$ may be larger than\n$A[\\textsc{Parent}(i)]$.\n\n\\end{quote}\nYou may assume that subarray $A[1, \\dots, A.\\text{\\emph{heap-size}}]$\nsatisfies the max-heap property at the time \\textsc{Heap-Increase-Key} is\ncalled.\n}\n\n\\begin{framed}\nWe need to show that this invariant is true prior to the first loop iteration,\nthat each iteration of the loop maintains the invariant, and that the invariant\nprovides a useful property to show correctness when the loop terminates.\n\n\\begin{itemize}\n\\item \\textbf{Initialization.} Before the \\textbf{while} loop, $A$ is\na valid max-heap with a possible change on the value of the element $A[i]$.\nThus, the invariants $A[\\textsc{Parent}(i)] \\ge A[\\textsc{Left}(i)]$ and\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Right}(i)]$ holds (these values were\nnot changed before the loop). Since the new value of $A[i]$ is equal or larger\nits previous value and its previous value was equal or larger than the value of\nits children ($A$ was a max-heap at the time \\textsc{Heap-Increse-Key}\nwas called), the only possible violation on the heap is that $A[i]$ may be\nlarger than $A[\\textsc{Parent}(i)]$, thus the second invariant also holds.\n\\item \\textbf{Maintenance.} By the loop invariant, the only possible violation\nis that $A[i]$ may be larger than $A[\\textsc{Parent}(i)]$. If there is no\nviolation ($A[i]$ does not have a parent of $A[i] \\le A[\\textsc{Parent}(i)]$),\nthe loop terminates and $A$ is a valid max-heap. If there is a violation on\n$A[i]$, the positions of $A[i]$ and $A[\\textsc{Parent}(i)]$ are exchanged.\nFrom the loop invariant, before the exchange,\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Left}(i)]$ and\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Right}(i)]$, which implies that, after\nthe exchange, the new $A[i]$ will not violate the max-heap property anymore and\nthe invariants $A[\\textsc{Parent}(i)] \\ge A[\\textsc{Left}(i)]$ and\n$A[\\textsc{Parent}(i)] \\ge A[\\textsc{Right}(i)]$ will remain valid. The only\npossible violation after the exchange is that $A[\\textsc{Parent}(i)]$ may be\nlarger than $A[\\textsc{Parent}(\\textsc{Parent}(i))]$, but setting\n$i = \\textsc{Parent}(i)$ preserves the loop invariant for the next iteration.\n\\item \\textbf{Termination.} At termination, either $i = 1$ or\n$A[i] \\le A[\\textsc{Parent}(i)]$. In both cases, $A[i]$ is not larger than\n$A[\\textsc{Parent}(i)]$, which implies that $A$ is a valid max-heap.\n\\end{itemize}\n\\end{framed}\n\n\\item[6.5{-}6]{Each exchange operation on line 5 of \\textsc{Heap-Increase-Key}\ntypically requires three assignments. Show how to use the idea of the inner\nloop of \\textsc{Insertion-Sort} to reduce the three assignments down to just one\nassignment.}\n\n\\begin{framed}\nThe updated pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Heap-Increase-Key}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, i, key}}{%\n\\nl \\If{$\\text{key} < A[i]$}{%\n\\nl   \\textbf{error} ``new key is smaller than current key''\\; }\n\\nl \\While{$i > 1$ \\textbf{and} $A[\\texttt{\\upshape{Parent}}(i)] < key$}{%\n\\nl   $A[i] = A[\\texttt{Parent}(i)]$\\;\n\\nl   $i = \\texttt{Parent}(i)$\\; }\n\\nl $A[i] = key$\\; }\n\\end{algorithm}\n\\end{framed}\n\n\\item[6.5{-}7]{Show how to implement a first-in, first-out queue with a priority\nqueue. Show how to implement a stack with a priority queue. (Queues and stacks\nare defined in Section 10.1.)}\n\n\\begin{framed}\nA first-in, first-out queue can be implemented using a min-priority-queue, in\nsuch a way that each heap element is a tuple (key, handle) and the key of a new\nelement is greater than the key of the current elements. The\n\\textsc{Extract-Min} operation will always return the oldest element (minimum\nkey value) and the \\textsc{Insert} operation will keep the min-heap property.\nA stack can be implemented similarly, but with a max-priority-heap instead of\na min-priority-heap.\n\\end{framed}\n\n\\item[6.5{-}8]{The operation \\textsc{Heap-Delete}$(A, i)$ deletes the item in\nnode $i$ from heap $A$. Give an implementation of \\textsc{Heap-Delete} that runs\nin $O(\\lg n)$ time for an $n$-element max-heap.}\n\n\\begin{framed}\nThe pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Heap-Delete}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, i}}{%\n\\nl $A[i] = A[\\text{\\emph{heap-size}}]$\\;\n\\nl $A.\\text{\\emph{heap-size}} = A.\\text{\\emph{heap-size}} - 1$\\;\n\\nl \\texttt{Max-Heapify}$(A, i)$\\; }\n\\end{algorithm}\n\\end{framed}\n\n\\item[6.5{-}9]{Give an $O(n \\lg k)$-time algorithm to merge $k$ sorted lists\ninto one sorted list, where $n$ is the total number of elements in all the input\nlists. (Hint: Use a min-heap for $k$-way merging.)}\n\n\\begin{framed}\nLet $T$ denote the final sorted list and $S_i$ the $i$th input list. The\npseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Merge-Lists-Min-Heap}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{$S_1, S_2, \\dots, S_k$}}{%\n\\nl Let $T$ be a list\\;\n\\nl Let $H$ be a min-heap of tuples in the form $(key, j)$\\;\n\\nl \\For{$i = 1$ \\KwTo $k$}{%\n\\nl   $\\texttt{Insert}(H, (S_i[1], i))$\\;\n\\nl   $p_i = 2$\\; }\n\\nl \\While{$H.\\text{heap-size} > 0$}{%\n\\nl   $(key, j) = \\texttt{Extract-Min}(H)$\\;\n\\nl   add $key$ to $T$\\;\n\\nl   \\If{$p_j \\le S_j.\\text{length}$}{%\n\\nl     $\\texttt{Insert}(H, (S_j[p_j], j))$\\;\n\\nl     $p_j = p_j + 1$\\; } }\n\\nl \\Return{T}\\; }\n\\end{algorithm}\n\nThe \\textbf{for} loop of lines 3{-}5 runs in $O(k \\lg k)$. The \\textbf{while}\nloop of lines 6{-}11 will iterate $n$ times and each iteration takes $O(\\lg k)$.\nSince $n \\ge k$, the algorithm runs in $O(n \\lg k)$.\n\\end{framed}\n\n\\end{enumerate}\n\n\\newpage\n\n\\section*{Problems}\n\\addcontentsline{toc}{section}{\\protect\\numberline{}Problems}%\n\n\\begin{enumerate}\n\n\n\\item[6{-}1]{\\textbf{\\emph{Building a heap using insertion}}\\\\\nWe can build a heap by repeatedly calling \\textsc{Max-Heap-Insert} to insert\nthe elements into the heap. Consider the following variation on the\n\\textsc{Build-Max-Heap} procedure:\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Build-Max-Heap'}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $A.\\text{\\emph{heap-size}} = 1$\\;\n\\nl \\For{$i = 2$ \\KwTo $A.\\text{length}$}{%\n\\nl   $\\textsc{Max-Heap-Insert}(A, A[i])$\\; } }\n\\end{algorithm}\n\n\\begin{enumerate}\n\\item[\\textbf{a.}]{Do the procedures \\textsc{Build-Max-Heap} and\n\\textsc{Build-Max-Heap\\texttt{'}} always create the same heap when run on the\nsame input array? Prove that they do, or provide a counterexample.}\n\\item[\\textbf{b.}]{Show that in the worst-case,\n\\textsc{Build-Max-Heap\\texttt{'}} requires $\\Theta(n \\lg n)$ time to build an\n$n$-element heap.}\n\\end{enumerate}\n\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\n\\item No. Consider the array $A = [1, 2, 3]$. \\textsc{Build-Max-Heap}$(A)$ will\ncreate the heap\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n  [.\\node[red]{1};\n  \\edge[]; {2}\n  \\edge[]; {3}\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n  [.3\n  \\edge[]; {2}\n  \\edge[]; {1}\n]\n\\end{tikzpicture}\n\\end{center}\n\nwhile \\textsc{Build-Max-Heap\\texttt{'}}$(A)$ will create the heap\n\n\\begin{center}\n\\begin{tikzpicture}\n\\Tree\n  [.1\n  \\edge[]; \\node[red]{2};\n  \\edge[]; {3}\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n  [.2\n  \\edge[]; {1}\n  \\edge[]; \\node[red]{3};\n]\n\\end{tikzpicture}\n\\begin{tikzpicture}\n\\Tree\n  [.3\n  \\edge[]; {1}\n  \\edge[]; {2}\n]\n\\end{tikzpicture}\n\\end{center}\n\n\\item Let $A$ be the input array. The worst-case occurs when there is an integer\n$k$ such that $n = A.\\text{\\emph{length}} = 2^k - 1$ (that is, the elements of\n$A$ forms a complete binary tree) and each call to \\textsc{Max-Heap-Insert}\ncovers the entire height of the heap (occurs when $A$ is sorted). Since any heap\nhas $\\ceil{n/2}$ leaves, the last $\\ceil{n/2}$ elements of $A$ will be the\nleaves of the final heap. Note that, at the time \\textsc{Max-Heap-Insert} is\ncalled on these last $\\ceil{n/2}$ nodes, the height of the heap will be\n$\\floor{\\lg n}$. Thus, considering only the last $\\ceil{n/2}$ calls to\n$\\textsc{Max-Heap-Insert}$, the algorithm will take $\\ceil{n/2} \\cdot\n\\Theta(\\floor{\\lg n}) = \\Theta(n \\lg n)$, which implies that the worst-case\nof \\textsc{Build-Max-Heap\\texttt{'}} runs in $\\Omega(n \\lg n)$. Also, note\nthat there will be exactly $n - 1$ calls to \\textsc{Max-Heap-Insert} and\neach call takes $O(\\floor{\\lg n})$. Thus, the worst-case of\n\\textsc{Build-Max-Heap\\texttt{'}} runs in $\\Theta(n \\lg n)$.\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[6{-}2]{\\textbf{\\emph{Analysis of d-ary heaps}}\\\\\nA \\textbf{\\emph{d-ary}} heap is like a binary heap, but (with one possible\nexception) non-leaf nodes have $d$ children instead of 2 children.\n\\begin{enumerate}\n\\item[\\textbf{a.}] How would you represent a $d$-ary heap in an array?\n\\item[\\textbf{b.}] What is the height of a $d$-ary heap of $n$ elements in terms\nof $n$ and $d$?\n\\item[\\textbf{c.}] Give an efficient implementation of \\textsc{Extract-Max} in\na $d$-ary max-heap. Analyze its running time in terms of $d$ and $n$.\n\\item[\\textbf{d.}] Give an efficient implementation of \\textsc{Insert} in\na $d$-ary max-heap. Analyze its running time in terms of $d$ and $n$.\n\\item[\\textbf{e.}] Give an efficient implementation of\n\\textsc{Increase-Key}$(A, i, k)$, which flags an error if $k < A[i]$, but\notherwise sets $A[i] = k$ and then updates the $d$-ary max-heap structure\nappropriately. Analyze its running time in terms of $d$ and $n$.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item The root occupies the first $d^0 = 1$ positions of the array, its\nchildren occupies the next $d^1 = d$ positions of the array, and so on until\nthe bottom level. That way, the parent of a node with index $i$ will be at\nposition\n\\[\n  \\Bigl\\lfloor{\\frac{i - (d - 2)}{d}}\\Bigr\\rfloor\n  = \\Bigl\\lfloor{\\frac{i - d + 2}{d}}\\Bigr\\rfloor,\n\\]\nand its $j$th children will be at position\n\\[\n  di - (d - j) + 1 = di - d + j + 1 = d (i - 1) + j + 1.\n\\]\n\n\\item $h = \\floor{\\log_d n}$.\n\n\\item The only major modification is the \\textsc{Max-Heapify} procedure. The\npseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Child-D-Ary}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{d, i, j}}{%\n\\nl \\Return{$d (i - 1) + j + 1$}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Extract-Max-D-Ary}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, d}}{%\n\\nl \\If{$A.\\text{heap-size} < 1$}{%\n\\nl   \\textbf{error} ``heap underflow''\\; }\n\\nl $\\text{\\emph{max}} = A[1]$\\;\n\\nl $A.\\text{\\emph{heap-size}} = A.\\text{\\emph{heap-size}} - 1$\\;\n\\nl $\\texttt{Max-Heapify-D-Ary}(A, d, 1)$\\;\n\\nl \\Return{\\text{max}}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Max-Heapify-D-Ary}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A, d, i}}{%\n\\nl $\\text{\\emph{largest}} = i$\\;\n\\nl \\For{$j = 1$ \\KwTo $d$}{%\n\\nl   $\\text{\\emph{child-j}} = \\texttt{Child}(d, i, j)$\\;\n\\nl   \\If{$\\text{child-j} > A.\\text{heap-size}$}{%\n\\nl     break\\; }\n\\nl   \\If{$A[\\text{child-j}] > A[\\text{largest}]$}{%\n\\nl     $\\text{\\emph{largest}} = \\text{\\emph{child-j}}$\\; } }\n\\nl \\If{$\\text{largest} \\neq i$}{%\n\\nl   exchange $A[i]$ with $A[\\text{\\emph{largest}}]$\\;\n\\nl   $\\texttt{Max-Heapify-D-Ary}(A, d, \\text{\\emph{largest}})$\\; } }\n\\end{algorithm}\n\nIn the worst-case, \\textsc{Max-Heapify-D-Ary} covers the height of the heap\n(which is $\\log_d n$).  Since each recursive call takes $O(d)$,\n\\textsc{Max-Heapify-D-Ary} runs in $O(d \\log_d n)$. The running time of\n\\textsc{Extract-Max-D-Ary} is also $O(d \\log_d n)$, since it performs a constant\namount of work on top of \\textsc{Max-Heapify-D-Ary}.\n\n\\item The $\\textsc{Max-Heap-Insert}$ procedure given in the text book also works\nfor a $d$-ary heap. The only modification is to use \\textsc{Parent-D-Ary}\ninstead of \\textsc{Parent} in the \\textsc{Heap-Increase-Key} subroutine. In the\nworst case, it will cover the height of the tree. Thus, the running time is\n$O(\\log_d n)$.\n\n\\item The $\\textsc{Heap-Increase-Key}$ procedure given in the text book also\nworks for a $d$-ary heap. The only modification is to use \\textsc{Parent-D-Ary}\ninstead of \\textsc{Parent}. In the worst case, it will cover the height of the\ntree. Thus, the running time is $O(\\log_d n)$.\n\\end{enumerate}\n\\end{framed}\n\n\\newpage\n\n\\item[6{-}3]{\\textbf{\\emph{Young tableaus}}\\\\\nAn $m \\times n$ \\textbf{\\emph{Young tableau}} is an $m \\times n$ matrix such\nthat the entries of each row are in sorted order from left to right and the\nentries of each column are in sorted order from top to bottom. Some of the\nentries of a Young tableau may be $\\infty$, which we treat as nonexistent\nelements. Thus, a Young tableau can be used to hold $r \\le mn$ finite numbers.\n\\begin{enumerate}\n\\item[\\textbf{a.}] Draw a $4 \\times 4$ Young tableau containing the elements\n$\\{9, 16, 3, 2, 4, 8, 5, 14, 12\\}$.\n\\item[\\textbf{b.}] Argue that an $m \\times n$ Young tableau $Y$ is empty if\n$Y[1, 1] = \\infty$. Argue that $Y$ is full (contains $mn$ elements) if\n$Y[m, n] < \\infty$.\n\\item[\\textbf{c.}] Give an algorithm to implement \\textsc{Extract-Min} on\na non-empty $m \\times n$ Young tableau that runs in $O(m + n)$ time. Your\nalgorithm should use a recursive subroutine that solves an $m \\times n$ problem\nby recursively solving either an $(m - 1) \\times n$ or an $m \\times (n - 1)$\nsubproblem. (Hint: Think about \\textsc{Max-Heapify}.) Define $T(p)$, where\n$p = m + n$, to be the maximum running time of \\textsc{Extract-Min} on any\n$m \\times n$ Young tableau. Give and solve a recurrence for $T(p)$ that yields\nthe $O(m + n)$ time bound.\n\\item[\\textbf{d.}] Show how to insert a new element into a nonfull $m \\times n$\nYoung tableau in $O(m + n)$ time.\n\\item[\\textbf{e.}] Using no other sorting method as a subroutine, show how to\nuse an $n \\times n$ Young tableau to sort $n^2$ numbers in $O(n^3)$ time.\n\\item[\\textbf{f.}] Give an $O(m + n)$-time algorithm to determine whether\na given number is stored in a given $m \\times n$ Young tableau.\n\\end{enumerate}\n}\n\n\\begin{framed}\n\\begin{enumerate}\n\\item Here it is:\n\n\\begin{center}\n\\begin{tabular}{cccc}\n  2 & 3 & 4 & 5\\\\\n  8 & 9 & 12 & 14\\\\\n  16 & $\\infty$ & $\\infty$ & $\\infty$\\\\\n  $\\infty$ & $\\infty$ & $\\infty$ & $\\infty$\n\\end{tabular}\n\\end{center}\n\n\\item From the definition of a Young tableau, we have\n\\[\n  Y[1, 1] \\le Y[i, j]\\;\\Forall i, j,\n\\]\nwhich implies\n\\[\n  Y[1, 1] = \\infty \\rightarrow Y[i, j] = \\infty\\;\\Forall i, j.\n\\]\nThus, $Y$ is full of $\\infty$ and is therefore empty.\n\nFrom the definition of a Young tableau, we have\n\\[\n  Y[m, n] \\ge Y[i, j]\\;\\Forall i, j,\n\\]\nwhich implies\n\\[\n  Y[m, n] < \\infty \\rightarrow Y[i, j] < \\infty\\;\\Forall i, j.\n\\]\nThus, $Y$ does not have any $\\infty$ and is therefore full.\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Extract-Min}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{Y}}{%\n\\nl $\\text{\\emph{min}} = Y[1, 1]$\\;\n\\nl \\If{$\\text{min} == \\infty$}{%\n\\nl    \\textbf{error} ``tableau underflow''\\; }\n\\nl $Y[1, 1] = \\infty$\\;\n\\nl $\\texttt{Min-Tableauify}(Y, 1, 1)$\\;\n\\nl \\Return{min}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Min-Tableauify}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{Y, i, j}}{%\n\\nl $\\text{\\emph{smallest-i}} = i$\\;\n\\nl $\\text{\\emph{smallest-j}} = j$\\;\n\\nl \\If{$i + 1 \\le Y.\\text{rows}$ \\textbf{\\upshape{and}} $Y[i + 1, j] < Y[\\text{smallest-i}, \\text{smallest-j}]$}{%\n\\nl   $\\text{\\emph{smallest-i}} = i + 1$\\; }\n\\nl \\If{$j + 1 \\le Y.\\text{cols}$ \\textbf{\\upshape{and}} $Y[i, j + 1] < Y[\\text{smallest-i}, \\text{smallest-j}]$}{%\n\\nl   $\\text{\\emph{smallest-i}} = i$\\;\n\\nl   $\\text{\\emph{smallest-j}} = j + 1$\\; }\n\\nl \\If{$i \\neq \\text{smallest-i}$ \\textbf{\\upshape{or}} $j \\neq \\text{smallest-j}$}{%\n\\nl   $Y[i, j] = Y[\\text{\\emph{smallest-i}}, \\text{\\emph{smallest-j}}]$\\;\n\\nl   $Y[\\text{\\emph{smallest-i}}, \\text{\\emph{smallest-j}}] = \\infty$\\;\n\\nl   $\\texttt{Min-Tableauify}(Y, \\text{\\emph{smallest-i}}, \\text{\\emph{smallest-j}})$\\; } }\n\\end{algorithm}\n\nThe algorithm has the recurrence $T(p) \\le T(p - 1) + \\Theta(1) = O(p) + O(m + n)$.\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Tableau-Insert}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{Y, key}}{%\n\\nl $i = Y.\\text{\\emph{rows}}$\\;\n\\nl $j = Y.\\text{\\emph{cols}}$\\;\n\\nl \\If{$Y[i, j] == \\infty$}{%\n\\nl   \\textbf{error} ``tableau overflow''\\; }\n\\nl $Y[i, j] = \\text{\\emph{key}}$\\;\n\\nl \\While{$i > 1$ \\textbf{\\upshape{or}} $j > 1$}{%\n\\nl   \\If{$i > 1$ \\textbf{\\upshape{and}} $Y[i, j] < Y[i - 1, j]$}{%\n\\nl     exchange $Y[i, j]$ with $Y[i - 1, j]$\\;\n\\nl     $i = i - 1$\\; }\n\\nl   \\ElseIf{$j > 1$ \\textbf{\\upshape{and}} $Y[i, j] < Y[i, j - 1]$}{%\n\\nl     exchange $Y[i, j]$ with $Y[i, j - 1]$\\;\n\\nl     $j = j - 1$\\; }\n\\nl   \\Else{%\n\\nl     break\\; } } }\n\\end{algorithm}\n\nWe first set the element to the position $A[m, n]$ and move it upwards and/or\nleftwards until we find a valid position. The running time is $O(m + n)$\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Build-Young-Tableau}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $n = \\sqrt{A.\\text{\\emph{length}}}$\\;\n\\nl Let $Y$ be an $n \\times n$ array\\;\n\\nl \\For{$i = 1$ \\KwTo $A.\\text{\\emph{length}}$}{%\n\\nl   \\texttt{Tableau-Insert}$(Y, A[i])$\\; }\n\\nl \\Return{$Y$}\\; }\n\\end{algorithm}\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Tableausort}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{A}}{%\n\\nl $Y = \\textsc{Build-Young-Tableau}(A)$\\;\n\\nl \\For{$i = 1$ \\KwTo $A.\\text{length}$}{%\n\\nl   $A[i] = \\texttt{Extract-Min}(Y)$\\; } }\n\\end{algorithm}\n\nThe \\textsc{Build-Young-Tableau} procedure runs in\n$n^2 \\cdot O(n + n) = O(n^3)$. Each call to \\textsc{Min-Tableauify} runs in\n$O(n + n) = O(n)$. Thus, the algorithm runs in\n$O(n^3) + n^2 \\cdot O(n) = O(n^3)$.\n\n\\item The pseudocode is stated below.\n\n\\begin{algorithm}[H]\n\\SetAlgoNoEnd\\DontPrintSemicolon\n\\BlankLine\n\\SetKwFunction{algo}{Tableau-Find}\n\\SetKwProg{myalg}{}{}{}\n\\myalg{\\algo{Y, key}}{%\n\\nl $i = Y.\\text{\\emph{rows}}$\\;\n\\nl $j = 1$\\;\n\\nl \\While{$i \\ge 1$ \\textbf{\\upshape{and}} $j \\le Y.\\text{cols}$}{%\n\\nl   \\If{$Y[i, j] == \\text{\\emph{key}}$}{%\n\\nl     \\Return{\\texttt{\\upshape{True}}}\\; }\n\\nl   \\ElseIf{$Y[i, j] \\le Y[i - 1, j]$}{%\n\\nl     $i = i - 1$\\; }\n\\nl   \\ElseIf{$Y[i, j] \\ge Y[i, j + 1]$}{%\n\\nl     $j = j + 1$\\; }\n\\nl   \\Else{%\n\\nl     break\\; }\n\\nl \\Return{\\texttt{\\upshape{False}}}\\; } }\n\\end{algorithm}\n\n\\end{enumerate}\n\\end{framed}\n\n\\end{enumerate}\n", "meta": {"hexsha": "7539b55ff1f62b0ed9d2aef62fdde72a20b43b7f", "size": 42450, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapters/C6.tex", "max_stars_repo_name": "danielmoraes/clrs", "max_stars_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2016-07-08T17:39:19.000Z", "max_stars_repo_stars_event_max_datetime": "2016-07-08T17:39:19.000Z", "max_issues_repo_path": "chapters/C6.tex", "max_issues_repo_name": "danielmoraes/clrs", "max_issues_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 1, "max_issues_repo_issues_event_min_datetime": "2021-01-31T20:41:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-31T20:41:48.000Z", "max_forks_repo_path": "chapters/C6.tex", "max_forks_repo_name": "danielmoraes/clrs", "max_forks_repo_head_hexsha": "2eb6b5e0be2d6569bf19181dfd972209d97f0e0e", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-03-12T04:51:51.000Z", "max_forks_repo_forks_event_max_datetime": "2020-03-12T04:51:51.000Z", "avg_line_length": 28.1312127237, "max_line_length": 132, "alphanum_fraction": 0.6086925795, "num_tokens": 15580, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8311430478583168, "lm_q2_score": 0.9032942001955142, "lm_q1q2_score": 0.7507666946632403}}
{"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^n}{n!}$\r\ndiverge, converge absolutely, or converge conditionally?\r\n\r\n\\subsection*{Solution}\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| \\frac{(n+1)^{n+1}}{(n+1)!} \\cdot \\frac{n!}{n^n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\left(\\frac{n+1}{n}\\right)^n\\right|\\\\\r\n&= \\lim_{n \\to \\infty}  \\left(\\frac{n+1}{n}\\right)^n.\r\n\\end{align*}\r\nThis is an indeterminate form, so we let $y = \\left(\\frac{n+1}{n}\\right)^n$. So $\\ln y = n \\ln \\frac{n+1}{n}$. Applying limit to both sides, we have\r\n\\[ \\lim_{n \\to \\infty} \\ln y =  \\lim_{n \\to \\infty}  n \\ln \\frac{n+1}{n}.\\]\r\nThe limit on the right can be computed using L'Hopital's rule (with a chain rule and quotent rule).\r\n\\begin{align*}\r\n&\\lim_{n \\to \\infty}  n \\ln \\frac{n+1}{n} \\text{, which was the limit on the right side above}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{ \\ln \\frac{n+1}{n}}{\\frac1n}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{ \\frac{n}{n+1} \\cdot \\frac{n \\cdot 1 - (n+1) \\cdot 1}{n^2}}{\\frac{-1}{n^2}} \\text{ by L'Hopital's}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac{n}{n+1} \\text{ after algebra simplification}\\\\\r\n&= \\lim_{n \\to \\infty} \\frac11\\\\\r\n&= 1.\r\n\\end{align*}\r\nSo, $\\lim y = e^1 = e$. So $L=e$.\r\n\r\nSince $L>1$, the series $\\displaystyle \\sum_{n=1}^\\infty \\frac{n^n}{n!}$ diverges by the Ratio Test.\r\n\r\n\\end{document}%%%%%%%%%%%%%%%%%\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\sqrt[n]{|a_n|}\\\\\r\n&= \\lim_{n \\to \\infty} \\sqrt[n]{\\left| \\right|}\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\nL&=\\lim_{n \\to \\infty} \\left|\\frac{a_{n+1}}{a_n}\\right|\\\\\r\n&= \\lim_{n \\to \\infty} \\left| \\right|\\\\\r\n\\end{align*}\r\n\r\n\\begin{align*}\r\n\\lim_{n \\to \\infty} a_n\r\n&= \\lim_{n \\to \\infty} \\\\\r\n\\end{align*}\r\n\r\n\r\nSince $\\sum |a_n| = \\sum a_n$, the series $\\displaystyle \\sum_{n=1}^\\infty AAAAAAAAAAAAAA$ converges absolutely.\r\n\r\nSince $|r| < 1$, the series ...  converges by the Geometric Series Test.\r\n\r\nSince $|r| \\geq 1$, the series ...  diverges by the Geometric Series Test.\r\n\r\nThe function $f(x)=\\frac{}{}$ is continuous, positive, and decreasing on $[1,\\infty)$.\r\n\r\n\\subsection*{Solution}\r\n\r\n", "meta": {"hexsha": "babf21436b2e51328a79a8e11f01de3af8afc2be", "size": 2251, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "key/series/m2.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/m2.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/m2.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.7301587302, "max_line_length": 149, "alphanum_fraction": 0.5992892048, "num_tokens": 889, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8918110569397307, "lm_q2_score": 0.8418256452674008, "lm_q1q2_score": 0.7507494184648915}}
{"text": "\\chapter{Vectors and Matrices \\label{chapter:linear-algebra.tex}}\nCertain applications, for example data mining and machine learning, require an efficient support of both\nvectors and matrices. \nAlthough vectors and matrices could easily be implemented in \\setlx, this would not be very\nefficient because of the overhead of the interpreter loop.  Therefore, \\setlx\\ supports both vectors and\nmatrices natively.  This support is based on the \\textsl{Java} library \n\\href{http://math.nist.gov/javanumerics/jama/}{\\textsl{Jama}}.  This library is the result of a joint effort of\n\\href{http://www.mathworks.com/}{Mathworks} and the \\href{https://www.nist.gov}{National Institute\n  of Standards and Technology}.  \\textsl{Jama} has been integrated into  \n\\setlx\\ by Patrick Robinson.  This library provides the basic means for computations involving\nmatrices and vectors.  In the following exposition we assume that the reader has some familiarity with  \n\\href{http://en.wikipedia.org/wiki/Linear_algebra}{linear algebra}.\n\n\\section{Vectors}\n\\setlx\\ supports real valued vectors of arbitrary dimensions.  Conceptually, a vector can be viewed as\na list of floating point numbers.  A vector is constructed from a list of numbers via the\nfunction \\texttt{la\\_vector} as follows:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{v := la\\_vector([1/2, 1/4, 1/5]);}\n\\\\[0.2cm]\nWhen executed, this statement yields the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<0.5 0.25 0.2>>}.\n\\\\[0.2cm]\nThis result shows that the fractions in the argument list have been converted to floating point\nnumbers.  Conceptually, the vector \\texttt{v} is a column vector.  Therefore, mathematically\n\\texttt{v} would be written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\left(\\begin{array}{l}\n  0.5  \\\\\n  0.25 \\\\\n  0.2\n\\end{array}\\right)\n$.\n\\\\[0.2cm]\nInstead of using the function \\texttt{la\\_vector,} we could also have used the command\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{v := <<1/2 1/4 1/5>>;}\n\\\\[0.2cm]\nto define the vector \\texttt{v}.  This shows that the operators ``\\texttt{<<}'' and ``\\texttt{>>}''\ncan be used to define a vector.  \\textbf{Note} that the components of a vector are \\textbf{not} separated by the\ncharacter ``\\texttt{,}'' but \\textbf{rather} are separated by white space.  Furthermore, at the\nmoment the syntax that uses the operators ``\\texttt{<<}'' and ``\\texttt{>>}'' only works with\nnumbers, it does not work with arbitrary expressions!\n\n\\setlx\\ support the basic arithmetic operations that are defined for vectors.  If \\texttt{a} and\n\\texttt{b} are two vectors, then \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a + b}\n\\\\[0.2cm]\ncomputes the sum of \\texttt{a} and \\texttt{b}, while \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a - b}\n\\\\[0.2cm]\ncomputes their difference.  Concretely, if we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a = <<a$_1$ $\\cdots$ a$_n$>>} \\quad and \\quad\n\\texttt{b = <<b$_1$ $\\cdots$ b$_n$>>},\n\\\\[0.2cm]\nthen ``\\texttt{a+b}'' and ``\\texttt{a-b}'' are defined componentwise:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a + b := <<(a$_1$+b$_1$) $\\cdots$ (a$_n$+b$_n$)>>} \\quad and \\quad\n\\texttt{a - b := <<(a$_1$-b$_1$) $\\cdots$ (a$_n$-b$_n$)>>}.\n\\\\[0.2cm]\nFor example, if we define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a := <<1 2 3>>; \\ b := <<4 5 6>>;}\n\\\\[0.2cm]\nthen the expressions ``\\texttt{a + b}'' and ``\\texttt{a - b}'' yield the results\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<5.0 7.0 9.0>>} \\quad and \\quad \\texttt{<<-3.0 -3.0 -3.0>>},\n\\\\[0.2cm]\nrespectively.  Additionally, the shortcut assignment operators ``\\texttt{+=}'' and ``\\texttt{-=}''\nare available for vectors.  They work as expected.  Note that for the expressions ``\\texttt{a + b}''\nand ``\\texttt{a - b}'' to be defined, \\texttt{a} and \\texttt{b} have to have \n\\textbf{the same number of elements}. \n\nVectors support \n\\href{http://en.wikipedia.org/wiki/Scalar_multiplication}{\\emph{scalar multiplication}}.  If\n$\\alpha$ is a real number and \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{v = <<v$_1$ $\\cdots$ a$_n$>>}\n\\\\[0.2cm]\nis an $n$-dimensional number, then the scalar products \\texttt{$\\alpha$ * v} and \\texttt{v * $\\alpha$}\nare both defined as the vector\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<($\\alpha$ * v$_1$) $\\cdots$ ($\\alpha$ * v$_n$)>>}.\n\\\\[0.2cm]\nFor example, if \\texttt{a} is defined as above, then the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{1/2 * a}\n\\\\[0.2cm]\nyields the vector\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<0.5 1.0 1.5>>}.\n\\\\[0.2cm]\nIt does not matter whether we multiply the scalar from the left or from the right, so the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a * (1/2)}\n\\\\[0.2cm]\nyields the same result.  We could also have written the previous expression as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a / 2}.\n\\\\[0.2cm]\nIn general, if \\texttt{x} is a vector and $\\alpha$ is a real number, then the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{x / $\\alpha$} \\quad is equivalent to \\quad \n\\texttt{x * (1/$\\alpha$)},\n\\\\[0.2cm]\nHowever, an expression of the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{$\\alpha$ / x}\n\\\\[0.2cm]\nis not defined if \\texttt{x} is a vector.\n\n If \\texttt{v} is a vector and \\texttt{n} is a\nnumber, then the assignment statement\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{v *= n;}\n\\\\[0.2cm]\nis equivalent to the statement\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{v = v * n;}\n\\\\[0.2cm]\nFor two $n$-dimensional vectors\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x} = \\left(\n  \\begin{array}[c]{c}\n  x_1 \\\\\n  \\vdots \\\\\n  x_n    \n  \\end{array}\n\\right)\n$ \n\\quad and \\quad\n$\\vec{y} = \\left(\n  \\begin{array}[c]{c}\n  y_1 \\\\\n  \\vdots \\\\\n  y_n    \n  \\end{array}\n\\right),\n$ \n\\\\[0.2cm]\nthe \\href{http://en.wikipedia.org/wiki/Dot_product}{\\emph{dot product}}, which is also known as the  \n\\emph{scalar product}, is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x} \\cdot \\vec{y} := \\sum\\limits_{i=1}^n x_i \\cdot y_i$.\n\\\\[0.2cm]\nStudents often confuse scalar multiplication and the scalar product.\nTherefore, we have decided to use the same operator for both products:\nIf \\texttt{a} and \\texttt{b} are two vectors of the same dimension, the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a * b}\n\\\\[0.2cm]\nyields their scalar product.  For example,\nusing the definition of \\texttt{a} and \\texttt{b} given above, the expression\n``\\texttt{a * b}''\nyields the result $32$ since\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$1 \\cdot 4 + 2 \\cdot 5 + 3 \\cdot 6 = 32$.\n\\\\[0.2cm]\nFinally, \\setlx\\ supports the \n\\href{http://en.wikipedia.org/wiki/Cross_product}{\\emph{cross product}}.  For two three-dimensional\nvectors \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x} = \\left(\n  \\begin{array}[c]{c}\n  x_1 \\\\\n  x_2 \\\\\n  x_3    \n  \\end{array}\n\\right)\n$ \n\\quad and \\quad\n$\\vec{y} = \\left(\n  \\begin{array}[c]{c}\n  y_1 \\\\\n  y_2 \\\\\n  y_3    \n  \\end{array}\n\\right),\n$ \n\\\\[0.2cm]\nthe cross product $\\vec{x} \\times \\vec{y}$ is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x} = \\left(\n  \\begin{array}[c]{c}\n  x_1 \\\\\n  x_2 \\\\\n  x_3    \n  \\end{array}\n\\right) \\times \\left(\n  \\begin{array}[c]{c}\n  y_1 \\\\\n  y_2 \\\\\n  y_3    \n  \\end{array}\n\\right) = \\left(\n  \\begin{array}[c]{c}\n  x_2 \\cdot y_3 - x_3 \\cdot y_2 \\\\\n  x_3 \\cdot y_1 - x_1 \\cdot y_3 \\\\\n  x_1 \\cdot y_2 - x_2 \\cdot y_1    \n  \\end{array}\n\\right)\n$. \n\\\\[0.2cm]\nIf \\texttt{a} and\n\\texttt{b} are both 3-dimensional vectors, then the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a >< b}\n\\\\[0.2cm]\ncomputes the cross product of \\texttt{a} and \\texttt{b}.  For example, if \\texttt{a} and \\texttt{b}\nare the vectors defined at the beginning of this section, then the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{a >< b}\n\\\\[0.2cm]\nyields the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<-3.0  6.0  -3.0>>}\n\\\\[0.2cm]\nsince we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\left(\n \\begin{array}[c]{l}\n   1 \\\\ 2 \\\\ 3\n \\end{array}\n \\right)\n   \\times\n \\left(\n \\begin{array}[c]{l}\n    4 \\\\ 5 \\\\ 6\n \\end{array}\n \\right)\n    =\n \\left(\n  \\begin{array}[c]{l}\n    2 \\cdot 6 - 3 \\cdot 5 \\\\ 3 \\cdot 4 - 6 \\cdot 1 \\\\ 1 \\cdot 5 - 2 \\cdot 4\n  \\end{array}\n \\right)\n    =\n \\left(\n  \\begin{array}[c]{r}\n    -3 \\\\ 6 \\\\ -3\n  \\end{array}\n \\right)\n$.\n\\\\[0.2cm]\nNote that the cross product of two vectors is only defined iff both \\texttt{a} and \\texttt{b} are \nthree-dimensional.  There are generalisations of the cross product for $n$-dimensional vectors.\nHowever, in that case the cross product is no longer a binary operator but rather takes $n-1$ arguments.\nThese generalisations are not supported in \\setlx.\n\nVectors provide the same access operations as list.  Therefore, to extract the $i$-th component of a\nvector \\texttt{v} we can use the expression ``\\texttt{v[$i$]}''.  Furthermore, the operator\n``\\texttt{\\#}'' returns the dimension of a given vector.  Therefore, given the vector \\texttt{a}\ndefined above, the expression \\texttt{\\#a} returns the value 3.\n\n\n\\section{Matrices}\n\\setlx\\ supports real valued matrices.  The function \\texttt{la\\_matrix} can be used to construct a\nmatrix from a list of list of numbers.  For example, the assignment\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := la\\_matrix([[1,2],[3,4]]);}\n\\\\[0.2cm]\nconstructs a matrix that can be written as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\left(\n\\begin{array}[c]{ll}\n  1 & 2 \\\\\n  3 & 4\n\\end{array}\n\\right)\n$.\n\\\\[0.2cm]\nWe can see that the inner lists used as an argument to the function \\texttt{la\\_matrix} correspond\nto the rows of the resulting matrix.   In \\setlx, the matrix is printed as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<1.0 2.0>> <<3.0 4.0>> >>}.\n\\\\[0.2cm]\nNote that a matrix is written as a list of vectors where instead of the square brackets\n``\\texttt{[}'' and ``\\texttt{]}''  the tokens ``\\texttt{<<}'' and\n``\\texttt{>>}'' are used as opening and closing delimiters.  However, whereas the elements of a list\nare separated by commas, the row vectors making up a matrix are separated by white space.  \nInstead of using the function \\texttt{la\\_matrix} we could have defined the matrix \\texttt{A} using\nthe following command:\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1.0 2.0>> <<3.0 4.0>> >>;}\n\\\\[0.2cm]  \nThe function \\texttt{la\\_matrix} can also be called with a single vector as its argument.  If $v$ is an\n$n$-dimensional vector, then \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_matrix($v$)}\n\\\\[0.2cm]\ninterprets this vector as a column vector and turns it into an $n \\times 1$ matrix.  For example, \nthe statement \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := la\\_matrix(<<1 2 3>>);}\n\\\\[0.2cm]\nyields the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<1.0>> <<2.0>> <<3.0>> >>}.\n\\\\[0.2cm]\nThis result shows that \\texttt{A} is a matrix that consists of three rows that are themselves\nvectors of length 1.\n\nSimilar to vectors, matrices can be added and subtracted using the operators ``\\texttt{+}'' and\n``\\texttt{-}''.   If we define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1 2>> <<3 4>> >>;} \\quad and \\quad \\texttt{B := << <<5 6>> <<7 8>> >>;}   \n\\\\[0.2cm]\nthen the expressions ``\\texttt{A + B}'' and ``\\texttt{A - B}'' work componentwise and yield the\nresults \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<6.0 8.0>> <<10.0 12.0>> >>} \\quad and \\quad \n\\texttt{<< <<-4.0 -4.0>> <<-4.0 -4.0>> >>}.\n\\\\[0.2cm]\nIn addition to ``\\texttt{+}'' and ``\\texttt{-}'', the assignment operators ``\\texttt{+=}'' and\n``\\texttt{-=}'' are supported for matrices and work as expected.\n\nFurthermore, matrices support scalar multiplication in the same way as vectors.  For example, if the\nmatrix \\texttt{A} is defined as above, then the expressions \n``\\texttt{2 * A}'' and ``\\texttt{A * 2}'' both yield the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<2.0 4.0>> <<6.0 8.0>> >>}.\n\\vspace*{0.2cm} \n\nNext,\n\\setlx\\ supports \\href{http://en.wikipedia.org/wiki/Matrix_multiplication}{matrix multiplication}.\nIf\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n $\\texttt{A} = (\\mathtt{a}_{i,j})_{1 \\leq i \\leq m \\atop 1 \\leq j \\leq n}$ \\quad is an $m \\times n$ matrix \n\\\\\nand\n\\\\\n\\hspace*{1.3cm}\n$\\texttt{B} = (\\mathtt{b}_{j,l})_{1 \\leq j \\leq n \\atop 1 \\leq l \\leq k}$ \\quad is an $n \\times k$ matrix, \n\\\\[0.2cm]\nthen the matrix product \\texttt{A * B} is defined as the matrix\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\Bigl(\\sum\\limits_{j=1}^n \\texttt{a}_{i,j}\\cdot \\texttt{b}_{j,l}\\Bigr)_{1 \\leq i \\leq n \\atop 1 \\leq l \\leq k}$.\n\\\\[0.2cm]\nFor example, given the definitions of\n\\texttt{A} and \\texttt{B} shown above,  the expression ``\\texttt{A * B}'' yields the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<19.0 22.0>> <<43.0 50.0>> >>}.\n\\\\[0.2cm]\nFurthermore, if \\texttt{A} is an $m \\times n$ matrix and \\texttt{v} is an $n$ dimensional vector,\nthen the expression \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A * v}\n\\\\[0.2cm]\nis computed as a matrix multiplication, where $v$ is interpreted as an $n \\times 1$ matrix.  In\nthis case, the resulting $m \\times 1$ matrix is then automatically converted back into an $m$ dimensional vector.\nFor example, if we define the matrix \\texttt{A} as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1 2>> <<3 4>> >>;}\n\\\\[0.2cm]\nand the vector \\texttt{x} is defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{x := <<5 6>>;}\n\\\\[0.2cm]\nthen evaluating the product \\texttt{A * x} yields the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<17.0 39.0>>}\n\\\\[0.2cm]\nsince we have\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$1 \\cdot 5 + 2 \\cdot 6 = 17$ \\quad and \\quad $3 \\cdot 5 + 4 \\cdot 6 = 39$.\n\\\\[0.2cm]\nIn addition to matrix multiplication, \\setlx\\ also support exponentiation of a square matrix by an\ninteger number.  For example, \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A ** 2;}\n\\\\[0.2cm]\nreturns the square  of \\texttt{A}, while \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A ** -1}\n\\\\[0.2cm]\nreturn the \\href{http://en.wikipedia.org/wiki/Invertible_matrix}{\\emph{inverse}} of a matrix,\nprovided the matrix is not \\emph{singular}.  If the matrix \\texttt{A} is singular, evaluation of the\nexpression \\texttt{A ** $n$} raises an exception if the exponent $n$ is negative.\n\nMatrices can be \\href{http://en.wikipedia.org/wiki/Transpose}{\\emph{transposed}} via the postfix\noperator ``\\texttt{!}''.  For example, using the definition of the matrix \\texttt{A} shown above,\nthe expression ``\\texttt{A!}'' yields \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<< <<1.0 3.0>> <<2.0 4.0>> >>}.\n\\\\[0.2cm]\nIf \\texttt{A} is an $m \\times n$ matrix, the expression ``\\texttt{\\#A}'' yields the dimension $m$.  \nIn order to compute the dimension $n$, we can use the expression \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{\\#A[1]}.\n\\\\[0.2cm]\nThe reason is that \\texttt{A[1]} returns the first row of the matrix \\texttt{A} as a list and the\nlength of this list is the dimension $n$.  In order to access the element in row $i$ and column $j$\nof matrix \\texttt{A} we can use the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A[$i$][$j$]}.\n\n\\section{Numerical Methods for Matrices and Vectors}\nIn this section we will discuss the numerical methods that are provided.  These methods are inherited\nfrom \\href{http://math.nist.gov/javanumerics/jama/}{\\textsl{Jama}}, which is a \\textsl{Java} matrix\npackage.  The names of all methods inherited from \\textsl{Jama} start with ``\\texttt{la\\_}''.  This\nis short for \\underline{l}inear \\underline{a}lgebra.\n\n\\subsection{Computing the Determinant}\nIf \\texttt{A} is a square matrix, the expression \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_det(A)}\n\\\\[0.2cm]\ncomputes the \\href{http://en.wikipedia.org/wiki/Determinant}{\\emph{determinant}} of \\texttt{a}.\nFor example, if we define \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1 2>> <<3 4>> >>;}\n\\\\[0.2cm]\nthen the expression ``\\texttt{la\\_det(A)}'' yields the result $-2$.  The determinant can be used to\ncheck whether a matrix is invertible as a matrix is invertible if and only if the determinant\nis different from $0$.  However, note that due to rounding errors the result of the expression \n``\\texttt{la\\_det(A)}''  might be a small non-zero number even if the matrix \\texttt{A} really is\nsingular. \n\n\\subsection{Solving a System of Linear Equations}\nA system of linear equations of the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\texttt{A} \\cdot \\texttt{x} = \\texttt{b}$\n\\\\[0.2cm]\nwhere \\texttt{A} is a square matrix $n \\times n$  matrix and  \\texttt{b} is an $n$-dimensional\nvector can be solved using the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_solve(A, b)}.\n\\\\[0.2cm]\nFor example, to solve the system of equations\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\begin{array}[c]{lcl}\n  1 \\cdot x + 2 \\cdot y & = & 5 \\\\[0.1cm]\n  3 \\cdot x + 4 \\cdot y & = & 6 \n\\end{array}\n$\n\\\\[0.2cm]\nwe define\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1 2>> <<3 4>> >>;} \\quad and \\quad \\texttt{b := <<5 6>>;}\n\\\\[0.2cm]\nThen, the solution is computed via the expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_solve(A, b)}.\n\\\\[0.2cm]\nNote that this expression throws an exception if the given system of equations is not solvable.\n\nNote that it is also posible to solve a system of equations that is \n\\href{http://en.wikipedia.org/wiki/Overdetermined_system}{\\emph{overdetermined}}.  For example,\nassume that the system of equations is given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\n\\begin{array}[c]{lcl}\n  1 \\cdot x + 2 \\cdot y & = & 1 \\\\[0.1cm]\n  2 \\cdot x + 3 \\cdot y & = & 2 \\\\[0.1cm]\n  3 \\cdot x + 4 \\cdot y & = & 3 \n\\end{array}\n$\n\\\\[0.2cm]\nIn order to compute the solution $\\vec{x}$ that minimizes the error\n $\\|a \\cdot \\vec{x} - \\vec{b}\\|_2$ we can \ndefine \\texttt{A} and \\texttt{b} via\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{A := << <<1 2>> <<2 3>> <<3 4>> >>;} \\quad and \\quad \\texttt{b := <<1 2 3>>;}\n\\\\[0.2cm]\nand then call  the function \\texttt{la\\_solve} as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_solve(A, b);}\n\\\\[0.2cm]\nIn this case, \\texttt{la\\_solve} computes the result\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{<<0.9999999999999982 1.4430967688835178E-15>>}\n\\\\[0.2cm]\nwhich is pretty close to the exact result $\\left(\\begin{array}[c]{l} 1 \\\\ 0 \\end{array}\\right)$.\n\\vspace*{0.3cm}\n\n\\noindent\nWhen solving a system of linear equations, care has to be taken that the solution is well defined.\nTo this end, \\setlx\\ provides the function \\texttt{la\\_cond} that computes the \n\\href{http://en.wikipedia.org/wiki/Condition_number}{condition number} of a given matrix.\nLet us describe the problem via an example borrowed from\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\href{http://nm.mathforcollege.com/mws/gen/04sle/mws_gen_sle_spe_adequacy.pdf}{\\texttt{http://nm.mathforcollege.com/mws/gen/04sle/mws\\_gen\\_sle\\_spe\\_adequacy.pdf}}.\n\\\\[0.2cm]\nAssume the matrix $A$ and the vector $\\vec{b}$ are defined as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$A := \\left(\n  \\begin{array}[c]{ll}\n    1.000 &  2.000 \\\\\n    2.000 &  3.999\n  \\end{array}\n  \\right)\n$  \\quad and \\quad\n$\\vec{b} := \\left(\n  \\begin{array}[c]{l}\n    4.000 \\\\ 7.999\n  \\end{array}\n  \\right).\n$\n\\\\[0.2cm]\nIt can easily be verified that the solution $\\vec{x}$ to the system of equations \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{b} = A \\cdot \\vec{x}$\n\\\\[0.2cm]\nis given as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x}  = \n \\left(\n   \\begin{array}[c]{l}\n     2 \\\\ 1\n   \\end{array}\n  \\right)\n$.\n\\\\[0.2cm]\nHowever, let us assume that the vector $\\vec{b}$ is distorted into the vector $\\vec{c}$ that is\ngiven as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{c} := \\left(\n  \\begin{array}[c]{l}\n    4.001 \\\\ 7.998\n  \\end{array}\n  \\right).\n$\n\\\\[0.2cm]\nIf we solve the system\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{c} = A \\cdot \\vec{x}$,\n\\\\[0.2cm]\nthe solution for $\\vec{x}$ becomes\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\vec{x}  = \n \\left(\n   \\begin{array}[c]{r}\n     -3.999 \\\\ 4.000\n   \\end{array}\n  \\right)\n$.\n\\\\[0.2cm]\nWe see that a tiny change in the right hand side of the system of equations has caused a big change\nin the solution $\\vec{x}$.  The reason is that the matrix \\texttt{A} is \\emph{ill-conditioned}.\nWe can verify this using the function \\texttt{la\\_cond}:  The expression\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_cond(<< <<1.000 2.000>> <<2.000 3.999>> >>);}\n\\\\[0.2cm]\nyields the result \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{24992.000959995028}.\n\\\\[0.2cm]\nThis shows that small errors in the right hand side of a system of linear equations involving the\nmatrix \\texttt{A} are multiplied by a factor of nearly $25\\,000$.  Our recommendation is that if you\never have to solve a system of equations, you should first check whether the system is\nwell-conditioned by computing the condition number of the matrix associated with the system.  This \ncondition number tells us by how much an error in the right hand side of the system of equations is\nmagnified when we compute the solution.  In particular, if the condition number is so big that it\nwill magnify known uncertainties in  the right hand side of the equations to an extend that the\nresult is meaningless, then it is not possible to solve the given system of equations in a meaningful\nway. \n\n\n\\subsection{The Singular Value Decomposition and the Pseudo-Inverse}\nThe function \\texttt{la\\_svd} can be used to compute the \n\\href{http://en.wikipedia.org/wiki/Singular_value_decomposition}{\\emph{singular value decomposition}} \nof a given matrix \\texttt{A}.  For a given $m \\times n$ matrix \\texttt{A}, the expression \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_svd(A)}\n\\\\[0.2cm]\nreturns a list of the form\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{[U, S, V]}\n\\\\[0.2cm]\nwhere \\texttt{U} is an \n\\href{http://en.wikipedia.org/wiki/Orthogonal_matrix}{orthogonal} $m \\times m$ matrix, \\texttt{S}\nis an $m \\times n$ \n\\href{http://en.wikipedia.org/wiki/Diagonal_matrix}{diagonal matrix}, and \\texttt{V} is an $n \\times n$\northogonal matrix such that\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$A = U \\cdot S \\cdot V^{\\mathtt{T}}$,\n\\\\[0.2cm]\nwhere $V^{\\mathtt{T}}$ denotes the transpose of the matrix $V$.\n  In practice, the singular value decomposition is often used to compute the\n\\href{http://en.wikipedia.org/wiki/Moore-Penrose_pseudoinverse}{\\emph{pseudo-inverse}}\n of a singular matrix.   However, this can be done directly as for a matrix \\texttt{A} the call\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_pseudoInverse(A);}\n\\\\[0.2cm]\ncomputes the pseudo-inverse of \\texttt{A}.\n\n\\subsection{Eigenvalues and Eigenvectors}\nIn order to compute the \n\\href{http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors}{eigenvalues and eigenvectors} of a\nsquare matrix, \\setlx\\ provides the functions\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_eigenValues} \\quad and \\quad \\texttt{la\\_eigenVectors}.\n\\\\[0.2cm]\nBoth of these function take a single argument \\texttt{A}, where \\texttt{A} must be a square matrix.\nThe function \\texttt{la\\_eigenValues} returns a list of the eigenvalues of \\texttt{A}.  The\nfunction call \\texttt{la\\_eigenVectors(a)} returns a list of the eigenvectors of the matrix \\texttt{A}.\nFor example, in order to compute the eigenvalues and eigenvectors of the matrix\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\mathtt{A} :=\n\\left(\\begin{array}[c]{ll}\n  1 & 2 \\\\\n  2 & 3\n\\end{array}\\right)\n$\n\\\\[0.2cm]\nwe can execute the following commands:\n\n\\begin{Verbatim}[ frame         = lines, \n                  framesep      = 0.3cm, \n                  firstnumber   = 1,\n                  labelposition = bottomline,\n                  numbers       = left,\n                  numbersep     = -0.2cm,\n                  xleftmargin   = 0.8cm,\n                  xrightmargin  = 0.8cm,\n                ]\n    A        := << <<1 2>> <<2 3>> >>;\n    [l1, l2] := la_eigenValues(a);\n    [x1, x2] := la_eigenVectors(a);\n\\end{Verbatim}\n\nThen, the eigenvalues will be computed as\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{l1 = -0.23606797749978958} \\quad and \\quad \\texttt{l2 = 4.23606797749979}\n\\\\[0.2cm]\nIn this case, the exact values of these eigenvalues are \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n$\\mathtt{l1} = 2 - \\sqrt{5}$ \\quad and \\quad $\\mathtt{l2} = 2 + \\sqrt{5}$.\n\\\\[0.2cm]\nThe eigenvectors are computed as \n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{x1 = <<-0.8506508083520399 0.5257311121191336>>} \\quad and \\\\\n\\hspace*{1.3cm}\n\\texttt{x2 = <<0.5257311121191336 0.8506508083520399>>}.\n\\\\[0.2cm]\nThe eigenvectors computed are \\emph{normalized}, that is the length of these vectors is $1$.\nFurthermore, as the matrix \\texttt{A} happens to be symmetric, i.e.~we have \\texttt{A = A!},\nthe eigenvectors are orthogonal to each other.\n\nObserve that not every square $n \\times n$ matrix is \n\\href{http://en.wikipedia.org/wiki/Diagonalizable_matrix}{\\emph{diagonalizable}}\nand hence has $n$ different eigenvectors.  In case the matrix is not diagonalizable in the real\nnumbers, the functions \\texttt{la\\_eigenValues} and \\texttt{la\\_eigenVectors} both throw an\nexception.  Note, however, that every \n\\href{http://en.wikipedia.org/wiki/Symmetric_matrix}{\\emph{symmetric}} matrix is diagonalizable.\nTherefore, if the matrix \\texttt{A} is symmetric, neither of the two calls\n\\\\[0.2cm]\n\\hspace*{1.3cm}\n\\texttt{la\\_eigenValues(A)} \\quad or \\quad \\texttt{la\\_eigenVectors(A)}\n\\\\[0.2cm]\nwill throw an exception.\n\n\n%%% Local Variables: \n%%% mode: latex\n%%% TeX-master: \"tutorial.tex\"\n%%% End: \n\n\n\n", "meta": {"hexsha": "5475bff71bfe616dfedca0e7a7c1351593c29698", "size": 24465, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Tutorial/linear-algebra.tex", "max_stars_repo_name": "leonmutschke/setlX", "max_stars_repo_head_hexsha": "a10333405cba3d9d814d7de9e160561bd5fa4f76", "max_stars_repo_licenses": ["BSD-3-Clause"], "max_stars_count": 28, "max_stars_repo_stars_event_min_datetime": "2015-01-14T11:12:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T21:06:05.000Z", "max_issues_repo_path": "Tutorial/linear-algebra.tex", "max_issues_repo_name": "leonmutschke/setlX", "max_issues_repo_head_hexsha": "a10333405cba3d9d814d7de9e160561bd5fa4f76", "max_issues_repo_licenses": ["BSD-3-Clause"], "max_issues_count": 6, "max_issues_repo_issues_event_min_datetime": "2016-08-01T14:21:37.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-03T17:15:00.000Z", "max_forks_repo_path": "Tutorial/linear-algebra.tex", "max_forks_repo_name": "leonmutschke/setlX", "max_forks_repo_head_hexsha": "a10333405cba3d9d814d7de9e160561bd5fa4f76", "max_forks_repo_licenses": ["BSD-3-Clause"], "max_forks_count": 18, "max_forks_repo_forks_event_min_datetime": "2015-02-11T21:10:18.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-02T07:41:41.000Z", "avg_line_length": 32.62, "max_line_length": 165, "alphanum_fraction": 0.6636419375, "num_tokens": 9012, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.89181104831338, "lm_q2_score": 0.8418256532040707, "lm_q1q2_score": 0.7507494182810182}}
{"text": "\\lab{K-Means Clustering}{K-Means Clustering}\n\\objective{Clustering is the one of the main tools in unsupervised learning---machine learning problems where the data comes without labels.\nIn this lab we implement the k-means algorithm, a simple and popular clustering method, and apply it to geographic clustering and color quantization.\n}\n\n\\section*{Clustering}\n\nPreviously, we analyzed the iris dataset from \\li{sklearn} using PCA; we have reproduced the first two principal components of the iris data in Figure \\ref{fig:iris_data}.\nUpon inspection, a human can easily see that there are two very distinct groups of irises.\nCan we create an algorithm to identify these groups without human supervision?\nThis task is called \\emph{clustering}, an instance of \\emph{unsupervised learning}.\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=.7\\textwidth]{iris_pca.pdf}\n\\caption{The first two principal components of the iris dataset.}\n\\label{fig:iris_data}\n\\end{figure}\n\nThe objective of clustering is to find a partition of the data such that points in the same subset will be ``close'' according to some metric.\nThe metric used will likely depend on the data, but some obvious choices include Euclidean distance and angular distance.\nThroughout this lab we will use the metric $d(x,y) = \\|x-y\\|_2$, the Euclidean distance between $x$ and $y$.\n\nMore formally, suppose we have a collection of $\\mathbb{R}^K$-valued observations $X = \\{x_1,x_2,\\ldots,x_n\\}$.\nLet $N \\in \\mathbb{N}$ and let $\\mathcal{S}$ be the set of all $N$-partitions of $X$, where an $N$-partition is a partition with exactly $N$ nonempty elements.\nWe can represent a typical partition in $\\mathcal{S}$ as $S = \\{S_1,S_2,\\ldots,S_N\\}$, where\n\\[\nX = \\bigcup_{i=1}^N S_i\n\\]\nand\n\\[\n|S_i| > 0, \\qquad i=1,2,\\ldots,N.\n\\]\nWe seek the $N$-partition $S^*$ that minimizes the within-cluster sum of squares, i.e.\n\\[\nS^* = \\underset{S\\in\\mathcal{S}}{\\arg\\min} \\sum_{i=1}^N\\sum_{x_j\\in S_i}\\|x_j-\\mu_i\\|_2^2,\n\\]\nwhere $\\mu_i$ is the mean of the elements in $S_i$, i.e.\n\\[\n\\mu_i = \\frac{1}{|S_i|}\\sum_{x_j\\in S_i}x_j.\n\\]\n\n\\subsection*{The K-Means Algorithm}\n\nFinding the global minimizing partition $S^*$ is generally intractable since the set of partitions can be very large indeed,\nbut the \\emph{k-means} algorithm is a heuristic approach that can often provide reasonably accurate results.\n\n\nWe begin by specifying an initial cluster mean $\\mu_i^{(1)}$ for each $i = 1, \\cdots, N$ (this can be done by random initialization, or according to some heuristic).\nFor each iteration, we adopt the following procedure.\nGiven a current set of cluster means $\\mu^{(t)}$, we find a partition $S^{(t)}$ of the observations such that\n\\begin{equation*}\nS_{i}^{(t)} = \\{x_j \\; : \\; \\|x_j - \\mu_{i}^{(t)}\\|_2^2 \\leq \\|x_j - \\mu_{l}^{(t)}\\|_2^2,\\,\\,\\,  l = 1, \\cdots, N\\}.\n\\end{equation*}\nWe then update our cluster means by computing for each $i = 1, \\cdots, N$.\nWe continue to iterate in this manner until the partition ceases to change.\n\n\nFigure \\ref{fig:iris_clusterings} shows two different clusterings of the iris data produced by the \\emph{k-means} algorithm.\nNote that the quality of the clustering can depend heavily on the initial cluster means.\nWe can use the within-cluster sum of squares as a measure of the quality of a clustering (a lower sum of squares is better).\nWhere possible, it is advisable to run the clustering algorithm several times, each with a different initialization of the means,\nand keep the best clustering.\nNote also that it is possible to have very slow convergence.\nThus, when implementing the algorithm, it is a good idea to terminate after some specified maximum number of iterations.\n%\n\\begin{figure}[h]\n    \\centering\n    \\begin{tabular}{cc}\n    \\includegraphics[width=.49\\textwidth]{iris_means_1.pdf} &\n    \\includegraphics[width=.49\\textwidth]{iris_means_2.pdf}\n    \\end{tabular}\n    \\caption{Two different K-Means clusterings for the iris dataset.\n            Notice that the clustering on the left predicts the flower species to a high degree of accuracy,\n            while the clustering on the right is less effective.}\n    \\label{fig:iris_clusterings}\n\\end{figure}\n%\nThe algorithm can be summarized as follows.\n\\begin{enumerate}\n    \\item Choose $k$ initial cluster centers.\n    \\item For $i=0,\\ \\ldots,$\\ \\li{max_iter},\n    \\begin{enumerate}\n        \\item Assign each data point to the cluster center that is closest, forming $k$ clusters.\n        \\item Recompute the cluster centers as the means of the new clusters.\n        \\item If the old cluster centers and the new cluster centers are sufficiently close, terminate early.\n    \\end{enumerate}\n\\end{enumerate}\n\n\\begin{problem}\nWrite a \\li{KMeans} class for doing basic $k$-means clustering.\nImplement the following methods, following \\li{sklearn} class conventions.\n\\begin{enumerate}\n\\item \\li{__init__()}: Accept a number of clusters $k$, a maximum number of iterations, and a convergence tolerance.\nStore these as attributes.\n\n\\item \\li{fit()}: Accept an $m \\times n$ matrix $X$ of $m$ data points with $n$ features.\nChoose $k$ random rows of $X$ as the initial cluster centers.\nRun the $k$-means iteration until consecutive centers are within the convergence tolerance, or until iterating the maximum number of times.\nSave the cluster centers as attributes.\n\nIf a cluster is empty, reassign the cluster center as a random row of $X$.\n\n\\item \\li{predict()}: Accept an $l \\times n$ matrix $X$ of data.\nReturn an array of $l$ integers where the $i$th entry indicates which cluster center the $i$th row of $X$ is closest to.\n\\end{enumerate}\n%\nTest your class on the iris data set after reducing the data to two principal components.\nPlot the data, coloring by cluster.\n\\end{problem}\n\n\\section*{Detecting Active Earthquake Regions} % ==============================\n\nSuppose we are interested in learning about which regions are prone to experience frequent earthquake activity.\nWe could make a map of all earthquakes over a given period of time and examine it ourselves, but this, as an unsupervised learning problem, can be solved using our $k$-means clustering tool.\n\n% % Old approach (required students to parse 6 files for some reason).\n% These files contain a lot of information which isn't of interest to us at the present time; all we would like to extract from them is the location of each earthquake, which appears in characters $21$ through $33$ of each line.\n% Characters $21$ through $26$ contain the latitude of each epicenter, character $26$ denoting North or South, and characters $27$ through $33$ contain the longitude of each epicenter, character $33$ denoting East or West.\n% We need to divide each value by $1,000$ to represent these as degrees and decimals.\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{earthquakes.png}\n    \\caption{Earthquake epicenters over a 6 month period.}\n    \\label{fig:earthquakes}\n\\end{figure}\n\nThe file \\texttt{earthquake\\_coordinates.npy} contains earthquake data throughout the world from January 2010 through June 2010.\nEach row represents a different earthquake; the columns are scaled longitude and latitude measurements.\nWe want to cluster this data into active earthquake regions.\nFor this task, we might think that we can regard any epicenter as a point in $\\mathbb{R}^{2}$ with coordinates being their latitude and longitude.\nThis, however, would be incorrect, because the earth is not flat.\nInstead, latitude and longitude should be viewed in \\emph{spherical coordinates} in $\\mathbb{R}^{3}$, which could then be clustered.\n\nA simple way to accomplish this transformation is to first transform the latitude and longitude values to spherical coordinates, and then to Euclidean coordinates.\nRecall that a spherical coordinate in $\\mathbb{R}^3$ is a triple $(r,\\theta,\\varphi)$, where $r$ is the distance from the origin, $\\theta$ is the radial angle in the $xy$-plane from the $x$-axis, and $\\varphi$ is the angle from the $z$-axis.\nIn our earthquake data, once the longitude is converted to radians it is an appropriate $\\theta$ value; the latitude needs to be offset by $90^\\circ$ degrees, then converted to radians to obtain $\\varphi$.\nFor simplicity, we can take $r=1$, since the earth is roughly a sphere.\nWe can then transform to Euclidean coordinates using the following relationships.\n\\[\n\\theta = \\frac{\\pi}{180}\\left(\\text{longitude}\\right)\n\\qquad\n\\varphi = \\frac{\\pi}{180}\\left(90 - \\text{latitude}\\right)\n\\]\n\\begin{align*}\nr & = \\sqrt{x^{2} + y^{2} + z^{2}} & x & = r \\sin \\varphi \\cos \\theta \\\\\n\\varphi & = \\arccos \\frac{z}{r} & y & = r \\sin \\varphi \\sin \\theta \\\\\n\\theta & = \\arctan \\frac{y}{x} & z & = r \\cos \\varphi\n\\end{align*}\n\nThere is one last issue to solve before clustering.\nEach earthquake data point has norm 1 in Euclidean coordinates, since it lies on the surface of a sphere of radius 1.\nTherefore, the cluster centers should also have norm 1.\nOtherwise, the means can't be interpreted as locations on the surface of the earth, and the \\emph{k-means} algorithm will struggle to find good clusters.\nA solution to this problem is to normalize the mean vectors at each iteration, so that they are always unit vectors.\n\n\\begin{problem}\nAdd a keyword argument \\li{normalize=False} to your \\li{KMeans} constructor.\nModify \\li{fit()} so that if \\li{normalize} is \\li{True}, the cluster centers are normalized at each iteration.\n\nCluster the earthquake data in three dimensions by converting the data from raw data to spherical coordinates to euclidean coordinates on the sphere.\n\\begin{enumerate}\n\\item Convert longitude and latitude to radians, then to spherical coordinates.\n\\\\(Hint: \\li{np.deg2rad()} may be helpful.)\n\\item Convert the spherical coordinates to euclidean coordinates in $\\mathbb{R}^3$.\n\\item Use your \\li{KMeans} class with normalization to cluster the euclidean coordinates.\n\\item Translate the cluster center coordinates back to spherical coordinates, then to degrees.\nTransform the cluster means back to latitude and longitude coordinates.\n\\\\(Hint: use \\li{numpy.arctan2()} for $\\arctan$, so that that correct quadrant is chosen).\n\\item Plot the data, coloring by cluster.\nAlso mark the cluster centers.\n\\end{enumerate}\nWith 15 clusters, your plot should resemble the Figure \\ref{fig:earthquakeclusters}.\n\\end{problem}\n\n\\begin{figure}[H]\n    \\centering\n    \\includegraphics[width=.7\\textwidth]{earthquake_clusters.png}\n    \\caption{Earthquake epicenter clusters with $k = 15$.}\n    \\label{fig:earthquakeclusters}\n\\end{figure}\n\n\\begin{comment}\nThough plotting our results in two dimensions gives us a good picture, we can see that this is not entirely accurate.  There are points that appear to be closer to a different cluster center than the one to which they belong.  This comes from viewing the results in only two dimensions.  When viewing in three dimensions, we can see more clearly the accuracy of our results.\n\\begin{problem}\nAdd a keyword argument \\li{3d=False} to your \\li{kmeans} function, and add code to show the three-dimensional plot instead of the two-dimensional scatter plot should this argument be set to \\li{True}.  Maintain the same color-coding scheme as before.  Use \\li{mpl_toolkits.mplot3d.Axes3D} to make your plot.\n\\end{problem}\n\\end{comment}\n\n\\section*{Color Quantization} % ===============================================\n\nThe $k$-means algorithm uses the euclidean metric, so it is natural to cluster geographic data.\nHowever, clustering can be done in any abstract vector space.\nThe following application is one example.\n\nImages are usually represented on computers as $3$-dimensional arrays.\nEach $2$-dimensional layer represents the red, green, and blue color values, so each pixel on the image is really a vector in $\\mathbb{R}^3$.\nClustering the pixels in $RGB$ space leads a one kind of image segmentation that facilitate memory reduction.\n\nReading: \\url{https://en.wikipedia.org/wiki/Color_quantization}\n\n\\begin{problem}\nWrite a function that accepts an image array (of shape $(m,n,3)$), an integer number of clusters $k$, and an integer number of samples $S$.\nReshape the image so that each row represents a single pixel.\nChoose $S$ pixels to train a $k$-means model on with $k$ clusters.\nMake a copy of the original picture where each pixel has the same color as its cluster center.\nReturn the new image.\nFor this problem, you may use \\li{sklearn.cluster.KMeans} instead of your \\li{KMeans} class from Problem 1.\n\nTest your function on some of the provided NASA images.\n\\end{problem}\n\n\\newpage\n\n\\section*{Additional Material} % ==============================================\n\n\\subsection*{Spectral Clustering}\nWe now turn to another method for solving a clustering problem, namely that of Spectral Clustering.  As you can see in Figure ???, it can cluster data not just by its location on a graph, but can even separate shapes that overlap others into distinct clusters.  It does so by utilizing the spectral properties of a Laplacian matrix.  Different types of Laplacian matrices can be used.  In order to construct a Laplacian matrix, we first need to create a graph of vertices and edges from our data points.  This graph can be represented as a symmetric matrix $W$ where $w_{ij}$ represents the edge from $x_i$ to $x_j$.  In the simplest approach, we can set $w_{ij} = 1$ if there exists an edge and $w_{ij} = 0$ otherwise.  However, we are interested in the similarity of points, so we will weight the edges by using a \\emph{similarity measure}.  Points that are similar to one another are assigned a high similarity measure value, and dissimilar points a low value.  One possible measure is the \\emph{Gaussian similarity function}, which defines the similarity between distinct points $x_i$ and $x_j$ as\n\\begin{equation*}\ns(x_i,x_j) = e^{- \\frac{\\| x_i - x_j \\| ^2}{2 \\sigma ^2}}\n\\end{equation*}\nfor some set value $\\sigma$.\n\nNote that some similarity functions can yield extremely small values for dissimilar points.  We have several options for dealing with this possibility.  One is simply to set all values which are less than some $\\epsilon$ to be zero, entirely erasing the edge between these two points.  Another option is to keep only the $T$ largest-valued edges for each vertex.  Whichever method we choose to use, we will end up with a weighted \\emph{similarity matrix} $W$.  Using this we can find the diagonal \\emph{degree matrix} $D$, which gives the number of edges found at each vertex.  If we have the original fully-connected graph, then $D_{ii} = n-1$ for each $i$.  If we keep the $T$ highest-valued edges, $D_{ii} = T$ for each $i$.\n\nAs mentioned before, we may use different types of Laplacian matrices.  Three such possibilities are:\n\\begin{enumerate}\n    \\item The \\emph{unnormalized Laplacian}, $L = D - W$\n    \\item The \\emph{symmetric normalized Laplacian}, $L_{sym} = I - D^{-1/2}WD^{-1/2}$\n    \\item The \\emph{random walk normalized Laplacian}, $L_{rw} = I - D^{-1}W$.\n \\end{enumerate}\n\nGiven a similarity measure, which type of Laplacian to use, and the desired number of clusters $k$, we can now proceed with the Spectral Clustering algorithm as follows:\n\n\\begin{itemize}\n    \\item Compute $W$, $D$, and the appropriate Laplacian matrix.\n    \\item Compute the first $k$ eigenvectors $u_1, \\cdots , u_k$ of the Laplacian matrix.\n    \\item Set $U = [u_1, \\cdots , u_k]$, and if using $L_{sym}$ or $L_{rw}$ normalize $U$ so that each row is a unit vector in the Euclidean norm.\n    \\item Perform $k$-means clustering on the $n$ rows of $U$.\n    \\item The $n$ labels returned from your \\li{kmeans} function correspond to the label assignments for $x_1, \\cdots, x_n$.\n\\end{itemize}\n\nAs before, we need to run through our $k$-means function multiple times to find the best measure when we use random initialization.  Also, if you normalize the rows of $U$, then you will need to set the argument \\li{normalize = True}.\n\n\\begin{problem}\nImplement the Spectral Clustering Algorithm by calling your \\li{kmeans} function, using the following function declaration:\n\\begin{lstlisting}\ndef specClus(measure,Laplacian,args,arg1=None,kiters=10):\n    \"\"\"\n    Cluster a dataset using the k-means algorithm.\n\n    Parameters\n    ----------\n    measure : function\n        The function used to calculate the similarity measure.\n    Laplacian : int in {1,2,3}\n        Which Laplacian matrix to use. 1 corresponds to the unnormalized,\n        2 to the symmetric normalized, 3 to the random walk normalized.\n    args : tuple\n        The arguments as they were passed into your k-means function,\n        consisting of (data, n_clusters, init, max_iter, normalize). Note\n        that you will not pass 'data' into your k-means function.\n    arg1 : None, float, or int\n        If Laplacian==1, it should remain as None\n        If Laplacian==2, the cut-off value, epsilon.\n        If Laplacian==3, the number of edges to retain, T.\n    kiters : int\n        How many times to call your kmeans function to get the best\n        measure.\n\n    Returns\n    -------\n    labels : ndarray of shape (n,)\n        The i-th entry is an integer in [0,n_clusters-1] indicating\n        which cluster the i-th row of data belongs to.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n\nWe now need a way to test our code.  The website http://cs.joensuu.fi/sipu/datasets/ contains many free data sets that will be of use to us.  Scroll down to the ``Shape sets\" heading, and download some of the datasets found there to use for trial datasets.\n\\begin{problem}\nCreate a function that will return the accuracy of your spectral clustering implementation, as follows:\n\\begin{lstlisting}\ndef test_specClus(location,measure,Laplacian,args,arg1=None,kiters=10):\n    \"\"\"\n    Cluster a dataset using the k-means algorithm.\n\n    Parameters\n    ----------\n    location : string\n        The location of the dataset to be tested.\n    measure : function\n        The function used to calculate the similarity measure.\n    Laplacian : int in {1,2,3}\n        Which Laplacian matrix to use. 1 corresponds to the unnormalized,\n        2 to the symmetric normalized, 3 to the random walk normalized.\n    args : tuple\n        The arguments as they were passed into your k-means function,\n        consisting of (data, n_clusters, init, max_iter, normalize). Note\n        that you will not pass 'data' into your k-means function.\n    arg1 : None, float, or int\n        If Laplacian==1, it should remain as None\n        If Laplacian==2, the cut-off value, epsilon.\n        If Laplacian==3, the number of edges to retain, T.\n    kiters : int\n        How many times to call your kmeans function to get the best\n        measure.\n\n    Returns\n    -------\n    accuracy : float\n        The percent of labels correctly predicted by your spectral\n        clustering function with the given arguments (the number\n        correctly predicted divided by the total number of points.\n    \"\"\"\n    pass\n\\end{lstlisting}\n\\end{problem}\n", "meta": {"hexsha": "f62b844977290773ae31f9fb645e00ede2446d21", "size": 18891, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Volume3/KMeans/kmeans.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/KMeans/kmeans.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/KMeans/kmeans.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": 59.034375, "max_line_length": 1101, "alphanum_fraction": 0.7337356413, "num_tokens": 4821, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256551882382, "lm_q2_score": 0.8918110425624792, "lm_q1q2_score": 0.7507494152092649}}
{"text": "\\documentclass[../main.tex]{subfiles}\n\n\\begin{document}\n        \\section{Curves \\& Arc Length}\n        \\begin{definition}{Smoothness}{}\n                A vector valued function \\(\\vec{r}(t)\\) is \\emph{smooth} on an interval \\((a,b)\\) if \\(\\vec{r}'(t)\\) exists \\emph{and} \\(\\vec{r}'(t)\\neq\\vec{0}\\) on the interval.\n        \\end{definition}\n        In the above definition, the case where \\(\\vec{r}'(t)=\\vec{0}\\) corresponds to coming to a full stop, at which point motion may resume in any direction while maintaining the existence of the derivative, so a stronger condition is necessary to eliminate these cases.\n        \\begin{definition}{Closure}{}\n                A vector valued function \\(\\vec{r}(t)\\) is \\emph{closed} on an interval \\((a,b)\\) if \\(\\vec{r}(a)=\\vec{r}(b)\\).\n        \\end{definition}\n        \\begin{definition}{Simplicity}{}\n                A vector valued function \\(\\vec{r}(t)\\) is \\emph{simple} on an interval \\((a,b)\\) if it has no self-intersections on the interval, except possibly where \\(\\vec{r}(a)=\\vec{r}(b)\\).\n        \\end{definition}\n        Given a curve described by some function \\(\\vec{r}(t)\\) on some interval \\((a,b)\\), we may wish to find its arc length. We assume that \\(\\vec{r}\\) is continuous, smooth, and 1-to-1. This may be done by approximating the curve as a sequence of line segments, and taking the limit as their length goes to \\(0\\). We consider some set of points \\(\\{t_0,\\ldots,t_n\\}\\), where \\(a=t_0 < t_1 < \\ldots < t_n=b\\), which yield the corresponding line segments \\(\\{\\vec{r}(t_1)-\\vec{r}(t_0),\\ldots,\\vec{r}(t_n)-\\vec{r}(t_{n-1})\\}\\) whose lengths may be summed up to obtain an approximation.\n        \\begin{definition}{Rectifiability}{}\n                A curve is rectifiable if there exists some \\(k>0\\) such that the length of an approximation of the curve in terms of line segments is less than \\(k\\) for any number of line segments. In other words, if the length of the approximation approaches a limit.\n        \\end{definition}\n        If a curve is rectifiable with some \\(k\\), then the smallest such \\(k\\) is the length of the curve. Formulaically,\n        \\[\n        L = \\int_a^b \\left| \\vec{r}'(t) \\right|\\, dt = \\int_a^b v(t)\\,dt\n        \\]\n        which may be proven by noting that the length of the line segment between \\(\\vec{r}(t_i)\\) and \\(\\vec{r}(t_{i-1})\\) is \\(|\\vec{r}(t_i)-\\vec{r}(t_{i-1})|\\), which approaches \\(|\\vec{v}'(t_i)|\\) as \\(t_i\\) and \\(t_{i-1}\\) become very close.\n        \\begin{example}{}{}\n                Find the length of the helix described by \\(\\vec{r}(t)=a\\cos{t}\\i+a\\sin{t}\\j+bt\\) on the interval \\(0\\leq t \\leq T\\).\n                \\tcblower\n                \\(\\vec{r}'(t)=-a\\sin{t}\\i+a\\cos{t}\\j+b\\k\\), so \\(v(t)=\\sqrt{a^2\\sin^2{t}+a^2\\cos^2{t}+b^2}=\\sqrt{a^2+b^2}\\) and\n                \\[\n                L = \\int_0^T \\sqrt{a^2+b^2}\\,dt = \\left[\\sqrt{a^2+b^2}t\\right]_0^T = T\\sqrt{a^2+b^2}\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                Find the length of the curve described by \\(\\vec{r}(t)=2t\\i+t^2\\j+\\frac{1}{3}t^3\\k\\) on the interval \\(1\\leq t \\leq 2\\).\n                \\tcblower\n                \\(\\vec{r}'(t)=2\\i+2t\\j+t^2\\k\\), so \\(v(t)=\\sqrt{4+4t^2+t^4}=\\sqrt{(2+t^2)^2}=2+t^2\\), and the length of the curve is\n                \\[\n                L = \\int_1^2 2+t^2\\,dt = \\left[2t+\\frac{t^3}{3}\\right]_1^2 = \\frac{13}{3}\n                \\]\n        \\end{example}\n        Let's say that \\(\\vec{r}:[a,b]\\to\\mathbb{R}^d\\) is a smooth parametric curve, and \\(s(t)\\) is the length of the curve from \\(\\vec{r}(a)\\) to \\(\\vec{r}(t)\\). We may then use \\(s\\) to parametrize the curve instead of \\(t\\), which yields a parameterization with a constant speed of \\(1\\).\n\n        Note that\n        \\[\n        s(t) = \\int_a^t v(u)\\,du\n        \\]\n        so\n        \\[\n        \\frac{ds}{dt}=v(t)\n        \\]\n        by FTC.\n        \\begin{theorem}{}{}\n                Prove that an arc length parametrized curve has constant speed \\(1\\).\n                \\tcblower\n                Note that\n                \\[\n                \\left|\\frac{d\\vec{r}}{dt}\\right|=\\left|\\frac{d\\vec{r}}{dt}\\frac{dt}{ds}\\right|\n                \\]\n                but by the definition of arc length parameterization we have \\(\\frac{dt}{ds}=\\frac{1}{v(t)}\\), which is always defined because \\(\\vec{r}\\) is smooth. In that case,\n                \\[\n                \\frac{d\\vec{r}}{dt}=|v(t)|\\frac{1}{|v(t)|}=1\n                \\]\n        \\end{theorem}\n        \\begin{example}{}{}\n                Find the arc length parameterization of the helix described by \\(\\vec{r}(t)=a\\cos{t}\\i+a\\sin{t}\\j+bt\\) on the interval \\(0\\leq t \\leq T\\).\n                \\tcblower\n                \\(\\vec{r}(t)=a\\cos{t}\\i+a\\sin{t}\\j+b\\k\\), so \\(v(t)=\\sqrt{a^2+b^2}\\) and\n                \\[\n                s(t) = \\int_0^t \\sqrt{a^2+b^2}\\,du = t\\sqrt{a^2+b^2}\n                \\]\n                which we may use this to reparameterize the curve in the form\n                \\[\n                        \\vec{r}=a\\cos\\left(\\frac{s}{\\sqrt{a^2+b^2}}\\right)\\i + a\\sin\\left(\\frac{s}{\\sqrt{a^2+b^2}}\\right)\\j + b\\frac{s}{\\sqrt{a^2+b^2}}\\k\n                \\]\n        \\end{example}\n        \\begin{example}{}{}\n                Find the arc length parameterization of the curve described by \\(\\vec{r}(t)=2t\\i+t^2\\j+\\frac{t^3}{3}\\k\\) on the interval \\(0 \\leq t \\leq T\\).\n                \\tcblower\n                \\(\\vec{r}(t)=2t\\i+t^2\\j+\\frac{t^3}{3}\\k\\), so \\(v(t)=t^2+2\\) and\n                \\[\n                s(t) = \\int_0^tu^2+2\\,du = \\frac{t^3}{3}+2t\n                \\]\n                which may be solved for \\(t\\) to find a parameterization. The algebra involved is tedious, and thus elided.\n        \\end{example}\n\\end{document}\n", "meta": {"hexsha": "707cf43e2b1f3315070fab27443c25df6d653619", "size": 5704, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "src/lec_2.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_2.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_2.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": 67.1058823529, "max_line_length": 586, "alphanum_fraction": 0.5347124825, "num_tokens": 1897, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8418256472515683, "lm_q2_score": 0.8918110418436166, "lm_q1q2_score": 0.750749407526098}}
{"text": "\\section{Integral Curves}\r\n\\noindent\r\nAn integral curve, $\\vec{r}$, of a vector field, $\\vec{F}$, is a VVF such that $\\vec{r^\\prime}(t) = \\left(\\vec{F}\\circ\\vec{r}\\right)(t)$.\\\\\r\n\r\n\\noindent\r\nFor example, let's find an integral curve to $\\vec{F}(x,y) = \\langle x, 2y\\rangle$.\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}}{\\mathrm{d}t}\\vec{r}(t) = \\vec{F}\\circ\\vec{r}\r\n\\end{equation*}\r\n\\begin{equation*}\r\n\t\\frac{\\mathrm{d}}{\\mathrm{d}t}\\langle x(t), y(t) \\rangle = \\langle x(t), 2 y(t) \\rangle \\to\r\n\t\\begin{cases}\r\n\t\tx^\\prime(t) = x(t) \\\\\r\n\t\ty^\\prime(t) = 2 y(t)\r\n\t\\end{cases} \r\n\t\\implies \\vec{r}(t) = \\langle c_1 e^t, c_2 e^{2t} \\rangle\r\n\\end{equation*}\r\n\r\n\\noindent\r\nThese integral curves have applications in physics and show up naturally in nature alongside vector fields. In physics, the integral curves for an electric field are called “field lines” and integral curves of the velocity field of a fluid like water or air are called “streamlines.” You may recognize these curves as tracing out a slope field.\r\n\r\n[INSERT IMAGE]", "meta": {"hexsha": "cd7f925084dd9435f4ca141f10fc0f3863b1dfa4", "size": 1023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "multiCalc/vectorAnalysis/integralCurves.tex", "max_stars_repo_name": "aneziac/Math-Summaries", "max_stars_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_stars_repo_licenses": ["Unlicense"], "max_stars_count": 39, "max_stars_repo_stars_event_min_datetime": "2020-03-26T06:20:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T17:38:45.000Z", "max_issues_repo_path": "multiCalc/vectorAnalysis/integralCurves.tex", "max_issues_repo_name": "aneziac/Math-Summaries", "max_issues_repo_head_hexsha": "20a0efd79057a1f54e093b5021fbc616aab78c3f", "max_issues_repo_licenses": ["Unlicense"], "max_issues_count": 26, "max_issues_repo_issues_event_min_datetime": "2020-03-28T17:44:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-07T04:47:03.000Z", "max_forks_repo_path": "multiCalc/vectorAnalysis/integralCurves.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": 46.5, "max_line_length": 345, "alphanum_fraction": 0.669599218, "num_tokens": 345, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8962513648201266, "lm_q2_score": 0.8376199572530448, "lm_q1q2_score": 0.7507180298886175}}
{"text": "%!TEX root=ClassNotes.tex\n\\section{Fundamental Theorem of Calculus}\n\nThe Fundamental Theorem of Calculus is a remarkable theorem that connects the notions of derivatives and integrals.\n\nIf we denote by $\\mathcal{D}$ the {\\it operator} that takes a function and produces it's derivative i.e. $\\mathcal{D}(f) = f'$ and by $\\mathcal{I}$ the {\\it operator} that takes a function and produces (one of) it's antiderivative i.e. $\\mathcal{I}(f) = \\int_a^x f(t) \\: \\:dt$, for some real number $a$, then the Fundamental Theorem of Calculus says that\n\\begin{enumerate}\n\t\\item $\\mathcal{D}(\\mathcal{I}(f)) = f$, and\n\t\\item  $\\mathcal{I}(\\mathcal{D}(f)) = f + $ a constant.\n\\end{enumerate} so that Integral and Derivative are (almost) inverse operators.\\footnote{Compare this to the definition of inverse functions: $f(g(x)) = x$ and $g(f(x)) = x$.} This is why $\\int_a^x f(t) \\: \\:dt$ is called (an) {antiderivative}.\\\\\n\n\n\n\\begin{theorem}[Fundamental Theorem of Calculus]$ $\n\t\\begin{description}\n\t\t\\item[Form 1] Let $f$ be a continuous function. For a real number $a$, let $ F_a(x) = \\int \\limits_a^x f(t) \\:dt$.\n\t\t      Then $F_a(x)$ is differentiable with\n\t\t      \\begin{align*}\n\t\t\t      F_a'(x) = f(x).\n\t\t      \\end{align*}\n\t\t\\item[Form 2]\n\t\t      Let $f$ be a differentiable function with $f'$ continuous. Then for any real numbers $a$ and $x$,\n\t\t      \\begin{align*}\n\t\t\t      \\int \\limits_a^x f'(t) \\:dt = f(x) - f(a).\n\t\t      \\end{align*}\n\t\\end{description}\n\\end{theorem}\n\nThe idea of the proof of Form 1 is very straightforward. By definition of derivative,\n\\begin{align}\n\t\\begin{split}\n\t\tF_a'(x)\n\t\t& = \\lim \\limits_{h \\rightarrow 0} \\dfrac{F_a(x+h) - F_a(x)}{h}                                                                                                 \\\\\n\t\t& = \\lim \\limits_{h \\rightarrow 0} \\dfrac{\\int \\limits_a^{x+h} f(t) \\:dt - \\int \\limits_a^x f(t) \\:dt}{h}                                                           \\\\\n\t\t& = \\lim \\limits_{h \\rightarrow 0} \\dfrac{\\int \\limits_x^{x+h} f(t) \\:dt}{h}\n\t\t\\qquad\n\t\t\\qquad\n\t\t\\mbox{ by Exercise } \\ref{q:difference_antiderivatives}\n\t\\end{split}\n\t\\label{eq:Fundamental_Theorem_Reduction}\n\\end{align}\nFor small $h$ this last integral can be approximated by the area of a rectangle with height $f(x)$ and base $h$.\n\\begin{align*}\n\t\\int \\limits_x^{x+h} f(t) \\:dt\n\t & \\approx f(x) \\cdot h \\\\\n\t\\implies \\dfrac{\\int \\limits_x^{x+h} f(t) \\:dt}{h}\n\t & \\approx f(x)\n\\end{align*}\nWe'll make this last statement precise using $\\epsilon, \\delta$ arguments. We'll start with a small Proposition.\n\\begin{figure}[t]\n\t\\centering\n\t\\includegraphics[width=0.6\\textwidth]{FundamentalTheorem.png}\n\t\\caption*{The area $\\int_x^{x+h} f(t)\\:dt$ can be approximated by a rectangle with height $f(x)$ and base $h$.}\n\\end{figure}\n\n\\begin{prop}\n\t\\label{theorem:Fundamental_theorem_lemma}\n\tIf for all $ y$ in the interval $(x,x+h)$,\n\t\\begin{align*}\n\tm < f(y) < M\n\t\\end{align*}\n\tfor some real numbers $m$, $M$, then\n\t\\begin{align*}\n\t\tmh < \\int \\limits_{a}^{b} f(t) \\: \\:dt < Mh\n\t\\end{align*}\n\\end{prop}\n\\begin{exercise}$ $\n\t\\begin{enumerate}\n\t\t\\item Prove the above Proposition using a {\\it geometric} argument.\n\t\t\\item \\textbf{Optional: } Prove the above Proposition rigorously using the definition of integral involving Riemann sums.\n\t\\end{enumerate}\n\\end{exercise}\n\nNow we get back to the proof of the Form 1 of the Fundamental Theorem of Calculus.\n\\begin{proof}[Proof of Form 1 of the Fundamental Theorem of Calculus]\n\tLet $f(x)$ be a continuous function, let $a$ be a real number. We want to show that\n\t\\begin{align*}\n\t\tF_a'(x) = f(x)\n\t\\end{align*}\n\tBy Equations \\eqref{eq:Fundamental_Theorem_Reduction} this is equivalent to proving that\n\t\\begin{align*}\n\t\t\\lim \\limits_{h \\rightarrow 0}\\dfrac{\\int \\limits_x^{x+h} f(t) \\:dt}{h}\n\t\t & = f(x)\n\t\\end{align*}\n\tWe'll only prove this for the right hand limit, the left hand limit is proved similarly. We want to show that\n\t\\begin{align}\n\t\t\\label{eq:Fundamental_theorem_limit}\n\t\t\\lim \\limits_{h \\rightarrow 0^+}\\dfrac{\\int \\limits_x^{x+h} f(t) \\:dt}{h}\n\t\t & = f(x)\n\t\\end{align}\n\t\\begin{exercise}\n\t\t\\label{q:epsilon_delta_limit}\n\t\tConvert Equation \\eqref{eq:Fundamental_theorem_limit} into an $\\epsilon, \\delta$ statement using the definition of limit.\n\t\\end{exercise}\n\n\t\\begin{exercise}\n\t\tRecall what it means for $f(x)$ to be continuous from the right, using the  $\\epsilon, \\delta$ definition of continuity.\n\t\\end{exercise}\n\n\t\\begin{exercise}\n\t\tUsing this $\\delta$ and Proposition \\ref{theorem:Fundamental_theorem_lemma} prove the statement in Exercise \\ref{q:epsilon_delta_limit}, thereby completing the proof of the Fundamental Theorem of Calculus.\n\t\\end{exercise}\n\\end{proof}\n\n\\begin{exercise}[{\\bf Optional}]\n\tProve that $\\lim \\limits_{h \\rightarrow 0^-}\\dfrac{\\int \\limits_x^{x+h} f(t) \\:dt}{h}\n\t= f(x)$. (Be careful of the signs.)\n\\end{exercise}\n\n\nThe Form 2 of the fundamental theorem follows directly from Form 1 using a small Proposition about derivatives.\n\\begin{prop}\n\t\\label{theorem:Fundamental_theorem_lemma2}\n\tIf $g(x)$ is a differentiable function such that $g'(x) = 0$ for all real numbers $x$, then $g(x)$ is a constant function i.e. $g(x) = g(y)$ for all real numbers $x$, $y$.\n\\end{prop}\n\\begin{exercise}\n\tProve the above Proposition by Contradiction\\hint{Use the Mean Value Theorem}.\n\\end{exercise}\n\n\\begin{proof}[Proof of Form 2 of the Fundamental Theorem of Calculus]\n\tLet $f$ be a diffentiable function with $f'$ continuous, and let $a$ be a real number. We want to show that\n\t\\begin{align*}\n\t\t\\int \\limits_a^x f'(t) \\:dt = f(x) - f(a)\n\t\\end{align*}\n\tConsider the function\n\t\\begin{align*}\n\t\tg(x) = f(x) - \\int \\limits_a^x f'(t) \\:dt.\n\t\\end{align*}\n\t\\begin{exercise}\n\t\tUsing Form 1 of the Fundamental Theorem and Proposition \\ref{theorem:Fundamental_theorem_lemma2} prove that $g(x)$ is a constant function.\n\t\\end{exercise}\n\t\\begin{exercise}\n\t\tAs $g$ is a constant function, for all real numbers $x$, $g(x) = g(a)$. Use this to prove Form 2 of the Fundamental Theorem of Calculus.\n\t\\end{exercise}\n\\end{proof}\n\n\\begin{remark}\n\tFor real numbers $b$, $c$,\n\t\t\\begin{align*}\n\t\t\t\\int \\limits_b^c f(t) \\:dt\n\t\t\t&= \\int \\limits_b^a f(t) \\:dt + \\int \\limits_a^c f(t) \\:dt\\\\\n\t\t\t&= -\\int \\limits_a^b f(t) \\:dt + \\int \\limits_a^c f(t) \\:dt\\\\\n\t\t\t&= F_a(c) - F_a(b)\n\t\t\\end{align*}\n\twhere $F_a(x)$ is {\\it an} antiderivative of $f(x)$ i.e. it is a function whose derivative is $f(x)$. This is the form is which the Fundamental Theorem of Calculus is most often used. Which $a$ we use to find the antiderivative does not matter, so the integral can be written in the following forms.\n\t\\begin{align*}\n\t\t\\int \\limits_b^c f(t) \\: \\:dt\n\t\t&= F_a(c) - F_a(b) \\\\\n\t\t&= \\left. F_a(x) \\right|_{b}^c \\\\\n\t\t&= \\left. \\int f(x) dx \\right|_{b}^c \\\\\n\t\t&= \\left. \\int f(x) dx \\right|_{x=b}^{x=c}\n\t\\end{align*}\n\tIt is acceptable to use any of these forms as they all mean the same thing.\n\\end{remark}\n\n\\newpage\n\\subsection{Understanding the Fundamental Theorem of Calculus}\nThe Fundamental Theorem has a LOT of applications. We'll spend the next several sections just understanding this theorem.\n\\begin{exercise}\n\tLet $a$ be a real number. Find derivatives of the following functions using the Fundamental Theorem and simple algebraic manipulations.\n\t\\begin{enumerate}\n\t\t\\item $\\int \\limits_{x}^{a} f(t) \\: dt$.\n\t\t\\item $\\int \\limits_a^{x^2} f(t) \\: dt$.\n\t\t\\item $\\int \\limits_a^{g(x)} f(t) \\: dt$, where\t$g(x)$ is a differentiable function.\n\t\t\\item $\\int \\limits_{x}^{x^2} f(t) \\: dt$.\n\t\t\\item $\\int \\limits_{h(x)}^{g(x)} f(t) \\: dt$, where\t$g(x)$, $h(x)$ are differentiable functions.\n\t\t% \\item $\\int \\limits_a^{x} t \\cdot f(t) \\: dt$.\n\t\t\\item $\\int \\limits_a^{x} x \\cdot f(t) \\: dt$. (Be careful!)\n\t\\end{enumerate}\n\\end{exercise}\n\n\\begin{exercise}\n\tProve that if\n\t\\begin{align*}\n\t\tf'(t) > 0\n\t\\end{align*}\n\tfor all $t \\in [a,b]$, then $f$ is increasing on the interval $[a,b]$ i.e. for all $x$, $y$ in the interval $[a,b]$ if $x < y$ then $f(x) < f(y)$.\\hint{Compute the integral $\\int \\limits_x^y f'(t) \\: dt$.}\n\\end{exercise}\n\n\\begin{theorem}[u-substitution]\n\tLet $f$, $g$ be differentiable functions. Then,\n\t\\begin{align*}\n\t\t\\int_a^x f(g(t)) g'(t)\\: dt = \\int_{g(a)}^{g(x)} f(u) \\: du\n\t\\end{align*}\n\\end{theorem}\n\\begin{exercise}[Proof of u-substitution] Consider the function\n\t\\begin{align*}\n\t\th(x)\n\t\t=\n\t\t\\int_a^x f(g(t)) g'(t)\\: dt - \\int_{g(a)}^{g(x)} f(u) \\: du\n\t\\end{align*}\n\\begin{enumerate}\n\t\\item Show that $h'(x) = 0$.\n\t\\item Show that $h(a) = 0$.\n\t\\item Argue that these two statements imply that $h(x) = 0$ for all $x$, thereby proving u-substitution.\n\\end{enumerate}\n\\end{exercise}\n\n\n\\begin{theorem}[Integration by parts]\n\tLet $f$, $g$ be differentiable functions. Then,\n\t\\begin{align}\n\t\t\\label{eq:integration_by_parts}\n\t\t\\int_a^x f(t) g'(t)\\: dt = f(x)g(x) - \\int_{a}^{x} f'(t) g(t) \\: dt + c\n\t\\end{align}\n\tfor some constant $c$.\n\\end{theorem}\n\\begin{exercise}[Proof of Integration by parts] Consider the function\n\t\\begin{align*}\n\t\th(x)\n\t\t=\n\t\t\\int_a^x f(t) g'(t)\\: dt - \\left(f(x)g(x) - \\int_{a}^{x} f'(t) g(t) \\: dt \\right)\n\t\\end{align*}\nShow that $h'(x) = 0$. Argue that this proves Integration by parts.\n\\end{exercise}\n\n\\begin{exercise}\n\tFind the contant $c$ in Equation \\eqref{eq:integration_by_parts}.\n\\end{exercise}\n\nBecause of the constant $c$ that shows up in Equation \\eqref{eq:integration_by_parts} integration by parts is often expressed using indefinite integrals as,\n\\begin{align*}\n\t\\int f(x) g'(x)\\: dx = f(x)g(x) - \\int f'(x) g(x) \\: dx + c\n\\end{align*}\n\n\\begin{remark}\n\tThese two theorems\n\t\\begin{itemize}\n\t\t\\item u-substitution\n\t\t\\item integration by parts\n\t\\end{itemize}\n\tprovide the main techniques for computing integrals. In the later sections we'll do several problems to practice these.\n\\end{remark}\n", "meta": {"hexsha": "37a807f4a4ddc975666bbe5a717c559a4bd6266f", "size": 9696, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "2018/07FundamentalTheorem.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/07FundamentalTheorem.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/07FundamentalTheorem.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": 41.4358974359, "max_line_length": 354, "alphanum_fraction": 0.6602722772, "num_tokens": 3282, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8539127529517043, "lm_q2_score": 0.8791467675095294, "lm_q1q2_score": 0.7507146364926541}}
{"text": "\\section{Cap product and ``\\v{C}ech'' cohomology}\nLet $R$ be a commutative ring with coefficients. The cap product is a map $\\cap: H^p(X)\\otimes H_n(X)\\to H_{q}(X)$ where $p+q=n$. This comes from a chain level map $S^p(X)\\otimes S_n(X)\\xrightarrow{1\\otimes\\alpha} S^p(X)\\otimes S_p(X)\\otimes S_q(X)\\xrightarrow{\\langle-,-\\rangle\\otimes 1}R\\otimes S_q(X)\\cong S_q(X)$. Using our explicit formula for $\\alpha$, we can write:\n\\begin{equation*}\n\\cap:\\beta\\otimes\\sigma\\mapsto\\beta\\otimes(\\sigma\\circ\\alpha_p)\\otimes(\\sigma\\circ\\omega_q)\\mapsto\\left(\\beta(\\sigma\\circ\\alpha_p)\\right)\\cdot (\\sigma\\circ\\omega_q)\n\\end{equation*}\nThere's many things to say:\n\\begin{enumerate}\n\\item $ H_\\ast(X)$ is a module for $ H^\\ast(X)$.\n\\item The only reasonable thing to ask for in terms of naturality is the following. Suppose $f:X\\to Y$, and let $b\\in H^p(Y)$ and $x\\in H_n(X)$. We then have $f_\\ast(f^\\ast(b)\\cap x)=b\\cap f_\\ast(x)$, where $f^\\ast(b)\\cap x\\in H_q(X)$ and $b\\cap f_\\ast(x)\\in H_n(X)$. This is called a projection formula. To see this, let $[\\beta]=b$. Then:\n\\begin{align*}\nf_\\ast(f^\\ast(\\beta)\\cap\\sigma)& =f_\\ast(\\left(f^\\ast(\\beta)(\\sigma\\circ\\alpha_p)\\right)\\cdot(\\sigma\\circ\\omega_q))\\\\\n& =f_\\ast(\\beta(f\\circ\\sigma\\circ\\alpha_p)\\cdot(\\sigma\\circ\\omega))\\\\\n& =\\beta(f\\circ\\sigma\\circ\\alpha_p)\\cdot f_\\ast(\\sigma\\circ\\omega_q)\\\\\n& = \\beta(f\\circ\\sigma\\circ\\alpha_p)\\cdot(f\\circ\\sigma\\circ\\omega_q)\\\\\n& = \\beta\\cap f_\\ast(\\sigma)\n\\end{align*}\nSo we're done.\n\\item There's a relation between the cap and Kronecker product. Any space has an augmentation $\\varepsilon:X\\to\\ast$, so I get $\\varepsilon_\\ast: H_\\ast(X)\\to R$. Maybe we should compute $\\varepsilon_\\ast(\\beta\\cap \\sigma)$. I will get zero unless $p=n$ and $q=0$. What does our formula say? This just says that $\\varepsilon_\\ast(b\\cap x)=\\varepsilon_\\ast(\\beta(\\sigma)\\cdot c^0_{\\sigma(n)})=\\beta(\\sigma)\\varepsilon_\\ast(c^0_{\\sigma(n)})=\\beta(\\sigma)=\\langle \\beta,\\sigma\\rangle$ because $\\varepsilon_\\ast$ counts the number of points, i.e., it's $1$. Hence $\\varepsilon_\\ast(b\\cap x)=\\langle b,x\\rangle$.\n\\item What is $\\langle a\\cup b,x\\rangle$? This is $\\varepsilon_\\ast((a\\cup b)\\cap x)=\\varepsilon_\\ast(a\\cap(b\\cap x))$ by an assertion in the previous lecture (namely that $(\\alpha\\cup\\beta)\\cap x=\\alpha\\cap(\\beta\\cap x)$ and $1\\cap x=x$), which becomes $\\langle a,b\\cap x\\rangle$. In other words, $\\langle a\\cup b,x\\rangle=\\langle a,b\\cap x\\rangle$. So the cup product is adjoint to the cap product.\n\\end{enumerate}\n\\subsection{Relative $\\cap$}\nThere's a lot of structure, but we want more. We want to now try to understand the relative cap product. Suppose $A\\subseteq X$ is a subspace. We have:\n\\begin{equation*}\n\\xymatrix{\n\t0\\ar[d] & & 0\\ar[d]\\\\\n\tS^p(X)\\otimes S_n(A)\\ar[d]^{1\\otimes i_\\ast}\\ar[r]^{i^\\ast\\otimes 1} & S^p(A)\\otimes S_n(A)\\ar[r]^{\\cap} & S_q(A)\\ar[d]\\\\\n\tS^p(X)\\otimes S_n(X)\\ar[rr]^\\cap\\ar[d] & & S_q(X)\\ar[d]\\\\\n\tS^p(X)\\otimes S_n(X,A)\\ar[d]\\ar@{-->}[rr] & & S_q(X,A)\\ar[d]\\\\\n\t0 & & 0\n}\n\\end{equation*}\nThe left sequence is exact because $0\\to S_n(A)\\to S_n(X)\\to S_n(X,A)\\to 0$ splits and tensoring with $S^p(X)$ still leaves it exact. We have to check that this diagram commutes.\n\nLet $\\beta\\otimes \\sigma\\in S^p(X)\\otimes S_n(A)$. We then get:\n\\begin{equation*}\n\\beta\\otimes\\sigma\\xrightarrow{i^\\ast\\otimes 1}i^\\ast\\beta\\otimes\\sigma\\to i^\\ast(\\beta)\\cap\\sigma\\xrightarrow{i_\\ast}i_\\ast(i^\\ast(\\beta)\\cap\\sigma)\n\\end{equation*}\nAnd:\n\\begin{equation*}\n\\beta\\otimes\\sigma\\xrightarrow{1\\otimes i_\\ast}\\beta\\otimes i_\\ast\\sigma\\to \\beta\\cap i_\\ast(\\sigma)\n\\end{equation*}\nSo they're equal by the projection formula. Hence you get $\\cap: H^p(X)\\otimes H_n(X,A)\\to H_q(X,A)$ that makes $ H_\\ast(X,A)$ a $ H^\\ast(X)$-module.\n\\subsection{A different perspective on excision}\nRecall what excision is. We know that $ H_\\ast(X-U,A-U)\\cong H_\\ast(X,A)$. There's another perspective on this. Suppose $K\\subseteq U\\subseteq X$ such that $\\overline{K}\\subseteq\\mathrm{Int}(U)$. To simplify things, suppose $K$ is closed and $U$ is open. Let $A=X-K\\supseteq X-U=V$. Then excision says that $ H_\\ast(X-V,A-V)= H_\\ast(X-(X-U),(X-K)-(X-U))\\cong H_\\ast(X,A)= H_\\ast(X,X-K)$. There's a simpler expression: $ H_\\ast(X-(X-U),(X-K)-(X-U))= H_\\ast(U,U-K)$, so $ H_\\ast(U,U-K)\\cong H_\\ast(X,X-K)$, i.e., it depends only on an open neighborhood of $K$. A question that we now have is: how does this depend on $ H_\\ast(K)$? $ H^\\ast(K)$? This is really what Poincar\\'{e} duality wants to understand.\n\\begin{example}\nWe'll eventually be talking, for example, about $X=S^3$ and $K=\\text{knot}$.\n\\end{example}\nWe want to understand $ H_\\ast(X,X-K)$ better. We have a cap product $ H^p(X)\\otimes H_n(X,X-K)\\to H_q(X,X-K)$. We just decided that $ H_n(X,X-K)\\cong H_n(U,U-K)$, and so I have the cap product $ H^p(U)\\otimes H_n(U,U-K)\\to H_q(U-U-K)$. Hence I get the cap product map like $ H^p(U)\\otimes H_n(X,X-K)\\to H_q(X,X-K)$. But this seems to depend upon a choice of $U$. What if I make $U$ smaller?\n\\begin{lemma}\nLet $U\\supseteq V\\supseteq K$. Then:\n\\begin{equation*}\n\\xymatrix{\n\t H^p(U)\\ar[dd]^{i^\\ast\\otimes 1}\\otimes H_n(X,X-K)\\ar[dr]^\\cap & \\\\\n\t & H_q(X,X-K)\\\\\n\t H^p(V)\\otimes H_n(X,X-K)\\ar[ur]^\\cap\n}\n\\end{equation*}\n\\end{lemma}\n\\begin{proof}\nHint: use projection formula again.\n\\end{proof}\nLet $\\mathcal{U}_K$ be the set of open neighborhoods of $K$ in $X$. This is a poset (actually a directed set because you can take intersections), under reverse-inclusion as the ordering. This lemma says that $ H^p:\\mathcal{U}_K\\to\\mathbf{Ab}$.\n\\begin{definition}\n$\\cHH^p(K):=\\varinjlim_{U\\in\\mathcal{U}_K} H^p(U)$.\n\\end{definition}\nThis is bad notation because it depends on the way $K$ is sitting in $X$.\n\nYou therefore get $\\cHH^p(K)\\otimes H_n(X,X-K)\\xrightarrow{\\cap} H_q(X,X-K)$. This is the best you can do. It's the natural structure that this relative homology has, i.e., $ H_\\ast(X,X-K)$ is a module over $\\cHH^\\ast(K)$.\n\nSometimes, $\\cHH^\\ast(K)$ will just be $ H^\\ast(K)$. Suppose $K\\subseteq X$ satisfies the condition (called the ``regularity'' condition) that for every open $U\\supseteq K$, there exists an open $V$ such that $U\\supseteq V\\supseteq K$ such that $K\\to V$ is a homotopy equivalence (or actually just a homology isomorphism). (for example, a smooth knot in $S^3$) Then:\n\\begin{lemma}\nSuppose $\\cI$ is a directed set (nonempty). Let $F:\\cI\\to\\mathbf{Ab}$, and suppose I have a natural transformation $\\theta:F\\to c_A$ (for example, a map from $F$ to its direct limit). This expresses $A$ as $\\varinjlim_\\cI F$ provided that for all $i$, there is $j\\geq i$ such that $F(i)\\to A$ factors through $F(j)\\to A$, which should be an isomorphism, i.e.:\n\\begin{equation*}\n\\xymatrix{\n\tF(i)\\ar[dr]\\ar[rr] & & A\\\\\n\t& F(j)\\ar[ur]^\\cong\n}\n\\end{equation*}\n\\end{lemma}\n\\begin{proof}\nGiven $a\\in A$, it has to come from somewhere to be a direct limit. This is obviously true. Also, for any $i$ and $a_i\\in F(i)$ such that $a_i\\mapsto 0$, then there exists $j\\geq i$ such that $a_i\\mapsto 0\\in F(j)$. This is also obvious.\n\\end{proof}\n\\begin{remark}\nThis is a really strong condition by the way. It is a really stupid way.\n\\end{remark}\nThis works in the case that $K$ is regular in $X$. Thus, under this condition, $\\cHH^p(K)\\cong H^p(K)$. One other comment is that more generally, if $X$ is an Euclidean neighborhood retract (a retract of a neighborhood in some $\\RR^n$), and $K$ is locally compact, then $\\cHH^p(K)$ depends only on $K$, and it is isomorphic to \\v{C}ech cohomology (which is a different type of cohomology theory).\n", "meta": {"hexsha": "0f0be5d6ad73e240e2a6471ee41cd1024fd36bad", "size": 7501, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old-905/lec-32-cap-product-cech-cohomology.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-32-cap-product-cech-cohomology.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-32-cap-product-cech-cohomology.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": 86.2183908046, "max_line_length": 704, "alphanum_fraction": 0.6871083855, "num_tokens": 2641, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8791467580102418, "lm_q2_score": 0.8539127492339909, "lm_q1q2_score": 0.7507146251126756}}
{"text": "\\documentclass{article}\n\n\\usepackage[utf8]{inputenc}\n\\usepackage[T1]{fontenc}\n\n% Main maths packages\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathrsfs}\n\n\\begin{document}\n\n\\section*{Matrices}\n\n\\subsection*{Basic matrix}\n\n\\[\n\\begin{matrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{matrix}\n\\]\n\n\\subsection*{Matrix with braces}\n\n\\[\n\\begin{pmatrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{pmatrix}\n\\]\n\nA lot of environments exist with different brackets.\n\n\\[\n\\begin{vmatrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{vmatrix}\n\\]\n\n\\[\n\\begin{Vmatrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{Vmatrix}\n\\]\n\n\\[\n\\begin{bmatrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{bmatrix}\n\\]\n\n\\[\n\\begin{Bmatrix}\n\ta_{11} & \\cdots & a_{1k}\\\\\n\t\\vdots & \\ddots & \\vdots\\\\\n\ta_{k1} & \\cdots & a_{kk}\n\\end{Bmatrix}\n\\]\n\n\\end{document}", "meta": {"hexsha": "24ca9f003ff7853a391661392ef60c30047401d6", "size": 1047, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "compendium/mathematics/matrices.tex", "max_stars_repo_name": "ZenLulz/LatexCompendium", "max_stars_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2016-07-30T21:43:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-23T20:16:19.000Z", "max_issues_repo_path": "compendium/mathematics/matrices.tex", "max_issues_repo_name": "ZenLulz/LatexCompendium", "max_issues_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "compendium/mathematics/matrices.tex", "max_forks_repo_name": "ZenLulz/LatexCompendium", "max_forks_repo_head_hexsha": "cc623a88ab05ca90430338333003293baea00f8c", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 15.1739130435, "max_line_length": 52, "alphanum_fraction": 0.6074498567, "num_tokens": 447, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9207896671963206, "lm_q2_score": 0.8152324803738429, "lm_q1q2_score": 0.7506576442910617}}
{"text": "\\documentclass{article}\n\\usepackage{graphicx}\n\\usepackage{amsmath}\n\\usepackage{amssymb}\n\\usepackage{mathtools}\n\\usepackage{datetime}\n\\usepackage{lipsum}\n\\graphicspath{{images/}}\n\n\\setlength\\parindent{0pt}\t% no indent for entire document\n\n\\title{Backpropagation for FC Neural Network}\n\n\\newcommand\\blfootnote[1]\n{%\n  \\begingroup\n  \\renewcommand\\thefootnote{}\\footnote{#1}%\n  \\addtocounter{footnote}{-1}%\n  \\endgroup\n}\n \n\\begin{document}\n\n\\begin{titlepage}\n\\author{Hao Huang}\n\\date{\\today}\n\\maketitle\n\\end{titlepage}\n\n\\tableofcontents\n\\newpage\n\n\\section{Network Structure}\n\\begin{center}\n\\includegraphics[scale=0.3]{neuralnetwork}\n\\end{center} \n\n\\blfootnote{Credit and Copyright:}\n\\blfootnote{http://blog.csdn.net/sysstc/article/details/75305276}\n\\blfootnote{http://blog.csdn.net/sysstc/article/details/75269563}\n \n\\section{Notations}\n\\subsection{Output of activation}\n\\begin{center}\n\\includegraphics[scale=0.3]{activation_output}\n\\end{center}\nOutput of a neuron: $a^l_i$ (Superscript $l$ is the layer, and subscript is the index in layer)\n\nOutput of a layer: $a^l$ (a vector)\n\n\\subsection{Weights}\n\\begin{center}\n\\includegraphics[scale=0.4]{weights}\n\\end{center}\n$w^l_{ij}$: from neuron $j$ (layer $l-1$) to neuron $i$ (layer $l$)\n\n\\[\nW^l\n=\n\\begin{bmatrix}\n    w^l_{11} & w^l_{12} & \\dots & w^l_{1j} & \\dots  & w^l_{1N_{l-1}} \\\\\n    w^l_{21} & w^l_{22} & \\dots & w^l_{2j} & \\dots  & w^l_{2N_{l-1}} \\\\\n    \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\\n    w^l_{N_l1} & w^l_{N_l2} & \\dots & w^l_{N_lj} & \\dots & w^l_{N_lN_{l-1}}\n\\end{bmatrix}_{N_l\\times N_{l-1}}\n\\]\n\n\\subsection{Biases}\n\\begin{center}\n\\includegraphics[scale=0.4]{biases}\n\\end{center}\n$b^l_i$: bias for neuron $i$ at layer $l$\n\\[\nb^l\n=\n\\begin{bmatrix}\n    b^l_{1} & b^l_{2} & \\dots & b^l_{i} & \\dots  & b^l_{N_l}\n\\end{bmatrix}^T\n\\]\n\n\\subsection{Input of activation}\n\\begin{center}\n\\includegraphics[scale=0.4]{activation_input}\n\\end{center}\n$z^l_i$: input of the activation function of neuron $i$ at layer $l$\n\n$z^l$: input of the activation function of all neurons at layer $l$\n\n\\[\nz^l_i = \\sum_j^{N_{l-1}} w^l_{ij}a^{l-1}_j + b^l_i\n\\]\n\n\\[\nz^l = \n\\begin{bmatrix}\n    z^l_{1} & z^l_{2} & \\dots & z^l_{i} & \\dots  & z^l_{N_l}\n\\end{bmatrix}^T\n\\]\n\n\\subsection{Relations between layers}\n\\begin{center}\n\\includegraphics[scale=0.4]{layer_1}\n\\end{center}\n\\[\nz^l_1 = w^l_{11}a^{l-1}_1 + w^l_{12}a^{l-1}_2 + \\dots + w^l_{1j}a^{l-1}_j + \\dots + w^l_{1N_{l-1}}a^{l-1}_{N_{l-1}} + b^l_1\n\\]\n\\[\nz^l_2 = w^l_{21}a^{l-1}_1 + w^l_{22}a^{l-1}_2 + \\dots + w^l_{2j}a^{l-1}_j + \\dots + w^l_{2N_{l-1}}a^{l-1}_{N_{l-1}} + b^l_2\n\\]\n\\[\n\\vdots\n\\]\n\\[\nz^l_i = w^l_{i1}a^{l-1}_1 + w^l_{i2}a^{l-1}_2 + \\dots + w^l_{ij}a^{l-1}_j + \\dots + w^l_{iN_{l-1}}a^{l-1}_{N_{l-1}} + b^l_i\n\\]\n\\[\n\\vdots\n\\]\n\\[\nz^l_{N_l} = w^l_{N_l1}a^{l-1}_1 + w^l_{N_l2}a^{l-1}_2 + \\dots + w^l_{N_lj}a^{l-1}_j + \\dots + w^l_{N_lN_{l-1}}a^{l-1}_{N_{l-1}} + b^l_{N_l}\n\\]\nRewrite them as matrix multiplication form:\n\\[\n\\begin{bmatrix}\nz^l_{1} \\\\ z^l_{2} \\\\ \\vdots \\\\ z^l_{i} \\\\ \\vdots  \\\\ z^l_{N_l}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n    w^l_{11} & w^l_{12} & \\dots & w^l_{1j} & \\dots  & w^l_{1N_{l-1}} \\\\\n    w^l_{21} & w^l_{22} & \\dots & w^l_{2j} & \\dots  & w^l_{2N_{l-1}} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    w^l_{i1} & w^l_{i2} & \\dots & w^l_{ij} & \\dots  & w^l_{iN_{l-1}} \\\\\n    \\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots \\\\\n    w^l_{N_l1} & w^l_{N_l2} & \\dots & w^l_{N_lj} & \\dots & w^l_{N_lN_{l-1}}\n\\end{bmatrix}\n\\begin{bmatrix}\na^{l-1}_{1} \\\\ a^{l-1}_{2} \\\\ \\vdots \\\\ a^{l-1}_{j} \\\\ \\vdots  \\\\ a^{l-1}_{N_{l-1}}\n\\end{bmatrix}\n+\n\\begin{bmatrix}\nb^l_{1} \\\\ b^l_{2} \\\\ \\vdots \\\\ b^l_{i} \\\\ \\vdots  \\\\ b^l_{N_l}\n\\end{bmatrix}\n\\]\nThat is:\n\\[\nz^l = W^l a^{l-1} + b^l\n\\]\n\n\\begin{center}\n\\includegraphics[scale=0.4]{layer_2}\n\\end{center}\nFor neuron $i$ in layer $l$:\n\\[\na^l_i = \\sigma(z^l_i)\n\\]\nFor the layer $l$:\n\\[\n\\begin{bmatrix}\na^l_{1} \\\\ a^l_{2} \\\\ \\vdots \\\\ a^l_{i} \\\\ \\vdots  \\\\ a^l_{N_l}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\\sigma(z^l_1) \\\\ \\sigma(z^l_2) \\\\ \\vdots \\\\ \\sigma(z^l_i) \\\\ \\vdots  \\\\ \\sigma(z^l_{N_l})\n\\end{bmatrix}\n\\]\nRewrite it as:\n\\[\na^l = \\sigma(z^l)\n\\]\n\n\\begin{center}\n\\includegraphics[scale=0.4]{layer_3}\n\\end{center}\n\\[\n\\begin{rcases*}\na^l = \\sigma(z^l)\\\\\nz^l = W^l a^{l-1} + b^l\n\\end{rcases*} \\Rightarrow a^l=\\sigma(W^la^{l-1}+b^l)\n\\]\n\n\\subsection{Summary of notation}\n\\begin{center}\n\\includegraphics[scale=0.4]{notation_1}\n\\end{center}\n\\[\na^1=\\sigma(W^1x+b^1)\n\\]\n\\[\na^2=\\sigma(W^2a^1+b^2)\n\\]\n\\[\n\\vdots\n\\]\n\\[\ny=a^L=\\sigma(W^{L}a^{L-1}+b^L)\n\\]\nConsider a neural network as a function:\n\\[\ny=f(x)=\\sigma(W^L...\\sigma(W^2\\sigma(W^1x+b^1)+b^2)...+b^L)\n\\]\n\n\\section{Three gradient descent approaches}\n$\\theta$ is the parameter set of a neural network (e.g. $\\{W^1, b^1, ..., W^L, b^L\\}$), and $C$ is the cost function. The superscript $i$ indicates the $i$-th update. $N$ is the number of training samples.\n\\subsection{Gradient descent}\n\\[\n\\theta^i = \\theta^{i-1} - \\eta\\nabla C(\\theta^{i-1})\n\\]\n\\[\n\\nabla C(\\theta^{i-1}) = \\frac{1}{N}\\sum_{r = 1}^N\\nabla C _r(\\theta^{i-1})\n\\]\n\\subsection{Stochastic gradient descent}\nRandomly pick a training sample $x_r$:\n\\[\n\\theta^i = \\theta^{i-1} - \\eta \\nabla C_r(\\theta^{i-1})\n\\]\n\\subsection{Mini-batch gradient descent}\nShuffle the training data and then pick $M$ samples as a batch:\n\\[\n\\theta^i = \\theta^{i-1} - \\eta \\frac{1}{M}\\sum_{x_r\\in batch}\\nabla C_r(\\theta^{i-1})\n\\]\n\n\\section{Backpropagation}\nThe change in $w^l_{ij}$ leads to the change in $C_r$, so we need to compute $\\nabla C_r$ with respect to $w^l_{ij}$.\n\n\\subsection{Partial derivative of $C_r$ w.r.t $w^l_{ij}$}\n\\begin{center}\n\\includegraphics[scale=0.4]{grad_ctow}\n\\end{center}\n\\[\n\\Delta w^l_{ij}\\rightarrow \\Delta z^l_i\\rightarrow \\Delta a^l_i \\rightarrow \\dots \\rightarrow \\Delta C_r \n\\]\n\\[\n\\frac{\\partial C_r}{\\partial w^l_{ij}} = \\frac{\\partial C_r}{\\partial z^l_i}\\frac{\\partial z^l_i}{\\partial w^l_{ij}}\n\\]\n\n\\subsection{Partial derivative of $z^l_i$ w.r.t $w^l_{ij}$}\nWe divide this partial derivative into two parts: input layer and hidden layer(s).\n\n\\subsubsection{Input layer}\nSuppose the input layer has $N_0$ input nodes. The superscript $r$ of $x$ means the $r$-th sample.\n\\begin{center}\n\\includegraphics[scale=0.5]{grad_ztow_input}\n\\end{center}\n\\[\nz^1_i = \\sum_j^{N_0}w^1_{ij}x^r_j + b^1_i\n\\]\n\\[\n\\frac{\\partial z^1_i}{\\partial w^1_{ij}} = x^r_j\n\\]\n\n\\subsubsection{Hidden layer}\n\\begin{center}\n\\includegraphics[scale=0.5]{grad_ztow_hidden}\n\\end{center}\n\\[\nz^l_i = \\sum_j^{N_{l-1}}w^l_{ij}a^{l-1}_j + b^l_i\n\\]\n\\[\n\\frac{\\partial z^l_i}{\\partial w^l_{ij}} = a^{l-1}_j\n\\]\n\n\\subsection{Partial derivative of $C_r$ w.r.t $z^l_{i}$}\n\\[\n\\frac{\\partial C_r}{\\partial w^l_{ij}} = \\frac{\\partial C_r}{\\partial z^l_i}\\frac{\\partial z^l_i}{\\partial w^l_{ij}}\n\\]\nWe denote $\\frac{\\partial C_r}{\\partial z^l_i}$ as $\\delta^l_i$ and define $\\delta^l = [\\delta^l_1 \\: \\delta^l_2 \\: \\dots \\delta^l_i \\: \\dots \\: \\delta^l_{N_l}]^T$.\n\n\\begin{center}\n\\includegraphics[scale=0.4]{delta}\n\\end{center}\n\nWe need to compute $\\delta^l$. However, computing $\\delta^l$ can be divided into two steps:\n\\begin{enumerate}\n\\item\ncomputing $\\delta^L$ (output layer)\n\\item\nfiguring out the relationship between $\\delta^{l+1}$ and $\\delta^l$ \n\\end{enumerate}\n\n\\subsubsection{Computing $\\delta^L$ (output layer)} \n\\begin{center}\n\\includegraphics[scale=0.5]{grad_last}\n\\end{center}\n\\[\n\\Delta z^L_n\\rightarrow \\Delta a^L_n = \\Delta y^r_n \\rightarrow \\Delta C_r \n\\]\n\\[\n\\delta^L_n = \\frac{\\partial C_r}{\\partial z^L_n} = \\frac{\\partial C_r}{\\partial y^r_n}\\frac{\\partial y^r_n}{\\partial z^L_n} = \\frac{\\partial C_r}{\\partial y^r_n}\\sigma^\\prime(z^L_n)\n\\]\nIn addition, $\\frac{\\partial C_r}{\\partial y^r_n}$ depends on the definition of the cost function.\n\\[\n\\delta^L\n=\n\\begin{bmatrix}\n\\delta^L_1 \\\\ \\delta^L_2 \\\\ \\vdots \\\\ \\delta^L_n \\\\ \\vdots  \\\\ \\delta^L_{N_L})\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n(\\partial C_r \\mathbin{/} \\partial y^r_1)\\times\\sigma^\\prime(z^L_1) \\\\ \n(\\partial C_r \\mathbin{/} \\partial y^r_2)\\times\\sigma^\\prime(z^L_2) \\\\\n\\vdots \\\\\n(\\partial C_r \\mathbin{/} \\partial y^r_n)\\times\\sigma^\\prime(z^L_n) \\\\\n\\vdots \\\\\n(\\partial C_r \\mathbin{/} \\partial y^r_{N_L})\\times\\sigma^\\prime(z^L_{N_L})\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n(\\partial C_r \\mathbin{/} \\partial y^r_1) \\\\ \n(\\partial C_r \\mathbin{/} \\partial y^r_2) \\\\\n\\vdots \\\\\n(\\partial C_r \\mathbin{/} \\partial y^r_n) \\\\\n\\vdots \\\\\n(\\partial C_r \\mathbin{/} \\partial y^r_{N_L})\n\\end{bmatrix}\n\\odot\n\\begin{bmatrix}\n\\sigma^\\prime(z^L_1) \\\\ \\sigma^\\prime(z^L_2) \\\\ \\vdots \\\\\n\\sigma^\\prime(z^L_n) \\\\ \\vdots \\\\ \\sigma^\\prime(z^L_{N_L})\n\\end{bmatrix}\n\\]\n$\\odot$ is element-wise multiplication. We rewrite this formula is a vector form:\n\\[\n\\delta^L = \\nabla C_r(y^r) \\odot \\sigma^\\prime(z^L)\n\\]\n\n\\subsubsection{Relationship between $\\delta^{l+1}$ and $\\delta^l$} \n\\begin{center}\n\\includegraphics[scale=0.6]{grad_delta}\n\\end{center}\nBecause the output of $i$-th node in layer $l$ (e.g., $a^l_i$) will be passed in to every node in layer $l+1$, so we have:\n\\[\n\\Delta z^l_i \\rightarrow \\Delta a^l_i \\rightarrow \n\\begin{dcases*}\n\\begin{rcases*}\n\\Delta z^{l+1}_1 \\\\ \\Delta z^{l+1}_2 \\\\ \\vdots \\\\ \\Delta z^{l+1}_k \\\\ \\vdots \\\\ \\Delta z^{l+1}_{N_{l+1}} \n\\end{rcases*} \n\\end{dcases*} \\dashrightarrow \\Delta C_r\n\\]\n\\[\n\\delta^l_i = \\frac{\\partial C_r}{\\partial z^l_i} = \\sum^{N_{l+1}}_k\\frac{\\partial C_r}{\\partial z^{l+1}_k}\\frac{\\partial z^{l+1}_k}{\\partial a^l_i}\\frac{\\partial a^l_i}{\\partial z^l_i} = \\frac{\\partial a^l_i}{\\partial z^l_i}\\sum^{N_{l+1}}_k\\frac{\\partial C_r}{\\partial z^{l+1}_k}\\frac{\\partial z^{l+1}_k}{\\partial a^l_i} = \\frac{\\partial a^l_i}{\\partial z^l_i}\\sum^{N_{l+1}}_k\\delta^{l+1}_k\\frac{\\partial z^{l+1}_k}{\\partial a^l_i}\n\\]\n\\[\n\\because a^l_i = \\sigma(z^l_i) \\; \\land \\; z^{l+1}_k = \\sum^{N_l}_i w^{l+1}_{ki}a^l_i + b^{l+1}_k\n\\] \n\\[\n\\therefore \\delta^l_i = \\sigma^\\prime(z^l_i)\\sum^{N_{l+1}}_k\\delta^{l+1}_kw^{l+1}_{ki} = \\sigma^\\prime(z^l_i)\\sum^{N_{l+1}}_kw^{l+1}_{ki}\\delta^{l+1}_k\n\\]\nLet us rewrite it in vector (and matrix) form:\n\\[\n\\sigma^\\prime(z^l)\n=\n\\begin{bmatrix}\n\\sigma^\\prime(z^l_1) \\\\ \\sigma^\\prime(z^l_2) \\\\ \\vdots \\\\\n\\sigma^\\prime(z^l_i) \\\\ \\vdots \\\\ \\sigma^\\prime(z^l_{N_l})\n\\end{bmatrix}\n\\; \\land \\;\n\\delta^{l+1}\n=\n\\begin{bmatrix}\n\\delta^{l+1}_1 \\\\ \\delta^{l+1}_2 \\\\ \\vdots \\\\\n\\delta^{l+1}_k \\\\ \\vdots \\\\ \\delta^{l+1}_{N_{l+1}}\n\\end{bmatrix}\n\\] \n\\[\n\\delta^l\n=\n\\begin{bmatrix}\n\\delta^l_1 \\\\ \\delta^l_2 \\\\ \\vdots \\\\\n\\delta^l_i \\\\ \\vdots \\\\ \\delta^l_{N_l}\n\\end{bmatrix}\n=\n\\begin{bmatrix}\n\\sigma^\\prime(z^l_1) \\\\ \\sigma^\\prime(z^l_2) \\\\ \\vdots \\\\\n\\sigma^\\prime(z^l_i) \\\\ \\vdots \\\\ \\sigma^\\prime(z^l_{N_l})\n\\end{bmatrix}\n\\odot\n\\begin{pmatrix} \n\\begin{bmatrix}\nw^{l+1}_{11} & w^{l+1}_{21} & \\dots & w^{l+1}_{k1} & \\dots & w^{l+1}_{N_{l+1}1}\\\\\nw^{l+1}_{12} & w^{l+1}_{22} & \\dots & w^{l+1}_{k2} & \\dots & w^{l+1}_{N_{l+1}2}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots\\\\\nw^{l+1}_{1i} & w^{l+1}_{2i} & \\dots & w^{l+1}_{ki} & \\dots & w^{l+1}_{N_{l+1}i}\\\\\n\\vdots & \\vdots & \\ddots & \\vdots & \\ddots & \\vdots\\\\\nw^{l+1}_{1N_l} & w^{l+1}_{2N_l} & \\dots & w^{l+1}_{kN_l} & \\dots & w^{l+1}_{N_{l+1}N_l}\\\\\n\\end{bmatrix}\n\\begin{bmatrix}\n\\delta^{l+1}_1 \\\\ \\delta^{l+1}_2 \\\\ \\vdots \\\\\n\\delta^{l+1}_k \\\\ \\vdots \\\\ \\delta^{l+1}_{N_{l+1}}\n\\end{bmatrix}\n\\end{pmatrix}\n\\]\nThat is:\n\\[\n\\delta^l = \\sigma^\\prime(z^l)\\odot[(W^{l+1})^T\\delta^{l+1}]\n\\]\nThus we get the relationship between $\\delta^{l+1}$ and $\\delta^l$.\n\n\\subsubsection{Another viewpoint}\nFrom this formula: $\\delta^l_i = \\sigma^\\prime(z^l_i)\\sum^{N_{l+1}}_kw^{l+1}_{ki}\\delta^{l+1}_k$, we can view it as a new type of neuron, where $\\sigma^\\prime(z^l_i)$ is an \"amplifier\".\n\\begin{center}\n\\includegraphics[scale=0.6]{new_neuron}\n\\end{center}\nThe relationship between the layer $l$ and layer $l+1$ (e.g., $\\delta^l = \\sigma^\\prime(z^l)\\odot[(W^{l+1})^T\\delta^{l+1}]$) can be viewed as:\n\\begin{center}\n\\includegraphics[scale=0.6]{new_layer}\n\\end{center}\nNow we compare the forward-pass network and the backward-pass network:\n\\begin{enumerate}\n\\item\nForward-pass network\n\\begin{center}\n\\includegraphics[scale=0.4]{forward}\n\\end{center}\n\\[\na^{l+1} = \\sigma(W^{l+1}a^l+b^{l+1})\n\\]\n\\item\nBackward-pass network\n\\begin{center}\n\\includegraphics[scale=0.4]{backward}\n\\end{center}\n\\[\n\\delta^l = \\sigma^\\prime(z^l)\\odot[(W^{l+1})^T\\delta^{l+1}]\n\\]\n\\end{enumerate}\n\n\\section{Summary}\nOur goal is:\n\\[\n\\frac{\\partial C_r}{\\partial w^l_{ij}} = \\frac{\\partial C_r}{\\partial z^l_i}\\frac{\\partial z^l_i}{\\partial w^l_{ij}}\n\\]\n\\[\n\\frac{\\partial z^l_i}{\\partial w^l_{ij}}\n=\n\\begin{cases}\nx^r_j & \\textrm{input layer}\\\\\na^{l-1}_j & \\textrm{hidden layer}\n\\end{cases}\n\\]\nTo compute $\\delta^l_i = \\frac{\\partial C_r}{\\partial z^l_i}$, we divide it into two step:\n\\begin{enumerate}\n\\item\nFor output layer $L$:\n\\[\n\\delta^L = \\nabla C_r(y^r)\\odot \\sigma^\\prime(z^L)\n\\]\n\\item\nFor hidden layers $\\delta^{l+1}$ and $\\delta^l$:\n\\[\n\\delta^l = \\sigma^\\prime(z^l)\\odot [(W^{l+1})^T\\delta^{l+1}]\n\\]\n\\end{enumerate}\nTo visualize forward-pass and backward-pass, we have:\n\\begin{center}\n\\includegraphics[scale=0.35]{summary}\n\\end{center}\nThe black dot in the figure is equivalent to $\\odot$ and means element-wise multiplication.\n\n\\end{document}", "meta": {"hexsha": "9a8d672257ea116b856390ac1bdcca6681af449a", "size": 13087, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Backpropagation/Backpropagation.tex", "max_stars_repo_name": "huanghao-code/Notes", "max_stars_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Backpropagation/Backpropagation.tex", "max_issues_repo_name": "huanghao-code/Notes", "max_issues_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Backpropagation/Backpropagation.tex", "max_forks_repo_name": "huanghao-code/Notes", "max_forks_repo_head_hexsha": "87349598cc6cf928bc4f87a3e1df25c231689045", "max_forks_repo_licenses": ["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.5119825708, "max_line_length": 431, "alphanum_fraction": 0.6312371055, "num_tokens": 5546, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297807787537, "lm_q2_score": 0.8333245994514082, "lm_q1q2_score": 0.7504336188615194}}
{"text": "\\chapter{Examples in Matlab}\n\nWe now want to find approximate numerical solutions using Fourier spectral methods. In this section we focus primarily on the heat equation with periodic boundary conditions for $x\\in[0,2\\pi)$. Many of the techniques used here will also work for more complicated partial differential equations for which separation of variables cannot be used directly.\n%%%%%%%\n%Section\n%%%%%%%\n\\section{1D Heat Equation}\nThe 1D heat equation\n\\begin{eqnarray}\\label{eq:heat}\n\\frac{\\partial u}{\\partial t} = \\alpha \\frac{\\partial^2 u}{\\partial x^2}\n\\end{eqnarray}\nis a well known second order PDE for which exact series solutions can be found using separation of variables.  It arises in several contexts such as in predicting the temperature in a thin uniform cross section rod. The equation and its derivation can be found in introductory books on partial differential equations and calculus, for example \\cite{BoyDip10}, \\cite{CouJoh98} and \\cite{HugEtAl08},   The constant $\\alpha$ is the thermal diffusivity and $u(x,t)$ is temperature. We have already described how to solve the heat equation using separation of variables. Let us first discretize $x$ such that $x_j$ where $j=0,1,2,...,n$. $x_j$ are uniformly spteaced in $[0,2\\pi)$. Let's now take the FFT of both sides of the 1D heat equation to obtain\n\\begin{eqnarray}\n\\widehat{\\frac{\\partial u}{\\partial t}} = \\alpha \\widehat{\\frac{\\partial^2 u}{\\partial x^2}}.\n\\end{eqnarray}\nWe then rewrite the spatial derivative using eq.\\ \\eqref{eq:Spectral_Method_Deriv} \\footnote{The $k$ subscript denotes the coefficient of the k$^{th}$ Fourier mode.}\n\\begin{eqnarray}\n\\frac{\\partial \\hat{u}_k}{\\partial t} = \\alpha (ik)^2 \\hat{u}_k, \n\\end{eqnarray}\nso that the partial differential equation now becomes a collection of independent ODEs. While we can solve these ODEs in time exactly, we will use techniques that will also allow us to obtain approximate solutions to PDEs we cannot solve exactly. We will discuss two methods for solving these ODEs, forward Euler and backward Euler.\n\n%subsection\n\\subsection{Forward Euler}\nUsing the forward Euler method in time, we obtain\n\\begin{eqnarray}\n\\frac{\\hat{u}_k^{n+1}-\\hat{u}_k^n}{h} = \\alpha (ik)^2 \\hat{u}_k^n \\\\\n\\hat{u}_k^{n+1} =\\hat{u}_{k}^n+\\alpha h(ik)^2\\hat{u}_k^n  \n\\end{eqnarray}\nAll that is left is to take the IFFT of the computed solution after all timesteps are taken to transfer it back to real space. This is a linear PDE, so only one IFFT is needed at the end. We will later see that this is different for a nonlinear PDE. A Matlab implementation of this is in listing \\ref{lst:HeatFE1dMatlab}.\n\n\\lstinputlisting[style=matlab_style,label=lst:HeatFE1dMatlab,caption={A Matlab program to solve the heat equation using forward Euler timestepping.}]{./ExamplesInMatlab/Programs/Heat_Eq_1D_Spectral_FE.m}\n \n %subsection\n\\subsection{Backward Euler}\nTo derive this method, we start by applying the FFT and then perform timestepping using backward Euler. We then rewrite the implicit form into a form that gives the next iterate,\n\\begin{eqnarray}\n\\frac{\\partial \\hat{u}_k}{\\partial t} &=& \\alpha (ik)^2 \\hat{u}_k \\\\\n\\frac{\\hat{u}_k^{n+1}-\\hat{u}_k^n}{h} &=& \\alpha (ik)^2 \\hat{u}_k^{n+1} \\\\\n\\hat{u}_k^{n+1}(1-\\alpha h(ik)^2) &=&\\hat{u}_k^n\\\\\n\\hat{u}_k^{n+1} &=&\\frac{\\hat{u}_k^n}{(1-\\alpha h(ik)^2)}.\n\\end{eqnarray}\nBelow is a graph of the numerical solution to the heat equation\\footnote{Methods to obtain the exact solution can be found in, among other places,  Boyce and DiPrima~\\cite{BoyDip10}. } where $n=64$ obtained using the Matlab program in listing \\ref{lst:HeatBE1dMatlab}. \n\\begin{figure}\n \\begin{center}\n\\includegraphics[scale=.35]{./ExamplesInMatlab/Heat_Equation_1D_BE_Color}\n\\caption{A numerical solution to the heat equation, eq.\\ \\eqref{eq:heat} computed using the backward Euler method.} \\label{fig:HeatBE1dMatlab}\n\\end{center}\n\\end{figure}\n\n\\lstinputlisting[style=matlab_style,label=lst:HeatBE1dMatlab,caption={A Matlab program to solve the heat equation using backward Euler timestepping.}]{./ExamplesInMatlab/Programs/Heat_Eq_1D_Spectral_BE.m}\n\n%subsection\n\\subsection{Exercises}\n\\begin{enumerate}\n\\item[1)] Write a program to solve the heat equation using the Crank-Nicolson method.\n\\item[2)] Solve the advection equation $u_t=u_x$ for $x\\in[0,2\\pi)$ with the initial data\n\\begin{enumerate}\n\\item[a)] $u(t=0,x)=\\cos(x)$\n\\item[b)] $u(t=0,x)=\\left\\{{0\\quad x<\\pi}\\atop{1\\quad x\\geq\\pi}\\right.$\n\\end{enumerate}\nup to a time $T=1$. You can do this either by using separation of variables or by assuming that the solution is of the form $u(x,t)=f(x+t)$ and deducing what $f$ is in order to satisfy the initial conditions. In both cases please use the forward Euler, backward Euler and Crank-Nicolson timestepping schemes. After calculating the exact solution in each of these cases, examine how the maximum error at the final time depends on the timestep for each of these three methods.\n\\end{enumerate}\n\n\n%%%%%%%\n%Section\n%%%%%%%\n\\section{Nonlinear Equations}\n%subsection\n\\subsection{The 1D Allen-Cahn Equation}\nSo far we have dealt only with linear equations. Now it's time for a nonlinear PDE. The \\emph{Allen-Cahn equation} models the separation of phases in a material. It was introduced by Sam Allen and J. W. Cahn~\\cite{AllCah79}  and is \n\\begin{eqnarray}\n\\frac{\\partial u}{\\partial t} = \\epsilon\\frac{\\partial^2 u}{\\partial x^2}+u-u^3, \\label{eq:AllCah}\n\\end{eqnarray} \nwhere $\\epsilon$ is a small but positive constant.  The way to numerically solve this is similar to the method used for the heat equation, but there are some notable differences. The biggest difference is that FFT($u^3$)$\\neq$FFT($u$)$^3$, so the $u^3$ must be computed before taking the FFT. The FFT is a linear operation but cubing is non-linear operation, so the order matters\n\\begin{eqnarray}\n\\frac{\\partial \\hat{u}_k}{\\partial t} = \\epsilon\\frac{\\partial^2 \\hat{u}_k}{\\partial x^2}+\\hat{u}_k-\\widehat{u^3}_k. \\label{Allen_Cahn_1D}\n\\end{eqnarray}\nNext rewrite the first term on the right hand side, just like we did in the heat equation\n\\begin{eqnarray}\n\\frac{\\partial \\hat{u}_k}{\\partial t} = \\epsilon(ik)^2\\hat{u}_k+\\hat{u}_k-\\widehat{u^3}_k.\n\\end{eqnarray}\nIn order to solve this numerically we are going to use a combination of implicit (backward Euler) and explicit (forward Euler) methods. We are going to skip forward Euler because it is unstable.\n\n%subsubsection\n\\subsubsection{Implicit-Explicit Method} \nYou might have already noticed that backward Euler is not going to work for the Allen-Cahn in its present state because of the nonlinear term. If you go to implement backward Euler you can see that you can't factor out all of the $\\hat{u}_k^{n+1}$. Luckily there is a simple intuitive way around this that isn't detrimental to the accuracy of the solution. Write all the terms implicitly (backwards Euler) except for the nonlinear term which is expressed explicitly.  Applying this to Allen-Cahn we find that \\footnote{Notice that when programming you are going to have to update the nonlinear term ($u^3$) each time you want to calculate the next timestep $n+1$. The reason this is worth mentioning is because for each timestep you are going to have to go from real space to Fourier space to real space, then repeat. For, the heat equation you can perform any number of timesteps in Fourier space and only convert back when you record your data.}\n\\begin{eqnarray}\n\\frac{\\hat{u}_k^{n+1}-\\hat{u}_k^n}{h} &=& \\epsilon(ik)^2\\hat{u}_k^{n+1}+\\hat{u}_k^n-\\widehat{(u^n)^3}_k \\\\\n\\hat{u}_k^{n+1}\\left(-\\epsilon(ik)^2+\\frac{1}{h}\\right)&=&\\frac{1}{h}\\hat{u}_k^n+\\hat{u}_k^n-\\widehat{(u^n)^3}_k \\\\\n\\hat{u}_k^{n+1}&=&\\frac{\\hat{u}_k^n(\\frac{1}{h}+1)-\\widehat{(u^n)^3}_k}{\\left(-\\epsilon(ik)^2+\\frac{1}{h}\\right)}. \n\\end{eqnarray}\nNow we have a form that we can work with. We can set the initial conditions to be $u(x,0)=\\frac{1}{4} \\sin(x)$ and plot the computed space-time evolution calculated by the Matlab code in listing \\ref{lst:AllenCahnIE1dMatlab}. The computed result is in Fig.\\ \\ref{fig:AllenCahnIE1dMatlab}.\n\n\\lstinputlisting[style=matlab_style,label=lst:AllenCahnIE1dMatlab,caption={A Matlab program to solve the 1D Allen-Cahn equation using implicit explicit timestepping.}]{./ExamplesInMatlab/Programs/Allen_Cahn_1D_Spectral_IE.m}\n\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=.2]{./ExamplesInMatlab/Allen_Cahn_BE_1D}\n\\caption{A numerical solution to the 1D Allen-Cahn equation, eq.\\ \\eqref{eq:AllCah}, with $\\epsilon=0.001$ and $u(x,t=0)=0.25\\sin(x)$ computed using an implicit explicit method.} \\label{fig:AllenCahnIE1dMatlab}\n\\end{center}\n\\end{figure}\n\n%subsection\n\\subsection{The 2D Allen-Cahn Equation}\nNow we will look at the 2D form of the Allen-Cahn Equation, where $u(x,y,t)$ satisfies\n\\begin{eqnarray}\n\\frac{\\partial u}{\\partial t} = \\epsilon\\left(\\frac{\\partial^2 u}{\\partial x^2}+\\frac{\\partial^2 u}{\\partial y^2}\\right)+u-u^3. \\label{eq:AllCah2D}\n\\end{eqnarray}\nThe convert it into Fourier space by taking the FFT of both sides\n\\begin{eqnarray}\n\\frac{\\partial \\hat{u}_k}{\\partial t} &=& \\epsilon\\left(\\frac{\\partial^2 \\hat{u}_k}{\\partial x^2}+\\frac{\\partial^2 \\hat{u}_k}{\\partial y^2}\\right)+\\hat{u}_k-\\widehat{u^3}_k\\\\\n\\frac{\\partial \\hat{u}_k}{\\partial t} &=& \\epsilon\\left((ik_x)^2\\hat{u}_k+(ik_y)^2\\hat{u}_k\\right)+\\hat{u}_k-\\widehat{(u^3)}_k \\label{eq:Allen_Cahn_2D}\n\\end{eqnarray}\nwhere $k_x$ and $k_y$ is to remind us that we take the FFT in respected directions. We will also define\n\\begin{eqnarray}\nf(u) \\equiv u-u^3 \\label{eq:nonlinear}\n\\end{eqnarray}\nThe way to deal with the first two terms on the right hand side is to take the FFT in the x-direction and then take it in the y-direction. The order in which the FFT is done, $x$ first or $y$ first is not important. Some software libraries offer a two dimensional FFT. It usually depends on the equation being solved whether it is more efficient to use a multidimensional FFT or many one dimensional FFTs. Typically, it is easier to write a program which uses a multidimensional FFT, but in some situations this is not very efficient since one can immediately reuse data that has just been Fourier transformed.\n%subsubsection\n\\subsubsection{Implicit-Explicit Method}\nIn this method, the nonlinear term in eq.\\ \\eqref{eq:nonlinear} is calculated explicitly, while the rest of the terms will be written implicitly such that\n\\begin{align}\n&{} \\frac{\\hat{u}_k^{n+1}-\\hat{u}_k^n}{h} = \\epsilon\\left((ik_x)^2\\hat{u}_k^{n+1}+(ik_y)^2\\hat{u}_k^{n+1}\\right)+\\widehat{f(u^n)}_k \n\\\\&{} \\hat{u}_k^{n+1}\\left(-\\epsilon(ik_x)^2-\\epsilon(ik_y)^2+\\frac{1}{h}\\right)=\\frac{\\hat{u}_k^n}{h}+\\widehat{f(u^n)}_k\n\\\\&{} \\hat{u}_k^{n+1} = \\frac{\\frac{\\hat{u}_k^n}{h}+\\widehat{f(u^n)}_k}{ \\left(-\\epsilon(ik_x)^2-\\epsilon(ik_y)^2+\\frac{1}{h}\\right)}\n\\end{align}\nwe can then substitute in for $f(u)$\n\\begin{align}\n\\hat{u}_k^{n+1} = \\frac{\\hat{u}_k^n\\left(\\frac{1}{h}+1\\right)-\\widehat{(u^n)^3}_k}{ \\left(-\\epsilon(ik_x)^2-\\epsilon(ik_y)^2+\\frac{1}{h}\\right)}. \\label{eq:Allen_Cahn_IE_2D}\n\\end{align}\n\\begin{figure}\n\\begin{center}\n\\includegraphics[scale=.2]{./ExamplesInMatlab/Allen_Cahn_2D_IE}\n\\caption{A numerical solution to the 2D Allen-Cahn equation, eq.\\ \\eqref{eq:AllCah2D} at time $t=500$ with $\\epsilon=0.1$ and $u(x,y,t=0)=\\sin(2\\pi x)+0.001\\cos(16\\pi x)$ computed using an implicit explicit method.} \\label{fig:AllenCahnIE2dMatlab}\n\\end{center}\n\\end{figure}\nThe Matlab code used to generate Fig.\\ \\ref{fig:AllenCahnIE2dMatlab} is in listing \\ref{lst:AllenCahnIE2dMatlab}.\n\n\\lstinputlisting[style=matlab_style,label=lst:AllenCahnIE2dMatlab,caption={A Matlab program to solve the 2D Allen-Cahn equation using implicit explicit timestepping.}]{./ExamplesInMatlab/Programs/Allen_Cahn_2D_Spectral_IE.m}\n\n%subsection\n\\subsection{Exercises}\n\nMany of these exercises are taken from Uecker~\\cite{Uec09}. Another introductory source of information on these equations is Trefethen and Embree~\\cite{TreEmb01}.\n\n\\begin{enumerate}\n\\item[1)] Burgers equation is given by:\n$$\\frac{\\partial u}{\\partial t}=\\nu \\frac{\\partial^2 u}{\\partial x^2} - u\\frac{\\partial u}{\\partial x}$$\nwhere $\\nu\\in\\mathbb{R}^+$ and $u$ has periodic boundary conditions. Solve this equation using an implicit-explicit method. If you take $\\nu$ to be small, ensure that a sufficient number of grid points are used to get the correct numerical solution. A simple way to check this is to keep increasing the number of grid points and checking that there is no change in the solution. Another way to check this is to calculate the Fourier coefficients and check that the highest ones decay to machine precision. \n\\item[2)] The Kuramoto-Sivashinsky equation is given by:\n$$\\frac{\\partial u}{\\partial t}=-\\frac{\\partial^2 u}{\\partial x^2}-\\frac{\\partial^4 u}{\\partial x^4}-u\\frac{\\partial u}{\\partial x}$$\nwhere $u$ has periodic boundary conditions.\n\\begin{itemize}\n\\item[a)] What does this equation model and what type of behavior do you expect its solutions to have?\n\\item[b)] Find numerical solutions to this equation using an implicit-explicit method.\n\\end{itemize}\n\\item[3)] The 1D Gray-Scott equations are given by:\n$$\\frac{\\partial u}{\\partial t}=d_1\\frac{\\partial^2 u}{\\partial x^2}-uv^2+f(1-u),$$\n$$\\frac{\\partial v}{\\partial t}=d_2\\frac{\\partial^2 v}{\\partial x^2} + uv^2 - (f+k)v$$\nwhere $d_1$, $d_2$, $f$ and $k$ are constants. \n\\begin{itemize}\n\\item[a)] What does this equation model and what type of behavior do you expect its solutions to have?\n\\item[b)] Find numerical solutions to this equation using an implicit-explicit method. Try several different values of $d_1$, $d_2$, $f$ and $k$ and compare the resulting patterns to what you can find in the literature.\n\\end{itemize}\n\\item[4)] The 2D Swift-Hohenberg equation is given by:\n$$\\frac{\\partial u}{\\partial t}=-\\Delta^2u+2\\Delta u+ (\\alpha-1)u-u^3,$$\n\\begin{itemize}\n\\item[a)] What does this equation model and what type of behavior do you expect its solutions to have?\n\\item[b)] Find numerical solutions to this equation using an implicit-explicit method for several values of $\\alpha$.\n\\end{itemize}\n\\item[5)] The 2D Gray-Scott equations are given by:\n$$\\frac{\\partial u}{\\partial t}=d_1\\Delta u -uv^2+f(1-u)$$\n$$\\frac{\\partial v}{\\partial t}=d_2\\Delta v  + uv^2 - (f+k)v$$\nwhere $d_1$, $d_2$, $f$ and $k$ are constants. \n\\begin{itemize}\n\\item[a)] What does this equation model and what type of behavior do you expect its solutions to have?\n\\item[b)] Find numerical solutions to this equation using an implicit-explicit method.\n\\end{itemize}\n\\item[6)] The 2D Complex Ginzburg-Landau equation is given by:\n$$\\frac{\\partial A}{\\partial t}=A+(1+i\\alpha)\\Delta A- (1+i\\beta)|A|^2A.$$\nAn introductory tutorial to this equation can be found at \\url{http://codeinthehole.com/static/tutorial/index.html}\n\\begin{itemize}\n\\item[a)] What does this equation model and what type of behavior do you expect its solutions to have?\n\\item[b)] Find numerical solutions to this equation using an implicit-explicit method for several values of $\\alpha$ and $\\beta$.\n\\end{itemize}\n\\end{enumerate}\n", "meta": {"hexsha": "c3a0574fa5235da6003ccb9c207c2cd4f20628f1", "size": 15001, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ExamplesInMatlab/ExamplesInMatlab.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": "ExamplesInMatlab/ExamplesInMatlab.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": "ExamplesInMatlab/ExamplesInMatlab.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": 79.7925531915, "max_line_length": 947, "alphanum_fraction": 0.7426171589, "num_tokens": 4628, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.900529778109184, "lm_q2_score": 0.8333245994514084, "lm_q1q2_score": 0.7504336166369014}}
{"text": "% Copyright 2018 Melvin Eloy Irizarry-Gelpí\n\\chapter{Simple Harmonic Motion}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Preliminary}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nWhen an elastic spring is stretched or compressed beyond its natural relaxed length, a restorative force arises on the spring that causes the spring to return to its natural relaxed length. This force is proportional to how much distance $x$ the spring is stretched:\n\\begin{equation} \\label{eq.11.hooke}\n    F_{k} = - k x\n\\end{equation}\nHere the minus sign is due to the restorative nature of the force (it is always opposite to what the spring is doing), and $k$ is the spring constant.\n\nIf a mass $m$ is attached to one end of the spring, the mass will move back-and-forth when the spring is stretched or compressed. Due to Newton's second law, you have a relation between force and acceleration:\n\\begin{equation}\n    F_{\\text{net}} = m a \\quad \\Longrightarrow \\quad -kx = m a\n\\end{equation}\nOr in other words:\n\\begin{equation} \\label{eq.11.ax}\n    a = -\\left( \\frac{k}{m} \\right) x\n\\end{equation}\nThat is, for this motion, the acceleration is proportional to the amount of distance that the spring is stretched or compressed. Note that the slope is negative.\n\nWhen you look at the position as it change with time, it follows a pattern similar to a sine or cosine function, familiar from trigonometry. This suggest a sinusoidal fit for position $x$ as a function of time $t$:\n\\begin{equation}\n    x(t) = A \\sin{\\left( Bt + C \\right)} + D\n\\end{equation}\nHere $A$ is the amplitude of the motion (in m), $B$ is the angular frequency (in rad/s), $C$ is the time shift (in rad), and $D$ is the position shift (in m). Velocity is defined as the rate of change of position with respect to time. With calculus, this is equivalent to taking a derivative with respect to time:\n\\begin{equation} \\label{eq.11.v}\n    v(t) = \\frac{\\mathrm{d} x}{\\mathrm{d} t} = AB \\cos{\\left( Bt + C \\right)}\n\\end{equation}\nThat is, the parameters that describe the fit for position ($A$, $B$, $C$, and $D$) can also be used to describe the fit for velocity. Similarly, acceleration is defined as the rate of change of velocity with respect to time. With calculus, this is equivalent to taking a derivative with respect to time:\n\\begin{equation} \\label{eq.11.a}\n    a(t) = \\frac{\\mathrm{d} v}{\\mathrm{d} t} = -AB^{2} \\sin{\\left( Bt + C \\right)}\n\\end{equation}\nAgain, the parameters that describe the fit for position can also be used to describe the fit for acceleration.\n\nFor a mass $m$ attached to a spring with spring constant $k$, the period of oscillation is given by\n\\begin{equation}\n    T = 2\\pi \\sqrt{\\frac{m}{k}}\n\\end{equation}\nThe period is the time it takes for the mass to do one full cycle. Related to the period is the angular frequency $\\omega$:\n\\begin{equation} \\label{eq.11.omega}\n    \\omega = \\frac{2 \\pi}{T} = \\sqrt{\\frac{k}{m}}\n\\end{equation}\nAs you are going to see, the same value of angular frequency controls how quickly position, velocity, acceleration, and force change with time.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Experiment}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nWe are going to use a motion sensor to measure the position, velocity and acceleration of a mass hanging from a spring. The spring in turn hangs from a force sensor that we are going to use to measure force. When the sensor is zeroed correctly, the constant weight force $mg$ is taken into account. When the hanging mass is moved from equilibrium and released, the motion is oscillatory.\n\nAfter recording data for a short time, you can use the LabQuest device to obtain the values of the parameters $A$, $B$, $C$, and $D$ that best describe the force and the position data versus time.\n\nWe are going to do four combinations of mass and spring constant, as stated in Table \\ref{table.11.parameters}.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{table}\n    \\centering\n    \\begin{tabular}{|r|r|r|}\\hline\n        $k$ (N/m) & $m$ (kg) & $\\omega$ (rad/s) \\\\ \\hline\n        5 & 0.05 & 10 \\\\\n        5 & 0.1 & 7.071 \\\\\n        15 & 0.1 & 12.247 \\\\\n        15 & 0.15 & 10 \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Four combinations of mass and spring constant, along with $\\omega$ prediction}\n    \\label{table.11.parameters}\n\\end{table}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Analysis}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThere are many aspects of simple harmonic motion that can be verified with this experiment.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Force and Position}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou can verify Hooke's law, equation (\\ref{eq.11.hooke}), by making a scatter plot chart with position in the horizontal axis, and force in the vertical axis. The shape of this graph is a downward line, as in Figure \\ref{figure.11.hooke}. You can find the slope with the \\texttt{SLOPE} function. If position is in column X with the first value in row 6, and force is in column Y, with first value in row 6; then the command is\n\\begin{center}\n    \\texttt{=SLOPE(Y6:Y, X6:X)}\n\\end{center}\nThe linear behavior confirms Hooke's law. The slope of the linear fit corresponds to the (negative) value of the spring constant. Conversely, the negative of the slope serves as an indirect measurement of the spring constant:\n\\begin{equation}\n    k_{\\text{exp}} = - (\\text{slope of force versus position linear fit})\n\\end{equation}\nNote that position and force data come from different sensors.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/11-shm/hooke.png}\n    \\caption{}\n    \\label{figure.11.hooke}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Force and Acceleration}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nYou can verify Newton's second law of motion by making a scatter plot chart with acceleration in the horizontal axis, and force in the vertical axis. The shape of this graph is an upward line, as in Figure \\ref{figure.11.newton}. You can find the slope with the \\texttt{SLOPE} function. The linear behavior confirms Newton's second law, and the value of the slope is mass. You can use this slope as an indirect measurement of the amount of mass hanging from the spring:\n\\begin{equation}\n    m_{\\text{exp}} = \\text{slope of force versus acceleration linear fit}\n\\end{equation}\nNote that acceleration and force data come from different sensors.\n\nTogether with the measurement of the spring constant from the force versus position graph, you can compute an experimental estimate of the angular frequency via\n\\begin{equation}\n    \\omega_{1} = \\sqrt{\\frac{k_{\\text{exp}}}{m_{\\text{exp}}}}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/11-shm/newton.png}\n    \\caption{}\n    \\label{figure.11.newton}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Acceleration and Position}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nCombining Hooke's law with Newton's second law of motion gives equation (\\ref{eq.11.ax}). Using the definition of $\\omega$ in equation (\\ref{eq.11.omega}), we find that indeed,\n\\begin{equation}\n    a = -\\omega^{2}x\n\\end{equation}\nThat is, for simple harmonic motion, the acceleration is proportional to the position with the slope being the (negative) squared angular frequency. The shape of this graph is a downward line, as in Figure \\ref{figure.11.ax}. The slope of this graph is the negative of the squared angular frequency. This value provides another experimental estimate of the angular frequency:\n\\begin{equation}\n    \\omega_{2} = \\sqrt{- (\\text{slope of acceleration versus position})}\n\\end{equation}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/11-shm/a-vs-x.png}\n    \\caption{}\n    \\label{figure.11.ax}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Common Angular Frequency}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nFrom the LabQuest device, you can obtain the parameters for the sinusoidal fit for position and force. The values for $A$, $C$, and $D$ will not necessarily agree, but the values for $B$ in both fits should be very close. Indeed, the $B$ from the force and position fits provide yet more experimental estimates of the angular frequency:\n\\begin{equation}\n    \\omega_{3} = B \\text{ from force fit}\n\\end{equation}\nand\n\\begin{equation}\n    \\omega_{4} = B \\text{ from position fit}\n\\end{equation}\nNote that, since the data for position and force comes from different sensors, these measurements can be taken as fully independent.\n\nIn principle you can perform a sinusoidal fit on velocity and acceleration too. However, the parameters of these fits are not independent. Indeed, theoretically, they depend on the parameters for the position fit as stated in equations (\\ref{eq.11.v}) and (\\ref{eq.11.a}). In class we saw how you can use compute the fit functions in (\\ref{eq.11.v}) and (\\ref{eq.11.a}) with the parameters from the position fit, and how those function are in very good agreement with the experimental data collected.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\subsection{Velocity and Position}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nA graph with velocity and position is called a phase space graph. For this particular experiment with simple harmonic motion, the velocity and position data yield an elliptical shape (a closed orbit), as in Figure \\ref{figure.11.phase}. Now you know!\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{figure}\n    \\centering\n    \\includegraphics[scale=0.71]{image/11-shm/phase.png}\n    \\caption{}\n    \\label{figure.11.phase}\n\\end{figure}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{My Data}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nThe results for my run 1 are summarized in Table \\ref{table.11.results}.\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{table}\n    \\centering\n    \\begin{tabular}{|l|r|}\n        \\hline\n        Name & Value \\\\\n        \\hline\n        $m_{\\text{exp}}$ & 0.0498 kg \\\\\n        $k_{\\text{exp}}$ & 4.4255 N/m \\\\\n        $\\omega_{1}$ & 9.4230 rad/s \\\\\n        $\\omega_{2}$ & 9.3776 rad/s \\\\\n        $\\omega_{3}$ & 9.5802 rad/s \\\\\n        $\\omega_{4}$ & 9.5796 rad/s \\\\\n        \\hline\n        $\\omega_{\\text{ave}}$ & 9.4901 rad/s \\\\\n        \\hline\n    \\end{tabular}\n    \\caption{Results for run 1. The last row is the average of the previous four rows.}\n    \\label{table.11.results}\n\\end{table}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Your Data}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n...\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\section{Your Lab Report}\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\nIn your lab report you should include:\n\\begin{enumerate}\n    \\item A version of Table \\ref{table.11.results} with four runs, one for each different mass/spring constant combination. You do not have to make the graphs in order to get the slopes; use the \\texttt{SLOPE} function.\n    \\item One acceleration versus position graph with the linear fit, for a run of your choosing.\n    \\item One force versus acceleration graph with the linear fit, for a run of your choosing.\n    \\item One force versus position graph with the linear fit, for a run of your choosing.\n    \\item One velocity versus position graph for a run of your choosing.\n\\end{enumerate}\nYou should answer the following questions:\n\\begin{enumerate}\n    \\item Based on your analysis and what we saw in class, are you convinced that (for simple harmonic motion) all of position, velocity, acceleration, and force can be described by sines or cosines with a common angular frequency?\n    \\item Is the angular frequency parameter $B$ for the position versus time graph the same or close to the angular frequency parameter $B$ for the force versus time graph?\n    \\item Can you test Newton's second law with the data from this experiment? Does the measured mass agree with the expected value used?\n    \\item Can you test Hooke's law with the data from this experiment? Does the measured spring constant agree with the expected value used?\n    \\item Are your four estimates of the angular frequencies close to the expected theoretical value given by (\\ref{eq.11.omega}).\n\\end{enumerate}", "meta": {"hexsha": "1aa5cc99f2268d1f9e7e477530af4be8ddf3fb87", "size": 13437, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "chapter/11-shm.tex", "max_stars_repo_name": "meridethfrey/phys-207L", "max_stars_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_stars_repo_licenses": ["MIT"], "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/11-shm.tex", "max_issues_repo_name": "meridethfrey/phys-207L", "max_issues_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_issues_repo_licenses": ["MIT"], "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/11-shm.tex", "max_forks_repo_name": "meridethfrey/phys-207L", "max_forks_repo_head_hexsha": "372e7c08b2782171fd56a5204dda7cbdb2d066b3", "max_forks_repo_licenses": ["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.8507462687, "max_line_length": 500, "alphanum_fraction": 0.6031108134, "num_tokens": 2987, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9005297781091839, "lm_q2_score": 0.8333245973817158, "lm_q1q2_score": 0.7504336147730816}}
{"text": "\\subsection{Velocity Field for a Rigid Body}\n\n\n\\begin{frame}{Introduction}\n\\begin{figure}[ht]\n\t\\includegraphics[width=80mm]{images/v_a.png}\n\\end{figure}\n\tLet $M$ be a point in rigid body $(R_1)$. Then $\\vb{r}{M}$ is the position vector of $M$ relative to fixed reference frame $(O_0x_0y_0z_0)$.\n\t\\[\n\t\\vb{r}{M} = \\vb{r}{O} + \\vb{r}{MO} = \\vb{r}{O} + x\\ih+y\\jh+z\\kh\n\t\\]\n\\end{frame}\n\n\\begin{frame}\n\tFor Cartesian coordinates, the following relations are true:\n\t\\[\\begin{cases}\n\t\t\\ih\\cdot\\ih=\\jh\\cdot\\jh=\\kh\\cdot\\kh=1\\\\\n\t\t\\ih\\cdot\\jh=\\jh\\cdot\\kh=\\kh\\cdot\\ih=0\n\t\\end{cases}\\]\n\t\n\tVelocity vector $\\vb{v}{M}=\\xvec[.]{\\bm{r}}_{\\bm{M}}$ with respect to time $t$:\n\t\\[\n\t\\vb{v}{M} = \\vb{v}{O} + \\dot{x}\\ih + \\dot{y}\\jh + \\dot{z}\\kh + x\\frac{d\\ih}{dt} + y\\frac{d\\jh}{dt} + z\\frac{d\\kh}{dt}\n\t\\]\n\t\n\tFor a rigid body, $\\dot{x}=\\dot{y}=\\dot{z}=0$\n\t\\[\n\t\\Rightarrow\\vb{v}{M}=\\vb{v}{O}+x\\frac{d\\ih}{dt}+y\\frac{d\\jh}{dt}+z\\frac{d\\kh}{dt}\n\t\\]\n\\end{frame}\n\n\\begin{frame}\n\tLet $\\vb{\\omega}{} = \\omega_x\\ih + \\omega_y\\jh + \\omega_z\\kh$ be rotational vector of rigid body $(R_1)$. Then\n\t\\[\n\t\\vb{\\omega}{} = (\\frac{d\\ih}{dt}\\cdot\\jh)\\ih+ (\\frac{d\\jh}{dt}\\cdot\\kh)\\jh + (\\frac{d\\kh}{dt}\\cdot\\ih)\\kh\\]\\[\\hskip 13mm=(-\\ih\\cdot\\frac{d\\jh}{dt})\\ih+(-\\jh\\cdot\\frac{d\\kh}{dt})\\jh+(-\\kh\\cdot\\frac{d\\ih}{dt})\\kh\n\t\\]\n\tCombine with the fact that $\\displaystyle \\frac{d\\ih}{dt}\\cdot\\ih=\\frac{d\\jh}{dt}\\cdot\\jh=\\frac{d\\kh}{dt}\\cdot\\kh=0$\\vskip1.25mm\n\t$\\displaystyle \\frac{d\\ih}{dt}=(\\frac{d\\ih}{dt}\\cdot\\ih)\\ih + (\\frac{d\\ih}{dt}\\cdot\\jh)\\jh + (\\frac{d\\ih}{dt}\\cdot\\kh)\\kh= 0\\ih+\\omega_z\\jh-\\omega_y\\kh=\\vb{\\omega}\\times\\ih$\\\\\n\t$\\displaystyle \\frac{d\\jh}{dt}=(\\frac{d\\jh}{dt}\\cdot\\ih)\\ih + (\\frac{d\\jh}{dt}\\cdot\\jh)\\jh + (\\frac{d\\jh}{dt}\\cdot\\kh)\\kh=-\\omega_z\\ih+0\\jh+\\omega_x\\kh=\\vb{\\omega}\\times\\jh$\\\\\n\t$\\displaystyle \\frac{d\\kh}{dt}=(\\frac{d\\kh}{dt}\\cdot\\ih)\\ih + (\\frac{d\\kh}{dt}\\cdot\\jh)\\jh + (\\frac{d\\kh}{dt}\\cdot\\kh)\\kh= \\omega_y\\ih-\\omega_x\\jh+0\\kh=\\vb{\\omega}\\times\\kh$\n\t\\[\n\t\\Rightarrow\\vb{v}{}=\\vb{v}{O}+\\vb{\\omega}{}\\times(x\\ih+y\\jh+z\\kh)\n\t\\]\n\\end{frame}\n\n\\begin{frame}\n\t\\begin{block}{Formula}\n\t\tFor any point of a rigid body, its velocity equation is:\n\t\t\\[\n\t\t\\vb{v}{} = \\vb{v}{O} + \\vb{\\omega}{}\\times\\vb{r}{}\n\t\t\\]\n\t\twhere $\\vb{\\omega}{}\\times \\vb{r}{}$ is the rotational motion of that point with respect to $O$\n\t\n\t\\end{block}\n\t\\emph{Example}\\vskip 2.5mm\n\tIn matrix form, velocity vector $\\vb{v}{M}$ of point $M$ relative to fixed reference frame $(O_0x_0y_0z_0)$ can be written as:\n\t\\[\n\t\\vb{v}{M}=\n\t\\begin{bmatrix}\n\tv_x\\\\v_y\\\\v_z\n\t\\end{bmatrix}=\n\t\\begin{bmatrix}\n\tv_{Ox}+z\\omega_y-y\\omega_z\\\\v_{Oy}+x\\omega_z-z\\omega_x\\\\v_{Oz}+y\\omega_x-x\\omega_y\n\t\\end{bmatrix}=\n\t\\vb{v}{O}+\\vb{\\omega}{}\\times\\vb{r}{MO}\n\t\\]\n\\end{frame}", "meta": {"hexsha": "e59a9670b8ddd6e813618624d909b69fbee33ec6", "size": 2693, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Velocity_field_rigid_body.tex", "max_stars_repo_name": "HungNguyenDang/literate-meme", "max_stars_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Velocity_field_rigid_body.tex", "max_issues_repo_name": "HungNguyenDang/literate-meme", "max_issues_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Finished/velocity_acceleration_analysis_pdf/Sections/Introduction/Velocity_field_rigid_body.tex", "max_forks_repo_name": "HungNguyenDang/literate-meme", "max_forks_repo_head_hexsha": "ed3383576918b6ca1480e45c6ed689c87636fc41", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 40.1940298507, "max_line_length": 211, "alphanum_fraction": 0.6108429261, "num_tokens": 1222, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8807970873650401, "lm_q2_score": 0.8519527982093666, "lm_q1q2_score": 0.7503975432353059}}
{"text": "\\subsection{Modelling vaccine effects}\nWe stratified all model compartments as either vaccinated or unvaccinated and commenced simulations with an fully unvaccinated population. With vaccination roll-out, individuals in the susceptible and recovered compartments move from “unvaccinated” to “vaccinated” at a constant rate representing vaccine administration over time. The daily rate of vaccination is calculated from the vaccine coverage achieved over a given period of time is calculated as $rate_{vac} = \\frac{-log(1-coverage)}{T}$, where coverage represents the targeted proportion of people vaccinated by the end of the roll-out period and \\textit{T} represents the roll-out period.\n\nVaccination is assumed to have two mechanisms of effect: 1) prevention of infection and 2) protection against progressing to severe infection among those infected. A particular vaccine roll-out programme can be simulated to act through these two mechanisms simultaneously. The proportion of the effect that is attributed to preventing infection, $V_p = V_iV_e$ , where $V_i$ $\\in [0,1]$ is the infection prevention efficacy and $V_e$ $\\in [0,1]$ is the overall efficacy (that would be observed in clinical trials). If severity prevention efficacy is denoted $V_s$, since $V_e =V_i+V_s(1-V_i)$ it follows that $V_s =\\frac {V_e(1-V_p)} {1- V_p V_e}$ . For the component of the vaccine effect attributed to infection prevention,\nthe infection risk of vaccinated individuals is reduced by ($1-V_i$). Severity-preventing vaccination reduces the infection fatality rate (IFR) and the probability that an infected individual experiences symptomatic disease. Thus, the vaccine efficacy parameter pertaining to disease severity prevention modifies the splitting proportions of infected individuals between the different clinical categories and the rate of COVID-19-related mortality.", "meta": {"hexsha": "2ae53ee47df8bfa2bdf1bcc83820dc527a5b4bc1", "size": 1864, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/papers/covid_19/projects/sri_lanka/vaccination.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/sri_lanka/vaccination.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/sri_lanka/vaccination.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": 372.8, "max_line_length": 725, "alphanum_fraction": 0.8090128755, "num_tokens": 390, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9653811641488385, "lm_q2_score": 0.7772998611746911, "lm_q1q2_score": 0.7503906448735538}}
{"text": "\\subsection{Contact matrices construction}\n\\label{matrix_construction}\nFor each location $L$ (home, school, work, other locations) the age-specific contact matrix $\\mathbf{C^L} = (c_{i,j}^L) \\in \\mathbb{R}_{+}^{16 \\times 16}$ is defined such that $c_{i,j}^L$ is the average number of contacts that a typical individual aged $i$ has with individuals aged $j$. As there is no contact survey available for Australia that is complete across all age groups, the matrices $\\mathbf{C^L}$ were obtained by extrapolating contact matrices from the United Kingdom, being a country included in the POLYMOD study in 2005 \\cite{RN141}. The original matrices from the United Kingdom are denoted $\\mathbf{Q^L} = (q_{i,j}^L) \\in \\mathbb{R}_{+}^{16 \\times 16}$, where $q_{i,j}^L$ is defined using the same convention as for $c_{i,j}^L$. The matrices $\\mathbf{Q^L}$ were extracted using the R package ``socialmixr'' (v 0.1.8) and then adjusted to account for age distribution differences between Victoria and the United Kingdom.\n\nLet $\\pi_j$ denote the proportion of people aged $j$ in Victoria, and $\\rho_j$ the proportion of people aged $j$ in the United Kingdom. The contact matrices $\\mathbf{C^L}$ were obtained from:\n$$\nc_{i,j}^L = q_{i,j}^L \\times \\frac{\\pi_j}{\\rho_j} . \n$$", "meta": {"hexsha": "7d35c44c5bfac39ddac8aef8d4113573715e437f", "size": 1261, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/papers/covid_19/preprocess/mixing_matrix/contacts_extrapolation_vic.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/preprocess/mixing_matrix/contacts_extrapolation_vic.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/preprocess/mixing_matrix/contacts_extrapolation_vic.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": 157.625, "max_line_length": 938, "alphanum_fraction": 0.7351308485, "num_tokens": 364, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.9284087946129327, "lm_q2_score": 0.8080672181749422, "lm_q1q2_score": 0.7502167119920238}}
{"text": "\\section*{Problem 2 Solution}\n\nSince we are assuming no scattering, at any given time $t$ there are three possible ``fates'' of our neutron in the next infinitesimal timestep, $dt$. These are (1) the particle continues with no decay or interaction, (2) the neutron decays, or (3) the neutron is absorbed. We want to find the probability that, given a destructive event has taken place (situation 2 or 3), the event was decay, rather than absorption. Formally, we write this as \n$$ \\text{p}(E=d | E \\in \\{d,a\\}) $$\n\nwhich we read as ``the instantaneous probability that an event is decay, given the event was decay or absorption.'' Statistically this is equivalent to\n\\begin{equation}\n\\label{prob}\n\\frac{\\text{p}(E=d)}{\\text{p}(E \\in \\{d,a\\}} \\text{ or } \\frac{\\text{p}(d)}{\\text{p}(d) + \\text{p}(a)}.\n\\end{equation}\n(If you're not comfortable with the statistics here, you can reason through this intuitively. We have some event occuring, being either a decay or an absorption collision. The probability of that event depends on the individual probabilities of the independent events, decay and absorption. The probability of that event being a decay is just the fraction of the event's total probability that is attributable to the decay.)\n\nFrom here on, we will write the argument of the probality function as a subscript, which will allow us to note the probability's dependence on either time or space. (For example, $\\text{p}(d) \\rightarrow \\text{p}_d$.)\n\nNow, we know that the exponential decay law is $N(t) = N_0 e^{-\\lambda t}$. The probability that a neutron decays in some time $t$ is then\n$$ P_d(t) = 1-\\frac{N(t)}{N_0} = 1-e^{-\\lambda t} $$\nWe can calculate that the instantantaneous probability that a neutron decays between times $t$ and $t+dt$ is \n$$ \\frac{dP_d(t)}{dt} = \\lambda e^{-\\lambda t} $$\nFrom this equation, we note that $dP_d(t) = p_d(t)dt$. Remember, $P_d(t)$ is the total probability of decay, and so $p_d(t)$ is the instantaneous probability of decay per time. When multiplied by $dt$, this is $\\text{p}_d(t)$.\n$$ \\text{p}_d(t) = p_d(t) \\, dt = \\lambda e^{-\\lambda t} dt $$\nWe rewrite this equation in terms of $N(t)$, and  \n$$ \\text{p}_d(t) = \\frac{\\lambda N(t)}{N_0} dt$$\n\nAdditionally, we know that the attenuation of neutrons moving through a material also follows an exponential function. The number of neutrons remaining after traveling through a material with macroscopic absorption cross section $\\Sigma_a$, is\n$$ N(x) = N_0 e^{-\\Sigma_a x} $$\n(note: $\\Sigma_a = \\sigma_a n$, where $\\sigma_a$ is the microscopic absorption cross section and $n$ is the number density of the material in question) \n\nWe repeat the procedure from above, but now in space rather than time. The probability for a collision is\n$$ P_a(x) = 1-\\frac{N(x)}{N_0} = 1 - e^{-\\Sigma_a x} $$\nand the instantaneous probability is \n$$ \\frac{dP_a(x)}{dt} = \\Sigma_a e^{\\Sigma_a x} $$\nor \n$$ \\text{p}_a(x) = p_a(x) \\, dx = \\Sigma_a e^{\\Sigma_a x} dx .$$\nAgain, eliminating $dx$ and writing in terms of $N(x)$, we have\n$$ \\text{p}_a(x) = \\frac{\\Sigma_a N(x)}{N_0} dx $$\nNow, we observe that using $\\text{p}_d(t)$ and $\\text{p}_a(x)$ in equation (\\ref{prob}) causes all terms to be dependent on $N$, the number of neutrons. Unfortunately, we have $p_d$ reliant on $N(t)$, the number of neutrons surviving until time $t$, and $\\text{p}_a$ reliant on $N(x)$, the number of neutrons reaching distance $x$. We are told, however, that these neutrons are thermal, and so are moving at $v = 2200$m/s. If we say $dx = v \\, dt$, then we can rewrite $N(x) dx$ as a function of time! \n$$ N(x) \\, dx = N(t) v \\, dt $$\nand\n$$ \\text{p}_a(t) = \\frac{\\Sigma_a N(t) v}{N_0} dt $$\nFinally, we do substitute this into equation (\\ref{prob}), and get\n\\begin{align*}\n\\text{p}(E=d | E \\in \\{d,a\\})\t&= \\frac{\\frac{\\lambda N(t)}{N_0} dt}{\\frac{\\lambda N(t)}{N_0} dt + \\frac{\\Sigma_a N(t) v}{N_0} dt}\\\\\n\t\t\t\t\t\t\t\t&= \\frac{\\lambda}{\\lambda + \\Sigma_a v}\\\\\n\t\t\t\t\t\t\t\t&= \\left(1 + \\frac{\\Sigma_a v}{\\lambda}\\right)^{-1}\\\\\n\\end{align*}\nWe can look up $\\Sigma_a$ to find it is approximately $0.022\\text{ cm}^{-1}$ (or $2.2\\text{ m}^{-1}$, and can calculate that 10.2 minutes is 612 seconds.  Using this, along with $v = 2200$ m/s, and $\\lambda = \\frac{\\ln 2}{612} = 1.13\\times10^{-3}\\text{ s}^{-1}$, we can find the probability.\n$$ \\text{p}(E=d | E \\in \\{d,a\\}) = \\left(1 + \\frac{(2.2\\text{ m}^{-1})(2200\\text{ m/s})}{1.13\\times10^{-3}\\text{ s}^{-1}}\\right)^{-1} $$\n$$\\boxed{ \\text{p}(E=d | E \\in \\{d,a\\}) = 2.33\\times10^{-7} }$$\n\n", "meta": {"hexsha": "79a44368aef78f962770454f0686d39f0618728d", "size": 4495, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "exercises/drafts/disc02/disc02_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/disc02/disc02_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/disc02/disc02_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": 89.9, "max_line_length": 502, "alphanum_fraction": 0.6760845384, "num_tokens": 1437, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8652240877899776, "lm_q1q2_score": 0.7501802243561233}}
{"text": "\\chapter{Number Theory}\n\n\\section{Misc}\n\n\\subsection{Geometric Series}\nThe geometric series is defined as \n\\begin{align}\n\t\\sum_{n=0}^{N-1} ar^n =a\\Big( \\frac{1-r^{N}}{1-r}\\Big)\n\\end{align}\nWhich is only convergent for $r < 1$. To prove it, let's call whatever the value of the total series is equal to $s$, so we have\n\\begin{align}\n\ts = a + ar + ar^2 + ar^3 + ... + ar^{N-1}\n\\end{align}\nLet's multiply it by $r$\n\\begin{align}\n\trs =  ar + ar^2 + ar^3 + ... + ar^{N}\n\\end{align}\nWe recognize that the portion on the right is basically the same as the earlier expression for $s$, so let's plug in exactly what that is\n\\begin{align}\n\trs = (s - a) + ar^N\n\\end{align}\nRearranging this, we find\n\\begin{align}\n\t(r-1)s = a(r^N - 1)\n\\end{align}\nDividing through, we see that\n\\begin{align}\n\t\\sum_{n=0}^{N-1} ar^n = s = a\\Big( \\frac{1-r^{N}}{1-r}\\Big)\n\\end{align}\n\n\n\\subsection{Completing the Square}\nIf we have some function that looks like\n\\begin{align}\nax^2 + bx + c\n\\end{align}\nand we want it to look like\n\\begin{align}\nd(x+e)^2 + f\n\\end{align}\nWe have that \n\\begin{align}\nax^2 + bx + c = dx^2 + 2ed x + de^2 + f\n\\end{align}\nMatching powers of $x$, we get that\n\\begin{align}\na &= d\\\\\nb &= 2ed\\\\\nc &= de^2+f\n\\end{align}\nSolving these gives us\n\\begin{align}\nd = a && e =\\frac{b}{2a}  && f = c-\\frac{b^2}{4a}\n\\end{align}\n\n\n\n\n\\subsection{Trigonometric Identities}\n\n\\begin{align}\n\\sin(\\alpha\\pm\\beta) = \\sin\\alpha\\cos\\beta\\pm\\cos\\alpha\\sin\\beta\\\\\n\\cos(\\alpha\\pm\\beta) = \\cos\\alpha\\cos\\beta\\mp\\sin\\alpha\\sin\\beta\n\\end{align}\n\nWith these identities we can derive the double angle formula, setting $\\alpha = \\beta$ so\n\\begin{align}\n\\cos2\\alpha &= \\cos^2\\alpha -\\sin^2\\alpha\\\\\n&= 2\\cos^2\\alpha-1\n\\end{align}\nThe Law of Cosines is \n\\begin{align}\nc^2 = a^2 + b^2 -2ab\\cos\\theta\n\\end{align}\nWhere $\\theta$ is the angle between $a$ and $b$. Can remember this because reduces to the Pythagorean Theorem for $\\theta = \\pi/2$ and when $\\theta = \\pi$ we have\n\\begin{align}\nc^2 = a^2 + b^2 +2ab = (a+b)^2\n\\end{align}\nA much simpler way to recover this same identity is to draw out the vectors themselves\n\\begin{align}\n\t\\textbf{a} + \\textbf{c} = \\textbf{b} \\rightarrow \\textbf{c} = \\textbf{a} - \\textbf{b}\n\\end{align}\nLooking at the square of this, we have\n\\begin{align}\n\tc^2 &= a^2 + b^2 - 2\\textbf{a}\\cdot\\textbf{b}\\\\\n\t&= a^2 + b^2 -2ab\\cos\\theta \n\\end{align}\n\nYou can always remember the derivatives of a trigonometric function by looking at it's Taylor expansion, and taking the derivative of that\n\\begin{align}\n\t\\sin x &= x - \\frac{x^3}{3!} + \\frac{x^5}{5!} + ...\\\\\n\t\\cos x &= 1 - \\frac{x^2}{2!} + \\frac{x^4}{41} + ...\n\\end{align}\nTaking the derivative of sin for instances gives us\n\\begin{align}\n\t\\frac{d}{dx}\\sin x &= \\frac{d}{dx}\\Big( x - \\frac{x^3}{3!} + \\frac{x^5}{5!} + ...\\Big)\\\\\n\t&= 1 - \\frac{x^2}{2!} + \\frac{x^4}{41} + ...\\\\\n\t&= \\cos x\n\\end{align}\n\n\\subsection{Polynomial Algebra}\n\nCan find roots of polynomial equations with\n$$\n\\begin{array}{rc@{}c@{}c@{}c@{}}\n& -x^2 +& x + &2 & \\\\ \\cline{2-4}\n\\multicolumn{1}{r|}{x+1} &-x^3+ & 0 + & 3x +&2\\\\\n-&-x^2 -&x  &\\\\ \\cline{2-3}\n& 0 +& x^2 &\\\\ \n-&  & x^2 +&x\\\\ \\cline{3-4}\n& & 0 +&2x &\\\\ \n-& &  &2x +&2\\\\ \\cline{4-5}\n& & & &0\\\\\n\\end{array}\n$$\n\n\\section{Combinatorics}\nA critical combinatorics formula is \n\\begin{align}\n{{n}\\choose{k}} = \\frac{n!}{k!(n-k)!}\n\\end{align}\nWhich tells us how may ways we can pick $k$ objects out of a total of $n$ of them. Obviously we should have $n>k$, so the number is positive, which means we should have $n$ on the top.\n\n\n\\subsection{Euclidean Algorithm}\n\nIf you have two numbers that you don't know the prime factorization of, one can find their greatest common denominator (qcd) using this algorithm. \n\\begin{enumerate}\n\\item Choose two numbers $N_1, N_2$ \n\\begin{itemize}\n\\item\te.g. $57, 27$\n\\end{itemize}\n\\item Subtract the smaller of the two from the larger $\\max(N_1,N_2) -\\min(N_1,N_2)$\n\\begin{itemize}\n\\item\t$57 -27 = 30$\n\\end{itemize}\n\\item Continue to subtract $\\min(N_1,N_2)$ until you're about to get negative numbers\n\\begin{itemize}\n\\item $30 -27 = 3$\n\\end{itemize}\n\\item This number is the greatest common denominator of the two\n\\begin{itemize}\n\\item $3\\times 19 = 57$\n\\item $3 \\times 9 = 27$\n\\end{itemize}\n\\end{enumerate}\n\n\\subsection{Modular Arthimetic}\nTODO\n\n\\section{Distributions}\n\\subsection{Binomial Distribution}\nThe Binomial distribution is given by\n\\begin{align}\nP(k;n,p) = \\begin{pmatrix}\nn\\\\\nk\n\\end{pmatrix}p^k(1-p)^{n-k}\n\\end{align}\nWhere \n\\begin{align}\n\\begin{pmatrix}\nn\\\\\nk\n\\end{pmatrix} = \\frac{n!}{k!(n-k)!}\n\\end{align}\nWhich tells us, if we try something $n$ times, each of which has a chance $p$ of succeeding, that we get $k$ successes. \n\n\\subsection{Poisson Distribution}\nThe Poisson distribution is used to describe the distribution of discrete events over a given time or space interval. Consider a radioactive decay process which has $\\lambda$ decays per minute. \n\nFor a process which obey's Binomial statistics, we have a set amount of times the event could happen $n$ and a proportion of successes $k$. For a Poisson process the time or space interval could in principle be broken up infinitely, making it such that we don't just count over a set number of dice rolls, effectively infinitely many of them. Thus we take the limit $n\\rightarrow \\infty$ of the Binomial distribution with\n\\begin{align}\np = \\frac{\\lambda}{n}\n\\end{align}\nWhich tells us that the probability of the event happening at any given time is $0$, but as we will see, will give us a property such that a finite amount of events are seen when we are done counting. Mathematically we find\n\n\\begin{align}\nP(k; \\mu) &= \\lim_{n\\to \\infty} \\frac{n(n-1)(n-2)...(n-k+1)}{k!}\\left(\\frac{\\lambda}{n}\\right)^k\\left(1-\\frac{\\lambda}{n}\\right)^{n-k}\\\\\n&= \\lim_{n\\to \\infty}\\frac{n^k}{k!}\\frac{\\lambda^k}{n^k}\\left(1-\\frac{\\lambda}{n}\\right)^{n-k}\n\\end{align}\nUsing the definition of the exponential function we arrive at the Poisson distribution with\n\\begin{align}\nP(k; \\lambda) = \\frac{\\lambda^ke^{-\\lambda}}{k!}\n\\end{align}\n\nThus the Poisson distribution is a limiting case of the Binomial distribution when the number of dice rolls is infinite, but the amount of events we observe remain finite.\n\nIn counting experiments, it is often useful to know that if 0 events are observed coming from a Poisson distribution, the one-sided 95\\% upper limit on the number of events is $\\approx 3$, which is consistent with\n\\begin{align}\n\t\\frac{3^0e^{-3}}{0!} \\approx 0.05\n\\end{align}\nSince the confidence interval tells us a model with true parameter $\\lambda=3$ has a 5\\% chance to see 0 events. In particle physics, $\\lambda=3$ is held as a the benchmark for if your theory is testable or not, if $\\lambda < 3$ you have a large chance that even if your theory is correct, you would still see nothing. \n\n\n\n\\subsection{Gaussian Distribution}\nAnother distribution shows up in the case where $\\lambda$ becomes so large that Stirling's approximation (Section \\ref{stirling}) becomes valid. If we take a Poisson distribution with  $k = \\lambda(1+\\delta) \\equiv x$ with $\\lambda \\gg 1, \\delta \\ll 1$ we can write\n\\begin{align}\n\tP(x; \\lambda) &= \\frac{\\lambda^xe^{-\\lambda}}{x!}\\\\\n\t&= \\frac{\\lambda^{\\lambda(1+\\delta)}e^{-\\lambda}}{\\lambda(1+\\delta)!}\n\\end{align}\nUsing Stirling's approximation, one has\n\\begin{align}\n\t\tP(x; \\lambda) &\\approx \\frac{\\lambda^{\\lambda(1+\\delta)}e^{-\\lambda}}{\\sqrt{2\\pi}e^{-\\lambda(1+\\delta)}(\\lambda(1+\\delta))^{\\lambda(1+\\delta)+1/2}}\\\\\n\t\t&\\approx \\frac{e^{-\\lambda\\delta}}{\\sqrt{2\\pi\\lambda}} (1+\\delta)^{-\\lambda(1+\\delta)-1/2}\n\\end{align}\nExpanding the last term around $\\delta=0$, we have\n\\begin{align}\n\t(1+\\delta)^{-\\lambda(1+\\delta)-1/2} &\\approx 1 + \\delta*(\\lambda+1/2) + \\dots\n\\end{align} \nTODO\n\nIn summary:\n\\begin{itemize}\n\t\\item Poisson is limit of binomial for $p$ small and $n\\gg \\mu$\n\t\\item Gaussian is limit of Poisson for large $\\mu$\n\t\\item Gaussian is limit of binomial for large $\\mu=np$\n\\end{itemize}\n\n\n\n", "meta": {"hexsha": "1c78821792e003f94589c90ef7e4387df4ce1fc2", "size": 7904, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "mathematics/numbertheory.tex", "max_stars_repo_name": "williamnash/notes", "max_stars_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "mathematics/numbertheory.tex", "max_issues_repo_name": "williamnash/notes", "max_issues_repo_head_hexsha": "6f89e27c51a1c0e14b3a24eab825299fb406fc2f", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 5, "max_issues_repo_issues_event_min_datetime": "2020-08-23T23:01:48.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-16T23:17:43.000Z", "max_forks_repo_path": "mathematics/numbertheory.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": 35.4439461883, "max_line_length": 421, "alphanum_fraction": 0.6804149798, "num_tokens": 2708, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8670357598021707, "lm_q2_score": 0.8652240756264639, "lm_q1q2_score": 0.750180213809922}}
{"text": "\\section{Applications of the determinant}\n\n\\begin{outcome}\n  \\begin{enumerate}\n  \\item Use determinants to determine whether a matrix has an inverse,\n    and evaluate the inverse using cofactors.\n  \\item Apply Cramer's rule to solve a $2\\times 2$ or a $3\\times 3$\n    linear system.\n  \\item Given data points, find an appropriate interpolating\n    polynomial and use it to estimate points.\n  \\end{enumerate}\n\\end{outcome}\n", "meta": {"hexsha": "b79a7591977a01fbc63f17c986f6fb5845eb2c38", "size": 422, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "old/content/determinantsApplications.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/determinantsApplications.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/determinantsApplications.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.4615384615, "max_line_length": 70, "alphanum_fraction": 0.7440758294, "num_tokens": 107, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8933094003735664, "lm_q2_score": 0.8397339696776499, "lm_q1q2_score": 0.7501422489260561}}
{"text": "\\lab{A Pseudospectral method for periodic functions}{A Pseudospectral method for periodic functions}\n\\label{lab:pseudospectral2}\n\n\\objective{\n% We study traveling wave solutions of the Korteweg-de Vries (KdV) equation. \nWe look at a pseudospectral method with a Fourier basis, and numerically solve the advection equation using a pseudospectral discretization in space and a Runge-Kutta integration scheme in time.  }\n\n% \\section{A Pseudospectral method for periodic functions}\nLet $f$ be a periodic function on $[0,2\\pi]$. Let $x_1,\\ldots,x_N$ be $N$ evenly spaced grid points on $[0,2\\pi].$ Since $f$ is periodic on $[0,2\\pi]$, we can ignore the grid point $x_0 = 0$. We will further assume that $N$ is even; similar formulas can be derived for $N$ odd. Let $h = 2\\pi/N$; then $\\{x_1,\\ldots,x_N\\} = \\{h,2h,\\ldots,2\\pi-h,2\\pi\\}$.  \n\nThe discrete Fourier transform (DFT) of $f$, denoted by $\\hat{f}$ or $\\mathcal{F}(f)$, is given by\n\\[\n\\hat{f}(k) = h \\sum_{j=1}^N e^{-ikx_j}f(x_j) \\quad \\text{ where } k = -N/2+1, \\ldots,0,1,\\ldots, N/2.\n\\]\nThe inverse DFT is then given by\n\\begin{align}\n\\begin{split}\nf(x_j) &= \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2}\\frac{e^{ikx_j}}{c_k}\\hat{f}(k), \\quad j = 1,\\ldots, N,\n% \\\\\n% &= \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2}\\!\\!{}^{'} e^{ikx_j}\\hat{f}(k), \\quad j = 1,\\ldots, N, \n\\end{split}\\label{inverse_dft}\n\\end{align}\nwhere %$\\sum_{k=-N/2}^{N/2}\\!\\!{}^{'}$ is used to denote...\n\\begin{align}\n\tc_k = \\begin{cases} 2 & \\text{if }k = -N/2 \\text{ or }k = N/2, \\\\ 1 &  \\text{otherwise.}\n\\end{cases}\n\\end{align}\nThe inverse DFT can then be used to define a natural interpolant (sometimes called a band-limited interpolant) by evaluating (\\ref{inverse_dft}) at any $x$ rather than $x_j$:\n\\begin{align}\np(x) = \\frac{1}{2\\pi}\\sum_{k=-N/2}^{N/2} e^{ikx}\\hat{f}(k). \\label{interpolant}\n\\end{align}\nThe interpolant for $f'$ is then given by \n\\begin{align}\np'(x) = ik \\frac{1}{2\\pi}\\sum_{k=-N/2+1}^{N/2-1} e^{ikx}\\hat{f}(k). \\label{spectral2:deriv}\n\\end{align}\n\n\nConsider the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$. \nUsing \\eqref{spectral2:deriv}, the derivative $u'$ may be approximated with the following code.  \\footnote{See \\textit{Spectral Methods in MATLAB} by Lloyd N. Trefethen.  Another good reference is \\textit{Chebyshev and Fourier Spectral Methods} by John P. Boyd.}\nWe note that although we only approximate $u'$ at the Fourier grid points, \\eqref{spectral2:deriv} provides an analytic approximation of $u'$ in the form of a trigonometric polynomial.\n\n\\begin{lstlisting}\nimport numpy as np\nfrom scipy.fftpack import fft, ifft\nimport matplotlib.pyplot as plt\n\nN=24\nx1 = (2.*np.pi/N)*np.arange(1,N+1)\nf = np.sin(x1)**2.*np.cos(x1) + np.exp(2.*np.sin(x1+1))\n\n\nk = np.concatenate(( np.arange(0,N/2) ,\n\t\t\t\t\t np.array([0])\t, # Because hat{f}'(k) at k = N/2 is zero.\n\t\t\t\t\t np.arange(-N/2+1,0,1)\t))\n\n# Approximates the derivative using the pseudospectral method\nf_hat = fft(f)\nfp_hat = ((1j*k)*f_hat)\nfp = np.real(ifft(fp_hat))\n\n# Calculates the derivative analytically\nx2 = np.linspace(0,2*np.pi,200)\nderivative = (2.*np.sin(x2)*np.cos(x2)**2. - \n\t\t\t\tnp.sin(x2)**3. + \n\t\t\t\t2*np.cos(x2+1)*np.exp(2*np.sin(x2+1))\n\t\t\t\t)\n\nplt.plot(x2,derivative,'-k',linewidth=2.)\nplt.plot(x1,fp,'*b')\nplt.savefig('spectral2_derivative.pdf')\nplt.show()\n\n\\end{lstlisting}\n\n\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{spectral2_derivative.pdf}\n\\caption{The derivative of $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.}\n\\label{fig:spectral:spectral2_derivative}\n\\end{figure}\n\n\\begin{problem}\nConsider again the function $u(x) = \\sin^2 (x) \\cos(x) +e^{2\\sin(x+1)}$.\nCreate a function that approximates $\\frac{1}{2}u''-u'$ on the Fourier grid points for a given $N$.\t\n\\end{problem}\n\n% \\begin{lstlisting}\n% import numpy as np\n% import matplotlib.pyplot as plt\n% \n% # Solve the ODE $u_{xx} = e^u,$ with boundary conditions\n% #  $u(0) = u(2\\pi) = 0$\n% \n% \n% \\end{lstlisting}\n\n\n% \\begin{problem}\n% The motion of a damped pendulum can be described by the ODE\n% \t\\begin{align}\n% \t\\theta'' + \\theta' +\\sin \\theta = 0. \\label{damped_pendulum}\n% \t\\end{align}\n% Using the pseudospectral method, solve \\eqref{damped_pendulum} on the interval $[0,2\\pi]$, with the boundary conditions $\\theta(0) = \\theta(2\\pi) =0$. Produce at least two unique solutions.\n% \\end{problem}\n\n% \\section{The KdV equation}\n% \n% There are canonical model equations for various types of phenomena.  Long, small amplitude waves moving in one direction can generally be described by the  Korteweg-de Vries (KdV) equation. The KdV equation is given by \n% \\[  \\frac{\\partial u }{\\partial t} + u \\frac{\\partial u}{\\partial x} + \\frac{\\partial^3 u}{\\partial x^3} = 0.\n% \\]\n% \n% The KdV equation possesses traveling wave solutions called solitary waves. These traveling waves have the form \n% \\[ u(x,t) = 3\\alpha^2 \\sech^2(\\alpha(x-x_0)/2 - \\alpha^3 t).\n% \\]\n% \n% History of solitons: first observed by John Scott Russell in 1834. \n% Solution form:  \n% Interaction of solitons: \n% \n% Solitons versus solitary waves. I believe solitary waves are solitons in a fluid dynamics context. \n% John Russell \n\n\n\\section*{The advection equation}\nRecall that the advection equation is given by\n\\begin{align}\n&{ }u_t + cu_x = 0\n\\end{align}\nwhere $c$ is the speed of the wave (the wave travels to the right for $c > 0$).\nWe will consider the solution of the advection equation on the circle; this essentially amounts to solving the advection equation on $[0,2\\pi]$ and assuming periodic boundary conditions. \n\nA common method for solving time-dependent PDEs is called the \\textit{method of lines}. To apply the method of lines to our problem, we use our Fourier grid points in $[0,\\pi]$: given an even $N$, let $h = 2\\pi/N$, so that $\\{x_1,\\ldots,x_N\\} = \\{h,2h,\\ldots,2\\pi-h,2\\pi\\}$.  By using these grid points we obtain the collection of equations\n\\begin{align}\n&{ }u_t(x_j,t) + cu_x(x_j,t) = 0, \\quad t >0, \\quad j = 1, \\ldots N. \\label{spectral2:method_oflines}\n\\end{align}\n\nLet $U(t)$ be the vector valued function given by $U(t) = (u(x_j,t))_{j=1}^N$.\nLet $\\mathcal{F}(U)(t)$ denote the discrete Fourier transform of $u(x,t)$ (in space), so that \n\\[\n\\mathcal{F}(U)(t) = (\\hat{u}(k,t))_{k=-N/2+1}^{N/2}.\n\\]\nDefine $\\mathcal{F}^{-1}$ similarly.\nUsing the pseudospectral approximation in space leads to the system of ODEs\n\\begin{align}\n\tU_t +  \\vec{c}\\mathcal{F}^{-1}\\left(i\\vec{k}\\mathcal{F}(U) \\right) = 0\n\\end{align}\nwhere $\\vec{k}$ is a vector, and $\\vec{k}\\mathcal{F}(U) $ denotes element-wise multiplication. \nSimilarly $\\vec{c}$ could also be a vector, if the wave speed $c$ is allowed to vary. \n\n\n\\begin{problem}\n\tUsing a fourth order Runge-Kutta method (RK4), solve the initial value problem \n\t\\begin{align}\n\t\tu_t +c(x) u_x = 0,\n\t\\end{align}\n\twhere $c(x) = .2 + \\sin^2(x-1)$, and $u(x,t=0) = e^{-100(x-1)^2}.$  Plot your numerical solution from $t = 0$ to $t = 8$.  Note that the initial data is nearly zero near $x = 0$ and  $2 \\pi$, and so we can use the pseudospectral method. \\footnote{This problem is solved in \\textit{Spectral Methods in MATLAB} using a leapfrog discretization in time. } \n\t\\label{spectral2:advection_equation}\n\\end{problem}\n\n\n\n\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{advection.png}\n\\caption{The solution of the variable speed advection equation; see Problem  \\ref{spectral2:advection_equation}.}\n\\label{fig:spectral:spectral2_advection}\n\\end{figure}\n\n\n\n\n\n", "meta": {"hexsha": "b0149981a72bfb4077f29a8f27dc63696903e35f", "size": 7381, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Labs/Spectral2/Spectral2.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/Spectral2/Spectral2.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/Spectral2/Spectral2.tex", "max_forks_repo_name": "jessicaleete/numerical_computing", "max_forks_repo_head_hexsha": "cc71f51f35ca74d00e617af3d1a0223e19fb9a68", "max_forks_repo_licenses": ["CC-BY-3.0"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-05-14T16:07:59.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-20T09:05:06.000Z", "avg_line_length": 41.9375, "max_line_length": 354, "alphanum_fraction": 0.6839181683, "num_tokens": 2550, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8933093975331752, "lm_q2_score": 0.8397339616560072, "lm_q1q2_score": 0.7501422393750742}}
{"text": "\\documentclass{article}\n\n\\usepackage{amsmath} % allows you to put text in the math environment.\n\n\\begin{document}\n\n\\title{Some Examples of Equation-Writing in \\LaTeX}\n\\author{Doreen De Leon\\\\Department of Mathematics, UCLA}\n\\date{December 20, 2002}\n\\maketitle\n\n\\section{Writing a Simple Equation}\n\\label{sec:simple}\n\\setcounter{equation}{0} % sets equation counter to 1\n\nTo display an unnumbered equation on a new line, just type:\n\\emph{$\\backslash$[ x' = 2x - 3 $\\backslash$]}.  This will display as:\n\\[ x' = 2x - 3 \\]\nIf we want to get a numbered equation, we must type:\\\\\n\\emph{$\\backslash$begin\\{equation\\}\\\\x' = 2x - 3\\\\$\\backslash$end\\{equation}\\}.\nThis will display as:\n\\begin{equation}\nx' = 2x - 3\n\\end{equation}\n\nNow, suppose we want to write a differential equation in another form.\nTry, \\emph{$\\backslash$[$ \\backslash$frac\\{dy\\}\\{dt\\} = 2y + 8 $\\backslash$]}.\nThis displays as:\n\\[ \\frac{dy}{dt} = 2y + 8 \\]\nor, we may write \\emph{\\$\\$ y\\_t = 2y + 8\\$\\$}:\n$$ y_t = 2y + 8 $$\n\nNow, suppose we have a partial differential equation.\nTo write it with the partial derivatives, we just do:\\\\\n\\emph{\\$\\$ $\\backslash$frac\\{$\\backslash$partial\\^2 u\\}\n    \\{$\\backslash$partial\\^2 x\\} + $\\backslash$frac\\{$\\backslash$partial\\^2 u\\}\n    \\{$\\backslash$partial\\^2 y\\} = 0 \\$\\$}.\nThis displays as:\n$$ \\frac{\\partial^2 u}{\\partial^2 x} +\n\\frac{\\partial^2 u}{\\partial^2 y} = 0 $$\nOr, we may write \\emph{\\$\\$ u\\_\\{xx\\} + u\\_\\{yy\\} = 0 \\$\\$}, which displays as:\n$$ u_{xx} + u_{yy} = 0 $$\n\nTo add text to an equation do for example,:\\\\\n\\emph{\\$\\$ y=mx+b, $\\backslash$text\\{ where \\$m\\$ is the slope, \\} x\n      $\\backslash$in (-$\\backslash$infty, $\\backslash$infty) \\$\\$}.\nThis displays as:\n$$ y=mx+b, \\text{ where $m$ is the slope, } x \\in (-\\infty, \\infty) $$.\nNote: You need to have included the \\texttt{amstext} package at the beginning\nof the document (after the \\emph{$\\backslash$documentclass} command.\n\nIf we want to write an equation with a two-line right-hand-side,\n\\begin{equation}\ny(0) = \\left\\{ \\begin{array}{cc}\n              1 & \\mbox{if $x \\le 0$, }\\\\\n              -1 & \\mbox{if $x > 0$.}\n             \\end{array} \\right.\n\\end{equation}\n\n% Note:  The single dollar sign puts us into math mode.  The double dollar\n% sign puts us into the equation mode.\n\nTo write several equations together, we do the following:\n\\begin{eqnarray}\n\\label{eqn:wave}\nu_t + u_x & = & 0 \\nonumber \\\\\nu(x, 0) & = & \\left\\{ \\begin{array}{cc}\n              1 & \\mbox{if $x \\le 0$, }\\\\\n              -1 & \\mbox{if $x > 0$.}\n             \\end{array} \\right.\n\\end{eqnarray}\n\n\n\\section{More complicated expressions}\n\\label{comp}\n\\setcounter{equation}{0}\n\nHere is how we would write a matrix:\n$ A = \\left( \\begin{array}{ccc} a_{11} \\hspace{1mm} a_{12} \\hspace{1mm}\n                                    \\ldots \\hspace{1mm} a_{1n} \\\\\n                              a_{21} \\hspace{1mm} a_{22} \\hspace{1mm}\n                                     \\ldots \\hspace{1mm} a_{2n} \\\\\n                              \\vdots \\hspace{6mm} \\vdots \\hspace{11mm} \\vdots \\\\\n                              a_{n1} \\hspace{1mm} a_{n2} \\hspace{1mm}\n                                     \\ldots \\hspace{1mm} a_{nn}\n              \\end{array}  \\right) $\n\n\nTo write a system of equations:\n\\begin{equation}\n\\label{eq:pred}\n\\left\\{  \\begin{array}{c}\n                        x'  =  3x - 2y + 3xy, \\nonumber \\\\\n                        y'  =  2x - 3y - 2xy, \\\\\n                        x(0)  =  0, \\nonumber \\\\\n                        y(0)  =  1 \\nonumber\n           \\end{array}  \\right.\n\\end{equation}\n\n\\end{document}\n", "meta": {"hexsha": "b7435dbde332c26cd1fa5fa8156b714d81117563", "size": 3555, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "equations.tex", "max_stars_repo_name": "perfectbark/LaTex2Docx", "max_stars_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 23, "max_stars_repo_stars_event_min_datetime": "2019-06-16T06:00:39.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T14:44:32.000Z", "max_issues_repo_path": "equations.tex", "max_issues_repo_name": "hao-han/LaTex2Docx", "max_issues_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "equations.tex", "max_forks_repo_name": "hao-han/LaTex2Docx", "max_forks_repo_head_hexsha": "e32f9dcc59cce7bea4e7b114687b2300c623d8c0", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 12, "max_forks_repo_forks_event_min_datetime": "2019-05-27T06:32:06.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T10:22:07.000Z", "avg_line_length": 35.198019802, "max_line_length": 80, "alphanum_fraction": 0.5721518987, "num_tokens": 1231, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8633916205190226, "lm_q2_score": 0.8688267830311354, "lm_q1q2_score": 0.7501377641515813}}
{"text": "\n\\section{Constraint Logic Programming}\n\\label{sec:constr-logic-progr}\n\nProlog is based on unification. Data of the program are terms, and\nunification solves equations between terms. A natural extension to\nthis is to allow for other types of equations, for example, arithmetic\nequations, inequations, or disequations. This is what Constraint Logic\nProgramming (CLP) does, providing the mechanisms to solve arithmetic\nconstraints. See~\\cite{marriot-stuckey-98} for a good introduction to\nCLP. \n\nThe Ciao packages for CLP allow for constraints over arithmetic\nexpressions. Constraints include equations, inequations, and\ndisequations. Constraints are expressed using the operators:  \n\\begin{quote}\n\\begin{verbatim}\n.=.   .<>.   .<.   .=<.   .>.   .>=.\n\\end{verbatim}\n\\end{quote}\n%\nfor equalities (\\verb+.=.+), inequalities (\\verb+.<>.+), and\ndisequalities between two arithmetic expressions.\n%\nExpressions are built with the usual arithmetic operators, numbers,\nand variables. \n%\nFor example:\n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .=. 5, X-Y .=. 2, ...\n\\end{verbatim}\n\\end{quote}\n%\nsets up a system of equations that CLP will solve, yielding:\n\\begin{quote}\n\\begin{verbatim}\nY .=. 1.5,\nX .=. 3.5 \n\\end{verbatim}\n\\end{quote}\n%\nand the disequalities:\n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .>=. 5, X-Y .=<. 2, ...\n\\end{verbatim}\n\\end{quote}\n%\nset up a system of disequations, the solution of which can only be\nparametric (because there is not a unique solution). CLP will yield:\n\\begin{quote}\n\\begin{verbatim}\nX. >=. 5.0-Y,\nX .=<. 2.0+Y\n\\end{verbatim}\n\\end{quote}\n%\nin this case. Note how variable \\verb+Y+ acts as a parameter of the\nsolution. Once a value is assigned to \\verb+Y+, the value(s) of \\verb+X+\nis determined by the above solution inequations. For example:\n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .>=. 5, X-Y .=<. 2, ..., Y .=. 0, ...\n\\end{verbatim}\n\\end{quote}\n%\nmakes CLP answer ``no'', because for a value 0 for \\verb+Y+ there are\nno values for \\verb+X+ that satisfy the inequations. However:\n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .>=. 5, X-Y .=<. 2, ..., Y .=. 2, ...\n\\end{verbatim}\n\\end{quote}\n%\nyields:\n\\begin{quote}\n\\begin{verbatim}\nX.>=.3.0,\nX.=<.4.0,\nY.=.2.0 \n\\end{verbatim}\n\\end{quote}\n%\nsince any real number between (and including) 3 and 4 satisfies the\nsolution. \n\nYou can mix equations, inequations, and disequations arbitrarily. You\ncan also mix constraints with the classical unification and Prolog\narithmetic operator \\verb+arithmetic:is/2+. \n\nHowever, note that unification manipulates terms, which include\nnumbers and expressions that may ``look like'' arithmetic expressions,\nbut are not evaluated. Thus: \n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .>=. 5, X-Y .=<. 2, ..., Y = 2, ...\n\\end{verbatim}\n\\end{quote}\n%\nyields the same solution as above, but:\n\\begin{quote}\n\\begin{verbatim}\n... :- ..., X+Y .>=. 5, X-Y .=<. 2, ..., Y = 1+1, ...\n\\end{verbatim}\n\\end{quote}\n%\nfails, since \\verb-1+1- is not a number, and can not participate in\nexpressions involved in constraints.\n\nThe particular domain of numbers which can be involved in constraints\nconditions the particular constraint system used. Thus, for real numbers,\nrational numbers, and (finite ranges of) integer numbers, we have\nCLP(R), CLP(Q), and CLP(FD) (for Finite Domains), respectively.\n\nEach of the constraint systems mentioned corresponds to a\npackage. They are revised in the following, but please consult the\nCiao reference manual for each package for details on the constraints\nand the operators that can be used in the expressions appearing in the\nconstraints for each system.\n\n\\subsection{Constraints over Reals}\n\nThe package \\verb+clpr+ enables CLP(R), which allows for constraints\nover real numbers. This means that the solutions for the variables\ninvolved in constraints are real numbers, and all numbers used in the\nexpressions in constraints are considered real numbers. \n\nThe internal representation of real numbers may cause losses of\nprecision. For example,\n\\begin{quote}\n\\begin{verbatim}\n?- X+Y .>=. 3, X=0.1.\n\nY.>=.2.9,\nX.=.0.100000000000000089 ? \n\\end{verbatim}\n\\end{quote}\n\n\\comment{Incomplete}\n\n\\subsection{Constraints over Rationals}\n\nThe package \\verb+clpq+ enables CLP(Q), which allows for constraints\nover rational numbers. This means that the solutions for the variables\ninvolved in constraints are rational numbers, and all numbers used in the\nexpressions in constraints are considered rational. \n\nThe internal representation of rational numbers allows for infinite\nprecision. For example,\n\\begin{quote}\n\\begin{verbatim}\n?- X+Y .>=. 3, X=0.1.\n\nX = 1/10,\nY.>=.29/10 ? \n\\end{verbatim}\n\\end{quote}\n\n\\comment{The output {\\tt X = 1/10} is incorrect!!!}\n\n\\comment{Incomplete}\n\nThe conversion of reals to rationals...\n\n\\subsection{Finite Domain Constraints}\n\n\\comment{Still under construction}\n", "meta": {"hexsha": "b5724dff5f4b0a3defa9bc0c659e15ca125560eb", "size": 4838, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "www/CiaoDE/ciao/doc/tutorial/SRC/clp.tex", "max_stars_repo_name": "leuschel/ecce", "max_stars_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "max_stars_repo_licenses": ["Apache-2.0"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2015-10-16T08:23:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-10T18:17:26.000Z", "max_issues_repo_path": "www/CiaoDE/ciao/doc/tutorial/SRC/clp.tex", "max_issues_repo_name": "leuschel/ecce", "max_issues_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "max_issues_repo_licenses": ["Apache-2.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "www/CiaoDE/ciao/doc/tutorial/SRC/clp.tex", "max_forks_repo_name": "leuschel/ecce", "max_forks_repo_head_hexsha": "f7f834bd219759cd7e8b3709801ffe26082c766d", "max_forks_repo_licenses": ["Apache-2.0"], "max_forks_count": 3, "max_forks_repo_forks_event_min_datetime": "2015-10-18T11:11:44.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-13T14:18:49.000Z", "avg_line_length": 28.6272189349, "max_line_length": 73, "alphanum_fraction": 0.720959074, "num_tokens": 1371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.863391599428538, "lm_q2_score": 0.8688267830311355, "lm_q1q2_score": 0.7501377458276035}}
{"text": "\n\\chapter{Derivation of implicit backwards difference formulae}\n\\label{cha:deriv-impl-backw}\n\nStarting from \\cref{eq:59} and setting $\\pv_k(t_{n+1}) = \\ffv{t_{n+1}, \\yv_{n+1}}$ we obtain\n\\begin{equation}\n  \\begin{aligned}\n    \\fv(t_{n+1}, \\yv_{n+1}) &= \\sum_{j=1}^k \\yv[t_{n+1}, \\ldots, t_{n+1-j}] \\sum_{l=0}^{j-1} \\prod_{i=0, i \\neq l}^{j-1} (t_{n+1} - t_{n+1-i}).\n  \\end{aligned}\n\\end{equation}\nThis can be greatly simplified by noticing that the product $ \\prod_{i=0, i \\neq l}^{j-1} (t_{n+1} - t_{n+1-i})$ is zero whenever it contains $i=0$, \\ie all terms in the sum with $l \\neq 0$.\nThis leaves us with\n\\begin{equation}\n  \\begin{aligned}\n    \\fv(t_{n+1}, \\yv_{n+1}) &= \\sum_{j=1}^k \\yv[t_{n+1}, \\ldots, t_{n+1-j}] \\prod_{i=0, i \\neq 0}^{j-1} (t_{n+1} - t_{n+1-i}), \\\\\n    &=  \\yv[t_{n+1}, t_n] + \\sum_{j=2}^k \\yv[t_{n+1}, \\ldots, t_{n+1-j}] \\prod_{i=1}^{j-1} (t_{n+1} - t_{n+1-i}). \\\\\n  \\end{aligned}\n\\end{equation}\n\nFor $k=1$ we get\n\\begin{equation}\n  \\begin{aligned}\n    \\fv(t_{n+1}, \\yv_{n+1}) &= \\frac{\\yv_{n+1} - \\yv_n}{\\dtn}, \\\\\n    \\yv_{n+1} &= \\yv_n + \\dtn \\fv(t_{n+1}, \\yv_{n+1}),\n  \\end{aligned}\n\\end{equation}\nwhich is backward Euler as expected.\n\nFor $k=2$\n\\begin{equation}\n  \\label{eqn:bdf2-derivation}\n  \\begin{aligned}\n    \\fv(t_{n+1}, \\yv_{n+1}) &= \\frac{\\yv_{n+1} - \\yv_n}{\\dtn} +  \\yv[t_{n+1}, t_{n}, t_{n-1}](t_{n+1} - t_n), \\\\\n    &= \\frac{\\yv_{n+1} - \\yv_n}{\\dtn} +  \\frac{\\dtn}{\\dtx{n+1} + \\dtn} \\bigb{\\frac{\\yv_{n+1} - \\yv_n}{\\dtn} - \\frac{\\yv_n - \\yv_{n-1}}{\\dtx{n-1}}}. \\\\\n  \\end{aligned}\n\\end{equation}\nAfter some algebra this becomes\n\\begin{equation}\n  \\label{eqn:bdf2-derivation-rearranged}\n  \\begin{aligned}\n    \\frac{\\yv_{n+1} - \\yv_n}{\\dtn} = \\frac{\\dtn}{2\\dtn + \\dtx{n-1}} \\frac{\\yv_n - \\yv_{n-1}}{\\dtx{n-1}}\n    + \\frac{\\dtn + \\dtx{n-1}}{2\\dtn + \\dtx{n-1}} \\fv(t_{n+1}, \\yv_{n+1}),\n  \\end{aligned}\n\\end{equation}\nwhich is variable step BDF2 \\cite[715]{GreshoSani}.\n\n%%% Local Variables:\n%%% mode: latex\n%%% TeX-master: \"main\"\n%%% End:\n", "meta": {"hexsha": "6dcd5a55b0d061db64331bfef61bf5c34cbb344b", "size": 1973, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "implicit-bdf-derivation.tex", "max_stars_repo_name": "davidshepherd7/thesis", "max_stars_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "max_stars_repo_licenses": ["CC-BY-4.0"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-02-13T10:36:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-28T21:11:27.000Z", "max_issues_repo_path": "implicit-bdf-derivation.tex", "max_issues_repo_name": "davidshepherd7/thesis", "max_issues_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "max_issues_repo_licenses": ["CC-BY-4.0"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "implicit-bdf-derivation.tex", "max_forks_repo_name": "davidshepherd7/thesis", "max_forks_repo_head_hexsha": "c4f1e903fa74e8fbc0667538e808fd7e3c947783", "max_forks_repo_licenses": ["CC-BY-4.0"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 38.6862745098, "max_line_length": 190, "alphanum_fraction": 0.5732387228, "num_tokens": 946, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9149009619539554, "lm_q2_score": 0.8198933271118221, "lm_q1q2_score": 0.750121193674235}}
{"text": "\\hypertarget{group__numpp__roots}{}\\section{Root Finding}\n\\label{group__numpp__roots}\\index{Root Finding@{Root Finding}}\n\n\nThis module provides methods for finding roots of $f(x) = 0$.  \n\n\n\\subsection*{Functions}\n\\begin{DoxyCompactItemize}\n\\item \n{\\footnotesize template$<$typename T , typename Func , typename  = std\\+::enable\\+\\_\\+if\\+\\_\\+t$<$std\\+::is\\+\\_\\+floating\\+\\_\\+point$<$\\+T$>$\\+::value$>$$>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga8b5bb65b3192456c184a331f88af0b56}{numpp\\+::roots\\+::bisection} (Func \\&\\&f, T lower\\+\\_\\+bound, T upper\\+\\_\\+bound, std\\+::size\\+\\_\\+t iterations=1000)\n\\item \n{\\footnotesize template$<$typename T , typename Func $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga1b4f2040358e71ad1fd2bfcc8c71a8d6}{numpp\\+::roots\\+::bisection} (Func \\&\\&f, T \\&\\&lower\\+\\_\\+bound, T \\&\\&upper\\+\\_\\+bound, const double epsilon, std\\+::size\\+\\_\\+t iterations)\n\\item \n{\\footnotesize template$<$typename Function , typename Derivative , typename Second\\+Derivative , typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga30924012d656a67696860b51d3d3f315}{numpp\\+::roots\\+::halley} (T \\&\\&value, std\\+::size\\+\\_\\+t iterations=1000, const double epsilon=1e-\\/7)\n\\item \n{\\footnotesize template$<$typename Function , typename Derivative , typename Second\\+Derivative , typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_gaa5dcba977340c78cd587fc7f9a3c0648}{numpp\\+::roots\\+::halley} (T \\&\\&value, Function f, Derivative df, Second\\+Derivative dfdf, std\\+::size\\+\\_\\+t iterations=1000, const double epsilon=1e-\\/7)\n\\item \n{\\footnotesize template$<$typename Function , typename Derivative , typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga756a768c79701c5506809765b24f89a0}{numpp\\+::roots\\+::newton} (T \\&\\&value, std\\+::size\\+\\_\\+t iterations=1000, const double epsilon=1e-\\/7)\n\\item \n{\\footnotesize template$<$typename Function , typename Derivative , typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga0c3358cbe925f1840d2332f81dec42ab}{numpp\\+::roots\\+::newton} (Function \\&\\&f, Derivative \\&\\&df, T \\&\\&value, std\\+::size\\+\\_\\+t iterations=1000, const double epsilon=1e-\\/7)\n\\item \n{\\footnotesize template$<$typename Function\\+And\\+Derivative , typename T $>$ }\\\\constexpr auto \\hyperlink{group__numpp__roots_ga7784b72874be701ab11320a8ab594e6f}{numpp\\+::roots\\+::newton} (Function\\+And\\+Derivative \\&\\&f, T \\&\\&value, std\\+::size\\+\\_\\+t iterations=1000, const double epsilon=1e-\\/7)\n\\end{DoxyCompactItemize}\n\n\n\\subsection{Detailed Description}\nThis module provides methods for finding roots of $f(x) = 0$. \n\nNamespace\\+: \n\\begin{DoxyCode}\n\\hyperlink{namespacenumpp_1_1roots}{numpp::roots}\n\\end{DoxyCode}\n\n\nInclude\\+: \n\\begin{DoxyCode}\n\\hyperlink{namespacenumpp}{numpp}/roots.h #includes every method in the module\n\\hyperlink{namespacenumpp}{numpp}/roots/METHOD.hpp #include specific METHOD\n\\end{DoxyCode}\n \n\n\\subsection{Function Documentation}\n\\mbox{\\Hypertarget{group__numpp__roots_ga8b5bb65b3192456c184a331f88af0b56}\\label{group__numpp__roots_ga8b5bb65b3192456c184a331f88af0b56}} \n\\index{Root Finding@{Root Finding}!bisection@{bisection}}\n\\index{bisection@{bisection}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{bisection()}{bisection()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [1/2]}}\n{\\footnotesize\\ttfamily template$<$typename T , typename Func , typename  = std\\+::enable\\+\\_\\+if\\+\\_\\+t$<$std\\+::is\\+\\_\\+floating\\+\\_\\+point$<$\\+T$>$\\+::value$>$$>$ \\\\\nconstexpr auto numpp\\+::roots\\+::bisection (\\begin{DoxyParamCaption}\\item[{Func \\&\\&}]{f,  }\\item[{T}]{lower\\+\\_\\+bound,  }\\item[{T}]{upper\\+\\_\\+bound,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000} }\\end{DoxyParamCaption})}\n\nBisects given interval and finds the root of function.\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of interval arguments \\\\\n\\hline\n{\\em Func} & type of Function (auto-\\/deduced Functor or function pointer)\\\\\n\\hline\n\\end{DoxyTemplParams}\nAlgorithm stops when it reaches automatically calculated precision or exceeds maximum number of iterations (default\\+: 1000)\n\nPrecision adjusted to the lower and upper arguments, accordingly to Numerical Recipees recipe.\\mbox{\\Hypertarget{group__numpp__roots_ga1b4f2040358e71ad1fd2bfcc8c71a8d6}\\label{group__numpp__roots_ga1b4f2040358e71ad1fd2bfcc8c71a8d6}} \n\\index{Root Finding@{Root Finding}!bisection@{bisection}}\n\\index{bisection@{bisection}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{bisection()}{bisection()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [2/2]}}\n{\\footnotesize\\ttfamily template$<$typename T , typename Func $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::bisection (\\begin{DoxyParamCaption}\\item[{Func \\&\\&}]{f,  }\\item[{T \\&\\&}]{lower\\+\\_\\+bound,  }\\item[{T \\&\\&}]{upper\\+\\_\\+bound,  }\\item[{const double}]{epsilon,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations }\\end{DoxyParamCaption})}\n\nThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.\n\nEverything has to be specified by the user\n\nAlgorithm stops when it reaches precision given by epsilon or exceeds iterations provided by the user\\mbox{\\Hypertarget{group__numpp__roots_ga30924012d656a67696860b51d3d3f315}\\label{group__numpp__roots_ga30924012d656a67696860b51d3d3f315}} \n\\index{Root Finding@{Root Finding}!halley@{halley}}\n\\index{halley@{halley}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{halley()}{halley()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [1/2]}}\n{\\footnotesize\\ttfamily template$<$typename Function , typename Derivative , typename Second\\+Derivative , typename T $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::halley (\\begin{DoxyParamCaption}\\item[{T \\&\\&}]{value,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000},  }\\item[{const double}]{epsilon = {\\ttfamily 1e-\\/7} }\\end{DoxyParamCaption})}\n\nS\\+Y\\+M\\+B\\+O\\+L\\+I\\+C\\+AL O\\+V\\+E\\+R\\+L\\+O\\+AD\\+:\n\nHalley\\textquotesingle{}s algorithm for finding root of the function using first and second order derivatives.\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of function argument \\\\\n\\hline\n{\\em Function} & type of function (has to be symbolic, check\\+: symbolic) \\\\\n\\hline\n{\\em Derivative} & type of derivative (has to be symbolic, check\\+: symbolic) \\\\\n\\hline\n{\\em Second\\+Derivative} & type of second derivative (has to be symbolic, check\\+: symbolic)\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyWarning}{Warning}\nTheorethically cubic convergence when $f'''$ continuous.\n\nSome problems may arise for this method, check professional literature\n\\end{DoxyWarning}\nAlgorithm stops when it reaches given precision or exceeds maximum number of iterations (default\\+: 1000)\n\n\\begin{DoxyReturn}{Returns}\n{\\bfseries Type}\\+: Same as Function return type \n\n{\\bfseries Value}\\+: Root in the case of convergence\n\\end{DoxyReturn}\n\\begin{DoxyWarning}{Warning}\n{\\bfseries May not converge to the root, evaluate your result after obtaining it}\n\\end{DoxyWarning}\n\\begin{DoxySeeAlso}{See also}\nSymbolic Differentiation\n\\end{DoxySeeAlso}\n\\mbox{\\Hypertarget{group__numpp__roots_gaa5dcba977340c78cd587fc7f9a3c0648}\\label{group__numpp__roots_gaa5dcba977340c78cd587fc7f9a3c0648}} \n\\index{Root Finding@{Root Finding}!halley@{halley}}\n\\index{halley@{halley}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{halley()}{halley()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [2/2]}}\n{\\footnotesize\\ttfamily template$<$typename Function , typename Derivative , typename Second\\+Derivative , typename T $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::halley (\\begin{DoxyParamCaption}\\item[{T \\&\\&}]{value,  }\\item[{Function}]{f,  }\\item[{Derivative}]{df,  }\\item[{Second\\+Derivative}]{dfdf,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000},  }\\item[{const double}]{epsilon = {\\ttfamily 1e-\\/7} }\\end{DoxyParamCaption})}\n\nF\\+I\\+N\\+I\\+TE D\\+I\\+F\\+F\\+E\\+R\\+E\\+N\\+C\\+E/\\+O\\+T\\+H\\+ER M\\+E\\+T\\+H\\+O\\+DS O\\+V\\+E\\+R\\+L\\+O\\+AD\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of function argument \\\\\n\\hline\n{\\em Function} & type of function (Functor or function) \\\\\n\\hline\n{\\em Derivative} & type of derivative (Functor of function) \\\\\n\\hline\n{\\em Second\\+Derivative} & type of second derivative (Functor or function)\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\mbox{\\Hypertarget{group__numpp__roots_ga756a768c79701c5506809765b24f89a0}\\label{group__numpp__roots_ga756a768c79701c5506809765b24f89a0}} \n\\index{Root Finding@{Root Finding}!newton@{newton}}\n\\index{newton@{newton}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{newton()}{newton()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [1/3]}}\n{\\footnotesize\\ttfamily template$<$typename Function , typename Derivative , typename T $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::newton (\\begin{DoxyParamCaption}\\item[{T \\&\\&}]{value,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000},  }\\item[{const double}]{epsilon = {\\ttfamily 1e-\\/7} }\\end{DoxyParamCaption})}\n\nS\\+Y\\+M\\+B\\+O\\+L\\+I\\+C\\+AL O\\+V\\+E\\+R\\+L\\+O\\+AD\n\nNewton\\textquotesingle{}s algorithm for finding root of the function using first order derivative.\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of function argument \\\\\n\\hline\n{\\em Function} & type of function (has to be symbolic, check\\+: symbolic) \\\\\n\\hline\n{\\em Derivative} & type of derivative (has to be symbolic, check\\+: symbolic)\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyWarning}{Warning}\nTheorethically quadratic convergence when $f''$ continuous.\n\nSome problems may arise for this method, check professional literature\n\\end{DoxyWarning}\nAlgorithm stops when it reaches given precision or exceeds maximum number of iterations (default\\+: 1000)\n\n\\begin{DoxyReturn}{Returns}\n{\\bfseries Type}\\+: Same as Function return type \n\n{\\bfseries Value}\\+: Root in the case of convergence\n\\end{DoxyReturn}\n\\begin{DoxyWarning}{Warning}\n{\\bfseries May not converge to the root, evaluate your result after obtaining it}\n\\end{DoxyWarning}\n\\begin{DoxySeeAlso}{See also}\nSymbolic Differentiation\n\\end{DoxySeeAlso}\n\\mbox{\\Hypertarget{group__numpp__roots_ga0c3358cbe925f1840d2332f81dec42ab}\\label{group__numpp__roots_ga0c3358cbe925f1840d2332f81dec42ab}} \n\\index{Root Finding@{Root Finding}!newton@{newton}}\n\\index{newton@{newton}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{newton()}{newton()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [2/3]}}\n{\\footnotesize\\ttfamily template$<$typename Function , typename Derivative , typename T $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::newton (\\begin{DoxyParamCaption}\\item[{Function \\&\\&}]{f,  }\\item[{Derivative \\&\\&}]{df,  }\\item[{T \\&\\&}]{value,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000},  }\\item[{const double}]{epsilon = {\\ttfamily 1e-\\/7} }\\end{DoxyParamCaption})}\n\nF\\+U\\+N\\+C\\+T\\+O\\+R/\\+F\\+U\\+N\\+C\\+T\\+I\\+ON O\\+V\\+E\\+R\\+L\\+O\\+AD\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of function argument \\\\\n\\hline\n{\\em Function} & type of function (Functor or function) \\\\\n\\hline\n{\\em Derivative} & type of derivative (Functor or function)\\\\\n\\hline\n\\end{DoxyTemplParams}\nYou may use finite difference code from differentiation module\n\n\\begin{DoxySeeAlso}{See also}\nFinite Difference Differentiation\n\\end{DoxySeeAlso}\n\\mbox{\\Hypertarget{group__numpp__roots_ga7784b72874be701ab11320a8ab594e6f}\\label{group__numpp__roots_ga7784b72874be701ab11320a8ab594e6f}} \n\\index{Root Finding@{Root Finding}!newton@{newton}}\n\\index{newton@{newton}!Root Finding@{Root Finding}}\n\\subsubsection{\\texorpdfstring{newton()}{newton()}\\hspace{0.1cm}{\\footnotesize\\ttfamily [3/3]}}\n{\\footnotesize\\ttfamily template$<$typename Function\\+And\\+Derivative , typename T $>$ \\\\\nconstexpr auto numpp\\+::roots\\+::newton (\\begin{DoxyParamCaption}\\item[{Function\\+And\\+Derivative \\&\\&}]{f,  }\\item[{T \\&\\&}]{value,  }\\item[{std\\+::size\\+\\_\\+t}]{iterations = {\\ttfamily 1000},  }\\item[{const double}]{epsilon = {\\ttfamily 1e-\\/7} }\\end{DoxyParamCaption})}\n\nA\\+U\\+T\\+O\\+M\\+A\\+T\\+IC D\\+I\\+F\\+F\\+E\\+R\\+E\\+N\\+T\\+I\\+A\\+T\\+I\\+ON O\\+V\\+E\\+R\\+L\\+O\\+AD\n\n\n\\begin{DoxyTemplParams}{Template Parameters}\n{\\em T} & type of function argument \\\\\n\\hline\n{\\em Function\\+And\\+Derivative} & Functor returning tuple \\mbox{[}value, derivative\\mbox{]} \\\\\n\\hline\n{\\em Derivative} & type of derivative (Functor or function)\\\\\n\\hline\n\\end{DoxyTemplParams}\n\\begin{DoxyWarning}{Warning}\nFunction\\+And\\+Derivative should be of type automatic differentiation forward\n\\end{DoxyWarning}\n\\begin{DoxySeeAlso}{See also}\n\\hyperlink{group__numpp__differentiation__automatic}{Automatic Differentiation}\n\\end{DoxySeeAlso}\n", "meta": {"hexsha": "71adb435e05aa49dd1096bec3da8a6e33ec68f53", "size": 12481, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "docs/group__numpp__roots.tex", "max_stars_repo_name": "szymonmaszke/numpp", "max_stars_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 10, "max_stars_repo_stars_event_min_datetime": "2018-06-06T01:51:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-01-02T15:17:00.000Z", "max_issues_repo_path": "docs/group__numpp__roots.tex", "max_issues_repo_name": "vyzyv/numpp", "max_issues_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 2, "max_issues_repo_issues_event_min_datetime": "2018-11-28T12:15:46.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-16T00:03:38.000Z", "max_forks_repo_path": "docs/group__numpp__roots.tex", "max_forks_repo_name": "szymonmaszke/numpp", "max_forks_repo_head_hexsha": "9149c9d81f70a6ce833fdd1d2f0f2b584e2ac4d9", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 2, "max_forks_repo_forks_event_min_datetime": "2017-08-06T13:58:27.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-06T06:45:22.000Z", "avg_line_length": 57.252293578, "max_line_length": 359, "alphanum_fraction": 0.7367999359, "num_tokens": 4371, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9073122188543453, "lm_q2_score": 0.8267117983401363, "lm_q1q2_score": 0.7500857161050551}}
{"text": "\n\\section{New Results from Relativistic Theory}\n    To compute the relativistic version of the normal form factor, we\n    need to use the Dirac four component spinors. As for the non\n    relativistic case we need to determine the electronic charge\n    density given by:\n    \\(\n        \\rho(\\mb{r}) = \\psi^{\\dagger} \\psi =\n            = |\\psi_1|^2 + |\\psi_2|^2 + |\\psi_3|^2 + |\\psi_4|^2 \n    \\)\n\n    Using the ground state solution to the Dirac equation for hydrogenic\n    atoms given by equation~\\ref{eq:dirac-ground}, the electron density\n    is given by:\n    \\begin{eqnarray*}\n        \\rho(\\mb{r}) &=&  |g_0(r) Y_{00}|^2 + \n                            \\frac{1}{3} |i h_0(r) Y_{10}|^2 +\n                            \\frac{2}{3} |i h_0(r) Y_{11}|^2\n       \\\\\n       \\rho(\\mb{r}) &=&  \\frac{1}{4\\pi} \\left( |g_0(r)|^2 +\n                            |h_0(r) \\cos \\theta|^2  +\n                            |h_0(r) \\sin \\theta \\; e^{i\\phi}|^2  \\right)\n       % \\\\\n       % \\rho(\\mb{r}) &=&  \n       = \\frac{1}{4\\pi} \n                            \\left(\n                                |g_0(r)|^2 + |h_0(r)|^2\n                            \\right)\n    \\end{eqnarray*}\n\n    The radial function $g_0(r)$ and $h_0(r)$ are defined by\n    equation~\\ref{eq:dirac-radial}. Once again\n    using the assumption that a hydrogenic atom is spherically symmetric we\n    substitute the electron density $\\rho$ into the normal form factor equation\n    given by~\\ref{eq:nff-spherical}.\n    \\begin{eqnarray*}\n        f_0(q) &=&  \\frac{1}{q} \n                    \\int_0^\\infty \\sin (qr) r \n                    \\left(\n                        |g_0(r)|^2 + |h_0(r)|^2\n                    \\right) \\; dr\n                = \\frac{2}{q(1 + \\epsilon_1)} \n                    \\int_0^\\infty r |g_0(r)|^2 \\sin (qr) \\; dr\n        \\\\\n                &=& \\frac{1}{q \\; \\Gamma(2\\gamma_1 + 1)}\n                    \\left(\n                        \\frac{2Z}{a_0}  \n                    \\right)^{2\\gamma_1 + 1}\n                    \\int_0^\\infty r^{2\\gamma_1 - 1} e^{-2Zr/a_0} \\sin (qr) \\; dr\n        \\\\\n                &=& \\frac{1}{2iq \\Gamma(2\\gamma_1 + 1)}\n                    \\left(\n                        \\frac{2Z}{a_0}\n                    \\right)^{2\\gamma_1 + 1}\n                    \\left[\n                        \\int_0^\\infty r^{2\\gamma_1-1} e^{-(2Z/a_0 - iq)r} \\; dr\n                    -\n                        \\int_0^\\infty r^{2\\gamma_1-1} e^{-(2Z/a_0 + iq)r} \\; dr\n                    \\right]\n    \\end{eqnarray*}\n    Making use of the standard integral\n    \\(\n        \\int_0^\\infty x^n e^{-ax} \\; dx = \\frac{\\Gamma(n+1)}{a^{n+1}}.\n    \\)\n    and after some algebraic manipulation, we obtain\n    equation~\\ref{eq:nff-relativistic}.\n    Equation~\\ref{eq:nff-relativistic} is a \\emph{new} result, providing an explicit\n    analytic solution for the relativistic normal form factor for hydrogenic\n    atoms.\n    \\begin{equation} \\label{eq:nff-relativistic}\n        \\boxed{\n            f_0(q) = \n            \\frac{\\Gamma(2\\gamma_1)}{2iq \\Gamma(2\\gamma_1+1)}\n            \\left(\n                \\frac{2Z}{a_0}\n            \\right)^{2\\gamma_1 + 1}\n            \\left[\n                \\frac{\n                    \\left(\n                        \\frac{2Z}{a_0} + iq\n                    \\right)^{2\\gamma_1}\n                    -\n                    \\left(\n                        \\frac{2Z}{a_0} - iq\n                    \\right)^{2\\gamma_1}\n                } {\n                    \\left[\n                        \\left(\n                            \\frac{2Z}{a_0} \n                        \\right)^2   \n                        + q^2\n                    \\right]^{2\\gamma_1}\n                }\n            \\right]\n        }\n    \\end{equation}\n    This equation cannot be simplified any further because $\\gamma_1$ is not an\n    integer. Although the equation has expression containing the complex number\n    $i$, when it is evaluated $f_0(q)$ is real valued as expected.\n\n    Previous work in this area include the analytic atomic form factor\n    for two electrons in the ground state (K shell) for a helium like atom by\n    Bethe and Levinger~\\cite{Bethe-Levinger} and Smend and\n    Schumacher~\\cite{Smend-Schumacher}. The normal form factor for two electrons in the\n    K shell as quote in Schaupp et al.~\\cite{Schaupp-1983} is\n    \\begin{equation}\n        f_0(q) = \\frac{(2Z\\alpha)^{2\\gamma_1 + 1}}{\\gamma_1 q}\n                \\frac{ \\sin[2\\gamma_1 \\arctan(\\frac{q}{2Z\\alpha}) ] }{\n                    [(2Z\\alpha)^2 + q^2]^{\\gamma_1}\n                }.\n    \\end{equation}\n\n", "meta": {"hexsha": "b5ae4808284d4e38afef2632008aa70b3dda2ca3", "size": 4515, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "normal_relativistic.tex", "max_stars_repo_name": "mikepsn/atomic-form-factors-thesis", "max_stars_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "normal_relativistic.tex", "max_issues_repo_name": "mikepsn/atomic-form-factors-thesis", "max_issues_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "normal_relativistic.tex", "max_forks_repo_name": "mikepsn/atomic-form-factors-thesis", "max_forks_repo_head_hexsha": "63a8d151c4d53c369d223d44ff80c075ea102420", "max_forks_repo_licenses": ["MIT"], "max_forks_count": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null, "avg_line_length": 39.9557522124, "max_line_length": 87, "alphanum_fraction": 0.4633444075, "num_tokens": 1376, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8705972650509008, "lm_q2_score": 0.8615382129861583, "lm_q1q2_score": 0.7500528119625899}}
{"text": "\\documentclass[12pt]{mpllatex}\n\\usepackage{examples}\n\n\\begin{document}\n\n\\section*{Quadratic convergence of Newton-Raphson iterations}\n\nThis is a simple example that uses Maple to demonstrate the quadratic converegnce of Newton-Raphson iterations to the exact root of a non-linear equation.\n\n\\vspace{-5pt}\n\n\\begin{minipage}[t]{0.55\\textwidth}\n\\begin{maple}\n   # mplBeg (table)\n\n      Digits := 200:\n\n       f := x -> x - exp(-x):\n      df := x -> eval (diff (f(u),u), u=x):\n\n      x_new := 0.5:\n      f_new := f (x_new):\n\n      Print (sprintf(\"\\\\RuleA % 2d &% .25f &% .10e &\\\\\\\\\",\n                     0,x_new,f_new)):\n\n      for n from 1 to 6 do\n         x_old := x_new:\n         x_new := x_old - f(x_old)/df(x_old):\n         f_old := evalf (f (x_old)):\n         f_new := evalf (f (x_new)):\n         ratio := evalf (f_new / f_old^2):\n         Print (sprintf(\"\\\\RuleA % 2d &% .25f &% .10e &% .5f\\\\\\\\\",\n                        n,x_new,f_new,ratio)):\n      end do:\n\n   # mplEnd (table)\n\\end{maple}\n\\end{minipage}\n\\hskip 1cm\n\\begin{minipage}[t]{0.45\\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$&\n            $\\eps_{n} = x_{n} - e^{-x_{n}}$&\n            $\\eps_{n}/\\eps_{n-1}^2$\\\\\n      \\noalign{\\hrule height 0.5pt}\n      \\mpl{table}\n      \\noalign{\\hrule height 1pt}\n   \\end{tabular}\n   \\end{center}\n\\end{latex}\n\\end{minipage}\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   \\mpl{table}\n   \\noalign{\\hrule height 1pt}\n\\end{tabular}\n\\end{center}\n\n\\end{document}\n", "meta": {"hexsha": "7d6979a6f1db665f4bd7063fe4e19124c9ae03fa", "size": 2809, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "maple/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": "maple/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": "maple/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": 29.8829787234, "max_line_length": 330, "alphanum_fraction": 0.6208615166, "num_tokens": 983, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8824278664544912, "lm_q2_score": 0.8499711737573763, "lm_q1q2_score": 0.7500382494065412}}
{"text": "\\documentclass{book}\n\n\\usepackage{HBSuerDemir}\n\\usepackage{graphicx}\n\\graphicspath{ {image/} }\n\n\\begin{document}\n\n\t\\paragraph{}$M_{ox} = \n\t\\begin{cases}\t\\int_{a}^{b} \\  f(x) \\ \\delta{x} \\ \\sqrt{1 + f^{'^{2}}(x)}\\hDif {x} \\\\ \\int_{c}^{d} \\  y \\ \\delta{y} \\ \\sqrt{1 + g^{'^{2}}(y)}\\hDif {y}, \\\\ \\end{cases}$ \\\\ \n\t\\paragraph{}$M_{oy} = \\begin{cases} \\int_{a}^{b} \\ x \\ \\delta{x} \\ \\sqrt{1 + f^{'^{2}}(x)}\\hDif {x} \\\\ \\int_{c}^{d} \\ g(y) \\ \\delta{y} \\ \\sqrt{1 + g^{'^{2}}(y)}\\hDif {y}. \\\\ \n\t\\end{cases}$\n\t\\paragraph{}We define the \\textit{center of mass (center of gravity)} of the arc with mass as the point G($\\overline{x}$, $\\overline{y}$) such that the moments m$\\overline{y}$, m$\\overline{x}$ of the particle G(m) are the same as the moments $M_{ox}$, $M_{oy}$ of the arc where m is the total mass of the arc:\n\t\\begin{align*}\n\t\tm \\overline{x} &= M_{oy} \\ ,  &m\\overline{y}= M_{ox}\n\t\\end{align*}\n\tThese defined equalities give\n\t\\begin{align*}\n\t\t  \\overline{x} &= \\frac{M_{oy}}{m}  \\text{,}   &\\overline{y} = \\frac{M_{ox}}{m}\n\t\\end{align*}\n\tas coordinates of the center of mass G. \n\t\\paragraph{}$\\underline{Example}$. Find the center of mass of a wire bent in the shape of semi circle $x^{2}$ + $y^{2}$ = $a^{2}$ if the density is $\\delta{}$ = 2y. \\paragraph{}$\\underline{Solution}$. Since the arc and the density function are symmetric with respect to y-axis, it follows that G lies on y, axis, and $\\overline{x}$ = 0.\n\t\\paragraph{}To find $\\overline{y}$, we evaluate first the total mass m of the wire:\\\\\n\t\\begin{minipage}{0.55\\textwidth}\n\t\\begin{align*}\n\t    m = 2\\int_{0}^{a} 2y\\sqrt{1 + \\frac{y^2}{x^2}} \\ \\hDif{y} = 4a^2 \n\t\\end{align*}\n\tThen\n\t\\end{minipage}\n\t\\begin{minipage}{0.45\\textwidth}\n\t\\includegraphics[width=\\textwidth]{image}\n\t\\end{minipage}\n\t\n\t    \n\t\n\t\n\\end{document}", "meta": {"hexsha": "8715008de5db366767aead0f073af48834a336a7", "size": 1782, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "hw1/non-merged/CANBERK YILDIRIM_35942_assignsubmission_file_/b1p2-497.tex", "max_stars_repo_name": "yildirimyigit/cmpe220_2016_3", "max_stars_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1, "max_stars_repo_stars_event_min_datetime": "2019-05-15T22:03:34.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-15T22:03:34.000Z", "max_issues_repo_path": "hw1/non-merged/CANBERK YILDIRIM_35942_assignsubmission_file_/b1p2-497.tex", "max_issues_repo_name": "yildirimyigit/cmpe220_2016_3", "max_issues_repo_head_hexsha": "4e71a0ed20d76b93c144c2f9c0fbbd52c04b5ae3", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hw1/non-merged/CANBERK YILDIRIM_35942_assignsubmission_file_/b1p2-497.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": 48.1621621622, "max_line_length": 337, "alphanum_fraction": 0.61335578, "num_tokens": 709, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8499711718571775, "lm_q2_score": 0.8824278649085117, "lm_q1q2_score": 0.7500382464157148}}
{"text": "\\chapter{Classical Logic}\n\n    \\begin{definition*}[Formulae]\n        A \\textit{formula} within classical logic is constructed as follows:\n        \\begin{align*}\n            A, B, C                \\quad &\\defeq \\quad \\top \\,|\\, \\bot \\,|\\, a \\,|\\, \\neg\\, a \\,|\\, A \\vee B \\,|\\, A \\wedge B \\\\\n            \\Gamma, \\Delta, \\Sigma \\quad &\\defeq \\quad A \\,|\\, A,B \\,|\\, A,B,C \\ldots\n        \\end{align*}\n        where $\\vee, \\wedge$ are additive linear logic disjunction and conjunction respectively and $\\Gamma, \\Delta, \\Sigma$ are contexts.\n    \\end{definition*}\n\n    \\begin{example*}\n        Consider the formulae constructed as follows:\n        \\begin{equation*}\n            A \\seteq a \\vee b \\quad B \\seteq \\neg b \\vee c \\quad C \\seteq A \\wedge B \\equiv (a \\vee b) \\wedge (\\neg b \\vee c)\n        \\end{equation*}\n    \\end{example*}\n\n\n    \\begin{definition*}[Sequent Proofs]\n        Within \\textit{classical logic}, a \\textit{sequent proof} is constructed from the following rules:\n\n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{.3\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{~}\n                    \\RightLabel{$\\top$}\n                    \\UnaryInfC{$\\vdash \\top$}\n                \\end{prooftree}\n                \\begin{prooftree}\n                    \\AxiomC{~}\n                    \\RightLabel{$ax$}\n                    \\UnaryInfC{$\\vdash a, \\neg\\, a$}\n                \\end{prooftree}\n            \\end{minipage}\n            \\begin{minipage}[H]{.3\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$\\vee$}\n                    \\UnaryInfC{$\\vdash \\Gamma, A \\vee B$}\n                \\end{prooftree}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$\\wedge$}\n                    \\BinaryInfC{$\\vdash \\Gamma, A \\wedge B$}\n                \\end{prooftree}\n            \\end{minipage}\n            \\begin{minipage}[H]{.3\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma$}\n                    \\RightLabel{$w$}\n                    \\UnaryInfC{$\\vdash \\Gamma, A$}\n                \\end{prooftree}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$c$}\n                    \\UnaryInfC{$\\vdash \\Gamma, A$}\n                \\end{prooftree}\n            \\end{minipage}\n        \\end{minipage}\n\n        where $A, B, C$ are formulae and $\\Gamma, \\Delta, \\Sigma$ are sequents.\n        A sequent proof provides, without context, a proof of its conclusion and each line of the proof represents a tautology.\n    \\end{definition*}\n\n    \\begin{example*}\n        Consider the formula $P \\seteq (a \\vee \\neg a) \\wedge \\top$.\n        The sequent proof of $P$, written $\\vdash P$, is constructed as follows:\n        \\begin{prooftree}\n            \\AxiomC{$~$}\n            \\RightLabel{$ax$}\\UnaryInfC{$\\vdash a, \\neg a$}\n            \\RightLabel{$\\vee R$}\\UnaryInfC{$\\vdash a \\vee \\neg a, \\neg a$}\n            \\RightLabel{$\\vee R$}\\UnaryInfC{$\\vdash a \\vee \\neg a, a \\vee \\neg a$}\n            \\RightLabel{$c$}\\UnaryInfC{$\\vdash a \\vee \\neg a$}\n            \\AxiomC{$~$}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$\\wedge R$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top$}\n        \\end{prooftree}\n    \\end{example*}\n\n\n    \\begin{remark*}\n        Within the context of weakening and contraction, \\textit{additive} and \\textit{multiplicative} rules of linear logic are inter-derivable.\n        In this case, the \\textit{additive} rules are used, with the effect of $\\vee R, \\wedge R$ maintaining the number of formulae in a seqent across derivation steps.\n    \\end{remark*}\n\n\n    \\begin{definition*}[Derivations]\n        Given \\textit{tops} $\\Gamma_1 \\ldots \\Gamma_n$ for the sequent proof $\\vdash \\Delta$, a \\textit{derivation} is a tree providing a proof of $\\Gamma_1 \\ldots \\Gamma_n \\implies \\Delta$.\n\n        A derivation is written as:\n        \\begin{prooftree}\n            \\AxiomC{$\\vdash \\Gamma_1$}\n            \\AxiomC{$\\ldots$}\n            \\AxiomC{$\\vdash \\Gamma_n$}\n            \\RightLabel{\\textit{[label]}} \\doubleLine\\TrinaryInfC{$\\vdash \\Delta$}\n        \\end{prooftree}\n        where the \\textit{label} describes which rules may be used within the derivation.\n    \\end{definition*}\n\n    \\begin{corollary*}[Derivation Equivalence]\n        A sequent proof is a derivation where all top derivations of the tree are $=\\joinrel= \\top, ax$.\n        Equivalence of derivations may be weakly defined up to equivalence of leaves and conclusion.\n\n        This is described in detail by \\citet{proofs-and-types} as \\textit{morally equivalent}.\n    \\end{corollary*}\n\n    \\begin{example*}\n        Considering the leaves $\\vdash A, A$ and $\\vdash B$ with the conclusion $\\vdash A \\wedge B$, the following proofs are morally equivalent:\n        \\begin{prooftree}\n            \\AxiomC{$\\vdash A, A$}\n            \\RightLabel{$c$}\\UnaryInfC{$\\vdash A$}\n            \\AxiomC{$\\vdash B$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash A \\wedge B$}\n        \\end{prooftree}\n        \\begin{prooftree}\n            \\AxiomC{$\\vdash A, A$}\n            \\AxiomC{$\\vdash B$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash A, B$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash A, A \\wedge B$}\n            \\AxiomC{$\\vdash B$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash B, A \\wedge B$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash A \\wedge B, A \\wedge B$}\n            \\RightLabel{$c$}\\UnaryInfC{$\\vdash A \\wedge B$}\n        \\end{prooftree}\n        Note that the collection of leaves is a \\texttt{Set}, so equivalence is up to existence of terms only and not number.\n        Furthermore, equivalence of leaves is also defined up to equivalence of sequents, in particular equivalence up to commutativity of formulae $\\vdash A, B \\equiv \\,\\, \\vdash B, A$.\n        Equivalence may also be considered up to idempotency of formulae $\\vdash A, A \\equiv \\,\\, \\vdash A$, but this interferes with the correctness of some definitions.\n    \\end{example*}\n\n\n    \\begin{definition*}[Additive Stratification]\n        A proof tree is said to be \\textit{additively stratified} if $\\vdash P$ is structured as follows:\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_1$}\n            \\RightLabel{$w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_1$}\n            \\AxiomC{\\ldots}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_n$}\n            \\RightLabel{$w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_n$}\n            \\RightLabel{$\\wedge, \\vee$}\\doubleLine\\TrinaryInfC{$\\vdash P \\ldots P$}\n            \\RightLabel{$c$}\\doubleLine\\UnaryInfC{$\\vdash P$}\n        \\end{prooftree}\n        That is, the inferences made in an additively stratified proof are strictly ordered by:\n        \\begin{enumerate}[nosep]\n            \\item Top/Axiomatic\n            \\item Weakening\n            \\item Conjunction/Disjunction\n            \\item Contraction\n        \\end{enumerate}\n    \\end{definition*}\n    \n    \\begin{example}\\label{example:add-strat-proof}\n        The following proof tree is additively stratified:\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$ax$}\\UnaryInfC{$\\vdash a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, a \\vee \\neg a$}\n            \\AxiomC{}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\top, a \\vee \\neg a$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top, a \\vee \\neg a$}\n            \\AxiomC{}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\top, (a \\vee \\neg a) \\wedge \\top$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top, (a \\vee \\neg a) \\wedge \\top$}\n            \\RightLabel{$c$}\\UnaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top$}\n        \\end{prooftree}\n    \\end{example}\n\n\n    \\begin{proposition*}[Stratification Equivalence]\n        Given $\\vdash A$, there exists a morally equivalent additively stratified proof of $A$.\n    \\end{proposition*}\n\n    \\begin{proof}\n        For each instance of a weakening below another inference, there exists an equivalent subproof that is additively stratified:\n\n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B$, C}\n                \\end{prooftree}\n            \\end{minipage}\n            $\\leadsto$\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A, C$}\n                    \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B, C$}\n                \\end{prooftree}\n            \\end{minipage}\n        \\end{minipage}\n        \n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash \\Gamma, A \\wedge B$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A \\wedge B, C$}\n                \\end{prooftree}\n            \\end{minipage}\n            $\\leadsto\\quad$\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A, C$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, B, C$}\n                    \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash \\Gamma, A \\wedge B, C$}\n                \\end{prooftree}\n            \\end{minipage}\n        \\end{minipage}\n\n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A, B$}\n                \\end{prooftree}\n            \\end{minipage}\n            $\\leadsto\\quad$\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A, A, B$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A, B$}\n                \\end{prooftree}\n            \\end{minipage}\n        \\end{minipage}\n\n        Similarly, for each instance of a contraction above another inference, there exists an equivalent subproof that is additively stratified:\n\n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A$}\n                    \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B$}\n                \\end{prooftree}\n            \\end{minipage}\n            $\\leadsto$\n            \\begin{minipage}[H]{0.4\\linewidth}\n                \\begin{prooftree}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B, A$}\n                    \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B, A \\vee B$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A \\vee B$}\n                \\end{prooftree}\n            \\end{minipage}\n        \\end{minipage}\n\n        \\begin{minipage}[H]{\\linewidth}\n            \\centering\n            \\begin{minipage}[H]{0.3\\linewidth}\n                \\begin{scprooftree}{0.8}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash \\Gamma, A \\wedge B$}\n                \\end{scprooftree}\n            \\end{minipage}\n            $\\leadsto\\quad$\n            \\begin{minipage}[H]{0.6\\linewidth}\n                \\begin{scprooftree}{0.8}\n                    \\AxiomC{$\\vdash \\Gamma, A, A$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, A, B$}\n                    \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash \\Gamma, A, A \\wedge B$}\n                    \\AxiomC{$\\vdash \\Gamma, B$}\n                    \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\Gamma, B, A \\wedge B$}\n                    \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash \\Gamma, A \\wedge B, A \\wedge B$}\n                    \\RightLabel{$c$}\\UnaryInfC{$\\vdash \\Gamma, A \\wedge B$}\n                \\end{scprooftree}\n            \\end{minipage}\n        \\end{minipage}\n        \n        By induction from the leaves downwards on a finite height tree, apply the associated rule to each pair of inferences of the form ($c$ above \\textit{inf}).\n        Any given $\\vdash P$ may be rewritten:\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_1$}\n            \\RightLabel{$\\wedge, \\vee, w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_1$}\n            \\AxiomC{\\ldots}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_n$}\n            \\RightLabel{$\\wedge, \\vee, w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_n$}\n            \\RightLabel{$c$}\\doubleLine\\TrinaryInfC{$\\vdash P$}\n        \\end{prooftree}\n        \n        Again, by induction from the root upwards on this partially stratified tree, apply the associated rule to each pair of inferences of the form ($w$ below \\textit{inf}).\n        $\\vdash P$ may then be further rewritten:\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_1$}\n            \\RightLabel{$w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_1$}\n            \\AxiomC{\\ldots}\n            \\AxiomC{}\n            \\RightLabel{$\\top, ax$}\\doubleLine\\UnaryInfC{$\\vdash A_n$}\n            \\RightLabel{$w$}\\doubleLine\\UnaryInfC{$\\vdash \\Gamma_n$}\n            \\RightLabel{$\\wedge, \\vee$}\\doubleLine\\TrinaryInfC{$\\vdash P \\ldots P$}\n            \\RightLabel{$c$}\\doubleLine\\UnaryInfC{$\\vdash P$}\n        \\end{prooftree}\n\n    \\end{proof}\n\n    \\begin{example*}\n        Similarly to Example~\\ref{example:add-strat-proof}, consider the two following morally equivalent proofs, with only the latter additively stratified.\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$ax$}\\UnaryInfC{$\\vdash a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, a \\vee \\neg a$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash a \\vee \\neg a$}\n            \\AxiomC{}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top$}\n        \\end{prooftree}\n        \\begin{prooftree}\n            \\AxiomC{}\n            \\RightLabel{$ax$}\\UnaryInfC{$\\vdash a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, \\neg a$}\n            \\RightLabel{$\\vee$}\\UnaryInfC{$\\vdash a \\vee \\neg a, a \\vee \\neg a$}\n            \\AxiomC{}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\top, a \\vee \\neg a$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top, a \\vee \\neg a$}\n            \\AxiomC{}\n            \\RightLabel{$\\top$}\\UnaryInfC{$\\vdash \\top$}\n            \\RightLabel{$w$}\\UnaryInfC{$\\vdash \\top, (a \\vee \\neg a) \\wedge \\top$}\n            \\RightLabel{$\\wedge$}\\BinaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top, (a \\vee \\neg a) \\wedge \\top$}\n            \\RightLabel{$c$}\\UnaryInfC{$\\vdash (a \\vee \\neg a) \\wedge \\top$}\n        \\end{prooftree}\n        Note that moral equivalence here is without regard to number --- there are two leaves $\\vdash \\top$ under additive stratification versus one otherwise.\n        Furthermore, notice that the proof without additive stratification is shorter --- this will be of importance when improving asymptotic performance.\n    \\end{example*}\n", "meta": {"hexsha": "886607a9527435c0e451e4a063b5d24ab7c55702", "size": 16771, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "tex/classical-logic.tex", "max_stars_repo_name": "AdamLassiter/petri-nets", "max_stars_repo_head_hexsha": "a13b6df797d7d2b69a397da5939e757a9e35a127", "max_stars_repo_licenses": ["MIT"], "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/classical-logic.tex", "max_issues_repo_name": "AdamLassiter/petri-nets", "max_issues_repo_head_hexsha": "a13b6df797d7d2b69a397da5939e757a9e35a127", "max_issues_repo_licenses": ["MIT"], "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/classical-logic.tex", "max_forks_repo_name": "AdamLassiter/petri-nets", "max_forks_repo_head_hexsha": "a13b6df797d7d2b69a397da5939e757a9e35a127", "max_forks_repo_licenses": ["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.0544412607, "max_line_length": 190, "alphanum_fraction": 0.537475404, "num_tokens": 5254, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8887588052782737, "lm_q2_score": 0.8438951084436077, "lm_q1q2_score": 0.7500192083605199}}
{"text": "\\chapter{Propositional Logic}\n\\begin{definition}\n    A \\underline{\\textbf{proposition}} is a statement with exactly one truth\n    value.\n\\end{definition}\n\\begin{definition}\n    Two propositions are said to be \\underline{\\textbf{equivalent}} if they\n    have the same truth table.\n\\end{definition}\n\\begin{definition}\n    A \\underline{\\textbf{tautology}} is a statement that is always true.\n\\end{definition}\n\\begin{definition}\n    A \\underline{\\textbf{contradiction}} is a statement that is always false.\n\\end{definition}\n\n\\section{Truth Tables and Logical Equivalences}\nIf you are given a proposition and asked to check if it is a tautology or a\ncontradiction, here are two different ways to proceed:\n\n\\begin{enumerate}[noitemsep]\n    \\item Construct a truth table for the given proposition.\n    \\item Use logical equivalences.\n\\end{enumerate}\n\n\\begin{question}\n    Is this a tautology or a contradiction?\n\n    \\[\n        [p \\wedge (q \\wedge r)] \\rightarrow [( ( (r \\wedge p)\\wedge q) \\vee q)]\n    \\]\n\\end{question}\n\n\\begin{solution}\n    \\textbf{1 - Truth Table:} For readability, let us define $\\alpha =  p\n    \\wedge (q \\wedge r)$ and let us define $\\beta = ( ( (r \\wedge p)\\wedge q)\n    \\vee q)$\n\n    \\pagebreak[4]\n\n    \\begin{table}[ht]\n        \\caption{Truth Table}\n        \\vspace{0.5em}\n        \\centering % used for centering table\n        \\begin{tabular}{c c c c c c c c c } % 9 columns\n        % centered columns (4 columns)\n            \\toprule\n            p & q & r & $q \\wedge r$ &  $\\alpha$ & $(r \\wedge p)$ & $((r \\wedge\n            p) \\wedge q)$ & $\\beta$ & $\\alpha \\rightarrow \\beta$\\\\ [0.5ex]\n            \\midrule\n            T & T & T & T & T & T & T & T & \\textbf{T} \\\\\n            T & T & F & F & F & F & F & T & \\textbf{T} \\\\\n            T & F & T & F & F & T & F & F & \\textbf{T} \\\\\n            T & F & F & F & F & F & F & F & \\textbf{T} \\\\\n            F & T & T & T & F & F & F & T & \\textbf{T} \\\\\n            F & T & F & F & F & F & F & T & \\textbf{T} \\\\\n            F & F & T & F & F & F & F & F & \\textbf{T} \\\\\n            F & F & F & F & F & F & F & F & \\textbf{T} \\\\\n            \\bottomrule\n        \\end{tabular}\n        \\label{table:question_1_truthtable}\n    \\end{table}\n\n    \\noindent Since $\\alpha \\rightarrow \\beta$ is always true, this is an example\n    of a tautology!\n\\end{solution}\n\n\\begin{solution}\n    \\textbf{2 - Logical Equivalences: }\n    \\[\n        \\begin{split}\n            &[p \\wedge (q \\wedge r)] \\rightarrow [( ( (r \\wedge p)\\wedge q) \\vee\n            q)] \\\\\n            \\iff &\\neg[p \\wedge q \\wedge r] \\vee [(  (r \\wedge p\\wedge q) \\vee q)]\n            \\textbf{ (Definition)} \\\\\n            \\iff &\\neg (p \\wedge q \\wedge r) \\vee [(p \\wedge q \\wedge r) \\vee q]\n            \\textbf{ (Commutative law)} \\\\\n            \\iff &[\\neg (p \\wedge q \\wedge r) \\vee (p \\wedge q \\wedge r)] \\vee\n            q \\textbf{ (Associative Law)} \\\\\n            \\iff &T \\vee q \\textbf{ (Complement Law)} \\\\\n            \\iff &T (\\textbf{Identity Law}) \\\\\n        \\end{split}\n    \\]\n    \\noindent Since the result is always true, the given proposition is a\n    tautology! \\\\\n\\end{solution}\n\n\\begin{remark}\n    As you can see, solving problems through logical equivalences is quicker,\n    but require you to manipulate the given propositions. If you are\n    uncomfortable doing this, please feel free to resort to Truth Tables. The\n    same question showed up on my midterm, and I used logical equivalences to\n    solve the problem.\n\\end{remark}\n\n\\section{Knights and Knaves}\nYou can always expect a question on logic puzzles on the midterms and the\nfinals. These questions are actually fun to do and are not too difficult.\n\nYou will be given a situation and you are required to use truth tables to solve\nthe problem. Here is a sample problem (From a past midterm):\n\nA very special island is inhabited only by Knights and Knaves. Knights always\ntell the truth,while Knaves always lie. You meet three inhabitants: Alex, John\nand Sally.Alex says, “John is a Knight if and only if Sally is a Knave”. John\nsays, “If Sally is a Knight, then Alex is a Knight”.\n\n\\begin{question}\n    Can you find what Alex, John, and Sally are? Explain your answer.\n\\end{question}\n\n\\begin{solution}\n    Let us break down the problem:\n\n    You have three people: Alex (A), John (J), and Sally (S). Each of them are\n    either a Knight or a Knave. Hence, we have 8 possible rows in our truth table.\n\n    Let us also break down what the people have to say:\n\n    \\begin{enumerate}\n        \\item Alex says, ``John is a Knight if and only if Sally is a Knave,\"\n            which basically means: \\textbf{John is a Knight} $\\iff$\n            \\textbf{Sally is a Knave.}\n        \\item John says, ``If Sally is a Knight, then Alex is a Knight,\" which\n            basically means: \\textbf{Sally is a Knight} $\\implies$ \\textbf{Alex\n            is a Knight.}\n    \\end{enumerate}\n\n    With this information, let us construct our truth table:\n\n    \\begin{table}[ht]\n        \\caption{Truth Table}\n        \\centering\n        \\begin{tabular}{c c c c c c}\n            \\toprule\n            A & J & S & Alex Says & John Says & Does This Work?\\\\ [0.5ex]\n            \\midrule\n            Knight & Knight & Knight & F & T & \\textbf{No} - Alex is a Knight who is\n            lying\\\\\n            Knight & Knight & Knave & T & T & \\textbf{YES}\\\\\n            Knight & Knave & Knight & T & T & \\textbf{No} - John is a Knave who is telling\n            the truth\\\\\n            Knight & Knave & Knave & F & T & \\textbf{No} -John is a Knave who is telling\n            the truth\\\\\n            Knave & Knight & Knight & F & F & \\textbf{No} - John is a Knight who is lying\\\\\n            Knave & Knight & Knave & T & T & \\textbf{No} - Alex is a Knave who is telling\n            the truth\\\\\n            Knave & Knave & Knight & T & F & \\textbf{No} - Alex is a Knave who is telling\n            the truth \\\\\n            Knave & Knave & Knave & F & T & \\textbf{No} - John is a Knave who is telling\n            the truth\\\\\n            \\bottomrule\n        \\end{tabular}\n        \\label{table:nonlin} % is used to refer this table in the text\n    \\end{table}\n    \\noindent From this, we can see that there is only one possible\n    combination, that Alex and John are Knights and Sally is a Knave. \\\\ \\\\\n\\end{solution}\n\n\\begin{remark}\n    Sometimes there may be more than one possible combination that works out,\n    in that case it is not possible to correctly determine who is who, but it\n    is one of those correct combinations.\n\\end{remark}\n\n\\begin{remark}\n    There's almost always a Knights and Knaves (or a variation) question on the\n    exams.\n\\end{remark}\n\n\\begin{remark}\n    If you are interested in these problems, These problems are called\n    \\emph{Smullyan's Island Puzzles}.\n\\end{remark}\n\n\\section{Additional Exercises}\nPlease note that there are no solutions for the following questions.\n\n\\subsection{Logic}\n\\begin{question}\n    Construct the truth table for the following proposition:\n\n    \\[\n        [p \\wedge (p \\rightarrow q)] \\rightarrow q\n    \\]\n\n    This rule of inference is commonly referred to as \\emph{Modus Ponens}.\n\\end{question}\n\n\\begin{question}\n    Prove or disprove:\n\n    \\[\n        (p \\rightarrow q) \\Leftrightarrow (q \\rightarrow p)\n    \\]\n\\end{question}\n\n\\begin{question}\n    Is this a tautology or a contradiction?\n\n    \\[\n        (( (P \\rightarrow Q) \\wedge (R \\rightarrow S) \\wedge (P \\vee R))) \\rightarrow\n        (Q \\vee S)\n    \\]\n\n    You may use either Truth Tables or Logical Equivalences for this question.\n\n    This proposition is usually referred to as the \\emph{Constructive\n    Dilemma}.\n\\end{question}\n\n\\begin{question}\n    Prove or disprove:\n\n    \\[\n        (p \\oplus q) \\Leftrightarrow (p \\wedge \\neg q) \\vee (\\neg p \\wedge q)\n    \\]\n\\end{question}\n\n\\subsection{Logic Puzzles}\n%1) You meet two inhabitants, Alex and John, in an island of %Knights and\n%Knaves. You also know that Knights always tell %the truth and Knaves always\n%lie. Alex tells you, \"At least %one of us is a Knave\". Again, Alex tells you,\n%\"Both of us are %Knaves\". What can you conclude from the given information? \\\\\n%\\\\\n\n\\begin{question}\n    A very special island is inhabited only by Knights and Knaves. Knights\n    always tell the truth, while Knaves always lie. You meet three inhabitants:\n    Alex, John and Sally. Alex says, \"John is a Knight, if and only if Sally is\n    a Knave\". John says, \"If Sally is a Knight, then Alex is a Knight\". What\n    can you conclude from the given information?\n\\end{question}\n\n\\begin{question}\n    A very special island is inhabited only by knights and knaves. Knights\n    always tell the truth, and knaves always lie. You meet three inhabitants:\n    Alex, John and Sally. Alex says, \"At least one of the following is true:\n    that Sally is a knave or that I am a knight.\" John says, \"Alex could claim\n    that I am a knave.\" Sally claims, \"Neither Alex nor John are knights.\" What\n    can you conclude from the given information?\n\\end{question}\n", "meta": {"hexsha": "655787f53059e312929c667a121fc60ff72d768c", "size": 8963, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "ECS 20 Study Guide/Logic.tex", "max_stars_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_stars_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "ECS 20 Study Guide/Logic.tex", "max_issues_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_issues_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 9, "max_issues_repo_issues_event_min_datetime": "2018-12-19T03:33:59.000Z", "max_issues_repo_issues_event_max_datetime": "2018-12-30T05:45:28.000Z", "max_forks_repo_path": "ECS 20 Study Guide/Logic.tex", "max_forks_repo_name": "UC-Davis-CS-Tutoring/Study-Guides", "max_forks_repo_head_hexsha": "3123a6e883b7379c865df9287da2b969e7af20bb", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2019-06-19T01:54:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-19T01:54:16.000Z", "avg_line_length": 36.8847736626, "max_line_length": 91, "alphanum_fraction": 0.6243445275, "num_tokens": 2563, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438951104066295, "lm_q2_score": 0.8887587912826161, "lm_q1q2_score": 0.7500191982943059}}
{"text": "\\documentclass{article}\n\\usepackage[top=2cm,bottom=2cm,left=2cm,right=2cm]{geometry}\n\\usepackage{amsmath, amssymb, amsthm}\n\\usepackage{hyperref}\n\n\\usepackage{datetime}\n\\newdateformat{petsa}{\\the\\day\\ \\shortmonthname[\\the\\month] \\the\\year}\n\n\\newtheorem{definition}{Definition}[section]\n\\newtheorem{theorem}{Theorem}[section]\n\\newtheorem{lemma}[theorem]{Lemma}\n\\newtheorem{conjecture}[theorem]{Conjecture}\n\n\\title{The Diagonal Argument, Clarified and Generalized}\n\\author{poypoyan}\n\\date{\\petsa\\today}\n\n\\begin{document}\n\n\\maketitle\n\n\\begin{abstract}\nThe diagonal argument is a key ingredient in proving both the uncountability of $2^{\\omega}$ (which is a celebrated Cantor's usage of the argument) and the same-named diagonal lemma (which is used in proving Gödel's first incompleteness theorem). In this short note we present a simple formulation of the diagonal argument that is applicable to both results, and hopefully to a lot more.\n\\end{abstract}\n\n\\section{Introduction}\nWell the abstract introduced already. We think that doing this formulation ``exercise\" provided us with a clearer understanding of the concepts surrounding diagonal lemma and Cantor's diagonal argument. Now let's get into the main thing!\n\n\\section{Diagonal Argument}\n\\begin{lemma}\\label{diag-arg}\nLet $A, B, C$ be sets such that:\n\\begin{enumerate}\n\t\\item $C$ is a set of functions from $A \\rightarrow B$.\n\t\\item There exists a bijection $f:A \\rightarrow C$.\n\\end{enumerate}\nThen there exists a function $d:A \\rightarrow B$ such that $d(x) = (f(x))(x)$.\n\\end{lemma}\n\\begin{proof}\nTrivial! For every $x \\in A$, $f(x)$ is unique in $C$. Letting $c = f(x)$, $c(x)$ is unique in $B$ because $c:A \\rightarrow B$.\n\\end{proof}\n\n\\section{Cantor's Diagonal Argument}\nWe follow Cantor's original diagonal argument for the uncountability of $2^{\\omega}$ in \\cite{cantor}, which he further used to show the uncountability of the set of real numbers $\\mathbb{R}$. We'll interpret $2^{\\omega}$ as the set of \\textit{all} functions from $\\omega \\rightarrow 2$.\n\nThe proof starts by assuming that there is a bijection $f:\\omega \\rightarrow 2^{\\omega}$. This $f$ is actually the indexing of elements of $2^{\\omega}$, more commonly shown as the ``listing\" of infinite binary sequences. Applying Lemma \\ref{diag-arg} to $A = \\omega$, $B = 2$, $C = 2^{\\omega}$, and $f$ gives the diagonal function $d:\\omega \\rightarrow 2$. What we really need is $d':\\omega \\rightarrow 2$ such that $d'(x) = 1 - d(x)$; $d'$ is more commonly shown as the ``diagonal\" sequence constructed from the one's complement of the diagonal bits in the list. Now one may notice that for all $c \\in 2^{\\omega}$, $c \\ne d'$ because $c(f^{-1}(c)) \\ne d'(f^{-1}(c))$. Hence $d' \\not\\in 2^{\\omega}$, but this is in contradiction to the definition of $2^{\\omega}$. Therefore the initial assumption of existence of bijection $f:\\omega \\rightarrow 2^{\\omega}$ is false, and this completes the proof.\n\nOne may notice that the more general \\textit{Cantor's theorem}, $2^{A} > A$ for any set $A$, can be proven similarly.\n\n\\section{Gödel-Carnap Diagonal Lemma}\nWe'll just do an informal sketch. Setup first: let $\\Gamma$ be a logic on a language $\\mathcal{L}$, $N \\subset \\mathcal{L}$ be the set of all ``objects of study\" of $\\Gamma$, $P \\subset \\mathcal{L}$ be the set of all ``definable\" propositions, and $C \\subset \\mathcal{L}$ be the set of all definable predicates with only one free variable $x$. For example, if $\\Gamma = \\textsf{PA}$, (Classical) Peano Arithmetic, then the strings $``\\textsf{S0}\", ``\\textsf{SS0}\" \\in N$, and $``x + \\textsf{S0} = \\textsf{SS0}\" \\in C$. In an abuse of notation, while $c \\in C$ is a string, it can also be treated as a function $c:N \\rightarrow P$. For example in \\textsf{PA}, $``x + \\textsf{S0} = \\textsf{SS0}\"(``\\textsf{S0}\") = ``\\textsf{S0} + \\textsf{S0} = \\textsf{SS0}\"$.\n\nOne requirement of the lemma is the existence of the so-called \\textit{Gödel numbering} which is an injective (total) function $g:\\mathcal{L} \\rightarrow N$. We can now apply the diagonal argument: applying Lemma \\ref{diag-arg} to $A = \\{x \\in N \\mid g^{-1}(x) \\in C\\}$, $B = P$, $C$ is itself, and $f = g^{-1}$ restricted to $A$, gives the diagonal function $d: A \\rightarrow B$ such that $d(x) = (g^{-1}(x))(x)$. We can now present a strong variant of the lemma:\n\n\\begin{lemma}\nIf $d$ is definable in $\\mathcal{L}$ (in short, $d \\in C$) and for all $c_1, c_2 \\in C$, $c_1 \\circ g \\circ c_2 \\in C$, then for every $c \\in C$, there exists a predicate $x \\in C$ such that $x = c \\circ g \\circ x$.\n\\end{lemma}\n\\begin{proof}\nDefine a new predicate $h = c \\circ g \\circ d$. This is in $C$ because both $c, d \\in C$. We can now define $x = h \\circ g \\circ h$. This works because $h \\circ g \\circ h = c \\circ g \\circ d \\circ (g \\circ h) = c \\circ g \\circ (g^{-1}(g \\circ h))(g \\circ h) = c \\circ g \\circ (h \\circ g \\circ h)$.\n\\end{proof}\n\nThis proof is based from Section 2.2 of \\cite{salehi} \\footnote{The``$\\varrho$\" there is defined as $g \\circ d$ here.} which ultimately came from \\cite{jeroslow}. The name of lemma is not due to the resemblance to the statement, but to the usage of a diagonal function in its proof!\n\nLastly, the reason we say that the presented lemma is ``strong\" is that the more commonly presented property of $x$ is something like $\\Gamma \\vdash x(n) \\leftrightarrow (c \\circ g \\circ x)(n)$ \\footnote{Note that the weaker property requires $``\\leftrightarrow\" \\in \\mathcal{L}$.} with a valid $n \\in N$, and surely that is weaker than $x = c \\circ g \\circ x$.\n\n\\bibliographystyle{plain}\n\\bibliography{diagonal}\n\\end{document}", "meta": {"hexsha": "78080e1a2f01fd2c928ded71615648188c945d08", "size": 5579, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "files/diagonal.tex", "max_stars_repo_name": "poypoyan/matematex", "max_stars_repo_head_hexsha": "379c7c386b2a692537dea5209d9b246e434a8faa", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "files/diagonal.tex", "max_issues_repo_name": "poypoyan/matematex", "max_issues_repo_head_hexsha": "379c7c386b2a692537dea5209d9b246e434a8faa", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "files/diagonal.tex", "max_forks_repo_name": "poypoyan/matematex", "max_forks_repo_head_hexsha": "379c7c386b2a692537dea5209d9b246e434a8faa", "max_forks_repo_licenses": ["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.2686567164, "max_line_length": 896, "alphanum_fraction": 0.7065782398, "num_tokens": 1712, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8438950868503682, "lm_q2_score": 0.8887587979121383, "lm_q1q2_score": 0.7500191829530928}}
{"text": "\\lab{Algorithms}{B-Splines}{B-Splines}\nThough B\\'{e}zier curves are good for a variety of things, they have certain limitations.\n\\begin{itemize}\n\\item As the number of control points increases it becomes very expensive to compute the points on the curve.\n\\item Changes in the placement of a single control point affect the shape of the entire curve.\n\\item Since a change in any control point affects the entire curve, it is necessary to recompute the entire curve to account for any change in any control point.\n\\item As the number of points increases, individual points have progressively less affect on the portions of the curve that lie nearest to them.\n\\end{itemize}\n\nB-Splines are an ideal way to answer these limitations.\nA B-Spline is, roughly speaking, a piecewise B\\'{e}zier curve.\nIn order to better explain what a Basis function is.\n\n\\section*{B-Spline Basis Functions}\n\nIn the previous lab we introduced a way to represent B\\'{e}zier curves as a linear combination of Bernstein Polynomials.\nNotice the convenient property that the coefficient of each Bernstein polynomial for the B\\'{e}zier curve formed from a given control point is simply the control point itself.\n\n\\begin{figure}\n\\includegraphics[width=\\textwidth]{bernstein_basis}\n\\caption{5th degree Bernstein basis functions}\n\\end{figure}\n\nThis is a useful property.\nB-splines are a generalization of B\\'{e}zier curves which allow us to use piecewise basis functions.\nUsing piecewise basis functions allows us to make local changes to the curve we are representing.\nThis makes it so that we do not have to recompute the entire curve when we change only one control point.\nThis also makes control of the curve easier because changes from each contro point are only applied locally.\nAnother useful effect is that this makes the individual pieces of the B-Spline more responsive to changes in the control points that are used in creating it.\nThis, again, makes the curve easier to control.\nThe idea is that each point has a strictly local influence on the curve so that each point has a larger effect on a smaller portion of the curve.\n\nWe would like to be able to do this without loosing the useful properties of B\\'{e}zier curves.\nSimply using basis functions guarantees that each point of the curve will be a linear combination of the control points.\nIt would be best if we could make it so that this curve has the convex hull property (i.e. that it lies within the area bounded by the outermost control points).\nB\\'{e}zier curves also allow easy computation of their derivatives, so we would hope that B-Splines would allow this as well.\nOne of the largest constraints we need is that the curve we are forming be continuous.\nIt would be even better if it were differentiable, or even twice-differentiable.\nThe construction of the B-Spline Basis functions takes all of these factors into account.\n\nThere are a number of ways the B-Spline basis functions can be defined.\nA common approach is to use recursion.\nLet $U = \\lbrace u_0, u_1, ... , u_m \\rbrace$ be a nondecreasing sequence of real numbers.\n$U$ is called the knot vector.\nThe $u_i$ are called the knots.\nNote that each $u_i$ is not necessarily distinct.\n$N_{i,p}(u)$, the $i$'th B-Spline basis function of degree $p$, or order $p+1$ is defined as:\n\n\\begin{equation}\nN_{i,0}(u) = \n\\begin{cases}\n1 & \\text{if } u_i \\leq u < u_{i+1} \\\\\n0 & \\text{otherwise}\n\\end{cases}\n\\end{equation}\n\n\\begin{equation}\nN_{i,p}(u) = \\frac{u - u_i}{u_{i+p} - u_i} N_{i,p-1}(u) + \\frac{u_{i + p + 1} - u}{u_{i + p + 1} - u_{i + 1}} N_{i+1,p-1}(u)\n\\end{equation}\n\nThis is known as the Cox-De Boor recursion formula.\nThis algorithm is the De Boor algorithm. \nWhen implemented properly, this algorithm is both fast and numerically stable.\n\nNotice that we defined $U$ to be nondecreasing, which means some $u_i$ may be repeated.\nWhen programming this algorithm as written, be careful to avoid division by zero.\nWhen we get the indeterminate form $\\frac{0}{0}$ we define these terms to be zero.\n\nAlso note that $N_{i,0}$ is a step function which is zero except on $[u_i, u_{i+1})$. \nThe other basis functions are piecewise polynomials of degree $p$ that are nonzero on $[u_{i-p}, u_{i+1+p})$.\nThis is also nice because computation of a set of basis functions requires only a knot vector $U$ and a degree $p$, so we can predefine basis functions before we know the actual positions of the control points.\n\n\\begin{problem}\nUse the De Boor algorithm to write a recursive python function to evaluate a b-spline basis function for some $u$ spanned by the knot vector.\n\\end{problem}\n\nUpon considering the computation involved in the previous problem, we see that this recursion, particularly for higher order splines, involves a massive amount of repetitive calculation.\nSome of this excess computation can be eliminated while still using recursion, but we will do this by forming an iterative solution to the problem.\n\nFirst, notice that for splines of order $2$ and higher, we actually compute the values of some splines multiple times.\nA simple way to avoid this is to figure out which of the 0-order splines we will actually use in our computation, compute them all, then compute all the needed splines of order 1, 2, etc.\n\nThere is also some redundant computation in the computation of the coefficients used at each stage of the recursion.\nThis can be eliminated by using good control structure and a temporary variable.\n\nWe will label the left and right coefficients in the formula $L$ and $R$ respectively, so we have $L(n,p,u) = \\frac{u - u_i}{u_{i+p} - u_i}$ and $R(n,p,u) = \\frac{u_{i + p + 1} - u}{u_{i + p + 1} - u_{i + 1}}$. Notice that $L(n+1,p,u) = 1 - R(n,p,u)$. We can eliminate much of the duplicate computation by computing the new left hand side coefficient the iteration before we actually need it. This avoids nearly all the repeated computation.\n\n\\begin{problem}\nWrite an iterative function that computes the values for all the b-spline basis functions of a given power $p$ for a given array of $u$ values. Return the answer as a two dimensional array.\n\\end{problem}\n\nIt is worth noting that you can remove further excess computation when evaluating a single function and even further when evaluating a single function at a single point.\nThis can be done by figuring out in advance which of the $N_{i,p}$ will be nonzero and only iterating over those terms.\nThis approach may or may not be faster depending on the form of the problem.\n\nScipy has some built in functions and a built in class for B-splines.\nThey are all part of the scipy.interpolate package.\n", "meta": {"hexsha": "6349cc6607502057ee7c926afc0cce9a8132abb2", "size": 6574, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "Algorithms/Splines/bsplines.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/Splines/bsplines.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/Splines/bsplines.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": 67.0816326531, "max_line_length": 441, "alphanum_fraction": 0.7681776696, "num_tokens": 1602, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.897695292107347, "lm_q2_score": 0.8354835452961427, "lm_q1q2_score": 0.7500096452455026}}
{"text": "\\section{The Bootstrap}\n\nBootstrap allows for investigating the variance of a statistic by calculating the statistic many times on samples drawn from the empirical CDF. This amounts to sampling from the dataset with replacement (i.e. datapoints may be included in a sample several times).\n\nThere are two approximations in play: first, the true CDF is approximated using the empirical CDF. Second, the variance of the statistic is estimated based on a sample.\n\nUncertainty in terms of bootstrap estimates may be calculated in terms of normal, pivotal or percentile intervals. The normal interval is valid when the statistic is approximately normally distributed.\n\n\\section{Jackknife}\nThe Jackknife method is less computationally expensive, but less general than the bootstrap. For a dataset of $n$ elements, the Jackknife method calculates the statistic $n$ times, each time removing one of the estimates from the calculation. The jackknife does not produce consistent estimators of the standard error of sample quantiles. \n", "meta": {"hexsha": "f09a352ddd379d15b22e84f33b9a290a1ce91702", "size": 1023, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "notes/chapters/sections/stats_bootstrap.tex", "max_stars_repo_name": "jpbm/probabilism", "max_stars_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_stars_repo_licenses": ["MIT"], "max_stars_count": null, "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "notes/chapters/sections/stats_bootstrap.tex", "max_issues_repo_name": "jpbm/probabilism", "max_issues_repo_head_hexsha": "a2f5c1595aed616236b2b889195604f365175899", "max_issues_repo_licenses": ["MIT"], "max_issues_count": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "notes/chapters/sections/stats_bootstrap.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": 93.0, "max_line_length": 339, "alphanum_fraction": 0.8172043011, "num_tokens": 198, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976953003183443, "lm_q2_score": 0.8354835350552603, "lm_q1q2_score": 0.7500096429124639}}
{"text": "\\section{The Wave Equation}\r\n\\subsection{Waves on an Elastic String}\r\nConsider small displacements $y(x,t)$ on a stretched string with fixed ends at $x=0$ and $x=L$, that is with boundary conditions $y(0,t)=y(L,t)=0$.\r\nWe want to determine the string's motion subject to initial conditions\r\n$$y(x,0)=p(x),\\frac{\\partial y}{\\partial t}(x,0)=q(x)$$\r\nWe want to derive its equation of motion.\r\nWe try to obtain a differential equation by balancing the forces on string segment $x,x+\\delta x$ and taking $\\delta x\\to 0$.\r\nBy resolving in $x$ direction we get that the tension $T$ on the string is independent of $x$.\r\nBy resolving in $y$ direction we arrive at\r\n$$(\\mu\\delta x)\\frac{\\partial^2y}{\\partial t^2}=T\\frac{\\partial^2y}{\\partial x^2}\\delta x-g\\mu\\delta x$$\r\nwhere $\\mu$ is the mass per unit length (aka linear mass density).\r\nWrite $c=\\sqrt{T/\\mu}$ the wave speed and assume the acceleration due to gravity is negligible, then this equation is just\r\n$$\\frac{1}{c^2}\\frac{\\partial^2y}{\\partial t^2}=\\frac{\\partial^2y}{\\partial x^2}$$\r\nwhich is called the one-dimensional wave equation.\r\n\\subsection{Seperation of Variables}\r\nOur first attempt at a solution is to guess a solution of seperable form, that is $y(x,t)=X(x)T(t)$, then substitution gives\r\n$$\\frac{1}{c^2}X\\ddot{T}=X^{\\prime\\prime}T\\implies \\frac{1}{c^2}\\frac{\\ddot{T}}{T}=\\frac{X^{\\prime\\prime}}{X}$$\r\nThe left hand side depends only on $t$ and the right hand side depends only on $x$, so they can only equal if both sides equal a constant $-\\lambda$ (called the seperation constant), then we get\r\n$$\\begin{cases}\r\n    X^{\\prime\\prime}+\\lambda X=0\\\\\r\n    \\ddot{T}+\\lambda c^2T=0\r\n\\end{cases}$$\r\nSuch nice things don't always happen, but we are glad it happened in this particular case.\r\n\\footnote{Whether we can do it depends on the existence of symmetry in the boundary conditions, which is probably not going to be discussed here.}\r\nSo we reduced a PDE to two independent ODEs, which we know how to solve.\r\n\\subsection{Boundary Conditions and Normal Modes}\r\nThere are a few possibilities depending on the sign of $\\lambda$.\\\\\r\nIf $\\lambda<0$, then taking $\\chi^2=-\\lambda$ gives the general solution\r\n$$X(x)=Ae^{\\chi x}+Be^{-\\chi x}=\\tilde{A}\\cosh(\\chi x)+\\tilde{B}\\sinh(\\chi x)$$\r\nwhere $A,B,\\tilde{A},\\tilde{B}$ are constants.\r\nBut the boundary conditions $X(0)=X(L)=0$ would yield $X=0$ everywhere, so this is just the trivial solution.\\\\\r\nNow if $\\lambda=0$, then $X(x)=Ax+B$ where $A,B$ are constants, but again we must have $A=B=0$ as $X(0)=X(L)=0$.\r\nTrivial solution again.\\\\\r\nWhat is left is $\\lambda>0$, so $X(x)=A\\cos(\\sqrt{\\lambda}x)+B\\sin(\\sqrt{\\lambda}x)$, then the boundary condition $X(0)=X(L)=0$ gives the family of solutions\r\n$$\\lambda_n=\\left( \\frac{n\\pi}{L} \\right)^2,X_n(x)=B_n\\sin\\frac{n\\pi x}{L}$$\r\nwhere $B_n$ are constants.\r\nIt is not hard to observe that they are just our familiar Fourier eigenvalues and eigenfunctions.\r\nThese are called the normal modes of the system since its spacial shape in $x$ does not change in time but the amplitudes may vary.\r\n\\footnote{Well, duh!}\r\nThe case $n=1$ is called the fundamental mode.\r\nA plot shows the modes are simply just the patterns of simple vibrations we expect.\r\n\\subsection{Initial Conditions and Temporal Solutions}\r\nSubstituting $\\lambda_n=(n\\pi/L)^2$ into the time ODE gives\r\n$$T_n(t)=C_n\\cos\\frac{n\\pi ct}{L}+D_n\\sin\\frac{n\\pi ct}{L}$$\r\nwhere $C_n,D_n$ are constants.\r\nSo we obtain the family of solutions\r\n$$y_n(x,t)=T_n(t)X_n(x)=\\left( C_n\\cos\\frac{n\\pi ct}{L}+D_n\\sin\\frac{n\\pi ct}{L} \\right)\\sin\\frac{n\\pi x}{L}$$\r\nAs the system we are trying to deal with is homogeneous and linear, we have the superposition principle, so the general solution is\r\n$$y(x,t)=\\sum_{n=1}^\\infty\\left( C_n\\cos\\frac{n\\pi ct}{L}+D_n\\sin\\frac{n\\pi ct}{L} \\right)\\sin\\frac{n\\pi x}{L}$$\r\nassuming it converges sufficiently well.\r\nThis satisfies the boundary conditions as $X_n$ does.\r\nSubstituting into the initial condition, we get\r\n$$p(x)=\\sum_{n=1}^\\infty C_n\\sin\\frac{n\\pi x}{L},q(x)=\\sum_{n=1}^\\infty\\frac{n\\pi c}{L}D_n\\sin\\frac{n\\pi x}{L}$$\r\nwhich allows us to find $C_n,D_n$ by expanding $p,q$ as Fourier sine series.\r\nIn particular,\r\n$$C_n=\\frac{2}{L}\\int_0^Lp(x)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx,D_n=\\frac{2}{n\\pi c}\\int_0^Lq(x)\\sin\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nThis is possible (well, assuming everything), so we have found a particular solution to the system.\r\n\\begin{example}\r\n    We pluck string at $x=\\xi$, which requires\r\n    $$y(x,0)=p(x)=\\begin{cases}\r\n        x(1-\\xi)\\text{, for $0\\le x\\le \\xi$}\\\\\r\n        \\xi(1-x)\\text{, for $\\xi\\le x\\le 1$}\r\n    \\end{cases},\\frac{\\partial y}{\\partial t}(x,0)=q(x)=0$$\r\n    Then with our formulas we obtain\r\n    $$C_n=\\frac{2\\sin(n\\pi\\xi)}{(n\\pi)^2},D_n=0\\implies y(x,t)=\\sum_{n=1}^\\infty\\frac{2}{(n\\pi)^2}\\sin(n\\pi\\xi)\\sin(n\\pi x)\\cos(n\\pi ct)$$\r\n    Of course, this case happens to be the way of making sound on a string instrument, where guitar has $\\xi\\in [1/4,1/3]$ and violin has $\\xi\\approx 1/7$.\r\n\\end{example}\r\nBy the usual trigonometric identities, the general solution we found earlier becomes $y(x,t)=f(x-ct)+g(x+ct)$ where\r\n$$f(x-ct)=\\frac{1}{2}\\sum_{n=1}^\\infty\\left(C_n\\sin\\frac{n\\pi(x-ct)}{L}+D_n\\cos\\frac{n\\pi(x-ct)}{L}\\right)$$\r\nand\r\n$$g(x+ct)=\\frac{1}{2}\\sum_{n=1}^\\infty\\left(C_n\\sin\\frac{n\\pi(x+ct)}{L}-D_n\\cos\\frac{n\\pi(x+ct)}{L}\\right)$$\r\nSo the standing wave solution can be interpreted as a superposition of a right-moving wave (along $x-ct=\\eta$, $\\eta$ constant) and a left-moving wave (along $x+ct=\\xi$, $\\xi$ constant).\r\nWe can generalise this idea later.\r\n\\begin{example}\r\n    In the special case where $q=0$, we have $f=g=p/2$, so\r\n    $$y(x,t)=\\frac{p(x-ct)+p(x+ct)}{2}$$\r\n\\end{example}\r\n\\subsection{Oscillation Energy}\r\nA vibrating string has kinetic energy due to the motion of the particles in the string.\r\nThis is given by $mv^2/2$.\r\nSo the total kinetic energy on the string would be the integral\r\n$$\\operatorname{KE}=\\frac{1}{2}\\int_0^L\\left(\\frac{\\partial y}{\\partial t}\\right)^2\\mu\\,\\mathrm dx$$\r\nwhere $\\mu$ is the mass per unit length.\r\nThe (elastic) potential energy due to streching $\\Delta x$ is then\r\n$$\\operatorname{PE}=T\\int_0^L\\left( \\sqrt{1+\\left( \\frac{\\partial y}{\\partial x} \\right)^2} -1\\right)\\,\\mathrm dx\\approx\\frac{1}{2}T\\int_0^L\\left( \\frac{\\partial y}{\\partial x} \\right)^2\\,\\mathrm dx$$\r\nfor small $|\\partial y/\\partial x|$.\r\nSo the total summed energy of the string is then, via $c^2=T/\\mu$,\r\n$$E=\\frac{1}{2}\\mu\\int_0^L\\left( \\left( \\frac{\\partial y}{\\partial t} \\right)^2+c^2\\left(\\frac{\\partial y}{\\partial x}\\right)^2 \\right)\\,\\mathrm dx$$\r\nSo by substituting our generalisation and using orthogonality,\r\n$$E=\\frac{1}{2}\\mu\\sum_{n=1}^\\infty (A_n+B_n)$$\r\nwhere\r\n$$A_n=\\int_0^L \\left( \\frac{n\\pi c}{L}C_n\\sin\\frac{n\\pi ct}{L}+ \\frac{n\\pi c}{L}D_n\\cos\\frac{n\\pi ct}{L}\\right)^2\\sin^2\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nand\r\n$$B_n=\\int_0^Lc^2\\left( C_n\\cos\\frac{n\\pi ct}{L}+ D_n\\sin\\frac{n\\pi ct}{L}\\right)^2\\frac{n^2\\pi^2}{L^2}\\cos^2\\frac{n\\pi x}{L}\\,\\mathrm dx$$\r\nSimplifying this mess gives\r\n$$E=\\frac{1}{4}\\mu\\sum_{n=1}^\\infty\\frac{n^2\\pi^2c^2}{L}(C_n^2+D_n^2)$$\r\nwhich can be interpreted as the sum of the energy of all normal modes.\r\nAlso, this is constant, so it is conserved in time.\r\n\\subsection{Wave Reflection and Transmission}\r\nRecall the travelling wave solution along the $x\\pm ct$ directions.\r\nWe want to further develop this idea\r\n\\begin{definition}\r\n    A simple harmonic travelling wave is defined as\r\n    $$t=\\operatorname{Re}(Ae^{i\\omega (t-x/c)})=|A|\\cos(\\omega(t-x/c)+\\phi)$$\r\n    where $\\phi=\\arg A$ is the phase and $2\\pi c/\\omega$ is the wavelength.\r\n\\end{definition}\r\nSometimes we will just assume the $\\operatorname{Re}$ is there without writing it out explicitly.\\\\\r\nConsider a density discontinuity on the string at $x=0$ with\r\n$$\\mu=\\begin{cases}\r\n    \\mu_-\\text{, for $x<0$}\\implies c_-=\\sqrt{T/\\mu_-}\\\\\r\n    \\mu_+\\text{, for $x>0$}\\implies c_+=\\sqrt{T/\\mu_+}\r\n\\end{cases}$$\r\nSo a wave $Ae^{i\\omega (t-x/c_-)}$ approaching $0$ from left will break down to two parts:\r\nThe reflected wave $Be^{i\\omega (t+x/c_-)}$ and the transmitted wave $De^{i\\omega (t-x/c_+)}$.\r\nThe continuity condition on $y$ gives $A+B=D$ and by balancing the forces\r\n$$T\\left.\\frac{\\partial y}{\\partial x}\\right|_{x=0_-}=T\\left.\\frac{\\partial y}{\\partial x}\\right|_{x=0_+}$$\r\n(which is basically the continuity condition on $\\partial y/\\partial x$) it gives $2A=D(c_++c_-)/c_+$.\r\nCombining them all gives\r\n$$D=\\frac{2c_+}{c_-+c_+},B=\\frac{c_+-c_-}{c_-+c_+}A$$\r\nIn general, it is possible to have different phase shifts $\\phi$.\\\\\r\nNow, if $c_+=c_-$, then $D=A$ and $B=0$, so there is no reflection, which is intuitive.\r\nIf we have the Dirichlet boundary conditions $\\mu_+/\\mu_-\\to\\infty$ (interpreted as a fixed end $y=0$ at $x=0$), then $c_+/c_-\\to 0$, so $D=0$ and $B=-A$ where we get total reflection (with opposite phase $\\phi=\\pi$).\r\nThis is also what is expected.\r\nIf we have the Neumann boundary conditions $\\mu_+/\\mu_-\\to 0$ (interpreted as an extremely light string in $x>0$), then $c_+/c_-\\to\\infty$, so $D=2A$ and $B=A$, so we get total reflection with same phase $\\phi=0$.\r\n\\subsection{Wave Equation in the Plane Polar Coordinates}\r\nThe wave equation in two dimensions is\r\n$$\\frac{1}{c^2}\\frac{\\partial^2u}{\\partial t^2}=\\nabla^2u$$\r\nUnder plane polar coordinates $u=u(r,\\theta,t)$, we impose the boundary condition $u(1,\\theta,t)=0$ for any $\\theta,t$ (interpreted as a fixed rim) and initial conditions\r\n$$u(r,\\theta,0)=\\phi(r,\\theta),\\frac{\\partial u}{\\partial t}(r,\\theta,0)=\\psi(r,\\theta)$$\r\nWe use seperation of variables again.\r\nIf we substitute $u(r,\\theta,t)=T(t)V(r,\\theta)$, then we obtain the decoupled system\r\n$$\\begin{cases}\r\n    \\ddot{T}+\\lambda c^2T=0\\\\\r\n    \\nabla^2V+\\lambda V=0\r\n\\end{cases}$$\r\nwhere $\\lambda$ is a seperation constant.\r\nNote that in plane polar,\r\n$$\\nabla^2V=\\frac{\\partial^2V}{\\partial r^2}+\\frac{1}{r}\\frac{\\partial V}{\\partial r}+\\frac{1}{r^2}\\frac{\\partial^2V}{\\partial\\theta^2}+\\lambda V=0$$\r\nWe seperate the variables further by writing $V(r,\\theta)=R(r)\\Theta(\\theta)$.\r\nThis gives\r\n$$\\begin{cases}\r\n    \\Theta^{\\prime\\prime}+\\mu\\Theta=0\\\\\r\n    r^2R^{\\prime\\prime}+rR^\\prime+(\\lambda r^2-\\mu)R=0\r\n\\end{cases}$$\r\nwhere $\\mu$ is again a seperation constant.\r\nAssuming $\\mu>0$.\r\nSolving for $\\Theta$ subject to $\\Theta(0)=\\Theta(\\pi)$ gives our old friend\r\n$$\\Theta_m(\\theta)=A_m\\cos(m\\theta)+B_m\\sin(m\\theta),m\\in\\mathbb Z_{>0}$$\r\nwith $\\mu_m=m^2$.\r\nFor $R$, we divide the equation by $r$ and transform it into Sturm-Liouville form\r\n$$\\frac{\\mathrm d}{\\mathrm dr}(rR^\\prime)-\\frac{m^2}{r}=-\\lambda rR$$\r\nNote that the boundary condition means we only care about $r\\in[0,1]$.\r\nThe boundary condition are self-adjoint, which is convenient.\r\n\\subsection{Bessel's Equation}\r\nSubstitute $z=\\sqrt{\\lambda}r$ gives\r\n$$z^2\\frac{\\mathrm d^2R}{\\mathrm dz^2}+z\\frac{\\mathrm dR}{\\mathrm dz}+(z^2-m^2)R=0\\iff (zR^\\prime)^\\prime+\\left( z-\\frac{m^2}{z} \\right)R=0$$\r\nApparently $0$ is a regular singular point, so we substitute the power series\r\n$$R=z^p\\sum_{n=0}^\\infty a_nz^n$$\r\nwhich gives\r\n$$\\sum_{n=0}^\\infty (a_n(n+p)(n+p-1)z^{n+p}+(n+p)z^{n+p}+z^{n+p+2}+m^2z^{n+p})=0$$\r\nThe indivial equation is then $p^2-m^2=0$, so $p=\\pm m$.\r\nFor $p=m$, it is called the regular solution (otherwise you get a singular point at $0$).\r\nHere we have the recurrence\r\n$$(n+m)^2a_n+a_{n-2}-m^2a_n=0\\implies a_n=-\\frac{1}{n(n+2m)}a_{n-2}$$\r\nThis gives the even series with solutions\r\n$$a_{2n}=a_0\\frac{(-1)^n}{2^{2n}n!(n+m)(n+m-1)\\cdots (m+1)}$$\r\nConveniently we set $a_0=1/(2^mm!)$ which gives the Bessel function\r\n$$J_m(z)=\\left( \\frac{z}{2} \\right)^m\\sum_{n=0}^\\infty\\frac{(-1)^n}{n!(n+m)!}\\left( \\frac{z}{2} \\right)^{2n}$$\r\nActually, if we set $y=\\sqrt{z}R$, then we will obtain\r\n$$y^{\\prime\\prime}+y\\left( 1+\\frac{1}{4z}-\\frac{m^2}{z^2} \\right)=0$$\r\nwhich, as $z\\to\\infty$, gives the approximation $y^{\\prime\\prime}\\approx -y$ which has (approximated) solutions $R\\approx z^{-1/2}(A\\cos z+B\\sin z)$ for $A,B$ constants.\\\\\r\nBack to Bessel's function.\r\nIn fact, when $m=\\nu\\notin\\mathbb Z$, this power solution also works but replace $(n+m)!$ by $\\Gamma(n+\\nu+1)$.\r\nThe second solution with $p=-m$ is known as the Neumann functions (or Bessel functions of second kind) which satisfies\r\n$$Y_m(z)=\\lim_{\\nu\\to m}\\frac{J_\\nu(z)\\cos(\\nu\\pi)-J_{-\\nu}(z)}{\\sin(\\nu\\pi)}$$\r\nAs one can verify, there are a number of identities associated with Bessel functions, e.g. we have $(z^mJ_m(z))^\\prime=z^mJ_{m-1}(z)$.\r\nThis also implies\r\n$$\\begin{cases}\r\n    J_m^\\prime(z)+mJ_m(z)/z=J_{m-1}(z)\\\\\r\n    J_{m-1}(z)+J_{m+1}(z)=2mJ_m(z)/z\\\\\r\n    2J_m^\\prime(z)=J_{m-1}(z)-J_{m+1}(z)\r\n\\end{cases}$$\r\nNaturally, we want to study the aymptopic behaviour of $J_m$ and $Y_m$.\r\nAs $z\\to 0$, easily $J_0(z)\\to 1$, $J_m(z)\\sim (z/2)^m/m!$ and $Y_0(z)\\to 2\\log(z/2)/\\pi$, $Y_m(z)=-(m-1)!(2/z)^m/\\pi$.\r\nSo $0$ is a singularity of $Y_m$.\\\\\r\nFor large $z\\to\\infty$, $J_m,Y_m$ converges to $0$ oscillatorily, i.e.\r\n$$J_m(z)\\sim\\sqrt{\\frac{2}{\\pi z}}\\cos\\left( z-\\frac{m\\pi}{2}-\\frac{\\pi}{4} \\right),Y_m(z)\\sim\\sqrt{\\frac{2}{\\pi z}}\\sin\\left( z-\\frac{m\\pi}{2}-\\frac{\\pi}{4} \\right)$$\r\nThis hints that we might want to take a look at the infinitely many zeros in $\\mathbb R_{>0}$ of Bessel function.\r\nLet $j_{m,n}$ to be the $n^{th}$ positive zero of $J_m$.\r\nSo the asymptopic formula above shows approximately $j_{m,n}\\approx \\tilde{j}_{m,n}=n\\pi +m\\pi/2-\\pi/4$ with accuracy $|(j_{m,n}-\\tilde{j}_{m,n})/j_{m,n}|<1/(10n)$ for $n>m^2/2$.\r\nA few of the actual values are below:\r\n$$j_{0,1}\\approx 2.405,j_{0,2}\\approx 5.520,j_{0,3}\\approx 8.653$$\r\nIt is a fun activity for the reader to try and draw $J_m$.\r\n\\subsection{A Vibrating Drum}\r\nSo the radial solutions become\r\n$$R_m(z)=R_m(\\sqrt{\\lambda}r)=AJ_m(\\sqrt{\\lambda}r)+BY_m(\\sqrt{\\lambda} r)$$\r\nFor $A,B$ constants.\r\nBut we want the solution to be bounded near zero which would mean $B=0$.\r\nWe also need $R(1)=0$, therefore $\\lambda_{m,n}=j_{m,n}^2$ are the eigenvalues.\r\nTherefore the spacial solutions are\r\n$$V_{m,n}(r,\\theta)=\\Theta_m(\\theta)R_{m,n}(\\sqrt{\\lambda_{m,n}}r)=(A_{m,n}\\cos(m\\theta)+B_{m,n}\\sin(m\\theta))J_m(j_{m,n}r)$$\r\nPutting these eigenvalues to the temporal equation then shows $T_{m,n}$ are just linear combinations of $\\cos(j_{m,n}ct)$ and $\\sin(j_{m,n}ct)$.\r\nPutting everything together we get $u(r,\\theta,t)=A+B+C$ where\r\n$$A=\\sum_{n=1}^\\infty J_0(j_{0n})r(A_{0n}\\cos(j_{0n}ct)+C_{0n}\\sin(j_{0n}ct))$$\r\n$$B=\\sum_{m=1}^\\infty\\sum_{n=1}^\\infty J_m(j_{m,n}r)(A_{m,n}\\cos(m\\theta)+B_{m,n}\\sin(m\\theta))\\cos(j_{m,n}ct)$$\r\n$$C=\\sum_{m=1}^\\infty\\sum_{n=1}^\\infty J_m(j_{m,n}r)(C_{m,n}\\cos(m\\theta)+D_{m,n}\\sin(m\\theta))\\sin(j_{m,n}ct)$$\r\nWe still have to impose the initial conditions.\r\n$$\\phi(r,\\theta)=u(r,\\theta,0)=\\sum_{m=0}^\\infty\\sum_{n=1}^\\infty J_m(j_{m,n}r)(A_{m,n}\\cos(m\\theta)+B_{m,n}\\sin(m\\theta))$$\r\n$$\\psi(r,\\theta)=\\frac{\\partial u}{\\partial t}(r,\\theta,0)=\\sum_{m=0}^\\infty\\sum_{n=1}^\\infty j_{mn}cJ_m(j_{m,n}r)(C_{m,n}\\cos(m\\theta)+D_{m,n}\\sin(m\\theta))$$\r\nAs usual, we find the coefficient by orthogonality of these eigenfunctions.\r\nWe do already know that they are orthogonal, what we really need is the normalisation constant.\r\nSome calculation then reveals\r\n$$\\int_0^1J_m(j_{m,n}r)J_m(j_{m,k}r)r\\,\\mathrm dr=\\frac{1}{2}(J_m^\\prime(j_{m,n}))\\delta_{nk}=\\frac{1}{2}J_{m+1}(j_{m,n})^2\\delta_{n,k}$$\r\nTherefore for $p>0$,\r\n$$A_{pq}=\\left(\\int_0^{2\\pi}\\int_0^1\\cos(p\\theta)J_p(j_{pq}r)\\phi(r,\\theta)r\\,\\mathrm dr\\mathrm d\\theta\\right)\\left( \\frac{\\pi+\\delta_{0p}\\pi}{2}J_{p+1}(j_{pq})^2 \\right)^{-1}$$\r\nWe can obtain $B_{m,n},C_{m,n},D_{m,n}$ in similar ways.\r\n\\begin{example}\r\n    Consider $\\phi=1-r^2$, so we have $\\forall m,B_{m,n}=0$ and $\\forall m\\neq 0,A_{m,n}=0$.\r\n    We also set $\\psi=0$, which means $C_{m,n}=D_{m,n}=0$ for all $m,n$.\r\n    By calculations,\r\n    $$A_{0,n}=\\frac{2}{J_1(j_{0,n})^2}\\frac{J_2(j_{0,n})}{j_{0,n}^2}\\approx\\frac{J_2(j_{0,n})}{n}$$\r\n    for large $n$.\r\n    So the solution is\r\n    $$u(r,\\theta,t)=\\sum_{n=1}^\\infty\\frac{2}{J_1(j_{0,n})^2}\\frac{J_2(j_{0,n})}{j_{0,n}^2}J_0(j_{0,n}r)\\cos(j_{0,n}ct)$$\r\n    So the fundamental frequency is $\\omega=j_{0,1}c(2/d)\\approx 4.8c/d$ which is higher than the value for a string, whose value is approximately $77\\%$ of the figure for the drum.\\\\\r\n    A sketch of the nodal lines will then show that the solution is pretty close to our intuition.\r\n\\end{example}", "meta": {"hexsha": "62a652255911048aa54a3b6136969ed109598110", "size": 16351, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "3/wave.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": "3/wave.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": "3/wave.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": 72.0308370044, "max_line_length": 218, "alphanum_fraction": 0.6657696777, "num_tokens": 5992, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.8976952866333483, "lm_q2_score": 0.8354835432479663, "lm_q1q2_score": 0.7500096388334285}}
{"text": "\\section{Normalized Cuts and Image Segmentation}\n\\label{ch:jianbo00}\n\n\\textit{Normalized Cuts and Image Segmentation} by Jianbo Shi(Associate Professor at the University of Pennsylvania, Computer and Information Science). \\\\\nCited by 9393. \\textit{Pattern Analysis and Machine Intelligence, IEEE, 2000}\n\\newline\n\n\\textbf{Main point} is that the normalized cut algorithm \\begin{inparaenum}[\\itshape a\\upshape)]\n\\item partitioning algorithm to disjoint the graph into two cluster.\n\\item and it solves NP-hard problem by approximate solution.\n\\end{inparaenum}\n\n\\subsection{Normalized cut algorithm}\nA graph $G = (V, E)$ can be partitioned into two disjoint sets $A, B$ by removing edges connecting two parts. The goal of algorithm is that computes the cut cost as a fraction of the total edge connections to all the nodes in the graph. It can be founded in polynomial time but often divide with small cluster. Normalized cut solves this problem.\n\n\\begin{figure}[ht]\n\\begin{mdframed}\n$Ncut(A,B) = \\frac{cut(A,B)}{assoc(A,V)} + \\frac{cut(A,B)}{assoc(B,V)}$ \\\\\n\\\\\nwhere \\\\\n$cut(A,B) = \\sum_{u \\in A, v \\in B} w(u, v)$,\\\\\n$assoc(A,V) = \\sum_{u \\in A, t \\in V} w(u, t)$\n\\end{mdframed}\n\\caption{Nomalized cut algorithm}\n\\end{figure}\n\nBasic idea is that big clusters will inclease $assoc(A,B)$, thus decreasing $Ncut(A,B)$. It is NP-Hard problem though, it can find approximate solution by finding the eigenvector with the second-smallest eigenvalue of this generalized eigenvalue problem. This splits the data into two clusters. We can recursively partition data to find more clusters.\n\\begin{figure}[ht]\n\\begin{mdframed}\n$(D - W)y = \\lambda D y$\n\\end{mdframed}\n\\caption{Generalized eigenvalue system to solve}\n\\end{figure}\n\n\n", "meta": {"hexsha": "a6d61c07db1c3a8d8156b952cf43ec1319c013e2", "size": 1717, "ext": "tex", "lang": "TeX", "max_stars_repo_path": "report/references/reference_research/jianbo2000.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/jianbo2000.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/jianbo2000.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": 47.6944444444, "max_line_length": 351, "alphanum_fraction": 0.750728014, "num_tokens": 471, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.8976952811593495, "lm_q2_score": 0.8354835391516133, "lm_q1q2_score": 0.7500096305827159}}
